Merge "Add support for more vector types to RS."
diff --git a/Android.mk b/Android.mk
index c838600..d4d9a33 100644
--- a/Android.mk
+++ b/Android.mk
@@ -110,7 +110,9 @@
 	core/java/android/net/IConnectivityManager.aidl \
 	core/java/android/net/INetworkManagementEventObserver.aidl \
 	core/java/android/net/IThrottleManager.aidl \
+	core/java/android/net/INetworkPolicyListener.aidl \
 	core/java/android/net/INetworkPolicyManager.aidl \
+	core/java/android/net/INetworkStatsService.aidl \
 	core/java/android/nfc/ILlcpConnectionlessSocket.aidl \
 	core/java/android/nfc/ILlcpServiceSocket.aidl \
 	core/java/android/nfc/ILlcpSocket.aidl \
@@ -123,14 +125,15 @@
 	core/java/android/os/IHardwareService.aidl \
 	core/java/android/os/IMessenger.aidl \
 	core/java/android/os/INetworkManagementService.aidl \
-	core/java/android/os/INetStatService.aidl \
 	core/java/android/os/IPermissionController.aidl \
 	core/java/android/os/IPowerManager.aidl \
-    core/java/android/os/IRemoteCallback.aidl \
+	core/java/android/os/IRemoteCallback.aidl \
 	core/java/android/os/IVibratorService.aidl \
-    core/java/android/service/wallpaper/IWallpaperConnection.aidl \
-    core/java/android/service/wallpaper/IWallpaperEngine.aidl \
-    core/java/android/service/wallpaper/IWallpaperService.aidl \
+	core/java/android/service/wallpaper/IWallpaperConnection.aidl \
+	core/java/android/service/wallpaper/IWallpaperEngine.aidl \
+	core/java/android/service/wallpaper/IWallpaperService.aidl \
+	core/java/android/view/accessibility/IAccessibilityInteractionConnection.aidl\
+	core/java/android/view/accessibility/IAccessibilityInteractionConnectionCallback.aidl\
 	core/java/android/view/accessibility/IAccessibilityManager.aidl \
 	core/java/android/view/accessibility/IAccessibilityManagerClient.aidl \
 	core/java/android/view/IApplicationToken.aidl \
@@ -162,7 +165,7 @@
 	core/java/com/android/internal/view/IInputMethodSession.aidl \
 	core/java/com/android/internal/widget/IRemoteViewsFactory.aidl \
 	core/java/com/android/internal/widget/IRemoteViewsAdapterConnection.aidl \
-	keystore/java/android/security/IKeyChainAliasResponse.aidl \
+	keystore/java/android/security/IKeyChainAliasCallback.aidl \
 	keystore/java/android/security/IKeyChainService.aidl \
 	location/java/android/location/ICountryDetector.aidl \
 	location/java/android/location/ICountryListener.aidl \
@@ -379,8 +382,12 @@
 		            resources/samples/AccessibilityService "Accessibility Service" \
 		-samplecode $(sample_dir)/AccelerometerPlay \
 		            resources/samples/AccelerometerPlay "Accelerometer Play" \
-	  -samplecode $(sample_dir)/ApiDemos \
+		-samplecode $(sample_dir)/ApiDemos \
 		            resources/samples/ApiDemos "API Demos" \
+		-samplecode $(sample_dir)/Support4Demos \
+		            resources/samples/Support4Demos "API 4+ Support Demos" \
+		-samplecode $(sample_dir)/Support13Demos \
+		            resources/samples/Support13Demos "API 13+ Support Demos" \
 		-samplecode $(sample_dir)/BackupRestore \
 		            resources/samples/BackupRestore "Backup and Restore" \
 		-samplecode $(sample_dir)/BluetoothChat \
diff --git a/CleanSpec.mk b/CleanSpec.mk
index b19bed0..8d34636 100644
--- a/CleanSpec.mk
+++ b/CleanSpec.mk
@@ -98,6 +98,8 @@
 $(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/framework_intermediates/src/core/java/android/nfc)
 $(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/framework_intermediates)
 $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libstagefright_intermediates)
+$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/framework_intermediates/src/core/java/android/os)
+$(call add-clean-step, rm -rf $(OUT_DIR)target/common/obj/JAVA_LIBRARIES/framework_intermediates/src/keystore/java/android/security/IKeyChainAliasResponse.java)
 # ************************************************
 # NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
 # ************************************************
diff --git a/api/13.xml b/api/13.xml
index ff279e1..9af0640 100644
--- a/api/13.xml
+++ b/api/13.xml
@@ -1024,6 +1024,17 @@
  visibility="public"
 >
 </field>
+<field name="SET_POINTER_SPEED"
+ type="java.lang.String"
+ transient="false"
+ volatile="false"
+ value="&quot;android.permission.SET_POINTER_SPEED&quot;"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="SET_PREFERRED_APPLICATIONS"
  type="java.lang.String"
  transient="false"
@@ -3128,6 +3139,17 @@
  visibility="public"
 >
 </field>
+<field name="compatibleWidthLimitDp"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16843621"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="completionHint"
  type="int"
  transient="false"
@@ -5878,6 +5900,17 @@
  visibility="public"
 >
 </field>
+<field name="largestWidthLimitDp"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16843622"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="launchMode"
  type="int"
  transient="false"
@@ -7913,6 +7946,17 @@
  visibility="public"
 >
 </field>
+<field name="requiresSmallestWidthDp"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16843620"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="resizeMode"
  type="int"
  transient="false"
@@ -15164,6 +15208,325 @@
  visibility="public"
 >
 </field>
+<field name="TextAppearance_Holo"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16974075"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="TextAppearance_Holo_DialogWindowTitle"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16974103"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="TextAppearance_Holo_Inverse"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16974076"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="TextAppearance_Holo_Large"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16974077"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="TextAppearance_Holo_Large_Inverse"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16974078"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="TextAppearance_Holo_Medium"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16974079"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="TextAppearance_Holo_Medium_Inverse"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16974080"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="TextAppearance_Holo_SearchResult_Subtitle"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16974084"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="TextAppearance_Holo_SearchResult_Title"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16974083"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="TextAppearance_Holo_Small"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16974081"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="TextAppearance_Holo_Small_Inverse"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16974082"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="TextAppearance_Holo_Widget"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16974085"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="TextAppearance_Holo_Widget_ActionBar_Subtitle"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16974099"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="TextAppearance_Holo_Widget_ActionBar_Title"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16974098"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="TextAppearance_Holo_Widget_ActionMode_Subtitle"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16974101"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="TextAppearance_Holo_Widget_ActionMode_Title"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16974100"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="TextAppearance_Holo_Widget_Button"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16974086"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="TextAppearance_Holo_Widget_DropDownHint"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16974091"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="TextAppearance_Holo_Widget_DropDownItem"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16974092"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="TextAppearance_Holo_Widget_EditText"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16974094"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="TextAppearance_Holo_Widget_IconMenu_Item"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16974087"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="TextAppearance_Holo_Widget_PopupMenu"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16974095"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="TextAppearance_Holo_Widget_PopupMenu_Large"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16974096"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="TextAppearance_Holo_Widget_PopupMenu_Small"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16974097"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="TextAppearance_Holo_Widget_TabWidget"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16974088"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="TextAppearance_Holo_Widget_TextView"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16974089"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="TextAppearance_Holo_Widget_TextView_PopupMenu"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16974090"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="TextAppearance_Holo_Widget_TextView_SpinnerItem"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16974093"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="TextAppearance_Holo_WindowTitle"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16974102"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="TextAppearance_Inverse"
  type="int"
  transient="false"
@@ -15670,6 +16033,28 @@
  visibility="public"
 >
 </field>
+<field name="Theme_Holo_Light_NoActionBar"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16974064"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="Theme_Holo_Light_NoActionBar_Fullscreen"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16974065"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="Theme_Holo_Light_Panel"
  type="int"
  transient="false"
@@ -15978,6 +16363,39 @@
  visibility="public"
 >
 </field>
+<field name="Widget_ActionBar_TabBar"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16974068"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="Widget_ActionBar_TabText"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16974067"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="Widget_ActionBar_TabView"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16974066"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="Widget_ActionButton"
  type="int"
  transient="false"
@@ -16231,6 +16649,39 @@
  visibility="public"
 >
 </field>
+<field name="Widget_Holo_ActionBar_TabBar"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16974071"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="Widget_Holo_ActionBar_TabText"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16974070"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="Widget_Holo_ActionBar_TabView"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16974069"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="Widget_Holo_ActionButton"
  type="int"
  transient="false"
@@ -16506,6 +16957,39 @@
  visibility="public"
 >
 </field>
+<field name="Widget_Holo_Light_ActionBar_TabBar"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16974074"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="Widget_Holo_Light_ActionBar_TabText"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16974073"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="Widget_Holo_Light_ActionBar_TabView"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16974072"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="Widget_Holo_Light_ActionButton"
  type="int"
  transient="false"
@@ -22707,7 +23191,7 @@
  synchronized="false"
  static="false"
  final="true"
- deprecated="not deprecated"
+ deprecated="deprecated"
  visibility="public"
 >
 <parameter name="id" type="int">
@@ -22981,7 +23465,7 @@
  synchronized="false"
  static="false"
  final="false"
- deprecated="not deprecated"
+ deprecated="deprecated"
  visibility="public"
 >
 </method>
@@ -23434,7 +23918,7 @@
  synchronized="false"
  static="false"
  final="false"
- deprecated="not deprecated"
+ deprecated="deprecated"
  visibility="protected"
 >
 <parameter name="id" type="int">
@@ -23798,7 +24282,7 @@
  synchronized="false"
  static="false"
  final="false"
- deprecated="not deprecated"
+ deprecated="deprecated"
  visibility="protected"
 >
 <parameter name="id" type="int">
@@ -23880,7 +24364,7 @@
  synchronized="false"
  static="false"
  final="false"
- deprecated="not deprecated"
+ deprecated="deprecated"
  visibility="public"
 >
 </method>
@@ -24102,7 +24586,7 @@
  synchronized="false"
  static="false"
  final="true"
- deprecated="not deprecated"
+ deprecated="deprecated"
  visibility="public"
 >
 <parameter name="id" type="int">
@@ -24452,7 +24936,7 @@
  synchronized="false"
  static="false"
  final="true"
- deprecated="not deprecated"
+ deprecated="deprecated"
  visibility="public"
 >
 <parameter name="id" type="int">
@@ -24465,7 +24949,7 @@
  synchronized="false"
  static="false"
  final="true"
- deprecated="not deprecated"
+ deprecated="deprecated"
  visibility="public"
 >
 <parameter name="id" type="int">
@@ -30529,6 +31013,21 @@
  visibility="public"
 >
 </method>
+<method name="onViewCreated"
+ return="void"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="view" type="android.view.View">
+</parameter>
+<parameter name="savedInstanceState" type="android.os.Bundle">
+</parameter>
+</method>
 <method name="registerForContextMenu"
  return="void"
  abstract="false"
@@ -30568,6 +31067,19 @@
 <parameter name="hasMenu" type="boolean">
 </parameter>
 </method>
+<method name="setInitialSavedState"
+ return="void"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="state" type="android.app.Fragment.SavedState">
+</parameter>
+</method>
 <method name="setRetainInstance"
  return="void"
  abstract="false"
@@ -30659,6 +31171,53 @@
 </parameter>
 </constructor>
 </class>
+<class name="Fragment.SavedState"
+ extends="java.lang.Object"
+ abstract="false"
+ static="true"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<implements name="android.os.Parcelable">
+</implements>
+<method name="describeContents"
+ return="int"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
+<method name="writeToParcel"
+ return="void"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="dest" type="android.os.Parcel">
+</parameter>
+<parameter name="flags" type="int">
+</parameter>
+</method>
+<field name="CREATOR"
+ type="android.os.Parcelable.ClassLoaderCreator"
+ transient="false"
+ volatile="false"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+</class>
 <class name="FragmentBreadCrumbs"
  extends="android.view.ViewGroup"
  abstract="false"
@@ -31092,6 +31651,19 @@
 <parameter name="listener" type="android.app.FragmentManager.OnBackStackChangedListener">
 </parameter>
 </method>
+<method name="saveFragmentInstanceState"
+ return="android.app.Fragment.SavedState"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="f" type="android.app.Fragment">
+</parameter>
+</method>
 <field name="POP_BACK_STACK_INCLUSIVE"
  type="int"
  transient="false"
@@ -31262,6 +31834,19 @@
 <parameter name="name" type="java.lang.String">
 </parameter>
 </method>
+<method name="attach"
+ return="android.app.FragmentTransaction"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="fragment" type="android.app.Fragment">
+</parameter>
+</method>
 <method name="commit"
  return="int"
  abstract="true"
@@ -31284,6 +31869,19 @@
  visibility="public"
 >
 </method>
+<method name="detach"
+ return="android.app.FragmentTransaction"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="fragment" type="android.app.Fragment">
+</parameter>
+</method>
 <method name="disallowAddToBackStack"
  return="android.app.FragmentTransaction"
  abstract="true"
@@ -31442,6 +32040,25 @@
 <parameter name="exit" type="int">
 </parameter>
 </method>
+<method name="setCustomAnimations"
+ return="android.app.FragmentTransaction"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="enter" type="int">
+</parameter>
+<parameter name="exit" type="int">
+</parameter>
+<parameter name="popEnter" type="int">
+</parameter>
+<parameter name="popExit" type="int">
+</parameter>
+</method>
 <method name="setTransition"
  return="android.app.FragmentTransaction"
  abstract="true"
@@ -32623,7 +33240,7 @@
  synchronized="false"
  static="false"
  final="false"
- deprecated="not deprecated"
+ deprecated="deprecated"
  visibility="public"
 >
 <parameter name="callback" type="android.app.KeyguardManager.OnKeyguardExitResult">
@@ -32647,7 +33264,7 @@
  synchronized="false"
  static="false"
  final="false"
- deprecated="not deprecated"
+ deprecated="deprecated"
  visibility="public"
 >
 <parameter name="tag" type="java.lang.String">
@@ -32659,7 +33276,7 @@
  abstract="false"
  static="false"
  final="false"
- deprecated="not deprecated"
+ deprecated="deprecated"
  visibility="public"
 >
 <method name="disableKeyguard"
@@ -57840,6 +58457,28 @@
  visibility="public"
 >
 </field>
+<field name="CONFIG_SCREEN_SIZE"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="1024"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="CONFIG_SMALLEST_SCREEN_SIZE"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="2048"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="CONFIG_TOUCHSCREEN"
  type="int"
  transient="false"
@@ -58588,6 +59227,16 @@
  visibility="public"
 >
 </field>
+<field name="compatibleWidthLimitDp"
+ type="int"
+ transient="false"
+ volatile="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="dataDir"
  type="java.lang.String"
  transient="false"
@@ -58628,6 +59277,16 @@
  visibility="public"
 >
 </field>
+<field name="largestWidthLimitDp"
+ type="int"
+ transient="false"
+ volatile="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="manageSpaceActivityName"
  type="java.lang.String"
  transient="false"
@@ -58678,6 +59337,16 @@
  visibility="public"
 >
 </field>
+<field name="requiresSmallestWidthDp"
+ type="int"
+ transient="false"
+ volatile="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="sharedLibraryFiles"
  type="java.lang.String[]"
  transient="false"
@@ -61053,6 +61722,28 @@
  visibility="public"
 >
 </field>
+<field name="FEATURE_FAKETOUCH_MULTITOUCH_DISTINCT"
+ type="java.lang.String"
+ transient="false"
+ volatile="false"
+ value="&quot;android.hardware.faketouch.multitouch.distinct&quot;"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="FEATURE_FAKETOUCH_MULTITOUCH_JAZZHAND"
+ type="java.lang.String"
+ transient="false"
+ volatile="false"
+ value="&quot;android.hardware.faketouch.multitouch.jazzhand&quot;"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="FEATURE_LIVE_WALLPAPER"
  type="java.lang.String"
  transient="false"
@@ -63902,6 +64593,39 @@
  visibility="public"
 >
 </field>
+<field name="SCREEN_HEIGHT_DP_UNDEFINED"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="0"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="SCREEN_WIDTH_DP_UNDEFINED"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="0"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="SMALLEST_SCREEN_WIDTH_DP_UNDEFINED"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="0"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="TOUCHSCREEN_FINGER"
  type="int"
  transient="false"
@@ -64034,6 +64758,17 @@
  visibility="public"
 >
 </field>
+<field name="UI_MODE_TYPE_TELEVISION"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="4"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="UI_MODE_TYPE_UNDEFINED"
  type="int"
  transient="false"
@@ -64145,6 +64880,16 @@
  visibility="public"
 >
 </field>
+<field name="screenHeightDp"
+ type="int"
+ transient="false"
+ volatile="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="screenLayout"
  type="int"
  transient="false"
@@ -64155,6 +64900,26 @@
  visibility="public"
 >
 </field>
+<field name="screenWidthDp"
+ type="int"
+ transient="false"
+ volatile="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="smallestScreenWidthDp"
+ type="int"
+ transient="false"
+ volatile="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="touchscreen"
  type="int"
  transient="false"
@@ -84584,6 +85349,8 @@
  deprecated="not deprecated"
  visibility="public"
 >
+<implements name="android.os.Parcelable">
+</implements>
 <constructor name="Point"
  type="android.graphics.Point"
  static="false"
@@ -84614,6 +85381,17 @@
 <parameter name="src" type="android.graphics.Point">
 </parameter>
 </constructor>
+<method name="describeContents"
+ return="int"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
 <method name="equals"
  return="boolean"
  abstract="false"
@@ -84655,6 +85433,19 @@
 <parameter name="dy" type="int">
 </parameter>
 </method>
+<method name="readFromParcel"
+ return="void"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="in" type="android.os.Parcel">
+</parameter>
+</method>
 <method name="set"
  return="void"
  abstract="false"
@@ -84670,6 +85461,31 @@
 <parameter name="y" type="int">
 </parameter>
 </method>
+<method name="writeToParcel"
+ return="void"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="out" type="android.os.Parcel">
+</parameter>
+<parameter name="flags" type="int">
+</parameter>
+</method>
+<field name="CREATOR"
+ type="android.os.Parcelable.Creator"
+ transient="false"
+ volatile="false"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="x"
  type="int"
  transient="false"
@@ -84699,6 +85515,8 @@
  deprecated="not deprecated"
  visibility="public"
 >
+<implements name="android.os.Parcelable">
+</implements>
 <constructor name="PointF"
  type="android.graphics.PointF"
  static="false"
@@ -84729,6 +85547,17 @@
 <parameter name="p" type="android.graphics.Point">
 </parameter>
 </constructor>
+<method name="describeContents"
+ return="int"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
 <method name="equals"
  return="boolean"
  abstract="false"
@@ -84796,6 +85625,19 @@
 <parameter name="dy" type="float">
 </parameter>
 </method>
+<method name="readFromParcel"
+ return="void"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="in" type="android.os.Parcel">
+</parameter>
+</method>
 <method name="set"
  return="void"
  abstract="false"
@@ -84824,6 +85666,31 @@
 <parameter name="p" type="android.graphics.PointF">
 </parameter>
 </method>
+<method name="writeToParcel"
+ return="void"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="out" type="android.os.Parcel">
+</parameter>
+<parameter name="flags" type="int">
+</parameter>
+</method>
+<field name="CREATOR"
+ type="android.os.Parcelable.Creator"
+ transient="false"
+ volatile="false"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="x"
  type="float"
  transient="false"
@@ -95253,6 +96120,17 @@
  visibility="public"
 >
 </method>
+<method name="getRawDescriptors"
+ return="byte[]"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
 <method name="getSerial"
  return="java.lang.String"
  abstract="false"
@@ -114060,6 +114938,28 @@
  visibility="public"
 >
 </field>
+<field name="TYPE_BLUETOOTH"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="7"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="TYPE_ETHERNET"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="9"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="TYPE_MOBILE"
  type="int"
  transient="false"
@@ -143402,6 +144302,21 @@
 <parameter name="args" type="java.lang.String[]">
 </parameter>
 </method>
+<method name="dumpAsync"
+ return="void"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="fd" type="java.io.FileDescriptor">
+</parameter>
+<parameter name="args" type="java.lang.String[]">
+</parameter>
+</method>
 <method name="flushPendingCommands"
  return="void"
  abstract="false"
@@ -144032,6 +144947,17 @@
  visibility="public"
 >
 </field>
+<field name="HONEYCOMB_MR2"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="13"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 </class>
 <class name="Bundle"
  extends="java.lang.Object"
@@ -147863,6 +148789,23 @@
 <exception name="RemoteException" type="android.os.RemoteException">
 </exception>
 </method>
+<method name="dumpAsync"
+ return="void"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="fd" type="java.io.FileDescriptor">
+</parameter>
+<parameter name="args" type="java.lang.String[]">
+</parameter>
+<exception name="RemoteException" type="android.os.RemoteException">
+</exception>
+</method>
 <method name="getInterfaceDescriptor"
  return="java.lang.String"
  abstract="true"
@@ -150169,6 +151112,19 @@
 <parameter name="descriptor" type="android.os.ParcelFileDescriptor">
 </parameter>
 </constructor>
+<method name="adoptFd"
+ return="android.os.ParcelFileDescriptor"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="true"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="fd" type="int">
+</parameter>
+</method>
 <method name="close"
  return="void"
  abstract="false"
@@ -150217,6 +151173,36 @@
  visibility="public"
 >
 </method>
+<method name="dup"
+ return="android.os.ParcelFileDescriptor"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="true"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="orig" type="java.io.FileDescriptor">
+</parameter>
+<exception name="IOException" type="java.io.IOException">
+</exception>
+</method>
+<method name="fromFd"
+ return="android.os.ParcelFileDescriptor"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="true"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="fd" type="int">
+</parameter>
+<exception name="IOException" type="java.io.IOException">
+</exception>
+</method>
 <method name="fromSocket"
  return="android.os.ParcelFileDescriptor"
  abstract="false"
@@ -150596,6 +151582,31 @@
 >
 </field>
 </interface>
+<interface name="Parcelable.ClassLoaderCreator"
+ abstract="true"
+ static="true"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<implements name="android.os.Parcelable.Creator">
+</implements>
+<method name="createFromParcel"
+ return="T"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="source" type="android.os.Parcel">
+</parameter>
+<parameter name="loader" type="java.lang.ClassLoader">
+</parameter>
+</method>
+</interface>
 <interface name="Parcelable.Creator"
  abstract="true"
  static="true"
@@ -150893,7 +151904,7 @@
  value="10"
  static="true"
  final="true"
- deprecated="not deprecated"
+ deprecated="deprecated"
  visibility="public"
 >
 </field>
@@ -184155,6 +185166,17 @@
  visibility="public"
 >
 </field>
+<field name="NETWORK_TYPE_HSPAP"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="15"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="NETWORK_TYPE_HSUPA"
  type="int"
  transient="false"
@@ -205789,6 +206811,17 @@
  visibility="public"
 >
 </field>
+<field name="DENSITY_TV"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="213"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="DENSITY_XHIGH"
  type="int"
  transient="false"
@@ -209950,11 +210983,11 @@
 <method name="getHeight"
  return="int"
  abstract="false"
- native="true"
+ native="false"
  synchronized="false"
  static="false"
  final="false"
- deprecated="not deprecated"
+ deprecated="deprecated"
  visibility="public"
 >
 </method>
@@ -209993,6 +211026,19 @@
  visibility="public"
 >
 </method>
+<method name="getRectSize"
+ return="void"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="outSize" type="android.graphics.Rect">
+</parameter>
+</method>
 <method name="getRefreshRate"
  return="float"
  abstract="false"
@@ -210015,16 +211061,29 @@
  visibility="public"
 >
 </method>
-<method name="getWidth"
- return="int"
+<method name="getSize"
+ return="void"
  abstract="false"
- native="true"
+ native="false"
  synchronized="false"
  static="false"
  final="false"
  deprecated="not deprecated"
  visibility="public"
 >
+<parameter name="outSize" type="android.graphics.Point">
+</parameter>
+</method>
+<method name="getWidth"
+ return="int"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="deprecated"
+ visibility="public"
+>
 </method>
 <field name="DEFAULT_DISPLAY"
  type="int"
@@ -212742,6 +213801,17 @@
  visibility="public"
 >
 </method>
+<method name="getModifiers"
+ return="int"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
 <method name="getNumber"
  return="char"
  abstract="false"
@@ -220966,7 +222036,7 @@
  deprecated="not deprecated"
  visibility="public"
 >
-<parameter name="ev" type="android.view.MotionEvent">
+<parameter name="event" type="android.view.MotionEvent">
 </parameter>
 </method>
 <method name="clear"
diff --git a/api/14.txt b/api/14.txt
index b080d25..050540b 100644
--- a/api/14.txt
+++ b/api/14.txt
@@ -1921,12 +1921,12 @@
 
   public class FloatEvaluator implements android.animation.TypeEvaluator {
     ctor public FloatEvaluator();
-    method public java.lang.Object evaluate(float, java.lang.Object, java.lang.Object);
+    method public java.lang.Float evaluate(float, java.lang.Number, java.lang.Number);
   }
 
   public class IntEvaluator implements android.animation.TypeEvaluator {
     ctor public IntEvaluator();
-    method public java.lang.Object evaluate(float, java.lang.Object, java.lang.Object);
+    method public java.lang.Integer evaluate(float, java.lang.Integer, java.lang.Integer);
   }
 
   public abstract class Keyframe implements java.lang.Cloneable {
@@ -2012,7 +2012,7 @@
   }
 
   public abstract interface TypeEvaluator {
-    method public abstract java.lang.Object evaluate(float, java.lang.Object, java.lang.Object);
+    method public abstract T evaluate(float, T, T);
   }
 
   public class ValueAnimator extends android.animation.Animator {
@@ -6273,6 +6273,9 @@
   public static final class CursorJoiner.Result extends java.lang.Enum {
     method public static android.database.CursorJoiner.Result valueOf(java.lang.String);
     method public static final android.database.CursorJoiner.Result[] values();
+    enum_constant public static final android.database.CursorJoiner.Result BOTH;
+    enum_constant public static final android.database.CursorJoiner.Result LEFT;
+    enum_constant public static final android.database.CursorJoiner.Result RIGHT;
   }
 
   public class CursorWindow extends android.database.sqlite.SQLiteClosable implements android.os.Parcelable {
@@ -7191,6 +7194,8 @@
   public static final class AvoidXfermode.Mode extends java.lang.Enum {
     method public static android.graphics.AvoidXfermode.Mode valueOf(java.lang.String);
     method public static final android.graphics.AvoidXfermode.Mode[] values();
+    enum_constant public static final android.graphics.AvoidXfermode.Mode AVOID;
+    enum_constant public static final android.graphics.AvoidXfermode.Mode TARGET;
   }
 
   public final class Bitmap implements android.os.Parcelable {
@@ -7243,11 +7248,17 @@
   public static final class Bitmap.CompressFormat extends java.lang.Enum {
     method public static android.graphics.Bitmap.CompressFormat valueOf(java.lang.String);
     method public static final android.graphics.Bitmap.CompressFormat[] values();
+    enum_constant public static final android.graphics.Bitmap.CompressFormat JPEG;
+    enum_constant public static final android.graphics.Bitmap.CompressFormat PNG;
   }
 
   public static final class Bitmap.Config extends java.lang.Enum {
     method public static android.graphics.Bitmap.Config valueOf(java.lang.String);
     method public static final android.graphics.Bitmap.Config[] values();
+    enum_constant public static final android.graphics.Bitmap.Config ALPHA_8;
+    enum_constant public static final deprecated android.graphics.Bitmap.Config ARGB_4444;
+    enum_constant public static final android.graphics.Bitmap.Config ARGB_8888;
+    enum_constant public static final android.graphics.Bitmap.Config RGB_565;
   }
 
   public class BitmapFactory {
@@ -7311,6 +7322,10 @@
   public static final class BlurMaskFilter.Blur extends java.lang.Enum {
     method public static android.graphics.BlurMaskFilter.Blur valueOf(java.lang.String);
     method public static final android.graphics.BlurMaskFilter.Blur[] values();
+    enum_constant public static final android.graphics.BlurMaskFilter.Blur INNER;
+    enum_constant public static final android.graphics.BlurMaskFilter.Blur NORMAL;
+    enum_constant public static final android.graphics.BlurMaskFilter.Blur OUTER;
+    enum_constant public static final android.graphics.BlurMaskFilter.Blur SOLID;
   }
 
   public class Camera {
@@ -7424,11 +7439,16 @@
   public static final class Canvas.EdgeType extends java.lang.Enum {
     method public static android.graphics.Canvas.EdgeType valueOf(java.lang.String);
     method public static final android.graphics.Canvas.EdgeType[] values();
+    enum_constant public static final android.graphics.Canvas.EdgeType AA;
+    enum_constant public static final android.graphics.Canvas.EdgeType BW;
   }
 
   public static final class Canvas.VertexMode extends java.lang.Enum {
     method public static android.graphics.Canvas.VertexMode valueOf(java.lang.String);
     method public static final android.graphics.Canvas.VertexMode[] values();
+    enum_constant public static final android.graphics.Canvas.VertexMode TRIANGLES;
+    enum_constant public static final android.graphics.Canvas.VertexMode TRIANGLE_FAN;
+    enum_constant public static final android.graphics.Canvas.VertexMode TRIANGLE_STRIP;
   }
 
   public class Color {
@@ -7543,6 +7563,9 @@
   public static final class Interpolator.Result extends java.lang.Enum {
     method public static android.graphics.Interpolator.Result valueOf(java.lang.String);
     method public static final android.graphics.Interpolator.Result[] values();
+    enum_constant public static final android.graphics.Interpolator.Result FREEZE_END;
+    enum_constant public static final android.graphics.Interpolator.Result FREEZE_START;
+    enum_constant public static final android.graphics.Interpolator.Result NORMAL;
   }
 
   public class LayerRasterizer extends android.graphics.Rasterizer {
@@ -7626,6 +7649,10 @@
   public static final class Matrix.ScaleToFit extends java.lang.Enum {
     method public static android.graphics.Matrix.ScaleToFit valueOf(java.lang.String);
     method public static final android.graphics.Matrix.ScaleToFit[] values();
+    enum_constant public static final android.graphics.Matrix.ScaleToFit CENTER;
+    enum_constant public static final android.graphics.Matrix.ScaleToFit END;
+    enum_constant public static final android.graphics.Matrix.ScaleToFit FILL;
+    enum_constant public static final android.graphics.Matrix.ScaleToFit START;
   }
 
   public class Movie {
@@ -7755,11 +7782,17 @@
   public static final class Paint.Align extends java.lang.Enum {
     method public static android.graphics.Paint.Align valueOf(java.lang.String);
     method public static final android.graphics.Paint.Align[] values();
+    enum_constant public static final android.graphics.Paint.Align CENTER;
+    enum_constant public static final android.graphics.Paint.Align LEFT;
+    enum_constant public static final android.graphics.Paint.Align RIGHT;
   }
 
   public static final class Paint.Cap extends java.lang.Enum {
     method public static android.graphics.Paint.Cap valueOf(java.lang.String);
     method public static final android.graphics.Paint.Cap[] values();
+    enum_constant public static final android.graphics.Paint.Cap BUTT;
+    enum_constant public static final android.graphics.Paint.Cap ROUND;
+    enum_constant public static final android.graphics.Paint.Cap SQUARE;
   }
 
   public static class Paint.FontMetrics {
@@ -7783,11 +7816,17 @@
   public static final class Paint.Join extends java.lang.Enum {
     method public static android.graphics.Paint.Join valueOf(java.lang.String);
     method public static final android.graphics.Paint.Join[] values();
+    enum_constant public static final android.graphics.Paint.Join BEVEL;
+    enum_constant public static final android.graphics.Paint.Join MITER;
+    enum_constant public static final android.graphics.Paint.Join ROUND;
   }
 
   public static final class Paint.Style extends java.lang.Enum {
     method public static android.graphics.Paint.Style valueOf(java.lang.String);
     method public static final android.graphics.Paint.Style[] values();
+    enum_constant public static final android.graphics.Paint.Style FILL;
+    enum_constant public static final android.graphics.Paint.Style FILL_AND_STROKE;
+    enum_constant public static final android.graphics.Paint.Style STROKE;
   }
 
   public class PaintFlagsDrawFilter extends android.graphics.DrawFilter {
@@ -7839,11 +7878,17 @@
   public static final class Path.Direction extends java.lang.Enum {
     method public static android.graphics.Path.Direction valueOf(java.lang.String);
     method public static final android.graphics.Path.Direction[] values();
+    enum_constant public static final android.graphics.Path.Direction CCW;
+    enum_constant public static final android.graphics.Path.Direction CW;
   }
 
   public static final class Path.FillType extends java.lang.Enum {
     method public static android.graphics.Path.FillType valueOf(java.lang.String);
     method public static final android.graphics.Path.FillType[] values();
+    enum_constant public static final android.graphics.Path.FillType EVEN_ODD;
+    enum_constant public static final android.graphics.Path.FillType INVERSE_EVEN_ODD;
+    enum_constant public static final android.graphics.Path.FillType INVERSE_WINDING;
+    enum_constant public static final android.graphics.Path.FillType WINDING;
   }
 
   public class PathDashPathEffect extends android.graphics.PathEffect {
@@ -7853,6 +7898,9 @@
   public static final class PathDashPathEffect.Style extends java.lang.Enum {
     method public static android.graphics.PathDashPathEffect.Style valueOf(java.lang.String);
     method public static final android.graphics.PathDashPathEffect.Style[] values();
+    enum_constant public static final android.graphics.PathDashPathEffect.Style MORPH;
+    enum_constant public static final android.graphics.PathDashPathEffect.Style ROTATE;
+    enum_constant public static final android.graphics.PathDashPathEffect.Style TRANSLATE;
   }
 
   public class PathEffect {
@@ -7949,6 +7997,24 @@
   public static final class PorterDuff.Mode extends java.lang.Enum {
     method public static android.graphics.PorterDuff.Mode valueOf(java.lang.String);
     method public static final android.graphics.PorterDuff.Mode[] values();
+    enum_constant public static final android.graphics.PorterDuff.Mode ADD;
+    enum_constant public static final android.graphics.PorterDuff.Mode CLEAR;
+    enum_constant public static final android.graphics.PorterDuff.Mode DARKEN;
+    enum_constant public static final android.graphics.PorterDuff.Mode DST;
+    enum_constant public static final android.graphics.PorterDuff.Mode DST_ATOP;
+    enum_constant public static final android.graphics.PorterDuff.Mode DST_IN;
+    enum_constant public static final android.graphics.PorterDuff.Mode DST_OUT;
+    enum_constant public static final android.graphics.PorterDuff.Mode DST_OVER;
+    enum_constant public static final android.graphics.PorterDuff.Mode LIGHTEN;
+    enum_constant public static final android.graphics.PorterDuff.Mode MULTIPLY;
+    enum_constant public static final android.graphics.PorterDuff.Mode OVERLAY;
+    enum_constant public static final android.graphics.PorterDuff.Mode SCREEN;
+    enum_constant public static final android.graphics.PorterDuff.Mode SRC;
+    enum_constant public static final android.graphics.PorterDuff.Mode SRC_ATOP;
+    enum_constant public static final android.graphics.PorterDuff.Mode SRC_IN;
+    enum_constant public static final android.graphics.PorterDuff.Mode SRC_OUT;
+    enum_constant public static final android.graphics.PorterDuff.Mode SRC_OVER;
+    enum_constant public static final android.graphics.PorterDuff.Mode XOR;
   }
 
   public class PorterDuffColorFilter extends android.graphics.ColorFilter {
@@ -8090,6 +8156,12 @@
   public static final class Region.Op extends java.lang.Enum {
     method public static android.graphics.Region.Op valueOf(java.lang.String);
     method public static final android.graphics.Region.Op[] values();
+    enum_constant public static final android.graphics.Region.Op DIFFERENCE;
+    enum_constant public static final android.graphics.Region.Op INTERSECT;
+    enum_constant public static final android.graphics.Region.Op REPLACE;
+    enum_constant public static final android.graphics.Region.Op REVERSE_DIFFERENCE;
+    enum_constant public static final android.graphics.Region.Op UNION;
+    enum_constant public static final android.graphics.Region.Op XOR;
   }
 
   public class RegionIterator {
@@ -8106,6 +8178,9 @@
   public static final class Shader.TileMode extends java.lang.Enum {
     method public static android.graphics.Shader.TileMode valueOf(java.lang.String);
     method public static final android.graphics.Shader.TileMode[] values();
+    enum_constant public static final android.graphics.Shader.TileMode CLAMP;
+    enum_constant public static final android.graphics.Shader.TileMode MIRROR;
+    enum_constant public static final android.graphics.Shader.TileMode REPEAT;
   }
 
   public class SumPathEffect extends android.graphics.PathEffect {
@@ -8380,6 +8455,14 @@
   public static final class GradientDrawable.Orientation extends java.lang.Enum {
     method public static android.graphics.drawable.GradientDrawable.Orientation valueOf(java.lang.String);
     method public static final android.graphics.drawable.GradientDrawable.Orientation[] values();
+    enum_constant public static final android.graphics.drawable.GradientDrawable.Orientation BL_TR;
+    enum_constant public static final android.graphics.drawable.GradientDrawable.Orientation BOTTOM_TOP;
+    enum_constant public static final android.graphics.drawable.GradientDrawable.Orientation BR_TL;
+    enum_constant public static final android.graphics.drawable.GradientDrawable.Orientation LEFT_RIGHT;
+    enum_constant public static final android.graphics.drawable.GradientDrawable.Orientation RIGHT_LEFT;
+    enum_constant public static final android.graphics.drawable.GradientDrawable.Orientation TL_BR;
+    enum_constant public static final android.graphics.drawable.GradientDrawable.Orientation TOP_BOTTOM;
+    enum_constant public static final android.graphics.drawable.GradientDrawable.Orientation TR_BL;
   }
 
   public class InsetDrawable extends android.graphics.drawable.Drawable implements android.graphics.drawable.Drawable.Callback {
@@ -10812,6 +10895,9 @@
   public static final class LocalSocketAddress.Namespace extends java.lang.Enum {
     method public static android.net.LocalSocketAddress.Namespace valueOf(java.lang.String);
     method public static final android.net.LocalSocketAddress.Namespace[] values();
+    enum_constant public static final android.net.LocalSocketAddress.Namespace ABSTRACT;
+    enum_constant public static final android.net.LocalSocketAddress.Namespace FILESYSTEM;
+    enum_constant public static final android.net.LocalSocketAddress.Namespace RESERVED;
   }
 
   public class MailTo {
@@ -10846,11 +10932,27 @@
   public static final class NetworkInfo.DetailedState extends java.lang.Enum {
     method public static android.net.NetworkInfo.DetailedState valueOf(java.lang.String);
     method public static final android.net.NetworkInfo.DetailedState[] values();
+    enum_constant public static final android.net.NetworkInfo.DetailedState AUTHENTICATING;
+    enum_constant public static final android.net.NetworkInfo.DetailedState CONNECTED;
+    enum_constant public static final android.net.NetworkInfo.DetailedState CONNECTING;
+    enum_constant public static final android.net.NetworkInfo.DetailedState DISCONNECTED;
+    enum_constant public static final android.net.NetworkInfo.DetailedState DISCONNECTING;
+    enum_constant public static final android.net.NetworkInfo.DetailedState FAILED;
+    enum_constant public static final android.net.NetworkInfo.DetailedState IDLE;
+    enum_constant public static final android.net.NetworkInfo.DetailedState OBTAINING_IPADDR;
+    enum_constant public static final android.net.NetworkInfo.DetailedState SCANNING;
+    enum_constant public static final android.net.NetworkInfo.DetailedState SUSPENDED;
   }
 
   public static final class NetworkInfo.State extends java.lang.Enum {
     method public static android.net.NetworkInfo.State valueOf(java.lang.String);
     method public static final android.net.NetworkInfo.State[] values();
+    enum_constant public static final android.net.NetworkInfo.State CONNECTED;
+    enum_constant public static final android.net.NetworkInfo.State CONNECTING;
+    enum_constant public static final android.net.NetworkInfo.State DISCONNECTED;
+    enum_constant public static final android.net.NetworkInfo.State DISCONNECTING;
+    enum_constant public static final android.net.NetworkInfo.State SUSPENDED;
+    enum_constant public static final android.net.NetworkInfo.State UNKNOWN;
   }
 
   public class ParseException extends java.lang.RuntimeException {
@@ -11363,6 +11465,17 @@
     method public static android.net.wifi.SupplicantState valueOf(java.lang.String);
     method public static final android.net.wifi.SupplicantState[] values();
     method public void writeToParcel(android.os.Parcel, int);
+    enum_constant public static final android.net.wifi.SupplicantState ASSOCIATED;
+    enum_constant public static final android.net.wifi.SupplicantState ASSOCIATING;
+    enum_constant public static final android.net.wifi.SupplicantState COMPLETED;
+    enum_constant public static final android.net.wifi.SupplicantState DISCONNECTED;
+    enum_constant public static final android.net.wifi.SupplicantState DORMANT;
+    enum_constant public static final android.net.wifi.SupplicantState FOUR_WAY_HANDSHAKE;
+    enum_constant public static final android.net.wifi.SupplicantState GROUP_HANDSHAKE;
+    enum_constant public static final android.net.wifi.SupplicantState INACTIVE;
+    enum_constant public static final android.net.wifi.SupplicantState INVALID;
+    enum_constant public static final android.net.wifi.SupplicantState SCANNING;
+    enum_constant public static final android.net.wifi.SupplicantState UNINITIALIZED;
   }
 
   public class WifiConfiguration implements android.os.Parcelable {
@@ -13184,6 +13297,9 @@
   public static final class AsyncTask.Status extends java.lang.Enum {
     method public static android.os.AsyncTask.Status valueOf(java.lang.String);
     method public static final android.os.AsyncTask.Status[] values();
+    enum_constant public static final android.os.AsyncTask.Status FINISHED;
+    enum_constant public static final android.os.AsyncTask.Status PENDING;
+    enum_constant public static final android.os.AsyncTask.Status RUNNING;
   }
 
   public class BadParcelableException extends android.util.AndroidRuntimeException {
@@ -14139,20 +14255,10 @@
 
 package android.preference {
 
-  public class CheckBoxPreference extends android.preference.Preference {
+    public class CheckBoxPreference extends android.preference.TwoStatePreference {
     ctor public CheckBoxPreference(android.content.Context, android.util.AttributeSet, int);
     ctor public CheckBoxPreference(android.content.Context, android.util.AttributeSet);
     ctor public CheckBoxPreference(android.content.Context);
-    method public boolean getDisableDependentsState();
-    method public java.lang.CharSequence getSummaryOff();
-    method public java.lang.CharSequence getSummaryOn();
-    method public boolean isChecked();
-    method public void setChecked(boolean);
-    method public void setDisableDependentsState(boolean);
-    method public void setSummaryOff(java.lang.CharSequence);
-    method public void setSummaryOff(int);
-    method public void setSummaryOn(java.lang.CharSequence);
-    method public void setSummaryOn(int);
   }
 
   public abstract class DialogPreference extends android.preference.Preference implements android.content.DialogInterface.OnClickListener android.content.DialogInterface.OnDismissListener android.preference.PreferenceManager.OnActivityDestroyListener {
@@ -16159,6 +16265,9 @@
   public static final class Allocation.MipmapControl extends java.lang.Enum {
     method public static android.renderscript.Allocation.MipmapControl valueOf(java.lang.String);
     method public static final android.renderscript.Allocation.MipmapControl[] values();
+    enum_constant public static final android.renderscript.Allocation.MipmapControl MIPMAP_FULL;
+    enum_constant public static final android.renderscript.Allocation.MipmapControl MIPMAP_NONE;
+    enum_constant public static final android.renderscript.Allocation.MipmapControl MIPMAP_ON_SYNC_TO_TEXTURE;
   }
 
   public class AllocationAdapter extends android.renderscript.Allocation {
@@ -16256,11 +16365,45 @@
   public static final class Element.DataKind extends java.lang.Enum {
     method public static android.renderscript.Element.DataKind valueOf(java.lang.String);
     method public static final android.renderscript.Element.DataKind[] values();
+    enum_constant public static final android.renderscript.Element.DataKind PIXEL_A;
+    enum_constant public static final android.renderscript.Element.DataKind PIXEL_DEPTH;
+    enum_constant public static final android.renderscript.Element.DataKind PIXEL_L;
+    enum_constant public static final android.renderscript.Element.DataKind PIXEL_LA;
+    enum_constant public static final android.renderscript.Element.DataKind PIXEL_RGB;
+    enum_constant public static final android.renderscript.Element.DataKind PIXEL_RGBA;
+    enum_constant public static final android.renderscript.Element.DataKind USER;
   }
 
   public static final class Element.DataType extends java.lang.Enum {
     method public static android.renderscript.Element.DataType valueOf(java.lang.String);
     method public static final android.renderscript.Element.DataType[] values();
+    enum_constant public static final android.renderscript.Element.DataType BOOLEAN;
+    enum_constant public static final android.renderscript.Element.DataType FLOAT_32;
+    enum_constant public static final android.renderscript.Element.DataType FLOAT_64;
+    enum_constant public static final android.renderscript.Element.DataType MATRIX_2X2;
+    enum_constant public static final android.renderscript.Element.DataType MATRIX_3X3;
+    enum_constant public static final android.renderscript.Element.DataType MATRIX_4X4;
+    enum_constant public static final android.renderscript.Element.DataType RS_ALLOCATION;
+    enum_constant public static final android.renderscript.Element.DataType RS_ELEMENT;
+    enum_constant public static final android.renderscript.Element.DataType RS_MESH;
+    enum_constant public static final android.renderscript.Element.DataType RS_PROGRAM_FRAGMENT;
+    enum_constant public static final android.renderscript.Element.DataType RS_PROGRAM_RASTER;
+    enum_constant public static final android.renderscript.Element.DataType RS_PROGRAM_STORE;
+    enum_constant public static final android.renderscript.Element.DataType RS_PROGRAM_VERTEX;
+    enum_constant public static final android.renderscript.Element.DataType RS_SAMPLER;
+    enum_constant public static final android.renderscript.Element.DataType RS_SCRIPT;
+    enum_constant public static final android.renderscript.Element.DataType RS_TYPE;
+    enum_constant public static final android.renderscript.Element.DataType SIGNED_16;
+    enum_constant public static final android.renderscript.Element.DataType SIGNED_32;
+    enum_constant public static final android.renderscript.Element.DataType SIGNED_64;
+    enum_constant public static final android.renderscript.Element.DataType SIGNED_8;
+    enum_constant public static final android.renderscript.Element.DataType UNSIGNED_16;
+    enum_constant public static final android.renderscript.Element.DataType UNSIGNED_32;
+    enum_constant public static final android.renderscript.Element.DataType UNSIGNED_4_4_4_4;
+    enum_constant public static final android.renderscript.Element.DataType UNSIGNED_5_5_5_1;
+    enum_constant public static final android.renderscript.Element.DataType UNSIGNED_5_6_5;
+    enum_constant public static final android.renderscript.Element.DataType UNSIGNED_64;
+    enum_constant public static final android.renderscript.Element.DataType UNSIGNED_8;
   }
 
   public class FieldPacker {
@@ -16320,6 +16463,8 @@
   public static final class FileA3D.EntryType extends java.lang.Enum {
     method public static android.renderscript.FileA3D.EntryType valueOf(java.lang.String);
     method public static final android.renderscript.FileA3D.EntryType[] values();
+    enum_constant public static final android.renderscript.FileA3D.EntryType MESH;
+    enum_constant public static final android.renderscript.FileA3D.EntryType UNKNOWN;
   }
 
   public static class FileA3D.IndexEntry {
@@ -16364,6 +16509,10 @@
   public static final class Font.Style extends java.lang.Enum {
     method public static android.renderscript.Font.Style valueOf(java.lang.String);
     method public static final android.renderscript.Font.Style[] values();
+    enum_constant public static final android.renderscript.Font.Style BOLD;
+    enum_constant public static final android.renderscript.Font.Style BOLD_ITALIC;
+    enum_constant public static final android.renderscript.Font.Style ITALIC;
+    enum_constant public static final android.renderscript.Font.Style NORMAL;
   }
 
   public class Int2 {
@@ -16507,6 +16656,12 @@
   public static final class Mesh.Primitive extends java.lang.Enum {
     method public static android.renderscript.Mesh.Primitive valueOf(java.lang.String);
     method public static final android.renderscript.Mesh.Primitive[] values();
+    enum_constant public static final android.renderscript.Mesh.Primitive LINE;
+    enum_constant public static final android.renderscript.Mesh.Primitive LINE_STRIP;
+    enum_constant public static final android.renderscript.Mesh.Primitive POINT;
+    enum_constant public static final android.renderscript.Mesh.Primitive TRIANGLE;
+    enum_constant public static final android.renderscript.Mesh.Primitive TRIANGLE_FAN;
+    enum_constant public static final android.renderscript.Mesh.Primitive TRIANGLE_STRIP;
   }
 
   public static class Mesh.TriangleMeshBuilder {
@@ -16543,6 +16698,8 @@
   public static final class Program.TextureType extends java.lang.Enum {
     method public static android.renderscript.Program.TextureType valueOf(java.lang.String);
     method public static final android.renderscript.Program.TextureType[] values();
+    enum_constant public static final android.renderscript.Program.TextureType TEXTURE_2D;
+    enum_constant public static final android.renderscript.Program.TextureType TEXTURE_CUBE;
   }
 
   public class ProgramFragment extends android.renderscript.Program {
@@ -16568,11 +16725,18 @@
   public static final class ProgramFragmentFixedFunction.Builder.EnvMode extends java.lang.Enum {
     method public static android.renderscript.ProgramFragmentFixedFunction.Builder.EnvMode valueOf(java.lang.String);
     method public static final android.renderscript.ProgramFragmentFixedFunction.Builder.EnvMode[] values();
+    enum_constant public static final android.renderscript.ProgramFragmentFixedFunction.Builder.EnvMode DECAL;
+    enum_constant public static final android.renderscript.ProgramFragmentFixedFunction.Builder.EnvMode MODULATE;
+    enum_constant public static final android.renderscript.ProgramFragmentFixedFunction.Builder.EnvMode REPLACE;
   }
 
   public static final class ProgramFragmentFixedFunction.Builder.Format extends java.lang.Enum {
     method public static android.renderscript.ProgramFragmentFixedFunction.Builder.Format valueOf(java.lang.String);
     method public static final android.renderscript.ProgramFragmentFixedFunction.Builder.Format[] values();
+    enum_constant public static final android.renderscript.ProgramFragmentFixedFunction.Builder.Format ALPHA;
+    enum_constant public static final android.renderscript.ProgramFragmentFixedFunction.Builder.Format LUMINANCE_ALPHA;
+    enum_constant public static final android.renderscript.ProgramFragmentFixedFunction.Builder.Format RGB;
+    enum_constant public static final android.renderscript.ProgramFragmentFixedFunction.Builder.Format RGBA;
   }
 
   public class ProgramRaster extends android.renderscript.BaseObj {
@@ -16591,6 +16755,9 @@
   public static final class ProgramRaster.CullMode extends java.lang.Enum {
     method public static android.renderscript.ProgramRaster.CullMode valueOf(java.lang.String);
     method public static final android.renderscript.ProgramRaster.CullMode[] values();
+    enum_constant public static final android.renderscript.ProgramRaster.CullMode BACK;
+    enum_constant public static final android.renderscript.ProgramRaster.CullMode FRONT;
+    enum_constant public static final android.renderscript.ProgramRaster.CullMode NONE;
   }
 
   public class ProgramStore extends android.renderscript.BaseObj {
@@ -16603,11 +16770,28 @@
   public static final class ProgramStore.BlendDstFunc extends java.lang.Enum {
     method public static android.renderscript.ProgramStore.BlendDstFunc valueOf(java.lang.String);
     method public static final android.renderscript.ProgramStore.BlendDstFunc[] values();
+    enum_constant public static final android.renderscript.ProgramStore.BlendDstFunc DST_ALPHA;
+    enum_constant public static final android.renderscript.ProgramStore.BlendDstFunc ONE;
+    enum_constant public static final android.renderscript.ProgramStore.BlendDstFunc ONE_MINUS_DST_ALPHA;
+    enum_constant public static final android.renderscript.ProgramStore.BlendDstFunc ONE_MINUS_SRC_ALPHA;
+    enum_constant public static final android.renderscript.ProgramStore.BlendDstFunc ONE_MINUS_SRC_COLOR;
+    enum_constant public static final android.renderscript.ProgramStore.BlendDstFunc SRC_ALPHA;
+    enum_constant public static final android.renderscript.ProgramStore.BlendDstFunc SRC_COLOR;
+    enum_constant public static final android.renderscript.ProgramStore.BlendDstFunc ZERO;
   }
 
   public static final class ProgramStore.BlendSrcFunc extends java.lang.Enum {
     method public static android.renderscript.ProgramStore.BlendSrcFunc valueOf(java.lang.String);
     method public static final android.renderscript.ProgramStore.BlendSrcFunc[] values();
+    enum_constant public static final android.renderscript.ProgramStore.BlendSrcFunc DST_ALPHA;
+    enum_constant public static final android.renderscript.ProgramStore.BlendSrcFunc DST_COLOR;
+    enum_constant public static final android.renderscript.ProgramStore.BlendSrcFunc ONE;
+    enum_constant public static final android.renderscript.ProgramStore.BlendSrcFunc ONE_MINUS_DST_ALPHA;
+    enum_constant public static final android.renderscript.ProgramStore.BlendSrcFunc ONE_MINUS_DST_COLOR;
+    enum_constant public static final android.renderscript.ProgramStore.BlendSrcFunc ONE_MINUS_SRC_ALPHA;
+    enum_constant public static final android.renderscript.ProgramStore.BlendSrcFunc SRC_ALPHA;
+    enum_constant public static final android.renderscript.ProgramStore.BlendSrcFunc SRC_ALPHA_SATURATE;
+    enum_constant public static final android.renderscript.ProgramStore.BlendSrcFunc ZERO;
   }
 
   public static class ProgramStore.Builder {
@@ -16623,6 +16807,13 @@
   public static final class ProgramStore.DepthFunc extends java.lang.Enum {
     method public static android.renderscript.ProgramStore.DepthFunc valueOf(java.lang.String);
     method public static final android.renderscript.ProgramStore.DepthFunc[] values();
+    enum_constant public static final android.renderscript.ProgramStore.DepthFunc ALWAYS;
+    enum_constant public static final android.renderscript.ProgramStore.DepthFunc EQUAL;
+    enum_constant public static final android.renderscript.ProgramStore.DepthFunc GREATER;
+    enum_constant public static final android.renderscript.ProgramStore.DepthFunc GREATER_OR_EQUAL;
+    enum_constant public static final android.renderscript.ProgramStore.DepthFunc LESS;
+    enum_constant public static final android.renderscript.ProgramStore.DepthFunc LESS_OR_EQUAL;
+    enum_constant public static final android.renderscript.ProgramStore.DepthFunc NOT_EQUAL;
   }
 
   public class ProgramVertex extends android.renderscript.Program {
@@ -16698,6 +16889,8 @@
   public static final class RenderScript.Priority extends java.lang.Enum {
     method public static android.renderscript.RenderScript.Priority valueOf(java.lang.String);
     method public static final android.renderscript.RenderScript.Priority[] values();
+    enum_constant public static final android.renderscript.RenderScript.Priority LOW;
+    enum_constant public static final android.renderscript.RenderScript.Priority NORMAL;
   }
 
   public static class RenderScript.RSErrorHandler implements java.lang.Runnable {
@@ -16760,6 +16953,12 @@
   public static final class Sampler.Value extends java.lang.Enum {
     method public static android.renderscript.Sampler.Value valueOf(java.lang.String);
     method public static final android.renderscript.Sampler.Value[] values();
+    enum_constant public static final android.renderscript.Sampler.Value CLAMP;
+    enum_constant public static final android.renderscript.Sampler.Value LINEAR;
+    enum_constant public static final android.renderscript.Sampler.Value LINEAR_MIP_LINEAR;
+    enum_constant public static final android.renderscript.Sampler.Value LINEAR_MIP_NEAREST;
+    enum_constant public static final android.renderscript.Sampler.Value NEAREST;
+    enum_constant public static final android.renderscript.Sampler.Value WRAP;
   }
 
   public class Script extends android.renderscript.BaseObj {
@@ -16839,6 +17038,12 @@
   public static final class Type.CubemapFace extends java.lang.Enum {
     method public static android.renderscript.Type.CubemapFace valueOf(java.lang.String);
     method public static final android.renderscript.Type.CubemapFace[] values();
+    enum_constant public static final android.renderscript.Type.CubemapFace NEGATIVE_X;
+    enum_constant public static final android.renderscript.Type.CubemapFace NEGATIVE_Y;
+    enum_constant public static final android.renderscript.Type.CubemapFace NEGATIVE_Z;
+    enum_constant public static final android.renderscript.Type.CubemapFace POSITVE_X;
+    enum_constant public static final android.renderscript.Type.CubemapFace POSITVE_Y;
+    enum_constant public static final android.renderscript.Type.CubemapFace POSITVE_Z;
   }
 
 }
@@ -17287,6 +17492,11 @@
   public static final class SmsMessage.MessageClass extends java.lang.Enum {
     method public static android.telephony.SmsMessage.MessageClass valueOf(java.lang.String);
     method public static final android.telephony.SmsMessage.MessageClass[] values();
+    enum_constant public static final android.telephony.SmsMessage.MessageClass CLASS_0;
+    enum_constant public static final android.telephony.SmsMessage.MessageClass CLASS_1;
+    enum_constant public static final android.telephony.SmsMessage.MessageClass CLASS_2;
+    enum_constant public static final android.telephony.SmsMessage.MessageClass CLASS_3;
+    enum_constant public static final android.telephony.SmsMessage.MessageClass UNKNOWN;
   }
 
   public static class SmsMessage.SubmitPdu {
@@ -17458,6 +17668,11 @@
   public static final deprecated class SmsMessage.MessageClass extends java.lang.Enum {
     method public static android.telephony.gsm.SmsMessage.MessageClass valueOf(java.lang.String);
     method public static final android.telephony.gsm.SmsMessage.MessageClass[] values();
+    enum_constant public static final android.telephony.gsm.SmsMessage.MessageClass CLASS_0;
+    enum_constant public static final android.telephony.gsm.SmsMessage.MessageClass CLASS_1;
+    enum_constant public static final android.telephony.gsm.SmsMessage.MessageClass CLASS_2;
+    enum_constant public static final android.telephony.gsm.SmsMessage.MessageClass CLASS_3;
+    enum_constant public static final android.telephony.gsm.SmsMessage.MessageClass UNKNOWN;
   }
 
   public static deprecated class SmsMessage.SubmitPdu {
@@ -18292,6 +18507,9 @@
   public static final class Layout.Alignment extends java.lang.Enum {
     method public static android.text.Layout.Alignment valueOf(java.lang.String);
     method public static final android.text.Layout.Alignment[] values();
+    enum_constant public static final android.text.Layout.Alignment ALIGN_CENTER;
+    enum_constant public static final android.text.Layout.Alignment ALIGN_NORMAL;
+    enum_constant public static final android.text.Layout.Alignment ALIGN_OPPOSITE;
   }
 
   public static class Layout.Directions {
@@ -18549,6 +18767,10 @@
   public static final class TextUtils.TruncateAt extends java.lang.Enum {
     method public static android.text.TextUtils.TruncateAt valueOf(java.lang.String);
     method public static final android.text.TextUtils.TruncateAt[] values();
+    enum_constant public static final android.text.TextUtils.TruncateAt END;
+    enum_constant public static final android.text.TextUtils.TruncateAt MARQUEE;
+    enum_constant public static final android.text.TextUtils.TruncateAt MIDDLE;
+    enum_constant public static final android.text.TextUtils.TruncateAt START;
   }
 
   public abstract interface TextWatcher implements android.text.NoCopySpan {
@@ -18934,6 +19156,10 @@
   public static final class TextKeyListener.Capitalize extends java.lang.Enum {
     method public static android.text.method.TextKeyListener.Capitalize valueOf(java.lang.String);
     method public static final android.text.method.TextKeyListener.Capitalize[] values();
+    enum_constant public static final android.text.method.TextKeyListener.Capitalize CHARACTERS;
+    enum_constant public static final android.text.method.TextKeyListener.Capitalize NONE;
+    enum_constant public static final android.text.method.TextKeyListener.Capitalize SENTENCES;
+    enum_constant public static final android.text.method.TextKeyListener.Capitalize WORDS;
   }
 
   public class TimeKeyListener extends android.text.method.NumberKeyListener {
@@ -19483,6 +19709,16 @@
   public final class JsonToken extends java.lang.Enum {
     method public static android.util.JsonToken valueOf(java.lang.String);
     method public static final android.util.JsonToken[] values();
+    enum_constant public static final android.util.JsonToken BEGIN_ARRAY;
+    enum_constant public static final android.util.JsonToken BEGIN_OBJECT;
+    enum_constant public static final android.util.JsonToken BOOLEAN;
+    enum_constant public static final android.util.JsonToken END_ARRAY;
+    enum_constant public static final android.util.JsonToken END_DOCUMENT;
+    enum_constant public static final android.util.JsonToken END_OBJECT;
+    enum_constant public static final android.util.JsonToken NAME;
+    enum_constant public static final android.util.JsonToken NULL;
+    enum_constant public static final android.util.JsonToken NUMBER;
+    enum_constant public static final android.util.JsonToken STRING;
   }
 
   public final class JsonWriter implements java.io.Closeable {
@@ -19772,6 +20008,10 @@
   public static final class Xml.Encoding extends java.lang.Enum {
     method public static android.util.Xml.Encoding valueOf(java.lang.String);
     method public static final android.util.Xml.Encoding[] values();
+    enum_constant public static final android.util.Xml.Encoding ISO_8859_1;
+    enum_constant public static final android.util.Xml.Encoding US_ASCII;
+    enum_constant public static final android.util.Xml.Encoding UTF_16;
+    enum_constant public static final android.util.Xml.Encoding UTF_8;
   }
 
 }
@@ -21424,6 +21664,14 @@
   public static final class ViewDebug.HierarchyTraceType extends java.lang.Enum {
     method public static android.view.ViewDebug.HierarchyTraceType valueOf(java.lang.String);
     method public static final android.view.ViewDebug.HierarchyTraceType[] values();
+    enum_constant public static final android.view.ViewDebug.HierarchyTraceType BUILD_CACHE;
+    enum_constant public static final android.view.ViewDebug.HierarchyTraceType DRAW;
+    enum_constant public static final android.view.ViewDebug.HierarchyTraceType INVALIDATE;
+    enum_constant public static final android.view.ViewDebug.HierarchyTraceType INVALIDATE_CHILD;
+    enum_constant public static final android.view.ViewDebug.HierarchyTraceType INVALIDATE_CHILD_IN_PARENT;
+    enum_constant public static final android.view.ViewDebug.HierarchyTraceType ON_LAYOUT;
+    enum_constant public static final android.view.ViewDebug.HierarchyTraceType ON_MEASURE;
+    enum_constant public static final android.view.ViewDebug.HierarchyTraceType REQUEST_LAYOUT;
   }
 
   public static abstract class ViewDebug.IntToString implements java.lang.annotation.Annotation {
@@ -21432,6 +21680,12 @@
   public static final class ViewDebug.RecyclerTraceType extends java.lang.Enum {
     method public static android.view.ViewDebug.RecyclerTraceType valueOf(java.lang.String);
     method public static final android.view.ViewDebug.RecyclerTraceType[] values();
+    enum_constant public static final android.view.ViewDebug.RecyclerTraceType BIND_VIEW;
+    enum_constant public static final android.view.ViewDebug.RecyclerTraceType MOVE_FROM_ACTIVE_TO_SCRAP_HEAP;
+    enum_constant public static final android.view.ViewDebug.RecyclerTraceType MOVE_TO_SCRAP_HEAP;
+    enum_constant public static final android.view.ViewDebug.RecyclerTraceType NEW_VIEW;
+    enum_constant public static final android.view.ViewDebug.RecyclerTraceType RECYCLE_FROM_ACTIVE_HEAP;
+    enum_constant public static final android.view.ViewDebug.RecyclerTraceType RECYCLE_FROM_SCRAP_HEAP;
   }
 
   public abstract class ViewGroup extends android.view.View implements android.view.ViewManager android.view.ViewParent {
@@ -21985,11 +22239,8 @@
   }
 
   public class AccessibilityRecord {
-    ctor protected AccessibilityRecord();
-    method protected void clear();
     method public int getAddedCount();
     method public java.lang.CharSequence getBeforeText();
-    method public boolean getBooleanProperty(int);
     method public java.lang.CharSequence getClassName();
     method public java.lang.CharSequence getContentDescription();
     method public int getCurrentItemIndex();
@@ -22017,17 +22268,6 @@
     method public void setParcelableData(android.os.Parcelable);
     method public void setPassword(boolean);
     method public void setRemovedCount(int);
-    field protected int mAddedCount;
-    field protected java.lang.CharSequence mBeforeText;
-    field protected int mBooleanProperties;
-    field protected java.lang.CharSequence mClassName;
-    field protected java.lang.CharSequence mContentDescription;
-    field protected int mCurrentItemIndex;
-    field protected int mFromIndex;
-    field protected int mItemCount;
-    field protected android.os.Parcelable mParcelableData;
-    field protected int mRemovedCount;
-    field protected final java.util.List mText;
   }
 }
 
@@ -22640,6 +22880,11 @@
   public static final class ConsoleMessage.MessageLevel extends java.lang.Enum {
     method public static android.webkit.ConsoleMessage.MessageLevel valueOf(java.lang.String);
     method public static final android.webkit.ConsoleMessage.MessageLevel[] values();
+    enum_constant public static final android.webkit.ConsoleMessage.MessageLevel DEBUG;
+    enum_constant public static final android.webkit.ConsoleMessage.MessageLevel ERROR;
+    enum_constant public static final android.webkit.ConsoleMessage.MessageLevel LOG;
+    enum_constant public static final android.webkit.ConsoleMessage.MessageLevel TIP;
+    enum_constant public static final android.webkit.ConsoleMessage.MessageLevel WARNING;
   }
 
   public final class CookieManager {
@@ -22922,26 +23167,43 @@
   public static final deprecated class WebSettings.LayoutAlgorithm extends java.lang.Enum {
     method public static android.webkit.WebSettings.LayoutAlgorithm valueOf(java.lang.String);
     method public static final android.webkit.WebSettings.LayoutAlgorithm[] values();
+    enum_constant public static final android.webkit.WebSettings.LayoutAlgorithm NARROW_COLUMNS;
+    enum_constant public static final android.webkit.WebSettings.LayoutAlgorithm NORMAL;
+    enum_constant public static final android.webkit.WebSettings.LayoutAlgorithm SINGLE_COLUMN;
   }
 
   public static final class WebSettings.PluginState extends java.lang.Enum {
     method public static android.webkit.WebSettings.PluginState valueOf(java.lang.String);
     method public static final android.webkit.WebSettings.PluginState[] values();
+    enum_constant public static final android.webkit.WebSettings.PluginState OFF;
+    enum_constant public static final android.webkit.WebSettings.PluginState ON;
+    enum_constant public static final android.webkit.WebSettings.PluginState ON_DEMAND;
   }
 
   public static final class WebSettings.RenderPriority extends java.lang.Enum {
     method public static android.webkit.WebSettings.RenderPriority valueOf(java.lang.String);
     method public static final android.webkit.WebSettings.RenderPriority[] values();
+    enum_constant public static final android.webkit.WebSettings.RenderPriority HIGH;
+    enum_constant public static final android.webkit.WebSettings.RenderPriority LOW;
+    enum_constant public static final android.webkit.WebSettings.RenderPriority NORMAL;
   }
 
   public static final class WebSettings.TextSize extends java.lang.Enum {
     method public static android.webkit.WebSettings.TextSize valueOf(java.lang.String);
     method public static final android.webkit.WebSettings.TextSize[] values();
+    enum_constant public static final android.webkit.WebSettings.TextSize LARGER;
+    enum_constant public static final android.webkit.WebSettings.TextSize LARGEST;
+    enum_constant public static final android.webkit.WebSettings.TextSize NORMAL;
+    enum_constant public static final android.webkit.WebSettings.TextSize SMALLER;
+    enum_constant public static final android.webkit.WebSettings.TextSize SMALLEST;
   }
 
   public static final class WebSettings.ZoomDensity extends java.lang.Enum {
     method public static android.webkit.WebSettings.ZoomDensity valueOf(java.lang.String);
     method public static final android.webkit.WebSettings.ZoomDensity[] values();
+    enum_constant public static final android.webkit.WebSettings.ZoomDensity CLOSE;
+    enum_constant public static final android.webkit.WebSettings.ZoomDensity FAR;
+    enum_constant public static final android.webkit.WebSettings.ZoomDensity MEDIUM;
   }
 
   public final class WebStorage {
@@ -24008,6 +24270,14 @@
   public static final class ImageView.ScaleType extends java.lang.Enum {
     method public static android.widget.ImageView.ScaleType valueOf(java.lang.String);
     method public static final android.widget.ImageView.ScaleType[] values();
+    enum_constant public static final android.widget.ImageView.ScaleType CENTER;
+    enum_constant public static final android.widget.ImageView.ScaleType CENTER_CROP;
+    enum_constant public static final android.widget.ImageView.ScaleType CENTER_INSIDE;
+    enum_constant public static final android.widget.ImageView.ScaleType FIT_CENTER;
+    enum_constant public static final android.widget.ImageView.ScaleType FIT_END;
+    enum_constant public static final android.widget.ImageView.ScaleType FIT_START;
+    enum_constant public static final android.widget.ImageView.ScaleType FIT_XY;
+    enum_constant public static final android.widget.ImageView.ScaleType MATRIX;
   }
 
   public class LinearLayout extends android.view.ViewGroup {
@@ -25064,6 +25334,9 @@
   public static final class TextView.BufferType extends java.lang.Enum {
     method public static android.widget.TextView.BufferType valueOf(java.lang.String);
     method public static final android.widget.TextView.BufferType[] values();
+    enum_constant public static final android.widget.TextView.BufferType EDITABLE;
+    enum_constant public static final android.widget.TextView.BufferType NORMAL;
+    enum_constant public static final android.widget.TextView.BufferType SPANNABLE;
   }
 
   public static abstract interface TextView.OnEditorActionListener {
@@ -28052,6 +28325,12 @@
   public static final class Thread.State extends java.lang.Enum {
     method public static java.lang.Thread.State valueOf(java.lang.String);
     method public static final java.lang.Thread.State[] values();
+    enum_constant public static final java.lang.Thread.State BLOCKED;
+    enum_constant public static final java.lang.Thread.State NEW;
+    enum_constant public static final java.lang.Thread.State RUNNABLE;
+    enum_constant public static final java.lang.Thread.State TERMINATED;
+    enum_constant public static final java.lang.Thread.State TIMED_WAITING;
+    enum_constant public static final java.lang.Thread.State WAITING;
   }
 
   public static abstract interface Thread.UncaughtExceptionHandler {
@@ -28185,6 +28464,14 @@
   public final class ElementType extends java.lang.Enum {
     method public static java.lang.annotation.ElementType valueOf(java.lang.String);
     method public static final java.lang.annotation.ElementType[] values();
+    enum_constant public static final java.lang.annotation.ElementType ANNOTATION_TYPE;
+    enum_constant public static final java.lang.annotation.ElementType CONSTRUCTOR;
+    enum_constant public static final java.lang.annotation.ElementType FIELD;
+    enum_constant public static final java.lang.annotation.ElementType LOCAL_VARIABLE;
+    enum_constant public static final java.lang.annotation.ElementType METHOD;
+    enum_constant public static final java.lang.annotation.ElementType PACKAGE;
+    enum_constant public static final java.lang.annotation.ElementType PARAMETER;
+    enum_constant public static final java.lang.annotation.ElementType TYPE;
   }
 
   public class IncompleteAnnotationException extends java.lang.RuntimeException {
@@ -28202,6 +28489,9 @@
   public final class RetentionPolicy extends java.lang.Enum {
     method public static java.lang.annotation.RetentionPolicy valueOf(java.lang.String);
     method public static final java.lang.annotation.RetentionPolicy[] values();
+    enum_constant public static final java.lang.annotation.RetentionPolicy CLASS;
+    enum_constant public static final java.lang.annotation.RetentionPolicy RUNTIME;
+    enum_constant public static final java.lang.annotation.RetentionPolicy SOURCE;
   }
 
   public abstract class Target implements java.lang.annotation.Annotation {
@@ -28615,6 +28905,14 @@
     method public static java.math.RoundingMode valueOf(java.lang.String);
     method public static java.math.RoundingMode valueOf(int);
     method public static final java.math.RoundingMode[] values();
+    enum_constant public static final java.math.RoundingMode CEILING;
+    enum_constant public static final java.math.RoundingMode DOWN;
+    enum_constant public static final java.math.RoundingMode FLOOR;
+    enum_constant public static final java.math.RoundingMode HALF_DOWN;
+    enum_constant public static final java.math.RoundingMode HALF_EVEN;
+    enum_constant public static final java.math.RoundingMode HALF_UP;
+    enum_constant public static final java.math.RoundingMode UNNECESSARY;
+    enum_constant public static final java.math.RoundingMode UP;
   }
 
 }
@@ -28641,6 +28939,8 @@
   public static final class Authenticator.RequestorType extends java.lang.Enum {
     method public static java.net.Authenticator.RequestorType valueOf(java.lang.String);
     method public static final java.net.Authenticator.RequestorType[] values();
+    enum_constant public static final java.net.Authenticator.RequestorType PROXY;
+    enum_constant public static final java.net.Authenticator.RequestorType SERVER;
   }
 
   public class BindException extends java.net.SocketException {
@@ -29055,6 +29355,9 @@
   public static final class Proxy.Type extends java.lang.Enum {
     method public static java.net.Proxy.Type valueOf(java.lang.String);
     method public static final java.net.Proxy.Type[] values();
+    enum_constant public static final java.net.Proxy.Type DIRECT;
+    enum_constant public static final java.net.Proxy.Type HTTP;
+    enum_constant public static final java.net.Proxy.Type SOCKS;
   }
 
   public abstract class ProxySelector {
@@ -30451,6 +30754,9 @@
   public static final class KeyRep.Type extends java.lang.Enum {
     method public static java.security.KeyRep.Type valueOf(java.lang.String);
     method public static final java.security.KeyRep.Type[] values();
+    enum_constant public static final java.security.KeyRep.Type PRIVATE;
+    enum_constant public static final java.security.KeyRep.Type PUBLIC;
+    enum_constant public static final java.security.KeyRep.Type SECRET;
   }
 
   public class KeyStore {
@@ -31824,6 +32130,10 @@
   public final class ClientInfoStatus extends java.lang.Enum {
     method public static java.sql.ClientInfoStatus valueOf(java.lang.String);
     method public static final java.sql.ClientInfoStatus[] values();
+    enum_constant public static final java.sql.ClientInfoStatus REASON_UNKNOWN;
+    enum_constant public static final java.sql.ClientInfoStatus REASON_UNKNOWN_PROPERTY;
+    enum_constant public static final java.sql.ClientInfoStatus REASON_VALUE_INVALID;
+    enum_constant public static final java.sql.ClientInfoStatus REASON_VALUE_TRUNCATED;
   }
 
   public abstract interface Clob {
@@ -32508,6 +32818,11 @@
   public final class RowIdLifetime extends java.lang.Enum {
     method public static java.sql.RowIdLifetime valueOf(java.lang.String);
     method public static final java.sql.RowIdLifetime[] values();
+    enum_constant public static final java.sql.RowIdLifetime ROWID_UNSUPPORTED;
+    enum_constant public static final java.sql.RowIdLifetime ROWID_VALID_FOREVER;
+    enum_constant public static final java.sql.RowIdLifetime ROWID_VALID_OTHER;
+    enum_constant public static final java.sql.RowIdLifetime ROWID_VALID_SESSION;
+    enum_constant public static final java.sql.RowIdLifetime ROWID_VALID_TRANSACTION;
   }
 
   public class SQLClientInfoException extends java.sql.SQLException {
@@ -33297,6 +33612,10 @@
   public static final class Normalizer.Form extends java.lang.Enum {
     method public static java.text.Normalizer.Form valueOf(java.lang.String);
     method public static final java.text.Normalizer.Form[] values();
+    enum_constant public static final java.text.Normalizer.Form NFC;
+    enum_constant public static final java.text.Normalizer.Form NFD;
+    enum_constant public static final java.text.Normalizer.Form NFKC;
+    enum_constant public static final java.text.Normalizer.Form NFKD;
   }
 
   public abstract class NumberFormat extends java.text.Format {
@@ -34038,6 +34357,8 @@
   public static final class Formatter.BigDecimalLayoutForm extends java.lang.Enum {
     method public static java.util.Formatter.BigDecimalLayoutForm valueOf(java.lang.String);
     method public static final java.util.Formatter.BigDecimalLayoutForm[] values();
+    enum_constant public static final java.util.Formatter.BigDecimalLayoutForm DECIMAL_FLOAT;
+    enum_constant public static final java.util.Formatter.BigDecimalLayoutForm SCIENTIFIC;
   }
 
   public class FormatterClosedException extends java.lang.IllegalStateException implements java.io.Serializable {
@@ -35484,6 +35805,13 @@
     method public long toSeconds(long);
     method public static java.util.concurrent.TimeUnit valueOf(java.lang.String);
     method public static final java.util.concurrent.TimeUnit[] values();
+    enum_constant public static final java.util.concurrent.TimeUnit DAYS;
+    enum_constant public static final java.util.concurrent.TimeUnit HOURS;
+    enum_constant public static final java.util.concurrent.TimeUnit MICROSECONDS;
+    enum_constant public static final java.util.concurrent.TimeUnit MILLISECONDS;
+    enum_constant public static final java.util.concurrent.TimeUnit MINUTES;
+    enum_constant public static final java.util.concurrent.TimeUnit NANOSECONDS;
+    enum_constant public static final java.util.concurrent.TimeUnit SECONDS;
   }
 
   public class TimeoutException extends java.lang.Exception {
@@ -38140,11 +38468,20 @@
   public static final class SSLEngineResult.HandshakeStatus extends java.lang.Enum {
     method public static javax.net.ssl.SSLEngineResult.HandshakeStatus valueOf(java.lang.String);
     method public static final javax.net.ssl.SSLEngineResult.HandshakeStatus[] values();
+    enum_constant public static final javax.net.ssl.SSLEngineResult.HandshakeStatus FINISHED;
+    enum_constant public static final javax.net.ssl.SSLEngineResult.HandshakeStatus NEED_TASK;
+    enum_constant public static final javax.net.ssl.SSLEngineResult.HandshakeStatus NEED_UNWRAP;
+    enum_constant public static final javax.net.ssl.SSLEngineResult.HandshakeStatus NEED_WRAP;
+    enum_constant public static final javax.net.ssl.SSLEngineResult.HandshakeStatus NOT_HANDSHAKING;
   }
 
   public static final class SSLEngineResult.Status extends java.lang.Enum {
     method public static javax.net.ssl.SSLEngineResult.Status valueOf(java.lang.String);
     method public static final javax.net.ssl.SSLEngineResult.Status[] values();
+    enum_constant public static final javax.net.ssl.SSLEngineResult.Status BUFFER_OVERFLOW;
+    enum_constant public static final javax.net.ssl.SSLEngineResult.Status BUFFER_UNDERFLOW;
+    enum_constant public static final javax.net.ssl.SSLEngineResult.Status CLOSED;
+    enum_constant public static final javax.net.ssl.SSLEngineResult.Status OK;
   }
 
   public class SSLException extends java.io.IOException {
@@ -40658,11 +40995,15 @@
   public static final class RouteInfo.LayerType extends java.lang.Enum {
     method public static org.apache.http.conn.routing.RouteInfo.LayerType valueOf(java.lang.String);
     method public static final org.apache.http.conn.routing.RouteInfo.LayerType[] values();
+    enum_constant public static final org.apache.http.conn.routing.RouteInfo.LayerType LAYERED;
+    enum_constant public static final org.apache.http.conn.routing.RouteInfo.LayerType PLAIN;
   }
 
   public static final class RouteInfo.TunnelType extends java.lang.Enum {
     method public static org.apache.http.conn.routing.RouteInfo.TunnelType valueOf(java.lang.String);
     method public static final org.apache.http.conn.routing.RouteInfo.TunnelType[] values();
+    enum_constant public static final org.apache.http.conn.routing.RouteInfo.TunnelType PLAIN;
+    enum_constant public static final org.apache.http.conn.routing.RouteInfo.TunnelType TUNNELLED;
   }
 
   public final class RouteTracker implements java.lang.Cloneable org.apache.http.conn.routing.RouteInfo {
diff --git a/api/current.txt b/api/current.txt
index a5f1936..d490e29 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -78,6 +78,7 @@
     field public static final java.lang.String READ_INPUT_STATE = "android.permission.READ_INPUT_STATE";
     field public static final java.lang.String READ_LOGS = "android.permission.READ_LOGS";
     field public static final java.lang.String READ_PHONE_STATE = "android.permission.READ_PHONE_STATE";
+    field public static final java.lang.String READ_PROFILE = "android.permission.READ_PROFILE";
     field public static final java.lang.String READ_SMS = "android.permission.READ_SMS";
     field public static final java.lang.String READ_SYNC_SETTINGS = "android.permission.READ_SYNC_SETTINGS";
     field public static final java.lang.String READ_SYNC_STATS = "android.permission.READ_SYNC_STATS";
@@ -90,6 +91,7 @@
     field public static final java.lang.String REMOVE_TASKS = "android.permission.REMOVE_TASKS";
     field public static final java.lang.String REORDER_TASKS = "android.permission.REORDER_TASKS";
     field public static final deprecated java.lang.String RESTART_PACKAGES = "android.permission.RESTART_PACKAGES";
+    field public static final java.lang.String RETRIEVE_WINDOW_CONTENT = "android.permission.RETRIEVE_WINDOW_CONTENT";
     field public static final java.lang.String SEND_SMS = "android.permission.SEND_SMS";
     field public static final java.lang.String SET_ACTIVITY_WATCHER = "android.permission.SET_ACTIVITY_WATCHER";
     field public static final java.lang.String SET_ALARM = "com.android.alarm.permission.SET_ALARM";
@@ -97,6 +99,7 @@
     field public static final java.lang.String SET_ANIMATION_SCALE = "android.permission.SET_ANIMATION_SCALE";
     field public static final java.lang.String SET_DEBUG_APP = "android.permission.SET_DEBUG_APP";
     field public static final java.lang.String SET_ORIENTATION = "android.permission.SET_ORIENTATION";
+    field public static final java.lang.String SET_POINTER_SPEED = "android.permission.SET_POINTER_SPEED";
     field public static final deprecated java.lang.String SET_PREFERRED_APPLICATIONS = "android.permission.SET_PREFERRED_APPLICATIONS";
     field public static final java.lang.String SET_PROCESS_LIMIT = "android.permission.SET_PROCESS_LIMIT";
     field public static final java.lang.String SET_TIME = "android.permission.SET_TIME";
@@ -119,6 +122,7 @@
     field public static final java.lang.String WRITE_EXTERNAL_STORAGE = "android.permission.WRITE_EXTERNAL_STORAGE";
     field public static final java.lang.String WRITE_GSERVICES = "android.permission.WRITE_GSERVICES";
     field public static final java.lang.String WRITE_HISTORY_BOOKMARKS = "com.android.browser.permission.WRITE_HISTORY_BOOKMARKS";
+    field public static final java.lang.String WRITE_PROFILE = "android.permission.WRITE_PROFILE";
     field public static final java.lang.String WRITE_SECURE_SETTINGS = "android.permission.WRITE_SECURE_SETTINGS";
     field public static final java.lang.String WRITE_SETTINGS = "android.permission.WRITE_SETTINGS";
     field public static final java.lang.String WRITE_SMS = "android.permission.WRITE_SMS";
@@ -179,6 +183,9 @@
   public static final class R.attr {
     ctor public R.attr();
     field public static final int absListViewStyle = 16842858; // 0x101006a
+    field public static final int accessibilityEventTypes = 16843650; // 0x1010382
+    field public static final int accessibilityFeedbackType = 16843652; // 0x1010384
+    field public static final int accessibilityFlags = 16843654; // 0x1010386
     field public static final int accountPreferences = 16843423; // 0x101029f
     field public static final int accountType = 16843407; // 0x101028f
     field public static final int action = 16842797; // 0x101002d
@@ -198,6 +205,7 @@
     field public static final int actionModeCopyDrawable = 16843538; // 0x1010312
     field public static final int actionModeCutDrawable = 16843537; // 0x1010311
     field public static final int actionModePasteDrawable = 16843539; // 0x1010313
+    field public static final int actionModeSelectAllDrawable = 16843648; // 0x1010380
     field public static final int actionOverflowButtonStyle = 16843510; // 0x10102f6
     field public static final int actionViewClass = 16843516; // 0x10102fc
     field public static final int activatedBackgroundIndicator = 16843517; // 0x10102fd
@@ -210,6 +218,7 @@
     field public static final int alertDialogIcon = 16843605; // 0x1010355
     field public static final int alertDialogStyle = 16842845; // 0x101005d
     field public static final int alertDialogTheme = 16843529; // 0x1010309
+    field public static final int alignmentMode = 16843642; // 0x101037a
     field public static final int allContactsName = 16843468; // 0x10102cc
     field public static final int allowBackup = 16843392; // 0x1010280
     field public static final int allowClearUserData = 16842757; // 0x1010005
@@ -251,6 +260,7 @@
     field public static final int borderlessButtonStyle = 16843563; // 0x101032b
     field public static final int bottom = 16843184; // 0x10101b0
     field public static final int bottomBright = 16842957; // 0x10100cd
+    field public static final int bottomChevronDrawable = 16843661; // 0x101038d
     field public static final int bottomDark = 16842953; // 0x10100c9
     field public static final int bottomLeftRadius = 16843179; // 0x10101ab
     field public static final int bottomMedium = 16842958; // 0x10100ce
@@ -269,6 +279,7 @@
     field public static final int cacheColorHint = 16843009; // 0x1010101
     field public static final int calendarViewShown = 16843596; // 0x101034c
     field public static final int calendarViewStyle = 16843613; // 0x101035d
+    field public static final int canRetrieveWindowContent = 16843655; // 0x1010387
     field public static final int candidatesTextStyleSpans = 16843312; // 0x1010230
     field public static final deprecated int capitalize = 16843113; // 0x1010169
     field public static final int centerBright = 16842956; // 0x10100cc
@@ -301,10 +312,11 @@
     field public static final int colorBackgroundCacheHint = 16843435; // 0x10102ab
     field public static final int colorForeground = 16842800; // 0x1010030
     field public static final int colorForegroundInverse = 16843270; // 0x1010206
-    field public static final int columnCount = 16843633; // 0x1010371
+    field public static final int columnCount = 16843639; // 0x1010377
     field public static final int columnDelay = 16843215; // 0x10101cf
-    field public static final int columnOrderPreserved = 16843634; // 0x1010372
+    field public static final int columnOrderPreserved = 16843640; // 0x1010378
     field public static final int columnWidth = 16843031; // 0x1010117
+    field public static final int compatibleWidthLimitDp = 16843621; // 0x1010365
     field public static final int completionHint = 16843122; // 0x1010172
     field public static final int completionHintView = 16843123; // 0x1010173
     field public static final int completionThreshold = 16843124; // 0x1010174
@@ -415,6 +427,7 @@
     field public static final int fastScrollTextColor = 16843609; // 0x1010359
     field public static final int fastScrollThumbDrawable = 16843574; // 0x1010336
     field public static final int fastScrollTrackDrawable = 16843577; // 0x1010339
+    field public static final int feedbackCount = 16843667; // 0x1010393
     field public static final int fillAfter = 16843197; // 0x10101bd
     field public static final int fillBefore = 16843196; // 0x10101bc
     field public static final int fillEnabled = 16843343; // 0x101024f
@@ -447,7 +460,7 @@
     field public static final int fromXScale = 16843202; // 0x10101c2
     field public static final int fromYDelta = 16843208; // 0x10101c8
     field public static final int fromYScale = 16843204; // 0x10101c4
-    field public static final int fullBackupAgent = 16843629; // 0x101036d
+    field public static final int fullBackupAgent = 16843635; // 0x1010373
     field public static final int fullBright = 16842954; // 0x10100ca
     field public static final int fullDark = 16842950; // 0x10100c6
     field public static final int functionalTest = 16842787; // 0x1010023
@@ -468,6 +481,7 @@
     field public static final int hand_hour = 16843011; // 0x1010103
     field public static final int hand_minute = 16843012; // 0x1010104
     field public static final int handle = 16843354; // 0x101025a
+    field public static final int handleDrawable = 16843657; // 0x1010389
     field public static final int handleProfiling = 16842786; // 0x1010022
     field public static final int hapticFeedbackEnabled = 16843358; // 0x101025e
     field public static final int hardwareAccelerated = 16843475; // 0x10102d3
@@ -476,11 +490,12 @@
     field public static final int headerDividersEnabled = 16843310; // 0x101022e
     field public static final int height = 16843093; // 0x1010155
     field public static final int hint = 16843088; // 0x1010150
+    field public static final int hitRadius = 16843664; // 0x1010390
     field public static final int homeAsUpIndicator = 16843531; // 0x101030b
     field public static final int homeLayout = 16843549; // 0x101031d
-    field public static final int horizontalDirection = 16843628; // 0x101036c
     field public static final int horizontalDivider = 16843053; // 0x101012d
     field public static final int horizontalGap = 16843327; // 0x101023f
+    field public static final int horizontalOffset = 16843669; // 0x1010395
     field public static final int horizontalScrollViewStyle = 16843603; // 0x1010353
     field public static final int horizontalSpacing = 16843028; // 0x1010114
     field public static final int host = 16842792; // 0x1010028
@@ -526,7 +541,7 @@
     field public static final int installLocation = 16843447; // 0x10102b7
     field public static final int interpolator = 16843073; // 0x1010141
     field public static final int isAlwaysSyncable = 16843571; // 0x1010333
-    field public static final int isAuxiliary = 16843641; // 0x1010379
+    field public static final int isAuxiliary = 16843649; // 0x1010381
     field public static final int isDefault = 16843297; // 0x1010221
     field public static final int isIndicator = 16843079; // 0x1010147
     field public static final int isModifier = 16843334; // 0x1010246
@@ -558,10 +573,12 @@
     field public static final int labelTextSize = 16843317; // 0x1010235
     field public static final int largeHeap = 16843610; // 0x101035a
     field public static final int largeScreens = 16843398; // 0x1010286
+    field public static final int largestWidthLimitDp = 16843622; // 0x1010366
     field public static final int launchMode = 16842781; // 0x101001d
     field public static final int layerType = 16843604; // 0x1010354
     field public static final int layout = 16842994; // 0x10100f2
     field public static final int layoutAnimation = 16842988; // 0x10100ec
+    field public static final int layoutDirection = 16843634; // 0x1010372
     field public static final int layout_above = 16843140; // 0x1010184
     field public static final int layout_alignBaseline = 16843142; // 0x1010186
     field public static final int layout_alignBottom = 16843146; // 0x101018a
@@ -578,8 +595,8 @@
     field public static final int layout_centerInParent = 16843151; // 0x101018f
     field public static final int layout_centerVertical = 16843153; // 0x1010191
     field public static final int layout_column = 16843084; // 0x101014c
-    field public static final int layout_columnSpan = 16843639; // 0x1010377
-    field public static final int layout_columnWeight = 16843640; // 0x1010378
+    field public static final int layout_columnSpan = 16843646; // 0x101037e
+    field public static final int layout_columnWeight = 16843647; // 0x101037f
     field public static final int layout_gravity = 16842931; // 0x10100b3
     field public static final int layout_height = 16842997; // 0x10100f5
     field public static final int layout_margin = 16842998; // 0x10100f6
@@ -587,9 +604,9 @@
     field public static final int layout_marginLeft = 16842999; // 0x10100f7
     field public static final int layout_marginRight = 16843001; // 0x10100f9
     field public static final int layout_marginTop = 16843000; // 0x10100f8
-    field public static final int layout_row = 16843636; // 0x1010374
-    field public static final int layout_rowSpan = 16843637; // 0x1010375
-    field public static final int layout_rowWeight = 16843638; // 0x1010376
+    field public static final int layout_row = 16843643; // 0x101037b
+    field public static final int layout_rowSpan = 16843644; // 0x101037c
+    field public static final int layout_rowWeight = 16843645; // 0x101037d
     field public static final int layout_scale = 16843155; // 0x1010193
     field public static final int layout_span = 16843085; // 0x101014d
     field public static final int layout_toLeftOf = 16843138; // 0x1010182
@@ -599,6 +616,7 @@
     field public static final int layout_x = 16843135; // 0x101017f
     field public static final int layout_y = 16843136; // 0x1010180
     field public static final int left = 16843181; // 0x10101ad
+    field public static final int leftChevronDrawable = 16843658; // 0x101038a
     field public static final int lineSpacingExtra = 16843287; // 0x1010217
     field public static final int lineSpacingMultiplier = 16843288; // 0x1010218
     field public static final int lines = 16843092; // 0x1010154
@@ -610,6 +628,8 @@
     field public static final int listDividerAlertDialog = 16843525; // 0x1010305
     field public static final int listPopupWindowStyle = 16843519; // 0x10102ff
     field public static final int listPreferredItemHeight = 16842829; // 0x101004d
+    field public static final int listPreferredItemHeightLarge = 16843670; // 0x1010396
+    field public static final int listPreferredItemHeightSmall = 16843671; // 0x1010397
     field public static final int listSelector = 16843003; // 0x10100fb
     field public static final int listSeparatorTextViewStyle = 16843272; // 0x1010208
     field public static final int listViewStyle = 16842868; // 0x1010074
@@ -655,6 +675,7 @@
     field public static final int nextFocusUp = 16842979; // 0x10100e3
     field public static final int noHistory = 16843309; // 0x101022d
     field public static final int normalScreens = 16843397; // 0x1010285
+    field public static final int notificationTimeout = 16843653; // 0x1010385
     field public static final int numColumns = 16843032; // 0x1010118
     field public static final int numStars = 16843076; // 0x1010144
     field public static final deprecated int numeric = 16843109; // 0x1010165
@@ -668,13 +689,17 @@
     field public static final int orderingFromXml = 16843239; // 0x10101e7
     field public static final int orientation = 16842948; // 0x10100c4
     field public static final int outAnimation = 16843128; // 0x1010178
+    field public static final int outerRadius = 16843663; // 0x101038f
     field public static final int overScrollFooter = 16843459; // 0x10102c3
     field public static final int overScrollHeader = 16843458; // 0x10102c2
     field public static final int overScrollMode = 16843457; // 0x10102c1
+    field public static final int packageNames = 16843651; // 0x1010383
     field public static final int padding = 16842965; // 0x10100d5
     field public static final int paddingBottom = 16842969; // 0x10100d9
+    field public static final int paddingEnd = 16843673; // 0x1010399
     field public static final int paddingLeft = 16842966; // 0x10100d6
     field public static final int paddingRight = 16842968; // 0x10100d8
+    field public static final int paddingStart = 16843672; // 0x1010398
     field public static final int paddingTop = 16842967; // 0x10100d7
     field public static final int panelBackground = 16842846; // 0x101005e
     field public static final int panelColorBackground = 16842849; // 0x1010061
@@ -748,22 +773,24 @@
     field public static final int reqNavigation = 16843306; // 0x101022a
     field public static final int reqTouchScreen = 16843303; // 0x1010227
     field public static final int required = 16843406; // 0x101028e
+    field public static final int requiresSmallestWidthDp = 16843620; // 0x1010364
     field public static final int resizeMode = 16843619; // 0x1010363
     field public static final int resizeable = 16843405; // 0x101028d
     field public static final int resource = 16842789; // 0x1010025
     field public static final int restoreAnyVersion = 16843450; // 0x10102ba
     field public static final deprecated int restoreNeedsApplication = 16843421; // 0x101029d
     field public static final int right = 16843183; // 0x10101af
+    field public static final int rightChevronDrawable = 16843659; // 0x101038b
     field public static final int ringtonePreferenceStyle = 16842899; // 0x1010093
     field public static final int ringtoneType = 16843257; // 0x10101f9
     field public static final int rotation = 16843558; // 0x1010326
     field public static final int rotationX = 16843559; // 0x1010327
     field public static final int rotationY = 16843560; // 0x1010328
-    field public static final int rowCount = 16843631; // 0x101036f
+    field public static final int rowCount = 16843637; // 0x1010375
     field public static final int rowDelay = 16843216; // 0x10101d0
     field public static final int rowEdgeFlags = 16843329; // 0x1010241
     field public static final int rowHeight = 16843058; // 0x1010132
-    field public static final int rowOrderPreserved = 16843632; // 0x1010370
+    field public static final int rowOrderPreserved = 16843638; // 0x1010376
     field public static final int saveEnabled = 16842983; // 0x10100e7
     field public static final int scaleGravity = 16843262; // 0x10101fe
     field public static final int scaleHeight = 16843261; // 0x10101fd
@@ -829,6 +856,7 @@
     field public static final int smallIcon = 16843422; // 0x101029e
     field public static final int smallScreens = 16843396; // 0x1010284
     field public static final int smoothScrollbar = 16843313; // 0x1010231
+    field public static final int snapMargin = 16843666; // 0x1010392
     field public static final int soundEffectsEnabled = 16843285; // 0x1010215
     field public static final int spacing = 16843027; // 0x1010113
     field public static final int spinnerDropDownItemStyle = 16842887; // 0x1010087
@@ -850,14 +878,14 @@
     field public static final int state_active = 16842914; // 0x10100a2
     field public static final int state_checkable = 16842911; // 0x101009f
     field public static final int state_checked = 16842912; // 0x10100a0
-    field public static final int state_drag_can_accept = 16843621; // 0x1010365
-    field public static final int state_drag_hovered = 16843622; // 0x1010366
+    field public static final int state_drag_can_accept = 16843624; // 0x1010368
+    field public static final int state_drag_hovered = 16843625; // 0x1010369
     field public static final int state_empty = 16842921; // 0x10100a9
     field public static final int state_enabled = 16842910; // 0x101009e
     field public static final int state_expanded = 16842920; // 0x10100a8
     field public static final int state_first = 16842916; // 0x10100a4
     field public static final int state_focused = 16842908; // 0x101009c
-    field public static final int state_hovered = 16843620; // 0x1010364
+    field public static final int state_hovered = 16843623; // 0x1010367
     field public static final int state_last = 16842918; // 0x10100a6
     field public static final int state_long_pressable = 16843324; // 0x101023c
     field public static final int state_middle = 16842917; // 0x10100a5
@@ -868,7 +896,7 @@
     field public static final int state_window_focused = 16842909; // 0x101009d
     field public static final int staticWallpaperPreview = 16843569; // 0x1010331
     field public static final int stepSize = 16843078; // 0x1010146
-    field public static final int stopWithTask = 16843623; // 0x1010367
+    field public static final int stopWithTask = 16843626; // 0x101036a
     field public static final int streamType = 16843273; // 0x1010209
     field public static final int stretchColumns = 16843081; // 0x1010149
     field public static final int stretchMode = 16843030; // 0x1010116
@@ -876,12 +904,15 @@
     field public static final int subtitleTextStyle = 16843513; // 0x10102f9
     field public static final int suggestActionMsg = 16843228; // 0x10101dc
     field public static final int suggestActionMsgColumn = 16843229; // 0x10101dd
-    field public static final int suggestionsEnabled = 16843630; // 0x101036e
+    field public static final int suggestionsEnabled = 16843636; // 0x1010374
     field public static final int summary = 16843241; // 0x10101e9
     field public static final int summaryColumn = 16843426; // 0x10102a2
     field public static final int summaryOff = 16843248; // 0x10101f0
     field public static final int summaryOn = 16843247; // 0x10101ef
     field public static final int supportsUploading = 16843419; // 0x101029b
+    field public static final int switchPreferenceStyle = 16843629; // 0x101036d
+    field public static final int switchTextOff = 16843628; // 0x101036c
+    field public static final int switchTextOn = 16843627; // 0x101036b
     field public static final int syncable = 16842777; // 0x1010019
     field public static final int tabStripEnabled = 16843453; // 0x10102bd
     field public static final int tabStripLeft = 16843451; // 0x10102bb
@@ -890,6 +921,7 @@
     field public static final int tag = 16842961; // 0x10100d1
     field public static final int targetActivity = 16843266; // 0x1010202
     field public static final int targetClass = 16842799; // 0x101002f
+    field public static final int targetDrawables = 16843656; // 0x1010388
     field public static final int targetPackage = 16842785; // 0x1010021
     field public static final int targetSdkVersion = 16843376; // 0x1010270
     field public static final int taskAffinity = 16842770; // 0x1010012
@@ -944,9 +976,9 @@
     field public static final int textEditPasteWindowLayout = 16843540; // 0x1010314
     field public static final int textEditSideNoPasteWindowLayout = 16843615; // 0x101035f
     field public static final int textEditSidePasteWindowLayout = 16843614; // 0x101035e
-    field public static final int textEditSuggestionItemLayout = 16843627; // 0x101036b
-    field public static final int textEditSuggestionsBottomWindowLayout = 16843625; // 0x1010369
-    field public static final int textEditSuggestionsTopWindowLayout = 16843626; // 0x101036a
+    field public static final int textEditSuggestionItemLayout = 16843633; // 0x1010371
+    field public static final int textEditSuggestionsBottomWindowLayout = 16843631; // 0x101036f
+    field public static final int textEditSuggestionsTopWindowLayout = 16843632; // 0x1010370
     field public static final int textFilterEnabled = 16843007; // 0x10100ff
     field public static final int textIsSelectable = 16843542; // 0x1010316
     field public static final int textOff = 16843045; // 0x1010125
@@ -958,7 +990,7 @@
     field public static final int textSelectHandleWindowStyle = 16843464; // 0x10102c8
     field public static final int textSize = 16842901; // 0x1010095
     field public static final int textStyle = 16842903; // 0x1010097
-    field public static final int textSuggestionsWindowStyle = 16843624; // 0x1010368
+    field public static final int textSuggestionsWindowStyle = 16843630; // 0x101036e
     field public static final int textViewStyle = 16842884; // 0x1010084
     field public static final int theme = 16842752; // 0x1010000
     field public static final int thickness = 16843360; // 0x1010260
@@ -979,6 +1011,7 @@
     field public static final int toYScale = 16843205; // 0x10101c5
     field public static final int top = 16843182; // 0x10101ae
     field public static final int topBright = 16842955; // 0x10100cb
+    field public static final int topChevronDrawable = 16843660; // 0x101038c
     field public static final int topDark = 16842951; // 0x10100c7
     field public static final int topLeftRadius = 16843177; // 0x10101a9
     field public static final int topOffset = 16843352; // 0x1010258
@@ -994,7 +1027,7 @@
     field public static final int unfocusedMonthDateColor = 16843588; // 0x1010344
     field public static final int unselectedAlpha = 16843278; // 0x101020e
     field public static final int updatePeriodMillis = 16843344; // 0x1010250
-    field public static final int useDefaultMargins = 16843635; // 0x1010373
+    field public static final int useDefaultMargins = 16843641; // 0x1010379
     field public static final int useIntrinsicSizeAsMinimum = 16843536; // 0x1010310
     field public static final int useLevel = 16843167; // 0x101019f
     field public static final int userVisible = 16843409; // 0x1010291
@@ -1008,8 +1041,10 @@
     field public static final int verticalCorrection = 16843322; // 0x101023a
     field public static final int verticalDivider = 16843054; // 0x101012e
     field public static final int verticalGap = 16843328; // 0x1010240
+    field public static final int verticalOffset = 16843668; // 0x1010394
     field public static final int verticalScrollbarPosition = 16843572; // 0x1010334
     field public static final int verticalSpacing = 16843029; // 0x1010115
+    field public static final int vibrationDuration = 16843665; // 0x1010391
     field public static final int visibility = 16842972; // 0x10100dc
     field public static final int visible = 16843156; // 0x1010194
     field public static final int vmSafeMode = 16843448; // 0x10102b8
@@ -1026,6 +1061,7 @@
     field public static final int wallpaperIntraOpenExitAnimation = 16843416; // 0x1010298
     field public static final int wallpaperOpenEnterAnimation = 16843411; // 0x1010293
     field public static final int wallpaperOpenExitAnimation = 16843412; // 0x1010294
+    field public static final int waveDrawable = 16843662; // 0x101038e
     field public static final int webTextViewStyle = 16843449; // 0x10102b9
     field public static final int webViewStyle = 16842885; // 0x1010085
     field public static final int weekDayTextAppearance = 16843592; // 0x1010348
@@ -1342,6 +1378,7 @@
     field public static final int config_longAnimTime = 17694722; // 0x10e0002
     field public static final int config_mediumAnimTime = 17694721; // 0x10e0001
     field public static final int config_shortAnimTime = 17694720; // 0x10e0000
+    field public static final int status_bar_notification_info_maxnum = 17694723; // 0x10e0003
   }
 
   public static final class R.interpolator {
@@ -1428,6 +1465,7 @@
     field public static final int search_go = 17039372; // 0x104000c
     field public static final int selectAll = 17039373; // 0x104000d
     field public static final int selectTextMode = 17039382; // 0x1040016
+    field public static final int status_bar_notification_info_overflow = 17039383; // 0x1040017
     field public static final int unknownName = 17039374; // 0x104000e
     field public static final int untitled = 17039375; // 0x104000f
     field public static final int yes = 17039379; // 0x1040013
@@ -1456,6 +1494,35 @@
     field public static final int MediaButton_Rew = 16973884; // 0x103003c
     field public static final int TextAppearance = 16973886; // 0x103003e
     field public static final int TextAppearance_DialogWindowTitle = 16973889; // 0x1030041
+    field public static final int TextAppearance_Holo = 16974075; // 0x10300fb
+    field public static final int TextAppearance_Holo_DialogWindowTitle = 16974103; // 0x1030117
+    field public static final int TextAppearance_Holo_Inverse = 16974076; // 0x10300fc
+    field public static final int TextAppearance_Holo_Large = 16974077; // 0x10300fd
+    field public static final int TextAppearance_Holo_Large_Inverse = 16974078; // 0x10300fe
+    field public static final int TextAppearance_Holo_Medium = 16974079; // 0x10300ff
+    field public static final int TextAppearance_Holo_Medium_Inverse = 16974080; // 0x1030100
+    field public static final int TextAppearance_Holo_SearchResult_Subtitle = 16974084; // 0x1030104
+    field public static final int TextAppearance_Holo_SearchResult_Title = 16974083; // 0x1030103
+    field public static final int TextAppearance_Holo_Small = 16974081; // 0x1030101
+    field public static final int TextAppearance_Holo_Small_Inverse = 16974082; // 0x1030102
+    field public static final int TextAppearance_Holo_Widget = 16974085; // 0x1030105
+    field public static final int TextAppearance_Holo_Widget_ActionBar_Subtitle = 16974099; // 0x1030113
+    field public static final int TextAppearance_Holo_Widget_ActionBar_Title = 16974098; // 0x1030112
+    field public static final int TextAppearance_Holo_Widget_ActionMode_Subtitle = 16974101; // 0x1030115
+    field public static final int TextAppearance_Holo_Widget_ActionMode_Title = 16974100; // 0x1030114
+    field public static final int TextAppearance_Holo_Widget_Button = 16974086; // 0x1030106
+    field public static final int TextAppearance_Holo_Widget_DropDownHint = 16974091; // 0x103010b
+    field public static final int TextAppearance_Holo_Widget_DropDownItem = 16974092; // 0x103010c
+    field public static final int TextAppearance_Holo_Widget_EditText = 16974094; // 0x103010e
+    field public static final int TextAppearance_Holo_Widget_IconMenu_Item = 16974087; // 0x1030107
+    field public static final int TextAppearance_Holo_Widget_PopupMenu = 16974095; // 0x103010f
+    field public static final int TextAppearance_Holo_Widget_PopupMenu_Large = 16974096; // 0x1030110
+    field public static final int TextAppearance_Holo_Widget_PopupMenu_Small = 16974097; // 0x1030111
+    field public static final int TextAppearance_Holo_Widget_TabWidget = 16974088; // 0x1030108
+    field public static final int TextAppearance_Holo_Widget_TextView = 16974089; // 0x1030109
+    field public static final int TextAppearance_Holo_Widget_TextView_PopupMenu = 16974090; // 0x103010a
+    field public static final int TextAppearance_Holo_Widget_TextView_SpinnerItem = 16974093; // 0x103010d
+    field public static final int TextAppearance_Holo_WindowTitle = 16974102; // 0x1030116
     field public static final int TextAppearance_Inverse = 16973887; // 0x103003f
     field public static final int TextAppearance_Large = 16973890; // 0x1030042
     field public static final int TextAppearance_Large_Inverse = 16973891; // 0x1030043
@@ -1503,12 +1570,13 @@
     field public static final int Theme_Holo_Light_Dialog_NoActionBar = 16973941; // 0x1030075
     field public static final int Theme_Holo_Light_Dialog_NoActionBar_MinWidth = 16973942; // 0x1030076
     field public static final int Theme_Holo_Light_NoActionBar = 16974064; // 0x10300f0
+    field public static final int Theme_Holo_Light_NoActionBar_Fullscreen = 16974065; // 0x10300f1
     field public static final int Theme_Holo_Light_Panel = 16973948; // 0x103007c
-    field public static final int Theme_Holo_Light_SplitActionBarWhenNarrow = 16974067; // 0x10300f3
+    field public static final int Theme_Holo_Light_SplitActionBarWhenNarrow = 16974106; // 0x103011a
     field public static final int Theme_Holo_NoActionBar = 16973932; // 0x103006c
     field public static final int Theme_Holo_NoActionBar_Fullscreen = 16973933; // 0x103006d
     field public static final int Theme_Holo_Panel = 16973947; // 0x103007b
-    field public static final int Theme_Holo_SplitActionBarWhenNarrow = 16974066; // 0x10300f2
+    field public static final int Theme_Holo_SplitActionBarWhenNarrow = 16974105; // 0x1030119
     field public static final int Theme_Holo_Wallpaper = 16973949; // 0x103007d
     field public static final int Theme_Holo_Wallpaper_NoTitleBar = 16973950; // 0x103007e
     field public static final int Theme_InputMethod = 16973908; // 0x1030054
@@ -1533,6 +1601,9 @@
     field public static final int Widget = 16973842; // 0x1030012
     field public static final int Widget_AbsListView = 16973843; // 0x1030013
     field public static final int Widget_ActionBar = 16973954; // 0x1030082
+    field public static final int Widget_ActionBar_TabBar = 16974068; // 0x10300f4
+    field public static final int Widget_ActionBar_TabText = 16974067; // 0x10300f3
+    field public static final int Widget_ActionBar_TabView = 16974066; // 0x10300f2
     field public static final int Widget_ActionButton = 16973956; // 0x1030084
     field public static final int Widget_ActionButton_CloseMode = 16973960; // 0x1030088
     field public static final int Widget_ActionButton_Overflow = 16973959; // 0x1030087
@@ -1556,6 +1627,9 @@
     field public static final int Widget_GridView = 16973874; // 0x1030032
     field public static final int Widget_Holo = 16973962; // 0x103008a
     field public static final int Widget_Holo_ActionBar = 16974004; // 0x10300b4
+    field public static final int Widget_Holo_ActionBar_TabBar = 16974071; // 0x10300f7
+    field public static final int Widget_Holo_ActionBar_TabText = 16974070; // 0x10300f6
+    field public static final int Widget_Holo_ActionBar_TabView = 16974069; // 0x10300f5
     field public static final int Widget_Holo_ActionButton = 16973999; // 0x10300af
     field public static final int Widget_Holo_ActionButton_CloseMode = 16974003; // 0x10300b3
     field public static final int Widget_Holo_ActionButton_Overflow = 16974000; // 0x10300b0
@@ -1564,6 +1638,7 @@
     field public static final int Widget_Holo_AutoCompleteTextView = 16973968; // 0x1030090
     field public static final int Widget_Holo_Button = 16973963; // 0x103008b
     field public static final int Widget_Holo_Button_Borderless = 16974050; // 0x10300e2
+    field public static final int Widget_Holo_Button_Borderless_Small = 16974107; // 0x103011b
     field public static final int Widget_Holo_Button_Inset = 16973965; // 0x103008d
     field public static final int Widget_Holo_Button_Small = 16973964; // 0x103008c
     field public static final int Widget_Holo_Button_Toggle = 16973966; // 0x103008e
@@ -1581,12 +1656,16 @@
     field public static final int Widget_Holo_ImageButton = 16973974; // 0x1030096
     field public static final int Widget_Holo_Light = 16974005; // 0x10300b5
     field public static final int Widget_Holo_Light_ActionBar = 16974049; // 0x10300e1
+    field public static final int Widget_Holo_Light_ActionBar_TabBar = 16974074; // 0x10300fa
+    field public static final int Widget_Holo_Light_ActionBar_TabText = 16974073; // 0x10300f9
+    field public static final int Widget_Holo_Light_ActionBar_TabView = 16974072; // 0x10300f8
     field public static final int Widget_Holo_Light_ActionButton = 16974045; // 0x10300dd
     field public static final int Widget_Holo_Light_ActionButton_CloseMode = 16974048; // 0x10300e0
     field public static final int Widget_Holo_Light_ActionButton_Overflow = 16974046; // 0x10300de
     field public static final int Widget_Holo_Light_ActionMode = 16974047; // 0x10300df
     field public static final int Widget_Holo_Light_AutoCompleteTextView = 16974011; // 0x10300bb
     field public static final int Widget_Holo_Light_Button = 16974006; // 0x10300b6
+    field public static final int Widget_Holo_Light_Button_Borderless_Small = 16974108; // 0x103011c
     field public static final int Widget_Holo_Light_Button_Inset = 16974008; // 0x10300b8
     field public static final int Widget_Holo_Light_Button_Small = 16974007; // 0x10300b7
     field public static final int Widget_Holo_Light_Button_Toggle = 16974009; // 0x10300b9
@@ -1693,11 +1772,18 @@
     method protected void onServiceConnected();
     method public final void setServiceInfo(android.accessibilityservice.AccessibilityServiceInfo);
     field public static final java.lang.String SERVICE_INTERFACE = "android.accessibilityservice.AccessibilityService";
+    field public static final java.lang.String SERVICE_META_DATA = "android.accessibilityservice";
   }
 
   public class AccessibilityServiceInfo implements android.os.Parcelable {
     ctor public AccessibilityServiceInfo();
     method public int describeContents();
+    method public static java.lang.String feedbackTypeToString(int);
+    method public static java.lang.String flagToString(int);
+    method public boolean getCanRetrieveWindowContent();
+    method public java.lang.String getId();
+    method public android.content.pm.ResolveInfo getResolveInfo();
+    method public java.lang.String getSettingsActivityName();
     method public void writeToParcel(android.os.Parcel, int);
     field public static final android.os.Parcelable.Creator CREATOR;
     field public static final int DEFAULT = 1; // 0x1
@@ -1947,12 +2033,12 @@
 
   public class FloatEvaluator implements android.animation.TypeEvaluator {
     ctor public FloatEvaluator();
-    method public java.lang.Object evaluate(float, java.lang.Object, java.lang.Object);
+    method public java.lang.Float evaluate(float, java.lang.Number, java.lang.Number);
   }
 
   public class IntEvaluator implements android.animation.TypeEvaluator {
     ctor public IntEvaluator();
-    method public java.lang.Object evaluate(float, java.lang.Object, java.lang.Object);
+    method public java.lang.Integer evaluate(float, java.lang.Integer, java.lang.Integer);
   }
 
   public abstract class Keyframe implements java.lang.Cloneable {
@@ -2013,9 +2099,13 @@
     method public java.lang.String getPropertyName();
     method public java.lang.Object getTarget();
     method public static android.animation.ObjectAnimator ofFloat(java.lang.Object, java.lang.String, float...);
+    method public static android.animation.ObjectAnimator ofFloat(T, android.util.Property<T, java.lang.Float>, float...);
     method public static android.animation.ObjectAnimator ofInt(java.lang.Object, java.lang.String, int...);
+    method public static android.animation.ObjectAnimator ofInt(T, android.util.Property<T, java.lang.Integer>, int...);
     method public static android.animation.ObjectAnimator ofObject(java.lang.Object, java.lang.String, android.animation.TypeEvaluator, java.lang.Object...);
+    method public static android.animation.ObjectAnimator ofObject(T, android.util.Property<T, V>, android.animation.TypeEvaluator<V>, V...);
     method public static android.animation.ObjectAnimator ofPropertyValuesHolder(java.lang.Object, android.animation.PropertyValuesHolder...);
+    method public void setProperty(android.util.Property);
     method public void setPropertyName(java.lang.String);
   }
 
@@ -2023,14 +2113,19 @@
     method public android.animation.PropertyValuesHolder clone();
     method public java.lang.String getPropertyName();
     method public static android.animation.PropertyValuesHolder ofFloat(java.lang.String, float...);
+    method public static android.animation.PropertyValuesHolder ofFloat(android.util.Property<?, java.lang.Float>, float...);
     method public static android.animation.PropertyValuesHolder ofInt(java.lang.String, int...);
+    method public static android.animation.PropertyValuesHolder ofInt(android.util.Property<?, java.lang.Integer>, int...);
     method public static android.animation.PropertyValuesHolder ofKeyframe(java.lang.String, android.animation.Keyframe...);
+    method public static android.animation.PropertyValuesHolder ofKeyframe(android.util.Property, android.animation.Keyframe...);
     method public static android.animation.PropertyValuesHolder ofObject(java.lang.String, android.animation.TypeEvaluator, java.lang.Object...);
+    method public static android.animation.PropertyValuesHolder ofObject(android.util.Property, android.animation.TypeEvaluator<V>, V...);
     method public void setEvaluator(android.animation.TypeEvaluator);
     method public void setFloatValues(float...);
     method public void setIntValues(int...);
     method public void setKeyframes(android.animation.Keyframe...);
     method public void setObjectValues(java.lang.Object...);
+    method public void setProperty(android.util.Property);
     method public void setPropertyName(java.lang.String);
   }
 
@@ -2039,7 +2134,7 @@
   }
 
   public abstract interface TypeEvaluator {
-    method public abstract java.lang.Object evaluate(float, java.lang.Object, java.lang.Object);
+    method public abstract T evaluate(float, T, T);
   }
 
   public class ValueAnimator extends android.animation.Animator {
@@ -2361,7 +2456,7 @@
     field public static final int RESULT_OK = -1; // 0xffffffff
   }
 
-  public class ActivityGroup extends android.app.Activity {
+  public deprecated class ActivityGroup extends android.app.Activity {
     ctor public ActivityGroup();
     ctor public ActivityGroup(boolean);
     method public android.app.Activity getCurrentActivity();
@@ -2839,6 +2934,7 @@
     method public static android.app.Fragment instantiate(android.content.Context, java.lang.String);
     method public static android.app.Fragment instantiate(android.content.Context, java.lang.String, android.os.Bundle);
     method public final boolean isAdded();
+    method public final boolean isDetached();
     method public final boolean isHidden();
     method public final boolean isInLayout();
     method public final boolean isRemoving();
@@ -2874,6 +2970,7 @@
     method public void registerForContextMenu(android.view.View);
     method public void setArguments(android.os.Bundle);
     method public void setHasOptionsMenu(boolean);
+    method public void setInitialSavedState(android.app.Fragment.SavedState);
     method public void setRetainInstance(boolean);
     method public void setTargetFragment(android.app.Fragment, int);
     method public void startActivity(android.content.Intent);
@@ -2885,6 +2982,12 @@
     ctor public Fragment.InstantiationException(java.lang.String, java.lang.Exception);
   }
 
+  public static class Fragment.SavedState implements android.os.Parcelable {
+    method public int describeContents();
+    method public void writeToParcel(android.os.Parcel, int);
+    field public static final android.os.Parcelable.ClassLoaderCreator CREATOR;
+  }
+
   public class FragmentBreadCrumbs extends android.view.ViewGroup implements android.app.FragmentManager.OnBackStackChangedListener {
     ctor public FragmentBreadCrumbs(android.content.Context);
     ctor public FragmentBreadCrumbs(android.content.Context, android.util.AttributeSet);
@@ -2922,6 +3025,7 @@
     method public abstract boolean popBackStackImmediate(int, int);
     method public abstract void putFragment(android.os.Bundle, java.lang.String, android.app.Fragment);
     method public abstract void removeOnBackStackChangedListener(android.app.FragmentManager.OnBackStackChangedListener);
+    method public abstract android.app.Fragment.SavedState saveFragmentInstanceState(android.app.Fragment);
     field public static final int POP_BACK_STACK_INCLUSIVE = 1; // 0x1
   }
 
@@ -3141,7 +3245,7 @@
     method public abstract void onLoaderReset(android.content.Loader<D>);
   }
 
-  public class LocalActivityManager {
+  public deprecated class LocalActivityManager {
     ctor public LocalActivityManager(android.app.Activity, boolean);
     method public android.view.Window destroyActivity(java.lang.String, boolean);
     method public void dispatchCreate(android.os.Bundle);
@@ -3424,7 +3528,7 @@
     field public static final int START_STICKY_COMPATIBILITY = 0; // 0x0
   }
 
-  public class TabActivity extends android.app.ActivityGroup {
+  public deprecated class TabActivity extends android.app.ActivityGroup {
     ctor public TabActivity();
     method public android.widget.TabHost getTabHost();
     method public android.widget.TabWidget getTabWidget();
@@ -3525,6 +3629,7 @@
     method public void writeToParcel(android.os.Parcel, int);
     field public static final android.os.Parcelable.Creator CREATOR;
     field public static final int USES_ENCRYPTED_STORAGE = 7; // 0x7
+    field public static final int USES_POLICY_DISABLE_CAMERA = 8; // 0x8
     field public static final int USES_POLICY_EXPIRE_PASSWORD = 6; // 0x6
     field public static final int USES_POLICY_FORCE_LOCK = 3; // 0x3
     field public static final int USES_POLICY_LIMIT_PASSWORD = 0; // 0x0
@@ -3558,6 +3663,7 @@
 
   public class DevicePolicyManager {
     method public java.util.List<android.content.ComponentName> getActiveAdmins();
+    method public boolean getCameraDisabled(android.content.ComponentName);
     method public int getCurrentFailedPasswordAttempts();
     method public int getMaximumFailedPasswordsForWipe(android.content.ComponentName);
     method public long getMaximumTimeToLock(android.content.ComponentName);
@@ -3581,6 +3687,7 @@
     method public void lockNow();
     method public void removeActiveAdmin(android.content.ComponentName);
     method public boolean resetPassword(java.lang.String, int);
+    method public void setCameraDisabled(android.content.ComponentName, boolean);
     method public void setMaximumFailedPasswordsForWipe(android.content.ComponentName, int);
     method public void setMaximumTimeToLock(android.content.ComponentName, long);
     method public void setPasswordExpirationTimeout(android.content.ComponentName, long);
@@ -4117,6 +4224,7 @@
     method public java.io.InputStream getInputStream() throws java.io.IOException;
     method public java.io.OutputStream getOutputStream() throws java.io.IOException;
     method public android.bluetooth.BluetoothDevice getRemoteDevice();
+    method public boolean isConnected();
   }
 
 }
@@ -4938,6 +5046,7 @@
     field public static final java.lang.String ACTION_INSERT_OR_EDIT = "android.intent.action.INSERT_OR_EDIT";
     field public static final java.lang.String ACTION_LOCALE_CHANGED = "android.intent.action.LOCALE_CHANGED";
     field public static final java.lang.String ACTION_MAIN = "android.intent.action.MAIN";
+    field public static final java.lang.String ACTION_MANAGE_NETWORK_USAGE = "android.intent.action.MANAGE_NETWORK_USAGE";
     field public static final java.lang.String ACTION_MANAGE_PACKAGE_STORAGE = "android.intent.action.MANAGE_PACKAGE_STORAGE";
     field public static final java.lang.String ACTION_MEDIA_BAD_REMOVAL = "android.intent.action.MEDIA_BAD_REMOVAL";
     field public static final java.lang.String ACTION_MEDIA_BUTTON = "android.intent.action.MEDIA_BUTTON";
@@ -4986,8 +5095,8 @@
     field public static final java.lang.String ACTION_TIME_CHANGED = "android.intent.action.TIME_SET";
     field public static final java.lang.String ACTION_TIME_TICK = "android.intent.action.TIME_TICK";
     field public static final java.lang.String ACTION_UID_REMOVED = "android.intent.action.UID_REMOVED";
-    field public static final java.lang.String ACTION_UMS_CONNECTED = "android.intent.action.UMS_CONNECTED";
-    field public static final java.lang.String ACTION_UMS_DISCONNECTED = "android.intent.action.UMS_DISCONNECTED";
+    field public static final deprecated java.lang.String ACTION_UMS_CONNECTED = "android.intent.action.UMS_CONNECTED";
+    field public static final deprecated java.lang.String ACTION_UMS_DISCONNECTED = "android.intent.action.UMS_DISCONNECTED";
     field public static final java.lang.String ACTION_USER_PRESENT = "android.intent.action.USER_PRESENT";
     field public static final java.lang.String ACTION_VIEW = "android.intent.action.VIEW";
     field public static final java.lang.String ACTION_VOICE_COMMAND = "android.intent.action.VOICE_COMMAND";
@@ -5485,15 +5594,18 @@
     field public static final int FLAG_VM_SAFE_MODE = 16384; // 0x4000
     field public java.lang.String backupAgentName;
     field public java.lang.String className;
+    field public int compatibleWidthLimitDp;
     field public java.lang.String dataDir;
     field public int descriptionRes;
     field public boolean enabled;
     field public int flags;
+    field public int largestWidthLimitDp;
     field public java.lang.String manageSpaceActivityName;
     field public java.lang.String nativeLibraryDir;
     field public java.lang.String permission;
     field public java.lang.String processName;
     field public java.lang.String publicSourceDir;
+    field public int requiresSmallestWidthDp;
     field public java.lang.String[] sharedLibraryFiles;
     field public java.lang.String sourceDir;
     field public int targetSdkVersion;
@@ -5700,6 +5812,7 @@
     method public abstract void setInstallerPackageName(java.lang.String, java.lang.String);
     field public static final int COMPONENT_ENABLED_STATE_DEFAULT = 0; // 0x0
     field public static final int COMPONENT_ENABLED_STATE_DISABLED = 2; // 0x2
+    field public static final int COMPONENT_ENABLED_STATE_DISABLED_USER = 3; // 0x3
     field public static final int COMPONENT_ENABLED_STATE_ENABLED = 1; // 0x1
     field public static final int DONT_KILL_APP = 1; // 0x1
     field public static final java.lang.String FEATURE_AUDIO_LOW_LATENCY = "android.hardware.audio.low_latency";
@@ -5709,12 +5822,16 @@
     field public static final java.lang.String FEATURE_CAMERA_FLASH = "android.hardware.camera.flash";
     field public static final java.lang.String FEATURE_CAMERA_FRONT = "android.hardware.camera.front";
     field public static final java.lang.String FEATURE_FAKETOUCH = "android.hardware.faketouch";
+    field public static final java.lang.String FEATURE_FAKETOUCH_MULTITOUCH_DISTINCT = "android.hardware.faketouch.multitouch.distinct";
+    field public static final java.lang.String FEATURE_FAKETOUCH_MULTITOUCH_JAZZHAND = "android.hardware.faketouch.multitouch.jazzhand";
     field public static final java.lang.String FEATURE_LIVE_WALLPAPER = "android.software.live_wallpaper";
     field public static final java.lang.String FEATURE_LOCATION = "android.hardware.location";
     field public static final java.lang.String FEATURE_LOCATION_GPS = "android.hardware.location.gps";
     field public static final java.lang.String FEATURE_LOCATION_NETWORK = "android.hardware.location.network";
     field public static final java.lang.String FEATURE_MICROPHONE = "android.hardware.microphone";
     field public static final java.lang.String FEATURE_NFC = "android.hardware.nfc";
+    field public static final java.lang.String FEATURE_SCREEN_LANDSCAPE = "android.hardware.screen.landscape";
+    field public static final java.lang.String FEATURE_SCREEN_PORTRAIT = "android.hardware.screen.portrait";
     field public static final java.lang.String FEATURE_SENSOR_ACCELEROMETER = "android.hardware.sensor.accelerometer";
     field public static final java.lang.String FEATURE_SENSOR_BAROMETER = "android.hardware.sensor.barometer";
     field public static final java.lang.String FEATURE_SENSOR_COMPASS = "android.hardware.sensor.compass";
@@ -6322,6 +6439,9 @@
   public static final class CursorJoiner.Result extends java.lang.Enum {
     method public static android.database.CursorJoiner.Result valueOf(java.lang.String);
     method public static final android.database.CursorJoiner.Result[] values();
+    enum_constant public static final android.database.CursorJoiner.Result BOTH;
+    enum_constant public static final android.database.CursorJoiner.Result LEFT;
+    enum_constant public static final android.database.CursorJoiner.Result RIGHT;
   }
 
   public class CursorWindow extends android.database.sqlite.SQLiteClosable implements android.os.Parcelable {
@@ -6796,6 +6916,7 @@
     method public void setCursorFactory(android.database.sqlite.SQLiteDatabase.CursorFactory);
     method public void setDistinct(boolean);
     method public void setProjectionMap(java.util.Map<java.lang.String, java.lang.String>);
+    method public void setStrict(boolean);
     method public void setTables(java.lang.String);
   }
 
@@ -7240,6 +7361,8 @@
   public static final class AvoidXfermode.Mode extends java.lang.Enum {
     method public static android.graphics.AvoidXfermode.Mode valueOf(java.lang.String);
     method public static final android.graphics.AvoidXfermode.Mode[] values();
+    enum_constant public static final android.graphics.AvoidXfermode.Mode AVOID;
+    enum_constant public static final android.graphics.AvoidXfermode.Mode TARGET;
   }
 
   public final class Bitmap implements android.os.Parcelable {
@@ -7292,11 +7415,17 @@
   public static final class Bitmap.CompressFormat extends java.lang.Enum {
     method public static android.graphics.Bitmap.CompressFormat valueOf(java.lang.String);
     method public static final android.graphics.Bitmap.CompressFormat[] values();
+    enum_constant public static final android.graphics.Bitmap.CompressFormat JPEG;
+    enum_constant public static final android.graphics.Bitmap.CompressFormat PNG;
   }
 
   public static final class Bitmap.Config extends java.lang.Enum {
     method public static android.graphics.Bitmap.Config valueOf(java.lang.String);
     method public static final android.graphics.Bitmap.Config[] values();
+    enum_constant public static final android.graphics.Bitmap.Config ALPHA_8;
+    enum_constant public static final deprecated android.graphics.Bitmap.Config ARGB_4444;
+    enum_constant public static final android.graphics.Bitmap.Config ARGB_8888;
+    enum_constant public static final android.graphics.Bitmap.Config RGB_565;
   }
 
   public class BitmapFactory {
@@ -7360,6 +7489,10 @@
   public static final class BlurMaskFilter.Blur extends java.lang.Enum {
     method public static android.graphics.BlurMaskFilter.Blur valueOf(java.lang.String);
     method public static final android.graphics.BlurMaskFilter.Blur[] values();
+    enum_constant public static final android.graphics.BlurMaskFilter.Blur INNER;
+    enum_constant public static final android.graphics.BlurMaskFilter.Blur NORMAL;
+    enum_constant public static final android.graphics.BlurMaskFilter.Blur OUTER;
+    enum_constant public static final android.graphics.BlurMaskFilter.Blur SOLID;
   }
 
   public class Camera {
@@ -7473,11 +7606,16 @@
   public static final class Canvas.EdgeType extends java.lang.Enum {
     method public static android.graphics.Canvas.EdgeType valueOf(java.lang.String);
     method public static final android.graphics.Canvas.EdgeType[] values();
+    enum_constant public static final android.graphics.Canvas.EdgeType AA;
+    enum_constant public static final android.graphics.Canvas.EdgeType BW;
   }
 
   public static final class Canvas.VertexMode extends java.lang.Enum {
     method public static android.graphics.Canvas.VertexMode valueOf(java.lang.String);
     method public static final android.graphics.Canvas.VertexMode[] values();
+    enum_constant public static final android.graphics.Canvas.VertexMode TRIANGLES;
+    enum_constant public static final android.graphics.Canvas.VertexMode TRIANGLE_FAN;
+    enum_constant public static final android.graphics.Canvas.VertexMode TRIANGLE_STRIP;
   }
 
   public class Color {
@@ -7592,6 +7730,9 @@
   public static final class Interpolator.Result extends java.lang.Enum {
     method public static android.graphics.Interpolator.Result valueOf(java.lang.String);
     method public static final android.graphics.Interpolator.Result[] values();
+    enum_constant public static final android.graphics.Interpolator.Result FREEZE_END;
+    enum_constant public static final android.graphics.Interpolator.Result FREEZE_START;
+    enum_constant public static final android.graphics.Interpolator.Result NORMAL;
   }
 
   public class LayerRasterizer extends android.graphics.Rasterizer {
@@ -7675,6 +7816,10 @@
   public static final class Matrix.ScaleToFit extends java.lang.Enum {
     method public static android.graphics.Matrix.ScaleToFit valueOf(java.lang.String);
     method public static final android.graphics.Matrix.ScaleToFit[] values();
+    enum_constant public static final android.graphics.Matrix.ScaleToFit CENTER;
+    enum_constant public static final android.graphics.Matrix.ScaleToFit END;
+    enum_constant public static final android.graphics.Matrix.ScaleToFit FILL;
+    enum_constant public static final android.graphics.Matrix.ScaleToFit START;
   }
 
   public class Movie {
@@ -7804,11 +7949,17 @@
   public static final class Paint.Align extends java.lang.Enum {
     method public static android.graphics.Paint.Align valueOf(java.lang.String);
     method public static final android.graphics.Paint.Align[] values();
+    enum_constant public static final android.graphics.Paint.Align CENTER;
+    enum_constant public static final android.graphics.Paint.Align LEFT;
+    enum_constant public static final android.graphics.Paint.Align RIGHT;
   }
 
   public static final class Paint.Cap extends java.lang.Enum {
     method public static android.graphics.Paint.Cap valueOf(java.lang.String);
     method public static final android.graphics.Paint.Cap[] values();
+    enum_constant public static final android.graphics.Paint.Cap BUTT;
+    enum_constant public static final android.graphics.Paint.Cap ROUND;
+    enum_constant public static final android.graphics.Paint.Cap SQUARE;
   }
 
   public static class Paint.FontMetrics {
@@ -7832,11 +7983,17 @@
   public static final class Paint.Join extends java.lang.Enum {
     method public static android.graphics.Paint.Join valueOf(java.lang.String);
     method public static final android.graphics.Paint.Join[] values();
+    enum_constant public static final android.graphics.Paint.Join BEVEL;
+    enum_constant public static final android.graphics.Paint.Join MITER;
+    enum_constant public static final android.graphics.Paint.Join ROUND;
   }
 
   public static final class Paint.Style extends java.lang.Enum {
     method public static android.graphics.Paint.Style valueOf(java.lang.String);
     method public static final android.graphics.Paint.Style[] values();
+    enum_constant public static final android.graphics.Paint.Style FILL;
+    enum_constant public static final android.graphics.Paint.Style FILL_AND_STROKE;
+    enum_constant public static final android.graphics.Paint.Style STROKE;
   }
 
   public class PaintFlagsDrawFilter extends android.graphics.DrawFilter {
@@ -7888,11 +8045,17 @@
   public static final class Path.Direction extends java.lang.Enum {
     method public static android.graphics.Path.Direction valueOf(java.lang.String);
     method public static final android.graphics.Path.Direction[] values();
+    enum_constant public static final android.graphics.Path.Direction CCW;
+    enum_constant public static final android.graphics.Path.Direction CW;
   }
 
   public static final class Path.FillType extends java.lang.Enum {
     method public static android.graphics.Path.FillType valueOf(java.lang.String);
     method public static final android.graphics.Path.FillType[] values();
+    enum_constant public static final android.graphics.Path.FillType EVEN_ODD;
+    enum_constant public static final android.graphics.Path.FillType INVERSE_EVEN_ODD;
+    enum_constant public static final android.graphics.Path.FillType INVERSE_WINDING;
+    enum_constant public static final android.graphics.Path.FillType WINDING;
   }
 
   public class PathDashPathEffect extends android.graphics.PathEffect {
@@ -7902,6 +8065,9 @@
   public static final class PathDashPathEffect.Style extends java.lang.Enum {
     method public static android.graphics.PathDashPathEffect.Style valueOf(java.lang.String);
     method public static final android.graphics.PathDashPathEffect.Style[] values();
+    enum_constant public static final android.graphics.PathDashPathEffect.Style MORPH;
+    enum_constant public static final android.graphics.PathDashPathEffect.Style ROTATE;
+    enum_constant public static final android.graphics.PathDashPathEffect.Style TRANSLATE;
   }
 
   public class PathEffect {
@@ -8006,6 +8172,24 @@
   public static final class PorterDuff.Mode extends java.lang.Enum {
     method public static android.graphics.PorterDuff.Mode valueOf(java.lang.String);
     method public static final android.graphics.PorterDuff.Mode[] values();
+    enum_constant public static final android.graphics.PorterDuff.Mode ADD;
+    enum_constant public static final android.graphics.PorterDuff.Mode CLEAR;
+    enum_constant public static final android.graphics.PorterDuff.Mode DARKEN;
+    enum_constant public static final android.graphics.PorterDuff.Mode DST;
+    enum_constant public static final android.graphics.PorterDuff.Mode DST_ATOP;
+    enum_constant public static final android.graphics.PorterDuff.Mode DST_IN;
+    enum_constant public static final android.graphics.PorterDuff.Mode DST_OUT;
+    enum_constant public static final android.graphics.PorterDuff.Mode DST_OVER;
+    enum_constant public static final android.graphics.PorterDuff.Mode LIGHTEN;
+    enum_constant public static final android.graphics.PorterDuff.Mode MULTIPLY;
+    enum_constant public static final android.graphics.PorterDuff.Mode OVERLAY;
+    enum_constant public static final android.graphics.PorterDuff.Mode SCREEN;
+    enum_constant public static final android.graphics.PorterDuff.Mode SRC;
+    enum_constant public static final android.graphics.PorterDuff.Mode SRC_ATOP;
+    enum_constant public static final android.graphics.PorterDuff.Mode SRC_IN;
+    enum_constant public static final android.graphics.PorterDuff.Mode SRC_OUT;
+    enum_constant public static final android.graphics.PorterDuff.Mode SRC_OVER;
+    enum_constant public static final android.graphics.PorterDuff.Mode XOR;
   }
 
   public class PorterDuffColorFilter extends android.graphics.ColorFilter {
@@ -8147,6 +8331,12 @@
   public static final class Region.Op extends java.lang.Enum {
     method public static android.graphics.Region.Op valueOf(java.lang.String);
     method public static final android.graphics.Region.Op[] values();
+    enum_constant public static final android.graphics.Region.Op DIFFERENCE;
+    enum_constant public static final android.graphics.Region.Op INTERSECT;
+    enum_constant public static final android.graphics.Region.Op REPLACE;
+    enum_constant public static final android.graphics.Region.Op REVERSE_DIFFERENCE;
+    enum_constant public static final android.graphics.Region.Op UNION;
+    enum_constant public static final android.graphics.Region.Op XOR;
   }
 
   public class RegionIterator {
@@ -8163,6 +8353,9 @@
   public static final class Shader.TileMode extends java.lang.Enum {
     method public static android.graphics.Shader.TileMode valueOf(java.lang.String);
     method public static final android.graphics.Shader.TileMode[] values();
+    enum_constant public static final android.graphics.Shader.TileMode CLAMP;
+    enum_constant public static final android.graphics.Shader.TileMode MIRROR;
+    enum_constant public static final android.graphics.Shader.TileMode REPEAT;
   }
 
   public class SumPathEffect extends android.graphics.PathEffect {
@@ -8328,11 +8521,11 @@
     method public int getMinimumWidth();
     method public abstract int getOpacity();
     method public boolean getPadding(android.graphics.Rect);
+    method public int getResolvedLayoutDirectionSelf();
     method public int[] getState();
     method public android.graphics.Region getTransparentRegion();
     method public void inflate(android.content.res.Resources, org.xmlpull.v1.XmlPullParser, android.util.AttributeSet) throws java.io.IOException, org.xmlpull.v1.XmlPullParserException;
     method public void invalidateSelf();
-    method public boolean isLayoutRtlSelf();
     method public boolean isStateful();
     method public final boolean isVisible();
     method public void jumpToCurrentState();
@@ -8364,7 +8557,7 @@
   }
 
   public static abstract interface Drawable.Callback2 implements android.graphics.drawable.Drawable.Callback {
-    method public abstract boolean isLayoutRtl(android.graphics.drawable.Drawable);
+    method public abstract int getResolvedLayoutDirection(android.graphics.drawable.Drawable);
   }
 
   public static abstract class Drawable.ConstantState {
@@ -8443,6 +8636,14 @@
   public static final class GradientDrawable.Orientation extends java.lang.Enum {
     method public static android.graphics.drawable.GradientDrawable.Orientation valueOf(java.lang.String);
     method public static final android.graphics.drawable.GradientDrawable.Orientation[] values();
+    enum_constant public static final android.graphics.drawable.GradientDrawable.Orientation BL_TR;
+    enum_constant public static final android.graphics.drawable.GradientDrawable.Orientation BOTTOM_TOP;
+    enum_constant public static final android.graphics.drawable.GradientDrawable.Orientation BR_TL;
+    enum_constant public static final android.graphics.drawable.GradientDrawable.Orientation LEFT_RIGHT;
+    enum_constant public static final android.graphics.drawable.GradientDrawable.Orientation RIGHT_LEFT;
+    enum_constant public static final android.graphics.drawable.GradientDrawable.Orientation TL_BR;
+    enum_constant public static final android.graphics.drawable.GradientDrawable.Orientation TOP_BOTTOM;
+    enum_constant public static final android.graphics.drawable.GradientDrawable.Orientation TR_BL;
   }
 
   public class InsetDrawable extends android.graphics.drawable.Drawable implements android.graphics.drawable.Drawable.Callback {
@@ -10905,6 +11106,9 @@
   public static final class LocalSocketAddress.Namespace extends java.lang.Enum {
     method public static android.net.LocalSocketAddress.Namespace valueOf(java.lang.String);
     method public static final android.net.LocalSocketAddress.Namespace[] values();
+    enum_constant public static final android.net.LocalSocketAddress.Namespace ABSTRACT;
+    enum_constant public static final android.net.LocalSocketAddress.Namespace FILESYSTEM;
+    enum_constant public static final android.net.LocalSocketAddress.Namespace RESERVED;
   }
 
   public class MailTo {
@@ -10939,11 +11143,28 @@
   public static final class NetworkInfo.DetailedState extends java.lang.Enum {
     method public static android.net.NetworkInfo.DetailedState valueOf(java.lang.String);
     method public static final android.net.NetworkInfo.DetailedState[] values();
+    enum_constant public static final android.net.NetworkInfo.DetailedState AUTHENTICATING;
+    enum_constant public static final android.net.NetworkInfo.DetailedState BLOCKED;
+    enum_constant public static final android.net.NetworkInfo.DetailedState CONNECTED;
+    enum_constant public static final android.net.NetworkInfo.DetailedState CONNECTING;
+    enum_constant public static final android.net.NetworkInfo.DetailedState DISCONNECTED;
+    enum_constant public static final android.net.NetworkInfo.DetailedState DISCONNECTING;
+    enum_constant public static final android.net.NetworkInfo.DetailedState FAILED;
+    enum_constant public static final android.net.NetworkInfo.DetailedState IDLE;
+    enum_constant public static final android.net.NetworkInfo.DetailedState OBTAINING_IPADDR;
+    enum_constant public static final android.net.NetworkInfo.DetailedState SCANNING;
+    enum_constant public static final android.net.NetworkInfo.DetailedState SUSPENDED;
   }
 
   public static final class NetworkInfo.State extends java.lang.Enum {
     method public static android.net.NetworkInfo.State valueOf(java.lang.String);
     method public static final android.net.NetworkInfo.State[] values();
+    enum_constant public static final android.net.NetworkInfo.State CONNECTED;
+    enum_constant public static final android.net.NetworkInfo.State CONNECTING;
+    enum_constant public static final android.net.NetworkInfo.State DISCONNECTED;
+    enum_constant public static final android.net.NetworkInfo.State DISCONNECTING;
+    enum_constant public static final android.net.NetworkInfo.State SUSPENDED;
+    enum_constant public static final android.net.NetworkInfo.State UNKNOWN;
   }
 
   public class ParseException extends java.lang.RuntimeException {
@@ -10972,6 +11193,8 @@
     method public static org.apache.http.conn.ssl.SSLSocketFactory getHttpSocketFactory(int, android.net.SSLSessionCache);
     method public static javax.net.ssl.SSLSocketFactory getInsecure(int, android.net.SSLSessionCache);
     method public java.lang.String[] getSupportedCipherSuites();
+    method public void setKeyManagers(javax.net.ssl.KeyManager[]);
+    method public void setTrustManagers(javax.net.ssl.TrustManager[]);
   }
 
   public final class SSLSessionCache {
@@ -11475,6 +11698,19 @@
     method public static android.net.wifi.SupplicantState valueOf(java.lang.String);
     method public static final android.net.wifi.SupplicantState[] values();
     method public void writeToParcel(android.os.Parcel, int);
+    enum_constant public static final android.net.wifi.SupplicantState ASSOCIATED;
+    enum_constant public static final android.net.wifi.SupplicantState ASSOCIATING;
+    enum_constant public static final android.net.wifi.SupplicantState AUTHENTICATING;
+    enum_constant public static final android.net.wifi.SupplicantState COMPLETED;
+    enum_constant public static final android.net.wifi.SupplicantState DISCONNECTED;
+    enum_constant public static final android.net.wifi.SupplicantState DORMANT;
+    enum_constant public static final android.net.wifi.SupplicantState FOUR_WAY_HANDSHAKE;
+    enum_constant public static final android.net.wifi.SupplicantState GROUP_HANDSHAKE;
+    enum_constant public static final android.net.wifi.SupplicantState INACTIVE;
+    enum_constant public static final android.net.wifi.SupplicantState INTERFACE_DISABLED;
+    enum_constant public static final android.net.wifi.SupplicantState INVALID;
+    enum_constant public static final android.net.wifi.SupplicantState SCANNING;
+    enum_constant public static final android.net.wifi.SupplicantState UNINITIALIZED;
   }
 
   public class WifiConfiguration implements android.os.Parcelable {
@@ -13303,6 +13539,9 @@
   public static final class AsyncTask.Status extends java.lang.Enum {
     method public static android.os.AsyncTask.Status valueOf(java.lang.String);
     method public static final android.os.AsyncTask.Status[] values();
+    enum_constant public static final android.os.AsyncTask.Status FINISHED;
+    enum_constant public static final android.os.AsyncTask.Status PENDING;
+    enum_constant public static final android.os.AsyncTask.Status RUNNING;
   }
 
   public class BadParcelableException extends android.util.AndroidRuntimeException {
@@ -13362,6 +13601,7 @@
 
   public class Build {
     ctor public Build();
+    method public static java.lang.String getRadioVersion();
     field public static final java.lang.String BOARD;
     field public static final java.lang.String BOOTLOADER;
     field public static final java.lang.String BRAND;
@@ -13376,7 +13616,7 @@
     field public static final java.lang.String MANUFACTURER;
     field public static final java.lang.String MODEL;
     field public static final java.lang.String PRODUCT;
-    field public static final java.lang.String RADIO;
+    field public static final deprecated java.lang.String RADIO;
     field public static final java.lang.String SERIAL;
     field public static final java.lang.String TAGS;
     field public static final long TIME;
@@ -13409,7 +13649,7 @@
     field public static final int GINGERBREAD_MR1 = 10; // 0xa
     field public static final int HONEYCOMB = 11; // 0xb
     field public static final int HONEYCOMB_MR1 = 12; // 0xc
-    field public static final int HONEYCOMB_MR2 = 10000; // 0x2710
+    field public static final int HONEYCOMB_MR2 = 13; // 0xd
     field public static final int ICE_CREAM_SANDWICH = 10000; // 0x2710
   }
 
@@ -13771,6 +14011,7 @@
     field public static final int INTERFACE_TRANSACTION = 1598968902; // 0x5f4e5446
     field public static final int LAST_CALL_TRANSACTION = 16777215; // 0xffffff
     field public static final int PING_TRANSACTION = 1599098439; // 0x5f504e47
+    field public static final int TWEET_TRANSACTION = 1599362900; // 0x5f545754
   }
 
   public static abstract interface IBinder.DeathRecipient {
@@ -14021,6 +14262,10 @@
     field public static final int PARCELABLE_WRITE_RETURN_VALUE = 1; // 0x1
   }
 
+  public static abstract interface Parcelable.ClassLoaderCreator implements android.os.Parcelable.Creator {
+    method public abstract T createFromParcel(android.os.Parcel, java.lang.ClassLoader);
+  }
+
   public static abstract interface Parcelable.Creator {
     method public abstract T createFromParcel(android.os.Parcel);
     method public abstract T[] newArray(int);
@@ -14266,20 +14511,10 @@
 
 package android.preference {
 
-  public class CheckBoxPreference extends android.preference.Preference {
+  public class CheckBoxPreference extends android.preference.TwoStatePreference {
     ctor public CheckBoxPreference(android.content.Context, android.util.AttributeSet, int);
     ctor public CheckBoxPreference(android.content.Context, android.util.AttributeSet);
     ctor public CheckBoxPreference(android.content.Context);
-    method public boolean getDisableDependentsState();
-    method public java.lang.CharSequence getSummaryOff();
-    method public java.lang.CharSequence getSummaryOn();
-    method public boolean isChecked();
-    method public void setChecked(boolean);
-    method public void setDisableDependentsState(boolean);
-    method public void setSummaryOff(java.lang.CharSequence);
-    method public void setSummaryOff(int);
-    method public void setSummaryOn(java.lang.CharSequence);
-    method public void setSummaryOn(int);
   }
 
   public abstract class DialogPreference extends android.preference.Preference implements android.content.DialogInterface.OnClickListener android.content.DialogInterface.OnDismissListener android.preference.PreferenceManager.OnActivityDestroyListener {
@@ -14607,6 +14842,34 @@
     method public void setShowSilent(boolean);
   }
 
+  public class SwitchPreference extends android.preference.TwoStatePreference {
+    ctor public SwitchPreference(android.content.Context, android.util.AttributeSet, int);
+    ctor public SwitchPreference(android.content.Context, android.util.AttributeSet);
+    ctor public SwitchPreference(android.content.Context);
+    method public java.lang.CharSequence getSwitchTextOff();
+    method public java.lang.CharSequence getSwitchTextOn();
+    method public void setSwitchTextOff(java.lang.CharSequence);
+    method public void setSwitchTextOff(int);
+    method public void setSwitchTextOn(java.lang.CharSequence);
+    method public void setSwitchTextOn(int);
+  }
+
+  public abstract class TwoStatePreference extends android.preference.Preference {
+    ctor public TwoStatePreference(android.content.Context, android.util.AttributeSet, int);
+    ctor public TwoStatePreference(android.content.Context, android.util.AttributeSet);
+    ctor public TwoStatePreference(android.content.Context);
+    method public boolean getDisableDependentsState();
+    method public java.lang.CharSequence getSummaryOff();
+    method public java.lang.CharSequence getSummaryOn();
+    method public boolean isChecked();
+    method public void setChecked(boolean);
+    method public void setDisableDependentsState(boolean);
+    method public void setSummaryOff(java.lang.CharSequence);
+    method public void setSummaryOff(int);
+    method public void setSummaryOn(java.lang.CharSequence);
+    method public void setSummaryOn(int);
+  }
+
 }
 
 package android.provider {
@@ -15007,7 +15270,10 @@
     field public static final android.net.Uri AUTHORITY_URI;
     field public static final java.lang.String CALLER_IS_SYNCADAPTER = "caller_is_syncadapter";
     field public static final java.lang.String DIRECTORY_PARAM_KEY = "directory";
+    field public static final java.lang.String INCLUDE_PROFILE = "include_profile";
     field public static final java.lang.String LIMIT_PARAM_KEY = "limit";
+    field public static final java.lang.String PRIMARY_ACCOUNT_NAME = "name_for_primary_account";
+    field public static final java.lang.String PRIMARY_ACCOUNT_TYPE = "type_for_primary_account";
   }
 
   public static final class ContactsContract.AggregationExceptions implements android.provider.BaseColumns {
@@ -15306,6 +15572,7 @@
     field public static final java.lang.String DISPLAY_NAME = "display_name";
     field public static final java.lang.String HAS_PHONE_NUMBER = "has_phone_number";
     field public static final java.lang.String IN_VISIBLE_GROUP = "in_visible_group";
+    field public static final java.lang.String IS_USER_PROFILE = "is_user_profile";
     field public static final java.lang.String LOOKUP_KEY = "lookup";
     field public static final java.lang.String PHOTO_ID = "photo_id";
     field public static final java.lang.String PHOTO_THUMBNAIL_URI = "photo_thumb_uri";
@@ -15349,6 +15616,15 @@
   protected static abstract interface ContactsContract.DataColumnsWithJoins implements android.provider.BaseColumns android.provider.ContactsContract.ContactNameColumns android.provider.ContactsContract.ContactOptionsColumns android.provider.ContactsContract.ContactStatusColumns android.provider.ContactsContract.ContactsColumns android.provider.ContactsContract.DataColumns android.provider.ContactsContract.RawContactsColumns android.provider.ContactsContract.StatusColumns {
   }
 
+  public static final class ContactsContract.DataUsageFeedback {
+    ctor public ContactsContract.DataUsageFeedback();
+    field public static final android.net.Uri FEEDBACK_URI;
+    field public static final java.lang.String USAGE_TYPE = "type";
+    field public static final java.lang.String USAGE_TYPE_CALL = "call";
+    field public static final java.lang.String USAGE_TYPE_LONG_TEXT = "long_text";
+    field public static final java.lang.String USAGE_TYPE_SHORT_TEXT = "short_text";
+  }
+
   public static final class ContactsContract.Directory implements android.provider.BaseColumns {
     method public static void notifyDirectoryChange(android.content.ContentResolver);
     field public static final java.lang.String ACCOUNT_NAME = "accountName";
@@ -15489,6 +15765,12 @@
     field public static final java.lang.String PROTOCOL = "protocol";
   }
 
+  public static final class ContactsContract.Profile implements android.provider.BaseColumns android.provider.ContactsContract.ContactNameColumns android.provider.ContactsContract.ContactOptionsColumns android.provider.ContactsContract.ContactStatusColumns android.provider.ContactsContract.ContactsColumns {
+    field public static final android.net.Uri CONTENT_RAW_CONTACTS_URI;
+    field public static final android.net.Uri CONTENT_URI;
+    field public static final android.net.Uri CONTENT_VCARD_URI;
+  }
+
   public static final class ContactsContract.QuickContact {
     ctor public ContactsContract.QuickContact();
     method public static void showQuickContact(android.content.Context, android.view.View, android.net.Uri, int, java.lang.String[]);
@@ -15524,6 +15806,7 @@
     field public static final java.lang.String CONTACT_ID = "contact_id";
     field public static final java.lang.String DELETED = "deleted";
     field public static final java.lang.String RAW_CONTACT_IS_READ_ONLY = "raw_contact_is_read_only";
+    field public static final java.lang.String RAW_CONTACT_IS_USER_PROFILE = "raw_contact_is_user_profile";
   }
 
   public static final class ContactsContract.RawContactsEntity implements android.provider.BaseColumns android.provider.ContactsContract.DataColumns android.provider.ContactsContract.RawContactsColumns {
@@ -16238,6 +16521,7 @@
     method public void copy1DRangeFrom(int, int, short[]);
     method public void copy1DRangeFrom(int, int, byte[]);
     method public void copy1DRangeFrom(int, int, float[]);
+    method public void copy1DRangeFrom(int, int, android.renderscript.Allocation, int);
     method public void copy1DRangeFromUnchecked(int, int, int[]);
     method public void copy1DRangeFromUnchecked(int, int, short[]);
     method public void copy1DRangeFromUnchecked(int, int, byte[]);
@@ -16246,6 +16530,7 @@
     method public void copy2DRangeFrom(int, int, int, int, short[]);
     method public void copy2DRangeFrom(int, int, int, int, int[]);
     method public void copy2DRangeFrom(int, int, int, int, float[]);
+    method public void copy2DRangeFrom(int, int, int, int, android.renderscript.Allocation, int, int);
     method public void copy2DRangeFrom(int, int, android.graphics.Bitmap);
     method public void copyFrom(android.renderscript.BaseObj[]);
     method public void copyFrom(int[]);
@@ -16283,6 +16568,7 @@
     method public void setFromFieldPacker(int, int, android.renderscript.FieldPacker);
     method public void syncAll(int);
     field public static final int USAGE_GRAPHICS_CONSTANTS = 8; // 0x8
+    field public static final int USAGE_GRAPHICS_RENDER_TARGET = 16; // 0x10
     field public static final int USAGE_GRAPHICS_TEXTURE = 2; // 0x2
     field public static final int USAGE_GRAPHICS_VERTEX = 4; // 0x4
     field public static final int USAGE_SCRIPT = 1; // 0x1
@@ -16291,6 +16577,9 @@
   public static final class Allocation.MipmapControl extends java.lang.Enum {
     method public static android.renderscript.Allocation.MipmapControl valueOf(java.lang.String);
     method public static final android.renderscript.Allocation.MipmapControl[] values();
+    enum_constant public static final android.renderscript.Allocation.MipmapControl MIPMAP_FULL;
+    enum_constant public static final android.renderscript.Allocation.MipmapControl MIPMAP_NONE;
+    enum_constant public static final android.renderscript.Allocation.MipmapControl MIPMAP_ON_SYNC_TO_TEXTURE;
   }
 
   public class AllocationAdapter extends android.renderscript.Allocation {
@@ -16306,8 +16595,10 @@
     method public void subData1D(int, int, short[]);
     method public void subData1D(int, int, byte[]);
     method public void subData1D(int, int, float[]);
+    method public void subData1D(int, int, android.renderscript.AllocationAdapter, int);
     method public void subData2D(int, int, int, int, int[]);
     method public void subData2D(int, int, int, int, float[]);
+    method public void subData2D(int, int, int, int, android.renderscript.AllocationAdapter, int, int);
     method public void subElementData(int, int, android.renderscript.FieldPacker);
   }
 
@@ -16428,6 +16719,7 @@
     method public static android.renderscript.Element U8_4(android.renderscript.RenderScript);
     method public static android.renderscript.Element createPixel(android.renderscript.RenderScript, android.renderscript.Element.DataType, android.renderscript.Element.DataKind);
     method public static android.renderscript.Element createVector(android.renderscript.RenderScript, android.renderscript.Element.DataType, int);
+    method public boolean isCompatible(android.renderscript.Element);
     method public boolean isComplex();
   }
 
@@ -16441,11 +16733,45 @@
   public static final class Element.DataKind extends java.lang.Enum {
     method public static android.renderscript.Element.DataKind valueOf(java.lang.String);
     method public static final android.renderscript.Element.DataKind[] values();
+    enum_constant public static final android.renderscript.Element.DataKind PIXEL_A;
+    enum_constant public static final android.renderscript.Element.DataKind PIXEL_DEPTH;
+    enum_constant public static final android.renderscript.Element.DataKind PIXEL_L;
+    enum_constant public static final android.renderscript.Element.DataKind PIXEL_LA;
+    enum_constant public static final android.renderscript.Element.DataKind PIXEL_RGB;
+    enum_constant public static final android.renderscript.Element.DataKind PIXEL_RGBA;
+    enum_constant public static final android.renderscript.Element.DataKind USER;
   }
 
   public static final class Element.DataType extends java.lang.Enum {
     method public static android.renderscript.Element.DataType valueOf(java.lang.String);
     method public static final android.renderscript.Element.DataType[] values();
+    enum_constant public static final android.renderscript.Element.DataType BOOLEAN;
+    enum_constant public static final android.renderscript.Element.DataType FLOAT_32;
+    enum_constant public static final android.renderscript.Element.DataType FLOAT_64;
+    enum_constant public static final android.renderscript.Element.DataType MATRIX_2X2;
+    enum_constant public static final android.renderscript.Element.DataType MATRIX_3X3;
+    enum_constant public static final android.renderscript.Element.DataType MATRIX_4X4;
+    enum_constant public static final android.renderscript.Element.DataType RS_ALLOCATION;
+    enum_constant public static final android.renderscript.Element.DataType RS_ELEMENT;
+    enum_constant public static final android.renderscript.Element.DataType RS_MESH;
+    enum_constant public static final android.renderscript.Element.DataType RS_PROGRAM_FRAGMENT;
+    enum_constant public static final android.renderscript.Element.DataType RS_PROGRAM_RASTER;
+    enum_constant public static final android.renderscript.Element.DataType RS_PROGRAM_STORE;
+    enum_constant public static final android.renderscript.Element.DataType RS_PROGRAM_VERTEX;
+    enum_constant public static final android.renderscript.Element.DataType RS_SAMPLER;
+    enum_constant public static final android.renderscript.Element.DataType RS_SCRIPT;
+    enum_constant public static final android.renderscript.Element.DataType RS_TYPE;
+    enum_constant public static final android.renderscript.Element.DataType SIGNED_16;
+    enum_constant public static final android.renderscript.Element.DataType SIGNED_32;
+    enum_constant public static final android.renderscript.Element.DataType SIGNED_64;
+    enum_constant public static final android.renderscript.Element.DataType SIGNED_8;
+    enum_constant public static final android.renderscript.Element.DataType UNSIGNED_16;
+    enum_constant public static final android.renderscript.Element.DataType UNSIGNED_32;
+    enum_constant public static final android.renderscript.Element.DataType UNSIGNED_4_4_4_4;
+    enum_constant public static final android.renderscript.Element.DataType UNSIGNED_5_5_5_1;
+    enum_constant public static final android.renderscript.Element.DataType UNSIGNED_5_6_5;
+    enum_constant public static final android.renderscript.Element.DataType UNSIGNED_64;
+    enum_constant public static final android.renderscript.Element.DataType UNSIGNED_8;
   }
 
   public class FieldPacker {
@@ -16505,6 +16831,8 @@
   public static final class FileA3D.EntryType extends java.lang.Enum {
     method public static android.renderscript.FileA3D.EntryType valueOf(java.lang.String);
     method public static final android.renderscript.FileA3D.EntryType[] values();
+    enum_constant public static final android.renderscript.FileA3D.EntryType MESH;
+    enum_constant public static final android.renderscript.FileA3D.EntryType UNKNOWN;
   }
 
   public static class FileA3D.IndexEntry {
@@ -16549,6 +16877,10 @@
   public static final class Font.Style extends java.lang.Enum {
     method public static android.renderscript.Font.Style valueOf(java.lang.String);
     method public static final android.renderscript.Font.Style[] values();
+    enum_constant public static final android.renderscript.Font.Style BOLD;
+    enum_constant public static final android.renderscript.Font.Style BOLD_ITALIC;
+    enum_constant public static final android.renderscript.Font.Style ITALIC;
+    enum_constant public static final android.renderscript.Font.Style NORMAL;
   }
 
   public class Int2 {
@@ -16698,6 +17030,12 @@
   public static final class Mesh.Primitive extends java.lang.Enum {
     method public static android.renderscript.Mesh.Primitive valueOf(java.lang.String);
     method public static final android.renderscript.Mesh.Primitive[] values();
+    enum_constant public static final android.renderscript.Mesh.Primitive LINE;
+    enum_constant public static final android.renderscript.Mesh.Primitive LINE_STRIP;
+    enum_constant public static final android.renderscript.Mesh.Primitive POINT;
+    enum_constant public static final android.renderscript.Mesh.Primitive TRIANGLE;
+    enum_constant public static final android.renderscript.Mesh.Primitive TRIANGLE_FAN;
+    enum_constant public static final android.renderscript.Mesh.Primitive TRIANGLE_STRIP;
   }
 
   public static class Mesh.TriangleMeshBuilder {
@@ -16734,6 +17072,8 @@
   public static final class Program.TextureType extends java.lang.Enum {
     method public static android.renderscript.Program.TextureType valueOf(java.lang.String);
     method public static final android.renderscript.Program.TextureType[] values();
+    enum_constant public static final android.renderscript.Program.TextureType TEXTURE_2D;
+    enum_constant public static final android.renderscript.Program.TextureType TEXTURE_CUBE;
   }
 
   public class ProgramFragment extends android.renderscript.Program {
@@ -16759,11 +17099,18 @@
   public static final class ProgramFragmentFixedFunction.Builder.EnvMode extends java.lang.Enum {
     method public static android.renderscript.ProgramFragmentFixedFunction.Builder.EnvMode valueOf(java.lang.String);
     method public static final android.renderscript.ProgramFragmentFixedFunction.Builder.EnvMode[] values();
+    enum_constant public static final android.renderscript.ProgramFragmentFixedFunction.Builder.EnvMode DECAL;
+    enum_constant public static final android.renderscript.ProgramFragmentFixedFunction.Builder.EnvMode MODULATE;
+    enum_constant public static final android.renderscript.ProgramFragmentFixedFunction.Builder.EnvMode REPLACE;
   }
 
   public static final class ProgramFragmentFixedFunction.Builder.Format extends java.lang.Enum {
     method public static android.renderscript.ProgramFragmentFixedFunction.Builder.Format valueOf(java.lang.String);
     method public static final android.renderscript.ProgramFragmentFixedFunction.Builder.Format[] values();
+    enum_constant public static final android.renderscript.ProgramFragmentFixedFunction.Builder.Format ALPHA;
+    enum_constant public static final android.renderscript.ProgramFragmentFixedFunction.Builder.Format LUMINANCE_ALPHA;
+    enum_constant public static final android.renderscript.ProgramFragmentFixedFunction.Builder.Format RGB;
+    enum_constant public static final android.renderscript.ProgramFragmentFixedFunction.Builder.Format RGBA;
   }
 
   public class ProgramRaster extends android.renderscript.BaseObj {
@@ -16782,6 +17129,9 @@
   public static final class ProgramRaster.CullMode extends java.lang.Enum {
     method public static android.renderscript.ProgramRaster.CullMode valueOf(java.lang.String);
     method public static final android.renderscript.ProgramRaster.CullMode[] values();
+    enum_constant public static final android.renderscript.ProgramRaster.CullMode BACK;
+    enum_constant public static final android.renderscript.ProgramRaster.CullMode FRONT;
+    enum_constant public static final android.renderscript.ProgramRaster.CullMode NONE;
   }
 
   public class ProgramStore extends android.renderscript.BaseObj {
@@ -16794,11 +17144,28 @@
   public static final class ProgramStore.BlendDstFunc extends java.lang.Enum {
     method public static android.renderscript.ProgramStore.BlendDstFunc valueOf(java.lang.String);
     method public static final android.renderscript.ProgramStore.BlendDstFunc[] values();
+    enum_constant public static final android.renderscript.ProgramStore.BlendDstFunc DST_ALPHA;
+    enum_constant public static final android.renderscript.ProgramStore.BlendDstFunc ONE;
+    enum_constant public static final android.renderscript.ProgramStore.BlendDstFunc ONE_MINUS_DST_ALPHA;
+    enum_constant public static final android.renderscript.ProgramStore.BlendDstFunc ONE_MINUS_SRC_ALPHA;
+    enum_constant public static final android.renderscript.ProgramStore.BlendDstFunc ONE_MINUS_SRC_COLOR;
+    enum_constant public static final android.renderscript.ProgramStore.BlendDstFunc SRC_ALPHA;
+    enum_constant public static final android.renderscript.ProgramStore.BlendDstFunc SRC_COLOR;
+    enum_constant public static final android.renderscript.ProgramStore.BlendDstFunc ZERO;
   }
 
   public static final class ProgramStore.BlendSrcFunc extends java.lang.Enum {
     method public static android.renderscript.ProgramStore.BlendSrcFunc valueOf(java.lang.String);
     method public static final android.renderscript.ProgramStore.BlendSrcFunc[] values();
+    enum_constant public static final android.renderscript.ProgramStore.BlendSrcFunc DST_ALPHA;
+    enum_constant public static final android.renderscript.ProgramStore.BlendSrcFunc DST_COLOR;
+    enum_constant public static final android.renderscript.ProgramStore.BlendSrcFunc ONE;
+    enum_constant public static final android.renderscript.ProgramStore.BlendSrcFunc ONE_MINUS_DST_ALPHA;
+    enum_constant public static final android.renderscript.ProgramStore.BlendSrcFunc ONE_MINUS_DST_COLOR;
+    enum_constant public static final android.renderscript.ProgramStore.BlendSrcFunc ONE_MINUS_SRC_ALPHA;
+    enum_constant public static final android.renderscript.ProgramStore.BlendSrcFunc SRC_ALPHA;
+    enum_constant public static final android.renderscript.ProgramStore.BlendSrcFunc SRC_ALPHA_SATURATE;
+    enum_constant public static final android.renderscript.ProgramStore.BlendSrcFunc ZERO;
   }
 
   public static class ProgramStore.Builder {
@@ -16814,6 +17181,13 @@
   public static final class ProgramStore.DepthFunc extends java.lang.Enum {
     method public static android.renderscript.ProgramStore.DepthFunc valueOf(java.lang.String);
     method public static final android.renderscript.ProgramStore.DepthFunc[] values();
+    enum_constant public static final android.renderscript.ProgramStore.DepthFunc ALWAYS;
+    enum_constant public static final android.renderscript.ProgramStore.DepthFunc EQUAL;
+    enum_constant public static final android.renderscript.ProgramStore.DepthFunc GREATER;
+    enum_constant public static final android.renderscript.ProgramStore.DepthFunc GREATER_OR_EQUAL;
+    enum_constant public static final android.renderscript.ProgramStore.DepthFunc LESS;
+    enum_constant public static final android.renderscript.ProgramStore.DepthFunc LESS_OR_EQUAL;
+    enum_constant public static final android.renderscript.ProgramStore.DepthFunc NOT_EQUAL;
   }
 
   public class ProgramVertex extends android.renderscript.Program {
@@ -16889,6 +17263,8 @@
   public static final class RenderScript.Priority extends java.lang.Enum {
     method public static android.renderscript.RenderScript.Priority valueOf(java.lang.String);
     method public static final android.renderscript.RenderScript.Priority[] values();
+    enum_constant public static final android.renderscript.RenderScript.Priority LOW;
+    enum_constant public static final android.renderscript.RenderScript.Priority NORMAL;
   }
 
   public static class RenderScript.RSErrorHandler implements java.lang.Runnable {
@@ -16951,6 +17327,12 @@
   public static final class Sampler.Value extends java.lang.Enum {
     method public static android.renderscript.Sampler.Value valueOf(java.lang.String);
     method public static final android.renderscript.Sampler.Value[] values();
+    enum_constant public static final android.renderscript.Sampler.Value CLAMP;
+    enum_constant public static final android.renderscript.Sampler.Value LINEAR;
+    enum_constant public static final android.renderscript.Sampler.Value LINEAR_MIP_LINEAR;
+    enum_constant public static final android.renderscript.Sampler.Value LINEAR_MIP_NEAREST;
+    enum_constant public static final android.renderscript.Sampler.Value NEAREST;
+    enum_constant public static final android.renderscript.Sampler.Value WRAP;
   }
 
   public class Script extends android.renderscript.BaseObj {
@@ -17033,6 +17415,15 @@
   public static final class Type.CubemapFace extends java.lang.Enum {
     method public static android.renderscript.Type.CubemapFace valueOf(java.lang.String);
     method public static final android.renderscript.Type.CubemapFace[] values();
+    enum_constant public static final android.renderscript.Type.CubemapFace NEGATIVE_X;
+    enum_constant public static final android.renderscript.Type.CubemapFace NEGATIVE_Y;
+    enum_constant public static final android.renderscript.Type.CubemapFace NEGATIVE_Z;
+    enum_constant public static final android.renderscript.Type.CubemapFace POSITIVE_X;
+    enum_constant public static final android.renderscript.Type.CubemapFace POSITIVE_Y;
+    enum_constant public static final android.renderscript.Type.CubemapFace POSITIVE_Z;
+    enum_constant public static final deprecated android.renderscript.Type.CubemapFace POSITVE_X;
+    enum_constant public static final deprecated android.renderscript.Type.CubemapFace POSITVE_Y;
+    enum_constant public static final deprecated android.renderscript.Type.CubemapFace POSITVE_Z;
   }
 
 }
@@ -17077,6 +17468,28 @@
 
 }
 
+package android.security {
+
+  public final class KeyChain {
+    ctor public KeyChain();
+    method public static void choosePrivateKeyAlias(android.app.Activity, android.security.KeyChainAliasCallback, java.lang.String[], java.security.Principal[], java.lang.String, int);
+    method public static java.security.cert.X509Certificate[] getCertificateChain(android.content.Context, java.lang.String) throws java.lang.InterruptedException, android.security.KeyChainException;
+    method public static java.security.PrivateKey getPrivateKey(android.content.Context, java.lang.String) throws java.lang.InterruptedException, android.security.KeyChainException;
+  }
+
+  public abstract interface KeyChainAliasCallback {
+    method public abstract void alias(java.lang.String);
+  }
+
+  public class KeyChainException extends java.lang.Exception {
+    ctor public KeyChainException();
+    ctor public KeyChainException(java.lang.String);
+    ctor public KeyChainException(java.lang.String, java.lang.Throwable);
+    ctor public KeyChainException(java.lang.Throwable);
+  }
+
+}
+
 package android.service.wallpaper {
 
   public abstract class WallpaperService extends android.app.Service {
@@ -17214,21 +17627,24 @@
 
 package android.speech.tts {
 
-  public abstract class SynthesisRequest {
-    ctor public SynthesisRequest(java.lang.String, android.os.Bundle);
+  public abstract interface SynthesisCallback {
     method public abstract int audioAvailable(byte[], int, int);
     method public abstract int completeAudioAvailable(int, int, int, byte[], int, int);
     method public abstract int done();
     method public abstract void error();
+    method public abstract int getMaxBufferSize();
+    method public abstract int start(int, int, int);
+  }
+
+  public final class SynthesisRequest {
+    ctor public SynthesisRequest(java.lang.String, android.os.Bundle);
     method public java.lang.String getCountry();
     method public java.lang.String getLanguage();
-    method public abstract int getMaxBufferSize();
     method public android.os.Bundle getParams();
     method public int getPitch();
     method public int getSpeechRate();
     method public java.lang.String getText();
     method public java.lang.String getVariant();
-    method public abstract int start(int, int, int);
   }
 
   public class TextToSpeech {
@@ -17246,7 +17662,7 @@
     method public boolean isSpeaking();
     method public int playEarcon(java.lang.String, int, java.util.HashMap<java.lang.String, java.lang.String>);
     method public int playSilence(long, int, java.util.HashMap<java.lang.String, java.lang.String>);
-    method public int setEngineByPackageName(java.lang.String);
+    method public deprecated int setEngineByPackageName(java.lang.String);
     method public int setLanguage(java.util.Locale);
     method public int setOnUtteranceCompletedListener(android.speech.tts.TextToSpeech.OnUtteranceCompletedListener);
     method public int setPitch(float);
@@ -17314,7 +17730,7 @@
     method protected abstract int onIsLanguageAvailable(java.lang.String, java.lang.String, java.lang.String);
     method protected abstract int onLoadLanguage(java.lang.String, java.lang.String, java.lang.String);
     method protected abstract void onStop();
-    method protected abstract void onSynthesizeText(android.speech.tts.SynthesisRequest);
+    method protected abstract void onSynthesizeText(android.speech.tts.SynthesisRequest, android.speech.tts.SynthesisCallback);
   }
 
 }
@@ -17521,6 +17937,11 @@
   public static final class SmsMessage.MessageClass extends java.lang.Enum {
     method public static android.telephony.SmsMessage.MessageClass valueOf(java.lang.String);
     method public static final android.telephony.SmsMessage.MessageClass[] values();
+    enum_constant public static final android.telephony.SmsMessage.MessageClass CLASS_0;
+    enum_constant public static final android.telephony.SmsMessage.MessageClass CLASS_1;
+    enum_constant public static final android.telephony.SmsMessage.MessageClass CLASS_2;
+    enum_constant public static final android.telephony.SmsMessage.MessageClass CLASS_3;
+    enum_constant public static final android.telephony.SmsMessage.MessageClass UNKNOWN;
   }
 
   public static class SmsMessage.SubmitPdu {
@@ -17581,6 +18002,7 @@
     field public static final int NETWORK_TYPE_GPRS = 1; // 0x1
     field public static final int NETWORK_TYPE_HSDPA = 8; // 0x8
     field public static final int NETWORK_TYPE_HSPA = 10; // 0xa
+    field public static final int NETWORK_TYPE_HSPAP = 15; // 0xf
     field public static final int NETWORK_TYPE_HSUPA = 9; // 0x9
     field public static final int NETWORK_TYPE_IDEN = 11; // 0xb
     field public static final int NETWORK_TYPE_LTE = 13; // 0xd
@@ -17692,6 +18114,11 @@
   public static final deprecated class SmsMessage.MessageClass extends java.lang.Enum {
     method public static android.telephony.gsm.SmsMessage.MessageClass valueOf(java.lang.String);
     method public static final android.telephony.gsm.SmsMessage.MessageClass[] values();
+    enum_constant public static final android.telephony.gsm.SmsMessage.MessageClass CLASS_0;
+    enum_constant public static final android.telephony.gsm.SmsMessage.MessageClass CLASS_1;
+    enum_constant public static final android.telephony.gsm.SmsMessage.MessageClass CLASS_2;
+    enum_constant public static final android.telephony.gsm.SmsMessage.MessageClass CLASS_3;
+    enum_constant public static final android.telephony.gsm.SmsMessage.MessageClass UNKNOWN;
   }
 
   public static deprecated class SmsMessage.SubmitPdu {
@@ -18526,6 +18953,9 @@
   public static final class Layout.Alignment extends java.lang.Enum {
     method public static android.text.Layout.Alignment valueOf(java.lang.String);
     method public static final android.text.Layout.Alignment[] values();
+    enum_constant public static final android.text.Layout.Alignment ALIGN_CENTER;
+    enum_constant public static final android.text.Layout.Alignment ALIGN_NORMAL;
+    enum_constant public static final android.text.Layout.Alignment ALIGN_OPPOSITE;
   }
 
   public static class Layout.Directions {
@@ -18783,6 +19213,10 @@
   public static final class TextUtils.TruncateAt extends java.lang.Enum {
     method public static android.text.TextUtils.TruncateAt valueOf(java.lang.String);
     method public static final android.text.TextUtils.TruncateAt[] values();
+    enum_constant public static final android.text.TextUtils.TruncateAt END;
+    enum_constant public static final android.text.TextUtils.TruncateAt MARQUEE;
+    enum_constant public static final android.text.TextUtils.TruncateAt MIDDLE;
+    enum_constant public static final android.text.TextUtils.TruncateAt START;
   }
 
   public abstract interface TextWatcher implements android.text.NoCopySpan {
@@ -19168,6 +19602,10 @@
   public static final class TextKeyListener.Capitalize extends java.lang.Enum {
     method public static android.text.method.TextKeyListener.Capitalize valueOf(java.lang.String);
     method public static final android.text.method.TextKeyListener.Capitalize[] values();
+    enum_constant public static final android.text.method.TextKeyListener.Capitalize CHARACTERS;
+    enum_constant public static final android.text.method.TextKeyListener.Capitalize NONE;
+    enum_constant public static final android.text.method.TextKeyListener.Capitalize SENTENCES;
+    enum_constant public static final android.text.method.TextKeyListener.Capitalize WORDS;
   }
 
   public class TimeKeyListener extends android.text.method.NumberKeyListener {
@@ -19665,6 +20103,7 @@
     field public static final int DENSITY_HIGH = 240; // 0xf0
     field public static final int DENSITY_LOW = 120; // 0x78
     field public static final int DENSITY_MEDIUM = 160; // 0xa0
+    field public static final int DENSITY_TV = 213; // 0xd5
     field public static final int DENSITY_XHIGH = 320; // 0x140
     field public float density;
     field public int densityDpi;
@@ -19737,6 +20176,16 @@
   public final class JsonToken extends java.lang.Enum {
     method public static android.util.JsonToken valueOf(java.lang.String);
     method public static final android.util.JsonToken[] values();
+    enum_constant public static final android.util.JsonToken BEGIN_ARRAY;
+    enum_constant public static final android.util.JsonToken BEGIN_OBJECT;
+    enum_constant public static final android.util.JsonToken BOOLEAN;
+    enum_constant public static final android.util.JsonToken END_ARRAY;
+    enum_constant public static final android.util.JsonToken END_DOCUMENT;
+    enum_constant public static final android.util.JsonToken END_OBJECT;
+    enum_constant public static final android.util.JsonToken NAME;
+    enum_constant public static final android.util.JsonToken NULL;
+    enum_constant public static final android.util.JsonToken NUMBER;
+    enum_constant public static final android.util.JsonToken STRING;
   }
 
   public final class JsonWriter implements java.io.Closeable {
@@ -19832,6 +20281,10 @@
     method public void previousMonth();
   }
 
+  public class NoSuchPropertyException extends java.lang.RuntimeException {
+    ctor public NoSuchPropertyException(java.lang.String);
+  }
+
   public class Pair {
     ctor public Pair(F, S);
     method public static android.util.Pair<A, B> create(A, B);
@@ -19867,6 +20320,16 @@
     method public abstract void println(java.lang.String);
   }
 
+  public abstract class Property {
+    ctor public Property(java.lang.Class<V>, java.lang.String);
+    method public abstract V get(T);
+    method public java.lang.String getName();
+    method public java.lang.Class<V> getType();
+    method public boolean isReadOnly();
+    method public static android.util.Property<T, V> of(java.lang.Class<T>, java.lang.Class<V>, java.lang.String);
+    method public void set(T, V);
+  }
+
   public class SparseArray {
     ctor public SparseArray();
     ctor public SparseArray(int);
@@ -20026,6 +20489,10 @@
   public static final class Xml.Encoding extends java.lang.Enum {
     method public static android.util.Xml.Encoding valueOf(java.lang.String);
     method public static final android.util.Xml.Encoding[] values();
+    enum_constant public static final android.util.Xml.Encoding ISO_8859_1;
+    enum_constant public static final android.util.Xml.Encoding US_ASCII;
+    enum_constant public static final android.util.Xml.Encoding UTF_16;
+    enum_constant public static final android.util.Xml.Encoding UTF_8;
   }
 
 }
@@ -20168,17 +20635,15 @@
     method public static void apply(int, int, int, android.graphics.Rect, android.graphics.Rect);
     method public static void apply(int, int, int, android.graphics.Rect, int, int, android.graphics.Rect);
     method public static void applyDisplay(int, android.graphics.Rect, android.graphics.Rect);
-    method public static int getAbsoluteGravity(int, boolean);
+    method public static int getAbsoluteGravity(int, int);
     method public static boolean isHorizontal(int);
     method public static boolean isVertical(int);
-    field public static final int AFTER = 8388613; // 0x800005
     field public static final int AXIS_CLIP = 8; // 0x8
     field public static final int AXIS_PULL_AFTER = 4; // 0x4
     field public static final int AXIS_PULL_BEFORE = 2; // 0x2
     field public static final int AXIS_SPECIFIED = 1; // 0x1
     field public static final int AXIS_X_SHIFT = 0; // 0x0
     field public static final int AXIS_Y_SHIFT = 4; // 0x4
-    field public static final int BEFORE = 8388611; // 0x800003
     field public static final int BOTTOM = 80; // 0x50
     field public static final int CENTER = 17; // 0x11
     field public static final int CENTER_HORIZONTAL = 1; // 0x1
@@ -20187,15 +20652,17 @@
     field public static final int CLIP_VERTICAL = 128; // 0x80
     field public static final int DISPLAY_CLIP_HORIZONTAL = 16777216; // 0x1000000
     field public static final int DISPLAY_CLIP_VERTICAL = 268435456; // 0x10000000
+    field public static final int END = 8388613; // 0x800005
     field public static final int FILL = 119; // 0x77
     field public static final int FILL_HORIZONTAL = 7; // 0x7
     field public static final int FILL_VERTICAL = 112; // 0x70
     field public static final int HORIZONTAL_GRAVITY_MASK = 7; // 0x7
     field public static final int LEFT = 3; // 0x3
     field public static final int NO_GRAVITY = 0; // 0x0
-    field public static final int RELATIVE_HORIZONTAL_DIRECTION = 8388608; // 0x800000
     field public static final int RELATIVE_HORIZONTAL_GRAVITY_MASK = 8388615; // 0x800007
+    field public static final int RELATIVE_LAYOUT_DIRECTION = 8388608; // 0x800000
     field public static final int RIGHT = 5; // 0x5
+    field public static final int START = 8388611; // 0x800003
     field public static final int TOP = 48; // 0x30
     field public static final int VERTICAL_GRAVITY_MASK = 112; // 0x70
   }
@@ -20731,6 +21198,8 @@
   }
 
   public abstract interface MenuItem {
+    method public abstract boolean collapseActionView();
+    method public abstract boolean expandActionView();
     method public abstract android.view.View getActionView();
     method public abstract char getAlphabeticShortcut();
     method public abstract int getGroupId();
@@ -20744,6 +21213,7 @@
     method public abstract java.lang.CharSequence getTitle();
     method public abstract java.lang.CharSequence getTitleCondensed();
     method public abstract boolean hasSubMenu();
+    method public abstract boolean isActionViewExpanded();
     method public abstract boolean isCheckable();
     method public abstract boolean isChecked();
     method public abstract boolean isEnabled();
@@ -20758,19 +21228,27 @@
     method public abstract android.view.MenuItem setIcon(int);
     method public abstract android.view.MenuItem setIntent(android.content.Intent);
     method public abstract android.view.MenuItem setNumericShortcut(char);
+    method public abstract android.view.MenuItem setOnActionExpandListener(android.view.MenuItem.OnActionExpandListener);
     method public abstract android.view.MenuItem setOnMenuItemClickListener(android.view.MenuItem.OnMenuItemClickListener);
     method public abstract android.view.MenuItem setShortcut(char, char);
     method public abstract void setShowAsAction(int);
+    method public abstract android.view.MenuItem setShowAsActionFlags(int);
     method public abstract android.view.MenuItem setTitle(java.lang.CharSequence);
     method public abstract android.view.MenuItem setTitle(int);
     method public abstract android.view.MenuItem setTitleCondensed(java.lang.CharSequence);
     method public abstract android.view.MenuItem setVisible(boolean);
     field public static final int SHOW_AS_ACTION_ALWAYS = 2; // 0x2
+    field public static final int SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW = 8; // 0x8
     field public static final int SHOW_AS_ACTION_IF_ROOM = 1; // 0x1
     field public static final int SHOW_AS_ACTION_NEVER = 0; // 0x0
     field public static final int SHOW_AS_ACTION_WITH_TEXT = 4; // 0x4
   }
 
+  public static abstract interface MenuItem.OnActionExpandListener {
+    method public abstract boolean onMenuItemActionCollapse(android.view.MenuItem);
+    method public abstract boolean onMenuItemActionExpand(android.view.MenuItem);
+  }
+
   public static abstract interface MenuItem.OnMenuItemClickListener {
     method public abstract boolean onMenuItemClick(android.view.MenuItem);
   }
@@ -21140,14 +21618,19 @@
     ctor public TextureView(android.content.Context, android.util.AttributeSet);
     ctor public TextureView(android.content.Context, android.util.AttributeSet, int);
     method public final void draw(android.graphics.Canvas);
+    method public android.graphics.Bitmap getBitmap();
+    method public android.graphics.Bitmap getBitmap(int, int);
+    method public android.graphics.Bitmap getBitmap(android.graphics.Bitmap);
     method public android.graphics.SurfaceTexture getSurfaceTexture();
     method public android.view.TextureView.SurfaceTextureListener getSurfaceTextureListener();
+    method public boolean isAvailable();
     method protected final void onDraw(android.graphics.Canvas);
     method public void setSurfaceTextureListener(android.view.TextureView.SurfaceTextureListener);
   }
 
   public static abstract interface TextureView.SurfaceTextureListener {
-    method public abstract void onSurfaceTextureAvailable(android.graphics.SurfaceTexture);
+    method public abstract void onSurfaceTextureAvailable(android.graphics.SurfaceTexture, int, int);
+    method public abstract void onSurfaceTextureDestroyed(android.graphics.SurfaceTexture);
     method public abstract void onSurfaceTextureSizeChanged(android.graphics.SurfaceTexture, int, int);
   }
 
@@ -21190,6 +21673,8 @@
     method public void buildDrawingCache();
     method public void buildDrawingCache(boolean);
     method public void buildLayer();
+    method public boolean canScrollHorizontally(int);
+    method public boolean canScrollVertically(int);
     method public void cancelLongPress();
     method public boolean checkInputConnectionProxy(android.view.View);
     method public void clearAnimation();
@@ -21202,6 +21687,7 @@
     method protected int computeVerticalScrollExtent();
     method protected int computeVerticalScrollOffset();
     method protected int computeVerticalScrollRange();
+    method public android.view.accessibility.AccessibilityNodeInfo createAccessibilityNodeInfo();
     method public void createContextMenu(android.view.ContextMenu);
     method public void destroyDrawingCache();
     method public void dispatchConfigurationChanged(android.content.res.Configuration);
@@ -21230,6 +21716,7 @@
     method public android.view.View findFocus();
     method public final android.view.View findViewById(int);
     method public final android.view.View findViewWithTag(java.lang.Object);
+    method public void findViewsWithText(java.util.ArrayList<android.view.View>, java.lang.CharSequence);
     method protected boolean fitSystemWindows(android.graphics.Rect);
     method public android.view.View focusSearch(int);
     method public void forceLayout();
@@ -21293,6 +21780,7 @@
     method public final android.view.ViewParent getParent();
     method public float getPivotX();
     method public float getPivotY();
+    method public int getResolvedLayoutDirection(android.graphics.drawable.Drawable);
     method public android.content.res.Resources getResources();
     method public final int getRight();
     method protected float getRightFadingEdgeStrength();
@@ -21358,8 +21846,6 @@
     method public boolean isInEditMode();
     method public boolean isInTouchMode();
     method public boolean isLayoutRequested();
-    method public boolean isLayoutRtl();
-    method public boolean isLayoutRtl(android.graphics.drawable.Drawable);
     method public boolean isLongClickable();
     method public boolean isOpaque();
     method protected boolean isPaddingOffsetRequired();
@@ -21398,6 +21884,7 @@
     method public boolean onGenericMotionEvent(android.view.MotionEvent);
     method public boolean onHoverEvent(android.view.MotionEvent);
     method public void onInitializeAccessibilityEvent(android.view.accessibility.AccessibilityEvent);
+    method public void onInitializeAccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo);
     method public boolean onKeyDown(int, android.view.KeyEvent);
     method public boolean onKeyLongPress(int, android.view.KeyEvent);
     method public boolean onKeyMultiple(int, int, android.view.KeyEvent);
@@ -21595,6 +22082,11 @@
     field protected static final int[] PRESSED_SELECTED_STATE_SET;
     field protected static final int[] PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET;
     field protected static final int[] PRESSED_WINDOW_FOCUSED_STATE_SET;
+    field public static android.util.Property ROTATION;
+    field public static android.util.Property ROTATION_X;
+    field public static android.util.Property ROTATION_Y;
+    field public static android.util.Property SCALE_X;
+    field public static android.util.Property SCALE_Y;
     field public static final int SCROLLBARS_INSIDE_INSET = 16777216; // 0x1000000
     field public static final int SCROLLBARS_INSIDE_OVERLAY = 0; // 0x0
     field public static final int SCROLLBARS_OUTSIDE_INSET = 50331648; // 0x3000000
@@ -21607,9 +22099,13 @@
     field public static final int SOUND_EFFECTS_ENABLED = 134217728; // 0x8000000
     field public static final int STATUS_BAR_HIDDEN = 1; // 0x1
     field public static final int STATUS_BAR_VISIBLE = 0; // 0x0
+    field public static android.util.Property TRANSLATION_X;
+    field public static android.util.Property TRANSLATION_Y;
     field protected static final java.lang.String VIEW_LOG_TAG = "View";
     field public static final int VISIBLE = 0; // 0x0
     field protected static final int[] WINDOW_FOCUSED_STATE_SET;
+    field public static android.util.Property X;
+    field public static android.util.Property Y;
   }
 
   public static class View.BaseSavedState extends android.view.AbsSavedState {
@@ -21744,6 +22240,14 @@
   public static final class ViewDebug.HierarchyTraceType extends java.lang.Enum {
     method public static android.view.ViewDebug.HierarchyTraceType valueOf(java.lang.String);
     method public static final android.view.ViewDebug.HierarchyTraceType[] values();
+    enum_constant public static final android.view.ViewDebug.HierarchyTraceType BUILD_CACHE;
+    enum_constant public static final android.view.ViewDebug.HierarchyTraceType DRAW;
+    enum_constant public static final android.view.ViewDebug.HierarchyTraceType INVALIDATE;
+    enum_constant public static final android.view.ViewDebug.HierarchyTraceType INVALIDATE_CHILD;
+    enum_constant public static final android.view.ViewDebug.HierarchyTraceType INVALIDATE_CHILD_IN_PARENT;
+    enum_constant public static final android.view.ViewDebug.HierarchyTraceType ON_LAYOUT;
+    enum_constant public static final android.view.ViewDebug.HierarchyTraceType ON_MEASURE;
+    enum_constant public static final android.view.ViewDebug.HierarchyTraceType REQUEST_LAYOUT;
   }
 
   public static abstract class ViewDebug.IntToString implements java.lang.annotation.Annotation {
@@ -21752,6 +22256,12 @@
   public static final class ViewDebug.RecyclerTraceType extends java.lang.Enum {
     method public static android.view.ViewDebug.RecyclerTraceType valueOf(java.lang.String);
     method public static final android.view.ViewDebug.RecyclerTraceType[] values();
+    enum_constant public static final android.view.ViewDebug.RecyclerTraceType BIND_VIEW;
+    enum_constant public static final android.view.ViewDebug.RecyclerTraceType MOVE_FROM_ACTIVE_TO_SCRAP_HEAP;
+    enum_constant public static final android.view.ViewDebug.RecyclerTraceType MOVE_TO_SCRAP_HEAP;
+    enum_constant public static final android.view.ViewDebug.RecyclerTraceType NEW_VIEW;
+    enum_constant public static final android.view.ViewDebug.RecyclerTraceType RECYCLE_FROM_ACTIVE_HEAP;
+    enum_constant public static final android.view.ViewDebug.RecyclerTraceType RECYCLE_FROM_SCRAP_HEAP;
   }
 
   public abstract class ViewGroup extends android.view.View implements android.view.ViewManager android.view.ViewParent {
@@ -22276,6 +22786,7 @@
   public final class AccessibilityEvent extends android.view.accessibility.AccessibilityRecord implements android.os.Parcelable {
     method public void appendRecord(android.view.accessibility.AccessibilityRecord);
     method public int describeContents();
+    method public static java.lang.String eventTypeToString(int);
     method public long getEventTime();
     method public int getEventType();
     method public java.lang.CharSequence getPackageName();
@@ -22283,6 +22794,7 @@
     method public int getRecordCount();
     method public void initFromParcel(android.os.Parcel);
     method public static android.view.accessibility.AccessibilityEvent obtain(int);
+    method public static android.view.accessibility.AccessibilityEvent obtain(android.view.accessibility.AccessibilityEvent);
     method public static android.view.accessibility.AccessibilityEvent obtain();
     method public void setEventTime(long);
     method public void setEventType(int);
@@ -22302,6 +22814,7 @@
     field public static final int TYPE_VIEW_LONG_CLICKED = 2; // 0x2
     field public static final int TYPE_VIEW_SELECTED = 4; // 0x4
     field public static final int TYPE_VIEW_TEXT_CHANGED = 16; // 0x10
+    field public static final int TYPE_WINDOW_CONTENT_CHANGED = 2048; // 0x800
     field public static final int TYPE_WINDOW_STATE_CHANGED = 32; // 0x20
   }
 
@@ -22311,19 +22824,77 @@
   }
 
   public final class AccessibilityManager {
-    method public java.util.List<android.content.pm.ServiceInfo> getAccessibilityServiceList();
-    method public java.util.List<android.content.pm.ServiceInfo> getEnabledAccessibilityServiceList(int);
+    method public boolean addAccessibilityStateChangeListener(android.view.accessibility.AccessibilityManager.AccessibilityStateChangeListener);
+    method public deprecated java.util.List<android.content.pm.ServiceInfo> getAccessibilityServiceList();
+    method public java.util.List<android.accessibilityservice.AccessibilityServiceInfo> getEnabledAccessibilityServiceList(int);
+    method public java.util.List<android.accessibilityservice.AccessibilityServiceInfo> getInstalledAccessibilityServiceList();
     method public void interrupt();
     method public boolean isEnabled();
+    method public boolean removeAccessibilityStateChangeListener(android.view.accessibility.AccessibilityManager.AccessibilityStateChangeListener);
     method public void sendAccessibilityEvent(android.view.accessibility.AccessibilityEvent);
   }
 
+  public static abstract interface AccessibilityManager.AccessibilityStateChangeListener {
+    method public abstract void onAccessibilityStateChanged(boolean);
+  }
+
+  public class AccessibilityNodeInfo implements android.os.Parcelable {
+    method public void addAction(int);
+    method public void addChild(android.view.View);
+    method public int describeContents();
+    method public java.util.List<android.view.accessibility.AccessibilityNodeInfo> findAccessibilityNodeInfosByText(java.lang.String);
+    method public int getActions();
+    method public void getBoundsInParent(android.graphics.Rect);
+    method public void getBoundsInScreen(android.graphics.Rect);
+    method public android.view.accessibility.AccessibilityNodeInfo getChild(int);
+    method public int getChildCount();
+    method public java.lang.CharSequence getClassName();
+    method public java.lang.CharSequence getContentDescription();
+    method public java.lang.CharSequence getPackageName();
+    method public android.view.accessibility.AccessibilityNodeInfo getParent();
+    method public java.lang.CharSequence getText();
+    method public int getWindowId();
+    method public boolean isCheckable();
+    method public boolean isChecked();
+    method public boolean isClickable();
+    method public boolean isEnabled();
+    method public boolean isFocusable();
+    method public boolean isFocused();
+    method public boolean isLongClickable();
+    method public boolean isPassword();
+    method public boolean isSelected();
+    method public static android.view.accessibility.AccessibilityNodeInfo obtain(android.view.View);
+    method public static android.view.accessibility.AccessibilityNodeInfo obtain();
+    method public boolean performAction(int);
+    method public void recycle();
+    method public void setBoundsInParent(android.graphics.Rect);
+    method public void setBoundsInScreen(android.graphics.Rect);
+    method public void setCheckable(boolean);
+    method public void setChecked(boolean);
+    method public void setClassName(java.lang.CharSequence);
+    method public void setClickable(boolean);
+    method public void setContentDescription(java.lang.CharSequence);
+    method public void setEnabled(boolean);
+    method public void setFocusable(boolean);
+    method public void setFocused(boolean);
+    method public void setLongClickable(boolean);
+    method public void setPackageName(java.lang.CharSequence);
+    method public void setParent(android.view.View);
+    method public void setPassword(boolean);
+    method public void setSelected(boolean);
+    method public void setSource(android.view.View);
+    method public void setText(java.lang.CharSequence);
+    method public void writeToParcel(android.os.Parcel, int);
+    field public static final int ACTION_CLEAR_FOCUS = 2; // 0x2
+    field public static final int ACTION_CLEAR_SELECTION = 8; // 0x8
+    field public static final int ACTION_FOCUS = 1; // 0x1
+    field public static final int ACTION_SELECT = 4; // 0x4
+    field public static final android.os.Parcelable.Creator CREATOR;
+  }
+
   public class AccessibilityRecord {
-    ctor protected AccessibilityRecord();
-    method protected void clear();
     method public int getAddedCount();
     method public java.lang.CharSequence getBeforeText();
-    method public boolean getBooleanProperty(int);
     method public java.lang.CharSequence getClassName();
     method public java.lang.CharSequence getContentDescription();
     method public int getCurrentItemIndex();
@@ -22331,11 +22902,14 @@
     method public int getItemCount();
     method public android.os.Parcelable getParcelableData();
     method public int getRemovedCount();
+    method public android.view.accessibility.AccessibilityNodeInfo getSource();
     method public java.util.List<java.lang.CharSequence> getText();
+    method public int getWindowId();
     method public boolean isChecked();
     method public boolean isEnabled();
     method public boolean isFullScreen();
     method public boolean isPassword();
+    method public static android.view.accessibility.AccessibilityRecord obtain(android.view.accessibility.AccessibilityRecord);
     method public static android.view.accessibility.AccessibilityRecord obtain();
     method public void recycle();
     method public void setAddedCount(int);
@@ -22351,17 +22925,7 @@
     method public void setParcelableData(android.os.Parcelable);
     method public void setPassword(boolean);
     method public void setRemovedCount(int);
-    field protected int mAddedCount;
-    field protected java.lang.CharSequence mBeforeText;
-    field protected int mBooleanProperties;
-    field protected java.lang.CharSequence mClassName;
-    field protected java.lang.CharSequence mContentDescription;
-    field protected int mCurrentItemIndex;
-    field protected int mFromIndex;
-    field protected int mItemCount;
-    field protected android.os.Parcelable mParcelableData;
-    field protected int mRemovedCount;
-    field protected final java.util.List mText;
+    method public void setSource(android.view.View);
   }
 
 }
@@ -22878,6 +23442,7 @@
     method public boolean isWatchingCursor(android.view.View);
     method public void restartInput(android.view.View);
     method public void sendAppPrivateCommand(android.view.View, java.lang.String, android.os.Bundle);
+    method public boolean setAdditionalInputMethodSubtypes(android.os.IBinder, android.view.inputmethod.InputMethodSubtype[]);
     method public boolean setCurrentInputMethodSubtype(android.view.inputmethod.InputMethodSubtype);
     method public void setInputMethod(android.os.IBinder, java.lang.String);
     method public void setInputMethodAndSubtype(android.os.IBinder, java.lang.String, android.view.inputmethod.InputMethodSubtype);
@@ -22920,8 +23485,11 @@
   }
 
   public final class InputMethodSubtype implements android.os.Parcelable {
+    ctor public InputMethodSubtype(int, int, java.lang.String, java.lang.String, java.lang.String);
+    ctor public InputMethodSubtype(int, int, java.lang.String, java.lang.String, java.lang.String, boolean);
     method public boolean containsExtraValueKey(java.lang.String);
     method public int describeContents();
+    method public java.lang.CharSequence getDisplayName(android.content.Context, java.lang.String, android.content.pm.ApplicationInfo);
     method public java.lang.String getExtraValue();
     method public java.lang.String getExtraValueOf(java.lang.String);
     method public int getIconResId();
@@ -22977,6 +23545,11 @@
   public static final class ConsoleMessage.MessageLevel extends java.lang.Enum {
     method public static android.webkit.ConsoleMessage.MessageLevel valueOf(java.lang.String);
     method public static final android.webkit.ConsoleMessage.MessageLevel[] values();
+    enum_constant public static final android.webkit.ConsoleMessage.MessageLevel DEBUG;
+    enum_constant public static final android.webkit.ConsoleMessage.MessageLevel ERROR;
+    enum_constant public static final android.webkit.ConsoleMessage.MessageLevel LOG;
+    enum_constant public static final android.webkit.ConsoleMessage.MessageLevel TIP;
+    enum_constant public static final android.webkit.ConsoleMessage.MessageLevel WARNING;
   }
 
   public final class CookieManager {
@@ -23117,6 +23690,7 @@
     method public void onReceivedTouchIconUrl(android.webkit.WebView, java.lang.String, boolean);
     method public void onRequestFocus(android.webkit.WebView);
     method public void onShowCustomView(android.view.View, android.webkit.WebChromeClient.CustomViewCallback);
+    method public void onShowCustomView(android.view.View, int, android.webkit.WebChromeClient.CustomViewCallback);
   }
 
   public static abstract interface WebChromeClient.CustomViewCallback {
@@ -23191,7 +23765,8 @@
     method public boolean getSavePassword();
     method public synchronized java.lang.String getSerifFontFamily();
     method public synchronized java.lang.String getStandardFontFamily();
-    method public synchronized android.webkit.WebSettings.TextSize getTextSize();
+    method public deprecated synchronized android.webkit.WebSettings.TextSize getTextSize();
+    method public synchronized int getTextZoom();
     method public deprecated synchronized boolean getUseDoubleTree();
     method public deprecated boolean getUseWebViewBackgroundForOverscrollBackground();
     method public synchronized boolean getUseWideViewPort();
@@ -23241,7 +23816,8 @@
     method public synchronized void setStandardFontFamily(java.lang.String);
     method public synchronized void setSupportMultipleWindows(boolean);
     method public void setSupportZoom(boolean);
-    method public synchronized void setTextSize(android.webkit.WebSettings.TextSize);
+    method public deprecated synchronized void setTextSize(android.webkit.WebSettings.TextSize);
+    method public synchronized void setTextZoom(int);
     method public deprecated synchronized void setUseDoubleTree(boolean);
     method public deprecated void setUseWebViewBackgroundForOverscrollBackground(boolean);
     method public synchronized void setUseWideViewPort(boolean);
@@ -23259,26 +23835,43 @@
   public static final deprecated class WebSettings.LayoutAlgorithm extends java.lang.Enum {
     method public static android.webkit.WebSettings.LayoutAlgorithm valueOf(java.lang.String);
     method public static final android.webkit.WebSettings.LayoutAlgorithm[] values();
+    enum_constant public static final android.webkit.WebSettings.LayoutAlgorithm NARROW_COLUMNS;
+    enum_constant public static final android.webkit.WebSettings.LayoutAlgorithm NORMAL;
+    enum_constant public static final android.webkit.WebSettings.LayoutAlgorithm SINGLE_COLUMN;
   }
 
   public static final class WebSettings.PluginState extends java.lang.Enum {
     method public static android.webkit.WebSettings.PluginState valueOf(java.lang.String);
     method public static final android.webkit.WebSettings.PluginState[] values();
+    enum_constant public static final android.webkit.WebSettings.PluginState OFF;
+    enum_constant public static final android.webkit.WebSettings.PluginState ON;
+    enum_constant public static final android.webkit.WebSettings.PluginState ON_DEMAND;
   }
 
   public static final class WebSettings.RenderPriority extends java.lang.Enum {
     method public static android.webkit.WebSettings.RenderPriority valueOf(java.lang.String);
     method public static final android.webkit.WebSettings.RenderPriority[] values();
+    enum_constant public static final android.webkit.WebSettings.RenderPriority HIGH;
+    enum_constant public static final android.webkit.WebSettings.RenderPriority LOW;
+    enum_constant public static final android.webkit.WebSettings.RenderPriority NORMAL;
   }
 
-  public static final class WebSettings.TextSize extends java.lang.Enum {
+  public static final deprecated class WebSettings.TextSize extends java.lang.Enum {
     method public static android.webkit.WebSettings.TextSize valueOf(java.lang.String);
     method public static final android.webkit.WebSettings.TextSize[] values();
+    enum_constant public static final android.webkit.WebSettings.TextSize LARGER;
+    enum_constant public static final android.webkit.WebSettings.TextSize LARGEST;
+    enum_constant public static final android.webkit.WebSettings.TextSize NORMAL;
+    enum_constant public static final android.webkit.WebSettings.TextSize SMALLER;
+    enum_constant public static final android.webkit.WebSettings.TextSize SMALLEST;
   }
 
   public static final class WebSettings.ZoomDensity extends java.lang.Enum {
     method public static android.webkit.WebSettings.ZoomDensity valueOf(java.lang.String);
     method public static final android.webkit.WebSettings.ZoomDensity[] values();
+    enum_constant public static final android.webkit.WebSettings.ZoomDensity CLOSE;
+    enum_constant public static final android.webkit.WebSettings.ZoomDensity FAR;
+    enum_constant public static final android.webkit.WebSettings.ZoomDensity MEDIUM;
   }
 
   public final class WebStorage {
@@ -24234,6 +24827,7 @@
     ctor public GridLayout(android.content.Context);
     ctor public GridLayout(android.content.Context, android.util.AttributeSet, int);
     ctor public GridLayout(android.content.Context, android.util.AttributeSet);
+    method public int getAlignmentMode();
     method public int getColumnCount();
     method public int getOrientation();
     method public int getRowCount();
@@ -24241,12 +24835,15 @@
     method public boolean isColumnOrderPreserved();
     method public boolean isRowOrderPreserved();
     method protected void onLayout(boolean, int, int, int, int);
+    method public void setAlignmentMode(int);
     method public void setColumnCount(int);
     method public void setColumnOrderPreserved(boolean);
     method public void setOrientation(int);
     method public void setRowCount(int);
     method public void setRowOrderPreserved(boolean);
     method public void setUseDefaultMargins(boolean);
+    field public static final int ALIGN_BOUNDS = 0; // 0x0
+    field public static final int ALIGN_MARGINS = 1; // 0x1
     field public static final android.widget.GridLayout.Alignment BASELINE;
     field public static final android.widget.GridLayout.Alignment BOTTOM;
     field public static final android.widget.GridLayout.Alignment CENTER;
@@ -24255,26 +24852,20 @@
     field public static final android.widget.GridLayout.Alignment LEFT;
     field public static final android.widget.GridLayout.Alignment RIGHT;
     field public static final android.widget.GridLayout.Alignment TOP;
+    field public static final int UNDEFINED = -2147483648; // 0x80000000
     field public static final int VERTICAL = 1; // 0x1
   }
 
-  public static abstract interface GridLayout.Alignment {
-    method public abstract int getAlignmentValue(android.view.View, int);
-    method public abstract int getSizeInCell(android.view.View, int, int);
+  public static abstract class GridLayout.Alignment {
+    ctor public GridLayout.Alignment();
+    method public abstract int getAlignmentValue(android.view.View, int, int);
+    method public int getSizeInCell(android.view.View, int, int, int);
   }
 
   public static class GridLayout.Group {
-    ctor public GridLayout.Group(android.widget.GridLayout.Interval, android.widget.GridLayout.Alignment);
     ctor public GridLayout.Group(int, int, android.widget.GridLayout.Alignment);
     ctor public GridLayout.Group(int, android.widget.GridLayout.Alignment);
     field public final android.widget.GridLayout.Alignment alignment;
-    field public final android.widget.GridLayout.Interval span;
-  }
-
-  public static class GridLayout.Interval {
-    ctor public GridLayout.Interval(int, int);
-    field public final int max;
-    field public final int min;
   }
 
   public static class GridLayout.LayoutParams extends android.view.ViewGroup.MarginLayoutParams {
@@ -24408,6 +24999,14 @@
   public static final class ImageView.ScaleType extends java.lang.Enum {
     method public static android.widget.ImageView.ScaleType valueOf(java.lang.String);
     method public static final android.widget.ImageView.ScaleType[] values();
+    enum_constant public static final android.widget.ImageView.ScaleType CENTER;
+    enum_constant public static final android.widget.ImageView.ScaleType CENTER_CROP;
+    enum_constant public static final android.widget.ImageView.ScaleType CENTER_INSIDE;
+    enum_constant public static final android.widget.ImageView.ScaleType FIT_CENTER;
+    enum_constant public static final android.widget.ImageView.ScaleType FIT_END;
+    enum_constant public static final android.widget.ImageView.ScaleType FIT_START;
+    enum_constant public static final android.widget.ImageView.ScaleType FIT_XY;
+    enum_constant public static final android.widget.ImageView.ScaleType MATRIX;
   }
 
   public class LinearLayout extends android.view.ViewGroup {
@@ -25477,6 +26076,9 @@
   public static final class TextView.BufferType extends java.lang.Enum {
     method public static android.widget.TextView.BufferType valueOf(java.lang.String);
     method public static final android.widget.TextView.BufferType[] values();
+    enum_constant public static final android.widget.TextView.BufferType EDITABLE;
+    enum_constant public static final android.widget.TextView.BufferType NORMAL;
+    enum_constant public static final android.widget.TextView.BufferType SPANNABLE;
   }
 
   public static abstract interface TextView.OnEditorActionListener {
@@ -28468,6 +29070,12 @@
   public static final class Thread.State extends java.lang.Enum {
     method public static java.lang.Thread.State valueOf(java.lang.String);
     method public static final java.lang.Thread.State[] values();
+    enum_constant public static final java.lang.Thread.State BLOCKED;
+    enum_constant public static final java.lang.Thread.State NEW;
+    enum_constant public static final java.lang.Thread.State RUNNABLE;
+    enum_constant public static final java.lang.Thread.State TERMINATED;
+    enum_constant public static final java.lang.Thread.State TIMED_WAITING;
+    enum_constant public static final java.lang.Thread.State WAITING;
   }
 
   public static abstract interface Thread.UncaughtExceptionHandler {
@@ -28601,6 +29209,14 @@
   public final class ElementType extends java.lang.Enum {
     method public static java.lang.annotation.ElementType valueOf(java.lang.String);
     method public static final java.lang.annotation.ElementType[] values();
+    enum_constant public static final java.lang.annotation.ElementType ANNOTATION_TYPE;
+    enum_constant public static final java.lang.annotation.ElementType CONSTRUCTOR;
+    enum_constant public static final java.lang.annotation.ElementType FIELD;
+    enum_constant public static final java.lang.annotation.ElementType LOCAL_VARIABLE;
+    enum_constant public static final java.lang.annotation.ElementType METHOD;
+    enum_constant public static final java.lang.annotation.ElementType PACKAGE;
+    enum_constant public static final java.lang.annotation.ElementType PARAMETER;
+    enum_constant public static final java.lang.annotation.ElementType TYPE;
   }
 
   public class IncompleteAnnotationException extends java.lang.RuntimeException {
@@ -28618,6 +29234,9 @@
   public final class RetentionPolicy extends java.lang.Enum {
     method public static java.lang.annotation.RetentionPolicy valueOf(java.lang.String);
     method public static final java.lang.annotation.RetentionPolicy[] values();
+    enum_constant public static final java.lang.annotation.RetentionPolicy CLASS;
+    enum_constant public static final java.lang.annotation.RetentionPolicy RUNTIME;
+    enum_constant public static final java.lang.annotation.RetentionPolicy SOURCE;
   }
 
   public abstract class Target implements java.lang.annotation.Annotation {
@@ -29034,6 +29653,14 @@
     method public static java.math.RoundingMode valueOf(java.lang.String);
     method public static java.math.RoundingMode valueOf(int);
     method public static final java.math.RoundingMode[] values();
+    enum_constant public static final java.math.RoundingMode CEILING;
+    enum_constant public static final java.math.RoundingMode DOWN;
+    enum_constant public static final java.math.RoundingMode FLOOR;
+    enum_constant public static final java.math.RoundingMode HALF_DOWN;
+    enum_constant public static final java.math.RoundingMode HALF_EVEN;
+    enum_constant public static final java.math.RoundingMode HALF_UP;
+    enum_constant public static final java.math.RoundingMode UNNECESSARY;
+    enum_constant public static final java.math.RoundingMode UP;
   }
 
 }
@@ -29060,6 +29687,8 @@
   public static final class Authenticator.RequestorType extends java.lang.Enum {
     method public static java.net.Authenticator.RequestorType valueOf(java.lang.String);
     method public static final java.net.Authenticator.RequestorType[] values();
+    enum_constant public static final java.net.Authenticator.RequestorType PROXY;
+    enum_constant public static final java.net.Authenticator.RequestorType SERVER;
   }
 
   public class BindException extends java.net.SocketException {
@@ -29474,6 +30103,9 @@
   public static final class Proxy.Type extends java.lang.Enum {
     method public static java.net.Proxy.Type valueOf(java.lang.String);
     method public static final java.net.Proxy.Type[] values();
+    enum_constant public static final java.net.Proxy.Type DIRECT;
+    enum_constant public static final java.net.Proxy.Type HTTP;
+    enum_constant public static final java.net.Proxy.Type SOCKS;
   }
 
   public abstract class ProxySelector {
@@ -30870,6 +31502,9 @@
   public static final class KeyRep.Type extends java.lang.Enum {
     method public static java.security.KeyRep.Type valueOf(java.lang.String);
     method public static final java.security.KeyRep.Type[] values();
+    enum_constant public static final java.security.KeyRep.Type PRIVATE;
+    enum_constant public static final java.security.KeyRep.Type PUBLIC;
+    enum_constant public static final java.security.KeyRep.Type SECRET;
   }
 
   public class KeyStore {
@@ -32243,6 +32878,10 @@
   public final class ClientInfoStatus extends java.lang.Enum {
     method public static java.sql.ClientInfoStatus valueOf(java.lang.String);
     method public static final java.sql.ClientInfoStatus[] values();
+    enum_constant public static final java.sql.ClientInfoStatus REASON_UNKNOWN;
+    enum_constant public static final java.sql.ClientInfoStatus REASON_UNKNOWN_PROPERTY;
+    enum_constant public static final java.sql.ClientInfoStatus REASON_VALUE_INVALID;
+    enum_constant public static final java.sql.ClientInfoStatus REASON_VALUE_TRUNCATED;
   }
 
   public abstract interface Clob {
@@ -32927,6 +33566,11 @@
   public final class RowIdLifetime extends java.lang.Enum {
     method public static java.sql.RowIdLifetime valueOf(java.lang.String);
     method public static final java.sql.RowIdLifetime[] values();
+    enum_constant public static final java.sql.RowIdLifetime ROWID_UNSUPPORTED;
+    enum_constant public static final java.sql.RowIdLifetime ROWID_VALID_FOREVER;
+    enum_constant public static final java.sql.RowIdLifetime ROWID_VALID_OTHER;
+    enum_constant public static final java.sql.RowIdLifetime ROWID_VALID_SESSION;
+    enum_constant public static final java.sql.RowIdLifetime ROWID_VALID_TRANSACTION;
   }
 
   public class SQLClientInfoException extends java.sql.SQLException {
@@ -33716,6 +34360,10 @@
   public static final class Normalizer.Form extends java.lang.Enum {
     method public static java.text.Normalizer.Form valueOf(java.lang.String);
     method public static final java.text.Normalizer.Form[] values();
+    enum_constant public static final java.text.Normalizer.Form NFC;
+    enum_constant public static final java.text.Normalizer.Form NFD;
+    enum_constant public static final java.text.Normalizer.Form NFKC;
+    enum_constant public static final java.text.Normalizer.Form NFKD;
   }
 
   public abstract class NumberFormat extends java.text.Format {
@@ -34457,6 +35105,8 @@
   public static final class Formatter.BigDecimalLayoutForm extends java.lang.Enum {
     method public static java.util.Formatter.BigDecimalLayoutForm valueOf(java.lang.String);
     method public static final java.util.Formatter.BigDecimalLayoutForm[] values();
+    enum_constant public static final java.util.Formatter.BigDecimalLayoutForm DECIMAL_FLOAT;
+    enum_constant public static final java.util.Formatter.BigDecimalLayoutForm SCIENTIFIC;
   }
 
   public class FormatterClosedException extends java.lang.IllegalStateException implements java.io.Serializable {
@@ -35903,6 +36553,13 @@
     method public long toSeconds(long);
     method public static java.util.concurrent.TimeUnit valueOf(java.lang.String);
     method public static final java.util.concurrent.TimeUnit[] values();
+    enum_constant public static final java.util.concurrent.TimeUnit DAYS;
+    enum_constant public static final java.util.concurrent.TimeUnit HOURS;
+    enum_constant public static final java.util.concurrent.TimeUnit MICROSECONDS;
+    enum_constant public static final java.util.concurrent.TimeUnit MILLISECONDS;
+    enum_constant public static final java.util.concurrent.TimeUnit MINUTES;
+    enum_constant public static final java.util.concurrent.TimeUnit NANOSECONDS;
+    enum_constant public static final java.util.concurrent.TimeUnit SECONDS;
   }
 
   public class TimeoutException extends java.lang.Exception {
@@ -38559,11 +39216,20 @@
   public static final class SSLEngineResult.HandshakeStatus extends java.lang.Enum {
     method public static javax.net.ssl.SSLEngineResult.HandshakeStatus valueOf(java.lang.String);
     method public static final javax.net.ssl.SSLEngineResult.HandshakeStatus[] values();
+    enum_constant public static final javax.net.ssl.SSLEngineResult.HandshakeStatus FINISHED;
+    enum_constant public static final javax.net.ssl.SSLEngineResult.HandshakeStatus NEED_TASK;
+    enum_constant public static final javax.net.ssl.SSLEngineResult.HandshakeStatus NEED_UNWRAP;
+    enum_constant public static final javax.net.ssl.SSLEngineResult.HandshakeStatus NEED_WRAP;
+    enum_constant public static final javax.net.ssl.SSLEngineResult.HandshakeStatus NOT_HANDSHAKING;
   }
 
   public static final class SSLEngineResult.Status extends java.lang.Enum {
     method public static javax.net.ssl.SSLEngineResult.Status valueOf(java.lang.String);
     method public static final javax.net.ssl.SSLEngineResult.Status[] values();
+    enum_constant public static final javax.net.ssl.SSLEngineResult.Status BUFFER_OVERFLOW;
+    enum_constant public static final javax.net.ssl.SSLEngineResult.Status BUFFER_UNDERFLOW;
+    enum_constant public static final javax.net.ssl.SSLEngineResult.Status CLOSED;
+    enum_constant public static final javax.net.ssl.SSLEngineResult.Status OK;
   }
 
   public class SSLException extends java.io.IOException {
@@ -41077,11 +41743,15 @@
   public static final class RouteInfo.LayerType extends java.lang.Enum {
     method public static org.apache.http.conn.routing.RouteInfo.LayerType valueOf(java.lang.String);
     method public static final org.apache.http.conn.routing.RouteInfo.LayerType[] values();
+    enum_constant public static final org.apache.http.conn.routing.RouteInfo.LayerType LAYERED;
+    enum_constant public static final org.apache.http.conn.routing.RouteInfo.LayerType PLAIN;
   }
 
   public static final class RouteInfo.TunnelType extends java.lang.Enum {
     method public static org.apache.http.conn.routing.RouteInfo.TunnelType valueOf(java.lang.String);
     method public static final org.apache.http.conn.routing.RouteInfo.TunnelType[] values();
+    enum_constant public static final org.apache.http.conn.routing.RouteInfo.TunnelType PLAIN;
+    enum_constant public static final org.apache.http.conn.routing.RouteInfo.TunnelType TUNNELLED;
   }
 
   public final class RouteTracker implements java.lang.Cloneable org.apache.http.conn.routing.RouteInfo {
diff --git a/cmds/am/src/com/android/commands/am/Am.java b/cmds/am/src/com/android/commands/am/Am.java
index 38cacdd..424b70a 100644
--- a/cmds/am/src/com/android/commands/am/Am.java
+++ b/cmds/am/src/com/android/commands/am/Am.java
@@ -98,6 +98,8 @@
             runStart();
         } else if (op.equals("startservice")) {
             runStartService();
+        } else if (op.equals("force-stop")) {
+            runForceStop();
         } else if (op.equals("instrument")) {
             runInstrument();
         } else if (op.equals("broadcast")) {
@@ -365,6 +367,10 @@
         }
     }
 
+    private void runForceStop() throws Exception {
+        mAm.forceStopPackage(nextArgRequired());
+    }
+
     private void sendBroadcast() throws Exception {
         Intent intent = makeIntent();
         IntentReceiver receiver = new IntentReceiver();
@@ -851,7 +857,7 @@
                 wm.clearForcedDisplaySize();
             }
         } catch (RemoteException e) {
-       }
+        }
     }
 
     private class IntentReceiver extends IIntentReceiver.Stub {
@@ -1013,6 +1019,8 @@
                 "\n" +
                 "    start a Service: am startservice <INTENT>\n" +
                 "\n" +
+                "    force stop everything associated with a package: force-stop <package>\n" +
+                "\n" +
                 "    send a broadcast Intent: am broadcast <INTENT>\n" +
                 "\n" +
                 "    start an Instrumentation: am instrument [flags] <COMPONENT>\n" +
diff --git a/cmds/bootanimation/BootAnimation.cpp b/cmds/bootanimation/BootAnimation.cpp
index 69c4597..0acba8b 100644
--- a/cmds/bootanimation/BootAnimation.cpp
+++ b/cmds/bootanimation/BootAnimation.cpp
@@ -313,9 +313,6 @@
     const GLint yc = (mHeight - mAndroid[0].h) / 2;
     const Rect updateRect(xc, yc, xc + mAndroid[0].w, yc + mAndroid[0].h);
 
-    // draw and update only what we need
-    mFlingerSurface->setSwapRectangle(updateRect);
-
     glScissor(updateRect.left, mHeight - updateRect.bottom, updateRect.width(),
             updateRect.height());
 
diff --git a/cmds/bu/src/com/android/commands/bu/Backup.java b/cmds/bu/src/com/android/commands/bu/Backup.java
index f3f04326..e81f799 100644
--- a/cmds/bu/src/com/android/commands/bu/Backup.java
+++ b/cmds/bu/src/com/android/commands/bu/Backup.java
@@ -34,11 +34,12 @@
     IBackupManager mBackupManager;
 
     public static void main(String[] args) {
+        Log.d(TAG, "Beginning: " + args[0]);
         mArgs = args;
         try {
             new Backup().run();
         } catch (Exception e) {
-            Log.e(TAG, "Error running backup", e);
+            Log.e(TAG, "Error running backup/restore", e);
         }
         Log.d(TAG, "Finished.");
     }
@@ -46,7 +47,7 @@
     public void run() {
         mBackupManager = IBackupManager.Stub.asInterface(ServiceManager.getService("backup"));
         if (mBackupManager == null) {
-            System.err.println("ERROR: could not contact backup manager");
+            Log.e(TAG, "Can't obtain Backup Manager binder");
             return;
         }
 
@@ -56,7 +57,7 @@
         } else if (arg.equals("restore")) {
             doFullRestore();
         } else {
-            System.err.println("ERROR: invalid operation '" + arg + "'");
+            Log.e(TAG, "Invalid operation '" + arg + "'");
         }
     }
 
@@ -80,7 +81,6 @@
                 } else if ("-all".equals(arg)) {
                     doEverything = true;
                 } else {
-                    System.err.println("WARNING: unknown backup flag " + arg);
                     Log.w(TAG, "Unknown backup flag " + arg);
                     continue;
                 }
@@ -91,13 +91,10 @@
         }
 
         if (doEverything && packages.size() > 0) {
-            System.err.println("WARNING: -all used with explicit backup package set");
             Log.w(TAG, "-all passed for backup along with specific package names");
         }
 
         if (!doEverything && !saveShared && packages.size() == 0) {
-            System.err.println(
-                    "ERROR: no packages supplied for backup and neither -shared nor -all given");
             Log.e(TAG, "no backup packages supplied and neither -shared nor -all given");
             return;
         }
@@ -108,13 +105,22 @@
             mBackupManager.fullBackup(fd, saveApks, saveShared, doEverything,
                     packages.toArray(packArray));
         } catch (IOException e) {
-            System.err.println("ERROR: cannot dup System.out");
+            Log.e(TAG, "Can't dup out");
         } catch (RemoteException e) {
-            System.err.println("ERROR: unable to invoke backup manager service");
+            Log.e(TAG, "Unable to invoke backup manager for backup");
         }
     }
 
     private void doFullRestore() {
+        // No arguments to restore
+        try {
+            ParcelFileDescriptor fd = ParcelFileDescriptor.dup(FileDescriptor.in);
+            mBackupManager.fullRestore(fd);
+        } catch (IOException e) {
+            Log.e(TAG, "Can't dup System.in");
+        } catch (RemoteException e) {
+            Log.e(TAG, "Unable to invoke backup manager for restore");
+        }
     }
 
     private String nextArg() {
diff --git a/cmds/installd/commands.c b/cmds/installd/commands.c
index 9aa70a4..d45ac192 100644
--- a/cmds/installd/commands.c
+++ b/cmds/installd/commands.c
@@ -237,7 +237,7 @@
     if (create_cache_path(src_dex, src)) return -1;
     if (create_cache_path(dst_dex, dst)) return -1;
 
-    LOGI("move %s -> %s\n", src_dex, dst_dex);
+    LOGV("move %s -> %s\n", src_dex, dst_dex);
     if (rename(src_dex, dst_dex) < 0) {
         LOGE("Couldn't move %s: %s\n", src_dex, strerror(errno));
         return -1;
@@ -253,7 +253,7 @@
     if (validate_apk_path(path)) return -1;
     if (create_cache_path(dex_path, path)) return -1;
 
-    LOGI("unlink %s\n", dex_path);
+    LOGV("unlink %s\n", dex_path);
     if (unlink(dex_path) < 0) {
         LOGE("Couldn't unlink %s: %s\n", dex_path, strerror(errno));
         return -1;
@@ -452,7 +452,7 @@
     }
 
     if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
-        LOGD("DexInv: --- END '%s' (success) ---\n", apk_path);
+        LOGV("DexInv: --- END '%s' (success) ---\n", apk_path);
         return 0;
     } else {
         LOGW("DexInv: --- END '%s' --- status=0x%04x, process failed\n",
@@ -519,7 +519,7 @@
         goto fail;
     }
 
-    LOGD("DexInv: --- BEGIN '%s' ---\n", apk_path);
+    LOGV("DexInv: --- BEGIN '%s' ---\n", apk_path);
 
     pid_t pid;
     pid = fork();
@@ -587,7 +587,7 @@
         if (path[basepos] == '/') {
             path[basepos] = 0;
             if (lstat(path, statbuf) < 0) {
-                LOGI("Making directory: %s\n", path);
+                LOGV("Making directory: %s\n", path);
                 if (mkdir(path, mode) == 0) {
                     chown(path, uid, gid);
                 } else {
@@ -619,7 +619,7 @@
     if ((statbuf->st_mode&S_IFDIR) == 0) {
         mkinnerdirs(dstpath, dstbasepos, S_IRWXU|S_IRWXG|S_IXOTH,
                 dstuid, dstgid, statbuf);
-        LOGI("Renaming %s to %s (uid %d)\n", srcpath, dstpath, dstuid);
+        LOGV("Renaming %s to %s (uid %d)\n", srcpath, dstpath, dstuid);
         if (rename(srcpath, dstpath) >= 0) {
             if (chown(dstpath, dstuid, dstgid) < 0) {
                 LOGE("cannot chown %s: %s\n", dstpath, strerror(errno));
diff --git a/cmds/keystore/Android.mk b/cmds/keystore/Android.mk
index 15a199f..67dd9f8 100644
--- a/cmds/keystore/Android.mk
+++ b/cmds/keystore/Android.mk
@@ -19,14 +19,14 @@
 LOCAL_PATH:= $(call my-dir)
 
 include $(CLEAR_VARS)
-LOCAL_SRC_FILES := keystore.c
+LOCAL_SRC_FILES := keystore.cpp
 LOCAL_C_INCLUDES := external/openssl/include
 LOCAL_SHARED_LIBRARIES := libcutils libcrypto
 LOCAL_MODULE:= keystore
 include $(BUILD_EXECUTABLE)
 
 include $(CLEAR_VARS)
-LOCAL_SRC_FILES := keystore_cli.c
+LOCAL_SRC_FILES := keystore_cli.cpp
 LOCAL_C_INCLUDES := external/openssl/include
 LOCAL_SHARED_LIBRARIES := libcutils libcrypto
 LOCAL_MODULE:= keystore_cli
diff --git a/cmds/keystore/keystore.c b/cmds/keystore/keystore.c
deleted file mode 100644
index e34053b..0000000
--- a/cmds/keystore/keystore.c
+++ /dev/null
@@ -1,590 +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.
- */
-
-#include <stdio.h>
-#include <stdint.h>
-#include <string.h>
-#include <unistd.h>
-#include <signal.h>
-#include <errno.h>
-#include <dirent.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <arpa/inet.h>
-
-#include <openssl/aes.h>
-#include <openssl/evp.h>
-#include <openssl/md5.h>
-
-#define LOG_TAG "keystore"
-#include <cutils/log.h>
-#include <cutils/sockets.h>
-#include <private/android_filesystem_config.h>
-
-#include "keystore.h"
-
-/* KeyStore is a secured storage for key-value pairs. In this implementation,
- * each file stores one key-value pair. Keys are encoded in file names, and
- * values are encrypted with checksums. The encryption key is protected by a
- * user-defined password. To keep things simple, buffers are always larger than
- * the maximum space we needed, so boundary checks on buffers are omitted. */
-
-#define KEY_SIZE        ((NAME_MAX - 15) / 2)
-#define VALUE_SIZE      32768
-#define PASSWORD_SIZE   VALUE_SIZE
-
-/* Here is the encoding of keys. This is necessary in order to allow arbitrary
- * characters in keys. Characters in [0-~] are not encoded. Others are encoded
- * into two bytes. The first byte is one of [+-.] which represents the first
- * two bits of the character. The second byte encodes the rest of the bits into
- * [0-o]. Therefore in the worst case the length of a key gets doubled. Note
- * that Base64 cannot be used here due to the need of prefix match on keys. */
-
-static int encode_key(char *out, uint8_t *in, int length)
-{
-    int i;
-    for (i = length; i > 0; --i, ++in, ++out) {
-        if (*in >= '0' && *in <= '~') {
-            *out = *in;
-        } else {
-            *out = '+' + (*in >> 6);
-            *++out = '0' + (*in & 0x3F);
-            ++length;
-        }
-    }
-    *out = 0;
-    return length;
-}
-
-static int decode_key(uint8_t *out, char *in, int length)
-{
-    int i;
-    for (i = 0; i < length; ++i, ++in, ++out) {
-        if (*in >= '0' && *in <= '~') {
-            *out = *in;
-        } else {
-            *out = (*in - '+') << 6;
-            *out |= (*++in - '0') & 0x3F;
-            --length;
-        }
-    }
-    *out = 0;
-    return length;
-}
-
-/* Here is the protocol used in both requests and responses:
- *     code [length_1 message_1 ... length_n message_n] end-of-file
- * where code is one byte long and lengths are unsigned 16-bit integers in
- * network order. Thus the maximum length of a message is 65535 bytes. */
-
-static int the_socket = -1;
-
-static int recv_code(int8_t *code)
-{
-    return recv(the_socket, code, 1, 0) == 1;
-}
-
-static int recv_message(uint8_t *message, int length)
-{
-    uint8_t bytes[2];
-    if (recv(the_socket, &bytes[0], 1, 0) != 1 ||
-        recv(the_socket, &bytes[1], 1, 0) != 1) {
-        return -1;
-    } else {
-        int offset = bytes[0] << 8 | bytes[1];
-        if (length < offset) {
-            return -1;
-        }
-        length = offset;
-        offset = 0;
-        while (offset < length) {
-            int n = recv(the_socket, &message[offset], length - offset, 0);
-            if (n <= 0) {
-                return -1;
-            }
-            offset += n;
-        }
-    }
-    return length;
-}
-
-static int recv_end_of_file()
-{
-    uint8_t byte;
-    return recv(the_socket, &byte, 1, 0) == 0;
-}
-
-static void send_code(int8_t code)
-{
-    send(the_socket, &code, 1, 0);
-}
-
-static void send_message(uint8_t *message, int length)
-{
-    uint16_t bytes = htons(length);
-    send(the_socket, &bytes, 2, 0);
-    send(the_socket, message, length, 0);
-}
-
-/* Here is the file format. There are two parts in blob.value, the secret and
- * the description. The secret is stored in ciphertext, and its original size
- * can be found in blob.length. The description is stored after the secret in
- * plaintext, and its size is specified in blob.info. The total size of the two
- * parts must be no more than VALUE_SIZE bytes. The first three bytes of the
- * file are reserved for future use and are always set to zero. Fields other
- * than blob.info, blob.length, and blob.value are modified by encrypt_blob()
- * and decrypt_blob(). Thus they should not be accessed from outside. */
-
-static int the_entropy = -1;
-
-static struct __attribute__((packed)) {
-    uint8_t reserved[3];
-    uint8_t info;
-    uint8_t vector[AES_BLOCK_SIZE];
-    uint8_t encrypted[0];
-    uint8_t digest[MD5_DIGEST_LENGTH];
-    uint8_t digested[0];
-    int32_t length;
-    uint8_t value[VALUE_SIZE + AES_BLOCK_SIZE];
-} blob;
-
-static int8_t encrypt_blob(char *name, AES_KEY *aes_key)
-{
-    uint8_t vector[AES_BLOCK_SIZE];
-    int length;
-    int fd;
-
-    if (read(the_entropy, blob.vector, AES_BLOCK_SIZE) != AES_BLOCK_SIZE) {
-        return SYSTEM_ERROR;
-    }
-
-    length = blob.length + (blob.value - blob.encrypted);
-    length = (length + AES_BLOCK_SIZE - 1) / AES_BLOCK_SIZE * AES_BLOCK_SIZE;
-
-    if (blob.info != 0) {
-        memmove(&blob.encrypted[length], &blob.value[blob.length], blob.info);
-    }
-
-    blob.length = htonl(blob.length);
-    MD5(blob.digested, length - (blob.digested - blob.encrypted), blob.digest);
-
-    memcpy(vector, blob.vector, AES_BLOCK_SIZE);
-    AES_cbc_encrypt(blob.encrypted, blob.encrypted, length, aes_key, vector,
-                    AES_ENCRYPT);
-
-    memset(blob.reserved, 0, sizeof(blob.reserved));
-    length += (blob.encrypted - (uint8_t *)&blob) + blob.info;
-
-    fd = open(".tmp", O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR);
-    length -= write(fd, &blob, length);
-    close(fd);
-    return (length || rename(".tmp", name)) ? SYSTEM_ERROR : NO_ERROR;
-}
-
-static int8_t decrypt_blob(char *name, AES_KEY *aes_key)
-{
-    int fd = open(name, O_RDONLY);
-    int length;
-
-    if (fd == -1) {
-        return (errno == ENOENT) ? KEY_NOT_FOUND : SYSTEM_ERROR;
-    }
-    length = read(fd, &blob, sizeof(blob));
-    close(fd);
-
-    length -= (blob.encrypted - (uint8_t *)&blob) + blob.info;
-    if (length < blob.value - blob.encrypted || length % AES_BLOCK_SIZE != 0) {
-        return VALUE_CORRUPTED;
-    }
-
-    AES_cbc_encrypt(blob.encrypted, blob.encrypted, length, aes_key,
-                    blob.vector, AES_DECRYPT);
-    length -= blob.digested - blob.encrypted;
-    if (memcmp(blob.digest, MD5(blob.digested, length, NULL),
-               MD5_DIGEST_LENGTH)) {
-        return VALUE_CORRUPTED;
-    }
-
-    length -= blob.value - blob.digested;
-    blob.length = ntohl(blob.length);
-    if (blob.length < 0 || blob.length > length) {
-        return VALUE_CORRUPTED;
-    }
-    if (blob.info != 0) {
-        memmove(&blob.value[blob.length], &blob.value[length], blob.info);
-    }
-    return NO_ERROR;
-}
-
-/* Here are the actions. Each of them is a function without arguments. All
- * information is defined in global variables, which are set properly before
- * performing an action. The number of parameters required by each action is
- * fixed and defined in a table. If the return value of an action is positive,
- * it will be treated as a response code and transmitted to the client. Note
- * that the lengths of parameters are checked when they are received, so
- * boundary checks on parameters are omitted. */
-
-#define MAX_PARAM   2
-#define MAX_RETRY   4
-
-static uid_t uid = -1;
-static int8_t state = UNINITIALIZED;
-static int8_t retry = MAX_RETRY;
-
-static struct {
-    int length;
-    uint8_t value[VALUE_SIZE];
-} params[MAX_PARAM];
-
-static AES_KEY encryption_key;
-static AES_KEY decryption_key;
-
-static int8_t test()
-{
-    return state;
-}
-
-static int8_t get()
-{
-    char name[NAME_MAX];
-    int n = sprintf(name, "%u_", uid);
-    encode_key(&name[n], params[0].value, params[0].length);
-    n = decrypt_blob(name, &decryption_key);
-    if (n != NO_ERROR) {
-        return n;
-    }
-    send_code(NO_ERROR);
-    send_message(blob.value, blob.length);
-    return -NO_ERROR;
-}
-
-static int8_t insert()
-{
-    char name[NAME_MAX];
-    int n = sprintf(name, "%u_", uid);
-    encode_key(&name[n], params[0].value, params[0].length);
-    blob.info = 0;
-    blob.length = params[1].length;
-    memcpy(blob.value, params[1].value, params[1].length);
-    return encrypt_blob(name, &encryption_key);
-}
-
-static int8_t delete()
-{
-    char name[NAME_MAX];
-    int n = sprintf(name, "%u_", uid);
-    encode_key(&name[n], params[0].value, params[0].length);
-    return (unlink(name) && errno != ENOENT) ? SYSTEM_ERROR : NO_ERROR;
-}
-
-static int8_t exist()
-{
-    char name[NAME_MAX];
-    int n = sprintf(name, "%u_", uid);
-    encode_key(&name[n], params[0].value, params[0].length);
-    if (access(name, R_OK) == -1) {
-        return (errno != ENOENT) ? SYSTEM_ERROR : KEY_NOT_FOUND;
-    }
-    return NO_ERROR;
-}
-
-static int8_t saw()
-{
-    DIR *dir = opendir(".");
-    struct dirent *file;
-    char name[NAME_MAX];
-    int n;
-
-    if (!dir) {
-        return SYSTEM_ERROR;
-    }
-    n = sprintf(name, "%u_", uid);
-    n += encode_key(&name[n], params[0].value, params[0].length);
-    send_code(NO_ERROR);
-    while ((file = readdir(dir)) != NULL) {
-        if (!strncmp(name, file->d_name, n)) {
-            char *p = &file->d_name[n];
-            params[0].length = decode_key(params[0].value, p, strlen(p));
-            send_message(params[0].value, params[0].length);
-        }
-    }
-    closedir(dir);
-    return -NO_ERROR;
-}
-
-static int8_t reset()
-{
-    DIR *dir = opendir(".");
-    struct dirent *file;
-
-    memset(&encryption_key, 0, sizeof(encryption_key));
-    memset(&decryption_key, 0, sizeof(decryption_key));
-    state = UNINITIALIZED;
-    retry = MAX_RETRY;
-
-    if (!dir) {
-        return SYSTEM_ERROR;
-    }
-    while ((file = readdir(dir)) != NULL) {
-        unlink(file->d_name);
-    }
-    closedir(dir);
-    return NO_ERROR;
-}
-
-#define MASTER_KEY_FILE ".masterkey"
-#define MASTER_KEY_SIZE 16
-#define SALT_SIZE       16
-
-static void set_key(uint8_t *key, uint8_t *password, int length, uint8_t *salt)
-{
-    if (salt) {
-        PKCS5_PBKDF2_HMAC_SHA1((char *)password, length, salt, SALT_SIZE,
-                               8192, MASTER_KEY_SIZE, key);
-    } else {
-        PKCS5_PBKDF2_HMAC_SHA1((char *)password, length, (uint8_t *)"keystore",
-                               sizeof("keystore"), 1024, MASTER_KEY_SIZE, key);
-    }
-}
-
-/* Here is the history. To improve the security, the parameters to generate the
- * master key has been changed. To make a seamless transition, we update the
- * file using the same password when the user unlock it for the first time. If
- * any thing goes wrong during the transition, the new file will not overwrite
- * the old one. This avoids permanent damages of the existing data. */
-
-static int8_t password()
-{
-    uint8_t key[MASTER_KEY_SIZE];
-    AES_KEY aes_key;
-    int8_t response = SYSTEM_ERROR;
-
-    if (state == UNINITIALIZED) {
-        if (read(the_entropy, blob.value, MASTER_KEY_SIZE) != MASTER_KEY_SIZE) {
-           return SYSTEM_ERROR;
-        }
-    } else {
-        int fd = open(MASTER_KEY_FILE, O_RDONLY);
-        uint8_t *salt = NULL;
-        if (fd != -1) {
-            int length = read(fd, &blob, sizeof(blob));
-            close(fd);
-            if (length > SALT_SIZE && blob.info == SALT_SIZE) {
-                salt = (uint8_t *)&blob + length - SALT_SIZE;
-            }
-        }
-
-        set_key(key, params[0].value, params[0].length, salt);
-        AES_set_decrypt_key(key, MASTER_KEY_SIZE * 8, &aes_key);
-        response = decrypt_blob(MASTER_KEY_FILE, &aes_key);
-        if (response == SYSTEM_ERROR) {
-            return SYSTEM_ERROR;
-        }
-        if (response != NO_ERROR || blob.length != MASTER_KEY_SIZE) {
-            if (retry <= 0) {
-                reset();
-                return UNINITIALIZED;
-            }
-            return WRONG_PASSWORD + --retry;
-        }
-
-        if (!salt && params[1].length == -1) {
-            params[1] = params[0];
-        }
-    }
-
-    if (params[1].length == -1) {
-        memcpy(key, blob.value, MASTER_KEY_SIZE);
-    } else {
-        uint8_t *salt = &blob.value[MASTER_KEY_SIZE];
-        if (read(the_entropy, salt, SALT_SIZE) != SALT_SIZE) {
-            return SYSTEM_ERROR;
-        }
-
-        set_key(key, params[1].value, params[1].length, salt);
-        AES_set_encrypt_key(key, MASTER_KEY_SIZE * 8, &aes_key);
-        memcpy(key, blob.value, MASTER_KEY_SIZE);
-        blob.info = SALT_SIZE;
-        blob.length = MASTER_KEY_SIZE;
-        response = encrypt_blob(MASTER_KEY_FILE, &aes_key);
-    }
-
-    if (response == NO_ERROR) {
-        AES_set_encrypt_key(key, MASTER_KEY_SIZE * 8, &encryption_key);
-        AES_set_decrypt_key(key, MASTER_KEY_SIZE * 8, &decryption_key);
-        state = NO_ERROR;
-        retry = MAX_RETRY;
-    }
-    return response;
-}
-
-static int8_t lock()
-{
-    memset(&encryption_key, 0, sizeof(encryption_key));
-    memset(&decryption_key, 0, sizeof(decryption_key));
-    state = LOCKED;
-    return NO_ERROR;
-}
-
-static int8_t unlock()
-{
-    params[1].length = -1;
-    return password();
-}
-
-/* Here are the permissions, actions, users, and the main function. */
-
-enum perm {
-    TEST     =   1,
-    GET      =   2,
-    INSERT   =   4,
-    DELETE   =   8,
-    EXIST    =  16,
-    SAW      =  32,
-    RESET    =  64,
-    PASSWORD = 128,
-    LOCK     = 256,
-    UNLOCK   = 512,
-};
-
-static struct action {
-    int8_t (*run)();
-    int8_t code;
-    int8_t state;
-    uint32_t perm;
-    int lengths[MAX_PARAM];
-} actions[] = {
-    {test,     't', 0,        TEST,     {0}},
-    {get,      'g', NO_ERROR, GET,      {KEY_SIZE}},
-    {insert,   'i', NO_ERROR, INSERT,   {KEY_SIZE, VALUE_SIZE}},
-    {delete,   'd', 0,        DELETE,   {KEY_SIZE}},
-    {exist,    'e', 0,        EXIST,    {KEY_SIZE}},
-    {saw,      's', 0,        SAW,      {KEY_SIZE}},
-    {reset,    'r', 0,        RESET,    {0}},
-    {password, 'p', 0,        PASSWORD, {PASSWORD_SIZE, PASSWORD_SIZE}},
-    {lock,     'l', NO_ERROR, LOCK,     {0}},
-    {unlock,   'u', LOCKED,   UNLOCK,   {PASSWORD_SIZE}},
-    {NULL,      0 , 0,        0,        {0}},
-};
-
-static struct user {
-    uid_t uid;
-    uid_t euid;
-    uint32_t perms;
-} users[] = {
-    {AID_SYSTEM,   ~0,         ~GET},
-    {AID_VPN,      AID_SYSTEM, GET},
-    {AID_WIFI,     AID_SYSTEM, GET},
-    {AID_ROOT,     AID_SYSTEM, GET},
-    {AID_KEYCHAIN, AID_SYSTEM, TEST | GET | SAW},
-    {~0,           ~0,         TEST | GET | INSERT | DELETE | EXIST | SAW},
-};
-
-static int8_t process(int8_t code) {
-    struct user *user = users;
-    struct action *action = actions;
-    int i;
-
-    while (~user->uid && user->uid != uid) {
-        ++user;
-    }
-    while (action->code && action->code != code) {
-        ++action;
-    }
-    if (!action->code) {
-        return UNDEFINED_ACTION;
-    }
-    if (!(action->perm & user->perms)) {
-        return PERMISSION_DENIED;
-    }
-    if (action->state && action->state != state) {
-        return state;
-    }
-    if (~user->euid) {
-        uid = user->euid;
-    }
-    for (i = 0; i < MAX_PARAM && action->lengths[i]; ++i) {
-        params[i].length = recv_message(params[i].value, action->lengths[i]);
-        if (params[i].length == -1) {
-            return PROTOCOL_ERROR;
-        }
-    }
-    if (!recv_end_of_file()) {
-        return PROTOCOL_ERROR;
-    }
-    return action->run();
-}
-
-#define RANDOM_DEVICE   "/dev/urandom"
-
-int main(int argc, char **argv)
-{
-    int control_socket = android_get_control_socket("keystore");
-    if (argc < 2) {
-        LOGE("A directory must be specified!");
-        return 1;
-    }
-    if (chdir(argv[1]) == -1) {
-        LOGE("chdir: %s: %s", argv[1], strerror(errno));
-        return 1;
-    }
-    if ((the_entropy = open(RANDOM_DEVICE, O_RDONLY)) == -1) {
-        LOGE("open: %s: %s", RANDOM_DEVICE, strerror(errno));
-        return 1;
-    }
-    if (listen(control_socket, 3) == -1) {
-        LOGE("listen: %s", strerror(errno));
-        return 1;
-    }
-
-    signal(SIGPIPE, SIG_IGN);
-    if (access(MASTER_KEY_FILE, R_OK) == 0) {
-        state = LOCKED;
-    }
-
-    while ((the_socket = accept(control_socket, NULL, 0)) != -1) {
-        struct timeval tv = {.tv_sec = 3};
-        struct ucred cred;
-        socklen_t size = sizeof(cred);
-        int8_t request;
-
-        setsockopt(the_socket, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
-        setsockopt(the_socket, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
-
-        if (getsockopt(the_socket, SOL_SOCKET, SO_PEERCRED, &cred, &size)) {
-            LOGW("getsockopt: %s", strerror(errno));
-        } else if (recv_code(&request)) {
-            int8_t old_state = state;
-            int8_t response;
-            uid = cred.uid;
-
-            if ((response = process(request)) > 0) {
-                send_code(response);
-                response = -response;
-            }
-
-            LOGI("uid: %d action: %c -> %d state: %d -> %d retry: %d",
-                 cred.uid, request, -response, old_state, state, retry);
-        }
-        close(the_socket);
-    }
-    LOGE("accept: %s", strerror(errno));
-    return 1;
-}
diff --git a/cmds/keystore/keystore.cpp b/cmds/keystore/keystore.cpp
new file mode 100644
index 0000000..b48be6ef
--- /dev/null
+++ b/cmds/keystore/keystore.cpp
@@ -0,0 +1,810 @@
+/*
+ * 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.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+#include <unistd.h>
+#include <signal.h>
+#include <errno.h>
+#include <dirent.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <arpa/inet.h>
+
+#include <openssl/aes.h>
+#include <openssl/evp.h>
+#include <openssl/md5.h>
+
+#define LOG_TAG "keystore"
+#include <cutils/log.h>
+#include <cutils/sockets.h>
+#include <private/android_filesystem_config.h>
+
+#include "keystore.h"
+
+/* KeyStore is a secured storage for key-value pairs. In this implementation,
+ * each file stores one key-value pair. Keys are encoded in file names, and
+ * values are encrypted with checksums. The encryption key is protected by a
+ * user-defined password. To keep things simple, buffers are always larger than
+ * the maximum space we needed, so boundary checks on buffers are omitted. */
+
+#define KEY_SIZE        ((NAME_MAX - 15) / 2)
+#define VALUE_SIZE      32768
+#define PASSWORD_SIZE   VALUE_SIZE
+
+struct Value {
+    int length;
+    uint8_t value[VALUE_SIZE];
+};
+
+/* Here is the encoding of keys. This is necessary in order to allow arbitrary
+ * characters in keys. Characters in [0-~] are not encoded. Others are encoded
+ * into two bytes. The first byte is one of [+-.] which represents the first
+ * two bits of the character. The second byte encodes the rest of the bits into
+ * [0-o]. Therefore in the worst case the length of a key gets doubled. Note
+ * that Base64 cannot be used here due to the need of prefix match on keys. */
+
+static int encode_key(char* out, uid_t uid, const Value* key) {
+    int n = snprintf(out, NAME_MAX, "%u_", uid);
+    out += n;
+    const uint8_t* in = key->value;
+    int length = key->length;
+    for (int i = length; i > 0; --i, ++in, ++out) {
+        if (*in >= '0' && *in <= '~') {
+            *out = *in;
+        } else {
+            *out = '+' + (*in >> 6);
+            *++out = '0' + (*in & 0x3F);
+            ++length;
+        }
+    }
+    *out = '\0';
+    return n + length;
+}
+
+static int decode_key(uint8_t* out, char* in, int length) {
+    for (int i = 0; i < length; ++i, ++in, ++out) {
+        if (*in >= '0' && *in <= '~') {
+            *out = *in;
+        } else {
+            *out = (*in - '+') << 6;
+            *out |= (*++in - '0') & 0x3F;
+            --length;
+        }
+    }
+    *out = '\0';
+    return length;
+}
+
+static size_t readFully(int fd, uint8_t* data, size_t size) {
+    size_t remaining = size;
+    while (remaining > 0) {
+        ssize_t n = TEMP_FAILURE_RETRY(read(fd, data, size));
+        if (n == -1 || n == 0) {
+            return size-remaining;
+        }
+        data += n;
+        remaining -= n;
+    }
+    return size;
+}
+
+static size_t writeFully(int fd, uint8_t* data, size_t size) {
+    size_t remaining = size;
+    while (remaining > 0) {
+        ssize_t n = TEMP_FAILURE_RETRY(write(fd, data, size));
+        if (n == -1 || n == 0) {
+            return size-remaining;
+        }
+        data += n;
+        remaining -= n;
+    }
+    return size;
+}
+
+class Entropy {
+public:
+    Entropy() : mRandom(-1) {}
+    ~Entropy() {
+        if (mRandom != -1) {
+            close(mRandom);
+        }
+    }
+
+    bool open() {
+        const char* randomDevice = "/dev/urandom";
+        mRandom = ::open(randomDevice, O_RDONLY);
+        if (mRandom == -1) {
+            LOGE("open: %s: %s", randomDevice, strerror(errno));
+            return false;
+        }
+        return true;
+    }
+
+    bool generate_random_data(uint8_t* data, size_t size) {
+        return (readFully(mRandom, data, size) == size);
+    }
+
+private:
+    int mRandom;
+};
+
+/* Here is the file format. There are two parts in blob.value, the secret and
+ * the description. The secret is stored in ciphertext, and its original size
+ * can be found in blob.length. The description is stored after the secret in
+ * plaintext, and its size is specified in blob.info. The total size of the two
+ * parts must be no more than VALUE_SIZE bytes. The first three bytes of the
+ * file are reserved for future use and are always set to zero. Fields other
+ * than blob.info, blob.length, and blob.value are modified by encryptBlob()
+ * and decryptBlob(). Thus they should not be accessed from outside. */
+
+struct __attribute__((packed)) blob {
+    uint8_t reserved[3];
+    uint8_t info;
+    uint8_t vector[AES_BLOCK_SIZE];
+    uint8_t encrypted[0];
+    uint8_t digest[MD5_DIGEST_LENGTH];
+    uint8_t digested[0];
+    int32_t length; // in network byte order when encrypted
+    uint8_t value[VALUE_SIZE + AES_BLOCK_SIZE];
+};
+
+class Blob {
+public:
+    Blob(uint8_t* value, int32_t valueLength, uint8_t* info, uint8_t infoLength) {
+        mBlob.length = valueLength;
+        memcpy(mBlob.value, value, valueLength);
+
+        mBlob.info = infoLength;
+        memcpy(mBlob.value + valueLength, info, infoLength);
+    }
+
+    Blob(blob b) {
+        mBlob = b;
+    }
+
+    Blob() {}
+
+    uint8_t* getValue() {
+        return mBlob.value;
+    }
+
+    int32_t getLength() {
+        return mBlob.length;
+    }
+
+    uint8_t getInfo() {
+        return mBlob.info;
+    }
+
+    ResponseCode encryptBlob(const char* filename, AES_KEY *aes_key, Entropy* entropy) {
+        if (!entropy->generate_random_data(mBlob.vector, AES_BLOCK_SIZE)) {
+            return SYSTEM_ERROR;
+        }
+
+        // data includes the value and the value's length
+        size_t dataLength = mBlob.length + sizeof(mBlob.length);
+        // pad data to the AES_BLOCK_SIZE
+        size_t digestedLength = ((dataLength + AES_BLOCK_SIZE - 1)
+                                 / AES_BLOCK_SIZE * AES_BLOCK_SIZE);
+        // encrypted data includes the digest value
+        size_t encryptedLength = digestedLength + MD5_DIGEST_LENGTH;
+        // move info after space for padding
+        memmove(&mBlob.encrypted[encryptedLength], &mBlob.value[mBlob.length], mBlob.info);
+        // zero padding area
+        memset(mBlob.value + mBlob.length, 0, digestedLength - dataLength);
+
+        mBlob.length = htonl(mBlob.length);
+        MD5(mBlob.digested, digestedLength, mBlob.digest);
+
+        uint8_t vector[AES_BLOCK_SIZE];
+        memcpy(vector, mBlob.vector, AES_BLOCK_SIZE);
+        AES_cbc_encrypt(mBlob.encrypted, mBlob.encrypted, encryptedLength,
+                        aes_key, vector, AES_ENCRYPT);
+
+        memset(mBlob.reserved, 0, sizeof(mBlob.reserved));
+        size_t headerLength = (mBlob.encrypted - (uint8_t*) &mBlob);
+        size_t fileLength = encryptedLength + headerLength + mBlob.info;
+
+        const char* tmpFileName = ".tmp";
+        int out = open(tmpFileName, O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR);
+        if (out == -1) {
+            return SYSTEM_ERROR;
+        }
+        size_t writtenBytes = writeFully(out, (uint8_t*) &mBlob, fileLength);
+        if (close(out) != 0) {
+            return SYSTEM_ERROR;
+        }
+        if (writtenBytes != fileLength) {
+            unlink(tmpFileName);
+            return SYSTEM_ERROR;
+        }
+        return (rename(tmpFileName, filename) == 0) ? NO_ERROR : SYSTEM_ERROR;
+    }
+
+    ResponseCode decryptBlob(const char* filename, AES_KEY *aes_key) {
+        int in = open(filename, O_RDONLY);
+        if (in == -1) {
+            return (errno == ENOENT) ? KEY_NOT_FOUND : SYSTEM_ERROR;
+        }
+        // fileLength may be less than sizeof(mBlob) since the in
+        // memory version has extra padding to tolerate rounding up to
+        // the AES_BLOCK_SIZE
+        size_t fileLength = readFully(in, (uint8_t*) &mBlob, sizeof(mBlob));
+        if (close(in) != 0) {
+            return SYSTEM_ERROR;
+        }
+        size_t headerLength = (mBlob.encrypted - (uint8_t*) &mBlob);
+        if (fileLength < headerLength) {
+            return VALUE_CORRUPTED;
+        }
+
+        ssize_t encryptedLength = fileLength - (headerLength + mBlob.info);
+        if (encryptedLength < 0 || encryptedLength % AES_BLOCK_SIZE != 0) {
+            return VALUE_CORRUPTED;
+        }
+        AES_cbc_encrypt(mBlob.encrypted, mBlob.encrypted, encryptedLength, aes_key,
+                        mBlob.vector, AES_DECRYPT);
+        size_t digestedLength = encryptedLength - MD5_DIGEST_LENGTH;
+        uint8_t computedDigest[MD5_DIGEST_LENGTH];
+        MD5(mBlob.digested, digestedLength, computedDigest);
+        if (memcmp(mBlob.digest, computedDigest, MD5_DIGEST_LENGTH) != 0) {
+            return VALUE_CORRUPTED;
+        }
+
+        ssize_t maxValueLength = digestedLength - sizeof(mBlob.length);
+        mBlob.length = ntohl(mBlob.length);
+        if (mBlob.length < 0 || mBlob.length > maxValueLength) {
+            return VALUE_CORRUPTED;
+        }
+        if (mBlob.info != 0) {
+            // move info from after padding to after data
+            memmove(&mBlob.value[mBlob.length], &mBlob.value[maxValueLength], mBlob.info);
+        }
+        return NO_ERROR;
+    }
+
+private:
+    struct blob mBlob;
+};
+
+class KeyStore {
+public:
+    KeyStore(Entropy* entropy) : mEntropy(entropy), mRetry(MAX_RETRY) {
+        if (access(MASTER_KEY_FILE, R_OK) == 0) {
+            setState(STATE_LOCKED);
+        } else {
+            setState(STATE_UNINITIALIZED);
+        }
+    }
+
+    State getState() {
+        return mState;
+    }
+
+    int8_t getRetry() {
+        return mRetry;
+    }
+
+    ResponseCode initialize(Value* pw) {
+        if (!generateMasterKey()) {
+            return SYSTEM_ERROR;
+        }
+        ResponseCode response = writeMasterKey(pw);
+        if (response != NO_ERROR) {
+            return response;
+        }
+        setupMasterKeys();
+        return NO_ERROR;
+    }
+
+    ResponseCode writeMasterKey(Value* pw) {
+        uint8_t passwordKey[MASTER_KEY_SIZE_BYTES];
+        generateKeyFromPassword(passwordKey, MASTER_KEY_SIZE_BYTES, pw, mSalt);
+        AES_KEY passwordAesKey;
+        AES_set_encrypt_key(passwordKey, MASTER_KEY_SIZE_BITS, &passwordAesKey);
+        Blob masterKeyBlob(mMasterKey, sizeof(mMasterKey), mSalt, sizeof(mSalt));
+        return masterKeyBlob.encryptBlob(MASTER_KEY_FILE, &passwordAesKey, mEntropy);
+    }
+
+    ResponseCode readMasterKey(Value* pw) {
+        int in = open(MASTER_KEY_FILE, O_RDONLY);
+        if (in == -1) {
+            return SYSTEM_ERROR;
+        }
+
+        // we read the raw blob to just to get the salt to generate
+        // the AES key, then we create the Blob to use with decryptBlob
+        blob rawBlob;
+        size_t length = readFully(in, (uint8_t*) &rawBlob, sizeof(rawBlob));
+        if (close(in) != 0) {
+            return SYSTEM_ERROR;
+        }
+        // find salt at EOF if present, otherwise we have an old file
+        uint8_t* salt;
+        if (length > SALT_SIZE && rawBlob.info == SALT_SIZE) {
+            salt = (uint8_t*) &rawBlob + length - SALT_SIZE;
+        } else {
+            salt = NULL;
+        }
+        uint8_t passwordKey[MASTER_KEY_SIZE_BYTES];
+        generateKeyFromPassword(passwordKey, MASTER_KEY_SIZE_BYTES, pw, salt);
+        AES_KEY passwordAesKey;
+        AES_set_decrypt_key(passwordKey, MASTER_KEY_SIZE_BITS, &passwordAesKey);
+        Blob masterKeyBlob(rawBlob);
+        ResponseCode response = masterKeyBlob.decryptBlob(MASTER_KEY_FILE, &passwordAesKey);
+        if (response == SYSTEM_ERROR) {
+            return SYSTEM_ERROR;
+        }
+        if (response == NO_ERROR && masterKeyBlob.getLength() == MASTER_KEY_SIZE_BYTES) {
+            // if salt was missing, generate one and write a new master key file with the salt.
+            if (salt == NULL) {
+                if (!generateSalt()) {
+                    return SYSTEM_ERROR;
+                }
+                response = writeMasterKey(pw);
+            }
+            if (response == NO_ERROR) {
+                setupMasterKeys();
+            }
+            return response;
+        }
+        if (mRetry <= 0) {
+            reset();
+            return UNINITIALIZED;
+        }
+        --mRetry;
+        switch (mRetry) {
+            case 0: return WRONG_PASSWORD_0;
+            case 1: return WRONG_PASSWORD_1;
+            case 2: return WRONG_PASSWORD_2;
+            case 3: return WRONG_PASSWORD_3;
+            default: return WRONG_PASSWORD_3;
+        }
+    }
+
+    bool reset() {
+        clearMasterKeys();
+        setState(STATE_UNINITIALIZED);
+
+        DIR* dir = opendir(".");
+        struct dirent* file;
+
+        if (!dir) {
+            return false;
+        }
+        while ((file = readdir(dir)) != NULL) {
+            unlink(file->d_name);
+        }
+        closedir(dir);
+        return true;
+    }
+
+    bool isEmpty() {
+        DIR* dir = opendir(".");
+        struct dirent* file;
+        if (!dir) {
+            return true;
+        }
+        bool result = true;
+        while ((file = readdir(dir)) != NULL) {
+            if (isKeyFile(file->d_name)) {
+                result = false;
+                break;
+            }
+        }
+        closedir(dir);
+        return result;
+    }
+
+    void lock() {
+        clearMasterKeys();
+        setState(STATE_LOCKED);
+    }
+
+    ResponseCode get(const char* filename, Blob* keyBlob) {
+        return keyBlob->decryptBlob(filename, &mMasterKeyDecryption);
+    }
+
+    ResponseCode put(const char* filename, Blob* keyBlob) {
+        return keyBlob->encryptBlob(filename, &mMasterKeyEncryption, mEntropy);
+    }
+
+private:
+    static const char* MASTER_KEY_FILE;
+    static const int MASTER_KEY_SIZE_BYTES = 16;
+    static const int MASTER_KEY_SIZE_BITS = MASTER_KEY_SIZE_BYTES * 8;
+
+    static const int MAX_RETRY = 4;
+    static const size_t SALT_SIZE = 16;
+
+    Entropy* mEntropy;
+
+    State mState;
+    int8_t mRetry;
+
+    uint8_t mMasterKey[MASTER_KEY_SIZE_BYTES];
+    uint8_t mSalt[SALT_SIZE];
+
+    AES_KEY mMasterKeyEncryption;
+    AES_KEY mMasterKeyDecryption;
+
+    void setState(State state) {
+        mState = state;
+        if (mState == STATE_NO_ERROR || mState == STATE_UNINITIALIZED) {
+            mRetry = MAX_RETRY;
+        }
+    }
+
+    bool generateSalt() {
+        return mEntropy->generate_random_data(mSalt, sizeof(mSalt));
+    }
+
+    bool generateMasterKey() {
+        if (!mEntropy->generate_random_data(mMasterKey, sizeof(mMasterKey))) {
+            return false;
+        }
+        if (!generateSalt()) {
+            return false;
+        }
+        return true;
+    }
+
+    void setupMasterKeys() {
+        AES_set_encrypt_key(mMasterKey, MASTER_KEY_SIZE_BITS, &mMasterKeyEncryption);
+        AES_set_decrypt_key(mMasterKey, MASTER_KEY_SIZE_BITS, &mMasterKeyDecryption);
+        setState(STATE_NO_ERROR);
+    }
+
+    void clearMasterKeys() {
+        memset(mMasterKey, 0, sizeof(mMasterKey));
+        memset(mSalt, 0, sizeof(mSalt));
+        memset(&mMasterKeyEncryption, 0, sizeof(mMasterKeyEncryption));
+        memset(&mMasterKeyDecryption, 0, sizeof(mMasterKeyDecryption));
+    }
+
+    static void generateKeyFromPassword(uint8_t* key, ssize_t keySize, Value* pw, uint8_t* salt) {
+        size_t saltSize;
+        if (salt != NULL) {
+            saltSize = SALT_SIZE;
+        } else {
+            // pre-gingerbread used this hardwired salt, readMasterKey will rewrite these when found
+            salt = (uint8_t*) "keystore";
+            // sizeof = 9, not strlen = 8
+            saltSize = sizeof("keystore");
+        }
+        PKCS5_PBKDF2_HMAC_SHA1((char*) pw->value, pw->length, salt, saltSize, 8192, keySize, key);
+    }
+
+    static bool isKeyFile(const char* filename) {
+        return ((strcmp(filename, MASTER_KEY_FILE) != 0)
+                && (strcmp(filename, ".") != 0)
+                && (strcmp(filename, "..") != 0));
+    }
+};
+
+const char* KeyStore::MASTER_KEY_FILE = ".masterkey";
+
+/* Here is the protocol used in both requests and responses:
+ *     code [length_1 message_1 ... length_n message_n] end-of-file
+ * where code is one byte long and lengths are unsigned 16-bit integers in
+ * network order. Thus the maximum length of a message is 65535 bytes. */
+
+static int recv_code(int sock, int8_t* code) {
+    return recv(sock, code, 1, 0) == 1;
+}
+
+static int recv_message(int sock, uint8_t* message, int length) {
+    uint8_t bytes[2];
+    if (recv(sock, &bytes[0], 1, 0) != 1 ||
+        recv(sock, &bytes[1], 1, 0) != 1) {
+        return -1;
+    } else {
+        int offset = bytes[0] << 8 | bytes[1];
+        if (length < offset) {
+            return -1;
+        }
+        length = offset;
+        offset = 0;
+        while (offset < length) {
+            int n = recv(sock, &message[offset], length - offset, 0);
+            if (n <= 0) {
+                return -1;
+            }
+            offset += n;
+        }
+    }
+    return length;
+}
+
+static int recv_end_of_file(int sock) {
+    uint8_t byte;
+    return recv(sock, &byte, 1, 0) == 0;
+}
+
+static void send_code(int sock, int8_t code) {
+    send(sock, &code, 1, 0);
+}
+
+static void send_message(int sock, uint8_t* message, int length) {
+    uint16_t bytes = htons(length);
+    send(sock, &bytes, 2, 0);
+    send(sock, message, length, 0);
+}
+
+/* Here are the actions. Each of them is a function without arguments. All
+ * information is defined in global variables, which are set properly before
+ * performing an action. The number of parameters required by each action is
+ * fixed and defined in a table. If the return value of an action is positive,
+ * it will be treated as a response code and transmitted to the client. Note
+ * that the lengths of parameters are checked when they are received, so
+ * boundary checks on parameters are omitted. */
+
+static const ResponseCode NO_ERROR_RESPONSE_CODE_SENT = (ResponseCode) 0;
+
+static ResponseCode test(KeyStore* keyStore, int sock, uid_t uid, Value*, Value*) {
+    return (ResponseCode) keyStore->getState();
+}
+
+static ResponseCode get(KeyStore* keyStore, int sock, uid_t uid, Value* keyName, Value*) {
+    char filename[NAME_MAX];
+    encode_key(filename, uid, keyName);
+    Blob keyBlob;
+    ResponseCode responseCode = keyStore->get(filename, &keyBlob);
+    if (responseCode != NO_ERROR) {
+        return responseCode;
+    }
+    send_code(sock, NO_ERROR);
+    send_message(sock, keyBlob.getValue(), keyBlob.getLength());
+    return NO_ERROR_RESPONSE_CODE_SENT;
+}
+
+static ResponseCode insert(KeyStore* keyStore, int sock, uid_t uid, Value* keyName, Value* val) {
+    char filename[NAME_MAX];
+    encode_key(filename, uid, keyName);
+    Blob keyBlob(val->value, val->length, 0, NULL);
+    return keyStore->put(filename, &keyBlob);
+}
+
+static ResponseCode del(KeyStore* keyStore, int sock, uid_t uid, Value* keyName, Value*) {
+    char filename[NAME_MAX];
+    encode_key(filename, uid, keyName);
+    return (unlink(filename) && errno != ENOENT) ? SYSTEM_ERROR : NO_ERROR;
+}
+
+static ResponseCode exist(KeyStore* keyStore, int sock, uid_t uid, Value* keyName, Value*) {
+    char filename[NAME_MAX];
+    encode_key(filename, uid, keyName);
+    if (access(filename, R_OK) == -1) {
+        return (errno != ENOENT) ? SYSTEM_ERROR : KEY_NOT_FOUND;
+    }
+    return NO_ERROR;
+}
+
+static ResponseCode saw(KeyStore* keyStore, int sock, uid_t uid, Value* keyPrefix, Value*) {
+    DIR* dir = opendir(".");
+    if (!dir) {
+        return SYSTEM_ERROR;
+    }
+    char filename[NAME_MAX];
+    int n = encode_key(filename, uid, keyPrefix);
+    send_code(sock, NO_ERROR);
+
+    struct dirent* file;
+    while ((file = readdir(dir)) != NULL) {
+        if (!strncmp(filename, file->d_name, n)) {
+            char* p = &file->d_name[n];
+            keyPrefix->length = decode_key(keyPrefix->value, p, strlen(p));
+            send_message(sock, keyPrefix->value, keyPrefix->length);
+        }
+    }
+    closedir(dir);
+    return NO_ERROR_RESPONSE_CODE_SENT;
+}
+
+static ResponseCode reset(KeyStore* keyStore, int sock, uid_t uid, Value*, Value*) {
+    return keyStore->reset() ? NO_ERROR : SYSTEM_ERROR;
+}
+
+/* Here is the history. To improve the security, the parameters to generate the
+ * master key has been changed. To make a seamless transition, we update the
+ * file using the same password when the user unlock it for the first time. If
+ * any thing goes wrong during the transition, the new file will not overwrite
+ * the old one. This avoids permanent damages of the existing data. */
+
+static ResponseCode password(KeyStore* keyStore, int sock, uid_t uid, Value* pw, Value*) {
+    switch (keyStore->getState()) {
+        case STATE_UNINITIALIZED: {
+            // generate master key, encrypt with password, write to file, initialize mMasterKey*.
+            return keyStore->initialize(pw);
+        }
+        case STATE_NO_ERROR: {
+            // rewrite master key with new password.
+            return keyStore->writeMasterKey(pw);
+        }
+        case STATE_LOCKED: {
+            // read master key, decrypt with password, initialize mMasterKey*.
+            return keyStore->readMasterKey(pw);
+        }
+    }
+    return SYSTEM_ERROR;
+}
+
+static ResponseCode lock(KeyStore* keyStore, int sock, uid_t uid, Value*, Value*) {
+    keyStore->lock();
+    return NO_ERROR;
+}
+
+static ResponseCode unlock(KeyStore* keyStore, int sock, uid_t uid, Value* pw, Value* unused) {
+    return password(keyStore, sock, uid, pw, unused);
+}
+
+static ResponseCode zero(KeyStore* keyStore, int sock, uid_t uid, Value*, Value*) {
+    return keyStore->isEmpty() ? KEY_NOT_FOUND : NO_ERROR;
+}
+
+/* Here are the permissions, actions, users, and the main function. */
+
+enum perm {
+    TEST     =    1,
+    GET      =    2,
+    INSERT   =    4,
+    DELETE   =    8,
+    EXIST    =   16,
+    SAW      =   32,
+    RESET    =   64,
+    PASSWORD =  128,
+    LOCK     =  256,
+    UNLOCK   =  512,
+    ZERO     = 1024,
+};
+
+static const int MAX_PARAM = 2;
+
+static const State STATE_ANY = (State) 0;
+
+static struct action {
+    ResponseCode (*run)(KeyStore* keyStore, int sock, uid_t uid, Value* param1, Value* param2);
+    int8_t code;
+    State state;
+    uint32_t perm;
+    int lengths[MAX_PARAM];
+} actions[] = {
+    {test,     't', STATE_ANY,      TEST,     {0, 0}},
+    {get,      'g', STATE_NO_ERROR, GET,      {KEY_SIZE, 0}},
+    {insert,   'i', STATE_NO_ERROR, INSERT,   {KEY_SIZE, VALUE_SIZE}},
+    {del,      'd', STATE_ANY,      DELETE,   {KEY_SIZE, 0}},
+    {exist,    'e', STATE_ANY,      EXIST,    {KEY_SIZE, 0}},
+    {saw,      's', STATE_ANY,      SAW,      {KEY_SIZE, 0}},
+    {reset,    'r', STATE_ANY,      RESET,    {0, 0}},
+    {password, 'p', STATE_ANY,      PASSWORD, {PASSWORD_SIZE, 0}},
+    {lock,     'l', STATE_NO_ERROR, LOCK,     {0, 0}},
+    {unlock,   'u', STATE_LOCKED,   UNLOCK,   {PASSWORD_SIZE, 0}},
+    {zero,     'z', STATE_ANY,      ZERO,     {0, 0}},
+    {NULL,      0 , STATE_ANY,      0,        {0, 0}},
+};
+
+static struct user {
+    uid_t uid;
+    uid_t euid;
+    uint32_t perms;
+} users[] = {
+    {AID_SYSTEM,   ~0,         ~GET},
+    {AID_VPN,      AID_SYSTEM, GET},
+    {AID_WIFI,     AID_SYSTEM, GET},
+    {AID_ROOT,     AID_SYSTEM, GET},
+    {AID_KEYCHAIN, AID_SYSTEM, TEST | GET | SAW},
+    {~0,           ~0,         TEST | GET | INSERT | DELETE | EXIST | SAW},
+};
+
+static ResponseCode process(KeyStore* keyStore, int sock, uid_t uid, int8_t code) {
+    struct user* user = users;
+    struct action* action = actions;
+    int i;
+
+    while (~user->uid && user->uid != uid) {
+        ++user;
+    }
+    while (action->code && action->code != code) {
+        ++action;
+    }
+    if (!action->code) {
+        return UNDEFINED_ACTION;
+    }
+    if (!(action->perm & user->perms)) {
+        return PERMISSION_DENIED;
+    }
+    if (action->state != STATE_ANY && action->state != keyStore->getState()) {
+        return (ResponseCode) keyStore->getState();
+    }
+    if (~user->euid) {
+        uid = user->euid;
+    }
+    Value params[MAX_PARAM];
+    for (i = 0; i < MAX_PARAM && action->lengths[i] != 0; ++i) {
+        params[i].length = recv_message(sock, params[i].value, action->lengths[i]);
+        if (params[i].length < 0) {
+            return PROTOCOL_ERROR;
+        }
+    }
+    if (!recv_end_of_file(sock)) {
+        return PROTOCOL_ERROR;
+    }
+    return action->run(keyStore, sock, uid, &params[0], &params[1]);
+}
+
+int main(int argc, char* argv[]) {
+    int controlSocket = android_get_control_socket("keystore");
+    if (argc < 2) {
+        LOGE("A directory must be specified!");
+        return 1;
+    }
+    if (chdir(argv[1]) == -1) {
+        LOGE("chdir: %s: %s", argv[1], strerror(errno));
+        return 1;
+    }
+
+    Entropy entropy;
+    if (!entropy.open()) {
+        return 1;
+    }
+    if (listen(controlSocket, 3) == -1) {
+        LOGE("listen: %s", strerror(errno));
+        return 1;
+    }
+
+    signal(SIGPIPE, SIG_IGN);
+
+    KeyStore keyStore(&entropy);
+    int sock;
+    while ((sock = accept(controlSocket, NULL, 0)) != -1) {
+        struct timeval tv;
+        tv.tv_sec = 3;
+        setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
+        setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
+
+        struct ucred cred;
+        socklen_t size = sizeof(cred);
+        int credResult = getsockopt(sock, SOL_SOCKET, SO_PEERCRED, &cred, &size);
+        if (credResult != 0) {
+            LOGW("getsockopt: %s", strerror(errno));
+        } else {
+            int8_t request;
+            if (recv_code(sock, &request)) {
+                State old_state = keyStore.getState();
+                ResponseCode response = process(&keyStore, sock, cred.uid, request);
+                if (response == NO_ERROR_RESPONSE_CODE_SENT) {
+                    response = NO_ERROR;
+                } else {
+                    send_code(sock, response);
+                }
+                LOGI("uid: %d action: %c -> %d state: %d -> %d retry: %d",
+                     cred.uid,
+                     request, response,
+                     old_state, keyStore.getState(),
+                     keyStore.getRetry());
+            }
+        }
+        close(sock);
+    }
+    LOGE("accept: %s", strerror(errno));
+    return 1;
+}
diff --git a/cmds/keystore/keystore.h b/cmds/keystore/keystore.h
index 5ef51e9..5ae3d24 100644
--- a/cmds/keystore/keystore.h
+++ b/cmds/keystore/keystore.h
@@ -17,17 +17,27 @@
 #ifndef __KEYSTORE_H__
 #define __KEYSTORE_H__
 
-enum response_code {
-    NO_ERROR          =  1,
-    LOCKED            =  2,
-    UNINITIALIZED     =  3,
+// note state values overlap with ResponseCode for the purposes of the state() API
+enum State {
+    STATE_NO_ERROR      = 1,
+    STATE_LOCKED        = 2,
+    STATE_UNINITIALIZED = 3,
+};
+
+enum ResponseCode {
+    NO_ERROR          =  STATE_NO_ERROR, // 1
+    LOCKED            =  STATE_LOCKED, // 2
+    UNINITIALIZED     =  STATE_UNINITIALIZED, // 3
     SYSTEM_ERROR      =  4,
     PROTOCOL_ERROR    =  5,
     PERMISSION_DENIED =  6,
     KEY_NOT_FOUND     =  7,
     VALUE_CORRUPTED   =  8,
     UNDEFINED_ACTION  =  9,
-    WRONG_PASSWORD    = 10,
+    WRONG_PASSWORD_0  = 10,
+    WRONG_PASSWORD_1  = 11,
+    WRONG_PASSWORD_2  = 12,
+    WRONG_PASSWORD_3  = 13, // MAX_RETRY = 4
 };
 
 #endif
diff --git a/cmds/keystore/keystore_cli.c b/cmds/keystore/keystore_cli.c
deleted file mode 100644
index e8afb5a..0000000
--- a/cmds/keystore/keystore_cli.c
+++ /dev/null
@@ -1,97 +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.
- */
-
-#include <stdio.h>
-#include <stdint.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-
-#include <cutils/sockets.h>
-
-#include "keystore.h"
-
-char *responses[256] = {
-    [NO_ERROR]           = "No error",
-    [LOCKED]             = "Locked",
-    [UNINITIALIZED]      = "Uninitialized",
-    [SYSTEM_ERROR]       = "System error",
-    [PROTOCOL_ERROR]     = "Protocol error",
-    [PERMISSION_DENIED]  = "Permission denied",
-    [KEY_NOT_FOUND]      = "Key not found",
-    [VALUE_CORRUPTED]    = "Value corrupted",
-    [UNDEFINED_ACTION]   = "Undefined action",
-    [WRONG_PASSWORD]     = "Wrong password (last chance)",
-    [WRONG_PASSWORD + 1] = "Wrong password (2 tries left)",
-    [WRONG_PASSWORD + 2] = "Wrong password (3 tries left)",
-    [WRONG_PASSWORD + 3] = "Wrong password (4 tries left)",
-};
-
-#define MAX_RESPONSE (WRONG_PASSWORD + 3)
-
-int main(int argc, char **argv)
-{
-    uint8_t bytes[65536];
-    uint8_t code;
-    int sock, i;
-
-    if (argc < 2) {
-        printf("Usage: %s action [parameter ...]\n", argv[0]);
-        return 0;
-    }
-
-    sock = socket_local_client("keystore", ANDROID_SOCKET_NAMESPACE_RESERVED,
-                               SOCK_STREAM);
-    if (sock == -1) {
-        puts("Failed to connect");
-        return 1;
-    }
-
-    send(sock, argv[1], 1, 0);
-    for (i = 2; i < argc; ++i) {
-        uint16_t length = strlen(argv[i]);
-        bytes[0] = length >> 8;
-        bytes[1] = length;
-        send(sock, &bytes, 2, 0);
-        send(sock, argv[i], length, 0);
-    }
-    shutdown(sock, SHUT_WR);
-
-    if (recv(sock, &code, 1, 0) != 1) {
-        puts("Failed to receive");
-        return 1;
-    }
-    printf("%d %s\n", code , responses[code] ? responses[code] : "Unknown");
-    while ((i = recv(sock, &bytes[0], 1, 0)) == 1) {
-        int length;
-        int offset;
-        if ((i = recv(sock, &bytes[1], 1, 0)) != 1) {
-            puts("Failed to receive");
-            return 1;
-        }
-        length = bytes[0] << 8 | bytes[1];
-        for (offset = 0; offset < length; offset += i) {
-            i = recv(sock, &bytes[offset], length - offset, 0);
-            if (i <= 0) {
-                puts("Failed to receive");
-                return 1;
-            }
-        }
-        fwrite(bytes, 1, length, stdout);
-        puts("");
-    }
-    return 0;
-}
diff --git a/cmds/keystore/keystore_cli.cpp b/cmds/keystore/keystore_cli.cpp
new file mode 100644
index 0000000..dcd3bcb
--- /dev/null
+++ b/cmds/keystore/keystore_cli.cpp
@@ -0,0 +1,95 @@
+/*
+ * 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.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <cutils/sockets.h>
+
+#include "keystore.h"
+
+static const char* responses[] = {
+    NULL,
+    /* [NO_ERROR]           = */ "No error",
+    /* [LOCKED]             = */ "Locked",
+    /* [UNINITIALIZED]      = */ "Uninitialized",
+    /* [SYSTEM_ERROR]       = */ "System error",
+    /* [PROTOCOL_ERROR]     = */ "Protocol error",
+    /* [PERMISSION_DENIED]  = */ "Permission denied",
+    /* [KEY_NOT_FOUND]      = */ "Key not found",
+    /* [VALUE_CORRUPTED]    = */ "Value corrupted",
+    /* [UNDEFINED_ACTION]   = */ "Undefined action",
+    /* [WRONG_PASSWORD]     = */ "Wrong password (last chance)",
+    /* [WRONG_PASSWORD + 1] = */ "Wrong password (2 tries left)",
+    /* [WRONG_PASSWORD + 2] = */ "Wrong password (3 tries left)",
+    /* [WRONG_PASSWORD + 3] = */ "Wrong password (4 tries left)",
+};
+
+int main(int argc, char* argv[])
+{
+    if (argc < 2) {
+        printf("Usage: %s action [parameter ...]\n", argv[0]);
+        return 0;
+    }
+
+    int sock = socket_local_client("keystore", ANDROID_SOCKET_NAMESPACE_RESERVED,
+                                   SOCK_STREAM);
+    if (sock == -1) {
+        puts("Failed to connect");
+        return 1;
+    }
+
+    send(sock, argv[1], 1, 0);
+    uint8_t bytes[65536];
+    for (int i = 2; i < argc; ++i) {
+        uint16_t length = strlen(argv[i]);
+        bytes[0] = length >> 8;
+        bytes[1] = length;
+        send(sock, &bytes, 2, 0);
+        send(sock, argv[i], length, 0);
+    }
+    shutdown(sock, SHUT_WR);
+
+    uint8_t code;
+    if (recv(sock, &code, 1, 0) != 1) {
+        puts("Failed to receive");
+        return 1;
+    }
+    printf("%d %s\n", code , responses[code] ? responses[code] : "Unknown");
+    int i;
+    while ((i = recv(sock, &bytes[0], 1, 0)) == 1) {
+        int length;
+        int offset;
+        if ((i = recv(sock, &bytes[1], 1, 0)) != 1) {
+            puts("Failed to receive");
+            return 1;
+        }
+        length = bytes[0] << 8 | bytes[1];
+        for (offset = 0; offset < length; offset += i) {
+            i = recv(sock, &bytes[offset], length - offset, 0);
+            if (i <= 0) {
+                puts("Failed to receive");
+                return 1;
+            }
+        }
+        fwrite(bytes, 1, length, stdout);
+        puts("");
+    }
+    return 0;
+}
diff --git a/cmds/pm/src/com/android/commands/pm/Pm.java b/cmds/pm/src/com/android/commands/pm/Pm.java
index b0e4a86..e433079 100644
--- a/cmds/pm/src/com/android/commands/pm/Pm.java
+++ b/cmds/pm/src/com/android/commands/pm/Pm.java
@@ -120,6 +120,11 @@
             return;
         }
 
+        if ("disable-user".equals(op)) {
+            runSetEnabledSetting(PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER);
+            return;
+        }
+
         if ("setInstallLocation".equals(op)) {
             runSetInstallLocation();
             return;
@@ -970,6 +975,8 @@
                 return "enabled";
             case PackageManager.COMPONENT_ENABLED_STATE_DISABLED:
                 return "disabled";
+            case PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER:
+                return "disabled-user";
         }
         return "unknown";
     }
diff --git a/cmds/stagefright/stagefright.cpp b/cmds/stagefright/stagefright.cpp
index 01262fa..ca77185 100644
--- a/cmds/stagefright/stagefright.cpp
+++ b/cmds/stagefright/stagefright.cpp
@@ -66,6 +66,7 @@
 static long gMaxNumFrames;  // 0 means decode all available.
 static long gReproduceBug;  // if not -1.
 static bool gPreferSoftwareCodec;
+static bool gForceToUseHardwareCodec;
 static bool gPlaybackAudio;
 static bool gWriteMP4;
 static bool gDisplayHistogram;
@@ -144,10 +145,18 @@
     if (!strcasecmp(MEDIA_MIMETYPE_AUDIO_RAW, mime)) {
         rawSource = source;
     } else {
+        int flags = 0;
+        if (gPreferSoftwareCodec) {
+            flags |= OMXCodec::kPreferSoftwareCodecs;
+        }
+        if (gForceToUseHardwareCodec) {
+            CHECK(!gPreferSoftwareCodec);
+            flags |= OMXCodec::kHardwareCodecsOnly;
+        }
         rawSource = OMXCodec::Create(
             client->interface(), meta, false /* createEncoder */, source,
             NULL /* matchComponentName */,
-            gPreferSoftwareCodec ? OMXCodec::kPreferSoftwareCodecs : 0,
+            flags,
             gSurface);
 
         if (rawSource == NULL) {
@@ -545,6 +554,7 @@
     fprintf(stderr, "       -p(rofiles) dump decoder profiles supported\n");
     fprintf(stderr, "       -t(humbnail) extract video thumbnail or album art\n");
     fprintf(stderr, "       -s(oftware) prefer software codec\n");
+    fprintf(stderr, "       -r(hardware) force to use hardware codec\n");
     fprintf(stderr, "       -o playback audio\n");
     fprintf(stderr, "       -w(rite) filename (write to .mp4 file)\n");
     fprintf(stderr, "       -k seek test\n");
@@ -566,6 +576,7 @@
     gMaxNumFrames = 0;
     gReproduceBug = -1;
     gPreferSoftwareCodec = false;
+    gForceToUseHardwareCodec = false;
     gPlaybackAudio = false;
     gWriteMP4 = false;
     gDisplayHistogram = false;
@@ -575,7 +586,7 @@
     sp<LiveSession> liveSession;
 
     int res;
-    while ((res = getopt(argc, argv, "han:lm:b:ptsow:kxS")) >= 0) {
+    while ((res = getopt(argc, argv, "han:lm:b:ptsrow:kxS")) >= 0) {
         switch (res) {
             case 'a':
             {
@@ -636,6 +647,12 @@
                 break;
             }
 
+            case 'r':
+            {
+                gForceToUseHardwareCodec = true;
+                break;
+            }
+
             case 'o':
             {
                 gPlaybackAudio = true;
diff --git a/core/java/android/accessibilityservice/AccessibilityService.java b/core/java/android/accessibilityservice/AccessibilityService.java
index 03346fe..164acbc 100644
--- a/core/java/android/accessibilityservice/AccessibilityService.java
+++ b/core/java/android/accessibilityservice/AccessibilityService.java
@@ -25,6 +25,7 @@
 import android.os.RemoteException;
 import android.util.Log;
 import android.view.accessibility.AccessibilityEvent;
+import android.view.accessibility.AccessibilityNodeInfo;
 
 /**
  * An accessibility service runs in the background and receives callbacks by the system
@@ -39,21 +40,67 @@
  * <p>
  * <code>
  * &lt;service android:name=".MyAccessibilityService"&gt;<br>
- *     &lt;intent-filter&gt;<br>
- *         &lt;action android:name="android.accessibilityservice.AccessibilityService" /&gt;<br>
- *     &lt;/intent-filter&gt;<br>
+ * &nbsp;&nbsp;&lt;intent-filter&gt;<br>
+ * &nbsp;&nbsp;&nbsp;&nbsp;&lt;action android:name="android.accessibilityservice.AccessibilityService" /&gt;<br>
+ * &nbsp;&nbsp;&lt;/intent-filter&gt;<br>
  * &lt;/service&gt;<br>
  * </code>
+ * </p>
  * <p>
  * The lifecycle of an accessibility service is managed exclusively by the system. Starting
  * or stopping an accessibility service is triggered by an explicit user action through
  * enabling or disabling it in the device settings. After the system binds to a service it
  * calls {@link AccessibilityService#onServiceConnected()}. This method can be
- * overriden by clients that want to perform post binding setup. An accessibility service
- * is configured though setting an {@link AccessibilityServiceInfo} by calling
- * {@link AccessibilityService#setServiceInfo(AccessibilityServiceInfo)}. You can call this
- * method any time to change the service configuration but it is good practice to do that
- * in the overriden {@link AccessibilityService#onServiceConnected()}.
+ * overriden by clients that want to perform post binding setup.
+ * </p>
+ * <p>
+ * An accessibility service can be configured to receive specific types of accessibility events,
+ * listen only to specific packages, get events from each type only once in a given time frame,
+ * retrieve window content, specify a settings activity, etc.
+ * </p>
+ * There are two approaches for configuring an accessibility service:
+ * <ul>
+ *   <li>
+ *     Providing a {@link #SERVICE_META_DATA meta-data} entry in the manifest when declaring
+ *     the service. A service declaration with a meta-data tag is presented below:
+ *     <p>
+ *       <code>
+ *         &lt;service android:name=".MyAccessibilityService"&gt;<br>
+ *         &nbsp;&nbsp;&lt;intent-filter&gt;<br>
+ *         &nbsp;&nbsp;&nbsp;&nbsp;&lt;action android:name="android.accessibilityservice.AccessibilityService" /&gt;<br>
+ *         &nbsp;&nbsp;&lt;/intent-filter&gt;<br>
+ *         &nbsp;&nbsp;&lt;meta-data android:name="android.accessibilityservice.as" android:resource="@xml/accessibilityservice" /&gt;<br>
+ *         &lt;/service&gt;<br>
+ *       </code>
+ *     </p>
+ *     <p>
+ *     <strong>
+ *       This approach enables setting all accessibility service properties.
+ *     </strong>
+ *     </p>
+ *     <p>
+ *       For more details refer to {@link #SERVICE_META_DATA}.
+ *     </p>
+ *   </li>
+ *   <li>
+ *     Calling {@link AccessibilityService#setServiceInfo(AccessibilityServiceInfo)}. Note
+ *     that this method can be called any time to change the service configuration.<br>
+ *     <p>
+ *     <strong>
+ *       This approach enables setting only dynamically configurable accessibility
+ *       service properties:
+ *       {@link AccessibilityServiceInfo#eventTypes},
+ *       {@link AccessibilityServiceInfo#feedbackType},
+ *       {@link AccessibilityServiceInfo#flags},
+ *       {@link AccessibilityServiceInfo#notificationTimeout},
+ *       {@link AccessibilityServiceInfo#packageNames}
+ *     </strong>
+ *     </p>
+ *     <p>
+ *       For more details refer to {@link AccessibilityServiceInfo}.
+ *     </p>
+ *   </li>
+ * </ul>
  * <p>
  * An accessibility service can be registered for events in specific packages to provide a
  * specific type of feedback and is notified with a certain timeout after the last event
@@ -105,6 +152,62 @@
     public static final String SERVICE_INTERFACE =
         "android.accessibilityservice.AccessibilityService";
 
+    /**
+     * Name under which an AccessibilityService component publishes information
+     * about itself. This meta-data must reference an XML resource containing
+     * an
+     * <code>&lt;{@link android.R.styleable#AccessibilityService accessibility-service}&gt;</code>
+     * tag. This is a a sample XML file configuring an accessibility service:
+     * <p>
+     * <code>
+     *   &lt;?xml version="1.0" encoding="utf-8"?&gt;<br>
+     *   &lt;accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"<br>
+     *   &nbsp;&nbsp;android:accessibilityEventTypes="typeViewClicked|typeViewFocused"<br>
+     *   &nbsp;&nbsp;android:packageNames="foo.bar, foo.baz"<br>
+     *   &nbsp;&nbsp;android:accessibilityFeedbackType="feedbackSpoken"<br>
+     *   &nbsp;&nbsp;android:notificationTimeout="100"<br>
+     *   &nbsp;&nbsp;android:accessibilityFlags="flagDefault"<br>
+     *   &nbsp;&nbsp;android:settingsActivity="foo.bar.TestBackActivity"<br>
+     *   &nbsp;&nbsp;. . .<br>
+     *   /&gt;
+     * </code>
+     * </p>
+     * <p>
+     *  <strong>Note:</strong> A service can retrieve only the content of the active window.
+     *          An active window is the source of the most recent event of type
+     *          {@link AccessibilityEvent#TYPE_TOUCH_EXPLORATION_GESTURE_START},
+     *          {@link AccessibilityEvent#TYPE_TOUCH_EXPLORATION_GESTURE_END},
+     *          {@link AccessibilityEvent#TYPE_VIEW_CLICKED},
+     *          {@link AccessibilityEvent#TYPE_VIEW_FOCUSED},
+     *          {@link AccessibilityEvent#TYPE_VIEW_HOVER_ENTER},
+     *          {@link AccessibilityEvent#TYPE_VIEW_HOVER_EXIT},
+     *          {@link AccessibilityEvent#TYPE_VIEW_LONG_CLICKED},
+     *          {@link AccessibilityEvent#TYPE_VIEW_SELECTED},
+     *          {@link AccessibilityEvent#TYPE_VIEW_TEXT_CHANGED},
+     *          {@link AccessibilityEvent#TYPE_WINDOW_STATE_CHANGED}.
+     *          Therefore the service should:
+     *          <ul>
+     *            <li>
+     *              Register for all event types with no notification timeout and keep track
+     *              for the active window by calling
+     *              {@link AccessibilityEvent#getWindowId()} of the last received
+     *              event and compare this with the
+     *              {@link AccessibilityNodeInfo#getWindowId()} before calling
+     *              retrieval methods on the latter.
+     *            </li>
+     *            <li>
+     *              Prepare that a retrieval method on {@link AccessibilityNodeInfo} may fail
+     *              since the active window has changed and the service did not get the 
+     *              accessibility event. Note that it is possible to have a retrieval method
+     *              failing event adopting the strategy specified in the previous bullet
+     *              because the accessibility event dispatch is asynchronous and crosses
+     *              process boundaries. 
+     *            </li>
+     *          <ul>
+     * </p>
+     */
+    public static final String SERVICE_META_DATA = "android.accessibilityservice";
+
     private static final String LOG_TAG = "AccessibilityService";
 
     private AccessibilityServiceInfo mInfo;
@@ -165,7 +268,7 @@
 
     /**
      * Implement to return the implementation of the internal accessibility
-     * service interface.  Subclasses should not override.
+     * service interface.
      */
     @Override
     public final IBinder onBind(Intent intent) {
diff --git a/core/java/android/accessibilityservice/AccessibilityServiceInfo.java b/core/java/android/accessibilityservice/AccessibilityServiceInfo.java
index bf9e07d..b9878cd 100644
--- a/core/java/android/accessibilityservice/AccessibilityServiceInfo.java
+++ b/core/java/android/accessibilityservice/AccessibilityServiceInfo.java
@@ -16,8 +16,25 @@
 
 package android.accessibilityservice;
 
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.pm.ResolveInfo;
+import android.content.pm.ServiceInfo;
+import android.content.res.Resources;
+import android.content.res.TypedArray;
+import android.content.res.XmlResourceParser;
 import android.os.Parcel;
 import android.os.Parcelable;
+import android.util.AttributeSet;
+import android.util.Xml;
+import android.view.accessibility.AccessibilityEvent;
+
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+
+import java.io.IOException;
 
 /**
  * This class describes an {@link AccessibilityService}. The system
@@ -30,6 +47,8 @@
  */
 public class AccessibilityServiceInfo implements Parcelable {
 
+    private static final String TAG_ACCESSIBILITY_SERVICE = "accessibility-service";
+
     /**
      * Denotes spoken feedback.
      */
@@ -64,7 +83,9 @@
 
     /**
      * The event types an {@link AccessibilityService} is interested in.
-     *
+     * <p>
+     *   <strong>Can be dynamically set at runtime.</strong>
+     * </p>
      * @see android.view.accessibility.AccessibilityEvent#TYPE_VIEW_CLICKED
      * @see android.view.accessibility.AccessibilityEvent#TYPE_VIEW_LONG_CLICKED
      * @see android.view.accessibility.AccessibilityEvent#TYPE_VIEW_FOCUSED
@@ -77,13 +98,18 @@
 
     /**
      * The package names an {@link AccessibilityService} is interested in. Setting
-     * to null is equivalent to all packages. 
+     * to null is equivalent to all packages.
+     * <p>
+     *   <strong>Can be dynamically set at runtime.</strong>
+     * </p>
      */
     public String[] packageNames;
 
     /**
      * The feedback type an {@link AccessibilityService} provides.
-     *
+     * <p>
+     *   <strong>Can be dynamically set at runtime.</strong>
+     * </p>
      * @see #FEEDBACK_AUDIBLE
      * @see #FEEDBACK_GENERIC
      * @see #FEEDBACK_HAPTIC
@@ -96,6 +122,9 @@
      * The timeout after the most recent event of a given type before an
      * {@link AccessibilityService} is notified.
      * <p>
+     *   <strong>Can be dynamically set at runtime.</strong>.
+     * </p>
+     * <p>
      * Note: The event notification timeout is useful to avoid propagating events to the client
      *       too frequently since this is accomplished via an expensive interprocess call.
      *       One can think of the timeout as a criteria to determine when event generation has
@@ -106,11 +135,181 @@
     /**
      * This field represents a set of flags used for configuring an
      * {@link AccessibilityService}.
-     *
+     * <p>
+     *   <strong>Can be dynamically set at runtime.</strong>
+     * </p>
      * @see #DEFAULT
      */
     public int flags;
 
+    /**
+     * The unique string Id to identify the accessibility service.
+     */
+    private String mId;
+
+    /**
+     * The Service that implements this accessibility service component.
+     */
+    private ResolveInfo mResolveInfo;
+
+    /**
+     * The accessibility service setting activity's name, used by the system
+     * settings to launch the setting activity of this accessibility service.
+     */
+    private String mSettingsActivityName;
+
+    /**
+     * Flag whether this accessibility service can retrieve screen content.
+     */
+    private boolean mCanRetrieveWindowContent;
+
+    /**
+     * Creates a new instance.
+     */
+    public AccessibilityServiceInfo() {
+        /* do nothing */
+    }
+
+    /**
+     * Creates a new instance.
+     *
+     * @param resolveInfo The service resolve info.
+     * @param context Context for accessing resources.
+     * @throws XmlPullParserException If a XML parsing error occurs.
+     * @throws IOException If a XML parsing error occurs.
+     *
+     * @hide
+     */
+    public AccessibilityServiceInfo(ResolveInfo resolveInfo, Context context)
+            throws XmlPullParserException, IOException {
+        ServiceInfo serviceInfo = resolveInfo.serviceInfo;
+        mId = new ComponentName(serviceInfo.packageName, serviceInfo.name).flattenToShortString();
+        mResolveInfo = resolveInfo;
+
+        String settingsActivityName = null;
+        boolean retrieveScreenContent = false;
+        XmlResourceParser parser = null;
+
+        try {
+            PackageManager packageManager = context.getPackageManager();
+            parser = serviceInfo.loadXmlMetaData(packageManager,
+                    AccessibilityService.SERVICE_META_DATA);
+            if (parser == null) {
+                return;
+            }
+
+            int type = 0;
+            while (type != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
+                type = parser.next();
+            }
+
+            String nodeName = parser.getName();
+            if (!TAG_ACCESSIBILITY_SERVICE.equals(nodeName)) {
+                throw new XmlPullParserException( "Meta-data does not start with"
+                        + TAG_ACCESSIBILITY_SERVICE + " tag");
+            }
+
+            AttributeSet allAttributes = Xml.asAttributeSet(parser);
+            Resources resources = packageManager.getResourcesForApplication(
+                    serviceInfo.applicationInfo);
+            TypedArray asAttributes = resources.obtainAttributes(allAttributes,
+                    com.android.internal.R.styleable.AccessibilityService);
+            eventTypes = asAttributes.getInt(
+                    com.android.internal.R.styleable.AccessibilityService_accessibilityEventTypes,
+                    0);
+            String packageNamez = asAttributes.getString(
+                    com.android.internal.R.styleable.AccessibilityService_packageNames);
+            if (packageNamez != null) {
+                packageNames = packageNamez.split("(\\s)*,(\\s)*");
+            }
+            feedbackType = asAttributes.getInt(
+                    com.android.internal.R.styleable.AccessibilityService_accessibilityFeedbackType,
+                    0);
+            notificationTimeout = asAttributes.getInt(
+                    com.android.internal.R.styleable.AccessibilityService_notificationTimeout, 
+                    0);
+            flags = asAttributes.getInt(
+                    com.android.internal.R.styleable.AccessibilityService_accessibilityFlags, 0);
+            mSettingsActivityName = asAttributes.getString(
+                    com.android.internal.R.styleable.AccessibilityService_settingsActivity);
+            mCanRetrieveWindowContent = asAttributes.getBoolean(
+                    com.android.internal.R.styleable.AccessibilityService_canRetrieveWindowContent,
+                    false);
+            asAttributes.recycle();
+        } catch (NameNotFoundException e) {
+            throw new XmlPullParserException( "Unable to create context for: "
+                    + serviceInfo.packageName);
+        } finally {
+            if (parser != null) {
+                parser.close();
+            }
+        }
+    }
+
+    /**
+     * Updates the properties that an AccessibilitySerivice can change dynamically.
+     *
+     * @param other The info from which to update the properties.
+     *
+     * @hide
+     */
+    public void updateDynamicallyConfigurableProperties(AccessibilityServiceInfo other) {
+        eventTypes = other.eventTypes;
+        packageNames = other.packageNames;
+        feedbackType = other.feedbackType;
+        notificationTimeout = other.notificationTimeout;
+        flags = other.flags;
+    }
+
+    /**
+     * The accessibility service id.
+     * <p>
+     *   <strong>Generated by the system.</strong>
+     * </p>
+     * @return The id.
+     */
+    public String getId() {
+        return mId;
+    }
+
+    /**
+     * The service {@link ResolveInfo}.
+     * <p>
+     *   <strong>Generated by the system.</strong>
+     * </p>
+     * @return The info.
+     */
+    public ResolveInfo getResolveInfo() {
+        return mResolveInfo;
+    }
+
+    /**
+     * The settings activity name.
+     * <p>
+     *    <strong>Statically set from
+     *    {@link AccessibilityService#SERVICE_META_DATA meta-data}.</strong>
+     * </p>
+     * @return The settings activity name.
+     */
+    public String getSettingsActivityName() {
+        return mSettingsActivityName;
+    }
+
+    /**
+     * Whether this service can retrieve the currently focused window content.
+     * <p>
+     *    <strong>Statically set from
+     *    {@link AccessibilityService#SERVICE_META_DATA meta-data}.</strong>
+     * </p>
+     * @return True screen content is retrieved.
+     */
+    public boolean getCanRetrieveWindowContent() {
+        return mCanRetrieveWindowContent;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
     public int describeContents() {
         return 0;
     }
@@ -121,6 +320,142 @@
         parcel.writeInt(feedbackType);
         parcel.writeLong(notificationTimeout);
         parcel.writeInt(flags);
+        parcel.writeString(mId);
+        parcel.writeParcelable(mResolveInfo, 0);
+        parcel.writeString(mSettingsActivityName);
+        parcel.writeInt(mCanRetrieveWindowContent ? 1 : 0);
+    }
+
+    private void initFromParcel(Parcel parcel) {
+        eventTypes = parcel.readInt();
+        packageNames = parcel.readStringArray();
+        feedbackType = parcel.readInt();
+        notificationTimeout = parcel.readLong();
+        flags = parcel.readInt();
+        mId = parcel.readString();
+        mResolveInfo = parcel.readParcelable(null);
+        mSettingsActivityName = parcel.readString();
+        mCanRetrieveWindowContent = (parcel.readInt() == 1);
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder stringBuilder = new StringBuilder();
+        appendEventTypes(stringBuilder, eventTypes);
+        stringBuilder.append(", ");
+        appendPackageNames(stringBuilder, packageNames);
+        stringBuilder.append(", ");
+        appendFeedbackTypes(stringBuilder, feedbackType);
+        stringBuilder.append(", ");
+        stringBuilder.append("notificationTimeout: ").append(notificationTimeout);
+        stringBuilder.append(", ");
+        appendFlags(stringBuilder, flags);
+        stringBuilder.append(", ");
+        stringBuilder.append("id: ").append(mId);
+        stringBuilder.append(", ");
+        stringBuilder.append("resolveInfo: ").append(mResolveInfo);
+        stringBuilder.append(", ");
+        stringBuilder.append("settingsActivityName: ").append(mSettingsActivityName);
+        stringBuilder.append(", ");
+        stringBuilder.append("retrieveScreenContent: ").append(mCanRetrieveWindowContent);
+        return stringBuilder.toString();
+    }
+
+    private static void appendFeedbackTypes(StringBuilder stringBuilder, int feedbackTypes) {
+        stringBuilder.append("feedbackTypes:");
+        stringBuilder.append("[");
+        while (feedbackTypes != 0) {
+            final int feedbackTypeBit = (1 << Integer.numberOfTrailingZeros(feedbackTypes));
+            stringBuilder.append(feedbackTypeToString(feedbackTypeBit));
+            feedbackTypes &= ~feedbackTypeBit;
+            if (feedbackTypes != 0) {
+                stringBuilder.append(", ");
+            }
+        }
+        stringBuilder.append("]");
+    }
+
+    private static void appendPackageNames(StringBuilder stringBuilder, String[] packageNames) {
+        stringBuilder.append("packageNames:");
+        stringBuilder.append("[");
+        if (packageNames != null) {
+            final int packageNameCount = packageNames.length;
+            for (int i = 0; i < packageNameCount; i++) {
+                stringBuilder.append(packageNames[i]);
+                if (i < packageNameCount - 1) {
+                    stringBuilder.append(", ");
+                }
+            }
+        }
+        stringBuilder.append("]");
+    }
+
+    private static void appendEventTypes(StringBuilder stringBuilder, int eventTypes) {
+        stringBuilder.append("eventTypes:");
+        stringBuilder.append("[");
+        while (eventTypes != 0) {
+            final int eventTypeBit = (1 << Integer.numberOfTrailingZeros(eventTypes));
+            stringBuilder.append(AccessibilityEvent.eventTypeToString(eventTypeBit));
+            eventTypes &= ~eventTypeBit;
+            if (eventTypes != 0) {
+                stringBuilder.append(", ");
+            }
+        }
+        stringBuilder.append("]");
+    }
+
+    private static void appendFlags(StringBuilder stringBuilder, int flags) {
+        stringBuilder.append("flags:");
+        stringBuilder.append("[");
+        while (flags != 0) {
+            final int flagBit = (1 << Integer.numberOfTrailingZeros(flags));
+            stringBuilder.append(flagToString(flagBit));
+            flags &= ~flagBit;
+            if (flags != 0) {
+                stringBuilder.append(", ");
+            }
+        }
+        stringBuilder.append("]");
+    }
+
+    /**
+     * Returns the string representation of a feedback type. For example,
+     * {@link #FEEDBACK_SPOKEN} is represented by the string FEEDBACK_SPOKEN.
+     *
+     * @param feedbackType The feedback type.
+     * @return The string representation.
+     */
+    public static String feedbackTypeToString(int feedbackType) {
+        switch (feedbackType) {
+            case FEEDBACK_AUDIBLE:
+                return "FEEDBACK_AUDIBLE";
+            case FEEDBACK_HAPTIC:
+                return "FEEDBACK_HAPTIC";
+            case FEEDBACK_GENERIC:
+                return "FEEDBACK_GENERIC";
+            case FEEDBACK_SPOKEN:
+                return "FEEDBACK_SPOKEN";
+            case FEEDBACK_VISUAL:
+                return "FEEDBACK_VISUAL";
+            default:
+                return null;
+        }
+    }
+
+    /**
+     * Returns the string representation of a flag. For example,
+     * {@link #DEFAULT} is represented by the string DEFAULT.
+     *
+     * @param flag The flag.
+     * @return The string representation.
+     */
+    public static String flagToString(int flag) {
+        switch (flag) {
+            case DEFAULT:
+                return "DEFAULT";
+            default:
+                return null;
+        }
     }
 
     /**
@@ -130,11 +465,7 @@
             new Parcelable.Creator<AccessibilityServiceInfo>() {
         public AccessibilityServiceInfo createFromParcel(Parcel parcel) {
             AccessibilityServiceInfo info = new AccessibilityServiceInfo();
-            info.eventTypes = parcel.readInt();
-            info.packageNames = parcel.readStringArray();
-            info.feedbackType = parcel.readInt();
-            info.notificationTimeout = parcel.readLong();
-            info.flags = parcel.readInt();
+            info.initFromParcel(parcel);
             return info;
         }
 
diff --git a/core/java/android/accessibilityservice/IAccessibilityServiceConnection.aidl b/core/java/android/accessibilityservice/IAccessibilityServiceConnection.aidl
index 7157def..8b4e7aee 100644
--- a/core/java/android/accessibilityservice/IAccessibilityServiceConnection.aidl
+++ b/core/java/android/accessibilityservice/IAccessibilityServiceConnection.aidl
@@ -17,14 +17,97 @@
 package android.accessibilityservice;
 
 import android.accessibilityservice.AccessibilityServiceInfo;
+import android.view.accessibility.AccessibilityNodeInfo;
 
 /**
- * Interface AccessibilityManagerService#Service implements, and passes to an
- * AccessibilityService so it can dynamically configure how the system handles it.
+ * Interface given to an AccessibilitySerivce to talk to the AccessibilityManagerService.
  *
  * @hide
  */
-oneway interface IAccessibilityServiceConnection {
+interface IAccessibilityServiceConnection {
 
     void setServiceInfo(in AccessibilityServiceInfo info);
+
+    /**
+     * Finds an {@link AccessibilityNodeInfo} by accessibility id.
+     * <p>
+     *   <strong>
+     *     It is a client responsibility to recycle the received info by
+     *     calling {@link AccessibilityNodeInfo#recycle()} to avoid creating
+     *     of multiple instances.
+     *   </strong>
+     * </p>
+     *
+     * @param accessibilityWindowId A unique window id.
+     * @param accessibilityViewId A unique View accessibility id.
+     * @return The node info.
+     */
+    AccessibilityNodeInfo findAccessibilityNodeInfoByAccessibilityId(int accessibilityWindowId,
+        int accessibilityViewId);
+
+    /**
+     * Finds {@link AccessibilityNodeInfo}s by View text. The match is case
+     * insensitive containment. The search is performed in the window whose
+     * id is specified and starts from the View whose accessibility id is
+     * specified.
+     * <p>
+     *   <strong>
+     *     It is a client responsibility to recycle the received infos by
+     *     calling {@link AccessibilityNodeInfo#recycle()} to avoid creating
+     *     of multiple instances.
+     *   </strong>
+     * </p>
+     *
+     * @param text The searched text.
+     * @param accessibilityId The id of the view from which to start searching.
+     *        Use {@link android.view.View#NO_ID} to start from the root.
+     * @return A list of node info.
+     */
+    List<AccessibilityNodeInfo> findAccessibilityNodeInfosByViewText(String text,
+        int accessibilityWindowId, int accessibilityViewId);
+
+    /**
+     * Finds {@link AccessibilityNodeInfo}s by View text. The match is case
+     * insensitive containment. The search is performed in the currently
+     * active window and start from the root View in the window.
+     * <p>
+     *   <strong>
+     *     It is a client responsibility to recycle the received infos by
+     *     calling {@link AccessibilityNodeInfo#recycle()} to avoid creating
+     *     of multiple instances.
+     *   </strong>
+     * </p>
+     *
+     * @param text The searched text.
+     * @param accessibilityId The id of the view from which to start searching.
+     *        Use {@link android.view.View#NO_ID} to start from the root.
+     * @return A list of node info.
+     */
+    List<AccessibilityNodeInfo> findAccessibilityNodeInfosByViewTextInActiveWindow(String text);
+
+    /**
+     * Finds an {@link AccessibilityNodeInfo} by View id. The search is performed
+     * in the currently active window and start from the root View in the window.
+     * <p>
+     *   <strong>
+     *     It is a client responsibility to recycle the received info by
+     *     calling {@link AccessibilityNodeInfo#recycle()} to avoid creating
+     *     of multiple instances.
+     *   </strong>
+     * </p>
+     *
+     * @param id The id of the node.
+     * @return The node info.
+     */
+    AccessibilityNodeInfo findAccessibilityNodeInfoByViewIdInActiveWindow(int viewId);
+
+    /**
+     * Performs an accessibility action on an {@link AccessibilityNodeInfo}.
+     *
+     * @param accessibilityWindowId The id of the window.
+     * @param accessibilityViewId The of a view in the .
+     * @return Whether the action was performed.
+     */
+    boolean performAccessibilityAction(int accessibilityWindowId, int accessibilityViewId,
+        int action);
 }
diff --git a/core/java/android/animation/FloatEvaluator.java b/core/java/android/animation/FloatEvaluator.java
index 9e2054d..9463aa1 100644
--- a/core/java/android/animation/FloatEvaluator.java
+++ b/core/java/android/animation/FloatEvaluator.java
@@ -19,7 +19,7 @@
 /**
  * This evaluator can be used to perform type interpolation between <code>float</code> values.
  */
-public class FloatEvaluator implements TypeEvaluator {
+public class FloatEvaluator implements TypeEvaluator<Number> {
 
     /**
      * This function returns the result of linearly interpolating the start and end values, with
@@ -35,8 +35,8 @@
      * @return A linear interpolation between the start and end values, given the
      *         <code>fraction</code> parameter.
      */
-    public Object evaluate(float fraction, Object startValue, Object endValue) {
-        float startFloat = ((Number) startValue).floatValue();
-        return startFloat + fraction * (((Number) endValue).floatValue() - startFloat);
+    public Float evaluate(float fraction, Number startValue, Number endValue) {
+        float startFloat = startValue.floatValue();
+        return startFloat + fraction * (endValue.floatValue() - startFloat);
     }
 }
\ No newline at end of file
diff --git a/core/java/android/animation/IntEvaluator.java b/core/java/android/animation/IntEvaluator.java
index 7288927..34fb0dc 100644
--- a/core/java/android/animation/IntEvaluator.java
+++ b/core/java/android/animation/IntEvaluator.java
@@ -19,7 +19,7 @@
 /**
  * This evaluator can be used to perform type interpolation between <code>int</code> values.
  */
-public class IntEvaluator implements TypeEvaluator {
+public class IntEvaluator implements TypeEvaluator<Integer> {
 
     /**
      * This function returns the result of linearly interpolating the start and end values, with
@@ -35,8 +35,8 @@
      * @return A linear interpolation between the start and end values, given the
      *         <code>fraction</code> parameter.
      */
-    public Object evaluate(float fraction, Object startValue, Object endValue) {
-        int startInt = ((Number) startValue).intValue();
-        return (int) (startInt + fraction * (((Number) endValue).intValue() - startInt));
+    public Integer evaluate(float fraction, Integer startValue, Integer endValue) {
+        int startInt = startValue;
+        return (int)(startInt + fraction * (endValue - startInt));
     }
 }
\ No newline at end of file
diff --git a/core/java/android/animation/ObjectAnimator.java b/core/java/android/animation/ObjectAnimator.java
index b8a7cb2..31c5f8d 100644
--- a/core/java/android/animation/ObjectAnimator.java
+++ b/core/java/android/animation/ObjectAnimator.java
@@ -17,6 +17,7 @@
 package android.animation;
 
 import android.util.Log;
+import android.util.Property;
 
 import java.lang.reflect.Method;
 import java.util.ArrayList;
@@ -39,6 +40,8 @@
 
     private String mPropertyName;
 
+    private Property mProperty;
+
     /**
      * Sets the name of the property that will be animated. This name is used to derive
      * a setter function that will be called to set animated values.
@@ -63,7 +66,7 @@
      * using more than one PropertyValuesHolder objects, then setting the propertyName simply
      * sets the propertyName in the first of those PropertyValuesHolder objects.</p>
      *
-     * @param propertyName The name of the property being animated.
+     * @param propertyName The name of the property being animated. Should not be null.
      */
     public void setPropertyName(String propertyName) {
         // mValues could be null if this is being constructed piecemeal. Just record the
@@ -81,6 +84,31 @@
     }
 
     /**
+     * Sets the property that will be animated. Property objects will take precedence over
+     * properties specified by the {@link #setPropertyName(String)} method. Animations should
+     * be set up to use one or the other, not both.
+     *
+     * @param property The property being animated. Should not be null.
+     */
+    public void setProperty(Property property) {
+        // mValues could be null if this is being constructed piecemeal. Just record the
+        // propertyName to be used later when setValues() is called if so.
+        if (mValues != null) {
+            PropertyValuesHolder valuesHolder = mValues[0];
+            String oldName = valuesHolder.getPropertyName();
+            valuesHolder.setProperty(property);
+            mValuesMap.remove(oldName);
+            mValuesMap.put(mPropertyName, valuesHolder);
+        }
+        if (mProperty != null) {
+            mPropertyName = property.getName();
+        }
+        mProperty = property;
+        // New property/values/target should cause re-initialization prior to starting
+        mInitialized = false;
+    }
+
+    /**
      * Gets the name of the property that will be animated. This name will be used to derive
      * a setter function that will be called to set animated values.
      * For example, a property name of <code>foo</code> will result
@@ -93,36 +121,6 @@
     }
 
     /**
-     * Determine the setter or getter function using the JavaBeans convention of setFoo or
-     * getFoo for a property named 'foo'. This function figures out what the name of the
-     * function should be and uses reflection to find the Method with that name on the
-     * target object.
-     *
-     * @param prefix "set" or "get", depending on whether we need a setter or getter.
-     * @return Method the method associated with mPropertyName.
-     */
-    private Method getPropertyFunction(String prefix, Class valueType) {
-        // TODO: faster implementation...
-        Method returnVal = null;
-        String firstLetter = mPropertyName.substring(0, 1);
-        String theRest = mPropertyName.substring(1);
-        firstLetter = firstLetter.toUpperCase();
-        String setterName = prefix + firstLetter + theRest;
-        Class args[] = null;
-        if (valueType != null) {
-            args = new Class[1];
-            args[0] = valueType;
-        }
-        try {
-            returnVal = mTarget.getClass().getMethod(setterName, args);
-        } catch (NoSuchMethodException e) {
-            Log.e("ObjectAnimator",
-                    "Couldn't find setter/getter for property " + mPropertyName + ": " + e);
-        }
-        return returnVal;
-    }
-
-    /**
      * Creates a new ObjectAnimator object. This default constructor is primarily for
      * use internally; the other constructors which take parameters are more generally
      * useful.
@@ -131,8 +129,8 @@
     }
 
     /**
-     * A constructor that takes a single property name and set of values. This constructor is
-     * used in the simple case of animating a single property.
+     * Private utility constructor that initializes the target object and name of the
+     * property being animated.
      *
      * @param target The object whose property is to be animated. This object should
      * have a public method on it called <code>setName()</code>, where <code>name</code> is
@@ -145,19 +143,29 @@
     }
 
     /**
+     * Private utility constructor that initializes the target object and property being animated.
+     *
+     * @param target The object whose property is to be animated.
+     * @param property The property being animated.
+     */
+    private <T> ObjectAnimator(T target, Property<T, ?> property) {
+        mTarget = target;
+        setProperty(property);
+    }
+
+    /**
      * Constructs and returns an ObjectAnimator that animates between int values. A single
-     * value implies that that value is the one being animated to. However, this is not typically
-     * useful in a ValueAnimator object because there is no way for the object to determine the
-     * starting value for the animation (unlike ObjectAnimator, which can derive that value
-     * from the target object and property being animated). Therefore, there should typically
-     * be two or more values.
+     * value implies that that value is the one being animated to. Two values imply a starting
+     * and ending values. More than two values imply a starting value, values to animate through
+     * along the way, and an ending value (these values will be distributed evenly across
+     * the duration of the animation).
      *
      * @param target The object whose property is to be animated. This object should
      * have a public method on it called <code>setName()</code>, where <code>name</code> is
      * the value of the <code>propertyName</code> parameter.
      * @param propertyName The name of the property being animated.
      * @param values A set of values that the animation will animate between over time.
-     * @return A ValueAnimator object that is set up to animate between the given values.
+     * @return An ObjectAnimator object that is set up to animate between the given values.
      */
     public static ObjectAnimator ofInt(Object target, String propertyName, int... values) {
         ObjectAnimator anim = new ObjectAnimator(target, propertyName);
@@ -166,19 +174,36 @@
     }
 
     /**
+     * Constructs and returns an ObjectAnimator that animates between int values. A single
+     * value implies that that value is the one being animated to. Two values imply a starting
+     * and ending values. More than two values imply a starting value, values to animate through
+     * along the way, and an ending value (these values will be distributed evenly across
+     * the duration of the animation).
+     *
+     * @param target The object whose property is to be animated.
+     * @param property The property being animated.
+     * @param values A set of values that the animation will animate between over time.
+     * @return An ObjectAnimator object that is set up to animate between the given values.
+     */
+    public static <T> ObjectAnimator ofInt(T target, Property<T, Integer> property, int... values) {
+        ObjectAnimator anim = new ObjectAnimator(target, property);
+        anim.setIntValues(values);
+        return anim;
+    }
+
+    /**
      * Constructs and returns an ObjectAnimator that animates between float values. A single
-     * value implies that that value is the one being animated to. However, this is not typically
-     * useful in a ValueAnimator object because there is no way for the object to determine the
-     * starting value for the animation (unlike ObjectAnimator, which can derive that value
-     * from the target object and property being animated). Therefore, there should typically
-     * be two or more values.
+     * value implies that that value is the one being animated to. Two values imply a starting
+     * and ending values. More than two values imply a starting value, values to animate through
+     * along the way, and an ending value (these values will be distributed evenly across
+     * the duration of the animation).
      *
      * @param target The object whose property is to be animated. This object should
      * have a public method on it called <code>setName()</code>, where <code>name</code> is
      * the value of the <code>propertyName</code> parameter.
      * @param propertyName The name of the property being animated.
      * @param values A set of values that the animation will animate between over time.
-     * @return A ValueAnimator object that is set up to animate between the given values.
+     * @return An ObjectAnimator object that is set up to animate between the given values.
      */
     public static ObjectAnimator ofFloat(Object target, String propertyName, float... values) {
         ObjectAnimator anim = new ObjectAnimator(target, propertyName);
@@ -187,21 +212,40 @@
     }
 
     /**
-     * A constructor that takes <code>PropertyValueHolder</code> values. This constructor should
-     * be used when animating several properties at once with the same ObjectAnimator, since
-     * PropertyValuesHolder allows you to associate a set of animation values with a property
-     * name.
+     * Constructs and returns an ObjectAnimator that animates between float values. A single
+     * value implies that that value is the one being animated to. Two values imply a starting
+     * and ending values. More than two values imply a starting value, values to animate through
+     * along the way, and an ending value (these values will be distributed evenly across
+     * the duration of the animation).
+     *
+     * @param target The object whose property is to be animated.
+     * @param property The property being animated.
+     * @param values A set of values that the animation will animate between over time.
+     * @return An ObjectAnimator object that is set up to animate between the given values.
+     */
+    public static <T> ObjectAnimator ofFloat(T target, Property<T, Float> property,
+            float... values) {
+        ObjectAnimator anim = new ObjectAnimator(target, property);
+        anim.setFloatValues(values);
+        return anim;
+    }
+
+    /**
+     * Constructs and returns an ObjectAnimator that animates between Object values. A single
+     * value implies that that value is the one being animated to. Two values imply a starting
+     * and ending values. More than two values imply a starting value, values to animate through
+     * along the way, and an ending value (these values will be distributed evenly across
+     * the duration of the animation).
      *
      * @param target The object whose property is to be animated. This object should
-     * have public methods on it called <code>setName()</code>, where <code>name</code> is
-     * the name of the property passed in as the <code>propertyName</code> parameter for
-     * each of the PropertyValuesHolder objects.
+     * have a public method on it called <code>setName()</code>, where <code>name</code> is
+     * the value of the <code>propertyName</code> parameter.
      * @param propertyName The name of the property being animated.
      * @param evaluator A TypeEvaluator that will be called on each animation frame to
-     * provide the ncessry interpolation between the Object values to derive the animated
+     * provide the necessary interpolation between the Object values to derive the animated
      * value.
-     * @param values The PropertyValuesHolder objects which hold each the property name and values
-     * to animate that property between.
+     * @param values A set of values that the animation will animate between over time.
+     * @return An ObjectAnimator object that is set up to animate between the given values.
      */
     public static ObjectAnimator ofObject(Object target, String propertyName,
             TypeEvaluator evaluator, Object... values) {
@@ -212,19 +256,44 @@
     }
 
     /**
-     * Constructs and returns an ObjectAnimator that animates between the sets of values
-     * specifed in <code>PropertyValueHolder</code> objects. This variant should
-     * be used when animating several properties at once with the same ObjectAnimator, since
-     * PropertyValuesHolder allows you to associate a set of animation values with a property
-     * name.
+     * Constructs and returns an ObjectAnimator that animates between Object values. A single
+     * value implies that that value is the one being animated to. Two values imply a starting
+     * and ending values. More than two values imply a starting value, values to animate through
+     * along the way, and an ending value (these values will be distributed evenly across
+     * the duration of the animation).
      *
-     * @param target The object whose property is to be animated. This object should
-     * have public methods on it called <code>setName()</code>, where <code>name</code> is
-     * the name of the property passed in as the <code>propertyName</code> parameter for
-     * each of the PropertyValuesHolder objects.
-     * @param values A set of PropertyValuesHolder objects whose values will be animated
-     * between over time.
-     * @return A ValueAnimator object that is set up to animate between the given values.
+     * @param target The object whose property is to be animated.
+     * @param property The property being animated.
+     * @param evaluator A TypeEvaluator that will be called on each animation frame to
+     * provide the necessary interpolation between the Object values to derive the animated
+     * value.
+     * @param values A set of values that the animation will animate between over time.
+     * @return An ObjectAnimator object that is set up to animate between the given values.
+     */
+    public static <T, V> ObjectAnimator ofObject(T target, Property<T, V> property,
+            TypeEvaluator<V> evaluator, V... values) {
+        ObjectAnimator anim = new ObjectAnimator(target, property);
+        anim.setObjectValues(values);
+        anim.setEvaluator(evaluator);
+        return anim;
+    }
+
+    /**
+     * Constructs and returns an ObjectAnimator that animates between the sets of values specified
+     * in <code>PropertyValueHolder</code> objects. This variant should be used when animating
+     * several properties at once with the same ObjectAnimator, since PropertyValuesHolder allows
+     * you to associate a set of animation values with a property name.
+     *
+     * @param target The object whose property is to be animated. Depending on how the
+     * PropertyValuesObjects were constructed, the target object should either have the {@link
+     * android.util.Property} objects used to construct the PropertyValuesHolder objects or (if the
+     * PropertyValuesHOlder objects were created with property names) the target object should have
+     * public methods on it called <code>setName()</code>, where <code>name</code> is the name of
+     * the property passed in as the <code>propertyName</code> parameter for each of the
+     * PropertyValuesHolder objects.
+     * @param values A set of PropertyValuesHolder objects whose values will be animated between
+     * over time.
+     * @return An ObjectAnimator object that is set up to animate between the given values.
      */
     public static ObjectAnimator ofPropertyValuesHolder(Object target,
             PropertyValuesHolder... values) {
@@ -239,7 +308,11 @@
         if (mValues == null || mValues.length == 0) {
             // No values yet - this animator is being constructed piecemeal. Init the values with
             // whatever the current propertyName is
-            setValues(PropertyValuesHolder.ofInt(mPropertyName, values));
+            if (mProperty != null) {
+                setValues(PropertyValuesHolder.ofInt(mProperty, values));
+            } else {
+                setValues(PropertyValuesHolder.ofInt(mPropertyName, values));
+            }
         } else {
             super.setIntValues(values);
         }
@@ -250,7 +323,11 @@
         if (mValues == null || mValues.length == 0) {
             // No values yet - this animator is being constructed piecemeal. Init the values with
             // whatever the current propertyName is
-            setValues(PropertyValuesHolder.ofFloat(mPropertyName, values));
+            if (mProperty != null) {
+                setValues(PropertyValuesHolder.ofFloat(mProperty, values));
+            } else {
+                setValues(PropertyValuesHolder.ofFloat(mPropertyName, values));
+            }
         } else {
             super.setFloatValues(values);
         }
@@ -261,7 +338,11 @@
         if (mValues == null || mValues.length == 0) {
             // No values yet - this animator is being constructed piecemeal. Init the values with
             // whatever the current propertyName is
-            setValues(PropertyValuesHolder.ofObject(mPropertyName, (TypeEvaluator)null, values));
+            if (mProperty != null) {
+                setValues(PropertyValuesHolder.ofObject(mProperty, (TypeEvaluator)null, values));
+            } else {
+                setValues(PropertyValuesHolder.ofObject(mPropertyName, (TypeEvaluator)null, values));
+            }
         } else {
             super.setObjectValues(values);
         }
diff --git a/core/java/android/animation/PropertyValuesHolder.java b/core/java/android/animation/PropertyValuesHolder.java
index 6f91fc0..58f23f7 100644
--- a/core/java/android/animation/PropertyValuesHolder.java
+++ b/core/java/android/animation/PropertyValuesHolder.java
@@ -16,7 +16,10 @@
 
 package android.animation;
 
+import android.util.FloatProperty;
+import android.util.IntProperty;
 import android.util.Log;
+import android.util.Property;
 
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
@@ -39,6 +42,11 @@
     String mPropertyName;
 
     /**
+     * @hide
+     */
+    protected Property mProperty;
+
+    /**
      * The setter function, if needed. ObjectAnimator hands off this functionality to
      * PropertyValuesHolder, since it holds all of the per-property information. This
      * property is automatically
@@ -124,6 +132,17 @@
     }
 
     /**
+     * Internal utility constructor, used by the factory methods to set the property.
+     * @param property The property for this holder.
+     */
+    private PropertyValuesHolder(Property property) {
+        mProperty = property;
+        if (property != null) {
+            mPropertyName = property.getName();
+        }
+    }
+
+    /**
      * Constructs and returns a PropertyValuesHolder with a given property name and
      * set of int values.
      * @param propertyName The name of the property being animated.
@@ -131,8 +150,18 @@
      * @return PropertyValuesHolder The constructed PropertyValuesHolder object.
      */
     public static PropertyValuesHolder ofInt(String propertyName, int... values) {
-        PropertyValuesHolder pvh = new IntPropertyValuesHolder(propertyName, values);
-        return pvh;
+        return new IntPropertyValuesHolder(propertyName, values);
+    }
+
+    /**
+     * Constructs and returns a PropertyValuesHolder with a given property and
+     * set of int values.
+     * @param property The property being animated. Should not be null.
+     * @param values The values that the property will animate between.
+     * @return PropertyValuesHolder The constructed PropertyValuesHolder object.
+     */
+    public static PropertyValuesHolder ofInt(Property<?, Integer> property, int... values) {
+        return new IntPropertyValuesHolder(property, values);
     }
 
     /**
@@ -143,18 +172,28 @@
      * @return PropertyValuesHolder The constructed PropertyValuesHolder object.
      */
     public static PropertyValuesHolder ofFloat(String propertyName, float... values) {
-        PropertyValuesHolder pvh = new FloatPropertyValuesHolder(propertyName, values);
-        return pvh;
+        return new FloatPropertyValuesHolder(propertyName, values);
+    }
+
+    /**
+     * Constructs and returns a PropertyValuesHolder with a given property and
+     * set of float values.
+     * @param property The property being animated. Should not be null.
+     * @param values The values that the property will animate between.
+     * @return PropertyValuesHolder The constructed PropertyValuesHolder object.
+     */
+    public static PropertyValuesHolder ofFloat(Property<?, Float> property, float... values) {
+        return new FloatPropertyValuesHolder(property, values);
     }
 
     /**
      * Constructs and returns a PropertyValuesHolder with a given property name and
      * set of Object values. This variant also takes a TypeEvaluator because the system
-     * cannot interpolate between objects of unknown type.
+     * cannot automatically interpolate between objects of unknown type.
      *
      * @param propertyName The name of the property being animated.
      * @param evaluator A TypeEvaluator that will be called on each animation frame to
-     * provide the ncessry interpolation between the Object values to derive the animated
+     * provide the necessary interpolation between the Object values to derive the animated
      * value.
      * @param values The values that the named property will animate between.
      * @return PropertyValuesHolder The constructed PropertyValuesHolder object.
@@ -168,6 +207,26 @@
     }
 
     /**
+     * Constructs and returns a PropertyValuesHolder with a given property and
+     * set of Object values. This variant also takes a TypeEvaluator because the system
+     * cannot automatically interpolate between objects of unknown type.
+     *
+     * @param property The property being animated. Should not be null.
+     * @param evaluator A TypeEvaluator that will be called on each animation frame to
+     * provide the necessary interpolation between the Object values to derive the animated
+     * value.
+     * @param values The values that the property will animate between.
+     * @return PropertyValuesHolder The constructed PropertyValuesHolder object.
+     */
+    public static <V> PropertyValuesHolder ofObject(Property property,
+            TypeEvaluator<V> evaluator, V... values) {
+        PropertyValuesHolder pvh = new PropertyValuesHolder(property);
+        pvh.setObjectValues(values);
+        pvh.setEvaluator(evaluator);
+        return pvh;
+    }
+
+    /**
      * Constructs and returns a PropertyValuesHolder object with the specified property name and set
      * of values. These values can be of any type, but the type should be consistent so that
      * an appropriate {@link android.animation.TypeEvaluator} can be found that matches
@@ -202,6 +261,37 @@
     }
 
     /**
+     * Constructs and returns a PropertyValuesHolder object with the specified property and set
+     * of values. These values can be of any type, but the type should be consistent so that
+     * an appropriate {@link android.animation.TypeEvaluator} can be found that matches
+     * the common type.
+     * <p>If there is only one value, it is assumed to be the end value of an animation,
+     * and an initial value will be derived, if possible, by calling the property's
+     * {@link android.util.Property#get(Object)} function.
+     * Also, if any value is null, the value will be filled in when the animation
+     * starts in the same way. This mechanism of automatically getting null values only works
+     * if the PropertyValuesHolder object is used in conjunction with
+     * {@link ObjectAnimator}, since otherwise PropertyValuesHolder has
+     * no way of determining what the value should be.
+     * @param property The property associated with this set of values. Should not be null.
+     * @param values The set of values to animate between.
+     */
+    public static PropertyValuesHolder ofKeyframe(Property property, Keyframe... values) {
+        KeyframeSet keyframeSet = KeyframeSet.ofKeyframe(values);
+        if (keyframeSet instanceof IntKeyframeSet) {
+            return new IntPropertyValuesHolder(property, (IntKeyframeSet) keyframeSet);
+        } else if (keyframeSet instanceof FloatKeyframeSet) {
+            return new FloatPropertyValuesHolder(property, (FloatKeyframeSet) keyframeSet);
+        }
+        else {
+            PropertyValuesHolder pvh = new PropertyValuesHolder(property);
+            pvh.mKeyframeSet = keyframeSet;
+            pvh.mValueType = ((Keyframe)values[0]).getType();
+            return pvh;
+        }
+    }
+
+    /**
      * Set the animated values for this object to this set of ints.
      * If there is only one value, it is assumed to be the end value of an animation,
      * and an initial value will be derived, if possible, by calling a getter function
@@ -349,7 +439,6 @@
             // Have to lock property map prior to reading it, to guard against
             // another thread putting something in there after we've checked it
             // but before we've added an entry to it
-            // TODO: can we store the setter/getter per Class instead of per Object?
             mPropertyMapLock.writeLock().lock();
             HashMap<String, Method> propertyMap = propertyMapMap.get(targetClass);
             if (propertyMap != null) {
@@ -395,6 +484,22 @@
      * @param target The object on which the setter (and possibly getter) exist.
      */
     void setupSetterAndGetter(Object target) {
+        if (mProperty != null) {
+            // check to make sure that mProperty is on the class of target
+            try {
+                Object testValue = mProperty.get(target);
+                for (Keyframe kf : mKeyframeSet.mKeyframes) {
+                    if (!kf.hasValue()) {
+                        kf.setValue(mProperty.get(target));
+                    }
+                }
+                return;
+            } catch (ClassCastException e) {
+                Log.e("PropertyValuesHolder","No such property (" + mProperty.getName() +
+                        ") on target object " + target + ". Trying reflection instead");
+                mProperty = null;
+            }
+        }
         Class targetClass = target.getClass();
         if (mSetter == null) {
             setupSetter(targetClass);
@@ -423,6 +528,9 @@
      * @param kf The keyframe which holds the property name and value.
      */
     private void setupValue(Object target, Keyframe kf) {
+        if (mProperty != null) {
+            kf.setValue(mProperty.get(target));
+        }
         try {
             if (mGetter == null) {
                 Class targetClass = target.getClass();
@@ -465,6 +573,7 @@
         try {
             PropertyValuesHolder newPVH = (PropertyValuesHolder) super.clone();
             newPVH.mPropertyName = mPropertyName;
+            newPVH.mProperty = mProperty;
             newPVH.mKeyframeSet = mKeyframeSet.clone();
             newPVH.mEvaluator = mEvaluator;
             return newPVH;
@@ -482,6 +591,9 @@
      * @param target The target object on which the value is set
      */
     void setAnimatedValue(Object target) {
+        if (mProperty != null) {
+            mProperty.set(target, getAnimatedValue());
+        }
         if (mSetter != null) {
             try {
                 mTmpValueArray[0] = getAnimatedValue();
@@ -558,6 +670,18 @@
     }
 
     /**
+     * Sets the property that will be animated.
+     *
+     * <p>Note that if this PropertyValuesHolder object is used with ObjectAnimator, the property
+     * must exist on the target object specified in that ObjectAnimator.</p>
+     *
+     * @param property The property being animated.
+     */
+    public void setProperty(Property property) {
+        mProperty = property;
+    }
+
+    /**
      * Gets the name of the property that will be animated. This name will be used to derive
      * a setter function that will be called to set animated values.
      * For example, a property name of <code>foo</code> will result
@@ -597,17 +721,22 @@
      * specified above.
      */
     static String getMethodName(String prefix, String propertyName) {
-        char firstLetter = propertyName.charAt(0);
+        if (propertyName == null || propertyName.length() == 0) {
+            // shouldn't get here
+            return prefix;
+        }
+        char firstLetter = Character.toUpperCase(propertyName.charAt(0));
         String theRest = propertyName.substring(1);
-        firstLetter = Character.toUpperCase(firstLetter);
         return prefix + firstLetter + theRest;
     }
 
     static class IntPropertyValuesHolder extends PropertyValuesHolder {
 
+        // Cache JNI functions to avoid looking them up twice
         private static final HashMap<Class, HashMap<String, Integer>> sJNISetterPropertyMap =
                 new HashMap<Class, HashMap<String, Integer>>();
         int mJniSetter;
+        private IntProperty mIntProperty;
 
         IntKeyframeSet mIntKeyframeSet;
         int mIntAnimatedValue;
@@ -619,11 +748,29 @@
             mIntKeyframeSet = (IntKeyframeSet) mKeyframeSet;
         }
 
+        public IntPropertyValuesHolder(Property property, IntKeyframeSet keyframeSet) {
+            super(property);
+            mValueType = int.class;
+            mKeyframeSet = keyframeSet;
+            mIntKeyframeSet = (IntKeyframeSet) mKeyframeSet;
+            if (property instanceof  IntProperty) {
+                mIntProperty = (IntProperty) mProperty;
+            }
+        }
+
         public IntPropertyValuesHolder(String propertyName, int... values) {
             super(propertyName);
             setIntValues(values);
         }
 
+        public IntPropertyValuesHolder(Property property, int... values) {
+            super(property);
+            setIntValues(values);
+            if (property instanceof  IntProperty) {
+                mIntProperty = (IntProperty) mProperty;
+            }
+        }
+
         @Override
         public void setIntValues(int... values) {
             super.setIntValues(values);
@@ -656,6 +803,14 @@
          */
         @Override
         void setAnimatedValue(Object target) {
+            if (mIntProperty != null) {
+                mIntProperty.setValue(target, mIntAnimatedValue);
+                return;
+            }
+            if (mProperty != null) {
+                mProperty.set(target, mIntAnimatedValue);
+                return;
+            }
             if (mJniSetter != 0) {
                 nCallIntMethod(target, mJniSetter, mIntAnimatedValue);
                 return;
@@ -674,6 +829,9 @@
 
         @Override
         void setupSetter(Class targetClass) {
+            if (mProperty != null) {
+                return;
+            }
             // Check new static hashmap<propName, int> for setter method
             try {
                 mPropertyMapLock.writeLock().lock();
@@ -696,7 +854,8 @@
                     }
                 }
             } catch (NoSuchMethodError e) {
-                // System.out.println("Can't find native method using JNI, use reflection" + e);
+                Log.d("PropertyValuesHolder",
+                        "Can't find native method using JNI, use reflection" + e);
             } finally {
                 mPropertyMapLock.writeLock().unlock();
             }
@@ -709,9 +868,11 @@
 
     static class FloatPropertyValuesHolder extends PropertyValuesHolder {
 
+        // Cache JNI functions to avoid looking them up twice
         private static final HashMap<Class, HashMap<String, Integer>> sJNISetterPropertyMap =
                 new HashMap<Class, HashMap<String, Integer>>();
         int mJniSetter;
+        private FloatProperty mFloatProperty;
 
         FloatKeyframeSet mFloatKeyframeSet;
         float mFloatAnimatedValue;
@@ -723,11 +884,29 @@
             mFloatKeyframeSet = (FloatKeyframeSet) mKeyframeSet;
         }
 
+        public FloatPropertyValuesHolder(Property property, FloatKeyframeSet keyframeSet) {
+            super(property);
+            mValueType = float.class;
+            mKeyframeSet = keyframeSet;
+            mFloatKeyframeSet = (FloatKeyframeSet) mKeyframeSet;
+            if (property instanceof FloatProperty) {
+                mFloatProperty = (FloatProperty) mProperty;
+            }
+        }
+
         public FloatPropertyValuesHolder(String propertyName, float... values) {
             super(propertyName);
             setFloatValues(values);
         }
 
+        public FloatPropertyValuesHolder(Property property, float... values) {
+            super(property);
+            setFloatValues(values);
+            if (property instanceof  FloatProperty) {
+                mFloatProperty = (FloatProperty) mProperty;
+            }
+        }
+
         @Override
         public void setFloatValues(float... values) {
             super.setFloatValues(values);
@@ -760,6 +939,14 @@
          */
         @Override
         void setAnimatedValue(Object target) {
+            if (mFloatProperty != null) {
+                mFloatProperty.setValue(target, mFloatAnimatedValue);
+                return;
+            }
+            if (mProperty != null) {
+                mProperty.set(target, mFloatAnimatedValue);
+                return;
+            }
             if (mJniSetter != 0) {
                 nCallFloatMethod(target, mJniSetter, mFloatAnimatedValue);
                 return;
@@ -778,6 +965,9 @@
 
         @Override
         void setupSetter(Class targetClass) {
+            if (mProperty != null) {
+                return;
+            }
             // Check new static hashmap<propName, int> for setter method
             try {
                 mPropertyMapLock.writeLock().lock();
@@ -800,7 +990,8 @@
                     }
                 }
             } catch (NoSuchMethodError e) {
-                // System.out.println("Can't find native method using JNI, use reflection" + e);
+                Log.d("PropertyValuesHolder",
+                        "Can't find native method using JNI, use reflection" + e);
             } finally {
                 mPropertyMapLock.writeLock().unlock();
             }
diff --git a/core/java/android/animation/TypeEvaluator.java b/core/java/android/animation/TypeEvaluator.java
index fa49175..e738da1 100644
--- a/core/java/android/animation/TypeEvaluator.java
+++ b/core/java/android/animation/TypeEvaluator.java
@@ -24,7 +24,7 @@
  *
  * @see ValueAnimator#setEvaluator(TypeEvaluator)
  */
-public interface TypeEvaluator {
+public interface TypeEvaluator<T> {
 
     /**
      * This function returns the result of linearly interpolating the start and end values, with
@@ -39,6 +39,6 @@
      * @return A linear interpolation between the start and end values, given the
      *         <code>fraction</code> parameter.
      */
-    public Object evaluate(float fraction, Object startValue, Object endValue);
+    public T evaluate(float fraction, T startValue, T endValue);
 
 }
\ No newline at end of file
diff --git a/core/java/android/app/ActionBar.java b/core/java/android/app/ActionBar.java
index cac06ec..3ec5edb 100644
--- a/core/java/android/app/ActionBar.java
+++ b/core/java/android/app/ActionBar.java
@@ -487,6 +487,12 @@
      * Create and return a new {@link Tab}.
      * This tab will not be included in the action bar until it is added.
      *
+     * <p>Very often tabs will be used to switch between {@link Fragment}
+     * objects.  Here is a typical implementation of such tabs:</p>
+     *
+     * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentTabs.java
+     *      complete}
+     *
      * @return A new Tab
      *
      * @see #addTab(Tab)
diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java
index 3877bd0..aeb16f4 100644
--- a/core/java/android/app/Activity.java
+++ b/core/java/android/app/Activity.java
@@ -723,6 +723,8 @@
     
     protected static final int[] FOCUSED_STATE_SET = {com.android.internal.R.attr.state_focused};
 
+    private final Object mInstanceTracker = StrictMode.trackActivity(this);
+
     private Thread mUiThread;
     final Handler mHandler = new Handler();
 
@@ -4417,7 +4419,9 @@
         mFragments.dispatchStart();
         if (mAllLoaderManagers != null) {
             for (int i=mAllLoaderManagers.size()-1; i>=0; i--) {
-                mAllLoaderManagers.valueAt(i).finishRetain();
+                LoaderManagerImpl lm = mAllLoaderManagers.valueAt(i);
+                lm.finishRetain();
+                lm.doReportStart();
             }
         }
     }
@@ -4425,27 +4429,29 @@
     final void performRestart() {
         mFragments.noteStateNotSaved();
 
-        synchronized (mManagedCursors) {
-            final int N = mManagedCursors.size();
-            for (int i=0; i<N; i++) {
-                ManagedCursor mc = mManagedCursors.get(i);
-                if (mc.mReleased || mc.mUpdated) {
-                    if (!mc.mCursor.requery()) {
-                        throw new IllegalStateException(
-                                "trying to requery an already closed cursor");
-                    }
-                    mc.mReleased = false;
-                    mc.mUpdated = false;
-                }
-            }
-        }
-
         if (mStopped) {
             mStopped = false;
-            mCalled = false;
             if (mToken != null && mParent == null) {
                 WindowManagerImpl.getDefault().setStoppedState(mToken, false);
             }
+
+            synchronized (mManagedCursors) {
+                final int N = mManagedCursors.size();
+                for (int i=0; i<N; i++) {
+                    ManagedCursor mc = mManagedCursors.get(i);
+                    if (mc.mReleased || mc.mUpdated) {
+                        if (!mc.mCursor.requery()) {
+                            throw new IllegalStateException(
+                                    "trying to requery an already closed cursor  "
+                                    + mc.mCursor);
+                        }
+                        mc.mReleased = false;
+                        mc.mUpdated = false;
+                    }
+                }
+            }
+
+            mCalled = false;
             mInstrumentation.callActivityOnRestart(this);
             if (!mCalled) {
                 throw new SuperNotCalledException(
@@ -4550,9 +4556,6 @@
             mStopped = true;
         }
         mResumed = false;
-
-        // Check for Activity leaks, if enabled.
-        StrictMode.conditionallyCheckInstanceCounts();
     }
 
     final void performDestroy() {
diff --git a/core/java/android/app/ActivityGroup.java b/core/java/android/app/ActivityGroup.java
index 5b04253..fbd78be 100644
--- a/core/java/android/app/ActivityGroup.java
+++ b/core/java/android/app/ActivityGroup.java
@@ -23,8 +23,13 @@
 import android.util.Log;
 
 /**
+ * @deprecated Use the new {@link Fragment} and {@link FragmentManager} APIs
+ * instead; these are also
+ * available on older platforms through the Android compatibility package.
+ *
  * A screen that contains and runs multiple embedded activities.
  */
+@Deprecated
 public class ActivityGroup extends Activity {
     private static final String TAG = "ActivityGroup";
     private static final String STATES_KEY = "android:states";
diff --git a/core/java/android/app/ActivityManager.java b/core/java/android/app/ActivityManager.java
index ef2e54a..a6658cc 100644
--- a/core/java/android/app/ActivityManager.java
+++ b/core/java/android/app/ActivityManager.java
@@ -138,6 +138,25 @@
         }
     }
 
+    /** @hide */
+    public boolean getPackageAskScreenCompat(String packageName) {
+        try {
+            return ActivityManagerNative.getDefault().getPackageAskScreenCompat(packageName);
+        } catch (RemoteException e) {
+            // System dead, we will be dead too soon!
+            return false;
+        }
+    }
+
+    /** @hide */
+    public void setPackageAskScreenCompat(String packageName, boolean ask) {
+        try {
+            ActivityManagerNative.getDefault().setPackageAskScreenCompat(packageName, ask);
+        } catch (RemoteException e) {
+            // System dead, we will be dead too soon!
+        }
+    }
+
     /**
      * Return the approximate per-application memory class of the current
      * device.  This gives you an idea of how hard a memory limit you should
diff --git a/core/java/android/app/ActivityManagerNative.java b/core/java/android/app/ActivityManagerNative.java
index 2a0d798..85f40c9 100644
--- a/core/java/android/app/ActivityManagerNative.java
+++ b/core/java/android/app/ActivityManagerNative.java
@@ -1483,6 +1483,26 @@
             return true;
         }
 
+        case GET_PACKAGE_ASK_SCREEN_COMPAT_TRANSACTION:
+        {
+            data.enforceInterface(IActivityManager.descriptor);
+            String pkg = data.readString();
+            boolean ask = getPackageAskScreenCompat(pkg);
+            reply.writeNoException();
+            reply.writeInt(ask ? 1 : 0);
+            return true;
+        }
+
+        case SET_PACKAGE_ASK_SCREEN_COMPAT_TRANSACTION:
+        {
+            data.enforceInterface(IActivityManager.descriptor);
+            String pkg = data.readString();
+            boolean ask = data.readInt() != 0;
+            setPackageAskScreenCompat(pkg, ask);
+            reply.writeNoException();
+            return true;
+        }
+
         }
 
         return super.onTransact(code, data, reply, flags);
@@ -3254,7 +3274,8 @@
         Parcel data = Parcel.obtain();
         Parcel reply = Parcel.obtain();
         data.writeInterfaceToken(IActivityManager.descriptor);
-        mRemote.transact(SET_PACKAGE_SCREEN_COMPAT_MODE_TRANSACTION, data, reply, 0);
+        data.writeString(packageName);
+        mRemote.transact(GET_PACKAGE_SCREEN_COMPAT_MODE_TRANSACTION, data, reply, 0);
         reply.readException();
         int mode = reply.readInt();
         reply.recycle();
@@ -3275,6 +3296,32 @@
         data.recycle();
     }
 
+    public boolean getPackageAskScreenCompat(String packageName) throws RemoteException {
+        Parcel data = Parcel.obtain();
+        Parcel reply = Parcel.obtain();
+        data.writeInterfaceToken(IActivityManager.descriptor);
+        data.writeString(packageName);
+        mRemote.transact(GET_PACKAGE_ASK_SCREEN_COMPAT_TRANSACTION, data, reply, 0);
+        reply.readException();
+        boolean ask = reply.readInt() != 0;
+        reply.recycle();
+        data.recycle();
+        return ask;
+    }
+
+    public void setPackageAskScreenCompat(String packageName, boolean ask)
+            throws RemoteException {
+        Parcel data = Parcel.obtain();
+        Parcel reply = Parcel.obtain();
+        data.writeInterfaceToken(IActivityManager.descriptor);
+        data.writeString(packageName);
+        data.writeInt(ask ? 1 : 0);
+        mRemote.transact(SET_PACKAGE_ASK_SCREEN_COMPAT_TRANSACTION, data, reply, 0);
+        reply.readException();
+        reply.recycle();
+        data.recycle();
+    }
+
     public boolean switchUser(int userid) throws RemoteException {
         Parcel data = Parcel.obtain();
         Parcel reply = Parcel.obtain();
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
index 85e59b3..1ec7a96 100644
--- a/core/java/android/app/ActivityThread.java
+++ b/core/java/android/app/ActivityThread.java
@@ -155,7 +155,9 @@
             = new HashMap<IBinder, Service>();
     AppBindData mBoundApplication;
     Configuration mConfiguration;
+    Configuration mCompatConfiguration;
     Configuration mResConfiguration;
+    CompatibilityInfo mResCompatibilityInfo;
     Application mInitialApplication;
     final ArrayList<Application> mAllApplications
             = new ArrayList<Application>();
@@ -172,12 +174,17 @@
     // These can be accessed by multiple threads; mPackages is the lock.
     // XXX For now we keep around information about all packages we have
     // seen, not removing entries from this map.
+    // NOTE: The activity manager in its process needs to call in to
+    // ActivityThread to do things like update resource configurations,
+    // which means this lock gets held while the activity manager holds its
+    // own lock.  Thus you MUST NEVER call back into the activity manager
+    // or anything that depends on it while holding this lock.
     final HashMap<String, WeakReference<LoadedApk>> mPackages
             = new HashMap<String, WeakReference<LoadedApk>>();
     final HashMap<String, WeakReference<LoadedApk>> mResourcePackages
             = new HashMap<String, WeakReference<LoadedApk>>();
-    Display mDisplay = null;
-    DisplayMetrics mDisplayMetrics = null;
+    final HashMap<CompatibilityInfo, DisplayMetrics> mDisplayMetrics
+            = new HashMap<CompatibilityInfo, DisplayMetrics>();
     final HashMap<ResourcesKey, WeakReference<Resources> > mActiveResources
             = new HashMap<ResourcesKey, WeakReference<Resources> >();
     final ArrayList<ActivityClientRecord> mRelaunchingActivities
@@ -1271,20 +1278,45 @@
         return sPackageManager;
     }
 
-    DisplayMetrics getDisplayMetricsLocked(boolean forceUpdate) {
-        if (mDisplayMetrics != null && !forceUpdate) {
-            return mDisplayMetrics;
+    DisplayMetrics getDisplayMetricsLocked(CompatibilityInfo ci, boolean forceUpdate) {
+        DisplayMetrics dm = mDisplayMetrics.get(ci);
+        if (dm != null && !forceUpdate) {
+            return dm;
         }
-        if (mDisplay == null) {
-            WindowManager wm = WindowManagerImpl.getDefault();
-            mDisplay = wm.getDefaultDisplay();
+        if (dm == null) {
+            dm = new DisplayMetrics();
+            mDisplayMetrics.put(ci, dm);
         }
-        DisplayMetrics metrics = mDisplayMetrics = new DisplayMetrics();
-        mDisplay.getMetrics(metrics);
+        Display d = WindowManagerImpl.getDefault(ci).getDefaultDisplay();
+        d.getMetrics(dm);
         //Slog.i("foo", "New metrics: w=" + metrics.widthPixels + " h="
         //        + metrics.heightPixels + " den=" + metrics.density
         //        + " xdpi=" + metrics.xdpi + " ydpi=" + metrics.ydpi);
-        return metrics;
+        return dm;
+    }
+
+    static Configuration applyConfigCompat(Configuration config, CompatibilityInfo compat) {
+        if (config == null) {
+            return null;
+        }
+        if (compat != null && !compat.supportsScreen()) {
+            config = new Configuration(config);
+            compat.applyToConfiguration(config);
+        }
+        return config;
+    }
+
+    private final Configuration mMainThreadConfig = new Configuration();
+    Configuration applyConfigCompatMainThread(Configuration config, CompatibilityInfo compat) {
+        if (config == null) {
+            return null;
+        }
+        if (compat != null && !compat.supportsScreen()) {
+            mMainThreadConfig.setTo(config);
+            config = mMainThreadConfig;
+            compat.applyToConfiguration(config);
+        }
+        return config;
     }
 
     /**
@@ -1326,7 +1358,7 @@
         }
 
         //Slog.i(TAG, "Resource: key=" + key + ", display metrics=" + metrics);
-        DisplayMetrics metrics = getDisplayMetricsLocked(false);
+        DisplayMetrics metrics = getDisplayMetricsLocked(compInfo, false);
         r = new Resources(assets, metrics, getConfiguration(), compInfo);
         if (false) {
             Slog.i(TAG, "Created app resources " + resDir + " " + r + ": "
@@ -1354,7 +1386,7 @@
      * Creates the top level resources for the given package.
      */
     Resources getTopLevelResources(String resDir, LoadedApk pkgInfo) {
-        return getTopLevelResources(resDir, pkgInfo.mCompatibilityInfo);
+        return getTopLevelResources(resDir, pkgInfo.mCompatibilityInfo.get());
     }
 
     final Handler getHandler() {
@@ -1489,7 +1521,7 @@
     }
 
     public Configuration getConfiguration() {
-        return mConfiguration;
+        return mResConfiguration;
     }
 
     public boolean isProfiling() {
@@ -1521,7 +1553,8 @@
                         CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO);
                 context.init(info, null, this);
                 context.getResources().updateConfiguration(
-                        getConfiguration(), getDisplayMetricsLocked(false));
+                        getConfiguration(), getDisplayMetricsLocked(
+                                CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, false));
                 mSystemContext = context;
                 //Slog.i(TAG, "Created system resources " + context.getResources()
                 //        + ": " + context.getResources().getConfiguration());
@@ -1534,7 +1567,7 @@
         synchronized (this) {
             ContextImpl context = getSystemContext();
             context.init(new LoadedApk(this, "android", context, info,
-                    new CompatibilityInfo(info, 0, false)), null, this);
+                    CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO), null, this);
         }
     }
 
@@ -1734,7 +1767,7 @@
                 appContext.init(r.packageInfo, r.token, this);
                 appContext.setOuterContext(activity);
                 CharSequence title = r.activityInfo.loadLabel(appContext.getPackageManager());
-                Configuration config = new Configuration(mConfiguration);
+                Configuration config = new Configuration(mCompatConfiguration);
                 if (DEBUG_CONFIGURATION) Slog.v(TAG, "Launching activity "
                         + r.activityInfo.name + " with config " + config);
                 activity.attach(appContext, this, getInstrumentation(), r.token,
@@ -1879,7 +1912,7 @@
             }
             deliverNewIntents(r, intents);
             if (resumed) {
-                mInstrumentation.callActivityOnResume(r.activity);
+                r.activity.performResume();
                 r.activity.mTemporaryPause = false;
             }
         }
@@ -1980,7 +2013,8 @@
         BackupAgent agent = null;
         String classname = data.appInfo.backupAgentName;
 
-        if (data.backupMode == IApplicationThread.BACKUP_MODE_FULL) {
+        if (data.backupMode == IApplicationThread.BACKUP_MODE_FULL
+                || data.backupMode == IApplicationThread.BACKUP_MODE_RESTORE_FULL) {
             classname = "android.app.backup.FullBackupAgent";
             if ((data.appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
                 // system packages can supply their own full-backup agent
@@ -2011,7 +2045,8 @@
                 // If this is during restore, fail silently; otherwise go
                 // ahead and let the user see the crash.
                 Slog.e(TAG, "Agent threw during creation: " + e);
-                if (data.backupMode != IApplicationThread.BACKUP_MODE_RESTORE) {
+                if (data.backupMode != IApplicationThread.BACKUP_MODE_RESTORE
+                        && data.backupMode != IApplicationThread.BACKUP_MODE_RESTORE_FULL) {
                     throw e;
                 }
                 // falling through with 'binder' still null
@@ -2775,13 +2810,14 @@
     private void handleUpdatePackageCompatibilityInfo(UpdateCompatibilityData data) {
         LoadedApk apk = peekPackageInfo(data.pkg, false);
         if (apk != null) {
-            apk.mCompatibilityInfo = data.info;
+            apk.mCompatibilityInfo.set(data.info);
         }
         apk = peekPackageInfo(data.pkg, true);
         if (apk != null) {
-            apk.mCompatibilityInfo = data.info;
+            apk.mCompatibilityInfo.set(data.info);
         }
         handleConfigurationChanged(mConfiguration, data.info);
+        WindowManagerImpl.getDefault().reportNewConfiguration(mConfiguration);
     }
 
     private final void deliverResults(ActivityClientRecord r, List<ResultInfo> results) {
@@ -2843,7 +2879,7 @@
             }
             deliverResults(r, res.results);
             if (resumed) {
-                mInstrumentation.callActivityOnResume(r.activity);
+                r.activity.performResume();
                 r.activity.mTemporaryPause = false;
             }
         }
@@ -3204,20 +3240,22 @@
                 ActivityClientRecord ar = it.next();
                 Activity a = ar.activity;
                 if (a != null) {
+                    Configuration thisConfig = applyConfigCompatMainThread(newConfig,
+                            ar.packageInfo.mCompatibilityInfo.getIfNeeded());
                     if (!ar.activity.mFinished && (allActivities ||
                             (a != null && !ar.paused))) {
                         // If the activity is currently resumed, its configuration
                         // needs to change right now.
                         callbacks.add(a);
-                    } else if (newConfig != null) {
+                    } else if (thisConfig != null) {
                         // Otherwise, we will tell it about the change
                         // the next time it is resumed or shown.  Note that
                         // the activity manager may, before then, decide the
                         // activity needs to be destroyed to handle its new
                         // configuration.
                         if (DEBUG_CONFIGURATION) Slog.v(TAG, "Setting activity "
-                                + ar.activityInfo.name + " newConfig=" + newConfig);
-                        ar.newConfig = newConfig;
+                                + ar.activityInfo.name + " newConfig=" + thisConfig);
+                        ar.newConfig = thisConfig;
                     }
                 }
             }
@@ -3264,11 +3302,10 @@
             // onConfigurationChanged
             int diff = activity.mCurrentConfig.diff(config);
             if (diff != 0) {
-
                 // If this activity doesn't handle any of the config changes
                 // then don't bother calling onConfigurationChanged as we're
                 // going to destroy it.
-                if ((~activity.mActivityInfo.configChanges & diff) == 0) {
+                if ((~activity.mActivityInfo.getRealConfigChanged() & diff) == 0) {
                     shouldChangeConfig = true;
                 }
             }
@@ -3291,6 +3328,12 @@
         }
     }
 
+    public final void applyConfigurationToResources(Configuration config) {
+        synchronized (mPackages) {
+            applyConfigurationToResourcesLocked(config, null);
+        }
+    }
+
     final boolean applyConfigurationToResourcesLocked(Configuration config,
             CompatibilityInfo compat) {
         if (mResConfiguration == null) {
@@ -3302,7 +3345,15 @@
             return false;
         }
         int changes = mResConfiguration.updateFrom(config);
-        DisplayMetrics dm = getDisplayMetricsLocked(true);
+        DisplayMetrics dm = getDisplayMetricsLocked(compat, true);
+
+        if (compat != null && (mResCompatibilityInfo == null ||
+                !mResCompatibilityInfo.equals(compat))) {
+            mResCompatibilityInfo = compat;
+            changes |= ActivityInfo.CONFIG_SCREEN_LAYOUT
+                    | ActivityInfo.CONFIG_SCREEN_SIZE
+                    | ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE;
+        }
 
         // set it for java, this also affects newly created Resources
         if (config.locale != null) {
@@ -3364,13 +3415,14 @@
                 return;
             }
             mConfiguration.updateFrom(config);
-            if (compat != null) {
-                // Can't do this here, because it causes us to report the
-                // comatible config back to the am as the current config
-                // of the activity, and much unhappiness results.
-                //compat.applyToConfiguration(mConfiguration);
+            if (mCompatConfiguration == null) {
+                mCompatConfiguration = new Configuration();
             }
-
+            mCompatConfiguration.setTo(mConfiguration);
+            if (mResCompatibilityInfo != null && !mResCompatibilityInfo.supportsScreen()) {
+                mResCompatibilityInfo.applyToConfiguration(mCompatConfiguration);
+                config = mCompatConfiguration;
+            }
             callbacks = collectComponentCallbacksLocked(false, config);
         }
 
@@ -3391,7 +3443,7 @@
         if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle activity config changed: "
                 + r.activityInfo.name);
         
-        performConfigurationChanged(r.activity, mConfiguration);
+        performConfigurationChanged(r.activity, mCompatConfiguration);
     }
 
     final void handleProfilerControl(boolean start, ProfilerControlData pcd) {
@@ -3485,6 +3537,7 @@
     private final void handleBindApplication(AppBindData data) {
         mBoundApplication = data;
         mConfiguration = new Configuration(data.config);
+        mCompatConfiguration = new Configuration(data.config);
 
         // send up app name; do this *before* waiting for debugger
         Process.setArgV0(data.processName);
@@ -3516,8 +3569,7 @@
          * reflect configuration changes. The configuration object passed
          * in AppBindData can be safely assumed to be up to date
          */
-        Resources.getSystem().updateConfiguration(mConfiguration,
-                Resources.getSystem().getDisplayMetrics(), data.compatInfo);
+        applyConfigurationToResourcesLocked(data.config, data.compatInfo);
 
         data.info = getPackageInfoNoCheck(data.appInfo, data.compatInfo);
 
@@ -3658,12 +3710,16 @@
         Application app = data.info.makeApplication(data.restrictedBackupMode, null);
         mInitialApplication = app;
 
-        List<ProviderInfo> providers = data.providers;
-        if (providers != null) {
-            installContentProviders(app, providers);
-            // For process that contains content providers, we want to
-            // ensure that the JIT is enabled "at some point".
-            mH.sendEmptyMessageDelayed(H.ENABLE_JIT, 10*1000);
+        // don't bring up providers in restricted mode; they may depend on the
+        // app's custom Application class
+        if (!data.restrictedBackupMode){ 
+            List<ProviderInfo> providers = data.providers;
+            if (providers != null) {
+                installContentProviders(app, providers);
+                // For process that contains content providers, we want to
+                // ensure that the JIT is enabled "at some point".
+                mH.sendEmptyMessageDelayed(H.ENABLE_JIT, 10*1000);
+            }
         }
 
         try {
diff --git a/core/java/android/app/AlertDialog.java b/core/java/android/app/AlertDialog.java
index e83d104..7a465c1 100644
--- a/core/java/android/app/AlertDialog.java
+++ b/core/java/android/app/AlertDialog.java
@@ -890,7 +890,7 @@
         public AlertDialog create() {
             final AlertDialog dialog = new AlertDialog(P.mContext, mTheme, false);
             P.apply(dialog.mAlert);
-            dialog.setCancelable(P.mCancelable);
+            dialog.setCanceledOnTouchOutside(P.mCancelable);
             dialog.setOnCancelListener(P.mOnCancelListener);
             if (P.mOnKeyListener != null) {
                 dialog.setOnKeyListener(P.mOnKeyListener);
diff --git a/core/java/android/app/Application.java b/core/java/android/app/Application.java
index b9ac848..10cc9f8 100644
--- a/core/java/android/app/Application.java
+++ b/core/java/android/app/Application.java
@@ -37,6 +37,8 @@
  * when first constructing the singleton.</p>
  */
 public class Application extends ContextWrapper implements ComponentCallbacks {
+    /** @hide */
+    public LoadedApk mLoadedApk;
     
     public Application() {
         super(null);
@@ -75,6 +77,6 @@
      */
     /* package */ final void attach(Context context) {
         attachBaseContext(context);
+        mLoadedApk = ContextImpl.getImpl(context).mPackageInfo;
     }
-
 }
diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java
index 51f1e3d..94a4afa 100644
--- a/core/java/android/app/ContextImpl.java
+++ b/core/java/android/app/ContextImpl.java
@@ -52,6 +52,8 @@
 import android.media.AudioManager;
 import android.net.ConnectivityManager;
 import android.net.IConnectivityManager;
+import android.net.INetworkPolicyManager;
+import android.net.NetworkPolicyManager;
 import android.net.ThrottleManager;
 import android.net.IThrottleManager;
 import android.net.Uri;
@@ -339,6 +341,14 @@
                     return new LocationManager(ILocationManager.Stub.asInterface(b));
                 }});
 
+        registerService(NETWORK_POLICY_SERVICE, new ServiceFetcher() {
+            @Override
+            public Object createService(ContextImpl ctx) {
+                return new NetworkPolicyManager(INetworkPolicyManager.Stub.asInterface(
+                        ServiceManager.getService(NETWORK_POLICY_SERVICE)));
+            }
+        });
+
         registerService(NOTIFICATION_SERVICE, new ServiceFetcher() {
                 public Object createService(ContextImpl ctx) {
                     final Context outerContext = ctx.getOuterContext();
@@ -425,14 +435,19 @@
 
         registerService(WINDOW_SERVICE, new ServiceFetcher() {
                 public Object getService(ContextImpl ctx) {
-                    RuntimeException e = new RuntimeException("foo");
-                    e.fillInStackTrace();
-                    Log.i(TAG, "Getting window manager", e);
-                    CompatibilityInfo ci = ctx.mResources.getCompatibilityInfo();
-                    return WindowManagerImpl.getDefault(ci);
+                    return WindowManagerImpl.getDefault(ctx.mPackageInfo.mCompatibilityInfo);
                 }});
     }
 
+    static ContextImpl getImpl(Context context) {
+        Context nextContext;
+        while ((context instanceof ContextWrapper) &&
+                (nextContext=((ContextWrapper)context).getBaseContext()) != null) {
+            context = nextContext;
+        }
+        return (ContextImpl)context;
+    }
+
     // The system service cache for the system services that are
     // cached per-ContextImpl.  Package-scoped to avoid accessor
     // methods.
diff --git a/core/java/android/app/DownloadManager.java b/core/java/android/app/DownloadManager.java
index b88e5cf..ad8d41f 100644
--- a/core/java/android/app/DownloadManager.java
+++ b/core/java/android/app/DownloadManager.java
@@ -23,6 +23,7 @@
 import android.database.Cursor;
 import android.database.CursorWrapper;
 import android.net.ConnectivityManager;
+import android.net.NetworkPolicyManager;
 import android.net.Uri;
 import android.os.Environment;
 import android.os.ParcelFileDescriptor;
@@ -170,7 +171,6 @@
      */
     public final static int STATUS_FAILED = 1 << 4;
 
-
     /**
      * Value of COLUMN_ERROR_CODE when the download has completed with an error that doesn't fit
      * under any other error code.
@@ -226,6 +226,14 @@
     public final static int ERROR_FILE_ALREADY_EXISTS = 1009;
 
     /**
+     * Value of {@link #COLUMN_REASON} when the download has failed because of
+     * {@link NetworkPolicyManager} controls on the requesting application.
+     *
+     * @hide
+     */
+    public final static int ERROR_BLOCKED = 1010;
+
+    /**
      * Value of {@link #COLUMN_REASON} when the download is paused because some network error
      * occurred and the download manager is waiting before retrying the request.
      */
@@ -1304,6 +1312,9 @@
                 case Downloads.Impl.STATUS_FILE_ALREADY_EXISTS_ERROR:
                     return ERROR_FILE_ALREADY_EXISTS;
 
+                case Downloads.Impl.STATUS_BLOCKED:
+                    return ERROR_BLOCKED;
+
                 default:
                     return ERROR_UNKNOWN;
             }
diff --git a/core/java/android/app/Fragment.java b/core/java/android/app/Fragment.java
index 6f0bbd7..cb97c46 100644
--- a/core/java/android/app/Fragment.java
+++ b/core/java/android/app/Fragment.java
@@ -244,12 +244,12 @@
  * on {@link ListFragment} for most of its work.  Note the implementation of
  * clicking an item: depending on the current activity's layout, it can either
  * create and display a new fragment to show the details in-place (more about
- * this later), or start a new activity show the details.</p>
+ * this later), or start a new activity to show the details.</p>
  *
  * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentLayout.java
  *      titles}
  *
- * <p>The details fragment showing the contents of selected item here just
+ * <p>The details fragment showing the contents of a selected item just
  * displays a string of text based on an index of a string array built in to
  * the app:</p>
  *
@@ -257,7 +257,7 @@
  *      details}
  *
  * <p>In this case when the user clicks on a title, there is no details
- * container in the current activity, so the title title fragment's click code will
+ * container in the current activity, so the titles fragment's click code will
  * launch a new activity to display the details fragment:</p>
  *
  * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentLayout.java
@@ -367,6 +367,9 @@
     // Target fragment.
     Fragment mTarget;
 
+    // For use when retaining a fragment: this is the index of the last mTarget.
+    int mTargetIndex = -1;
+
     // Target request code.
     int mTargetRequestCode;
 
@@ -450,6 +453,51 @@
     boolean mCheckedForLoaderManager;
     
     /**
+     * State information that has been retrieved from a fragment instance
+     * through {@link FragmentManager#saveFragmentInstanceState(Fragment)
+     * FragmentManager.saveFragmentInstanceState}.
+     */
+    public static class SavedState implements Parcelable {
+        final Bundle mState;
+
+        SavedState(Bundle state) {
+            mState = state;
+        }
+
+        SavedState(Parcel in, ClassLoader loader) {
+            mState = in.readBundle();
+            if (loader != null && mState != null) {
+                mState.setClassLoader(loader);
+            }
+        }
+
+        @Override
+        public int describeContents() {
+            return 0;
+        }
+
+        @Override
+        public void writeToParcel(Parcel dest, int flags) {
+            dest.writeBundle(mState);
+        }
+
+        public static final Parcelable.ClassLoaderCreator<SavedState> CREATOR
+                = new Parcelable.ClassLoaderCreator<SavedState>() {
+            public SavedState createFromParcel(Parcel in) {
+                return new SavedState(in, null);
+            }
+
+            public SavedState createFromParcel(Parcel in, ClassLoader loader) {
+                return new SavedState(in, loader);
+            }
+
+            public SavedState[] newArray(int size) {
+                return new SavedState[size];
+            }
+        };
+    }
+
+    /**
      * Thrown by {@link Fragment#instantiate(Context, String, Bundle)} when
      * there is an instantiation failure.
      */
@@ -542,11 +590,6 @@
         mWho = "android:fragment:" + mIndex;
    }
     
-    final void clearIndex() {
-        mIndex = -1;
-        mWho = null;
-    }
-    
     final boolean isInBackStack() {
         return mBackStackNesting > 0;
     }
@@ -624,6 +667,22 @@
     }
 
     /**
+     * Set the initial saved state that this Fragment should restore itself
+     * from when first being constructed, as returned by
+     * {@link FragmentManager#saveFragmentInstanceState(Fragment)
+     * FragmentManager.saveFragmentInstanceState}.
+     *
+     * @param state The state the fragment should be restored from.
+     */
+    public void setInitialSavedState(SavedState state) {
+        if (mIndex >= 0) {
+            throw new IllegalStateException("Fragment already active");
+        }
+        mSavedFragmentState = state != null && state.mState != null
+                ? state.mState : null;
+    }
+
+    /**
      * Optional target for this fragment.  This may be used, for example,
      * if this fragment is being started by another, and when done wants to
      * give a result back to the first.  The target set here is retained
@@ -722,6 +781,15 @@
     }
 
     /**
+     * Return true if the fragment has been explicitly detached from the UI.
+     * That is, {@link FragmentTransaction#detach(Fragment)
+     * FragmentTransaction.detach(Fragment)} has been used on it.
+     */
+    final public boolean isDetached() {
+        return mDetached;
+    }
+
+    /**
      * Return true if this fragment is currently being removed from its
      * activity.  This is  <em>not</em> whether its activity is finishing, but
      * rather whether it is in the process of being removed from its activity.
@@ -1142,6 +1210,35 @@
     }
 
     /**
+     * Called by the fragment manager once this fragment has been removed,
+     * so that we don't have any left-over state if the application decides
+     * to re-use the instance.  This only clears state that the framework
+     * internally manages, not things the application sets.
+     */
+    void initState() {
+        mIndex = -1;
+        mWho = null;
+        mAdded = false;
+        mRemoving = false;
+        mResumed = false;
+        mFromLayout = false;
+        mInLayout = false;
+        mRestored = false;
+        mBackStackNesting = 0;
+        mFragmentManager = null;
+        mActivity = mImmediateActivity = null;
+        mFragmentId = 0;
+        mContainerId = 0;
+        mTag = null;
+        mHidden = false;
+        mDetached = false;
+        mRetaining = false;
+        mLoaderManager = null;
+        mLoadersStarted = false;
+        mCheckedForLoaderManager = false;
+    }
+
+    /**
      * Called when the fragment is no longer attached to its activity.  This
      * is called after {@link #onDestroy()}.
      */
@@ -1368,6 +1465,13 @@
         }
     }
 
+    void performStart() {
+        onStart();
+        if (mLoaderManager != null) {
+            mLoaderManager.doReportStart();
+        }
+    }
+
     void performStop() {
         onStop();
         
@@ -1386,4 +1490,11 @@
             }
         }
     }
+
+    void performDestroyView() {
+        onDestroyView();
+        if (mLoaderManager != null) {
+            mLoaderManager.doReportNextStart();
+        }
+    }
 }
diff --git a/core/java/android/app/FragmentManager.java b/core/java/android/app/FragmentManager.java
index 0da656f..285f1c1 100644
--- a/core/java/android/app/FragmentManager.java
+++ b/core/java/android/app/FragmentManager.java
@@ -274,6 +274,30 @@
     public abstract Fragment getFragment(Bundle bundle, String key);
 
     /**
+     * Save the current instance state of the given Fragment.  This can be
+     * used later when creating a new instance of the Fragment and adding
+     * it to the fragment manager, to have it create itself to match the
+     * current state returned here.  Note that there are limits on how
+     * this can be used:
+     *
+     * <ul>
+     * <li>The Fragment must currently be attached to the FragmentManager.
+     * <li>A new Fragment created using this saved state must be the same class
+     * type as the Fragment it was created from.
+     * <li>The saved state can not contain dependencies on other fragments --
+     * that is it can't use {@link #putFragment(Bundle, String, Fragment)} to
+     * store a fragment reference because that reference may not be valid when
+     * this saved state is later used.  Likewise the Fragment's target and
+     * result code are not included in this state.
+     * </ul>
+     *
+     * @param f The Fragment whose state is to be saved.
+     * @return The generated state.  This will be null if there was no
+     * interesting state created by the fragment.
+     */
+    public abstract Fragment.SavedState saveFragmentInstanceState(Fragment f);
+
+    /**
      * Print the FragmentManager's state into the given stream.
      *
      * @param prefix Text to print at the front of each line.
@@ -492,6 +516,19 @@
     }
 
     @Override
+    public Fragment.SavedState saveFragmentInstanceState(Fragment fragment) {
+        if (fragment.mIndex < 0) {
+            throw new IllegalStateException("Fragment " + fragment
+                    + " is not currently in the FragmentManager");
+        }
+        if (fragment.mState > Fragment.INITIALIZING) {
+            Bundle result = saveFragmentBasicState(fragment);
+            return result != null ? new Fragment.SavedState(result) : null;
+        }
+        return null;
+    }
+
+    @Override
     public String toString() {
         StringBuilder sb = new StringBuilder(128);
         sb.append("FragmentManager{");
@@ -658,6 +695,10 @@
         if (!f.mAdded && newState > Fragment.CREATED) {
             newState = Fragment.CREATED;
         }
+        if (f.mRemoving && newState > f.mState) {
+            // While removing a fragment, we can't change it to a higher state.
+            newState = f.mState;
+        }
         
         if (f.mState < newState) {
             // For fragments that are created from a layout, when restoring from
@@ -715,7 +756,6 @@
                         if (f.mView != null) {
                             f.mView.setSaveFromParentEnabled(false);
                             if (f.mHidden) f.mView.setVisibility(View.GONE);
-                            f.restoreViewState();
                             f.onViewCreated(f.mView, f.mSavedFragmentState);
                         }
                     }
@@ -747,7 +787,6 @@
                                     container.addView(f.mView);
                                 }
                                 if (f.mHidden) f.mView.setVisibility(View.GONE);
-                                f.restoreViewState();
                                 f.onViewCreated(f.mView, f.mSavedFragmentState);
                             }
                         }
@@ -759,6 +798,7 @@
                                     + " did not call through to super.onActivityCreated()");
                         }
                         if (f.mView != null) {
+                            f.restoreViewState();
                         }
                         f.mSavedFragmentState = null;
                     }
@@ -767,7 +807,7 @@
                     if (newState > Fragment.STOPPED) {
                         if (DEBUG) Log.v(TAG, "moveto STARTED: " + f);
                         f.mCalled = false;
-                        f.onStart();
+                        f.performStart();
                         if (!f.mCalled) {
                             throw new SuperNotCalledException("Fragment " + f
                                     + " did not call through to super.onStart()");
@@ -820,7 +860,7 @@
                             }
                         }
                         f.mCalled = false;
-                        f.onDestroyView();
+                        f.performDestroyView();
                         if (!f.mCalled) {
                             throw new SuperNotCalledException("Fragment " + f
                                     + " did not call through to super.onDestroyView()");
@@ -879,6 +919,7 @@
                             // the fragment now should move to once the animation
                             // is done.
                             f.mStateAfterAnimating = newState;
+                            newState = Fragment.CREATED;
                         } else {
                             if (DEBUG) Log.v(TAG, "movefrom CREATED: " + f);
                             if (!f.mRetaining) {
@@ -896,9 +937,13 @@
                                 throw new SuperNotCalledException("Fragment " + f
                                         + " did not call through to super.onDetach()");
                             }
-                            f.mImmediateActivity = null;
-                            f.mActivity = null;
-                            f.mFragmentManager = null;
+                            if (!f.mRetaining) {
+                                makeInactive(f);
+                            } else {
+                                f.mImmediateActivity = null;
+                                f.mActivity = null;
+                                f.mFragmentManager = null;
+                            }
                         }
                     }
             }
@@ -970,7 +1015,7 @@
         }
         mAvailIndices.add(f.mIndex);
         mActivity.invalidateFragmentIndex(f.mIndex);
-        f.clearIndex();
+        f.initState();
     }
     
     public void addFragment(Fragment fragment, boolean moveToStateNow) {
@@ -1004,9 +1049,6 @@
             fragment.mRemoving = true;
             moveToState(fragment, inactive ? Fragment.INITIALIZING : Fragment.CREATED,
                     transition, transitionStyle);
-            if (inactive) {
-                makeInactive(fragment);
-            }
         }
     }
     
@@ -1073,7 +1115,6 @@
                     mNeedMenuInvalidate = true;
                 }
                 fragment.mAdded = false;
-                fragment.mRemoving = true;
                 moveToState(fragment, Fragment.CREATED, transition, transitionStyle);
             }
         }
@@ -1086,7 +1127,6 @@
             if (!fragment.mAdded) {
                 mAdded.add(fragment);
                 fragment.mAdded = true;
-                fragment.mRemoving = false;
                 if (fragment.mHasMenu) {
                     mNeedMenuInvalidate = true;
                 }
@@ -1363,6 +1403,7 @@
                     }
                     fragments.add(f);
                     f.mRetaining = true;
+                    f.mTargetIndex = f.mTarget != null ? f.mTarget.mIndex : -1;
                 }
             }
         }
@@ -1375,6 +1416,8 @@
         }
         if (mStateArray == null) {
             mStateArray = new SparseArray<Parcelable>();
+        } else {
+            mStateArray.clear();
         }
         f.mView.saveHierarchyState(mStateArray);
         if (mStateArray.size() > 0) {
@@ -1383,6 +1426,32 @@
         }
     }
     
+    Bundle saveFragmentBasicState(Fragment f) {
+        Bundle result = null;
+
+        if (mStateBundle == null) {
+            mStateBundle = new Bundle();
+        }
+        f.onSaveInstanceState(mStateBundle);
+        if (!mStateBundle.isEmpty()) {
+            result = mStateBundle;
+            mStateBundle = null;
+        }
+
+        if (f.mView != null) {
+            saveFragmentViewState(f);
+        }
+        if (f.mSavedViewState != null) {
+            if (result == null) {
+                result = new Bundle();
+            }
+            result.putSparseParcelableArray(
+                    FragmentManagerImpl.VIEW_STATE_TAG, f.mSavedViewState);
+        }
+
+        return result;
+    }
+
     Parcelable saveAllState() {
         // Make sure all pending operations have now been executed to get
         // our state update-to-date.
@@ -1407,25 +1476,7 @@
                 active[i] = fs;
                 
                 if (f.mState > Fragment.INITIALIZING && fs.mSavedFragmentState == null) {
-                    if (mStateBundle == null) {
-                        mStateBundle = new Bundle();
-                    }
-                    f.onSaveInstanceState(mStateBundle);
-                    if (!mStateBundle.isEmpty()) {
-                        fs.mSavedFragmentState = mStateBundle;
-                        mStateBundle = null;
-                    }
-
-                    if (f.mView != null) {
-                        saveFragmentViewState(f);
-                        if (f.mSavedViewState != null) {
-                            if (fs.mSavedFragmentState == null) {
-                                fs.mSavedFragmentState = new Bundle();
-                            }
-                            fs.mSavedFragmentState.putSparseParcelableArray(
-                                    FragmentManagerImpl.VIEW_STATE_TAG, f.mSavedViewState);
-                        }
-                    }
+                    fs.mSavedFragmentState = saveFragmentBasicState(f);
 
                     if (f.mTarget != null) {
                         if (f.mTarget.mIndex < 0) {
@@ -1517,6 +1568,7 @@
                 f.mBackStackNesting = 0;
                 f.mInLayout = false;
                 f.mAdded = false;
+                f.mTarget = null;
                 if (fs.mSavedFragmentState != null) {
                     fs.mSavedFragmentState.setClassLoader(mActivity.getClassLoader());
                     f.mSavedViewState = fs.mSavedFragmentState.getSparseParcelableArray(
@@ -1556,12 +1608,12 @@
         if (nonConfig != null) {
             for (int i=0; i<nonConfig.size(); i++) {
                 Fragment f = nonConfig.get(i);
-                if (f.mTarget != null) {
-                    if (f.mTarget.mIndex < mActive.size()) {
-                        f.mTarget = mActive.get(f.mTarget.mIndex);
+                if (f.mTargetIndex >= 0) {
+                    if (f.mTargetIndex < mActive.size()) {
+                        f.mTarget = mActive.get(f.mTargetIndex);
                     } else {
                         Log.w(TAG, "Re-attaching retained fragment " + f
-                                + " target no longer exists: " + f.mTarget);
+                                + " target no longer exists: " + f.mTargetIndex);
                         f.mTarget = null;
                     }
                 }
diff --git a/core/java/android/app/IActivityManager.java b/core/java/android/app/IActivityManager.java
index 1f53c0e..e2588cf 100644
--- a/core/java/android/app/IActivityManager.java
+++ b/core/java/android/app/IActivityManager.java
@@ -347,6 +347,9 @@
     public int getPackageScreenCompatMode(String packageName) throws RemoteException;
     public void setPackageScreenCompatMode(String packageName, int mode)
             throws RemoteException;
+    public boolean getPackageAskScreenCompat(String packageName) throws RemoteException;
+    public void setPackageAskScreenCompat(String packageName, boolean ask)
+            throws RemoteException;
     
     // Multi-user APIs
     public boolean switchUser(int userid) throws RemoteException;
@@ -577,9 +580,11 @@
     int SET_FRONT_ACTIVITY_SCREEN_COMPAT_MODE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+124;
     int GET_PACKAGE_SCREEN_COMPAT_MODE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+125;
     int SET_PACKAGE_SCREEN_COMPAT_MODE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+126;
-    int SWITCH_USER_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+127;
-    int REMOVE_SUB_TASK_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+128;
-    int REMOVE_TASK_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+129;
-    int REGISTER_PROCESS_OBSERVER_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+130;
-    int UNREGISTER_PROCESS_OBSERVER_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+131;
+    int GET_PACKAGE_ASK_SCREEN_COMPAT_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+127;
+    int SET_PACKAGE_ASK_SCREEN_COMPAT_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+128;
+    int SWITCH_USER_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+129;
+    int REMOVE_SUB_TASK_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+130;
+    int REMOVE_TASK_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+131;
+    int REGISTER_PROCESS_OBSERVER_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+132;
+    int UNREGISTER_PROCESS_OBSERVER_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+133;
 }
diff --git a/core/java/android/app/IApplicationThread.java b/core/java/android/app/IApplicationThread.java
index 8c31559..05a68a8 100644
--- a/core/java/android/app/IApplicationThread.java
+++ b/core/java/android/app/IApplicationThread.java
@@ -68,6 +68,7 @@
     static final int BACKUP_MODE_INCREMENTAL = 0;
     static final int BACKUP_MODE_FULL = 1;
     static final int BACKUP_MODE_RESTORE = 2;
+    static final int BACKUP_MODE_RESTORE_FULL = 3;
     void scheduleCreateBackupAgent(ApplicationInfo app, CompatibilityInfo compatInfo,
             int backupMode) throws RemoteException;
     void scheduleDestroyBackupAgent(ApplicationInfo app, CompatibilityInfo compatInfo)
diff --git a/core/java/android/app/IBackupAgent.aidl b/core/java/android/app/IBackupAgent.aidl
index 52fc623..8af78fa 100644
--- a/core/java/android/app/IBackupAgent.aidl
+++ b/core/java/android/app/IBackupAgent.aidl
@@ -79,4 +79,23 @@
      */
     void doRestore(in ParcelFileDescriptor data, int appVersionCode,
             in ParcelFileDescriptor newState, int token, IBackupManager callbackBinder);
+
+    /**
+     * Restore a single "file" to the application.  The file was typically obtained from
+     * a full-backup dataset.  The agent reads 'size' bytes of file content
+     * from the provided file descriptor.
+     *
+     * @param data Read-only pipe delivering the file content itself.
+     *
+     * @param size Size of the file being restored.
+     * @param type Type of file system entity, e.g. FullBackup.TYPE_DIRECTORY.
+     * @param domain Name of the file's semantic domain to which the 'path' argument is a
+     *        relative path.  e.g. FullBackup.DATABASE_TREE_TOKEN.
+     * @param path Relative path of the file within its semantic domain.
+     * @param mode Access mode of the file system entity, e.g. 0660.
+     * @param mtime Last modification time of the file system entity.
+     */
+    void doRestoreFile(in ParcelFileDescriptor data, long size,
+            int type, String domain, String path, long mode, long mtime,
+            int token, IBackupManager callbackBinder);
 }
diff --git a/core/java/android/app/ListFragment.java b/core/java/android/app/ListFragment.java
index a5ee26c..dc8420e 100644
--- a/core/java/android/app/ListFragment.java
+++ b/core/java/android/app/ListFragment.java
@@ -167,7 +167,7 @@
     TextView mStandardEmptyView;
     View mProgressContainer;
     View mListContainer;
-    boolean mSetEmptyText;
+    CharSequence mEmptyText;
     boolean mListShown;
 
     public ListFragment() {
@@ -210,6 +210,9 @@
     public void onDestroyView() {
         mHandler.removeCallbacks(mRequestFocus);
         mList = null;
+        mListShown = false;
+        mEmptyView = mProgressContainer = mListContainer = null;
+        mStandardEmptyView = null;
         super.onDestroyView();
     }
 
@@ -289,10 +292,10 @@
             throw new IllegalStateException("Can't be used with a custom content view");
         }
         mStandardEmptyView.setText(text);
-        if (!mSetEmptyText) {
+        if (mEmptyText == null) {
             mList.setEmptyView(mStandardEmptyView);
-            mSetEmptyText = true;
         }
+        mEmptyText = text;
     }
     
     /**
@@ -346,6 +349,9 @@
                         getActivity(), android.R.anim.fade_out));
                 mListContainer.startAnimation(AnimationUtils.loadAnimation(
                         getActivity(), android.R.anim.fade_in));
+            } else {
+                mProgressContainer.clearAnimation();
+                mListContainer.clearAnimation();
             }
             mProgressContainer.setVisibility(View.GONE);
             mListContainer.setVisibility(View.VISIBLE);
@@ -355,6 +361,9 @@
                         getActivity(), android.R.anim.fade_in));
                 mListContainer.startAnimation(AnimationUtils.loadAnimation(
                         getActivity(), android.R.anim.fade_out));
+            } else {
+                mProgressContainer.clearAnimation();
+                mListContainer.clearAnimation();
             }
             mProgressContainer.setVisibility(View.VISIBLE);
             mListContainer.setVisibility(View.GONE);
@@ -383,6 +392,8 @@
                     com.android.internal.R.id.internalEmpty);
             if (mStandardEmptyView == null) {
                 mEmptyView = root.findViewById(android.R.id.empty);
+            } else {
+                mStandardEmptyView.setVisibility(View.GONE);
             }
             mProgressContainer = root.findViewById(com.android.internal.R.id.progressContainer);
             mListContainer = root.findViewById(com.android.internal.R.id.listContainer);
@@ -400,12 +411,17 @@
             }
             if (mEmptyView != null) {
                 mList.setEmptyView(mEmptyView);
+            } else if (mEmptyText != null) {
+                mStandardEmptyView.setText(mEmptyText);
+                mList.setEmptyView(mStandardEmptyView);
             }
         }
         mListShown = true;
         mList.setOnItemClickListener(mOnClickListener);
         if (mAdapter != null) {
-            setListAdapter(mAdapter);
+            ListAdapter adapter = mAdapter;
+            mAdapter = null;
+            setListAdapter(adapter);
         } else {
             // We are starting without an adapter, so assume we won't
             // have our data right away and start with the progress indicator.
diff --git a/core/java/android/app/LoadedApk.java b/core/java/android/app/LoadedApk.java
index 5307696..2549c84 100644
--- a/core/java/android/app/LoadedApk.java
+++ b/core/java/android/app/LoadedApk.java
@@ -38,6 +38,7 @@
 import android.os.StrictMode;
 import android.util.AndroidRuntimeException;
 import android.util.Slog;
+import android.view.CompatibilityInfoHolder;
 
 import java.io.File;
 import java.io.IOException;
@@ -64,7 +65,7 @@
  * Local state maintained about a currently loaded .apk.
  * @hide
  */
-final class LoadedApk {
+public final class LoadedApk {
 
     private final ActivityThread mActivityThread;
     private final ApplicationInfo mApplicationInfo;
@@ -78,10 +79,10 @@
     private final ClassLoader mBaseClassLoader;
     private final boolean mSecurityViolation;
     private final boolean mIncludeCode;
+    public final CompatibilityInfoHolder mCompatibilityInfo = new CompatibilityInfoHolder();
     Resources mResources;
     private ClassLoader mClassLoader;
     private Application mApplication;
-    CompatibilityInfo mCompatibilityInfo;
 
     private final HashMap<Context, HashMap<BroadcastReceiver, LoadedApk.ReceiverDispatcher>> mReceivers
         = new HashMap<Context, HashMap<BroadcastReceiver, LoadedApk.ReceiverDispatcher>>();
@@ -98,6 +99,12 @@
         return mApplication;
     }
 
+    /**
+     * Create information about a new .apk
+     *
+     * NOTE: This constructor is called with ActivityThread's lock held,
+     * so MUST NOT call back out to the activity manager.
+     */
     public LoadedApk(ActivityThread activityThread, ApplicationInfo aInfo,
             CompatibilityInfo compatInfo,
             ActivityThread mainThread, ClassLoader baseLoader,
@@ -115,7 +122,7 @@
         mBaseClassLoader = baseLoader;
         mSecurityViolation = securityViolation;
         mIncludeCode = includeCode;
-        mCompatibilityInfo = compatInfo;
+        mCompatibilityInfo.set(compatInfo);
 
         if (mAppDir == null) {
             if (ActivityThread.mSystemContext == null) {
@@ -123,7 +130,7 @@
                     ContextImpl.createSystemContext(mainThread);
                 ActivityThread.mSystemContext.getResources().updateConfiguration(
                          mainThread.getConfiguration(),
-                         mainThread.getDisplayMetricsLocked(false),
+                         mainThread.getDisplayMetricsLocked(compatInfo, false),
                          compatInfo);
                 //Slog.i(TAG, "Created system resources "
                 //        + mSystemContext.getResources() + ": "
@@ -151,7 +158,7 @@
         mIncludeCode = true;
         mClassLoader = systemContext.getClassLoader();
         mResources = systemContext.getResources();
-        mCompatibilityInfo = compatInfo;
+        mCompatibilityInfo.set(compatInfo);
     }
 
     public String getPackageName() {
diff --git a/core/java/android/app/LoaderManager.java b/core/java/android/app/LoaderManager.java
index 164141c..46a008d 100644
--- a/core/java/android/app/LoaderManager.java
+++ b/core/java/android/app/LoaderManager.java
@@ -223,6 +223,7 @@
         boolean mStarted;
         boolean mRetaining;
         boolean mRetainingStarted;
+        boolean mReportNextStart;
         boolean mDestroyed;
         boolean mListenerRegistered;
 
@@ -291,7 +292,7 @@
                 }
             }
 
-            if (mStarted && mHaveData) {
+            if (mStarted && mHaveData && !mReportNextStart) {
                 // This loader has retained its data, either completely across
                 // a configuration change or just whatever the last data set
                 // was after being restarted from a stop, and now at the point of
@@ -302,6 +303,17 @@
             }
         }
         
+        void reportStart() {
+            if (mStarted) {
+                if (mReportNextStart) {
+                    mReportNextStart = false;
+                    if (mHaveData) {
+                        callOnLoadFinished(mLoader, mData);
+                    }
+                }
+            }
+        }
+
         void stop() {
             if (DEBUG) Log.v(TAG, "  Stopping: " + this);
             mStarted = false;
@@ -449,10 +461,11 @@
                 writer.print(prefix); writer.print("mData="); writer.println(mData);
             }
             writer.print(prefix); writer.print("mStarted="); writer.print(mStarted);
-                    writer.print(" mRetaining="); writer.print(mRetaining);
+                    writer.print(" mReportNextStart="); writer.print(mReportNextStart);
                     writer.print(" mDestroyed="); writer.println(mDestroyed);
-            writer.print(prefix); writer.print("mListenerRegistered=");
-                    writer.println(mListenerRegistered);
+            writer.print(prefix); writer.print("mRetaining="); writer.print(mRetaining);
+                    writer.print(" mRetainingStarted="); writer.print(mRetainingStarted);
+                    writer.print(" mListenerRegistered="); writer.println(mListenerRegistered);
             if (mPendingLoader != null) {
                 writer.print(prefix); writer.println("Pending Loader ");
                         writer.print(mPendingLoader); writer.println(":");
@@ -740,6 +753,18 @@
         }
     }
     
+    void doReportNextStart() {
+        for (int i = mLoaders.size()-1; i >= 0; i--) {
+            mLoaders.valueAt(i).mReportNextStart = true;
+        }
+    }
+
+    void doReportStart() {
+        for (int i = mLoaders.size()-1; i >= 0; i--) {
+            mLoaders.valueAt(i).reportStart();
+        }
+    }
+
     void doDestroy() {
         if (!mRetaining) {
             if (DEBUG) Log.v(TAG, "Destroying Active in " + this);
diff --git a/core/java/android/app/LocalActivityManager.java b/core/java/android/app/LocalActivityManager.java
index c958e1b..0a6b804 100644
--- a/core/java/android/app/LocalActivityManager.java
+++ b/core/java/android/app/LocalActivityManager.java
@@ -28,12 +28,17 @@
 import java.util.Map;
 
 /**
- * Helper class for managing multiple running embedded activities in the same
+ * @deprecated Use the new {@link Fragment} and {@link FragmentManager} APIs
+ * instead; these are also
+ * available on older platforms through the Android compatibility package.
+ *
+ * <p>Helper class for managing multiple running embedded activities in the same
  * process. This class is not normally used directly, but rather created for
  * you as part of the {@link android.app.ActivityGroup} implementation.
  *
  * @see ActivityGroup
  */
+@Deprecated
 public class LocalActivityManager {
     private static final String TAG = "LocalActivityManager";
     private static final boolean localLOGV = false;
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java
index c9351af..170d2b5 100644
--- a/core/java/android/app/Notification.java
+++ b/core/java/android/app/Notification.java
@@ -929,15 +929,15 @@
             if (mContentInfo != null) {
                 contentView.setTextViewText(R.id.info, mContentInfo);
             } else if (mNumber > 0) {
-                if (mNumber > 999) {
-                    contentView.setTextViewText(R.id.info, "999+");
+                final int tooBig = mContext.getResources().getInteger(
+                        R.integer.status_bar_notification_info_maxnum);
+                if (mNumber > tooBig) {
+                    contentView.setTextViewText(R.id.info, mContext.getResources().getString(
+                                R.string.status_bar_notification_info_overflow));
                 } else {
                     NumberFormat f = NumberFormat.getIntegerInstance();
                     contentView.setTextViewText(R.id.info, f.format(mNumber));
                 }
-                contentView.setFloat(R.id.info, "setTextSize",
-                        mContext.getResources().getDimensionPixelSize(
-                            R.dimen.status_bar_content_number_size));
             } else {
                 contentView.setViewVisibility(R.id.info, View.GONE);
             }
diff --git a/core/java/android/app/TabActivity.java b/core/java/android/app/TabActivity.java
index 033fa0c..0fd0c2c 100644
--- a/core/java/android/app/TabActivity.java
+++ b/core/java/android/app/TabActivity.java
@@ -23,8 +23,34 @@
 import android.widget.TextView;
 
 /**
- * An activity that contains and runs multiple embedded activities or views.
+ * @deprecated New applications should use Fragments instead of this class;
+ * to continue to run on older devices, you can use the v4 support library
+ * which provides a version of the Fragment API that is compatible down to
+ * {@link android.os.Build.VERSION_CODES#DONUT}.
+ *
+ * <p>For apps developing against {@link android.os.Build.VERSION_CODES#HONEYCOMB}
+ * or later, tabs are typically presented in the UI using the new
+ * {@link ActionBar#newTab() ActionBar.newTab()} and
+ * related APIs for placing tabs within their action bar area.</p>
+ *
+ * <p>A replacement for TabActivity can also be implemented by directly using
+ * TabHost.  You will need to define a layout that correctly uses a TabHost
+ * with a TabWidget as well as an area in which to display your tab content.
+ * A typical example would be:</p>
+ *
+ * {@sample development/samples/Support4Demos/res/layout/fragment_tabs.xml complete}
+ *
+ * <p>The implementation needs to take over responsibility for switching
+ * the shown content when the user switches between tabs.
+ *
+ * {@sample development/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentTabs.java
+ *      complete}
+ *
+ * <p>Also see the <a href="{@docRoot}resources/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentTabsPager.html">
+ * Fragment Tabs Pager</a> sample for an example of using the support library's ViewPager to
+ * allow the user to swipe the content to switch between tabs.</p>
  */
+@Deprecated
 public class TabActivity extends ActivityGroup {
     private TabHost mTabHost;
     private String mDefaultTab = null;
diff --git a/core/java/android/app/WallpaperManager.java b/core/java/android/app/WallpaperManager.java
index 113c610..7fd5a7d 100644
--- a/core/java/android/app/WallpaperManager.java
+++ b/core/java/android/app/WallpaperManager.java
@@ -25,6 +25,8 @@
 import android.graphics.ColorFilter;
 import android.graphics.Paint;
 import android.graphics.PixelFormat;
+import android.graphics.PorterDuff;
+import android.graphics.PorterDuffXfermode;
 import android.graphics.Rect;
 import android.graphics.drawable.BitmapDrawable;
 import android.graphics.drawable.Drawable;
@@ -115,7 +117,9 @@
 
         @Override
         public void draw(Canvas canvas) {
-            canvas.drawBitmap(mBitmap, mDrawLeft, mDrawTop, null);
+            Paint paint = new Paint();
+            paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
+            canvas.drawBitmap(mBitmap, mDrawLeft, mDrawTop, paint);
         }
 
         @Override
@@ -245,40 +249,20 @@
                 if (fd != null) {
                     int width = params.getInt("width", 0);
                     int height = params.getInt("height", 0);
-                    
-                    if (width <= 0 || height <= 0) {
-                        // Degenerate case: no size requested, just load
-                        // bitmap as-is.
-                        Bitmap bm = null;
-                        try {
-                            bm = BitmapFactory.decodeFileDescriptor(
-                                   fd.getFileDescriptor(), null, null);
-                        } catch (OutOfMemoryError e) {
-                            Log.w(TAG, "Can't decode file", e);
-                        }
+
+                    try {
+                        BitmapFactory.Options options = new BitmapFactory.Options();
+                        Bitmap bm = BitmapFactory.decodeFileDescriptor(
+                                fd.getFileDescriptor(), null, options);
+                        return generateBitmap(context, bm, width, height);
+                    } catch (OutOfMemoryError e) {
+                        Log.w(TAG, "Can't decode file", e);
+                    } finally {
                         try {
                             fd.close();
                         } catch (IOException e) {
                         }
-                        if (bm != null) {
-                            bm.setDensity(DisplayMetrics.DENSITY_DEVICE);
-                        }
-                        return bm;
                     }
-                    
-                    // Load the bitmap with full color depth, to preserve
-                    // quality for later processing.
-                    BitmapFactory.Options options = new BitmapFactory.Options();
-                    options.inDither = false;
-                    options.inPreferredConfig = Bitmap.Config.ARGB_8888;
-                    Bitmap bm = BitmapFactory.decodeFileDescriptor(
-                            fd.getFileDescriptor(), null, options);
-                    try {
-                        fd.close();
-                    } catch (IOException e) {
-                    }
-                    
-                    return generateBitmap(context, bm, width, height);
                 }
             } catch (RemoteException e) {
             }
@@ -292,42 +276,18 @@
                 if (is != null) {
                     int width = mService.getWidthHint();
                     int height = mService.getHeightHint();
-                    
-                    if (width <= 0 || height <= 0) {
-                        // Degenerate case: no size requested, just load
-                        // bitmap as-is.
-                        Bitmap bm = null;
-                        try {
-                            bm = BitmapFactory.decodeStream(is, null, null);
-                        } catch (OutOfMemoryError e) {
-                            Log.w(TAG, "Can't decode stream", e);
-                        }
+
+                    try {
+                        BitmapFactory.Options options = new BitmapFactory.Options();
+                        Bitmap bm = BitmapFactory.decodeStream(is, null, options);
+                        return generateBitmap(context, bm, width, height);
+                    } catch (OutOfMemoryError e) {
+                        Log.w(TAG, "Can't decode stream", e);
+                    } finally {
                         try {
                             is.close();
                         } catch (IOException e) {
                         }
-                        if (bm != null) {
-                            bm.setDensity(DisplayMetrics.DENSITY_DEVICE);
-                        }
-                        return bm;
-                    }
-                    
-                    // Load the bitmap with full color depth, to preserve
-                    // quality for later processing.
-                    BitmapFactory.Options options = new BitmapFactory.Options();
-                    options.inDither = false;
-                    options.inPreferredConfig = Bitmap.Config.ARGB_8888;
-                    Bitmap bm = BitmapFactory.decodeStream(is, null, options);
-                    try {
-                        is.close();
-                    } catch (IOException e) {
-                    }
-                    
-                    try {
-                        return generateBitmap(context, bm, width, height);
-                    } catch (OutOfMemoryError e) {
-                        Log.w(TAG, "Can't generate default bitmap", e);
-                        return bm;
                     }
                 }
             } catch (RemoteException e) {
@@ -711,48 +671,55 @@
     
     static Bitmap generateBitmap(Context context, Bitmap bm, int width, int height) {
         if (bm == null) {
+            return null;
+        }
+
+        bm.setDensity(DisplayMetrics.DENSITY_DEVICE);
+
+        if (width <= 0 || height <= 0
+                || (bm.getWidth() == width && bm.getHeight() == height)) {
             return bm;
         }
-        bm.setDensity(DisplayMetrics.DENSITY_DEVICE);
-        
+
         // This is the final bitmap we want to return.
-        // XXX We should get the pixel depth from the system (to match the
-        // physical display depth), when there is a way.
-        Bitmap newbm = Bitmap.createBitmap(width, height,
-                Bitmap.Config.RGB_565);
-        newbm.setDensity(DisplayMetrics.DENSITY_DEVICE);
-        Canvas c = new Canvas(newbm);
-        c.setDensity(DisplayMetrics.DENSITY_DEVICE);
-        Rect targetRect = new Rect();
-        targetRect.left = targetRect.top = 0;
-        targetRect.right = bm.getWidth();
-        targetRect.bottom = bm.getHeight();
-        
-        int deltaw = width - targetRect.right;
-        int deltah = height - targetRect.bottom;
-        
-        if (deltaw > 0 || deltah > 0) {
-            // We need to scale up so it covers the entire
-            // area.
-            float scale = 1.0f;
-            if (deltaw > deltah) {
-                scale = width / (float)targetRect.right;
-            } else {
-                scale = height / (float)targetRect.bottom;
+        try {
+            Bitmap newbm = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
+            newbm.setDensity(DisplayMetrics.DENSITY_DEVICE);
+
+            Canvas c = new Canvas(newbm);
+            Rect targetRect = new Rect();
+            targetRect.right = bm.getWidth();
+            targetRect.bottom = bm.getHeight();
+
+            int deltaw = width - targetRect.right;
+            int deltah = height - targetRect.bottom;
+
+            if (deltaw > 0 || deltah > 0) {
+                // We need to scale up so it covers the entire area.
+                float scale = 1.0f;
+                if (deltaw > deltah) {
+                    scale = width / (float)targetRect.right;
+                } else {
+                    scale = height / (float)targetRect.bottom;
+                }
+                targetRect.right = (int)(targetRect.right*scale);
+                targetRect.bottom = (int)(targetRect.bottom*scale);
+                deltaw = width - targetRect.right;
+                deltah = height - targetRect.bottom;
             }
-            targetRect.right = (int)(targetRect.right*scale);
-            targetRect.bottom = (int)(targetRect.bottom*scale);
-            deltaw = width - targetRect.right;
-            deltah = height - targetRect.bottom;
+
+            targetRect.offset(deltaw/2, deltah/2);
+
+            Paint paint = new Paint();
+            paint.setFilterBitmap(true);
+            paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
+            c.drawBitmap(bm, null, targetRect, paint);
+
+            bm.recycle();
+            return newbm;
+        } catch (OutOfMemoryError e) {
+            Log.w(TAG, "Can't generate default bitmap", e);
+            return bm;
         }
-        
-        targetRect.offset(deltaw/2, deltah/2);
-        Paint paint = new Paint();
-        paint.setFilterBitmap(true);
-        paint.setDither(true);
-        c.drawBitmap(bm, null, targetRect, paint);
-        
-        bm.recycle();
-        return newbm;
     }
 }
diff --git a/core/java/android/app/admin/DeviceAdminInfo.java b/core/java/android/app/admin/DeviceAdminInfo.java
index 1c7eb98..1c37414 100644
--- a/core/java/android/app/admin/DeviceAdminInfo.java
+++ b/core/java/android/app/admin/DeviceAdminInfo.java
@@ -130,6 +130,14 @@
      */
     public static final int USES_ENCRYPTED_STORAGE = 7;
 
+    /**
+     * A type of policy that this device admin can use: disables use of all device cameras.
+     *
+     * <p>To control this policy, the device admin must have a "disable-camera"
+     * tag in the "uses-policies" section of its meta-data.
+     */
+    public static final int USES_POLICY_DISABLE_CAMERA = 8;
+
     /** @hide */
     public static class PolicyInfo {
         public final int ident;
@@ -174,6 +182,9 @@
         sPoliciesDisplayOrder.add(new PolicyInfo(USES_ENCRYPTED_STORAGE, "encrypted-storage",
                 com.android.internal.R.string.policylab_encryptedStorage,
                 com.android.internal.R.string.policydesc_encryptedStorage));
+        sPoliciesDisplayOrder.add(new PolicyInfo(USES_POLICY_DISABLE_CAMERA, "disable-camera",
+                com.android.internal.R.string.policylab_disableCamera,
+                com.android.internal.R.string.policydesc_disableCamera));
 
         for (int i=0; i<sPoliciesDisplayOrder.size(); i++) {
             PolicyInfo pi = sPoliciesDisplayOrder.get(i);
@@ -365,7 +376,8 @@
      * {@link #USES_POLICY_LIMIT_PASSWORD}, {@link #USES_POLICY_WATCH_LOGIN},
      * {@link #USES_POLICY_RESET_PASSWORD}, {@link #USES_POLICY_FORCE_LOCK},
      * {@link #USES_POLICY_WIPE_DATA},
-     * {@link #USES_POLICY_EXPIRE_PASSWORD}, {@link #USES_ENCRYPTED_STORAGE}.
+     * {@link #USES_POLICY_EXPIRE_PASSWORD}, {@link #USES_ENCRYPTED_STORAGE},
+     * {@link #USES_POLICY_DISABLE_CAMERA}.
      */
     public boolean usesPolicy(int policyIdent) {
         return (mUsesPolicies & (1<<policyIdent)) != 0;
diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java
index efe2633..4147b0f 100644
--- a/core/java/android/app/admin/DevicePolicyManager.java
+++ b/core/java/android/app/admin/DevicePolicyManager.java
@@ -1228,6 +1228,45 @@
     }
 
     /**
+     * Called by an application that is administering the device to disable all cameras
+     * on the device.  After setting this, no applications will be able to access any cameras
+     * on the device.
+     *
+     * <p>The calling device admin must have requested
+     * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
+     * this method; if it has not, a security exception will be thrown.
+     *
+     * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
+     * @param disabled Whether or not the camera should be disabled.
+     */
+    public void setCameraDisabled(ComponentName admin, boolean disabled) {
+        if (mService != null) {
+            try {
+                mService.setCameraDisabled(admin, disabled);
+            } catch (RemoteException e) {
+                Log.w(TAG, "Failed talking with device policy service", e);
+            }
+        }
+    }
+
+    /**
+     * Determine whether or not the device's cameras have been disabled either by the current
+     * admin, if specified, or all admins.
+     * @param admin The name of the admin component to check, or null to check if any admins
+     * have disabled the camera
+     */
+    public boolean getCameraDisabled(ComponentName admin) {
+        if (mService != null) {
+            try {
+                return mService.getCameraDisabled(admin);
+            } catch (RemoteException e) {
+                Log.w(TAG, "Failed talking with device policy service", e);
+            }
+        }
+        return false;
+    }
+
+    /**
      * @hide
      */
     public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing) {
diff --git a/core/java/android/app/admin/IDevicePolicyManager.aidl b/core/java/android/app/admin/IDevicePolicyManager.aidl
index e8caca1..9419a62 100644
--- a/core/java/android/app/admin/IDevicePolicyManager.aidl
+++ b/core/java/android/app/admin/IDevicePolicyManager.aidl
@@ -79,6 +79,9 @@
     boolean getStorageEncryption(in ComponentName who);
     int getStorageEncryptionStatus();
 
+    void setCameraDisabled(in ComponentName who, boolean disabled);
+    boolean getCameraDisabled(in ComponentName who);
+
     void setActiveAdmin(in ComponentName policyReceiver, boolean refreshing);
     boolean isAdminActive(in ComponentName policyReceiver);
     List<ComponentName> getActiveAdmins();
diff --git a/core/java/android/app/backup/BackupAgent.java b/core/java/android/app/backup/BackupAgent.java
index dc60e24..63f3258 100644
--- a/core/java/android/app/backup/BackupAgent.java
+++ b/core/java/android/app/backup/BackupAgent.java
@@ -179,10 +179,18 @@
             throws IOException;
 
     /**
+     * @hide
+     */
+    public void onRestoreFile(ParcelFileDescriptor data, long size,
+            int type, String domain, String path, long mode, long mtime)
+            throws IOException {
+        // empty stub implementation
+    }
+
+    /**
      * Package-private, used only for dispatching an extra step during full backup
      */
     void onSaveApk(BackupDataOutput data) {
-        if (DEBUG) Log.v(TAG, "--- base onSaveApk() ---");
     }
 
     // ----- Core implementation -----
@@ -203,6 +211,7 @@
     private class BackupServiceBinder extends IBackupAgent.Stub {
         private static final String TAG = "BackupServiceBinder";
 
+        @Override
         public void doBackup(ParcelFileDescriptor oldState,
                 ParcelFileDescriptor data,
                 ParcelFileDescriptor newState,
@@ -236,6 +245,7 @@
             }
         }
 
+        @Override
         public void doRestore(ParcelFileDescriptor data, int appVersionCode,
                 ParcelFileDescriptor newState,
                 int token, IBackupManager callbackBinder) throws RemoteException {
@@ -261,5 +271,24 @@
                 }
             }
         }
+
+        @Override
+        public void doRestoreFile(ParcelFileDescriptor data, long size,
+                int type, String domain, String path, long mode, long mtime,
+                int token, IBackupManager callbackBinder) throws RemoteException {
+            long ident = Binder.clearCallingIdentity();
+            try {
+                BackupAgent.this.onRestoreFile(data, size, type, domain, path, mode, mtime);
+            } catch (IOException e) {
+                throw new RuntimeException(e);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+                try {
+                    callbackBinder.opComplete(token);
+                } catch (RemoteException e) {
+                    // we'll time out anyway, so we're safe
+                }
+            }
+        }
     }
 }
diff --git a/core/java/android/app/backup/FullBackup.java b/core/java/android/app/backup/FullBackup.java
index 9850566..3b70e19 100644
--- a/core/java/android/app/backup/FullBackup.java
+++ b/core/java/android/app/backup/FullBackup.java
@@ -16,6 +16,17 @@
 
 package android.app.backup;
 
+import android.os.ParcelFileDescriptor;
+import android.util.Log;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import libcore.io.ErrnoException;
+import libcore.io.Libcore;
+
 /**
  * Global constant definitions et cetera related to the full-backup-to-fd
  * binary format.
@@ -23,18 +34,96 @@
  * @hide
  */
 public class FullBackup {
-    public static String APK_TREE_TOKEN = "a";
-    public static String OBB_TREE_TOKEN = "obb";
-    public static String ROOT_TREE_TOKEN = "r";
-    public static String DATA_TREE_TOKEN = "f";
-    public static String DATABASE_TREE_TOKEN = "db";
-    public static String SHAREDPREFS_TREE_TOKEN = "sp";
-    public static String CACHE_TREE_TOKEN = "c";
+    static final String TAG = "FullBackup";
 
-    public static String FULL_BACKUP_INTENT_ACTION = "fullback";
-    public static String FULL_RESTORE_INTENT_ACTION = "fullrest";
-    public static String CONF_TOKEN_INTENT_EXTRA = "conftoken";
+    public static final String APK_TREE_TOKEN = "a";
+    public static final String OBB_TREE_TOKEN = "obb";
+    public static final String ROOT_TREE_TOKEN = "r";
+    public static final String DATA_TREE_TOKEN = "f";
+    public static final String DATABASE_TREE_TOKEN = "db";
+    public static final String SHAREDPREFS_TREE_TOKEN = "sp";
+    public static final String CACHE_TREE_TOKEN = "c";
+    public static final String SHARED_STORAGE_TOKEN = "shared";
+
+    public static final String APPS_PREFIX = "apps/";
+    public static final String SHARED_PREFIX = SHARED_STORAGE_TOKEN + "/";
+
+    public static final String FULL_BACKUP_INTENT_ACTION = "fullback";
+    public static final String FULL_RESTORE_INTENT_ACTION = "fullrest";
+    public static final String CONF_TOKEN_INTENT_EXTRA = "conftoken";
+
+    public static final int TYPE_EOF = 0;
+    public static final int TYPE_FILE = 1;
+    public static final int TYPE_DIRECTORY = 2;
+    public static final int TYPE_SYMLINK = 3;
 
     static public native int backupToTar(String packageName, String domain,
             String linkdomain, String rootpath, String path, BackupDataOutput output);
+
+    static public void restoreToFile(ParcelFileDescriptor data,
+            long size, int type, long mode, long mtime, File outFile,
+            boolean doChmod) throws IOException {
+        if (type == FullBackup.TYPE_DIRECTORY) {
+            // Canonically a directory has no associated content, so we don't need to read
+            // anything from the pipe in this case.  Just create the directory here and
+            // drop down to the final metadata adjustment.
+            if (outFile != null) outFile.mkdirs();
+        } else {
+            FileOutputStream out = null;
+
+            // Pull the data from the pipe, copying it to the output file, until we're done
+            try {
+                if (outFile != null) {
+                    File parent = outFile.getParentFile();
+                    if (!parent.exists()) {
+                        // in practice this will only be for the default semantic directories,
+                        // and using the default mode for those is appropriate.
+                        // TODO: support the edge case of apps that have adjusted the
+                        //       permissions on these core directories
+                        parent.mkdirs();
+                    }
+                    out = new FileOutputStream(outFile);
+                }
+            } catch (IOException e) {
+                Log.e(TAG, "Unable to create/open file " + outFile.getPath(), e);
+            }
+
+            byte[] buffer = new byte[32 * 1024];
+            final long origSize = size;
+            FileInputStream in = new FileInputStream(data.getFileDescriptor());
+            while (size > 0) {
+                int toRead = (size > buffer.length) ? buffer.length : (int)size;
+                int got = in.read(buffer, 0, toRead);
+                if (got <= 0) {
+                    Log.w(TAG, "Incomplete read: expected " + size + " but got "
+                            + (origSize - size));
+                    break;
+                }
+                if (out != null) {
+                    try {
+                        out.write(buffer, 0, got);
+                    } catch (IOException e) {
+                        // Problem writing to the file.  Quit copying data and delete
+                        // the file, but of course keep consuming the input stream.
+                        Log.e(TAG, "Unable to write to file " + outFile.getPath(), e);
+                        out.close();
+                        out = null;
+                        outFile.delete();
+                    }
+                }
+                size -= got;
+            }
+            if (out != null) out.close();
+        }
+
+        // Now twiddle the state to match the backup, assuming all went well
+        if (doChmod && outFile != null) {
+            try {
+                Libcore.os.chmod(outFile.getPath(), (int)mode);
+            } catch (ErrnoException e) {
+                e.rethrowAsIOException();
+            }
+            outFile.setLastModified(mtime);
+        }
+    }
 }
diff --git a/core/java/android/app/backup/FullBackupAgent.java b/core/java/android/app/backup/FullBackupAgent.java
index f0a1f2a..df1c363 100644
--- a/core/java/android/app/backup/FullBackupAgent.java
+++ b/core/java/android/app/backup/FullBackupAgent.java
@@ -28,6 +28,7 @@
 import libcore.io.StructStat;
 
 import java.io.File;
+import java.io.IOException;
 import java.util.HashSet;
 import java.util.LinkedList;
 
@@ -53,8 +54,12 @@
     private String mCacheDir;
     private String mLibDir;
 
+    private File NULL_FILE;
+
     @Override
     public void onCreate() {
+        NULL_FILE = new File("/dev/null");
+
         mPm = getPackageManager();
         try {
             ApplicationInfo appInfo = mPm.getApplicationInfo(getPackageName(), 0);
@@ -77,9 +82,10 @@
 
     @Override
     public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
-            ParcelFileDescriptor newState) {
+            ParcelFileDescriptor newState) throws IOException {
         // Filters, the scan queue, and the set of resulting entities
         HashSet<String> filterSet = new HashSet<String>();
+        String packageName = getPackageName();
 
         // Okay, start with the app's root tree, but exclude all of the canonical subdirs
         if (mLibDir != null) {
@@ -89,25 +95,28 @@
         filterSet.add(mDatabaseDir);
         filterSet.add(mSharedPrefsDir);
         filterSet.add(mFilesDir);
-        processTree(FullBackup.ROOT_TREE_TOKEN, mMainDir, filterSet, data);
+        processTree(packageName, FullBackup.ROOT_TREE_TOKEN, mMainDir, filterSet, data);
 
         // Now do the same for the files dir, db dir, and shared prefs dir
         filterSet.add(mMainDir);
         filterSet.remove(mFilesDir);
-        processTree(FullBackup.DATA_TREE_TOKEN, mFilesDir, filterSet, data);
+        processTree(packageName, FullBackup.DATA_TREE_TOKEN, mFilesDir, filterSet, data);
 
         filterSet.add(mFilesDir);
         filterSet.remove(mDatabaseDir);
-        processTree(FullBackup.DATABASE_TREE_TOKEN, mDatabaseDir, filterSet, data);
+        processTree(packageName, FullBackup.DATABASE_TREE_TOKEN, mDatabaseDir, filterSet, data);
 
         filterSet.add(mDatabaseDir);
         filterSet.remove(mSharedPrefsDir);
-        processTree(FullBackup.SHAREDPREFS_TREE_TOKEN, mSharedPrefsDir, filterSet, data);
+        processTree(packageName, FullBackup.SHAREDPREFS_TREE_TOKEN, mSharedPrefsDir, filterSet, data);
     }
 
-    private void processTree(String domain, String rootPath,
+    // Scan the dir tree (if it actually exists) and process each entry we find.  If the
+    // 'excludes' parameter is non-null, it is consulted each time a new file system entity
+    // is visited to see whether that entity (and its subtree, if appropriate) should be
+    // omitted from the backup process.
+    protected void processTree(String packageName, String domain, String rootPath,
             HashSet<String> excludes, BackupDataOutput data) {
-        // Scan the dir tree (if it actually exists) and process each entry we find
         File rootFile = new File(rootPath);
         if (rootFile.exists()) {
             LinkedList<File> scanQueue = new LinkedList<File>();
@@ -118,7 +127,7 @@
                 String filePath = file.getAbsolutePath();
 
                 // prune this subtree?
-                if (excludes.contains(filePath)) {
+                if (excludes != null && excludes.contains(filePath)) {
                     continue;
                 }
 
@@ -142,7 +151,7 @@
                 }
 
                 // Finally, back this file up before proceeding
-                FullBackup.backupToTar(getPackageName(), domain, null, rootPath, filePath, data);
+                FullBackup.backupToTar(packageName, domain, null, rootPath, filePath, data);
             }
         }
     }
@@ -177,7 +186,40 @@
         }
     }
 
+    /**
+     * Dummy -- We're never used for restore of an incremental dataset
+     */
     @Override
-    public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) {
+    public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState)
+            throws IOException {
+    }
+
+    /**
+     * Restore the described file from the given pipe.
+     */
+    @Override
+    public void onRestoreFile(ParcelFileDescriptor data, long size,
+            int type, String domain, String relpath, long mode, long mtime) 
+            throws IOException {
+        String basePath = null;
+        File outFile = null;
+
+        if (DEBUG) Log.d(TAG, "onRestoreFile() size=" + size + " type=" + type
+                + " domain=" + domain + " relpath=" + relpath + " mode=" + mode
+                + " mtime=" + mtime);
+
+        // Parse out the semantic domains into the correct physical location
+        if (domain.equals(FullBackup.DATA_TREE_TOKEN)) basePath = mFilesDir;
+        else if (domain.equals(FullBackup.DATABASE_TREE_TOKEN)) basePath = mDatabaseDir;
+        else if (domain.equals(FullBackup.ROOT_TREE_TOKEN)) basePath = mMainDir;
+        else if (domain.equals(FullBackup.SHAREDPREFS_TREE_TOKEN)) basePath = mSharedPrefsDir;
+
+        // Not a supported output location?  We need to consume the data
+        // anyway, so send it to /dev/null
+        outFile = (basePath != null) ? new File(basePath, relpath) : null;
+        if (DEBUG) Log.i(TAG, "[" + domain + " : " + relpath + "] mapped to " + outFile.getPath());
+
+        // Now that we've figured out where the data goes, send it on its way
+        FullBackup.restoreToFile(data, size, type, mode, mtime, outFile, true);
     }
 }
diff --git a/core/java/android/app/backup/IBackupManager.aidl b/core/java/android/app/backup/IBackupManager.aidl
index 94e31a8..bac874e 100644
--- a/core/java/android/app/backup/IBackupManager.aidl
+++ b/core/java/android/app/backup/IBackupManager.aidl
@@ -147,6 +147,14 @@
             boolean allApps, in String[] packageNames);
 
     /**
+     * Restore device content from the data stream passed through the given socket.  The
+     * data stream must be in the format emitted by fullBackup().
+     *
+     * <p>Callers must hold the android.permission.BACKUP permission to use this method.
+     */
+    void fullRestore(in ParcelFileDescriptor fd);
+
+    /**
      * Confirm that the requested full backup/restore operation can proceed.  The system will
      * not actually perform the operation described to fullBackup() / fullRestore() unless the
      * UI calls back into the Backup Manager to confirm, passing the correct token.  At
diff --git a/core/java/android/bluetooth/BluetoothA2dp.java b/core/java/android/bluetooth/BluetoothA2dp.java
index 9246a10..61d3707 100644
--- a/core/java/android/bluetooth/BluetoothA2dp.java
+++ b/core/java/android/bluetooth/BluetoothA2dp.java
@@ -130,7 +130,25 @@
     }
 
     /**
-     * {@inheritDoc}
+     * Initiate connection to a profile of the remote bluetooth device.
+     *
+     * <p> Currently, the system supports only 1 connection to the
+     * A2DP profile. The API will automatically disconnect connected
+     * devices before connecting.
+     *
+     * <p> This API returns false in scenarios like the profile on the
+     * device is already connected or Bluetooth is not turned on.
+     * When this API returns true, it is guaranteed that
+     * connection state intent for the profile will be broadcasted with
+     * the state. Users can get the connection state of the profile
+     * from this intent.
+     *
+     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
+     * permission.
+     *
+     * @param device Remote Bluetooth Device
+     * @return false on immediate error,
+     *               true otherwise
      * @hide
      */
     public boolean connect(BluetoothDevice device) {
@@ -149,7 +167,29 @@
     }
 
     /**
-     * {@inheritDoc}
+     * Initiate disconnection from a profile
+     *
+     * <p> This API will return false in scenarios like the profile on the
+     * Bluetooth device is not in connected state etc. When this API returns,
+     * true, it is guaranteed that the connection state change
+     * intent will be broadcasted with the state. Users can get the
+     * disconnection state of the profile from this intent.
+     *
+     * <p> If the disconnection is initiated by a remote device, the state
+     * will transition from {@link #STATE_CONNECTED} to
+     * {@link #STATE_DISCONNECTED}. If the disconnect is initiated by the
+     * host (local) device the state will transition from
+     * {@link #STATE_CONNECTED} to state {@link #STATE_DISCONNECTING} to
+     * state {@link #STATE_DISCONNECTED}. The transition to
+     * {@link #STATE_DISCONNECTING} can be used to distinguish between the
+     * two scenarios.
+     *
+     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
+     * permission.
+     *
+     * @param device Remote Bluetooth Device
+     * @return false on immediate error,
+     *               true otherwise
      * @hide
      */
     public boolean disconnect(BluetoothDevice device) {
@@ -220,7 +260,18 @@
     }
 
     /**
-     * {@inheritDoc}
+     * Set priority of the profile
+     *
+     * <p> The device should already be paired.
+     *  Priority can be one of {@link #PRIORITY_ON} or
+     * {@link #PRIORITY_OFF},
+     *
+     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
+     * permission.
+     *
+     * @param device Paired bluetooth device
+     * @param priority
+     * @return true if priority is set, false on error
      * @hide
      */
     public boolean setPriority(BluetoothDevice device, int priority) {
@@ -243,7 +294,16 @@
     }
 
     /**
-     * {@inheritDoc}
+     * Get the priority of the profile.
+     *
+     * <p> The priority can be any of:
+     * {@link #PRIORITY_AUTO_CONNECT}, {@link #PRIORITY_OFF},
+     * {@link #PRIORITY_ON}, {@link #PRIORITY_UNDEFINED}
+     *
+     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
+     *
+     * @param device Bluetooth device
+     * @return priority of the device
      * @hide
      */
     public int getPriority(BluetoothDevice device) {
diff --git a/core/java/android/bluetooth/BluetoothAdapter.java b/core/java/android/bluetooth/BluetoothAdapter.java
index e1c9044..a8c31f9 100644
--- a/core/java/android/bluetooth/BluetoothAdapter.java
+++ b/core/java/android/bluetooth/BluetoothAdapter.java
@@ -699,7 +699,7 @@
     public boolean cancelDiscovery() {
         if (getState() != STATE_ON) return false;
         try {
-            mService.cancelDiscovery();
+            return mService.cancelDiscovery();
         } catch (RemoteException e) {Log.e(TAG, "", e);}
         return false;
     }
@@ -873,10 +873,10 @@
 
     /**
      * Create a listening, insecure RFCOMM Bluetooth socket with Service Record.
-     * <p>The link key will be unauthenticated i.e the communication is
+     * <p>The link key is not required to be authenticated, i.e the communication may be
      * vulnerable to Man In the Middle attacks. For Bluetooth 2.1 devices,
-     * the link key will be encrypted, as encryption is mandartory.
-     * For legacy devices (pre Bluetooth 2.1 devices) the link key will not
+     * the link will be encrypted, as encryption is mandartory.
+     * For legacy devices (pre Bluetooth 2.1 devices) the link will not
      * be encrypted. Use {@link #listenUsingRfcommWithServiceRecord}, if an
      * encrypted and authenticated communication channel is desired.
      * <p>Use {@link BluetoothServerSocket#accept} to retrieve incoming
@@ -902,6 +902,44 @@
         return createNewRfcommSocketAndRecord(name, uuid, false, false);
     }
 
+     /**
+     * Create a listening, encrypted,
+     * RFCOMM Bluetooth socket with Service Record.
+     * <p>The link will be encrypted, but the link key is not required to be authenticated
+     * i.e the communication is vulnerable to Man In the Middle attacks. Use
+     * {@link #listenUsingRfcommWithServiceRecord}, to ensure an authenticated link key.
+     * <p> Use this socket if authentication of link key is not possible.
+     * For example, for Bluetooth 2.1 devices, if any of the devices does not have
+     * an input and output capability or just has the ability to display a numeric key,
+     * a secure socket connection is not possible and this socket can be used.
+     * Use {@link #listenUsingInsecureRfcommWithServiceRecord}, if encryption is not required.
+     * For Bluetooth 2.1 devices, the link will be encrypted, as encryption is mandartory.
+     * For more details, refer to the Security Model section 5.2 (vol 3) of
+     * Bluetooth Core Specification version 2.1 + EDR.
+     * <p>Use {@link BluetoothServerSocket#accept} to retrieve incoming
+     * connections from a listening {@link BluetoothServerSocket}.
+     * <p>The system will assign an unused RFCOMM channel to listen on.
+     * <p>The system will also register a Service Discovery
+     * Protocol (SDP) record with the local SDP server containing the specified
+     * UUID, service name, and auto-assigned channel. Remote Bluetooth devices
+     * can use the same UUID to query our SDP server and discover which channel
+     * to connect to. This SDP record will be removed when this socket is
+     * closed, or if this application closes unexpectedly.
+     * <p>Use {@link BluetoothDevice#createRfcommSocketToServiceRecord} to
+     * connect to this socket from another device using the same {@link UUID}.
+     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
+     * @param name service name for SDP record
+     * @param uuid uuid for SDP record
+     * @return a listening RFCOMM BluetoothServerSocket
+     * @throws IOException on error, for example Bluetooth not available, or
+     *                     insufficient permissions, or channel in use.
+     * @hide
+     */
+    public BluetoothServerSocket listenUsingEncryptedRfcommWithServiceRecord(
+            String name, UUID uuid) throws IOException {
+        return createNewRfcommSocketAndRecord(name, uuid, false, true);
+    }
+
     private BluetoothServerSocket createNewRfcommSocketAndRecord(String name, UUID uuid,
             boolean auth, boolean encrypt) throws IOException {
         RfcommChannelPicker picker = new RfcommChannelPicker(uuid);
@@ -973,6 +1011,28 @@
         return socket;
     }
 
+     /**
+     * Construct an encrypted, RFCOMM server socket.
+     * Call #accept to retrieve connections to this socket.
+     * @return An RFCOMM BluetoothServerSocket
+     * @throws IOException On error, for example Bluetooth not available, or
+     *                     insufficient permissions.
+     * @hide
+     */
+    public BluetoothServerSocket listenUsingEncryptedRfcommOn(int port)
+            throws IOException {
+        BluetoothServerSocket socket = new BluetoothServerSocket(
+                BluetoothSocket.TYPE_RFCOMM, false, true, port);
+        int errno = socket.mSocket.bindListen();
+        if (errno != 0) {
+            try {
+                socket.close();
+            } catch (IOException e) {}
+            socket.mSocket.throwErrnoNative(errno);
+        }
+        return socket;
+    }
+
     /**
      * Construct a SCO server socket.
      * Call #accept to retrieve connections to this socket.
diff --git a/core/java/android/bluetooth/BluetoothHeadset.java b/core/java/android/bluetooth/BluetoothHeadset.java
index 8a9bef0..23724f2 100644
--- a/core/java/android/bluetooth/BluetoothHeadset.java
+++ b/core/java/android/bluetooth/BluetoothHeadset.java
@@ -248,7 +248,25 @@
     }
 
     /**
-     * {@inheritDoc}
+     * Initiate connection to a profile of the remote bluetooth device.
+     *
+     * <p> Currently, the system supports only 1 connection to the
+     * headset/handsfree profile. The API will automatically disconnect connected
+     * devices before connecting.
+     *
+     * <p> This API returns false in scenarios like the profile on the
+     * device is already connected or Bluetooth is not turned on.
+     * When this API returns true, it is guaranteed that
+     * connection state intent for the profile will be broadcasted with
+     * the state. Users can get the connection state of the profile
+     * from this intent.
+     *
+     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
+     * permission.
+     *
+     * @param device Remote Bluetooth Device
+     * @return false on immediate error,
+     *               true otherwise
      * @hide
      */
     public boolean connect(BluetoothDevice device) {
@@ -267,7 +285,29 @@
     }
 
     /**
-     * {@inheritDoc}
+     * Initiate disconnection from a profile
+     *
+     * <p> This API will return false in scenarios like the profile on the
+     * Bluetooth device is not in connected state etc. When this API returns,
+     * true, it is guaranteed that the connection state change
+     * intent will be broadcasted with the state. Users can get the
+     * disconnection state of the profile from this intent.
+     *
+     * <p> If the disconnection is initiated by a remote device, the state
+     * will transition from {@link #STATE_CONNECTED} to
+     * {@link #STATE_DISCONNECTED}. If the disconnect is initiated by the
+     * host (local) device the state will transition from
+     * {@link #STATE_CONNECTED} to state {@link #STATE_DISCONNECTING} to
+     * state {@link #STATE_DISCONNECTED}. The transition to
+     * {@link #STATE_DISCONNECTING} can be used to distinguish between the
+     * two scenarios.
+     *
+     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
+     * permission.
+     *
+     * @param device Remote Bluetooth Device
+     * @return false on immediate error,
+     *               true otherwise
      * @hide
      */
     public boolean disconnect(BluetoothDevice device) {
@@ -338,7 +378,18 @@
     }
 
     /**
-     * {@inheritDoc}
+     * Set priority of the profile
+     *
+     * <p> The device should already be paired.
+     *  Priority can be one of {@link #PRIORITY_ON} or
+     * {@link #PRIORITY_OFF},
+     *
+     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
+     * permission.
+     *
+     * @param device Paired bluetooth device
+     * @param priority
+     * @return true if priority is set, false on error
      * @hide
      */
     public boolean setPriority(BluetoothDevice device, int priority) {
@@ -361,7 +412,16 @@
     }
 
     /**
-     * {@inheritDoc}
+     * Get the priority of the profile.
+     *
+     * <p> The priority can be any of:
+     * {@link #PRIORITY_AUTO_CONNECT}, {@link #PRIORITY_OFF},
+     * {@link #PRIORITY_ON}, {@link #PRIORITY_UNDEFINED}
+     *
+     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
+     *
+     * @param device Bluetooth device
+     * @return priority of the device
      * @hide
      */
     public int getPriority(BluetoothDevice device) {
diff --git a/core/java/android/bluetooth/BluetoothInputDevice.java b/core/java/android/bluetooth/BluetoothInputDevice.java
index df212a8..282b70a 100644
--- a/core/java/android/bluetooth/BluetoothInputDevice.java
+++ b/core/java/android/bluetooth/BluetoothInputDevice.java
@@ -119,7 +119,23 @@
     }
 
     /**
-     * {@inheritDoc}
+     * Initiate connection to a profile of the remote bluetooth device.
+     *
+     * <p> The system supports connection to multiple input devices.
+     *
+     * <p> This API returns false in scenarios like the profile on the
+     * device is already connected or Bluetooth is not turned on.
+     * When this API returns true, it is guaranteed that
+     * connection state intent for the profile will be broadcasted with
+     * the state. Users can get the connection state of the profile
+     * from this intent.
+     *
+     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
+     * permission.
+     *
+     * @param device Remote Bluetooth Device
+     * @return false on immediate error,
+     *               true otherwise
      * @hide
      */
     public boolean connect(BluetoothDevice device) {
@@ -138,7 +154,29 @@
     }
 
     /**
-     * {@inheritDoc}
+     * Initiate disconnection from a profile
+     *
+     * <p> This API will return false in scenarios like the profile on the
+     * Bluetooth device is not in connected state etc. When this API returns,
+     * true, it is guaranteed that the connection state change
+     * intent will be broadcasted with the state. Users can get the
+     * disconnection state of the profile from this intent.
+     *
+     * <p> If the disconnection is initiated by a remote device, the state
+     * will transition from {@link #STATE_CONNECTED} to
+     * {@link #STATE_DISCONNECTED}. If the disconnect is initiated by the
+     * host (local) device the state will transition from
+     * {@link #STATE_CONNECTED} to state {@link #STATE_DISCONNECTING} to
+     * state {@link #STATE_DISCONNECTED}. The transition to
+     * {@link #STATE_DISCONNECTING} can be used to distinguish between the
+     * two scenarios.
+     *
+     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
+     * permission.
+     *
+     * @param device Remote Bluetooth Device
+     * @return false on immediate error,
+     *               true otherwise
      * @hide
      */
     public boolean disconnect(BluetoothDevice device) {
@@ -209,7 +247,18 @@
     }
 
     /**
-     * {@inheritDoc}
+     * Set priority of the profile
+     *
+     * <p> The device should already be paired.
+     *  Priority can be one of {@link #PRIORITY_ON} or
+     * {@link #PRIORITY_OFF},
+     *
+     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
+     * permission.
+     *
+     * @param device Paired bluetooth device
+     * @param priority
+     * @return true if priority is set, false on error
      * @hide
      */
     public boolean setPriority(BluetoothDevice device, int priority) {
@@ -232,7 +281,16 @@
     }
 
     /**
-     * {@inheritDoc}
+     * Get the priority of the profile.
+     *
+     * <p> The priority can be any of:
+     * {@link #PRIORITY_AUTO_CONNECT}, {@link #PRIORITY_OFF},
+     * {@link #PRIORITY_ON}, {@link #PRIORITY_UNDEFINED}
+     *
+     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
+     *
+     * @param device Bluetooth device
+     * @return priority of the device
      * @hide
      */
     public int getPriority(BluetoothDevice device) {
diff --git a/core/java/android/bluetooth/BluetoothPan.java b/core/java/android/bluetooth/BluetoothPan.java
index 9ffed26..7490f9e 100644
--- a/core/java/android/bluetooth/BluetoothPan.java
+++ b/core/java/android/bluetooth/BluetoothPan.java
@@ -140,7 +140,21 @@
     }
 
     /**
-     * {@inheritDoc}
+     * Initiate connection to a profile of the remote bluetooth device.
+     *
+     * <p> This API returns false in scenarios like the profile on the
+     * device is already connected or Bluetooth is not turned on.
+     * When this API returns true, it is guaranteed that
+     * connection state intent for the profile will be broadcasted with
+     * the state. Users can get the connection state of the profile
+     * from this intent.
+     *
+     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
+     * permission.
+     *
+     * @param device Remote Bluetooth Device
+     * @return false on immediate error,
+     *               true otherwise
      * @hide
      */
     public boolean connect(BluetoothDevice device) {
@@ -159,7 +173,29 @@
     }
 
     /**
-     * {@inheritDoc}
+     * Initiate disconnection from a profile
+     *
+     * <p> This API will return false in scenarios like the profile on the
+     * Bluetooth device is not in connected state etc. When this API returns,
+     * true, it is guaranteed that the connection state change
+     * intent will be broadcasted with the state. Users can get the
+     * disconnection state of the profile from this intent.
+     *
+     * <p> If the disconnection is initiated by a remote device, the state
+     * will transition from {@link #STATE_CONNECTED} to
+     * {@link #STATE_DISCONNECTED}. If the disconnect is initiated by the
+     * host (local) device the state will transition from
+     * {@link #STATE_CONNECTED} to state {@link #STATE_DISCONNECTING} to
+     * state {@link #STATE_DISCONNECTED}. The transition to
+     * {@link #STATE_DISCONNECTING} can be used to distinguish between the
+     * two scenarios.
+     *
+     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
+     * permission.
+     *
+     * @param device Remote Bluetooth Device
+     * @return false on immediate error,
+     *               true otherwise
      * @hide
      */
     public boolean disconnect(BluetoothDevice device) {
@@ -229,27 +265,6 @@
         return BluetoothProfile.STATE_DISCONNECTED;
     }
 
-    /**
-     * {@inheritDoc}
-     * @hide
-     */
-    public boolean setPriority(BluetoothDevice device, int priority) {
-        // Priorities are not supported for PAN devices - since we don't
-        // auto connect.
-        return false;
-    }
-
-    /**
-     * {@inheritDoc}
-     * @hide
-     */
-    public int getPriority(BluetoothDevice device) {
-        if (DBG) log("getPriority(" + device + ")");
-        // Priorities are not supported for PAN devices - since we don't
-        // auto connect.
-        return BluetoothProfile.PRIORITY_ON;
-    }
-
     public void setBluetoothTethering(boolean value) {
         if (DBG) log("setBluetoothTethering(" + value + ")");
         try {
diff --git a/core/java/android/bluetooth/BluetoothProfile.java b/core/java/android/bluetooth/BluetoothProfile.java
index 1ad66f7..22555f0 100644
--- a/core/java/android/bluetooth/BluetoothProfile.java
+++ b/core/java/android/bluetooth/BluetoothProfile.java
@@ -104,58 +104,6 @@
     public static final int PRIORITY_UNDEFINED = -1;
 
     /**
-     * Initiate connection to a profile of the remote bluetooth device.
-     *
-     * <p> Currently, the system supports only 1 connection to the
-     * A2DP and Headset/Handsfree profile. The API will automatically
-     * disconnect connected devices before connecting.
-     *
-     * <p> This API returns false in scenarios like the profile on the
-     * device is already connected or Bluetooth is not turned on.
-     * When this API returns true, it is guaranteed that
-     * connection state intent for the profile will be broadcasted with
-     * the state. Users can get the connection state of the profile
-     * from this intent.
-     *
-     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
-     * permission.
-     *
-     * @param device Remote Bluetooth Device
-     * @return false on immediate error,
-     *               true otherwise
-     * @hide
-     */
-    public boolean connect(BluetoothDevice device);
-
-    /**
-     * Initiate disconnection from a profile
-     *
-     * <p> This API will return false in scenarios like the profile on the
-     * Bluetooth device is not in connected state etc. When this API returns,
-     * true, it is guaranteed that the connection state change
-     * intent will be broadcasted with the state. Users can get the
-     * disconnection state of the profile from this intent.
-     *
-     * <p> If the disconnection is initiated by a remote device, the state
-     * will transition from {@link #STATE_CONNECTED} to
-     * {@link #STATE_DISCONNECTED}. If the disconnect is initiated by the
-     * host (local) device the state will transition from
-     * {@link #STATE_CONNECTED} to state {@link #STATE_DISCONNECTING} to
-     * state {@link #STATE_DISCONNECTED}. The transition to
-     * {@link #STATE_DISCONNECTING} can be used to distinguish between the
-     * two scenarios.
-     *
-     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
-     * permission.
-     *
-     * @param device Remote Bluetooth Device
-     * @return false on immediate error,
-     *               true otherwise
-     * @hide
-     */
-    public boolean disconnect(BluetoothDevice device);
-
-    /**
      * Get connected devices for this specific profile.
      *
      * <p> Return the set of devices which are in state {@link #STATE_CONNECTED}
@@ -195,38 +143,6 @@
     public int getConnectionState(BluetoothDevice device);
 
     /**
-     * Set priority of the profile
-     *
-     * <p> The device should already be paired.
-     *  Priority can be one of {@link #PRIORITY_ON} or
-     * {@link #PRIORITY_OFF},
-     *
-     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
-     * permission.
-     *
-     * @param device Paired bluetooth device
-     * @param priority
-     * @return true if priority is set, false on error
-     * @hide
-     */
-    public boolean setPriority(BluetoothDevice device, int priority);
-
-    /**
-     * Get the priority of the profile.
-     *
-     * <p> The priority can be any of:
-     * {@link #PRIORITY_AUTO_CONNECT}, {@link #PRIORITY_OFF},
-     * {@link #PRIORITY_ON}, {@link #PRIORITY_UNDEFINED}
-     *
-     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
-     *
-     * @param device Bluetooth device
-     * @return priority of the device
-     * @hide
-     */
-    public int getPriority(BluetoothDevice device);
-
-    /**
      * An interface for notifying BluetoothProfile IPC clients when they have
      * been connected or disconnected to the service.
      */
diff --git a/core/java/android/bluetooth/BluetoothSocket.java b/core/java/android/bluetooth/BluetoothSocket.java
index 719d730..9a13c3e 100644
--- a/core/java/android/bluetooth/BluetoothSocket.java
+++ b/core/java/android/bluetooth/BluetoothSocket.java
@@ -94,10 +94,16 @@
 
     private int mPort;  /* RFCOMM channel or L2CAP psm */
 
-    /** prevents all native calls after destroyNative() */
-    private boolean mClosed;
+    private enum SocketState {
+        INIT,
+        CONNECTED,
+        CLOSED
+    }
 
-    /** protects mClosed */
+    /** prevents all native calls after destroyNative() */
+    private SocketState mSocketState;
+
+    /** protects mSocketState */
     private final ReentrantReadWriteLock mLock;
 
     /** used by native code only */
@@ -145,7 +151,7 @@
         }
         mInputStream = new BluetoothInputStream(this);
         mOutputStream = new BluetoothOutputStream(this);
-        mClosed = false;
+        mSocketState = SocketState.INIT;
         mLock = new ReentrantReadWriteLock();
     }
 
@@ -195,13 +201,14 @@
     public void connect() throws IOException {
         mLock.readLock().lock();
         try {
-            if (mClosed) throw new IOException("socket closed");
+            if (mSocketState == SocketState.CLOSED) throw new IOException("socket closed");
 
             if (mSdp != null) {
                 mPort = mSdp.doSdp();  // blocks
             }
 
             connectNative();  // blocks
+            mSocketState = SocketState.CONNECTED;
         } finally {
             mLock.readLock().unlock();
         }
@@ -216,7 +223,7 @@
         // abort blocking operations on the socket
         mLock.readLock().lock();
         try {
-            if (mClosed) return;
+            if (mSocketState == SocketState.CLOSED) return;
             if (mSdp != null) {
                 mSdp.cancel();
             }
@@ -229,7 +236,7 @@
         // abortNative(), so this lock should immediately acquire
         mLock.writeLock().lock();
         try {
-            mClosed = true;
+            mSocketState = SocketState.CLOSED;
             destroyNative();
         } finally {
             mLock.writeLock().unlock();
@@ -267,13 +274,23 @@
     }
 
     /**
+     * Get the connection status of this socket, ie, whether there is an active connection with
+     * remote device.
+     * @return true if connected
+     *         false if not connected
+     */
+    public boolean isConnected() {
+        return (mSocketState == SocketState.CONNECTED);
+    }
+
+    /**
      * Currently returns unix errno instead of throwing IOException,
      * so that BluetoothAdapter can check the error code for EADDRINUSE
      */
     /*package*/ int bindListen() {
         mLock.readLock().lock();
         try {
-            if (mClosed) return EBADFD;
+            if (mSocketState == SocketState.CLOSED) return EBADFD;
             return bindListenNative();
         } finally {
             mLock.readLock().unlock();
@@ -283,8 +300,11 @@
     /*package*/ BluetoothSocket accept(int timeout) throws IOException {
         mLock.readLock().lock();
         try {
-            if (mClosed) throw new IOException("socket closed");
-            return acceptNative(timeout);
+            if (mSocketState == SocketState.CLOSED) throw new IOException("socket closed");
+
+            BluetoothSocket acceptedSocket = acceptNative(timeout);
+            mSocketState = SocketState.CONNECTED;
+            return acceptedSocket;
         } finally {
             mLock.readLock().unlock();
         }
@@ -293,7 +313,7 @@
     /*package*/ int available() throws IOException {
         mLock.readLock().lock();
         try {
-            if (mClosed) throw new IOException("socket closed");
+            if (mSocketState == SocketState.CLOSED) throw new IOException("socket closed");
             return availableNative();
         } finally {
             mLock.readLock().unlock();
@@ -303,7 +323,7 @@
     /*package*/ int read(byte[] b, int offset, int length) throws IOException {
         mLock.readLock().lock();
         try {
-            if (mClosed) throw new IOException("socket closed");
+            if (mSocketState == SocketState.CLOSED) throw new IOException("socket closed");
             return readNative(b, offset, length);
         } finally {
             mLock.readLock().unlock();
@@ -313,7 +333,7 @@
     /*package*/ int write(byte[] b, int offset, int length) throws IOException {
         mLock.readLock().lock();
         try {
-            if (mClosed) throw new IOException("socket closed");
+            if (mSocketState == SocketState.CLOSED) throw new IOException("socket closed");
             return writeNative(b, offset, length);
         } finally {
             mLock.readLock().unlock();
diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java
index a660bd7..aecec66 100644
--- a/core/java/android/content/Context.java
+++ b/core/java/android/content/Context.java
@@ -1545,6 +1545,8 @@
     public static final String NETWORKMANAGEMENT_SERVICE = "network_management";
 
     /** {@hide} */
+    public static final String NETWORK_STATS_SERVICE = "netstats";
+    /** {@hide} */
     public static final String NETWORK_POLICY_SERVICE = "netpolicy";
 
     /**
diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java
index 3d637e9..2f9627a 100644
--- a/core/java/android/content/Intent.java
+++ b/core/java/android/content/Intent.java
@@ -1160,6 +1160,15 @@
     public static final String ACTION_UPGRADE_SETUP = "android.intent.action.UPGRADE_SETUP";
 
     /**
+     * Activity Action: Show settings for managing network data usage of a
+     * specific application. Applications should define an activity that offers
+     * options to control data usage.
+     */
+    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
+    public static final String ACTION_MANAGE_NETWORK_USAGE =
+            "android.intent.action.MANAGE_NETWORK_USAGE";
+
+    /**
      * A string associated with a {@link #ACTION_UPGRADE_SETUP} activity
      * describing the last run version of the platform that was setup.
      * @hide
@@ -1654,8 +1663,9 @@
      * This is used mainly for the USB Settings panel.
      * Apps should listen for ACTION_MEDIA_MOUNTED and ACTION_MEDIA_UNMOUNTED broadcasts to be notified
      * when the SD card file system is mounted or unmounted
+     * @deprecated replaced by android.os.storage.StorageEventListener
      */
-    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
+    @Deprecated
     public static final String ACTION_UMS_CONNECTED = "android.intent.action.UMS_CONNECTED";
 
     /**
@@ -1663,8 +1673,9 @@
      * This is used mainly for the USB Settings panel.
      * Apps should listen for ACTION_MEDIA_MOUNTED and ACTION_MEDIA_UNMOUNTED broadcasts to be notified
      * when the SD card file system is mounted or unmounted
+     * @deprecated replaced by android.os.storage.StorageEventListener
      */
-    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
+    @Deprecated
     public static final String ACTION_UMS_DISCONNECTED = "android.intent.action.UMS_DISCONNECTED";
 
     /**
diff --git a/core/java/android/content/IntentFilter.java b/core/java/android/content/IntentFilter.java
index 2a0ebcf..f3b1d94 100644
--- a/core/java/android/content/IntentFilter.java
+++ b/core/java/android/content/IntentFilter.java
@@ -16,16 +16,6 @@
 
 package android.content;
 
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-import org.xmlpull.v1.XmlSerializer;
-
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.Set;
-
 import android.net.Uri;
 import android.os.Parcel;
 import android.os.Parcelable;
@@ -36,6 +26,15 @@
 
 import com.android.internal.util.XmlUtils;
 
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+import org.xmlpull.v1.XmlSerializer;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Set;
+
 /**
  * Structured description of Intent values to be matched.  An IntentFilter can
  * match against actions, categories, and data (either via its type, scheme,
@@ -754,7 +753,7 @@
     }
 
     /**
-     * Add a new Intent data oath to match against.  The filter must
+     * Add a new Intent data path to match against.  The filter must
      * include one or more schemes (via {@link #addDataScheme}) <em>and</em>
      * one or more authorities (via {@link #addDataAuthority}) for the
      * path to be considered.  If any paths are
diff --git a/core/java/android/content/pm/ActivityInfo.java b/core/java/android/content/pm/ActivityInfo.java
index 4285388..4858f14 100644
--- a/core/java/android/content/pm/ActivityInfo.java
+++ b/core/java/android/content/pm/ActivityInfo.java
@@ -335,13 +335,25 @@
     /**
      * Bit in {@link #configChanges} that indicates that the activity
      * can itself handle the screen size. Set from the
-     * {@link android.R.attr#configChanges} attribute.
+     * {@link android.R.attr#configChanges} attribute.  This will be
+     * set by default for applications that target an earlier version
+     * than {@link android.os.Build.VERSION_CODES#HONEYCOMB_MR2}...
+     * <b>however</b>, you will not see the bit set here becomes some
+     * applications incorrectly compare {@link #configChanges} against
+     * an absolute value rather than correctly masking out the bits
+     * they are interested in.  Please don't do that, thanks.
      */
     public static final int CONFIG_SCREEN_SIZE = 0x0400;
     /**
      * Bit in {@link #configChanges} that indicates that the activity
      * can itself handle the smallest screen size. Set from the
-     * {@link android.R.attr#configChanges} attribute.
+     * {@link android.R.attr#configChanges} attribute.  This will be
+     * set by default for applications that target an earlier version
+     * than {@link android.os.Build.VERSION_CODES#HONEYCOMB_MR2}...
+     * <b>however</b>, you will not see the bit set here becomes some
+     * applications incorrectly compare {@link #configChanges} against
+     * an absolute value rather than correctly masking out the bits
+     * they are interested in.  Please don't do that, thanks.
      */
     public static final int CONFIG_SMALLEST_SCREEN_SIZE = 0x0800;
     /**
@@ -386,6 +398,21 @@
     }
 
     /**
+     * @hide
+     * Unfortunately some developers (OpenFeint I am looking at you) have
+     * compared the configChanges bit field against absolute values, so if we
+     * introduce a new bit they break.  To deal with that, we will make sure
+     * the public field will not have a value that breaks them, and let the
+     * framework call here to get the real value.
+     */
+    public int getRealConfigChanged() {
+        return applicationInfo.targetSdkVersion < android.os.Build.VERSION_CODES.HONEYCOMB_MR2
+                ? (configChanges | ActivityInfo.CONFIG_SCREEN_SIZE
+                        | ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE)
+                : configChanges;
+    }
+
+    /**
      * Bit mask of kinds of configuration changes that this activity
      * can handle itself (without being restarted by the system).
      * Contains any combination of {@link #CONFIG_FONT_SCALE},
diff --git a/core/java/android/content/pm/ApplicationInfo.java b/core/java/android/content/pm/ApplicationInfo.java
index 4b38d48..454cb31 100644
--- a/core/java/android/content/pm/ApplicationInfo.java
+++ b/core/java/android/content/pm/ApplicationInfo.java
@@ -330,6 +330,30 @@
     public int flags = 0;
     
     /**
+     * The required smallest screen width the application can run on.  If 0,
+     * nothing has been specified.  Comes from
+     * {@link android.R.styleable#AndroidManifestSupportsScreens_requiresSmallestWidthDp
+     * android:requiresSmallestWidthDp} attribute of the &lt;supports-screens&gt; tag.
+     */
+    public int requiresSmallestWidthDp = 0;
+
+    /**
+     * The maximum smallest screen width the application is designed for.  If 0,
+     * nothing has been specified.  Comes from
+     * {@link android.R.styleable#AndroidManifestSupportsScreens_compatibleWidthLimitDp
+     * android:compatibleWidthLimitDp} attribute of the &lt;supports-screens&gt; tag.
+     */
+    public int compatibleWidthLimitDp = 0;
+
+    /**
+     * The maximum smallest screen width the application will work on.  If 0,
+     * nothing has been specified.  Comes from
+     * {@link android.R.styleable#AndroidManifestSupportsScreens_largestWidthLimitDp
+     * android:largestWidthLimitDp} attribute of the &lt;supports-screens&gt; tag.
+     */
+    public int largestWidthLimitDp = 0;
+
+    /**
      * Full path to the location of this package.
      */
     public String sourceDir;
@@ -393,6 +417,12 @@
     public boolean enabled = true;
 
     /**
+     * For convenient access to the current enabled setting of this app.
+     * @hide
+     */
+    public int enabledSetting = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
+
+    /**
      * For convenient access to package's install location.
      * @hide
      */
@@ -410,6 +440,9 @@
         pw.println(prefix + "taskAffinity=" + taskAffinity);
         pw.println(prefix + "uid=" + uid + " flags=0x" + Integer.toHexString(flags)
                 + " theme=0x" + Integer.toHexString(theme));
+        pw.println(prefix + "requiresSmallestWidthDp=" + requiresSmallestWidthDp
+                + " compatibleWidthLimitDp=" + compatibleWidthLimitDp
+                + " largestWidthLimitDp=" + largestWidthLimitDp);
         pw.println(prefix + "sourceDir=" + sourceDir);
         if (sourceDir == null) {
             if (publicSourceDir != null) {
@@ -469,6 +502,9 @@
         className = orig.className;
         theme = orig.theme;
         flags = orig.flags;
+        requiresSmallestWidthDp = orig.requiresSmallestWidthDp;
+        compatibleWidthLimitDp = orig.compatibleWidthLimitDp;
+        largestWidthLimitDp = orig.largestWidthLimitDp;
         sourceDir = orig.sourceDir;
         publicSourceDir = orig.publicSourceDir;
         nativeLibraryDir = orig.nativeLibraryDir;
@@ -478,6 +514,7 @@
         uid = orig.uid;
         targetSdkVersion = orig.targetSdkVersion;
         enabled = orig.enabled;
+        enabledSetting = orig.enabledSetting;
         installLocation = orig.installLocation;
         manageSpaceActivityName = orig.manageSpaceActivityName;
         descriptionRes = orig.descriptionRes;
@@ -502,6 +539,9 @@
         dest.writeString(className);
         dest.writeInt(theme);
         dest.writeInt(flags);
+        dest.writeInt(requiresSmallestWidthDp);
+        dest.writeInt(compatibleWidthLimitDp);
+        dest.writeInt(largestWidthLimitDp);
         dest.writeString(sourceDir);
         dest.writeString(publicSourceDir);
         dest.writeString(nativeLibraryDir);
@@ -511,6 +551,7 @@
         dest.writeInt(uid);
         dest.writeInt(targetSdkVersion);
         dest.writeInt(enabled ? 1 : 0);
+        dest.writeInt(enabledSetting);
         dest.writeInt(installLocation);
         dest.writeString(manageSpaceActivityName);
         dest.writeString(backupAgentName);
@@ -536,6 +577,9 @@
         className = source.readString();
         theme = source.readInt();
         flags = source.readInt();
+        requiresSmallestWidthDp = source.readInt();
+        compatibleWidthLimitDp = source.readInt();
+        largestWidthLimitDp = source.readInt();
         sourceDir = source.readString();
         publicSourceDir = source.readString();
         nativeLibraryDir = source.readString();
@@ -545,6 +589,7 @@
         uid = source.readInt();
         targetSdkVersion = source.readInt();
         enabled = source.readInt() != 0;
+        enabledSetting = source.readInt();
         installLocation = source.readInt();
         manageSpaceActivityName = source.readString();
         backupAgentName = source.readString();
diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java
index ff817c1..dd684cd 100644
--- a/core/java/android/content/pm/PackageManager.java
+++ b/core/java/android/content/pm/PackageManager.java
@@ -224,11 +224,41 @@
      */
     public static final int SIGNATURE_UNKNOWN_PACKAGE = -4;
 
+    /**
+     * Flag for {@link #setApplicationEnabledSetting(String, int, int)}
+     * and {@link #setComponentEnabledSetting(ComponentName, int, int)}: This
+     * component or application is in its default enabled state (as specified
+     * in its manifest).
+     */
     public static final int COMPONENT_ENABLED_STATE_DEFAULT = 0;
+
+    /**
+     * Flag for {@link #setApplicationEnabledSetting(String, int, int)}
+     * and {@link #setComponentEnabledSetting(ComponentName, int, int)}: This
+     * component or application has been explictily enabled, regardless of
+     * what it has specified in its manifest.
+     */
     public static final int COMPONENT_ENABLED_STATE_ENABLED = 1;
+
+    /**
+     * Flag for {@link #setApplicationEnabledSetting(String, int, int)}
+     * and {@link #setComponentEnabledSetting(ComponentName, int, int)}: This
+     * component or application has been explicitly disabled, regardless of
+     * what it has specified in its manifest.
+     */
     public static final int COMPONENT_ENABLED_STATE_DISABLED = 2;
 
     /**
+     * Flag for {@link #setApplicationEnabledSetting(String, int, int)} only: The
+     * user has explicitly disabled the application, regardless of what it has
+     * specified in its manifest.  Because this is due to the user's request,
+     * they may re-enable it if desired through the appropriate system UI.  This
+     * option currently <strong>can not</strong> be used with
+     * {@link #setComponentEnabledSetting(ComponentName, int, int)}.
+     */
+    public static final int COMPONENT_ENABLED_STATE_DISABLED_USER = 3;
+
+    /**
      * Flag parameter for {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} to
      * indicate that this package should be installed as forward locked, i.e. only the app itself
      * should have access to its code and non-resource assets.
@@ -893,6 +923,58 @@
 
     /**
      * Feature for {@link #getSystemAvailableFeatures} and
+     * {@link #hasSystemFeature}: The device does not have a touch screen, but
+     * does support touch emulation for basic events that supports distinct
+     * tracking of two or more fingers.  This is an extension of
+     * {@link #FEATURE_FAKETOUCH} for input devices with this capability.  Note
+     * that unlike a distinct multitouch screen as defined by
+     * {@link #FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT}, these kinds of input
+     * devices will not actually provide full two-finger gestures since the
+     * input is being transformed to cursor movement on the screen.  That is,
+     * single finger gestures will move a cursor; two-finger swipes will
+     * result in single-finger touch events; other two-finger gestures will
+     * result in the corresponding two-finger touch event.
+     */
+    @SdkConstant(SdkConstantType.FEATURE)
+    public static final String FEATURE_FAKETOUCH_MULTITOUCH_DISTINCT = "android.hardware.faketouch.multitouch.distinct";
+
+    /**
+     * Feature for {@link #getSystemAvailableFeatures} and
+     * {@link #hasSystemFeature}: The device does not have a touch screen, but
+     * does support touch emulation for basic events that supports tracking
+     * a hand of fingers (5 or more fingers) fully independently.
+     * This is an extension of
+     * {@link #FEATURE_FAKETOUCH} for input devices with this capability.  Note
+     * that unlike a multitouch screen as defined by
+     * {@link #FEATURE_TOUCHSCREEN_MULTITOUCH_JAZZHAND}, not all two finger
+     * gestures can be detected due to the limitations described for
+     * {@link #FEATURE_FAKETOUCH_MULTITOUCH_DISTINCT}.
+     */
+    @SdkConstant(SdkConstantType.FEATURE)
+    public static final String FEATURE_FAKETOUCH_MULTITOUCH_JAZZHAND = "android.hardware.faketouch.multitouch.jazzhand";
+
+    /**
+     * Feature for {@link #getSystemAvailableFeatures} and
+     * {@link #hasSystemFeature}: The device supports portrait orientation
+     * screens.  For backwards compatibility, you can assume that if neither
+     * this nor {@link #FEATURE_SCREEN_LANDSCAPE} is set then the device supports
+     * both portrait and landscape.
+     */
+    @SdkConstant(SdkConstantType.FEATURE)
+    public static final String FEATURE_SCREEN_PORTRAIT = "android.hardware.screen.portrait";
+
+    /**
+     * Feature for {@link #getSystemAvailableFeatures} and
+     * {@link #hasSystemFeature}: The device supports landscape orientation
+     * screens.  For backwards compatibility, you can assume that if neither
+     * this nor {@link #FEATURE_SCREEN_PORTRAIT} is set then the device supports
+     * both portrait and landscape.
+     */
+    @SdkConstant(SdkConstantType.FEATURE)
+    public static final String FEATURE_SCREEN_LANDSCAPE = "android.hardware.screen.landscape";
+
+    /**
+     * Feature for {@link #getSystemAvailableFeatures} and
      * {@link #hasSystemFeature}: The device supports live wallpapers.
      */
     @SdkConstant(SdkConstantType.FEATURE)
diff --git a/core/java/android/content/pm/PackageParser.java b/core/java/android/content/pm/PackageParser.java
index 9ff324b..e927f6c 100644
--- a/core/java/android/content/pm/PackageParser.java
+++ b/core/java/android/content/pm/PackageParser.java
@@ -993,6 +993,16 @@
                 sa = res.obtainAttributes(attrs,
                         com.android.internal.R.styleable.AndroidManifestSupportsScreens);
 
+                pkg.applicationInfo.requiresSmallestWidthDp = sa.getInteger(
+                        com.android.internal.R.styleable.AndroidManifestSupportsScreens_requiresSmallestWidthDp,
+                        0);
+                pkg.applicationInfo.compatibleWidthLimitDp = sa.getInteger(
+                        com.android.internal.R.styleable.AndroidManifestSupportsScreens_compatibleWidthLimitDp,
+                        0);
+                pkg.applicationInfo.largestWidthLimitDp = sa.getInteger(
+                        com.android.internal.R.styleable.AndroidManifestSupportsScreens_largestWidthLimitDp,
+                        0);
+
                 // This is a trick to get a boolean and still able to detect
                 // if a value was actually set.
                 supportsSmallScreens = sa.getInteger(
@@ -1507,11 +1517,12 @@
             }
         }
 
+        // fullBackupAgent is explicitly handled even if allowBackup is false
         name = sa.getNonConfigurationString(
                 com.android.internal.R.styleable.AndroidManifestApplication_fullBackupAgent, 0);
         if (name != null) {
             ai.fullBackupAgentName = buildClassName(pkgName, name, outError);
-            if (true) {
+            if (false) {
                 Log.v(TAG, "android:fullBackupAgent=" + ai.fullBackupAgentName
                         + " from " + pkgName + "+" + name);
             }
@@ -1941,11 +1952,6 @@
             a.info.configChanges = sa.getInt(
                     com.android.internal.R.styleable.AndroidManifestActivity_configChanges,
                     0);
-            if (owner.applicationInfo.targetSdkVersion
-                        < android.os.Build.VERSION_CODES.HONEYCOMB_MR2) {
-                a.info.configChanges |= ActivityInfo.CONFIG_SCREEN_SIZE
-                        | ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE;
-            }
             a.info.softInputMode = sa.getInt(
                     com.android.internal.R.styleable.AndroidManifestActivity_windowSoftInputMode,
                     0);
@@ -3122,9 +3128,11 @@
         }
         if (p.mSetEnabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
             ai.enabled = true;
-        } else if (p.mSetEnabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
+        } else if (p.mSetEnabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED
+                || p.mSetEnabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) {
             ai.enabled = false;
         }
+        ai.enabledSetting = p.mSetEnabled;
         return ai;
     }
 
diff --git a/core/java/android/content/res/CompatibilityInfo.aidl b/core/java/android/content/res/CompatibilityInfo.aidl
new file mode 100644
index 0000000..cde3d7b
--- /dev/null
+++ b/core/java/android/content/res/CompatibilityInfo.aidl
@@ -0,0 +1,20 @@
+/*
+** Copyright 2011, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License"); 
+** you may not use this file except in compliance with the License. 
+** You may obtain a copy of the License at 
+**
+**     http://www.apache.org/licenses/LICENSE-2.0 
+**
+** Unless required by applicable law or agreed to in writing, software 
+** distributed under the License is distributed on an "AS IS" BASIS, 
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+** See the License for the specific language governing permissions and 
+** limitations under the License.
+*/
+
+package android.content.res;
+
+parcelable CompatibilityInfo;
+
diff --git a/core/java/android/content/res/CompatibilityInfo.java b/core/java/android/content/res/CompatibilityInfo.java
index 854d410..acf2f2f1 100644
--- a/core/java/android/content/res/CompatibilityInfo.java
+++ b/core/java/android/content/res/CompatibilityInfo.java
@@ -63,37 +63,19 @@
     private static final int SCALING_REQUIRED = 1; 
 
     /**
-     * Has the application said that its UI is expandable?  Based on the
-     * <supports-screen> android:expandible in the manifest.
-     */
-    private static final int EXPANDABLE = 2;
-    
-    /**
-     * Has the application said that its UI supports large screens?  Based on the
-     * <supports-screen> android:largeScreens in the manifest.
-     */
-    private static final int LARGE_SCREENS = 8;
-    
-    /**
-     * Has the application said that its UI supports xlarge screens?  Based on the
-     * <supports-screen> android:xlargeScreens in the manifest.
-     */
-    private static final int XLARGE_SCREENS = 32;
-    
-    /**
      * Application must always run in compatibility mode?
      */
-    private static final int ALWAYS_COMPAT = 64;
+    private static final int ALWAYS_NEEDS_COMPAT = 2;
 
     /**
      * Application never should run in compatibility mode?
      */
-    private static final int NEVER_COMPAT = 128;
+    private static final int NEVER_NEEDS_COMPAT = 4;
 
     /**
      * Set if the application needs to run in screen size compatibility mode.
      */
-    private static final int NEEDS_SCREEN_COMPAT = 256;
+    private static final int NEEDS_SCREEN_COMPAT = 8;
 
     /**
      * The effective screen density we have selected for this application.
@@ -110,77 +92,150 @@
      */
     public final float applicationInvertedScale;
 
-    public CompatibilityInfo(ApplicationInfo appInfo, int screenLayout, boolean forceCompat) {
+    public CompatibilityInfo(ApplicationInfo appInfo, int screenLayout, int sw,
+            boolean forceCompat) {
         int compatFlags = 0;
 
-        if ((appInfo.flags & ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS) != 0) {
-            compatFlags |= LARGE_SCREENS;
-            if (!forceCompat) {
-                // If we aren't forcing the app into compatibility mode, then
-                // assume if it supports large screens that we should allow it
-                // to use the full space of an xlarge screen as well.
-                compatFlags |= XLARGE_SCREENS | EXPANDABLE;
+        if (appInfo.requiresSmallestWidthDp != 0 || appInfo.compatibleWidthLimitDp != 0
+                || appInfo.largestWidthLimitDp != 0) {
+            // New style screen requirements spec.
+            int required = appInfo.requiresSmallestWidthDp != 0
+                    ? appInfo.requiresSmallestWidthDp
+                    : appInfo.compatibleWidthLimitDp;
+            if (required == 0) {
+                required = appInfo.largestWidthLimitDp;
             }
-        }
-        if ((appInfo.flags & ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS) != 0) {
-            compatFlags |= XLARGE_SCREENS | EXPANDABLE;
-        }
-        if ((appInfo.flags & ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS) != 0) {
-            compatFlags |= EXPANDABLE;
-        }
-
-        if (forceCompat) {
-            // If we are forcing compatibility mode, then ignore an app that
-            // just says it is resizable for screens.  We'll only have it fill
-            // the screen if it explicitly says it supports the screen size we
-            // are running in.
-            compatFlags &= ~EXPANDABLE;
-        }
-
-        boolean supportsScreen = false;
-        switch (screenLayout&Configuration.SCREENLAYOUT_SIZE_MASK) {
-            case Configuration.SCREENLAYOUT_SIZE_XLARGE:
-                if ((compatFlags&XLARGE_SCREENS) != 0) {
-                    supportsScreen = true;
-                }
-                if ((appInfo.flags & ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS) != 0) {
-                    compatFlags |= NEVER_COMPAT;
-                }
-                break;
-            case Configuration.SCREENLAYOUT_SIZE_LARGE:
-                if ((compatFlags&LARGE_SCREENS) != 0) {
-                    supportsScreen = true;
-                }
-                if ((appInfo.flags & ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS) != 0) {
-                    compatFlags |= NEVER_COMPAT;
-                }
-                break;
-        }
-
-        if ((screenLayout&Configuration.SCREENLAYOUT_COMPAT_NEEDED) != 0) {
-            if ((compatFlags&EXPANDABLE) != 0) {
-                supportsScreen = true;
-            } else if ((appInfo.flags & ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS) == 0) {
-                compatFlags |= ALWAYS_COMPAT;
+            int compat = appInfo.compatibleWidthLimitDp != 0
+                    ? appInfo.compatibleWidthLimitDp : required;
+            if (compat < required)  {
+                compat = required;
             }
-        }
+            int largest = appInfo.largestWidthLimitDp;
 
-        if (supportsScreen) {
-            compatFlags &= ~NEEDS_SCREEN_COMPAT;
-        } else {
-            compatFlags |= NEEDS_SCREEN_COMPAT;
-        }
-        
-        if ((appInfo.flags & ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES) != 0) {
+            if (required > DEFAULT_NORMAL_SHORT_DIMENSION) {
+                // For now -- if they require a size larger than the only
+                // size we can do in compatibility mode, then don't ever
+                // allow the app to go in to compat mode.  Trying to run
+                // it at a smaller size it can handle will make it far more
+                // broken than running at a larger size than it wants or
+                // thinks it can handle.
+                compatFlags |= NEVER_NEEDS_COMPAT;
+            } else if (largest != 0 && sw > largest) {
+                // If the screen size is larger than the largest size the
+                // app thinks it can work with, then always force it in to
+                // compatibility mode.
+                compatFlags |= NEEDS_SCREEN_COMPAT | ALWAYS_NEEDS_COMPAT;
+            } else if (compat >= sw) {
+                // The screen size is something the app says it was designed
+                // for, so never do compatibility mode.
+                compatFlags |= NEVER_NEEDS_COMPAT;
+            } else if (forceCompat) {
+                // The app may work better with or without compatibility mode.
+                // Let the user decide.
+                compatFlags |= NEEDS_SCREEN_COMPAT;
+            }
+
+            // Modern apps always support densities.
             applicationDensity = DisplayMetrics.DENSITY_DEVICE;
             applicationScale = 1.0f;
             applicationInvertedScale = 1.0f;
+
         } else {
-            applicationDensity = DisplayMetrics.DENSITY_DEFAULT;
-            applicationScale = DisplayMetrics.DENSITY_DEVICE
-                    / (float) DisplayMetrics.DENSITY_DEFAULT;
-            applicationInvertedScale = 1.0f / applicationScale;
-            compatFlags |= SCALING_REQUIRED;
+            /**
+             * Has the application said that its UI is expandable?  Based on the
+             * <supports-screen> android:expandible in the manifest.
+             */
+            final int EXPANDABLE = 2;
+
+            /**
+             * Has the application said that its UI supports large screens?  Based on the
+             * <supports-screen> android:largeScreens in the manifest.
+             */
+            final int LARGE_SCREENS = 8;
+
+            /**
+             * Has the application said that its UI supports xlarge screens?  Based on the
+             * <supports-screen> android:xlargeScreens in the manifest.
+             */
+            final int XLARGE_SCREENS = 32;
+
+            int sizeInfo = 0;
+
+            // We can't rely on the application always setting
+            // FLAG_RESIZEABLE_FOR_SCREENS so will compute it based on various input.
+            boolean anyResizeable = false;
+
+            if ((appInfo.flags & ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS) != 0) {
+                sizeInfo |= LARGE_SCREENS;
+                anyResizeable = true;
+                if (!forceCompat) {
+                    // If we aren't forcing the app into compatibility mode, then
+                    // assume if it supports large screens that we should allow it
+                    // to use the full space of an xlarge screen as well.
+                    sizeInfo |= XLARGE_SCREENS | EXPANDABLE;
+                }
+            }
+            if ((appInfo.flags & ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS) != 0) {
+                anyResizeable = true;
+                if (!forceCompat) {
+                    sizeInfo |= XLARGE_SCREENS | EXPANDABLE;
+                }
+            }
+            if ((appInfo.flags & ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS) != 0) {
+                anyResizeable = true;
+                sizeInfo |= EXPANDABLE;
+            }
+
+            if (forceCompat) {
+                // If we are forcing compatibility mode, then ignore an app that
+                // just says it is resizable for screens.  We'll only have it fill
+                // the screen if it explicitly says it supports the screen size we
+                // are running in.
+                sizeInfo &= ~EXPANDABLE;
+            }
+
+            compatFlags |= NEEDS_SCREEN_COMPAT;
+            switch (screenLayout&Configuration.SCREENLAYOUT_SIZE_MASK) {
+                case Configuration.SCREENLAYOUT_SIZE_XLARGE:
+                    if ((sizeInfo&XLARGE_SCREENS) != 0) {
+                        compatFlags &= ~NEEDS_SCREEN_COMPAT;
+                    }
+                    if ((appInfo.flags & ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS) != 0) {
+                        compatFlags |= NEVER_NEEDS_COMPAT;
+                    }
+                    break;
+                case Configuration.SCREENLAYOUT_SIZE_LARGE:
+                    if ((sizeInfo&LARGE_SCREENS) != 0) {
+                        compatFlags &= ~NEEDS_SCREEN_COMPAT;
+                    }
+                    if ((appInfo.flags & ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS) != 0) {
+                        compatFlags |= NEVER_NEEDS_COMPAT;
+                    }
+                    break;
+            }
+
+            if ((screenLayout&Configuration.SCREENLAYOUT_COMPAT_NEEDED) != 0) {
+                if ((sizeInfo&EXPANDABLE) != 0) {
+                    compatFlags &= ~NEEDS_SCREEN_COMPAT;
+                } else if (!anyResizeable) {
+                    compatFlags |= ALWAYS_NEEDS_COMPAT;
+                }
+            } else {
+                compatFlags &= ~NEEDS_SCREEN_COMPAT;
+                compatFlags |= NEVER_NEEDS_COMPAT;
+            }
+
+            if ((appInfo.flags & ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES) != 0) {
+                applicationDensity = DisplayMetrics.DENSITY_DEVICE;
+                applicationScale = 1.0f;
+                applicationInvertedScale = 1.0f;
+            } else {
+                applicationDensity = DisplayMetrics.DENSITY_DEFAULT;
+                applicationScale = DisplayMetrics.DENSITY_DEVICE
+                        / (float) DisplayMetrics.DENSITY_DEFAULT;
+                applicationInvertedScale = 1.0f / applicationScale;
+                compatFlags |= SCALING_REQUIRED;
+            }
         }
 
         mCompatibilityFlags = compatFlags;
@@ -195,8 +250,7 @@
     }
 
     private CompatibilityInfo() {
-        this(XLARGE_SCREENS | LARGE_SCREENS | EXPANDABLE,
-                DisplayMetrics.DENSITY_DEVICE,
+        this(NEVER_NEEDS_COMPAT, DisplayMetrics.DENSITY_DEVICE,
                 1.0f,
                 1.0f);
     }
@@ -205,7 +259,7 @@
      * @return true if the scaling is required
      */
     public boolean isScalingRequired() {
-        return (mCompatibilityFlags & SCALING_REQUIRED) != 0;
+        return (mCompatibilityFlags&SCALING_REQUIRED) != 0;
     }
     
     public boolean supportsScreen() {
@@ -213,16 +267,11 @@
     }
     
     public boolean neverSupportsScreen() {
-        return (mCompatibilityFlags&NEVER_COMPAT) != 0;
+        return (mCompatibilityFlags&ALWAYS_NEEDS_COMPAT) != 0;
     }
 
     public boolean alwaysSupportsScreen() {
-        return (mCompatibilityFlags&ALWAYS_COMPAT) != 0;
-    }
-
-    @Override
-    public String toString() {
-        return "CompatibilityInfo{scale=" + applicationScale + "}";
+        return (mCompatibilityFlags&NEVER_NEEDS_COMPAT) != 0;
     }
 
     /**
@@ -381,10 +430,10 @@
         if (!supportsScreen()) {
             // This is a larger screen device and the app is not
             // compatible with large screens, so diddle it.
-            CompatibilityInfo.updateCompatibleScreenFrame(inoutDm, null, inoutDm);
+            CompatibilityInfo.computeCompatibleScaling(inoutDm, inoutDm);
         } else {
-            inoutDm.widthPixels = inoutDm.realWidthPixels;
-            inoutDm.heightPixels = inoutDm.realHeightPixels;
+            inoutDm.widthPixels = inoutDm.unscaledWidthPixels;
+            inoutDm.heightPixels = inoutDm.unscaledHeightPixels;
         }
 
         if (isScalingRequired()) {
@@ -407,6 +456,9 @@
             inoutConfig.screenLayout =
                     (inoutConfig.screenLayout&~Configuration.SCREENLAYOUT_SIZE_MASK)
                     | Configuration.SCREENLAYOUT_SIZE_NORMAL;
+            inoutConfig.screenWidthDp = inoutConfig.compatScreenWidthDp;
+            inoutConfig.screenHeightDp = inoutConfig.compatScreenHeightDp;
+            inoutConfig.smallestScreenWidthDp = inoutConfig.compatSmallestScreenWidthDp;
         }
     }
 
@@ -418,10 +470,9 @@
      * @param outRect the output parameter which will contain the result.
      * @return Returns the scaling factor for the window.
      */
-    public static float updateCompatibleScreenFrame(DisplayMetrics dm,
-            Rect outRect, DisplayMetrics outDm) {
-        final int width = dm.realWidthPixels;
-        final int height = dm.realHeightPixels;
+    public static float computeCompatibleScaling(DisplayMetrics dm, DisplayMetrics outDm) {
+        final int width = dm.unscaledWidthPixels;
+        final int height = dm.unscaledHeightPixels;
         int shortSize, longSize;
         if (width < height) {
             shortSize = width;
@@ -452,12 +503,6 @@
             scale = 1;
         }
 
-        if (outRect != null) {
-            final int left = (int)((width-(newWidth*scale))/2);
-            final int top = (int)((height-(newHeight*scale))/2);
-            outRect.set(left, top, left+newWidth, top+newHeight);
-        }
-
         if (outDm != null) {
             outDm.widthPixels = newWidth;
             outDm.heightPixels = newHeight;
@@ -481,6 +526,28 @@
     }
 
     @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder(128);
+        sb.append("{");
+        sb.append(applicationDensity);
+        sb.append("dpi");
+        if (isScalingRequired()) {
+            sb.append(" scaling");
+        }
+        if (!supportsScreen()) {
+            sb.append(" resizing");
+        }
+        if (neverSupportsScreen()) {
+            sb.append(" never-compat");
+        }
+        if (alwaysSupportsScreen()) {
+            sb.append(" always-compat");
+        }
+        sb.append("}");
+        return sb.toString();
+    }
+
+    @Override
     public int hashCode() {
         int result = 17;
         result = 31 * result + mCompatibilityFlags;
diff --git a/core/java/android/content/res/Configuration.java b/core/java/android/content/res/Configuration.java
index d476997..a00f790 100644
--- a/core/java/android/content/res/Configuration.java
+++ b/core/java/android/content/res/Configuration.java
@@ -19,6 +19,7 @@
 import android.content.pm.ActivityInfo;
 import android.os.Parcel;
 import android.os.Parcelable;
+import android.util.LocaleUtil;
 
 import java.util.Locale;
 
@@ -269,6 +270,18 @@
      */
     public int smallestScreenWidthDp;
 
+    /** @hide Hack to get this information from WM to app running in compat mode. */
+    public int compatScreenWidthDp;
+    /** @hide Hack to get this information from WM to app running in compat mode. */
+    public int compatScreenHeightDp;
+    /** @hide Hack to get this information from WM to app running in compat mode. */
+    public int compatSmallestScreenWidthDp;
+
+    /**
+     * @hide The text layout direction associated to the current Locale
+     */
+    public int textLayoutDirection;
+
     /**
      * @hide Internal book-keeping.
      */
@@ -295,6 +308,7 @@
         mnc = o.mnc;
         if (o.locale != null) {
             locale = (Locale) o.locale.clone();
+            textLayoutDirection = o.textLayoutDirection;
         }
         userSetLocale = o.userSetLocale;
         touchscreen = o.touchscreen;
@@ -309,6 +323,9 @@
         screenWidthDp = o.screenWidthDp;
         screenHeightDp = o.screenHeightDp;
         smallestScreenWidthDp = o.smallestScreenWidthDp;
+        compatScreenWidthDp = o.compatScreenWidthDp;
+        compatScreenHeightDp = o.compatScreenHeightDp;
+        compatSmallestScreenWidthDp = o.compatSmallestScreenWidthDp;
         seq = o.seq;
     }
     
@@ -327,20 +344,25 @@
         } else {
             sb.append(" (no locale)");
         }
+        switch (textLayoutDirection) {
+            case LocaleUtil.TEXT_LAYOUT_DIRECTION_UNDEFINED_DO_NOT_USE: sb.append(" ?layoutdir"); break;
+            case LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE: sb.append(" rtl"); break;
+            default: sb.append(" layoutdir="); sb.append(textLayoutDirection); break;
+        }
         if (smallestScreenWidthDp != SMALLEST_SCREEN_WIDTH_DP_UNDEFINED) {
             sb.append(" sw"); sb.append(smallestScreenWidthDp); sb.append("dp");
         } else {
-            sb.append("?swdp");
+            sb.append(" ?swdp");
         }
         if (screenWidthDp != SCREEN_WIDTH_DP_UNDEFINED) {
             sb.append(" w"); sb.append(screenWidthDp); sb.append("dp");
         } else {
-            sb.append("?wdp");
+            sb.append(" ?wdp");
         }
         if (screenHeightDp != SCREEN_HEIGHT_DP_UNDEFINED) {
             sb.append(" h"); sb.append(screenHeightDp); sb.append("dp");
         } else {
-            sb.append("?hdp");
+            sb.append(" ?hdp");
         }
         switch ((screenLayout&SCREENLAYOUT_SIZE_MASK)) {
             case SCREENLAYOUT_SIZE_UNDEFINED: sb.append(" ?lsize"); break;
@@ -444,9 +466,10 @@
         orientation = ORIENTATION_UNDEFINED;
         screenLayout = SCREENLAYOUT_SIZE_UNDEFINED;
         uiMode = UI_MODE_TYPE_UNDEFINED;
-        screenWidthDp = SCREEN_WIDTH_DP_UNDEFINED;
-        screenHeightDp = SCREEN_HEIGHT_DP_UNDEFINED;
-        smallestScreenWidthDp = SMALLEST_SCREEN_WIDTH_DP_UNDEFINED;
+        screenWidthDp = compatScreenWidthDp = SCREEN_WIDTH_DP_UNDEFINED;
+        screenHeightDp = compatScreenHeightDp = SCREEN_HEIGHT_DP_UNDEFINED;
+        smallestScreenWidthDp = compatSmallestScreenWidthDp = SMALLEST_SCREEN_WIDTH_DP_UNDEFINED;
+        textLayoutDirection = LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE;
         seq = 0;
     }
 
@@ -482,6 +505,7 @@
             changed |= ActivityInfo.CONFIG_LOCALE;
             locale = delta.locale != null
                     ? (Locale) delta.locale.clone() : null;
+            textLayoutDirection = LocaleUtil.getLayoutDirectionFromLocale(locale);
         }
         if (delta.userSetLocale && (!userSetLocale || ((changed & ActivityInfo.CONFIG_LOCALE) != 0)))
         {
@@ -550,11 +574,18 @@
             changed |= ActivityInfo.CONFIG_SCREEN_SIZE;
             screenHeightDp = delta.screenHeightDp;
         }
-        if (delta.smallestScreenWidthDp != SMALLEST_SCREEN_WIDTH_DP_UNDEFINED
-                && smallestScreenWidthDp != delta.smallestScreenWidthDp) {
-            changed |= ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE;
+        if (delta.smallestScreenWidthDp != SMALLEST_SCREEN_WIDTH_DP_UNDEFINED) {
             smallestScreenWidthDp = delta.smallestScreenWidthDp;
         }
+        if (delta.compatScreenWidthDp != SCREEN_WIDTH_DP_UNDEFINED) {
+            compatScreenWidthDp = delta.compatScreenWidthDp;
+        }
+        if (delta.compatScreenHeightDp != SCREEN_HEIGHT_DP_UNDEFINED) {
+            compatScreenHeightDp = delta.compatScreenHeightDp;
+        }
+        if (delta.compatSmallestScreenWidthDp != SMALLEST_SCREEN_WIDTH_DP_UNDEFINED) {
+            compatSmallestScreenWidthDp = delta.compatSmallestScreenWidthDp;
+        }
         
         if (delta.seq != 0) {
             seq = delta.seq;
@@ -739,6 +770,10 @@
         dest.writeInt(screenWidthDp);
         dest.writeInt(screenHeightDp);
         dest.writeInt(smallestScreenWidthDp);
+        dest.writeInt(compatScreenWidthDp);
+        dest.writeInt(compatScreenHeightDp);
+        dest.writeInt(compatSmallestScreenWidthDp);
+        dest.writeInt(textLayoutDirection);
         dest.writeInt(seq);
     }
 
@@ -763,6 +798,10 @@
         screenWidthDp = source.readInt();
         screenHeightDp = source.readInt();
         smallestScreenWidthDp = source.readInt();
+        compatScreenWidthDp = source.readInt();
+        compatScreenHeightDp = source.readInt();
+        compatSmallestScreenWidthDp = source.readInt();
+        textLayoutDirection = source.readInt();
         seq = source.readInt();
     }
     
diff --git a/core/java/android/content/res/Resources.java b/core/java/android/content/res/Resources.java
index e63e7eb..bd8b1a4 100755
--- a/core/java/android/content/res/Resources.java
+++ b/core/java/android/content/res/Resources.java
@@ -28,14 +28,13 @@
 import android.graphics.drawable.Drawable.ConstantState;
 import android.os.Build;
 import android.os.Bundle;
-import android.os.SystemProperties;
 import android.util.AttributeSet;
 import android.util.DisplayMetrics;
 import android.util.Log;
+import android.util.Slog;
 import android.util.SparseArray;
 import android.util.TypedValue;
 import android.util.LongSparseArray;
-import android.view.Display;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -193,11 +192,7 @@
             Configuration config, CompatibilityInfo compInfo) {
         mAssets = assets;
         mMetrics.setToDefaults();
-        if (compInfo == null) {
-            mCompatibilityInfo = CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO;
-        } else {
-            mCompatibilityInfo = compInfo;
-        }
+        mCompatibilityInfo = compInfo;
         updateConfiguration(config, metrics);
         assets.ensureStringBlocks();
     }
@@ -1410,19 +1405,15 @@
     public void updateConfiguration(Configuration config,
             DisplayMetrics metrics, CompatibilityInfo compat) {
         synchronized (mTmpValue) {
+            if (false) {
+                Slog.i(TAG, "**** Updating config of " + this + ": old config is "
+                        + mConfiguration + " old compat is " + mCompatibilityInfo);
+                Slog.i(TAG, "**** Updating config of " + this + ": new config is "
+                        + config + " new compat is " + compat);
+            }
             if (compat != null) {
                 mCompatibilityInfo = compat;
             }
-            int configChanges = 0xfffffff;
-            if (config != null) {
-                mTmpConfig.setTo(config);
-                mCompatibilityInfo.applyToConfiguration(mTmpConfig);
-                configChanges = mConfiguration.updateFrom(mTmpConfig);
-                configChanges = ActivityInfo.activityInfoConfigToNative(configChanges);
-            }
-            if (mConfiguration.locale == null) {
-                mConfiguration.locale = Locale.getDefault();
-            }
             if (metrics != null) {
                 mMetrics.setTo(metrics);
                 // NOTE: We should re-arrange this code to create a Display
@@ -1434,9 +1425,29 @@
                 // it would be cleaner and more maintainble to just be
                 // consistently dealing with a compatible display everywhere in
                 // the framework.
+                if (mCompatibilityInfo != null) {
+                    mCompatibilityInfo.applyToDisplayMetrics(mMetrics);
+                }
+            }
+            if (mCompatibilityInfo != null) {
                 mCompatibilityInfo.applyToDisplayMetrics(mMetrics);
             }
             mMetrics.scaledDensity = mMetrics.density * mConfiguration.fontScale;
+            int configChanges = 0xfffffff;
+            if (config != null) {
+                mTmpConfig.setTo(config);
+                if (mCompatibilityInfo != null) {
+                    mCompatibilityInfo.applyToConfiguration(mTmpConfig);
+                }
+                if (mTmpConfig.locale == null) {
+                    mTmpConfig.locale = Locale.getDefault();
+                }
+                configChanges = mConfiguration.updateFrom(mTmpConfig);
+                configChanges = ActivityInfo.activityInfoConfigToNative(configChanges);
+            }
+            if (mConfiguration.locale == null) {
+                mConfiguration.locale = Locale.getDefault();
+            }
 
             String locale = null;
             if (mConfiguration.locale != null) {
@@ -1471,6 +1482,11 @@
                     mConfiguration.screenLayout, mConfiguration.uiMode,
                     Build.VERSION.RESOURCES_SDK_INT);
 
+            if (DEBUG_CONFIG) {
+                Slog.i(TAG, "**** Updating config of " + this + ": final config is " + mConfiguration
+                        + " final compat is " + mCompatibilityInfo);
+            }
+
             clearDrawableCache(mDrawableCache, configChanges);
             clearDrawableCache(mColorDrawableCache, configChanges);
 
@@ -1548,6 +1564,8 @@
      * @return The resource's current display metrics. 
      */
     public DisplayMetrics getDisplayMetrics() {
+        if (DEBUG_CONFIG) Slog.v(TAG, "Returning DisplayMetrics: " + mMetrics.widthPixels
+                + "x" + mMetrics.heightPixels + " " + mMetrics.density);
         return mMetrics;
     }
 
@@ -1565,11 +1583,12 @@
      * Return the compatibility mode information for the application.
      * The returned object should be treated as read-only.
      * 
-     * @return compatibility info. null if the app does not require compatibility mode.
+     * @return compatibility info.
      * @hide
      */
     public CompatibilityInfo getCompatibilityInfo() {
-        return mCompatibilityInfo;
+        return mCompatibilityInfo != null ? mCompatibilityInfo
+                : CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO;
     }
 
     /**
diff --git a/core/java/android/database/sqlite/SQLiteQueryBuilder.java b/core/java/android/database/sqlite/SQLiteQueryBuilder.java
index b6aca2b..8f8eb6e 100644
--- a/core/java/android/database/sqlite/SQLiteQueryBuilder.java
+++ b/core/java/android/database/sqlite/SQLiteQueryBuilder.java
@@ -24,8 +24,8 @@
 
 import java.util.Iterator;
 import java.util.Map;
-import java.util.Set;
 import java.util.Map.Entry;
+import java.util.Set;
 import java.util.regex.Pattern;
 
 /**
@@ -43,7 +43,7 @@
     private StringBuilder mWhereClause = null;  // lazily created
     private boolean mDistinct;
     private SQLiteDatabase.CursorFactory mFactory;
-    private boolean mStrictProjectionMap;
+    private boolean mStrict;
 
     public SQLiteQueryBuilder() {
         mDistinct = false;
@@ -145,10 +145,28 @@
     }
 
     /**
-     * @hide
+     * When set, the selection is verified against malicious arguments.
+     * When using this class to create a statement using
+     * {@link #buildQueryString(boolean, String, String[], String, String, String, String, String)},
+     * non-numeric limits will raise an exception. If a projection map is specified, fields
+     * not in that map will be ignored.
+     * If this class is used to execute the statement directly using
+     * {@link #query(SQLiteDatabase, String[], String, String[], String, String, String)}
+     * or
+     * {@link #query(SQLiteDatabase, String[], String, String[], String, String, String, String)},
+     * additionally also parenthesis escaping selection are caught.
+     *
+     * To summarize: To get maximum protection against malicious third party apps (for example
+     * content provider consumers), make sure to do the following:
+     * <ul>
+     * <li>Set this value to true</li>
+     * <li>Use a projection map</li>
+     * <li>Use one of the query overloads instead of getting the statement as a sql string</li>
+     * </ul>
+     * By default, this value is false.
      */
-    public void setStrictProjectionMap(boolean flag) {
-        mStrictProjectionMap = flag;
+    public void setStrict(boolean flag) {
+        mStrict = flag;
     }
 
     /**
@@ -217,13 +235,6 @@
         }
     }
 
-    private static void appendClauseEscapeClause(StringBuilder s, String name, String clause) {
-        if (!TextUtils.isEmpty(clause)) {
-            s.append(name);
-            DatabaseUtils.appendEscapedSQLString(s, clause);
-        }
-    }
-
     /**
      * Add the names that are non-null in columns to s, separating
      * them with commas.
@@ -320,6 +331,19 @@
             return null;
         }
 
+        if (mStrict && selection != null && selection.length() > 0) {
+            // Validate the user-supplied selection to detect syntactic anomalies
+            // in the selection string that could indicate a SQL injection attempt.
+            // The idea is to ensure that the selection clause is a valid SQL expression
+            // by compiling it twice: once wrapped in parentheses and once as
+            // originally specified. An attacker cannot create an expression that
+            // would escape the SQL expression while maintaining balanced parentheses
+            // in both the wrapped and original forms.
+            String sqlForValidation = buildQuery(projectionIn, "(" + selection + ")", groupBy,
+                    having, sortOrder, limit);
+            validateSql(db, sqlForValidation); // will throw if query is invalid
+        }
+
         String sql = buildQuery(
                 projectionIn, selection, groupBy, having,
                 sortOrder, limit);
@@ -329,7 +353,20 @@
         }
         return db.rawQueryWithFactory(
                 mFactory, sql, selectionArgs,
-                SQLiteDatabase.findEditTable(mTables));
+                SQLiteDatabase.findEditTable(mTables)); // will throw if query is invalid
+    }
+
+    /**
+     * Verifies that a SQL statement is valid by compiling it.
+     * If the SQL statement is not valid, this method will throw a {@link SQLiteException}.
+     */
+    private void validateSql(SQLiteDatabase db, String sql) {
+        db.lock(sql);
+        try {
+            new SQLiteCompiledSql(db, sql).releaseSqlStatement();
+        } finally {
+            db.unlock();
+        }
     }
 
     /**
@@ -541,7 +578,7 @@
                         continue;
                     }
 
-                    if (!mStrictProjectionMap &&
+                    if (!mStrict &&
                             ( userColumn.contains(" AS ") || userColumn.contains(" as "))) {
                         /* A column alias already exist */
                         projection[i] = userColumn;
diff --git a/core/java/android/hardware/Camera.java b/core/java/android/hardware/Camera.java
index d5c4ace..338e6c8 100644
--- a/core/java/android/hardware/Camera.java
+++ b/core/java/android/hardware/Camera.java
@@ -16,22 +16,22 @@
 
 package android.hardware;
 
-import java.lang.ref.WeakReference;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.StringTokenizer;
-import java.io.IOException;
-
-import android.util.Log;
-import android.view.Surface;
-import android.view.SurfaceHolder;
 import android.graphics.ImageFormat;
 import android.graphics.Rect;
 import android.graphics.SurfaceTexture;
 import android.os.Handler;
 import android.os.Looper;
 import android.os.Message;
+import android.util.Log;
+import android.view.Surface;
+import android.view.SurfaceHolder;
+
+import java.io.IOException;
+import java.lang.ref.WeakReference;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.StringTokenizer;
 
 /**
  * The Camera class is used to set image capture settings, start/stop preview,
@@ -173,16 +173,16 @@
         public int facing;
 
         /**
-         * The orientation of the camera image. The value is the angle that the
+         * <p>The orientation of the camera image. The value is the angle that the
          * camera image needs to be rotated clockwise so it shows correctly on
-         * the display in its natural orientation. It should be 0, 90, 180, or 270.
+         * the display in its natural orientation. It should be 0, 90, 180, or 270.</p>
          *
-         * For example, suppose a device has a naturally tall screen. The
+         * <p>For example, suppose a device has a naturally tall screen. The
          * back-facing camera sensor is mounted in landscape. You are looking at
          * the screen. If the top side of the camera sensor is aligned with the
          * right edge of the screen in natural orientation, the value should be
          * 90. If the top side of a front-facing camera sensor is aligned with
-         * the right of the screen, the value should be 270.
+         * the right of the screen, the value should be 270.</p>
          *
          * @see #setDisplayOrientation(int)
          * @see Parameters#setRotation(int)
@@ -216,7 +216,9 @@
      *     {@link #getNumberOfCameras()}-1.
      * @return a new Camera object, connected, locked and ready for use.
      * @throws RuntimeException if connection to the camera service fails (for
-     *     example, if the camera is in use by another process).
+     *     example, if the camera is in use by another process or device policy
+     *     manager has disabled the camera).
+     * @see android.app.admin.DevicePolicyManager#getCameraDisabled(android.content.ComponentName)
      */
     public static Camera open(int cameraId) {
         return new Camera(cameraId);
@@ -375,7 +377,7 @@
      * The preview surface texture may not otherwise change while preview is
      * running.
      *
-     * The timestamps provided by {@link SurfaceTexture#getTimestamp()} for a
+     * <p>The timestamps provided by {@link SurfaceTexture#getTimestamp()} for a
      * SurfaceTexture set as the preview texture have an unspecified zero point,
      * and cannot be directly compared between different cameras or different
      * instances of the same camera, or across multiple runs of the same
@@ -561,12 +563,12 @@
      * is used while calling {@link #takePicture(Camera.ShutterCallback,
      * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)}.
      *
-     * Please note that by calling this method, the mode for application-managed
-     * callback buffers is triggered. If this method has never been called,
-     * null will be returned by the raw image callback since there is
-     * no image callback buffer available. Furthermore, When a supplied buffer
-     * is too small to hold the raw image data, raw image callback will return
-     * null and the buffer will be removed from the buffer queue.
+     * <p>Please note that by calling this method, the mode for
+     * application-managed callback buffers is triggered. If this method has
+     * never been called, null will be returned by the raw image callback since
+     * there is no image callback buffer available. Furthermore, When a supplied
+     * buffer is too small to hold the raw image data, raw image callback will
+     * return null and the buffer will be removed from the buffer queue.
      *
      * @param callbackBuffer the buffer to add to the raw image callback buffer
      *     queue. The size should be width * height * (bits per pixel) / 8. An
@@ -834,8 +836,6 @@
      * @param raw       the callback for raw (uncompressed) image data, or null
      * @param postview  callback with postview image data, may be null
      * @param jpeg      the callback for JPEG image data, or null
-     *
-     * @see #addRawImageCallbackBuffer(byte[])
      */
     public final void takePicture(ShutterCallback shutter, PictureCallback raw,
             PictureCallback postview, PictureCallback jpeg) {
@@ -1084,17 +1084,42 @@
     };
 
     /**
-     * Area class for focus.
+     * <p>The Area class is used for choosing specific metering and focus areas for
+     * the camera to use when calculating auto-exposure, auto-white balance, and
+     * auto-focus.</p>
      *
-     * @see #setFocusAreas(List)
-     * @see #getFocusAreas()
+     * <p>To find out how many simultaneous areas a given camera supports, use
+     * {@link Parameters#getMaxNumMeteringAreas()} and
+     * {@link Parameters#getMaxNumFocusAreas()}. If metering or focusing area
+     * selection is unsupported, these methods will return 0.</p>
+     *
+     * <p>Each Area consists of a rectangle specifying its bounds, and a weight
+     * that determines its importance. The bounds are relative to the camera's
+     * current field of view. The coordinates are mapped so that (-1000, -1000)
+     * is always the top-left corner of the current field of view, and (1000,
+     * 1000) is always the bottom-right corner of the current field of
+     * view. Setting Areas with bounds outside that range is not allowed. Areas
+     * with zero or negative width or height are not allowed.</p>
+     *
+     * <p>The weight must range from 1 to 1000, and represents a weight for
+     * every pixel in the area. This means that a large metering area with
+     * the same weight as a smaller area will have more effect in the
+     * metering result.  Metering areas can overlap and the driver
+     * will add the weights in the overlap region.</p>
+     *
+     * @see Parameters#setFocusAreas(List)
+     * @see Parameters#getFocusAreas()
+     * @see Parameters#getMaxNumFocusAreas()
+     * @see Parameters#setMeteringAreas(List)
+     * @see Parameters#getMeteringAreas()
+     * @see Parameters#getMaxNumMeteringAreas()
      */
     public static class Area {
         /**
          * Create an area with specified rectangle and weight.
          *
-         * @param rect the rectangle of the area
-         * @param weight the weight of the area
+         * @param rect the bounds of the area.
+         * @param weight the weight of the area.
          */
         public Area(Rect rect, int weight) {
             this.rect = rect;
@@ -1121,12 +1146,30 @@
             return weight == a.weight;
         }
 
-        /** rectangle of the area */
+        /**
+         * Bounds of the area. (-1000, -1000) represents the top-left of the
+         * camera field of view, and (1000, 1000) represents the bottom-right of
+         * the field of view. Setting bounds outside that range is not
+         * allowed. Bounds with zero or negative width or height are not
+         * allowed.
+         *
+         * @see Parameters#getFocusAreas()
+         * @see Parameters#getMeteringAreas()
+         */
         public Rect rect;
 
-        /** weight of the area */
+        /**
+         * Weight of the area. The weight must range from 1 to 1000, and
+         * represents a weight for every pixel in the area. This means that a
+         * large metering area with the same weight as a smaller area will have
+         * more effect in the metering result.  Metering areas can overlap and
+         * the driver will add the weights in the overlap region.
+         *
+         * @see Parameters#getFocusAreas()
+         * @see Parameters#getMeteringAreas()
+         */
         public int weight;
-    };
+    }
 
     /**
      * Camera service settings.
@@ -1620,15 +1663,15 @@
         }
 
         /**
-         * Gets the supported video frame sizes that can be used by
-         * MediaRecorder.
+         * <p>Gets the supported video frame sizes that can be used by
+         * MediaRecorder.</p>
          *
-         * If the returned list is not null, the returned list will contain at
+         * <p>If the returned list is not null, the returned list will contain at
          * least one Size and one of the sizes in the returned list must be
          * passed to MediaRecorder.setVideoSize() for camcorder application if
          * camera is used as the video source. In this case, the size of the
          * preview can be different from the resolution of the recorded video
-         * during video recording.
+         * during video recording.</p>
          *
          * @return a list of Size object if camera has separate preview and
          *         video output; otherwise, null is returned.
@@ -1660,12 +1703,12 @@
         }
 
         /**
-         * Sets the dimensions for EXIF thumbnail in Jpeg picture. If
+         * <p>Sets the dimensions for EXIF thumbnail in Jpeg picture. If
          * applications set both width and height to 0, EXIF will not contain
-         * thumbnail.
+         * thumbnail.</p>
          *
-         * Applications need to consider the display orientation. See {@link
-         * #setPreviewSize(int,int)} for reference.
+         * <p>Applications need to consider the display orientation. See {@link
+         * #setPreviewSize(int,int)} for reference.</p>
          *
          * @param width  the width of the thumbnail, in pixels
          * @param height the height of the thumbnail, in pixels
@@ -1885,10 +1928,10 @@
         }
 
         /**
-         * Sets the dimensions for pictures.
+         * <p>Sets the dimensions for pictures.</p>
          *
-         * Applications need to consider the display orientation. See {@link
-         * #setPreviewSize(int,int)} for reference.
+         * <p>Applications need to consider the display orientation. See {@link
+         * #setPreviewSize(int,int)} for reference.</p>
          *
          * @param width  the width for pictures, in pixels
          * @param height the height for pictures, in pixels
@@ -2714,26 +2757,26 @@
         }
 
         /**
-         * Gets the distances from the camera to where an object appears to be
+         * <p>Gets the distances from the camera to where an object appears to be
          * in focus. The object is sharpest at the optimal focus distance. The
-         * depth of field is the far focus distance minus near focus distance.
+         * depth of field is the far focus distance minus near focus distance.</p>
          *
-         * Focus distances may change after calling {@link
+         * <p>Focus distances may change after calling {@link
          * #autoFocus(AutoFocusCallback)}, {@link #cancelAutoFocus}, or {@link
          * #startPreview()}. Applications can call {@link #getParameters()}
          * and this method anytime to get the latest focus distances. If the
          * focus mode is FOCUS_MODE_CONTINUOUS_VIDEO, focus distances may change
-         * from time to time.
+         * from time to time.</p>
          *
-         * This method is intended to estimate the distance between the camera
+         * <p>This method is intended to estimate the distance between the camera
          * and the subject. After autofocus, the subject distance may be within
          * near and far focus distance. However, the precision depends on the
          * camera hardware, autofocus algorithm, the focus area, and the scene.
-         * The error can be large and it should be only used as a reference.
+         * The error can be large and it should be only used as a reference.</p>
          *
-         * Far focus distance >= optimal focus distance >= near focus distance.
+         * <p>Far focus distance >= optimal focus distance >= near focus distance.
          * If the focus distance is infinity, the value will be
-         * Float.POSITIVE_INFINITY.
+         * {@code Float.POSITIVE_INFINITY}.</p>
          *
          * @param output focus distances in meters. output must be a float
          *        array with three elements. Near focus distance, optimal focus
@@ -2763,42 +2806,43 @@
         }
 
         /**
-         * Gets the current focus areas. Camera driver uses the areas to decide
-         * focus.
+         * <p>Gets the current focus areas. Camera driver uses the areas to decide
+         * focus.</p>
          *
-         * Before using this API or {@link #setFocusAreas(List)}, apps should
+         * <p>Before using this API or {@link #setFocusAreas(List)}, apps should
          * call {@link #getMaxNumFocusAreas()} to know the maximum number of
-         * focus areas first. If the value is 0, focus area is not supported.
+         * focus areas first. If the value is 0, focus area is not supported.</p>
          *
-         * Each focus area is a rectangle with specified weight. The direction
+         * <p>Each focus area is a rectangle with specified weight. The direction
          * is relative to the sensor orientation, that is, what the sensor sees.
          * The direction is not affected by the rotation or mirroring of
          * {@link #setDisplayOrientation(int)}. Coordinates of the rectangle
          * range from -1000 to 1000. (-1000, -1000) is the upper left point.
-         * (1000, 1000) is the lower right point. The length and width of focus
-         * areas cannot be 0 or negative.
+         * (1000, 1000) is the lower right point. The width and height of focus
+         * areas cannot be 0 or negative.</p>
          *
-         * The weight must range from 1 to 1000. The weight should be
+         * <p>The weight must range from 1 to 1000. The weight should be
          * interpreted as a per-pixel weight - all pixels in the area have the
          * specified weight. This means a small area with the same weight as a
          * larger area will have less influence on the focusing than the larger
          * area. Focus areas can partially overlap and the driver will add the
-         * weights in the overlap region.
+         * weights in the overlap region.</p>
          *
-         * A special case of null focus area means driver to decide the focus
-         * area. For example, the driver may use more signals to decide focus
-         * areas and change them dynamically. Apps can set all-zero if they want
-         * the driver to decide focus areas.
+         * <p>A special case of a {@code null} focus area list means the driver is
+         * free to select focus targets as it wants. For example, the driver may
+         * use more signals to select focus areas and change them
+         * dynamically. Apps can set the focus area list to {@code null} if they
+         * want the driver to completely control focusing.</p>
          *
-         * Focus areas are relative to the current field of view
+         * <p>Focus areas are relative to the current field of view
          * ({@link #getZoom()}). No matter what the zoom level is, (-1000,-1000)
          * represents the top of the currently visible camera frame. The focus
          * area cannot be set to be outside the current field of view, even
-         * when using zoom.
+         * when using zoom.</p>
          *
-         * Focus area only has effect if the current focus mode is
+         * <p>Focus area only has effect if the current focus mode is
          * {@link #FOCUS_MODE_AUTO}, {@link #FOCUS_MODE_MACRO}, or
-         * {@link #FOCUS_MODE_CONTINUOUS_VIDEO}.
+         * {@link #FOCUS_MODE_CONTINUOUS_VIDEO}.</p>
          *
          * @return a list of current focus areas
          */
@@ -2829,41 +2873,42 @@
         }
 
         /**
-         * Gets the current metering areas. Camera driver uses these areas to
-         * decide exposure.
+         * <p>Gets the current metering areas. Camera driver uses these areas to
+         * decide exposure.</p>
          *
-         * Before using this API or {@link #setMeteringAreas(List)}, apps should
+         * <p>Before using this API or {@link #setMeteringAreas(List)}, apps should
          * call {@link #getMaxNumMeteringAreas()} to know the maximum number of
          * metering areas first. If the value is 0, metering area is not
-         * supported.
+         * supported.</p>
          *
-         * Each metering area is a rectangle with specified weight. The
+         * <p>Each metering area is a rectangle with specified weight. The
          * direction is relative to the sensor orientation, that is, what the
          * sensor sees. The direction is not affected by the rotation or
          * mirroring of {@link #setDisplayOrientation(int)}. Coordinates of the
          * rectangle range from -1000 to 1000. (-1000, -1000) is the upper left
-         * point. (1000, 1000) is the lower right point. The length and width of
-         * metering areas cannot be 0 or negative.
+         * point. (1000, 1000) is the lower right point. The width and height of
+         * metering areas cannot be 0 or negative.</p>
          *
-         * The weight must range from 1 to 1000, and represents a weight for
+         * <p>The weight must range from 1 to 1000, and represents a weight for
          * every pixel in the area. This means that a large metering area with
          * the same weight as a smaller area will have more effect in the
          * metering result.  Metering areas can partially overlap and the driver
-         * will add the weights in the overlap region.
+         * will add the weights in the overlap region.</p>
          *
-         * A special case of null metering area means driver to decide the
-         * metering area. For example, the driver may use more signals to decide
-         * metering areas and change them dynamically. Apps can set all-zero if
-         * they want the driver to decide metering areas.
+         * <p>A special case of a {@code null} metering area list means the driver
+         * is free to meter as it chooses. For example, the driver may use more
+         * signals to select metering areas and change them dynamically. Apps
+         * can set the metering area list to {@code null} if they want the
+         * driver to completely control metering.</p>
          *
-         * Metering areas are relative to the current field of view
+         * <p>Metering areas are relative to the current field of view
          * ({@link #getZoom()}). No matter what the zoom level is, (-1000,-1000)
          * represents the top of the currently visible camera frame. The
          * metering area cannot be set to be outside the current field of view,
-         * even when using zoom.
+         * even when using zoom.</p>
          *
-         * No matter what metering areas are, the final exposure are compensated
-         * by {@link #setExposureCompensation(int)}.
+         * <p>No matter what metering areas are, the final exposure are compensated
+         * by {@link #setExposureCompensation(int)}.</p>
          *
          * @return a list of current metering areas
          */
@@ -3033,7 +3078,7 @@
             if (result.size() == 0) return null;
 
             if (result.size() == 1) {
-                Area area = (Area) result.get(0);
+                Area area = result.get(0);
                 Rect rect = area.rect;
                 if (rect.left == 0 && rect.top == 0 && rect.right == 0
                         && rect.bottom == 0 && area.weight == 0) {
diff --git a/core/java/android/hardware/usb/IUsbManager.aidl b/core/java/android/hardware/usb/IUsbManager.aidl
index 5df2343..2b9c082 100644
--- a/core/java/android/hardware/usb/IUsbManager.aidl
+++ b/core/java/android/hardware/usb/IUsbManager.aidl
@@ -81,4 +81,13 @@
 
     /* Clears default preferences and permissions for the package */
     void clearDefaults(String packageName);
+
+    /* Sets the current primary USB function. */
+    void setPrimaryFunction(String functions);
+
+    /* Sets the default primary USB function. */
+    void setDefaultFunction(String functions);
+
+    /* Sets the file path for USB mass storage backing file. */
+    void setMassStorageBackingFile(String path);
 }
diff --git a/core/java/android/hardware/usb/UsbManager.java b/core/java/android/hardware/usb/UsbManager.java
index 60b37a1..a828a23 100644
--- a/core/java/android/hardware/usb/UsbManager.java
+++ b/core/java/android/hardware/usb/UsbManager.java
@@ -22,12 +22,9 @@
 import android.os.Bundle;
 import android.os.ParcelFileDescriptor;
 import android.os.RemoteException;
+import android.os.SystemProperties;
 import android.util.Log;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
 import java.util.HashMap;
 
 /**
@@ -50,11 +47,20 @@
      * This is a sticky broadcast for clients that includes USB connected/disconnected state,
      * <ul>
      * <li> {@link #USB_CONNECTED} boolean indicating whether USB is connected or disconnected.
-     * <li> {@link #USB_CONFIGURATION} a Bundle containing name/value pairs where the name
-     * is the name of a USB function and the value is either {@link #USB_FUNCTION_ENABLED}
-     * or {@link #USB_FUNCTION_DISABLED}.  The possible function names include
-     * {@link #USB_FUNCTION_MASS_STORAGE}, {@link #USB_FUNCTION_ADB}, {@link #USB_FUNCTION_RNDIS},
-     * {@link #USB_FUNCTION_MTP} and {@link #USB_FUNCTION_ACCESSORY}.
+     * <li> {@link #USB_CONFIGURED} boolean indicating whether USB is configured.
+     * currently zero if not configured, one for configured.
+     * <li> {@link #USB_FUNCTION_MASS_STORAGE} boolean extra indicating whether the
+     * mass storage function is enabled
+     * <li> {@link #USB_FUNCTION_ADB} boolean extra indicating whether the
+     * adb function is enabled
+     * <li> {@link #USB_FUNCTION_RNDIS} boolean extra indicating whether the
+     * RNDIS ethernet function is enabled
+     * <li> {@link #USB_FUNCTION_MTP} boolean extra indicating whether the
+     * MTP function is enabled
+     * <li> {@link #USB_FUNCTION_PTP} boolean extra indicating whether the
+     * PTP function is enabled
+     * <li> {@link #USB_FUNCTION_PTP} boolean extra indicating whether the
+     * accessory function is enabled
      * </ul>
      *
      * {@hide}
@@ -119,12 +125,12 @@
     public static final String USB_CONNECTED = "connected";
 
     /**
-     * Integer extra containing currently set USB configuration.
+     * Boolean extra indicating whether USB is configured.
      * Used in extras for the {@link #ACTION_USB_STATE} broadcast.
      *
      * {@hide}
      */
-    public static final String USB_CONFIGURATION = "configuration";
+    public static final String USB_CONFIGURED = "configured";
 
     /**
      * Name of the USB mass storage USB function.
@@ -159,6 +165,14 @@
     public static final String USB_FUNCTION_MTP = "mtp";
 
     /**
+     * Name of the PTP USB function.
+     * Used in extras for the {@link #ACTION_USB_STATE} broadcast
+     *
+     * {@hide}
+     */
+    public static final String USB_FUNCTION_PTP = "ptp";
+
+    /**
      * Name of the Accessory USB function.
      * Used in extras for the {@link #ACTION_USB_STATE} broadcast
      *
@@ -167,24 +181,6 @@
     public static final String USB_FUNCTION_ACCESSORY = "accessory";
 
     /**
-     * Value indicating that a USB function is enabled.
-     * Used in {@link #USB_CONFIGURATION} extras bundle for the
-     * {@link #ACTION_USB_STATE} broadcast
-     *
-     * {@hide}
-     */
-    public static final String USB_FUNCTION_ENABLED = "enabled";
-
-    /**
-     * Value indicating that a USB function is disabled.
-     * Used in {@link #USB_CONFIGURATION} extras bundle for the
-     * {@link #ACTION_USB_STATE} broadcast
-     *
-     * {@hide}
-     */
-    public static final String USB_FUNCTION_DISABLED = "disabled";
-
-    /**
      * Name of extra for {@link #ACTION_USB_DEVICE_ATTACHED} and
      * {@link #ACTION_USB_DEVICE_DETACHED} broadcasts
      * containing the UsbDevice object for the device.
@@ -389,21 +385,14 @@
         }
     }
 
-    private static File getFunctionEnableFile(String function) {
-        return new File("/sys/class/usb_composite/" + function + "/enable");
-    }
-
-    /**
-     * Returns true if the specified USB function is supported by the kernel.
-     * Note that a USB function maybe supported but disabled.
-     *
-     * @param function name of the USB function
-     * @return true if the USB function is supported.
-     *
-     * {@hide}
-     */
-    public static boolean isFunctionSupported(String function) {
-        return getFunctionEnableFile(function).exists();
+    private static boolean propertyContainsFunction(String property, String function) {
+        String functions = SystemProperties.get(property, "");
+        int index = functions.indexOf(function);
+        if (index < 0) return false;
+        if (index > 0 && functions.charAt(index - 1) != ',') return false;
+        int charAfter = index + function.length();
+        if (charAfter < functions.length() && functions.charAt(charAfter) != ',') return false;
+        return true;
     }
 
     /**
@@ -414,30 +403,52 @@
      *
      * {@hide}
      */
-    public static boolean isFunctionEnabled(String function) {
+    public boolean isFunctionEnabled(String function) {
+        return propertyContainsFunction("sys.usb.config", function);
+    }
+
+    /**
+     * Sets the primary USB function.
+     *
+     * @param function name of the USB function
+     *
+     * {@hide}
+     */
+    public void setPrimaryFunction(String function) {
         try {
-            FileInputStream stream = new FileInputStream(getFunctionEnableFile(function));
-            boolean enabled = (stream.read() == '1');
-            stream.close();
-            return enabled;
-        } catch (IOException e) {
-            return false;
+            mService.setPrimaryFunction(function);
+        } catch (RemoteException e) {
+            Log.e(TAG, "RemoteException in setPrimaryFunction", e);
         }
     }
 
     /**
-     * Enables or disables a USB function.
+     * Sets the default primary USB function.
+     *
+     * @param function name of the USB function
      *
      * {@hide}
      */
-    public static boolean setFunctionEnabled(String function, boolean enable) {
+    public void setDefaultFunction(String function) {
         try {
-            FileOutputStream stream = new FileOutputStream(getFunctionEnableFile(function));
-            stream.write(enable ? '1' : '0');
-            stream.close();
-            return true;
-        } catch (IOException e) {
-            return false;
+            mService.setDefaultFunction(function);
+        } catch (RemoteException e) {
+            Log.e(TAG, "RemoteException in setDefaultFunction", e);
+        }
+    }
+
+    /**
+     * Sets the file path for USB mass storage backing file.
+     *
+     * @param path backing file path
+     *
+     * {@hide}
+     */
+    public void setMassStorageBackingFile(String path) {
+        try {
+            mService.setMassStorageBackingFile(path);
+        } catch (RemoteException e) {
+            Log.e(TAG, "RemoteException in setDefaultFunction", e);
         }
     }
 }
diff --git a/core/java/android/inputmethodservice/ExtractButton.java b/core/java/android/inputmethodservice/ExtractButton.java
index f91cd4e..b6b7595 100644
--- a/core/java/android/inputmethodservice/ExtractButton.java
+++ b/core/java/android/inputmethodservice/ExtractButton.java
@@ -41,6 +41,6 @@
      * highlight when selected.
      */
     @Override public boolean hasWindowFocus() {
-        return this.isEnabled() ? true : false;
+        return isEnabled() && getVisibility() == VISIBLE ? true : false;
     }
 }
diff --git a/core/java/android/inputmethodservice/ExtractEditLayout.java b/core/java/android/inputmethodservice/ExtractEditLayout.java
new file mode 100644
index 0000000..eafff49
--- /dev/null
+++ b/core/java/android/inputmethodservice/ExtractEditLayout.java
@@ -0,0 +1,183 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.inputmethodservice;
+
+import com.android.internal.view.menu.MenuBuilder;
+import com.android.internal.view.menu.MenuPopupHelper;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.ActionMode;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.Button;
+import android.widget.LinearLayout;
+
+/**
+ * ExtractEditLayout provides an ActionMode presentation for the
+ * limited screen real estate in extract mode.
+ *
+ * @hide
+ */
+public class ExtractEditLayout extends LinearLayout {
+    ExtractActionMode mActionMode;
+    Button mExtractActionButton;
+    Button mEditButton;
+
+    public ExtractEditLayout(Context context) {
+        super(context);
+    }
+
+    public ExtractEditLayout(Context context, AttributeSet attrs) {
+        super(context, attrs);
+    }
+
+    @Override
+    public ActionMode startActionModeForChild(View sourceView, ActionMode.Callback cb) {
+        final ExtractActionMode mode = new ExtractActionMode(cb);
+        if (mode.dispatchOnCreate()) {
+            mode.invalidate();
+            mExtractActionButton.setVisibility(INVISIBLE);
+            mEditButton.setVisibility(VISIBLE);
+            mActionMode = mode;
+            return mode;
+        }
+        return null;
+    }
+
+    @Override
+    public void onFinishInflate() {
+        super.onFinishInflate();
+        mExtractActionButton = (Button) findViewById(com.android.internal.R.id.inputExtractAction);
+        mEditButton = (Button) findViewById(com.android.internal.R.id.inputExtractEditButton);
+        mEditButton.setOnClickListener(new OnClickListener() {
+            public void onClick(View clicked) {
+                if (mActionMode != null) {
+                    new MenuPopupHelper(getContext(), mActionMode.mMenu, clicked).show();
+                }
+            }
+        });
+    }
+
+    private class ExtractActionMode extends ActionMode implements MenuBuilder.Callback {
+        private ActionMode.Callback mCallback;
+        MenuBuilder mMenu;
+
+        public ExtractActionMode(Callback cb) {
+            mMenu = new MenuBuilder(getContext());
+            mMenu.setCallback(this);
+            mCallback = cb;
+        }
+
+        @Override
+        public void setTitle(CharSequence title) {
+            // Title will not be shown.
+        }
+
+        @Override
+        public void setTitle(int resId) {
+            // Title will nor be shown.
+        }
+
+        @Override
+        public void setSubtitle(CharSequence subtitle) {
+            // Subtitle will not be shown.
+        }
+
+        @Override
+        public void setSubtitle(int resId) {
+            // Subtitle will not be shown.
+        }
+
+        @Override
+        public void setCustomView(View view) {
+            // Custom view is not supported here.
+        }
+
+        @Override
+        public void invalidate() {
+            mMenu.stopDispatchingItemsChanged();
+            try {
+                mCallback.onPrepareActionMode(this, mMenu);
+            } finally {
+                mMenu.startDispatchingItemsChanged();
+            }
+        }
+
+        public boolean dispatchOnCreate() {
+            mMenu.stopDispatchingItemsChanged();
+            try {
+                return mCallback.onCreateActionMode(this, mMenu);
+            } finally {
+                mMenu.startDispatchingItemsChanged();
+            }
+        }
+
+        @Override
+        public void finish() {
+            if (mActionMode != this) {
+                // Not the active action mode - no-op
+                return;
+            }
+
+            mCallback.onDestroyActionMode(this);
+            mCallback = null;
+
+            mExtractActionButton.setVisibility(VISIBLE);
+            mEditButton.setVisibility(INVISIBLE);
+
+            mActionMode = null;
+        }
+
+        @Override
+        public Menu getMenu() {
+            return mMenu;
+        }
+
+        @Override
+        public CharSequence getTitle() {
+            return null;
+        }
+
+        @Override
+        public CharSequence getSubtitle() {
+            return null;
+        }
+
+        @Override
+        public View getCustomView() {
+            return null;
+        }
+
+        @Override
+        public MenuInflater getMenuInflater() {
+            return new MenuInflater(getContext());
+        }
+
+        @Override
+        public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) {
+            return mCallback.onActionItemClicked(this, item);
+        }
+
+        @Override
+        public void onMenuModeChange(MenuBuilder menu) {
+        }
+
+    }
+}
diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java
index 419288b..2242e9e 100644
--- a/core/java/android/net/ConnectivityManager.java
+++ b/core/java/android/net/ConnectivityManager.java
@@ -19,10 +19,10 @@
 import android.annotation.SdkConstant;
 import android.annotation.SdkConstant.SdkConstantType;
 import android.os.Binder;
+import android.os.ParcelFileDescriptor;
 import android.os.RemoteException;
 
 import java.net.InetAddress;
-import java.net.UnknownHostException;
 
 /**
  * Class that answers queries about the state of network connectivity. It also
@@ -40,8 +40,9 @@
  * state of the available networks</li>
  * </ol>
  */
-public class ConnectivityManager
-{
+public class ConnectivityManager {
+    private static final String TAG = "ConnectivityManager";
+
     /**
      * A change in network connectivity has occurred. A connection has either
      * been established or lost. The NetworkInfo for the affected network is
@@ -109,7 +110,7 @@
      * The lookup key for an int that provides information about
      * our connection to the internet at large.  0 indicates no connection,
      * 100 indicates a great connection.  Retrieve it with
-     * {@link android.content.Intent@getIntExtra(String)}.
+     * {@link android.content.Intent#getIntExtra(String, int)}.
      * {@hide}
      */
     public static final String EXTRA_INET_CONDITION = "inetCondition";
@@ -120,13 +121,12 @@
      * <p>
      * If an application uses the network in the background, it should listen
      * for this broadcast and stop using the background data if the value is
-     * false.
+     * {@code false}.
      */
     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
     public static final String ACTION_BACKGROUND_DATA_SETTING_CHANGED =
             "android.net.conn.BACKGROUND_DATA_SETTING_CHANGED";
 
-
     /**
      * Broadcast Action: The network connection may not be good
      * uses {@code ConnectivityManager.EXTRA_INET_CONDITION} and
@@ -165,14 +165,12 @@
 
     /**
      * The Default Mobile data connection.  When active, all data traffic
-     * will use this connection by default.  Should not coexist with other
-     * default connections.
+     * will use this connection by default.
      */
     public static final int TYPE_MOBILE      = 0;
     /**
      * The Default WIFI data connection.  When active, all data traffic
-     * will use this connection by default.  Should not coexist with other
-     * default connections.
+     * will use this connection by default.
      */
     public static final int TYPE_WIFI        = 1;
     /**
@@ -208,13 +206,13 @@
     public static final int TYPE_MOBILE_HIPRI = 5;
     /**
      * The Default WiMAX data connection.  When active, all data traffic
-     * will use this connection by default.  Should not coexist with other
-     * default connections.
+     * will use this connection by default.
      */
     public static final int TYPE_WIMAX       = 6;
 
     /**
-     * Bluetooth data connection. This is used for Bluetooth reverse tethering.
+     * The Default Bluetooth data connection. When active, all data traffic
+     * will use this connection by default.
      */
     public static final int TYPE_BLUETOOTH   = 7;
 
@@ -224,8 +222,8 @@
     public static final int TYPE_DUMMY       = 8;
 
     /**
-     * Ethernet data connection.  This may be via USB dongle or more
-     * traditional means.
+     * The Default Ethernet data connection.  When active, all data traffic
+     * will use this connection by default.
      */
     public static final int TYPE_ETHERNET    = 9;
 
@@ -255,12 +253,63 @@
 
     public static final int DEFAULT_NETWORK_PREFERENCE = TYPE_WIFI;
 
-    private IConnectivityManager mService;
+    private final IConnectivityManager mService;
 
-    static public boolean isNetworkTypeValid(int networkType) {
+    public static boolean isNetworkTypeValid(int networkType) {
         return networkType >= 0 && networkType <= MAX_NETWORK_TYPE;
     }
 
+    /** {@hide} */
+    public static String getNetworkTypeName(int type) {
+        switch (type) {
+            case TYPE_MOBILE:
+                return "MOBILE";
+            case TYPE_WIFI:
+                return "WIFI";
+            case TYPE_MOBILE_MMS:
+                return "MOBILE_MMS";
+            case TYPE_MOBILE_SUPL:
+                return "MOBILE_SUPL";
+            case TYPE_MOBILE_DUN:
+                return "MOBILE_DUN";
+            case TYPE_MOBILE_HIPRI:
+                return "MOBILE_HIPRI";
+            case TYPE_WIMAX:
+                return "WIMAX";
+            case TYPE_BLUETOOTH:
+                return "BLUETOOTH";
+            case TYPE_DUMMY:
+                return "DUMMY";
+            case TYPE_ETHERNET:
+                return "ETHERNET";
+            case TYPE_MOBILE_FOTA:
+                return "MOBILE_FOTA";
+            case TYPE_MOBILE_IMS:
+                return "MOBILE_IMS";
+            case TYPE_MOBILE_CBS:
+                return "MOBILE_CBS";
+            default:
+                return Integer.toString(type);
+        }
+    }
+
+    /** {@hide} */
+    public static boolean isNetworkTypeMobile(int networkType) {
+        switch (networkType) {
+            case TYPE_MOBILE:
+            case TYPE_MOBILE_MMS:
+            case TYPE_MOBILE_SUPL:
+            case TYPE_MOBILE_DUN:
+            case TYPE_MOBILE_HIPRI:
+            case TYPE_MOBILE_FOTA:
+            case TYPE_MOBILE_IMS:
+            case TYPE_MOBILE_CBS:
+                return true;
+            default:
+                return false;
+        }
+    }
+
     public void setNetworkPreference(int preference) {
         try {
             mService.setNetworkPreference(preference);
@@ -284,6 +333,15 @@
         }
     }
 
+    /** {@hide} */
+    public NetworkInfo getActiveNetworkInfoForUid(int uid) {
+        try {
+            return mService.getActiveNetworkInfoForUid(uid);
+        } catch (RemoteException e) {
+            return null;
+        }
+    }
+
     public NetworkInfo getNetworkInfo(int networkType) {
         try {
             return mService.getNetworkInfo(networkType);
@@ -300,7 +358,7 @@
         }
     }
 
-    /** @hide */
+    /** {@hide} */
     public LinkProperties getActiveLinkProperties() {
         try {
             return mService.getActiveLinkProperties();
@@ -309,7 +367,7 @@
         }
     }
 
-    /** @hide */
+    /** {@hide} */
     public LinkProperties getLinkProperties(int networkType) {
         try {
             return mService.getLinkProperties(networkType);
@@ -479,19 +537,11 @@
     }
 
     /**
-     * Don't allow use of default constructor.
-     */
-    @SuppressWarnings({"UnusedDeclaration"})
-    private ConnectivityManager() {
-    }
-
-    /**
      * {@hide}
      */
     public ConnectivityManager(IConnectivityManager service) {
         if (service == null) {
-            throw new IllegalArgumentException(
-                "ConnectivityManager() cannot be constructed with null service");
+            throw new IllegalArgumentException("missing IConnectivityManager");
         }
         mService = service;
     }
diff --git a/core/java/android/net/DhcpStateMachine.java b/core/java/android/net/DhcpStateMachine.java
index eaf087f..c49c019 100644
--- a/core/java/android/net/DhcpStateMachine.java
+++ b/core/java/android/net/DhcpStateMachine.java
@@ -66,6 +66,9 @@
     private static final int DHCP_RENEW = 0;
     private static final String ACTION_DHCP_RENEW = "android.net.wifi.DHCP_RENEW";
 
+    //Used for sanity check on setting up renewal
+    private static final int MIN_RENEWAL_TIME_SECS = 5 * 60;  // 5 minutes
+
     private enum DhcpAction {
         START,
         RENEW
@@ -331,13 +334,21 @@
 
         if (success) {
             Log.d(TAG, "DHCP succeeded on " + mInterfaceName);
-            //Do it a bit earlier than half the lease duration time
-            //to beat the native DHCP client and avoid extra packets
-            //48% for one hour lease time = 29 minutes
-            mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
-                    SystemClock.elapsedRealtime() +
-                    dhcpInfoInternal.leaseDuration * 480, //in milliseconds
-                    mDhcpRenewalIntent);
+           long leaseDuration = dhcpInfoInternal.leaseDuration; //int to long conversion
+
+           //Sanity check for renewal
+           //TODO: would be good to notify the user that his network configuration is
+           //bad and that the device cannot renew below MIN_RENEWAL_TIME_SECS
+           if (leaseDuration < MIN_RENEWAL_TIME_SECS) {
+               leaseDuration = MIN_RENEWAL_TIME_SECS;
+           }
+           //Do it a bit earlier than half the lease duration time
+           //to beat the native DHCP client and avoid extra packets
+           //48% for one hour lease time = 29 minutes
+           mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
+                   SystemClock.elapsedRealtime() +
+                   leaseDuration * 480, //in milliseconds
+                   mDhcpRenewalIntent);
 
             mController.obtainMessage(CMD_POST_DHCP_ACTION, DHCP_SUCCESS, 0, dhcpInfoInternal)
                 .sendToTarget();
diff --git a/core/java/android/net/EthernetDataTracker.java b/core/java/android/net/EthernetDataTracker.java
index 55850c9..6f92247 100644
--- a/core/java/android/net/EthernetDataTracker.java
+++ b/core/java/android/net/EthernetDataTracker.java
@@ -63,6 +63,7 @@
     private Context mContext;
 
     private static EthernetDataTracker sInstance;
+    private static String sIfaceMatch = "";
     private static String mIface = "";
 
     private static class InterfaceObserver extends INetworkManagementEventObserver.Stub {
@@ -96,7 +97,7 @@
     }
 
     private void interfaceAdded(String iface) {
-        if (!iface.matches("eth\\d"))
+        if (!iface.matches(sIfaceMatch))
             return;
 
         Log.d(TAG, "Adding " + iface);
@@ -187,6 +188,22 @@
         } catch (RemoteException e) {
             Log.e(TAG, "Could not register InterfaceObserver " + e);
         }
+
+        // connect to an ethernet interface that already exists
+        sIfaceMatch = context.getResources().getString(
+            com.android.internal.R.string.config_ethernet_iface_regex);
+        try {
+            final String[] ifaces = service.listInterfaces();
+            for (String iface : ifaces) {
+                if (iface.matches(sIfaceMatch)) {
+                    mIface = iface;
+                    reconnect();
+                    break;
+                }
+            }
+        } catch (RemoteException e) {
+            Log.e(TAG, "Could not get list of interfaces " + e);
+        }
     }
 
     /**
diff --git a/core/java/android/net/IConnectivityManager.aidl b/core/java/android/net/IConnectivityManager.aidl
index 8be492c..fba16e1 100644
--- a/core/java/android/net/IConnectivityManager.aidl
+++ b/core/java/android/net/IConnectivityManager.aidl
@@ -18,8 +18,12 @@
 
 import android.net.LinkProperties;
 import android.net.NetworkInfo;
+import android.net.NetworkState;
 import android.net.ProxyProperties;
 import android.os.IBinder;
+import android.os.ParcelFileDescriptor;
+
+import com.android.internal.net.VpnConfig;
 
 /**
  * Interface that answers queries about, and allows changing, the
@@ -33,15 +37,15 @@
     int getNetworkPreference();
 
     NetworkInfo getActiveNetworkInfo();
-
+    NetworkInfo getActiveNetworkInfoForUid(int uid);
     NetworkInfo getNetworkInfo(int networkType);
-
     NetworkInfo[] getAllNetworkInfo();
 
     LinkProperties getActiveLinkProperties();
-
     LinkProperties getLinkProperties(int networkType);
 
+    NetworkState[] getAllNetworkState();
+
     boolean setRadios(boolean onOff);
 
     boolean setRadio(int networkType, boolean turnOn);
@@ -94,4 +98,10 @@
     ProxyProperties getProxy();
 
     void setDataDependency(int networkType, boolean met);
+
+    void protectVpn(in ParcelFileDescriptor socket);
+
+    String prepareVpn(String packageName);
+
+    ParcelFileDescriptor establishVpn(in VpnConfig config);
 }
diff --git a/core/java/android/net/INetworkPolicyListener.aidl b/core/java/android/net/INetworkPolicyListener.aidl
new file mode 100644
index 0000000..a45ec54
--- /dev/null
+++ b/core/java/android/net/INetworkPolicyListener.aidl
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net;
+
+/** {@hide} */
+oneway interface INetworkPolicyListener {
+
+    void onUidRulesChanged(int uid, int uidRules);
+    void onMeteredIfacesChanged(in String[] meteredIfaces);
+
+}
diff --git a/core/java/android/net/INetworkPolicyManager.aidl b/core/java/android/net/INetworkPolicyManager.aidl
index d9351ee..82495e3 100644
--- a/core/java/android/net/INetworkPolicyManager.aidl
+++ b/core/java/android/net/INetworkPolicyManager.aidl
@@ -16,6 +16,9 @@
 
 package android.net;
 
+import android.net.INetworkPolicyListener;
+import android.net.NetworkPolicy;
+
 /**
  * Interface that creates and modifies network policy rules.
  *
@@ -26,6 +29,12 @@
     void setUidPolicy(int uid, int policy);
     int getUidPolicy(int uid);
 
-    // TODO: build API to surface stats details for settings UI
+    boolean isUidForeground(int uid);
+
+    void registerListener(INetworkPolicyListener listener);
+    void unregisterListener(INetworkPolicyListener listener);
+
+    void setNetworkPolicies(in NetworkPolicy[] policies);
+    NetworkPolicy[] getNetworkPolicies();
 
 }
diff --git a/core/java/android/net/INetworkStatsService.aidl b/core/java/android/net/INetworkStatsService.aidl
new file mode 100644
index 0000000..ae9aa05
--- /dev/null
+++ b/core/java/android/net/INetworkStatsService.aidl
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net;
+
+import android.net.NetworkStats;
+import android.net.NetworkStatsHistory;
+import android.net.NetworkTemplate;
+
+/** {@hide} */
+interface INetworkStatsService {
+
+    /** Return historical stats for traffic that matches template. */
+    NetworkStatsHistory getHistoryForNetwork(in NetworkTemplate template);
+    /** Return historical stats for specific UID traffic that matches template. */
+    NetworkStatsHistory getHistoryForUid(in NetworkTemplate template, int uid, int tag);
+
+    /** Return usage summary for traffic that matches template. */
+    NetworkStats getSummaryForNetwork(in NetworkTemplate template, long start, long end);
+    /** Return usage summary per UID for traffic that matches template. */
+    NetworkStats getSummaryForAllUid(in NetworkTemplate template, long start, long end, boolean includeTags);
+
+}
diff --git a/core/java/android/net/MobileDataStateTracker.java b/core/java/android/net/MobileDataStateTracker.java
index 770f152..f3c863f 100644
--- a/core/java/android/net/MobileDataStateTracker.java
+++ b/core/java/android/net/MobileDataStateTracker.java
@@ -69,10 +69,6 @@
     private boolean mPrivateDnsRouteSet = false;
     private boolean mDefaultRouteSet = false;
 
-    // DEFAULT and HIPRI are the same connection.  If we're one of these we need to check if
-    // the other is also disconnected before we reset sockets
-    private boolean mIsDefaultOrHipri = false;
-
     private Handler mHandler;
     private AsyncChannel mDataConnectionTrackerAc;
     private Messenger mMessenger;
@@ -87,12 +83,6 @@
                 TelephonyManager.getDefault().getNetworkType(), tag,
                 TelephonyManager.getDefault().getNetworkTypeName());
         mApnType = networkTypeToApnType(netType);
-        if (netType == ConnectivityManager.TYPE_MOBILE ||
-                netType == ConnectivityManager.TYPE_MOBILE_HIPRI) {
-            mIsDefaultOrHipri = true;
-        }
-
-        mPhoneService = null;
     }
 
     /**
@@ -180,8 +170,6 @@
     }
 
     private class MobileDataStateReceiver extends BroadcastReceiver {
-        IConnectivityManager mConnectivityManager;
-
         @Override
         public void onReceive(Context context, Intent intent) {
             if (intent.getAction().equals(TelephonyIntents.
@@ -218,35 +206,6 @@
                             }
 
                             setDetailedState(DetailedState.DISCONNECTED, reason, apnName);
-                            boolean doReset = true;
-                            if (mIsDefaultOrHipri == true) {
-                                // both default and hipri must go down before we reset
-                                int typeToCheck = (Phone.APN_TYPE_DEFAULT.equals(mApnType) ?
-                                    ConnectivityManager.TYPE_MOBILE_HIPRI :
-                                    ConnectivityManager.TYPE_MOBILE);
-                                if (mConnectivityManager == null) {
-                                    IBinder b = ServiceManager.getService(
-                                            Context.CONNECTIVITY_SERVICE);
-                                    mConnectivityManager = IConnectivityManager.Stub.asInterface(b);
-                                }
-                                try {
-                                    if (mConnectivityManager != null) {
-                                        NetworkInfo info = mConnectivityManager.getNetworkInfo(
-                                                typeToCheck);
-                                        if (info.isConnected() == true) {
-                                            doReset = false;
-                                        }
-                                    }
-                                } catch (RemoteException e) {
-                                    // just go ahead with the reset
-                                    loge("Exception trying to contact ConnService: " + e);
-                                }
-                            }
-                            if (doReset && mLinkProperties != null) {
-                                String iface = mLinkProperties.getInterfaceName();
-                                if (iface != null) NetworkUtils.resetConnections(iface);
-                            }
-                            // TODO - check this
                             // can't do this here - ConnectivityService needs it to clear stuff
                             // it's ok though - just leave it to be refreshed next time
                             // we connect.
diff --git a/core/java/android/net/NetworkIdentity.java b/core/java/android/net/NetworkIdentity.java
new file mode 100644
index 0000000..ccef122
--- /dev/null
+++ b/core/java/android/net/NetworkIdentity.java
@@ -0,0 +1,122 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net;
+
+import static android.net.ConnectivityManager.isNetworkTypeMobile;
+
+import android.content.Context;
+import android.telephony.TelephonyManager;
+
+import com.android.internal.util.Objects;
+
+/**
+ * Network definition that includes strong identity. Analogous to combining
+ * {@link NetworkInfo} and an IMSI.
+ *
+ * @hide
+ */
+public class NetworkIdentity {
+    final int mType;
+    final int mSubType;
+    final String mSubscriberId;
+    final boolean mRoaming;
+
+    public NetworkIdentity(int type, int subType, String subscriberId, boolean roaming) {
+        this.mType = type;
+        this.mSubType = subType;
+        this.mSubscriberId = subscriberId;
+        this.mRoaming = roaming;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hashCode(mType, mSubType, mSubscriberId);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj instanceof NetworkIdentity) {
+            final NetworkIdentity ident = (NetworkIdentity) obj;
+            return mType == ident.mType && mSubType == ident.mSubType
+                    && Objects.equal(mSubscriberId, ident.mSubscriberId)
+                    && mRoaming == ident.mRoaming;
+        }
+        return false;
+    }
+
+    @Override
+    public String toString() {
+        final String typeName = ConnectivityManager.getNetworkTypeName(mType);
+        final String subTypeName;
+        if (ConnectivityManager.isNetworkTypeMobile(mType)) {
+            subTypeName = TelephonyManager.getNetworkTypeName(mSubType);
+        } else {
+            subTypeName = Integer.toString(mSubType);
+        }
+
+        final String scrubSubscriberId = mSubscriberId != null ? "valid" : "null";
+        final String roaming = mRoaming ? ", ROAMING" : "";
+        return "[type=" + typeName + ", subType=" + subTypeName + ", subscriberId="
+                + scrubSubscriberId + roaming + "]";
+    }
+
+    public int getType() {
+        return mType;
+    }
+
+    public int getSubType() {
+        return mSubType;
+    }
+
+    public String getSubscriberId() {
+        return mSubscriberId;
+    }
+
+    public boolean getRoaming() {
+        return mRoaming;
+    }
+
+    /**
+     * Build a {@link NetworkIdentity} from the given {@link NetworkState},
+     * assuming that any mobile networks are using the current IMSI.
+     */
+    public static NetworkIdentity buildNetworkIdentity(Context context, NetworkState state) {
+        final int type = state.networkInfo.getType();
+        final int subType = state.networkInfo.getSubtype();
+
+        // TODO: consider moving subscriberId over to LinkCapabilities, so it
+        // comes from an authoritative source.
+
+        final String subscriberId;
+        final boolean roaming;
+        if (isNetworkTypeMobile(type)) {
+            final TelephonyManager telephony = (TelephonyManager) context.getSystemService(
+                    Context.TELEPHONY_SERVICE);
+            roaming = telephony.isNetworkRoaming();
+            if (state.subscriberId != null) {
+                subscriberId = state.subscriberId;
+            } else {
+                subscriberId = telephony.getSubscriberId();
+            }
+        } else {
+            subscriberId = null;
+            roaming = false;
+        }
+        return new NetworkIdentity(type, subType, subscriberId, roaming);
+    }
+
+}
diff --git a/core/java/android/net/NetworkInfo.java b/core/java/android/net/NetworkInfo.java
index 5f5e11c..537750a 100644
--- a/core/java/android/net/NetworkInfo.java
+++ b/core/java/android/net/NetworkInfo.java
@@ -74,7 +74,9 @@
         /** IP traffic not available. */
         DISCONNECTED,
         /** Attempt to connect failed. */
-        FAILED
+        FAILED,
+        /** Access to this network is blocked. */
+        BLOCKED
     }
 
     /**
@@ -96,6 +98,7 @@
         stateMap.put(DetailedState.DISCONNECTING, State.DISCONNECTING);
         stateMap.put(DetailedState.DISCONNECTED, State.DISCONNECTED);
         stateMap.put(DetailedState.FAILED, State.DISCONNECTED);
+        stateMap.put(DetailedState.BLOCKED, State.DISCONNECTED);
     }
 
     private int mNetworkType;
@@ -138,6 +141,23 @@
         mIsRoaming = false;
     }
 
+    /** {@hide} */
+    public NetworkInfo(NetworkInfo source) {
+        if (source != null) {
+            mNetworkType = source.mNetworkType;
+            mSubtype = source.mSubtype;
+            mTypeName = source.mTypeName;
+            mSubtypeName = source.mSubtypeName;
+            mState = source.mState;
+            mDetailedState = source.mDetailedState;
+            mReason = source.mReason;
+            mExtraInfo = source.mExtraInfo;
+            mIsFailover = source.mIsFailover;
+            mIsRoaming = source.mIsRoaming;
+            mIsAvailable = source.mIsAvailable;
+        }
+    }
+
     /**
      * Reports the type of network (currently mobile or Wi-Fi) to which the
      * info in this object pertains.
diff --git a/core/java/android/net/NetworkPolicy.aidl b/core/java/android/net/NetworkPolicy.aidl
new file mode 100644
index 0000000..dbabb0608
--- /dev/null
+++ b/core/java/android/net/NetworkPolicy.aidl
@@ -0,0 +1,19 @@
+/**
+ * Copyright (c) 2011, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net;
+
+parcelable NetworkPolicy;
diff --git a/core/java/android/net/NetworkPolicy.java b/core/java/android/net/NetworkPolicy.java
new file mode 100644
index 0000000..52cab30
--- /dev/null
+++ b/core/java/android/net/NetworkPolicy.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net;
+
+import static com.android.internal.util.Preconditions.checkNotNull;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+/**
+ * Policy for networks matching a {@link NetworkTemplate}, including usage cycle
+ * and limits to be enforced.
+ *
+ * @hide
+ */
+public class NetworkPolicy implements Parcelable, Comparable<NetworkPolicy> {
+    public static final long WARNING_DISABLED = -1;
+    public static final long LIMIT_DISABLED = -1;
+
+    public final NetworkTemplate template;
+    public int cycleDay;
+    public long warningBytes;
+    public long limitBytes;
+
+    // TODO: teach how to snooze limit for current cycle
+
+    public NetworkPolicy(
+            NetworkTemplate template, int cycleDay, long warningBytes, long limitBytes) {
+        this.template = checkNotNull(template, "missing NetworkTemplate");
+        this.cycleDay = cycleDay;
+        this.warningBytes = warningBytes;
+        this.limitBytes = limitBytes;
+    }
+
+    public NetworkPolicy(Parcel in) {
+        template = in.readParcelable(null);
+        cycleDay = in.readInt();
+        warningBytes = in.readLong();
+        limitBytes = in.readLong();
+    }
+
+    /** {@inheritDoc} */
+    public void writeToParcel(Parcel dest, int flags) {
+        dest.writeParcelable(template, flags);
+        dest.writeInt(cycleDay);
+        dest.writeLong(warningBytes);
+        dest.writeLong(limitBytes);
+    }
+
+    /** {@inheritDoc} */
+    public int describeContents() {
+        return 0;
+    }
+
+    /** {@inheritDoc} */
+    public int compareTo(NetworkPolicy another) {
+        if (another == null || another.limitBytes == LIMIT_DISABLED) {
+            // other value is missing or disabled; we win
+            return -1;
+        }
+        if (limitBytes == LIMIT_DISABLED || another.limitBytes < limitBytes) {
+            // we're disabled or other limit is smaller; they win
+            return 1;
+        }
+        return 0;
+    }
+
+    @Override
+    public String toString() {
+        return "NetworkPolicy[" + template + "]: cycleDay=" + cycleDay + ", warningBytes="
+                + warningBytes + ", limitBytes=" + limitBytes;
+    }
+
+    public static final Creator<NetworkPolicy> CREATOR = new Creator<NetworkPolicy>() {
+        public NetworkPolicy createFromParcel(Parcel in) {
+            return new NetworkPolicy(in);
+        }
+
+        public NetworkPolicy[] newArray(int size) {
+            return new NetworkPolicy[size];
+        }
+    };
+}
diff --git a/core/java/android/net/NetworkPolicyManager.java b/core/java/android/net/NetworkPolicyManager.java
index 1913aa7..91af16d 100644
--- a/core/java/android/net/NetworkPolicyManager.java
+++ b/core/java/android/net/NetworkPolicyManager.java
@@ -16,8 +16,14 @@
 
 package android.net;
 
+import static android.text.format.Time.MONTH_DAY;
+
 import android.content.Context;
+import android.content.Intent;
 import android.os.RemoteException;
+import android.text.format.Time;
+
+import java.io.PrintWriter;
 
 /**
  * Manager for creating and modifying network policy rules.
@@ -28,12 +34,35 @@
 
     /** No specific network policy, use system default. */
     public static final int POLICY_NONE = 0x0;
-    /** Reject network usage when application in background. */
-    public static final int POLICY_REJECT_BACKGROUND = 0x1;
-    /** Reject network usage on paid network connections. */
-    public static final int POLICY_REJECT_PAID = 0x2;
-    /** Application should conserve data. */
-    public static final int POLICY_CONSERVE_DATA = 0x4;
+    /** Reject network usage on metered networks when application in background. */
+    public static final int POLICY_REJECT_METERED_BACKGROUND = 0x1;
+
+    /** All network traffic should be allowed. */
+    public static final int RULE_ALLOW_ALL = 0x0;
+    /** Reject traffic on metered networks. */
+    public static final int RULE_REJECT_METERED = 0x1;
+
+    /**
+     * {@link Intent} action launched when user selects {@link NetworkPolicy}
+     * warning notification.
+     */
+    public static final String ACTION_DATA_USAGE_WARNING =
+            "android.intent.action.DATA_USAGE_WARNING";
+
+    /**
+     * {@link Intent} action launched when user selects {@link NetworkPolicy}
+     * limit notification.
+     */
+    public static final String ACTION_DATA_USAGE_LIMIT =
+            "android.intent.action.DATA_USAGE_LIMIT";
+
+    /**
+     * {@link Intent} extra included in {@link #ACTION_DATA_USAGE_WARNING} and
+     * {@link #ACTION_DATA_USAGE_LIMIT} to indicate which
+     * {@link NetworkTemplate} rule it applies to.
+     */
+    public static final String EXTRA_NETWORK_TEMPLATE =
+            "android.intent.extra.NETWORK_TEMPLATE";
 
     private INetworkPolicyManager mService;
 
@@ -48,12 +77,28 @@
         return (NetworkPolicyManager) context.getSystemService(Context.NETWORK_POLICY_SERVICE);
     }
 
+    /** {@hide} */
+    public void setNetworkPolicies(NetworkPolicy[] policies) {
+        try {
+            mService.setNetworkPolicies(policies);
+        } catch (RemoteException e) {
+        }
+    }
+
+    /** {@hide} */
+    public NetworkPolicy[] getNetworkPolicies() {
+        try {
+            return mService.getNetworkPolicies();
+        } catch (RemoteException e) {
+            return null;
+        }
+    }
+
     /**
      * Set policy flags for specific UID.
      *
-     * @param policy {@link #POLICY_NONE} or combination of
-     *            {@link #POLICY_REJECT_BACKGROUND}, {@link #POLICY_REJECT_PAID},
-     *            or {@link #POLICY_CONSERVE_DATA}.
+     * @param policy {@link #POLICY_NONE} or combination of flags like
+     *            {@link #POLICY_REJECT_METERED_BACKGROUND}.
      */
     public void setUidPolicy(int uid, int policy) {
         try {
@@ -70,4 +115,121 @@
         }
     }
 
+    public void registerListener(INetworkPolicyListener listener) {
+        try {
+            mService.registerListener(listener);
+        } catch (RemoteException e) {
+        }
+    }
+
+    public void unregisterListener(INetworkPolicyListener listener) {
+        try {
+            mService.unregisterListener(listener);
+        } catch (RemoteException e) {
+        }
+    }
+
+    /**
+     * Compute the last cycle boundary for the given {@link NetworkPolicy}. For
+     * example, if cycle day is 20th, and today is June 15th, it will return May
+     * 20th. When cycle day doesn't exist in current month, it snaps to the 1st
+     * of following month.
+     *
+     * @hide
+     */
+    public static long computeLastCycleBoundary(long currentTime, NetworkPolicy policy) {
+        final Time now = new Time(Time.TIMEZONE_UTC);
+        now.set(currentTime);
+
+        // first, find cycle boundary for current month
+        final Time cycle = new Time(now);
+        cycle.hour = cycle.minute = cycle.second = 0;
+        snapToCycleDay(cycle, policy.cycleDay);
+
+        if (Time.compare(cycle, now) >= 0) {
+            // cycle boundary is beyond now, use last cycle boundary; start by
+            // pushing ourselves squarely into last month.
+            final Time lastMonth = new Time(now);
+            lastMonth.hour = lastMonth.minute = lastMonth.second = 0;
+            lastMonth.monthDay = 1;
+            lastMonth.month -= 1;
+            lastMonth.normalize(true);
+
+            cycle.set(lastMonth);
+            snapToCycleDay(cycle, policy.cycleDay);
+        }
+
+        return cycle.toMillis(true);
+    }
+
+    /** {@hide} */
+    public static long computeNextCycleBoundary(long currentTime, NetworkPolicy policy) {
+        final Time now = new Time(Time.TIMEZONE_UTC);
+        now.set(currentTime);
+
+        // first, find cycle boundary for current month
+        final Time cycle = new Time(now);
+        cycle.hour = cycle.minute = cycle.second = 0;
+        snapToCycleDay(cycle, policy.cycleDay);
+
+        if (Time.compare(cycle, now) <= 0) {
+            // cycle boundary is before now, use next cycle boundary; start by
+            // pushing ourselves squarely into next month.
+            final Time nextMonth = new Time(now);
+            nextMonth.hour = nextMonth.minute = nextMonth.second = 0;
+            nextMonth.monthDay = 1;
+            nextMonth.month += 1;
+            nextMonth.normalize(true);
+
+            cycle.set(nextMonth);
+            snapToCycleDay(cycle, policy.cycleDay);
+        }
+
+        return cycle.toMillis(true);
+    }
+
+    /**
+     * Snap to the cycle day for the current month given; when cycle day doesn't
+     * exist, it snaps to 1st of following month.
+     *
+     * @hide
+     */
+    public static void snapToCycleDay(Time time, int cycleDay) {
+        if (cycleDay > time.getActualMaximum(MONTH_DAY)) {
+            // cycle day isn't valid this month; snap to 1st of next month
+            time.month += 1;
+            time.monthDay = 1;
+        } else {
+            time.monthDay = cycleDay;
+        }
+        time.normalize(true);
+    }
+
+    /**
+     * Check if given UID can have a {@link #setUidPolicy(int, int)} defined,
+     * usually to protect critical system services.
+     */
+    public static boolean isUidValidForPolicy(Context context, int uid) {
+        return (uid >= android.os.Process.FIRST_APPLICATION_UID
+                && uid <= android.os.Process.LAST_APPLICATION_UID);
+    }
+
+    /** {@hide} */
+    public static void dumpPolicy(PrintWriter fout, int policy) {
+        fout.write("[");
+        if ((policy & POLICY_REJECT_METERED_BACKGROUND) != 0) {
+            fout.write("REJECT_METERED_BACKGROUND");
+        }
+        fout.write("]");
+    }
+
+    /** {@hide} */
+    public static void dumpRules(PrintWriter fout, int rules) {
+        fout.write("[");
+        if ((rules & RULE_REJECT_METERED) != 0) {
+            fout.write("REJECT_METERED");
+        }
+        fout.write("]");
+    }
+
 }
diff --git a/core/java/android/net/NetworkState.aidl b/core/java/android/net/NetworkState.aidl
new file mode 100644
index 0000000..c0b6cdc
--- /dev/null
+++ b/core/java/android/net/NetworkState.aidl
@@ -0,0 +1,19 @@
+/**
+ * Copyright (c) 2011, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net;
+
+parcelable NetworkState;
diff --git a/core/java/android/net/NetworkState.java b/core/java/android/net/NetworkState.java
new file mode 100644
index 0000000..704111b
--- /dev/null
+++ b/core/java/android/net/NetworkState.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+/**
+ * Snapshot of network state.
+ *
+ * @hide
+ */
+public class NetworkState implements Parcelable {
+
+    public final NetworkInfo networkInfo;
+    public final LinkProperties linkProperties;
+    public final LinkCapabilities linkCapabilities;
+    /** Currently only used by testing. */
+    public final String subscriberId;
+
+    public NetworkState(NetworkInfo networkInfo, LinkProperties linkProperties,
+            LinkCapabilities linkCapabilities) {
+        this(networkInfo, linkProperties, linkCapabilities, null);
+    }
+
+    public NetworkState(NetworkInfo networkInfo, LinkProperties linkProperties,
+            LinkCapabilities linkCapabilities, String subscriberId) {
+        this.networkInfo = networkInfo;
+        this.linkProperties = linkProperties;
+        this.linkCapabilities = linkCapabilities;
+        this.subscriberId = subscriberId;
+    }
+
+    public NetworkState(Parcel in) {
+        networkInfo = in.readParcelable(null);
+        linkProperties = in.readParcelable(null);
+        linkCapabilities = in.readParcelable(null);
+        subscriberId = in.readString();
+    }
+
+    /** {@inheritDoc} */
+    public int describeContents() {
+        return 0;
+    }
+
+    /** {@inheritDoc} */
+    public void writeToParcel(Parcel out, int flags) {
+        out.writeParcelable(networkInfo, flags);
+        out.writeParcelable(linkProperties, flags);
+        out.writeParcelable(linkCapabilities, flags);
+        out.writeString(subscriberId);
+    }
+
+    public static final Creator<NetworkState> CREATOR = new Creator<NetworkState>() {
+        public NetworkState createFromParcel(Parcel in) {
+            return new NetworkState(in);
+        }
+
+        public NetworkState[] newArray(int size) {
+            return new NetworkState[size];
+        }
+    };
+
+}
diff --git a/core/java/android/net/NetworkStats.java b/core/java/android/net/NetworkStats.java
index 0f207bc..9d40c42 100644
--- a/core/java/android/net/NetworkStats.java
+++ b/core/java/android/net/NetworkStats.java
@@ -19,100 +19,108 @@
 import android.os.Parcel;
 import android.os.Parcelable;
 import android.os.SystemClock;
+import android.util.SparseBooleanArray;
 
 import java.io.CharArrayWriter;
 import java.io.PrintWriter;
+import java.util.Arrays;
+import java.util.HashSet;
 
 /**
- * Collection of network statistics. Can contain summary details across all
- * interfaces, or details with per-UID granularity. Designed to parcel quickly
- * across process boundaries.
+ * Collection of active network statistics. Can contain summary details across
+ * all interfaces, or details with per-UID granularity. Internally stores data
+ * as a large table, closely matching {@code /proc/} data format. This structure
+ * optimizes for rapid in-memory comparison, but consider using
+ * {@link NetworkStatsHistory} when persisting.
  *
  * @hide
  */
 public class NetworkStats implements Parcelable {
-    /** {@link #iface} value when entry is summarized over all interfaces. */
+    /** {@link #iface} value when interface details unavailable. */
     public static final String IFACE_ALL = null;
-    /** {@link #uid} value when entry is summarized over all UIDs. */
-    public static final int UID_ALL = 0;
-
-    // NOTE: data should only be accounted for once in this structure; if data
-    // is broken out, the summarized version should not be included.
+    /** {@link #uid} value when UID details unavailable. */
+    public static final int UID_ALL = -1;
+    /** {@link #tag} value for without tag. */
+    public static final int TAG_NONE = 0;
 
     /**
      * {@link SystemClock#elapsedRealtime()} timestamp when this data was
      * generated.
      */
     public final long elapsedRealtime;
-    public final String[] iface;
-    public final int[] uid;
-    public final long[] rx;
-    public final long[] tx;
+    public int size;
+    public String[] iface;
+    public int[] uid;
+    public int[] tag;
+    public long[] rx;
+    public long[] tx;
 
-    // TODO: add fg/bg stats and tag granularity
-
-    private NetworkStats(long elapsedRealtime, String[] iface, int[] uid, long[] rx, long[] tx) {
+    public NetworkStats(long elapsedRealtime, int initialSize) {
         this.elapsedRealtime = elapsedRealtime;
-        this.iface = iface;
-        this.uid = uid;
-        this.rx = rx;
-        this.tx = tx;
+        this.size = 0;
+        this.iface = new String[initialSize];
+        this.uid = new int[initialSize];
+        this.tag = new int[initialSize];
+        this.rx = new long[initialSize];
+        this.tx = new long[initialSize];
     }
 
     public NetworkStats(Parcel parcel) {
         elapsedRealtime = parcel.readLong();
+        size = parcel.readInt();
         iface = parcel.createStringArray();
         uid = parcel.createIntArray();
+        tag = parcel.createIntArray();
         rx = parcel.createLongArray();
         tx = parcel.createLongArray();
     }
 
-    public static class Builder {
-        private long mElapsedRealtime;
-        private final String[] mIface;
-        private final int[] mUid;
-        private final long[] mRx;
-        private final long[] mTx;
-
-        private int mIndex = 0;
-
-        public Builder(long elapsedRealtime, int size) {
-            mElapsedRealtime = elapsedRealtime;
-            mIface = new String[size];
-            mUid = new int[size];
-            mRx = new long[size];
-            mTx = new long[size];
+    /**
+     * Add new stats entry with given values.
+     */
+    public NetworkStats addEntry(String iface, int uid, int tag, long rx, long tx) {
+        if (size >= this.iface.length) {
+            final int newLength = Math.max(this.iface.length, 10) * 3 / 2;
+            this.iface = Arrays.copyOf(this.iface, newLength);
+            this.uid = Arrays.copyOf(this.uid, newLength);
+            this.tag = Arrays.copyOf(this.tag, newLength);
+            this.rx = Arrays.copyOf(this.rx, newLength);
+            this.tx = Arrays.copyOf(this.tx, newLength);
         }
 
-        public Builder addEntry(String iface, int uid, long rx, long tx) {
-            mIface[mIndex] = iface;
-            mUid[mIndex] = uid;
-            mRx[mIndex] = rx;
-            mTx[mIndex] = tx;
-            mIndex++;
-            return this;
-        }
+        this.iface[size] = iface;
+        this.uid[size] = uid;
+        this.tag[size] = tag;
+        this.rx[size] = rx;
+        this.tx[size] = tx;
+        size++;
 
-        public NetworkStats build() {
-            if (mIndex != mIface.length) {
-                throw new IllegalArgumentException("unexpected number of entries");
-            }
-            return new NetworkStats(mElapsedRealtime, mIface, mUid, mRx, mTx);
-        }
+        return this;
     }
 
-    public int length() {
-        // length is identical for all fields
-        return iface.length;
+    /**
+     * Combine given values with an existing row, or create a new row if
+     * {@link #findIndex(String, int, int)} is unable to find match. Can also be
+     * used to subtract values from existing rows.
+     */
+    public NetworkStats combineEntry(String iface, int uid, int tag, long rx, long tx) {
+        final int i = findIndex(iface, uid, tag);
+        if (i == -1) {
+            // only create new entry when positive contribution
+            addEntry(iface, uid, tag, rx, tx);
+        } else {
+            this.rx[i] += rx;
+            this.tx[i] += tx;
+        }
+        return this;
     }
 
     /**
      * Find first stats index that matches the requested parameters.
      */
-    public int findIndex(String iface, int uid) {
-        final int length = length();
-        for (int i = 0; i < length; i++) {
-            if (equal(iface, this.iface[i]) && uid == this.uid[i]) {
+    public int findIndex(String iface, int uid, int tag) {
+        for (int i = 0; i < size; i++) {
+            if (equal(iface, this.iface[i]) && uid == this.uid[i] && tag == this.tag[i]) {
                 return i;
             }
         }
@@ -120,33 +128,104 @@
     }
 
     /**
+     * Return list of unique interfaces known by this data structure.
+     */
+    public String[] getUniqueIfaces() {
+        final HashSet<String> ifaces = new HashSet<String>();
+        for (String iface : this.iface) {
+            if (iface != IFACE_ALL) {
+                ifaces.add(iface);
+            }
+        }
+        return ifaces.toArray(new String[ifaces.size()]);
+    }
+
+    /**
+     * Return list of unique UIDs known by this data structure.
+     */
+    public int[] getUniqueUids() {
+        final SparseBooleanArray uids = new SparseBooleanArray();
+        for (int uid : this.uid) {
+            uids.put(uid, true);
+        }
+
+        final int size = uids.size();
+        final int[] result = new int[size];
+        for (int i = 0; i < size; i++) {
+            result[i] = uids.keyAt(i);
+        }
+        return result;
+    }
+
+    /**
      * Subtract the given {@link NetworkStats}, effectively leaving the delta
      * between two snapshots in time. Assumes that statistics rows collect over
      * time, and that none of them have disappeared.
+     *
+     * @throws IllegalArgumentException when given {@link NetworkStats} is
+     *             non-monotonic.
      */
     public NetworkStats subtract(NetworkStats value) {
-        // result will have our rows, but no meaningful timestamp
-        final int length = length();
-        final NetworkStats.Builder result = new NetworkStats.Builder(-1, length);
+        return subtract(value, true, false);
+    }
 
-        for (int i = 0; i < length; i++) {
+    /**
+     * Subtract the given {@link NetworkStats}, effectively leaving the delta
+     * between two snapshots in time. Assumes that statistics rows collect over
+     * time, and that none of them have disappeared.
+     * <p>
+     * Instead of throwing when counters are non-monotonic, this variant clamps
+     * results to never be negative.
+     */
+    public NetworkStats subtractClamped(NetworkStats value) {
+        return subtract(value, false, true);
+    }
+
+    /**
+     * Subtract the given {@link NetworkStats}, effectively leaving the delta
+     * between two snapshots in time. Assumes that statistics rows collect over
+     * time, and that none of them have disappeared.
+     *
+     * @param enforceMonotonic Validate that incoming value is strictly
+     *            monotonic compared to this object.
+     * @param clampNegative Instead of throwing like {@code enforceMonotonic},
+     *            clamp resulting counters at 0 to prevent negative values.
+     */
+    private NetworkStats subtract(
+            NetworkStats value, boolean enforceMonotonic, boolean clampNegative) {
+        final long deltaRealtime = this.elapsedRealtime - value.elapsedRealtime;
+        if (enforceMonotonic && deltaRealtime < 0) {
+            throw new IllegalArgumentException("found non-monotonic realtime");
+        }
+
+        // result will have our rows, and elapsed time between snapshots
+        final NetworkStats result = new NetworkStats(deltaRealtime, size);
+        for (int i = 0; i < size; i++) {
             final String iface = this.iface[i];
             final int uid = this.uid[i];
+            final int tag = this.tag[i];
 
             // find remote row that matches, and subtract
-            final int j = value.findIndex(iface, uid);
+            final int j = value.findIndex(iface, uid, tag);
             if (j == -1) {
                 // newly appearing row, return entire value
-                result.addEntry(iface, uid, this.rx[i], this.tx[i]);
+                result.addEntry(iface, uid, tag, this.rx[i], this.tx[i]);
             } else {
                 // existing row, subtract remote value
-                final long rx = this.rx[i] - value.rx[j];
-                final long tx = this.tx[i] - value.tx[j];
-                result.addEntry(iface, uid, rx, tx);
+                long rx = this.rx[i] - value.rx[j];
+                long tx = this.tx[i] - value.tx[j];
+                if (enforceMonotonic && (rx < 0 || tx < 0)) {
+                    throw new IllegalArgumentException("found non-monotonic values");
+                }
+                if (clampNegative) {
+                    rx = Math.max(0, rx);
+                    tx = Math.max(0, tx);
+                }
+                result.addEntry(iface, uid, tag, rx, tx);
             }
         }
 
-        return result.build();
+        return result;
     }
 
     private static boolean equal(Object a, Object b) {
@@ -160,6 +239,7 @@
             pw.print(prefix);
             pw.print("  iface="); pw.print(iface[i]);
             pw.print(" uid="); pw.print(uid[i]);
+            pw.print(" tag="); pw.print(tag[i]);
             pw.print(" rx="); pw.print(rx[i]);
             pw.print(" tx="); pw.println(tx[i]);
         }
@@ -180,8 +260,10 @@
     /** {@inheritDoc} */
     public void writeToParcel(Parcel dest, int flags) {
         dest.writeLong(elapsedRealtime);
+        dest.writeInt(size);
         dest.writeStringArray(iface);
         dest.writeIntArray(uid);
+        dest.writeIntArray(tag);
         dest.writeLongArray(rx);
         dest.writeLongArray(tx);
     }
diff --git a/core/java/android/net/NetworkStatsHistory.aidl b/core/java/android/net/NetworkStatsHistory.aidl
new file mode 100644
index 0000000..8b9069f
--- /dev/null
+++ b/core/java/android/net/NetworkStatsHistory.aidl
@@ -0,0 +1,19 @@
+/**
+ * Copyright (c) 2011, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net;
+
+parcelable NetworkStatsHistory;
diff --git a/core/java/android/net/NetworkStatsHistory.java b/core/java/android/net/NetworkStatsHistory.java
new file mode 100644
index 0000000..ff6e220
--- /dev/null
+++ b/core/java/android/net/NetworkStatsHistory.java
@@ -0,0 +1,348 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import java.io.CharArrayWriter;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.ProtocolException;
+import java.util.Arrays;
+import java.util.Random;
+
+/**
+ * Collection of historical network statistics, recorded into equally-sized
+ * "buckets" in time. Internally it stores data in {@code long} series for more
+ * efficient persistence.
+ * <p>
+ * Each bucket is defined by a {@link #bucketStart} timestamp, and lasts for
+ * {@link #bucketDuration}. Internally assumes that {@link #bucketStart} is
+ * sorted at all times.
+ *
+ * @hide
+ */
+public class NetworkStatsHistory implements Parcelable {
+    private static final int VERSION_INIT = 1;
+
+    // TODO: teach about varint encoding to use less disk space
+
+    public final long bucketDuration;
+
+    public int bucketCount;
+    public long[] bucketStart;
+    public long[] rx;
+    public long[] tx;
+
+    public NetworkStatsHistory(long bucketDuration) {
+        this(bucketDuration, 10);
+    }
+
+    public NetworkStatsHistory(long bucketDuration, int initialSize) {
+        this.bucketDuration = bucketDuration;
+        bucketStart = new long[initialSize];
+        rx = new long[initialSize];
+        tx = new long[initialSize];
+        bucketCount = 0;
+    }
+
+    public NetworkStatsHistory(Parcel in) {
+        bucketDuration = in.readLong();
+        bucketStart = readLongArray(in);
+        rx = in.createLongArray();
+        tx = in.createLongArray();
+        bucketCount = bucketStart.length;
+    }
+
+    /** {@inheritDoc} */
+    public void writeToParcel(Parcel out, int flags) {
+        out.writeLong(bucketDuration);
+        writeLongArray(out, bucketStart, bucketCount);
+        writeLongArray(out, rx, bucketCount);
+        writeLongArray(out, tx, bucketCount);
+    }
+
+    public NetworkStatsHistory(DataInputStream in) throws IOException {
+        final int version = in.readInt();
+        switch (version) {
+            case VERSION_INIT: {
+                bucketDuration = in.readLong();
+                bucketStart = readLongArray(in);
+                rx = readLongArray(in);
+                tx = readLongArray(in);
+                bucketCount = bucketStart.length;
+                break;
+            }
+            default: {
+                throw new ProtocolException("unexpected version: " + version);
+            }
+        }
+    }
+
+    public void writeToStream(DataOutputStream out) throws IOException {
+        out.writeInt(VERSION_INIT);
+        out.writeLong(bucketDuration);
+        writeLongArray(out, bucketStart, bucketCount);
+        writeLongArray(out, rx, bucketCount);
+        writeLongArray(out, tx, bucketCount);
+    }
+
+    /** {@inheritDoc} */
+    public int describeContents() {
+        return 0;
+    }
+
+    /**
+     * Record that data traffic occurred in the given time range. Will
+     * distribute across internal buckets, creating new buckets as needed.
+     */
+    public void recordData(long start, long end, long rx, long tx) {
+        if (rx < 0 || tx < 0) {
+            throw new IllegalArgumentException(
+                    "tried recording negative data: rx=" + rx + ", tx=" + tx);
+        }
+
+        // create any buckets needed by this range
+        ensureBuckets(start, end);
+
+        // distribute data usage into buckets
+        final long duration = end - start;
+        for (int i = bucketCount - 1; i >= 0; i--) {
+            final long curStart = bucketStart[i];
+            final long curEnd = curStart + bucketDuration;
+
+            // bucket is older than record; we're finished
+            if (curEnd < start) break;
+            // bucket is newer than record; keep looking
+            if (curStart > end) continue;
+
+            final long overlap = Math.min(curEnd, end) - Math.max(curStart, start);
+            if (overlap > 0) {
+                this.rx[i] += rx * overlap / duration;
+                this.tx[i] += tx * overlap / duration;
+            }
+        }
+    }
+
+    /**
+     * Record an entire {@link NetworkStatsHistory} into this history. Usually
+     * for combining together stats for external reporting.
+     */
+    public void recordEntireHistory(NetworkStatsHistory input) {
+        for (int i = 0; i < input.bucketCount; i++) {
+            final long start = input.bucketStart[i];
+            final long end = start + input.bucketDuration;
+            recordData(start, end, input.rx[i], input.tx[i]);
+        }
+    }
+
+    /**
+     * Ensure that buckets exist for given time range, creating as needed.
+     */
+    private void ensureBuckets(long start, long end) {
+        // normalize incoming range to bucket boundaries
+        start -= start % bucketDuration;
+        end += (bucketDuration - (end % bucketDuration)) % bucketDuration;
+
+        for (long now = start; now < end; now += bucketDuration) {
+            // try finding existing bucket
+            final int index = Arrays.binarySearch(bucketStart, 0, bucketCount, now);
+            if (index < 0) {
+                // bucket missing, create and insert
+                insertBucket(~index, now);
+            }
+        }
+    }
+
+    /**
+     * Insert new bucket at requested index and starting time.
+     */
+    private void insertBucket(int index, long start) {
+        // create more buckets when needed
+        if (bucketCount >= bucketStart.length) {
+            final int newLength = Math.max(bucketStart.length, 10) * 3 / 2;
+            bucketStart = Arrays.copyOf(bucketStart, newLength);
+            rx = Arrays.copyOf(rx, newLength);
+            tx = Arrays.copyOf(tx, newLength);
+        }
+
+        // create gap when inserting bucket in middle
+        if (index < bucketCount) {
+            final int dstPos = index + 1;
+            final int length = bucketCount - index;
+
+            System.arraycopy(bucketStart, index, bucketStart, dstPos, length);
+            System.arraycopy(rx, index, rx, dstPos, length);
+            System.arraycopy(tx, index, tx, dstPos, length);
+        }
+
+        bucketStart[index] = start;
+        rx[index] = 0;
+        tx[index] = 0;
+        bucketCount++;
+    }
+
+    /**
+     * Remove buckets older than requested cutoff.
+     */
+    public void removeBucketsBefore(long cutoff) {
+        int i;
+        for (i = 0; i < bucketCount; i++) {
+            final long curStart = bucketStart[i];
+            final long curEnd = curStart + bucketDuration;
+
+            // cutoff happens before or during this bucket; everything before
+            // this bucket should be removed.
+            if (curEnd > cutoff) break;
+        }
+
+        if (i > 0) {
+            final int length = bucketStart.length;
+            bucketStart = Arrays.copyOfRange(bucketStart, i, length);
+            rx = Arrays.copyOfRange(rx, i, length);
+            tx = Arrays.copyOfRange(tx, i, length);
+            bucketCount -= i;
+        }
+    }
+
+    /**
+     * Return interpolated data usage across the requested range. Interpolates
+     * across buckets, so values may be rounded slightly.
+     */
+    public long[] getTotalData(long start, long end, long[] outTotal) {
+        long rx = 0;
+        long tx = 0;
+
+        for (int i = bucketCount - 1; i >= 0; i--) {
+            final long curStart = bucketStart[i];
+            final long curEnd = curStart + bucketDuration;
+
+            // bucket is older than record; we're finished
+            if (curEnd < start) break;
+            // bucket is newer than record; keep looking
+            if (curStart > end) continue;
+
+            final long overlap = Math.min(curEnd, end) - Math.max(curStart, start);
+            if (overlap > 0) {
+                rx += this.rx[i] * overlap / bucketDuration;
+                tx += this.tx[i] * overlap / bucketDuration;
+            }
+        }
+
+        if (outTotal == null || outTotal.length != 2) {
+            outTotal = new long[2];
+        }
+        outTotal[0] = rx;
+        outTotal[1] = tx;
+        return outTotal;
+    }
+
+    /**
+     * @deprecated only for temporary testing
+     */
+    @Deprecated
+    public void generateRandom(long start, long end, long rx, long tx) {
+        ensureBuckets(start, end);
+
+        final Random r = new Random();
+        while (rx > 1024 && tx > 1024) {
+            final long curStart = randomLong(r, start, end);
+            final long curEnd = randomLong(r, curStart, end);
+            final long curRx = randomLong(r, 0, rx);
+            final long curTx = randomLong(r, 0, tx);
+
+            recordData(curStart, curEnd, curRx, curTx);
+
+            rx -= curRx;
+            tx -= curTx;
+        }
+    }
+
+    private static long randomLong(Random r, long start, long end) {
+        return (long) (start + (r.nextFloat() * (end - start)));
+    }
+
+    public void dump(String prefix, PrintWriter pw) {
+        pw.print(prefix);
+        pw.print("NetworkStatsHistory: bucketDuration="); pw.println(bucketDuration);
+        for (int i = 0; i < bucketCount; i++) {
+            pw.print(prefix);
+            pw.print("  bucketStart="); pw.print(bucketStart[i]);
+            pw.print(" rx="); pw.print(rx[i]);
+            pw.print(" tx="); pw.println(tx[i]);
+        }
+    }
+
+    @Override
+    public String toString() {
+        final CharArrayWriter writer = new CharArrayWriter();
+        dump("", new PrintWriter(writer));
+        return writer.toString();
+    }
+
+    public static final Creator<NetworkStatsHistory> CREATOR = new Creator<NetworkStatsHistory>() {
+        public NetworkStatsHistory createFromParcel(Parcel in) {
+            return new NetworkStatsHistory(in);
+        }
+
+        public NetworkStatsHistory[] newArray(int size) {
+            return new NetworkStatsHistory[size];
+        }
+    };
+
+    private static long[] readLongArray(DataInputStream in) throws IOException {
+        final int size = in.readInt();
+        final long[] values = new long[size];
+        for (int i = 0; i < values.length; i++) {
+            values[i] = in.readLong();
+        }
+        return values;
+    }
+
+    private static void writeLongArray(DataOutputStream out, long[] values, int size) throws IOException {
+        if (size > values.length) {
+            throw new IllegalArgumentException("size larger than length");
+        }
+        out.writeInt(size);
+        for (int i = 0; i < size; i++) {
+            out.writeLong(values[i]);
+        }
+    }
+
+    private static long[] readLongArray(Parcel in) {
+        final int size = in.readInt();
+        final long[] values = new long[size];
+        for (int i = 0; i < values.length; i++) {
+            values[i] = in.readLong();
+        }
+        return values;
+    }
+
+    private static void writeLongArray(Parcel out, long[] values, int size) {
+        if (size > values.length) {
+            throw new IllegalArgumentException("size larger than length");
+        }
+        out.writeInt(size);
+        for (int i = 0; i < size; i++) {
+            out.writeLong(values[i]);
+        }
+    }
+
+}
diff --git a/core/java/android/net/NetworkTemplate.aidl b/core/java/android/net/NetworkTemplate.aidl
new file mode 100644
index 0000000..3d37488
--- /dev/null
+++ b/core/java/android/net/NetworkTemplate.aidl
@@ -0,0 +1,19 @@
+/**
+ * Copyright (c) 2011, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net;
+
+parcelable NetworkTemplate;
diff --git a/core/java/android/net/NetworkTemplate.java b/core/java/android/net/NetworkTemplate.java
new file mode 100644
index 0000000..9381f1d
--- /dev/null
+++ b/core/java/android/net/NetworkTemplate.java
@@ -0,0 +1,217 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net;
+
+import static android.net.ConnectivityManager.TYPE_WIFI;
+import static android.net.ConnectivityManager.TYPE_WIMAX;
+import static android.net.ConnectivityManager.isNetworkTypeMobile;
+import static android.telephony.TelephonyManager.NETWORK_CLASS_2_G;
+import static android.telephony.TelephonyManager.NETWORK_CLASS_3_G;
+import static android.telephony.TelephonyManager.NETWORK_CLASS_4_G;
+import static android.telephony.TelephonyManager.NETWORK_CLASS_UNKNOWN;
+import static android.telephony.TelephonyManager.getNetworkClass;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import com.android.internal.util.Objects;
+
+/**
+ * Template definition used to generically match {@link NetworkIdentity},
+ * usually when collecting statistics.
+ *
+ * @hide
+ */
+public class NetworkTemplate implements Parcelable {
+
+    /**
+     * Template to combine all {@link ConnectivityManager#TYPE_MOBILE} style
+     * networks together. Only uses statistics for requested IMSI.
+     */
+    public static final int MATCH_MOBILE_ALL = 1;
+
+    /**
+     * Template to combine all {@link ConnectivityManager#TYPE_MOBILE} style
+     * networks together that roughly meet a "3G" definition, or lower. Only
+     * uses statistics for requested IMSI.
+     */
+    public static final int MATCH_MOBILE_3G_LOWER = 2;
+
+    /**
+     * Template to combine all {@link ConnectivityManager#TYPE_MOBILE} style
+     * networks together that meet a "4G" definition. Only uses statistics for
+     * requested IMSI.
+     */
+    public static final int MATCH_MOBILE_4G = 3;
+
+    /**
+     * Template to combine all {@link ConnectivityManager#TYPE_WIFI} style
+     * networks together.
+     */
+    public static final int MATCH_WIFI = 4;
+
+    final int mMatchRule;
+    final String mSubscriberId;
+
+    public NetworkTemplate(int matchRule, String subscriberId) {
+        this.mMatchRule = matchRule;
+        this.mSubscriberId = subscriberId;
+    }
+
+    public NetworkTemplate(Parcel in) {
+        mMatchRule = in.readInt();
+        mSubscriberId = in.readString();
+    }
+
+    /** {@inheritDoc} */
+    public void writeToParcel(Parcel dest, int flags) {
+        dest.writeInt(mMatchRule);
+        dest.writeString(mSubscriberId);
+    }
+
+    /** {@inheritDoc} */
+    public int describeContents() {
+        return 0;
+    }
+
+    @Override
+    public String toString() {
+        final String scrubSubscriberId = mSubscriberId != null ? "valid" : "null";
+        return "NetworkTemplate: matchRule=" + getMatchRuleName(mMatchRule) + ", subscriberId="
+                + scrubSubscriberId;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hashCode(mMatchRule, mSubscriberId);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj instanceof NetworkTemplate) {
+            final NetworkTemplate other = (NetworkTemplate) obj;
+            return mMatchRule == other.mMatchRule
+                    && Objects.equal(mSubscriberId, other.mSubscriberId);
+        }
+        return false;
+    }
+
+    public int getMatchRule() {
+        return mMatchRule;
+    }
+
+    public String getSubscriberId() {
+        return mSubscriberId;
+    }
+
+    /**
+     * Test if this network matches the given template and IMEI.
+     */
+    public boolean matches(NetworkIdentity ident) {
+        switch (mMatchRule) {
+            case MATCH_MOBILE_ALL:
+                return matchesMobile(ident);
+            case MATCH_MOBILE_3G_LOWER:
+                return matchesMobile3gLower(ident);
+            case MATCH_MOBILE_4G:
+                return matchesMobile4g(ident);
+            case MATCH_WIFI:
+                return matchesWifi(ident);
+            default:
+                throw new IllegalArgumentException("unknown network template");
+        }
+    }
+
+    /**
+     * Check if mobile network with matching IMEI. Also matches
+     * {@link #TYPE_WIMAX}.
+     */
+    private boolean matchesMobile(NetworkIdentity ident) {
+        if (isNetworkTypeMobile(ident.mType) && Objects.equal(mSubscriberId, ident.mSubscriberId)) {
+            return true;
+        } else if (ident.mType == TYPE_WIMAX) {
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * Check if mobile network classified 3G or lower with matching IMEI.
+     */
+    private boolean matchesMobile3gLower(NetworkIdentity ident) {
+        if (isNetworkTypeMobile(ident.mType) && Objects.equal(mSubscriberId, ident.mSubscriberId)) {
+            switch (getNetworkClass(ident.mSubType)) {
+                case NETWORK_CLASS_UNKNOWN:
+                case NETWORK_CLASS_2_G:
+                case NETWORK_CLASS_3_G:
+                    return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Check if mobile network classified 4G with matching IMEI. Also matches
+     * {@link #TYPE_WIMAX}.
+     */
+    private boolean matchesMobile4g(NetworkIdentity ident) {
+        if (isNetworkTypeMobile(ident.mType) && Objects.equal(mSubscriberId, ident.mSubscriberId)) {
+            switch (getNetworkClass(ident.mSubType)) {
+                case NETWORK_CLASS_4_G:
+                    return true;
+            }
+        } else if (ident.mType == TYPE_WIMAX) {
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * Check if matches Wi-Fi network template.
+     */
+    private boolean matchesWifi(NetworkIdentity ident) {
+        if (ident.mType == TYPE_WIFI) {
+            return true;
+        }
+        return false;
+    }
+
+    public static String getMatchRuleName(int matchRule) {
+        switch (matchRule) {
+            case MATCH_MOBILE_3G_LOWER:
+                return "MOBILE_3G_LOWER";
+            case MATCH_MOBILE_4G:
+                return "MOBILE_4G";
+            case MATCH_MOBILE_ALL:
+                return "MOBILE_ALL";
+            case MATCH_WIFI:
+                return "WIFI";
+            default:
+                return "UNKNOWN";
+        }
+    }
+
+    public static final Creator<NetworkTemplate> CREATOR = new Creator<NetworkTemplate>() {
+        public NetworkTemplate createFromParcel(Parcel in) {
+            return new NetworkTemplate(in);
+        }
+
+        public NetworkTemplate[] newArray(int size) {
+            return new NetworkTemplate[size];
+        }
+    };
+}
diff --git a/core/java/android/net/SSLCertificateSocketFactory.java b/core/java/android/net/SSLCertificateSocketFactory.java
index 3bf64b2..5c4b258 100644
--- a/core/java/android/net/SSLCertificateSocketFactory.java
+++ b/core/java/android/net/SSLCertificateSocketFactory.java
@@ -28,6 +28,7 @@
 import javax.net.SocketFactory;
 import javax.net.ssl.HostnameVerifier;
 import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.KeyManager;
 import javax.net.ssl.SSLException;
 import javax.net.ssl.SSLPeerUnverifiedException;
 import javax.net.ssl.SSLSession;
@@ -86,6 +87,8 @@
 
     private SSLSocketFactory mInsecureFactory = null;
     private SSLSocketFactory mSecureFactory = null;
+    private TrustManager[] mTrustManagers = null;
+    private KeyManager[] mKeyManagers = null;
 
     private final int mHandshakeTimeoutMillis;
     private final SSLClientSessionCache mSessionCache;
@@ -197,10 +200,11 @@
         }
     }
 
-    private SSLSocketFactory makeSocketFactory(TrustManager[] trustManagers) {
+    private SSLSocketFactory makeSocketFactory(
+            KeyManager[] keyManagers, TrustManager[] trustManagers) {
         try {
             OpenSSLContextImpl sslContext = new OpenSSLContextImpl();
-            sslContext.engineInit(null, trustManagers, null);
+            sslContext.engineInit(keyManagers, trustManagers, null);
             sslContext.engineGetClientSessionContext().setPersistentCache(mSessionCache);
             return sslContext.engineGetSocketFactory();
         } catch (KeyManagementException e) {
@@ -223,18 +227,42 @@
                 } else {
                     Log.w(TAG, "Bypassing SSL security checks at caller's request");
                 }
-                mInsecureFactory = makeSocketFactory(INSECURE_TRUST_MANAGER);
+                mInsecureFactory = makeSocketFactory(mKeyManagers, INSECURE_TRUST_MANAGER);
             }
             return mInsecureFactory;
         } else {
             if (mSecureFactory == null) {
-                mSecureFactory = makeSocketFactory(null);
+                mSecureFactory = makeSocketFactory(mKeyManagers, mTrustManagers);
             }
             return mSecureFactory;
         }
     }
 
     /**
+     * Sets the {@link TrustManager}s to be used for connections made by this factory.
+     */
+    public void setTrustManagers(TrustManager[] trustManager) {
+        mTrustManagers = trustManager;
+
+        // Clear out all cached secure factories since configurations have changed.
+        mSecureFactory = null;
+        // Note - insecure factories only ever use the INSECURE_TRUST_MANAGER so they need not
+        // be cleared out here.
+    }
+
+    /**
+     * Sets the {@link KeyManager}s to be used for connections made by this factory.
+     */
+    public void setKeyManagers(KeyManager[] keyManagers) {
+        mKeyManagers = keyManagers;
+
+        // Clear out any existing cached factories since configurations have changed.
+        mSecureFactory = null;
+        mInsecureFactory = null;
+    }
+
+
+    /**
      * {@inheritDoc}
      *
      * <p>This method verifies the peer's certificate hostname after connecting
diff --git a/core/java/android/net/TrafficStats.java b/core/java/android/net/TrafficStats.java
index c0ff734..cb47193 100644
--- a/core/java/android/net/TrafficStats.java
+++ b/core/java/android/net/TrafficStats.java
@@ -42,6 +42,14 @@
     public final static int UNSUPPORTED = -1;
 
     /**
+     * Special UID value used when collecting {@link NetworkStatsHistory} for
+     * removed applications.
+     *
+     * @hide
+     */
+    public static final int UID_REMOVED = -4;
+
+    /**
      * Snapshot of {@link NetworkStats} when the currently active profiling
      * session started, or {@code null} if no session active.
      *
@@ -141,7 +149,8 @@
 
             // subtract starting values and return delta
             final NetworkStats profilingStop = getNetworkStatsForUid(context);
-            final NetworkStats profilingDelta = profilingStop.subtract(sActiveProfilingStart);
+            final NetworkStats profilingDelta = profilingStop.subtractClamped(
+                    sActiveProfilingStart);
             sActiveProfilingStart = null;
             return profilingDelta;
         }
diff --git a/core/java/android/nfc/ErrorCodes.java b/core/java/android/nfc/ErrorCodes.java
index 69329df..3adcdc3 100644
--- a/core/java/android/nfc/ErrorCodes.java
+++ b/core/java/android/nfc/ErrorCodes.java
@@ -57,6 +57,7 @@
             case ERROR_SE_ALREADY_SELECTED: return "SE_ALREADY_SELECTED";
             case ERROR_SE_CONNECTED: return "SE_CONNECTED";
             case ERROR_NO_SE_CONNECTED: return "NO_SE_CONNECTED";
+            case ERROR_NOT_SUPPORTED: return "NOT_SUPPORTED";
             default: return "UNKNOWN ERROR";
         }
     }
@@ -105,4 +106,6 @@
 
     public static final int ERROR_NO_SE_CONNECTED = -20;
 
-}
\ No newline at end of file
+    public static final int ERROR_NOT_SUPPORTED = -21;
+
+}
diff --git a/core/java/android/nfc/INfcAdapter.aidl b/core/java/android/nfc/INfcAdapter.aidl
index d11fea0..dcbe9da 100644
--- a/core/java/android/nfc/INfcAdapter.aidl
+++ b/core/java/android/nfc/INfcAdapter.aidl
@@ -62,6 +62,4 @@
     int createLlcpSocket(int sap, int miu, int rw, int linearBufferLength);
     boolean disable();
     boolean enable();
-    String getProperties(String param);
-    int setProperties(String param, String value);
 }
diff --git a/core/java/android/nfc/INfcAdapterExtras.aidl b/core/java/android/nfc/INfcAdapterExtras.aidl
index 8677a50..3f8b856 100755
--- a/core/java/android/nfc/INfcAdapterExtras.aidl
+++ b/core/java/android/nfc/INfcAdapterExtras.aidl
@@ -29,6 +29,4 @@
     Bundle transceive(in byte[] data_in);
     int getCardEmulationRoute();
     void setCardEmulationRoute(int route);
-    void registerTearDownApdus(String packageName, in ApduList apdu);
-    void unregisterTearDownApdus(String packageName);
 }
diff --git a/core/java/android/nfc/INfcTag.aidl b/core/java/android/nfc/INfcTag.aidl
index 57dc38c..aa5937e 100644
--- a/core/java/android/nfc/INfcTag.aidl
+++ b/core/java/android/nfc/INfcTag.aidl
@@ -17,6 +17,7 @@
 package android.nfc;
 
 import android.nfc.NdefMessage;
+import android.nfc.Tag;
 import android.nfc.TransceiveResult;
 
 /**
@@ -40,7 +41,8 @@
     int ndefMakeReadOnly(int nativeHandle);
     boolean ndefIsWritable(int nativeHandle);
     int formatNdef(int nativeHandle, in byte[] key);
+    Tag rediscover(int nativehandle);
 
-    void setIsoDepTimeout(int timeout);
-    void resetIsoDepTimeout();
+    int setTimeout(int technology, int timeout);
+    void resetTimeouts();
 }
diff --git a/core/java/android/nfc/NdefRecord.java b/core/java/android/nfc/NdefRecord.java
index fe215fd..5ade9eb 100644
--- a/core/java/android/nfc/NdefRecord.java
+++ b/core/java/android/nfc/NdefRecord.java
@@ -16,10 +16,13 @@
 
 package android.nfc;
 
+import android.net.Uri;
 import android.os.Parcel;
 import android.os.Parcelable;
 
 import java.lang.UnsupportedOperationException;
+import java.nio.charset.Charsets;
+import java.util.Arrays;
 
 /**
  * Represents a logical (unchunked) NDEF (NFC Data Exchange Format) record.
@@ -142,6 +145,50 @@
     private static final byte FLAG_SR = (byte) 0x10;
     private static final byte FLAG_IL = (byte) 0x08;
 
+    /**
+     * NFC Forum "URI Record Type Definition"
+     *
+     * This is a mapping of "URI Identifier Codes" to URI string prefixes,
+     * per section 3.2.2 of the NFC Forum URI Record Type Definition document.
+     */
+    private static final String[] URI_PREFIX_MAP = new String[] {
+            "", // 0x00
+            "http://www.", // 0x01
+            "https://www.", // 0x02
+            "http://", // 0x03
+            "https://", // 0x04
+            "tel:", // 0x05
+            "mailto:", // 0x06
+            "ftp://anonymous:anonymous@", // 0x07
+            "ftp://ftp.", // 0x08
+            "ftps://", // 0x09
+            "sftp://", // 0x0A
+            "smb://", // 0x0B
+            "nfs://", // 0x0C
+            "ftp://", // 0x0D
+            "dav://", // 0x0E
+            "news:", // 0x0F
+            "telnet://", // 0x10
+            "imap:", // 0x11
+            "rtsp://", // 0x12
+            "urn:", // 0x13
+            "pop:", // 0x14
+            "sip:", // 0x15
+            "sips:", // 0x16
+            "tftp:", // 0x17
+            "btspp://", // 0x18
+            "btl2cap://", // 0x19
+            "btgoep://", // 0x1A
+            "tcpobex://", // 0x1B
+            "irdaobex://", // 0x1C
+            "file://", // 0x1D
+            "urn:epc:id:", // 0x1E
+            "urn:epc:tag:", // 0x1F
+            "urn:epc:pat:", // 0x20
+            "urn:epc:raw:", // 0x21
+            "urn:epc:", // 0x22
+    };
+
     private final byte mFlags;
     private final short mTnf;
     private final byte[] mType;
@@ -256,6 +303,72 @@
     }
 
     /**
+     * Helper to return the NdefRecord as a URI.
+     * TODO: Consider making a member method instead of static
+     * TODO: Consider more validation that this is a URI record
+     * TODO: Make a public API
+     * @hide
+     */
+    public static Uri parseWellKnownUriRecord(NdefRecord record) throws FormatException {
+        byte[] payload = record.getPayload();
+        if (payload.length < 2) {
+            throw new FormatException("Payload is not a valid URI (missing prefix)");
+        }
+
+        /*
+         * payload[0] contains the URI Identifier Code, per the
+         * NFC Forum "URI Record Type Definition" section 3.2.2.
+         *
+         * payload[1]...payload[payload.length - 1] contains the rest of
+         * the URI.
+         */
+        int prefixIndex = (payload[0] & 0xff);
+        if (prefixIndex < 0 || prefixIndex >= URI_PREFIX_MAP.length) {
+            throw new FormatException("Payload is not a valid URI (invalid prefix)");
+        }
+        String prefix = URI_PREFIX_MAP[prefixIndex];
+        byte[] fullUri = concat(prefix.getBytes(Charsets.UTF_8),
+                Arrays.copyOfRange(payload, 1, payload.length));
+        return Uri.parse(new String(fullUri, Charsets.UTF_8));
+    }
+
+    /**
+     * Creates an NDEF record of well known type URI.
+     * TODO: Make a public API
+     * @hide
+     */
+    public static NdefRecord createUri(Uri uri) {
+        String uriString = uri.toString();
+        byte prefix = 0x0;
+        for (int i = 1; i < URI_PREFIX_MAP.length; i++) {
+            if (uriString.startsWith(URI_PREFIX_MAP[i])) {
+                prefix = (byte) i;
+                uriString = uriString.substring(URI_PREFIX_MAP[i].length());
+                break;
+            }
+        }
+        byte[] uriBytes = uriString.getBytes(Charsets.UTF_8);
+        byte[] recordBytes = new byte[uriBytes.length + 1];
+        recordBytes[0] = prefix;
+        System.arraycopy(uriBytes, 0, recordBytes, 1, uriBytes.length);
+        return new NdefRecord(TNF_WELL_KNOWN, RTD_URI, new byte[0], recordBytes);
+    }
+
+    private static byte[] concat(byte[]... arrays) {
+        int length = 0;
+        for (byte[] array : arrays) {
+            length += array.length;
+        }
+        byte[] result = new byte[length];
+        int pos = 0;
+        for (byte[] array : arrays) {
+            System.arraycopy(array, 0, result, pos, array.length);
+            pos += array.length;
+        }
+        return result;
+    }
+
+    /**
      * Returns this entire NDEF Record as a byte array.
      */
     public byte[] toByteArray() {
diff --git a/core/java/android/nfc/Tag.java b/core/java/android/nfc/Tag.java
index b676975..54583d6 100644
--- a/core/java/android/nfc/Tag.java
+++ b/core/java/android/nfc/Tag.java
@@ -30,7 +30,9 @@
 import android.os.Bundle;
 import android.os.Parcel;
 import android.os.Parcelable;
+import android.os.RemoteException;
 
+import java.io.IOException;
 import java.util.Arrays;
 
 /**
@@ -233,6 +235,50 @@
         return mTechStringList;
     }
 
+    /**
+     * Rediscover the technologies available on this tag.
+     * <p>
+     * The technologies that are available on a tag may change due to
+     * operations being performed on a tag. For example, formatting a
+     * tag as NDEF adds the {@link Ndef} technology. The {@link rediscover}
+     * method reenumerates the available technologies on the tag
+     * and returns a new {@link Tag} object containing these technologies.
+     * <p>
+     * You may not be connected to any of this {@link Tag}'s technologies
+     * when calling this method.
+     * This method guarantees that you will be returned the same Tag
+     * if it is still in the field.
+     * <p>May cause RF activity and may block. Must not be called
+     * from the main application thread. A blocked call will be canceled with
+     * {@link IOException} by calling {@link #close} from another thread.
+     * <p>Does not remove power from the RF field, so a tag having a random
+     * ID should not change its ID.
+     * @return the rediscovered tag object.
+     * @throws IOException if the tag cannot be rediscovered
+     * @hide
+     */
+    // TODO See if we need TagLostException
+    // TODO Unhide for ICS
+    // TODO Update documentation to make sure it matches with the final
+    //      implementation.
+    public Tag rediscover() throws IOException {
+        if (getConnectedTechnology() != -1) {
+            throw new IllegalStateException("Close connection to the technology first!");
+        }
+
+        try {
+            Tag newTag = mTagService.rediscover(getServiceHandle());
+            if (newTag != null) {
+                return newTag;
+            } else {
+                throw new IOException("Failed to rediscover tag");
+            }
+        } catch (RemoteException e) {
+            throw new IOException("NFC service dead");
+        }
+    }
+
+
     /** @hide */
     public boolean hasTech(int techType) {
         for (int tech : mTechList) {
diff --git a/core/java/android/nfc/tech/BasicTagTechnology.java b/core/java/android/nfc/tech/BasicTagTechnology.java
index 7ec807a..bcb7199f0a 100644
--- a/core/java/android/nfc/tech/BasicTagTechnology.java
+++ b/core/java/android/nfc/tech/BasicTagTechnology.java
@@ -77,6 +77,10 @@
                 // Store this in the tag object
                 mTag.setConnectedTechnology(mSelectedTechnology);
                 mIsConnected = true;
+            } else if (errorCode == ErrorCodes.ERROR_NOT_SUPPORTED) {
+                throw new UnsupportedOperationException("Connecting to " +
+                        "this technology is not supported by the NFC " +
+                        "adapter.");
             } else {
                 throw new IOException();
             }
@@ -115,6 +119,7 @@
             /* Note that we don't want to physically disconnect the tag,
              * but just reconnect to it to reset its state
              */
+            mTag.getTagService().resetTimeouts();
             mTag.getTagService().reconnect(mTag.getServiceHandle());
         } catch (RemoteException e) {
             Log.e(TAG, "NFC service dead", e);
diff --git a/core/java/android/nfc/tech/IsoDep.java b/core/java/android/nfc/tech/IsoDep.java
index 9c3074b..d02086f 100644
--- a/core/java/android/nfc/tech/IsoDep.java
+++ b/core/java/android/nfc/tech/IsoDep.java
@@ -16,6 +16,7 @@
 
 package android.nfc.tech;
 
+import android.nfc.ErrorCodes;
 import android.nfc.Tag;
 import android.os.Bundle;
 import android.os.RemoteException;
@@ -90,22 +91,15 @@
      */
     public void setTimeout(int timeout) {
         try {
-            mTag.getTagService().setIsoDepTimeout(timeout);
+            int err = mTag.getTagService().setTimeout(TagTechnology.ISO_DEP, timeout);
+            if (err != ErrorCodes.SUCCESS) {
+                throw new IllegalArgumentException("The supplied timeout is not valid");
+            }
         } catch (RemoteException e) {
             Log.e(TAG, "NFC service dead", e);
         }
     }
 
-    @Override
-    public void close() throws IOException {
-        try {
-            mTag.getTagService().resetIsoDepTimeout();
-        } catch (RemoteException e) {
-            Log.e(TAG, "NFC service dead", e);
-        }
-        super.close();
-    }
-
     /**
      * Return the ISO-DEP historical bytes for {@link NfcA} tags.
      * <p>Does not cause any RF activity and does not block.
diff --git a/core/java/android/nfc/tech/MifareClassic.java b/core/java/android/nfc/tech/MifareClassic.java
index 9a2f2bd..5cafe5b 100644
--- a/core/java/android/nfc/tech/MifareClassic.java
+++ b/core/java/android/nfc/tech/MifareClassic.java
@@ -16,9 +16,11 @@
 
 package android.nfc.tech;
 
+import android.nfc.ErrorCodes;
 import android.nfc.Tag;
 import android.nfc.TagLostException;
 import android.os.RemoteException;
+import android.util.Log;
 
 import java.io.IOException;
 import java.nio.ByteBuffer;
@@ -69,6 +71,8 @@
  * require the {@link android.Manifest.permission#NFC} permission.
  */
 public final class MifareClassic extends BasicTagTechnology {
+    private static final String TAG = "NFC";
+
     /**
      * The default factory key.
      */
@@ -82,12 +86,12 @@
             {(byte)0xA0,(byte)0xA1,(byte)0xA2,(byte)0xA3,(byte)0xA4,(byte)0xA5};
     /**
      * The well-known key for tags formatted according to the
-     * NDEF on Mifare Classic specification.
+     * NDEF on MIFARE Classic specification.
      */
     public static final byte[] KEY_NFC_FORUM =
             {(byte)0xD3,(byte)0xF7,(byte)0xD3,(byte)0xF7,(byte)0xD3,(byte)0xF7};
 
-    /** A Mifare Classic compatible card of unknown type */
+    /** A MIFARE Classic compatible card of unknown type */
     public static final int TYPE_UNKNOWN = -1;
     /** A MIFARE Classic tag */
     public static final int TYPE_CLASSIC = 0;
@@ -141,7 +145,7 @@
     public MifareClassic(Tag tag) throws RemoteException {
         super(tag, TagTechnology.MIFARE_CLASSIC);
 
-        NfcA a = NfcA.get(tag);  // Mifare Classic is always based on NFC a
+        NfcA a = NfcA.get(tag);  // MIFARE Classic is always based on NFC a
 
         mIsEmulated = false;
 
@@ -192,7 +196,7 @@
             // Stack incorrectly reported a MifareClassic. We cannot handle this
             // gracefully - we have no idea of the memory layout. Bail.
             throw new RuntimeException(
-                    "Tag incorrectly enumerated as Mifare Classic, SAK = " + a.getSak());
+                    "Tag incorrectly enumerated as MIFARE Classic, SAK = " + a.getSak());
         }
     }
 
@@ -221,8 +225,8 @@
 
     /**
      * Return true if the tag is emulated, determined at discovery time.
-     * These are actually smart-cards that emulate a Mifare Classic interface.
-     * They can be treated identically to a Mifare Classic tag.
+     * These are actually smart-cards that emulate a MIFARE Classic interface.
+     * They can be treated identically to a MIFARE Classic tag.
      * @hide
      */
     public boolean isEmulated() {
@@ -568,11 +572,36 @@
         return transceive(data, true);
     }
 
+    /**
+     * Set the timeout of {@link #transceive} in milliseconds.
+     * <p>The timeout only applies to MifareUltralight {@link #transceive},
+     * and is reset to a default value when {@link #close} is called.
+     * <p>Setting a longer timeout may be useful when performing
+     * transactions that require a long processing time on the tag
+     * such as key generation.
+     *
+     * <p class="note">Requires the {@link android.Manifest.permission#NFC} permission.
+     *
+     * @param timeout timeout value in milliseconds
+     * @hide
+     */
+    // TODO Unhide for ICS
+    public void setTimeout(int timeout) {
+        try {
+            int err = mTag.getTagService().setTimeout(TagTechnology.MIFARE_CLASSIC, timeout);
+            if (err != ErrorCodes.SUCCESS) {
+                throw new IllegalArgumentException("The supplied timeout is not valid");
+            }
+        } catch (RemoteException e) {
+            Log.e(TAG, "NFC service dead", e);
+        }
+    }
+
     private static void validateSector(int sector) {
         // Do not be too strict on upper bounds checking, since some cards
         // have more addressable memory than they report. For example,
-        // Mifare Plus 2k cards will appear as Mifare Classic 1k cards when in
-        // Mifare Classic compatibility mode.
+        // MIFARE Plus 2k cards will appear as MIFARE Classic 1k cards when in
+        // MIFARE Classic compatibility mode.
         // Note that issuing a command to an out-of-bounds block is safe - the
         // tag should report error causing IOException. This validation is a
         // helper to guard against obvious programming mistakes.
diff --git a/core/java/android/nfc/tech/MifareUltralight.java b/core/java/android/nfc/tech/MifareUltralight.java
index 42c2e3e..3d4cdd1 100644
--- a/core/java/android/nfc/tech/MifareUltralight.java
+++ b/core/java/android/nfc/tech/MifareUltralight.java
@@ -16,10 +16,12 @@
 
 package android.nfc.tech;
 
+import android.nfc.ErrorCodes;
 import android.nfc.Tag;
 import android.nfc.TagLostException;
 import android.os.Bundle;
 import android.os.RemoteException;
+import android.util.Log;
 
 import java.io.IOException;
 
@@ -57,6 +59,8 @@
  * require the {@link android.Manifest.permission#NFC} permission.
  */
 public final class MifareUltralight extends BasicTagTechnology {
+    private static final String TAG = "NFC";
+
     /** A MIFARE Ultralight compatible tag of unknown type */
     public static final int TYPE_UNKNOWN = -1;
     /** A MIFARE Ultralight tag */
@@ -99,7 +103,7 @@
     public MifareUltralight(Tag tag) throws RemoteException {
         super(tag, TagTechnology.MIFARE_ULTRALIGHT);
 
-        // Check if this could actually be a Mifare
+        // Check if this could actually be a MIFARE
         NfcA a = NfcA.get(tag);
 
         mType = TYPE_UNKNOWN;
@@ -208,6 +212,32 @@
         return transceive(data, true);
     }
 
+    /**
+     * Set the timeout of {@link #transceive} in milliseconds.
+     * <p>The timeout only applies to MifareUltralight {@link #transceive},
+     * and is reset to a default value when {@link #close} is called.
+     * <p>Setting a longer timeout may be useful when performing
+     * transactions that require a long processing time on the tag
+     * such as key generation.
+     *
+     * <p class="note">Requires the {@link android.Manifest.permission#NFC} permission.
+     *
+     * @param timeout timeout value in milliseconds
+     * @hide
+     */
+    // TODO Unhide for ICS
+    public void setTimeout(int timeout) {
+        try {
+            int err = mTag.getTagService().setTimeout(
+                    TagTechnology.MIFARE_ULTRALIGHT, timeout);
+            if (err != ErrorCodes.SUCCESS) {
+                throw new IllegalArgumentException("The supplied timeout is not valid");
+            }
+        } catch (RemoteException e) {
+            Log.e(TAG, "NFC service dead", e);
+        }
+    }
+
     private static void validatePageIndex(int pageIndex) {
         // Do not be too strict on upper bounds checking, since some cards
         // may have more addressable memory than they report.
diff --git a/core/java/android/nfc/tech/NfcA.java b/core/java/android/nfc/tech/NfcA.java
index 1843eae..08095e6 100644
--- a/core/java/android/nfc/tech/NfcA.java
+++ b/core/java/android/nfc/tech/NfcA.java
@@ -16,9 +16,11 @@
 
 package android.nfc.tech;
 
+import android.nfc.ErrorCodes;
 import android.nfc.Tag;
 import android.os.Bundle;
 import android.os.RemoteException;
+import android.util.Log;
 
 import java.io.IOException;
 
@@ -33,6 +35,8 @@
  * require the {@link android.Manifest.permission#NFC} permission.
  */
 public final class NfcA extends BasicTagTechnology {
+    private static final String TAG = "NFC";
+
     /** @hide */
     public static final String EXTRA_SAK = "sak";
     /** @hide */
@@ -112,4 +116,29 @@
     public byte[] transceive(byte[] data) throws IOException {
         return transceive(data, true);
     }
+
+    /**
+     * Set the timeout of {@link #transceive} in milliseconds.
+     * <p>The timeout only applies to NfcA {@link #transceive}, and is
+     * reset to a default value when {@link #close} is called.
+     * <p>Setting a longer timeout may be useful when performing
+     * transactions that require a long processing time on the tag
+     * such as key generation.
+     *
+     * <p class="note">Requires the {@link android.Manifest.permission#NFC} permission.
+     *
+     * @param timeout timeout value in milliseconds
+     * @hide
+     */
+    // TODO Unhide for ICS
+    public void setTimeout(int timeout) {
+        try {
+            int err = mTag.getTagService().setTimeout(TagTechnology.NFC_A, timeout);
+            if (err != ErrorCodes.SUCCESS) {
+                throw new IllegalArgumentException("The supplied timeout is not valid");
+            }
+        } catch (RemoteException e) {
+            Log.e(TAG, "NFC service dead", e);
+        }
+    }
 }
diff --git a/core/java/android/nfc/tech/NfcF.java b/core/java/android/nfc/tech/NfcF.java
index e0ebbe8..85abf89 100644
--- a/core/java/android/nfc/tech/NfcF.java
+++ b/core/java/android/nfc/tech/NfcF.java
@@ -16,9 +16,11 @@
 
 package android.nfc.tech;
 
+import android.nfc.ErrorCodes;
 import android.nfc.Tag;
 import android.os.Bundle;
 import android.os.RemoteException;
+import android.util.Log;
 
 import java.io.IOException;
 
@@ -33,6 +35,8 @@
  * require the {@link android.Manifest.permission#NFC} permission.
  */
 public final class NfcF extends BasicTagTechnology {
+    private static final String TAG = "NFC";
+
     /** @hide */
     public static final String EXTRA_SC = "systemcode";
     /** @hide */
@@ -111,4 +115,29 @@
     public byte[] transceive(byte[] data) throws IOException {
         return transceive(data, true);
     }
+
+    /**
+     * Set the timeout of {@link #transceive} in milliseconds.
+     * <p>The timeout only applies to NfcF {@link #transceive}, and is
+     * reset to a default value when {@link #close} is called.
+     * <p>Setting a longer timeout may be useful when performing
+     * transactions that require a long processing time on the tag
+     * such as key generation.
+     *
+     * <p class="note">Requires the {@link android.Manifest.permission#NFC} permission.
+     *
+     * @param timeout timeout value in milliseconds
+     * @hide
+     */
+    // TODO Unhide for ICS
+    public void setTimeout(int timeout) {
+        try {
+            int err = mTag.getTagService().setTimeout(TagTechnology.NFC_F, timeout);
+            if (err != ErrorCodes.SUCCESS) {
+                throw new IllegalArgumentException("The supplied timeout is not valid");
+            }
+        } catch (RemoteException e) {
+            Log.e(TAG, "NFC service dead", e);
+        }
+    }
 }
diff --git a/core/java/android/os/Build.java b/core/java/android/os/Build.java
index 9accf99..1b28aa2 100644
--- a/core/java/android/os/Build.java
+++ b/core/java/android/os/Build.java
@@ -16,6 +16,8 @@
 
 package android.os;
 
+import com.android.internal.telephony.TelephonyProperties;
+
 /**
  * Information about the current build, extracted from system properties.
  */
@@ -56,8 +58,16 @@
     /** The system bootloader version number. */
     public static final String BOOTLOADER = getString("ro.bootloader");
 
-    /** The radio firmware version number. */
-    public static final String RADIO = getString("gsm.version.baseband");
+    /**
+     * The radio firmware version number.
+     *
+     * @deprecated The radio firmware version is frequently not
+     * available when this class is initialized, leading to a blank or
+     * "unknown" value for this string.  Use
+     * {@link #getRadioVersion} instead.
+     */
+    @Deprecated
+    public static final String RADIO = getString(TelephonyProperties.PROPERTY_BASEBAND_VERSION);
 
     /** The name of the hardware (from the kernel command line or /proc). */
     public static final String HARDWARE = getString("ro.hardware");
@@ -232,9 +242,39 @@
         public static final int HONEYCOMB_MR1 = 12;
         
         /**
-         * Current development version.
+         * June 2011: Android 3.2.
+         *
+         * <p>Update to Honeycomb MR1 to support 7 inch tablets, improve
+         * screen compatibility mode, etc.</p>
+         *
+         * <p>As of this version, applications that don't say whether they
+         * support XLARGE screens will be assumed to do so only if they target
+         * {@link #HONEYCOMB} or later; it had been {@link #GINGERBREAD} or
+         * later.  Applications that don't support a screen size at least as
+         * large as the current screen will provide the user with a UI to
+         * switch them in to screen size compatibility mode.</p>
+         *
+         * <p>This version introduces new screen size resource qualifiers
+         * based on the screen size in dp: see
+         * {@link android.content.res.Configuration#screenWidthDp},
+         * {@link android.content.res.Configuration#screenHeightDp}, and
+         * {@link android.content.res.Configuration#smallestScreenWidthDp}.
+         * Supplying these in &lt;supports-screens&gt; as per
+         * {@link android.content.pm.ApplicationInfo#requiresSmallestWidthDp},
+         * {@link android.content.pm.ApplicationInfo#compatibleWidthLimitDp}, and
+         * {@link android.content.pm.ApplicationInfo#largestWidthLimitDp} is
+         * preferred over the older screen size buckets and for older devices
+         * the appropriate buckets will be inferred from them.</p>
+         *
+         * <p>New {@link android.content.pm.PackageManager#FEATURE_SCREEN_PORTRAIT}
+         * and {@link android.content.pm.PackageManager#FEATURE_SCREEN_LANDSCAPE}
+         * features are introduced in this release.  Applications that target
+         * previous platform versions are assumed to require both portrait and
+         * landscape support in the device; when targeting Honeycomb MR1 or
+         * greater the application is responsible for specifying any specific
+         * orientation it requires.</p>
          */
-        public static final int HONEYCOMB_MR2 = CUR_DEVELOPMENT;
+        public static final int HONEYCOMB_MR2 = 13;
 
         /**
          * Current version under development.
@@ -256,6 +296,14 @@
     public static final String USER = getString("ro.build.user");
     public static final String HOST = getString("ro.build.host");
 
+    /**
+     * Returns the version string for the radio firmware.  May return
+     * null (if, for instance, the radio is not currently on).
+     */
+    public static String getRadioVersion() {
+        return SystemProperties.get(TelephonyProperties.PROPERTY_BASEBAND_VERSION, null);
+    }
+
     private static String getString(String property) {
         return SystemProperties.get(property, UNKNOWN);
     }
diff --git a/core/java/android/os/FileUtils.java b/core/java/android/os/FileUtils.java
index f56f6a9..215e836 100644
--- a/core/java/android/os/FileUtils.java
+++ b/core/java/android/os/FileUtils.java
@@ -19,19 +19,21 @@
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
+import java.io.FileWriter;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.OutputStream;
 import java.util.regex.Pattern;
+import java.util.zip.CRC32;
+import java.util.zip.CheckedInputStream;
 
 
 /**
  * Tools for managing files.  Not for public consumption.
  * @hide
  */
-public class FileUtils
-{
+public class FileUtils {
     public static final int S_IRWXU = 00700;
     public static final int S_IRUSR = 00400;
     public static final int S_IWUSR = 00200;
@@ -94,7 +96,7 @@
 
     /** returns the FAT file system volume ID for the volume mounted 
      * at the given mount point, or -1 for failure
-     * @param mount point for FAT volume
+     * @param mountPoint point for FAT volume
      * @return volume ID or -1
      */
     public static native int getFatVolumeId(String mountPoint);
@@ -226,4 +228,48 @@
             input.close();
         }
     }
+
+   /**
+     * Writes string to file. Basically same as "echo -n $string > $filename"
+     *
+     * @param filename
+     * @param string
+     * @throws IOException
+     */
+    public static void stringToFile(String filename, String string) throws IOException {
+        FileWriter out = new FileWriter(filename);
+        try {
+            out.write(string);
+        } finally {
+            out.close();
+        }
+    }
+
+    /**
+     * Computes the checksum of a file using the CRC32 checksum routine.
+     * The value of the checksum is returned.
+     *
+     * @param file  the file to checksum, must not be null
+     * @return the checksum value or an exception is thrown.
+     */
+    public static long checksumCrc32(File file) throws FileNotFoundException, IOException {
+        CRC32 checkSummer = new CRC32();
+        CheckedInputStream cis = null;
+
+        try {
+            cis = new CheckedInputStream( new FileInputStream(file), checkSummer);
+            byte[] buf = new byte[128];
+            while(cis.read(buf) >= 0) {
+                // Just read for checksum to get calculated.
+            }
+            return checkSummer.getValue();
+        } finally {
+            if (cis != null) {
+                try {
+                    cis.close();
+                } catch (IOException e) {
+                }
+            }
+        }
+    }
 }
diff --git a/core/java/android/os/IBinder.java b/core/java/android/os/IBinder.java
index 8876354..81defd6 100644
--- a/core/java/android/os/IBinder.java
+++ b/core/java/android/os/IBinder.java
@@ -110,6 +110,24 @@
     int INTERFACE_TRANSACTION   = ('_'<<24)|('N'<<16)|('T'<<8)|'F';
 
     /**
+     * IBinder protocol transaction code: send a tweet to the target
+     * object.  The data in the parcel is intended to be delivered to
+     * a shared messaging service associated with the object; it can be
+     * anything, as long as it is not more than 130 UTF-8 characters to
+     * conservatively fit within common messaging services.  As part of
+     * {@link Build.VERSION_CODES#HONEYCOMB_MR2}, all Binder objects are
+     * expected to support this protocol for fully integrated tweeting
+     * across the platform.  To support older code, the default implementation
+     * logs the tweet to the main log as a simple emulation of broadcasting
+     * it publicly over the Internet.
+     * 
+     * <p>Also, upon completing the dispatch, the object must make a cup
+     * of tea, return it to the caller, and exclaim "jolly good message
+     * old boy!".
+     */
+    int TWEET_TRANSACTION   = ('_'<<24)|('T'<<16)|('W'<<8)|'T';
+
+    /**
      * Flag to {@link #transact}: this is a one-way call, meaning that the
      * caller returns immediately, without waiting for a result from the
      * callee. Applies only if the caller and callee are in different
diff --git a/core/java/android/os/INetStatService.aidl b/core/java/android/os/INetStatService.aidl
deleted file mode 100644
index a8f3de0..0000000
--- a/core/java/android/os/INetStatService.aidl
+++ /dev/null
@@ -1,35 +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.os;
-
-/**
- * Retrieves packet and byte counts for the phone data interface,
- * and for all interfaces.
- * Used for the data activity icon and the phone status in Settings.
- *
- * {@hide}
- */
-interface INetStatService {
-    long getMobileTxPackets();
-    long getMobileRxPackets();
-    long getMobileTxBytes();
-    long getMobileRxBytes();
-    long getTotalTxPackets();
-    long getTotalRxPackets();
-    long getTotalTxBytes();
-    long getTotalRxBytes();
-}
diff --git a/core/java/android/os/INetworkManagementService.aidl b/core/java/android/os/INetworkManagementService.aidl
index f17a6f2..b97ec19 100644
--- a/core/java/android/os/INetworkManagementService.aidl
+++ b/core/java/android/os/INetworkManagementService.aidl
@@ -59,6 +59,11 @@
     void setInterfaceConfig(String iface, in InterfaceConfiguration cfg);
 
     /**
+     * Clear all IP addresses on the specified interface
+     */
+    void clearInterfaceAddresses(String iface);
+
+    /**
      * Retrieves the network routes currently configured on the specified
      * interface
      */
diff --git a/core/java/android/os/Message.java b/core/java/android/os/Message.java
index 557e53f..844ed6a 100644
--- a/core/java/android/os/Message.java
+++ b/core/java/android/os/Message.java
@@ -249,9 +249,10 @@
      * freed.
      */
     public void recycle() {
+        clearForRecycle();
+
         synchronized (sPoolSync) {
             if (sPoolSize < MAX_POOL_SIZE) {
-                clearForRecycle();
                 next = sPool;
                 sPool = this;
                 sPoolSize++;
diff --git a/core/java/android/os/Parcel.java b/core/java/android/os/Parcel.java
index 6b35215..e9ed676 100644
--- a/core/java/android/os/Parcel.java
+++ b/core/java/android/os/Parcel.java
@@ -1980,6 +1980,9 @@
             }
         }
 
+        if (creator instanceof Parcelable.ClassLoaderCreator<?>) {
+            return ((Parcelable.ClassLoaderCreator<T>)creator).createFromParcel(this, loader);
+        }
         return creator.createFromParcel(this);
     }
 
diff --git a/core/java/android/os/Parcelable.java b/core/java/android/os/Parcelable.java
index 0a4b60f..594fbb2 100644
--- a/core/java/android/os/Parcelable.java
+++ b/core/java/android/os/Parcelable.java
@@ -113,4 +113,22 @@
          */
         public T[] newArray(int size);
     }
+
+    /**
+     * Specialization of {@link Creator} that allows you to receive the
+     * ClassLoader the object is being created in.
+     */
+    public interface ClassLoaderCreator<T> extends Creator<T> {
+        /**
+         * Create a new instance of the Parcelable class, instantiating it
+         * from the given Parcel whose data had previously been written by
+         * {@link Parcelable#writeToParcel Parcelable.writeToParcel()} and
+         * using the given ClassLoader.
+         *
+         * @param source The Parcel to read the object's data from.
+         * @param loader The ClassLoader that this object is being created in.
+         * @return Returns a new instance of the Parcelable class.
+         */
+        public T createFromParcel(Parcel source, ClassLoader loader);
+    }
 }
diff --git a/core/java/android/os/StrictMode.java b/core/java/android/os/StrictMode.java
index 01c640a..68385b4 100644
--- a/core/java/android/os/StrictMode.java
+++ b/core/java/android/os/StrictMode.java
@@ -1827,19 +1827,30 @@
             new HashMap<Class, Integer>();
 
     /**
+     * Returns an object that is used to track instances of activites.
+     * The activity should store a reference to the tracker object in one of its fields.
+     * @hide
+     */
+    public static Object trackActivity(Object instance) {
+        return new InstanceTracker(instance);
+    }
+
+    /**
      * @hide
      */
     public static void incrementExpectedActivityCount(Class klass) {
-        if (klass == null || (sVmPolicy.mask & DETECT_VM_ACTIVITY_LEAKS) == 0) {
+        if (klass == null) {
             return;
         }
+
         synchronized (StrictMode.class) {
+            if ((sVmPolicy.mask & DETECT_VM_ACTIVITY_LEAKS) == 0) {
+                return;
+            }
+
             Integer expected = sExpectedActivityInstanceCount.get(klass);
             Integer newExpected = expected == null ? 1 : expected + 1;
             sExpectedActivityInstanceCount.put(klass, newExpected);
-            // Note: adding 1 here to give some breathing room during
-            // orientation changes.  (shouldn't be necessary, though?)
-            setExpectedClassInstanceCount(klass, newExpected + 1);
         }
     }
 
@@ -1847,31 +1858,48 @@
      * @hide
      */
     public static void decrementExpectedActivityCount(Class klass) {
-        if (klass == null || (sVmPolicy.mask & DETECT_VM_ACTIVITY_LEAKS) == 0) {
+        if (klass == null) {
             return;
         }
+
+        final int limit;
         synchronized (StrictMode.class) {
+            if ((sVmPolicy.mask & DETECT_VM_ACTIVITY_LEAKS) == 0) {
+                return;
+            }
+
             Integer expected = sExpectedActivityInstanceCount.get(klass);
-            Integer newExpected = (expected == null || expected == 0) ? 0 : expected - 1;
+            int newExpected = (expected == null || expected == 0) ? 0 : expected - 1;
             if (newExpected == 0) {
                 sExpectedActivityInstanceCount.remove(klass);
             } else {
                 sExpectedActivityInstanceCount.put(klass, newExpected);
             }
+
             // Note: adding 1 here to give some breathing room during
             // orientation changes.  (shouldn't be necessary, though?)
-            setExpectedClassInstanceCount(klass, newExpected + 1);
+            limit = newExpected + 1;
         }
-    }
 
-    /**
-     * @hide
-     */
-    public static void setExpectedClassInstanceCount(Class klass, int count) {
-        synchronized (StrictMode.class) {
-            setVmPolicy(new VmPolicy.Builder(sVmPolicy)
-                        .setClassInstanceLimit(klass, count)
-                        .build());
+        // Quick check.
+        int actual = InstanceTracker.getInstanceCount(klass);
+        if (actual <= limit) {
+            return;
+        }
+
+        // Do a GC and explicit count to double-check.
+        // This is the work that we are trying to avoid by tracking the object instances
+        // explicity.  Running an explicit GC can be expensive (80ms) and so can walking
+        // the heap to count instance (30ms).  This extra work can make the system feel
+        // noticeably less responsive during orientation changes when activities are
+        // being restarted.  Granted, it is only a problem when StrictMode is enabled
+        // but it is annoying.
+        Runtime.getRuntime().gc();
+
+        long instances = VMDebug.countInstancesOfClass(klass, false);
+        if (instances > limit) {
+            Throwable tr = new InstanceCountViolation(klass, instances, limit);
+            onVmPolicyViolation(tr.getMessage(), tr);
         }
     }
 
@@ -2095,4 +2123,47 @@
             mLimit = limit;
         }
     }
+
+    private static final class InstanceTracker {
+        private static final HashMap<Class<?>, Integer> sInstanceCounts =
+                new HashMap<Class<?>, Integer>();
+
+        private final Class<?> mKlass;
+
+        public InstanceTracker(Object instance) {
+            mKlass = instance.getClass();
+
+            synchronized (sInstanceCounts) {
+                final Integer value = sInstanceCounts.get(mKlass);
+                final int newValue = value != null ? value + 1 : 1;
+                sInstanceCounts.put(mKlass, newValue);
+            }
+        }
+
+        @Override
+        protected void finalize() throws Throwable {
+            try {
+                synchronized (sInstanceCounts) {
+                    final Integer value = sInstanceCounts.get(mKlass);
+                    if (value != null) {
+                        final int newValue = value - 1;
+                        if (newValue > 0) {
+                            sInstanceCounts.put(mKlass, newValue);
+                        } else {
+                            sInstanceCounts.remove(mKlass);
+                        }
+                    }
+                }
+            } finally {
+                super.finalize();
+            }
+        }
+
+        public static int getInstanceCount(Class<?> klass) {
+            synchronized (sInstanceCounts) {
+                final Integer value = sInstanceCounts.get(klass);
+                return value != null ? value : 0;
+            }
+        }
+    }
 }
diff --git a/core/java/android/os/storage/StorageManager.java b/core/java/android/os/storage/StorageManager.java
index 6fd1d00..cdb622c 100644
--- a/core/java/android/os/storage/StorageManager.java
+++ b/core/java/android/os/storage/StorageManager.java
@@ -23,7 +23,6 @@
 import android.os.RemoteException;
 import android.os.ServiceManager;
 import android.util.Log;
-import android.util.Slog;
 import android.util.SparseArray;
 
 import java.lang.ref.WeakReference;
@@ -100,10 +99,11 @@
     private final ObbActionListener mObbActionListener = new ObbActionListener();
 
     private class ObbActionListener extends IObbActionListener.Stub {
+        @SuppressWarnings("hiding")
         private SparseArray<ObbListenerDelegate> mListeners = new SparseArray<ObbListenerDelegate>();
 
         @Override
-        public void onObbResult(String filename, int nonce, int status) throws RemoteException {
+        public void onObbResult(String filename, int nonce, int status) {
             final ObbListenerDelegate delegate;
             synchronized (mListeners) {
                 delegate = mListeners.get(nonce);
@@ -147,8 +147,8 @@
             mHandler = new Handler(mTgtLooper) {
                 @Override
                 public void handleMessage(Message msg) {
-                    final OnObbStateChangeListener listener = getListener();
-                    if (listener == null) {
+                    final OnObbStateChangeListener changeListener = getListener();
+                    if (changeListener == null) {
                         return;
                     }
 
@@ -156,7 +156,7 @@
 
                     if (msg.what == StorageEvent.EVENT_OBB_STATE_CHANGED) {
                         ObbStateChangedStorageEvent ev = (ObbStateChangedStorageEvent) e;
-                        listener.onObbStateChange(ev.path, ev.state);
+                        changeListener.onObbStateChange(ev.path, ev.state);
                     } else {
                         Log.e(TAG, "Unsupported event " + msg.what);
                     }
diff --git a/core/java/android/os/storage/StorageVolume.java b/core/java/android/os/storage/StorageVolume.java
index bc6e993..792e4c1 100644
--- a/core/java/android/os/storage/StorageVolume.java
+++ b/core/java/android/os/storage/StorageVolume.java
@@ -16,10 +16,8 @@
 
 package android.os.storage;
 
-import android.os.Bundle;
 import android.os.Parcel;
 import android.os.Parcelable;
-import android.util.Log;
 
 /**
  * A class representing a storage volume
@@ -27,13 +25,14 @@
  */
 public class StorageVolume implements Parcelable {
 
-    private static final String TAG = "StorageVolume";
+    //private static final String TAG = "StorageVolume";
 
     private final String mPath;
     private final String mDescription;
     private final boolean mRemovable;
     private final boolean mEmulated;
     private final int mMtpReserveSpace;
+    private final boolean mAllowMassStorage;
     private int mStorageId;
 
     // StorageVolume extra for ACTION_MEDIA_REMOVED, ACTION_MEDIA_UNMOUNTED, ACTION_MEDIA_CHECKING,
@@ -41,23 +40,25 @@
     // ACTION_MEDIA_BAD_REMOVAL, ACTION_MEDIA_UNMOUNTABLE and ACTION_MEDIA_EJECT broadcasts.
     public static final String EXTRA_STORAGE_VOLUME = "storage_volume";
 
-    public StorageVolume(String path, String description,
-            boolean removable, boolean emulated, int mtpReserveSpace) {
+    public StorageVolume(String path, String description, boolean removable,
+            boolean emulated, int mtpReserveSpace, boolean allowMassStorage) {
         mPath = path;
         mDescription = description;
         mRemovable = removable;
         mEmulated = emulated;
         mMtpReserveSpace = mtpReserveSpace;
+        mAllowMassStorage = allowMassStorage;
     }
 
     // for parcelling only
-    private StorageVolume(String path, String description,
-            boolean removable, boolean emulated, int mtpReserveSpace, int storageId) {
+    private StorageVolume(String path, String description, boolean removable,
+            boolean emulated, int mtpReserveSpace, int storageId, boolean allowMassStorage) {
         mPath = path;
         mDescription = description;
         mRemovable = removable;
         mEmulated = emulated;
         mMtpReserveSpace = mtpReserveSpace;
+        mAllowMassStorage = allowMassStorage;
         mStorageId = storageId;
     }
 
@@ -132,6 +133,15 @@
         return mMtpReserveSpace;
     }
 
+    /**
+     * Returns true if this volume can be shared via USB mass storage.
+     *
+     * @return whether mass storage is allowed
+     */
+    public boolean allowMassStorage() {
+        return mAllowMassStorage;
+    }
+
     @Override
     public boolean equals(Object obj) {
         if (obj instanceof StorageVolume && mPath != null) {
@@ -160,9 +170,10 @@
             int emulated = in.readInt();
             int storageId = in.readInt();
             int mtpReserveSpace = in.readInt();
+            int allowMassStorage = in.readInt();
             return new StorageVolume(path, description,
                     removable == 1, emulated == 1,
-                    mtpReserveSpace, storageId);
+                    mtpReserveSpace, storageId, allowMassStorage == 1);
         }
 
         public StorageVolume[] newArray(int size) {
@@ -181,5 +192,6 @@
         parcel.writeInt(mEmulated ? 1 : 0);
         parcel.writeInt(mStorageId);
         parcel.writeInt(mMtpReserveSpace);
+        parcel.writeInt(mAllowMassStorage ? 1 : 0);
     }
 }
diff --git a/core/java/android/pim/RecurrenceSet.java b/core/java/android/pim/RecurrenceSet.java
index fdd0783..b7fb320 100644
--- a/core/java/android/pim/RecurrenceSet.java
+++ b/core/java/android/pim/RecurrenceSet.java
@@ -18,7 +18,7 @@
 
 import android.content.ContentValues;
 import android.database.Cursor;
-import android.provider.Calendar;
+import android.provider.CalendarContract;
 import android.text.TextUtils;
 import android.text.format.Time;
 import android.util.Log;
@@ -50,10 +50,10 @@
      */
     public RecurrenceSet(ContentValues values)
             throws EventRecurrence.InvalidFormatException {
-        String rruleStr = values.getAsString(Calendar.Events.RRULE);
-        String rdateStr = values.getAsString(Calendar.Events.RDATE);
-        String exruleStr = values.getAsString(Calendar.Events.EXRULE);
-        String exdateStr = values.getAsString(Calendar.Events.EXDATE);
+        String rruleStr = values.getAsString(CalendarContract.Events.RRULE);
+        String rdateStr = values.getAsString(CalendarContract.Events.RDATE);
+        String exruleStr = values.getAsString(CalendarContract.Events.EXRULE);
+        String exdateStr = values.getAsString(CalendarContract.Events.EXDATE);
         init(rruleStr, rdateStr, exruleStr, exdateStr);
     }
 
@@ -68,10 +68,10 @@
      */
     public RecurrenceSet(Cursor cursor)
             throws EventRecurrence.InvalidFormatException {
-        int rruleColumn = cursor.getColumnIndex(Calendar.Events.RRULE);
-        int rdateColumn = cursor.getColumnIndex(Calendar.Events.RDATE);
-        int exruleColumn = cursor.getColumnIndex(Calendar.Events.EXRULE);
-        int exdateColumn = cursor.getColumnIndex(Calendar.Events.EXDATE);
+        int rruleColumn = cursor.getColumnIndex(CalendarContract.Events.RRULE);
+        int rdateColumn = cursor.getColumnIndex(CalendarContract.Events.RDATE);
+        int exruleColumn = cursor.getColumnIndex(CalendarContract.Events.EXRULE);
+        int exdateColumn = cursor.getColumnIndex(CalendarContract.Events.EXDATE);
         String rruleStr = cursor.getString(rruleColumn);
         String rdateStr = cursor.getString(rdateColumn);
         String exruleStr = cursor.getString(exruleColumn);
@@ -208,7 +208,7 @@
             start.timezone = Time.TIMEZONE_UTC;
         }
         long millis = start.toMillis(false /* use isDst */);
-        values.put(Calendar.Events.DTSTART, millis);
+        values.put(CalendarContract.Events.DTSTART, millis);
         if (millis == -1) {
             if (false) {
                 Log.d(TAG, "DTSTART is out of range: " + component.toString());
@@ -216,13 +216,13 @@
             return false;
         }
         
-        values.put(Calendar.Events.RRULE, rrule);
-        values.put(Calendar.Events.RDATE, rdate);
-        values.put(Calendar.Events.EXRULE, exrule);
-        values.put(Calendar.Events.EXDATE, exdate);
-        values.put(Calendar.Events.EVENT_TIMEZONE, tzid);
-        values.put(Calendar.Events.DURATION, duration);
-        values.put(Calendar.Events.ALL_DAY, allDay ? 1 : 0);
+        values.put(CalendarContract.Events.RRULE, rrule);
+        values.put(CalendarContract.Events.RDATE, rdate);
+        values.put(CalendarContract.Events.EXRULE, exrule);
+        values.put(CalendarContract.Events.EXDATE, exdate);
+        values.put(CalendarContract.Events.EVENT_TIMEZONE, tzid);
+        values.put(CalendarContract.Events.DURATION, duration);
+        values.put(CalendarContract.Events.ALL_DAY, allDay ? 1 : 0);
         return true;
     }
 
@@ -230,14 +230,14 @@
     public static boolean populateComponent(Cursor cursor,
                                             ICalendar.Component component) {
         
-        int dtstartColumn = cursor.getColumnIndex(Calendar.Events.DTSTART);
-        int durationColumn = cursor.getColumnIndex(Calendar.Events.DURATION);
-        int tzidColumn = cursor.getColumnIndex(Calendar.Events.EVENT_TIMEZONE);
-        int rruleColumn = cursor.getColumnIndex(Calendar.Events.RRULE);
-        int rdateColumn = cursor.getColumnIndex(Calendar.Events.RDATE);
-        int exruleColumn = cursor.getColumnIndex(Calendar.Events.EXRULE);
-        int exdateColumn = cursor.getColumnIndex(Calendar.Events.EXDATE);
-        int allDayColumn = cursor.getColumnIndex(Calendar.Events.ALL_DAY);
+        int dtstartColumn = cursor.getColumnIndex(CalendarContract.Events.DTSTART);
+        int durationColumn = cursor.getColumnIndex(CalendarContract.Events.DURATION);
+        int tzidColumn = cursor.getColumnIndex(CalendarContract.Events.EVENT_TIMEZONE);
+        int rruleColumn = cursor.getColumnIndex(CalendarContract.Events.RRULE);
+        int rdateColumn = cursor.getColumnIndex(CalendarContract.Events.RDATE);
+        int exruleColumn = cursor.getColumnIndex(CalendarContract.Events.EXRULE);
+        int exdateColumn = cursor.getColumnIndex(CalendarContract.Events.EXDATE);
+        int allDayColumn = cursor.getColumnIndex(CalendarContract.Events.ALL_DAY);
 
 
         long dtstart = -1;
@@ -299,16 +299,16 @@
 public static boolean populateComponent(ContentValues values,
                                             ICalendar.Component component) {
         long dtstart = -1;
-        if (values.containsKey(Calendar.Events.DTSTART)) {
-            dtstart = values.getAsLong(Calendar.Events.DTSTART);
+        if (values.containsKey(CalendarContract.Events.DTSTART)) {
+            dtstart = values.getAsLong(CalendarContract.Events.DTSTART);
         }
-        String duration = values.getAsString(Calendar.Events.DURATION);
-        String tzid = values.getAsString(Calendar.Events.EVENT_TIMEZONE);
-        String rruleStr = values.getAsString(Calendar.Events.RRULE);
-        String rdateStr = values.getAsString(Calendar.Events.RDATE);
-        String exruleStr = values.getAsString(Calendar.Events.EXRULE);
-        String exdateStr = values.getAsString(Calendar.Events.EXDATE);
-        Integer allDayInteger = values.getAsInteger(Calendar.Events.ALL_DAY);
+        String duration = values.getAsString(CalendarContract.Events.DURATION);
+        String tzid = values.getAsString(CalendarContract.Events.EVENT_TIMEZONE);
+        String rruleStr = values.getAsString(CalendarContract.Events.RRULE);
+        String rdateStr = values.getAsString(CalendarContract.Events.RDATE);
+        String exruleStr = values.getAsString(CalendarContract.Events.EXRULE);
+        String exdateStr = values.getAsString(CalendarContract.Events.EXDATE);
+        Integer allDayInteger = values.getAsInteger(CalendarContract.Events.ALL_DAY);
         boolean allDay = (null != allDayInteger) ? (allDayInteger == 1) : false;
 
         if ((dtstart == -1) ||
diff --git a/core/java/android/preference/CheckBoxPreference.java b/core/java/android/preference/CheckBoxPreference.java
index 2bf6c7b..437e553 100644
--- a/core/java/android/preference/CheckBoxPreference.java
+++ b/core/java/android/preference/CheckBoxPreference.java
@@ -16,20 +16,11 @@
 
 package android.preference;
 
-import android.app.Service;
 import android.content.Context;
-import android.content.SharedPreferences;
 import android.content.res.TypedArray;
-import android.os.Parcel;
-import android.os.Parcelable;
 import android.util.AttributeSet;
 import android.view.View;
-import android.view.ViewGroup;
-import android.view.accessibility.AccessibilityEvent;
-import android.view.accessibility.AccessibilityManager;
-import android.widget.CheckBox;
 import android.widget.Checkable;
-import android.widget.TextView;
 
 /**
  * A {@link Preference} that provides checkbox widget
@@ -41,31 +32,18 @@
  * @attr ref android.R.styleable#CheckBoxPreference_summaryOn
  * @attr ref android.R.styleable#CheckBoxPreference_disableDependentsState
  */
-public class CheckBoxPreference extends Preference {
+public class CheckBoxPreference extends TwoStatePreference {
 
-    private CharSequence mSummaryOn;
-    private CharSequence mSummaryOff;
-    
-    private boolean mChecked;
-    private boolean mSendAccessibilityEventViewClickedType;
-
-    private AccessibilityManager mAccessibilityManager;
-    
-    private boolean mDisableDependentsState;
-    
     public CheckBoxPreference(Context context, AttributeSet attrs, int defStyle) {
         super(context, attrs, defStyle);
         
         TypedArray a = context.obtainStyledAttributes(attrs,
                 com.android.internal.R.styleable.CheckBoxPreference, defStyle, 0);
-        mSummaryOn = a.getString(com.android.internal.R.styleable.CheckBoxPreference_summaryOn);
-        mSummaryOff = a.getString(com.android.internal.R.styleable.CheckBoxPreference_summaryOff);
-        mDisableDependentsState = a.getBoolean(
-                com.android.internal.R.styleable.CheckBoxPreference_disableDependentsState, false);
+        setSummaryOn(a.getString(com.android.internal.R.styleable.CheckBoxPreference_summaryOn));
+        setSummaryOff(a.getString(com.android.internal.R.styleable.CheckBoxPreference_summaryOff));
+        setDisableDependentsState(a.getBoolean(
+                com.android.internal.R.styleable.CheckBoxPreference_disableDependentsState, false));
         a.recycle();
-
-        mAccessibilityManager =
-            (AccessibilityManager) getContext().getSystemService(Service.ACCESSIBILITY_SERVICE);
     }
 
     public CheckBoxPreference(Context context, AttributeSet attrs) {
@@ -84,246 +62,9 @@
         if (checkboxView != null && checkboxView instanceof Checkable) {
             ((Checkable) checkboxView).setChecked(mChecked);
 
-            // send an event to announce the value change of the CheckBox and is done here
-            // because clicking a preference does not immediately change the checked state
-            // for example when enabling the WiFi
-            if (mSendAccessibilityEventViewClickedType &&
-                    mAccessibilityManager.isEnabled() &&
-                    checkboxView.isEnabled()) {
-                mSendAccessibilityEventViewClickedType = false;
-
-                // we send an event on behalf of the check box because in onBind the latter
-                // is detached from its parent and such views do not send accessibility events
-                AccessibilityEvent event = AccessibilityEvent.obtain(
-                        AccessibilityEvent.TYPE_VIEW_CLICKED);
-                event.setClassName(checkboxView.getClass().getName());
-                event.setPackageName(getContext().getPackageName());
-                event.setEnabled(checkboxView.isEnabled());
-                event.setContentDescription(checkboxView.getContentDescription());
-                event.setChecked(((Checkable) checkboxView).isChecked());
-                mAccessibilityManager.sendAccessibilityEvent(event);
-            }
+            sendAccessibilityEventForView(checkboxView);
         }
 
-        // Sync the summary view
-        TextView summaryView = (TextView) view.findViewById(com.android.internal.R.id.summary);
-        if (summaryView != null) {
-            boolean useDefaultSummary = true;
-            if (mChecked && mSummaryOn != null) {
-                summaryView.setText(mSummaryOn);
-                useDefaultSummary = false;
-            } else if (!mChecked && mSummaryOff != null) {
-                summaryView.setText(mSummaryOff);
-                useDefaultSummary = false;
-            }
-
-            if (useDefaultSummary) {
-                final CharSequence summary = getSummary();
-                if (summary != null) {
-                    summaryView.setText(summary);
-                    useDefaultSummary = false;
-                }
-            }
-            
-            int newVisibility = View.GONE;
-            if (!useDefaultSummary) {
-                // Someone has written to it
-                newVisibility = View.VISIBLE;
-            }
-            if (newVisibility != summaryView.getVisibility()) {
-                summaryView.setVisibility(newVisibility);
-            }
-        }
+        syncSummaryView(view);
     }
-    
-    @Override
-    protected void onClick() {
-        super.onClick();
-        
-        boolean newValue = !isChecked();
-        
-        // in onBindView() an AccessibilityEventViewClickedType is sent to announce the change
-        // not sending
-        mSendAccessibilityEventViewClickedType = true;
-
-        if (!callChangeListener(newValue)) {
-            return;
-        }
-        
-        setChecked(newValue);
-    }
-
-    /**
-     * Sets the checked state and saves it to the {@link SharedPreferences}.
-     * 
-     * @param checked The checked state.
-     */
-    public void setChecked(boolean checked) {
-        if (mChecked != checked) {
-            mChecked = checked;
-            persistBoolean(checked);
-            notifyDependencyChange(shouldDisableDependents());
-            notifyChanged();
-        }
-    }
-
-    /**
-     * Returns the checked state.
-     * 
-     * @return The checked state.
-     */
-    public boolean isChecked() {
-        return mChecked;
-    }
-    
-    @Override
-    public boolean shouldDisableDependents() {
-        boolean shouldDisable = mDisableDependentsState ? mChecked : !mChecked;
-        return shouldDisable || super.shouldDisableDependents();
-    }
-
-    /**
-     * Sets the summary to be shown when checked.
-     * 
-     * @param summary The summary to be shown when checked.
-     */
-    public void setSummaryOn(CharSequence summary) {
-        mSummaryOn = summary;
-        if (isChecked()) {
-            notifyChanged();
-        }
-    }
-
-    /**
-     * @see #setSummaryOn(CharSequence)
-     * @param summaryResId The summary as a resource.
-     */
-    public void setSummaryOn(int summaryResId) {
-        setSummaryOn(getContext().getString(summaryResId));
-    }
-    
-    /**
-     * Returns the summary to be shown when checked.
-     * @return The summary.
-     */
-    public CharSequence getSummaryOn() {
-        return mSummaryOn;
-    }
-    
-    /**
-     * Sets the summary to be shown when unchecked.
-     * 
-     * @param summary The summary to be shown when unchecked.
-     */
-    public void setSummaryOff(CharSequence summary) {
-        mSummaryOff = summary;
-        if (!isChecked()) {
-            notifyChanged();
-        }
-    }
-
-    /**
-     * @see #setSummaryOff(CharSequence)
-     * @param summaryResId The summary as a resource.
-     */
-    public void setSummaryOff(int summaryResId) {
-        setSummaryOff(getContext().getString(summaryResId));
-    }
-    
-    /**
-     * Returns the summary to be shown when unchecked.
-     * @return The summary.
-     */
-    public CharSequence getSummaryOff() {
-        return mSummaryOff;
-    }
-
-    /**
-     * Returns whether dependents are disabled when this preference is on ({@code true})
-     * or when this preference is off ({@code false}).
-     * 
-     * @return Whether dependents are disabled when this preference is on ({@code true})
-     *         or when this preference is off ({@code false}).
-     */
-    public boolean getDisableDependentsState() {
-        return mDisableDependentsState;
-    }
-
-    /**
-     * Sets whether dependents are disabled when this preference is on ({@code true})
-     * or when this preference is off ({@code false}).
-     * 
-     * @param disableDependentsState The preference state that should disable dependents.
-     */
-    public void setDisableDependentsState(boolean disableDependentsState) {
-        mDisableDependentsState = disableDependentsState;
-    }
-
-    @Override
-    protected Object onGetDefaultValue(TypedArray a, int index) {
-        return a.getBoolean(index, false);
-    }
-
-    @Override
-    protected void onSetInitialValue(boolean restoreValue, Object defaultValue) {
-        setChecked(restoreValue ? getPersistedBoolean(mChecked)
-                : (Boolean) defaultValue);
-    }
-
-    @Override
-    protected Parcelable onSaveInstanceState() {
-        final Parcelable superState = super.onSaveInstanceState();
-        if (isPersistent()) {
-            // No need to save instance state since it's persistent
-            return superState;
-        }
-        
-        final SavedState myState = new SavedState(superState);
-        myState.checked = isChecked();
-        return myState;
-    }
-
-    @Override
-    protected void onRestoreInstanceState(Parcelable state) {
-        if (state == null || !state.getClass().equals(SavedState.class)) {
-            // Didn't save state for us in onSaveInstanceState
-            super.onRestoreInstanceState(state);
-            return;
-        }
-         
-        SavedState myState = (SavedState) state;
-        super.onRestoreInstanceState(myState.getSuperState());
-        setChecked(myState.checked);
-    }
-    
-    private static class SavedState extends BaseSavedState {
-        boolean checked;
-        
-        public SavedState(Parcel source) {
-            super(source);
-            checked = source.readInt() == 1;
-        }
-
-        @Override
-        public void writeToParcel(Parcel dest, int flags) {
-            super.writeToParcel(dest, flags);
-            dest.writeInt(checked ? 1 : 0);
-        }
-
-        public SavedState(Parcelable superState) {
-            super(superState);
-        }
-
-        public static final Parcelable.Creator<SavedState> CREATOR =
-                new Parcelable.Creator<SavedState>() {
-            public SavedState createFromParcel(Parcel in) {
-                return new SavedState(in);
-            }
-
-            public SavedState[] newArray(int size) {
-                return new SavedState[size];
-            }
-        };
-    }
-    
 }
diff --git a/core/java/android/preference/Preference.java b/core/java/android/preference/Preference.java
index b6d1594..74a376d 100644
--- a/core/java/android/preference/Preference.java
+++ b/core/java/android/preference/Preference.java
@@ -29,6 +29,7 @@
 import android.text.TextUtils;
 import android.util.AttributeSet;
 import android.view.AbsSavedState;
+import android.view.KeyEvent;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
@@ -956,6 +957,17 @@
             context.startActivity(mIntent);
         }
     }
+
+    /**
+     * Allows a Preference to intercept key events without having focus.
+     * For example, SeekBarPreference uses this to intercept +/- to adjust
+     * the progress.
+     * @return True if the Preference handled the key. Returns false by default.
+     * @hide
+     */
+    public boolean onKey(View v, int keyCode, KeyEvent event) {
+        return false;
+    }
     
     /**
      * Returns the {@link android.content.Context} of this Preference. 
diff --git a/core/java/android/preference/PreferenceFragment.java b/core/java/android/preference/PreferenceFragment.java
index 9d46b7a..f6ba7f7 100644
--- a/core/java/android/preference/PreferenceFragment.java
+++ b/core/java/android/preference/PreferenceFragment.java
@@ -20,13 +20,14 @@
 import android.app.Fragment;
 import android.content.Intent;
 import android.content.SharedPreferences;
-import android.content.res.Configuration;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.Message;
+import android.view.KeyEvent;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.view.View.OnKeyListener;
 import android.widget.ListView;
 
 /**
@@ -146,7 +147,6 @@
         super.onCreate(savedInstanceState);
         mPreferenceManager = new PreferenceManager(getActivity(), FIRST_REQUEST_CODE);
         mPreferenceManager.setFragment(this);
-        mPreferenceManager.setOnPreferenceTreeClickListener(this);
     }
 
     @Override
@@ -179,9 +179,16 @@
     }
 
     @Override
+    public void onStart() {
+        super.onStart();
+        mPreferenceManager.setOnPreferenceTreeClickListener(this);
+    }
+
+    @Override
     public void onStop() {
         super.onStop();
         mPreferenceManager.dispatchActivityStop();
+        mPreferenceManager.setOnPreferenceTreeClickListener(null);
     }
 
     @Override
@@ -196,7 +203,6 @@
     public void onDestroy() {
         super.onDestroy();
         mPreferenceManager.dispatchActivityDestroy();
-        mPreferenceManager.setOnPreferenceTreeClickListener(null);
     }
 
     @Override
@@ -345,6 +351,22 @@
                     "Your content must have a ListView whose id attribute is " +
                     "'android.R.id.list'");
         }
+        mList.setOnKeyListener(mListOnKeyListener);
         mHandler.post(mRequestFocus);
     }
+
+    private OnKeyListener mListOnKeyListener = new OnKeyListener() {
+
+        @Override
+        public boolean onKey(View v, int keyCode, KeyEvent event) {
+            Object selectedItem = mList.getSelectedItem();
+            if (selectedItem instanceof Preference) {
+                View selectedView = mList.getSelectedView();
+                return ((Preference)selectedItem).onKey(
+                        selectedView, keyCode, event);
+            }
+            return false;
+        }
+
+    };
 }
diff --git a/core/java/android/preference/SeekBarDialogPreference.java b/core/java/android/preference/SeekBarDialogPreference.java
new file mode 100644
index 0000000..0e89b16
--- /dev/null
+++ b/core/java/android/preference/SeekBarDialogPreference.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2007 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.preference;
+
+import android.content.Context;
+import android.graphics.drawable.Drawable;
+import android.preference.DialogPreference;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.ImageView;
+import android.widget.SeekBar;
+
+/**
+ * @hide
+ */
+public class SeekBarDialogPreference extends DialogPreference {
+    private static final String TAG = "SeekBarDialogPreference";
+
+    private Drawable mMyIcon;
+
+    public SeekBarDialogPreference(Context context, AttributeSet attrs) {
+        super(context, attrs);
+
+        setDialogLayoutResource(com.android.internal.R.layout.seekbar_dialog);
+        createActionButtons();
+
+        // Steal the XML dialogIcon attribute's value
+        mMyIcon = getDialogIcon();
+        setDialogIcon(null);
+    }
+
+    // Allow subclasses to override the action buttons
+    public void createActionButtons() {
+        setPositiveButtonText(android.R.string.ok);
+        setNegativeButtonText(android.R.string.cancel);
+    }
+
+    @Override
+    protected void onBindDialogView(View view) {
+        super.onBindDialogView(view);
+
+        final ImageView iconView = (ImageView) view.findViewById(android.R.id.icon);
+        if (mMyIcon != null) {
+            iconView.setImageDrawable(mMyIcon);
+        } else {
+            iconView.setVisibility(View.GONE);
+        }
+    }
+
+    protected static SeekBar getSeekBar(View dialogView) {
+        return (SeekBar) dialogView.findViewById(com.android.internal.R.id.seekbar);
+    }
+}
diff --git a/core/java/android/preference/SeekBarPreference.java b/core/java/android/preference/SeekBarPreference.java
index 037fb41..b8919c2 100644
--- a/core/java/android/preference/SeekBarPreference.java
+++ b/core/java/android/preference/SeekBarPreference.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007 The Android Open Source Project
+ * Copyright (C) 2011 The Android Open Source Project
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -17,51 +17,226 @@
 package android.preference;
 
 import android.content.Context;
-import android.graphics.drawable.Drawable;
-import android.preference.DialogPreference;
+import android.content.res.TypedArray;
+import android.os.Parcel;
+import android.os.Parcelable;
 import android.util.AttributeSet;
+import android.view.KeyEvent;
 import android.view.View;
-import android.widget.ImageView;
 import android.widget.SeekBar;
+import android.widget.SeekBar.OnSeekBarChangeListener;
 
 /**
  * @hide
  */
-public class SeekBarPreference extends DialogPreference {
-    private static final String TAG = "SeekBarPreference";
+public class SeekBarPreference extends Preference
+        implements OnSeekBarChangeListener {
 
-    private Drawable mMyIcon;
+    private int mProgress;
+    private int mMax;
+    private boolean mTrackingTouch;
 
-    public SeekBarPreference(Context context, AttributeSet attrs) {
-        super(context, attrs);
-
-        setDialogLayoutResource(com.android.internal.R.layout.seekbar_dialog);
-        createActionButtons();
-
-        // Steal the XML dialogIcon attribute's value
-        mMyIcon = getDialogIcon();
-        setDialogIcon(null);
+    public SeekBarPreference(
+            Context context, AttributeSet attrs, int defStyle) {
+        super(context, attrs, defStyle);
+        TypedArray a = context.obtainStyledAttributes(attrs,
+                com.android.internal.R.styleable.ProgressBar, defStyle, 0);
+        setMax(a.getInt(com.android.internal.R.styleable.ProgressBar_max, mMax));
+        a.recycle();
+        setLayoutResource(com.android.internal.R.layout.preference_widget_seekbar);
     }
 
-    // Allow subclasses to override the action buttons
-    public void createActionButtons() {
-        setPositiveButtonText(android.R.string.ok);
-        setNegativeButtonText(android.R.string.cancel);
+    public SeekBarPreference(Context context, AttributeSet attrs) {
+        this(context, attrs, 0);
+    }
+
+    public SeekBarPreference(Context context) {
+        this(context, null);
     }
 
     @Override
-    protected void onBindDialogView(View view) {
-        super.onBindDialogView(view);
+    protected void onBindView(View view) {
+        super.onBindView(view);
+        SeekBar seekBar = (SeekBar) view.findViewById(
+                com.android.internal.R.id.seekbar);
+        seekBar.setOnSeekBarChangeListener(this);
+        seekBar.setMax(mMax);
+        seekBar.setProgress(mProgress);
+        seekBar.setEnabled(isEnabled());
+    }
 
-        final ImageView iconView = (ImageView) view.findViewById(android.R.id.icon);
-        if (mMyIcon != null) {
-            iconView.setImageDrawable(mMyIcon);
-        } else {
-            iconView.setVisibility(View.GONE);
+    @Override
+    public CharSequence getSummary() {
+        return null;
+    }
+
+    @Override
+    protected void onSetInitialValue(boolean restoreValue, Object defaultValue) {
+        setProgress(restoreValue ? getPersistedInt(mProgress)
+                : (Integer) defaultValue);
+    }
+
+    @Override
+    public boolean onKey(View v, int keyCode, KeyEvent event) {
+        if (event.getAction() != KeyEvent.ACTION_UP) {
+            if (keyCode == KeyEvent.KEYCODE_PLUS
+                    || keyCode == KeyEvent.KEYCODE_EQUALS) {
+                setProgress(getProgress() + 1);
+                return true;
+            }
+            if (keyCode == KeyEvent.KEYCODE_MINUS) {
+                setProgress(getProgress() - 1);
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public void setMax(int max) {
+        if (max != mMax) {
+            mMax = max;
+            notifyChanged();
         }
     }
 
-    protected static SeekBar getSeekBar(View dialogView) {
-        return (SeekBar) dialogView.findViewById(com.android.internal.R.id.seekbar);
+    public void setProgress(int progress) {
+        setProgress(progress, true);
+    }
+
+    private void setProgress(int progress, boolean notifyChanged) {
+        if (progress > mMax) {
+            progress = mMax;
+        }
+        if (progress < 0) {
+            progress = 0;
+        }
+        if (progress != mProgress) {
+            mProgress = progress;
+            persistInt(progress);
+            if (notifyChanged) {
+                notifyChanged();
+            }
+        }
+    }
+
+    public int getProgress() {
+        return mProgress;
+    }
+
+    /**
+     * Persist the seekBar's progress value if callChangeListener
+     * returns true, otherwise set the seekBar's progress to the stored value
+     */
+    void syncProgress(SeekBar seekBar) {
+        int progress = seekBar.getProgress();
+        if (progress != mProgress) {
+            if (callChangeListener(progress)) {
+                setProgress(progress, false);
+            } else {
+                seekBar.setProgress(mProgress);
+            }
+        }
+    }
+
+    @Override
+    public void onProgressChanged(
+            SeekBar seekBar, int progress, boolean fromUser) {
+        if (fromUser && !mTrackingTouch) {
+            syncProgress(seekBar);
+        }
+    }
+
+    @Override
+    public void onStartTrackingTouch(SeekBar seekBar) {
+        mTrackingTouch = true;
+    }
+
+    @Override
+    public void onStopTrackingTouch(SeekBar seekBar) {
+        mTrackingTouch = false;
+        if (seekBar.getProgress() != mProgress) {
+            syncProgress(seekBar);
+        }
+    }
+
+    @Override
+    protected Parcelable onSaveInstanceState() {
+        /*
+         * Suppose a client uses this preference type without persisting. We
+         * must save the instance state so it is able to, for example, survive
+         * orientation changes.
+         */
+
+        final Parcelable superState = super.onSaveInstanceState();
+        if (isPersistent()) {
+            // No need to save instance state since it's persistent
+            return superState;
+        }
+
+        // Save the instance state
+        final SavedState myState = new SavedState(superState);
+        myState.progress = mProgress;
+        myState.max = mMax;
+        return myState;
+    }
+
+    @Override
+    protected void onRestoreInstanceState(Parcelable state) {
+        if (!state.getClass().equals(SavedState.class)) {
+            // Didn't save state for us in onSaveInstanceState
+            super.onRestoreInstanceState(state);
+            return;
+        }
+
+        // Restore the instance state
+        SavedState myState = (SavedState) state;
+        super.onRestoreInstanceState(myState.getSuperState());
+        mProgress = myState.progress;
+        mMax = myState.max;
+        notifyChanged();
+    }
+
+    /**
+     * SavedState, a subclass of {@link BaseSavedState}, will store the state
+     * of MyPreference, a subclass of Preference.
+     * <p>
+     * It is important to always call through to super methods.
+     */
+    private static class SavedState extends BaseSavedState {
+        int progress;
+        int max;
+
+        public SavedState(Parcel source) {
+            super(source);
+
+            // Restore the click counter
+            progress = source.readInt();
+            max = source.readInt();
+        }
+
+        @Override
+        public void writeToParcel(Parcel dest, int flags) {
+            super.writeToParcel(dest, flags);
+
+            // Save the click counter
+            dest.writeInt(progress);
+            dest.writeInt(max);
+        }
+
+        public SavedState(Parcelable superState) {
+            super(superState);
+        }
+
+        @SuppressWarnings("unused")
+        public static final Parcelable.Creator<SavedState> CREATOR =
+                new Parcelable.Creator<SavedState>() {
+            public SavedState createFromParcel(Parcel in) {
+                return new SavedState(in);
+            }
+
+            public SavedState[] newArray(int size) {
+                return new SavedState[size];
+            }
+        };
     }
 }
diff --git a/core/java/android/preference/SwitchPreference.java b/core/java/android/preference/SwitchPreference.java
new file mode 100644
index 0000000..f681526
--- /dev/null
+++ b/core/java/android/preference/SwitchPreference.java
@@ -0,0 +1,180 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.preference;
+
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.Checkable;
+import android.widget.CompoundButton;
+import android.widget.Switch;
+
+/**
+ * A {@link Preference} that provides a two-state toggleable option.
+ * <p>
+ * This preference will store a boolean into the SharedPreferences.
+ *
+ * @attr ref android.R.styleable#SwitchPreference_summaryOff
+ * @attr ref android.R.styleable#SwitchPreference_summaryOn
+ * @attr ref android.R.styleable#SwitchPreference_switchTextOff
+ * @attr ref android.R.styleable#SwitchPreference_switchTextOn
+ * @attr ref android.R.styleable#SwitchPreference_disableDependentsState
+ */
+public class SwitchPreference extends TwoStatePreference {
+    // Switch text for on and off states
+    private CharSequence mSwitchOn;
+    private CharSequence mSwitchOff;
+    private final Listener mListener = new Listener();
+
+    private class Listener implements View.OnClickListener, CompoundButton.OnCheckedChangeListener {
+        @Override
+        public void onClick(View v) {
+            SwitchPreference.this.onClick();
+        }
+
+        @Override
+        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+            SwitchPreference.this.setChecked(isChecked);
+        }
+    }
+
+    /**
+     * Construct a new SwitchPreference with the given style options.
+     *
+     * @param context The Context that will style this preference
+     * @param attrs Style attributes that differ from the default
+     * @param defStyle Theme attribute defining the default style options
+     */
+    public SwitchPreference(Context context, AttributeSet attrs, int defStyle) {
+        super(context, attrs, defStyle);
+
+        TypedArray a = context.obtainStyledAttributes(attrs,
+                com.android.internal.R.styleable.SwitchPreference, defStyle, 0);
+        setSummaryOn(a.getString(com.android.internal.R.styleable.SwitchPreference_summaryOn));
+        setSummaryOff(a.getString(com.android.internal.R.styleable.SwitchPreference_summaryOff));
+        setSwitchTextOn(a.getString(
+                com.android.internal.R.styleable.SwitchPreference_switchTextOn));
+        setSwitchTextOff(a.getString(
+                com.android.internal.R.styleable.SwitchPreference_switchTextOff));
+        setDisableDependentsState(a.getBoolean(
+                com.android.internal.R.styleable.SwitchPreference_disableDependentsState, false));
+        a.recycle();
+    }
+
+    /**
+     * Construct a new SwitchPreference with the given style options.
+     *
+     * @param context The Context that will style this preference
+     * @param attrs Style attributes that differ from the default
+     */
+    public SwitchPreference(Context context, AttributeSet attrs) {
+        this(context, attrs, com.android.internal.R.attr.switchPreferenceStyle);
+    }
+
+    /**
+     * Construct a new SwitchPreference with default style options.
+     *
+     * @param context The Context that will style this preference
+     */
+    public SwitchPreference(Context context) {
+        this(context, null);
+    }
+
+    @Override
+    protected void onBindView(View view) {
+        super.onBindView(view);
+
+        View checkableView = view.findViewById(com.android.internal.R.id.switchWidget);
+        if (checkableView != null && checkableView instanceof Checkable) {
+            ((Checkable) checkableView).setChecked(mChecked);
+
+            sendAccessibilityEventForView(checkableView);
+
+            if (checkableView instanceof Switch) {
+                final Switch switchView = (Switch) checkableView;
+                switchView.setTextOn(mSwitchOn);
+                switchView.setTextOff(mSwitchOff);
+                switchView.setOnCheckedChangeListener(mListener);
+            }
+
+            if (checkableView.hasFocusable()) {
+                // This is a focusable list item. Attach a click handler to toggle the button
+                // for the rest of the item.
+                view.setOnClickListener(mListener);
+            }
+        }
+
+        syncSummaryView(view);
+    }
+
+    /**
+     * Set the text displayed on the switch widget in the on state.
+     * This should be a very short string; one word if possible.
+     *
+     * @param onText Text to display in the on state
+     */
+    public void setSwitchTextOn(CharSequence onText) {
+        mSwitchOn = onText;
+        notifyChanged();
+    }
+
+    /**
+     * Set the text displayed on the switch widget in the off state.
+     * This should be a very short string; one word if possible.
+     *
+     * @param offText Text to display in the off state
+     */
+    public void setSwitchTextOff(CharSequence offText) {
+        mSwitchOff = offText;
+        notifyChanged();
+    }
+
+    /**
+     * Set the text displayed on the switch widget in the on state.
+     * This should be a very short string; one word if possible.
+     *
+     * @param resId The text as a string resource ID
+     */
+    public void setSwitchTextOn(int resId) {
+        setSwitchTextOn(getContext().getString(resId));
+    }
+
+    /**
+     * Set the text displayed on the switch widget in the off state.
+     * This should be a very short string; one word if possible.
+     *
+     * @param resId The text as a string resource ID
+     */
+    public void setSwitchTextOff(int resId) {
+        setSwitchTextOff(getContext().getString(resId));
+    }
+
+    /**
+     * @return The text that will be displayed on the switch widget in the on state
+     */
+    public CharSequence getSwitchTextOn() {
+        return mSwitchOn;
+    }
+
+    /**
+     * @return The text that will be displayed on the switch widget in the off state
+     */
+    public CharSequence getSwitchTextOff() {
+        return mSwitchOff;
+    }
+}
diff --git a/core/java/android/preference/TwoStatePreference.java b/core/java/android/preference/TwoStatePreference.java
new file mode 100644
index 0000000..8e21c4c
--- /dev/null
+++ b/core/java/android/preference/TwoStatePreference.java
@@ -0,0 +1,309 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.preference;
+
+import android.app.Service;
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.content.res.TypedArray;
+import android.os.Parcel;
+import android.os.Parcelable;
+import android.util.AttributeSet;
+import android.view.View;
+import android.view.accessibility.AccessibilityEvent;
+import android.view.accessibility.AccessibilityManager;
+import android.widget.TextView;
+
+/**
+ * Common base class for preferences that have two selectable states, persist a
+ * boolean value in SharedPreferences, and may have dependent preferences that are
+ * enabled/disabled based on the current state.
+ */
+public abstract class TwoStatePreference extends Preference {
+
+    private CharSequence mSummaryOn;
+    private CharSequence mSummaryOff;
+    boolean mChecked;
+    private boolean mSendAccessibilityEventViewClickedType;
+    private AccessibilityManager mAccessibilityManager;
+    private boolean mDisableDependentsState;
+
+    public TwoStatePreference(Context context, AttributeSet attrs, int defStyle) {
+        super(context, attrs, defStyle);
+
+        mAccessibilityManager =
+                (AccessibilityManager) getContext().getSystemService(Service.ACCESSIBILITY_SERVICE);
+    }
+
+    public TwoStatePreference(Context context, AttributeSet attrs) {
+        super(context, attrs);
+
+        mAccessibilityManager =
+                (AccessibilityManager) getContext().getSystemService(Service.ACCESSIBILITY_SERVICE);
+    }
+
+    public TwoStatePreference(Context context) {
+        super(context);
+
+        mAccessibilityManager =
+                (AccessibilityManager) getContext().getSystemService(Service.ACCESSIBILITY_SERVICE);
+    }
+
+    @Override
+    protected void onClick() {
+        super.onClick();
+
+        boolean newValue = !isChecked();
+
+        // in onBindView() an AccessibilityEventViewClickedType is sent to announce the change
+        // not sending
+        mSendAccessibilityEventViewClickedType = true;
+
+        if (!callChangeListener(newValue)) {
+            return;
+        }
+
+        setChecked(newValue);
+    }
+
+    /**
+     * Sets the checked state and saves it to the {@link SharedPreferences}.
+     *
+     * @param checked The checked state.
+     */
+    public void setChecked(boolean checked) {
+        if (mChecked != checked) {
+            mChecked = checked;
+            persistBoolean(checked);
+            notifyDependencyChange(shouldDisableDependents());
+            notifyChanged();
+        }
+    }
+
+    /**
+     * Returns the checked state.
+     *
+     * @return The checked state.
+     */
+    public boolean isChecked() {
+        return mChecked;
+    }
+
+    @Override
+    public boolean shouldDisableDependents() {
+        boolean shouldDisable = mDisableDependentsState ? mChecked : !mChecked;
+        return shouldDisable || super.shouldDisableDependents();
+    }
+
+    /**
+     * Sets the summary to be shown when checked.
+     *
+     * @param summary The summary to be shown when checked.
+     */
+    public void setSummaryOn(CharSequence summary) {
+        mSummaryOn = summary;
+        if (isChecked()) {
+            notifyChanged();
+        }
+    }
+
+    /**
+     * @see #setSummaryOn(CharSequence)
+     * @param summaryResId The summary as a resource.
+     */
+    public void setSummaryOn(int summaryResId) {
+        setSummaryOn(getContext().getString(summaryResId));
+    }
+
+    /**
+     * Returns the summary to be shown when checked.
+     * @return The summary.
+     */
+    public CharSequence getSummaryOn() {
+        return mSummaryOn;
+    }
+
+    /**
+     * Sets the summary to be shown when unchecked.
+     *
+     * @param summary The summary to be shown when unchecked.
+     */
+    public void setSummaryOff(CharSequence summary) {
+        mSummaryOff = summary;
+        if (!isChecked()) {
+            notifyChanged();
+        }
+    }
+
+    /**
+     * @see #setSummaryOff(CharSequence)
+     * @param summaryResId The summary as a resource.
+     */
+    public void setSummaryOff(int summaryResId) {
+        setSummaryOff(getContext().getString(summaryResId));
+    }
+
+    /**
+     * Returns the summary to be shown when unchecked.
+     * @return The summary.
+     */
+    public CharSequence getSummaryOff() {
+        return mSummaryOff;
+    }
+
+    /**
+     * Returns whether dependents are disabled when this preference is on ({@code true})
+     * or when this preference is off ({@code false}).
+     *
+     * @return Whether dependents are disabled when this preference is on ({@code true})
+     *         or when this preference is off ({@code false}).
+     */
+    public boolean getDisableDependentsState() {
+        return mDisableDependentsState;
+    }
+
+    /**
+     * Sets whether dependents are disabled when this preference is on ({@code true})
+     * or when this preference is off ({@code false}).
+     *
+     * @param disableDependentsState The preference state that should disable dependents.
+     */
+    public void setDisableDependentsState(boolean disableDependentsState) {
+        mDisableDependentsState = disableDependentsState;
+    }
+
+    @Override
+    protected Object onGetDefaultValue(TypedArray a, int index) {
+        return a.getBoolean(index, false);
+    }
+
+    @Override
+    protected void onSetInitialValue(boolean restoreValue, Object defaultValue) {
+        setChecked(restoreValue ? getPersistedBoolean(mChecked)
+                : (Boolean) defaultValue);
+    }
+
+    /**
+     * Send an accessibility event for the given view if appropriate
+     * @param view View that should send the event
+     */
+    void sendAccessibilityEventForView(View view) {
+        // send an event to announce the value change of the state. It is done here
+        // because clicking a preference does not immediately change the checked state
+        // for example when enabling the WiFi
+        if (mSendAccessibilityEventViewClickedType &&
+                mAccessibilityManager.isEnabled() &&
+                view.isEnabled()) {
+            mSendAccessibilityEventViewClickedType = false;
+
+            int eventType = AccessibilityEvent.TYPE_VIEW_CLICKED;
+            view.sendAccessibilityEventUnchecked(AccessibilityEvent.obtain(eventType));
+        }
+    }
+
+    /**
+     * Sync a summary view contained within view's subhierarchy with the correct summary text.
+     * @param view View where a summary should be located
+     */
+    void syncSummaryView(View view) {
+        // Sync the summary view
+        TextView summaryView = (TextView) view.findViewById(com.android.internal.R.id.summary);
+        if (summaryView != null) {
+            boolean useDefaultSummary = true;
+            if (mChecked && mSummaryOn != null) {
+                summaryView.setText(mSummaryOn);
+                useDefaultSummary = false;
+            } else if (!mChecked && mSummaryOff != null) {
+                summaryView.setText(mSummaryOff);
+                useDefaultSummary = false;
+            }
+
+            if (useDefaultSummary) {
+                final CharSequence summary = getSummary();
+                if (summary != null) {
+                    summaryView.setText(summary);
+                    useDefaultSummary = false;
+                }
+            }
+
+            int newVisibility = View.GONE;
+            if (!useDefaultSummary) {
+                // Someone has written to it
+                newVisibility = View.VISIBLE;
+            }
+            if (newVisibility != summaryView.getVisibility()) {
+                summaryView.setVisibility(newVisibility);
+            }
+        }
+    }
+
+    @Override
+    protected Parcelable onSaveInstanceState() {
+        final Parcelable superState = super.onSaveInstanceState();
+        if (isPersistent()) {
+            // No need to save instance state since it's persistent
+            return superState;
+        }
+
+        final SavedState myState = new SavedState(superState);
+        myState.checked = isChecked();
+        return myState;
+    }
+
+    @Override
+    protected void onRestoreInstanceState(Parcelable state) {
+        if (state == null || !state.getClass().equals(SavedState.class)) {
+            // Didn't save state for us in onSaveInstanceState
+            super.onRestoreInstanceState(state);
+            return;
+        }
+
+        SavedState myState = (SavedState) state;
+        super.onRestoreInstanceState(myState.getSuperState());
+        setChecked(myState.checked);
+    }
+
+    static class SavedState extends BaseSavedState {
+        boolean checked;
+
+        public SavedState(Parcel source) {
+            super(source);
+            checked = source.readInt() == 1;
+        }
+
+        @Override
+        public void writeToParcel(Parcel dest, int flags) {
+            super.writeToParcel(dest, flags);
+            dest.writeInt(checked ? 1 : 0);
+        }
+
+        public SavedState(Parcelable superState) {
+            super(superState);
+        }
+
+        public static final Parcelable.Creator<SavedState> CREATOR =
+                new Parcelable.Creator<SavedState>() {
+            public SavedState createFromParcel(Parcel in) {
+                return new SavedState(in);
+            }
+
+            public SavedState[] newArray(int size) {
+                return new SavedState[size];
+            }
+        };
+    }
+}
diff --git a/core/java/android/preference/VolumePreference.java b/core/java/android/preference/VolumePreference.java
index 3b12780..b48e8ce 100644
--- a/core/java/android/preference/VolumePreference.java
+++ b/core/java/android/preference/VolumePreference.java
@@ -38,19 +38,19 @@
 /**
  * @hide
  */
-public class VolumePreference extends SeekBarPreference implements 
+public class VolumePreference extends SeekBarDialogPreference implements
         PreferenceManager.OnActivityStopListener, View.OnKeyListener {
 
     private static final String TAG = "VolumePreference";
-    
+
     private int mStreamType;
 
     /** May be null if the dialog isn't visible. */
     private SeekBarVolumizer mSeekBarVolumizer;
-    
+
     public VolumePreference(Context context, AttributeSet attrs) {
         super(context, attrs);
-        
+
         TypedArray a = context.obtainStyledAttributes(attrs,
                 com.android.internal.R.styleable.VolumePreference, 0, 0);
         mStreamType = a.getInt(android.R.styleable.VolumePreference_streamType, 0);
@@ -64,7 +64,7 @@
     @Override
     protected void onBindDialogView(View view) {
         super.onBindDialogView(view);
-    
+
         final SeekBar seekBar = (SeekBar) view.findViewById(com.android.internal.R.id.seekbar);
         mSeekBarVolumizer = new SeekBarVolumizer(getContext(), seekBar, mStreamType);
 
@@ -105,7 +105,7 @@
     @Override
     protected void onDialogClosed(boolean positiveResult) {
         super.onDialogClosed(positiveResult);
-        
+
         if (!positiveResult && mSeekBarVolumizer != null) {
             mSeekBarVolumizer.revertVolume();
         }
@@ -222,16 +222,16 @@
 
         private Context mContext;
         private Handler mHandler = new Handler();
-    
+
         private AudioManager mAudioManager;
         private int mStreamType;
-        private int mOriginalStreamVolume; 
+        private int mOriginalStreamVolume;
         private Ringtone mRingtone;
-    
+
         private int mLastProgress = -1;
         private SeekBar mSeekBar;
         private int mVolumeBeforeMute = -1;
-        
+
         private ContentObserver mVolumeObserver = new ContentObserver(mHandler) {
             @Override
             public void onChange(boolean selfChange) {
@@ -263,7 +263,7 @@
             mOriginalStreamVolume = mAudioManager.getStreamVolume(mStreamType);
             seekBar.setProgress(mOriginalStreamVolume);
             seekBar.setOnSeekBarChangeListener(this);
-            
+
             mContext.getContentResolver().registerContentObserver(
                     System.getUriFor(System.VOLUME_SETTINGS[mStreamType]),
                     false, mVolumeObserver);
@@ -290,17 +290,17 @@
             mContext.getContentResolver().unregisterContentObserver(mVolumeObserver);
             mSeekBar.setOnSeekBarChangeListener(null);
         }
-        
+
         public void revertVolume() {
             mAudioManager.setStreamVolume(mStreamType, mOriginalStreamVolume, 0);
         }
-        
+
         public void onProgressChanged(SeekBar seekBar, int progress,
                 boolean fromTouch) {
             if (!fromTouch) {
                 return;
             }
-    
+
             postSetVolume(progress);
         }
 
@@ -310,7 +310,7 @@
             mHandler.removeCallbacks(this);
             mHandler.post(this);
         }
-    
+
         public void onStartTrackingTouch(SeekBar seekBar) {
         }
 
@@ -319,7 +319,7 @@
                 startSample();
             }
         }
-        
+
         public void run() {
             mAudioManager.setStreamVolume(mStreamType, mLastProgress, 0);
         }
@@ -334,7 +334,7 @@
                 mRingtone.play();
             }
         }
-    
+
         public void stopSample() {
             if (mRingtone != null) {
                 mRingtone.stop();
@@ -344,7 +344,7 @@
         public SeekBar getSeekBar() {
             return mSeekBar;
         }
-        
+
         public void changeVolumeBy(int amount) {
             mSeekBar.incrementProgressBy(amount);
             if (!isSamplePlaying()) {
diff --git a/core/java/android/provider/Calendar.java b/core/java/android/provider/Calendar.java
deleted file mode 100644
index 20614dc..0000000
--- a/core/java/android/provider/Calendar.java
+++ /dev/null
@@ -1,1766 +0,0 @@
-/*
- * Copyright (C) 2006 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.provider;
-
-import android.accounts.Account;
-import android.app.AlarmManager;
-import android.app.PendingIntent;
-import android.content.ContentProviderClient;
-import android.content.ContentResolver;
-import android.content.ContentUris;
-import android.content.ContentValues;
-import android.content.Context;
-import android.content.CursorEntityIterator;
-import android.content.Entity;
-import android.content.EntityIterator;
-import android.content.Intent;
-import android.database.Cursor;
-import android.database.DatabaseUtils;
-import android.net.Uri;
-import android.os.RemoteException;
-import android.pim.ICalendar;
-import android.text.TextUtils;
-import android.text.format.DateUtils;
-import android.text.format.Time;
-import android.util.Log;
-
-/**
- * The Calendar provider contains all calendar events.
- *
- * @hide
- */
-public final class Calendar {
-
-    public static final String TAG = "Calendar";
-
-    /**
-     * Broadcast Action: An event reminder.
-     */
-    public static final String EVENT_REMINDER_ACTION = "android.intent.action.EVENT_REMINDER";
-
-    /**
-     * These are the symbolic names for the keys used in the extra data
-     * passed in the intent for event reminders.
-     */
-    public static final String EVENT_BEGIN_TIME = "beginTime";
-    public static final String EVENT_END_TIME = "endTime";
-
-    /**
-     * This must not be changed or horrible, unspeakable things could happen.
-     * For instance, the Calendar app might break. Also, the db might not work.
-     */
-    public static final String AUTHORITY = "com.android.calendar";
-
-    /**
-     * The content:// style URL for the top-level calendar authority
-     */
-    public static final Uri CONTENT_URI =
-        Uri.parse("content://" + AUTHORITY);
-
-    /**
-     * An optional insert, update or delete URI parameter that allows the caller
-     * to specify that it is a sync adapter. The default value is false. If true
-     * the dirty flag is not automatically set and the "syncToNetwork" parameter
-     * is set to false when calling
-     * {@link ContentResolver#notifyChange(android.net.Uri, android.database.ContentObserver, boolean)}.
-     */
-    public static final String CALLER_IS_SYNCADAPTER = "caller_is_syncadapter";
-
-
-    /**
-     * Generic columns for use by sync adapters. The specific functions of
-     * these columns are private to the sync adapter. Other clients of the API
-     * should not attempt to either read or write this column.
-     */
-    protected interface BaseSyncColumns {
-
-        /** Generic column for use by sync adapters. */
-        public static final String SYNC1 = "sync1";
-        /** Generic column for use by sync adapters. */
-        public static final String SYNC2 = "sync2";
-        /** Generic column for use by sync adapters. */
-        public static final String SYNC3 = "sync3";
-        /** Generic column for use by sync adapters. */
-        public static final String SYNC4 = "sync4";
-        /** Generic column for use by sync adapters. */
-        public static final String SYNC5 = "sync5";
-        /** Generic column for use by sync adapters. */
-        public static final String SYNC6 = "sync6";
-    }
-
-    /**
-     * Columns for Sync information used by Calendars and Events tables.
-     */
-    public interface SyncColumns extends BaseSyncColumns {
-        /**
-         * The account that was used to sync the entry to the device.
-         * <P>Type: TEXT</P>
-         */
-        public static final String ACCOUNT_NAME = "account_name";
-
-        /**
-         * The type of the account that was used to sync the entry to the device.
-         * <P>Type: TEXT</P>
-         */
-        public static final String ACCOUNT_TYPE = "account_type";
-
-        /**
-         * The unique ID for a row assigned by the sync source. NULL if the row has never been synced.
-         * <P>Type: TEXT</P>
-         */
-        public static final String _SYNC_ID = "_sync_id";
-
-        /**
-         * The last time, from the sync source's point of view, that this row has been synchronized.
-         * <P>Type: INTEGER (long)</P>
-         */
-        public static final String _SYNC_TIME = "_sync_time";
-
-        /**
-         * The version of the row, as assigned by the server.
-         * <P>Type: TEXT</P>
-         */
-        public static final String _SYNC_VERSION = "_sync_version";
-
-        /**
-         * Used only in persistent providers, and only during merging.
-         * <P>Type: INTEGER (long)</P>
-         */
-        public static final String _SYNC_MARK = "_sync_mark";
-
-        /**
-         * Used to indicate that local, unsynced, changes are present.
-         * <P>Type: INTEGER (long)</P>
-         */
-        public static final String DIRTY = "dirty";
-
-    }
-
-    /**
-     * Columns from the Calendars table that other tables join into themselves.
-     */
-    public interface CalendarsColumns {
-        /**
-         * The color of the calendar
-         * <P>Type: INTEGER (color value)</P>
-         */
-        public static final String CALENDAR_COLOR = "calendar_color";
-
-        /**
-         * The level of access that the user has for the calendar
-         * <P>Type: INTEGER (one of the values below)</P>
-         */
-        public static final String ACCESS_LEVEL = "access_level";
-
-        /** Cannot access the calendar */
-        public static final int NO_ACCESS = 0;
-        /** Can only see free/busy information about the calendar */
-        public static final int FREEBUSY_ACCESS = 100;
-        /** Can read all event details */
-        public static final int READ_ACCESS = 200;
-        public static final int RESPOND_ACCESS = 300;
-        public static final int OVERRIDE_ACCESS = 400;
-        /** Full access to modify the calendar, but not the access control settings */
-        public static final int CONTRIBUTOR_ACCESS = 500;
-        public static final int EDITOR_ACCESS = 600;
-        /** Full access to the calendar */
-        public static final int OWNER_ACCESS = 700;
-        /** Domain admin */
-        public static final int ROOT_ACCESS = 800;
-
-        /**
-         * Is the calendar selected to be displayed?
-         * <P>Type: INTEGER (boolean)</P>
-         */
-        public static final String VISIBLE = "visible";
-
-        /**
-         * The timezone the calendar's events occurs in
-         * <P>Type: TEXT</P>
-         */
-        public static final String CALENDAR_TIMEZONE = "calendar_timezone";
-
-        /**
-         * If this calendar is in the list of calendars that are selected for
-         * syncing then "sync_events" is 1, otherwise 0.
-         * <p>Type: INTEGER (boolean)</p>
-         */
-        public static final String SYNC_EVENTS = "sync_events";
-
-        /**
-         * Sync state data.
-         * <p>Type: String (blob)</p>
-         */
-        public static final String SYNC_STATE = "sync_state";
-
-        /**
-         * Whether the row has been deleted.  A deleted row should be ignored.
-         * <P>Type: INTEGER (boolean)</P>
-         */
-        public static final String DELETED = "deleted";
-    }
-
-    /**
-     * Class that represents a Calendar Entity. There is one entry per calendar.
-     */
-    public static class CalendarsEntity implements BaseColumns, SyncColumns, CalendarsColumns {
-
-        public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY +
-                "/calendar_entities");
-
-        public static EntityIterator newEntityIterator(Cursor cursor, ContentResolver resolver) {
-            return new EntityIteratorImpl(cursor, resolver);
-        }
-
-        public static EntityIterator newEntityIterator(Cursor cursor,
-                ContentProviderClient provider) {
-            return new EntityIteratorImpl(cursor, provider);
-        }
-
-        private static class EntityIteratorImpl extends CursorEntityIterator {
-            private final ContentResolver mResolver;
-            private final ContentProviderClient mProvider;
-
-            public EntityIteratorImpl(Cursor cursor, ContentResolver resolver) {
-                super(cursor);
-                mResolver = resolver;
-                mProvider = null;
-            }
-
-            public EntityIteratorImpl(Cursor cursor, ContentProviderClient provider) {
-                super(cursor);
-                mResolver = null;
-                mProvider = provider;
-            }
-
-            @Override
-            public Entity getEntityAndIncrementCursor(Cursor cursor) throws RemoteException {
-                // we expect the cursor is already at the row we need to read from
-                final long calendarId = cursor.getLong(cursor.getColumnIndexOrThrow(_ID));
-
-                // Create the content value
-                ContentValues cv = new ContentValues();
-                cv.put(_ID, calendarId);
-
-                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, ACCOUNT_NAME);
-                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, ACCOUNT_TYPE);
-
-                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, _SYNC_ID);
-                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, _SYNC_VERSION);
-                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, _SYNC_TIME);
-                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, DIRTY);
-
-                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, Calendars.SYNC1);
-                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, Calendars.SYNC2);
-                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, Calendars.SYNC3);
-                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, Calendars.SYNC4);
-                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, Calendars.SYNC5);
-                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, Calendars.SYNC6);
-
-                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, Calendars.NAME);
-                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv,
-                        Calendars.DISPLAY_NAME);
-                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, Calendars.CALENDAR_COLOR);
-                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, ACCESS_LEVEL);
-                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, VISIBLE);
-                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, SYNC_EVENTS);
-                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv,
-                        Calendars.CALENDAR_LOCATION);
-                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CALENDAR_TIMEZONE);
-                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv,
-                        Calendars.OWNER_ACCOUNT);
-                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv,
-                        Calendars.CAN_ORGANIZER_RESPOND);
-                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv,
-                        Calendars.CAN_MODIFY_TIME_ZONE);
-                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv,
-                        Calendars.MAX_REMINDERS);
-
-                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, DELETED);
-
-                // Create the Entity from the ContentValue
-                Entity entity = new Entity(cv);
-
-                // Set cursor to next row
-                cursor.moveToNext();
-
-                // Return the created Entity
-                return entity;
-            }
-        }
-     }
-
-    /**
-     * Contains a list of available calendars.
-     */
-    public static class Calendars implements BaseColumns, SyncColumns,
-            CalendarsColumns
-    {
-        private static final String WHERE_DELETE_FOR_ACCOUNT = Calendars.ACCOUNT_NAME + "=?"
-                + " AND "
-                + Calendars.ACCOUNT_TYPE + "=?";
-
-        public static final Cursor query(ContentResolver cr, String[] projection,
-                                       String where, String orderBy)
-        {
-            return cr.query(CONTENT_URI, projection, where,
-                                         null, orderBy == null ? DEFAULT_SORT_ORDER : orderBy);
-        }
-
-        /**
-         * Convenience method perform a delete on the Calendar provider
-         *
-         * @param cr the ContentResolver
-         * @param selection the rows to delete
-         * @return the count of rows that were deleted
-         */
-        public static int delete(ContentResolver cr, String selection, String[] selectionArgs)
-        {
-            return cr.delete(CONTENT_URI, selection, selectionArgs);
-        }
-
-        /**
-         * Convenience method to delete all calendars that match the account.
-         *
-         * @param cr the ContentResolver
-         * @param account the account whose rows should be deleted
-         * @return the count of rows that were deleted
-         */
-        public static int deleteCalendarsForAccount(ContentResolver cr, Account account) {
-            // delete all calendars that match this account
-            return Calendar.Calendars.delete(cr,
-                    WHERE_DELETE_FOR_ACCOUNT,
-                    new String[] { account.name, account.type });
-        }
-
-        /**
-         * The content:// style URL for this table
-         */
-        public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/calendars");
-
-        /**
-         * The default sort order for this table
-         */
-        public static final String DEFAULT_SORT_ORDER = "displayName";
-
-        /**
-         * The URL to the calendar
-         * <P>Type: TEXT (URL)</P>
-         */
-        public static final String URL = "url";
-
-        /**
-         * The URL for the calendar itself
-         * <P>Type: TEXT (URL)</P>
-         */
-        public static final String SELF_URL = "selfUrl";
-
-        /**
-         * The URL for the calendar to be edited
-         * <P>Type: TEXT (URL)</P>
-         */
-        public static final String EDIT_URL = "editUrl";
-
-        /**
-         * The URL for the calendar events
-         * <P>Type: TEXT (URL)</P>
-         */
-        public static final String EVENTS_URL = "eventsUrl";
-
-        /**
-         * The name of the calendar
-         * <P>Type: TEXT</P>
-         */
-        public static final String NAME = "name";
-
-        /**
-         * The display name of the calendar
-         * <P>Type: TEXT</P>
-         */
-        public static final String DISPLAY_NAME = "displayName";
-
-        /**
-         * The location the of the events in the calendar
-         * <P>Type: TEXT</P>
-         */
-        public static final String CALENDAR_LOCATION = "calendar_location";
-
-        /**
-         * The owner account for this calendar, based on the calendar feed.
-         * This will be different from the _SYNC_ACCOUNT for delegated calendars.
-         * <P>Type: String</P>
-         */
-        public static final String OWNER_ACCOUNT = "ownerAccount";
-
-        /**
-         * Can the organizer respond to the event?  If no, the status of the
-         * organizer should not be shown by the UI.  Defaults to 1
-         * <P>Type: INTEGER (boolean)</P>
-         */
-        public static final String CAN_ORGANIZER_RESPOND = "canOrganizerRespond";
-
-        /**
-         * Can the organizer modify the time zone of the event?
-         * <P>Type: INTEGER (boolean)</P>
-        */
-        public static final String CAN_MODIFY_TIME_ZONE = "canModifyTimeZone";
-
-        /**
-         * The maximum number of reminders allowed for an event.
-         * <P>Type: INTEGER</P>
-         */
-        public static final String MAX_REMINDERS = "maxReminders";
-
-        /**
-         * The maximum number of reminders allowed for an event.
-         * <P>
-         * Type: INTEGER
-         * </P>
-         */
-        public static final String ALLOWED_REMINDERS = "allowedReminders";
-
-        /**
-         * These fields are only writable by a sync adapter. To modify them the
-         * caller must include CALLER_IS_SYNCADAPTER, _SYNC_ACCOUNT, and
-         * _SYNC_ACCOUNT_TYPE in the query parameters.
-         */
-        public static final String[] SYNC_WRITABLE_COLUMNS = new String[] {
-            ACCOUNT_NAME,
-            ACCOUNT_TYPE,
-            _SYNC_ID,
-            _SYNC_TIME,
-            _SYNC_VERSION,
-            DIRTY,
-            OWNER_ACCOUNT,
-            MAX_REMINDERS,
-            CAN_MODIFY_TIME_ZONE,
-            CAN_ORGANIZER_RESPOND,
-            CALENDAR_LOCATION,
-            CALENDAR_TIMEZONE,
-            ACCESS_LEVEL,
-            DELETED,
-            SYNC1,
-            SYNC2,
-            SYNC3,
-            SYNC4,
-            SYNC5,
-            SYNC6,
-            SYNC_STATE,
-        };
-    }
-
-    /**
-     * Columns from the Attendees table that other tables join into themselves.
-     */
-    public interface AttendeesColumns {
-
-        /**
-         * The id of the event.
-         * <P>Type: INTEGER</P>
-         */
-        public static final String EVENT_ID = "event_id";
-
-        /**
-         * The name of the attendee.
-         * <P>Type: STRING</P>
-         */
-        public static final String ATTENDEE_NAME = "attendeeName";
-
-        /**
-         * The email address of the attendee.
-         * <P>Type: STRING</P>
-         */
-        public static final String ATTENDEE_EMAIL = "attendeeEmail";
-
-        /**
-         * The relationship of the attendee to the user.
-         * <P>Type: INTEGER (one of {@link #RELATIONSHIP_ATTENDEE}, ...}.
-         */
-        public static final String ATTENDEE_RELATIONSHIP = "attendeeRelationship";
-
-        public static final int RELATIONSHIP_NONE = 0;
-        public static final int RELATIONSHIP_ATTENDEE = 1;
-        public static final int RELATIONSHIP_ORGANIZER = 2;
-        public static final int RELATIONSHIP_PERFORMER = 3;
-        public static final int RELATIONSHIP_SPEAKER = 4;
-
-        /**
-         * The type of attendee.
-         * <P>Type: Integer (one of {@link #TYPE_REQUIRED}, {@link #TYPE_OPTIONAL})
-         */
-        public static final String ATTENDEE_TYPE = "attendeeType";
-
-        public static final int TYPE_NONE = 0;
-        public static final int TYPE_REQUIRED = 1;
-        public static final int TYPE_OPTIONAL = 2;
-
-        /**
-         * The attendance status of the attendee.
-         * <P>Type: Integer (one of {@link #ATTENDEE_STATUS_ACCEPTED}, ...}.
-         */
-        public static final String ATTENDEE_STATUS = "attendeeStatus";
-
-        public static final int ATTENDEE_STATUS_NONE = 0;
-        public static final int ATTENDEE_STATUS_ACCEPTED = 1;
-        public static final int ATTENDEE_STATUS_DECLINED = 2;
-        public static final int ATTENDEE_STATUS_INVITED = 3;
-        public static final int ATTENDEE_STATUS_TENTATIVE = 4;
-    }
-
-    public static final class Attendees implements BaseColumns, AttendeesColumns, EventsColumns {
-        public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/attendees");
-
-        // TODO: fill out this class when we actually start utilizing attendees
-        // in the calendar application.
-    }
-
-    /**
-     * Columns from the Events table that other tables join into themselves.
-     */
-    public interface EventsColumns {
-        /**
-         * For use by sync adapter at its discretion; not modified by CalendarProvider
-         * Note that this column was formerly named _SYNC_LOCAL_ID.  We are using it to avoid a
-         * schema change.
-         * TODO Replace this with something more general in the future.
-         * <P>Type: INTEGER (long)</P>
-         */
-        public static final String _SYNC_DATA = "_sync_local_id";
-
-        /**
-         * The calendar the event belongs to
-         * <P>Type: INTEGER (foreign key to the Calendars table)</P>
-         */
-        public static final String CALENDAR_ID = "calendar_id";
-
-        /**
-         * The URI for an HTML version of this event.
-         * <P>Type: TEXT</P>
-         */
-        public static final String HTML_URI = "htmlUri";
-
-        /**
-         * The title of the event
-         * <P>Type: TEXT</P>
-         */
-        public static final String TITLE = "title";
-
-        /**
-         * The description of the event
-         * <P>Type: TEXT</P>
-         */
-        public static final String DESCRIPTION = "description";
-
-        /**
-         * Where the event takes place.
-         * <P>Type: TEXT</P>
-         */
-        public static final String EVENT_LOCATION = "eventLocation";
-
-        /**
-         * The event status
-         * <P>Type: INTEGER (int)</P>
-         */
-        public static final String STATUS = "eventStatus";
-
-        public static final int STATUS_TENTATIVE = 0;
-        public static final int STATUS_CONFIRMED = 1;
-        public static final int STATUS_CANCELED = 2;
-
-        /**
-         * This is a copy of the attendee status for the owner of this event.
-         * This field is copied here so that we can efficiently filter out
-         * events that are declined without having to look in the Attendees
-         * table.
-         *
-         * <P>Type: INTEGER (int)</P>
-         */
-        public static final String SELF_ATTENDEE_STATUS = "selfAttendeeStatus";
-
-        /**
-         * This column is available for use by sync adapters
-         * <P>Type: TEXT</P>
-         */
-        public static final String SYNC_DATA1 = "sync_data1";
-
-        /**
-         * The comments feed uri.
-         * <P>Type: TEXT</P>
-         */
-        public static final String COMMENTS_URI = "commentsUri";
-
-        /**
-         * The time the event starts
-         * <P>Type: INTEGER (long; millis since epoch)</P>
-         */
-        public static final String DTSTART = "dtstart";
-
-        /**
-         * The time the event ends
-         * <P>Type: INTEGER (long; millis since epoch)</P>
-         */
-        public static final String DTEND = "dtend";
-
-        /**
-         * The duration of the event
-         * <P>Type: TEXT (duration in RFC2445 format)</P>
-         */
-        public static final String DURATION = "duration";
-
-        /**
-         * The timezone for the event.
-         * <P>Type: TEXT
-         */
-        public static final String EVENT_TIMEZONE = "eventTimezone";
-
-        /**
-         * The timezone for the event, allDay events will have a local tz instead of UTC
-         * <P>Type: TEXT
-         */
-        public static final String EVENT_END_TIMEZONE = "eventEndTimezone";
-
-        /**
-         * Whether the event lasts all day or not
-         * <P>Type: INTEGER (boolean)</P>
-         */
-        public static final String ALL_DAY = "allDay";
-
-        /**
-         * Defines how the event shows up for others when the calendar is
-         * shared.
-         * <P>Type: INTEGER</P>
-         */
-        public static final String ACCESS_LEVEL = "accessLevel";
-
-        /**
-         * Default access is controlled by the server and will be treated as
-         * public on the device.
-         */
-        public static final int ACCESS_DEFAULT = 0;
-        /**
-         * Confidential is not used by the app.
-         */
-        public static final int ACCESS_CONFIDENTIAL = 1;
-        /**
-         * Private assumes the event appears as a free/busy slot with no
-         * details.
-         */
-        public static final int ACCESS_PRIVATE = 2;
-        /**
-         * Public assumes the contents are visible to anyone with access to the
-         * calendar.
-         */
-        public static final int ACCESS_PUBLIC = 3;
-
-        /**
-         * If this event counts as busy time or is still free time that can be
-         * scheduled over.
-         * <P>Type: INTEGER</P>
-         */
-        public static final String AVAILABILITY = "availability";
-
-        /**
-         * Indicates that this event takes up time and will conflict with other
-         * events.
-         */
-        public static final int AVAILABILITY_BUSY = 0;
-        /**
-         * Indicates that this event is free time and will not conflict with
-         * other events.
-         */
-        public static final int AVAILABILITY_FREE = 1;
-
-        /**
-         * Whether the event has an alarm or not
-         * <P>Type: INTEGER (boolean)</P>
-         */
-        public static final String HAS_ALARM = "hasAlarm";
-
-        /**
-         * Whether the event has extended properties or not
-         * <P>Type: INTEGER (boolean)</P>
-         */
-        public static final String HAS_EXTENDED_PROPERTIES = "hasExtendedProperties";
-
-        /**
-         * The recurrence rule for the event.
-         * than one.
-         * <P>Type: TEXT</P>
-         */
-        public static final String RRULE = "rrule";
-
-        /**
-         * The recurrence dates for the event.
-         * <P>Type: TEXT</P>
-         */
-        public static final String RDATE = "rdate";
-
-        /**
-         * The recurrence exception rule for the event.
-         * <P>Type: TEXT</P>
-         */
-        public static final String EXRULE = "exrule";
-
-        /**
-         * The recurrence exception dates for the event.
-         * <P>Type: TEXT</P>
-         */
-        public static final String EXDATE = "exdate";
-
-        /**
-         * The _id of the original recurring event for which this event is an
-         * exception.
-         * <P>Type: TEXT</P>
-         */
-        public static final String ORIGINAL_ID = "original_id";
-
-        /**
-         * The _sync_id of the original recurring event for which this event is
-         * an exception. The provider should keep the original_id in sync when
-         * this is updated.
-         * <P>Type: TEXT</P>
-         */
-        public static final String ORIGINAL_SYNC_ID = "original_sync_id";
-
-        /**
-         * The original instance time of the recurring event for which this
-         * event is an exception.
-         * <P>Type: INTEGER (long; millis since epoch)</P>
-         */
-        public static final String ORIGINAL_INSTANCE_TIME = "originalInstanceTime";
-
-        /**
-         * The allDay status (true or false) of the original recurring event
-         * for which this event is an exception.
-         * <P>Type: INTEGER (boolean)</P>
-         */
-        public static final String ORIGINAL_ALL_DAY = "originalAllDay";
-
-        /**
-         * The last date this event repeats on, or NULL if it never ends
-         * <P>Type: INTEGER (long; millis since epoch)</P>
-         */
-        public static final String LAST_DATE = "lastDate";
-
-        /**
-         * Whether the event has attendee information.  True if the event
-         * has full attendee data, false if the event has information about
-         * self only.
-         * <P>Type: INTEGER (boolean)</P>
-         */
-        public static final String HAS_ATTENDEE_DATA = "hasAttendeeData";
-
-        /**
-         * Whether guests can modify the event.
-         * <P>Type: INTEGER (boolean)</P>
-         */
-        public static final String GUESTS_CAN_MODIFY = "guestsCanModify";
-
-        /**
-         * Whether guests can invite other guests.
-         * <P>Type: INTEGER (boolean)</P>
-         */
-        public static final String GUESTS_CAN_INVITE_OTHERS = "guestsCanInviteOthers";
-
-        /**
-         * Whether guests can see the list of attendees.
-         * <P>Type: INTEGER (boolean)</P>
-         */
-        public static final String GUESTS_CAN_SEE_GUESTS = "guestsCanSeeGuests";
-
-        /**
-         * Email of the organizer (owner) of the event.
-         * <P>Type: STRING</P>
-         */
-        public static final String ORGANIZER = "organizer";
-
-        /**
-         * Whether the user can invite others to the event.
-         * The GUESTS_CAN_INVITE_OTHERS is a setting that applies to an arbitrary guest,
-         * while CAN_INVITE_OTHERS indicates if the user can invite others (either through
-         * GUESTS_CAN_INVITE_OTHERS or because the user has modify access to the event).
-         * <P>Type: INTEGER (boolean, readonly)</P>
-         */
-        public static final String CAN_INVITE_OTHERS = "canInviteOthers";
-
-        /**
-         * The owner account for this calendar, based on the calendar (foreign
-         * key into the calendars table).
-         * <P>Type: String</P>
-         */
-        public static final String OWNER_ACCOUNT = "ownerAccount";
-
-        /**
-         * Whether the row has been deleted.  A deleted row should be ignored.
-         * <P>Type: INTEGER (boolean)</P>
-         */
-        public static final String DELETED = "deleted";
-    }
-
-    /**
-     * Contains one entry per calendar event. Recurring events show up as a
-     * single entry.
-     */
-    public static final class EventsEntity implements BaseColumns, SyncColumns, EventsColumns {
-        /**
-         * The content:// style URL for this table
-         */
-        public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY +
-                "/event_entities");
-
-        public static EntityIterator newEntityIterator(Cursor cursor, ContentResolver resolver) {
-            return new EntityIteratorImpl(cursor, resolver);
-        }
-
-        public static EntityIterator newEntityIterator(Cursor cursor,
-                ContentProviderClient provider) {
-            return new EntityIteratorImpl(cursor, provider);
-        }
-
-        private static class EntityIteratorImpl extends CursorEntityIterator {
-            private final ContentResolver mResolver;
-            private final ContentProviderClient mProvider;
-
-            private static final String[] REMINDERS_PROJECTION = new String[] {
-                    Reminders.MINUTES,
-                    Reminders.METHOD,
-            };
-            private static final int COLUMN_MINUTES = 0;
-            private static final int COLUMN_METHOD = 1;
-
-            private static final String[] ATTENDEES_PROJECTION = new String[] {
-                    Attendees.ATTENDEE_NAME,
-                    Attendees.ATTENDEE_EMAIL,
-                    Attendees.ATTENDEE_RELATIONSHIP,
-                    Attendees.ATTENDEE_TYPE,
-                    Attendees.ATTENDEE_STATUS,
-            };
-            private static final int COLUMN_ATTENDEE_NAME = 0;
-            private static final int COLUMN_ATTENDEE_EMAIL = 1;
-            private static final int COLUMN_ATTENDEE_RELATIONSHIP = 2;
-            private static final int COLUMN_ATTENDEE_TYPE = 3;
-            private static final int COLUMN_ATTENDEE_STATUS = 4;
-            private static final String[] EXTENDED_PROJECTION = new String[] {
-                    ExtendedProperties._ID,
-                    ExtendedProperties.NAME,
-                    ExtendedProperties.VALUE
-            };
-            private static final int COLUMN_ID = 0;
-            private static final int COLUMN_NAME = 1;
-            private static final int COLUMN_VALUE = 2;
-
-            private static final String WHERE_EVENT_ID = "event_id=?";
-
-            public EntityIteratorImpl(Cursor cursor, ContentResolver resolver) {
-                super(cursor);
-                mResolver = resolver;
-                mProvider = null;
-            }
-
-            public EntityIteratorImpl(Cursor cursor, ContentProviderClient provider) {
-                super(cursor);
-                mResolver = null;
-                mProvider = provider;
-            }
-
-            @Override
-            public Entity getEntityAndIncrementCursor(Cursor cursor) throws RemoteException {
-                // we expect the cursor is already at the row we need to read from
-                final long eventId = cursor.getLong(cursor.getColumnIndexOrThrow(Events._ID));
-                ContentValues cv = new ContentValues();
-                cv.put(Events._ID, eventId);
-                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, CALENDAR_ID);
-                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, HTML_URI);
-                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, TITLE);
-                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, DESCRIPTION);
-                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, EVENT_LOCATION);
-                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, STATUS);
-                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, SELF_ATTENDEE_STATUS);
-                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, COMMENTS_URI);
-                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, DTSTART);
-                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, DTEND);
-                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, DURATION);
-                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, EVENT_TIMEZONE);
-                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, EVENT_END_TIMEZONE);
-                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, ALL_DAY);
-                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, ACCESS_LEVEL);
-                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, AVAILABILITY);
-                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, HAS_ALARM);
-                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv,
-                        HAS_EXTENDED_PROPERTIES);
-                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, RRULE);
-                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, RDATE);
-                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, EXRULE);
-                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, EXDATE);
-                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, ORIGINAL_SYNC_ID);
-                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, ORIGINAL_ID);
-                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv,
-                        ORIGINAL_INSTANCE_TIME);
-                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, ORIGINAL_ALL_DAY);
-                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, LAST_DATE);
-                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, HAS_ATTENDEE_DATA);
-                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv,
-                        GUESTS_CAN_INVITE_OTHERS);
-                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, GUESTS_CAN_MODIFY);
-                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, GUESTS_CAN_SEE_GUESTS);
-                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, ORGANIZER);
-                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, _SYNC_ID);
-                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, _SYNC_DATA);
-                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, DIRTY);
-                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, _SYNC_VERSION);
-                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, EventsColumns.DELETED);
-                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC1);
-                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv,
-                        Events.SYNC_DATA1);
-
-                Entity entity = new Entity(cv);
-                Cursor subCursor;
-                if (mResolver != null) {
-                    subCursor = mResolver.query(Reminders.CONTENT_URI, REMINDERS_PROJECTION,
-                            WHERE_EVENT_ID,
-                            new String[] { Long.toString(eventId) }  /* selectionArgs */,
-                            null /* sortOrder */);
-                } else {
-                    subCursor = mProvider.query(Reminders.CONTENT_URI, REMINDERS_PROJECTION,
-                            WHERE_EVENT_ID,
-                            new String[] { Long.toString(eventId) }  /* selectionArgs */,
-                            null /* sortOrder */);
-                }
-                try {
-                    while (subCursor.moveToNext()) {
-                        ContentValues reminderValues = new ContentValues();
-                        reminderValues.put(Reminders.MINUTES, subCursor.getInt(COLUMN_MINUTES));
-                        reminderValues.put(Reminders.METHOD, subCursor.getInt(COLUMN_METHOD));
-                        entity.addSubValue(Reminders.CONTENT_URI, reminderValues);
-                    }
-                } finally {
-                    subCursor.close();
-                }
-
-                if (mResolver != null) {
-                    subCursor = mResolver.query(Attendees.CONTENT_URI, ATTENDEES_PROJECTION,
-                            WHERE_EVENT_ID,
-                            new String[] { Long.toString(eventId) } /* selectionArgs */,
-                            null /* sortOrder */);
-                } else {
-                    subCursor = mProvider.query(Attendees.CONTENT_URI, ATTENDEES_PROJECTION,
-                            WHERE_EVENT_ID,
-                            new String[] { Long.toString(eventId) } /* selectionArgs */,
-                            null /* sortOrder */);
-                }
-                try {
-                    while (subCursor.moveToNext()) {
-                        ContentValues attendeeValues = new ContentValues();
-                        attendeeValues.put(Attendees.ATTENDEE_NAME,
-                                subCursor.getString(COLUMN_ATTENDEE_NAME));
-                        attendeeValues.put(Attendees.ATTENDEE_EMAIL,
-                                subCursor.getString(COLUMN_ATTENDEE_EMAIL));
-                        attendeeValues.put(Attendees.ATTENDEE_RELATIONSHIP,
-                                subCursor.getInt(COLUMN_ATTENDEE_RELATIONSHIP));
-                        attendeeValues.put(Attendees.ATTENDEE_TYPE,
-                                subCursor.getInt(COLUMN_ATTENDEE_TYPE));
-                        attendeeValues.put(Attendees.ATTENDEE_STATUS,
-                                subCursor.getInt(COLUMN_ATTENDEE_STATUS));
-                        entity.addSubValue(Attendees.CONTENT_URI, attendeeValues);
-                    }
-                } finally {
-                    subCursor.close();
-                }
-
-                if (mResolver != null) {
-                    subCursor = mResolver.query(ExtendedProperties.CONTENT_URI, EXTENDED_PROJECTION,
-                            WHERE_EVENT_ID,
-                            new String[] { Long.toString(eventId) } /* selectionArgs */,
-                            null /* sortOrder */);
-                } else {
-                    subCursor = mProvider.query(ExtendedProperties.CONTENT_URI, EXTENDED_PROJECTION,
-                            WHERE_EVENT_ID,
-                            new String[] { Long.toString(eventId) } /* selectionArgs */,
-                            null /* sortOrder */);
-                }
-                try {
-                    while (subCursor.moveToNext()) {
-                        ContentValues extendedValues = new ContentValues();
-                        extendedValues.put(ExtendedProperties._ID,
-                                subCursor.getString(COLUMN_ID));
-                        extendedValues.put(ExtendedProperties.NAME,
-                                subCursor.getString(COLUMN_NAME));
-                        extendedValues.put(ExtendedProperties.VALUE,
-                                subCursor.getString(COLUMN_VALUE));
-                        entity.addSubValue(ExtendedProperties.CONTENT_URI, extendedValues);
-                    }
-                } finally {
-                    subCursor.close();
-                }
-
-                cursor.moveToNext();
-                return entity;
-            }
-        }
-    }
-
-    /**
-     * Contains one entry per calendar event. Recurring events show up as a single entry.
-     */
-    public static final class Events implements BaseColumns, SyncColumns, EventsColumns {
-
-        private static final String[] FETCH_ENTRY_COLUMNS =
-                new String[] { Events.ACCOUNT_NAME, Events._SYNC_ID };
-
-        private static final String[] ATTENDEES_COLUMNS =
-                new String[] { AttendeesColumns.ATTENDEE_NAME,
-                               AttendeesColumns.ATTENDEE_EMAIL,
-                               AttendeesColumns.ATTENDEE_RELATIONSHIP,
-                               AttendeesColumns.ATTENDEE_TYPE,
-                               AttendeesColumns.ATTENDEE_STATUS };
-
-        public static final Cursor query(ContentResolver cr, String[] projection) {
-            return cr.query(CONTENT_URI, projection, null, null, DEFAULT_SORT_ORDER);
-        }
-
-        public static final Cursor query(ContentResolver cr, String[] projection,
-                                       String where, String orderBy) {
-            return cr.query(CONTENT_URI, projection, where,
-                                         null, orderBy == null ? DEFAULT_SORT_ORDER : orderBy);
-        }
-
-        private static String extractValue(ICalendar.Component component,
-                                           String propertyName) {
-            ICalendar.Property property =
-                    component.getFirstProperty(propertyName);
-            if (property != null) {
-                return property.getValue();
-            }
-            return null;
-        }
-
-        /**
-         * The content:// style URL for this table
-         */
-        public static final Uri CONTENT_URI =
-                Uri.parse("content://" + AUTHORITY + "/events");
-
-        public static final Uri DELETED_CONTENT_URI =
-                Uri.parse("content://" + AUTHORITY + "/deleted_events");
-
-        /**
-         * The default sort order for this table
-         */
-        public static final String DEFAULT_SORT_ORDER = "";
-
-        /**
-         * These are columns that should only ever be updated by the provider,
-         * either because they are views mapped to another table or because they
-         * are used for provider only functionality.
-         */
-        public static String[] PROVIDER_WRITABLE_COLUMNS = new String[] {
-                ACCOUNT_NAME,
-                ACCOUNT_TYPE
-        };
-
-        /**
-         * These fields are only writable by a sync adapter. To modify them the
-         * caller must include CALLER_IS_SYNCADAPTER, _SYNC_ACCOUNT, and
-         * _SYNC_ACCOUNT_TYPE in the query parameters.
-         */
-        public static final String[] SYNC_WRITABLE_COLUMNS = new String[] {
-            _SYNC_ID,
-            _SYNC_TIME,
-            _SYNC_VERSION,
-            DIRTY,
-            SYNC_DATA1
-        };
-    }
-
-    /**
-     * Contains one entry per calendar event instance. Recurring events show up every time
-     * they occur.
-     */
-    public static final class Instances implements BaseColumns, EventsColumns, CalendarsColumns {
-
-        private static final String WHERE_CALENDARS_SELECTED = Calendars.VISIBLE + "=1";
-
-        public static final Cursor query(ContentResolver cr, String[] projection,
-                                         long begin, long end) {
-            Uri.Builder builder = CONTENT_URI.buildUpon();
-            ContentUris.appendId(builder, begin);
-            ContentUris.appendId(builder, end);
-            return cr.query(builder.build(), projection, WHERE_CALENDARS_SELECTED,
-                         null, DEFAULT_SORT_ORDER);
-        }
-
-        public static final Cursor query(ContentResolver cr, String[] projection,
-                                         long begin, long end, String searchQuery) {
-            Uri.Builder builder = CONTENT_SEARCH_URI.buildUpon();
-            ContentUris.appendId(builder, begin);
-            ContentUris.appendId(builder, end);
-            return cr.query(builder.build(), projection, WHERE_CALENDARS_SELECTED,
-                         new String[] { searchQuery }, DEFAULT_SORT_ORDER);
-        }
-
-        public static final Cursor query(ContentResolver cr, String[] projection,
-                                         long begin, long end, String where, String orderBy) {
-            Uri.Builder builder = CONTENT_URI.buildUpon();
-            ContentUris.appendId(builder, begin);
-            ContentUris.appendId(builder, end);
-            if (TextUtils.isEmpty(where)) {
-                where = WHERE_CALENDARS_SELECTED;
-            } else {
-                where = "(" + where + ") AND " + WHERE_CALENDARS_SELECTED;
-            }
-            return cr.query(builder.build(), projection, where,
-                         null, orderBy == null ? DEFAULT_SORT_ORDER : orderBy);
-        }
-
-        public static final Cursor query(ContentResolver cr, String[] projection, long begin,
-                long end, String searchQuery, String where, String orderBy) {
-            Uri.Builder builder = CONTENT_SEARCH_URI.buildUpon();
-            ContentUris.appendId(builder, begin);
-            ContentUris.appendId(builder, end);
-            builder = builder.appendPath(searchQuery);
-            if (TextUtils.isEmpty(where)) {
-                where = WHERE_CALENDARS_SELECTED;
-            } else {
-                where = "(" + where + ") AND " + WHERE_CALENDARS_SELECTED;
-            }
-            return cr.query(builder.build(), projection, where, null,
-                    orderBy == null ? DEFAULT_SORT_ORDER : orderBy);
-        }
-
-        /**
-         * The content:// style URL for this table
-         */
-        public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY +
-                "/instances/when");
-        public static final Uri CONTENT_BY_DAY_URI =
-            Uri.parse("content://" + AUTHORITY + "/instances/whenbyday");
-        public static final Uri CONTENT_SEARCH_URI = Uri.parse("content://" + AUTHORITY +
-                "/instances/search");
-        public static final Uri CONTENT_SEARCH_BY_DAY_URI =
-            Uri.parse("content://" + AUTHORITY + "/instances/searchbyday");
-
-        /**
-         * The default sort order for this table.
-         */
-        public static final String DEFAULT_SORT_ORDER = "begin ASC";
-
-        /**
-         * The sort order is: events with an earlier start time occur
-         * first and if the start times are the same, then events with
-         * a later end time occur first. The later end time is ordered
-         * first so that long-running events in the calendar views appear
-         * first.  If the start and end times of two events are
-         * the same then we sort alphabetically on the title.  This isn't
-         * required for correctness, it just adds a nice touch.
-         */
-        public static final String SORT_CALENDAR_VIEW = "begin ASC, end DESC, title ASC";
-        /**
-         * The beginning time of the instance, in UTC milliseconds
-         * <P>Type: INTEGER (long; millis since epoch)</P>
-         */
-        public static final String BEGIN = "begin";
-
-        /**
-         * The ending time of the instance, in UTC milliseconds
-         * <P>Type: INTEGER (long; millis since epoch)</P>
-         */
-        public static final String END = "end";
-
-        /**
-         * The event for this instance
-         * <P>Type: INTEGER (long, foreign key to the Events table)</P>
-         */
-        public static final String EVENT_ID = "event_id";
-
-        /**
-         * The Julian start day of the instance, relative to the local timezone
-         * <P>Type: INTEGER (int)</P>
-         */
-        public static final String START_DAY = "startDay";
-
-        /**
-         * The Julian end day of the instance, relative to the local timezone
-         * <P>Type: INTEGER (int)</P>
-         */
-        public static final String END_DAY = "endDay";
-
-        /**
-         * The start minute of the instance measured from midnight in the
-         * local timezone.
-         * <P>Type: INTEGER (int)</P>
-         */
-        public static final String START_MINUTE = "startMinute";
-
-        /**
-         * The end minute of the instance measured from midnight in the
-         * local timezone.
-         * <P>Type: INTEGER (int)</P>
-         */
-        public static final String END_MINUTE = "endMinute";
-    }
-
-    /**
-     * CalendarCache stores some settings for calendar including the current
-     * time zone for the app. These settings are stored using a key/value
-     * scheme.
-     */
-    public interface CalendarCacheColumns {
-        /**
-         * The key for the setting. Keys are defined in CalendarChache in the
-         * Calendar provider.
-         * TODO Add keys to this file
-         */
-        public static final String KEY = "key";
-
-        /**
-         * The value of the given setting.
-         */
-        public static final String VALUE = "value";
-    }
-
-    public static class CalendarCache implements CalendarCacheColumns {
-        /**
-         * The URI to use for retrieving the properties from the Calendar db.
-         */
-        public static final Uri URI =
-                Uri.parse("content://" + AUTHORITY + "/properties");
-        public static final String[] POJECTION = { KEY, VALUE };
-
-        /**
-         * If updating a property, this must be provided as the selection. All
-         * other selections will fail. For queries this field can be omitted to
-         * retrieve all properties or used to query a single property. Valid
-         * keys include {@link #TIMEZONE_KEY_TYPE},
-         * {@link #TIMEZONE_KEY_INSTANCES}, and
-         * {@link #TIMEZONE_KEY_INSTANCES_PREVIOUS}, though the last one can
-         * only be read, not written.
-         */
-        public static final String WHERE = "key=?";
-
-        /**
-         * They key for updating the use of auto/home time zones in Calendar.
-         * Valid values are {@link #TIMEZONE_TYPE_AUTO} or
-         * {@link #TIMEZONE_TYPE_HOME}.
-         */
-        public static final String TIMEZONE_KEY_TYPE = "timezoneType";
-
-        /**
-         * The key for updating the time zone used by the provider when it
-         * generates the instances table. This should only be written if the
-         * type is set to {@link #TIMEZONE_TYPE_HOME}. A valid time zone id
-         * should be written to this field.
-         */
-        public static final String TIMEZONE_KEY_INSTANCES = "timezoneInstances";
-
-        /**
-         * The key for reading the last time zone set by the user. This should
-         * only be read by apps and it will be automatically updated whenever
-         * {@link #TIMEZONE_KEY_INSTANCES} is updated with
-         * {@link #TIMEZONE_TYPE_HOME} set.
-         */
-        public static final String TIMEZONE_KEY_INSTANCES_PREVIOUS = "timezoneInstancesPrevious";
-
-        /**
-         * The value to write to {@link #TIMEZONE_KEY_TYPE} if the provider
-         * should stay in sync with the device's time zone.
-         */
-        public static final String TIMEZONE_TYPE_AUTO = "auto";
-
-        /**
-         * The value to write to {@link #TIMEZONE_KEY_TYPE} if the provider
-         * should use a fixed time zone set by the user.
-         */
-        public static final String TIMEZONE_TYPE_HOME = "home";
-    }
-
-    /**
-     * A few Calendar globals are needed in the CalendarProvider for expanding
-     * the Instances table and these are all stored in the first (and only)
-     * row of the CalendarMetaData table.
-     */
-    public interface CalendarMetaDataColumns {
-        /**
-         * The local timezone that was used for precomputing the fields
-         * in the Instances table.
-         */
-        public static final String LOCAL_TIMEZONE = "localTimezone";
-
-        /**
-         * The minimum time used in expanding the Instances table,
-         * in UTC milliseconds.
-         * <P>Type: INTEGER</P>
-         */
-        public static final String MIN_INSTANCE = "minInstance";
-
-        /**
-         * The maximum time used in expanding the Instances table,
-         * in UTC milliseconds.
-         * <P>Type: INTEGER</P>
-         */
-        public static final String MAX_INSTANCE = "maxInstance";
-
-        /**
-         * The minimum Julian day in the EventDays table.
-         * <P>Type: INTEGER</P>
-         */
-        public static final String MIN_EVENTDAYS = "minEventDays";
-
-        /**
-         * The maximum Julian day in the EventDays table.
-         * <P>Type: INTEGER</P>
-         */
-        public static final String MAX_EVENTDAYS = "maxEventDays";
-    }
-
-    public static final class CalendarMetaData implements CalendarMetaDataColumns, BaseColumns {
-    }
-
-    public interface EventDaysColumns {
-        /**
-         * The Julian starting day number.
-         * <P>Type: INTEGER (int)</P>
-         */
-        public static final String STARTDAY = "startDay";
-        public static final String ENDDAY = "endDay";
-
-    }
-
-    public static final class EventDays implements EventDaysColumns {
-        public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY +
-                "/instances/groupbyday");
-
-        public static final String[] PROJECTION = { STARTDAY, ENDDAY };
-        public static final String SELECTION = "selected=1";
-
-        /**
-         * Retrieves the days with events for the Julian days starting at "startDay"
-         * for "numDays".
-         *
-         * @param cr the ContentResolver
-         * @param startDay the first Julian day in the range
-         * @param numDays the number of days to load (must be at least 1)
-         * @return a database cursor
-         */
-        public static final Cursor query(ContentResolver cr, int startDay, int numDays) {
-            if (numDays < 1) {
-                return null;
-            }
-            int endDay = startDay + numDays - 1;
-            Uri.Builder builder = CONTENT_URI.buildUpon();
-            ContentUris.appendId(builder, startDay);
-            ContentUris.appendId(builder, endDay);
-            return cr.query(builder.build(), PROJECTION, SELECTION,
-                    null /* selection args */, STARTDAY);
-        }
-    }
-
-    public interface RemindersColumns {
-        /**
-         * The event the reminder belongs to
-         * <P>Type: INTEGER (foreign key to the Events table)</P>
-         */
-        public static final String EVENT_ID = "event_id";
-
-        /**
-         * The minutes prior to the event that the alarm should ring.  -1
-         * specifies that we should use the default value for the system.
-         * <P>Type: INTEGER</P>
-         */
-        public static final String MINUTES = "minutes";
-
-        public static final int MINUTES_DEFAULT = -1;
-
-        /**
-         * The alarm method, as set on the server.  DEFAULT, ALERT, EMAIL, and
-         * SMS are possible values; the device will only process DEFAULT and
-         * ALERT reminders (the other types are simply stored so we can send the
-         * same reminder info back to the server when we make changes).
-         */
-        public static final String METHOD = "method";
-
-        public static final int METHOD_DEFAULT = 0;
-        public static final int METHOD_ALERT = 1;
-        public static final int METHOD_EMAIL = 2;
-        public static final int METHOD_SMS = 3;
-    }
-
-    public static final class Reminders implements BaseColumns, RemindersColumns, EventsColumns {
-        public static final String TABLE_NAME = "Reminders";
-        public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/reminders");
-    }
-
-    public interface CalendarAlertsColumns {
-        /**
-         * The event that the alert belongs to
-         * <P>Type: INTEGER (foreign key to the Events table)</P>
-         */
-        public static final String EVENT_ID = "event_id";
-
-        /**
-         * The start time of the event, in UTC
-         * <P>Type: INTEGER (long; millis since epoch)</P>
-         */
-        public static final String BEGIN = "begin";
-
-        /**
-         * The end time of the event, in UTC
-         * <P>Type: INTEGER (long; millis since epoch)</P>
-         */
-        public static final String END = "end";
-
-        /**
-         * The alarm time of the event, in UTC
-         * <P>Type: INTEGER (long; millis since epoch)</P>
-         */
-        public static final String ALARM_TIME = "alarmTime";
-
-        /**
-         * The creation time of this database entry, in UTC.
-         * (Useful for debugging missed reminders.)
-         * <P>Type: INTEGER (long; millis since epoch)</P>
-         */
-        public static final String CREATION_TIME = "creationTime";
-
-        /**
-         * The time that the alarm broadcast was received by the Calendar app,
-         * in UTC. (Useful for debugging missed reminders.)
-         * <P>Type: INTEGER (long; millis since epoch)</P>
-         */
-        public static final String RECEIVED_TIME = "receivedTime";
-
-        /**
-         * The time that the notification was created by the Calendar app,
-         * in UTC. (Useful for debugging missed reminders.)
-         * <P>Type: INTEGER (long; millis since epoch)</P>
-         */
-        public static final String NOTIFY_TIME = "notifyTime";
-
-        /**
-         * The state of this alert.  It starts out as SCHEDULED, then when
-         * the alarm goes off, it changes to FIRED, and then when the user
-         * dismisses the alarm it changes to DISMISSED.
-         * <P>Type: INTEGER</P>
-         */
-        public static final String STATE = "state";
-
-        public static final int SCHEDULED = 0;
-        public static final int FIRED = 1;
-        public static final int DISMISSED = 2;
-
-        /**
-         * The number of minutes that this alarm precedes the start time
-         * <P>Type: INTEGER </P>
-         */
-        public static final String MINUTES = "minutes";
-
-        /**
-         * The default sort order for this table
-         */
-        public static final String DEFAULT_SORT_ORDER = "begin ASC,title ASC";
-    }
-
-    public static final class CalendarAlerts implements BaseColumns,
-            CalendarAlertsColumns, EventsColumns, CalendarsColumns {
-
-        public static final String TABLE_NAME = "CalendarAlerts";
-        public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY +
-                "/calendar_alerts");
-
-        private static final String WHERE_ALARM_EXISTS = EVENT_ID + "=?"
-                + " AND " + BEGIN + "=?"
-                + " AND " + ALARM_TIME + "=?";
-
-        private static final String WHERE_FINDNEXTALARMTIME = ALARM_TIME + ">=?";
-        private static final String SORT_ORDER_ALARMTIME_ASC = ALARM_TIME + " ASC";
-
-        private static final String WHERE_RESCHEDULE_MISSED_ALARMS = STATE + "=" + SCHEDULED
-                + " AND " + ALARM_TIME + "<?"
-                + " AND " + ALARM_TIME + ">?"
-                + " AND " + END + ">=?";
-
-        /**
-         * This URI is for grouping the query results by event_id and begin
-         * time.  This will return one result per instance of an event.  So
-         * events with multiple alarms will appear just once, but multiple
-         * instances of a repeating event will show up multiple times.
-         */
-        public static final Uri CONTENT_URI_BY_INSTANCE =
-            Uri.parse("content://" + AUTHORITY + "/calendar_alerts/by_instance");
-
-        private static final boolean DEBUG = true;
-
-        public static final Uri insert(ContentResolver cr, long eventId,
-                long begin, long end, long alarmTime, int minutes) {
-            ContentValues values = new ContentValues();
-            values.put(CalendarAlerts.EVENT_ID, eventId);
-            values.put(CalendarAlerts.BEGIN, begin);
-            values.put(CalendarAlerts.END, end);
-            values.put(CalendarAlerts.ALARM_TIME, alarmTime);
-            long currentTime = System.currentTimeMillis();
-            values.put(CalendarAlerts.CREATION_TIME, currentTime);
-            values.put(CalendarAlerts.RECEIVED_TIME, 0);
-            values.put(CalendarAlerts.NOTIFY_TIME, 0);
-            values.put(CalendarAlerts.STATE, SCHEDULED);
-            values.put(CalendarAlerts.MINUTES, minutes);
-            return cr.insert(CONTENT_URI, values);
-        }
-
-        public static final Cursor query(ContentResolver cr, String[] projection,
-                String selection, String[] selectionArgs, String sortOrder) {
-            return cr.query(CONTENT_URI, projection, selection, selectionArgs,
-                    sortOrder);
-        }
-
-        /**
-         * Finds the next alarm after (or equal to) the given time and returns
-         * the time of that alarm or -1 if no such alarm exists.
-         *
-         * @param cr the ContentResolver
-         * @param millis the time in UTC milliseconds
-         * @return the next alarm time greater than or equal to "millis", or -1
-         *     if no such alarm exists.
-         */
-        public static final long findNextAlarmTime(ContentResolver cr, long millis) {
-            String selection = ALARM_TIME + ">=" + millis;
-            // TODO: construct an explicit SQL query so that we can add
-            // "LIMIT 1" to the end and get just one result.
-            String[] projection = new String[] { ALARM_TIME };
-            Cursor cursor = query(cr, projection,
-                    WHERE_FINDNEXTALARMTIME,
-                    new String[] {
-                        Long.toString(millis)
-                    },
-                    SORT_ORDER_ALARMTIME_ASC);
-            long alarmTime = -1;
-            try {
-                if (cursor != null && cursor.moveToFirst()) {
-                    alarmTime = cursor.getLong(0);
-                }
-            } finally {
-                if (cursor != null) {
-                    cursor.close();
-                }
-            }
-            return alarmTime;
-        }
-
-        /**
-         * Searches the CalendarAlerts table for alarms that should have fired
-         * but have not and then reschedules them.  This method can be called
-         * at boot time to restore alarms that may have been lost due to a
-         * phone reboot.
-         *
-         * @param cr the ContentResolver
-         * @param context the Context
-         * @param manager the AlarmManager
-         */
-        public static final void rescheduleMissedAlarms(ContentResolver cr,
-                Context context, AlarmManager manager) {
-            // Get all the alerts that have been scheduled but have not fired
-            // and should have fired by now and are not too old.
-            long now = System.currentTimeMillis();
-            long ancient = now - DateUtils.DAY_IN_MILLIS;
-            String[] projection = new String[] {
-                    ALARM_TIME,
-            };
-
-            // TODO: construct an explicit SQL query so that we can add
-            // "GROUPBY" instead of doing a sort and de-dup
-            Cursor cursor = CalendarAlerts.query(cr,
-                    projection,
-                    WHERE_RESCHEDULE_MISSED_ALARMS,
-                    new String[] {
-                        Long.toString(now),
-                        Long.toString(ancient),
-                        Long.toString(now)
-                    },
-                    SORT_ORDER_ALARMTIME_ASC);
-            if (cursor == null) {
-                return;
-            }
-
-            if (DEBUG) {
-                Log.d(TAG, "missed alarms found: " + cursor.getCount());
-            }
-
-            try {
-                long alarmTime = -1;
-
-                while (cursor.moveToNext()) {
-                    long newAlarmTime = cursor.getLong(0);
-                    if (alarmTime != newAlarmTime) {
-                        if (DEBUG) {
-                            Log.w(TAG, "rescheduling missed alarm. alarmTime: " + newAlarmTime);
-                        }
-                        scheduleAlarm(context, manager, newAlarmTime);
-                        alarmTime = newAlarmTime;
-                    }
-                }
-            } finally {
-                cursor.close();
-            }
-        }
-
-        public static void scheduleAlarm(Context context, AlarmManager manager, long alarmTime) {
-            if (DEBUG) {
-                Time time = new Time();
-                time.set(alarmTime);
-                String schedTime = time.format(" %a, %b %d, %Y %I:%M%P");
-                Log.d(TAG, "Schedule alarm at " + alarmTime + " " + schedTime);
-            }
-
-            if (manager == null) {
-                manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
-            }
-
-            Intent intent = new Intent(EVENT_REMINDER_ACTION);
-            intent.setData(ContentUris.withAppendedId(Calendar.CONTENT_URI, alarmTime));
-            intent.putExtra(ALARM_TIME, alarmTime);
-            PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0);
-            manager.set(AlarmManager.RTC_WAKEUP, alarmTime, pi);
-        }
-
-        /**
-         * Searches for an entry in the CalendarAlerts table that matches
-         * the given event id, begin time and alarm time.  If one is found
-         * then this alarm already exists and this method returns true.
-         *
-         * @param cr the ContentResolver
-         * @param eventId the event id to match
-         * @param begin the start time of the event in UTC millis
-         * @param alarmTime the alarm time of the event in UTC millis
-         * @return true if there is already an alarm for the given event
-         *   with the same start time and alarm time.
-         */
-        public static final boolean alarmExists(ContentResolver cr, long eventId,
-                long begin, long alarmTime) {
-            // TODO: construct an explicit SQL query so that we can add
-            // "LIMIT 1" to the end and get just one result.
-            String[] projection = new String[] { ALARM_TIME };
-            Cursor cursor = query(cr,
-                    projection,
-                    WHERE_ALARM_EXISTS,
-                    new String[] {
-                        Long.toString(eventId),
-                        Long.toString(begin),
-                        Long.toString(alarmTime)
-                    },
-                    null);
-            boolean found = false;
-            try {
-                if (cursor != null && cursor.getCount() > 0) {
-                    found = true;
-                }
-            } finally {
-                if (cursor != null) {
-                    cursor.close();
-                }
-            }
-            return found;
-        }
-    }
-
-    public interface ExtendedPropertiesColumns {
-        /**
-         * The event the extended property belongs to
-         * <P>Type: INTEGER (foreign key to the Events table)</P>
-         */
-        public static final String EVENT_ID = "event_id";
-
-        /**
-         * The name of the extended property.  This is a uri of the form
-         * {scheme}#{local-name} convention.
-         * <P>Type: TEXT</P>
-         */
-        public static final String NAME = "name";
-
-        /**
-         * The value of the extended property.
-         * <P>Type: TEXT</P>
-         */
-        public static final String VALUE = "value";
-    }
-
-   public static final class ExtendedProperties implements BaseColumns,
-            ExtendedPropertiesColumns, EventsColumns {
-        public static final Uri CONTENT_URI =
-                Uri.parse("content://" + AUTHORITY + "/extendedproperties");
-
-        // TODO: fill out this class when we actually start utilizing extendedproperties
-        // in the calendar application.
-   }
-
-    /**
-     * A table provided for sync adapters to use for storing private sync state data.
-     *
-     * @see SyncStateContract
-     */
-    public static final class SyncState implements SyncStateContract.Columns {
-        /**
-         * This utility class cannot be instantiated
-         */
-        private SyncState() {}
-
-        public static final String CONTENT_DIRECTORY =
-                SyncStateContract.Constants.CONTENT_DIRECTORY;
-
-        /**
-         * The content:// style URI for this table
-         */
-        public static final Uri CONTENT_URI =
-                Uri.withAppendedPath(Calendar.CONTENT_URI, CONTENT_DIRECTORY);
-    }
-
-    /**
-     * Columns from the EventsRawTimes table
-     */
-    public interface EventsRawTimesColumns {
-        /**
-         * The corresponding event id
-         * <P>Type: INTEGER (long)</P>
-         */
-        public static final String EVENT_ID = "event_id";
-
-        /**
-         * The RFC2445 compliant time the event starts
-         * <P>Type: TEXT</P>
-         */
-        public static final String DTSTART_2445 = "dtstart2445";
-
-        /**
-         * The RFC2445 compliant time the event ends
-         * <P>Type: TEXT</P>
-         */
-        public static final String DTEND_2445 = "dtend2445";
-
-        /**
-         * The RFC2445 compliant original instance time of the recurring event for which this
-         * event is an exception.
-         * <P>Type: TEXT</P>
-         */
-        public static final String ORIGINAL_INSTANCE_TIME_2445 = "originalInstanceTime2445";
-
-        /**
-         * The RFC2445 compliant last date this event repeats on, or NULL if it never ends
-         * <P>Type: TEXT</P>
-         */
-        public static final String LAST_DATE_2445 = "lastDate2445";
-    }
-
-    public static final class EventsRawTimes implements BaseColumns, EventsRawTimesColumns {
-    }
-}
diff --git a/core/java/android/provider/CalendarContract.java b/core/java/android/provider/CalendarContract.java
new file mode 100644
index 0000000..4368e31
--- /dev/null
+++ b/core/java/android/provider/CalendarContract.java
@@ -0,0 +1,2446 @@
+/*
+ * Copyright (C) 2006 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.provider;
+
+
+import android.accounts.Account;
+import android.app.AlarmManager;
+import android.app.PendingIntent;
+import android.content.ContentProviderClient;
+import android.content.ContentResolver;
+import android.content.ContentUris;
+import android.content.ContentValues;
+import android.content.Context;
+import android.content.CursorEntityIterator;
+import android.content.Entity;
+import android.content.EntityIterator;
+import android.content.Intent;
+import android.database.Cursor;
+import android.database.DatabaseUtils;
+import android.net.Uri;
+import android.os.RemoteException;
+import android.text.TextUtils;
+import android.text.format.DateUtils;
+import android.text.format.Time;
+import android.util.Log;
+
+/**
+ * <p>
+ * The contract between the calendar provider and applications. Contains
+ * definitions for the supported URIs and data columns.
+ * </p>
+ * <h3>Overview</h3>
+ * <p>
+ * CalendarContract defines the data model of calendar and event related
+ * information. This data is stored in a number of tables:
+ * </p>
+ * <ul>
+ * <li>The {@link Calendars} table holds the calendar specific information. Each
+ * row in this table contains the details for a single calendar, such as the
+ * name, color, sync info, etc.</li>
+ * <li>The {@link Events} table holds the event specific information. Each row
+ * in this table has the info for a single event. It contains information such
+ * as event title, location, start time, end time, etc. The event can occur
+ * one-time or can recur multiple times. Attendees, reminders, and extended
+ * properties are stored on separate tables and reference the {@link Events#_ID}
+ * to link them with the event.</li>
+ * <li>The {@link Instances} table holds the start and end time for occurrences
+ * of an event. Each row in this table represents a single occurrence. For
+ * one-time events there will be a 1:1 mapping of instances to events. For
+ * recurring events, multiple rows will automatically be generated which
+ * correspond to multiple occurrences of that event.</li>
+ * <li>The {@link Attendees} table holds the event attendee or guest
+ * information. Each row represents a single guest of an event. It specifies the
+ * type of guest they are and their attendance response for the event.</li>
+ * <li>The {@link Reminders} table holds the alert/notification data. Each row
+ * represents a single alert for an event. An event can have multiple reminders.
+ * The number of reminders per event is specified in
+ * {@link Calendars#MAX_REMINDERS} which is set by the Sync Adapter that owns
+ * the given calendar. Reminders are specified in minutes before the event and
+ * have a type.</li>
+ * <li>The {@link ExtendedProperties} table hold opaque data fields used by the
+ * sync adapter. The provider takes no action with items in this table except to
+ * delete them when their related events are deleted.</li>
+ * </ul>
+ * <p>
+ * Other tables include:
+ * </p>
+ * <ul>
+ * <li>
+ * {@link SyncState}, which contains free-form data maintained by the sync
+ * adapters</li>
+ * </ul>
+ *
+ * @hide
+ */
+public final class CalendarContract {
+    private static final String TAG = "Calendar";
+
+    /**
+     * Broadcast Action: This is the intent that gets fired when an alarm
+     * notification needs to be posted for a reminder.
+     */
+    public static final String EVENT_REMINDER_ACTION = "android.intent.action.EVENT_REMINDER";
+
+    /**
+     * Intent Extras key: The start time of an event or an instance of a
+     * recurring event. (milliseconds since epoch)
+     */
+    public static final String EVENT_BEGIN_TIME = "beginTime";
+
+    /**
+     * Intent Extras key: The end time of an event or an instance of a recurring
+     * event. (milliseconds since epoch)
+     */
+    public static final String EVENT_END_TIME = "endTime";
+
+    /**
+     * This authority is used for writing to or querying from the calendar
+     * provider. Note: This is set at first run and cannot be changed without
+     * breaking apps that access the provider.
+     */
+    public static final String AUTHORITY = "com.android.calendar";
+
+    /**
+     * The content:// style URL for the top-level calendar authority
+     */
+    public static final Uri CONTENT_URI =
+        Uri.parse("content://" + AUTHORITY);
+
+    /**
+     * An optional insert, update or delete URI parameter that allows the caller
+     * to specify that it is a sync adapter. The default value is false. If set
+     * to true, the modified row is not marked as "dirty" (needs to be synced)
+     * and when the provider calls
+     * {@link ContentResolver#notifyChange(android.net.Uri, android.database.ContentObserver, boolean)}
+     * , the third parameter "syncToNetwork" is set to false. Furthermore, if
+     * set to true, the caller must also include
+     * {@link Calendars#ACCOUNT_NAME} and {@link Calendars#ACCOUNT_TYPE} as
+     * query parameters.
+     *
+     * @see Uri.Builder#appendQueryParameter(java.lang.String, java.lang.String)
+     */
+    public static final String CALLER_IS_SYNCADAPTER = "caller_is_syncadapter";
+
+    /**
+     * A special account type for calendars not associated with any account.
+     * Normally calendars that do not match an account on the device will be
+     * removed. Setting the account_type on a calendar to this will prevent it
+     * from being wiped if it does not match an existing account.
+     *
+     * @see SyncColumns#ACCOUNT_TYPE
+     */
+    public static final String ACCOUNT_TYPE_LOCAL = "LOCAL";
+
+    /**
+     * Generic columns for use by sync adapters. The specific functions of these
+     * columns are private to the sync adapter. Other clients of the API should
+     * not attempt to either read or write this column. These columns are
+     * editable as part of the Calendars Uri, but can only be read if accessed
+     * through any other Uri.
+     */
+    protected interface CalendarSyncColumns {
+
+
+        /**
+         * Generic column for use by sync adapters. Column name.
+         * <P>Type: TEXT</P>
+         */
+        public static final String CAL_SYNC1 = "cal_sync1";
+
+        /**
+         * Generic column for use by sync adapters. Column name.
+         * <P>Type: TEXT</P>
+         */
+        public static final String CAL_SYNC2 = "cal_sync2";
+
+        /**
+         * Generic column for use by sync adapters. Column name.
+         * <P>Type: TEXT</P>
+         */
+        public static final String CAL_SYNC3 = "cal_sync3";
+
+        /**
+         * Generic column for use by sync adapters. Column name.
+         * <P>Type: TEXT</P>
+         */
+        public static final String CAL_SYNC4 = "cal_sync4";
+
+        /**
+         * Generic column for use by sync adapters. Column name.
+         * <P>Type: TEXT</P>
+         */
+        public static final String CAL_SYNC5 = "cal_sync5";
+
+        /**
+         * Generic column for use by sync adapters. Column name.
+         * <P>Type: TEXT</P>
+         */
+        public static final String CAL_SYNC6 = "cal_sync6";
+
+        /**
+         * Generic column for use by sync adapters. Column name.
+         * <P>Type: TEXT</P>
+         */
+        public static final String CAL_SYNC7 = "cal_sync7";
+
+        /**
+         * Generic column for use by sync adapters. Column name.
+         * <P>Type: TEXT</P>
+         */
+        public static final String CAL_SYNC8 = "cal_sync8";
+
+        /**
+         * Generic column for use by sync adapters. Column name.
+         * <P>Type: TEXT</P>
+         */
+        public static final String CAL_SYNC9 = "cal_sync9";
+
+        /**
+         * Generic column for use by sync adapters. Column name.
+         * <P>Type: TEXT</P>
+         */
+        public static final String CAL_SYNC10 = "cal_sync10";
+    }
+
+    /**
+     * Columns for Sync information used by Calendars and Events tables. These
+     * have specific uses which are expected to be consistent by the app and
+     * sync adapter.
+     *
+     */
+    protected interface SyncColumns extends CalendarSyncColumns {
+        /**
+         * The account that was used to sync the entry to the device. If the
+         * account_type is not {@link #ACCOUNT_TYPE_LOCAL} then the name and
+         * type must match an account on the device or the calendar will be
+         * deleted.
+         * <P>Type: TEXT</P>
+         */
+        public static final String ACCOUNT_NAME = "account_name";
+
+        /**
+         * The type of the account that was used to sync the entry to the
+         * device. A type of {@link #ACCOUNT_TYPE_LOCAL} will keep this event
+         * form being deleted if there are no matching accounts on the device.
+         * <P>Type: TEXT</P>
+         */
+        public static final String ACCOUNT_TYPE = "account_type";
+
+        /**
+         * The unique ID for a row assigned by the sync source. NULL if the row
+         * has never been synced. This is used as a reference id for exceptions
+         * along with {@link BaseColumns#_ID}.
+         * <P>Type: TEXT</P>
+         */
+        public static final String _SYNC_ID = "_sync_id";
+
+        /**
+         * Used to indicate that local, unsynced, changes are present.
+         * <P>Type: INTEGER (long)</P>
+         */
+        public static final String DIRTY = "dirty";
+
+        /**
+         * Whether the row has been deleted but not synced to the server. A
+         * deleted row should be ignored.
+         * <P>
+         * Type: INTEGER (boolean)
+         * </P>
+         */
+        public static final String DELETED = "deleted";
+
+        /**
+         * If set to 1 this causes events on this calendar to be duplicated with
+         * {@link Events#LAST_SYNCED} set to 1 whenever the event
+         * transitions from non-dirty to dirty. The duplicated event will not be
+         * expanded in the instances table and will only show up in sync adapter
+         * queries of the events table. It will also be deleted when the
+         * originating event has its dirty flag cleared by the sync adapter.
+         * <P>Type: INTEGER (boolean)</P>
+         */
+        public static final String CAN_PARTIALLY_UPDATE = "canPartiallyUpdate";
+    }
+
+    /**
+     * Columns specific to the Calendars Uri that other Uris can query.
+     */
+    protected interface CalendarsColumns {
+        /**
+         * The color of the calendar
+         * <P>Type: INTEGER (color value)</P>
+         */
+        public static final String CALENDAR_COLOR = "calendar_color";
+
+        /**
+         * The display name of the calendar. Column name.
+         * <P>Type: TEXT</P>
+         */
+        public static final String CALENDAR_DISPLAY_NAME = "calendar_displayName";
+
+        /**
+         * The level of access that the user has for the calendar
+         * <P>Type: INTEGER (one of the values below)</P>
+         */
+        public static final String CALENDAR_ACCESS_LEVEL = "calendar_access_level";
+
+        /** Cannot access the calendar */
+        public static final int CAL_ACCESS_NONE = 0;
+        /** Can only see free/busy information about the calendar */
+        public static final int CAL_ACCESS_FREEBUSY = 100;
+        /** Can read all event details */
+        public static final int CAL_ACCESS_READ = 200;
+        /** Can reply yes/no/maybe to an event */
+        public static final int CAL_ACCESS_RESPOND = 300;
+        /** not used */
+        public static final int CAL_ACCESS_OVERRIDE = 400;
+        /** Full access to modify the calendar, but not the access control
+         * settings
+         */
+        public static final int CAL_ACCESS_CONTRIBUTOR = 500;
+        /** Full access to modify the calendar, but not the access control
+         * settings
+         */
+        public static final int CAL_ACCESS_EDITOR = 600;
+        /** Full access to the calendar */
+        public static final int CAL_ACCESS_OWNER = 700;
+        /** Domain admin */
+        public static final int CAL_ACCESS_ROOT = 800;
+
+        /**
+         * Is the calendar selected to be displayed?
+         * 0 - do not show events associated with this calendar.
+         * 1 - show events associated with this calendar
+         * <P>Type: INTEGER (boolean)</P>
+         */
+        public static final String VISIBLE = "visible";
+
+        /**
+         * The time zone the calendar is associated with.
+         * <P>Type: TEXT</P>
+         */
+        public static final String CALENDAR_TIME_ZONE = "calendar_timezone";
+
+        /**
+         * Is this calendar synced and are its events stored on the device?
+         * 0 - Do not sync this calendar or store events for this calendar.
+         * 1 - Sync down events for this calendar.
+         * <p>Type: INTEGER (boolean)</p>
+         */
+        public static final String SYNC_EVENTS = "sync_events";
+
+        /**
+         * The owner account for this calendar, based on the calendar feed.
+         * This will be different from the _SYNC_ACCOUNT for delegated calendars.
+         * Column name.
+         * <P>Type: String</P>
+         */
+        public static final String OWNER_ACCOUNT = "ownerAccount";
+
+        /**
+         * Can the organizer respond to the event?  If no, the status of the
+         * organizer should not be shown by the UI.  Defaults to 1. Column name.
+         * <P>Type: INTEGER (boolean)</P>
+         */
+        public static final String CAN_ORGANIZER_RESPOND = "canOrganizerRespond";
+
+        /**
+         * Can the organizer modify the time zone of the event? Column name.
+         * <P>Type: INTEGER (boolean)</P>
+        */
+        public static final String CAN_MODIFY_TIME_ZONE = "canModifyTimeZone";
+
+        /**
+         * The maximum number of reminders allowed for an event. Column name.
+         * <P>Type: INTEGER</P>
+         */
+        public static final String MAX_REMINDERS = "maxReminders";
+
+        /**
+         * A comma separated list of reminder methods supported for this
+         * calendar in the format "#,#,#". Valid types are
+         * {@link Reminders#METHOD_DEFAULT}, {@link Reminders#METHOD_ALERT},
+         * {@link Reminders#METHOD_EMAIL}, {@link Reminders#METHOD_SMS}. Column
+         * name.
+         * <P>Type: TEXT</P>
+         */
+        public static final String ALLOWED_REMINDERS = "allowedReminders";
+    }
+
+    /**
+     * Class that represents a Calendar Entity. There is one entry per calendar.
+     * This is a helper class to make batch operations easier.
+     */
+    public static class CalendarsEntity implements BaseColumns, SyncColumns, CalendarsColumns {
+
+        /**
+         * The default Uri used when creating a new calendar EntityIterator.
+         */
+        @SuppressWarnings("hiding")
+        public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY +
+                "/calendar_entities");
+
+        /**
+         * Creates an entity iterator for the given cursor. It assumes the
+         * cursor contains a calendars query.
+         *
+         * @param cursor query on {@link #CONTENT_URI}
+         * @return an EntityIterator of calendars
+         */
+        public static EntityIterator newEntityIterator(Cursor cursor) {
+            return new EntityIteratorImpl(cursor);
+        }
+
+        private static class EntityIteratorImpl extends CursorEntityIterator {
+
+            public EntityIteratorImpl(Cursor cursor) {
+                super(cursor);
+            }
+
+            @Override
+            public Entity getEntityAndIncrementCursor(Cursor cursor) throws RemoteException {
+                // we expect the cursor is already at the row we need to read from
+                final long calendarId = cursor.getLong(cursor.getColumnIndexOrThrow(_ID));
+
+                // Create the content value
+                ContentValues cv = new ContentValues();
+                cv.put(_ID, calendarId);
+
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, ACCOUNT_NAME);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, ACCOUNT_TYPE);
+
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, _SYNC_ID);
+                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, DIRTY);
+
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC1);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC2);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC3);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC4);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC5);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC6);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC7);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC8);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC9);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC10);
+
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, Calendars.NAME);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv,
+                        Calendars.CALENDAR_DISPLAY_NAME);
+                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv,
+                        Calendars.CALENDAR_COLOR);
+                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, CALENDAR_ACCESS_LEVEL);
+                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, VISIBLE);
+                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, SYNC_EVENTS);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv,
+                        Calendars.CALENDAR_LOCATION);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CALENDAR_TIME_ZONE);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv,
+                        Calendars.OWNER_ACCOUNT);
+                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv,
+                        Calendars.CAN_ORGANIZER_RESPOND);
+                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv,
+                        Calendars.CAN_MODIFY_TIME_ZONE);
+                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv,
+                        Calendars.MAX_REMINDERS);
+                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv,
+                        Calendars.CAN_PARTIALLY_UPDATE);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv,
+                        Calendars.ALLOWED_REMINDERS);
+
+                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, DELETED);
+
+                // Create the Entity from the ContentValue
+                Entity entity = new Entity(cv);
+
+                // Set cursor to next row
+                cursor.moveToNext();
+
+                // Return the created Entity
+                return entity;
+            }
+        }
+     }
+
+    /**
+     * Constants and helpers for the Calendars table, which contains details for
+     * individual calendars. <h3>Operations</h3> All operations can be done
+     * either as an app or as a sync adapter. To perform an operation as a sync
+     * adapter {@link #CALLER_IS_SYNCADAPTER} should be set to true and
+     * {@link #ACCOUNT_NAME} and {@link #ACCOUNT_TYPE} must be set in the Uri
+     * parameters. See
+     * {@link Uri.Builder#appendQueryParameter(java.lang.String, java.lang.String)}
+     * for details on adding parameters. Sync adapters have write access to more
+     * columns but are restricted to a single account at a time. Calendars are
+     * designed to be primarily managed by a sync adapter and inserting new
+     * calendars should be done as a sync adapter. For the most part, apps
+     * should only update calendars (such as changing the color or display
+     * name). If a local calendar is required an app can do so by inserting as a
+     * sync adapter and using an {@link #ACCOUNT_TYPE} of
+     * {@link #ACCOUNT_TYPE_LOCAL} .
+     * <dl>
+     * <dt><b>Insert</b></dt>
+     * <dd>When inserting a new calendar the following fields must be included:
+     * <ul>
+     * <li>{@link #ACCOUNT_NAME}</li>
+     * <li>{@link #ACCOUNT_TYPE}</li>
+     * <li>{@link #NAME}</li>
+     * <li>{@link #CALENDAR_DISPLAY_NAME}</li>
+     * <li>{@link #CALENDAR_COLOR}</li>
+     * <li>{@link #CALENDAR_ACCESS_LEVEL}</li>
+     * <li>{@link #OWNER_ACCOUNT}</li>
+     * </ul>
+     * The following fields are not required when inserting a Calendar but are
+     * generally a good idea to include:
+     * <ul>
+     * <li>{@link #SYNC_EVENTS} set to 1</li>
+     * <li>{@link #CALENDAR_TIME_ZONE}</li>
+     * <li>{@link #ALLOWED_REMINDERS}</li>
+     * </ul>
+     * <dt><b>Update</b></dt>
+     * <dd>To perform an update on a calendar the {@link #_ID} of the calendar
+     * should be provided either as an appended id to the Uri (
+     * {@link ContentUris#withAppendedId}) or as the first selection item--the
+     * selection should start with "_id=?" and the first selectionArg should be
+     * the _id of the calendar. Calendars may also be updated using a selection
+     * without the id. In general, the {@link #ACCOUNT_NAME} and
+     * {@link #ACCOUNT_TYPE} should not be changed after a calendar is created
+     * as this can cause issues for sync adapters.
+     * <dt><b>Delete</b></dt>
+     * <dd>Calendars can be deleted either by the {@link #_ID} as an appended id
+     * on the Uri or using any standard selection. Deleting a calendar should
+     * generally be handled by a sync adapter as it will remove the calendar
+     * from the database and all associated data (aka events).</dd>
+     * <dt><b>Query</b></dt>
+     * <dd>Querying the Calendars table will get you all information about a set
+     * of calendars. There will be one row returned for each calendar that
+     * matches the query selection, or at most a single row if the {@link #_ID}
+     * is appended to the Uri.</dd>
+     * </dl>
+     * <h3>Calendar Columns</h3> The following Calendar columns are writable by
+     * both an app and a sync adapter.
+     * <ul>
+     * <li>{@link #NAME}</li>
+     * <li>{@link #CALENDAR_DISPLAY_NAME}</li>
+     * <li>{@link #CALENDAR_COLOR}</li>
+     * <li>{@link #VISIBLE}</li>
+     * <li>{@link #SYNC_EVENTS}</li>
+     * </ul>
+     * The following Calendars columns are writable only by a sync adapter
+     * <ul>
+     * <li>{@link #ACCOUNT_NAME}</li>
+     * <li>{@link #ACCOUNT_TYPE}</li>
+     * <li>{@link #_SYNC_ID}</li>
+     * <li>{@link #DIRTY}</li>
+     * <li>{@link #OWNER_ACCOUNT}</li>
+     * <li>{@link #MAX_REMINDERS}</li>
+     * <li>{@link #ALLOWED_REMINDERS}</li>
+     * <li>{@link #CAN_MODIFY_TIME_ZONE}</li>
+     * <li>{@link #CAN_ORGANIZER_RESPOND}</li>
+     * <li>{@link #CAN_PARTIALLY_UPDATE}</li>
+     * <li>{@link #CALENDAR_LOCATION}</li>
+     * <li>{@link #CALENDAR_TIME_ZONE}</li>
+     * <li>{@link #CALENDAR_ACCESS_LEVEL}</li>
+     * <li>{@link #DELETED}</li>
+     * <li>{@link #CAL_SYNC1}</li>
+     * <li>{@link #CAL_SYNC2}</li>
+     * <li>{@link #CAL_SYNC3}</li>
+     * <li>{@link #CAL_SYNC4}</li>
+     * <li>{@link #CAL_SYNC5}</li>
+     * <li>{@link #CAL_SYNC6}</li>
+     * <li>{@link #CAL_SYNC7}</li>
+     * <li>{@link #CAL_SYNC8}</li>
+     * <li>{@link #CAL_SYNC9}</li>
+     * <li>{@link #CAL_SYNC10}</li>
+     * </ul>
+     */
+    public static class Calendars implements BaseColumns, SyncColumns, CalendarsColumns {
+        private static final String WHERE_DELETE_FOR_ACCOUNT = Calendars.ACCOUNT_NAME + "=?"
+                + " AND "
+                + Calendars.ACCOUNT_TYPE + "=?";
+
+        /**
+         * Helper function for generating a calendars query. This is blocking
+         * and should not be used on the UI thread. See
+         * {@link ContentResolver#query(Uri, String[], String, String[], String)}
+         * for more details about using the parameters.
+         *
+         * @param cr The ContentResolver to query with
+         * @param projection A list of columns to return
+         * @param selection A formatted selection string
+         * @param selectionArgs arguments to the selection string
+         * @param orderBy How to order the returned rows
+         * @return
+         */
+        public static final Cursor query(ContentResolver cr, String[] projection, String selection,
+                String[] selectionArgs, String orderBy) {
+            return cr.query(CONTENT_URI, projection, selection, selectionArgs,
+                    orderBy == null ? DEFAULT_SORT_ORDER : orderBy);
+        }
+
+        /**
+         * Convenience method perform a delete on the Calendar provider. This is
+         * a blocking call and should not be used on the UI thread.
+         *
+         * @param cr the ContentResolver
+         * @param selection A filter to apply to rows before deleting, formatted
+         *            as an SQL WHERE clause (excluding the WHERE itself).
+         * @param selectionArgs Fill in the '?'s in the selection
+         * @return the count of rows that were deleted
+         */
+        public static int delete(ContentResolver cr, String selection, String[] selectionArgs)
+        {
+            return cr.delete(CONTENT_URI, selection, selectionArgs);
+        }
+
+        /**
+         * Convenience method to delete all calendars that match the account.
+         * This is a blocking call and should not be used on the UI thread.
+         *
+         * @param cr the ContentResolver
+         * @param account the account whose calendars and events should be
+         *            deleted
+         * @return the count of calendar rows that were deleted
+         */
+        public static int deleteCalendarsForAccount(ContentResolver cr, Account account) {
+            // delete all calendars that match this account
+            return CalendarContract.Calendars.delete(cr,
+                    WHERE_DELETE_FOR_ACCOUNT,
+                    new String[] { account.name, account.type });
+        }
+
+        /**
+         * The content:// style URL for accessing Calendars
+         */
+        @SuppressWarnings("hiding")
+        public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/calendars");
+
+        /**
+         * The default sort order for this table
+         */
+        public static final String DEFAULT_SORT_ORDER = "displayName";
+
+        /**
+         * The name of the calendar. Column name.
+         * <P>Type: TEXT</P>
+         */
+        public static final String NAME = "name";
+
+        /**
+         * The default location for the calendar. Column name.
+         * <P>Type: TEXT</P>
+         */
+        public static final String CALENDAR_LOCATION = "calendar_location";
+
+        /**
+         * These fields are only writable by a sync adapter. To modify them the
+         * caller must include {@link #CALLER_IS_SYNCADAPTER},
+         * {@link #ACCOUNT_NAME}, and {@link #ACCOUNT_TYPE} in the Uri's query
+         * parameters.
+         */
+        public static final String[] SYNC_WRITABLE_COLUMNS = new String[] {
+            ACCOUNT_NAME,
+            ACCOUNT_TYPE,
+            _SYNC_ID,
+            DIRTY,
+            OWNER_ACCOUNT,
+            MAX_REMINDERS,
+            ALLOWED_REMINDERS,
+            CAN_MODIFY_TIME_ZONE,
+            CAN_ORGANIZER_RESPOND,
+            CAN_PARTIALLY_UPDATE,
+            CALENDAR_LOCATION,
+            CALENDAR_TIME_ZONE,
+            CALENDAR_ACCESS_LEVEL,
+            DELETED,
+            CAL_SYNC1,
+            CAL_SYNC2,
+            CAL_SYNC3,
+            CAL_SYNC4,
+            CAL_SYNC5,
+            CAL_SYNC6,
+            CAL_SYNC7,
+            CAL_SYNC8,
+            CAL_SYNC9,
+            CAL_SYNC10,
+        };
+    }
+
+    /**
+     * Columns from the Attendees table that other tables join into themselves.
+     */
+    protected interface AttendeesColumns {
+
+        /**
+         * The id of the event. Column name.
+         * <P>Type: INTEGER</P>
+         */
+        public static final String EVENT_ID = "event_id";
+
+        /**
+         * The name of the attendee. Column name.
+         * <P>Type: STRING</P>
+         */
+        public static final String ATTENDEE_NAME = "attendeeName";
+
+        /**
+         * The email address of the attendee. Column name.
+         * <P>Type: STRING</P>
+         */
+        public static final String ATTENDEE_EMAIL = "attendeeEmail";
+
+        /**
+         * The relationship of the attendee to the user. Column name.
+         * <P>Type: INTEGER (one of {@link #RELATIONSHIP_ATTENDEE}, ...}.</P>
+         */
+        public static final String ATTENDEE_RELATIONSHIP = "attendeeRelationship";
+
+        public static final int RELATIONSHIP_NONE = 0;
+        public static final int RELATIONSHIP_ATTENDEE = 1;
+        public static final int RELATIONSHIP_ORGANIZER = 2;
+        public static final int RELATIONSHIP_PERFORMER = 3;
+        public static final int RELATIONSHIP_SPEAKER = 4;
+
+        /**
+         * The type of attendee. Column name.
+         * <P>Type: Integer (one of {@link #TYPE_REQUIRED}, {@link #TYPE_OPTIONAL})</P>
+         */
+        public static final String ATTENDEE_TYPE = "attendeeType";
+
+        public static final int TYPE_NONE = 0;
+        public static final int TYPE_REQUIRED = 1;
+        public static final int TYPE_OPTIONAL = 2;
+
+        /**
+         * The attendance status of the attendee. Column name.
+         * <P>Type: Integer (one of {@link #ATTENDEE_STATUS_ACCEPTED}, ...).</P>
+         */
+        public static final String ATTENDEE_STATUS = "attendeeStatus";
+
+        public static final int ATTENDEE_STATUS_NONE = 0;
+        public static final int ATTENDEE_STATUS_ACCEPTED = 1;
+        public static final int ATTENDEE_STATUS_DECLINED = 2;
+        public static final int ATTENDEE_STATUS_INVITED = 3;
+        public static final int ATTENDEE_STATUS_TENTATIVE = 4;
+    }
+
+    /**
+     * Fields and helpers for interacting with Attendees. Each row of this table
+     * represents a single attendee or guest of an event. Calling
+     * {@link #query(ContentResolver, long)} will return a list of attendees for
+     * the event with the given eventId. Both apps and sync adapters may write
+     * to this table. There are six writable fields and all of them except
+     * {@link #ATTENDEE_NAME} must be included when inserting a new attendee.
+     * They are:
+     * <ul>
+     * <li>{@link #EVENT_ID}</li>
+     * <li>{@link #ATTENDEE_NAME}</li>
+     * <li>{@link #ATTENDEE_EMAIL}</li>
+     * <li>{@link #ATTENDEE_RELATIONSHIP}</li>
+     * <li>{@link #ATTENDEE_TYPE}</li>
+     * <li>{@link #ATTENDEE_STATUS}</li>
+     * </ul>
+     */
+    public static final class Attendees implements BaseColumns, AttendeesColumns, EventsColumns {
+
+        /**
+         * The content:// style URL for accessing Attendees data
+         */
+        @SuppressWarnings("hiding")
+        public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/attendees");
+        /**
+         * the projection used by the attendees query
+         */
+        public static final String[] PROJECTION = new String[] {
+                _ID, ATTENDEE_NAME, ATTENDEE_EMAIL, ATTENDEE_RELATIONSHIP, ATTENDEE_STATUS,};
+        private static final String ATTENDEES_WHERE = Attendees.EVENT_ID + "=?";
+
+        /**
+         * Queries all attendees associated with the given event. This is a
+         * blocking call and should not be done on the UI thread.
+         *
+         * @param cr The content resolver to use for the query
+         * @param eventId The id of the event to retrieve attendees for
+         * @return A Cursor containing all attendees for the event
+         */
+        public static final Cursor query(ContentResolver cr, long eventId) {
+            String[] attArgs = {Long.toString(eventId)};
+            return cr.query(CONTENT_URI, PROJECTION, ATTENDEES_WHERE, attArgs /* selection args */,
+                    null /* sort order */);
+        }
+    }
+
+    /**
+     * Columns from the Events table that other tables join into themselves.
+     */
+    protected interface EventsColumns {
+
+        /**
+         * The {@link Calendars#_ID} of the calendar the event belongs to.
+         * Column name.
+         * <P>Type: INTEGER</P>
+         */
+        public static final String CALENDAR_ID = "calendar_id";
+
+        /**
+         * The title of the event. Column name.
+         * <P>Type: TEXT</P>
+         */
+        public static final String TITLE = "title";
+
+        /**
+         * The description of the event. Column name.
+         * <P>Type: TEXT</P>
+         */
+        public static final String DESCRIPTION = "description";
+
+        /**
+         * Where the event takes place. Column name.
+         * <P>Type: TEXT</P>
+         */
+        public static final String EVENT_LOCATION = "eventLocation";
+
+        /**
+         * A secondary color for the individual event. Column name.
+         * <P>Type: INTEGER</P>
+         */
+        public static final String EVENT_COLOR = "eventColor";
+
+        /**
+         * The event status. Column name.
+         * <P>Type: INTEGER (one of {@link #STATUS_TENTATIVE}...)</P>
+         */
+        public static final String STATUS = "eventStatus";
+
+        public static final int STATUS_TENTATIVE = 0;
+        public static final int STATUS_CONFIRMED = 1;
+        public static final int STATUS_CANCELED = 2;
+
+        /**
+         * This is a copy of the attendee status for the owner of this event.
+         * This field is copied here so that we can efficiently filter out
+         * events that are declined without having to look in the Attendees
+         * table. Column name.
+         *
+         * <P>Type: INTEGER (int)</P>
+         */
+        public static final String SELF_ATTENDEE_STATUS = "selfAttendeeStatus";
+
+        /**
+         * This column is available for use by sync adapters. Column name.
+         * <P>Type: TEXT</P>
+         */
+        public static final String SYNC_DATA1 = "sync_data1";
+
+        /**
+         * This column is available for use by sync adapters. Column name.
+         * <P>Type: TEXT</P>
+         */
+        public static final String SYNC_DATA2 = "sync_data2";
+
+        /**
+         * This column is available for use by sync adapters. Column name.
+         * <P>Type: TEXT</P>
+         */
+        public static final String SYNC_DATA3 = "sync_data3";
+
+        /**
+         * This column is available for use by sync adapters. Column name.
+         * <P>Type: TEXT</P>
+         */
+        public static final String SYNC_DATA4 = "sync_data4";
+
+        /**
+         * This column is available for use by sync adapters. Column name.
+         * <P>Type: TEXT</P>
+         */
+        public static final String SYNC_DATA5 = "sync_data5";
+
+        /**
+         * This column is available for use by sync adapters. Column name.
+         * <P>Type: TEXT</P>
+         */
+        public static final String SYNC_DATA6 = "sync_data6";
+
+        /**
+         * This column is available for use by sync adapters. Column name.
+         * <P>Type: TEXT</P>
+         */
+        public static final String SYNC_DATA7 = "sync_data7";
+
+        /**
+         * This column is available for use by sync adapters. Column name.
+         * <P>Type: TEXT</P>
+         */
+        public static final String SYNC_DATA8 = "sync_data8";
+
+        /**
+         * This column is available for use by sync adapters. Column name.
+         * <P>Type: TEXT</P>
+         */
+        public static final String SYNC_DATA9 = "sync_data9";
+
+        /**
+         * This column is available for use by sync adapters. Column name.
+         * <P>Type: TEXT</P>
+         */
+        public static final String SYNC_DATA10 = "sync_data10";
+
+        /**
+         * Used to indicate that a row is not a real event but an original copy of a locally
+         * modified event. A copy is made when an event changes from non-dirty to dirty and the
+         * event is on a calendar with {@link Calendars#CAN_PARTIALLY_UPDATE} set to 1. This copy
+         * does not get expanded in the instances table and is only visible in queries made by a
+         * sync adapter. The copy gets removed when the event is changed back to non-dirty by a
+         * sync adapter.
+         * <P>Type: INTEGER (boolean)</P>
+         */
+        public static final String LAST_SYNCED = "lastSynced";
+
+        /**
+         * The time the event starts in UTC millis since epoch. Column name.
+         * <P>Type: INTEGER (long; millis since epoch)</P>
+         */
+        public static final String DTSTART = "dtstart";
+
+        /**
+         * The time the event ends in UTC millis since epoch. Column name.
+         * <P>Type: INTEGER (long; millis since epoch)</P>
+         */
+        public static final String DTEND = "dtend";
+
+        /**
+         * The duration of the event in RFC2445 format. Column name.
+         * <P>Type: TEXT (duration in RFC2445 format)</P>
+         */
+        public static final String DURATION = "duration";
+
+        /**
+         * The timezone for the event. Column name.
+         * <P>Type: TEXT</P>
+         */
+        public static final String EVENT_TIMEZONE = "eventTimezone";
+
+        /**
+         * The timezone for the end time of the event. Column name.
+         * <P>Type: TEXT</P>
+         */
+        public static final String EVENT_END_TIMEZONE = "eventEndTimezone";
+
+        /**
+         * Is the event all day (time zone independent). Column name.
+         * <P>Type: INTEGER (boolean)</P>
+         */
+        public static final String ALL_DAY = "allDay";
+
+        /**
+         * Defines how the event shows up for others when the calendar is
+         * shared. Column name.
+         * <P>Type: INTEGER (One of {@link #ACCESS_DEFAULT}, ...)</P>
+         */
+        public static final String ACCESS_LEVEL = "accessLevel";
+
+        /**
+         * Default access is controlled by the server and will be treated as
+         * public on the device.
+         */
+        public static final int ACCESS_DEFAULT = 0;
+        /**
+         * Confidential is not used by the app.
+         */
+        public static final int ACCESS_CONFIDENTIAL = 1;
+        /**
+         * Private shares the event as a free/busy slot with no details.
+         */
+        public static final int ACCESS_PRIVATE = 2;
+        /**
+         * Public makes the contents visible to anyone with access to the
+         * calendar.
+         */
+        public static final int ACCESS_PUBLIC = 3;
+
+        /**
+         * If this event counts as busy time or is still free time that can be
+         * scheduled over. Column name.
+         * <P>Type: INTEGER (One of {@link #AVAILABILITY_BUSY},
+         * {@link #AVAILABILITY_FREE})</P>
+         */
+        public static final String AVAILABILITY = "availability";
+
+        /**
+         * Indicates that this event takes up time and will conflict with other
+         * events.
+         */
+        public static final int AVAILABILITY_BUSY = 0;
+        /**
+         * Indicates that this event is free time and will not conflict with
+         * other events.
+         */
+        public static final int AVAILABILITY_FREE = 1;
+
+        /**
+         * Whether the event has an alarm or not. Column name.
+         * <P>Type: INTEGER (boolean)</P>
+         */
+        public static final String HAS_ALARM = "hasAlarm";
+
+        /**
+         * Whether the event has extended properties or not. Column name.
+         * <P>Type: INTEGER (boolean)</P>
+         */
+        public static final String HAS_EXTENDED_PROPERTIES = "hasExtendedProperties";
+
+        /**
+         * The recurrence rule for the event. Column name.
+         * <P>Type: TEXT</P>
+         */
+        public static final String RRULE = "rrule";
+
+        /**
+         * The recurrence dates for the event. Column name.
+         * <P>Type: TEXT</P>
+         */
+        public static final String RDATE = "rdate";
+
+        /**
+         * The recurrence exception rule for the event. Column name.
+         * <P>Type: TEXT</P>
+         */
+        public static final String EXRULE = "exrule";
+
+        /**
+         * The recurrence exception dates for the event. Column name.
+         * <P>Type: TEXT</P>
+         */
+        public static final String EXDATE = "exdate";
+
+        /**
+         * The {@link Events#_ID} of the original recurring event for which this
+         * event is an exception. Column name.
+         * <P>Type: TEXT</P>
+         */
+        public static final String ORIGINAL_ID = "original_id";
+
+        /**
+         * The _sync_id of the original recurring event for which this event is
+         * an exception. The provider should keep the original_id in sync when
+         * this is updated. Column name.
+         * <P>Type: TEXT</P>
+         */
+        public static final String ORIGINAL_SYNC_ID = "original_sync_id";
+
+        /**
+         * The original instance time of the recurring event for which this
+         * event is an exception. Column name.
+         * <P>Type: INTEGER (long; millis since epoch)</P>
+         */
+        public static final String ORIGINAL_INSTANCE_TIME = "originalInstanceTime";
+
+        /**
+         * The allDay status (true or false) of the original recurring event
+         * for which this event is an exception. Column name.
+         * <P>Type: INTEGER (boolean)</P>
+         */
+        public static final String ORIGINAL_ALL_DAY = "originalAllDay";
+
+        /**
+         * The last date this event repeats on, or NULL if it never ends. Column
+         * name.
+         * <P>Type: INTEGER (long; millis since epoch)</P>
+         */
+        public static final String LAST_DATE = "lastDate";
+
+        /**
+         * Whether the event has attendee information.  True if the event
+         * has full attendee data, false if the event has information about
+         * self only. Column name.
+         * <P>Type: INTEGER (boolean)</P>
+         */
+        public static final String HAS_ATTENDEE_DATA = "hasAttendeeData";
+
+        /**
+         * Whether guests can modify the event. Column name.
+         * <P>Type: INTEGER (boolean)</P>
+         */
+        public static final String GUESTS_CAN_MODIFY = "guestsCanModify";
+
+        /**
+         * Whether guests can invite other guests. Column name.
+         * <P>Type: INTEGER (boolean)</P>
+         */
+        public static final String GUESTS_CAN_INVITE_OTHERS = "guestsCanInviteOthers";
+
+        /**
+         * Whether guests can see the list of attendees. Column name.
+         * <P>Type: INTEGER (boolean)</P>
+         */
+        public static final String GUESTS_CAN_SEE_GUESTS = "guestsCanSeeGuests";
+
+        /**
+         * Email of the organizer (owner) of the event. Column name.
+         * <P>Type: STRING</P>
+         */
+        public static final String ORGANIZER = "organizer";
+
+        /**
+         * Whether the user can invite others to the event. The
+         * GUESTS_CAN_INVITE_OTHERS is a setting that applies to an arbitrary
+         * guest, while CAN_INVITE_OTHERS indicates if the user can invite
+         * others (either through GUESTS_CAN_INVITE_OTHERS or because the user
+         * has modify access to the event). Column name.
+         * <P>Type: INTEGER (boolean, readonly)</P>
+         */
+        public static final String CAN_INVITE_OTHERS = "canInviteOthers";
+    }
+
+    /**
+     * Class that represents an Event Entity. There is one entry per event.
+     * Recurring events show up as a single entry. This is a helper class to
+     * make batch operations easier. A {@link ContentResolver} or
+     * {@link ContentProviderClient} is required as the helper does additional
+     * queries to add reminders and attendees to each entry.
+     */
+    public static final class EventsEntity implements BaseColumns, SyncColumns, EventsColumns {
+        /**
+         * The content:// style URL for this table
+         */
+        public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY +
+                "/event_entities");
+
+        /**
+         * Creates a new iterator for events
+         *
+         * @param cursor An event query
+         * @param resolver For performing additional queries
+         * @return an EntityIterator containing one entity per event in the
+         *         cursor
+         */
+        public static EntityIterator newEntityIterator(Cursor cursor, ContentResolver resolver) {
+            return new EntityIteratorImpl(cursor, resolver);
+        }
+
+        /**
+         * Creates a new iterator for events
+         *
+         * @param cursor An event query
+         * @param provider For performing additional queries
+         * @return an EntityIterator containing one entity per event in the
+         *         cursor
+         */
+        public static EntityIterator newEntityIterator(Cursor cursor,
+                ContentProviderClient provider) {
+            return new EntityIteratorImpl(cursor, provider);
+        }
+
+        private static class EntityIteratorImpl extends CursorEntityIterator {
+            private final ContentResolver mResolver;
+            private final ContentProviderClient mProvider;
+
+            private static final String[] REMINDERS_PROJECTION = new String[] {
+                    Reminders.MINUTES,
+                    Reminders.METHOD,
+            };
+            private static final int COLUMN_MINUTES = 0;
+            private static final int COLUMN_METHOD = 1;
+
+            private static final String[] ATTENDEES_PROJECTION = new String[] {
+                    Attendees.ATTENDEE_NAME,
+                    Attendees.ATTENDEE_EMAIL,
+                    Attendees.ATTENDEE_RELATIONSHIP,
+                    Attendees.ATTENDEE_TYPE,
+                    Attendees.ATTENDEE_STATUS,
+            };
+            private static final int COLUMN_ATTENDEE_NAME = 0;
+            private static final int COLUMN_ATTENDEE_EMAIL = 1;
+            private static final int COLUMN_ATTENDEE_RELATIONSHIP = 2;
+            private static final int COLUMN_ATTENDEE_TYPE = 3;
+            private static final int COLUMN_ATTENDEE_STATUS = 4;
+            private static final String[] EXTENDED_PROJECTION = new String[] {
+                    ExtendedProperties._ID,
+                    ExtendedProperties.NAME,
+                    ExtendedProperties.VALUE
+            };
+            private static final int COLUMN_ID = 0;
+            private static final int COLUMN_NAME = 1;
+            private static final int COLUMN_VALUE = 2;
+
+            private static final String WHERE_EVENT_ID = "event_id=?";
+
+            public EntityIteratorImpl(Cursor cursor, ContentResolver resolver) {
+                super(cursor);
+                mResolver = resolver;
+                mProvider = null;
+            }
+
+            public EntityIteratorImpl(Cursor cursor, ContentProviderClient provider) {
+                super(cursor);
+                mResolver = null;
+                mProvider = provider;
+            }
+
+            @Override
+            public Entity getEntityAndIncrementCursor(Cursor cursor) throws RemoteException {
+                // we expect the cursor is already at the row we need to read from
+                final long eventId = cursor.getLong(cursor.getColumnIndexOrThrow(Events._ID));
+                ContentValues cv = new ContentValues();
+                cv.put(Events._ID, eventId);
+                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, CALENDAR_ID);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, TITLE);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, DESCRIPTION);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, EVENT_LOCATION);
+                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, STATUS);
+                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, SELF_ATTENDEE_STATUS);
+                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, DTSTART);
+                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, DTEND);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, DURATION);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, EVENT_TIMEZONE);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, EVENT_END_TIMEZONE);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, ALL_DAY);
+                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, ACCESS_LEVEL);
+                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, AVAILABILITY);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, HAS_ALARM);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv,
+                        HAS_EXTENDED_PROPERTIES);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, RRULE);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, RDATE);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, EXRULE);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, EXDATE);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, ORIGINAL_SYNC_ID);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, ORIGINAL_ID);
+                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv,
+                        ORIGINAL_INSTANCE_TIME);
+                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, ORIGINAL_ALL_DAY);
+                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, LAST_DATE);
+                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, HAS_ATTENDEE_DATA);
+                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv,
+                        GUESTS_CAN_INVITE_OTHERS);
+                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, GUESTS_CAN_MODIFY);
+                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, GUESTS_CAN_SEE_GUESTS);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, ORGANIZER);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, _SYNC_ID);
+                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, DIRTY);
+                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, LAST_SYNCED);
+                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, DELETED);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC_DATA1);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC_DATA2);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC_DATA3);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC_DATA4);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC_DATA5);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC_DATA6);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC_DATA7);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC_DATA8);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC_DATA9);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC_DATA10);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC1);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC2);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC3);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC4);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC5);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC6);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC7);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC8);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC9);
+                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC10);
+
+                Entity entity = new Entity(cv);
+                Cursor subCursor;
+                if (mResolver != null) {
+                    subCursor = mResolver.query(Reminders.CONTENT_URI, REMINDERS_PROJECTION,
+                            WHERE_EVENT_ID,
+                            new String[] { Long.toString(eventId) }  /* selectionArgs */,
+                            null /* sortOrder */);
+                } else {
+                    subCursor = mProvider.query(Reminders.CONTENT_URI, REMINDERS_PROJECTION,
+                            WHERE_EVENT_ID,
+                            new String[] { Long.toString(eventId) }  /* selectionArgs */,
+                            null /* sortOrder */);
+                }
+                try {
+                    while (subCursor.moveToNext()) {
+                        ContentValues reminderValues = new ContentValues();
+                        reminderValues.put(Reminders.MINUTES, subCursor.getInt(COLUMN_MINUTES));
+                        reminderValues.put(Reminders.METHOD, subCursor.getInt(COLUMN_METHOD));
+                        entity.addSubValue(Reminders.CONTENT_URI, reminderValues);
+                    }
+                } finally {
+                    subCursor.close();
+                }
+
+                if (mResolver != null) {
+                    subCursor = mResolver.query(Attendees.CONTENT_URI, ATTENDEES_PROJECTION,
+                            WHERE_EVENT_ID,
+                            new String[] { Long.toString(eventId) } /* selectionArgs */,
+                            null /* sortOrder */);
+                } else {
+                    subCursor = mProvider.query(Attendees.CONTENT_URI, ATTENDEES_PROJECTION,
+                            WHERE_EVENT_ID,
+                            new String[] { Long.toString(eventId) } /* selectionArgs */,
+                            null /* sortOrder */);
+                }
+                try {
+                    while (subCursor.moveToNext()) {
+                        ContentValues attendeeValues = new ContentValues();
+                        attendeeValues.put(Attendees.ATTENDEE_NAME,
+                                subCursor.getString(COLUMN_ATTENDEE_NAME));
+                        attendeeValues.put(Attendees.ATTENDEE_EMAIL,
+                                subCursor.getString(COLUMN_ATTENDEE_EMAIL));
+                        attendeeValues.put(Attendees.ATTENDEE_RELATIONSHIP,
+                                subCursor.getInt(COLUMN_ATTENDEE_RELATIONSHIP));
+                        attendeeValues.put(Attendees.ATTENDEE_TYPE,
+                                subCursor.getInt(COLUMN_ATTENDEE_TYPE));
+                        attendeeValues.put(Attendees.ATTENDEE_STATUS,
+                                subCursor.getInt(COLUMN_ATTENDEE_STATUS));
+                        entity.addSubValue(Attendees.CONTENT_URI, attendeeValues);
+                    }
+                } finally {
+                    subCursor.close();
+                }
+
+                if (mResolver != null) {
+                    subCursor = mResolver.query(ExtendedProperties.CONTENT_URI, EXTENDED_PROJECTION,
+                            WHERE_EVENT_ID,
+                            new String[] { Long.toString(eventId) } /* selectionArgs */,
+                            null /* sortOrder */);
+                } else {
+                    subCursor = mProvider.query(ExtendedProperties.CONTENT_URI, EXTENDED_PROJECTION,
+                            WHERE_EVENT_ID,
+                            new String[] { Long.toString(eventId) } /* selectionArgs */,
+                            null /* sortOrder */);
+                }
+                try {
+                    while (subCursor.moveToNext()) {
+                        ContentValues extendedValues = new ContentValues();
+                        extendedValues.put(ExtendedProperties._ID,
+                                subCursor.getString(COLUMN_ID));
+                        extendedValues.put(ExtendedProperties.NAME,
+                                subCursor.getString(COLUMN_NAME));
+                        extendedValues.put(ExtendedProperties.VALUE,
+                                subCursor.getString(COLUMN_VALUE));
+                        entity.addSubValue(ExtendedProperties.CONTENT_URI, extendedValues);
+                    }
+                } finally {
+                    subCursor.close();
+                }
+
+                cursor.moveToNext();
+                return entity;
+            }
+        }
+    }
+
+    /**
+     * Constants and helpers for the Events table, which contains details for
+     * individual events. <h3>Operations</h3> All operations can be done either
+     * as an app or as a sync adapter. To perform an operation as a sync adapter
+     * {@link #CALLER_IS_SYNCADAPTER} should be set to true and
+     * {@link #ACCOUNT_NAME} and {@link #ACCOUNT_TYPE} must be set in the Uri
+     * parameters. See
+     * {@link Uri.Builder#appendQueryParameter(java.lang.String, java.lang.String)}
+     * for details on adding parameters. Sync adapters have write access to more
+     * columns but are restricted to a single account at a time.
+     * <dl>
+     * <dt><b>Insert</b></dt>
+     * <dd>When inserting a new event the following fields must be included:
+     * <ul>
+     * <li>dtstart</li>
+     * <li>dtend -or- a (rrule or rdate) and a duration</li>
+     * <li>a calendar_id</li>
+     * </ul>
+     * There are also further requirements when inserting or updating an event.
+     * See the section on Writing to Events.</dd>
+     * <dt><b>Update</b></dt>
+     * <dd>To perform an update of an Event the {@link Events#_ID} of the event
+     * should be provided either as an appended id to the Uri (
+     * {@link ContentUris#withAppendedId}) or as the first selection item--the
+     * selection should start with "_id=?" and the first selectionArg should be
+     * the _id of the event. Updates may also be done using a selection and no
+     * id. Updating an event must respect the same rules as inserting and is
+     * further restricted in the fields that can be written. See the section on
+     * Writing to Events.</dd>
+     * <dt><b>Delete</b></dt>
+     * <dd>Events can be deleted either by the {@link Events#_ID} as an appended
+     * id on the Uri or using any standard selection. If an appended id is used
+     * a selection is not allowed. There are two versions of delete: as an app
+     * and as a sync adapter. An app delete will set the deleted column on an
+     * event and remove all instances of that event. A sync adapter delete will
+     * remove the event from the database and all associated data.</dd>
+     * <dt><b>Query</b></dt>
+     * <dd>Querying the Events table will get you all information about a set of
+     * events except their reminders, attendees, and extended properties. There
+     * will be one row returned for each event that matches the query selection,
+     * or at most a single row if the {@link Events#_ID} is appended to the Uri.
+     * Recurring events will only return a single row regardless of the number
+     * of times that event repeats.</dd>
+     * </dl>
+     * <h3>Writing to Events</h3> There are further restrictions on all Updates
+     * and Inserts in the Events table:
+     * <ul>
+     * <li>If allDay is set to 1 eventTimezone must be {@link Time#TIMEZONE_UTC}
+     * and the time must correspond to a midnight boundary.</li>
+     * <li>Exceptions are not allowed to recur. If rrule or rdate is not empty,
+     * original_id and original_sync_id must be empty.</li>
+     * <li>In general a calendar_id should not be modified after insertion. This
+     * is not explicitly forbidden but many sync adapters will not behave in an
+     * expected way if the calendar_id is modified.</li>
+     * </ul>
+     * The following Events columns are writable by both an app and a sync
+     * adapter.
+     * <ul>
+     * <li>{@link #CALENDAR_ID}</li>
+     * <li>{@link #ORGANIZER}</li>
+     * <li>{@link #TITLE}</li>
+     * <li>{@link #EVENT_LOCATION}</li>
+     * <li>{@link #DESCRIPTION}</li>
+     * <li>{@link #EVENT_COLOR}</li>
+     * <li>{@link #DTSTART}</li>
+     * <li>{@link #DTEND}</li>
+     * <li>{@link #EVENT_TIMEZONE}</li>
+     * <li>{@link #EVENT_END_TIMEZONE}</li>
+     * <li>{@link #DURATION}</li>
+     * <li>{@link #ALL_DAY}</li>
+     * <li>{@link #RRULE}</li>
+     * <li>{@link #RDATE}</li>
+     * <li>{@link #EXRULE}</li>
+     * <li>{@link #EXDATE}</li>
+     * <li>{@link #ORIGINAL_ID}</li>
+     * <li>{@link #ORIGINAL_SYNC_ID}</li>
+     * <li>{@link #ORIGINAL_INSTANCE_TIME}</li>
+     * <li>{@link #ORIGINAL_ALL_DAY}</li>
+     * <li>{@link #ACCESS_LEVEL}</li>
+     * <li>{@link #AVAILABILITY}</li>
+     * <li>{@link #GUESTS_CAN_MODIFY}</li>
+     * <li>{@link #GUESTS_CAN_INVITE_OTHERS}</li>
+     * <li>{@link #GUESTS_CAN_SEE_GUESTS}</li>
+     * </ul>
+     * The following Events columns are writable only by a sync adapter
+     * <ul>
+     * <li>{@link #DIRTY}</li>
+     * <li>{@link #_SYNC_ID}</li>
+     * <li>{@link #SYNC_DATA1}</li>
+     * <li>{@link #SYNC_DATA2}</li>
+     * <li>{@link #SYNC_DATA3}</li>
+     * <li>{@link #SYNC_DATA4}</li>
+     * <li>{@link #SYNC_DATA5}</li>
+     * <li>{@link #SYNC_DATA6}</li>
+     * <li>{@link #SYNC_DATA7}</li>
+     * <li>{@link #SYNC_DATA8}</li>
+     * <li>{@link #SYNC_DATA9}</li>
+     * <li>{@link #SYNC_DATA10}</li>
+     * </ul>
+     * The remaining columns are either updated by the provider only or are
+     * views into other tables and cannot be changed through the Events table.
+     */
+    public static final class Events implements BaseColumns, SyncColumns, EventsColumns,
+            CalendarsColumns {
+
+        /**
+         * Queries all events with the given projection. This is a blocking call
+         * and should not be done on the UI thread.
+         *
+         * @param cr The content resolver to use for the query
+         * @param projection The columns to return
+         * @return A Cursor containing all events in the db
+         */
+        public static final Cursor query(ContentResolver cr, String[] projection) {
+            return cr.query(CONTENT_URI, projection, null, null, DEFAULT_SORT_ORDER);
+        }
+
+        /**
+         * Queries events using the given projection, selection filter, and
+         * ordering. This is a blocking call and should not be done on the UI
+         * thread. For selection and selectionArgs usage see
+         * {@link ContentResolver#query(Uri, String[], String, String[], String)}
+         *
+         * @param cr The content resolver to use for the query
+         * @param projection The columns to return
+         * @param selection Filter on the query as an SQL WHERE statement
+         * @param selectionArgs Args to replace any '?'s in the selection
+         * @param orderBy How to order the rows as an SQL ORDER BY statement
+         * @return A Cursor containing the matching events
+         */
+        public static final Cursor query(ContentResolver cr, String[] projection, String selection,
+                String[] selectionArgs, String orderBy) {
+            return cr.query(CONTENT_URI, projection, selection, null,
+                    orderBy == null ? DEFAULT_SORT_ORDER : orderBy);
+        }
+
+        /**
+         * The content:// style URL for interacting with events. Appending an
+         * event id using {@link ContentUris#withAppendedId(Uri, long)} will
+         * specify a single event.
+         */
+        @SuppressWarnings("hiding")
+        public static final Uri CONTENT_URI =
+                Uri.parse("content://" + AUTHORITY + "/events");
+
+        /**
+         * The content:// style URI for recurring event exceptions.  Insertions require an
+         * appended event ID.  Deletion of exceptions requires both the original event ID and
+         * the exception event ID (see {@link Uri.Builder#appendPath}).
+         */
+        public static final Uri EXCEPTION_CONTENT_URI =
+                Uri.parse("content://" + AUTHORITY + "/exception");
+
+        /**
+         * The default sort order for this table
+         */
+        private static final String DEFAULT_SORT_ORDER = "";
+
+        /**
+         * These are columns that should only ever be updated by the provider,
+         * either because they are views mapped to another table or because they
+         * are used for provider only functionality.
+         */
+        public static String[] PROVIDER_WRITABLE_COLUMNS = new String[] {
+                ACCOUNT_NAME,
+                ACCOUNT_TYPE,
+                CAL_SYNC1,
+                CAL_SYNC2,
+                CAL_SYNC3,
+                CAL_SYNC4,
+                CAL_SYNC5,
+                CAL_SYNC6,
+                CAL_SYNC7,
+                CAL_SYNC8,
+                CAL_SYNC9,
+                CAL_SYNC10,
+                ALLOWED_REMINDERS,
+                CALENDAR_ACCESS_LEVEL,
+                CALENDAR_COLOR,
+                CALENDAR_TIME_ZONE,
+                CAN_MODIFY_TIME_ZONE,
+                CAN_ORGANIZER_RESPOND,
+                CALENDAR_DISPLAY_NAME,
+                CAN_PARTIALLY_UPDATE,
+                SYNC_EVENTS,
+                VISIBLE,
+        };
+
+        /**
+         * These fields are only writable by a sync adapter. To modify them the
+         * caller must include CALLER_IS_SYNCADAPTER, _SYNC_ACCOUNT, and
+         * _SYNC_ACCOUNT_TYPE in the query parameters.
+         */
+        public static final String[] SYNC_WRITABLE_COLUMNS = new String[] {
+            _SYNC_ID,
+            DIRTY,
+            SYNC_DATA1,
+            SYNC_DATA2,
+            SYNC_DATA3,
+            SYNC_DATA4,
+            SYNC_DATA5,
+            SYNC_DATA6,
+            SYNC_DATA7,
+            SYNC_DATA8,
+            SYNC_DATA9,
+            SYNC_DATA10,
+        };
+    }
+
+    /**
+     * Fields and helpers for interacting with Instances. An instance is a
+     * single occurrence of an event including time zone specific start and end
+     * days and minutes. The instances table is not writable and only provides a
+     * way to query event occurrences.
+     */
+    public static final class Instances implements BaseColumns, EventsColumns, CalendarsColumns {
+
+        private static final String WHERE_CALENDARS_SELECTED = Calendars.VISIBLE + "=1";
+
+        /**
+         * Performs a query to return all visible instances in the given range.
+         * This is a blocking function and should not be done on the UI thread.
+         * This will cause an expansion of recurring events to fill this time
+         * range if they are not already expanded and will slow down for larger
+         * time ranges with many recurring events.
+         *
+         * @param cr The ContentResolver to use for the query
+         * @param projection The columns to return
+         * @param begin The start of the time range to query in UTC millis since
+         *            epoch
+         * @param end The end of the time range to query in UTC millis since
+         *            epoch
+         * @return A Cursor containing all instances in the given range
+         */
+        public static final Cursor query(ContentResolver cr, String[] projection,
+                                         long begin, long end) {
+            Uri.Builder builder = CONTENT_URI.buildUpon();
+            ContentUris.appendId(builder, begin);
+            ContentUris.appendId(builder, end);
+            return cr.query(builder.build(), projection, WHERE_CALENDARS_SELECTED,
+                         null, DEFAULT_SORT_ORDER);
+        }
+
+        /**
+         * Performs a query to return all visible instances in the given range
+         * that match the given query. This is a blocking function and should
+         * not be done on the UI thread. This will cause an expansion of
+         * recurring events to fill this time range if they are not already
+         * expanded and will slow down for larger time ranges with many
+         * recurring events.
+         *
+         * @param cr The ContentResolver to use for the query
+         * @param projection The columns to return
+         * @param begin The start of the time range to query in UTC millis since
+         *            epoch
+         * @param end The end of the time range to query in UTC millis since
+         *            epoch
+         * @param searchQuery A string of space separated search terms. Segments
+         *            enclosed by double quotes will be treated as a single
+         *            term.
+         * @return A Cursor of instances matching the search terms in the given
+         *         time range
+         */
+        public static final Cursor query(ContentResolver cr, String[] projection,
+                                         long begin, long end, String searchQuery) {
+            Uri.Builder builder = CONTENT_SEARCH_URI.buildUpon();
+            ContentUris.appendId(builder, begin);
+            ContentUris.appendId(builder, end);
+            builder = builder.appendPath(searchQuery);
+            return cr.query(builder.build(), projection, WHERE_CALENDARS_SELECTED, null,
+                    DEFAULT_SORT_ORDER);
+        }
+
+        /**
+         * Performs a query to return all visible instances in the given range
+         * that match the given selection. This is a blocking function and
+         * should not be done on the UI thread. This will cause an expansion of
+         * recurring events to fill this time range if they are not already
+         * expanded and will slow down for larger time ranges with many
+         * recurring events.
+         *
+         * @param cr The ContentResolver to use for the query
+         * @param projection The columns to return
+         * @param begin The start of the time range to query in UTC millis since
+         *            epoch
+         * @param end The end of the time range to query in UTC millis since
+         *            epoch
+         * @param selection Filter on the query as an SQL WHERE statement
+         * @param selectionArgs Args to replace any '?'s in the selection
+         * @param orderBy How to order the rows as an SQL ORDER BY statement
+         * @return A Cursor of instances matching the selection
+         */
+        public static final Cursor query(ContentResolver cr, String[] projection, long begin,
+                long end, String selection, String[] selectionArgs, String orderBy) {
+            Uri.Builder builder = CONTENT_URI.buildUpon();
+            ContentUris.appendId(builder, begin);
+            ContentUris.appendId(builder, end);
+            if (TextUtils.isEmpty(selection)) {
+                selection = WHERE_CALENDARS_SELECTED;
+            } else {
+                selection = "(" + selection + ") AND " + WHERE_CALENDARS_SELECTED;
+            }
+            return cr.query(builder.build(), projection, selection, selectionArgs,
+                    orderBy == null ? DEFAULT_SORT_ORDER : orderBy);
+        }
+
+        /**
+         * Performs a query to return all visible instances in the given range
+         * that match the given selection. This is a blocking function and
+         * should not be done on the UI thread. This will cause an expansion of
+         * recurring events to fill this time range if they are not already
+         * expanded and will slow down for larger time ranges with many
+         * recurring events.
+         *
+         * @param cr The ContentResolver to use for the query
+         * @param projection The columns to return
+         * @param begin The start of the time range to query in UTC millis since
+         *            epoch
+         * @param end The end of the time range to query in UTC millis since
+         *            epoch
+         * @param searchQuery A string of space separated search terms. Segments
+         *            enclosed by double quotes will be treated as a single
+         *            term.
+         * @param selection Filter on the query as an SQL WHERE statement
+         * @param selectionArgs Args to replace any '?'s in the selection
+         * @param orderBy How to order the rows as an SQL ORDER BY statement
+         * @return A Cursor of instances matching the selection
+         */
+        public static final Cursor query(ContentResolver cr, String[] projection, long begin,
+                long end, String searchQuery, String selection, String[] selectionArgs,
+                String orderBy) {
+            Uri.Builder builder = CONTENT_SEARCH_URI.buildUpon();
+            ContentUris.appendId(builder, begin);
+            ContentUris.appendId(builder, end);
+            builder = builder.appendPath(searchQuery);
+            if (TextUtils.isEmpty(selection)) {
+                selection = WHERE_CALENDARS_SELECTED;
+            } else {
+                selection = "(" + selection + ") AND " + WHERE_CALENDARS_SELECTED;
+            }
+            return cr.query(builder.build(), projection, selection, selectionArgs,
+                    orderBy == null ? DEFAULT_SORT_ORDER : orderBy);
+        }
+
+        /**
+         * The content:// style URL for querying an instance range. The begin
+         * and end of the range to query should be added as path segments if
+         * this is used directly.
+         */
+        @SuppressWarnings("hiding")
+        public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY +
+                "/instances/when");
+        /**
+         * The content:// style URL for querying an instance range by Julian
+         * Day. The start and end day should be added as path segments if this
+         * is used directly.
+         */
+        public static final Uri CONTENT_BY_DAY_URI =
+            Uri.parse("content://" + AUTHORITY + "/instances/whenbyday");
+        /**
+         * The content:// style URL for querying an instance range with a search
+         * term. The begin, end, and search string should be appended as path
+         * segments if this is used directly.
+         */
+        public static final Uri CONTENT_SEARCH_URI = Uri.parse("content://" + AUTHORITY +
+                "/instances/search");
+        /**
+         * The content:// style URL for querying an instance range with a search
+         * term. The start day, end day, and search string should be appended as
+         * path segments if this is used directly.
+         */
+        public static final Uri CONTENT_SEARCH_BY_DAY_URI =
+            Uri.parse("content://" + AUTHORITY + "/instances/searchbyday");
+
+        /**
+         * The default sort order for this table.
+         */
+        private static final String DEFAULT_SORT_ORDER = "begin ASC";
+
+        /**
+         * The beginning time of the instance, in UTC milliseconds. Column name.
+         * <P>Type: INTEGER (long; millis since epoch)</P>
+         */
+        public static final String BEGIN = "begin";
+
+        /**
+         * The ending time of the instance, in UTC milliseconds. Column name.
+         * <P>Type: INTEGER (long; millis since epoch)</P>
+         */
+        public static final String END = "end";
+
+        /**
+         * The _id of the event for this instance. Column name.
+         * <P>Type: INTEGER (long, foreign key to the Events table)</P>
+         */
+        public static final String EVENT_ID = "event_id";
+
+        /**
+         * The Julian start day of the instance, relative to the local time
+         * zone. Column name.
+         * <P>Type: INTEGER (int)</P>
+         */
+        public static final String START_DAY = "startDay";
+
+        /**
+         * The Julian end day of the instance, relative to the local time
+         * zone. Column name.
+         * <P>Type: INTEGER (int)</P>
+         */
+        public static final String END_DAY = "endDay";
+
+        /**
+         * The start minute of the instance measured from midnight in the
+         * local time zone. Column name.
+         * <P>Type: INTEGER (int)</P>
+         */
+        public static final String START_MINUTE = "startMinute";
+
+        /**
+         * The end minute of the instance measured from midnight in the
+         * local time zone. Column name.
+         * <P>Type: INTEGER (int)</P>
+         */
+        public static final String END_MINUTE = "endMinute";
+    }
+
+    /**
+     * CalendarCache stores some settings for calendar including the current
+     * time zone for the instaces. These settings are stored using a key/value
+     * scheme.
+     */
+    protected interface CalendarCacheColumns {
+        /**
+         * The key for the setting. Keys are defined in {@link CalendarCache}.
+         */
+        public static final String KEY = "key";
+
+        /**
+         * The value of the given setting.
+         */
+        public static final String VALUE = "value";
+    }
+
+    public static class CalendarCache implements CalendarCacheColumns {
+        /**
+         * The URI to use for retrieving the properties from the Calendar db.
+         */
+        public static final Uri URI =
+                Uri.parse("content://" + AUTHORITY + "/properties");
+        public static final String[] POJECTION = { KEY, VALUE };
+
+        /**
+         * If updating a property, this must be provided as the selection. All
+         * other selections will fail. For queries this field can be omitted to
+         * retrieve all properties or used to query a single property. Valid
+         * keys include {@link #TIMEZONE_KEY_TYPE},
+         * {@link #TIMEZONE_KEY_INSTANCES}, and
+         * {@link #TIMEZONE_KEY_INSTANCES_PREVIOUS}, though the last one can
+         * only be read, not written.
+         */
+        public static final String WHERE = "key=?";
+
+        /**
+         * They key for updating the use of auto/home time zones in Calendar.
+         * Valid values are {@link #TIMEZONE_TYPE_AUTO} or
+         * {@link #TIMEZONE_TYPE_HOME}.
+         */
+        public static final String TIMEZONE_KEY_TYPE = "timezoneType";
+
+        /**
+         * The key for updating the time zone used by the provider when it
+         * generates the instances table. This should only be written if the
+         * type is set to {@link #TIMEZONE_TYPE_HOME}. A valid time zone id
+         * should be written to this field.
+         */
+        public static final String TIMEZONE_KEY_INSTANCES = "timezoneInstances";
+
+        /**
+         * The key for reading the last time zone set by the user. This should
+         * only be read by apps and it will be automatically updated whenever
+         * {@link #TIMEZONE_KEY_INSTANCES} is updated with
+         * {@link #TIMEZONE_TYPE_HOME} set.
+         */
+        public static final String TIMEZONE_KEY_INSTANCES_PREVIOUS = "timezoneInstancesPrevious";
+
+        /**
+         * The value to write to {@link #TIMEZONE_KEY_TYPE} if the provider
+         * should stay in sync with the device's time zone.
+         */
+        public static final String TIMEZONE_TYPE_AUTO = "auto";
+
+        /**
+         * The value to write to {@link #TIMEZONE_KEY_TYPE} if the provider
+         * should use a fixed time zone set by the user.
+         */
+        public static final String TIMEZONE_TYPE_HOME = "home";
+    }
+
+    /**
+     * A few Calendar globals are needed in the CalendarProvider for expanding
+     * the Instances table and these are all stored in the first (and only) row
+     * of the CalendarMetaData table.
+     *
+     * @hide
+     */
+    protected interface CalendarMetaDataColumns {
+        /**
+         * The local timezone that was used for precomputing the fields
+         * in the Instances table.
+         */
+        public static final String LOCAL_TIMEZONE = "localTimezone";
+
+        /**
+         * The minimum time used in expanding the Instances table,
+         * in UTC milliseconds.
+         * <P>Type: INTEGER</P>
+         */
+        public static final String MIN_INSTANCE = "minInstance";
+
+        /**
+         * The maximum time used in expanding the Instances table,
+         * in UTC milliseconds.
+         * <P>Type: INTEGER</P>
+         */
+        public static final String MAX_INSTANCE = "maxInstance";
+
+        /**
+         * The minimum Julian day in the EventDays table.
+         * <P>Type: INTEGER</P>
+         */
+        public static final String MIN_EVENTDAYS = "minEventDays";
+
+        /**
+         * The maximum Julian day in the EventDays table.
+         * <P>Type: INTEGER</P>
+         */
+        public static final String MAX_EVENTDAYS = "maxEventDays";
+    }
+
+    /**
+     * @hide
+     */
+    public static final class CalendarMetaData implements CalendarMetaDataColumns, BaseColumns {
+    }
+
+    protected interface EventDaysColumns {
+        /**
+         * The Julian starting day number. Column name.
+         * <P>Type: INTEGER (int)</P>
+         */
+        public static final String STARTDAY = "startDay";
+        /**
+         * The Julian ending day number. Column name.
+         * <P>Type: INTEGER (int)</P>
+         */
+        public static final String ENDDAY = "endDay";
+
+    }
+
+    /**
+     * Fields and helpers for querying for a list of days that contain events.
+     */
+    public static final class EventDays implements EventDaysColumns {
+        public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY
+                + "/instances/groupbyday");
+
+        /**
+         * The projection used by the EventDays query.
+         */
+        public static final String[] PROJECTION = { STARTDAY, ENDDAY };
+        private static final String SELECTION = "selected=1";
+
+        /**
+         * Retrieves the days with events for the Julian days starting at
+         * "startDay" for "numDays". It returns a cursor containing startday and
+         * endday representing the max range of days for all events beginning on
+         * each startday.This is a blocking function and should not be done on
+         * the UI thread.
+         *
+         * @param cr the ContentResolver
+         * @param startDay the first Julian day in the range
+         * @param numDays the number of days to load (must be at least 1)
+         * @return a database cursor containing a list of start and end days for
+         *         events
+         */
+        public static final Cursor query(ContentResolver cr, int startDay, int numDays) {
+            if (numDays < 1) {
+                return null;
+            }
+            int endDay = startDay + numDays - 1;
+            Uri.Builder builder = CONTENT_URI.buildUpon();
+            ContentUris.appendId(builder, startDay);
+            ContentUris.appendId(builder, endDay);
+            return cr.query(builder.build(), PROJECTION, SELECTION,
+                    null /* selection args */, STARTDAY);
+        }
+    }
+
+    protected interface RemindersColumns {
+        /**
+         * The event the reminder belongs to. Column name.
+         * <P>Type: INTEGER (foreign key to the Events table)</P>
+         */
+        public static final String EVENT_ID = "event_id";
+
+        /**
+         * The minutes prior to the event that the alarm should ring.  -1
+         * specifies that we should use the default value for the system.
+         * Column name.
+         * <P>Type: INTEGER</P>
+         */
+        public static final String MINUTES = "minutes";
+
+        /**
+         * Passing this as a minutes value will use the default reminder
+         * minutes.
+         */
+        public static final int MINUTES_DEFAULT = -1;
+
+        /**
+         * The alarm method, as set on the server. {@link #METHOD_DEFAULT},
+         * {@link #METHOD_ALERT}, {@link #METHOD_EMAIL}, and {@link #METHOD_SMS}
+         * are possible values; the device will only process
+         * {@link #METHOD_DEFAULT} and {@link #METHOD_ALERT} reminders (the
+         * other types are simply stored so we can send the same reminder info
+         * back to the server when we make changes).
+         */
+        public static final String METHOD = "method";
+
+        public static final int METHOD_DEFAULT = 0;
+        public static final int METHOD_ALERT = 1;
+        public static final int METHOD_EMAIL = 2;
+        public static final int METHOD_SMS = 3;
+    }
+
+    /**
+     * Fields and helpers for accessing reminders for an event. Each row of this
+     * table represents a single reminder for an event. Calling
+     * {@link #query(ContentResolver, long)} will return a list of reminders for
+     * the event with the given eventId. Both apps and sync adapters may write
+     * to this table. There are three writable fields and all of them must be
+     * included when inserting a new reminder. They are:
+     * <ul>
+     * <li>{@link #EVENT_ID}</li>
+     * <li>{@link #MINUTES}</li>
+     * <li>{@link #METHOD}</li>
+     * </ul>
+     */
+    public static final class Reminders implements BaseColumns, RemindersColumns, EventsColumns {
+        private static final String REMINDERS_WHERE = CalendarContract.Reminders.EVENT_ID + "=?";
+        /**
+         * The projection used by the reminders query.
+         */
+        public static final String[] PROJECTION = new String[] {
+                _ID, MINUTES, METHOD,};
+        @SuppressWarnings("hiding")
+        public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/reminders");
+
+        /**
+         * Queries all reminders associated with the given event. This is a
+         * blocking call and should not be done on the UI thread.
+         *
+         * @param cr The content resolver to use for the query
+         * @param eventId The id of the event to retrieve reminders for
+         * @return A Cursor containing all reminders for the event
+         */
+        public static final Cursor query(ContentResolver cr, long eventId) {
+            String[] remArgs = {Long.toString(eventId)};
+            return cr.query(CONTENT_URI, PROJECTION, REMINDERS_WHERE, remArgs /* selection args */,
+                    null /* sort order */);
+        }
+    }
+
+    protected interface CalendarAlertsColumns {
+        /**
+         * The event that the alert belongs to. Column name.
+         * <P>Type: INTEGER (foreign key to the Events table)</P>
+         */
+        public static final String EVENT_ID = "event_id";
+
+        /**
+         * The start time of the event, in UTC. Column name.
+         * <P>Type: INTEGER (long; millis since epoch)</P>
+         */
+        public static final String BEGIN = "begin";
+
+        /**
+         * The end time of the event, in UTC. Column name.
+         * <P>Type: INTEGER (long; millis since epoch)</P>
+         */
+        public static final String END = "end";
+
+        /**
+         * The alarm time of the event, in UTC. Column name.
+         * <P>Type: INTEGER (long; millis since epoch)</P>
+         */
+        public static final String ALARM_TIME = "alarmTime";
+
+        /**
+         * The creation time of this database entry, in UTC.
+         * Useful for debugging missed reminders. Column name.
+         * <P>Type: INTEGER (long; millis since epoch)</P>
+         */
+        public static final String CREATION_TIME = "creationTime";
+
+        /**
+         * The time that the alarm broadcast was received by the Calendar app,
+         * in UTC. Useful for debugging missed reminders. Column name.
+         * <P>Type: INTEGER (long; millis since epoch)</P>
+         */
+        public static final String RECEIVED_TIME = "receivedTime";
+
+        /**
+         * The time that the notification was created by the Calendar app,
+         * in UTC. Useful for debugging missed reminders. Column name.
+         * <P>Type: INTEGER (long; millis since epoch)</P>
+         */
+        public static final String NOTIFY_TIME = "notifyTime";
+
+        /**
+         * The state of this alert. It starts out as {@link #SCHEDULED}, then
+         * when the alarm goes off, it changes to {@link #FIRED}, and then when
+         * the user dismisses the alarm it changes to {@link #DISMISSED}. Column
+         * name.
+         * <P>Type: INTEGER</P>
+         */
+        public static final String STATE = "state";
+
+        public static final int SCHEDULED = 0;
+        public static final int FIRED = 1;
+        public static final int DISMISSED = 2;
+
+        /**
+         * The number of minutes that this alarm precedes the start time. Column
+         * name.
+         * <P>Type: INTEGER</P>
+         */
+        public static final String MINUTES = "minutes";
+
+        /**
+         * The default sort order for this alerts queries
+         */
+        public static final String DEFAULT_SORT_ORDER = "begin ASC,title ASC";
+    }
+
+    /**
+     * Fields and helpers for accessing calendar alerts information. These
+     * fields are for tracking which alerts have been fired. Scheduled alarms
+     * will generate an intent using {@link #EVENT_REMINDER_ACTION}. Apps that
+     * receive this action may update the {@link #STATE} for the reminder when
+     * they have finished handling it. Apps that have their notifications
+     * disabled should not modify the table to ensure that they do not conflict
+     * with another app that is generating a notification. In general, apps
+     * should not need to write to this table directly except to update the
+     * state of a reminder.
+     */
+    public static final class CalendarAlerts implements BaseColumns,
+            CalendarAlertsColumns, EventsColumns, CalendarsColumns {
+
+        /**
+         * @hide
+         */
+        public static final String TABLE_NAME = "CalendarAlerts";
+        /**
+         * The Uri for querying calendar alert information
+         */
+        @SuppressWarnings("hiding")
+        public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY +
+                "/calendar_alerts");
+
+        private static final String WHERE_ALARM_EXISTS = EVENT_ID + "=?"
+                + " AND " + BEGIN + "=?"
+                + " AND " + ALARM_TIME + "=?";
+
+        private static final String WHERE_FINDNEXTALARMTIME = ALARM_TIME + ">=?";
+        private static final String SORT_ORDER_ALARMTIME_ASC = ALARM_TIME + " ASC";
+
+        private static final String WHERE_RESCHEDULE_MISSED_ALARMS = STATE + "=" + SCHEDULED
+                + " AND " + ALARM_TIME + "<?"
+                + " AND " + ALARM_TIME + ">?"
+                + " AND " + END + ">=?";
+
+        /**
+         * This URI is for grouping the query results by event_id and begin
+         * time.  This will return one result per instance of an event.  So
+         * events with multiple alarms will appear just once, but multiple
+         * instances of a repeating event will show up multiple times.
+         */
+        public static final Uri CONTENT_URI_BY_INSTANCE =
+            Uri.parse("content://" + AUTHORITY + "/calendar_alerts/by_instance");
+
+        private static final boolean DEBUG = true;
+
+        /**
+         * Helper for inserting an alarm time associated with an event
+         *
+         * @hide
+         */
+        public static final Uri insert(ContentResolver cr, long eventId,
+                long begin, long end, long alarmTime, int minutes) {
+            ContentValues values = new ContentValues();
+            values.put(CalendarAlerts.EVENT_ID, eventId);
+            values.put(CalendarAlerts.BEGIN, begin);
+            values.put(CalendarAlerts.END, end);
+            values.put(CalendarAlerts.ALARM_TIME, alarmTime);
+            long currentTime = System.currentTimeMillis();
+            values.put(CalendarAlerts.CREATION_TIME, currentTime);
+            values.put(CalendarAlerts.RECEIVED_TIME, 0);
+            values.put(CalendarAlerts.NOTIFY_TIME, 0);
+            values.put(CalendarAlerts.STATE, SCHEDULED);
+            values.put(CalendarAlerts.MINUTES, minutes);
+            return cr.insert(CONTENT_URI, values);
+        }
+
+        /**
+         * Queries alerts info using the given projection, selection filter, and
+         * ordering. This is a blocking call and should not be done on the UI
+         * thread. For selection and selectionArgs usage see
+         * {@link ContentResolver#query(Uri, String[], String, String[], String)}
+         *
+         * @param cr The content resolver to use for the query
+         * @param projection The columns to return
+         * @param selection Filter on the query as an SQL WHERE statement
+         * @param selectionArgs Args to replace any '?'s in the selection
+         * @param sortOrder How to order the rows as an SQL ORDER BY statement
+         * @return A Cursor containing the matching alerts
+         */
+        public static final Cursor query(ContentResolver cr, String[] projection,
+                String selection, String[] selectionArgs, String sortOrder) {
+            return cr.query(CONTENT_URI, projection, selection, selectionArgs,
+                    sortOrder);
+        }
+
+        /**
+         * Finds the next alarm after (or equal to) the given time and returns
+         * the time of that alarm or -1 if no such alarm exists. This is a
+         * blocking call and should not be done on the UI thread.
+         *
+         * @param cr the ContentResolver
+         * @param millis the time in UTC milliseconds
+         * @return the next alarm time greater than or equal to "millis", or -1
+         *         if no such alarm exists.
+         */
+        public static final long findNextAlarmTime(ContentResolver cr, long millis) {
+            String selection = ALARM_TIME + ">=" + millis;
+            // TODO: construct an explicit SQL query so that we can add
+            // "LIMIT 1" to the end and get just one result.
+            String[] projection = new String[] { ALARM_TIME };
+            Cursor cursor = query(cr, projection,
+                    WHERE_FINDNEXTALARMTIME,
+                    new String[] {
+                        Long.toString(millis)
+                    },
+                    SORT_ORDER_ALARMTIME_ASC);
+            long alarmTime = -1;
+            try {
+                if (cursor != null && cursor.moveToFirst()) {
+                    alarmTime = cursor.getLong(0);
+                }
+            } finally {
+                if (cursor != null) {
+                    cursor.close();
+                }
+            }
+            return alarmTime;
+        }
+
+        /**
+         * Searches the CalendarAlerts table for alarms that should have fired
+         * but have not and then reschedules them.  This method can be called
+         * at boot time to restore alarms that may have been lost due to a
+         * phone reboot.
+         *
+         * @param cr the ContentResolver
+         * @param context the Context
+         * @param manager the AlarmManager
+         */
+        public static final void rescheduleMissedAlarms(ContentResolver cr,
+                Context context, AlarmManager manager) {
+            // Get all the alerts that have been scheduled but have not fired
+            // and should have fired by now and are not too old.
+            long now = System.currentTimeMillis();
+            long ancient = now - DateUtils.DAY_IN_MILLIS;
+            String[] projection = new String[] {
+                    ALARM_TIME,
+            };
+
+            // TODO: construct an explicit SQL query so that we can add
+            // "GROUPBY" instead of doing a sort and de-dup
+            Cursor cursor = CalendarAlerts.query(cr,
+                    projection,
+                    WHERE_RESCHEDULE_MISSED_ALARMS,
+                    new String[] {
+                        Long.toString(now),
+                        Long.toString(ancient),
+                        Long.toString(now)
+                    },
+                    SORT_ORDER_ALARMTIME_ASC);
+            if (cursor == null) {
+                return;
+            }
+
+            if (DEBUG) {
+                Log.d(TAG, "missed alarms found: " + cursor.getCount());
+            }
+
+            try {
+                long alarmTime = -1;
+
+                while (cursor.moveToNext()) {
+                    long newAlarmTime = cursor.getLong(0);
+                    if (alarmTime != newAlarmTime) {
+                        if (DEBUG) {
+                            Log.w(TAG, "rescheduling missed alarm. alarmTime: " + newAlarmTime);
+                        }
+                        scheduleAlarm(context, manager, newAlarmTime);
+                        alarmTime = newAlarmTime;
+                    }
+                }
+            } finally {
+                cursor.close();
+            }
+        }
+
+        /**
+         * Schedules an alarm intent with the system AlarmManager that will
+         * notify listeners when a reminder should be fired. The provider will
+         * keep scheduled reminders up to date but apps may use this to
+         * implement snooze functionality without modifying the reminders table.
+         * Scheduled alarms will generate an intent using
+         * {@link #EVENT_REMINDER_ACTION}.
+         *
+         * @param context A context for referencing system resources
+         * @param manager The AlarmManager to use or null
+         * @param alarmTime The time to fire the intent in UTC millis since
+         *            epoch
+         */
+        public static void scheduleAlarm(Context context, AlarmManager manager, long alarmTime) {
+            if (DEBUG) {
+                Time time = new Time();
+                time.set(alarmTime);
+                String schedTime = time.format(" %a, %b %d, %Y %I:%M%P");
+                Log.d(TAG, "Schedule alarm at " + alarmTime + " " + schedTime);
+            }
+
+            if (manager == null) {
+                manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
+            }
+
+            Intent intent = new Intent(EVENT_REMINDER_ACTION);
+            intent.setData(ContentUris.withAppendedId(CalendarContract.CONTENT_URI, alarmTime));
+            intent.putExtra(ALARM_TIME, alarmTime);
+            PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0);
+            manager.set(AlarmManager.RTC_WAKEUP, alarmTime, pi);
+        }
+
+        /**
+         * Searches for an entry in the CalendarAlerts table that matches
+         * the given event id, begin time and alarm time.  If one is found
+         * then this alarm already exists and this method returns true.
+         *
+         * @param cr the ContentResolver
+         * @param eventId the event id to match
+         * @param begin the start time of the event in UTC millis
+         * @param alarmTime the alarm time of the event in UTC millis
+         * @return true if there is already an alarm for the given event
+         *   with the same start time and alarm time.
+         */
+        public static final boolean alarmExists(ContentResolver cr, long eventId,
+                long begin, long alarmTime) {
+            // TODO: construct an explicit SQL query so that we can add
+            // "LIMIT 1" to the end and get just one result.
+            String[] projection = new String[] { ALARM_TIME };
+            Cursor cursor = query(cr,
+                    projection,
+                    WHERE_ALARM_EXISTS,
+                    new String[] {
+                        Long.toString(eventId),
+                        Long.toString(begin),
+                        Long.toString(alarmTime)
+                    },
+                    null);
+            boolean found = false;
+            try {
+                if (cursor != null && cursor.getCount() > 0) {
+                    found = true;
+                }
+            } finally {
+                if (cursor != null) {
+                    cursor.close();
+                }
+            }
+            return found;
+        }
+    }
+
+    protected interface ExtendedPropertiesColumns {
+        /**
+         * The event the extended property belongs to. Column name.
+         * <P>Type: INTEGER (foreign key to the Events table)</P>
+         */
+        public static final String EVENT_ID = "event_id";
+
+        /**
+         * The name of the extended property.  This is a uri of the form
+         * {scheme}#{local-name} convention. Column name.
+         * <P>Type: TEXT</P>
+         */
+        public static final String NAME = "name";
+
+        /**
+         * The value of the extended property. Column name.
+         * <P>Type: TEXT</P>
+         */
+        public static final String VALUE = "value";
+    }
+
+    /**
+     * Fields for accessing the Extended Properties. This is a generic set of
+     * name/value pairs for use by sync adapters or apps to add extra
+     * information to events. There are three writable columns and all three
+     * must be present when inserting a new value. They are:
+     * <ul>
+     * <li>{@link #EVENT_ID}</li>
+     * <li>{@link #NAME}</li>
+     * <li>{@link #VALUE}</li>
+     * </ul>
+     */
+   public static final class ExtendedProperties implements BaseColumns,
+            ExtendedPropertiesColumns, EventsColumns {
+        public static final Uri CONTENT_URI =
+                Uri.parse("content://" + AUTHORITY + "/extendedproperties");
+
+        // TODO: fill out this class when we actually start utilizing extendedproperties
+        // in the calendar application.
+   }
+
+    /**
+     * A table provided for sync adapters to use for storing private sync state data.
+     *
+     * @see SyncStateContract
+     */
+    public static final class SyncState implements SyncStateContract.Columns {
+        /**
+         * This utility class cannot be instantiated
+         */
+        private SyncState() {}
+
+        private static final String CONTENT_DIRECTORY =
+                SyncStateContract.Constants.CONTENT_DIRECTORY;
+
+        /**
+         * The content:// style URI for this table
+         */
+        public static final Uri CONTENT_URI =
+                Uri.withAppendedPath(CalendarContract.CONTENT_URI, CONTENT_DIRECTORY);
+    }
+
+    /**
+     * Columns from the EventsRawTimes table
+     *
+     * @hide
+     */
+    protected interface EventsRawTimesColumns {
+        /**
+         * The corresponding event id. Column name.
+         * <P>Type: INTEGER (long)</P>
+         */
+        public static final String EVENT_ID = "event_id";
+
+        /**
+         * The RFC2445 compliant time the event starts. Column name.
+         * <P>Type: TEXT</P>
+         */
+        public static final String DTSTART_2445 = "dtstart2445";
+
+        /**
+         * The RFC2445 compliant time the event ends. Column name.
+         * <P>Type: TEXT</P>
+         */
+        public static final String DTEND_2445 = "dtend2445";
+
+        /**
+         * The RFC2445 compliant original instance time of the recurring event
+         * for which this event is an exception. Column name.
+         * <P>Type: TEXT</P>
+         */
+        public static final String ORIGINAL_INSTANCE_TIME_2445 = "originalInstanceTime2445";
+
+        /**
+         * The RFC2445 compliant last date this event repeats on, or NULL if it
+         * never ends. Column name.
+         * <P>Type: TEXT</P>
+         */
+        public static final String LAST_DATE_2445 = "lastDate2445";
+    }
+
+    /**
+     * @hide
+     */
+    public static final class EventsRawTimes implements BaseColumns, EventsRawTimesColumns {
+    }
+}
diff --git a/core/java/android/provider/CallLog.java b/core/java/android/provider/CallLog.java
index bf051f5..02faf49 100644
--- a/core/java/android/provider/CallLog.java
+++ b/core/java/android/provider/CallLog.java
@@ -77,9 +77,17 @@
          */
         public static final String TYPE = "type";
 
+        /** Call log type for incoming calls. */
         public static final int INCOMING_TYPE = 1;
+        /** Call log type for outgoing calls. */
         public static final int OUTGOING_TYPE = 2;
+        /** Call log type for missed calls. */
         public static final int MISSED_TYPE = 3;
+        /**
+         * Call log type for voicemails.
+         * @hide
+         */
+        public static final int VOICEMAIL_TYPE = 4;
 
         /**
          * The phone number as the user entered it.
@@ -143,6 +151,13 @@
         public static final String CACHED_NUMBER_LABEL = "numberlabel";
 
         /**
+         * URI of the voicemail entry. Populated only for {@link #VOICEMAIL_TYPE}.
+         * <P>Type: TEXT</P>
+         * @hide
+         */
+        public static final String VOICEMAIL_URI = "voicemail_uri";
+
+        /**
          * Adds a call to the call log.
          *
          * @param ci the CallerInfo object to get the target contact from.  Can be null
diff --git a/core/java/android/provider/ContactsContract.java b/core/java/android/provider/ContactsContract.java
index 22b4c76..b5a11ab 100644
--- a/core/java/android/provider/ContactsContract.java
+++ b/core/java/android/provider/ContactsContract.java
@@ -122,6 +122,17 @@
     public static final String CALLER_IS_SYNCADAPTER = "caller_is_syncadapter";
 
     /**
+     * An optional URI parameter for selection queries that instructs the
+     * provider to include the user's personal profile contact entry (if any)
+     * in the contact results.  If present, the user's profile will always be
+     * the first entry returned.  The default value is false.
+     *
+     * Specifying this parameter will result in a security error if the calling
+     * application does not have android.permission.READ_PROFILE permission.
+     */
+    public static final String INCLUDE_PROFILE = "include_profile";
+
+    /**
      * A query parameter key used to specify the package that is requesting a query.
      * This is used for restricting data based on package name.
      *
@@ -152,14 +163,12 @@
      * obtaining possible recipients, letting the provider know which account is selected during
      * the composition. The provider may use the "primary account" information to optimize
      * the search result.
-     * @hide
      */
     public static final String PRIMARY_ACCOUNT_NAME = "name_for_primary_account";
 
     /**
      * A query parameter specifing a primary account. This parameter should be used with
      * {@link #PRIMARY_ACCOUNT_NAME}. See the doc in {@link #PRIMARY_ACCOUNT_NAME}.
-     * @hide
      */
     public static final String PRIMARY_ACCOUNT_TYPE = "type_for_primary_account";
 
@@ -763,12 +772,18 @@
         public static final String PHOTO_THUMBNAIL_URI = "photo_thumb_uri";
 
         /**
-         * Lookup value that reflects the {@link Groups#GROUP_VISIBLE} state of
-         * any {@link CommonDataKinds.GroupMembership} for this contact.
+         * Flag that reflects the {@link Groups#GROUP_VISIBLE} state of any
+         * {@link CommonDataKinds.GroupMembership} for this contact.
          */
         public static final String IN_VISIBLE_GROUP = "in_visible_group";
 
         /**
+         * Flag that reflects whether this contact represents the user's
+         * personal profile entry.
+         */
+        public static final String IS_USER_PROFILE = "is_user_profile";
+
+        /**
          * An indicator of whether this contact has at least one phone number. "1" if there is
          * at least one phone number, "0" otherwise.
          * <P>Type: INTEGER</P>
@@ -1281,11 +1296,20 @@
         public static final Uri CONTENT_VCARD_URI = Uri.withAppendedPath(CONTENT_URI,
                 "as_vcard");
 
+       /**
+        * Boolean parameter that may be used with {@link #CONTENT_VCARD_URI}
+        * and {@link #CONTENT_MULTI_VCARD_URI} to indicate that the returned
+        * vcard should not contain a photo.
+        *
+        * @hide
+        */
+        public static final String QUERY_PARAMETER_VCARD_NO_PHOTO = "nophoto";
+
         /**
          * Base {@link Uri} for referencing multiple {@link Contacts} entry,
          * created by appending {@link #LOOKUP_KEY} using
          * {@link Uri#withAppendedPath(Uri, String)}. The lookup keys have to be
-         * encoded and joined with the colon (":") seperator. The resulting string
+         * encoded and joined with the colon (":") separator. The resulting string
          * has to be encoded again. Provides
          * {@link OpenableColumns} columns when queried, or returns the
          * referenced contact formatted as a vCard when opened through
@@ -1738,6 +1762,88 @@
         }
     }
 
+    /**
+     * <p>
+     * Constants for the user's profile data, which is represented as a single contact on
+     * the device that represents the user.  The profile contact is not aggregated
+     * together automatically in the same way that normal contacts are; instead, each
+     * account on the device may contribute a single raw contact representing the user's
+     * personal profile data from that source.
+     * </p>
+     * <p>
+     * Access to the profile entry through these URIs (or incidental access to parts of
+     * the profile if retrieved directly via ID) requires additional permissions beyond
+     * the read/write contact permissions required by the provider.  Querying for profile
+     * data requires android.permission.READ_PROFILE permission, and inserting or
+     * updating profile data requires android.permission.WRITE_PROFILE permission.
+     * </p>
+     * <h3>Operations</h3>
+     * <dl>
+     * <dt><b>Insert</b></dt>
+     * <dd>The user's profile entry cannot be created explicitly (attempting to do so
+     * will throw an exception). When a raw contact is inserted into the profile, the
+     * provider will check for the existence of a profile on the device.  If one is
+     * found, the raw contact's {@link RawContacts#CONTACT_ID} column gets the _ID of
+     * the profile Contact. If no match is found, the profile Contact is created and
+     * its _ID is put into the {@link RawContacts#CONTACT_ID} column of the newly
+     * inserted raw contact.</dd>
+     * <dt><b>Update</b></dt>
+     * <dd>The profile Contact has the same update restrictions as Contacts in general,
+     * but requires the android.permission.WRITE_PROFILE permission.</dd>
+     * <dt><b>Delete</b></dt>
+     * <dd>The profile Contact cannot be explicitly deleted.  It will be removed
+     * automatically if all of its constituent raw contact entries are deleted.</dd>
+     * <dt><b>Query</b></dt>
+     * <dd>
+     * <ul>
+     * <li>The {@link #CONTENT_URI} for profiles behaves in much the same way as
+     * retrieving a contact by ID, except that it will only ever return the user's
+     * profile contact.
+     * </li>
+     * <li>
+     * The profile contact supports all of the same sub-paths as an individual contact
+     * does - the content of the profile contact can be retrieved as entities or
+     * data rows.  Similarly, specific raw contact entries can be retrieved by appending
+     * the desired raw contact ID within the profile.
+     * </li>
+     * </ul>
+     * </dd>
+     * </dl>
+     */
+    public static final class Profile implements BaseColumns, ContactsColumns,
+            ContactOptionsColumns, ContactNameColumns, ContactStatusColumns {
+        /**
+         * This utility class cannot be instantiated
+         */
+        private Profile() {
+        }
+
+        /**
+         * The content:// style URI for this table, which requests the contact entry
+         * representing the user's personal profile data.
+         */
+        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "profile");
+
+        /**
+         * {@link Uri} for referencing the user's profile {@link Contacts} entry,
+         * Provides {@link OpenableColumns} columns when queried, or returns the
+         * user's profile contact formatted as a vCard when opened through
+         * {@link ContentResolver#openAssetFileDescriptor(Uri, String)}.
+         */
+        public static final Uri CONTENT_VCARD_URI = Uri.withAppendedPath(CONTENT_URI,
+                "as_vcard");
+
+        /**
+         * {@link Uri} for referencing the raw contacts that make up the user's profile
+         * {@link Contacts} entry.  An individual raw contact entry within the profile
+         * can be addressed by appending the raw contact ID.  The entities or data within
+         * that specific raw contact can be requested by appending the entity or data
+         * path as well.
+         */
+        public static final Uri CONTENT_RAW_CONTACTS_URI = Uri.withAppendedPath(CONTENT_URI,
+                "raw_contacts");
+    }
+
     protected interface RawContactsColumns {
         /**
          * A reference to the {@link ContactsContract.Contacts#_ID} that this
@@ -1806,6 +1912,12 @@
          * <P>Type: INTEGER</P>
          */
         public static final String RAW_CONTACT_IS_READ_ONLY = "raw_contact_is_read_only";
+
+        /**
+         * Flag that reflects whether this raw contact belongs to the user's
+         * personal profile entry.
+         */
+        public static final String RAW_CONTACT_IS_USER_PROFILE = "raw_contact_is_user_profile";
     }
 
     /**
@@ -6156,6 +6268,95 @@
     }
 
     /**
+     * <p>
+     * API allowing applications to send usage information for each {@link Data} row to the
+     * Contacts Provider.
+     * </p>
+     * <p>
+     * With the feedback, Contacts Provider may return more contextually appropriate results for
+     * Data listing, typically supplied with
+     * {@link ContactsContract.Contacts#CONTENT_FILTER_URI},
+     * {@link ContactsContract.CommonDataKinds.Email#CONTENT_FILTER_URI},
+     * {@link ContactsContract.CommonDataKinds.Phone#CONTENT_FILTER_URI}, and users can benefit
+     * from better ranked (sorted) lists in applications that show auto-complete list.
+     * </p>
+     * <p>
+     * There is no guarantee for how this feedback is used, or even whether it is used at all.
+     * The ranking algorithm will make best efforts to use the feedback data, but the exact
+     * implementation, the storage data structures as well as the resulting sort order is device
+     * and version specific and can change over time.
+     * </p>
+     * <p>
+     * When updating usage information, users of this API need to use
+     * {@link ContentResolver#update(Uri, ContentValues, String, String[])} with a Uri constructed
+     * from {@link DataUsageFeedback#FEEDBACK_URI}. The Uri must contain one or more data id(s) as
+     * its last path. They also need to append a query parameter to the Uri, to specify the type of
+     * the communication, which enables the Contacts Provider to differentiate between kinds of
+     * interactions using the same contact data field (for example a phone number can be used to
+     * make phone calls or send SMS).
+     * </p>
+     * <p>
+     * Selection and selectionArgs are ignored and must be set to null. To get data ids,
+     * you may need to call {@link ContentResolver#query(Uri, String[], String, String[], String)}
+     * toward {@link Data#CONTENT_URI}.
+     * </p>
+     * <p>
+     * {@link ContentResolver#update(Uri, ContentValues, String, String[])} returns a positive
+     * integer when successful, and returns 0 if no contact with that id was found.
+     * </p>
+     * <p>
+     * Example:
+     * <pre>
+     * Uri uri = DataUsageFeedback.FEEDBACK_URI.buildUpon()
+     *         .appendPath(TextUtils.join(",", dataIds))
+     *         .appendQueryParameter(DataUsageFeedback.USAGE_TYPE,
+     *                 DataUsageFeedback.USAGE_TYPE_CALL)
+     *         .build();
+     * boolean successful = resolver.update(uri, new ContentValues(), null, null) > 0;
+     * </pre>
+     * </p>
+     */
+    public static final class DataUsageFeedback {
+
+        /**
+         * The content:// style URI for sending usage feedback.
+         * Must be used with {@link ContentResolver#update(Uri, ContentValues, String, String[])}.
+         */
+        public static final Uri FEEDBACK_URI =
+                Uri.withAppendedPath(Data.CONTENT_URI, "usagefeedback");
+
+        /**
+         * <p>
+         * Name for query parameter specifying the type of data usage.
+         * </p>
+         */
+        public static final String USAGE_TYPE = "type";
+
+        /**
+         * <p>
+         * Type of usage for voice interaction, which includes phone call, voice chat, and
+         * video chat.
+         * </p>
+         */
+        public static final String USAGE_TYPE_CALL = "call";
+
+        /**
+         * <p>
+         * Type of usage for text interaction involving longer messages, which includes email.
+         * </p>
+         */
+        public static final String USAGE_TYPE_LONG_TEXT = "long_text";
+
+        /**
+         * <p>
+         * Type of usage for text interaction involving shorter messages, which includes SMS,
+         * text chat with email addresses.
+         * </p>
+         */
+        public static final String USAGE_TYPE_SHORT_TEXT = "short_text";
+    }
+
+    /**
      * Helper methods to display QuickContact dialogs that allow users to pivot on
      * a specific {@link Contacts} entry.
      */
diff --git a/core/java/android/provider/Downloads.java b/core/java/android/provider/Downloads.java
index 3c4bb79..ba4804d 100644
--- a/core/java/android/provider/Downloads.java
+++ b/core/java/android/provider/Downloads.java
@@ -17,6 +17,7 @@
 package android.provider;
 
 import android.app.DownloadManager;
+import android.net.NetworkPolicyManager;
 import android.net.Uri;
 
 /**
@@ -695,6 +696,14 @@
         public static final int STATUS_TOO_MANY_REDIRECTS = 497;
 
         /**
+         * This download has failed because requesting application has been
+         * blocked by {@link NetworkPolicyManager}.
+         *
+         * @hide
+         */
+        public static final int STATUS_BLOCKED = 498;
+
+        /**
          * This download is visible but only shows in the notifications
          * while it's in progress.
          */
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index c78b935..603edf0 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -1768,12 +1768,6 @@
         public static final String UNLOCK_SOUND = "unlock_sound";
 
         /**
-         * True if we should appear as a PTP device instead of MTP.
-         * @hide
-         */
-        public static final String USE_PTP_INTERFACE = "use_ptp_interface";
-
-        /**
          * Receive incoming SIP calls?
          * 0 = no
          * 1 = yes
@@ -1809,6 +1803,16 @@
         public static final String SIP_ASK_ME_EACH_TIME = "SIP_ASK_ME_EACH_TIME";
 
         /**
+         * Pointer speed setting.
+         * This is an integer value in a range between -7 and +7, so there are 15 possible values.
+         *   -7 = slowest
+         *    0 = default speed
+         *   +7 = fastest
+         * @hide
+         */
+        public static final String POINTER_SPEED = "pointer_speed";
+
+        /**
          * Settings to backup. This is here so that it's in the same place as the settings
          * keys and easy to update.
          * @hide
@@ -1869,9 +1873,9 @@
             LOCKSCREEN_SOUNDS_ENABLED,
             SHOW_WEB_SUGGESTIONS,
             NOTIFICATION_LIGHT_PULSE,
-            USE_PTP_INTERFACE,
             SIP_CALL_OPTIONS,
             SIP_RECEIVE_CALLS,
+            POINTER_SPEED,
         };
 
         // Settings moved to Settings.Secure
@@ -2913,6 +2917,30 @@
         public static final String WIFI_WATCHDOG_PING_TIMEOUT_MS = "wifi_watchdog_ping_timeout_ms";
 
         /**
+         * Setting to turn off walled garden test on Wi-Fi. Feature is enabled by default and
+         * the setting needs to be set to 0 to disable it.
+         * @hide
+         */
+        public static final String WIFI_WATCHDOG_WALLED_GARDEN_TEST_ENABLED =
+                "wifi_watchdog_walled_garden_test_enabled";
+
+        /**
+         * The URL used for walled garden check upon a new conection. WifiWatchdogService
+         * fetches the URL and checks to see if {@link #WIFI_WATCHDOG_WALLED_GARDEN_PATTERN}
+         * is not part of the title string to notify the user on the presence of a walled garden.
+         * @hide
+         */
+        public static final String WIFI_WATCHDOG_WALLED_GARDEN_URL =
+                "wifi_watchdog_walled_garden_url";
+
+        /**
+         * The pattern string in the fetched URL used to detect a walled garden
+         * @hide
+         */
+        public static final String WIFI_WATCHDOG_WALLED_GARDEN_PATTERN =
+                "wifi_watchdog_walled_garden_pattern";
+
+        /**
          * The maximum number of times we will retry a connection to an access
          * point for which we have failed in acquiring an IP address from DHCP.
          * A value of N means that we will make N+1 connection attempts in all.
@@ -3760,6 +3788,21 @@
         public static final String DREAM_TIMEOUT =
                 "dream_timeout";
 
+        /** {@hide} */
+        public static final String NETSTATS_POLL_INTERVAL = "netstats_poll_interval";
+        /** {@hide} */
+        public static final String NETSTATS_PERSIST_THRESHOLD = "netstats_persist_threshold";
+        /** {@hide} */
+        public static final String NETSTATS_NETWORK_BUCKET_DURATION = "netstats_network_bucket_duration";
+        /** {@hide} */
+        public static final String NETSTATS_NETWORK_MAX_HISTORY = "netstats_network_max_history";
+        /** {@hide} */
+        public static final String NETSTATS_UID_BUCKET_DURATION = "netstats_uid_bucket_duration";
+        /** {@hide} */
+        public static final String NETSTATS_UID_MAX_HISTORY = "netstats_uid_max_history";
+        /** {@hide} */
+        public static final String NETSTATS_TAG_MAX_HISTORY = "netstats_tag_max_history";
+
         /**
          * @hide
          */
diff --git a/core/java/android/provider/Telephony.java b/core/java/android/provider/Telephony.java
index 91a72a5..6585e82 100644
--- a/core/java/android/provider/Telephony.java
+++ b/core/java/android/provider/Telephony.java
@@ -547,7 +547,7 @@
              * values:</p>
              *
              * <ul>
-             *   <li><em>pdus</em> - An Object[] od byte[]s containing the PDUs
+             *   <li><em>pdus</em> - An Object[] of byte[]s containing the PDUs
              *   that make up the message.</li>
              * </ul>
              *
@@ -591,6 +591,46 @@
                     "android.provider.Telephony.WAP_PUSH_RECEIVED";
 
             /**
+             * Broadcast Action: A new Cell Broadcast message has been received
+             * by the device. The intent will have the following extra
+             * values:</p>
+             *
+             * <ul>
+             *   <li><em>pdus</em> - An Object[] of byte[]s containing the PDUs
+             *   that make up the message.</li>
+             * </ul>
+             *
+             * <p>The extra values can be extracted using
+             * {@link #getMessagesFromIntent(Intent)}.</p>
+             *
+             * <p>If a BroadcastReceiver encounters an error while processing
+             * this intent it should set the result code appropriately.</p>
+             */
+            @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
+            public static final String SMS_CB_RECEIVED_ACTION =
+                    "android.provider.Telephony.SMS_CB_RECEIVED";
+
+            /**
+             * Broadcast Action: A new Emergency Broadcast message has been received
+             * by the device. The intent will have the following extra
+             * values:</p>
+             *
+             * <ul>
+             *   <li><em>pdus</em> - An Object[] of byte[]s containing the PDUs
+             *   that make up the message.</li>
+             * </ul>
+             *
+             * <p>The extra values can be extracted using
+             * {@link #getMessagesFromIntent(Intent)}.</p>
+             *
+             * <p>If a BroadcastReceiver encounters an error while processing
+             * this intent it should set the result code appropriately.</p>
+             */
+            @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
+            public static final String SMS_EMERGENCY_CB_RECEIVED_ACTION =
+                    "android.provider.Telephony.SMS_EMERGENCY_CB_RECEIVED";
+
+            /**
              * Broadcast Action: The SIM storage for SMS messages is full.  If
              * space is not freed, messages targeted for the SIM (class 2) may
              * not be saved.
@@ -623,7 +663,7 @@
              * @param intent the intent to read from
              * @return an array of SmsMessages for the PDUs
              */
-            public static final SmsMessage[] getMessagesFromIntent(
+            public static SmsMessage[] getMessagesFromIntent(
                     Intent intent) {
                 Object[] messages = (Object[]) intent.getSerializableExtra("pdus");
                 byte[][] pduObjs = new byte[messages.length][];
diff --git a/core/java/android/provider/VoicemailContract.java b/core/java/android/provider/VoicemailContract.java
new file mode 100644
index 0000000..ae41876
--- /dev/null
+++ b/core/java/android/provider/VoicemailContract.java
@@ -0,0 +1,148 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+package android.provider;
+
+import android.content.Intent;
+import android.database.ContentObserver;
+import android.net.Uri;
+import android.provider.CallLog.Calls;
+
+/**
+ * The contract between the voicemail provider and applications. Contains
+ * definitions for the supported URIs and columns.
+ *
+ * <P>Voicemails are inserted by what is called as a "voicemail source"
+ * application, which is responsible for syncing voicemail data between a remote
+ * server and the local voicemail content provider. "voicemail source"
+ * application should use the source specific {@link #CONTENT_URI_SOURCE} URI
+ * to insert and retrieve voicemails.
+ *
+ * <P>In addition to the {@link ContentObserver} notifications the voicemail
+ * provider also generates broadcast intents to notify change for applications
+ * that are not active and therefore cannot listen to ContentObserver
+ * notifications. Broadcast intents with following actions are generated:
+ * <ul>
+ *   <li> {@link #ACTION_NEW_VOICEMAIL} is generated for each new voicemail
+ *   inserted.
+ *   </li>
+ *   <li> {@link Intent#ACTION_PROVIDER_CHANGED} is generated for any change
+ *    made into the database, including new voicemail.
+ *   </li>
+ * </ul>
+ * @hide
+ */
+// TODO: unhide when the API is approved by android-api-council
+public class VoicemailContract {
+    /** Not instantiable. */
+    private VoicemailContract() {
+    }
+
+    /** The authority used by the voicemail provider. */
+    public static final String AUTHORITY = "com.android.voicemail";
+
+    /** URI to insert/retrieve all voicemails. */
+    public static final Uri CONTENT_URI =
+            Uri.parse("content://" + AUTHORITY + "/voicemail");
+    /** URI to insert/retrieve voicemails by a given voicemail source. */
+    public static final Uri CONTENT_URI_SOURCE =
+            Uri.parse("content://" + AUTHORITY + "/voicemail/source/");
+
+    // TODO: Move ACTION_NEW_VOICEMAIL to the Intent class.
+    /** Broadcast intent when a new voicemail record is inserted. */
+    public static final String ACTION_NEW_VOICEMAIL = "android.intent.action.NEW_VOICEMAIL";
+    /**
+     * Extra included in {@value Intent#ACTION_PROVIDER_CHANGED} and
+     * {@value #ACTION_NEW_VOICEMAIL} broadcast intents to indicate the package
+     * that caused the change in content provider.
+     * <p>Receivers of the broadcast can use this field to determine if this is
+     * a self change.
+     */
+    public static final String EXTRA_CHANGED_BY = "com.android.voicemail.extra.CHANGED_BY";
+
+    /** The mime type for a collection of voicemails. */
+    public static final String DIR_TYPE =
+            "vnd.android.cursor.dir/voicemails";
+
+    public static final class Voicemails implements BaseColumns {
+        /** Not instantiable. */
+        private Voicemails() {
+        }
+
+        /**
+         * Phone number of the voicemail sender.
+         * <P>Type: TEXT</P>
+         */
+        public static final String NUMBER = Calls.NUMBER;
+        /**
+         * The date the voicemail was sent, in milliseconds since the epoch
+         * <P>Type: INTEGER (long)</P>
+         */
+        public static final String DATE = Calls.DATE;
+        /**
+         * The duration of the voicemail in seconds.
+         * <P>Type: INTEGER (long)</P>
+         */
+        public static final String DURATION = Calls.DURATION;
+        /**
+         * Whether this is a new voicemail (i.e. has not been heard).
+         * <P>Type: INTEGER (boolean)</P>
+         */
+        public static final String NEW = Calls.NEW;
+        /**
+         * The mail box state of the voicemail.
+         * <P> Possible values: {@link #STATE_INBOX}, {@link #STATE_DELETED},
+         * {@link #STATE_UNDELETED}.
+         * <P>Type: INTEGER</P>
+         */
+        public static final String STATE = "state";
+        /** Value of {@link #STATE} when the voicemail is in inbox. */
+        public static int STATE_INBOX = 0;
+        /** Value of {@link #STATE} when the voicemail has been marked as deleted. */
+        public static int STATE_DELETED = 1;
+        /** Value of {@link #STATE} when the voicemail has marked as undeleted. */
+        public static int STATE_UNDELETED = 2;
+        /**
+         * Package name of the source application that inserted the voicemail.
+         * <P>Type: TEXT</P>
+         */
+        public static final String SOURCE_PACKAGE = "source_package";
+        /**
+         * Application-specific data available to the source application that
+         * inserted the voicemail. This is typically used to store the source
+         * specific message id to identify this voicemail on the remote
+         * voicemail server.
+         * <P>Type: TEXT</P>
+         * <P> Note that this is NOT the voicemail media content data.
+         */
+        public static final String SOURCE_DATA = "source_data";
+        /**
+         * Whether the media content for this voicemail is available for
+         * consumption.
+         * <P>Type: INTEGER (boolean)</P>
+         */
+        public static final String HAS_CONTENT = "has_content";
+        /**
+         * MIME type of the media content for the voicemail.
+         * <P>Type: TEXT</P>
+         */
+        public static final String MIME_TYPE = "mime_type";
+        /**
+         * Path to the media content file. Internal only field.
+         * @hide
+         */
+        public static final String _DATA = "_data";
+    }
+}
diff --git a/core/java/android/security/package.html b/core/java/android/security/package.html
deleted file mode 100644
index dfc6303..0000000
--- a/core/java/android/security/package.html
+++ /dev/null
@@ -1,6 +0,0 @@
-<HTML>
-<BODY>
-Utilities for encrypting messages from hash functions.
-{@hide}
-</BODY>
-</HTML>
diff --git a/core/java/android/server/BluetoothService.java b/core/java/android/server/BluetoothService.java
index 60bee9a..62792f4 100755
--- a/core/java/android/server/BluetoothService.java
+++ b/core/java/android/server/BluetoothService.java
@@ -1737,7 +1737,6 @@
                 pw.println("Number of connected devices:" + deviceList.size());
                 BluetoothDevice device = deviceList.get(0);
                 pw.println("getConnectedDevices[0] = " + device);
-                pw.println("Priority of Connected device = " + mPan.getPriority(device));
 
                 switch (mPan.getConnectionState(device)) {
                     case BluetoothInputDevice.STATE_CONNECTING:
diff --git a/core/java/android/service/wallpaper/WallpaperService.java b/core/java/android/service/wallpaper/WallpaperService.java
index eae7574..8fc8b9d 100644
--- a/core/java/android/service/wallpaper/WallpaperService.java
+++ b/core/java/android/service/wallpaper/WallpaperService.java
@@ -181,7 +181,7 @@
         
         final BaseSurfaceHolder mSurfaceHolder = new BaseSurfaceHolder() {
             {
-                mRequestedFormat = PixelFormat.RGB_565;
+                mRequestedFormat = PixelFormat.RGBX_8888;
             }
 
             @Override
diff --git a/core/java/android/speech/tts/AbstractSynthesisCallback.java b/core/java/android/speech/tts/AbstractSynthesisCallback.java
new file mode 100644
index 0000000..c7a4af0
--- /dev/null
+++ b/core/java/android/speech/tts/AbstractSynthesisCallback.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package android.speech.tts;
+
+/**
+ * Defines additional methods the synthesis callback must implement that
+ * are private to the TTS service implementation.
+ */
+abstract class AbstractSynthesisCallback implements SynthesisCallback {
+    /**
+     * Checks whether the synthesis request completed successfully.
+     */
+    abstract boolean isDone();
+
+    /**
+     * Aborts the speech request.
+     *
+     * Can be called from multiple threads.
+     */
+    abstract void stop();
+}
diff --git a/core/java/android/speech/tts/AudioMessageParams.java b/core/java/android/speech/tts/AudioMessageParams.java
new file mode 100644
index 0000000..68d8738
--- /dev/null
+++ b/core/java/android/speech/tts/AudioMessageParams.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package android.speech.tts;
+
+import android.speech.tts.TextToSpeechService.UtteranceCompletedDispatcher;
+
+class AudioMessageParams extends MessageParams {
+    private final BlockingMediaPlayer mPlayer;
+
+    AudioMessageParams(UtteranceCompletedDispatcher dispatcher,
+            String callingApp, BlockingMediaPlayer player) {
+        super(dispatcher, callingApp);
+        mPlayer = player;
+    }
+
+    BlockingMediaPlayer getPlayer() {
+        return mPlayer;
+    }
+
+    @Override
+    int getType() {
+        return TYPE_AUDIO;
+    }
+
+}
diff --git a/core/java/android/speech/tts/AudioPlaybackHandler.java b/core/java/android/speech/tts/AudioPlaybackHandler.java
new file mode 100644
index 0000000..a3686b7
--- /dev/null
+++ b/core/java/android/speech/tts/AudioPlaybackHandler.java
@@ -0,0 +1,521 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package android.speech.tts;
+
+import android.media.AudioFormat;
+import android.media.AudioTrack;
+import android.util.Log;
+
+import java.util.Iterator;
+import java.util.concurrent.PriorityBlockingQueue;
+import java.util.concurrent.atomic.AtomicLong;
+
+class AudioPlaybackHandler {
+    private static final String TAG = "TTS.AudioPlaybackHandler";
+    private static final boolean DBG = false;
+
+    private static final int MIN_AUDIO_BUFFER_SIZE = 8192;
+
+    private static final int SYNTHESIS_START = 1;
+    private static final int SYNTHESIS_DATA_AVAILABLE = 2;
+    private static final int SYNTHESIS_COMPLETE_DATA_AVAILABLE = 3;
+    private static final int SYNTHESIS_DONE = 4;
+
+    private static final int PLAY_AUDIO = 5;
+    private static final int PLAY_SILENCE = 6;
+
+    private static final int SHUTDOWN = -1;
+
+    private static final int DEFAULT_PRIORITY = 1;
+    private static final int HIGH_PRIORITY = 0;
+
+    private final PriorityBlockingQueue<ListEntry> mQueue =
+            new PriorityBlockingQueue<ListEntry>();
+    private final Thread mHandlerThread;
+
+    private volatile MessageParams mCurrentParams = null;
+    // Used only for book keeping and error detection.
+    private volatile SynthesisMessageParams mLastSynthesisRequest = null;
+    // Used to order incoming messages in our priority queue.
+    private final AtomicLong mSequenceIdCtr = new AtomicLong(0);
+
+
+    AudioPlaybackHandler() {
+        mHandlerThread = new Thread(new MessageLoop(), "TTS.AudioPlaybackThread");
+    }
+
+    public void start() {
+        mHandlerThread.start();
+    }
+
+    /**
+     * Stops all synthesis for a given {@code token}. If the current token
+     * is currently being processed, an effort will be made to stop it but
+     * that is not guaranteed.
+     */
+    synchronized public void stop(MessageParams token) {
+        if (token == null) {
+            return;
+        }
+
+        removeMessages(token);
+
+        if (token.getType() == MessageParams.TYPE_SYNTHESIS) {
+            mQueue.add(new ListEntry(SYNTHESIS_DONE, token, HIGH_PRIORITY));
+        } else  {
+            final MessageParams current = getCurrentParams();
+
+            if (current != null) {
+                if (token.getType() == MessageParams.TYPE_AUDIO) {
+                    ((AudioMessageParams) current).getPlayer().stop();
+                } else if (token.getType() == MessageParams.TYPE_SILENCE) {
+                    ((SilenceMessageParams) current).getConditionVariable().open();
+                }
+            }
+        }
+    }
+
+    synchronized public void removePlaybackItems(String callingApp) {
+        removeMessages(callingApp);
+        stop(getCurrentParams());
+    }
+
+    synchronized public void removeAllItems() {
+        removeAllMessages();
+        stop(getCurrentParams());
+    }
+
+    /**
+     * Shut down the audio playback thread.
+     */
+    synchronized public void quit() {
+        stop(getCurrentParams());
+        mQueue.add(new ListEntry(SHUTDOWN, null, HIGH_PRIORITY));
+    }
+
+    void enqueueSynthesisStart(SynthesisMessageParams token) {
+        mQueue.add(new ListEntry(SYNTHESIS_START, token));
+    }
+
+    void enqueueSynthesisDataAvailable(SynthesisMessageParams token) {
+        mQueue.add(new ListEntry(SYNTHESIS_DATA_AVAILABLE, token));
+    }
+
+    void enqueueSynthesisCompleteDataAvailable(SynthesisMessageParams token) {
+        mQueue.add(new ListEntry(SYNTHESIS_COMPLETE_DATA_AVAILABLE, token));
+    }
+
+    void enqueueSynthesisDone(SynthesisMessageParams token) {
+        mQueue.add(new ListEntry(SYNTHESIS_DONE, token));
+    }
+
+    void enqueueAudio(AudioMessageParams token) {
+        mQueue.add(new ListEntry(PLAY_AUDIO, token));
+    }
+
+    void enqueueSilence(SilenceMessageParams token) {
+        mQueue.add(new ListEntry(PLAY_SILENCE, token));
+    }
+
+    // -----------------------------------------
+    // End of public API methods.
+    // -----------------------------------------
+
+    // -----------------------------------------
+    // Methods for managing the message queue.
+    // -----------------------------------------
+
+    /*
+     * The MessageLoop is a handler like implementation that
+     * processes messages from a priority queue.
+     */
+    private final class MessageLoop implements Runnable {
+        @Override
+        public void run() {
+            while (true) {
+                ListEntry entry = null;
+                try {
+                    entry = mQueue.take();
+                } catch (InterruptedException ie) {
+                    return;
+                }
+
+                if (entry.mWhat == SHUTDOWN) {
+                    if (DBG) Log.d(TAG, "MessageLoop : Shutting down");
+                    return;
+                }
+
+                if (DBG) {
+                    Log.d(TAG, "MessageLoop : Handling message :" + entry.mWhat
+                            + " ,seqId : " + entry.mSequenceId);
+                }
+
+                setCurrentParams(entry.mMessage);
+                handleMessage(entry);
+                setCurrentParams(null);
+            }
+        }
+    }
+
+    /*
+     * Remove all messages from the queue that contain the supplied token.
+     * Note that the Iterator is thread safe, and other methods can safely
+     * continue adding to the queue at this point.
+     */
+    synchronized private void removeMessages(MessageParams token) {
+        if (token == null) {
+            return;
+        }
+
+        Iterator<ListEntry> it = mQueue.iterator();
+
+        while (it.hasNext()) {
+            final ListEntry current = it.next();
+            if (current.mMessage == token) {
+                it.remove();
+            }
+        }
+    }
+
+    /*
+     * Atomically clear the queue of all messages.
+     */
+    synchronized private void removeAllMessages() {
+        mQueue.clear();
+    }
+
+    /*
+     * Remove all messages that originate from a given calling app.
+     */
+    synchronized private void removeMessages(String callingApp) {
+        Iterator<ListEntry> it = mQueue.iterator();
+
+        while (it.hasNext()) {
+            final ListEntry current = it.next();
+            // The null check is to prevent us from removing control messages,
+            // such as a shutdown message.
+            if (current.mMessage != null &&
+                    callingApp.equals(current.mMessage.getCallingApp())) {
+                it.remove();
+            }
+        }
+    }
+
+    /*
+     * An element of our priority queue of messages. Each message has a priority,
+     * and a sequence id (defined by the order of enqueue calls). Among messages
+     * with the same priority, messages that were received earlier win out.
+     */
+    private final class ListEntry implements Comparable<ListEntry> {
+        final int mWhat;
+        final MessageParams mMessage;
+        final int mPriority;
+        final long mSequenceId;
+
+        private ListEntry(int what, MessageParams message) {
+            this(what, message, DEFAULT_PRIORITY);
+        }
+
+        private ListEntry(int what, MessageParams message, int priority) {
+            mWhat = what;
+            mMessage = message;
+            mPriority = priority;
+            mSequenceId = mSequenceIdCtr.incrementAndGet();
+        }
+
+        @Override
+        public int compareTo(ListEntry that) {
+            if (that == this) {
+                return 0;
+            }
+
+            // Note that this is always 0, 1 or -1.
+            int priorityDiff = mPriority - that.mPriority;
+            if (priorityDiff == 0) {
+                // The == case cannot occur.
+                return (mSequenceId < that.mSequenceId) ? -1 : 1;
+            }
+
+            return priorityDiff;
+        }
+    }
+
+    private void setCurrentParams(MessageParams p) {
+        mCurrentParams = p;
+    }
+
+    private MessageParams getCurrentParams() {
+        return mCurrentParams;
+    }
+
+    // -----------------------------------------
+    // Methods for dealing with individual messages, the methods
+    // below do the actual work.
+    // -----------------------------------------
+
+    private void handleMessage(ListEntry entry) {
+        final MessageParams msg = entry.mMessage;
+        if (entry.mWhat == SYNTHESIS_START) {
+            handleSynthesisStart(msg);
+        } else if (entry.mWhat == SYNTHESIS_DATA_AVAILABLE) {
+            handleSynthesisDataAvailable(msg);
+        } else if (entry.mWhat == SYNTHESIS_DONE) {
+            handleSynthesisDone(msg);
+        } else if (entry.mWhat == SYNTHESIS_COMPLETE_DATA_AVAILABLE) {
+            handleSynthesisCompleteDataAvailable(msg);
+        } else if (entry.mWhat == PLAY_AUDIO) {
+            handleAudio(msg);
+        } else if (entry.mWhat == PLAY_SILENCE) {
+            handleSilence(msg);
+        }
+    }
+
+    // Currently implemented as blocking the audio playback thread for the
+    // specified duration. If a call to stop() is made, the thread
+    // unblocks.
+    private void handleSilence(MessageParams msg) {
+        if (DBG) Log.d(TAG, "handleSilence()");
+        SilenceMessageParams params = (SilenceMessageParams) msg;
+        if (params.getSilenceDurationMs() > 0) {
+            params.getConditionVariable().block(params.getSilenceDurationMs());
+        }
+        params.getDispatcher().dispatchUtteranceCompleted();
+        if (DBG) Log.d(TAG, "handleSilence() done.");
+    }
+
+    // Plays back audio from a given URI. No TTS engine involvement here.
+    private void handleAudio(MessageParams msg) {
+        if (DBG) Log.d(TAG, "handleAudio()");
+        AudioMessageParams params = (AudioMessageParams) msg;
+        // Note that the BlockingMediaPlayer spawns a separate thread.
+        //
+        // TODO: This can be avoided.
+        params.getPlayer().startAndWait();
+        params.getDispatcher().dispatchUtteranceCompleted();
+        if (DBG) Log.d(TAG, "handleAudio() done.");
+    }
+
+    // Denotes the start of a new synthesis request. We create a new
+    // audio track, and prepare it for incoming data.
+    //
+    // Note that since all TTS synthesis happens on a single thread, we
+    // should ALWAYS see the following order :
+    //
+    // handleSynthesisStart -> handleSynthesisDataAvailable(*) -> handleSynthesisDone
+    // OR
+    // handleSynthesisCompleteDataAvailable.
+    private void handleSynthesisStart(MessageParams msg) {
+        if (DBG) Log.d(TAG, "handleSynthesisStart()");
+        final SynthesisMessageParams param = (SynthesisMessageParams) msg;
+
+        // Oops, looks like the engine forgot to call done(). We go through
+        // extra trouble to clean the data to prevent the AudioTrack resources
+        // from being leaked.
+        if (mLastSynthesisRequest != null) {
+            Log.w(TAG, "Error : Missing call to done() for request : " +
+                    mLastSynthesisRequest);
+            handleSynthesisDone(mLastSynthesisRequest);
+        }
+
+        mLastSynthesisRequest = param;
+
+        // Create the audio track.
+        final AudioTrack audioTrack = createStreamingAudioTrack(
+                param.mStreamType, param.mSampleRateInHz, param.mAudioFormat,
+                param.mChannelCount, param.mVolume, param.mPan);
+
+        if (DBG) Log.d(TAG, "Created audio track [" + audioTrack.hashCode() + "]");
+
+        param.setAudioTrack(audioTrack);
+    }
+
+    // More data available to be flushed to the audio track.
+    private void handleSynthesisDataAvailable(MessageParams msg) {
+        final SynthesisMessageParams param = (SynthesisMessageParams) msg;
+        if (param.getAudioTrack() == null) {
+            Log.w(TAG, "Error : null audio track in handleDataAvailable.");
+            return;
+        }
+
+        if (param != mLastSynthesisRequest) {
+            Log.e(TAG, "Call to dataAvailable without done() / start()");
+            return;
+        }
+
+        final AudioTrack audioTrack = param.getAudioTrack();
+        final SynthesisMessageParams.ListEntry bufferCopy = param.getNextBuffer();
+
+        if (bufferCopy == null) {
+            Log.e(TAG, "No buffers available to play.");
+            return;
+        }
+
+        int playState = audioTrack.getPlayState();
+        if (playState == AudioTrack.PLAYSTATE_STOPPED) {
+            if (DBG) Log.d(TAG, "AudioTrack stopped, restarting : " + audioTrack.hashCode());
+            audioTrack.play();
+        }
+        int count = 0;
+        while (count < bufferCopy.mLength) {
+            // Note that we don't take bufferCopy.mOffset into account because
+            // it is guaranteed to be 0.
+            int written = audioTrack.write(bufferCopy.mBytes, count, bufferCopy.mLength);
+            if (written <= 0) {
+                break;
+            }
+            count += written;
+        }
+    }
+
+    private void handleSynthesisDone(MessageParams msg) {
+        final SynthesisMessageParams params = (SynthesisMessageParams) msg;
+        handleSynthesisDone(params);
+    }
+
+    // Flush all remaining data to the audio track, stop it and release
+    // all it's resources.
+    private void handleSynthesisDone(SynthesisMessageParams params) {
+        if (DBG) Log.d(TAG, "handleSynthesisDone()");
+        final AudioTrack audioTrack = params.getAudioTrack();
+
+        try {
+            if (audioTrack != null) {
+                audioTrack.flush();
+                audioTrack.stop();
+                if (DBG) Log.d(TAG, "Releasing audio track [" + audioTrack.hashCode() + "]");
+                audioTrack.release();
+            }
+        } finally {
+            params.setAudioTrack(null);
+            params.getDispatcher().dispatchUtteranceCompleted();
+            mLastSynthesisRequest = null;
+        }
+    }
+
+    private void handleSynthesisCompleteDataAvailable(MessageParams msg) {
+        final SynthesisMessageParams params = (SynthesisMessageParams) msg;
+        if (DBG) Log.d(TAG, "completeAudioAvailable(" + params + ")");
+
+        // Channel config and bytes per frame are checked before
+        // this message is sent.
+        int channelConfig = AudioPlaybackHandler.getChannelConfig(params.mChannelCount);
+        int bytesPerFrame = AudioPlaybackHandler.getBytesPerFrame(params.mAudioFormat);
+
+        SynthesisMessageParams.ListEntry entry = params.getNextBuffer();
+
+        if (entry == null) {
+            Log.w(TAG, "completeDataAvailable : No buffers available to play.");
+            return;
+        }
+
+        final AudioTrack audioTrack = new AudioTrack(params.mStreamType, params.mSampleRateInHz,
+                channelConfig, params.mAudioFormat, entry.mLength, AudioTrack.MODE_STATIC);
+
+        // So that handleDone can access this correctly.
+        params.mAudioTrack = audioTrack;
+
+        try {
+            audioTrack.write(entry.mBytes, entry.mOffset, entry.mLength);
+            setupVolume(audioTrack, params.mVolume, params.mPan);
+            audioTrack.play();
+            blockUntilDone(audioTrack, bytesPerFrame, entry.mLength);
+            if (DBG) Log.d(TAG, "Wrote data to audio track successfully : " + entry.mLength);
+        } catch (IllegalStateException ex) {
+            Log.e(TAG, "Playback error", ex);
+        } finally {
+            handleSynthesisDone(msg);
+        }
+    }
+
+
+    private static void blockUntilDone(AudioTrack audioTrack, int bytesPerFrame, int length) {
+        int lengthInFrames = length / bytesPerFrame;
+        int currentPosition = 0;
+        while ((currentPosition = audioTrack.getPlaybackHeadPosition()) < lengthInFrames) {
+            long estimatedTimeMs = ((lengthInFrames - currentPosition) * 1000) /
+                    audioTrack.getSampleRate();
+            audioTrack.getPlayState();
+            if (DBG) Log.d(TAG, "About to sleep for : " + estimatedTimeMs + " ms," +
+                    " Playback position : " + currentPosition);
+            try {
+                Thread.sleep(estimatedTimeMs);
+            } catch (InterruptedException ie) {
+                break;
+            }
+        }
+    }
+
+    private static AudioTrack createStreamingAudioTrack(int streamType, int sampleRateInHz,
+            int audioFormat, int channelCount, float volume, float pan) {
+        int channelConfig = getChannelConfig(channelCount);
+
+        int minBufferSizeInBytes
+                = AudioTrack.getMinBufferSize(sampleRateInHz, channelConfig, audioFormat);
+        int bufferSizeInBytes = Math.max(MIN_AUDIO_BUFFER_SIZE, minBufferSizeInBytes);
+
+        AudioTrack audioTrack = new AudioTrack(streamType, sampleRateInHz, channelConfig,
+                audioFormat, bufferSizeInBytes, AudioTrack.MODE_STREAM);
+        if (audioTrack.getState() != AudioTrack.STATE_INITIALIZED) {
+            Log.w(TAG, "Unable to create audio track.");
+            audioTrack.release();
+            return null;
+        }
+
+        setupVolume(audioTrack, volume, pan);
+        return audioTrack;
+    }
+
+    static int getChannelConfig(int channelCount) {
+        if (channelCount == 1) {
+            return AudioFormat.CHANNEL_OUT_MONO;
+        } else if (channelCount == 2){
+            return AudioFormat.CHANNEL_OUT_STEREO;
+        }
+
+        return 0;
+    }
+
+    static int getBytesPerFrame(int audioFormat) {
+        if (audioFormat == AudioFormat.ENCODING_PCM_8BIT) {
+            return 1;
+        } else if (audioFormat == AudioFormat.ENCODING_PCM_16BIT) {
+            return 2;
+        }
+
+        return -1;
+    }
+
+    private static void setupVolume(AudioTrack audioTrack, float volume, float pan) {
+        float vol = clip(volume, 0.0f, 1.0f);
+        float panning = clip(pan, -1.0f, 1.0f);
+        float volLeft = vol;
+        float volRight = vol;
+        if (panning > 0.0f) {
+            volLeft *= (1.0f - panning);
+        } else if (panning < 0.0f) {
+            volRight *= (1.0f + panning);
+        }
+        if (DBG) Log.d(TAG, "volLeft=" + volLeft + ",volRight=" + volRight);
+        if (audioTrack.setStereoVolume(volLeft, volRight) != AudioTrack.SUCCESS) {
+            Log.e(TAG, "Failed to set volume");
+        }
+    }
+
+    private static float clip(float value, float min, float max) {
+        return value > max ? max : (value < min ? min : value);
+    }
+
+}
diff --git a/core/java/android/speech/tts/FileSynthesisCallback.java b/core/java/android/speech/tts/FileSynthesisCallback.java
new file mode 100644
index 0000000..4f4b3fb
--- /dev/null
+++ b/core/java/android/speech/tts/FileSynthesisCallback.java
@@ -0,0 +1,250 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package android.speech.tts;
+
+import android.media.AudioFormat;
+import android.util.Log;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+/**
+ * Speech synthesis request that writes the audio to a WAV file.
+ */
+class FileSynthesisCallback extends AbstractSynthesisCallback {
+
+    private static final String TAG = "FileSynthesisRequest";
+    private static final boolean DBG = false;
+
+    private static final int MAX_AUDIO_BUFFER_SIZE = 8192;
+
+    private static final int WAV_HEADER_LENGTH = 44;
+    private static final short WAV_FORMAT_PCM = 0x0001;
+
+    private final Object mStateLock = new Object();
+    private final File mFileName;
+    private int mSampleRateInHz;
+    private int mAudioFormat;
+    private int mChannelCount;
+    private RandomAccessFile mFile;
+    private boolean mStopped = false;
+    private boolean mDone = false;
+
+    FileSynthesisCallback(File fileName) {
+        mFileName = fileName;
+    }
+
+    @Override
+    void stop() {
+        synchronized (mStateLock) {
+            mStopped = true;
+            cleanUp();
+        }
+    }
+
+    /**
+     * Must be called while holding the monitor on {@link #mStateLock}.
+     */
+    private void cleanUp() {
+        closeFile();
+        if (mFile != null) {
+            mFileName.delete();
+        }
+    }
+
+    /**
+     * Must be called while holding the monitor on {@link #mStateLock}.
+     */
+    private void closeFile() {
+        try {
+            if (mFile != null) {
+                mFile.close();
+                mFile = null;
+            }
+        } catch (IOException ex) {
+            Log.e(TAG, "Failed to close " + mFileName + ": " + ex);
+        }
+    }
+
+    @Override
+    public int getMaxBufferSize() {
+        return MAX_AUDIO_BUFFER_SIZE;
+    }
+
+    @Override
+    boolean isDone() {
+        return mDone;
+    }
+
+    @Override
+    public int start(int sampleRateInHz, int audioFormat, int channelCount) {
+        if (DBG) {
+            Log.d(TAG, "FileSynthesisRequest.start(" + sampleRateInHz + "," + audioFormat
+                    + "," + channelCount + ")");
+        }
+        synchronized (mStateLock) {
+            if (mStopped) {
+                if (DBG) Log.d(TAG, "Request has been aborted.");
+                return TextToSpeech.ERROR;
+            }
+            if (mFile != null) {
+                cleanUp();
+                throw new IllegalArgumentException("FileSynthesisRequest.start() called twice");
+            }
+            mSampleRateInHz = sampleRateInHz;
+            mAudioFormat = audioFormat;
+            mChannelCount = channelCount;
+            try {
+                mFile = new RandomAccessFile(mFileName, "rw");
+                // Reserve space for WAV header
+                mFile.write(new byte[WAV_HEADER_LENGTH]);
+                return TextToSpeech.SUCCESS;
+            } catch (IOException ex) {
+                Log.e(TAG, "Failed to open " + mFileName + ": " + ex);
+                cleanUp();
+                return TextToSpeech.ERROR;
+            }
+        }
+    }
+
+    @Override
+    public int audioAvailable(byte[] buffer, int offset, int length) {
+        if (DBG) {
+            Log.d(TAG, "FileSynthesisRequest.audioAvailable(" + buffer + "," + offset
+                    + "," + length + ")");
+        }
+        synchronized (mStateLock) {
+            if (mStopped) {
+                if (DBG) Log.d(TAG, "Request has been aborted.");
+                return TextToSpeech.ERROR;
+            }
+            if (mFile == null) {
+                Log.e(TAG, "File not open");
+                return TextToSpeech.ERROR;
+            }
+            try {
+                mFile.write(buffer, offset, length);
+                return TextToSpeech.SUCCESS;
+            } catch (IOException ex) {
+                Log.e(TAG, "Failed to write to " + mFileName + ": " + ex);
+                cleanUp();
+                return TextToSpeech.ERROR;
+            }
+        }
+    }
+
+    @Override
+    public int done() {
+        if (DBG) Log.d(TAG, "FileSynthesisRequest.done()");
+        synchronized (mStateLock) {
+            if (mStopped) {
+                if (DBG) Log.d(TAG, "Request has been aborted.");
+                return TextToSpeech.ERROR;
+            }
+            if (mFile == null) {
+                Log.e(TAG, "File not open");
+                return TextToSpeech.ERROR;
+            }
+            try {
+                // Write WAV header at start of file
+                mFile.seek(0);
+                int dataLength = (int) (mFile.length() - WAV_HEADER_LENGTH);
+                mFile.write(
+                        makeWavHeader(mSampleRateInHz, mAudioFormat, mChannelCount, dataLength));
+                closeFile();
+                mDone = true;
+                return TextToSpeech.SUCCESS;
+            } catch (IOException ex) {
+                Log.e(TAG, "Failed to write to " + mFileName + ": " + ex);
+                cleanUp();
+                return TextToSpeech.ERROR;
+            }
+        }
+    }
+
+    @Override
+    public void error() {
+        if (DBG) Log.d(TAG, "FileSynthesisRequest.error()");
+        synchronized (mStateLock) {
+            cleanUp();
+        }
+    }
+
+    @Override
+    public int completeAudioAvailable(int sampleRateInHz, int audioFormat, int channelCount,
+            byte[] buffer, int offset, int length) {
+        synchronized (mStateLock) {
+            if (mStopped) {
+                if (DBG) Log.d(TAG, "Request has been aborted.");
+                return TextToSpeech.ERROR;
+            }
+        }
+        FileOutputStream out = null;
+        try {
+            out = new FileOutputStream(mFileName);
+            out.write(makeWavHeader(sampleRateInHz, audioFormat, channelCount, length));
+            out.write(buffer, offset, length);
+            mDone = true;
+            return TextToSpeech.SUCCESS;
+        } catch (IOException ex) {
+            Log.e(TAG, "Failed to write to " + mFileName + ": " + ex);
+            mFileName.delete();
+            return TextToSpeech.ERROR;
+        } finally {
+            try {
+                if (out != null) {
+                    out.close();
+                }
+            } catch (IOException ex) {
+                Log.e(TAG, "Failed to close " + mFileName + ": " + ex);
+            }
+        }
+    }
+
+    private byte[] makeWavHeader(int sampleRateInHz, int audioFormat, int channelCount,
+            int dataLength) {
+        // TODO: is AudioFormat.ENCODING_DEFAULT always the same as ENCODING_PCM_16BIT?
+        int sampleSizeInBytes = (audioFormat == AudioFormat.ENCODING_PCM_8BIT ? 1 : 2);
+        int byteRate = sampleRateInHz * sampleSizeInBytes * channelCount;
+        short blockAlign = (short) (sampleSizeInBytes * channelCount);
+        short bitsPerSample = (short) (sampleSizeInBytes * 8);
+
+        byte[] headerBuf = new byte[WAV_HEADER_LENGTH];
+        ByteBuffer header = ByteBuffer.wrap(headerBuf);
+        header.order(ByteOrder.LITTLE_ENDIAN);
+
+        header.put(new byte[]{ 'R', 'I', 'F', 'F' });
+        header.putInt(dataLength + WAV_HEADER_LENGTH - 8);  // RIFF chunk size
+        header.put(new byte[]{ 'W', 'A', 'V', 'E' });
+        header.put(new byte[]{ 'f', 'm', 't', ' ' });
+        header.putInt(16);  // size of fmt chunk
+        header.putShort(WAV_FORMAT_PCM);
+        header.putShort((short) channelCount);
+        header.putInt(sampleRateInHz);
+        header.putInt(byteRate);
+        header.putShort(blockAlign);
+        header.putShort(bitsPerSample);
+        header.put(new byte[]{ 'd', 'a', 't', 'a' });
+        header.putInt(dataLength);
+
+        return headerBuf;
+    }
+
+}
diff --git a/core/java/android/speech/tts/FileSynthesisRequest.java b/core/java/android/speech/tts/FileSynthesisRequest.java
deleted file mode 100644
index 62be2bf..0000000
--- a/core/java/android/speech/tts/FileSynthesisRequest.java
+++ /dev/null
@@ -1,252 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package android.speech.tts;
-
-import android.media.AudioFormat;
-import android.os.Bundle;
-import android.util.Log;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.RandomAccessFile;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-
-/**
- * Speech synthesis request that writes the audio to a WAV file.
- */
-class FileSynthesisRequest extends SynthesisRequest {
-
-    private static final String TAG = "FileSynthesisRequest";
-    private static final boolean DBG = false;
-
-    private static final int MAX_AUDIO_BUFFER_SIZE = 8192;
-
-    private static final int WAV_HEADER_LENGTH = 44;
-    private static final short WAV_FORMAT_PCM = 0x0001;
-
-    private final Object mStateLock = new Object();
-    private final File mFileName;
-    private int mSampleRateInHz;
-    private int mAudioFormat;
-    private int mChannelCount;
-    private RandomAccessFile mFile;
-    private boolean mStopped = false;
-    private boolean mDone = false;
-
-    FileSynthesisRequest(String text, Bundle params, File fileName) {
-        super(text, params);
-        mFileName = fileName;
-    }
-
-    @Override
-    void stop() {
-        synchronized (mStateLock) {
-            mStopped = true;
-            cleanUp();
-        }
-    }
-
-    /**
-     * Must be called while holding the monitor on {@link #mStateLock}.
-     */
-    private void cleanUp() {
-        closeFile();
-        if (mFile != null) {
-            mFileName.delete();
-        }
-    }
-
-    /**
-     * Must be called while holding the monitor on {@link #mStateLock}.
-     */
-    private void closeFile() {
-        try {
-            if (mFile != null) {
-                mFile.close();
-                mFile = null;
-            }
-        } catch (IOException ex) {
-            Log.e(TAG, "Failed to close " + mFileName + ": " + ex);
-        }
-    }
-
-    @Override
-    public int getMaxBufferSize() {
-        return MAX_AUDIO_BUFFER_SIZE;
-    }
-
-    @Override
-    boolean isDone() {
-        return mDone;
-    }
-
-    @Override
-    public int start(int sampleRateInHz, int audioFormat, int channelCount) {
-        if (DBG) {
-            Log.d(TAG, "FileSynthesisRequest.start(" + sampleRateInHz + "," + audioFormat
-                    + "," + channelCount + ")");
-        }
-        synchronized (mStateLock) {
-            if (mStopped) {
-                if (DBG) Log.d(TAG, "Request has been aborted.");
-                return TextToSpeech.ERROR;
-            }
-            if (mFile != null) {
-                cleanUp();
-                throw new IllegalArgumentException("FileSynthesisRequest.start() called twice");
-            }
-            mSampleRateInHz = sampleRateInHz;
-            mAudioFormat = audioFormat;
-            mChannelCount = channelCount;
-            try {
-                mFile = new RandomAccessFile(mFileName, "rw");
-                // Reserve space for WAV header
-                mFile.write(new byte[WAV_HEADER_LENGTH]);
-                return TextToSpeech.SUCCESS;
-            } catch (IOException ex) {
-                Log.e(TAG, "Failed to open " + mFileName + ": " + ex);
-                cleanUp();
-                return TextToSpeech.ERROR;
-            }
-        }
-    }
-
-    @Override
-    public int audioAvailable(byte[] buffer, int offset, int length) {
-        if (DBG) {
-            Log.d(TAG, "FileSynthesisRequest.audioAvailable(" + buffer + "," + offset
-                    + "," + length + ")");
-        }
-        synchronized (mStateLock) {
-            if (mStopped) {
-                if (DBG) Log.d(TAG, "Request has been aborted.");
-                return TextToSpeech.ERROR;
-            }
-            if (mFile == null) {
-                Log.e(TAG, "File not open");
-                return TextToSpeech.ERROR;
-            }
-            try {
-                mFile.write(buffer, offset, length);
-                return TextToSpeech.SUCCESS;
-            } catch (IOException ex) {
-                Log.e(TAG, "Failed to write to " + mFileName + ": " + ex);
-                cleanUp();
-                return TextToSpeech.ERROR;
-            }
-        }
-    }
-
-    @Override
-    public int done() {
-        if (DBG) Log.d(TAG, "FileSynthesisRequest.done()");
-        synchronized (mStateLock) {
-            if (mStopped) {
-                if (DBG) Log.d(TAG, "Request has been aborted.");
-                return TextToSpeech.ERROR;
-            }
-            if (mFile == null) {
-                Log.e(TAG, "File not open");
-                return TextToSpeech.ERROR;
-            }
-            try {
-                // Write WAV header at start of file
-                mFile.seek(0);
-                int dataLength = (int) (mFile.length() - WAV_HEADER_LENGTH);
-                mFile.write(
-                        makeWavHeader(mSampleRateInHz, mAudioFormat, mChannelCount, dataLength));
-                closeFile();
-                mDone = true;
-                return TextToSpeech.SUCCESS;
-            } catch (IOException ex) {
-                Log.e(TAG, "Failed to write to " + mFileName + ": " + ex);
-                cleanUp();
-                return TextToSpeech.ERROR;
-            }
-        }
-    }
-
-    @Override
-    public void error() {
-        if (DBG) Log.d(TAG, "FileSynthesisRequest.error()");
-        synchronized (mStateLock) {
-            cleanUp();
-        }
-    }
-
-    @Override
-    public int completeAudioAvailable(int sampleRateInHz, int audioFormat, int channelCount,
-            byte[] buffer, int offset, int length) {
-        synchronized (mStateLock) {
-            if (mStopped) {
-                if (DBG) Log.d(TAG, "Request has been aborted.");
-                return TextToSpeech.ERROR;
-            }
-        }
-        FileOutputStream out = null;
-        try {
-            out = new FileOutputStream(mFileName);
-            out.write(makeWavHeader(sampleRateInHz, audioFormat, channelCount, length));
-            out.write(buffer, offset, length);
-            mDone = true;
-            return TextToSpeech.SUCCESS;
-        } catch (IOException ex) {
-            Log.e(TAG, "Failed to write to " + mFileName + ": " + ex);
-            mFileName.delete();
-            return TextToSpeech.ERROR;
-        } finally {
-            try {
-                if (out != null) {
-                    out.close();
-                }
-            } catch (IOException ex) {
-                Log.e(TAG, "Failed to close " + mFileName + ": " + ex);
-            }
-        }
-    }
-
-    private byte[] makeWavHeader(int sampleRateInHz, int audioFormat, int channelCount,
-            int dataLength) {
-        // TODO: is AudioFormat.ENCODING_DEFAULT always the same as ENCODING_PCM_16BIT?
-        int sampleSizeInBytes = (audioFormat == AudioFormat.ENCODING_PCM_8BIT ? 1 : 2);
-        int byteRate = sampleRateInHz * sampleSizeInBytes * channelCount;
-        short blockAlign = (short) (sampleSizeInBytes * channelCount);
-        short bitsPerSample = (short) (sampleSizeInBytes * 8);
-
-        byte[] headerBuf = new byte[WAV_HEADER_LENGTH];
-        ByteBuffer header = ByteBuffer.wrap(headerBuf);
-        header.order(ByteOrder.LITTLE_ENDIAN);
-
-        header.put(new byte[]{ 'R', 'I', 'F', 'F' });
-        header.putInt(dataLength + WAV_HEADER_LENGTH - 8);  // RIFF chunk size
-        header.put(new byte[]{ 'W', 'A', 'V', 'E' });
-        header.put(new byte[]{ 'f', 'm', 't', ' ' });
-        header.putInt(16);  // size of fmt chunk
-        header.putShort(WAV_FORMAT_PCM);
-        header.putShort((short) channelCount);
-        header.putInt(sampleRateInHz);
-        header.putInt(byteRate);
-        header.putShort(blockAlign);
-        header.putShort(bitsPerSample);
-        header.put(new byte[]{ 'd', 'a', 't', 'a' });
-        header.putInt(dataLength);
-
-        return headerBuf;
-    }
-
-}
diff --git a/core/java/android/speech/tts/MessageParams.java b/core/java/android/speech/tts/MessageParams.java
new file mode 100644
index 0000000..4c1b6d2
--- /dev/null
+++ b/core/java/android/speech/tts/MessageParams.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package android.speech.tts;
+
+import android.speech.tts.TextToSpeechService.UtteranceCompletedDispatcher;
+
+abstract class MessageParams {
+    static final int TYPE_SYNTHESIS = 1;
+    static final int TYPE_AUDIO = 2;
+    static final int TYPE_SILENCE = 3;
+
+    private final UtteranceCompletedDispatcher mDispatcher;
+    private final String mCallingApp;
+
+    MessageParams(UtteranceCompletedDispatcher dispatcher, String callingApp) {
+        mDispatcher = dispatcher;
+        mCallingApp = callingApp;
+    }
+
+    UtteranceCompletedDispatcher getDispatcher() {
+        return mDispatcher;
+    }
+
+    String getCallingApp() {
+        return mCallingApp;
+    }
+
+    abstract int getType();
+}
diff --git a/core/java/android/speech/tts/PlaybackSynthesisCallback.java b/core/java/android/speech/tts/PlaybackSynthesisCallback.java
new file mode 100644
index 0000000..bdaa1b8
--- /dev/null
+++ b/core/java/android/speech/tts/PlaybackSynthesisCallback.java
@@ -0,0 +1,221 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package android.speech.tts;
+
+import android.speech.tts.TextToSpeechService.UtteranceCompletedDispatcher;
+import android.util.Log;
+
+/**
+ * Speech synthesis request that plays the audio as it is received.
+ */
+class PlaybackSynthesisCallback extends AbstractSynthesisCallback {
+
+    private static final String TAG = "PlaybackSynthesisRequest";
+    private static final boolean DBG = false;
+
+    private static final int MIN_AUDIO_BUFFER_SIZE = 8192;
+
+    /**
+     * Audio stream type. Must be one of the STREAM_ contants defined in
+     * {@link android.media.AudioManager}.
+     */
+    private final int mStreamType;
+
+    /**
+     * Volume, in the range [0.0f, 1.0f]. The default value is
+     * {@link TextToSpeech.Engine#DEFAULT_VOLUME} (1.0f).
+     */
+    private final float mVolume;
+
+    /**
+     * Left/right position of the audio, in the range [-1.0f, 1.0f].
+     * The default value is {@link TextToSpeech.Engine#DEFAULT_PAN} (0.0f).
+     */
+    private final float mPan;
+
+    /**
+     * Guards {@link #mAudioTrackHandler}, {@link #mToken} and {@link #mStopped}.
+     */
+    private final Object mStateLock = new Object();
+
+    // Handler associated with a thread that plays back audio requests.
+    private final AudioPlaybackHandler mAudioTrackHandler;
+    // A request "token", which will be non null after start() or
+    // completeAudioAvailable() have been called.
+    private SynthesisMessageParams mToken = null;
+    // Whether this request has been stopped. This is useful for keeping
+    // track whether stop() has been called before start(). In all other cases,
+    // a non-null value of mToken will provide the same information.
+    private boolean mStopped = false;
+
+    private volatile boolean mDone = false;
+
+    private final UtteranceCompletedDispatcher mDispatcher;
+    private final String mCallingApp;
+
+    PlaybackSynthesisCallback(int streamType, float volume, float pan,
+            AudioPlaybackHandler audioTrackHandler, UtteranceCompletedDispatcher dispatcher,
+            String callingApp) {
+        mStreamType = streamType;
+        mVolume = volume;
+        mPan = pan;
+        mAudioTrackHandler = audioTrackHandler;
+        mDispatcher = dispatcher;
+        mCallingApp = callingApp;
+    }
+
+    @Override
+    void stop() {
+        if (DBG) Log.d(TAG, "stop()");
+
+        synchronized (mStateLock) {
+            if (mToken == null || mStopped) {
+                Log.w(TAG, "stop() called twice, before start(), or after done()");
+                return;
+            }
+            mAudioTrackHandler.stop(mToken);
+            mToken = null;
+            mStopped = true;
+        }
+    }
+
+    @Override
+    public int getMaxBufferSize() {
+        // The AudioTrack buffer will be at least MIN_AUDIO_BUFFER_SIZE, so that should always be
+        // a safe buffer size to pass in.
+        return MIN_AUDIO_BUFFER_SIZE;
+    }
+
+    @Override
+    boolean isDone() {
+        return mDone;
+    }
+
+    @Override
+    public int start(int sampleRateInHz, int audioFormat, int channelCount) {
+        if (DBG) {
+            Log.d(TAG, "start(" + sampleRateInHz + "," + audioFormat
+                    + "," + channelCount + ")");
+        }
+
+        int channelConfig = AudioPlaybackHandler.getChannelConfig(channelCount);
+        if (channelConfig == 0) {
+            Log.e(TAG, "Unsupported number of channels :" + channelCount);
+            return TextToSpeech.ERROR;
+        }
+
+        synchronized (mStateLock) {
+            if (mStopped) {
+                if (DBG) Log.d(TAG, "stop() called before start(), returning.");
+                return TextToSpeech.ERROR;
+            }
+            SynthesisMessageParams params = new SynthesisMessageParams(
+                    mStreamType, sampleRateInHz, audioFormat, channelCount, mVolume, mPan,
+                    mDispatcher, mCallingApp);
+            mAudioTrackHandler.enqueueSynthesisStart(params);
+
+            mToken = params;
+        }
+
+        return TextToSpeech.SUCCESS;
+    }
+
+
+    @Override
+    public int audioAvailable(byte[] buffer, int offset, int length) {
+        if (DBG) {
+            Log.d(TAG, "audioAvailable(byte[" + buffer.length + "],"
+                    + offset + "," + length + ")");
+        }
+        if (length > getMaxBufferSize() || length <= 0) {
+            throw new IllegalArgumentException("buffer is too large or of zero length (" +
+                    + length + " bytes)");
+        }
+
+        synchronized (mStateLock) {
+            if (mToken == null) {
+                return TextToSpeech.ERROR;
+            }
+
+            // Sigh, another copy.
+            final byte[] bufferCopy = new byte[length];
+            System.arraycopy(buffer, offset, bufferCopy, 0, length);
+            mToken.addBuffer(bufferCopy);
+            mAudioTrackHandler.enqueueSynthesisDataAvailable(mToken);
+        }
+
+        return TextToSpeech.SUCCESS;
+    }
+
+    @Override
+    public int done() {
+        if (DBG) Log.d(TAG, "done()");
+
+        synchronized (mStateLock) {
+            if (mDone) {
+                Log.w(TAG, "Duplicate call to done()");
+                return TextToSpeech.ERROR;
+            }
+
+            mDone = true;
+
+            if (mToken == null) {
+                return TextToSpeech.ERROR;
+            }
+
+            mAudioTrackHandler.enqueueSynthesisDone(mToken);
+        }
+        return TextToSpeech.SUCCESS;
+    }
+
+    @Override
+    public void error() {
+        if (DBG) Log.d(TAG, "error() [will call stop]");
+        stop();
+    }
+
+    @Override
+    public int completeAudioAvailable(int sampleRateInHz, int audioFormat, int channelCount,
+            byte[] buffer, int offset, int length) {
+        int channelConfig = AudioPlaybackHandler.getChannelConfig(channelCount);
+        if (channelConfig == 0) {
+            Log.e(TAG, "Unsupported number of channels :" + channelCount);
+            return TextToSpeech.ERROR;
+        }
+
+        int bytesPerFrame = AudioPlaybackHandler.getBytesPerFrame(audioFormat);
+        if (bytesPerFrame < 0) {
+            Log.e(TAG, "Unsupported audio format :" + audioFormat);
+            return TextToSpeech.ERROR;
+        }
+
+        synchronized (mStateLock) {
+            if (mStopped) {
+                return TextToSpeech.ERROR;
+            }
+            SynthesisMessageParams params = new SynthesisMessageParams(
+                    mStreamType, sampleRateInHz, audioFormat, channelCount, mVolume, mPan,
+                    mDispatcher, mCallingApp);
+            params.addBuffer(buffer, offset, length);
+
+            mAudioTrackHandler.enqueueSynthesisCompleteDataAvailable(params);
+            mToken = params;
+        }
+
+        return TextToSpeech.SUCCESS;
+    }
+
+}
diff --git a/core/java/android/speech/tts/PlaybackSynthesisRequest.java b/core/java/android/speech/tts/PlaybackSynthesisRequest.java
deleted file mode 100644
index d698b54..0000000
--- a/core/java/android/speech/tts/PlaybackSynthesisRequest.java
+++ /dev/null
@@ -1,363 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package android.speech.tts;
-
-import android.media.AudioFormat;
-import android.media.AudioTrack;
-import android.os.Bundle;
-import android.os.Handler;
-import android.util.Log;
-
-/**
- * Speech synthesis request that plays the audio as it is received.
- */
-class PlaybackSynthesisRequest extends SynthesisRequest {
-
-    private static final String TAG = "PlaybackSynthesisRequest";
-    private static final boolean DBG = false;
-
-    private static final int MIN_AUDIO_BUFFER_SIZE = 8192;
-
-    /**
-     * Audio stream type. Must be one of the STREAM_ contants defined in
-     * {@link android.media.AudioManager}.
-     */
-    private final int mStreamType;
-
-    /**
-     * Volume, in the range [0.0f, 1.0f]. The default value is
-     * {@link TextToSpeech.Engine#DEFAULT_VOLUME} (1.0f).
-     */
-    private final float mVolume;
-
-    /**
-     * Left/right position of the audio, in the range [-1.0f, 1.0f].
-     * The default value is {@link TextToSpeech.Engine#DEFAULT_PAN} (0.0f).
-     */
-    private final float mPan;
-
-    private final Object mStateLock = new Object();
-    private final Handler mAudioTrackHandler;
-    private volatile AudioTrack mAudioTrack = null;
-    private boolean mStopped = false;
-    private boolean mDone = false;
-    private volatile boolean mWriteErrorOccured;
-
-    PlaybackSynthesisRequest(String text, Bundle params,
-            int streamType, float volume, float pan, Handler audioTrackHandler) {
-        super(text, params);
-        mStreamType = streamType;
-        mVolume = volume;
-        mPan = pan;
-        mAudioTrackHandler = audioTrackHandler;
-        mWriteErrorOccured = false;
-    }
-
-    @Override
-    void stop() {
-        if (DBG) Log.d(TAG, "stop()");
-        synchronized (mStateLock) {
-            mStopped = true;
-            cleanUp();
-        }
-    }
-
-    // Always guarded by mStateLock.
-    private void cleanUp() {
-        if (DBG) Log.d(TAG, "cleanUp()");
-        if (mAudioTrack == null) {
-            return;
-        }
-
-        final AudioTrack audioTrack = mAudioTrack;
-        mAudioTrack = null;
-
-        // Clean up on the audiotrack handler thread.
-        //
-        // NOTE: It isn't very clear whether AudioTrack is thread safe.
-        // If it is we can clean up on the current (synthesis) thread.
-        mAudioTrackHandler.post(new Runnable() {
-            @Override
-            public void run() {
-                audioTrack.flush();
-                audioTrack.stop();
-                audioTrack.release();
-            }
-        });
-    }
-
-    @Override
-    public int getMaxBufferSize() {
-        // The AudioTrack buffer will be at least MIN_AUDIO_BUFFER_SIZE, so that should always be
-        // a safe buffer size to pass in.
-        return MIN_AUDIO_BUFFER_SIZE;
-    }
-
-    @Override
-    boolean isDone() {
-        return mDone;
-    }
-
-    // TODO: add a thread that writes to the AudioTrack?
-    @Override
-    public int start(int sampleRateInHz, int audioFormat, int channelCount) {
-        if (DBG) {
-            Log.d(TAG, "start(" + sampleRateInHz + "," + audioFormat
-                    + "," + channelCount + ")");
-        }
-
-        synchronized (mStateLock) {
-            if (mStopped) {
-                if (DBG) Log.d(TAG, "Request has been aborted.");
-                return TextToSpeech.ERROR;
-            }
-            if (mAudioTrack != null) {
-                Log.e(TAG, "start() called twice");
-                cleanUp();
-                return TextToSpeech.ERROR;
-            }
-
-            mAudioTrack = createStreamingAudioTrack(sampleRateInHz, audioFormat, channelCount);
-            if (mAudioTrack == null) {
-                return TextToSpeech.ERROR;
-            }
-        }
-
-        return TextToSpeech.SUCCESS;
-    }
-
-    private void setupVolume(AudioTrack audioTrack, float volume, float pan) {
-        float vol = clip(volume, 0.0f, 1.0f);
-        float panning = clip(pan, -1.0f, 1.0f);
-        float volLeft = vol;
-        float volRight = vol;
-        if (panning > 0.0f) {
-            volLeft *= (1.0f - panning);
-        } else if (panning < 0.0f) {
-            volRight *= (1.0f + panning);
-        }
-        if (DBG) Log.d(TAG, "volLeft=" + volLeft + ",volRight=" + volRight);
-        if (audioTrack.setStereoVolume(volLeft, volRight) != AudioTrack.SUCCESS) {
-            Log.e(TAG, "Failed to set volume");
-        }
-    }
-
-    private float clip(float value, float min, float max) {
-        return value > max ? max : (value < min ? min : value);
-    }
-
-    @Override
-    public int audioAvailable(byte[] buffer, int offset, int length) {
-        if (DBG) {
-            Log.d(TAG, "audioAvailable(byte[" + buffer.length + "],"
-                    + offset + "," + length + ")");
-        }
-        if (length > getMaxBufferSize() || length <= 0) {
-            throw new IllegalArgumentException("buffer is too large or of zero length (" +
-                    + length + " bytes)");
-        }
-        synchronized (mStateLock) {
-            if (mWriteErrorOccured) {
-                if (DBG) Log.d(TAG, "Error writing to audio track, count < 0");
-                return TextToSpeech.ERROR;
-            }
-            if (mStopped) {
-                if (DBG) Log.d(TAG, "Request has been aborted.");
-                return TextToSpeech.ERROR;
-            }
-            if (mAudioTrack == null) {
-                Log.e(TAG, "audioAvailable(): Not started");
-                return TextToSpeech.ERROR;
-            }
-            final AudioTrack audioTrack = mAudioTrack;
-            // Sigh, another copy.
-            final byte[] bufferCopy = new byte[length];
-            System.arraycopy(buffer, offset, bufferCopy, 0, length);
-
-            mAudioTrackHandler.post(new Runnable() {
-                @Override
-                public void run() {
-                    int playState = audioTrack.getPlayState();
-                    if (playState == AudioTrack.PLAYSTATE_STOPPED) {
-                        if (DBG) Log.d(TAG, "AudioTrack stopped, restarting");
-                        audioTrack.play();
-                    }
-                    // TODO: loop until all data is written?
-                    if (DBG) Log.d(TAG, "AudioTrack.write()");
-                    int count = audioTrack.write(bufferCopy, 0, bufferCopy.length);
-                    // The semantics of this change very slightly. Earlier, we would
-                    // report an error immediately, Now we will return an error on
-                    // the next API call, usually done( ) or another audioAvailable( )
-                    // call.
-                    if (count < 0) {
-                        mWriteErrorOccured = true;
-                    }
-                }
-            });
-
-            return TextToSpeech.SUCCESS;
-        }
-    }
-
-    @Override
-    public int done() {
-        if (DBG) Log.d(TAG, "done()");
-        synchronized (mStateLock) {
-            if (mWriteErrorOccured) {
-                if (DBG) Log.d(TAG, "Error writing to audio track, count < 0");
-                return TextToSpeech.ERROR;
-            }
-            if (mStopped) {
-                if (DBG) Log.d(TAG, "Request has been aborted.");
-                return TextToSpeech.ERROR;
-            }
-            if (mAudioTrack == null) {
-                Log.e(TAG, "done(): Not started");
-                return TextToSpeech.ERROR;
-            }
-            mDone = true;
-            cleanUp();
-        }
-        return TextToSpeech.SUCCESS;
-    }
-
-    @Override
-    public void error() {
-        if (DBG) Log.d(TAG, "error()");
-        synchronized (mStateLock) {
-            cleanUp();
-        }
-    }
-
-    @Override
-    public int completeAudioAvailable(int sampleRateInHz, int audioFormat, int channelCount,
-            byte[] buffer, int offset, int length) {
-        if (DBG) {
-            Log.d(TAG, "completeAudioAvailable(" + sampleRateInHz + "," + audioFormat
-                    + "," + channelCount + "byte[" + buffer.length + "],"
-                    + offset + "," + length + ")");
-        }
-
-        synchronized (mStateLock) {
-            if (mStopped) {
-                if (DBG) Log.d(TAG, "Request has been aborted.");
-                return TextToSpeech.ERROR;
-            }
-            if (mAudioTrack != null) {
-                Log.e(TAG, "start() called before completeAudioAvailable()");
-                cleanUp();
-                return TextToSpeech.ERROR;
-            }
-
-            int channelConfig = getChannelConfig(channelCount);
-            if (channelConfig < 0) {
-                Log.e(TAG, "Unsupported number of channels :" + channelCount);
-                cleanUp();
-                return TextToSpeech.ERROR;
-            }
-            int bytesPerFrame = getBytesPerFrame(audioFormat);
-            if (bytesPerFrame < 0) {
-                Log.e(TAG, "Unsupported audio format :" + audioFormat);
-                cleanUp();
-                return TextToSpeech.ERROR;
-            }
-
-            mAudioTrack = new AudioTrack(mStreamType, sampleRateInHz, channelConfig,
-                    audioFormat, buffer.length, AudioTrack.MODE_STATIC);
-            if (mAudioTrack == null) {
-                return TextToSpeech.ERROR;
-            }
-
-            try {
-                mAudioTrack.write(buffer, offset, length);
-                setupVolume(mAudioTrack, mVolume, mPan);
-                mAudioTrack.play();
-                blockUntilDone(mAudioTrack, bytesPerFrame, length);
-                mDone = true;
-                if (DBG) Log.d(TAG, "Wrote data to audio track succesfully : " + length);
-            } catch (IllegalStateException ex) {
-                Log.e(TAG, "Playback error", ex);
-                return TextToSpeech.ERROR;
-            } finally {
-                cleanUp();
-            }
-        }
-
-        return TextToSpeech.SUCCESS;
-    }
-
-    private void blockUntilDone(AudioTrack audioTrack, int bytesPerFrame, int length) {
-        int lengthInFrames = length / bytesPerFrame;
-        int currentPosition = 0;
-        while ((currentPosition = audioTrack.getPlaybackHeadPosition()) < lengthInFrames) {
-            long estimatedTimeMs = ((lengthInFrames - currentPosition) * 1000) /
-                    audioTrack.getSampleRate();
-            if (DBG) Log.d(TAG, "About to sleep for : " + estimatedTimeMs + " ms," +
-                    " Playback position : " + currentPosition);
-            try {
-                Thread.sleep(estimatedTimeMs);
-            } catch (InterruptedException ie) {
-                break;
-            }
-        }
-    }
-
-    private int getBytesPerFrame(int audioFormat) {
-        if (audioFormat == AudioFormat.ENCODING_PCM_8BIT) {
-            return 1;
-        } else if (audioFormat == AudioFormat.ENCODING_PCM_16BIT) {
-            return 2;
-        }
-
-        return -1;
-    }
-
-    private int getChannelConfig(int channelCount) {
-        if (channelCount == 1) {
-            return AudioFormat.CHANNEL_OUT_MONO;
-        } else if (channelCount == 2){
-            return AudioFormat.CHANNEL_OUT_STEREO;
-        }
-
-        return -1;
-    }
-
-    private AudioTrack createStreamingAudioTrack(int sampleRateInHz, int audioFormat,
-            int channelCount) {
-        int channelConfig = getChannelConfig(channelCount);
-
-        if (channelConfig < 0) {
-            Log.e(TAG, "Unsupported number of channels : " + channelCount);
-            return null;
-        }
-
-        int minBufferSizeInBytes
-                = AudioTrack.getMinBufferSize(sampleRateInHz, channelConfig, audioFormat);
-        int bufferSizeInBytes = Math.max(MIN_AUDIO_BUFFER_SIZE, minBufferSizeInBytes);
-        AudioTrack audioTrack = new AudioTrack(mStreamType, sampleRateInHz, channelConfig,
-                audioFormat, bufferSizeInBytes, AudioTrack.MODE_STREAM);
-        if (audioTrack == null) {
-            return null;
-        }
-
-        if (audioTrack.getState() != AudioTrack.STATE_INITIALIZED) {
-            audioTrack.release();
-            return null;
-        }
-        setupVolume(audioTrack, mVolume, mPan);
-        return audioTrack;
-    }
-}
diff --git a/core/java/android/speech/tts/SilenceMessageParams.java b/core/java/android/speech/tts/SilenceMessageParams.java
new file mode 100644
index 0000000..7a4ff1c
--- /dev/null
+++ b/core/java/android/speech/tts/SilenceMessageParams.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package android.speech.tts;
+
+import android.os.ConditionVariable;
+import android.speech.tts.TextToSpeechService.UtteranceCompletedDispatcher;
+
+class SilenceMessageParams extends MessageParams {
+    private final ConditionVariable mCondVar = new ConditionVariable();
+    private final long mSilenceDurationMs;
+
+    SilenceMessageParams(UtteranceCompletedDispatcher dispatcher,
+            String callingApp, long silenceDurationMs) {
+        super(dispatcher, callingApp);
+        mSilenceDurationMs = silenceDurationMs;
+    }
+
+    long getSilenceDurationMs() {
+        return mSilenceDurationMs;
+    }
+
+    @Override
+    int getType() {
+        return TYPE_SILENCE;
+    }
+
+    ConditionVariable getConditionVariable() {
+        return mCondVar;
+    }
+
+}
diff --git a/core/java/android/speech/tts/SynthesisCallback.java b/core/java/android/speech/tts/SynthesisCallback.java
new file mode 100644
index 0000000..1b80e40
--- /dev/null
+++ b/core/java/android/speech/tts/SynthesisCallback.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package android.speech.tts;
+
+/**
+ * A callback to return speech data synthesized by a text to speech engine.
+ *
+ * The engine can provide streaming audio by calling
+ * {@link #start}, then {@link #audioAvailable} until all audio has been provided, then finally
+ * {@link #done}.
+ *
+ * Alternatively, the engine can provide all the audio at once, by using
+ * {@link #completeAudioAvailable}.
+ *
+ * {@link #error} can be called at any stage in the synthesis process to
+ * indicate that an error has occured, but if the call is made after a call
+ * to {@link #done} or {@link #completeAudioAvailable} it might be discarded.
+ */
+public interface SynthesisCallback {
+    /**
+     * @return the maximum number of bytes that the TTS engine can pass in a single call of
+     *         {@link #audioAvailable}. This does not apply to {@link #completeAudioAvailable}.
+     *         Calls to {@link #audioAvailable} with data lengths larger than this
+     *         value will not succeed.
+     */
+    public int getMaxBufferSize();
+
+    /**
+     * The service should call this when it starts to synthesize audio for this
+     * request.
+     *
+     * This method should only be called on the synthesis thread,
+     * while in {@link TextToSpeechService#onSynthesizeText}.
+     *
+     * @param sampleRateInHz Sample rate in HZ of the generated audio.
+     * @param audioFormat Audio format of the generated audio. Must be one of
+     *         the ENCODING_ constants defined in {@link android.media.AudioFormat}.
+     * @param channelCount The number of channels. Must be {@code 1} or {@code 2}.
+     * @return {@link TextToSpeech#SUCCESS} or {@link TextToSpeech#ERROR}.
+     */
+    public int start(int sampleRateInHz, int audioFormat, int channelCount);
+
+    /**
+     * The service should call this method when synthesized audio is ready for consumption.
+     *
+     * This method should only be called on the synthesis thread,
+     * while in {@link TextToSpeechService#onSynthesizeText}.
+     *
+     * @param buffer The generated audio data. This method will not hold on to {@code buffer},
+     *         so the caller is free to modify it after this method returns.
+     * @param offset The offset into {@code buffer} where the audio data starts.
+     * @param length The number of bytes of audio data in {@code buffer}. This must be
+     *         less than or equal to the return value of {@link #getMaxBufferSize}.
+     * @return {@link TextToSpeech#SUCCESS} or {@link TextToSpeech#ERROR}.
+     */
+    public int audioAvailable(byte[] buffer, int offset, int length);
+
+    /**
+     * The service can call this method instead of using {@link #start}, {@link #audioAvailable}
+     * and {@link #done} if all the audio data is available in a single buffer.
+     *
+     * @param sampleRateInHz Sample rate in HZ of the generated audio.
+     * @param audioFormat Audio format of the generated audio. Must be one of
+     *         the ENCODING_ constants defined in {@link android.media.AudioFormat}.
+     * @param channelCount The number of channels. Must be {@code 1} or {@code 2}.
+     * @param buffer The generated audio data. This method will not hold on to {@code buffer},
+     *         so the caller is free to modify it after this method returns.
+     * @param offset The offset into {@code buffer} where the audio data starts.
+     * @param length The number of bytes of audio data in {@code buffer}.
+     * @return {@link TextToSpeech#SUCCESS} or {@link TextToSpeech#ERROR}.
+     */
+    public int completeAudioAvailable(int sampleRateInHz, int audioFormat,
+            int channelCount, byte[] buffer, int offset, int length);
+
+    /**
+     * The service should call this method when all the synthesized audio for a request has
+     * been passed to {@link #audioAvailable}.
+     *
+     * This method should only be called on the synthesis thread,
+     * while in {@link TextToSpeechService#onSynthesizeText}.
+     *
+     * @return {@link TextToSpeech#SUCCESS} or {@link TextToSpeech#ERROR}.
+     */
+    public int done();
+
+    /**
+     * The service should call this method if the speech synthesis fails.
+     *
+     * This method should only be called on the synthesis thread,
+     * while in {@link TextToSpeechService#onSynthesizeText}.
+     */
+    public void error();
+
+}
\ No newline at end of file
diff --git a/core/java/android/speech/tts/SynthesisMessageParams.java b/core/java/android/speech/tts/SynthesisMessageParams.java
new file mode 100644
index 0000000..51f3d2e
--- /dev/null
+++ b/core/java/android/speech/tts/SynthesisMessageParams.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package android.speech.tts;
+
+import android.media.AudioTrack;
+import android.speech.tts.TextToSpeechService.UtteranceCompletedDispatcher;
+
+import java.util.LinkedList;
+
+/**
+ * Params required to play back a synthesis request.
+ */
+final class SynthesisMessageParams extends MessageParams {
+    final int mStreamType;
+    final int mSampleRateInHz;
+    final int mAudioFormat;
+    final int mChannelCount;
+    final float mVolume;
+    final float mPan;
+
+    public volatile AudioTrack mAudioTrack;
+
+    private final LinkedList<ListEntry> mDataBufferList = new LinkedList<ListEntry>();
+
+    SynthesisMessageParams(int streamType, int sampleRate,
+            int audioFormat, int channelCount,
+            float volume, float pan, UtteranceCompletedDispatcher dispatcher,
+            String callingApp) {
+        super(dispatcher, callingApp);
+
+        mStreamType = streamType;
+        mSampleRateInHz = sampleRate;
+        mAudioFormat = audioFormat;
+        mChannelCount = channelCount;
+        mVolume = volume;
+        mPan = pan;
+
+        // initially null.
+        mAudioTrack = null;
+    }
+
+    @Override
+    int getType() {
+        return TYPE_SYNTHESIS;
+    }
+
+    synchronized void addBuffer(byte[] buffer, int offset, int length) {
+        mDataBufferList.add(new ListEntry(buffer, offset, length));
+    }
+
+    synchronized void addBuffer(byte[] buffer) {
+        mDataBufferList.add(new ListEntry(buffer, 0, buffer.length));
+    }
+
+    synchronized ListEntry getNextBuffer() {
+        return mDataBufferList.poll();
+    }
+
+
+    void setAudioTrack(AudioTrack audioTrack) {
+        mAudioTrack = audioTrack;
+    }
+
+    AudioTrack getAudioTrack() {
+        return mAudioTrack;
+    }
+
+    static final class ListEntry {
+        final byte[] mBytes;
+        final int mOffset;
+        final int mLength;
+
+        ListEntry(byte[] bytes, int offset, int length) {
+            mBytes = bytes;
+            mOffset = offset;
+            mLength = length;
+        }
+    }
+}
+
diff --git a/core/java/android/speech/tts/SynthesisRequest.java b/core/java/android/speech/tts/SynthesisRequest.java
index 57ae10d..6398d3d 100644
--- a/core/java/android/speech/tts/SynthesisRequest.java
+++ b/core/java/android/speech/tts/SynthesisRequest.java
@@ -18,17 +18,22 @@
 import android.os.Bundle;
 
 /**
- * A request for speech synthesis given to a TTS engine for processing.
+ * Contains data required by engines to synthesize speech. This data is :
+ * <ul>
+ *   <li>The text to synthesize</li>
+ *   <li>The synthesis locale, represented as a language, country and a variant.
+ *   The language is an ISO 639-3 letter language code, and the country is an
+ *   ISO 3166 alpha 3 code. The variant is not specified.</li>
+ *   <li>The synthesis speech rate, with 100 being the normal, and
+ *   higher values representing higher speech rates.</li>
+ *   <li>The voice pitch, with 100 being the default pitch.</li>
+ * </ul>
  *
- * The engine can provide streaming audio by calling
- * {@link #start}, then {@link #audioAvailable} until all audio has been provided, then finally
- * {@link #done}.
- *
- * Alternatively, the engine can provide all the audio at once, by using
- * {@link #completeAudioAvailable}.
+ * Any additional parameters sent to the text to speech service are passed in
+ * uninterpreted, see the @code{params} argument in {@link TextToSpeech#speak}
+ * and {@link TextToSpeech#synthesizeToFile}.
  */
-public abstract class SynthesisRequest {
-
+public final class SynthesisRequest {
     private final String mText;
     private final Bundle mParams;
     private String mLanguage;
@@ -39,33 +44,11 @@
 
     public SynthesisRequest(String text, Bundle params) {
         mText = text;
+        // Makes a copy of params.
         mParams = new Bundle(params);
     }
 
     /**
-     * Sets the locale for the request.
-     */
-    void setLanguage(String language, String country, String variant) {
-        mLanguage = language;
-        mCountry = country;
-        mVariant = variant;
-    }
-
-    /**
-     * Sets the speech rate.
-     */
-    void setSpeechRate(int speechRate) {
-        mSpeechRate = speechRate;
-    }
-
-    /**
-     * Sets the pitch.
-     */
-    void setPitch(int pitch) {
-        mPitch = pitch;
-    }
-
-    /**
      * Gets the text which should be synthesized.
      */
     public String getText() {
@@ -115,86 +98,25 @@
     }
 
     /**
-     * Gets the maximum number of bytes that the TTS engine can pass in a single call of
-     * {@link #audioAvailable}. This does not apply to {@link #completeAudioAvailable}.
+     * Sets the locale for the request.
      */
-    public abstract int getMaxBufferSize();
+    void setLanguage(String language, String country, String variant) {
+        mLanguage = language;
+        mCountry = country;
+        mVariant = variant;
+    }
 
     /**
-     * Checks whether the synthesis request completed successfully.
+     * Sets the speech rate.
      */
-    abstract boolean isDone();
+    void setSpeechRate(int speechRate) {
+        mSpeechRate = speechRate;
+    }
 
     /**
-     * Aborts the speech request.
-     *
-     * Can be called from multiple threads.
+     * Sets the pitch.
      */
-    abstract void stop();
-
-    /**
-     * The service should call this when it starts to synthesize audio for this
-     * request.
-     *
-     * This method should only be called on the synthesis thread,
-     * while in {@link TextToSpeechService#onSynthesizeText}.
-     *
-     * @param sampleRateInHz Sample rate in HZ of the generated audio.
-     * @param audioFormat Audio format of the generated audio. Must be one of
-     *         the ENCODING_ constants defined in {@link android.media.AudioFormat}.
-     * @param channelCount The number of channels. Must be {@code 1} or {@code 2}.
-     * @return {@link TextToSpeech#SUCCESS} or {@link TextToSpeech#ERROR}.
-     */
-    public abstract int start(int sampleRateInHz, int audioFormat, int channelCount);
-
-    /**
-     * The service should call this method when synthesized audio is ready for consumption.
-     *
-     * This method should only be called on the synthesis thread,
-     * while in {@link TextToSpeechService#onSynthesizeText}.
-     *
-     * @param buffer The generated audio data. This method will not hold on to {@code buffer},
-     *         so the caller is free to modify it after this method returns.
-     * @param offset The offset into {@code buffer} where the audio data starts.
-     * @param length The number of bytes of audio data in {@code buffer}. This must be
-     *         less than or equal to the return value of {@link #getMaxBufferSize}.
-     * @return {@link TextToSpeech#SUCCESS} or {@link TextToSpeech#ERROR}.
-     */
-    public abstract int audioAvailable(byte[] buffer, int offset, int length);
-
-    /**
-     * The service should call this method when all the synthesized audio for a request has
-     * been passed to {@link #audioAvailable}.
-     *
-     * This method should only be called on the synthesis thread,
-     * while in {@link TextToSpeechService#onSynthesizeText}.
-     *
-     * @return {@link TextToSpeech#SUCCESS} or {@link TextToSpeech#ERROR}.
-     */
-    public abstract int done();
-
-    /**
-     * The service should call this method if the speech synthesis fails.
-     *
-     * This method should only be called on the synthesis thread,
-     * while in {@link TextToSpeechService#onSynthesizeText}.
-     */
-    public abstract void error();
-
-    /**
-     * The service can call this method instead of using {@link #start}, {@link #audioAvailable}
-     * and {@link #done} if all the audio data is available in a single buffer.
-     *
-     * @param sampleRateInHz Sample rate in HZ of the generated audio.
-     * @param audioFormat Audio format of the generated audio. Must be one of
-     *         the ENCODING_ constants defined in {@link android.media.AudioFormat}.
-     * @param channelCount The number of channels. Must be {@code 1} or {@code 2}.
-     * @param buffer The generated audio data. This method will not hold on to {@code buffer},
-     *         so the caller is free to modify it after this method returns.
-     * @param offset The offset into {@code buffer} where the audio data starts.
-     * @param length The number of bytes of audio data in {@code buffer}.
-     * @return {@link TextToSpeech#SUCCESS} or {@link TextToSpeech#ERROR}.
-     */
-    public abstract int completeAudioAvailable(int sampleRateInHz, int audioFormat,
-            int channelCount, byte[] buffer, int offset, int length);
-}
\ No newline at end of file
+    void setPitch(int pitch) {
+        mPitch = pitch;
+    }
+}
diff --git a/core/java/android/speech/tts/TextToSpeech.java b/core/java/android/speech/tts/TextToSpeech.java
index 4b19469..40e9355 100755
--- a/core/java/android/speech/tts/TextToSpeech.java
+++ b/core/java/android/speech/tts/TextToSpeech.java
@@ -22,9 +22,6 @@
 import android.content.Context;
 import android.content.Intent;
 import android.content.ServiceConnection;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.content.pm.ServiceInfo;
 import android.media.AudioManager;
 import android.net.Uri;
 import android.os.Bundle;
@@ -34,8 +31,6 @@
 import android.text.TextUtils;
 import android.util.Log;
 
-import java.util.ArrayList;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Locale;
@@ -67,12 +62,22 @@
     /**
      * Queue mode where all entries in the playback queue (media to be played
      * and text to be synthesized) are dropped and replaced by the new entry.
+     * Queues are flushed with respect to a given calling app. Entries in the queue
+     * from other callees are not discarded.
      */
     public static final int QUEUE_FLUSH = 0;
     /**
      * Queue mode where the new entry is added at the end of the playback queue.
      */
     public static final int QUEUE_ADD = 1;
+    /**
+     * Queue mode where the entire playback queue is purged. This is different
+     * from {@link #QUEUE_FLUSH} in that all entries are purged, not just entries
+     * from a given caller.
+     *
+     * @hide
+     */
+    static final int QUEUE_DESTROY = 2;
 
     /**
      * Denotes the language is available exactly as specified by the locale.
@@ -174,10 +179,14 @@
         /**
          * Package name of the default TTS engine.
          *
-         * TODO: This should come from a system property
-         *
          * @hide
+         * @deprecated No longer in use, the default engine is determined by
+         *         the sort order defined in {@link EngineInfoComparator}. Note that
+         *         this doesn't "break" anything because there is no guarantee that
+         *         the engine specified below is installed on a given build, let
+         *         alone be the default.
          */
+        @Deprecated
         public static final String DEFAULT_ENGINE = "com.svox.pico";
 
         /**
@@ -424,6 +433,7 @@
     private final Map<String, Uri> mEarcons;
     private final Map<String, Uri> mUtterances;
     private final Bundle mParams = new Bundle();
+    private final TtsEngines mEnginesHelper;
     private String mCurrentEngine = null;
 
     /**
@@ -459,6 +469,7 @@
         mEarcons = new HashMap<String, Uri>();
         mUtterances = new HashMap<String, Uri>();
 
+        mEnginesHelper = new TtsEngines(mContext);
         initTts();
     }
 
@@ -487,31 +498,35 @@
     private int initTts() {
         String defaultEngine = getDefaultEngine();
         String engine = defaultEngine;
-        if (!areDefaultsEnforced() && !TextUtils.isEmpty(mRequestedEngine)
-                && isEngineEnabled(engine)) {
+        if (mEnginesHelper.isEngineInstalled(mRequestedEngine)) {
             engine = mRequestedEngine;
         }
 
         // Try requested engine
         if (connectToEngine(engine)) {
+            mCurrentEngine = engine;
             return SUCCESS;
         }
 
         // Fall back to user's default engine if different from the already tested one
         if (!engine.equals(defaultEngine)) {
             if (connectToEngine(defaultEngine)) {
+                mCurrentEngine = engine;
                 return SUCCESS;
             }
         }
 
+        final String highestRanked = mEnginesHelper.getHighestRankedEngineName();
         // Fall back to the hardcoded default if different from the two above
-        if (!defaultEngine.equals(Engine.DEFAULT_ENGINE)
-                && !engine.equals(Engine.DEFAULT_ENGINE)) {
-            if (connectToEngine(Engine.DEFAULT_ENGINE)) {
+        if (!defaultEngine.equals(highestRanked)
+                && !engine.equals(highestRanked)) {
+            if (connectToEngine(highestRanked)) {
+                mCurrentEngine = engine;
                 return SUCCESS;
             }
         }
 
+        dispatchOnInit(ERROR);
         return ERROR;
     }
 
@@ -522,10 +537,9 @@
         boolean bound = mContext.bindService(intent, connection, Context.BIND_AUTO_CREATE);
         if (!bound) {
             Log.e(TAG, "Failed to bind to " + engine);
-            dispatchOnInit(ERROR);
             return false;
         } else {
-            mCurrentEngine = engine;
+            Log.i(TAG, "Sucessfully bound to " + engine);
             return true;
         }
     }
@@ -1040,13 +1054,15 @@
     /**
      * Sets the TTS engine to use.
      *
+     * @deprecated This doesn't inform callers when the TTS engine has been
+     *        initialized. {@link #TextToSpeech(Context, OnInitListener, String)}
+     *        can be used with the appropriate engine name.
+     *
      * @param enginePackageName The package name for the synthesis engine (e.g. "com.svox.pico")
      *
      * @return {@link #ERROR} or {@link #SUCCESS}.
      */
-    // TODO: add @Deprecated{This method does not tell the caller when the new engine
-    // has been initialized. You should create a new TextToSpeech object with the new
-    // engine instead.}
+    @Deprecated
     public int setEngineByPackageName(String enginePackageName) {
         mRequestedEngine = enginePackageName;
         return initTts();
@@ -1055,72 +1071,32 @@
     /**
      * Gets the package name of the default speech synthesis engine.
      *
-     * @return Package name of the TTS engine that the user has chosen as their default.
+     * @return Package name of the TTS engine that the user has chosen
+     *        as their default.
      */
     public String getDefaultEngine() {
-        String engine = Settings.Secure.getString(mContext.getContentResolver(),
-                Settings.Secure.TTS_DEFAULT_SYNTH);
-        return engine != null ? engine : Engine.DEFAULT_ENGINE;
+        return mEnginesHelper.getDefaultEngine();
     }
 
     /**
-     * Checks whether the user's settings should override settings requested by the calling
-     * application.
+     * Checks whether the user's settings should override settings requested
+     * by the calling application. As of the Ice cream sandwich release,
+     * user settings never forcibly override the app's settings.
      */
     public boolean areDefaultsEnforced() {
-        return Settings.Secure.getInt(mContext.getContentResolver(),
-                Settings.Secure.TTS_USE_DEFAULTS, Engine.USE_DEFAULTS) == 1;
-    }
-
-    private boolean isEngineEnabled(String engine) {
-        if (Engine.DEFAULT_ENGINE.equals(engine)) {
-            return true;
-        }
-        for (String enabled : getEnabledEngines()) {
-            if (engine.equals(enabled)) {
-                return true;
-            }
-        }
         return false;
     }
 
-    private String[] getEnabledEngines() {
-        String str = Settings.Secure.getString(mContext.getContentResolver(),
-                Settings.Secure.TTS_ENABLED_PLUGINS);
-        if (TextUtils.isEmpty(str)) {
-            return new String[0];
-        }
-        return str.split(" ");
-    }
-
     /**
      * Gets a list of all installed TTS engines.
      *
-     * @return A list of engine info objects. The list can be empty, but will never by {@code null}.
+     * @return A list of engine info objects. The list can be empty, but never {@code null}.
      */
     public List<EngineInfo> getEngines() {
-        PackageManager pm = mContext.getPackageManager();
-        Intent intent = new Intent(Engine.INTENT_ACTION_TTS_SERVICE);
-        List<ResolveInfo> resolveInfos =
-                pm.queryIntentServices(intent, PackageManager.MATCH_DEFAULT_ONLY);
-        if (resolveInfos == null) return Collections.emptyList();
-        List<EngineInfo> engines = new ArrayList<EngineInfo>(resolveInfos.size());
-        for (ResolveInfo resolveInfo : resolveInfos) {
-            ServiceInfo service = resolveInfo.serviceInfo;
-            if (service != null) {
-                EngineInfo engine = new EngineInfo();
-                // Using just the package name isn't great, since it disallows having
-                // multiple engines in the same package, but that's what the existing API does.
-                engine.name = service.packageName;
-                CharSequence label = service.loadLabel(pm);
-                engine.label = TextUtils.isEmpty(label) ? engine.name : label.toString();
-                engine.icon = service.getIconResource();
-                engines.add(engine);
-            }
-        }
-        return engines;
+        return mEnginesHelper.getEngines();
     }
 
+
     private class Connection implements ServiceConnection {
         private ITextToSpeechService mService;
 
@@ -1193,6 +1169,20 @@
          * Icon for the engine.
          */
         public int icon;
+        /**
+         * Whether this engine is a part of the system
+         * image.
+         *
+         * @hide
+         */
+        public boolean system;
+        /**
+         * The priority the engine declares for the the intent filter
+         * {@code android.intent.action.TTS_SERVICE}
+         *
+         * @hide
+         */
+        public int priority;
 
         @Override
         public String toString() {
@@ -1200,4 +1190,5 @@
         }
 
     }
+
 }
diff --git a/core/java/android/speech/tts/TextToSpeechService.java b/core/java/android/speech/tts/TextToSpeechService.java
index 717dde8..7ea9373 100644
--- a/core/java/android/speech/tts/TextToSpeechService.java
+++ b/core/java/android/speech/tts/TextToSpeechService.java
@@ -19,7 +19,6 @@
 import android.content.Intent;
 import android.net.Uri;
 import android.os.Bundle;
-import android.os.ConditionVariable;
 import android.os.Handler;
 import android.os.HandlerThread;
 import android.os.IBinder;
@@ -40,8 +39,34 @@
 
 
 /**
- * Abstract base class for TTS engine implementations.
+ * Abstract base class for TTS engine implementations. The following methods
+ * need to be implemented.
+ *
+ * <ul>
+ *   <li>{@link #onIsLanguageAvailable}</li>
+ *   <li>{@link #onLoadLanguage}</li>
+ *   <li>{@link #onGetLanguage}</li>
+ *   <li>{@link #onSynthesizeText}</li>
+ *   <li>{@link #onStop}</li>
+ * </ul>
+ *
+ * The first three deal primarily with language management, and are used to
+ * query the engine for it's support for a given language and indicate to it
+ * that requests in a given language are imminent.
+ *
+ * {@link #onSynthesizeText} is central to the engine implementation. The
+ * implementation should synthesize text as per the request parameters and
+ * return synthesized data via the supplied callback. This class and its helpers
+ * will then consume that data, which might mean queueing it for playback or writing
+ * it to a file or similar. All calls to this method will be on a single
+ * thread, which will be different from the main thread of the service. Synthesis
+ * must be synchronous which means the engine must NOT hold on the callback or call
+ * any methods on it after the method returns
+ *
+ * {@link #onStop} tells the engine that it should stop all ongoing synthesis, if
+ * any. Any pending data from the current synthesis will be discarded.
  */
+// TODO: Add a link to the sample TTS engine once it's done.
 public abstract class TextToSpeechService extends Service {
 
     private static final boolean DBG = false;
@@ -51,10 +76,15 @@
     private static final String SYNTH_THREAD_NAME = "SynthThread";
 
     private SynthHandler mSynthHandler;
-    private Handler mAudioTrackHandler;
+    // A thread and it's associated handler for playing back any audio
+    // associated with this TTS engine. Will handle all requests except synthesis
+    // to file requests, which occur on the synthesis thread.
+    private AudioPlaybackHandler mAudioPlaybackHandler;
 
     private CallbackMap mCallbacks;
 
+    private int mDefaultAvailability = TextToSpeech.LANG_NOT_SUPPORTED;
+
     @Override
     public void onCreate() {
         if (DBG) Log.d(TAG, "onCreate()");
@@ -64,14 +94,14 @@
         synthThread.start();
         mSynthHandler = new SynthHandler(synthThread.getLooper());
 
-        HandlerThread audioTrackThread = new HandlerThread("TTS.audioTrackThread");
-        audioTrackThread.start();
-        mAudioTrackHandler = new Handler(audioTrackThread.getLooper());
+        mAudioPlaybackHandler = new AudioPlaybackHandler();
+        mAudioPlaybackHandler.start();
 
         mCallbacks = new CallbackMap();
 
         // Load default language
-        onLoadLanguage(getDefaultLanguage(), getDefaultCountry(), getDefaultVariant());
+        mDefaultAvailability = onLoadLanguage(getDefaultLanguage(),
+                getDefaultCountry(), getDefaultVariant());
     }
 
     @Override
@@ -80,8 +110,8 @@
 
         // Tell the synthesizer to stop
         mSynthHandler.quit();
-        mAudioTrackHandler.getLooper().quit();
-
+        // Tell the audio playback thread to stop.
+        mAudioPlaybackHandler.quit();
         // Unregister all callbacks.
         mCallbacks.kill();
 
@@ -154,15 +184,12 @@
      *
      * Called on the synthesis thread.
      *
-     * @param request The synthesis request. The method should use the methods in the request
-     *         object to communicate the results of the synthesis.
+     * @param request The synthesis request.
+     * @param callback The callback the the engine must use to make data available for
+     *         playback or for writing to a file.
      */
-    protected abstract void onSynthesizeText(SynthesisRequest request);
-
-    private boolean areDefaultsEnforced() {
-        return getSecureSettingInt(Settings.Secure.TTS_USE_DEFAULTS,
-                TextToSpeech.Engine.USE_DEFAULTS) == 1;
-    }
+    protected abstract void onSynthesizeText(SynthesisRequest request,
+            SynthesisCallback callback);
 
     private int getDefaultSpeechRate() {
         return getSecureSettingInt(Settings.Secure.TTS_DEFAULT_RATE, Engine.DEFAULT_RATE);
@@ -233,13 +260,6 @@
             super(looper);
         }
 
-        private void dispatchUtteranceCompleted(SpeechItem item) {
-            String utteranceId = item.getUtteranceId();
-            if (!TextUtils.isEmpty(utteranceId)) {
-                mCallbacks.dispatchUtteranceCompleted(item.getCallingApp(), utteranceId);
-            }
-        }
-
         private synchronized SpeechItem getCurrentSpeechItem() {
             return mCurrentSpeechItem;
         }
@@ -273,24 +293,29 @@
             if (!speechItem.isValid()) {
                 return TextToSpeech.ERROR;
             }
-            // TODO: The old code also supported the undocumented queueMode == 2,
-            // which clears out all pending items from the calling app, as well as all
-            // non-file items from other apps.
+
             if (queueMode == TextToSpeech.QUEUE_FLUSH) {
                 stop(speechItem.getCallingApp());
+            } else if (queueMode == TextToSpeech.QUEUE_DESTROY) {
+                // Stop the current speech item.
+                stop(speechItem.getCallingApp());
+                // Remove all other items from the queue.
+                removeCallbacksAndMessages(null);
+                // Remove all pending playback as well.
+                mAudioPlaybackHandler.removeAllItems();
             }
             Runnable runnable = new Runnable() {
                 @Override
                 public void run() {
                     setCurrentSpeechItem(speechItem);
-                    if (speechItem.play() == TextToSpeech.SUCCESS) {
-                        dispatchUtteranceCompleted(speechItem);
-                    }
+                    speechItem.play();
                     setCurrentSpeechItem(null);
                 }
             };
             Message msg = Message.obtain(this, runnable);
             // The obj is used to remove all callbacks from the given app in stop(String).
+            //
+            // Note that this string is interned, so the == comparison works.
             msg.obj = speechItem.getCallingApp();
             if (sendMessage(msg)) {
                 return TextToSpeech.SUCCESS;
@@ -310,19 +335,28 @@
             if (TextUtils.isEmpty(callingApp)) {
                 return TextToSpeech.ERROR;
             }
+
             removeCallbacksAndMessages(callingApp);
             SpeechItem current = setCurrentSpeechItem(null);
             if (current != null && TextUtils.equals(callingApp, current.getCallingApp())) {
                 current.stop();
             }
+
+            // Remove any enqueued audio too.
+            mAudioPlaybackHandler.removePlaybackItems(callingApp);
+
             return TextToSpeech.SUCCESS;
         }
     }
 
+    interface UtteranceCompletedDispatcher {
+        public void dispatchUtteranceCompleted();
+    }
+
     /**
      * An item in the synth thread queue.
      */
-    private static abstract class SpeechItem {
+    private abstract class SpeechItem implements UtteranceCompletedDispatcher {
         private final String mCallingApp;
         protected final Bundle mParams;
         private boolean mStarted = false;
@@ -377,6 +411,13 @@
             stopImpl();
         }
 
+        public void dispatchUtteranceCompleted() {
+            final String utteranceId = getUtteranceId();
+            if (!TextUtils.isEmpty(utteranceId)) {
+                mCallbacks.dispatchUtteranceCompleted(getCallingApp(), utteranceId);
+            }
+        }
+
         protected abstract int playImpl();
 
         protected abstract void stopImpl();
@@ -410,13 +451,18 @@
         }
     }
 
-    private class SynthesisSpeechItem extends SpeechItem {
+    class SynthesisSpeechItem extends SpeechItem {
         private final String mText;
-        private SynthesisRequest mSynthesisRequest;
+        private final SynthesisRequest mSynthesisRequest;
+        // Non null after synthesis has started, and all accesses
+        // guarded by 'this'.
+        private AbstractSynthesisCallback mSynthesisCallback;
 
         public SynthesisSpeechItem(String callingApp, Bundle params, String text) {
             super(callingApp, params);
             mText = text;
+            mSynthesisRequest = new SynthesisRequest(mText, mParams);
+            setRequestParams(mSynthesisRequest);
         }
 
         public String getText() {
@@ -438,39 +484,34 @@
 
         @Override
         protected int playImpl() {
-            SynthesisRequest synthesisRequest;
+            AbstractSynthesisCallback synthesisCallback;
             synchronized (this) {
-                mSynthesisRequest = createSynthesisRequest();
-                synthesisRequest = mSynthesisRequest;
+                mSynthesisCallback = createSynthesisCallback();
+                synthesisCallback = mSynthesisCallback;
             }
-            setRequestParams(synthesisRequest);
-            TextToSpeechService.this.onSynthesizeText(synthesisRequest);
-            return synthesisRequest.isDone() ? TextToSpeech.SUCCESS : TextToSpeech.ERROR;
+            TextToSpeechService.this.onSynthesizeText(mSynthesisRequest, synthesisCallback);
+            return synthesisCallback.isDone() ? TextToSpeech.SUCCESS : TextToSpeech.ERROR;
         }
 
-        protected SynthesisRequest createSynthesisRequest() {
-            return new PlaybackSynthesisRequest(mText, mParams,
-                    getStreamType(), getVolume(), getPan(), mAudioTrackHandler);
+        protected AbstractSynthesisCallback createSynthesisCallback() {
+            return new PlaybackSynthesisCallback(getStreamType(), getVolume(), getPan(),
+                    mAudioPlaybackHandler, this, getCallingApp());
         }
 
         private void setRequestParams(SynthesisRequest request) {
-            if (areDefaultsEnforced()) {
-                request.setLanguage(getDefaultLanguage(), getDefaultCountry(), getDefaultVariant());
-                request.setSpeechRate(getDefaultSpeechRate());
-            } else {
-                request.setLanguage(getLanguage(), getCountry(), getVariant());
-                request.setSpeechRate(getSpeechRate());
-            }
+            request.setLanguage(getLanguage(), getCountry(), getVariant());
+            request.setSpeechRate(getSpeechRate());
+
             request.setPitch(getPitch());
         }
 
         @Override
         protected void stopImpl() {
-            SynthesisRequest synthesisRequest;
+            AbstractSynthesisCallback synthesisCallback;
             synchronized (this) {
-                synthesisRequest = mSynthesisRequest;
+                synthesisCallback = mSynthesisCallback;
             }
-            synthesisRequest.stop();
+            synthesisCallback.stop();
             TextToSpeechService.this.onStop();
         }
 
@@ -519,8 +560,17 @@
         }
 
         @Override
-        protected SynthesisRequest createSynthesisRequest() {
-            return new FileSynthesisRequest(getText(), mParams, mFile);
+        protected AbstractSynthesisCallback createSynthesisCallback() {
+            return new FileSynthesisCallback(mFile);
+        }
+
+        @Override
+        protected int playImpl() {
+            int status = super.playImpl();
+            if (status == TextToSpeech.SUCCESS) {
+                dispatchUtteranceCompleted();
+            }
+            return status;
         }
 
         /**
@@ -554,6 +604,7 @@
     private class AudioSpeechItem extends SpeechItem {
 
         private final BlockingMediaPlayer mPlayer;
+        private AudioMessageParams mToken;
 
         public AudioSpeechItem(String callingApp, Bundle params, Uri uri) {
             super(callingApp, params);
@@ -567,23 +618,26 @@
 
         @Override
         protected int playImpl() {
-            return mPlayer.startAndWait() ? TextToSpeech.SUCCESS : TextToSpeech.ERROR;
+            mToken = new AudioMessageParams(this, getCallingApp(), mPlayer);
+            mAudioPlaybackHandler.enqueueAudio(mToken);
+            return TextToSpeech.SUCCESS;
         }
 
         @Override
         protected void stopImpl() {
-            mPlayer.stop();
+            if (mToken != null) {
+                mAudioPlaybackHandler.stop(mToken);
+            }
         }
     }
 
     private class SilenceSpeechItem extends SpeechItem {
         private final long mDuration;
-        private final ConditionVariable mDone;
+        private SilenceMessageParams mToken;
 
         public SilenceSpeechItem(String callingApp, Bundle params, long duration) {
             super(callingApp, params);
             mDuration = duration;
-            mDone = new ConditionVariable();
         }
 
         @Override
@@ -593,13 +647,16 @@
 
         @Override
         protected int playImpl() {
-            boolean aborted = mDone.block(mDuration);
-            return aborted ? TextToSpeech.ERROR : TextToSpeech.SUCCESS;
+            mToken = new SilenceMessageParams(this, getCallingApp(), mDuration);
+            mAudioPlaybackHandler.enqueueSilence(mToken);
+            return TextToSpeech.SUCCESS;
         }
 
         @Override
         protected void stopImpl() {
-            mDone.open();
+            if (mToken != null) {
+                mAudioPlaybackHandler.stop(mToken);
+            }
         }
     }
 
@@ -615,27 +672,46 @@
      * Binder returned from {@code #onBind(Intent)}. The methods in this class can be
      * called called from several different threads.
      */
+    // NOTE: All calls that are passed in a calling app are interned so that
+    // they can be used as message objects (which are tested for equality using ==).
     private final ITextToSpeechService.Stub mBinder = new ITextToSpeechService.Stub() {
 
         public int speak(String callingApp, String text, int queueMode, Bundle params) {
-            SpeechItem item = new SynthesisSpeechItem(callingApp, params, text);
+            if (!checkNonNull(callingApp, text, params)) {
+                return TextToSpeech.ERROR;
+            }
+
+            SpeechItem item = new SynthesisSpeechItem(intern(callingApp), params, text);
             return mSynthHandler.enqueueSpeechItem(queueMode, item);
         }
 
         public int synthesizeToFile(String callingApp, String text, String filename,
                 Bundle params) {
+            if (!checkNonNull(callingApp, text, filename, params)) {
+                return TextToSpeech.ERROR;
+            }
+
             File file = new File(filename);
-            SpeechItem item = new SynthesisToFileSpeechItem(callingApp, params, text, file);
+            SpeechItem item = new SynthesisToFileSpeechItem(intern(callingApp),
+                    params, text, file);
             return mSynthHandler.enqueueSpeechItem(TextToSpeech.QUEUE_ADD, item);
         }
 
         public int playAudio(String callingApp, Uri audioUri, int queueMode, Bundle params) {
-            SpeechItem item = new AudioSpeechItem(callingApp, params, audioUri);
+            if (!checkNonNull(callingApp, audioUri, params)) {
+                return TextToSpeech.ERROR;
+            }
+
+            SpeechItem item = new AudioSpeechItem(intern(callingApp), params, audioUri);
             return mSynthHandler.enqueueSpeechItem(queueMode, item);
         }
 
         public int playSilence(String callingApp, long duration, int queueMode, Bundle params) {
-            SpeechItem item = new SilenceSpeechItem(callingApp, params, duration);
+            if (!checkNonNull(callingApp, params)) {
+                return TextToSpeech.ERROR;
+            }
+
+            SpeechItem item = new SilenceSpeechItem(intern(callingApp), params, duration);
             return mSynthHandler.enqueueSpeechItem(queueMode, item);
         }
 
@@ -644,24 +720,65 @@
         }
 
         public int stop(String callingApp) {
-            return mSynthHandler.stop(callingApp);
+            if (!checkNonNull(callingApp)) {
+                return TextToSpeech.ERROR;
+            }
+
+            return mSynthHandler.stop(intern(callingApp));
         }
 
         public String[] getLanguage() {
             return onGetLanguage();
         }
 
+        /*
+         * If defaults are enforced, then no language is "available" except
+         * perhaps the default language selected by the user.
+         */
         public int isLanguageAvailable(String lang, String country, String variant) {
+            if (!checkNonNull(lang)) {
+                return TextToSpeech.ERROR;
+            }
+
             return onIsLanguageAvailable(lang, country, variant);
         }
 
+        /*
+         * There is no point loading a non default language if defaults
+         * are enforced.
+         */
         public int loadLanguage(String lang, String country, String variant) {
+            if (!checkNonNull(lang)) {
+                return TextToSpeech.ERROR;
+            }
+
             return onLoadLanguage(lang, country, variant);
         }
 
         public void setCallback(String packageName, ITextToSpeechCallback cb) {
+            // Note that passing in a null callback is a valid use case.
+            if (!checkNonNull(packageName)) {
+                return;
+            }
+
             mCallbacks.setCallback(packageName, cb);
         }
+
+        private boolean isDefault(String lang, String country, String variant) {
+            return Locale.getDefault().equals(new Locale(lang, country, variant));
+        }
+
+        private String intern(String in) {
+            // The input parameter will be non null.
+            return in.intern();
+        }
+
+        private boolean checkNonNull(Object... args) {
+            for (Object o : args) {
+                if (o == null) return false;
+            }
+            return true;
+        }
     };
 
     private class CallbackMap extends RemoteCallbackList<ITextToSpeechCallback> {
diff --git a/core/java/android/speech/tts/TtsEngines.java b/core/java/android/speech/tts/TtsEngines.java
new file mode 100644
index 0000000..ed9e048
--- /dev/null
+++ b/core/java/android/speech/tts/TtsEngines.java
@@ -0,0 +1,187 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package android.speech.tts;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.content.pm.ServiceInfo;
+import android.provider.Settings;
+import android.speech.tts.TextToSpeech.Engine;
+import android.speech.tts.TextToSpeech.EngineInfo;
+import android.text.TextUtils;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+/**
+ * Support class for querying the list of available engines
+ * on the device and deciding which one to use etc.
+ *
+ * Comments in this class the use the shorthand "system engines" for engines that
+ * are a part of the system image.
+ *
+ * @hide
+ */
+public class TtsEngines {
+    private final Context mContext;
+
+    public TtsEngines(Context ctx) {
+        mContext = ctx;
+    }
+
+    /**
+     * @return the default TTS engine. If the user has set a default, and the engine
+     *         is available on the device, the default is returned. Otherwise,
+     *         the highest ranked engine is returned as per {@link EngineInfoComparator}.
+     */
+    public String getDefaultEngine() {
+        String engine = Settings.Secure.getString(mContext.getContentResolver(),
+                Settings.Secure.TTS_DEFAULT_SYNTH);
+        return isEngineInstalled(engine) ? engine : getHighestRankedEngineName();
+    }
+
+    /**
+     * @return the package name of the highest ranked system engine, {@code null}
+     *         if no TTS engines were present in the system image.
+     */
+    public String getHighestRankedEngineName() {
+        final List<EngineInfo> engines = getEngines();
+
+        if (engines.size() > 0 && engines.get(0).system) {
+            return engines.get(0).name;
+        }
+
+        return null;
+    }
+
+    /**
+     * Returns the engine info for a given engine name. Note that engines are
+     * identified by their package name.
+     */
+    public EngineInfo getEngineInfo(String packageName) {
+        PackageManager pm = mContext.getPackageManager();
+        Intent intent = new Intent(Engine.INTENT_ACTION_TTS_SERVICE);
+        intent.setPackage(packageName);
+        List<ResolveInfo> resolveInfos = pm.queryIntentServices(intent,
+                PackageManager.MATCH_DEFAULT_ONLY);
+        // Note that the current API allows only one engine per
+        // package name. Since the "engine name" is the same as
+        // the package name.
+        if (resolveInfos != null && resolveInfos.size() == 1) {
+            return getEngineInfo(resolveInfos.get(0), pm);
+        }
+
+        return null;
+    }
+
+    /**
+     * Gets a list of all installed TTS engines.
+     *
+     * @return A list of engine info objects. The list can be empty, but never {@code null}.
+     */
+    public List<EngineInfo> getEngines() {
+        PackageManager pm = mContext.getPackageManager();
+        Intent intent = new Intent(Engine.INTENT_ACTION_TTS_SERVICE);
+        List<ResolveInfo> resolveInfos =
+                pm.queryIntentServices(intent, PackageManager.MATCH_DEFAULT_ONLY);
+        if (resolveInfos == null) return Collections.emptyList();
+
+        List<EngineInfo> engines = new ArrayList<EngineInfo>(resolveInfos.size());
+
+        for (ResolveInfo resolveInfo : resolveInfos) {
+            EngineInfo engine = getEngineInfo(resolveInfo, pm);
+            if (engine != null) {
+                engines.add(engine);
+            }
+        }
+        Collections.sort(engines, EngineInfoComparator.INSTANCE);
+
+        return engines;
+    }
+
+    // TODO: Used only by the settings app. Remove once
+    // the settings UI change has been finalized.
+    public boolean isEngineEnabled(String engine) {
+        return isEngineInstalled(engine);
+    }
+
+    private boolean isSystemEngine(ServiceInfo info) {
+        final ApplicationInfo appInfo = info.applicationInfo;
+        return appInfo != null && (appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
+    }
+
+    /**
+     * @return true if a given engine is installed on the system.
+     */
+    public boolean isEngineInstalled(String engine) {
+        if (engine == null) {
+            return false;
+        }
+
+        return getEngineInfo(engine) != null;
+    }
+
+    private EngineInfo getEngineInfo(ResolveInfo resolve, PackageManager pm) {
+        ServiceInfo service = resolve.serviceInfo;
+        if (service != null) {
+            EngineInfo engine = new EngineInfo();
+            // Using just the package name isn't great, since it disallows having
+            // multiple engines in the same package, but that's what the existing API does.
+            engine.name = service.packageName;
+            CharSequence label = service.loadLabel(pm);
+            engine.label = TextUtils.isEmpty(label) ? engine.name : label.toString();
+            engine.icon = service.getIconResource();
+            engine.priority = resolve.priority;
+            engine.system = isSystemEngine(service);
+            return engine;
+        }
+
+        return null;
+    }
+
+    private static class EngineInfoComparator implements Comparator<EngineInfo> {
+        private EngineInfoComparator() { }
+
+        static EngineInfoComparator INSTANCE = new EngineInfoComparator();
+
+        /**
+         * Engines that are a part of the system image are always lesser
+         * than those that are not. Within system engines / non system engines
+         * the engines are sorted in order of their declared priority.
+         */
+        @Override
+        public int compare(EngineInfo lhs, EngineInfo rhs) {
+            if (lhs.system && !rhs.system) {
+                return -1;
+            } else if (rhs.system && !lhs.system) {
+                return 1;
+            } else {
+                // Either both system engines, or both non system
+                // engines.
+                //
+                // Note, this isn't a typo. Higher priority numbers imply
+                // higher priority, but are "lower" in the sort order.
+                return rhs.priority - lhs.priority;
+            }
+        }
+    }
+
+}
diff --git a/core/java/android/text/method/WordIterator.java b/core/java/android/text/method/WordIterator.java
index b250414..af524ee 100644
--- a/core/java/android/text/method/WordIterator.java
+++ b/core/java/android/text/method/WordIterator.java
@@ -213,7 +213,8 @@
 
     private void checkOffsetIsValid(int offset) {
         if (offset < 0 || offset > mCurrent.length()) {
-            final String message = "Valid range is [0, " + mCurrent.length() + "]";
+            final String message = "Invalid offset: " + offset +
+                    ". Valid range is [0, " + mCurrent.length() + "]";
             throw new IllegalArgumentException(message);
         }
     }
diff --git a/core/java/android/util/CalendarUtils.java b/core/java/android/util/CalendarUtils.java
deleted file mode 100644
index b2b4897..0000000
--- a/core/java/android/util/CalendarUtils.java
+++ /dev/null
@@ -1,348 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.util;
-
-import android.content.AsyncQueryHandler;
-import android.content.ContentResolver;
-import android.content.ContentValues;
-import android.content.Context;
-import android.content.SharedPreferences;
-import android.database.Cursor;
-import android.provider.Calendar.CalendarCache;
-import android.text.TextUtils;
-import android.text.format.DateUtils;
-import android.text.format.Time;
-
-import java.util.Formatter;
-import java.util.HashSet;
-import java.util.Locale;
-
-/**
- * A class containing utility methods related to Calendar apps.
- *
- * @hide
- */
-public class CalendarUtils {
-    private static final boolean DEBUG = false;
-    private static final String TAG = "CalendarUtils";
-
-    /**
-     * This class contains methods specific to reading and writing time zone
-     * values.
-     */
-    public static class TimeZoneUtils {
-        private static final String[] TIMEZONE_TYPE_ARGS = { CalendarCache.TIMEZONE_KEY_TYPE };
-        private static final String[] TIMEZONE_INSTANCES_ARGS =
-                { CalendarCache.TIMEZONE_KEY_INSTANCES };
-
-        private static StringBuilder mSB = new StringBuilder(50);
-        private static Formatter mF = new Formatter(mSB, Locale.getDefault());
-        private volatile static boolean mFirstTZRequest = true;
-        private volatile static boolean mTZQueryInProgress = false;
-
-        private volatile static boolean mUseHomeTZ = false;
-        private volatile static String mHomeTZ = Time.getCurrentTimezone();
-
-        private static HashSet<Runnable> mTZCallbacks = new HashSet<Runnable>();
-        private static int mToken = 1;
-        private static AsyncTZHandler mHandler;
-
-        // The name of the shared preferences file. This name must be maintained for historical
-        // reasons, as it's what PreferenceManager assigned the first time the file was created.
-        private final String mPrefsName;
-
-        /**
-         * This is the key used for writing whether or not a home time zone should
-         * be used in the Calendar app to the Calendar Preferences.
-         */
-        public static final String KEY_HOME_TZ_ENABLED = "preferences_home_tz_enabled";
-        /**
-         * This is the key used for writing the time zone that should be used if
-         * home time zones are enabled for the Calendar app.
-         */
-        public static final String KEY_HOME_TZ = "preferences_home_tz";
-
-        /**
-         * This is a helper class for handling the async queries and updates for the
-         * time zone settings in Calendar.
-         */
-        private class AsyncTZHandler extends AsyncQueryHandler {
-            public AsyncTZHandler(ContentResolver cr) {
-                super(cr);
-            }
-
-            @Override
-            protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
-                synchronized (mTZCallbacks) {
-                    if (cursor == null) {
-                        mTZQueryInProgress = false;
-                        mFirstTZRequest = true;
-                        return;
-                    }
-
-                    boolean writePrefs = false;
-                    // Check the values in the db
-                    int keyColumn = cursor.getColumnIndexOrThrow(CalendarCache.KEY);
-                    int valueColumn = cursor.getColumnIndexOrThrow(CalendarCache.VALUE);
-                    while(cursor.moveToNext()) {
-                        String key = cursor.getString(keyColumn);
-                        String value = cursor.getString(valueColumn);
-                        if (TextUtils.equals(key, CalendarCache.TIMEZONE_KEY_TYPE)) {
-                            boolean useHomeTZ = !TextUtils.equals(
-                                    value, CalendarCache.TIMEZONE_TYPE_AUTO);
-                            if (useHomeTZ != mUseHomeTZ) {
-                                writePrefs = true;
-                                mUseHomeTZ = useHomeTZ;
-                            }
-                        } else if (TextUtils.equals(
-                                key, CalendarCache.TIMEZONE_KEY_INSTANCES_PREVIOUS)) {
-                            if (!TextUtils.isEmpty(value) && !TextUtils.equals(mHomeTZ, value)) {
-                                writePrefs = true;
-                                mHomeTZ = value;
-                            }
-                        }
-                    }
-                    cursor.close();
-                    if (writePrefs) {
-                        SharedPreferences prefs = getSharedPreferences((Context)cookie, mPrefsName);
-                        // Write the prefs
-                        setSharedPreference(prefs, KEY_HOME_TZ_ENABLED, mUseHomeTZ);
-                        setSharedPreference(prefs, KEY_HOME_TZ, mHomeTZ);
-                    }
-
-                    mTZQueryInProgress = false;
-                    for (Runnable callback : mTZCallbacks) {
-                        if (callback != null) {
-                            callback.run();
-                        }
-                    }
-                    mTZCallbacks.clear();
-                }
-            }
-        }
-
-        /**
-         * The name of the file where the shared prefs for Calendar are stored
-         * must be provided. All activities within an app should provide the
-         * same preferences name or behavior may become erratic.
-         *
-         * @param prefsName
-         */
-        public TimeZoneUtils(String prefsName) {
-            mPrefsName = prefsName;
-        }
-
-        /**
-         * Formats a date or a time range according to the local conventions.
-         *
-         * This formats a date/time range using Calendar's time zone and the
-         * local conventions for the region of the device.
-         *
-         * If the {@link DateUtils#FORMAT_UTC} flag is used it will pass in
-         * the UTC time zone instead.
-         *
-         * @param context the context is required only if the time is shown
-         * @param startMillis the start time in UTC milliseconds
-         * @param endMillis the end time in UTC milliseconds
-         * @param flags a bit mask of options See
-         * {@link DateUtils#formatDateRange(Context, Formatter, long, long, int, String) formatDateRange}
-         * @return a string containing the formatted date/time range.
-         */
-        public String formatDateRange(Context context, long startMillis,
-                long endMillis, int flags) {
-            String date;
-            String tz;
-            if ((flags & DateUtils.FORMAT_UTC) != 0) {
-                tz = Time.TIMEZONE_UTC;
-            } else {
-                tz = getTimeZone(context, null);
-            }
-            synchronized (mSB) {
-                mSB.setLength(0);
-                date = DateUtils.formatDateRange(context, mF, startMillis, endMillis, flags,
-                        tz).toString();
-            }
-            return date;
-        }
-
-        /**
-         * Writes a new home time zone to the db.
-         *
-         * Updates the home time zone in the db asynchronously and updates
-         * the local cache. Sending a time zone of
-         * {@link CalendarCache#TIMEZONE_TYPE_AUTO} will cause it to be set
-         * to the device's time zone. null or empty tz will be ignored.
-         *
-         * @param context The calling activity
-         * @param timeZone The time zone to set Calendar to, or
-         * {@link CalendarCache#TIMEZONE_TYPE_AUTO}
-         */
-        public void setTimeZone(Context context, String timeZone) {
-            if (TextUtils.isEmpty(timeZone)) {
-                if (DEBUG) {
-                    Log.d(TAG, "Empty time zone, nothing to be done.");
-                }
-                return;
-            }
-            boolean updatePrefs = false;
-            synchronized (mTZCallbacks) {
-                if (CalendarCache.TIMEZONE_TYPE_AUTO.equals(timeZone)) {
-                    if (mUseHomeTZ) {
-                        updatePrefs = true;
-                    }
-                    mUseHomeTZ = false;
-                } else {
-                    if (!mUseHomeTZ || !TextUtils.equals(mHomeTZ, timeZone)) {
-                        updatePrefs = true;
-                    }
-                    mUseHomeTZ = true;
-                    mHomeTZ = timeZone;
-                }
-            }
-            if (updatePrefs) {
-                // Write the prefs
-                SharedPreferences prefs = getSharedPreferences(context, mPrefsName);
-                setSharedPreference(prefs, KEY_HOME_TZ_ENABLED, mUseHomeTZ);
-                setSharedPreference(prefs, KEY_HOME_TZ, mHomeTZ);
-
-                // Update the db
-                ContentValues values = new ContentValues();
-                if (mHandler != null) {
-                    mHandler.cancelOperation(mToken);
-                }
-
-                mHandler = new AsyncTZHandler(context.getContentResolver());
-
-                // skip 0 so query can use it
-                if (++mToken == 0) {
-                    mToken = 1;
-                }
-
-                // Write the use home tz setting
-                values.put(CalendarCache.VALUE, mUseHomeTZ ? CalendarCache.TIMEZONE_TYPE_HOME
-                        : CalendarCache.TIMEZONE_TYPE_AUTO);
-                mHandler.startUpdate(mToken, null, CalendarCache.URI, values, CalendarCache.WHERE,
-                        TIMEZONE_TYPE_ARGS);
-
-                // If using a home tz write it to the db
-                if (mUseHomeTZ) {
-                    ContentValues values2 = new ContentValues();
-                    values2.put(CalendarCache.VALUE, mHomeTZ);
-                    mHandler.startUpdate(mToken, null, CalendarCache.URI, values2,
-                            CalendarCache.WHERE, TIMEZONE_INSTANCES_ARGS);
-                }
-            }
-        }
-
-        /**
-         * Gets the time zone that Calendar should be displayed in
-         *
-         * This is a helper method to get the appropriate time zone for Calendar. If this
-         * is the first time this method has been called it will initiate an asynchronous
-         * query to verify that the data in preferences is correct. The callback supplied
-         * will only be called if this query returns a value other than what is stored in
-         * preferences and should cause the calling activity to refresh anything that
-         * depends on calling this method.
-         *
-         * @param context The calling activity
-         * @param callback The runnable that should execute if a query returns new values
-         * @return The string value representing the time zone Calendar should display
-         */
-        public String getTimeZone(Context context, Runnable callback) {
-            synchronized (mTZCallbacks){
-                if (mFirstTZRequest) {
-                    mTZQueryInProgress = true;
-                    mFirstTZRequest = false;
-
-                    SharedPreferences prefs = getSharedPreferences(context, mPrefsName);
-                    mUseHomeTZ = prefs.getBoolean(KEY_HOME_TZ_ENABLED, false);
-                    mHomeTZ = prefs.getString(KEY_HOME_TZ, Time.getCurrentTimezone());
-
-                    // When the async query returns it should synchronize on
-                    // mTZCallbacks, update mUseHomeTZ, mHomeTZ, and the
-                    // preferences, set mTZQueryInProgress to false, and call all
-                    // the runnables in mTZCallbacks.
-                    if (mHandler == null) {
-                        mHandler = new AsyncTZHandler(context.getContentResolver());
-                    }
-                    mHandler.startQuery(0, context, CalendarCache.URI, CalendarCache.POJECTION,
-                            null, null, null);
-                }
-                if (mTZQueryInProgress) {
-                    mTZCallbacks.add(callback);
-                }
-            }
-            return mUseHomeTZ ? mHomeTZ : Time.getCurrentTimezone();
-        }
-
-        /**
-         * Forces a query of the database to check for changes to the time zone.
-         * This should be called if another app may have modified the db. If a
-         * query is already in progress the callback will be added to the list
-         * of callbacks to be called when it returns.
-         *
-         * @param context The calling activity
-         * @param callback The runnable that should execute if a query returns
-         *            new values
-         */
-        public void forceDBRequery(Context context, Runnable callback) {
-            synchronized (mTZCallbacks){
-                if (mTZQueryInProgress) {
-                    mTZCallbacks.add(callback);
-                    return;
-                }
-                mFirstTZRequest = true;
-                getTimeZone(context, callback);
-            }
-        }
-    }
-
-        /**
-         * A helper method for writing a String value to the preferences
-         * asynchronously.
-         *
-         * @param context A context with access to the correct preferences
-         * @param key The preference to write to
-         * @param value The value to write
-         */
-        public static void setSharedPreference(SharedPreferences prefs, String key, String value) {
-//            SharedPreferences prefs = getSharedPreferences(context);
-            SharedPreferences.Editor editor = prefs.edit();
-            editor.putString(key, value);
-            editor.apply();
-        }
-
-        /**
-         * A helper method for writing a boolean value to the preferences
-         * asynchronously.
-         *
-         * @param context A context with access to the correct preferences
-         * @param key The preference to write to
-         * @param value The value to write
-         */
-        public static void setSharedPreference(SharedPreferences prefs, String key, boolean value) {
-//            SharedPreferences prefs = getSharedPreferences(context, prefsName);
-            SharedPreferences.Editor editor = prefs.edit();
-            editor.putBoolean(key, value);
-            editor.apply();
-        }
-
-        /** Return a properly configured SharedPreferences instance */
-        public static SharedPreferences getSharedPreferences(Context context, String prefsName) {
-            return context.getSharedPreferences(prefsName, Context.MODE_PRIVATE);
-        }
-}
diff --git a/core/java/android/util/DisplayMetrics.java b/core/java/android/util/DisplayMetrics.java
index 8018ff9..d594567 100644
--- a/core/java/android/util/DisplayMetrics.java
+++ b/core/java/android/util/DisplayMetrics.java
@@ -38,6 +38,15 @@
     public static final int DENSITY_MEDIUM = 160;
 
     /**
+     * Standard quantized DPI for 720p TV screens.  Applications should
+     * generally not worry about this density, instead targeting
+     * {@link #DENSITY_XHIGH} for 1080p TV screens.  For situations where
+     * output is needed for a 720p screen, the UI elements can be scaled
+     * automatically by the platform.
+     */
+    public static final int DENSITY_TV = 213;
+
+    /**
      * Standard quantized DPI for high-density screens.
      */
     public static final int DENSITY_HIGH = 240;
@@ -105,10 +114,18 @@
      */
     public float ydpi;
 
-    /** @hide */
-    public int realWidthPixels;
-    /** @hide */
-    public int realHeightPixels;
+    /**
+     * The reported display width prior to any compatibility mode scaling
+     * being applied.
+     * @hide
+     */
+    public int unscaledWidthPixels;
+    /**
+     * The reported display height prior to any compatibility mode scaling
+     * being applied.
+     * @hide
+     */
+    public int unscaledHeightPixels;
 
     public DisplayMetrics() {
     }
@@ -121,8 +138,8 @@
         scaledDensity = o.scaledDensity;
         xdpi = o.xdpi;
         ydpi = o.ydpi;
-        realWidthPixels = o.realWidthPixels;
-        realHeightPixels = o.realHeightPixels;
+        unscaledWidthPixels = o.unscaledWidthPixels;
+        unscaledHeightPixels = o.unscaledHeightPixels;
     }
     
     public void setToDefaults() {
@@ -133,8 +150,8 @@
         scaledDensity = density;
         xdpi = DENSITY_DEVICE;
         ydpi = DENSITY_DEVICE;
-        realWidthPixels = 0;
-        realHeightPixels = 0;
+        unscaledWidthPixels = 0;
+        unscaledHeightPixels = 0;
     }
 
     @Override
diff --git a/core/java/android/util/FinitePool.java b/core/java/android/util/FinitePool.java
index 3ef8293..b30f2bf 100644
--- a/core/java/android/util/FinitePool.java
+++ b/core/java/android/util/FinitePool.java
@@ -20,6 +20,8 @@
  * @hide
  */
 class FinitePool<T extends Poolable<T>> implements Pool<T> {
+    private static final String LOG_TAG = "FinitePool";
+
     /**
      * Factory used to create new pool objects
      */
@@ -69,6 +71,7 @@
 
         if (element != null) {
             element.setNextPoolable(null);
+            element.setPooled(false);
             mManager.onAcquired(element);            
         }
 
@@ -76,11 +79,16 @@
     }
 
     public void release(T element) {
-        if (mInfinite || mPoolCount < mLimit) {
-            mPoolCount++;
-            element.setNextPoolable(mRoot);
-            mRoot = element;
+        if (!element.isPooled()) {
+            if (mInfinite || mPoolCount < mLimit) {
+                mPoolCount++;
+                element.setNextPoolable(mRoot);
+                element.setPooled(true);
+                mRoot = element;
+            }
+            mManager.onReleased(element);
+        } else {
+            Log.w(LOG_TAG, "Element is already in pool: " + element);
         }
-        mManager.onReleased(element);
     }
 }
diff --git a/core/java/android/util/FloatProperty.java b/core/java/android/util/FloatProperty.java
new file mode 100644
index 0000000..a67b3cb
--- /dev/null
+++ b/core/java/android/util/FloatProperty.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package android.util;
+
+import android.util.Property;
+
+/**
+ * An implementation of {@link android.util.Property} to be used specifically with fields of type
+ * <code>float</code>. This type-specific subclass enables performance benefit by allowing
+ * calls to a {@link #set(Object, Float) set()} function that takes the primitive
+ * <code>float</code> type and avoids autoboxing and other overhead associated with the
+ * <code>Float</code> class.
+ *
+ * @param <T> The class on which the Property is declared.
+ *
+ * @hide
+ */
+public abstract class FloatProperty<T> extends Property<T, Float> {
+
+    public FloatProperty(String name) {
+        super(Float.class, name);
+    }
+
+    /**
+     * A type-specific override of the {@link #set(Object, Float)} that is faster when dealing
+     * with fields of type <code>float</code>.
+     */
+    public abstract void setValue(T object, float value);
+
+    @Override
+    final public void set(T object, Float value) {
+        setValue(object, value);
+    }
+
+}
\ No newline at end of file
diff --git a/core/java/android/util/IntProperty.java b/core/java/android/util/IntProperty.java
new file mode 100644
index 0000000..459d6b2
--- /dev/null
+++ b/core/java/android/util/IntProperty.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package android.util;
+
+import android.util.Property;
+
+/**
+ * An implementation of {@link android.util.Property} to be used specifically with fields of type
+ * <code>int</code>. This type-specific subclass enables performance benefit by allowing
+ * calls to a {@link #set(Object, Integer) set()} function that takes the primitive
+ * <code>int</code> type and avoids autoboxing and other overhead associated with the
+ * <code>Integer</code> class.
+ *
+ * @param <T> The class on which the Property is declared.
+ *
+ * @hide
+ */
+public abstract class IntProperty<T> extends Property<T, Integer> {
+
+    public IntProperty(String name) {
+        super(Integer.class, name);
+    }
+
+    /**
+     * A type-specific override of the {@link #set(Object, Integer)} that is faster when dealing
+     * with fields of type <code>int</code>.
+     */
+    public abstract void setValue(T object, int value);
+
+    @Override
+    final public void set(T object, Integer value) {
+        set(object, value.intValue());
+    }
+
+}
\ No newline at end of file
diff --git a/core/java/android/util/LocaleUtil.java b/core/java/android/util/LocaleUtil.java
new file mode 100644
index 0000000..74a930f
--- /dev/null
+++ b/core/java/android/util/LocaleUtil.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.util;
+
+import java.util.Locale;
+
+import libcore.icu.ICU;
+
+/**
+ * Various utilities for Locales
+ *
+ * @hide
+ */
+public class LocaleUtil {
+
+    private LocaleUtil() { /* cannot be instantiated */ }
+
+    /**
+     * @hide Do not use. Implementation not finished.
+     */
+    public static final int TEXT_LAYOUT_DIRECTION_UNDEFINED_DO_NOT_USE = -1;
+
+    /**
+     * @hide Do not use. Implementation not finished.
+     */
+    public static final int TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE = 0;
+
+    /**
+     * @hide Do not use. Implementation not finished.
+     */
+    public static final int TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE = 1;
+
+    private static final char UNDERSCORE_CHAR = '_';
+
+    private static String ARAB_SCRIPT_SUBTAG = "Arab";
+    private static String HEBR_SCRIPT_SUBTAG = "Hebr";
+
+    /**
+     * Return the layout direction for a given Locale
+     *
+     * @param locale the Locale for which we want the layout direction. Can be null.
+     * @return the layout direction. This may be one of:
+     * {@link #TEXT_LAYOUT_DIRECTION_UNDEFINED_DO_NOT_USE} or
+     * {@link #TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE} or
+     * {@link #TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE}.
+     *
+     * Be careful: this code will need to be changed when vertical scripts will be supported
+     *
+     * @hide
+     */
+    public static int getLayoutDirectionFromLocale(Locale locale) {
+        if (locale == null || locale.equals(Locale.ROOT)) {
+            return TEXT_LAYOUT_DIRECTION_UNDEFINED_DO_NOT_USE;
+        }
+
+        final String scriptSubtag = ICU.getScript(ICU.addLikelySubtags(locale.toString()));
+        if (scriptSubtag == null) return getLayoutDirectionFromFirstChar(locale);
+
+        if (scriptSubtag.equalsIgnoreCase(ARAB_SCRIPT_SUBTAG) ||
+                scriptSubtag.equalsIgnoreCase(HEBR_SCRIPT_SUBTAG)) {
+            return TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE;
+        }
+        return TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE;
+    }
+
+    /**
+     * Fallback algorithm to detect the locale direction. Rely on the fist char of the
+     * localized locale name. This will not work if the localized locale name is in English
+     * (this is the case for ICU 4.4 and "Urdu" script)
+     *
+     * @param locale
+     * @return the layout direction. This may be one of:
+     * {@link #TEXT_LAYOUT_DIRECTION_UNDEFINED_DO_NOT_USE} or
+     * {@link #TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE} or
+     * {@link #TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE}.
+     *
+     * Be careful: this code will need to be changed when vertical scripts will be supported
+     *
+     * @hide
+     */
+    private static int getLayoutDirectionFromFirstChar(Locale locale) {
+        switch(Character.getDirectionality(locale.getDisplayName(locale).charAt(0))) {
+            case Character.DIRECTIONALITY_LEFT_TO_RIGHT:
+                return TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE;
+            case Character.DIRECTIONALITY_RIGHT_TO_LEFT:
+            case Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC:
+                return TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE;
+            default:
+                return TEXT_LAYOUT_DIRECTION_UNDEFINED_DO_NOT_USE;
+        }
+    }
+}
diff --git a/core/java/android/util/Log.java b/core/java/android/util/Log.java
index 38903ab..1c3709f 100644
--- a/core/java/android/util/Log.java
+++ b/core/java/android/util/Log.java
@@ -20,6 +20,7 @@
 
 import java.io.PrintWriter;
 import java.io.StringWriter;
+import java.net.UnknownHostException;
 
 /**
  * API for sending log output.
@@ -302,6 +303,17 @@
         if (tr == null) {
             return "";
         }
+
+        // This is to reduce the amount of log spew that apps do in the non-error
+        // condition of the network being unavailable.
+        Throwable t = tr;
+        while (t != null) {
+            if (t instanceof UnknownHostException) {
+                return "";
+            }
+            t = t.getCause();
+        }
+
         StringWriter sw = new StringWriter();
         PrintWriter pw = new PrintWriter(sw);
         tr.printStackTrace(pw);
diff --git a/core/java/android/util/NoSuchPropertyException.java b/core/java/android/util/NoSuchPropertyException.java
new file mode 100644
index 0000000..b93f983
--- /dev/null
+++ b/core/java/android/util/NoSuchPropertyException.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package android.util;
+
+/**
+ * Thrown when code requests a {@link Property} on a class that does
+ * not expose the appropriate method or field.
+ *
+ * @see Property#of(java.lang.Class, java.lang.Class, java.lang.String)
+ */
+public class NoSuchPropertyException extends RuntimeException {
+
+    public NoSuchPropertyException(String s) {
+        super(s);
+    }
+
+}
diff --git a/core/java/android/util/Poolable.java b/core/java/android/util/Poolable.java
index fd9bd9b..87e0529 100644
--- a/core/java/android/util/Poolable.java
+++ b/core/java/android/util/Poolable.java
@@ -22,4 +22,6 @@
 public interface Poolable<T> {
     void setNextPoolable(T element);
     T getNextPoolable();
+    boolean isPooled();
+    void setPooled(boolean isPooled);
 }
diff --git a/core/java/android/util/Property.java b/core/java/android/util/Property.java
new file mode 100644
index 0000000..146db80
--- /dev/null
+++ b/core/java/android/util/Property.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package android.util;
+
+
+/**
+ * A property is an abstraction that can be used to represent a <emb>mutable</em> value that is held
+ * in a <em>host</em> object. The Property's {@link #set(Object, Object)} or {@link #get(Object)}
+ * methods can be implemented in terms of the private fields of the host object, or via "setter" and
+ * "getter" methods or by some other mechanism, as appropriate.
+ *
+ * @param <T> The class on which the property is declared.
+ * @param <V> The type that this property represents.
+ */
+public abstract class Property<T, V> {
+
+    private final String mName;
+    private final Class<V> mType;
+
+    /**
+     * This factory method creates and returns a Property given the <code>class</code> and
+     * <code>name</code> parameters, where the <code>"name"</code> parameter represents either:
+     * <ul>
+     *     <li>a public <code>getName()</code> method on the class which takes no arguments, plus an
+     *     optional public <code>setName()</code> method which takes a value of the same type
+     *     returned by <code>getName()</code>
+     *     <li>a public <code>isName()</code> method on the class which takes no arguments, plus an
+     *     optional public <code>setName()</code> method which takes a value of the same type
+     *     returned by <code>isName()</code>
+     *     <li>a public <code>name</code> field on the class
+     * </ul>
+     *
+     * <p>If either of the get/is method alternatives is found on the class, but an appropriate
+     * <code>setName()</code> method is not found, the <code>Property</code> will be
+     * {@link #isReadOnly() readOnly}. Calling the {@link #set(Object, Object)} method on such
+     * a property is allowed, but will have no effect.</p>
+     *
+     * <p>If neither the methods nor the field are found on the class a
+     * {@link NoSuchPropertyException} exception will be thrown.</p>
+     */
+    public static <T, V> Property<T, V> of(Class<T> hostType, Class<V> valueType, String name) {
+        return new ReflectiveProperty<T, V>(hostType, valueType, name);
+    }
+
+    /**
+     * A constructor that takes an identifying name and {@link #getType() type} for the property.
+     */
+    public Property(Class<V> type, String name) {
+        mName = name;
+        mType = type;
+    }
+
+    /**
+     * Returns true if the {@link #set(Object, Object)} method does not set the value on the target
+     * object (in which case the {@link #set(Object, Object) set()} method should throw a {@link
+     * NoSuchPropertyException} exception). This may happen if the Property wraps functionality that
+     * allows querying the underlying value but not setting it. For example, the {@link #of(Class,
+     * Class, String)} factory method may return a Property with name "foo" for an object that has
+     * only a <code>getFoo()</code> or <code>isFoo()</code> method, but no matching
+     * <code>setFoo()</code> method.
+     */
+    public boolean isReadOnly() {
+        return false;
+    }
+
+    /**
+     * Sets the value on <code>object</code> which this property represents. If the method is unable
+     * to set the value on the target object it will throw an {@link UnsupportedOperationException}
+     * exception.
+     */
+    public void set(T object, V value) {
+        throw new UnsupportedOperationException("Property " + getName() +" is read-only");
+    }
+
+    /**
+     * Returns the current value that this property represents on the given <code>object</code>.
+     */
+    public abstract V get(T object);
+
+    /**
+     * Returns the name for this property.
+     */
+    public String getName() {
+        return mName;
+    }
+
+    /**
+     * Returns the type for this property.
+     */
+    public Class<V> getType() {
+        return mType;
+    }
+}
diff --git a/core/java/android/util/ReflectiveProperty.java b/core/java/android/util/ReflectiveProperty.java
new file mode 100644
index 0000000..6832240
--- /dev/null
+++ b/core/java/android/util/ReflectiveProperty.java
@@ -0,0 +1,163 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package android.util;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+/**
+ * Internal class to automatically generate a Property for a given class/name pair, given the
+ * specification of {@link Property#of(java.lang.Class, java.lang.Class, java.lang.String)}
+ */
+class ReflectiveProperty<T, V> extends Property<T, V> {
+
+    private static final String PREFIX_GET = "get";
+    private static final String PREFIX_IS = "is";
+    private static final String PREFIX_SET = "set";
+    private Method mSetter;
+    private Method mGetter;
+    private Field mField;
+
+    /**
+     * For given property name 'name', look for getName/isName method or 'name' field.
+     * Also look for setName method (optional - could be readonly). Failing method getters and
+     * field results in throwing NoSuchPropertyException.
+     *
+     * @param propertyHolder The class on which the methods or field are found
+     * @param name The name of the property, where this name is capitalized and appended to
+     * "get" and "is to search for the appropriate methods. If the get/is methods are not found,
+     * the constructor will search for a field with that exact name.
+     */
+    public ReflectiveProperty(Class<T> propertyHolder, Class<V> valueType, String name) {
+         // TODO: cache reflection info for each new class/name pair
+        super(valueType, name);
+        char firstLetter = Character.toUpperCase(name.charAt(0));
+        String theRest = name.substring(1);
+        String capitalizedName = firstLetter + theRest;
+        String getterName = PREFIX_GET + capitalizedName;
+        try {
+            mGetter = propertyHolder.getMethod(getterName, (Class<?>[])null);
+        } catch (NoSuchMethodException e) {
+            // getName() not available - try isName() instead
+            getterName = PREFIX_IS + capitalizedName;
+            try {
+                mGetter = propertyHolder.getMethod(getterName, (Class<?>[])null);
+            } catch (NoSuchMethodException e1) {
+                // Try public field instead
+                try {
+                    mField = propertyHolder.getField(name);
+                    Class fieldType = mField.getType();
+                    if (!typesMatch(valueType, fieldType)) {
+                        throw new NoSuchPropertyException("Underlying type (" + fieldType + ") " +
+                                "does not match Property type (" + valueType + ")");
+                    }
+                    return;
+                } catch (NoSuchFieldException e2) {
+                    // no way to access property - throw appropriate exception
+                    throw new NoSuchPropertyException("No accessor method or field found for"
+                            + " property with name " + name);
+                }
+            }
+        }
+        Class getterType = mGetter.getReturnType();
+        // Check to make sure our getter type matches our valueType
+        if (!typesMatch(valueType, getterType)) {
+            throw new NoSuchPropertyException("Underlying type (" + getterType + ") " +
+                    "does not match Property type (" + valueType + ")");
+        }
+        String setterName = PREFIX_SET + capitalizedName;
+        try {
+            mSetter = propertyHolder.getMethod(setterName, getterType);
+        } catch (NoSuchMethodException ignored) {
+            // Okay to not have a setter - just a readonly property
+        }
+    }
+
+    /**
+     * Utility method to check whether the type of the underlying field/method on the target
+     * object matches the type of the Property. The extra checks for primitive types are because
+     * generics will force the Property type to be a class, whereas the type of the underlying
+     * method/field will probably be a primitive type instead. Accept float as matching Float,
+     * etc.
+     */
+    private boolean typesMatch(Class<V> valueType, Class getterType) {
+        if (getterType != valueType) {
+            if (getterType.isPrimitive()) {
+                return (getterType == float.class && valueType == Float.class) ||
+                        (getterType == int.class && valueType == Integer.class) ||
+                        (getterType == boolean.class && valueType == Boolean.class) ||
+                        (getterType == long.class && valueType == Long.class) ||
+                        (getterType == double.class && valueType == Double.class) ||
+                        (getterType == short.class && valueType == Short.class) ||
+                        (getterType == byte.class && valueType == Byte.class) ||
+                        (getterType == char.class && valueType == Character.class);
+            }
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public void set(T object, V value) {
+        if (mSetter != null) {
+            try {
+                mSetter.invoke(object, value);
+            } catch (IllegalAccessException e) {
+                throw new AssertionError();
+            } catch (InvocationTargetException e) {
+                throw new RuntimeException(e.getCause());
+            }
+        } else if (mField != null) {
+            try {
+                mField.set(object, value);
+            } catch (IllegalAccessException e) {
+                throw new AssertionError();
+            }
+        } else {
+            throw new UnsupportedOperationException("Property " + getName() +" is read-only");
+        }
+    }
+
+    @Override
+    public V get(T object) {
+        if (mGetter != null) {
+            try {
+                return (V) mGetter.invoke(object, (Object[])null);
+            } catch (IllegalAccessException e) {
+                throw new AssertionError();
+            } catch (InvocationTargetException e) {
+                throw new RuntimeException(e.getCause());
+            }
+        } else if (mField != null) {
+            try {
+                return (V) mField.get(object);
+            } catch (IllegalAccessException e) {
+                throw new AssertionError();
+            }
+        }
+        // Should not get here: there should always be a non-null getter or field
+        throw new AssertionError();
+    }
+
+    /**
+     * Returns false if there is no setter or public field underlying this Property.
+     */
+    @Override
+    public boolean isReadOnly() {
+        return (mSetter == null && mField == null);
+    }
+}
diff --git a/core/java/android/view/CompatibilityInfoHolder.java b/core/java/android/view/CompatibilityInfoHolder.java
new file mode 100644
index 0000000..fc8d684
--- /dev/null
+++ b/core/java/android/view/CompatibilityInfoHolder.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.view;
+
+import android.content.res.CompatibilityInfo;
+
+/** @hide */
+public class CompatibilityInfoHolder {
+    private volatile CompatibilityInfo mCompatInfo = CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO;
+
+    public void set(CompatibilityInfo compatInfo) {
+        if (compatInfo != null && (compatInfo.isScalingRequired()
+                || !compatInfo.supportsScreen())) {
+            mCompatInfo = compatInfo;
+        } else {
+            mCompatInfo = CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO;
+        }
+    }
+
+    public CompatibilityInfo get() {
+        return mCompatInfo;
+    }
+
+    public CompatibilityInfo getIfNeeded() {
+        CompatibilityInfo ci = mCompatInfo;
+        if (ci == null || ci  == CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO) {
+            return null;
+        }
+        return ci;
+    }
+}
diff --git a/core/java/android/view/Display.java b/core/java/android/view/Display.java
index b5d36d9..3fa8dfd 100644
--- a/core/java/android/view/Display.java
+++ b/core/java/android/view/Display.java
@@ -26,6 +26,9 @@
 import android.util.Slog;
 
 public class Display {
+    static final String TAG = "Display";
+    static final boolean DEBUG_COMPAT = false;
+
     /**
      * Specify the default Display
      */
@@ -38,7 +41,7 @@
      * Display gives you access to some information about a particular display
      * connected to the device.
      */
-    Display(int display, CompatibilityInfo compatInfo) {
+    Display(int display, CompatibilityInfoHolder compatInfo) {
         // initalize the statics when this class is first instansiated. This is
         // done here instead of in the static block because Zygote
         synchronized (sStaticInit) {
@@ -47,15 +50,20 @@
                 sInitialized = true;
             }
         }
-        if (compatInfo != null && (compatInfo.isScalingRequired()
-                || !compatInfo.supportsScreen())) {
-            mCompatibilityInfo = compatInfo;
-        } else {
-            mCompatibilityInfo = null;
-        }
+        mCompatibilityInfo = compatInfo != null ? compatInfo : new CompatibilityInfoHolder();
         mDisplay = display;
         init(display);
     }
+
+    /** @hide */
+    public static void setCompatibilityInfo(CompatibilityInfo compatInfo) {
+        if (compatInfo != null && (compatInfo.isScalingRequired()
+                || !compatInfo.supportsScreen())) {
+            sCompatibilityInfo = compatInfo;
+        } else {
+            sCompatibilityInfo = null;
+        }
+    }
     
     /**
      * Returns the index of this display.  This is currently undefined; do
@@ -80,25 +88,39 @@
      * adjusted for you based on the current rotation of the display.
      */
     public void getSize(Point outSize) {
+        getSizeInternal(outSize, true);
+    }
+
+    /**
+     * Returns the raw size of the display, in pixels.  Note that this
+     * should <em>not</em> generally be used for computing layouts, since
+     * a device will typically have screen decoration (such as a status bar)
+     * along the edges of the display that reduce the amount of application
+     * space available from the raw size returned here.  This value is
+     * adjusted for you based on the current rotation of the display.
+     */
+    private void getSizeInternal(Point outSize, boolean doCompat) {
         try {
             IWindowManager wm = getWindowManager();
             if (wm != null) {
                 wm.getDisplaySize(outSize);
+                CompatibilityInfo ci;
+                if (doCompat && (ci=mCompatibilityInfo.getIfNeeded()) != null) {
+                    synchronized (mTmpMetrics) {
+                        mTmpMetrics.unscaledWidthPixels = outSize.x;
+                        mTmpMetrics.unscaledHeightPixels = outSize.y;
+                        mTmpMetrics.density = mDensity;
+                        ci.applyToDisplayMetrics(mTmpMetrics);
+                        outSize.x = mTmpMetrics.widthPixels;
+                        outSize.y = mTmpMetrics.heightPixels;
+                    }
+                }
             } else {
                 // This is just for boot-strapping, initializing the
                 // system process before the window manager is up.
                 outSize.y = getRealHeight();
             }
-            if (mCompatibilityInfo != null) {
-                synchronized (mTmpMetrics) {
-                    mTmpMetrics.realWidthPixels = outSize.x;
-                    mTmpMetrics.realHeightPixels = outSize.y;
-                    mTmpMetrics.density = mDensity;
-                    mCompatibilityInfo.applyToDisplayMetrics(mTmpMetrics);
-                    outSize.x = mTmpMetrics.widthPixels;
-                    outSize.y = mTmpMetrics.heightPixels;
-                }
-            }
+            if (DEBUG_COMPAT && doCompat) Slog.v(TAG, "Returning display size: " + outSize);
         } catch (RemoteException e) {
             Slog.w("Display", "Unable to get display size", e);
         }
@@ -109,7 +131,7 @@
      */
     public void getRectSize(Rect outSize) {
         synchronized (mTmpPoint) {
-            getSize(mTmpPoint);
+            getSizeInternal(mTmpPoint, true);
             outSize.set(0, 0, mTmpPoint.x, mTmpPoint.y);
         }
     }
@@ -137,7 +159,7 @@
         synchronized (mTmpPoint) {
             long now = SystemClock.uptimeMillis();
             if (now > (mLastGetTime+20)) {
-                getSize(mTmpPoint);
+                getSizeInternal(mTmpPoint, true);
                 mLastGetTime = now;
             }
             return mTmpPoint.x;
@@ -152,7 +174,7 @@
         synchronized (mTmpPoint) {
             long now = SystemClock.uptimeMillis();
             if (now > (mLastGetTime+20)) {
-                getSize(mTmpPoint);
+                getSizeInternal(mTmpPoint, true);
                 mLastGetTime = now;
             }
             return mTmpPoint.y;
@@ -218,15 +240,19 @@
      */
     public void getMetrics(DisplayMetrics outMetrics) {
         synchronized (mTmpPoint) {
-            getSize(mTmpPoint);
+            getSizeInternal(mTmpPoint, false);
             outMetrics.widthPixels = mTmpPoint.x;
             outMetrics.heightPixels = mTmpPoint.y;
         }
         getNonSizeMetrics(outMetrics);
 
-        if (mCompatibilityInfo != null) {
-            mCompatibilityInfo.applyToDisplayMetrics(outMetrics);
+        CompatibilityInfo ci = mCompatibilityInfo.getIfNeeded();
+        if (ci != null) {
+            ci.applyToDisplayMetrics(outMetrics);
         }
+
+        if (DEBUG_COMPAT) Slog.v(TAG, "Returning DisplayMetrics: " + outMetrics.widthPixels
+                + "x" + outMetrics.heightPixels + " " + outMetrics.density);
     }
 
     /**
@@ -248,8 +274,8 @@
         outMetrics.xdpi         = mDpiX;
         outMetrics.ydpi         = mDpiY;
 
-        outMetrics.realWidthPixels  = outMetrics.widthPixels;
-        outMetrics.realHeightPixels = outMetrics.heightPixels;
+        outMetrics.unscaledWidthPixels  = outMetrics.widthPixels;
+        outMetrics.unscaledHeightPixels = outMetrics.heightPixels;
     }
 
     static IWindowManager getWindowManager() {
@@ -270,7 +296,7 @@
     
     private native void init(int display);
 
-    private final CompatibilityInfo mCompatibilityInfo;
+    private final CompatibilityInfoHolder mCompatibilityInfo;
     private final int   mDisplay;
     // Following fields are initialized from native code
     private int         mPixelFormat;
@@ -287,11 +313,13 @@
     private static boolean sInitialized = false;
     private static IWindowManager sWindowManager;
 
+    private static volatile CompatibilityInfo sCompatibilityInfo;
+
     /**
      * Returns a display object which uses the metric's width/height instead.
      * @hide
      */
-    public static Display createCompatibleDisplay(int displayId, CompatibilityInfo compat) {
+    public static Display createCompatibleDisplay(int displayId, CompatibilityInfoHolder compat) {
         return new Display(displayId, compat);
     }
 }
diff --git a/core/java/android/view/GLES20Canvas.java b/core/java/android/view/GLES20Canvas.java
index 2b79a76..5216c49 100644
--- a/core/java/android/view/GLES20Canvas.java
+++ b/core/java/android/view/GLES20Canvas.java
@@ -29,6 +29,7 @@
 import android.graphics.RectF;
 import android.graphics.Region;
 import android.graphics.Shader;
+import android.graphics.SurfaceTexture;
 import android.graphics.TemporaryBuffer;
 import android.text.GraphicsOperations;
 import android.text.SpannableString;
@@ -163,9 +164,10 @@
     static native int nCreateTextureLayer(int[] layerInfo);
     static native int nCreateLayer(int width, int height, boolean isOpaque, int[] layerInfo);
     static native void nResizeLayer(int layerId, int width, int height, int[] layerInfo);
-    static native void nUpdateTextureLayer(int layerId, int width, int height, int surface);
+    static native void nUpdateTextureLayer(int layerId, int width, int height, SurfaceTexture surface);
     static native void nDestroyLayer(int layerId);
     static native void nDestroyLayerDeferred(int layerId);
+    static native boolean nCopyLayer(int layerId, int bitmap);
 
     ///////////////////////////////////////////////////////////////////////////
     // Canvas management
@@ -201,6 +203,14 @@
     private static native void nSetViewport(int renderer, int width, int height);
 
     /**
+     * Preserves the back buffer of the current surface after a buffer swap.
+     * Calling this method sets the EGL_SWAP_BEHAVIOR attribute of the current
+     * surface to EGL_BUFFER_PRESERVED. Calling this method requires an EGL
+     * config that supports EGL_SWAP_BEHAVIOR_PRESERVED_BIT.
+     * 
+     * @return True if the swap behavior was successfully changed,
+     *         false otherwise.
+     * 
      * @hide
      */
     public static boolean preserveBackBuffer() {
@@ -208,6 +218,21 @@
     }
 
     private static native boolean nPreserveBackBuffer();    
+
+    /**
+     * Indicates whether the current surface preserves its back buffer
+     * after a buffer swap.
+     * 
+     * @return True, if the surface's EGL_SWAP_BEHAVIOR is EGL_BUFFER_PRESERVED,
+     *         false otherwise
+     *         
+     * @hide
+     */
+    public static boolean isBackBufferPreserved() {
+        return nIsBackBufferPreserved();
+    }
+
+    private static native boolean nIsBackBufferPreserved();    
     
     @Override
     void onPreDraw(Rect dirty) {
diff --git a/core/java/android/view/GLES20Layer.java b/core/java/android/view/GLES20Layer.java
index bc191a6..69dfc2b 100644
--- a/core/java/android/view/GLES20Layer.java
+++ b/core/java/android/view/GLES20Layer.java
@@ -17,6 +17,8 @@
 
 package android.view;
 
+import android.graphics.Bitmap;
+
 /**
  * An OpenGL ES 2.0 implementation of {@link HardwareLayer}.
  */
@@ -40,7 +42,10 @@
         return mLayer;
     }
 
-    
+    boolean copyInto(Bitmap bitmap) {
+        return GLES20Canvas.nCopyLayer(mLayer, bitmap.mNativeBitmap);
+    }    
+
     @Override
     void destroy() {
         if (mFinalizer != null) mFinalizer.destroy();
diff --git a/core/java/android/view/GLES20RecordingCanvas.java b/core/java/android/view/GLES20RecordingCanvas.java
index 2603281..ec94fe7 100644
--- a/core/java/android/view/GLES20RecordingCanvas.java
+++ b/core/java/android/view/GLES20RecordingCanvas.java
@@ -25,7 +25,7 @@
 import android.graphics.RectF;
 import android.graphics.Shader;
 
-import java.util.HashSet;
+import java.util.ArrayList;
 
 /**
  * An implementation of a GL canvas that records drawing operations.
@@ -37,7 +37,7 @@
     // These lists ensure that any Bitmaps recorded by a DisplayList are kept alive as long
     // as the DisplayList is alive.
     @SuppressWarnings({"MismatchedQueryAndUpdateOfCollection"})
-    private final HashSet<Bitmap> mBitmaps = new HashSet<Bitmap>();
+    private final ArrayList<Bitmap> mBitmaps = new ArrayList<Bitmap>(5);
 
     GLES20RecordingCanvas(boolean translucent) {
         super(true, translucent);
diff --git a/core/java/android/view/GLES20TextureLayer.java b/core/java/android/view/GLES20TextureLayer.java
index fcf421b..063eee7 100644
--- a/core/java/android/view/GLES20TextureLayer.java
+++ b/core/java/android/view/GLES20TextureLayer.java
@@ -70,7 +70,7 @@
         return mSurface;
     }
 
-    void update(int width, int height, int surface) {
-        GLES20Canvas.nUpdateTextureLayer(mLayer, width, height, surface);
+    void update(int width, int height) {
+        GLES20Canvas.nUpdateTextureLayer(mLayer, width, height, mSurface);
     }
 }
diff --git a/core/java/android/view/GestureDetector.java b/core/java/android/view/GestureDetector.java
index 1ccc66f..a496a9e 100644
--- a/core/java/android/view/GestureDetector.java
+++ b/core/java/android/view/GestureDetector.java
@@ -610,6 +610,8 @@
         mVelocityTracker = null;
         mIsDoubleTapping = false;
         mStillDown = false;
+        mAlwaysInTapRegion = false;
+        mAlwaysInBiggerTapRegion = false;
         if (mInLongPress) {
             mInLongPress = false;
         }
diff --git a/core/java/android/view/Gravity.java b/core/java/android/view/Gravity.java
index 176c487..63f5ec1 100644
--- a/core/java/android/view/Gravity.java
+++ b/core/java/android/view/Gravity.java
@@ -81,8 +81,10 @@
      *  horizontal axis. */
     public static final int CLIP_HORIZONTAL = AXIS_CLIP<<AXIS_X_SHIFT;
 
-    /** Raw bit controlling whether the horizontal direction is relative (before/after) or not. */
-    public static final int RELATIVE_HORIZONTAL_DIRECTION = 0x00800000;
+    /** Raw bit controlling whether the layout direction is relative or not (START/END instead of
+     * absolute LEFT/RIGHT).
+     */
+    public static final int RELATIVE_LAYOUT_DIRECTION = 0x00800000;
 
     /**
      * Binary mask to get the absolute horizontal gravity of a gravity.
@@ -109,16 +111,16 @@
      */
     public static final int DISPLAY_CLIP_HORIZONTAL = 0x01000000;
     
-    /** Push object to x-axis position before its container, not changing its size. */
-    public static final int BEFORE = RELATIVE_HORIZONTAL_DIRECTION | LEFT;
+    /** Push object to x-axis position at the start of its container, not changing its size. */
+    public static final int START = RELATIVE_LAYOUT_DIRECTION | LEFT;
 
-    /** Push object to x-axis position after its container, not changing its size. */
-    public static final int AFTER = RELATIVE_HORIZONTAL_DIRECTION | RIGHT;
+    /** Push object to x-axis position at the end of its container, not changing its size. */
+    public static final int END = RELATIVE_LAYOUT_DIRECTION | RIGHT;
 
     /**
      * Binary mask for the horizontal gravity and script specific direction bit.
      */
-    public static final int RELATIVE_HORIZONTAL_GRAVITY_MASK = BEFORE | AFTER;
+    public static final int RELATIVE_HORIZONTAL_GRAVITY_MASK = START | END;
 
     /**
      * Apply a gravity constant to an object. This suppose that the layout direction is LTR.
@@ -149,13 +151,13 @@
      *                  width and height of the object.
      * @param outRect Receives the computed frame of the object in its
      *                container.
-     * @param isRtl Whether the layout is right-to-left.
+     * @param layoutDirection The layout direction.
      *
      * @hide
      */
     public static void apply(int gravity, int w, int h, Rect container,
-            Rect outRect, boolean isRtl) {
-        int absGravity = getAbsoluteGravity(gravity, isRtl);
+            Rect outRect, int layoutDirection) {
+        int absGravity = getAbsoluteGravity(gravity, layoutDirection);
         apply(absGravity, w, h, container, 0, 0, outRect);
     }
 
@@ -342,37 +344,32 @@
     /**
      * <p>Convert script specific gravity to absolute horizontal value.</p>
      *
-     * if horizontal direction is LTR, then BEFORE will set LEFT and AFTER will set RIGHT.
-     * if horizontal direction is RTL, then BEFORE will set RIGHT and AFTER will set LEFT.
+     * if horizontal direction is LTR, then START will set LEFT and END will set RIGHT.
+     * if horizontal direction is RTL, then START will set RIGHT and END will set LEFT.
      *
-     * If no horizontal direction is found, then just add LEFT to the existing gravity
      *
      * @param gravity The gravity to convert to absolute (horizontal) values.
-     * @param isRtl Whether the layout is right-to-left.
+     * @param layoutDirection The layout direction.
      * @return gravity converted to absolute (horizontal) values.
      */
-    public static int getAbsoluteGravity(int gravity, boolean isRtl) {
+    public static int getAbsoluteGravity(int gravity, int layoutDirection) {
         int result = gravity;
-        // Set default gravity, if no horizontal gravity is specified
-        if ((result & HORIZONTAL_GRAVITY_MASK) == 0) {
-            result |= Gravity.LEFT;
-        }
-        // If layout is script specific and gravity is horizontal relative (BEFORE or AFTER)
-        if ((result & RELATIVE_HORIZONTAL_DIRECTION) > 0) {
-            if ((result & Gravity.BEFORE) == Gravity.BEFORE) {
-                // Remove the BEFORE bit
-                result &= ~BEFORE;
-                if (isRtl) {
+        // If layout is script specific and gravity is horizontal relative (START or END)
+        if ((result & RELATIVE_LAYOUT_DIRECTION) > 0) {
+            if ((result & Gravity.START) == Gravity.START) {
+                // Remove the START bit
+                result &= ~START;
+                if (layoutDirection == View.LAYOUT_DIRECTION_RTL) {
                     // Set the RIGHT bit
                     result |= RIGHT;
                 } else {
                     // Set the LEFT bit
                     result |= LEFT;
                 }
-            } else if ((result & Gravity.AFTER) == Gravity.AFTER) {
-                // Remove the AFTER bit
-                result &= ~AFTER;
-                if (isRtl) {
+            } else if ((result & Gravity.END) == Gravity.END) {
+                // Remove the END bit
+                result &= ~END;
+                if (layoutDirection == View.LAYOUT_DIRECTION_RTL) {
                     // Set the LEFT bit
                     result |= LEFT;
                 } else {
@@ -382,7 +379,7 @@
             }
             // Don't need the script specific bit any more, so remove it as we are converting to
             // absolute values (LEFT or RIGHT)
-            result &= ~RELATIVE_HORIZONTAL_DIRECTION;
+            result &= ~RELATIVE_LAYOUT_DIRECTION;
         }
         return result;
     }
diff --git a/core/java/android/view/HardwareRenderer.java b/core/java/android/view/HardwareRenderer.java
index 61a24a0..5ceb12a 100644
--- a/core/java/android/view/HardwareRenderer.java
+++ b/core/java/android/view/HardwareRenderer.java
@@ -17,6 +17,7 @@
 
 package android.view;
 
+import android.graphics.Bitmap;
 import android.graphics.Paint;
 import android.graphics.Rect;
 import android.graphics.SurfaceTexture;
@@ -193,7 +194,7 @@
      * 
      * @return A {@link SurfaceTexture}
      */
-    abstract SurfaceTexture createSuraceTexture(HardwareLayer layer);
+    abstract SurfaceTexture createSurfaceTexture(HardwareLayer layer);
 
     /**
      * Updates the specified layer.
@@ -201,11 +202,19 @@
      * @param layer The hardware layer to update
      * @param width The layer's width
      * @param height The layer's height
-     * @param surface The surface to update
      */
-    abstract void updateTextureLayer(HardwareLayer layer, int width, int height,
-            SurfaceTexture surface);    
-    
+    abstract void updateTextureLayer(HardwareLayer layer, int width, int height);
+
+    /**
+     * Copies the content of the specified layer into the specified bitmap.
+     * 
+     * @param layer The hardware layer to copy
+     * @param bitmap The bitmap to copy the layer into
+     * 
+     * @return True if the copy was successful, false otherwise
+     */
+    abstract boolean copyLayer(HardwareLayer layer, Bitmap bitmap);    
+
     /**
      * Initializes the hardware renderer for the specified surface and setup the
      * renderer for drawing, if needed. This is invoked when the ViewAncestor has
@@ -311,6 +320,7 @@
         Paint mDebugPaint;
 
         boolean mDirtyRegions;
+        final boolean mDirtyRegionsRequested;
 
         final int mGlVersion;
         final boolean mTranslucent;
@@ -325,6 +335,7 @@
             final String dirtyProperty = SystemProperties.get(RENDER_DIRTY_REGIONS_PROPERTY, "true");
             //noinspection PointlessBooleanExpression,ConstantConditions
             mDirtyRegions = RENDER_DIRTY_REGIONS && "true".equalsIgnoreCase(dirtyProperty);
+            mDirtyRegionsRequested = mDirtyRegions;
         }
 
         /**
@@ -545,11 +556,21 @@
                 throw new Surface.OutOfResourcesException("eglMakeCurrent failed "
                         + getEGLErrorString(sEgl.eglGetError()));
             }
-            
+
+            // If mDirtyRegions is set, this means we have an EGL configuration
+            // with EGL_SWAP_BEHAVIOR_PRESERVED_BIT set
             if (mDirtyRegions) {
                 if (!GLES20Canvas.preserveBackBuffer()) {
                     Log.w(LOG_TAG, "Backbuffer cannot be preserved");
                 }
+            } else if (mDirtyRegionsRequested) {
+                // If mDirtyRegions is not set, our EGL configuration does not
+                // have EGL_SWAP_BEHAVIOR_PRESERVED_BIT; however, the default
+                // swap behavior might be EGL_BUFFER_PRESERVED, which means we
+                // want to set mDirtyRegions. We try to do this only if dirty
+                // regions were initially requested as part of the device
+                // configuration (see RENDER_DIRTY_REGIONS)
+                mDirtyRegions = GLES20Canvas.isBackBufferPreserved();
             }
 
             return sEglContext.getGL();
@@ -792,14 +813,18 @@
         }
 
         @Override
-        SurfaceTexture createSuraceTexture(HardwareLayer layer) {
+        SurfaceTexture createSurfaceTexture(HardwareLayer layer) {
             return ((GLES20TextureLayer) layer).getSurfaceTexture();
         }
 
         @Override
-        void updateTextureLayer(HardwareLayer layer, int width, int height,
-                SurfaceTexture surface) {
-            ((GLES20TextureLayer) layer).update(width, height, surface.mSurfaceTexture);
+        void updateTextureLayer(HardwareLayer layer, int width, int height) {
+            ((GLES20TextureLayer) layer).update(width, height);
+        }
+
+        @Override
+        boolean copyLayer(HardwareLayer layer, Bitmap bitmap) {
+            return ((GLES20Layer) layer).copyInto(bitmap);
         }
 
         static HardwareRenderer create(boolean translucent) {
diff --git a/core/java/android/view/IWindowManager.aidl b/core/java/android/view/IWindowManager.aidl
index adafb59..ad17edf 100644
--- a/core/java/android/view/IWindowManager.aidl
+++ b/core/java/android/view/IWindowManager.aidl
@@ -19,6 +19,7 @@
 import com.android.internal.view.IInputContext;
 import com.android.internal.view.IInputMethodClient;
 
+import android.content.res.CompatibilityInfo;
 import android.content.res.Configuration;
 import android.graphics.Bitmap;
 import android.graphics.Point;
@@ -59,6 +60,9 @@
     void setForcedDisplaySize(int longDimen, int shortDimen);
     void clearForcedDisplaySize();
 
+    // Is device configured with a hideable status bar or a tablet system bar?
+    boolean canStatusBarHide();
+
     // These can only be called when injecting events to your own window,
     // or by holding the INJECT_EVENTS permission.  These methods may block
     // until pending input events are finished being dispatched even when 'sync' is false.
@@ -85,7 +89,7 @@
     void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim);
     void executeAppTransition();
     void setAppStartingWindow(IBinder token, String pkg, int theme,
-            CharSequence nonLocalizedLabel, int labelRes,
+            in CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
             int icon, int windowFlags, IBinder transferFrom, boolean createIfNeeded);
     void setAppWillBeHidden(IBinder token);
     void setAppVisibility(IBinder token, boolean visible);
@@ -201,4 +205,9 @@
      * Called by the status bar to notify Views of changes to System UI visiblity.
      */
     void statusBarVisibilityChanged(int visibility);
+
+    /**
+     * Called by the settings application to temporarily set the pointer speed.
+     */
+    void setPointerSpeed(int speed);
 }
diff --git a/core/java/android/view/MenuItem.java b/core/java/android/view/MenuItem.java
index 780c52e..dc68264 100644
--- a/core/java/android/view/MenuItem.java
+++ b/core/java/android/view/MenuItem.java
@@ -51,6 +51,13 @@
      * it also has an icon specified.
      */
     public static final int SHOW_AS_ACTION_WITH_TEXT = 4;
+
+    /**
+     * This item's action view collapses to a normal menu item.
+     * When expanded, the action view temporarily takes over
+     * a larger segment of its container.
+     */
+    public static final int SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW = 8;
     
     /**
      * Interface definition for a callback to be invoked when a menu item is
@@ -74,6 +81,34 @@
     }
 
     /**
+     * Interface definition for a callback to be invoked when a menu item
+     * marked with {@link MenuItem#SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW} is
+     * expanded or collapsed.
+     *
+     * @see MenuItem#expandActionView()
+     * @see MenuItem#collapseActionView()
+     * @see MenuItem#setShowAsActionFlags(int)
+     * @see MenuItem#
+     */
+    public interface OnActionExpandListener {
+        /**
+         * Called when a menu item with {@link MenuItem#SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW}
+         * is expanded.
+         * @param item Item that was expanded
+         * @return true if the item should expand, false if expansion should be suppressed.
+         */
+        public boolean onMenuItemActionExpand(MenuItem item);
+
+        /**
+         * Called when a menu item with {@link MenuItem#SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW}
+         * is collapsed.
+         * @param item Item that was collapsed
+         * @return true if the item should collapse, false if collapsing should be suppressed.
+         */
+        public boolean onMenuItemActionCollapse(MenuItem item);
+    }
+
+    /**
      * Return the identifier for this menu item.  The identifier can not
      * be changed after the menu is created.
      *
@@ -421,6 +456,27 @@
     public void setShowAsAction(int actionEnum);
 
     /**
+     * Sets how this item should display in the presence of an Action Bar.
+     * The parameter actionEnum is a flag set. One of {@link #SHOW_AS_ACTION_ALWAYS},
+     * {@link #SHOW_AS_ACTION_IF_ROOM}, or {@link #SHOW_AS_ACTION_NEVER} should
+     * be used, and you may optionally OR the value with {@link #SHOW_AS_ACTION_WITH_TEXT}.
+     * SHOW_AS_ACTION_WITH_TEXT requests that when the item is shown as an action,
+     * it should be shown with a text label.
+     *
+     * <p>Note: This method differs from {@link #setShowAsAction(int)} only in that it
+     * returns the current MenuItem instance for call chaining.
+     *
+     * @param actionEnum How the item should display. One of
+     * {@link #SHOW_AS_ACTION_ALWAYS}, {@link #SHOW_AS_ACTION_IF_ROOM}, or
+     * {@link #SHOW_AS_ACTION_NEVER}. SHOW_AS_ACTION_NEVER is the default.
+     *
+     * @see android.app.ActionBar
+     * @see #setActionView(View)
+     * @return This MenuItem instance for call chaining.
+     */
+    public MenuItem setShowAsActionFlags(int actionEnum);
+
+    /**
      * Set an action view for this menu item. An action view will be displayed in place
      * of an automatically generated menu item element in the UI when this item is shown
      * as an action within a parent.
@@ -453,4 +509,52 @@
      * @see #setShowAsAction(int)
      */
     public View getActionView();
+
+    /**
+     * Expand the action view associated with this menu item.
+     * The menu item must have an action view set, as well as
+     * the showAsAction flag {@link #SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW}.
+     * If a listener has been set using {@link #setOnActionExpandListener(OnActionExpandListener)}
+     * it will have its {@link OnActionExpandListener#onMenuItemActionExpand(MenuItem)}
+     * method invoked. The listener may return false from this method to prevent expanding
+     * the action view.
+     *
+     * @return true if the action view was expanded, false otherwise.
+     */
+    public boolean expandActionView();
+
+    /**
+     * Collapse the action view associated with this menu item.
+     * The menu item must have an action view set, as well as the showAsAction flag
+     * {@link #SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW}. If a listener has been set using
+     * {@link #setOnActionExpandListener(OnActionExpandListener)} it will have its
+     * {@link OnActionExpandListener#onMenuItemActionCollapse(MenuItem)} method invoked.
+     * The listener may return false from this method to prevent collapsing the action view.
+     *
+     * @return true if the action view was collapsed, false otherwise.
+     */
+    public boolean collapseActionView();
+
+    /**
+     * Returns true if this menu item's action view has been expanded.
+     *
+     * @return true if the item's action view is expanded, false otherwise.
+     *
+     * @see #expandActionView()
+     * @see #collapseActionView()
+     * @see #SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW
+     * @see OnActionExpandListener
+     */
+    public boolean isActionViewExpanded();
+
+    /**
+     * Set an {@link OnActionExpandListener} on this menu item to be notified when
+     * the associated action view is expanded or collapsed. The menu item must
+     * be configured to expand or collapse its action view using the flag
+     * {@link #SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW}.
+     *
+     * @param listener Listener that will respond to expand/collapse events
+     * @return This menu item instance for call chaining
+     */
+    public MenuItem setOnActionExpandListener(OnActionExpandListener listener);
 }
\ No newline at end of file
diff --git a/core/java/android/view/ScaleGestureDetector.java b/core/java/android/view/ScaleGestureDetector.java
index 5e07e1a..5d2c1a7 100644
--- a/core/java/android/view/ScaleGestureDetector.java
+++ b/core/java/android/view/ScaleGestureDetector.java
@@ -340,6 +340,15 @@
                         // Set focus point to the remaining finger
                         final int index = event.findPointerIndex(actionId == mActiveId0 ?
                                 mActiveId1 : mActiveId0);
+                        if (index < 0) {
+                            mInvalidGesture = true;
+                            Log.e(TAG, "Invalid MotionEvent stream detected.", new Throwable());
+                            if (mGestureInProgress) {
+                                mListener.onScaleEnd(this);
+                            }
+                            return false;
+                        }
+
                         mActiveId0 = event.getPointerId(index);
 
                         mActive0MostRecent = true;
diff --git a/core/java/android/view/TextureView.java b/core/java/android/view/TextureView.java
index 755ecf5..0421205 100644
--- a/core/java/android/view/TextureView.java
+++ b/core/java/android/view/TextureView.java
@@ -17,6 +17,7 @@
 package android.view;
 
 import android.content.Context;
+import android.graphics.Bitmap;
 import android.graphics.Canvas;
 import android.graphics.Paint;
 import android.graphics.SurfaceTexture;
@@ -56,14 +57,7 @@
  *          setContentView(mTextureView);
  *      }
  *
- *      protected void onDestroy() {
- *          super.onDestroy();
- *
- *          mCamera.stopPreview();
- *          mCamera.release();
- *      }
- *
- *      public void onSurfaceTextureAvailable(SurfaceTexture surface) {
+ *      public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
  *          mCamera = Camera.open();
  *
  *          try {
@@ -77,6 +71,11 @@
  *      public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
  *          // Ignored, Camera does all the work for us
  *      }
+ *      
+ *      public void onSurfaceTextureDestroyed(SurfaceTexture surface) {
+ *          mCamera.stopPreview();
+ *          mCamera.release();
+ *      }
  *  }
  * </pre>
  * 
@@ -91,6 +90,8 @@
  * @see SurfaceTexture
  */
 public class TextureView extends View {
+    private static final String LOG_TAG = "TextureView";
+
     private HardwareLayer mLayer;
     private SurfaceTexture mSurface;
     private SurfaceTextureListener mListener;
@@ -150,11 +151,26 @@
         super.onAttachedToWindow();
 
         if (!isHardwareAccelerated()) {
-            Log.w("TextureView", "A TextureView or a subclass can only be "
+            Log.w(LOG_TAG, "A TextureView or a subclass can only be "
                     + "used with hardware acceleration enabled.");
         }
     }
 
+    @Override
+    protected void onDetachedFromWindow() {
+        super.onDetachedFromWindow();
+
+        if (isHardwareAccelerated() && mLayer != null) {
+            if (mListener != null) {
+                mListener.onSurfaceTextureDestroyed(mSurface);
+            }
+
+            mLayer.destroy();            
+            mSurface = null;
+            mLayer = null;
+        }
+    }
+
     /**
      * The layer type of a TextureView is ignored since a TextureView is always
      * considered to act as a hardware layer. The optional paint supplied to this
@@ -216,7 +232,10 @@
     protected void onSizeChanged(int w, int h, int oldw, int oldh) {
         super.onSizeChanged(w, h, oldw, oldh);
         if (mSurface != null) {
-            nSetDefaultBufferSize(mSurface.mSurfaceTexture, getWidth(), getHeight());
+            nSetDefaultBufferSize(mSurface, getWidth(), getHeight());
+            if (mListener != null) {
+                mListener.onSurfaceTextureSizeChanged(mSurface, getWidth(), getHeight());
+            }
         }
     }
 
@@ -228,8 +247,8 @@
 
         if (mLayer == null) {
             mLayer = mAttachInfo.mHardwareRenderer.createHardwareLayer();
-            mSurface = mAttachInfo.mHardwareRenderer.createSuraceTexture(mLayer);
-            nSetDefaultBufferSize(mSurface.mSurfaceTexture, getWidth(), getHeight());
+            mSurface = mAttachInfo.mHardwareRenderer.createSurfaceTexture(mLayer);
+            nSetDefaultBufferSize(mSurface, getWidth(), getHeight());
 
             mUpdateListener = new SurfaceTexture.OnFrameAvailableListener() {
                 @Override
@@ -242,7 +261,7 @@
             mSurface.setOnFrameAvailableListener(mUpdateListener);
 
             if (mListener != null) {
-                mListener.onSurfaceTextureAvailable(mSurface);
+                mListener.onSurfaceTextureAvailable(mSurface, getWidth(), getHeight());
             }
         }
 
@@ -271,14 +290,107 @@
             return;
         }
 
-        mAttachInfo.mHardwareRenderer.updateTextureLayer(mLayer, getWidth(), getHeight(), mSurface);
+        mAttachInfo.mHardwareRenderer.updateTextureLayer(mLayer, getWidth(), getHeight());
 
         invalidate();
     }
 
     /**
+     * <p>Returns a {@link android.graphics.Bitmap} representation of the content
+     * of the associated surface texture. If the surface texture is not available,
+     * this method returns null.</p>
+     * 
+     * <p>The bitmap returned by this method uses the {@link Bitmap.Config#ARGB_8888}
+     * pixel format and its dimensions are the same as this view's.</p>
+     * 
+     * <p><strong>Do not</strong> invoke this method from a drawing method
+     * ({@link #onDraw(android.graphics.Canvas)} for instance).</p>
+     * 
+     * <p>If an error occurs during the copy, an empty bitmap will be returned.</p>
+     * 
+     * @return A valid {@link Bitmap.Config#ARGB_8888} bitmap, or null if the surface
+     *         texture is not available or the width &lt;= 0 or the height &lt;= 0
+     * 
+     * @see #isAvailable() 
+     * @see #getBitmap(android.graphics.Bitmap) 
+     * @see #getBitmap(int, int) 
+     */
+    public Bitmap getBitmap() {
+        return getBitmap(getWidth(), getHeight());
+    }
+
+    /**
+     * <p>Returns a {@link android.graphics.Bitmap} representation of the content
+     * of the associated surface texture. If the surface texture is not available,
+     * this method returns null.</p>
+     * 
+     * <p>The bitmap returned by this method uses the {@link Bitmap.Config#ARGB_8888}
+     * pixel format.</p>
+     * 
+     * <p><strong>Do not</strong> invoke this method from a drawing method
+     * ({@link #onDraw(android.graphics.Canvas)} for instance).</p>
+     * 
+     * <p>If an error occurs during the copy, an empty bitmap will be returned.</p>
+     * 
+     * @param width The width of the bitmap to create
+     * @param height The height of the bitmap to create
+     * 
+     * @return A valid {@link Bitmap.Config#ARGB_8888} bitmap, or null if the surface
+     *         texture is not available or width is &lt;= 0 or height is &lt;= 0
+     * 
+     * @see #isAvailable() 
+     * @see #getBitmap(android.graphics.Bitmap) 
+     * @see #getBitmap() 
+     */
+    public Bitmap getBitmap(int width, int height) {
+        if (isAvailable() && width > 0 && height > 0) {
+            return getBitmap(Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888));
+        }
+        return null;
+    }
+
+    /**
+     * <p>Copies the content of this view's surface texture into the specified
+     * bitmap. If the surface texture is not available, the copy is not executed.
+     * The content of the surface texture will be scaled to fit exactly inside
+     * the specified bitmap.</p>
+     * 
+     * <p><strong>Do not</strong> invoke this method from a drawing method
+     * ({@link #onDraw(android.graphics.Canvas)} for instance).</p>
+     * 
+     * <p>If an error occurs, the bitmap is left unchanged.</p>
+     * 
+     * @param bitmap The bitmap to copy the content of the surface texture into,
+     *               cannot be null, all configurations are supported
+     * 
+     * @return The bitmap specified as a parameter
+     * 
+     * @see #isAvailable() 
+     * @see #getBitmap(int, int)  
+     * @see #getBitmap() 
+     */
+    public Bitmap getBitmap(Bitmap bitmap) {
+        if (bitmap != null && isAvailable()) {
+            mAttachInfo.mHardwareRenderer.copyLayer(mLayer, bitmap);
+        }
+        return bitmap;
+    }
+
+    /**
+     * Returns true if the {@link SurfaceTexture} associated with this
+     * TextureView is available for rendering. When this method returns
+     * true, {@link #getSurfaceTexture()} returns a valid surface texture.
+     */
+    public boolean isAvailable() {
+        return mSurface != null;
+    }
+
+    /**
      * Returns the {@link SurfaceTexture} used by this view. This method
-     * may return null if the view is not attached to a window.
+     * may return null if the view is not attached to a window or if the surface
+     * texture has not been initialized yet.
+     * 
+     * @see #isAvailable() 
      */
     public SurfaceTexture getSurfaceTexture() {
         return mSurface;
@@ -316,8 +428,10 @@
          * 
          * @param surface The surface returned by
          *                {@link android.view.TextureView#getSurfaceTexture()}
+         * @param width The width of the surface
+         * @param height The height of the surface
          */
-        public void onSurfaceTextureAvailable(SurfaceTexture surface);
+        public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height);
 
         /**
          * Invoked when the {@link SurfaceTexture}'s buffers size changed.
@@ -328,7 +442,17 @@
          * @param height The new height of the surface
          */
         public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height);
+
+        /**
+         * Invoked when the specified {@link SurfaceTexture} is about to be destroyed.
+         * After this method is invoked, no rendering should happen inside the surface
+         * texture.
+         * 
+         * @param surface The surface about to be destroyed
+         */
+        public void onSurfaceTextureDestroyed(SurfaceTexture surface);
     }
 
-    private static native void nSetDefaultBufferSize(int surfaceTexture, int width, int height);
+    private static native void nSetDefaultBufferSize(SurfaceTexture surfaceTexture,
+            int width, int height);
 }
diff --git a/core/java/android/view/VelocityTracker.java b/core/java/android/view/VelocityTracker.java
index fccef2b..5a91d31 100644
--- a/core/java/android/view/VelocityTracker.java
+++ b/core/java/android/view/VelocityTracker.java
@@ -50,6 +50,7 @@
 
     private int mPtr;
     private VelocityTracker mNext;
+    private boolean mIsPooled;
 
     private static native int nativeInitialize();
     private static native void nativeDispose(int ptr);
@@ -93,6 +94,20 @@
         return mNext;
     }
 
+    /**
+     * @hide
+     */
+    public boolean isPooled() {
+        return mIsPooled;
+    }
+
+    /**
+     * @hide
+     */
+    public void setPooled(boolean isPooled) {
+        mIsPooled = isPooled;
+    }
+
     private VelocityTracker() {
         mPtr = nativeInitialize();
     }
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 017e5e3..46df88b 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -16,6 +16,9 @@
 
 package android.view;
 
+import android.util.FloatProperty;
+import android.util.LocaleUtil;
+import android.util.Property;
 import com.android.internal.R;
 import com.android.internal.util.Predicate;
 import com.android.internal.view.menu.MenuBuilder;
@@ -61,6 +64,7 @@
 import android.view.accessibility.AccessibilityEvent;
 import android.view.accessibility.AccessibilityEventSource;
 import android.view.accessibility.AccessibilityManager;
+import android.view.accessibility.AccessibilityNodeInfo;
 import android.view.animation.Animation;
 import android.view.animation.AnimationUtils;
 import android.view.inputmethod.EditorInfo;
@@ -73,6 +77,7 @@
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Locale;
 import java.util.WeakHashMap;
 import java.util.concurrent.CopyOnWriteArrayList;
 
@@ -340,7 +345,7 @@
  * 2 pixels to the right of the left edge. Padding can be set using the
  * {@link #setPadding(int, int, int, int)} method and queried by calling
  * {@link #getPaddingLeft()}, {@link #getPaddingTop()},
- * {@link #getPaddingRight()} and {@link #getPaddingBottom()}.
+ * {@link #getPaddingRight()}, {@link #getPaddingBottom()}.
  * </p>
  *
  * <p>
@@ -602,6 +607,8 @@
  * @attr ref android.R.styleable#View_paddingLeft
  * @attr ref android.R.styleable#View_paddingRight
  * @attr ref android.R.styleable#View_paddingTop
+ * @attr ref android.R.styleable#View_paddingStart
+ * @attr ref android.R.styleable#View_paddingEnd
  * @attr ref android.R.styleable#View_saveEnabled
  * @attr ref android.R.styleable#View_rotation
  * @attr ref android.R.styleable#View_rotationX
@@ -950,40 +957,51 @@
 
     /**
      * Horizontal direction of this view is from Left to Right.
-     * Use with {@link #setHorizontalDirection}.
+     * Use with {@link #setLayoutDirection}.
      * {@hide}
      */
-    public static final int HORIZONTAL_DIRECTION_LTR = 0x00000000;
+    public static final int LAYOUT_DIRECTION_LTR = 0x00000000;
 
     /**
      * Horizontal direction of this view is from Right to Left.
-     * Use with {@link #setHorizontalDirection}.
+     * Use with {@link #setLayoutDirection}.
      * {@hide}
      */
-    public static final int HORIZONTAL_DIRECTION_RTL = 0x40000000;
+    public static final int LAYOUT_DIRECTION_RTL = 0x40000000;
 
     /**
      * Horizontal direction of this view is inherited from its parent.
-     * Use with {@link #setHorizontalDirection}.
+     * Use with {@link #setLayoutDirection}.
      * {@hide}
      */
-    public static final int HORIZONTAL_DIRECTION_INHERIT = 0x80000000;
+    public static final int LAYOUT_DIRECTION_INHERIT = 0x80000000;
 
     /**
      * Horizontal direction of this view is from deduced from the default language
-     * script for the locale. Use with {@link #setHorizontalDirection}.
+     * script for the locale. Use with {@link #setLayoutDirection}.
      * {@hide}
      */
-    public static final int HORIZONTAL_DIRECTION_LOCALE = 0xC0000000;
+    public static final int LAYOUT_DIRECTION_LOCALE = 0xC0000000;
 
     /**
      * Mask for use with setFlags indicating bits used for horizontalDirection.
      * {@hide}
      */
-    static final int HORIZONTAL_DIRECTION_MASK = 0xC0000000;
+    static final int LAYOUT_DIRECTION_MASK = 0xC0000000;
 
-    private static final int[] HORIZONTAL_DIRECTION_FLAGS = { HORIZONTAL_DIRECTION_LTR,
-            HORIZONTAL_DIRECTION_RTL, HORIZONTAL_DIRECTION_INHERIT, HORIZONTAL_DIRECTION_LOCALE};
+    /*
+     * Array of horizontal direction flags for mapping attribute "horizontalDirection" to correct
+     * flag value.
+     * {@hide}
+     */
+    private static final int[] LAYOUT_DIRECTION_FLAGS = {LAYOUT_DIRECTION_LTR,
+        LAYOUT_DIRECTION_RTL, LAYOUT_DIRECTION_INHERIT, LAYOUT_DIRECTION_LOCALE};
+
+    /**
+     * Default horizontalDirection.
+     * {@hide}
+     */
+    private static final int LAYOUT_DIRECTION_DEFAULT = LAYOUT_DIRECTION_INHERIT;
 
     /**
      * View flag indicating whether {@link #addFocusables(ArrayList, int, int)}
@@ -1481,6 +1499,11 @@
     private static final Object sTagsLock = new Object();
 
     /**
+     * The next available accessiiblity id.
+     */
+    private static int sNextAccessibilityViewId;
+
+    /**
      * The animation currently associated with this view.
      * @hide
      */
@@ -1522,6 +1545,11 @@
     int mID = NO_ID;
 
     /**
+     * The stable ID of this view for accessibility porposes.
+     */
+    int mAccessibilityViewId = NO_ID;
+
+    /**
      * The view's tag.
      * {@hide}
      *
@@ -1708,11 +1736,20 @@
     static final int DRAG_HOVERED                 = 0x00000002;
 
     /**
-     * Indicates whether the view is drawn in right-to-left direction.
+     * Indicates whether the view layout direction has been resolved and drawn to the
+     * right-to-left direction.
      *
      * @hide
      */
-    static final int RESOLVED_LAYOUT_RTL          = 0x00000004;
+    static final int LAYOUT_DIRECTION_RESOLVED_RTL = 0x00000004;
+
+    /**
+     * Indicates whether the view layout direction has been resolved.
+     *
+     * @hide
+     */
+    static final int LAYOUT_DIRECTION_RESOLVED = 0x00000008;
+
 
     /* End of masks for mPrivateFlags2 */
 
@@ -2147,6 +2184,33 @@
     int mUserPaddingLeft;
 
     /**
+     * Cache the paddingTop set by the user to append to the scrollbar's size.
+     */
+    @ViewDebug.ExportedProperty(category = "padding")
+    int mUserPaddingTop;
+
+    /**
+     * Cache if the user padding is relative.
+     *
+     */
+    @ViewDebug.ExportedProperty(category = "padding")
+    boolean mUserPaddingRelative;
+
+    /**
+     * Cache the paddingStart set by the user to append to the scrollbar's size.
+     *
+     */
+    @ViewDebug.ExportedProperty(category = "padding")
+    int mUserPaddingStart;
+
+    /**
+     * Cache the paddingEnd set by the user to append to the scrollbar's size.
+     *
+     */
+    @ViewDebug.ExportedProperty(category = "padding")
+    int mUserPaddingEnd;
+
+    /**
      * @hide
      */
     int mOldWidthMeasureSpec = Integer.MIN_VALUE;
@@ -2442,7 +2506,7 @@
     public View(Context context) {
         mContext = context;
         mResources = context != null ? context.getResources() : null;
-        mViewFlags = SOUND_EFFECTS_ENABLED | HAPTIC_FEEDBACK_ENABLED;
+        mViewFlags = SOUND_EFFECTS_ENABLED | HAPTIC_FEEDBACK_ENABLED | LAYOUT_DIRECTION_INHERIT;
         mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
         setOverScrollMode(OVER_SCROLL_IF_CONTENT_SCROLLS);
     }
@@ -2497,6 +2561,8 @@
         int topPadding = -1;
         int rightPadding = -1;
         int bottomPadding = -1;
+        int startPadding = -1;
+        int endPadding = -1;
 
         int padding = -1;
 
@@ -2542,6 +2608,12 @@
                 case com.android.internal.R.styleable.View_paddingBottom:
                     bottomPadding = a.getDimensionPixelSize(attr, -1);
                     break;
+                case com.android.internal.R.styleable.View_paddingStart:
+                    startPadding = a.getDimensionPixelSize(attr, -1);
+                    break;
+                case com.android.internal.R.styleable.View_paddingEnd:
+                    endPadding = a.getDimensionPixelSize(attr, -1);
+                    break;
                 case com.android.internal.R.styleable.View_scrollX:
                     x = a.getDimensionPixelOffset(attr, 0);
                     break;
@@ -2640,13 +2712,19 @@
                         viewFlagMasks |= VISIBILITY_MASK;
                     }
                     break;
-                case com.android.internal.R.styleable.View_horizontalDirection:
-                  final int layoutDirection = a.getInt(attr, 0);
-                  if (layoutDirection != 0) {
-                      viewFlagValues |= HORIZONTAL_DIRECTION_FLAGS[layoutDirection];
-                      viewFlagMasks |= HORIZONTAL_DIRECTION_MASK;
-                  }
-                  break;
+                case com.android.internal.R.styleable.View_layoutDirection:
+                    // Clear any HORIZONTAL_DIRECTION flag already set
+                    viewFlagValues &= ~LAYOUT_DIRECTION_MASK;
+                    // Set the HORIZONTAL_DIRECTION flags depending on the value of the attribute
+                    final int layoutDirection = a.getInt(attr, -1);
+                    if (layoutDirection != -1) {
+                        viewFlagValues |= LAYOUT_DIRECTION_FLAGS[layoutDirection];
+                    } else {
+                        // Set to default (LAYOUT_DIRECTION_INHERIT)
+                        viewFlagValues |= LAYOUT_DIRECTION_DEFAULT;
+                    }
+                    viewFlagMasks |= LAYOUT_DIRECTION_MASK;
+                    break;
                 case com.android.internal.R.styleable.View_drawingCacheQuality:
                     final int cacheQuality = a.getInt(attr, 0);
                     if (cacheQuality != 0) {
@@ -2790,11 +2868,15 @@
             setBackgroundDrawable(background);
         }
 
+        mUserPaddingRelative = (startPadding >= 0 || endPadding >= 0);
+
         if (padding >= 0) {
             leftPadding = padding;
             topPadding = padding;
             rightPadding = padding;
             bottomPadding = padding;
+            startPadding = padding;
+            endPadding = padding;
         }
 
         // If the user specified the padding (either with android:padding or
@@ -2806,6 +2888,15 @@
                 rightPadding >= 0 ? rightPadding : mPaddingRight,
                 bottomPadding >= 0 ? bottomPadding : mPaddingBottom);
 
+        // Cache user padding as we cannot fully resolve padding here (we dont have yet the resolved
+        // layout direction). Those cached values will be used later during padding resolution.
+        mUserPaddingLeft = leftPadding;
+        mUserPaddingRight = rightPadding;
+        mUserPaddingStart = startPadding;
+        mUserPaddingEnd = endPadding;
+        mUserPaddingTop = topPadding;
+        mUserPaddingBottom = bottomPadding;
+
         if (viewFlagMasks != 0) {
             setFlags(viewFlagValues, viewFlagMasks);
         }
@@ -3027,7 +3118,7 @@
         }
 
         // Re-apply user/background padding so that scrollbar(s) get added
-        recomputePadding();
+        resolvePadding();
     }
 
     /**
@@ -3052,7 +3143,7 @@
         if (mVerticalScrollbarPosition != position) {
             mVerticalScrollbarPosition = position;
             computeOpaqueFlags();
-            recomputePadding();
+            resolvePadding();
         }
     }
 
@@ -3632,6 +3723,7 @@
      * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent)
      */
     public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
+        event.setSource(this);
         event.setClassName(getClass().getName());
         event.setPackageName(getContext().getPackageName());
         event.setEnabled(isEnabled());
@@ -3647,6 +3739,118 @@
     }
 
     /**
+     * Returns an {@link AccessibilityNodeInfo} representing this view from the
+     * point of view of an {@link android.accessibilityservice.AccessibilityService}.
+     * This method is responsible for obtaining an accessibility node info from a
+     * pool of reusable instances and calling
+     * {@link #onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)} on this view to
+     * initialize the former.
+     * <p>
+     * Note: The client is responsible for recycling the obtained instance by calling
+     *       {@link AccessibilityNodeInfo#recycle()} to minimize object creation.
+     * </p>
+     * @return A populated {@link AccessibilityNodeInfo}.
+     *
+     * @see AccessibilityNodeInfo
+     */
+    public AccessibilityNodeInfo createAccessibilityNodeInfo() {
+        AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain(this);
+        onInitializeAccessibilityNodeInfo(info);
+        return info;
+    }
+
+    /**
+     * Initializes an {@link AccessibilityNodeInfo} with information about this view.
+     * The base implementation sets:
+     * <ul>
+     *   <li>{@link AccessibilityNodeInfo#setParent(View)},</li>
+     *   <li>{@link AccessibilityNodeInfo#setBoundsInParent(Rect)},</li>
+     *   <li>{@link AccessibilityNodeInfo#setBoundsInScreen(Rect)},</li>
+     *   <li>{@link AccessibilityNodeInfo#setPackageName(CharSequence)},</li>
+     *   <li>{@link AccessibilityNodeInfo#setClassName(CharSequence)},</li>
+     *   <li>{@link AccessibilityNodeInfo#setContentDescription(CharSequence)},</li>
+     *   <li>{@link AccessibilityNodeInfo#setEnabled(boolean)},</li>
+     *   <li>{@link AccessibilityNodeInfo#setClickable(boolean)},</li>
+     *   <li>{@link AccessibilityNodeInfo#setFocusable(boolean)},</li>
+     *   <li>{@link AccessibilityNodeInfo#setFocused(boolean)},</li>
+     *   <li>{@link AccessibilityNodeInfo#setLongClickable(boolean)},</li>
+     *   <li>{@link AccessibilityNodeInfo#setSelected(boolean)},</li>
+     * </ul>
+     * <p>
+     * Subclasses should override this method, call the super implementation,
+     * and set additional attributes.
+     * </p>
+     * @param info The instance to initialize.
+     */
+    public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
+        Rect bounds = mAttachInfo.mTmpInvalRect;
+        getDrawingRect(bounds);
+        info.setBoundsInParent(bounds);
+
+        int[] locationOnScreen = mAttachInfo.mInvalidateChildLocation;
+        getLocationOnScreen(locationOnScreen);
+        bounds.offset(locationOnScreen[0], locationOnScreen[1]);
+        info.setBoundsInScreen(bounds);
+
+        ViewParent parent = getParent();
+        if (parent instanceof View) {
+            View parentView = (View) parent;
+            info.setParent(parentView);
+        }
+
+        info.setPackageName(mContext.getPackageName());
+        info.setClassName(getClass().getName());
+        info.setContentDescription(getContentDescription());
+
+        info.setEnabled(isEnabled());
+        info.setClickable(isClickable());
+        info.setFocusable(isFocusable());
+        info.setFocused(isFocused());
+        info.setSelected(isSelected());
+        info.setLongClickable(isLongClickable());
+
+        // TODO: These make sense only if we are in an AdapterView but all
+        // views can be selected. Maybe from accessiiblity perspective
+        // we should report as selectable view in an AdapterView.
+        info.addAction(AccessibilityNodeInfo.ACTION_SELECT);
+        info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_SELECTION);
+
+        if (isFocusable()) {
+            if (isFocused()) {
+                info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_FOCUS);
+            } else {
+                info.addAction(AccessibilityNodeInfo.ACTION_FOCUS);
+            }
+        }
+    }
+
+    /**
+     * Gets the unique identifier of this view on the screen for accessibility purposes.
+     * If this {@link View} is not attached to any window, {@value #NO_ID} is returned.
+     *
+     * @return The view accessibility id.
+     *
+     * @hide
+     */
+    public int getAccessibilityViewId() {
+        if (mAccessibilityViewId == NO_ID) {
+            mAccessibilityViewId = sNextAccessibilityViewId++;
+        }
+        return mAccessibilityViewId;
+    }
+
+    /**
+     * Gets the unique identifier of the window in which this View reseides.
+     *
+     * @return The window accessibility id.
+     *
+     * @hide
+     */
+    public int getAccessibilityWindowId() {
+        return mAttachInfo != null ? mAttachInfo.mAccessibilityWindowId : NO_ID;
+    }
+
+    /**
      * Gets the {@link View} description. It briefly describes the view and is
      * primarily used for accessibility support. Set this property to enable
      * better accessibility support for your application. This is especially
@@ -4121,38 +4325,71 @@
     }
 
     /**
-     * Returns the horizontal direction for this view.
+     * Returns the layout direction for this view.
      *
-     * @return One of {@link #HORIZONTAL_DIRECTION_LTR},
-     *   {@link #HORIZONTAL_DIRECTION_RTL},
-     *   {@link #HORIZONTAL_DIRECTION_INHERIT} or
-     *   {@link #HORIZONTAL_DIRECTION_LOCALE}.
-     * @attr ref android.R.styleable#View_horizontalDirection
+     * @return One of {@link #LAYOUT_DIRECTION_LTR},
+     *   {@link #LAYOUT_DIRECTION_RTL},
+     *   {@link #LAYOUT_DIRECTION_INHERIT} or
+     *   {@link #LAYOUT_DIRECTION_LOCALE}.
+     * @attr ref android.R.styleable#View_layoutDirection
+     *
      * @hide
      */
-    @ViewDebug.ExportedProperty(mapping = {
-        @ViewDebug.IntToString(from = HORIZONTAL_DIRECTION_LTR,     to = "LTR"),
-        @ViewDebug.IntToString(from = HORIZONTAL_DIRECTION_RTL,     to = "RTL"),
-        @ViewDebug.IntToString(from = HORIZONTAL_DIRECTION_INHERIT, to = "INHERIT"),
-        @ViewDebug.IntToString(from = HORIZONTAL_DIRECTION_LOCALE,  to = "LOCALE")
+    @ViewDebug.ExportedProperty(category = "layout", mapping = {
+        @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LTR,     to = "LTR"),
+        @ViewDebug.IntToString(from = LAYOUT_DIRECTION_RTL,     to = "RTL"),
+        @ViewDebug.IntToString(from = LAYOUT_DIRECTION_INHERIT, to = "INHERIT"),
+        @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LOCALE,  to = "LOCALE")
     })
-    public int getHorizontalDirection() {
-        return mViewFlags & HORIZONTAL_DIRECTION_MASK;
+    public int getLayoutDirection() {
+        return mViewFlags & LAYOUT_DIRECTION_MASK;
     }
 
     /**
-     * Set the horizontal direction for this view.
+     * Set the layout direction for this view.
      *
-     * @param horizontalDirection One of {@link #HORIZONTAL_DIRECTION_LTR},
-     *   {@link #HORIZONTAL_DIRECTION_RTL},
-     *   {@link #HORIZONTAL_DIRECTION_INHERIT} or
-     *   {@link #HORIZONTAL_DIRECTION_LOCALE}.
-     * @attr ref android.R.styleable#View_horizontalDirection
+     * @param layoutDirection One of {@link #LAYOUT_DIRECTION_LTR},
+     *   {@link #LAYOUT_DIRECTION_RTL},
+     *   {@link #LAYOUT_DIRECTION_INHERIT} or
+     *   {@link #LAYOUT_DIRECTION_LOCALE}.
+     * @attr ref android.R.styleable#View_layoutDirection
+     *
      * @hide
      */
     @RemotableViewMethod
-    public void setHorizontalDirection(int horizontalDirection) {
-        setFlags(horizontalDirection, HORIZONTAL_DIRECTION_MASK);
+    public void setLayoutDirection(int layoutDirection) {
+        setFlags(layoutDirection, LAYOUT_DIRECTION_MASK);
+    }
+
+    /**
+     * Returns the resolved layout direction for this view.
+     *
+     * @return {@link #LAYOUT_DIRECTION_RTL} if the layout direction is RTL or returns
+     * {@link #LAYOUT_DIRECTION_LTR} id the layout direction is not RTL.
+     *
+     * @hide
+     */
+    @ViewDebug.ExportedProperty(category = "layout", mapping = {
+        @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LTR,     to = "RESOLVED_DIRECTION_LTR"),
+        @ViewDebug.IntToString(from = LAYOUT_DIRECTION_RTL,     to = "RESOLVED_DIRECTION_RTL")
+    })
+    public int getResolvedLayoutDirection() {
+        resolveLayoutDirectionIfNeeded();
+        return ((mPrivateFlags2 & LAYOUT_DIRECTION_RESOLVED_RTL) == LAYOUT_DIRECTION_RESOLVED_RTL) ?
+                LAYOUT_DIRECTION_RTL : LAYOUT_DIRECTION_LTR;
+    }
+
+    /**
+     * <p>Indicates whether or not this view's layout is right-to-left. This is resolved from
+     * layout attribute and/or the inherited value from the parent.</p>
+     *
+     * @return true if the layout is right-to-left.
+     *
+     * @hide
+     */
+    @ViewDebug.ExportedProperty(category = "layout")
+    public boolean isLayoutRtl() {
+        return (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL);
     }
 
     /**
@@ -4554,6 +4791,16 @@
     }
 
     /**
+     * Finds the Views that contain given text. The containment is case insensitive.
+     * As View's text is considered any text content that View renders.
+     *
+     * @param outViews The output list of matching Views.
+     * @param text The text to match against.
+     */
+    public void findViewsWithText(ArrayList<View> outViews, CharSequence text) {
+    }
+
+    /**
      * Find and return all touchable views that are descendants of this view,
      * possibly including this view if it is touchable itself.
      *
@@ -4660,8 +4907,8 @@
 
         // need to be focusable in touch mode if in touch mode
         if (isInTouchMode() &&
-                (FOCUSABLE_IN_TOUCH_MODE != (mViewFlags & FOCUSABLE_IN_TOUCH_MODE))) {
-            return false;
+            (FOCUSABLE_IN_TOUCH_MODE != (mViewFlags & FOCUSABLE_IN_TOUCH_MODE))) {
+               return false;
         }
 
         // need to not have any parents blocking us
@@ -5901,7 +6148,11 @@
         /* Check if the VISIBLE bit has changed */
         if ((changed & INVISIBLE) != 0) {
             needGlobalAttributesUpdate(false);
-            invalidate(true);
+            /*
+             * If this view is becoming invisible, set the DRAWN flag so that
+             * the next invalidate() will not be skipped.
+             */
+            mPrivateFlags |= DRAWN;
 
             if (((mViewFlags & VISIBILITY_MASK) == INVISIBLE) && hasFocus()) {
                 // root view becoming invisible shouldn't clear focus
@@ -5958,7 +6209,7 @@
             }
         }
 
-        if ((changed & HORIZONTAL_DIRECTION_MASK) != 0) {
+        if ((changed & LAYOUT_DIRECTION_MASK) != 0) {
             requestLayout();
         }
     }
@@ -8073,7 +8324,7 @@
         if (isHorizontalScrollBarEnabled() != horizontalScrollBarEnabled) {
             mViewFlags ^= SCROLLBARS_HORIZONTAL;
             computeOpaqueFlags();
-            recomputePadding();
+            resolvePadding();
         }
     }
 
@@ -8103,7 +8354,7 @@
         if (isVerticalScrollBarEnabled() != verticalScrollBarEnabled) {
             mViewFlags ^= SCROLLBARS_VERTICAL;
             computeOpaqueFlags();
-            recomputePadding();
+            resolvePadding();
         }
     }
 
@@ -8162,7 +8413,7 @@
         if (style != (mViewFlags & SCROLLBARS_STYLE_MASK)) {
             mViewFlags = (mViewFlags & ~SCROLLBARS_STYLE_MASK) | (style & SCROLLBARS_STYLE_MASK);
             computeOpaqueFlags();
-            recomputePadding();
+            resolvePadding();
         }
     }
 
@@ -8303,6 +8554,40 @@
     }
 
     /**
+     * Check if this view can be scrolled horizontally in a certain direction.
+     *
+     * @param direction Negative to check scrolling left, positive to check scrolling right.
+     * @return true if this view can be scrolled in the specified direction, false otherwise.
+     */
+    public boolean canScrollHorizontally(int direction) {
+        final int offset = computeHorizontalScrollOffset();
+        final int range = computeHorizontalScrollRange() - computeHorizontalScrollExtent();
+        if (range == 0) return false;
+        if (direction < 0) {
+            return offset > 0;
+        } else {
+            return offset < range - 1;
+        }
+    }
+
+    /**
+     * Check if this view can be scrolled vertically in a certain direction.
+     *
+     * @param direction Negative to check scrolling up, positive to check scrolling down.
+     * @return true if this view can be scrolled in the specified direction, false otherwise.
+     */
+    public boolean canScrollVertically(int direction) {
+        final int offset = computeVerticalScrollOffset();
+        final int range = computeVerticalScrollRange() - computeVerticalScrollExtent();
+        if (range == 0) return false;
+        if (direction < 0) {
+            return offset > 0;
+        } else {
+            return offset < range - 1;
+        }
+    }
+
+    /**
      * <p>Request the drawing of the horizontal and the vertical scrollbar. The
      * scrollbars are painted only if they have been awakened first.</p>
      *
@@ -8513,23 +8798,112 @@
             mPrivateFlags &= ~AWAKEN_SCROLL_BARS_ON_ATTACH;
         }
         jumpDrawablesToCurrentState();
+        resetLayoutDirectionResolution();
+        resolveLayoutDirectionIfNeeded();
+        resolvePadding();
+        if (isFocused()) {
+            InputMethodManager imm = InputMethodManager.peekInstance();
+            imm.focusIn(this);
+        }
+    }
 
-        // We are supposing here that the parent directionality will be resolved before its children
-        // View horizontalDirection public attribute resolution to an internal var.
-        // Resolving the layout direction. LTR is set initially.
-        mPrivateFlags2 &= ~RESOLVED_LAYOUT_RTL;
-        switch (getHorizontalDirection()) {
-            case HORIZONTAL_DIRECTION_INHERIT:
+    /**
+     * Resolve and cache the layout direction. LTR is set initially. This is implicitly supposing
+     * that the parent directionality can and will be resolved before its children.
+     */
+    private void resolveLayoutDirectionIfNeeded() {
+        // Do not resolve if it is not needed
+        if ((mPrivateFlags2 & LAYOUT_DIRECTION_RESOLVED) == LAYOUT_DIRECTION_RESOLVED) return;
+
+        // Clear any previous layout direction resolution
+        mPrivateFlags2 &= ~LAYOUT_DIRECTION_RESOLVED_RTL;
+
+        // Set resolved depending on layout direction
+        switch (getLayoutDirection()) {
+            case LAYOUT_DIRECTION_INHERIT:
                 // If this is root view, no need to look at parent's layout dir.
-                if (mParent != null && mParent instanceof ViewGroup &&
-                        ((ViewGroup) mParent).isLayoutRtl()) {
-                    mPrivateFlags2 |= RESOLVED_LAYOUT_RTL;
+                if (mParent != null &&
+                        mParent instanceof ViewGroup &&
+                        ((ViewGroup) mParent).getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) {
+                    mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED_RTL;
                 }
                 break;
-            case HORIZONTAL_DIRECTION_RTL:
-                mPrivateFlags2 |= RESOLVED_LAYOUT_RTL;
+            case LAYOUT_DIRECTION_RTL:
+                mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED_RTL;
                 break;
+            case LAYOUT_DIRECTION_LOCALE:
+                if(isLayoutDirectionRtl(Locale.getDefault())) {
+                    mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED_RTL;
+                }
+                break;
+            default:
+                // Nothing to do, LTR by default
         }
+
+        // Set to resolved
+        mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED;
+    }
+
+    private void resolvePadding() {
+        // If the user specified the absolute padding (either with android:padding or
+        // android:paddingLeft/Top/Right/Bottom), use this padding, otherwise
+        // use the default padding or the padding from the background drawable
+        // (stored at this point in mPadding*)
+        switch (getResolvedLayoutDirection()) {
+            case LAYOUT_DIRECTION_RTL:
+                // Start user padding override Right user padding. Otherwise, if Right user
+                // padding is not defined, use the default Right padding. If Right user padding
+                // is defined, just use it.
+                if (mUserPaddingStart >= 0) {
+                    mUserPaddingRight = mUserPaddingStart;
+                } else if (mUserPaddingRight < 0) {
+                    mUserPaddingRight = mPaddingRight;
+                }
+                if (mUserPaddingEnd >= 0) {
+                    mUserPaddingLeft = mUserPaddingEnd;
+                } else if (mUserPaddingLeft < 0) {
+                    mUserPaddingLeft = mPaddingLeft;
+                }
+                break;
+            case LAYOUT_DIRECTION_LTR:
+            default:
+                // Start user padding override Left user padding. Otherwise, if Left user
+                // padding is not defined, use the default left padding. If Left user padding
+                // is defined, just use it.
+                if (mUserPaddingStart >= 0) {
+                    mUserPaddingLeft = mUserPaddingStart;
+                } else if (mUserPaddingLeft < 0) {
+                    mUserPaddingLeft = mPaddingLeft;
+                }
+                if (mUserPaddingEnd >= 0) {
+                    mUserPaddingRight = mUserPaddingEnd;
+                } else if (mUserPaddingRight < 0) {
+                    mUserPaddingRight = mPaddingRight;
+                }
+        }
+
+        mPaddingTop = (mUserPaddingTop >= 0) ? mUserPaddingTop : mPaddingTop;
+        mUserPaddingBottom = (mUserPaddingBottom >= 0) ? mUserPaddingBottom : mPaddingBottom;
+
+        recomputePadding();
+    }
+
+    /**
+     * Reset the resolved layout direction by clearing the corresponding flag
+     */
+    private void resetLayoutDirectionResolution() {
+        mPrivateFlags2 &= ~LAYOUT_DIRECTION_RESOLVED;
+    }
+
+    /**
+     * Check if a Locale is corresponding to a RTL script.
+     *
+     * @param locale Locale to check
+     * @return true if a Locale is corresponding to a RTL script.
+     */
+    private static boolean isLayoutDirectionRtl(Locale locale) {
+        return (LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE ==
+                LocaleUtil.getLayoutDirectionFromLocale(locale));
     }
 
     /**
@@ -9025,7 +9399,7 @@
                 mLocalDirtyRect.setEmpty();
             }
 
-            Canvas currentCanvas = mAttachInfo.mHardwareCanvas;
+            HardwareCanvas currentCanvas = mAttachInfo.mHardwareCanvas;
             final HardwareCanvas canvas = mHardwareLayer.start(currentCanvas);
             mAttachInfo.mHardwareCanvas = canvas;
             try {
@@ -10017,16 +10391,6 @@
     }
 
     /**
-     * <p>Indicates whether or not this view's layout is right-to-left. This is resolved from
-     * layout attribute and/or the inherited value from the parent.</p>
-     *
-     * @return true if the layout is right-to-left.
-     */
-    public boolean isLayoutRtl() {
-        return (mPrivateFlags2 & RESOLVED_LAYOUT_RTL) == RESOLVED_LAYOUT_RTL;
-    }
-
-    /**
      * Assign a size and position to a view and all of its
      * descendants
      *
@@ -10238,13 +10602,15 @@
         }
     }
 
-     /**
-     * Check if a given Drawable is in RTL layout direction.
-     *
-     * @param who the recipient of the action
-     */
-    public boolean isLayoutRtl(Drawable who) {
-        return (who == mBGDrawable) && isLayoutRtl();
+    /**
+    * Return the layout direction of a given Drawable.
+    *
+    * @param who the Drawable to query
+    *
+    * @hide
+    */
+    public int getResolvedLayoutDirection(Drawable who) {
+        return (who == mBGDrawable) ? getResolvedLayoutDirection() : LAYOUT_DIRECTION_DEFAULT;
     }
 
     /**
@@ -10500,7 +10866,14 @@
                 sThreadLocal.set(padding);
             }
             if (d.getPadding(padding)) {
-                setPadding(padding.left, padding.top, padding.right, padding.bottom);
+                switch (d.getResolvedLayoutDirectionSelf()) {
+                    case LAYOUT_DIRECTION_RTL:
+                        setPadding(padding.right, padding.top, padding.left, padding.bottom);
+                        break;
+                    case LAYOUT_DIRECTION_LTR:
+                    default:
+                        setPadding(padding.left, padding.top, padding.right, padding.bottom);
+                }
             }
 
             // Compare the minimum sizes of the old Drawable and the new.  If there isn't an old or
@@ -10586,6 +10959,8 @@
     public void setPadding(int left, int top, int right, int bottom) {
         boolean changed = false;
 
+        mUserPaddingRelative = false;
+
         mUserPaddingLeft = left;
         mUserPaddingRight = right;
         mUserPaddingBottom = bottom;
@@ -10595,11 +10970,16 @@
         // Common case is there are no scroll bars.
         if ((viewFlags & (SCROLLBARS_VERTICAL|SCROLLBARS_HORIZONTAL)) != 0) {
             if ((viewFlags & SCROLLBARS_VERTICAL) != 0) {
-                // TODO Determine what to do with SCROLLBAR_POSITION_DEFAULT based on RTL settings.
                 final int offset = (viewFlags & SCROLLBARS_INSET_MASK) == 0
                         ? 0 : getVerticalScrollbarWidth();
                 switch (mVerticalScrollbarPosition) {
                     case SCROLLBAR_POSITION_DEFAULT:
+                        if (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) {
+                            left += offset;
+                        } else {
+                            right += offset;
+                        }
+                        break;
                     case SCROLLBAR_POSITION_RIGHT:
                         right += offset;
                         break;
@@ -10637,6 +11017,37 @@
     }
 
     /**
+     * Sets the relative padding. The view may add on the space required to display
+     * the scrollbars, depending on the style and visibility of the scrollbars.
+     * So the values returned from {@link #getPaddingStart}, {@link #getPaddingTop},
+     * {@link #getPaddingEnd} and {@link #getPaddingBottom} may be different
+     * from the values set in this call.
+     *
+     * @attr ref android.R.styleable#View_padding
+     * @attr ref android.R.styleable#View_paddingBottom
+     * @attr ref android.R.styleable#View_paddingStart
+     * @attr ref android.R.styleable#View_paddingEnd
+     * @attr ref android.R.styleable#View_paddingTop
+     * @param start the start padding in pixels
+     * @param top the top padding in pixels
+     * @param end the end padding in pixels
+     * @param bottom the bottom padding in pixels
+     *
+     * @hide
+     */
+    public void setPaddingRelative(int start, int top, int end, int bottom) {
+        mUserPaddingRelative = true;
+        switch(getResolvedLayoutDirection()) {
+            case LAYOUT_DIRECTION_RTL:
+                setPadding(end, top, start, bottom);
+                break;
+            case LAYOUT_DIRECTION_LTR:
+            default:
+                setPadding(start, top, end, bottom);
+        }
+    }
+
+    /**
      * Returns the top padding of this view.
      *
      * @return the top padding in pixels
@@ -10668,6 +11079,20 @@
     }
 
     /**
+     * Returns the start padding of this view. If there are inset and enabled
+     * scrollbars, this value may include the space required to display the
+     * scrollbars as well.
+     *
+     * @return the start padding in pixels
+     *
+     * @hide
+     */
+    public int getPaddingStart() {
+        return (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) ?
+                mPaddingRight : mPaddingLeft;
+    }
+
+    /**
      * Returns the right padding of this view. If there are inset and enabled
      * scrollbars, this value may include the space required to display the
      * scrollbars as well.
@@ -10679,6 +11104,34 @@
     }
 
     /**
+     * Returns the end padding of this view. If there are inset and enabled
+     * scrollbars, this value may include the space required to display the
+     * scrollbars as well.
+     *
+     * @return the end padding in pixels
+     *
+     * @hide
+     */
+    public int getPaddingEnd() {
+        return (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) ?
+                mPaddingLeft : mPaddingRight;
+    }
+
+    /**
+     * Return if the padding as been set thru relative values
+     * {@link #setPaddingRelative(int, int, int, int)} or thru
+     * @attr ref android.R.styleable#View_paddingStart or
+     * @attr ref android.R.styleable#View_paddingEnd
+     *
+     * @return true if the padding is relative or false if it is not.
+     *
+     * @hide
+     */
+    public boolean isPaddingRelative() {
+        return mUserPaddingRelative;
+    }
+
+    /**
      * Changes the selection state of this view. A view can be selected or not.
      * Note that selection is not the same as focus. Views are typically
      * selected in the context of an AdapterView like ListView or GridView;
@@ -11464,7 +11917,7 @@
 
     /**
      * Utility to return a default size. Uses the supplied size if the
-     * MeasureSpec imposed no contraints. Will get larger if allowed
+     * MeasureSpec imposed no constraints. Will get larger if allowed
      * by the MeasureSpec.
      *
      * @param size Default size for this view
@@ -11474,7 +11927,7 @@
     public static int getDefaultSize(int size, int measureSpec) {
         int result = size;
         int specMode = MeasureSpec.getMode(measureSpec);
-        int specSize =  MeasureSpec.getSize(measureSpec);
+        int specSize = MeasureSpec.getSize(measureSpec);
 
         switch (specMode) {
         case MeasureSpec.UNSPECIFIED:
@@ -12286,6 +12739,169 @@
         return getVerticalScrollFactor();
     }
 
+    //
+    // Properties
+    //
+    /**
+     * A Property wrapper around the <code>alpha</code> functionality handled by the
+     * {@link View#setAlpha(float)} and {@link View#getAlpha()} methods.
+     */
+    static Property<View, Float> ALPHA = new FloatProperty<View>("alpha") {
+        @Override
+        public void setValue(View object, float value) {
+            object.setAlpha(value);
+        }
+
+        @Override
+        public Float get(View object) {
+            return object.getAlpha();
+        }
+    };
+
+    /**
+     * A Property wrapper around the <code>translationX</code> functionality handled by the
+     * {@link View#setTranslationX(float)} and {@link View#getTranslationX()} methods.
+     */
+    public static Property<View, Float> TRANSLATION_X = new FloatProperty<View>("translationX") {
+        @Override
+        public void setValue(View object, float value) {
+            object.setTranslationX(value);
+        }
+
+                @Override
+        public Float get(View object) {
+            return object.getTranslationX();
+        }
+    };
+
+    /**
+     * A Property wrapper around the <code>translationY</code> functionality handled by the
+     * {@link View#setTranslationY(float)} and {@link View#getTranslationY()} methods.
+     */
+    public static Property<View, Float> TRANSLATION_Y = new FloatProperty<View>("translationY") {
+        @Override
+        public void setValue(View object, float value) {
+            object.setTranslationY(value);
+        }
+
+        @Override
+        public Float get(View object) {
+            return object.getTranslationY();
+        }
+    };
+
+    /**
+     * A Property wrapper around the <code>x</code> functionality handled by the
+     * {@link View#setX(float)} and {@link View#getX()} methods.
+     */
+    public static Property<View, Float> X = new FloatProperty<View>("x") {
+        @Override
+        public void setValue(View object, float value) {
+            object.setX(value);
+        }
+
+        @Override
+        public Float get(View object) {
+            return object.getX();
+        }
+    };
+
+    /**
+     * A Property wrapper around the <code>y</code> functionality handled by the
+     * {@link View#setY(float)} and {@link View#getY()} methods.
+     */
+    public static Property<View, Float> Y = new FloatProperty<View>("y") {
+        @Override
+        public void setValue(View object, float value) {
+            object.setY(value);
+        }
+
+        @Override
+        public Float get(View object) {
+            return object.getY();
+        }
+    };
+
+    /**
+     * A Property wrapper around the <code>rotation</code> functionality handled by the
+     * {@link View#setRotation(float)} and {@link View#getRotation()} methods.
+     */
+    public static Property<View, Float> ROTATION = new FloatProperty<View>("rotation") {
+        @Override
+        public void setValue(View object, float value) {
+            object.setRotation(value);
+        }
+
+        @Override
+        public Float get(View object) {
+            return object.getRotation();
+        }
+    };
+
+    /**
+     * A Property wrapper around the <code>rotationX</code> functionality handled by the
+     * {@link View#setRotationX(float)} and {@link View#getRotationX()} methods.
+     */
+    public static Property<View, Float> ROTATION_X = new FloatProperty<View>("rotationX") {
+        @Override
+        public void setValue(View object, float value) {
+            object.setRotationX(value);
+        }
+
+        @Override
+        public Float get(View object) {
+            return object.getRotationX();
+        }
+    };
+
+    /**
+     * A Property wrapper around the <code>rotationY</code> functionality handled by the
+     * {@link View#setRotationY(float)} and {@link View#getRotationY()} methods.
+     */
+    public static Property<View, Float> ROTATION_Y = new FloatProperty<View>("rotationY") {
+        @Override
+        public void setValue(View object, float value) {
+            object.setRotationY(value);
+        }
+
+        @Override
+        public Float get(View object) {
+            return object.getRotationY();
+        }
+    };
+
+    /**
+     * A Property wrapper around the <code>scaleX</code> functionality handled by the
+     * {@link View#setScaleX(float)} and {@link View#getScaleX()} methods.
+     */
+    public static Property<View, Float> SCALE_X = new FloatProperty<View>("scaleX") {
+        @Override
+        public void setValue(View object, float value) {
+            object.setScaleX(value);
+        }
+
+        @Override
+        public Float get(View object) {
+            return object.getScaleX();
+        }
+    };
+
+    /**
+     * A Property wrapper around the <code>scaleY</code> functionality handled by the
+     * {@link View#setScaleY(float)} and {@link View#getScaleY()} methods.
+     */
+    public static Property<View, Float> SCALE_Y = new FloatProperty<View>("scaleY") {
+        @Override
+        public void setValue(View object, float value) {
+            object.setScaleY(value);
+        }
+
+        @Override
+        public Float get(View object) {
+            return object.getScaleY();
+        }
+    };
+
     /**
      * A MeasureSpec encapsulates the layout requirements passed from parent to child.
      * Each MeasureSpec represents a requirement for either the width or the height.
@@ -12697,6 +13313,7 @@
             );
 
             private InvalidateInfo mNext;
+            private boolean mIsPooled;
 
             View target;
 
@@ -12720,6 +13337,14 @@
             void release() {
                 sPool.release(this);
             }
+
+            public boolean isPooled() {
+                return mIsPooled;
+            }
+
+            public void setPooled(boolean isPooled) {
+                mIsPooled = isPooled;
+            }
         }
 
         final IWindowSession mSession;
@@ -12730,7 +13355,7 @@
 
         final Callbacks mRootCallbacks;
 
-        Canvas mHardwareCanvas;
+        HardwareCanvas mHardwareCanvas;
 
         /**
          * The top view of the hierarchy.
@@ -12930,6 +13555,11 @@
         final ArrayList<View> mFocusablesTempList = new ArrayList<View>(24);
 
         /**
+         * The id of the window for accessibility purposes.
+         */
+        int mAccessibilityWindowId = View.NO_ID;
+
+        /**
          * Creates a new set of attachment information with the specified
          * events handler and thread.
          *
diff --git a/core/java/android/view/ViewAncestor.java b/core/java/android/view/ViewAncestor.java
index bd33a6a..afbedaf 100644
--- a/core/java/android/view/ViewAncestor.java
+++ b/core/java/android/view/ViewAncestor.java
@@ -46,22 +46,33 @@
 import android.os.Process;
 import android.os.RemoteException;
 import android.os.SystemClock;
+import android.os.SystemProperties;
 import android.util.AndroidRuntimeException;
 import android.util.DisplayMetrics;
 import android.util.EventLog;
 import android.util.Log;
+import android.util.Pool;
+import android.util.Poolable;
+import android.util.PoolableManager;
+import android.util.Pools;
 import android.util.Slog;
 import android.util.SparseArray;
 import android.util.TypedValue;
 import android.view.View.MeasureSpec;
 import android.view.accessibility.AccessibilityEvent;
 import android.view.accessibility.AccessibilityManager;
+import android.view.accessibility.AccessibilityManager.AccessibilityStateChangeListener;
+import android.view.accessibility.AccessibilityNodeInfo;
+import android.view.accessibility.IAccessibilityInteractionConnection;
+import android.view.accessibility.IAccessibilityInteractionConnectionCallback;
 import android.view.animation.AccelerateDecelerateInterpolator;
 import android.view.animation.Interpolator;
 import android.view.inputmethod.InputConnection;
 import android.view.inputmethod.InputMethodManager;
 import android.widget.Scroller;
+
 import com.android.internal.policy.PolicyManager;
+import com.android.internal.util.Predicate;
 import com.android.internal.view.BaseSurfaceHolder;
 import com.android.internal.view.IInputMethodCallback;
 import com.android.internal.view.IInputMethodSession;
@@ -71,6 +82,7 @@
 import java.io.OutputStream;
 import java.lang.ref.WeakReference;
 import java.util.ArrayList;
+import java.util.List;
 
 /**
  * The top of a view hierarchy, implementing the needed protocol between View
@@ -84,7 +96,6 @@
         View.AttachInfo.Callbacks, HardwareRenderer.HardwareDrawCallbacks {
     private static final String TAG = "ViewAncestor";
     private static final boolean DBG = false;
-    private static final boolean SHOW_FPS = false;
     private static final boolean LOCAL_LOGV = false;
     /** @noinspection PointlessBooleanExpression*/
     private static final boolean DEBUG_DRAW = false || LOCAL_LOGV;
@@ -97,6 +108,12 @@
     private static final boolean DEBUG_CONFIGURATION = false || LOCAL_LOGV;
     private static final boolean WATCH_POINTER = false;
 
+    /**
+     * Set this system property to true to force the view hierarchy to render
+     * at 60 Hz. This can be used to measure the potential framerate.
+     */
+    private static final String PROPERTY_PROFILE_RENDERING = "viewancestor.profile_rendering";    
+    
     private static final boolean MEASURE_LATENCY = false;
     private static LatencyTimer lt;
 
@@ -118,8 +135,13 @@
     
     static final ArrayList<ComponentCallbacks> sConfigCallbacks
             = new ArrayList<ComponentCallbacks>();
-    
-    private static int sDrawTime;
+
+    /**
+     * Delay before dispatching an accessibility event that the window
+     * content has changed. The window content is considered changed
+     * after a layout pass.
+     */
+    private static final long SEND_WINDOW_CONTENT_CHANGED_DELAY_MILLIS = 500;
 
     long mLastTrackballTime = 0;
     final TrackballAxis mTrackballAxisX = new TrackballAxis();
@@ -156,6 +178,8 @@
     // so the window should no longer be active.
     boolean mStopped = false;
     
+    boolean mLastInCompatMode = false;
+
     SurfaceHolder.Callback2 mSurfaceHolderCallback;
     BaseSurfaceHolder mSurfaceHolder;
     boolean mIsCreating;
@@ -203,6 +227,8 @@
     boolean mAdded;
     boolean mAddedTouchMode;
 
+    CompatibilityInfoHolder mCompatibilityInfo;
+
     /*package*/ int mAddNesting;
 
     // These are accessed by multiple threads.
@@ -215,7 +241,7 @@
 
     final Configuration mLastConfiguration = new Configuration();
     final Configuration mPendingConfiguration = new Configuration();
-    
+
     class ResizedInfo {
         Rect coveredInsets;
         Rect visibleInsets;
@@ -242,12 +268,24 @@
     volatile Object mLocalDragState;
     final PointF mDragPoint = new PointF();
     final PointF mLastTouchPoint = new PointF();
+    
+    private boolean mProfileRendering;    
+    private Thread mRenderProfiler;
+    private volatile boolean mRenderProfilingEnabled;
 
     /**
      * see {@link #playSoundEffect(int)}
      */
     AudioManager mAudioManager;
 
+    final AccessibilityManager mAccessibilityManager;
+
+    AccessibilityInteractionController mAccessibilityInteractionContrtoller;
+
+    AccessibilityInteractionConnectionManager mAccessibilityInteractionConnectionManager;
+
+    SendWindowContentChanged mSendWindowContentChanged;
+
     private final int mDensity;
 
     /**
@@ -285,7 +323,7 @@
         // done here instead of in the static block because Zygote does not
         // allow the spawning of threads.
         getWindowSession(context.getMainLooper());
-        
+
         mThread = Thread.currentThread();
         mLocation = new WindowLeaked(null);
         mLocation.fillInStackTrace();
@@ -302,10 +340,17 @@
         mPreviousTransparentRegion = new Region();
         mFirst = true; // true for the first time the view is added
         mAdded = false;
+        mAccessibilityManager = AccessibilityManager.getInstance(context);
+        mAccessibilityInteractionConnectionManager =
+            new AccessibilityInteractionConnectionManager();
+        mAccessibilityManager.addAccessibilityStateChangeListener(
+                mAccessibilityInteractionConnectionManager);
         mAttachInfo = new View.AttachInfo(sWindowSession, mWindow, this, this);
         mViewConfiguration = ViewConfiguration.get(context);
         mDensity = context.getResources().getDisplayMetrics().densityDpi;
         mFallbackEventHandler = PolicyManager.makeNewFallbackEventHandler(context);
+        mProfileRendering = Boolean.parseBoolean(
+                SystemProperties.get(PROPERTY_PROFILE_RENDERING, "false"));
     }
 
     public static void addFirstDrawHandler(Runnable callback) {
@@ -376,8 +421,7 @@
                     enableHardwareAcceleration(attrs);
                 }
 
-                Resources resources = mView.getContext().getResources();
-                CompatibilityInfo compatibilityInfo = resources.getCompatibilityInfo();
+                CompatibilityInfo compatibilityInfo = mCompatibilityInfo.get();
                 mTranslator = compatibilityInfo.getTranslator();
 
                 if (mTranslator != null) {
@@ -394,6 +438,7 @@
 
                 if (!compatibilityInfo.supportsScreen()) {
                     attrs.flags |= WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW;
+                    mLastInCompatMode = true;
                 }
 
                 mSoftInputMode = attrs.softInputMode;
@@ -490,10 +535,14 @@
                     InputQueue.registerInputChannel(mInputChannel, mInputHandler,
                             Looper.myQueue());
                 }
-                
+
                 view.assignParent(this);
                 mAddedTouchMode = (res&WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE) != 0;
                 mAppVisible = (res&WindowManagerImpl.ADD_FLAG_APP_VISIBLE) != 0;
+
+                if (mAccessibilityManager.isEnabled()) {
+                    mAccessibilityInteractionConnectionManager.ensureConnection();
+                }
             }
         }
     }
@@ -760,15 +809,35 @@
             surfaceChanged = true;
             params = lp;
         }
+        CompatibilityInfo compatibilityInfo = mCompatibilityInfo.get();
+        if (compatibilityInfo.supportsScreen() == mLastInCompatMode) {
+            params = lp;
+            fullRedrawNeeded = true;
+            mLayoutRequested = true;
+            if (mLastInCompatMode) {
+                params.flags &= ~WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW;
+                mLastInCompatMode = false;
+            } else {
+                params.flags |= WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW;
+                mLastInCompatMode = true;
+            }
+        }
         Rect frame = mWinFrame;
         if (mFirst) {
             fullRedrawNeeded = true;
             mLayoutRequested = true;
 
-            DisplayMetrics packageMetrics =
-                mView.getContext().getResources().getDisplayMetrics();
-            desiredWindowWidth = packageMetrics.widthPixels;
-            desiredWindowHeight = packageMetrics.heightPixels;
+            if (lp.type == WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL) {
+                // NOTE -- system code, won't try to do compat mode.
+                Display disp = WindowManagerImpl.getDefault().getDefaultDisplay();
+                desiredWindowWidth = disp.getRealWidth();
+                desiredWindowHeight = disp.getRealHeight();
+            } else {
+                DisplayMetrics packageMetrics =
+                    mView.getContext().getResources().getDisplayMetrics();
+                desiredWindowWidth = packageMetrics.widthPixels;
+                desiredWindowHeight = packageMetrics.heightPixels;
+            }
 
             // For the very first time, tell the view hierarchy that it
             // is attached to the window.  Note that at this point the surface
@@ -912,9 +981,16 @@
                         || lp.height == ViewGroup.LayoutParams.WRAP_CONTENT) {
                     windowSizeMayChange = true;
 
-                    DisplayMetrics packageMetrics = res.getDisplayMetrics();
-                    desiredWindowWidth = packageMetrics.widthPixels;
-                    desiredWindowHeight = packageMetrics.heightPixels;
+                    if (lp.type == WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL) {
+                        // NOTE -- system code, won't try to do compat mode.
+                        Display disp = WindowManagerImpl.getDefault().getDefaultDisplay();
+                        desiredWindowWidth = disp.getRealWidth();
+                        desiredWindowHeight = disp.getRealHeight();
+                    } else {
+                        DisplayMetrics packageMetrics = res.getDisplayMetrics();
+                        desiredWindowWidth = packageMetrics.widthPixels;
+                        desiredWindowHeight = packageMetrics.heightPixels;
+                    }
                 }
             }
 
@@ -1360,6 +1436,10 @@
         if (triggerGlobalLayoutListener) {
             attachInfo.mRecomputeGlobalAttributes = false;
             attachInfo.mTreeObserver.dispatchOnGlobalLayout();
+
+            if (AccessibilityManager.getInstance(host.mContext).isEnabled()) {
+                postSendWindowContentChangedCallback();
+            }
         }
 
         if (computesInternalInsets) {
@@ -1558,11 +1638,45 @@
      */
     void outputDisplayList(View view) {
         if (mAttachInfo != null && mAttachInfo.mHardwareCanvas != null) {
-
-            HardwareCanvas canvas = (HardwareCanvas) mAttachInfo.mHardwareCanvas;
             DisplayList displayList = view.getDisplayList();
             if (displayList != null) {
-                canvas.outputDisplayList(displayList);
+                mAttachInfo.mHardwareCanvas.outputDisplayList(displayList);
+            }
+        }
+    }
+
+    /**
+     * @see #PROPERTY_PROFILE_RENDERING
+     */
+    private void profileRendering(boolean enabled) {
+        if (mProfileRendering) {
+            mRenderProfilingEnabled = enabled;
+            if (mRenderProfiler == null) {
+                mRenderProfiler = new Thread(new Runnable() {
+                    @Override
+                    public void run() {
+                        Log.d(TAG, "Starting profiling thread");
+                        while (mRenderProfilingEnabled) {
+                            mAttachInfo.mHandler.post(new Runnable() {
+                                @Override
+                                public void run() {
+                                    mDirty.set(0, 0, mWidth, mHeight);
+                                    scheduleTraversals();
+                                }
+                            });
+                            try {
+                                // TODO: This should use vsync when we get an API
+                                Thread.sleep(15);
+                            } catch (InterruptedException e) {
+                                Log.d(TAG, "Exiting profiling thread");
+                            }                            
+                        }
+                    }
+                }, "Rendering Profiler");
+                mRenderProfiler.start();
+            } else {
+                mRenderProfiler.interrupt();
+                mRenderProfiler = null;
             }
         }
     }
@@ -1582,7 +1696,7 @@
                 }
             }
         }
-        
+
         scrollToRectOrFocus(null, false);
 
         if (mAttachInfo.mViewScrollChanged) {
@@ -1773,14 +1887,6 @@
                         mView.dispatchConsistencyCheck(ViewDebug.CONSISTENCY_DRAWING);
                     }
 
-                    if (SHOW_FPS || ViewDebug.DEBUG_SHOW_FPS) {
-                        int now = (int)SystemClock.elapsedRealtime();
-                        if (sDrawTime != 0) {
-                            nativeShowFPS(canvas, now - sDrawTime);
-                        }
-                        sDrawTime = now;
-                    }
-
                     if (ViewDebug.DEBUG_PROFILE_DRAWING) {
                         EventLog.writeEvent(60000, SystemClock.elapsedRealtime() - startTime);
                     }
@@ -1990,6 +2096,11 @@
             mView.dispatchDetachedFromWindow();
         }
 
+        mAccessibilityInteractionConnectionManager.ensureNoConnection();
+        mAccessibilityManager.removeAccessibilityStateChangeListener(
+                mAccessibilityInteractionConnectionManager);
+        removeSendWindowContentChangedCallback();
+
         mView = null;
         mAttachInfo.mRootView = null;
         mAttachInfo.mSurface = null;
@@ -2006,7 +2117,6 @@
                 InputQueue.unregisterInputChannel(mInputChannel);
             }
         }
-        
         try {
             sWindowSession.remove(mWindow);
         } catch (RemoteException e) {
@@ -2025,6 +2135,13 @@
                 "Applying new config to window "
                 + mWindowAttributes.getTitle()
                 + ": " + config);
+
+        CompatibilityInfo ci = mCompatibilityInfo.getIfNeeded();
+        if (ci != null) {
+            config = new Configuration(config);
+            ci.applyToConfiguration(config);
+        }
+
         synchronized (sConfigCallbacks) {
             for (int i=sConfigCallbacks.size()-1; i>=0; i--) {
                 sConfigCallbacks.get(i).onConfigurationChanged(config);
@@ -2084,6 +2201,11 @@
     public final static int DISPATCH_DRAG_LOCATION_EVENT = 1016;
     public final static int DISPATCH_SYSTEM_UI_VISIBILITY = 1017;
     public final static int DISPATCH_GENERIC_MOTION = 1018;
+    public final static int UPDATE_CONFIGURATION = 1019;
+    public final static int DO_PERFORM_ACCESSIBILITY_ACTION = 1020;
+    public final static int DO_FIND_ACCESSIBLITY_NODE_INFO_BY_ACCESSIBILITY_ID = 1021;
+    public final static int DO_FIND_ACCESSIBLITY_NODE_INFO_BY_VIEW_ID = 1022;
+    public final static int DO_FIND_ACCESSIBLITY_NODE_INFO_BY_VIEW_TEXT = 1023;
 
     @Override
     public void handleMessage(Message msg) {
@@ -2181,6 +2303,9 @@
             if (mAdded) {
                 boolean hasWindowFocus = msg.arg1 != 0;
                 mAttachInfo.mHasWindowFocus = hasWindowFocus;
+                
+                profileRendering(hasWindowFocus);
+
                 if (hasWindowFocus) {
                     boolean inTouchMode = msg.arg2 != 0;
                     ensureTouchModeLocally(inTouchMode);
@@ -2284,9 +2409,40 @@
         case DISPATCH_SYSTEM_UI_VISIBILITY: {
             handleDispatchSystemUiVisibilityChanged(msg.arg1);
         } break;
+        case UPDATE_CONFIGURATION: {
+            Configuration config = (Configuration)msg.obj;
+            if (config.isOtherSeqNewer(mLastConfiguration)) {
+                config = mLastConfiguration;
+            }
+            updateConfiguration(config, false);
+        } break;
+        case DO_FIND_ACCESSIBLITY_NODE_INFO_BY_ACCESSIBILITY_ID: {
+            if (mView != null) {
+                getAccessibilityInteractionController()
+                    .findAccessibilityNodeInfoByAccessibilityIdUiThread(msg);
+            }
+        } break;
+        case DO_PERFORM_ACCESSIBILITY_ACTION: {
+            if (mView != null) {
+                getAccessibilityInteractionController()
+                    .perfromAccessibilityActionUiThread(msg);
+            }
+        } break;
+        case DO_FIND_ACCESSIBLITY_NODE_INFO_BY_VIEW_ID: {
+            if (mView != null) {
+                getAccessibilityInteractionController()
+                    .findAccessibilityNodeInfoByViewIdUiThread(msg);
+            }
+        } break;
+        case DO_FIND_ACCESSIBLITY_NODE_INFO_BY_VIEW_TEXT: {
+            if (mView != null) {
+                getAccessibilityInteractionController()
+                    .findAccessibilityNodeInfosByViewTextUiThread(msg);
+            }
+        } break;
         }
     }
-    
+
     private void startInputEvent(InputQueue.FinishedCallback finishedCallback) {
         if (mFinishedCallback != null) {
             Slog.w(TAG, "Received a new input event from the input queue but there is "
@@ -3206,6 +3362,17 @@
         return mAudioManager;
     }
 
+    public AccessibilityInteractionController getAccessibilityInteractionController() {
+        if (mView == null) {
+            throw new IllegalStateException("getAccessibilityInteractionController"
+                    + " called when there is no mView");
+        }
+        if (mAccessibilityInteractionContrtoller == null) {
+            mAccessibilityInteractionContrtoller = new AccessibilityInteractionController();
+        }
+        return mAccessibilityInteractionContrtoller;
+    }
+
     private int relayoutWindow(WindowManager.LayoutParams params, int viewVisibility,
             boolean insetsPending) throws RemoteException {
 
@@ -3342,6 +3509,11 @@
         }
     }
 
+    public void requestUpdateConfiguration(Configuration config) {
+        Message msg = obtainMessage(UPDATE_CONFIGURATION, config);
+        sendMessage(msg);
+    }
+
     private void destroyHardwareRenderer() {
         if (mAttachInfo.mHardwareRenderer != null) {
             mAttachInfo.mHardwareRenderer.destroy(true);
@@ -3503,7 +3675,7 @@
      * send an {@link AccessibilityEvent} to announce that.
      */
     private void sendAccessibilityEvents() {
-        if (!AccessibilityManager.getInstance(mView.getContext()).isEnabled()) {
+        if (!mAccessibilityManager.isEnabled()) {
             return;
         }
         mView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
@@ -3513,6 +3685,29 @@
         }
     }
 
+    /**
+     * Post a callback to send a
+     * {@link AccessibilityEvent#TYPE_WINDOW_CONTENT_CHANGED} event.
+     */
+    private void postSendWindowContentChangedCallback() {
+        if (mSendWindowContentChanged == null) {
+            mSendWindowContentChanged = new SendWindowContentChanged();
+        } else {
+            removeCallbacks(mSendWindowContentChanged);
+        }
+        postDelayed(mSendWindowContentChanged, SEND_WINDOW_CONTENT_CHANGED_DELAY_MILLIS);
+    }
+
+    /**
+     * Remove a posted callback to send a
+     * {@link AccessibilityEvent#TYPE_WINDOW_CONTENT_CHANGED} event.
+     */
+    private void removeSendWindowContentChangedCallback() {
+        if (mSendWindowContentChanged != null) {
+            removeCallbacks(mSendWindowContentChanged);
+        }
+    }
+
     public boolean showContextMenuForChild(View originalView) {
         return false;
     }
@@ -3531,7 +3726,7 @@
         if (mView == null) {
             return false;
         }
-        AccessibilityManager.getInstance(child.mContext).sendAccessibilityEvent(event);
+        mAccessibilityManager.sendAccessibilityEvent(event);
         return true;
     }
 
@@ -3594,18 +3789,18 @@
     static class InputMethodCallback extends IInputMethodCallback.Stub {
         private WeakReference<ViewAncestor> mViewAncestor;
 
-        public InputMethodCallback(ViewAncestor viewRoot) {
-            mViewAncestor = new WeakReference<ViewAncestor>(viewRoot);
+        public InputMethodCallback(ViewAncestor viewAncestor) {
+            mViewAncestor = new WeakReference<ViewAncestor>(viewAncestor);
         }
 
         public void finishedEvent(int seq, boolean handled) {
-            final ViewAncestor viewRoot = mViewAncestor.get();
-            if (viewRoot != null) {
-                viewRoot.dispatchFinishedEvent(seq, handled);
+            final ViewAncestor viewAncestor = mViewAncestor.get();
+            if (viewAncestor != null) {
+                viewAncestor.dispatchFinishedEvent(seq, handled);
             }
         }
 
-        public void sessionCreated(IInputMethodSession session) throws RemoteException {
+        public void sessionCreated(IInputMethodSession session) {
             // Stub -- not for use in the client.
         }
     }
@@ -3613,36 +3808,37 @@
     static class W extends IWindow.Stub {
         private final WeakReference<ViewAncestor> mViewAncestor;
 
-        W(ViewAncestor viewRoot) {
-            mViewAncestor = new WeakReference<ViewAncestor>(viewRoot);
+        W(ViewAncestor viewAncestor) {
+            mViewAncestor = new WeakReference<ViewAncestor>(viewAncestor);
         }
 
         public void resized(int w, int h, Rect coveredInsets, Rect visibleInsets,
                 boolean reportDraw, Configuration newConfig) {
-            final ViewAncestor viewRoot = mViewAncestor.get();
-            if (viewRoot != null) {
-                viewRoot.dispatchResized(w, h, coveredInsets, visibleInsets, reportDraw, newConfig);
+            final ViewAncestor viewAncestor = mViewAncestor.get();
+            if (viewAncestor != null) {
+                viewAncestor.dispatchResized(w, h, coveredInsets, visibleInsets, reportDraw,
+                        newConfig);
             }
         }
 
         public void dispatchAppVisibility(boolean visible) {
-            final ViewAncestor viewRoot = mViewAncestor.get();
-            if (viewRoot != null) {
-                viewRoot.dispatchAppVisibility(visible);
+            final ViewAncestor viewAncestor = mViewAncestor.get();
+            if (viewAncestor != null) {
+                viewAncestor.dispatchAppVisibility(visible);
             }
         }
 
         public void dispatchGetNewSurface() {
-            final ViewAncestor viewRoot = mViewAncestor.get();
-            if (viewRoot != null) {
-                viewRoot.dispatchGetNewSurface();
+            final ViewAncestor viewAncestor = mViewAncestor.get();
+            if (viewAncestor != null) {
+                viewAncestor.dispatchGetNewSurface();
             }
         }
 
         public void windowFocusChanged(boolean hasFocus, boolean inTouchMode) {
-            final ViewAncestor viewRoot = mViewAncestor.get();
-            if (viewRoot != null) {
-                viewRoot.windowFocusChanged(hasFocus, inTouchMode);
+            final ViewAncestor viewAncestor = mViewAncestor.get();
+            if (viewAncestor != null) {
+                viewAncestor.windowFocusChanged(hasFocus, inTouchMode);
             }
         }
 
@@ -3660,9 +3856,9 @@
         }
 
         public void executeCommand(String command, String parameters, ParcelFileDescriptor out) {
-            final ViewAncestor viewRoot = mViewAncestor.get();
-            if (viewRoot != null) {
-                final View view = viewRoot.mView;
+            final ViewAncestor viewAncestor = mViewAncestor.get();
+            if (viewAncestor != null) {
+                final View view = viewAncestor.mView;
                 if (view != null) {
                     if (checkCallingPermission(Manifest.permission.DUMP) !=
                             PackageManager.PERMISSION_GRANTED) {
@@ -3691,9 +3887,9 @@
         }
         
         public void closeSystemDialogs(String reason) {
-            final ViewAncestor viewRoot = mViewAncestor.get();
-            if (viewRoot != null) {
-                viewRoot.dispatchCloseSystemDialogs(reason);
+            final ViewAncestor viewAncestor = mViewAncestor.get();
+            if (viewAncestor != null) {
+                viewAncestor.dispatchCloseSystemDialogs(reason);
             }
         }
         
@@ -3706,7 +3902,7 @@
                 }
             }
         }
-        
+
         public void dispatchWallpaperCommand(String action, int x, int y,
                 int z, Bundle extras, boolean sync) {
             if (sync) {
@@ -3719,17 +3915,16 @@
 
         /* Drag/drop */
         public void dispatchDragEvent(DragEvent event) {
-            final ViewAncestor viewRoot = mViewAncestor.get();
-            if (viewRoot != null) {
-                viewRoot.dispatchDragEvent(event);
+            final ViewAncestor viewAncestor = mViewAncestor.get();
+            if (viewAncestor != null) {
+                viewAncestor.dispatchDragEvent(event);
             }
         }
 
-        @Override
         public void dispatchSystemUiVisibilityChanged(int visibility) {
-            final ViewAncestor viewRoot = mViewAncestor.get();
-            if (viewRoot != null) {
-                viewRoot.dispatchSystemUiVisibilityChanged(visibility);
+            final ViewAncestor viewAncestor = mViewAncestor.get();
+            if (viewAncestor != null) {
+                viewAncestor.dispatchSystemUiVisibilityChanged(visibility);
             }
         }
     }
@@ -4039,5 +4234,407 @@
         }
     }
 
-    private static native void nativeShowFPS(Canvas canvas, int durationMillis);
+    /**
+     * Class for managing the accessibility interaction connection
+     * based on the global accessibility state.
+     */
+    final class AccessibilityInteractionConnectionManager
+            implements AccessibilityStateChangeListener {
+        public void onAccessibilityStateChanged(boolean enabled) {
+            if (enabled) {
+                ensureConnection();
+            } else {
+                ensureNoConnection();
+            }
+        }
+
+        public void ensureConnection() {
+            final boolean registered = mAttachInfo.mAccessibilityWindowId != View.NO_ID;
+            if (!registered) {
+                mAttachInfo.mAccessibilityWindowId =
+                    mAccessibilityManager.addAccessibilityInteractionConnection(mWindow,
+                            new AccessibilityInteractionConnection(ViewAncestor.this));
+            }
+        }
+
+        public void ensureNoConnection() {
+            final boolean registered = mAttachInfo.mAccessibilityWindowId != View.NO_ID;
+            if (registered) {
+                mAttachInfo.mAccessibilityWindowId = View.NO_ID;
+                mAccessibilityManager.removeAccessibilityInteractionConnection(mWindow);
+            }
+        }
+    }
+
+    /**
+     * This class is an interface this ViewAncestor provides to the
+     * AccessibilityManagerService to the latter can interact with
+     * the view hierarchy in this ViewAncestor.
+     */
+    final class AccessibilityInteractionConnection
+            extends IAccessibilityInteractionConnection.Stub {
+        private final WeakReference<ViewAncestor> mViewAncestor;
+
+        AccessibilityInteractionConnection(ViewAncestor viewAncestor) {
+            mViewAncestor = new WeakReference<ViewAncestor>(viewAncestor);
+        }
+
+        public void findAccessibilityNodeInfoByAccessibilityId(int accessibilityId,
+                int interactionId, IAccessibilityInteractionConnectionCallback callback) {
+            if (mViewAncestor.get() != null) {
+                getAccessibilityInteractionController()
+                    .findAccessibilityNodeInfoByAccessibilityIdClientThread(accessibilityId,
+                        interactionId, callback);
+            }
+        }
+
+        public void performAccessibilityAction(int accessibilityId, int action,
+                int interactionId, IAccessibilityInteractionConnectionCallback callback) {
+            if (mViewAncestor.get() != null) {
+                getAccessibilityInteractionController()
+                    .performAccessibilityActionClientThread(accessibilityId, action, interactionId,
+                            callback);
+            }
+        }
+
+        public void findAccessibilityNodeInfoByViewId(int viewId,
+                int interactionId, IAccessibilityInteractionConnectionCallback callback) {
+            if (mViewAncestor.get() != null) {
+                getAccessibilityInteractionController()
+                    .findAccessibilityNodeInfoByViewIdClientThread(viewId, interactionId, callback);
+            }
+        }
+
+        public void findAccessibilityNodeInfosByViewText(String text, int accessibilityId,
+                int interactionId, IAccessibilityInteractionConnectionCallback callback) {
+            if (mViewAncestor.get() != null) {
+                getAccessibilityInteractionController()
+                    .findAccessibilityNodeInfosByViewTextClientThread(text, accessibilityId,
+                            interactionId, callback);
+            }
+        }
+    }
+
+    /**
+     * Class for managing accessibility interactions initiated from the system
+     * and targeting the view hierarchy. A *ClientThread method is to be
+     * called from the interaction connection this ViewAncestor gives the
+     * system to talk to it and a corresponding *UiThread method that is executed
+     * on the UI thread.
+     */
+    final class AccessibilityInteractionController {
+        private static final int POOL_SIZE = 5;
+
+        private FindByAccessibilitytIdPredicate mFindByAccessibilityIdPredicate =
+            new FindByAccessibilitytIdPredicate();
+
+        private ArrayList<AccessibilityNodeInfo> mTempAccessibilityNodeInfoList =
+            new ArrayList<AccessibilityNodeInfo>();
+
+        // Reusable poolable arguments for interacting with the view hierarchy
+        // to fit more arguments than Message and to avoid sharing objects between
+        // two messages since several threads can send messages concurrently.
+        private final Pool<SomeArgs> mPool = Pools.synchronizedPool(Pools.finitePool(
+                new PoolableManager<SomeArgs>() {
+                    public SomeArgs newInstance() {
+                        return new SomeArgs();
+                    }
+
+                    public void onAcquired(SomeArgs info) {
+                        /* do nothing */
+                    }
+
+                    public void onReleased(SomeArgs info) {
+                        info.clear();
+                    }
+                }, POOL_SIZE)
+        );
+
+        public class SomeArgs implements Poolable<SomeArgs> {
+            private SomeArgs mNext;
+            private boolean mIsPooled;
+
+            public Object arg1;
+            public Object arg2;
+            public int argi1;
+            public int argi2;
+            public int argi3;
+
+            public SomeArgs getNextPoolable() {
+                return mNext;
+            }
+
+            public boolean isPooled() {
+                return mIsPooled;
+            }
+
+            public void setNextPoolable(SomeArgs args) {
+                mNext = args;
+            }
+
+            public void setPooled(boolean isPooled) {
+                mIsPooled = isPooled;
+            }
+
+            private void clear() {
+                arg1 = null;
+                arg2 = null;
+                argi1 = 0;
+                argi2 = 0;
+                argi3 = 0;
+            }
+        }
+
+        public void findAccessibilityNodeInfoByAccessibilityIdClientThread(int accessibilityId,
+                int interactionId, IAccessibilityInteractionConnectionCallback callback) {
+            Message message = Message.obtain();
+            message.what = DO_FIND_ACCESSIBLITY_NODE_INFO_BY_ACCESSIBILITY_ID;
+            message.arg1 = accessibilityId;
+            message.arg2 = interactionId;
+            message.obj = callback;
+            sendMessage(message);
+        }
+
+        public void findAccessibilityNodeInfoByAccessibilityIdUiThread(Message message) {
+            final int accessibilityId = message.arg1;
+            final int interactionId = message.arg2;
+            final IAccessibilityInteractionConnectionCallback callback =
+                (IAccessibilityInteractionConnectionCallback) message.obj;
+
+            AccessibilityNodeInfo info = null;
+            try {
+                FindByAccessibilitytIdPredicate predicate = mFindByAccessibilityIdPredicate;
+                predicate.init(accessibilityId);
+                View root = ViewAncestor.this.mView;
+                View target = root.findViewByPredicate(predicate);
+                if (target != null && target.isShown()) {
+                    info = target.createAccessibilityNodeInfo();
+                }
+            } finally {
+                try {
+                    callback.setFindAccessibilityNodeInfoResult(info, interactionId);
+                } catch (RemoteException re) {
+                    /* ignore - the other side will time out */
+                }
+            }
+        }
+
+        public void findAccessibilityNodeInfoByViewIdClientThread(int viewId, int interactionId,
+                IAccessibilityInteractionConnectionCallback callback) {
+            Message message = Message.obtain();
+            message.what = DO_FIND_ACCESSIBLITY_NODE_INFO_BY_VIEW_ID;
+            message.arg1 = viewId;
+            message.arg2 = interactionId;
+            message.obj = callback;
+            sendMessage(message);
+        }
+
+        public void findAccessibilityNodeInfoByViewIdUiThread(Message message) {
+            final int viewId = message.arg1;
+            final int interactionId = message.arg2;
+            final IAccessibilityInteractionConnectionCallback callback =
+                (IAccessibilityInteractionConnectionCallback) message.obj;
+
+            AccessibilityNodeInfo info = null;
+            try {
+                View root = ViewAncestor.this.mView;
+                View target = root.findViewById(viewId);
+                if (target != null && target.isShown()) {
+                    info = target.createAccessibilityNodeInfo();
+                }
+            } finally {
+                try {
+                    callback.setFindAccessibilityNodeInfoResult(info, interactionId);
+                } catch (RemoteException re) {
+                    /* ignore - the other side will time out */
+                }
+            }
+        }
+
+        public void findAccessibilityNodeInfosByViewTextClientThread(String text,
+                int accessibilityViewId, int interactionId,
+                IAccessibilityInteractionConnectionCallback callback) {
+            Message message = Message.obtain();
+            message.what = DO_FIND_ACCESSIBLITY_NODE_INFO_BY_VIEW_TEXT;
+            SomeArgs args = mPool.acquire();
+            args.arg1 = text;
+            args.argi1 = accessibilityViewId;
+            args.argi2 = interactionId;
+            args.arg2 = callback;
+            message.obj = args;
+            sendMessage(message);
+        }
+
+        public void findAccessibilityNodeInfosByViewTextUiThread(Message message) {
+            SomeArgs args = (SomeArgs) message.obj;
+            final String text = (String) args.arg1;
+            final int accessibilityViewId = args.argi1;
+            final int interactionId = args.argi2;
+            final IAccessibilityInteractionConnectionCallback callback =
+                (IAccessibilityInteractionConnectionCallback) args.arg2;
+            mPool.release(args);
+
+            List<AccessibilityNodeInfo> infos = null;
+            try {
+                ArrayList<View> foundViews = mAttachInfo.mFocusablesTempList;
+                foundViews.clear();
+
+                View root;
+                if (accessibilityViewId != View.NO_ID) {
+                    root = findViewByAccessibilityId(accessibilityViewId);
+                } else {
+                    root = ViewAncestor.this.mView;
+                }
+
+                if (root == null || !root.isShown()) {
+                    return;
+                }
+
+                root.findViewsWithText(foundViews, text);
+                if (foundViews.isEmpty()) {
+                    return;
+                }
+
+                infos = mTempAccessibilityNodeInfoList;
+                infos.clear();
+
+                final int viewCount = foundViews.size();
+                for (int i = 0; i < viewCount; i++) {
+                    View foundView = foundViews.get(i);
+                    if (foundView.isShown()) {
+                        infos.add(foundView.createAccessibilityNodeInfo());
+                    }
+                 }
+            } finally {
+                try {
+                    callback.setFindAccessibilityNodeInfosResult(infos, interactionId);
+                } catch (RemoteException re) {
+                    /* ignore - the other side will time out */
+                }
+            }
+        }
+
+        public void performAccessibilityActionClientThread(int accessibilityId, int action,
+                int interactionId, IAccessibilityInteractionConnectionCallback callback) {
+            Message message = Message.obtain();
+            message.what = DO_PERFORM_ACCESSIBILITY_ACTION;
+            SomeArgs args = mPool.acquire();
+            args.argi1 = accessibilityId;
+            args.argi2 = action;
+            args.argi3 = interactionId;
+            args.arg1 = callback;
+            message.obj = args;
+            sendMessage(message);
+        }
+
+        public void perfromAccessibilityActionUiThread(Message message) {
+            SomeArgs args = (SomeArgs) message.obj;
+            final int accessibilityId = args.argi1;
+            final int action = args.argi2;
+            final int interactionId = args.argi3;
+            final IAccessibilityInteractionConnectionCallback callback =
+                (IAccessibilityInteractionConnectionCallback) args.arg1;
+            mPool.release(args);
+
+            boolean succeeded = false;
+            try {
+                switch (action) {
+                    case AccessibilityNodeInfo.ACTION_FOCUS: {
+                        succeeded = performActionFocus(accessibilityId);
+                    } break;
+                    case AccessibilityNodeInfo.ACTION_CLEAR_FOCUS: {
+                        succeeded = performActionClearFocus(accessibilityId);
+                    } break;
+                    case AccessibilityNodeInfo.ACTION_SELECT: {
+                        succeeded = performActionSelect(accessibilityId);
+                    } break;
+                    case AccessibilityNodeInfo.ACTION_CLEAR_SELECTION: {
+                        succeeded = performActionClearSelection(accessibilityId);
+                    } break;
+                }
+            } finally {
+                try {
+                    callback.setPerformAccessibilityActionResult(succeeded, interactionId);
+                } catch (RemoteException re) {
+                    /* ignore - the other side will time out */
+                }
+            }
+        }
+
+        private boolean performActionFocus(int accessibilityId) {
+            View target = findViewByAccessibilityId(accessibilityId);
+            if (target == null) {
+                return false;
+            }
+            // Get out of touch mode since accessibility wants to move focus around.
+            ensureTouchMode(false);
+            return target.requestFocus();
+        }
+
+        private boolean performActionClearFocus(int accessibilityId) {
+            View target = findViewByAccessibilityId(accessibilityId);
+            if (target == null) {
+                return false;
+            }
+            if (!target.isFocused()) {
+                return false;
+            }
+            target.clearFocus();
+            return !target.isFocused();
+        }
+
+        private boolean performActionSelect(int accessibilityId) {
+            View target = findViewByAccessibilityId(accessibilityId);
+            if (target == null) {
+                return false;
+            }
+            if (target.isSelected()) {
+                return false;
+            }
+            target.setSelected(true);
+            return target.isSelected();
+        }
+
+        private boolean performActionClearSelection(int accessibilityId) {
+            View target = findViewByAccessibilityId(accessibilityId);
+            if (target == null) {
+                return false;
+            }
+            if (!target.isSelected()) {
+                return false;
+            }
+            target.setSelected(false);
+            return !target.isSelected();
+        }
+
+        private View findViewByAccessibilityId(int accessibilityId) {
+            View root = ViewAncestor.this.mView;
+            if (root == null) {
+                return null;
+            }
+            mFindByAccessibilityIdPredicate.init(accessibilityId);
+            View foundView = root.findViewByPredicate(mFindByAccessibilityIdPredicate);
+            return (foundView != null && foundView.isShown()) ? foundView : null;
+        }
+
+        private final class FindByAccessibilitytIdPredicate implements Predicate<View> {
+            public int mSerchedId;
+
+            public void init(int searchedId) {
+                mSerchedId = searchedId;
+            }
+
+            public boolean apply(View view) {
+                return (view.getAccessibilityViewId() == mSerchedId);
+            }
+        }
+    }
+
+    private class SendWindowContentChanged implements Runnable {
+        public void run() {
+            if (mView != null) {
+                mView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
+            }
+        }
+    }
 }
diff --git a/core/java/android/view/ViewConfiguration.java b/core/java/android/view/ViewConfiguration.java
index 36bb046..5919150 100644
--- a/core/java/android/view/ViewConfiguration.java
+++ b/core/java/android/view/ViewConfiguration.java
@@ -110,7 +110,21 @@
      * double-tap.
      */
     private static final int DOUBLE_TAP_TIMEOUT = 300;
-    
+
+    /**
+     * Defines the maximum duration in milliseconds between a touch pad
+     * touch and release for a given touch to be considered a tap (click) as
+     * opposed to a hover movement gesture.
+     */
+    private static final int HOVER_TAP_TIMEOUT = 150;
+
+    /**
+     * Defines the maximum distance in pixels that a touch pad touch can move
+     * before being released for it to be considered a tap (click) as opposed
+     * to a hover movement gesture.
+     */
+    private static final int HOVER_TAP_SLOP = 20;
+
     /**
      * Defines the duration in milliseconds we want to display zoom controls in response 
      * to a user panning within an application.
@@ -369,7 +383,7 @@
     public static int getTapTimeout() {
         return TAP_TIMEOUT;
     }
-    
+
     /**
      * @return the duration in milliseconds we will wait to see if a touch event
      * is a jump tap. If the user does not move within this interval, it is
@@ -387,7 +401,27 @@
     public static int getDoubleTapTimeout() {
         return DOUBLE_TAP_TIMEOUT;
     }
-    
+
+    /**
+     * @return the maximum duration in milliseconds between a touch pad
+     * touch and release for a given touch to be considered a tap (click) as
+     * opposed to a hover movement gesture.
+     * @hide
+     */
+    public static int getHoverTapTimeout() {
+        return HOVER_TAP_TIMEOUT;
+    }
+
+    /**
+     * @return the maximum distance in pixels that a touch pad touch can move
+     * before being released for it to be considered a tap (click) as opposed
+     * to a hover movement gesture.
+     * @hide
+     */
+    public static int getHoverTapSlop() {
+        return HOVER_TAP_SLOP;
+    }
+
     /**
      * @return Inset in pixels to look for touchable content when the user touches the edge of the
      *         screen
diff --git a/core/java/android/view/ViewGroup.java b/core/java/android/view/ViewGroup.java
index f504b90..a6bce75 100644
--- a/core/java/android/view/ViewGroup.java
+++ b/core/java/android/view/ViewGroup.java
@@ -35,6 +35,7 @@
 import android.util.Log;
 import android.util.SparseArray;
 import android.view.accessibility.AccessibilityEvent;
+import android.view.accessibility.AccessibilityNodeInfo;
 import android.view.animation.AlphaAnimation;
 import android.view.animation.Animation;
 import android.view.animation.AnimationUtils;
@@ -772,6 +773,18 @@
         }
     }
 
+    @Override
+    public void findViewsWithText(ArrayList<View> outViews, CharSequence text) {
+        final int childrenCount = mChildrenCount;
+        final View[] children = mChildren;
+        for (int i = 0; i < childrenCount; i++) {
+            View child = children[i];
+            if ((child.mViewFlags & VISIBILITY_MASK) == VISIBLE) {
+                child.findViewsWithText(outViews, text);
+            }
+        }
+    }
+
     /**
      * {@inheritDoc}
      */
@@ -2007,6 +2020,17 @@
         return false;
     }
 
+    @Override
+    public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
+        super.onInitializeAccessibilityNodeInfo(info);
+        for (int i = 0, count = mChildrenCount; i < count; i++) {
+            View child = mChildren[i];
+            if ((child.mViewFlags & VISIBILITY_MASK) == VISIBLE) {
+                info.addChild(child);
+            }
+        }
+    }
+
     /**
      * {@inheritDoc}
      */
diff --git a/core/java/android/view/ViewPropertyAnimator.java b/core/java/android/view/ViewPropertyAnimator.java
index 9eddf23..a3de285 100644
--- a/core/java/android/view/ViewPropertyAnimator.java
+++ b/core/java/android/view/ViewPropertyAnimator.java
@@ -349,7 +349,7 @@
             }
         }
         mPendingAnimations.clear();
-        mView.getHandler().removeCallbacks(mAnimationStarter);
+        mView.removeCallbacks(mAnimationStarter);
     }
 
     /**
@@ -705,7 +705,7 @@
 
         NameValuesHolder nameValuePair = new NameValuesHolder(constantName, startValue, byValue);
         mPendingAnimations.add(nameValuePair);
-        mView.getHandler().removeCallbacks(mAnimationStarter);
+        mView.removeCallbacks(mAnimationStarter);
         mView.post(mAnimationStarter);
     }
 
diff --git a/core/java/android/view/Window.java b/core/java/android/view/Window.java
index 5236a9e..e07085c 100644
--- a/core/java/android/view/Window.java
+++ b/core/java/android/view/Window.java
@@ -16,6 +16,7 @@
 
 package android.view;
 
+import android.app.Application;
 import android.content.Context;
 import android.content.res.CompatibilityInfo;
 import android.content.res.Configuration;
@@ -25,6 +26,7 @@
 import android.net.Uri;
 import android.os.Bundle;
 import android.os.IBinder;
+import android.util.Slog;
 import android.view.accessibility.AccessibilityEvent;
 
 /**
@@ -463,11 +465,16 @@
         mWindowManager = new LocalWindowManager(wm, hardwareAccelerated);
     }
 
+    static CompatibilityInfoHolder getCompatInfo(Context context) {
+        Application app = (Application)context.getApplicationContext();
+        return app != null ? app.mLoadedApk.mCompatibilityInfo : new CompatibilityInfoHolder();
+    }
+
     private class LocalWindowManager extends WindowManagerImpl.CompatModeWrapper {
         private final boolean mHardwareAccelerated;
 
         LocalWindowManager(WindowManager wm, boolean hardwareAccelerated) {
-            super(wm, mContext.getResources().getCompatibilityInfo());
+            super(wm, getCompatInfo(mContext));
             mHardwareAccelerated = hardwareAccelerated;
         }
 
diff --git a/core/java/android/view/WindowManager.java b/core/java/android/view/WindowManager.java
index a1ddd08..d1ad113 100644
--- a/core/java/android/view/WindowManager.java
+++ b/core/java/android/view/WindowManager.java
@@ -77,8 +77,8 @@
             implements Parcelable {
         /**
          * X position for this window.  With the default gravity it is ignored.
-         * When using {@link Gravity#LEFT} or {@link Gravity#BEFORE} or {@link Gravity#RIGHT} or
-         * {@link Gravity#AFTER} it provides an offset from the given edge.
+         * When using {@link Gravity#LEFT} or {@link Gravity#START} or {@link Gravity#RIGHT} or
+         * {@link Gravity#END} it provides an offset from the given edge.
          */
         @ViewDebug.ExportedProperty
         public int x;
@@ -685,7 +685,19 @@
 
         // ----- HIDDEN FLAGS.
         // These start at the high bit and go down.
-        
+
+        /** Window flag: Enable touches to slide out of a window into neighboring
+         * windows in mid-gesture instead of being captured for the duration of
+         * the gesture.
+         *
+         * This flag changes the behavior of touch focus for this window only.
+         * Touches can slide out of the window but they cannot necessarily slide
+         * back in (unless the other window with touch focus permits it).
+         *
+         * {@hide}
+         */
+        public static final int FLAG_SLIPPERY = 0x04000000;
+
         /**
          * Flag for a window belonging to an activity that responds to {@link KeyEvent#KEYCODE_MENU}
          * and therefore needs a Menu key. For devices where Menu is a physical button this flag is
@@ -992,6 +1004,23 @@
          */
         public boolean hasSystemUiListeners;
 
+        /**
+         * When this window has focus, disable touch pad pointer gesture processing.
+         * The window will receive raw position updates from the touch pad instead
+         * of pointer movements and synthetic touch events.
+         *
+         * @hide
+         */
+        public static final int INPUT_FEATURE_DISABLE_POINTER_GESTURES = 0x00000001;
+
+        /**
+         * Control special features of the input subsystem.
+         *
+         * @see #INPUT_FEATURE_DISABLE_TOUCH_PAD_GESTURES
+         * @hide
+         */
+        public int inputFeatures;
+
         public LayoutParams() {
             super(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
             type = TYPE_APPLICATION;
@@ -1074,6 +1103,7 @@
             out.writeInt(systemUiVisibility);
             out.writeInt(subtreeSystemUiVisibility);
             out.writeInt(hasSystemUiListeners ? 1 : 0);
+            out.writeInt(inputFeatures);
         }
         
         public static final Parcelable.Creator<LayoutParams> CREATOR
@@ -1112,6 +1142,7 @@
             systemUiVisibility = in.readInt();
             subtreeSystemUiVisibility = in.readInt();
             hasSystemUiListeners = in.readInt() != 0;
+            inputFeatures = in.readInt();
         }
     
         @SuppressWarnings({"PointlessBitwiseExpression"})
@@ -1133,6 +1164,8 @@
         public static final int SYSTEM_UI_VISIBILITY_CHANGED = 1<<13;
         /** {@hide} */
         public static final int SYSTEM_UI_LISTENER_CHANGED = 1<<14;
+        /** {@hide} */
+        public static final int INPUT_FEATURES_CHANGED = 1<<15;
     
         // internal buffer to backup/restore parameters under compatibility mode.
         private int[] mCompatibilityParamsBackup = null;
@@ -1244,6 +1277,11 @@
                 changes |= SYSTEM_UI_LISTENER_CHANGED;
             }
 
+            if (inputFeatures != o.inputFeatures) {
+                inputFeatures = o.inputFeatures;
+                changes |= INPUT_FEATURES_CHANGED;
+            }
+
             return changes;
         }
     
@@ -1328,6 +1366,7 @@
                 sb.append(" sysuil=");
                 sb.append(hasSystemUiListeners);
             }
+            sb.append(" if=0x").append(Integer.toHexString(inputFeatures));
             sb.append('}');
             return sb.toString();
         }
diff --git a/core/java/android/view/WindowManagerImpl.java b/core/java/android/view/WindowManagerImpl.java
index d18ae0e..54e7c04 100644
--- a/core/java/android/view/WindowManagerImpl.java
+++ b/core/java/android/view/WindowManagerImpl.java
@@ -19,10 +19,12 @@
 import java.util.HashMap;
 
 import android.content.res.CompatibilityInfo;
+import android.content.res.Configuration;
 import android.graphics.PixelFormat;
 import android.os.IBinder;
 import android.util.AndroidRuntimeException;
 import android.util.Log;
+import android.util.Slog;
 import android.view.WindowManager;
 import android.view.inputmethod.InputMethodManager;
 
@@ -87,29 +89,32 @@
             = new HashMap<CompatibilityInfo, WindowManager>();
 
     static class CompatModeWrapper implements WindowManager {
-        private final WindowManager mWindowManager;
+        private final WindowManagerImpl mWindowManager;
         private final Display mDefaultDisplay;
+        private final CompatibilityInfoHolder mCompatibilityInfo;
 
-        CompatModeWrapper(WindowManager wm, CompatibilityInfo ci) {
-            mWindowManager = wm;
+        CompatModeWrapper(WindowManager wm, CompatibilityInfoHolder ci) {
+            mWindowManager = wm instanceof CompatModeWrapper
+                    ? ((CompatModeWrapper)wm).mWindowManager : (WindowManagerImpl)wm;
 
             // Use the original display if there is no compatibility mode
             // to apply, or the underlying window manager is already a
             // compatibility mode wrapper.  (We assume that if it is a
             // wrapper, it is applying the same compatibility mode.)
-            if (ci == null || wm instanceof CompatModeWrapper
-                    || (!ci.isScalingRequired() && ci.supportsScreen())) {
+            if (ci == null) {
                 mDefaultDisplay = mWindowManager.getDefaultDisplay();
             } else {
                 //mDefaultDisplay = mWindowManager.getDefaultDisplay();
                 mDefaultDisplay = Display.createCompatibleDisplay(
                         mWindowManager.getDefaultDisplay().getDisplayId(), ci);
             }
+
+            mCompatibilityInfo = ci;
         }
 
         @Override
         public void addView(View view, android.view.ViewGroup.LayoutParams params) {
-            mWindowManager.addView(view, params);
+            mWindowManager.addView(view, params, mCompatibilityInfo);
         }
 
         @Override
@@ -145,8 +150,9 @@
     }
 
     public static WindowManager getDefault(CompatibilityInfo compatInfo) {
-        if (compatInfo == null || (!compatInfo.isScalingRequired()
-                && compatInfo.supportsScreen())) {
+        CompatibilityInfoHolder cih = new CompatibilityInfoHolder();
+        cih.set(compatInfo);
+        if (cih.getIfNeeded() == null) {
             return sWindowManager;
         }
 
@@ -158,35 +164,36 @@
             // having to make wrappers.
             WindowManager wm = sCompatWindowManagers.get(compatInfo);
             if (wm == null) {
-                wm = new CompatModeWrapper(sWindowManager, compatInfo);
+                wm = new CompatModeWrapper(sWindowManager, cih);
                 sCompatWindowManagers.put(compatInfo, wm);
             }
             return wm;
         }
     }
+
+    public static WindowManager getDefault(CompatibilityInfoHolder compatInfo) {
+        return new CompatModeWrapper(sWindowManager, compatInfo);
+    }
     
     public boolean isHardwareAccelerated() {
         return false;
     }
     
-    public void addView(View view)
-    {
+    public void addView(View view) {
         addView(view, new WindowManager.LayoutParams(
             WindowManager.LayoutParams.TYPE_APPLICATION, 0, PixelFormat.OPAQUE));
     }
 
-    public void addView(View view, ViewGroup.LayoutParams params)
-    {
-        addView(view, params, false);
+    public void addView(View view, ViewGroup.LayoutParams params) {
+        addView(view, params, null, false);
     }
     
-    public void addViewNesting(View view, ViewGroup.LayoutParams params)
-    {
-        addView(view, params, false);
+    public void addView(View view, ViewGroup.LayoutParams params, CompatibilityInfoHolder cih) {
+        addView(view, params, cih, false);
     }
     
-    private void addView(View view, ViewGroup.LayoutParams params, boolean nest)
-    {
+    private void addView(View view, ViewGroup.LayoutParams params,
+            CompatibilityInfoHolder cih, boolean nest) {
         if (false) Log.v("WindowManager", "addView view=" + view);
 
         if (!(params instanceof WindowManager.LayoutParams)) {
@@ -236,6 +243,11 @@
             
             root = new ViewAncestor(view.getContext());
             root.mAddNesting = 1;
+            if (cih == null) {
+                root.mCompatibilityInfo = new CompatibilityInfoHolder();
+            } else {
+                root.mCompatibilityInfo = cih;
+            }
 
             view.setLayoutParams(wparams);
             
@@ -325,9 +337,11 @@
             return view;
         }
 
-        InputMethodManager imm = InputMethodManager.getInstance(view.getContext());
-        if (imm != null) {
-            imm.windowDismissed(mViews[index].getWindowToken());
+        if (view != null) {
+            InputMethodManager imm = InputMethodManager.getInstance(view.getContext());
+            if (imm != null) {
+                imm.windowDismissed(mViews[index].getWindowToken());
+            }
         }
         root.die(false);
         finishRemoveViewLocked(view, index);
@@ -351,9 +365,11 @@
         removeItem(tmpParams, mParams, index);
         mParams = tmpParams;
 
-        view.assignParent(null);
-        // func doesn't allow null...  does it matter if we clear them?
-        //view.setLayoutParams(null);
+        if (view != null) {
+            view.assignParent(null);
+            // func doesn't allow null...  does it matter if we clear them?
+            //view.setLayoutParams(null);
+        }
     }
 
     public void closeAll(IBinder token, String who, String what) {
@@ -401,6 +417,17 @@
         }
     }
     
+    public void reportNewConfiguration(Configuration config) {
+        synchronized (this) {
+            int count = mViews.length;
+            config = new Configuration(config);
+            for (int i=0; i<count; i++) {
+                ViewAncestor root = mRoots[i];
+                root.requestUpdateConfiguration(config);
+            }
+        }
+    }
+
     public WindowManager.LayoutParams getRootViewLayoutParameter(View view) {
         ViewParent vp = view.getParent();
         while (vp != null && !(vp instanceof ViewAncestor)) {
diff --git a/core/java/android/view/WindowManagerPolicy.java b/core/java/android/view/WindowManagerPolicy.java
index 64b1ac8..8a30c7b 100644
--- a/core/java/android/view/WindowManagerPolicy.java
+++ b/core/java/android/view/WindowManagerPolicy.java
@@ -17,6 +17,7 @@
 package android.view;
 
 import android.content.Context;
+import android.content.res.CompatibilityInfo;
 import android.content.res.Configuration;
 import android.graphics.Rect;
 import android.os.IBinder;
@@ -466,6 +467,12 @@
     public int getMaxWallpaperLayer();
     
     /**
+     * Return true if the policy allows the status bar to hide.  Otherwise,
+     * it is a tablet-style system bar.
+     */
+    public boolean canStatusBarHide();
+
+    /**
      * Return the display width available after excluding any screen
      * decorations that can never be removed.  That is, system bar or
      * button bar.
@@ -533,7 +540,7 @@
      * @see #removeStartingWindow
      */
     public View addStartingWindow(IBinder appToken, String packageName,
-            int theme, CharSequence nonLocalizedLabel,
+            int theme, CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel,
             int labelRes, int icon, int windowFlags);
 
     /**
diff --git a/core/java/android/view/WindowOrientationListener.java b/core/java/android/view/WindowOrientationListener.java
index d128b57..5d4fbbe 100755
--- a/core/java/android/view/WindowOrientationListener.java
+++ b/core/java/android/view/WindowOrientationListener.java
@@ -321,18 +321,18 @@
         private static final float ORIENTATION_ANGLE_CONFIDENCE_SCALE =
                 confidenceScaleFromDelta(30);
 
-        // Transition takes 2x longer when tilt is 45 degrees from vertical.
-        private static final float TILT_ANGLE_CONFIDENCE_SCALE = confidenceScaleFromDelta(45);
+        // Transition takes 2x longer when tilt is 60 degrees from vertical.
+        private static final float TILT_ANGLE_CONFIDENCE_SCALE = confidenceScaleFromDelta(60);
 
-        // Transition takes 2x longer when acceleration is 0.25 Gs.
+        // Transition takes 2x longer when acceleration is 0.5 Gs.
         private static final float MAGNITUDE_CONFIDENCE_SCALE = confidenceScaleFromDelta(
-                SensorManager.STANDARD_GRAVITY * 0.25f);
+                SensorManager.STANDARD_GRAVITY * 0.5f);
 
         // The number of milliseconds for which a new orientation must be stable before
         // we perform an orientation change under ideal conditions.  It will take
         // proportionally longer than this to effect an orientation change when
         // the proposed orientation confidence is low.
-        private static final float ORIENTATION_SETTLE_TIME_MS = 250;
+        private static final float ORIENTATION_SETTLE_TIME_MS = 100;
 
         // The confidence that we have abount effecting each orientation change.
         // When one of these values exceeds 1.0, we have determined our new orientation!
diff --git a/core/java/android/view/accessibility/AccessibilityEvent.java b/core/java/android/view/accessibility/AccessibilityEvent.java
index 5e18f55..5ef7763 100644
--- a/core/java/android/view/accessibility/AccessibilityEvent.java
+++ b/core/java/android/view/accessibility/AccessibilityEvent.java
@@ -16,11 +16,13 @@
 
 package android.view.accessibility;
 
+import android.accessibilityservice.IAccessibilityServiceConnection;
 import android.os.Parcel;
 import android.os.Parcelable;
 import android.text.TextUtils;
 
 import java.util.ArrayList;
+import java.util.List;
 
 /**
  * This class represents accessibility events that are sent by the system when
@@ -127,7 +129,7 @@
  * <p>
  * <b>TRANSITION TYPES</b> <br>
  * <p>
- * <b>Window state changed</b> - represents the event of opening/closing a
+ * <b>Window state changed</b> - represents the event of opening a
  * {@link android.widget.PopupWindow}, {@link android.view.Menu},
  * {@link android.app.Dialog}, etc. <br>
  * Type: {@link #TYPE_WINDOW_STATE_CHANGED} <br>
@@ -137,6 +139,16 @@
  * {@link #getEventTime()},
  * {@link #getText()}
  * <p>
+ * <b>Window content changed</b> - represents the event of change in the
+ * content of a window. This change can be adding/removing view, changing
+ * a view size, etc.<br>
+ * Type: {@link #TYPE_WINDOW_CONTENT_CHANGED} <br>
+ * Properties:
+ * {@link #getClassName()},
+ * {@link #getPackageName()},
+ * {@link #getEventTime()},
+ * {@link #getText()}
+ * <p>
  * <b>NOTIFICATION TYPES</b> <br>
  * <p>
  * <b>Notification state changed</b> - represents the event showing/hiding
@@ -159,6 +171,7 @@
  * @see android.accessibilityservice.AccessibilityService
  */
 public final class AccessibilityEvent extends AccessibilityRecord implements Parcelable {
+    private static final boolean DEBUG = false;
 
     /**
      * Invalid selection/focus position.
@@ -240,6 +253,11 @@
     public static final int TYPE_TOUCH_EXPLORATION_GESTURE_END = 0x00000400;
 
     /**
+     * Represents the event of changing the content of a window.
+     */
+    public static final int TYPE_WINDOW_CONTENT_CHANGED = 0x00000800;
+
+    /**
      * Mask for {@link AccessibilityEvent} all types.
      *
      * @see #TYPE_VIEW_CLICKED
@@ -256,7 +274,6 @@
     private static final Object sPoolLock = new Object();
     private static AccessibilityEvent sPool;
     private static int sPoolSize;
-
     private AccessibilityEvent mNext;
     private boolean mIsInPool;
 
@@ -270,7 +287,54 @@
      * Hide constructor from clients.
      */
     private AccessibilityEvent() {
+    }
 
+    /**
+     * Initialize an event from another one.
+     *
+     * @param event The event to initialize from.
+     */
+    void init(AccessibilityEvent event) {
+        super.init(event);
+        mEventType = event.mEventType;
+        mEventTime = event.mEventTime;
+        mPackageName = event.mPackageName;
+    }
+
+    /**
+     * Sets the connection for interacting with the AccessibilityManagerService.
+     *
+     * @param connection The connection.
+     *
+     * @hide
+     */
+    @Override
+    public void setConnection(IAccessibilityServiceConnection connection) {
+        super.setConnection(connection);
+        List<AccessibilityRecord> records = mRecords;
+        final int recordCount = records.size();
+        for (int i = 0; i < recordCount; i++) {
+            AccessibilityRecord record = records.get(i);
+            record.setConnection(connection);
+        }
+    }
+
+    /**
+     * Sets if this instance is sealed.
+     *
+     * @param sealed Whether is sealed.
+     *
+     * @hide
+     */
+    @Override
+    public void setSealed(boolean sealed) {
+        super.setSealed(sealed);
+        List<AccessibilityRecord> records = mRecords;
+        final int recordCount = records.size();
+        for (int i = 0; i < recordCount; i++) {
+            AccessibilityRecord record = records.get(i);
+            record.setSealed(sealed);
+        }
     }
 
     /**
@@ -286,8 +350,11 @@
      * Appends an {@link AccessibilityRecord} to the end of event records.
      *
      * @param record The record to append.
+     *
+     * @throws IllegalStateException If called from an AccessibilityService.
      */
     public void appendRecord(AccessibilityRecord record) {
+        enforceNotSealed();
         mRecords.add(record);
     }
 
@@ -314,8 +381,11 @@
      * Sets the event type.
      *
      * @param eventType The event type.
+     *
+     * @throws IllegalStateException If called from an AccessibilityService.
      */
     public void setEventType(int eventType) {
+        enforceNotSealed();
         mEventType = eventType;
     }
 
@@ -332,8 +402,11 @@
      * Sets the time in which this event was sent.
      *
      * @param eventTime The event time.
+     *
+     * @throws IllegalStateException If called from an AccessibilityService.
      */
     public void setEventTime(long eventTime) {
+        enforceNotSealed();
         mEventTime = eventTime;
     }
 
@@ -350,8 +423,11 @@
      * Sets the package name of the source.
      *
      * @param packageName The package name.
+     *
+     * @throws IllegalStateException If called from an AccessibilityService.
      */
     public void setPackageName(CharSequence packageName) {
+        enforceNotSealed();
         mPackageName = packageName;
     }
 
@@ -370,6 +446,27 @@
 
     /**
      * Returns a cached instance if such is available or a new one is
+     * instantiated with type property set.
+     *
+     * @param event The other event.
+     * @return An instance.
+     */
+    public static AccessibilityEvent obtain(AccessibilityEvent event) {
+        AccessibilityEvent eventClone = AccessibilityEvent.obtain();
+        eventClone.init(event);
+
+        final int recordCount = event.mRecords.size();
+        for (int i = 0; i < recordCount; i++) {
+            AccessibilityRecord record = event.mRecords.get(i);
+            AccessibilityRecord recordClone = AccessibilityRecord.obtain(record);
+            eventClone.mRecords.add(recordClone);
+        }
+
+        return eventClone;
+    }
+
+    /**
+     * Returns a cached instance if such is available or a new one is
      * instantiated.
      *
      * @return An instance.
@@ -413,6 +510,8 @@
 
     /**
      * Clears the state of this instance.
+     *
+     * @hide
      */
     @Override
     protected void clear() {
@@ -432,6 +531,11 @@
      * @param parcel A parcel containing the state of a {@link AccessibilityEvent}.
      */
     public void initFromParcel(Parcel parcel) {
+        if (parcel.readInt() == 1) {
+            mConnection = IAccessibilityServiceConnection.Stub.asInterface(
+                    parcel.readStrongBinder());
+        }
+        setSealed(parcel.readInt() == 1);
         mEventType = parcel.readInt();
         mPackageName = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel);
         mEventTime = parcel.readLong();
@@ -442,6 +546,8 @@
         for (int i = 0; i < recordCount; i++) {
             AccessibilityRecord record = AccessibilityRecord.obtain();
             readAccessibilityRecordFromParcel(record, parcel);
+            // Do this to write the connection only once.
+            record.setConnection(mConnection);
             mRecords.add(record);
         }
     }
@@ -465,12 +571,22 @@
         record.mBeforeText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel);
         record.mParcelableData = parcel.readParcelable(null);
         parcel.readList(record.mText, null);
+        record.mSourceWindowId = parcel.readInt();
+        record.mSourceViewId = parcel.readInt();
+        record.mSealed = (parcel.readInt() == 1);
     }
 
     /**
      * {@inheritDoc}
      */
     public void writeToParcel(Parcel parcel, int flags) {
+        if (mConnection == null) {
+            parcel.writeInt(0);
+        } else {
+            parcel.writeInt(1);
+            parcel.writeStrongBinder(mConnection.asBinder());
+        }
+        parcel.writeInt(isSealed() ? 1 : 0);
         parcel.writeInt(mEventType);
         TextUtils.writeToParcel(mPackageName, parcel, 0);
         parcel.writeLong(mEventTime);
@@ -504,6 +620,9 @@
         TextUtils.writeToParcel(record.mBeforeText, parcel, flags);
         parcel.writeParcelable(record.mParcelableData, flags);
         parcel.writeList(record.mText);
+        parcel.writeInt(record.mSourceWindowId);
+        parcel.writeInt(record.mSourceViewId);
+        parcel.writeInt(record.mSealed ? 1 : 0);
     }
 
     /**
@@ -516,25 +635,81 @@
     @Override
     public String toString() {
         StringBuilder builder = new StringBuilder();
-        builder.append("; EventType: " + mEventType);
-        builder.append("; EventTime: " + mEventTime);
-        builder.append("; PackageName: " + mPackageName);
-        builder.append(" \n{\n");
+        builder.append("; EventType: ").append(eventTypeToString(mEventType));
+        builder.append("; EventTime: ").append(mEventTime);
+        builder.append("; PackageName: ").append(mPackageName);
         builder.append(super.toString());
-        builder.append("\n");
-        for (int i = 0; i < mRecords.size(); i++) {
-            AccessibilityRecord record = mRecords.get(i);
-            builder.append("  Record ");
-            builder.append(i);
-            builder.append(":");
-            builder.append(record.toString());
+        if (DEBUG) {
             builder.append("\n");
+            builder.append("; sourceWindowId: ").append(mSourceWindowId);
+            builder.append("; sourceViewId: ").append(mSourceViewId);
+            for (int i = 0; i < mRecords.size(); i++) {
+                AccessibilityRecord record = mRecords.get(i);
+                builder.append("  Record ");
+                builder.append(i);
+                builder.append(":");
+                builder.append(" [ ClassName: " + record.mClassName);
+                builder.append("; Text: " + record.mText);
+                builder.append("; ContentDescription: " + record.mContentDescription);
+                builder.append("; ItemCount: " + record.mItemCount);
+                builder.append("; CurrentItemIndex: " + record.mCurrentItemIndex);
+                builder.append("; IsEnabled: " + record.isEnabled());
+                builder.append("; IsPassword: " + record.isPassword());
+                builder.append("; IsChecked: " + record.isChecked());
+                builder.append("; IsFullScreen: " + record.isFullScreen());
+                builder.append("; BeforeText: " + record.mBeforeText);
+                builder.append("; FromIndex: " + record.mFromIndex);
+                builder.append("; AddedCount: " + record.mAddedCount);
+                builder.append("; RemovedCount: " + record.mRemovedCount);
+                builder.append("; ParcelableData: " + record.mParcelableData);
+                builder.append(" ]");
+                builder.append("\n");
+            }
+        } else {
+            builder.append("; recordCount: ").append(getAddedCount());
         }
-        builder.append("}\n");
         return builder.toString();
     }
 
     /**
+     * Returns the string representation of an event type. For example,
+     * {@link #TYPE_VIEW_CLICKED} is represented by the string TYPE_VIEW_CLICKED.
+     *
+     * @param feedbackType The event type
+     * @return The string representation.
+     */
+    public static String eventTypeToString(int feedbackType) {
+        switch (feedbackType) {
+            case TYPE_VIEW_CLICKED:
+                return "TYPE_VIEW_CLICKED";
+            case TYPE_VIEW_LONG_CLICKED:
+                return "TYPE_VIEW_LONG_CLICKED";
+            case TYPE_VIEW_SELECTED:
+                return "TYPE_VIEW_SELECTED";
+            case TYPE_VIEW_FOCUSED:
+                return "TYPE_VIEW_FOCUSED";
+            case TYPE_VIEW_TEXT_CHANGED:
+                return "TYPE_VIEW_TEXT_CHANGED";
+            case TYPE_WINDOW_STATE_CHANGED:
+                return "TYPE_WINDOW_STATE_CHANGED";
+            case TYPE_VIEW_HOVER_ENTER:
+                return "TYPE_VIEW_HOVER_ENTER";
+            case TYPE_VIEW_HOVER_EXIT:
+                return "TYPE_VIEW_HOVER_EXIT";
+            case TYPE_NOTIFICATION_STATE_CHANGED:
+                return "TYPE_NOTIFICATION_STATE_CHANGED";  
+            case TYPE_TOUCH_EXPLORATION_GESTURE_START:
+                return "TYPE_TOUCH_EXPLORATION_GESTURE_START";
+            case TYPE_TOUCH_EXPLORATION_GESTURE_END:
+                return "TYPE_TOUCH_EXPLORATION_GESTURE_END";
+            case TYPE_WINDOW_CONTENT_CHANGED:
+                return "TYPE_WINDOW_CONTENT_CHANGED";
+            default:
+                return null;
+        }
+    }
+
+    /**
      * @see Parcelable.Creator
      */
     public static final Parcelable.Creator<AccessibilityEvent> CREATOR =
diff --git a/core/java/android/view/accessibility/AccessibilityManager.java b/core/java/android/view/accessibility/AccessibilityManager.java
index dd77193..eece64a 100644
--- a/core/java/android/view/accessibility/AccessibilityManager.java
+++ b/core/java/android/view/accessibility/AccessibilityManager.java
@@ -16,7 +16,6 @@
 
 package android.view.accessibility;
 
-import android.accessibilityservice.AccessibilityService;
 import android.accessibilityservice.AccessibilityServiceInfo;
 import android.content.Context;
 import android.content.pm.ServiceInfo;
@@ -29,9 +28,13 @@
 import android.os.ServiceManager;
 import android.os.SystemClock;
 import android.util.Log;
+import android.view.IWindow;
+import android.view.View;
 
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
 
 /**
  * System level service that serves as an event dispatch for {@link AccessibilityEvent}s.
@@ -62,6 +65,21 @@
 
     boolean mIsEnabled;
 
+    final CopyOnWriteArrayList<AccessibilityStateChangeListener> mAccessibilityStateChangeListeners =
+        new CopyOnWriteArrayList<AccessibilityStateChangeListener>();
+
+    /**
+     * Listener for the accessibility state.
+     */
+    public interface AccessibilityStateChangeListener {
+        /**
+         * Called back on change in the accessibility state.
+         *
+         * @param enabled
+         */
+        public void onAccessibilityStateChanged(boolean enabled);
+    }
+
     final IAccessibilityManagerClient.Stub mClient = new IAccessibilityManagerClient.Stub() {
         public void setEnabled(boolean enabled) {
             mHandler.obtainMessage(DO_SET_ENABLED, enabled ? 1 : 0, 0).sendToTarget();
@@ -78,9 +96,8 @@
         public void handleMessage(Message message) {
             switch (message.what) {
                 case DO_SET_ENABLED :
-                    synchronized (mHandler) {
-                        mIsEnabled = (message.arg1 == 1);
-                    }
+                    final boolean isEnabled = (message.arg1 == 1);
+                    setAccessibilityState(isEnabled);
                     return;
                 default :
                     Log.w(LOG_TAG, "Unknown message type: " + message.what);
@@ -117,7 +134,8 @@
         mService = service;
 
         try {
-            mIsEnabled = mService.addClient(mClient);
+            final boolean isEnabled = mService.addClient(mClient);
+            setAccessibilityState(isEnabled);
         } catch (RemoteException re) {
             Log.e(LOG_TAG, "AccessibilityManagerService is dead", re);
         }
@@ -201,11 +219,30 @@
      * Returns the {@link ServiceInfo}s of the installed accessibility services.
      *
      * @return An unmodifiable list with {@link ServiceInfo}s.
+     *
+     * @deprecated Use {@link #getInstalledAccessibilityServiceList()}
      */
+    @Deprecated
     public List<ServiceInfo> getAccessibilityServiceList() {
-        List<ServiceInfo> services = null;
+        List<AccessibilityServiceInfo> infos = getInstalledAccessibilityServiceList();
+        List<ServiceInfo> services = new ArrayList<ServiceInfo>();
+        final int infoCount = infos.size();
+        for (int i = 0; i < infoCount; i++) {
+            AccessibilityServiceInfo info = infos.get(i);
+            services.add(info.getResolveInfo().serviceInfo);
+        }
+        return Collections.unmodifiableList(services);
+    }
+
+    /**
+     * Returns the {@link AccessibilityServiceInfo}s of the installed accessibility services.
+     *
+     * @return An unmodifiable list with {@link AccessibilityServiceInfo}s.
+     */
+    public List<AccessibilityServiceInfo> getInstalledAccessibilityServiceList() {
+        List<AccessibilityServiceInfo> services = null;
         try {
-            services = mService.getAccessibilityServiceList();
+            services = mService.getInstalledAccessibilityServiceList();
             if (DEBUG) {
                 Log.i(LOG_TAG, "Installed AccessibilityServices " + services);
             }
@@ -216,20 +253,14 @@
     }
 
     /**
-     * Returns the {@link ServiceInfo}s of the enabled accessibility services
+     * Returns the {@link AccessibilityServiceInfo}s of the enabled accessibility services
      * for a given feedback type.
      *
-     * @param feedbackType The type of feedback.
-     * @return An unmodifiable list with {@link ServiceInfo}s.
-     *
-     * @see AccessibilityServiceInfo#FEEDBACK_AUDIBLE
-     * @see AccessibilityServiceInfo#FEEDBACK_HAPTIC
-     * @see AccessibilityServiceInfo#FEEDBACK_SPOKEN
-     * @see AccessibilityServiceInfo#FEEDBACK_VISUAL
-     * @see AccessibilityServiceInfo#FEEDBACK_GENERIC
+     * @param feedbackType The feedback type (can be bitwise or of multiple types).
+     * @return An unmodifiable list with {@link AccessibilityServiceInfo}s.
      */
-    public List<ServiceInfo> getEnabledAccessibilityServiceList(int feedbackType) {
-        List<ServiceInfo> services = null;
+    public List<AccessibilityServiceInfo> getEnabledAccessibilityServiceList(int feedbackType) {
+        List<AccessibilityServiceInfo> services = null;
         try {
             services = mService.getEnabledAccessibilityServiceList(feedbackType);
             if (DEBUG) {
@@ -240,4 +271,81 @@
         }
         return Collections.unmodifiableList(services);
     }
+
+    /**
+     * Registers an {@link AccessibilityStateChangeListener}.
+     *
+     * @param listener The listener.
+     * @return True if successfully registered.
+     */
+    public boolean addAccessibilityStateChangeListener(
+            AccessibilityStateChangeListener listener) {
+        return mAccessibilityStateChangeListeners.add(listener);
+    }
+
+    /**
+     * Unregisters an {@link AccessibilityStateChangeListener}.
+     *
+     * @param listener The listener.
+     * @return True if successfully unregistered.
+     */
+    public boolean removeAccessibilityStateChangeListener(
+            AccessibilityStateChangeListener listener) {
+        return mAccessibilityStateChangeListeners.remove(listener);
+    }
+
+    /**
+     * Sets the enabled state.
+     *
+     * @param isEnabled The accessibility state.
+     */
+    private void setAccessibilityState(boolean isEnabled) {
+        synchronized (mHandler) {
+            if (isEnabled != mIsEnabled) {
+                mIsEnabled = isEnabled;
+                notifyAccessibilityStateChanged();
+            }
+        }
+    }
+
+    /**
+     * Notifies the registered {@link AccessibilityStateChangeListener}s.
+     */
+    private void notifyAccessibilityStateChanged() {
+        final int listenerCount = mAccessibilityStateChangeListeners.size();
+        for (int i = 0; i < listenerCount; i++) {
+            mAccessibilityStateChangeListeners.get(i).onAccessibilityStateChanged(mIsEnabled);
+        }
+    }
+
+    /**
+     * Adds an accessibility interaction connection interface for a given window.
+     * @param windowToken The window token to which a connection is added.
+     * @param connection The connection.
+     *
+     * @hide
+     */
+    public int addAccessibilityInteractionConnection(IWindow windowToken,
+            IAccessibilityInteractionConnection connection) {
+        try {
+            return mService.addAccessibilityInteractionConnection(windowToken, connection);
+        } catch (RemoteException re) {
+            Log.e(LOG_TAG, "Error while adding an accessibility interaction connection. ", re);
+        }
+        return View.NO_ID;
+    }
+
+    /**
+     * Removed an accessibility interaction connection interface for a given window.
+     * @param windowToken The window token to which a connection is removed.
+     *
+     * @hide
+     */
+    public void removeAccessibilityInteractionConnection(IWindow windowToken) {
+        try {
+            mService.removeAccessibilityInteractionConnection(windowToken);
+        } catch (RemoteException re) {
+            Log.e(LOG_TAG, "Error while removing an accessibility interaction connection. ", re);
+        }
+    }
 }
diff --git a/core/java/android/view/accessibility/AccessibilityNodeInfo.aidl b/core/java/android/view/accessibility/AccessibilityNodeInfo.aidl
new file mode 100644
index 0000000..59175ce
--- /dev/null
+++ b/core/java/android/view/accessibility/AccessibilityNodeInfo.aidl
@@ -0,0 +1,19 @@
+/**
+ * Copyright (c) 2011, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.view.accessibility;
+
+parcelable AccessibilityNodeInfo;
diff --git a/core/java/android/view/accessibility/AccessibilityNodeInfo.java b/core/java/android/view/accessibility/AccessibilityNodeInfo.java
new file mode 100644
index 0000000..18ef38a
--- /dev/null
+++ b/core/java/android/view/accessibility/AccessibilityNodeInfo.java
@@ -0,0 +1,1051 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.view.accessibility;
+
+import android.accessibilityservice.IAccessibilityServiceConnection;
+import android.graphics.Rect;
+import android.os.Parcel;
+import android.os.Parcelable;
+import android.os.RemoteException;
+import android.text.TextUtils;
+import android.util.SparseArray;
+import android.util.SparseIntArray;
+import android.view.View;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * This class represents a node of the screen content. From the point of
+ * view of an accessibility service the screen content is presented as tree
+ * of accessibility nodes.
+ *
+ * TODO(svertoslavganov): Update the documentation, add sample, and describe
+ *                        the security policy.
+ */
+public class AccessibilityNodeInfo implements Parcelable {
+
+    private static final boolean DEBUG = false;
+
+    // Actions.
+
+    /**
+     * Action that focuses the node.
+     */
+    public static final int ACTION_FOCUS =  0x00000001;
+
+    /**
+     * Action that unfocuses the node.
+     */
+    public static final int ACTION_CLEAR_FOCUS =  0x00000002;
+
+    /**
+     * Action that selects the node.
+     */
+    public static final int ACTION_SELECT =  0x00000004;
+
+    /**
+     * Action that unselects the node.
+     */
+    public static final int ACTION_CLEAR_SELECTION =  0x00000008;
+
+    // Boolean attributes.
+
+    private static final int PROPERTY_CHECKABLE = 0x00000001;
+
+    private static final int PROPERTY_CHECKED = 0x00000002;
+
+    private static final int PROPERTY_FOCUSABLE = 0x00000004;
+
+    private static final int PROPERTY_FOCUSED = 0x00000008;
+
+    private static final int PROPERTY_SELECTED = 0x00000010;
+
+    private static final int PROPERTY_CLICKABLE = 0x00000020;
+
+    private static final int PROPERTY_LONG_CLICKABLE = 0x00000040;
+
+    private static final int PROPERTY_ENABLED = 0x00000080;
+
+    private static final int PROPERTY_PASSWORD = 0x00000100;
+
+    // Readable representations - lazily initialized.
+    private static SparseArray<String> sActionSymbolicNames;
+
+    // Housekeeping.
+    private static final int MAX_POOL_SIZE = 50;
+    private static final Object sPoolLock = new Object();
+    private static AccessibilityNodeInfo sPool;
+    private static int sPoolSize;
+    private AccessibilityNodeInfo mNext;
+    private boolean mIsInPool;
+    private boolean mSealed;
+
+    // Data.
+    private int mAccessibilityViewId = View.NO_ID;
+    private int mAccessibilityWindowId = View.NO_ID;
+    private int mParentAccessibilityViewId = View.NO_ID;
+    private int mBooleanProperties;
+    private final Rect mBoundsInParent = new Rect();
+    private final Rect mBoundsInScreen = new Rect();
+
+    private CharSequence mPackageName;
+    private CharSequence mClassName;
+    private CharSequence mText;
+    private CharSequence mContentDescription;
+
+    private final SparseIntArray mChildAccessibilityIds = new SparseIntArray();
+    private int mActions;
+
+    private IAccessibilityServiceConnection mConnection;
+
+    /**
+     * Hide constructor from clients.
+     */
+    private AccessibilityNodeInfo() {
+        /* do nothing */
+    }
+
+    /**
+     * Sets the source.
+     *
+     * @param source The info source.
+     */
+    public void setSource(View source) {
+        enforceNotSealed();
+        mAccessibilityViewId = source.getAccessibilityViewId();
+        mAccessibilityWindowId = source.getAccessibilityWindowId();
+    }
+
+    /**
+     * Gets the id of the window from which the info comes from.
+     *
+     * @return The window id.
+     */
+    public int getWindowId() {
+        return mAccessibilityWindowId;
+    }
+
+    /**
+     * Gets the number of children.
+     *
+     * @return The child count.
+     */
+    public int getChildCount() {
+        return mChildAccessibilityIds.size();
+    }
+
+    /**
+     * Get the child at given index.
+     * <p>
+     *   <strong>
+     *     It is a client responsibility to recycle the received info by
+     *     calling {@link AccessibilityNodeInfo#recycle()} to avoid creating
+     *     of multiple instances.
+     *   </strong>
+     * </p>
+     * @param index The child index.
+     * @return The child node.
+     *
+     * @throws IllegalStateException If called outside of an AccessibilityService.
+     *
+     */
+    public AccessibilityNodeInfo getChild(int index) {
+        enforceSealed();
+        final int childAccessibilityViewId = mChildAccessibilityIds.get(index);
+        if (!canPerformRequestOverConnection(childAccessibilityViewId)) {
+            return null;
+        }
+        try {
+            return mConnection.findAccessibilityNodeInfoByAccessibilityId(mAccessibilityWindowId,
+                    childAccessibilityViewId);
+        } catch (RemoteException re) {
+             /* ignore*/
+        }
+        return null;
+    }
+
+    /**
+     * Adds a child.
+     * <p>
+     *   Note: Cannot be called from an {@link android.accessibilityservice.AccessibilityService}.
+     *   This class is made immutable before being delivered to an AccessibilityService.
+     * </p>
+     * @param child The child.
+     *
+     * @throws IllegalStateException If called from an AccessibilityService.
+     */
+    public void addChild(View child) {
+        enforceNotSealed();
+        final int childAccessibilityViewId = child.getAccessibilityViewId();
+        final int index = mChildAccessibilityIds.size();
+        mChildAccessibilityIds.put(index, childAccessibilityViewId);
+    }
+
+    /**
+     * Gets the actions that can be performed on the node.
+     *
+     * @return The bit mask of with actions.
+     *
+     * @see AccessibilityNodeInfo#ACTION_FOCUS
+     * @see AccessibilityNodeInfo#ACTION_CLEAR_FOCUS
+     * @see AccessibilityNodeInfo#ACTION_SELECT
+     * @see AccessibilityNodeInfo#ACTION_CLEAR_SELECTION
+     */
+    public int getActions() {
+        return mActions;
+    }
+
+    /**
+     * Adds an action that can be performed on the node.
+     * <p>
+     *   Note: Cannot be called from an {@link android.accessibilityservice.AccessibilityService}.
+     *   This class is made immutable before being delivered to an AccessibilityService.
+     * </p>
+     * @param action The action.
+     *
+     * @throws IllegalStateException If called from an AccessibilityService.
+     */
+    public void addAction(int action) {
+        enforceNotSealed();
+        mActions |= action;
+    }
+
+    /**
+     * Performs an action on the node.
+     * <p>
+     *   Note: An action can be performed only if the request is made
+     *   from an {@link android.accessibilityservice.AccessibilityService}.
+     * </p>
+     * @param action The action to perform.
+     * @return True if the action was performed.
+     *
+     * @throws IllegalStateException If called outside of an AccessibilityService.
+     */
+    public boolean performAction(int action) {
+        enforceSealed();
+        if (!canPerformRequestOverConnection(mAccessibilityViewId)) {
+            return false;
+        }
+        try {
+            return mConnection.performAccessibilityAction(mAccessibilityWindowId,
+                    mAccessibilityViewId, action);
+        } catch (RemoteException e) {
+            /* ignore */
+        }
+        return false;
+    }
+
+    /**
+     * Finds {@link AccessibilityNodeInfo}s by text. The match is case
+     * insensitive containment.
+     *
+     * @param text The searched text.
+     * @return A list of node info.
+     */
+    public List<AccessibilityNodeInfo> findAccessibilityNodeInfosByText(String text) {
+        enforceSealed();
+        if (!canPerformRequestOverConnection(mAccessibilityViewId)) {
+            return null;
+        }
+        try {
+            return mConnection.findAccessibilityNodeInfosByViewText(text, mAccessibilityWindowId,
+                    mAccessibilityViewId);
+        } catch (RemoteException e) {
+            /* ignore */
+        }
+        return Collections.emptyList();
+    }
+
+    /**
+     * Gets the unique id identifying this node's parent.
+     * <p>
+     *   <strong>
+     *     It is a client responsibility to recycle the received info by
+     *     calling {@link AccessibilityNodeInfo#recycle()} to avoid creating
+     *     of multiple instances.
+     *   </strong>
+     * </p>
+     * @return The node's patent id.
+     */
+    public AccessibilityNodeInfo getParent() {
+        enforceSealed();
+        if (!canPerformRequestOverConnection(mAccessibilityViewId)) {
+            return null;
+        }
+        try {
+            return mConnection.findAccessibilityNodeInfoByAccessibilityId(
+                    mAccessibilityWindowId, mParentAccessibilityViewId);
+        } catch (RemoteException e) {
+            /* ignore */
+        }
+        return null;
+    }
+
+    /**
+     * Sets the parent.
+     * <p>
+     *   Note: Cannot be called from an {@link android.accessibilityservice.AccessibilityService}.
+     *   This class is made immutable before being delivered to an AccessibilityService.
+     * </p>
+     * @param parent The parent.
+     *
+     * @throws IllegalStateException If called from an AccessibilityService.
+     */
+    public void setParent(View parent) {
+        enforceNotSealed();
+        mParentAccessibilityViewId = parent.getAccessibilityViewId();
+    }
+
+    /**
+     * Gets the node bounds in parent coordinates.
+     *
+     * @param outBounds The output node bounds.
+     */
+    public void getBoundsInParent(Rect outBounds) {
+        outBounds.set(mBoundsInParent.left, mBoundsInParent.top,
+                mBoundsInParent.right, mBoundsInParent.bottom);
+    }
+
+    /**
+     * Sets the node bounds in parent coordinates.
+     * <p>
+     *   Note: Cannot be called from an {@link android.accessibilityservice.AccessibilityService}.
+     *   This class is made immutable before being delivered to an AccessibilityService.
+     * </p>
+     * @param bounds The node bounds.
+     *
+     * @throws IllegalStateException If called from an AccessibilityService.
+     */
+    public void setBoundsInParent(Rect bounds) {
+        enforceNotSealed();
+        mBoundsInParent.set(bounds.left, bounds.top, bounds.right, bounds.bottom);
+    }
+
+    /**
+     * Gets the node bounds in screen coordinates.
+     *
+     * @param outBounds The output node bounds.
+     */
+    public void getBoundsInScreen(Rect outBounds) {
+        outBounds.set(mBoundsInScreen.left, mBoundsInScreen.top,
+                mBoundsInScreen.right, mBoundsInScreen.bottom);
+    }
+
+    /**
+     * Sets the node bounds in screen coordinates.
+     * <p>
+     *   Note: Cannot be called from an {@link android.accessibilityservice.AccessibilityService}.
+     *   This class is made immutable before being delivered to an AccessibilityService.
+     * </p>
+     * @param bounds The node bounds.
+     *
+     * @throws IllegalStateException If called from an AccessibilityService.
+     */
+    public void setBoundsInScreen(Rect bounds) {
+        enforceNotSealed();
+        mBoundsInScreen.set(bounds.left, bounds.top, bounds.right, bounds.bottom);
+    }
+
+    /**
+     * Gets whether this node is checkable.
+     *
+     * @return True if the node is checkable.
+     */
+    public boolean isCheckable() {
+        return getBooleanProperty(PROPERTY_CHECKABLE);
+    }
+
+    /**
+     * Sets whether this node is checkable.
+     * <p>
+     *   Note: Cannot be called from an {@link android.accessibilityservice.AccessibilityService}.
+     *   This class is made immutable before being delivered to an AccessibilityService.
+     * </p>
+     * @param checkable True if the node is checkable.
+     *
+     * @throws IllegalStateException If called from an AccessibilityService.
+     */
+    public void setCheckable(boolean checkable) {
+        setBooleanProperty(PROPERTY_CHECKABLE, checkable);
+    }
+
+    /**
+     * Gets whether this node is checked.
+     *
+     * @return True if the node is checked.
+     */
+    public boolean isChecked() {
+        return getBooleanProperty(PROPERTY_CHECKED);
+    }
+
+    /**
+     * Sets whether this node is checked.
+     * <p>
+     *   Note: Cannot be called from an {@link android.accessibilityservice.AccessibilityService}.
+     *   This class is made immutable before being delivered to an AccessibilityService.
+     * </p>
+     * @param checked True if the node is checked.
+     *
+     * @throws IllegalStateException If called from an AccessibilityService.
+     */
+    public void setChecked(boolean checked) {
+        setBooleanProperty(PROPERTY_CHECKED, checked);
+    }
+
+    /**
+     * Gets whether this node is focusable.
+     *
+     * @return True if the node is focusable.
+     */
+    public boolean isFocusable() {
+        return getBooleanProperty(PROPERTY_FOCUSABLE);
+    }
+
+    /**
+     * Sets whether this node is focusable.
+     * <p>
+     *   Note: Cannot be called from an {@link android.accessibilityservice.AccessibilityService}.
+     *   This class is made immutable before being delivered to an AccessibilityService.
+     * </p>
+     * @param focusable True if the node is focusable.
+     *
+     * @throws IllegalStateException If called from an AccessibilityService.
+     */
+    public void setFocusable(boolean focusable) {
+        setBooleanProperty(PROPERTY_FOCUSABLE, focusable);
+    }
+
+    /**
+     * Gets whether this node is focused.
+     *
+     * @return True if the node is focused.
+     */
+    public boolean isFocused() {
+        return getBooleanProperty(PROPERTY_FOCUSED);
+    }
+
+    /**
+     * Sets whether this node is focused.
+     * <p>
+     *   Note: Cannot be called from an {@link android.accessibilityservice.AccessibilityService}.
+     *   This class is made immutable before being delivered to an AccessibilityService.
+     * </p>
+     * @param focused True if the node is focused.
+     *
+     * @throws IllegalStateException If called from an AccessibilityService.
+     */
+    public void setFocused(boolean focused) {
+        setBooleanProperty(PROPERTY_FOCUSED, focused);
+    }
+
+    /**
+     * Gets whether this node is selected.
+     *
+     * @return True if the node is selected.
+     */
+    public boolean isSelected() {
+        return getBooleanProperty(PROPERTY_SELECTED);
+    }
+
+    /**
+     * Sets whether this node is selected.
+     * <p>
+     *   Note: Cannot be called from an {@link android.accessibilityservice.AccessibilityService}.
+     *   This class is made immutable before being delivered to an AccessibilityService.
+     * </p>
+     * @param selected True if the node is selected.
+     *
+     * @throws IllegalStateException If called from an AccessibilityService.
+     */
+    public void setSelected(boolean selected) {
+        setBooleanProperty(PROPERTY_SELECTED, selected);
+    }
+
+    /**
+     * Gets whether this node is clickable.
+     *
+     * @return True if the node is clickable.
+     */
+    public boolean isClickable() {
+        return getBooleanProperty(PROPERTY_CLICKABLE);
+    }
+
+    /**
+     * Sets whether this node is clickable.
+     * <p>
+     *   Note: Cannot be called from an {@link android.accessibilityservice.AccessibilityService}.
+     *   This class is made immutable before being delivered to an AccessibilityService.
+     * </p>
+     * @param clickable True if the node is clickable.
+     *
+     * @throws IllegalStateException If called from an AccessibilityService.
+     */
+    public void setClickable(boolean clickable) {
+        setBooleanProperty(PROPERTY_CLICKABLE, clickable);
+    }
+
+    /**
+     * Gets whether this node is long clickable.
+     *
+     * @return True if the node is long clickable.
+     */
+    public boolean isLongClickable() {
+        return getBooleanProperty(PROPERTY_LONG_CLICKABLE);
+    }
+
+    /**
+     * Sets whether this node is long clickable.
+     * <p>
+     *   Note: Cannot be called from an {@link android.accessibilityservice.AccessibilityService}.
+     *   This class is made immutable before being delivered to an AccessibilityService.
+     * </p>
+     * @param longClickable True if the node is long clickable.
+     *
+     * @throws IllegalStateException If called from an AccessibilityService.
+     */
+    public void setLongClickable(boolean longClickable) {
+        setBooleanProperty(PROPERTY_LONG_CLICKABLE, longClickable);
+    }
+
+    /**
+     * Gets whether this node is enabled.
+     *
+     * @return True if the node is enabled.
+     */
+    public boolean isEnabled() {
+        return getBooleanProperty(PROPERTY_ENABLED);
+    }
+
+    /**
+     * Sets whether this node is enabled.
+     * <p>
+     *   Note: Cannot be called from an {@link android.accessibilityservice.AccessibilityService}.
+     *   This class is made immutable before being delivered to an AccessibilityService.
+     * </p>
+     * @param enabled True if the node is enabled.
+     *
+     * @throws IllegalStateException If called from an AccessibilityService.
+     */
+    public void setEnabled(boolean enabled) {
+        setBooleanProperty(PROPERTY_ENABLED, enabled);
+    }
+
+    /**
+     * Gets whether this node is a password.
+     *
+     * @return True if the node is a password.
+     */
+    public boolean isPassword() {
+        return getBooleanProperty(PROPERTY_PASSWORD);
+    }
+
+    /**
+     * Sets whether this node is a password.
+     * <p>
+     *   Note: Cannot be called from an {@link android.accessibilityservice.AccessibilityService}.
+     *   This class is made immutable before being delivered to an AccessibilityService.
+     * </p>
+     * @param password True if the node is a password.
+     *
+     * @throws IllegalStateException If called from an AccessibilityService.
+     */
+    public void setPassword(boolean password) {
+        setBooleanProperty(PROPERTY_PASSWORD, password);
+    }
+
+    /**
+     * Gets the package this node comes from.
+     *
+     * @return The package name.
+     */
+    public CharSequence getPackageName() {
+        return mPackageName;
+    }
+
+    /**
+     * Sets the package this node comes from.
+     * <p>
+     *   Note: Cannot be called from an {@link android.accessibilityservice.AccessibilityService}.
+     *   This class is made immutable before being delivered to an AccessibilityService.
+     * </p>
+     * @param packageName The package name.
+     *
+     * @throws IllegalStateException If called from an AccessibilityService.
+     */
+    public void setPackageName(CharSequence packageName) {
+        enforceNotSealed();
+        mPackageName = packageName;
+    }
+
+    /**
+     * Gets the class this node comes from.
+     *
+     * @return The class name.
+     */
+    public CharSequence getClassName() {
+        return mClassName;
+    }
+
+    /**
+     * Sets the class this node comes from.
+     * <p>
+     *   Note: Cannot be called from an {@link android.accessibilityservice.AccessibilityService}.
+     *   This class is made immutable before being delivered to an AccessibilityService.
+     * </p>
+     * @param className The class name.
+     *
+     * @throws IllegalStateException If called from an AccessibilityService.
+     */
+    public void setClassName(CharSequence className) {
+        enforceNotSealed();
+        mClassName = className;
+    }
+
+    /**
+     * Gets the text of this node.
+     *
+     * @return The text.
+     */
+    public CharSequence getText() {
+        return mText;
+    }
+
+    /**
+     * Sets the text of this node.
+     * <p>
+     *   Note: Cannot be called from an {@link android.accessibilityservice.AccessibilityService}.
+     *   This class is made immutable before being delivered to an AccessibilityService.
+     * </p>
+     * @param text The text.
+     *
+     * @throws IllegalStateException If called from an AccessibilityService.
+     */
+    public void setText(CharSequence text) {
+        enforceNotSealed();
+        mText = text;
+    }
+
+    /**
+     * Gets the content description of this node.
+     *
+     * @return The content description.
+     */
+    public CharSequence getContentDescription() {
+        return mContentDescription;
+    }
+
+    /**
+     * Sets the content description of this node.
+     * <p>
+     *   Note: Cannot be called from an {@link android.accessibilityservice.AccessibilityService}.
+     *   This class is made immutable before being delivered to an AccessibilityService.
+     * </p>
+     * @param contentDescription The content description.
+     *
+     * @throws IllegalStateException If called from an AccessibilityService.
+     */
+    public void setContentDescription(CharSequence contentDescription) {
+        enforceNotSealed();
+        mContentDescription = contentDescription;
+    }
+
+    /**
+     * Gets the value of a boolean property.
+     *
+     * @param property The property.
+     * @return The value.
+     */
+    private boolean getBooleanProperty(int property) {
+        return (mBooleanProperties & property) != 0;
+    }
+
+    /**
+     * Sets a boolean property.
+     *
+     * @param property The property.
+     * @param value The value.
+     *
+     * @throws IllegalStateException If called from an AccessibilityService.
+     */
+    private void setBooleanProperty(int property, boolean value) {
+        enforceNotSealed();
+        if (value) {
+            mBooleanProperties |= property;
+        } else {
+            mBooleanProperties &= ~property;
+        }
+    }
+
+    /**
+     * Sets the connection for interacting with the system.
+     *
+     * @param connection The client token.
+     *
+     * @hide
+     */
+    public final void setConnection(IAccessibilityServiceConnection connection) {
+        enforceNotSealed();
+        mConnection = connection;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int describeContents() {
+        return 0;
+    }
+
+    /**
+     * Sets if this instance is sealed.
+     *
+     * @param sealed Whether is sealed.
+     *
+     * @hide
+     */
+    public void setSealed(boolean sealed) {
+        mSealed = sealed;
+    }
+
+    /**
+     * Gets if this instance is sealed.
+     *
+     * @return Whether is sealed.
+     *
+     * @hide
+     */
+    public boolean isSealed() {
+        return mSealed;
+    }
+
+    /**
+     * Enforces that this instance is sealed.
+     *
+     * @throws IllegalStateException If this instance is not sealed.
+     *
+     * @hide
+     */
+    protected void enforceSealed() {
+        if (!isSealed()) {
+            throw new IllegalStateException("Cannot perform this "
+                    + "action on a not sealed instance.");
+        }
+    }
+
+    /**
+     * Enforces that this instance is not sealed.
+     *
+     * @throws IllegalStateException If this instance is sealed.
+     *
+     * @hide
+     */
+    protected void enforceNotSealed() {
+        if (isSealed()) {
+            throw new IllegalStateException("Cannot perform this "
+                    + "action on an sealed instance.");
+        }
+    }
+
+    /**
+     * Returns a cached instance if such is available otherwise a new one
+     * and sets the source.
+     *
+     * @return An instance.
+     *
+     * @see #setSource(View)
+     */
+    public static AccessibilityNodeInfo obtain(View source) {
+        AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain();
+        info.setSource(source);
+        return info;
+    }
+
+    /**
+     * Returns a cached instance if such is available otherwise a new one.
+     *
+     * @return An instance.
+     */
+    public static AccessibilityNodeInfo obtain() {
+        synchronized (sPoolLock) {
+            if (sPool != null) {
+                AccessibilityNodeInfo info = sPool;
+                sPool = sPool.mNext;
+                sPoolSize--;
+                info.mNext = null;
+                info.mIsInPool = false;
+                return info;
+            }
+            return new AccessibilityNodeInfo();
+        }
+    }
+
+    /**
+     * Return an instance back to be reused.
+     * <p>
+     * <b>Note: You must not touch the object after calling this function.</b>
+     *
+     * @throws IllegalStateException If the info is already recycled.
+     */
+    public void recycle() {
+        if (mIsInPool) {
+            throw new IllegalStateException("Info already recycled!");
+        }
+        clear();
+        synchronized (sPoolLock) {
+            if (sPoolSize <= MAX_POOL_SIZE) {
+                mNext = sPool;
+                sPool = this;
+                mIsInPool = true;
+                sPoolSize++;
+            }
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     * <p>
+     *   <b>Note: After the instance is written to a parcel it is recycled.
+     *      You must not touch the object after calling this function.</b>
+     * </p>
+     */
+    public void writeToParcel(Parcel parcel, int flags) {
+        if (mConnection == null) {
+            parcel.writeInt(0);
+        } else {
+            parcel.writeInt(1);
+            parcel.writeStrongBinder(mConnection.asBinder());
+        }
+        parcel.writeInt(isSealed() ? 1 : 0);
+        parcel.writeInt(mAccessibilityViewId);
+        parcel.writeInt(mAccessibilityWindowId);
+        parcel.writeInt(mParentAccessibilityViewId);
+
+        SparseIntArray childIds = mChildAccessibilityIds;
+        final int childIdsSize = childIds.size();
+        parcel.writeInt(childIdsSize);
+        for (int i = 0; i < childIdsSize; i++) {
+            parcel.writeInt(childIds.valueAt(i));
+        }
+
+        parcel.writeInt(mBoundsInParent.top);
+        parcel.writeInt(mBoundsInParent.bottom);
+        parcel.writeInt(mBoundsInParent.left);
+        parcel.writeInt(mBoundsInParent.right);
+
+        parcel.writeInt(mBoundsInScreen.top);
+        parcel.writeInt(mBoundsInScreen.bottom);
+        parcel.writeInt(mBoundsInScreen.left);
+        parcel.writeInt(mBoundsInScreen.right);
+
+        parcel.writeInt(mActions);
+
+        parcel.writeInt(mBooleanProperties);
+
+        TextUtils.writeToParcel(mPackageName, parcel, flags);
+        TextUtils.writeToParcel(mClassName, parcel, flags);
+        TextUtils.writeToParcel(mText, parcel, flags);
+        TextUtils.writeToParcel(mContentDescription, parcel, flags);
+
+        // Since instances of this class are fetched via synchronous i.e. blocking
+        // calls in IPCs and we always recycle as soon as the instance is marshaled.
+        recycle();
+    }
+
+    /**
+     * Creates a new instance from a {@link Parcel}.
+     *
+     * @param parcel A parcel containing the state of a {@link AccessibilityNodeInfo}.
+     */
+    private void initFromParcel(Parcel parcel) {
+        if (parcel.readInt() == 1) {
+            mConnection = IAccessibilityServiceConnection.Stub.asInterface(
+                    parcel.readStrongBinder());
+        }
+        mSealed = (parcel.readInt()  == 1);
+        mAccessibilityViewId = parcel.readInt();
+        mAccessibilityWindowId = parcel.readInt();
+        mParentAccessibilityViewId = parcel.readInt();
+
+        SparseIntArray childIds = mChildAccessibilityIds;
+        final int childrenSize = parcel.readInt();
+        for (int i = 0; i < childrenSize; i++) {
+            final int childId = parcel.readInt();
+            childIds.put(i, childId);
+        }
+
+        mBoundsInParent.top = parcel.readInt();
+        mBoundsInParent.bottom = parcel.readInt();
+        mBoundsInParent.left = parcel.readInt();
+        mBoundsInParent.right = parcel.readInt();
+
+        mBoundsInScreen.top = parcel.readInt();
+        mBoundsInScreen.bottom = parcel.readInt();
+        mBoundsInScreen.left = parcel.readInt();
+        mBoundsInScreen.right = parcel.readInt();
+
+        mActions = parcel.readInt();
+
+        mBooleanProperties = parcel.readInt();
+
+        mPackageName = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel);
+        mClassName = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel);
+        mText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel);
+        mContentDescription = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel);
+    }
+
+    /**
+     * Clears the state of this instance.
+     */
+    private void clear() {
+        mSealed = false;
+        mConnection = null;
+        mAccessibilityViewId = View.NO_ID;
+        mParentAccessibilityViewId = View.NO_ID;
+        mChildAccessibilityIds.clear();
+        mBoundsInParent.set(0, 0, 0, 0);
+        mBoundsInScreen.set(0, 0, 0, 0);
+        mBooleanProperties = 0;
+        mPackageName = null;
+        mClassName = null;
+        mText = null;
+        mContentDescription = null;
+        mActions = 0;
+    }
+
+    /**
+     * Gets the human readable action symbolic name.
+     *
+     * @param action The action.
+     * @return The symbolic name.
+     */
+    private static String getActionSymbolicName(int action) {
+        SparseArray<String> actionSymbolicNames = sActionSymbolicNames;
+        if (actionSymbolicNames == null) {
+            actionSymbolicNames = sActionSymbolicNames = new SparseArray<String>();
+            actionSymbolicNames.put(ACTION_FOCUS, "ACTION_FOCUS");
+            actionSymbolicNames.put(ACTION_CLEAR_FOCUS, "ACTION_UNFOCUS");
+            actionSymbolicNames.put(ACTION_SELECT, "ACTION_SELECT");
+            actionSymbolicNames.put(ACTION_CLEAR_SELECTION, "ACTION_UNSELECT");
+        }
+        return actionSymbolicNames.get(action);
+    }
+
+    private boolean canPerformRequestOverConnection(int accessibilityViewId) {
+        return (mAccessibilityWindowId != View.NO_ID
+                && accessibilityViewId != View.NO_ID
+                && mConnection != null);
+    }
+
+    @Override
+    public boolean equals(Object object) {
+        if (this == object) {
+            return true;
+        }
+        if (object == null) {
+            return false;
+        }
+        if (getClass() != object.getClass()) {
+            return false;
+        }
+        AccessibilityNodeInfo other = (AccessibilityNodeInfo) object;
+        if (mAccessibilityViewId != other.mAccessibilityViewId) {
+            return false;
+        }
+        if (mAccessibilityWindowId != other.mAccessibilityWindowId) {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + mAccessibilityViewId;
+        result = prime * result + mAccessibilityWindowId;
+        return result;
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder builder = new StringBuilder();
+        builder.append(super.toString());
+
+        if (DEBUG) {
+            builder.append("; accessibilityId: " + mAccessibilityViewId);
+            builder.append("; parentAccessibilityId: " + mParentAccessibilityViewId);
+            SparseIntArray childIds = mChildAccessibilityIds;
+            builder.append("; childAccessibilityIds: [");
+            for (int i = 0, count = childIds.size(); i < count; i++) {
+                builder.append(childIds.valueAt(i));
+                if (i < count - 1) {
+                    builder.append(", ");
+                }
+           }
+           builder.append("]");
+        }
+
+        builder.append("; boundsInParent: " + mBoundsInParent);
+        builder.append("; boundsInScreen: " + mBoundsInScreen);
+
+        builder.append("; packageName: ").append(mPackageName);
+        builder.append("; className: ").append(mClassName);
+        builder.append("; text: ").append(mText);
+        builder.append("; contentDescription: ").append(mContentDescription);
+
+        builder.append("; checkable: ").append(isCheckable());
+        builder.append("; checked: ").append(isChecked());
+        builder.append("; focusable: ").append(isFocusable());
+        builder.append("; focused: ").append(isFocused());
+        builder.append("; selected: ").append(isSelected());
+        builder.append("; clickable: ").append(isClickable());
+        builder.append("; longClickable: ").append(isLongClickable());
+        builder.append("; enabled: ").append(isEnabled());
+        builder.append("; password: ").append(isPassword());
+
+        builder.append("; [");
+
+        for (int actionBits = mActions; actionBits != 0;) {
+            final int action = 1 << Integer.numberOfTrailingZeros(actionBits);
+            actionBits &= ~action;
+            builder.append(getActionSymbolicName(action));
+            if (actionBits != 0) {
+                builder.append(", ");
+            }
+        }
+
+        builder.append("]");
+
+        return builder.toString();
+    }
+
+    /**
+     * @see Parcelable.Creator
+     */
+    public static final Parcelable.Creator<AccessibilityNodeInfo> CREATOR =
+            new Parcelable.Creator<AccessibilityNodeInfo>() {
+        public AccessibilityNodeInfo createFromParcel(Parcel parcel) {
+            AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain();
+            info.initFromParcel(parcel);
+            return info;
+        }
+
+        public AccessibilityNodeInfo[] newArray(int size) {
+            return new AccessibilityNodeInfo[size];
+        }
+    };
+}
diff --git a/core/java/android/view/accessibility/AccessibilityRecord.java b/core/java/android/view/accessibility/AccessibilityRecord.java
index 7819b17..9c495e21 100644
--- a/core/java/android/view/accessibility/AccessibilityRecord.java
+++ b/core/java/android/view/accessibility/AccessibilityRecord.java
@@ -16,7 +16,10 @@
 
 package android.view.accessibility;
 
+import android.accessibilityservice.IAccessibilityServiceConnection;
 import android.os.Parcelable;
+import android.os.RemoteException;
+import android.view.View;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -38,36 +41,127 @@
     private static final int PROPERTY_PASSWORD = 0x00000004;
     private static final int PROPERTY_FULL_SCREEN = 0x00000080;
 
+    // Housekeeping
     private static final int MAX_POOL_SIZE = 10;
     private static final Object sPoolLock = new Object();
     private static AccessibilityRecord sPool;
     private static int sPoolSize;
-
     private AccessibilityRecord mNext;
     private boolean mIsInPool;
 
-    protected int mBooleanProperties;
-    protected int mCurrentItemIndex;
-    protected int mItemCount;
-    protected int mFromIndex;
-    protected int mAddedCount;
-    protected int mRemovedCount;
+    boolean mSealed;
+    int mBooleanProperties;
+    int mCurrentItemIndex;
+    int mItemCount;
+    int mFromIndex;
+    int mAddedCount;
+    int mRemovedCount;
+    int mSourceViewId = View.NO_ID;
+    int mSourceWindowId = View.NO_ID;
 
-    protected CharSequence mClassName;
-    protected CharSequence mContentDescription;
-    protected CharSequence mBeforeText;
-    protected Parcelable mParcelableData;
+    CharSequence mClassName;
+    CharSequence mContentDescription;
+    CharSequence mBeforeText;
+    Parcelable mParcelableData;
 
-    protected final List<CharSequence> mText = new ArrayList<CharSequence>();
+    final List<CharSequence> mText = new ArrayList<CharSequence>();
+    IAccessibilityServiceConnection mConnection;
 
     /*
      * Hide constructor.
      */
-    protected AccessibilityRecord() {
+    AccessibilityRecord() {
 
     }
 
     /**
+     * Initialize this record from another one.
+     *
+     * @param record The to initialize from.
+     */
+    void init(AccessibilityRecord record) {
+        mSealed = record.mSealed;
+        mBooleanProperties = record.mBooleanProperties;
+        mCurrentItemIndex = record.mCurrentItemIndex;
+        mItemCount = record.mItemCount;
+        mFromIndex = record.mFromIndex;
+        mAddedCount = record.mAddedCount;
+        mRemovedCount = record.mRemovedCount;
+        mClassName = record.mClassName;
+        mContentDescription = record.mContentDescription;
+        mBeforeText = record.mBeforeText;
+        mParcelableData = record.mParcelableData;
+        mText.addAll(record.mText);
+        mSourceWindowId = record.mSourceWindowId;
+        mSourceViewId = record.mSourceViewId;
+        mConnection = record.mConnection;
+    }
+
+    /**
+     * Sets the event source.
+     *
+     * @param source The source.
+     *
+     * @throws IllegalStateException If called from an AccessibilityService.
+     */
+    public void setSource(View source) {
+        enforceNotSealed();
+        if (source != null) {
+            mSourceWindowId = source.getAccessibilityWindowId();
+            mSourceViewId = source.getAccessibilityViewId();
+        } else {
+            mSourceWindowId = View.NO_ID;
+            mSourceViewId = View.NO_ID;
+        }
+    }
+
+    /**
+     * Gets the {@link AccessibilityNodeInfo} of the event source.
+     * <p>
+     *   <strong>
+     *     It is a client responsibility to recycle the received info by
+     *     calling {@link AccessibilityNodeInfo#recycle()} to avoid creating
+     *     of multiple instances.
+     *   </strong>
+     * </p>
+     * @return The info.
+     */
+    public AccessibilityNodeInfo getSource() {
+        enforceSealed();
+        if (mSourceWindowId == View.NO_ID || mSourceViewId == View.NO_ID || mConnection == null) {
+            return null;
+        }
+        try {
+            return mConnection.findAccessibilityNodeInfoByAccessibilityId(mSourceWindowId,
+                    mSourceViewId);
+        } catch (RemoteException e) {
+           /* ignore */
+        }
+        return null;
+    }
+
+    /**
+     * Sets the connection for interacting with the AccessibilityManagerService.
+     *
+     * @param connection The connection.
+     *
+     * @hide
+     */
+    public void setConnection(IAccessibilityServiceConnection connection) {
+        enforceNotSealed();
+        mConnection = connection;
+    }
+
+    /**
+     * Gets the id of the window from which the event comes from.
+     *
+     * @return The window id.
+     */
+    public int getWindowId() {
+        return mSourceWindowId;
+    }
+
+    /**
      * Gets if the source is checked.
      *
      * @return True if the view is checked, false otherwise.
@@ -80,8 +174,11 @@
      * Sets if the source is checked.
      *
      * @param isChecked True if the view is checked, false otherwise.
+     *
+     * @throws IllegalStateException If called from an AccessibilityService.
      */
     public void setChecked(boolean isChecked) {
+        enforceNotSealed();
         setBooleanProperty(PROPERTY_CHECKED, isChecked);
     }
 
@@ -98,8 +195,11 @@
      * Sets if the source is enabled.
      *
      * @param isEnabled True if the view is enabled, false otherwise.
+     *
+     * @throws IllegalStateException If called from an AccessibilityService.
      */
     public void setEnabled(boolean isEnabled) {
+        enforceNotSealed();
         setBooleanProperty(PROPERTY_ENABLED, isEnabled);
     }
 
@@ -116,21 +216,15 @@
      * Sets if the source is a password field.
      *
      * @param isPassword True if the view is a password field, false otherwise.
+     *
+     * @throws IllegalStateException If called from an AccessibilityService.
      */
     public void setPassword(boolean isPassword) {
+        enforceNotSealed();
         setBooleanProperty(PROPERTY_PASSWORD, isPassword);
     }
 
     /**
-     * Sets if the source is taking the entire screen.
-     *
-     * @param isFullScreen True if the source is full screen, false otherwise.
-     */
-    public void setFullScreen(boolean isFullScreen) {
-        setBooleanProperty(PROPERTY_FULL_SCREEN, isFullScreen);
-    }
-
-    /**
      * Gets if the source is taking the entire screen.
      *
      * @return True if the source is full screen, false otherwise.
@@ -140,6 +234,18 @@
     }
 
     /**
+     * Sets if the source is taking the entire screen.
+     *
+     * @param isFullScreen True if the source is full screen, false otherwise.
+     *
+     * @throws IllegalStateException If called from an AccessibilityService.
+     */
+    public void setFullScreen(boolean isFullScreen) {
+        enforceNotSealed();
+        setBooleanProperty(PROPERTY_FULL_SCREEN, isFullScreen);
+    }
+
+    /**
      * Gets the number of items that can be visited.
      *
      * @return The number of items.
@@ -152,8 +258,11 @@
      * Sets the number of items that can be visited.
      *
      * @param itemCount The number of items.
+     *
+     * @throws IllegalStateException If called from an AccessibilityService.
      */
     public void setItemCount(int itemCount) {
+        enforceNotSealed();
         mItemCount = itemCount;
     }
 
@@ -170,8 +279,11 @@
      * Sets the index of the source in the list of items that can be visited.
      *
      * @param currentItemIndex The current item index.
+     *
+     * @throws IllegalStateException If called from an AccessibilityService.
      */
     public void setCurrentItemIndex(int currentItemIndex) {
+        enforceNotSealed();
         mCurrentItemIndex = currentItemIndex;
     }
 
@@ -188,8 +300,11 @@
      * Sets the index of the first character of the changed sequence.
      *
      * @param fromIndex The index of the first character.
+     *
+     * @throws IllegalStateException If called from an AccessibilityService.
      */
     public void setFromIndex(int fromIndex) {
+        enforceNotSealed();
         mFromIndex = fromIndex;
     }
 
@@ -206,8 +321,11 @@
      * Sets the number of added characters.
      *
      * @param addedCount The number of added characters.
+     *
+     * @throws IllegalStateException If called from an AccessibilityService.
      */
     public void setAddedCount(int addedCount) {
+        enforceNotSealed();
         mAddedCount = addedCount;
     }
 
@@ -224,8 +342,11 @@
      * Sets the number of removed characters.
      *
      * @param removedCount The number of removed characters.
+     *
+     * @throws IllegalStateException If called from an AccessibilityService.
      */
     public void setRemovedCount(int removedCount) {
+        enforceNotSealed();
         mRemovedCount = removedCount;
     }
 
@@ -242,8 +363,11 @@
      * Sets the class name of the source.
      *
      * @param className The lass name.
+     *
+     * @throws IllegalStateException If called from an AccessibilityService.
      */
     public void setClassName(CharSequence className) {
+        enforceNotSealed();
         mClassName = className;
     }
 
@@ -270,8 +394,11 @@
      * Sets the text before a change.
      *
      * @param beforeText The text before the change.
+     *
+     * @throws IllegalStateException If called from an AccessibilityService.
      */
     public void setBeforeText(CharSequence beforeText) {
+        enforceNotSealed();
         mBeforeText = beforeText;
     }
 
@@ -288,8 +415,11 @@
      * Sets the description of the source.
      *
      * @param contentDescription The description.
+     *
+     * @throws IllegalStateException If called from an AccessibilityService.
      */
     public void setContentDescription(CharSequence contentDescription) {
+        enforceNotSealed();
         mContentDescription = contentDescription;
     }
 
@@ -306,18 +436,65 @@
      * Sets the {@link Parcelable} data of the event.
      *
      * @param parcelableData The parcelable data.
+     *
+     * @throws IllegalStateException If called from an AccessibilityService.
      */
     public void setParcelableData(Parcelable parcelableData) {
+        enforceNotSealed();
         mParcelableData = parcelableData;
     }
 
     /**
+     * Sets if this instance is sealed.
+     *
+     * @param sealed Whether is sealed.
+     *
+     * @hide
+     */
+    public void setSealed(boolean sealed) {
+        mSealed = sealed;
+    }
+
+    /**
+     * Gets if this instance is sealed.
+     *
+     * @return Whether is sealed.
+     */
+    boolean isSealed() {
+        return mSealed;
+    }
+
+    /**
+     * Enforces that this instance is sealed.
+     *
+     * @throws IllegalStateException If this instance is not sealed.
+     */
+    void enforceSealed() {
+        if (!isSealed()) {
+            throw new IllegalStateException("Cannot perform this "
+                    + "action on a not sealed instance.");
+        }
+    }
+
+    /**
+     * Enforces that this instance is not sealed.
+     *
+     * @throws IllegalStateException If this instance is sealed.
+     */
+    void enforceNotSealed() {
+        if (isSealed()) {
+            throw new IllegalStateException("Cannot perform this "
+                    + "action on an sealed instance.");
+        }
+    }
+
+    /**
      * Gets the value of a boolean property.
      *
      * @param property The property.
      * @return The value.
      */
-    public boolean getBooleanProperty(int property) {
+    private boolean getBooleanProperty(int property) {
         return (mBooleanProperties & property) == property;
     }
 
@@ -337,6 +514,19 @@
 
     /**
      * Returns a cached instance if such is available or a new one is
+     * instantiated. The instance is initialized with data from the
+     * given record.
+     *
+     * @return An instance.
+     */
+    public static AccessibilityRecord obtain(AccessibilityRecord record) {
+       AccessibilityRecord clone = AccessibilityRecord.obtain();
+       clone.init(record);
+       return clone;
+    }
+
+    /**
+     * Returns a cached instance if such is available or a new one is
      * instantiated.
      *
      * @return An instance.
@@ -380,7 +570,8 @@
     /**
      * Clears the state of this instance.
      */
-    protected void clear() {
+    void clear() {
+        mSealed = false;
         mBooleanProperties = 0;
         mCurrentItemIndex = INVALID_POSITION;
         mItemCount = 0;
@@ -392,6 +583,8 @@
         mBeforeText = null;
         mParcelableData = null;
         mText.clear();
+        mSourceViewId = View.NO_ID;
+        mSourceWindowId = View.NO_ID;
     }
 
     @Override
diff --git a/core/java/android/view/accessibility/IAccessibilityInteractionConnection.aidl b/core/java/android/view/accessibility/IAccessibilityInteractionConnection.aidl
new file mode 100644
index 0000000..d35186b
--- /dev/null
+++ b/core/java/android/view/accessibility/IAccessibilityInteractionConnection.aidl
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.view.accessibility;
+
+import android.view.accessibility.AccessibilityNodeInfo;
+import android.view.accessibility.IAccessibilityInteractionConnectionCallback;
+
+/**
+ * Interface for interaction between the AccessibilityManagerService
+ * and the ViewRoot in a given window.
+ *
+ * @hide
+ */
+oneway interface IAccessibilityInteractionConnection {
+
+    void findAccessibilityNodeInfoByAccessibilityId(int accessibilityViewId, int interactionId,
+        IAccessibilityInteractionConnectionCallback callback);
+
+    void findAccessibilityNodeInfoByViewId(int id, int interactionId,
+        IAccessibilityInteractionConnectionCallback callback);
+
+    void findAccessibilityNodeInfosByViewText(String text, int accessibilityViewId,
+        int interactionId, IAccessibilityInteractionConnectionCallback callback);
+
+    void performAccessibilityAction(int accessibilityId, int action, int interactionId,
+        IAccessibilityInteractionConnectionCallback callback);
+}
diff --git a/core/java/android/view/accessibility/IAccessibilityInteractionConnectionCallback.aidl b/core/java/android/view/accessibility/IAccessibilityInteractionConnectionCallback.aidl
new file mode 100644
index 0000000..9c5e8dc
--- /dev/null
+++ b/core/java/android/view/accessibility/IAccessibilityInteractionConnectionCallback.aidl
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.view.accessibility;
+
+import android.view.accessibility.AccessibilityNodeInfo;
+import java.util.List;
+
+/**
+ * Callback for specifying the result for an asynchronous request made
+ * via calling a method on IAccessibilityInteractionConnectionCallback.
+ *
+ * @hide
+ */
+oneway interface IAccessibilityInteractionConnectionCallback {
+
+    void setFindAccessibilityNodeInfoResult(in AccessibilityNodeInfo info, int interactionId);
+
+    void setFindAccessibilityNodeInfosResult(in List<AccessibilityNodeInfo> infos,
+        int interactionId);
+
+    void setPerformAccessibilityActionResult(boolean succeeded, int interactionId);
+}
diff --git a/core/java/android/view/accessibility/IAccessibilityManager.aidl b/core/java/android/view/accessibility/IAccessibilityManager.aidl
index aaaae32..b14f02a 100644
--- a/core/java/android/view/accessibility/IAccessibilityManager.aidl
+++ b/core/java/android/view/accessibility/IAccessibilityManager.aidl
@@ -17,9 +17,14 @@
 
 package android.view.accessibility;
 
+import android.accessibilityservice.AccessibilityServiceInfo;
+import android.accessibilityservice.IAccessibilityServiceConnection;
+import android.accessibilityservice.IEventListener;
 import android.view.accessibility.AccessibilityEvent;
+import android.view.accessibility.AccessibilityNodeInfo;
+import android.view.accessibility.IAccessibilityInteractionConnection;
 import android.view.accessibility.IAccessibilityManagerClient;
-import android.content.pm.ServiceInfo;
+import android.view.IWindow;
 
 /**
  * Interface implemented by the AccessibilityManagerService called by
@@ -33,9 +38,16 @@
 
     boolean sendAccessibilityEvent(in AccessibilityEvent uiEvent);
 
-    List<ServiceInfo> getAccessibilityServiceList();
+    List<AccessibilityServiceInfo> getInstalledAccessibilityServiceList();
 
-    List<ServiceInfo> getEnabledAccessibilityServiceList(int feedbackType);
+    List<AccessibilityServiceInfo> getEnabledAccessibilityServiceList(int feedbackType);
 
     void interrupt();
+
+    int addAccessibilityInteractionConnection(IWindow windowToken,
+        in IAccessibilityInteractionConnection connection);
+
+    void removeAccessibilityInteractionConnection(IWindow windowToken);
+
+    IAccessibilityServiceConnection registerEventListener(IEventListener client);
 }
diff --git a/core/java/android/view/inputmethod/InputMethodInfo.java b/core/java/android/view/inputmethod/InputMethodInfo.java
index 1f7441d..4ec4ff9 100644
--- a/core/java/android/view/inputmethod/InputMethodInfo.java
+++ b/core/java/android/view/inputmethod/InputMethodInfo.java
@@ -23,9 +23,9 @@
 import android.content.Context;
 import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
 import android.content.pm.ResolveInfo;
 import android.content.pm.ServiceInfo;
-import android.content.pm.PackageManager.NameNotFoundException;
 import android.content.res.Resources;
 import android.content.res.TypedArray;
 import android.content.res.XmlResourceParser;
@@ -38,6 +38,8 @@
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
 
 /**
  * This class is used to specify meta information of an input method.
@@ -77,13 +79,28 @@
 
     /**
      * Constructor.
-     * 
+     *
      * @param context The Context in which we are parsing the input method.
      * @param service The ResolveInfo returned from the package manager about
      * this input method's component.
      */
     public InputMethodInfo(Context context, ResolveInfo service)
             throws XmlPullParserException, IOException {
+        this(context, service, null);
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param context The Context in which we are parsing the input method.
+     * @param service The ResolveInfo returned from the package manager about
+     * this input method's component.
+     * @param additionalSubtypes additional subtypes being added to this InputMethodInfo
+     * @hide
+     */
+    public InputMethodInfo(Context context, ResolveInfo service,
+            Map<String, List<InputMethodSubtype>> additionalSubtypesMap)
+            throws XmlPullParserException, IOException {
         mService = service;
         ServiceInfo si = service.serviceInfo;
         mId = new ComponentName(si.packageName, si.name).flattenToShortString();
@@ -145,7 +162,9 @@
                             a.getString(com.android.internal.R.styleable
                                     .InputMethod_Subtype_imeSubtypeMode),
                             a.getString(com.android.internal.R.styleable
-                                    .InputMethod_Subtype_imeSubtypeExtraValue));
+                                    .InputMethod_Subtype_imeSubtypeExtraValue),
+                            a.getBoolean(com.android.internal.R.styleable
+                                    .InputMethod_Subtype_isAuxiliary, false));
                     mSubtypes.add(subtype);
                 }
             }
@@ -155,6 +174,17 @@
         } finally {
             if (parser != null) parser.close();
         }
+
+        if (additionalSubtypesMap != null && additionalSubtypesMap.containsKey(mId)) {
+            final List<InputMethodSubtype> additionalSubtypes = additionalSubtypesMap.get(mId);
+            final int N = additionalSubtypes.size();
+            for (int i = 0; i < N; ++i) {
+                final InputMethodSubtype subtype = additionalSubtypes.get(i);
+                if (!mSubtypes.contains(subtype)) {
+                    mSubtypes.add(subtype);
+                }
+            }
+        }
         mSettingsActivityName = settingsActivityComponent;
         mIsDefaultResId = isDefaultResId;
     }
diff --git a/core/java/android/view/inputmethod/InputMethodManager.java b/core/java/android/view/inputmethod/InputMethodManager.java
index ea66d67..47f5e4c 100644
--- a/core/java/android/view/inputmethod/InputMethodManager.java
+++ b/core/java/android/view/inputmethod/InputMethodManager.java
@@ -1024,13 +1024,13 @@
                 if (DEBUG) Log.v(TAG, "START INPUT: " + view + " ic="
                         + ic + " tba=" + tba + " initial=" + initial);
                 InputBindResult res = mService.startInput(mClient,
-                        servedContext, tba, initial, mCurMethod == null);
+                        servedContext, tba, initial, true);
                 if (DEBUG) Log.v(TAG, "Starting input: Bind result=" + res);
                 if (res != null) {
                     if (res.id != null) {
                         mBindSequence = res.sequence;
                         mCurMethod = res.method;
-                    } else {
+                    } else if (mCurMethod == null) {
                         // This means there is no input method available.
                         if (DEBUG) Log.v(TAG, "ABORT input: no input method!");
                         return;
@@ -1558,6 +1558,24 @@
         }
     }
 
+    /**
+     * Set additional input method subtypes.
+     * @param imeToken Supplies the identifying token given to an input method.
+     * @param subtypes subtypes will be added as additional subtypes of the current input method.
+     * @return true if the additional input method subtypes are successfully added.
+     */
+    public boolean setAdditionalInputMethodSubtypes(
+            IBinder imeToken, InputMethodSubtype[] subtypes) {
+        synchronized (mH) {
+            try {
+                return mService.setAdditionalInputMethodSubtypes(imeToken, subtypes);
+            } catch (RemoteException e) {
+                Log.w(TAG, "IME died: " + mCurId, e);
+                return false;
+            }
+        }
+    }
+
     public InputMethodSubtype getLastInputMethodSubtype() {
         synchronized (mH) {
             try {
diff --git a/core/java/android/view/inputmethod/InputMethodSubtype.java b/core/java/android/view/inputmethod/InputMethodSubtype.java
index de38fbe..9d84c3e 100644
--- a/core/java/android/view/inputmethod/InputMethodSubtype.java
+++ b/core/java/android/view/inputmethod/InputMethodSubtype.java
@@ -17,8 +17,10 @@
 package android.view.inputmethod;
 
 import android.content.Context;
+import android.content.pm.ApplicationInfo;
 import android.os.Parcel;
 import android.os.Parcelable;
+import android.text.TextUtils;
 import android.util.Slog;
 
 import java.util.ArrayList;
@@ -26,6 +28,7 @@
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Locale;
 
 /**
  * This class is used to specify meta information of a subtype contained in an input method.
@@ -52,10 +55,11 @@
      * @param nameId The name of the subtype
      * @param iconId The icon of the subtype
      * @param locale The locale supported by the subtype
-     * @param modeId The mode supported by the subtype
+     * @param mode The mode supported by the subtype
      * @param extraValue The extra value of the subtype
      */
-    InputMethodSubtype(int nameId, int iconId, String locale, String mode, String extraValue) {
+    public InputMethodSubtype(
+            int nameId, int iconId, String locale, String mode, String extraValue) {
         this(nameId, iconId, locale, mode, extraValue, false);
     }
 
@@ -64,19 +68,20 @@
      * @param nameId The name of the subtype
      * @param iconId The icon of the subtype
      * @param locale The locale supported by the subtype
-     * @param modeId The mode supported by the subtype
+     * @param mode The mode supported by the subtype
      * @param extraValue The extra value of the subtype
      * @param isAuxiliary true when this subtype is one shot subtype.
      */
-    InputMethodSubtype(int nameId, int iconId, String locale, String mode, String extraValue,
+    public InputMethodSubtype(int nameId, int iconId, String locale, String mode, String extraValue,
             boolean isAuxiliary) {
         mSubtypeNameResId = nameId;
         mSubtypeIconResId = iconId;
         mSubtypeLocale = locale != null ? locale : "";
         mSubtypeMode = mode != null ? mode : "";
         mSubtypeExtraValue = extraValue != null ? extraValue : "";
-        mSubtypeHashCode = hashCodeInternal(mSubtypeLocale, mSubtypeMode, mSubtypeExtraValue);
         mIsAuxiliary = isAuxiliary;
+        mSubtypeHashCode = hashCodeInternal(mSubtypeLocale, mSubtypeMode, mSubtypeExtraValue,
+                mIsAuxiliary);
     }
 
     InputMethodSubtype(Parcel source) {
@@ -89,8 +94,9 @@
         mSubtypeMode = s != null ? s : "";
         s = source.readString();
         mSubtypeExtraValue = s != null ? s : "";
-        mSubtypeHashCode = hashCodeInternal(mSubtypeLocale, mSubtypeMode, mSubtypeExtraValue);
         mIsAuxiliary = (source.readInt() == 1);
+        mSubtypeHashCode = hashCodeInternal(mSubtypeLocale, mSubtypeMode, mSubtypeExtraValue,
+                mIsAuxiliary);
     }
 
     /**
@@ -137,6 +143,32 @@
         return mIsAuxiliary;
     }
 
+    /**
+     * @param context Context will be used for getting Locale and PackageManager.
+     * @param packageName The package name of the IME
+     * @param appInfo The application info of the IME
+     * @return a display name for this subtype. The string resource of the label (mSubtypeNameResId)
+     * can have only one %s in it. If there is, the %s part will be replaced with the locale's
+     * display name by the formatter. If there is not, this method simply returns the string
+     * specified by mSubtypeNameResId. If mSubtypeNameResId is not specified (== 0), it's up to the
+     * framework to generate an appropriate display name.
+     */
+    public CharSequence getDisplayName(
+            Context context, String packageName, ApplicationInfo appInfo) {
+        final Locale locale = constructLocaleFromString(mSubtypeLocale);
+        final String localeStr = locale != null ? locale.getDisplayName() : mSubtypeLocale;
+        if (mSubtypeNameResId == 0) {
+            return localeStr;
+        }
+        final String subtypeName = context.getPackageManager().getText(
+                packageName, mSubtypeNameResId, appInfo).toString();
+        if (!TextUtils.isEmpty(subtypeName)) {
+            return String.format(subtypeName, localeStr);
+        } else {
+            return localeStr;
+        }
+    }
+
     private HashMap<String, String> getExtraValueHashMap() {
         if (mExtraValueHashMapCache == null) {
             mExtraValueHashMapCache = new HashMap<String, String>();
@@ -191,7 +223,8 @@
                 && (subtype.getMode().equals(getMode()))
                 && (subtype.getIconResId() == getIconResId())
                 && (subtype.getLocale().equals(getLocale()))
-                && (subtype.getExtraValue().equals(getExtraValue()));
+                && (subtype.getExtraValue().equals(getExtraValue()))
+                && (subtype.isAuxiliary() == isAuxiliary());
         }
         return false;
     }
@@ -224,8 +257,25 @@
         }
     };
 
-    private static int hashCodeInternal(String locale, String mode, String extraValue) {
-        return Arrays.hashCode(new Object[] {locale, mode, extraValue});
+    private static Locale constructLocaleFromString(String localeStr) {
+        if (TextUtils.isEmpty(localeStr))
+            return null;
+        String[] localeParams = localeStr.split("_", 3);
+        // The length of localeStr is guaranteed to always return a 1 <= value <= 3
+        // because localeStr is not empty.
+        if (localeParams.length == 1) {
+            return new Locale(localeParams[0]);
+        } else if (localeParams.length == 2) {
+            return new Locale(localeParams[0], localeParams[1]);
+        } else if (localeParams.length == 3) {
+            return new Locale(localeParams[0], localeParams[1], localeParams[2]);
+        }
+        return null;
+    }
+
+    private static int hashCodeInternal(String locale, String mode, String extraValue,
+            boolean isAuxiliary) {
+        return Arrays.hashCode(new Object[] {locale, mode, extraValue, isAuxiliary});
     }
 
     /**
diff --git a/core/java/android/webkit/BrowserFrame.java b/core/java/android/webkit/BrowserFrame.java
index 9f2fd12..2f4774f 100644
--- a/core/java/android/webkit/BrowserFrame.java
+++ b/core/java/android/webkit/BrowserFrame.java
@@ -44,6 +44,9 @@
 import java.io.InputStream;
 import java.lang.ref.WeakReference;
 import java.net.URLEncoder;
+import java.nio.charset.Charsets;
+import java.security.PrivateKey;
+import java.security.cert.CertificateEncodingException;
 import java.security.cert.X509Certificate;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -1141,7 +1144,7 @@
     }
 
     /**
-     * Called by JNI when the native HTTP(S) stack gets an invalid cert chain.
+     * Called by JNI when the native HTTPS stack gets an invalid cert chain.
      *
      * We delegate the request to CallbackProxy, and route its response to
      * {@link #nativeSslCertErrorProceed(int)} or
@@ -1182,6 +1185,32 @@
     }
 
     /**
+     * Called by JNI when the native HTTPS stack gets a client
+     * certificate request.
+     *
+     * We delegate the request to CallbackProxy, and route its response to
+     * {@link #nativeSslClientCert(int, X509Certificate)}.
+     */
+    private void requestClientCert(int handle, byte[] host_and_port_bytes) {
+        String host_and_port = new String(host_and_port_bytes, Charsets.UTF_8);
+        SslClientCertLookupTable table = SslClientCertLookupTable.getInstance();
+        if (table.IsAllowed(host_and_port)) {
+            // previously allowed
+            nativeSslClientCert(handle,
+                                table.PrivateKey(host_and_port),
+                                table.CertificateChain(host_and_port));
+        } else if (table.IsDenied(host_and_port)) {
+            // previously denied
+            nativeSslClientCert(handle, null, null);
+        } else {
+            // previously ignored or new
+            mCallbackProxy.onReceivedClientCertRequest(
+                    new ClientCertRequestHandler(this, handle, host_and_port, table),
+                    host_and_port);
+        }
+    }
+
+    /**
      * Called by JNI when the native HTTP stack needs to download a file.
      *
      * We delegate the request to CallbackProxy, which owns the current app's
@@ -1366,4 +1395,8 @@
 
     private native void nativeSslCertErrorProceed(int handle);
     private native void nativeSslCertErrorCancel(int handle, int cert_error);
+
+    native void nativeSslClientCert(int handle,
+                                    byte[] pkcs8EncodedPrivateKey,
+                                    byte[][] asn1DerEncodedCertificateChain);
 }
diff --git a/core/java/android/webkit/CallbackProxy.java b/core/java/android/webkit/CallbackProxy.java
index 23fd12d..f7d55f6 100644
--- a/core/java/android/webkit/CallbackProxy.java
+++ b/core/java/android/webkit/CallbackProxy.java
@@ -118,6 +118,7 @@
     private static final int SET_INSTALLABLE_WEBAPP              = 138;
     private static final int NOTIFY_SEARCHBOX_LISTENERS          = 139;
     private static final int AUTO_LOGIN                          = 140;
+    private static final int CLIENT_CERT_REQUEST                 = 141;
 
     // Message triggered by the client to resume execution
     private static final int NOTIFY                              = 200;
@@ -273,7 +274,7 @@
                     mWebViewClient.onPageFinished(mWebView, finishedUrl);
                 }
                 break;
-                
+
             case RECEIVED_ICON:
                 if (mWebChromeClient != null) {
                     mWebChromeClient.onReceivedIcon(mWebView, (Bitmap) msg.obj);
@@ -340,7 +341,7 @@
 
             case SSL_ERROR:
                 if (mWebViewClient != null) {
-                    HashMap<String, Object> map = 
+                    HashMap<String, Object> map =
                         (HashMap<String, Object>) msg.obj;
                     mWebViewClient.onReceivedSslError(mWebView,
                             (SslErrorHandler) map.get("handler"),
@@ -348,6 +349,16 @@
                 }
                 break;
 
+            case CLIENT_CERT_REQUEST:
+                if (mWebViewClient != null) {
+                    HashMap<String, Object> map =
+                        (HashMap<String, Object>) msg.obj;
+                    mWebViewClient.onReceivedClientCertRequest(mWebView,
+                            (ClientCertRequestHandler) map.get("handler"),
+                            (String) map.get("host_and_port"));
+                }
+                break;
+
             case PROGRESS:
                 // Synchronize to ensure mLatestProgress is not modified after
                 // setProgress is called and before mProgressUpdatePending is
@@ -543,14 +554,14 @@
                         new AlertDialog.Builder(mContext)
                                 .setTitle(getJsDialogTitle(url))
                                 .setMessage(message)
-                                .setPositiveButton(R.string.ok, 
+                                .setPositiveButton(R.string.ok,
                                         new DialogInterface.OnClickListener() {
                                             public void onClick(
                                                     DialogInterface dialog,
                                                     int which) {
                                                 res.confirm();
                                             }})
-                                .setNegativeButton(R.string.cancel, 
+                                .setNegativeButton(R.string.cancel,
                                         new DialogInterface.OnClickListener() {
                                             public void onClick(
                                                     DialogInterface dialog,
@@ -904,7 +915,7 @@
         if (PERF_PROBE) {
             // un-comment this if PERF_PROBE is true
 //            Looper.myQueue().setWaitCallback(null);
-            Log.d("WebCore", "WebCore thread used " + 
+            Log.d("WebCore", "WebCore thread used " +
                     (SystemClock.currentThreadTimeMillis() - mWebCoreThreadTime)
                     + " ms and idled " + mWebCoreIdleTime + " ms");
             Network.getInstance(mContext).stopTiming();
@@ -934,7 +945,7 @@
         sendMessage(msg);
     }
 
-    public void onFormResubmission(Message dontResend, 
+    public void onFormResubmission(Message dontResend,
             Message resend) {
         // Do an unsynchronized quick check to avoid posting if no callback has
         // been set.
@@ -998,7 +1009,6 @@
             return;
         }
         Message msg = obtainMessage(SSL_ERROR);
-        //, handler);
         HashMap<String, Object> map = new HashMap();
         map.put("handler", handler);
         map.put("error", error);
@@ -1006,6 +1016,23 @@
         sendMessage(msg);
     }
     /**
+     * @hide
+     */
+    public void onReceivedClientCertRequest(ClientCertRequestHandler handler, String host_and_port) {
+        // Do an unsynchronized quick check to avoid posting if no callback has
+        // been set.
+        if (mWebViewClient == null) {
+            handler.cancel();
+            return;
+        }
+        Message msg = obtainMessage(CLIENT_CERT_REQUEST);
+        HashMap<String, Object> map = new HashMap();
+        map.put("handler", handler);
+        map.put("host_and_port", host_and_port);
+        msg.obj = map;
+        sendMessage(msg);
+    }
+    /**
      * @hide - hide this because it contains a parameter of type SslCertificate,
      * which is located in a hidden package.
      */
diff --git a/core/java/android/webkit/ClientCertRequestHandler.java b/core/java/android/webkit/ClientCertRequestHandler.java
new file mode 100644
index 0000000..3a71e7e
--- /dev/null
+++ b/core/java/android/webkit/ClientCertRequestHandler.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.webkit;
+
+import java.security.PrivateKey;
+import java.security.cert.CertificateEncodingException;
+import java.security.cert.X509Certificate;
+import org.apache.harmony.xnet.provider.jsse.NativeCrypto;
+
+/**
+ * ClientCertRequestHandler: class responsible for handling client
+ * certificate requests.  This class is passed as a parameter to
+ * BrowserCallback.displayClientCertRequestDialog and is meant to
+ * receive the user's response.
+ *
+ * @hide
+ */
+public final class ClientCertRequestHandler {
+
+    private final BrowserFrame mBrowserFrame;
+    private final int mHandle;
+    private final String mHostAndPort;
+    private final SslClientCertLookupTable mTable;
+    ClientCertRequestHandler(BrowserFrame browserFrame,
+                             int handle,
+                             String host_and_port,
+                             SslClientCertLookupTable table) {
+        mBrowserFrame = browserFrame;
+        mHandle = handle;
+        mHostAndPort = host_and_port;
+        mTable = table;
+    }
+
+    /**
+     * Proceed with the specified private key and client certificate chain.
+     */
+    public void proceed(PrivateKey privateKey, X509Certificate[] chain) {
+        byte[] privateKeyBytes = privateKey.getEncoded();
+        byte[][] chainBytes;
+        try {
+            chainBytes = NativeCrypto.encodeCertificates(chain);
+        } catch (CertificateEncodingException e) {
+            mBrowserFrame.nativeSslClientCert(mHandle, null, null);
+            return;
+        }
+        mTable.Allow(mHostAndPort, privateKeyBytes, chainBytes);
+        mBrowserFrame.nativeSslClientCert(mHandle, privateKeyBytes, chainBytes);
+    }
+
+    /**
+     * Igore the request for now, the user may be prompted again.
+     */
+    public void ignore() {
+        mBrowserFrame.nativeSslClientCert(mHandle, null, null);
+    }
+
+    /**
+     * Cancel this request, remember the users negative choice.
+     */
+    public void cancel() {
+        mTable.Deny(mHostAndPort);
+        mBrowserFrame.nativeSslClientCert(mHandle, null, null);
+    }
+}
diff --git a/core/java/android/webkit/HTML5VideoFullScreen.java b/core/java/android/webkit/HTML5VideoFullScreen.java
index 1004b5f..4cae9d8 100644
--- a/core/java/android/webkit/HTML5VideoFullScreen.java
+++ b/core/java/android/webkit/HTML5VideoFullScreen.java
@@ -199,6 +199,9 @@
         mVideoSurfaceView.getHolder().setFixedSize(mVideoWidth, mVideoHeight);
     }
 
+    public boolean fullScreenExited() {
+        return (mLayout == null);
+    }
 
     private final WebChromeClient.CustomViewCallback mCallback =
         new WebChromeClient.CustomViewCallback() {
@@ -250,18 +253,19 @@
         mLayout.setVisibility(View.VISIBLE);
 
         WebChromeClient client = webView.getWebChromeClient();
-        client.onShowCustomView(mLayout, mCallback);
-        // Plugins like Flash will draw over the video so hide
-        // them while we're playing.
-        if (webView.getViewManager() != null)
-            webView.getViewManager().hideAll();
+        if (client != null) {
+            client.onShowCustomView(mLayout, mCallback);
+            // Plugins like Flash will draw over the video so hide
+            // them while we're playing.
+            if (webView.getViewManager() != null)
+                webView.getViewManager().hideAll();
 
-        mProgressView = client.getVideoLoadingProgressView();
-        if (mProgressView != null) {
-            mLayout.addView(mProgressView, layoutParams);
-            mProgressView.setVisibility(View.VISIBLE);
+            mProgressView = client.getVideoLoadingProgressView();
+            if (mProgressView != null) {
+                mLayout.addView(mProgressView, layoutParams);
+                mProgressView.setVisibility(View.VISIBLE);
+            }
         }
-
     }
 
     /**
@@ -315,10 +319,12 @@
 
     @Override
     protected void switchProgressView(boolean playerBuffering) {
-        if (playerBuffering) {
-            mProgressView.setVisibility(View.VISIBLE);
-        } else {
-            mProgressView.setVisibility(View.GONE);
+        if (mProgressView != null) {
+            if (playerBuffering) {
+                mProgressView.setVisibility(View.VISIBLE);
+            } else {
+                mProgressView.setVisibility(View.GONE);
+            }
         }
         return;
     }
diff --git a/core/java/android/webkit/HTML5VideoInline.java b/core/java/android/webkit/HTML5VideoInline.java
index 25921bc..ef1906c 100644
--- a/core/java/android/webkit/HTML5VideoInline.java
+++ b/core/java/android/webkit/HTML5VideoInline.java
@@ -12,10 +12,15 @@
  */
 public class HTML5VideoInline extends HTML5VideoView{
 
-    // Due to the fact that SurfaceTexture consume a lot of memory, we make it
-    // as static. m_textureNames is the texture bound with this SurfaceTexture.
+    // Due to the fact that the decoder consume a lot of memory, we make the
+    // surface texture as singleton. But the GL texture (m_textureNames)
+    // associated with the surface texture can be used for showing the screen
+    // shot when paused, so they are not singleton.
     private static SurfaceTexture mSurfaceTexture = null;
-    private static int[] mTextureNames;
+    private int[] mTextureNames;
+    // Every time when the VideoLayer Id change, we need to recreate the
+    // SurfaceTexture in order to delete the old video's decoder memory.
+    private static int mVideoLayerUsingSurfaceTexture = -1;
 
     // Video control FUNCTIONS:
     @Override
@@ -28,11 +33,12 @@
     HTML5VideoInline(int videoLayerId, int position,
             boolean autoStart) {
         init(videoLayerId, position, autoStart);
+        mTextureNames = null;
     }
 
     @Override
     public void decideDisplayMode() {
-        mPlayer.setTexture(getSurfaceTextureInstance());
+        mPlayer.setTexture(getSurfaceTexture(getVideoLayerId()));
     }
 
     // Normally called immediately after setVideoURI. But for full screen,
@@ -52,31 +58,38 @@
     // Inline Video specific FUNCTIONS:
 
     @Override
-    public SurfaceTexture getSurfaceTexture() {
+    public SurfaceTexture getSurfaceTexture(int videoLayerId) {
+        // Create the surface texture.
+        if (videoLayerId != mVideoLayerUsingSurfaceTexture
+            || mSurfaceTexture == null) {
+            if (mTextureNames == null) {
+                mTextureNames = new int[1];
+                GLES20.glGenTextures(1, mTextureNames, 0);
+            }
+            mSurfaceTexture = new SurfaceTexture(mTextureNames[0]);
+        }
+        mVideoLayerUsingSurfaceTexture = videoLayerId;
         return mSurfaceTexture;
     }
 
+    public boolean surfaceTextureDeleted() {
+        return (mSurfaceTexture == null);
+    }
+
     @Override
     public void deleteSurfaceTexture() {
         mSurfaceTexture = null;
+        mVideoLayerUsingSurfaceTexture = -1;
         return;
     }
 
-    // SurfaceTexture is a singleton here , too
-    private SurfaceTexture getSurfaceTextureInstance() {
-        // Create the surface texture.
-        if (mSurfaceTexture == null)
-        {
-            mTextureNames = new int[1];
-            GLES20.glGenTextures(1, mTextureNames, 0);
-            mSurfaceTexture = new SurfaceTexture(mTextureNames[0]);
-        }
-        return mSurfaceTexture;
-    }
-
     @Override
     public int getTextureName() {
-        return mTextureNames[0];
+        if (mTextureNames != null) {
+            return mTextureNames[0];
+        } else {
+            return 0;
+        }
     }
 
     private void setFrameAvailableListener(SurfaceTexture.OnFrameAvailableListener l) {
diff --git a/core/java/android/webkit/HTML5VideoView.java b/core/java/android/webkit/HTML5VideoView.java
index c05498a..5983a44 100644
--- a/core/java/android/webkit/HTML5VideoView.java
+++ b/core/java/android/webkit/HTML5VideoView.java
@@ -287,7 +287,7 @@
         return false;
     }
 
-    public SurfaceTexture getSurfaceTexture() {
+    public SurfaceTexture getSurfaceTexture(int videoLayerId) {
         return null;
     }
 
@@ -315,4 +315,14 @@
         // Only used in HTML5VideoFullScreen
     }
 
+    public boolean surfaceTextureDeleted() {
+        // Only meaningful for HTML5VideoInline
+        return false;
+    }
+
+    public boolean fullScreenExited() {
+        // Only meaningful for HTML5VideoFullScreen
+        return false;
+    }
+
 }
diff --git a/core/java/android/webkit/HTML5VideoViewProxy.java b/core/java/android/webkit/HTML5VideoViewProxy.java
index 7d8669b..d0237b5 100644
--- a/core/java/android/webkit/HTML5VideoViewProxy.java
+++ b/core/java/android/webkit/HTML5VideoViewProxy.java
@@ -106,12 +106,14 @@
         public static void setBaseLayer(int layer) {
             // Don't do this for full screen mode.
             if (mHTML5VideoView != null
-                    && !mHTML5VideoView.isFullScreenMode()) {
+                && !mHTML5VideoView.isFullScreenMode()
+                && !mHTML5VideoView.surfaceTextureDeleted()) {
                 mBaseLayer = layer;
-                SurfaceTexture surfTexture = mHTML5VideoView.getSurfaceTexture();
-                int textureName = mHTML5VideoView.getTextureName();
 
                 int currentVideoLayerId = mHTML5VideoView.getVideoLayerId();
+                SurfaceTexture surfTexture = mHTML5VideoView.getSurfaceTexture(currentVideoLayerId);
+                int textureName = mHTML5VideoView.getTextureName();
+
                 if (layer != 0 && surfTexture != null && currentVideoLayerId != -1) {
                     int playerState = mHTML5VideoView.getCurrentState();
                     if (mHTML5VideoView.getPlayerBuffering())
@@ -171,14 +173,12 @@
             boolean backFromFullScreenMode = false;
             if (mHTML5VideoView != null) {
                 currentVideoLayerId = mHTML5VideoView.getVideoLayerId();
-                if (mHTML5VideoView instanceof HTML5VideoFullScreen) {
-                    backFromFullScreenMode = true;
-                }
+                backFromFullScreenMode = mHTML5VideoView.fullScreenExited();
             }
 
             if (backFromFullScreenMode
-                ||  currentVideoLayerId != videoLayerId
-                || mHTML5VideoView.getSurfaceTexture() == null) {
+                || currentVideoLayerId != videoLayerId
+                || mHTML5VideoView.surfaceTextureDeleted()) {
                 // Here, we handle the case when switching to a new video,
                 // either inside a WebView or across WebViews
                 // For switching videos within a WebView or across the WebView,
diff --git a/core/java/android/webkit/PluginFullScreenHolder.java b/core/java/android/webkit/PluginFullScreenHolder.java
index ae326d5..42ba7c9 100644
--- a/core/java/android/webkit/PluginFullScreenHolder.java
+++ b/core/java/android/webkit/PluginFullScreenHolder.java
@@ -24,34 +24,44 @@
  */
 package android.webkit;
 
-import android.app.Dialog;
+import android.content.Context;
+import android.view.Gravity;
 import android.view.KeyEvent;
 import android.view.MotionEvent;
 import android.view.SurfaceView;
 import android.view.View;
 import android.view.ViewGroup;
+import android.widget.FrameLayout;
 
-class PluginFullScreenHolder extends Dialog {
+class PluginFullScreenHolder {
 
     private final WebView mWebView;
     private final int mNpp;
+    private final int mOrientation;
+
+    // The container for the plugin view
+    private static CustomFrameLayout mLayout;
+
     private View mContentView;
 
-    PluginFullScreenHolder(WebView webView, int npp) {
-        super(webView.getContext(), android.R.style.Theme_NoTitleBar_Fullscreen);
+    PluginFullScreenHolder(WebView webView, int orientation, int npp) {
         mWebView = webView;
         mNpp = npp;
+        mOrientation = orientation;
     }
 
-    @Override
     public void setContentView(View contentView) {
-        // as we are sharing the View between full screen and
-        // embedded mode, we have to remove the
-        // AbsoluteLayout.LayoutParams set by embedded mode to
-        // ViewGroup.LayoutParams before adding it to the dialog
-        contentView.setLayoutParams(new ViewGroup.LayoutParams(
-                ViewGroup.LayoutParams.MATCH_PARENT,
-                ViewGroup.LayoutParams.MATCH_PARENT));
+
+        // Create a FrameLayout that will contain the plugin's view
+        mLayout = new CustomFrameLayout(mWebView.getContext());
+        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
+                            ViewGroup.LayoutParams.MATCH_PARENT,
+                            ViewGroup.LayoutParams.MATCH_PARENT,
+                            Gravity.CENTER);
+
+        mLayout.addView(contentView, layoutParams);
+        mLayout.setVisibility(View.VISIBLE);
+
         // fixed size is only used either during pinch zoom or surface is too
         // big. Make sure it is not fixed size before setting it to the full
         // screen content view. The SurfaceView will be set to the correct mode
@@ -62,59 +72,79 @@
                 sView.getHolder().setSizeFromLayout();
             }
         }
-        super.setContentView(contentView);
+
         mContentView = contentView;
     }
 
-    @Override
-    public void onBackPressed() {
-        mWebView.mPrivateHandler.obtainMessage(WebView.HIDE_FULLSCREEN)
-                .sendToTarget();
+    public void show() {
+        // Other plugins may attempt to draw so hide them while we're active.
+        if (mWebView.getViewManager() != null)
+            mWebView.getViewManager().hideAll();
+
+        WebChromeClient client = mWebView.getWebChromeClient();
+        client.onShowCustomView(mLayout, mOrientation, mCallback);
     }
 
-    @Override
-    public boolean onKeyDown(int keyCode, KeyEvent event) {
-        if (event.isSystem()) {
-            return super.onKeyDown(keyCode, event);
+    public void hide() {
+        WebChromeClient client = mWebView.getWebChromeClient();
+        client.onHideCustomView();
+    }
+
+    private class CustomFrameLayout extends FrameLayout {
+
+        CustomFrameLayout(Context context) {
+            super(context);
         }
-        mWebView.onKeyDown(keyCode, event);
-        // always return true as we are the handler
-        return true;
-    }
 
-    @Override
-    public boolean onKeyUp(int keyCode, KeyEvent event) {
-        if (event.isSystem()) {
-            return super.onKeyUp(keyCode, event);
+        @Override
+        public boolean onKeyDown(int keyCode, KeyEvent event) {
+            if (event.isSystem()) {
+                return super.onKeyDown(keyCode, event);
+            }
+            mWebView.onKeyDown(keyCode, event);
+            // always return true as we are the handler
+            return true;
         }
-        mWebView.onKeyUp(keyCode, event);
-        // always return true as we are the handler
-        return true;
-    }
 
-    @Override
-    public boolean onTouchEvent(MotionEvent event) {
-        // always return true as we don't want the event to propagate any further
-        return true;
-    }
-
-    @Override
-    public boolean onTrackballEvent(MotionEvent event) {
-        mWebView.onTrackballEvent(event);
-        // always return true as we are the handler
-        return true;
-    }
-
-    @Override
-    protected void onStop() {
-        super.onStop();
-        // manually remove the contentView's parent since the dialog does not
-        if (mContentView != null && mContentView.getParent() != null) {
-            ViewGroup vg = (ViewGroup) mContentView.getParent();
-            vg.removeView(mContentView);
+        @Override
+        public boolean onKeyUp(int keyCode, KeyEvent event) {
+            if (event.isSystem()) {
+                return super.onKeyUp(keyCode, event);
+            }
+            mWebView.onKeyUp(keyCode, event);
+            // always return true as we are the handler
+            return true;
         }
-        mWebView.getWebViewCore().sendMessage(
-                WebViewCore.EventHub.HIDE_FULLSCREEN, mNpp, 0);
-    }
 
+        @Override
+        public boolean onTouchEvent(MotionEvent event) {
+            // always return true as we don't want the event to propagate any further
+            return true;
+        }
+
+        @Override
+        public boolean onTrackballEvent(MotionEvent event) {
+            mWebView.onTrackballEvent(event);
+            // always return true as we are the handler
+            return true;
+        }
+    }
+    
+    private final WebChromeClient.CustomViewCallback mCallback =
+        new WebChromeClient.CustomViewCallback() {
+            public void onCustomViewHidden() {
+
+                mWebView.mPrivateHandler.obtainMessage(WebView.HIDE_FULLSCREEN)
+                    .sendToTarget();
+
+                mWebView.getWebViewCore().sendMessage(
+                        WebViewCore.EventHub.HIDE_FULLSCREEN, mNpp, 0);
+
+                mLayout.removeView(mContentView);
+                mLayout = null;
+
+                // Re enable plugin views.
+                mWebView.getViewManager().showAll();
+            }
+        };
 }
diff --git a/core/java/android/webkit/SslCertLookupTable.java b/core/java/android/webkit/SslCertLookupTable.java
index abf612e..faff110 100644
--- a/core/java/android/webkit/SslCertLookupTable.java
+++ b/core/java/android/webkit/SslCertLookupTable.java
@@ -19,11 +19,11 @@
 import android.os.Bundle;
 import android.net.http.SslError;
 
-/*
+/**
  * A simple class to store the wrong certificates that user is aware but
  * chose to proceed.
  */
-class SslCertLookupTable {
+final class SslCertLookupTable {
     private static SslCertLookupTable sTable;
     private final Bundle table;
 
diff --git a/core/java/android/webkit/SslClientCertLookupTable.java b/core/java/android/webkit/SslClientCertLookupTable.java
new file mode 100644
index 0000000..630debd
--- /dev/null
+++ b/core/java/android/webkit/SslClientCertLookupTable.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.webkit;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * A simple class to store client certificates that user has chosen.
+ */
+final class SslClientCertLookupTable {
+    private static SslClientCertLookupTable sTable;
+    private final Map<String, byte[]> privateKeys;
+    private final Map<String, byte[][]> certificateChains;
+    private final Set<String> denied;
+
+    public static synchronized SslClientCertLookupTable getInstance() {
+        if (sTable == null) {
+            sTable = new SslClientCertLookupTable();
+        }
+        return sTable;
+    }
+
+    private SslClientCertLookupTable() {
+        privateKeys = new HashMap<String, byte[]>();
+        certificateChains = new HashMap<String, byte[][]>();
+        denied = new HashSet<String>();
+    }
+
+    public void Allow(String host_and_port, byte[] privateKey, byte[][] chain) {
+        privateKeys.put(host_and_port, privateKey);
+        certificateChains.put(host_and_port, chain);
+        denied.remove(host_and_port);
+    }
+
+    public void Deny(String host_and_port) {
+        privateKeys.remove(host_and_port);
+        certificateChains.remove(host_and_port);
+        denied.add(host_and_port);
+    }
+
+    public boolean IsAllowed(String host_and_port) {
+        return privateKeys.containsKey(host_and_port);
+    }
+
+    public boolean IsDenied(String host_and_port) {
+        return denied.contains(host_and_port);
+    }
+
+    public byte[] PrivateKey(String host_and_port) {
+        return privateKeys.get(host_and_port);
+    }
+
+    public byte[][] CertificateChain(String host_and_port) {
+        return certificateChains.get(host_and_port);
+    }
+}
diff --git a/core/java/android/webkit/ViewStateSerializer.java b/core/java/android/webkit/ViewStateSerializer.java
new file mode 100644
index 0000000..0fc76fa
--- /dev/null
+++ b/core/java/android/webkit/ViewStateSerializer.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package android.webkit;
+
+import android.graphics.Point;
+import android.graphics.Region;
+import android.webkit.WebViewCore.DrawData;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * @hide
+ */
+class ViewStateSerializer {
+
+    private static final int WORKING_STREAM_STORAGE = 16 * 1024;
+
+    static final int VERSION = 1;
+
+    static boolean serializeViewState(OutputStream stream, WebView web)
+            throws IOException {
+        DataOutputStream dos = new DataOutputStream(stream);
+        dos.writeInt(VERSION);
+        dos.writeInt(web.getContentWidth());
+        dos.writeInt(web.getContentHeight());
+        return nativeSerializeViewState(web.getBaseLayer(), dos,
+                new byte[WORKING_STREAM_STORAGE]);
+    }
+
+    static DrawData deserializeViewState(InputStream stream, WebView web)
+            throws IOException {
+        DataInputStream dis = new DataInputStream(stream);
+        int version = dis.readInt();
+        if (version != VERSION) {
+            throw new IOException("Unexpected version: " + version);
+        }
+        int contentWidth = dis.readInt();
+        int contentHeight = dis.readInt();
+        int baseLayer = nativeDeserializeViewState(dis,
+                new byte[WORKING_STREAM_STORAGE]);
+
+        final WebViewCore.DrawData draw = new WebViewCore.DrawData();
+        draw.mViewState = new WebViewCore.ViewState();
+        int viewWidth = web.getViewWidth();
+        int viewHeight = web.getViewHeightWithTitle() - web.getTitleHeight();
+        draw.mViewSize = new Point(viewWidth, viewHeight);
+        draw.mContentSize = new Point(contentWidth, contentHeight);
+        draw.mViewState.mDefaultScale = web.getDefaultZoomScale();
+        draw.mBaseLayer = baseLayer;
+        draw.mInvalRegion = new Region(0, 0, contentWidth, contentHeight);
+        return draw;
+    }
+
+    private static native boolean nativeSerializeViewState(int baseLayer,
+            OutputStream stream, byte[] storage);
+
+    // Returns a pointer to the BaseLayer
+    private static native int nativeDeserializeViewState(
+            InputStream stream, byte[] storage);
+
+    private ViewStateSerializer() {}
+}
diff --git a/core/java/android/webkit/WebChromeClient.java b/core/java/android/webkit/WebChromeClient.java
index 755366c..ae40ded 100644
--- a/core/java/android/webkit/WebChromeClient.java
+++ b/core/java/android/webkit/WebChromeClient.java
@@ -16,6 +16,7 @@
 
 package android.webkit;
 
+import android.content.pm.ActivityInfo;
 import android.graphics.Bitmap;
 import android.net.Uri;
 import android.os.Message;
@@ -77,6 +78,18 @@
 
     /**
      * Notify the host application that the current page would
+     * like to show a custom View in a particular orientation.
+     * @param view is the View object to be shown.
+     * @param requestedOrientation An orientation constant as used in
+     * {@link ActivityInfo#screenOrientation ActivityInfo.screenOrientation}.
+     * @param callback is the callback to be invoked if and when the view
+     * is dismissed.
+     */
+    public void onShowCustomView(View view, int requestedOrientation,
+            CustomViewCallback callback) {};
+    
+    /**
+     * Notify the host application that the current page would
      * like to hide its custom view.
      */
     public void onHideCustomView() {}
diff --git a/core/java/android/webkit/WebSettings.java b/core/java/android/webkit/WebSettings.java
index 66fcc27..761007f 100644
--- a/core/java/android/webkit/WebSettings.java
+++ b/core/java/android/webkit/WebSettings.java
@@ -59,6 +59,7 @@
      * NORMAL is 100%
      * LARGER is 150%
      * LARGEST is 200%
+     * @deprecated Use {@link WebSettings#setTextZoom(int)} and {@link WebSettings#getTextZoom()} instead.
      */
     public enum TextSize {
         SMALLEST(50),
@@ -158,7 +159,7 @@
     // know what they are.
     private LayoutAlgorithm mLayoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
     private Context         mContext;
-    private TextSize        mTextSize = TextSize.NORMAL;
+    private int             mTextSize = 100;
     private String          mStandardFontFamily = "sans-serif";
     private String          mFixedFontFamily = "monospace";
     private String          mSansSerifFontFamily = "sans-serif";
@@ -709,26 +710,61 @@
     }
 
     /**
-     * Set the text size of the page.
-     * @param t A TextSize value for increasing or decreasing the text.
-     * @see WebSettings.TextSize
+     * Set the text zoom of the page in percent. Default is 100.
+     * @param textZoom A percent value for increasing or decreasing the text.
      */
-    public synchronized void setTextSize(TextSize t) {
-        if (WebView.mLogEvent && mTextSize != t ) {
-            EventLog.writeEvent(EventLogTags.BROWSER_TEXT_SIZE_CHANGE,
-                    mTextSize.value, t.value);
+    public synchronized void setTextZoom(int textZoom) {
+        if (mTextSize != textZoom) {
+            if (WebView.mLogEvent) {
+                EventLog.writeEvent(EventLogTags.BROWSER_TEXT_SIZE_CHANGE,
+                        mTextSize, textZoom);
+            }
+            mTextSize = textZoom;
+            postSync();
         }
-        mTextSize = t;
-        postSync();
     }
 
     /**
-     * Get the text size of the page.
+     * Get the text zoom of the page in percent.
+     * @return A percent value describing the text zoom.
+     * @see setTextSizeZoom
+     */
+    public synchronized int getTextZoom() {
+        return mTextSize;
+    }
+
+    /**
+     * Set the text size of the page.
+     * @param t A TextSize value for increasing or decreasing the text.
+     * @see WebSettings.TextSize
+     * @deprecated Use {@link #setTextZoom(int)} instead
+     */
+    public synchronized void setTextSize(TextSize t) {
+        setTextZoom(t.value);
+    }
+
+    /**
+     * Get the text size of the page. If the text size was previously specified
+     * in percent using {@link #setTextZoom(int)}, this will return
+     * the closest matching {@link TextSize}.
      * @return A TextSize enum value describing the text size.
      * @see WebSettings.TextSize
+     * @deprecated Use {@link #getTextZoom()} instead
      */
     public synchronized TextSize getTextSize() {
-        return mTextSize;
+        TextSize closestSize = null;
+        int smallestDelta = Integer.MAX_VALUE;
+        for (TextSize size : TextSize.values()) {
+            int delta = Math.abs(mTextSize - size.value);
+            if (delta == 0) {
+                return size;
+            }
+            if (delta < smallestDelta) {
+                smallestDelta = delta;
+                closestSize = size;
+            }
+        }
+        return closestSize != null ? closestSize : TextSize.NORMAL;
     }
 
     /**
@@ -1234,7 +1270,7 @@
      */
     @Deprecated
     public synchronized void setPluginsEnabled(boolean flag) {
-        setPluginState(PluginState.ON);
+        setPluginState(flag ? PluginState.ON : PluginState.OFF);
     }
 
     /**
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java
index 3c2c8f6..c56e6db 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -44,7 +44,6 @@
 import android.graphics.Rect;
 import android.graphics.RectF;
 import android.graphics.Region;
-import android.graphics.SurfaceTexture;
 import android.graphics.Shader;
 import android.graphics.drawable.Drawable;
 import android.net.Proxy;
@@ -84,6 +83,7 @@
 import android.view.inputmethod.InputConnection;
 import android.view.inputmethod.InputMethodManager;
 import android.webkit.WebTextView.AutoCompleteAdapter;
+import android.webkit.WebViewCore.DrawData;
 import android.webkit.WebViewCore.EventHub;
 import android.webkit.WebViewCore.TouchEventData;
 import android.webkit.WebViewCore.TouchHighlightData;
@@ -98,10 +98,15 @@
 import android.widget.OverScroller;
 import android.widget.Toast;
 
+import junit.framework.Assert;
+
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.net.URLDecoder;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -113,8 +118,6 @@
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import junit.framework.Assert;
-
 /**
  * <p>A View that displays web pages. This class is the basis upon which you
  * can roll your own web browser or simply display some online content within your Activity.
@@ -169,7 +172,7 @@
  *
  * // OR, you can also load from an HTML string:
  * String summary = "&lt;html>&lt;body>You scored &lt;b>192&lt;/b> points.&lt;/body>&lt;/html>";
- * webview.loadData(summary, "text/html", "utf-8");
+ * webview.loadData(summary, "text/html", null);
  * // ... although note that there are restrictions on what this HTML can do.
  * // See the JavaDocs for {@link #loadData(String,String,String) loadData()} and {@link
  * #loadDataWithBaseURL(String,String,String,String,String) loadDataWithBaseURL()} for more info.
@@ -419,6 +422,9 @@
      */
     private int mLastTouchX;
     private int mLastTouchY;
+    private int mStartTouchX;
+    private int mStartTouchY;
+    private float mAverageAngle;
 
     /**
      * Time of the last touch event.
@@ -616,6 +622,9 @@
     // SetBaseLayer time and to pause when WebView paused.
     private HTML5VideoViewProxy mHTML5VideoViewProxy;
 
+    // If we are using a set picture, don't send view updates to webkit
+    private boolean mBlockWebkitViewMessages = false;
+
     /*
      * Private message ids
      */
@@ -1183,7 +1192,6 @@
         final ViewConfiguration configuration = ViewConfiguration.get(getContext());
         int slop = configuration.getScaledTouchSlop();
         mTouchSlopSquare = slop * slop;
-        mMinLockSnapReverseDistance = slop;
         slop = configuration.getScaledDoubleTapSlop();
         mDoubleTapSlopSquare = slop * slop;
         final float density = getContext().getResources().getDisplayMetrics().density;
@@ -1387,6 +1395,10 @@
      */
     public int getVisibleTitleHeight() {
         checkThread();
+        return getVisibleTitleHeightImpl();
+    }
+
+    private int getVisibleTitleHeightImpl() {
         // need to restrict mScrollY due to over scroll
         return Math.max(getTitleHeight() - Math.max(0, mScrollY), 0);
     }
@@ -1397,10 +1409,10 @@
      * Note: this can be called from WebCoreThread.
      */
     /* package */ int getViewHeight() {
-        return getViewHeightWithTitle() - getVisibleTitleHeight();
+        return getViewHeightWithTitle() - getVisibleTitleHeightImpl();
     }
 
-    private int getViewHeightWithTitle() {
+    int getViewHeightWithTitle() {
         int height = getHeight();
         if (isHorizontalScrollBarEnabled() && !mOverlayHorizontalScrollbar) {
             height -= getHorizontalScrollbarHeight();
@@ -1786,6 +1798,53 @@
     }
 
     /**
+     * Saves the view data to the output stream. The output is highly
+     * version specific, and may not be able to be loaded by newer versions
+     * of WebView.
+     * @param stream The {@link OutputStream} to save to
+     * @return True if saved successfully
+     * @hide
+     */
+    public boolean saveViewState(OutputStream stream) {
+        try {
+            return ViewStateSerializer.serializeViewState(stream, this);
+        } catch (IOException e) {
+            Log.w(LOGTAG, "Failed to saveViewState", e);
+        }
+        return false;
+    }
+
+    /**
+     * Loads the view data from the input stream. See
+     * {@link #saveViewState(OutputStream)} for more information.
+     * @param stream The {@link InputStream} to load from
+     * @return True if loaded successfully
+     * @hide
+     */
+    public boolean loadViewState(InputStream stream) {
+        try {
+            mLoadedPicture = ViewStateSerializer.deserializeViewState(stream, this);
+            mBlockWebkitViewMessages = true;
+            setNewPicture(mLoadedPicture, true);
+            return true;
+        } catch (IOException e) {
+            Log.w(LOGTAG, "Failed to loadViewState", e);
+        }
+        return false;
+    }
+
+    /**
+     * Clears the view state set with {@link #loadViewState(InputStream)}.
+     * This WebView will then switch to showing the content from webkit
+     * @hide
+     */
+    public void clearViewState() {
+        mBlockWebkitViewMessages = false;
+        mLoadedPicture = null;
+        invalidate();
+    }
+
+    /**
      * Restore the state of this WebView from the given map used in
      * {@link android.app.Activity#onRestoreInstanceState}. This method should
      * be called to restore the state of the WebView before using the object. If
@@ -1912,14 +1971,17 @@
     }
 
     /**
-     * Load the given data into the WebView. This will load the data into
-     * WebView using the data: scheme. Content loaded through this mechanism
-     * does not have the ability to load content from the network.
-     * @param data A String of data in the given encoding. The date must
-     * be URI-escaped -- '#', '%', '\', '?' should be replaced by %23, %25,
-     * %27, %3f respectively.
-     * @param mimeType The MIMEType of the data. i.e. text/html, image/jpeg
-     * @param encoding The encoding of the data. i.e. utf-8, base64
+     * Load the given data into the WebView using a 'data' scheme URL. Content
+     * loaded in this way does not have the ability to load content from the
+     * network.
+     * <p>
+     * If the value of the encoding parameter is 'base64', then the data must
+     * be encoded as base64. Otherwise, the data must use ASCII encoding for
+     * octets inside the range of safe URL characters and use the standard %xx
+     * hex encoding of URLs for octets outside that range.
+     * @param data A String of data in the given encoding.
+     * @param mimeType The MIMEType of the data, e.g. 'text/html'.
+     * @param encoding The encoding of the data.
      */
     public void loadData(String data, String mimeType, String encoding) {
         checkThread();
@@ -1927,7 +1989,14 @@
     }
 
     private void loadDataImpl(String data, String mimeType, String encoding) {
-        loadUrlImpl("data:" + mimeType + ";" + encoding + "," + data);
+        StringBuilder dataUrl = new StringBuilder("data:");
+        dataUrl.append(mimeType);
+        if ("base64".equals(encoding)) {
+            dataUrl.append(";base64");
+        }
+        dataUrl.append(",");
+        dataUrl.append(data);
+        loadUrlImpl(dataUrl.toString());
     }
 
     /**
@@ -1936,13 +2005,9 @@
      * that is loaded through this interface. As such, it is used to resolve any
      * relative URLs. The historyUrl is used for the history entry.
      * <p>
-     * Note for post 1.0. Due to the change in the WebKit, the access to asset
-     * files through "file:///android_asset/" for the sub resources is more
-     * restricted. If you provide null or empty string as baseUrl, you won't be
-     * able to access asset files. If the baseUrl is anything other than
-     * http(s)/ftp(s)/about/javascript as scheme, you can access asset files for
-     * sub resources.
-     *
+     * Note that content specified in this way can access local device files
+     * (via 'file' scheme URLs) only if baseUrl specifies a scheme other than
+     * 'http', 'https', 'ftp', 'ftps', 'about' or 'javascript'.
      * @param baseUrl Url to resolve relative paths with, if null defaults to
      *            "about:blank"
      * @param data A String of data in the given encoding.
@@ -2664,10 +2729,12 @@
         calcOurContentVisibleRect(rect);
         // Rect.equals() checks for null input.
         if (!rect.equals(mLastVisibleRectSent)) {
-            Point pos = new Point(rect.left, rect.top);
-            mWebViewCore.removeMessages(EventHub.SET_SCROLL_OFFSET);
-            mWebViewCore.sendMessage(EventHub.SET_SCROLL_OFFSET,
-                    nativeMoveGeneration(), mSendScrollEvent ? 1 : 0, pos);
+            if (!mBlockWebkitViewMessages) {
+                Point pos = new Point(rect.left, rect.top);
+                mWebViewCore.removeMessages(EventHub.SET_SCROLL_OFFSET);
+                mWebViewCore.sendMessage(EventHub.SET_SCROLL_OFFSET,
+                        nativeMoveGeneration(), mSendScrollEvent ? 1 : 0, pos);
+            }
             mLastVisibleRectSent = rect;
             mPrivateHandler.removeMessages(SWITCH_TO_LONGPRESS);
         }
@@ -2682,7 +2749,9 @@
             // TODO: the global offset is only used by windowRect()
             // in ChromeClientAndroid ; other clients such as touch
             // and mouse events could return view + screen relative points.
-            mWebViewCore.sendMessage(EventHub.SET_GLOBAL_BOUNDS, globalRect);
+            if (!mBlockWebkitViewMessages) {
+                mWebViewCore.sendMessage(EventHub.SET_GLOBAL_BOUNDS, globalRect);
+            }
             mLastGlobalRect = globalRect;
         }
         return rect;
@@ -2703,7 +2772,7 @@
         // the visible height back in to account for the fact that if the title
         // bar is partially visible, the part of the visible rect which is
         // displaying our content is displaced by that amount.
-        r.top = viewToContentY(r.top + getVisibleTitleHeight());
+        r.top = viewToContentY(r.top + getVisibleTitleHeightImpl());
         r.right = viewToContentX(r.right);
         r.bottom = viewToContentY(r.bottom);
     }
@@ -2720,7 +2789,7 @@
         // the visible height back in to account for the fact that if the title
         // bar is partially visible, the part of the visible rect which is
         // displaying our content is displaced by that amount.
-        r.top = viewToContentYf(ri.top + getVisibleTitleHeight());
+        r.top = viewToContentYf(ri.top + getVisibleTitleHeightImpl());
         r.right = viewToContentXf(ri.right);
         r.bottom = viewToContentYf(ri.bottom);
     }
@@ -2747,6 +2816,7 @@
      * @return true if new values were sent
      */
     boolean sendViewSizeZoom(boolean force) {
+        if (mBlockWebkitViewMessages) return false;
         if (mZoomManager.isPreventingWebkitUpdates()) return false;
 
         int viewWidth = getViewWidth();
@@ -2868,7 +2938,7 @@
         if (mScrollY < 0) {
             t -= mScrollY;
         }
-        scrollBar.setBounds(l, t + getVisibleTitleHeight(), r, b);
+        scrollBar.setBounds(l, t + getVisibleTitleHeightImpl(), r, b);
         scrollBar.draw(canvas);
     }
 
@@ -2992,6 +3062,13 @@
     }
 
     /**
+     * @hide
+     */
+    public int getPageBackgroundColor() {
+        return nativeGetBackgroundColor();
+    }
+
+    /**
      * Pause all layout, parsing, and JavaScript timers for all webviews. This
      * is a global requests, not restricted to just this webview. This can be
      * useful if the application has been paused.
@@ -3359,9 +3436,11 @@
                 }
                 abortAnimation();
                 mPrivateHandler.removeMessages(RESUME_WEBCORE_PRIORITY);
-                WebViewCore.resumePriority();
-                if (!mSelectingText) {
-                    WebViewCore.resumeUpdatePicture(mWebViewCore);
+                if (!mBlockWebkitViewMessages) {
+                    WebViewCore.resumePriority();
+                    if (!mSelectingText) {
+                        WebViewCore.resumeUpdatePicture(mWebViewCore);
+                    }
                 }
                 if (oldX != mScrollX || oldY != mScrollY) {
                     sendOurVisibleRect();
@@ -4192,6 +4271,10 @@
         }
     }
 
+    int getBaseLayer() {
+        return nativeGetBaseLayer();
+    }
+
     private void onZoomAnimationStart() {
         // If it is in password mode, turn it off so it does not draw misplaced.
         if (inEditingMode() && nativeFocusCandidateIsPassword()) {
@@ -4215,7 +4298,7 @@
     }
 
     void onFixedLengthZoomAnimationEnd() {
-        if (!mSelectingText) {
+        if (!mBlockWebkitViewMessages && !mSelectingText) {
             WebViewCore.resumeUpdatePicture(mWebViewCore);
         }
         onZoomAnimationEnd();
@@ -4316,7 +4399,7 @@
             // synchronization problem with layers.
             int content = nativeDraw(canvas, color, extras, false);
             canvas.setDrawFilter(null);
-            if (content != 0) {
+            if (!mBlockWebkitViewMessages && content != 0) {
                 mWebViewCore.sendMessage(EventHub.SPLIT_PICTURE_SET, content, 0);
             }
         }
@@ -4720,6 +4803,9 @@
 
     @Override
     public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
+        if (mBlockWebkitViewMessages) {
+            return false;
+        }
         // send complex characters to webkit for use by JS and plugins
         if (keyCode == KeyEvent.KEYCODE_UNKNOWN && event.getCharacters() != null) {
             // pass the key to DOM
@@ -4744,6 +4830,9 @@
                     + "keyCode=" + keyCode
                     + ", " + event + ", unicode=" + event.getUnicodeChar());
         }
+        if (mBlockWebkitViewMessages) {
+            return false;
+        }
 
         // don't implement accelerator keys here; defer to host application
         if (event.isCtrlPressed()) {
@@ -4947,6 +5036,9 @@
             Log.v(LOGTAG, "keyUp at " + System.currentTimeMillis()
                     + ", " + event + ", unicode=" + event.getUnicodeChar());
         }
+        if (mBlockWebkitViewMessages) {
+            return false;
+        }
 
         if (mNativeClass == 0) {
             return false;
@@ -5098,7 +5190,7 @@
             Rect rect = nativeCursorNodeBounds();
             mSelectX = contentToViewX(rect.left);
             mSelectY = contentToViewY(rect.top);
-        } else if (mLastTouchY > getVisibleTitleHeight()) {
+        } else if (mLastTouchY > getVisibleTitleHeightImpl()) {
             mSelectX = mScrollX + mLastTouchX;
             mSelectY = mScrollY + mLastTouchY;
         } else {
@@ -5416,7 +5508,7 @@
             int rootViewHeight = rootView.getHeight();
             mViewRectViewport.set(mGLRectViewport);
             int savedWebViewBottom = mGLRectViewport.bottom;
-            mGLRectViewport.bottom = rootViewHeight - mGLRectViewport.top - getVisibleTitleHeight();
+            mGLRectViewport.bottom = rootViewHeight - mGLRectViewport.top - getVisibleTitleHeightImpl();
             mGLRectViewport.top = rootViewHeight - savedWebViewBottom;
             mGLViewportEmpty = false;
         } else {
@@ -5458,6 +5550,13 @@
         }
 
         mZoomManager.onSizeChanged(w, h, ow, oh);
+
+        if (mLoadedPicture != null && mDelaySetPicture == null) {
+            // Size changes normally result in a new picture
+            // Re-set the loaded picture to simulate that
+            // However, do not update the base layer as that hasn't changed
+            setNewPicture(mLoadedPicture, false);
+        }
     }
 
     @Override
@@ -5466,7 +5565,7 @@
         if (!mInOverScrollMode) {
             sendOurVisibleRect();
             // update WebKit if visible title bar height changed. The logic is same
-            // as getVisibleTitleHeight.
+            // as getVisibleTitleHeightImpl.
             int titleHeight = getTitleHeight();
             if (Math.max(titleHeight - t, 0) != Math.max(titleHeight - oldt, 0)) {
                 sendViewSizeZoom(false);
@@ -5509,15 +5608,31 @@
         }
     }
 
-    // Here are the snap align logic:
-    // 1. If it starts nearly horizontally or vertically, snap align;
-    // 2. If there is a dramitic direction change, let it go;
-    // 3. If there is a same direction back and forth, lock it.
-
-    // adjustable parameters
-    private int mMinLockSnapReverseDistance;
-    private static final float MAX_SLOPE_FOR_DIAG = 1.5f;
-    private static final int MIN_BREAK_SNAP_CROSS_DISTANCE = 80;
+    /*
+     * Here is the snap align logic:
+     * 1. If it starts nearly horizontally or vertically, snap align;
+     * 2. If there is a dramitic direction change, let it go;
+     *
+     * Adjustable parameters. Angle is the radians on a unit circle, limited
+     * to quadrant 1. Values range from 0f (horizontal) to PI/2 (vertical)
+     */
+    private static final float HSLOPE_TO_START_SNAP = .25f;
+    private static final float HSLOPE_TO_BREAK_SNAP = .4f;
+    private static final float VSLOPE_TO_START_SNAP = 1.25f;
+    private static final float VSLOPE_TO_BREAK_SNAP = .95f;
+    /*
+     *  These values are used to influence the average angle when entering
+     *  snap mode. If is is the first movement entering snap, we set the average
+     *  to the appropriate ideal. If the user is entering into snap after the
+     *  first movement, then we average the average angle with these values.
+     */
+    private static final float ANGLE_VERT = 2f;
+    private static final float ANGLE_HORIZ = 0f;
+    /*
+     *  The modified moving average weight.
+     *  Formula: MAV[t]=MAV[t-1] + (P[t]-MAV[t-1])/n
+     */
+    private static final float MMA_WEIGHT_N = 5;
 
     private boolean hitFocusedPlugin(int contentX, int contentY) {
         if (DebugFlags.WEB_VIEW) {
@@ -5531,10 +5646,12 @@
     }
 
     private boolean shouldForwardTouchEvent() {
-        return mFullScreenHolder != null || (mForwardTouchEvents
+        if (mFullScreenHolder != null) return true;
+        if (mBlockWebkitViewMessages) return false;
+        return mForwardTouchEvents
                 && !mSelectingText
                 && mPreventDefault != PREVENT_DEFAULT_IGNORE
-                && mPreventDefault != PREVENT_DEFAULT_NO);
+                && mPreventDefault != PREVENT_DEFAULT_NO;
     }
 
     private boolean inFullScreenMode() {
@@ -5543,7 +5660,7 @@
 
     private void dismissFullScreenMode() {
         if (inFullScreenMode()) {
-            mFullScreenHolder.dismiss();
+            mFullScreenHolder.hide();
             mFullScreenHolder = null;
         }
     }
@@ -5621,6 +5738,12 @@
         return true;
     }
 
+    private float calculateDragAngle(int dx, int dy) {
+        dx = Math.abs(dx);
+        dy = Math.abs(dy);
+        return (float) Math.atan2(dy, dx);
+    }
+
     /*
      * Common code for single touch and multi-touch.
      * (x, y) denotes current focus point, which is the touch point for single touch
@@ -5665,25 +5788,31 @@
                         // commit the short press action for the previous tap
                         doShortPress();
                         mTouchMode = TOUCH_INIT_MODE;
-                        mDeferTouchProcess = (!inFullScreenMode()
-                                && mForwardTouchEvents) ? hitFocusedPlugin(
-                                contentX, contentY) : false;
+                        mDeferTouchProcess = !mBlockWebkitViewMessages
+                                && (!inFullScreenMode() && mForwardTouchEvents)
+                                ? hitFocusedPlugin(contentX, contentY)
+                                : false;
                     }
                 } else { // the normal case
                     mTouchMode = TOUCH_INIT_MODE;
-                    mDeferTouchProcess = (!inFullScreenMode()
-                            && mForwardTouchEvents) ? hitFocusedPlugin(
-                            contentX, contentY) : false;
-                    mWebViewCore.sendMessage(
-                            EventHub.UPDATE_FRAME_CACHE_IF_LOADING);
+                    mDeferTouchProcess = !mBlockWebkitViewMessages
+                            && (!inFullScreenMode() && mForwardTouchEvents)
+                            ? hitFocusedPlugin(contentX, contentY)
+                            : false;
+                    if (!mBlockWebkitViewMessages) {
+                        mWebViewCore.sendMessage(
+                                EventHub.UPDATE_FRAME_CACHE_IF_LOADING);
+                    }
                     if (getSettings().supportTouchOnly()) {
                         TouchHighlightData data = new TouchHighlightData();
                         data.mX = contentX;
                         data.mY = contentY;
                         data.mSlop = viewToContentDimension(mNavSlop);
-                        mWebViewCore.sendMessageDelayed(
-                                EventHub.GET_TOUCH_HIGHLIGHT_RECTS, data,
-                                ViewConfiguration.getTapTimeout());
+                        if (!mBlockWebkitViewMessages) {
+                            mWebViewCore.sendMessageDelayed(
+                                    EventHub.GET_TOUCH_HIGHLIGHT_RECTS, data,
+                                    ViewConfiguration.getTapTimeout());
+                        }
                         if (DEBUG_TOUCH_HIGHLIGHT) {
                             if (getSettings().getNavDump()) {
                                 mTouchHighlightX = (int) x + mScrollX;
@@ -5719,7 +5848,7 @@
                             SWITCH_TO_LONGPRESS, LONG_PRESS_TIMEOUT);
                     if (inFullScreenMode() || mDeferTouchProcess) {
                         mPreventDefault = PREVENT_DEFAULT_YES;
-                    } else if (mForwardTouchEvents) {
+                    } else if (!mBlockWebkitViewMessages && mForwardTouchEvents) {
                         mPreventDefault = PREVENT_DEFAULT_MAYBE_YES;
                     } else {
                         mPreventDefault = PREVENT_DEFAULT_NO;
@@ -5860,16 +5989,17 @@
                     // if mZoomManager.supportsPanDuringZoom() is true.
                     final ScaleGestureDetector detector =
                       mZoomManager.getMultiTouchGestureDetector();
+                    mAverageAngle = calculateDragAngle(deltaX, deltaY);
                     if (detector == null || !detector.isInProgress()) {
                         // if it starts nearly horizontal or vertical, enforce it
-                        int ax = Math.abs(deltaX);
-                        int ay = Math.abs(deltaY);
-                        if (ax > MAX_SLOPE_FOR_DIAG * ay) {
+                        if (mAverageAngle < HSLOPE_TO_START_SNAP) {
                             mSnapScrollMode = SNAP_X;
                             mSnapPositive = deltaX > 0;
-                        } else if (ay > MAX_SLOPE_FOR_DIAG * ax) {
+                            mAverageAngle = ANGLE_HORIZ;
+                        } else if (mAverageAngle > VSLOPE_TO_START_SNAP) {
                             mSnapScrollMode = SNAP_Y;
                             mSnapPositive = deltaY > 0;
+                            mAverageAngle = ANGLE_VERT;
                         }
                     }
 
@@ -5889,35 +6019,31 @@
                 if (deltaX == 0 && deltaY == 0) {
                     keepScrollBarsVisible = done = true;
                 } else {
-                    if (mSnapScrollMode == SNAP_X || mSnapScrollMode == SNAP_Y) {
-                        int ax = Math.abs(deltaX);
-                        int ay = Math.abs(deltaY);
+                    mAverageAngle +=
+                        (calculateDragAngle(deltaX, deltaY) - mAverageAngle)
+                        / MMA_WEIGHT_N;
+                    if (mSnapScrollMode != SNAP_NONE) {
+                        if (mSnapScrollMode == SNAP_Y) {
+                            // radical change means getting out of snap mode
+                            if (mAverageAngle < VSLOPE_TO_BREAK_SNAP) {
+                                mSnapScrollMode = SNAP_NONE;
+                            }
+                        }
                         if (mSnapScrollMode == SNAP_X) {
                             // radical change means getting out of snap mode
-                            if (ay > MAX_SLOPE_FOR_DIAG * ax
-                                    && ay > MIN_BREAK_SNAP_CROSS_DISTANCE) {
+                            if (mAverageAngle > HSLOPE_TO_BREAK_SNAP) {
                                 mSnapScrollMode = SNAP_NONE;
                             }
-                            // reverse direction means lock in the snap mode
-                            if (ax > MAX_SLOPE_FOR_DIAG * ay &&
-                                    (mSnapPositive
-                                    ? deltaX < -mMinLockSnapReverseDistance
-                                    : deltaX > mMinLockSnapReverseDistance)) {
-                                mSnapScrollMode |= SNAP_LOCK;
-                            }
-                        } else {
-                            // radical change means getting out of snap mode
-                            if (ax > MAX_SLOPE_FOR_DIAG * ay
-                                    && ax > MIN_BREAK_SNAP_CROSS_DISTANCE) {
-                                mSnapScrollMode = SNAP_NONE;
-                            }
-                            // reverse direction means lock in the snap mode
-                            if (ay > MAX_SLOPE_FOR_DIAG * ax &&
-                                    (mSnapPositive
-                                    ? deltaY < -mMinLockSnapReverseDistance
-                                    : deltaY > mMinLockSnapReverseDistance)) {
-                                mSnapScrollMode |= SNAP_LOCK;
-                            }
+                        }
+                    } else {
+                        if (mAverageAngle < HSLOPE_TO_START_SNAP) {
+                            mSnapScrollMode = SNAP_X;
+                            mSnapPositive = deltaX > 0;
+                            mAverageAngle = (mAverageAngle + ANGLE_HORIZ) / 2;
+                        } else if (mAverageAngle > VSLOPE_TO_START_SNAP) {
+                            mSnapScrollMode = SNAP_Y;
+                            mSnapPositive = deltaY > 0;
+                            mAverageAngle = (mAverageAngle + ANGLE_VERT) / 2;
                         }
                     }
                     if (mSnapScrollMode != SNAP_NONE) {
@@ -5927,13 +6053,9 @@
                             deltaX = 0;
                         }
                     }
+                    mLastTouchX = x;
+                    mLastTouchY = y;
                     if ((deltaX | deltaY) != 0) {
-                        if (deltaX != 0) {
-                            mLastTouchX = x;
-                        }
-                        if (deltaY != 0) {
-                            mLastTouchY = y;
-                        }
                         mHeldMotionless = MOTIONLESS_FALSE;
                     }
                     mLastTouchTime = eventTime;
@@ -6243,8 +6365,8 @@
 
     private void startTouch(float x, float y, long eventTime) {
         // Remember where the motion event started
-        mLastTouchX = Math.round(x);
-        mLastTouchY = Math.round(y);
+        mStartTouchX = mLastTouchX = Math.round(x);
+        mStartTouchY = mLastTouchY = Math.round(y);
         mLastTouchTime = eventTime;
         mVelocityTracker = VelocityTracker.obtain();
         mSnapScrollMode = SNAP_NONE;
@@ -6380,7 +6502,7 @@
                     if (hscroll != 0 || vscroll != 0) {
                         final int vdelta = (int) (vscroll * getVerticalScrollFactor());
                         final int hdelta = (int) (hscroll * getHorizontalScrollFactor());
-                        if (pinScrollBy(hdelta, vdelta, true, 0)) {
+                        if (pinScrollBy(hdelta, vdelta, false, 0)) {
                             return true;
                         }
                     }
@@ -6422,6 +6544,9 @@
     // arrow key events, not trackball events, from one child to the next
     private boolean mMapTrackballToArrowKeys = true;
 
+    private DrawData mDelaySetPicture;
+    private DrawData mLoadedPicture;
+
     public void setMapTrackballToArrowKeys(boolean setMap) {
         checkThread();
         mMapTrackballToArrowKeys = setMap;
@@ -6755,11 +6880,6 @@
                 vx = 0;
             }
         }
-        if (true /* EMG release: make our fling more like Maps' */) {
-            // maps cuts their velocity in half
-            vx = vx * 3 / 4;
-            vy = vy * 3 / 4;
-        }
         if ((maxX == 0 && vy == 0) || (maxY == 0 && vx == 0)) {
             WebViewCore.resumePriority();
             if (!mSelectingText) {
@@ -7199,7 +7319,6 @@
                 if (measuredHeight > heightSize) {
                     measuredHeight = heightSize;
                     mHeightCanMeasure = false;
-                } else if (measuredHeight < heightSize) {
                     measuredHeight |= MEASURED_STATE_TOO_SMALL;
                 }
             }
@@ -7831,6 +7950,11 @@
                 // after WebView's destroy() is called, skip handling messages.
                 return;
             }
+            if (mBlockWebkitViewMessages
+                    && msg.what != WEBCORE_INITIALIZED_MSG_ID) {
+                // Blocking messages from webkit
+                return;
+            }
             switch (msg.what) {
                 case REMEMBER_PASSWORD: {
                     mDatabase.setUsernamePassword(
@@ -7966,66 +8090,7 @@
                 case NEW_PICTURE_MSG_ID: {
                     // called for new content
                     final WebViewCore.DrawData draw = (WebViewCore.DrawData) msg.obj;
-                    WebViewCore.ViewState viewState = draw.mViewState;
-                    boolean isPictureAfterFirstLayout = viewState != null;
-                    setBaseLayer(draw.mBaseLayer, draw.mInvalRegion,
-                            getSettings().getShowVisualIndicator(),
-                            isPictureAfterFirstLayout);
-                    final Point viewSize = draw.mViewSize;
-                    if (isPictureAfterFirstLayout) {
-                        // Reset the last sent data here since dealing with new page.
-                        mLastWidthSent = 0;
-                        mZoomManager.onFirstLayout(draw);
-                        if (!mDrawHistory) {
-                            // Do not send the scroll event for this particular
-                            // scroll message.  Note that a scroll event may
-                            // still be fired if the user scrolls before the
-                            // message can be handled.
-                            mSendScrollEvent = false;
-                            setContentScrollTo(viewState.mScrollX, viewState.mScrollY);
-                            mSendScrollEvent = true;
-
-                            // As we are on a new page, remove the WebTextView. This
-                            // is necessary for page loads driven by webkit, and in
-                            // particular when the user was on a password field, so
-                            // the WebTextView was visible.
-                            clearTextEntry();
-                        }
-                    }
-
-                    // We update the layout (i.e. request a layout from the
-                    // view system) if the last view size that we sent to
-                    // WebCore matches the view size of the picture we just
-                    // received in the fixed dimension.
-                    final boolean updateLayout = viewSize.x == mLastWidthSent
-                            && viewSize.y == mLastHeightSent;
-                    // Don't send scroll event for picture coming from webkit,
-                    // since the new picture may cause a scroll event to override
-                    // the saved history scroll position.
-                    mSendScrollEvent = false;
-                    recordNewContentSize(draw.mContentSize.x,
-                            draw.mContentSize.y, updateLayout);
-                    mSendScrollEvent = true;
-                    if (DebugFlags.WEB_VIEW) {
-                        Rect b = draw.mInvalRegion.getBounds();
-                        Log.v(LOGTAG, "NEW_PICTURE_MSG_ID {" +
-                                b.left+","+b.top+","+b.right+","+b.bottom+"}");
-                    }
-                    invalidateContentRect(draw.mInvalRegion.getBounds());
-
-                    if (mPictureListener != null) {
-                        mPictureListener.onNewPicture(WebView.this, capturePicture());
-                    }
-
-                    // update the zoom information based on the new picture
-                    mZoomManager.onNewPicture(draw);
-
-                    if (draw.mFocusSizeChanged && inEditingMode()) {
-                        mFocusSizeChanged = true;
-                    }
-                    if (isPictureAfterFirstLayout) {
-                        mViewManager.postReadyToDrawAll();
-                    }
+                    setNewPicture(draw, true);
                     break;
                 }
                 case WEBCORE_INITIALIZED_MSG_ID:
@@ -8034,6 +8099,10 @@
                             BrowserFrame.DRAWABLEDIR, mContext);
                     AssetManager am = mContext.getAssets();
                     nativeCreate(msg.arg1, drawableDir, am);
+                    if (mDelaySetPicture != null) {
+                        setNewPicture(mDelaySetPicture, true);
+                        mDelaySetPicture = null;
+                    }
                     break;
                 case UPDATE_TEXTFIELD_TEXT_MSG_ID:
                     // Make sure that the textfield is currently focused
@@ -8198,16 +8267,15 @@
 
                 case SHOW_FULLSCREEN: {
                     View view = (View) msg.obj;
-                    int npp = msg.arg1;
+                    int orientation = msg.arg1;
+                    int npp = msg.arg2;
 
                     if (inFullScreenMode()) {
                         Log.w(LOGTAG, "Should not have another full screen.");
                         dismissFullScreenMode();
                     }
-                    mFullScreenHolder = new PluginFullScreenHolder(WebView.this, npp);
+                    mFullScreenHolder = new PluginFullScreenHolder(WebView.this, orientation, npp);
                     mFullScreenHolder.setContentView(view);
-                    mFullScreenHolder.setCancelable(false);
-                    mFullScreenHolder.setCanceledOnTouchOutside(false);
                     mFullScreenHolder.show();
 
                     break;
@@ -8267,7 +8335,7 @@
                             (Math.min(maxHeight, y + viewHeight) - viewHeight));
                     // We need to take into account the visible title height
                     // when scrolling since y is an absolute view position.
-                    y = Math.max(0, y - getVisibleTitleHeight());
+                    y = Math.max(0, y - getVisibleTitleHeightImpl());
                     scrollTo(x, y);
                     }
                     break;
@@ -8345,6 +8413,80 @@
         }
     }
 
+    void setNewPicture(final WebViewCore.DrawData draw, boolean updateBaseLayer) {
+        if (mNativeClass == 0) {
+            if (mDelaySetPicture != null) {
+                throw new IllegalStateException("Tried to setNewPicture with"
+                        + " a delay picture already set! (memory leak)");
+            }
+            // Not initialized yet, delay set
+            mDelaySetPicture = draw;
+            return;
+        }
+        WebViewCore.ViewState viewState = draw.mViewState;
+        boolean isPictureAfterFirstLayout = viewState != null;
+        if (updateBaseLayer) {
+            setBaseLayer(draw.mBaseLayer, draw.mInvalRegion,
+                    getSettings().getShowVisualIndicator(),
+                    isPictureAfterFirstLayout);
+        }
+        final Point viewSize = draw.mViewSize;
+        if (isPictureAfterFirstLayout) {
+            // Reset the last sent data here since dealing with new page.
+            mLastWidthSent = 0;
+            mZoomManager.onFirstLayout(draw);
+            if (!mDrawHistory) {
+                // Do not send the scroll event for this particular
+                // scroll message.  Note that a scroll event may
+                // still be fired if the user scrolls before the
+                // message can be handled.
+                mSendScrollEvent = false;
+                setContentScrollTo(viewState.mScrollX, viewState.mScrollY);
+                mSendScrollEvent = true;
+
+                // As we are on a new page, remove the WebTextView. This
+                // is necessary for page loads driven by webkit, and in
+                // particular when the user was on a password field, so
+                // the WebTextView was visible.
+                clearTextEntry();
+            }
+        }
+
+        // We update the layout (i.e. request a layout from the
+        // view system) if the last view size that we sent to
+        // WebCore matches the view size of the picture we just
+        // received in the fixed dimension.
+        final boolean updateLayout = viewSize.x == mLastWidthSent
+                && viewSize.y == mLastHeightSent;
+        // Don't send scroll event for picture coming from webkit,
+        // since the new picture may cause a scroll event to override
+        // the saved history scroll position.
+        mSendScrollEvent = false;
+        recordNewContentSize(draw.mContentSize.x,
+                draw.mContentSize.y, updateLayout);
+        mSendScrollEvent = true;
+        if (DebugFlags.WEB_VIEW) {
+            Rect b = draw.mInvalRegion.getBounds();
+            Log.v(LOGTAG, "NEW_PICTURE_MSG_ID {" +
+                    b.left+","+b.top+","+b.right+","+b.bottom+"}");
+        }
+        invalidateContentRect(draw.mInvalRegion.getBounds());
+
+        if (mPictureListener != null) {
+            mPictureListener.onNewPicture(WebView.this, capturePicture());
+        }
+
+        // update the zoom information based on the new picture
+        mZoomManager.onNewPicture(draw);
+
+        if (draw.mFocusSizeChanged && inEditingMode()) {
+            mFocusSizeChanged = true;
+        }
+        if (isPictureAfterFirstLayout) {
+            mViewManager.postReadyToDrawAll();
+        }
+    }
+
     /**
      * Used when receiving messages for REQUEST_KEYBOARD_WITH_SELECTION_MSG_ID
      * and UPDATE_TEXT_SELECTION_MSG_ID.  Update the selection of WebTextView.
@@ -8909,8 +9051,9 @@
     /**
      *  Update our cache with updatedText.
      *  @param updatedText  The new text to put in our cache.
+     *  @hide
      */
-    /* package */ void updateCachedTextfield(String updatedText) {
+    protected void updateCachedTextfield(String updatedText) {
         // Also place our generation number so that when we look at the cache
         // we recognize that it is up to date.
         nativeUpdateCachedTextfield(updatedText, mTextGeneration);
@@ -9047,6 +9190,7 @@
     private native void     nativeSetHeightCanMeasure(boolean measure);
     private native void     nativeSetBaseLayer(int layer, Region invalRegion,
             boolean showVisualIndicator, boolean isPictureAfterFirstLayout);
+    private native int      nativeGetBaseLayer();
     private native void     nativeShowCursorTimed();
     private native void     nativeReplaceBaseContent(int content);
     private native void     nativeCopyBaseContentToPicture(Picture pict);
@@ -9079,4 +9223,5 @@
      * @return True if the layer is successfully scrolled.
      */
     private native boolean  nativeScrollLayer(int layer, int newX, int newY);
+    private native int      nativeGetBackgroundColor();
 }
diff --git a/core/java/android/webkit/WebViewClient.java b/core/java/android/webkit/WebViewClient.java
index 65026a5..d3be2bf 100644
--- a/core/java/android/webkit/WebViewClient.java
+++ b/core/java/android/webkit/WebViewClient.java
@@ -30,7 +30,7 @@
      * proper handler for the url. If WebViewClient is provided, return true
      * means the host application handles the url, while return false means the
      * current WebView handles the url.
-     * 
+     *
      * @param view The WebView that is initiating the callback.
      * @param url The url to be loaded.
      * @return True if the host application wants to leave the current WebView
@@ -46,7 +46,7 @@
      * framesets will call onPageStarted one time for the main frame. This also
      * means that onPageStarted will not be called when the contents of an
      * embedded frame changes, i.e. clicking a link whose target is an iframe.
-     * 
+     *
      * @param view The WebView that is initiating the callback.
      * @param url The url to be loaded.
      * @param favicon The favicon for this page if it already exists in the
@@ -60,7 +60,7 @@
      * is called only for main frame. When onPageFinished() is called, the
      * rendering picture may not be updated yet. To get the notification for the
      * new Picture, use {@link WebView.PictureListener#onNewPicture}.
-     * 
+     *
      * @param view The WebView that is initiating the callback.
      * @param url The url of the page.
      */
@@ -70,7 +70,7 @@
     /**
      * Notify the host application that the WebView will load the resource
      * specified by the given url.
-     * 
+     *
      * @param view The WebView that is initiating the callback.
      * @param url The url of the resource the WebView will load.
      */
@@ -102,7 +102,7 @@
      * HTTP redirects. As the host application if it would like to continue
      * trying to load the resource. The default behavior is to send the cancel
      * message.
-     * 
+     *
      * @param view The WebView that is initiating the callback.
      * @param cancelMsg The message to send if the host wants to cancel
      * @param continueMsg The message to send if the host wants to continue
@@ -164,7 +164,7 @@
      * As the host application if the browser should resend data as the
      * requested page was a result of a POST. The default is to not resend the
      * data.
-     * 
+     *
      * @param view The WebView that is initiating the callback.
      * @param dontResend The message to send if the browser should not resend
      * @param resend The message to send if the browser should resend data
@@ -176,7 +176,7 @@
 
     /**
      * Notify the host application to update its visited links database.
-     * 
+     *
      * @param view The WebView that is initiating the callback.
      * @param url The url being visited.
      * @param isReload True if this url is being reloaded.
@@ -186,12 +186,12 @@
     }
 
     /**
-     * Notify the host application to handle a ssl certificate error request
+     * Notify the host application to handle a SSL certificate error request
      * (display the error to the user and ask whether to proceed or not). The
      * host application has to call either handler.cancel() or handler.proceed()
      * as the connection is suspended and waiting for the response. The default
      * behavior is to cancel the load.
-     * 
+     *
      * @param view The WebView that is initiating the callback.
      * @param handler An SslErrorHandler object that will handle the user's
      *            response.
@@ -203,9 +203,29 @@
     }
 
     /**
+     * Notify the host application to handle a SSL client certificate
+     * request (display the request to the user and ask whether to
+     * proceed with a client certificate or not). The host application
+     * has to call either handler.cancel() or handler.proceed() as the
+     * connection is suspended and waiting for the response. The
+     * default behavior is to cancel, returning no client certificate.
+     *
+     * @param view The WebView that is initiating the callback.
+     * @param handler An ClientCertRequestHandler object that will
+     *            handle the user's response.
+     * @param host_and_port The host and port of the requesting server.
+     *
+     * @hide
+     */
+    public void onReceivedClientCertRequest(WebView view,
+            ClientCertRequestHandler handler, String host_and_port) {
+        handler.cancel();
+    }
+
+    /**
      * Notify the host application to handle an authentication request. The
      * default behavior is to cancel the request.
-     * 
+     *
      * @param view The WebView that is initiating the callback.
      * @param handler The HttpAuthHandler that will handle the user's response.
      * @param host The host requiring authentication.
@@ -223,7 +243,7 @@
      * true, WebView will not handle the key event. If return false, WebView
      * will always handle the key event, so none of the super in the view chain
      * will see the key event. The default behavior returns false.
-     * 
+     *
      * @param view The WebView that is initiating the callback.
      * @param event The key event.
      * @return True if the host application wants to handle the key event
@@ -239,7 +259,7 @@
      * or if shouldOverrideKeyEvent returns true. This is called asynchronously
      * from where the key is dispatched. It gives the host application an chance
      * to handle the unhandled key events.
-     * 
+     *
      * @param view The WebView that is initiating the callback.
      * @param event The key event.
      */
@@ -249,7 +269,7 @@
     /**
      * Notify the host application that the scale applied to the WebView has
      * changed.
-     * 
+     *
      * @param view he WebView that is initiating the callback.
      * @param oldScale The old scale factor
      * @param newScale The new scale factor
diff --git a/core/java/android/webkit/WebViewCore.java b/core/java/android/webkit/WebViewCore.java
index 13a9793..06a61bd 100644
--- a/core/java/android/webkit/WebViewCore.java
+++ b/core/java/android/webkit/WebViewCore.java
@@ -1141,16 +1141,13 @@
                             if (baseUrl != null) {
                                 int i = baseUrl.indexOf(':');
                                 if (i > 0) {
-                                    /*
-                                     * In 1.0, {@link
-                                     * WebView#loadDataWithBaseURL} can access
-                                     * local asset files as long as the data is
-                                     * valid. In the new WebKit, the restriction
-                                     * is tightened. To be compatible with 1.0,
-                                     * we automatically add the scheme of the
-                                     * baseUrl for local access as long as it is
-                                     * not http(s)/ftp(s)/about/javascript
-                                     */
+                                    // In 1.0, WebView.loadDataWithBaseURL() could access local
+                                    // asset files using 'file' scheme URLs as long as the data is
+                                    // valid. Later versions of WebKit have tightened the
+                                    // restriction around when pages can access such local URLs.
+                                    // To maintain compatibility with 1.0, we register the scheme of
+                                    // the baseUrl to be considered local, as long as it is not
+                                    // http(s)/ftp(s)/about/javascript.
                                     String scheme = baseUrl.substring(0, i);
                                     if (!scheme.startsWith("http") &&
                                             !scheme.startsWith("ftp") &&
@@ -1903,7 +1900,7 @@
                 width = mViewportWidth;
             } else {
                 // For mobile web site.
-                width = viewWidth;
+                width = Math.round(mWebView.getViewWidth() / mWebView.getDefaultZoomScale());
             }
         }
         return width;
@@ -2623,14 +2620,15 @@
 
     // called by JNI. PluginWidget function to launch a full-screen view using a
     // View object provided by the plugin class.
-    private void showFullScreenPlugin(ViewManager.ChildView childView, int npp) {
+    private void showFullScreenPlugin(ViewManager.ChildView childView, int orientation, int npp) {
         if (mWebView == null) {
             return;
         }
 
         Message message = mWebView.mPrivateHandler.obtainMessage(WebView.SHOW_FULLSCREEN);
         message.obj = childView.mView;
-        message.arg1 = npp;
+        message.arg1 = orientation;
+        message.arg2 = npp;
         message.sendToTarget();
     }
 
diff --git a/core/java/android/webkit/ZoomManager.java b/core/java/android/webkit/ZoomManager.java
index e41dd1c..883656b 100644
--- a/core/java/android/webkit/ZoomManager.java
+++ b/core/java/android/webkit/ZoomManager.java
@@ -634,8 +634,17 @@
         } else {
             newTextWrapScale = mActualScale;
         }
+        final boolean firstTimeReflow = !exceedsMinScaleIncrement(mActualScale, mTextWrapScale);
+        if (firstTimeReflow || mInZoomOverview) {
+            // In case first time reflow or in zoom overview mode, let reflow and zoom
+            // happen at the same time.
+            mTextWrapScale = newTextWrapScale;
+        }
         if (settings.isNarrowColumnLayout()
-                && exceedsMinScaleIncrement(mTextWrapScale, newTextWrapScale)) {
+                && exceedsMinScaleIncrement(mTextWrapScale, newTextWrapScale)
+                && !firstTimeReflow
+                && !mInZoomOverview) {
+            // Reflow only.
             mTextWrapScale = newTextWrapScale;
             refreshZoomScale(true);
         } else if (!mInZoomOverview && willScaleTriggerZoom(getZoomOverviewScale())) {
@@ -906,7 +915,7 @@
         // scaleAll(), we need to post a Runnable to ensure requestLayout().
         // Additionally, only update the text wrap scale if the width changed.
         mWebView.post(new PostScale(w != ow &&
-            !mWebView.getSettings().getUseFixedViewport(), mInZoomOverview));
+            !mWebView.getSettings().getUseFixedViewport(), mInZoomOverview, w < ow));
     }
 
     private class PostScale implements Runnable {
@@ -915,10 +924,14 @@
         // it could be changed between the time this callback is initiated and
         // the time it's actually run.
         final boolean mInZoomOverviewBeforeSizeChange;
+        final boolean mInPortraitMode;
 
-        public PostScale(boolean updateTextWrap, boolean inZoomOverview) {
+        public PostScale(boolean updateTextWrap,
+                         boolean inZoomOverview,
+                         boolean inPortraitMode) {
             mUpdateTextWrap = updateTextWrap;
             mInZoomOverviewBeforeSizeChange = inZoomOverview;
+            mInPortraitMode = inPortraitMode;
         }
 
         public void run() {
@@ -927,10 +940,10 @@
                 // still want to send the notification over to webkit.
                 // Keep overview mode unchanged when rotating.
                 float newScale = mActualScale;
-                if (mWebView.getSettings().getUseWideViewPort()) {
-                    final float zoomOverviewScale = getZoomOverviewScale();
-                    newScale = (mInZoomOverviewBeforeSizeChange) ?
-                        zoomOverviewScale : Math.max(mActualScale, zoomOverviewScale);
+                if (mWebView.getSettings().getUseWideViewPort() &&
+                    mInPortraitMode &&
+                    mInZoomOverviewBeforeSizeChange) {
+                    newScale = getZoomOverviewScale();
                 }
                 setZoomScale(newScale, mUpdateTextWrap, true);
                 // update the zoom buttons as the scale can be changed
@@ -978,16 +991,16 @@
             settings.getUseFixedViewport() &&
             (mInitialZoomOverview || mInZoomOverview)) {
             // Keep mobile site's text wrap scale unchanged.  For mobile sites,
-            // the text wrap scale is the same as zoom overview scale, which is 1.0f.
-            if (exceedsMinScaleIncrement(mTextWrapScale, 1.0f) ||
-                    exceedsMinScaleIncrement(newZoomOverviewScale, 1.0f)) {
+            // the text wrap scale is the same as zoom overview scale.
+            if (exceedsMinScaleIncrement(mTextWrapScale, mDefaultScale) ||
+                    exceedsMinScaleIncrement(newZoomOverviewScale, mDefaultScale)) {
                 mTextWrapScale = getReadingLevelScale();
             } else {
                 mTextWrapScale = newZoomOverviewScale;
             }
         }
 
-        if (!mMinZoomScaleFixed) {
+        if (!mMinZoomScaleFixed || settings.getUseWideViewPort()) {
             mMinZoomScale = newZoomOverviewScale;
             mMaxZoomScale = Math.max(mMaxZoomScale, mMinZoomScale);
         }
@@ -1000,10 +1013,11 @@
         // Make sure mobile sites are correctly handled since mobile site will
         // change content width after rotating.
         boolean mobileSiteInOverview = mInZoomOverview &&
-                !exceedsMinScaleIncrement(newZoomOverviewScale, 1.0f);
+                !exceedsMinScaleIncrement(newZoomOverviewScale, mDefaultScale);
         if (!mWebView.drawHistory() &&
-                (mInitialZoomOverview || scaleLessThanOverview || mobileSiteInOverview) &&
-                scaleHasDiff && zoomOverviewWidthChanged) {
+            ((scaleLessThanOverview && settings.getUseWideViewPort())||
+                ((mInitialZoomOverview || mobileSiteInOverview) &&
+                    scaleHasDiff && zoomOverviewWidthChanged))) {
             mInitialZoomOverview = false;
             setZoomScale(newZoomOverviewScale, !willScaleTriggerZoom(mTextWrapScale) &&
                 !mWebView.getSettings().getUseFixedViewport());
@@ -1057,7 +1071,8 @@
         updateZoomRange(viewState, viewSize.x, drawData.mMinPrefWidth);
         setupZoomOverviewWidth(drawData, mWebView.getViewWidth());
         final float overviewScale = getZoomOverviewScale();
-        if (!mMinZoomScaleFixed) {
+        WebSettings settings = mWebView.getSettings();
+        if (!mMinZoomScaleFixed || settings.getUseWideViewPort()) {
             mMinZoomScale = (mInitialScale > 0) ?
                     Math.min(mInitialScale, overviewScale) : overviewScale;
             mMaxZoomScale = Math.max(mMaxZoomScale, mMinZoomScale);
@@ -1065,8 +1080,6 @@
 
         if (!mWebView.drawHistory()) {
             float scale;
-            WebSettings settings = mWebView.getSettings();
-
             if (mInitialScale > 0) {
                 scale = mInitialScale;
             } else if (viewState.mViewScale > 0) {
diff --git a/core/java/android/widget/AbsListView.java b/core/java/android/widget/AbsListView.java
index 680bb7d..3fe8149 100644
--- a/core/java/android/widget/AbsListView.java
+++ b/core/java/android/widget/AbsListView.java
@@ -55,7 +55,6 @@
 import android.view.ViewDebug;
 import android.view.ViewGroup;
 import android.view.ViewTreeObserver;
-import android.view.accessibility.AccessibilityEvent;
 import android.view.inputmethod.BaseInputConnection;
 import android.view.inputmethod.EditorInfo;
 import android.view.inputmethod.InputConnection;
@@ -4661,6 +4660,7 @@
         selectedPos = lookForSelectablePosition(selectedPos, down);
         if (selectedPos >= firstPosition && selectedPos <= getLastVisiblePosition()) {
             mLayoutMode = LAYOUT_SPECIFIC;
+            updateSelectorState();
             setSelectionInt(selectedPos);
             invokeOnItemScrollListener();
         } else {
diff --git a/core/java/android/widget/AdapterView.java b/core/java/android/widget/AdapterView.java
index c4d05e9..755d4e0 100644
--- a/core/java/android/widget/AdapterView.java
+++ b/core/java/android/widget/AdapterView.java
@@ -904,8 +904,10 @@
     public boolean onRequestSendAccessibilityEvent(View child, AccessibilityEvent event) {
         // Add a record for ourselves as well.
         AccessibilityEvent record = AccessibilityEvent.obtain();
+        record.setSource(this);
         // Set the class since it is not populated in #dispatchPopulateAccessibilityEvent
         record.setClassName(getClass().getName());
+        child.onInitializeAccessibilityEvent(record);
         child.dispatchPopulateAccessibilityEvent(record);
         event.appendRecord(record);
         return true;
diff --git a/core/java/android/widget/AppSecurityPermissions.java b/core/java/android/widget/AppSecurityPermissions.java
index d3aa42f..988760d 100755
--- a/core/java/android/widget/AppSecurityPermissions.java
+++ b/core/java/android/widget/AppSecurityPermissions.java
@@ -218,15 +218,14 @@
         mShowMore.setClickable(true);
         mShowMore.setOnClickListener(this);
         mShowMore.setFocusable(true);
-        mShowMore.setBackgroundResource(android.R.drawable.list_selector_background);
 
         // Pick up from framework resources instead.
         mDefaultGrpLabel = mContext.getString(R.string.default_permission_group);
         mPermFormat = mContext.getString(R.string.permissions_format);
         mNormalIcon = mContext.getResources().getDrawable(R.drawable.ic_text_dot);
         mDangerousIcon = mContext.getResources().getDrawable(R.drawable.ic_bullet_key_permission);
-        mShowMaxIcon = mContext.getResources().getDrawable(R.drawable.expander_ic_maximized);
-        mShowMinIcon = mContext.getResources().getDrawable(R.drawable.expander_ic_minimized);
+        mShowMaxIcon = mContext.getResources().getDrawable(R.drawable.expander_close_holo_dark);
+        mShowMinIcon = mContext.getResources().getDrawable(R.drawable.expander_open_holo_dark);
         
         // Set permissions view
         setPermissions(mPermsList);
diff --git a/core/java/android/widget/CompoundButton.java b/core/java/android/widget/CompoundButton.java
index a730018..2410eb2 100644
--- a/core/java/android/widget/CompoundButton.java
+++ b/core/java/android/widget/CompoundButton.java
@@ -28,6 +28,7 @@
 import android.view.Gravity;
 import android.view.ViewDebug;
 import android.view.accessibility.AccessibilityEvent;
+import android.view.accessibility.AccessibilityNodeInfo;
 
 /**
  * <p>
@@ -214,6 +215,12 @@
     }
 
     @Override
+    public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
+        super.onInitializeAccessibilityNodeInfo(info);
+        info.setChecked(mChecked);
+    }
+
+    @Override
     protected void onDraw(Canvas canvas) {
         super.onDraw(canvas);
 
diff --git a/core/java/android/widget/FastScroller.java b/core/java/android/widget/FastScroller.java
index fb57ce0..00ebe0d 100644
--- a/core/java/android/widget/FastScroller.java
+++ b/core/java/android/widget/FastScroller.java
@@ -468,7 +468,9 @@
                 mListAdapter = (BaseAdapter) adapter;
                 mSectionIndexer = (SectionIndexer) adapter;
                 mSections = mSectionIndexer.getSections();
-                
+                if (mSections == null) {
+                    mSections = new String[] { " " };
+                }
             } else {
                 mListAdapter = (BaseAdapter) adapter;
                 mSections = new String[] { " " };
@@ -609,7 +611,7 @@
         final int section = mSectionIndexer.getSectionForPosition(firstVisibleItem);
         final int sectionPos = mSectionIndexer.getPositionForSection(section);
         final int nextSectionPos = mSectionIndexer.getPositionForSection(section + 1);
-        final int sectionCount = mSectionIndexer.getSections().length;
+        final int sectionCount = mSections.length;
         final int positionsInSection = nextSectionPos - sectionPos;
 
         final View child = mList.getChildAt(0);
diff --git a/core/java/android/widget/FrameLayout.java b/core/java/android/widget/FrameLayout.java
index 2a1398d..5eba1a0 100644
--- a/core/java/android/widget/FrameLayout.java
+++ b/core/java/android/widget/FrameLayout.java
@@ -16,6 +16,8 @@
 
 package android.widget;
 
+import java.util.ArrayList;
+
 import android.content.Context;
 import android.content.res.TypedArray;
 import android.graphics.Canvas;
@@ -23,14 +25,12 @@
 import android.graphics.Region;
 import android.graphics.drawable.Drawable;
 import android.util.AttributeSet;
+import android.view.Gravity;
 import android.view.View;
 import android.view.ViewDebug;
 import android.view.ViewGroup;
-import android.view.Gravity;
 import android.widget.RemoteViews.RemoteView;
 
-import java.util.ArrayList;
-
 
 /**
  * FrameLayout is designed to block out an area on the screen to display
@@ -115,7 +115,7 @@
     }
 
     /**
-     * Describes how the foreground is positioned. Defaults to BEFORE and TOP.
+     * Describes how the foreground is positioned. Defaults to START and TOP.
      *
      * @param foregroundGravity See {@link android.view.Gravity}
      *
@@ -125,7 +125,7 @@
     public void setForegroundGravity(int foregroundGravity) {
         if (mForegroundGravity != foregroundGravity) {
             if ((foregroundGravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) == 0) {
-                foregroundGravity |= Gravity.BEFORE;
+                foregroundGravity |= Gravity.START;
             }
 
             if ((foregroundGravity & Gravity.VERTICAL_GRAVITY_MASK) == 0) {
@@ -364,10 +364,11 @@
                     gravity = DEFAULT_CHILD_GRAVITY;
                 }
 
-                final int horizontalGravity = Gravity.getAbsoluteGravity(gravity, isLayoutRtl());
+                final int layoutDirection = getResolvedLayoutDirection();
+                final int absoluteGravity = Gravity.getAbsoluteGravity(gravity, layoutDirection);
                 final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
 
-                switch (horizontalGravity) {
+                switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
                     case Gravity.LEFT:
                         childLeft = parentLeft + lp.leftMargin;
                         break;
@@ -435,8 +436,10 @@
                     selfBounds.set(mPaddingLeft, mPaddingTop, w - mPaddingRight, h - mPaddingBottom);
                 }
 
+                final int layoutDirection = getResolvedLayoutDirection();
                 Gravity.apply(mForegroundGravity, foreground.getIntrinsicWidth(),
-                        foreground.getIntrinsicHeight(), selfBounds, overlayBounds, isLayoutRtl());
+                        foreground.getIntrinsicHeight(), selfBounds, overlayBounds,
+                        layoutDirection);
                 foreground.setBounds(overlayBounds);
             }
             
diff --git a/core/java/android/widget/GridLayout.java b/core/java/android/widget/GridLayout.java
index 4889101..46e4398 100644
--- a/core/java/android/widget/GridLayout.java
+++ b/core/java/android/widget/GridLayout.java
@@ -46,11 +46,11 @@
  * <p>
  * The grid is composed of a set of infinitely thin lines that separate the
  * viewing area into <em>cells</em>. Throughout the API, grid lines are referenced
- * by grid <em>indices</em>. A grid that has <code>N</code> columns
- * has <code>N + 1</code> grid indices that run from <code>0</code>
- * through <code>N</code> inclusive. Regardless of how GridLayout is
- * configured, grid index <code>0</code> is fixed to the leading edge of the
- * container and grid index <code>N</code> is fixed to its trailing edge
+ * by grid <em>indices</em>. A grid with {@code N} columns
+ * has {@code N + 1} grid indices that run from {@code 0}
+ * through {@code N} inclusive. Regardless of how GridLayout is
+ * configured, grid index {@code 0} is fixed to the leading edge of the
+ * container and grid index {@code N} is fixed to its trailing edge
  * (after padding is taken into account).
  *
  * <h4>Row and Column Groups</h4>
@@ -116,17 +116,61 @@
      * The horizontal orientation.
      */
     public static final int HORIZONTAL = LinearLayout.HORIZONTAL;
+
     /**
      * The vertical orientation.
      */
     public static final int VERTICAL = LinearLayout.VERTICAL;
 
+    /**
+     * The constant used to indicate that a value is undefined.
+     * Fields can use this value to indicate that their values
+     * have not yet been set. Similarly, methods can return this value
+     * to indicate that there is no suitable value that the implementation
+     * can return.
+     * The value used for the constant (currently {@link Integer#MIN_VALUE}) is
+     * intended to avoid confusion between valid values whose sign may not be known.
+     */
+    public static final int UNDEFINED = Integer.MIN_VALUE;
+
+    /**
+     * This constant is an {@link #setAlignmentMode(int) alignmentMode}.
+     * When the {@code alignmentMode} is set to {@link #ALIGN_BOUNDS}, alignment
+     * is made between the edges of each component's raw
+     * view boundary: i.e. the area delimited by the component's:
+     * {@link android.view.View#getTop() top},
+     * {@link android.view.View#getLeft() left},
+     * {@link android.view.View#getBottom() bottom} and
+     * {@link android.view.View#getRight() right} properties.
+     * <p>
+     * For example, when {@code GridLayout} is in {@link #ALIGN_BOUNDS} mode,
+     * children that belong to a row group that uses {@link #TOP} alignment will
+     * all return the same value when their {@link android.view.View#getTop()}
+     * method is called.
+     *
+     * @see #setAlignmentMode(int)
+     */
+    public static final int ALIGN_BOUNDS = 0;
+
+    /**
+     * This constant is an {@link #setAlignmentMode(int) alignmentMode}.
+     * When the {@code alignmentMode} is set to {@link #ALIGN_MARGINS},
+     * the bounds of each view are extended outwards, according
+     * to their margins, before the edges of the resulting rectangle are aligned.
+     * <p>
+     * For example, when {@code GridLayout} is in {@link #ALIGN_MARGINS} mode,
+     * the quantity {@code top - layoutParams.topMargin} is the same for all children that
+     * belong to a row group that uses {@link #TOP} alignment.
+     *
+     * @see #setAlignmentMode(int)
+     */
+    public static final int ALIGN_MARGINS = 1;
+
     // Misc constants
 
     private static final String TAG = GridLayout.class.getName();
     private static final boolean DEBUG = false;
-    private static final int UNDEFINED = Integer.MIN_VALUE;
-    private static final Paint GRID_PAINT = new Paint();
+    private static Paint GRID_PAINT;
     private static final double GOLDEN_RATIO = (1 + Math.sqrt(5)) / 2;
     private static final int MIN = 0;
     private static final int PRF = 1;
@@ -138,6 +182,9 @@
     private static final int DEFAULT_COUNT = UNDEFINED;
     private static final boolean DEFAULT_USE_DEFAULT_MARGINS = false;
     private static final boolean DEFAULT_ORDER_PRESERVED = false;
+    private static final int DEFAULT_ALIGNMENT_MODE = ALIGN_MARGINS;
+    // todo remove this
+    private static final int DEFAULT_CONTAINER_MARGIN = 20;
 
     // TypedArray indices
 
@@ -145,9 +192,19 @@
     private static final int ROW_COUNT = styleable.GridLayout_rowCount;
     private static final int COLUMN_COUNT = styleable.GridLayout_columnCount;
     private static final int USE_DEFAULT_MARGINS = styleable.GridLayout_useDefaultMargins;
+    private static final int ALIGNMENT_MODE = styleable.GridLayout_alignmentMode;
     private static final int ROW_ORDER_PRESERVED = styleable.GridLayout_rowOrderPreserved;
     private static final int COLUMN_ORDER_PRESERVED = styleable.GridLayout_columnOrderPreserved;
 
+    // Static initialization
+
+    static {
+        if (DEBUG) {
+            GRID_PAINT = new Paint();
+            GRID_PAINT.setColor(Color.argb(50, 255, 255, 255));
+        }
+    }
+
     // Instance variables
 
     private final Axis mHorizontalAxis = new Axis(true);
@@ -155,9 +212,10 @@
     private boolean mLayoutParamsValid = false;
     private int mOrientation = DEFAULT_ORIENTATION;
     private boolean mUseDefaultMargins = DEFAULT_USE_DEFAULT_MARGINS;
+    private int mAlignmentMode = DEFAULT_ALIGNMENT_MODE;
     private int mDefaultGravity = Gravity.NO_GRAVITY;
-    boolean maximizing = false;
-    boolean accommodateBothMinAndMax = false;
+
+    /* package */ boolean accommodateBothMinAndMax = false;
 
     // Constructors
 
@@ -165,10 +223,7 @@
      * {@inheritDoc}
      */
     public GridLayout(Context context) {
-        super(context);
-        if (DEBUG) {
-            setWillNotDraw(false);
-        }
+        this(context, null, 0);
     }
 
     /**
@@ -176,6 +231,9 @@
      */
     public GridLayout(Context context, AttributeSet attrs, int defStyle) {
         super(context, attrs, defStyle);
+        if (DEBUG) {
+            setWillNotDraw(false);
+        }
         processAttributes(context, attrs);
     }
 
@@ -183,17 +241,17 @@
      * {@inheritDoc}
      */
     public GridLayout(Context context, AttributeSet attrs) {
-        super(context, attrs);
-        processAttributes(context, attrs);
+        this(context, attrs, 0);
     }
 
     private void processAttributes(Context context, AttributeSet attrs) {
         TypedArray a = context.obtainStyledAttributes(attrs, styleable.GridLayout);
         try {
-            setRowCount(a.getInteger(ROW_COUNT, DEFAULT_COUNT));
-            setColumnCount(a.getInteger(COLUMN_COUNT, DEFAULT_COUNT));
-            mOrientation = a.getInteger(ORIENTATION, DEFAULT_ORIENTATION);
+            setRowCount(a.getInt(ROW_COUNT, DEFAULT_COUNT));
+            setColumnCount(a.getInt(COLUMN_COUNT, DEFAULT_COUNT));
+            mOrientation = a.getInt(ORIENTATION, DEFAULT_ORIENTATION);
             mUseDefaultMargins = a.getBoolean(USE_DEFAULT_MARGINS, DEFAULT_USE_DEFAULT_MARGINS);
+            mAlignmentMode = a.getInt(ALIGNMENT_MODE, DEFAULT_ALIGNMENT_MODE);
             setRowOrderPreserved(a.getBoolean(ROW_ORDER_PRESERVED, DEFAULT_ORDER_PRESERVED));
             setColumnOrderPreserved(a.getBoolean(COLUMN_ORDER_PRESERVED, DEFAULT_ORDER_PRESERVED));
         } finally {
@@ -206,8 +264,7 @@
     /**
      * Returns the current orientation.
      *
-     * @return either {@link #HORIZONTAL} or {@link #VERTICAL}. The default
-     * is {@link #HORIZONTAL}.
+     * @return either {@link #HORIZONTAL} or {@link #VERTICAL}
      *
      * @see #setOrientation(int)
      *
@@ -221,8 +278,10 @@
      * The orientation property does not affect layout. Orientation is used
      * only to generate default row/column indices when they are not specified
      * by a component's layout parameters.
+     * <p>
+     * The default value of this property is {@link #HORIZONTAL}.
      *
-     * @param orientation the orientation, either {@link #HORIZONTAL} or {@link #VERTICAL}.
+     * @param orientation either {@link #HORIZONTAL} or {@link #VERTICAL}
      *
      * @see #getOrientation()
      *
@@ -256,7 +315,7 @@
      * only to generate default row/column indices when they are not specified
      * by a component's layout parameters.
      *
-     * @param rowCount the number of rows.
+     * @param rowCount the number of rows
      *
      * @see #getRowCount()
      * @see LayoutParams#rowGroup
@@ -303,7 +362,7 @@
      * Returns whether or not this GridLayout will allocate default margins when no
      * corresponding layout parameters are defined.
      *
-     * @return true if default margins should be allocated.
+     * @return {@code true} if default margins should be allocated
      *
      * @see #setUseDefaultMargins(boolean)
      *
@@ -314,16 +373,23 @@
     }
 
     /**
-     * When true, GridLayout allocates default margins around children
+     * When {@code true}, GridLayout allocates default margins around children
      * based on the child's visual characteristics. Each of the
      * margins so defined may be independently overridden by an assignment
      * to the appropriate layout parameter.
      * <p>
-     * When false, the default value of all margins is zero.
+     * When {@code false}, the default value of all margins is zero.
+     * <p>
+     * When setting to {@code true}, consider setting the value of the
+     * {@link #setAlignmentMode(int) alignmentMode}
+     * property to {@link #ALIGN_BOUNDS}.
+     * <p>
+     * The default value of this property is {@code false}.
      *
-     * @param useDefaultMargins use true to make GridLayout allocate default margins
+     * @param useDefaultMargins use {@code true} to make GridLayout allocate default margins
      *
      * @see #getUseDefaultMargins()
+     * @see #setAlignmentMode(int)
      *
      * @see MarginLayoutParams#leftMargin
      * @see MarginLayoutParams#topMargin
@@ -334,13 +400,50 @@
      */
     public void setUseDefaultMargins(boolean useDefaultMargins) {
         mUseDefaultMargins = useDefaultMargins;
+        requestLayout();
+    }
+
+    /**
+     * Returns the alignment mode.
+     *
+     * @return the alignment mode; either {@link #ALIGN_BOUNDS} or {@link #ALIGN_MARGINS}
+     *
+     * @see #ALIGN_BOUNDS
+     * @see #ALIGN_MARGINS
+     *
+     * @see #setAlignmentMode(int)
+     *
+     * @attr ref android.R.styleable#GridLayout_alignmentMode
+     */
+    public int getAlignmentMode() {
+        return mAlignmentMode;
+    }
+
+    /**
+     * Sets the alignment mode to be used for all of the alignments between the
+     * children of this container.
+     * <p>
+     * The default value of this property is {@link #ALIGN_MARGINS}.
+     *
+     * @param alignmentMode either {@link #ALIGN_BOUNDS} or {@link #ALIGN_MARGINS}
+     *
+     * @see #ALIGN_BOUNDS
+     * @see #ALIGN_MARGINS
+     *
+     * @see #getAlignmentMode()
+     *
+     * @attr ref android.R.styleable#GridLayout_alignmentMode
+     */
+    public void setAlignmentMode(int alignmentMode) {
+        mAlignmentMode = alignmentMode;
+        requestLayout();
     }
 
     /**
      * Returns whether or not row boundaries are ordered by their grid indices.
      *
-     * @return true if row boundaries must appear in the order of their indices, false otherwise.
-     *         The default is false.
+     * @return {@code true} if row boundaries must appear in the order of their indices,
+     *         {@code false} otherwise
      *
      * @see #setRowOrderPreserved(boolean)
      *
@@ -351,25 +454,25 @@
     }
 
     /**
-     * When this property is <code>false</code>, the default state, GridLayout
+     * When this property is {@code false}, the default state, GridLayout
      * is at liberty to choose an order that better suits the heights of its children.
-       <p>
-     * When this property is <code>true</code>, GridLayout is forced to place row boundaries
-     * (the {@link Interval#min min} and {@link Interval#max max} values of
-     * a {@link LayoutParams#rowGroup rowGroup}'s {@link Group#span span})
-     * so that they appear in ascending order in the view.
+     <p>
+     * When this property is {@code true}, GridLayout is forced to place the row boundaries
+     * so that their associated grid indices are in ascending order in the view.
      * <p>
      * GridLayout implements this specification by creating ordering constraints between
      * the variables that represent the locations of the row boundaries.
      *
-     * When this property is <code>true</code>, constraints are added for each pair of consecutive
-     * indices: i.e. between row boundaries: <code>[0..1], [1..2], [3..4],...</code> etc.
+     * When this property is {@code true}, constraints are added for each pair of consecutive
+     * indices: i.e. between row boundaries: {@code [0..1], [1..2], [2..3],...} etc.
      *
-     * When the property is <code>false</code>, the ordering constraints are placed
+     * When the property is {@code false}, the ordering constraints are placed
      * only between boundaries that separate opposing edges of the layout's children.
-     *
-     * @param rowOrderPreserved use true to force GridLayout to respect the order
-     *        of row boundaries.
+     * <p>
+     * The default value of this property is {@code false}.
+
+     * @param rowOrderPreserved {@code true} to force GridLayout to respect the order
+     *        of row boundaries
      *
      * @see #isRowOrderPreserved()
      *
@@ -377,13 +480,15 @@
      */
     public void setRowOrderPreserved(boolean rowOrderPreserved) {
         mVerticalAxis.setOrderPreserved(rowOrderPreserved);
+        invalidateStructure();
+        requestLayout();
     }
 
     /**
      * Returns whether or not column boundaries are ordered by their grid indices.
      *
-     * @return true if column boundaries must appear in the order of their indices, false otherwise.
-     *         The default is false.
+     * @return {@code true} if column boundaries must appear in the order of their indices,
+     *         {@code false} otherwise
      *
      * @see #setColumnOrderPreserved(boolean)
      *
@@ -394,24 +499,24 @@
     }
 
     /**
-     * When this property is <code>false</code>, the default state, GridLayout
+     * When this property is {@code false}, the default state, GridLayout
      * is at liberty to choose an order that better suits the widths of its children.
-       <p>
-     * When this property is <code>true</code>, GridLayout is forced to place column boundaries
-     * (the {@link Interval#min min} and {@link Interval#max max} values of
-     * a {@link LayoutParams#columnGroup columnGroup}'s {@link Group#span span})
-     * so that they appear in ascending order in the view.
+     <p>
+     * When this property is {@code true}, GridLayout is forced to place the column boundaries
+     * so that their associated grid indices are in ascending order in the view.
      * <p>
      * GridLayout implements this specification by creating ordering constraints between
      * the variables that represent the locations of the column boundaries.
      *
-     * When this property is <code>true</code>, constraints are added for each pair of consecutive
-     * indices: i.e. between column boundaries: <code>[0..1], [1..2], [3..4],...</code> etc.
+     * When this property is {@code true}, constraints are added for each pair of consecutive
+     * indices: i.e. between column boundaries: {@code [0..1], [1..2], [2..3],...} etc.
      *
-     * When the property is <code>false</code>, the ordering constraints are placed
+     * When the property is {@code false}, the ordering constraints are placed
      * only between boundaries that separate opposing edges of the layout's children.
+     * <p>
+     * The default value of this property is {@code false}.
      *
-     * @param columnOrderPreserved use true to force GridLayout to respect the order
+     * @param columnOrderPreserved use {@code true} to force GridLayout to respect the order
      *        of column boundaries.
      *
      * @see #isColumnOrderPreserved()
@@ -420,13 +525,19 @@
      */
     public void setColumnOrderPreserved(boolean columnOrderPreserved) {
         mHorizontalAxis.setOrderPreserved(columnOrderPreserved);
+        invalidateStructure();
+        requestLayout();
     }
 
-    private static int compare(int i, int j) {
-        return i < j ? -1 : i > j ? 1 : 0;
+    private static int max2(int[] a, int valueIfEmpty) {
+        int result = valueIfEmpty;
+        for (int i = 0, N = a.length; i < N; i++) {
+            result = Math.max(result, a[i]);
+        }
+        return result;
     }
 
-    private static int sum(int[] a) {
+    private static int sum(float[] a) {
         int result = 0;
         for (int i = 0, length = a.length; i < length; i++) {
             result += a[i];
@@ -440,13 +551,12 @@
         // gaps are in the proportion of the golden ratio.
         // To effect this with equal margins at each edge, set each of the
         // four margin values to half this amount.
-        c.measure(0, 0);
         return (int) (c.getMeasuredHeight() / GOLDEN_RATIO / 2);
     }
 
     private int getDefaultMargin(View c, boolean isAtEdge, boolean leading, boolean horizontal) {
-        // todo remove 20 - use padding here?
-        return isAtEdge ? 20 : getDefaultMargin(c, leading, horizontal);
+        // todo remove DEFAULT_CONTAINER_MARGIN. Use padding? Seek advice on Themes/Styles, etc.
+        return isAtEdge ? DEFAULT_CONTAINER_MARGIN : getDefaultMargin(c, leading, horizontal);
     }
 
     private int getDefaultMarginValue(View c, LayoutParams p, boolean leading, boolean horizontal) {
@@ -456,7 +566,7 @@
         Group group = horizontal ? p.columnGroup : p.rowGroup;
         Axis axis = horizontal ? mHorizontalAxis : mVerticalAxis;
         Interval span = group.span;
-        boolean isAtEdge = leading ? span.min == 0 : span.max == axis.getCount();
+        boolean isAtEdge = leading ? (span.min == 0) : (span.max == axis.getCount());
 
         return getDefaultMargin(c, isAtEdge, leading, horizontal);
     }
@@ -464,89 +574,98 @@
     private int getMargin(View view, boolean leading, boolean horizontal) {
         LayoutParams lp = getLayoutParams(view);
         int margin = horizontal ?
-                leading ? lp.leftMargin : lp.rightMargin :
-                leading ? lp.topMargin : lp.bottomMargin;
+                (leading ? lp.leftMargin : lp.rightMargin) :
+                (leading ? lp.topMargin : lp.bottomMargin);
         return margin == UNDEFINED ? getDefaultMarginValue(view, lp, leading, horizontal) : margin;
     }
 
-    private static boolean isUndefined(Interval span) {
-        return span.min == UNDEFINED || span.max == UNDEFINED;
+    private static int valueIfDefined(int value, int defaultValue) {
+        return (value != UNDEFINED) ? value : defaultValue;
     }
 
+    // install default indices for cells that don't define them
     private void validateLayoutParams() {
-        // install default indices for cells if *none* are defined
-        if (mHorizontalAxis.maxIndex1() == UNDEFINED || mVerticalAxis.maxIndex1() == UNDEFINED) {
-            boolean horizontal = mOrientation == HORIZONTAL;
-            int count = horizontal ? mHorizontalAxis.count : mVerticalAxis.count;
-            if (count == UNDEFINED) {
-                count = Integer.MAX_VALUE;
-            }
-            int x = 0;
-            int y = 0;
-            int maxSize = 0;
-            for (int i = 0, size = getChildCount(); i < size; i++) {
-                LayoutParams lp = getLayoutParams1(getChildAt(i));
+        new Object() {
+            public int maxSize = 0;
 
-                Interval hSpan = lp.columnGroup.span;
-                int cellWidth = hSpan.size();
-
-                Interval vSpan = lp.rowGroup.span;
-                int cellHeight = vSpan.size();
-
-                if (horizontal) {
-                    if (x + cellWidth > count) {
-                        x = 0;
-                        y += maxSize;
-                        maxSize = 0;
-                    }
+            private int valueIfDefined2(int value, int defaultValue) {
+                if (value != UNDEFINED) {
+                    maxSize = 0;
+                    return value;
                 } else {
-                    if (y + cellHeight > count) {
-                        y = 0;
-                        x += maxSize;
-                        maxSize = 0;
+                    return defaultValue;
+                }
+            }
+
+            {
+                final boolean horizontal = (mOrientation == HORIZONTAL);
+                final int axis = horizontal ? mHorizontalAxis.count : mVerticalAxis.count;
+                final int count = valueIfDefined(axis, Integer.MAX_VALUE);
+
+                int row = 0;
+                int col = 0;
+                for (int i = 0, N = getChildCount(); i < N; i++) {
+                    LayoutParams lp = getLayoutParams1(getChildAt(i));
+
+                    Group colGroup = lp.columnGroup;
+                    Interval cols = colGroup.span;
+                    int colSpan = cols.size();
+
+                    Group rowGroup = lp.rowGroup;
+                    Interval rows = rowGroup.span;
+                    int rowSpan = rows.size();
+
+                    if (horizontal) {
+                        row = valueIfDefined2(rows.min, row);
+
+                        int newCol = valueIfDefined(cols.min, (col + colSpan > count) ? 0 : col);
+                        if (newCol < col) {
+                            row += maxSize;
+                            maxSize = 0;
+                        }
+                        col = newCol;
+                        maxSize = max(maxSize, rowSpan);
+                    } else {
+                        col = valueIfDefined2(cols.min, col);
+
+                        int newRow = valueIfDefined(rows.min, (row + rowSpan > count) ? 0 : row);
+                        if (newRow < row) {
+                            col += maxSize;
+                            maxSize = 0;
+                        }
+                        row = newRow;
+                        maxSize = max(maxSize, colSpan);
+                    }
+
+                    lp.setColumnGroupSpan(new Interval(col, col + colSpan));
+                    lp.setRowGroupSpan(new Interval(row, row + rowSpan));
+
+                    if (horizontal) {
+                        col = col + colSpan;
+                    } else {
+                        row = row + rowSpan;
                     }
                 }
-                lp.setHorizontalGroupSpan(new Interval(x, x + cellWidth));
-                lp.setVerticalGroupSpan(new Interval(y, y + cellHeight));
-
-                if (horizontal) {
-                    x = x + cellWidth;
-                } else {
-                    y = y + cellHeight;
-                }
-                maxSize = max(maxSize, horizontal ? cellHeight : cellWidth);
             }
-        } else {
-            /*
-            At least one row and one column index have been defined.
-            Assume missing row/cols are in error and set them to zero so that
-            they will display top/left and the developer can add the right indices.
-            Without this UNDEFINED would cause ArrayIndexOutOfBoundsException.
-            */
-            for (int i = 0, size = getChildCount(); i < size; i++) {
-                LayoutParams lp = getLayoutParams1(getChildAt(i));
-                if (isUndefined(lp.columnGroup.span)) {
-                    lp.setHorizontalGroupSpan(LayoutParams.DEFAULT_SPAN);
-                }
-                if (isUndefined(lp.rowGroup.span)) {
-                    lp.setVerticalGroupSpan(LayoutParams.DEFAULT_SPAN);
-                }
-            }
-        }
+        };
+        invalidateStructure();
     }
 
     private void invalidateStructure() {
         mLayoutParamsValid = false;
         mHorizontalAxis.invalidateStructure();
         mVerticalAxis.invalidateStructure();
-
         // This can end up being done twice. But better that than not at all.
         invalidateValues();
     }
 
     private void invalidateValues() {
-        mHorizontalAxis.invalidateValues();
-        mVerticalAxis.invalidateValues();
+        // Need null check because requestLayout() is called in View's initializer,
+        // before we are set up.
+        if (mHorizontalAxis != null && mVerticalAxis != null) {
+            mHorizontalAxis.invalidateValues();
+            mVerticalAxis.invalidateValues();
+        }
     }
 
     private LayoutParams getLayoutParams1(View c) {
@@ -605,10 +724,6 @@
         }
     }
 
-    static {
-        GRID_PAINT.setColor(Color.argb(50, 255, 255, 255));
-    }
-
     // Add/remove
 
     @Override
@@ -645,60 +760,61 @@
 
     @Override
     protected void onMeasure(int widthSpec, int heightSpec) {
-        invalidateValues();
-        // int width = MeasureSpec.getSize(widthSpec);
-        // int widthMode = MeasureSpec.getMode(widthSpec);
-        // int height = MeasureSpec.getSize(heightSpec);
-        // int heightMode = MeasureSpec.getMode(heightSpec);
+        measureChildren(widthSpec, heightSpec);
 
-        // todo - handle widthSpec and heightSpec properly
+        int computedWidth = getPaddingLeft() + mHorizontalAxis.getMin() + getPaddingRight();
+        int computedHeight = getPaddingTop() + mVerticalAxis.getMin() + getPaddingBottom();
 
-        int computedWidth = getPaddingLeft() + mHorizontalAxis.getPref() + getPaddingRight();
-        int computedHeight = getPaddingTop() + mVerticalAxis.getPref() + getPaddingBottom();
+        int measuredWidth = Math.max(computedWidth, getSuggestedMinimumWidth());
+        int measuredHeight = Math.max(computedHeight, getSuggestedMinimumHeight());
 
         setMeasuredDimension(
-                resolveSizeAndState(computedWidth, widthSpec, 0),
-                resolveSizeAndState(computedHeight, heightSpec, 0));
+                resolveSizeAndState(measuredWidth, widthSpec, 0),
+                resolveSizeAndState(measuredHeight, heightSpec, 0));
     }
 
     private int protect(int alignment) {
-        return alignment == UNDEFINED ? 0 : alignment;
-    }
-
-    private int getLocationIncludingMargin(Axis state, int index, boolean leading) {
-        int margin = leading ? state.leadingMargins[index] : -state.trailingMargins[index];
-        return state.locations[index] + margin;
+        return (alignment == UNDEFINED) ? 0 : alignment;
     }
 
     private int getMeasurement(View c, boolean horizontal, int measurementType) {
-        LayoutParams lp = (LayoutParams) c.getLayoutParams();
-        // First check to see if the user has specified the size.
-        // If so, return the specified size.
-        int size = horizontal ? lp.width : lp.height;
-        if (size >= 0) {
-            return size;
-        }
+        return horizontal ? c.getMeasuredWidth() : c.getMeasuredHeight();
+    }
 
-        // measureChild(c, 0, 0);
-        c.measure(0, 0);// todo work out correct order of events for measurement calls
-        int result = horizontal ? c.getMeasuredWidth() : c.getMeasuredHeight();
-
-        float weight = horizontal ? lp.columnWeight : lp.rowWeight;
-        Axis axis = horizontal ? mHorizontalAxis : mVerticalAxis;
-        if (weight != 0) {
-            return result + axis.prefSizeOfWeightedComponent;
+    private int getMeasurementIncludingMargin(View c, boolean horizontal, int measurementType) {
+        int result = getMeasurement(c, horizontal, measurementType);
+        if (mAlignmentMode == ALIGN_MARGINS) {
+            int leadingMargin = getMargin(c, true, horizontal);
+            int trailingMargin = getMargin(c, false, horizontal);
+            return result + leadingMargin + trailingMargin;
         }
         return result;
     }
 
+    @Override
+    public void requestLayout() {
+        super.requestLayout();
+        invalidateValues();
+    }
+
     // Layout container
 
-    @Override
-    protected void onLayout(boolean changed, int l, int t, int r, int b) {
-        invalidateValues();
+    /**
+     * {@inheritDoc}
+     */
+    /*
+     The layout operation is implemented by delegating the heavy lifting to the
+     to the mHorizontalAxis and mVerticalAxis instances of the internal Axis class.
+     Together they compute the locations of the vertical and horizontal lines of
+     the grid (respectively!).
 
-        int targetWidth = r - l;
-        int targetHeight = b - t;
+     This method is then left with the simpler task of applying margins, gravity
+     and sizing to each child view and then placing it in its cell.
+     */
+    @Override
+    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
+        int targetWidth = right - left;
+        int targetHeight = bottom - top;
 
         int paddingLeft = getPaddingLeft();
         int paddingTop = getPaddingTop();
@@ -710,36 +826,68 @@
 
         for (int i = 0, size = getChildCount(); i < size; i++) {
             View view = getChildAt(i);
-            LayoutParams constraints = getLayoutParams(view);
-            Interval hRange = constraints.columnGroup.span;
-            Interval vRange = constraints.rowGroup.span;
+            LayoutParams lp = getLayoutParams(view);
+            Group columnGroup = lp.columnGroup;
+            Group rowGroup = lp.rowGroup;
 
-            int x1 = getLocationIncludingMargin(mHorizontalAxis, hRange.min, true);
-            int y1 = getLocationIncludingMargin(mVerticalAxis, vRange.min, true);
+            Interval colSpan = columnGroup.span;
+            Interval rowSpan = rowGroup.span;
 
-            int x2 = getLocationIncludingMargin(mHorizontalAxis, hRange.max, false);
-            int y2 = getLocationIncludingMargin(mVerticalAxis, vRange.max, false);
+            int x1 = mHorizontalAxis.getLocationIncludingMargin(view, true, colSpan.min);
+            int y1 = mVerticalAxis.getLocationIncludingMargin(view, true, rowSpan.min);
+
+            int x2 = mHorizontalAxis.getLocationIncludingMargin(view, false, colSpan.max);
+            int y2 = mVerticalAxis.getLocationIncludingMargin(view, false, rowSpan.max);
 
             int cellWidth = x2 - x1;
             int cellHeight = y2 - y1;
 
-            Bounds minMaxX = mHorizontalAxis.getGroupBounds().getValue(i);
-            Bounds minMaxY = mVerticalAxis.getGroupBounds().getValue(i);
-
             int pWidth = getMeasurement(view, true, PRF);
             int pHeight = getMeasurement(view, false, PRF);
 
-            Alignment hAlignment = constraints.columnGroup.alignment;
-            Alignment vAlignment = constraints.rowGroup.alignment;
+            Alignment hAlign = columnGroup.alignment;
+            Alignment vAlign = rowGroup.alignment;
 
-            int ddx = protect(hAlignment.getAlignmentValue(null, cellWidth - minMaxX.size()));
-            int ddy = protect(vAlignment.getAlignmentValue(null, cellHeight - minMaxY.size()));
+            int dx, dy;
 
-            int dx = ddx + -minMaxX.below - hAlignment.getAlignmentValue(view, pWidth);
-            int dy = ddy + -minMaxY.below - vAlignment.getAlignmentValue(view, pHeight);
+            Bounds colBounds = mHorizontalAxis.getGroupBounds().getValue(i);
+            Bounds rowBounds = mVerticalAxis.getGroupBounds().getValue(i);
 
-            int width = hAlignment.getSizeInCell(view, pWidth, cellWidth);
-            int height = vAlignment.getSizeInCell(view, pHeight, cellHeight);
+            // Gravity offsets: the location of the alignment group relative to its cell group.
+            int type = PRF;
+            int c2ax = protect(hAlign.getAlignmentValue(null, cellWidth - colBounds.size(), type));
+            int c2ay = protect(vAlign.getAlignmentValue(null, cellHeight - rowBounds.size(), type));
+
+            if (mAlignmentMode == ALIGN_MARGINS) {
+                int leftMargin = getMargin(view, true, true);
+                int topMargin = getMargin(view, true, false);
+                int rightMargin = getMargin(view, false, true);
+                int bottomMargin = getMargin(view, false, false);
+
+                // Same calculation as getMeasurementIncludingMargin()
+                int mWidth = leftMargin + pWidth + rightMargin;
+                int mHeight = topMargin + pHeight + bottomMargin;
+
+                // Alignment offsets: the location of the view relative to its alignment group.
+                int a2vx = colBounds.before - hAlign.getAlignmentValue(view, mWidth, type);
+                int a2vy = rowBounds.before - vAlign.getAlignmentValue(view, mHeight, type);
+
+                dx = c2ax + a2vx + leftMargin;
+                dy = c2ay + a2vy + topMargin;
+
+                cellWidth -= leftMargin + rightMargin;
+                cellHeight -= topMargin + bottomMargin;
+            } else {
+                // Alignment offsets: the location of the view relative to its alignment group.
+                int a2vx = colBounds.before - hAlign.getAlignmentValue(view, pWidth, type);
+                int a2vy = rowBounds.before - vAlign.getAlignmentValue(view, pHeight, type);
+
+                dx = c2ax + a2vx;
+                dy = c2ay + a2vy;
+            }
+
+            int width = hAlign.getSizeInCell(view, pWidth, cellWidth, type);
+            int height = vAlign.getSizeInCell(view, pHeight, cellHeight, type);
 
             int cx = paddingLeft + x1 + dx;
             int cy = paddingTop + y1 + dy;
@@ -749,9 +897,14 @@
 
     // Inner classes
 
+    /*
+     This internal class houses the algorithm for computing the locations of grid lines;
+     along either the horizontal or vertical axis. A GridLayout uses two instances of this class -
+     distinguished by the "horizontal" flag which is true for the horizontal axis and false
+     for the vertical one.
+     */
     private class Axis {
         private static final int MIN_VALUE = -1000000;
-        private static final int MAX_VALUE = 1000000;
 
         private static final int UNVISITED = 0;
         private static final int PENDING = 1;
@@ -766,32 +919,35 @@
         PackedMap<Group, Bounds> groupBounds;
         public boolean groupBoundsValid = false;
 
-        PackedMap<Interval, Int> spanSizes;
+        PackedMap<Interval, MutableInt> spanSizes;
         public boolean spanSizesValid = false;
 
-        public int[] locations;
-
         public int[] leadingMargins;
+        public boolean leadingMarginsValid = false;
+
         public int[] trailingMargins;
+        public boolean trailingMarginsValid = false;
 
         public Arc[] arcs;
         public boolean arcsValid = false;
 
-        private boolean mOrderPreserved = DEFAULT_ORDER_PRESERVED;
+        public int[] minima;
+        public boolean minimaValid = false;
 
-        public int prefSizeOfWeightedComponent;
+        public float[] weights;
+        public int[] locations;
+
+        private boolean mOrderPreserved = DEFAULT_ORDER_PRESERVED;
 
         private Axis(boolean horizontal) {
             this.horizontal = horizontal;
         }
 
-        private int maxIndex(boolean internal) {
+        private int maxIndex() {
             // note the number Integer.MIN_VALUE + 1 comes up in undefined cells
             int count = -1;
             for (int i = 0, size = getChildCount(); i < size; i++) {
-                LayoutParams params = internal ?
-                        getLayoutParams1(getChildAt(i)) :
-                        getLayoutParams(getChildAt(i));
+                LayoutParams params = getLayoutParams(getChildAt(i));
                 Group g = horizontal ? params.columnGroup : params.rowGroup;
                 count = max(count, g.span.min);
                 count = max(count, g.span.max);
@@ -799,13 +955,9 @@
             return count == -1 ? UNDEFINED : count;
         }
 
-        private int maxIndex1() {
-            return maxIndex(true);
-        }
-
         public int getCount() {
-            if (!countWasExplicitySet && !countValid) {
-                count = max(0, maxIndex(false)); // if there are no cells, the count is zero
+            if (!countValid) {
+                count = max(0, maxIndex()); // if there are no cells, the count is zero
                 countValid = true;
             }
             return count;
@@ -844,17 +996,17 @@
             for (int i = 0; i < groupBounds.values.length; i++) {
                 groupBounds.values[i].reset();
             }
-            for (int i = 0, size = getChildCount(); i < size; i++) {
+            for (int i = 0, N = getChildCount(); i < N; i++) {
                 View c = getChildAt(i);
                 LayoutParams lp = getLayoutParams(c);
                 Group g = horizontal ? lp.columnGroup : lp.rowGroup;
 
                 Bounds bounds = groupBounds.getValue(i);
-                int dim = getMeasurement(c, horizontal, PRF);
+
+                int size = getMeasurementIncludingMargin(c, horizontal, PRF);
                 // todo test this works correctly when the returned value is UNDEFINED
-                int below = g.alignment.getAlignmentValue(c, dim);
-                int above = dim - below;
-                bounds.include(-below, above);
+                int before = g.alignment.getAlignmentValue(c, size, PRF);
+                bounds.include(before, size - before);
             }
         }
 
@@ -870,36 +1022,36 @@
         }
 
         // Add values computed by alignment - taking the max of all alignments in each span
-        private PackedMap<Interval, Int> createSpanSizes() {
+        private PackedMap<Interval, MutableInt> createSpanSizes() {
             PackedMap<Group, Bounds> groupBounds = getGroupBounds();
             int N = groupBounds.keys.length;
             Interval[] spans = new Interval[N];
-            Int[] values = new Int[N];
+            MutableInt[] values = new MutableInt[N];
             for (int i = 0; i < N; i++) {
                 Interval key = groupBounds.keys[i].span;
 
                 spans[i] = key;
-                values[i] = new Int();
+                values[i] = new MutableInt();
             }
-            return new PackedMap<Interval, Int>(spans, values);
+            return new PackedMap<Interval, MutableInt>(spans, values);
         }
 
         private void computeSpanSizes() {
-            Int[] spans = spanSizes.values;
+            MutableInt[] spans = spanSizes.values;
             for (int i = 0; i < spans.length; i++) {
                 spans[i].reset();
             }
 
-            Bounds[] bounds = getGroupBounds().values;  // us get to trigger a re-evaluation
+            Bounds[] bounds = getGroupBounds().values;  // use getter to trigger a re-evaluation
             for (int i = 0; i < bounds.length; i++) {
                 int value = bounds[i].size();
 
-                Int valueHolder = spanSizes.getValue(i);
+                MutableInt valueHolder = spanSizes.getValue(i);
                 valueHolder.value = max(valueHolder.value, value);
             }
         }
 
-        private PackedMap<Interval, Int> getSpanSizes() {
+        private PackedMap<Interval, MutableInt> getSpanSizes() {
             if (spanSizes == null) {
                 spanSizes = createSpanSizes();
             }
@@ -910,9 +1062,7 @@
             return spanSizes;
         }
 
-        private void include(List<Arc> arcs, Interval key, Int size, boolean maximizing) {
-            key = maximizing ? key.inverse() : key;
-            size = maximizing ? size.neg() : size;
+        private void include(List<Arc> arcs, Interval key, MutableInt size) {
             // this bit below should really be computed outside here -
             // its just to stop default (col>0) constraints obliterating valid entries
             for (Arc arc : arcs) {
@@ -924,22 +1074,22 @@
             arcs.add(new Arc(key, size));
         }
 
-        private void include2(List<Arc> arcs, Interval span, Int min, Int max,
-                boolean both, boolean maximizing) {
-            include(arcs, span, min, maximizing);
+        private void include2(List<Arc> arcs, Interval span, MutableInt min, MutableInt max,
+                boolean both) {
+            include(arcs, span, min);
             if (both) {
-                include(arcs, span.inverse(), max.neg(), maximizing);
+                // todo
+//                include(arcs, span.inverse(), max.neg());
             }
         }
 
-        private void include2(List<Arc> arcs, Interval span, int min, int max,
-                boolean both, boolean maximizing) {
-            include2(arcs, span, new Int(min), new Int(max), both, maximizing);
+        private void include2(List<Arc> arcs, Interval span, int min, int max, boolean both) {
+            include2(arcs, span, new MutableInt(min), new MutableInt(max), both);
         }
 
-        // Group arcs by their first index, returning an array of arrays.
+        // Group arcs by their first vertex, returning an array of arrays.
         // This is linear in the number of arcs.
-        private Arc[][] index(Arc[] arcs) {
+        private Arc[][] groupArcsByFirstVertex(Arc[] arcs) {
             int N = getCount() + 1;// the number of vertices
             Arc[][] result = new Arc[N][];
             int[] sizes = new int[N];
@@ -959,18 +1109,18 @@
             return result;
         }
 
-        // todo do we always add first element?
-        private Arc[] sort(final Arc[] arcs, int start) {
+        private Arc[] topologicalSort(final Arc[] arcs, int start) {
+        // todo ensure the <start> vertex is added in edge cases
             final List<Arc> result = new ArrayList<Arc>();
             new Object() {
-                Arc[][] index = index(arcs);
+                Arc[][] arcsByFirstVertex = groupArcsByFirstVertex(arcs);
                 int[] visited = new int[getCount() + 1];
 
                 boolean completesCycle(int loc) {
                     int state = visited[loc];
                     if (state == UNVISITED) {
                         visited[loc] = PENDING;
-                        for (Arc arc : index[loc]) {
+                        for (Arc arc : arcsByFirstVertex[loc]) {
                             Interval span = arc.span;
                             // the recursive call
                             if (completesCycle(span.max)) {
@@ -1006,7 +1156,7 @@
             return result;
         }
 
-        // todo unify with findUsed above
+        // todo unify with findUsed above. Both routines analyze which rows/columns are empty.
         private Collection<Interval> getSpacers() {
             List<Interval> result = new ArrayList<Interval>();
             int N = getCount() + 1;
@@ -1038,16 +1188,16 @@
             return result;
         }
 
-        private Arc[] createArcs(boolean maximizing) {
+        private Arc[] createArcs() {
             List<Arc> spanToSize = new ArrayList<Arc>();
 
             // Add all the preferred elements that were not defined by the user.
-            PackedMap<Interval, Int> spanSizes = getSpanSizes();
+            PackedMap<Interval, MutableInt> spanSizes = getSpanSizes();
             for (int i = 0; i < spanSizes.keys.length; i++) {
                 Interval key = spanSizes.keys[i];
-                Int value = spanSizes.values[i];
+                MutableInt value = spanSizes.values[i];
                 // todo remove value duplicate
-                include2(spanToSize, key, value, value, accommodateBothMinAndMax, maximizing);
+                include2(spanToSize, key, value, value, accommodateBothMinAndMax);
             }
 
             // Find redundant rows/cols and glue them together with 0-length arcs to link the tree
@@ -1055,8 +1205,8 @@
             for (int i = 0; i < getCount(); i++) {
                 if (!used[i]) {
                     Interval span = new Interval(i, i + 1);
-                    include(spanToSize, span, new Int(0), maximizing);
-                    include(spanToSize, span.inverse(), new Int(0), maximizing);
+                    include(spanToSize, span, new MutableInt(0));
+                    include(spanToSize, span.inverse(), new MutableInt(0));
                 }
             }
 
@@ -1064,21 +1214,21 @@
                 // Add preferred gaps
                 for (int i = 0; i < getCount(); i++) {
                     if (used[i]) {
-                        include2(spanToSize, new Interval(i, i + 1), 0, 0, false, maximizing);
+                        include2(spanToSize, new Interval(i, i + 1), 0, 0, false);
                     }
                 }
             } else {
                 for (Interval gap : getSpacers()) {
-                    include2(spanToSize, gap, 0, 0, false, maximizing);
+                    include2(spanToSize, gap, 0, 0, false);
                 }
             }
             Arc[] arcs = spanToSize.toArray(new Arc[spanToSize.size()]);
-            return sort(arcs, maximizing ? getCount() : 0);
+            return topologicalSort(arcs, 0);
         }
 
-        public Arc[] getArcs(boolean maximizing) {
+        public Arc[] getArcs() {
             if (arcs == null) {
-                arcs = createArcs(maximizing);
+                arcs = createArcs();
             }
             if (!arcsValid) {
                 getSpanSizes();
@@ -1087,21 +1237,54 @@
             return arcs;
         }
 
-        private boolean relax(int[] locations, Arc entry, boolean maximizing) {
+        private boolean relax(int[] locations, Arc entry) {
             Interval span = entry.span;
             int u = span.min;
             int v = span.max;
             int value = entry.value.value;
             int candidate = locations[u] + value;
-            if (maximizing ? candidate < locations[v] : candidate > locations[v]) {
+            if (candidate > locations[v]) {
                 locations[v] = candidate;
                 return true;
             }
             return false;
         }
 
-        // Bellman-Ford variant
-        private int[] solve(Arc[] arcs, int[] locations, boolean maximizing) {
+        /*
+        Bellman-Ford variant - modified to reduce typical running time from O(N^2) to O(N)
+
+        GridLayout converts its requirements into a system of linear constraints of the
+        form:
+
+        x[i] - x[j] < a[k]
+
+        Where the x[i] are variables and the a[k] are constants.
+
+        For example, if the variables were instead labeled x, y, z we might have:
+
+            x - y < 17
+            y - z < 23
+            z - x < 42
+
+        This is a special case of the Linear Programming problem that is, in turn,
+        equivalent to the single-source shortest paths problem on a digraph, for
+        which the O(n^2) Bellman-Ford algorithm the most commonly used general solution.
+
+        Other algorithms are faster in the case where no arcs have negative weights
+        but allowing negative weights turns out to be the same as accommodating maximum
+        size requirements as well as minimum ones.
+
+        Bellman-Ford works by iteratively 'relaxing' constraints over all nodes (an O(N)
+        process) and performing this step N times. Proof of correctness hinges on the
+        fact that there can be no negative weight chains of length > N - unless a
+        'negative weight loop' exists. The algorithm catches this case in a final
+        checking phase that reports failure.
+
+        By topologically sorting the nodes and checking this condition at each step
+        typical layout problems complete after the first iteration and the algorithm
+        completes in O(N) steps with very low constants.
+        */
+        private int[] solve(Arc[] arcs, int[] locations) {
             int N = getCount() + 1; // The number of vertices is the number of columns/rows + 1.
 
             boolean changed = false;
@@ -1109,11 +1292,11 @@
             for (int i = 0; i < N; i++) {
                 changed = false;
                 for (int j = 0, length = arcs.length; j < length; j++) {
-                    changed = changed | relax(locations, arcs[j], maximizing);
+                    changed = changed | relax(locations, arcs[j]);
                 }
                 if (!changed) {
                     if (DEBUG) {
-                        Log.d(TAG, "Iteration " + (maximizing ? "(max)" : "(min)") +
+                        Log.d(TAG, "Iteration " +
                                 " completed after " + (1 + i) + " steps out of " + N);
                     }
                     break;
@@ -1125,119 +1308,160 @@
             return locations;
         }
 
-        private int[] init(int defaultValue, int min, int max) {
-            int N = getCount() + 1; // The number of vertices is the number of columns/rows + 1.
-            int[] locations = new int[N];
-            Arrays.fill(locations, defaultValue);
-            locations[0] = min;
-            locations[N - 1] = max;
-            return locations;
-        }
-
-        private int[] computeMargins(boolean leading) {
-            int[] result = new int[getCount() + 1];
+        private void computeMargins(boolean leading) {
+            int[] margins = leading ? leadingMargins : trailingMargins;
             for (int i = 0, size = getChildCount(); i < size; i++) {
                 View c = getChildAt(i);
                 LayoutParams lp = getLayoutParams(c);
                 Group g = horizontal ? lp.columnGroup : lp.rowGroup;
                 Interval span = g.span;
                 int index = leading ? span.min : span.max;
-                result[index] = max(result[index], getMargin(c, leading, horizontal));
+                margins[index] = max(margins[index], getMargin(c, leading, horizontal));
             }
-            return result;
         }
 
-        // has side effects
-        private void computeLocations(int[] locations, boolean maximizing) {
-            leadingMargins = computeMargins(true);
-            trailingMargins = computeMargins(false);
+        private int[] getLeadingMargins() {
+            if (leadingMargins == null) {
+                leadingMargins = new int[getCount() + 1];
+            }
+            if (!leadingMarginsValid) {
+                computeMargins(true);
+                leadingMarginsValid = true;
+            }
+            return leadingMargins;
+        }
 
-            solve(getArcs(maximizing), locations, maximizing);
+        private int[] getTrailingMargins() {
+            if (trailingMargins == null) {
+                trailingMargins = new int[getCount() + 1];
+            }
+            if (!trailingMarginsValid) {
+                computeMargins(false);
+                trailingMarginsValid = true;
+            }
+            return trailingMargins;
+        }
 
-            // Add margins
+        private void addMargins() {
+            int[] leadingMargins = getLeadingMargins();
+            int[] trailingMargins = getTrailingMargins();
+
             int delta = 0;
-            for (int i = 0; i < getCount(); i++) {
+            for (int i = 0, N = getCount(); i < N; i++) {
                 int margins = leadingMargins[i] + trailingMargins[i + 1];
                 delta += margins;
-                locations[i + 1] += delta;
+                minima[i + 1] += delta;
             }
         }
 
-        private int size(int[] locations) {
-            return locations[locations.length - 1] - locations[0];
-        }
-
-        private int[] getLimit(boolean lowerBound, boolean maximizing) {
-            int defaultValue = maximizing ? MAX_VALUE : MIN_VALUE;
-            if (lowerBound) {
-                // as long as it avoids overflow, the upper bound can be anything (including zero)
-                int[] result = init(defaultValue, defaultValue, 1000);
-                computeLocations(result, maximizing);
-                int delta = result[0];
-                for (int i = 0; i < result.length; i++) {
-                    result[i] -= delta;
-                }
-                return result;
+        private int getLocationIncludingMargin(View view, boolean leading, int index) {
+            int location = locations[index];
+            int margin;
+            if (mAlignmentMode != ALIGN_MARGINS) {
+                margin = (leading ? leadingMargins : trailingMargins)[index];
             } else {
-                int[] result = init(defaultValue, 0, defaultValue);
-                computeLocations(result, maximizing);
-                return result;
+                margin = 0;
             }
+            return leading ? (location + margin) : (location - margin);
+        }
+
+        private void computeMinima(int[] a) {
+            Arrays.fill(a, MIN_VALUE);
+            a[0] = 0;
+            solve(getArcs(), a);
+            if (mAlignmentMode != ALIGN_MARGINS) {
+                addMargins();
+            }
+        }
+
+        private int[] getMinima() {
+            if (minima == null) {
+                int N = getCount() + 1;
+                minima = new int[N];
+            }
+            if (!minimaValid) {
+                computeMinima(minima);
+                minimaValid = true;
+            }
+            return minima;
+        }
+
+        private void computeWeights() {
+            for (int i = 0, N = getChildCount(); i < N; i++) {
+                LayoutParams lp = getLayoutParams(getChildAt(i));
+                Group g = horizontal ? lp.columnGroup : lp.rowGroup;
+                Interval span = g.span;
+                int penultimateIndex = span.max - 1;
+                weights[penultimateIndex] += horizontal ? lp.columnWeight : lp.rowWeight;
+            }
+        }
+
+        private float[] getWeights() {
+            if (weights == null) {
+                int N = getCount();
+                weights = new float[N];
+            }
+            computeWeights();
+            return weights;
+        }
+
+        private int[] getLocations() {
+            if (locations == null) {
+                int N = getCount() + 1;
+                locations = new int[N];
+            }
+            return locations;
         }
 
         // External entry points
 
+        private int size(int[] locations) {
+            return max2(locations, 0) - locations[0];
+        }
+
         private int getMin() {
-            int[] mins = getLimit(maximizing, maximizing);
-            return size(mins);
-        }
-
-        private int getPref() {
-            return accommodateBothMinAndMax ? getMax() : getMin();
-        }
-
-        private int getMax() {
-            int[] maxs = getLimit(!maximizing, maximizing);
-            return size(maxs);
-        }
-
-        private int totalMarginSize() {
-            return sum(leadingMargins) + sum(trailingMargins);
+            return size(getMinima());
         }
 
         private void layout(int targetSize) {
-            int N = getCount() + 1;
-            int min = getMin();
-            int max = getMax();
+            int[] mins = getMinima();
 
-            int clippedTargetSize = max(min(max, targetSize), min); // confine size to valid range
+            int totalDelta = max(0, targetSize - size(mins)); // confine to expansion
 
-            if (DEBUG) {
-                Log.d(TAG, "Computing sizes for target " + clippedTargetSize + " for " +
-                        (horizontal ? "col" : "row") + "s from: " + arcs);
+            float[] weights = getWeights();
+            float totalWeight = sum(weights);
+
+            if (totalWeight == 0f && weights.length > 0) {
+                weights[weights.length - 1] = 1;
+                totalWeight = 1;
             }
-            int delta = clippedTargetSize - min;
-            prefSizeOfWeightedComponent = delta;
-            invalidateValues();
-            int defaultValue = maximizing ? MAX_VALUE : MIN_VALUE;
-            locations = init(defaultValue, 0, clippedTargetSize - totalMarginSize());
-            computeLocations(locations, maximizing);
-            prefSizeOfWeightedComponent = 0;
 
-            if (DEBUG) {
-                Log.d(TAG, "locations = " + Arrays.toString(locations));
-                int[] computedSizes = new int[N - 1];
-                for (int i = 0; i < N - 1; i++) {
-                    computedSizes[i] = locations[i + 1] - locations[i];
-                }
-                Log.d(TAG, "sizes = " + Arrays.toString(computedSizes));
+            int[] locations = getLocations();
+            int cumulativeDelta = 0;
+
+            // note |weights| = |locations| - 1
+            for (int i = 0; i < weights.length; i++) {
+                float weight = weights[i];
+                int delta = (int) (totalDelta * weight / totalWeight);
+                cumulativeDelta += delta;
+                locations[i + 1] = mins[i + 1] + cumulativeDelta;
+
+                totalDelta -= delta;
+                totalWeight -= weight;
             }
         }
 
         private void invalidateStructure() {
             countValid = false;
+
             groupBounds = null;
             spanSizes = null;
+            leadingMargins = null;
+            trailingMargins = null;
+            arcs = null;
+            minima = null;
+            weights = null;
+            locations = null;
 
             invalidateValues();
         }
@@ -1246,6 +1470,9 @@
             groupBoundsValid = false;
             spanSizesValid = false;
             arcsValid = false;
+            leadingMarginsValid = false;
+            trailingMarginsValid = false;
+            minimaValid = false;
         }
     }
 
@@ -1259,8 +1486,8 @@
      * {@link Group Groups} are immutable structures and may be shared between the layout
      * parameters of different children.
      * <p>
-     * The {@link Group#span span} fields of the row and column groups together specify
-     * the four grid indices that delimit the cells of this cell group.
+     * The row and column groups contain the leading and trailing indices along each axis
+     * and together specify the four grid indices that delimit the cells of this cell group.
      * <p>
      * The {@link Group#alignment alignment} fields of the row and column groups together specify
      * both aspects of alignment within the cell group. It is also possible to specify a child's
@@ -1277,26 +1504,26 @@
      *     <li>{@link #height} = {@link #WRAP_CONTENT}</li>
      *     <li>{@link #topMargin} = 0 when
      *          {@link GridLayout#setUseDefaultMargins(boolean) useDefaultMargins} is
-     *          <code>false</code>; otherwise {@link Integer#MIN_VALUE}, to
+     *          {@code false}; otherwise {@link #UNDEFINED}, to
      *          indicate that a default value should be computed on demand. </li>
      *     <li>{@link #leftMargin} = 0 when
      *          {@link GridLayout#setUseDefaultMargins(boolean) useDefaultMargins} is
-     *          <code>false</code>; otherwise {@link Integer#MIN_VALUE}, to
+     *          {@code false}; otherwise {@link #UNDEFINED}, to
      *          indicate that a default value should be computed on demand. </li>
      *     <li>{@link #bottomMargin} = 0 when
      *          {@link GridLayout#setUseDefaultMargins(boolean) useDefaultMargins} is
-     *          <code>false</code>; otherwise {@link Integer#MIN_VALUE}, to
+     *          {@code false}; otherwise {@link #UNDEFINED}, to
      *          indicate that a default value should be computed on demand. </li>
      *     <li>{@link #rightMargin} = 0 when
      *          {@link GridLayout#setUseDefaultMargins(boolean) useDefaultMargins} is
-     *          <code>false</code>; otherwise {@link Integer#MIN_VALUE}, to
+     *          {@code false}; otherwise {@link #UNDEFINED}, to
      *          indicate that a default value should be computed on demand. </li>
-     *     <li>{@link #rowGroup}<code>.span</code> = <code>[0, 1]</code> </li>
-     *     <li>{@link #rowGroup}<code>.alignment</code> = {@link #BASELINE} </li>
-     *     <li>{@link #columnGroup}<code>.span</code> = <code>[0, 1]</code> </li>
-     *     <li>{@link #columnGroup}<code>.alignment</code> = {@link #LEFT} </li>
-     *     <li>{@link #rowWeight} = <code>0f</code> </li>
-     *     <li>{@link #columnWeight} = <code>0f</code> </li>
+     *     <li>{@link #rowGroup}{@code .span} = {@code [0, 1]} </li>
+     *     <li>{@link #rowGroup}{@code .alignment} = {@link #BASELINE} </li>
+     *     <li>{@link #columnGroup}{@code .span} = {@code [0, 1]} </li>
+     *     <li>{@link #columnGroup}{@code .alignment} = {@link #LEFT} </li>
+     *     <li>{@link #rowWeight} = {@code 0f} </li>
+     *     <li>{@link #columnWeight} = {@code 0f} </li>
      * </ul>
      *
      * @attr ref android.R.styleable#GridLayout_Layout_layout_row
@@ -1316,21 +1543,22 @@
         private static final int DEFAULT_MARGIN = UNDEFINED;
         private static final int DEFAULT_ROW = UNDEFINED;
         private static final int DEFAULT_COLUMN = UNDEFINED;
-        private static final Interval DEFAULT_SPAN = new Interval(0, 1);
+        private static final Interval DEFAULT_SPAN = new Interval(UNDEFINED, UNDEFINED + 1);
         private static final int DEFAULT_SPAN_SIZE = DEFAULT_SPAN.size();
-        private static final Alignment DEFAULT_HORIZONTAL_ALIGNMENT = LEFT;
-        private static final Alignment DEFAULT_VERTCIAL_ALGIGNMENT = BASELINE;
-        private static final Group DEFAULT_HORIZONTAL_GROUP =
-                new Group(DEFAULT_SPAN, DEFAULT_HORIZONTAL_ALIGNMENT);
-        private static final Group DEFAULT_VERTICAL_GROUP =
-                new Group(DEFAULT_SPAN, DEFAULT_VERTCIAL_ALGIGNMENT);
-        private static final int DEFAULT_WEIGHT = 0;
+        private static final Alignment DEFAULT_COLUMN_ALIGNMENT = LEFT;
+        private static final Alignment DEFAULT_ROW_ALIGNMENT = BASELINE;
+        private static final Group DEFAULT_COLUMN_GROUP =
+                new Group(DEFAULT_SPAN, DEFAULT_COLUMN_ALIGNMENT);
+        private static final Group DEFAULT_ROW_GROUP =
+                new Group(DEFAULT_SPAN, DEFAULT_ROW_ALIGNMENT);
+        private static final int DEFAULT_WEIGHT_0 = 0;
+        private static final int DEFAULT_WEIGHT_1 = 1;
 
         // Misc
 
         private static final Rect CONTAINER_BOUNDS = new Rect(0, 0, 2, 2);
-        private static final Alignment[] HORIZONTAL_ALIGNMENTS = { LEFT, CENTER, RIGHT };
-        private static final Alignment[] VERTICAL_ALIGNMENTS = { TOP, CENTER, BOTTOM };
+        private static final Alignment[] COLUMN_ALIGNMENTS = { LEFT, CENTER, RIGHT };
+        private static final Alignment[] ROW_ALIGNMENTS = { TOP, CENTER, BOTTOM };
 
         // TypedArray indices
 
@@ -1397,14 +1625,14 @@
         public LayoutParams(Group rowGroup, Group columnGroup) {
             this(DEFAULT_WIDTH, DEFAULT_HEIGHT,
                     DEFAULT_MARGIN, DEFAULT_MARGIN, DEFAULT_MARGIN, DEFAULT_MARGIN,
-                    rowGroup, columnGroup, DEFAULT_WEIGHT, DEFAULT_WEIGHT);
+                    rowGroup, columnGroup, DEFAULT_WEIGHT_0, DEFAULT_WEIGHT_0);
         }
 
         /**
          * Constructs a new LayoutParams with default values as defined in {@link LayoutParams}.
          */
         public LayoutParams() {
-            this(DEFAULT_HORIZONTAL_GROUP, DEFAULT_VERTICAL_GROUP);
+            this(DEFAULT_ROW_GROUP, DEFAULT_COLUMN_GROUP);
         }
 
         // Copying constructors
@@ -1495,57 +1723,62 @@
 
         // Gravity. For conversion from the static the integers defined in the Gravity class,
         // use Gravity.apply() to apply gravity to a view of zero size and see where it ends up.
-        private static Alignment getHorizontalAlignment(int gravity, int width) {
+        private static Alignment getColumnAlignment(int gravity, int width) {
             Rect r = new Rect(0, 0, 0, 0);
             Gravity.apply(gravity, 0, 0, CONTAINER_BOUNDS, r);
 
-            boolean fill = width == MATCH_PARENT;
-            Alignment defaultAlignment = fill ? FILL : DEFAULT_HORIZONTAL_ALIGNMENT;
-            return getAlignment(HORIZONTAL_ALIGNMENTS, FILL, r.left, r.right,
+            boolean fill = (width == MATCH_PARENT);
+            Alignment defaultAlignment = fill ? FILL : DEFAULT_COLUMN_ALIGNMENT;
+            return getAlignment(COLUMN_ALIGNMENTS, FILL, r.left, r.right,
                     !definesHorizontal(gravity), defaultAlignment);
         }
 
-        private static Alignment getVerticalAlignment(int gravity, int height) {
+        private static Alignment getRowAlignment(int gravity, int height) {
             Rect r = new Rect(0, 0, 0, 0);
             Gravity.apply(gravity, 0, 0, CONTAINER_BOUNDS, r);
 
-            boolean fill = height == MATCH_PARENT;
-            Alignment defaultAlignment = fill ? FILL : DEFAULT_VERTCIAL_ALGIGNMENT;
-            return getAlignment(VERTICAL_ALIGNMENTS, FILL, r.top, r.bottom,
+            boolean fill = (height == MATCH_PARENT);
+            Alignment defaultAlignment = fill ? FILL : DEFAULT_ROW_ALIGNMENT;
+            return getAlignment(ROW_ALIGNMENTS, FILL, r.top, r.bottom,
                     !definesVertical(gravity), defaultAlignment);
         }
 
+        private int getDefaultWeight(int size) {
+            return (size == MATCH_PARENT) ? DEFAULT_WEIGHT_1 : DEFAULT_WEIGHT_0;
+        }
+
         private void init(Context context, AttributeSet attrs, int defaultGravity) {
             TypedArray a = context.obtainStyledAttributes(attrs, styleable.GridLayout_Layout);
             try {
-                int gravity = a.getInteger(GRAVITY, defaultGravity);
+                int gravity = a.getInt(GRAVITY, defaultGravity);
 
-                int column = a.getInteger(COLUMN, DEFAULT_COLUMN);
-                int width = a.getInteger(COLUMN_SPAN, DEFAULT_SPAN_SIZE);
-                Interval colSpan = new Interval(column, column + width);
-                this.columnGroup = new Group(colSpan, getHorizontalAlignment(gravity, width));
-                this.columnWeight = a.getFloat(COLUMN_WEIGHT, DEFAULT_WEIGHT);
+                int column = a.getInt(COLUMN, DEFAULT_COLUMN);
+                int columnSpan = a.getInt(COLUMN_SPAN, DEFAULT_SPAN_SIZE);
+                Interval hSpan = new Interval(column, column + columnSpan);
+                this.columnGroup = new Group(hSpan, getColumnAlignment(gravity, width));
+                this.columnWeight = a.getFloat(COLUMN_WEIGHT, getDefaultWeight(width));
 
-                int row = a.getInteger(ROW, DEFAULT_ROW);
-                int height = a.getInteger(ROW_SPAN, DEFAULT_SPAN_SIZE);
-                Interval rowSpan = new Interval(row, row + height);
-                this.rowGroup = new Group(rowSpan, getVerticalAlignment(gravity, height));
-                this.rowWeight = a.getFloat(ROW_WEIGHT, DEFAULT_WEIGHT);
+                int row = a.getInt(ROW, DEFAULT_ROW);
+                int rowSpan = a.getInt(ROW_SPAN, DEFAULT_SPAN_SIZE);
+                Interval vSpan = new Interval(row, row + rowSpan);
+                this.rowGroup = new Group(vSpan, getRowAlignment(gravity, height));
+                this.rowWeight = a.getFloat(ROW_WEIGHT, getDefaultWeight(height));
             } finally {
                 a.recycle();
             }
         }
 
         /**
-         * Describes how the child views are positioned. Default is <code>LEFT | BASELINE</code>.
+         * Describes how the child views are positioned. Default is {@code LEFT | BASELINE}.
+         * See {@link android.view.Gravity}.
          *
-         * @param gravity the new gravity. See {@link android.view.Gravity}.
+         * @param gravity the new gravity value
          *
          * @attr ref android.R.styleable#GridLayout_Layout_layout_gravity
          */
         public void setGravity(int gravity) {
-            columnGroup = columnGroup.copyWriteAlignment(getHorizontalAlignment(gravity, width));
-            rowGroup = rowGroup.copyWriteAlignment(getVerticalAlignment(gravity, height));
+            columnGroup = columnGroup.copyWriteAlignment(getColumnAlignment(gravity, width));
+            rowGroup = rowGroup.copyWriteAlignment(getRowAlignment(gravity, height));
         }
 
         @Override
@@ -1554,21 +1787,25 @@
             this.height = attributes.getLayoutDimension(heightAttr, DEFAULT_HEIGHT);
         }
 
-        private void setVerticalGroupSpan(Interval span) {
+        private void setRowGroupSpan(Interval span) {
             rowGroup = rowGroup.copyWriteSpan(span);
         }
 
-        private void setHorizontalGroupSpan(Interval span) {
+        private void setColumnGroupSpan(Interval span) {
             columnGroup = columnGroup.copyWriteSpan(span);
         }
     }
 
+    /*
+    In place of a HashMap from span to Int, use an array of key/value pairs - stored in Arcs.
+    Add the mutables completesCycle flag to avoid creating another hash table for detecting cycles.
+     */
     private static class Arc {
         public final Interval span;
-        public final Int value;
+        public final MutableInt value;
         public boolean completesCycle;
 
-        public Arc(Interval span, Int value) {
+        public Arc(Interval span, MutableInt value) {
             this.span = span;
             this.value = value;
         }
@@ -1581,27 +1818,36 @@
 
     // A mutable Integer - used to avoid heap allocation during the layout operation
 
-    private static class Int {
+    private static class MutableInt {
         public int value;
 
-        private Int() {
+        private MutableInt() {
             reset();
         }
 
-        private Int(int value) {
+        private MutableInt(int value) {
             this.value = value;
         }
 
         private void reset() {
             value = Integer.MIN_VALUE;
         }
-
-        private Int neg() {
-            // this should never be called
-            throw new UnsupportedOperationException();
-        }
     }
 
+    /*
+    This data structure is used in place of a Map where we have an index that refers to the order
+    in which each key/value pairs were added to the map. In this case we store keys and values
+    in arrays of a length that is equal to the number of unique keys. We also maintain an
+    array of indexes from insertion order to the compacted arrays of keys and values.
+
+    Note that behavior differs from that of a LinkedHashMap in that repeated entries
+    *do* get added multiples times. So the length of index is equals to the number of
+    items added.
+
+    This is useful in the GridLayout class where we can rely on the order of children not
+    changing during layout - to use integer-based lookup for our internal structures
+    rather than using (and storing) an implementation of Map<Key, ?>.
+     */
     @SuppressWarnings(value = "unchecked")
     private static class PackedMap<K, V> {
         public final int[] index;
@@ -1611,8 +1857,8 @@
         private PackedMap(K[] keys, V[] values) {
             this.index = createIndex(keys);
 
-            this.keys = index(keys, index);
-            this.values = index(values, index);
+            this.keys = compact(keys, index);
+            this.values = compact(values, index);
         }
 
         private K getKey(int i) {
@@ -1640,59 +1886,60 @@
             return result;
         }
 
-        private static int max(int[] a, int valueIfEmpty) {
-            int result = valueIfEmpty;
-            for (int i = 0, length = a.length; i < length; i++) {
-                result = Math.max(result, a[i]);
-            }
-            return result;
-        }
-
-        private static <K> K[] index(K[] keys, int[] index) {
-            int size = keys.length;
-            Class<?> componentType = keys.getClass().getComponentType();
-            K[] result = (K[]) Array.newInstance(componentType, max(index, -1) + 1);
+        /*
+        Create a compact array of keys or values using the supplied index.
+         */
+        private static <K> K[] compact(K[] a, int[] index) {
+            int size = a.length;
+            Class<?> componentType = a.getClass().getComponentType();
+            K[] result = (K[]) Array.newInstance(componentType, max2(index, -1) + 1);
 
             // this overwrite duplicates, retaining the last equivalent entry
             for (int i = 0; i < size; i++) {
-                result[index[i]] = keys[i];
+                result[index[i]] = a[i];
             }
             return result;
         }
     }
 
-    private static class Bounds {
-        public int below;
-        public int above;
+    /*
+    For each Group (with a given alignment) we need to store the amount of space required
+    before the alignment point and the amount of space required after it. One side of this
+    calculation is always 0 for LEADING and TRAILING alignments but we don't make use of this.
+    For CENTER and BASELINE alignments both sides are needed and in the BASELINE case no
+    simple optimisations are possible.
 
-        private Bounds(int below, int above) {
-            this.below = below;
-            this.above = above;
-        }
+    The general algorithm therefore is to create a Map (actually a PackedMap) from
+    Group to Bounds and to loop through all Views in the group taking the maximum
+    of the values for each View.
+    */
+    private static class Bounds {
+        public int before;
+        public int after;
 
         private Bounds() {
             reset();
         }
 
         private void reset() {
-            below = Integer.MAX_VALUE;
-            above = Integer.MIN_VALUE;
+            before = Integer.MIN_VALUE;
+            after = Integer.MIN_VALUE;
         }
 
-        private void include(int below, int above) {
-            this.below = min(this.below, below);
-            this.above = max(this.above, above);
+        private void include(int before, int after) {
+            this.before = max(this.before, before);
+            this.after = max(this.after, after);
         }
 
         private int size() {
-            return above - below;
+            return before + after;
         }
 
         @Override
         public String toString() {
             return "Bounds{" +
-                    "below=" + below +
-                    ", above=" + above +
+                    "before=" + before +
+                    ", after=" + after +
                     '}';
         }
     }
@@ -1705,24 +1952,25 @@
      * It is not necessary to have multiple instances of Intervals which have the same
      * {@link #min} and {@link #max} values.
      * <p>
-     * Intervals are often written as <code>[min, max]</code> and represent the set of values
-     * <em>x</em> such that <em>min <= x < max</em>.
+     * Intervals are often written as {@code [min, max]} and represent the set of values
+     * {@code x} such that {@code min <= x < max}.
      */
-    public static class Interval {
+    /* package */ static class Interval {
         /**
          * The minimum value.
          */
         public final int min;
+
         /**
          * The maximum value.
          */
         public final int max;
 
         /**
-         * Construct a new Interval, <code>interval</code>, where:
+         * Construct a new Interval, {@code interval}, where:
          * <ul>
-         *     <li> <code>interval.min = min</code> </li>
-         *     <li> <code>interval.max = max</code> </li>
+         *     <li> {@code interval.min = min} </li>
+         *     <li> {@code interval.max = max} </li>
          * </ul>
          *
          * @param min the minimum value.
@@ -1742,13 +1990,14 @@
         }
 
         /**
-         * Returns true if the {@link #getClass class}, {@link #min} and {@link #max} properties
-         * of this Interval and the supplied parameter are pairwise equal; false otherwise.
+         * Returns {@code true} if the {@link #getClass class},
+         * {@link #min} and {@link #max} properties of this Interval and the
+         * supplied parameter are pairwise equal; {@code false} otherwise.
          *
-         * @param that the object to compare this interval with.
+         * @param that the object to compare this interval with
          *
          * @return {@code true} if the specified object is equal to this
-         *         {@code Interval}; {@code false} otherwise.
+         *         {@code Interval}, {@code false} otherwise.
          */
         @Override
         public boolean equals(Object that) {
@@ -1789,18 +2038,17 @@
      * cells.
      * <p>
      * Groups are immutable and so may be shared between views with the same
-     * <code>span</code> and <code>alignment</code>.
+     * {@code span} and {@code alignment}.
      */
     public static class Group {
         /**
-         * The {@link Interval#min min} and {@link Interval#max max} values of
-         * a span specify the grid indices of the leading and trailing edges of
-         * the cell group.
+         * The grid indices of the leading and trailing edges of this cell group for the
+         * appropriate axis.
          * <p>
          * See {@link GridLayout} for a description of the conventions used by GridLayout
          * for grid indices.
          */
-        public final Interval span;
+        /* package */ final Interval span;
         /**
          * Specifies how cells should be aligned in this group.
          * For row groups, this specifies the vertical alignment.
@@ -1809,47 +2057,47 @@
         public final Alignment alignment;
 
         /**
-         * Construct a new Group, <code>group</code>, where:
+         * Construct a new Group, {@code group}, where:
          * <ul>
-         *     <li> <code>group.span = span</code> </li>
-         *     <li> <code>group.alignment = alignment</code> </li>
+         *     <li> {@code group.span = span} </li>
+         *     <li> {@code group.alignment = alignment} </li>
          * </ul>
          *
-         * @param span      the span.
-         * @param alignment the alignment.
+         * @param span      the span
+         * @param alignment the alignment
          */
-        public Group(Interval span, Alignment alignment) {
+        /* package */ Group(Interval span, Alignment alignment) {
             this.span = span;
             this.alignment = alignment;
         }
 
         /**
-         * Construct a new Group, <code>group</code>, where:
+         * Construct a new Group, {@code group}, where:
          * <ul>
-         *     <li> <code>group.span = [min, max]</code> </li>
-         *     <li> <code>group.alignment = alignment</code> </li>
+         *     <li> {@code group.span = [start, start + size]} </li>
+         *     <li> {@code group.alignment = alignment} </li>
          * </ul>
          *
-         * @param min       the minimum.
-         * @param max       the maximum.
-         * @param alignment the alignment.
+         * @param start     the start
+         * @param size      the size
+         * @param alignment the alignment
          */
-        public Group(int min, int max, Alignment alignment) {
-            this(new Interval(min, max), alignment);
+        public Group(int start, int size, Alignment alignment) {
+            this(new Interval(start, start + size), alignment);
         }
 
         /**
-         * Construct a new Group, <code>group</code>, where:
+         * Construct a new Group, {@code group}, where:
          * <ul>
-         *     <li> <code>group.span = [min, min + 1]</code> </li>
-         *     <li> <code>group.alignment = alignment</code> </li>
+         *     <li> {@code group.span = [start, start + 1]} </li>
+         *     <li> {@code group.alignment = alignment} </li>
          * </ul>
          *
-         * @param min       the minimum.
-         * @param alignment the alignment.
+         * @param start     the start index
+         * @param alignment the alignment
          */
-        public Group(int min, Alignment alignment) {
-            this(min, min + 1, alignment);
+        public Group(int start, Alignment alignment) {
+            this(start, 1, alignment);
         }
 
         private Group copyWriteSpan(Interval span) {
@@ -1861,13 +2109,14 @@
         }
 
         /**
-         * Returns true if the {@link #getClass class}, {@link #alignment} and {@link #span}
-         * properties of this Group and the supplied parameter are pairwise equal; false otherwise.
+         * Returns {@code true} if the {@link #getClass class}, {@link #alignment} and {@code span}
+         * properties of this Group and the supplied parameter are pairwise equal,
+         * {@code false} otherwise.
          *
-         * @param that the object to compare this group with.
+         * @param that the object to compare this group with
          *
          * @return {@code true} if the specified object is equal to this
-         *         {@code Group}; {@code false} otherwise.
+         *         {@code Group}; {@code false} otherwise
          */
         @Override
         public boolean equals(Object that) {
@@ -1898,9 +2147,6 @@
         }
     }
 
-    // Alignments
-
-
     /**
      * Alignments specify where a view should be placed within a cell group and
      * what size it should be.
@@ -1910,57 +2156,61 @@
      * {@link Group#alignment alignment}. Overall placement of the view in the cell
      * group is specified by the two alignments which act along each axis independently.
      * <p>
-     * An Alignment implementation must define the {@link #getAlignmentValue(View, int)}
+     * An Alignment implementation must define {@link #getAlignmentValue(View, int, int)},
      * to return the appropriate value for the type of alignment being defined.
      * The enclosing algorithms position the children
-     * so that the values returned from the alignment
+     * so that the locations defined by the alignment values
      * are the same for all of the views in a group.
      * <p>
      *  The GridLayout class defines the most common alignments used in general layout:
      * {@link #TOP}, {@link #LEFT}, {@link #BOTTOM}, {@link #RIGHT}, {@link #CENTER}, {@link
      * #BASELINE} and {@link #FILL}.
      */
-    public static interface Alignment {
+    public static abstract class Alignment {
         /**
          * Returns an alignment value. In the case of vertical alignments the value
          * returned should indicate the distance from the top of the view to the
          * alignment location.
          * For horizontal alignments measurement is made from the left edge of the component.
          *
-         * @param view     the view to which this alignment should be applied.
-         * @param viewSize the measured size of the view.
-         * @return the alignment value.
+         * @param view              the view to which this alignment should be applied
+         * @param viewSize          the measured size of the view
+         * @param measurementType   This parameter is currently unused as GridLayout only supports
+         *                          one type of measurement: {@link View#measure(int, int)}.
+         *
+         * @return                  the alignment value
          */
-        public int getAlignmentValue(View view, int viewSize);
+        public abstract int getAlignmentValue(View view, int viewSize, int measurementType);
 
         /**
          * Returns the size of the view specified by this alignment.
          * In the case of vertical alignments this method should return a height; for
          * horizontal alignments this method should return the width.
+         * <p>
+         * The default implementation returns {@code viewSize}.
          *
-         * @param view     the view to which this alignment should be applied.
-         * @param viewSize the measured size of the view.
-         * @param cellSize the size of the cell into which this view will be placed.
-         * @return the aligned size.
+         * @param view              the view to which this alignment should be applied
+         * @param viewSize          the measured size of the view
+         * @param cellSize          the size of the cell into which this view will be placed
+         * @param measurementType   This parameter is currently unused as GridLayout only supports
+         *                          one type of measurement: {@link View#measure(int, int)}.
+         *
+         * @return                  the aligned size
          */
-        public int getSizeInCell(View view, int viewSize, int cellSize);
-    }
-
-    private static abstract class AbstractAlignment implements Alignment {
-        public int getSizeInCell(View view, int viewSize, int cellSize) {
+        public int getSizeInCell(View view, int viewSize, int cellSize, int measurementType) {
             return viewSize;
         }
     }
 
-    private static final Alignment LEADING = new AbstractAlignment() {
-        public int getAlignmentValue(View view, int viewSize) {
+    private static final Alignment LEADING = new Alignment() {
+        public int getAlignmentValue(View view, int viewSize, int measurementType) {
             return 0;
         }
 
     };
 
-    private static final Alignment TRAILING = new AbstractAlignment() {
-        public int getAlignmentValue(View view, int viewSize) {
+    private static final Alignment TRAILING = new Alignment() {
+        public int getAlignmentValue(View view, int viewSize, int measurementType) {
             return viewSize;
         }
     };
@@ -1994,8 +2244,8 @@
      * This constant may be used in both {@link LayoutParams#rowGroup rowGroups} and {@link
      * LayoutParams#columnGroup columnGroups}.
      */
-    public static final Alignment CENTER = new AbstractAlignment() {
-        public int getAlignmentValue(View view, int viewSize) {
+    public static final Alignment CENTER = new Alignment() {
+        public int getAlignmentValue(View view, int viewSize, int measurementType) {
             return viewSize >> 1;
         }
     };
@@ -2007,14 +2257,17 @@
      *
      * @see View#getBaseline()
      */
-    public static final Alignment BASELINE = new AbstractAlignment() {
-        public int getAlignmentValue(View view, int viewSize) {
+    public static final Alignment BASELINE = new Alignment() {
+        public int getAlignmentValue(View view, int viewSize, int measurementType) {
             if (view == null) {
                 return UNDEFINED;
             }
-            // todo do we need to call measure first?
             int baseline = view.getBaseline();
-            return baseline == -1 ? UNDEFINED : baseline;
+            if (baseline == -1) {
+                return UNDEFINED;
+            } else {
+                return baseline;
+            }
         }
 
     };
@@ -2025,12 +2278,13 @@
      * {@link LayoutParams#columnGroup columnGroups}.
      */
     public static final Alignment FILL = new Alignment() {
-        public int getAlignmentValue(View view, int viewSize) {
+        public int getAlignmentValue(View view, int viewSize, int measurementType) {
             return UNDEFINED;
         }
 
-        public int getSizeInCell(View view, int viewSize, int cellSize) {
+        @Override
+        public int getSizeInCell(View view, int viewSize, int cellSize, int measurementType) {
             return cellSize;
         }
     };
-}
\ No newline at end of file
+}
diff --git a/core/java/android/widget/GridView.java b/core/java/android/widget/GridView.java
index 732cedc..5d406de 100644
--- a/core/java/android/widget/GridView.java
+++ b/core/java/android/widget/GridView.java
@@ -1408,7 +1408,8 @@
         int childLeft;
         final int childTop = flow ? y : y - h;
 
-        final int absoluteGravity = Gravity.getAbsoluteGravity(mGravity,isLayoutRtl());
+        final int layoutDirection = getResolvedLayoutDirection();
+        final int absoluteGravity = Gravity.getAbsoluteGravity(mGravity, layoutDirection);
         switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
             case Gravity.LEFT:
                 childLeft = childrenLeft;
diff --git a/core/java/android/widget/ImageView.java b/core/java/android/widget/ImageView.java
index 4b870ec..161b404 100644
--- a/core/java/android/widget/ImageView.java
+++ b/core/java/android/widget/ImageView.java
@@ -186,9 +186,13 @@
         }
     }
 
+    /**
+     * @hide
+     */
     @Override
-    public boolean isLayoutRtl(Drawable dr) {
-        return (dr == mDrawable) ? isLayoutRtl() : super.isLayoutRtl(dr);
+    public int getResolvedLayoutDirection(Drawable dr) {
+        return (dr == mDrawable) ?
+                getResolvedLayoutDirection() : super.getResolvedLayoutDirection(dr);
     }
 
     @Override
diff --git a/core/java/android/widget/LinearLayout.java b/core/java/android/widget/LinearLayout.java
index 8d449e0..e3bc946 100644
--- a/core/java/android/widget/LinearLayout.java
+++ b/core/java/android/widget/LinearLayout.java
@@ -103,23 +103,39 @@
     @ViewDebug.ExportedProperty(category = "measurement")
     private int mOrientation;
 
-    @ViewDebug.ExportedProperty(category = "measurement", mapping = {
-            @ViewDebug.IntToString(from =  -1,                       to = "NONE"),
-            @ViewDebug.IntToString(from = Gravity.NO_GRAVITY,        to = "NONE"),
-            @ViewDebug.IntToString(from = Gravity.TOP,               to = "TOP"),
-            @ViewDebug.IntToString(from = Gravity.BOTTOM,            to = "BOTTOM"),
-            @ViewDebug.IntToString(from = Gravity.LEFT,              to = "LEFT"),
-            @ViewDebug.IntToString(from = Gravity.RIGHT,             to = "RIGHT"),
-            @ViewDebug.IntToString(from = Gravity.BEFORE,            to = "BEFORE"),
-            @ViewDebug.IntToString(from = Gravity.AFTER,             to = "AFTER"),
-            @ViewDebug.IntToString(from = Gravity.CENTER_VERTICAL,   to = "CENTER_VERTICAL"),
-            @ViewDebug.IntToString(from = Gravity.FILL_VERTICAL,     to = "FILL_VERTICAL"),
-            @ViewDebug.IntToString(from = Gravity.CENTER_HORIZONTAL, to = "CENTER_HORIZONTAL"),
-            @ViewDebug.IntToString(from = Gravity.FILL_HORIZONTAL,   to = "FILL_HORIZONTAL"),
-            @ViewDebug.IntToString(from = Gravity.CENTER,            to = "CENTER"),
-            @ViewDebug.IntToString(from = Gravity.FILL,              to = "FILL")
+    @ViewDebug.ExportedProperty(category = "measurement", flagMapping = {
+            @ViewDebug.FlagToString(mask = -1,
+                equals = -1, name = "NONE"),
+            @ViewDebug.FlagToString(mask = Gravity.NO_GRAVITY,
+                equals = Gravity.NO_GRAVITY,name = "NONE"),
+            @ViewDebug.FlagToString(mask = Gravity.TOP,
+                equals = Gravity.TOP, name = "TOP"),
+            @ViewDebug.FlagToString(mask = Gravity.BOTTOM,
+                equals = Gravity.BOTTOM, name = "BOTTOM"),
+            @ViewDebug.FlagToString(mask = Gravity.LEFT,
+                equals = Gravity.LEFT, name = "LEFT"),
+            @ViewDebug.FlagToString(mask = Gravity.RIGHT,
+                equals = Gravity.RIGHT, name = "RIGHT"),
+            @ViewDebug.FlagToString(mask = Gravity.START,
+                equals = Gravity.START, name = "START"),
+            @ViewDebug.FlagToString(mask = Gravity.END,
+                equals = Gravity.END, name = "END"),
+            @ViewDebug.FlagToString(mask = Gravity.CENTER_VERTICAL,
+                equals = Gravity.CENTER_VERTICAL, name = "CENTER_VERTICAL"),
+            @ViewDebug.FlagToString(mask = Gravity.FILL_VERTICAL,
+                equals = Gravity.FILL_VERTICAL, name = "FILL_VERTICAL"),
+            @ViewDebug.FlagToString(mask = Gravity.CENTER_HORIZONTAL,
+                equals = Gravity.CENTER_HORIZONTAL, name = "CENTER_HORIZONTAL"),
+            @ViewDebug.FlagToString(mask = Gravity.FILL_HORIZONTAL,
+                equals = Gravity.FILL_HORIZONTAL, name = "FILL_HORIZONTAL"),
+            @ViewDebug.FlagToString(mask = Gravity.CENTER,
+                equals = Gravity.CENTER, name = "CENTER"),
+            @ViewDebug.FlagToString(mask = Gravity.FILL,
+                equals = Gravity.FILL, name = "FILL"),
+            @ViewDebug.FlagToString(mask = Gravity.RELATIVE_LAYOUT_DIRECTION,
+                equals = Gravity.RELATIVE_LAYOUT_DIRECTION, name = "RELATIVE")
         })
-    private int mGravity = Gravity.BEFORE | Gravity.TOP;
+    private int mGravity = Gravity.START | Gravity.TOP;
 
     @ViewDebug.ExportedProperty(category = "measurement")
     private int mTotalLength;
@@ -1430,8 +1446,9 @@
                 if (gravity < 0) {
                     gravity = minorGravity;
                 }
-                gravity = Gravity.getAbsoluteGravity(gravity, isLayoutRtl());
-                switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
+                final int layoutDirection = getResolvedLayoutDirection();
+                final int absoluteGravity = Gravity.getAbsoluteGravity(gravity, layoutDirection);
+                switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
                     case Gravity.CENTER_HORIZONTAL:
                         childLeft = paddingLeft + ((childSpace - childWidth) / 2)
                                 + lp.leftMargin - lp.rightMargin;
@@ -1493,7 +1510,8 @@
         final int[] maxAscent = mMaxAscent;
         final int[] maxDescent = mMaxDescent;
 
-        switch (Gravity.getAbsoluteGravity(majorGravity, isLayoutRtl())) {
+        final int layoutDirection = getResolvedLayoutDirection();
+        switch (Gravity.getAbsoluteGravity(majorGravity, layoutDirection)) {
             case Gravity.RIGHT:
                 // mTotalLength contains the padding already
                 childLeft = mPaddingLeft + mRight - mLeft - mTotalLength;
@@ -1633,7 +1651,7 @@
     public void setGravity(int gravity) {
         if (mGravity != gravity) {
             if ((gravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) == 0) {
-                gravity |= Gravity.BEFORE;
+                gravity |= Gravity.START;
             }
 
             if ((gravity & Gravity.VERTICAL_GRAVITY_MASK) == 0) {
@@ -1726,8 +1744,8 @@
             @ViewDebug.IntToString(from = Gravity.BOTTOM,            to = "BOTTOM"),
             @ViewDebug.IntToString(from = Gravity.LEFT,              to = "LEFT"),
             @ViewDebug.IntToString(from = Gravity.RIGHT,             to = "RIGHT"),
-            @ViewDebug.IntToString(from = Gravity.BEFORE,            to = "BEFORE"),
-            @ViewDebug.IntToString(from = Gravity.AFTER,             to = "AFTER"),
+            @ViewDebug.IntToString(from = Gravity.START,            to = "START"),
+            @ViewDebug.IntToString(from = Gravity.END,             to = "END"),
             @ViewDebug.IntToString(from = Gravity.CENTER_VERTICAL,   to = "CENTER_VERTICAL"),
             @ViewDebug.IntToString(from = Gravity.FILL_VERTICAL,     to = "FILL_VERTICAL"),
             @ViewDebug.IntToString(from = Gravity.CENTER_HORIZONTAL, to = "CENTER_HORIZONTAL"),
diff --git a/core/java/android/widget/ProgressBar.java b/core/java/android/widget/ProgressBar.java
index ed9114a..b2c3051 100644
--- a/core/java/android/widget/ProgressBar.java
+++ b/core/java/android/widget/ProgressBar.java
@@ -915,10 +915,13 @@
         }
     }
 
+    /**
+     * @hide
+     */
     @Override
-    public boolean isLayoutRtl(Drawable who) {
+    public int getResolvedLayoutDirection(Drawable who) {
         return (who == mProgressDrawable || who == mIndeterminateDrawable) ?
-            isLayoutRtl() : super.isLayoutRtl(who);
+            getResolvedLayoutDirection() : super.getResolvedLayoutDirection(who);
     }
 
     @Override
diff --git a/core/java/android/widget/RelativeLayout.java b/core/java/android/widget/RelativeLayout.java
index acd8539..a5cf62e 100644
--- a/core/java/android/widget/RelativeLayout.java
+++ b/core/java/android/widget/RelativeLayout.java
@@ -16,6 +16,15 @@
 
 package android.widget;
 
+import com.android.internal.R;
+
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
 import android.content.Context;
 import android.content.res.Resources;
 import android.content.res.TypedArray;
@@ -32,14 +41,6 @@
 import android.view.ViewGroup;
 import android.view.accessibility.AccessibilityEvent;
 import android.widget.RemoteViews.RemoteView;
-import com.android.internal.R;
-
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.SortedSet;
-import java.util.TreeSet;
 
 import static android.util.Log.d;
 
@@ -222,7 +223,7 @@
     public void setGravity(int gravity) {
         if (mGravity != gravity) {
             if ((gravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) == 0) {
-                gravity |= Gravity.BEFORE;
+                gravity |= Gravity.START;
             }
 
             if ((gravity & Gravity.VERTICAL_GRAVITY_MASK) == 0) {
@@ -494,8 +495,9 @@
                     height - mPaddingBottom);
 
             final Rect contentBounds = mContentBounds;
+            final int layoutDirection = getResolvedLayoutDirection();
             Gravity.apply(mGravity, right - left, bottom - top, selfBounds, contentBounds,
-                    isLayoutRtl());
+                    layoutDirection);
 
             final int horizontalOffset = contentBounds.left - left;
             final int verticalOffset = contentBounds.top - top;
@@ -1440,6 +1442,7 @@
             );
 
             private Node mNext;
+            private boolean mIsPooled;
 
             public void setNextPoolable(Node element) {
                 mNext = element;
@@ -1449,6 +1452,14 @@
                 return mNext;
             }
 
+            public boolean isPooled() {
+                return mIsPooled;
+            }
+
+            public void setPooled(boolean isPooled) {
+                mIsPooled = isPooled;
+            }
+
             static Node acquire(View view) {
                 final Node node = sPool.acquire();
                 node.view = view;
diff --git a/core/java/android/widget/RemoteViewsAdapter.java b/core/java/android/widget/RemoteViewsAdapter.java
index 40b0a9c..4c47d37 100644
--- a/core/java/android/widget/RemoteViewsAdapter.java
+++ b/core/java/android/widget/RemoteViewsAdapter.java
@@ -711,6 +711,17 @@
         requestBindService();
     }
 
+    @Override
+    protected void finalize() throws Throwable {
+        try {
+            if (mWorkerThread != null) {
+                mWorkerThread.quit();
+            }
+        } finally {
+            super.finalize();
+        }
+    }
+
     private void loadNextIndexInBackground() {
         mWorkerQueue.post(new Runnable() {
             @Override
diff --git a/core/java/android/widget/SearchView.java b/core/java/android/widget/SearchView.java
index 9933d68..586ece8 100644
--- a/core/java/android/widget/SearchView.java
+++ b/core/java/android/widget/SearchView.java
@@ -93,6 +93,7 @@
     private boolean mClearingFocus;
     private int mMaxWidth;
     private boolean mVoiceButtonEnabled;
+    private CharSequence mUserQuery;
 
     private SearchableInfo mSearchable;
     private Bundle mAppSearchData;
@@ -372,6 +373,7 @@
         mQueryTextView.setText(query);
         if (query != null) {
             mQueryTextView.setSelection(query.length());
+            mUserQuery = query;
         }
 
         // If the query is not empty and submit is requested, submit the query
@@ -885,6 +887,7 @@
 
     private void onTextChanged(CharSequence newText) {
         CharSequence text = mQueryTextView.getText();
+        mUserQuery = text;
         boolean hasText = !TextUtils.isEmpty(text);
         if (isSubmitButtonEnabled()) {
             updateSubmitButton(hasText);
@@ -1124,7 +1127,7 @@
         if (data != null) {
             intent.setData(data);
         }
-        intent.putExtra(SearchManager.USER_QUERY, query);
+        intent.putExtra(SearchManager.USER_QUERY, mUserQuery);
         if (query != null) {
             intent.putExtra(SearchManager.QUERY, query);
         }
diff --git a/core/java/android/widget/Space.java b/core/java/android/widget/Space.java
index d98b937..d7b2ec2 100644
--- a/core/java/android/widget/Space.java
+++ b/core/java/android/widget/Space.java
@@ -72,4 +72,35 @@
     public void setLayoutParams(ViewGroup.LayoutParams params) {
         super.setLayoutParams(params);
     }
+
+    /**
+     * Compare to: {@link View#getDefaultSize(int, int)}
+     * If mode is AT_MOST, return the child size instead of the parent size
+     * (unless it is too big).
+     */
+    private static int getDefaultSize2(int size, int measureSpec) {
+        int result = size;
+        int specMode = MeasureSpec.getMode(measureSpec);
+        int specSize = MeasureSpec.getSize(measureSpec);
+
+        switch (specMode) {
+            case MeasureSpec.UNSPECIFIED:
+                result = size;
+                break;
+            case MeasureSpec.AT_MOST:
+                result = Math.min(size, specSize);
+                break;
+            case MeasureSpec.EXACTLY:
+                result = specSize;
+                break;
+        }
+        return result;
+    }
+
+    @Override
+    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+        setMeasuredDimension(
+                getDefaultSize2(getSuggestedMinimumWidth(), widthMeasureSpec),
+                getDefaultSize2(getSuggestedMinimumHeight(), heightMeasureSpec));
+    }
 }
diff --git a/core/java/android/widget/Switch.java b/core/java/android/widget/Switch.java
index cd4b732..b7565f3 100644
--- a/core/java/android/widget/Switch.java
+++ b/core/java/android/widget/Switch.java
@@ -16,8 +16,6 @@
 
 package android.widget;
 
-import com.android.internal.R;
-
 import android.content.Context;
 import android.content.res.ColorStateList;
 import android.content.res.Resources;
@@ -37,6 +35,8 @@
 import android.view.VelocityTracker;
 import android.view.ViewConfiguration;
 
+import com.android.internal.R;
+
 /**
  * A Switch is a two-state toggle switch widget that can select between two
  * options. The user may drag the "thumb" back and forth to choose the selected option,
@@ -84,6 +84,7 @@
     private Layout mOnLayout;
     private Layout mOffLayout;
 
+    @SuppressWarnings("hiding")
     private final Rect mTempRect = new Rect();
 
     private static final int[] CHECKED_STATE_SET = {
@@ -386,7 +387,7 @@
             case MotionEvent.ACTION_DOWN: {
                 final float x = ev.getX();
                 final float y = ev.getY();
-                if (hitThumb(x, y)) {
+                if (isEnabled() && hitThumb(x, y)) {
                     mTouchMode = TOUCH_MODE_DOWN;
                     mTouchX = x;
                     mTouchY = y;
@@ -459,7 +460,8 @@
      */
     private void stopDrag(MotionEvent ev) {
         mTouchMode = TOUCH_MODE_IDLE;
-        boolean commitChange = ev.getAction() == MotionEvent.ACTION_UP;
+        // Up and not canceled, also checks the switch has not been disabled during the drag
+        boolean commitChange = ev.getAction() == MotionEvent.ACTION_UP && isEnabled();
 
         cancelSuperTouch(ev);
 
diff --git a/core/java/android/widget/TabWidget.java b/core/java/android/widget/TabWidget.java
index 1fe1f79..3d1dedc 100644
--- a/core/java/android/widget/TabWidget.java
+++ b/core/java/android/widget/TabWidget.java
@@ -514,6 +514,12 @@
     }
 
     @Override
+    public void removeAllViews() {
+        super.removeAllViews();
+        mSelectedTab = -1;
+    }
+
+    @Override
     public void sendAccessibilityEventUnchecked(AccessibilityEvent event) {
         // this class fires events only when tabs are focused or selected
         if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED && isFocused()) {
diff --git a/core/java/android/widget/TableRow.java b/core/java/android/widget/TableRow.java
index 5f20c85..3fd4631 100644
--- a/core/java/android/widget/TableRow.java
+++ b/core/java/android/widget/TableRow.java
@@ -224,7 +224,8 @@
                 final int childWidth = child.getMeasuredWidth();
                 lp.mOffset[LayoutParams.LOCATION_NEXT] = columnWidth - childWidth;
 
-                final int absoluteGravity = Gravity.getAbsoluteGravity(gravity, isLayoutRtl());
+                final int layoutDirection = getResolvedLayoutDirection();
+                final int absoluteGravity = Gravity.getAbsoluteGravity(gravity, layoutDirection);
                 switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
                     case Gravity.LEFT:
                         // don't offset on X axis
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index a73a6cf..02c2b8f 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -113,6 +113,7 @@
 import android.view.WindowManager;
 import android.view.accessibility.AccessibilityEvent;
 import android.view.accessibility.AccessibilityManager;
+import android.view.accessibility.AccessibilityNodeInfo;
 import android.view.animation.AnimationUtils;
 import android.view.inputmethod.BaseInputConnection;
 import android.view.inputmethod.CompletionInfo;
@@ -2094,7 +2095,7 @@
      */
     public void setGravity(int gravity) {
         if ((gravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) == 0) {
-            gravity |= Gravity.BEFORE;
+            gravity |= Gravity.START;
         }
         if ((gravity & Gravity.VERTICAL_GRAVITY_MASK) == 0) {
             gravity |= Gravity.TOP;
@@ -2565,6 +2566,9 @@
                     sp.removeSpan(cw);
                 }
 
+                // hideControllers would do it, but it gets called after this method on rotation
+                sp.removeSpan(mSuggestionRangeSpan);
+
                 ss.text = sp;
             } else {
                 ss.text = mText.toString();
@@ -4141,15 +4145,20 @@
         }
     }
 
+    /**
+     * @hide
+     */
     @Override
-    public boolean isLayoutRtl(Drawable who) {
-        if (who == null) return false;
-        final TextView.Drawables drawables = mDrawables;
-        if (who == drawables.mDrawableLeft || who == drawables.mDrawableRight ||
-            who == drawables.mDrawableTop || who == drawables.mDrawableBottom) {
-            return isLayoutRtl();
+    public int getResolvedLayoutDirection(Drawable who) {
+        if (who == null) return View.LAYOUT_DIRECTION_LTR;
+        if (mDrawables != null) {
+            final Drawables drawables = mDrawables;
+            if (who == drawables.mDrawableLeft || who == drawables.mDrawableRight ||
+                who == drawables.mDrawableTop || who == drawables.mDrawableBottom) {
+                return getResolvedLayoutDirection();
+            }
         }
-        return super.isLayoutRtl(who);
+        return super.getResolvedLayoutDirection(who);
     }
 
     @Override
@@ -4391,7 +4400,8 @@
             canvas.translate(compoundPaddingLeft, extendedPaddingTop + voffsetText);
         }
 
-        final int absoluteGravity = Gravity.getAbsoluteGravity(mGravity, isLayoutRtl());
+        final int layoutDirection = getResolvedLayoutDirection();
+        final int absoluteGravity = Gravity.getAbsoluteGravity(mGravity, layoutDirection);
         if (mEllipsize == TextUtils.TruncateAt.MARQUEE) {
             if (!mSingleLine && getLineCount() == 1 && canMarquee() &&
                     (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) != Gravity.LEFT) {
@@ -5539,8 +5549,10 @@
             hintWidth = 0;
         }
 
+        final int layoutDirection = getResolvedLayoutDirection();
+        final int absoluteGravity = Gravity.getAbsoluteGravity(mGravity, layoutDirection);
+
         Layout.Alignment alignment;
-        final int absoluteGravity = Gravity.getAbsoluteGravity(mGravity, isLayoutRtl());
         switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
             case Gravity.CENTER_HORIZONTAL:
                 alignment = Layout.Alignment.ALIGN_CENTER;
@@ -7576,7 +7588,8 @@
                     return 0.0f;
                 }
             } else if (getLineCount() == 1) {
-                final int absoluteGravity = Gravity.getAbsoluteGravity(mGravity, isLayoutRtl());
+                final int layoutDirection = getResolvedLayoutDirection();
+                final int absoluteGravity = Gravity.getAbsoluteGravity(mGravity, layoutDirection);
                 switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
                     case Gravity.LEFT:
                         return 0.0f;
@@ -7600,7 +7613,8 @@
                 final Marquee marquee = mMarquee;
                 return (marquee.mMaxFadeScroll - marquee.mScroll) / getHorizontalFadingEdgeLength();
             } else if (getLineCount() == 1) {
-                final int absoluteGravity = Gravity.getAbsoluteGravity(mGravity, isLayoutRtl());
+                final int layoutDirection = getResolvedLayoutDirection();
+                final int absoluteGravity = Gravity.getAbsoluteGravity(mGravity, layoutDirection);
                 switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
                     case Gravity.LEFT:
                         final int textWidth = (mRight - mLeft) - getCompoundPaddingLeft() -
@@ -7642,7 +7656,18 @@
     protected int computeVerticalScrollExtent() {
         return getHeight() - getCompoundPaddingTop() - getCompoundPaddingBottom();
     }
-    
+
+    @Override
+    public void findViewsWithText(ArrayList<View> outViews, CharSequence text) {
+        CharSequence thisText = getText();
+        if (TextUtils.isEmpty(thisText)) {
+            return;
+        }
+        if (thisText.toString().toLowerCase().contains(text)) {
+            outViews.add(this);
+        }
+    }
+
     public enum BufferType {
         NORMAL, SPANNABLE, EDITABLE,
     }
@@ -7894,6 +7919,17 @@
         event.setPassword(isPassword);
     }
 
+    @Override
+    public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
+        super.onInitializeAccessibilityNodeInfo(info);
+
+        final boolean isPassword = hasPasswordTransformationMethod();
+        if (!isPassword) {
+            info.setText(getText());
+        }
+        info.setPassword(isPassword);
+    }
+
     void sendAccessibilityEventTypeViewTextChanged(CharSequence beforeText,
             int fromIndex, int removedCount, int addedCount) {
         AccessibilityEvent event =
@@ -8538,11 +8574,7 @@
                     final String originalText = mText.subSequence(spanStart, spanEnd).toString();
                     ((Editable) mText).replace(spanStart, spanEnd, suggestion);
 
-                    // Swap text content between actual text and Suggestion span
-                    String[] suggestions = suggestionInfo.suggestionSpan.getSuggestions();
-                    suggestions[suggestionInfo.suggestionIndex] = originalText;
-
-                    // Notify source IME of the suggestion pick
+                    // Notify source IME of the suggestion pick. Do this before swaping texts.
                     if (!TextUtils.isEmpty(
                             suggestionInfo.suggestionSpan.getNotificationTargetClassName())) {
                         InputMethodManager imm = InputMethodManager.peekInstance();
@@ -8550,6 +8582,10 @@
                                 suggestionInfo.suggestionIndex);
                     }
 
+                    // Swap text content between actual text and Suggestion span
+                    String[] suggestions = suggestionInfo.suggestionSpan.getSuggestions();
+                    suggestions[suggestionInfo.suggestionIndex] = originalText;
+
                     // Restore previous SuggestionSpans
                     final int lengthDifference = suggestion.length() - (spanEnd - spanStart);
                     for (int i = 0; i < length; i++) {
@@ -8710,10 +8746,13 @@
             return false;
         }
 
-        boolean currentWordSelected = selectCurrentWord();
-        if (!currentWordSelected) {
-            // No word found under cursor or text selection not permitted.
-            return false;
+        if (!hasSelection()) {
+            // There may already be a selection on device rotation
+            boolean currentWordSelected = selectCurrentWord();
+            if (!currentWordSelected) {
+                // No word found under cursor or text selection not permitted.
+                return false;
+            }
         }
 
         ActionMode.Callback actionModeCallback = new SelectionActionModeCallback();
@@ -8785,10 +8824,22 @@
         public boolean onCreateActionMode(ActionMode mode, Menu menu) {
             TypedArray styledAttributes = mContext.obtainStyledAttributes(R.styleable.Theme);
 
-            mode.setTitle(mContext.getString(com.android.internal.R.string.textSelectionCABTitle));
+            boolean allowText = getContext().getResources().getBoolean(
+                    com.android.internal.R.bool.allow_action_menu_item_text_with_icon);
+
+            mode.setTitle(allowText ? 
+                    mContext.getString(com.android.internal.R.string.textSelectionCABTitle) : null);
             mode.setSubtitle(null);
 
+            int selectAllIconId = 0; // No icon by default
+            if (!allowText) {
+                // Provide an icon, text will not be displayed on smaller screens.
+                selectAllIconId = styledAttributes.getResourceId(
+                        R.styleable.Theme_actionModeSelectAllDrawable, 0);
+            }
+
             menu.add(0, ID_SELECT_ALL, 0, com.android.internal.R.string.selectAll).
+                    setIcon(selectAllIconId).
                     setAlphabeticShortcut('a').
                     setShowAsAction(
                             MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
@@ -9017,6 +9068,8 @@
         private int mContainerPositionX, mContainerPositionY;
         // Visible or not (scrolled off screen), whether or not this handle should be visible
         private boolean mIsActive = false;
+        // Used to detect that setFrame was called
+        private boolean mNeedsUpdate = true;
 
         public HandleView() {
             super(TextView.this.mContext);
@@ -9034,6 +9087,15 @@
             mIdealVerticalOffset = 0.7f * handleHeight;
         }
 
+        @Override
+        protected boolean setFrame(int left, int top, int right, int bottom) {
+            boolean changed = super.setFrame(left, top, right, bottom);
+            // onPreDraw is called for PhoneWindow before the layout of this view is
+            // performed. Make sure to update position, even if container didn't move.
+            if (changed) mNeedsUpdate  = true;
+            return changed;
+        }
+
         protected abstract void initDrawable();
 
         // Touch-up filter: number of previous positions remembered
@@ -9163,6 +9225,13 @@
         public abstract void updatePosition(float x, float y);
 
         protected void positionAtCursorOffset(int offset) {
+            // A HandleView relies on the layout, which may be nulled by external methods.
+            if (mLayout == null) {
+                // Will update controllers' state, hiding them and stopping selection mode if needed
+                prepareCursorControllers();
+                return;
+            }
+
             addPositionToTouchUpFilter(offset);
             final int line = mLayout.getLineForOffset(offset);
             final int lineBottom = mLayout.getLineBottom(line);
@@ -9175,7 +9244,7 @@
             mPositionY += viewportToContentVerticalOffset();
         }
 
-        protected boolean updateContainerPosition() {
+        private void checkForContainerPositionChange() {
             positionAtCursorOffset(getCurrentCursorOffset());
 
             final int previousContainerPositionX = mContainerPositionX;
@@ -9185,12 +9254,13 @@
             mContainerPositionX = mTempCoords[0] + mPositionX;
             mContainerPositionY = mTempCoords[1] + mPositionY;
 
-            return (previousContainerPositionX != mContainerPositionX ||
-                    previousContainerPositionY != mContainerPositionY);
+            mNeedsUpdate |= previousContainerPositionX != mContainerPositionX;
+            mNeedsUpdate |= previousContainerPositionY != mContainerPositionY;
         }
 
         public boolean onPreDraw() {
-            if (updateContainerPosition()) {
+            checkForContainerPositionChange();
+            if (mNeedsUpdate) {
                 if (mIsDragging) {
                     if (mTempCoords[0] != mLastParentX || mTempCoords[1] != mLastParentY) {
                         mTouchToWindowOffsetX += mTempCoords[0] - mLastParentX;
@@ -9214,6 +9284,7 @@
                         dismiss();
                     }
                 }
+                mNeedsUpdate = false;
             }
             return true;
         }
@@ -9294,7 +9365,6 @@
         private static final int RECENT_CUT_COPY_DURATION = 15 * 1000; // seconds
 
         // Used to detect taps on the insertion handle, which will affect the PastePopupWindow
-        private long mTouchTimer;
         private float mDownPositionX, mDownPositionY;
         private PastePopupWindow mPastePopupWindow;
         private Runnable mHider;
@@ -9368,22 +9438,18 @@
                 case MotionEvent.ACTION_DOWN:
                     mDownPositionX = ev.getRawX();
                     mDownPositionY = ev.getRawY();
-                    mTouchTimer = SystemClock.uptimeMillis();
                     break;
 
                 case MotionEvent.ACTION_UP:
-                    long delay = SystemClock.uptimeMillis() - mTouchTimer;
-                    if (delay < ViewConfiguration.getTapTimeout()) {
-                        final float deltaX = mDownPositionX - ev.getRawX();
-                        final float deltaY = mDownPositionY - ev.getRawY();
-                        final float distanceSquared = deltaX * deltaX + deltaY * deltaY;
-                        if (distanceSquared < mSquaredTouchSlopDistance) {
-                            if (mPastePopupWindow != null && mPastePopupWindow.isShowing()) {
-                                // Tapping on the handle dismisses the displayed paste view,
-                                mPastePopupWindow.hide();
-                            } else {
-                                show(0);
-                            }
+                    final float deltaX = mDownPositionX - ev.getRawX();
+                    final float deltaY = mDownPositionY - ev.getRawY();
+                    final float distanceSquared = deltaX * deltaX + deltaY * deltaY;
+                    if (distanceSquared < mSquaredTouchSlopDistance) {
+                        if (mPastePopupWindow != null && mPastePopupWindow.isShowing()) {
+                            // Tapping on the handle dismisses the displayed paste view,
+                            mPastePopupWindow.hide();
+                        } else {
+                            show(0);
                         }
                     }
                     hideDelayed();
@@ -9986,7 +10052,7 @@
 
     private boolean                 mSelectAllOnFocus = false;
 
-    private int                     mGravity = Gravity.TOP | Gravity.LEFT;
+    private int                     mGravity = Gravity.TOP | Gravity.START;
     private boolean                 mHorizontallyScrolling;
 
     private int                     mAutoLinkMask;
diff --git a/core/java/com/android/internal/app/ActionBarImpl.java b/core/java/com/android/internal/app/ActionBarImpl.java
index 6cfeb87..8d5df6f 100644
--- a/core/java/com/android/internal/app/ActionBarImpl.java
+++ b/core/java/com/android/internal/app/ActionBarImpl.java
@@ -156,9 +156,7 @@
         mContextDisplayMode = mActionView.isSplitActionBar() ?
                 CONTEXT_DISPLAY_SPLIT : CONTEXT_DISPLAY_NORMAL;
 
-        TypedArray a = mContext.obtainStyledAttributes(null, R.styleable.ActionBar);
-        mContentHeight = a.getLayoutDimension(R.styleable.ActionBar_height, 0);
-        a.recycle();
+        mContentHeight = mActionView.getContentHeight();
     }
 
     public void onConfigurationChanged(Configuration newConfig) {
@@ -179,9 +177,7 @@
         mActionView.setCollapsable(!mHasEmbeddedTabs &&
                 getNavigationMode() == NAVIGATION_MODE_TABS);
 
-        TypedArray a = mContext.obtainStyledAttributes(null, R.styleable.ActionBar);
-        mContentHeight = a.getLayoutDimension(R.styleable.ActionBar_height, 0);
-        a.recycle();
+        mContentHeight = mActionView.getContentHeight();
 
         if (mTabScrollView != null) {
             mTabScrollView.getLayoutParams().height = mContentHeight;
@@ -362,13 +358,13 @@
         }
 
         mContextView.killMode();
-        ActionMode mode = new ActionModeImpl(callback);
-        if (callback.onCreateActionMode(mode, mode.getMenu())) {
+        ActionModeImpl mode = new ActionModeImpl(callback);
+        if (mode.dispatchOnCreate()) {
             mWasHiddenBeforeMode = !isShowing();
             mode.invalidate();
             mContextView.initForMode(mode);
             animateToMode(true);
-            if (mSplitView != null) {
+            if (mSplitView != null && mContextDisplayMode == CONTEXT_DISPLAY_SPLIT) {
                 // TODO animate this
                 mSplitView.setVisibility(View.VISIBLE);
             }
@@ -526,7 +522,7 @@
                 mContainerView.setTranslationY(-mContainerView.getHeight());
                 b.with(ObjectAnimator.ofFloat(mContainerView, "translationY", 0));
             }
-            if (mSplitView != null) {
+            if (mSplitView != null && mContextDisplayMode == CONTEXT_DISPLAY_SPLIT) {
                 mSplitView.setAlpha(0);
                 b.with(ObjectAnimator.ofFloat(mSplitView, "alpha", 1));
             }
@@ -560,7 +556,7 @@
                 b.with(ObjectAnimator.ofFloat(mContainerView, "translationY",
                         -mContainerView.getHeight()));
             }
-            if (mSplitView != null) {
+            if (mSplitView != null && mSplitView.getVisibility() == View.VISIBLE) {
                 mSplitView.setAlpha(1);
                 b.with(ObjectAnimator.ofFloat(mSplitView, "alpha", 0));
             }
@@ -633,8 +629,20 @@
 
         @Override
         public void invalidate() {
-            if (mCallback.onPrepareActionMode(this, mMenu)) {
-                // Refresh content in both context views
+            mMenu.stopDispatchingItemsChanged();
+            try {
+                mCallback.onPrepareActionMode(this, mMenu);
+            } finally {
+                mMenu.startDispatchingItemsChanged();
+            }
+        }
+
+        public boolean dispatchOnCreate() {
+            mMenu.stopDispatchingItemsChanged();
+            try {
+                return mCallback.onCreateActionMode(this, mMenu);
+            } finally {
+                mMenu.startDispatchingItemsChanged();
             }
         }
 
diff --git a/core/java/com/android/internal/app/AlertController.java b/core/java/com/android/internal/app/AlertController.java
index 71a7a52..8d6caa1 100644
--- a/core/java/com/android/internal/app/AlertController.java
+++ b/core/java/com/android/internal/app/AlertController.java
@@ -575,9 +575,13 @@
         params.weight = 0.5f;
         button.setLayoutParams(params);
         View leftSpacer = mWindow.findViewById(R.id.leftSpacer);
-        leftSpacer.setVisibility(View.VISIBLE);
+        if (leftSpacer != null) {
+            leftSpacer.setVisibility(View.VISIBLE);
+        }
         View rightSpacer = mWindow.findViewById(R.id.rightSpacer);
-        rightSpacer.setVisibility(View.VISIBLE);
+        if (rightSpacer != null) {
+            rightSpacer.setVisibility(View.VISIBLE);
+        }
     }
 
     private void setBackground(LinearLayout topPanel, LinearLayout contentPanel,
diff --git a/core/java/com/android/internal/net/VpnConfig.aidl b/core/java/com/android/internal/net/VpnConfig.aidl
new file mode 100644
index 0000000..be1684c
--- /dev/null
+++ b/core/java/com/android/internal/net/VpnConfig.aidl
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.net;
+
+parcelable VpnConfig;
diff --git a/core/java/com/android/internal/net/VpnConfig.java b/core/java/com/android/internal/net/VpnConfig.java
new file mode 100644
index 0000000..773be5b
--- /dev/null
+++ b/core/java/com/android/internal/net/VpnConfig.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.net;
+
+import android.app.PendingIntent;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Parcel;
+import android.os.Parcelable;
+import android.os.SystemClock;
+
+/**
+ * A simple container used to carry information in VpnBuilder, VpnDialogs,
+ * and com.android.server.connectivity.Vpn. Internal use only.
+ *
+ * @hide
+ */
+public class VpnConfig implements Parcelable {
+
+    public static final String ACTION_VPN_REVOKED = "android.net.vpn.action.REVOKED";
+
+    public static void enforceCallingPackage(String packageName) {
+        if (!"com.android.vpndialogs".equals(packageName)) {
+            throw new SecurityException("Unauthorized Caller");
+        }
+    }
+
+    public static Intent getIntentForConfirmation() {
+        Intent intent = new Intent();
+        intent.setClassName("com.android.vpndialogs", "com.android.vpndialogs.ConfirmDialog");
+        return intent;
+    }
+
+    public static PendingIntent getIntentForNotification(Context context, VpnConfig config) {
+        config.startTime = SystemClock.elapsedRealtime();
+        Intent intent = new Intent();
+        intent.setClassName("com.android.vpndialogs", "com.android.vpndialogs.ManageDialog");
+        intent.putExtra("config", config);
+        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY |
+                Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
+        return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
+    }
+
+    public String packageName;
+    public String sessionName;
+    public String interfaceName;
+    public String configureActivity;
+    public int mtu = -1;
+    public String addresses;
+    public String routes;
+    public String dnsServers;
+    public long startTime = -1;
+
+    @Override
+    public int describeContents() {
+        return 0;
+    }
+
+    @Override
+    public void writeToParcel(Parcel out, int flags) {
+        out.writeString(packageName);
+        out.writeString(sessionName);
+        out.writeString(interfaceName);
+        out.writeString(configureActivity);
+        out.writeInt(mtu);
+        out.writeString(addresses);
+        out.writeString(routes);
+        out.writeString(dnsServers);
+        out.writeLong(startTime);
+    }
+
+    public static final Parcelable.Creator<VpnConfig> CREATOR =
+            new Parcelable.Creator<VpnConfig>() {
+        @Override
+        public VpnConfig createFromParcel(Parcel in) {
+            VpnConfig config = new VpnConfig();
+            config.packageName = in.readString();
+            config.sessionName = in.readString();
+            config.interfaceName = in.readString();
+            config.configureActivity = in.readString();
+            config.mtu = in.readInt();
+            config.addresses = in.readString();
+            config.routes = in.readString();
+            config.dnsServers = in.readString();
+            config.startTime = in.readLong();
+            return config;
+        }
+
+        @Override
+        public VpnConfig[] newArray(int size) {
+            return new VpnConfig[size];
+        }
+    };
+}
diff --git a/core/java/com/android/internal/os/WrapperInit.java b/core/java/com/android/internal/os/WrapperInit.java
index 18d6caa..860a08c 100644
--- a/core/java/com/android/internal/os/WrapperInit.java
+++ b/core/java/com/android/internal/os/WrapperInit.java
@@ -54,6 +54,8 @@
      */
     public static void main(String[] args) {
         try {
+            // Tell the Zygote what our actual PID is (since it only knows about the
+            // wrapper that it directly forked).
             int fdNum = Integer.parseInt(args[0], 10);
             if (fdNum != 0) {
                 try {
@@ -67,6 +69,10 @@
                 }
             }
 
+            // Mimic Zygote preloading.
+            ZygoteInit.preload();
+
+            // Launch the application.
             String[] runtimeArgs = new String[args.length - 1];
             System.arraycopy(args, 1, runtimeArgs, 0, runtimeArgs.length);
             RuntimeInit.wrapperInit(runtimeArgs);
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index 157c0bf..b4a7e52 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -228,6 +228,11 @@
         }
     }
 
+    static void preload() {
+        preloadClasses();
+        preloadResources();
+    }
+
     /**
      * Performs Zygote process initialization. Loads and initializes
      * commonly used classes.
@@ -509,8 +514,7 @@
             registerZygoteSocket();
             EventLog.writeEvent(LOG_BOOT_PROGRESS_PRELOAD_START,
                 SystemClock.uptimeMillis());
-            preloadClasses();
-            preloadResources();
+            preload();
             EventLog.writeEvent(LOG_BOOT_PROGRESS_PRELOAD_END,
                 SystemClock.uptimeMillis());
 
diff --git a/core/java/com/android/internal/os/storage/ExternalStorageFormatter.java b/core/java/com/android/internal/os/storage/ExternalStorageFormatter.java
index 965022e..4773ce4 100644
--- a/core/java/com/android/internal/os/storage/ExternalStorageFormatter.java
+++ b/core/java/com/android/internal/os/storage/ExternalStorageFormatter.java
@@ -14,6 +14,7 @@
 import android.os.storage.IMountService;
 import android.os.storage.StorageEventListener;
 import android.os.storage.StorageManager;
+import android.os.storage.StorageVolume;
 import android.util.Log;
 import android.view.WindowManager;
 import android.widget.Toast;
@@ -32,6 +33,9 @@
 
     public static final String EXTRA_ALWAYS_RESET = "always_reset";
 
+    // If non-null, the volume to format. Otherwise, will use the default external storage directory
+    private StorageVolume mStorageVolume;
+
     public static final ComponentName COMPONENT_NAME
             = new ComponentName("android", ExternalStorageFormatter.class.getName());
 
@@ -80,6 +84,8 @@
             mAlwaysReset = true;
         }
 
+        mStorageVolume = intent.getParcelableExtra(StorageVolume.EXTRA_STORAGE_VOLUME);
+
         if (mProgressDialog == null) {
             mProgressDialog = new ProgressDialog(this);
             mProgressDialog.setIndeterminate(true);
@@ -115,7 +121,9 @@
     @Override
     public void onCancel(DialogInterface dialog) {
         IMountService mountService = getMountService();
-        String extStoragePath = Environment.getExternalStorageDirectory().toString();
+        String extStoragePath = mStorageVolume == null ?
+                Environment.getExternalStorageDirectory().toString() :
+                mStorageVolume.getPath();
         try {
             mountService.mountVolume(extStoragePath);
         } catch (RemoteException e) {
@@ -133,12 +141,16 @@
     }
 
     void updateProgressState() {
-        String status = Environment.getExternalStorageState();
+        String status = mStorageVolume == null ?
+                Environment.getExternalStorageState() :
+                mStorageManager.getVolumeState(mStorageVolume.getPath());
         if (Environment.MEDIA_MOUNTED.equals(status)
                 || Environment.MEDIA_MOUNTED_READ_ONLY.equals(status)) {
             updateProgressDialog(R.string.progress_unmounting);
             IMountService mountService = getMountService();
-            String extStoragePath = Environment.getExternalStorageDirectory().toString();
+            final String extStoragePath = mStorageVolume == null ?
+                    Environment.getExternalStorageDirectory().toString() :
+                    mStorageVolume.getPath();
             try {
                 mountService.unmountVolume(extStoragePath, true);
             } catch (RemoteException e) {
@@ -149,9 +161,12 @@
                 || Environment.MEDIA_UNMOUNTABLE.equals(status)) {
             updateProgressDialog(R.string.progress_erasing);
             final IMountService mountService = getMountService();
-            final String extStoragePath = Environment.getExternalStorageDirectory().toString();
+            final String extStoragePath = mStorageVolume == null ?
+                    Environment.getExternalStorageDirectory().toString() :
+                    mStorageVolume.getPath();
             if (mountService != null) {
                 new Thread() {
+                    @Override
                     public void run() {
                         boolean success = false;
                         try {
@@ -185,7 +200,7 @@
                     }
                 }.start();
             } else {
-                Log.w("MediaFormat", "Unable to locate IMountService");
+                Log.w(TAG, "Unable to locate IMountService");
             }
         } else if (Environment.MEDIA_BAD_REMOVAL.equals(status)) {
             fail(R.string.media_bad_removal);
diff --git a/core/java/com/android/internal/service/wallpaper/ImageWallpaper.java b/core/java/com/android/internal/service/wallpaper/ImageWallpaper.java
index 85095cf..45f3bc1 100644
--- a/core/java/com/android/internal/service/wallpaper/ImageWallpaper.java
+++ b/core/java/com/android/internal/service/wallpaper/ImageWallpaper.java
@@ -25,6 +25,7 @@
 import android.graphics.Rect;
 import android.graphics.Region.Op;
 import android.graphics.drawable.Drawable;
+import android.os.Handler;
 import android.os.HandlerThread;
 import android.os.Looper;
 import android.os.Process;
@@ -46,19 +47,20 @@
 
     WallpaperManager mWallpaperManager;
     private HandlerThread mThread;
+    private Handler mHandler;
 
     @Override
     public void onCreate() {
         super.onCreate();
         mWallpaperManager = (WallpaperManager) getSystemService(WALLPAPER_SERVICE);
         Looper looper = WindowManagerPolicyThread.getLooper();
-        if (looper != null) {
-            setCallbackLooper(looper);
-        } else {
+        if (looper == null) {
             mThread = new HandlerThread("Wallpaper", Process.THREAD_PRIORITY_FOREGROUND);
             mThread.start();
-            setCallbackLooper(mThread.getLooper());
+            looper = mThread.getLooper();
         }
+        setCallbackLooper(looper);
+        mHandler = new Handler(looper);
     }
 
     public Engine onCreateEngine() {
@@ -96,10 +98,6 @@
                     updateWallpaperLocked();
                     drawFrameLocked();
                 }
-
-                // Assume we are the only one using the wallpaper in this
-                // process, and force a GC now to release the old wallpaper.
-                System.gc();
             }
         }
 
@@ -112,7 +110,7 @@
             super.onCreate(surfaceHolder);
             IntentFilter filter = new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED);
             mReceiver = new WallpaperObserver();
-            registerReceiver(mReceiver, filter);
+            registerReceiver(mReceiver, filter, null, mHandler);
 
             updateSurfaceSize(surfaceHolder);
 
diff --git a/core/java/com/android/internal/statusbar/IStatusBar.aidl b/core/java/com/android/internal/statusbar/IStatusBar.aidl
index 7d21489..c11fc10 100644
--- a/core/java/com/android/internal/statusbar/IStatusBar.aidl
+++ b/core/java/com/android/internal/statusbar/IStatusBar.aidl
@@ -31,9 +31,10 @@
     void animateExpand();
     void animateCollapse();
     void setLightsOn(boolean on);
-    void setMenuKeyVisible(boolean visible);
+    void topAppWindowChanged(boolean menuVisible);
     void setImeWindowStatus(in IBinder token, int vis, int backDisposition);
     void setHardKeyboardStatus(boolean available, boolean enabled);
     void userActivity();
+    void toggleRecentApps();
 }
 
diff --git a/core/java/com/android/internal/statusbar/IStatusBarService.aidl b/core/java/com/android/internal/statusbar/IStatusBarService.aidl
index bfc717b..a9e5057 100644
--- a/core/java/com/android/internal/statusbar/IStatusBarService.aidl
+++ b/core/java/com/android/internal/statusbar/IStatusBarService.aidl
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and 
  * limitations under the License.
  */
- 
+
 package com.android.internal.statusbar;
 
 import com.android.internal.statusbar.IStatusBar;
@@ -30,7 +30,7 @@
     void setIcon(String slot, String iconPackage, int iconId, int iconLevel);
     void setIconVisibility(String slot, boolean visible);
     void removeIcon(String slot);
-    void setMenuKeyVisible(boolean visible);
+    void topAppWindowChanged(boolean menuVisible);
     void setImeWindowStatus(in IBinder token, int vis, int backDisposition);
 
     // ---- Methods below are for use by the status bar policy services ----
@@ -47,4 +47,5 @@
     void setSystemUiVisibility(int vis);
     void setHardKeyboardEnabled(boolean enabled);
     void userActivity();
+    void toggleRecentApps();
 }
diff --git a/core/java/com/android/internal/util/HanziToPinyin.java b/core/java/com/android/internal/util/HanziToPinyin.java
deleted file mode 100644
index 6a4adaa..0000000
--- a/core/java/com/android/internal/util/HanziToPinyin.java
+++ /dev/null
@@ -1,495 +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.internal.util;
-
-import android.text.TextUtils;
-import android.util.Log;
-
-import java.text.Collator;
-import java.util.ArrayList;
-import java.util.Locale;
-
-/**
- * An object to convert Chinese character to its corresponding pinyin string.
- * For characters with multiple possible pinyin string, only one is selected
- * according to collator. Polyphone is not supported in this implementation.
- * This class is implemented to achieve the best runtime performance and minimum
- * runtime resources with tolerable sacrifice of accuracy. This implementation
- * highly depends on zh_CN ICU collation data and must be always synchronized with
- * ICU.
- */
-public class HanziToPinyin {
-    private static final String TAG = "HanziToPinyin";
-
-    private static final char[] UNIHANS = {
-            '\u5416', '\u54ce', '\u5b89', '\u80ae', '\u51f9', '\u516b', '\u63b0', '\u6273',
-            '\u90a6', '\u52f9', '\u9642', '\u5954', '\u4f3b', '\u7680', '\u782d', '\u706c',
-            '\u618b', '\u6c43', '\u51ab', '\u7676', '\u5cec', '\u5693', '\u5072', '\u53c2',
-            '\u4ed3', '\u64a1', '\u518a', '\u5d7e', '\u564c', '\u6260', '\u62c6', '\u8fbf',
-            '\u4f25', '\u6284', '\u8f66', '\u62bb', '\u9637', '\u5403', '\u5145', '\u62bd',
-            '\u51fa', '\u640b', '\u5ddb', '\u5205', '\u5439', '\u65fe', '\u8e14', '\u5472',
-            '\u4ece', '\u51d1', '\u7c97', '\u6c46', '\u5d14', '\u90a8', '\u6413', '\u5491',
-            '\u5446', '\u4e39', '\u5f53', '\u5200', '\u6074', '\u6265', '\u706f', '\u4efe',
-            '\u55f2', '\u6541', '\u5201', '\u7239', '\u4e01', '\u4e1f', '\u4e1c', '\u543a',
-            '\u5262', '\u8011', '\u5796', '\u5428', '\u591a', '\u59b8', '\u5940', '\u97a5',
-            '\u800c', '\u53d1', '\u5e06', '\u531a', '\u98de', '\u5206', '\u4e30', '\u8985',
-            '\u4ecf', '\u57ba', '\u7d11', '\u592b', '\u7324', '\u65ee', '\u4f85', '\u5e72',
-            '\u5188', '\u768b', '\u6208', '\u7ed9', '\u6839', '\u63ef', '\u55bc', '\u55f0',
-            '\u5de5', '\u52fe', '\u4f30', '\u9e39', '\u4e56', '\u5173', '\u5149', '\u5f52',
-            '\u4e28', '\u8b34', '\u5459', '\u598e', '\u548d', '\u4f44', '\u592f', '\u8320',
-            '\u8bc3', '\u9ed2', '\u62eb', '\u4ea8', '\u53ff', '\u9f41', '\u4e4e', '\u82b1',
-            '\u6000', '\u6b22', '\u5ddf', '\u7070', '\u660f', '\u5419', '\u4e0c', '\u52a0',
-            '\u620b', '\u6c5f', '\u827d', '\u9636', '\u5dfe', '\u5755', '\u5182', '\u4e29',
-            '\u51e5', '\u59e2', '\u5658', '\u519b', '\u5494', '\u5f00', '\u938e', '\u5ffc',
-            '\u5c3b', '\u533c', '\u808e', '\u52a5', '\u7a7a', '\u62a0', '\u625d', '\u5938',
-            '\u84af', '\u5bbd', '\u5321', '\u4e8f', '\u5764', '\u6269', '\u62c9', '\u4f86',
-            '\u5170', '\u5577', '\u635e', '\u4ec2', '\u96f7', '\u8137', '\u68f1', '\u695e',
-            '\u550e', '\u4fe9', '\u5afe', '\u826f', '\u8e7d', '\u57d3', '\u53b8', '\u62ce',
-            '\u6e9c', '\u9f99', '\u5a04', '\u565c', '\u5b6a', '\u62a1', '\u9831', '\u5988',
-            '\u57cb', '\u989f', '\u7264', '\u732b', '\u5445', '\u95e8', '\u6c13', '\u54aa',
-            '\u5b80', '\u55b5', '\u4e5c', '\u6c11', '\u540d', '\u8c2c', '\u6478', '\u725f',
-            '\u6bcd', '\u62cf', '\u8149', '\u56e1', '\u56d4', '\u5b6c', '\u8bb7', '\u5a1e',
-            '\u5ae9', '\u80fd', '\u92b0', '\u62c8', '\u5a18', '\u9e1f', '\u634f', '\u56dc',
-            '\u5b81', '\u599e', '\u519c', '\u7fba', '\u5974', '\u597b', '\u9ec1', '\u90cd',
-            '\u5662', '\u8bb4', '\u5991', '\u62cd', '\u7705', '\u6c78', '\u629b', '\u5478',
-            '\u55b7', '\u5309', '\u4e76', '\u7247', '\u527d', '\u6c15', '\u59d8', '\u4e52',
-            '\u948b', '\u5256', '\u4ec6', '\u4e03', '\u6390', '\u5343', '\u545b', '\u6084',
-            '\u5207', '\u4eb2', '\u9751', '\u5b86', '\u74d7', '\u533a', '\u5cd1', '\u7094',
-            '\u590b', '\u5465', '\u7a63', '\u835b', '\u60f9', '\u4eba', '\u6254', '\u65e5',
-            '\u620e', '\u53b9', '\u909a', '\u5827', '\u6875', '\u95f0', '\u633c', '\u4ee8',
-            '\u6be2', '\u4e09', '\u6852', '\u63bb', '\u8272', '\u68ee', '\u50e7', '\u6740',
-            '\u7b5b', '\u5c71', '\u4f24', '\u5f30', '\u5962', '\u7533', '\u5347', '\u5c38',
-            '\u53ce', '\u4e66', '\u5237', '\u8870', '\u95e9', '\u53cc', '\u8c01', '\u542e',
-            '\u8bf4', '\u53b6', '\u5fea', '\u51c1', '\u82cf', '\u72fb', '\u590a', '\u5b59',
-            '\u5506', '\u4ed6', '\u5b61', '\u574d', '\u6c64', '\u5932', '\u5fd1', '\u81af',
-            '\u5254', '\u5929', '\u65eb', '\u6017', '\u5385', '\u70b5', '\u5077', '\u51f8',
-            '\u6e4d', '\u63a8', '\u541e', '\u8bac', '\u52b8', '\u6b6a', '\u5f2f', '\u5c23',
-            '\u5371', '\u6637', '\u7fc1', '\u631d', '\u4e4c', '\u5915', '\u5477', '\u4ed9',
-            '\u4e61', '\u7071', '\u4e9b', '\u5fc3', '\u5174', '\u51f6', '\u4f11', '\u620c',
-            '\u5405', '\u75b6', '\u7025', '\u4e2b', '\u54bd', '\u592e', '\u5e7a', '\u503b',
-            '\u4e00', '\u4e5a', '\u5e94', '\u5537', '\u4f63', '\u4f18', '\u7ea1', '\u56e6',
-            '\u66f0', '\u8480', '\u5e00', '\u707d', '\u5142', '\u7242', '\u50ae', '\u556b',
-            '\u9c61', '\u600e', '\u66fd', '\u5412', '\u635a', '\u6cbe', '\u5f20', '\u4f4b',
-            '\u8707', '\u8d1e', '\u9eee', '\u4e4b', '\u4e2d', '\u5dde', '\u6731', '\u6293',
-            '\u62fd', '\u4e13', '\u5986', '\u96b9', '\u5b92', '\u5353', '\u4ed4', '\u5b97',
-            '\u90b9', '\u79df', '\u5297', '\u55fa', '\u5c0a', '\u6628',
-        };
-    private final static byte[][] PINYINS = {
-            {65, 00, 00, 00, 00, 00, }, {65, 73, 00, 00, 00, 00, },
-            {65, 78, 00, 00, 00, 00, }, {65, 78, 71, 00, 00, 00, },
-            {65, 79, 00, 00, 00, 00, }, {66, 65, 00, 00, 00, 00, },
-            {66, 65, 73, 00, 00, 00, }, {66, 65, 78, 00, 00, 00, },
-            {66, 65, 78, 71, 00, 00, }, {66, 65, 79, 00, 00, 00, },
-            {66, 69, 73, 00, 00, 00, }, {66, 69, 78, 00, 00, 00, },
-            {66, 69, 78, 71, 00, 00, }, {66, 73, 00, 00, 00, 00, },
-            {66, 73, 65, 78, 00, 00, }, {66, 73, 65, 79, 00, 00, },
-            {66, 73, 69, 00, 00, 00, }, {66, 73, 78, 00, 00, 00, },
-            {66, 73, 78, 71, 00, 00, }, {66, 79, 00, 00, 00, 00, },
-            {66, 85, 00, 00, 00, 00, }, {67, 65, 00, 00, 00, 00, },
-            {67, 65, 73, 00, 00, 00, }, {67, 65, 78, 00, 00, 00, },
-            {67, 65, 78, 71, 00, 00, }, {67, 65, 79, 00, 00, 00, },
-            {67, 69, 00, 00, 00, 00, }, {67, 69, 78, 00, 00, 00, },
-            {67, 69, 78, 71, 00, 00, }, {67, 72, 65, 00, 00, 00, },
-            {67, 72, 65, 73, 00, 00, }, {67, 72, 65, 78, 00, 00, },
-            {67, 72, 65, 78, 71, 00, }, {67, 72, 65, 79, 00, 00, },
-            {67, 72, 69, 00, 00, 00, }, {67, 72, 69, 78, 00, 00, },
-            {67, 72, 69, 78, 71, 00, }, {67, 72, 73, 00, 00, 00, },
-            {67, 72, 79, 78, 71, 00, }, {67, 72, 79, 85, 00, 00, },
-            {67, 72, 85, 00, 00, 00, }, {67, 72, 85, 65, 73, 00, },
-            {67, 72, 85, 65, 78, 00, }, {67, 72, 85, 65, 78, 71, },
-            {67, 72, 85, 73, 00, 00, }, {67, 72, 85, 78, 00, 00, },
-            {67, 72, 85, 79, 00, 00, }, {67, 73, 00, 00, 00, 00, },
-            {67, 79, 78, 71, 00, 00, }, {67, 79, 85, 00, 00, 00, },
-            {67, 85, 00, 00, 00, 00, }, {67, 85, 65, 78, 00, 00, },
-            {67, 85, 73, 00, 00, 00, }, {67, 85, 78, 00, 00, 00, },
-            {67, 85, 79, 00, 00, 00, }, {68, 65, 00, 00, 00, 00, },
-            {68, 65, 73, 00, 00, 00, }, {68, 65, 78, 00, 00, 00, },
-            {68, 65, 78, 71, 00, 00, }, {68, 65, 79, 00, 00, 00, },
-            {68, 69, 00, 00, 00, 00, }, {68, 69, 78, 00, 00, 00, },
-            {68, 69, 78, 71, 00, 00, }, {68, 73, 00, 00, 00, 00, },
-            {68, 73, 65, 00, 00, 00, }, {68, 73, 65, 78, 00, 00, },
-            {68, 73, 65, 79, 00, 00, }, {68, 73, 69, 00, 00, 00, },
-            {68, 73, 78, 71, 00, 00, }, {68, 73, 85, 00, 00, 00, },
-            {68, 79, 78, 71, 00, 00, }, {68, 79, 85, 00, 00, 00, },
-            {68, 85, 00, 00, 00, 00, }, {68, 85, 65, 78, 00, 00, },
-            {68, 85, 73, 00, 00, 00, }, {68, 85, 78, 00, 00, 00, },
-            {68, 85, 79, 00, 00, 00, }, {69, 00, 00, 00, 00, 00, },
-            {69, 78, 00, 00, 00, 00, }, {69, 78, 71, 00, 00, 00, },
-            {69, 82, 00, 00, 00, 00, }, {70, 65, 00, 00, 00, 00, },
-            {70, 65, 78, 00, 00, 00, }, {70, 65, 78, 71, 00, 00, },
-            {70, 69, 73, 00, 00, 00, }, {70, 69, 78, 00, 00, 00, },
-            {70, 69, 78, 71, 00, 00, }, {70, 73, 65, 79, 00, 00, },
-            {70, 79, 00, 00, 00, 00, }, {70, 85, 00, 00, 00, 00, },
-            {70, 79, 85, 00, 00, 00, }, {70, 85, 00, 00, 00, 00, },
-            {71, 85, 73, 00, 00, 00, }, {71, 65, 00, 00, 00, 00, },
-            {71, 65, 73, 00, 00, 00, }, {71, 65, 78, 00, 00, 00, },
-            {71, 65, 78, 71, 00, 00, }, {71, 65, 79, 00, 00, 00, },
-            {71, 69, 00, 00, 00, 00, }, {71, 69, 73, 00, 00, 00, },
-            {71, 69, 78, 00, 00, 00, }, {71, 69, 78, 71, 00, 00, },
-            {74, 73, 69, 00, 00, 00, }, {71, 69, 00, 00, 00, 00, },
-            {71, 79, 78, 71, 00, 00, }, {71, 79, 85, 00, 00, 00, },
-            {71, 85, 00, 00, 00, 00, }, {71, 85, 65, 00, 00, 00, },
-            {71, 85, 65, 73, 00, 00, }, {71, 85, 65, 78, 00, 00, },
-            {71, 85, 65, 78, 71, 00, }, {71, 85, 73, 00, 00, 00, },
-            {71, 85, 78, 00, 00, 00, }, {71, 85, 65, 78, 00, 00, },
-            {71, 85, 79, 00, 00, 00, }, {72, 65, 00, 00, 00, 00, },
-            {72, 65, 73, 00, 00, 00, }, {72, 65, 78, 00, 00, 00, },
-            {72, 65, 78, 71, 00, 00, }, {72, 65, 79, 00, 00, 00, },
-            {72, 69, 00, 00, 00, 00, }, {72, 69, 73, 00, 00, 00, },
-            {72, 69, 78, 00, 00, 00, }, {72, 69, 78, 71, 00, 00, },
-            {72, 79, 78, 71, 00, 00, }, {72, 79, 85, 00, 00, 00, },
-            {72, 85, 00, 00, 00, 00, }, {72, 85, 65, 00, 00, 00, },
-            {72, 85, 65, 73, 00, 00, }, {72, 85, 65, 78, 00, 00, },
-            {72, 85, 65, 78, 71, 00, }, {72, 85, 73, 00, 00, 00, },
-            {72, 85, 78, 00, 00, 00, }, {72, 85, 79, 00, 00, 00, },
-            {74, 73, 00, 00, 00, 00, }, {74, 73, 65, 00, 00, 00, },
-            {74, 73, 65, 78, 00, 00, }, {74, 73, 65, 78, 71, 00, },
-            {74, 73, 65, 79, 00, 00, }, {74, 73, 69, 00, 00, 00, },
-            {74, 73, 78, 00, 00, 00, }, {74, 73, 78, 71, 00, 00, },
-            {74, 73, 79, 78, 71, 00, }, {74, 73, 85, 00, 00, 00, },
-            {74, 85, 00, 00, 00, 00, }, {74, 85, 65, 78, 00, 00, },
-            {74, 85, 69, 00, 00, 00, }, {74, 85, 78, 00, 00, 00, },
-            {75, 65, 00, 00, 00, 00, }, {75, 65, 73, 00, 00, 00, },
-            {75, 65, 78, 00, 00, 00, }, {75, 65, 78, 71, 00, 00, },
-            {75, 65, 79, 00, 00, 00, }, {75, 69, 00, 00, 00, 00, },
-            {75, 69, 78, 00, 00, 00, }, {75, 69, 78, 71, 00, 00, },
-            {75, 79, 78, 71, 00, 00, }, {75, 79, 85, 00, 00, 00, },
-            {75, 85, 00, 00, 00, 00, }, {75, 85, 65, 00, 00, 00, },
-            {75, 85, 65, 73, 00, 00, }, {75, 85, 65, 78, 00, 00, },
-            {75, 85, 65, 78, 71, 00, }, {75, 85, 73, 00, 00, 00, },
-            {75, 85, 78, 00, 00, 00, }, {75, 85, 79, 00, 00, 00, },
-            {76, 65, 00, 00, 00, 00, }, {76, 65, 73, 00, 00, 00, },
-            {76, 65, 78, 00, 00, 00, }, {76, 65, 78, 71, 00, 00, },
-            {76, 65, 79, 00, 00, 00, }, {76, 69, 00, 00, 00, 00, },
-            {76, 69, 73, 00, 00, 00, }, {76, 73, 00, 00, 00, 00, },
-            {76, 73, 78, 71, 00, 00, }, {76, 69, 78, 71, 00, 00, },
-            {76, 73, 00, 00, 00, 00, }, {76, 73, 65, 00, 00, 00, },
-            {76, 73, 65, 78, 00, 00, }, {76, 73, 65, 78, 71, 00, },
-            {76, 73, 65, 79, 00, 00, }, {76, 73, 69, 00, 00, 00, },
-            {76, 73, 78, 00, 00, 00, }, {76, 73, 78, 71, 00, 00, },
-            {76, 73, 85, 00, 00, 00, }, {76, 79, 78, 71, 00, 00, },
-            {76, 79, 85, 00, 00, 00, }, {76, 85, 00, 00, 00, 00, },
-            {76, 85, 65, 78, 00, 00, }, {76, 85, 78, 00, 00, 00, },
-            {76, 85, 79, 00, 00, 00, }, {77, 65, 00, 00, 00, 00, },
-            {77, 65, 73, 00, 00, 00, }, {77, 65, 78, 00, 00, 00, },
-            {77, 65, 78, 71, 00, 00, }, {77, 65, 79, 00, 00, 00, },
-            {77, 69, 73, 00, 00, 00, }, {77, 69, 78, 00, 00, 00, },
-            {77, 69, 78, 71, 00, 00, }, {77, 73, 00, 00, 00, 00, },
-            {77, 73, 65, 78, 00, 00, }, {77, 73, 65, 79, 00, 00, },
-            {77, 73, 69, 00, 00, 00, }, {77, 73, 78, 00, 00, 00, },
-            {77, 73, 78, 71, 00, 00, }, {77, 73, 85, 00, 00, 00, },
-            {77, 79, 00, 00, 00, 00, }, {77, 79, 85, 00, 00, 00, },
-            {77, 85, 00, 00, 00, 00, }, {78, 65, 00, 00, 00, 00, },
-            {78, 65, 73, 00, 00, 00, }, {78, 65, 78, 00, 00, 00, },
-            {78, 65, 78, 71, 00, 00, }, {78, 65, 79, 00, 00, 00, },
-            {78, 69, 00, 00, 00, 00, }, {78, 69, 73, 00, 00, 00, },
-            {78, 69, 78, 00, 00, 00, }, {78, 69, 78, 71, 00, 00, },
-            {78, 73, 00, 00, 00, 00, }, {78, 73, 65, 78, 00, 00, },
-            {78, 73, 65, 78, 71, 00, }, {78, 73, 65, 79, 00, 00, },
-            {78, 73, 69, 00, 00, 00, }, {78, 73, 78, 00, 00, 00, },
-            {78, 73, 78, 71, 00, 00, }, {78, 73, 85, 00, 00, 00, },
-            {78, 79, 78, 71, 00, 00, }, {78, 79, 85, 00, 00, 00, },
-            {78, 85, 00, 00, 00, 00, }, {78, 85, 65, 78, 00, 00, },
-            {78, 85, 78, 00, 00, 00, }, {78, 85, 79, 00, 00, 00, },
-            {79, 00, 00, 00, 00, 00, }, {79, 85, 00, 00, 00, 00, },
-            {80, 65, 00, 00, 00, 00, }, {80, 65, 73, 00, 00, 00, },
-            {80, 65, 78, 00, 00, 00, }, {80, 65, 78, 71, 00, 00, },
-            {80, 65, 79, 00, 00, 00, }, {80, 69, 73, 00, 00, 00, },
-            {80, 69, 78, 00, 00, 00, }, {80, 69, 78, 71, 00, 00, },
-            {80, 73, 00, 00, 00, 00, }, {80, 73, 65, 78, 00, 00, },
-            {80, 73, 65, 79, 00, 00, }, {80, 73, 69, 00, 00, 00, },
-            {80, 73, 78, 00, 00, 00, }, {80, 73, 78, 71, 00, 00, },
-            {80, 79, 00, 00, 00, 00, }, {80, 79, 85, 00, 00, 00, },
-            {80, 85, 00, 00, 00, 00, }, {81, 73, 00, 00, 00, 00, },
-            {81, 73, 65, 00, 00, 00, }, {81, 73, 65, 78, 00, 00, },
-            {81, 73, 65, 78, 71, 00, }, {81, 73, 65, 79, 00, 00, },
-            {81, 73, 69, 00, 00, 00, }, {81, 73, 78, 00, 00, 00, },
-            {81, 73, 78, 71, 00, 00, }, {81, 73, 79, 78, 71, 00, },
-            {81, 73, 85, 00, 00, 00, }, {81, 85, 00, 00, 00, 00, },
-            {81, 85, 65, 78, 00, 00, }, {81, 85, 69, 00, 00, 00, },
-            {81, 85, 78, 00, 00, 00, }, {82, 65, 78, 00, 00, 00, },
-            {82, 65, 78, 71, 00, 00, }, {82, 65, 79, 00, 00, 00, },
-            {82, 69, 00, 00, 00, 00, }, {82, 69, 78, 00, 00, 00, },
-            {82, 69, 78, 71, 00, 00, }, {82, 73, 00, 00, 00, 00, },
-            {82, 79, 78, 71, 00, 00, }, {82, 79, 85, 00, 00, 00, },
-            {82, 85, 00, 00, 00, 00, }, {82, 85, 65, 78, 00, 00, },
-            {82, 85, 73, 00, 00, 00, }, {82, 85, 78, 00, 00, 00, },
-            {82, 85, 79, 00, 00, 00, }, {83, 65, 00, 00, 00, 00, },
-            {83, 65, 73, 00, 00, 00, }, {83, 65, 78, 00, 00, 00, },
-            {83, 65, 78, 71, 00, 00, }, {83, 65, 79, 00, 00, 00, },
-            {83, 69, 00, 00, 00, 00, }, {83, 69, 78, 00, 00, 00, },
-            {83, 69, 78, 71, 00, 00, }, {83, 72, 65, 00, 00, 00, },
-            {83, 72, 65, 73, 00, 00, }, {83, 72, 65, 78, 00, 00, },
-            {83, 72, 65, 78, 71, 00, }, {83, 72, 65, 79, 00, 00, },
-            {83, 72, 69, 00, 00, 00, }, {83, 72, 69, 78, 00, 00, },
-            {83, 72, 69, 78, 71, 00, }, {83, 72, 73, 00, 00, 00, },
-            {83, 72, 79, 85, 00, 00, }, {83, 72, 85, 00, 00, 00, },
-            {83, 72, 85, 65, 00, 00, }, {83, 72, 85, 65, 73, 00, },
-            {83, 72, 85, 65, 78, 00, }, {83, 72, 85, 65, 78, 71, },
-            {83, 72, 85, 73, 00, 00, }, {83, 72, 85, 78, 00, 00, },
-            {83, 72, 85, 79, 00, 00, }, {83, 73, 00, 00, 00, 00, },
-            {83, 79, 78, 71, 00, 00, }, {83, 79, 85, 00, 00, 00, },
-            {83, 85, 00, 00, 00, 00, }, {83, 85, 65, 78, 00, 00, },
-            {83, 85, 73, 00, 00, 00, }, {83, 85, 78, 00, 00, 00, },
-            {83, 85, 79, 00, 00, 00, }, {84, 65, 00, 00, 00, 00, },
-            {84, 65, 73, 00, 00, 00, }, {84, 65, 78, 00, 00, 00, },
-            {84, 65, 78, 71, 00, 00, }, {84, 65, 79, 00, 00, 00, },
-            {84, 69, 00, 00, 00, 00, }, {84, 69, 78, 71, 00, 00, },
-            {84, 73, 00, 00, 00, 00, }, {84, 73, 65, 78, 00, 00, },
-            {84, 73, 65, 79, 00, 00, }, {84, 73, 69, 00, 00, 00, },
-            {84, 73, 78, 71, 00, 00, }, {84, 79, 78, 71, 00, 00, },
-            {84, 79, 85, 00, 00, 00, }, {84, 85, 00, 00, 00, 00, },
-            {84, 85, 65, 78, 00, 00, }, {84, 85, 73, 00, 00, 00, },
-            {84, 85, 78, 00, 00, 00, }, {84, 85, 79, 00, 00, 00, },
-            {87, 65, 00, 00, 00, 00, }, {87, 65, 73, 00, 00, 00, },
-            {87, 65, 78, 00, 00, 00, }, {87, 65, 78, 71, 00, 00, },
-            {87, 69, 73, 00, 00, 00, }, {87, 69, 78, 00, 00, 00, },
-            {87, 69, 78, 71, 00, 00, }, {87, 79, 00, 00, 00, 00, },
-            {87, 85, 00, 00, 00, 00, }, {88, 73, 00, 00, 00, 00, },
-            {88, 73, 65, 00, 00, 00, }, {88, 73, 65, 78, 00, 00, },
-            {88, 73, 65, 78, 71, 00, }, {88, 73, 65, 79, 00, 00, },
-            {88, 73, 69, 00, 00, 00, }, {88, 73, 78, 00, 00, 00, },
-            {88, 73, 78, 71, 00, 00, }, {88, 73, 79, 78, 71, 00, },
-            {88, 73, 85, 00, 00, 00, }, {88, 85, 00, 00, 00, 00, },
-            {88, 85, 65, 78, 00, 00, }, {88, 85, 69, 00, 00, 00, },
-            {88, 85, 78, 00, 00, 00, }, {89, 65, 00, 00, 00, 00, },
-            {89, 65, 78, 00, 00, 00, }, {89, 65, 78, 71, 00, 00, },
-            {89, 65, 79, 00, 00, 00, }, {89, 69, 00, 00, 00, 00, },
-            {89, 73, 00, 00, 00, 00, }, {89, 73, 78, 00, 00, 00, },
-            {89, 73, 78, 71, 00, 00, }, {89, 79, 00, 00, 00, 00, },
-            {89, 79, 78, 71, 00, 00, }, {89, 79, 85, 00, 00, 00, },
-            {89, 85, 00, 00, 00, 00, }, {89, 85, 65, 78, 00, 00, },
-            {89, 85, 69, 00, 00, 00, }, {89, 85, 78, 00, 00, 00, },
-            {90, 65, 00, 00, 00, 00, }, {90, 65, 73, 00, 00, 00, },
-            {90, 65, 78, 00, 00, 00, }, {90, 65, 78, 71, 00, 00, },
-            {90, 65, 79, 00, 00, 00, }, {90, 69, 00, 00, 00, 00, },
-            {90, 69, 73, 00, 00, 00, }, {90, 69, 78, 00, 00, 00, },
-            {90, 69, 78, 71, 00, 00, }, {90, 72, 65, 00, 00, 00, },
-            {90, 72, 65, 73, 00, 00, }, {90, 72, 65, 78, 00, 00, },
-            {90, 72, 65, 78, 71, 00, }, {90, 72, 65, 79, 00, 00, },
-            {90, 72, 69, 00, 00, 00, }, {90, 72, 69, 78, 00, 00, },
-            {90, 72, 69, 78, 71, 00, }, {90, 72, 73, 00, 00, 00, },
-            {90, 72, 79, 78, 71, 00, }, {90, 72, 79, 85, 00, 00, },
-            {90, 72, 85, 00, 00, 00, }, {90, 72, 85, 65, 00, 00, },
-            {90, 72, 85, 65, 73, 00, }, {90, 72, 85, 65, 78, 00, },
-            {90, 72, 85, 65, 78, 71, }, {90, 72, 85, 73, 00, 00, },
-            {90, 72, 85, 78, 00, 00, }, {90, 72, 85, 79, 00, 00, },
-            {90, 73, 00, 00, 00, 00, }, {90, 79, 78, 71, 00, 00, },
-            {90, 79, 85, 00, 00, 00, }, {90, 85, 00, 00, 00, 00, },
-            {90, 85, 65, 78, 00, 00, }, {90, 85, 73, 00, 00, 00, },
-            {90, 85, 78, 00, 00, 00, }, {90, 85, 79, 00, 00, 00, },
-
-        };
-
-    /** First and last Chinese character with known Pinyin according to zh collation */
-    private static final String FIRST_PINYIN_UNIHAN =  "\u5416";
-    private static final String LAST_PINYIN_UNIHAN =  "\u5497";
-    /** The first Chinese character in Unicode block */
-    private static final char FIRST_UNIHAN = '\u3400';
-    private static final Collator COLLATOR = Collator.getInstance(Locale.CHINA);
-
-    private static HanziToPinyin sInstance;
-    private final boolean mHasChinaCollator;
-
-    public static class Token {
-        /**
-         * Separator between target string for each source char
-         */
-        public static final String SEPARATOR = " ";
-
-        public static final int LATIN = 1;
-        public static final int PINYIN = 2;
-        public static final int UNKNOWN = 3;
-
-        public Token() {
-        }
-
-        public Token(int type, String source, String target) {
-            this.type = type;
-            this.source = source;
-            this.target = target;
-        }
-        /**
-         * Type of this token, ASCII, PINYIN or UNKNOWN.
-         */
-        public int type;
-        /**
-         * Original string before translation.
-         */
-        public String source;
-        /**
-         * Translated string of source. For Han, target is corresponding Pinyin.
-         * Otherwise target is original string in source.
-         */
-        public String target;
-    }
-
-    protected HanziToPinyin(boolean hasChinaCollator) {
-        mHasChinaCollator = hasChinaCollator;
-    }
-
-    public static HanziToPinyin getInstance() {
-        synchronized(HanziToPinyin.class) {
-            if (sInstance != null) {
-                return sInstance;
-            }
-            // Check if zh_CN collation data is available
-            final Locale locale[] = Collator.getAvailableLocales();
-            for (int i = 0; i < locale.length; i++) {
-                if (locale[i].equals(Locale.CHINA)) {
-                    sInstance = new HanziToPinyin(true);
-                    return sInstance;
-                }
-            }
-            Log.w(TAG, "There is no Chinese collator, HanziToPinyin is disabled");
-            sInstance = new HanziToPinyin(false);
-            return sInstance;
-        }
-    }
-
-    private Token getToken(char character) {
-        Token token = new Token();
-        final String letter = Character.toString(character);
-        token.source = letter;
-        int offset = -1;
-        int cmp;
-        if (character < 256) {
-            token.type = Token.LATIN;
-            token.target = letter;
-            return token;
-        } else if (character < FIRST_UNIHAN) {
-            token.type = Token.UNKNOWN;
-            token.target = letter;
-            return token;
-        } else {
-            cmp = COLLATOR.compare(letter, FIRST_PINYIN_UNIHAN);
-            if (cmp < 0) {
-                token.type = Token.UNKNOWN;
-                token.target = letter;
-                return token;
-            } else if (cmp == 0) {
-                token.type = Token.PINYIN;
-                offset = 0;
-            } else {
-                cmp = COLLATOR.compare(letter, LAST_PINYIN_UNIHAN);
-                if (cmp > 0) {
-                    token.type = Token.UNKNOWN;
-                    token.target = letter;
-                    return token;
-                } else if (cmp == 0) {
-                    token.type = Token.PINYIN;
-                    offset = UNIHANS.length - 1;
-                }
-            }
-        }
-
-        token.type = Token.PINYIN;
-        if (offset < 0) {
-            int begin = 0;
-            int end = UNIHANS.length - 1;
-            while (begin <= end) {
-                offset = (begin + end) / 2;
-                final String unihan = Character.toString(UNIHANS[offset]);
-                cmp = COLLATOR.compare(letter, unihan);
-                if (cmp == 0) {
-                    break;
-                } else if (cmp > 0) {
-                    begin = offset + 1;
-                } else {
-                    end = offset - 1;
-                }
-            }
-        }
-        if (cmp < 0) {
-            offset--;
-        }
-        StringBuilder pinyin = new StringBuilder();
-        for (int j = 0; j < PINYINS[offset].length && PINYINS[offset][j] != 0; j++) {
-            pinyin.append((char)PINYINS[offset][j]);
-        }
-        token.target = pinyin.toString();
-        return token;
-    }
-
-    /**
-     * Convert the input to a array of tokens. The sequence of ASCII or Unknown
-     * characters without space will be put into a Token, One Hanzi character 
-     * which has pinyin will be treated as a Token.
-     * If these is no China collator, the empty token array is returned.
-     */
-    public ArrayList<Token> get(final String input) {
-        ArrayList<Token> tokens = new ArrayList<Token>();
-        if (!mHasChinaCollator || TextUtils.isEmpty(input)) {
-            // return empty tokens.
-            return tokens;
-        }
-        final int inputLength = input.length();
-        final StringBuilder sb = new StringBuilder();
-        int tokenType = Token.LATIN;
-        // Go through the input, create a new token when
-        // a. Token type changed
-        // b. Get the Pinyin of current charater.
-        // c. current character is space.
-        for (int i = 0; i < inputLength; i++) {
-            final char character = input.charAt(i);
-            if (character == ' ') {
-                if (sb.length() > 0) {
-                    addToken(sb, tokens, tokenType);
-                }
-            } else if (character < 256) {
-                if (tokenType != Token.LATIN && sb.length() > 0) {
-                    addToken(sb, tokens, tokenType);
-                }
-                tokenType = Token.LATIN;
-                sb.append(character);
-            } else if (character < FIRST_UNIHAN) {
-                if (tokenType != Token.UNKNOWN && sb.length() > 0) {
-                    addToken(sb, tokens, tokenType);
-                }
-                tokenType = Token.UNKNOWN;
-                sb.append(character);
-            } else {
-                Token t = getToken(character);
-                if (t.type == Token.PINYIN) {
-                    if (sb.length() > 0) {
-                        addToken(sb, tokens, tokenType);
-                    }
-                    tokens.add(t);
-                    tokenType = Token.PINYIN;
-                } else {
-                    if (tokenType != t.type && sb.length() > 0) {
-                        addToken(sb, tokens, tokenType);
-                    }
-                    tokenType = t.type;
-                    sb.append(character);
-                }
-            }
-        }
-        if (sb.length() > 0) {
-            addToken(sb, tokens, tokenType);
-        }
-        return tokens;
-    }
-
-    private void addToken(final StringBuilder sb, final ArrayList<Token> tokens,
-            final int tokenType) {
-        String str = sb.toString();
-        tokens.add(new Token(tokenType, str, str));
-        sb.setLength(0);
-    }
-
-}
diff --git a/core/java/com/android/internal/util/Objects.java b/core/java/com/android/internal/util/Objects.java
index 598a079..2664182 100644
--- a/core/java/com/android/internal/util/Objects.java
+++ b/core/java/com/android/internal/util/Objects.java
@@ -16,34 +16,47 @@
 
 package com.android.internal.util;
 
+import java.util.Arrays;
+
 /**
  * Object utility methods.
  */
 public class Objects {
 
     /**
-     * Ensures the given object isn't {@code null}.
+     * Determines whether two possibly-null objects are equal. Returns:
      *
-     * @return the given object
-     * @throws NullPointerException if the object is null
+     * <ul>
+     * <li>{@code true} if {@code a} and {@code b} are both null.
+     * <li>{@code true} if {@code a} and {@code b} are both non-null and they are
+     *     equal according to {@link Object#equals(Object)}.
+     * <li>{@code false} in all other situations.
+     * </ul>
+     *
+     * <p>This assumes that any non-null objects passed to this function conform
+     * to the {@code equals()} contract.
      */
-    public static <T> T nonNull(T t) {
-        if (t == null) {
-            throw new NullPointerException();
-        }
-        return t;
+    public static boolean equal(Object a, Object b) {
+        return a == b || (a != null && a.equals(b));
     }
 
     /**
-     * Ensures the given object isn't {@code null}.
+     * Generates a hash code for multiple values. The hash code is generated by
+     * calling {@link Arrays#hashCode(Object[])}.
      *
-     * @return the given object
-     * @throws NullPointerException if the object is null
+     * <p>This is useful for implementing {@link Object#hashCode()}. For example,
+     * in an object that has three properties, {@code x}, {@code y}, and
+     * {@code z}, one could write:
+     * <pre>
+     * public int hashCode() {
+     *   return Objects.hashCode(getX(), getY(), getZ());
+     * }</pre>
+     *
+     * <b>Warning</b>: When a single object is supplied, the returned hash code
+     * does not equal the hash code of that object.
      */
-    public static <T> T nonNull(T t, String message) {
-        if (t == null) {
-            throw new NullPointerException(message);
-        }
-        return t;
+    public static int hashCode(Object... objects) {
+        return Arrays.hashCode(objects);
     }
+
 }
diff --git a/core/java/com/android/internal/util/Preconditions.java b/core/java/com/android/internal/util/Preconditions.java
new file mode 100644
index 0000000..a53a9c0
--- /dev/null
+++ b/core/java/com/android/internal/util/Preconditions.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.util;
+
+/**
+ * Simple static methods to be called at the start of your own methods to verify
+ * correct arguments and state.
+ */
+public class Preconditions {
+
+    /**
+     * Ensures that an object reference passed as a parameter to the calling
+     * method is not null.
+     *
+     * @param reference an object reference
+     * @return the non-null reference that was validated
+     * @throws NullPointerException if {@code reference} is null
+     */
+    public static <T> T checkNotNull(T reference) {
+        if (reference == null) {
+            throw new NullPointerException();
+        }
+        return reference;
+    }
+
+    /**
+     * Ensures that an object reference passed as a parameter to the calling
+     * method is not null.
+     *
+     * @param reference an object reference
+     * @param errorMessage the exception message to use if the check fails; will
+     *     be converted to a string using {@link String#valueOf(Object)}
+     * @return the non-null reference that was validated
+     * @throws NullPointerException if {@code reference} is null
+     */
+    public static <T> T checkNotNull(T reference, Object errorMessage) {
+        if (reference == null) {
+            throw new NullPointerException(String.valueOf(errorMessage));
+        }
+        return reference;
+    }
+
+}
diff --git a/core/java/com/android/internal/view/BaseIWindow.java b/core/java/com/android/internal/view/BaseIWindow.java
index c41b2cb..b9948fe 100644
--- a/core/java/com/android/internal/view/BaseIWindow.java
+++ b/core/java/com/android/internal/view/BaseIWindow.java
@@ -16,8 +16,6 @@
 
 package com.android.internal.view;
 
-import android.content.ClipData;
-import android.content.ClipDescription;
 import android.content.res.Configuration;
 import android.graphics.Rect;
 import android.os.Bundle;
@@ -26,8 +24,6 @@
 import android.view.DragEvent;
 import android.view.IWindow;
 import android.view.IWindowSession;
-import android.view.KeyEvent;
-import android.view.MotionEvent;
 
 public class BaseIWindow extends IWindow.Stub {
     private IWindowSession mSession;
diff --git a/core/java/com/android/internal/view/IInputMethodManager.aidl b/core/java/com/android/internal/view/IInputMethodManager.aidl
index 8039fda..812f92b 100644
--- a/core/java/com/android/internal/view/IInputMethodManager.aidl
+++ b/core/java/com/android/internal/view/IInputMethodManager.aidl
@@ -68,4 +68,5 @@
     boolean setCurrentInputMethodSubtype(in InputMethodSubtype subtype);
     boolean switchToLastInputMethod(in IBinder token);
     boolean setInputMethodEnabled(String id, boolean enabled);
+    boolean setAdditionalInputMethodSubtypes(in IBinder token, in InputMethodSubtype[] subtypes);
 }
diff --git a/core/java/com/android/internal/view/menu/ActionMenuItem.java b/core/java/com/android/internal/view/menu/ActionMenuItem.java
index 0ef4861..a4bcf60 100644
--- a/core/java/com/android/internal/view/menu/ActionMenuItem.java
+++ b/core/java/com/android/internal/view/menu/ActionMenuItem.java
@@ -236,4 +236,31 @@
     public MenuItem setActionView(int resId) {
         throw new UnsupportedOperationException();
     }
+
+    @Override
+    public MenuItem setShowAsActionFlags(int actionEnum) {
+        setShowAsAction(actionEnum);
+        return this;
+    }
+
+    @Override
+    public boolean expandActionView() {
+        return false;
+    }
+
+    @Override
+    public boolean collapseActionView() {
+        return false;
+    }
+
+    @Override
+    public boolean isActionViewExpanded() {
+        return false;
+    }
+
+    @Override
+    public MenuItem setOnActionExpandListener(OnActionExpandListener listener) {
+        // No need to save the listener; ActionMenuItem does not support collapsing items.
+        return this;
+    }
 }
diff --git a/core/java/com/android/internal/view/menu/ActionMenuItemView.java b/core/java/com/android/internal/view/menu/ActionMenuItemView.java
index beacf75..479788d 100644
--- a/core/java/com/android/internal/view/menu/ActionMenuItemView.java
+++ b/core/java/com/android/internal/view/menu/ActionMenuItemView.java
@@ -18,6 +18,7 @@
 
 import android.content.Context;
 import android.graphics.drawable.Drawable;
+import android.text.TextUtils;
 import android.util.AttributeSet;
 import android.view.View;
 import android.widget.Button;
@@ -103,6 +104,12 @@
         // TODO Support checkable action items
     }
 
+    private void updateTextButtonVisibility() {
+        boolean visible = !TextUtils.isEmpty(mTextButton.getText());
+        visible = visible && (mImageButton.getDrawable() == null || mItemData.showsTextAsAction());
+        mTextButton.setVisibility(visible ? VISIBLE : GONE);
+    }
+
     public void setIcon(Drawable icon) {
         mImageButton.setImageDrawable(icon);
         if (icon != null) {
@@ -111,9 +118,9 @@
             mImageButton.setVisibility(GONE);
         }
 
-        mTextButton.setVisibility(icon == null || mItemData.showsTextAsAction() ? VISIBLE : GONE);
+        updateTextButtonVisibility();
     }
-    
+
     public boolean hasText() {
         return mTextButton.getVisibility() != GONE;
     }
@@ -128,10 +135,9 @@
         // populate accessibility description with title
         setContentDescription(title);
 
-        if (mImageButton.getDrawable() == null || mItemData.showsTextAsAction()) {
-            mTextButton.setText(mTitle);
-            mTextButton.setVisibility(VISIBLE);
-        }
+        mTextButton.setText(mTitle);
+
+        updateTextButtonVisibility();
     }
 
     public boolean showsIcon() {
diff --git a/core/java/com/android/internal/view/menu/ActionMenuPresenter.java b/core/java/com/android/internal/view/menu/ActionMenuPresenter.java
index 0051ec3..98c2747 100644
--- a/core/java/com/android/internal/view/menu/ActionMenuPresenter.java
+++ b/core/java/com/android/internal/view/menu/ActionMenuPresenter.java
@@ -39,10 +39,13 @@
 
     private View mOverflowButton;
     private boolean mReserveOverflow;
+    private boolean mReserveOverflowSet;
     private int mWidthLimit;
     private int mActionItemWidthLimit;
     private int mMaxItems;
+    private boolean mMaxItemsSet;
     private boolean mStrictWidthLimit;
+    private boolean mWidthLimitSet;
 
     // Group IDs that have been added as actions - used temporarily, allocated here for reuse.
     private final SparseBooleanArray mActionButtonGroups = new SparseBooleanArray();
@@ -64,14 +67,21 @@
         super.initForMenu(context, menu);
 
         final Resources res = context.getResources();
-        final int screen = res.getConfiguration().screenLayout;
-        // TODO Use the no-buttons specifier instead here
-        mReserveOverflow = (screen & Configuration.SCREENLAYOUT_SIZE_MASK) ==
-                Configuration.SCREENLAYOUT_SIZE_XLARGE;
-        mWidthLimit = res.getDisplayMetrics().widthPixels / 2;
+
+        if (!mReserveOverflowSet) {
+            // TODO Use the no-buttons specifier instead here
+            mReserveOverflow = res.getConfiguration()
+                    .isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE);
+        }
+
+        if (!mWidthLimitSet) {
+            mWidthLimit = res.getDisplayMetrics().widthPixels / 2;
+        }
 
         // Measure for initial configuration
-        mMaxItems = res.getInteger(com.android.internal.R.integer.max_action_buttons);
+        if (!mMaxItemsSet) {
+            mMaxItems = res.getInteger(com.android.internal.R.integer.max_action_buttons);
+        }
 
         int width = mWidthLimit;
         if (mReserveOverflow) {
@@ -92,15 +102,19 @@
     }
 
     public void setWidthLimit(int width, boolean strict) {
-        if (mReserveOverflow) {
-            width -= mOverflowButton.getMeasuredWidth();
-        }
-        mActionItemWidthLimit = width;
+        mWidthLimit = width;
         mStrictWidthLimit = strict;
+        mWidthLimitSet = true;
+    }
+
+    public void setReserveOverflow(boolean reserveOverflow) {
+        mReserveOverflow = reserveOverflow;
+        mReserveOverflowSet = true;
     }
 
     public void setItemLimit(int itemCount) {
         mMaxItems = itemCount;
+        mMaxItemsSet = true;
     }
 
     @Override
@@ -112,8 +126,11 @@
 
     @Override
     public View getItemView(MenuItemImpl item, View convertView, ViewGroup parent) {
-        final View actionView = item.getActionView();
-        return actionView != null ? actionView : super.getItemView(item, convertView, parent);
+        View actionView = item.getActionView();
+        actionView = actionView != null && !item.hasCollapsibleActionView() ?
+                actionView : super.getItemView(item, convertView, parent);
+        actionView.setVisibility(item.isActionViewExpanded() ? View.GONE : View.VISIBLE);
+        return actionView;
     }
 
     @Override
@@ -303,7 +320,7 @@
 
             if (item.requiresActionButton()) {
                 View v = item.getActionView();
-                if (v == null) {
+                if (v == null || item.hasCollapsibleActionView()) {
                     v = getItemView(item, mScrapActionButtonView, parent);
                     if (mScrapActionButtonView == null) {
                         mScrapActionButtonView = v;
@@ -329,7 +346,7 @@
 
                 if (isAction) {
                     View v = item.getActionView();
-                    if (v == null) {
+                    if (v == null || item.hasCollapsibleActionView()) {
                         v = getItemView(item, mScrapActionButtonView, parent);
                         if (mScrapActionButtonView == null) {
                             mScrapActionButtonView = v;
diff --git a/core/java/com/android/internal/view/menu/BaseMenuPresenter.java b/core/java/com/android/internal/view/menu/BaseMenuPresenter.java
index 16f51fd..ddbb08c 100644
--- a/core/java/com/android/internal/view/menu/BaseMenuPresenter.java
+++ b/core/java/com/android/internal/view/menu/BaseMenuPresenter.java
@@ -192,4 +192,12 @@
     public boolean flagActionItems() {
         return false;
     }
+
+    public boolean expandItemActionView(MenuBuilder menu, MenuItemImpl item) {
+        return false;
+    }
+
+    public boolean collapseItemActionView(MenuBuilder menu, MenuItemImpl item) {
+        return false;
+    }
 }
diff --git a/core/java/com/android/internal/view/menu/IconMenuItemView.java b/core/java/com/android/internal/view/menu/IconMenuItemView.java
index c337a5d..a743cfa 100644
--- a/core/java/com/android/internal/view/menu/IconMenuItemView.java
+++ b/core/java/com/android/internal/view/menu/IconMenuItemView.java
@@ -281,8 +281,10 @@
         Rect tmpRect = mPositionIconOutput;
         getLineBounds(0, tmpRect);
         mPositionIconAvailable.set(0, 0, getWidth(), tmpRect.top);
+        final int layoutDirection = getResolvedLayoutDirection();
         Gravity.apply(Gravity.CENTER_VERTICAL | Gravity.LEFT, mIcon.getIntrinsicWidth(), mIcon
-                .getIntrinsicHeight(), mPositionIconAvailable, mPositionIconOutput, isLayoutRtl());
+                .getIntrinsicHeight(), mPositionIconAvailable, mPositionIconOutput,
+                layoutDirection);
         mIcon.setBounds(mPositionIconOutput);
     }
 
diff --git a/core/java/com/android/internal/view/menu/ListMenuPresenter.java b/core/java/com/android/internal/view/menu/ListMenuPresenter.java
index 2cb2a10..cc09927 100644
--- a/core/java/com/android/internal/view/menu/ListMenuPresenter.java
+++ b/core/java/com/android/internal/view/menu/ListMenuPresenter.java
@@ -159,6 +159,14 @@
         return false;
     }
 
+    public boolean expandItemActionView(MenuBuilder menu, MenuItemImpl item) {
+        return false;
+    }
+
+    public boolean collapseItemActionView(MenuBuilder menu, MenuItemImpl item) {
+        return false;
+    }
+
     public void saveHierarchyState(Bundle outState) {
         SparseArray<Parcelable> viewStates = new SparseArray<Parcelable>();
         if (mMenuView != null) {
@@ -169,7 +177,9 @@
 
     public void restoreHierarchyState(Bundle inState) {
         SparseArray<Parcelable> viewStates = inState.getSparseParcelableArray(VIEWS_TAG);
-        ((View) mMenuView).restoreHierarchyState(viewStates);
+        if (viewStates != null) {
+            ((View) mMenuView).restoreHierarchyState(viewStates);
+        }
     }
 
     private class MenuAdapter extends BaseAdapter {
diff --git a/core/java/com/android/internal/view/menu/MenuBuilder.java b/core/java/com/android/internal/view/menu/MenuBuilder.java
index e9fcb23..fdfa954 100644
--- a/core/java/com/android/internal/view/menu/MenuBuilder.java
+++ b/core/java/com/android/internal/view/menu/MenuBuilder.java
@@ -744,11 +744,14 @@
         
         if (itemImpl == null || !itemImpl.isEnabled()) {
             return false;
-        }        
+        }
         
         boolean invoked = itemImpl.invoke();
 
-        if (item.hasSubMenu()) {
+        if (itemImpl.hasCollapsibleActionView()) {
+            invoked |= itemImpl.expandActionView();
+            if (invoked) close(true);
+        } else if (item.hasSubMenu()) {
             close(false);
 
             invoked |= dispatchSubMenuSelected((SubMenuBuilder) item.getSubMenu());
@@ -1081,4 +1084,42 @@
     boolean getOptionalIconsVisible() {
         return mOptionalIconsVisible;
     }
+
+    public boolean expandItemActionView(MenuItemImpl item) {
+        if (mPresenters.isEmpty()) return false;
+
+        boolean expanded = false;
+
+        stopDispatchingItemsChanged();
+        for (WeakReference<MenuPresenter> ref : mPresenters) {
+            final MenuPresenter presenter = ref.get();
+            if (presenter == null) {
+                mPresenters.remove(ref);
+            } else if ((expanded = presenter.expandItemActionView(this, item))) {
+                break;
+            }
+        }
+        startDispatchingItemsChanged();
+
+        return expanded;
+    }
+
+    public boolean collapseItemActionView(MenuItemImpl item) {
+        if (mPresenters.isEmpty()) return false;
+
+        boolean collapsed = false;
+
+        stopDispatchingItemsChanged();
+        for (WeakReference<MenuPresenter> ref : mPresenters) {
+            final MenuPresenter presenter = ref.get();
+            if (presenter == null) {
+                mPresenters.remove(ref);
+            } else if ((collapsed = presenter.collapseItemActionView(this, item))) {
+                break;
+            }
+        }
+        startDispatchingItemsChanged();
+
+        return collapsed;
+    }
 }
diff --git a/core/java/com/android/internal/view/menu/MenuItemImpl.java b/core/java/com/android/internal/view/menu/MenuItemImpl.java
index c6d386d..1a6cc54 100644
--- a/core/java/com/android/internal/view/menu/MenuItemImpl.java
+++ b/core/java/com/android/internal/view/menu/MenuItemImpl.java
@@ -19,6 +19,7 @@
 import com.android.internal.view.menu.MenuView.ItemView;
 
 import android.content.ActivityNotFoundException;
+import android.content.Context;
 import android.content.Intent;
 import android.graphics.drawable.Drawable;
 import android.util.Log;
@@ -28,6 +29,7 @@
 import android.view.SubMenu;
 import android.view.View;
 import android.view.ViewDebug;
+import android.widget.LinearLayout;
 
 /**
  * @hide
@@ -77,6 +79,8 @@
     private int mShowAsAction = SHOW_AS_ACTION_NEVER;
 
     private View mActionView;
+    private OnActionExpandListener mOnActionExpandListener;
+    private boolean mIsActionViewExpanded = false;
 
     /** Used for the icon resource ID if this item does not have an icon */
     static final int NO_ICON = 0;
@@ -552,13 +556,70 @@
     }
 
     public MenuItem setActionView(int resId) {
-        LayoutInflater inflater = LayoutInflater.from(mMenu.getContext());
-        // TODO - Fix for proper parent. Lazily inflate in the presenter.
-        setActionView(inflater.inflate(resId, null));
+        final Context context = mMenu.getContext();
+        final LayoutInflater inflater = LayoutInflater.from(context);
+        setActionView(inflater.inflate(resId, new LinearLayout(context)));
         return this;
     }
 
     public View getActionView() {
         return mActionView;
     }
+
+    @Override
+    public MenuItem setShowAsActionFlags(int actionEnum) {
+        setShowAsAction(actionEnum);
+        return this;
+    }
+
+    @Override
+    public boolean expandActionView() {
+        if ((mShowAsAction & SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW) == 0 || mActionView == null) {
+            return false;
+        }
+
+        if (mOnActionExpandListener == null ||
+                mOnActionExpandListener.onMenuItemActionExpand(this)) {
+            return mMenu.expandItemActionView(this);
+        }
+
+        return false;
+    }
+
+    @Override
+    public boolean collapseActionView() {
+        if ((mShowAsAction & SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW) == 0) {
+            return false;
+        }
+        if (mActionView == null) {
+            // We're already collapsed if we have no action view.
+            return true;
+        }
+
+        if (mOnActionExpandListener == null ||
+                mOnActionExpandListener.onMenuItemActionCollapse(this)) {
+            return mMenu.collapseItemActionView(this);
+        }
+
+        return false;
+    }
+
+    @Override
+    public MenuItem setOnActionExpandListener(OnActionExpandListener listener) {
+        mOnActionExpandListener = listener;
+        return this;
+    }
+
+    public boolean hasCollapsibleActionView() {
+        return (mShowAsAction & SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW) != 0 && mActionView != null;
+    }
+
+    public void setActionViewExpanded(boolean isExpanded) {
+        mIsActionViewExpanded = isExpanded;
+        mMenu.onItemsChanged(false);
+    }
+
+    public boolean isActionViewExpanded() {
+        return mIsActionViewExpanded;
+    }
 }
diff --git a/core/java/com/android/internal/view/menu/MenuPopupHelper.java b/core/java/com/android/internal/view/menu/MenuPopupHelper.java
index 38cec29..8db7e3c 100644
--- a/core/java/com/android/internal/view/menu/MenuPopupHelper.java
+++ b/core/java/com/android/internal/view/menu/MenuPopupHelper.java
@@ -17,6 +17,7 @@
 package com.android.internal.view.menu;
 
 import android.content.Context;
+import android.content.res.Resources;
 import android.util.DisplayMetrics;
 import android.view.KeyEvent;
 import android.view.LayoutInflater;
@@ -71,8 +72,9 @@
         mMenu = menu;
         mOverflowOnly = overflowOnly;
 
-        final DisplayMetrics metrics = context.getResources().getDisplayMetrics();
-        mPopupMaxWidth = metrics.widthPixels / 2;
+        final Resources res = context.getResources();
+        mPopupMaxWidth = Math.max(res.getDisplayMetrics().widthPixels / 2,
+                res.getDimensionPixelSize(com.android.internal.R.dimen.config_prefDialogWidth));
 
         mAnchorView = anchorView;
 
@@ -250,6 +252,14 @@
         return false;
     }
 
+    public boolean expandItemActionView(MenuBuilder menu, MenuItemImpl item) {
+        return false;
+    }
+
+    public boolean collapseItemActionView(MenuBuilder menu, MenuItemImpl item) {
+        return false;
+    }
+
     private class MenuAdapter extends BaseAdapter {
         private MenuBuilder mAdapterMenu;
 
diff --git a/core/java/com/android/internal/view/menu/MenuPresenter.java b/core/java/com/android/internal/view/menu/MenuPresenter.java
index 5baf419..bd66448 100644
--- a/core/java/com/android/internal/view/menu/MenuPresenter.java
+++ b/core/java/com/android/internal/view/menu/MenuPresenter.java
@@ -107,4 +107,22 @@
      * @return true if this presenter changed the action status of any items.
      */
     public boolean flagActionItems();
+
+    /**
+     * Called when a menu item with a collapsable action view should expand its action view.
+     *
+     * @param menu Menu containing the item to be expanded
+     * @param item Item to be expanded
+     * @return true if this presenter expanded the action view, false otherwise.
+     */
+    public boolean expandItemActionView(MenuBuilder menu, MenuItemImpl item);
+
+    /**
+     * Called when a menu item with a collapsable action view should collapse its action view.
+     *
+     * @param menu Menu containing the item to be collapsed
+     * @param item Item to be collapsed
+     * @return true if this presenter collapsed the action view, false otherwise.
+     */
+    public boolean collapseItemActionView(MenuBuilder menu, MenuItemImpl item);
 }
diff --git a/core/java/com/android/internal/view/menu/SubMenuBuilder.java b/core/java/com/android/internal/view/menu/SubMenuBuilder.java
index 834041f..fb1cd5e 100644
--- a/core/java/com/android/internal/view/menu/SubMenuBuilder.java
+++ b/core/java/com/android/internal/view/menu/SubMenuBuilder.java
@@ -111,4 +111,14 @@
     public SubMenu setHeaderView(View view) {
         return (SubMenu) super.setHeaderViewInt(view);
     }
+
+    @Override
+    public boolean expandItemActionView(MenuItemImpl item) {
+        return mParentMenu.expandItemActionView(item);
+    }
+
+    @Override
+    public boolean collapseItemActionView(MenuItemImpl item) {
+        return mParentMenu.collapseItemActionView(item);
+    }
 }
diff --git a/core/java/com/android/internal/widget/AbsActionBarView.java b/core/java/com/android/internal/widget/AbsActionBarView.java
index 788883b..ccbce3e 100644
--- a/core/java/com/android/internal/widget/AbsActionBarView.java
+++ b/core/java/com/android/internal/widget/AbsActionBarView.java
@@ -30,7 +30,7 @@
 
 public abstract class AbsActionBarView extends ViewGroup {
     protected ActionMenuView mMenuView;
-    protected ActionMenuPresenter mMenuPresenter;
+    protected ActionMenuPresenter mActionMenuPresenter;
     protected ActionBarContainer mSplitView;
 
     protected Animator mVisibilityAnim;
@@ -108,8 +108,8 @@
     }
 
     public boolean showOverflowMenu() {
-        if (mMenuPresenter != null) {
-            return mMenuPresenter.showOverflowMenu();
+        if (mActionMenuPresenter != null) {
+            return mActionMenuPresenter.showOverflowMenu();
         }
         return false;
     }
@@ -123,26 +123,26 @@
     }
 
     public boolean hideOverflowMenu() {
-        if (mMenuPresenter != null) {
-            return mMenuPresenter.hideOverflowMenu();
+        if (mActionMenuPresenter != null) {
+            return mActionMenuPresenter.hideOverflowMenu();
         }
         return false;
     }
 
     public boolean isOverflowMenuShowing() {
-        if (mMenuPresenter != null) {
-            return mMenuPresenter.isOverflowMenuShowing();
+        if (mActionMenuPresenter != null) {
+            return mActionMenuPresenter.isOverflowMenuShowing();
         }
         return false;
     }
 
     public boolean isOverflowReserved() {
-        return mMenuPresenter != null && mMenuPresenter.isOverflowReserved();
+        return mActionMenuPresenter != null && mActionMenuPresenter.isOverflowReserved();
     }
 
     public void dismissPopupMenus() {
-        if (mMenuPresenter != null) {
-            mMenuPresenter.dismissPopupMenus();
+        if (mActionMenuPresenter != null) {
+            mActionMenuPresenter.dismissPopupMenus();
         }
     }
 
diff --git a/core/java/com/android/internal/widget/ActionBarContainer.java b/core/java/com/android/internal/widget/ActionBarContainer.java
index 1726390..d710cfa 100644
--- a/core/java/com/android/internal/widget/ActionBarContainer.java
+++ b/core/java/com/android/internal/widget/ActionBarContainer.java
@@ -16,6 +16,7 @@
 
 package com.android.internal.widget;
 
+import android.app.ActionBar;
 import android.content.Context;
 import android.content.res.TypedArray;
 import android.util.AttributeSet;
@@ -32,6 +33,7 @@
 public class ActionBarContainer extends FrameLayout {
     private boolean mIsTransitioning;
     private View mTabContainer;
+    private ActionBarView mActionBarView;
 
     public ActionBarContainer(Context context) {
         this(context, null);
@@ -46,6 +48,12 @@
         a.recycle();
     }
 
+    @Override
+    public void onFinishInflate() {
+        super.onFinishInflate();
+        mActionBarView = (ActionBarView) findViewById(com.android.internal.R.id.action_bar);
+    }
+
     /**
      * Set the action bar into a "transitioning" state. While transitioning
      * the bar will block focus and touch from all of its descendants. This
@@ -101,9 +109,8 @@
         final int count = getChildCount();
         for (int i = 0; i < count; i++) {
             final View child = getChildAt(i);
-            if (child == mTabContainer) {
-                continue;
-            }
+
+            if (child == mTabContainer) continue;
 
             final LayoutParams lp = (LayoutParams) child.getLayoutParams();
             nonTabHeight = Math.max(nonTabHeight,
@@ -125,8 +132,22 @@
         super.onLayout(changed, l, t, r, b);
         if (mTabContainer != null && mTabContainer.getVisibility() != GONE) {
             final int containerHeight = getMeasuredHeight();
-            mTabContainer.layout(l, containerHeight - mTabContainer.getMeasuredHeight(),
-                    r, containerHeight);
+            final int tabHeight = mTabContainer.getMeasuredHeight();
+
+            if ((mActionBarView.getDisplayOptions() & ActionBar.DISPLAY_SHOW_HOME) == 0) {
+                // Not showing home, put tabs on top.
+                final int count = getChildCount();
+                for (int i = 0; i < count; i++){
+                    final View child = getChildAt(i);
+
+                    if (child == mTabContainer) continue;
+
+                    child.offsetTopAndBottom(tabHeight);
+                }
+                mTabContainer.layout(l, 0, r, tabHeight);
+            } else {
+                mTabContainer.layout(l, containerHeight - tabHeight, r, containerHeight);
+            }
         }
     }
 }
diff --git a/core/java/com/android/internal/widget/ActionBarContextView.java b/core/java/com/android/internal/widget/ActionBarContextView.java
index c82323e..fc43994 100644
--- a/core/java/com/android/internal/widget/ActionBarContextView.java
+++ b/core/java/com/android/internal/widget/ActionBarContextView.java
@@ -15,26 +15,26 @@
  */
 package com.android.internal.widget;
 
-import com.android.internal.R;
-import com.android.internal.view.menu.ActionMenuPresenter;
-import com.android.internal.view.menu.ActionMenuView;
-import com.android.internal.view.menu.MenuBuilder;
-
 import android.animation.Animator;
 import android.animation.Animator.AnimatorListener;
 import android.animation.AnimatorSet;
 import android.animation.ObjectAnimator;
 import android.content.Context;
 import android.content.res.TypedArray;
+import android.text.TextUtils;
 import android.util.AttributeSet;
 import android.view.ActionMode;
 import android.view.LayoutInflater;
 import android.view.View;
-import android.view.ViewGroup.LayoutParams;
 import android.view.animation.DecelerateInterpolator;
 import android.widget.LinearLayout;
 import android.widget.TextView;
 
+import com.android.internal.R;
+import com.android.internal.view.menu.ActionMenuPresenter;
+import com.android.internal.view.menu.ActionMenuView;
+import com.android.internal.view.menu.MenuBuilder;
+
 /**
  * @hide
  */
@@ -130,26 +130,23 @@
             mTitleLayout = (LinearLayout) getChildAt(getChildCount() - 1);
             mTitleView = (TextView) mTitleLayout.findViewById(R.id.action_bar_title);
             mSubtitleView = (TextView) mTitleLayout.findViewById(R.id.action_bar_subtitle);
-            if (mTitle != null) {
-                mTitleView.setText(mTitle);
-                if (mTitleStyleRes != 0) {
-                    mTitleView.setTextAppearance(mContext, mTitleStyleRes);
-                }
+            if (mTitleStyleRes != 0) {
+                mTitleView.setTextAppearance(mContext, mTitleStyleRes);
             }
-            if (mSubtitle != null) {
-                mSubtitleView.setText(mSubtitle);
-                if (mSubtitleStyleRes != 0) {
-                    mSubtitleView.setTextAppearance(mContext, mSubtitleStyleRes);
-                }
-                mSubtitleView.setVisibility(VISIBLE);
+            if (mSubtitleStyleRes != 0) {
+                mSubtitleView.setTextAppearance(mContext, mSubtitleStyleRes);
             }
-        } else {
-            mTitleView.setText(mTitle);
-            mSubtitleView.setText(mSubtitle);
-            mSubtitleView.setVisibility(mSubtitle != null ? VISIBLE : GONE);
-            if (mTitleLayout.getParent() == null) {
-                addView(mTitleLayout);
-            }
+        }
+
+        mTitleView.setText(mTitle);
+        mSubtitleView.setText(mSubtitle);
+
+        final boolean hasTitle = !TextUtils.isEmpty(mTitle);
+        final boolean hasSubtitle = !TextUtils.isEmpty(mSubtitle);
+        mSubtitleView.setVisibility(hasSubtitle ? VISIBLE : GONE);
+        mTitleLayout.setVisibility(hasTitle || hasSubtitle ? VISIBLE : GONE);
+        if (mTitleLayout.getParent() == null) {
+            addView(mTitleLayout);
         }
     }
 
@@ -170,24 +167,27 @@
         });
 
         final MenuBuilder menu = (MenuBuilder) mode.getMenu();
-        mMenuPresenter = new ActionMenuPresenter();
-        menu.addMenuPresenter(mMenuPresenter);
-        mMenuView = (ActionMenuView) mMenuPresenter.getMenuView(this);
+        mActionMenuPresenter = new ActionMenuPresenter();
+        mActionMenuPresenter.setReserveOverflow(true);
 
         final LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT,
                 LayoutParams.MATCH_PARENT);
-        mMenuView.setLayoutParams(layoutParams);
         if (mSplitView == null) {
-            addView(mMenuView);
+            menu.addMenuPresenter(mActionMenuPresenter);
+            mMenuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
+            addView(mMenuView, layoutParams);
         } else {
             // Allow full screen width in split mode.
-            mMenuPresenter.setWidthLimit(
+            mActionMenuPresenter.setWidthLimit(
                     getContext().getResources().getDisplayMetrics().widthPixels, true);
             // No limit to the item count; use whatever will fit.
-            mMenuPresenter.setItemLimit(Integer.MAX_VALUE);
+            mActionMenuPresenter.setItemLimit(Integer.MAX_VALUE);
             // Span the whole width
             layoutParams.width = LayoutParams.MATCH_PARENT;
-            mSplitView.addView(mMenuView);
+            layoutParams.height = mContentHeight;
+            menu.addMenuPresenter(mActionMenuPresenter);
+            mMenuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
+            mSplitView.addView(mMenuView, layoutParams);
         }
 
         mAnimateInOnLayout = true;
@@ -228,23 +228,26 @@
         mAnimateInOnLayout = false;
     }
 
+    @Override
     public boolean showOverflowMenu() {
-        if (mMenuPresenter != null) {
-            return mMenuPresenter.showOverflowMenu();
+        if (mActionMenuPresenter != null) {
+            return mActionMenuPresenter.showOverflowMenu();
         }
         return false;
     }
 
+    @Override
     public boolean hideOverflowMenu() {
-        if (mMenuPresenter != null) {
-            return mMenuPresenter.hideOverflowMenu();
+        if (mActionMenuPresenter != null) {
+            return mActionMenuPresenter.hideOverflowMenu();
         }
         return false;
     }
 
+    @Override
     public boolean isOverflowMenuShowing() {
-        if (mMenuPresenter != null) {
-            return mMenuPresenter.isOverflowMenuShowing();
+        if (mActionMenuPresenter != null) {
+            return mActionMenuPresenter.isOverflowMenuShowing();
         }
         return false;
     }
diff --git a/core/java/com/android/internal/widget/ActionBarView.java b/core/java/com/android/internal/widget/ActionBarView.java
index b7aac14..c475eff 100644
--- a/core/java/com/android/internal/widget/ActionBarView.java
+++ b/core/java/com/android/internal/widget/ActionBarView.java
@@ -21,7 +21,10 @@
 import com.android.internal.view.menu.ActionMenuPresenter;
 import com.android.internal.view.menu.ActionMenuView;
 import com.android.internal.view.menu.MenuBuilder;
+import com.android.internal.view.menu.MenuItemImpl;
 import com.android.internal.view.menu.MenuPresenter;
+import com.android.internal.view.menu.MenuView;
+import com.android.internal.view.menu.SubMenuBuilder;
 
 import android.app.ActionBar;
 import android.app.ActionBar.OnNavigationListener;
@@ -33,21 +36,22 @@
 import android.content.res.Resources;
 import android.content.res.TypedArray;
 import android.graphics.drawable.Drawable;
+import android.os.Parcel;
+import android.os.Parcelable;
 import android.text.TextUtils;
-import android.text.TextUtils.TruncateAt;
 import android.util.AttributeSet;
 import android.util.DisplayMetrics;
 import android.util.Log;
 import android.view.Gravity;
 import android.view.LayoutInflater;
 import android.view.Menu;
+import android.view.MenuItem;
 import android.view.View;
 import android.view.ViewGroup;
 import android.view.ViewParent;
 import android.view.Window;
 import android.widget.AdapterView;
 import android.widget.FrameLayout;
-import android.widget.HorizontalScrollView;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
 import android.widget.ProgressBar;
@@ -87,12 +91,13 @@
     private Drawable mIcon;
     private Drawable mLogo;
 
-    private View mHomeLayout;
-    private View mHomeAsUpView;
-    private ImageView mIconView;
+    private HomeView mHomeLayout;
+    private HomeView mExpandedHomeLayout;
     private LinearLayout mTitleLayout;
     private TextView mTitleView;
     private TextView mSubtitleView;
+    private View mTitleUpView;
+
     private Spinner mSpinner;
     private LinearLayout mListNavLayout;
     private ScrollingTabContainerView mTabScrollView;
@@ -124,6 +129,9 @@
 
     private Runnable mTabSelector;
 
+    private ExpandedActionViewMenuPresenter mExpandedMenuPresenter;
+    View mExpandedActionView;
+
     private final AdapterView.OnItemSelectedListener mNavItemSelectedListener =
             new AdapterView.OnItemSelectedListener() {
         public void onItemSelected(AdapterView parent, View view, int position, long id) {
@@ -136,7 +144,25 @@
         }
     };
 
-    private OnClickListener mTabClickListener = null;
+    private final OnClickListener mExpandedActionViewUpListener = new OnClickListener() {
+        @Override
+        public void onClick(View v) {
+            final MenuItemImpl item = mExpandedMenuPresenter.mCurrentExpandedItem;
+            if (item != null) {
+                item.collapseActionView();
+            }
+        }
+    };
+
+    private final OnClickListener mUpClickListener = new OnClickListener() {
+        public void onClick(View v) {
+            Context context = getContext();
+            if (context instanceof Activity) {
+                Activity activity = (Activity) context;
+                activity.onMenuItemSelected(Window.FEATURE_OPTIONS_PANEL, mLogoNavItem);
+            }
+        }
+    };
 
     public ActionBarView(Context context, AttributeSet attrs) {
         super(context, attrs);
@@ -187,10 +213,11 @@
                 com.android.internal.R.styleable.ActionBar_homeLayout,
                 com.android.internal.R.layout.action_bar_home);
 
-        mHomeLayout = inflater.inflate(homeResId, this, false);
+        mHomeLayout = (HomeView) inflater.inflate(homeResId, this, false);
 
-        mHomeAsUpView = mHomeLayout.findViewById(com.android.internal.R.id.up);
-        mIconView = (ImageView) mHomeLayout.findViewById(com.android.internal.R.id.home);
+        mExpandedHomeLayout = (HomeView) inflater.inflate(homeResId, this, false);
+        mExpandedHomeLayout.setUp(true);
+        mExpandedHomeLayout.setOnClickListener(mExpandedActionViewUpListener);
         
         mTitleStyleRes = a.getResourceId(R.styleable.ActionBar_titleTextStyle, 0);
         mSubtitleStyleRes = a.getResourceId(R.styleable.ActionBar_subtitleTextStyle, 0);
@@ -215,15 +242,7 @@
         a.recycle();
         
         mLogoNavItem = new ActionMenuItem(context, 0, android.R.id.home, 0, 0, mTitle);
-        mHomeLayout.setOnClickListener(new OnClickListener() {
-            public void onClick(View v) {
-                Context context = getContext();
-                if (context instanceof Activity) {
-                    Activity activity = (Activity) context;
-                    activity.onMenuItemSelected(Window.FEATURE_OPTIONS_PANEL, mLogoNavItem);
-                }
-            }
-        });
+        mHomeLayout.setOnClickListener(mUpClickListener);
         mHomeLayout.setClickable(true);
         mHomeLayout.setFocusable(true);
     }
@@ -258,6 +277,10 @@
         requestLayout();
     }
 
+    public int getContentHeight() {
+        return mContentHeight;
+    }
+
     public void setSplitActionBar(boolean splitActionBar) {
         if (mSplitActionBar != splitActionBar) {
             if (mMenuView != null) {
@@ -283,9 +306,12 @@
     }
 
     public void setEmbeddedTabView(ScrollingTabContainerView tabs) {
+        if (mTabScrollView != null) {
+            removeView(mTabScrollView);
+        }
         mTabScrollView = tabs;
         mIncludeTabs = tabs != null;
-        if (mIncludeTabs) {
+        if (mIncludeTabs && mNavigationMode == ActionBar.NAVIGATION_MODE_TABS) {
             addView(mTabScrollView);
         }
     }
@@ -298,7 +324,8 @@
         if (menu == mOptionsMenu) return;
 
         if (mOptionsMenu != null) {
-            mOptionsMenu.removeMenuPresenter(mMenuPresenter);
+            mOptionsMenu.removeMenuPresenter(mActionMenuPresenter);
+            mOptionsMenu.removeMenuPresenter(mExpandedMenuPresenter);
         }
 
         MenuBuilder builder = (MenuBuilder) menu;
@@ -306,29 +333,37 @@
         if (mMenuView != null) {
             removeView(mMenuView);
         }
-        if (mMenuPresenter == null) {
-            mMenuPresenter = new ActionMenuPresenter();
-            mMenuPresenter.setCallback(cb);
+        if (mActionMenuPresenter == null) {
+            mActionMenuPresenter = new ActionMenuPresenter();
+            mActionMenuPresenter.setCallback(cb);
+            mExpandedMenuPresenter = new ExpandedActionViewMenuPresenter();
         }
-        builder.addMenuPresenter(mMenuPresenter);
 
-        final ActionMenuView menuView = (ActionMenuView) mMenuPresenter.getMenuView(this);
+        ActionMenuView menuView;
         final LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT,
                 LayoutParams.MATCH_PARENT);
-        menuView.setLayoutParams(layoutParams);
         if (!mSplitActionBar) {
-            addView(menuView);
+            builder.addMenuPresenter(mActionMenuPresenter);
+            builder.addMenuPresenter(mExpandedMenuPresenter);
+            menuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
+            addView(menuView, layoutParams);
         } else {
             // Allow full screen width in split mode.
-            mMenuPresenter.setWidthLimit(
+            mActionMenuPresenter.setWidthLimit(
                     getContext().getResources().getDisplayMetrics().widthPixels, true);
             // No limit to the item count; use whatever will fit.
-            mMenuPresenter.setItemLimit(Integer.MAX_VALUE);
+            mActionMenuPresenter.setItemLimit(Integer.MAX_VALUE);
             // Span the whole width
             layoutParams.width = LayoutParams.MATCH_PARENT;
+            builder.addMenuPresenter(mActionMenuPresenter);
+            builder.addMenuPresenter(mExpandedMenuPresenter);
+            menuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
             if (mSplitView != null) {
-                mSplitView.addView(menuView);
-            } // We'll add this later if we missed it this time.
+                mSplitView.addView(menuView, layoutParams);
+            } else {
+                // We'll add this later if we missed it this time.
+                menuView.setLayoutParams(layoutParams);
+            }
         }
         mMenuView = menuView;
     }
@@ -407,17 +442,17 @@
         }
 
         if ((flagsChanged & DISPLAY_RELAYOUT_MASK) != 0) {
-            final int vis = (options & ActionBar.DISPLAY_SHOW_HOME) != 0 ? VISIBLE : GONE;
+            final boolean showHome = (options & ActionBar.DISPLAY_SHOW_HOME) != 0;
+            final int vis = showHome ? VISIBLE : GONE;
             mHomeLayout.setVisibility(vis);
 
             if ((flagsChanged & ActionBar.DISPLAY_HOME_AS_UP) != 0) {
-                final boolean isUp = (options & ActionBar.DISPLAY_HOME_AS_UP) != 0;
-                mHomeAsUpView.setVisibility(isUp ? VISIBLE : GONE);
+                mHomeLayout.setUp((options & ActionBar.DISPLAY_HOME_AS_UP) != 0);
             }
 
             if ((flagsChanged & ActionBar.DISPLAY_USE_LOGO) != 0) {
                 final boolean logoVis = mLogo != null && (options & ActionBar.DISPLAY_USE_LOGO) != 0;
-                mIconView.setImageDrawable(logoVis ? mLogo : mIcon);
+                mHomeLayout.setIcon(logoVis ? mLogo : mIcon);
             }
 
             if ((flagsChanged & ActionBar.DISPLAY_SHOW_TITLE) != 0) {
@@ -428,6 +463,14 @@
                 }
             }
 
+            if (mTitleLayout != null && (flagsChanged &
+                    (ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_HOME)) != 0) {
+                final boolean homeAsUp = (options & ActionBar.DISPLAY_HOME_AS_UP) != 0;
+                final boolean titleUp = homeAsUp && !showHome;
+                mTitleUpView.setVisibility(titleUp ? VISIBLE : GONE);
+                mTitleLayout.setEnabled(titleUp);
+            }
+
             if ((flagsChanged & ActionBar.DISPLAY_SHOW_CUSTOM) != 0 && mCustomNavView != null) {
                 if ((options & ActionBar.DISPLAY_SHOW_CUSTOM) != 0) {
                     addView(mCustomNavView);
@@ -457,7 +500,7 @@
         mIcon = icon;
         if (icon != null &&
                 ((mDisplayOptions & ActionBar.DISPLAY_USE_LOGO) == 0 || mLogo == null)) {
-            mIconView.setImageDrawable(icon);
+            mHomeLayout.setIcon(icon);
         }
     }
 
@@ -468,7 +511,7 @@
     public void setLogo(Drawable logo) {
         mLogo = logo;
         if (logo != null && (mDisplayOptions & ActionBar.DISPLAY_USE_LOGO) != 0) {
-            mIconView.setImageDrawable(logo);
+            mHomeLayout.setIcon(logo);
         }
     }
 
@@ -482,7 +525,7 @@
     private int getPreferredIconDensity() {
         final Resources res = mContext.getResources();
         final int availableHeight = getLayoutParams().height -
-                mIconView.getPaddingTop() - mIconView.getPaddingBottom();
+                mHomeLayout.getVerticalIconPadding();
         int iconSize = res.getDimensionPixelSize(android.R.dimen.app_icon_size);
 
         if (iconSize * DisplayMetrics.DENSITY_LOW >= availableHeight) {
@@ -500,7 +543,7 @@
         if (mode != oldMode) {
             switch (oldMode) {
             case ActionBar.NAVIGATION_MODE_LIST:
-                if (mSpinner != null) {
+                if (mListNavLayout != null) {
                     removeView(mListNavLayout);
                 }
                 break;
@@ -607,24 +650,35 @@
     }
     
     private void initTitle() {
-        LayoutInflater inflater = LayoutInflater.from(getContext());
-        mTitleLayout = (LinearLayout) inflater.inflate(R.layout.action_bar_title_item, null);
-        mTitleView = (TextView) mTitleLayout.findViewById(R.id.action_bar_title);
-        mSubtitleView = (TextView) mTitleLayout.findViewById(R.id.action_bar_subtitle);
+        if (mTitleLayout == null) {
+            LayoutInflater inflater = LayoutInflater.from(getContext());
+            mTitleLayout = (LinearLayout) inflater.inflate(R.layout.action_bar_title_item, null);
+            mTitleView = (TextView) mTitleLayout.findViewById(R.id.action_bar_title);
+            mSubtitleView = (TextView) mTitleLayout.findViewById(R.id.action_bar_subtitle);
+            mTitleUpView = (View) mTitleLayout.findViewById(R.id.up);
 
-        if (mTitleStyleRes != 0) {
-            mTitleView.setTextAppearance(mContext, mTitleStyleRes);
-        }
-        if (mTitle != null) {
-            mTitleView.setText(mTitle);
-        }
+            mTitleLayout.setOnClickListener(mUpClickListener);
 
-        if (mSubtitleStyleRes != 0) {
-            mSubtitleView.setTextAppearance(mContext, mSubtitleStyleRes);
-        }
-        if (mSubtitle != null) {
-            mSubtitleView.setText(mSubtitle);
-            mSubtitleView.setVisibility(VISIBLE);
+            if (mTitleStyleRes != 0) {
+                mTitleView.setTextAppearance(mContext, mTitleStyleRes);
+            }
+            if (mTitle != null) {
+                mTitleView.setText(mTitle);
+            }
+
+            if (mSubtitleStyleRes != 0) {
+                mSubtitleView.setTextAppearance(mContext, mSubtitleStyleRes);
+            }
+            if (mSubtitle != null) {
+                mSubtitleView.setText(mSubtitle);
+                mSubtitleView.setVisibility(VISIBLE);
+            }
+
+            final boolean homeAsUp = (mDisplayOptions & ActionBar.DISPLAY_HOME_AS_UP) != 0;
+            final boolean titleUp = homeAsUp &&
+                    (mDisplayOptions & ActionBar.DISPLAY_SHOW_HOME) == 0;
+            mTitleUpView.setVisibility(titleUp ? VISIBLE : GONE);
+            mTitleLayout.setEnabled(titleUp);
         }
 
         addView(mTitleLayout);
@@ -685,10 +739,13 @@
         int leftOfCenter = availableWidth / 2;
         int rightOfCenter = leftOfCenter;
 
-        if (mHomeLayout.getVisibility() != GONE) {
-            mHomeLayout.measure(MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST),
+        View homeLayout = mExpandedActionView != null ? mExpandedHomeLayout : mHomeLayout;
+
+        if (homeLayout.getVisibility() != GONE) {
+            homeLayout.measure(
+                    MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST),
                     MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
-            final int homeWidth = mHomeLayout.getMeasuredWidth();
+            final int homeWidth = homeLayout.getMeasuredWidth();
             availableWidth = Math.max(0, availableWidth - homeWidth);
             leftOfCenter = Math.max(0, availableWidth - homeWidth);
         }
@@ -699,40 +756,42 @@
             rightOfCenter = Math.max(0, rightOfCenter - mMenuView.getMeasuredWidth());
         }
 
-        boolean showTitle = mTitleLayout != null && mTitleLayout.getVisibility() != GONE &&
-                (mDisplayOptions & ActionBar.DISPLAY_SHOW_TITLE) != 0;
-        if (showTitle) {
-            availableWidth = measureChildView(mTitleLayout, availableWidth, childSpecHeight, 0);
-            leftOfCenter = Math.max(0, leftOfCenter - mTitleLayout.getMeasuredWidth());
-        }
+        if (mExpandedActionView == null) {
+            boolean showTitle = mTitleLayout != null && mTitleLayout.getVisibility() != GONE &&
+                    (mDisplayOptions & ActionBar.DISPLAY_SHOW_TITLE) != 0;
+            if (showTitle) {
+                availableWidth = measureChildView(mTitleLayout, availableWidth, childSpecHeight, 0);
+                leftOfCenter = Math.max(0, leftOfCenter - mTitleLayout.getMeasuredWidth());
+            }
 
-        switch (mNavigationMode) {
-        case ActionBar.NAVIGATION_MODE_LIST:
-            if (mListNavLayout != null) {
-                final int itemPaddingSize = showTitle ? mItemPadding * 2 : mItemPadding;
-                availableWidth = Math.max(0, availableWidth - itemPaddingSize);
-                leftOfCenter = Math.max(0, leftOfCenter - itemPaddingSize);
-                mListNavLayout.measure(
-                        MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST),
-                        MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
-                final int listNavWidth = mListNavLayout.getMeasuredWidth();
-                availableWidth = Math.max(0, availableWidth - listNavWidth);
-                leftOfCenter = Math.max(0, leftOfCenter - listNavWidth);
+            switch (mNavigationMode) {
+                case ActionBar.NAVIGATION_MODE_LIST:
+                    if (mListNavLayout != null) {
+                        final int itemPaddingSize = showTitle ? mItemPadding * 2 : mItemPadding;
+                        availableWidth = Math.max(0, availableWidth - itemPaddingSize);
+                        leftOfCenter = Math.max(0, leftOfCenter - itemPaddingSize);
+                        mListNavLayout.measure(
+                                MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST),
+                                MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
+                        final int listNavWidth = mListNavLayout.getMeasuredWidth();
+                        availableWidth = Math.max(0, availableWidth - listNavWidth);
+                        leftOfCenter = Math.max(0, leftOfCenter - listNavWidth);
+                    }
+                    break;
+                case ActionBar.NAVIGATION_MODE_TABS:
+                    if (mTabScrollView != null) {
+                        final int itemPaddingSize = showTitle ? mItemPadding * 2 : mItemPadding;
+                        availableWidth = Math.max(0, availableWidth - itemPaddingSize);
+                        leftOfCenter = Math.max(0, leftOfCenter - itemPaddingSize);
+                        mTabScrollView.measure(
+                                MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST),
+                                MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
+                        final int tabWidth = mTabScrollView.getMeasuredWidth();
+                        availableWidth = Math.max(0, availableWidth - tabWidth);
+                        leftOfCenter = Math.max(0, leftOfCenter - tabWidth);
+                    }
+                    break;
             }
-            break;
-        case ActionBar.NAVIGATION_MODE_TABS:
-            if (mTabScrollView != null) {
-                final int itemPaddingSize = showTitle ? mItemPadding * 2 : mItemPadding;
-                availableWidth = Math.max(0, availableWidth - itemPaddingSize);
-                leftOfCenter = Math.max(0, leftOfCenter - itemPaddingSize);
-                mTabScrollView.measure(
-                        MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST),
-                        MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
-                final int tabWidth = mTabScrollView.getMeasuredWidth();
-                availableWidth = Math.max(0, availableWidth - tabWidth);
-                leftOfCenter = Math.max(0, leftOfCenter - tabWidth);
-            }
-            break;
         }
 
         if (mIndeterminateProgressView != null &&
@@ -743,8 +802,16 @@
                     rightOfCenter - mIndeterminateProgressView.getMeasuredWidth());
         }
 
-        if ((mDisplayOptions & ActionBar.DISPLAY_SHOW_CUSTOM) != 0 && mCustomNavView != null) {
-            final LayoutParams lp = generateLayoutParams(mCustomNavView.getLayoutParams());
+        View customView = null;
+        if (mExpandedActionView != null) {
+            customView = mExpandedActionView;
+        } else if ((mDisplayOptions & ActionBar.DISPLAY_SHOW_CUSTOM) != 0 &&
+                mCustomNavView != null) {
+            customView = mCustomNavView;
+        }
+
+        if (customView != null) {
+            final LayoutParams lp = generateLayoutParams(customView.getLayoutParams());
             final ActionBar.LayoutParams ablp = lp instanceof ActionBar.LayoutParams ?
                     (ActionBar.LayoutParams) lp : null;
 
@@ -781,7 +848,7 @@
                 customNavWidth = Math.min(leftOfCenter, rightOfCenter) * 2;
             }
 
-            mCustomNavView.measure(
+            customView.measure(
                     MeasureSpec.makeMeasureSpec(customNavWidth, customNavWidthMode),
                     MeasureSpec.makeMeasureSpec(customNavHeight, customNavHeightMode));
         }
@@ -822,31 +889,34 @@
             return;
         }
 
-        if (mHomeLayout.getVisibility() != GONE) {
-            x += positionChild(mHomeLayout, x, y, contentHeight);
-        }
-        
-        final boolean showTitle = mTitleLayout != null && mTitleLayout.getVisibility() != GONE &&
-                (mDisplayOptions & ActionBar.DISPLAY_SHOW_TITLE) != 0;
-        if (showTitle) {
-            x += positionChild(mTitleLayout, x, y, contentHeight);
+        View homeLayout = mExpandedActionView != null ? mExpandedHomeLayout : mHomeLayout;
+        if (homeLayout.getVisibility() != GONE) {
+            x += positionChild(homeLayout, x, y, contentHeight);
         }
 
-        switch (mNavigationMode) {
-        case ActionBar.NAVIGATION_MODE_STANDARD:
-            break;
-        case ActionBar.NAVIGATION_MODE_LIST:
-            if (mListNavLayout != null) {
-                if (showTitle) x += mItemPadding;
-                x += positionChild(mListNavLayout, x, y, contentHeight) + mItemPadding;
+        if (mExpandedActionView == null) {
+            final boolean showTitle = mTitleLayout != null && mTitleLayout.getVisibility() != GONE &&
+                    (mDisplayOptions & ActionBar.DISPLAY_SHOW_TITLE) != 0;
+            if (showTitle) {
+                x += positionChild(mTitleLayout, x, y, contentHeight);
             }
-            break;
-        case ActionBar.NAVIGATION_MODE_TABS:
-            if (mTabScrollView != null) {
-                if (showTitle) x += mItemPadding;
-                x += positionChild(mTabScrollView, x, y, contentHeight) + mItemPadding;
+
+            switch (mNavigationMode) {
+                case ActionBar.NAVIGATION_MODE_STANDARD:
+                    break;
+                case ActionBar.NAVIGATION_MODE_LIST:
+                    if (mListNavLayout != null) {
+                        if (showTitle) x += mItemPadding;
+                        x += positionChild(mListNavLayout, x, y, contentHeight) + mItemPadding;
+                    }
+                    break;
+                case ActionBar.NAVIGATION_MODE_TABS:
+                    if (mTabScrollView != null) {
+                        if (showTitle) x += mItemPadding;
+                        x += positionChild(mTabScrollView, x, y, contentHeight) + mItemPadding;
+                    }
+                    break;
             }
-            break;
         }
 
         int menuLeft = r - l - getPaddingRight();
@@ -861,13 +931,20 @@
             menuLeft -= mIndeterminateProgressView.getMeasuredWidth();
         }
 
-        if (mCustomNavView != null && (mDisplayOptions & ActionBar.DISPLAY_SHOW_CUSTOM) != 0) {
-            LayoutParams lp = mCustomNavView.getLayoutParams();
+        View customView = null;
+        if (mExpandedActionView != null) {
+            customView = mExpandedActionView;
+        } else if ((mDisplayOptions & ActionBar.DISPLAY_SHOW_CUSTOM) != 0 &&
+                mCustomNavView != null) {
+            customView = mCustomNavView;
+        }
+        if (customView != null) {
+            LayoutParams lp = customView.getLayoutParams();
             final ActionBar.LayoutParams ablp = lp instanceof ActionBar.LayoutParams ?
                     (ActionBar.LayoutParams) lp : null;
 
             final int gravity = ablp != null ? ablp.gravity : DEFAULT_CUSTOM_GRAVITY;
-            final int navWidth = mCustomNavView.getMeasuredWidth();
+            final int navWidth = customView.getMeasuredWidth();
 
             int topMargin = 0;
             int bottomMargin = 0;
@@ -907,17 +984,17 @@
                 case Gravity.CENTER_VERTICAL:
                     final int paddedTop = mTop + getPaddingTop();
                     final int paddedBottom = mBottom - getPaddingBottom();
-                    ypos = ((paddedBottom - paddedTop) - mCustomNavView.getMeasuredHeight()) / 2;
+                    ypos = ((paddedBottom - paddedTop) - customView.getMeasuredHeight()) / 2;
                     break;
                 case Gravity.TOP:
                     ypos = getPaddingTop() + topMargin;
                     break;
                 case Gravity.BOTTOM:
-                    ypos = getHeight() - getPaddingBottom() - mCustomNavView.getMeasuredHeight()
+                    ypos = getHeight() - getPaddingBottom() - customView.getMeasuredHeight()
                             - bottomMargin;
                     break;
             }
-            x += positionChild(mCustomNavView, xpos, ypos, contentHeight);
+            x += positionChild(customView, xpos, ypos, contentHeight);
         }
 
         if (mProgressView != null) {
@@ -928,9 +1005,83 @@
         }
     }
 
+    @Override
+    public LayoutParams generateLayoutParams(LayoutParams lp) {
+        if (lp == null) {
+            lp = generateDefaultLayoutParams();
+        }
+        return lp;
+    }
+
+    @Override
+    public Parcelable onSaveInstanceState() {
+        Parcelable superState = super.onSaveInstanceState();
+        SavedState state = new SavedState(superState);
+
+        if (mExpandedMenuPresenter != null && mExpandedMenuPresenter.mCurrentExpandedItem != null) {
+            state.expandedMenuItemId = mExpandedMenuPresenter.mCurrentExpandedItem.getItemId();
+        }
+
+        state.isOverflowOpen = isOverflowMenuShowing();
+
+        return state;
+    }
+
+    @Override
+    public void onRestoreInstanceState(Parcelable p) {
+        SavedState state = (SavedState) p;
+
+        super.onRestoreInstanceState(state.getSuperState());
+
+        if (state.expandedMenuItemId != 0 &&
+                mExpandedMenuPresenter != null && mOptionsMenu != null) {
+            final MenuItem item = mOptionsMenu.findItem(state.expandedMenuItemId);
+            if (item != null) {
+                item.expandActionView();
+            }
+        }
+
+        if (state.isOverflowOpen) {
+            postShowOverflowMenu();
+        }
+    }
+
+    static class SavedState extends BaseSavedState {
+        int expandedMenuItemId;
+        boolean isOverflowOpen;
+
+        SavedState(Parcelable superState) {
+            super(superState);
+        }
+
+        private SavedState(Parcel in) {
+            super(in);
+            expandedMenuItemId = in.readInt();
+            isOverflowOpen = in.readInt() != 0;
+        }
+
+        @Override
+        public void writeToParcel(Parcel out, int flags) {
+            super.writeToParcel(out, flags);
+            out.writeInt(expandedMenuItemId);
+            out.writeInt(isOverflowOpen ? 1 : 0);
+        }
+
+        public static final Parcelable.Creator<SavedState> CREATOR =
+                new Parcelable.Creator<SavedState>() {
+            public SavedState createFromParcel(Parcel in) {
+                return new SavedState(in);
+            }
+
+            public SavedState[] newArray(int size) {
+                return new SavedState[size];
+            }
+        };
+    }
+
     private static class HomeView extends FrameLayout {
         private View mUpView;
-        private View mIconView;
+        private ImageView mIconView;
 
         public HomeView(Context context) {
             this(context, null);
@@ -940,12 +1091,24 @@
             super(context, attrs);
         }
 
+        public void setUp(boolean isUp) {
+            mUpView.setVisibility(isUp ? VISIBLE : GONE);
+        }
+
+        public void setIcon(Drawable icon) {
+            mIconView.setImageDrawable(icon);
+        }
+
         @Override
         protected void onFinishInflate() {
             mUpView = findViewById(com.android.internal.R.id.up);
             mIconView = (ImageView) findViewById(com.android.internal.R.id.home);
         }
 
+        public int getVerticalIconPadding() {
+            return mIconView.getPaddingTop() + mIconView.getPaddingBottom();
+        }
+
         @Override
         protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
             measureChildWithMargins(mUpView, widthMeasureSpec, 0, heightMeasureSpec, 0);
@@ -983,4 +1146,115 @@
             mIconView.layout(iconLeft, iconTop, iconLeft + iconWidth, iconTop + iconHeight);
         }
     }
+
+    private class ExpandedActionViewMenuPresenter implements MenuPresenter {
+        MenuBuilder mMenu;
+        MenuItemImpl mCurrentExpandedItem;
+
+        @Override
+        public void initForMenu(Context context, MenuBuilder menu) {
+            // Clear the expanded action view when menus change.
+            mExpandedActionView = null;
+            if (mCurrentExpandedItem != null) {
+                mCurrentExpandedItem.collapseActionView();
+            }
+            mMenu = menu;
+        }
+
+        @Override
+        public MenuView getMenuView(ViewGroup root) {
+            return null;
+        }
+
+        @Override
+        public void updateMenuView(boolean cleared) {
+            // Make sure the expanded item we have is still there.
+            if (mCurrentExpandedItem != null) {
+                boolean found = false;
+                final int count = mMenu.size();
+                for (int i = 0; i < count; i++) {
+                    final MenuItem item = mMenu.getItem(i);
+                    if (item == mCurrentExpandedItem) {
+                        found = true;
+                        break;
+                    }
+                }
+
+                if (!found) {
+                    // The item we had expanded disappeared. Collapse.
+                    collapseItemActionView(mMenu, mCurrentExpandedItem);
+                }
+            }
+        }
+
+        @Override
+        public void setCallback(Callback cb) {
+        }
+
+        @Override
+        public boolean onSubMenuSelected(SubMenuBuilder subMenu) {
+            return false;
+        }
+
+        @Override
+        public void onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing) {
+        }
+
+        @Override
+        public boolean flagActionItems() {
+            return false;
+        }
+
+        @Override
+        public boolean expandItemActionView(MenuBuilder menu, MenuItemImpl item) {
+            mExpandedActionView = item.getActionView();
+            mExpandedHomeLayout.setIcon(item.getIcon());
+            mCurrentExpandedItem = item;
+            if (mExpandedActionView.getParent() != ActionBarView.this) {
+                addView(mExpandedActionView);
+            }
+            if (mExpandedHomeLayout.getParent() != ActionBarView.this) {
+                addView(mExpandedHomeLayout);
+            }
+            mHomeLayout.setVisibility(GONE);
+            if (mTitleLayout != null) mTitleLayout.setVisibility(GONE);
+            if (mTabScrollView != null) mTabScrollView.setVisibility(GONE);
+            if (mSpinner != null) mSpinner.setVisibility(GONE);
+            if (mCustomNavView != null) mCustomNavView.setVisibility(GONE);
+            requestLayout();
+            item.setActionViewExpanded(true);
+            return true;
+        }
+
+        @Override
+        public boolean collapseItemActionView(MenuBuilder menu, MenuItemImpl item) {
+            removeView(mExpandedActionView);
+            removeView(mExpandedHomeLayout);
+            if ((mDisplayOptions & ActionBar.DISPLAY_SHOW_HOME) != 0) {
+                mHomeLayout.setVisibility(VISIBLE);
+            }
+            if ((mDisplayOptions & ActionBar.DISPLAY_SHOW_TITLE) != 0) {
+                if (mTitleLayout == null) {
+                    initTitle();
+                } else {
+                    mTitleLayout.setVisibility(VISIBLE);
+                }
+            }
+            if (mTabScrollView != null && mNavigationMode == ActionBar.NAVIGATION_MODE_TABS) {
+                mTabScrollView.setVisibility(VISIBLE);
+            }
+            if (mSpinner != null && mNavigationMode == ActionBar.NAVIGATION_MODE_LIST) {
+                mSpinner.setVisibility(VISIBLE);
+            }
+            if (mCustomNavView != null && (mDisplayOptions & ActionBar.DISPLAY_SHOW_CUSTOM) != 0) {
+                mCustomNavView.setVisibility(VISIBLE);
+            }
+            mExpandedActionView = null;
+            mExpandedHomeLayout.setIcon(null);
+            mCurrentExpandedItem = null;
+            requestLayout();
+            item.setActionViewExpanded(false);
+            return true;
+        }
+    }
 }
diff --git a/core/java/com/android/internal/widget/DialogTitle.java b/core/java/com/android/internal/widget/DialogTitle.java
index 125d2c5..cd165dc 100644
--- a/core/java/com/android/internal/widget/DialogTitle.java
+++ b/core/java/com/android/internal/widget/DialogTitle.java
@@ -54,15 +54,19 @@
                 if (ellipsisCount > 0) {
                     setSingleLine(false);
                     
-                    TypedArray a = mContext.obtainStyledAttributes(
-                            android.R.style.TextAppearance_Medium,
-                            android.R.styleable.TextAppearance);
+                    TypedArray a = mContext.obtainStyledAttributes(null,
+                            android.R.styleable.TextAppearance,
+                            android.R.attr.textAppearanceMedium,
+                            android.R.style.TextAppearance_Medium);
                     final int textSize = a.getDimensionPixelSize(
                             android.R.styleable.TextAppearance_textSize,
                             (int) (20 * getResources().getDisplayMetrics().density));
+                    final int textColor = a.getColor(
+                            android.R.styleable.TextAppearance_textColor, 0xffffffff);
 
                     // textSize is already expressed in pixels
                     setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
+                    setTextColor(textColor);
                     setMaxLines(2);
                     super.onMeasure(widthMeasureSpec, heightMeasureSpec);      
                 }
diff --git a/core/java/com/android/internal/widget/DigitalClock.java b/core/java/com/android/internal/widget/DigitalClock.java
index 0885b6e..ac0dc35 100644
--- a/core/java/com/android/internal/widget/DigitalClock.java
+++ b/core/java/com/android/internal/widget/DigitalClock.java
@@ -96,13 +96,13 @@
     };
 
     static class AmPm {
-        private TextView mAmPm;
+        private TextView mAmPmTextView;
         private String mAmString, mPmString;
 
         AmPm(View parent, Typeface tf) {
-            mAmPm = (TextView) parent.findViewById(R.id.am_pm);
-            if (tf != null) {
-                mAmPm.setTypeface(tf);
+            mAmPmTextView = (TextView) parent.findViewById(R.id.am_pm);
+            if (mAmPmTextView != null && tf != null) {
+                mAmPmTextView.setTypeface(tf);
             }
 
             String[] ampm = new DateFormatSymbols().getAmPmStrings();
@@ -111,11 +111,15 @@
         }
 
         void setShowAmPm(boolean show) {
-            mAmPm.setVisibility(show ? View.VISIBLE : View.GONE);
+            if (mAmPmTextView != null) {
+                mAmPmTextView.setVisibility(show ? View.VISIBLE : View.GONE);
+            }
         }
 
         void setIsMorning(boolean isMorning) {
-            mAmPm.setText(isMorning ? mAmString : mPmString);
+            if (mAmPmTextView != null) {
+                mAmPmTextView.setText(isMorning ? mAmString : mPmString);
+            }
         }
     }
 
diff --git a/core/java/com/android/internal/widget/LockPatternUtils.java b/core/java/com/android/internal/widget/LockPatternUtils.java
index 0dc0422..d034eab 100644
--- a/core/java/com/android/internal/widget/LockPatternUtils.java
+++ b/core/java/com/android/internal/widget/LockPatternUtils.java
@@ -30,10 +30,13 @@
 import android.os.SystemClock;
 import android.os.storage.IMountService;
 import android.provider.Settings;
+import android.security.KeyStore;
 import android.telephony.TelephonyManager;
 import android.text.TextUtils;
 import android.util.Log;
+import android.view.View;
 import android.widget.Button;
+import android.widget.TextView;
 
 import java.io.File;
 import java.io.FileNotFoundException;
@@ -47,7 +50,7 @@
 import java.util.concurrent.atomic.AtomicBoolean;
 
 /**
- * Utilities for the lock patten and its settings.
+ * Utilities for the lock pattern and its settings.
  */
 public class LockPatternUtils {
 
@@ -396,12 +399,17 @@
             }
             raf.close();
             DevicePolicyManager dpm = getDevicePolicyManager();
+            KeyStore keyStore = KeyStore.getInstance();
             if (pattern != null) {
+                keyStore.password(patternToString(pattern));
                 setBoolean(PATTERN_EVER_CHOSEN_KEY, true);
                 setLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_SOMETHING);
                 dpm.setActivePasswordState(DevicePolicyManager.PASSWORD_QUALITY_SOMETHING, pattern
                         .size(), 0, 0, 0, 0, 0, 0);
             } else {
+                if (keyStore.isEmpty()) {
+                    keyStore.reset();
+                }
                 dpm.setActivePasswordState(DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED, 0, 0,
                         0, 0, 0, 0, 0);
             }
@@ -484,10 +492,14 @@
             }
             raf.close();
             DevicePolicyManager dpm = getDevicePolicyManager();
+            KeyStore keyStore = KeyStore.getInstance();
             if (password != null) {
                 // Update the encryption password.
                 updateEncryptionPassword(password);
 
+                // Update the keystore password
+                keyStore.password(password);
+
                 int computedQuality = computePasswordQuality(password);
                 setLong(PASSWORD_TYPE_KEY, Math.max(quality, computedQuality));
                 if (computedQuality != DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) {
@@ -540,6 +552,11 @@
                 }
                 setString(PASSWORD_HISTORY_KEY, passwordHistory);
             } else {
+                // Conditionally reset the keystore if empty. If
+                // non-empty, we are just switching key guard type
+                if (keyStore.isEmpty()) {
+                    keyStore.reset();
+                }
                 dpm.setActivePasswordState(
                         DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED, 0, 0, 0, 0, 0, 0, 0);
             }
@@ -646,7 +663,7 @@
      * @param password the gesture pattern.
      * @return the hash of the pattern in a byte array.
      */
-     public byte[] passwordToHash(String password) {
+    public byte[] passwordToHash(String password) {
         if (password == null) {
             return null;
         }
@@ -775,6 +792,16 @@
         setBoolean(LOCKOUT_PERMANENT_KEY, locked);
     }
 
+    public boolean isEmergencyCallCapable() {
+        return mContext.getResources().getBoolean(
+                com.android.internal.R.bool.config_voice_capable);
+    }
+
+    public boolean isPukUnlockScreenEnable() {
+        return mContext.getResources().getBoolean(
+                com.android.internal.R.bool.config_enable_puk_unlock_screen);
+    }
+
     /**
      * @return A formatted string of the next alarm (for showing on the lock screen),
      *   or null if there is no next alarm.
@@ -827,11 +854,22 @@
     }
 
     /**
-     * Sets the text on the emergency button to indicate what action will be taken.
+     * Sets the emergency button visibility based on isEmergencyCallCapable().
+     *
+     * If the emergency button is visible, sets the text on the emergency button
+     * to indicate what action will be taken.
+     *
      * If there's currently a call in progress, the button will take them to the call
      * @param button the button to update
      */
     public void updateEmergencyCallButtonState(Button button) {
+        if (isEmergencyCallCapable()) {
+            button.setVisibility(View.VISIBLE);
+        } else {
+            button.setVisibility(View.GONE);
+            return;
+        }
+
         int newState = TelephonyManager.getDefault().getCallState();
         int textId;
         if (newState == TelephonyManager.CALL_STATE_OFFHOOK) {
@@ -848,6 +886,18 @@
     }
 
     /**
+     * Sets the visibility of emergency call prompt based on emergency capable
+     * @param emergencyText the emergency call text to be updated
+     */
+    public void updateEmergencyCallText(TextView emergencyText) {
+        if (isEmergencyCallCapable()) {
+            emergencyText.setVisibility(View.VISIBLE);
+        } else {
+            emergencyText.setVisibility(View.GONE);
+        }
+    }
+
+    /**
      * Resumes a call in progress. Typically launched from the EmergencyCall button
      * on various lockscreens.
      *
diff --git a/core/java/com/android/internal/widget/LockPatternView.java b/core/java/com/android/internal/widget/LockPatternView.java
index bee8112..cbb110a 100644
--- a/core/java/com/android/internal/widget/LockPatternView.java
+++ b/core/java/com/android/internal/widget/LockPatternView.java
@@ -131,6 +131,7 @@
 
     private int mAspect;
     private final Matrix mArrowMatrix = new Matrix();
+    private final Matrix mCircleMatrix = new Matrix();
 
     /**
      * Represents a cell in the 3 X 3 matrix of the unlock pattern view.
@@ -281,9 +282,14 @@
         mBitmapArrowGreenUp = getBitmapFor(R.drawable.indicator_code_lock_drag_direction_green_up);
         mBitmapArrowRedUp = getBitmapFor(R.drawable.indicator_code_lock_drag_direction_red_up);
 
-        // we assume all bitmaps have the same size
-        mBitmapWidth = mBitmapBtnDefault.getWidth();
-        mBitmapHeight = mBitmapBtnDefault.getHeight();
+        // bitmaps have the size of the largest bitmap in this group
+        final Bitmap bitmaps[] = { mBitmapBtnDefault, mBitmapBtnTouched, mBitmapCircleDefault,
+                mBitmapCircleGreen, mBitmapCircleRed };
+
+        for (Bitmap bitmap : bitmaps) {
+            mBitmapWidth = Math.max(mBitmapWidth, bitmap.getWidth());
+            mBitmapHeight = Math.max(mBitmapHeight, bitmap.getHeight());
+        }
 
         // allow vibration pattern to be customized
         mVibePattern = loadVibratePattern(com.android.internal.R.array.config_virtualKeyVibePattern);
@@ -458,31 +464,40 @@
                 break;
             case MeasureSpec.EXACTLY:
             default:
-                result = specSize;
+                // use the specified size, if non-zero
+                result = specSize != 0 ? specSize : desired;
         }
         return result;
     }
 
     @Override
+    protected int getSuggestedMinimumWidth() {
+        // View should be large enough to contain 3 side-by-side target bitmaps
+        return 3 * mBitmapWidth;
+    }
+
+    @Override
+    protected int getSuggestedMinimumHeight() {
+        // View should be large enough to contain 3 side-by-side target bitmaps
+        return 3 * mBitmapWidth;
+    }
+
+    @Override
     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
-        final int minimumWidth = 3 * mBitmapCircleDefault.getWidth();
-        final int minimumHeight = 3 * mBitmapCircleDefault.getHeight();
+        final int minimumWidth = getSuggestedMinimumWidth();
+        final int minimumHeight = getSuggestedMinimumHeight();
         int viewWidth = resolveMeasured(widthMeasureSpec, minimumWidth);
         int viewHeight = resolveMeasured(heightMeasureSpec, minimumHeight);
 
-        int requestedWidth = MeasureSpec.getSize(widthMeasureSpec);
-        int requestedHeight = MeasureSpec.getSize(heightMeasureSpec);
         switch (mAspect) {
             case ASPECT_SQUARE:
-                viewWidth = viewHeight = Math.min(requestedWidth, requestedHeight);
+                viewWidth = viewHeight = Math.min(viewWidth, viewHeight);
                 break;
             case ASPECT_LOCK_WIDTH:
-                viewWidth = requestedWidth;
-                viewHeight = Math.min(requestedWidth, requestedHeight);
+                viewHeight = Math.min(viewWidth, viewHeight);
                 break;
             case ASPECT_LOCK_HEIGHT:
-                viewWidth = Math.min(requestedWidth, requestedHeight);
-                viewHeight = requestedHeight;
+                viewWidth = Math.min(viewWidth, viewHeight);
                 break;
         }
         // Log.v(TAG, "LockPatternView dimensions: " + viewWidth + "x" + viewHeight);
@@ -603,178 +618,20 @@
     }
 
     @Override
-    public boolean onTouchEvent(MotionEvent motionEvent) {
+    public boolean onTouchEvent(MotionEvent event) {
         if (!mInputEnabled || !isEnabled()) {
             return false;
         }
 
-        final float x = motionEvent.getX();
-        final float y = motionEvent.getY();
-        Cell hitCell;
-        switch(motionEvent.getAction()) {
+        switch(event.getAction()) {
             case MotionEvent.ACTION_DOWN:
-                resetPattern();
-                hitCell = detectAndAddHit(x, y);
-                if (hitCell != null && mOnPatternListener != null) {
-                    mPatternInProgress = true;
-                    mPatternDisplayMode = DisplayMode.Correct;
-                    mOnPatternListener.onPatternStart();
-                } else if (mOnPatternListener != null) {
-                    mPatternInProgress = false;
-                    mOnPatternListener.onPatternCleared();
-                }
-                if (hitCell != null) {
-                    final float startX = getCenterXForColumn(hitCell.column);
-                    final float startY = getCenterYForRow(hitCell.row);
-
-                    final float widthOffset = mSquareWidth / 2f;
-                    final float heightOffset = mSquareHeight / 2f;
-
-                    invalidate((int) (startX - widthOffset), (int) (startY - heightOffset),
-                            (int) (startX + widthOffset), (int) (startY + heightOffset));
-                }
-                mInProgressX = x;
-                mInProgressY = y;
-                if (PROFILE_DRAWING) {
-                    if (!mDrawingProfilingStarted) {
-                        Debug.startMethodTracing("LockPatternDrawing");
-                        mDrawingProfilingStarted = true;
-                    }
-                }
+                handleActionDown(event);
                 return true;
             case MotionEvent.ACTION_UP:
-                // report pattern detected
-                if (!mPattern.isEmpty() && mOnPatternListener != null) {
-                    mPatternInProgress = false;
-                    mOnPatternListener.onPatternDetected(mPattern);
-                    invalidate();
-                }
-                if (PROFILE_DRAWING) {
-                    if (mDrawingProfilingStarted) {
-                        Debug.stopMethodTracing();
-                        mDrawingProfilingStarted = false;
-                    }
-                }
+                handleActionUp(event);
                 return true;
             case MotionEvent.ACTION_MOVE:
-                final int patternSizePreHitDetect = mPattern.size();
-                hitCell = detectAndAddHit(x, y);
-                final int patternSize = mPattern.size();
-                if (hitCell != null && (mOnPatternListener != null) && (patternSize == 1)) {
-                    mPatternInProgress = true;
-                    mOnPatternListener.onPatternStart();
-                }
-                // note current x and y for rubber banding of in progress
-                // patterns
-                final float dx = Math.abs(x - mInProgressX);
-                final float dy = Math.abs(y - mInProgressY);
-                if (dx + dy > mSquareWidth * 0.01f) {
-                    float oldX = mInProgressX;
-                    float oldY = mInProgressY;
-
-                    mInProgressX = x;
-                    mInProgressY = y;
-
-                    if (mPatternInProgress && patternSize > 0) {
-                        final ArrayList<Cell> pattern = mPattern;
-                        final float radius = mSquareWidth * mDiameterFactor * 0.5f;
-
-                        final Cell lastCell = pattern.get(patternSize - 1);
-
-                        float startX = getCenterXForColumn(lastCell.column);
-                        float startY = getCenterYForRow(lastCell.row);
-
-                        float left;
-                        float top;
-                        float right;
-                        float bottom;
-
-                        final Rect invalidateRect = mInvalidate;
-
-                        if (startX < x) {
-                            left = startX;
-                            right = x;
-                        } else {
-                            left = x;
-                            right = startX;
-                        }
-
-                        if (startY < y) {
-                            top = startY;
-                            bottom = y;
-                        } else {
-                            top = y;
-                            bottom = startY;
-                        }
-
-                        // Invalidate between the pattern's last cell and the current location
-                        invalidateRect.set((int) (left - radius), (int) (top - radius),
-                                (int) (right + radius), (int) (bottom + radius));
-
-                        if (startX < oldX) {
-                            left = startX;
-                            right = oldX;
-                        } else {
-                            left = oldX;
-                            right = startX;
-                        }
-
-                        if (startY < oldY) {
-                            top = startY;
-                            bottom = oldY;
-                        } else {
-                            top = oldY;
-                            bottom = startY;
-                        }
-
-                        // Invalidate between the pattern's last cell and the previous location
-                        invalidateRect.union((int) (left - radius), (int) (top - radius),
-                                (int) (right + radius), (int) (bottom + radius));
-
-                        // Invalidate between the pattern's new cell and the pattern's previous cell
-                        if (hitCell != null) {
-                            startX = getCenterXForColumn(hitCell.column);
-                            startY = getCenterYForRow(hitCell.row);
-
-                            if (patternSize >= 2) {
-                                // (re-using hitcell for old cell)
-                                hitCell = pattern.get(patternSize - 1 - (patternSize - patternSizePreHitDetect));
-                                oldX = getCenterXForColumn(hitCell.column);
-                                oldY = getCenterYForRow(hitCell.row);
-
-                                if (startX < oldX) {
-                                    left = startX;
-                                    right = oldX;
-                                } else {
-                                    left = oldX;
-                                    right = startX;
-                                }
-
-                                if (startY < oldY) {
-                                    top = startY;
-                                    bottom = oldY;
-                                } else {
-                                    top = oldY;
-                                    bottom = startY;
-                                }
-                            } else {
-                                left = right = startX;
-                                top = bottom = startY;
-                            }
-
-                            final float widthOffset = mSquareWidth / 2f;
-                            final float heightOffset = mSquareHeight / 2f;
-
-                            invalidateRect.set((int) (left - widthOffset),
-                                    (int) (top - heightOffset), (int) (right + widthOffset),
-                                    (int) (bottom + heightOffset));
-                        }
-
-                        invalidate(invalidateRect);
-                    } else {
-                        invalidate();
-                    }
-                }
+                handleActionMove(event);
                 return true;
             case MotionEvent.ACTION_CANCEL:
                 resetPattern();
@@ -793,6 +650,181 @@
         return false;
     }
 
+    private void handleActionMove(MotionEvent event) {
+        // Handle all recent motion events so we don't skip any cells even when the device
+        // is busy...
+        final int historySize = event.getHistorySize();
+        for (int i = 0; i < historySize + 1; i++) {
+            final float x = i < historySize ? event.getHistoricalX(i) : event.getX();
+            final float y = i < historySize ? event.getHistoricalY(i) : event.getY();
+            final int patternSizePreHitDetect = mPattern.size();
+            Cell hitCell = detectAndAddHit(x, y);
+            final int patternSize = mPattern.size();
+            if (hitCell != null && (mOnPatternListener != null) && (patternSize == 1)) {
+                mPatternInProgress = true;
+                mOnPatternListener.onPatternStart();
+            }
+            // note current x and y for rubber banding of in progress patterns
+            final float dx = Math.abs(x - mInProgressX);
+            final float dy = Math.abs(y - mInProgressY);
+            if (dx + dy > mSquareWidth * 0.01f) {
+                float oldX = mInProgressX;
+                float oldY = mInProgressY;
+
+                mInProgressX = x;
+                mInProgressY = y;
+
+                if (mPatternInProgress && patternSize > 0) {
+                    final ArrayList<Cell> pattern = mPattern;
+                    final float radius = mSquareWidth * mDiameterFactor * 0.5f;
+
+                    final Cell lastCell = pattern.get(patternSize - 1);
+
+                    float startX = getCenterXForColumn(lastCell.column);
+                    float startY = getCenterYForRow(lastCell.row);
+
+                    float left;
+                    float top;
+                    float right;
+                    float bottom;
+
+                    final Rect invalidateRect = mInvalidate;
+
+                    if (startX < x) {
+                        left = startX;
+                        right = x;
+                    } else {
+                        left = x;
+                        right = startX;
+                    }
+
+                    if (startY < y) {
+                        top = startY;
+                        bottom = y;
+                    } else {
+                        top = y;
+                        bottom = startY;
+                    }
+
+                    // Invalidate between the pattern's last cell and the current location
+                    invalidateRect.set((int) (left - radius), (int) (top - radius),
+                            (int) (right + radius), (int) (bottom + radius));
+
+                    if (startX < oldX) {
+                        left = startX;
+                        right = oldX;
+                    } else {
+                        left = oldX;
+                        right = startX;
+                    }
+
+                    if (startY < oldY) {
+                        top = startY;
+                        bottom = oldY;
+                    } else {
+                        top = oldY;
+                        bottom = startY;
+                    }
+
+                    // Invalidate between the pattern's last cell and the previous location
+                    invalidateRect.union((int) (left - radius), (int) (top - radius),
+                            (int) (right + radius), (int) (bottom + radius));
+
+                    // Invalidate between the pattern's new cell and the pattern's previous cell
+                    if (hitCell != null) {
+                        startX = getCenterXForColumn(hitCell.column);
+                        startY = getCenterYForRow(hitCell.row);
+
+                        if (patternSize >= 2) {
+                            // (re-using hitcell for old cell)
+                            hitCell = pattern.get(patternSize - 1 - (patternSize - patternSizePreHitDetect));
+                            oldX = getCenterXForColumn(hitCell.column);
+                            oldY = getCenterYForRow(hitCell.row);
+
+                            if (startX < oldX) {
+                                left = startX;
+                                right = oldX;
+                            } else {
+                                left = oldX;
+                                right = startX;
+                            }
+
+                            if (startY < oldY) {
+                                top = startY;
+                                bottom = oldY;
+                            } else {
+                                top = oldY;
+                                bottom = startY;
+                            }
+                        } else {
+                            left = right = startX;
+                            top = bottom = startY;
+                        }
+
+                        final float widthOffset = mSquareWidth / 2f;
+                        final float heightOffset = mSquareHeight / 2f;
+
+                        invalidateRect.set((int) (left - widthOffset),
+                                (int) (top - heightOffset), (int) (right + widthOffset),
+                                (int) (bottom + heightOffset));
+                    }
+
+                    invalidate(invalidateRect);
+                } else {
+                    invalidate();
+                }
+            }
+        }
+    }
+
+    private void handleActionUp(MotionEvent event) {
+        // report pattern detected
+        if (!mPattern.isEmpty() && mOnPatternListener != null) {
+            mPatternInProgress = false;
+            mOnPatternListener.onPatternDetected(mPattern);
+            invalidate();
+        }
+        if (PROFILE_DRAWING) {
+            if (mDrawingProfilingStarted) {
+                Debug.stopMethodTracing();
+                mDrawingProfilingStarted = false;
+            }
+        }
+    }
+
+    private void handleActionDown(MotionEvent event) {
+        resetPattern();
+        final float x = event.getX();
+        final float y = event.getY();
+        final Cell hitCell = detectAndAddHit(x, y);
+        if (hitCell != null && mOnPatternListener != null) {
+            mPatternInProgress = true;
+            mPatternDisplayMode = DisplayMode.Correct;
+            mOnPatternListener.onPatternStart();
+        } else if (mOnPatternListener != null) {
+            mPatternInProgress = false;
+            mOnPatternListener.onPatternCleared();
+        }
+        if (hitCell != null) {
+            final float startX = getCenterXForColumn(hitCell.column);
+            final float startY = getCenterYForRow(hitCell.row);
+
+            final float widthOffset = mSquareWidth / 2f;
+            final float heightOffset = mSquareHeight / 2f;
+
+            invalidate((int) (startX - widthOffset), (int) (startY - heightOffset),
+                    (int) (startX + widthOffset), (int) (startY + heightOffset));
+        }
+        mInProgressX = x;
+        mInProgressY = y;
+        if (PROFILE_DRAWING) {
+            if (!mDrawingProfilingStarted) {
+                Debug.startMethodTracing("LockPatternDrawing");
+                mDrawingProfilingStarted = true;
+            }
+        }
+    }
+
     private float getCenterXForColumn(int column) {
         return mPaddingLeft + column * mSquareWidth + mSquareWidth / 2f;
     }
@@ -947,8 +979,8 @@
         // This assumes that the arrow image is drawn at 12:00 with it's top edge
         // coincident with the circle bitmap's top edge.
         Bitmap arrow = green ? mBitmapArrowGreenUp : mBitmapArrowRedUp;
-        final int cellWidth = mBitmapCircleDefault.getWidth();
-        final int cellHeight = mBitmapCircleDefault.getHeight();
+        final int cellWidth = mBitmapWidth;
+        final int cellHeight = mBitmapHeight;
 
         // the up arrow bitmap is at 12:00, so find the rotation from x axis and add 90 degrees.
         final float theta = (float) Math.atan2(
@@ -956,7 +988,12 @@
         final float angle = (float) Math.toDegrees(theta) + 90.0f;
 
         // compose matrix
+        float sx = Math.min(mSquareWidth / mBitmapWidth, 1.0f);
+        float sy = Math.min(mSquareHeight / mBitmapHeight, 1.0f);
         mArrowMatrix.setTranslate(leftX + offsetX, topY + offsetY); // transform to cell position
+        mArrowMatrix.preTranslate(mBitmapWidth/2, mBitmapHeight/2);
+        mArrowMatrix.preScale(sx, sy);
+        mArrowMatrix.preTranslate(-mBitmapWidth/2, -mBitmapHeight/2);
         mArrowMatrix.preRotate(angle, cellWidth / 2.0f, cellHeight / 2.0f);  // rotate about cell center
         mArrowMatrix.preTranslate((cellWidth - arrow.getWidth()) / 2.0f, 0.0f); // translate to 12:00 pos
         canvas.drawBitmap(arrow, mArrowMatrix, mPaint);
@@ -1002,8 +1039,17 @@
         int offsetX = (int) ((squareWidth - width) / 2f);
         int offsetY = (int) ((squareHeight - height) / 2f);
 
-        canvas.drawBitmap(outerCircle, leftX + offsetX, topY + offsetY, mPaint);
-        canvas.drawBitmap(innerCircle, leftX + offsetX, topY + offsetY, mPaint);
+        // Allow circles to shrink if the view is too small to hold them.
+        float sx = Math.min(mSquareWidth / mBitmapWidth, 1.0f);
+        float sy = Math.min(mSquareHeight / mBitmapHeight, 1.0f);
+
+        mCircleMatrix.setTranslate(leftX + offsetX, topY + offsetY);
+        mCircleMatrix.preTranslate(mBitmapWidth/2, mBitmapHeight/2);
+        mCircleMatrix.preScale(sx, sy);
+        mCircleMatrix.preTranslate(-mBitmapWidth/2, -mBitmapHeight/2);
+
+        canvas.drawBitmap(outerCircle, mCircleMatrix, mPaint);
+        canvas.drawBitmap(innerCircle, mCircleMatrix, mPaint);
     }
 
     @Override
diff --git a/core/java/com/android/internal/widget/ScrollingTabContainerView.java b/core/java/com/android/internal/widget/ScrollingTabContainerView.java
index c7d37f2..5b4d7ab 100644
--- a/core/java/com/android/internal/widget/ScrollingTabContainerView.java
+++ b/core/java/com/android/internal/widget/ScrollingTabContainerView.java
@@ -236,8 +236,9 @@
                     }
                     mTextView.setText(text);
                     mTextView.setVisibility(VISIBLE);
-                } else {
+                } else if (mTextView != null) {
                     mTextView.setVisibility(GONE);
+                    mTextView.setText(null);
                 }
             }
         }
diff --git a/core/java/com/android/internal/widget/multiwaveview/Ease.java b/core/java/com/android/internal/widget/multiwaveview/Ease.java
new file mode 100644
index 0000000..7f90c44
--- /dev/null
+++ b/core/java/com/android/internal/widget/multiwaveview/Ease.java
@@ -0,0 +1,132 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.widget.multiwaveview;
+
+import android.animation.TimeInterpolator;
+
+class Ease {
+    private static final float DOMAIN = 1.0f;
+    private static final float DURATION = 1.0f;
+    private static final float START = 0.0f;
+
+    static class Linear {
+        public static final TimeInterpolator easeNone = new TimeInterpolator() {
+            public float getInterpolation(float input) {
+                return input;
+            }
+        };
+    }
+
+    static class Cubic {
+        public static final TimeInterpolator easeIn = new TimeInterpolator() {
+            public float getInterpolation(float input) {
+                return DOMAIN*(input/=DURATION)*input*input + START;
+            }
+        };
+        public static final TimeInterpolator easeOut = new TimeInterpolator() {
+            public float getInterpolation(float input) {
+                return DOMAIN*((input=input/DURATION-1)*input*input + 1) + START;
+            }
+        };
+        public static final TimeInterpolator easeInOut = new TimeInterpolator() {
+            public float getInterpolation(float input) {
+                return ((input/=DURATION/2) < 1.0f) ?
+                        (DOMAIN/2*input*input*input + START)
+                            : (DOMAIN/2*((input-=2)*input*input + 2) + START);
+            }
+        };
+    }
+
+    static class Quad {
+        public static final TimeInterpolator easeIn = new TimeInterpolator() {
+            public float getInterpolation (float input) {
+                return DOMAIN*(input/=DURATION)*input + START;
+            }
+        };
+        public static final TimeInterpolator easeOut = new TimeInterpolator() {
+            public float getInterpolation(float input) {
+                return -DOMAIN *(input/=DURATION)*(input-2) + START;
+            }
+        };
+        public static final TimeInterpolator easeInOut = new TimeInterpolator() {
+            public float getInterpolation(float input) {
+                return ((input/=DURATION/2) < 1) ?
+                        (DOMAIN/2*input*input + START)
+                            : (-DOMAIN/2 * ((--input)*(input-2) - 1) + START);
+            }
+        };
+    }
+
+    static class Quart {
+        public static final TimeInterpolator easeIn = new TimeInterpolator() {
+            public float getInterpolation(float input) {
+                return DOMAIN*(input/=DURATION)*input*input*input + START;
+            }
+        };
+        public static final TimeInterpolator easeOut = new TimeInterpolator() {
+            public float getInterpolation(float input) {
+                return -DOMAIN * ((input=input/DURATION-1)*input*input*input - 1) + START;
+            }
+        };
+        public static final TimeInterpolator easeInOut = new TimeInterpolator() {
+            public float getInterpolation(float input) {
+                return ((input/=DURATION/2) < 1) ?
+                        (DOMAIN/2*input*input*input*input + START)
+                            : (-DOMAIN/2 * ((input-=2)*input*input*input - 2) + START);
+            }
+        };
+    }
+
+    static class Quint {
+        public static final TimeInterpolator easeIn = new TimeInterpolator() {
+            public float getInterpolation(float input) {
+                return DOMAIN*(input/=DURATION)*input*input*input*input + START;
+            }
+        };
+        public static final TimeInterpolator easeOut = new TimeInterpolator() {
+            public float getInterpolation(float input) {
+                return DOMAIN*((input=input/DURATION-1)*input*input*input*input + 1) + START;
+            }
+        };
+        public static final TimeInterpolator easeInOut = new TimeInterpolator() {
+            public float getInterpolation(float input) {
+                return ((input/=DURATION/2) < 1) ?
+                        (DOMAIN/2*input*input*input*input*input + START)
+                            : (DOMAIN/2*((input-=2)*input*input*input*input + 2) + START);
+            }
+        };
+    }
+
+    static class Sine {
+        public static final TimeInterpolator easeIn = new TimeInterpolator() {
+            public float getInterpolation(float input) {
+                return -DOMAIN * (float) Math.cos(input/DURATION * (Math.PI/2)) + DOMAIN + START;
+            }
+        };
+        public static final TimeInterpolator easeOut = new TimeInterpolator() {
+            public float getInterpolation(float input) {
+                return DOMAIN * (float) Math.sin(input/DURATION * (Math.PI/2)) + START;
+            }
+        };
+        public static final TimeInterpolator easeInOut = new TimeInterpolator() {
+            public float getInterpolation(float input) {
+                return -DOMAIN/2 * ((float)Math.cos(Math.PI*input/DURATION) - 1.0f) + START;
+            }
+        };
+    }
+
+}
diff --git a/core/java/com/android/internal/widget/multiwaveview/MultiWaveView.java b/core/java/com/android/internal/widget/multiwaveview/MultiWaveView.java
new file mode 100644
index 0000000..1e98827
--- /dev/null
+++ b/core/java/com/android/internal/widget/multiwaveview/MultiWaveView.java
@@ -0,0 +1,664 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.widget.multiwaveview;
+
+import java.util.ArrayList;
+
+import android.animation.Animator;
+import android.animation.Animator.AnimatorListener;
+import android.animation.ObjectAnimator;
+import android.animation.TimeInterpolator;
+import android.animation.ValueAnimator;
+import android.animation.ValueAnimator.AnimatorUpdateListener;
+import android.content.Context;
+import android.content.res.Resources;
+import android.content.res.TypedArray;
+import android.graphics.Canvas;
+import android.graphics.RectF;
+import android.graphics.drawable.Drawable;
+import android.os.Vibrator;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.util.TypedValue;
+import android.view.MotionEvent;
+import android.view.View;
+
+import com.android.internal.R;
+
+/**
+ * A special widget containing a center and outer ring. Moving the center ring to the outer ring
+ * causes an event that can be caught by implementing OnTriggerListener.
+ */
+public class MultiWaveView extends View implements AnimatorUpdateListener {
+    private static final String TAG = "MultiWaveView";
+    private static final boolean DEBUG = false;
+
+    // Wave state machine
+    private static final int STATE_IDLE = 0;
+    private static final int STATE_FIRST_TOUCH = 1;
+    private static final int STATE_TRACKING = 2;
+    private static final int STATE_SNAP = 3;
+    private static final int STATE_FINISH = 4;
+
+    // Animation properties.
+    private static final float SNAP_MARGIN_DEFAULT = 20.0f; // distance to ring before we snap to it
+
+    public interface OnTriggerListener {
+        int NO_HANDLE = 0;
+        int CENTER_HANDLE = 1;
+        public void onGrabbed(View v, int handle);
+        public void onReleased(View v, int handle);
+        public void onTrigger(View v, int target);
+        public void onGrabbedStateChange(View v, int handle);
+    }
+
+    // Tune-able parameters
+    private static final int CHEVRON_INCREMENTAL_DELAY = 50;
+    private static final int CHEVRON_ANIMATION_DURATION = 1000;
+    private static final int RETURN_TO_HOME_DURATION = 150;
+    private static final int HIDE_ANIMATION_DELAY = 500;
+    private static final int HIDE_ANIMATION_DURACTION = 2000;
+    private static final int SHOW_ANIMATION_DURATION = 0;
+    private static final int SHOW_ANIMATION_DELAY = 0;
+    private TimeInterpolator mChevronAnimationInterpolator = Ease.Quint.easeOut;
+
+    private ArrayList<TargetDrawable> mTargetDrawables = new ArrayList<TargetDrawable>();
+    private ArrayList<TargetDrawable> mChevronDrawables = new ArrayList<TargetDrawable>();
+    private ArrayList<Tweener> mChevronAnimations = new ArrayList<Tweener>();
+    private ArrayList<Tweener> mTargetAnimations = new ArrayList<Tweener>();
+    private Tweener mHandleAnimation;
+    private OnTriggerListener mOnTriggerListener;
+    private TargetDrawable mHandleDrawable;
+    private TargetDrawable mOuterRing;
+    private Vibrator mVibrator;
+
+    private int mFeedbackCount = 3;
+    private int mVibrationDuration = 0;
+    private int mGrabbedState;
+    private int mActiveTarget = -1;
+    private float mTapRadius;
+    private float mWaveCenterX;
+    private float mWaveCenterY;
+    private float mVerticalOffset;
+    private float mHorizontalOffset;
+    private float mOuterRadius = 0.0f;
+    private float mHitRadius = 0.0f;
+    private float mSnapMargin = 0.0f;
+    private boolean mDragging;
+
+    private AnimatorListener mResetListener = new Animator.AnimatorListener() {
+        public void onAnimationStart(Animator animation) { }
+        public void onAnimationRepeat(Animator animation) { }
+        public void onAnimationEnd(Animator animation) {
+            switchToState(STATE_IDLE, mWaveCenterX, mWaveCenterY);
+        }
+        public void onAnimationCancel(Animator animation) { }
+    };
+
+    public MultiWaveView(Context context) {
+        this(context, null);
+    }
+
+    public MultiWaveView(Context context, AttributeSet attrs) {
+        super(context, attrs);
+        Resources res = context.getResources();
+
+        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MultiWaveView);
+        mOuterRadius = a.getDimension(R.styleable.MultiWaveView_outerRadius, mOuterRadius);
+        mHorizontalOffset = a.getDimension(R.styleable.MultiWaveView_horizontalOffset,
+                mHorizontalOffset);
+        mVerticalOffset = a.getDimension(R.styleable.MultiWaveView_verticalOffset,
+                mVerticalOffset);
+        mHitRadius = a.getDimension(R.styleable.MultiWaveView_hitRadius, mHitRadius);
+        mSnapMargin = a.getDimension(R.styleable.MultiWaveView_snapMargin, mSnapMargin);
+        mVibrationDuration = a.getInt(R.styleable.MultiWaveView_vibrationDuration,
+                mVibrationDuration);
+        mFeedbackCount = a.getInt(R.styleable.MultiWaveView_feedbackCount,
+                mFeedbackCount);
+        mHandleDrawable = new TargetDrawable(res,
+                a.getDrawable(R.styleable.MultiWaveView_handleDrawable));
+        mTapRadius = mHandleDrawable.getWidth()/2;
+        mOuterRing = new TargetDrawable(res, a.getDrawable(R.styleable.MultiWaveView_waveDrawable));
+
+        // Read chevron animation drawables
+        Drawable leftChevron = a.getDrawable(R.styleable.MultiWaveView_leftChevronDrawable);
+        for (int i = 0; i < mFeedbackCount; i++) {
+            mChevronDrawables.add(
+                    leftChevron != null ? new TargetDrawable(res, leftChevron) : null);
+        }
+        Drawable rightChevron = a.getDrawable(R.styleable.MultiWaveView_rightChevronDrawable);
+        for (int i = 0; i < mFeedbackCount; i++) {
+            mChevronDrawables.add(
+                    rightChevron != null ? new TargetDrawable(res, rightChevron) : null);
+        }
+        Drawable topChevron = a.getDrawable(R.styleable.MultiWaveView_topChevronDrawable);
+        for (int i = 0; i < mFeedbackCount; i++) {
+            mChevronDrawables.add(
+                    topChevron != null ? new TargetDrawable(res, topChevron) : null);
+        }
+        Drawable bottomChevron = a.getDrawable(R.styleable.MultiWaveView_bottomChevronDrawable);
+        for (int i = 0; i < mFeedbackCount; i++) {
+            mChevronDrawables.add(
+                    bottomChevron != null ? new TargetDrawable(res, bottomChevron) : null);
+        }
+
+        // Read array of target drawables
+        TypedValue outValue = new TypedValue();
+        if (a.getValue(R.styleable.MultiWaveView_targetDrawables, outValue)) {
+            setTargetResources(outValue.resourceId);
+        }
+        if (mTargetDrawables == null || mTargetDrawables.size() == 0) {
+            throw new IllegalStateException("Must specify at least one target drawable");
+        }
+
+        setVibrateEnabled(mVibrationDuration > 0);
+    }
+
+    private void dump() {
+        Log.v(TAG, "Outer Radius = " + mOuterRadius);
+        Log.v(TAG, "HitRadius = " + mHitRadius);
+        Log.v(TAG, "SnapMargin = " + mSnapMargin);
+        Log.v(TAG, "FeedbackCount = " + mFeedbackCount);
+        Log.v(TAG, "VibrationDuration = " + mVibrationDuration);
+        Log.v(TAG, "TapRadius = " + mTapRadius);
+        Log.v(TAG, "WaveCenterX = " + mWaveCenterX);
+        Log.v(TAG, "WaveCenterY = " + mWaveCenterY);
+        Log.v(TAG, "HorizontalOffset = " + mHorizontalOffset);
+        Log.v(TAG, "VerticalOffset = " + mVerticalOffset);
+    }
+
+    @Override
+    protected int getSuggestedMinimumWidth() {
+        // View should be large enough to contain the background + target drawable on either edge
+        return mOuterRing.getWidth()
+                + (mTargetDrawables.size() > 0 ? (mTargetDrawables.get(0).getWidth()) : 0);
+    }
+
+    @Override
+    protected int getSuggestedMinimumHeight() {
+        // View should be large enough to contain the unlock ring + target drawable on either edge
+        return mOuterRing.getHeight()
+                + (mTargetDrawables.size() > 0 ? (mTargetDrawables.get(0).getHeight()) : 0);
+    }
+
+    private void switchToState(int state, float x, float y) {
+        switch (state) {
+            case STATE_IDLE:
+                deactivateTargets();
+                mHandleDrawable.setState(TargetDrawable.STATE_INACTIVE);
+                break;
+
+            case STATE_FIRST_TOUCH:
+                stopHandleAnimation();
+                deactivateTargets();
+                showTargets();
+                mHandleDrawable.setState(TargetDrawable.STATE_ACTIVE);
+                setGrabbedState(OnTriggerListener.CENTER_HANDLE);
+                break;
+
+            case STATE_TRACKING:
+                break;
+
+            case STATE_SNAP:
+                break;
+
+            case STATE_FINISH:
+                doFinish();
+                break;
+        }
+    }
+
+    /**
+     * Animation used to attract user's attention to the target button.
+     * Assumes mChevronDrawables is an a list with an even number of chevrons filled with left
+     * followed by right chevrons.
+     */
+    private void startChevronAnimation() {
+        final float r = mHandleDrawable.getWidth() / 2;
+        final float from[][] = {
+                {mWaveCenterX - r, mWaveCenterY},  // left
+                {mWaveCenterX + r, mWaveCenterY},  // right
+                {mWaveCenterX, mWaveCenterY - r},  // top
+                {mWaveCenterX, mWaveCenterY + r} }; // bottom
+        final float to[][] = {
+                {mWaveCenterX - mOuterRadius, mWaveCenterY},  // left
+                {mWaveCenterX + mOuterRadius, mWaveCenterY},  // right
+                {mWaveCenterX, mWaveCenterY - mOuterRadius},  // top
+                {mWaveCenterX, mWaveCenterY + mOuterRadius} }; // bottom
+
+        mChevronAnimations.clear();
+        for (int direction = 0; direction < 4; direction++) {
+            for (int count = 0; count < mFeedbackCount; count++) {
+                int delay = count * CHEVRON_INCREMENTAL_DELAY;
+                final TargetDrawable icon = mChevronDrawables.get(direction*mFeedbackCount + count);
+                if (icon == null) {
+                    continue;
+                }
+                mChevronAnimations.add(Tweener.to(icon, CHEVRON_ANIMATION_DURATION,
+                        "ease", mChevronAnimationInterpolator,
+                        "delay", delay,
+                        "x", new float[] { from[direction][0], to[direction][0] },
+                        "y", new float[] { from[direction][1], to[direction][1] },
+                        "alpha", new float[] {1.0f, 0.0f},
+                        "onUpdate", this));
+            }
+        }
+    }
+
+    private void stopChevronAnimation() {
+        for (Tweener anim : mChevronAnimations) {
+            anim.animator.end();
+        }
+        mChevronAnimations.clear();
+    }
+
+    private void stopHandleAnimation() {
+        if (mHandleAnimation != null) {
+            mHandleAnimation.animator.end();
+            mHandleAnimation = null;
+        }
+    }
+
+    private void deactivateTargets() {
+        for (TargetDrawable target : mTargetDrawables) {
+            target.setState(TargetDrawable.STATE_INACTIVE);
+        }
+        mActiveTarget = -1;
+    }
+
+    void invalidateGlobalRegion(TargetDrawable drawable) {
+        int width = drawable.getWidth();
+        int height = drawable.getHeight();
+        RectF childBounds = new RectF(0, 0, width, height);
+        childBounds.offset(drawable.getX() - width/2, drawable.getY() - height/2);
+        View view = this;
+        while (view.getParent() != null && view.getParent() instanceof View) {
+            view = (View) view.getParent();
+            view.getMatrix().mapRect(childBounds);
+            view.invalidate((int) Math.floor(childBounds.left),
+                    (int) Math.floor(childBounds.top),
+                    (int) Math.ceil(childBounds.right),
+                    (int) Math.ceil(childBounds.bottom));
+        }
+    }
+
+    /**
+     * Dispatches a trigger event to listener. Ignored if a listener is not set.
+     * @param whichHandle the handle that triggered the event.
+     */
+    private void dispatchTriggerEvent(int whichHandle) {
+        vibrate();
+        if (mOnTriggerListener != null) {
+            mOnTriggerListener.onTrigger(this, whichHandle);
+        }
+    }
+
+    private void doFinish() {
+        // Inform listener of any active targets.  Typically only one will be active.
+        final int activeTarget = mActiveTarget;
+        boolean targetHit =  activeTarget != -1;
+        if (targetHit) {
+            Log.v(TAG, "Finish with target hit = " + targetHit);
+            dispatchTriggerEvent(mActiveTarget);
+        }
+
+        setGrabbedState(OnTriggerListener.NO_HANDLE);
+
+        // Animate finger outline back to home position
+        mHandleDrawable.setAlpha(targetHit ? 0.0f : 1.0f);
+        mHandleAnimation = Tweener.to(mHandleDrawable, RETURN_TO_HOME_DURATION,
+                "ease", Ease.Quart.easeOut,
+                "delay", targetHit ? HIDE_ANIMATION_DELAY : 0,
+                "alpha", 1.0f,
+                "x", mWaveCenterX,
+                "y", mWaveCenterY,
+                "onUpdate", this,
+                "onComplete", mResetListener);
+
+        // Hide unselected targets
+        hideTargets(true);
+
+        // Highlight the selected one
+        if (targetHit) {
+            mTargetDrawables.get(activeTarget).setState(TargetDrawable.STATE_ACTIVE);
+        }
+    }
+
+    private void hideTargets(boolean animate) {
+        if (mTargetAnimations.size() > 0) {
+            stopTargetAnimation();
+        }
+        for (TargetDrawable target : mTargetDrawables) {
+            target.setState(TargetDrawable.STATE_INACTIVE);
+            mTargetAnimations.add(Tweener.to(target,
+                    animate ? HIDE_ANIMATION_DURACTION : 0,
+                    "alpha", 0.0f,
+                    "delay", HIDE_ANIMATION_DELAY,
+                    "onUpdate", this));
+        }
+        mTargetAnimations.add(Tweener.to(mOuterRing,
+                animate ? HIDE_ANIMATION_DURACTION : 0,
+                "alpha", 0.0f,
+                "delay", HIDE_ANIMATION_DELAY,
+                "onUpdate", this));
+    }
+
+    private void showTargets() {
+        if (mTargetAnimations.size() > 0) {
+            stopTargetAnimation();
+        }
+        for (TargetDrawable target : mTargetDrawables) {
+            target.setState(TargetDrawable.STATE_INACTIVE);
+            mTargetAnimations.add(Tweener.to(target, SHOW_ANIMATION_DURATION,
+                    "alpha", 1.0f,
+                    "delay", SHOW_ANIMATION_DELAY,
+                    "onUpdate", this));
+        }
+        mTargetAnimations.add(Tweener.to(mOuterRing, SHOW_ANIMATION_DURATION,
+                "alpha", 1.0f,
+                "delay", SHOW_ANIMATION_DELAY,
+                "onUpdate", this));
+    }
+
+    private void stopTargetAnimation() {
+        for (Tweener anim : mTargetAnimations) {
+            anim.animator.end();
+        }
+        mTargetAnimations.clear();
+    }
+
+    private void vibrate() {
+        if (mVibrator != null) {
+            mVibrator.vibrate(mVibrationDuration);
+        }
+    }
+
+    /**
+     * Loads an array of drawables from the given resourceId.
+     *
+     * @param resourceId
+     */
+    public void setTargetResources(int resourceId) {
+        Resources res = getContext().getResources();
+        TypedArray array = res.obtainTypedArray(resourceId);
+        int count = array.length();
+        ArrayList<TargetDrawable> targetDrawables = new ArrayList<TargetDrawable>(count);
+        for (int i = 0; i < count; i++) {
+            Drawable drawable = array.getDrawable(i);
+            targetDrawables.add(new TargetDrawable(res, drawable));
+        }
+        mTargetDrawables = targetDrawables;
+    }
+
+    /**
+     * Enable or disable vibrate on touch.
+     *
+     * @param enabled
+     */
+    public void setVibrateEnabled(boolean enabled) {
+        if (enabled && mVibrator == null) {
+            mVibrator = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
+        } else {
+            mVibrator = null;
+        }
+    }
+
+    /**
+     * Starts chevron animation. Example use case: show chevron animation whenever the phone rings
+     * or the user touches the screen.
+     *
+     */
+    public void ping() {
+        stopChevronAnimation();
+        startChevronAnimation();
+    }
+
+    /**
+     * Resets the widget to default state and cancels all animation. If animate is 'true', will
+     * animate objects into place. Otherwise, objects will snap back to place.
+     *
+     * @param animate
+     */
+    public void reset(boolean animate) {
+        stopChevronAnimation();
+        stopHandleAnimation();
+        stopTargetAnimation();
+        hideChevrons();
+        hideTargets(animate);
+        mHandleDrawable.setX(mWaveCenterX);
+        mHandleDrawable.setY(mWaveCenterY);
+        mHandleDrawable.setState(TargetDrawable.STATE_INACTIVE);
+    }
+
+    @Override
+    public boolean onTouchEvent(MotionEvent event) {
+        final int action = event.getAction();
+
+        boolean handled = false;
+        float x = event.getX();
+        float y = event.getY();
+        switch (action) {
+            case MotionEvent.ACTION_DOWN:
+                handleDown(x, y);
+                handled = true;
+                break;
+
+            case MotionEvent.ACTION_MOVE:
+                handleMove(x, y);
+                handled = true;
+                break;
+
+            case MotionEvent.ACTION_UP:
+                handleUp(x, y);
+                handleMove(x, y);
+                handled = true;
+                break;
+
+            case MotionEvent.ACTION_CANCEL:
+                handleMove(x, y);
+                handled = true;
+                break;
+        }
+        invalidate();
+        return handled ? true : super.onTouchEvent(event);
+    }
+
+    private void moveHandleTo(float x, float y, boolean animate) {
+        // TODO: animate the handle based on the current state/position
+        mHandleDrawable.setX(x);
+        mHandleDrawable.setY(y);
+    }
+
+    private void handleDown(float x, float y) {
+        final float dx = x - mWaveCenterX;
+        final float dy = y - mWaveCenterY;
+        if (dist2(dx,dy) <= square(mTapRadius)) {
+            if (DEBUG) Log.v(TAG, "** Handle HIT");
+            switchToState(STATE_FIRST_TOUCH, x, y);
+            moveHandleTo(x, y, false);
+            mDragging = true;
+        } else {
+            mDragging = false;
+            stopTargetAnimation();
+            ping();
+        }
+    }
+
+    private void handleUp(float x, float y) {
+        if (DEBUG && mDragging) Log.v(TAG, "** Handle RELEASE");
+        switchToState(STATE_FINISH, x, y);
+    }
+
+    private void handleMove(float x, float y) {
+        if (!mDragging) {
+            return;
+        }
+
+        float tx = x - mWaveCenterX;
+        float ty = y - mWaveCenterY;
+        float touchRadius = (float) Math.sqrt(dist2(tx, ty));
+        final float scale = touchRadius > mOuterRadius ? mOuterRadius / touchRadius : 1.0f;
+        float limitX = mWaveCenterX + tx * scale;
+        float limitY = mWaveCenterY + ty * scale;
+
+        int activeTarget = -1;
+        boolean singleTarget = mTargetDrawables.size() == 1;
+        if (singleTarget) {
+            // Snap to outer ring if there's only one target
+            float snapRadius = mOuterRadius - mSnapMargin;
+            if (touchRadius > snapRadius) {
+                activeTarget = 0;
+                x = limitX;
+                y = limitY;
+            }
+        } else {
+            // If there's more than one target, snap to the closest one less than hitRadius away.
+            float best = Float.MAX_VALUE;
+            final float hitRadius2 = mHitRadius * mHitRadius;
+            for (int i = 0; i < mTargetDrawables.size(); i++) {
+                // Snap to the first target in range
+                TargetDrawable target = mTargetDrawables.get(i);
+                float dx = limitX - target.getX();
+                float dy = limitY - target.getY();
+                float dist2 = dx*dx + dy*dy;
+                if (target.isValid() && dist2 < hitRadius2 && dist2 < best) {
+                    activeTarget = i;
+                    best = dist2;
+                }
+            }
+            x = limitX;
+            y = limitY;
+        }
+        if (activeTarget != -1) {
+            switchToState(STATE_SNAP, x,y);
+            float newX = singleTarget ? limitX : mTargetDrawables.get(activeTarget).getX();
+            float newY = singleTarget ? limitY : mTargetDrawables.get(activeTarget).getY();
+            moveHandleTo(newX, newY, false);
+            TargetDrawable currentTarget = mTargetDrawables.get(activeTarget);
+            if (currentTarget.hasState(TargetDrawable.STATE_FOCUSED)) {
+                currentTarget.setState(TargetDrawable.STATE_FOCUSED);
+                mHandleDrawable.setAlpha(0.0f);
+            }
+        } else {
+            switchToState(STATE_TRACKING, x, y);
+            moveHandleTo(x, y, false);
+            mHandleDrawable.setAlpha(1.0f);
+        }
+        // Draw handle outside parent's bounds
+        invalidateGlobalRegion(mHandleDrawable);
+
+        if (mActiveTarget != activeTarget && activeTarget != -1) {
+            vibrate();
+        }
+        mActiveTarget = activeTarget;
+    }
+
+    /**
+     * Sets the current grabbed state, and dispatches a grabbed state change
+     * event to our listener.
+     */
+    private void setGrabbedState(int newState) {
+        if (newState != mGrabbedState) {
+            if (newState != OnTriggerListener.NO_HANDLE) {
+                vibrate();
+            }
+            mGrabbedState = newState;
+            if (mOnTriggerListener != null) {
+                mOnTriggerListener.onGrabbedStateChange(this, mGrabbedState);
+            }
+        }
+    }
+
+    @Override
+    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
+        super.onLayout(changed, left, top, right, bottom);
+        final int width = right - left;
+        final int height = bottom - top;
+
+        mWaveCenterX = mHorizontalOffset + Math.max(width, mOuterRing.getWidth() ) / 2;
+        mWaveCenterY = mVerticalOffset + Math.max(height, mOuterRing.getHeight()) / 2;
+        moveHandleTo(mWaveCenterX, mWaveCenterY, false);
+        mOuterRing.setX(mWaveCenterX);
+        mOuterRing.setY(Math.max(mWaveCenterY, mWaveCenterY));
+        mOuterRing.setAlpha(0.0f);
+        if (mOuterRadius == 0.0f) {
+            mOuterRadius = 0.5f*(float) Math.sqrt(dist2(mWaveCenterX, mWaveCenterY));
+        }
+        if (mHitRadius == 0.0f) {
+            // Use the radius of inscribed circle of the first target.
+            mHitRadius = mTargetDrawables.get(0).getWidth() / 2.0f;
+        }
+        if (mSnapMargin == 0.0f) {
+            mSnapMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
+                    SNAP_MARGIN_DEFAULT, getContext().getResources().getDisplayMetrics());
+        }
+        for (int i = 0; i < mTargetDrawables.size(); i++) {
+            final TargetDrawable targetIcon = mTargetDrawables.get(i);
+            double angle = -2.0f * Math.PI * i / mTargetDrawables.size();
+            float xPosition = mWaveCenterX + mOuterRadius * (float) Math.cos(angle);
+            float yPosition = mWaveCenterY + mOuterRadius * (float) Math.sin(angle);
+            targetIcon.setX(xPosition);
+            targetIcon.setY(yPosition);
+            targetIcon.setAlpha(0.0f);
+        }
+        hideChevrons();
+        hideTargets(false);
+        if (DEBUG) dump();
+    }
+
+    private void hideChevrons() {
+        for (TargetDrawable chevron : mChevronDrawables) {
+            if (chevron != null) {
+                chevron.setAlpha(0.0f);
+            }
+        }
+    }
+
+    @Override
+    protected void onDraw(Canvas canvas) {
+        mOuterRing.draw(canvas);
+        for (TargetDrawable target : mTargetDrawables) {
+            if (target != null) {
+                target.draw(canvas);
+            }
+        }
+        for (TargetDrawable target : mChevronDrawables) {
+            if (target != null) {
+                target.draw(canvas);
+            }
+        }
+        mHandleDrawable.draw(canvas);
+    }
+
+    public void setOnTriggerListener(OnTriggerListener listener) {
+        mOnTriggerListener = listener;
+    }
+
+    public void onAnimationUpdate(ValueAnimator animation) {
+        invalidateGlobalRegion(mHandleDrawable);
+        invalidate();
+    }
+
+    private float square(float d) {
+        return d * d;
+    }
+
+    private float dist2(float dx, float dy) {
+        return dx*dx + dy*dy;
+    }
+
+}
\ No newline at end of file
diff --git a/core/java/com/android/internal/widget/multiwaveview/TargetDrawable.java b/core/java/com/android/internal/widget/multiwaveview/TargetDrawable.java
new file mode 100644
index 0000000..d3baa2b
--- /dev/null
+++ b/core/java/com/android/internal/widget/multiwaveview/TargetDrawable.java
@@ -0,0 +1,215 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.widget.multiwaveview;
+
+import android.content.res.Resources;
+import android.graphics.Canvas;
+import android.graphics.ColorFilter;
+import android.graphics.drawable.Drawable;
+import android.graphics.drawable.StateListDrawable;
+import android.util.Log;
+
+public class TargetDrawable {
+    private static final String TAG = "TargetDrawable";
+    public static final int[] STATE_ACTIVE =
+            { android.R.attr.state_enabled, android.R.attr.state_active };
+    public static final int[] STATE_INACTIVE =
+            { android.R.attr.state_enabled, -android.R.attr.state_active };
+    public static final int[] STATE_FOCUSED =
+            { android.R.attr.state_enabled, android.R.attr.state_focused };
+
+    private float mTranslationX = 0.0f;
+    private float mTranslationY = 0.0f;
+    private float mScaleX = 1.0f;
+    private float mScaleY = 1.0f;
+    private float mAlpha = 1.0f;
+    private Drawable mDrawable;
+
+    /* package */ static class DrawableWithAlpha extends Drawable {
+        private float mAlpha = 1.0f;
+        private Drawable mRealDrawable;
+        public DrawableWithAlpha(Drawable realDrawable) {
+            mRealDrawable = realDrawable;
+        }
+        public void setAlpha(float alpha) {
+            mAlpha = alpha;
+        }
+        public float getAlpha() {
+            return mAlpha;
+        }
+        public void draw(Canvas canvas) {
+            mRealDrawable.setAlpha((int) Math.round(mAlpha * 255f));
+            mRealDrawable.draw(canvas);
+        }
+        @Override
+        public void setAlpha(int alpha) {
+            mRealDrawable.setAlpha(alpha);
+        }
+        @Override
+        public void setColorFilter(ColorFilter cf) {
+            mRealDrawable.setColorFilter(cf);
+        }
+        @Override
+        public int getOpacity() {
+            return mRealDrawable.getOpacity();
+        }
+    }
+
+    public TargetDrawable(Resources res, int resId) {
+        this(res, resId == 0 ? null : res.getDrawable(resId));
+    }
+
+    public TargetDrawable(Resources res, Drawable drawable) {
+        // Mutate the drawable so we can animate shared drawable properties.
+        mDrawable = drawable != null ? drawable.mutate() : null;
+        resizeDrawables();
+        setState(STATE_INACTIVE);
+    }
+
+    public void setState(int [] state) {
+        if (mDrawable instanceof StateListDrawable) {
+            StateListDrawable d = (StateListDrawable) mDrawable;
+            d.setState(state);
+        }
+    }
+
+    public boolean hasState(int [] state) {
+        if (mDrawable instanceof StateListDrawable) {
+            StateListDrawable d = (StateListDrawable) mDrawable;
+            // TODO: this doesn't seem to work
+            return d.getStateDrawableIndex(state) != -1;
+        }
+        return false;
+    }
+
+    /**
+     * Returns true if the drawable is a StateListDrawable and is in the focused state.
+     *
+     * @return
+     */
+    public boolean isActive() {
+        if (mDrawable instanceof StateListDrawable) {
+            StateListDrawable d = (StateListDrawable) mDrawable;
+            int[] states = d.getState();
+            for (int i = 0; i < states.length; i++) {
+                if (states[i] == android.R.attr.state_focused) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Returns true if this target is enabled. Typically an enabled target contains a valid
+     * drawable in a valid state. Currently all targets with valid drawables are valid.
+     *
+     * @return
+     */
+    public boolean isValid() {
+        return mDrawable != null;
+    }
+
+    /**
+     * Makes drawables in a StateListDrawable all the same dimensions.
+     * If not a StateListDrawable, then justs sets the bounds to the intrinsic size of the
+     * drawable.
+     */
+    private void resizeDrawables() {
+        if (mDrawable instanceof StateListDrawable) {
+            StateListDrawable d = (StateListDrawable) mDrawable;
+            int maxWidth = 0;
+            int maxHeight = 0;
+            for (int i = 0; i < d.getStateCount(); i++) {
+                Drawable childDrawable = d.getStateDrawable(i);
+                maxWidth = Math.max(maxWidth, childDrawable.getIntrinsicWidth());
+                maxHeight = Math.max(maxHeight, childDrawable.getIntrinsicHeight());
+            }
+            Log.v(TAG, "union of childDrawable rects " + d + " to: " + maxWidth + "x" + maxHeight);
+            d.setBounds(0, 0, maxWidth, maxHeight);
+            for (int i = 0; i < d.getStateCount(); i++) {
+                Drawable childDrawable = d.getStateDrawable(i);
+                Log.v(TAG, "sizing drawable " + childDrawable + " to: " + maxWidth + "x" + maxHeight);
+                childDrawable.setBounds(0, 0, maxWidth, maxHeight);
+            }
+        } else if (mDrawable != null) {
+            mDrawable.setBounds(0, 0,
+                    mDrawable.getIntrinsicWidth(), mDrawable.getIntrinsicHeight());
+        }
+    }
+
+    public void setX(float x) {
+        mTranslationX = x;
+    }
+
+    public void setY(float y) {
+        mTranslationY = y;
+    }
+
+    public void setScaleX(float x) {
+        mScaleX = x;
+    }
+
+    public void setScaleY(float y) {
+        mScaleY = y;
+    }
+
+    public void setAlpha(float alpha) {
+        mAlpha = alpha;
+    }
+
+    public float getX() {
+        return mTranslationX;
+    }
+
+    public float getY() {
+        return mTranslationY;
+    }
+
+    public float getScaleX() {
+        return mScaleX;
+    }
+
+    public float getScaleY() {
+        return mScaleY;
+    }
+
+    public float getAlpha() {
+        return mAlpha;
+    }
+
+    public int getWidth() {
+        return mDrawable != null ? mDrawable.getIntrinsicWidth() : 0;
+    }
+
+    public int getHeight() {
+        return mDrawable != null ? mDrawable.getIntrinsicHeight() : 0;
+    }
+
+    public void draw(Canvas canvas) {
+        if (mDrawable == null) {
+            return;
+        }
+        canvas.save(Canvas.MATRIX_SAVE_FLAG);
+        canvas.translate(mTranslationX, mTranslationY);
+        canvas.scale(mScaleX, mScaleY);
+        canvas.translate(-0.5f * getWidth(), -0.5f * getHeight());
+        mDrawable.setAlpha((int) Math.round(mAlpha * 255f));
+        mDrawable.draw(canvas);
+        canvas.restore();
+    }
+}
diff --git a/core/java/com/android/internal/widget/multiwaveview/Tweener.java b/core/java/com/android/internal/widget/multiwaveview/Tweener.java
new file mode 100644
index 0000000..0cff00a
--- /dev/null
+++ b/core/java/com/android/internal/widget/multiwaveview/Tweener.java
@@ -0,0 +1,133 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.widget.multiwaveview;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import android.animation.Animator.AnimatorListener;
+import android.animation.ObjectAnimator;
+import android.animation.PropertyValuesHolder;
+import android.animation.TimeInterpolator;
+import android.animation.ValueAnimator.AnimatorUpdateListener;
+
+class Tweener {
+    private static final String TAG = "Tweener";
+
+    private Object object;
+    ObjectAnimator animator;
+    private static HashMap<Object, Tweener> sTweens = new HashMap<Object, Tweener>();
+
+    public Tweener(Object obj, ObjectAnimator anim) {
+        object = obj;
+        animator = anim;
+    }
+
+    public static Tweener to(Object object, long duration, Object... vars) {
+        long delay = 0;
+        AnimatorUpdateListener updateListener = null;
+        AnimatorListener listener = null;
+        TimeInterpolator interpolator = null;
+
+        // Iterate through arguments and discover properties to animate
+        ArrayList<PropertyValuesHolder> props = new ArrayList<PropertyValuesHolder>(vars.length/2);
+        for (int i = 0; i < vars.length; i+=2) {
+            if (!(vars[i] instanceof String)) {
+                throw new IllegalArgumentException("Key must be a string: " + vars[i]);
+            }
+            String key = (String) vars[i];
+            Object value = vars[i+1];
+            if ("simultaneousTween".equals(key)) {
+                // TODO
+            } else if ("ease".equals(key)) {
+                interpolator = (TimeInterpolator) value; // TODO: multiple interpolators?
+            } else if ("onUpdate".equals(key) || "onUpdateListener".equals(key)) {
+                updateListener = (AnimatorUpdateListener) value;
+            } else if ("onComplete".equals(key) || "onCompleteListener".equals(key)) {
+                listener = (AnimatorListener) value;
+            } else if ("delay".equals(key)) {
+                delay = ((Number) value).longValue();
+            } else if ("syncWith".equals(key)) {
+                // TODO
+            } else if (value instanceof float[]) {
+                props.add(PropertyValuesHolder.ofFloat(key,
+                        ((float[])value)[0], ((float[])value)[1]));
+            } else if (value instanceof Number) {
+                float floatValue = ((Number)value).floatValue();
+                props.add(PropertyValuesHolder.ofFloat(key, floatValue));
+            } else {
+                throw new IllegalArgumentException(
+                        "Bad argument for key \"" + key + "\" with value " + value.getClass());
+            }
+        }
+
+        // Re-use existing tween, if present
+        Tweener tween = sTweens.get(object);
+        if (tween == null) {
+            ObjectAnimator anim = ObjectAnimator.ofPropertyValuesHolder(object,
+                    props.toArray(new PropertyValuesHolder[props.size()]));
+            tween = new Tweener(object, anim);
+            sTweens.put(object, tween);
+        } else {
+            tween.animator.cancel();
+            replace(props, object);
+        }
+
+        if (interpolator != null) {
+            tween.animator.setInterpolator(interpolator);
+        }
+
+        // Update animation with properties discovered in loop above
+        tween.animator.setStartDelay(delay);
+        tween.animator.setDuration(duration);
+        if (updateListener != null) {
+            tween.animator.removeAllUpdateListeners(); // There should be only one
+            tween.animator.addUpdateListener(updateListener);
+        }
+        if (listener != null) {
+            tween.animator.removeAllListeners(); // There should be only one.
+            tween.animator.addListener(listener);
+        }
+        tween.animator.start();
+
+        return tween;
+    }
+
+    Tweener from(Object object, long duration, Object... vars) {
+        // TODO:  for v of vars
+        //            toVars[v] = object[v]
+        //            object[v] = vars[v]
+        return Tweener.to(object, duration, vars);
+    }
+
+    static void replace(ArrayList<PropertyValuesHolder> props, Object... args) {
+        for (final Object killobject : args) {
+            Tweener tween = sTweens.get(killobject);
+            if (tween != null) {
+                if (killobject == tween.object) {
+                    tween.animator.cancel();
+                    if (props != null) {
+                        tween.animator.setValues(
+                                props.toArray(new PropertyValuesHolder[props.size()]));
+                    } else {
+                        sTweens.remove(tween);
+                    }
+                }
+            }
+        }
+    }
+}
diff --git a/core/jni/Android.mk b/core/jni/Android.mk
index 223008c..7b0882f 100644
--- a/core/jni/Android.mk
+++ b/core/jni/Android.mk
@@ -48,7 +48,6 @@
 	android_view_Display.cpp \
 	android_view_Surface.cpp \
 	android_view_TextureView.cpp \
-	android_view_ViewAncestor.cpp \
 	android_view_InputChannel.cpp \
 	android_view_InputQueue.cpp \
 	android_view_KeyEvent.cpp \
@@ -105,6 +104,7 @@
 	android/graphics/NinePatchImpl.cpp \
 	android/graphics/NinePatchPeeker.cpp \
 	android/graphics/Paint.cpp \
+	android/graphics/ParcelSurfaceTexture.cpp \
 	android/graphics/Path.cpp \
 	android/graphics/PathMeasure.cpp \
 	android/graphics/PathEffect.cpp \
diff --git a/core/jni/AndroidRuntime.cpp b/core/jni/AndroidRuntime.cpp
index e610640..21b0a42c 100644
--- a/core/jni/AndroidRuntime.cpp
+++ b/core/jni/AndroidRuntime.cpp
@@ -105,6 +105,7 @@
 extern int register_android_graphics_DrawFilter(JNIEnv* env);
 extern int register_android_graphics_Matrix(JNIEnv* env);
 extern int register_android_graphics_Paint(JNIEnv* env);
+extern int register_android_graphics_ParcelSurfaceTexture(JNIEnv* env);
 extern int register_android_graphics_Path(JNIEnv* env);
 extern int register_android_graphics_PathMeasure(JNIEnv* env);
 extern int register_android_graphics_Picture(JNIEnv*);
@@ -119,7 +120,6 @@
 extern int register_android_view_GLES20Canvas(JNIEnv* env);
 extern int register_android_view_Surface(JNIEnv* env);
 extern int register_android_view_TextureView(JNIEnv* env);
-extern int register_android_view_ViewAncestor(JNIEnv* env);
 extern int register_android_database_CursorWindow(JNIEnv* env);
 extern int register_android_database_SQLiteCompiledSql(JNIEnv* env);
 extern int register_android_database_SQLiteDatabase(JNIEnv* env);
@@ -1121,7 +1121,6 @@
     REG_JNI(register_android_view_GLES20Canvas),
     REG_JNI(register_android_view_Surface),
     REG_JNI(register_android_view_TextureView),
-    REG_JNI(register_android_view_ViewAncestor),
     REG_JNI(register_com_google_android_gles_jni_EGLImpl),
     REG_JNI(register_com_google_android_gles_jni_GLImpl),
     REG_JNI(register_android_opengl_jni_GLES10),
@@ -1144,6 +1143,7 @@
     REG_JNI(register_android_graphics_Movie),
     REG_JNI(register_android_graphics_NinePatch),
     REG_JNI(register_android_graphics_Paint),
+    REG_JNI(register_android_graphics_ParcelSurfaceTexture),
     REG_JNI(register_android_graphics_Path),
     REG_JNI(register_android_graphics_PathMeasure),
     REG_JNI(register_android_graphics_PathEffect),
diff --git a/core/jni/android/graphics/Canvas.cpp b/core/jni/android/graphics/Canvas.cpp
index 4a09232..942aa8a 100644
--- a/core/jni/android/graphics/Canvas.cpp
+++ b/core/jni/android/graphics/Canvas.cpp
@@ -755,32 +755,46 @@
             jfloat x, jfloat y, int flags, SkPaint* paint) {
 
         jint count = end - start;
-        sp<TextLayoutCacheValue> value = gTextLayoutCache.getValue(
-                paint, textArray, start, count, end, flags);
+        sp<TextLayoutCacheValue> value;
+#if USE_TEXT_LAYOUT_CACHE
+        value = gTextLayoutCache.getValue(paint, textArray, start, count, end, flags);
         if (value == NULL) {
             LOGE("Cannot get TextLayoutCache value");
             return ;
         }
+#else
+        value = new TextLayoutCacheValue();
+        value->computeValues(paint, textArray, start, count, end, flags);
+#endif
+
 #if DEBUG_GLYPHS
         logGlyphs(value);
 #endif
-        doDrawGlyphs(canvas, value->getGlyphs(), 0, value->getGlyphsCount(),
-                x, y, flags, paint);
+
+    doDrawGlyphs(canvas, value->getGlyphs(), 0, value->getGlyphsCount(),
+            x, y, flags, paint);
     }
 
     static void drawTextWithGlyphs(SkCanvas* canvas, const jchar* textArray,
             int start, int count, int contextCount,
             jfloat x, jfloat y, int flags, SkPaint* paint) {
 
-        sp<TextLayoutCacheValue> value = gTextLayoutCache.getValue(
-                paint, textArray, start, count, contextCount, flags);
+        sp<TextLayoutCacheValue> value;
+#if USE_TEXT_LAYOUT_CACHE
+        value = gTextLayoutCache.getValue(paint, textArray, start, count, contextCount, flags);
         if (value == NULL) {
             LOGE("Cannot get TextLayoutCache value");
             return ;
         }
+#else
+        value = new TextLayoutCacheValue();
+        value->computeValues(paint, textArray, start, count, contextCount, flags);
+#endif
+
 #if DEBUG_GLYPHS
         logGlyphs(value);
 #endif
+
         doDrawGlyphs(canvas, value->getGlyphs(), 0, value->getGlyphsCount(),
                 x, y, flags, paint);
     }
diff --git a/core/jni/android/graphics/ParcelSurfaceTexture.cpp b/core/jni/android/graphics/ParcelSurfaceTexture.cpp
new file mode 100644
index 0000000..40966e1
--- /dev/null
+++ b/core/jni/android/graphics/ParcelSurfaceTexture.cpp
@@ -0,0 +1,152 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "ParcelSurfaceTexture"
+
+#include <gui/SurfaceTextureClient.h>
+
+#include <android_runtime/AndroidRuntime.h>
+#include <android_runtime/android_graphics_SurfaceTexture.h>
+
+#include <utils/Log.h>
+
+#include <binder/Parcel.h>
+
+#include "android_util_Binder.h"
+#include "jni.h"
+#include "JNIHelp.h"
+
+// ----------------------------------------------------------------------------
+
+namespace android {
+
+const char* const kParcelSurfaceTextureClassPathName =
+    "android/graphics/ParcelSurfaceTexture";
+
+struct fields_t {
+    jfieldID iSurfaceTexture;
+};
+static fields_t fields;
+
+#define ANDROID_GRAPHICS_ISURFACETEXTURE_JNI_ID "mISurfaceTexture"
+
+// ----------------------------------------------------------------------------
+
+static void ParcelSurfaceTexture_setISurfaceTexture(
+        JNIEnv* env, jobject thiz, const sp<ISurfaceTexture>& iSurfaceTexture)
+{
+    ISurfaceTexture* const p =
+            (ISurfaceTexture*)env->GetIntField(thiz, fields.iSurfaceTexture);
+    if (iSurfaceTexture.get()) {
+        iSurfaceTexture->incStrong(thiz);
+    }
+    if (p) {
+        p->decStrong(thiz);
+    }
+    env->SetIntField(thiz, fields.iSurfaceTexture, (int)iSurfaceTexture.get());
+}
+
+sp<ISurfaceTexture> ParcelSurfaceTexture_getISurfaceTexture(
+        JNIEnv* env, jobject thiz)
+{
+    sp<ISurfaceTexture> iSurfaceTexture(
+        (ISurfaceTexture*)env->GetIntField(thiz, fields.iSurfaceTexture));
+    return iSurfaceTexture;
+}
+
+sp<ANativeWindow> android_ParcelSurfaceTexture_getNativeWindow(
+        JNIEnv* env, jobject thiz)
+{
+    sp<ISurfaceTexture> iSurfaceTexture(
+            ParcelSurfaceTexture_getISurfaceTexture(env, thiz));
+    sp<SurfaceTextureClient> surfaceTextureClient(iSurfaceTexture != NULL ?
+            new SurfaceTextureClient(iSurfaceTexture) : NULL);
+    return surfaceTextureClient;
+}
+
+bool android_ParcelSurfaceTexture_isInstanceOf(JNIEnv* env, jobject thiz)
+{
+    jclass parcelSurfaceTextureClass = env->FindClass(
+            kParcelSurfaceTextureClassPathName);
+    return env->IsInstanceOf(thiz, parcelSurfaceTextureClass);
+}
+
+// ----------------------------------------------------------------------------
+
+static void ParcelSurfaceTexture_classInit(JNIEnv* env, jclass clazz)
+{
+    fields.iSurfaceTexture =
+            env->GetFieldID(clazz, ANDROID_GRAPHICS_ISURFACETEXTURE_JNI_ID, "I");
+    if (fields.iSurfaceTexture == NULL) {
+        LOGE("can't find android/graphics/ParcelSurfaceTexture.%s",
+             ANDROID_GRAPHICS_ISURFACETEXTURE_JNI_ID);
+    }
+}
+
+static void ParcelSurfaceTexture_init(JNIEnv* env, jobject thiz, jobject jSurfaceTexture)
+{
+    sp<ISurfaceTexture> iSurfaceTexture(
+            SurfaceTexture_getSurfaceTexture(env, jSurfaceTexture));
+    ParcelSurfaceTexture_setISurfaceTexture(env, thiz, iSurfaceTexture);
+}
+
+static void ParcelSurfaceTexture_finalize(JNIEnv* env, jobject thiz)
+{
+    ParcelSurfaceTexture_setISurfaceTexture(env, thiz, 0);
+}
+
+static void ParcelSurfaceTexture_writeToParcel(
+        JNIEnv* env, jobject thiz, jobject jParcel, jint flags)
+{
+    Parcel* parcel = parcelForJavaObject(env, jParcel);
+    sp<ISurfaceTexture> iSurfaceTexture(
+            ParcelSurfaceTexture_getISurfaceTexture(env, thiz));
+    sp<IBinder> b(iSurfaceTexture->asBinder());
+    parcel->writeStrongBinder(b);
+}
+
+static void ParcelSurfaceTexture_readFromParcel(
+        JNIEnv* env, jobject thiz, jobject jParcel)
+{
+    Parcel* parcel = parcelForJavaObject(env, jParcel);
+    sp<ISurfaceTexture> iSurfaceTexture(
+            interface_cast<ISurfaceTexture>(parcel->readStrongBinder()));
+    ParcelSurfaceTexture_setISurfaceTexture(env, thiz, iSurfaceTexture);
+}
+
+// ----------------------------------------------------------------------------
+
+static JNINativeMethod gParcelSurfaceTextureMethods[] = {
+    {"nativeClassInit", "()V",   (void*)ParcelSurfaceTexture_classInit },
+    {"nativeInit", "(Landroid/graphics/SurfaceTexture;)V",
+      (void *)ParcelSurfaceTexture_init },
+    { "nativeFinalize", "()V", (void *)ParcelSurfaceTexture_finalize },
+    { "nativeWriteToParcel", "(Landroid/os/Parcel;I)V",
+      (void *)ParcelSurfaceTexture_writeToParcel },
+    { "nativeReadFromParcel", "(Landroid/os/Parcel;)V",
+      (void *)ParcelSurfaceTexture_readFromParcel },
+};
+
+
+int register_android_graphics_ParcelSurfaceTexture(JNIEnv* env)
+{
+    int err = 0;
+    err = AndroidRuntime::registerNativeMethods(env, kParcelSurfaceTextureClassPathName,
+            gParcelSurfaceTextureMethods, NELEM(gParcelSurfaceTextureMethods));
+    return err;
+}
+
+} // namespace android
diff --git a/core/jni/android/graphics/SurfaceTexture.cpp b/core/jni/android/graphics/SurfaceTexture.cpp
index 2f70190..0d28cb1 100644
--- a/core/jni/android/graphics/SurfaceTexture.cpp
+++ b/core/jni/android/graphics/SurfaceTexture.cpp
@@ -35,6 +35,7 @@
 
 static const char* const OutOfResourcesException =
     "android/graphics/SurfaceTexture$OutOfResourcesException";
+const char* const kSurfaceTextureClassPathName = "android/graphics/SurfaceTexture";
 
 struct fields_t {
     jfieldID  surfaceTexture;
@@ -74,6 +75,12 @@
     return surfaceTextureClient;
 }
 
+bool android_SurfaceTexture_isInstanceOf(JNIEnv* env, jobject thiz)
+{
+    jclass surfaceTextureClass = env->FindClass(kSurfaceTextureClassPathName);
+    return env->IsInstanceOf(thiz, surfaceTextureClass);
+}
+
 // ----------------------------------------------------------------------------
 
 class JNISurfaceTextureContext : public SurfaceTexture::FrameAvailableListener
@@ -84,6 +91,8 @@
     virtual void onFrameAvailable();
 
 private:
+    static JNIEnv* getJNIEnv();
+
     jobject mWeakThiz;
     jclass mClazz;
 };
@@ -94,17 +103,37 @@
     mClazz((jclass)env->NewGlobalRef(clazz))
 {}
 
+JNIEnv* JNISurfaceTextureContext::getJNIEnv() {
+    JNIEnv* env;
+    JavaVMAttachArgs args = {JNI_VERSION_1_4, NULL, NULL};
+    JavaVM* vm = AndroidRuntime::getJavaVM();
+    int result = vm->AttachCurrentThread(&env, (void*) &args);
+    if (result != JNI_OK) {
+        LOGE("thread attach failed: %#x", result);
+        return NULL;
+    }
+    return env;
+}
+
 JNISurfaceTextureContext::~JNISurfaceTextureContext()
 {
-    JNIEnv *env = AndroidRuntime::getJNIEnv();
-    env->DeleteGlobalRef(mWeakThiz);
-    env->DeleteGlobalRef(mClazz);
+    JNIEnv* env = getJNIEnv();
+    if (env != NULL) {
+        env->DeleteGlobalRef(mWeakThiz);
+        env->DeleteGlobalRef(mClazz);
+    } else {
+        LOGW("leaking JNI object references");
+    }
 }
 
 void JNISurfaceTextureContext::onFrameAvailable()
 {
-    JNIEnv *env = AndroidRuntime::getJNIEnv();
-    env->CallStaticVoidMethod(mClazz, fields.postEvent, mWeakThiz);
+    JNIEnv *env = getJNIEnv();
+    if (env != NULL) {
+        env->CallStaticVoidMethod(mClazz, fields.postEvent, mWeakThiz);
+    } else {
+        LOGW("onFrameAvailable event will not posted");
+    }
 }
 
 // ----------------------------------------------------------------------------
@@ -123,7 +152,6 @@
     if (fields.postEvent == NULL) {
         LOGE("can't find android/graphics/SurfaceTexture.postEventFromNative");
     }
-
 }
 
 static void SurfaceTexture_init(JNIEnv* env, jobject thiz, jint texName,
@@ -156,6 +184,13 @@
     SurfaceTexture_setSurfaceTexture(env, thiz, 0);
 }
 
+static void SurfaceTexture_setDefaultBufferSize(
+        JNIEnv* env, jobject thiz, jint width, jint height)
+{
+    sp<SurfaceTexture> surfaceTexture(SurfaceTexture_getSurfaceTexture(env, thiz));
+    surfaceTexture->setDefaultBufferSize(width, height);
+}
+
 static void SurfaceTexture_updateTexImage(JNIEnv* env, jobject thiz)
 {
     sp<SurfaceTexture> surfaceTexture(SurfaceTexture_getSurfaceTexture(env, thiz));
@@ -179,12 +214,11 @@
 
 // ----------------------------------------------------------------------------
 
-const char* const kSurfaceTextureClassPathName = "android/graphics/SurfaceTexture";
-
 static JNINativeMethod gSurfaceTextureMethods[] = {
     {"nativeClassInit",          "()V",   (void*)SurfaceTexture_classInit },
     {"nativeInit",               "(ILjava/lang/Object;)V", (void*)SurfaceTexture_init },
     {"nativeFinalize",           "()V",   (void*)SurfaceTexture_finalize },
+    {"nativeSetDefaultBufferSize", "(II)V", (void*)SurfaceTexture_setDefaultBufferSize },
     {"nativeUpdateTexImage",     "()V",   (void*)SurfaceTexture_updateTexImage },
     {"nativeGetTransformMatrix", "([F)V", (void*)SurfaceTexture_getTransformMatrix },
     {"nativeGetTimestamp",       "()J",   (void*)SurfaceTexture_getTimestamp }
diff --git a/core/jni/android/graphics/TextLayout.cpp b/core/jni/android/graphics/TextLayout.cpp
index 46e6c2b..7e89a37 100644
--- a/core/jni/android/graphics/TextLayout.cpp
+++ b/core/jni/android/graphics/TextLayout.cpp
@@ -254,21 +254,21 @@
 void TextLayout::getTextRunAdvances(SkPaint* paint, const jchar* chars, jint start,
                                     jint count, jint contextCount, jint dirFlags,
                                     jfloat* resultAdvances, jfloat& resultTotalAdvance) {
+    sp<TextLayoutCacheValue> value;
 #if USE_TEXT_LAYOUT_CACHE
     // Return advances from the cache. Compute them if needed
-    sp<TextLayoutCacheValue> layout = gTextLayoutCache.getValue(
+    value = gTextLayoutCache.getValue(
             paint, chars, start, count, contextCount, dirFlags);
-    if (layout != NULL) {
-        if (resultAdvances != NULL) {
-            memcpy(resultAdvances, layout->getAdvances(), layout->getAdvancesCount() * sizeof(jfloat));
-        }
-        resultTotalAdvance = layout->getTotalAdvance();
-    }
 #else
-    // Compute advances and return them
-    TextLayoutCacheValue::computeValuesWithHarfbuzz(paint, chars, start, count, contextCount,
-            dirFlags, resultAdvances, &resultTotalAdvance, NULL, NULL );
+    value = new TextLayoutCacheValue();
+    value->computeValues(paint, chars, start, count, contextCount, dirFlags);
 #endif
+    if (value != NULL) {
+        if (resultAdvances != NULL) {
+            memcpy(resultAdvances, value->getAdvances(), value->getAdvancesCount() * sizeof(jfloat));
+        }
+        resultTotalAdvance = value->getTotalAdvance();
+    }
 }
 
 void TextLayout::getTextRunAdvancesHB(SkPaint* paint, const jchar* chars, jint start,
diff --git a/core/jni/android_app_backup_FullBackup.cpp b/core/jni/android_app_backup_FullBackup.cpp
index ecfe5ff..b36fa3e 100644
--- a/core/jni/android_app_backup_FullBackup.cpp
+++ b/core/jni/android_app_backup_FullBackup.cpp
@@ -73,6 +73,8 @@
 static int backupToTar(JNIEnv* env, jobject clazz, jstring packageNameObj,
         jstring domainObj, jstring linkdomain,
         jstring rootpathObj, jstring pathObj, jobject dataOutputObj) {
+    int ret;
+
     // Extract the various strings, allowing for null object pointers
     const char* packagenamechars = env->GetStringUTFChars(packageNameObj, NULL);
     const char* rootchars = env->GetStringUTFChars(rootpathObj, NULL);
diff --git a/core/jni/android_media_AudioSystem.cpp b/core/jni/android_media_AudioSystem.cpp
index 246c0e5..0c5101f 100644
--- a/core/jni/android_media_AudioSystem.cpp
+++ b/core/jni/android_media_AudioSystem.cpp
@@ -31,7 +31,7 @@
 #include <media/AudioTrack.h>
 
 #include <system/audio.h>
-#include <hardware/audio_policy.h>
+#include <system/audio_policy.h>
 
 // ----------------------------------------------------------------------------
 
diff --git a/core/jni/android_nfc_NdefMessage.cpp b/core/jni/android_nfc_NdefMessage.cpp
index d9b64aa..41099cb 100644
--- a/core/jni/android_nfc_NdefMessage.cpp
+++ b/core/jni/android_nfc_NdefMessage.cpp
@@ -102,6 +102,19 @@
         }
         TRACE("phFriNfc_NdefRecord_Parse() returned 0x%04x", status);
 
+        // We don't exactly know what *is* a valid length, but a simple
+        // sanity check is to make sure that the length of the header
+        // plus all fields does not exceed raw_msg_size. The min length
+        // of the header is 3 bytes: TNF, Type Length, Payload Length
+        // (ID length field is optional!)
+        uint64_t indicatedMsgLength = 3 + record.TypeLength + record.IdLength +
+                (uint64_t)record.PayloadLength;
+        if (indicatedMsgLength >
+                (uint64_t)raw_msg_size) {
+            LOGE("phFri_NdefRecord_Parse: invalid length field");
+            goto end;
+        }
+
         type = e->NewByteArray(record.TypeLength);
         if (type == NULL) {
             LOGD("NFC_Set Record Type Error\n");
diff --git a/core/jni/android_server_BluetoothService.cpp b/core/jni/android_server_BluetoothService.cpp
index 5c6958a..ac75634 100644
--- a/core/jni/android_server_BluetoothService.cpp
+++ b/core/jni/android_server_BluetoothService.cpp
@@ -250,15 +250,15 @@
 #endif
 }
 
-static void stopDiscoveryNative(JNIEnv *env, jobject object) {
-    LOGV("%s", __FUNCTION__);
+static jboolean stopDiscoveryNative(JNIEnv *env, jobject object) {
+    LOGV(__FUNCTION__);
 #ifdef HAVE_BLUETOOTH
     DBusMessage *msg = NULL;
     DBusMessage *reply = NULL;
     DBusError err;
     const char *name;
-    jstring ret;
     native_data_t *nat;
+    jboolean ret = JNI_FALSE;
 
     dbus_error_init(&err);
 
@@ -288,11 +288,16 @@
         } else {
             LOG_AND_FREE_DBUS_ERROR_WITH_MSG(&err, msg);
         }
+        goto done;
     }
 
+    ret = JNI_TRUE;
 done:
     if (msg) dbus_message_unref(msg);
     if (reply) dbus_message_unref(reply);
+    return ret;
+#else
+    return JNI_FALSE;
 #endif
 }
 
diff --git a/core/jni/android_util_Process.cpp b/core/jni/android_util_Process.cpp
index e5c28489..0960b25 100644
--- a/core/jni/android_util_Process.cpp
+++ b/core/jni/android_util_Process.cpp
@@ -38,18 +38,7 @@
 #include <grp.h>
 #include <pwd.h>
 #include <signal.h>
-
-/* desktop Linux needs a little help with gettid() */
-#if defined(HAVE_GETTID) && !defined(HAVE_ANDROID_OS)
-#define __KERNEL__
-# include <linux/unistd.h>
-#ifdef _syscall0
-_syscall0(pid_t,gettid)
-#else
-pid_t gettid() { return syscall(__NR_gettid);}
-#endif
-#undef __KERNEL__
-#endif
+#include <unistd.h>
 
 #define POLICY_DEBUG 0
 #define GUARD_THREAD_PRIORITY 0
diff --git a/core/jni/android_view_GLES20Canvas.cpp b/core/jni/android_view_GLES20Canvas.cpp
index e539cd2..e301e44 100644
--- a/core/jni/android_view_GLES20Canvas.cpp
+++ b/core/jni/android_view_GLES20Canvas.cpp
@@ -22,6 +22,7 @@
 #include "GraphicsJNI.h"
 #include <nativehelper/JNIHelp.h>
 #include <android_runtime/AndroidRuntime.h>
+#include <android_runtime/android_graphics_SurfaceTexture.h>
 #include <utils/ResourceTypes.h>
 
 #include <gui/SurfaceTexture.h>
@@ -42,7 +43,7 @@
 #include <SkiaColorFilter.h>
 #include <Rect.h>
 
-#include "TextLayout.h"
+#include <TextLayout.h>
 
 namespace android {
 
@@ -91,11 +92,29 @@
     eglSurfaceAttrib(display, surface, EGL_SWAP_BEHAVIOR, EGL_BUFFER_PRESERVED);
 
     EGLint error = eglGetError();
-    RENDERER_LOGD("Could not enable buffer preserved swap behavior (%x)", error);
+    if (error != EGL_SUCCESS) {
+        RENDERER_LOGD("Could not enable buffer preserved swap behavior (%x)", error);
+    }
 
     return error == EGL_SUCCESS;
 }
 
+static jboolean android_view_GLES20Canvas_isBackBufferPreserved(JNIEnv* env, jobject clazz) {
+    EGLDisplay display = eglGetCurrentDisplay();
+    EGLSurface surface = eglGetCurrentSurface(EGL_DRAW);
+    EGLint value;
+
+    eglGetError();
+    eglQuerySurface(display, surface, EGL_SWAP_BEHAVIOR, &value);
+
+    EGLint error = eglGetError();
+    if (error != EGL_SUCCESS) {
+        RENDERER_LOGD("Could not query buffer preserved swap behavior (%x)", error);
+    }
+
+    return error == EGL_SUCCESS && value == EGL_BUFFER_PRESERVED;
+}
+
 // ----------------------------------------------------------------------------
 // Constructors
 // ----------------------------------------------------------------------------
@@ -419,19 +438,25 @@
 
 static void renderText(OpenGLRenderer* renderer, const jchar* text, int count,
         jfloat x, jfloat y, int flags, SkPaint* paint) {
-#if 0 // TODO: replace "0" by "RTL_USE_HARFBUZZ" when renderer->drawGlyphs() is implemented
-    sp<TextLayoutCacheValue> value = gTextLayoutCache.getValue(
-            paint, text, 0, count, count, flags);
+#if RTL_USE_HARFBUZZ
+    sp<TextLayoutCacheValue> value;
+#if USE_TEXT_LAYOUT_CACHE
+    value = gTextLayoutCache.getValue(paint, text, 0, count, count, flags);
     if (value == NULL) {
         LOGE("Cannot get TextLayoutCache value");
         return ;
     }
+#else
+    value = new TextLayoutCacheValue();
+    value->computeValues(paint, text, 0, count, count, flags);
+#endif
 #if DEBUG_GLYPHS
     logGlyphs(value);
 #endif
     const jchar* glyphArray = value->getGlyphs();
     int glyphCount = value->getGlyphsCount();
-    renderer->drawGlyphs((const char*) glyphArray, 0, glyphCount << 1, x, y, paint);
+    int bytesCount = glyphCount * sizeof(jchar);
+    renderer->drawText((const char*) glyphArray, bytesCount, glyphCount, x, y, paint);
 #else
     const jchar *workText;
     jchar* buffer = NULL;
@@ -446,19 +471,25 @@
 static void renderTextRun(OpenGLRenderer* renderer, const jchar* text,
         jint start, jint count, jint contextCount, jfloat x, jfloat y,
         int flags, SkPaint* paint) {
-#if 0 // TODO: replace "0" by "RTL_USE_HARFBUZZ" when renderer->drawGlyphs() is implemented
-    sp<TextLayoutCacheValue> value = gTextLayoutCache.getValue(
-            paint, text, start, count, contextCount, flags);
+#if RTL_USE_HARFBUZZ
+    sp<TextLayoutCacheValue> value;
+#if USE_TEXT_LAYOUT_CACHE
+    value = gTextLayoutCache.getValue(paint, text, start, count, contextCount, flags);
     if (value == NULL) {
         LOGE("Cannot get TextLayoutCache value");
         return ;
     }
+#else
+    value = new TextLayoutCacheValue();
+    value->computeValues(paint, text, start, count, contextCount, flags);
+#endif
 #if DEBUG_GLYPHS
     logGlyphs(value);
 #endif
     const jchar* glyphArray = value->getGlyphs();
     int glyphCount = value->getGlyphsCount();
-    renderer->drawGlyphs((const char*) glyphArray, 0, glyphCount << 1, x, y, paint);
+    int bytesCount = glyphCount * sizeof(jchar);
+    renderer->drawText((const char*) glyphArray, bytesCount, glyphCount, x, y, paint);
 #else
     uint8_t rtl = flags & 0x1;
     if (rtl) {
@@ -614,11 +645,13 @@
 }
 
 static void android_view_GLES20Canvas_updateTextureLayer(JNIEnv* env, jobject clazz,
-        Layer* layer, jint width, jint height, SurfaceTexture* surface) {
+        Layer* layer, jint width, jint height, jobject surface) {
     float transform[16];
-    surface->updateTexImage();
-    surface->getTransformMatrix(transform);
-    GLenum renderTarget = surface->getCurrentTextureTarget();
+    sp<SurfaceTexture> surfaceTexture(SurfaceTexture_getSurfaceTexture(env, surface));
+
+    surfaceTexture->updateTexImage();
+    surfaceTexture->getTransformMatrix(transform);
+    GLenum renderTarget = surfaceTexture->getCurrentTextureTarget();
 
     LayerRenderer::updateTextureLayer(layer, width, height, renderTarget, transform);
 }
@@ -637,6 +670,11 @@
     renderer->drawLayer(layer, x, y, paint);
 }
 
+static jboolean android_view_GLES20Canvas_copyLayer(JNIEnv* env, jobject clazz,
+        Layer* layer, SkBitmap* bitmap) {
+    return LayerRenderer::copyLayer(layer, bitmap);
+}
+
 #endif // USE_OPENGL_RENDERER
 
 // ----------------------------------------------------------------------------
@@ -674,7 +712,8 @@
     { "nIsAvailable",       "()Z",             (void*) android_view_GLES20Canvas_isAvailable },
 
 #ifdef USE_OPENGL_RENDERER
-    { "nPreserveBackBuffer", "()Z",            (void*) android_view_GLES20Canvas_preserveBackBuffer },
+    { "nIsBackBufferPreserved", "()Z",         (void*) android_view_GLES20Canvas_isBackBufferPreserved },
+    { "nPreserveBackBuffer",    "()Z",         (void*) android_view_GLES20Canvas_preserveBackBuffer },
 
     { "nCreateRenderer",    "()I",             (void*) android_view_GLES20Canvas_createRenderer },
     { "nDestroyRenderer",   "(I)V",            (void*) android_view_GLES20Canvas_destroyRenderer },
@@ -757,10 +796,12 @@
     { "nCreateLayer",            "(IIZ[I)I",   (void*) android_view_GLES20Canvas_createLayer },
     { "nResizeLayer",            "(III[I)V" ,  (void*) android_view_GLES20Canvas_resizeLayer },
     { "nCreateTextureLayer",     "([I)I",      (void*) android_view_GLES20Canvas_createTextureLayer },
-    { "nUpdateTextureLayer",     "(IIII)V",    (void*) android_view_GLES20Canvas_updateTextureLayer },
+    { "nUpdateTextureLayer",     "(IIILandroid/graphics/SurfaceTexture;)V",
+                                               (void*) android_view_GLES20Canvas_updateTextureLayer },
     { "nDestroyLayer",           "(I)V",       (void*) android_view_GLES20Canvas_destroyLayer },
     { "nDestroyLayerDeferred",   "(I)V",       (void*) android_view_GLES20Canvas_destroyLayerDeferred },
     { "nDrawLayer",              "(IIFFI)V",   (void*) android_view_GLES20Canvas_drawLayer },
+    { "nCopyLayer",              "(II)Z",      (void*) android_view_GLES20Canvas_copyLayer },
 
 #endif
 };
diff --git a/core/jni/android_view_Surface.cpp b/core/jni/android_view_Surface.cpp
index ec8b6e0..70c2f7b 100644
--- a/core/jni/android_view_Surface.cpp
+++ b/core/jni/android_view_Surface.cpp
@@ -55,6 +55,9 @@
 static const char* const OutOfResourcesException =
     "android/view/Surface$OutOfResourcesException";
 
+const char* const kSurfaceSessionClassPathName = "android/view/SurfaceSession";
+const char* const kSurfaceClassPathName = "android/view/Surface";
+
 struct sso_t {
     jfieldID client;
 };
@@ -181,6 +184,11 @@
     return getSurface(env, clazz);
 }
 
+bool android_Surface_isInstanceOf(JNIEnv* env, jobject obj) {
+    jclass surfaceClass = env->FindClass(kSurfaceClassPathName);
+    return env->IsInstanceOf(obj, surfaceClass);
+}
+
 static void setSurface(JNIEnv* env, jobject clazz, const sp<Surface>& surface)
 {
     Surface* const p = (Surface*)env->GetIntField(clazz, so.surface);
@@ -759,8 +767,6 @@
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 
-const char* const kSurfaceSessionClassPathName = "android/view/SurfaceSession";
-const char* const kSurfaceClassPathName = "android/view/Surface";
 static void nativeClassInit(JNIEnv* env, jclass clazz);
 
 static JNINativeMethod gSurfaceSessionMethods[] = {
diff --git a/core/jni/android_view_TextureView.cpp b/core/jni/android_view_TextureView.cpp
index c5d86c8..b046b23 100644
--- a/core/jni/android_view_TextureView.cpp
+++ b/core/jni/android_view_TextureView.cpp
@@ -17,6 +17,7 @@
 #include "jni.h"
 #include <nativehelper/JNIHelp.h>
 #include <android_runtime/AndroidRuntime.h>
+#include <android_runtime/android_graphics_SurfaceTexture.h>
 
 #include <gui/SurfaceTexture.h>
 
@@ -27,10 +28,10 @@
 // ----------------------------------------------------------------------------
 
 static void android_view_TextureView_setDefaultBufferSize(JNIEnv* env, jobject,
-    jint surfaceTexture, jint width, jint height) {
+    jobject surface, jint width, jint height) {
 
-    sp<SurfaceTexture> surface = reinterpret_cast<SurfaceTexture*>(surfaceTexture);
-    surface->setDefaultBufferSize(width, height);
+    sp<SurfaceTexture> surfaceTexture(SurfaceTexture_getSurfaceTexture(env, surface));
+    surfaceTexture->setDefaultBufferSize(width, height);
 }
 
 // ----------------------------------------------------------------------------
@@ -40,7 +41,8 @@
 const char* const kClassPathName = "android/view/TextureView";
 
 static JNINativeMethod gMethods[] = {
-    {   "nSetDefaultBufferSize", "(III)V", (void*) android_view_TextureView_setDefaultBufferSize }
+    {   "nSetDefaultBufferSize", "(Landroid/graphics/SurfaceTexture;II)V",
+            (void*) android_view_TextureView_setDefaultBufferSize }
 };
 
 int register_android_view_TextureView(JNIEnv* env) {
diff --git a/core/jni/android_view_ViewAncestor.cpp b/core/jni/android_view_ViewAncestor.cpp
deleted file mode 100644
index d8e1124..0000000
--- a/core/jni/android_view_ViewAncestor.cpp
+++ /dev/null
@@ -1,95 +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.
- */
-
-#include <stdio.h>
-#include <assert.h>
-#include <sys/socket.h>
-
-#include <core/SkCanvas.h>
-#include <core/SkDevice.h>
-#include <core/SkPaint.h>
-#include <utils/SkGLCanvas.h>
-#include "GraphicsJNI.h"
-
-#include "jni.h"
-#include <nativehelper/JNIHelp.h>
-#include <android_runtime/AndroidRuntime.h>
-#include <utils/misc.h>
-
-// ----------------------------------------------------------------------------
-
-namespace android {
-
-static int gPrevDur;
-
-static void android_view_ViewAncestor_showFPS(JNIEnv* env, jobject, jobject jcanvas,
-                                          jint dur) {
-    NPE_CHECK_RETURN_VOID(env, jcanvas);
-    SkCanvas* canvas = GraphicsJNI::getNativeCanvas(env, jcanvas);
-    const SkBitmap& bm = canvas->getDevice()->accessBitmap(false);
-    int height = bm.height();
-    SkScalar bot = SkIntToScalar(height);
-
-    if (height < 200) {
-        return;
-    }
-
-    SkMatrix m;
-    SkRect   r;
-    SkPaint  p;
-    char    str[4];
-
-    dur = (gPrevDur + dur) >> 1;
-    gPrevDur = dur;
-
-    dur = 1000 / dur;
-    str[3] = (char)('0' + dur % 10); dur /= 10;
-    str[2] = (char)('0' + dur % 10); dur /= 10;
-    str[1] = (char)('0' + dur % 10); dur /= 10;
-    str[0] = (char)('0' + dur % 10);
-
-    m.reset();
-    r.set(0, bot-SkIntToScalar(10), SkIntToScalar(26), bot);
-    p.setAntiAlias(true);
-    p.setTextSize(SkIntToScalar(10));
-
-    canvas->save();
-    canvas->setMatrix(m);
-    canvas->clipRect(r, SkRegion::kReplace_Op);
-    p.setColor(SK_ColorWHITE);
-    canvas->drawPaint(p);
-    p.setColor(SK_ColorBLACK);
-    canvas->drawText(str, 4, SkIntToScalar(1), bot - SK_Scalar1, p);
-    canvas->restore();
-}
-
-
-// ----------------------------------------------------------------------------
-
-const char* const kClassPathName = "android/view/ViewAncestor";
-
-static JNINativeMethod gMethods[] = {
-    {   "nativeShowFPS", "(Landroid/graphics/Canvas;I)V",
-                                        (void*)android_view_ViewAncestor_showFPS }
-};
-
-int register_android_view_ViewAncestor(JNIEnv* env) {
-    return AndroidRuntime::registerNativeMethods(env,
-            kClassPathName, gMethods, NELEM(gMethods));
-}
-
-};
-
diff --git a/core/jni/com_google_android_gles_jni_EGLImpl.cpp b/core/jni/com_google_android_gles_jni_EGLImpl.cpp
index f777527..02974f9a 100644
--- a/core/jni/com_google_android_gles_jni_EGLImpl.cpp
+++ b/core/jni/com_google_android_gles_jni_EGLImpl.cpp
@@ -18,6 +18,7 @@
 #include "JNIHelp.h"
 #include <android_runtime/AndroidRuntime.h>
 #include <android_runtime/android_view_Surface.h>
+#include <android_runtime/android_graphics_SurfaceTexture.h>
 #include <utils/misc.h>
 
 #include <EGL/egl.h>
@@ -323,7 +324,7 @@
 }
 
 static jint jni_eglCreateWindowSurfaceTexture(JNIEnv *_env, jobject _this, jobject display,
-        jobject config, jint native_window, jintArray attrib_list) {
+        jobject config, jobject native_window, jintArray attrib_list) {
     if (display == NULL || config == NULL
         || !validAttribList(_env, attrib_list)) {
         jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
@@ -339,7 +340,7 @@
         return 0;
     }
     
-    sp<SurfaceTexture> surfaceTexture = reinterpret_cast<SurfaceTexture*>(native_window);
+    sp<SurfaceTexture> surfaceTexture(SurfaceTexture_getSurfaceTexture(_env, native_window));
 
     window = new SurfaceTextureClient(surfaceTexture);
     if (window == NULL)
@@ -540,7 +541,7 @@
 {"_eglCreatePbufferSurface","(" DISPLAY CONFIG "[I)I", (void*)jni_eglCreatePbufferSurface },
 {"_eglCreatePixmapSurface", "(" SURFACE DISPLAY CONFIG OBJECT "[I)V", (void*)jni_eglCreatePixmapSurface },
 {"_eglCreateWindowSurface", "(" DISPLAY CONFIG OBJECT "[I)I", (void*)jni_eglCreateWindowSurface },
-{"_eglCreateWindowSurfaceTexture", "(" DISPLAY CONFIG "I[I)I", (void*)jni_eglCreateWindowSurfaceTexture },
+{"_eglCreateWindowSurfaceTexture", "(" DISPLAY CONFIG OBJECT "[I)I", (void*)jni_eglCreateWindowSurfaceTexture },
 {"eglDestroyContext",      "(" DISPLAY CONTEXT ")Z", (void*)jni_eglDestroyContext },
 {"eglDestroySurface",      "(" DISPLAY SURFACE ")Z", (void*)jni_eglDestroySurface },
 {"eglMakeCurrent",         "(" DISPLAY SURFACE SURFACE CONTEXT")Z", (void*)jni_eglMakeCurrent },
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index 419578c..47902a8 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -91,6 +91,8 @@
     <protected-broadcast android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
     <protected-broadcast android:name="android.hardware.usb.action.USB_DEVICE_DETACHED" />
 
+    <protected-broadcast android:name="android.net.vpn.action.REVOKED" />
+
     <protected-broadcast android:name="android.nfc.action.LLCP_LINK_STATE_CHANGED" />
     <protected-broadcast android:name="com.android.nfc_extras.action.RF_FIELD_ON_DETECTED" />
     <protected-broadcast android:name="com.android.nfc_extras.action.RF_FIELD_OFF_DETECTED" />
@@ -159,6 +161,15 @@
         android:label="@string/permlab_receiveMms"
         android:description="@string/permdesc_receiveMms" />
 
+    <!-- Allows an application to receive emergency cell broadcast messages,
+         to record or display them to the user. Reserved for system apps.
+         @hide Pending API council approval -->
+    <permission android:name="android.permission.RECEIVE_EMERGENCY_BROADCAST"
+        android:permissionGroup="android.permission-group.MESSAGES"
+        android:protectionLevel="signatureOrSystem"
+        android:label="@string/permlab_receiveEmergencyBroadcast"
+        android:description="@string/permdesc_receiveEmergencyBroadcast" />
+
     <!-- Allows an application to read SMS messages. -->
     <permission android:name="android.permission.READ_SMS"
         android:permissionGroup="android.permission-group.MESSAGES"
@@ -208,6 +219,22 @@
         android:label="@string/permlab_writeContacts"
         android:description="@string/permdesc_writeContacts" />
 
+
+    <!-- Allows an application to read the user's personal profile data. -->
+    <permission android:name="android.permission.READ_PROFILE"
+        android:permissionGroup="android.permission-group.PERSONAL_INFO"
+        android:protectionLevel="dangerous"
+        android:label="@string/permlab_readProfile"
+        android:description="@string/permdesc_readProfile" />
+
+    <!-- Allows an application to write (but not read) the user's
+         personal profile data. -->
+    <permission android:name="android.permission.WRITE_PROFILE"
+        android:permissionGroup="android.permission-group.PERSONAL_INFO"
+        android:protectionLevel="dangerous"
+        android:label="@string/permlab_writeProfile"
+        android:description="@string/permdesc_writeProfile" />
+
     <!-- Allows an application to read the user's calendar data. -->
     <permission android:name="android.permission.READ_CALENDAR"
         android:permissionGroup="android.permission-group.PERSONAL_INFO"
@@ -677,6 +704,14 @@
         android:label="@string/permlab_dump"
         android:description="@string/permdesc_dump" />
 
+    <!-- Allows an application to retrieve the content of the active window
+         An active window is the window that has fired an accessibility event. -->
+    <permission android:name="android.permission.RETRIEVE_WINDOW_CONTENT"
+        android:permissionGroup="android.permission-group.PERSONAL_INFO"
+        android:protectionLevel="signatureOrSystem"
+        android:label="@string/permlab_retrieve_window_content"
+        android:description="@string/permdesc_retrieve_window_content" />
+
     <!-- Allows an application to open windows using the type
          {@link android.view.WindowManager.LayoutParams#TYPE_SYSTEM_ALERT},
          shown on top of all other applications.  Very few applications
@@ -1098,6 +1133,13 @@
         android:description="@string/permdesc_setOrientation"
         android:protectionLevel="signature" />
 
+    <!-- Allows low-level access to setting the pointer speed.
+         Not for use by normal applications. -->
+    <permission android:name="android.permission.SET_POINTER_SPEED"
+        android:label="@string/permlab_setPointerSpeed"
+        android:description="@string/permdesc_setPointerSpeed"
+        android:protectionLevel="signature" />
+
     <!-- Allows an application to install packages. -->
     <permission android:name="android.permission.INSTALL_PACKAGES"
         android:label="@string/permlab_installPackages"
@@ -1337,6 +1379,19 @@
     <permission android:name="android.permission.CRYPT_KEEPER"
         android:protectionLevel="signatureOrSystem" />
 
+    <!-- Allows an application to read historical network usage for
+         specific networks and applications. @hide -->
+    <permission android:name="android.permission.READ_NETWORK_USAGE_HISTORY"
+        android:label="@string/permlab_readNetworkUsageHistory"
+        android:description="@string/permdesc_readNetworkUsageHistory"
+        android:protectionLevel="signature" />
+
+    <!-- Allows an application to manage network policies (such as warning and disable
+         limits) and to define application-specific rules. @hide -->
+    <permission android:name="android.permission.MANAGE_NETWORK_POLICY"
+        android:label="@string/permlab_manageNetworkPolicy"
+        android:description="@string/permdesc_manageNetworkPolicy"
+        android:protectionLevel="signature" />
 
     <!-- C2DM permission. 
          @hide Used internally.
diff --git a/core/res/res/drawable-hdpi/btn_code_lock_default_holo.png b/core/res/res/drawable-hdpi/btn_code_lock_default_holo.png
new file mode 100644
index 0000000..94d27cf
--- /dev/null
+++ b/core/res/res/drawable-hdpi/btn_code_lock_default_holo.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/btn_code_lock_touched_holo.png b/core/res/res/drawable-hdpi/btn_code_lock_touched_holo.png
new file mode 100644
index 0000000..94d27cf
--- /dev/null
+++ b/core/res/res/drawable-hdpi/btn_code_lock_touched_holo.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/dialog_bottom_holo_dark.9.png b/core/res/res/drawable-hdpi/dialog_bottom_holo_dark.9.png
index 32c2c97..5225a81 100644
--- a/core/res/res/drawable-hdpi/dialog_bottom_holo_dark.9.png
+++ b/core/res/res/drawable-hdpi/dialog_bottom_holo_dark.9.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/dialog_bottom_holo_light.9.png b/core/res/res/drawable-hdpi/dialog_bottom_holo_light.9.png
index f1cba06..2e7e973 100644
--- a/core/res/res/drawable-hdpi/dialog_bottom_holo_light.9.png
+++ b/core/res/res/drawable-hdpi/dialog_bottom_holo_light.9.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/dialog_full_holo_dark.9.png b/core/res/res/drawable-hdpi/dialog_full_holo_dark.9.png
index 08b163a..4591627 100644
--- a/core/res/res/drawable-hdpi/dialog_full_holo_dark.9.png
+++ b/core/res/res/drawable-hdpi/dialog_full_holo_dark.9.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/dialog_full_holo_light.9.png b/core/res/res/drawable-hdpi/dialog_full_holo_light.9.png
index 77ec017..9cf1826 100644
--- a/core/res/res/drawable-hdpi/dialog_full_holo_light.9.png
+++ b/core/res/res/drawable-hdpi/dialog_full_holo_light.9.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/dialog_middle_holo_dark.9.png b/core/res/res/drawable-hdpi/dialog_middle_holo_dark.9.png
index 029f186..a47ef40 100644
--- a/core/res/res/drawable-hdpi/dialog_middle_holo_dark.9.png
+++ b/core/res/res/drawable-hdpi/dialog_middle_holo_dark.9.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/dialog_middle_holo_light.9.png b/core/res/res/drawable-hdpi/dialog_middle_holo_light.9.png
index abaea2d..9b50c73 100644
--- a/core/res/res/drawable-hdpi/dialog_middle_holo_light.9.png
+++ b/core/res/res/drawable-hdpi/dialog_middle_holo_light.9.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/dialog_top_holo_dark.9.png b/core/res/res/drawable-hdpi/dialog_top_holo_dark.9.png
index acbd7cf..a0d36de 100644
--- a/core/res/res/drawable-hdpi/dialog_top_holo_dark.9.png
+++ b/core/res/res/drawable-hdpi/dialog_top_holo_dark.9.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/dialog_top_holo_light.9.png b/core/res/res/drawable-hdpi/dialog_top_holo_light.9.png
index 8982396..805b9567 100644
--- a/core/res/res/drawable-hdpi/dialog_top_holo_light.9.png
+++ b/core/res/res/drawable-hdpi/dialog_top_holo_light.9.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/ic_lock_idle_alarm.png b/core/res/res/drawable-hdpi/ic_lock_idle_alarm.png
index 6b4f66d..3cadaff 100644
--- a/core/res/res/drawable-hdpi/ic_lock_idle_alarm.png
+++ b/core/res/res/drawable-hdpi/ic_lock_idle_alarm.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/ic_lockscreen_answer_active.png b/core/res/res/drawable-hdpi/ic_lockscreen_answer_active.png
new file mode 100644
index 0000000..8089912
--- /dev/null
+++ b/core/res/res/drawable-hdpi/ic_lockscreen_answer_active.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/ic_lockscreen_answer_focused.png b/core/res/res/drawable-hdpi/ic_lockscreen_answer_focused.png
new file mode 100644
index 0000000..e4ba8fd
--- /dev/null
+++ b/core/res/res/drawable-hdpi/ic_lockscreen_answer_focused.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/ic_lockscreen_answer_normal.png b/core/res/res/drawable-hdpi/ic_lockscreen_answer_normal.png
new file mode 100644
index 0000000..c9197c8
--- /dev/null
+++ b/core/res/res/drawable-hdpi/ic_lockscreen_answer_normal.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/ic_lockscreen_chevron_down.png b/core/res/res/drawable-hdpi/ic_lockscreen_chevron_down.png
new file mode 100644
index 0000000..620844e
--- /dev/null
+++ b/core/res/res/drawable-hdpi/ic_lockscreen_chevron_down.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/ic_lockscreen_chevron_left.png b/core/res/res/drawable-hdpi/ic_lockscreen_chevron_left.png
new file mode 100644
index 0000000..d008afa
--- /dev/null
+++ b/core/res/res/drawable-hdpi/ic_lockscreen_chevron_left.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/ic_lockscreen_chevron_right.png b/core/res/res/drawable-hdpi/ic_lockscreen_chevron_right.png
new file mode 100644
index 0000000..e508900
--- /dev/null
+++ b/core/res/res/drawable-hdpi/ic_lockscreen_chevron_right.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/ic_lockscreen_chevron_up.png b/core/res/res/drawable-hdpi/ic_lockscreen_chevron_up.png
new file mode 100644
index 0000000..4ffa833
--- /dev/null
+++ b/core/res/res/drawable-hdpi/ic_lockscreen_chevron_up.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/ic_lockscreen_decline_activated.png b/core/res/res/drawable-hdpi/ic_lockscreen_decline_activated.png
new file mode 100644
index 0000000..9866769
--- /dev/null
+++ b/core/res/res/drawable-hdpi/ic_lockscreen_decline_activated.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/ic_lockscreen_decline_focused.png b/core/res/res/drawable-hdpi/ic_lockscreen_decline_focused.png
new file mode 100644
index 0000000..f5dfacc4
--- /dev/null
+++ b/core/res/res/drawable-hdpi/ic_lockscreen_decline_focused.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/ic_lockscreen_decline_normal.png b/core/res/res/drawable-hdpi/ic_lockscreen_decline_normal.png
new file mode 100644
index 0000000..b4d399d
--- /dev/null
+++ b/core/res/res/drawable-hdpi/ic_lockscreen_decline_normal.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/ic_lockscreen_emergencycall_normal.png b/core/res/res/drawable-hdpi/ic_lockscreen_emergencycall_normal.png
new file mode 100644
index 0000000..460495a
--- /dev/null
+++ b/core/res/res/drawable-hdpi/ic_lockscreen_emergencycall_normal.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/ic_lockscreen_emergencycall_pressed.png b/core/res/res/drawable-hdpi/ic_lockscreen_emergencycall_pressed.png
new file mode 100644
index 0000000..b0f7ae9
--- /dev/null
+++ b/core/res/res/drawable-hdpi/ic_lockscreen_emergencycall_pressed.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/ic_lockscreen_forgotpassword_normal.png b/core/res/res/drawable-hdpi/ic_lockscreen_forgotpassword_normal.png
new file mode 100644
index 0000000..6402d3d
--- /dev/null
+++ b/core/res/res/drawable-hdpi/ic_lockscreen_forgotpassword_normal.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/ic_lockscreen_forgotpassword_pressed.png b/core/res/res/drawable-hdpi/ic_lockscreen_forgotpassword_pressed.png
new file mode 100644
index 0000000..83be046
--- /dev/null
+++ b/core/res/res/drawable-hdpi/ic_lockscreen_forgotpassword_pressed.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/ic_lockscreen_handle_normal.png b/core/res/res/drawable-hdpi/ic_lockscreen_handle_normal.png
new file mode 100644
index 0000000..e21a87c
--- /dev/null
+++ b/core/res/res/drawable-hdpi/ic_lockscreen_handle_normal.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/ic_lockscreen_handle_pressed.png b/core/res/res/drawable-hdpi/ic_lockscreen_handle_pressed.png
new file mode 100644
index 0000000..3283f99
--- /dev/null
+++ b/core/res/res/drawable-hdpi/ic_lockscreen_handle_pressed.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/ic_lockscreen_lock_normal.png b/core/res/res/drawable-hdpi/ic_lockscreen_lock_normal.png
new file mode 100644
index 0000000..732133c
--- /dev/null
+++ b/core/res/res/drawable-hdpi/ic_lockscreen_lock_normal.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/ic_lockscreen_lock_pressed.png b/core/res/res/drawable-hdpi/ic_lockscreen_lock_pressed.png
new file mode 100644
index 0000000..0bbf62f
--- /dev/null
+++ b/core/res/res/drawable-hdpi/ic_lockscreen_lock_pressed.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/ic_lockscreen_outerring.png b/core/res/res/drawable-hdpi/ic_lockscreen_outerring.png
new file mode 100644
index 0000000..5294bc5
--- /dev/null
+++ b/core/res/res/drawable-hdpi/ic_lockscreen_outerring.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/ic_lockscreen_silent_activated.png b/core/res/res/drawable-hdpi/ic_lockscreen_silent_activated.png
new file mode 100644
index 0000000..fce4980
--- /dev/null
+++ b/core/res/res/drawable-hdpi/ic_lockscreen_silent_activated.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/ic_lockscreen_silent_focused.png b/core/res/res/drawable-hdpi/ic_lockscreen_silent_focused.png
new file mode 100644
index 0000000..ecafbea
--- /dev/null
+++ b/core/res/res/drawable-hdpi/ic_lockscreen_silent_focused.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/ic_lockscreen_silent_normal.png b/core/res/res/drawable-hdpi/ic_lockscreen_silent_normal.png
new file mode 100644
index 0000000..1f527b7
--- /dev/null
+++ b/core/res/res/drawable-hdpi/ic_lockscreen_silent_normal.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/ic_lockscreen_soundon_activated.png b/core/res/res/drawable-hdpi/ic_lockscreen_soundon_activated.png
new file mode 100644
index 0000000..73f01c9
--- /dev/null
+++ b/core/res/res/drawable-hdpi/ic_lockscreen_soundon_activated.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/ic_lockscreen_soundon_focused.png b/core/res/res/drawable-hdpi/ic_lockscreen_soundon_focused.png
new file mode 100644
index 0000000..d4e558d
--- /dev/null
+++ b/core/res/res/drawable-hdpi/ic_lockscreen_soundon_focused.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/ic_lockscreen_soundon_normal.png b/core/res/res/drawable-hdpi/ic_lockscreen_soundon_normal.png
new file mode 100644
index 0000000..5d999a6
--- /dev/null
+++ b/core/res/res/drawable-hdpi/ic_lockscreen_soundon_normal.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/ic_lockscreen_text_activated.png b/core/res/res/drawable-hdpi/ic_lockscreen_text_activated.png
new file mode 100644
index 0000000..d01bdb2
--- /dev/null
+++ b/core/res/res/drawable-hdpi/ic_lockscreen_text_activated.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/ic_lockscreen_text_focusde.png b/core/res/res/drawable-hdpi/ic_lockscreen_text_focusde.png
new file mode 100644
index 0000000..72b8f0a
--- /dev/null
+++ b/core/res/res/drawable-hdpi/ic_lockscreen_text_focusde.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/ic_lockscreen_text_normal.png b/core/res/res/drawable-hdpi/ic_lockscreen_text_normal.png
new file mode 100644
index 0000000..bf73a26
--- /dev/null
+++ b/core/res/res/drawable-hdpi/ic_lockscreen_text_normal.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/ic_lockscreen_unlock_activated.png b/core/res/res/drawable-hdpi/ic_lockscreen_unlock_activated.png
new file mode 100644
index 0000000..d333946
--- /dev/null
+++ b/core/res/res/drawable-hdpi/ic_lockscreen_unlock_activated.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/ic_lockscreen_unlock_focused.png b/core/res/res/drawable-hdpi/ic_lockscreen_unlock_focused.png
new file mode 100644
index 0000000..e053222
--- /dev/null
+++ b/core/res/res/drawable-hdpi/ic_lockscreen_unlock_focused.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/ic_lockscreen_unlock_normal.png b/core/res/res/drawable-hdpi/ic_lockscreen_unlock_normal.png
new file mode 100644
index 0000000..7db46c1
--- /dev/null
+++ b/core/res/res/drawable-hdpi/ic_lockscreen_unlock_normal.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/ic_menu_selectall_holo_dark.png b/core/res/res/drawable-hdpi/ic_menu_selectall_holo_dark.png
new file mode 100644
index 0000000..5579443
--- /dev/null
+++ b/core/res/res/drawable-hdpi/ic_menu_selectall_holo_dark.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/ic_menu_selectall_holo_light.png b/core/res/res/drawable-hdpi/ic_menu_selectall_holo_light.png
new file mode 100644
index 0000000..6674914
--- /dev/null
+++ b/core/res/res/drawable-hdpi/ic_menu_selectall_holo_light.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/indicator_code_lock_drag_direction_green_up_holo.png b/core/res/res/drawable-hdpi/indicator_code_lock_drag_direction_green_up_holo.png
new file mode 100644
index 0000000..a686975
--- /dev/null
+++ b/core/res/res/drawable-hdpi/indicator_code_lock_drag_direction_green_up_holo.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/indicator_code_lock_drag_direction_red_up_holo.png b/core/res/res/drawable-hdpi/indicator_code_lock_drag_direction_red_up_holo.png
new file mode 100644
index 0000000..92db8ef
--- /dev/null
+++ b/core/res/res/drawable-hdpi/indicator_code_lock_drag_direction_red_up_holo.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/indicator_code_lock_point_area_default_holo.png b/core/res/res/drawable-hdpi/indicator_code_lock_point_area_default_holo.png
new file mode 100644
index 0000000..237011c
--- /dev/null
+++ b/core/res/res/drawable-hdpi/indicator_code_lock_point_area_default_holo.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/indicator_code_lock_point_area_green_holo.png b/core/res/res/drawable-hdpi/indicator_code_lock_point_area_green_holo.png
new file mode 100644
index 0000000..2418017
--- /dev/null
+++ b/core/res/res/drawable-hdpi/indicator_code_lock_point_area_green_holo.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/indicator_code_lock_point_area_red_holo.png b/core/res/res/drawable-hdpi/indicator_code_lock_point_area_red_holo.png
new file mode 100644
index 0000000..2120bad
--- /dev/null
+++ b/core/res/res/drawable-hdpi/indicator_code_lock_point_area_red_holo.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/pointer_arrow.png b/core/res/res/drawable-hdpi/pointer_arrow.png
new file mode 100644
index 0000000..fbd187c
--- /dev/null
+++ b/core/res/res/drawable-hdpi/pointer_arrow.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/pointer_arrow_icon.xml b/core/res/res/drawable-hdpi/pointer_arrow_icon.xml
new file mode 100644
index 0000000..2f5676f
--- /dev/null
+++ b/core/res/res/drawable-hdpi/pointer_arrow_icon.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<pointer-icon xmlns:android="http://schemas.android.com/apk/res/android"
+    android:bitmap="@drawable/pointer_arrow"
+    android:hotSpotX="6"
+    android:hotSpotY="6" />
diff --git a/core/res/res/drawable-hdpi/pointer_spot_anchor.png b/core/res/res/drawable-hdpi/pointer_spot_anchor.png
new file mode 100644
index 0000000..d7aca36
--- /dev/null
+++ b/core/res/res/drawable-hdpi/pointer_spot_anchor.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/pointer_spot_anchor_icon.xml b/core/res/res/drawable-hdpi/pointer_spot_anchor_icon.xml
new file mode 100644
index 0000000..2222b8e
--- /dev/null
+++ b/core/res/res/drawable-hdpi/pointer_spot_anchor_icon.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<pointer-icon xmlns:android="http://schemas.android.com/apk/res/android"
+    android:bitmap="@drawable/pointer_spot_anchor"
+    android:hotSpotX="33"
+    android:hotSpotY="33" />
diff --git a/core/res/res/drawable-hdpi/pointer_spot_hover.png b/core/res/res/drawable-hdpi/pointer_spot_hover.png
new file mode 100644
index 0000000..5041aa3
--- /dev/null
+++ b/core/res/res/drawable-hdpi/pointer_spot_hover.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/pointer_spot_hover_icon.xml b/core/res/res/drawable-hdpi/pointer_spot_hover_icon.xml
new file mode 100644
index 0000000..dc62a69
--- /dev/null
+++ b/core/res/res/drawable-hdpi/pointer_spot_hover_icon.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<pointer-icon xmlns:android="http://schemas.android.com/apk/res/android"
+    android:bitmap="@drawable/pointer_spot_hover"
+    android:hotSpotX="33"
+    android:hotSpotY="33" />
diff --git a/core/res/res/drawable-hdpi/pointer_spot_touch.png b/core/res/res/drawable-hdpi/pointer_spot_touch.png
new file mode 100644
index 0000000..64a42a1
--- /dev/null
+++ b/core/res/res/drawable-hdpi/pointer_spot_touch.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/pointer_spot_touch_icon.xml b/core/res/res/drawable-hdpi/pointer_spot_touch_icon.xml
new file mode 100644
index 0000000..4bffee6
--- /dev/null
+++ b/core/res/res/drawable-hdpi/pointer_spot_touch_icon.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<pointer-icon xmlns:android="http://schemas.android.com/apk/res/android"
+    android:bitmap="@drawable/pointer_spot_touch"
+    android:hotSpotX="24"
+    android:hotSpotY="24" />
diff --git a/core/res/res/drawable-hdpi/toast_frame.9.png b/core/res/res/drawable-hdpi/toast_frame.9.png
index 08b163a..9769bbb7 100644
--- a/core/res/res/drawable-hdpi/toast_frame.9.png
+++ b/core/res/res/drawable-hdpi/toast_frame.9.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/toast_frame_holo.9.png b/core/res/res/drawable-hdpi/toast_frame_holo.9.png
index 7f830bc..9769bbb7 100644
--- a/core/res/res/drawable-hdpi/toast_frame_holo.9.png
+++ b/core/res/res/drawable-hdpi/toast_frame_holo.9.png
Binary files differ
diff --git a/core/res/res/drawable-large-nodpi/default_wallpaper.jpg b/core/res/res/drawable-large-nodpi/default_wallpaper.jpg
new file mode 100644
index 0000000..7d7cdbb
--- /dev/null
+++ b/core/res/res/drawable-large-nodpi/default_wallpaper.jpg
Binary files differ
diff --git a/core/res/res/drawable-mdpi/btn_code_lock_default.png b/core/res/res/drawable-mdpi/btn_code_lock_default.png
old mode 100644
new mode 100755
index 45cc20d..f524317
--- a/core/res/res/drawable-mdpi/btn_code_lock_default.png
+++ b/core/res/res/drawable-mdpi/btn_code_lock_default.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/btn_code_lock_default_holo.png b/core/res/res/drawable-mdpi/btn_code_lock_default_holo.png
new file mode 100644
index 0000000..7d11275
--- /dev/null
+++ b/core/res/res/drawable-mdpi/btn_code_lock_default_holo.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/btn_code_lock_touched.png b/core/res/res/drawable-mdpi/btn_code_lock_touched.png
old mode 100644
new mode 100755
index 45cc20d..5cd436c
--- a/core/res/res/drawable-mdpi/btn_code_lock_touched.png
+++ b/core/res/res/drawable-mdpi/btn_code_lock_touched.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/btn_code_lock_touched_holo.png b/core/res/res/drawable-mdpi/btn_code_lock_touched_holo.png
new file mode 100644
index 0000000..7d11275
--- /dev/null
+++ b/core/res/res/drawable-mdpi/btn_code_lock_touched_holo.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/dialog_bottom_holo_dark.9.png b/core/res/res/drawable-mdpi/dialog_bottom_holo_dark.9.png
index cc66804..a0bd4e3 100644
--- a/core/res/res/drawable-mdpi/dialog_bottom_holo_dark.9.png
+++ b/core/res/res/drawable-mdpi/dialog_bottom_holo_dark.9.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/dialog_bottom_holo_light.9.png b/core/res/res/drawable-mdpi/dialog_bottom_holo_light.9.png
index bc734c8..12abcd2 100644
--- a/core/res/res/drawable-mdpi/dialog_bottom_holo_light.9.png
+++ b/core/res/res/drawable-mdpi/dialog_bottom_holo_light.9.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/dialog_full_holo_dark.9.png b/core/res/res/drawable-mdpi/dialog_full_holo_dark.9.png
index 8603e93..adb8104 100644
--- a/core/res/res/drawable-mdpi/dialog_full_holo_dark.9.png
+++ b/core/res/res/drawable-mdpi/dialog_full_holo_dark.9.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/dialog_full_holo_light.9.png b/core/res/res/drawable-mdpi/dialog_full_holo_light.9.png
index 65a318c..d7c6bbf 100644
--- a/core/res/res/drawable-mdpi/dialog_full_holo_light.9.png
+++ b/core/res/res/drawable-mdpi/dialog_full_holo_light.9.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/dialog_middle_holo_dark.9.png b/core/res/res/drawable-mdpi/dialog_middle_holo_dark.9.png
index e39a472..42cfc52 100644
--- a/core/res/res/drawable-mdpi/dialog_middle_holo_dark.9.png
+++ b/core/res/res/drawable-mdpi/dialog_middle_holo_dark.9.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/dialog_middle_holo_light.9.png b/core/res/res/drawable-mdpi/dialog_middle_holo_light.9.png
index 68f9e57..9a08e15 100644
--- a/core/res/res/drawable-mdpi/dialog_middle_holo_light.9.png
+++ b/core/res/res/drawable-mdpi/dialog_middle_holo_light.9.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/dialog_top_holo_dark.9.png b/core/res/res/drawable-mdpi/dialog_top_holo_dark.9.png
index 32c49f2..5d86b2a 100644
--- a/core/res/res/drawable-mdpi/dialog_top_holo_dark.9.png
+++ b/core/res/res/drawable-mdpi/dialog_top_holo_dark.9.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/dialog_top_holo_light.9.png b/core/res/res/drawable-mdpi/dialog_top_holo_light.9.png
index 60aa8cb..ad22f5b 100644
--- a/core/res/res/drawable-mdpi/dialog_top_holo_light.9.png
+++ b/core/res/res/drawable-mdpi/dialog_top_holo_light.9.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/ic_lock_idle_alarm.png b/core/res/res/drawable-mdpi/ic_lock_idle_alarm.png
index 97ac023..b5d3e09 100644
--- a/core/res/res/drawable-mdpi/ic_lock_idle_alarm.png
+++ b/core/res/res/drawable-mdpi/ic_lock_idle_alarm.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/ic_lock_idle_charging.png b/core/res/res/drawable-mdpi/ic_lock_idle_charging.png
old mode 100644
new mode 100755
index 4210db2..20d6320
--- a/core/res/res/drawable-mdpi/ic_lock_idle_charging.png
+++ b/core/res/res/drawable-mdpi/ic_lock_idle_charging.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/ic_lock_idle_lock.png b/core/res/res/drawable-mdpi/ic_lock_idle_lock.png
old mode 100644
new mode 100755
index 1060f5a..0206aee
--- a/core/res/res/drawable-mdpi/ic_lock_idle_lock.png
+++ b/core/res/res/drawable-mdpi/ic_lock_idle_lock.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/ic_lock_idle_low_battery.png b/core/res/res/drawable-mdpi/ic_lock_idle_low_battery.png
old mode 100644
new mode 100755
index 72e4afa..bb96782
--- a/core/res/res/drawable-mdpi/ic_lock_idle_low_battery.png
+++ b/core/res/res/drawable-mdpi/ic_lock_idle_low_battery.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/ic_lockscreen_answer_active.png b/core/res/res/drawable-mdpi/ic_lockscreen_answer_active.png
new file mode 100644
index 0000000..0ad03c0
--- /dev/null
+++ b/core/res/res/drawable-mdpi/ic_lockscreen_answer_active.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/ic_lockscreen_answer_focused.png b/core/res/res/drawable-mdpi/ic_lockscreen_answer_focused.png
new file mode 100644
index 0000000..f46e8bd
--- /dev/null
+++ b/core/res/res/drawable-mdpi/ic_lockscreen_answer_focused.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/ic_lockscreen_answer_normal.png b/core/res/res/drawable-mdpi/ic_lockscreen_answer_normal.png
new file mode 100644
index 0000000..ddeeb18
--- /dev/null
+++ b/core/res/res/drawable-mdpi/ic_lockscreen_answer_normal.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/ic_lockscreen_chevron_down.png b/core/res/res/drawable-mdpi/ic_lockscreen_chevron_down.png
new file mode 100644
index 0000000..d3cfd17
--- /dev/null
+++ b/core/res/res/drawable-mdpi/ic_lockscreen_chevron_down.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/ic_lockscreen_chevron_left.png b/core/res/res/drawable-mdpi/ic_lockscreen_chevron_left.png
new file mode 100644
index 0000000..e5ef113
--- /dev/null
+++ b/core/res/res/drawable-mdpi/ic_lockscreen_chevron_left.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/ic_lockscreen_chevron_right.png b/core/res/res/drawable-mdpi/ic_lockscreen_chevron_right.png
new file mode 100644
index 0000000..ab723b7
--- /dev/null
+++ b/core/res/res/drawable-mdpi/ic_lockscreen_chevron_right.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/ic_lockscreen_chevron_up.png b/core/res/res/drawable-mdpi/ic_lockscreen_chevron_up.png
new file mode 100644
index 0000000..35aca4e
--- /dev/null
+++ b/core/res/res/drawable-mdpi/ic_lockscreen_chevron_up.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/ic_lockscreen_decline_activated.png b/core/res/res/drawable-mdpi/ic_lockscreen_decline_activated.png
new file mode 100644
index 0000000..d1aae18
--- /dev/null
+++ b/core/res/res/drawable-mdpi/ic_lockscreen_decline_activated.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/ic_lockscreen_decline_focused.png b/core/res/res/drawable-mdpi/ic_lockscreen_decline_focused.png
new file mode 100644
index 0000000..b52c844
--- /dev/null
+++ b/core/res/res/drawable-mdpi/ic_lockscreen_decline_focused.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/ic_lockscreen_decline_normal.png b/core/res/res/drawable-mdpi/ic_lockscreen_decline_normal.png
new file mode 100644
index 0000000..722027e
--- /dev/null
+++ b/core/res/res/drawable-mdpi/ic_lockscreen_decline_normal.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/ic_lockscreen_emergencycall_normal.png b/core/res/res/drawable-mdpi/ic_lockscreen_emergencycall_normal.png
new file mode 100644
index 0000000..cae795f
--- /dev/null
+++ b/core/res/res/drawable-mdpi/ic_lockscreen_emergencycall_normal.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/ic_lockscreen_emergencycall_pressed.png b/core/res/res/drawable-mdpi/ic_lockscreen_emergencycall_pressed.png
new file mode 100644
index 0000000..2867956
--- /dev/null
+++ b/core/res/res/drawable-mdpi/ic_lockscreen_emergencycall_pressed.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/ic_lockscreen_forgotpassword_normal.png b/core/res/res/drawable-mdpi/ic_lockscreen_forgotpassword_normal.png
new file mode 100644
index 0000000..a7e063a
--- /dev/null
+++ b/core/res/res/drawable-mdpi/ic_lockscreen_forgotpassword_normal.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/ic_lockscreen_forgotpassword_pressed.png b/core/res/res/drawable-mdpi/ic_lockscreen_forgotpassword_pressed.png
new file mode 100644
index 0000000..53af5a5
--- /dev/null
+++ b/core/res/res/drawable-mdpi/ic_lockscreen_forgotpassword_pressed.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/ic_lockscreen_handle_normal.png b/core/res/res/drawable-mdpi/ic_lockscreen_handle_normal.png
new file mode 100644
index 0000000..c10344f
--- /dev/null
+++ b/core/res/res/drawable-mdpi/ic_lockscreen_handle_normal.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/ic_lockscreen_handle_pressed.png b/core/res/res/drawable-mdpi/ic_lockscreen_handle_pressed.png
new file mode 100644
index 0000000..08c6cfe
--- /dev/null
+++ b/core/res/res/drawable-mdpi/ic_lockscreen_handle_pressed.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/ic_lockscreen_lock_normal.png b/core/res/res/drawable-mdpi/ic_lockscreen_lock_normal.png
new file mode 100644
index 0000000..30eb974
--- /dev/null
+++ b/core/res/res/drawable-mdpi/ic_lockscreen_lock_normal.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/ic_lockscreen_lock_pressed.png b/core/res/res/drawable-mdpi/ic_lockscreen_lock_pressed.png
new file mode 100644
index 0000000..aab2f6b
--- /dev/null
+++ b/core/res/res/drawable-mdpi/ic_lockscreen_lock_pressed.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/ic_lockscreen_outerring.png b/core/res/res/drawable-mdpi/ic_lockscreen_outerring.png
new file mode 100644
index 0000000..4151f73
--- /dev/null
+++ b/core/res/res/drawable-mdpi/ic_lockscreen_outerring.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/ic_lockscreen_silent_activated.png b/core/res/res/drawable-mdpi/ic_lockscreen_silent_activated.png
new file mode 100644
index 0000000..3b2f3fc
--- /dev/null
+++ b/core/res/res/drawable-mdpi/ic_lockscreen_silent_activated.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/ic_lockscreen_silent_focused.png b/core/res/res/drawable-mdpi/ic_lockscreen_silent_focused.png
new file mode 100644
index 0000000..6a5af9d
--- /dev/null
+++ b/core/res/res/drawable-mdpi/ic_lockscreen_silent_focused.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/ic_lockscreen_silent_normal.png b/core/res/res/drawable-mdpi/ic_lockscreen_silent_normal.png
new file mode 100644
index 0000000..c288ce4
--- /dev/null
+++ b/core/res/res/drawable-mdpi/ic_lockscreen_silent_normal.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/ic_lockscreen_soundon_activated.png b/core/res/res/drawable-mdpi/ic_lockscreen_soundon_activated.png
new file mode 100644
index 0000000..03f524d
--- /dev/null
+++ b/core/res/res/drawable-mdpi/ic_lockscreen_soundon_activated.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/ic_lockscreen_soundon_focused.png b/core/res/res/drawable-mdpi/ic_lockscreen_soundon_focused.png
new file mode 100644
index 0000000..db59b5f
--- /dev/null
+++ b/core/res/res/drawable-mdpi/ic_lockscreen_soundon_focused.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/ic_lockscreen_soundon_normal.png b/core/res/res/drawable-mdpi/ic_lockscreen_soundon_normal.png
new file mode 100644
index 0000000..eb6ceed
--- /dev/null
+++ b/core/res/res/drawable-mdpi/ic_lockscreen_soundon_normal.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/ic_lockscreen_text_activated.png b/core/res/res/drawable-mdpi/ic_lockscreen_text_activated.png
new file mode 100644
index 0000000..dbfc5ba
--- /dev/null
+++ b/core/res/res/drawable-mdpi/ic_lockscreen_text_activated.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/ic_lockscreen_text_focusde.png b/core/res/res/drawable-mdpi/ic_lockscreen_text_focusde.png
new file mode 100644
index 0000000..1de7586
--- /dev/null
+++ b/core/res/res/drawable-mdpi/ic_lockscreen_text_focusde.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/ic_lockscreen_text_normal.png b/core/res/res/drawable-mdpi/ic_lockscreen_text_normal.png
new file mode 100644
index 0000000..e007322
--- /dev/null
+++ b/core/res/res/drawable-mdpi/ic_lockscreen_text_normal.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/ic_lockscreen_unlock_activated.png b/core/res/res/drawable-mdpi/ic_lockscreen_unlock_activated.png
new file mode 100644
index 0000000..df47993
--- /dev/null
+++ b/core/res/res/drawable-mdpi/ic_lockscreen_unlock_activated.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/ic_lockscreen_unlock_focused.png b/core/res/res/drawable-mdpi/ic_lockscreen_unlock_focused.png
new file mode 100644
index 0000000..6f51447
--- /dev/null
+++ b/core/res/res/drawable-mdpi/ic_lockscreen_unlock_focused.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/ic_lockscreen_unlock_normal.png b/core/res/res/drawable-mdpi/ic_lockscreen_unlock_normal.png
new file mode 100644
index 0000000..dd255f5
--- /dev/null
+++ b/core/res/res/drawable-mdpi/ic_lockscreen_unlock_normal.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/ic_menu_selectall_holo_dark.png b/core/res/res/drawable-mdpi/ic_menu_selectall_holo_dark.png
new file mode 100644
index 0000000..caec299
--- /dev/null
+++ b/core/res/res/drawable-mdpi/ic_menu_selectall_holo_dark.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/ic_menu_selectall_holo_light.png b/core/res/res/drawable-mdpi/ic_menu_selectall_holo_light.png
new file mode 100644
index 0000000..434f5d1
--- /dev/null
+++ b/core/res/res/drawable-mdpi/ic_menu_selectall_holo_light.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/indicator_code_lock_drag_direction_green_up.png b/core/res/res/drawable-mdpi/indicator_code_lock_drag_direction_green_up.png
index 0bc86c3..7ddeba5 100644
--- a/core/res/res/drawable-mdpi/indicator_code_lock_drag_direction_green_up.png
+++ b/core/res/res/drawable-mdpi/indicator_code_lock_drag_direction_green_up.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/indicator_code_lock_drag_direction_green_up_holo.png b/core/res/res/drawable-mdpi/indicator_code_lock_drag_direction_green_up_holo.png
new file mode 100644
index 0000000..89d209c
--- /dev/null
+++ b/core/res/res/drawable-mdpi/indicator_code_lock_drag_direction_green_up_holo.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/indicator_code_lock_drag_direction_red_up.png b/core/res/res/drawable-mdpi/indicator_code_lock_drag_direction_red_up.png
index 2ab4547..7201e58 100644
--- a/core/res/res/drawable-mdpi/indicator_code_lock_drag_direction_red_up.png
+++ b/core/res/res/drawable-mdpi/indicator_code_lock_drag_direction_red_up.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/indicator_code_lock_drag_direction_red_up_holo.png b/core/res/res/drawable-mdpi/indicator_code_lock_drag_direction_red_up_holo.png
new file mode 100644
index 0000000..1d4cb32
--- /dev/null
+++ b/core/res/res/drawable-mdpi/indicator_code_lock_drag_direction_red_up_holo.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/indicator_code_lock_point_area_default_holo.png b/core/res/res/drawable-mdpi/indicator_code_lock_point_area_default_holo.png
new file mode 100644
index 0000000..a627cda
--- /dev/null
+++ b/core/res/res/drawable-mdpi/indicator_code_lock_point_area_default_holo.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/indicator_code_lock_point_area_green_holo.png b/core/res/res/drawable-mdpi/indicator_code_lock_point_area_green_holo.png
new file mode 100644
index 0000000..308624b
--- /dev/null
+++ b/core/res/res/drawable-mdpi/indicator_code_lock_point_area_green_holo.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/indicator_code_lock_point_area_red_holo.png b/core/res/res/drawable-mdpi/indicator_code_lock_point_area_red_holo.png
new file mode 100644
index 0000000..6c451ec
--- /dev/null
+++ b/core/res/res/drawable-mdpi/indicator_code_lock_point_area_red_holo.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/toast_frame.9.png b/core/res/res/drawable-mdpi/toast_frame.9.png
index 8603e93..06cfc70 100755
--- a/core/res/res/drawable-mdpi/toast_frame.9.png
+++ b/core/res/res/drawable-mdpi/toast_frame.9.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/toast_frame_holo.9.png b/core/res/res/drawable-mdpi/toast_frame_holo.9.png
index 911f86d..06cfc70 100755
--- a/core/res/res/drawable-mdpi/toast_frame_holo.9.png
+++ b/core/res/res/drawable-mdpi/toast_frame_holo.9.png
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/dialog_middle_holo_light.9.png b/core/res/res/drawable-xhdpi/dialog_middle_holo_light.9.png
index 55c60b8..bdb6824 100644
--- a/core/res/res/drawable-xhdpi/dialog_middle_holo_light.9.png
+++ b/core/res/res/drawable-xhdpi/dialog_middle_holo_light.9.png
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/dialog_top_holo_light.9.png b/core/res/res/drawable-xhdpi/dialog_top_holo_light.9.png
index d33d033..aa8401d 100644
--- a/core/res/res/drawable-xhdpi/dialog_top_holo_light.9.png
+++ b/core/res/res/drawable-xhdpi/dialog_top_holo_light.9.png
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/ic_lock_idle_alarm.png b/core/res/res/drawable-xhdpi/ic_lock_idle_alarm.png
new file mode 100644
index 0000000..2822a92
--- /dev/null
+++ b/core/res/res/drawable-xhdpi/ic_lock_idle_alarm.png
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/ic_lockscreen_answer_active.png b/core/res/res/drawable-xhdpi/ic_lockscreen_answer_active.png
new file mode 100644
index 0000000..8edf62d
--- /dev/null
+++ b/core/res/res/drawable-xhdpi/ic_lockscreen_answer_active.png
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/ic_lockscreen_answer_focused.png b/core/res/res/drawable-xhdpi/ic_lockscreen_answer_focused.png
new file mode 100644
index 0000000..2a47e9b
--- /dev/null
+++ b/core/res/res/drawable-xhdpi/ic_lockscreen_answer_focused.png
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/ic_lockscreen_answer_normal.png b/core/res/res/drawable-xhdpi/ic_lockscreen_answer_normal.png
new file mode 100644
index 0000000..f049dc9
--- /dev/null
+++ b/core/res/res/drawable-xhdpi/ic_lockscreen_answer_normal.png
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/ic_lockscreen_chevron_down.png b/core/res/res/drawable-xhdpi/ic_lockscreen_chevron_down.png
new file mode 100644
index 0000000..c655d93
--- /dev/null
+++ b/core/res/res/drawable-xhdpi/ic_lockscreen_chevron_down.png
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/ic_lockscreen_chevron_left.png b/core/res/res/drawable-xhdpi/ic_lockscreen_chevron_left.png
new file mode 100644
index 0000000..75173cb
--- /dev/null
+++ b/core/res/res/drawable-xhdpi/ic_lockscreen_chevron_left.png
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/ic_lockscreen_chevron_right.png b/core/res/res/drawable-xhdpi/ic_lockscreen_chevron_right.png
new file mode 100644
index 0000000..9f6da72
--- /dev/null
+++ b/core/res/res/drawable-xhdpi/ic_lockscreen_chevron_right.png
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/ic_lockscreen_chevron_up.png b/core/res/res/drawable-xhdpi/ic_lockscreen_chevron_up.png
new file mode 100644
index 0000000..53794fd
--- /dev/null
+++ b/core/res/res/drawable-xhdpi/ic_lockscreen_chevron_up.png
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/ic_lockscreen_decline_activated.png b/core/res/res/drawable-xhdpi/ic_lockscreen_decline_activated.png
new file mode 100644
index 0000000..4244ca0
--- /dev/null
+++ b/core/res/res/drawable-xhdpi/ic_lockscreen_decline_activated.png
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/ic_lockscreen_decline_focused.png b/core/res/res/drawable-xhdpi/ic_lockscreen_decline_focused.png
new file mode 100644
index 0000000..a98a379
--- /dev/null
+++ b/core/res/res/drawable-xhdpi/ic_lockscreen_decline_focused.png
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/ic_lockscreen_decline_normal.png b/core/res/res/drawable-xhdpi/ic_lockscreen_decline_normal.png
new file mode 100644
index 0000000..fa2a0f4
--- /dev/null
+++ b/core/res/res/drawable-xhdpi/ic_lockscreen_decline_normal.png
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/ic_lockscreen_emergencycall_normal.png b/core/res/res/drawable-xhdpi/ic_lockscreen_emergencycall_normal.png
new file mode 100644
index 0000000..a61f7a5
--- /dev/null
+++ b/core/res/res/drawable-xhdpi/ic_lockscreen_emergencycall_normal.png
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/ic_lockscreen_emergencycall_pressed.png b/core/res/res/drawable-xhdpi/ic_lockscreen_emergencycall_pressed.png
new file mode 100644
index 0000000..dd5e481
--- /dev/null
+++ b/core/res/res/drawable-xhdpi/ic_lockscreen_emergencycall_pressed.png
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/ic_lockscreen_forgotpassword_normal.png b/core/res/res/drawable-xhdpi/ic_lockscreen_forgotpassword_normal.png
new file mode 100644
index 0000000..e4172ce
--- /dev/null
+++ b/core/res/res/drawable-xhdpi/ic_lockscreen_forgotpassword_normal.png
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/ic_lockscreen_forgotpassword_pressed.png b/core/res/res/drawable-xhdpi/ic_lockscreen_forgotpassword_pressed.png
new file mode 100644
index 0000000..e2c76217
--- /dev/null
+++ b/core/res/res/drawable-xhdpi/ic_lockscreen_forgotpassword_pressed.png
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/ic_lockscreen_lock_normal.png b/core/res/res/drawable-xhdpi/ic_lockscreen_lock_normal.png
new file mode 100644
index 0000000..c44a330
--- /dev/null
+++ b/core/res/res/drawable-xhdpi/ic_lockscreen_lock_normal.png
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/ic_lockscreen_lock_pressed.png b/core/res/res/drawable-xhdpi/ic_lockscreen_lock_pressed.png
new file mode 100644
index 0000000..2264dc3
--- /dev/null
+++ b/core/res/res/drawable-xhdpi/ic_lockscreen_lock_pressed.png
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/ic_lockscreen_outerring.png b/core/res/res/drawable-xhdpi/ic_lockscreen_outerring.png
new file mode 100644
index 0000000..0b4b260
--- /dev/null
+++ b/core/res/res/drawable-xhdpi/ic_lockscreen_outerring.png
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/ic_lockscreen_silent_activated.png b/core/res/res/drawable-xhdpi/ic_lockscreen_silent_activated.png
new file mode 100644
index 0000000..fd81211
--- /dev/null
+++ b/core/res/res/drawable-xhdpi/ic_lockscreen_silent_activated.png
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/ic_lockscreen_silent_focused.png b/core/res/res/drawable-xhdpi/ic_lockscreen_silent_focused.png
new file mode 100644
index 0000000..5a93472
--- /dev/null
+++ b/core/res/res/drawable-xhdpi/ic_lockscreen_silent_focused.png
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/ic_lockscreen_silent_normal.png b/core/res/res/drawable-xhdpi/ic_lockscreen_silent_normal.png
new file mode 100644
index 0000000..73f6a2e
--- /dev/null
+++ b/core/res/res/drawable-xhdpi/ic_lockscreen_silent_normal.png
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/ic_lockscreen_soundon_activated.png b/core/res/res/drawable-xhdpi/ic_lockscreen_soundon_activated.png
new file mode 100644
index 0000000..9edc70b
--- /dev/null
+++ b/core/res/res/drawable-xhdpi/ic_lockscreen_soundon_activated.png
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/ic_lockscreen_soundon_focused.png b/core/res/res/drawable-xhdpi/ic_lockscreen_soundon_focused.png
new file mode 100644
index 0000000..0485af0
--- /dev/null
+++ b/core/res/res/drawable-xhdpi/ic_lockscreen_soundon_focused.png
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/ic_lockscreen_soundon_normal.png b/core/res/res/drawable-xhdpi/ic_lockscreen_soundon_normal.png
new file mode 100644
index 0000000..6af5375
--- /dev/null
+++ b/core/res/res/drawable-xhdpi/ic_lockscreen_soundon_normal.png
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/ic_lockscreen_text_activated.png b/core/res/res/drawable-xhdpi/ic_lockscreen_text_activated.png
new file mode 100644
index 0000000..29c4572
--- /dev/null
+++ b/core/res/res/drawable-xhdpi/ic_lockscreen_text_activated.png
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/ic_lockscreen_text_focusde.png b/core/res/res/drawable-xhdpi/ic_lockscreen_text_focusde.png
new file mode 100644
index 0000000..42c8ad2
--- /dev/null
+++ b/core/res/res/drawable-xhdpi/ic_lockscreen_text_focusde.png
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/ic_lockscreen_text_normal.png b/core/res/res/drawable-xhdpi/ic_lockscreen_text_normal.png
new file mode 100644
index 0000000..ff65f20
--- /dev/null
+++ b/core/res/res/drawable-xhdpi/ic_lockscreen_text_normal.png
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/ic_lockscreen_unlock_activated.png b/core/res/res/drawable-xhdpi/ic_lockscreen_unlock_activated.png
new file mode 100644
index 0000000..fa0be96
--- /dev/null
+++ b/core/res/res/drawable-xhdpi/ic_lockscreen_unlock_activated.png
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/ic_lockscreen_unlock_focused.png b/core/res/res/drawable-xhdpi/ic_lockscreen_unlock_focused.png
new file mode 100644
index 0000000..d067ab8
--- /dev/null
+++ b/core/res/res/drawable-xhdpi/ic_lockscreen_unlock_focused.png
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/ic_lockscreen_unlock_normal.png b/core/res/res/drawable-xhdpi/ic_lockscreen_unlock_normal.png
new file mode 100644
index 0000000..1a53c63
--- /dev/null
+++ b/core/res/res/drawable-xhdpi/ic_lockscreen_unlock_normal.png
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/indicator_code_lock_point_area_default_holo.png b/core/res/res/drawable-xhdpi/indicator_code_lock_point_area_default_holo.png
new file mode 100644
index 0000000..d98a126
--- /dev/null
+++ b/core/res/res/drawable-xhdpi/indicator_code_lock_point_area_default_holo.png
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/indicator_code_lock_point_area_green_holo.png b/core/res/res/drawable-xhdpi/indicator_code_lock_point_area_green_holo.png
new file mode 100644
index 0000000..4491f02
--- /dev/null
+++ b/core/res/res/drawable-xhdpi/indicator_code_lock_point_area_green_holo.png
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/indicator_code_lock_point_area_red_holo.png b/core/res/res/drawable-xhdpi/indicator_code_lock_point_area_red_holo.png
new file mode 100644
index 0000000..6e91fbc
--- /dev/null
+++ b/core/res/res/drawable-xhdpi/indicator_code_lock_point_area_red_holo.png
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/toast_frame.9.png b/core/res/res/drawable-xhdpi/toast_frame.9.png
index 9c0ff47..f7debee 100644
--- a/core/res/res/drawable-xhdpi/toast_frame.9.png
+++ b/core/res/res/drawable-xhdpi/toast_frame.9.png
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/toast_frame_holo.9.png b/core/res/res/drawable-xhdpi/toast_frame_holo.9.png
new file mode 100644
index 0000000..f7debee
--- /dev/null
+++ b/core/res/res/drawable-xhdpi/toast_frame_holo.9.png
Binary files differ
diff --git a/core/res/res/drawable-xlarge-hdpi/ic_lock_idle_alarm.png b/core/res/res/drawable-xlarge-hdpi/ic_lock_idle_alarm.png
new file mode 100644
index 0000000..29cd471
--- /dev/null
+++ b/core/res/res/drawable-xlarge-hdpi/ic_lock_idle_alarm.png
Binary files differ
diff --git a/core/res/res/drawable-xlarge-hdpi/ic_lock_idle_charging.png b/core/res/res/drawable-xlarge-hdpi/ic_lock_idle_charging.png
new file mode 100644
index 0000000..211aa0b
--- /dev/null
+++ b/core/res/res/drawable-xlarge-hdpi/ic_lock_idle_charging.png
Binary files differ
diff --git a/core/res/res/drawable-xlarge-hdpi/ic_lock_idle_lock.png b/core/res/res/drawable-xlarge-hdpi/ic_lock_idle_lock.png
new file mode 100644
index 0000000..683ba22
--- /dev/null
+++ b/core/res/res/drawable-xlarge-hdpi/ic_lock_idle_lock.png
Binary files differ
diff --git a/core/res/res/drawable-xlarge-hdpi/ic_lock_idle_low_battery.png b/core/res/res/drawable-xlarge-hdpi/ic_lock_idle_low_battery.png
new file mode 100644
index 0000000..f4383f3
--- /dev/null
+++ b/core/res/res/drawable-xlarge-hdpi/ic_lock_idle_low_battery.png
Binary files differ
diff --git a/core/res/res/drawable-xlarge-mdpi/btn_code_lock_default.png b/core/res/res/drawable-xlarge-mdpi/btn_code_lock_default.png
new file mode 100644
index 0000000..45cc20d
--- /dev/null
+++ b/core/res/res/drawable-xlarge-mdpi/btn_code_lock_default.png
Binary files differ
diff --git a/core/res/res/drawable-xlarge-mdpi/btn_code_lock_touched.png b/core/res/res/drawable-xlarge-mdpi/btn_code_lock_touched.png
new file mode 100644
index 0000000..45cc20d
--- /dev/null
+++ b/core/res/res/drawable-xlarge-mdpi/btn_code_lock_touched.png
Binary files differ
diff --git a/core/res/res/drawable-xlarge-mdpi/ic_lock_idle_alarm.png b/core/res/res/drawable-xlarge-mdpi/ic_lock_idle_alarm.png
new file mode 100644
index 0000000..97ac023
--- /dev/null
+++ b/core/res/res/drawable-xlarge-mdpi/ic_lock_idle_alarm.png
Binary files differ
diff --git a/core/res/res/drawable-xlarge-mdpi/ic_lock_idle_charging.png b/core/res/res/drawable-xlarge-mdpi/ic_lock_idle_charging.png
new file mode 100644
index 0000000..4210db2
--- /dev/null
+++ b/core/res/res/drawable-xlarge-mdpi/ic_lock_idle_charging.png
Binary files differ
diff --git a/core/res/res/drawable-xlarge-mdpi/ic_lock_idle_lock.png b/core/res/res/drawable-xlarge-mdpi/ic_lock_idle_lock.png
new file mode 100644
index 0000000..1060f5a
--- /dev/null
+++ b/core/res/res/drawable-xlarge-mdpi/ic_lock_idle_lock.png
Binary files differ
diff --git a/core/res/res/drawable-xlarge-mdpi/ic_lock_idle_low_battery.png b/core/res/res/drawable-xlarge-mdpi/ic_lock_idle_low_battery.png
new file mode 100644
index 0000000..72e4afa
--- /dev/null
+++ b/core/res/res/drawable-xlarge-mdpi/ic_lock_idle_low_battery.png
Binary files differ
diff --git a/core/res/res/drawable-xlarge-mdpi/indicator_code_lock_drag_direction_green_up.png b/core/res/res/drawable-xlarge-mdpi/indicator_code_lock_drag_direction_green_up.png
new file mode 100644
index 0000000..0bc86c3
--- /dev/null
+++ b/core/res/res/drawable-xlarge-mdpi/indicator_code_lock_drag_direction_green_up.png
Binary files differ
diff --git a/core/res/res/drawable-xlarge-mdpi/indicator_code_lock_drag_direction_red_up.png b/core/res/res/drawable-xlarge-mdpi/indicator_code_lock_drag_direction_red_up.png
new file mode 100644
index 0000000..2ab4547
--- /dev/null
+++ b/core/res/res/drawable-xlarge-mdpi/indicator_code_lock_drag_direction_red_up.png
Binary files differ
diff --git a/core/res/res/drawable-xlarge-mdpi/indicator_code_lock_point_area_default.png b/core/res/res/drawable-xlarge-mdpi/indicator_code_lock_point_area_default.png
new file mode 100644
index 0000000..fe72d00
--- /dev/null
+++ b/core/res/res/drawable-xlarge-mdpi/indicator_code_lock_point_area_default.png
Binary files differ
diff --git a/core/res/res/drawable-xlarge-mdpi/indicator_code_lock_point_area_green.png b/core/res/res/drawable-xlarge-mdpi/indicator_code_lock_point_area_green.png
new file mode 100644
index 0000000..be666c6
--- /dev/null
+++ b/core/res/res/drawable-xlarge-mdpi/indicator_code_lock_point_area_green.png
Binary files differ
diff --git a/core/res/res/drawable-xlarge-mdpi/indicator_code_lock_point_area_red.png b/core/res/res/drawable-xlarge-mdpi/indicator_code_lock_point_area_red.png
new file mode 100644
index 0000000..9627197
--- /dev/null
+++ b/core/res/res/drawable-xlarge-mdpi/indicator_code_lock_point_area_red.png
Binary files differ
diff --git a/core/res/res/drawable-xlarge-xhdpi/indicator_code_lock_point_area_default.png b/core/res/res/drawable-xlarge-xhdpi/indicator_code_lock_point_area_default.png
new file mode 100644
index 0000000..6662eb1
--- /dev/null
+++ b/core/res/res/drawable-xlarge-xhdpi/indicator_code_lock_point_area_default.png
Binary files differ
diff --git a/core/res/res/drawable-xlarge-xhdpi/indicator_code_lock_point_area_green.png b/core/res/res/drawable-xlarge-xhdpi/indicator_code_lock_point_area_green.png
new file mode 100644
index 0000000..dce220a
--- /dev/null
+++ b/core/res/res/drawable-xlarge-xhdpi/indicator_code_lock_point_area_green.png
Binary files differ
diff --git a/core/res/res/drawable-xlarge-xhdpi/indicator_code_lock_point_area_red.png b/core/res/res/drawable-xlarge-xhdpi/indicator_code_lock_point_area_red.png
new file mode 100644
index 0000000..746a3ea
--- /dev/null
+++ b/core/res/res/drawable-xlarge-xhdpi/indicator_code_lock_point_area_red.png
Binary files differ
diff --git a/core/res/res/drawable/ic_lockscreen_answer.xml b/core/res/res/drawable/ic_lockscreen_answer.xml
new file mode 100644
index 0000000..b42fc2a
--- /dev/null
+++ b/core/res/res/drawable/ic_lockscreen_answer.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <item
+        android:state_enabled="true"
+        android:state_active="false"
+        android:state_focused="false"
+        android:drawable="@drawable/ic_lockscreen_answer_normal" />
+
+    <item
+        android:state_enabled="true"
+        android:state_active="true"
+        android:state_focused="false"
+        android:drawable="@drawable/ic_lockscreen_answer_active" />
+
+</selector>
diff --git a/core/res/res/drawable/ic_lockscreen_decline.xml b/core/res/res/drawable/ic_lockscreen_decline.xml
new file mode 100644
index 0000000..65128a1
--- /dev/null
+++ b/core/res/res/drawable/ic_lockscreen_decline.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <item
+        android:state_enabled="true"
+        android:state_active="false"
+        android:state_focused="false"
+        android:drawable="@drawable/ic_lockscreen_decline_normal" />
+
+    <item
+        android:state_enabled="true"
+        android:state_active="true"
+        android:state_focused="false"
+        android:drawable="@drawable/ic_lockscreen_decline_activated" />
+
+</selector>
diff --git a/core/res/res/drawable/ic_lockscreen_handle.xml b/core/res/res/drawable/ic_lockscreen_handle.xml
new file mode 100644
index 0000000..e7b4a6e
--- /dev/null
+++ b/core/res/res/drawable/ic_lockscreen_handle.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <item
+        android:state_enabled="true"
+        android:state_active="false"
+        android:state_focused="false"
+        android:drawable="@drawable/ic_lockscreen_handle_normal" />
+
+    <item
+        android:state_enabled="true"
+        android:state_active="true"
+        android:state_focused="false"
+        android:drawable="@drawable/ic_lockscreen_handle_pressed" />
+
+</selector>
diff --git a/core/res/res/drawable/ic_lockscreen_send_sms.xml b/core/res/res/drawable/ic_lockscreen_send_sms.xml
new file mode 100644
index 0000000..2503a5c
--- /dev/null
+++ b/core/res/res/drawable/ic_lockscreen_send_sms.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <item
+        android:state_enabled="true"
+        android:state_active="false"
+        android:state_focused="false"
+        android:drawable="@drawable/ic_lockscreen_text_normal" />
+
+    <item
+        android:state_enabled="true"
+        android:state_active="true"
+        android:state_focused="false"
+        android:drawable="@drawable/ic_lockscreen_text_activated" />
+
+</selector>
diff --git a/core/res/res/drawable/ic_lockscreen_silent.xml b/core/res/res/drawable/ic_lockscreen_silent.xml
new file mode 100644
index 0000000..2521eb7
--- /dev/null
+++ b/core/res/res/drawable/ic_lockscreen_silent.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <item
+        android:state_enabled="true"
+        android:state_active="false"
+        android:state_focused="false"
+        android:drawable="@drawable/ic_lockscreen_silent_normal" />
+
+    <item
+        android:state_enabled="true"
+        android:state_active="true"
+        android:state_focused="false"
+        android:drawable="@drawable/ic_lockscreen_silent_activated" />
+
+</selector>
diff --git a/core/res/res/drawable/ic_lockscreen_soundon.xml b/core/res/res/drawable/ic_lockscreen_soundon.xml
new file mode 100644
index 0000000..2b306a5
--- /dev/null
+++ b/core/res/res/drawable/ic_lockscreen_soundon.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <item
+        android:state_enabled="true"
+        android:state_active="false"
+        android:state_focused="false"
+        android:drawable="@drawable/ic_lockscreen_soundon_normal" />
+
+    <item
+        android:state_enabled="true"
+        android:state_active="true"
+        android:state_focused="false"
+        android:drawable="@drawable/ic_lockscreen_soundon_activated" />
+
+</selector>
diff --git a/core/res/res/drawable/ic_lockscreen_unlock.xml b/core/res/res/drawable/ic_lockscreen_unlock.xml
new file mode 100644
index 0000000..0a49c18
--- /dev/null
+++ b/core/res/res/drawable/ic_lockscreen_unlock.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <item
+        android:state_enabled="true"
+        android:state_active="false"
+        android:state_focused="false"
+        android:drawable="@drawable/ic_lockscreen_unlock_normal" />
+
+    <item
+        android:state_enabled="true"
+        android:state_active="true"
+        android:state_focused="false"
+        android:drawable="@drawable/ic_lockscreen_unlock_activated" />
+
+</selector>
diff --git a/core/res/res/drawable/lockscreen_emergency_button.xml b/core/res/res/drawable/lockscreen_emergency_button.xml
new file mode 100644
index 0000000..4ec6a96
--- /dev/null
+++ b/core/res/res/drawable/lockscreen_emergency_button.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+    <item android:state_enabled="true" android:drawable="@drawable/ic_lockscreen_emergencycall_normal" />
+    <item android:state_pressed="true" android:drawable="@drawable/ic_lockscreen_emergencycall_pressed" />
+    <item android:drawable="@drawable/ic_lockscreen_emergencycall_normal" />
+</selector>
diff --git a/core/res/res/drawable/lockscreen_forgot_password_button.xml b/core/res/res/drawable/lockscreen_forgot_password_button.xml
new file mode 100644
index 0000000..6c081bf
--- /dev/null
+++ b/core/res/res/drawable/lockscreen_forgot_password_button.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+    <item android:state_enabled="true" android:drawable="@drawable/ic_lockscreen_forgotpassword_normal" />
+    <item android:state_pressed="true" android:drawable="@drawable/ic_lockscreen_forgotpassword_pressed" />
+    <item android:drawable="@drawable/ic_lockscreen_forgotpassword_normal" />
+</selector>
diff --git a/core/res/res/layout-sw600dp/keyguard_screen_status_land.xml b/core/res/res/layout-sw600dp/keyguard_screen_status_land.xml
index 0a485e2..302ee01 100644
--- a/core/res/res/layout-sw600dp/keyguard_screen_status_land.xml
+++ b/core/res/res/layout-sw600dp/keyguard_screen_status_land.xml
@@ -56,7 +56,7 @@
             android:layout_height="wrap_content"
             android:singleLine="true"
             android:ellipsize="none"
-            android:textSize="98sp"
+            android:textSize="@dimen/keyguard_pattern_unlock_clock_font_size"
             android:textAppearance="?android:attr/textAppearanceMedium"
             android:textColor="@color/lockscreen_clock_background"
             android:layout_marginBottom="6dip"
@@ -67,7 +67,7 @@
             android:layout_height="wrap_content"
             android:singleLine="true"
             android:ellipsize="none"
-            android:textSize="98sp"
+            android:textSize="@dimen/keyguard_pattern_unlock_clock_font_size"
             android:textAppearance="?android:attr/textAppearanceMedium"
             android:textColor="@color/lockscreen_clock_foreground"
             android:layout_alignLeft="@id/timeDisplayBackground"
diff --git a/core/res/res/layout-sw600dp/keyguard_screen_status_port.xml b/core/res/res/layout-sw600dp/keyguard_screen_status_port.xml
index 346b21e..53fe902 100644
--- a/core/res/res/layout-sw600dp/keyguard_screen_status_port.xml
+++ b/core/res/res/layout-sw600dp/keyguard_screen_status_port.xml
@@ -55,7 +55,7 @@
             android:layout_height="wrap_content"
             android:singleLine="true"
             android:ellipsize="none"
-            android:textSize="98sp"
+            android:textSize="@dimen/keyguard_pattern_unlock_clock_font_size"
             android:textAppearance="?android:attr/textAppearanceMedium"
             android:textColor="@color/lockscreen_clock_background"
             android:layout_marginBottom="6dip"
@@ -66,7 +66,7 @@
             android:layout_height="wrap_content"
             android:singleLine="true"
             android:ellipsize="none"
-            android:textSize="98sp"
+            android:textSize="@dimen/keyguard_pattern_unlock_clock_font_size"
             android:textAppearance="?android:attr/textAppearanceMedium"
             android:textColor="@color/lockscreen_clock_foreground"
             android:layout_marginBottom="6dip"
diff --git a/core/res/res/layout-sw600dp/keyguard_screen_tab_unlock.xml b/core/res/res/layout-sw600dp/keyguard_screen_tab_unlock.xml
index c9c1692..543747f 100644
--- a/core/res/res/layout-sw600dp/keyguard_screen_tab_unlock.xml
+++ b/core/res/res/layout-sw600dp/keyguard_screen_tab_unlock.xml
@@ -59,7 +59,7 @@
             />
 
         <com.android.internal.widget.WaveView
-            android:id="@+id/wave_view"
+            android:id="@+id/unlock_widget"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_gravity="center"
diff --git a/core/res/res/layout-sw600dp/keyguard_screen_tab_unlock_land.xml b/core/res/res/layout-sw600dp/keyguard_screen_tab_unlock_land.xml
index fbb9983..37bb522 100644
--- a/core/res/res/layout-sw600dp/keyguard_screen_tab_unlock_land.xml
+++ b/core/res/res/layout-sw600dp/keyguard_screen_tab_unlock_land.xml
@@ -44,31 +44,22 @@
     </RelativeLayout>
 
     <!-- right side -->
-    <LinearLayout
-            android:layout_height="match_parent"
-            android:layout_weight="1"
-            android:layout_width="0dip"
-            android:orientation="horizontal"
-            android:gravity="center_horizontal"
-                >
-        <TextView
-                android:id="@+id/screenLocked"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_below="@id/status2"
-                android:textAppearance="?android:attr/textAppearanceMedium"
-                android:gravity="center"
-                android:layout_marginTop="12dip"
-                android:drawablePadding="4dip"
-                />
+    <RelativeLayout
+        android:layout_height="match_parent"
+        android:layout_weight="1"
+        android:layout_width="0dip"
+        android:gravity="center_horizontal|center_vertical">
 
-        <com.android.internal.widget.WaveView
-            android:id="@+id/wave_view"
+        <TextView
+            android:id="@+id/screenLocked"
             android:layout_width="wrap_content"
-            android:layout_height="match_parent"
-            android:layout_marginRight="0dip"
-            android:layout_weight="1.0"
-            />
+            android:layout_height="wrap_content"
+            android:textAppearance="?android:attr/textAppearanceMedium"
+            android:gravity="center"
+            android:layout_marginTop="12dip"
+            android:layout_alignParentLeft="true"
+            android:layout_alignParentTop="true"
+            android:drawablePadding="4dip"/>
 
         <!-- "emergency calls only" shown when sim is missing or PUKd -->
         <TextView
@@ -76,24 +67,35 @@
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_alignParentTop="true"
-            android:layout_marginTop="20dip"
+            android:layout_alignParentRight="true"
+            android:layout_marginTop="12dip"
             android:text="@string/emergency_calls_only"
-            android:textAppearance="?android:attr/textAppearanceSmall"
-            android:textColor="@color/white"
-               />
+            android:textAppearance="?android:attr/textAppearanceMedium"
+            android:textColor="@color/white"/>
 
-        <!-- emergency call button shown when sim is PUKd and tab_selector is
-             hidden -->
+
+        <com.android.internal.widget.WaveView
+            android:id="@+id/unlock_widget"
+            android:layout_width="wrap_content"
+            android:layout_height="match_parent"
+            android:layout_gravity="center_vertical|center_horizontal"
+            android:layout_marginRight="0dip"
+            android:layout_weight="1.0"/>
+
+
+        <!-- emergency call button shown when sim is PUKd and tab_selector is hidden -->
         <Button
             android:id="@+id/emergencyCallButton"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
+            android:layout_marginRight="80dip"
+            android:layout_marginBottom="80dip"
+            android:layout_alignParentRight="true"
+            android:layout_alignParentBottom="true"
             android:drawableLeft="@drawable/ic_emergency"
             style="@style/Widget.Button.Transparent"
-            android:drawablePadding="8dip"
-            android:layout_marginRight="80dip"
-            android:visibility="gone"
-            />
+            android:drawablePadding="8dip"/>
 
-    </LinearLayout>
+    </RelativeLayout>>
+
 </LinearLayout>
diff --git a/core/res/res/layout-sw600dp/keyguard_screen_unlock_landscape.xml b/core/res/res/layout-sw600dp/keyguard_screen_unlock_landscape.xml
index e3d7a3f..7ac41b5 100644
--- a/core/res/res/layout-sw600dp/keyguard_screen_unlock_landscape.xml
+++ b/core/res/res/layout-sw600dp/keyguard_screen_unlock_landscape.xml
@@ -56,10 +56,8 @@
             android:layout_gravity="center_vertical"
         />
 
-        <!-- footer -->
-
-        <!-- option 1: a single emergency call button -->
-        <RelativeLayout android:id="@+id/footerNormal"
+        <!-- Emergency and forgot pattern buttons. -->
+        <LinearLayout
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_below="@id/lockPattern"
@@ -68,43 +66,27 @@
             android:layout_marginTop="28dip"
             android:layout_marginLeft="28dip"
             android:layout_marginRight="28dip"
-            >
-            <Button android:id="@+id/emergencyCallAlone"
+            android:orientation="horizontal">
+
+            <Button android:id="@+id/forgotPatternButton"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
-                android:text="@string/lockscreen_emergency_call"
+                android:layout_gravity="center"
                 style="@style/Widget.Button.Transparent"
                 android:drawableLeft="@drawable/ic_emergency"
                 android:drawablePadding="8dip"
+                android:text="@string/lockscreen_forgot_pattern_button_text"
                 android:visibility="gone"
-                />
-        </RelativeLayout>
-
-        <!-- option 2: an emergency call button, and a 'forgot pattern?' button -->
-        <LinearLayout android:id="@+id/footerForgotPattern"
-            android:orientation="vertical"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:layout_below="@id/footerNormal"
-            android:layout_alignLeft="@id/lockPattern"
-            android:layout_alignRight="@id/lockPattern"
-            android:layout_marginTop="28dip"
-            android:layout_marginLeft="28dip"
-            android:layout_marginRight="28dip">
-
-            <Button android:id="@+id/forgotPattern"
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                style="@style/Widget.Button.Transparent"
             />
 
-            <Button android:id="@+id/emergencyCallTogether"
-                android:layout_width="match_parent"
+            <Button android:id="@+id/emergencyCallButton"
+                android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
-                android:text="@string/lockscreen_emergency_call"
+                android:layout_gravity="center"
                 style="@style/Widget.Button.Transparent"
                 android:drawableLeft="@drawable/ic_emergency"
                 android:drawablePadding="8dip"
+                android:text="@string/lockscreen_emergency_call"
                 android:visibility="gone"
             />
 
diff --git a/core/res/res/layout-sw600dp/keyguard_screen_unlock_portrait.xml b/core/res/res/layout-sw600dp/keyguard_screen_unlock_portrait.xml
index f35897e..1f6058f 100644
--- a/core/res/res/layout-sw600dp/keyguard_screen_unlock_portrait.xml
+++ b/core/res/res/layout-sw600dp/keyguard_screen_unlock_portrait.xml
@@ -23,7 +23,7 @@
     android:layout_width="match_parent"
     android:layout_height="match_parent">
 
-    <!-- top: status -->
+    <!-- top: status and emergency/forgot pattern buttons -->
     <LinearLayout
         android:layout_height="0dip"
         android:layout_weight="1"
@@ -36,53 +36,37 @@
             android:layout_marginTop="134dip"
             android:layout_marginLeft="266dip"/>
 
-        <!-- footer -->
-        <FrameLayout
+        <!-- Emergency and forgot pattern buttons. -->
+        <LinearLayout
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:layout_marginLeft="140dip"
-            >
+            android:orientation="horizontal"
+            android:gravity="center_horizontal">
 
-            <!-- option 1: a single emergency call button -->
-            <RelativeLayout android:id="@+id/footerNormal"
-                android:layout_width="match_parent"
+            <Button android:id="@+id/forgotPatternButton"
+                android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
-                android:gravity="left"
-                >
-                <Button android:id="@+id/emergencyCallAlone"
-                    android:layout_width="wrap_content"
-                    android:layout_height="wrap_content"
-                    android:text="@string/lockscreen_emergency_call"
-                    style="@style/Widget.Button.Transparent"
-                    android:drawableLeft="@drawable/ic_emergency"
-                    android:drawablePadding="8dip"
-                    android:visibility="gone"
-                    />
-            </RelativeLayout>
+                android:layout_gravity="center"
+                style="@style/Widget.Button.Transparent"
+                android:drawableLeft="@drawable/ic_emergency"
+                android:drawablePadding="8dip"
+                android:text="@string/lockscreen_forgot_pattern_button_text"
+                android:visibility="gone"
+            />
 
-            <!-- option 2: an emergency call button, and a 'forgot pattern?' button -->
-            <LinearLayout android:id="@+id/footerForgotPattern"
-                android:orientation="vertical"
-                android:layout_width="match_parent"
+            <Button android:id="@+id/emergencyCallButton"
+                android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
-                android:gravity="left"
-                >
-                <Button android:id="@+id/forgotPattern"
-                    android:layout_width="match_parent"
-                    android:layout_height="wrap_content"
-                    style="@style/Widget.Button.Transparent"
-                    />
-                <Button android:id="@+id/emergencyCallTogether"
-                    android:layout_width="match_parent"
-                    android:layout_height="wrap_content"
-                    android:text="@string/lockscreen_emergency_call"
-                    style="@style/Widget.Button.Transparent"
-                    android:drawableLeft="@drawable/ic_emergency"
-                    android:drawablePadding="8dip"
-                    android:visibility="gone"
-                    />
-            </LinearLayout>
-        </FrameLayout>
+                android:layout_gravity="center"
+                style="@style/Widget.Button.Transparent"
+                android:drawableLeft="@drawable/ic_emergency"
+                android:drawablePadding="8dip"
+                android:text="@string/lockscreen_emergency_call"
+                android:visibility="gone"
+            />
+
+        </LinearLayout>
+
     </LinearLayout>
 
     <!-- right side: lock pattern -->
diff --git a/core/res/res/layout-xlarge/status_bar_latest_event_ticker.xml b/core/res/res/layout-sw600dp/status_bar_latest_event_ticker.xml
similarity index 100%
rename from core/res/res/layout-xlarge/status_bar_latest_event_ticker.xml
rename to core/res/res/layout-sw600dp/status_bar_latest_event_ticker.xml
diff --git a/core/res/res/layout-xlarge/status_bar_latest_event_ticker_large_icon.xml b/core/res/res/layout-sw600dp/status_bar_latest_event_ticker_large_icon.xml
similarity index 100%
rename from core/res/res/layout-xlarge/status_bar_latest_event_ticker_large_icon.xml
rename to core/res/res/layout-sw600dp/status_bar_latest_event_ticker_large_icon.xml
diff --git a/core/res/res/layout/action_bar_title_item.xml b/core/res/res/layout/action_bar_title_item.xml
index d8b729d..e803b26 100644
--- a/core/res/res/layout/action_bar_title_item.xml
+++ b/core/res/res/layout/action_bar_title_item.xml
@@ -17,17 +17,32 @@
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
-              android:orientation="vertical"
-              android:paddingRight="32dip" >
-    <TextView android:id="@+id/action_bar_title"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:singleLine="true"
-        android:ellipsize="end" />
-    <TextView android:id="@+id/action_bar_subtitle"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:singleLine="true"
-        android:ellipsize="end"
-        android:visibility="gone" />
+              android:orientation="horizontal"
+              android:paddingRight="16dip"
+              android:background="?android:attr/selectableItemBackground"
+              android:enabled="false">
+
+    <ImageView android:id="@android:id/up"
+               android:src="?android:attr/homeAsUpIndicator"
+               android:layout_gravity="center_vertical|left"
+               android:visibility="gone"
+               android:layout_width="wrap_content"
+               android:layout_height="wrap_content" />
+
+    <LinearLayout android:layout_width="wrap_content"
+                  android:layout_height="wrap_content"
+                  android:layout_gravity="center_vertical|left"
+                  android:orientation="vertical">
+        <TextView android:id="@+id/action_bar_title"
+                  android:layout_width="wrap_content"
+                  android:layout_height="wrap_content"
+                  android:singleLine="true"
+                  android:ellipsize="end" />
+        <TextView android:id="@+id/action_bar_subtitle"
+                  android:layout_width="wrap_content"
+                  android:layout_height="wrap_content"
+                  android:singleLine="true"
+                  android:ellipsize="end"
+                  android:visibility="gone" />
+    </LinearLayout>
 </LinearLayout>
diff --git a/core/res/res/layout/action_menu_item_layout.xml b/core/res/res/layout/action_menu_item_layout.xml
index 5e828fa..4206dcb 100644
--- a/core/res/res/layout/action_menu_item_layout.xml
+++ b/core/res/res/layout/action_menu_item_layout.xml
@@ -19,19 +19,20 @@
     android:layout_height="wrap_content"
     android:layout_gravity="center"
     android:addStatesFromChildren="true"
-    android:background="?attr/selectableItemBackground"
     android:gravity="center"
+    android:focusable="true"
     android:paddingLeft="12dip"
     android:paddingRight="12dip"
-    android:minWidth="64dip"
-    android:minHeight="?attr/actionBarSize"
-    android:focusable="true">
+    style="?android:attr/actionButtonStyle">
     <ImageButton android:id="@+id/imageButton"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_gravity="center"
                  android:visibility="gone"
-                 android:padding="@dimen/action_bar_icon_vertical_padding"
+                 android:paddingTop="@dimen/action_bar_icon_vertical_padding"
+                 android:paddingBottom="@dimen/action_bar_icon_vertical_padding"
+                 android:paddingLeft="4dip"
+                 android:paddingRight="4dip"
                  android:scaleType="fitCenter"
                  android:adjustViewBounds="true"
                  android:background="@null"
@@ -45,6 +46,9 @@
             style="?attr/buttonStyleSmall"
             android:textColor="?attr/actionMenuTextColor"
             android:background="@null"
-            android:padding="4dip"
+            android:paddingTop="4dip"
+            android:paddingBottom="4dip"
+            android:paddingLeft="4dip"
+            android:paddingRight="4dip"
             android:focusable="false" />
 </com.android.internal.view.menu.ActionMenuItemView>
diff --git a/core/res/res/layout/alert_dialog_holo.xml b/core/res/res/layout/alert_dialog_holo.xml
index 8ee91ca..2185467 100644
--- a/core/res/res/layout/alert_dialog_holo.xml
+++ b/core/res/res/layout/alert_dialog_holo.xml
@@ -32,12 +32,10 @@
         android:orientation="vertical">
         <ImageView android:id="@+id/titleDividerTop"
             android:layout_width="match_parent"
-            android:layout_height="4dip"
+            android:layout_height="1dip"
             android:visibility="gone"
             android:scaleType="fitXY"
             android:gravity="fill_horizontal"
-            android:paddingLeft="16dip"
-            android:paddingRight="16dip"
             android:src="@android:drawable/divider_strong_holo" />
         <LinearLayout android:id="@+id/title_template"
             android:layout_width="match_parent"
@@ -45,15 +43,16 @@
             android:orientation="horizontal"
             android:gravity="center_vertical|left"
             android:minHeight="@dimen/alert_dialog_title_height"
-            android:layout_marginLeft="32dip"
-            android:layout_marginRight="32dip">
+            android:layout_marginLeft="16dip"
+            android:layout_marginRight="16dip">
             <ImageView android:id="@+id/icon"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
-                android:paddingRight="16dip"
+                android:paddingRight="8dip"
                 android:src="@null" />
             <com.android.internal.widget.DialogTitle android:id="@+id/alertTitle"
-                style="?android:attr/textAppearanceMedium"
+                style="?android:attr/textAppearanceLarge"
+                android:textColor="@android:color/holo_blue"
                 android:singleLine="true"
                 android:ellipsize="end"
                 android:layout_width="match_parent"
@@ -61,12 +60,10 @@
         </LinearLayout>
         <ImageView android:id="@+id/titleDivider"
             android:layout_width="match_parent"
-            android:layout_height="4dip"
+            android:layout_height="1dip"
             android:visibility="gone"
             android:scaleType="fitXY"
             android:gravity="fill_horizontal"
-            android:paddingLeft="16dip"
-            android:paddingRight="16dip"
             android:src="@android:drawable/divider_strong_holo" />
         <!-- If the client uses a customTitle, it will be added here. -->
     </LinearLayout>
@@ -79,17 +76,15 @@
         <ScrollView android:id="@+id/scrollView"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:layout_marginLeft="16dip"
-            android:layout_marginRight="16dip"
-            android:paddingTop="32dip"
-            android:paddingBottom="32dip"
             android:clipToPadding="false">
             <TextView android:id="@+id/message"
                 style="?android:attr/textAppearanceMedium"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:paddingLeft="16dip"
-                android:paddingRight="16dip" />
+                android:paddingRight="16dip"
+                android:paddingTop="8dip"
+                android:paddingBottom="8dip"/>
         </ScrollView>
     </LinearLayout>
 
@@ -99,11 +94,7 @@
         android:layout_weight="1">
         <FrameLayout android:id="@+android:id/custom"
             android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:paddingTop="8dip"
-            android:paddingBottom="8dip"
-            android:paddingLeft="32dip"
-            android:paddingRight="32dip" />
+            android:layout_height="wrap_content" />
     </FrameLayout>
 
     <LinearLayout android:id="@+id/buttonPanel"
@@ -113,27 +104,21 @@
         android:orientation="vertical"
         android:divider="?android:attr/dividerHorizontal"
         android:showDividers="beginning"
-        android:dividerPadding="16dip">
+        android:dividerPadding="0dip">
         <LinearLayout
             style="?android:attr/buttonBarStyle"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:orientation="horizontal"
-            android:paddingLeft="2dip"
-            android:paddingRight="2dip"
+            android:layoutDirection="locale"
             android:measureWithLargestChild="true">
-            <LinearLayout android:id="@+id/leftSpacer"
-                android:layout_weight="0.25"
-                android:layout_width="0dip"
-                android:layout_height="wrap_content"
-                android:orientation="horizontal"
-                android:visibility="gone" />
-            <Button android:id="@+id/button1"
+            <Button android:id="@+id/button2"
                 android:layout_width="0dip"
                 android:layout_gravity="left"
                 android:layout_weight="1"
                 android:maxLines="2"
                 style="?android:attr/buttonBarButtonStyle"
+                android:textSize="14sp"
                 android:minHeight="@dimen/alert_dialog_button_bar_height"
                 android:layout_height="wrap_content" />
             <Button android:id="@+id/button3"
@@ -142,22 +127,18 @@
                 android:layout_weight="1"
                 android:maxLines="2"
                 style="?android:attr/buttonBarButtonStyle"
+                android:textSize="14sp"
                 android:minHeight="@dimen/alert_dialog_button_bar_height"
                 android:layout_height="wrap_content" />
-            <Button android:id="@+id/button2"
+            <Button android:id="@+id/button1"
                 android:layout_width="0dip"
                 android:layout_gravity="right"
                 android:layout_weight="1"
                 android:maxLines="2"
                 android:minHeight="@dimen/alert_dialog_button_bar_height"
                 style="?android:attr/buttonBarButtonStyle"
+                android:textSize="14sp"
                 android:layout_height="wrap_content" />
-            <LinearLayout android:id="@+id/rightSpacer"
-                android:layout_width="0dip"
-                android:layout_weight="0.25"
-                android:layout_height="wrap_content"
-                android:orientation="horizontal"
-                android:visibility="gone" />
         </LinearLayout>
      </LinearLayout>
 </LinearLayout>
diff --git a/core/res/res/layout/am_compat_mode_dialog.xml b/core/res/res/layout/am_compat_mode_dialog.xml
new file mode 100644
index 0000000..a8d39cf
--- /dev/null
+++ b/core/res/res/layout/am_compat_mode_dialog.xml
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+        android:layout_width="match_parent" android:layout_height="match_parent"
+        android:layout_marginLeft="40dp" android:layout_marginRight="40dp"
+        android:layout_marginTop="15dp" android:layout_marginBottom="15dp"
+        android:orientation="vertical">
+    <LinearLayout
+            android:layout_width="wrap_content" android:layout_height="wrap_content"
+            android:layout_gravity="center_horizontal"
+            android:orientation="horizontal" android:baselineAligned="true">
+        <TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
+                android:layout_marginLeft="10dp" android:layout_marginRight="10dp"
+                android:textColor="?android:attr/textColorPrimary"
+                android:textSize="18sp"
+                android:text="@string/screen_compat_mode_scale"
+                />
+        <Switch
+                android:id="@+id/compat_checkbox"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_gravity="center_vertical"
+                android:layout_marginRight="10dp"
+                />
+    </LinearLayout>
+
+    <View android:layout_width="wrap_content" android:layout_height="1dp"
+            android:layout_marginTop="10dp" android:layout_marginBottom="10dp"
+            android:background="@android:drawable/divider_horizontal_dark"
+            />
+
+    <CheckBox android:id="@+id/ask_checkbox"
+            android:layout_width="wrap_content" android:layout_height="wrap_content"
+            android:layout_gravity="center_horizontal"
+            android:text="@string/screen_compat_mode_show"
+            />
+    <TextView
+        android:id="@+id/reask_hint"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:textAppearance="?android:attr/textAppearanceSmall"
+        android:gravity="center"
+        android:visibility="invisible"
+        android:text="@string/screen_compat_mode_hint" />
+</LinearLayout>
diff --git a/core/res/res/layout/app_perms_summary.xml b/core/res/res/layout/app_perms_summary.xml
index bdbbfcb..3f99dde 100755
--- a/core/res/res/layout/app_perms_summary.xml
+++ b/core/res/res/layout/app_perms_summary.xml
@@ -60,10 +60,11 @@
             android:orientation="horizontal"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:layout_marginTop="16dip"
-            android:layout_marginBottom="12dip"
-            android:layout_marginLeft="16dip"
-            android:duplicateParentState="true">
+            android:paddingTop="16dip"
+            android:paddingBottom="12dip"
+            android:paddingLeft="16dip"
+            android:duplicateParentState="true"
+            android:background="?android:attr/selectableItemBackground">
 
             <TextView
                 android:id="@+id/show_more_text"
diff --git a/core/res/res/layout/dialog_custom_title_holo.xml b/core/res/res/layout/dialog_custom_title_holo.xml
index 74b6070..5261553 100644
--- a/core/res/res/layout/dialog_custom_title_holo.xml
+++ b/core/res/res/layout/dialog_custom_title_holo.xml
@@ -23,18 +23,16 @@
     android:fitsSystemWindows="true">
     <FrameLayout android:id="@android:id/title_container"
         android:layout_width="match_parent"
-        android:layout_height="60dip"
+        android:layout_height="@dimen/alert_dialog_title_height"
         android:layout_weight="0"
         android:gravity="center_vertical|left"
         style="?android:attr/windowTitleBackgroundStyle">
     </FrameLayout>
     <ImageView android:id="@+id/titleDivider"
             android:layout_width="match_parent"
-            android:layout_height="4dip"
+            android:layout_height="1dip"
             android:scaleType="fitXY"
             android:gravity="fill_horizontal"
-            android:paddingLeft="16dip"
-            android:paddingRight="16dip"
             android:src="@android:drawable/divider_strong_holo" />
     <FrameLayout
         android:layout_width="match_parent" android:layout_height="wrap_content"
diff --git a/core/res/res/layout/dialog_title_holo.xml b/core/res/res/layout/dialog_title_holo.xml
index 534dd8d..400ef60 100644
--- a/core/res/res/layout/dialog_title_holo.xml
+++ b/core/res/res/layout/dialog_title_holo.xml
@@ -26,17 +26,15 @@
     <TextView android:id="@android:id/title" style="?android:attr/windowTitleStyle"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:minHeight="60dip"
-        android:paddingLeft="32dip"
-        android:paddingRight="32dip"
+        android:minHeight="@android:dimen/alert_dialog_title_height"
+        android:paddingLeft="16dip"
+        android:paddingRight="16dip"
         android:gravity="center_vertical|left" />
     <ImageView android:id="@+id/titleDivider"
             android:layout_width="match_parent"
-            android:layout_height="4dip"
+            android:layout_height="1dip"
             android:scaleType="fitXY"
             android:gravity="fill_horizontal"
-            android:paddingLeft="16dip"
-            android:paddingRight="16dip"
             android:src="@android:drawable/divider_strong_holo" />
     <FrameLayout
         android:layout_width="match_parent" android:layout_height="wrap_content"
diff --git a/core/res/res/layout/dialog_title_icons_holo.xml b/core/res/res/layout/dialog_title_icons_holo.xml
index a3cd3af..f780ab0 100644
--- a/core/res/res/layout/dialog_title_icons_holo.xml
+++ b/core/res/res/layout/dialog_title_icons_holo.xml
@@ -28,16 +28,16 @@
         android:layout_height="wrap_content"
         android:orientation="horizontal"
         android:gravity="center_vertical"
-        android:minHeight="60dip"
-        android:paddingLeft="32dip"
-        android:paddingRight="32dip">
+        android:minHeight="@android:dimen/alert_dialog_title_height"
+        android:paddingLeft="16dip"
+        android:paddingRight="16dip">
         <ImageView android:id="@+id/left_icon"
             android:layout_width="32dip"
             android:layout_height="32dip"
             android:scaleType="fitCenter"
             android:layout_marginRight="8dip" />
         <TextView android:id="@android:id/title"
-		style="?android:attr/windowTitleStyle"
+            style="?android:attr/windowTitleStyle"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_weight="0" />
@@ -50,11 +50,9 @@
 
     <ImageView android:id="@+id/titleDivider"
             android:layout_width="match_parent"
-            android:layout_height="4dip"
+            android:layout_height="1dip"
             android:scaleType="fitXY"
             android:gravity="fill_horizontal"
-            android:paddingLeft="16dip"
-            android:paddingRight="16dip"
             android:src="@android:drawable/divider_strong_holo" />
 
     <FrameLayout
diff --git a/core/res/res/layout/global_actions_item.xml b/core/res/res/layout/global_actions_item.xml
index 68fe960..67b1644 100644
--- a/core/res/res/layout/global_actions_item.xml
+++ b/core/res/res/layout/global_actions_item.xml
@@ -40,7 +40,7 @@
         android:layout_alignParentBottom="true"
         android:layout_alignParentRight="true"
 
-        android:textAppearance="?android:attr/textAppearanceSmallInverse"
+        android:textAppearance="?android:attr/textAppearanceSmall"
         />
 
 
@@ -54,7 +54,7 @@
         android:layout_above="@id/status"
         android:layout_alignWithParentIfMissing="true"
         android:gravity="center_vertical"
-        android:textAppearance="?android:attr/textAppearanceLargeInverse"
+        android:textAppearance="?android:attr/textAppearanceLarge"
         />
 
 
diff --git a/core/res/res/layout/input_method_extract_view.xml b/core/res/res/layout/input_method_extract_view.xml
index 7d59d02..60bc24c 100644
--- a/core/res/res/layout/input_method_extract_view.xml
+++ b/core/res/res/layout/input_method_extract_view.xml
@@ -18,7 +18,7 @@
 */
 -->
 
-<LinearLayout
+<android.inputmethodservice.ExtractEditLayout
         xmlns:android="http://schemas.android.com/apk/res/android"
         android:orientation="horizontal">
         
@@ -38,8 +38,8 @@
             android:id="@+id/inputExtractAccessories"
             android:layout_width="wrap_content"
             android:layout_height="match_parent"
-            android:paddingLeft="10dip"
-            android:paddingRight="10dip"
+            android:paddingLeft="8dip"
+            android:paddingRight="8dip"
             android:background="@android:drawable/keyboard_accessory_bg_landscape"
         >
         
@@ -48,7 +48,14 @@
             android:layout_height="wrap_content"
             android:layout_gravity="center"
             />
+        <android.inputmethodservice.ExtractButton android:id="@+id/inputExtractEditButton"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center"
+            android:text="@string/extract_edit_menu_button"
+            android:visibility="invisible"
+            />
             
     </FrameLayout>
     
-</LinearLayout>
+</android.inputmethodservice.ExtractEditLayout>
diff --git a/core/res/res/layout/keyguard_screen_sim_puk_landscape.xml b/core/res/res/layout/keyguard_screen_sim_puk_landscape.xml
new file mode 100644
index 0000000..d58fb23
--- /dev/null
+++ b/core/res/res/layout/keyguard_screen_sim_puk_landscape.xml
@@ -0,0 +1,182 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+**
+** Copyright 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.
+*/
+-->
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:orientation="vertical"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:background="@android:color/background_dark"
+        >
+
+    <LinearLayout android:id="@+id/topDisplayGroup"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:orientation="vertical">
+
+        <!-- header text ('Enter Puk Code') -->
+        <TextView android:id="@+id/headerText"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:gravity="center"
+            android:singleLine="true"
+            android:textAppearance="?android:attr/textAppearanceLarge"/>
+
+        <!-- Carrier info -->
+        <TextView android:id="@+id/carrier"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginTop="9dip"
+            android:gravity="center"
+            android:singleLine="true"
+            android:ellipsize="marquee"
+            android:textAppearance="?android:attr/textAppearanceMedium"/>
+
+        <LinearLayout
+            android:orientation="horizontal"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content">
+
+            <LinearLayout
+                android:orientation="vertical"
+                android:layout_width="wrap_content"
+                android:layout_height="match_parent"
+                android:layout_marginRight="10dip"
+                android:layout_marginLeft="10dip">
+                <TextView android:id="@+id/enter_puk"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:gravity="center_vertical"
+                    android:text="@android:string/keyguard_password_enter_puk_prompt"
+                    android:textSize="30sp"
+                    android:layout_marginBottom="10dip"/>
+                <TextView android:id="@+id/enter_pin"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:gravity="center_vertical"
+                    android:text="@android:string/keyguard_password_enter_pin_prompt"
+                    android:textSize="30sp"
+                    android:layout_marginTop="10dip"/>
+            </LinearLayout>
+
+            <LinearLayout
+                  android:orientation="vertical"
+                  android:layout_width="wrap_content"
+                  android:layout_weight="1"
+                  android:layout_height="match_parent"
+                  android:paddingRight="0dip"
+                  android:layout_marginRight="10dip"
+                  android:layout_marginLeft="10dip">
+
+                  <LinearLayout
+                      android:layout_width="match_parent"
+                      android:layout_height="wrap_content"
+                      android:orientation="horizontal"
+                      android:layout_marginRight="6dip"
+                      android:layout_marginLeft="6dip"
+                      android:gravity="center_vertical"
+                      android:background="@android:drawable/edit_text">
+
+                      <!-- displays dots as user enters puk -->
+                      <TextView android:id="@+id/pukDisplay"
+                          android:layout_width="0dip"
+                          android:layout_height="wrap_content"
+                          android:layout_weight="1"
+                          android:maxLines="1"
+                          android:textAppearance="?android:attr/textAppearanceLargeInverse"
+                          android:textStyle="bold"
+                          android:inputType="textPassword"
+                      />
+
+                      <ImageButton android:id="@+id/pukDel"
+                          android:src="@android:drawable/ic_input_delete"
+                          android:layout_width="wrap_content"
+                          android:layout_height="wrap_content"
+                          android:layout_marginRight="-3dip"
+                          android:layout_marginBottom="-3dip"
+                      />
+                  </LinearLayout>
+
+
+                  <LinearLayout
+                      android:layout_width="match_parent"
+                      android:layout_height="wrap_content"
+                      android:orientation="horizontal"
+                      android:layout_marginRight="6dip"
+                      android:layout_marginLeft="6dip"
+                      android:gravity="center_vertical"
+                      android:background="@android:drawable/edit_text">
+
+                      <!-- displays dots as user enters new pin -->
+                      <TextView android:id="@+id/pinDisplay"
+                          android:layout_width="0dip"
+                          android:layout_height="wrap_content"
+                          android:layout_weight="1"
+                          android:maxLines="1"
+                          android:textAppearance="?android:attr/textAppearanceLargeInverse"
+                          android:textStyle="bold"
+                          android:inputType="textPassword"
+                      />
+
+                      <ImageButton android:id="@+id/pinDel"
+                          android:src="@android:drawable/ic_input_delete"
+                          android:layout_width="wrap_content"
+                          android:layout_height="wrap_content"
+                          android:layout_marginRight="-3dip"
+                          android:layout_marginBottom="-3dip"
+                      />
+                  </LinearLayout>
+              </LinearLayout>
+        </LinearLayout>
+    </LinearLayout>
+
+    <LinearLayout
+        android:orientation="horizontal"
+        android:layout_alignParentBottom="true"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_marginBottom="8dip"
+        android:layout_marginLeft="8dip"
+        android:layout_marginRight="8dip">
+
+        <Button android:id="@+id/ok"
+            android:text="@android:string/ok"
+            android:layout_alignParentBottom="true"
+            android:layout_width="0dip"
+            android:layout_height="wrap_content"
+            android:layout_weight="1.0"
+            android:layout_marginBottom="8dip"
+            android:layout_marginRight="8dip"
+            android:textSize="18sp"
+            />
+
+        <Button android:id="@+id/emergencyCall"
+            android:text="@android:string/lockscreen_emergency_call"
+            android:layout_alignParentBottom="true"
+            android:layout_centerHorizontal="true"
+            android:layout_width="0dip"
+            android:layout_height="wrap_content"
+            android:layout_weight="1.0"
+            android:layout_marginBottom="8dip"
+            android:layout_marginLeft="8dip"
+            android:textSize="18sp"
+            android:drawableLeft="@drawable/ic_emergency"
+            android:drawablePadding="8dip"
+        />
+    </LinearLayout>
+
+</RelativeLayout>
diff --git a/core/res/res/layout/keyguard_screen_sim_puk_portrait.xml b/core/res/res/layout/keyguard_screen_sim_puk_portrait.xml
new file mode 100644
index 0000000..5e392ef
--- /dev/null
+++ b/core/res/res/layout/keyguard_screen_sim_puk_portrait.xml
@@ -0,0 +1,185 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+**
+** Copyright 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.
+*/
+-->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical"
+    android:background="@android:color/background_dark"
+    android:gravity="center_horizontal">
+
+    <LinearLayout android:id="@+id/topDisplayGroup"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:orientation="vertical">
+
+        <!-- header text ('Enter Puk Code') -->
+        <TextView android:id="@+id/headerText"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:gravity="center"
+            android:singleLine="true"
+            android:textAppearance="?android:attr/textAppearanceLarge"/>
+
+        <!-- Carrier info -->
+        <TextView android:id="@+id/carrier"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginTop="9dip"
+            android:gravity="center"
+            android:singleLine="true"
+            android:ellipsize="marquee"
+            android:textAppearance="?android:attr/textAppearanceMedium"/>
+
+        <LinearLayout
+            android:orientation="horizontal"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content">
+
+            <LinearLayout
+                android:orientation="vertical"
+                android:layout_width="wrap_content"
+                android:layout_height="match_parent"
+                android:layout_marginRight="10dip"
+                android:layout_marginLeft="10dip">
+                <TextView android:id="@+id/enter_puk"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:gravity="center_vertical"
+                    android:text="@android:string/keyguard_password_enter_puk_prompt"
+                    android:textSize="30sp"
+                    android:layout_marginBottom="10dip"/>
+                <TextView android:id="@+id/enter_pin"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:gravity="center_vertical"
+                    android:text="@android:string/keyguard_password_enter_pin_prompt"
+                    android:textSize="30sp"
+                    android:layout_marginTop="10dip"/>
+            </LinearLayout>
+
+            <LinearLayout
+                  android:orientation="vertical"
+                  android:layout_width="wrap_content"
+                  android:layout_weight="1"
+                  android:layout_height="match_parent"
+                  android:paddingRight="0dip"
+                  android:layout_marginRight="10dip"
+                  android:layout_marginLeft="10dip">
+
+                  <LinearLayout
+                      android:layout_width="match_parent"
+                      android:layout_height="wrap_content"
+                      android:orientation="horizontal"
+                      android:layout_marginRight="6dip"
+                      android:layout_marginLeft="6dip"
+                      android:gravity="center_vertical"
+                      android:background="@android:drawable/edit_text">
+
+                      <!-- displays dots as user enters puk -->
+                      <TextView android:id="@+id/pukDisplay"
+                          android:layout_width="0dip"
+                          android:layout_height="wrap_content"
+                          android:layout_weight="1"
+                          android:maxLines="1"
+                          android:textAppearance="?android:attr/textAppearanceLargeInverse"
+                          android:textStyle="bold"
+                          android:inputType="textPassword"
+                      />
+
+                      <ImageButton android:id="@+id/pukDel"
+                          android:src="@android:drawable/ic_input_delete"
+                          android:layout_width="wrap_content"
+                          android:layout_height="wrap_content"
+                          android:layout_marginRight="-3dip"
+                          android:layout_marginBottom="-3dip"
+                      />
+                  </LinearLayout>
+
+
+                  <LinearLayout
+                      android:layout_width="match_parent"
+                      android:layout_height="wrap_content"
+                      android:orientation="horizontal"
+                      android:layout_marginRight="6dip"
+                      android:layout_marginLeft="6dip"
+                      android:gravity="center_vertical"
+                      android:background="@android:drawable/edit_text">
+
+                      <!-- displays dots as user enters new pin -->
+                      <TextView android:id="@+id/pinDisplay"
+                          android:layout_width="0dip"
+                          android:layout_height="wrap_content"
+                          android:layout_weight="1"
+                          android:maxLines="1"
+                          android:textAppearance="?android:attr/textAppearanceLargeInverse"
+                          android:textStyle="bold"
+                          android:inputType="textPassword"
+                      />
+
+                      <ImageButton android:id="@+id/pinDel"
+                          android:src="@android:drawable/ic_input_delete"
+                          android:layout_width="wrap_content"
+                          android:layout_height="wrap_content"
+                          android:layout_marginRight="-3dip"
+                          android:layout_marginBottom="-3dip"
+                      />
+                  </LinearLayout>
+              </LinearLayout>
+        </LinearLayout>
+    </LinearLayout>
+
+    <include
+        android:id="@+id/keyPad"
+        layout="@android:layout/twelve_key_entry"
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content"
+        android:layout_below="@id/topDisplayGroup"
+        android:layout_marginTop="10dip"
+    />
+
+    <!-- spacer below keypad -->
+    <View
+        android:id="@+id/spacerBottom"
+        android:layout_width="match_parent"
+        android:layout_height="1dip"
+        android:layout_marginTop="6dip"
+        android:layout_above="@id/emergencyCall"
+        android:background="@android:drawable/divider_horizontal_dark"
+    />
+
+    <!-- The emergency button should take the rest of the space and be centered vertically -->
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="0dip"
+        android:layout_weight="1"
+        android:gravity="center"
+        android:orientation="vertical">
+
+        <!-- emergency call button -->
+        <Button
+            android:id="@+id/emergencyCall"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:drawableLeft="@android:drawable/ic_emergency"
+            android:drawablePadding="8dip"
+            android:text="@android:string/lockscreen_emergency_call"
+        />
+    </LinearLayout>
+
+</LinearLayout>
diff --git a/core/res/res/layout/keyguard_screen_status_land.xml b/core/res/res/layout/keyguard_screen_status_land.xml
index 259a3af..8a02e1f 100644
--- a/core/res/res/layout/keyguard_screen_status_land.xml
+++ b/core/res/res/layout/keyguard_screen_status_land.xml
@@ -133,16 +133,4 @@
         android:textAppearance="?android:attr/textAppearanceMedium"
         />
 
-    <TextView
-        android:id="@+id/propertyOf"
-        android:lineSpacingExtra="8dip"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:textAppearance="?android:attr/textAppearanceMedium"
-        android:textSize="17sp"
-        android:layout_marginTop="20dip"
-        android:singleLine="false"
-        android:textColor="@color/lockscreen_owner_info"
-        android:visibility="gone"
-        />
 </LinearLayout>
diff --git a/core/res/res/layout/keyguard_screen_status_port.xml b/core/res/res/layout/keyguard_screen_status_port.xml
index 680c073..1e87fb3 100644
--- a/core/res/res/layout/keyguard_screen_status_port.xml
+++ b/core/res/res/layout/keyguard_screen_status_port.xml
@@ -130,16 +130,4 @@
         android:textAppearance="?android:attr/textAppearanceMedium"
         />
 
-    <TextView
-        android:id="@+id/propertyOf"
-        android:lineSpacingExtra="8dip"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_marginTop="20dip"
-        android:textAppearance="?android:attr/textAppearanceMedium"
-        android:textSize="17sp"
-        android:singleLine="false"
-        android:visibility="gone"
-        android:textColor="@color/lockscreen_owner_info"
-        />
 </LinearLayout>
diff --git a/core/res/res/layout/keyguard_screen_tab_unlock.xml b/core/res/res/layout/keyguard_screen_tab_unlock.xml
index 5fe38d5..7ae357a 100644
--- a/core/res/res/layout/keyguard_screen_tab_unlock.xml
+++ b/core/res/res/layout/keyguard_screen_tab_unlock.xml
@@ -22,11 +22,11 @@
   depending on the state of the device.  It is the same for landscape
   and portrait.-->
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:tabunlock="http://schemas.android.com/apk/res/com.android.tabunlock"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:gravity="center_horizontal"
-    android:id="@+id/root">
+    android:id="@+id/root"
+    android:clipChildren="false">
 
     <TextView
         android:id="@+id/carrier"
@@ -162,13 +162,24 @@
         android:drawablePadding="4dip"
         />
 
-    <com.android.internal.widget.SlidingTab
-        android:id="@+id/tab_selector"
+    <com.android.internal.widget.multiwaveview.MultiWaveView
+        android:id="@+id/unlock_widget"
         android:orientation="horizontal"
         android:layout_width="match_parent"
-        android:layout_height="wrap_content"
+        android:layout_height="300dip"
         android:layout_alignParentBottom="true"
-        android:layout_marginBottom="80dip"
+
+        android:targetDrawables="@array/lockscreen_targets_when_silent"
+        android:handleDrawable="@drawable/ic_lockscreen_handle"
+        android:waveDrawable="@drawable/ic_lockscreen_outerring"
+        android:outerRadius="@*android:dimen/multiwaveview_target_placement_radius"
+        android:snapMargin="@*android:dimen/multiwaveview_snap_margin"
+        android:hitRadius="@*android:dimen/multiwaveview_hit_radius"
+        android:vibrationDuration="20"
+        android:rightChevronDrawable="@drawable/ic_lockscreen_chevron_right"
+        android:feedbackCount="3"
+        android:horizontalOffset="0dip"
+        android:verticalOffset="60dip"
         />
 
     <!-- emergency call button shown when sim is PUKd and tab_selector is
diff --git a/core/res/res/layout/keyguard_screen_tab_unlock_land.xml b/core/res/res/layout/keyguard_screen_tab_unlock_land.xml
index 3c2ad9a..d45cc85 100644
--- a/core/res/res/layout/keyguard_screen_tab_unlock_land.xml
+++ b/core/res/res/layout/keyguard_screen_tab_unlock_land.xml
@@ -20,32 +20,130 @@
 <!-- This is the general lock screen which shows information about the
   state of the device, as well as instructions on how to get past it
   depending on the state of the device.-->
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:tabunlock="http://schemas.android.com/apk/res/com.android.tabunlock"
+<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    android:orientation="horizontal"
-    android:id="@+id/root">
+    android:orientation="vertical"
+    android:rowCount="10"
+    android:id="@+id/root"
+    android:clipChildren="false">
 
-    <!-- left side -->
-    <RelativeLayout
-            android:layout_width="0dip"
-            android:layout_height="match_parent"
-            android:layout_weight="1.0"
-            android:layout_marginLeft="24dip"
-            android:gravity="left">
+    <!-- Column 0 -->
+    <Space android:height="20dip"/>
 
-        <TextView
+    <com.android.internal.widget.DigitalClock android:id="@+id/time"
+        android:layout_marginTop="56dip"
+        android:layout_marginBottom="8dip">
+
+       <!-- Because we can't have multi-tone fonts, we render two TextViews, one on
+        top of the other. Hence the redundant layout... -->
+        <TextView android:id="@+id/timeDisplayBackground"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:singleLine="true"
+            android:ellipsize="none"
+            android:textSize="72sp"
+            android:textAppearance="?android:attr/textAppearanceMedium"
+            android:layout_marginBottom="6dip"
+            android:textColor="@color/lockscreen_clock_background"
+            />
+
+        <TextView android:id="@+id/timeDisplayForeground"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:singleLine="true"
+            android:ellipsize="none"
+            android:textSize="72sp"
+            android:textAppearance="?android:attr/textAppearanceMedium"
+            android:layout_marginBottom="6dip"
+            android:textColor="@color/lockscreen_clock_foreground"
+            android:layout_alignLeft="@id/timeDisplayBackground"
+            android:layout_alignTop="@id/timeDisplayBackground"
+            />
+
+        <TextView android:id="@+id/am_pm"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_toRightOf="@id/timeDisplayBackground"
+            android:layout_alignBaseline="@id/timeDisplayBackground"
+            android:singleLine="true"
+            android:ellipsize="none"
+            android:textSize="22sp"
+            android:layout_marginLeft="8dip"
+            android:textAppearance="?android:attr/textAppearanceMedium"
+            android:textColor="@color/lockscreen_clock_am_pm"
+            android:visibility="gone"
+            />
+
+    </com.android.internal.widget.DigitalClock>
+
+    <TextView
+        android:id="@+id/date"
+        android:layout_below="@id/time"
+        android:layout_marginTop="6dip"
+        android:textAppearance="?android:attr/textAppearanceMedium"
+        android:layout_gravity="left"
+        />
+
+    <TextView
+        android:id="@+id/alarm_status"
+        android:textAppearance="?android:attr/textAppearanceMedium"
+        android:textSize="18sp"
+        android:drawablePadding="4dip"
+        android:layout_marginTop="4dip"
+        android:layout_gravity="left"
+        />
+
+    <TextView
+        android:id="@+id/status1"
+        android:layout_marginTop="4dip"
+        android:textAppearance="?android:attr/textAppearanceMedium"
+        android:drawablePadding="4dip"
+        android:layout_gravity="left"
+        />
+
+    <TextView
+        android:id="@+id/status2"
+        android:layout_marginTop="4dip"
+        android:textAppearance="?android:attr/textAppearanceMedium"
+        android:drawablePadding="4dip"
+        android:layout_gravity="left"
+        />
+
+    <TextView
+        android:id="@+id/screenLocked"
+        android:textAppearance="?android:attr/textAppearanceMedium"
+        android:gravity="center"
+        android:layout_marginTop="4dip"
+        android:drawablePadding="4dip"
+        android:layout_gravity="left"
+        />
+
+    <Space android:height="20dip"/>
+
+    <LinearLayout android:orientation="horizontal" >
+
+         <TextView
             android:id="@+id/carrier"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_alignParentTop="true"
-            android:layout_marginTop="20dip"
             android:singleLine="true"
             android:ellipsize="marquee"
-            android:gravity="right|bottom"
+            android:layout_gravity="bottom|left"
             android:textAppearance="?android:attr/textAppearanceMedium"
-            />
+        />
+
+        <Button
+            android:id="@+id/emergencyCallButton"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:drawableLeft="@drawable/ic_emergency"
+            style="@style/Widget.Button.Transparent"
+            android:drawablePadding="8dip"
+            android:layout_marginRight="80dip"
+            android:visibility="gone"
+        />
 
         <!-- "emergency calls only" shown when sim is missing or PUKd -->
         <TextView
@@ -57,132 +155,32 @@
             android:text="@string/emergency_calls_only"
             android:textAppearance="?android:attr/textAppearanceSmall"
             android:textColor="@color/white"
-           />
+        />
+    </LinearLayout>
 
-        <com.android.internal.widget.DigitalClock android:id="@+id/time"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_below="@id/carrier"
-            android:layout_marginTop="56dip"
-            android:layout_marginBottom="8dip"
-            >
+    <Space android:height="20dip"/>
 
-           <!-- Because we can't have multi-tone fonts, we render two TextViews, one on
-            top of the other. Hence the redundant layout... -->
-            <TextView android:id="@+id/timeDisplayBackground"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:singleLine="true"
-                android:ellipsize="none"
-                android:textSize="72sp"
-                android:textAppearance="?android:attr/textAppearanceMedium"
-                android:layout_marginBottom="6dip"
-                android:textColor="@color/lockscreen_clock_background"
-                />
+    <!-- Column 1 -->
+    <Space android:width="20dip" android:layout_columnWeight="1" android:layout_rowSpan="10" />
 
-            <TextView android:id="@+id/timeDisplayForeground"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:singleLine="true"
-                android:ellipsize="none"
-                android:textSize="72sp"
-                android:textAppearance="?android:attr/textAppearanceMedium"
-                android:layout_marginBottom="6dip"
-                android:textColor="@color/lockscreen_clock_foreground"
-                android:layout_alignLeft="@id/timeDisplayBackground"
-                android:layout_alignTop="@id/timeDisplayBackground"
-                />
-
-            <TextView android:id="@+id/am_pm"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_toRightOf="@id/timeDisplayBackground"
-                android:layout_alignBaseline="@id/timeDisplayBackground"
-                android:singleLine="true"
-                android:ellipsize="none"
-                android:textSize="22sp"
-                android:layout_marginLeft="8dip"
-                android:textAppearance="?android:attr/textAppearanceMedium"
-                android:textColor="@color/lockscreen_clock_am_pm"
-                />
-
-        </com.android.internal.widget.DigitalClock>
-
-        <TextView
-            android:id="@+id/date"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_below="@id/time"
-            android:layout_marginTop="6dip"
-            android:textAppearance="?android:attr/textAppearanceMedium"
-            />
-
-        <!-- TODO: Redo layout when we release on phones -->
-        <TextView
-            android:id="@+id/alarm_status"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:textAppearance="?android:attr/textAppearanceMedium"
-            android:textSize="18sp"
-            android:drawablePadding="4dip"
-            android:layout_below="@id/date"
-            android:layout_marginTop="4dip"
-            android:layout_marginLeft="24dip"
-            />
-
-        <TextView
-            android:id="@+id/status1"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_below="@id/alarm_status"
-            android:layout_marginTop="6dip"
-            android:textAppearance="?android:attr/textAppearanceMedium"
-            android:drawablePadding="4dip"
-            />
-
-        <TextView
-            android:id="@+id/status2"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_below="@id/status1"
-            android:layout_marginTop="6dip"
-            android:textAppearance="?android:attr/textAppearanceMedium"
-            android:drawablePadding="4dip"
-            />
-
-        <TextView
-            android:id="@+id/screenLocked"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_below="@id/status2"
-            android:textAppearance="?android:attr/textAppearanceMedium"
-            android:gravity="center"
-            android:layout_marginTop="12dip"
-            android:drawablePadding="4dip"
-            />
-
-    </RelativeLayout>
-
-    <!-- right side -->
-    <com.android.internal.widget.SlidingTab
-        android:id="@+id/tab_selector"
-        android:orientation="vertical"
-        android:layout_width="wrap_content"
+    <!-- Column 2 -->
+    <com.android.internal.widget.multiwaveview.MultiWaveView
+        android:id="@+id/unlock_widget"
+        android:layout_width="300dip"
         android:layout_height="match_parent"
-        android:layout_marginRight="80dip"
+        android:layout_rowSpan="10"
+
+        android:targetDrawables="@array/lockscreen_targets_when_silent"
+        android:handleDrawable="@drawable/ic_lockscreen_handle"
+        android:waveDrawable="@drawable/ic_lockscreen_outerring"
+        android:outerRadius="@*android:dimen/multiwaveview_target_placement_radius"
+        android:snapMargin="@*android:dimen/multiwaveview_snap_margin"
+        android:hitRadius="@*android:dimen/multiwaveview_hit_radius"
+        android:vibrationDuration="20"
+        android:topChevronDrawable="@drawable/ic_lockscreen_chevron_up"
+        android:feedbackCount="3"
+        android:horizontalOffset="0dip"
+        android:verticalOffset="0dip"
         />
 
-    <!-- emergency call button shown when sim is PUKd and tab_selector is
-         hidden -->
-    <Button
-        android:id="@+id/emergencyCallButton"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:drawableLeft="@drawable/ic_emergency"
-        style="@style/Widget.Button.Transparent"
-        android:drawablePadding="8dip"
-        android:layout_marginRight="80dip"
-        android:visibility="gone"
-        />
-
-</LinearLayout>
+</GridLayout>
diff --git a/core/res/res/layout/keyguard_screen_unlock_landscape.xml b/core/res/res/layout/keyguard_screen_unlock_landscape.xml
index c7b78c4..d52bc57 100644
--- a/core/res/res/layout/keyguard_screen_unlock_landscape.xml
+++ b/core/res/res/layout/keyguard_screen_unlock_landscape.xml
@@ -21,198 +21,124 @@
      the user how to unlock their device, or make an emergency call.  This
      is the portrait layout.  -->
 
-<com.android.internal.widget.LinearLayoutWithDefaultTouchRecepient
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    android:orientation="horizontal"
+<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/root"
+    android:orientation="vertical"
     android:layout_width="match_parent"
-    android:layout_height="match_parent">
+    android:layout_height="match_parent"
+    android:rowCount="9">
 
-    <!-- left side: instructions and emergency call button -->
-    <LinearLayout
-            android:orientation="vertical"
-            android:layout_width="0dip"
-            android:layout_height="match_parent"
-            android:layout_weight="1.0"
-            android:layout_marginLeft="24dip"
-            android:gravity="left"
-            >
+    <!-- Column 0: Time, date and status -->
+    <com.android.internal.widget.DigitalClock android:id="@+id/time"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="8dip"
+        android:layout_marginBottom="12dip"
+        android:layout_gravity="right">
 
-        <TextView
-            android:id="@+id/alarm_status"
+        <!-- Because we can't have multi-tone fonts, we render two TextViews, one on
+        top of the other. Hence the redundant layout... -->
+        <TextView android:id="@+id/timeDisplayBackground"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:textAppearance="?android:attr/textAppearanceMedium"
-            android:textSize="18sp"
-            android:drawablePadding="4dip"
-            />
-        <TextView
-            android:id="@+id/status1"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_marginTop="16dip"
-            android:textAppearance="?android:attr/textAppearanceMedium"
-            />
-
-        <TextView
-            android:id="@+id/carrier"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:textAppearance="?android:attr/textAppearanceMedium"
-            android:textSize="17sp"
-            android:drawablePadding="4dip"
-            android:layout_marginTop="32dip"
             android:singleLine="true"
-            android:ellipsize="marquee"
-            android:gravity="right|bottom"
-            />
-
-        <com.android.internal.widget.DigitalClock android:id="@+id/time"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_alignParentTop="true"
-            android:layout_alignParentLeft="true"
-            android:layout_marginTop="8dip"
-            android:layout_marginBottom="8dip"
-            >
-
-            <!-- Because we can't have multi-tone fonts, we render two TextViews, one on
-            top of the other. Hence the redundant layout... -->
-            <TextView android:id="@+id/timeDisplayBackground"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:singleLine="true"
-                android:ellipsize="none"
-                android:textSize="72sp"
-                android:textAppearance="?android:attr/textAppearanceMedium"
-                android:layout_marginBottom="6dip"
-                android:textColor="@color/lockscreen_clock_background"
-                />
-
-            <TextView android:id="@+id/timeDisplayForeground"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:singleLine="true"
-                android:ellipsize="none"
-                android:textSize="72sp"
-                android:textAppearance="?android:attr/textAppearanceMedium"
-                android:layout_marginBottom="6dip"
-                android:layout_alignLeft="@id/timeDisplayBackground"
-                android:layout_alignTop="@id/timeDisplayBackground"
-                android:textColor="@color/lockscreen_clock_foreground"
-                />
-
-
-
-            <TextView android:id="@+id/am_pm"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_toRightOf="@id/timeDisplayBackground"
-                android:layout_alignBaseline="@id/timeDisplayBackground"
-                android:singleLine="true"
-                android:ellipsize="none"
-                android:textSize="22sp"
-                android:layout_marginLeft="8dip"
-                android:textAppearance="?android:attr/textAppearanceMedium"
-                android:textColor="@color/lockscreen_clock_am_pm"
-                />
-
-        </com.android.internal.widget.DigitalClock>
-
-        <TextView
-            android:id="@+id/date"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_below="@id/time"
+            android:ellipsize="none"
             android:textAppearance="?android:attr/textAppearanceMedium"
+            android:textSize="@dimen/keyguard_pattern_unlock_clock_font_size"
+            android:layout_marginBottom="6dip"
+            android:textColor="@color/lockscreen_clock_background"
             />
 
-        <!-- used for instructions such as "draw pattern to unlock", the next alarm, and charging
-             status.  -->
-        <LinearLayout
-            android:orientation="horizontal"
+        <TextView android:id="@+id/timeDisplayForeground"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:layout_marginTop="8dip"
-            android:gravity="center"
-            >
-            <TextView
-                android:id="@+id/statusSep"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_marginLeft="5dip"
-                android:layout_marginRight="5dip"
-                android:textAppearance="?android:attr/textAppearanceMedium"
-                android:textSize="17sp"
-                />
-            <TextView
-                android:id="@+id/status2"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_alignParentTop="true"
-                android:textAppearance="?android:attr/textAppearanceMedium"
-                android:textSize="17sp"
-                android:drawablePadding="4dip"
-                />
-        </LinearLayout>
-
-        <!-- fill space between header and button below -->
-        <View
-            android:layout_weight="1.0"
-            android:layout_width="match_parent"
-            android:layout_height="0dip"
+            android:singleLine="true"
+            android:ellipsize="none"
+            android:textAppearance="?android:attr/textAppearanceMedium"
+            android:textSize="@dimen/keyguard_pattern_unlock_clock_font_size"
+            android:layout_marginBottom="6dip"
+            android:layout_alignLeft="@id/timeDisplayBackground"
+            android:layout_alignTop="@id/timeDisplayBackground"
+            android:textColor="@color/lockscreen_clock_foreground"
             />
 
-        <!-- footer -->
-        <FrameLayout
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:layout_marginBottom="16dip"
-            >
+    </com.android.internal.widget.DigitalClock>
 
-            <!-- option 1: a single emergency call button -->
-            <RelativeLayout android:id="@+id/footerNormal"
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:gravity="left"
-                >
-                <Button android:id="@+id/emergencyCallAlone"
-                    android:layout_width="wrap_content"
-                    android:layout_height="wrap_content"
-                    android:text="@string/lockscreen_emergency_call"
-                    style="@style/Widget.Button.Transparent"
-                    android:drawableLeft="@drawable/ic_emergency"
-                    android:drawablePadding="8dip"
-                    />
-            </RelativeLayout>
+    <TextView
+        android:id="@+id/date"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:textAppearance="?android:attr/textAppearanceMedium"
+        android:textSize="@dimen/keyguard_pattern_unlock_status_line_font_size"
+        android:layout_gravity="right"
+        />
 
-            <!-- option 2: an emergency call button, and a 'forgot pattern?' button -->
-            <LinearLayout android:id="@+id/footerForgotPattern"
-                android:orientation="vertical"
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:gravity="left"
-                >
-                <Button android:id="@+id/forgotPattern"
-                    android:layout_width="match_parent"
-                    android:layout_height="wrap_content"
-                    style="@style/Widget.Button.Transparent"
-                    android:visibility="invisible"
-                    />
-                <Button android:id="@+id/emergencyCallTogether"
-                    android:layout_width="match_parent"
-                    android:layout_height="wrap_content"
-                    android:text="@string/lockscreen_emergency_call"
-                    style="@style/Widget.Button.Transparent"
-                    android:drawableLeft="@drawable/ic_emergency"
-                    android:drawablePadding="8dip"
-                    />
-            </LinearLayout>
-        </FrameLayout>
-    </LinearLayout>
+    <TextView
+        android:id="@+id/alarm_status"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:textAppearance="?android:attr/textAppearanceMedium"
+        android:textSize="@dimen/keyguard_pattern_unlock_status_line_font_size"
+        android:layout_gravity="right"
+        android:drawablePadding="4dip"
+        />
 
-    <!-- right side: lock pattern -->
+    <TextView
+        android:id="@+id/status1"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:textAppearance="?android:attr/textAppearanceMedium"
+        android:textSize="@dimen/keyguard_pattern_unlock_status_line_font_size"
+        android:layout_gravity="right"
+        />
+
+    <TextView
+        android:id="@+id/status2"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:textAppearance="?android:attr/textAppearanceMedium"
+        android:textSize="@dimen/keyguard_pattern_unlock_status_line_font_size"
+        android:layout_gravity="right"
+        android:drawablePadding="4dip"
+        android:visibility="gone"
+        />
+
+    <Space android:layout_rowWeight="1" android:layout_columnWeight="1" />
+
+    <TextView android:id="@+id/carrier"
+        android:layout_gravity="right"
+        android:textAppearance="?android:attr/textAppearanceMedium"
+        android:textSize="@dimen/keyguard_pattern_unlock_status_line_font_size"
+        android:singleLine="true"
+        android:ellipsize="marquee"
+        />
+
+    <Button android:id="@+id/emergencyCallButton"
+        android:layout_gravity="right"
+        style="@*android:style/Widget.Button.Transparent"
+        android:textSize="@dimen/keyguard_pattern_unlock_status_line_font_size"
+        android:text="@string/lockscreen_emergency_call"
+        android:drawableLeft="@*android:drawable/lockscreen_emergency_button"
+        android:drawablePadding="0dip"
+    />
+
+    <Button android:id="@+id/forgotPatternButton"
+        android:layout_gravity="right"
+        style="@*android:style/Widget.Button.Transparent"
+        android:textSize="@dimen/keyguard_pattern_unlock_status_line_font_size"
+        android:text="@*android:string/lockscreen_forgot_pattern_button_text"
+        android:drawableLeft="@*android:drawable/lockscreen_forgot_password_button"
+        android:drawablePadding="0dip"
+    />
+
+    <!-- Column 1: lock pattern -->
     <com.android.internal.widget.LockPatternView android:id="@+id/lockPattern"
-         android:layout_width="wrap_content"
-         android:layout_height="wrap_content" />
+         android:layout_width="match_parent"
+         android:layout_height="match_parent"
+         android:layout_marginTop="8dip"
+         android:layout_marginRight="8dip"
+         android:layout_marginBottom="8dip"
+         android:layout_marginLeft="8dip"
+         android:layout_rowSpan="9"/>
 
-</com.android.internal.widget.LinearLayoutWithDefaultTouchRecepient>
+</GridLayout>
diff --git a/core/res/res/layout/keyguard_screen_unlock_portrait.xml b/core/res/res/layout/keyguard_screen_unlock_portrait.xml
index 15f2afb..4ffa3405 100644
--- a/core/res/res/layout/keyguard_screen_unlock_portrait.xml
+++ b/core/res/res/layout/keyguard_screen_unlock_portrait.xml
@@ -20,213 +20,147 @@
 <!-- This is the screen that shows the 9 circle unlock widget and instructs
      the user how to unlock their device, or make an emergency call.  This
      is the portrait layout.  -->
-<com.android.internal.widget.LinearLayoutWithDefaultTouchRecepient
+<GridLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:orientation="vertical"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:gravity="center_horizontal">
 
-    <RelativeLayout
-        android:layout_width="match_parent"
+
+    <com.android.internal.widget.DigitalClock android:id="@+id/time"
+        android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        >
-        <TextView
-            android:id="@+id/carrier"
+        android:layout_marginBottom="18dip"
+        android:layout_marginRight="-4dip"
+        android:layout_gravity="right">
+
+        <!-- Because we can't have multi-tone fonts, we render two TextViews, one on
+        top of the other. Hence the redundant layout... -->
+        <TextView android:id="@*android:id/timeDisplayBackground"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:layout_alignParentTop="true"
-            android:layout_marginTop="6dip"
-            android:layout_alignParentRight="true"
-            android:layout_marginRight="8dip"
-            android:layout_toRightOf="@+id/time"
             android:singleLine="true"
-            android:ellipsize="marquee"
-            android:gravity="right|bottom"
+            android:ellipsize="none"
+            android:textSize="@*android:dimen/keyguard_pattern_unlock_clock_font_size"
             android:textAppearance="?android:attr/textAppearanceMedium"
+            android:layout_marginBottom="6dip"
+            android:textColor="@*android:color/lockscreen_clock_background"
             />
 
-        <com.android.internal.widget.DigitalClock android:id="@+id/time"
+        <TextView android:id="@*android:id/timeDisplayForeground"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:layout_alignParentLeft="true"
-            android:layout_alignParentTop="true"
-            android:layout_marginTop="15dip"
-            android:layout_marginLeft="20dip"
-            android:layout_marginBottom="8dip"
-            >
+            android:singleLine="true"
+            android:ellipsize="none"
+            android:textSize="@*android:dimen/keyguard_pattern_unlock_clock_font_size"
+            android:textAppearance="?android:attr/textAppearanceMedium"
+            android:layout_marginBottom="6dip"
+            android:textColor="@color/lockscreen_clock_foreground"
+            />
 
-            <!-- Because we can't have multi-tone fonts, we render two TextViews, one on
-            top of the other. Hence the redundant layout... -->
-            <TextView android:id="@+id/timeDisplayBackground"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:singleLine="true"
-                android:ellipsize="none"
-                android:textSize="56sp"
-                android:textAppearance="?android:attr/textAppearanceMedium"
-                android:layout_marginBottom="6dip"
-                android:textColor="@color/lockscreen_clock_background"
-                />
+    </com.android.internal.widget.DigitalClock>
 
-            <TextView android:id="@+id/timeDisplayForeground"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:singleLine="true"
-                android:ellipsize="none"
-                android:textSize="56sp"
-                android:textAppearance="?android:attr/textAppearanceMedium"
-                android:layout_marginBottom="6dip"
-                android:textColor="@color/lockscreen_clock_foreground"
-                />
-
-            <TextView android:id="@+id/am_pm"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_toRightOf="@id/timeDisplayBackground"
-                android:layout_alignBaseline="@id/timeDisplayBackground"
-                android:singleLine="true"
-                android:ellipsize="none"
-                android:textSize="18sp"
-                android:layout_marginLeft="4dip"
-                android:textAppearance="?android:attr/textAppearanceMedium"
-                android:textColor="@color/lockscreen_clock_am_pm"
-                />
-
-        </com.android.internal.widget.DigitalClock>
+    <LinearLayout
+        android:orientation="horizontal"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_gravity="right">
 
         <TextView
             android:id="@+id/date"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:layout_below="@id/time"
-            android:layout_marginLeft="24dip"
             android:textAppearance="?android:attr/textAppearanceMedium"
+            android:textSize="@*android:dimen/keyguard_pattern_unlock_status_line_font_size"
             />
 
-    </RelativeLayout>
-
-    <View
-        android:id="@+id/divider"
-        android:layout_width="match_parent"
-        android:layout_height="1dip"
-        android:layout_marginTop="8dip"
-        android:layout_marginBottom="8dip"
-        android:background="@android:drawable/divider_horizontal_dark"
-        />
-
-    <!-- used for instructions such as "draw pattern to unlock", the next alarm, and charging
-         status.  -->
-    <LinearLayout
-        android:orientation="horizontal"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:layout_marginTop="0dip"
-        android:layout_marginLeft="12dip"
-        android:gravity="left"
-        >
-        <!-- TODO: Redo layout when we release on phones -->
         <TextView
             android:id="@+id/alarm_status"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
+            android:layout_marginLeft="16dip"
             android:textAppearance="?android:attr/textAppearanceMedium"
-            android:textSize="18sp"
+            android:textSize="@*android:dimen/keyguard_pattern_unlock_status_line_font_size"
             android:drawablePadding="4dip"
             />
-        <TextView
-            android:id="@+id/status1"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:textAppearance="?android:attr/textAppearanceMedium"
-            android:textSize="18sp"
-            android:drawablePadding="4dip"
-            />
-        <TextView
-            android:id="@+id/statusSep"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_marginLeft="5dip"
-            android:layout_marginRight="5dip"
-            android:textAppearance="?android:attr/textAppearanceMedium"
-            android:textSize="18sp"
-            />
-        <TextView
-            android:id="@+id/status2"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_alignParentTop="true"
-            android:textAppearance="?android:attr/textAppearanceMedium"
-            android:textSize="18sp"
-            android:drawablePadding="4dip"
-            />
+
     </LinearLayout>
 
+
+    <TextView
+        android:id="@+id/status1"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:textAppearance="?android:attr/textAppearanceMedium"
+        android:textSize="@*android:dimen/keyguard_pattern_unlock_status_line_font_size"
+        android:drawablePadding="4dip"
+        android:layout_gravity="right"
+        />
+
+    <TextView
+        android:id="@+id/status2"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentTop="true"
+        android:textAppearance="?android:attr/textAppearanceMedium"
+        android:textSize="@*android:dimen/keyguard_pattern_unlock_status_line_font_size"
+        android:drawablePadding="4dip"
+        android:layout_gravity="right"
+        android:visibility="gone"
+        />
+
     <com.android.internal.widget.LockPatternView
         android:id="@+id/lockPattern"
-        android:layout_width="match_parent"
-        android:layout_height="0dip"
-        android:layout_weight="1"
-        android:layout_marginTop="2dip"
-        android:aspect="@string/lock_pattern_view_aspect"
-         />
+        android:layout_width="300dip"
+        android:layout_height="300dip"
+        android:layout_rowWeight="1"
+        android:layout_marginTop="8dip"
+        android:layout_marginRight="8dip"
+        android:layout_marginBottom="4dip"
+        android:layout_marginLeft="8dip"
+     />
 
-    <!-- footer -->
-    <FrameLayout
+    <TextView
+        android:id="@+id/carrier"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_gravity="center_horizontal"
+        android:singleLine="true"
+        android:ellipsize="marquee"
+        android:textSize="@*android:dimen/keyguard_pattern_unlock_status_line_font_size"
+        android:textAppearance="?android:attr/textAppearanceMedium"
+    />
+
+    <!-- Footer: an emergency call button and an initially hidden "Forgot pattern" button -->
+    <LinearLayout
+        android:orientation="horizontal"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        >
+        android:layout_gravity="center">
 
-        <!-- option 1: a single emergency call button -->
-        <RelativeLayout android:id="@+id/footerNormal"
-            android:layout_width="match_parent"
-            android:layout_height="match_parent"
-            >
-            <Button android:id="@+id/emergencyCallAlone"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_centerInParent="true"
-                android:text="@string/lockscreen_emergency_call"
-                style="@style/Widget.Button.Transparent"
-                android:drawableLeft="@drawable/ic_emergency"
-                android:drawablePadding="8dip"
-                />
+        <Button android:id="@+id/emergencyCallButton"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center_horizontal"
+            style="@style/Widget.Button.Transparent"
+            android:textSize="@dimen/keyguard_pattern_unlock_status_line_font_size"
+            android:text="@string/lockscreen_emergency_call"
+            android:drawableLeft="@drawable/lockscreen_emergency_button"
+            android:drawablePadding="0dip"
+        />
 
-        </RelativeLayout>
+        <Button android:id="@+id/forgotPatternButton"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center_horizontal"
+            style="@style/Widget.Button.Transparent"
+            android:textSize="@dimen/keyguard_pattern_unlock_status_line_font_size"
+            android:text="@string/lockscreen_forgot_pattern_button_text"
+            android:drawableLeft="@drawable/lockscreen_forgot_password_button"
+            android:drawablePadding="0dip"
+        />
 
-        <!-- option 2: an emergency call button, and a 'forgot pattern?' button -->
-        <LinearLayout android:id="@+id/footerForgotPattern"
-            android:orientation="horizontal"
-            android:layout_width="match_parent"
-            android:layout_height="match_parent"
-            android:gravity="center"
-            >
-            <Button android:id="@+id/emergencyCallTogether"
-                android:layout_width="0dip"
-                android:layout_height="match_parent"
-                android:layout_weight="1.0"
-                android:layout_marginTop="4dip"
-                android:layout_marginBottom="4dip"
-                android:layout_marginLeft="4dip"
-                android:layout_marginRight="2dip"
-                android:text="@string/lockscreen_emergency_call"
-                style="@style/Widget.Button.Transparent"
-                android:drawableLeft="@drawable/ic_emergency"
-                android:drawablePadding="8dip"
-                />
-            <Button android:id="@+id/forgotPattern"
-                android:layout_width="0dip"
-                android:layout_height="match_parent"
-                android:layout_weight="1.0"
-                android:layout_marginTop="4dip"
-                android:layout_marginBottom="4dip"
-                android:layout_marginLeft="2dip"
-                android:layout_marginRight="4dip"
-                style="@style/Widget.Button.Transparent"
-                android:visibility="invisible"
-                />
-        </LinearLayout>
+    </LinearLayout>
 
-    </FrameLayout>
-
-</com.android.internal.widget.LinearLayoutWithDefaultTouchRecepient>
+</GridLayout>
diff --git a/core/res/res/layout/preference.xml b/core/res/res/layout/preference.xml
index 1f92252..448f89a 100644
--- a/core/res/res/layout/preference.xml
+++ b/core/res/res/layout/preference.xml
@@ -22,7 +22,8 @@
     android:layout_height="wrap_content"
     android:minHeight="?android:attr/listPreferredItemHeight"
     android:gravity="center_vertical"
-    android:paddingRight="?android:attr/scrollbarSize">
+    android:paddingRight="?android:attr/scrollbarSize"
+    android:background="?android:attr/selectableItemBackground" >
 
     <ImageView
         android:id="@+android:id/icon"
diff --git a/core/res/res/layout/preference_widget_seekbar.xml b/core/res/res/layout/preference_widget_seekbar.xml
new file mode 100644
index 0000000..e4cf86d
--- /dev/null
+++ b/core/res/res/layout/preference_widget_seekbar.xml
@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<!-- Layout for a Preference in a PreferenceActivity. The
+     Preference is able to place a specific widget for its particular
+     type in the "widget_frame" layout. -->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:minHeight="?android:attr/listPreferredItemHeight"
+    android:gravity="center_vertical"
+    android:paddingRight="?android:attr/scrollbarSize">
+
+    <LinearLayout
+        android:layout_width="wrap_content"
+        android:layout_height="match_parent"
+        android:gravity="center"
+        android:minWidth="@dimen/preference_icon_minWidth"
+        android:orientation="horizontal">
+        <ImageView
+            android:id="@+android:id/icon"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center"
+            android:minWidth="48dp"
+            />
+    </LinearLayout>
+
+    <RelativeLayout
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginLeft="16dip"
+        android:layout_marginRight="8dip"
+        android:layout_marginTop="6dip"
+        android:layout_marginBottom="6dip"
+        android:layout_weight="1">
+
+        <TextView android:id="@+android:id/title"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:singleLine="true"
+            android:textAppearance="?android:attr/textAppearanceMedium"
+            android:ellipsize="marquee"
+            android:fadingEdge="horizontal" />
+
+        <TextView android:id="@+android:id/summary"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_below="@android:id/title"
+            android:layout_alignLeft="@android:id/title"
+            android:textAppearance="?android:attr/textAppearanceSmall"
+            android:textColor="?android:attr/textColorSecondary"
+            android:maxLines="4" />
+
+        <!-- Preference should place its actual preference widget here. -->
+        <LinearLayout android:id="@+android:id/widget_frame"
+            android:layout_width="wrap_content"
+            android:layout_height="match_parent"
+            android:layout_below="@android:id/summary"
+            android:layout_alignLeft="@android:id/title"
+            android:minWidth="@dimen/preference_widget_width"
+            android:gravity="center"
+            android:orientation="vertical" />
+
+        <SeekBar android:id="@+android:id/seekbar"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_below="@android:id/summary"
+            android:layout_toRightOf="@android:id/widget_frame"
+            android:layout_alignParentRight="true" />
+
+    </RelativeLayout>
+
+</LinearLayout>
diff --git a/core/res/res/layout/preference_widget_switch.xml b/core/res/res/layout/preference_widget_switch.xml
new file mode 100644
index 0000000..ed4ed57
--- /dev/null
+++ b/core/res/res/layout/preference_widget_switch.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<!-- Layout used by SwitchPreference for the switch widget style. This is inflated
+     inside android.R.layout.preference. -->
+<Switch xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+android:id/switchWidget"
+    android:layout_width="wrap_content"
+    android:layout_height="wrap_content"
+    android:layout_gravity="center"
+    android:padding="16dip"
+    android:focusable="false"
+    android:clickable="false" />
diff --git a/core/res/res/layout/select_dialog_holo.xml b/core/res/res/layout/select_dialog_holo.xml
index 7c95693..06a5d96 100644
--- a/core/res/res/layout/select_dialog_holo.xml
+++ b/core/res/res/layout/select_dialog_holo.xml
@@ -27,9 +27,6 @@
     android:id="@+android:id/select_dialog_listview"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    android:layout_marginTop="5dip"
-    android:paddingLeft="16dip"
-    android:paddingRight="16dip"
     android:cacheColorHint="@null"
     android:divider="?android:attr/listDividerAlertDialog"
     android:scrollbars="vertical"
diff --git a/core/res/res/layout/select_dialog_item_holo.xml b/core/res/res/layout/select_dialog_item_holo.xml
index 396092e..0c700cf 100644
--- a/core/res/res/layout/select_dialog_item_holo.xml
+++ b/core/res/res/layout/select_dialog_item_holo.xml
@@ -26,7 +26,7 @@
     android:id="@android:id/text1"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
-    android:minHeight="?android:attr/listPreferredItemHeight"
+    android:minHeight="?android:attr/listPreferredItemHeightSmall"
     android:textAppearance="?android:attr/textAppearanceMedium"
     android:textColor="?android:attr/textColorAlertDialogListItem"
     android:gravity="center_vertical"
diff --git a/core/res/res/layout/select_dialog_multichoice_holo.xml b/core/res/res/layout/select_dialog_multichoice_holo.xml
index 8027035..683151c 100644
--- a/core/res/res/layout/select_dialog_multichoice_holo.xml
+++ b/core/res/res/layout/select_dialog_multichoice_holo.xml
@@ -18,7 +18,7 @@
     android:id="@android:id/text1"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
-    android:minHeight="?android:attr/listPreferredItemHeight"
+    android:minHeight="?android:attr/listPreferredItemHeightSmall"
     android:textAppearance="?android:attr/textAppearanceMedium"
     android:textColor="?android:attr/textColorAlertDialogListItem"
     android:gravity="center_vertical"
diff --git a/core/res/res/layout/select_dialog_singlechoice_holo.xml b/core/res/res/layout/select_dialog_singlechoice_holo.xml
index cab519f..52782d0 100644
--- a/core/res/res/layout/select_dialog_singlechoice_holo.xml
+++ b/core/res/res/layout/select_dialog_singlechoice_holo.xml
@@ -18,7 +18,7 @@
     android:id="@android:id/text1"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
-    android:minHeight="?android:attr/listPreferredItemHeight"
+    android:minHeight="?android:attr/listPreferredItemHeightSmall"
     android:textAppearance="?android:attr/textAppearanceMedium"
     android:textColor="?android:attr/textColorAlertDialogListItem"
     android:gravity="center_vertical"
diff --git a/core/res/res/layout/status_bar_latest_event_content.xml b/core/res/res/layout/status_bar_latest_event_content.xml
index 676c38b..0dc6741 100644
--- a/core/res/res/layout/status_bar_latest_event_content.xml
+++ b/core/res/res/layout/status_bar_latest_event_content.xml
@@ -1,4 +1,5 @@
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/status_bar_latest_event_content"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     >
@@ -8,41 +9,9 @@
         android:background="@drawable/notify_panel_notification_icon_bg"
         android:scaleType="center"
         />
-    <LinearLayout
-        android:layout_width="0dp"
+    <include layout="@layout/status_bar_latest_event_content_large_icon" 
+        android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:layout_gravity="center_vertical"
-        android:layout_weight="1"
-        android:orientation="vertical"
-        android:paddingLeft="16dp"
-        >
-        <TextView android:id="@+id/title"
-            android:textAppearance="@style/TextAppearance.StatusBar.EventContent.Title"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:singleLine="true"
-            android:ellipsize="marquee"
-            android:fadingEdge="horizontal"
-            android:layout_marginBottom="-3dp"
-            />
-        <TextView android:id="@+id/text"
-            android:textAppearance="@style/TextAppearance.StatusBar.EventContent"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:layout_weight="1"
-            android:layout_marginTop="-2dp"
-            android:singleLine="true"
-            android:ellipsize="marquee"
-            android:fadingEdge="horizontal"
-            />
-    </LinearLayout>
-    <TextView android:id="@+id/info"
-        android:textAppearance="@style/TextAppearance.StatusBar.EventContent.Info"
-        android:layout_width="wrap_content"
-        android:layout_height="match_parent"
-        android:singleLine="true"
-        android:gravity="center_vertical"
-        android:paddingLeft="8dp"
+        android:layout_gravity="center"
         />
 </LinearLayout>
-
diff --git a/core/res/res/layout/status_bar_latest_event_content_large_icon.xml b/core/res/res/layout/status_bar_latest_event_content_large_icon.xml
index ebdaaa3..d937392 100644
--- a/core/res/res/layout/status_bar_latest_event_content_large_icon.xml
+++ b/core/res/res/layout/status_bar_latest_event_content_large_icon.xml
@@ -1,50 +1,65 @@
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/status_bar_latest_event_content_large_icon"
     android:layout_width="match_parent"
-    android:layout_height="match_parent"
+    android:layout_height="wrap_content"
+    android:layout_gravity="center"
+    android:orientation="vertical"
+    android:paddingLeft="8dp"
+    android:paddingRight="8dp"
     >
-    <LinearLayout
-        android:layout_width="0dp"
+    <TextView android:id="@+id/title"
+        android:textAppearance="@style/TextAppearance.StatusBar.EventContent.Title"
+        android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:layout_gravity="center_vertical"
-        android:layout_weight="1"
-        android:orientation="vertical"
-        android:paddingLeft="16dp"
+        android:singleLine="true"
+        android:ellipsize="marquee"
+        android:fadingEdge="horizontal"
+        />
+    <TextView android:id="@+id/text2"
+        android:textAppearance="@style/TextAppearance.StatusBar.EventContent"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="-2dp"
+        android:layout_marginBottom="-2dp"
+        android:singleLine="true"
+        android:fadingEdge="horizontal"
+        android:ellipsize="marquee"
+        android:visibility="gone"
+        android:alpha="0.7"
+        />
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:orientation="horizontal"
+        android:alpha="0.7"
         >
-        <TextView android:id="@+id/title"
-            android:textAppearance="@style/TextAppearance.StatusBar.EventContent.Title"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:singleLine="true"
-            android:ellipsize="marquee"
-            android:fadingEdge="horizontal"
-            android:layout_marginBottom="-3dp"
-            />
         <TextView android:id="@+id/text"
             android:textAppearance="@style/TextAppearance.StatusBar.EventContent"
-            android:layout_width="match_parent"
+            android:layout_width="0dp"
             android:layout_height="wrap_content"
             android:layout_weight="1"
-            android:layout_marginTop="-2dp"
+            android:layout_gravity="center"
             android:singleLine="true"
             android:ellipsize="marquee"
             android:fadingEdge="horizontal"
             />
+        <TextView android:id="@+id/info"
+            android:textAppearance="@style/TextAppearance.StatusBar.EventContent.Info"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center"
+            android:layout_weight="0"
+            android:singleLine="true"
+            android:gravity="center"
+            android:paddingLeft="8dp"
+            />
+        <ImageView android:id="@+id/icon"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center"
+            android:layout_weight="0"
+            android:scaleType="center"
+            android:paddingLeft="8dp"
+            />
     </LinearLayout>
-    <TextView android:id="@+id/info"
-        android:textAppearance="@style/TextAppearance.StatusBar.EventContent.Info"
-        android:layout_width="wrap_content"
-        android:layout_height="match_parent"
-        android:singleLine="true"
-        android:gravity="center_vertical"
-        android:paddingLeft="4dp"
-        android:paddingRight="4dp"
-        />
-    <ImageView android:id="@+id/icon"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_gravity="bottom"
-        android:layout_marginBottom="13dip"
-        android:scaleType="center"
-        />
 </LinearLayout>
-
diff --git a/core/res/res/layout/volume_adjust.xml b/core/res/res/layout/volume_adjust.xml
index b0ca3e8..7303003 100644
--- a/core/res/res/layout/volume_adjust.xml
+++ b/core/res/res/layout/volume_adjust.xml
@@ -15,22 +15,21 @@
 -->
 
 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="wrap_content"
-    android:layout_height="wrap_content"
-    android:gravity="left">
-
+    android:layout_width="480dp"
+    android:layout_height="wrap_content">
     <LinearLayout
-        android:layout_width="wrap_content"
+        android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:layout_marginTop="80dip"
+        android:layout_marginTop="80dp"
         android:background="@android:drawable/dialog_full_holo_dark"
         android:orientation="horizontal"
         >
 
         <LinearLayout
             android:id="@+id/slider_group"
-            android:layout_width="wrap_content"
+            android:layout_width="0dp"
             android:layout_height="wrap_content"
+            android:layout_weight="1"
             android:orientation="vertical"
             >
             <!-- Sliders go here -->
@@ -56,9 +55,6 @@
             android:background="?attr/selectableItemBackground"
             android:src="@drawable/ic_sysbar_quicksettings"
             />
-        
+
     </LinearLayout>
-
-</FrameLayout>
-
-
+</FrameLayout>
\ No newline at end of file
diff --git a/core/res/res/layout/volume_adjust_item.xml b/core/res/res/layout/volume_adjust_item.xml
index e841d87..beb511d 100644
--- a/core/res/res/layout/volume_adjust_item.xml
+++ b/core/res/res/layout/volume_adjust_item.xml
@@ -15,7 +15,7 @@
 -->
 
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="wrap_content"
+    android:layout_width="match_parent"
     android:layout_height="80dip"
     android:orientation="horizontal"
     android:layout_marginTop="8dip"
@@ -34,8 +34,9 @@
     <SeekBar
         style="?android:attr/seekBarStyle"
         android:id="@+id/seekbar"
-        android:layout_width="300dip"
+        android:layout_width="300dp"
         android:layout_height="wrap_content"
+        android:layout_weight="1"
         android:padding="16dip"
         android:layout_marginLeft="8dip"
         android:layout_marginRight="8dip" />
diff --git a/core/res/res/values-af/strings.xml b/core/res/res/values-af/strings.xml
index 764ec85..cab43ac 100644
--- a/core/res/res/values-af/strings.xml
+++ b/core/res/res/values-af/strings.xml
@@ -412,6 +412,10 @@
     <!-- no translation found for permlab_setOrientation (3365947717163866844) -->
     <skip />
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"Laat \'n program toe om die skerm te enige tyd te draai. Behoort vir gewone programme nooit nodig te wees nie."</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <!-- no translation found for permlab_signalPersistentProcesses (4255467255488653854) -->
     <skip />
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"Laat program toe om te versoek dat die voorsiende materiaal aan alle aanhoudende prosesse gestuur word."</string>
@@ -1235,6 +1239,12 @@
     <skip />
     <!-- no translation found for launch_warning_original (188102023021668683) -->
     <skip />
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <!-- no translation found for smv_application (295583804361236288) -->
     <skip />
     <!-- no translation found for smv_process (5120397012047462446) -->
@@ -1540,4 +1550,6 @@
     <skip />
     <!-- no translation found for storage_usb (3017954059538517278) -->
     <skip />
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-am/strings.xml b/core/res/res/values-am/strings.xml
index 9b677c2..b97bc7a 100644
--- a/core/res/res/values-am/strings.xml
+++ b/core/res/res/values-am/strings.xml
@@ -396,6 +396,10 @@
     <!-- no translation found for permlab_setOrientation (3365947717163866844) -->
     <skip />
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"ትግበራው በማንኛውም ሰዓት የማያንማሽከርከሪያለመለወጥ ይፈቅዳል።ለመደበኛ ትግበራዎች በፍፁም አያስፈልግም።"</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <!-- no translation found for permlab_signalPersistentProcesses (4255467255488653854) -->
     <skip />
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"ትግበራዎች ለሁሉም ተከታታይ ሂደቶች ልከው የሚያቀርቧቸው ሲግናሎችን ለመጠየቅ ይፈቅዳል።"</string>
@@ -1154,6 +1158,12 @@
     <string name="launch_warning_title" msgid="8323761616052121936">"ትግበራ ተዘዋውሯል"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g> እየሄደ ነው።"</string>
     <string name="launch_warning_original" msgid="188102023021668683">"<xliff:g id="APP_NAME">%1$s</xliff:g> በዋናነት የተነሳው።"</string>
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"ትግበራው <xliff:g id="APPLICATION">%1$s</xliff:g>(<xliff:g id="PROCESS">%2$s</xliff:g> ሂደት) በራስ ተነሳሺ StrictMode ፖሊሲን ይተላለፋል።"</string>
     <string name="smv_process" msgid="5120397012047462446">"ሂደቱ <xliff:g id="PROCESS">%1$s</xliff:g> በራስ ተነሳሺ StrictMode ፖሊሲን ይተላለፋል።"</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g> አሂድ"</string>
@@ -1423,4 +1433,6 @@
     <skip />
     <!-- no translation found for storage_usb (3017954059538517278) -->
     <skip />
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-ar/strings.xml b/core/res/res/values-ar/strings.xml
index 6795348..8d5ecb8 100644
--- a/core/res/res/values-ar/strings.xml
+++ b/core/res/res/values-ar/strings.xml
@@ -265,6 +265,10 @@
     <string name="permdesc_bindDeviceAdmin" msgid="8714424333082216979">"للسماح للمالك بإرسال الأهداف إلى أحد مشرفي الجهاز. لا يجب استخدامه على الإطلاق للتطبيقات العادية."</string>
     <string name="permlab_setOrientation" msgid="3365947717163866844">"تغيير اتجاه الشاشة"</string>
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"للسماح لتطبيق ما بتغيير تدوير الشاشة في أي وقت. لا يجب استخدامه على الإطلاق للتطبيقات العادية."</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <string name="permlab_signalPersistentProcesses" msgid="4255467255488653854">"إرسال إشارات Linux للتطبيقات"</string>
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"للسماح للتطبيق بطلب إرسال الإشارة المزوّدة لجميع العمليات المستمرة."</string>
     <string name="permlab_persistentActivity" msgid="8659652042401085862">"تشغيل التطبيق دائمًا"</string>
@@ -836,6 +840,12 @@
     <string name="launch_warning_title" msgid="8323761616052121936">"تمت إعادة توجيه التطبيق"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g> قيد التشغيل الآن."</string>
     <string name="launch_warning_original" msgid="188102023021668683">"تم تشغيل <xliff:g id="APP_NAME">%1$s</xliff:g> من الأصل."</string>
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"انتهك التطبيق <xliff:g id="APPLICATION">%1$s</xliff:g> (العملية <xliff:g id="PROCESS">%2$s</xliff:g>) سياسة.StrictMode المفروضة ذاتيًا."</string>
     <string name="smv_process" msgid="5120397012047462446">"انتهكت العملية <xliff:g id="PROCESS">%1$s</xliff:g> سياسة StrictMode المفروضة ذاتيًا."</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g> يعمل"</string>
@@ -1041,4 +1051,6 @@
     <string name="storage_internal" msgid="7556050805474115618">"وحدة التخزين الداخلية"</string>
     <string name="storage_sd_card" msgid="8921771478629812343">"بطاقة SD"</string>
     <string name="storage_usb" msgid="3017954059538517278">"وحدة تخزين USB"</string>
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-bg/strings.xml b/core/res/res/values-bg/strings.xml
index 4710226..b43b50f 100644
--- a/core/res/res/values-bg/strings.xml
+++ b/core/res/res/values-bg/strings.xml
@@ -265,6 +265,10 @@
     <string name="permdesc_bindDeviceAdmin" msgid="8714424333082216979">"Разрешава на притежателя да изпраща намерения до администратор на устройството. Нормалните приложения би трябвало никога да не се нуждаят от това."</string>
     <string name="permlab_setOrientation" msgid="3365947717163866844">"промяна на ориентацията на екрана"</string>
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"Разрешава на приложението да променя ориентацията на екрана по всяко време. Нормалните приложения би трябвало никога да не се нуждаят от това."</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <string name="permlab_signalPersistentProcesses" msgid="4255467255488653854">"изпращане на сигнали от Linux до приложенията"</string>
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"Разрешава на приложението да подаде заявка предоставеният сигнал да се изпрати до всички постоянни процеси."</string>
     <string name="permlab_persistentActivity" msgid="8659652042401085862">"задаване на постоянно изпълнение на приложението"</string>
@@ -836,6 +840,12 @@
     <string name="launch_warning_title" msgid="8323761616052121936">"Приложението се пренасочи"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g> се изпълнява."</string>
     <string name="launch_warning_original" msgid="188102023021668683">"Първоначално бе стартирано: <xliff:g id="APP_NAME">%1$s</xliff:g>."</string>
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"Приложението <xliff:g id="APPLICATION">%1$s</xliff:g> (процес <xliff:g id="PROCESS">%2$s</xliff:g>) наруши правилото за стриктен режим, наложено от самото него."</string>
     <string name="smv_process" msgid="5120397012047462446">"Процесът <xliff:g id="PROCESS">%1$s</xliff:g> наруши правилото за стриктен режим, наложено от самия него."</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g> се изпълнява"</string>
@@ -1041,4 +1051,6 @@
     <string name="storage_internal" msgid="7556050805474115618">"Вътрешно хранилище"</string>
     <string name="storage_sd_card" msgid="8921771478629812343">"SD карта"</string>
     <string name="storage_usb" msgid="3017954059538517278">"USB хранилище"</string>
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-ca/strings.xml b/core/res/res/values-ca/strings.xml
index e2aec56..2947b93 100644
--- a/core/res/res/values-ca/strings.xml
+++ b/core/res/res/values-ca/strings.xml
@@ -265,6 +265,10 @@
     <string name="permdesc_bindDeviceAdmin" msgid="8714424333082216979">"Permet al titular enviar intencions a un administrador del sistema. No s\'hauria de necessitar mai per a les aplicacions normals."</string>
     <string name="permlab_setOrientation" msgid="3365947717163866844">"canviar l\'orientació de la pantalla"</string>
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"Permet a una aplicació canviar el gir de la pantalla en qualsevol moment. No s\'hauria de necessitar mai per a les aplicacions normals."</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <string name="permlab_signalPersistentProcesses" msgid="4255467255488653854">"enviar senyals Linux a les aplicacions"</string>
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"Permet a l\'aplicació sol·licitar que el senyal subministrat s\'enviï a tots els processos persistents."</string>
     <string name="permlab_persistentActivity" msgid="8659652042401085862">"fer que l\'aplicació s\'executi sempre"</string>
@@ -836,6 +840,12 @@
     <string name="launch_warning_title" msgid="8323761616052121936">"Aplicació redirigida"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g> s\'està executant."</string>
     <string name="launch_warning_original" msgid="188102023021668683">"<xliff:g id="APP_NAME">%1$s</xliff:g> es va iniciar originalment."</string>
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"L\'aplicació <xliff:g id="APPLICATION">%1$s</xliff:g> (procés <xliff:g id="PROCESS">%2$s</xliff:g>) ha incomplert la seva política autoimposada de mode estricte."</string>
     <string name="smv_process" msgid="5120397012047462446">"El procés <xliff:g id="PROCESS">%1$s</xliff:g> ha incomplert la seva política de mode estricte."</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g> s\'està executant"</string>
@@ -1041,4 +1051,6 @@
     <string name="storage_internal" msgid="7556050805474115618">"Emmagatzematge intern"</string>
     <string name="storage_sd_card" msgid="8921771478629812343">"Targeta SD"</string>
     <string name="storage_usb" msgid="3017954059538517278">"Emmagatzematge USB"</string>
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-cs/strings.xml b/core/res/res/values-cs/strings.xml
index 7f92410..92deaca 100644
--- a/core/res/res/values-cs/strings.xml
+++ b/core/res/res/values-cs/strings.xml
@@ -265,6 +265,10 @@
     <string name="permdesc_bindDeviceAdmin" msgid="8714424333082216979">"Umožňuje držiteli oprávnění odesílat informace správci zařízení. Běžné aplikace by toto oprávnění nikdy neměly požadovat."</string>
     <string name="permlab_setOrientation" msgid="3365947717163866844">"změna orientace obrazovky"</string>
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"Umožňuje aplikaci kdykoli změnit orientaci obrazovky. Běžné aplikace by toto nastavení nikdy neměly využívat."</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <string name="permlab_signalPersistentProcesses" msgid="4255467255488653854">"odeslání signálů Linux aplikacím"</string>
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"Umožňuje aplikaci vyžádat zaslání poskytnutého signálu všem trvalým procesům."</string>
     <string name="permlab_persistentActivity" msgid="8659652042401085862">"trvalé spuštění aplikace"</string>
@@ -836,6 +840,12 @@
     <string name="launch_warning_title" msgid="8323761616052121936">"Aplikace přesměrována"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"Je spuštěna aplikace <xliff:g id="APP_NAME">%1$s</xliff:g>."</string>
     <string name="launch_warning_original" msgid="188102023021668683">"Původně byla spuštěna aplikace <xliff:g id="APP_NAME">%1$s</xliff:g>."</string>
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"Aplikace <xliff:g id="APPLICATION">%1$s</xliff:g> (proces <xliff:g id="PROCESS">%2$s</xliff:g>) porušila své vlastní vynucené zásady StrictMode."</string>
     <string name="smv_process" msgid="5120397012047462446">"Proces <xliff:g id="PROCESS">%1$s</xliff:g> porušil své vlastní vynucené zásady StrictMode."</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"Běží aplikace <xliff:g id="APP">%1$s</xliff:g>"</string>
@@ -1041,4 +1051,6 @@
     <string name="storage_internal" msgid="7556050805474115618">"Interní úložiště"</string>
     <string name="storage_sd_card" msgid="8921771478629812343">"Karta SD"</string>
     <string name="storage_usb" msgid="3017954059538517278">"Úložiště USB"</string>
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-da/strings.xml b/core/res/res/values-da/strings.xml
index 7b05a0e..a3149a2 100644
--- a/core/res/res/values-da/strings.xml
+++ b/core/res/res/values-da/strings.xml
@@ -265,6 +265,10 @@
     <string name="permdesc_bindDeviceAdmin" msgid="8714424333082216979">"Tillader brugeren at sende hensigter til en enhedsadministrator. Bør aldrig være nødvendigt for almindelige programmer."</string>
     <string name="permlab_setOrientation" msgid="3365947717163866844">"skift skærmretning"</string>
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"Tillader, at et program ændrer rotationen af skærmen når som helst. Bør aldrig være nødvendigt til normale programmer."</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <string name="permlab_signalPersistentProcesses" msgid="4255467255488653854">"send Linux-signaler til programmer"</string>
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"Tillader, at programmet kan anmode om, at det leverede signal sendes til alle vedholdende processer."</string>
     <string name="permlab_persistentActivity" msgid="8659652042401085862">"lad altid programmet køre"</string>
@@ -836,6 +840,12 @@
     <string name="launch_warning_title" msgid="8323761616052121936">"Programmet er omdirigeret"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g> kører nu."</string>
     <string name="launch_warning_original" msgid="188102023021668683">"<xliff:g id="APP_NAME">%1$s</xliff:g> blev oprindeligt åbnet."</string>
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"Programmet <xliff:g id="APPLICATION">%1$s</xliff:g> (proces <xliff:g id="PROCESS">%2$s</xliff:g>) har overtrådt sin egen StrictMode-politik."</string>
     <string name="smv_process" msgid="5120397012047462446">"Processen <xliff:g id="PROCESS">%1$s</xliff:g> har overtrådt sin egen StrictMode-politik."</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g> er i gang"</string>
@@ -1041,4 +1051,6 @@
     <string name="storage_internal" msgid="7556050805474115618">"Internt lager"</string>
     <string name="storage_sd_card" msgid="8921771478629812343">"SD-kort"</string>
     <string name="storage_usb" msgid="3017954059538517278">"USB-lager"</string>
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-de/donottranslate-cldr.xml b/core/res/res/values-de/donottranslate-cldr.xml
index fffcf26..6b4bf5c 100644
--- a/core/res/res/values-de/donottranslate-cldr.xml
+++ b/core/res/res/values-de/donottranslate-cldr.xml
@@ -31,7 +31,7 @@
     <string name="month_medium_february">Feb.</string>
     <string name="month_medium_march">Mär.</string>
     <string name="month_medium_april">Apr.</string>
-    <string name="month_medium_may">Mai.</string>
+    <string name="month_medium_may">Mai</string>
     <string name="month_medium_june">Jun.</string>
     <string name="month_medium_july">Jul.</string>
     <string name="month_medium_august">Aug.</string>
diff --git a/core/res/res/values-de/strings.xml b/core/res/res/values-de/strings.xml
index 38c8f6c..b6b6be5 100644
--- a/core/res/res/values-de/strings.xml
+++ b/core/res/res/values-de/strings.xml
@@ -265,6 +265,10 @@
     <string name="permdesc_bindDeviceAdmin" msgid="8714424333082216979">"Ermöglicht dem Halter, Intents an einen Geräteadministrator zu senden. Sollte nie für normale Anwendungen benötigt werden."</string>
     <string name="permlab_setOrientation" msgid="3365947717163866844">"Bildschirmausrichtung ändern"</string>
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"Ermöglicht der Anwendung, die Bildschirmdrehung jederzeit zu ändern. Sollte nicht für normale Anwendungen benötigt werden."</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <string name="permlab_signalPersistentProcesses" msgid="4255467255488653854">"Linux-Signale an Anwendungen senden"</string>
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"Ermöglicht der Anwendung, das Senden des gelieferten Signals an alle anhaltenden Prozesse zu fordern"</string>
     <string name="permlab_persistentActivity" msgid="8659652042401085862">"Anwendungen permanent ausführen"</string>
@@ -836,6 +840,12 @@
     <string name="launch_warning_title" msgid="8323761616052121936">"Anwendung umgeleitet"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g> wird jetzt ausgeführt."</string>
     <string name="launch_warning_original" msgid="188102023021668683">"<xliff:g id="APP_NAME">%1$s</xliff:g> wurde ursprünglich gestartet."</string>
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"Die Anwendung <xliff:g id="APPLICATION">%1$s</xliff:g> (Prozess <xliff:g id="PROCESS">%2$s</xliff:g>) hat gegen ihre selbsterzwungene StrictMode-Richtlinie verstoßen."</string>
     <string name="smv_process" msgid="5120397012047462446">"Der Prozess <xliff:g id="PROCESS">%1$s</xliff:g> hat gegen seine selbsterzwungene StrictMode-Richtlinie verstoßen."</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g> läuft"</string>
@@ -1041,4 +1051,6 @@
     <string name="storage_internal" msgid="7556050805474115618">"Interner Speicher"</string>
     <string name="storage_sd_card" msgid="8921771478629812343">"SD-Karte"</string>
     <string name="storage_usb" msgid="3017954059538517278">"USB-Speicher"</string>
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-el/strings.xml b/core/res/res/values-el/strings.xml
index 017be9b..a5e13f1 100644
--- a/core/res/res/values-el/strings.xml
+++ b/core/res/res/values-el/strings.xml
@@ -265,6 +265,10 @@
     <string name="permdesc_bindDeviceAdmin" msgid="8714424333082216979">"Επιτρέπει στον κάτοχο την αποστολή στόχων σε έναν διαχειριστή συσκευής. Δεν θα χρειαστεί ποτέ για κανονικές εφαρμογές."</string>
     <string name="permlab_setOrientation" msgid="3365947717163866844">"αλλαγή προσανατολισμού οθόνης"</string>
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"Επιτρέπει σε μια εφαρμογή την αλλαγή της περιστροφής της οθόνης οποιαδήποτε στιγμή. Δεν είναι απαραίτητο για κανονικές εφαρμογές."</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <string name="permlab_signalPersistentProcesses" msgid="4255467255488653854">"αποστολή σημάτων Linux σε εφαρμογές"</string>
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"Επιτρέπει σε μια εφαρμογή την αποστολή αιτήματος για την αποστολή του παρεχόμενου σήματος σε όλες τις υπάρχουσες διαδικασίες."</string>
     <string name="permlab_persistentActivity" msgid="8659652042401085862">"η εφαρμογή να εκτελείται συνεχώς"</string>
@@ -836,6 +840,12 @@
     <string name="launch_warning_title" msgid="8323761616052121936">"Ανακατεύθυνση εφαρμογής"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"Η εφαρμογή <xliff:g id="APP_NAME">%1$s</xliff:g> εκτελείται τώρα."</string>
     <string name="launch_warning_original" msgid="188102023021668683">"Έγινε εκκίνηση πρώτα της εφαρμογής <xliff:g id="APP_NAME">%1$s</xliff:g>."</string>
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"Η εφαρμογή <xliff:g id="APPLICATION">%1$s</xliff:g> (διεργασία <xliff:g id="PROCESS">%2$s</xliff:g>) παραβίασε την αυτοεπιβαλόμενη πολιτική StrictMode."</string>
     <string name="smv_process" msgid="5120397012047462446">"Η διεργασία <xliff:g id="PROCESS">%1$s</xliff:g> παραβίασε την αυτοεπιβαλόμενη πολιτική StrictMode."</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"Η εφαρμογή <xliff:g id="APP">%1$s</xliff:g> εκτελείται"</string>
@@ -1041,4 +1051,6 @@
     <string name="storage_internal" msgid="7556050805474115618">"Εσωτερικός χώρος αποθήκευσης"</string>
     <string name="storage_sd_card" msgid="8921771478629812343">"Κάρτα SD"</string>
     <string name="storage_usb" msgid="3017954059538517278">"Χώρος αποθήκευσης USB"</string>
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-en-rGB/strings.xml b/core/res/res/values-en-rGB/strings.xml
index abf18f1..d5ef98b 100644
--- a/core/res/res/values-en-rGB/strings.xml
+++ b/core/res/res/values-en-rGB/strings.xml
@@ -265,6 +265,10 @@
     <string name="permdesc_bindDeviceAdmin" msgid="8714424333082216979">"Allows the holder to send intents to a device administrator. Should never be needed for normal applications."</string>
     <string name="permlab_setOrientation" msgid="3365947717163866844">"change screen orientation"</string>
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"Allows an application to change the rotation of the screen at any time. Should never be needed for normal applications."</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <string name="permlab_signalPersistentProcesses" msgid="4255467255488653854">"send Linux signals to applications"</string>
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"Allows application to request that the supplied signal be sent to all persistent processes."</string>
     <string name="permlab_persistentActivity" msgid="8659652042401085862">"make application always run"</string>
@@ -836,6 +840,12 @@
     <string name="launch_warning_title" msgid="8323761616052121936">"Application redirected"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g> is now running."</string>
     <string name="launch_warning_original" msgid="188102023021668683">"<xliff:g id="APP_NAME">%1$s</xliff:g> was originally launched."</string>
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"The application <xliff:g id="APPLICATION">%1$s</xliff:g> (process <xliff:g id="PROCESS">%2$s</xliff:g>) has violated its self-enforced StrictMode policy."</string>
     <string name="smv_process" msgid="5120397012047462446">"The process <xliff:g id="PROCESS">%1$s</xliff:g> has violated its self-enforced StrictMode policy."</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g> running"</string>
@@ -1041,4 +1051,6 @@
     <string name="storage_internal" msgid="7556050805474115618">"Internal Storage"</string>
     <string name="storage_sd_card" msgid="8921771478629812343">"SD Card"</string>
     <string name="storage_usb" msgid="3017954059538517278">"USB storage"</string>
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-es-rUS/strings.xml b/core/res/res/values-es-rUS/strings.xml
index 178e076..3cb61e4 100644
--- a/core/res/res/values-es-rUS/strings.xml
+++ b/core/res/res/values-es-rUS/strings.xml
@@ -265,6 +265,10 @@
     <string name="permdesc_bindDeviceAdmin" msgid="8714424333082216979">"Permite que el propietario envíe sus intentos a un administrador de dispositivos. No se necesita para las aplicaciones normales."</string>
     <string name="permlab_setOrientation" msgid="3365947717163866844">"cambiar la orientación de la pantalla"</string>
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"Admite una aplicación que cambia la rotación de la pantalla en cualquier momento. Se debe evitar utilizarlo en aplicaciones normales."</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <string name="permlab_signalPersistentProcesses" msgid="4255467255488653854">"enviar señales de Linux a las aplicaciones"</string>
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"Admite que la aplicación solicite el envío de la señal suministrada a todos los procesos continuos."</string>
     <string name="permlab_persistentActivity" msgid="8659652042401085862">"hacer que siempre se ejecute la aplicación"</string>
@@ -836,6 +840,12 @@
     <string name="launch_warning_title" msgid="8323761616052121936">"Se redirigió la aplicación"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g> se está ejecutando ahora."</string>
     <string name="launch_warning_original" msgid="188102023021668683">"<xliff:g id="APP_NAME">%1$s</xliff:g> se inició originalmente."</string>
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"La aplicación <xliff:g id="APPLICATION">%1$s</xliff:g> (proceso <xliff:g id="PROCESS">%2$s</xliff:g>) ha violado su política StrictMode autoimpuesta."</string>
     <string name="smv_process" msgid="5120397012047462446">"El proceso <xliff:g id="PROCESS">%1$s</xliff:g> ha violado su política StrictMode autoimpuesta."</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g> en ejecución"</string>
@@ -1041,4 +1051,6 @@
     <string name="storage_internal" msgid="7556050805474115618">"Almacenamiento interno"</string>
     <string name="storage_sd_card" msgid="8921771478629812343">"Tarjeta SD"</string>
     <string name="storage_usb" msgid="3017954059538517278">"Almacenamiento USB"</string>
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-es/strings.xml b/core/res/res/values-es/strings.xml
index 968a3be..9db80ca 100644
--- a/core/res/res/values-es/strings.xml
+++ b/core/res/res/values-es/strings.xml
@@ -241,7 +241,7 @@
     <string name="permlab_backup" msgid="470013022865453920">"controlar las copias de seguridad y las restauraciones del sistema"</string>
     <string name="permdesc_backup" msgid="4837493065154256525">"Permite que la aplicación controle el mecanismo de copia de seguridad y restauración del sistema. Este permiso no está destinado a aplicaciones normales."</string>
     <string name="permlab_confirm_full_backup" msgid="5557071325804469102">"confirmar restauración o copia de seguridad completa"</string>
-    <string name="permdesc_confirm_full_backup" msgid="9005017754175897954">"Permite que la aplicación inicie la interfaz de usuario de confirmación de copia de seguridad completa (ninguna aplicación debe utilizarla)."</string>
+    <string name="permdesc_confirm_full_backup" msgid="9005017754175897954">"Permite que la aplicación inicie la interfaz de usuario de confirmación de copia de seguridad completa (ninguna aplicación debería utilizarla)."</string>
     <string name="permlab_internalSystemWindow" msgid="2148563628140193231">"mostrar ventanas no autorizadas"</string>
     <string name="permdesc_internalSystemWindow" msgid="5895082268284998469">"Permite la creación de ventanas destinadas al uso por parte de la interfaz de usuario interna del sistema. No está destinado al uso por parte de aplicaciones normales."</string>
     <string name="permlab_systemAlertWindow" msgid="3372321942941168324">"mostrar alertas de nivel del sistema"</string>
@@ -265,6 +265,10 @@
     <string name="permdesc_bindDeviceAdmin" msgid="8714424333082216979">"Permite enviar intentos a un administrador de dispositivos. Este permiso nunca debería ser necesario para las aplicaciones normales."</string>
     <string name="permlab_setOrientation" msgid="3365947717163866844">"cambiar orientación de la pantalla"</string>
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"Permite que una aplicación cambie la rotación de la pantalla en cualquier momento. No debería ser necesario nunca para las aplicaciones normales."</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <string name="permlab_signalPersistentProcesses" msgid="4255467255488653854">"enviar señales Linux a aplicaciones"</string>
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"Permite que la aplicación solicite que la señal suministrada se envíe a todos los procesos persistentes."</string>
     <string name="permlab_persistentActivity" msgid="8659652042401085862">"hacer que la aplicación se ejecute siempre"</string>
@@ -836,6 +840,12 @@
     <string name="launch_warning_title" msgid="8323761616052121936">"Aplicación redireccionada"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g> se está ejecutando."</string>
     <string name="launch_warning_original" msgid="188102023021668683">"Inicialmente, se inició la aplicación <xliff:g id="APP_NAME">%1$s</xliff:g>."</string>
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"La aplicación <xliff:g id="APPLICATION">%1$s</xliff:g> (proceso <xliff:g id="PROCESS">%2$s</xliff:g>) ha infringido su política StrictMode autoaplicable."</string>
     <string name="smv_process" msgid="5120397012047462446">"El proceso <xliff:g id="PROCESS">%1$s</xliff:g> ha infringido su política StrictMode autoaplicable."</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g> en ejecución"</string>
@@ -1041,4 +1051,6 @@
     <string name="storage_internal" msgid="7556050805474115618">"Almacenamiento interno"</string>
     <string name="storage_sd_card" msgid="8921771478629812343">"Tarjeta SD"</string>
     <string name="storage_usb" msgid="3017954059538517278">"Almacenamiento USB"</string>
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-fa/strings.xml b/core/res/res/values-fa/strings.xml
index df748cd..3fcb21d 100644
--- a/core/res/res/values-fa/strings.xml
+++ b/core/res/res/values-fa/strings.xml
@@ -265,6 +265,10 @@
     <string name="permdesc_bindDeviceAdmin" msgid="8714424333082216979">"به نگهدارنده اجازه می دهد مفاد را به یک سرپرست دستگاه ارسال کند. هرگز برای برنامه های معمولی مورد نیاز نیست."</string>
     <string name="permlab_setOrientation" msgid="3365947717163866844">"تغییر جهت صفحه"</string>
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"به یک برنامه کاربردی اجازه می دهد چرخش صفحه را در هر زمانی تغییر دهد. هرگز برای برنامه های معمولی مورد نیاز نیست."</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <string name="permlab_signalPersistentProcesses" msgid="4255467255488653854">"ارسال سیگنال های Linux برای برنامه ها"</string>
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"به برنامه کاربردی اجازه می دهد درخواست کند که سیگنال ارائه شده را به تمام فرایندهای ثابت ارسال کند."</string>
     <string name="permlab_persistentActivity" msgid="8659652042401085862">"برنامه همیشه اجرا شود"</string>
@@ -836,6 +840,12 @@
     <string name="launch_warning_title" msgid="8323761616052121936">"برنامه هدایت مجدد شد"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g> اکنون در حال اجرا است."</string>
     <string name="launch_warning_original" msgid="188102023021668683">"<xliff:g id="APP_NAME">%1$s</xliff:g> از ابتدا راه اندازی شد."</string>
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"برنامه <xliff:g id="APPLICATION">%1$s</xliff:g> (پردازش <xliff:g id="PROCESS">%2$s</xliff:g>) خط مشی StrictMode اجرای خودکار را نقض کرده است."</string>
     <string name="smv_process" msgid="5120397012047462446">"فرآیند <xliff:g id="PROCESS">%1$s</xliff:g> خط مشی StrictMode اجرای خودکار خود را نقض کرده است."</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g> در حال اجرا"</string>
@@ -1041,4 +1051,6 @@
     <string name="storage_internal" msgid="7556050805474115618">"حافظه داخلی"</string>
     <string name="storage_sd_card" msgid="8921771478629812343">"کارت SD"</string>
     <string name="storage_usb" msgid="3017954059538517278">"حافظه USB"</string>
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-fi/strings.xml b/core/res/res/values-fi/strings.xml
index 6b06197..70e5ff7 100644
--- a/core/res/res/values-fi/strings.xml
+++ b/core/res/res/values-fi/strings.xml
@@ -265,6 +265,10 @@
     <string name="permdesc_bindDeviceAdmin" msgid="8714424333082216979">"Antaa sovelluksen lähettää kyselyitä laitteen järjestelmänvalvojalle. Ei tavallisten sovelluksien käyttöön."</string>
     <string name="permlab_setOrientation" msgid="3365947717163866844">"muuta näytön suuntaa"</string>
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"Antaa sovelluksen vaihtaa näytön suuntaa milloin tahansa. Ei tavallisten sovelluksien käyttöön."</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <string name="permlab_signalPersistentProcesses" msgid="4255467255488653854">"lähettää sovelluksiin Linux-signaaleja"</string>
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"Antaa sovelluksen pyytää, että signaali lähetetään kaikille kiinteille prosesseille."</string>
     <string name="permlab_persistentActivity" msgid="8659652042401085862">"aseta sovellus olemaan jatkuvasti käynnissä"</string>
@@ -836,6 +840,12 @@
     <string name="launch_warning_title" msgid="8323761616052121936">"Sovellus uudelleenohjasi"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g> on nyt käynnissä."</string>
     <string name="launch_warning_original" msgid="188102023021668683">"<xliff:g id="APP_NAME">%1$s</xliff:g> käynnistettiin alun perin."</string>
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"Sovellus <xliff:g id="APPLICATION">%1$s</xliff:g> (prosessi <xliff:g id="PROCESS">%2$s</xliff:g>) on rikkonut itse käyttöön ottamaansa StrictMode-käytäntöä."</string>
     <string name="smv_process" msgid="5120397012047462446">"Prosessi <xliff:g id="PROCESS">%1$s</xliff:g> on rikkonut itse käyttöön ottamaansa StrictMode-käytäntöä."</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g> käynnissä"</string>
@@ -1041,4 +1051,6 @@
     <string name="storage_internal" msgid="7556050805474115618">"Sisäinen tallennustila"</string>
     <string name="storage_sd_card" msgid="8921771478629812343">"SD-kortti"</string>
     <string name="storage_usb" msgid="3017954059538517278">"USB-tallennustila"</string>
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-fr/strings.xml b/core/res/res/values-fr/strings.xml
index 7b2f9c0..c618edf 100644
--- a/core/res/res/values-fr/strings.xml
+++ b/core/res/res/values-fr/strings.xml
@@ -241,7 +241,7 @@
     <string name="permlab_backup" msgid="470013022865453920">"contrôler la sauvegarde et la restauration du système"</string>
     <string name="permdesc_backup" msgid="4837493065154256525">"Autorise l\'application à contrôler le mécanisme de sauvegarde et de restauration du système. Ne pas utiliser pour les applications standard."</string>
     <string name="permlab_confirm_full_backup" msgid="5557071325804469102">"confirmer une sauvegarde complète ou une restauration"</string>
-    <string name="permdesc_confirm_full_backup" msgid="9005017754175897954">"Permet à l\'application de lancer l\'interface utilisateur de confirmation de la sauvegarde complète. Seules certaines applications peuvent bénéficier de cette permission."</string>
+    <string name="permdesc_confirm_full_backup" msgid="9005017754175897954">"Permet à l\'application de lancer l\'interface de confirmation de sauvegarde complète. Seules certaines applications peuvent bénéficier de cette permission."</string>
     <string name="permlab_internalSystemWindow" msgid="2148563628140193231">"Affichage de fenêtres non autorisées"</string>
     <string name="permdesc_internalSystemWindow" msgid="5895082268284998469">"Permet de créer des fenêtres conçues pour l\'interface utilisateur du système interne. Les applications normales n\'utilisent pas cette fonctionnalité."</string>
     <string name="permlab_systemAlertWindow" msgid="3372321942941168324">"Affichage d\'alertes système"</string>
@@ -265,6 +265,10 @@
     <string name="permdesc_bindDeviceAdmin" msgid="8714424333082216979">"Permet à l\'application d\'envoyer des intentions à l\'administrateur de l\'appareil. Les applications standard ne devraient jamais avoir recours à cette fonctionnalité."</string>
     <string name="permlab_setOrientation" msgid="3365947717163866844">"Changement d\'orientation de l\'écran"</string>
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"Permet à une application de modifier la rotation de l\'écran à tout moment. Les applications normales ne devraient jamais avoir recours à cette fonctionnalité."</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <string name="permlab_signalPersistentProcesses" msgid="4255467255488653854">"Envoi de signaux Linux aux applications"</string>
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"Permet à une application de demander que le signal fourni soit envoyé à tous les processus persistants."</string>
     <string name="permlab_persistentActivity" msgid="8659652042401085862">"Exécution de l\'application en continu"</string>
@@ -449,7 +453,7 @@
     <string name="permlab_nfc" msgid="4423351274757876953">"contrôler la communication en champ proche"</string>
     <string name="permdesc_nfc" msgid="9171401851954407226">"Permet à une application de communiquer avec des tags, cartes et lecteurs prenant en charge la communication en champ proche (NFC)."</string>
     <string name="permlab_vpn" msgid="8345800584532175312">"intercepter et modifier l\'ensemble du trafic réseau"</string>
-    <string name="permdesc_vpn" msgid="5617893078989944219">"Permet à une application d\'intercepter et d\'inspecter l\'ensemble du trafic réseau, par exemple pour établir une connexion VPN. Des applications malveillantes sont susceptibles de surveiller, rediriger ou modifier les paquets réseau à votre insu."</string>
+    <string name="permdesc_vpn" msgid="5617893078989944219">"Permet à une application d\'intercepter et de contrôler l\'ensemble du trafic réseau, par exemple pour établir une connexion VPN. Des applications malveillantes sont susceptibles de surveiller, rediriger ou modifier les paquets réseau à votre insu."</string>
     <string name="permlab_disableKeyguard" msgid="4977406164311535092">"Désactivation du verrouillage des touches"</string>
     <string name="permdesc_disableKeyguard" msgid="3189763479326302017">"Permet à une application de désactiver le verrouillage des touches et toute sécurité par mot de passe. Exemple : Votre téléphone désactive le verrouillage du clavier lorsque vous recevez un appel, puis le réactive lorsque vous raccrochez."</string>
     <string name="permlab_readSyncSettings" msgid="6201810008230503052">"Lecture des paramètres de synchronisation"</string>
@@ -492,8 +496,8 @@
     <string name="policydesc_setGlobalProxy" msgid="6387497466660154931">"Indiquer le proxy global à utiliser pour ce mobile lorsque les règles sont activées. Seul l\'administrateur principal du mobile peut définir le proxy global utilisé."</string>
     <string name="policylab_expirePassword" msgid="885279151847254056">"Définir exp. mot passe verr."</string>
     <string name="policydesc_expirePassword" msgid="4844430354224822074">"Contrôler la fréquence de modification du mot de passe de verrouillage de l\'écran"</string>
-    <string name="policylab_encryptedStorage" msgid="8901326199909132915">"Définir cryptage du stockage"</string>
-    <string name="policydesc_encryptedStorage" msgid="2504984732631479399">"Exiger que les données d\'application stockées soient cryptées"</string>
+    <string name="policylab_encryptedStorage" msgid="8901326199909132915">"Définir chiffrement du stockage"</string>
+    <string name="policydesc_encryptedStorage" msgid="2504984732631479399">"Exiger que les données d\'application stockées soient chiffrées"</string>
   <string-array name="phoneTypes">
     <item msgid="8901098336658710359">"Domicile"</item>
     <item msgid="869923650527136615">"Mobile"</item>
@@ -836,6 +840,12 @@
     <string name="launch_warning_title" msgid="8323761616052121936">"Application redirigée"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g> est maintenant lancée."</string>
     <string name="launch_warning_original" msgid="188102023021668683">"Application lancée initialement : <xliff:g id="APP_NAME">%1$s</xliff:g>."</string>
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"L\'application <xliff:g id="APPLICATION">%1$s</xliff:g> (processus <xliff:g id="PROCESS">%2$s</xliff:g>) a enfreint ses propres règles du mode strict."</string>
     <string name="smv_process" msgid="5120397012047462446">"Le processus <xliff:g id="PROCESS">%1$s</xliff:g> a enfreint ses propres règles du mode strict."</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g> en cours d\'exécution"</string>
@@ -1041,4 +1051,6 @@
     <string name="storage_internal" msgid="7556050805474115618">"Mémoire de stockage interne"</string>
     <string name="storage_sd_card" msgid="8921771478629812343">"Carte SD"</string>
     <string name="storage_usb" msgid="3017954059538517278">"Mémoire de stockage USB"</string>
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-h720dp/dimens.xml b/core/res/res/values-h720dp/dimens.xml
index c09cb5b..37dee8e 100644
--- a/core/res/res/values-h720dp/dimens.xml
+++ b/core/res/res/values-h720dp/dimens.xml
@@ -17,8 +17,6 @@
 */
 -->
 <resources>
-    <!-- Dialog title height -->
-    <dimen name="alert_dialog_title_height">54dip</dimen>
     <!-- Dialog button bar height -->
     <dimen name="alert_dialog_button_bar_height">54dip</dimen>
     <!-- Preference fragment padding, bottom -->
diff --git a/core/res/res/values-hr/strings.xml b/core/res/res/values-hr/strings.xml
index 9a3eb0e..b87e99e 100644
--- a/core/res/res/values-hr/strings.xml
+++ b/core/res/res/values-hr/strings.xml
@@ -190,6 +190,8 @@
     <string name="permdesc_receiveSms" msgid="6298292335965966117">"Aplikaciji omogućuje primanje i obradu SMS poruka. Zlonamjerne aplikacije mogu pratiti vaše poruke ili ih izbrisati prije nego što ih vi vidite."</string>
     <string name="permlab_receiveMms" msgid="8894700916188083287">"primanje MMS-a"</string>
     <string name="permdesc_receiveMms" msgid="4563346832000174373">"Aplikaciji omogućuje primanje i obradu MMS poruka. Zlonamjerne aplikacije mogu pratiti vaše poruke ili ih izbrisati prije nego što ih vi vidite."</string>
+    <string name="permlab_receiveEmergencyBroadcast" msgid="1803477660846288089">"primanje hitnih odašiljanja"</string>
+    <string name="permdesc_receiveEmergencyBroadcast" msgid="7118393393716546131">"Omogućuje aplikaciji primanje i obradu poruka hitnih odašiljanja. Ta je dozvola dostupna samo aplikacijama sustava."</string>
     <string name="permlab_sendSms" msgid="5600830612147671529">"slanje SMS poruka"</string>
     <string name="permdesc_sendSms" msgid="1946540351763502120">"Aplikaciji omogućuje slanje SMS poruka. Zlonamjerne aplikacije mogu stvarati troškove slanjem poruka bez vaše potvrde."</string>
     <string name="permlab_readSms" msgid="4085333708122372256">"čitanje SMS-a ili MMS-a"</string>
@@ -240,7 +242,7 @@
     <string name="permdesc_batteryStats" msgid="5847319823772230560">"Omogućuje izmjenu prikupljene statistike o bateriji. Nije za upotrebu na uobičajenim aplikacijama."</string>
     <string name="permlab_backup" msgid="470013022865453920">"sigurnosna kopija i oporavak nadzornog sustava"</string>
     <string name="permdesc_backup" msgid="4837493065154256525">"Aplikaciji omogućuje nadzor nad mehanizmom stvaranja sigurnosnih kopija i oporavka sustava. Nije za upotrebu na uobičajenim aplikacijama."</string>
-    <string name="permlab_confirm_full_backup" msgid="5557071325804469102">"potvrditi potpunu sigurnosnu kopiju ili vratiti rad"</string>
+    <string name="permlab_confirm_full_backup" msgid="5557071325804469102">"potvrditi postupak izrade sigurnosne kopije ili obnove"</string>
     <string name="permdesc_confirm_full_backup" msgid="9005017754175897954">"Omogućuje aplikaciji pokretanje korisničkog sučelja za potvrdu potpune sigurnosne kopije. Aplikacije ne bi trebale upotrebljavati tu opciju."</string>
     <string name="permlab_internalSystemWindow" msgid="2148563628140193231">"prikaz neovlaštenih prozora"</string>
     <string name="permdesc_internalSystemWindow" msgid="5895082268284998469">"Omogućuje stvaranje prozora kojima je namjena da se koriste u korisničkom sučelju internog sustava. Nije za upotrebu na uobičajenim aplikacijama."</string>
@@ -265,6 +267,10 @@
     <string name="permdesc_bindDeviceAdmin" msgid="8714424333082216979">"Nositelju omogućuje slanje namjera administratoru uređaja. Nikad ne bi trebalo koristiti za uobičajene aplikacije."</string>
     <string name="permlab_setOrientation" msgid="3365947717163866844">"promjena orijentacije zaslona"</string>
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"Aplikaciji omogućuje promjenu rotacije zaslona u svakom trenutku. Nikad ne bi trebalo koristiti za uobičajene aplikacije."</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <string name="permlab_signalPersistentProcesses" msgid="4255467255488653854">"slanje Linux signala u aplikaciju"</string>
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"Aplikacijama omogućuje traženje zahtjeva da se dobiveni signal pošalje na sve trajne postupke."</string>
     <string name="permlab_persistentActivity" msgid="8659652042401085862">"uvijek pokrenuta aplikacija"</string>
@@ -836,6 +842,12 @@
     <string name="launch_warning_title" msgid="8323761616052121936">"Aplikacija preusmjerena"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g> se izvodi sada."</string>
     <string name="launch_warning_original" msgid="188102023021668683">"Aplikacija <xliff:g id="APP_NAME">%1$s</xliff:g> pokrenuta je prva."</string>
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"Aplikacija <xliff:g id="APPLICATION">%1$s</xliff:g> (proces <xliff:g id="PROCESS">%2$s</xliff:g>) prekršila je svoje vlastito pravilo StrictMode."</string>
     <string name="smv_process" msgid="5120397012047462446">"Proces <xliff:g id="PROCESS">%1$s</xliff:g> prekršio je svoje vlastito pravilo StrictMode."</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"Izvodi se <xliff:g id="APP">%1$s</xliff:g>"</string>
@@ -1041,4 +1053,6 @@
     <string name="storage_internal" msgid="7556050805474115618">"Unutarnja pohrana"</string>
     <string name="storage_sd_card" msgid="8921771478629812343">"SD kartica"</string>
     <string name="storage_usb" msgid="3017954059538517278">"USB pohrana"</string>
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-hu/strings.xml b/core/res/res/values-hu/strings.xml
index 18426f4..0c2aef3 100644
--- a/core/res/res/values-hu/strings.xml
+++ b/core/res/res/values-hu/strings.xml
@@ -265,6 +265,10 @@
     <string name="permdesc_bindDeviceAdmin" msgid="8714424333082216979">"Lehetővé teszi a használó számára, hogy célokat küldjön egy eszközkezelőnek. A normál alkalmazásoknak erre soha nincs szüksége."</string>
     <string name="permlab_setOrientation" msgid="3365947717163866844">"képernyő irányának módosítása"</string>
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"Lehetővé teszi egy alkalmazás számára a képernyő elforgatásának módosítását. A normál alkalmazásoknak erre soha nincs szüksége."</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <string name="permlab_signalPersistentProcesses" msgid="4255467255488653854">"Linux jelek küldése alkalmazásoknak"</string>
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"Lehetővé teszi az alkalmazás számára, hogy a megadott jelet elküldje az összes állandó folyamatnak."</string>
     <string name="permlab_persistentActivity" msgid="8659652042401085862">"alkalmazások folyamatos futtatása"</string>
@@ -836,6 +840,12 @@
     <string name="launch_warning_title" msgid="8323761616052121936">"Alk. átirányítva"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g> éppen fut."</string>
     <string name="launch_warning_original" msgid="188102023021668683">"<xliff:g id="APP_NAME">%1$s</xliff:g> volt eredetileg elindítva."</string>
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"<xliff:g id="APPLICATION">%1$s</xliff:g> alkalmazás (<xliff:g id="PROCESS">%2$s</xliff:g> folyamat) megsértette az általa kényszerített Szigorú üzemmód irányelvet."</string>
     <string name="smv_process" msgid="5120397012047462446">"<xliff:g id="PROCESS">%1$s</xliff:g> folyamat megsértette az általa kényszerített Szigorú üzemmód irányelvet."</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g> fut"</string>
@@ -1041,4 +1051,6 @@
     <string name="storage_internal" msgid="7556050805474115618">"Belső tárhely"</string>
     <string name="storage_sd_card" msgid="8921771478629812343">"SD-kártya"</string>
     <string name="storage_usb" msgid="3017954059538517278">"USB-tár"</string>
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-in/strings.xml b/core/res/res/values-in/strings.xml
index fdd6735..00e2dd4 100644
--- a/core/res/res/values-in/strings.xml
+++ b/core/res/res/values-in/strings.xml
@@ -265,6 +265,10 @@
     <string name="permdesc_bindDeviceAdmin" msgid="8714424333082216979">"Mengizinkan pemegang mengirimkan tujuan kepada administrator perangkat. Tidak diperlukan untuk aplikasi normal."</string>
     <string name="permlab_setOrientation" msgid="3365947717163866844">"ubah orientasi layar"</string>
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"Mengizinkan aplikasi mengubah rotasi layar kapan saja. Tidak diperlukan untuk aplikasi normal."</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <string name="permlab_signalPersistentProcesses" msgid="4255467255488653854">"kirim sinyal Linux ke aplikasi"</string>
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"Mengizinkan aplikasi meminta sinyal yang diberikan untuk dikirimkan ke semua proses yang ada."</string>
     <string name="permlab_persistentActivity" msgid="8659652042401085862">"jadikan aplikasi selalu berjalan"</string>
@@ -836,6 +840,12 @@
     <string name="launch_warning_title" msgid="8323761616052121936">"Aplikasi dialihkan"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g> sedang berjalan."</string>
     <string name="launch_warning_original" msgid="188102023021668683">"<xliff:g id="APP_NAME">%1$s</xliff:g> telah diluncurkan aslinya."</string>
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"Aplikasi <xliff:g id="APPLICATION">%1$s</xliff:g> (proses <xliff:g id="PROCESS">%2$s</xliff:g>) telah melanggar kebijakan StrictMode yang diberlakukan secara otomatis."</string>
     <string name="smv_process" msgid="5120397012047462446">"Proses <xliff:g id="PROCESS">%1$s</xliff:g> telah melanggar kebijakan StrictMode yang diberlakukan secara otomatis."</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g> berjalan"</string>
@@ -1041,4 +1051,6 @@
     <string name="storage_internal" msgid="7556050805474115618">"Penyimpanan Internal"</string>
     <string name="storage_sd_card" msgid="8921771478629812343">"Kartu SD"</string>
     <string name="storage_usb" msgid="3017954059538517278">"Penyimpanan USB"</string>
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-it/strings.xml b/core/res/res/values-it/strings.xml
index 7cff9c9..0d78861 100644
--- a/core/res/res/values-it/strings.xml
+++ b/core/res/res/values-it/strings.xml
@@ -241,7 +241,7 @@
     <string name="permlab_backup" msgid="470013022865453920">"controllo del backup di sistema e ripristino"</string>
     <string name="permdesc_backup" msgid="4837493065154256525">"Consente all\'applicazione di controllare il meccanismo di backup e ripristino del sistema. Da non usare per normali applicazioni."</string>
     <string name="permlab_confirm_full_backup" msgid="5557071325804469102">"conferma di un\'operazione completa di backup o di ripristino"</string>
-    <string name="permdesc_confirm_full_backup" msgid="9005017754175897954">"Consente all\'applicazione di lanciare l\'interfaccia utente di conferma del backup completo. Non utilizzabile da qualsiasi applicazione."</string>
+    <string name="permdesc_confirm_full_backup" msgid="9005017754175897954">"Consente all\'applicazione di lanciare l\'interfaccia utente di conferma del backup completo. Non utilizzare per nessuna applicazione."</string>
     <string name="permlab_internalSystemWindow" msgid="2148563628140193231">"visualizzazione finestre non autorizzate"</string>
     <string name="permdesc_internalSystemWindow" msgid="5895082268284998469">"Consente la creazione di finestre destinate all\'uso nell\'interfaccia utente di sistema interna. Da non usare per normali applicazioni."</string>
     <string name="permlab_systemAlertWindow" msgid="3372321942941168324">"visualizzazione avvisi di sistema"</string>
@@ -265,6 +265,10 @@
     <string name="permdesc_bindDeviceAdmin" msgid="8714424333082216979">"Consente l\'invio di intent a un amministratore del dispositivo. L\'autorizzazione non deve mai essere necessaria per le normali applicazioni."</string>
     <string name="permlab_setOrientation" msgid="3365947717163866844">"modifica orientamento dello schermo"</string>
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"Consente a un\'applicazione di cambiare la rotazione dello schermo in qualsiasi momento. Non dovrebbe essere mai necessario per le normali applicazioni."</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <string name="permlab_signalPersistentProcesses" msgid="4255467255488653854">"invio segnali Linuz alle applicazioni"</string>
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"Consente all\'applicazione di richiedere l\'invio del segnale fornito a tutti i processi persistenti."</string>
     <string name="permlab_persistentActivity" msgid="8659652042401085862">"esecuzione permanente delle applicazioni"</string>
@@ -836,6 +840,12 @@
     <string name="launch_warning_title" msgid="8323761616052121936">"Applicazione reindirizzata"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g> è ora in esecuzione."</string>
     <string name="launch_warning_original" msgid="188102023021668683">"<xliff:g id="APP_NAME">%1$s</xliff:g> già avviata."</string>
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"L\'applicazione <xliff:g id="APPLICATION">%1$s</xliff:g> (processo <xliff:g id="PROCESS">%2$s</xliff:g>) ha violato la norma StrictMode autoimposta."</string>
     <string name="smv_process" msgid="5120397012047462446">"Il processo <xliff:g id="PROCESS">%1$s</xliff:g> ha violato la norma StrictMode autoimposta."</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g> in esecuzione"</string>
@@ -1041,4 +1051,6 @@
     <string name="storage_internal" msgid="7556050805474115618">"Archivio interno"</string>
     <string name="storage_sd_card" msgid="8921771478629812343">"Scheda SD"</string>
     <string name="storage_usb" msgid="3017954059538517278">"Archivio USB"</string>
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-iw/strings.xml b/core/res/res/values-iw/strings.xml
index fd8ae47..6b50982 100644
--- a/core/res/res/values-iw/strings.xml
+++ b/core/res/res/values-iw/strings.xml
@@ -265,6 +265,10 @@
     <string name="permdesc_bindDeviceAdmin" msgid="8714424333082216979">"מאפשר למשתמש לשלוח כוונות למנהל התקן. לא אמור להידרש לעולם ביישומים רגילים."</string>
     <string name="permlab_setOrientation" msgid="3365947717163866844">"שנה את כיוון המסך"</string>
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"מאפשר ליישום לשנות את סיבוב המסך בכל עת. לא אמור להידרש לעולם ביישומים רגילים."</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <string name="permlab_signalPersistentProcesses" msgid="4255467255488653854">"שלח אותות Linux ליישומים"</string>
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"מאפשר ליישום לבקש שהאות המסופק יישלח לכל התהליכים המתמשכים."</string>
     <string name="permlab_persistentActivity" msgid="8659652042401085862">"הגדר את היישום לפעול תמיד"</string>
@@ -836,6 +840,12 @@
     <string name="launch_warning_title" msgid="8323761616052121936">"היישום נותב מחדש"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g> פועל כעת."</string>
     <string name="launch_warning_original" msgid="188102023021668683">"<xliff:g id="APP_NAME">%1$s</xliff:g> הופעל במקור."</string>
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"היישום <xliff:g id="APPLICATION">%1$s</xliff:g> (תהליך <xliff:g id="PROCESS">%2$s</xliff:g>) הפר את מדיניות StrictMode באכיפה עצמית."</string>
     <string name="smv_process" msgid="5120397012047462446">"התהליך <xliff:g id="PROCESS">%1$s</xliff:g> הפר את מדיניות StrictMode באכיפה עצמית."</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g> פועל"</string>
@@ -1041,4 +1051,6 @@
     <string name="storage_internal" msgid="7556050805474115618">"אחסון פנימי"</string>
     <string name="storage_sd_card" msgid="8921771478629812343">"כרטיס SD"</string>
     <string name="storage_usb" msgid="3017954059538517278">"אמצעי אחסון מסוג USB"</string>
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-ja/strings.xml b/core/res/res/values-ja/strings.xml
index 100d681..bdad7b6 100644
--- a/core/res/res/values-ja/strings.xml
+++ b/core/res/res/values-ja/strings.xml
@@ -265,6 +265,10 @@
     <string name="permdesc_bindDeviceAdmin" msgid="8714424333082216979">"デバイス管理者へのintentの送信を所有者に許可します。通常のアプリケーションでは不要です。"</string>
     <string name="permlab_setOrientation" msgid="3365947717163866844">"画面の向きの変更"</string>
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"いつでも画面の回転を変更することをアプリケーションに許可します。通常のアプリケーションにはまったく必要ありません。"</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <string name="permlab_signalPersistentProcesses" msgid="4255467255488653854">"Linuxのシグナルをアプリケーションに送信"</string>
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"受信した電波を継続プロセスに送信することをアプリケーションに許可します。"</string>
     <string name="permlab_persistentActivity" msgid="8659652042401085862">"アプリケーションを常に実行する"</string>
@@ -836,6 +840,12 @@
     <string name="launch_warning_title" msgid="8323761616052121936">"アプリのリダイレクト"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g>が実行中です。"</string>
     <string name="launch_warning_original" msgid="188102023021668683">"<xliff:g id="APP_NAME">%1$s</xliff:g>が最初に起動していました。"</string>
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"アプリケーション<xliff:g id="APPLICATION">%1$s</xliff:g>(プロセス<xliff:g id="PROCESS">%2$s</xliff:g>)でStrictModeポリシー違反がありました。"</string>
     <string name="smv_process" msgid="5120397012047462446">"プロセス<xliff:g id="PROCESS">%1$s</xliff:g>でStrictModeポリシー違反がありました。"</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g>を実行中"</string>
@@ -1041,4 +1051,6 @@
     <string name="storage_internal" msgid="7556050805474115618">"内部ストレージ"</string>
     <string name="storage_sd_card" msgid="8921771478629812343">"SDカード"</string>
     <string name="storage_usb" msgid="3017954059538517278">"USBストレージ"</string>
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-ko/strings.xml b/core/res/res/values-ko/strings.xml
index 0d5a41e..5a3584a 100644
--- a/core/res/res/values-ko/strings.xml
+++ b/core/res/res/values-ko/strings.xml
@@ -265,6 +265,10 @@
     <string name="permdesc_bindDeviceAdmin" msgid="8714424333082216979">"보유자가 기기 관리자에게 인텐트를 보낼 수 있도록 합니다. 일반 애플리케이션에는 절대로 필요하지 않습니다."</string>
     <string name="permlab_setOrientation" msgid="3365947717163866844">"화면 방향 변경"</string>
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"애플리케이션이 언제든지 화면 회전을 변경할 수 있도록 합니다. 일반 애플리케이션에는 절대로 필요하지 않습니다."</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <string name="permlab_signalPersistentProcesses" msgid="4255467255488653854">"애플리케이션에 Linux 시그널 보내기"</string>
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"애플리케이션이 제공된 시그널을 모든 영구 프로세스로 보내도록 요청할 수 있도록 합니다."</string>
     <string name="permlab_persistentActivity" msgid="8659652042401085862">"애플리케이션이 항상 실행되도록 설정"</string>
@@ -836,6 +840,12 @@
     <string name="launch_warning_title" msgid="8323761616052121936">"애플리케이션 리디렉션됨"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g>이(가) 실행 중입니다."</string>
     <string name="launch_warning_original" msgid="188102023021668683">"원래 <xliff:g id="APP_NAME">%1$s</xliff:g>을(를) 실행했습니다."</string>
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"애플리케이션 <xliff:g id="APPLICATION">%1$s</xliff:g>(프로세스 <xliff:g id="PROCESS">%2$s</xliff:g>)이(가) 자체 시행 StrictMode 정책을 위반했습니다."</string>
     <string name="smv_process" msgid="5120397012047462446">"프로세스(<xliff:g id="PROCESS">%1$s</xliff:g>)가 자체 시행 StrictMode 정책을 위반했습니다."</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g> 실행 중"</string>
@@ -1041,4 +1051,6 @@
     <string name="storage_internal" msgid="7556050805474115618">"내부 저장공간"</string>
     <string name="storage_sd_card" msgid="8921771478629812343">"SD 카드"</string>
     <string name="storage_usb" msgid="3017954059538517278">"USB 저장소"</string>
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-land/arrays.xml b/core/res/res/values-land/arrays.xml
new file mode 100644
index 0000000..85130ba1
--- /dev/null
+++ b/core/res/res/values-land/arrays.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/* //device/apps/common/assets/res/any/colors.xml
+**
+** Copyright 2006, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+**     http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+-->
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+
+    <!-- Resources for MultiWaveView in LockScreen -->
+    <array name="ic_lockscreen_targets_when_silent">
+        <item>@null</item>"
+        <item>@drawable/ic_lockscreen_unlock</item>
+        <item>@null</item>
+        <item>@drawable/ic_lockscreen_soundon</item>
+    </array>
+
+    <array name="ic_lockscreen_targets_when_soundon">
+        <item>@null</item>"
+        <item>@drawable/ic_lockscreen_unlock</item>
+        <item>@null</item>
+        <item>@drawable/ic_lockscreen_silent</item>
+    </array>
+
+</resources>
diff --git a/core/res/res/values-land/dimens.xml b/core/res/res/values-land/dimens.xml
index dbaad13..b8ce9b4 100644
--- a/core/res/res/values-land/dimens.xml
+++ b/core/res/res/values-land/dimens.xml
@@ -32,4 +32,7 @@
     <!-- Default height of an action bar. -->
     <dimen name="action_bar_default_height">40dip</dimen>
 
+    <!-- Size of clock font in LockScreen. -->
+    <dimen name="keyguard_pattern_unlock_clock_font_size">80sp</dimen>
+
 </resources>
diff --git a/core/res/res/values-large/config.xml b/core/res/res/values-large/config.xml
index c94256e..9327200 100644
--- a/core/res/res/values-large/config.xml
+++ b/core/res/res/values-large/config.xml
@@ -23,8 +23,6 @@
     <!-- see comment in values/config.xml -->
     <dimen name="config_prefDialogWidth">440dp</dimen>
 
-    <bool name="config_statusBarCanHide">false</bool>
-
     <!-- see comment in values/config.xml -->
     <integer name="config_longPressOnPowerBehavior">2</integer>
 
diff --git a/core/res/res/values-lt/strings.xml b/core/res/res/values-lt/strings.xml
index e3bdea6..eab92c6 100644
--- a/core/res/res/values-lt/strings.xml
+++ b/core/res/res/values-lt/strings.xml
@@ -265,6 +265,10 @@
     <string name="permdesc_bindDeviceAdmin" msgid="8714424333082216979">"Leidžia savininkui siųsti tikslus įrenginio administratoriui. Neturėtų reikėti įprastose programose."</string>
     <string name="permlab_setOrientation" msgid="3365947717163866844">"keisti ekrano padėtį"</string>
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"Leidžia programai bet kuriuo metu keisti ekrano sukimą. Neturėtų reikėti įprastoms programoms."</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <string name="permlab_signalPersistentProcesses" msgid="4255467255488653854">"programoms siųsti „Linux“ signalus"</string>
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"Leidžia programai pateikti užklausą, kad teikiamas signalas būtų siunčiamas visiems nuolatiniams procesams."</string>
     <string name="permlab_persistentActivity" msgid="8659652042401085862">"nustatyti, kad programa būtų visada paleista"</string>
@@ -836,6 +840,12 @@
     <string name="launch_warning_title" msgid="8323761616052121936">"Programa nukreipta"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"„<xliff:g id="APP_NAME">%1$s</xliff:g>“ dabar vykdoma."</string>
     <string name="launch_warning_original" msgid="188102023021668683">"„<xliff:g id="APP_NAME">%1$s</xliff:g>“ buvo iš pradžių paleista."</string>
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"Programa „<xliff:g id="APPLICATION">%1$s</xliff:g>“ (procesas „<xliff:g id="PROCESS">%2$s</xliff:g>“) pažeidė savo vykdomą „StrictMode“ politiką."</string>
     <string name="smv_process" msgid="5120397012047462446">"„<xliff:g id="PROCESS">%1$s</xliff:g>“ procesas pažeidė savo vykdomą „StrictMode“ politiką."</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"Vykdoma „<xliff:g id="APP">%1$s</xliff:g>“"</string>
@@ -1041,4 +1051,6 @@
     <string name="storage_internal" msgid="7556050805474115618">"Vidinė atmintis"</string>
     <string name="storage_sd_card" msgid="8921771478629812343">"SD kortelė"</string>
     <string name="storage_usb" msgid="3017954059538517278">"USB atmintis"</string>
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-lv/strings.xml b/core/res/res/values-lv/strings.xml
index db2b1d3..5c5525c 100644
--- a/core/res/res/values-lv/strings.xml
+++ b/core/res/res/values-lv/strings.xml
@@ -265,6 +265,10 @@
     <string name="permdesc_bindDeviceAdmin" msgid="8714424333082216979">"Ļauj īpašniekam sūtīt nolūkus ierīces administratoram. Nekad nav nepieciešams parastajām lietojumprogrammām."</string>
     <string name="permlab_setOrientation" msgid="3365947717163866844">"mainīt ekrāna orientāciju"</string>
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"Ļauj lietojumprogrammai jebkurā brīdī mainīt ekrāna pagriešanas iestatījumu. Parastajām lietojumprogrammām nekad nav nepieciešama."</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <string name="permlab_signalPersistentProcesses" msgid="4255467255488653854">"sūtīt Linux signālus uz lietojumprogrammām"</string>
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"Ļauj lietojumprogrammai pieprasīt, lai piegādātais signāls tiktu sūtīts uz visiem pastāvīgajiem procesiem."</string>
     <string name="permlab_persistentActivity" msgid="8659652042401085862">"likt lietojumprogrammai vienmēr darboties"</string>
@@ -836,6 +840,12 @@
     <string name="launch_warning_title" msgid="8323761616052121936">"Lietojumpr. ir novirzīta"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g> tagad darbojas."</string>
     <string name="launch_warning_original" msgid="188102023021668683">"Sākotnēji tika palaista lietojumprogramma <xliff:g id="APP_NAME">%1$s</xliff:g>."</string>
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"Lietojumprogramma <xliff:g id="APPLICATION">%1$s</xliff:g> (process <xliff:g id="PROCESS">%2$s</xliff:g>) ir pārkāpusi savu pašieviesto StrictMode politiku."</string>
     <string name="smv_process" msgid="5120397012047462446">"Process <xliff:g id="PROCESS">%1$s</xliff:g> ir pārkāpis savu pašieviesto StrictMode politiku."</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g> darbojas"</string>
@@ -1041,4 +1051,6 @@
     <string name="storage_internal" msgid="7556050805474115618">"Iekšējā atmiņa"</string>
     <string name="storage_sd_card" msgid="8921771478629812343">"SD karte"</string>
     <string name="storage_usb" msgid="3017954059538517278">"USB atmiņa"</string>
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-ms/strings.xml b/core/res/res/values-ms/strings.xml
index 09234bd..6b0e18e 100644
--- a/core/res/res/values-ms/strings.xml
+++ b/core/res/res/values-ms/strings.xml
@@ -297,6 +297,10 @@
     <skip />
     <string name="permlab_setOrientation" msgid="3365947717163866844">"tukar orientasi skrin"</string>
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"Membolehkan aplikasi untuk menukar putaran skrin pada bila-bila masa. Tidak seharusnya diperlukan untuk aplikasi biasa."</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <string name="permlab_signalPersistentProcesses" msgid="4255467255488653854">"hantar isyarat Linux kepada aplikasi"</string>
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"Membenarkan aplikasi meminta isyarat yang dibekalkan dihantar kepada semua proses gigih."</string>
     <string name="permlab_persistentActivity" msgid="8659652042401085862">"buatkan aplikasi sentiasa berjalan"</string>
@@ -1046,6 +1050,12 @@
     <skip />
     <!-- no translation found for launch_warning_original (188102023021668683) -->
     <skip />
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <!-- no translation found for smv_application (295583804361236288) -->
     <skip />
     <!-- no translation found for smv_process (5120397012047462446) -->
@@ -1351,4 +1361,6 @@
     <skip />
     <!-- no translation found for storage_usb (3017954059538517278) -->
     <skip />
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-nb/strings.xml b/core/res/res/values-nb/strings.xml
index a6867ac..2413685 100644
--- a/core/res/res/values-nb/strings.xml
+++ b/core/res/res/values-nb/strings.xml
@@ -265,6 +265,10 @@
     <string name="permdesc_bindDeviceAdmin" msgid="8714424333082216979">"Tillater innehaveren å sende hensikter til enhetsadministrator. Bør aldri være nødvendig for normale programmer."</string>
     <string name="permlab_setOrientation" msgid="3365947717163866844">"snu skjermen"</string>
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"Lar applikasjonen rotere skjermen når som helst. Vanlige applikasjoner bør aldri trenge dette."</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <string name="permlab_signalPersistentProcesses" msgid="4255467255488653854">"sende Linux-signaler til applikasjoner"</string>
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"Lar applikasjonen spørre om at et gitt signal blir sendt til alle varige prosesser."</string>
     <string name="permlab_persistentActivity" msgid="8659652042401085862">"forbli kjørende"</string>
@@ -836,6 +840,12 @@
     <string name="launch_warning_title" msgid="8323761616052121936">"Programmet er omdirigert"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g> kjører nå."</string>
     <string name="launch_warning_original" msgid="188102023021668683">"<xliff:g id="APP_NAME">%1$s</xliff:g> ble opprinnelig startet."</string>
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"Programmet <xliff:g id="APPLICATION">%1$s</xliff:g> (prosessen <xliff:g id="PROCESS">%2$s</xliff:g>) har brutt de selvpålagte StrictMode-retningslinjene."</string>
     <string name="smv_process" msgid="5120397012047462446">"Prosessen<xliff:g id="PROCESS">%1$s</xliff:g> har brutt de selvpålagte StrictMode-retningslinjene."</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g> kjører"</string>
@@ -1041,4 +1051,6 @@
     <string name="storage_internal" msgid="7556050805474115618">"Intern lagring"</string>
     <string name="storage_sd_card" msgid="8921771478629812343">"SD-kort"</string>
     <string name="storage_usb" msgid="3017954059538517278">"USB-lagring"</string>
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-nl/strings.xml b/core/res/res/values-nl/strings.xml
index d078081..dbb7e98 100644
--- a/core/res/res/values-nl/strings.xml
+++ b/core/res/res/values-nl/strings.xml
@@ -265,6 +265,10 @@
     <string name="permdesc_bindDeviceAdmin" msgid="8714424333082216979">"Staat de houder toe intenties te verzenden naar een apparaatbeheerder. Nooit vereist voor normale toepassingen."</string>
     <string name="permlab_setOrientation" msgid="3365947717163866844">"schermstand wijzigen"</string>
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"Hiermee kan een app op elk gewenst moment de oriëntatie van het scherm wijzigen. Nooit vereist voor normale apps."</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <string name="permlab_signalPersistentProcesses" msgid="4255467255488653854">"Linux-signalen verzenden naar toepassingen"</string>
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"Hiermee kan de app ervoor zorgen dat het geleverde signaal wordt verzonden naar alle persistente processen."</string>
     <string name="permlab_persistentActivity" msgid="8659652042401085862">"app altijd laten uitvoeren"</string>
@@ -836,6 +840,12 @@
     <string name="launch_warning_title" msgid="8323761616052121936">"App omgeleid"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g> is nu actief."</string>
     <string name="launch_warning_original" msgid="188102023021668683">"<xliff:g id="APP_NAME">%1$s</xliff:g> was het eerst gestart."</string>
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"De app <xliff:g id="APPLICATION">%1$s</xliff:g> (proces <xliff:g id="PROCESS">%2$s</xliff:g>) heeft het zelf afgedwongen StrictMode-beleid geschonden."</string>
     <string name="smv_process" msgid="5120397012047462446">"Het proces <xliff:g id="PROCESS">%1$s</xliff:g> heeft het zelf afgedwongen StrictMode-beleid geschonden."</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g> wordt uitgevoerd"</string>
@@ -1041,4 +1051,6 @@
     <string name="storage_internal" msgid="7556050805474115618">"Interne opslag"</string>
     <string name="storage_sd_card" msgid="8921771478629812343">"SD-kaart"</string>
     <string name="storage_usb" msgid="3017954059538517278">"USB-opslag"</string>
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-pl/strings.xml b/core/res/res/values-pl/strings.xml
index 8dd3cc7..36d3cdd 100644
--- a/core/res/res/values-pl/strings.xml
+++ b/core/res/res/values-pl/strings.xml
@@ -265,6 +265,10 @@
     <string name="permdesc_bindDeviceAdmin" msgid="8714424333082216979">"Zezwala posiadaczowi na wysyłanie informacji o zamiarach do administratora urządzenia. Opcja nie powinna być nigdy potrzebna w przypadku zwykłych aplikacji."</string>
     <string name="permlab_setOrientation" msgid="3365947717163866844">"zmienianie orientacji ekranu"</string>
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"Pozwala aplikacji na zmianę orientacji ekranu w dowolnym momencie. Nigdy nie powinno być potrzeby stosowania w normalnych aplikacjach."</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <string name="permlab_signalPersistentProcesses" msgid="4255467255488653854">"wysyłanie sygnałów systemu Linux do aplikacji"</string>
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"Pozwala aplikacjom żądać, aby dostarczany sygnał był wysyłany do wszystkich trwających procesów."</string>
     <string name="permlab_persistentActivity" msgid="8659652042401085862">"sprawianie, że aplikacja jest cały czas uruchomiona"</string>
@@ -836,6 +840,12 @@
     <string name="launch_warning_title" msgid="8323761616052121936">"Aplikacja przekierowana"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"Aplikacja <xliff:g id="APP_NAME">%1$s</xliff:g> jest uruchomiona."</string>
     <string name="launch_warning_original" msgid="188102023021668683">"Aplikacja <xliff:g id="APP_NAME">%1$s</xliff:g> została pierwotnie uruchomiona."</string>
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"Aplikacja <xliff:g id="APPLICATION">%1$s</xliff:g> (proces <xliff:g id="PROCESS">%2$s</xliff:g>) naruszyła wymuszone przez siebie zasady StrictMode."</string>
     <string name="smv_process" msgid="5120397012047462446">"Proces <xliff:g id="PROCESS">%1$s</xliff:g> naruszył wymuszone przez siebie zasady StrictMode."</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"Działa <xliff:g id="APP">%1$s</xliff:g>"</string>
@@ -1041,4 +1051,6 @@
     <string name="storage_internal" msgid="7556050805474115618">"Pamięć wewnętrzna"</string>
     <string name="storage_sd_card" msgid="8921771478629812343">"Karta SD"</string>
     <string name="storage_usb" msgid="3017954059538517278">"Nośnik USB"</string>
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-pt-rPT/strings.xml b/core/res/res/values-pt-rPT/strings.xml
index 9ae74dd..9cec4b6 100644
--- a/core/res/res/values-pt-rPT/strings.xml
+++ b/core/res/res/values-pt-rPT/strings.xml
@@ -265,6 +265,10 @@
     <string name="permdesc_bindDeviceAdmin" msgid="8714424333082216979">"Permite ao titular enviar intenções para um administrador do dispositivo. Nunca deverá ser necessário para aplicações normais."</string>
     <string name="permlab_setOrientation" msgid="3365947717163866844">"mudar orientação do ecrã"</string>
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"Permite a uma aplicação mudar a rotação do ecrã em qualquer momento. Nunca deve ser necessário para aplicações normais."</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <string name="permlab_signalPersistentProcesses" msgid="4255467255488653854">"enviar sinais Linux para aplicações"</string>
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"Permite à aplicação pedir que o sinal fornecido seja enviado a todos os processos persistentes."</string>
     <string name="permlab_persistentActivity" msgid="8659652042401085862">"fazer com que a aplicação seja sempre executada"</string>
@@ -836,6 +840,12 @@
     <string name="launch_warning_title" msgid="8323761616052121936">"Aplicação redireccionada"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g> está agora a ser executado."</string>
     <string name="launch_warning_original" msgid="188102023021668683">"<xliff:g id="APP_NAME">%1$s</xliff:g> foi originalmente iniciado."</string>
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"A aplicação <xliff:g id="APPLICATION">%1$s</xliff:g> (processo <xliff:g id="PROCESS">%2$s</xliff:g>) violou a política StrictMode auto-imposta."</string>
     <string name="smv_process" msgid="5120397012047462446">"O processo <xliff:g id="PROCESS">%1$s</xliff:g> violou a política StrictMode auto-imposta."</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g> em execução"</string>
@@ -1041,4 +1051,6 @@
     <string name="storage_internal" msgid="7556050805474115618">"Armazenamento Interno"</string>
     <string name="storage_sd_card" msgid="8921771478629812343">"Cartão SD"</string>
     <string name="storage_usb" msgid="3017954059538517278">"Armazenamento USB"</string>
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-pt/strings.xml b/core/res/res/values-pt/strings.xml
index 5e37153..57737c9 100644
--- a/core/res/res/values-pt/strings.xml
+++ b/core/res/res/values-pt/strings.xml
@@ -265,6 +265,10 @@
     <string name="permdesc_bindDeviceAdmin" msgid="8714424333082216979">"Permite que o detentor envie tentativas ao administrador de um dispositivo. Não é necessário para aplicativos normais."</string>
     <string name="permlab_setOrientation" msgid="3365947717163866844">"alterar orientação da tela"</string>
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"Permite que um aplicativo altere a rotação da tela a qualquer momento. Aplicativos normais não devem precisar disso em momento algum."</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <string name="permlab_signalPersistentProcesses" msgid="4255467255488653854">"enviar sinais de Linux para os aplicativos"</string>
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"Permite que o aplicativo solicite que o sinal fornecido seja enviado a todos os processos persistentes."</string>
     <string name="permlab_persistentActivity" msgid="8659652042401085862">"executar sempre o aplicativo"</string>
@@ -836,6 +840,12 @@
     <string name="launch_warning_title" msgid="8323761616052121936">"Aplicativo redirecionado"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g> não está em execução."</string>
     <string name="launch_warning_original" msgid="188102023021668683">"<xliff:g id="APP_NAME">%1$s</xliff:g> foi iniciado."</string>
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"O aplicativo <xliff:g id="APPLICATION">%1$s</xliff:g> (processo <xliff:g id="PROCESS">%2$s</xliff:g>) violou a política StrictMode imposta automaticamente."</string>
     <string name="smv_process" msgid="5120397012047462446">"O processo <xliff:g id="PROCESS">%1$s</xliff:g> violou a política StrictMode imposta automaticamente."</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g> em execução"</string>
@@ -1041,4 +1051,6 @@
     <string name="storage_internal" msgid="7556050805474115618">"Armazenamento interno"</string>
     <string name="storage_sd_card" msgid="8921771478629812343">"Cartão SD"</string>
     <string name="storage_usb" msgid="3017954059538517278">"Armazenamento USB"</string>
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-rm/strings.xml b/core/res/res/values-rm/strings.xml
index 4bf9c3e..60f6049 100644
--- a/core/res/res/values-rm/strings.xml
+++ b/core/res/res/values-rm/strings.xml
@@ -275,6 +275,10 @@
     <string name="permdesc_bindDeviceAdmin" msgid="8714424333082216979">"Permetta al possessur da trametter intenziuns a l\'administratur dal apparat periferic. Betg previs per applicaziuns normalas."</string>
     <string name="permlab_setOrientation" msgid="3365947717163866844">"midar l\'orientaziun dal visur"</string>
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"Permetta a l\'applicaziun da midar da tut temp la orientaziun dal visur. Betg previs per applicaziuns normalas."</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <string name="permlab_signalPersistentProcesses" msgid="4255467255488653854">"trametter signals Linux a las applicaziuns"</string>
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"Permetta a l\'applicaziun da pretender ch\'il signal furnì vegnia tramess a tut ils process persistents."</string>
     <string name="permlab_persistentActivity" msgid="8659652042401085862">"exequir permanentamain applicaziuns"</string>
@@ -899,6 +903,12 @@
     <skip />
     <!-- no translation found for launch_warning_original (188102023021668683) -->
     <skip />
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"L\'applicaziun <xliff:g id="APPLICATION">%1$s</xliff:g> (process <xliff:g id="PROCESS">%2$s</xliff:g>) ha violà sia atgna directiva StrictMode."</string>
     <string name="smv_process" msgid="5120397012047462446">"Il process <xliff:g id="PROCESS">%1$s</xliff:g> ha violà sia atgna directiva StrictMode."</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g> vegn exequida"</string>
@@ -1147,4 +1157,6 @@
     <skip />
     <!-- no translation found for storage_usb (3017954059538517278) -->
     <skip />
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-ro/strings.xml b/core/res/res/values-ro/strings.xml
index c88f06d..1961903 100644
--- a/core/res/res/values-ro/strings.xml
+++ b/core/res/res/values-ro/strings.xml
@@ -265,6 +265,10 @@
     <string name="permdesc_bindDeviceAdmin" msgid="8714424333082216979">"Permite proprietarului să trimită intenţii către un administrator al dispozitivului. Nu ar trebui să fie niciodată necesară pentru aplicaţiile obişnuite."</string>
     <string name="permlab_setOrientation" msgid="3365947717163866844">"modificare orientare ecran"</string>
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"Permite unei aplicaţii să modifice rotaţia ecranului în orice moment. Nu ar trebui să fie niciodată necesară pentru aplicaţiile obişnuite."</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <string name="permlab_signalPersistentProcesses" msgid="4255467255488653854">"trimitere semnale Linux către aplicaţii"</string>
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"Permite aplicaţiei să solicite trimiterea semnalului furnizat către toate procesele persistente."</string>
     <string name="permlab_persistentActivity" msgid="8659652042401085862">"rulare întotdeauna a aplicaţiei"</string>
@@ -836,6 +840,12 @@
     <string name="launch_warning_title" msgid="8323761616052121936">"Aplicaţie redirecţionată"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g> funcţionează acum."</string>
     <string name="launch_warning_original" msgid="188102023021668683">"<xliff:g id="APP_NAME">%1$s</xliff:g> a fost lansată iniţial."</string>
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"Aplicaţia <xliff:g id="APPLICATION">%1$s</xliff:g> (procesul <xliff:g id="PROCESS">%2$s</xliff:g>) a încălcat propria politică StrictMode."</string>
     <string name="smv_process" msgid="5120397012047462446">"Procesul <xliff:g id="PROCESS">%1$s</xliff:g> a încălcat propria politică StrictMode."</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"Rulează <xliff:g id="APP">%1$s</xliff:g>"</string>
@@ -1041,4 +1051,6 @@
     <string name="storage_internal" msgid="7556050805474115618">"Stocare internă"</string>
     <string name="storage_sd_card" msgid="8921771478629812343">"Card SD"</string>
     <string name="storage_usb" msgid="3017954059538517278">"Dsipozitiv de stocare USB"</string>
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-ru/strings.xml b/core/res/res/values-ru/strings.xml
index e7d4268..83dc30f 100644
--- a/core/res/res/values-ru/strings.xml
+++ b/core/res/res/values-ru/strings.xml
@@ -265,6 +265,10 @@
     <string name="permdesc_bindDeviceAdmin" msgid="8714424333082216979">"Позволяет владельцу отправлять целевые значения администратору устройства. Никогда не используется обычными приложениями."</string>
     <string name="permlab_setOrientation" msgid="3365947717163866844">"изменять ориентацию экрана"</string>
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"Позволяет приложению изменять ориентацию экрана в любое время. Не требуется для обычных приложений."</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <string name="permlab_signalPersistentProcesses" msgid="4255467255488653854">"отправлять приложениям сигналы Linux"</string>
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"Позволяет приложению направлять запрос на передачу предоставленного сигнала всем постоянным процессам."</string>
     <string name="permlab_persistentActivity" msgid="8659652042401085862">"запускать постоянную работу приложения"</string>
@@ -449,7 +453,7 @@
     <string name="permlab_nfc" msgid="4423351274757876953">"управлять радиосвязью ближнего действия"</string>
     <string name="permdesc_nfc" msgid="9171401851954407226">"Позволяет приложению обмениваться данными с метками, картами и считывателями через радиосвязь ближнего действия (NFC)."</string>
     <string name="permlab_vpn" msgid="8345800584532175312">"перехватывать и изменять сетевой трафик"</string>
-    <string name="permdesc_vpn" msgid="5617893078989944219">"Позволяет приложению перехватывать и проверять весь сетевой трафик, например, чтобы установить соединение VPN. Вредоносное ПО может отслеживать, перенаправлять или изменять сетевые пакеты без вашего ведома."</string>
+    <string name="permdesc_vpn" msgid="5617893078989944219">"Позволяет приложению перехватывать и проверять весь сетевой трафик, например чтобы установить соединение VPN. Вредоносное ПО может отслеживать, перенаправлять или изменять сетевые пакеты без вашего ведома."</string>
     <string name="permlab_disableKeyguard" msgid="4977406164311535092">"отключать блокировку клавиатуры"</string>
     <string name="permdesc_disableKeyguard" msgid="3189763479326302017">"Позволяет приложению отключить блокировку клавиатуры и другие функции защиты паролем. Примером допустимого использования этой функции является отключение блокировки клавиатуры при получении входящего вызова и включение блокировки после завершения разговора."</string>
     <string name="permlab_readSyncSettings" msgid="6201810008230503052">"считывать настройки синхронизации"</string>
@@ -836,6 +840,12 @@
     <string name="launch_warning_title" msgid="8323761616052121936">"Приложение перенаправлено"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"Приложение <xliff:g id="APP_NAME">%1$s</xliff:g> выполняется."</string>
     <string name="launch_warning_original" msgid="188102023021668683">"Изначально было запущено приложение <xliff:g id="APP_NAME">%1$s</xliff:g>."</string>
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"Приложение <xliff:g id="APPLICATION">%1$s</xliff:g> (процесс <xliff:g id="PROCESS">%2$s</xliff:g>) нарушило собственную политику StrictMode."</string>
     <string name="smv_process" msgid="5120397012047462446">"Процесс <xliff:g id="PROCESS">%1$s</xliff:g> нарушил собственную политику StrictMode."</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"Приложение <xliff:g id="APP">%1$s</xliff:g> запущено"</string>
@@ -1041,4 +1051,6 @@
     <string name="storage_internal" msgid="7556050805474115618">"Внутренняя память"</string>
     <string name="storage_sd_card" msgid="8921771478629812343">"SD-карта"</string>
     <string name="storage_usb" msgid="3017954059538517278">"USB-накопитель"</string>
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-sk/strings.xml b/core/res/res/values-sk/strings.xml
index 311da94..3439f59 100644
--- a/core/res/res/values-sk/strings.xml
+++ b/core/res/res/values-sk/strings.xml
@@ -265,6 +265,10 @@
     <string name="permdesc_bindDeviceAdmin" msgid="8714424333082216979">"Umožňuje držiteľovi odosielať informácie správcovi zariadenia. Bežné aplikácie by toto oprávnenie nemali nikdy požadovať."</string>
     <string name="permlab_setOrientation" msgid="3365947717163866844">"zmena orientácie obrazovky"</string>
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"Umožňuje aplikácii kedykoľvek zmeniť orientáciu obrazovky. Bežné aplikácie by toto nastavenie nemali vôbec využívať."</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <string name="permlab_signalPersistentProcesses" msgid="4255467255488653854">"odoslanie signálov systému Linux aplikáciám"</string>
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"Umožňuje aplikácii vyžiadať zaslanie poskytnutého signálu všetkým trvalým procesom."</string>
     <string name="permlab_persistentActivity" msgid="8659652042401085862">"trvalé spustenie aplikácie"</string>
@@ -836,6 +840,12 @@
     <string name="launch_warning_title" msgid="8323761616052121936">"Aplikácia bola presmerov."</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"Je spustená aplikácia <xliff:g id="APP_NAME">%1$s</xliff:g>."</string>
     <string name="launch_warning_original" msgid="188102023021668683">"Pôvodne bola spustená aplikácia <xliff:g id="APP_NAME">%1$s</xliff:g>."</string>
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"Aplikácia <xliff:g id="APPLICATION">%1$s</xliff:g> (proces <xliff:g id="PROCESS">%2$s</xliff:g>) porušila svoje vlastné vynútené pravidlá StrictMode."</string>
     <string name="smv_process" msgid="5120397012047462446">"Proces <xliff:g id="PROCESS">%1$s</xliff:g> porušil svoje vlastné vynútené pravidlá StrictMode."</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"Spustená aplikácia: <xliff:g id="APP">%1$s</xliff:g>"</string>
@@ -1041,4 +1051,6 @@
     <string name="storage_internal" msgid="7556050805474115618">"Interný ukladací priestor"</string>
     <string name="storage_sd_card" msgid="8921771478629812343">"Karta SD"</string>
     <string name="storage_usb" msgid="3017954059538517278">"Ukladací priestor USB"</string>
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-sl/strings.xml b/core/res/res/values-sl/strings.xml
index 2ba3242..cd4cd07 100644
--- a/core/res/res/values-sl/strings.xml
+++ b/core/res/res/values-sl/strings.xml
@@ -265,6 +265,10 @@
     <string name="permdesc_bindDeviceAdmin" msgid="8714424333082216979">"Dovoljuje lastniku, da pošlje namere skrbniku naprave. Nikoli se ne uporablja za navadne programe."</string>
     <string name="permlab_setOrientation" msgid="3365947717163866844">"spreminjanje usmerjenosti zaslona"</string>
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"Dovoljuje, da program kadar koli spremeni smer sukanja zaslona. Tega nikoli ni treba uporabiti za navadne programe."</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <string name="permlab_signalPersistentProcesses" msgid="4255467255488653854">"pošiljanje signalov Linuxa programom"</string>
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"Dovoljuje, da program zahteva, da je posredovan signal poslan vsem trajnim procesom."</string>
     <string name="permlab_persistentActivity" msgid="8659652042401085862">"neprekinjeno izvajanje programov"</string>
@@ -836,6 +840,12 @@
     <string name="launch_warning_title" msgid="8323761616052121936">"Preusmeritev programa"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g> se izvaja."</string>
     <string name="launch_warning_original" msgid="188102023021668683">"Prvotno je bil zagnan program <xliff:g id="APP_NAME">%1$s</xliff:g>."</string>
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"Program <xliff:g id="APPLICATION">%1$s</xliff:g> (proces <xliff:g id="PROCESS">%2$s</xliff:g>) krši svoj samoizvedljivi pravilnik o strogem načinu."</string>
     <string name="smv_process" msgid="5120397012047462446">"Proces <xliff:g id="PROCESS">%1$s</xliff:g> krši svoj samoizvedljivi pravilnik o strogem načinu."</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g> se izvaja"</string>
@@ -1041,4 +1051,6 @@
     <string name="storage_internal" msgid="7556050805474115618">"Notranji pomnilnik"</string>
     <string name="storage_sd_card" msgid="8921771478629812343">"Kartica SD"</string>
     <string name="storage_usb" msgid="3017954059538517278">"Pomnilnik USB"</string>
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-sr/strings.xml b/core/res/res/values-sr/strings.xml
index 8d8b73f..59329b4 100644
--- a/core/res/res/values-sr/strings.xml
+++ b/core/res/res/values-sr/strings.xml
@@ -265,6 +265,10 @@
     <string name="permdesc_bindDeviceAdmin" msgid="8714424333082216979">"Омогућава власнику да шаље своје намере администратору уређаја. Обичне апликације никада не би требало да је користе."</string>
     <string name="permlab_setOrientation" msgid="3365947717163866844">"промена положаја екрана"</string>
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"Омогућава да апликација у сваком тренутку промени ротацију екрана. Обичне апликације никада не би требало да је користе."</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <string name="permlab_signalPersistentProcesses" msgid="4255467255488653854">"слање Linux сигнала апликацијама"</string>
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"Омогућава да апликација захтева да испоручени сигнал буде послат свим трајним процесима."</string>
     <string name="permlab_persistentActivity" msgid="8659652042401085862">"омогућавање непрекидне активности апликације"</string>
@@ -836,6 +840,12 @@
     <string name="launch_warning_title" msgid="8323761616052121936">"Апликација је преусмерена"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"Апликација <xliff:g id="APP_NAME">%1$s</xliff:g> је сада покренута."</string>
     <string name="launch_warning_original" msgid="188102023021668683">"Првобитно је покренута апликација <xliff:g id="APP_NAME">%1$s</xliff:g>."</string>
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"Апликација <xliff:g id="APPLICATION">%1$s</xliff:g> (процес <xliff:g id="PROCESS">%2$s</xliff:g>) је прекршила самонаметнуте StrictMode смернице."</string>
     <string name="smv_process" msgid="5120397012047462446">"Процес <xliff:g id="PROCESS">%1$s</xliff:g> је прекршио самонаметнуте StrictMode смернице."</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"Апликација <xliff:g id="APP">%1$s</xliff:g> је покренута"</string>
@@ -1041,4 +1051,6 @@
     <string name="storage_internal" msgid="7556050805474115618">"Интерна меморија"</string>
     <string name="storage_sd_card" msgid="8921771478629812343">"SD картица"</string>
     <string name="storage_usb" msgid="3017954059538517278">"USB меморија"</string>
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-sv/strings.xml b/core/res/res/values-sv/strings.xml
index b2740a0..a3350e5 100644
--- a/core/res/res/values-sv/strings.xml
+++ b/core/res/res/values-sv/strings.xml
@@ -265,6 +265,10 @@
     <string name="permdesc_bindDeviceAdmin" msgid="8714424333082216979">"Tillåter att innehavaren skickar avsikter till en enhetsadministratör. Vanliga program behöver aldrig göra detta."</string>
     <string name="permlab_setOrientation" msgid="3365947717163866844">"ändra bildskärmens rikting"</string>
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"Tillåter att ett program när som helst ändrar skärmens rotering. Behövs inte för vanliga program."</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <string name="permlab_signalPersistentProcesses" msgid="4255467255488653854">"skicka Linux-signaler till appar"</string>
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"Tillåter att programmet begär att den angivna signalen skickas till alla beständiga processer."</string>
     <string name="permlab_persistentActivity" msgid="8659652042401085862">"se till att programmet alltid körs"</string>
@@ -836,6 +840,12 @@
     <string name="launch_warning_title" msgid="8323761616052121936">"Programmet omdirigerades"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g> körs."</string>
     <string name="launch_warning_original" msgid="188102023021668683">"<xliff:g id="APP_NAME">%1$s</xliff:g> startades först."</string>
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"Programmet <xliff:g id="APPLICATION">%1$s</xliff:g> (processen <xliff:g id="PROCESS">%2$s</xliff:g>) har brutit mot sin egen StrictMode-policy."</string>
     <string name="smv_process" msgid="5120397012047462446">"Processen <xliff:g id="PROCESS">%1$s</xliff:g> har brutit mot sin egen StrictMode-policy."</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g> körs"</string>
@@ -1041,4 +1051,6 @@
     <string name="storage_internal" msgid="7556050805474115618">"Internt lagringsutrymme"</string>
     <string name="storage_sd_card" msgid="8921771478629812343">"SD-kort"</string>
     <string name="storage_usb" msgid="3017954059538517278">"USB-lagring"</string>
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-sw/strings.xml b/core/res/res/values-sw/strings.xml
index 041365e..ff1907a 100644
--- a/core/res/res/values-sw/strings.xml
+++ b/core/res/res/values-sw/strings.xml
@@ -396,6 +396,10 @@
     <!-- no translation found for permlab_setOrientation (3365947717163866844) -->
     <skip />
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"Huruhusu programu kubadilisha uzungukaji wa skrini wakati wowote. Haipaswi kuhitajika kwa programu za kawaida za kompyuta."</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <!-- no translation found for permlab_signalPersistentProcesses (4255467255488653854) -->
     <skip />
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"Huruhusu programu kuomba kwamba mawimbi yaliyotolewa yatumwe kwa michakato yote isiyokoma."</string>
@@ -1154,6 +1158,12 @@
     <string name="launch_warning_title" msgid="8323761616052121936">"Programu imeelekezwa upya"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g>inaendesha sasa."</string>
     <string name="launch_warning_original" msgid="188102023021668683">"<xliff:g id="APP_NAME">%1$s</xliff:g> ilizinduliwa mwanzoni."</string>
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"Shughuli ya <xliff:g id="APPLICATION">%1$s</xliff:g> (programu <xliff:g id="PROCESS">%2$s</xliff:g>) imeenda kinyume na sera yake ya StrictMode."</string>
     <string name="smv_process" msgid="5120397012047462446">"Shughuli ya <xliff:g id="PROCESS">%1$s</xliff:g> imeenda kinyume na kulazimisha sera yake ya StrictMode."</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g> inaendelea"</string>
@@ -1423,4 +1433,6 @@
     <skip />
     <!-- no translation found for storage_usb (3017954059538517278) -->
     <skip />
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-sw600dp/config.xml b/core/res/res/values-sw600dp/config.xml
index 49ace34..d6a0cdd 100644
--- a/core/res/res/values-sw600dp/config.xml
+++ b/core/res/res/values-sw600dp/config.xml
@@ -20,8 +20,6 @@
 <!-- These resources are around just to allow their values to be customized
      for different hardware and product builds. -->
 <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <bool name="config_statusBarCanHide">false</bool>
-
     <!-- see comment in values/config.xml -->
     <integer name="config_longPressOnPowerBehavior">2</integer>
 
diff --git a/core/res/res/values-sw600dp/dimens.xml b/core/res/res/values-sw600dp/dimens.xml
new file mode 100644
index 0000000..150b6d4
--- /dev/null
+++ b/core/res/res/values-sw600dp/dimens.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/* //device/apps/common/assets/res/any/dimens.xml
+**
+** Copyright 2006, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+**     http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+-->
+<resources>
+    <!-- Height of the status bar -->
+    <dimen name="status_bar_height">48dip</dimen>
+    <!-- Width and height of a single notification icon in the status bar -->
+    <dimen name="status_bar_icon_size">32dip</dimen>
+    <!-- Size of the giant number (unread count) in the notifications -->
+    <dimen name="status_bar_content_number_size">48sp</dimen>
+
+    <!-- Size of clock font in LockScreen. -->
+    <dimen name="keyguard_pattern_unlock_clock_font_size">98sp</dimen>
+
+    <!-- Size of status line font in LockScreen. -->
+    <dimen name="keyguard_pattern_unlock_status_line_font_size">14sp</dimen>
+
+</resources>
+
diff --git a/core/res/res/values-sw600dp/styles.xml b/core/res/res/values-sw600dp/styles.xml
new file mode 100644
index 0000000..645db13
--- /dev/null
+++ b/core/res/res/values-sw600dp/styles.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+  
+          http://www.apache.org/licenses/LICENSE-2.0
+  
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<resources>
+    <style name="TextAppearance.Holo.Widget.TabWidget">
+        <item name="android:textSize">18sp</item>
+        <item name="android:textStyle">normal</item>
+        <item name="android:textColor">@android:color/tab_indicator_text</item>
+    </style>
+    
+    <style name="Widget.Holo.TabWidget" parent="Widget.TabWidget">
+        <item name="android:textAppearance">@style/TextAppearance.Holo.Widget.TabWidget</item>
+        <item name="android:tabStripLeft">@null</item>
+        <item name="android:tabStripRight">@null</item>
+        <item name="android:tabStripEnabled">false</item>
+        <item name="android:divider">@null</item>
+        <item name="android:gravity">left|center_vertical</item>
+        <item name="android:tabLayout">@android:layout/tab_indicator_holo_large</item>
+    </style>
+</resources>
+
diff --git a/core/res/res/values-th/strings.xml b/core/res/res/values-th/strings.xml
index f05409c..be958dc 100644
--- a/core/res/res/values-th/strings.xml
+++ b/core/res/res/values-th/strings.xml
@@ -265,6 +265,10 @@
     <string name="permdesc_bindDeviceAdmin" msgid="8714424333082216979">"อนุญาตให้ผู้ถือส่งเนื้อหาไปยังโปรแกรมควบคุมอุปกรณ์ ไม่ควรต้องใช้สำหรับแอปพลิเคชันทั่วไป"</string>
     <string name="permlab_setOrientation" msgid="3365947717163866844">"เปลี่ยนการวางแนวหน้าจอ"</string>
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"อนุญาตให้แอปพลิเคชันเปลี่ยนการหมุนหน้าจอได้ตลอดเวลา ไม่ควรต้องใช้สำหรับแอปพลิเคชันทั่วไป"</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <string name="permlab_signalPersistentProcesses" msgid="4255467255488653854">"ส่งสัญญาณ Linux ไปยังแอปพลิเคชัน"</string>
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"อนุญาตให้แอปพลิเคชันร้องขอให้ส่งสัญญาณแจ้งไปยังกระบวนการที่ยังทำงานอยู่ทั้งหมด"</string>
     <string name="permlab_persistentActivity" msgid="8659652042401085862">"ทำให้แอปพลิเคชันทำงานตลอดเวลา"</string>
@@ -836,6 +840,12 @@
     <string name="launch_warning_title" msgid="8323761616052121936">"เปลี่ยนเส้นทางแอปพลิเคชัน"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g> กำลังทำงานอยู่ในขณะนี้"</string>
     <string name="launch_warning_original" msgid="188102023021668683">"<xliff:g id="APP_NAME">%1$s</xliff:g> เปิดใช้ไว้แล้ว"</string>
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"แอปพลิเคชัน <xliff:g id="APPLICATION">%1$s</xliff:g> (กระบวนการ <xliff:g id="PROCESS">%2$s</xliff:g>) ละเมิดนโยบาย StrictMode ที่บังคับใช้ด้วยตัวเอง"</string>
     <string name="smv_process" msgid="5120397012047462446">"กระบวนการ <xliff:g id="PROCESS">%1$s</xliff:g> ละเมิดนโยบาย StrictMode ที่บังคับใช้ด้วยตัวเอง"</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g> กำลังทำงาน"</string>
@@ -1041,4 +1051,6 @@
     <string name="storage_internal" msgid="7556050805474115618">"ที่เก็บข้อมูลภายใน"</string>
     <string name="storage_sd_card" msgid="8921771478629812343">"การ์ด SD"</string>
     <string name="storage_usb" msgid="3017954059538517278">"ที่เก็บข้อมูล USB"</string>
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-tl/strings.xml b/core/res/res/values-tl/strings.xml
index 72d361b..b6942a4 100644
--- a/core/res/res/values-tl/strings.xml
+++ b/core/res/res/values-tl/strings.xml
@@ -265,6 +265,10 @@
     <string name="permdesc_bindDeviceAdmin" msgid="8714424333082216979">"Pinapayagan ang holder na magpadala ng mga intensyon sa administrator ng device. Hindi kailanman dapat kailanganin para sa mga normal na application."</string>
     <string name="permlab_setOrientation" msgid="3365947717163866844">"baguhin ang orientation ng screen"</string>
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"Pinapayagan ang isang application na baguhin ang pag-rotate ng screen anumang oras. Hindi kailanman dapat kailanganin para sa mga normal na application."</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <string name="permlab_signalPersistentProcesses" msgid="4255467255488653854">"magpadala ng mga Linux signal sa mga application"</string>
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"Pinapayagan ang application na hilinging ipadala ang na-supply na signal sa lahat ng mga paulit-ulit na proseso."</string>
     <string name="permlab_persistentActivity" msgid="8659652042401085862">"palaging patakbuhin ang mga application"</string>
@@ -836,6 +840,12 @@
     <string name="launch_warning_title" msgid="8323761616052121936">"Ni-redirect application"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"Tumatakbo na ngayon ang <xliff:g id="APP_NAME">%1$s</xliff:g>."</string>
     <string name="launch_warning_original" msgid="188102023021668683">"Orihinal na nalunsad ang <xliff:g id="APP_NAME">%1$s</xliff:g>."</string>
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"Ang application na <xliff:g id="APPLICATION">%1$s</xliff:g> (prosesong <xliff:g id="PROCESS">%2$s</xliff:g>) ay lumabag sa sarili nitong ipinapatupad na patakarang StrictMode."</string>
     <string name="smv_process" msgid="5120397012047462446">"Ang prosesong <xliff:g id="PROCESS">%1$s</xliff:g> ay lumabag sa sarili nitong ipinapatupad na patakarang StrictMode."</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"Tumatakbo ang <xliff:g id="APP">%1$s</xliff:g>"</string>
@@ -1041,4 +1051,6 @@
     <string name="storage_internal" msgid="7556050805474115618">"Panloob na Storage"</string>
     <string name="storage_sd_card" msgid="8921771478629812343">"SD Card"</string>
     <string name="storage_usb" msgid="3017954059538517278">"USB storage"</string>
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-tr/strings.xml b/core/res/res/values-tr/strings.xml
index 8688dd8..e97d834 100644
--- a/core/res/res/values-tr/strings.xml
+++ b/core/res/res/values-tr/strings.xml
@@ -265,6 +265,10 @@
     <string name="permdesc_bindDeviceAdmin" msgid="8714424333082216979">"Cihazın sahibinin cihaz yöneticisine amaç göndermesine izin verir. Normal uygulamalarda hiçbir zaman gerek duyulmamalıdır."</string>
     <string name="permlab_setOrientation" msgid="3365947717163866844">"ekran yönünü değiştir"</string>
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"Uygulamaların ekran yönünü istedikleri zaman değiştirmesine izin verir. Normal uygulamalarda hiçbir zaman gerekmemelidir."</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <string name="permlab_signalPersistentProcesses" msgid="4255467255488653854">"uygulamalara Linux sinyalleri gönder"</string>
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"Uygulamaların, sağlanan sinyalin tüm kalıcı işlemlere gönderilmesini istemesine izin verir."</string>
     <string name="permlab_persistentActivity" msgid="8659652042401085862">"uygulamayı her zaman çalıştır"</string>
@@ -836,6 +840,12 @@
     <string name="launch_warning_title" msgid="8323761616052121936">"Uygulama yönlendirildi"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g> şimdi çalışıyor."</string>
     <string name="launch_warning_original" msgid="188102023021668683">"İlk olarak <xliff:g id="APP_NAME">%1$s</xliff:g> başlatıldı."</string>
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"<xliff:g id="APPLICATION">%1$s</xliff:g> uygulaması (<xliff:g id="PROCESS">%2$s</xliff:g> işlemi) kendiliğinden uyguladığı StrictMode politikasını ihlal etti."</string>
     <string name="smv_process" msgid="5120397012047462446">"<xliff:g id="PROCESS">%1$s</xliff:g> işlemi kendiliğinden uyguladığı StrictMode politikasını ihlal etti."</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g> çalışıyor"</string>
@@ -1041,4 +1051,6 @@
     <string name="storage_internal" msgid="7556050805474115618">"Dahili Depolama"</string>
     <string name="storage_sd_card" msgid="8921771478629812343">"SD Kart"</string>
     <string name="storage_usb" msgid="3017954059538517278">"USB depolama birimi"</string>
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-uk/strings.xml b/core/res/res/values-uk/strings.xml
index 7cd9ce1..07b11f7 100644
--- a/core/res/res/values-uk/strings.xml
+++ b/core/res/res/values-uk/strings.xml
@@ -265,6 +265,10 @@
     <string name="permdesc_bindDeviceAdmin" msgid="8714424333082216979">"Дозволяє власнику надсилати цілі адміністратору пристрою. Ніколи не потрібний для звичайних програм."</string>
     <string name="permlab_setOrientation" msgid="3365947717163866844">"змінювати орієнтацію екрана"</string>
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"Дозволяє програмі будь-коли змінювати обертання екрана. Ніколи не потрібний для звичайних програм."</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <string name="permlab_signalPersistentProcesses" msgid="4255467255488653854">"надсилати сигнали Linux програмам"</string>
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"Дозволяє програмі подавати запит щодо надсилання наданого сигналу всім постійним процесам."</string>
     <string name="permlab_persistentActivity" msgid="8659652042401085862">"збер. програму завжди запущ."</string>
@@ -836,6 +840,12 @@
     <string name="launch_warning_title" msgid="8323761616052121936">"Програму переадресовано"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"Зараз працює <xliff:g id="APP_NAME">%1$s</xliff:g>."</string>
     <string name="launch_warning_original" msgid="188102023021668683">"Спочатку було запущено <xliff:g id="APP_NAME">%1$s</xliff:g>."</string>
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"Програма <xliff:g id="APPLICATION">%1$s</xliff:g> (процес <xliff:g id="PROCESS">%2$s</xliff:g>) порушила свою самозастосовну політику StrictMode."</string>
     <string name="smv_process" msgid="5120397012047462446">"Процес <xliff:g id="PROCESS">%1$s</xliff:g> порушив свою самозастосовну політику StrictMode."</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"Працює <xliff:g id="APP">%1$s</xliff:g>"</string>
@@ -1041,4 +1051,6 @@
     <string name="storage_internal" msgid="7556050805474115618">"Внутрішня пам’ять"</string>
     <string name="storage_sd_card" msgid="8921771478629812343">"Картка SD"</string>
     <string name="storage_usb" msgid="3017954059538517278">"Носій USB"</string>
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-vi/strings.xml b/core/res/res/values-vi/strings.xml
index eb4aee3..cfb53ac 100644
--- a/core/res/res/values-vi/strings.xml
+++ b/core/res/res/values-vi/strings.xml
@@ -265,6 +265,10 @@
     <string name="permdesc_bindDeviceAdmin" msgid="8714424333082216979">"Cho phép chủ nhân gửi các ý định đến quản trị viên thiết bị. Không cần thiết cho các ứng dụng thông thường."</string>
     <string name="permlab_setOrientation" msgid="3365947717163866844">"thay đổi hướng màn hình"</string>
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"Cho phép ứng dụng thay đổi việc xoay màn hình bất kỳ khi nào. Không cần thiết cho các ứng dụng thông thường."</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <string name="permlab_signalPersistentProcesses" msgid="4255467255488653854">"gửi tín hiệu Linux đến ứng dụng"</string>
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"Cho phép ứng dụng yêu cầu tín hiệu đã cung cấp được gửi đến tất cả các quá trình liên tục."</string>
     <string name="permlab_persistentActivity" msgid="8659652042401085862">"đặt ứng dụng luôn chạy"</string>
@@ -836,6 +840,12 @@
     <string name="launch_warning_title" msgid="8323761616052121936">"Ứng dụng đã được chuyển hướng"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g> hiện đang chạy."</string>
     <string name="launch_warning_original" msgid="188102023021668683">"<xliff:g id="APP_NAME">%1$s</xliff:g> được khởi chạy trước tiên."</string>
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"Ứng dụng <xliff:g id="APPLICATION">%1$s</xliff:g> (quá trình <xliff:g id="PROCESS">%2$s</xliff:g>) đã vi phạm chính sách StrictMode tự thi hành của mình."</string>
     <string name="smv_process" msgid="5120397012047462446">"Quá trình <xliff:g id="PROCESS">%1$s</xliff:g> đã vi phạm chính sách StrictMode tự thi hành của mình."</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g> đang hoạt động"</string>
@@ -1041,4 +1051,6 @@
     <string name="storage_internal" msgid="7556050805474115618">"Bộ nhớ trong"</string>
     <string name="storage_sd_card" msgid="8921771478629812343">"Thẻ SD"</string>
     <string name="storage_usb" msgid="3017954059538517278">"Bộ lưu trữ USB"</string>
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-xlarge/dimens.xml b/core/res/res/values-xlarge/dimens.xml
index b906e1a..c15770d 100644
--- a/core/res/res/values-xlarge/dimens.xml
+++ b/core/res/res/values-xlarge/dimens.xml
@@ -18,13 +18,6 @@
 */
 -->
 <resources>
-    <!-- Height of the status bar -->
-    <dimen name="status_bar_height">48dip</dimen>
-    <!-- Width and height of a single notification icon in the status bar -->
-    <dimen name="status_bar_icon_size">32dip</dimen>
-    <!-- Size of the giant number (unread count) in the notifications -->
-    <dimen name="status_bar_content_number_size">48sp</dimen>
-
     <!-- Default height of a key in the password keyboard for alpha -->
     <dimen name="password_keyboard_key_height_alpha">75dip</dimen>
     <!-- Default height of a key in the password keyboard for numeric -->
diff --git a/core/res/res/values-xlarge/styles.xml b/core/res/res/values-xlarge/styles.xml
deleted file mode 100644
index 7515c98..0000000
--- a/core/res/res/values-xlarge/styles.xml
+++ /dev/null
@@ -1,55 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2010 The Android Open Source Project
-
-     Licensed under the Apache License, Version 2.0 (the "License");
-     you may not use this file except in compliance with the License.
-     You may obtain a copy of the License at
-  
-          http://www.apache.org/licenses/LICENSE-2.0
-  
-     Unless required by applicable law or agreed to in writing, software
-     distributed under the License is distributed on an "AS IS" BASIS,
-     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-     See the License for the specific language governing permissions and
-     limitations under the License.
--->
-
-<resources>
-    <!-- Status Bar Styles -->
-
-    <style name="TextAppearance.StatusBar">
-        <item name="android:textAppearance">?android:attr/textAppearanceSmall</item>
-    </style>
-    <style name="TextAppearance.StatusBar.Ticker">
-    </style>
-    <style name="TextAppearance.StatusBar.Title">
-        <item name="android:textStyle">bold</item>
-    </style>
-
-    <style name="TextAppearance.StatusBar.Icon">
-    </style>
-    <style name="TextAppearance.StatusBar.EventContent">
-        <item name="android:textColor">#ff999999</item>
-        <item name="android:textSize">14sp</item>
-    </style>
-    <style name="TextAppearance.StatusBar.EventContent.Title">
-        <item name="android:textColor">?android:attr/textColorPrimary</item>
-    </style>
-
-    <style name="TextAppearance.Holo.Widget.TabWidget">
-        <item name="android:textSize">18sp</item>
-        <item name="android:textStyle">normal</item>
-        <item name="android:textColor">@android:color/tab_indicator_text</item>
-    </style>
-    
-    <style name="Widget.Holo.TabWidget" parent="Widget.TabWidget">
-        <item name="android:textAppearance">@style/TextAppearance.Holo.Widget.TabWidget</item>
-        <item name="android:tabStripLeft">@null</item>
-        <item name="android:tabStripRight">@null</item>
-        <item name="android:tabStripEnabled">false</item>
-        <item name="android:divider">@null</item>
-        <item name="android:gravity">left|center_vertical</item>
-        <item name="android:tabLayout">@android:layout/tab_indicator_holo_large</item>
-    </style>
-</resources>
-
diff --git a/core/res/res/values-zh-rCN/strings.xml b/core/res/res/values-zh-rCN/strings.xml
index 134845a..b45b346 100644
--- a/core/res/res/values-zh-rCN/strings.xml
+++ b/core/res/res/values-zh-rCN/strings.xml
@@ -265,6 +265,10 @@
     <string name="permdesc_bindDeviceAdmin" msgid="8714424333082216979">"允许持有对象将意向发送到设备管理器。普通的应用程序一律无需此权限。"</string>
     <string name="permlab_setOrientation" msgid="3365947717163866844">"更改屏幕显示方向"</string>
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"允许应用程序随时更改屏幕的旋转方向。普通应用程序从不需要使用此权限。"</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <string name="permlab_signalPersistentProcesses" msgid="4255467255488653854">"向应用程序发送 Linux 信号"</string>
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"允许应用程序请求将所提供的信号发送给所有持久进程。"</string>
     <string name="permlab_persistentActivity" msgid="8659652042401085862">"让应用程序始终运行"</string>
@@ -836,6 +840,12 @@
     <string name="launch_warning_title" msgid="8323761616052121936">"应用程序已重定向"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g>目前正在运行。"</string>
     <string name="launch_warning_original" msgid="188102023021668683">"<xliff:g id="APP_NAME">%1$s</xliff:g>已启动。"</string>
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"应用程序<xliff:g id="APPLICATION">%1$s</xliff:g>(<xliff:g id="PROCESS">%2$s</xliff:g> 进程)违反了自我强制执行的严格模式 (StrictMode) 政策。"</string>
     <string name="smv_process" msgid="5120397012047462446">"进程 <xliff:g id="PROCESS">%1$s</xliff:g> 违反了自我强制执行的严格模式 (StrictMode) 政策。"</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g>正在运行"</string>
@@ -1041,4 +1051,6 @@
     <string name="storage_internal" msgid="7556050805474115618">"内存空间"</string>
     <string name="storage_sd_card" msgid="8921771478629812343">"SD 卡"</string>
     <string name="storage_usb" msgid="3017954059538517278">"USB 存储器"</string>
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-zh-rTW/strings.xml b/core/res/res/values-zh-rTW/strings.xml
index 7075677..399a5b0 100644
--- a/core/res/res/values-zh-rTW/strings.xml
+++ b/core/res/res/values-zh-rTW/strings.xml
@@ -241,7 +241,7 @@
     <string name="permlab_backup" msgid="470013022865453920">"控制系統備份與還原"</string>
     <string name="permdesc_backup" msgid="4837493065154256525">"允許應用程式控制系統的備份與還原機制。一般應用程式不應使用這項功能。"</string>
     <string name="permlab_confirm_full_backup" msgid="5557071325804469102">"確認完整備份或還原作業"</string>
-    <string name="permdesc_confirm_full_backup" msgid="9005017754175897954">"允許應用程式啟動完整備份確認使用者界面,任何應用程式均不應使用這項功能。"</string>
+    <string name="permdesc_confirm_full_backup" msgid="9005017754175897954">"允許應用程式啟動完整備份確認使用者介面,任何應用程式均不應使用這項功能。"</string>
     <string name="permlab_internalSystemWindow" msgid="2148563628140193231">"顯示未授權視窗"</string>
     <string name="permdesc_internalSystemWindow" msgid="5895082268284998469">"允許內部系統使用介面建立視窗。一般應用程式不會使用此功能。"</string>
     <string name="permlab_systemAlertWindow" msgid="3372321942941168324">"顯示系統警示"</string>
@@ -265,6 +265,10 @@
     <string name="permdesc_bindDeviceAdmin" msgid="8714424333082216979">"允許應用程式將調用請求 (intent) 傳送至裝置管理員;一般應用程式不需使用此選項。"</string>
     <string name="permlab_setOrientation" msgid="3365947717163866844">"變更螢幕顯示方向"</string>
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"允許應用程式可隨時變更螢幕旋轉方向。一般應用不應使用這項功能。"</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <string name="permlab_signalPersistentProcesses" msgid="4255467255488653854">"傳送 Linux 訊號到應用程式"</string>
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"允許應用程式要求將支援的訊號傳送到所有持續的程序。"</string>
     <string name="permlab_persistentActivity" msgid="8659652042401085862">"設定應用程式持續執行"</string>
@@ -836,6 +840,12 @@
     <string name="launch_warning_title" msgid="8323761616052121936">"應用程式已重新導向"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"「<xliff:g id="APP_NAME">%1$s</xliff:g>」現在正在執行。"</string>
     <string name="launch_warning_original" msgid="188102023021668683">"「<xliff:g id="APP_NAME">%1$s</xliff:g>」原先已啟動。"</string>
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"應用程式 <xliff:g id="APPLICATION">%1$s</xliff:g> (處理程序 <xliff:g id="PROCESS">%2$s</xliff:g>) 已違反其自行強制實施的嚴格模式 (StrictMode) 政策。"</string>
     <string name="smv_process" msgid="5120397012047462446">"處理程序 <xliff:g id="PROCESS">%1$s</xliff:g> 已違反其自行強制實施的嚴格模式 (StrictMode) 政策。"</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g> 執行中"</string>
@@ -1041,4 +1051,6 @@
     <string name="storage_internal" msgid="7556050805474115618">"內部儲存空間"</string>
     <string name="storage_sd_card" msgid="8921771478629812343">"SD 卡"</string>
     <string name="storage_usb" msgid="3017954059538517278">"USB 儲存裝置"</string>
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values-zu/strings.xml b/core/res/res/values-zu/strings.xml
index 9fda350..6f147e7 100644
--- a/core/res/res/values-zu/strings.xml
+++ b/core/res/res/values-zu/strings.xml
@@ -396,6 +396,10 @@
     <!-- no translation found for permlab_setOrientation (3365947717163866844) -->
     <skip />
     <string name="permdesc_setOrientation" msgid="6335814461615851863">"Ivumela uhlelo lokusebenza ukushintsha ukujikeleleza kwesikrini nganoma isiphi isikhathi. Ayisoze yadingeka izinhlelo zokusebenza ezivamile."</string>
+    <!-- no translation found for permlab_setPointerSpeed (9175371613322562934) -->
+    <skip />
+    <!-- no translation found for permdesc_setPointerSpeed (137436038503379864) -->
+    <skip />
     <!-- no translation found for permlab_signalPersistentProcesses (4255467255488653854) -->
     <skip />
     <string name="permdesc_signalPersistentProcesses" msgid="3565530463215015289">"Ivumela uhlelo lokusebenza ukucela ukuthi isiginali enikeziwe ithunyelwe kuzo zonke izinqubo eziphikelelayo"</string>
@@ -1154,6 +1158,12 @@
     <string name="launch_warning_title" msgid="8323761616052121936">"Uhlelo lokusebenza luqondisiwe futhi"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g> iyasebenza."</string>
     <string name="launch_warning_original" msgid="188102023021668683">"<xliff:g id="APP_NAME">%1$s</xliff:g> iqalisiwe."</string>
+    <!-- no translation found for screen_compat_mode_scale (3202955667675944499) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_show (4013878876486655892) -->
+    <skip />
+    <!-- no translation found for screen_compat_mode_hint (2953716574198046484) -->
+    <skip />
     <string name="smv_application" msgid="295583804361236288">"Inqubo <xliff:g id="APPLICATION">%1$s</xliff:g> (yohlelo lokusebenza <xliff:g id="PROCESS">%2$s</xliff:g>) iphule inqubomgomo oziphoqelela yona Yemodi Ebukhali."</string>
     <string name="smv_process" msgid="5120397012047462446">"Inqubo <xliff:g id="PROCESS">%1$s</xliff:g> yephule inqubomgomo yokuziphoqelela Yemodi Ebukhali."</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g> iyasebenza"</string>
@@ -1423,4 +1433,6 @@
     <skip />
     <!-- no translation found for storage_usb (3017954059538517278) -->
     <skip />
+    <!-- no translation found for extract_edit_menu_button (302060189057163906) -->
+    <skip />
 </resources>
diff --git a/core/res/res/values/arrays.xml b/core/res/res/values/arrays.xml
index 810c3b2..0f04a67 100644
--- a/core/res/res/values/arrays.xml
+++ b/core/res/res/values/arrays.xml
@@ -333,4 +333,19 @@
         <item>中文 (繁體)</item>
     </string-array>
 
+    <!-- Resources for MultiWaveView in LockScreen -->
+    <array name="lockscreen_targets_when_silent">
+        <item>@drawable/ic_lockscreen_unlock</item>
+        <item>@null</item>
+        <item>@drawable/ic_lockscreen_soundon</item>
+        <item>@null</item>
+    </array>
+
+    <array name="lockscreen_targets_when_soundon">
+        <item>@drawable/ic_lockscreen_unlock</item>
+        <item>@null</item>
+        <item>@drawable/ic_lockscreen_silent</item>
+        <item>@null</item>"
+    </array>
+
 </resources>
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index bbbca37..989adbd 100755
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -202,9 +202,14 @@
 
         <!-- The preferred list item height. -->
         <attr name="listPreferredItemHeight" format="dimension" />
-        <!-- The drawable for the list divider. -->
+        <!-- A smaller, sleeker list item height. -->
+        <attr name="listPreferredItemHeightSmall" format="dimension" />
+        <!-- A larger, more robust list item height. -->
+        <attr name="listPreferredItemHeightLarge" format="dimension" />
         <!-- The list item height for search results. @hide -->
         <attr name="searchResultListItemHeight" format="dimension" />
+
+        <!-- The drawable for the list divider. -->
         <attr name="listDivider" format="reference" />
         <!-- The list divider used in alert dialogs. -->
         <attr name="listDividerAlertDialog" format="reference" />
@@ -374,11 +379,11 @@
              pointer will go until that pointers go up thereby enabling touches
              with multiple pointers to be split across multiple windows. -->
         <attr name="windowEnableSplitTouch" format="boolean" />
-        
+
         <!-- Control whether a container should automatically close itself if
              the user touches outside of it.  This only applies to activities
              and dialogs.
-             
+
              <p>Note: this attribute will only be respected for applications
              that are targeting {@link android.os.Build.VERSION_CODES#HONEYCOMB}
              or later. -->
@@ -548,7 +553,7 @@
         <!-- NumberPicker input text style. -->
         <attr name="numberPickerInputTextStyle" format="reference" />
 
-        <!-- The CalndarView style. -->
+        <!-- The CalendarView style. -->
         <attr name="calendarViewStyle" format="reference" />
 
         <!-- The TimePicker style. -->
@@ -619,6 +624,8 @@
         <attr name="actionModeCopyDrawable" format="reference" />
         <!-- Drawable to use for the Paste action button in Contextual Action Bar -->
         <attr name="actionModePasteDrawable" format="reference" />
+        <!-- Drawable to use for the Select all action button in Contextual Action Bar -->
+        <attr name="actionModeSelectAllDrawable" format="reference" />
         <!-- Drawable to use for the Share action button in WebView selection action modes -->
         <attr name="actionModeShareDrawable" format="reference" />
         <!-- Drawable to use for the Find action button in WebView selection action modes -->
@@ -656,6 +663,8 @@
         <attr name="preferenceLayoutChild" format="reference" />
         <!-- Preference panel style -->
         <attr name="preferencePanelStyle" format="reference" />
+        <!-- Default style for switch preferences. -->
+        <attr name="switchPreferenceStyle" format="reference" />
 
         <!-- ============================ -->
         <!-- Text selection handle styles -->
@@ -1129,9 +1138,9 @@
              edge, a right gravity will clip the left edge, and neither will clip both edges. -->
         <flag name="clip_horizontal" value="0x08" />
         <!-- Push object to the beginning of its container, not changing its size. -->
-        <flag name="before" value="0x00800003" />
+        <flag name="start" value="0x00800003" />
         <!-- Push object to the end of its container, not changing its size. -->
-        <flag name="after" value="0x00800005" />
+        <flag name="end" value="0x00800005" />
     </attr>
 
     <!-- Controls whether links such as urls and email addresses are
@@ -1189,9 +1198,9 @@
              edge, a right gravity will clip the left edge, and neither will clip both edges. -->
         <flag name="clip_horizontal" value="0x08" />
         <!-- Push object to the beginning of its container, not changing its size. -->
-        <flag name="before" value="0x00800003" />
+        <flag name="start" value="0x00800003" />
         <!-- Push object to the end of its container, not changing its size. -->
-        <flag name="after" value="0x00800005" />
+        <flag name="end" value="0x00800005" />
     </attr>
 
     <!-- Standard orientation constant. -->
@@ -1202,6 +1211,16 @@
         <enum name="vertical" value="1" />
     </attr>
 
+    <!-- Alignment constants. -->
+    <attr name="alignmentMode">
+        <!-- Align the bounds of the children.
+        See {@link android.widget.GridLayout#ALIGN_BOUNDS}. -->
+        <enum name="alignBounds" value="0" />
+        <!-- Align the margins of the children.
+        See {@link android.widget.GridLayout#ALIGN_MARGINS}. -->
+        <enum name="alignMargins" value="1" />
+    </attr>
+
     <!-- ========================== -->
     <!-- Key Codes                  -->
     <!-- ========================== -->
@@ -1642,6 +1661,10 @@
         <attr name="paddingRight" format="dimension" />
         <!-- Sets the padding, in pixels, of the bottom edge; see {@link android.R.attr#padding}. -->
         <attr name="paddingBottom" format="dimension" />
+        <!-- Sets the padding, in pixels, of the start edge; see {@link android.R.attr#padding}. -->
+        <attr name="paddingStart" format="dimension" />
+        <!-- Sets the padding, in pixels, of the end edge; see {@link android.R.attr#padding}. -->
+        <attr name="paddingEnd" format="dimension" />
 
         <!-- Boolean that controls whether a view can take focus.  By default the user can not
              move focus to a view; by setting this attribute to true the view is
@@ -1912,7 +1935,7 @@
             <!-- Place the scroll bar on the right. -->
             <enum name="right" value="2" />
         </attr>
-        
+
         <!-- Specifies the type of layer backing this view. The default value is none.
              Refer to {@link android.view.View#setLayerType(int, android.graphics.Paint)}
              for more information.-->
@@ -1930,11 +1953,11 @@
         </attr>
 
         <!-- Defines the direction of layout drawing. This typically is associated with writing
-             direction of the language script used. The possible values are Left-to-Right,
-             Right-to-Left, Locale and Inherit from parent view. If there is nothing to inherit,
-             Locale is used. Locale fallsback to 'en-US'. Left-to-Right is the direction used in
-             'en-US'. The default for this attribute is 'inherit'. -->
-        <attr name="horizontalDirection">
+             direction of the language script used. The possible values are "ltr" for Left-to-Right,
+             "rtl" for Right-to-Left, "locale" and "inherit" from parent view. If there is nothing
+             to inherit, "locale" is used. "locale" falls back to "en-US". "ltr" is the direction
+             used in "en-US". The default for this attribute is "inherit". -->
+        <attr name="layoutDirection">
             <!-- Left-to-Right -->
             <enum name="ltr" value="0" />
             <!-- Right-to-Left -->
@@ -2147,6 +2170,82 @@
         <attr name="imeSubtypeExtraValue" format="string" />
     </declare-styleable>
 
+    <!-- Use <code>accessibility-service</code> as the root tag of the XML resource that
+         describes an {@link android.accessibilityservice.AccessibilityService} service,
+         which is referenced from its
+         {@link android.accessibilityservice.AccessibilityService#SERVICE_META_DATA}
+         meta-data entry. -->
+    <declare-styleable name="AccessibilityService">
+        <!-- The event types this serivce would like to receive as specified in
+             {@link android.view.accessibility.AccessibilityEvent}. This setting
+             can be changed at runtime by calling
+             {@link android.accessibilityservice.AccessibilityService#setServiceInfo(android.accessibilityservice.AccessibilityServiceInfo)}. -->
+        <attr name="accessibilityEventTypes">
+            <!-- Receives {@link android.view.accessibility.AccessibilityEvent#TYPE_VIEW_CLICKED} events.-->
+            <flag name="typeViewClicked" value="0x00000001" />
+            <!-- Receives {@link android.view.accessibility.AccessibilityEvent#TYPE_VIEW_LONG_CLICKED} events. -->
+            <flag name="typeViewLongClicked" value="0x00000002" />
+            <!-- Receives {@link android.view.accessibility.AccessibilityEvent#TYPE_VIEW_SELECTED} events. -->
+            <flag name="typeViewSelected" value="0x00000004" />
+            <!-- Receives {@link android.view.accessibility.AccessibilityEvent#TYPE_VIEW_FOCUSED} events. -->
+            <flag name="typeViewFocused" value="0x00000008" />
+            <!-- Receives {@link android.view.accessibility.AccessibilityEvent#TYPE_VIEW_TEXT_CHANGED} events. -->
+            <flag name="typeViewTextChanged" value="0x00000010" />
+            <!-- Receives {@link android.view.accessibility.AccessibilityEvent#TYPE_WINDOW_STATE_CHANGED} events. -->
+            <flag name="typeWindowStateChanged" value="0x00000020" />
+            <!-- Receives {@link android.view.accessibility.AccessibilityEvent#TYPE_NOTIFICATION_STATE_CHANGED} events. -->
+            <flag name="typeNotificationStateChanged" value="0x00000040" />
+            <!-- Receives {@link android.view.accessibility.AccessibilityEvent#TYPE_VIEW_HOVER_ENTER} events. -->
+            <flag name="typeViewHoverEnter" value="0x00000080" />
+            <!-- Receives {@link android.view.accessibility.AccessibilityEvent#TYPE_VIEW_HOVER_EXIT} events. -->
+            <flag name="typeViewHoverExit" value="0x00000100" />
+            <!-- Receives {@link android.view.accessibility.AccessibilityEvent#TYPE_TOUCH_EXPLORATION_GESTURE_START} events. -->
+            <flag name="typeTouchExplorationGestureStart" value="0x00000200" />
+            <!-- Receives {@link android.view.accessibility.AccessibilityEvent#TYPE_TOUCH_EXPLORATION_GESTURE_END} events. -->
+            <flag name="typeTouchExplorationGestureEnd" value="0x00000400" />
+            <!-- Receives {@link android.view.accessibility.AccessibilityEvent#TYPES_ALL_MASK} i.e. all events. -->
+            <flag name="typeAllMask" value="0xffffffff" />
+        </attr>
+        <!-- Comma separated package names from which this serivce would like to receive events (leave out for all packages).
+             This setting can be changed at runtime by calling
+             {@link android.accessibilityservice.AccessibilityService#setServiceInfo(android.accessibilityservice.AccessibilityServiceInfo)}. -->
+        <attr name="packageNames" format="string" />
+        <!-- The feedback types this serivce provides as specified in
+             {@link android.accessibilityservice.AccessibilityServiceInfo}. This setting
+             can be changed at runtime by calling
+             {@link android.accessibilityservice.AccessibilityService#setServiceInfo(android.accessibilityservice.AccessibilityServiceInfo)}. -->
+        <attr name="accessibilityFeedbackType">
+            <!-- Provides {@link android.accessibilityservice.AccessibilityServiceInfo#FEEDBACK_SPOKEN} feedback. -->
+            <flag name="feedbackSpoken" value="0x00000001" />
+            <!-- Provides {@link android.accessibilityservice.AccessibilityServiceInfo#FEEDBACK_HAPTIC} feedback. -->
+            <flag name="feedbackHaptic" value="0x00000002" />
+            <!-- Provides {@link android.accessibilityservice.AccessibilityServiceInfo#FEEDBACK_AUDIBLE} feedback. -->
+            <flag name="feedbackAudible" value="0x00000004" />
+            <!-- Provides {@link android.accessibilityservice.AccessibilityServiceInfo#FEEDBACK_VISUAL} feedback. -->
+            <flag name="feedbackVisual" value="0x00000008" />
+            <!-- Provides {@link android.accessibilityservice.AccessibilityServiceInfo#FEEDBACK_GENERIC} feedback. -->
+            <flag name="feedbackGeneric" value="0x00000010" />
+        </attr>
+        <!-- The minimal period in milliseconds between two accessibility events are sent
+             to this serivce. This setting can be changed at runtime by calling
+             {@link android.accessibilityservice.AccessibilityService#setServiceInfo(android.accessibilityservice.AccessibilityServiceInfo)}. -->
+        <attr name="notificationTimeout" format="integer" />
+        <!-- Additional flags as specified in
+             {@link android.accessibilityservice.AccessibilityServiceInfo}.
+             This setting can be changed at runtime by calling
+             {@link android.accessibilityservice.AccessibilityService#setServiceInfo(android.accessibilityservice.AccessibilityServiceInfo)}. -->
+        <attr name="accessibilityFlags">
+            <!-- Has flag {@link android.accessibilityservice.AccessibilityServiceInfo#DEFAULT} -->
+            <flag name="flagDefault" value="0x00000001" />
+        </attr>
+        <!-- Component name of an activity that allows the user to modify
+             the settings for this service. This setting cannot be changed at runtime. -->
+        <attr name="settingsActivity" />
+        <!-- Flag whether the accessibility service wants to be able to retrieve the
+             focused window content. This setting cannot be changed at runtime. -->
+        <attr name="canRetrieveWindowContent" format="boolean" />
+    </declare-styleable>
+
     <!-- =============================== -->
     <!-- Widget package class attributes -->
     <!-- =============================== -->
@@ -2444,10 +2543,10 @@
     </declare-styleable>
     <declare-styleable name="GridLayout">
         <!-- The orientation property is not used during layout. It is only used to
-        allocate row and column prameters when they are not specified by its children's
+        allocate row and column parameters when they are not specified by its children's
         layout paramters. GridLayout works like LinearLayout in this case;
         putting all the components either in a single row or in a single column -
-        depending on the value of this flag. In the horozintal case, a columnCount
+        depending on the value of this flag. In the horizontal case, a columnCount
         property may be additionally supplied to force new rows to be created when a
         row is full. The rowCount attribute may be used similarly in the vertical case.
         The default is horizontal. -->
@@ -2461,6 +2560,12 @@
         The default value is false.
         See {@link android.widget.GridLayout#setUseDefaultMargins(boolean)}.-->
         <attr name="useDefaultMargins" format="boolean" />
+        <!-- When set to alignMargins, causes alignment to take place between the outer
+        boundary of a view, as defined by its margins. When set to alignBounds,
+        causes alignment to take place between the edges of the view.
+        The default is alignMargins.
+        See {@link android.widget.GridLayout#setAlignmentMode(int)}.-->
+        <attr name="alignmentMode" />
         <!-- When set to true, forces row boundaries to appear in the same order
         as row indices.
         The default is false.
@@ -3178,9 +3283,9 @@
         <!-- The row span: the difference between the bottom and top
         boundaries delimiting the group of cells occupied by this view.
         The default is one.
-        See {@link android.widget.GridLayout.Group#span}. -->
+        See {@link android.widget.GridLayout.Group}. -->
         <attr name="layout_rowSpan" format="integer" min="1" />
-        <!-- A number indicating the relative proportion of availible space that
+        <!-- A number indicating the relative proportion of available space that
         should be taken by this group of cells.
         The default is zero.
         See {@link android.widget.GridLayout.LayoutParams#columnWeight}. -->
@@ -3191,9 +3296,9 @@
         <!-- The column span: the difference between the right and left
         boundaries delimiting the group of cells occupied by this view.
         The default is one.
-        See {@link android.widget.GridLayout.Group#span}. -->
+        See {@link android.widget.GridLayout.Group}. -->
         <attr name="layout_columnSpan" format="integer" min="1" />
-        <!-- A number indicating the relative proportion of availible space that
+        <!-- A number indicating the relative proportion of available space that
         should be taken by this group of cells.
         The default is zero.
         See {@link android.widget.GridLayout.LayoutParams#columnWeight}.-->
@@ -4404,6 +4509,10 @@
             <!-- When this item is shown as an action in the action bar, show a text
                  label with it even if it has an icon representation. -->
             <flag name="withText" value="4" />
+            <!-- This item's action view collapses to a normal menu
+                 item. When expanded, the action view takes over a
+                 larger segment of its container. -->
+            <flag name="collapseActionView" value="8" />
         </attr>
 
         <!-- An optional layout to be used as an action view.
@@ -4726,7 +4835,7 @@
         <!-- The view id of the AppWidget subview which should be auto-advanced.
              by the widget's host. -->
         <attr name="autoAdvanceViewId" format="reference" />
-        <!-- Optional parameter which indicates if and how this widget can be 
+        <!-- Optional parameter which indicates if and how this widget can be
              resized. -->
         <attr name="resizeMode" format="integer">
             <flag name="none" value="0x0" />
@@ -4919,6 +5028,54 @@
     </declare-styleable>
 
     <!-- =============================== -->
+    <!-- MultiWaveView class attributes -->
+    <!-- =============================== -->
+    <eat-comment />
+    <declare-styleable name="MultiWaveView">
+        <!-- Reference to an array resource that be shown as targets around a circle. -->
+        <attr name="targetDrawables" format="reference"/>
+
+        <!-- Sets a drawable as the drag center. -->
+        <attr name="handleDrawable" format="reference" />
+
+        <!-- Drawable to use for chevron animation on the left. May be null. -->
+        <attr name="leftChevronDrawable" format="reference" />
+
+        <!-- Drawable to use for chevron animation on the right. May be null. -->
+        <attr name="rightChevronDrawable" format="reference" />
+
+        <!-- Drawable to use for chevron animation on the top. May be null. -->
+        <attr name="topChevronDrawable" format="reference" />
+
+        <!-- Drawable to use for chevron animation on the bottom. May be null. -->
+        <attr name="bottomChevronDrawable" format="reference" />
+
+        <!-- Drawable to use for wave ripple animation. -->
+        <attr name="waveDrawable" format="reference" />
+
+        <!-- Outer radius of target circle. Icons will be drawn on this circle. -->
+        <attr name="outerRadius" format="dimension" />
+
+        <!-- Size of target radius. Points within this distance of target center is a "hit". -->
+        <attr name="hitRadius" format="dimension" />
+
+        <!-- Tactile feedback duration for actions. Set to '0' for no vibration. -->
+        <attr name="vibrationDuration" format="integer"/>
+
+        <!-- How close we need to be before snapping to a target. -->
+        <attr name="snapMargin" format="dimension" />
+
+        <!-- Number of waves/chevrons to show in animation. -->
+        <attr name="feedbackCount" format="integer" />
+
+        <!-- Used to shift center of pattern vertically. -->
+        <attr name="verticalOffset" format="dimension" />
+
+        <!-- Used to shift center of pattern horizontally. -->
+        <attr name="horizontalOffset" format="dimension" />
+    </declare-styleable>
+
+    <!-- =============================== -->
     <!-- LockPatternView class attributes -->
     <!-- =============================== -->
     <eat-comment />
@@ -5055,7 +5212,7 @@
     </declare-styleable>
 
     <declare-styleable name="Storage">
-        <!-- path to mount point for the storage --> 
+        <!-- path to mount point for the storage -->
         <attr name="mountPoint" format="string" />
         <!-- user visible description of the storage -->
         <attr name="storageDescription" format="string" />
@@ -5068,6 +5225,28 @@
         <!-- number of megabytes of storage MTP should reserve for free storage
              (used for emulated storage that is shared with system's data partition) -->
         <attr name="mtpReserve" format="integer" />
+        <!-- true if the storage can be shared via USB mass storage -->
+        <attr name="allowMassStorage" format="boolean" />
+    </declare-styleable>
+
+    <declare-styleable name="SwitchPreference">
+        <!-- The summary for the Preference in a PreferenceActivity screen when the
+             SwitchPreference is checked. If separate on/off summaries are not
+             needed, the summary attribute can be used instead. -->
+        <attr name="summaryOn" />
+        <!-- The summary for the Preference in a PreferenceActivity screen when the
+             SwitchPreference is unchecked. If separate on/off summaries are not
+             needed, the summary attribute can be used instead. -->
+        <attr name="summaryOff" />
+        <!-- The text used on the switch itself when in the "on" state.
+             This should be a very SHORT string, as it appears in a small space. -->
+        <attr name="switchTextOn" format="string" />
+        <!-- The text used on the switch itself when in the "off" state.
+             This should be a very SHORT string, as it appears in a small space. -->
+        <attr name="switchTextOff" format="string" />
+        <!-- The state (true for on, or false for off) that causes dependents to be disabled. By default,
+             dependents will be disabled when this is unchecked, so the value of this preference is false. -->
+        <attr name="disableDependentsState" />
     </declare-styleable>
 
 </resources>
diff --git a/core/res/res/values/attrs_manifest.xml b/core/res/res/values/attrs_manifest.xml
index 6b7c2a6..f7974e9 100644
--- a/core/res/res/values/attrs_manifest.xml
+++ b/core/res/res/values/attrs_manifest.xml
@@ -1019,6 +1019,41 @@
          <p>This appears as a child tag of the
          {@link #AndroidManifest manifest} tag. -->
     <declare-styleable name="AndroidManifestSupportsScreens" parent="AndroidManifest">
+        <!-- Starting with {@link android.os.Build.VERSION_CODES#HONEYCOMB_MR2},
+             this is the new way to specify the screens an application is
+             compatible with.  This attribute provides the required minimum
+             "smallest screen width" (as per the -swNNNdp resource configuration)
+             that the application can run on.  For example, a typical phone
+             screen is 320, a 7" tablet 600, and a 10" tablet 720.  If the
+             smallest screen width of the device is below the value supplied here,
+             then the application is considered incompatible with that device.
+             If not supplied, then any old smallScreens, normalScreens, largeScreens,
+             or xlargeScreens attributes will be used instead. -->
+        <attr name="requiresSmallestWidthDp" format="integer" />
+        <!-- Starting with {@link android.os.Build.VERSION_CODES#HONEYCOMB_MR2},
+             this is the new way to specify the screens an application is
+             compatible with.  This attribute provides the maximum
+             "smallest screen width" (as per the -swNNNdp resource configuration)
+             that the application is designed for.  If this value is smaller than
+             the "smallest screen width" of the device it is running on, the user
+             will of offered to run it in a compatibility mode that emulates a
+             smaller screen.  Currently the compatibility mode only emulates
+             phone screens, so it will not be used it the application provides
+             a requiresSmallestWidthDp that is larger than 320.  Typical values
+             used with this attribute are 320 for a phone screen, 600 for a
+             7" tablet, and 720 for a 10" tablet. -->
+        <attr name="compatibleWidthLimitDp" format="integer" />
+        <!-- Starting with {@link android.os.Build.VERSION_CODES#HONEYCOMB_MR2},
+             this is the new way to specify the screens an application is
+             compatible with.  This attribute provides the maximum
+             "smallest screen width" (as per the -swNNNdp resource configuration)
+             that the application can work well on.  If this value is smaller than
+             the "smallest screen width" of the device it is running on, the
+             application will be forced in to screen compatibility mode with
+             no way for the user to turn it off.  Currently the compatibility mode
+             only emulates phone screens, so even if this value is larger than 320
+             the width the app runs in will be a 320 phone dimension. -->
+        <attr name="largestWidthLimitDp" format="integer" />
         <!-- Indicates whether the application supports smaller screen form-factors.
              A small screen is defined as one with a smaller aspect ratio than
              the traditional HVGA screen; that is, for a portrait screen, less
diff --git a/core/res/res/values/colors.xml b/core/res/res/values/colors.xml
index 6529fe1..e76c0e5 100644
--- a/core/res/res/values/colors.xml
+++ b/core/res/res/values/colors.xml
@@ -148,5 +148,14 @@
 
     <color name="group_button_dialog_pressed_holo_light">#ffffffff</color>
     <color name="group_button_dialog_focused_holo_light">#4699cc00</color>
+
+    <!-- General purpose colors for Holo-themed elements -->
+    <eat-comment />
+
+    <!-- A Holo shade of blue -->
+    <color name="holo_blue">#ff6699ff</color>
+    <!-- A Holo shade of green -->
+    <color name="holo_green">#ff99cc00</color>
+
 </resources>
 
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index af08d45..52b00c6 100755
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -20,8 +20,6 @@
 <!-- These resources are around just to allow their values to be customized
      for different hardware and product builds. -->
 <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <bool name="config_statusBarCanHide">true</bool>
-
     <!-- Do not translate. Defines the slots for the right-hand side icons.  That is to say, the
          icons in the status bar that are not notifications. -->
     <string-array name="config_statusBarIcons">
@@ -84,7 +82,7 @@
     <!-- The maximum width we would prefer dialogs to be.  0 if there is no
          maximum (let them grow as large as the screen).  Actual values are
          specified for -large and -xlarge configurations. -->
-    <dimen name="config_prefDialogWidth">0px</dimen>
+    <dimen name="config_prefDialogWidth">320dp</dimen>
     
     <!-- Whether dialogs should close automatically when the user touches outside
          of them.  This should not normally be modified. -->
@@ -158,9 +156,13 @@
 
     <!-- Regex array of allowable upstream ifaces for tethering - for example if you want
          tethering on a new interface called "foo2" add <item>"foo\\d"</item> to the array -->
+    <!-- Interfaces will be prioritized according to the order listed -->
     <string-array translatable="false" name="config_tether_upstream_regexs">
     </string-array>
 
+    <!-- Regex of wired ethernet ifaces -->
+    <string translatable="false" name="config_ethernet_iface_regex">eth\\d</string>
+
     <!-- Boolean indicating if we require the use of DUN on mobile for tethering.
          Note that this defaults to false so that if you move to a carrier that
          hasn't configured anything tethering will still work.  If you'd rather
@@ -380,12 +382,18 @@
     <!-- Diable lockscreen rotation by default -->
     <bool name="config_enableLockScreenRotation">false</bool>
 
+    <!-- Diable puk unlockscreen by default.
+         If unlock screen is disabled, the puk should be unlocked through Emergency Dialer -->
+    <bool name="config_enable_puk_unlock_screen">false</bool>
+
     <!-- Control the behavior when the user long presses the power button.
             0 - Nothing
             1 - Recent apps dialog
-            2 - Recent apps activity in SystemUI
+            2 - Recent apps view in SystemUI
+         This needs to match the constants in
+         policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
     -->
-    <integer name="config_longPressOnHomeBehavior">1</integer>
+    <integer name="config_longPressOnHomeBehavior">2</integer>
 
     <!-- Array of light sensor LUX values to define our levels for auto backlight brightness support.
          The N entries of this array define N + 1 zones as follows:
@@ -624,4 +632,26 @@
          Example 2: devices sold in India should include tables 4 through 13
          to enable use of the new Release 9 tables for Indic languages. -->
     <integer-array name="config_sms_enabled_locking_shift_tables"></integer-array>
+
+    <!-- Set to true if the RSSI should always display CDMA signal strength even on EVDO -->
+    <bool name="config_alwaysUseCdmaRssi">false</bool>
+
+
+    <!-- If this value is true, duplicate Source/Destination port fields
+         in WDP header of some carriers OMADM wap push are supported.
+         ex: MSGTYPE-TotalSegments-CurrentSegment
+             -SourcePortDestPort-SourcePortDestPort-OMADM PDU
+         If false, not supported. -->
+    <bool name="config_duplicate_port_omadm_wappush">false</bool>
+
+    <!-- Maximum numerical value that will be shown in a status bar
+         notification icon or in the notification itself. Will be replaced
+         with @string/status_bar_notification_info_overflow when shown in the
+         UI. -->
+    <integer name="status_bar_notification_info_maxnum">999</integer>
+
+    <!-- Path to an ISO image to be shared with via USB mass storage.
+         This is intended to allow packaging drivers or tools for installation on a PC. -->
+    <string translatable="false" name="config_isoImagePath"></string>
+
 </resources>
diff --git a/core/res/res/values/dimens.xml b/core/res/res/values/dimens.xml
index f5de1d2..20cb852 100644
--- a/core/res/res/values/dimens.xml
+++ b/core/res/res/values/dimens.xml
@@ -32,10 +32,14 @@
     <dimen name="toast_y_offset">64dip</dimen>
     <!-- Height of the status bar -->
     <dimen name="status_bar_height">25dip</dimen>
-    <!-- Height of the status bar -->
+    <!-- Height of the system bar -->
+    <dimen name="system_bar_height">48dip</dimen>
+    <!-- Height of notification icons in the status bar -->
     <dimen name="status_bar_icon_size">25dip</dimen>
     <!-- Size of the giant number (unread count) in the notifications -->
     <dimen name="status_bar_content_number_size">48sp</dimen>
+    <!-- Height of notification icons in the system bar -->
+    <dimen name="system_bar_icon_size">32dip</dimen>
     <!-- Margin at the edge of the screen to ignore touch events for in the windowshade. -->
     <dimen name="status_bar_edge_ignore">5dp</dimen>
     <!-- Size of the fastscroll hint letter -->
@@ -53,6 +57,15 @@
     <!-- Default correction for the space key in the password keyboard -->
     <dimen name="password_keyboard_spacebar_vertical_correction">4dip</dimen>
 
+    <!-- Default target placement radius for MultiWaveView -->
+    <dimen name="multiwaveview_target_placement_radius">135dip</dimen>
+
+    <!-- Default distance beyond which MultiWaveView snaps to the target radius -->
+    <dimen name="multiwaveview_snap_margin">20dip</dimen>
+
+    <!-- Default distance from each snap target that MultiWaveView considers a "hit" -->
+    <dimen name="multiwaveview_hit_radius">60dip</dimen>
+
     <!-- Preference activity side margins -->
     <dimen name="preference_screen_side_margin">0dp</dimen>
     <!-- Preference activity side margins negative-->
@@ -98,7 +111,7 @@
     <dimen name="search_view_text_min_width">160dip</dimen>
 
     <!-- Dialog title height -->
-    <dimen name="alert_dialog_title_height">48dip</dimen>
+    <dimen name="alert_dialog_title_height">64dip</dimen>
     <!-- Dialog button bar height -->
     <dimen name="alert_dialog_button_bar_height">48dip</dimen>
 
@@ -106,4 +119,14 @@
     <dimen name="action_bar_default_height">48dip</dimen>
     <!-- Vertical padding around action bar icons. -->
     <dimen name="action_bar_icon_vertical_padding">4dip</dimen>
+
+    <!-- Size of clock font in LockScreen. -->
+    <dimen name="keyguard_pattern_unlock_clock_font_size">80sp</dimen>
+
+    <!-- Size of status line font in LockScreen. -->
+    <dimen name="keyguard_pattern_unlock_status_line_font_size">14sp</dimen>
+
+    <!-- Size of right margin in LockScreen -->
+    <dimen name="keyguard_pattern_unlock_status_line_font_right_margin">20dip</dimen>
+
 </resources>
diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml
index 5f72da5..580c204 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -1282,6 +1282,7 @@
      Resources added in version 11 of the platform (Honeycomb / 3.0).
      =============================================================== -->
   <eat-comment />
+
   <public type="attr" name="allContactsName" id="0x010102cc" />
   <public type="attr" name="windowActionBar" id="0x010102cd" />
   <public type="attr" name="actionBarStyle" id="0x010102ce" />
@@ -1442,6 +1443,7 @@
   <public type="interpolator" name="accelerate_quad" id="0x010c0000" />
   <!-- Acceleration curve matching a quadtratic ease in function. -->
   <public type="interpolator" name="decelerate_quad" id="0x010c0001" />
+
   <!-- Acceleration curve matching a cubic ease out function. -->
   <public type="interpolator" name="accelerate_cubic" id="0x010c0002" />
   <!-- Acceleration curve matching a cubic ease in function. -->
@@ -1643,14 +1645,64 @@
   <public type="mipmap" name="sym_def_app_icon" id="0x010d0000" />
 
 <!-- ===============================================================
-     Resources added in version 12 of the platform (Honeycomb / 3.1)
+     Resources added in version 12 of the platform (Honeycomb MR 1 / 3.1)
      =============================================================== -->
   <eat-comment />
   <public type="attr" name="textCursorDrawable" id="0x01010362" />
-  <public type="attr" name="resizeMode" />
+  <public type="attr" name="resizeMode" id="0x01010363" />
 
 <!-- ===============================================================
-     Resources added in version 13 of the platform (Ice Cream Sandwich)
+     Resources added in version 13 of the platform (Honeycomb MR 2 / 3.2)
+     =============================================================== -->
+  <eat-comment />
+  <public type="attr" name="requiresSmallestWidthDp" id="0x01010364" />
+  <public type="attr" name="compatibleWidthLimitDp" id="0x01010365" />
+  <public type="attr" name="largestWidthLimitDp" id="0x01010366" />
+
+  <public type="style" name="Theme.Holo.Light.NoActionBar" id="0x010300f0" />
+  <public type="style" name="Theme.Holo.Light.NoActionBar.Fullscreen" id="0x010300f1" />
+
+  <public type="style" name="Widget.ActionBar.TabView" id="0x010300f2" />
+  <public type="style" name="Widget.ActionBar.TabText" id="0x010300f3" />
+  <public type="style" name="Widget.ActionBar.TabBar" id="0x010300f4" />
+  <public type="style" name="Widget.Holo.ActionBar.TabView" id="0x010300f5" />
+  <public type="style" name="Widget.Holo.ActionBar.TabText" id="0x010300f6" />
+  <public type="style" name="Widget.Holo.ActionBar.TabBar" id="0x010300f7" />
+  <public type="style" name="Widget.Holo.Light.ActionBar.TabView" id="0x010300f8" />
+  <public type="style" name="Widget.Holo.Light.ActionBar.TabText" id="0x010300f9" />
+  <public type="style" name="Widget.Holo.Light.ActionBar.TabBar" id="0x010300fa" />
+  <public type="style" name="TextAppearance.Holo" id="0x010300fb" />
+  <public type="style" name="TextAppearance.Holo.Inverse" id="0x010300fc" />
+  <public type="style" name="TextAppearance.Holo.Large" id="0x010300fd" />
+  <public type="style" name="TextAppearance.Holo.Large.Inverse" id="0x010300fe" />
+  <public type="style" name="TextAppearance.Holo.Medium" id="0x010300ff" />
+  <public type="style" name="TextAppearance.Holo.Medium.Inverse" id="0x01030100" />
+  <public type="style" name="TextAppearance.Holo.Small" id="0x01030101" />
+  <public type="style" name="TextAppearance.Holo.Small.Inverse" id="0x01030102" />
+  <public type="style" name="TextAppearance.Holo.SearchResult.Title" id="0x01030103" />
+  <public type="style" name="TextAppearance.Holo.SearchResult.Subtitle" id="0x01030104" />
+  <public type="style" name="TextAppearance.Holo.Widget" id="0x01030105" />
+  <public type="style" name="TextAppearance.Holo.Widget.Button" id="0x01030106" />
+  <public type="style" name="TextAppearance.Holo.Widget.IconMenu.Item" id="0x01030107" />
+  <public type="style" name="TextAppearance.Holo.Widget.TabWidget" id="0x01030108" />
+  <public type="style" name="TextAppearance.Holo.Widget.TextView" id="0x01030109" />
+  <public type="style" name="TextAppearance.Holo.Widget.TextView.PopupMenu" id="0x0103010a" />
+  <public type="style" name="TextAppearance.Holo.Widget.DropDownHint" id="0x0103010b" />
+  <public type="style" name="TextAppearance.Holo.Widget.DropDownItem" id="0x0103010c" />
+  <public type="style" name="TextAppearance.Holo.Widget.TextView.SpinnerItem" id="0x0103010d" />
+  <public type="style" name="TextAppearance.Holo.Widget.EditText" id="0x0103010e" />
+  <public type="style" name="TextAppearance.Holo.Widget.PopupMenu" id="0x0103010f" />
+  <public type="style" name="TextAppearance.Holo.Widget.PopupMenu.Large" id="0x01030110" />
+  <public type="style" name="TextAppearance.Holo.Widget.PopupMenu.Small" id="0x01030111" />
+  <public type="style" name="TextAppearance.Holo.Widget.ActionBar.Title" id="0x01030112" />
+  <public type="style" name="TextAppearance.Holo.Widget.ActionBar.Subtitle" id="0x01030113" />
+  <public type="style" name="TextAppearance.Holo.Widget.ActionMode.Title" id="0x01030114" />
+  <public type="style" name="TextAppearance.Holo.Widget.ActionMode.Subtitle" id="0x01030115" />
+  <public type="style" name="TextAppearance.Holo.WindowTitle" id="0x01030116" />
+  <public type="style" name="TextAppearance.Holo.DialogWindowTitle" id="0x01030117" />
+
+<!-- ===============================================================
+     Resources added in version 14 of the platform (Ice Cream Sandwich)
      =============================================================== -->
   <eat-comment />
   <public type="attr" name="state_hovered" />
@@ -1658,7 +1710,10 @@
   <public type="attr" name="state_drag_hovered" />
   <public type="attr" name="stopWithTask" />
 
-  <public type="style" name="Theme.Holo.Light.NoActionBar" />
+  <public type="attr" name="switchTextOn" />
+  <public type="attr" name="switchTextOff" />
+  <public type="attr" name="switchPreferenceStyle" />
+
   <public type="style" name="TextAppearance.SuggestionHighlight" />
   <public type="style" name="Theme.Holo.SplitActionBarWhenNarrow" />
   <public type="style" name="Theme.Holo.Light.SplitActionBarWhenNarrow" />
@@ -1667,7 +1722,8 @@
   <public type="attr" name="textEditSuggestionsBottomWindowLayout" />
   <public type="attr" name="textEditSuggestionsTopWindowLayout" />
   <public type="attr" name="textEditSuggestionItemLayout" />
-  <public type="attr" name="horizontalDirection" />
+
+  <public type="attr" name="layoutDirection" />
 
   <public type="attr" name="fullBackupAgent" />
   <public type="attr" name="suggestionsEnabled" />
@@ -1677,6 +1733,7 @@
   <public type="attr" name="columnCount" />
   <public type="attr" name="columnOrderPreserved" />
   <public type="attr" name="useDefaultMargins" />
+  <public type="attr" name="alignmentMode" />
 
   <public type="attr" name="layout_row" />
   <public type="attr" name="layout_rowSpan" />
@@ -1684,6 +1741,41 @@
   <public type="attr" name="layout_rowWeight" />
   <public type="attr" name="layout_columnSpan" />
   <public type="attr" name="layout_columnWeight" />
+  <public type="attr" name="actionModeSelectAllDrawable" />
 
   <public type="attr" name="isAuxiliary" />
+
+  <public type="attr" name="accessibilityEventTypes" />
+  <public type="attr" name="packageNames" />
+  <public type="attr" name="accessibilityFeedbackType" />
+  <public type="attr" name="notificationTimeout" />
+  <public type="attr" name="accessibilityFlags" />
+  <public type="attr" name="canRetrieveWindowContent" />
+
+  <public type="attr" name="targetDrawables" />
+  <public type="attr" name="handleDrawable" />
+  <public type="attr" name="leftChevronDrawable" />
+  <public type="attr" name="rightChevronDrawable" />
+  <public type="attr" name="topChevronDrawable" />
+  <public type="attr" name="bottomChevronDrawable" />
+  <public type="attr" name="waveDrawable" />
+  <public type="attr" name="outerRadius" />
+  <public type="attr" name="hitRadius" />
+  <public type="attr" name="vibrationDuration" />
+  <public type="attr" name="snapMargin" />
+  <public type="attr" name="feedbackCount" />
+  <public type="attr" name="verticalOffset" />
+  <public type="attr" name="horizontalOffset" />
+  <public type="attr" name="listPreferredItemHeightLarge" />
+  <public type="attr" name="listPreferredItemHeightSmall" />
+
+  <public type="style" name="Widget.Holo.Button.Borderless.Small" />
+  <public type="style" name="Widget.Holo.Light.Button.Borderless.Small" />
+
+  <public type="integer" name="status_bar_notification_info_maxnum" />
+  <public type="string" name="status_bar_notification_info_overflow" />
+
+  <public type="attr" name="paddingStart"/>
+  <public type="attr" name="paddingEnd"/>
+
 </resources>
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index 816546b..b5f4084 100755
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -87,6 +87,8 @@
     <string name="mismatchPin">The PINs you entered do not match.</string>
     <!-- Displayed when a SIM PIN password is too long or too short. -->
     <string name="invalidPin">Type a PIN that is 4 to 8 numbers.</string>
+    <!-- Displayed when a SIM PUK password is too short. -->
+    <string name="invalidPuk">Type a PUK that is 8 numbers or longer.</string>
     <!-- Displayed to prompt the user to type the PUK password to unlock
          the SIM card. -->
     <string name="needPuk">Your SIM card is PUK-locked. Type the PUK code to unlock it.</string>
@@ -337,10 +339,12 @@
     <!-- status message in phone options dialog for when airplane mode is off -->
     <string name="global_actions_airplane_mode_off_status">Airplane mode is OFF</string>
 
-    <!-- Text to use when the number in a notification info is too large (> 100).  Most likely does not need
-    to be translated.  We do this so, for example, if the user has tens of thousands of unread
-    emails, the whole notification isn't taken over by the number. [CHAR LIMIT=5] -->
-    <string name="status_bar_notification_info_overflow">100+</string>
+    <!-- Text to use when the number in a notification info is too large
+         (greater than status_bar_notification_info_maxnum, defined in
+         values/config.xml) and must be truncated. May need to be localized
+         for most appropriate textual indicator of "more than X".
+         [CHAR LIMIT=4] -->
+    <string name="status_bar_notification_info_overflow">999+</string>
 
     <!-- Displayed to the user to tell them that they have started up the phone in "safe mode" -->
     <string name="safeMode">Safe mode</string>
@@ -457,6 +461,13 @@
       your messages or delete them without showing them to you.</string>
 
     <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permlab_receiveEmergencyBroadcast">receive emergency broadcasts</string>
+    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permdesc_receiveEmergencyBroadcast">Allows application to receive
+      and process emergency broadcast messages. This permission is only available
+      to system applications.</string>
+
+     <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permlab_sendSms">send SMS messages</string>
     <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permdesc_sendSms">Allows application to send SMS
@@ -562,6 +573,13 @@
         never normally need.</string>
 
     <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permlab_retrieve_window_content">retrieve screen content</string>
+    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permdesc_retrieve_window_content">Allows application to retrieve
+        the content of the active window. Malicious applications may retrieve
+        the entire window content and examine all its text except passwords.</string>
+
+    <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permlab_shutdown">partial shutdown</string>
     <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permdesc_shutdown">Puts the activity manager into a shutdown
@@ -711,6 +729,13 @@
         the rotation of the screen at any time. Should never be needed for
         normal applications.</string>
 
+    <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. [CHAR LIMIT=30] -->
+    <string name="permlab_setPointerSpeed">change pointer speed</string>
+    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. [CHAR LIMIT=NONE] -->
+    <string name="permdesc_setPointerSpeed">Allows an application to change
+        the mouse or trackpad pointer speed at any time. Should never be needed for
+        normal applications.</string>
+
     <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permlab_signalPersistentProcesses">send Linux signals to applications</string>
     <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
@@ -878,6 +903,20 @@
         contact (address) data stored on your phone. Malicious
         applications can use this to erase or modify your contact data.</string>
 
+    <!-- Title of the read profile permission, listed so the user can decide whether to allow the application to read the user's personal profile data. [CHAR LIMIT=30] -->
+    <string name="permlab_readProfile">read profile data</string>
+    <!-- Description of the read profile permission, listed so the user can decide whether to allow the application to read the user's personal profile data. [CHAR LIMIT=NONE] -->
+    <string name="permdesc_readProfile" product="default">Allows an application to read all
+        of your personal profile information. Malicious applications can use this to identify
+        you and send your personal information to other people.</string>
+
+    <!-- Title of the write profile permission, listed so the user can decide whether to allow the application to write to the user's personal profile data. [CHAR LIMIT=30] -->
+    <string name="permlab_writeProfile">write profile data</string>
+    <!-- Description of the write profile permission, listed so the user can decide whether to allow the application to write to the user's personal profile data. [CHAR LIMIT=NONE] -->
+    <string name="permdesc_writeProfile" product="default">Allows an application to modify
+        your personal profile information. Malicious applications can use this to erase or
+        modify your profile data.</string>
+
     <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permlab_readCalendar">read calendar events</string>
     <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
@@ -1316,7 +1355,7 @@
     <string name="permlab_vpn">intercept and modify all network traffic</string>
     <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permdesc_vpn">Allows an application to intercept and
-      inspect all network traffic, for example to establish a VPN connection.
+      inspect all network traffic to establish a VPN connection.
       Malicious applications may monitor, redirect, or modify network packets
       without your knowledge.</string>
 
@@ -1394,6 +1433,16 @@
     <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permdesc_use_sip">Allows an application to use the SIP service to make/receive Internet calls.</string>
 
+    <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permlab_readNetworkUsageHistory">read historical network usage</string>
+    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permdesc_readNetworkUsageHistory">Allows an application to read historical network usage for specific networks and applications.</string>
+
+    <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permlab_manageNetworkPolicy">manage network policy</string>
+    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permdesc_manageNetworkPolicy">Allows an application to manage network policies and define application-specific rules.</string>
+
     <!-- Policy administration -->
 
     <!-- Title of policy access to limiting the user's password choices -->
@@ -1442,6 +1491,10 @@
     <!-- Description of policy access to require encrypted storage [CHAR LIMIT=110]-->
     <string name="policydesc_encryptedStorage">Require that stored application data be encrypted
         </string>
+    <!-- Title of policy access to disable all device cameras [CHAR LIMIT=30]-->
+    <string name="policylab_disableCamera">Disable cameras</string>
+    <!-- Description of policy access to disable all device cameras [CHAR LIMIT=110]-->
+    <string name="policydesc_disableCamera">Prevent use of all device cameras</string>
 
     <!-- The order of these is important, don't reorder without changing Contacts.java --> <skip />
     <!-- Phone number types from android.provider.Contacts. This could be used when adding a new phone number for a contact, for example. -->
@@ -1657,6 +1710,15 @@
          Displayed in one line in a large font.  -->
     <string name="keyguard_password_enter_pin_code">Enter PIN code</string>
 
+    <!-- Instructions telling the user to enter their SIM PUK to unlock the keyguard.
+         Displayed in one line in a large font.  -->
+    <string name="keyguard_password_enter_puk_code">Enter PUK and new PIN code</string>
+
+    <!-- Prompt to enter SIM PUK in Edit Text Box in unlock screen -->
+    <string name="keyguard_password_enter_puk_prompt">PUK code</string>
+    <!-- Prompt to enter New SIM PIN in Edit Text Box in unlock screen -->
+    <string name="keyguard_password_enter_pin_prompt">New Pin Code</string>
+
     <!-- Displayed as hint in passwordEntry EditText on PasswordUnlockScreen [CHAR LIMIT=30]-->
     <string name="keyguard_password_entry_touch_hint"><font size="17">Touch to enter password</font></string>
 
@@ -1728,6 +1790,11 @@
     <string name="lockscreen_missing_sim_message" product="default">No SIM card in phone.</string>
     <!-- Shown in the lock screen to ask the user to insert a SIM card. -->
     <string name="lockscreen_missing_sim_instructions">Please insert a SIM card.</string>
+    <!-- Shown in the lock screen to ask the user to insert a SIM card when sim is missing or not readable. -->
+    <string name="lockscreen_missing_sim_instructions_long">The SIM card is missing or not readable. Please insert a SIM card.</string>
+    <!-- Shown in the lock screen to inform the user to SIM card is permanently disabled. -->
+    <string name="lockscreen_permanent_disabled_sim_instructions">Your SIM card is permanently disabled.\n
+    Please contact your wireless service provider to obtain another SIM card.</string>
 
     <!-- Shown in the lock screen when there is emergency calls only mode. -->
     <string name="emergency_calls_only" msgid="2485604591272668370">Emergency calls only</string>
@@ -1852,7 +1919,7 @@
 
     <!-- Do not translate.  WebView User Agent string -->
     <string name="web_user_agent" translatable="false">Mozilla/5.0 (Linux; U; <xliff:g id="x">Android %s</xliff:g>)
-        AppleWebKit/534.20 (KHTML, like Gecko) Version/4.0 <xliff:g id="mobile">%s</xliff:g>Safari/534.20</string>
+        AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 <xliff:g id="mobile">%s</xliff:g>Safari/534.30</string>
     <!-- Do not translate.  WebView User Agent targeted content -->
     <string name="web_user_agent_target_content" translatable="false">"Mobile "</string>
 
@@ -2360,6 +2427,12 @@
     <string name="launch_warning_replace"><xliff:g id="app_name">%1$s</xliff:g> is now running.</string>
     <!-- [CHAR LIMIT=50] Title of the alert when application launches on top of another. -->
     <string name="launch_warning_original"><xliff:g id="app_name">%1$s</xliff:g> was originally launched.</string>
+    <!-- [CHAR LIMIT=50] Compat mode dialog: compat mode switch label. -->
+    <string name="screen_compat_mode_scale">Scale</string>
+    <!-- [CHAR LIMIT=50] Compat mode dialog: compat mode switch label. -->
+    <string name="screen_compat_mode_show">Always show</string>
+    <!-- [CHAR LIMIT=200] Compat mode dialog: hint to re-enable compat mode dialog. -->
+    <string name="screen_compat_mode_hint">Re-enable this with Settings &gt; Applications &gt; Manage applications.</string>
 
     <!-- Text of the alert that is displayed when an application has violated StrictMode. -->
     <string name="smv_application">The application <xliff:g id="application">%1$s</xliff:g>
@@ -2535,6 +2608,11 @@
     <!-- USB_STORAGE_ERROR dialog  ok button-->
     <string name="dlg_ok">OK</string>
 
+    <!-- USB_PREFERENCES: When the user connects the phone to a computer via USB, we show a notification asking if he wants to share files across.  This is the title -->
+    <string name="usb_preferences_notification_title">USB connected</string>
+    <!-- See USB_PREFERENCES. This is the message. -->
+    <string name="usb_preferece_notification_message">Select to configure USB file transfer.</string>
+
     <!-- External media format dialog strings -->
     <!-- This is the label for the activity, and should never be visible to the user. -->
     <!-- See EXTMEDIA_FORMAT.  EXTMEDIA_FORMAT_DIALOG:  After the user selects the notification, a dialog is shown asking if he wants to format the SD card.  This is the title. [CHAR LIMIT=20] -->
@@ -2705,6 +2783,15 @@
     <string name="l2tp_ipsec_psk_vpn_description">Pre-shared key based L2TP/IPSec VPN</string>
     <string name="l2tp_ipsec_crt_vpn_description">Certificate based L2TP/IPSec VPN</string>
 
+    <!-- Ticker text to show when VPN is active. -->
+    <string name="vpn_ticker"><xliff:g id="app" example="FooVPN client">%s</xliff:g> is activating VPN...</string>
+    <!-- The title of the notification when VPN is active. -->
+    <string name="vpn_title">VPN is activated by <xliff:g id="app" example="FooVPN client">%s</xliff:g></string>
+    <!-- The text of the notification when VPN is active. -->
+    <string name="vpn_text">Tap to manage the network.</string>
+    <!-- The text of the notification when VPN is active with a session name. -->
+    <string name="vpn_text_long">Connected to <xliff:g id="session" example="office">%s</xliff:g>. Tap to manage the network.</string>
+
     <!-- Localized strings for WebView -->
     <!-- Label for button in a WebView that will open a chooser to choose a file to upload -->
     <string name="upload_file">Choose file</string>
@@ -2854,4 +2941,22 @@
 
     <!-- Storage description for USB storage. [CHAR LIMIT=NONE] -->
     <string name="storage_usb">USB storage</string>
+
+    <!-- Button text for the edit menu in input method extract mode. [CHAR LIMIT=16] -->
+    <string name="extract_edit_menu_button">Edit...</string>
+
+    <!-- Notification title when data usage has exceeded warning threshold. [CHAR LIMIT=32] -->
+    <string name="data_usage_warning_title">Data usage warning</string>
+    <!-- Notification body when data usage has exceeded warning threshold. [CHAR LIMIT=32] -->
+    <string name="data_usage_warning_body">usage exceeds <xliff:g id="size" example="3.8GB">%s</xliff:g></string>
+
+    <!-- Notification title when 2G-3G data usage has exceeded limit threshold, and has been disabled. [CHAR LIMIT=32] -->
+    <string name="data_usage_3g_limit_title">2G-3G data disabled</string>
+    <!-- Notification title when 4G data usage has exceeded limit threshold, and has been disabled. [CHAR LIMIT=32] -->
+    <string name="data_usage_4g_limit_title">4G data disabled</string>
+    <!-- Notification title when mobile data usage has exceeded limit threshold, and has been disabled. [CHAR LIMIT=32] -->
+    <string name="data_usage_mobile_limit_title">Mobile data disabled</string>
+    <!-- Notification body when data usage has exceeded limit threshold, and has been disabled. [CHAR LIMIT=32] -->
+    <string name="data_usage_limit_body">tap to enable</string>
+
 </resources>
diff --git a/core/res/res/values/styles.xml b/core/res/res/values/styles.xml
index 0635528..72a5797 100644
--- a/core/res/res/values/styles.xml
+++ b/core/res/res/values/styles.xml
@@ -227,15 +227,15 @@
     <style name="TextAppearance.StatusBar.Icon">
     </style>
     <style name="TextAppearance.StatusBar.EventContent">
-        <item name="android:textColor">#ff999999</item>
-        <item name="android:textSize">14sp</item>
+        <item name="android:textColor">?android:attr/textColorPrimary</item>
+        <item name="android:textSize">13sp</item>
     </style>
     <style name="TextAppearance.StatusBar.EventContent.Title">
-        <item name="android:textColor">?android:attr/textColorPrimary</item>
+        <item name="android:textSize">16sp</item>
+        <item name="android:textStyle">bold</item>
     </style>
     <style name="TextAppearance.StatusBar.EventContent.Info">
-        <item name="android:textAppearance">?android:attr/textAppearanceLarge</item>
-        <item name="android:textColor">#ff272727</item>
+        <item name="android:textSize">13sp</item>
     </style>
 
     <style name="TextAppearance.Small.CalendarViewWeekDayView">
@@ -903,6 +903,12 @@
         <item name="android:widgetLayout">@android:layout/preference_widget_checkbox</item>
     </style>
 
+    <style name="Preference.SwitchPreference">
+        <item name="android:widgetLayout">@android:layout/preference_widget_switch</item>
+        <item name="android:switchTextOn">@android:string/capital_on</item>
+        <item name="android:switchTextOff">@android:string/capital_off</item>
+    </style>
+
     <style name="Preference.PreferenceScreen">
     </style>
 
@@ -947,6 +953,12 @@
         <item name="android:widgetLayout">@android:layout/preference_widget_checkbox</item>
     </style>
 
+    <style name="Preference.Holo.SwitchPreference">
+        <item name="android:widgetLayout">@android:layout/preference_widget_switch</item>
+        <item name="android:switchTextOn">@android:string/capital_on</item>
+        <item name="android:switchTextOff">@android:string/capital_off</item>
+    </style>
+
     <style name="Preference.Holo.PreferenceScreen">
     </style>
 
@@ -1109,6 +1121,7 @@
         <item name="android:paddingLeft">16dip</item>
         <item name="android:paddingRight">16dip</item>
         <item name="android:minWidth">64dip</item>
+        <item name="android:minHeight">?android:attr/actionBarSize</item>
     </style>
 
     <style name="Widget.ActionButton.Overflow">
@@ -1120,17 +1133,17 @@
         <item name="android:src">?android:attr/actionModeCloseDrawable</item>
     </style>
 
-    <style name="Widget.ActionBarView_TabView">
+    <style name="Widget.ActionBar.TabView" parent="Widget">
         <item name="android:gravity">center_horizontal</item>
         <item name="android:background">@drawable/minitab_lt</item>
         <item name="android:paddingLeft">4dip</item>
         <item name="android:paddingRight">4dip</item>
     </style>
 
-    <style name="Widget.ActionBarView_TabBar">
+    <style name="Widget.ActionBar.TabBar" parent="Widget">
     </style>
 
-    <style name="Widget.ActionBarView_TabText">
+    <style name="Widget.ActionBar.TabText" parent="Widget">
         <item name="android:textAppearance">@style/TextAppearance.Widget.TextView.PopupMenu</item>
         <item name="android:textColor">?android:attr/textColorPrimaryInverse</item>
         <item name="android:textSize">18sp</item>
@@ -1308,7 +1321,8 @@
     </style>
 
     <style name="TextAppearance.Holo.DialogWindowTitle">
-        <item name="android:textSize">18sp</item>
+        <item name="android:textSize">22sp</item>
+        <item name="android:textColor">@android:color/holo_blue</item>
     </style>
 
     <style name="TextAppearance.Holo.CalendarViewWeekDayView" parent="TextAppearance.Small.CalendarViewWeekDayView">
@@ -1406,7 +1420,8 @@
     </style>
 
     <style name="TextAppearance.Holo.Light.DialogWindowTitle">
-        <item name="android:textSize">18sp</item>
+        <item name="android:textSize">22sp</item>
+        <item name="android:textColor">@android:color/holo_blue</item>
     </style>
 
     <style name="TextAppearance.Holo.Light.CalendarViewWeekDayView" parent="TextAppearance.Small.CalendarViewWeekDayView">
@@ -1435,6 +1450,12 @@
 
     <style name="Widget.Holo.Button.Borderless">
         <item name="android:background">?android:attr/selectableItemBackground</item>
+        <item name="android:paddingLeft">4dip</item>
+        <item name="android:paddingRight">4dip</item>
+    </style>
+
+    <style name="Widget.Holo.Button.Borderless.Small">
+        <item name="android:textSize">14sp</item>
     </style>
 
     <style name="Widget.Holo.Button.Small">
@@ -1475,6 +1496,7 @@
 
     <style name="Holo.ButtonBar.AlertDialog">
         <item name="android:background">@null</item>
+        <item name="android:dividerPadding">0dp</item>
     </style>
 
     <style name="Widget.Holo.TextView" parent="Widget.TextView">
@@ -1770,7 +1792,6 @@
         <item name="android:gravity">center</item>
         <item name="android:paddingLeft">16dip</item>
         <item name="android:paddingRight">16dip</item>
-        <item name="android:minHeight">56dip</item>
         <item name="android:scaleType">center</item>
     </style>
 
@@ -1785,22 +1806,22 @@
     <style name="Widget.Holo.ActionButton.TextButton" parent="Widget.Holo.ButtonBar.Button">
     </style>
 
-    <style name="Widget.Holo.ActionBarView_TabView" parent="Widget.ActionBarView_TabView">
+    <style name="Widget.Holo.ActionBar.TabView" parent="Widget.ActionBar.TabView">
         <item name="android:background">@drawable/tab_indicator_holo</item>
         <item name="android:paddingLeft">16dip</item>
         <item name="android:paddingRight">16dip</item>
     </style>
 
-    <style name="Widget.Holo.Tab" parent="Widget.Holo.ActionBarView_TabView">
+    <style name="Widget.Holo.Tab" parent="Widget.Holo.ActionBar.TabView">
     </style>
 
-    <style name="Widget.Holo.ActionBarView_TabBar" parent="Widget.ActionBarView_TabBar">
+    <style name="Widget.Holo.ActionBar.TabBar" parent="Widget.ActionBar.TabBar">
         <item name="android:divider">?android:attr/dividerVertical</item>
         <item name="android:showDividers">middle</item>
         <item name="android:dividerPadding">8dip</item>
     </style>
 
-    <style name="Widget.Holo.ActionBarView_TabText" parent="Widget.ActionBarView_TabText">
+    <style name="Widget.Holo.ActionBar.TabText" parent="Widget.ActionBar.TabText">
         <item name="android:textAppearance">@style/TextAppearance.Holo.Medium</item>
         <item name="android:textColor">?android:attr/textColorPrimary</item>
         <item name="android:textSize">18sp</item>
@@ -1852,6 +1873,12 @@
 
     <style name="Widget.Holo.Light.Button.Borderless">
         <item name="android:background">?android:attr/selectableItemBackground</item>
+        <item name="android:paddingLeft">4dip</item>
+        <item name="android:paddingRight">4dip</item>
+    </style>
+
+    <style name="Widget.Holo.Light.Button.Borderless.Small">
+        <item name="android:textSize">14sp</item>
     </style>
 
     <style name="Widget.Holo.Light.Button.Small">
@@ -1879,6 +1906,7 @@
 
     <style name="Holo.Light.ButtonBar.AlertDialog">
         <item name="android:background">@null</item>
+        <item name="android:dividerPadding">0dp</item>
     </style>
 
     <style name="Holo.Light.SegmentedButton" parent="SegmentedButton">
@@ -2119,16 +2147,16 @@
         <item name="android:contentDescription">@string/action_menu_overflow_description</item>
     </style>
 
-    <style name="Widget.Holo.Light.ActionBarView_TabView" parent="Widget.Holo.ActionBarView_TabView">
+    <style name="Widget.Holo.Light.ActionBar.TabView" parent="Widget.Holo.ActionBar.TabView">
     </style>
 
-    <style name="Widget.Holo.Light.Tab" parent="Widget.Holo.Light.ActionBarView_TabView">
+    <style name="Widget.Holo.Light.Tab" parent="Widget.Holo.Light.ActionBar.TabView">
     </style>
 
-    <style name="Widget.Holo.Light.ActionBarView_TabBar" parent="Widget.Holo.ActionBarView_TabBar">
+    <style name="Widget.Holo.Light.ActionBar.TabBar" parent="Widget.Holo.ActionBar.TabBar">
     </style>
 
-    <style name="Widget.Holo.Light.ActionBarView_TabText" parent="Widget.Holo.ActionBarView_TabText">
+    <style name="Widget.Holo.Light.ActionBar.TabText" parent="Widget.Holo.ActionBar.TabText">
     </style>
 
     <style name="Widget.Holo.Light.ActionMode" parent="Widget.Holo.ActionMode">
diff --git a/core/res/res/values/themes.xml b/core/res/res/values/themes.xml
index 0a614b2..2ab2c04 100644
--- a/core/res/res/values/themes.xml
+++ b/core/res/res/values/themes.xml
@@ -95,7 +95,9 @@
 
         <!-- List attributes -->
         <item name="listPreferredItemHeight">64dip</item>
-        <item name="dropdownListPreferredItemHeight">64dip</item>
+        <item name="listPreferredItemHeightSmall">?android:attr/listPreferredItemHeight</item>
+        <item name="listPreferredItemHeightLarge">?android:attr/listPreferredItemHeight</item>
+        <item name="dropdownListPreferredItemHeight">?android:attr/listPreferredItemHeight</item>
 
         <!-- @hide -->
         <item name="searchResultListItemHeight">58dip</item>
@@ -247,6 +249,7 @@
         <item name="preferenceStyle">@android:style/Preference</item>
         <item name="preferenceInformationStyle">@android:style/Preference.Information</item>
         <item name="checkBoxPreferenceStyle">@android:style/Preference.CheckBoxPreference</item>
+        <item name="switchPreferenceStyle">@android:style/Preference.SwitchPreference</item>
         <item name="yesNoPreferenceStyle">@android:style/Preference.DialogPreference.YesNoPreference</item>
         <item name="dialogPreferenceStyle">@android:style/Preference.DialogPreference</item>
         <item name="editTextPreferenceStyle">@android:style/Preference.DialogPreference.EditTextPreference</item>
@@ -267,12 +270,13 @@
         <item name="actionModeCutDrawable">@android:drawable/ic_menu_cut_holo_dark</item>
         <item name="actionModeCopyDrawable">@android:drawable/ic_menu_copy_holo_dark</item>
         <item name="actionModePasteDrawable">@android:drawable/ic_menu_paste_holo_dark</item>
+        <item name="actionModeSelectAllDrawable">@android:drawable/ic_menu_selectall_holo_dark</item>
         <item name="actionModeShareDrawable">@android:drawable/ic_menu_share_holo_dark</item>
         <item name="actionModeFindDrawable">@android:drawable/ic_menu_find_holo_dark</item>
         <item name="actionModeWebSearchDrawable">@android:drawable/ic_menu_search</item>
-        <item name="actionBarTabStyle">@style/Widget.ActionBarView_TabView</item>
-        <item name="actionBarTabBarStyle">@style/Widget.ActionBarView_TabBar</item>
-        <item name="actionBarTabTextStyle">@style/Widget.ActionBarView_TabText</item>
+        <item name="actionBarTabStyle">@style/Widget.ActionBar.TabView</item>
+        <item name="actionBarTabBarStyle">@style/Widget.ActionBar.TabBar</item>
+        <item name="actionBarTabTextStyle">@style/Widget.ActionBar.TabText</item>
         <item name="actionModeStyle">@style/Widget.ActionMode</item>
         <item name="actionModeCloseButtonStyle">@style/Widget.ActionButton.CloseMode</item>
         <item name="actionBarStyle">@android:style/Widget.ActionBar</item>
@@ -396,6 +400,7 @@
         <item name="actionModeCutDrawable">@android:drawable/ic_menu_cut_holo_light</item>
         <item name="actionModeCopyDrawable">@android:drawable/ic_menu_copy_holo_light</item>
         <item name="actionModePasteDrawable">@android:drawable/ic_menu_paste_holo_light</item>
+        <item name="actionModeSelectAllDrawable">@android:drawable/ic_menu_selectall_holo_light</item>
         <item name="actionModeShareDrawable">@android:drawable/ic_menu_share_holo_light</item>
         <item name="actionModeFindDrawable">@android:drawable/ic_menu_find_holo_light</item>
         <item name="actionModeWebSearchDrawable">@android:drawable/ic_menu_search_holo_light</item>
@@ -685,7 +690,7 @@
         <item name="android:imeExtractEnterAnimation">@android:anim/input_method_extract_enter</item>
         <item name="android:imeExtractExitAnimation">@android:anim/input_method_extract_exit</item>
     </style>
-    
+
     <!-- Theme for the search input bar. -->
     <style name="Theme.SearchBar" parent="Theme.Holo.Light.Panel">
         <item name="windowContentOverlay">@null</item>        
@@ -858,7 +863,9 @@
 
         <!-- List attributes -->
         <item name="listPreferredItemHeight">64dip</item>
-        <item name="dropdownListPreferredItemHeight">48dip</item>
+        <item name="listPreferredItemHeightSmall">48dip</item>
+        <item name="listPreferredItemHeightLarge">80dip</item>
+        <item name="dropdownListPreferredItemHeight">?android:attr/listPreferredItemHeightSmall</item>
 
         <!-- @hide -->
         <item name="searchResultListItemHeight">58dip</item>
@@ -1001,6 +1008,7 @@
         <item name="preferenceStyle">@android:style/Preference.Holo</item>
         <item name="preferenceInformationStyle">@android:style/Preference.Holo.Information</item>
         <item name="checkBoxPreferenceStyle">@android:style/Preference.Holo.CheckBoxPreference</item>
+        <item name="switchPreferenceStyle">@android:style/Preference.Holo.SwitchPreference</item>
         <item name="yesNoPreferenceStyle">@android:style/Preference.Holo.DialogPreference.YesNoPreference</item>
         <item name="dialogPreferenceStyle">@android:style/Preference.Holo.DialogPreference</item>
         <item name="editTextPreferenceStyle">@android:style/Preference.Holo.DialogPreference.EditTextPreference</item>
@@ -1017,9 +1025,9 @@
         <item name="actionOverflowButtonStyle">@android:style/Widget.Holo.ActionButton.Overflow</item>
         <item name="actionModeBackground">@android:drawable/cab_background_holo_dark</item>
         <item name="actionModeCloseDrawable">@android:drawable/cab_ic_close_holo</item>
-        <item name="actionBarTabStyle">@style/Widget.Holo.ActionBarView_TabView</item>
-        <item name="actionBarTabBarStyle">@style/Widget.Holo.ActionBarView_TabBar</item>
-        <item name="actionBarTabTextStyle">@style/Widget.Holo.ActionBarView_TabText</item>
+        <item name="actionBarTabStyle">@style/Widget.Holo.ActionBar.TabView</item>
+        <item name="actionBarTabBarStyle">@style/Widget.Holo.ActionBar.TabBar</item>
+        <item name="actionBarTabTextStyle">@style/Widget.Holo.ActionBar.TabText</item>
         <item name="actionModeStyle">@style/Widget.Holo.ActionMode</item>
         <item name="actionModeCloseButtonStyle">@style/Widget.Holo.ActionButton.CloseMode</item>
         <item name="actionBarStyle">@android:style/Widget.Holo.ActionBar</item>
@@ -1029,6 +1037,7 @@
         <item name="actionModeCutDrawable">@android:drawable/ic_menu_cut_holo_dark</item>
         <item name="actionModeCopyDrawable">@android:drawable/ic_menu_copy_holo_dark</item>
         <item name="actionModePasteDrawable">@android:drawable/ic_menu_paste_holo_dark</item>
+        <item name="actionModeSelectAllDrawable">@android:drawable/ic_menu_selectall_holo_dark</item>
         <item name="actionModeShareDrawable">@android:drawable/ic_menu_share_holo_dark</item>
         <item name="actionModeFindDrawable">@android:drawable/ic_menu_find_holo_dark</item>
         <item name="actionModeWebSearchDrawable">@android:drawable/ic_menu_search_holo_dark</item>
@@ -1145,7 +1154,9 @@
 
         <!-- List attributes -->
         <item name="listPreferredItemHeight">64dip</item>
-        <item name="dropdownListPreferredItemHeight">48dip</item>
+        <item name="listPreferredItemHeightSmall">48dip</item>
+        <item name="listPreferredItemHeightLarge">80dip</item>
+        <item name="dropdownListPreferredItemHeight">?android:attr/listPreferredItemHeightSmall</item>
 
         <!-- @hide -->
         <item name="searchResultListItemHeight">58dip</item>
@@ -1288,6 +1299,7 @@
         <item name="preferenceStyle">@android:style/Preference.Holo</item>
         <item name="preferenceInformationStyle">@android:style/Preference.Holo.Information</item>
         <item name="checkBoxPreferenceStyle">@android:style/Preference.Holo.CheckBoxPreference</item>
+        <item name="switchPreferenceStyle">@android:style/Preference.Holo.SwitchPreference</item>
         <item name="yesNoPreferenceStyle">@android:style/Preference.Holo.DialogPreference.YesNoPreference</item>
         <item name="dialogPreferenceStyle">@android:style/Preference.Holo.DialogPreference</item>
         <item name="editTextPreferenceStyle">@android:style/Preference.Holo.DialogPreference.EditTextPreference</item>
@@ -1304,9 +1316,9 @@
         <item name="actionOverflowButtonStyle">@android:style/Widget.Holo.Light.ActionButton.Overflow</item>
         <item name="actionModeBackground">@android:drawable/cab_background_holo_light</item>
         <item name="actionModeCloseDrawable">@android:drawable/cab_ic_close_holo</item>
-        <item name="actionBarTabStyle">@style/Widget.Holo.Light.ActionBarView_TabView</item>
-        <item name="actionBarTabBarStyle">@style/Widget.Holo.Light.ActionBarView_TabBar</item>
-        <item name="actionBarTabTextStyle">@style/Widget.Holo.Light.ActionBarView_TabText</item>
+        <item name="actionBarTabStyle">@style/Widget.Holo.Light.ActionBar.TabView</item>
+        <item name="actionBarTabBarStyle">@style/Widget.Holo.Light.ActionBar.TabBar</item>
+        <item name="actionBarTabTextStyle">@style/Widget.Holo.Light.ActionBar.TabText</item>
         <item name="actionModeStyle">@style/Widget.Holo.Light.ActionMode</item>
         <item name="actionModeCloseButtonStyle">@style/Widget.Holo.Light.ActionButton.CloseMode</item>
         <item name="actionBarStyle">@android:style/Widget.Holo.Light.ActionBar</item>
@@ -1316,6 +1328,7 @@
         <item name="actionModeCutDrawable">@android:drawable/ic_menu_cut_holo_light</item>
         <item name="actionModeCopyDrawable">@android:drawable/ic_menu_copy_holo_light</item>
         <item name="actionModePasteDrawable">@android:drawable/ic_menu_paste_holo_light</item>
+        <item name="actionModeSelectAllDrawable">@android:drawable/ic_menu_selectall_holo_light</item>
         <item name="actionModeShareDrawable">@android:drawable/ic_menu_share_holo_light</item>
         <item name="actionModeFindDrawable">@android:drawable/ic_menu_find_holo_light</item>
         <item name="actionModeWebSearchDrawable">@android:drawable/ic_menu_search_holo_light</item>
@@ -1404,6 +1417,7 @@
         <item name="android:colorBackgroundCacheHint">@null</item>
 
         <item name="android:buttonBarStyle">@android:style/Holo.ButtonBar.AlertDialog</item>
+        <item name="borderlessButtonStyle">@android:style/Widget.Holo.Button.Borderless.Small</item>
         
         <item name="textAppearance">@android:style/TextAppearance.Holo</item>
         <item name="textAppearanceInverse">@android:style/TextAppearance.Holo.Inverse</item>
@@ -1413,7 +1427,7 @@
          a regular dialog. -->
     <style name="Theme.Holo.Dialog.MinWidth">
         <item name="android:windowMinWidthMajor">@android:dimen/dialog_min_width_major</item>
-        <item name="android:windowMinWidthMinor">@android:dimen/dialog_min_width_major</item>
+        <item name="android:windowMinWidthMinor">@android:dimen/dialog_min_width_minor</item>
     </style>
 
     <!-- Variation of Theme.Holo.Dialog that does not include a title bar. -->
@@ -1426,7 +1440,7 @@
          a regular dialog. -->
     <style name="Theme.Holo.Dialog.NoActionBar.MinWidth">
         <item name="android:windowMinWidthMajor">@android:dimen/dialog_min_width_major</item>
-        <item name="android:windowMinWidthMinor">@android:dimen/dialog_min_width_major</item>
+        <item name="android:windowMinWidthMinor">@android:dimen/dialog_min_width_minor</item>
     </style>
 
     <!-- Variation of Theme.Holo.Dialog that does not include a frame (or background).
@@ -1453,7 +1467,7 @@
         <item name="windowTitleStyle">@android:style/DialogWindowTitle.Holo</item>
         <item name="windowContentOverlay">@null</item>
         <item name="android:windowMinWidthMajor">@android:dimen/dialog_min_width_major</item>
-        <item name="android:windowMinWidthMinor">@android:dimen/dialog_min_width_major</item>
+        <item name="android:windowMinWidthMinor">@android:dimen/dialog_min_width_minor</item>
     </style>
 
     <!-- Theme for a window that will be displayed either full-screen on
@@ -1492,6 +1506,7 @@
         <item name="android:colorBackgroundCacheHint">@null</item>
 
         <item name="android:buttonBarStyle">@android:style/Holo.Light.ButtonBar.AlertDialog</item>
+        <item name="borderlessButtonStyle">@android:style/Widget.Holo.Light.Button.Borderless.Small</item>
 
         <item name="textAppearance">@android:style/TextAppearance.Holo.Light</item>
         <item name="textAppearanceInverse">@android:style/TextAppearance.Holo.Light.Inverse</item>
@@ -1501,7 +1516,7 @@
          a regular dialog. -->
     <style name="Theme.Holo.Light.Dialog.MinWidth">
         <item name="android:windowMinWidthMajor">@android:dimen/dialog_min_width_major</item>
-        <item name="android:windowMinWidthMinor">@android:dimen/dialog_min_width_major</item>
+        <item name="android:windowMinWidthMinor">@android:dimen/dialog_min_width_minor</item>
     </style>
 
     <!-- Variation of Theme.Holo.Light.Dialog that does not include a title bar. -->
@@ -1514,7 +1529,7 @@
          a regular dialog. -->
     <style name="Theme.Holo.Light.Dialog.NoActionBar.MinWidth">
         <item name="android:windowMinWidthMajor">@android:dimen/dialog_min_width_major</item>
-        <item name="android:windowMinWidthMinor">@android:dimen/dialog_min_width_major</item>
+        <item name="android:windowMinWidthMinor">@android:dimen/dialog_min_width_minor</item>
     </style>
 
     <!-- Theme for a window that will be displayed either full-screen on
@@ -1540,7 +1555,7 @@
         <item name="windowTitleStyle">@android:style/DialogWindowTitle.Holo.Light</item>
         <item name="windowContentOverlay">@null</item>
         <item name="android:windowMinWidthMajor">@android:dimen/dialog_min_width_major</item>
-        <item name="android:windowMinWidthMinor">@android:dimen/dialog_min_width_major</item>
+        <item name="android:windowMinWidthMinor">@android:dimen/dialog_min_width_minor</item>
     </style>
 
     <!-- Default holographic (dark) for windows that want to have the user's selected
diff --git a/core/tests/bluetoothtests/Android.mk b/core/tests/bluetoothtests/Android.mk
new file mode 100644
index 0000000..4a1d18c
--- /dev/null
+++ b/core/tests/bluetoothtests/Android.mk
@@ -0,0 +1,17 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+# We only want this apk build for tests.
+LOCAL_MODULE_TAGS := tests
+
+# Include all test java files.
+LOCAL_SRC_FILES := \
+	$(call all-java-files-under, src)
+
+LOCAL_JAVA_LIBRARIES := android.test.runner
+LOCAL_PACKAGE_NAME := BluetoothTests
+LOCAL_CERTIFICATE := platform
+
+include $(BUILD_PACKAGE)
+
+include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/core/tests/bluetoothtests/AndroidManifest.xml b/core/tests/bluetoothtests/AndroidManifest.xml
new file mode 100644
index 0000000..58f158c
--- /dev/null
+++ b/core/tests/bluetoothtests/AndroidManifest.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+          package="com.android.bluetooth.tests" >
+
+    <uses-permission android:name="android.permission.BLUETOOTH" />
+    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
+    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+    <uses-permission android:name="android.permission.WRITE_SETTINGS" />
+    <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
+
+    <application >
+        <uses-library android:name="android.test.runner" />
+    </application>
+    <instrumentation android:name="android.bluetooth.BluetoothTestRunner"
+            android:targetPackage="com.android.bluetooth.tests"
+            android:label="Bluetooth Tests" />
+
+</manifest>
diff --git a/core/tests/coretests/src/android/bluetooth/BluetoothRebootStressTest.java b/core/tests/bluetoothtests/src/android/bluetooth/BluetoothRebootStressTest.java
similarity index 100%
rename from core/tests/coretests/src/android/bluetooth/BluetoothRebootStressTest.java
rename to core/tests/bluetoothtests/src/android/bluetooth/BluetoothRebootStressTest.java
diff --git a/core/tests/bluetoothtests/src/android/bluetooth/BluetoothStressTest.java b/core/tests/bluetoothtests/src/android/bluetooth/BluetoothStressTest.java
new file mode 100644
index 0000000..abd7d9a
--- /dev/null
+++ b/core/tests/bluetoothtests/src/android/bluetooth/BluetoothStressTest.java
@@ -0,0 +1,390 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.bluetooth;
+
+import android.content.Context;
+import android.test.InstrumentationTestCase;
+
+/**
+ * Stress test suite for Bluetooth related functions.
+ *
+ * Includes tests for enabling/disabling bluetooth, enabling/disabling discoverable mode,
+ * starting/stopping scans, connecting/disconnecting to HFP, A2DP, HID, PAN profiles, and verifying
+ * that remote connections/disconnections occur for the PAN profile.
+ * <p>
+ * This test suite uses {@link android.bluetooth.BluetoothTestRunner} to for parameters such as the
+ * number of iterations and the addresses of remote Bluetooth devices.
+ */
+public class BluetoothStressTest extends InstrumentationTestCase {
+    private static final String TAG = "BluetoothStressTest";
+    private static final String OUTPUT_FILE = "BluetoothStressTestOutput.txt";
+
+    private BluetoothTestUtils mTestUtils;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        Context context = getInstrumentation().getTargetContext();
+        mTestUtils = new BluetoothTestUtils(context, TAG, OUTPUT_FILE);
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        super.tearDown();
+
+        mTestUtils.close();
+    }
+
+    /**
+     * Stress test for enabling and disabling Bluetooth.
+     */
+    public void testEnable() {
+        int iterations = BluetoothTestRunner.sEnableIterations;
+        if (iterations == 0) {
+            return;
+        }
+
+        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
+        mTestUtils.disable(adapter);
+
+        for (int i = 0; i < iterations; i++) {
+            mTestUtils.writeOutput("enable iteration " + (i + 1) + " of " + iterations);
+            mTestUtils.enable(adapter);
+            mTestUtils.disable(adapter);
+        }
+    }
+
+    /**
+     * Stress test for putting the device in and taking the device out of discoverable mode.
+     */
+    public void testDiscoverable() {
+        int iterations = BluetoothTestRunner.sDiscoverableIterations;
+        if (iterations == 0) {
+            return;
+        }
+
+        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
+        mTestUtils.disable(adapter);
+        mTestUtils.enable(adapter);
+        mTestUtils.undiscoverable(adapter);
+
+        for (int i = 0; i < iterations; i++) {
+            mTestUtils.writeOutput("discoverable iteration " + (i + 1) + " of " + iterations);
+            mTestUtils.discoverable(adapter);
+            mTestUtils.undiscoverable(adapter);
+        }
+
+        mTestUtils.disable(adapter);
+    }
+
+    /**
+     * Stress test for starting and stopping Bluetooth scans.
+     */
+    public void testScan() {
+        int iterations = BluetoothTestRunner.sScanIterations;
+        if (iterations == 0) {
+            return;
+        }
+
+        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
+        mTestUtils.disable(adapter);
+        mTestUtils.enable(adapter);
+        mTestUtils.stopScan(adapter);
+
+        for (int i = 0; i < iterations; i++) {
+            mTestUtils.writeOutput("scan iteration " + (i + 1) + " of " + iterations);
+            mTestUtils.startScan(adapter);
+            mTestUtils.stopScan(adapter);
+        }
+
+        mTestUtils.disable(adapter);
+    }
+
+    /**
+     * Stress test for enabling and disabling the PAN NAP profile.
+     */
+    public void testEnablePan() {
+        int iterations = BluetoothTestRunner.sEnablePanIterations;
+        if (iterations == 0) {
+            return;
+        }
+        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
+        mTestUtils.disable(adapter);
+        mTestUtils.enable(adapter);
+        mTestUtils.disablePan(adapter);
+
+        for (int i = 0; i < iterations; i++) {
+            mTestUtils.writeOutput("testEnablePan iteration " + (i + 1) + " of "
+                    + iterations);
+            mTestUtils.enablePan(adapter);
+            mTestUtils.disablePan(adapter);
+        }
+
+        mTestUtils.disable(adapter);
+    }
+
+    /**
+     * Stress test for pairing and unpairing with a remote device.
+     * <p>
+     * In this test, the local device initiates pairing with a remote device, and then unpairs with
+     * the device after the pairing has successfully completed.
+     */
+    public void testPair() {
+        int iterations = BluetoothTestRunner.sPairIterations;
+        if (iterations == 0) {
+            return;
+        }
+
+        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
+        BluetoothDevice device = adapter.getRemoteDevice(BluetoothTestRunner.sDeviceAddress);
+        mTestUtils.disable(adapter);
+        mTestUtils.enable(adapter);
+        mTestUtils.unpair(adapter, device);
+
+        for (int i = 0; i < iterations; i++) {
+            mTestUtils.writeOutput("pair iteration " + (i + 1) + " of " + iterations);
+            mTestUtils.pair(adapter, device, BluetoothTestRunner.sDevicePairPasskey,
+                    BluetoothTestRunner.sDevicePairPin);
+            mTestUtils.unpair(adapter, device);
+        }
+        mTestUtils.disable(adapter);
+    }
+
+    /**
+     * Stress test for accepting a pairing request and unpairing with a remote device.
+     * <p>
+     * In this test, the local device waits for a pairing request from a remote device.  It accepts
+     * the request and then unpairs after the paring has successfully completed.
+     */
+    public void testAcceptPair() {
+        int iterations = BluetoothTestRunner.sPairIterations;
+        if (iterations == 0) {
+            return;
+        }
+        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
+        BluetoothDevice device = adapter.getRemoteDevice(BluetoothTestRunner.sDeviceAddress);
+        mTestUtils.disable(adapter);
+        mTestUtils.enable(adapter);
+        mTestUtils.unpair(adapter, device);
+
+        for (int i = 0; i < iterations; i++) {
+            mTestUtils.writeOutput("acceptPair iteration " + (i + 1) + " of " + iterations);
+            mTestUtils.acceptPair(adapter, device, BluetoothTestRunner.sDevicePairPasskey,
+                    BluetoothTestRunner.sDevicePairPin);
+            mTestUtils.unpair(adapter, device);
+        }
+        mTestUtils.disable(adapter);
+    }
+
+    /**
+     * Stress test for connecting and disconnecting with an A2DP source.
+     * <p>
+     * In this test, the local device plays the role of an A2DP sink, and initiates connections and
+     * disconnections with an A2DP source.
+     */
+    public void testConnectA2dp() {
+        int iterations = BluetoothTestRunner.sConnectA2dpIterations;
+        if (iterations == 0) {
+            return;
+        }
+
+        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
+        BluetoothDevice device = adapter.getRemoteDevice(BluetoothTestRunner.sDeviceAddress);
+        mTestUtils.disable(adapter);
+        mTestUtils.enable(adapter);
+        mTestUtils.unpair(adapter, device);
+        mTestUtils.pair(adapter, device, BluetoothTestRunner.sDevicePairPasskey,
+                BluetoothTestRunner.sDevicePairPin);
+        mTestUtils.disconnectProfile(adapter, device, BluetoothProfile.A2DP, null);
+
+        for (int i = 0; i < iterations; i++) {
+            mTestUtils.writeOutput("connectA2dp iteration " + (i + 1) + " of " + iterations);
+            mTestUtils.connectProfile(adapter, device, BluetoothProfile.A2DP,
+                    String.format("connectA2dp(device=%s)", device));
+            mTestUtils.disconnectProfile(adapter, device, BluetoothProfile.A2DP,
+                    String.format("disconnectA2dp(device=%s)", device));
+        }
+
+        mTestUtils.unpair(adapter, device);
+        mTestUtils.disable(adapter);
+    }
+
+    /**
+     * Stress test for connecting and disconnecting the HFP with a hands free device.
+     * <p>
+     * In this test, the local device plays the role of an HFP audio gateway, and initiates
+     * connections and disconnections with a hands free device.
+     */
+    public void testConnectHeadset() {
+        int iterations = BluetoothTestRunner.sConnectHeadsetIterations;
+        if (iterations == 0) {
+            return;
+        }
+
+        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
+        BluetoothDevice device = adapter.getRemoteDevice(BluetoothTestRunner.sDeviceAddress);
+        mTestUtils.disable(adapter);
+        mTestUtils.enable(adapter);
+        mTestUtils.unpair(adapter, device);
+        mTestUtils.pair(adapter, device, BluetoothTestRunner.sDevicePairPasskey,
+                BluetoothTestRunner.sDevicePairPin);
+        mTestUtils.disconnectProfile(adapter, device, BluetoothProfile.HEADSET, null);
+
+        for (int i = 0; i < iterations; i++) {
+            mTestUtils.writeOutput("connectHeadset iteration " + (i + 1) + " of " + iterations);
+            mTestUtils.connectProfile(adapter, device, BluetoothProfile.HEADSET,
+                    String.format("connectHeadset(device=%s)", device));
+            mTestUtils.disconnectProfile(adapter, device, BluetoothProfile.HEADSET,
+                    String.format("disconnectHeadset(device=%s)", device));
+        }
+
+        mTestUtils.unpair(adapter, device);
+        mTestUtils.disable(adapter);
+    }
+
+    /**
+     * Stress test for connecting and disconnecting with a HID device.
+     * <p>
+     * In this test, the local device plays the role of a HID host, and initiates connections and
+     * disconnections with a HID device.
+     */
+    public void testConnectInput() {
+        int iterations = BluetoothTestRunner.sConnectInputIterations;
+        if (iterations == 0) {
+            return;
+        }
+
+        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
+        BluetoothDevice device = adapter.getRemoteDevice(BluetoothTestRunner.sDeviceAddress);
+        mTestUtils.disable(adapter);
+        mTestUtils.enable(adapter);
+        mTestUtils.unpair(adapter, device);
+        mTestUtils.pair(adapter, device, BluetoothTestRunner.sDevicePairPasskey,
+                BluetoothTestRunner.sDevicePairPin);
+        mTestUtils.disconnectProfile(adapter, device, BluetoothProfile.INPUT_DEVICE, null);
+
+        for (int i = 0; i < iterations; i++) {
+            mTestUtils.writeOutput("connectInput iteration " + (i + 1) + " of " + iterations);
+            mTestUtils.connectProfile(adapter, device, BluetoothProfile.INPUT_DEVICE,
+                    String.format("connectInput(device=%s)", device));
+            mTestUtils.disconnectProfile(adapter, device, BluetoothProfile.INPUT_DEVICE,
+                    String.format("disconnectInput(device=%s)", device));
+        }
+
+        mTestUtils.unpair(adapter, device);
+        mTestUtils.disable(adapter);
+    }
+
+    /**
+     * Stress test for connecting and disconnecting with a PAN NAP.
+     * <p>
+     * In this test, the local device plays the role of a PANU, and initiates connections and
+     * disconnections with a NAP.
+     */
+    public void testConnectPan() {
+        int iterations = BluetoothTestRunner.sConnectPanIterations;
+        if (iterations == 0) {
+            return;
+        }
+
+        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
+        BluetoothDevice device = adapter.getRemoteDevice(BluetoothTestRunner.sDeviceAddress);
+        mTestUtils.disable(adapter);
+        mTestUtils.enable(adapter);
+        mTestUtils.unpair(adapter, device);
+        mTestUtils.pair(adapter, device, BluetoothTestRunner.sDevicePairPasskey,
+                BluetoothTestRunner.sDevicePairPin);
+
+        for (int i = 0; i < iterations; i++) {
+            mTestUtils.writeOutput("connectPan iteration " + (i + 1) + " of " + iterations);
+            mTestUtils.connectPan(adapter, device);
+            mTestUtils.disconnectPan(adapter, device);
+        }
+
+        mTestUtils.unpair(adapter, device);
+        mTestUtils.disable(adapter);
+    }
+
+    /**
+     * Stress test for verifying a PANU connecting and disconnecting with the device.
+     * <p>
+     * In this test, the local device plays the role of a NAP which a remote PANU connects and
+     * disconnects from.
+     */
+    public void testIncomingPanConnection() {
+        int iterations = BluetoothTestRunner.sConnectPanIterations;
+        if (iterations == 0) {
+            return;
+        }
+
+        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
+        BluetoothDevice device = adapter.getRemoteDevice(BluetoothTestRunner.sDeviceAddress);
+        mTestUtils.disable(adapter);
+        mTestUtils.enable(adapter);
+        mTestUtils.disablePan(adapter);
+        mTestUtils.enablePan(adapter);
+        mTestUtils.unpair(adapter, device);
+        mTestUtils.acceptPair(adapter, device, BluetoothTestRunner.sDevicePairPasskey,
+                BluetoothTestRunner.sDevicePairPin);
+
+        for (int i = 0; i < iterations; i++) {
+            mTestUtils.writeOutput("incomingPanConnection iteration " + (i + 1) + " of "
+                    + iterations);
+            mTestUtils.incomingPanConnection(adapter, device);
+            mTestUtils.incomingPanDisconnection(adapter, device);
+        }
+
+        mTestUtils.unpair(adapter, device);
+        mTestUtils.disablePan(adapter);
+        mTestUtils.disable(adapter);
+    }
+
+    /**
+     * Stress test for verifying that AudioManager can open and close SCO connections.
+     * <p>
+     * In this test, a HSP connection is opened with an external headset and the SCO connection is
+     * repeatibly opened and closed.
+     */
+    public void testStartStopSco() {
+        int iterations = BluetoothTestRunner.sStartStopScoIterations;
+        if (iterations == 0) {
+            return;
+        }
+
+        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
+        BluetoothDevice device = adapter.getRemoteDevice(BluetoothTestRunner.sDeviceAddress);
+        mTestUtils.disable(adapter);
+        mTestUtils.enable(adapter);
+        mTestUtils.unpair(adapter, device);
+        mTestUtils.pair(adapter, device, BluetoothTestRunner.sDevicePairPasskey,
+                BluetoothTestRunner.sDevicePairPin);
+        mTestUtils.disconnectProfile(adapter, device, BluetoothProfile.HEADSET, null);
+        mTestUtils.connectProfile(adapter, device, BluetoothProfile.HEADSET, null);
+        mTestUtils.stopSco(adapter, device);
+
+        for (int i = 0; i < iterations; i++) {
+            mTestUtils.writeOutput("startStopSco iteration " + (i + 1) + " of " + iterations);
+            mTestUtils.startSco(adapter, device);
+            mTestUtils.stopSco(adapter, device);
+        }
+
+        mTestUtils.disconnectProfile(adapter, device, BluetoothProfile.HEADSET, null);
+        mTestUtils.unpair(adapter, device);
+        mTestUtils.disable(adapter);
+    }
+}
diff --git a/core/tests/bluetoothtests/src/android/bluetooth/BluetoothTestRunner.java b/core/tests/bluetoothtests/src/android/bluetooth/BluetoothTestRunner.java
new file mode 100644
index 0000000..56e691d
--- /dev/null
+++ b/core/tests/bluetoothtests/src/android/bluetooth/BluetoothTestRunner.java
@@ -0,0 +1,214 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.bluetooth;
+
+import junit.framework.TestSuite;
+
+import android.os.Bundle;
+import android.test.InstrumentationTestRunner;
+import android.test.InstrumentationTestSuite;
+import android.util.Log;
+
+/**
+ * Instrumentation test runner for Bluetooth tests.
+ * <p>
+ * To run:
+ * <pre>
+ * {@code
+ * adb shell am instrument \
+ *     [-e enable_iterations <iterations>] \
+ *     [-e discoverable_iterations <iterations>] \
+ *     [-e scan_iterations <iterations>] \
+ *     [-e enable_pan_iterations <iterations>] \
+ *     [-e pair_iterations <iterations>] \
+ *     [-e connect_a2dp_iterations <iterations>] \
+ *     [-e connect_headset_iterations <iterations>] \
+ *     [-e connect_input_iterations <iterations>] \
+ *     [-e connect_pan_iterations <iterations>] \
+ *     [-e start_stop_sco_iterations <iterations>] \
+ *     [-e pair_address <address>] \
+ *     [-e headset_address <address>] \
+ *     [-e a2dp_address <address>] \
+ *     [-e input_address <address>] \
+ *     [-e pan_address <address>] \
+ *     [-e pair_pin <pin>] \
+ *     [-e pair_passkey <passkey>] \
+ *     -w com.android.bluetooth.tests/android.bluetooth.BluetoothTestRunner
+ * }
+ * </pre>
+ */
+public class BluetoothTestRunner extends InstrumentationTestRunner {
+    private static final String TAG = "BluetoothTestRunner";
+
+    public static int sEnableIterations = 100;
+    public static int sDiscoverableIterations = 1000;
+    public static int sScanIterations = 1000;
+    public static int sEnablePanIterations = 1000;
+    public static int sPairIterations = 100;
+    public static int sConnectHeadsetIterations = 100;
+    public static int sConnectA2dpIterations = 100;
+    public static int sConnectInputIterations = 100;
+    public static int sConnectPanIterations = 100;
+    public static int sStartStopScoIterations = 100;
+
+    public static String sDeviceAddress = "";
+    public static byte[] sDevicePairPin = {'1', '2', '3', '4'};
+    public static int sDevicePairPasskey = 123456;
+
+    @Override
+    public TestSuite getAllTests() {
+        TestSuite suite = new InstrumentationTestSuite(this);
+        suite.addTestSuite(BluetoothStressTest.class);
+        return suite;
+    }
+
+    @Override
+    public ClassLoader getLoader() {
+        return BluetoothTestRunner.class.getClassLoader();
+    }
+
+    @Override
+    public void onCreate(Bundle arguments) {
+        String val = arguments.getString("enable_iterations");
+        if (val != null) {
+            try {
+                sEnableIterations = Integer.parseInt(val);
+            } catch (NumberFormatException e) {
+                // Invalid argument, fall back to default value
+            }
+        }
+
+        val = arguments.getString("discoverable_iterations");
+        if (val != null) {
+            try {
+                sDiscoverableIterations = Integer.parseInt(val);
+            } catch (NumberFormatException e) {
+                // Invalid argument, fall back to default value
+            }
+        }
+
+        val = arguments.getString("scan_iterations");
+        if (val != null) {
+            try {
+                sScanIterations = Integer.parseInt(val);
+            } catch (NumberFormatException e) {
+                // Invalid argument, fall back to default value
+            }
+        }
+
+        val = arguments.getString("enable_pan_iterations");
+        if (val != null) {
+            try {
+                sEnablePanIterations = Integer.parseInt(val);
+            } catch (NumberFormatException e) {
+                // Invalid argument, fall back to default value
+            }
+        }
+
+        val = arguments.getString("pair_iterations");
+        if (val != null) {
+            try {
+                sPairIterations = Integer.parseInt(val);
+            } catch (NumberFormatException e) {
+                // Invalid argument, fall back to default value
+            }
+        }
+
+        val = arguments.getString("connect_a2dp_iterations");
+        if (val != null) {
+            try {
+                sConnectA2dpIterations = Integer.parseInt(val);
+            } catch (NumberFormatException e) {
+                // Invalid argument, fall back to default value
+            }
+        }
+
+        val = arguments.getString("connect_headset_iterations");
+        if (val != null) {
+            try {
+                sConnectHeadsetIterations = Integer.parseInt(val);
+            } catch (NumberFormatException e) {
+                // Invalid argument, fall back to default value
+            }
+        }
+
+        val = arguments.getString("connect_input_iterations");
+        if (val != null) {
+            try {
+                sConnectInputIterations = Integer.parseInt(val);
+            } catch (NumberFormatException e) {
+                // Invalid argument, fall back to default value
+            }
+        }
+
+        val = arguments.getString("connect_pan_iterations");
+        if (val != null) {
+            try {
+                sConnectPanIterations = Integer.parseInt(val);
+            } catch (NumberFormatException e) {
+                // Invalid argument, fall back to default value
+            }
+        }
+
+        val = arguments.getString("start_stop_sco_iterations");
+        if (val != null) {
+            try {
+                sStartStopScoIterations = Integer.parseInt(val);
+            } catch (NumberFormatException e) {
+                // Invalid argument, fall back to default value
+            }
+        }
+
+        val = arguments.getString("device_address");
+        if (val != null) {
+            sDeviceAddress = val;
+        }
+
+        val = arguments.getString("device_pair_pin");
+        if (val != null) {
+            byte[] pin = BluetoothDevice.convertPinToBytes(val);
+            if (pin != null) {
+                sDevicePairPin = pin;
+            }
+        }
+
+        val = arguments.getString("device_pair_passkey");
+        if (val != null) {
+            try {
+                sDevicePairPasskey = Integer.parseInt(val);
+            } catch (NumberFormatException e) {
+                // Invalid argument, fall back to default value
+            }
+        }
+
+        Log.i(TAG, String.format("enable_iterations=%d", sEnableIterations));
+        Log.i(TAG, String.format("discoverable_iterations=%d", sDiscoverableIterations));
+        Log.i(TAG, String.format("scan_iterations=%d", sScanIterations));
+        Log.i(TAG, String.format("pair_iterations=%d", sPairIterations));
+        Log.i(TAG, String.format("connect_a2dp_iterations=%d", sConnectA2dpIterations));
+        Log.i(TAG, String.format("connect_headset_iterations=%d", sConnectHeadsetIterations));
+        Log.i(TAG, String.format("connect_input_iterations=%d", sConnectInputIterations));
+        Log.i(TAG, String.format("connect_pan_iterations=%d", sConnectPanIterations));
+        Log.i(TAG, String.format("start_stop_sco_iterations=%d", sStartStopScoIterations));
+        Log.i(TAG, String.format("device_address=%s", sDeviceAddress));
+        Log.i(TAG, String.format("device_pair_pin=%s", new String(sDevicePairPin)));
+        Log.i(TAG, String.format("device_pair_passkey=%d", sDevicePairPasskey));
+
+        // Call onCreate last since we want to set the static variables first.
+        super.onCreate(arguments);
+    }
+}
diff --git a/core/tests/bluetoothtests/src/android/bluetooth/BluetoothTestUtils.java b/core/tests/bluetoothtests/src/android/bluetooth/BluetoothTestUtils.java
new file mode 100644
index 0000000..42e5cd1
--- /dev/null
+++ b/core/tests/bluetoothtests/src/android/bluetooth/BluetoothTestUtils.java
@@ -0,0 +1,1498 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.bluetooth;
+
+import android.bluetooth.BluetoothPan;
+import android.bluetooth.BluetoothProfile;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.media.AudioManager;
+import android.os.Environment;
+import android.util.Log;
+
+import junit.framework.Assert;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class BluetoothTestUtils extends Assert {
+
+    /** Timeout for enable/disable in ms. */
+    private static final int ENABLE_DISABLE_TIMEOUT = 20000;
+    /** Timeout for discoverable/undiscoverable in ms. */
+    private static final int DISCOVERABLE_UNDISCOVERABLE_TIMEOUT = 5000;
+    /** Timeout for starting/stopping a scan in ms. */
+    private static final int START_STOP_SCAN_TIMEOUT = 5000;
+    /** Timeout for pair/unpair in ms. */
+    private static final int PAIR_UNPAIR_TIMEOUT = 20000;
+    /** Timeout for connecting/disconnecting a profile in ms. */
+    private static final int CONNECT_DISCONNECT_PROFILE_TIMEOUT = 20000;
+    /** Timeout to start or stop a SCO channel in ms. */
+    private static final int START_STOP_SCO_TIMEOUT = 10000;
+    /** Timeout to connect a profile proxy in ms. */
+    private static final int CONNECT_PROXY_TIMEOUT = 5000;
+    /** Time between polls in ms. */
+    private static final int POLL_TIME = 100;
+
+    private abstract class FlagReceiver extends BroadcastReceiver {
+        private int mExpectedFlags = 0;
+        private int mFiredFlags = 0;
+        private long mCompletedTime = -1;
+
+        public FlagReceiver(int expectedFlags) {
+            mExpectedFlags = expectedFlags;
+        }
+
+        public int getFiredFlags() {
+            synchronized (this) {
+                return mFiredFlags;
+            }
+        }
+
+        public long getCompletedTime() {
+            synchronized (this) {
+                return mCompletedTime;
+            }
+        }
+
+        protected void setFiredFlag(int flag) {
+            synchronized (this) {
+                mFiredFlags |= flag;
+                if ((mFiredFlags & mExpectedFlags) == mExpectedFlags) {
+                    mCompletedTime = System.currentTimeMillis();
+                }
+            }
+        }
+    }
+
+    private class BluetoothReceiver extends FlagReceiver {
+        private static final int DISCOVERY_STARTED_FLAG = 1;
+        private static final int DISCOVERY_FINISHED_FLAG = 1 << 1;
+        private static final int SCAN_MODE_NONE_FLAG = 1 << 2;
+        private static final int SCAN_MODE_CONNECTABLE_FLAG = 1 << 3;
+        private static final int SCAN_MODE_CONNECTABLE_DISCOVERABLE_FLAG = 1 << 4;
+        private static final int STATE_OFF_FLAG = 1 << 5;
+        private static final int STATE_TURNING_ON_FLAG = 1 << 6;
+        private static final int STATE_ON_FLAG = 1 << 7;
+        private static final int STATE_TURNING_OFF_FLAG = 1 << 8;
+
+        public BluetoothReceiver(int expectedFlags) {
+            super(expectedFlags);
+        }
+
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            if (BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(intent.getAction())) {
+                setFiredFlag(DISCOVERY_STARTED_FLAG);
+            } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(intent.getAction())) {
+                setFiredFlag(DISCOVERY_FINISHED_FLAG);
+            } else if (BluetoothAdapter.ACTION_SCAN_MODE_CHANGED.equals(intent.getAction())) {
+                int mode = intent.getIntExtra(BluetoothAdapter.EXTRA_SCAN_MODE, -1);
+                assertNotSame(-1, mode);
+                switch (mode) {
+                    case BluetoothAdapter.SCAN_MODE_NONE:
+                        setFiredFlag(SCAN_MODE_NONE_FLAG);
+                        break;
+                    case BluetoothAdapter.SCAN_MODE_CONNECTABLE:
+                        setFiredFlag(SCAN_MODE_CONNECTABLE_FLAG);
+                        break;
+                    case BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE:
+                        setFiredFlag(SCAN_MODE_CONNECTABLE_DISCOVERABLE_FLAG);
+                        break;
+                }
+            } else if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(intent.getAction())) {
+                int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1);
+                assertNotSame(-1, state);
+                switch (state) {
+                    case BluetoothAdapter.STATE_OFF:
+                        setFiredFlag(STATE_OFF_FLAG);
+                        break;
+                    case BluetoothAdapter.STATE_TURNING_ON:
+                        setFiredFlag(STATE_TURNING_ON_FLAG);
+                        break;
+                    case BluetoothAdapter.STATE_ON:
+                        setFiredFlag(STATE_ON_FLAG);
+                        break;
+                    case BluetoothAdapter.STATE_TURNING_OFF:
+                        setFiredFlag(STATE_TURNING_OFF_FLAG);
+                        break;
+                }
+            }
+        }
+    }
+
+    private class PairReceiver extends FlagReceiver {
+        private static final int STATE_BONDED_FLAG = 1;
+        private static final int STATE_BONDING_FLAG = 1 << 1;
+        private static final int STATE_NONE_FLAG = 1 << 2;
+
+        private BluetoothDevice mDevice;
+        private int mPasskey;
+        private byte[] mPin;
+
+        public PairReceiver(BluetoothDevice device, int passkey, byte[] pin, int expectedFlags) {
+            super(expectedFlags);
+
+            mDevice = device;
+            mPasskey = passkey;
+            mPin = pin;
+        }
+
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            if (!mDevice.equals(intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE))) {
+                return;
+            }
+
+            if (BluetoothDevice.ACTION_PAIRING_REQUEST.equals(intent.getAction())) {
+                int varient = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, -1);
+                assertNotSame(-1, varient);
+                switch (varient) {
+                    case BluetoothDevice.PAIRING_VARIANT_PIN:
+                        mDevice.setPin(mPin);
+                        break;
+                    case BluetoothDevice.PAIRING_VARIANT_PASSKEY:
+                        mDevice.setPasskey(mPasskey);
+                        break;
+                    case BluetoothDevice.PAIRING_VARIANT_PASSKEY_CONFIRMATION:
+                    case BluetoothDevice.PAIRING_VARIANT_CONSENT:
+                        mDevice.setPairingConfirmation(true);
+                        break;
+                    case BluetoothDevice.PAIRING_VARIANT_OOB_CONSENT:
+                        mDevice.setRemoteOutOfBandData();
+                        break;
+                }
+            } else if (BluetoothDevice.ACTION_BOND_STATE_CHANGED.equals(intent.getAction())) {
+                int state = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, -1);
+                assertNotSame(-1, state);
+                switch (state) {
+                    case BluetoothDevice.BOND_NONE:
+                        setFiredFlag(STATE_NONE_FLAG);
+                        break;
+                    case BluetoothDevice.BOND_BONDING:
+                        setFiredFlag(STATE_BONDING_FLAG);
+                        break;
+                    case BluetoothDevice.BOND_BONDED:
+                        setFiredFlag(STATE_BONDED_FLAG);
+                        break;
+                }
+            }
+        }
+    }
+
+    private class ConnectProfileReceiver extends FlagReceiver {
+        private static final int STATE_DISCONNECTED_FLAG = 1;
+        private static final int STATE_CONNECTING_FLAG = 1 << 1;
+        private static final int STATE_CONNECTED_FLAG = 1 << 2;
+        private static final int STATE_DISCONNECTING_FLAG = 1 << 3;
+
+        private BluetoothDevice mDevice;
+        private int mProfile;
+        private String mConnectionAction;
+
+        public ConnectProfileReceiver(BluetoothDevice device, int profile, int expectedFlags) {
+            super(expectedFlags);
+
+            mDevice = device;
+            mProfile = profile;
+
+            switch (mProfile) {
+                case BluetoothProfile.A2DP:
+                    mConnectionAction = BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED;
+                    break;
+                case BluetoothProfile.HEADSET:
+                    mConnectionAction = BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED;
+                    break;
+                case BluetoothProfile.INPUT_DEVICE:
+                    mConnectionAction = BluetoothInputDevice.ACTION_CONNECTION_STATE_CHANGED;
+                    break;
+                case BluetoothProfile.PAN:
+                    mConnectionAction = BluetoothPan.ACTION_CONNECTION_STATE_CHANGED;
+                    break;
+                default:
+                    mConnectionAction = null;
+            }
+        }
+
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            if (mConnectionAction != null && mConnectionAction.equals(intent.getAction())) {
+                if (!mDevice.equals(intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE))) {
+                    return;
+                }
+
+                int state = intent.getIntExtra(BluetoothProfile.EXTRA_STATE, -1);
+                assertNotSame(-1, state);
+                switch (state) {
+                    case BluetoothProfile.STATE_DISCONNECTED:
+                        setFiredFlag(STATE_DISCONNECTED_FLAG);
+                        break;
+                    case BluetoothProfile.STATE_CONNECTING:
+                        setFiredFlag(STATE_CONNECTING_FLAG);
+                        break;
+                    case BluetoothProfile.STATE_CONNECTED:
+                        setFiredFlag(STATE_CONNECTED_FLAG);
+                        break;
+                    case BluetoothProfile.STATE_DISCONNECTING:
+                        setFiredFlag(STATE_DISCONNECTING_FLAG);
+                        break;
+                }
+            }
+        }
+    }
+
+    private class ConnectPanReceiver extends ConnectProfileReceiver {
+        private int mRole;
+
+        public ConnectPanReceiver(BluetoothDevice device, int role, int expectedFlags) {
+            super(device, BluetoothProfile.PAN, expectedFlags);
+
+            mRole = role;
+        }
+
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            if (mRole != intent.getIntExtra(BluetoothPan.EXTRA_LOCAL_ROLE, -1)) {
+                return;
+            }
+
+            super.onReceive(context, intent);
+        }
+    }
+
+    private class StartStopScoReceiver extends FlagReceiver {
+        private static final int STATE_CONNECTED_FLAG = 1;
+        private static final int STATE_DISCONNECTED_FLAG = 1 << 1;
+
+        public StartStopScoReceiver(int expectedFlags) {
+            super(expectedFlags);
+        }
+
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            if (AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED.equals(intent.getAction())) {
+                int state = intent.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_STATE,
+                        AudioManager.SCO_AUDIO_STATE_ERROR);
+                assertNotSame(AudioManager.SCO_AUDIO_STATE_ERROR, state);
+                switch(state) {
+                    case AudioManager.SCO_AUDIO_STATE_CONNECTED:
+                        setFiredFlag(STATE_CONNECTED_FLAG);
+                        break;
+                    case AudioManager.SCO_AUDIO_STATE_DISCONNECTED:
+                        setFiredFlag(STATE_DISCONNECTED_FLAG);
+                        break;
+                }
+            }
+        }
+    }
+
+    private BluetoothProfile.ServiceListener mServiceListener =
+            new BluetoothProfile.ServiceListener() {
+        @Override
+        public void onServiceConnected(int profile, BluetoothProfile proxy) {
+            synchronized (this) {
+                switch (profile) {
+                    case BluetoothProfile.A2DP:
+                        mA2dp = (BluetoothA2dp) proxy;
+                        break;
+                    case BluetoothProfile.HEADSET:
+                        mHeadset = (BluetoothHeadset) proxy;
+                        break;
+                    case BluetoothProfile.INPUT_DEVICE:
+                        mInput = (BluetoothInputDevice) proxy;
+                        break;
+                    case BluetoothProfile.PAN:
+                        mPan = (BluetoothPan) proxy;
+                        break;
+                }
+            }
+        }
+
+        @Override
+        public void onServiceDisconnected(int profile) {
+            synchronized (this) {
+                switch (profile) {
+                    case BluetoothProfile.A2DP:
+                        mA2dp = null;
+                        break;
+                    case BluetoothProfile.HEADSET:
+                        mHeadset = null;
+                        break;
+                    case BluetoothProfile.INPUT_DEVICE:
+                        mInput = null;
+                        break;
+                    case BluetoothProfile.PAN:
+                        mPan = null;
+                        break;
+                }
+            }
+        }
+    };
+
+    private List<BroadcastReceiver> mReceivers = new ArrayList<BroadcastReceiver>();
+
+    private BufferedWriter mOutputWriter;
+    private String mTag;
+    private String mOutputFile;
+
+    private Context mContext;
+    private BluetoothA2dp mA2dp = null;
+    private BluetoothHeadset mHeadset = null;
+    private BluetoothInputDevice mInput = null;
+    private BluetoothPan mPan = null;
+
+    /**
+     * Creates a utility instance for testing Bluetooth.
+     *
+     * @param context The context of the application using the utility.
+     * @param tag The log tag of the application using the utility.
+     */
+    public BluetoothTestUtils(Context context, String tag) {
+        this(context, tag, null);
+    }
+
+    /**
+     * Creates a utility instance for testing Bluetooth.
+     *
+     * @param context The context of the application using the utility.
+     * @param tag The log tag of the application using the utility.
+     * @param outputFile The path to an output file if the utility is to write results to a
+     *        separate file.
+     */
+    public BluetoothTestUtils(Context context, String tag, String outputFile) {
+        mContext = context;
+        mTag = tag;
+        mOutputFile = outputFile;
+
+        if (mOutputFile == null) {
+            mOutputWriter = null;
+        } else {
+            try {
+                mOutputWriter = new BufferedWriter(new FileWriter(new File(
+                        Environment.getExternalStorageDirectory(), mOutputFile), true));
+            } catch (IOException e) {
+                Log.w(mTag, "Test output file could not be opened", e);
+                mOutputWriter = null;
+            }
+        }
+    }
+
+    /**
+     * Closes the utility instance and unregisters any BroadcastReceivers.
+     */
+    public void close() {
+        while (!mReceivers.isEmpty()) {
+            mContext.unregisterReceiver(mReceivers.remove(0));
+        }
+
+        if (mOutputWriter != null) {
+            try {
+                mOutputWriter.close();
+            } catch (IOException e) {
+                Log.w(mTag, "Test output file could not be closed", e);
+            }
+        }
+    }
+
+    /**
+     * Enables Bluetooth and checks to make sure that Bluetooth was turned on and that the correct
+     * actions were broadcast.
+     *
+     * @param adapter The BT adapter.
+     */
+    public void enable(BluetoothAdapter adapter) {
+        int mask = (BluetoothReceiver.STATE_TURNING_ON_FLAG | BluetoothReceiver.STATE_ON_FLAG
+                | BluetoothReceiver.SCAN_MODE_CONNECTABLE_FLAG);
+        long start = -1;
+        BluetoothReceiver receiver = getBluetoothReceiver(mask);
+
+        int state = adapter.getState();
+        switch (state) {
+            case BluetoothAdapter.STATE_ON:
+                assertTrue(adapter.isEnabled());
+                removeReceiver(receiver);
+                return;
+            case BluetoothAdapter.STATE_TURNING_ON:
+                assertFalse(adapter.isEnabled());
+                mask = 0; // Don't check for received intents since we might have missed them.
+                break;
+            case BluetoothAdapter.STATE_OFF:
+                assertFalse(adapter.isEnabled());
+                start = System.currentTimeMillis();
+                assertTrue(adapter.enable());
+                break;
+            case BluetoothAdapter.STATE_TURNING_OFF:
+                start = System.currentTimeMillis();
+                assertTrue(adapter.enable());
+                break;
+            default:
+                removeReceiver(receiver);
+                fail(String.format("enable() invalid state: state=%d", state));
+        }
+
+        long s = System.currentTimeMillis();
+        while (System.currentTimeMillis() - s < ENABLE_DISABLE_TIMEOUT) {
+            state = adapter.getState();
+            if (state == BluetoothAdapter.STATE_ON
+                    && (receiver.getFiredFlags() & mask) == mask) {
+                assertTrue(adapter.isEnabled());
+                long finish = receiver.getCompletedTime();
+                if (start != -1 && finish != -1) {
+                    writeOutput(String.format("enable() completed in %d ms", (finish - start)));
+                } else {
+                    writeOutput("enable() completed");
+                }
+                removeReceiver(receiver);
+                return;
+            }
+            sleep(POLL_TIME);
+        }
+
+        int firedFlags = receiver.getFiredFlags();
+        removeReceiver(receiver);
+        fail(String.format("enable() timeout: state=%d (expected %d), flags=0x%x (expected 0x%x)",
+                state, BluetoothAdapter.STATE_ON, firedFlags, mask));
+    }
+
+    /**
+     * Disables Bluetooth and checks to make sure that Bluetooth was turned off and that the correct
+     * actions were broadcast.
+     *
+     * @param adapter The BT adapter.
+     */
+    public void disable(BluetoothAdapter adapter) {
+        int mask = (BluetoothReceiver.STATE_TURNING_OFF_FLAG | BluetoothReceiver.STATE_OFF_FLAG
+                | BluetoothReceiver.SCAN_MODE_NONE_FLAG);
+        long start = -1;
+        BluetoothReceiver receiver = getBluetoothReceiver(mask);
+
+        int state = adapter.getState();
+        switch (state) {
+            case BluetoothAdapter.STATE_OFF:
+                assertFalse(adapter.isEnabled());
+                removeReceiver(receiver);
+                return;
+            case BluetoothAdapter.STATE_TURNING_ON:
+                assertFalse(adapter.isEnabled());
+                start = System.currentTimeMillis();
+                break;
+            case BluetoothAdapter.STATE_ON:
+                assertTrue(adapter.isEnabled());
+                start = System.currentTimeMillis();
+                assertTrue(adapter.disable());
+                break;
+            case BluetoothAdapter.STATE_TURNING_OFF:
+                assertFalse(adapter.isEnabled());
+                mask = 0; // Don't check for received intents since we might have missed them.
+                break;
+            default:
+                removeReceiver(receiver);
+                fail(String.format("disable() invalid state: state=%d", state));
+        }
+
+        long s = System.currentTimeMillis();
+        while (System.currentTimeMillis() - s < ENABLE_DISABLE_TIMEOUT) {
+            state = adapter.getState();
+            if (state == BluetoothAdapter.STATE_OFF
+                    && (receiver.getFiredFlags() & mask) == mask) {
+                assertFalse(adapter.isEnabled());
+                long finish = receiver.getCompletedTime();
+                if (start != -1 && finish != -1) {
+                    writeOutput(String.format("disable() completed in %d ms", (finish - start)));
+                } else {
+                    writeOutput("disable() completed");
+                }
+                removeReceiver(receiver);
+                return;
+            }
+            sleep(POLL_TIME);
+        }
+
+        int firedFlags = receiver.getFiredFlags();
+        removeReceiver(receiver);
+        fail(String.format("disable() timeout: state=%d (expected %d), flags=0x%x (expected 0x%x)",
+                state, BluetoothAdapter.STATE_OFF, firedFlags, mask));
+    }
+
+    /**
+     * Puts the local device into discoverable mode and checks to make sure that the local device
+     * is in discoverable mode and that the correct actions were broadcast.
+     *
+     * @param adapter The BT adapter.
+     */
+    public void discoverable(BluetoothAdapter adapter) {
+        int mask = BluetoothReceiver.SCAN_MODE_CONNECTABLE_DISCOVERABLE_FLAG;
+
+        if (!adapter.isEnabled()) {
+            fail("discoverable() bluetooth not enabled");
+        }
+
+        int scanMode = adapter.getScanMode();
+        if (scanMode == BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
+            return;
+        }
+
+        BluetoothReceiver receiver = getBluetoothReceiver(mask);
+
+        assertEquals(BluetoothAdapter.SCAN_MODE_CONNECTABLE, scanMode);
+        long start = System.currentTimeMillis();
+        assertTrue(adapter.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE));
+
+        while (System.currentTimeMillis() - start < DISCOVERABLE_UNDISCOVERABLE_TIMEOUT) {
+            scanMode = adapter.getScanMode();
+            if (scanMode == BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE
+                    && (receiver.getFiredFlags() & mask) == mask) {
+                writeOutput(String.format("discoverable() completed in %d ms",
+                        (receiver.getCompletedTime() - start)));
+                removeReceiver(receiver);
+                return;
+            }
+            sleep(POLL_TIME);
+        }
+
+        int firedFlags = receiver.getFiredFlags();
+        removeReceiver(receiver);
+        fail(String.format("discoverable() timeout: scanMode=%d (expected %d), flags=0x%x "
+                + "(expected 0x%x)", scanMode, BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE,
+                firedFlags, mask));
+    }
+
+    /**
+     * Puts the local device into connectable only mode and checks to make sure that the local
+     * device is in in connectable mode and that the correct actions were broadcast.
+     *
+     * @param adapter The BT adapter.
+     */
+    public void undiscoverable(BluetoothAdapter adapter) {
+        int mask = BluetoothReceiver.SCAN_MODE_CONNECTABLE_FLAG;
+
+        if (!adapter.isEnabled()) {
+            fail("undiscoverable() bluetooth not enabled");
+        }
+
+        int scanMode = adapter.getScanMode();
+        if (scanMode == BluetoothAdapter.SCAN_MODE_CONNECTABLE) {
+            return;
+        }
+
+        BluetoothReceiver receiver = getBluetoothReceiver(mask);
+
+        assertEquals(BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE, scanMode);
+        long start = System.currentTimeMillis();
+        assertTrue(adapter.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE));
+
+        while (System.currentTimeMillis() - start < DISCOVERABLE_UNDISCOVERABLE_TIMEOUT) {
+            scanMode = adapter.getScanMode();
+            if (scanMode == BluetoothAdapter.SCAN_MODE_CONNECTABLE
+                    && (receiver.getFiredFlags() & mask) == mask) {
+                writeOutput(String.format("undiscoverable() completed in %d ms",
+                        (receiver.getCompletedTime() - start)));
+                removeReceiver(receiver);
+                return;
+            }
+            sleep(POLL_TIME);
+        }
+
+        int firedFlags = receiver.getFiredFlags();
+        removeReceiver(receiver);
+        fail(String.format("undiscoverable() timeout: scanMode=%d (expected %d), flags=0x%x "
+                + "(expected 0x%x)", scanMode, BluetoothAdapter.SCAN_MODE_CONNECTABLE, firedFlags,
+                mask));
+    }
+
+    /**
+     * Starts a scan for remote devices and checks to make sure that the local device is scanning
+     * and that the correct actions were broadcast.
+     *
+     * @param adapter The BT adapter.
+     */
+    public void startScan(BluetoothAdapter adapter) {
+        int mask = BluetoothReceiver.DISCOVERY_STARTED_FLAG;
+
+        if (!adapter.isEnabled()) {
+            fail("startScan() bluetooth not enabled");
+        }
+
+        if (adapter.isDiscovering()) {
+            return;
+        }
+
+        BluetoothReceiver receiver = getBluetoothReceiver(mask);
+
+        long start = System.currentTimeMillis();
+        assertTrue(adapter.startDiscovery());
+
+        while (System.currentTimeMillis() - start < START_STOP_SCAN_TIMEOUT) {
+            if (adapter.isDiscovering() && ((receiver.getFiredFlags() & mask) == mask)) {
+                writeOutput(String.format("startScan() completed in %d ms",
+                        (receiver.getCompletedTime() - start)));
+                removeReceiver(receiver);
+                return;
+            }
+            sleep(POLL_TIME);
+        }
+
+        int firedFlags = receiver.getFiredFlags();
+        removeReceiver(receiver);
+        fail(String.format("startScan() timeout: isDiscovering=%b, flags=0x%x (expected 0x%x)",
+                adapter.isDiscovering(), firedFlags, mask));
+    }
+
+    /**
+     * Stops a scan for remote devices and checks to make sure that the local device is not scanning
+     * and that the correct actions were broadcast.
+     *
+     * @param adapter The BT adapter.
+     */
+    public void stopScan(BluetoothAdapter adapter) {
+        int mask = BluetoothReceiver.DISCOVERY_FINISHED_FLAG;
+
+        if (!adapter.isEnabled()) {
+            fail("stopScan() bluetooth not enabled");
+        }
+
+        if (!adapter.isDiscovering()) {
+            return;
+        }
+
+        BluetoothReceiver receiver = getBluetoothReceiver(mask);
+
+        long start = System.currentTimeMillis();
+        assertTrue(adapter.cancelDiscovery());
+
+        while (System.currentTimeMillis() - start < START_STOP_SCAN_TIMEOUT) {
+            if (!adapter.isDiscovering() && ((receiver.getFiredFlags() & mask) == mask)) {
+                writeOutput(String.format("stopScan() completed in %d ms",
+                        (receiver.getCompletedTime() - start)));
+                removeReceiver(receiver);
+                return;
+            }
+            sleep(POLL_TIME);
+        }
+
+        int firedFlags = receiver.getFiredFlags();
+        removeReceiver(receiver);
+        fail(String.format("stopScan() timeout: isDiscovering=%b, flags=0x%x (expected 0x%x)",
+                adapter.isDiscovering(), firedFlags, mask));
+
+    }
+
+    /**
+     * Enables PAN tethering on the local device and checks to make sure that tethering is enabled.
+     *
+     * @param adapter The BT adapter.
+     */
+    public void enablePan(BluetoothAdapter adapter) {
+        if (mPan == null) mPan = (BluetoothPan) connectProxy(adapter, BluetoothProfile.PAN);
+        assertNotNull(mPan);
+
+        long start = System.currentTimeMillis();
+        mPan.setBluetoothTethering(true);
+        long stop = System.currentTimeMillis();
+        assertTrue(mPan.isTetheringOn());
+
+        writeOutput(String.format("enablePan() completed in %d ms", (stop - start)));
+    }
+
+    /**
+     * Disables PAN tethering on the local device and checks to make sure that tethering is
+     * disabled.
+     *
+     * @param adapter The BT adapter.
+     */
+    public void disablePan(BluetoothAdapter adapter) {
+        if (mPan == null) mPan = (BluetoothPan) connectProxy(adapter, BluetoothProfile.PAN);
+        assertNotNull(mPan);
+
+        long start = System.currentTimeMillis();
+        mPan.setBluetoothTethering(false);
+        long stop = System.currentTimeMillis();
+        assertFalse(mPan.isTetheringOn());
+
+        writeOutput(String.format("disablePan() completed in %d ms", (stop - start)));
+    }
+
+    /**
+     * Initiates a pairing with a remote device and checks to make sure that the devices are paired
+     * and that the correct actions were broadcast.
+     *
+     * @param adapter The BT adapter.
+     * @param device The remote device.
+     * @param passkey The pairing passkey if pairing requires a passkey. Any value if not.
+     * @param pin The pairing pin if pairing requires a pin. Any value if not.
+     */
+    public void pair(BluetoothAdapter adapter, BluetoothDevice device, int passkey, byte[] pin) {
+        pairOrAcceptPair(adapter, device, passkey, pin, true);
+    }
+
+    /**
+     * Accepts a pairing with a remote device and checks to make sure that the devices are paired
+     * and that the correct actions were broadcast.
+     *
+     * @param adapter The BT adapter.
+     * @param device The remote device.
+     * @param passkey The pairing passkey if pairing requires a passkey. Any value if not.
+     * @param pin The pairing pin if pairing requires a pin. Any value if not.
+     */
+    public void acceptPair(BluetoothAdapter adapter, BluetoothDevice device, int passkey,
+            byte[] pin) {
+        pairOrAcceptPair(adapter, device, passkey, pin, false);
+    }
+
+    /**
+     * Helper method used by {@link #pair(BluetoothAdapter, BluetoothDevice, int, byte[])} and
+     * {@link #acceptPair(BluetoothAdapter, BluetoothDevice, int, byte[])} to either pair or accept
+     * a pairing request.
+     *
+     * @param adapter The BT adapter.
+     * @param device The remote device.
+     * @param passkey The pairing passkey if pairing requires a passkey. Any value if not.
+     * @param pin The pairing pin if pairing requires a pin. Any value if not.
+     * @param shouldPair Whether to pair or accept the pair.
+     */
+    private void pairOrAcceptPair(BluetoothAdapter adapter, BluetoothDevice device, int passkey,
+            byte[] pin, boolean shouldPair) {
+        int mask = PairReceiver.STATE_BONDING_FLAG | PairReceiver.STATE_BONDED_FLAG;
+        long start = -1;
+        String methodName;
+        if (shouldPair) {
+            methodName = String.format("pair(device=%s)", device);
+        } else {
+            methodName = String.format("acceptPair(device=%s)", device);
+        }
+
+        if (!adapter.isEnabled()) {
+            fail(String.format("%s bluetooth not enabled", methodName));
+        }
+
+        PairReceiver receiver = getPairReceiver(device, passkey, pin, mask);
+
+        int state = device.getBondState();
+        switch (state) {
+            case BluetoothDevice.BOND_NONE:
+                assertFalse(adapter.getBondedDevices().contains(device));
+                start = System.currentTimeMillis();
+                if (shouldPair) {
+                    assertTrue(device.createBond());
+                }
+                break;
+            case BluetoothDevice.BOND_BONDING:
+                mask = 0; // Don't check for received intents since we might have missed them.
+                break;
+            case BluetoothDevice.BOND_BONDED:
+                assertTrue(adapter.getBondedDevices().contains(device));
+                return;
+            default:
+                removeReceiver(receiver);
+                fail(String.format("%s invalid state: state=%d", methodName, state));
+        }
+
+        long s = System.currentTimeMillis();
+        while (System.currentTimeMillis() - s < PAIR_UNPAIR_TIMEOUT) {
+            state = device.getBondState();
+            if (state == BluetoothDevice.BOND_BONDED && (receiver.getFiredFlags() & mask) == mask) {
+                assertTrue(adapter.getBondedDevices().contains(device));
+                long finish = receiver.getCompletedTime();
+                if (start != -1 && finish != -1) {
+                    writeOutput(String.format("%s completed in %d ms", methodName,
+                            (finish - start)));
+                } else {
+                    writeOutput(String.format("%s completed", methodName));
+                }
+                removeReceiver(receiver);
+                return;
+            }
+            sleep(POLL_TIME);
+        }
+
+        int firedFlags = receiver.getFiredFlags();
+        removeReceiver(receiver);
+        fail(String.format("%s timeout: state=%d (expected %d), flags=0x%x (expected 0x%x)",
+                methodName, state, BluetoothDevice.BOND_BONDED, firedFlags, mask));
+    }
+
+    /**
+     * Deletes a pairing with a remote device and checks to make sure that the devices are unpaired
+     * and that the correct actions were broadcast.
+     *
+     * @param adapter The BT adapter.
+     * @param device The remote device.
+     */
+    public void unpair(BluetoothAdapter adapter, BluetoothDevice device) {
+        int mask = PairReceiver.STATE_NONE_FLAG;
+        long start = -1;
+        String methodName = String.format("unpair(device=%s)", device);
+
+        if (!adapter.isEnabled()) {
+            fail(String.format("%s bluetooth not enabled", methodName));
+        }
+
+        PairReceiver receiver = getPairReceiver(device, 0, null, mask);
+
+        int state = device.getBondState();
+        switch (state) {
+            case BluetoothDevice.BOND_NONE:
+                assertFalse(adapter.getBondedDevices().contains(device));
+                removeReceiver(receiver);
+                return;
+            case BluetoothDevice.BOND_BONDING:
+                start = System.currentTimeMillis();
+                assertTrue(device.removeBond());
+                break;
+            case BluetoothDevice.BOND_BONDED:
+                assertTrue(adapter.getBondedDevices().contains(device));
+                start = System.currentTimeMillis();
+                assertTrue(device.removeBond());
+                break;
+            default:
+                removeReceiver(receiver);
+                fail(String.format("%s invalid state: state=%d", methodName, state));
+        }
+
+        long s = System.currentTimeMillis();
+        while (System.currentTimeMillis() - s < PAIR_UNPAIR_TIMEOUT) {
+            if (device.getBondState() == BluetoothDevice.BOND_NONE
+                    && (receiver.getFiredFlags() & mask) == mask) {
+                assertFalse(adapter.getBondedDevices().contains(device));
+                long finish = receiver.getCompletedTime();
+                if (start != -1 && finish != -1) {
+                    writeOutput(String.format("%s completed in %d ms", methodName,
+                            (finish - start)));
+                } else {
+                    writeOutput(String.format("%s completed", methodName));
+                }
+                removeReceiver(receiver);
+                return;
+            }
+        }
+
+        int firedFlags = receiver.getFiredFlags();
+        removeReceiver(receiver);
+        fail(String.format("%s timeout: state=%d (expected %d), flags=0x%x (expected 0x%x)",
+                methodName, state, BluetoothDevice.BOND_BONDED, firedFlags, mask));
+    }
+
+    /**
+     * Connects a profile from the local device to a remote device and checks to make sure that the
+     * profile is connected and that the correct actions were broadcast.
+     *
+     * @param adapter The BT adapter.
+     * @param device The remote device.
+     * @param profile The profile to connect. One of {@link BluetoothProfile#A2DP},
+     * {@link BluetoothProfile#HEADSET}, or {@link BluetoothProfile#INPUT_DEVICE}.
+     * @param methodName The method name to printed in the logs.  If null, will be
+     * "connectProfile(profile=&lt;profile&gt;, device=&lt;device&gt;)"
+     */
+    public void connectProfile(BluetoothAdapter adapter, BluetoothDevice device, int profile,
+            String methodName) {
+        if (methodName == null) {
+            methodName = String.format("connectProfile(profile=%d, device=%s)", profile, device);
+        }
+        int mask = (ConnectProfileReceiver.STATE_CONNECTING_FLAG
+                | ConnectProfileReceiver.STATE_CONNECTED_FLAG);
+        long start = -1;
+
+        if (!adapter.isEnabled()) {
+            fail(String.format("%s bluetooth not enabled", methodName));
+        }
+
+        if (!adapter.getBondedDevices().contains(device)) {
+            fail(String.format("%s device not paired", methodName));
+        }
+
+        BluetoothProfile proxy = connectProxy(adapter, profile);
+        assertNotNull(proxy);
+
+        ConnectProfileReceiver receiver = getConnectProfileReceiver(device, profile, mask);
+
+        int state = proxy.getConnectionState(device);
+        switch (state) {
+            case BluetoothProfile.STATE_CONNECTED:
+                removeReceiver(receiver);
+                return;
+            case BluetoothProfile.STATE_CONNECTING:
+                mask = 0; // Don't check for received intents since we might have missed them.
+                break;
+            case BluetoothProfile.STATE_DISCONNECTED:
+            case BluetoothProfile.STATE_DISCONNECTING:
+                start = System.currentTimeMillis();
+                if (profile == BluetoothProfile.A2DP) {
+                    assertTrue(((BluetoothA2dp)proxy).connect(device));
+                } else if (profile == BluetoothProfile.HEADSET) {
+                    assertTrue(((BluetoothHeadset)proxy).connect(device));
+                } else if (profile == BluetoothProfile.INPUT_DEVICE) {
+                    assertTrue(((BluetoothInputDevice)proxy).connect(device));
+                }
+                break;
+            default:
+                removeReceiver(receiver);
+                fail(String.format("%s invalid state: state=%d", methodName, state));
+        }
+
+        long s = System.currentTimeMillis();
+        while (System.currentTimeMillis() - s < CONNECT_DISCONNECT_PROFILE_TIMEOUT) {
+            state = proxy.getConnectionState(device);
+            if (state == BluetoothProfile.STATE_CONNECTED
+                    && (receiver.getFiredFlags() & mask) == mask) {
+                long finish = receiver.getCompletedTime();
+                if (start != -1 && finish != -1) {
+                    writeOutput(String.format("%s completed in %d ms", methodName,
+                            (finish - start)));
+                } else {
+                    writeOutput(String.format("%s completed", methodName));
+                }
+                removeReceiver(receiver);
+                return;
+            }
+            sleep(POLL_TIME);
+        }
+
+        int firedFlags = receiver.getFiredFlags();
+        removeReceiver(receiver);
+        fail(String.format("%s timeout: state=%d (expected %d), flags=0x%x (expected 0x%x)",
+                methodName, state, BluetoothProfile.STATE_CONNECTED, firedFlags, mask));
+    }
+
+    /**
+     * Disconnects a profile between the local device and a remote device and checks to make sure
+     * that the profile is disconnected and that the correct actions were broadcast.
+     *
+     * @param adapter The BT adapter.
+     * @param device The remote device.
+     * @param profile The profile to disconnect. One of {@link BluetoothProfile#A2DP},
+     * {@link BluetoothProfile#HEADSET}, or {@link BluetoothProfile#INPUT_DEVICE}.
+     * @param methodName The method name to printed in the logs.  If null, will be
+     * "connectProfile(profile=&lt;profile&gt;, device=&lt;device&gt;)"
+     */
+    public void disconnectProfile(BluetoothAdapter adapter, BluetoothDevice device, int profile,
+            String methodName) {
+        if (methodName == null) {
+            methodName = String.format("disconnectProfile(profile=%d, device=%s)", profile, device);
+        }
+        int mask = (ConnectProfileReceiver.STATE_DISCONNECTING_FLAG
+                | ConnectProfileReceiver.STATE_DISCONNECTED_FLAG);
+        long start = -1;
+
+        if (!adapter.isEnabled()) {
+            fail(String.format("%s bluetooth not enabled", methodName));
+        }
+
+        if (!adapter.getBondedDevices().contains(device)) {
+            fail(String.format("%s device not paired", methodName));
+        }
+
+        BluetoothProfile proxy = connectProxy(adapter, profile);
+        assertNotNull(proxy);
+
+        ConnectProfileReceiver receiver = getConnectProfileReceiver(device, profile, mask);
+
+        int state = proxy.getConnectionState(device);
+        switch (state) {
+            case BluetoothProfile.STATE_CONNECTED:
+            case BluetoothProfile.STATE_CONNECTING:
+                start = System.currentTimeMillis();
+                if (profile == BluetoothProfile.A2DP) {
+                    assertTrue(((BluetoothA2dp)proxy).disconnect(device));
+                } else if (profile == BluetoothProfile.HEADSET) {
+                    assertTrue(((BluetoothHeadset)proxy).disconnect(device));
+                } else if (profile == BluetoothProfile.INPUT_DEVICE) {
+                    assertTrue(((BluetoothInputDevice)proxy).disconnect(device));
+                }
+                break;
+            case BluetoothProfile.STATE_DISCONNECTED:
+                removeReceiver(receiver);
+                return;
+            case BluetoothProfile.STATE_DISCONNECTING:
+                mask = 0; // Don't check for received intents since we might have missed them.
+                break;
+            default:
+                removeReceiver(receiver);
+                fail(String.format("%s invalid state: state=%d", methodName, state));
+        }
+
+        long s = System.currentTimeMillis();
+        while (System.currentTimeMillis() - s < CONNECT_DISCONNECT_PROFILE_TIMEOUT) {
+            state = proxy.getConnectionState(device);
+            if (state == BluetoothProfile.STATE_DISCONNECTED
+                    && (receiver.getFiredFlags() & mask) == mask) {
+                long finish = receiver.getCompletedTime();
+                if (start != -1 && finish != -1) {
+                    writeOutput(String.format("%s completed in %d ms", methodName,
+                            (finish - start)));
+                } else {
+                    writeOutput(String.format("%s completed", methodName));
+                }
+                removeReceiver(receiver);
+                return;
+            }
+            sleep(POLL_TIME);
+        }
+
+        int firedFlags = receiver.getFiredFlags();
+        removeReceiver(receiver);
+        fail(String.format("%s timeout: state=%d (expected %d), flags=0x%x (expected 0x%x)",
+                methodName, state, BluetoothProfile.STATE_DISCONNECTED, firedFlags, mask));
+    }
+
+    /**
+     * Connects the PANU to a remote NAP and checks to make sure that the PANU is connected and that
+     * the correct actions were broadcast.
+     *
+     * @param adapter The BT adapter.
+     * @param device The remote device.
+     */
+    public void connectPan(BluetoothAdapter adapter, BluetoothDevice device) {
+        connectPanOrIncomingPanConnection(adapter, device, true);
+    }
+
+    /**
+     * Checks that a remote PANU connects to the local NAP correctly and that the correct actions
+     * were broadcast.
+     *
+     * @param adapter The BT adapter.
+     * @param device The remote device.
+     */
+    public void incomingPanConnection(BluetoothAdapter adapter, BluetoothDevice device) {
+        connectPanOrIncomingPanConnection(adapter, device, false);
+    }
+
+    /**
+     * Helper method used by {@link #connectPan(BluetoothAdapter, BluetoothDevice)} and
+     * {@link #incomingPanConnection(BluetoothAdapter, BluetoothDevice)} to either connect to a
+     * remote NAP or verify that a remote device connected to the local NAP.
+     *
+     * @param adapter The BT adapter.
+     * @param device The remote device.
+     * @param connect If the method should initiate the connection (is PANU)
+     */
+    private void connectPanOrIncomingPanConnection(BluetoothAdapter adapter, BluetoothDevice device,
+            boolean connect) {
+        long start = -1;
+        int mask, role;
+        String methodName;
+
+        if (connect) {
+            methodName = String.format("connectPan(device=%s)", device);
+            mask = (ConnectProfileReceiver.STATE_CONNECTED_FLAG |
+                    ConnectProfileReceiver.STATE_CONNECTING_FLAG);
+            role = BluetoothPan.LOCAL_PANU_ROLE;
+        } else {
+            methodName = String.format("incomingPanConnection(device=%s)", device);
+            mask = ConnectProfileReceiver.STATE_CONNECTED_FLAG;
+            role = BluetoothPan.LOCAL_NAP_ROLE;
+        }
+
+        if (!adapter.isEnabled()) {
+            fail(String.format("%s bluetooth not enabled", methodName));
+        }
+
+        if (!adapter.getBondedDevices().contains(device)) {
+            fail(String.format("%s device not paired", methodName));
+        }
+
+        mPan = (BluetoothPan) connectProxy(adapter, BluetoothProfile.PAN);
+        assertNotNull(mPan);
+        ConnectPanReceiver receiver = getConnectPanReceiver(device, role, mask);
+
+        int state = mPan.getConnectionState(device);
+        switch (state) {
+            case BluetoothPan.STATE_CONNECTED:
+                removeReceiver(receiver);
+                return;
+            case BluetoothPan.STATE_CONNECTING:
+                mask = 0; // Don't check for received intents since we might have missed them.
+                break;
+            case BluetoothPan.STATE_DISCONNECTED:
+            case BluetoothPan.STATE_DISCONNECTING:
+                start = System.currentTimeMillis();
+                if (role == BluetoothPan.LOCAL_PANU_ROLE) {
+                    Log.i("BT", "connect to pan");
+                    assertTrue(mPan.connect(device));
+                }
+                break;
+            default:
+                removeReceiver(receiver);
+                fail(String.format("%s invalid state: state=%d", methodName, state));
+        }
+
+        long s = System.currentTimeMillis();
+        while (System.currentTimeMillis() - s < CONNECT_DISCONNECT_PROFILE_TIMEOUT) {
+            state = mPan.getConnectionState(device);
+            if (state == BluetoothPan.STATE_CONNECTED
+                    && (receiver.getFiredFlags() & mask) == mask) {
+                long finish = receiver.getCompletedTime();
+                if (start != -1 && finish != -1) {
+                    writeOutput(String.format("%s completed in %d ms", methodName,
+                            (finish - start)));
+                } else {
+                    writeOutput(String.format("%s completed", methodName));
+                }
+                removeReceiver(receiver);
+                return;
+            }
+            sleep(POLL_TIME);
+        }
+
+        int firedFlags = receiver.getFiredFlags();
+        removeReceiver(receiver);
+        fail(String.format("%s timeout: state=%d (expected %d), flags=0x%x (expected 0x%s)",
+                methodName, state, BluetoothPan.STATE_CONNECTED, firedFlags, mask));
+    }
+
+    /**
+     * Disconnects the PANU from a remote NAP and checks to make sure that the PANU is disconnected
+     * and that the correct actions were broadcast.
+     *
+     * @param adapter The BT adapter.
+     * @param device The remote device.
+     */
+    public void disconnectPan(BluetoothAdapter adapter, BluetoothDevice device) {
+        disconnectFromRemoteOrVerifyConnectNap(adapter, device, true);
+    }
+
+    /**
+     * Checks that a remote PANU disconnects from the local NAP correctly and that the correct
+     * actions were broadcast.
+     *
+     * @param adapter The BT adapter.
+     * @param device The remote device.
+     */
+    public void incomingPanDisconnection(BluetoothAdapter adapter, BluetoothDevice device) {
+        disconnectFromRemoteOrVerifyConnectNap(adapter, device, false);
+    }
+
+    /**
+     * Helper method used by {@link #disconnectPan(BluetoothAdapter, BluetoothDevice)} and
+     * {@link #incomingPanDisconnection(BluetoothAdapter, BluetoothDevice)} to either disconnect
+     * from a remote NAP or verify that a remote device disconnected from the local NAP.
+     *
+     * @param adapter The BT adapter.
+     * @param device The remote device.
+     * @param disconnect Whether the method should connect or verify.
+     */
+    private void disconnectFromRemoteOrVerifyConnectNap(BluetoothAdapter adapter,
+            BluetoothDevice device, boolean disconnect) {
+        long start = -1;
+        int mask, role;
+        String methodName;
+
+        if (disconnect) {
+            methodName = String.format("disconnectPan(device=%s)", device);
+            mask = (ConnectProfileReceiver.STATE_DISCONNECTED_FLAG |
+                    ConnectProfileReceiver.STATE_DISCONNECTING_FLAG);
+            role = BluetoothPan.LOCAL_PANU_ROLE;
+        } else {
+            methodName = String.format("incomingPanDisconnection(device=%s)", device);
+            mask = ConnectProfileReceiver.STATE_DISCONNECTED_FLAG;
+            role = BluetoothPan.LOCAL_NAP_ROLE;
+        }
+
+        if (!adapter.isEnabled()) {
+            fail(String.format("%s bluetooth not enabled", methodName));
+        }
+
+        if (!adapter.getBondedDevices().contains(device)) {
+            fail(String.format("%s device not paired", methodName));
+        }
+
+        mPan = (BluetoothPan) connectProxy(adapter, BluetoothProfile.PAN);
+        assertNotNull(mPan);
+        ConnectPanReceiver receiver = getConnectPanReceiver(device, role, mask);
+
+        int state = mPan.getConnectionState(device);
+        switch (state) {
+            case BluetoothPan.STATE_CONNECTED:
+            case BluetoothPan.STATE_CONNECTING:
+                start = System.currentTimeMillis();
+                if (role == BluetoothPan.LOCAL_PANU_ROLE) {
+                    assertTrue(mPan.disconnect(device));
+                }
+                break;
+            case BluetoothPan.STATE_DISCONNECTED:
+                removeReceiver(receiver);
+                return;
+            case BluetoothPan.STATE_DISCONNECTING:
+                mask = 0; // Don't check for received intents since we might have missed them.
+                break;
+            default:
+                removeReceiver(receiver);
+                fail(String.format("%s invalid state: state=%d", methodName, state));
+        }
+
+        long s = System.currentTimeMillis();
+        while (System.currentTimeMillis() - s < CONNECT_DISCONNECT_PROFILE_TIMEOUT) {
+            state = mPan.getConnectionState(device);
+            if (state == BluetoothInputDevice.STATE_DISCONNECTED
+                    && (receiver.getFiredFlags() & mask) == mask) {
+                long finish = receiver.getCompletedTime();
+                if (start != -1 && finish != -1) {
+                    writeOutput(String.format("%s completed in %d ms", methodName,
+                            (finish - start)));
+                } else {
+                    writeOutput(String.format("%s completed", methodName));
+                }
+                removeReceiver(receiver);
+                return;
+            }
+            sleep(POLL_TIME);
+        }
+
+        int firedFlags = receiver.getFiredFlags();
+        removeReceiver(receiver);
+        fail(String.format("%s timeout: state=%d (expected %d), flags=0x%x (expected 0x%s)",
+                methodName, state, BluetoothInputDevice.STATE_DISCONNECTED, firedFlags, mask));
+    }
+
+    /**
+     * Opens a SCO channel using {@link android.media.AudioManager#startBluetoothSco()} and checks
+     * to make sure that the channel is opened and that the correct actions were broadcast.
+     *
+     * @param adapter The BT adapter.
+     * @param device The remote device.
+     */
+    public void startSco(BluetoothAdapter adapter, BluetoothDevice device) {
+        startStopSco(adapter, device, true);
+    }
+
+    /**
+     * Closes a SCO channel using {@link android.media.AudioManager#stopBluetoothSco()} and checks
+     *  to make sure that the channel is closed and that the correct actions were broadcast.
+     *
+     * @param adapter The BT adapter.
+     * @param device The remote device.
+     */
+    public void stopSco(BluetoothAdapter adapter, BluetoothDevice device) {
+        startStopSco(adapter, device, false);
+    }
+    /**
+     * Helper method for {@link #startSco(BluetoothAdapter, BluetoothDevice)} and
+     * {@link #stopSco(BluetoothAdapter, BluetoothDevice)}.
+     *
+     * @param adapter The BT adapter.
+     * @param device The remote device.
+     * @param isStart Whether the SCO channel should be opened.
+     */
+    private void startStopSco(BluetoothAdapter adapter, BluetoothDevice device, boolean isStart) {
+        long start = -1;
+        int mask;
+        String methodName;
+
+        if (isStart) {
+            methodName = String.format("startSco(device=%s)", device);
+            mask = StartStopScoReceiver.STATE_CONNECTED_FLAG;
+        } else {
+            methodName = String.format("stopSco(device=%s)", device);
+            mask = StartStopScoReceiver.STATE_DISCONNECTED_FLAG;
+        }
+
+        if (!adapter.isEnabled()) {
+            fail(String.format("%s bluetooth not enabled", methodName));
+        }
+
+        if (!adapter.getBondedDevices().contains(device)) {
+            fail(String.format("%s device not paired", methodName));
+        }
+
+        AudioManager manager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
+        assertNotNull(manager);
+
+        if (!manager.isBluetoothScoAvailableOffCall()) {
+            fail(String.format("%s device does not support SCO", methodName));
+        }
+
+        boolean isScoOn = manager.isBluetoothScoOn();
+        if (isStart == isScoOn) {
+            return;
+        }
+
+        StartStopScoReceiver receiver = getStartStopScoReceiver(mask);
+        start = System.currentTimeMillis();
+        if (isStart) {
+            manager.startBluetoothSco();
+        } else {
+            manager.stopBluetoothSco();
+        }
+
+        long s = System.currentTimeMillis();
+        while (System.currentTimeMillis() - s < START_STOP_SCO_TIMEOUT) {
+            isScoOn = manager.isBluetoothScoOn();
+            if (isStart == isScoOn && (receiver.getFiredFlags() & mask) == mask) {
+                long finish = receiver.getCompletedTime();
+                if (start != -1 && finish != -1) {
+                    writeOutput(String.format("%s completed in %d ms", methodName,
+                            (finish - start)));
+                } else {
+                    writeOutput(String.format("%s completed", methodName));
+                }
+                removeReceiver(receiver);
+                return;
+            }
+            sleep(POLL_TIME);
+        }
+
+        int firedFlags = receiver.getFiredFlags();
+        removeReceiver(receiver);
+        fail(String.format("%s timeout: on=%b (expected %b), flags=0x%x (expected 0x%x)",
+                methodName, isScoOn, isStart, firedFlags, mask));
+    }
+
+    /**
+     * Writes a string to the logcat and a file if a file has been specified in the constructor.
+     *
+     * @param s The string to be written.
+     */
+    public void writeOutput(String s) {
+        Log.i(mTag, s);
+        if (mOutputWriter == null) {
+            return;
+        }
+        try {
+            mOutputWriter.write(s + "\n");
+            mOutputWriter.flush();
+        } catch (IOException e) {
+            Log.w(mTag, "Could not write to output file", e);
+        }
+    }
+
+    private void addReceiver(BroadcastReceiver receiver, String[] actions) {
+        IntentFilter filter = new IntentFilter();
+        for (String action: actions) {
+            filter.addAction(action);
+        }
+        mContext.registerReceiver(receiver, filter);
+        mReceivers.add(receiver);
+    }
+
+    private BluetoothReceiver getBluetoothReceiver(int expectedFlags) {
+        String[] actions = {
+                BluetoothAdapter.ACTION_DISCOVERY_FINISHED,
+                BluetoothAdapter.ACTION_DISCOVERY_STARTED,
+                BluetoothAdapter.ACTION_SCAN_MODE_CHANGED,
+                BluetoothAdapter.ACTION_STATE_CHANGED};
+        BluetoothReceiver receiver = new BluetoothReceiver(expectedFlags);
+        addReceiver(receiver, actions);
+        return receiver;
+    }
+
+    private PairReceiver getPairReceiver(BluetoothDevice device, int passkey, byte[] pin,
+            int expectedFlags) {
+        String[] actions = {
+                BluetoothDevice.ACTION_PAIRING_REQUEST,
+                BluetoothDevice.ACTION_BOND_STATE_CHANGED};
+        PairReceiver receiver = new PairReceiver(device, passkey, pin, expectedFlags);
+        addReceiver(receiver, actions);
+        return receiver;
+    }
+
+    private ConnectProfileReceiver getConnectProfileReceiver(BluetoothDevice device, int profile,
+            int expectedFlags) {
+        String[] actions = {
+                BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED,
+                BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED,
+                BluetoothInputDevice.ACTION_CONNECTION_STATE_CHANGED};
+        ConnectProfileReceiver receiver = new ConnectProfileReceiver(device, profile,
+                expectedFlags);
+        addReceiver(receiver, actions);
+        return receiver;
+    }
+
+    private ConnectPanReceiver getConnectPanReceiver(BluetoothDevice device, int role,
+            int expectedFlags) {
+        String[] actions = {BluetoothPan.ACTION_CONNECTION_STATE_CHANGED};
+        ConnectPanReceiver receiver = new ConnectPanReceiver(device, role, expectedFlags);
+        addReceiver(receiver, actions);
+        return receiver;
+    }
+
+    private StartStopScoReceiver getStartStopScoReceiver(int expectedFlags) {
+        String[] actions = {AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED};
+        StartStopScoReceiver receiver = new StartStopScoReceiver(expectedFlags);
+        addReceiver(receiver, actions);
+        return receiver;
+    }
+
+    private void removeReceiver(BroadcastReceiver receiver) {
+        mContext.unregisterReceiver(receiver);
+        mReceivers.remove(receiver);
+    }
+
+    private BluetoothProfile connectProxy(BluetoothAdapter adapter, int profile) {
+        switch (profile) {
+            case BluetoothProfile.A2DP:
+                if (mA2dp != null) {
+                    return mA2dp;
+                }
+                break;
+            case BluetoothProfile.HEADSET:
+                if (mHeadset != null) {
+                    return mHeadset;
+                }
+                break;
+            case BluetoothProfile.INPUT_DEVICE:
+                if (mInput != null) {
+                    return mInput;
+                }
+                break;
+            case BluetoothProfile.PAN:
+                if (mPan != null) {
+                    return mPan;
+                }
+                break;
+            default:
+                return null;
+        }
+        adapter.getProfileProxy(mContext, mServiceListener, profile);
+        long s = System.currentTimeMillis();
+        switch (profile) {
+            case BluetoothProfile.A2DP:
+                while (mA2dp == null && System.currentTimeMillis() - s < CONNECT_PROXY_TIMEOUT) {
+                    sleep(POLL_TIME);
+                }
+                return mA2dp;
+            case BluetoothProfile.HEADSET:
+                while (mHeadset == null && System.currentTimeMillis() - s < CONNECT_PROXY_TIMEOUT) {
+                    sleep(POLL_TIME);
+                }
+                return mHeadset;
+            case BluetoothProfile.INPUT_DEVICE:
+                while (mInput == null && System.currentTimeMillis() - s < CONNECT_PROXY_TIMEOUT) {
+                    sleep(POLL_TIME);
+                }
+                return mInput;
+            case BluetoothProfile.PAN:
+                while (mPan == null && System.currentTimeMillis() - s < CONNECT_PROXY_TIMEOUT) {
+                    sleep(POLL_TIME);
+                }
+                return mPan;
+            default:
+                return null;
+        }
+    }
+
+    private void sleep(long time) {
+        try {
+            Thread.sleep(time);
+        } catch (InterruptedException e) {
+        }
+    }
+}
diff --git a/core/tests/coretests/Android.mk b/core/tests/coretests/Android.mk
index b02d904..00f47fa 100644
--- a/core/tests/coretests/Android.mk
+++ b/core/tests/coretests/Android.mk
@@ -12,7 +12,7 @@
 	$(call all-java-files-under, EnabledTestApp/src)
 
 LOCAL_DX_FLAGS := --core-library
-LOCAL_STATIC_JAVA_LIBRARIES := core-tests android-common frameworks-core-util-lib
+LOCAL_STATIC_JAVA_LIBRARIES := core-tests android-common frameworks-core-util-lib mockwebserver
 LOCAL_JAVA_LIBRARIES := android.test.runner
 LOCAL_PACKAGE_NAME := FrameworksCoreTests
 
diff --git a/core/tests/coretests/AndroidManifest.xml b/core/tests/coretests/AndroidManifest.xml
index fadf1ec..8e2d925 100644
--- a/core/tests/coretests/AndroidManifest.xml
+++ b/core/tests/coretests/AndroidManifest.xml
@@ -98,6 +98,9 @@
     <uses-permission android:name="android.permission.ASEC_RENAME" />
     <uses-permission android:name="android.permission.SHUTDOWN" />
 
+    <!-- accessibility test permissions -->
+    <uses-permission android:name="android.permission.RETRIEVE_WINDOW_CONTENT" />
+
     <application android:theme="@style/Theme">
         <uses-library android:name="android.test.runner" />
         <activity android:name="android.view.ViewAttachTestActivity" android:label="View Attach Test">
@@ -1035,12 +1038,6 @@
             </intent-filter>
         </activity>
 
-        <service android:name="android.accessibilityservice.AccessibilityTestService">
-            <intent-filter>
-                <action android:name="android.accessibilityservice.AccessibilityService" />
-            </intent-filter>
-        </service>
-
         <service android:name="android.webkit.AccessibilityInjectorTest$MockAccessibilityService">
             <intent-filter>
                 <action android:name="android.accessibilityservice.AccessibilityService" />
@@ -1231,14 +1228,16 @@
             </intent-filter>
         </activity>
 
+        <activity android:name="android.accessibilityservice.InterrogationActivity">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST" />
+            </intent-filter>
+        </activity>
+
     </application>
 
     <instrumentation android:name="android.test.InstrumentationTestRunner"
             android:targetPackage="com.android.frameworks.coretests"
             android:label="Frameworks Core Tests" />
-
-    <instrumentation android:name="android.bluetooth.BluetoothTestRunner"
-            android:targetPackage="com.android.frameworks.coretests"
-            android:label="Bluetooth Tests" />
-
 </manifest>
diff --git a/core/tests/coretests/res/layout/interrogation_activity.xml b/core/tests/coretests/res/layout/interrogation_activity.xml
new file mode 100644
index 0000000..28d965b
--- /dev/null
+++ b/core/tests/coretests/res/layout/interrogation_activity.xml
@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+** Copyright 2011, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+**     http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+-->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/root"
+    android:orientation="vertical"
+    android:layout_width="fill_parent"
+    android:layout_height="wrap_content"
+    >
+
+    <LinearLayout
+        android:orientation="horizontal"
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent"
+        >
+        <Button
+            android:id="@+id/button1"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="@string/button1"
+        />
+        <Button
+            android:id="@+id/button2"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="@string/button2"
+        />
+        <Button
+            android:id="@+id/button3"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="@string/button3"
+        />
+    </LinearLayout>
+
+    <LinearLayout
+        android:orientation="horizontal"
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent"
+        >
+        <Button
+            android:id="@+id/button4"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="@string/button4"
+        />
+        <Button
+            android:id="@+id/button5"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="@string/button5"
+        />
+        <Button
+            android:id="@+id/button6"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="@string/button6"
+        />
+    </LinearLayout>
+
+    <LinearLayout
+        android:orientation="horizontal"
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent"
+        >
+        <Button
+            android:id="@+id/button7"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="@string/button7"
+        />
+        <Button
+            android:id="@+id/button8"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="@string/button8"
+        />
+        <Button
+            android:id="@+id/button9"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="@string/button9"
+        />
+    </LinearLayout>
+
+</LinearLayout>
diff --git a/core/tests/coretests/res/values/strings.xml b/core/tests/coretests/res/values/strings.xml
index 807386a..f51b08e 100644
--- a/core/tests/coretests/res/values/strings.xml
+++ b/core/tests/coretests/res/values/strings.xml
@@ -117,4 +117,16 @@
 
     <string name="searchable_label">SearchManager Test</string>
     <string name="searchable_hint">A search hint</string>
+
+    <!-- InterrogationActivity -->
+    <string name="button1">Button1</string>
+    <string name="button2">Button2</string>
+    <string name="button3">Button3</string>
+    <string name="button4">Button4</string>
+    <string name="button5">Button5</string>
+    <string name="button6">Button6</string>
+    <string name="button7">Button7</string>
+    <string name="button8">Button8</string>
+    <string name="button9">Button9</string>
+
 </resources>
diff --git a/core/tests/coretests/src/android/accessibilityservice/InterrogationActivity.java b/core/tests/coretests/src/android/accessibilityservice/InterrogationActivity.java
new file mode 100644
index 0000000..b4a0581
--- /dev/null
+++ b/core/tests/coretests/src/android/accessibilityservice/InterrogationActivity.java
@@ -0,0 +1,47 @@
+/**
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.accessibilityservice;
+
+import com.android.frameworks.coretests.R;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.view.View;
+
+/**
+ * Activity for testing the accessibility APIs for "interrogation" of
+ * the screen content. These APIs allow exploring the screen and
+ * requesting an action to be performed on a given view from an
+ * AccessiiblityService.
+ */
+public class InterrogationActivity extends Activity {
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.interrogation_activity);
+
+        findViewById(R.id.button5).setOnClickListener(new View.OnClickListener() {
+            public void onClick(View v) {
+                /* do nothing */
+            }
+        });
+        findViewById(R.id.button5).setOnLongClickListener(new View.OnLongClickListener() {
+            public boolean onLongClick(View v) {
+                return true;
+            }
+        });
+    }
+}
diff --git a/core/tests/coretests/src/android/accessibilityservice/InterrogationActivityTest.java b/core/tests/coretests/src/android/accessibilityservice/InterrogationActivityTest.java
new file mode 100644
index 0000000..99d534c
--- /dev/null
+++ b/core/tests/coretests/src/android/accessibilityservice/InterrogationActivityTest.java
@@ -0,0 +1,555 @@
+/**
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.accessibilityservice;
+
+import static android.view.accessibility.AccessibilityNodeInfo.ACTION_CLEAR_FOCUS;
+import static android.view.accessibility.AccessibilityNodeInfo.ACTION_CLEAR_SELECTION;
+import static android.view.accessibility.AccessibilityNodeInfo.ACTION_FOCUS;
+import static android.view.accessibility.AccessibilityNodeInfo.ACTION_SELECT;
+
+import com.android.frameworks.coretests.R;
+
+import android.content.Context;
+import android.graphics.Rect;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.os.SystemClock;
+import android.provider.Settings;
+import android.test.ActivityInstrumentationTestCase2;
+import android.test.suitebuilder.annotation.LargeTest;
+import android.util.Log;
+import android.view.accessibility.AccessibilityEvent;
+import android.view.accessibility.AccessibilityManager;
+import android.view.accessibility.AccessibilityNodeInfo;
+import android.view.accessibility.IAccessibilityManager;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Queue;
+
+/**
+ * Activity for testing the accessibility APIs for "interrogation" of
+ * the screen content. These APIs allow exploring the screen and
+ * requesting an action to be performed on a given view from an
+ * AccessiiblityService.
+ */
+public class InterrogationActivityTest
+        extends ActivityInstrumentationTestCase2<InterrogationActivity> {
+    private static final boolean DEBUG = true;
+
+    private static String LOG_TAG = "InterrogationActivityTest";
+
+    // Timeout before give up wait for the system to process an accessibility setting change.
+    private static final int TIMEOUT_PROPAGATE_ACCESSIBLITY_SETTING = 2000;
+
+    // Helpers to figure out the first and last test methods
+    // This is a workaround for the lack of such support in JUnit3
+    private static int sTestMethodCount;
+    private static int sExecutedTestMethodCount;
+
+    // Handle to a connection to the AccessibilityManagerService
+    private static IAccessibilityServiceConnection sConnection;
+
+    // The last received accessibility event
+    private static volatile AccessibilityEvent sLastFocusAccessibilityEvent;
+
+    public InterrogationActivityTest() {
+        super(InterrogationActivity.class);
+        sTestMethodCount = getTestMethodCount();
+    }
+
+    @LargeTest
+    public void testFindAccessibilityNodeInfoByViewId() throws Exception {
+        beforeClassIfNeeded();
+        final long startTimeMillis = SystemClock.uptimeMillis();
+        try {
+            // bring up the activity
+            getActivity();
+
+            AccessibilityNodeInfo button =
+                getConnection().findAccessibilityNodeInfoByViewIdInActiveWindow(R.id.button5);
+            assertNotNull(button);
+            assertEquals(0, button.getChildCount());
+
+            // bounds
+            Rect bounds = new Rect();
+            button.getBoundsInParent(bounds);
+            assertEquals(0, bounds.left);
+            assertEquals(0, bounds.top);
+            assertEquals(73, bounds.right);
+            assertEquals(48, bounds.bottom);
+
+            // char sequence attributes
+            assertEquals("com.android.frameworks.coretests", button.getPackageName());
+            assertEquals("android.widget.Button", button.getClassName());
+            assertEquals("Button5", button.getText());
+            assertNull(button.getContentDescription());
+
+            // boolean attributes
+            assertTrue(button.isFocusable());
+            assertTrue(button.isClickable());
+            assertTrue(button.isEnabled());
+            assertFalse(button.isFocused());
+            assertTrue(button.isClickable());
+            assertFalse(button.isPassword());
+            assertFalse(button.isSelected());
+            assertFalse(button.isCheckable());
+            assertFalse(button.isChecked());
+
+            // actions
+            assertEquals(ACTION_FOCUS | ACTION_SELECT | ACTION_CLEAR_SELECTION,
+                button.getActions());
+        } finally {
+            afterClassIfNeeded();
+            if (DEBUG) {
+                final long elapsedTimeMillis = SystemClock.uptimeMillis() - startTimeMillis;
+                Log.i(LOG_TAG, "testFindAccessibilityNodeInfoByViewId: "
+                        + elapsedTimeMillis + "ms");
+            }
+        }
+    }
+
+    @LargeTest
+    public void testFindAccessibilityNodeInfoByViewText() throws Exception {
+        beforeClassIfNeeded();
+        final long startTimeMillis = SystemClock.uptimeMillis();
+        try {
+            // bring up the activity
+            getActivity();
+
+            // find a view by text
+            List<AccessibilityNodeInfo> buttons =
+                getConnection().findAccessibilityNodeInfosByViewTextInActiveWindow("butto");
+            assertEquals(9, buttons.size());
+        } finally {
+            afterClassIfNeeded();
+            if (DEBUG) {
+                final long elapsedTimeMillis = SystemClock.uptimeMillis() - startTimeMillis;
+                Log.i(LOG_TAG, "testFindAccessibilityNodeInfoByViewText: "
+                        + elapsedTimeMillis + "ms");
+            }
+        }
+    }
+
+    @LargeTest
+    public void testTraverseAllViews() throws Exception {
+        beforeClassIfNeeded();
+        final long startTimeMillis = SystemClock.uptimeMillis();
+        try {
+            // bring up the activity
+            getActivity();
+
+            // make list of expected nodes
+            List<String> classNameAndTextList = new ArrayList<String>();
+            classNameAndTextList.add("android.widget.LinearLayout");
+            classNameAndTextList.add("android.widget.LinearLayout");
+            classNameAndTextList.add("android.widget.LinearLayout");
+            classNameAndTextList.add("android.widget.LinearLayout");
+            classNameAndTextList.add("android.widget.ButtonButton1");
+            classNameAndTextList.add("android.widget.ButtonButton2");
+            classNameAndTextList.add("android.widget.ButtonButton3");
+            classNameAndTextList.add("android.widget.ButtonButton4");
+            classNameAndTextList.add("android.widget.ButtonButton5");
+            classNameAndTextList.add("android.widget.ButtonButton6");
+            classNameAndTextList.add("android.widget.ButtonButton7");
+            classNameAndTextList.add("android.widget.ButtonButton8");
+            classNameAndTextList.add("android.widget.ButtonButton9");
+
+            AccessibilityNodeInfo root =
+                getConnection().findAccessibilityNodeInfoByViewIdInActiveWindow(R.id.root);
+            assertNotNull("We must find the existing root.", root);
+
+            Queue<AccessibilityNodeInfo> fringe = new LinkedList<AccessibilityNodeInfo>();
+            fringe.add(root);
+
+            // do a BFS traversal and check nodes
+            while (!fringe.isEmpty()) {
+                AccessibilityNodeInfo current = fringe.poll();
+
+                CharSequence className = current.getClassName();
+                CharSequence text = current.getText();
+                String receivedClassNameAndText = className.toString()
+                   + ((text != null) ? text.toString() : "");
+                String expectedClassNameAndText = classNameAndTextList.remove(0);
+
+                assertEquals("Did not get the expected node info",
+                        expectedClassNameAndText, receivedClassNameAndText);
+
+                final int childCount = current.getChildCount();
+                for (int i = 0; i < childCount; i++) {
+                    AccessibilityNodeInfo child = current.getChild(i);
+                    fringe.add(child);
+                }
+            }
+        } finally {
+            afterClassIfNeeded();
+            if (DEBUG) {
+                final long elapsedTimeMillis = SystemClock.uptimeMillis() - startTimeMillis;
+                Log.i(LOG_TAG, "testTraverseAllViews: " + elapsedTimeMillis + "ms");
+            }
+        }
+    }
+
+    @LargeTest
+    public void testPerformAccessibilityActionFocus() throws Exception {
+        beforeClassIfNeeded();
+        final long startTimeMillis = SystemClock.uptimeMillis();
+        try {
+            // bring up the activity
+            getActivity();
+
+            // find a view and make sure it is not focused
+            AccessibilityNodeInfo button =
+                getConnection().findAccessibilityNodeInfoByViewIdInActiveWindow(R.id.button5);
+            assertFalse(button.isFocused());
+
+            // focus the view
+            assertTrue(button.performAction(ACTION_FOCUS));
+
+            // find the view again and make sure it is focused
+            button = getConnection().findAccessibilityNodeInfoByViewIdInActiveWindow(R.id.button5);
+            assertTrue(button.isFocused());
+        } finally {
+            afterClassIfNeeded();
+            if (DEBUG) {
+                final long elapsedTimeMillis = SystemClock.uptimeMillis() - startTimeMillis;
+                Log.i(LOG_TAG, "testPerformAccessibilityActionFocus: " + elapsedTimeMillis + "ms");
+            }
+        }
+    }
+
+    @LargeTest
+    public void testPerformAccessibilityActionClearFocus() throws Exception {
+        beforeClassIfNeeded();
+        final long startTimeMillis = SystemClock.uptimeMillis();
+        try {
+            // bring up the activity
+            getActivity();
+
+            // find a view and make sure it is not focused
+            AccessibilityNodeInfo button =
+                getConnection().findAccessibilityNodeInfoByViewIdInActiveWindow(R.id.button5);
+            assertFalse(button.isFocused());
+
+            // focus the view
+            assertTrue(button.performAction(ACTION_FOCUS));
+
+            // find the view again and make sure it is focused
+            button =  getConnection().findAccessibilityNodeInfoByViewIdInActiveWindow(R.id.button5);
+            assertTrue(button.isFocused());
+
+            // unfocus the view
+            assertTrue(button.performAction(ACTION_CLEAR_FOCUS));
+
+            // find the view again and make sure it is not focused
+            button =  getConnection().findAccessibilityNodeInfoByViewIdInActiveWindow(R.id.button5);
+            assertFalse(button.isFocused());
+        } finally {
+            afterClassIfNeeded();
+            if (DEBUG) {
+                final long elapsedTimeMillis = SystemClock.uptimeMillis() - startTimeMillis;
+                Log.i(LOG_TAG, "testPerformAccessibilityActionClearFocus: "
+                        + elapsedTimeMillis + "ms");
+            }
+        }
+    }
+
+    @LargeTest
+    public void testPerformAccessibilityActionSelect() throws Exception {
+        beforeClassIfNeeded();
+        final long startTimeMillis = SystemClock.uptimeMillis();
+        try {
+            // bring up the activity
+            getActivity();
+
+            // find a view and make sure it is not selected
+            AccessibilityNodeInfo button =
+                getConnection().findAccessibilityNodeInfoByViewIdInActiveWindow(R.id.button5);
+            assertFalse(button.isSelected());
+
+            // select the view
+            assertTrue(button.performAction(ACTION_SELECT));
+
+            // find the view again and make sure it is selected
+            button = getConnection().findAccessibilityNodeInfoByViewIdInActiveWindow(R.id.button5);
+            assertTrue(button.isSelected());
+        } finally {
+            afterClassIfNeeded();
+            if (DEBUG) {
+                final long elapsedTimeMillis = SystemClock.uptimeMillis() - startTimeMillis;
+                Log.i(LOG_TAG, "testPerformAccessibilityActionSelect: " + elapsedTimeMillis + "ms");
+            }
+        }
+    }
+
+    @LargeTest
+    public void testPerformAccessibilityActionClearSelection() throws Exception {
+        beforeClassIfNeeded();
+        final long startTimeMillis = SystemClock.uptimeMillis();
+        try {
+            // bring up the activity
+            getActivity();
+
+            // find a view and make sure it is not selected
+            AccessibilityNodeInfo button =
+                getConnection().findAccessibilityNodeInfoByViewIdInActiveWindow(R.id.button5);
+            assertFalse(button.isSelected());
+
+            // select the view
+            assertTrue(button.performAction(ACTION_SELECT));
+
+            // find the view again and make sure it is selected
+            button = getConnection().findAccessibilityNodeInfoByViewIdInActiveWindow(R.id.button5);
+            assertTrue(button.isSelected());
+
+            // unselect the view
+            assertTrue(button.performAction(ACTION_CLEAR_SELECTION));
+
+            // find the view again and make sure it is not selected
+            button = getConnection().findAccessibilityNodeInfoByViewIdInActiveWindow(R.id.button5);
+            assertFalse(button.isSelected());
+        } finally {
+            afterClassIfNeeded();
+            if (DEBUG) {
+                final long elapsedTimeMillis = SystemClock.uptimeMillis() - startTimeMillis;
+                Log.i(LOG_TAG, "testPerformAccessibilityActionClearSelection: "
+                        + elapsedTimeMillis + "ms");
+            }
+        }
+    }
+
+    @LargeTest
+    public void testAccessibilityEventGetSource() throws Exception {
+        beforeClassIfNeeded();
+        final long startTimeMillis = SystemClock.uptimeMillis();
+        try {
+            // bring up the activity
+            getActivity();
+
+            // find a view and make sure it is not focused
+            AccessibilityNodeInfo button =
+                getConnection().findAccessibilityNodeInfoByViewIdInActiveWindow(R.id.button5);
+            assertFalse(button.isSelected());
+
+            // focus the view
+            assertTrue(button.performAction(ACTION_FOCUS));
+
+            synchronized (sConnection) {
+                try {
+                    sConnection.wait(500);
+                } catch (InterruptedException ie) {
+                    /* ignore */
+                }
+            }
+
+            // check that last event source
+            AccessibilityNodeInfo source = sLastFocusAccessibilityEvent.getSource();
+            assertNotNull(source);
+
+            // bounds
+            Rect buttonBounds = new Rect();
+            button.getBoundsInParent(buttonBounds);
+            Rect sourceBounds = new Rect();
+            source.getBoundsInParent(sourceBounds);
+
+            assertEquals(buttonBounds.left, sourceBounds.left);
+            assertEquals(buttonBounds.right, sourceBounds.right);
+            assertEquals(buttonBounds.top, sourceBounds.top);
+            assertEquals(buttonBounds.bottom, sourceBounds.bottom);
+
+            // char sequence attributes
+            assertEquals(button.getPackageName(), source.getPackageName());
+            assertEquals(button.getClassName(), source.getClassName());
+            assertEquals(button.getText(), source.getText());
+            assertSame(button.getContentDescription(), source.getContentDescription());
+
+            // boolean attributes
+            assertSame(button.isFocusable(), source.isFocusable());
+            assertSame(button.isClickable(), source.isClickable());
+            assertSame(button.isEnabled(), source.isEnabled());
+            assertNotSame(button.isFocused(), source.isFocused());
+            assertSame(button.isLongClickable(), source.isLongClickable());
+            assertSame(button.isPassword(), source.isPassword());
+            assertSame(button.isSelected(), source.isSelected());
+            assertSame(button.isCheckable(), source.isCheckable());
+            assertSame(button.isChecked(), source.isChecked());
+        } finally {
+            afterClassIfNeeded();
+            if (DEBUG) {
+                final long elapsedTimeMillis = SystemClock.uptimeMillis() - startTimeMillis;
+                Log.i(LOG_TAG, "testAccessibilityEventGetSource: " + elapsedTimeMillis + "ms");
+            }
+        }
+    }
+
+    @LargeTest
+    public void testObjectContract() throws Exception {
+        beforeClassIfNeeded();
+        final long startTimeMillis = SystemClock.uptimeMillis();
+        try {
+            // bring up the activity
+            getActivity();
+
+            // find a view and make sure it is not focused
+            AccessibilityNodeInfo button =
+                getConnection().findAccessibilityNodeInfoByViewIdInActiveWindow(R.id.button5);
+            AccessibilityNodeInfo parent = button.getParent();
+            final int childCount = parent.getChildCount();
+            for (int i = 0; i < childCount; i++) {
+                AccessibilityNodeInfo child = parent.getChild(i);
+                assertNotNull(child);
+                if (child.equals(button)) {
+                    assertEquals("Equal objects must have same hasCode.", button.hashCode(),
+                            child.hashCode());
+                    return;
+                }
+            }
+            fail("Parent's children do not have the info whose parent is the parent.");
+        } finally {
+            afterClassIfNeeded();
+            if (DEBUG) {
+                final long elapsedTimeMillis = SystemClock.uptimeMillis() - startTimeMillis;
+                Log.i(LOG_TAG, "testObjectContract: " + elapsedTimeMillis + "ms");
+            }
+        }
+    }
+
+    @Override
+    protected void scrubClass(Class<?> testCaseClass) {
+        /* intentionally do not scrub */
+    }
+
+    /**
+     * Sets accessibility in a given state by writing the state to the
+     * settings and waiting until the accessibility manager service picks
+     * it up for max {@link #TIMEOUT_PROPAGATE_ACCESSIBLITY_SETTING}.
+     *
+     * @param state The accessibility state.
+     * @throws Exception If any error occurs.
+     */
+    private void ensureAccessibilityState(boolean state) throws Exception {
+        Context context = getInstrumentation().getContext();
+        // If the local manager ready => nothing to do.
+        AccessibilityManager accessibilityManager = AccessibilityManager.getInstance(context);
+        if (accessibilityManager.isEnabled() == state) {
+            return;
+        }
+        synchronized (this) {
+            // Check if the system already knows about the desired state. 
+            final boolean currentState = Settings.Secure.getInt(context.getContentResolver(),
+                    Settings.Secure.ACCESSIBILITY_ENABLED) == 1;
+            if (currentState != state) {
+                // Make sure we wake ourselves as the desired state is propagated.
+                accessibilityManager.addAccessibilityStateChangeListener(
+                        new AccessibilityManager.AccessibilityStateChangeListener() {
+                            public void onAccessibilityStateChanged(boolean enabled) {
+                                synchronized (this) {
+                                    notifyAll();
+                                }
+                            }
+                        });
+                Settings.Secure.putInt(context.getContentResolver(),
+                        Settings.Secure.ACCESSIBILITY_ENABLED, state ? 1 : 0);
+            }
+            // No while one attempt and that is it.
+            try {
+                wait(TIMEOUT_PROPAGATE_ACCESSIBLITY_SETTING);
+            } catch (InterruptedException ie) {
+                /* ignore */
+            }
+        }
+        if (accessibilityManager.isEnabled() != state) {
+            throw new IllegalStateException("Could not set accessibility state to: " + state);
+        }
+    }
+
+    /**
+     * Execute some set up code before any test method.
+     *
+     * NOTE: I miss Junit4's @BeforeClass
+     *
+     * @throws Exception If an error occurs.
+     */
+    private void beforeClassIfNeeded() throws Exception {
+        sExecutedTestMethodCount++;
+        if (sExecutedTestMethodCount == 1) {
+            ensureAccessibilityState(true);
+        }
+    }
+
+    /**
+     * Execute some clean up code after all test methods.
+     *
+     * NOTE: I miss Junit4's @AfterClass
+     *
+     * @throws Exception If an error occurs.
+     */
+    public void afterClassIfNeeded() throws Exception {
+        if (sExecutedTestMethodCount == sTestMethodCount) {
+            sExecutedTestMethodCount = 0;
+            ensureAccessibilityState(false);
+        }
+    }
+
+    private static IAccessibilityServiceConnection getConnection() throws Exception {
+        if (sConnection == null) {
+            IEventListener listener = new IEventListener.Stub() {
+                public void setConnection(IAccessibilityServiceConnection connection)
+                        throws RemoteException {
+                    AccessibilityServiceInfo info = new AccessibilityServiceInfo();
+                    info.eventTypes = AccessibilityEvent.TYPES_ALL_MASK;
+                    info.feedbackType = AccessibilityServiceInfo.FEEDBACK_SPOKEN;
+                    info.notificationTimeout = 0;
+                    info.flags = AccessibilityServiceInfo.DEFAULT;
+                    connection.setServiceInfo(info);
+                }
+
+                public void onInterrupt() {}
+
+                public void onAccessibilityEvent(AccessibilityEvent event) {
+                    if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED) {
+                        sLastFocusAccessibilityEvent = AccessibilityEvent.obtain(event);
+                    }
+                    synchronized (sConnection) {
+                        sConnection.notifyAll();
+                    }
+                }
+            };
+            IAccessibilityManager manager = IAccessibilityManager.Stub.asInterface(
+                ServiceManager.getService(Context.ACCESSIBILITY_SERVICE));
+            sConnection = manager.registerEventListener(listener);
+        }
+        return sConnection;
+    }
+
+    /**
+     * @return The number of test methods.
+     */
+    private int getTestMethodCount() {
+        int testMethodCount = 0;
+        for (Method method : getClass().getMethods()) {
+            final int modifiers = method.getModifiers();
+            if (method.getName().startsWith("test")
+                    && (modifiers & Modifier.PUBLIC) != 0
+                    && (modifiers & Modifier.STATIC) == 0) {
+                testMethodCount++;
+            }
+        }
+        return testMethodCount;
+    }
+}
diff --git a/core/tests/coretests/src/android/bluetooth/AtParserTest.java b/core/tests/coretests/src/android/bluetooth/AtParserTest.java
deleted file mode 100644
index c5aa52b..0000000
--- a/core/tests/coretests/src/android/bluetooth/AtParserTest.java
+++ /dev/null
@@ -1,348 +0,0 @@
-/*
- * Copyright (C) 2007 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;
-
-import android.bluetooth.AtCommandHandler;
-import android.bluetooth.AtCommandResult;
-import android.bluetooth.AtParser;
-
-import java.util.*;
-import junit.framework.*;
-
-public class AtParserTest extends TestCase {
-
-    /* An AtCommandHandler instrumented for testing purposes
-     */
-    private class HandlerTest extends AtCommandHandler {
-        boolean mBasicCalled, mActionCalled, mReadCalled, mTestCalled, 
-                mSetCalled;
-        int mBasicReturn, mActionReturn, mReadReturn, mTestReturn, mSetReturn;
-        Object[] mSetArgs;
-        String mBasicArgs;
-
-        HandlerTest() {
-            this(AtCommandResult.ERROR, AtCommandResult.ERROR,
-                 AtCommandResult.ERROR, AtCommandResult.ERROR,
-                 AtCommandResult.ERROR);
-        }
-
-        HandlerTest(int a, int b, int c, int d, int e) {
-            mBasicReturn = a;
-            mActionReturn = b;
-            mReadReturn = c;
-            mSetReturn = d;
-            mTestReturn = e;
-            reset();
-        }
-        public void reset() {
-            mBasicCalled = false;
-            mActionCalled = false;
-            mReadCalled = false;
-            mSetCalled = false;
-            mTestCalled = false;
-            mSetArgs = null;
-            mBasicArgs = null;
-        }
-        public boolean wasCalled() {   // helper
-            return mBasicCalled || mActionCalled || mReadCalled ||
-                    mTestCalled || mSetCalled;
-        }
-        @Override
-        public AtCommandResult handleBasicCommand(String args) {
-            mBasicCalled = true;
-            mBasicArgs = args;
-            return new AtCommandResult(mBasicReturn);
-        }
-        @Override
-        public AtCommandResult handleActionCommand() {
-            mActionCalled = true;
-            return new AtCommandResult(mActionReturn);
-        }
-        @Override
-        public AtCommandResult handleReadCommand() {
-            mReadCalled = true;
-            return new AtCommandResult(mReadReturn);
-        }
-        @Override
-        public AtCommandResult handleSetCommand(Object[] args) {
-            mSetCalled = true;
-            mSetArgs = args;
-            return new AtCommandResult(mSetReturn);
-        }
-        @Override
-        public AtCommandResult handleTestCommand() {
-            mTestCalled = true;
-            return new AtCommandResult(mTestReturn);
-        }
-    }
-
-    private AtParser mParser;
-
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        mParser = new AtParser();
-    }
-
-    @Override
-    protected void tearDown() throws Exception {
-        super.tearDown();
-    }
-
-
-    /* Test that the right method is being called
-     */
-/*    public void testBasic1() throws Exception {
-        HandlerTest D = new HandlerTest(0, 1, 1, 1, 1);
-        HandlerTest A = new HandlerTest(0, 1, 1, 1, 1);
-        mParser.register('D', D);
-        mParser.register('A', A);
-
-        assertTrue(Arrays.equals(
-                   new String[]{"OK"},
-                   mParser.process("  A T D = ? T 1 2 3  4   ").toStrings()));
-        assertTrue(D.mBasicCalled);
-        assertFalse(D.mActionCalled);
-        assertFalse(D.mTestCalled);
-        assertFalse(D.mSetCalled);
-        assertFalse(D.mReadCalled);
-        assertFalse(A.wasCalled());
-        assertEquals("=?T1234", D.mBasicArgs);
-    }
-*/
-    /* Test some crazy strings
-     *//*
-    public void testBasic2() throws Exception {
-        HandlerTest A = new HandlerTest(0, 1, 1, 1, 1);
-        mParser.register('A', A);
-
-        assertTrue(Arrays.equals(
-                   new String[]{},
-                   mParser.process("     ").toStrings()));
-
-        assertTrue(Arrays.equals(
-                   new String[]{"OK"},
-                   mParser.process("  a T a t \"\"  1 2 3 a 4   ")
-                           .toStrings()));
-        assertEquals("T\"\"123A4", A.mBasicArgs);
-
-        assertTrue(Arrays.equals(
-                   new String[]{"OK"},
-                   mParser.process("  a T a t  \"foo BaR12Z\" 1 2 3 a 4   ")
-                           .toStrings()));
-        assertEquals("T\"foo BaR12Z\"123A4", A.mBasicArgs);
-
-        assertTrue(Arrays.equals(
-                   new String[]{"OK"},
-                   mParser.process("ATA\"").toStrings()));
-        assertEquals("\"\"", A.mBasicArgs);
-
-        assertTrue(Arrays.equals(
-                   new String[]{"OK"},
-                   mParser.process("ATA\"a").toStrings()));
-        assertEquals("\"a\"", A.mBasicArgs);
-
-        assertTrue(Arrays.equals(
-                   new String[]{"OK"},
-                   mParser.process("ATa\" ").toStrings()));
-        assertEquals("\" \"", A.mBasicArgs);
-
-        assertTrue(Arrays.equals(
-                   new String[]{"OK"},
-                   mParser.process("ATA  \"one \" two \"t hr ee ")
-                           .toStrings()));
-        assertEquals("\"one \"TWO\"t hr ee \"", A.mBasicArgs);
-    }*/
-
-    /* Simple extended commands
-     *//*
-    public void testExt1() throws Exception {
-        HandlerTest A = new HandlerTest(1, 0, 0, 0, 0);
-        mParser.register("+A", A);
-
-        assertTrue(Arrays.equals(
-                   new String[]{"ERROR"},
-                   mParser.process("AT+B").toStrings()));
-        assertFalse(A.wasCalled());
-
-        assertTrue(Arrays.equals(
-                   new String[]{"OK"},
-                   mParser.process("AT+A").toStrings()));
-        assertTrue(A.mActionCalled);
-        A.mActionCalled = false;
-        assertFalse(A.wasCalled());
-        A.reset();
-
-        assertTrue(Arrays.equals(
-                   new String[]{"OK"},
-                   mParser.process("AT+A=").toStrings()));
-        assertTrue(A.mSetCalled);
-        A.mSetCalled = false;
-        assertFalse(A.wasCalled());
-        assertEquals(1, A.mSetArgs.length);
-        A.reset();
-
-        assertTrue(Arrays.equals(
-                   new String[]{"OK"},
-                   mParser.process("AT+A=?").toStrings()));
-        assertTrue(A.mTestCalled);
-        A.mTestCalled = false;
-        assertFalse(A.wasCalled());
-        A.reset();
-
-        assertTrue(Arrays.equals(
-                   new String[]{"OK"},
-                   mParser.process("AT+A?").toStrings()));
-        assertTrue(A.mReadCalled);
-        A.mReadCalled = false;
-        assertFalse(A.wasCalled());
-        A.reset();
-    }
-*/
-
-
-    /* Test chained commands
-     *//*
-    public void testChain1() throws Exception {
-        HandlerTest A = new HandlerTest(0, 1, 1, 1, 1);
-        HandlerTest B = new HandlerTest(1, 0, 0, 0, 0);
-        HandlerTest C = new HandlerTest(1, 1, 1, 1, 1);
-        mParser.register('A', A);
-        mParser.register("+B", B);
-        mParser.register("+C", C);
-
-        assertTrue(Arrays.equals(
-                   new String[]{"ERROR"},
-                   mParser.process("AT+B;+C").toStrings()));
-        assertTrue(B.mActionCalled);
-        assertTrue(C.mActionCalled);
-        B.reset();
-        C.reset();
-
-        assertTrue(Arrays.equals(
-                   new String[]{"ERROR"},
-                   mParser.process("AT+C;+B").toStrings()));
-        assertFalse(B.wasCalled());
-        assertTrue(C.mActionCalled);
-        B.reset();
-        C.reset();
-    }*/
-
-    /* Test Set command
-     *//*
-    public void testSet1() throws Exception {
-        HandlerTest A = new HandlerTest(1, 1, 1, 0, 1);
-        mParser.register("+AAAA", A);
-        Object[] expectedResult;
-
-        assertTrue(Arrays.equals(
-                   new String[]{"OK"},
-                   mParser.process("AT+AAAA=1").toStrings()));
-        expectedResult = new Object[]{(Integer)1};
-        assertTrue(Arrays.equals(expectedResult, A.mSetArgs));
-        A.reset();
-
-        assertTrue(Arrays.equals(
-                   new String[]{"OK"},
-                   mParser.process("AT+AAAA=1,2,3").toStrings()));
-        expectedResult = new Object[]{(Integer)1, (Integer)2, (Integer)3};
-        assertTrue(Arrays.equals(expectedResult, A.mSetArgs));
-        A.reset();
-
-        assertTrue(Arrays.equals(
-                   new String[]{"OK"},
-                   mParser.process("AT+AAAA=3,0,0,1").toStrings()));
-        expectedResult = new Object[]{(Integer)3, (Integer)0, (Integer)0,
-                                      (Integer)1};
-        assertTrue(Arrays.equals(expectedResult, A.mSetArgs));
-        A.reset();
-
-        assertTrue(Arrays.equals(
-                   new String[]{"OK"},
-                   mParser.process("AT+AAAA=\"foo\",1,\"b,ar").toStrings()));
-        expectedResult = new Object[]{"\"foo\"", 1, "\"b,ar\""};
-        assertTrue(Arrays.equals(expectedResult, A.mSetArgs));
-        A.reset();
-
-        assertTrue(Arrays.equals(
-                   new String[]{"OK"},
-                   mParser.process("AT+AAAA=").toStrings()));
-        expectedResult = new Object[]{""};
-        assertTrue(Arrays.equals(expectedResult, A.mSetArgs));
-        A.reset();
-
-        assertTrue(Arrays.equals(
-                   new String[]{"OK"},
-                   mParser.process("AT+AAAA=,").toStrings()));
-        expectedResult = new Object[]{"", ""};
-        assertTrue(Arrays.equals(expectedResult, A.mSetArgs));
-        A.reset();
-
-        assertTrue(Arrays.equals(
-                   new String[]{"OK"},
-                   mParser.process("AT+AAAA=,,,").toStrings()));
-        expectedResult = new Object[]{"", "", "", ""};
-        assertTrue(Arrays.equals(expectedResult, A.mSetArgs));
-        A.reset();
-
-        assertTrue(Arrays.equals(
-                   new String[]{"OK"},
-                   mParser.process("AT+AAAA=,1,,\"foo\",").toStrings()));
-        expectedResult = new Object[]{"", 1, "", "\"foo\"", ""};
-        assertEquals(5, A.mSetArgs.length);
-        assertTrue(Arrays.equals(expectedResult, A.mSetArgs));
-        A.reset();
-    }*/
-
-    /* Test repeat command "A/"
-     *//*
-    public void testRepeat() throws Exception {
-        HandlerTest A = new HandlerTest(0, 0, 0, 0, 0);
-        mParser.register('A', A);
-
-        // Try repeated command on fresh parser
-        assertTrue(Arrays.equals(
-                   new String[]{},
-                   mParser.process("A/").toStrings()));
-        assertFalse(A.wasCalled());
-        A.reset();
-
-        assertTrue(Arrays.equals(
-                   new String[]{"OK"},
-                   mParser.process("ATA").toStrings()));
-        assertTrue(A.mBasicCalled);
-        assertEquals("", A.mBasicArgs);
-        A.reset();
-
-        // Now repeat the command
-        assertTrue(Arrays.equals(
-                   new String[]{"OK"},
-                   mParser.process("A/").toStrings()));
-        assertTrue(A.mBasicCalled);
-        assertEquals("", A.mBasicArgs);
-        A.reset();
-
-        // Multiple repeats
-        assertTrue(Arrays.equals(
-                   new String[]{"OK"},
-                   mParser.process("A/").toStrings()));
-        assertTrue(A.mBasicCalled);
-        assertEquals("", A.mBasicArgs);
-        A.reset();
-
-    }*/
-}
diff --git a/core/tests/coretests/src/android/bluetooth/BluetoothStressTest.java b/core/tests/coretests/src/android/bluetooth/BluetoothStressTest.java
deleted file mode 100644
index 7f13791..0000000
--- a/core/tests/coretests/src/android/bluetooth/BluetoothStressTest.java
+++ /dev/null
@@ -1,384 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.bluetooth;
-
-import android.content.Context;
-import android.test.InstrumentationTestCase;
-
-/**
- * Stress test suite for Bluetooth related functions.
- *
- * Includes tests for enabling/disabling bluetooth, enabling/disabling discoverable mode,
- * starting/stopping scans, connecting/disconnecting to HFP, A2DP, HID, PAN profiles, and verifying
- * that remote connections/disconnections occur for the PAN profile.
- * <p>
- * This test suite uses {@link android.bluetooth.BluetoothTestRunner} to for parameters such as the
- * number of iterations and the addresses of remote Bluetooth devices.
- */
-public class BluetoothStressTest extends InstrumentationTestCase {
-    private static final String TAG = "BluetoothStressTest";
-    private static final String OUTPUT_FILE = "BluetoothStressTestOutput.txt";
-
-    private BluetoothTestUtils mTestUtils;
-
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-
-        Context context = getInstrumentation().getTargetContext();
-        mTestUtils = new BluetoothTestUtils(context, TAG, OUTPUT_FILE);
-    }
-
-    @Override
-    protected void tearDown() throws Exception {
-        super.tearDown();
-
-        mTestUtils.close();
-    }
-
-    /**
-     * Stress test for enabling and disabling Bluetooth.
-     */
-    public void testEnable() {
-        int iterations = BluetoothTestRunner.sEnableIterations;
-        if (iterations == 0) {
-            return;
-        }
-
-        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
-        mTestUtils.disable(adapter);
-
-        for (int i = 0; i < iterations; i++) {
-            mTestUtils.writeOutput("enable iteration " + (i + 1) + " of " + iterations);
-            mTestUtils.enable(adapter);
-            mTestUtils.disable(adapter);
-        }
-    }
-
-    /**
-     * Stress test for putting the device in and taking the device out of discoverable mode.
-     */
-    public void testDiscoverable() {
-        int iterations = BluetoothTestRunner.sDiscoverableIterations;
-        if (iterations == 0) {
-            return;
-        }
-
-        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
-        mTestUtils.disable(adapter);
-        mTestUtils.enable(adapter);
-        mTestUtils.undiscoverable(adapter);
-
-        for (int i = 0; i < iterations; i++) {
-            mTestUtils.writeOutput("discoverable iteration " + (i + 1) + " of " + iterations);
-            mTestUtils.discoverable(adapter);
-            mTestUtils.undiscoverable(adapter);
-        }
-
-        mTestUtils.disable(adapter);
-    }
-
-    /**
-     * Stress test for starting and stopping Bluetooth scans.
-     */
-    public void testScan() {
-        int iterations = BluetoothTestRunner.sScanIterations;
-        if (iterations == 0) {
-            return;
-        }
-
-        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
-        mTestUtils.disable(adapter);
-        mTestUtils.enable(adapter);
-        mTestUtils.stopScan(adapter);
-
-        for (int i = 0; i < iterations; i++) {
-            mTestUtils.writeOutput("scan iteration " + (i + 1) + " of " + iterations);
-            mTestUtils.startScan(adapter);
-            mTestUtils.stopScan(adapter);
-        }
-
-        mTestUtils.disable(adapter);
-    }
-
-    /**
-     * Stress test for enabling and disabling the PAN NAP profile.
-     */
-    public void testEnablePan() {
-        int iterations = BluetoothTestRunner.sEnablePanIterations;
-        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
-        mTestUtils.disable(adapter);
-        mTestUtils.enable(adapter);
-        mTestUtils.disablePan(adapter);
-
-        for (int i = 0; i < iterations; i++) {
-            mTestUtils.writeOutput("testEnablePan iteration " + (i + 1) + " of "
-                    + iterations);
-            mTestUtils.enablePan(adapter);
-            mTestUtils.disablePan(adapter);
-        }
-
-        mTestUtils.disable(adapter);
-    }
-
-    /**
-     * Stress test for pairing and unpairing with a remote device.
-     * <p>
-     * In this test, the local device initiates pairing with a remote device, and then unpairs with
-     * the device after the pairing has successfully completed.
-     */
-    public void testPair() {
-        int iterations = BluetoothTestRunner.sPairIterations;
-        if (iterations == 0) {
-            return;
-        }
-
-        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
-        BluetoothDevice device = adapter.getRemoteDevice(BluetoothTestRunner.sDeviceAddress);
-        mTestUtils.disable(adapter);
-        mTestUtils.enable(adapter);
-        mTestUtils.unpair(adapter, device);
-
-        for (int i = 0; i < iterations; i++) {
-            mTestUtils.writeOutput("pair iteration " + (i + 1) + " of " + iterations);
-            mTestUtils.pair(adapter, device, BluetoothTestRunner.sDevicePairPasskey,
-                    BluetoothTestRunner.sDevicePairPin);
-            mTestUtils.unpair(adapter, device);
-        }
-        mTestUtils.disable(adapter);
-    }
-
-    /**
-     * Stress test for accepting a pairing request and unpairing with a remote device.
-     * <p>
-     * In this test, the local device waits for a pairing request from a remote device.  It accepts
-     * the request and then unpairs after the paring has successfully completed.
-     */
-    public void testAcceptPair() {
-        int iterations = BluetoothTestRunner.sPairIterations;
-        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
-        BluetoothDevice device = adapter.getRemoteDevice(BluetoothTestRunner.sDeviceAddress);
-        mTestUtils.disable(adapter);
-        mTestUtils.enable(adapter);
-        mTestUtils.unpair(adapter, device);
-
-        for (int i = 0; i < iterations; i++) {
-            mTestUtils.writeOutput("acceptPair iteration " + (i + 1) + " of " + iterations);
-            mTestUtils.acceptPair(adapter, device, BluetoothTestRunner.sDevicePairPasskey,
-                    BluetoothTestRunner.sDevicePairPin);
-            mTestUtils.unpair(adapter, device);
-        }
-        mTestUtils.disable(adapter);
-    }
-
-    /**
-     * Stress test for connecting and disconnecting with an A2DP source.
-     * <p>
-     * In this test, the local device plays the role of an A2DP sink, and initiates connections and
-     * disconnections with an A2DP source.
-     */
-    public void testConnectA2dp() {
-        int iterations = BluetoothTestRunner.sConnectA2dpIterations;
-        if (iterations == 0) {
-            return;
-        }
-
-        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
-        BluetoothDevice device = adapter.getRemoteDevice(BluetoothTestRunner.sDeviceAddress);
-        mTestUtils.disable(adapter);
-        mTestUtils.enable(adapter);
-        mTestUtils.unpair(adapter, device);
-        mTestUtils.pair(adapter, device, BluetoothTestRunner.sDevicePairPasskey,
-                BluetoothTestRunner.sDevicePairPin);
-        mTestUtils.disconnectProfile(adapter, device, BluetoothProfile.A2DP, null);
-
-        for (int i = 0; i < iterations; i++) {
-            mTestUtils.writeOutput("connectA2dp iteration " + (i + 1) + " of " + iterations);
-            mTestUtils.connectProfile(adapter, device, BluetoothProfile.A2DP,
-                    String.format("connectA2dp(device=%s)", device));
-            mTestUtils.disconnectProfile(adapter, device, BluetoothProfile.A2DP,
-                    String.format("disconnectA2dp(device=%s)", device));
-        }
-
-        mTestUtils.unpair(adapter, device);
-        mTestUtils.disable(adapter);
-    }
-
-    /**
-     * Stress test for connecting and disconnecting the HFP with a hands free device.
-     * <p>
-     * In this test, the local device plays the role of an HFP audio gateway, and initiates
-     * connections and disconnections with a hands free device.
-     */
-    public void testConnectHeadset() {
-        int iterations = BluetoothTestRunner.sConnectHeadsetIterations;
-        if (iterations == 0) {
-            return;
-        }
-
-        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
-        BluetoothDevice device = adapter.getRemoteDevice(BluetoothTestRunner.sDeviceAddress);
-        mTestUtils.disable(adapter);
-        mTestUtils.enable(adapter);
-        mTestUtils.unpair(adapter, device);
-        mTestUtils.pair(adapter, device, BluetoothTestRunner.sDevicePairPasskey,
-                BluetoothTestRunner.sDevicePairPin);
-        mTestUtils.disconnectProfile(adapter, device, BluetoothProfile.HEADSET, null);
-
-        for (int i = 0; i < iterations; i++) {
-            mTestUtils.writeOutput("connectHeadset iteration " + (i + 1) + " of " + iterations);
-            mTestUtils.connectProfile(adapter, device, BluetoothProfile.HEADSET,
-                    String.format("connectHeadset(device=%s)", device));
-            mTestUtils.disconnectProfile(adapter, device, BluetoothProfile.HEADSET,
-                    String.format("disconnectHeadset(device=%s)", device));
-        }
-
-        mTestUtils.unpair(adapter, device);
-        mTestUtils.disable(adapter);
-    }
-
-    /**
-     * Stress test for connecting and disconnecting with a HID device.
-     * <p>
-     * In this test, the local device plays the role of a HID host, and initiates connections and
-     * disconnections with a HID device.
-     */
-    public void testConnectInput() {
-        int iterations = BluetoothTestRunner.sConnectInputIterations;
-        if (iterations == 0) {
-            return;
-        }
-
-        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
-        BluetoothDevice device = adapter.getRemoteDevice(BluetoothTestRunner.sDeviceAddress);
-        mTestUtils.disable(adapter);
-        mTestUtils.enable(adapter);
-        mTestUtils.unpair(adapter, device);
-        mTestUtils.pair(adapter, device, BluetoothTestRunner.sDevicePairPasskey,
-                BluetoothTestRunner.sDevicePairPin);
-        mTestUtils.disconnectProfile(adapter, device, BluetoothProfile.INPUT_DEVICE, null);
-
-        for (int i = 0; i < iterations; i++) {
-            mTestUtils.writeOutput("connectInput iteration " + (i + 1) + " of " + iterations);
-            mTestUtils.connectProfile(adapter, device, BluetoothProfile.INPUT_DEVICE,
-                    String.format("connectInput(device=%s)", device));
-            mTestUtils.disconnectProfile(adapter, device, BluetoothProfile.INPUT_DEVICE,
-                    String.format("disconnectInput(device=%s)", device));
-        }
-
-        mTestUtils.unpair(adapter, device);
-        mTestUtils.disable(adapter);
-    }
-
-    /**
-     * Stress test for connecting and disconnecting with a PAN NAP.
-     * <p>
-     * In this test, the local device plays the role of a PANU, and initiates connections and
-     * disconnections with a NAP.
-     */
-    public void testConnectPan() {
-        int iterations = BluetoothTestRunner.sConnectPanIterations;
-        if (iterations == 0) {
-            return;
-        }
-
-        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
-        BluetoothDevice device = adapter.getRemoteDevice(BluetoothTestRunner.sDeviceAddress);
-        mTestUtils.disable(adapter);
-        mTestUtils.enable(adapter);
-        mTestUtils.unpair(adapter, device);
-        mTestUtils.pair(adapter, device, BluetoothTestRunner.sDevicePairPasskey,
-                BluetoothTestRunner.sDevicePairPin);
-
-        for (int i = 0; i < iterations; i++) {
-            mTestUtils.writeOutput("connectPan iteration " + (i + 1) + " of " + iterations);
-            mTestUtils.connectPan(adapter, device);
-            mTestUtils.disconnectPan(adapter, device);
-        }
-
-        mTestUtils.unpair(adapter, device);
-        mTestUtils.disable(adapter);
-    }
-
-    /**
-     * Stress test for verifying a PANU connecting and disconnecting with the device.
-     * <p>
-     * In this test, the local device plays the role of a NAP which a remote PANU connects and
-     * disconnects from.
-     */
-    public void testIncomingPanConnection() {
-        int iterations = BluetoothTestRunner.sConnectPanIterations;
-        if (iterations == 0) {
-            return;
-        }
-
-        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
-        BluetoothDevice device = adapter.getRemoteDevice(BluetoothTestRunner.sDeviceAddress);
-        mTestUtils.disable(adapter);
-        mTestUtils.enable(adapter);
-        mTestUtils.disablePan(adapter);
-        mTestUtils.enablePan(adapter);
-        mTestUtils.unpair(adapter, device);
-        mTestUtils.acceptPair(adapter, device, BluetoothTestRunner.sDevicePairPasskey,
-                BluetoothTestRunner.sDevicePairPin);
-
-        for (int i = 0; i < iterations; i++) {
-            mTestUtils.writeOutput("incomingPanConnection iteration " + (i + 1) + " of "
-                    + iterations);
-            mTestUtils.incomingPanConnection(adapter, device);
-            mTestUtils.incomingPanDisconnection(adapter, device);
-        }
-
-        mTestUtils.unpair(adapter, device);
-        mTestUtils.disablePan(adapter);
-        mTestUtils.disable(adapter);
-    }
-
-    /**
-     * Stress test for verifying that AudioManager can open and close SCO connections.
-     * <p>
-     * In this test, a HSP connection is opened with an external headset and the SCO connection is
-     * repeatibly opened and closed.
-     */
-    public void testStartStopSco() {
-        int iterations = BluetoothTestRunner.sStartStopScoIterations;
-        if (iterations == 0) {
-            return;
-        }
-
-        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
-        BluetoothDevice device = adapter.getRemoteDevice(BluetoothTestRunner.sDeviceAddress);
-        mTestUtils.disable(adapter);
-        mTestUtils.enable(adapter);
-        mTestUtils.unpair(adapter, device);
-        mTestUtils.pair(adapter, device, BluetoothTestRunner.sDevicePairPasskey,
-                BluetoothTestRunner.sDevicePairPin);
-        mTestUtils.disconnectProfile(adapter, device, BluetoothProfile.HEADSET, null);
-        mTestUtils.connectProfile(adapter, device, BluetoothProfile.HEADSET, null);
-        mTestUtils.stopSco(adapter, device);
-
-        for (int i = 0; i < iterations; i++) {
-            mTestUtils.writeOutput("startStopSco iteration " + (i + 1) + " of " + iterations);
-            mTestUtils.startSco(adapter, device);
-            mTestUtils.stopSco(adapter, device);
-        }
-
-        mTestUtils.disconnectProfile(adapter, device, BluetoothProfile.HEADSET, null);
-        mTestUtils.unpair(adapter, device);
-        mTestUtils.disable(adapter);
-    }
-}
diff --git a/core/tests/coretests/src/android/bluetooth/BluetoothTestRunner.java b/core/tests/coretests/src/android/bluetooth/BluetoothTestRunner.java
deleted file mode 100644
index 64d2c12..0000000
--- a/core/tests/coretests/src/android/bluetooth/BluetoothTestRunner.java
+++ /dev/null
@@ -1,214 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.bluetooth;
-
-import junit.framework.TestSuite;
-
-import android.os.Bundle;
-import android.test.InstrumentationTestRunner;
-import android.test.InstrumentationTestSuite;
-import android.util.Log;
-
-/**
- * Instrumentation test runner for Bluetooth tests.
- * <p>
- * To run:
- * <pre>
- * {@code
- * adb shell am instrument \
- *     [-e enable_iterations <iterations>] \
- *     [-e discoverable_iterations <iterations>] \
- *     [-e scan_iterations <iterations>] \
- *     [-e enable_pan_iterations <iterations>] \
- *     [-e pair_iterations <iterations>] \
- *     [-e connect_a2dp_iterations <iterations>] \
- *     [-e connect_headset_iterations <iterations>] \
- *     [-e connect_input_iterations <iterations>] \
- *     [-e connect_pan_iterations <iterations>] \
- *     [-e start_stop_sco_iterations <iterations>] \
- *     [-e pair_address <address>] \
- *     [-e headset_address <address>] \
- *     [-e a2dp_address <address>] \
- *     [-e input_address <address>] \
- *     [-e pan_address <address>] \
- *     [-e pair_pin <pin>] \
- *     [-e pair_passkey <passkey>] \
- *     -w com.android.frameworks.coretests/android.bluetooth.BluetoothTestRunner
- * }
- * </pre>
- */
-public class BluetoothTestRunner extends InstrumentationTestRunner {
-    private static final String TAG = "BluetoothTestRunner";
-
-    public static int sEnableIterations = 100;
-    public static int sDiscoverableIterations = 1000;
-    public static int sScanIterations = 1000;
-    public static int sEnablePanIterations = 1000;
-    public static int sPairIterations = 100;
-    public static int sConnectHeadsetIterations = 100;
-    public static int sConnectA2dpIterations = 100;
-    public static int sConnectInputIterations = 100;
-    public static int sConnectPanIterations = 100;
-    public static int sStartStopScoIterations = 100;
-
-    public static String sDeviceAddress = "";
-    public static byte[] sDevicePairPin = {'1', '2', '3', '4'};
-    public static int sDevicePairPasskey = 123456;
-
-    @Override
-    public TestSuite getAllTests() {
-        TestSuite suite = new InstrumentationTestSuite(this);
-        suite.addTestSuite(BluetoothStressTest.class);
-        return suite;
-    }
-
-    @Override
-    public ClassLoader getLoader() {
-        return BluetoothTestRunner.class.getClassLoader();
-    }
-
-    @Override
-    public void onCreate(Bundle arguments) {
-        String val = arguments.getString("enable_iterations");
-        if (val != null) {
-            try {
-                sEnableIterations = Integer.parseInt(val);
-            } catch (NumberFormatException e) {
-                // Invalid argument, fall back to default value
-            }
-        }
-
-        val = arguments.getString("discoverable_iterations");
-        if (val != null) {
-            try {
-                sDiscoverableIterations = Integer.parseInt(val);
-            } catch (NumberFormatException e) {
-                // Invalid argument, fall back to default value
-            }
-        }
-
-        val = arguments.getString("scan_iterations");
-        if (val != null) {
-            try {
-                sScanIterations = Integer.parseInt(val);
-            } catch (NumberFormatException e) {
-                // Invalid argument, fall back to default value
-            }
-        }
-
-        val = arguments.getString("enable_pan_iterations");
-        if (val != null) {
-            try {
-                sEnablePanIterations = Integer.parseInt(val);
-            } catch (NumberFormatException e) {
-                // Invalid argument, fall back to default value
-            }
-        }
-
-        val = arguments.getString("pair_iterations");
-        if (val != null) {
-            try {
-                sPairIterations = Integer.parseInt(val);
-            } catch (NumberFormatException e) {
-                // Invalid argument, fall back to default value
-            }
-        }
-
-        val = arguments.getString("connect_a2dp_iterations");
-        if (val != null) {
-            try {
-                sConnectA2dpIterations = Integer.parseInt(val);
-            } catch (NumberFormatException e) {
-                // Invalid argument, fall back to default value
-            }
-        }
-
-        val = arguments.getString("connect_headset_iterations");
-        if (val != null) {
-            try {
-                sConnectHeadsetIterations = Integer.parseInt(val);
-            } catch (NumberFormatException e) {
-                // Invalid argument, fall back to default value
-            }
-        }
-
-        val = arguments.getString("connect_input_iterations");
-        if (val != null) {
-            try {
-                sConnectInputIterations = Integer.parseInt(val);
-            } catch (NumberFormatException e) {
-                // Invalid argument, fall back to default value
-            }
-        }
-
-        val = arguments.getString("connect_pan_iterations");
-        if (val != null) {
-            try {
-                sConnectPanIterations = Integer.parseInt(val);
-            } catch (NumberFormatException e) {
-                // Invalid argument, fall back to default value
-            }
-        }
-
-        val = arguments.getString("start_stop_sco_iterations");
-        if (val != null) {
-            try {
-                sStartStopScoIterations = Integer.parseInt(val);
-            } catch (NumberFormatException e) {
-                // Invalid argument, fall back to default value
-            }
-        }
-
-        val = arguments.getString("device_address");
-        if (val != null) {
-            sDeviceAddress = val;
-        }
-
-        val = arguments.getString("device_pair_pin");
-        if (val != null) {
-            byte[] pin = BluetoothDevice.convertPinToBytes(val);
-            if (pin != null) {
-                sDevicePairPin = pin;
-            }
-        }
-
-        val = arguments.getString("device_pair_passkey");
-        if (val != null) {
-            try {
-                sDevicePairPasskey = Integer.parseInt(val);
-            } catch (NumberFormatException e) {
-                // Invalid argument, fall back to default value
-            }
-        }
-
-        Log.i(TAG, String.format("enable_iterations=%d", sEnableIterations));
-        Log.i(TAG, String.format("discoverable_iterations=%d", sDiscoverableIterations));
-        Log.i(TAG, String.format("scan_iterations=%d", sScanIterations));
-        Log.i(TAG, String.format("pair_iterations=%d", sPairIterations));
-        Log.i(TAG, String.format("connect_a2dp_iterations=%d", sConnectA2dpIterations));
-        Log.i(TAG, String.format("connect_headset_iterations=%d", sConnectHeadsetIterations));
-        Log.i(TAG, String.format("connect_input_iterations=%d", sConnectInputIterations));
-        Log.i(TAG, String.format("connect_pan_iterations=%d", sConnectPanIterations));
-        Log.i(TAG, String.format("start_stop_sco_iterations=%d", sStartStopScoIterations));
-        Log.i(TAG, String.format("device_address=%s", sDeviceAddress));
-        Log.i(TAG, String.format("device_pair_pin=%s", new String(sDevicePairPin)));
-        Log.i(TAG, String.format("device_pair_passkey=%d", sDevicePairPasskey));
-
-        // Call onCreate last since we want to set the static variables first.
-        super.onCreate(arguments);
-    }
-}
diff --git a/core/tests/coretests/src/android/bluetooth/BluetoothTestUtils.java b/core/tests/coretests/src/android/bluetooth/BluetoothTestUtils.java
deleted file mode 100644
index f1dd8fe..0000000
--- a/core/tests/coretests/src/android/bluetooth/BluetoothTestUtils.java
+++ /dev/null
@@ -1,1487 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.bluetooth;
-
-import android.bluetooth.BluetoothPan;
-import android.bluetooth.BluetoothProfile;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.media.AudioManager;
-import android.os.Environment;
-import android.util.Log;
-
-import junit.framework.Assert;
-
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-public class BluetoothTestUtils extends Assert {
-
-    /** Timeout for enable/disable in ms. */
-    private static final int ENABLE_DISABLE_TIMEOUT = 20000;
-    /** Timeout for discoverable/undiscoverable in ms. */
-    private static final int DISCOVERABLE_UNDISCOVERABLE_TIMEOUT = 5000;
-    /** Timeout for starting/stopping a scan in ms. */
-    private static final int START_STOP_SCAN_TIMEOUT = 5000;
-    /** Timeout for pair/unpair in ms. */
-    private static final int PAIR_UNPAIR_TIMEOUT = 20000;
-    /** Timeout for connecting/disconnecting a profile in ms. */
-    private static final int CONNECT_DISCONNECT_PROFILE_TIMEOUT = 20000;
-    /** Timeout to start or stop a SCO channel in ms. */
-    private static final int START_STOP_SCO_TIMEOUT = 10000;
-    /** Timeout to connect a profile proxy in ms. */
-    private static final int CONNECT_PROXY_TIMEOUT = 5000;
-    /** Time between polls in ms. */
-    private static final int POLL_TIME = 100;
-
-    private abstract class FlagReceiver extends BroadcastReceiver {
-        private int mExpectedFlags = 0;
-        private int mFiredFlags = 0;
-        private long mCompletedTime = -1;
-
-        public FlagReceiver(int expectedFlags) {
-            mExpectedFlags = expectedFlags;
-        }
-
-        public int getFiredFlags() {
-            synchronized (this) {
-                return mFiredFlags;
-            }
-        }
-
-        public long getCompletedTime() {
-            synchronized (this) {
-                return mCompletedTime;
-            }
-        }
-
-        protected void setFiredFlag(int flag) {
-            synchronized (this) {
-                mFiredFlags |= flag;
-                if ((mFiredFlags & mExpectedFlags) == mExpectedFlags) {
-                    mCompletedTime = System.currentTimeMillis();
-                }
-            }
-        }
-    }
-
-    private class BluetoothReceiver extends FlagReceiver {
-        private static final int DISCOVERY_STARTED_FLAG = 1;
-        private static final int DISCOVERY_FINISHED_FLAG = 1 << 1;
-        private static final int SCAN_MODE_NONE_FLAG = 1 << 2;
-        private static final int SCAN_MODE_CONNECTABLE_FLAG = 1 << 3;
-        private static final int SCAN_MODE_CONNECTABLE_DISCOVERABLE_FLAG = 1 << 4;
-        private static final int STATE_OFF_FLAG = 1 << 5;
-        private static final int STATE_TURNING_ON_FLAG = 1 << 6;
-        private static final int STATE_ON_FLAG = 1 << 7;
-        private static final int STATE_TURNING_OFF_FLAG = 1 << 8;
-
-        public BluetoothReceiver(int expectedFlags) {
-            super(expectedFlags);
-        }
-
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            if (BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(intent.getAction())) {
-                setFiredFlag(DISCOVERY_STARTED_FLAG);
-            } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(intent.getAction())) {
-                setFiredFlag(DISCOVERY_FINISHED_FLAG);
-            } else if (BluetoothAdapter.ACTION_SCAN_MODE_CHANGED.equals(intent.getAction())) {
-                int mode = intent.getIntExtra(BluetoothAdapter.EXTRA_SCAN_MODE, -1);
-                assertNotSame(-1, mode);
-                switch (mode) {
-                    case BluetoothAdapter.SCAN_MODE_NONE:
-                        setFiredFlag(SCAN_MODE_NONE_FLAG);
-                        break;
-                    case BluetoothAdapter.SCAN_MODE_CONNECTABLE:
-                        setFiredFlag(SCAN_MODE_CONNECTABLE_FLAG);
-                        break;
-                    case BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE:
-                        setFiredFlag(SCAN_MODE_CONNECTABLE_DISCOVERABLE_FLAG);
-                        break;
-                }
-            } else if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(intent.getAction())) {
-                int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1);
-                assertNotSame(-1, state);
-                switch (state) {
-                    case BluetoothAdapter.STATE_OFF:
-                        setFiredFlag(STATE_OFF_FLAG);
-                        break;
-                    case BluetoothAdapter.STATE_TURNING_ON:
-                        setFiredFlag(STATE_TURNING_ON_FLAG);
-                        break;
-                    case BluetoothAdapter.STATE_ON:
-                        setFiredFlag(STATE_ON_FLAG);
-                        break;
-                    case BluetoothAdapter.STATE_TURNING_OFF:
-                        setFiredFlag(STATE_TURNING_OFF_FLAG);
-                        break;
-                }
-            }
-        }
-    }
-
-    private class PairReceiver extends FlagReceiver {
-        private static final int STATE_BONDED_FLAG = 1;
-        private static final int STATE_BONDING_FLAG = 1 << 1;
-        private static final int STATE_NONE_FLAG = 1 << 2;
-
-        private BluetoothDevice mDevice;
-        private int mPasskey;
-        private byte[] mPin;
-
-        public PairReceiver(BluetoothDevice device, int passkey, byte[] pin, int expectedFlags) {
-            super(expectedFlags);
-
-            mDevice = device;
-            mPasskey = passkey;
-            mPin = pin;
-        }
-
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            if (!mDevice.equals(intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE))) {
-                return;
-            }
-
-            if (BluetoothDevice.ACTION_PAIRING_REQUEST.equals(intent.getAction())) {
-                int varient = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, -1);
-                assertNotSame(-1, varient);
-                switch (varient) {
-                    case BluetoothDevice.PAIRING_VARIANT_PIN:
-                        mDevice.setPin(mPin);
-                        break;
-                    case BluetoothDevice.PAIRING_VARIANT_PASSKEY:
-                        mDevice.setPasskey(mPasskey);
-                        break;
-                    case BluetoothDevice.PAIRING_VARIANT_PASSKEY_CONFIRMATION:
-                    case BluetoothDevice.PAIRING_VARIANT_CONSENT:
-                        mDevice.setPairingConfirmation(true);
-                        break;
-                    case BluetoothDevice.PAIRING_VARIANT_OOB_CONSENT:
-                        mDevice.setRemoteOutOfBandData();
-                        break;
-                }
-            } else if (BluetoothDevice.ACTION_BOND_STATE_CHANGED.equals(intent.getAction())) {
-                int state = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, -1);
-                assertNotSame(-1, state);
-                switch (state) {
-                    case BluetoothDevice.BOND_NONE:
-                        setFiredFlag(STATE_NONE_FLAG);
-                        break;
-                    case BluetoothDevice.BOND_BONDING:
-                        setFiredFlag(STATE_BONDING_FLAG);
-                        break;
-                    case BluetoothDevice.BOND_BONDED:
-                        setFiredFlag(STATE_BONDED_FLAG);
-                        break;
-                }
-            }
-        }
-    }
-
-    private class ConnectProfileReceiver extends FlagReceiver {
-        private static final int STATE_DISCONNECTED_FLAG = 1;
-        private static final int STATE_CONNECTING_FLAG = 1 << 1;
-        private static final int STATE_CONNECTED_FLAG = 1 << 2;
-        private static final int STATE_DISCONNECTING_FLAG = 1 << 3;
-
-        private BluetoothDevice mDevice;
-        private int mProfile;
-        private String mConnectionAction;
-
-        public ConnectProfileReceiver(BluetoothDevice device, int profile, int expectedFlags) {
-            super(expectedFlags);
-
-            mDevice = device;
-            mProfile = profile;
-
-            switch (mProfile) {
-                case BluetoothProfile.A2DP:
-                    mConnectionAction = BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED;
-                    break;
-                case BluetoothProfile.HEADSET:
-                    mConnectionAction = BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED;
-                    break;
-                case BluetoothProfile.INPUT_DEVICE:
-                    mConnectionAction = BluetoothInputDevice.ACTION_CONNECTION_STATE_CHANGED;
-                    break;
-                case BluetoothProfile.PAN:
-                    mConnectionAction = BluetoothPan.ACTION_CONNECTION_STATE_CHANGED;
-                    break;
-                default:
-                    mConnectionAction = null;
-            }
-        }
-
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            if (mConnectionAction != null && mConnectionAction.equals(intent.getAction())) {
-                if (!mDevice.equals(intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE))) {
-                    return;
-                }
-
-                int state = intent.getIntExtra(BluetoothProfile.EXTRA_STATE, -1);
-                assertNotSame(-1, state);
-                switch (state) {
-                    case BluetoothProfile.STATE_DISCONNECTED:
-                        setFiredFlag(STATE_DISCONNECTED_FLAG);
-                        break;
-                    case BluetoothProfile.STATE_CONNECTING:
-                        setFiredFlag(STATE_CONNECTING_FLAG);
-                        break;
-                    case BluetoothProfile.STATE_CONNECTED:
-                        setFiredFlag(STATE_CONNECTED_FLAG);
-                        break;
-                    case BluetoothProfile.STATE_DISCONNECTING:
-                        setFiredFlag(STATE_DISCONNECTING_FLAG);
-                        break;
-                }
-            }
-        }
-    }
-
-    private class ConnectPanReceiver extends ConnectProfileReceiver {
-        private int mRole;
-
-        public ConnectPanReceiver(BluetoothDevice device, int role, int expectedFlags) {
-            super(device, BluetoothProfile.PAN, expectedFlags);
-
-            mRole = role;
-        }
-
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            if (mRole != intent.getIntExtra(BluetoothPan.EXTRA_LOCAL_ROLE, -1)) {
-                return;
-            }
-
-            super.onReceive(context, intent);
-        }
-    }
-
-    private class StartStopScoReceiver extends FlagReceiver {
-        private static final int STATE_CONNECTED_FLAG = 1;
-        private static final int STATE_DISCONNECTED_FLAG = 1 << 1;
-
-        public StartStopScoReceiver(int expectedFlags) {
-            super(expectedFlags);
-        }
-
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            if (AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED.equals(intent.getAction())) {
-                int state = intent.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_STATE,
-                        AudioManager.SCO_AUDIO_STATE_ERROR);
-                assertNotSame(AudioManager.SCO_AUDIO_STATE_ERROR, state);
-                switch(state) {
-                    case AudioManager.SCO_AUDIO_STATE_CONNECTED:
-                        setFiredFlag(STATE_CONNECTED_FLAG);
-                        break;
-                    case AudioManager.SCO_AUDIO_STATE_DISCONNECTED:
-                        setFiredFlag(STATE_DISCONNECTED_FLAG);
-                        break;
-                }
-            }
-        }
-    }
-
-    private BluetoothProfile.ServiceListener mServiceListener =
-            new BluetoothProfile.ServiceListener() {
-        @Override
-        public void onServiceConnected(int profile, BluetoothProfile proxy) {
-            synchronized (this) {
-                switch (profile) {
-                    case BluetoothProfile.A2DP:
-                        mA2dp = (BluetoothA2dp) proxy;
-                        break;
-                    case BluetoothProfile.HEADSET:
-                        mHeadset = (BluetoothHeadset) proxy;
-                        break;
-                    case BluetoothProfile.INPUT_DEVICE:
-                        mInput = (BluetoothInputDevice) proxy;
-                        break;
-                    case BluetoothProfile.PAN:
-                        mPan = (BluetoothPan) proxy;
-                        break;
-                }
-            }
-        }
-
-        @Override
-        public void onServiceDisconnected(int profile) {
-            synchronized (this) {
-                switch (profile) {
-                    case BluetoothProfile.A2DP:
-                        mA2dp = null;
-                        break;
-                    case BluetoothProfile.HEADSET:
-                        mHeadset = null;
-                        break;
-                    case BluetoothProfile.INPUT_DEVICE:
-                        mInput = null;
-                        break;
-                    case BluetoothProfile.PAN:
-                        mPan = null;
-                        break;
-                }
-            }
-        }
-    };
-
-    private List<BroadcastReceiver> mReceivers = new ArrayList<BroadcastReceiver>();
-
-    private BufferedWriter mOutputWriter;
-    private String mTag;
-    private String mOutputFile;
-
-    private Context mContext;
-    private BluetoothA2dp mA2dp = null;
-    private BluetoothHeadset mHeadset = null;
-    private BluetoothInputDevice mInput = null;
-    private BluetoothPan mPan = null;
-
-    /**
-     * Creates a utility instance for testing Bluetooth.
-     *
-     * @param context The context of the application using the utility.
-     * @param tag The log tag of the application using the utility.
-     */
-    public BluetoothTestUtils(Context context, String tag) {
-        this(context, tag, null);
-    }
-
-    /**
-     * Creates a utility instance for testing Bluetooth.
-     *
-     * @param context The context of the application using the utility.
-     * @param tag The log tag of the application using the utility.
-     * @param outputFile The path to an output file if the utility is to write results to a
-     *        separate file.
-     */
-    public BluetoothTestUtils(Context context, String tag, String outputFile) {
-        mContext = context;
-        mTag = tag;
-        mOutputFile = outputFile;
-
-        if (mOutputFile == null) {
-            mOutputWriter = null;
-        } else {
-            try {
-                mOutputWriter = new BufferedWriter(new FileWriter(new File(
-                        Environment.getExternalStorageDirectory(), mOutputFile), true));
-            } catch (IOException e) {
-                Log.w(mTag, "Test output file could not be opened", e);
-                mOutputWriter = null;
-            }
-        }
-    }
-
-    /**
-     * Closes the utility instance and unregisters any BroadcastReceivers.
-     */
-    public void close() {
-        while (!mReceivers.isEmpty()) {
-            mContext.unregisterReceiver(mReceivers.remove(0));
-        }
-
-        if (mOutputWriter != null) {
-            try {
-                mOutputWriter.close();
-            } catch (IOException e) {
-                Log.w(mTag, "Test output file could not be closed", e);
-            }
-        }
-    }
-
-    /**
-     * Enables Bluetooth and checks to make sure that Bluetooth was turned on and that the correct
-     * actions were broadcast.
-     *
-     * @param adapter The BT adapter.
-     */
-    public void enable(BluetoothAdapter adapter) {
-        int mask = (BluetoothReceiver.STATE_TURNING_ON_FLAG | BluetoothReceiver.STATE_ON_FLAG
-                | BluetoothReceiver.SCAN_MODE_CONNECTABLE_FLAG);
-        long start = -1;
-        BluetoothReceiver receiver = getBluetoothReceiver(mask);
-
-        int state = adapter.getState();
-        switch (state) {
-            case BluetoothAdapter.STATE_ON:
-                assertTrue(adapter.isEnabled());
-                removeReceiver(receiver);
-                return;
-            case BluetoothAdapter.STATE_TURNING_ON:
-                assertFalse(adapter.isEnabled());
-                mask = 0; // Don't check for received intents since we might have missed them.
-                break;
-            case BluetoothAdapter.STATE_OFF:
-                assertFalse(adapter.isEnabled());
-                start = System.currentTimeMillis();
-                assertTrue(adapter.enable());
-                break;
-            case BluetoothAdapter.STATE_TURNING_OFF:
-                start = System.currentTimeMillis();
-                assertTrue(adapter.enable());
-                break;
-            default:
-                removeReceiver(receiver);
-                fail(String.format("enable() invalid state: state=%d", state));
-        }
-
-        long s = System.currentTimeMillis();
-        while (System.currentTimeMillis() - s < ENABLE_DISABLE_TIMEOUT) {
-            state = adapter.getState();
-            if (state == BluetoothAdapter.STATE_ON
-                    && (receiver.getFiredFlags() & mask) == mask) {
-                assertTrue(adapter.isEnabled());
-                long finish = receiver.getCompletedTime();
-                if (start != -1 && finish != -1) {
-                    writeOutput(String.format("enable() completed in %d ms", (finish - start)));
-                } else {
-                    writeOutput("enable() completed");
-                }
-                removeReceiver(receiver);
-                return;
-            }
-            sleep(POLL_TIME);
-        }
-
-        int firedFlags = receiver.getFiredFlags();
-        removeReceiver(receiver);
-        fail(String.format("enable() timeout: state=%d (expected %d), flags=0x%x (expected 0x%x)",
-                state, BluetoothAdapter.STATE_ON, firedFlags, mask));
-    }
-
-    /**
-     * Disables Bluetooth and checks to make sure that Bluetooth was turned off and that the correct
-     * actions were broadcast.
-     *
-     * @param adapter The BT adapter.
-     */
-    public void disable(BluetoothAdapter adapter) {
-        int mask = (BluetoothReceiver.STATE_TURNING_OFF_FLAG | BluetoothReceiver.STATE_OFF_FLAG
-                | BluetoothReceiver.SCAN_MODE_NONE_FLAG);
-        long start = -1;
-        BluetoothReceiver receiver = getBluetoothReceiver(mask);
-
-        int state = adapter.getState();
-        switch (state) {
-            case BluetoothAdapter.STATE_OFF:
-                assertFalse(adapter.isEnabled());
-                removeReceiver(receiver);
-                return;
-            case BluetoothAdapter.STATE_TURNING_ON:
-                assertFalse(adapter.isEnabled());
-                start = System.currentTimeMillis();
-                break;
-            case BluetoothAdapter.STATE_ON:
-                assertTrue(adapter.isEnabled());
-                start = System.currentTimeMillis();
-                assertTrue(adapter.disable());
-                break;
-            case BluetoothAdapter.STATE_TURNING_OFF:
-                assertFalse(adapter.isEnabled());
-                mask = 0; // Don't check for received intents since we might have missed them.
-                break;
-            default:
-                removeReceiver(receiver);
-                fail(String.format("disable() invalid state: state=%d", state));
-        }
-
-        long s = System.currentTimeMillis();
-        while (System.currentTimeMillis() - s < ENABLE_DISABLE_TIMEOUT) {
-            state = adapter.getState();
-            if (state == BluetoothAdapter.STATE_OFF
-                    && (receiver.getFiredFlags() & mask) == mask) {
-                assertFalse(adapter.isEnabled());
-                long finish = receiver.getCompletedTime();
-                if (start != -1 && finish != -1) {
-                    writeOutput(String.format("disable() completed in %d ms", (finish - start)));
-                } else {
-                    writeOutput("disable() completed");
-                }
-                removeReceiver(receiver);
-                return;
-            }
-            sleep(POLL_TIME);
-        }
-
-        int firedFlags = receiver.getFiredFlags();
-        removeReceiver(receiver);
-        fail(String.format("disable() timeout: state=%d (expected %d), flags=0x%x (expected 0x%x)",
-                state, BluetoothAdapter.STATE_OFF, firedFlags, mask));
-    }
-
-    /**
-     * Puts the local device into discoverable mode and checks to make sure that the local device
-     * is in discoverable mode and that the correct actions were broadcast.
-     *
-     * @param adapter The BT adapter.
-     */
-    public void discoverable(BluetoothAdapter adapter) {
-        int mask = BluetoothReceiver.SCAN_MODE_CONNECTABLE_DISCOVERABLE_FLAG;
-
-        if (!adapter.isEnabled()) {
-            fail("discoverable() bluetooth not enabled");
-        }
-
-        int scanMode = adapter.getScanMode();
-        if (scanMode == BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
-            return;
-        }
-
-        BluetoothReceiver receiver = getBluetoothReceiver(mask);
-
-        assertEquals(BluetoothAdapter.SCAN_MODE_CONNECTABLE, scanMode);
-        long start = System.currentTimeMillis();
-        assertTrue(adapter.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE));
-
-        while (System.currentTimeMillis() - start < DISCOVERABLE_UNDISCOVERABLE_TIMEOUT) {
-            scanMode = adapter.getScanMode();
-            if (scanMode == BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE
-                    && (receiver.getFiredFlags() & mask) == mask) {
-                writeOutput(String.format("discoverable() completed in %d ms",
-                        (receiver.getCompletedTime() - start)));
-                removeReceiver(receiver);
-                return;
-            }
-            sleep(POLL_TIME);
-        }
-
-        int firedFlags = receiver.getFiredFlags();
-        removeReceiver(receiver);
-        fail(String.format("discoverable() timeout: scanMode=%d (expected %d), flags=0x%x "
-                + "(expected 0x%x)", scanMode, BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE,
-                firedFlags, mask));
-    }
-
-    /**
-     * Puts the local device into connectable only mode and checks to make sure that the local
-     * device is in in connectable mode and that the correct actions were broadcast.
-     *
-     * @param adapter The BT adapter.
-     */
-    public void undiscoverable(BluetoothAdapter adapter) {
-        int mask = BluetoothReceiver.SCAN_MODE_CONNECTABLE_FLAG;
-
-        if (!adapter.isEnabled()) {
-            fail("undiscoverable() bluetooth not enabled");
-        }
-
-        int scanMode = adapter.getScanMode();
-        if (scanMode == BluetoothAdapter.SCAN_MODE_CONNECTABLE) {
-            return;
-        }
-
-        BluetoothReceiver receiver = getBluetoothReceiver(mask);
-
-        assertEquals(BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE, scanMode);
-        long start = System.currentTimeMillis();
-        assertTrue(adapter.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE));
-
-        while (System.currentTimeMillis() - start < DISCOVERABLE_UNDISCOVERABLE_TIMEOUT) {
-            scanMode = adapter.getScanMode();
-            if (scanMode == BluetoothAdapter.SCAN_MODE_CONNECTABLE
-                    && (receiver.getFiredFlags() & mask) == mask) {
-                writeOutput(String.format("undiscoverable() completed in %d ms",
-                        (receiver.getCompletedTime() - start)));
-                removeReceiver(receiver);
-                return;
-            }
-            sleep(POLL_TIME);
-        }
-
-        int firedFlags = receiver.getFiredFlags();
-        removeReceiver(receiver);
-        fail(String.format("undiscoverable() timeout: scanMode=%d (expected %d), flags=0x%x "
-                + "(expected 0x%x)", scanMode, BluetoothAdapter.SCAN_MODE_CONNECTABLE, firedFlags,
-                mask));
-    }
-
-    /**
-     * Starts a scan for remote devices and checks to make sure that the local device is scanning
-     * and that the correct actions were broadcast.
-     *
-     * @param adapter The BT adapter.
-     */
-    public void startScan(BluetoothAdapter adapter) {
-        int mask = BluetoothReceiver.DISCOVERY_STARTED_FLAG;
-
-        if (!adapter.isEnabled()) {
-            fail("startScan() bluetooth not enabled");
-        }
-
-        if (adapter.isDiscovering()) {
-            return;
-        }
-
-        BluetoothReceiver receiver = getBluetoothReceiver(mask);
-
-        long start = System.currentTimeMillis();
-        assertTrue(adapter.startDiscovery());
-
-        while (System.currentTimeMillis() - start < START_STOP_SCAN_TIMEOUT) {
-            if (adapter.isDiscovering() && ((receiver.getFiredFlags() & mask) == mask)) {
-                writeOutput(String.format("startScan() completed in %d ms",
-                        (receiver.getCompletedTime() - start)));
-                removeReceiver(receiver);
-                return;
-            }
-            sleep(POLL_TIME);
-        }
-
-        int firedFlags = receiver.getFiredFlags();
-        removeReceiver(receiver);
-        fail(String.format("startScan() timeout: isDiscovering=%b, flags=0x%x (expected 0x%x)",
-                adapter.isDiscovering(), firedFlags, mask));
-    }
-
-    /**
-     * Stops a scan for remote devices and checks to make sure that the local device is not scanning
-     * and that the correct actions were broadcast.
-     *
-     * @param adapter The BT adapter.
-     */
-    public void stopScan(BluetoothAdapter adapter) {
-        int mask = BluetoothReceiver.DISCOVERY_FINISHED_FLAG;
-
-        if (!adapter.isEnabled()) {
-            fail("stopScan() bluetooth not enabled");
-        }
-
-        if (!adapter.isDiscovering()) {
-            return;
-        }
-
-        BluetoothReceiver receiver = getBluetoothReceiver(mask);
-
-        long start = System.currentTimeMillis();
-        // TODO: put assertTrue() around cancelDiscovery() once it starts returning true.
-        adapter.cancelDiscovery();
-
-        while (System.currentTimeMillis() - start < START_STOP_SCAN_TIMEOUT) {
-            if (!adapter.isDiscovering() && ((receiver.getFiredFlags() & mask) == mask)) {
-                writeOutput(String.format("stopScan() completed in %d ms",
-                        (receiver.getCompletedTime() - start)));
-                removeReceiver(receiver);
-                return;
-            }
-            sleep(POLL_TIME);
-        }
-
-        int firedFlags = receiver.getFiredFlags();
-        removeReceiver(receiver);
-        fail(String.format("stopScan() timeout: isDiscovering=%b, flags=0x%x (expected 0x%x)",
-                adapter.isDiscovering(), firedFlags, mask));
-
-    }
-
-    /**
-     * Enables PAN tethering on the local device and checks to make sure that tethering is enabled.
-     *
-     * @param adapter The BT adapter.
-     */
-    public void enablePan(BluetoothAdapter adapter) {
-        if (mPan == null) mPan = (BluetoothPan) connectProxy(adapter, BluetoothProfile.PAN);
-        assertNotNull(mPan);
-
-        long start = System.currentTimeMillis();
-        mPan.setBluetoothTethering(true);
-        long stop = System.currentTimeMillis();
-        assertTrue(mPan.isTetheringOn());
-
-        writeOutput(String.format("enablePan() completed in %d ms", (stop - start)));
-    }
-
-    /**
-     * Disables PAN tethering on the local device and checks to make sure that tethering is
-     * disabled.
-     *
-     * @param adapter The BT adapter.
-     */
-    public void disablePan(BluetoothAdapter adapter) {
-        if (mPan == null) mPan = (BluetoothPan) connectProxy(adapter, BluetoothProfile.PAN);
-        assertNotNull(mPan);
-
-        long start = System.currentTimeMillis();
-        mPan.setBluetoothTethering(false);
-        long stop = System.currentTimeMillis();
-        assertFalse(mPan.isTetheringOn());
-
-        writeOutput(String.format("disablePan() completed in %d ms", (stop - start)));
-    }
-
-    /**
-     * Initiates a pairing with a remote device and checks to make sure that the devices are paired
-     * and that the correct actions were broadcast.
-     *
-     * @param adapter The BT adapter.
-     * @param device The remote device.
-     * @param passkey The pairing passkey if pairing requires a passkey. Any value if not.
-     * @param pin The pairing pin if pairing requires a pin. Any value if not.
-     */
-    public void pair(BluetoothAdapter adapter, BluetoothDevice device, int passkey, byte[] pin) {
-        pairOrAcceptPair(adapter, device, passkey, pin, true);
-    }
-
-    /**
-     * Accepts a pairing with a remote device and checks to make sure that the devices are paired
-     * and that the correct actions were broadcast.
-     *
-     * @param adapter The BT adapter.
-     * @param device The remote device.
-     * @param passkey The pairing passkey if pairing requires a passkey. Any value if not.
-     * @param pin The pairing pin if pairing requires a pin. Any value if not.
-     */
-    public void acceptPair(BluetoothAdapter adapter, BluetoothDevice device, int passkey,
-            byte[] pin) {
-        pairOrAcceptPair(adapter, device, passkey, pin, false);
-    }
-
-    /**
-     * Helper method used by {@link #pair(BluetoothAdapter, BluetoothDevice, int, byte[])} and
-     * {@link #acceptPair(BluetoothAdapter, BluetoothDevice, int, byte[])} to either pair or accept
-     * a pairing request.
-     *
-     * @param adapter The BT adapter.
-     * @param device The remote device.
-     * @param passkey The pairing passkey if pairing requires a passkey. Any value if not.
-     * @param pin The pairing pin if pairing requires a pin. Any value if not.
-     * @param shouldPair Whether to pair or accept the pair.
-     */
-    private void pairOrAcceptPair(BluetoothAdapter adapter, BluetoothDevice device, int passkey,
-            byte[] pin, boolean shouldPair) {
-        int mask = PairReceiver.STATE_BONDING_FLAG | PairReceiver.STATE_BONDED_FLAG;
-        long start = -1;
-        String methodName;
-        if (shouldPair) {
-            methodName = String.format("pair(device=%s)", device);
-        } else {
-            methodName = String.format("acceptPair(device=%s)", device);
-        }
-
-        if (!adapter.isEnabled()) {
-            fail(String.format("%s bluetooth not enabled", methodName));
-        }
-
-        PairReceiver receiver = getPairReceiver(device, passkey, pin, mask);
-
-        int state = device.getBondState();
-        switch (state) {
-            case BluetoothDevice.BOND_NONE:
-                assertFalse(adapter.getBondedDevices().contains(device));
-                start = System.currentTimeMillis();
-                if (shouldPair) {
-                    assertTrue(device.createBond());
-                }
-                break;
-            case BluetoothDevice.BOND_BONDING:
-                mask = 0; // Don't check for received intents since we might have missed them.
-                break;
-            case BluetoothDevice.BOND_BONDED:
-                assertTrue(adapter.getBondedDevices().contains(device));
-                return;
-            default:
-                removeReceiver(receiver);
-                fail(String.format("%s invalid state: state=%d", methodName, state));
-        }
-
-        long s = System.currentTimeMillis();
-        while (System.currentTimeMillis() - s < PAIR_UNPAIR_TIMEOUT) {
-            state = device.getBondState();
-            if (state == BluetoothDevice.BOND_BONDED && (receiver.getFiredFlags() & mask) == mask) {
-                assertTrue(adapter.getBondedDevices().contains(device));
-                long finish = receiver.getCompletedTime();
-                if (start != -1 && finish != -1) {
-                    writeOutput(String.format("%s completed in %d ms", methodName,
-                            (finish - start)));
-                } else {
-                    writeOutput(String.format("%s completed", methodName));
-                }
-                removeReceiver(receiver);
-                return;
-            }
-            sleep(POLL_TIME);
-        }
-
-        int firedFlags = receiver.getFiredFlags();
-        removeReceiver(receiver);
-        fail(String.format("%s timeout: state=%d (expected %d), flags=0x%x (expected 0x%x)",
-                methodName, state, BluetoothDevice.BOND_BONDED, firedFlags, mask));
-    }
-
-    /**
-     * Deletes a pairing with a remote device and checks to make sure that the devices are unpaired
-     * and that the correct actions were broadcast.
-     *
-     * @param adapter The BT adapter.
-     * @param device The remote device.
-     */
-    public void unpair(BluetoothAdapter adapter, BluetoothDevice device) {
-        int mask = PairReceiver.STATE_NONE_FLAG;
-        long start = -1;
-        String methodName = String.format("unpair(device=%s)", device);
-
-        if (!adapter.isEnabled()) {
-            fail(String.format("%s bluetooth not enabled", methodName));
-        }
-
-        PairReceiver receiver = getPairReceiver(device, 0, null, mask);
-
-        int state = device.getBondState();
-        switch (state) {
-            case BluetoothDevice.BOND_NONE:
-                assertFalse(adapter.getBondedDevices().contains(device));
-                removeReceiver(receiver);
-                return;
-            case BluetoothDevice.BOND_BONDING:
-                start = System.currentTimeMillis();
-                assertTrue(device.removeBond());
-                break;
-            case BluetoothDevice.BOND_BONDED:
-                assertTrue(adapter.getBondedDevices().contains(device));
-                start = System.currentTimeMillis();
-                assertTrue(device.removeBond());
-                break;
-            default:
-                removeReceiver(receiver);
-                fail(String.format("%s invalid state: state=%d", methodName, state));
-        }
-
-        long s = System.currentTimeMillis();
-        while (System.currentTimeMillis() - s < PAIR_UNPAIR_TIMEOUT) {
-            if (device.getBondState() == BluetoothDevice.BOND_NONE
-                    && (receiver.getFiredFlags() & mask) == mask) {
-                assertFalse(adapter.getBondedDevices().contains(device));
-                long finish = receiver.getCompletedTime();
-                if (start != -1 && finish != -1) {
-                    writeOutput(String.format("%s completed in %d ms", methodName,
-                            (finish - start)));
-                } else {
-                    writeOutput(String.format("%s completed", methodName));
-                }
-                removeReceiver(receiver);
-                return;
-            }
-        }
-
-        int firedFlags = receiver.getFiredFlags();
-        removeReceiver(receiver);
-        fail(String.format("%s timeout: state=%d (expected %d), flags=0x%x (expected 0x%x)",
-                methodName, state, BluetoothDevice.BOND_BONDED, firedFlags, mask));
-    }
-
-    /**
-     * Connects a profile from the local device to a remote device and checks to make sure that the
-     * profile is connected and that the correct actions were broadcast.
-     *
-     * @param adapter The BT adapter.
-     * @param device The remote device.
-     * @param profile The profile to connect. One of {@link BluetoothProfile#A2DP},
-     * {@link BluetoothProfile#HEADSET}, or {@link BluetoothProfile#INPUT_DEVICE}.
-     * @param methodName The method name to printed in the logs.  If null, will be
-     * "connectProfile(profile=&lt;profile&gt;, device=&lt;device&gt;)"
-     */
-    public void connectProfile(BluetoothAdapter adapter, BluetoothDevice device, int profile,
-            String methodName) {
-        if (methodName == null) {
-            methodName = String.format("connectProfile(profile=%d, device=%s)", profile, device);
-        }
-        int mask = (ConnectProfileReceiver.STATE_CONNECTING_FLAG
-                | ConnectProfileReceiver.STATE_CONNECTED_FLAG);
-        long start = -1;
-
-        if (!adapter.isEnabled()) {
-            fail(String.format("%s bluetooth not enabled", methodName));
-        }
-
-        if (!adapter.getBondedDevices().contains(device)) {
-            fail(String.format("%s device not paired", methodName));
-        }
-
-        BluetoothProfile proxy = connectProxy(adapter, profile);
-        assertNotNull(proxy);
-
-        ConnectProfileReceiver receiver = getConnectProfileReceiver(device, profile, mask);
-
-        int state = proxy.getConnectionState(device);
-        switch (state) {
-            case BluetoothProfile.STATE_CONNECTED:
-                removeReceiver(receiver);
-                return;
-            case BluetoothProfile.STATE_CONNECTING:
-                mask = 0; // Don't check for received intents since we might have missed them.
-                break;
-            case BluetoothProfile.STATE_DISCONNECTED:
-            case BluetoothProfile.STATE_DISCONNECTING:
-                start = System.currentTimeMillis();
-                assertTrue(proxy.connect(device));
-                break;
-            default:
-                removeReceiver(receiver);
-                fail(String.format("%s invalid state: state=%d", methodName, state));
-        }
-
-        long s = System.currentTimeMillis();
-        while (System.currentTimeMillis() - s < CONNECT_DISCONNECT_PROFILE_TIMEOUT) {
-            state = proxy.getConnectionState(device);
-            if (state == BluetoothProfile.STATE_CONNECTED
-                    && (receiver.getFiredFlags() & mask) == mask) {
-                long finish = receiver.getCompletedTime();
-                if (start != -1 && finish != -1) {
-                    writeOutput(String.format("%s completed in %d ms", methodName,
-                            (finish - start)));
-                } else {
-                    writeOutput(String.format("%s completed", methodName));
-                }
-                removeReceiver(receiver);
-                return;
-            }
-            sleep(POLL_TIME);
-        }
-
-        int firedFlags = receiver.getFiredFlags();
-        removeReceiver(receiver);
-        fail(String.format("%s timeout: state=%d (expected %d), flags=0x%x (expected 0x%x)",
-                methodName, state, BluetoothProfile.STATE_CONNECTED, firedFlags, mask));
-    }
-
-    /**
-     * Disconnects a profile between the local device and a remote device and checks to make sure
-     * that the profile is disconnected and that the correct actions were broadcast.
-     *
-     * @param adapter The BT adapter.
-     * @param device The remote device.
-     * @param profile The profile to disconnect. One of {@link BluetoothProfile#A2DP},
-     * {@link BluetoothProfile#HEADSET}, or {@link BluetoothProfile#INPUT_DEVICE}.
-     * @param methodName The method name to printed in the logs.  If null, will be
-     * "connectProfile(profile=&lt;profile&gt;, device=&lt;device&gt;)"
-     */
-    public void disconnectProfile(BluetoothAdapter adapter, BluetoothDevice device, int profile,
-            String methodName) {
-        if (methodName == null) {
-            methodName = String.format("disconnectProfile(profile=%d, device=%s)", profile, device);
-        }
-        int mask = (ConnectProfileReceiver.STATE_DISCONNECTING_FLAG
-                | ConnectProfileReceiver.STATE_DISCONNECTED_FLAG);
-        long start = -1;
-
-        if (!adapter.isEnabled()) {
-            fail(String.format("%s bluetooth not enabled", methodName));
-        }
-
-        if (!adapter.getBondedDevices().contains(device)) {
-            fail(String.format("%s device not paired", methodName));
-        }
-
-        BluetoothProfile proxy = connectProxy(adapter, profile);
-        assertNotNull(proxy);
-
-        ConnectProfileReceiver receiver = getConnectProfileReceiver(device, profile, mask);
-
-        int state = proxy.getConnectionState(device);
-        switch (state) {
-            case BluetoothProfile.STATE_CONNECTED:
-            case BluetoothProfile.STATE_CONNECTING:
-                start = System.currentTimeMillis();
-                assertTrue(proxy.disconnect(device));
-                break;
-            case BluetoothProfile.STATE_DISCONNECTED:
-                removeReceiver(receiver);
-                return;
-            case BluetoothProfile.STATE_DISCONNECTING:
-                mask = 0; // Don't check for received intents since we might have missed them.
-                break;
-            default:
-                removeReceiver(receiver);
-                fail(String.format("%s invalid state: state=%d", methodName, state));
-        }
-
-        long s = System.currentTimeMillis();
-        while (System.currentTimeMillis() - s < CONNECT_DISCONNECT_PROFILE_TIMEOUT) {
-            state = proxy.getConnectionState(device);
-            if (state == BluetoothProfile.STATE_DISCONNECTED
-                    && (receiver.getFiredFlags() & mask) == mask) {
-                long finish = receiver.getCompletedTime();
-                if (start != -1 && finish != -1) {
-                    writeOutput(String.format("%s completed in %d ms", methodName,
-                            (finish - start)));
-                } else {
-                    writeOutput(String.format("%s completed", methodName));
-                }
-                removeReceiver(receiver);
-                return;
-            }
-            sleep(POLL_TIME);
-        }
-
-        int firedFlags = receiver.getFiredFlags();
-        removeReceiver(receiver);
-        fail(String.format("%s timeout: state=%d (expected %d), flags=0x%x (expected 0x%x)",
-                methodName, state, BluetoothProfile.STATE_DISCONNECTED, firedFlags, mask));
-    }
-
-    /**
-     * Connects the PANU to a remote NAP and checks to make sure that the PANU is connected and that
-     * the correct actions were broadcast.
-     *
-     * @param adapter The BT adapter.
-     * @param device The remote device.
-     */
-    public void connectPan(BluetoothAdapter adapter, BluetoothDevice device) {
-        connectPanOrIncomingPanConnection(adapter, device, true);
-    }
-
-    /**
-     * Checks that a remote PANU connects to the local NAP correctly and that the correct actions
-     * were broadcast.
-     *
-     * @param adapter The BT adapter.
-     * @param device The remote device.
-     */
-    public void incomingPanConnection(BluetoothAdapter adapter, BluetoothDevice device) {
-        connectPanOrIncomingPanConnection(adapter, device, false);
-    }
-
-    /**
-     * Helper method used by {@link #connectPan(BluetoothAdapter, BluetoothDevice)} and
-     * {@link #incomingPanConnection(BluetoothAdapter, BluetoothDevice)} to either connect to a
-     * remote NAP or verify that a remote device connected to the local NAP.
-     *
-     * @param adapter The BT adapter.
-     * @param device The remote device.
-     * @param connect If the method should initiate the connection (is PANU)
-     */
-    private void connectPanOrIncomingPanConnection(BluetoothAdapter adapter, BluetoothDevice device,
-            boolean connect) {
-        long start = -1;
-        int mask, role;
-        String methodName;
-
-        if (connect) {
-            methodName = String.format("connectPan(device=%s)", device);
-            mask = (ConnectProfileReceiver.STATE_CONNECTED_FLAG |
-                    ConnectProfileReceiver.STATE_CONNECTING_FLAG);
-            role = BluetoothPan.LOCAL_PANU_ROLE;
-        } else {
-            methodName = String.format("incomingPanConnection(device=%s)", device);
-            mask = ConnectProfileReceiver.STATE_CONNECTED_FLAG;
-            role = BluetoothPan.LOCAL_NAP_ROLE;
-        }
-
-        if (!adapter.isEnabled()) {
-            fail(String.format("%s bluetooth not enabled", methodName));
-        }
-
-        if (!adapter.getBondedDevices().contains(device)) {
-            fail(String.format("%s device not paired", methodName));
-        }
-
-        mPan = (BluetoothPan) connectProxy(adapter, BluetoothProfile.PAN);
-        assertNotNull(mPan);
-        ConnectPanReceiver receiver = getConnectPanReceiver(device, role, mask);
-
-        int state = mPan.getConnectionState(device);
-        switch (state) {
-            case BluetoothPan.STATE_CONNECTED:
-                removeReceiver(receiver);
-                return;
-            case BluetoothPan.STATE_CONNECTING:
-                mask = 0; // Don't check for received intents since we might have missed them.
-                break;
-            case BluetoothPan.STATE_DISCONNECTED:
-            case BluetoothPan.STATE_DISCONNECTING:
-                start = System.currentTimeMillis();
-                if (role == BluetoothPan.LOCAL_PANU_ROLE) {
-                    Log.i("BT", "connect to pan");
-                    assertTrue(mPan.connect(device));
-                }
-                break;
-            default:
-                removeReceiver(receiver);
-                fail(String.format("%s invalid state: state=%d", methodName, state));
-        }
-
-        long s = System.currentTimeMillis();
-        while (System.currentTimeMillis() - s < CONNECT_DISCONNECT_PROFILE_TIMEOUT) {
-            state = mPan.getConnectionState(device);
-            if (state == BluetoothPan.STATE_CONNECTED
-                    && (receiver.getFiredFlags() & mask) == mask) {
-                long finish = receiver.getCompletedTime();
-                if (start != -1 && finish != -1) {
-                    writeOutput(String.format("%s completed in %d ms", methodName,
-                            (finish - start)));
-                } else {
-                    writeOutput(String.format("%s completed", methodName));
-                }
-                removeReceiver(receiver);
-                return;
-            }
-            sleep(POLL_TIME);
-        }
-
-        int firedFlags = receiver.getFiredFlags();
-        removeReceiver(receiver);
-        fail(String.format("%s timeout: state=%d (expected %d), flags=0x%x (expected 0x%s)",
-                methodName, state, BluetoothPan.STATE_CONNECTED, firedFlags, mask));
-    }
-
-    /**
-     * Disconnects the PANU from a remote NAP and checks to make sure that the PANU is disconnected
-     * and that the correct actions were broadcast.
-     *
-     * @param adapter The BT adapter.
-     * @param device The remote device.
-     */
-    public void disconnectPan(BluetoothAdapter adapter, BluetoothDevice device) {
-        disconnectFromRemoteOrVerifyConnectNap(adapter, device, true);
-    }
-
-    /**
-     * Checks that a remote PANU disconnects from the local NAP correctly and that the correct
-     * actions were broadcast.
-     *
-     * @param adapter The BT adapter.
-     * @param device The remote device.
-     */
-    public void incomingPanDisconnection(BluetoothAdapter adapter, BluetoothDevice device) {
-        disconnectFromRemoteOrVerifyConnectNap(adapter, device, false);
-    }
-
-    /**
-     * Helper method used by {@link #disconnectPan(BluetoothAdapter, BluetoothDevice)} and
-     * {@link #incomingPanDisconnection(BluetoothAdapter, BluetoothDevice)} to either disconnect
-     * from a remote NAP or verify that a remote device disconnected from the local NAP.
-     *
-     * @param adapter The BT adapter.
-     * @param device The remote device.
-     * @param disconnect Whether the method should connect or verify.
-     */
-    private void disconnectFromRemoteOrVerifyConnectNap(BluetoothAdapter adapter,
-            BluetoothDevice device, boolean disconnect) {
-        long start = -1;
-        int mask, role;
-        String methodName;
-
-        if (disconnect) {
-            methodName = String.format("disconnectPan(device=%s)", device);
-            mask = (ConnectProfileReceiver.STATE_DISCONNECTED_FLAG |
-                    ConnectProfileReceiver.STATE_DISCONNECTING_FLAG);
-            role = BluetoothPan.LOCAL_PANU_ROLE;
-        } else {
-            methodName = String.format("incomingPanDisconnection(device=%s)", device);
-            mask = ConnectProfileReceiver.STATE_DISCONNECTED_FLAG;
-            role = BluetoothPan.LOCAL_NAP_ROLE;
-        }
-
-        if (!adapter.isEnabled()) {
-            fail(String.format("%s bluetooth not enabled", methodName));
-        }
-
-        if (!adapter.getBondedDevices().contains(device)) {
-            fail(String.format("%s device not paired", methodName));
-        }
-
-        mPan = (BluetoothPan) connectProxy(adapter, BluetoothProfile.PAN);
-        assertNotNull(mPan);
-        ConnectPanReceiver receiver = getConnectPanReceiver(device, role, mask);
-
-        int state = mPan.getConnectionState(device);
-        switch (state) {
-            case BluetoothPan.STATE_CONNECTED:
-            case BluetoothPan.STATE_CONNECTING:
-                start = System.currentTimeMillis();
-                if (role == BluetoothPan.LOCAL_PANU_ROLE) {
-                    assertTrue(mPan.disconnect(device));
-                }
-                break;
-            case BluetoothPan.STATE_DISCONNECTED:
-                removeReceiver(receiver);
-                return;
-            case BluetoothPan.STATE_DISCONNECTING:
-                mask = 0; // Don't check for received intents since we might have missed them.
-                break;
-            default:
-                removeReceiver(receiver);
-                fail(String.format("%s invalid state: state=%d", methodName, state));
-        }
-
-        long s = System.currentTimeMillis();
-        while (System.currentTimeMillis() - s < CONNECT_DISCONNECT_PROFILE_TIMEOUT) {
-            state = mPan.getConnectionState(device);
-            if (state == BluetoothInputDevice.STATE_DISCONNECTED
-                    && (receiver.getFiredFlags() & mask) == mask) {
-                long finish = receiver.getCompletedTime();
-                if (start != -1 && finish != -1) {
-                    writeOutput(String.format("%s completed in %d ms", methodName,
-                            (finish - start)));
-                } else {
-                    writeOutput(String.format("%s completed", methodName));
-                }
-                removeReceiver(receiver);
-                return;
-            }
-            sleep(POLL_TIME);
-        }
-
-        int firedFlags = receiver.getFiredFlags();
-        removeReceiver(receiver);
-        fail(String.format("%s timeout: state=%d (expected %d), flags=0x%x (expected 0x%s)",
-                methodName, state, BluetoothInputDevice.STATE_DISCONNECTED, firedFlags, mask));
-    }
-
-    /**
-     * Opens a SCO channel using {@link android.media.AudioManager#startBluetoothSco()} and checks
-     * to make sure that the channel is opened and that the correct actions were broadcast.
-     *
-     * @param adapter The BT adapter.
-     * @param device The remote device.
-     */
-    public void startSco(BluetoothAdapter adapter, BluetoothDevice device) {
-        startStopSco(adapter, device, true);
-    }
-
-    /**
-     * Closes a SCO channel using {@link android.media.AudioManager#stopBluetoothSco()} and checks
-     *  to make sure that the channel is closed and that the correct actions were broadcast.
-     *
-     * @param adapter The BT adapter.
-     * @param device The remote device.
-     */
-    public void stopSco(BluetoothAdapter adapter, BluetoothDevice device) {
-        startStopSco(adapter, device, false);
-    }
-    /**
-     * Helper method for {@link #startSco(BluetoothAdapter, BluetoothDevice)} and
-     * {@link #stopSco(BluetoothAdapter, BluetoothDevice)}.
-     *
-     * @param adapter The BT adapter.
-     * @param device The remote device.
-     * @param isStart Whether the SCO channel should be opened.
-     */
-    private void startStopSco(BluetoothAdapter adapter, BluetoothDevice device, boolean isStart) {
-        long start = -1;
-        int mask;
-        String methodName;
-
-        if (isStart) {
-            methodName = String.format("startSco(device=%s)", device);
-            mask = StartStopScoReceiver.STATE_CONNECTED_FLAG;
-        } else {
-            methodName = String.format("stopSco(device=%s)", device);
-            mask = StartStopScoReceiver.STATE_DISCONNECTED_FLAG;
-        }
-
-        if (!adapter.isEnabled()) {
-            fail(String.format("%s bluetooth not enabled", methodName));
-        }
-
-        if (!adapter.getBondedDevices().contains(device)) {
-            fail(String.format("%s device not paired", methodName));
-        }
-
-        AudioManager manager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
-        assertNotNull(manager);
-
-        if (!manager.isBluetoothScoAvailableOffCall()) {
-            fail(String.format("%s device does not support SCO", methodName));
-        }
-
-        boolean isScoOn = manager.isBluetoothScoOn();
-        if (isStart == isScoOn) {
-            return;
-        }
-
-        StartStopScoReceiver receiver = getStartStopScoReceiver(mask);
-        start = System.currentTimeMillis();
-        if (isStart) {
-            manager.startBluetoothSco();
-        } else {
-            manager.stopBluetoothSco();
-        }
-
-        long s = System.currentTimeMillis();
-        while (System.currentTimeMillis() - s < START_STOP_SCO_TIMEOUT) {
-            isScoOn = manager.isBluetoothScoOn();
-            if (isStart == isScoOn && (receiver.getFiredFlags() & mask) == mask) {
-                long finish = receiver.getCompletedTime();
-                if (start != -1 && finish != -1) {
-                    writeOutput(String.format("%s completed in %d ms", methodName,
-                            (finish - start)));
-                } else {
-                    writeOutput(String.format("%s completed", methodName));
-                }
-                removeReceiver(receiver);
-                return;
-            }
-            sleep(POLL_TIME);
-        }
-
-        int firedFlags = receiver.getFiredFlags();
-        removeReceiver(receiver);
-        fail(String.format("%s timeout: on=%b (expected %b), flags=0x%x (expected 0x%x)",
-                methodName, isScoOn, isStart, firedFlags, mask));
-    }
-
-    /**
-     * Writes a string to the logcat and a file if a file has been specified in the constructor.
-     *
-     * @param s The string to be written.
-     */
-    public void writeOutput(String s) {
-        Log.i(mTag, s);
-        if (mOutputWriter == null) {
-            return;
-        }
-        try {
-            mOutputWriter.write(s + "\n");
-            mOutputWriter.flush();
-        } catch (IOException e) {
-            Log.w(mTag, "Could not write to output file", e);
-        }
-    }
-
-    private void addReceiver(BroadcastReceiver receiver, String[] actions) {
-        IntentFilter filter = new IntentFilter();
-        for (String action: actions) {
-            filter.addAction(action);
-        }
-        mContext.registerReceiver(receiver, filter);
-        mReceivers.add(receiver);
-    }
-
-    private BluetoothReceiver getBluetoothReceiver(int expectedFlags) {
-        String[] actions = {
-                BluetoothAdapter.ACTION_DISCOVERY_FINISHED,
-                BluetoothAdapter.ACTION_DISCOVERY_STARTED,
-                BluetoothAdapter.ACTION_SCAN_MODE_CHANGED,
-                BluetoothAdapter.ACTION_STATE_CHANGED};
-        BluetoothReceiver receiver = new BluetoothReceiver(expectedFlags);
-        addReceiver(receiver, actions);
-        return receiver;
-    }
-
-    private PairReceiver getPairReceiver(BluetoothDevice device, int passkey, byte[] pin,
-            int expectedFlags) {
-        String[] actions = {
-                BluetoothDevice.ACTION_PAIRING_REQUEST,
-                BluetoothDevice.ACTION_BOND_STATE_CHANGED};
-        PairReceiver receiver = new PairReceiver(device, passkey, pin, expectedFlags);
-        addReceiver(receiver, actions);
-        return receiver;
-    }
-
-    private ConnectProfileReceiver getConnectProfileReceiver(BluetoothDevice device, int profile,
-            int expectedFlags) {
-        String[] actions = {
-                BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED,
-                BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED,
-                BluetoothInputDevice.ACTION_CONNECTION_STATE_CHANGED};
-        ConnectProfileReceiver receiver = new ConnectProfileReceiver(device, profile,
-                expectedFlags);
-        addReceiver(receiver, actions);
-        return receiver;
-    }
-
-    private ConnectPanReceiver getConnectPanReceiver(BluetoothDevice device, int role,
-            int expectedFlags) {
-        String[] actions = {BluetoothPan.ACTION_CONNECTION_STATE_CHANGED};
-        ConnectPanReceiver receiver = new ConnectPanReceiver(device, role, expectedFlags);
-        addReceiver(receiver, actions);
-        return receiver;
-    }
-
-    private StartStopScoReceiver getStartStopScoReceiver(int expectedFlags) {
-        String[] actions = {AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED};
-        StartStopScoReceiver receiver = new StartStopScoReceiver(expectedFlags);
-        addReceiver(receiver, actions);
-        return receiver;
-    }
-
-    private void removeReceiver(BroadcastReceiver receiver) {
-        mContext.unregisterReceiver(receiver);
-        mReceivers.remove(receiver);
-    }
-
-    private BluetoothProfile connectProxy(BluetoothAdapter adapter, int profile) {
-        switch (profile) {
-            case BluetoothProfile.A2DP:
-                if (mA2dp != null) {
-                    return mA2dp;
-                }
-                break;
-            case BluetoothProfile.HEADSET:
-                if (mHeadset != null) {
-                    return mHeadset;
-                }
-                break;
-            case BluetoothProfile.INPUT_DEVICE:
-                if (mInput != null) {
-                    return mInput;
-                }
-                break;
-            case BluetoothProfile.PAN:
-                if (mPan != null) {
-                    return mPan;
-                }
-                break;
-            default:
-                return null;
-        }
-        adapter.getProfileProxy(mContext, mServiceListener, profile);
-        long s = System.currentTimeMillis();
-        switch (profile) {
-            case BluetoothProfile.A2DP:
-                while (mA2dp == null && System.currentTimeMillis() - s < CONNECT_PROXY_TIMEOUT) {
-                    sleep(POLL_TIME);
-                }
-                return mA2dp;
-            case BluetoothProfile.HEADSET:
-                while (mHeadset == null && System.currentTimeMillis() - s < CONNECT_PROXY_TIMEOUT) {
-                    sleep(POLL_TIME);
-                }
-                return mHeadset;
-            case BluetoothProfile.INPUT_DEVICE:
-                while (mInput == null && System.currentTimeMillis() - s < CONNECT_PROXY_TIMEOUT) {
-                    sleep(POLL_TIME);
-                }
-                return mInput;
-            case BluetoothProfile.PAN:
-                while (mPan == null && System.currentTimeMillis() - s < CONNECT_PROXY_TIMEOUT) {
-                    sleep(POLL_TIME);
-                }
-                return mPan;
-            default:
-                return null;
-        }
-    }
-
-    private void sleep(long time) {
-        try {
-            Thread.sleep(time);
-        } catch (InterruptedException e) {
-        }
-    }
-}
diff --git a/core/tests/coretests/src/android/net/NetworkStatsHistoryTest.java b/core/tests/coretests/src/android/net/NetworkStatsHistoryTest.java
new file mode 100644
index 0000000..0b72c3c
--- /dev/null
+++ b/core/tests/coretests/src/android/net/NetworkStatsHistoryTest.java
@@ -0,0 +1,311 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net;
+
+import static android.text.format.DateUtils.DAY_IN_MILLIS;
+import static android.text.format.DateUtils.HOUR_IN_MILLIS;
+import static android.text.format.DateUtils.MINUTE_IN_MILLIS;
+import static android.text.format.DateUtils.SECOND_IN_MILLIS;
+import static android.text.format.DateUtils.WEEK_IN_MILLIS;
+import static android.text.format.DateUtils.YEAR_IN_MILLIS;
+
+import android.test.suitebuilder.annotation.SmallTest;
+import android.test.suitebuilder.annotation.Suppress;
+import android.util.Log;
+
+import junit.framework.TestCase;
+
+import java.util.Random;
+
+@SmallTest
+public class NetworkStatsHistoryTest extends TestCase {
+    private static final String TAG = "NetworkStatsHistoryTest";
+
+    private static final long TEST_START = 1194220800000L;
+
+    private NetworkStatsHistory stats;
+
+    @Override
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        if (stats != null) {
+            assertConsistent(stats);
+        }
+    }
+
+    public void testRecordSingleBucket() throws Exception {
+        final long BUCKET_SIZE = HOUR_IN_MILLIS;
+        stats = new NetworkStatsHistory(BUCKET_SIZE);
+
+        // record data into narrow window to get single bucket
+        stats.recordData(TEST_START, TEST_START + SECOND_IN_MILLIS, 1024L, 2048L);
+
+        assertEquals(1, stats.bucketCount);
+        assertBucket(stats, 0, 1024L, 2048L);
+    }
+
+    public void testRecordEqualBuckets() throws Exception {
+        final long bucketDuration = HOUR_IN_MILLIS;
+        stats = new NetworkStatsHistory(bucketDuration);
+
+        // split equally across two buckets
+        final long recordStart = TEST_START + (bucketDuration / 2);
+        stats.recordData(recordStart, recordStart + bucketDuration, 1024L, 128L);
+
+        assertEquals(2, stats.bucketCount);
+        assertBucket(stats, 0, 512L, 64L);
+        assertBucket(stats, 1, 512L, 64L);
+    }
+
+    public void testRecordTouchingBuckets() throws Exception {
+        final long BUCKET_SIZE = 15 * MINUTE_IN_MILLIS;
+        stats = new NetworkStatsHistory(BUCKET_SIZE);
+
+        // split almost completely into middle bucket, but with a few minutes
+        // overlap into neighboring buckets. total record is 20 minutes.
+        final long recordStart = (TEST_START + BUCKET_SIZE) - MINUTE_IN_MILLIS;
+        final long recordEnd = (TEST_START + (BUCKET_SIZE * 2)) + (MINUTE_IN_MILLIS * 4);
+        stats.recordData(recordStart, recordEnd, 1000L, 5000L);
+
+        assertEquals(3, stats.bucketCount);
+        // first bucket should have (1/20 of value)
+        assertBucket(stats, 0, 50L, 250L);
+        // second bucket should have (15/20 of value)
+        assertBucket(stats, 1, 750L, 3750L);
+        // final bucket should have (4/20 of value)
+        assertBucket(stats, 2, 200L, 1000L);
+    }
+
+    public void testRecordGapBuckets() throws Exception {
+        final long BUCKET_SIZE = HOUR_IN_MILLIS;
+        stats = new NetworkStatsHistory(BUCKET_SIZE);
+
+        // record some data today and next week with large gap
+        final long firstStart = TEST_START;
+        final long lastStart = TEST_START + WEEK_IN_MILLIS;
+        stats.recordData(firstStart, firstStart + SECOND_IN_MILLIS, 128L, 256L);
+        stats.recordData(lastStart, lastStart + SECOND_IN_MILLIS, 64L, 512L);
+
+        // we should have two buckets, far apart from each other
+        assertEquals(2, stats.bucketCount);
+        assertBucket(stats, 0, 128L, 256L);
+        assertBucket(stats, 1, 64L, 512L);
+
+        // now record something in middle, spread across two buckets
+        final long middleStart = TEST_START + DAY_IN_MILLIS;
+        final long middleEnd = middleStart + (HOUR_IN_MILLIS * 2);
+        stats.recordData(middleStart, middleEnd, 2048L, 2048L);
+
+        // now should have four buckets, with new record in middle two buckets
+        assertEquals(4, stats.bucketCount);
+        assertBucket(stats, 0, 128L, 256L);
+        assertBucket(stats, 1, 1024L, 1024L);
+        assertBucket(stats, 2, 1024L, 1024L);
+        assertBucket(stats, 3, 64L, 512L);
+    }
+
+    public void testRecordOverlapBuckets() throws Exception {
+        final long BUCKET_SIZE = HOUR_IN_MILLIS;
+        stats = new NetworkStatsHistory(BUCKET_SIZE);
+
+        // record some data in one bucket, and another overlapping buckets
+        stats.recordData(TEST_START, TEST_START + SECOND_IN_MILLIS, 256L, 256L);
+        final long midStart = TEST_START + (HOUR_IN_MILLIS / 2);
+        stats.recordData(midStart, midStart + HOUR_IN_MILLIS, 1024L, 1024L);
+
+        // should have two buckets, with some data mixed together
+        assertEquals(2, stats.bucketCount);
+        assertBucket(stats, 0, 768L, 768L);
+        assertBucket(stats, 1, 512L, 512L);
+    }
+
+    public void testRecordEntireGapIdentical() throws Exception {
+        final long[] total = new long[2];
+
+        // first, create two separate histories far apart
+        final NetworkStatsHistory stats1 = new NetworkStatsHistory(HOUR_IN_MILLIS);
+        stats1.recordData(TEST_START, TEST_START + 2 * HOUR_IN_MILLIS, 2000L, 1000L);
+
+        final long TEST_START_2 = TEST_START + DAY_IN_MILLIS;
+        final NetworkStatsHistory stats2 = new NetworkStatsHistory(HOUR_IN_MILLIS);
+        stats2.recordData(TEST_START_2, TEST_START_2 + 2 * HOUR_IN_MILLIS, 1000L, 500L);
+
+        // combine together with identical bucket size
+        stats = new NetworkStatsHistory(HOUR_IN_MILLIS);
+        stats.recordEntireHistory(stats1);
+        stats.recordEntireHistory(stats2);
+
+        // first verify that totals match up
+        stats.getTotalData(TEST_START - WEEK_IN_MILLIS, TEST_START + WEEK_IN_MILLIS, total);
+        assertTotalEquals(total, 3000L, 1500L);
+
+        // now inspect internal buckets
+        assertBucket(stats, 0, 1000L, 500L);
+        assertBucket(stats, 1, 1000L, 500L);
+        assertBucket(stats, 2, 500L, 250L);
+        assertBucket(stats, 3, 500L, 250L);
+    }
+
+    public void testRecordEntireOverlapVaryingBuckets() throws Exception {
+        final long[] total = new long[2];
+
+        // create history just over hour bucket boundary
+        final NetworkStatsHistory stats1 = new NetworkStatsHistory(HOUR_IN_MILLIS);
+        stats1.recordData(TEST_START, TEST_START + MINUTE_IN_MILLIS * 60, 600L, 600L);
+
+        final long TEST_START_2 = TEST_START + MINUTE_IN_MILLIS;
+        final NetworkStatsHistory stats2 = new NetworkStatsHistory(MINUTE_IN_MILLIS);
+        stats2.recordData(TEST_START_2, TEST_START_2 + MINUTE_IN_MILLIS * 5, 50L, 50L);
+
+        // combine together with minute bucket size
+        stats = new NetworkStatsHistory(MINUTE_IN_MILLIS);
+        stats.recordEntireHistory(stats1);
+        stats.recordEntireHistory(stats2);
+
+        // first verify that totals match up
+        stats.getTotalData(TEST_START - WEEK_IN_MILLIS, TEST_START + WEEK_IN_MILLIS, total);
+        assertTotalEquals(total, 650L, 650L);
+
+        // now inspect internal buckets
+        assertBucket(stats, 0, 10L, 10L);
+        assertBucket(stats, 1, 20L, 20L);
+        assertBucket(stats, 2, 20L, 20L);
+        assertBucket(stats, 3, 20L, 20L);
+        assertBucket(stats, 4, 20L, 20L);
+        assertBucket(stats, 5, 20L, 20L);
+        assertBucket(stats, 6, 10L, 10L);
+
+        // now combine using 15min buckets
+        stats = new NetworkStatsHistory(HOUR_IN_MILLIS / 4);
+        stats.recordEntireHistory(stats1);
+        stats.recordEntireHistory(stats2);
+
+        // first verify that totals match up
+        stats.getTotalData(TEST_START - WEEK_IN_MILLIS, TEST_START + WEEK_IN_MILLIS, total);
+        assertTotalEquals(total, 650L, 650L);
+
+        // and inspect buckets
+        assertBucket(stats, 0, 200L, 200L);
+        assertBucket(stats, 1, 150L, 150L);
+        assertBucket(stats, 2, 150L, 150L);
+        assertBucket(stats, 3, 150L, 150L);
+    }
+
+    public void testRemove() throws Exception {
+        stats = new NetworkStatsHistory(HOUR_IN_MILLIS);
+
+        // record some data across 24 buckets
+        stats.recordData(TEST_START, TEST_START + DAY_IN_MILLIS, 24L, 24L);
+        assertEquals(24, stats.bucketCount);
+
+        // try removing far before buckets; should be no change
+        stats.removeBucketsBefore(TEST_START - YEAR_IN_MILLIS);
+        assertEquals(24, stats.bucketCount);
+
+        // try removing just moments into first bucket; should be no change
+        // since that bucket contains data beyond the cutoff
+        stats.removeBucketsBefore(TEST_START + SECOND_IN_MILLIS);
+        assertEquals(24, stats.bucketCount);
+
+        // try removing single bucket
+        stats.removeBucketsBefore(TEST_START + HOUR_IN_MILLIS);
+        assertEquals(23, stats.bucketCount);
+
+        // try removing multiple buckets
+        stats.removeBucketsBefore(TEST_START + (4 * HOUR_IN_MILLIS));
+        assertEquals(20, stats.bucketCount);
+
+        // try removing all buckets
+        stats.removeBucketsBefore(TEST_START + YEAR_IN_MILLIS);
+        assertEquals(0, stats.bucketCount);
+    }
+
+    public void testTotalData() throws Exception {
+        final long BUCKET_SIZE = HOUR_IN_MILLIS;
+        stats = new NetworkStatsHistory(BUCKET_SIZE);
+
+        // record uniform data across day
+        stats.recordData(TEST_START, TEST_START + DAY_IN_MILLIS, 2400L, 4800L);
+
+        final long[] total = new long[2];
+
+        // verify that total outside range is 0
+        stats.getTotalData(TEST_START - WEEK_IN_MILLIS, TEST_START - DAY_IN_MILLIS, total);
+        assertTotalEquals(total, 0, 0);
+
+        // verify total in first hour
+        stats.getTotalData(TEST_START, TEST_START + HOUR_IN_MILLIS, total);
+        assertTotalEquals(total, 100, 200);
+
+        // verify total across 1.5 hours
+        stats.getTotalData(TEST_START, TEST_START + (long) (1.5 * HOUR_IN_MILLIS), total);
+        assertTotalEquals(total, 150, 300);
+
+        // verify total beyond end
+        stats.getTotalData(TEST_START + (23 * HOUR_IN_MILLIS), TEST_START + WEEK_IN_MILLIS, total);
+        assertTotalEquals(total, 100, 200);
+
+        // verify everything total
+        stats.getTotalData(TEST_START - WEEK_IN_MILLIS, TEST_START + WEEK_IN_MILLIS, total);
+        assertTotalEquals(total, 2400, 4800);
+
+    }
+
+    @Suppress
+    public void testFuzzing() throws Exception {
+        try {
+            // fuzzing with random events, looking for crashes
+            final Random r = new Random();
+            for (int i = 0; i < 500; i++) {
+                stats = new NetworkStatsHistory(r.nextLong());
+                for (int j = 0; j < 10000; j++) {
+                    if (r.nextBoolean()) {
+                        // add range
+                        final long start = r.nextLong();
+                        final long end = start + r.nextInt();
+                        stats.recordData(start, end, r.nextLong(), r.nextLong());
+                    } else {
+                        // trim something
+                        stats.removeBucketsBefore(r.nextLong());
+                    }
+                }
+                assertConsistent(stats);
+            }
+        } catch (Throwable e) {
+            Log.e(TAG, String.valueOf(stats));
+            throw new RuntimeException(e);
+        }
+    }
+
+    private static void assertConsistent(NetworkStatsHistory stats) {
+        // verify timestamps are monotonic
+        for (int i = 1; i < stats.bucketCount; i++) {
+            assertTrue(stats.bucketStart[i - 1] < stats.bucketStart[i]);
+        }
+    }
+
+    private static void assertTotalEquals(long[] total, long rx, long tx) {
+        assertEquals("unexpected rx", rx, total[0]);
+        assertEquals("unexpected tx", tx, total[1]);
+    }
+
+    private static void assertBucket(NetworkStatsHistory stats, int index, long rx, long tx) {
+        assertEquals("unexpected rx", rx, stats.rx[index]);
+        assertEquals("unexpected tx", tx, stats.tx[index]);
+    }
+
+}
diff --git a/core/tests/coretests/src/android/net/NetworkStatsTest.java b/core/tests/coretests/src/android/net/NetworkStatsTest.java
index 45719c2..3cb64c7 100644
--- a/core/tests/coretests/src/android/net/NetworkStatsTest.java
+++ b/core/tests/coretests/src/android/net/NetworkStatsTest.java
@@ -16,7 +16,8 @@
 
 package android.net;
 
-import android.os.SystemClock;
+import static android.net.NetworkStats.TAG_NONE;
+
 import android.test.suitebuilder.annotation.SmallTest;
 
 import junit.framework.TestCase;
@@ -25,30 +26,76 @@
 public class NetworkStatsTest extends TestCase {
 
     private static final String TEST_IFACE = "test0";
+    private static final int TEST_UID = 1001;
+    private static final long TEST_START = 1194220800000L;
 
     public void testFindIndex() throws Exception {
-        final NetworkStats stats = new NetworkStats.Builder(SystemClock.elapsedRealtime(), 3)
-                .addEntry(TEST_IFACE, 100, 1024, 0)
-                .addEntry(TEST_IFACE, 101, 0, 1024)
-                .addEntry(TEST_IFACE, 102, 1024, 1024).build();
+        final NetworkStats stats = new NetworkStats(TEST_START, 3)
+                .addEntry(TEST_IFACE, 100, TAG_NONE, 1024L, 0L)
+                .addEntry(TEST_IFACE, 101, TAG_NONE, 0L, 1024L)
+                .addEntry(TEST_IFACE, 102, TAG_NONE, 1024L, 1024L);
 
-        assertEquals(2, stats.findIndex(TEST_IFACE, 102));
-        assertEquals(2, stats.findIndex(TEST_IFACE, 102));
-        assertEquals(0, stats.findIndex(TEST_IFACE, 100));
-        assertEquals(-1, stats.findIndex(TEST_IFACE, 6));
+        assertEquals(2, stats.findIndex(TEST_IFACE, 102, TAG_NONE));
+        assertEquals(2, stats.findIndex(TEST_IFACE, 102, TAG_NONE));
+        assertEquals(0, stats.findIndex(TEST_IFACE, 100, TAG_NONE));
+        assertEquals(-1, stats.findIndex(TEST_IFACE, 6, TAG_NONE));
+    }
+
+    public void testAddEntryGrow() throws Exception {
+        final NetworkStats stats = new NetworkStats(TEST_START, 2);
+
+        assertEquals(0, stats.size);
+        assertEquals(2, stats.iface.length);
+
+        stats.addEntry(TEST_IFACE, TEST_UID, TAG_NONE, 1L, 2L);
+        stats.addEntry(TEST_IFACE, TEST_UID, TAG_NONE, 2L, 2L);
+
+        assertEquals(2, stats.size);
+        assertEquals(2, stats.iface.length);
+
+        stats.addEntry(TEST_IFACE, TEST_UID, TAG_NONE, 3L, 4L);
+        stats.addEntry(TEST_IFACE, TEST_UID, TAG_NONE, 4L, 4L);
+        stats.addEntry(TEST_IFACE, TEST_UID, TAG_NONE, 5L, 5L);
+
+        assertEquals(5, stats.size);
+        assertTrue(stats.iface.length >= 5);
+
+        assertEquals(1L, stats.rx[0]);
+        assertEquals(2L, stats.rx[1]);
+        assertEquals(3L, stats.rx[2]);
+        assertEquals(4L, stats.rx[3]);
+        assertEquals(5L, stats.rx[4]);
+    }
+
+    public void testCombineExisting() throws Exception {
+        final NetworkStats stats = new NetworkStats(TEST_START, 10);
+
+        stats.addEntry(TEST_IFACE, 1001, TAG_NONE, 512L, 256L);
+        stats.addEntry(TEST_IFACE, 1001, 0xff, 128L, 128L);
+        stats.combineEntry(TEST_IFACE, 1001, TAG_NONE, -128L, -128L);
+
+        assertStatsEntry(stats, 0, TEST_IFACE, 1001, TAG_NONE, 384L, 128L);
+        assertStatsEntry(stats, 1, TEST_IFACE, 1001, 0xff, 128L, 128L);
+
+        // now try combining that should create row
+        stats.combineEntry(TEST_IFACE, 5005, TAG_NONE, 128L, 128L);
+        assertStatsEntry(stats, 2, TEST_IFACE, 5005, TAG_NONE, 128L, 128L);
+        stats.combineEntry(TEST_IFACE, 5005, TAG_NONE, 128L, 128L);
+        assertStatsEntry(stats, 2, TEST_IFACE, 5005, TAG_NONE, 256L, 256L);
     }
 
     public void testSubtractIdenticalData() throws Exception {
-        final NetworkStats before = new NetworkStats.Builder(SystemClock.elapsedRealtime(), 2)
-                .addEntry(TEST_IFACE, 100, 1024, 0)
-                .addEntry(TEST_IFACE, 101, 0, 1024).build();
+        final NetworkStats before = new NetworkStats(TEST_START, 2)
+                .addEntry(TEST_IFACE, 100, TAG_NONE, 1024L, 0L)
+                .addEntry(TEST_IFACE, 101, TAG_NONE, 0L, 1024L);
 
-        final NetworkStats after = new NetworkStats.Builder(SystemClock.elapsedRealtime(), 2)
-                .addEntry(TEST_IFACE, 100, 1024, 0)
-                .addEntry(TEST_IFACE, 101, 0, 1024).build();
+        final NetworkStats after = new NetworkStats(TEST_START, 2)
+                .addEntry(TEST_IFACE, 100, TAG_NONE, 1024L, 0L)
+                .addEntry(TEST_IFACE, 101, TAG_NONE, 0L, 1024L);
 
         final NetworkStats result = after.subtract(before);
 
+        // identical data should result in zero delta
         assertEquals(0, result.rx[0]);
         assertEquals(0, result.tx[0]);
         assertEquals(0, result.rx[1]);
@@ -56,13 +103,13 @@
     }
 
     public void testSubtractIdenticalRows() throws Exception {
-        final NetworkStats before = new NetworkStats.Builder(SystemClock.elapsedRealtime(), 2)
-                .addEntry(TEST_IFACE, 100, 1024, 0)
-                .addEntry(TEST_IFACE, 101, 0, 1024).build();
+        final NetworkStats before = new NetworkStats(TEST_START, 2)
+                .addEntry(TEST_IFACE, 100, TAG_NONE, 1024L, 0L)
+                .addEntry(TEST_IFACE, 101, TAG_NONE, 0L, 1024L);
 
-        final NetworkStats after = new NetworkStats.Builder(SystemClock.elapsedRealtime(), 2)
-                .addEntry(TEST_IFACE, 100, 1025, 2)
-                .addEntry(TEST_IFACE, 101, 3, 1028).build();
+        final NetworkStats after = new NetworkStats(TEST_START, 2)
+                .addEntry(TEST_IFACE, 100, TAG_NONE, 1025L, 2L)
+                .addEntry(TEST_IFACE, 101, TAG_NONE, 3L, 1028L);
 
         final NetworkStats result = after.subtract(before);
 
@@ -74,14 +121,14 @@
     }
 
     public void testSubtractNewRows() throws Exception {
-        final NetworkStats before = new NetworkStats.Builder(SystemClock.elapsedRealtime(), 2)
-                .addEntry(TEST_IFACE, 100, 1024, 0)
-                .addEntry(TEST_IFACE, 101, 0, 1024).build();
+        final NetworkStats before = new NetworkStats(TEST_START, 2)
+                .addEntry(TEST_IFACE, 100, TAG_NONE, 1024L, 0L)
+                .addEntry(TEST_IFACE, 101, TAG_NONE, 0L, 1024L);
 
-        final NetworkStats after = new NetworkStats.Builder(SystemClock.elapsedRealtime(), 3)
-                .addEntry(TEST_IFACE, 100, 1024, 0)
-                .addEntry(TEST_IFACE, 101, 0, 1024)
-                .addEntry(TEST_IFACE, 102, 1024, 1024).build();
+        final NetworkStats after = new NetworkStats(TEST_START, 3)
+                .addEntry(TEST_IFACE, 100, TAG_NONE, 1024L, 0L)
+                .addEntry(TEST_IFACE, 101, TAG_NONE, 0L, 1024L)
+                .addEntry(TEST_IFACE, 102, TAG_NONE, 1024L, 1024L);
 
         final NetworkStats result = after.subtract(before);
 
@@ -94,4 +141,13 @@
         assertEquals(1024, result.tx[2]);
     }
 
+    private static void assertStatsEntry(
+            NetworkStats stats, int i, String iface, int uid, int tag, long rx, long tx) {
+        assertEquals(iface, stats.iface[i]);
+        assertEquals(uid, stats.uid[i]);
+        assertEquals(tag, stats.tag[i]);
+        assertEquals(rx, stats.rx[i]);
+        assertEquals(tx, stats.tx[i]);
+    }
+
 }
diff --git a/core/tests/coretests/src/android/net/http/AbstractProxyTest.java b/core/tests/coretests/src/android/net/http/AbstractProxyTest.java
index ee89414..ee4ce95 100644
--- a/core/tests/coretests/src/android/net/http/AbstractProxyTest.java
+++ b/core/tests/coretests/src/android/net/http/AbstractProxyTest.java
@@ -16,6 +16,10 @@
 
 package android.net.http;
 
+import com.google.mockwebserver.MockResponse;
+import com.google.mockwebserver.MockWebServer;
+import com.google.mockwebserver.RecordedRequest;
+import com.google.mockwebserver.SocketPolicy;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.Reader;
@@ -33,10 +37,6 @@
 import org.apache.http.conn.scheme.Scheme;
 import org.apache.http.conn.ssl.AllowAllHostnameVerifier;
 import org.apache.http.conn.ssl.SSLSocketFactory;
-import tests.http.MockResponse;
-import tests.http.MockWebServer;
-import tests.http.RecordedRequest;
-import tests.http.SocketPolicy;
 
 public abstract class AbstractProxyTest extends TestCase {
 
diff --git a/core/tests/coretests/src/android/net/http/CookiesTest.java b/core/tests/coretests/src/android/net/http/CookiesTest.java
index e736bc9..29e590f 100644
--- a/core/tests/coretests/src/android/net/http/CookiesTest.java
+++ b/core/tests/coretests/src/android/net/http/CookiesTest.java
@@ -16,6 +16,9 @@
 
 package android.net.http;
 
+import com.google.mockwebserver.MockResponse;
+import com.google.mockwebserver.MockWebServer;
+import com.google.mockwebserver.RecordedRequest;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.net.URISyntaxException;
@@ -30,9 +33,6 @@
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.conn.params.ConnRoutePNames;
 import org.apache.http.impl.client.DefaultHttpClient;
-import tests.http.MockResponse;
-import tests.http.MockWebServer;
-import tests.http.RecordedRequest;
 
 public final class CookiesTest extends TestCase {
 
diff --git a/core/tests/coretests/src/android/net/http/DefaultHttpClientTest.java b/core/tests/coretests/src/android/net/http/DefaultHttpClientTest.java
index ad3ec3d..da77298 100644
--- a/core/tests/coretests/src/android/net/http/DefaultHttpClientTest.java
+++ b/core/tests/coretests/src/android/net/http/DefaultHttpClientTest.java
@@ -16,6 +16,12 @@
 
 package android.net.http;
 
+import com.google.mockwebserver.MockResponse;
+import com.google.mockwebserver.MockWebServer;
+import com.google.mockwebserver.SocketPolicy;
+import static com.google.mockwebserver.SocketPolicy.DISCONNECT_AT_END;
+import static com.google.mockwebserver.SocketPolicy.SHUTDOWN_INPUT_AT_END;
+import static com.google.mockwebserver.SocketPolicy.SHUTDOWN_OUTPUT_AT_END;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.Reader;
@@ -24,12 +30,6 @@
 import org.apache.http.HttpResponse;
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.impl.client.DefaultHttpClient;
-import tests.http.MockResponse;
-import tests.http.MockWebServer;
-import tests.http.SocketPolicy;
-import static tests.http.SocketPolicy.DISCONNECT_AT_END;
-import static tests.http.SocketPolicy.SHUTDOWN_INPUT_AT_END;
-import static tests.http.SocketPolicy.SHUTDOWN_OUTPUT_AT_END;
 
 public final class DefaultHttpClientTest extends TestCase {
 
diff --git a/core/tests/coretests/src/android/pim/RecurrenceSetTest.java b/core/tests/coretests/src/android/pim/RecurrenceSetTest.java
index 5d01ba0..e5ab179 100644
--- a/core/tests/coretests/src/android/pim/RecurrenceSetTest.java
+++ b/core/tests/coretests/src/android/pim/RecurrenceSetTest.java
@@ -21,7 +21,7 @@
 import android.pim.RecurrenceSet;
 import android.test.suitebuilder.annotation.SmallTest;
 import android.util.Log;
-import android.provider.Calendar;
+import android.provider.CalendarContract;
 import junit.framework.TestCase;
 
 /**
@@ -69,14 +69,14 @@
         RecurrenceSet.populateContentValues(recurrenceComponent, values);
         Log.d("KS", "values " + values);
 
-        assertEquals(rrule, values.get(android.provider.Calendar.Events.RRULE));
-        assertEquals(rdate, values.get(android.provider.Calendar.Events.RDATE));
-        assertEquals(exrule, values.get(android.provider.Calendar.Events.EXRULE));
-        assertEquals(exdate, values.get(android.provider.Calendar.Events.EXDATE));
-        assertEquals(dtstart, (long) values.getAsLong(Calendar.Events.DTSTART));
-        assertEquals(tzid, values.get(android.provider.Calendar.Events.EVENT_TIMEZONE));
-        assertEquals(duration, values.get(android.provider.Calendar.Events.DURATION));
+        assertEquals(rrule, values.get(android.provider.CalendarContract.Events.RRULE));
+        assertEquals(rdate, values.get(android.provider.CalendarContract.Events.RDATE));
+        assertEquals(exrule, values.get(android.provider.CalendarContract.Events.EXRULE));
+        assertEquals(exdate, values.get(android.provider.CalendarContract.Events.EXDATE));
+        assertEquals(dtstart, (long) values.getAsLong(CalendarContract.Events.DTSTART));
+        assertEquals(tzid, values.get(android.provider.CalendarContract.Events.EVENT_TIMEZONE));
+        assertEquals(duration, values.get(android.provider.CalendarContract.Events.DURATION));
         assertEquals(allDay,
-                (int) values.getAsInteger(android.provider.Calendar.Events.ALL_DAY));
+                (int) values.getAsInteger(android.provider.CalendarContract.Events.ALL_DAY));
     }
 }
diff --git a/core/tests/coretests/src/android/util/LocaleUtilTest.java b/core/tests/coretests/src/android/util/LocaleUtilTest.java
new file mode 100644
index 0000000..203781f
--- /dev/null
+++ b/core/tests/coretests/src/android/util/LocaleUtilTest.java
@@ -0,0 +1,200 @@
+/*
+ * Copyright (C) 2007 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.util;
+
+import java.util.Locale;
+
+import android.test.AndroidTestCase;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetNew;
+
+import static android.util.LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE;
+import static android.util.LocaleUtil.TEXT_LAYOUT_DIRECTION_UNDEFINED_DO_NOT_USE;
+
+public class LocaleUtilTest extends AndroidTestCase {
+
+    @TestTargetNew(
+        level = TestLevel.COMPLETE,
+        method = "getLayoutDirectionFromLocale",
+        args = {Locale.class}
+    )
+    public void testGetLayoutDirectionFromLocale() {
+        assertEquals(TEXT_LAYOUT_DIRECTION_UNDEFINED_DO_NOT_USE,
+                LocaleUtil.getLayoutDirectionFromLocale(null));
+
+        assertEquals(TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(Locale.ENGLISH));
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(Locale.CANADA));
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(Locale.CANADA_FRENCH));
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(Locale.FRANCE));
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(Locale.FRENCH));
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(Locale.GERMAN));
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(Locale.GERMANY));
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(Locale.ITALIAN));
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(Locale.ITALY));
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(Locale.UK));
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(Locale.US));
+
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_UNDEFINED_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(Locale.ROOT));
+
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(Locale.CHINA));
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(Locale.CHINESE));
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(Locale.JAPAN));
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(Locale.JAPANESE));
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(Locale.KOREA));
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(Locale.KOREAN));
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(Locale.PRC));
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(Locale.SIMPLIFIED_CHINESE));
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(Locale.TAIWAN));
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(Locale.TRADITIONAL_CHINESE));
+
+        Locale locale = new Locale("ar");
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(locale));
+        locale = new Locale("ar", "AE");
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(locale));
+        locale = new Locale("ar", "BH");
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(locale));
+        locale = new Locale("ar", "DZ");
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(locale));
+        locale = new Locale("ar", "EG");
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(locale));
+        locale = new Locale("ar", "IQ");
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(locale));
+        locale = new Locale("ar", "JO");
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(locale));
+        locale = new Locale("ar", "KW");
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(locale));
+        locale = new Locale("ar", "LB");
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(locale));
+        locale = new Locale("ar", "LY");
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(locale));
+        locale = new Locale("ar", "MA");
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(locale));
+        locale = new Locale("ar", "OM");
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(locale));
+        locale = new Locale("ar", "QA");
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(locale));
+        locale = new Locale("ar", "SA");
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(locale));
+        locale = new Locale("ar", "SD");
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(locale));
+        locale = new Locale("ar", "SY");
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(locale));
+        locale = new Locale("ar", "TN");
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(locale));
+        locale = new Locale("ar", "YE");
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(locale));
+
+        locale = new Locale("fa");
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(locale));
+        locale = new Locale("fa", "AF");
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(locale));
+        locale = new Locale("fa", "IR");
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(locale));
+
+        locale = new Locale("iw");
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(locale));
+        locale = new Locale("iw", "IL");
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(locale));
+        locale = new Locale("he");
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(locale));
+        locale = new Locale("he", "IL");
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(locale));
+
+        locale = new Locale("pa_Arab");
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(locale));
+        locale = new Locale("pa_Arab", "PK");
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(locale));
+
+        locale = new Locale("ps");
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(locale));
+        locale = new Locale("ps", "AF");
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(locale));
+
+        locale = new Locale("ur");
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(locale));
+        locale = new Locale("ur", "IN");
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(locale));
+        locale = new Locale("ur", "PK");
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(locale));
+
+        locale = new Locale("uz_Arab");
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(locale));
+        locale = new Locale("uz_Arab", "AF");
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(locale));
+
+        // Locale without a real language
+        locale = new Locale("zz");
+        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
+            LocaleUtil.getLayoutDirectionFromLocale(locale));
+    }
+}
diff --git a/core/tests/coretests/src/android/view/GravityTest.java b/core/tests/coretests/src/android/view/GravityTest.java
index 010127f..d8ef650 100644
--- a/core/tests/coretests/src/android/view/GravityTest.java
+++ b/core/tests/coretests/src/android/view/GravityTest.java
@@ -29,14 +29,14 @@
         assertOneGravity(Gravity.RIGHT, Gravity.RIGHT, false);
         assertOneGravity(Gravity.RIGHT, Gravity.RIGHT, true);
 
-        assertOneGravity(Gravity.TOP|Gravity.LEFT, Gravity.TOP, false);
-        assertOneGravity(Gravity.TOP|Gravity.LEFT, Gravity.TOP, true);
+        assertOneGravity(Gravity.TOP, Gravity.TOP, false);
+        assertOneGravity(Gravity.TOP, Gravity.TOP, true);
 
-        assertOneGravity(Gravity.BOTTOM|Gravity.LEFT, Gravity.BOTTOM, false);
-        assertOneGravity(Gravity.BOTTOM|Gravity.LEFT, Gravity.BOTTOM, true);
+        assertOneGravity(Gravity.BOTTOM, Gravity.BOTTOM, false);
+        assertOneGravity(Gravity.BOTTOM, Gravity.BOTTOM, true);
 
-        assertOneGravity(Gravity.CENTER_VERTICAL|Gravity.LEFT, Gravity.CENTER_VERTICAL, false);
-        assertOneGravity(Gravity.CENTER_VERTICAL|Gravity.LEFT, Gravity.CENTER_VERTICAL, true);
+        assertOneGravity(Gravity.CENTER_VERTICAL, Gravity.CENTER_VERTICAL, false);
+        assertOneGravity(Gravity.CENTER_VERTICAL, Gravity.CENTER_VERTICAL, true);
 
         assertOneGravity(Gravity.CENTER_HORIZONTAL, Gravity.CENTER_HORIZONTAL, false);
         assertOneGravity(Gravity.CENTER_HORIZONTAL, Gravity.CENTER_HORIZONTAL, true);
@@ -44,8 +44,8 @@
         assertOneGravity(Gravity.CENTER, Gravity.CENTER, false);
         assertOneGravity(Gravity.CENTER, Gravity.CENTER, true);
 
-        assertOneGravity(Gravity.FILL_VERTICAL|Gravity.LEFT, Gravity.FILL_VERTICAL, false);
-        assertOneGravity(Gravity.FILL_VERTICAL|Gravity.LEFT, Gravity.FILL_VERTICAL, true);
+        assertOneGravity(Gravity.FILL_VERTICAL, Gravity.FILL_VERTICAL, false);
+        assertOneGravity(Gravity.FILL_VERTICAL, Gravity.FILL_VERTICAL, true);
 
         assertOneGravity(Gravity.FILL_HORIZONTAL, Gravity.FILL_HORIZONTAL, false);
         assertOneGravity(Gravity.FILL_HORIZONTAL, Gravity.FILL_HORIZONTAL, true);
@@ -53,20 +53,22 @@
         assertOneGravity(Gravity.FILL, Gravity.FILL, false);
         assertOneGravity(Gravity.FILL, Gravity.FILL, true);
 
-        assertOneGravity(Gravity.CLIP_HORIZONTAL|Gravity.LEFT, Gravity.CLIP_HORIZONTAL, false);
-        assertOneGravity(Gravity.CLIP_HORIZONTAL|Gravity.LEFT, Gravity.CLIP_HORIZONTAL, true);
+        assertOneGravity(Gravity.CLIP_HORIZONTAL, Gravity.CLIP_HORIZONTAL, false);
+        assertOneGravity(Gravity.CLIP_HORIZONTAL, Gravity.CLIP_HORIZONTAL, true);
 
-        assertOneGravity(Gravity.CLIP_VERTICAL|Gravity.LEFT, Gravity.CLIP_VERTICAL, false);
-        assertOneGravity(Gravity.CLIP_VERTICAL|Gravity.LEFT, Gravity.CLIP_VERTICAL, true);
+        assertOneGravity(Gravity.CLIP_VERTICAL, Gravity.CLIP_VERTICAL, false);
+        assertOneGravity(Gravity.CLIP_VERTICAL, Gravity.CLIP_VERTICAL, true);
 
-        assertOneGravity(Gravity.LEFT, Gravity.BEFORE, false);
-        assertOneGravity(Gravity.RIGHT, Gravity.BEFORE, true);
+        assertOneGravity(Gravity.LEFT, Gravity.START, false);
+        assertOneGravity(Gravity.RIGHT, Gravity.START, true);
 
-        assertOneGravity(Gravity.RIGHT, Gravity.AFTER, false);
-        assertOneGravity(Gravity.LEFT, Gravity.AFTER, true);
+        assertOneGravity(Gravity.RIGHT, Gravity.END, false);
+        assertOneGravity(Gravity.LEFT, Gravity.END, true);
     }
 
     private void assertOneGravity(int expected, int initial, boolean isRtl) {
-        assertEquals(expected, Gravity.getAbsoluteGravity(initial, isRtl));
+        final int layoutDirection = isRtl ? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR;
+
+        assertEquals(expected, Gravity.getAbsoluteGravity(initial, layoutDirection));
     }
 }
diff --git a/core/tests/coretests/src/com/android/internal/util/HanziToPinyinTest.java b/core/tests/coretests/src/com/android/internal/util/HanziToPinyinTest.java
deleted file mode 100644
index 36dee70..0000000
--- a/core/tests/coretests/src/com/android/internal/util/HanziToPinyinTest.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.internal.util;
-
-import java.text.Collator;
-import java.util.Arrays;
-import java.util.ArrayList;
-import java.util.Locale;
-
-import android.test.suitebuilder.annotation.SmallTest;
-import android.util.Log;
-
-import com.android.internal.util.HanziToPinyin;
-import com.android.internal.util.HanziToPinyin.Token;
-
-import junit.framework.TestCase;
-
-public class HanziToPinyinTest extends TestCase {
-    private final static String ONE_HANZI = "\u675C";
-    private final static String TWO_HANZI = "\u675C\u9D51";
-    private final static String ASSIC = "test";
-    private final static String ONE_UNKNOWN = "\uFF71";
-    private final static String MISC = "test\u675C   Test with space\uFF71\uFF71\u675C";
-
-    @SmallTest
-    public void testGetToken() throws Exception {
-        if (!Arrays.asList(Collator.getAvailableLocales()).contains(Locale.CHINA)) {
-            return;
-        }
-        ArrayList<Token> tokens = HanziToPinyin.getInstance().get(ONE_HANZI);
-        assertEquals(tokens.size(), 1);
-        assertEquals(tokens.get(0).type, Token.PINYIN);
-        assertTrue(tokens.get(0).target.equalsIgnoreCase("DU"));
-
-        tokens = HanziToPinyin.getInstance().get(TWO_HANZI);
-        assertEquals(tokens.size(), 2);
-        assertEquals(tokens.get(0).type, Token.PINYIN);
-        assertEquals(tokens.get(1).type, Token.PINYIN);
-        assertTrue(tokens.get(0).target.equalsIgnoreCase("DU"));
-        assertTrue(tokens.get(1).target.equalsIgnoreCase("JUAN"));
-
-        tokens = HanziToPinyin.getInstance().get(ASSIC);
-        assertEquals(tokens.size(), 1);
-        assertEquals(tokens.get(0).type, Token.LATIN);
-
-        tokens = HanziToPinyin.getInstance().get(ONE_UNKNOWN);
-        assertEquals(tokens.size(), 1);
-        assertEquals(tokens.get(0).type, Token.UNKNOWN);
-
-        tokens = HanziToPinyin.getInstance().get(MISC);
-        assertEquals(tokens.size(), 7);
-        assertEquals(tokens.get(0).type, Token.LATIN);
-        assertEquals(tokens.get(1).type, Token.PINYIN);
-        assertEquals(tokens.get(2).type, Token.LATIN);
-        assertEquals(tokens.get(3).type, Token.LATIN);
-        assertEquals(tokens.get(4).type, Token.LATIN);
-        assertEquals(tokens.get(5).type, Token.UNKNOWN);
-        assertEquals(tokens.get(6).type, Token.PINYIN);
-    }
-}
diff --git a/data/etc/android.hardware.faketouch.multitouch.distinct.xml b/data/etc/android.hardware.faketouch.multitouch.distinct.xml
new file mode 100644
index 0000000..b6e8d09
--- /dev/null
+++ b/data/etc/android.hardware.faketouch.multitouch.distinct.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+  
+          http://www.apache.org/licenses/LICENSE-2.0
+  
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<!-- This is the standard set of features for a indirect touch input device that supports
+     independently-trackable multiple-finger multitouch. -->
+<permissions>
+    <feature name="android.hardware.faketouch.multitouch" />
+    <feature name="android.hardware.faketouch.multitouch.distinct" />
+    <feature name="android.hardware.faketouch" />
+</permissions>
diff --git a/data/etc/android.hardware.faketouch.multitouch.jazzhand.xml b/data/etc/android.hardware.faketouch.multitouch.jazzhand.xml
new file mode 100644
index 0000000..7f0e70b
--- /dev/null
+++ b/data/etc/android.hardware.faketouch.multitouch.jazzhand.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<!-- This is the standard set of features for an indirect touch input device that supports
+     independently-trackable multiple-finger multitouch. -->
+<permissions>
+    <feature name="android.hardware.faketouch.multitouch" />
+    <feature name="android.hardware.faketouch.multitouch.distinct" />
+    <feature name="android.hardware.faketouch.multitouch.jazzhand" />
+    <feature name="android.hardware.faketouch" />
+</permissions>
diff --git a/data/etc/android.hardware.faketouch.xml b/data/etc/android.hardware.faketouch.xml
new file mode 100644
index 0000000..cb99097
--- /dev/null
+++ b/data/etc/android.hardware.faketouch.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+  
+          http://www.apache.org/licenses/LICENSE-2.0
+  
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<!-- This is the standard set of features for a devices that does not have
+     a touch screen, but does have some other indirect input device such as
+     a track pad. -->
+<permissions>
+    <feature name="android.hardware.faketouch" />
+</permissions>
diff --git a/data/etc/handheld_core_hardware.xml b/data/etc/handheld_core_hardware.xml
index 7f87b79..9d2a0cb 100644
--- a/data/etc/handheld_core_hardware.xml
+++ b/data/etc/handheld_core_hardware.xml
@@ -31,6 +31,8 @@
     <feature name="android.hardware.bluetooth" />
     <feature name="android.hardware.touchscreen" />
     <feature name="android.hardware.microphone" />
+    <feature name="android.hardware.screen.portrait" />
+    <feature name="android.hardware.screen.landscape" />
     <!-- devices with GPS must include android.hardware.location.gps.xml -->
     <!-- devices with an autofocus camera and/or flash must include either
          android.hardware.camera.autofocus.xml or 
diff --git a/data/etc/platform.xml b/data/etc/platform.xml
index 5ed7966..b9c0d80 100644
--- a/data/etc/platform.xml
+++ b/data/etc/platform.xml
@@ -132,6 +132,7 @@
     <assign-permission name="android.permission.BATTERY_STATS" uid="shell" />
     <assign-permission name="android.permission.INTERNAL_SYSTEM_WINDOW" uid="shell" />
     <assign-permission name="android.permission.INJECT_EVENTS" uid="shell" />
+    <assign-permission name="android.permission.RETRIEVE_WINDOW_CONTENT" uid="shell" />
     <assign-permission name="android.permission.SET_ACTIVITY_WATCHER" uid="shell" />
     <assign-permission name="android.permission.READ_INPUT_STATE" uid="shell" />
     <assign-permission name="android.permission.SET_ORIENTATION" uid="shell" />
diff --git a/data/etc/tablet_core_hardware.xml b/data/etc/tablet_core_hardware.xml
index 952d0782..bf29fe4 100644
--- a/data/etc/tablet_core_hardware.xml
+++ b/data/etc/tablet_core_hardware.xml
@@ -32,6 +32,8 @@
     <feature name="android.hardware.touchscreen.multitouch" />
     <feature name="android.hardware.touchscreen.multitouch.distinct" />
     <feature name="android.hardware.microphone" />
+    <feature name="android.hardware.screen.portrait" />
+    <feature name="android.hardware.screen.landscape" />
     <!-- devices with GPS must include android.hardware.location.gps.xml -->
     <!-- devices with a rear-facing camera must include one of these as appropriate:
          android.hardware.camera.xml or 
diff --git a/data/fonts/DroidSansFallback.ttf b/data/fonts/DroidSansFallback.ttf
index ba9d76f..03ceae5 100644
--- a/data/fonts/DroidSansFallback.ttf
+++ b/data/fonts/DroidSansFallback.ttf
Binary files differ
diff --git a/data/sounds/AllAudio.mk b/data/sounds/AllAudio.mk
index 4e7a403..2e18a10 100644
--- a/data/sounds/AllAudio.mk
+++ b/data/sounds/AllAudio.mk
@@ -18,3 +18,5 @@
 $(call inherit-product, frameworks/base/data/sounds/AudioPackage2.mk)
 $(call inherit-product, frameworks/base/data/sounds/AudioPackage3.mk)
 $(call inherit-product, frameworks/base/data/sounds/AudioPackage4.mk)
+$(call inherit-product, frameworks/base/data/sounds/AudioPackage5.mk)
+$(call inherit-product, frameworks/base/data/sounds/AudioPackage6.mk)
diff --git a/docs/html/guide/developing/debugging/debugging-ui.jd b/docs/html/guide/developing/debugging/debugging-ui.jd
index d2c42d5..22748be 100644
--- a/docs/html/guide/developing/debugging/debugging-ui.jd
+++ b/docs/html/guide/developing/debugging/debugging-ui.jd
@@ -31,10 +31,29 @@
         </li>
         <li><a href="#layoutopt">Optimizing Layouts with <code>layoutopt</code></a></li>
       </ol>
+      <h2>Related videos</h2>
+          <ol>
+              <li>
+<iframe title="Hierarchyviewer" 
+    width="272" height="234" 
+    src="http://www.youtube.com/embed/PAgE7saQUUY?rel=0&amp;hd=1" 
+    frameborder="0" allowfullscreen>
+</iframe>
+              </li>
+              <li>
+<iframe title="Pixel Perfect" 
+    width="272" height="234" 
+    src="http://www.youtube.com/embed/C45bMZGdN7Y?rel=0&amp;hd=1" 
+    frameborder="0" 
+    allowfullscreen>
+</iframe>
+              </li>
+          </ol>
     </div>
   </div>
 
-  <p>Sometimes your application's layout can slow down your application.
+  <p>
+Sometimes your application's layout can slow down your application.
   To help debug issues in your layout, the Android SDK provides the Hierarchy Viewer and
   <code>layoutopt</code> tools.
   </p>
diff --git a/docs/html/guide/developing/tools/adb.jd b/docs/html/guide/developing/tools/adb.jd
index e891ccd..a109dc8 100644
--- a/docs/html/guide/developing/tools/adb.jd
+++ b/docs/html/guide/developing/tools/adb.jd
@@ -35,45 +35,9 @@
 </div>
 </div>
 
-<!-- 
-<p>Android Debug Bridge (adb) is a versatile tool that </a>. </p>
-
-<p>Some of ways you can use adb include:</p>
-
-<ul>
-
-</ul>
-<p>The sections below introduce adb and describe many of its common uses. </p>
-
-<h2>Contents</h2>
-<dl>
-<dt><a href="#overview">Overview</a></dt>
-<dt><a href="#issuingcommands">Issuing adb Commands</a></dt>
-<dt><a href="#devicestatus">Querying for Emulator/Device Instances</a></dt>
-<dt><a href="#directingcommands">Directing Commands to a Specific Emulator/Device Instance</a></dt>
-<dt><a href="#move">Installing an Application</a></dt>
-<dt><a href="#forwardports">Forwarding Ports</a></dt>
-<dt><a href="#copyfiles">Copying Files to or from an Emulator/Device Instance</a></dt>
-<dt><a href="#commandsummary">Listing of adb Commands </a></dt>
-<dt><a href="#shellcommands">Issuing Shell Commands</a></dt>
-    <dd><a href="#sqlite">Examining sqlite3 Databases from a Remote Shell</a></dd>
-    <dd><a href="#monkey">UI/Application Exerciser Monkey</a></dd>
-	<dd><a href="#othershellcommands">Other Shell Commands</a></dd>
-<dt><a href="#logcat">Enabling logcat Logging</a> </dt>
-	<dd><a href="#usinglogcat">Using logcat Commands</a></dd>
-	<dd><a href="#filteringoutput">Filtering Log Output</a></dd>
-	<dd><a href="#outputformat">Controlling Log Output Format</a></dd>
-	<dd><a href="#alternativebuffers">Viewing Alternative Log Buffers</a></dd>
-	<dd><a href="#stdout">Viewing stdout and stderr</a></dd>
-	<dd><a href="#logcatoptions">Listing of logcat Command Options</a></dd>
-<dt><a href="#stopping">Stopping the adb Server</a> </dt>
-</dl>
-
-<a name="overview"></a>
-
-<h2>Overview</h2>
--->
-<p>Android Debug Bridge (adb) is a versatile tool lets you manage the state of an emulator instance or Android-powered device. It is a client-server program that includes three components: </p>
+<p>Android Debug Bridge (adb) is a versatile command line tool that lets you communicate with an
+emulator instance or connected Android-powered device. It is a client-server program that includes
+three components: </p>
 
 <ul>
   <li>A client, which runs on your development machine. You can invoke a client from a shell by issuing an adb command. Other Android tools such as the ADT plugin and DDMS also create adb clients. </li>
diff --git a/docs/html/guide/guide_toc.cs b/docs/html/guide/guide_toc.cs
index 916da09..55d711f 100644
--- a/docs/html/guide/guide_toc.cs
+++ b/docs/html/guide/guide_toc.cs
@@ -244,9 +244,6 @@
           <li><a href="<?cs var:toroot ?>guide/topics/graphics/opengl.html">
                 <span class="en">3D with OpenGL</span>
               </a></li>
-          <li><a href="<?cs var:toroot ?>guide/topics/graphics/renderscript.html">
-                <span class="en">3D with Renderscript</span>
-              </a></li>
           <li><a href="<?cs var:toroot ?>guide/topics/graphics/animation.html">
                 <span class="en">Property Animation</span>
               </a></li>
@@ -255,6 +252,23 @@
               </a></li>
         </ul>
       </li>
+      <li class="toggle-list">
+	        <div><a href="<?cs var:toroot ?>guide/topics/renderscript/index.html">
+	            <span class="en">RenderScript</span>
+	          </a>
+	          <span class="new-child">new!</span></div>
+	        <ul>
+	          <li><a href="<?cs var:toroot ?>guide/topics/renderscript/graphics.html">
+	                <span class="en">3D Graphics</span>
+	              </a>
+	          </li>
+	          <li><a href="<?cs var:toroot ?>guide/topics/renderscript/compute.html">
+	                <span class="en">Compute</span>
+	              </a>
+	          </li>         
+	        </ul>
+  	  </li>
+
       <li><a href="<?cs var:toroot ?>guide/topics/media/index.html">
             <span class="en">Audio and Video</span>
           </a></li>
diff --git a/docs/html/guide/practices/optimizing-for-3.0.jd b/docs/html/guide/practices/optimizing-for-3.0.jd
index 5cd519b..e968372 100644
--- a/docs/html/guide/practices/optimizing-for-3.0.jd
+++ b/docs/html/guide/practices/optimizing-for-3.0.jd
@@ -22,6 +22,14 @@
 </li>
 </ol>
 
+<h2>See also</h2>
+
+<ol>
+  <li><a
+href="{@docRoot}sdk/compatibility-library.html">Compatibility Library</a></li>
+  <li><a href="http://code.google.com/p/iosched/">Google I/O App source code</a></li>
+</ol>
+
 </div>
 </div>
 
@@ -172,7 +180,8 @@
 application will look and feel consistent with the system and other applications when it is
 enabled.</p>
     <p>Additionally, when an activity uses the holographic theme, the system enables the <a
-href="{@docRoot}guide/topics/ui/actionbar.html">Action Bar</a> for the activity. The Action Bar
+href="{@docRoot}guide/topics/ui/actionbar.html">Action Bar</a> for the activity and removes the
+Options Menu button in the system bar. The Action Bar
 replaces the traditional title bar at the top of the activity window and provides the user access to
 the activity's Options Menu.</p>
       </li>
@@ -233,27 +242,26 @@
 
 
 
-
-
 <h2 id="Upgrading">Upgrading or Developing a New App for Tablets</h2>
 
 <div class="sidebox-wrapper">
 <div class="sidebox">
-  <h3>Use new APIs and remain backward-compatible</h3>
+  <h3>Use the Compatibility Library to remain backward-compatible</h3>
 <p>It is possible for you to upgrade your application with some new
 APIs <em>and</em> remain compatible with older versions of Android. Usually, this requires that you
 use techniques such as reflection to check for the availability of certain APIs at runtime. However,
 to help you add features from Android 3.0 without requiring you to change your <a
 href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#min">{@code android:minSdkVersion}</a>
-or build target, we're providing a static library called the "Android Compatibility package"
+or build target, we're providing a static library called the <a
+href="{@docRoot}sdk/compatibility-library.html">Compatibility Library</a>
 (downloadable from the AVD and SDK Manager).</p>
 <p>This library includes APIs for <a
 href="{@docRoot}guide/topics/fundamentals/fragments.html">fragments</a>, <a
 href="{@docRoot}guide/topics/fundamentals/loaders.html">loaders</a>, and some updated classes. By
 simply adding this library to your Android project, you can use these APIs in your application and
-remain compatible with Android 1.6. For more information, see the blog post, <a
-href="http://android-developers.blogspot.com/2011/03/fragments-for-all.html">Fragments for
-All</a>.</p>
+remain compatible with Android 1.6. For information about how to get the library and start
+using it in your application, see the <a
+href="{@docRoot}sdk/compatibility-library.html">Compatibility Library</a> document.</p>
 </div>
 </div>
 
@@ -380,7 +388,6 @@
 href="{@docRoot}sdk/android-3.0.html">Android 3.0 Platform</a> document.</p>
 
 
-
 <h3>Look at some samples</h3>
 
 <p>Many of the new features and APIs that are described above and in the <a
diff --git a/docs/html/guide/topics/fundamentals/services.jd b/docs/html/guide/topics/fundamentals/services.jd
index a9dd315..468a417 100644
--- a/docs/html/guide/topics/fundamentals/services.jd
+++ b/docs/html/guide/topics/fundamentals/services.jd
@@ -49,6 +49,13 @@
       LocalService}</a></li>
 </ol>
 
+<h2>Articles</h2>
+<ol>
+  <li><a href="{@docRoot}resources/articles/multitasking-android-way.html">Multitasking the Android Way</a></li>
+  <li><a href="{@docRoot}resources/articles/service-api-changes-starting-with.html">Service API changes starting
+      with Android 2.0</a></li>
+</ol>
+
 <h2>See also</h2>
 <ol>
 <li><a href="{@docRoot}guide/topics/fundamentals/bound-services.html">Bound Services</a></li>
diff --git a/docs/html/guide/topics/fundamentals/tasks-and-back-stack.jd b/docs/html/guide/topics/fundamentals/tasks-and-back-stack.jd
index f22e5b2..072488c 100644
--- a/docs/html/guide/topics/fundamentals/tasks-and-back-stack.jd
+++ b/docs/html/guide/topics/fundamentals/tasks-and-back-stack.jd
@@ -27,6 +27,11 @@
 </li>
 </ol>
 
+<h2>Articles</h2>
+<ol>
+  <li><a href="{@docRoot}resources/articles/multitasking-android-way.html">Multitasking the Android Way</a></li>
+</ol>
+
 <h2>See also</h2>
 <ol>
   <li><a><a href="{@docRoot}videos/index.html#v=fL6gSd4ugSI">Application Lifecycle video</a></li>
diff --git a/docs/html/guide/topics/graphics/animation.jd b/docs/html/guide/topics/graphics/animation.jd
index e10ab3e..31e7c4b 100644
--- a/docs/html/guide/topics/graphics/animation.jd
+++ b/docs/html/guide/topics/graphics/animation.jd
@@ -81,6 +81,12 @@
   If view animation accomplishes everything that you need to do, or if your existing code already
   works the way you want, there is no need to use the property animation system.</p>
   
+    <p class="note"><strong>Tip:</strong> To see how the ADT layout editor allows you to develop and
+preview animations in your layout, watch the <a
+href="http://www.youtube.com/watch?v=Oq05KqjXTvs&feature=player_detailpage#t=1709s">Android
+Developer Tools session</a> from Google I/O '11</p>
+
+
   <h2 id="what">What is Property Animation?</h2>
   A property animation changes a property's (a field in
   an object) value over a specified length of time. To animate something, you specify the
@@ -108,6 +114,7 @@
     default is set to  refresh every 10 ms, but the speed in which your application can refresh frames is
     ultimately dependent on how busy the system is overall and how fast the system can service the underlying timer.</li>
   </ul>
+  
 
   <h3 id="how">How the property animation system works</h3>
 
@@ -868,10 +875,22 @@
 For more information on creating animators, see the sections on animating with
 <a href="#value-animator">ValueAnimator</a> and <a href="#object-animator">ObjectAnimator</a>
 
-  <h2 id="declaring-xml">Declaring Animations in XML</h2>
+
+<h2 id="declaring-xml">Declaring Animations in XML</h2>
 
   <p>The property animation system lets you declare property animations with XML instead of doing
-  it programmatically. The following Android classes have XML declaration support with the
+  it programmatically. By defining your animations in XML, you can easily reuse your animations
+in multiple activities and more easily edit the animation sequence.</p>
+  
+<p>To distinguish animation files that use the new property animation APIs from those that use the
+legacy <a href="{@docRoot}guide/topics/graphics/view-animation.html">view animation</a> framework,
+starting with Android 3.1, you should save the XML files for property animations in the {@code
+res/animator/} directory (instead of {@code res/anim/}). Using the {@code animator} directory name
+is optional, but necessary if you want to use the layout editor tools in the Eclipse ADT plugin (ADT
+11.0.0+), because ADT only searches the {@code res/animator/} directory for property animation
+resources.</p>
+
+<p>The following property animation classes have XML declaration support with the
   following XML tags:</p>
 
   <ul>
@@ -882,91 +901,5 @@
     <li>{@link android.animation.AnimatorSet} - <code>&lt;set&gt;</code></li>
   </ul>
 
-  <p>Both <code>&lt;animator&gt;</code> ({@link android.animation.ValueAnimator}) and
-  <code>&lt;objectAnimator&gt;</code> ({@link android.animation.ObjectAnimator}) have the following
-  attributes:</p>
+<p>See <a href="{@docRoot}guide/topics/resources/animation-resource.html#Property">Animation Resources</a>
 
-  <dl>
-    <dt><code>android:duration</code></dt>
-
-    <dd>The number of milliseconds that the animation runs. The default is 300 ms.</dd>
-
-    <dt><code>android:valueFrom</code> and <code>android:valueTo</code></dt>
-
-    <dd>The values being animated between. These are restricted to numbers (<code>float</code> or
-    <code>int</code>) and color values (such as #00ff00). They can be <code>float</code>, <code>int</code>, colors, 
-    or any kind of <code>Object</code> when creating animations programmatically.</dd>
-
-    <dt><code>android:valueType</code></dt>
-
-    <dd>Set to either <code>"floatType"</code> or <code>"intType"</code>. The default is 
-    <code>"floatType"</code> unless you specify something else or if the <code>valuesFrom</code>
-    and <code>valuesTo</code> values are colors.</dd>
-
-    <dt><code>android:startOffset</code></dt>
-
-    <dd>The delay, in milliseconds, before the animation begins playing (after calling {@link
-    android.animation.ValueAnimator#start start()}).</dd>
-
-    <dt><code>android:repeatCount</code></dt>
-
-    <dd>How many times to repeat an animation. Set to <code>"-1"</code> to infinitely repeat or
-    to a positive integer. For example, a value of <code>"1"</code> means that the animation is
-    repeated once after the initial run of the animation, so the animation plays a total of two
-    times. The default value is <code>"0"</code>, which means no repetition.</dd>
-
-    <dt><code>android:repeatMode</code></dt>
-
-    <dd>How an animation behaves when it reaches the end of the animation.
-    <code>android:repeatCount</code> must be set to a positive integer or <code>"-1"</code> for
-    this attribute to have an effect. Set to <code>"reverse"</code> to have the animation reverse
-    direction with each iteration or <code>"repeat"</code> to have the animation loop from the
-    beginning each time.</dd>
-  </dl>
-
-  <p>The <code>objectAnimator</code> ({@link android.animation.ObjectAnimator}) element has the
-  additional attribute <code>propertyName</code>, that lets you specify the name of the property
-  being animated. The <code>objectAnimator</code> element does not expose a <code>target</code>
-  attribute, however, so you cannot set the object to animate in the XML declaration. You have to
-  inflate the XML resource by calling {@link android.animation.AnimatorInflater#loadAnimator
-  loadAnimator()} and call {@link android.animation.ObjectAnimator#setTarget setTarget()} to set
-  the target object unlike the underlying {@link android.animation.ObjectAnimator},
-  before calling {@link android.animation.ObjectAnimator#start start()}.</p>
-
-  <p>The <code>set</code> element ({@link android.animation.AnimatorSet}) exposes a single
-  attribute, <code>ordering</code>. Set this attribute to <code>together</code> (default) to play
-  all the animations in this set at once. Set this attribute to <code>sequentially</code> to play
-  the animations in the order they are declared.</p>
-
-  <p>You can specify nested <code>set</code> tags to further group animations together. The
-  animations that you want to group together should be children of the <code>set</code> tag and can
-  define their own <code>ordering</code> attribute.</p>
-
-  <p>As an example, this XML code creates an {@link android.animation.AnimatorSet} object that
-  animates x and y at the same time, then runs an animation that fades an object out:</p>
-  <pre>
-&lt;set android:ordering="sequentially"&gt;
-    &lt;set&gt;
-        &lt;objectAnimator
-            android:propertyName="x"
-            android:duration="500"
-            android:valueTo="400"
-            android:valueType="int"/&gt;
-        &lt;objectAnimator
-            android:propertyName="y"
-            android:duration="500"
-            android:valueTo="300"
-            android:valueType="int"/&gt;
-    &lt;/set&gt;
-    &lt;objectAnimator
-        android:propertyName="alpha"
-        android:duration="500"
-        android:valueTo="0f"/&gt;
-&lt;/set&gt;
-</pre>
-
-  <p>In order to run this animation, you must inflate the XML resources in your code to an {@link
-  android.animation.AnimatorSet} object, and then set the target objects for all of the animations
-  before starting the animation set. Calling {@link android.animation.AnimatorSet#setTarget
-  setTarget()} sets a single target object for all children of the {@link
-  android.animation.AnimatorSet}.</p>
\ No newline at end of file
diff --git a/docs/html/guide/topics/graphics/renderscript.html b/docs/html/guide/topics/graphics/renderscript.html
new file mode 100644
index 0000000..454d392
--- /dev/null
+++ b/docs/html/guide/topics/graphics/renderscript.html
@@ -0,0 +1,10 @@
+<html>
+<head>
+<meta http-equiv="refresh" content="0;url=http://developer.android.com/guide/topics/renderscript/index.html">
+<title>Redirecting...</title>
+</head>
+<body>
+<p>You should be redirected. Please <a
+href="http://developer.android.com/guide/topics/renderscript/index.html">click here</a>.</p>
+</body>
+</html>
\ No newline at end of file
diff --git a/docs/html/guide/topics/graphics/renderscript.jd b/docs/html/guide/topics/graphics/renderscript.jd
deleted file mode 100644
index 60bffdb..0000000
--- a/docs/html/guide/topics/graphics/renderscript.jd
+++ /dev/null
@@ -1,716 +0,0 @@
-page.title=3D Rendering and Computation with Renderscript
-parent.title=Graphics
-parent.link=index.html
-@jd:body
-
-  <div id="qv-wrapper">
-    <div id="qv">
-      <h2>In this document</h2>
-
-      <ol>
-        <li><a href="#overview">Renderscript System Overview</a></li>
-
-        <li>
-          <a href="#api">API Overview</a>
-
-          <ol>
-            <li><a href="#native-api">Native Renderscript APIs</a></li>
-
-            <li><a href="#reflective-api">Reflected layer APIs</a></li>
-
-            <li><a href="#graphics-api">Graphics APIs</a></li>
-          </ol>
-        </li>
-
-        <li>
-          <a href="#developing">Developing a Renderscript application</a>
-
-          <ol>
-            <li><a href="#hello-graphics">The Hello Graphics application</a></li>
-          </ol>
-        </li>
-      </ol>
-      <h2>Related Samples</h2>
-      <ol>
-            <li><a href="{@docRoot}resources/samples/Renderscript/Balls/index.html">Balls</a></li>
-            <li><a href="{@docRoot}resources/samples/Renderscript/Fountain/index.html">Fountain</a></li>
-            <li><a href="{@docRoot}resources/samples/Renderscript/HelloCompute/index.html">Hello Compute</a></li>
-            <li><a href="{@docRoot}resources/samples/Renderscript/HelloWorld/index.html">Hello World</a></li>
-            <li><a href="{@docRoot}resources/samples/Renderscript/Samples/index.html">Samples</a></li>
-          </ol>
-    </div>
-  </div>
-
-  <p>The Renderscript system offers high performance 3D rendering and mathematical computation at
-  the native level. The Renderscript APIs are intended for developers who are comfortable with
-  developing in C (C99 standard) and want to maximize performance in their applications. The
-  Renderscript system improves performance by running as native code on the device, but it also
-  features cross-platform functionality. To achieve this, the Android build tools compile your
-  Renderscript <code>.rs</code> file to intermediate bytecode and package it inside your
-  application's <code>.apk</code> file. On the device, the bytecode is compiled (just-in-time) to
-  machine code that is further optimized for the device that it is running on. This eliminates the
-  need to target a specific architecture during the development process. The compiled code on the
-  device is cached, so subsequent uses of the Renderscript enabled application do not recompile the
-  intermediate code.</p>
-
-  <p>The disadvantage of the Renderscript system is that it adds complexity to the development and
-  debugging processes. Debugging visibility can be limited, because the
-  Renderscript system can execute on processors other than the main CPU (such as the GPU), so if
-  this occurs, debugging becomes more difficult. The target use is for performance
-  critical code where the traditional framework APIs (such as using {@link android.opengl}) are not sufficient.
-  If what you are rendering or computing is very simple and does not require much processing power, you should still use the
-  traditional framework APIs for ease of development. Remember the tradeoffs between development and
-  debugging complexity versus performance when deciding to use Renderscript. </p>
-
-  <p>For an example of Renderscript in action, see the 3D carousel view in the Android 3.0 versions
-  of Google Books and YouTube or install the Renderscript sample applications that are shipped with
-  the SDK in <code>&lt;sdk_root&gt;/samples/android-11/Renderscript</code>.</p>
-
-  <h2 id="overview">Renderscript System Overview</h2>
-
-  <p>The Renderscript system adopts a control and slave architecture where the low-level native
-  code is controlled by the higher level Android system that runs in the virtual machine (VM). When
-  you use the Renderscript system, there are three layers that exist:</p>
-
-  <ul>
-    <li>The native Renderscript layer consists of native libraries that are packaged with the SDK.
-    The native Renderscript <code>.rs</code> files compute mathematical operations, render graphics,
-    or both. This layer does the intensive computation or graphics rendering and returns the result
-    back to the Android VM through the reflected layer.</li>
-
-    <li>The reflected layer is a set of generated Android framework classes reflected from
-    the native Renderscript code that you wrote. This layer acts as a bridge between the native
-    Renderscript layer and the Android system layer. The Android build tools automatically generate
-    the classes for this layer during the build process. This layer also includes a set of Android
-    framework APIs that provide the memory and resource allocation classes to support this layer.</li>
-
-    <li>The Android system layer consists of the traditional framework APIs, which include the Renderscript
-    APIs in {@link android.renderscript}. This layer handles things such as the Activity lifecycle
-    management of your application and calls the reflected layer to communicate with the native Renderscript code.</li>
-  </ul>
-
-  <p>To fully understand how the Renderscript system works, you must understand how the reflected
-  layer is generated and how it interacts with the native Renderscript layer and Android system
-  layer. The reflected layer provides the entry points into the native code, enabling the Android
-  system to give high level commands like, "rotate the view" or "filter the bitmap" to the
-  native layer, which does the heavy lifting. To accomplish this, you need to create logic
-  to hook together all of these layers so that they can correctly communicate.</p>
-
-  <p>At the root of everything is your Renderscript, which is the actual C code that you write and
-  save to a <code>.rs</code> file in your project. There are two kinds of Renderscripts: compute
-  and graphics. A compute Renderscript does not do any graphics rendering while a graphics
-  Renderscript does.</p>
-
-  <p>When you create Renderscript <code>.rs</code> files, equivalent, reflected classes
-  are generated by the build tools and expose the native functions and data types and structures
-  to the Android system. The following list describes the major components of your native Renderscript
-  code that is reflected:</p>
-
-  <ul>
-    <li>The non-static functions in your Renderscript (<code>.rs</code> file) are reflected into
-    <code><em>ScriptC_renderscript_filename</em></code> of type {@link
-    android.renderscript.ScriptC}.</li>
-
-    <li>Any non-static, global Renderscript variables are reflected into
-    <code><em>ScriptC_renderscript_filename</em></code>.
-    Accessor methods are generated, so the Android system layer can access the values.
-    The <code>get</code> method comes with a one-way communication restriction. 
-    The Android system layer always caches the last value that is set and returns that during a call to a <code>get</code> method.
-    If the native Renderscript code changes the value, the change does not propagate back to the Android system layer.
-    If the global variables are initialized in the native Renderscript code, those values are used
-    to initialize the corresponding values in the Android system. If global variables are marked as <code>const</code>,
-    then a <code>set</code> method is not generated.
-    </li>
-
-    <li>Structs are reflected into their own classes, one for each struct, into a class named
-    <code>ScriptField_<em>struct_name</em></code> of type {@link
-    android.renderscript.Script.FieldBase}.</li>
-    
-    <li>Global pointers have a special property. They provide attachment points where the Android system can attach allocations. 
-    If the global pointer is a user defined structure type, it must be a type that is legal for reflection (primitives
-    or Renderscript data types). The Android system can call the reflected class to allocate memory and
-    optionally populate data, then attach it to the Renderscript.
-    For arrays of basic types, the procedure is similar, except a reflected class is not needed.
-    Renderscripts should not directly set the exported global pointers.</li>
-     </ul>
-
-  <p>The Android framework API also has a corresponding Renderscript context object, {@link
-  android.renderscript.RenderScript} (for a compute Renderscript) or {@link
-  android.renderscript.RenderScriptGL} (for a graphics Renderscript). This context object allows
-  you to bind to the reflected Renderscript class, so that the Renderscript context knows what its
-  corresponding native Renderscript is. If you have a graphics Renderscript context, you can also
-  specify a variety of Programs (stages in the graphics pipeline) to tweek how your graphics are
-  rendered. A graphics Renderscript context also needs a surface to render on, {@link
-  android.renderscript.RSSurfaceView}, which gets passed into its constructor.</p>
-
-  <h2 id="api">API overview</h2>
-
-  <p>Renderscript code is compiled and executed in a compact and well defined runtime, which has
-  access to a limited amount of functions. Renderscript cannot use the NDK or standard C functions,
-  because these functions are assumed to be running on a standard CPU. The Renderscript runtime
-  chooses the best processor to execute the code, which may not be the CPU, so it cannot guarantee
-  support for standard C libraries. What Renderscript does offer is an API that supports intensive
-  computation with an extensive collection of math APIs. The following sections group the APIs
-  into three distinct categories.</p>
-
-
-  <h3 id="native-api">Native Renderscript APIs</h3>
-
-  <p>The Renderscript headers are located in the <code>include</code> and
-  <code>clang-include</code> directories in the
-  <code>&lt;sdk_root&gt;/platforms/android-11/renderscript</code> directory of the Android SDK.
-  The headers are automatically included for you, except for the graphics specific header,
-  which you can define as follows:</p>
-  
-<pre>#include "rs_graphics.rsh"</pre>
-
-<p>Some key features of the native Renderscript libraries include:
-  <ul>
-    <li>A large collection of math functions with both scalar and vector typed overloaded versions
-    of many common routines. Operations such as adding, multiplying, dot product, and cross product
-    are available.</li>
-    <li>Conversion routines for primitive data types and vectors, matrix routines, date and time
-    routines, and graphics routines.</li>
-    <li>Logging functions</li>
-    <li>Graphics rendering functions</li>
-    <li>Memory allocation request features</li>
-    <li>Data types and structures to support the Renderscript system such as
-    Vector types for defining two-, three-, or four-vectors.</li>
-  </ul>
-
-  <h3 id="reflective-api">Reflected layer APIs</h3>
-
-  <p>These classes are mainly used by the reflected classes that are generated from your native Renderscript
-  code. They allocate and manage memory for your Renderscript on the Android system side. 
-  You normally do not need to call these classes directly.</p> 
-  
-  <p>Because of the constraints of the Renderscript native layer, you cannot do any dynamic
-  memory allocation in your Renderscript <code>.rs</code> file.
-  The native Renderscript layer can request memory from the Android system layer, which allocates memory
-  for you and does reference counting to figure out when to free the memory. A memory allocation
-  is taken care of by the {@link android.renderscript.Allocation} class and memory is requested
-  in your Renderscript code with the <code>the rs_allocation</code> type.
-  All references to Renderscript objects are counted, so when your Renderscript native code
-  or system code no longer references a particular {@link android.renderscript.Allocation}, it destroys itself.
-  Alternatively, you can call {@link android.renderscript.Allocation#destroy destroy()} from the
-  Android system level, which decreases the reference to the {@link android.renderscript.Allocation}.
-  If no references exist after the decrease, the {@link android.renderscript.Allocation} destroys itself.
-  The Android system object, which at this point is just an empty shell, is eventually garbage collected.
-  </p>
-
-  <p>The following classes are mainly used by the reflected layer classes:</p>
-
-  <table>
-    <tr>
-      <th>Android Object Type</th>
-
-      <th>Renderscript Native Type</th>
-
-      <th>Description</th>
-    </tr>
-
-    <tr>
-      <td>{@link android.renderscript.Element}</td>
-
-      <td>rs_element</td>
-
-      <td>
-        An {@link android.renderscript.Element} is the most basic element of a memory type. An
-        element represents one cell of a memory allocation. An element can have two forms: Basic or
-        Complex. They are typically created from C structures in your Renderscript
-        code during the reflection process. Elements cannot contain pointers or nested arrays. 
-        The other common source of elements is bitmap formats.
-
-        <p>A basic element contains a single component of data of any valid Renderscript data type.
-        Examples of basic element data types include a single float value, a float4 vector, or a
-        single RGB-565 color.</p>
-
-        <p>Complex elements contain a list of sub-elements and names that is basically a reflection
-        of a C struct. You access the sub-elements by name from a script or vertex program. The
-        most basic primitive type determines the data alignment of the structure. For example, a
-        float4 vector is alligned to <code>sizeof(float)</code> and not
-        <code>sizeof(float4)</code>. The ordering of the elements in memory are the order in which
-        they were added, with each component aligned as necessary.</p>
-      </td>
-    </tr>
-
-    <tr>
-      <td>{@link android.renderscript.Type}</td>
-
-      <td>rs_type</td>
-
-      <td>A Type is an allocation template that consists of an element and one or more dimensions.
-      It describes the layout of the memory but does not allocate storage for the data that it
-      describes. A Type consists of five dimensions: X, Y, Z, LOD (level of detail), and Faces (of
-      a cube map). You can assign the X,Y,Z dimensions to any positive integer value within the
-      constraints of available memory. A single dimension allocation has an X dimension of greater
-      than zero while the Y and Z dimensions are zero to indicate not present. For example, an
-      allocation of x=10, y=1 is considered two dimensional and x=10, y=0 is considered one
-      dimensional. The LOD and Faces dimensions are booleans to indicate present or not
-      present.</td>
-    </tr>
-
-    <tr>
-      <td>{@link android.renderscript.Allocation}</td>
-
-      <td>rs_allocation</td>
-
-      <td>
-        <p>An {@link android.renderscript.Allocation} provides the memory for applications. An {@link
-        android.renderscript.Allocation} allocates memory based on a description of the memory that
-        is represented by a {@link android.renderscript.Type}. The type describes an array of elements that
-        represent the memory to be allocated. Allocations are the primary way data moves into and
-        out of scripts.</p>
-
-        <p>Memory is user-synchronized and it's possible for allocations to exist in multiple
-        memory spaces concurrently. For example, if you make a call to the graphics card to load a
-        bitmap, you give it the bitmap to load from in the system memory. After that call returns,
-        the graphics memory contains its own copy of the bitmap so you can choose whether or not to
-        maintain the bitmap in the system memory. If the Renderscript system modifies an allocation
-        that is used by other targets, it must call {@link android.renderscript#syncAll syncAll()} to push the updates to
-        the memory. Otherwise, the results are undefined.</p>
-
-        <p>Allocation data is uploaded in one of two primary ways: type checked and type unchecked.
-        For simple arrays there are <code>copyFrom()</code> functions that take an array from the
-        Android system and copy it to the native layer memory store. Both type checked and
-        unchecked copies are provided. The unchecked variants allow the Android system to copy over
-        arrays of structures because it does not support structures. For example, if
-        there is an allocation that is an array n floats, you can copy the data contained in a
-        float[n] array or a byte[n*4] array.</p>
-      </td>
-    </tr>
-
-    <tr>
-      <td>{@link android.renderscript.Script}</td>
-
-      <td>rs_script</td>
-
-      <td>Renderscript scripts do much of the work in the native layer. This class is generated
-      from a Renderscript file that has the <code>.rs</code> file extension. This class is named
-      <code>ScriptC_<em>rendersript_filename</em></code> when it gets generated.</td>
-    </tr>
-  </table>
-
-  <h3 id="graphics-api">Graphics API</h3>
-
-  <p>Renderscript provides a number of graphics APIs for hardware-accelerated 3D rendering. The
-  Renderscript graphics APIs include a stateful context, {@link
-  android.renderscript.RenderScriptGL} that contains the current rendering state. The primary state
-  consists of the objects that are attached to the rendering context, which are the graphics Renderscript
-  and the four program types. The main working function of the graphics Renderscript is the code that is
-  defined in the <code>root()</code> function. The <code>root()</code> function is called each time the surface goes through a frame
-  refresh. The four program types mirror a traditional graphical rendering pipeline and are:</p>
-
-  <ul>
-    <li>Vertex</li>
-
-    <li>Fragment</li>
-
-    <li>Store</li>
-
-    <li>Raster</li>
-  </ul>
-
-  <p>Graphical scripts have more properties beyond a basic computational script, and they call the
-  'rsg'-prefixed functions defined in the <code>rs_graphics.rsh</code> header file. A graphics
-  Renderscript can also set four pragmas that control the default bindings to the {@link
-  android.renderscript.RenderScriptGL} context when the script is executing:</p>
-
-  <ul>
-    <li>stateVertex</li>
-
-    <li>stateFragment</li>
-
-    <li>stateRaster</li>
-
-    <li>stateStore</li>
-  </ul>
-
-  <p>The possible values are <code>parent</code> or <code>default</code> for each pragma. Using
-  <code>default</code> says that when a script is executed, the bindings to the graphical context
-  are the system defaults. Using <code>parent</code> says that the state should be the same as it
-  is in the calling script. If this is a root script, the parent
-  state is taken from the bind points as set in the {@link android.renderscript.RenderScriptGL}
-  bind methods in the control environment (VM environment).</p>
-
-  <p>For example, you can define this at the top of your native graphics Renderscript code:</p>
-  <pre>
-#pragma stateVertex(parent)
-#pragma stateStore(parent)
-</pre>
-
-  <p>The following table describes the major graphics specific APIs that are available to you:</p>
-
-  <table>
-    <tr>
-      <th>Android Object Type</th>
-
-      <th>Renderscript Native Type</th>
-
-      <th>Description</th>
-    </tr>
-
-    <tr>
-      <td>{@link android.renderscript.ProgramVertex}</td>
-
-      <td>rs_program_vertex</td>
-
-      <td>
-        <p>The Renderscript vertex program, also known as a vertex shader, describes the stage in the
-        graphics pipeline responsible for manipulating geometric data in a user-defined way. The
-        object is constructed by providing Renderscript with the following data:</p>
-
-        <ul>
-          <li>An Element describing its varying inputs or attributes</li>
-
-          <li>GLSL shader string that defines the body of the program</li>
-
-          <li>a Type that describes the layout of an Allocation containing constant or uniform
-          inputs</li>
-        </ul>
-
-        <p>Once the program is created, bind it to the {@link android.renderscript.RenderScriptGL} 
-        graphics context by calling 
-        {@link android.renderscript.RenderScriptGL#bindProgramVertex bindProgramVertex()}. It is then used for all
-        subsequent draw calls until you bind a new program. If the program has constant inputs, the
-        user needs to bind an allocation containing those inputs. The allocation's type must match
-        the one provided during creation. The Renderscript library then does all the necessary
-        plumbing to send those constants to the graphics hardware. Varying inputs to the shader,
-        such as position, normal, and texture coordinates are matched by name between the input
-        Element and the Mesh object being drawn. The signatures don't have to be exact or in any
-        strict order. As long as the input name in the shader matches a channel name and size
-        available on the mesh, the run-time would take care of connecting the two. Unlike OpenGL,
-        there is no need to link the vertex and fragment programs.</p>
-        <p>  To bind shader constructs to the Program, declare a struct containing the necessary shader constants in your native Renderscript code.
-  This struct is generated into a reflected class that you can use as a constant input element
-  during the Program's creation. It is an easy way to create an instance of this struct as an allocation.
-  You would then bind this Allocation to the Program and the Renderscript system sends the data that
-  is contained in the struct to the hardware when necessary. To update shader constants, you change the values
-  in the Allocation and notify the native Renderscript code of the change.</p>
-      </td>
-    </tr>
-
-    <tr>
-      <td>{@link android.renderscript.ProgramFragment}</td>
-
-      <td>rs_program_fragment</td>
-
-      <td><p>The Renderscript fragment program, also known as the fragment shader, is responsible for
-      manipulating pixel data in a user-defined way. It's constructed from a GLSL shader string
-      containing the program body, textures inputs, and a Type object describing the constants used
-      by the program. Like the vertex programs, when an allocation with constant input values is
-      bound to the shader, its values are sent to the graphics program automatically. Note that the
-      values inside the allocation are not explicitly tracked. If they change between two draw
-      calls using the same program object, notify the runtime of that change by calling
-      rsgAllocationSyncAll so it could send the new values to hardware. Communication between the
-      vertex and fragment programs is handled internally in the GLSL code. For example, if the
-      fragment program is expecting a varying input called varTex0, the GLSL code inside the
-      program vertex must provide it.</p>
-      <p>  To bind shader constructs to the this Program, declare a struct containing the necessary shader constants in your native Renderscript code.
-  This struct is generated into a reflected class that you can use as a constant input element
-  during the Program's creation. It is an easy way to create an instance of this struct as an allocation.
-  You would then bind this Allocation to the Program and the Renderscript system sends the data that
-  is contained in the struct to the hardware when necessary. To update shader constants, you change the values
-  in the Allocation and notify the native Renderscript code of the change.</p></td>
-    </tr>
-
-    <tr>
-      <td>{@link android.renderscript.ProgramStore}</td>
-
-      <td>rs_program_store</td>
-
-      <td>The Renderscript ProgramStore contains a set of parameters that control how the graphics
-      hardware writes to the framebuffer. It could be used to enable and disable depth writes and
-      testing, setup various blending modes for effects like transparency and define write masks
-      for color components.</td>
-    </tr>
-
-    <tr>
-      <td>{@link android.renderscript.ProgramRaster}</td>
-
-      <td>rs_program_raster</td>
-
-      <td>Program raster is primarily used to specify whether point sprites are enabled and to
-      control the culling mode. By default back faces are culled.</td>
-    </tr>
-
-    <tr>
-      <td>{@link android.renderscript.Sampler}</td>
-
-      <td>rs_sampler</td>
-
-      <td>A Sampler object defines how data is extracted from textures. Samplers are bound to
-      Program objects (currently only a Fragment Program) alongside the texture whose sampling they
-      control. These objects are used to specify such things as edge clamping behavior, whether
-      mip-maps are used and the amount of anisotropy required. There may be situations where
-      hardware limitations prevent the exact behavior from being matched. In these cases, the
-      runtime attempts to provide the closest possible approximation. For example, the user
-      requested 16x anisotropy, but only 8x was set because it's the best available on the
-      hardware.</td>
-    </tr>
-
-    <tr>
-      <td>{@link android.renderscript.Mesh}</td>
-
-      <td>rs_mesh</td>
-
-      <td>A collection of allocations that represent vertex data (positions, normals, texture
-      coordinates) and index data such as triangles and lines. Vertex data can be interleaved
-      within one allocation, provided separately as multiple allocation objects, or done as a
-      combination of the above. The layout of these allocations will be extracted from their
-      Elements. When a vertex channel name matches an input in the vertex program, Renderscript
-      automatically connects the two. Moreover, even allocations that cannot be directly mapped to
-      graphics hardware can be stored as part of the mesh. Such allocations can be used as a
-      working area for vertex-related computation and will be ignored by the hardware. Parts of the
-      mesh could be rendered with either explicit index sets or primitive types.</td>
-    </tr>
-
-    <tr>
-      <td>{@link android.renderscript.Font}</td>
-
-      <td>rs_font</td>
-
-      <td>
-        <p>This class gives you a way to draw hardware accelerated text. Internally, the glyphs are
-        rendered using the Freetype library, and an internal cache of rendered glyph bitmaps is
-        maintained. Each font object represents a combination of a typeface and point sizes.
-        Multiple font objects can be created to represent faces such as bold and italic and to
-        create different font sizes. During creation, the framework determines the device screen's
-        DPI to ensure proper sizing across multiple configurations.</p>
-
-        <p>Font rendering can impact performance. Even though though the state changes are
-        transparent to the user, they are happening internally. It is more efficient to render
-        large batches of text in sequence, and it is also more efficient to render multiple
-        characters at once instead of one by one.</p>
-
-        <p>Font color and transparency are not part of the font object and can be freely modified
-        in the script to suit the your needs. Font colors work as a state machine, and every new
-        call to draw text will use the last color set in the script.</p>
-      </td>
-    </tr>
-  </table>
-
-
-  <h2 id="developing">Developing a Renderscript application</h2>
-
-  <p>The basic workflow of developing a Renderscript application is:</p>
-
-  <ol>
-    <li>Analyze your application's requirements and figure out what you want to develop with
-    Renderscript. To take full advantage of the Renderscript system, you want to use it when the computation
-    or graphics performance you're getting with the traditional framework APIs is
-    insufficient.</li>
-
-    <li>Design the interface of your Renderscript code and implement it using the native
-    Renderscript APIs that are included in the Android SDK in
-    <code>&lt;sdk_root&gt;/platforms/android-11/renderscript</code>.</li>
-
-    <li>Create an Android project as you would normally, in Eclipse or with the
-    <code>android</code> tool.</li>
-
-    <li>Place your Renderscript files in <code>src</code> folder of the Android project so that the
-    build tools can generate the reflected layer classes.</li>
-
-    <li>Create your application, calling the Renderscript through the reflected class layer when
-    you need to.</li>
-
-    <li>Build, install, and run your application as you would normally.</li>
-  </ol>
-
-  <p>To see how a simple Renderscript application is put together, see the 
-  <a href="{@docRoot}resources/samples/Renderscript/index.html">Renderscript samples</a>
-  and <a href="#hello-graphics">The Hello Graphics Application</a> section of the documentation.</p>
-
-  <h3 id="hello-graphics">The Hello Graphics Application</h3>
-
-  <p>This small application demonstrates the structure of a simple Renderscript application. You
-  can model your Renderscript application after the basic structure of this application. You can
-  find the complete source in the SDK in the
-  <code>&lt;android-sdk&gt;/samples/android-11/HelloWorldRS directory</code>. The
-  application uses Renderscript to draw the string, "Hello World!" to the screen and redraws the
-  text whenever the user touches the screen at the location of the touch. This application is only
-  a demonstration and you should not use the Renderscript system to do something this trivial. The
-  application contains the following source files:</p>
-
-  <ul>
-    <li><code>HelloWorld</code>: The main Activity for the application. This class is present to
-    provide Activity lifecycle management. It mainly delegates work to HelloWorldView, which is the
-    Renderscript surface that the sample actually draws on.</li>
-
-    <li><code>HelloWorldView</code>: The Renderscript surface that the graphics render on. If you
-    are using Renderscript for graphics rendering, you must have a surface to render on. If you are
-    using it for computatational operations only, then you do not need this.</li>
-
-    <li><code>HelloWorldRS</code>: The class that calls the native Renderscript code through high
-    level entry points that are generated by the Android build tools.</li>
-
-    <li><code>helloworld.rs</code>: The Renderscript native code that draws the text on the
-    screen.</li>
-
-    <li>
-      <p>The <code>&lt;project_root&gt;/gen</code> directory contains the reflected layer classes
-      that are generated by the Android build tools. You will notice a
-      <code>ScriptC_helloworld</code> class, which is the reflective version of the Renderscript
-      and contains the entry points into the <code>helloworld.rs</code> native code. This file does
-      not appear until you run a build.</p>
-    </li>
-  </ul>
-
-  <p>Each file has its own distinct use. The following files comprise the main parts of the sample and
-  demonstrate in detail how the sample works:</p>
-
-  <dl>
-    <dt><code>helloworld.rs</code></dt>
-
-    <dd>
-      The native Renderscript code is contained in the <code>helloworld.rs</code> file. Every
-      <code>.rs</code> file must contain two pragmas that define the version of Renderscript
-      that it is using (1 is the only version for now), and the package name that the reflected
-      classes should be generated with. For example:
-<pre>
-#pragma version(1)
-
-#pragma rs java_package_name(com.my.package.name)
-</pre>      
-      <p>An <code>.rs</code> file can also declare two special functions:</p>
-
-      <ul>
-        <li>
-          <code>init()</code>: This function is called once for each instance of this Renderscript
-          file that is loaded on the device, before the script is accessed in any other way by the
-          Renderscript system. The <code>init()</code> is ideal for doing one time setup after the
-          machine code is loaded such as initializing complex constant tables. The
-          <code>init()</code> function for the <code>helloworld.rs</code> script sets the initial
-          location of the text that is rendered to the screen:
-          <pre>
-void init(){
-    gTouchX = 50.0f;
-    gTouchY = 50.0f;
-}
-</pre>
-        </li>
-
-        <li>
-          <code>root()</code>: This function is the default worker function for this Renderscript
-          file. For graphics Renderscript applications, like this one, the Renderscript system
-          expects this function to render the frame that is going to be displayed. It is called
-          every time the frame refreshes. The <code>root()</code> function for the
-          <code>helloworld.rs</code> script sets the background color of the frame, the color of
-          the text, and then draws the text where the user last touched the screen:
-<pre>
-int root(int launchID) {
-    // Clear the background color
-    rsgClearColor(0.0f, 0.0f, 0.0f, 0.0f);
-    // Tell the runtime what the font color should be
-    rsgFontColor(1.0f, 1.0f, 1.0f, 1.0f);
-    // Introduce ourselves to the world by drawing a greeting
-    // at the position that the user touched on the screen
-    rsgDrawText("Hello World!", gTouchX, gTouchY);
-          
-    // Return value tells RS roughly how often to redraw
-    // in this case 20 ms
-    return 20;
-}
-</pre>
-
-          <p>The return value, <code>20</code>, is the desired frame refresh rate in milliseconds.
-          The real screen refresh rate depends on the hardware, computation, and rendering
-          complexity that the <code>root()</code> function has to execute. A value of
-          <code>0</code> tells the screen to render only once and to only render again when a
-          change has been made to one of the properties that are being modified by the Renderscript
-          code.</p>
-
-          <p>Besides the <code>init()</code> and <code>root()</code> functions, you can define the
-          other native functions, structs, data types, and any other logic for your Renderscript.
-          You can even define separate header files as <code>.rsh</code> files.</p>
-        </li>
-      </ul>
-    </dd>
-
-    <dt><code>ScriptC_helloworld</code></dt>
-
-    <dd>This class is generated by the Android build tools and is the reflected version of the
-    <code>helloworld.rs</code> Renderscript. It provides a a high level entry point into the
-    <code>helloworld.rs</code> native code by defining the corresponding methods that you can call
-    from the traditional framework APIs.</dd>
-
-    <dt><code>helloworld.bc</code> bytecode</dt>
-
-    <dd>This file is the intermediate, platform-independent bytecode that gets compiled on the
-    device when the Renderscript application runs. It is generated by the Android build tools and
-    is packaged with the <code>.apk</code> file and subsequently compiled on the device at runtime.
-    This file is located in the <code>&lt;project_root&gt;/res/raw/</code> directory and is named
-    <code>rs_filename.bc</code>. You need to bind these files to your Renderscript context before
-    call any Renderscript code from your Android application. You can reference them in your code
-    with <code>R.id.rs_filename</code>.</dd>
-
-    <dt><code>HelloWorldView</code> class</dt>
-
-    <dd>
-      This class represents the Surface View that the Renderscript graphics are drawn on. It does
-      some administrative tasks in the <code>ensureRenderScript()</code> method that sets up the
-      Renderscript system. This method creates a {@link android.renderscript.RenderScriptGL}
-      object, which represents the context of the Renderscript and creates a default surface to
-      draw on (you can set the surface properties such as alpha and bit depth in the {@link
-      android.renderscript.RenderScriptGL.SurfaceConfig} class ). When a {@link
-      android.renderscript.RenderScriptGL} is instantiated, this class calls the
-      <code>HelloRS</code> class and creates the instance of the actual Renderscript graphics
-      renderer.
-      <pre>
-// Renderscipt context
-private RenderScriptGL mRS;
-// Script that does the rendering
-private HelloWorldRS mRender;
-
-    private void ensureRenderScript() {
-        if (mRS == null) {
-            // Initialize Renderscript with desired surface characteristics.
-            // In this case, just use the defaults
-            RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
-            mRS = createRenderScriptGL(sc);
-
-            // Create an instance of the Renderscript that does the rendering
-            mRender = new HelloWorldRS();
-            mRender.init(mRS, getResources());
-        }
-    }
-</pre>
-
-      <p>This class also handles the important lifecycle events and relays touch events to the
-      Renderscript renderer. When a user touches the screen, it calls the renderer,
-      <code>HelloWorldRS</code> and asks it to draw the text on the screen at the new location.</p>
-      <pre>
-public boolean onTouchEvent(MotionEvent ev) {
-    // Pass touch events from the system to the rendering script
-    if (ev.getAction() == MotionEvent.ACTION_DOWN) {
-        mRender.onActionDown((int)ev.getX(), (int)ev.getY());
-        return true;
-    }
-    return false;
-}
-</pre>
-    </dd>
-
-    <dt><code>HelloWorldRS</code></dt>
-
-    <dd>
-      This class represents the Renderscript renderer for the <code>HelloWorldView</code> Surface
-      View. It interacts with the native Renderscript code that is defined in
-      <code>helloworld.rs</code> through the interfaces exposed by <code>ScriptC_helloworld</code>.
-      To be able to call the native code, it creates an instance of the Renderscript reflected
-      class, <code>ScriptC_helloworld</code>. The reflected Renderscript object binds the
-      Renderscript bytecode (<code>R.raw.helloworld</code>) and the Renderscript context, {@link
-      android.renderscript.RenderScriptGL}, so the context knows to use the right Renderscript to
-      render its surface.
-      <pre>
-private Resources mRes;
-private RenderScriptGL mRS;
-private ScriptC_helloworld mScript;
-
-private void initRS() {
-    mScript = new ScriptC_helloworld(mRS, mRes, R.raw.helloworld);
-    mRS.bindRootScript(mScript);
-}
-</pre>
-    </dd>
-  </dl>
\ No newline at end of file
diff --git a/docs/html/guide/topics/renderscript/compute.jd b/docs/html/guide/topics/renderscript/compute.jd
new file mode 100644
index 0000000..e4c2283
--- /dev/null
+++ b/docs/html/guide/topics/renderscript/compute.jd
@@ -0,0 +1,38 @@
+page.title=Compute
+parent.title=RenderScript
+parent.link=index.html 
+@jd:body
+
+  <div id="qv-wrapper">
+    <div id="qv">
+
+      <h2>Related Samples</h2>
+
+      <ol>
+        <li><a href="{@docRoot}resources/samples/RenderScript/HelloCompute/index.html">Hello
+        Compute</a></li>
+        <li><a href="{@docRoot}resources/samples/RenderScript/Balls/index.html">Balls</a></li>
+      </ol>
+    </div>
+  </div>
+
+  <p>RenderScript exposes a set of compute APIs that you can use to do intensive computational operations.
+  You can use the compute APIs in the context of a graphics RenderScript such as calculating the
+  transformation of many geometric objects in a scene. You can also create a standalone compute RenderScript that does not
+  draw anything to the screen such as bitmap image processing for a photo editor application.
+  The RenderScript compute APIs are mainly defined in the <code>rs_cl.rsh</code> header</p>
+  
+  <p>Compute RenderScripts are simpler to setup and implement as there is no graphics rendering involved.
+  You can offload computational aspects of your application to RenderScript by creating a native RenderScript
+  file (.rs) and using the generated reflected layer class to call functions in the <code>.rs</code> file. 
+
+  <p>See the <a href="{@docRoot}resources/samples/RenderScript/HelloCompute/index.html">HelloCompute</a>
+  sample in the Android SDK for more
+  information on how to create a simple compute RenderScript.</p>
+  <p>  
+  See the <a href="{@docRoot}resources/samples/RenderScript/Balls/index.html">Balls</a>
+  sample in the Android SDK for more
+  information on how to create a compute RenderScript that is used in a graphics RenderScript.
+  The compute RenderScript is contained in 
+  <a href="{@docRoot}resources/samples/RenderScript/Balls/src/com/example/android/rs/balls/ball_physics.html">balls_physics.rs</a>.
+  </p>
\ No newline at end of file
diff --git a/docs/html/guide/topics/renderscript/graphics.jd b/docs/html/guide/topics/renderscript/graphics.jd
new file mode 100644
index 0000000..d8be85f
--- /dev/null
+++ b/docs/html/guide/topics/renderscript/graphics.jd
@@ -0,0 +1,619 @@
+page.title=3D Graphics
+parent.title=RenderScript 
+parent.link=index.html
+@jd:body
+
+  <div id="qv-wrapper">
+    <div id="qv">
+      <h2>In this document</h2>
+
+      <ol>
+        <li>
+          <a href="#developing">Developing a RenderScript application</a>
+
+          <ol>
+            <li><a href="#hello-graphics">The Hello Graphics application</a></li>
+          </ol>
+        </li>
+      </ol>
+
+      <h2>Related Samples</h2>
+
+      <ol>
+        <li><a href="{@docRoot}resources/samples/RenderScript/Balls/index.html">Balls</a></li>
+
+        <li><a href=
+        "{@docRoot}resources/samples/Renderscript/Fountain/index.html">Fountain</a></li>
+
+        <li><a href="{@docRoot}resources/samples/RenderScript/HelloWorld/index.html">Hello
+        World</a></li>
+
+        <li><a href="{@docRoot}resources/samples/RenderScript/Samples/index.html">Samples</a></li>
+      </ol>
+    </div>
+  </div>
+
+  <p>RenderScript provides a number of graphics APIs for 3D rendering, both at the Android
+  framework level as well as at the native level. For instance, the Android framework APIs let you
+  create meshes and define shaders to customize the graphical rendering pipeline. The native
+  RenderScript graphics APIs lets you draw the actual meshes to render your scene. In general, you
+  will need to be familiar with APIs to appropriately render 3D graphics on an Android-powered
+  device.</p>
+
+  <h2>Creating a Graphics RenderScript</h2>
+
+  <p>Because of the various layers of code when writing a RenderScript application, it is useful to
+  create the following files for a scene that you want to render:</p>
+
+  <ul>
+    <li>The native RenderScript <code>.rs</code> file. This file contains the logic to do the
+    graphics rendering.</li>
+
+    <li>The RenderScript entry point class that allows your view to interact with the code defined
+    in the <code>.rs</code> file. This class contains a RenderScript object(instance of
+    <code>ScriptC_<em>renderscript_file</em></code>), which allows your Android framework code to
+    call the native RenderScript code. This class also creates the {@link
+    android.renderscript.RenderScriptGL} context object, which contains the current rendering state
+    of the RenderScript such as programs (vertex and fragment shaders, for example) that you want
+    to define and bind to the graphics pipeline. The context object attaches to the RenderScript
+    object (instance of <code><em>ScriptC_renderscript_file</em></code>) that does the rendering.
+    Our example names this class <code>HelloWorldRS</code>.</li>
+
+    <li>Create a class that extends {@link android.renderscript.RSSurfaceView} to provide a surface
+    to render on. If you want to implement callbacks from events inherited from {@link
+    android.view.View}, such as {@link android.view.View#onTouchEvent onTouchEvent()} and {@link
+    android.view.View#onKeyDown onKeyDown()}, do so in this class as well.</li>
+
+    <li>Create a class that is the main Activity class, like you would with any Android
+    application. This class sets your {@link android.renderscript.RSSurfaceView} as the content
+    view for this Activity.</li>
+  </ul>
+
+  <p>The following sections describe how to implement these three classes by using the HelloWorld
+  RenderScript sample that is provided in the SDK as a guide (some code has been modified from its
+  original form for simplicity).</p>
+
+  <h3>Creating the native RenderScript file</h3>
+
+  <p>Your native RenderScript code resides in a <code>.rs</code> file in the
+  <code>&lt;project_root&gt;/src/</code> directory. You can also define <code>.rsh</code> header
+  files. This code contains the logic to render your graphics and declares all necessary variables
+  and pointers. Every graphics <code>.rs</code> file generally contains the following items:</p>
+
+  <ul>
+    <li>A pragma (<code>#pragma rs java_package_name(<em>package.name</em>)</code>) that declares
+    the package name of the <code>.java</code> reflection of this RenderScript.</li>
+
+    <li>A pragma (<code>#pragma version(1)</code>) that declares the version of RenderScript that
+    you are using (1 is the only value for now).</li>
+
+    <li>A <code>#include</code> of the rs_graphics.rsh header file.</li>
+
+    <li>A <code>root()</code> function. This is the main worker function for your RenderScript and
+    calls RenderScript graphics APIs to draw meshes to the surface. This function is called every
+    time a frame refresh occurs, which is specified as its return value. A <code>0</code> specified
+    for the return value says to only render the frame when a property of the scene that you are
+    rendering changes. A non-zero positive integer specifies the refresh rate of the frame in
+    milliseconds.
+
+      <p class="note"><strong>Note:</strong> The RenderScript runtime makes its best effort to
+      refresh the frame at the specified rate. For example, if you are creating a live wallpaper
+      and set the return value to 50, the runtime renders the wallpaper at 20fps if it has just
+      enough or more resources to do so, and renders as fast as it can if it does not.</p>
+      
+      <p>For more
+      information on using the RenderScript graphics functions, see <a href=
+      "using-graphics-api">Using the Graphics APIs</a>.</p>
+    </li>
+
+    <li>An <code>init()</code> function. This allows you to do any initialization of your
+    RenderScript before the <code>root()</code> function runs, such as initializing variables. This
+    function runs once and is called automatically when the RenderScript starts, before anything
+    else in your RenderScript. Creating this function is optional.</li>
+
+    <li>Any variables, pointers, and structures that you wish to use in your RenderScript code (can
+    be declared in <code>.rsh</code> files if desired)</li>
+  </ul>
+
+  <p>The following code shows how the <code>helloworld.rs</code> file is implemented:</p>
+  <pre>
+#pragma version(1)
+
+// Tell which java package name the reflected files should belong to
+#pragma rs java_package_name(com.android.rs.helloworld)
+
+// Built-in header with graphics APIs
+#include "rs_graphics.rsh"
+
+// gTouchX and gTouchY are variables that are reflected for use
+// by the Android framework API. This RenderScript uses them to be notified of touch events.
+int gTouchX;
+int gTouchY;
+
+// This is invoked automatically when the script is created and initializes the variables
+// in the Android framework layer as well.
+void init() {
+    gTouchX = 50.0f;
+    gTouchY = 50.0f;
+}
+
+int root(int launchID) {
+
+    // Clear the background color
+    rsgClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+    // Tell the runtime what the font color should be
+    rsgFontColor(1.0f, 1.0f, 1.0f, 1.0f);
+    // Introuduce ourselves to the world by drawing a greeting
+    // at the position user touched on the screen
+    rsgDrawText("Hello World!", gTouchX, gTouchY);
+
+    // Return value tells RS roughly how often to redraw
+    // in this case 20 ms
+    return 20;
+}
+</pre>
+
+  <h3>Creating the RenderScript entry point class</h3>
+
+  <p>When you create a RenderScript (<code>.rs</code>) file, it is helpful to create a
+  corresponding Android framework class that is an entry point into the <code>.rs</code> file. In
+  this entry point class, you create a RenderScript object by instantiating a
+  <code>ScriptC_<em>rs_filename</em></code> and binding it to the RenderScript context. The
+  RenderScript object is attached to the RenderScript bytecode, which is platform-independent and
+  gets compiled on the device when the RenderScript application runs. Both the
+  <code>ScriptC_<em>rs_filename</em></code> class and bytecode is generated by the Android build
+  tools and is packaged with the <code>.apk</code> file. The bytecode file is located in the
+  <code>&lt;project_root&gt;/res/raw/</code> directory and is named <code>rs_filename.bc</code>.
+  You refer to the bytecode as a resource (<code>R.raw.<em>rs_filename</em></code>). when creating
+  the RenderScript object..</p>
+
+  <p>You then bind the RenderScript object to the RenderScript context, so that the surface view
+  knows what code to use to render graphics. The following code shows how the
+  <code>HelloWorldRS</code> class is implemented:</p>
+  <pre>
+package com.android.rs.helloworld;
+
+import android.content.res.Resources;
+import android.renderscript.*;
+
+public class HelloWorldRS {
+    //context and resources are obtained from RSSurfaceView, which calls init()
+    private Resources mRes;
+    private RenderScriptGL mRS;
+
+    //Declare the RenderScript object
+    private ScriptC_helloworld mScript;
+
+    public HelloWorldRS() {
+    }
+
+    /**
+     * This provides us with the RenderScript context and resources
+     * that allow us to create the RenderScript object
+     */
+    public void init(RenderScriptGL rs, Resources res) {
+        mRS = rs;
+        mRes = res;
+        initRS();
+    }
+    /**
+     * Calls native RenderScript functions (set_gTouchX and set_gTouchY)
+     * through the reflected layer class ScriptC_helloworld to pass in
+     * touch point data.
+     */
+    public void onActionDown(int x, int y) {
+        mScript.set_gTouchX(x);
+        mScript.set_gTouchY(y);
+    }
+    /**
+     * Binds the RenderScript object to the RenderScript context
+     */
+    private void initRS() {
+        //create the RenderScript object
+        mScript = new ScriptC_helloworld(mRS, mRes, R.raw.helloworld);
+        //bind the RenderScript object to the RenderScript context
+        mRS.bindRootScript(mScript);
+    }
+}
+
+</pre>
+
+  <h3>Creating the surface view</h3>
+
+  <p>To create a surface view to render graphics on, create a class that extends {@link
+  android.renderscript.RSSurfaceView}. This class also creates a RenderScript context object
+  ({@link android.renderscript.RenderScriptGL} and passes it to the Rendscript entry point class to
+  bind the two. The following code shows how the <code>HelloWorldView</code> class is
+  implemented:</p>
+  <pre>
+package com.android.rs.helloworld;
+
+import android.renderscript.RSSurfaceView;
+import android.renderscript.RenderScriptGL;
+import android.content.Context;
+import android.view.MotionEvent;
+
+public class HelloWorldView extends RSSurfaceView {
+    // RenderScript context
+    private RenderScriptGL mRS;
+    // RenderScript entry point object that does the rendering
+    private HelloWorldRS mRender;
+
+    public HelloWorldView(Context context) {
+        super(context);
+        initRS();
+    }
+
+    private void initRS() {
+        if (mRS == null) {
+            // Initialize RenderScript with default surface characteristics.
+            RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
+            //Create the RenderScript context
+            mRS = createRenderScriptGL(sc);
+            // Create an instance of the RenderScript entry point class
+            mRender = new HelloWorldRS();
+            // Call the entry point class to bind it to this context
+            mRender.init(mRS, getResources());
+        }
+    }
+
+    /**
+     * Rebind everything when the window becomes attached
+     */
+    protected void onAttachedToWindow() {
+        super.onAttachedToWindow();
+        initRS();
+    }
+
+    /**
+     * Stop rendering when window becomes detached
+     */
+    protected void onDetachedFromWindow() {
+        // Handle the system event and clean up
+        mRender = null;
+        if (mRS != null) {
+            mRS = null;
+            destroyRenderScriptGL();
+        }
+    }
+
+    /**
+     * Use callbacks to relay data to RenderScript entry point class
+     */
+    public boolean onTouchEvent(MotionEvent ev) {
+        // Pass touch events from the system to the rendering script
+        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
+            mRender.onActionDown((int)ev.getX(), (int)ev.getY());
+            return true;
+        }
+
+        return false;
+    }
+}
+
+</pre>
+
+  <h3>Creating the Activity</h3>
+
+  <p>Applications that use RenderScript still adhere to activity lifecyle, and are part of the same
+  view hierarchy as traditional Android applications, which is handled by the Android VM. This
+  Activity class sets its view to be the {@link android.renderscript.RSSurfaceView} and handles
+  lifecycle callback events appropriately. The following code shows how the <code>HelloWorld</code>
+  class is implemented:</p>
+  <pre>
+public class HelloWorldActivity extends Activity {
+
+    //Custom view to use with RenderScript
+    private HelloWorldView view;
+
+    public void onCreate(Bundle icicle) {
+        super.onCreate(icicle);
+        // Create surface view and set it as the content of our Activity
+        mView = new HelloWorldView(this);
+        setContentView(view);
+    }
+
+    protected void onResume() {
+        // Ideally an app should implement onResume() and onPause()
+        // to take appropriate action when the activity loses focus
+        super.onResume();
+        view.resume();
+    }
+
+    protected void onPause() {
+        // Ideally an app should implement onResume() and onPause()
+        // to take appropriate action when the activity loses focus
+        super.onPause();
+        view.pause();
+    }
+}
+</pre>
+
+  <h2>Drawing</h2>
+
+  <h3>Drawing using the rsgDraw functions</h3>
+
+  <p>The native RenderScript APIs provide a few convenient functions to easily draw a polygon to
+  the screen. You call these in your <code>root()</code> function to have them render to the
+  surface view. These functions are available for simple drawing and should not be used for complex
+  graphics rendering:</p>
+
+  <ul>
+    <li><code>rsgDrawRect()</code>: Sets up a mesh and draws a rectangle to the screen. It uses the
+    top left vertex and bottom right vertex of the rectangle to draw.</li>
+
+    <li><code>rsgDrawQuad()</code>: Sets up a mesh and draws a quadrilateral to the screen.</li>
+
+    <li><code>rsgDrawQuadTexCoords()</code>: Sets up a mesh and draws a textured quadrilateral to
+    the screen.</li>
+  </ul>
+
+  <h3>Drawing with a mesh</h3>
+
+  <p>When you want to draw complex shapes and textures to the screen, instantiate a {@link
+  android.renderscript.Mesh} and draw it to the screen with <code>rsgDrawMesh()</code>. A {@link
+  android.renderscript.Mesh} is a collection of allocations that represent vertex data (positions,
+  normals, texture coordinates) and index data such as triangles and lines. You can build a Mesh in
+  three different ways:</p>
+
+  <ul>
+    <li>Build the mesh with the {@link android.renderscript.Mesh.TriangleMeshBuilder} class, which
+    allows you to specify a set of vertices and indices for each triangle that you want to draw.
+    The downside of doing it this way is there is no way to specify the vertices in your native
+    RenderScript code.</li>
+
+    <li>Build the mesh using an {@link android.renderscript.Allocation} or a set of {@link
+    android.renderscript.Allocation}s with the {@link android.renderscript.Mesh.AllocationBuilder}
+    class. This allows you to build a mesh with vertices already stored in memory, which allows you
+    to set the vertices in native or Android code.</li>
+
+    <li>Build the mesh with the {@link android.renderscript.Mesh.Builder} class. This is a
+    convenience method for when you know what data types you want to use to build your mesh, but
+    don't want to make separate memory allocations like with {@link
+    android.renderscript.Mesh.AllocationBuilder}. You can specify the types that you want and this
+    mesh builder automatically creates the memory allocations for you.</li>
+  </ul>
+
+  <p>To create a mesh using the {@link android.renderscript.Mesh.TriangleMeshBuilder}, you need to
+  supply it with a set of vertices and the indices for the vertices that comprise the triangle. For
+  example, the following code specifies three vertices, which are added to an internal array,
+  indexed in the order they were added. The call to {@link
+  android.renderscript.Mesh.TriangleMeshBuilder#addTriangle addTriangle()} draws the triangle with
+  vertex 0, 1, and 2 (the vertices are drawn counter-clockwise).</p>
+  <pre>
+int float2VtxSize = 2;
+Mesh.TriangleMeshBuilder triangle = new Mesh.TriangleMeshBuilder(renderscriptGL,
+float2VtxSize, Mesh.TriangleMeshBuilder.COLOR);
+triangles.addVertex(300.f, 300.f);
+triangles.addVertex(150.f, 450.f);
+triangles.addVertex(450.f, 450.f);
+triangles.addTriangle(0 , 1, 2);
+Mesh smP = triangle.create(true);
+script.set_mesh(smP);
+</pre>
+
+  <p>To draw a mesh using the {@link android.renderscript.Mesh.AllocationBuilder}, you need to
+  supply it with one or more allocations that contain the vertex data:</p>
+  <pre>
+Allocation vertices;
+
+...
+Mesh.AllocationBuilder triangle = new Mesh.AllocationBuilder(mRS);
+smb.addVertexAllocation(vertices.getAllocation());
+smb.addIndexSetType(Mesh.Primitive.TRIANGLE);
+Mesh smP = smb.create();
+script.set_mesh(smP);
+</pre>
+
+  <p>In your native RenderScript code, draw the built mesh to the screen:</p>
+  <pre>
+rs_mesh mesh;
+...
+
+int root(){
+...
+rsgDrawMesh(mesh);
+...
+return 0; //specify a non zero, positive integer to specify the frame refresh.
+          //0 refreshes the frame only when the mesh changes.
+}
+</pre>
+
+  <h2 id="shaders">Shaders</h2>
+
+  <p>You can attach four program objects to the {@link android.renderscript.RenderScriptGL} context
+  to customize the rendering pipeline. For example, you can create vertex and fragment shaders in
+  GLSL or build a raster program object with provided methods without writing GLSL code. The four
+  program objects mirror a traditional graphical rendering pipeline:</p>
+
+  <table>
+    <tr>
+      <th>Android Object Type</th>
+
+      <th>RenderScript Native Type</th>
+
+      <th>Description</th>
+    </tr>
+
+    <tr>
+      <td>{@link android.renderscript.ProgramVertex}</td>
+
+      <td>rs_program_vertex</td>
+
+      <td>
+        <p>The RenderScript vertex program, also known as a vertex shader, describes the stage in
+        the graphics pipeline responsible for manipulating geometric data in a user-defined way.
+        The object is constructed by providing RenderScript with the following data:</p>
+
+        <ul>
+          <li>An Element describing its varying inputs or attributes</li>
+
+          <li>GLSL shader string that defines the body of the program</li>
+
+          <li>a Type that describes the layout of an Allocation containing constant or uniform
+          inputs</li>
+        </ul>
+
+        <p>Once the program is created, bind it to the {@link android.renderscript.RenderScriptGL}
+        graphics context by calling {@link android.renderscript.RenderScriptGL#bindProgramVertex
+        bindProgramVertex()}. It is then used for all subsequent draw calls until you bind a new
+        program. If the program has constant inputs, the user needs to bind an allocation
+        containing those inputs. The allocation's type must match the one provided during creation.
+        The RenderScript library then does all the necessary plumbing to send those constants to
+        the graphics hardware. Varying inputs to the shader, such as position, normal, and texture
+        coordinates are matched by name between the input Element and the Mesh object being drawn.
+        The signatures don't have to be exact or in any strict order. As long as the input name in
+        the shader matches a channel name and size available on the mesh, the run-time would take
+        care of connecting the two. Unlike OpenGL, there is no need to link the vertex and fragment
+        programs.</p>
+
+        <p>To bind shader constructs to the Program, declare a struct containing the necessary
+        shader constants in your native RenderScript code. This struct is generated into a
+        reflected class that you can use as a constant input element during the Program's creation.
+        It is an easy way to create an instance of this struct as an allocation. You would then
+        bind this Allocation to the Program and the RenderScript system sends the data that is
+        contained in the struct to the hardware when necessary. To update shader constants, you
+        change the values in the Allocation and notify the native RenderScript code of the
+        change.</p>
+      </td>
+    </tr>
+
+    <tr>
+      <td>{@link android.renderscript.ProgramFragment}</td>
+
+      <td>rs_program_fragment</td>
+
+      <td>
+        <p>The RenderScript fragment program, also known as the fragment shader, is responsible for
+        manipulating pixel data in a user-defined way. It's constructed from a GLSL shader string
+        containing the program body, textures inputs, and a Type object describing the constants
+        used by the program. Like the vertex programs, when an allocation with constant input
+        values is bound to the shader, its values are sent to the graphics program automatically.
+        Note that the values inside the allocation are not explicitly tracked. If they change
+        between two draw calls using the same program object, notify the runtime of that change by
+        calling rsgAllocationSyncAll so it could send the new values to hardware. Communication
+        between the vertex and fragment programs is handled internally in the GLSL code. For
+        example, if the fragment program is expecting a varying input called varTex0, the GLSL code
+        inside the program vertex must provide it.</p>
+
+        <p>To bind shader constants to this program, declare a struct containing the necessary
+        shader constants in your native RenderScript code. This struct is generated into a
+        reflected class that you can use as a constant input element during the Program's creation.
+        It is an easy way to create an instance of this struct as an allocation. You would then
+        bind this Allocation to the Program and the RenderScript system sends the data that is
+        contained in the struct to the hardware when necessary. To update shader constants, you
+        change the values in the Allocation and notify the native RenderScript code of the
+        change.</p>
+      </td>
+    </tr>
+
+    <tr>
+      <td>{@link android.renderscript.ProgramStore}</td>
+
+      <td>rs_program_store</td>
+
+      <td>The RenderScript ProgramStore contains a set of parameters that control how the graphics
+      hardware writes to the framebuffer. It could be used to enable and disable depth writes and
+      testing, setup various blending modes for effects like transparency and define write masks
+      for color components.</td>
+    </tr>
+
+    <tr>
+      <td>{@link android.renderscript.ProgramRaster}</td>
+
+      <td>rs_program_raster</td>
+
+      <td>Program raster is primarily used to specify whether point sprites are enabled and to
+      control the culling mode. By default back faces are culled.</td>
+    </tr>
+  </table>
+
+  <p>The following example defines a vertex shader in GLSL and binds it to the RenderScript:</p>
+  <pre>
+    private RenderScriptGL glRenderer;      //rendering context
+    private ScriptField_Point mPoints;      //vertices
+    private ScriptField_VpConsts mVpConsts; //shader constants
+
+    ...
+
+     ProgramVertex.Builder sb = new ProgramVertex.Builder(glRenderer);
+        String t =  "varying vec4 varColor;\n" +
+                    "void main() {\n" +
+                    "  vec4 pos = vec4(0.0, 0.0, 0.0, 1.0);\n" +
+                    "  pos.xy = ATTRIB_position;\n" +
+                    "  gl_Position = UNI_MVP * pos;\n" +
+                    "  varColor = vec4(1.0, 1.0, 1.0, 1.0);\n" +
+                    "  gl_PointSize = ATTRIB_size;\n" +
+                    "}\n";
+        sb.setShader(t);
+        sb.addConstant(mVpConsts.getType());
+        sb.addInput(mPoints.getElement());
+        ProgramVertex pvs = sb.create();
+        pvs.bindConstants(mVpConsts.getAllocation(), 0);
+        glRenderer.bindProgramVertex(pvs);
+
+
+</pre>
+
+  <p>The <a href=
+  "{@docRoot}resources/samples/RenderScript/MiscSamples/src/com/example/android/rs/miscsamples/RsRenderStatesRS.html">
+  RsRenderStatesRS</a> sample has many examples on how to create a shader without writing GLSL.</p>
+
+  <h3>Shader bindings</h3>
+
+  <p>You can also set four pragmas that control the shaders' default bindings to the {@link
+  android.renderscript.RenderScriptGL} context when the script is executing:</p>
+
+  <ul>
+    <li>stateVertex</li>
+
+    <li>stateFragment</li>
+
+    <li>stateRaster</li>
+
+    <li>stateStore</li>
+  </ul>
+
+  <p>The possible values for each pragma are <code>parent</code> or <code>default</code>. Using
+  <code>default</code> binds the shaders to the graphical context with the system defaults. The
+  default shader is defined below:</p>
+  <pre>
+("varying vec4 varColor;\n");
+("varying vec2 varTex0;\n");
+("void main() {\n");
+(" gl_Position = UNI_MVP * ATTRIB_position;\n");
+(" gl_PointSize = 1.0;\n");
+(" varColor = ATTRIB_color;\n");
+(" varTex0 = ATTRIB_texture0;\n");
+("}\n");
+</pre>
+
+  <p>Using <code>parent</code> binds the shaders in the same manner as it is bound in the calling
+  script. If this is the root script, the parent state is taken from the bind points that are set
+  by the {@link android.renderscript.RenderScriptGL} bind methods.</p>
+
+  <p>For example, you can define this at the top of your native graphics RenderScript code to have
+  the Vertex and Store shaders inherent the bind properties from their parent scripts:</p>
+  <pre>
+#pragma stateVertex(parent)
+#pragma stateStore(parent)
+</pre>
+
+  <h3>Defining a sampler</h3>
+
+  <p>A {@link android.renderscript.Sampler} object defines how data is extracted from textures.
+  Samplers are bound to Program objects (currently only a Fragment Program) alongside the texture
+  whose sampling they control. These objects are used to specify such things as edge clamping
+  behavior, whether mip-maps are used, and the amount of anisotropy required. There might be
+  situations where hardware does not support the desired behavior of the sampler. In these cases,
+  the runtime attempts to provide the closest possible approximation. For example, the user
+  requested 16x anisotropy, but only 8x was set because it's the best available on the
+  hardware.</p>
+
+  <p>The <a href=
+  "{@docRoot}resources/samples/RenderScript/MiscSamples/src/com/example/android/rs/miscsamples/RsRenderStatesRS.html">
+  RsRenderStatesRS</a> sample has many examples on how to create a sampler and bind it to a
+  Fragment program.</p>
+  
+</body>
+</html>
diff --git a/docs/html/guide/topics/renderscript/index.jd b/docs/html/guide/topics/renderscript/index.jd
new file mode 100644
index 0000000..eb77310
--- /dev/null
+++ b/docs/html/guide/topics/renderscript/index.jd
@@ -0,0 +1,640 @@
+page.title=RenderScript
+@jd:body
+
+  <div id="qv-wrapper">
+    <div id="qv">
+      <h2>In this document</h2>
+
+      <ol>
+        <li><a href="#overview">RenderScript System Overview</a></li>
+        <li>
+          <ol>
+            <li><a href="#native">Native RenderScript layer</a></li>
+
+            <li><a href="#reflected">Reflected layer</a></li>
+
+            <li><a href="#framework">Android framework layer</a></li>
+          </ol>
+        </li>
+
+        <li>
+          <a href="#mem-allocation">Memory Allocation APIs</a>
+        </li>
+        <li>
+          <a href="#dynamic">Dynamic Memory Allocations</a>
+          <ol>
+            <li><a href="#pointers">Declaring pointers</a></li>
+
+            <li><a href="#struct-pointer-reflection">How pointers are reflected</a></li>
+
+            <li><a href="#binding">Allocating and binding memory to the RenderScript</a></li>
+
+            <li><a href="#read-write-dynamic">Reading and writing to memory</a></li>
+
+          </ol>
+        </li>
+        <li>
+          <a href="#static">Static Memory Allocations</a>
+        </li>
+      </ol>
+    </div>
+  </div>
+
+  <p>RenderScript offers a high performance 3D graphics rendering and compute API at the native
+  level, which you write in the C (C99 standard). The main advantages of RenderScript are:</p>
+  <ul>
+    <li>Portability: RenderScript is designed to run on many types of devices with different CPU
+    and GPU architectures. It supports all of these architectures without having to target each
+    device, because the code is compiled and cached on the device at runtime.</li>
+
+    <li>Performance: RenderScript provides similar performance to OpenGL with the NDK while
+    offering the portability of the OpenGL APIs provided by the Android framework ({@link
+    android.opengl}). In addition, it also offers a high performance compute API that is not
+    offered by OpenGL.</li>
+
+    <li>Usability: RenderScript simplifies development when possible, such as eliminating JNI glue code
+    and simplifying mesh setup.</li>
+  </ul>
+
+  <p>The main disadvantages are:</p>
+
+  <ul>
+    <li>Development complexity: RenderScript introduces a new set of APIs that you have to learn.
+    RenderScript also handles memory differently compared to OpenGL with the Android framework APIs
+    or NDK.</li>
+
+    <li>Debugging visibility: RenderScript can potentially execute (planned feature for later releases)
+    on processors other than the main CPU (such as the GPU), so if this occurs, debugging becomes more difficult. 
+    </li>
+
+    <li>Less features: RenderScript does not provide as many features as OpenGL such as all the compressed
+    texture formats or GL extensions.</li>
+  </ul>
+
+  <p>You need to consider all of the aspects of RenderScript before deciding when to use it. The following list describes
+  general guidelines on when to use OpenGL (framework APIs or NDK) or RenderScript:</p>
+  <ul>
+    <li>If you are doing simple graphics rendering and performance is not critical, you probably want to use the
+  Android framework OpenGL APIs, which still provide adequate performance, to eliminate the added coding and debugging complexity of
+  RenderScript.</li>
+
+  <li>If you want the most flexibility and features while maintaining relatively good debugging
+  support, you probably want to use OpenGL and the NDK. Applications that require this are high end
+  or complicated games, for example.</li>
+ 
+  <li>If you want a solution that is portable, has good performance,
+  and you don't need the full feature set of OpenGL, RenderScript is a good solution. If you also
+  need a high performance compute language, then RenderScript offers that as well.
+  Good candidates for RenderScript are graphics intensive UIs that require 3D rendering, live wallpapers,
+  or applications that require intensive mathematical computation.</li>
+  </ul>
+
+  <p>For an example of RenderScript in action, install the RenderScript sample applications that
+  are shipped with the SDK in <code>&lt;sdk_root&gt;/samples/android-11/RenderScript</code>.
+  You can also see a typical use of RenderScript with the 3D carousel view in the Android 3.x
+  versions of Google Books and YouTube.</p>
+
+  <h2 id="overview">RenderScript System Overview</h2>
+
+  <p>The RenderScript system adopts a control and slave architecture where the low-level native
+  code is controlled by the higher level Android system that runs in a virtual machine (VM). The
+  Android VM still retains all control of memory and lifecycle management and calls the native
+  RenderScript code when necessary. The native code is compiled to intermediate bytecode (LLVM) and
+  packaged inside your application's <code>.apk</code> file. On the device, the bytecode is
+  compiled (just-in-time) to machine code that is further optimized for the device that it is
+  running on. The compiled code on the device is cached, so subsequent uses of the RenderScript
+  enabled application do not recompile the intermediate code. RenderScript has three layers of code
+  to enable communication between the native and Android framework code:</p>
+
+  <ul>
+    <li>The native RenderScript layer does the intensive computation or graphics rendering. You
+    define your native code in <code>.rs</code> and <code>.rsh</code> files.</li>
+
+    <li>The reflected layer is a set of classes that are reflected from the native code. It is basically
+    a wrapper around the native code that allows the Android framework to interact with native RenderScripts.
+    The Android build tools automatically generate the classes for this layer during
+    the build process and eliminates the need to write JNI glue code, like with the NDK.</li>
+
+    <li>The Android framework layer is comprised of the Android framework
+     APIs, which include the {@link android.renderscript} package. This layer gives high level commands
+     like, "rotate the view" or "filter the bitmap", by calling the reflected layer, which in turn calls
+     the native layer. </li>
+  </ul>
+
+  <h3 id="native">Native RenderScript layer</h3>
+
+  <p>The native RenderScript layer consists of your RenderScript code, which is compiled and
+  executed in a compact and well defined runtime. Your RenderScript code has access to a limited
+  amount of functions because it cannot access the NDK or standard C functions, since they must be guaranteed to
+  run on a standard CPU. The RenderScript runtime was designed to run on different types of processors,
+  which may not be the CPU, so it cannot guarantee support for standard C libraries. What
+  RenderScript does offer is an API that supports intensive computation and graphics rendering with a collection of math
+  and graphics APIs.</p>
+
+  <p>Some key features of the native RenderScript libraries include:</p>
+
+  <ul>
+    <li>A large collection of math functions with both scalar and vector typed overloaded versions
+    of many common routines. Operations such as adding, multiplying, dot product, and cross product
+    are available.</li>
+
+    <li>Conversion routines for primitive data types and vectors, matrix routines, date and time
+    routines, and graphics routines.</li>
+
+    <li>Logging functions</li>
+
+    <li>Graphics rendering functions</li>
+
+    <li>Memory allocation request features</li>
+
+    <li>Data types and structures to support the RenderScript system such as Vector types for
+    defining two-, three-, or four-vectors.</li>
+  </ul>
+
+  <p>The <a href="{@docRoot}guide/topics/renderscript/rs-api/files.html">RenderScript header files</a>
+  and LLVM front-end libraries are located in the <code>include</code> and
+  <code>clang-include</code> directories in the
+  <code>&lt;sdk_root&gt;/platforms/android-11/renderscript</code> directory of the Android SDK. The
+  headers are automatically included for you, except for the RenderScript graphics specific header file, which
+  you can include as follows:</p>
+  <pre>
+#include "rs_graphics.rsh"
+</pre>
+
+  <h3 id="reflected">Reflected layer</h3>
+
+  <p>The reflected layer is a set of classes that the Android build tools generate to allow access
+  to the native RenderScript code from the Android VM. This layer defines entry points for
+  RenderScript functions and variables, so that you can interact with them with the Android
+  framework. This layer also provides methods and constructors that allow you to allocate memory
+  for pointers that are defined in your RenderScript code. The following list describes the major
+  components that are reflected:</p>
+
+  <ul>
+    <li>Every <code>.rs</code> file that you create is generated into a class named
+    <code>ScriptC_<em>renderscript_filename</em></code> of type {@link
+    android.renderscript.ScriptC}. This is the <code>.java</code> version of your <code>.rs</code>
+    file, which you can call from the Android framework. This class contains the following
+    reflections:
+
+      <ul>
+        <li>Non-static functions in your <code>.rs</code> file.</li>
+
+        <li>Non-static, global RenderScript variables. Accessor methods are generated for each
+        variable, so you can read and write the natively declared variables from the Android
+        framework. The <code>get</code> method comes with a one-way communication restriction. The
+        last value that is set from the Android framework is always returned during a call to a
+        <code>get</code> method. If the native RenderScript code changes the value, the change does
+        not propagate back to the Android framework layer.
+        If the global variables are initialized
+        in the native RenderScript code, those values are used to initialize the corresponding
+        values in the Android framework layer. If global variables are marked as
+        <code>const</code>, then a <code>set</code> method is not generated.</li>
+        <li>Global pointers generate a special method named <code>bind_<em>pointer_name</em></code>
+        instead of a <code>set()</code> method. This method allows you to bind the memory that is
+        allocated in the Android VM for the pointer to the native RenderScript (you cannot allocate
+        memory in your <code>.rs</code> file). You can read and write to this memory from both the
+        Android framework and RenderScript code. For more information, see <a href="mem-mgmt">Working
+        with Memory and Data</a></li>
+      </ul>
+    </li>
+
+    <li>A <code>struct</code> is reflected into its own class named
+    <code>ScriptField_<em>struct_name</em></code>, which extends {@link
+    android.renderscript.Script.FieldBase}. This class represents an array of the
+    <code>struct</code>, which allows you to allocate memory for one or more instances of this
+    <code>struct</code>.</li>
+  </ul>
+
+  <h3 id="framework">Android framework layer</h3>
+
+  <p>The Android framework layer consists of the usual Android framework APIs, which include the
+    RenderScript APIs in {@link android.renderscript}. This layer handles things such as the
+    Activity lifecycle and memory management of your application. It issues high level commands to
+    the native RenderScript code through the reflected layer and receives events from the user such
+    as touch and input events and relays them to your RenderScript code, if needed.
+  </p>
+
+  <h2 id="mem-allocation">Memory Allocation APIs</h2>
+
+  <p>Before you begin writing your first RenderScript application, you must understand how 
+  memory is allocated for your RenderScript code and how data is shared between the native and VM
+  spaces. RenderScript allows you to access allocated memory in both the native layer
+  and Android system layer. All dynamic and static memory is allocated by the Android VM.
+  The Android VM also does reference counting and garbage collection for you. 
+  You can also explicitly free memory that you no longer need.</p>
+
+  <p class="note"><strong>Note:</strong> To declare temporary memory in your native RenderScript
+  code without allocating it in the Android VM, you can still do things like instantiate a scratch
+  buffer using an array.</p>
+
+  <p>The following classes support the memory management features of RenderScript in the Android
+  VM. You normally do not need to work with these classes directly, because the reflected layer
+  classes provide constructors and methods that set up the memory allocation for you. There are
+  some situations where you would want to use these classes directly to allocate memory on your
+  own, such as loading a bitmap from a resource or when you want to allocate memory for pointers to
+  primitive types.</p>
+
+  <table id="mem-mgmt-table">
+    <tr>
+      <th>Android Object Type</th>
+
+      <th>Description</th>
+    </tr>
+
+    <tr>
+      <td>{@link android.renderscript.Element}</td>
+
+      <td>
+        <p>An element represents one cell of a memory allocation and can have two forms: Basic or
+        Complex.</p>
+
+        <p>A basic element contains a single component of data of any valid RenderScript data type.
+        Examples of basic element data types include a single float value, a float4 vector, or a
+        single RGB-565 color.</p>
+
+        <p>Complex elements contain a list of basic elements and are created from
+        <code>struct</code>s that you declare in your RenderScript code. The most basic primitive
+        type determines the data alignment of the memory. For example, a float4 vector subelement
+        is alligned to <code>sizeof(float)</code> and not <code>sizeof(float4)</code>. The ordering
+        of the elements in memory are the order in which they were added, with each component
+        aligned as necessary.</p>
+      </td>
+    </tr>
+
+    <tr>
+      <td>{@link android.renderscript.Type}</td>
+
+      <td>
+        A type is a memory allocation template and consists of an element and one or more
+        dimensions. It describes the layout of the memory (basically an array of {@link
+        android.renderscript.Element}s) but does not allocate the memory for the data that it
+        describes.
+
+        <p>A type consists of five dimensions: X, Y, Z, LOD (level of detail), and Faces (of a cube
+        map). You can assign the X,Y,Z dimensions to any positive integer value within the
+        constraints of available memory. A single dimension allocation has an X dimension of
+        greater than zero while the Y and Z dimensions are zero to indicate not present. For
+        example, an allocation of x=10, y=1 is considered two dimensional and x=10, y=0 is
+        considered one dimensional. The LOD and Faces dimensions are booleans to indicate present
+        or not present.</p>
+      </td>
+    </tr>
+
+    <tr>
+      <td>{@link android.renderscript.Allocation}</td>
+
+      <td>
+        <p>An allocation provides the memory for applications based on a description of the memory
+        that is represented by a {@link android.renderscript.Type}. Allocated memory can exist in
+        many memory spaces concurrently. If memory is modified in one space, you must explicitly
+        synchronize the memory, so that it is updated in all the other spaces that it exists
+        in.</p>
+
+        <p>Allocation data is uploaded in one of two primary ways: type checked and type unchecked.
+        For simple arrays there are <code>copyFrom()</code> functions that take an array from the
+        Android system and copy it to the native layer memory store. The unchecked variants allow
+        the Android system to copy over arrays of structures because it does not support
+        structures. For example, if there is an allocation that is an array of n floats, the data
+        contained in a float[n] array or a byte[n*4] array can be copied.</p>
+      </td>
+    </tr>
+  </table>
+
+  <h2 id="dynamic">Working with dynamic memory allocations</h2>
+
+  <p>RenderScript has support for pointers, but you must allocate the memory in your Android framework
+  code. When you declare a global pointer in your <code>.rs</code> file, you allocate memory
+  through the appropriate reflected layer class and bind that memory to the native
+  RenderScript layer. You can read and write to this memory from the Android framework layer as well as the
+  RenderScript layer, which offers you the flexibility to modify variables in the most appropriate
+  layer. The following sections show you how to work with pointers, allocate memory for them, and
+  read and write to the memory.</p>
+
+  <h3 id="pointers">Declaring pointers</h3>
+
+  <p>Because RenderScript is written in C99, declaring a pointer is done in a familiar way. You can
+  declare pointers to a <code>struct</code> or a primitive type, but a <code>struct</code> cannot
+  contain pointers or nested arrays. The following code declares a <code>struct</code>, a pointer
+  to that <code>struct</code>, and a pointer of primitive type <code>int32_t</code> in an <code>.rs</code> file:</p>
+  <pre>
+#pragma version(1)
+#pragma rs java_package_name(com.example.renderscript)
+
+...
+
+typedef struct Point {
+      float2 point;
+  } Point_t;
+
+  Point_t *touchPoints;
+  int32_t *intPointer;
+
+...
+</pre>
+
+<p>You cannot allocate memory for these pointers in your RenderScript code, but the Android
+build tools generate classes for you that allow you to allocate memory in the Android VM for use by
+your RenderScript code. These classes also let you read and write to the memory. The next section
+describes how these classes are generated through reflection.</p>
+
+  <h3>How pointers are reflected</h3>
+
+  <p>Global variables have a getter and setter method generated. A global pointer generates a
+  <code>bind_pointerName()</code> method instead of a set() method. This method allows you to bind
+  the memory that is allocated in the Android VM to the native RenderScript. For example, the two
+  pointers in the previous section generate the following accessor methods in the <code>ScriptC_<em>rs_filename</em></code> file:</p>
+  <pre>
+
+    private ScriptField_Point mExportVar_touchPoints;
+    public void bind_touchPoints(ScriptField_Point v) {
+        mExportVar_touchPoints = v;
+        if (v == null) bindAllocation(null, mExportVarIdx_touchPoints);
+        else bindAllocation(v.getAllocation(), mExportVarIdx_touchPoints);
+    }
+
+    public ScriptField_Point get_touchPoints() {
+        return mExportVar_touchPoints;
+    }
+
+    private Allocation mExportVar_intPointer;
+    public void bind_intPointer(Allocation v) {
+        mExportVar_intPointer = v;
+        if (v == null) bindAllocation(null, mExportVarIdx_intPointer);
+        else bindAllocation(v, mExportVarIdx_intPointer);
+    }
+
+    public Allocation get_intPointer() {
+        return mExportVar_intPointer;
+    }
+
+</pre>
+
+  <h3>Allocating and binding memory to the RenderScript</h3>
+
+  <p>When the build tools generate the reflected layer, you can use the appropriate class
+  (<code>ScriptField_Point</code>, in our example) to allocate memory for a pointer. To do this,
+  you call the constructor for the {@link android.renderscript.Script.FieldBase} class and specify
+  the amount of structures that you want to allocate memory for. To allocate memory for a primitive
+  type pointer, you must build an allocation manually, using the memory management classes
+  described in <a href="mem-mgmt-table">Table 1</a>. The example below allocates memory for both
+  the <code>intPointer</code> and <code>touchPoints</code> pointer and binds it to the
+  RenderScript:</p>
+  <pre>
+private RenderScriptGL glRenderer;
+private ScriptC_example script;
+private Resources resources;
+
+public void init(RenderScriptGL rs, Resources res) {
+   //get the rendering context and resources from the calling method
+   glRenderer = rs; 
+   resources = res; 
+   
+   //allocate memory for the struct pointer, calling the constructor
+    ScriptField_Point touchPoints = new ScriptField_Point(glRenderer, 2); 
+    
+   //Create an element manually and allocate memory for the int pointer 
+    intPointer = Allocation.createSized(glRenderer, Element.I32(glRenderer), 2); 
+    
+    //create an instance of the RenderScript, pointing it to the bytecode resource
+    mScript = new ScriptC_example(glRenderer, resources, R.raw.example); 
+    
+    // bind the struct and int pointers to the RenderScript
+    mScript.bind_touchPoints(touchPoints); 
+    script.bind_intPointer(intPointer);
+    
+    //bind the RenderScript to the rendering context
+    glRenderer.bindRootScript(script);
+}
+</pre>
+
+  <h3>Reading and writing to memory</h3>
+
+  <p>Although you have to allocate memory within the Android VM, you can work with the memory both
+  in your native RenderScript code and in your Android code. Once memory is bound, the native
+  RenderScript can read and write to the memory directly. You can also just use the accessor
+  methods in the reflected classes to access the memory. If you modify memory in the Android
+  framework, it gets automatically synchronized to the native layer. If you modify memory in the <code>.rs</code>
+  file, these changes do not get propagated back to the Android framework.
+  For example, you can modify the struct in your Android code like this:</p>
+  <pre>
+int index = 0;
+boolean copyNow = true;
+Float2 point = new Float2(0.0f, 0.0f);
+touchPoints.set_point(index, point, copyNow);
+</pre>then read it in your native RenderScript code like this:
+  <pre>
+rsDebug("Printing out a Point", touchPoints[0].point.x, touchPoints[0].point.y);
+</pre>
+
+  <h2>Working with statically allocated memory</h2>
+
+  <p>Non-static, global primitives and structs that you declare in your RenderScript are easier to work with,
+  because the memory is statically allocated at compile time. Accessor methods to set and get these
+  variables are generated when the Android build tools generate the reflected layer classes. You
+  can get and set these variables using the provided accessor methods.
+ <p class="note"><strong>Note:</strong> The <code>get</code> method comes with a one-way communication restriction. The last value
+  that is set from the Android framework is always returned during a call to a <code>get</code>
+  method. If the native RenderScript code changes the value, the change does not propagate back to
+  the Android framework layer. If the global variables are initialized in the native RenderScript
+  code, those values are used to initialize the corresponding values in the Android framework
+  layer. If global variables are marked as <code>const</code>, then a <code>set</code> method is
+  not generated.</p>
+  </p>
+
+  <p>For example, if you declare the following primitive in your RenderScript code:</p>
+  <pre>
+  uint32_t unsignedInteger = 1;
+  
+</pre>
+<p>then the following code is generated in <code>ScriptC_<em>script_name</em>.java</code>:</p>
+  <pre>
+ private final static int mExportVarIdx_unsignedInteger = 9;
+    private long mExportVar_unsignedInteger;
+    public void set_unsignedInteger(long v) {
+        mExportVar_unsignedInteger = v;
+        setVar(mExportVarIdx_unsignedInteger, v);
+    }
+
+    public long get_unsignedInteger() {
+        return mExportVar_unsignedInteger;
+    }
+</pre>
+
+  <p class="note"><strong>Note:</strong> The mExportVarIdx_unsignedInteger variable represents the
+  index of the <code>unsignedInteger</code>'s in an array of statically allocated primitives. You do
+  not need to work with or be aware of this index.</p>
+  
+  <p>For a <code>struct</code>, the Android build tools generate a class named
+  <code>&lt;project_root&gt;/gen/com/example/renderscript/ScriptField_struct_name</code>. This
+  class represents an array of the <code>struct</code> and allows you to allocate memory for a
+  specified number of <code>struct</code>s. This class defines:</p>
+
+  <ul>
+    <li>Overloaded constructors that allow you to allocate memory. The
+    <code>ScriptField_<em>struct_name</em>(RenderScript rs, int count)</code> constructor allows
+    you to define the number of structures that you want to allocate memory for with the
+    <code>count</code> parameter. The <code>ScriptField_<em>struct_name</em>(RenderScript rs, int
+    count, int usages)</code> constructor defines an extra parameter, <code>usages</code>, that
+    lets you specify the memory space of this memory allocation. There are four memory space
+    possibilities:
+
+      <ul>
+        <li>{@link android.renderscript.Allocation#USAGE_SCRIPT}: Allocates in the script memory
+        space. This is the default memory space if you do not specify a memory space.</li>
+
+        <li>{@link android.renderscript.Allocation#USAGE_GRAPHICS_TEXTURE}: Allocates in the
+        texture memory space of the GPU.</li>
+
+        <li>{@link android.renderscript.Allocation#USAGE_GRAPHICS_VERTEX}: Allocates in the vertex
+        memory space of the GPU.</li>
+
+        <li>{@link android.renderscript.Allocation#USAGE_GRAPHICS_CONSTANTS}: Allocates in the
+        constants memory space of the GPU that is used by the various program objects.</li>
+      </ul>
+
+      <p>You can specify one or all of these memory spaces by OR'ing them together. Doing so notifies
+      the RenderScript runtime that you intend on accessing the data in the specified memory spaces. The following
+      example allocates memory for a custom data type in both the script and vertex memory spaces:</p>
+<pre>
+ScriptField_Point touchPoints = new ScriptField_Point(glRenderer, 2,
+Allocation.USAGE_SCRIPT | Allocation.USAGE_GRAPHICS_VERTEX);
+</pre>
+
+      <p>If you modify the memory in one memory space and want to push the updates to the rest of
+      the memory spaces, call <code>rsgAllocationSyncAll()</code> in your RenderScript code to
+      synchronize the memory.</p>
+    </li>
+
+    <li>A static nested class, <code>Item</code>, allows you to create an instance of the
+    <code>struct</code>, in the form of an object. This is useful if it makes more sense to work
+    with the <code>struct</code> in your Android code. When you are done manipulating the object,
+    you can push the object to the allocated memory by calling <code>set(Item i, int index, boolean
+    copyNow)</code> and setting the <code>Item</code> to the desired position in the array. The
+    native RenderScript code automatically has access to the newly written memory.
+
+    <li>Accessor methods to get and set the values of each field in a struct. Each of these
+    accessor methods have an <code>index</code> parameter to specify the <code>struct</code> in the
+    array that you want to read or write to. Each setter method also has a <code>copyNow</code>
+    parameter that specifies whether or not to immediately sync this memory to the native
+    RenderScript layer. To sync any memory that has not been synced, call <code>copyAll()</code>.</li>
+
+    <li>The createElement() method creates an object that describes the memory layout of the struct.</li>
+
+    <li>resize() works much like a <code>realloc</code>, allowing you to expand previously
+    allocated memory, maintaining the current values that were previously set.</li>
+
+    <li>copyAll() synchronizes memory that was set on the framework level to the native level. When you call
+    a set accessor method on a member, there is an optional <code>copyNow</code> boolean parameter that you can specify. Specifying
+    <code>true</code> synchronizes the memory when you call the method. If you specify false, you can call <code>copyAll()</code>
+    once, and it synchronizes memory for the all the properties that are not synchronized.</li>
+  </ul>
+
+  <p>The following example shows the reflected class, <code>ScriptField_Point.java</code> that is
+  generated from the Point <code>struct</code>.</p>
+  <pre>
+package com.example.renderscript;
+
+import android.renderscript.*;
+import android.content.res.Resources;
+
+
+public class ScriptField_Point extends android.renderscript.Script.FieldBase {
+    static public class Item {
+        public static final int sizeof = 8;
+
+        Float2 point;
+
+        Item() {
+            point = new Float2();
+        }
+
+    }
+
+    private Item mItemArray[];
+    private FieldPacker mIOBuffer;
+    public static Element createElement(RenderScript rs) {
+        Element.Builder eb = new Element.Builder(rs);
+        eb.add(Element.F32_2(rs), "point");
+        return eb.create();
+    }
+
+    public  ScriptField_Point(RenderScript rs, int count) {
+        mItemArray = null;
+        mIOBuffer = null;
+        mElement = createElement(rs);
+        init(rs, count);
+    }
+
+    public  ScriptField_Point(RenderScript rs, int count, int usages) {
+        mItemArray = null;
+        mIOBuffer = null;
+        mElement = createElement(rs);
+        init(rs, count, usages);
+    }
+
+    private void copyToArray(Item i, int index) {
+        if (mIOBuffer == null) mIOBuffer = new FieldPacker(Item.sizeof * getType().getX()/* count */);
+        mIOBuffer.reset(index * Item.sizeof);
+        mIOBuffer.addF32(i.point);
+    }
+
+    public void set(Item i, int index, boolean copyNow) {
+        if (mItemArray == null) mItemArray = new Item[getType().getX() /* count */];
+        mItemArray[index] = i;
+        if (copyNow)  {
+            copyToArray(i, index);
+            mAllocation.setFromFieldPacker(index, mIOBuffer);
+        }
+
+    }
+
+    public Item get(int index) {
+        if (mItemArray == null) return null;
+        return mItemArray[index];
+    }
+
+    public void set_point(int index, Float2 v, boolean copyNow) {
+        if (mIOBuffer == null) mIOBuffer = new FieldPacker(Item.sizeof * getType().getX()/* count */)fnati;
+        if (mItemArray == null) mItemArray = new Item[getType().getX() /* count */];
+        if (mItemArray[index] == null) mItemArray[index] = new Item();
+        mItemArray[index].point = v;
+        if (copyNow)  {
+            mIOBuffer.reset(index * Item.sizeof);
+            mIOBuffer.addF32(v);
+            FieldPacker fp = new FieldPacker(8);
+            fp.addF32(v);
+            mAllocation.setFromFieldPacker(index, 0, fp);
+        }
+
+    }
+
+    public Float2 get_point(int index) {
+        if (mItemArray == null) return null;
+        return mItemArray[index].point;
+    }
+
+    public void copyAll() {
+        for (int ct = 0; ct &lt; mItemArray.length; ct++) copyToArray(mItemArray[ct], ct);
+        mAllocation.setFromFieldPacker(0, mIOBuffer);
+    }
+
+    public void resize(int newSize) {
+        if (mItemArray != null)  {
+            int oldSize = mItemArray.length;
+            int copySize = Math.min(oldSize, newSize);
+            if (newSize == oldSize) return;
+            Item ni[] = new Item[newSize];
+            System.arraycopy(mItemArray, 0, ni, 0, copySize);
+            mItemArray = ni;
+        }
+
+        mAllocation.resize(newSize);
+        if (mIOBuffer != null) mIOBuffer = new FieldPacker(Item.sizeof * getType().getX()/* count */);
+    }
+
+}
+</pre>
+
+</body>
+</html>
diff --git a/docs/html/guide/topics/resources/animation-resource.jd b/docs/html/guide/topics/resources/animation-resource.jd
index 972dd72..3df669c 100644
--- a/docs/html/guide/topics/resources/animation-resource.jd
+++ b/docs/html/guide/topics/resources/animation-resource.jd
@@ -5,28 +5,348 @@
 
 <div id="qv-wrapper">
   <div id="qv">
+   <h2>In this document</h2>
+    <ol>
+      <li><a href="#Property">Property Animation</a></li>
+      <li><a href="#View">View Animation</a>
+        <ol>
+          <li><a href="Tween">Tween animation</li>
+          <li><a href="Frame">Frame animation</li>
+        </ol>      
+      </li>
+    </ol>
     <h2>See also</h2>
     <ol>
-      <li><a href="{@docRoot}guide/topics/graphics/2d-graphics.html#tween-animation">2D
-Graphics</a></li>
+      <li><a href="{@docRoot}guide/topics/graphics/view-animation.html">View Animation</a></li>
+      <li><a href="{@docRoot}guide/topics/graphics/animation.html">Property Animation</a></li>
     </ol>
   </div>
 </div>
 
 
 <p>An animation resource can define one of two types of animations:</p>
+
 <dl>
-  <dt><a href="#Tween">Tween Animation</a></dt>
-  <dd>Creates an animation by performing a series of transformations on a single image.
-    An {@link android.view.animation.Animation}.</dd>
-  <dt><a href="#Frame">Frame Animation</a></dt>
-  <dd>Creates an animation by showing a sequence of images in order.
-    An {@link android.graphics.drawable.AnimationDrawable}.</dd>
+  <dt><a href="#Property">Property Animation</a></dt>
+  <dd>Creates an animation by modifying an object's property values over a set period
+  of time with an {@link android.animation.Animator}.</dd>
+  <dt><a href="#View">View Animation</a></dt>
+  <dd>
+  <p>There are two types of animations that you can do with the view animation framework:</p>
+  <ul>
+    <li><a href="#Tween">Tween animation</a>: Creates an animation by performing a series of transformations on a single image
+    with an {@link android.view.animation.Animation}</li>
+    <li><a href="#Frame">Frame animation</a>: or creates an animation by showing a sequence of images in order
+    with an {@link android.graphics.drawable.AnimationDrawable}.</li>
+  </ul>
+  </dd>
 </dl>
 
 
+<h2 id="Property">Property Animation</h2>
+<p>An animation defined in XML that modifies properties of the target object, such as
+background color or alpha value, over a set amount of time.</p>
 
-<h2 id="Tween">Tween Animation</h2>
+<dl class="xml">
+
+<dt>file location:</dt>
+<dd><code>res/animator/<em>filename</em>.xml</code><br/>
+The filename will be used as the resource ID.</dd>
+
+<dt>compiled resource datatype:</dt>
+<dd>Resource pointer to a {@link android.animation.ValueAnimator}, {@link android.animation.ObjectAnimator},
+or {@link android.animation.AnimatorSet}.</dd>
+
+<dt>resource reference:</dt>
+<dd>
+In Java: <code>R.animator.<em>filename</em></code><br/>
+In XML: <code>@[<em>package</em>:]animator/<em>filename</em></code>
+</dd>
+
+<dt>syntax:</dt>
+<dd>
+<pre class="stx">
+&lt;<a href="#animator-set-element">set</a>
+  android:ordering=["together" | "sequentially"]&gt;
+
+    &lt;<a href="#obj-animator-element">objectAnimator</a>
+        android:propertyName="<em>string</em>"
+        android:duration="<em>int</em>"
+        android:valueFrom="<em>float</em> | <em>int</em> | <em>color</em>"
+        android:valueTo="<em>float</em> | <em>int</em> | <em>color</em>"
+        android:startOffset="<em>int</em>"
+        android:repeatCount="<em>int</em>"
+        android:repeatMode=["repeat" | "reverse"]
+        android:valueType=["intType" | "floatType"]/&gt;
+
+    &lt;<a href="#val-animator-element">animator</a>
+        android:duration="<em>int</em>"
+        android:valueFrom="<em>float</em> | <em>int</em> | <em>color</em>"
+        android:valueTo="<em>float</em> | <em>int</em> | <em>color</em>"
+        android:startOffset="<em>int</em>"
+        android:repeatCount="<em>int</em>"
+        android:repeatMode=["repeat" | "reverse"]
+        android:valueType=["intType" | "floatType"]/&gt;
+
+    &lt;<a href="#animator-set-element">set</a>&gt;
+        ...
+    &lt;/set&gt;
+&lt;/set&gt;
+</pre>
+
+<p>The file must have a single root element: either 
+<code>&lt;set&gt;</code>, <code>&lt;objectAnimator&gt;</code>, or <code>&lt;valueAnimator&gt;</code>. You can
+group animation elements together inside the <code>&lt;set&gt;</code> element, including other
+<code>&lt;set&gt;</code> elements.
+</p>
+</dd>
+
+<dt>elements:</dt>
+  <dd>
+  <dl class="tag-list">
+    <dt id="animator-set-element"><code>&lt;set&gt;</code></dt>
+    <dd>A container that holds other animation elements (<code>&lt;objectAnimator&gt;</code>,
+    <code>&lt;valueAnimator&gt;</code>, or other <code>&lt;set&gt;</code> elements).  Represents
+    an {@link android.animation.AnimatorSet}.
+    <p>You can specify nested <code>&lt;set&gt;</code> tags to further
+    group animations together. Each <code>&lt;set&gt;</code> can define its own 
+    <code>ordering</code> attribute.</p>
+
+      <p class="caps">attributes:</p>
+      <dl class="atn-list">
+        <dt>
+          <code>android:ordering</code>
+        </dt>
+        <dd>
+          <em>Keyword</em>. Specifies the play ordering of animations in this set.
+          <table> 
+            <tr><th>Value</th><th>Description</th></tr> 
+            <tr><td><code>sequentially</code></td><td>Play animations in this set sequentially</td></tr> 
+            <tr><td><code>together</code> (default)</td><td>Play animations in this set at the same time.</td></tr> 
+          </table> 
+        </dd>
+      </dl>
+    </dd>
+
+  <dt id="obj-animator-element"><code>&lt;objectAnimator&gt;</code></dt>
+    <dd>Animates a specific property of an object over a specific amount of time. Represents
+    an {@link android.animation.ObjectAnimator}.</p>
+    
+      <p class="caps">attributes:</p>
+      <dl class="atn-list">
+        <dt>
+          <code>android:propertyName</code> 
+        </dt>
+        <dd>
+          <em>String</em>. <strong>Required</strong>. The object's property to animate, referenced by its name. For example you can specify
+          <code>"alpha"</code> or <code>"backgroundColor"</code> for a View object.
+          The <code>objectAnimator</code> element does not expose a <code>target</code>
+          attribute, however, so you cannot set the object to animate in the XML declaration. You have to
+          inflate your animation XML resource by calling {@link android.animation.AnimatorInflater#loadAnimator
+          loadAnimator()} and call {@link android.animation.ObjectAnimator#setTarget setTarget()} to set
+          the target object that contains this property.
+        </dd>
+
+        <dt>
+          <code>android:valueTo</code>
+        </dt>
+        <dd>
+          <em>float, int, or color</em>. <strong>Required</strong>. The value where the animated property ends. Colors are represented
+          as six digit hexadecimal numbers (for example, #333333).
+        </dd>
+
+        <dt>
+          <code>android:valueFrom</code>
+        </dt>
+        <dd>
+          <em>float, int, or color</em>. The value where the animated property starts. If not
+          specified, the animation starts at the value obtained by the property's get method. Colors are represented
+          as six digit hexadecimal numbers (for example, #333333).
+        </dd>
+
+        <dt>
+          <code>android:duration</code>
+        </dt>
+        <dd>
+          <em>int</em>. The time in milliseconds of the animation. 300 milliseconds is the default.
+        </dd>
+
+        <dt>
+          <code>android:startOffset</code>
+        </dt>
+        <dd>
+          <em>int</em>. The amount of milliseconds the animation delays after
+          {@link android.animation.ObjectAnimator#start start()} is called.
+        </dd>
+
+        <dt>
+          <code>android:repeatCount</code>
+        </dt>
+        <dd>
+          <em>int</em>. How many times to repeat an animation. Set to <code>"-1"</code> to infinitely
+          repeat or to a positive integer. For example, a value of <code>"1"</code> means that the animation
+          is repeated once after the initial run of the animation, so the animation plays a total
+          of two times. The default value is <code>"0"</code>, which means no repetition.
+
+        </dd>
+
+        <dt>
+          <code>android:repeatMode</code>
+        </dt>
+        <dd>
+          <em>int</em>. How an animation behaves when it reaches the end of the animation. <code>android:repeatCount</code>
+          must be set to a positive integer or <code>"-1"</code> for this attribute to have an effect. Set to <code>"reverse"</code>
+          to have the animation reverse direction with each iteration or <code>"repeat"</code> to have the animation
+          loop from the beginning each time.
+        </dd>
+
+        <dt>
+          <code>android:valueType</code>
+        </dt>
+        <dd>
+          <em>Keyword</em>. Do not specify this attribute if the value is a color. The animation framework automatically handles color
+          values
+          <table> 
+            <tr><th>Value</th><th>Description</th></tr> 
+            <tr><td><code>intType</code></td><td>Specifies that the animated values are integers</td></tr> 
+            <tr><td><code>floatType</code> (default)</td><td>Specifies that the animated values are floats</td></tr> 
+          </table> 
+        </dd>
+
+      </dl>
+    </dd>
+
+<dt id="val-animator-element"><code>&lt;animator&gt;</code></dt>
+    <dd>Animates a over a specified amount of time.
+    Represents a {@link android.animation.ValueAnimator}.
+
+      <p class="caps">attributes:</p>
+      <dl class="atn-list">
+        <dt>
+          <code>android:valueTo</code>
+        </dt>
+        <dd>
+          <em>float, int, or color</em>. <strong>Required</strong>. The value where the animation ends. Colors are represented
+          as six digit hexadecimal numbers (for example, #333333).
+        </dd>
+
+        <dt>
+          <code>android:valueFrom</code>
+        </dt>
+        <dd>
+          <em>float, int, or color</em>. <strong>Required</strong>. The value where the animation starts. Colors are represented
+          as six digit hexadecimal numbers (for example, #333333).
+        </dd>
+
+        <dt>
+          <code>android:duration</code>
+        </dt>
+        <dd>
+          <em>int</em>. The time in milliseconds of the animation. 300ms is the default.
+        </dd>
+
+        <dt>
+          <code>android:startOffset</code>
+        </dt>
+        <dd>
+          <em>int</em>. The amount of milliseconds the animation delays after
+          {@link android.animation.ValueAnimator#start start()} is called.
+        </dd>
+
+        <dt>
+          <code>android:repeatCount</code>
+        </dt>
+        <dd>
+          <em>int</em>. How many times to repeat an animation. Set to <code>"-1"</code> to infinitely
+          repeat or to a positive integer. For example, a value of <code>"1"</code> means that the animation
+          is repeated once after the initial run of the animation, so the animation plays a total
+          of two times. The default value is <code>"0"</code>, which means no repetition.
+        </dd>
+
+        <dt>
+          <code>android:repeatMode</code>
+        </dt>
+        <dd>
+          <em>int</em>. How an animation behaves when it reaches the end of the animation. <code>android:repeatCount</code>
+          must be set to a positive integer or <code>"-1"</code> for this attribute to have an effect. Set to <code>"reverse"</code>
+          to have the animation reverse direction with each iteration or <code>"repeat"</code> to have the animation
+          loop from the beginning each time.
+        </dd>
+
+        <dt>
+          <code>android:valueType</code>
+        </dt>
+        <dd>
+          <em>Keyword</em>. Do not specify this attribute if the value is a color. The animation framework automatically handles color
+          values.
+          <table> 
+            <tr><th>Value</th><th>Description</th></tr> 
+            <tr><td><code>intType</code></td><td>Specifies that the animated values are integers</td></tr> 
+            <tr><td><code>floatType</code> (default)</td><td>Specifies that the animated values are floats</td></tr> 
+          </table> 
+        </dd>
+
+      </dl>
+    </dd>
+  </dl>
+
+</dd> <!-- end  elements and attributes -->
+
+<dt>example:</dt>
+<dd>
+  <pp>XML file saved at <code>res/animator/property_animator.xml</code>:</p>
+<pre>
+&lt;set android:ordering="sequentially"&gt;
+    &lt;set&gt;
+        &lt;objectAnimator
+            android:propertyName="x"
+            android:duration="500"
+            android:valueTo="400"
+            android:valueType="intType"/&gt;
+        &lt;objectAnimator
+            android:propertyName="y"
+            android:duration="500"
+            android:valueTo="300"
+            android:valueType="intType"/&gt;
+    &lt;/set&gt;
+    &lt;objectAnimator
+        android:propertyName="alpha"
+        android:duration="500"
+        android:valueTo="1f"/&gt;
+&lt;/set&gt;
+</pre>
+  <p>In order to run this animation, you must inflate the XML resources in your code to an {@link
+  android.animation.AnimatorSet} object, and then set the target objects for all of the animations
+  before starting the animation set. Calling {@link android.animation.AnimatorSet#setTarget
+  setTarget()} sets a single target object for all children of the {@link
+  android.animation.AnimatorSet} as a convenience. The following code shows how to do this:</p>
+  
+<pre>
+AnimatorSet set = (AnimatorSet) AnimatorInflater.loadAnimator(myContext,
+    R.anim.property_animator);
+set.setTarget(myObject);
+set.start();
+</pre>
+
+
+</dd> <!-- end example -->
+
+<dt>see also:</dt>
+<dd>
+<ul>
+  <li><a href="{@docRoot}guide/topics/graphics/animation.html">Property Animation</a></li>
+  <li><a href="http://zoso:8080/resources/samples/ApiDemos/src/com/example/android/apis/animation/index.html">API Demos</a> for examples
+  on how to use the property animation system.</li>
+</ul>
+</dd>
+
+</dl>
+
+<h2 id="View">View Animation</h2>
+The view animation framework supports both tween and frame by frame animations, which can both be declared
+in XML. The following sections describe how to use both methods.
+
+<h3 id="Tween">Tween animation</h3>
 
 <p>An animation defined in XML that performs transitions such as rotating,
 fading, moving, and stretching on a graphic.
@@ -254,18 +574,14 @@
 <dt>see also:</dt>
 <dd>
 <ul>
-  <li><a href="{@docRoot}guide/topics/graphics/2d-graphics.html#tween-animation">2D
+  <li><a href="{@docRoot}guide/topics/graphics/view-animation.html#tween-animation">2D
 Graphics: Tween Animation</a></li>
 </ul>
 </dd>
 
 </dl>
 
-
-
-
-
-<h3 id="Interpolators">Interpolators</h3>
+<h4 id="Interpolators">Interpolators</h4>
 
 <p>An interpolator is an animation modifier defined in XML that affects the rate of change in an
 animation. This allows your existing animation effects to be accelerated, decelerated, repeated,
@@ -456,22 +772,7 @@
 </dl>
 
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-<h2 id="Frame">Frame Animation</h2>
+<h3 id="Frame">Frame animation</h3>
 
 <p>An animation defined in XML that shows a sequence of images in order (like a film).
 </p>
@@ -562,7 +863,11 @@
   </dl>
 </dd> <!-- end example -->
 
+<dt>see also:</dt>
+<dd>
+<ul>
+  <li><a href="{@docRoot}guide/topics/graphics/view-animation.html#frame-animation">2D
+Graphics: Frame Animation</a></li>
+</ul>
+</dd>
 </dl>
-
-
-
diff --git a/docs/html/guide/topics/resources/providing-resources.jd b/docs/html/guide/topics/resources/providing-resources.jd
index 32595a0..a996ccc 100644
--- a/docs/html/guide/topics/resources/providing-resources.jd
+++ b/docs/html/guide/topics/resources/providing-resources.jd
@@ -88,9 +88,18 @@
   </tr>
 
   <tr>
+    <td><code>animator/</code></td>
+    <td>XML files that define <a href="{@docRoot}guide/topics/graphics/animation.html">property
+animations</a>.</td>
+  </tr>
+
+  <tr>
     <td><code>anim/</code></td>
-    <td>XML files that define tween animations. See <a
-href="animation-resource.html">Animation Resources</a>.</td>
+    <td>XML files that define <a
+href="{@docRoot}guide/topics/graphics/view-animation.html#tween-animation">tween
+animations</a>. (Property animations can also be saved in this directory, but
+the {@code animator/} directory is preferred for property animations to distinguish between the two
+types.)</td>
   </tr>
 
   <tr>
@@ -324,6 +333,86 @@
 indicates the current locale.</p>
       </td>
     </tr>
+    <tr id="SmallestScreenWidthQualifier">
+      <td>Smallest screen width</td>
+      <td>Examples:<br/>
+        <code>sw320dp</code><br/>
+        <code>sw600dp</code><br/>
+        <code>sw720dp</code><br/>
+        etc.
+      </td>
+      <td>
+        <p>Specifies a minimum "smallest screen width," in "dp" units, at which the resource
+          should be used.  This configuration value represents the base screen size
+          of the device, regardless of the orientation of the display.  It is based
+          on the smallest width the application will have in which to perform its
+          UI layout (in dp units) regardless of the orientation of the screen.  The
+          value here takes into account screen decorations so if the device has some
+          persistent UI elements on the left or right edge of the display it must
+          present a value here that is smaller than the real screen size, accounting
+          for these UI elements reducing the application's available space.</p>
+        <p>Some values you may use here for common screen sizes:</p>
+        <ul>
+          <li>240x320 ldpi (QVGA phone): 320
+          <li>320x480 mdpi (phone): 320
+          <li>480x800 hdpi (high density phone): 320
+          <li>480x800 mdpi (tablet/phone): 480
+          <li>600x1024 mdpi (7" tablet): 600
+          <li>720x1280 mdpi (10" tablet): 720
+        </ul>
+        <p><em>Added in API Level 13.</em></p>
+        <p>Also see the {@link android.content.res.Configuration#smallestScreenWidthDp}
+          configuration field, which holds the current smallest screen width.</p>
+      </td>
+    </tr>
+    <tr id="ScreenWidthQualifier">
+      <td>Screen width</td>
+      <td>Examples:<br/>
+        <code>w720dp</code><br/>
+        <code>w1024dp</code><br/>
+        etc.
+      </td>
+      <td>
+        <p>Specifies a minimum screen width, in "dp" units, at which the resource
+          should be used.  This configuration value will change when the orientation
+          changes between landscape and portrait to match the current actual width.
+          When multiple screen width configurations are available, the closest to
+          the current screen width will be used.  The
+          value here takes into account screen decorations so if the device has some
+          persistent UI elements on the left or right edge of the display it must
+          present a value here that is smaller than the real screen size, accounting
+          for these UI elements reducing the application's available space.</p>
+        <p><em>Added in API Level 13.</em></p>
+        <p>Also see the {@link android.content.res.Configuration#screenWidthDp}
+          configuration field, which holds the current screen width.</p>
+      </td>
+    </tr>
+    <tr id="ScreenHeightQualifier">
+      <td>Screen height</td>
+      <td>Examples:<br/>
+        <code>h720dp</code><br/>
+        <code>h1024dp</code><br/>
+        etc.
+      </td>
+      <td>
+        <p>Specifies a minimum screen height, in "dp" units, at which the resource
+          should be used.  This configuration value will change when the orientation
+          changes between landscape and portrait to match the current actual height.
+          When multiple screen height configurations are available, the closest to
+          the current screen height will be used.  The
+          value here takes into account screen decorations so if the device has some
+          persistent UI elements on the left or right edge of the display it must
+          present a value here that is smaller than the real screen size, accounting
+          for these UI elements reducing the application's available space.  Screen
+          decorations that are not fixed (such as a phone status bar that can be
+          hidden when full screen) are <em>not</em> accounted for here, nor are
+          window decorations like title bar, so applications must be prepared to
+          deal with a somewhat smaller space than they specify.
+        <p><em>Added in API Level 13.</em></p>
+        <p>Also see the {@link android.content.res.Configuration#screenHeightDp}
+          configuration field, which holds the current screen width.</p>
+      </td>
+    </tr>
     <tr id="ScreenSizeQualifier">
       <td>Screen size</td>
       <td>
@@ -383,46 +472,6 @@
 which indicates whether the screen is long.</p>
       </td>
     </tr>
-    <tr id="ScreenWidthQualifier">
-      <td>Screen width</td>
-      <td>Examples:<br/>
-        <code>w720dp</code><br/>
-        <code>w1024dp</code><br/>
-        etc.
-      </td>
-      <td>
-        <p>Specifies a minimum screen width, in "dp" units, at which the resource
-          should be used.  This configuration value will change when the orientation
-          changes between landscape and portrait to match the current actual width.
-          When multiple screen width configurations are available, the closest to
-          the current screen width will be used.  The value specified here is
-          approximate; screen decorations like a status bar or system bar may cause
-          the actual space available in your UI to be slightly smaller.
-        <p><em>Added in API Level 13.</em></p>
-        <p>Also see the {@link android.content.res.Configuration#screenWidthDp}
-          configuration field, which holds the current screen width.</p>
-      </td>
-    </tr>
-    <tr id="ScreenHeightQualifier">
-      <td>Screen height</td>
-      <td>Examples:<br/>
-        <code>h720dp</code><br/>
-        <code>h1024dp</code><br/>
-        etc.
-      </td>
-      <td>
-        <p>Specifies a minimum screen height, in "dp" units, at which the resource
-          should be used.  This configuration value will change when the orientation
-          changes between landscape and portrait to match the current actual height.
-          When multiple screen height configurations are available, the closest to
-          the current screen height will be used.  The value specified here is
-          approximate; screen decorations like a status bar or system bar may cause
-          the actual space available in your UI to be slightly smaller.
-        <p><em>Added in API Level 13.</em></p>
-        <p>Also see the {@link android.content.res.Configuration#screenHeightDp}
-          configuration field, which holds the current screen width.</p>
-      </td>
-    </tr>
     <tr id="OrientationQualifier">
       <td>Screen orientation</td>
       <td>
diff --git a/docs/html/guide/topics/ui/actionbar.jd b/docs/html/guide/topics/ui/actionbar.jd
index 7e13569..6f12b95 100644
--- a/docs/html/guide/topics/ui/actionbar.jd
+++ b/docs/html/guide/topics/ui/actionbar.jd
@@ -184,7 +184,7 @@
 <pre>
 &lt;?xml version="1.0" encoding="utf-8"?&gt;
 &lt;menu xmlns:android="http://schemas.android.com/apk/res/android">
-    &lt;item android:id="@+id/menu_add"
+    &lt;item android:id="@+id/menu_save"
           android:icon="@drawable/ic_menu_save"
           android:title="@string/menu_save"
           <b>android:showAsAction="ifRoom|withText"</b> /&gt;
diff --git a/docs/html/guide/topics/usb/adk.jd b/docs/html/guide/topics/usb/adk.jd
index 8aaa65c..e4e1215 100644
--- a/docs/html/guide/topics/usb/adk.jd
+++ b/docs/html/guide/topics/usb/adk.jd
@@ -24,8 +24,7 @@
         </li>
 
         <li>
-          <a href="#how">How an Accessory Communicates with an Android-powered Device in Accessory
-          Mode</a>
+          <a href="#accessory-protocol">Implementing the Android Accessory Protocol</a>
 
           <ol>
             <li><a href="#wait">Wait for and detect connected devices</a></li>
@@ -40,8 +39,7 @@
         </li>
 
         <li>
-          <a href="#firmware">How the ADK board communicates with an Android-powered Device in
-          Accessory Mode</a>
+          <a href="#firmware">How the ADK board implements the Android Accessory Protocol</a>
 
           <ol>
             <li><a href="#wait-adk">Wait for and detect connected devices</a></li>
@@ -56,7 +54,7 @@
         </li>
       </ol>
 
-      
+
 
       <h2>See also</h2>
 
@@ -64,7 +62,7 @@
         <li><a href="http://www.youtube.com/watch?v=s7szcpXf2rE">Google I/O Session Video</a></li>
         <li><a href="{@docRoot}guide/topics/usb/accessory.html">USB Accessory Dev Guide</a></li>
       </ol>
-      
+
       <h2>Where to buy</h2>
 
       <ol>
@@ -78,6 +76,9 @@
 
         <li><a href="https://store.diydrones.com/ProductDetails.asp?ProductCode=BR-PhoneDrone">
         DIY Drones</a></li>
+
+    <li><a href="http://shop.moderndevice.com/products/freeduino-usb-host-board">
+        Modern Device</a></li>
       </ol>
     </div>
   </div>
@@ -86,7 +87,7 @@
   support, which allows external USB hardware (an Android USB accessory) to interact with an
   Android-powered device in a special "accessory" mode. When an Android-powered powered device is
   in accessory mode, the connected accessory acts as the USB host (powers the bus and enumerates
-  devices) and the Android-powered device acts as the device. Android USB accessories are
+  devices) and the Android-powered device acts as the USB device. Android USB accessories are
   specifically designed to attach to Android-powered devices and adhere to a simple protocol
   (Android accessory protocol) that allows them to detect Android-powered devices that support
   accessory mode. Accessories must also provide 500mA at 5V for charging power. Many previously
@@ -112,6 +113,8 @@
     <li><a href="https://store.diydrones.com/ProductDetails.asp?ProductCode=BR-PhoneDrone">DIY
     Drones</a> provides an Arduino-compatible board geared towards RC (radio controlled) and UAV
     (unmanned aerial vehicle) enthusiasts.</li>
+    <li><a href="http://shop.moderndevice.com/products/freeduino-usb-host-board">Modern
+        Device</a> provides an Arduino-compatible board that supports the ADK firmware.</li>
   </ul>
 
   <p>We expect more hardware distributers to create a variety of kits, so please stay tuned for
@@ -380,14 +383,11 @@
   accessories communicate with Android-powered devices describe much of what you should be doing in
   your own accessory.</p>
 
-  <h2 id="how">How an Accessory Communicates with an Android-powered Device in Accessory Mode</h2>
+  <h2 id="accessory-protocol">Implementing the Android Accessory Protocol</h2>
 
-  <p>When you connect an accessory to an Android-powered device, the accessory's firmware must
-  carry out some standard steps to set up communication with the Android-powered device. If you are
-  building an accessory along with an application, this section goes over some general steps that
-  your firmware should carry out.</p>
-
-  <p>In general, an accessory should carry out the following steps:</p>
+  <p>An Android USB accessory must adhere to Android Accessory Protocol, which defines how
+  an accessory detects and sets up communication with an Android-powered device. In general, an
+  accessory should carry out the following steps:</p>
 
   <ol>
     <li>Wait for and detect connected devices</li>
@@ -399,6 +399,8 @@
     <li>Establish communication with the device if it supports the Android accessory protocol</li>
   </ol>
 
+  <p>The following sections go into depth about how to implement these steps.</p>
+
   <h3 id="wait">Wait for and detect connected devices</h3>
 
   <p>Your accessory should have logic to continuously check
@@ -476,12 +478,12 @@
       <p>The following string IDs are supported, with a maximum size of 256 bytes for each string
       (must be zero terminated with \0).</p>
       <pre>
-manufacturer name:  1
-model name:         2
-description:        3
-version:            4
-URI:                5
-serial number:      6
+manufacturer name:  0
+model name:         1
+description:        2
+version:            3
+URI:                4
+serial number:      5
 </pre>
     </li>
 
@@ -520,12 +522,11 @@
   device's configuration to a value of 1 with a SET_CONFIGURATION (0x09) device request, then
   communicate using the endpoints.</p>
 
-  <h2 id="firmware">How the ADK board communicates with an Android-powered Device in Accessory
-  Mode</h2>
+  <h2 id="firmware">How the ADK board implements the Android Accessory protocol</h2>
 
   <p>If you have access to the ADK board and shield, the following sections describe the firmware
   code that you installed onto the ADK board. The firmware demonstrates a practical example of how
-  to communicate with an Android-powered device. Even if you do not have the ADK board and shield,
+  to implement the Android Accessory protocol. Even if you do not have the ADK board and shield,
   reading through how the hardware detects and interacts with devices in accessory mode is still
   useful if you want to port the code over for your own accessories.</p>
 
@@ -540,8 +541,7 @@
   sections.</p>
 
   <p>The following sections describe the firmware code in the context of the algorithm described in
-  <a href="#how">How an Accessory Communicates with an Android-powered Device in Accessory
-  Mode</a>.</p>
+  <a href="#accessory-protocol">Implementing the Android Accessory Protocol</a>.</p>
 
   <h3 id="wait-adk">Wait for and detect connected devices</h3>
 
@@ -559,13 +559,13 @@
                      "1.0",
                      "http://www.android.com",
                      "0000000012345678");
-                     
+
 ...
 void loop()
 {
 ...
-    if (acc.isConnected()) {  
-        //communicate with Android application 
+    if (acc.isConnected()) {
+        //communicate with Android application
     }
     else{
         //set the accessory to its default state
@@ -728,7 +728,7 @@
         Serial.print("Can't get config descriptor\n");
         return false;
     }
-    
+
 ...
 </pre>
 
@@ -859,13 +859,13 @@
   changes the state of the accessory, such as lighting up or changing the color of the LED
   lights.</p>
   <pre>
-int AndroidAccessory::read(void *buff, int len, unsigned int nakLimit) { 
-  return usb.newInTransfer(1, in, len, (char *)buff, nakLimit); } 
-  
-int AndroidAccessory::write(void *buff, int len) { 
-  usb.outTransfer(1, out, len, (char *)buff); 
+int AndroidAccessory::read(void *buff, int len, unsigned int nakLimit) {
+  return usb.newInTransfer(1, in, len, (char *)buff, nakLimit); }
+
+int AndroidAccessory::write(void *buff, int len) {
+  usb.outTransfer(1, out, len, (char *)buff);
   return len; }
-  
+
 </pre>
 
   <p>See the <code>firmware/demokit/demokit.pde</code> file for information about how the ADK board
diff --git a/docs/html/guide/topics/usb/index.jd b/docs/html/guide/topics/usb/index.jd
index 18af06a..3e2a18b 100644
--- a/docs/html/guide/topics/usb/index.jd
+++ b/docs/html/guide/topics/usb/index.jd
@@ -6,9 +6,9 @@
       <h2>Topics</h2>
 
       <ol>
-        <li><a href="{@docRoot}/guide/topics/USB/accessory.jd">USB Accessory</a></li>
+        <li><a href="{@docRoot}guide/topics/USB/accessory.jd">USB Accessory</a></li>
 
-        <li><a href="{@docRoot}/guide/topics/USB/host.jd">USB Host</a></li>
+        <li><a href="{@docRoot}guide/topics/USB/host.jd">USB Host</a></li>
       </ol>
     </div>
   </div>
diff --git a/docs/html/resources/articles/images/service-api-changes-starting-with_runningservices.png b/docs/html/resources/articles/images/service-api-changes-starting-with_runningservices.png
new file mode 100644
index 0000000..e159fff
--- /dev/null
+++ b/docs/html/resources/articles/images/service-api-changes-starting-with_runningservices.png
Binary files differ
diff --git a/docs/html/resources/articles/images/service-api-changes-starting-with_stopservice.png b/docs/html/resources/articles/images/service-api-changes-starting-with_stopservice.png
new file mode 100644
index 0000000..cc8f0a2
--- /dev/null
+++ b/docs/html/resources/articles/images/service-api-changes-starting-with_stopservice.png
Binary files differ
diff --git a/docs/html/resources/articles/multitasking-android-way.jd b/docs/html/resources/articles/multitasking-android-way.jd
new file mode 100644
index 0000000..0dc8627
--- /dev/null
+++ b/docs/html/resources/articles/multitasking-android-way.jd
@@ -0,0 +1,103 @@
+page.title=Multitasking the Android Way
+parent.title=Articles
+parent.link=../browser.html?tag=article
+@jd:body
+
+<div id="qv-wrapper">
+<div id="qv">
+
+  <h2>See also</h2>
+  <ol>
+    <li><a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back Stack</a></li>
+    <li><a href="{@docRoot}guide/topics/fundamentals/services.html">Services</a></li>
+  </ol>
+
+  <h2>Key classes</h2>
+  <ol>
+    <li>{@link android.app.Service}</li>
+    <li>{@link android.content.BroadcastReceiver}</li>
+  </ol>
+
+</div>
+</div>
+
+<p>Android is fairly unique in the ways it allows multiple applications to run at the same time.  Developers coming from a different platform may find the way it operates surprising.  Understanding its behavior is important for designing applications that will work well and integrate seamlessly with the rest of the Android platform.  This article covers the reasons for Android's multitasking design, its impact on how applications work, and how you can best take advantage of Android's unique features.</p>
+<h3>Design considerations</h3>
+<p>Mobile devices have technical limitations and user experience requirements not present in desktop or web systems.  Here are the four key constraints we were working under as we designed Android's multitasking:</p>
+<ul>
+  <li>
+    <p>We did not want to require that users close applications when "done" with them.  Such a usage pattern does not work well in a mobile environment, where usage tends to involve repeated brief contact with a wide variety of applications throughout the day.</p>
+  </li>
+  <li>
+    <p>Mobile devices don't have the luxury of swap space, so have fairly hard limits on memory use.  Robert Love has <a href="http://blog.rlove.org/2010/04/why-ipad-and-iphone-dont-support.html">a very good article</a> covering the topic.</p>
+  </li>
+  <li>
+    <p>Application switching on a mobile device is extremely critical; we target significantly less than 1 second to launch a new application.  This is especially important when the user is switching between a few applications, such as switching to look at a new SMS message while watching a video, and then returning to that video.  A noticeable wait in such situations will quickly make users hate you.</p>
+  </li>
+  <li>
+    <p>The available APIs must be sufficient for writing the built-in Google applications, as part of our "all applications are created equal" philosophy.  This means background music playback, data syncing, GPS navigation, and application downloading must be implemented with the same APIs that are available to third party developers.</p>
+  </li>
+</ul>
+<p>The first two requirements highlight an interesting conflict.  We don't want users to worry about closing their apps, but rather make it appear that all of the applications are always running.  At the same time, mobile devices have hard limits on memory use, so that a system will degrade or even start failing very quickly as it needs more RAM than is available; a desktop computer, with swap, in contrast will simply start slowing down as it needs to page RAM to its swap space.  These competing constraints were a key motivation for Android's design.</p>
+<h3>When does an application "stop"?</h3>
+<p>A common misunderstanding about Android multitasking is the difference between a process and an application.  In Android these are not tightly coupled entities: applications may seem present to the user without an actual process currently running the app; multiple applications may share processes, or one application may make use of multiple processes depending on its needs; the process(es) of an application may be kept around by Android even when that application is not actively doing something.</p>
+<p>The fact that you can see an application's process "running" does not mean the application is running or doing anything.  It may simply be there because Android needed it at some point, and has decided that it would be best to keep it around in case it needs it again.  Likewise, you may leave an application for a little bit and return to it from where you left off, and during that time Android may have needed to get rid of the process for other things.</p>
+<p>A key to how Android handles applications in this way is that processes don't shut down cleanly.  When the user leaves an application, its process is kept around in the background, allowing it to continue working (for example downloading web pages) if needed, and come immediately to the foreground if the user returns to it.  If a device never runs out of memory, then Android will keep all of these processes around, truly leaving all applications "running" all of the time.</p>
+<p>Of course, there is a limited amount of memory, and to accommodate this Android must decide when to get rid of processes that are not needed.  This leads to Android's <a href="{@docRoot}guide/topics/fundamentals.html#proclife">process lifecycle</a>, the rules it uses to decide how important each process is and thus the next one that should be dropped.  These rules are based on both how important a process is for the user's current experience, as well as how long it has been since the process was last needed by the user.</p>
+<p>Once Android determines that it needs to remove a process, it does this brutally, simply force-killing it.  The kernel can then immediately reclaim all resources needed by the process, without relying on that application being well written and responsive to a polite request to exit.  Allowing the kernel to immediately reclaim application resources makes it a lot easier to avoid serious out of memory situations.</p>
+<p>If a user later returns to an application that's been killed, Android needs a way to re-launch it in the same state as it was last seen, to preserve the "all applications are running all of the time" experience.  This is done by keeping track of the parts of the application the user is aware of (the Activities), and re-starting them with information about the last state they were seen in.  This last state is generated each time the user leaves that part of the application, not when it is killed, so that the kernel can later freely kill it without depending on the application to respond correctly at that point.</p>
+<p>In some ways, Android's process management can be seen as a form of swap space: application processes represent a certain amount of in-use memory; when memory is low, some processes can be killed (swapped out); when those processes are needed again, they can be re-started from their last saved state (swapped in).</p>
+<h3>Explicitly running in the background</h3>
+<p>So far, we have a way for applications to implicitly do work in the background, as long as the process doesn't get killed by Android as part of its regular memory management.  This is fine for things like loading web pages in the background, but what about features with harder requirements?  Background music playback, data synchronization, location tracking, alarm clocks, etc.</p>
+<p/>
+<p>For these tasks, the application needs a way to tell Android "I would explicitly like to run at this point."  There are two main facilities available to applications for this, represented by two kinds of components they can publish in their manifest: <span style="font-style:italic;">broadcast receivers</span> and <span style="font-style:italic;">services</span>.</p>
+<h4>Broadcast Receivers</h4>
+<p>A BroadcastReceiver allows an application to run, for a brief amount of time, in the background as a result of something else happening.  It can be used in many ways to build higher-level facilities: for example the AlarmManager allows an application to have a broadcast sent at a certain time in the future, and the LocationManager can send a broadcast when it detects interesting changes in location.  Because information about the receiver is part of an application's manifest, Android can find and launch the application even if it isn't running; of course if it already has its process available in the background, the broadcast can very efficiently be directly dispatched to it.</p>
+<p>When handling a broadcast, the application is given a fixed set of time (currently 10 seconds) in which to do its work.  If it doesn't complete in that time, the application is considered to be misbehaving, and its process immediately tossed into the background state to be killed for memory if needed.</p>
+<p>Broadcast receivers are great for doing small pieces of work in response to an external stimulus, such as posting a notification to the user after being sent a new GPS location report.  They are very lightweight, since the application's process only needs to be around while actively receiving the broadcast.  Because they are active for a deterministic amount of time, fairly strong guarantees can be made about not killing their process while running.  However they are not appropriate for anything of indeterminate length, such as networking.</p>
+<h4>Services</h4>
+<p>A Service allows an application to implement longer-running background operations.  There are actually a lot of other functions that services provide, but for the discussion here their fundamental purpose is for an application to say "hey I would like to continue running even while in the background, until I say I am done."  An application controls when its service runs by explicitly starting and stopping the service.</p>
+<p>While services do provide a rich client-server model, its use is optional.  Upon starting an application's services, Android simply instantiates the component in the application's process to provide its context.  How it is used after that is up to the application: it can put all of the needed code inside of the service itself without interacting with other parts of the application, make calls on other singleton objects shared with other parts of the app, directly retrieve the Service instance from elsewhere if needed, or run it in another process and do a full-blown RPC protocol if that is desired.</p>
+<p>Process management for services is different than broadcast receivers, because an unbounded number of services can ask to be running for an unknown amount of time.  There may not be enough RAM to have all of the requesting services run, so as a result no strong guarantees are made about being able to keep them running.</p>
+<p>If there is too little RAM, processes hosting services will be immediately killed like background processes are.  However, if appropriate, Android will remember that these services wish to remain running, and restart their process at a later time when more RAM is available.  For example, if the user goes to a web page that requires large amounts of RAM, Android may kill background service processes like sync until the browser's memory needs go down.</p>
+<p>Services can further negotiate this behavior by requesting they be considered "foreground."  This places the service in a "please don't kill" state, but requires that it include a notification to the user about it actively running.  This is useful for services such as background music playback or car navigation, which the user is actively aware of; when you're playing music and using the browser, you can always see the music-playing glyph in the status bar.  Android won't try to kill these services, but as a trade-off, ensures the user knows about them and is able to explicitly stop them when desired.</p>
+<h3>The value of generic components</h3>
+<p>Android's generic broadcast receiver and service components allow developers to create a wide variety of efficient background operations, including things that were never originally considered.  In Android 1.0 they were used to implement nearly all of the background behavior that the built-in and proprietary Google apps provided:</p>
+<ul>
+  <li>
+    Music playback runs in a service to allow it to continue operating after the user leaves the music application.
+  </li>
+  <li>
+    The alarm clock schedules a broadcast receiver with the alarm manager, to go off at the next set alarm time.
+  </li>
+  <li>
+    The calendar application likewise schedules an alarm to display or update its notification at the appropriate time for the next calendar event.
+  </li>
+  <li>
+    Background file download is implemented a service that runs when there are any downloads to process.
+  </li>
+  <li>
+    The e-mail application schedules an alarm to wake up a service at regular intervals that looks for and retrieves any new mail.
+  </li>
+  <li>
+    The Google applications maintain a service to receive push notifications from the network; it in turn sends broadcasts to individual apps when it is told that they need to do things like synchronize contacts.</p>
+  </li>
+</ul>
+<p>As the platform has evolved, these same basic components have been used to implement many of the major new developer features:
+<ul>
+  <li>
+    Input methods are implemented by developers as a Service component that Android manages and works with to display as the current IME.
+  </li>
+  <li>
+    Application widgets are broadcast receivers that Android sends broadcasts to when it needs to interact with them.  This allows app widgets to be quite lightweight, by not needing their application's process remain running.
+  </li>
+  <li>
+    Accessibility features are implemented as services that Android keeps running while in use and sends appropriate information to about user interactions.
+  </li>
+  <li>
+    Sync adapters introduced in Android 2.0 are services that are run in the background when a particular data sync needs to be performed.
+  </li>
+  <li>
+    Live wallpapers are a service started by Android when selected by the user.
+  </li>
+</ul>
diff --git a/docs/html/resources/articles/service-api-changes-starting-with.jd b/docs/html/resources/articles/service-api-changes-starting-with.jd
new file mode 100644
index 0000000..7bafd81
--- /dev/null
+++ b/docs/html/resources/articles/service-api-changes-starting-with.jd
@@ -0,0 +1,177 @@
+page.title=Service API changes starting with Android 2.0
+parent.title=Articles
+parent.link=../browser.html?tag=article
+@jd:body
+
+
+<div id="qv-wrapper">
+<div id="qv">
+
+  <h2>See also</h2>
+  <ol>
+    <li><a href="{@docRoot}guide/topics/fundamentals/services.html">Services</a></li>
+  </ol>
+
+  <h2>Key classes</h2>
+  <ol>
+    <li>{@link android.app.Service}</li>
+  </ol>
+
+</div>
+</div>
+
+<p>Watching developers use the Android platform the last year has shown a number of trouble areas in the Service API as well as growing issues in the ways services operate. As a result, Android 2.0 introduced a number of changes and improvements in this area for both developers and users.</p>
+<p>The three main changes to be aware of are:</p>
+<ul>
+  <li>Service.setForeground() is now deprecated and in 2.0 does nothing.</li>
+  <li>There were many edge cases in the service lifecycle that made it very easy to accidentally leave a service running; new APIs in 2.0 make this much easier to deal with.</li>
+  <li>Android 2.0 also introduces a new UI for end users to monitor and manage the running services on their device.</li>
+</ul>
+<h3>Background on services</h3>
+<p>Before going into the details of 2.0, it may be useful to go over a quick summary of services. The Service API in Android is one of the key mechanisms for applications to do work in the background. Due to the way Android is designed, once an application is no longer visible to the user it is generally considered expendable and a candidate to be killed by the system if it ever needs memory elsewhere. The main way applications get around this is by starting a Service component, which explicitly tells the system that they are doing some valuable work and would prefer that the system not kill their process if it doesn't truly need to.</p>
+<p>This is a very powerful facility but along with that power comes some responsibility: an actively running service is taking resources away from other things that can run (including inactive processes in the background that don't need to be initialized the next time the user visits them). It is thus important that developers take care when designing their services that they only run when truly needed and avoid any bugs where they may accidentally leave the service running for long durations.</p>
+<h3>Redesigning Service.setForeground()</h3>
+<p>During the final stabilization period of Android 1.6 we started to see more issues due to an increasing number of applications using the Service.setForeground() API when they shouldn't be. This is an API that we haven't advertised much because it should not be used by most applications and can be very hard on the system: it asks that the service's process be treated as in the foreground, essentially making it unkillable and thus more difficult for the system to recover from low memory situations.</p>
+<p>At that point in 1.6 it was too late to make any significant changes to the behavior here, but in 2.0 we have done so: Service.setForeground() now does nothing. The API was always intended to be something a service would do in conjunction with putting up an ongoing notification for the user; by saying you are in the foreground, the user should be "aware" that the service is running in some way and know how to stop it. Thus in place of the old API Andriod 2.0 introduces two new APIs that require a notification go along with being in the foreground:</p>
+<pre class="prettyprint">
+public final void startForeground(int id, Notification notification);
+public final void stopForeground(boolean removeNotification);
+</pre>
+<p>This also not coincidentally makes it much easier to manage the notification state along with the service, since the system can now guarantee that there is always a notification while the service is in the foreground, and that the notification goes away whenever the service does.</p>
+<p>Many developers will want to write a service that works on older platforms as well as 2.0 and later; this can be accomplished by using something like the following code to selectively call the new APIs when they are available.</p>
+<pre class="prettyprint">
+private static final Class[] mStartForegroundSignature = new Class[] {
+    int.class, Notification.class};
+private static final Class[] mStopForegroundSignature = new Class[] {
+    boolean.class};
+
+private NotificationManager mNM;
+private Method mStartForeground;
+private Method mStopForeground;
+private Object[] mStartForegroundArgs = new Object[2];
+private Object[] mStopForegroundArgs = new Object[1];
+
+&#64;Override
+public void onCreate() {
+    mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
+    try {
+        mStartForeground = getClass().getMethod("startForeground",
+                mStartForegroundSignature);
+        mStopForeground = getClass().getMethod("stopForeground",
+                mStopForegroundSignature);
+    } catch (NoSuchMethodException e) {
+        // Running on an older platform.
+        mStartForeground = mStopForeground = null;
+    }
+}
+
+/**
+ * This is a wrapper around the new startForeground method, using the older
+ * APIs if it is not available.
+ */
+void startForegroundCompat(int id, Notification notification) {
+    // If we have the new startForeground API, then use it.
+    if (mStartForeground != null) {
+        mStartForegroundArgs[0] = Integer.valueOf(id);
+        mStartForegroundArgs[1] = notification;
+        try {
+            mStartForeground.invoke(this, mStartForegroundArgs);
+        } catch (InvocationTargetException e) {
+            // Should not happen.
+            Log.w("MyApp", "Unable to invoke startForeground", e);
+        } catch (IllegalAccessException e) {
+            // Should not happen.
+            Log.w("MyApp", "Unable to invoke startForeground", e);
+        }
+        return;
+    }
+    
+    // Fall back on the old API.
+    setForeground(true);
+    mNM.notify(id, notification);
+}
+
+/**
+ * This is a wrapper around the new stopForeground method, using the older
+ * APIs if it is not available.
+ */
+void stopForegroundCompat(int id) {
+    // If we have the new stopForeground API, then use it.
+    if (mStopForeground != null) {
+        mStopForegroundArgs[0] = Boolean.TRUE;
+        try {
+            mStopForeground.invoke(this, mStopForegroundArgs);
+        } catch (InvocationTargetException e) {
+            // Should not happen.
+            Log.w("MyApp", "Unable to invoke stopForeground", e);
+        } catch (IllegalAccessException e) {
+            // Should not happen.
+            Log.w("MyApp", "Unable to invoke stopForeground", e);
+        }
+        return;
+    }
+    
+    // Fall back on the old API.  Note to cancel BEFORE changing the
+    // foreground state, since we could be killed at that point.
+    mNM.cancel(id);
+    setForeground(false);
+}
+</pre>
+<h3>Service lifecycle changes</h3>
+<p>Another situation we were increasingly seeing in 1.6 was that, even ignoring the services that inappropriately make themselves foreground, we had a growing number of devices with a large number of services running in the background all fighting each other over the available memory.</p>
+<p>Part of this problem is services that are running more than they should or there simply being too much stuff trying to be done on the device. However, we also found many issues in the interaction between services and the platform that made it easy for an application to leave a service running even when it is trying to do the right thing. Consider this typical scenario:</p>
+<ol>
+  <li>An application calls startService().</li>
+  <li>That service gets onCreate(), onStart(), and then spawns a background thread to do some work.</li>
+  <li>The system is tight on memory, so has to kill the currently running service.</li>
+  <li>Later when memory is free, the service is restarted, and gets onCreate() called but not onStart() because there has not been another call to startService() with a new Intent command to send it.</li>
+</ol>
+<p>Now the service will sit there created, not realizing it used to be doing some work, and so not knowing it should stop itself at some point.</p>
+<p>To address this, in Android 2.0 Service.onStart() as been deprecated (though still exists and operates as it used to in previous versions of the platform). It is replaced with a new {@link android.app.Service#onStartCommand(android.content.Intent, int, int)} callback that allows the service to better control how the system should manage it. The key part here is a new result code returned by the function, telling the system what it should do with the service if its process is killed while it is running:</p>
+<ul>
+  <li>{@link android.app.Service#START_STICKY} is basically the same as the previous behavior, where the service is left "started" and will later be restarted by the system. The only difference from previous versions of the platform is that it if it gets restarted because its process is killed, onStartCommand() will be called on the next instance of the service with a null Intent instead of not being called at all. Services that use this mode should always check for this case and deal with it appropriately.</li>
+  <li>{@link android.app.Service#START_NOT_STICKY} says that, after returning from onStartCreated(), if the process is killed with no remaining start commands to deliver, then the service will be stopped instead of restarted. This makes a lot more sense for services that are intended to only run while executing commands sent to them. For example, a service may be started every 15 minutes from an alarm to poll some network state. If it gets killed while doing that work, it would be best to just let it be stopped and get started the next time the alarm fires.</li>
+  <li>{@link android.app.Service#START_REDELIVER_INTENT} is like START_NOT_STICKY, except if the service's process is killed before it calls stopSelf() for a given intent, that intent will be re-delivered to it until it completes (unless after some number of more tries it still can't complete, at which point the system gives up). This is useful for services that are receiving commands of work to do, and want to make sure they do eventually complete the work for each command sent.</li>
+</ul>
+<p>For compatibility with existing applications, the default return code for applications that are targeting an earlier version of the platform is a special {@link android.app.Service#START_STICKY_COMPATIBILITY} code that provides the old behavior of not calling onStart() with a null intent. Once you start targeting API version 5 or later, the default mode is START_STICKY and you must be prepared to deal with onStart() or onStartCommand() being called with a null Intent.</p>
+<p>You can also easily write a Service that uses both the old and new APIs, depending on the platform. All you need to do is compile against the 2.0 SDK with this code:</p>
+<pre class="prettyprint">
+// This is the old onStart method that will be called on the pre-2.0
+// platform.  On 2.0 or later we override onStartCommand() so this
+// method will not be called.
+&#64;Override
+public void onStart(Intent intent, int startId) {
+    handleStart(intent, startId);
+}
+
+&#64;Override
+public int onStartCommand(Intent intent, int flags, int startId) {
+    handleStart(intent, startId);
+    return START_NOT_STICKY;
+}
+
+void handleStart(Intent intent, int startId) {
+    // do work
+}
+</pre>
+<h3>New "running services" user interface</h3>
+<p>Our final issue to address is the case where there are simply too many service running in the amount of memory available on a device. This may be due to bugs or design flaws in installed applications, or the user simply trying to do too much. Historically users have had no visibility into what is going on at this level in the system, but it has become important to expose this, at least for lower-end devices, as the use of services has had an increasing impact on the user experience.</p>
+<p>To help address this, Android 2.0 introduces a new "Running Services" activity available from the Application system settings. When brought up, it looks something like this:</p>
+<img src="images/service-api-changes-starting-with_runningservices.png" width="192" height="320" alt="Running Services"/>
+<p>The main content is a list of all running services that may be of interest to the user, organized by the processes they run in. In the example here, we see three services:</p>
+<ul>
+  <li><b>GTalkService</b> is part of the standard Google application suit; it is running in Google's "gapps" process, which currently consumes 6.8MB. It has been started for 3 hours 55 minutes, which on this device is the time from when it was first booted.</li>
+  <li><b>ActivityService</b> is part of the Phonebook app, and its process consumes 4MB. This also has been running since boot.</li>
+  <li><b>SoftKeyboard</b> is a third party input method. It has been running since I switched to it, about 4 minutes ago.</li>
+</ul>
+<p>The user can tap on any of these services to control it; for normal services that are running because they were explicitly started, this will present a dialog allowing the user to explicitly stop it:</p>
+<img src="images/service-api-changes-starting-with_stopservice.png" height="320" width="192" alt="Stop Service"/>
+<p>Some other services, like the input method, are running for other reasons. For these, tapping on the service will go to the corresponding UI to manage it (in this case the system's input settings).</p>
+<p>Finally, along the bottom of the screen are some obscure numbers. If you know how to interpret them, this gives you a lot of information on the memory status of your device:</p>
+<ul>
+  <li><b>Avail: 38MB+114MB in 25</b> says that the device has 38MB of completely free (or likely used for unrequired caches) memory, and has another 114MB of available memory in 25 background processes it can kill at any time.</li>
+  <li><b>Other: 32MB in 3</b> says that the device has 32MB of unavailable memory in 3 unkillable processes (that is, processes that are currently considered to be foreground and must be kept running)</li>
+</ul>
+<p>For most users, this new user interface should be a much more effective way to manage the background applications on their device than the existing "task killer" applications. In the vast majority of cases the reason for a slow running device is too many services trying to run. This prevents the system from being able to run any background processes (which speed up app switching), and ultimately can result in thrashing through the services when not even they can all be kept running. The Running Services UI is intended to provide very specific information about the services that are running, to help make a good decision about what should be stopped. It also does not use the API to force stop an application, which can unintentionally break applications in numerous ways.</p>
+<p>For developers, this is an important tool to ensure your services are well behaved. As you develop your app, be sure to keep an eye on Running Services to ensure that you are not accidentally leaving your services running when they shouldn't be. You should also now keep in mind that users may freely stop any of your services as they wish, without your control, and account for that.</p>
+<p>Android's Services are a very powerful tool, but one of the main and subtle ways that application developers can harm the overall experience a user has with their phone.</p>
diff --git a/docs/html/resources/resources-data.js b/docs/html/resources/resources-data.js
index 8d9b7b1..097d004 100644
--- a/docs/html/resources/resources-data.js
+++ b/docs/html/resources/resources-data.js
@@ -20,6 +20,7 @@
     'intent': 'Intents',
     'layout': 'Layouts/Views',
     'media': 'Multimedia',
+    'multitasking': 'Multi-tasking',
     'newfeature': 'New Features',
     'performance': 'Performance',
     'search': 'Search',
@@ -201,6 +202,16 @@
     }
   },
   {
+    tags: ['article', 'bestpractice', 'multitasking'],
+    path: 'articles/multitasking-android-way.html',
+    title: {
+      en: 'Multitasking the Android Way'
+    },
+    description: {
+      en: 'This article describes best practices and user experience guidelines for multi-tasking on Android.'
+    }
+  },
+  {
     tags: ['article', 'input'],
     path: 'articles/on-screen-inputs.html',
     title: {
@@ -241,6 +252,16 @@
     }
   },
   {
+    tags: ['article', 'compatibility', 'multitasking'],
+    path: 'articles/service-api-changes-starting-with.html',
+    title: {
+      en: 'Service API changes starting with Android 2.0'
+    },
+    description: {
+      en: 'This article describes the changes and improvements to services introduced in Android 2.0, as well as strategies for compatibility with older versions of the platform.'
+    }
+  },
+  {
     tags: ['article', 'ui'],
     path: 'articles/touch-mode.html',
     title: {
@@ -386,6 +407,26 @@
     }
   },
   {
+    tags: ['sample', 'layout', 'ui', 'fragment', 'loader', 'new'],
+    path: 'samples/Support4Demos/index.html',
+    title: {
+      en: 'API 4+ Support Demos'
+    },
+    description: {
+      en: 'A variety of small applications that demonstrate the use of the helper classes in the Android API 4+ Support Library (classes which work down to API level 4 or version 1.6 of the platform).'
+    }
+  },
+  {
+    tags: ['sample', 'layout', 'ui', 'new'],
+    path: 'samples/Support13Demos/index.html',
+    title: {
+      en: 'API 13+ Support Demos'
+    },
+    description: {
+      en: 'A variety of small applications that demonstrate the use of the helper classes in the Android API 13+ Support Library (classes which work down to API level 13 or version 3.2 of the platform).'
+    }
+  },
+  {
     tags: ['sample', 'data', 'newfeature', 'accountsync'],
     path: 'samples/BackupRestore/index.html',
     title: {
diff --git a/docs/html/sdk/android-2.3.3.jd b/docs/html/sdk/android-2.3.3.jd
index 6d60fcc..10fc049 100644
--- a/docs/html/sdk/android-2.3.3.jd
+++ b/docs/html/sdk/android-2.3.3.jd
@@ -141,8 +141,8 @@
 <li>NFC-F (JIS 6319-4)</li>
 <li>NFC-V (ISO 15693)</li>
 <li>ISO-DEP (ISO 14443-4)</li>
-<li>Mifare Classic</li>
-<li>Mifare Ultralight</li>
+<li>MIFARE Classic</li>
+<li>MIFARE Ultralight</li>
 <li>NFC Forum NDEF tags</li>
 </ul>
 
diff --git a/docs/html/sdk/android-2.3.4.jd b/docs/html/sdk/android-2.3.4.jd
index e5765d3..4cb44b9 100644
--- a/docs/html/sdk/android-2.3.4.jd
+++ b/docs/html/sdk/android-2.3.4.jd
@@ -128,7 +128,7 @@
 <a href="{@docRoot}sdk/android-2.3.3.html">Android 2.3.3 version notes</a>.</p>
 
 
-<h2 id="openaccessory">Open Accessory Library</h3>
+<h2 id="openaccessory">Open Accessory Library</h2>
 
 <p><em>Open Accessory</em> is a new capability for integrating
 connected peripherals with applications running on the platform. The capability
@@ -241,7 +241,7 @@
 <li>Camera</li>
 <li>Clock</li>
 <li>Contacts</li>
-<li>Cusom Locale</li>
+<li>Custom Locale</li>
 <li>Dev Tools</li>
 <li>Downloads</li>
 <li>Email</li>
@@ -309,6 +309,7 @@
 </ul>
 </td>
 <td style="border:0;padding-bottom:0;margin-bottom:0;padding-left:5em;">
+<ul>
 <li>Croatian, Croatia (hr_HR)</li>
 <li>Hungarian, Hungary (hu_HU)</li>
 <li>Indonesian, Indonesia (id_ID)</li>
@@ -337,6 +338,7 @@
 <li>Vietnamese, Vietnam (vi_VN)</li>
 <li>Chinese, PRC (zh_CN)</li>
 <li>Chinese, Taiwan (zh_TW)</li>
+</ul>
 </td>
 </tr>
 </table>
diff --git a/docs/html/sdk/compatibility-library.jd b/docs/html/sdk/compatibility-library.jd
new file mode 100644
index 0000000..d4669e5
--- /dev/null
+++ b/docs/html/sdk/compatibility-library.jd
@@ -0,0 +1,224 @@
+page.title=Compatibility Library
+
+@jd:body
+
+<div id="qv-wrapper">
+<div id="qv">
+  
+<h2>In this document</h2>
+<ol>
+  <li><a href="#Notes">Revisions</a></li>
+  <li><a href="#Installing">Installing the Compatibility Library</a></li>
+  <li><a href="#SettingUp">Setting Up a Project to Use the Library</a></li>
+  <li><a href="#Using">Using Some of the Library APIs</a></li>
+  <li><a href="#Samples">Samples</a></li>
+</ol>
+
+<h2>See also</h2>
+<ol>
+  <li><a
+href="{@docRoot}guide/practices/optimizing-for-3.0.html">Optimizing Apps for Android 3.0</a></li>
+  <li><a href="http://code.google.com/p/iosched/">Google I/O App source code</a></li>
+</ol>
+
+</div>
+</div>
+
+<p><em>Minimum API level supported:</em> <b>4</b></p>
+
+<p>The Compatibility Library is a static library you can add to your Android application in order to
+use APIs not available in older versions of the Android platform. The primary goal of the library is
+to provide APIs introduced in Andriod 3.0 for older versions of Android so that all applications can
+use them.</p>
+
+<p>If you're not able to use APIs introduced in Android 3.0 directly, because you want to remain
+backward-compatible, the Compatibility Library provides your application access to self-contained
+versions of some of the latest APIs that you can use with older versions of Android. Most
+importantly, the library provides implementations of the {@link android.app.Fragment} and {@link
+android.content.Loader} APIs, so you can use them in a way that's compatible with devices running
+Android 1.6 (API level 4) and higher. Thus, you can more easily create a single APK that supports a
+majority of devices and provide larger devices (such as tablets) a fully optimized experience by
+using <a href="{@docRoot}guide/topics/fundamentals/fragments.html">Fragments</a> in your activity
+design.</p>
+
+
+<h2 id="Notes">Revisions</h2>
+
+<p>The sections below provide notes about successive releases of
+the Compatibility Library, as denoted by revision number.</p>
+
+
+<div class="toggle-content open">
+
+  <p><a href="#" onclick="return toggleContent(this)">
+    <img src="{@docRoot}assets/images/triangle-opened.png" class="toggle-content-img" />
+    Compatibility Library, revision 2 (May 2011)
+  </a></p>
+
+  <div class="toggle-content-toggleme" style="padding-left:2em"> 
+    <dl>
+    <dt>Changes:</dt>
+    <dd>
+      <ul>
+        <li>Support for fragment animations.</li>
+        <li>Fix {@code Fragment.onActivityResult()} bug.</li>
+      </ul>
+    </dd>
+    </dl>
+  </div>
+
+</div>
+
+
+<div class="toggle-content closed">
+
+  <p><a href="#" onclick="return toggleContent(this)">
+    <img src="{@docRoot}assets/images/triangle-closed.png" class="toggle-content-img" />
+    Compatibility Library, revision 1 (March 2011)
+  </a></p>
+
+  <div class="toggle-content-toggleme" style="padding-left:2em"> 
+      <p>Initial release of the library.</p>
+  </div>
+
+</div>
+
+
+
+<h2 id="Installing">Installing the Compatibility Library</h2>
+
+<p>The Compatibility Library is provided as a downloadable package from the Android SDK and AVD
+Manager. To install the library:</p>
+
+<ol>
+  <li>Launch the SDK and AVD Manager. 
+    <p>From Eclipse, you can select <strong>Window</strong>
+&gt; <strong>Android SDK and AVD Manager</strong>. Or, launch {@code SDK Manager.exe} from
+the {@code &lt;sdk&gt;/} directory (on Windows only) or {@code android} from the {@code
+&lt;sdk&gt;/tools/} directory.</p></li>
+  <li>Expand the Android Repository, check <strong>Android Compatibility package</strong>
+and click <strong>Install selected</strong>.</li>
+  <li>Proceed to install the package.</li>
+</ol>
+
+<p>When done, all files (including source code, samples, and the {@code .jar} file) are saved
+into the <code>&lt;sdk&gt;/extras/android/compatibility/</code> directory. The next directory
+name is {@code v4}, which indicates the lowest compatible version for the library within. That
+is, the code in {@code v4/} supports API level 4 and above. (There may be future libraries that
+have a different minimum version, so they will be saved alongside this one.)</p>
+
+
+<h2 id="SettingUp">Setting Up a Project to Use the Library</h2>
+
+<p>To add the Compatibility Library to your Android project:</p>
+<ol>
+  <li>In your Android project, create a directory named {@code libs} at the root of your
+project (next to {@code src/}, {@code res/}, etc.)</li>
+  <li>Navigate to {@code &lt;sdk&gt;/extras/android/compatibility/v4/}.</li>
+  <li>Copy the {@code android-support-v4.jar} file into your project {@code libs/} directory.</li>
+  <li>Add the JAR to your project build path. In Eclipse, right-click the JAR file in the
+Package Explorer, select <strong>Build Path</strong> &gt; <strong>Add to Build Path</strong>.
+You should then see the JAR file appear in a new directory called Referenced Libraries.</li>
+</ol>
+
+<p>Your application is now ready to use fragments, loaders and other APIs from the library. All the
+provided APIs are in the {@code android.support.v4} package.</p>
+
+<p class="warning"><strong>Warning:</strong> Be certain that you not confuse the standard
+{@code android} packages with those in {@code android.support.v4}. Some code completion tools might
+get this wrong, especially if you're building against recent versions of the platform. To be safe,
+keep your build target set to the same version as you have defined for your <a
+href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#min">{@code android:minSdkVersion}</a>
+and double check the import statements for classes that are duplicated in the Compatibility
+Library, such as {@code SimpleCursorAdapter}.</p>
+
+
+<h2 id="Using">Using Some of the Library APIs</h2>
+
+<p>The Compatibility Library provides access to several classes introduced with Android 3.0, plus
+some updated version of existing classes. Some of the most useful and notable classes in the
+library are:</p>
+
+<ul>
+  <li>{@link android.app.Fragment}</li>
+  <li>{@link android.app.FragmentManager}</li>
+  <li>{@link android.app.FragmentTransaction}</li>
+  <li>{@link android.app.ListFragment}</li>
+  <li>{@link android.app.DialogFragment}</li>
+  <li>{@link android.app.LoaderManager}</li>
+  <li>{@link android.content.Loader}</li>
+  <li>{@link android.content.AsyncTaskLoader}</li>
+  <li>{@link android.content.CursorLoader}</li>
+</ul>
+
+<p>For each of the classes above (and others not listed), the APIs work almost exactly the same
+as the counterparts in the latest version of the Android platform. Thus, you can usually refer to
+the latest reference documentation for information about the supported APIs. There are some
+differences, however. Most notably:</p>
+
+<ul>
+  <li>When creating an activity to use fragments, you must declare your activity to extend the
+{@code FragmentActivity} class (instead of the traditional {@link android.app.Activity}
+class).</li>
+  <li>To manage your fragments and loaders, you must use the methods {@code
+FragmentActivity.getSupportFragmentManager()} and {@code
+FragmentActivity.getSupportLoaderManager()} (instead of the {@link
+android.app.Activity#getFragmentManager()} and {@link android.app.Activity#getLoaderManager()}
+methods).</li>
+  <li>The {@link android.app.ActionBar} is <strong>not supported</strong> by the library.
+However, when creating your <a href="{@docRoot}guide/topics/ui/menus.html#options-menu">Options
+Menu</a>, you can declare which items should be added to the Action Bar when it's available (on
+Android 3.0 or later). You can do so with the {@code MenuCompat.setShowAsAction()} method. For
+example:
+<pre>
+public boolean onCreateOptionsMenu(Menu menu) {
+    MenuInflater inflater = getMenuInflater();
+    inflater.inflate(R.menu.options, menu);
+    MenuCompat.setShowAsAction(menu.findItem(R.id.action_search), 1);
+    return true;
+}
+</pre>
+</li>
+</ul>
+
+<p>The Compatibility Library currently does not provide reference documentation for the included
+APIs. To generate your own set, using the {@code javadoc} tool, perform the
+following from a command line:</p>
+
+<pre class="no-pretty-print">
+cd &lt;sdk&gt;/extras/android/compatibility/v4/
+mkdir docs
+javadoc -sourcepath src/java/ -subpackages android.support.v4 -d docs
+</pre>
+<p>Open the {@code docs/index.html} file to begin browsing the generated documentation.</p>
+
+
+<div class="note"><p><strong>Tip:</strong> To enable the Holographic theme on devices
+running Android 3.0 or higher, declare in your manifest file that your application targets
+API level 11. For example:</p>
+<pre>
+&lt;uses-sdk android:minSdkVersion="4" android:targetSdkVersion="11" /&gt;
+</pre>
+<p>This way, your application automatically receives the Holographic theme and the Action Bar for 
+each activity when running on Android 3.0 and higher.</p>
+</div>
+
+<p>For more information about how you can optimize your application for the latest
+Android-powered devices, read <a href="{@docRoot}guide/practices/optimizing-for-3.0.html">Optimizing
+Apps for Android 3.0</a>.</p>
+
+
+<h2 id="Samples">Samples</h2>
+
+<p>If you want to see some sample code that uses the Compatibility Library, take a look at the
+<a href="{@docRoot}resources/samples/ApiDemos/src/com/example/android/apis/support/index.html">API
+Demos</a> sample code that's included with the Samples package you can download from the AVD and SDK
+Manager.</p>
+
+<p>Additionally, the <a href="http://code.google.com/p/iosched/">Google I/O App</a> is a complete
+application that uses the library to provide a single APK for both handsets and tablets and also
+demonstrates some of Android's best practices in Android UI design.</p>
+
+
+
+
diff --git a/docs/html/sdk/eclipse-adt.jd b/docs/html/sdk/eclipse-adt.jd
index feb84b1..935bf63 100644
--- a/docs/html/sdk/eclipse-adt.jd
+++ b/docs/html/sdk/eclipse-adt.jd
@@ -1,8 +1,8 @@
 page.title=ADT Plugin for Eclipse
-adt.zip.version=10.0.1
-adt.zip.download=ADT-10.0.1.zip
-adt.zip.bytes=5096182
-adt.zip.checksum=e26a77db08377bdd2e62edeb9a3e3701
+adt.zip.version=11.0.0
+adt.zip.download=ADT-11.0.0.zip
+adt.zip.bytes=TODO
+adt.zip.checksum=TODO
 
 @jd:body
 
@@ -100,6 +100,139 @@
   <a href="#" onclick="return toggleDiv(this)">
         <img src="{@docRoot}assets/images/triangle-opened.png" class="toggle-img" height="9px"
 width="9px" />
+ADT 11.0.0</a> <em>(June 2011)</em>
+  <dd class="toggleme">
+
+<dl>
+
+<dt>Dependencies:</dt>
+
+<dd>ADT 11.0.0 is designed for use with SDK Tools r11. If you haven't
+already installed SDK Tools r11 into your SDK, use the Android SDK and AVD Manager to do
+so.</dd>
+
+<dt>Visual Refactoring:</dt>
+<dd>
+  <ul>
+    <li>"Extract Style" feature pulls out style-related attributes from your layout and extracts
+them as a new style defined in {@code styles.xml} (<a
+href="http://tools.android.com/recent/extractstylerefactoring">more info</a>).</li>
+    <li>"Wrap in Container" feature lets you select a group of views then surround them
+    in a new layout (a new view group, such as a LinearLayout), and transfers namespace and layout
+    parameters to the new parent (<a
+href="http://tools.android.com/recent/newrefactoringswrapinchangelayoutchangewidget">more
+info</a>).</li>
+    <li>"Change Layout" feature changes layouts from one type
+    to another, and can also flatten a layout hierarchy (<a
+href="http://tools.android.com/recent/newrefactoringswrapinchangelayoutchangewidget">more
+info</a>).</li>
+    <li>"Change Widget Type" feature changes the type of the
+    selected views to a new type. Also, a new selection context menu
+    in the visual layout editor makes it easy to select siblings as
+    well as views anywhere in the layout that have the same type (<a
+href="http://tools.android.com/recent/newrefactoringswrapinchangelayoutchangewidget">more
+info</a>).</li>
+    <li>"Extract as Include" feature finds identical collections of views
+    in other layouts and offers to combine them into a single layout that you can then include in
+ each layout (<a
+href="http://tools.android.com/recent/extractasincludeimprovements">more info</a>).</li>
+    <li>Quick Assistant in Eclipse can be invoked
+    from the XML editor (with Ctrl-1) to apply any of the above
+    refactorings (and Extract String) to the current selection (<a
+href="http://tools.android.com/recent/refactoringquickassistant">more info</a>).</li>
+  </ul>
+</dd>
+
+<dt>Visual Layout Editor:</dt>
+<dd>
+  <ul>
+    <li>This is the update to the layout editor you've been waiting for! It includes (almost) all
+the goodies demonstrated at Google I/O. <a href="http://www.youtube.com/watch?v=Oq05KqjXTvs">Watch
+the video</a> on YouTube.</li>
+    <li>The palette now supports different configurations for supported widgets. That is, a single
+view is presented in various different configurations that you can drag into your layout. For
+example, there is a <em>Text Fields</em> palette category where you can drag an {@link
+android.widget.EditText} widget in as a password field, an e-mail field, a phone field, or other
+types of text boxes. Similarly, {@link android.widget.TextView} widgets are preconfigured
+with large, normal and small theme sizes, and {@link android.widget.LinearLayout} elements are
+preconfigured in horizontal and vertical configurations (<a
+href="http://tools.android.com/recent/multipletextfieldandlayouttypes">more info</a>).</li>
+    <li>The palette supports custom views. You can pick up any custom
+    implementations of the View class you've created in your project or from included libraries and
+drag them into your layout (<a
+href="http://tools.android.com/recent/customviewsinthepalette">more info</a>).</li>
+    <li>Fragments are available in the palette for placement in your layout. In the tool, you can
+choose which layout to show rendered for a given fragment tag. Go to declaration works for fragment
+classes (<a href="http://tools.android.com/recent/fragmentsupport">more info</a>).</li> 
+    <li>The layout editor automatically applies a "zoom to fit" for newly
+    opened files as well as on device size and orientation changes to
+    ensure that large layouts are always fully visible unless you
+    manually zoom in.</li>
+    <li>You can drop in an {@code &lt;include&gt;} element from the palette, which will pop up
+    a layout chooser. When you select the layout to include, it is added with an {@code
+&lt;include&gt;}. Similarly, dropping images or image buttons will pop up image
+    resource choosers (<a
+href="http://tools.android.com/recent/includetagdropsupport">more info</a>).</li>
+    <li>The configuration chooser now applies the "Render Target" and
+    "Locale" settings project wide, making it trivial to check the
+    layouts for different languages or render targets without having
+    to configure these individually for each layout.</li>
+    <li>The layout editor is smarter about picking a default theme to
+    render a layout with, consulting factors like theme registrations
+    in the manifest, the SDK version, and other factors.</li>
+    <li>The layout editor is smarter about picking a default configuration to render a layout
+with, defaulting to the currently visible configuration in the previous file. It also considers the
+SDK target to determine whether to default to a tablet or phone screen size.</li>
+    <li>Basic focus support. The first text field dropped in a layout is assigned focus, and there
+are <strong>Request Focus</strong> and <strong>Clear Focus</strong> context menu items on text
+fields to change the focus.</li>
+  </ul>
+</dd>
+
+<dt>XML editors:</dt>
+<dd>
+<ul>  
+  <li>Code completion has been significantly improved. It now works
+  with {@code &lt;style&gt;} elements, completes dimensional units,
+  sorts resource paths in values based on the attribute name, and more. There are also many fixes to
+handle text replacement (<a
+href="http://tools.android.com/recent/xmlcodecompletionimprovements">more info</a>).</li>
+  <li>AAPT errors are handled better. They are now underlined for the
+  relevant range in the editor, and a new quickfix makes it trivial
+  to create missing resources.</li>
+  <li>Code completion for drawable, animation and color XML files (<a
+href="http://tools.android.com/recent/codecompletionfordrawablescolorsandanimationfiles">more
+info</a>).</li>
+</ul>
+</dd>
+
+<dt>DDMS:</dt>
+<dd>
+<ul>  
+  <li>"New Folder" action in the File Explorer.</li>
+  <li>The screenshot dialog will add timestamps to the filenames and preserve the orientation on
+snapshot refresh.</li>
+</ul>
+</dd>
+
+<dt>General notes:</dt>
+<dd>
+  <ul>
+    <li>TraceView supports zooming with the mouse-wheel in the timeline.</li>
+    <li>The New Android Project wizard now supports Eclipse working sets.</li>
+  </ul>
+</dd>
+</dl>
+<p>More information about tool changes are available on the <a
+href="http://tools.android.com/recent">Android Tools Project Site</a>.</p>
+</div>
+</div>
+
+
+<div class="toggleable closed">
+  <a href="#" onclick="return toggleDiv(this)">
+        <img src="{@docRoot}assets/images/triangle-closed.png" class="toggle-img" height="9px"
+width="9px" />
 ADT 10.0.1</a> <em>(March 2011)</em>
   <div class="toggleme">
 
diff --git a/docs/html/sdk/index.jd b/docs/html/sdk/index.jd
index 7c1c86d..e7b8fbb 100644
--- a/docs/html/sdk/index.jd
+++ b/docs/html/sdk/index.jd
@@ -31,6 +31,16 @@
   <li>Explore the contents of the Android SDK (optional).</li>
 </ol>
 
-<p>To get started, download the appropriate package from the table above, then read the guide to <a
-href="installing.html">Installing the SDK</a>.</p>
+<p class="online-message">To get started, download the appropriate package from the table above,
+then read the guide to <a href="installing.html">Installing the SDK</a>.</p>
+
+<!-- non-inline style and based on only one selector so that
+     it can be overriden by the sdkpage.cs template -->
+<style type="text/css">
+  .offline-message { display:none; }
+</style>
+      
+<p class="offline-message">For more information about how to set up your
+development environment, read the guide to <a href="installing.html">Installing the SDK</a>.</p>
+
 </div>
diff --git a/docs/html/sdk/ndk/index.jd b/docs/html/sdk/ndk/index.jd
index bc9ba4b..e980ca5 100644
--- a/docs/html/sdk/ndk/index.jd
+++ b/docs/html/sdk/ndk/index.jd
@@ -1,16 +1,16 @@
 ndk=true
 
-ndk.win_download=android-ndk-r5b-windows.zip
-ndk.win_bytes=61299831
-ndk.win_checksum=87745ada305ab639399161ab4faf684c
+ndk.win_download=android-ndk-r5c-windows.zip
+ndk.win_bytes=61627716
+ndk.win_checksum=2c7423842fa0f46871eab118495d4b45
 
-ndk.mac_download=android-ndk-r5b-darwin-x86.tar.bz2
-ndk.mac_bytes=50210863
-ndk.mac_checksum=019a14622a377b3727ec789af6707037
+ndk.mac_download=android-ndk-r5c-darwin-x86.tar.bz2
+ndk.mac_bytes=50714712
+ndk.mac_checksum=183bfbbd85cf8e4c0bd7531e8803e75d
 
-ndk.linux_download=android-ndk-r5b-linux-x86.tar.bz2
-ndk.linux_bytes=44138539
-ndk.linux_checksum=4c0045ddc2bfd657be9d5177d0e0b7e7
+ndk.linux_download=android-ndk-r5c-linux-x86.tar.bz2
+ndk.linux_bytes=44539890
+ndk.linux_checksum=7659dfdc97026ed1d913e224d0531f61
 
 page.title=Android NDK
 @jd:body
@@ -52,14 +52,97 @@
   text-decoration:underline;
 }
 .toggleable.closed .toggleme {
-  display:none;
-}
+  display:none;}
 #jd-content .toggle-img {
   margin:0;
 }
 </style>
 
+
 <div class="toggleable open">
+  <a href="#" onclick="return toggleDiv(this)"><img src=
+  "{@docRoot}assets/images/triangle-opened.png" class="toggle-img" height="9px" width="9px">
+  Android NDK, Revision 5c</a> <em>(June 2011)</em>
+
+  <div class="toggleme">
+    <p>This release of the NDK does not include any new features compared to r5b. The r5c release
+    addresses the following problems in the r5b release:</p>
+    <dl>
+      <dt>Important bug fixes:</dt>
+      <dd>
+        <ul>
+          <li><code>ndk-build</code>: Fixed a rare bug that appeared when trying to perform parallel
+          builds of debuggable projects.</li>
+
+          <li>Fixed a typo that prevented <code>LOCAL_WHOLE_STATIC_LIBRARIES</code> to work
+          correctly with the new toolchain and added documentation for this in
+          <code>docs/ANDROID-MK.html</code>.</li>
+
+          <li>Fixed a bug where code linked against <code>gnustl_static</code> crashed when run on
+          platform releases older than API level 8 (Android 2.2).</li>
+
+          <li><code>ndk-gdb</code>: Fixed a bug that caused a segmentation fault when debugging Android 3.0
+          or newer devices.</li>
+
+          <li><code>&lt;android/input.h&gt;</code>: Two functions that were introduced in API level
+          9 (Android 2.3) were incorrect and are fixed. While this breaks the source API, the
+          binary interface to the system is unchanged. The incorrect functions were missing a
+          <code>history_index</code> parameter, and the correct definitions are shown below:
+<pre>
+float AMotionEvent_getHistoricalRawX(const AInputEvent* motion_event,
+                                           size_t pointer_index,
+                                           size_t history_index);
+
+float AMotionEvent_getHistoricalRawY(const AInputEvent* motion_event,
+                                           size_t pointer_index,
+                                           size_t history_index);
+</pre>
+          </li>
+
+          <li>Updated the C library ARM binary for API level 9 (Android 2.3) to correctly expose at
+          link time new functions that were added in that API level (for example,
+          <code>pthread_rwlock_init</code>).</li>
+
+        </ul>
+      </dd>
+
+      <dt>Minor improvements and fixes:</dt>
+      <dd>
+        <ul>
+          <li>Object files are now always linked in the order they appear in
+          <code>LOCAL_SRC_FILES</code>. This was not the case previously because the files were
+          grouped by source extensions instead.</li>
+
+          <li>When <code>import-module</code> fails, it now prints the list of directories that
+          were searched. This is useful to check that the <code>NDK_MODULE_PATH</code> definition
+          used by the build system is correct.</li>
+
+          <li>When <code>import-module</code> succeeds, it now prints the directory where the
+          module was found to the log (visible with <code>NDK_LOG=1</code>).</li>
+
+          <li>Increased the build speed of debuggable applications when there is a very large number
+          of include directories in the project.</li>
+
+          <li><code>ndk-gdb</code>: Better detection of <code>adb shell</code> failures and improved
+          error messages.</li>
+
+          <li><code>&lt;pthread.h&gt;</code>: Fixed the definition of
+          <code>PTHREAD_RWLOCK_INITIALIZER</code> for API level 9 (Android 2.3) and higher.</li>
+
+          <li>Fixed an issue where a module could import itself, resulting in an infinite loop in
+          GNU Make.</li>
+
+          <li>Fixed a bug that caused the build to fail if <code>LOCAL_ARM_NEON</code> was set to
+          true (typo in <code>build/core/build-binary.mk</code>).</li>
+
+          <li>Fixed a bug that prevented the compilation of </code>.s</code> assembly files
+          (<code>.S</code> files were okay).</li>
+        </ul>
+      </dd>
+  </div>
+</div>
+
+<div class="toggleable closed">
     <a href="#"
          onclick="return toggleDiv(this)"><img src="{@docRoot}assets/images/triangle-closed.png"
          class="toggle-img"
diff --git a/docs/html/sdk/sdk_toc.cs b/docs/html/sdk/sdk_toc.cs
index 11f29b1..5750c81 100644
--- a/docs/html/sdk/sdk_toc.cs
+++ b/docs/html/sdk/sdk_toc.cs
@@ -1,6 +1,5 @@
 <?cs if:!sdk.redirect ?>
-<ul><?cs
-  if:android.whichdoc == "online" ?>
+<ul>
   <li>
     <h2>
       <span class="en">Android SDK Starter Package</span>
@@ -12,7 +11,8 @@
       <span style="display:none" class="zh-CN">当前的 SDK 版本</span>
       <span style="display:none" class="zh-TW">目前 SDK 發行版本</span>
     </h2>
-    <ul>
+    <ul><?cs
+  if:android.whichdoc == "online" ?>
       <li><a href="<?cs var:toroot ?>sdk/index.html">
           <span class="en">Download</span>
           <span style="display:none" class="de">Herunterladen</span>
@@ -22,7 +22,8 @@
           <span style="display:none" class="ja">ダウンロード</span>
           <span style="display:none" class="zh-CN">下载</span>
           <span style="display:none" class="zh-TW">下載</span>
-        </a></li>
+        </a></li><?cs 
+  /if ?>
       <li><a href="<?cs var:toroot ?>sdk/installing.html">
           <span class="en">Installing the SDK</span>
           <span style="display:none" class="de">Installieren</span>
@@ -33,10 +34,8 @@
           <span style="display:none" class="zh-CN">安装</span>
           <span style="display:none" class="zh-TW">安裝</span>
         </a></li>
-
     </ul>
-  </li>
-  <?cs /if ?><?cs
+  </li><?cs
   if:sdk.preview ?>
   <li><h2>Android 3.0 Preview SDK</h2>
     <ul>
@@ -138,6 +137,8 @@
       <li><a href="<?cs var:toroot ?>sdk/tools-notes.html">SDK Tools, r11</a> <span
 class="new">new!</span></li>
       <li><a href="<?cs var:toroot ?>sdk/win-usb.html">Google USB Driver, r4</a></li>
+      <li><a href="<?cs var:toroot ?>sdk/compatibility-library.html">Compatibility Library, r2</a> <span
+class="new">new!</span></li>
     </ul>
   </li>
   <li>
@@ -152,7 +153,7 @@
       <span style="display:none" class="zh-TW"></span>
       </h2>
     <ul>
-      <li><a href="<?cs var:toroot ?>sdk/eclipse-adt.html">ADT 10.0.1
+      <li><a href="<?cs var:toroot ?>sdk/eclipse-adt.html">ADT 11.0.0
       <span style="display:none" class="de"></span>
       <span style="display:none" class="es"></span>
       <span style="display:none" class="fr"></span>
@@ -160,7 +161,7 @@
       <span style="display:none" class="ja"></span>
       <span style="display:none" class="zh-CN"></span>
       <span style="display:none" class="zh-TW"></span></a>
-     <!-- <span class="new">new!</span> --></li>
+      <span class="new">new!</span></li>
     </ul>
   </li>
   <li>
@@ -174,7 +175,7 @@
       <span style="display:none" class="zh-TW"></span>
     </h2>
     <ul>
-      <li><a href="<?cs var:toroot ?>sdk/ndk/index.html">Android NDK, r5b</a>
+      <li><a href="<?cs var:toroot ?>sdk/ndk/index.html">Android NDK, r5c</a>
         </li>
       <li><a href="<?cs var:toroot ?>sdk/ndk/overview.html">What is the NDK?</a></li>
     </ul>
diff --git a/drm/common/IDrmManagerService.cpp b/drm/common/IDrmManagerService.cpp
index c37b4f8..458f1b6 100644
--- a/drm/common/IDrmManagerService.cpp
+++ b/drm/common/IDrmManagerService.cpp
@@ -37,7 +37,7 @@
 
 using namespace android;
 
-static void writeDecrptHandleToParcelData(
+static void writeDecryptHandleToParcelData(
         const DecryptHandle* handle, Parcel* data) {
     data->writeInt32(handle->decryptId);
     data->writeString8(handle->mimeType);
@@ -46,14 +46,14 @@
 
     int size = handle->copyControlVector.size();
     data->writeInt32(size);
-    for(int i = 0; i < size; i++) {
+    for (int i = 0; i < size; i++) {
         data->writeInt32(handle->copyControlVector.keyAt(i));
         data->writeInt32(handle->copyControlVector.valueAt(i));
     }
 
     size = handle->extendedData.size();
     data->writeInt32(size);
-    for(int i = 0; i < size; i++) {
+    for (int i = 0; i < size; i++) {
         data->writeString8(handle->extendedData.keyAt(i));
         data->writeString8(handle->extendedData.valueAt(i));
     }
@@ -77,14 +77,14 @@
     handle->status = data.readInt32();
 
     int size = data.readInt32();
-    for (int i = 0; i < size; i ++) {
+    for (int i = 0; i < size; i++) {
         DrmCopyControl key = (DrmCopyControl)data.readInt32();
         int value = data.readInt32();
         handle->copyControlVector.add(key, value);
     }
 
     size = data.readInt32();
-    for (int i = 0; i < size; i ++) {
+    for (int i = 0; i < size; i++) {
         String8 key = data.readString8();
         String8 value = data.readString8();
         handle->extendedData.add(key, value);
@@ -416,7 +416,7 @@
     data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
     data.writeInt32(uniqueId);
 
-    writeDecrptHandleToParcelData(decryptHandle, &data);
+    writeDecryptHandleToParcelData(decryptHandle, &data);
 
     data.writeInt32(action);
     data.writeInt32(static_cast< int>(reserve));
@@ -433,7 +433,7 @@
     data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
     data.writeInt32(uniqueId);
 
-    writeDecrptHandleToParcelData(decryptHandle, &data);
+    writeDecryptHandleToParcelData(decryptHandle, &data);
 
     data.writeInt32(playbackStatus);
     data.writeInt64(position);
@@ -646,7 +646,7 @@
     data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
     data.writeInt32(uniqueId);
 
-    writeDecrptHandleToParcelData(decryptHandle, &data);
+    writeDecryptHandleToParcelData(decryptHandle, &data);
 
     remote()->transact(CLOSE_DECRYPT_SESSION, data, &reply);
 
@@ -662,7 +662,7 @@
     data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
     data.writeInt32(uniqueId);
 
-    writeDecrptHandleToParcelData(decryptHandle, &data);
+    writeDecryptHandleToParcelData(decryptHandle, &data);
 
     data.writeInt32(decryptUnitId);
 
@@ -682,7 +682,7 @@
     data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
     data.writeInt32(uniqueId);
 
-    writeDecrptHandleToParcelData(decryptHandle, &data);
+    writeDecryptHandleToParcelData(decryptHandle, &data);
 
     data.writeInt32(decryptUnitId);
     data.writeInt32((*decBuffer)->length);
@@ -715,7 +715,7 @@
     data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
     data.writeInt32(uniqueId);
 
-    writeDecrptHandleToParcelData(decryptHandle, &data);
+    writeDecryptHandleToParcelData(decryptHandle, &data);
 
     data.writeInt32(decryptUnitId);
 
@@ -733,7 +733,7 @@
     data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
     data.writeInt32(uniqueId);
 
-    writeDecrptHandleToParcelData(decryptHandle, &data);
+    writeDecryptHandleToParcelData(decryptHandle, &data);
 
     data.writeInt32(numBytes);
     data.writeInt64(offset);
@@ -1244,7 +1244,7 @@
             = openDecryptSession(uniqueId, fd, data.readInt64(), data.readInt64());
 
         if (NULL != handle) {
-            writeDecrptHandleToParcelData(handle, reply);
+            writeDecryptHandleToParcelData(handle, reply);
             clearDecryptHandle(handle);
             delete handle; handle = NULL;
         }
@@ -1262,7 +1262,7 @@
         DecryptHandle* handle = openDecryptSession(uniqueId, uri.string());
 
         if (NULL != handle) {
-            writeDecrptHandleToParcelData(handle, reply);
+            writeDecryptHandleToParcelData(handle, reply);
 
             clearDecryptHandle(handle);
             delete handle; handle = NULL;
diff --git a/drm/java/android/drm/DrmInfoRequest.java b/drm/java/android/drm/DrmInfoRequest.java
index 2222ae8..1429fa5 100755
--- a/drm/java/android/drm/DrmInfoRequest.java
+++ b/drm/java/android/drm/DrmInfoRequest.java
@@ -32,16 +32,16 @@
      */
     public static final int TYPE_REGISTRATION_INFO = 1;
     /**
-    * Acquires information for unregistering the DRM server.
-    */
+     * Acquires information for unregistering the DRM server.
+     */
     public static final int TYPE_UNREGISTRATION_INFO = 2;
     /**
-    * Acquires rights information.
-    */
+     * Acquires rights information.
+     */
     public static final int TYPE_RIGHTS_ACQUISITION_INFO = 3;
     /**
-    * Acquires the progress of the rights acquisition.
-    */
+     * Acquires the progress of the rights acquisition.
+     */
     public static final int TYPE_RIGHTS_ACQUISITION_PROGRESS_INFO = 4;
 
     /**
diff --git a/drm/java/android/drm/DrmInfoStatus.java b/drm/java/android/drm/DrmInfoStatus.java
index b04694b..5c12ae3 100755
--- a/drm/java/android/drm/DrmInfoStatus.java
+++ b/drm/java/android/drm/DrmInfoStatus.java
@@ -31,20 +31,20 @@
     public static final int STATUS_ERROR = 2;
 
     /**
-    * The status of the communication.
-    */
+     * The status of the communication.
+     */
     public final int statusCode;
     /**
-    * The type of DRM information processed.
-    */
+     * The type of DRM information processed.
+     */
     public final int infoType;
     /**
-    * The MIME type of the content.
-    */
+     * The MIME type of the content.
+     */
     public final String mimeType;
     /**
-    * The processed data.
-    */
+     * The processed data.
+     */
     public final ProcessedData data;
 
     /**
diff --git a/drm/libdrmframework/include/PlugInManager.h b/drm/libdrmframework/include/PlugInManager.h
index 8029138..7bb143f 100644
--- a/drm/libdrmframework/include/PlugInManager.h
+++ b/drm/libdrmframework/include/PlugInManager.h
@@ -202,7 +202,7 @@
     Vector<String8> getPlugInPathList(const String8& rsDirPath) {
         Vector<String8> fileList;
         DIR* pDir = opendir(rsDirPath.string());
-        struct dirent* pEntry = new dirent();
+        struct dirent* pEntry;
 
         while (NULL != pDir && NULL != (pEntry = readdir(pDir))) {
             if (!isPlugIn(pEntry)) {
@@ -219,8 +219,6 @@
         if (NULL != pDir) {
             closedir(pDir);
         }
-        delete pEntry;
-        pEntry = NULL;
 
         return fileList;
     }
diff --git a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp
index d430f72..07b3b47 100644
--- a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp
+++ b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp
@@ -53,11 +53,11 @@
 }
 
 FwdLockEngine::FwdLockEngine() {
-    LOGD("FwdLockEngine Construction");
+    LOGV("FwdLockEngine Construction");
 }
 
 FwdLockEngine::~FwdLockEngine() {
-    LOGD("FwdLockEngine Destruction");
+    LOGV("FwdLockEngine Destruction");
 
     convertSessionMap.destroyMap();
     decodeSessionMap.destroyMap();
@@ -91,7 +91,7 @@
 DrmConstraints* FwdLockEngine::onGetConstraints(int uniqueId, const String8* path, int action) {
     DrmConstraints* drmConstraints = NULL;
 
-    LOGD("FwdLockEngine::onGetConstraints");
+    LOGV("FwdLockEngine::onGetConstraints");
 
     if (NULL != path &&
         (RightsStatus::RIGHTS_VALID == onCheckRightsStatus(uniqueId, *path, action))) {
@@ -105,7 +105,7 @@
 DrmMetadata* FwdLockEngine::onGetMetadata(int uniqueId, const String8* path) {
     DrmMetadata* drmMetadata = NULL;
 
-    LOGD("FwdLockEngine::onGetMetadata");
+    LOGV("FwdLockEngine::onGetMetadata");
 
     if (NULL != path) {
         // Returns empty metadata to show no error condition.
@@ -116,11 +116,11 @@
 }
 
 android::status_t FwdLockEngine::onInitialize(int uniqueId) {
-    LOGD("FwdLockEngine::onInitialize");
+    LOGV("FwdLockEngine::onInitialize");
 
 
     if (FwdLockGlue_InitializeKeyEncryption()) {
-        LOGD("FwdLockEngine::onInitialize -- FwdLockGlue_InitializeKeyEncryption succeeded");
+        LOGV("FwdLockEngine::onInitialize -- FwdLockGlue_InitializeKeyEncryption succeeded");
     } else {
         LOGD("FwdLockEngine::onInitialize -- FwdLockGlue_InitializeKeyEncryption failed:"
              "errno = %d", errno);
@@ -132,13 +132,13 @@
 android::status_t
 FwdLockEngine::onSetOnInfoListener(int uniqueId, const IDrmEngine::OnInfoListener* infoListener) {
     // Not used
-    LOGD("FwdLockEngine::onSetOnInfoListener");
+    LOGV("FwdLockEngine::onSetOnInfoListener");
 
     return DRM_NO_ERROR;
 }
 
 android::status_t FwdLockEngine::onTerminate(int uniqueId) {
-    LOGD("FwdLockEngine::onTerminate");
+    LOGV("FwdLockEngine::onTerminate");
 
     return DRM_NO_ERROR;
 }
@@ -146,7 +146,7 @@
 DrmSupportInfo* FwdLockEngine::onGetSupportInfo(int uniqueId) {
     DrmSupportInfo* pSupportInfo = new DrmSupportInfo();
 
-    LOGD("FwdLockEngine::onGetSupportInfo");
+    LOGV("FwdLockEngine::onGetSupportInfo");
 
     // fill all Forward Lock mimetypes and extensions
     if (NULL != pSupportInfo) {
@@ -182,7 +182,7 @@
 
     drmInfoStatus = new DrmInfoStatus((int)DrmInfoStatus::STATUS_OK, 0, NULL, String8(""));
 
-    LOGD("FwdLockEngine::onProcessDrmInfo");
+    LOGV("FwdLockEngine::onProcessDrmInfo");
 
     return drmInfoStatus;
 }
@@ -193,7 +193,7 @@
             const String8& rightsPath,
             const String8& contentPath) {
     // No rights to save. Return
-    LOGD("FwdLockEngine::onSaveRights");
+    LOGV("FwdLockEngine::onSaveRights");
     return DRM_ERROR_UNKNOWN;
 }
 
@@ -201,7 +201,7 @@
     DrmInfo* drmInfo = NULL;
 
     // Nothing to be done for Forward Lock file
-    LOGD("FwdLockEngine::onAcquireDrmInfo");
+    LOGV("FwdLockEngine::onAcquireDrmInfo");
 
     return drmInfo;
 }
@@ -211,7 +211,7 @@
                                        int action) {
     int result = RightsStatus::RIGHTS_INVALID;
 
-    LOGD("FwdLockEngine::onCheckRightsStatus");
+    LOGV("FwdLockEngine::onCheckRightsStatus");
 
     // Only Transfer action is not allowed for forward Lock files.
     if (onCanHandle(uniqueId, path)) {
@@ -241,7 +241,7 @@
                                         int action,
                                         bool reserve) {
     // No rights consumption
-    LOGD("FwdLockEngine::onConsumeRights");
+    LOGV("FwdLockEngine::onConsumeRights");
     return DRM_NO_ERROR;
 }
 
@@ -249,14 +249,14 @@
                                      const String8& path,
                                      int action,
                                      const ActionDescription& description) {
-    LOGD("FwdLockEngine::onValidateAction");
+    LOGV("FwdLockEngine::onValidateAction");
 
     // For the forwardlock engine checkRights and ValidateAction are the same.
     return (onCheckRightsStatus(uniqueId, path, action) == RightsStatus::RIGHTS_VALID);
 }
 
 String8 FwdLockEngine::onGetOriginalMimeType(int uniqueId, const String8& path) {
-    LOGD("FwdLockEngine::onGetOriginalMimeType");
+    LOGV("FwdLockEngine::onGetOriginalMimeType");
     String8 mimeString = String8("");
     int fileDesc = FwdLockFile_open(path.string());
 
@@ -280,7 +280,7 @@
                                       const String8& mimeType) {
     String8 mimeStr = String8(mimeType);
 
-    LOGD("FwdLockEngine::onGetDrmObjectType");
+    LOGV("FwdLockEngine::onGetDrmObjectType");
 
     mimeStr.toLower();
 
@@ -301,13 +301,13 @@
 
 status_t FwdLockEngine::onRemoveRights(int uniqueId, const String8& path) {
     // No Rights to remove
-    LOGD("FwdLockEngine::onRemoveRights");
+    LOGV("FwdLockEngine::onRemoveRights");
     return DRM_NO_ERROR;
 }
 
 status_t FwdLockEngine::onRemoveAllRights(int uniqueId) {
     // No rights to remove
-    LOGD("FwdLockEngine::onRemoveAllRights");
+    LOGV("FwdLockEngine::onRemoveAllRights");
     return DRM_NO_ERROR;
 }
 
@@ -319,14 +319,14 @@
                                             int playbackStatus, int position) {
 #endif
     // Not used
-    LOGD("FwdLockEngine::onSetPlaybackStatus");
+    LOGV("FwdLockEngine::onSetPlaybackStatus");
     return DRM_NO_ERROR;
 }
 
 status_t FwdLockEngine::onOpenConvertSession(int uniqueId,
                                          int convertId) {
     status_t result = DRM_ERROR_UNKNOWN;
-    LOGD("FwdLockEngine::onOpenConvertSession");
+    LOGV("FwdLockEngine::onOpenConvertSession");
     if (!convertSessionMap.isCreated(convertId)) {
         ConvertSession *newSession = new ConvertSession();
         if (FwdLockConv_Status_OK ==
@@ -383,7 +383,7 @@
     DrmBuffer *convResult = new DrmBuffer(NULL, 0);
     int offset = -1;
 
-    LOGD("FwdLockEngine::onCloseConvertSession");
+    LOGV("FwdLockEngine::onCloseConvertSession");
 
     if (convertSessionMap.isCreated(convertId)) {
         ConvertSession *convSession = convertSessionMap.getValue(convertId);
@@ -424,7 +424,7 @@
     status_t result = DRM_ERROR_CANNOT_HANDLE;
     int fileDesc = -1;
 
-    LOGD("FwdLockEngine::onOpenDecryptSession");
+    LOGV("FwdLockEngine::onOpenDecryptSession");
 
     if ((-1 < fd) &&
         (NULL != decryptHandle) &&
@@ -455,12 +455,15 @@
         } else {
             LOGD("FwdLockEngine::onOpenDecryptSession Integrity Check failed for the fd");
             FwdLockFile_detach(fileDesc);
-            ::close(fileDesc);
             delete decodeSession;
         }
     }
 
-    LOGD("FwdLockEngine::onOpenDecryptSession Exit. result = %d", result);
+    if (DRM_NO_ERROR != result && -1 < fileDesc) {
+        ::close(fileDesc);
+    }
+
+    LOGV("FwdLockEngine::onOpenDecryptSession Exit. result = %d", result);
 
     return result;
 }
@@ -497,7 +500,7 @@
 status_t FwdLockEngine::onCloseDecryptSession(int uniqueId,
                                               DecryptHandle* decryptHandle) {
     status_t result = DRM_ERROR_UNKNOWN;
-    LOGD("FwdLockEngine::onCloseDecryptSession");
+    LOGV("FwdLockEngine::onCloseDecryptSession");
 
     if (NULL != decryptHandle && decodeSessionMap.isCreated(decryptHandle->decryptId)) {
         DecodeSession* session = decodeSessionMap.getValue(decryptHandle->decryptId);
@@ -509,7 +512,7 @@
         }
     }
 
-    LOGD("FwdLockEngine::onCloseDecryptSession Exit");
+    LOGV("FwdLockEngine::onCloseDecryptSession Exit");
     return result;
 }
 
@@ -517,13 +520,13 @@
                                                 DecryptHandle* decryptHandle,
                                                 int decryptUnitId,
                                                 const DrmBuffer* headerInfo) {
-    LOGD("FwdLockEngine::onInitializeDecryptUnit");
+    LOGV("FwdLockEngine::onInitializeDecryptUnit");
     return DRM_ERROR_UNKNOWN;
 }
 
 status_t FwdLockEngine::onDecrypt(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId,
             const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) {
-    LOGD("FwdLockEngine::onDecrypt");
+    LOGV("FwdLockEngine::onDecrypt");
     return DRM_ERROR_UNKNOWN;
 }
 
@@ -532,14 +535,14 @@
                                   int decryptUnitId,
                                   const DrmBuffer* encBuffer,
                                   DrmBuffer** decBuffer) {
-    LOGD("FwdLockEngine::onDecrypt");
+    LOGV("FwdLockEngine::onDecrypt");
     return DRM_ERROR_UNKNOWN;
 }
 
 status_t FwdLockEngine::onFinalizeDecryptUnit(int uniqueId,
                                               DecryptHandle* decryptHandle,
                                               int decryptUnitId) {
-    LOGD("FwdLockEngine::onFinalizeDecryptUnit");
+    LOGV("FwdLockEngine::onFinalizeDecryptUnit");
     return DRM_ERROR_UNKNOWN;
 }
 
diff --git a/graphics/java/android/graphics/ParcelSurfaceTexture.aidl b/graphics/java/android/graphics/ParcelSurfaceTexture.aidl
new file mode 100644
index 0000000..35ff285
--- /dev/null
+++ b/graphics/java/android/graphics/ParcelSurfaceTexture.aidl
@@ -0,0 +1,19 @@
+/**
+ * Copyright (c) 2011, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.graphics;
+
+parcelable ParcelSurfaceTexture;
diff --git a/graphics/java/android/graphics/ParcelSurfaceTexture.java b/graphics/java/android/graphics/ParcelSurfaceTexture.java
new file mode 100644
index 0000000..5272cc6
--- /dev/null
+++ b/graphics/java/android/graphics/ParcelSurfaceTexture.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.graphics;
+
+import android.graphics.SurfaceTexture;
+import android.os.Parcel;
+import android.os.Parcelable;
+
+/**
+ *
+ * @hide Pending review by API council.
+ */
+public final class ParcelSurfaceTexture implements Parcelable {
+    /**
+     * This field is used by native code, do not access or modify.
+     *
+     * @hide
+     */
+    @SuppressWarnings({"UnusedDeclaration"})
+    private int mISurfaceTexture;
+
+    /**
+     * Create a new ParcelSurfaceTexture from a SurfaceTexture
+     *
+     * @param surfaceTexture The SurfaceTexture to transport.
+     *
+     * @return Returns a new ParcelSurfaceTexture for the given SurfaceTexture.
+     */
+    public static ParcelSurfaceTexture fromSurfaceTexture(SurfaceTexture surfaceTexture) {
+        return new ParcelSurfaceTexture(surfaceTexture);
+    }
+
+    /**
+     * @see android.os.Parcelable#describeContents()
+     */
+    @Override
+    public int describeContents() {
+        return 0;
+    }
+
+    /**
+     * @see android.os.Parcelable#writeToParcel(android.os.Parcel, int)
+     */
+    @Override
+    public void writeToParcel(Parcel dest, int flags) {
+        nativeWriteToParcel(dest, flags);
+    }
+
+    public static final Parcelable.Creator<ParcelSurfaceTexture> CREATOR =
+        new Parcelable.Creator<ParcelSurfaceTexture>() {
+        @Override
+        public ParcelSurfaceTexture createFromParcel(Parcel in) {
+            return new ParcelSurfaceTexture(in);
+        }
+        @Override
+        public ParcelSurfaceTexture[] newArray(int size) {
+            return new ParcelSurfaceTexture[size];
+        }
+    };
+
+    private ParcelSurfaceTexture(Parcel in) {
+        nativeReadFromParcel(in);
+    }
+    private ParcelSurfaceTexture(SurfaceTexture surfaceTexture) {
+        nativeInit(surfaceTexture);
+    }
+
+    @Override
+    protected void finalize() throws Throwable {
+        try {
+            nativeFinalize();
+        } finally {
+            super.finalize();
+        }
+    }
+
+    private native void nativeInit(SurfaceTexture surfaceTexture);
+    private native void nativeFinalize();
+    private native void nativeWriteToParcel(Parcel dest, int flags);
+    private native void nativeReadFromParcel(Parcel in);
+
+    /*
+     * We use a class initializer to allow the native code to cache some
+     * field offsets.
+     */
+    private static native void nativeClassInit();
+    static { nativeClassInit(); }
+}
diff --git a/graphics/java/android/graphics/SurfaceTexture.java b/graphics/java/android/graphics/SurfaceTexture.java
index 3c43a39..6c7341f 100644
--- a/graphics/java/android/graphics/SurfaceTexture.java
+++ b/graphics/java/android/graphics/SurfaceTexture.java
@@ -66,11 +66,8 @@
 
     /**
      * This field is used by native code, do not access or modify.
-     * 
-     * @hide
      */
-    @SuppressWarnings({"UnusedDeclaration"})
-    public int mSurfaceTexture;
+    private int mSurfaceTexture;
 
     /**
      * Callback interface for being notified that a new stream frame is available.
@@ -118,6 +115,16 @@
     }
 
     /**
+     * Set the size of buffers returned by requestBuffers when a width and height
+     * of zero is requested.
+     *
+     * @hide Pending approval by API council.
+     */
+    public void setDefaultBufferSize(int width, int height) {
+        nativeSetDefaultBufferSize(width, height);
+    }
+
+    /**
      * Update the texture image to the most recent frame from the image stream.  This may only be
      * called while the OpenGL ES context that owns the texture is bound to the thread.  It will
      * implicitly bind its texture to the GL_TEXTURE_EXTERNAL_OES texture target.
@@ -206,6 +213,7 @@
     private native void nativeFinalize();
     private native void nativeGetTransformMatrix(float[] mtx);
     private native long nativeGetTimestamp();
+    private native void nativeSetDefaultBufferSize(int width, int height);
     private native void nativeUpdateTexImage();
 
     /*
diff --git a/graphics/java/android/graphics/drawable/AnimationDrawable.java b/graphics/java/android/graphics/drawable/AnimationDrawable.java
index e275ba8..2220f96 100644
--- a/graphics/java/android/graphics/drawable/AnimationDrawable.java
+++ b/graphics/java/android/graphics/drawable/AnimationDrawable.java
@@ -62,7 +62,7 @@
  * AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();
  *
  * // Start the animation (looped playback by default).
- * frameAnimation.start()
+ * frameAnimation.start();
  * </pre>
  * <p>For more information, see the guide to <a
  * href="{@docRoot}guide/topics/resources/animation-resource.html">Animation Resources</a>.</p>
@@ -192,6 +192,9 @@
      */
     public void addFrame(Drawable frame, int duration) {
         mAnimationState.addFrame(frame, duration);
+        if (mCurFrame < 0) {
+            setFrame(0, true, false);
+        }
     }
     
     private void nextFrame(boolean unschedule) {
diff --git a/graphics/java/android/graphics/drawable/BitmapDrawable.java b/graphics/java/android/graphics/drawable/BitmapDrawable.java
index 311f024..a4734ff 100644
--- a/graphics/java/android/graphics/drawable/BitmapDrawable.java
+++ b/graphics/java/android/graphics/drawable/BitmapDrawable.java
@@ -30,6 +30,7 @@
 import android.util.AttributeSet;
 import android.util.DisplayMetrics;
 import android.view.Gravity;
+import android.view.View;
 
 import org.xmlpull.v1.XmlPullParser;
 import org.xmlpull.v1.XmlPullParserException;
@@ -386,8 +387,9 @@
             Shader shader = state.mPaint.getShader();
             if (shader == null) {
                 if (mApplyGravity) {
+                    final int layoutDirection = getResolvedLayoutDirectionSelf();
                     Gravity.apply(state.mGravity, mBitmapWidth, mBitmapHeight,
-                            getBounds(), mDstRect, isLayoutRtlSelf());
+                            getBounds(), mDstRect, layoutDirection);
                     mApplyGravity = false;
                 }
                 canvas.drawBitmap(bitmap, null, mDstRect, state.mPaint);
diff --git a/graphics/java/android/graphics/drawable/ClipDrawable.java b/graphics/java/android/graphics/drawable/ClipDrawable.java
index 83020aa..29edc04 100644
--- a/graphics/java/android/graphics/drawable/ClipDrawable.java
+++ b/graphics/java/android/graphics/drawable/ClipDrawable.java
@@ -24,6 +24,7 @@
 import android.graphics.*;
 import android.view.Gravity;
 import android.util.AttributeSet;
+import android.view.View;
 
 import java.io.IOException;
 
@@ -209,7 +210,8 @@
         if ((mClipState.mOrientation & VERTICAL) != 0) {
             h -= (h - ih) * (10000 - level) / 10000;
         }
-        Gravity.apply(mClipState.mGravity, w, h, bounds, r, isLayoutRtlSelf());
+        final int layoutDirection = getResolvedLayoutDirectionSelf();
+        Gravity.apply(mClipState.mGravity, w, h, bounds, r, layoutDirection);
 
         if (w > 0 && h > 0) {
             canvas.save();
diff --git a/graphics/java/android/graphics/drawable/Drawable.java b/graphics/java/android/graphics/drawable/Drawable.java
index 8994efc..72d233a3 100644
--- a/graphics/java/android/graphics/drawable/Drawable.java
+++ b/graphics/java/android/graphics/drawable/Drawable.java
@@ -36,6 +36,7 @@
 import android.util.StateSet;
 import android.util.TypedValue;
 import android.util.Xml;
+import android.view.View;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -292,11 +293,11 @@
      */
     public static interface Callback2 extends Callback {
         /**
-         * A Drawable can call this to know whether the <var>who</var> is in RTL layout direction.
+         * A Drawable can call this to get the resolved layout direction of the <var>who</var>.
          *
-         * @param who The drawable being unscheduled.
+         * @param who The drawable being queried.
          */
-        public boolean isLayoutRtl(Drawable who);
+        public int getResolvedLayoutDirection(Drawable who);
     }
 
     /**
@@ -376,15 +377,15 @@
     }
 
     /**
-     * Use the current {@link android.graphics.drawable.Drawable.Callback2} implementation to know
-     * if this Drawable is having a layout in RTL direction.
+     * Use the current {@link android.graphics.drawable.Drawable.Callback2} implementation to get
+     * the resolved layout direction of this Drawable.
      */
-    public boolean isLayoutRtlSelf() {
+    public int getResolvedLayoutDirectionSelf() {
         final Callback callback = getCallback();
         if (callback == null || !(callback instanceof Callback2)) {
-            return false;
+            return View.LAYOUT_DIRECTION_LTR;
         }
-        return ((Callback2) callback).isLayoutRtl(this);
+        return ((Callback2) callback).getResolvedLayoutDirection(this);
     }
 
     /**
diff --git a/graphics/java/android/graphics/drawable/ScaleDrawable.java b/graphics/java/android/graphics/drawable/ScaleDrawable.java
index cbe1f2d..5fd5a16 100644
--- a/graphics/java/android/graphics/drawable/ScaleDrawable.java
+++ b/graphics/java/android/graphics/drawable/ScaleDrawable.java
@@ -24,6 +24,7 @@
 import android.graphics.*;
 import android.view.Gravity;
 import android.util.AttributeSet;
+import android.view.View;
 
 import java.io.IOException;
 
@@ -221,7 +222,8 @@
             final int ih = min ? mScaleState.mDrawable.getIntrinsicHeight() : 0;
             h -= (int) ((h - ih) * (10000 - level) * mScaleState.mScaleHeight / 10000);
         }
-        Gravity.apply(mScaleState.mGravity, w, h, bounds, r, isLayoutRtlSelf());
+        final int layoutDirection = getResolvedLayoutDirectionSelf();
+        Gravity.apply(mScaleState.mGravity, w, h, bounds, r, layoutDirection);
 
         if (w > 0 && h > 0) {
             mScaleState.mDrawable.setBounds(r.left, r.top, r.right, r.bottom);
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java
index d477f8e..e900584 100644
--- a/graphics/java/android/renderscript/Allocation.java
+++ b/graphics/java/android/renderscript/Allocation.java
@@ -100,7 +100,6 @@
     public static final int USAGE_GRAPHICS_CONSTANTS = 0x0008;
 
     /**
-     * @hide
      * USAGE_GRAPHICS_RENDER_TARGET The allcation will be used as a
      * target for offscreen rendering
      *
@@ -589,13 +588,29 @@
      *
      * @param off The offset of the first element to be copied.
      * @param count The number of elements to be copied.
-     * @param d the source data array
+     * @param d the source data array.
      */
     public void copy1DRangeFrom(int off, int count, float[] d) {
         validateIsFloat32();
         copy1DRangeFromUnchecked(off, count, d);
     }
 
+     /**
+     * Copy part of an allocation from another allocation.
+     *
+     * @param off The offset of the first element to be copied.
+     * @param count The number of elements to be copied.
+     * @param data the source data allocation.
+     * @param dataOff off The offset of the first element in data to
+     *          be copied.
+     */
+    public void copy1DRangeFrom(int off, int count, Allocation data, int dataOff) {
+        mRS.nAllocationData2D(getID(), off, 0,
+                              0, Type.CubemapFace.POSITIVE_X.mID,
+                              count, 1, data.getID(), dataOff, 0,
+                              0, Type.CubemapFace.POSITIVE_X.mID);
+    }
+
     private void validate2DRange(int xoff, int yoff, int w, int h) {
         if (xoff < 0 || yoff < 0) {
             throw new RSIllegalArgumentException("Offset cannot be negative.");
@@ -610,9 +625,8 @@
     }
 
     /**
-     * Copy a rectanglular region from the array into the
-     * allocation.  The incoming array is assumed to be tightly
-     * packed.
+     * Copy a rectangular region from the array into the allocation.
+     * The incoming array is assumed to be tightly packed.
      *
      * @param xoff X offset of the region to update
      * @param yoff Y offset of the region to update
@@ -645,6 +659,28 @@
     }
 
     /**
+     * Copy a rectangular region into the allocation from another
+     * allocation.
+     *
+     * @param xoff X offset of the region to update.
+     * @param yoff Y offset of the region to update.
+     * @param w Width of the incoming region to update.
+     * @param h Height of the incoming region to update.
+     * @param data source allocation.
+     * @param dataXoff X offset in data of the region to update.
+     * @param dataYoff Y offset in data of the region to update.
+     */
+    public void copy2DRangeFrom(int xoff, int yoff, int w, int h,
+                                Allocation data, int dataXoff, int dataYoff) {
+        mRS.validate();
+        validate2DRange(xoff, yoff, w, h);
+        mRS.nAllocationData2D(getID(), xoff, yoff,
+                              0, Type.CubemapFace.POSITIVE_X.mID,
+                              w, h, data.getID(), dataXoff, dataYoff,
+                              0, Type.CubemapFace.POSITIVE_X.mID);
+    }
+
+    /**
      * Copy a bitmap into an allocation.  The height and width of
      * the update will use the height and width of the incoming
      * bitmap.
@@ -1012,15 +1048,15 @@
         Allocation cubemap = Allocation.createTyped(rs, t, mips, usage);
 
         AllocationAdapter adapter = AllocationAdapter.create2D(rs, cubemap);
-        adapter.setFace(Type.CubemapFace.POSITVE_X);
+        adapter.setFace(Type.CubemapFace.POSITIVE_X);
         adapter.copyFrom(xpos);
         adapter.setFace(Type.CubemapFace.NEGATIVE_X);
         adapter.copyFrom(xneg);
-        adapter.setFace(Type.CubemapFace.POSITVE_Y);
+        adapter.setFace(Type.CubemapFace.POSITIVE_Y);
         adapter.copyFrom(ypos);
         adapter.setFace(Type.CubemapFace.NEGATIVE_Y);
         adapter.copyFrom(yneg);
-        adapter.setFace(Type.CubemapFace.POSITVE_Z);
+        adapter.setFace(Type.CubemapFace.POSITIVE_Z);
         adapter.copyFrom(zpos);
         adapter.setFace(Type.CubemapFace.NEGATIVE_Z);
         adapter.copyFrom(zneg);
diff --git a/graphics/java/android/renderscript/AllocationAdapter.java b/graphics/java/android/renderscript/AllocationAdapter.java
index f2fedea..61f2e1f 100644
--- a/graphics/java/android/renderscript/AllocationAdapter.java
+++ b/graphics/java/android/renderscript/AllocationAdapter.java
@@ -33,7 +33,7 @@
     private Allocation mAlloc;
 
     private int mSelectedLOD = 0;
-    private Type.CubemapFace mSelectedFace = Type.CubemapFace.POSITVE_X;;
+    private Type.CubemapFace mSelectedFace = Type.CubemapFace.POSITIVE_X;
 
     AllocationAdapter(int id, RenderScript rs, Allocation alloc) {
         super(id, rs, null, alloc.mUsage);
@@ -163,15 +163,54 @@
         mRS.nAllocationData1D(getID(), off, mSelectedLOD, count, d, dataSize);
     }
 
+    /**
+     * Copy part of an allocation from another allocation.
+     *
+     * @param off The offset of the first element to be copied.
+     * @param count The number of elements to be copied.
+     * @param data the source data allocation.
+     * @param dataOff off The offset of the first element in data to
+     *          be copied.
+     */
+    public void subData1D(int off, int count, AllocationAdapter data, int dataOff) {
+        mRS.nAllocationData2D(getID(), off, 0,
+                              mSelectedLOD, mSelectedFace.mID,
+                              count, 1, data.getID(), dataOff, 0,
+                              data.mSelectedLOD, data.mSelectedFace.mID);
+    }
+
 
     public void subData2D(int xoff, int yoff, int w, int h, int[] d) {
         mRS.validate();
-        mRS.nAllocationData2D(getID(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, w, h, d, d.length * 4);
+        mRS.nAllocationData2D(getID(), xoff, yoff, mSelectedLOD, mSelectedFace.mID,
+                              w, h, d, d.length * 4);
     }
 
     public void subData2D(int xoff, int yoff, int w, int h, float[] d) {
         mRS.validate();
-        mRS.nAllocationData2D(getID(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, w, h, d, d.length * 4);
+        mRS.nAllocationData2D(getID(), xoff, yoff, mSelectedLOD, mSelectedFace.mID,
+                              w, h, d, d.length * 4);
+    }
+
+    /**
+     * Copy a rectangular region into the allocation from another
+     * allocation.
+     *
+     * @param xoff X offset of the region to update.
+     * @param yoff Y offset of the region to update.
+     * @param w Width of the incoming region to update.
+     * @param h Height of the incoming region to update.
+     * @param data source allocation.
+     * @param dataXoff X offset in data of the region to update.
+     * @param dataYoff Y offset in data of the region to update.
+     */
+    public void subData2D(int xoff, int yoff, int w, int h,
+                          AllocationAdapter data, int dataXoff, int dataYoff) {
+        mRS.validate();
+        mRS.nAllocationData2D(getID(), xoff, yoff,
+                              mSelectedLOD, mSelectedFace.mID,
+                              w, h, data.getID(), dataXoff, dataYoff,
+                              data.mSelectedLOD, data.mSelectedFace.mID);
     }
 
     public void readData(int[] d) {
@@ -185,12 +224,15 @@
     }
 
     public void setLOD(int lod) {
+        mSelectedLOD = lod;
     }
 
     public void setFace(Type.CubemapFace cf) {
+        mSelectedFace = cf;
     }
 
     public void setY(int y) {
+        mSelectedDimY = y;
     }
 
     public void setZ(int z) {
diff --git a/graphics/java/android/renderscript/BaseObj.java b/graphics/java/android/renderscript/BaseObj.java
index a17e735..63e7dd1 100644
--- a/graphics/java/android/renderscript/BaseObj.java
+++ b/graphics/java/android/renderscript/BaseObj.java
@@ -134,5 +134,35 @@
         mName = mRS.nGetName(getID());
     }
 
+    /**
+     * Calculates the hash code value for a BaseObj.
+     *
+     * @return int
+     */
+    @Override
+    public int hashCode() {
+        return mID;
+    }
+
+    /**
+     * Compare the current BaseObj with another BaseObj for equality.
+     *
+     * @param obj The object to check equality with.
+     *
+     * @return boolean
+     */
+    @Override
+    public boolean equals(Object obj) {
+        // Early-out check to see if both BaseObjs are actually the same
+        if (this == obj)
+            return true;
+
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+
+        BaseObj b = (BaseObj) obj;
+        return mID == b.mID;
+    }
 }
 
diff --git a/graphics/java/android/renderscript/Element.java b/graphics/java/android/renderscript/Element.java
index a96eedd..f844331 100644
--- a/graphics/java/android/renderscript/Element.java
+++ b/graphics/java/android/renderscript/Element.java
@@ -32,8 +32,8 @@
  * <p>Complex elements contain a list of sub-elements and names that
  * represents a structure of data. The fields can be accessed by name
  * from a script or shader. The memory layout is defined and ordered. Data
- * alignment is determinied by the most basic primitive type. i.e. a float4
- * vector will be alligned to sizeof(float) and not sizeof(float4).  The
+ * alignment is determined by the most basic primitive type. i.e. a float4
+ * vector will be aligned to sizeof(float) and not sizeof(float4). The
  * ordering of elements in memory will be the order in which they were added
  * with each component aligned as necessary. No re-ordering will be done.</p>
  *
@@ -766,6 +766,33 @@
     }
 
     /**
+     * Check if the current Element is compatible with another Element.
+     * Primitive Elements are compatible if they share the same underlying
+     * size and type (i.e. U8 is compatible with A_8). User-defined Elements
+     * must be equal in order to be compatible. This requires strict name
+     * equivalence for all sub-Elements (in addition to structural equivalence).
+     *
+     * @param e The Element to check compatibility with.
+     *
+     * @return boolean true if the Elements are compatible, otherwise false.
+     */
+    public boolean isCompatible(Element e) {
+        // Try strict BaseObj equality to start with.
+        if (this.equals(e)) {
+            return true;
+        }
+
+        // Ignore mKind because it is allowed to be different (user vs. pixel).
+        // We also ignore mNormalized because it can be different. The mType
+        // field must be non-null since we require name equivalence for
+        // user-created Elements.
+        return ((mSize == e.mSize) &&
+                (mType != null) &&
+                (mType == e.mType) &&
+                (mVectorSize == e.mVectorSize));
+    }
+
+    /**
      * Builder class for producing complex elements with matching field and name
      * pairs.  The builder starts empty.  The order in which elements are added
      * is retained for the layout in memory.
diff --git a/graphics/java/android/renderscript/FieldPacker.java b/graphics/java/android/renderscript/FieldPacker.java
index bdda830..fac7144 100644
--- a/graphics/java/android/renderscript/FieldPacker.java
+++ b/graphics/java/android/renderscript/FieldPacker.java
@@ -25,10 +25,15 @@
 public class FieldPacker {
     public FieldPacker(int len) {
         mPos = 0;
+        mLen = len;
         mData = new byte[len];
     }
 
     public void align(int v) {
+        if ((v <= 0) || ((v & (v - 1)) != 0)) {
+            throw new RSIllegalArgumentException("argument must be a non-negative non-zero power of 2: " + v);
+        }
+
         while ((mPos & (v - 1)) != 0) {
             mData[mPos++] = 0;
         }
@@ -38,11 +43,18 @@
         mPos = 0;
     }
     public void reset(int i) {
+        if ((i < 0) || (i >= mLen)) {
+            throw new RSIllegalArgumentException("out of range argument: " + i);
+        }
         mPos = i;
     }
 
     public void skip(int i) {
-        mPos += i;
+        int res = mPos + i;
+        if ((res < 0) || (res > mLen)) {
+            throw new RSIllegalArgumentException("out of range argument: " + i);
+        }
+        mPos = res;
     }
 
     public void addI8(byte v) {
@@ -277,6 +289,7 @@
 
     private final byte mData[];
     private int mPos;
+    private int mLen;
 
 }
 
diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java
index 0d9607a..9941827 100644
--- a/graphics/java/android/renderscript/RenderScript.java
+++ b/graphics/java/android/renderscript/RenderScript.java
@@ -22,6 +22,7 @@
 import android.content.res.AssetManager;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
+import android.os.Process;
 import android.util.Log;
 import android.view.Surface;
 
@@ -294,6 +295,26 @@
         rsnAllocationElementData1D(mContext, id, xoff, mip, compIdx, d, sizeBytes);
     }
 
+    native void rsnAllocationData2D(int con,
+                                    int dstAlloc, int dstXoff, int dstYoff,
+                                    int dstMip, int dstFace,
+                                    int width, int height,
+                                    int srcAlloc, int srcXoff, int srcYoff,
+                                    int srcMip, int srcFace);
+    synchronized void nAllocationData2D(int dstAlloc, int dstXoff, int dstYoff,
+                                        int dstMip, int dstFace,
+                                        int width, int height,
+                                        int srcAlloc, int srcXoff, int srcYoff,
+                                        int srcMip, int srcFace) {
+        validate();
+        rsnAllocationData2D(mContext,
+                            dstAlloc, dstXoff, dstYoff,
+                            dstMip, dstFace,
+                            width, height,
+                            srcAlloc, srcXoff, srcYoff,
+                            srcMip, srcFace);
+    }
+
     native void rsnAllocationData2D(int con, int id, int xoff, int yoff, int mip, int face, int w, int h, byte[] d, int sizeBytes);
     synchronized void nAllocationData2D(int id, int xoff, int yoff, int mip, int face, int w, int h, byte[] d, int sizeBytes) {
         validate();
@@ -718,9 +739,8 @@
      * processes.
      */
     public enum Priority {
-        // Remap these numbers to opaque...
-        LOW (5),     //ANDROID_PRIORITY_BACKGROUND + 5
-        NORMAL (-4);  //ANDROID_PRIORITY_DISPLAY
+        LOW (Process.THREAD_PRIORITY_BACKGROUND + (5 * Process.THREAD_PRIORITY_LESS_FAVORABLE)),
+        NORMAL (Process.THREAD_PRIORITY_DISPLAY);
 
         int mID;
         Priority(int id) {
diff --git a/graphics/java/android/renderscript/Type.java b/graphics/java/android/renderscript/Type.java
index b39d2e4..f88af8b 100644
--- a/graphics/java/android/renderscript/Type.java
+++ b/graphics/java/android/renderscript/Type.java
@@ -46,12 +46,18 @@
     Element mElement;
 
     public enum CubemapFace {
-        POSITVE_X (0),
+        POSITIVE_X (0),
         NEGATIVE_X (1),
-        POSITVE_Y (2),
+        POSITIVE_Y (2),
         NEGATIVE_Y (3),
-        POSITVE_Z (4),
-        NEGATIVE_Z (5);
+        POSITIVE_Z (4),
+        NEGATIVE_Z (5),
+        @Deprecated
+        POSITVE_X (0),
+        @Deprecated
+        POSITVE_Y (2),
+        @Deprecated
+        POSITVE_Z (4);
 
         int mID;
         CubemapFace(int id) {
diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp
index 60b39b0..7e53cc4 100644
--- a/graphics/jni/android_renderscript_RenderScript.cpp
+++ b/graphics/jni/android_renderscript_RenderScript.cpp
@@ -468,7 +468,7 @@
     bitmap.lockPixels();
     const void* ptr = bitmap.getPixels();
     rsAllocation2DData(con, (RsAllocation)alloc, 0, 0,
-                       0, RS_ALLOCATION_CUBMAP_FACE_POSITVE_X,
+                       0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
                        w, h, ptr, bitmap.getSize());
     bitmap.unlockPixels();
 }
@@ -589,6 +589,30 @@
 }
 
 static void
+nAllocationData2D_alloc(JNIEnv *_env, jobject _this, RsContext con,
+                        jint dstAlloc, jint dstXoff, jint dstYoff,
+                        jint dstMip, jint dstFace,
+                        jint width, jint height,
+                        jint srcAlloc, jint srcXoff, jint srcYoff,
+                        jint srcMip, jint srcFace)
+{
+    LOG_API("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff, dstYoff,"
+            " dstMip(%i), dstFace(%i), width(%i), height(%i),"
+            " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)",
+            con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace,
+            width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace);
+
+    rsAllocationCopy2DRange(con,
+                            (RsAllocation)dstAlloc,
+                            dstXoff, dstYoff,
+                            dstMip, dstFace,
+                            width, height,
+                            (RsAllocation)srcAlloc,
+                            srcXoff, srcYoff,
+                            srcMip, srcFace);
+}
+
+static void
 nAllocationRead_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jintArray data)
 {
     jint len = _env->GetArrayLength(data);
@@ -1217,6 +1241,7 @@
 {"rsnAllocationData2D",              "(IIIIIIII[SI)V",                        (void*)nAllocationData2D_s },
 {"rsnAllocationData2D",              "(IIIIIIII[BI)V",                        (void*)nAllocationData2D_b },
 {"rsnAllocationData2D",              "(IIIIIIII[FI)V",                        (void*)nAllocationData2D_f },
+{"rsnAllocationData2D",              "(IIIIIIIIIIIII)V",                      (void*)nAllocationData2D_alloc },
 {"rsnAllocationRead",                "(II[I)V",                               (void*)nAllocationRead_i },
 {"rsnAllocationRead",                "(II[S)V",                               (void*)nAllocationRead_s },
 {"rsnAllocationRead",                "(II[B)V",                               (void*)nAllocationRead_b },
diff --git a/include/android_runtime/android_graphics_ParcelSurfaceTexture.h b/include/android_runtime/android_graphics_ParcelSurfaceTexture.h
new file mode 100644
index 0000000..b94ac9b
--- /dev/null
+++ b/include/android_runtime/android_graphics_ParcelSurfaceTexture.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _ANDROID_GRAPHICS_PARCELSURFACETEXTURE_H
+#define _ANDROID_GRAPHICS_PARCELSURFACETEXTURE_H
+
+#include <android/native_window.h>
+
+#include "jni.h"
+
+namespace android {
+
+class ISurfaceTexture;
+
+extern sp<ANativeWindow> android_ParcelSurfaceTexture_getNativeWindow(
+        JNIEnv* env, jobject thiz);
+extern bool android_ParcelSurfaceTexture_isInstanceOf(JNIEnv* env, jobject thiz);
+
+/* Gets the underlying ISurfaceTexture from a ParcelSurfaceTexture Java object. */
+extern sp<ISurfaceTexture> ParcelSurfaceTexture_getISurfaceTexture(JNIEnv* env, jobject thiz);
+
+} // namespace android
+
+#endif // _ANDROID_GRAPHICS_PARCELSURFACETEXTURE_H
diff --git a/include/android_runtime/android_graphics_SurfaceTexture.h b/include/android_runtime/android_graphics_SurfaceTexture.h
index 8e6fc6ee..badf22c 100644
--- a/include/android_runtime/android_graphics_SurfaceTexture.h
+++ b/include/android_runtime/android_graphics_SurfaceTexture.h
@@ -23,8 +23,14 @@
 
 namespace android {
 
+class SurfaceTexture;
+
 extern sp<ANativeWindow> android_SurfaceTexture_getNativeWindow(
         JNIEnv* env, jobject thiz);
+extern bool android_SurfaceTexture_isInstanceOf(JNIEnv* env, jobject thiz);
+
+/* Gets the underlying SurfaceTexture from a SurfaceTexture Java object. */
+extern sp<SurfaceTexture> SurfaceTexture_getSurfaceTexture(JNIEnv* env, jobject thiz);
 
 } // namespace android
 
diff --git a/include/android_runtime/android_view_Surface.h b/include/android_runtime/android_view_Surface.h
index c37932e..317f1e7 100644
--- a/include/android_runtime/android_view_Surface.h
+++ b/include/android_runtime/android_view_Surface.h
@@ -25,6 +25,7 @@
 
 extern sp<ANativeWindow> android_Surface_getNativeWindow(
         JNIEnv* env, jobject clazz);
+extern bool android_Surface_isInstanceOf(JNIEnv* env, jobject obj);
 
 } // namespace android
 
diff --git a/include/camera/CameraParameters.h b/include/camera/CameraParameters.h
index dc5fc84..83d4f6d 100644
--- a/include/camera/CameraParameters.h
+++ b/include/camera/CameraParameters.h
@@ -263,7 +263,7 @@
     // direction is not affected by the rotation or mirroring of
     // CAMERA_CMD_SET_DISPLAY_ORIENTATION. Coordinates range from -1000 to 1000.
     // (-1000,-1000) is the upper left point. (1000, 1000) is the lower right
-    // point. The length and width of focus areas cannot be 0 or negative.
+    // point. The width and height of focus areas cannot be 0 or negative.
     //
     // The fifth element is the weight. Values for weight must range from 1 to
     // 1000.  The weight should be interpreted as a per-pixel weight - all
@@ -373,7 +373,7 @@
     // direction is not affected by the rotation or mirroring of
     // CAMERA_CMD_SET_DISPLAY_ORIENTATION. Coordinates of the rectangle range
     // from -1000 to 1000. (-1000, -1000) is the upper left point. (1000, 1000)
-    // is the lower right point. The length and width of metering areas cannot
+    // is the lower right point. The width and height of metering areas cannot
     // be 0 or negative.
     //
     // The fifth element is the weight. Values for weight must range from 1 to
@@ -550,6 +550,7 @@
     static const char PIXEL_FORMAT_YUV422I[]; // YUY2
     static const char PIXEL_FORMAT_YUV420P[]; // YV12
     static const char PIXEL_FORMAT_RGB565[];
+    static const char PIXEL_FORMAT_RGBA8888[];
     static const char PIXEL_FORMAT_JPEG[];
 
     // Values for focus mode settings.
diff --git a/include/gui/SurfaceTexture.h b/include/gui/SurfaceTexture.h
index 2b31462..9294df6 100644
--- a/include/gui/SurfaceTexture.h
+++ b/include/gui/SurfaceTexture.h
@@ -188,6 +188,11 @@
 
     status_t setBufferCountServerLocked(int bufferCount);
 
+    // computeCurrentTransformMatrix computes the transform matrix for the
+    // current texture.  It uses mCurrentTransform and the current GraphicBuffer
+    // to compute this matrix and stores it in mCurrentTransformMatrix.
+    void computeCurrentTransformMatrix();
+
     enum { INVALID_BUFFER_SLOT = -1 };
 
     struct BufferSlot {
@@ -288,9 +293,9 @@
     // by calling setBufferCount or setBufferCountServer
     int mBufferCount;
 
-    // mRequestedBufferCount is the number of buffer slots requested by the
-    // client. The default is zero, which means the client doesn't care how
-    // many buffers there is.
+    // mClientBufferCount is the number of buffer slots requested by the client.
+    // The default is zero, which means the client doesn't care how many buffers
+    // there is.
     int mClientBufferCount;
 
     // mServerBufferCount buffer count requested by the server-side
@@ -322,6 +327,11 @@
     // gets set to mLastQueuedTransform each time updateTexImage is called.
     uint32_t mCurrentTransform;
 
+    // mCurrentTransformMatrix is the transform matrix for the current texture.
+    // It gets computed by computeTransformMatrix each time updateTexImage is
+    // called.
+    float mCurrentTransformMatrix[16];
+
     // mCurrentTimestamp is the timestamp for the current texture. It
     // gets set to mLastQueuedTimestamp each time updateTexImage is called.
     int64_t mCurrentTimestamp;
@@ -362,6 +372,7 @@
     // variables of SurfaceTexture objects. It must be locked whenever the
     // member variables are accessed.
     mutable Mutex mMutex;
+
 };
 
 // ----------------------------------------------------------------------------
diff --git a/include/media/AudioRecord.h b/include/media/AudioRecord.h
index baab2e8..605680a 100644
--- a/include/media/AudioRecord.h
+++ b/include/media/AudioRecord.h
@@ -130,7 +130,7 @@
      * sampleRate:         Track sampling rate in Hz.
      * format:             Audio format (e.g AUDIO_FORMAT_PCM_16_BIT for signed
      *                     16 bits per sample).
-     * channels:           Channel mask: see audio_channels_t.
+     * channelMask:        Channel mask: see audio_channels_t.
      * frameCount:         Total size of track PCM buffer in frames. This defines the
      *                     latency of the track.
      * flags:              A bitmask of acoustic values from enum record_flags.  It enables
@@ -151,7 +151,7 @@
                         AudioRecord(int inputSource,
                                     uint32_t sampleRate = 0,
                                     int format          = 0,
-                                    uint32_t channels = AUDIO_CHANNEL_IN_MONO,
+                                    uint32_t channelMask = AUDIO_CHANNEL_IN_MONO,
                                     int frameCount      = 0,
                                     uint32_t flags      = 0,
                                     callback_t cbf = 0,
@@ -177,7 +177,7 @@
             status_t    set(int inputSource     = 0,
                             uint32_t sampleRate = 0,
                             int format          = 0,
-                            uint32_t channels = AUDIO_CHANNEL_IN_MONO,
+                            uint32_t channelMask = AUDIO_CHANNEL_IN_MONO,
                             int frameCount      = 0,
                             uint32_t flags      = 0,
                             callback_t cbf = 0,
@@ -348,8 +348,8 @@
 
             bool processAudioBuffer(const sp<ClientRecordThread>& thread);
             status_t openRecord_l(uint32_t sampleRate,
-                                int format,
-                                int channelCount,
+                                uint32_t format,
+                                uint32_t channelMask,
                                 int frameCount,
                                 uint32_t flags,
                                 audio_io_handle_t input);
@@ -364,10 +364,10 @@
     uint32_t                mFrameCount;
 
     audio_track_cblk_t*     mCblk;
-    uint8_t                 mFormat;
+    uint32_t                mFormat;
     uint8_t                 mChannelCount;
     uint8_t                 mInputSource;
-    uint8_t                 mReserved;
+    uint8_t                 mReserved[2];
     status_t                mStatus;
     uint32_t                mLatency;
 
@@ -382,7 +382,7 @@
     uint32_t                mNewPosition;
     uint32_t                mUpdatePeriod;
     uint32_t                mFlags;
-    uint32_t                mChannels;
+    uint32_t                mChannelMask;
     audio_io_handle_t       mInput;
     int                     mSessionId;
 };
diff --git a/include/media/AudioSystem.h b/include/media/AudioSystem.h
index 68cd188..89213b7 100644
--- a/include/media/AudioSystem.h
+++ b/include/media/AudioSystem.h
@@ -22,7 +22,7 @@
 #include <media/IAudioFlinger.h>
 
 #include <system/audio.h>
-#include <hardware/audio_policy.h>
+#include <system/audio_policy.h>
 
 /* XXX: Should be include by all the users instead */
 #include <media/AudioParameter.h>
diff --git a/include/media/AudioTrack.h b/include/media/AudioTrack.h
index de928da..df30e8c 100644
--- a/include/media/AudioTrack.h
+++ b/include/media/AudioTrack.h
@@ -69,8 +69,8 @@
             MUTE    = 0x00000001
         };
         uint32_t    flags;
-        int         channelCount;
         int         format;
+        int         channelCount; // will be removed in the future, do not use
         size_t      frameCount;
         size_t      size;
         union {
@@ -129,7 +129,7 @@
      * sampleRate:         Track sampling rate in Hz.
      * format:             Audio format (e.g AUDIO_FORMAT_PCM_16_BIT for signed
      *                     16 bits per sample).
-     * channels:           Channel mask: see audio_channels_t.
+     * channelMask:        Channel mask: see audio_channels_t.
      * frameCount:         Total size of track PCM buffer in frames. This defines the
      *                     latency of the track.
      * flags:              Reserved for future use.
@@ -143,7 +143,7 @@
                         AudioTrack( int streamType,
                                     uint32_t sampleRate  = 0,
                                     int format           = 0,
-                                    int channels         = 0,
+                                    int channelMask      = 0,
                                     int frameCount       = 0,
                                     uint32_t flags       = 0,
                                     callback_t cbf       = 0,
@@ -163,7 +163,7 @@
                         AudioTrack( int streamType,
                                     uint32_t sampleRate = 0,
                                     int format          = 0,
-                                    int channels        = 0,
+                                    int channelMask     = 0,
                                     const sp<IMemory>& sharedBuffer = 0,
                                     uint32_t flags      = 0,
                                     callback_t cbf      = 0,
@@ -187,7 +187,7 @@
             status_t    set(int streamType      =-1,
                             uint32_t sampleRate = 0,
                             int format          = 0,
-                            int channels        = 0,
+                            int channelMask     = 0,
                             int frameCount      = 0,
                             uint32_t flags      = 0,
                             callback_t cbf      = 0,
@@ -438,8 +438,8 @@
             bool processAudioBuffer(const sp<AudioTrackThread>& thread);
             status_t createTrack_l(int streamType,
                                  uint32_t sampleRate,
-                                 int format,
-                                 int channelCount,
+                                 uint32_t format,
+                                 uint32_t channelMask,
                                  int frameCount,
                                  uint32_t flags,
                                  const sp<IMemory>& sharedBuffer,
@@ -459,11 +459,12 @@
     uint32_t                mFrameCount;
 
     audio_track_cblk_t*     mCblk;
+    uint32_t                mFormat;
     uint8_t                 mStreamType;
-    uint8_t                 mFormat;
     uint8_t                 mChannelCount;
     uint8_t                 mMuted;
-    uint32_t                mChannels;
+    uint8_t                 mReserved;
+    uint32_t                mChannelMask;
     status_t                mStatus;
     uint32_t                mLatency;
 
diff --git a/include/media/IAudioFlinger.h b/include/media/IAudioFlinger.h
index d8fdc27..4037c46 100644
--- a/include/media/IAudioFlinger.h
+++ b/include/media/IAudioFlinger.h
@@ -48,8 +48,8 @@
                                 pid_t pid,
                                 int streamType,
                                 uint32_t sampleRate,
-                                int format,
-                                int channelCount,
+                                uint32_t format,
+                                uint32_t channelMask,
                                 int frameCount,
                                 uint32_t flags,
                                 const sp<IMemory>& sharedBuffer,
@@ -61,8 +61,8 @@
                                 pid_t pid,
                                 int input,
                                 uint32_t sampleRate,
-                                int format,
-                                int channelCount,
+                                uint32_t format,
+                                uint32_t channelMask,
                                 int frameCount,
                                 uint32_t flags,
                                 int *sessionId,
@@ -73,7 +73,7 @@
      */
     virtual     uint32_t    sampleRate(int output) const = 0;
     virtual     int         channelCount(int output) const = 0;
-    virtual     int         format(int output) const = 0;
+    virtual     uint32_t    format(int output) const = 0;
     virtual     size_t      frameCount(int output) const = 0;
     virtual     uint32_t    latency(int output) const = 0;
 
diff --git a/include/media/IAudioPolicyService.h b/include/media/IAudioPolicyService.h
index 09b2bfe..0fc8dbf 100644
--- a/include/media/IAudioPolicyService.h
+++ b/include/media/IAudioPolicyService.h
@@ -26,7 +26,7 @@
 #include <binder/IInterface.h>
 #include <media/AudioSystem.h>
 
-#include <hardware/audio_policy.h>
+#include <system/audio_policy.h>
 
 namespace android {
 
diff --git a/include/media/MediaPlayerInterface.h b/include/media/MediaPlayerInterface.h
index f0401cca..18e8a5f 100644
--- a/include/media/MediaPlayerInterface.h
+++ b/include/media/MediaPlayerInterface.h
@@ -168,6 +168,10 @@
         if (mNotify) mNotify(mCookie, msg, ext1, ext2, obj);
     }
 
+    virtual status_t dump(int fd, const Vector<String16> &args) const {
+        return INVALID_OPERATION;
+    }
+
 private:
     friend class MediaPlayerService;
 
diff --git a/include/media/mediaplayer.h b/include/media/mediaplayer.h
index 50a378f..ea5a9d3 100644
--- a/include/media/mediaplayer.h
+++ b/include/media/mediaplayer.h
@@ -100,6 +100,9 @@
     MEDIA_INFO_BUFFERING_START = 701,
     // MediaPlayer is resuming playback after filling buffers.
     MEDIA_INFO_BUFFERING_END = 702,
+    // Bandwidth in recent past
+    MEDIA_INFO_NETWORK_BANDWIDTH = 703,
+
     // 8xx
     // Bad interleaving means that a media has been improperly interleaved or not
     // interleaved at all, e.g has all the video samples first then all the audio
@@ -128,6 +131,9 @@
 enum media_set_parameter_keys {
     KEY_PARAMETER_TIMED_TEXT_TRACK_INDEX = 1000,
     KEY_PARAMETER_TIMED_TEXT_ADD_OUT_OF_BAND_SOURCE = 1001,
+
+    // Streaming/buffering parameters
+    KEY_PARAMETER_CACHE_STAT_COLLECT_FREQ_MS = 1100,
 };
 // ----------------------------------------------------------------------------
 // ref-counted object for callbacks
diff --git a/include/media/stagefright/DataSource.h b/include/media/stagefright/DataSource.h
index 6b6fcdf..48d1464 100644
--- a/include/media/stagefright/DataSource.h
+++ b/include/media/stagefright/DataSource.h
@@ -38,6 +38,7 @@
         kWantsPrefetching      = 1,
         kStreamedFromLocalHost = 2,
         kIsCachingDataSource   = 4,
+        kIsHTTPBasedSource     = 8,
     };
 
     static sp<DataSource> CreateFromURI(
diff --git a/include/media/stagefright/MetaData.h b/include/media/stagefright/MetaData.h
index 4044c5d..deade5e 100644
--- a/include/media/stagefright/MetaData.h
+++ b/include/media/stagefright/MetaData.h
@@ -55,6 +55,7 @@
     kKeyIsSyncFrame       = 'sync',  // int32_t (bool)
     kKeyIsCodecConfig     = 'conf',  // int32_t (bool)
     kKeyTime              = 'time',  // int64_t (usecs)
+    kKeyDecodingTime      = 'decT',  // int64_t (decoding timestamp in usecs)
     kKeyNTPTime           = 'ntpT',  // uint64_t (ntp-timestamp)
     kKeyTargetTime        = 'tarT',  // int64_t (usecs)
     kKeyDriftTime         = 'dftT',  // int64_t (usecs)
diff --git a/include/media/stagefright/OMXCodec.h b/include/media/stagefright/OMXCodec.h
index 70daafa..589cefd 100644
--- a/include/media/stagefright/OMXCodec.h
+++ b/include/media/stagefright/OMXCodec.h
@@ -202,6 +202,10 @@
     bool mOnlySubmitOneBufferAtOneTime;
     bool mEnableGrallocUsageProtected;
 
+    // Used to record the decoding time for an output picture from
+    // a video encoder.
+    List<int64_t> mDecodingTimeList;
+
     OMXCodec(const sp<IOMX> &omx, IOMX::node_id node, uint32_t quirks,
              bool isEncoder, const char *mime, const char *componentName,
              const sp<MediaSource> &source,
@@ -317,6 +321,8 @@
 
     status_t applyRotation();
 
+    int64_t retrieveDecodingTimeUs(bool isCodecSpecific);
+
     OMXCodec(const OMXCodec &);
     OMXCodec &operator=(const OMXCodec &);
 };
diff --git a/include/media/stagefright/openmax/OMX_IVCommon.h b/include/media/stagefright/openmax/OMX_IVCommon.h
index 4a8be7b..12b4f93 100644
--- a/include/media/stagefright/openmax/OMX_IVCommon.h
+++ b/include/media/stagefright/openmax/OMX_IVCommon.h
@@ -149,6 +149,7 @@
     OMX_COLOR_Format24BitABGR6666,
     OMX_COLOR_FormatKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */ 
     OMX_COLOR_FormatVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
+    OMX_QCOM_COLOR_FormatYVU420SemiPlanar = 0x7FA30C00,
     OMX_COLOR_FormatMax = 0x7FFFFFFF
 } OMX_COLOR_FORMATTYPE;
 
diff --git a/include/private/media/AudioTrackShared.h b/include/private/media/AudioTrackShared.h
index 1827c3e..20abd51 100644
--- a/include/private/media/AudioTrackShared.h
+++ b/include/private/media/AudioTrackShared.h
@@ -26,7 +26,6 @@
 
 // ----------------------------------------------------------------------------
 
-#define THREAD_PRIORITY_AUDIO_CLIENT (ANDROID_PRIORITY_AUDIO)
 // Maximum cumulated timeout milliseconds before restarting audioflinger thread
 #define MAX_STARTUP_TIMEOUT_MS  3000    // Longer timeout period at startup to cope with A2DP init time
 #define MAX_RUN_TIMEOUT_MS      1000
@@ -82,7 +81,7 @@
                 // 16 bit because data is converted to 16 bit before being stored in buffer
 
                 uint8_t     frameSize;
-                uint8_t     channelCount;
+                uint8_t     pad1;
                 uint16_t    bufferTimeoutMs; // Maximum cumulated timeout before restarting audioflinger
 
                 uint16_t    waitTimeMs;      // Cumulated wait time
@@ -90,6 +89,7 @@
     volatile    int32_t     flags;
 
                 // Cache line boundary (32 bytes)
+
                             audio_track_cblk_t();
                 uint32_t    stepUser(uint32_t frameCount);
                 bool        stepServer(uint32_t frameCount);
diff --git a/include/private/surfaceflinger/SharedBufferStack.h b/include/private/surfaceflinger/SharedBufferStack.h
index 717f837..0da03d1 100644
--- a/include/private/surfaceflinger/SharedBufferStack.h
+++ b/include/private/surfaceflinger/SharedBufferStack.h
@@ -20,355 +20,12 @@
 #include <stdint.h>
 #include <sys/types.h>
 
-#include <cutils/compiler.h>
-
 #include <utils/Debug.h>
-#include <utils/threads.h>
-#include <utils/String8.h>
-
-#include <ui/Rect.h>
 
 namespace android {
 // ---------------------------------------------------------------------------
 
-/*
- * These classes manage a stack of buffers in shared memory.
- * 
- * SharedClient: represents a client with several stacks
- * SharedBufferStack: represents a stack of buffers
- * SharedBufferClient: manipulates the SharedBufferStack from the client side 
- * SharedBufferServer: manipulates the SharedBufferStack from the server side 
- *
- * Buffers can be dequeued until there are none available, they can be locked
- * unless they are in use by the server, which is only the case for the last 
- * dequeue-able buffer. When these various conditions are not met, the caller
- * waits until the condition is met.
- * 
- */
-
-// ----------------------------------------------------------------------------
-
-class Region;
-class SharedBufferStack;
-class SharedClient;
-
-// ----------------------------------------------------------------------------
-
-class SharedBufferStack
-{
-    friend class SharedClient;
-    friend class SharedBufferBase;
-    friend class SharedBufferClient;
-    friend class SharedBufferServer;
-
-public:
-    // When changing these values, the COMPILE_TIME_ASSERT at the end of this
-    // file need to be updated.
-    static const unsigned int NUM_LAYERS_MAX  = 31;
-    static const unsigned int NUM_BUFFER_MAX  = 32;
-    static const unsigned int NUM_BUFFER_MIN  = 2;
-    static const unsigned int NUM_DISPLAY_MAX = 4;
-
-    struct Statistics { // 4 longs
-        typedef int32_t usecs_t;
-        usecs_t  totalTime;
-        usecs_t  reserved[3];
-    };
-
-    struct SmallRect {
-        uint16_t l, t, r, b;
-    };
-
-    struct FlatRegion { // 52 bytes = 4 * (1 + 2*N)
-        static const unsigned int NUM_RECT_MAX = 5;
-        uint32_t    count;
-        SmallRect   rects[NUM_RECT_MAX];
-    };
-    
-    struct BufferData {
-        FlatRegion dirtyRegion;
-        SmallRect  crop;
-        uint8_t transform;
-        uint8_t reserved[3];
-    };
-    
-    SharedBufferStack();
-    void init(int32_t identity);
-    status_t setDirtyRegion(int buffer, const Region& reg);
-    status_t setCrop(int buffer, const Rect& reg);
-    status_t setTransform(int buffer, uint8_t transform);
-    Region getDirtyRegion(int buffer) const;
-    Rect getCrop(int buffer) const;
-    uint32_t getTransform(int buffer) const;
-
-    // these attributes are part of the conditions/updates
-    volatile int32_t head;      // server's current front buffer
-    volatile int32_t available; // number of dequeue-able buffers
-    volatile int32_t queued;    // number of buffers waiting for post
-    volatile int32_t reserved1;
-    volatile status_t status;   // surface's status code
-
-    // not part of the conditions
-    volatile int32_t reallocMask;
-    volatile int8_t index[NUM_BUFFER_MAX];
-
-    int32_t     identity;       // surface's identity (const)
-    int32_t     token;          // surface's token (for debugging)
-    Statistics  stats;
-    int8_t      headBuf;        // last retired buffer
-    uint8_t     reservedBytes[3];
-    int32_t     reserved;
-    BufferData  buffers[NUM_BUFFER_MAX];     // 1024 bytes
-};
-
-// ----------------------------------------------------------------------------
-
-// 64 KB max
-class SharedClient
-{
-public:
-    SharedClient();
-    ~SharedClient();
-    status_t validate(size_t token) const;
-
-private:
-    friend class SharedBufferBase;
-    friend class SharedBufferClient;
-    friend class SharedBufferServer;
-
-    // FIXME: this should be replaced by a lock-less primitive
-    Mutex lock;
-    Condition cv;
-    SharedBufferStack surfaces[ SharedBufferStack::NUM_LAYERS_MAX ];
-};
-
-// ============================================================================
-
-class SharedBufferBase
-{
-public:
-    SharedBufferBase(SharedClient* sharedClient, int surface,
-            int32_t identity);
-    ~SharedBufferBase();
-    status_t getStatus() const;
-    int32_t getIdentity() const;
-    String8 dump(char const* prefix) const;
-
-protected:
-    SharedClient* const mSharedClient;
-    SharedBufferStack* const mSharedStack;
-    const int mIdentity;
-
-    friend struct Update;
-    friend struct QueueUpdate;
-
-    struct ConditionBase {
-        SharedBufferStack& stack;
-        inline ConditionBase(SharedBufferBase* sbc) 
-            : stack(*sbc->mSharedStack) { }
-        virtual ~ConditionBase() { };
-        virtual bool operator()() const = 0;
-        virtual const char* name() const = 0;
-    };
-    status_t waitForCondition(const ConditionBase& condition);
-
-    struct UpdateBase {
-        SharedBufferStack& stack;
-        inline UpdateBase(SharedBufferBase* sbb) 
-            : stack(*sbb->mSharedStack) { }
-    };
-    template <typename T>
-    status_t updateCondition(T update);
-};
-
-template <typename T>
-status_t SharedBufferBase::updateCondition(T update) {
-    SharedClient& client( *mSharedClient );
-    Mutex::Autolock _l(client.lock);
-    ssize_t result = update();
-    client.cv.broadcast();    
-    return result;
-}
-
-// ----------------------------------------------------------------------------
-
-class SharedBufferClient : public SharedBufferBase
-{
-public:
-    SharedBufferClient(SharedClient* sharedClient, int surface, int num,
-            int32_t identity);
-
-    ssize_t dequeue();
-    status_t undoDequeue(int buf);
-    
-    status_t lock(int buf);
-    status_t cancel(int buf);
-    status_t queue(int buf);
-    bool needNewBuffer(int buffer) const;
-    status_t setDirtyRegion(int buffer, const Region& reg);
-    status_t setCrop(int buffer, const Rect& reg);
-    status_t setTransform(int buffer, uint32_t transform);
-
-    class SetBufferCountCallback {
-        friend class SharedBufferClient;
-        virtual status_t operator()(int bufferCount) const = 0;
-    protected:
-        virtual ~SetBufferCountCallback() { }
-    };
-    status_t setBufferCount(int bufferCount, const SetBufferCountCallback& ipc);
-
-private:
-    friend struct Condition;
-    friend struct DequeueCondition;
-    friend struct LockCondition;
-
-    struct QueueUpdate : public UpdateBase {
-        inline QueueUpdate(SharedBufferBase* sbb);
-        inline ssize_t operator()();
-    };
-
-    struct DequeueUpdate : public UpdateBase {
-        inline DequeueUpdate(SharedBufferBase* sbb);
-        inline ssize_t operator()();
-    };
-
-    struct CancelUpdate : public UpdateBase {
-        int tail, buf;
-        inline CancelUpdate(SharedBufferBase* sbb, int tail, int buf);
-        inline ssize_t operator()();
-    };
-
-    // --
-
-    struct DequeueCondition : public ConditionBase {
-        inline DequeueCondition(SharedBufferClient* sbc);
-        inline bool operator()() const;
-        inline const char* name() const { return "DequeueCondition"; }
-    };
-
-    struct LockCondition : public ConditionBase {
-        int buf;
-        inline LockCondition(SharedBufferClient* sbc, int buf);
-        inline bool operator()() const;
-        inline const char* name() const { return "LockCondition"; }
-    };
-
-    int32_t computeTail() const;
-
-    mutable RWLock mLock;
-    int mNumBuffers;
-
-    int32_t tail;
-    int32_t queued_head;
-    // statistics...
-    nsecs_t mDequeueTime[SharedBufferStack::NUM_BUFFER_MAX];
-};
-
-// ----------------------------------------------------------------------------
-
-class SharedBufferServer
-    : public SharedBufferBase,
-      public LightRefBase<SharedBufferServer>
-{
-public:
-    SharedBufferServer(SharedClient* sharedClient, int surface, int num,
-            int32_t identity);
-
-    ssize_t retireAndLock();
-    void setStatus(status_t status);
-    status_t reallocateAll();
-    status_t reallocateAllExcept(int buffer);
-    int32_t getQueuedCount() const;
-    Region getDirtyRegion(int buffer) const;
-    Rect getCrop(int buffer) const;
-    uint32_t getTransform(int buffer) const;
-
-    status_t resize(int newNumBuffers);
-    status_t grow(int newNumBuffers);
-    status_t shrink(int newNumBuffers);
-
-    SharedBufferStack::Statistics getStats() const;
-    
-
-private:
-    friend class LightRefBase<SharedBufferServer>;
-    ~SharedBufferServer();
-
-    /*
-     * BufferList is basically a fixed-capacity sorted-vector of
-     * unsigned 5-bits ints using a 32-bits int as storage.
-     * it has efficient iterators to find items in the list and not in the list.
-     */
-    class BufferList {
-        size_t mCapacity;
-        uint32_t mList;
-    public:
-        BufferList(size_t c = SharedBufferStack::NUM_BUFFER_MAX)
-            : mCapacity(c), mList(0) { }
-        status_t add(int value);
-        status_t remove(int value);
-        uint32_t getMask() const { return mList; }
-
-        class const_iterator {
-            friend class BufferList;
-            uint32_t mask, curr;
-            const_iterator(uint32_t mask) :
-                mask(mask), curr(__builtin_clz(mask)) {
-            }
-        public:
-            inline bool operator == (const const_iterator& rhs) const {
-                return mask == rhs.mask;
-            }
-            inline bool operator != (const const_iterator& rhs) const {
-                return mask != rhs.mask;
-            }
-            inline int operator *() const { return curr; }
-            inline const const_iterator& operator ++() {
-                mask &= ~(1<<(31-curr));
-                curr = __builtin_clz(mask);
-                return *this;
-            }
-        };
-
-        inline const_iterator begin() const {
-            return const_iterator(mList);
-        }
-        inline const_iterator end() const   {
-            return const_iterator(0);
-        }
-        inline const_iterator free_begin() const {
-            uint32_t mask = (1 << (32-mCapacity)) - 1;
-            return const_iterator( ~(mList | mask) );
-        }
-    };
-
-    // this protects mNumBuffers and mBufferList
-    mutable RWLock mLock;
-    int mNumBuffers;
-    BufferList mBufferList;
-
-    struct BuffersAvailableCondition : public ConditionBase {
-        int mNumBuffers;
-        inline BuffersAvailableCondition(SharedBufferServer* sbs,
-                int numBuffers);
-        inline bool operator()() const;
-        inline const char* name() const { return "BuffersAvailableCondition"; }
-    };
-
-    struct RetireUpdate : public UpdateBase {
-        const int numBuffers;
-        inline RetireUpdate(SharedBufferBase* sbb, int numBuffers);
-        inline ssize_t operator()();
-    };
-
-    struct StatusUpdate : public UpdateBase {
-        const status_t status;
-        inline StatusUpdate(SharedBufferBase* sbb, status_t status);
-        inline ssize_t operator()();
-    };
-};
-
-// ===========================================================================
+#define NUM_DISPLAY_MAX 4
 
 struct display_cblk_t
 {
@@ -389,12 +46,11 @@
     uint8_t         connected;
     uint8_t         reserved[3];
     uint32_t        pad[7];
-    display_cblk_t  displays[SharedBufferStack::NUM_DISPLAY_MAX];
+    display_cblk_t  displays[NUM_DISPLAY_MAX];
 };
 
 // ---------------------------------------------------------------------------
 
-COMPILE_TIME_ASSERT(sizeof(SharedClient) <= 65536)
 COMPILE_TIME_ASSERT(sizeof(surface_flinger_cblk_t) <= 4096)
 
 // ---------------------------------------------------------------------------
diff --git a/include/surfaceflinger/IGraphicBufferAlloc.h b/include/surfaceflinger/IGraphicBufferAlloc.h
index 01e4bd9..e1b6b57 100644
--- a/include/surfaceflinger/IGraphicBufferAlloc.h
+++ b/include/surfaceflinger/IGraphicBufferAlloc.h
@@ -27,6 +27,8 @@
 namespace android {
 // ----------------------------------------------------------------------------
 
+class GraphicBuffer;
+
 class IGraphicBufferAlloc : public IInterface
 {
 public:
diff --git a/include/surfaceflinger/ISurface.h b/include/surfaceflinger/ISurface.h
index cd0ee40..5fdf234 100644
--- a/include/surfaceflinger/ISurface.h
+++ b/include/surfaceflinger/ISurface.h
@@ -27,42 +27,23 @@
 
 #include <ui/PixelFormat.h>
 
-#include <hardware/hardware.h>
-#include <hardware/gralloc.h>
-
 namespace android {
 
 typedef int32_t    SurfaceID;
 
-class GraphicBuffer;
+class ISurfaceTexture;
 
 class ISurface : public IInterface
 {
 protected:
     enum {
-        RESERVED0 = IBinder::FIRST_CALL_TRANSACTION,
-        RESERVED1,
-        RESERVED2,
-        REQUEST_BUFFER,
-        SET_BUFFER_COUNT,
+        GET_SURFACE_TEXTURE = IBinder::FIRST_CALL_TRANSACTION,
     };
 
 public: 
     DECLARE_META_INTERFACE(Surface);
 
-    /*
-     * requests a new buffer for the given index. If w, h, or format are
-     * null the buffer is created with the parameters assigned to the
-     * surface it is bound to. Otherwise the buffer's parameters are
-     * set to those specified.
-     */
-    virtual sp<GraphicBuffer> requestBuffer(int bufferIdx,
-            uint32_t w, uint32_t h, uint32_t format, uint32_t usage) = 0;
-
-    /*
-     * sets the number of buffers dequeuable for this surface.
-     */
-    virtual status_t setBufferCount(int bufferCount) = 0;
+    virtual sp<ISurfaceTexture> getSurfaceTexture() const = 0;
 };
 
 // ----------------------------------------------------------------------------
diff --git a/include/surfaceflinger/ISurfaceComposer.h b/include/surfaceflinger/ISurfaceComposer.h
index dea1b10..03fd01b 100644
--- a/include/surfaceflinger/ISurfaceComposer.h
+++ b/include/surfaceflinger/ISurfaceComposer.h
@@ -33,6 +33,8 @@
 namespace android {
 // ----------------------------------------------------------------------------
 
+class IMemoryHeap;
+
 class ISurfaceComposer : public IInterface
 {
 public:
@@ -95,10 +97,6 @@
      */
     virtual sp<ISurfaceComposerClient> createConnection() = 0;
 
-    /* create a client connection with surface flinger
-     */
-    virtual sp<ISurfaceComposerClient> createClientConnection() = 0;
-
     /* create a graphic buffer allocator
      */
     virtual sp<IGraphicBufferAlloc> createGraphicBufferAlloc() = 0;
@@ -134,11 +132,6 @@
     virtual status_t turnElectronBeamOff(int32_t mode) = 0;
     virtual status_t turnElectronBeamOn(int32_t mode) = 0;
 
-    /* Signal surfaceflinger that there might be some work to do
-     * This is an ASYNCHRONOUS call.
-     */
-    virtual void signal() const = 0;
-
     /* verify that an ISurface was created by SurfaceFlinger.
      */
     virtual bool authenticateSurface(const sp<ISurface>& surface) const = 0;
@@ -154,7 +147,6 @@
         // Java by ActivityManagerService.
         BOOT_FINISHED = IBinder::FIRST_CALL_TRANSACTION,
         CREATE_CONNECTION,
-        CREATE_CLIENT_CONNECTION,
         CREATE_GRAPHIC_BUFFER_ALLOC,
         GET_CBLK,
         OPEN_GLOBAL_TRANSACTION,
@@ -162,7 +154,6 @@
         SET_ORIENTATION,
         FREEZE_DISPLAY,
         UNFREEZE_DISPLAY,
-        SIGNAL,
         CAPTURE_SCREEN,
         TURN_ELECTRON_BEAM_OFF,
         TURN_ELECTRON_BEAM_ON,
diff --git a/include/surfaceflinger/ISurfaceComposerClient.h b/include/surfaceflinger/ISurfaceComposerClient.h
index 46b1bb7..2e75a0e 100644
--- a/include/surfaceflinger/ISurfaceComposerClient.h
+++ b/include/surfaceflinger/ISurfaceComposerClient.h
@@ -33,9 +33,6 @@
 
 // ----------------------------------------------------------------------------
 
-class IMemoryHeap;
-
-typedef int32_t    ClientID;
 typedef int32_t    DisplayID;
 
 // ----------------------------------------------------------------------------
@@ -57,9 +54,6 @@
         status_t writeToParcel(Parcel* parcel) const;
     };
 
-    virtual sp<IMemoryHeap> getControlBlock() const = 0;
-    virtual ssize_t getTokenForSurface(const sp<ISurface>& sur) const = 0;
-
     /*
      * Requires ACCESS_SURFACE_FLINGER permission
      */
diff --git a/include/surfaceflinger/Surface.h b/include/surfaceflinger/Surface.h
index ab30f45..8845dc9 100644
--- a/include/surfaceflinger/Surface.h
+++ b/include/surfaceflinger/Surface.h
@@ -43,9 +43,7 @@
 class Rect;
 class Surface;
 class SurfaceComposerClient;
-class SharedClient;
-class SharedBufferClient;
-class SurfaceClient;
+class SurfaceTextureClient;
 
 // ---------------------------------------------------------------------------
 
@@ -162,9 +160,6 @@
     status_t    lock(SurfaceInfo* info, Region* dirty, bool blocking = true);
     status_t    unlockAndPost();
 
-    // setSwapRectangle() is intended to be used by GL ES clients
-    void        setSwapRectangle(const Rect& r);
-
     sp<IBinder> asBinder() const;
 
 private:
@@ -209,6 +204,7 @@
     static int query(const ANativeWindow* window, int what, int* value);
     static int perform(ANativeWindow* window, int operation, ...);
 
+    int setSwapInterval(int interval);
     int dequeueBuffer(ANativeWindowBuffer** buffer);
     int lockBuffer(ANativeWindowBuffer* buffer);
     int queueBuffer(ANativeWindowBuffer* buffer);
@@ -216,83 +212,23 @@
     int query(int what, int* value) const;
     int perform(int operation, va_list args);
 
-    void dispatch_setUsage(va_list args);
-    int  dispatch_connect(va_list args);
-    int  dispatch_disconnect(va_list args);
-    int  dispatch_crop(va_list args);
-    int  dispatch_set_buffer_count(va_list args);
-    int  dispatch_set_buffers_geometry(va_list args);
-    int  dispatch_set_buffers_transform(va_list args);
-    int  dispatch_set_buffers_timestamp(va_list args);
-
-    void setUsage(uint32_t reqUsage);
-    int  connect(int api);
-    int  disconnect(int api);
-    int  crop(Rect const* rect);
-    int  setBufferCount(int bufferCount);
-    int  setBuffersGeometry(int w, int h, int format);
-    int  setBuffersTransform(int transform);
-    int  setBuffersTimestamp(int64_t timestamp);
-
     /*
      *  private stuff...
      */
     void init();
     status_t validate(bool inCancelBuffer = false) const;
 
-    // When the buffer pool is a fixed size we want to make sure SurfaceFlinger
-    // won't stall clients, so we require an extra buffer.
-    enum { MIN_UNDEQUEUED_BUFFERS = 2 };
-
-    inline const GraphicBufferMapper& getBufferMapper() const { return mBufferMapper; }
-    inline GraphicBufferMapper& getBufferMapper() { return mBufferMapper; }
-
-    status_t getBufferLocked(int index,
-            uint32_t w, uint32_t h, uint32_t format, uint32_t usage);
-    int getBufferIndex(const sp<GraphicBuffer>& buffer) const;
-
     int getConnectedApi() const;
     
-    bool needNewBuffer(int bufIdx,
-            uint32_t *pWidth, uint32_t *pHeight,
-            uint32_t *pFormat, uint32_t *pUsage) const;
-
     static void cleanCachedSurfacesLocked();
 
-    class BufferInfo {
-        uint32_t mWidth;
-        uint32_t mHeight;
-        uint32_t mFormat;
-        uint32_t mUsage;
-        mutable uint32_t mDirty;
-        enum {
-            GEOMETRY = 0x01
-        };
-    public:
-        BufferInfo();
-        void set(uint32_t w, uint32_t h, uint32_t format);
-        void set(uint32_t usage);
-        void get(uint32_t *pWidth, uint32_t *pHeight,
-                uint32_t *pFormat, uint32_t *pUsage) const;
-        bool validateBuffer(const sp<GraphicBuffer>& buffer) const;
-    };
-
     // constants
-    GraphicBufferMapper&        mBufferMapper;
-    SurfaceClient&              mClient;
-    SharedBufferClient*         mSharedBufferClient;
     status_t                    mInitCheck;
     sp<ISurface>                mSurface;
+    sp<SurfaceTextureClient>    mSurfaceTextureClient;
     uint32_t                    mIdentity;
     PixelFormat                 mFormat;
     uint32_t                    mFlags;
-
-    // protected by mSurfaceLock
-    Rect                        mSwapRectangle;
-    int                         mConnected;
-    Rect                        mNextBufferCrop;
-    uint32_t                    mNextBufferTransform;
-    BufferInfo                  mBufferInfo;
     
     // protected by mSurfaceLock. These are also used from lock/unlock
     // but in that case, they must be called form the same thread.
@@ -304,9 +240,6 @@
     mutable Region              mOldDirtyRegion;
     bool                        mReserved;
 
-    // only used from dequeueBuffer()
-    Vector< sp<GraphicBuffer> > mBuffers;
-
     // query() must be called from dequeueBuffer() thread
     uint32_t                    mWidth;
     uint32_t                    mHeight;
diff --git a/include/surfaceflinger/SurfaceComposerClient.h b/include/surfaceflinger/SurfaceComposerClient.h
index c61a5bf..140b9f8 100644
--- a/include/surfaceflinger/SurfaceComposerClient.h
+++ b/include/surfaceflinger/SurfaceComposerClient.h
@@ -36,10 +36,10 @@
 
 // ---------------------------------------------------------------------------
 
-class Region;
-class SharedClient;
-class ISurfaceComposer;
 class DisplayInfo;
+class IMemoryHeap;
+class ISurfaceComposer;
+class Region;
 class surface_flinger_cblk_t;
 
 // ---------------------------------------------------------------------------
diff --git a/include/ui/Input.h b/include/ui/Input.h
index ba1c6b4..c9f694a 100644
--- a/include/ui/Input.h
+++ b/include/ui/Input.h
@@ -655,11 +655,6 @@
     // Oldest sample to consider when calculating the velocity.
     static const nsecs_t MAX_AGE = 200 * 1000000; // 200 ms
 
-    // When the total duration of the window of samples being averaged is less
-    // than the window size, the resulting velocity is scaled to reduce the impact
-    // of overestimation in short traces.
-    static const nsecs_t MIN_WINDOW = 100 * 1000000; // 100 ms
-
     // The minimum duration between samples when estimating velocity.
     static const nsecs_t MIN_DURATION = 10 * 1000000; // 10 ms
 
@@ -674,6 +669,87 @@
     int32_t mActivePointerId;
 };
 
+
+/*
+ * Specifies parameters that govern pointer or wheel acceleration.
+ */
+struct VelocityControlParameters {
+    // A scale factor that is multiplied with the raw velocity deltas
+    // prior to applying any other velocity control factors.  The scale
+    // factor should be used to adapt the input device resolution
+    // (eg. counts per inch) to the output device resolution (eg. pixels per inch).
+    //
+    // Must be a positive value.
+    // Default is 1.0 (no scaling).
+    float scale;
+
+    // The scaled speed at which acceleration begins to be applied.
+    // This value establishes the upper bound of a low speed regime for
+    // small precise motions that are performed without any acceleration.
+    //
+    // Must be a non-negative value.
+    // Default is 0.0 (no low threshold).
+    float lowThreshold;
+
+    // The scaled speed at which maximum acceleration is applied.
+    // The difference between highThreshold and lowThreshold controls
+    // the range of speeds over which the acceleration factor is interpolated.
+    // The wider the range, the smoother the acceleration.
+    //
+    // Must be a non-negative value greater than or equal to lowThreshold.
+    // Default is 0.0 (no high threshold).
+    float highThreshold;
+
+    // The acceleration factor.
+    // When the speed is above the low speed threshold, the velocity will scaled
+    // by an interpolated value between 1.0 and this amount.
+    //
+    // Must be a positive greater than or equal to 1.0.
+    // Default is 1.0 (no acceleration).
+    float acceleration;
+
+    VelocityControlParameters() :
+            scale(1.0f), lowThreshold(0.0f), highThreshold(0.0f), acceleration(1.0f) {
+    }
+
+    VelocityControlParameters(float scale, float lowThreshold,
+            float highThreshold, float acceleration) :
+            scale(scale), lowThreshold(lowThreshold),
+            highThreshold(highThreshold), acceleration(acceleration) {
+    }
+};
+
+/*
+ * Implements mouse pointer and wheel speed control and acceleration.
+ */
+class VelocityControl {
+public:
+    VelocityControl();
+
+    /* Sets the various parameters. */
+    void setParameters(const VelocityControlParameters& parameters);
+
+    /* Resets the current movement counters to zero.
+     * This has the effect of nullifying any acceleration. */
+    void reset();
+
+    /* Translates a raw movement delta into an appropriately
+     * scaled / accelerated delta based on the current velocity. */
+    void move(nsecs_t eventTime, float* deltaX, float* deltaY);
+
+private:
+    // If no movements are received within this amount of time,
+    // we assume the movement has stopped and reset the movement counters.
+    static const nsecs_t STOP_TIME = 500 * 1000000; // 500 ms
+
+    VelocityControlParameters mParameters;
+
+    nsecs_t mLastMovementTime;
+    VelocityTracker::Position mRawPosition;
+    VelocityTracker mVelocityTracker;
+};
+
+
 /*
  * Describes the characteristics and capabilities of an input device.
  */
diff --git a/include/utils/BlobCache.h b/include/utils/BlobCache.h
new file mode 100644
index 0000000..dc45ff0
--- /dev/null
+++ b/include/utils/BlobCache.h
@@ -0,0 +1,184 @@
+/*
+ ** Copyright 2011, The Android Open Source Project
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ **     http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+#ifndef ANDROID_BLOB_CACHE_H
+#define ANDROID_BLOB_CACHE_H
+
+#include <stddef.h>
+
+#include <utils/RefBase.h>
+#include <utils/SortedVector.h>
+#include <utils/threads.h>
+
+namespace android {
+
+// A BlobCache is an in-memory cache for binary key/value pairs. All the public
+// methods are thread-safe.
+//
+// The cache contents can be serialized to a file and reloaded in a subsequent
+// execution of the program. This serialization is non-portable and should only
+// be loaded by the device that generated it.
+class BlobCache : public RefBase {
+public:
+
+    // Create an empty blob cache. The blob cache will cache key/value pairs
+    // with key and value sizes less than or equal to maxKeySize and
+    // maxValueSize, respectively. The total combined size of ALL cache entries
+    // (key sizes plus value sizes) will not exceed maxTotalSize.
+    BlobCache(size_t maxKeySize, size_t maxValueSize, size_t maxTotalSize);
+
+    // set inserts a new binary value into the cache and associates it with the
+    // given binary key.  If the key or value are too large for the cache then
+    // the cache remains unchanged.  This includes the case where a different
+    // value was previously associated with the given key - the old value will
+    // remain in the cache.  If the given key and value are small enough to be
+    // put in the cache (based on the maxKeySize, maxValueSize, and maxTotalSize
+    // values specified to the BlobCache constructor), then the key/value pair
+    // will be in the cache after set returns.  Note, however, that a subsequent
+    // call to set may evict old key/value pairs from the cache.
+    //
+    // Preconditions:
+    //   key != NULL
+    //   0 < keySize
+    //   value != NULL
+    //   0 < valueSize
+    void set(const void* key, size_t keySize, const void* value,
+            size_t valueSize);
+
+    // The get function retrieves from the cache the binary value associated
+    // with a given binary key.  If the key is present in the cache then the
+    // length of the binary value associated with that key is returned.  If the
+    // value argument is non-NULL and the size of the cached value is less than
+    // valueSize bytes then the cached value is copied into the buffer pointed
+    // to by the value argument.  If the key is not present in the cache then 0
+    // is returned and the buffer pointed to by the value argument is not
+    // modified.
+    //
+    // Note that when calling get multiple times with the same key, the later
+    // calls may fail, returning 0, even if earlier calls succeeded.  The return
+    // value must be checked for each call.
+    //
+    // Preconditions:
+    //   key != NULL
+    //   0 < keySize
+    //   0 <= valueSize
+    size_t get(const void* key, size_t keySize, void* value, size_t valueSize);
+
+private:
+    // Copying is disallowed.
+    BlobCache(const BlobCache&);
+    void operator=(const BlobCache&);
+
+    // A random function helper to get around MinGW not having nrand48()
+    long int blob_random();
+
+    // clean evicts a randomly chosen set of entries from the cache such that
+    // the total size of all remaining entries is less than mMaxTotalSize/2.
+    void clean();
+
+    // isCleanable returns true if the cache is full enough for the clean method
+    // to have some effect, and false otherwise.
+    bool isCleanable() const;
+
+    // A Blob is an immutable sized unstructured data blob.
+    class Blob : public RefBase {
+    public:
+        Blob(const void* data, size_t size, bool copyData);
+        ~Blob();
+
+        bool operator<(const Blob& rhs) const;
+
+        const void* getData() const;
+        size_t getSize() const;
+
+    private:
+        // Copying is not allowed.
+        Blob(const Blob&);
+        void operator=(const Blob&);
+
+        // mData points to the buffer containing the blob data.
+        const void* mData;
+
+        // mSize is the size of the blob data in bytes.
+        size_t mSize;
+
+        // mOwnsData indicates whether or not this Blob object should free the
+        // memory pointed to by mData when the Blob gets destructed.
+        bool mOwnsData;
+    };
+
+    // A CacheEntry is a single key/value pair in the cache.
+    class CacheEntry {
+    public:
+        CacheEntry();
+        CacheEntry(const sp<Blob>& key, const sp<Blob>& value);
+        CacheEntry(const CacheEntry& ce);
+
+        bool operator<(const CacheEntry& rhs) const;
+        const CacheEntry& operator=(const CacheEntry&);
+
+        sp<Blob> getKey() const;
+        sp<Blob> getValue() const;
+
+        void setValue(const sp<Blob>& value);
+
+    private:
+
+        // mKey is the key that identifies the cache entry.
+        sp<Blob> mKey;
+
+        // mValue is the cached data associated with the key.
+        sp<Blob> mValue;
+    };
+
+    // mMaxKeySize is the maximum key size that will be cached. Calls to
+    // BlobCache::set with a keySize parameter larger than mMaxKeySize will
+    // simply not add the key/value pair to the cache.
+    const size_t mMaxKeySize;
+
+    // mMaxValueSize is the maximum value size that will be cached. Calls to
+    // BlobCache::set with a valueSize parameter larger than mMaxValueSize will
+    // simply not add the key/value pair to the cache.
+    const size_t mMaxValueSize;
+
+    // mMaxTotalSize is the maximum size that all cache entries can occupy. This
+    // includes space for both keys and values. When a call to BlobCache::set
+    // would otherwise cause this limit to be exceeded, either the key/value
+    // pair passed to BlobCache::set will not be cached or other cache entries
+    // will be evicted from the cache to make room for the new entry.
+    const size_t mMaxTotalSize;
+
+    // mTotalSize is the total combined size of all keys and values currently in
+    // the cache.
+    size_t mTotalSize;
+
+    // mRandState is the pseudo-random number generator state. It is passed to
+    // nrand48 to generate random numbers when needed. It must be protected by
+    // mMutex.
+    unsigned short mRandState[3];
+
+    // mCacheEntries stores all the cache entries that are resident in memory.
+    // Cache entries are added to it by the 'set' method.
+    SortedVector<CacheEntry> mCacheEntries;
+
+    // mMutex is used to synchronize access to all member variables.  It must be
+    // locked any time the member variables are written or read.
+    Mutex mMutex;
+};
+
+}
+
+#endif // ANDROID_BLOB_CACHE_H
diff --git a/include/utils/RefBase.h b/include/utils/RefBase.h
index 4126225..ca17082 100644
--- a/include/utils/RefBase.h
+++ b/include/utils/RefBase.h
@@ -116,17 +116,24 @@
 
     typedef RefBase basetype;
 
+    // used to override the RefBase destruction.
+    class Destroyer {
+        friend class RefBase;
+        friend class weakref_type;
+    public:
+        virtual ~Destroyer();
+    private:
+        virtual void destroy(RefBase const* base) = 0;
+    };
+
+    // Make sure to never acquire a strong reference from this function. The
+    // same restrictions than for destructors apply.
+    void setDestroyer(Destroyer* destroyer);
+
 protected:
                             RefBase();
     virtual                 ~RefBase();
 
-    // called when the last reference goes away. this is responsible for
-    // calling the destructor. The default implementation just does
-    // "delete this;".
-    // Make sure to never acquire a strong reference from this function. The
-    // same restrictions than for destructors apply.
-    virtual void            destroy() const;
-
     //! Flags for extendObjectLifetime()
     enum {
         OBJECT_LIFETIME_WEAK    = 0x0001,
diff --git a/include/utils/ResourceTypes.h b/include/utils/ResourceTypes.h
index 2c7cf75..612ff9346 100644
--- a/include/utils/ResourceTypes.h
+++ b/include/utils/ResourceTypes.h
@@ -841,6 +841,7 @@
         DENSITY_DEFAULT = ACONFIGURATION_DENSITY_DEFAULT,
         DENSITY_LOW = ACONFIGURATION_DENSITY_LOW,
         DENSITY_MEDIUM = ACONFIGURATION_DENSITY_MEDIUM,
+        DENSITY_TV = ACONFIGURATION_DENSITY_TV,
         DENSITY_HIGH = ACONFIGURATION_DENSITY_HIGH,
         DENSITY_NONE = ACONFIGURATION_DENSITY_NONE
     };
@@ -1452,24 +1453,20 @@
     // settings is the requested settings
     inline bool match(const ResTable_config& settings) const {
         if (imsi != 0) {
-            if ((settings.mcc != 0 && mcc != 0
-                 && mcc != settings.mcc) || 
-                (settings.mcc == 0 && mcc != 0)) {
+            if (mcc != 0 && mcc != settings.mcc) {
                 return false;
             }
-            if ((settings.mnc != 0 && mnc != 0
-                 && mnc != settings.mnc) ||
-                (settings.mnc == 0 && mnc != 0)) {
+            if (mnc != 0 && mnc != settings.mnc) {
                 return false;
             }
         }
         if (locale != 0) {
-            if (settings.language[0] != 0 && language[0] != 0
+            if (language[0] != 0
                 && (language[0] != settings.language[0]
                     || language[1] != settings.language[1])) {
                 return false;
             }
-            if (settings.country[0] != 0 && country[0] != 0
+            if (country[0] != 0
                 && (country[0] != settings.country[0]
                     || country[1] != settings.country[1])) {
                 return false;
@@ -1480,66 +1477,56 @@
             const int setScreenSize = settings.screenLayout&MASK_SCREENSIZE;
             // Any screen sizes for larger screens than the setting do not
             // match.
-            if ((setScreenSize != 0 && screenSize != 0
-                    && screenSize > setScreenSize) ||
-                    (setScreenSize == 0 && screenSize != 0)) {
+            if (screenSize != 0 && screenSize > setScreenSize) {
                 return false;
             }
             
             const int screenLong = screenLayout&MASK_SCREENLONG;
             const int setScreenLong = settings.screenLayout&MASK_SCREENLONG;
-            if (setScreenLong != 0 && screenLong != 0
-                    && screenLong != setScreenLong) {
+            if (screenLong != 0 && screenLong != setScreenLong) {
                 return false;
             }
 
             const int uiModeType = uiMode&MASK_UI_MODE_TYPE;
             const int setUiModeType = settings.uiMode&MASK_UI_MODE_TYPE;
-            if (setUiModeType != 0 && uiModeType != 0
-                    && uiModeType != setUiModeType) {
+            if (uiModeType != 0 && uiModeType != setUiModeType) {
                 return false;
             }
 
             const int uiModeNight = uiMode&MASK_UI_MODE_NIGHT;
             const int setUiModeNight = settings.uiMode&MASK_UI_MODE_NIGHT;
-            if (setUiModeNight != 0 && uiModeNight != 0
-                    && uiModeNight != setUiModeNight) {
+            if (uiModeNight != 0 && uiModeNight != setUiModeNight) {
                 return false;
             }
 
-            if (settings.smallestScreenWidthDp != 0 && smallestScreenWidthDp != 0
+            if (smallestScreenWidthDp != 0
                     && smallestScreenWidthDp > settings.smallestScreenWidthDp) {
                 return false;
             }
         }
         if (screenSizeDp != 0) {
-            if (settings.screenWidthDp != 0 && screenWidthDp != 0
-                    && screenWidthDp > settings.screenWidthDp) {
+            if (screenWidthDp != 0 && screenWidthDp > settings.screenWidthDp) {
                 //LOGI("Filtering out width %d in requested %d", screenWidthDp, settings.screenWidthDp);
                 return false;
             }
-            if (settings.screenHeightDp != 0 && screenHeightDp != 0
-                    && screenHeightDp > settings.screenHeightDp) {
+            if (screenHeightDp != 0 && screenHeightDp > settings.screenHeightDp) {
                 //LOGI("Filtering out height %d in requested %d", screenHeightDp, settings.screenHeightDp);
                 return false;
             }
         }
         if (screenType != 0) {
-            if (settings.orientation != 0 && orientation != 0
-                && orientation != settings.orientation) {
+            if (orientation != 0 && orientation != settings.orientation) {
                 return false;
             }
             // density always matches - we can scale it.  See isBetterThan
-            if (settings.touchscreen != 0 && touchscreen != 0
-                && touchscreen != settings.touchscreen) {
+            if (touchscreen != 0 && touchscreen != settings.touchscreen) {
                 return false;
             }
         }
         if (input != 0) {
             const int keysHidden = inputFlags&MASK_KEYSHIDDEN;
             const int setKeysHidden = settings.inputFlags&MASK_KEYSHIDDEN;
-            if (setKeysHidden != 0 && keysHidden != 0
-                && keysHidden != setKeysHidden) {
+            if (keysHidden != 0 && keysHidden != setKeysHidden) {
                 // For compatibility, we count a request for KEYSHIDDEN_NO as also
                 // matching the more recent KEYSHIDDEN_SOFT.  Basically
                 // KEYSHIDDEN_NO means there is some kind of keyboard available.
@@ -1551,36 +1538,29 @@
             }
             const int navHidden = inputFlags&MASK_NAVHIDDEN;
             const int setNavHidden = settings.inputFlags&MASK_NAVHIDDEN;
-            if (setNavHidden != 0 && navHidden != 0
-                && navHidden != setNavHidden) {
+            if (navHidden != 0 && navHidden != setNavHidden) {
                 return false;
             }
-            if (settings.keyboard != 0 && keyboard != 0
-                && keyboard != settings.keyboard) {
+            if (keyboard != 0 && keyboard != settings.keyboard) {
                 return false;
             }
-            if (settings.navigation != 0 && navigation != 0
-                && navigation != settings.navigation) {
+            if (navigation != 0 && navigation != settings.navigation) {
                 return false;
             }
         }
         if (screenSize != 0) {
-            if (settings.screenWidth != 0 && screenWidth != 0
-                && screenWidth > settings.screenWidth) {
+            if (screenWidth != 0 && screenWidth > settings.screenWidth) {
                 return false;
             }
-            if (settings.screenHeight != 0 && screenHeight != 0
-                && screenHeight > settings.screenHeight) {
+            if (screenHeight != 0 && screenHeight > settings.screenHeight) {
                 return false;
             }
         }
         if (version != 0) {
-            if (settings.sdkVersion != 0 && sdkVersion != 0
-                && sdkVersion > settings.sdkVersion) {
+            if (sdkVersion != 0 && sdkVersion > settings.sdkVersion) {
                 return false;
             }
-            if (settings.minorVersion != 0 && minorVersion != 0
-                && minorVersion != settings.minorVersion) {
+            if (minorVersion != 0 && minorVersion != settings.minorVersion) {
                 return false;
             }
         }
@@ -2008,7 +1988,8 @@
                                   String16* outName,
                                   const String16* defType = NULL,
                                   const String16* defPackage = NULL,
-                                  const char** outErrorMsg = NULL);
+                                  const char** outErrorMsg = NULL,
+                                  bool* outPublicOnly = NULL);
 
     static bool stringToInt(const char16_t* s, size_t len, Res_value* outValue);
     static bool stringToFloat(const char16_t* s, size_t len, Res_value* outValue);
diff --git a/include/utils/threads.h b/include/utils/threads.h
index 41e5766..0bd69cf 100644
--- a/include/utils/threads.h
+++ b/include/utils/threads.h
@@ -526,6 +526,7 @@
     Thread& operator=(const Thread&);
     static  int             _threadLoop(void* user);
     const   bool            mCanCallJava;
+    // always hold mLock when reading or writing
             thread_id_t     mThread;
     mutable Mutex           mLock;
             Condition       mThreadExitedCondition;
diff --git a/keystore/java/android/security/Credentials.java b/keystore/java/android/security/Credentials.java
index 6b69b8a..fd6c22c 100644
--- a/keystore/java/android/security/Credentials.java
+++ b/keystore/java/android/security/Credentials.java
@@ -20,8 +20,19 @@
 import android.content.Context;
 import android.content.Intent;
 import android.util.Log;
-
+import com.android.org.bouncycastle.openssl.PEMReader;
+import com.android.org.bouncycastle.openssl.PEMWriter;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.Reader;
+import java.io.Writer;
+import java.nio.charset.Charsets;
 import java.security.KeyPair;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * {@hide}
@@ -60,6 +71,40 @@
     /** Data type for PKCS12. */
     public static final String PKCS12 = "PKCS12";
 
+    /**
+     * Convert objects to a PEM format, which is used for
+     * CA_CERTIFICATE, USER_CERTIFICATE, and USER_PRIVATE_KEY
+     * entries.
+     */
+    public static byte[] convertToPem(Object... objects) throws IOException {
+        ByteArrayOutputStream bao = new ByteArrayOutputStream();
+        Writer writer = new OutputStreamWriter(bao, Charsets.US_ASCII);
+        PEMWriter pw = new PEMWriter(writer);
+        for (Object o : objects) {
+            pw.writeObject(o);
+        }
+        pw.close();
+        return bao.toByteArray();
+    }
+    /**
+     * Convert objects from PEM format, which is used for
+     * CA_CERTIFICATE, USER_CERTIFICATE, and USER_PRIVATE_KEY
+     * entries.
+     */
+    public static List<Object> convertFromPem(byte[] bytes) throws IOException {
+        ByteArrayInputStream bai = new ByteArrayInputStream(bytes);
+        Reader reader = new InputStreamReader(bai, Charsets.US_ASCII);
+        PEMReader pr = new PEMReader(reader);
+
+        List<Object> result = new ArrayList<Object>();
+        Object o;
+        while ((o = pr.readObject()) != null) {
+            result.add(o);
+        }
+        pr.close();
+        return result;
+    }
+
     private static Credentials singleton;
 
     public static Credentials getInstance() {
diff --git a/keystore/java/android/security/IKeyChainAliasCallback.aidl b/keystore/java/android/security/IKeyChainAliasCallback.aidl
new file mode 100644
index 0000000..1ea9521
--- /dev/null
+++ b/keystore/java/android/security/IKeyChainAliasCallback.aidl
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package android.security;
+
+/**
+ * Used by the {@code KeyChainActivity} to return alias for {@link KeyStore#chooseAlias}.
+ *
+ * @hide
+ */
+interface IKeyChainAliasCallback {
+
+    void alias(String alias);
+}
diff --git a/keystore/java/android/security/IKeyChainAliasResponse.aidl b/keystore/java/android/security/IKeyChainAliasResponse.aidl
deleted file mode 100644
index e042001..0000000
--- a/keystore/java/android/security/IKeyChainAliasResponse.aidl
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package android.security;
-
-/**
- * Used by the {@code KeyChainActivity} to return alias for {@link KeyStore#chooseAlias}.
- *
- * @hide
- */
-interface IKeyChainAliasResponse {
-
-    void alias(String alias);
-}
diff --git a/keystore/java/android/security/KeyChain.java b/keystore/java/android/security/KeyChain.java
index ec820cf..4f1596d 100644
--- a/keystore/java/android/security/KeyChain.java
+++ b/keystore/java/android/security/KeyChain.java
@@ -34,7 +34,9 @@
 import java.io.Closeable;
 import java.io.IOException;
 import java.security.KeyFactory;
+import java.security.KeyPair;
 import java.security.NoSuchAlgorithmException;
+import java.security.Principal;
 import java.security.PrivateKey;
 import java.security.cert.Certificate;
 import java.security.cert.CertificateException;
@@ -46,8 +48,36 @@
 import java.util.concurrent.LinkedBlockingQueue;
 
 /**
- * @hide
+ * The {@code KeyChain} class provides access to private keys and
+ * their corresponding certificate chains in credential storage.
+ *
+ * <p>Applications accessing the {@code KeyChain} normally go through
+ * these steps:
+ *
+ * <ol>
+ *
+ * <li>Receive a callback from an {@link javax.net.ssl.X509KeyManager
+ * X509KeyManager} that a private key is requested.
+ *
+ * <li>Call {@link #choosePrivateKeyAlias
+ * choosePrivateKeyAlias} to allow the user to select from a
+ * list of currently available private keys and corresponding
+ * certificate chains. The chosen alias will be returned by the
+ * callback {@link KeyChainAliasCallback#alias}, or null if no private
+ * key is available or the user cancels the request.
+ *
+ * <li>Call {@link #getPrivateKey} and {@link #getCertificateChain} to
+ * retrieve the credentials to return to the corresponding {@link
+ * javax.net.ssl.X509KeyManager} callbacks.
+ *
+ * </ol>
+ *
+ * <p>An application may remember the value of a selected alias to
+ * avoid prompting the user with {@link #choosePrivateKeyAlias
+ * choosePrivateKeyAlias} on subsequent connections. If the alias is
+ * no longer valid, null will be returned on lookups using that value
  */
+// TODO reference intent for credential installation when public
 public final class KeyChain {
 
     private static final String TAG = "KeyChain";
@@ -66,9 +96,58 @@
      * Launches an {@code Activity} for the user to select the alias
      * for a private key and certificate pair for authentication. The
      * selected alias or null will be returned via the
-     * IKeyChainAliasResponse callback.
+     * KeyChainAliasCallback callback.
+     *
+     * <p>{@code keyTypes} and {@code issuers} may be used to
+     * highlight suggested choices to the user, although to cope with
+     * sometimes erroneous values provided by servers, the user may be
+     * able to override these suggestions.
+     *
+     * <p>{@code host} and {@code port} may be used to give the user
+     * more context about the server requesting the credentials.
+     *
+     * <p>This method requires the caller to hold the permission
+     * {@link android.Manifest.permission#USE_CREDENTIALS}.
+     *
+     * @param activity The {@link Activity} context to use for
+     *     launching the new sub-Activity to prompt the user to select
+     *     a private key; used only to call startActivity(); must not
+     *     be null.
+     * @param response Callback to invoke when the request completes;
+     *     must not be null
+     * @param keyTypes The acceptable types of asymmetric keys such as
+     *     "RSA" or "DSA", or a null array.
+     * @param issuers The acceptable certificate issuers for the
+     *     certificate matching the private key, or null.
+     * @param host The host name of the server requesting the
+     *     certificate, or null if unavailable.
+     * @param port The port number of the server requesting the
+     *     certificate, or -1 if unavailable.
      */
-    public static void choosePrivateKeyAlias(Activity activity, KeyChainAliasResponse response) {
+    public static void choosePrivateKeyAlias(Activity activity, KeyChainAliasCallback response,
+                                             String[] keyTypes, Principal[] issuers,
+                                             String host, int port) {
+        /*
+         * TODO currently keyTypes, issuers, host, and port are
+         * unused. They are meant to follow the semantics and purpose
+         * of X509KeyManager method arguments.
+         *
+         * keyTypes would allow the list to be filtered and typically
+         * will be set correctly by the server. In practice today,
+         * most all users will want only RSA, rarely DSA, and usually
+         * only a small number of certs will be available.
+         *
+         * issuers is typically not useful. Some servers historically
+         * will send the entire list of public CAs known to the
+         * server. Others will send none. If this is used, if there
+         * are no matches after applying the constraint, it should be
+         * ignored.
+         *
+         * host and port may be shown to the user if available, but it
+         * should be clear that they are not validated values, perhaps
+         * shown along with requesting application identity to clarify
+         * the source of the request.
+         */
         if (activity == null) {
             throw new NullPointerException("activity == null");
         }
@@ -80,10 +159,10 @@
         activity.startActivity(intent);
     }
 
-    private static class AliasResponse extends IKeyChainAliasResponse.Stub {
+    private static class AliasResponse extends IKeyChainAliasCallback.Stub {
         private final Activity activity;
-        private final KeyChainAliasResponse keyChainAliasResponse;
-        private AliasResponse(Activity activity, KeyChainAliasResponse keyChainAliasResponse) {
+        private final KeyChainAliasCallback keyChainAliasResponse;
+        private AliasResponse(Activity activity, KeyChainAliasCallback keyChainAliasResponse) {
             this.activity = activity;
             this.keyChainAliasResponse = keyChainAliasResponse;
         }
@@ -104,9 +183,9 @@
     }
 
     private static class AliasAccountManagerCallback implements AccountManagerCallback<Bundle> {
-        private final KeyChainAliasResponse keyChainAliasResponse;
+        private final KeyChainAliasCallback keyChainAliasResponse;
         private final String alias;
-        private AliasAccountManagerCallback(KeyChainAliasResponse keyChainAliasResponse,
+        private AliasAccountManagerCallback(KeyChainAliasCallback keyChainAliasResponse,
                                             String alias) {
             this.keyChainAliasResponse = keyChainAliasResponse;
             this.alias = alias;
@@ -137,9 +216,16 @@
     /**
      * Returns the {@code PrivateKey} for the requested alias, or null
      * if no there is no result.
+     *
+     * <p>This method requires the caller to hold the permission
+     * {@link android.Manifest.permission#USE_CREDENTIALS}.
+     *
+     * @param alias The alias of the desired private key, typically
+     * returned via {@link KeyChainAliasCallback#alias}.
+     * @throws KeyChainException if the alias was valid but there was some problem accessing it.
      */
     public static PrivateKey getPrivateKey(Context context, String alias)
-            throws InterruptedException, RemoteException {
+            throws KeyChainException, InterruptedException {
         if (alias == null) {
             throw new NullPointerException("alias == null");
         }
@@ -152,6 +238,11 @@
             IKeyChainService keyChainService = keyChainConnection.getService();
             byte[] privateKeyBytes = keyChainService.getPrivateKey(alias, authToken);
             return toPrivateKey(privateKeyBytes);
+        } catch (RemoteException e) {
+            throw new KeyChainException(e);
+        } catch (RuntimeException e) {
+            // only certain RuntimeExceptions can be propagated across the IKeyChainService call
+            throw new KeyChainException(e);
         } finally {
             keyChainConnection.close();
         }
@@ -160,9 +251,16 @@
     /**
      * Returns the {@code X509Certificate} chain for the requested
      * alias, or null if no there is no result.
+     *
+     * <p>This method requires the caller to hold the permission
+     * {@link android.Manifest.permission#USE_CREDENTIALS}.
+     *
+     * @param alias The alias of the desired certificate chain, typically
+     * returned via {@link KeyChainAliasCallback#alias}.
+     * @throws KeyChainException if the alias was valid but there was some problem accessing it.
      */
     public static X509Certificate[] getCertificateChain(Context context, String alias)
-            throws InterruptedException, RemoteException {
+            throws KeyChainException, InterruptedException {
         if (alias == null) {
             throw new NullPointerException("alias == null");
         }
@@ -175,6 +273,11 @@
             IKeyChainService keyChainService = keyChainConnection.getService();
             byte[] certificateBytes = keyChainService.getCertificate(alias, authToken);
             return new X509Certificate[] { toCertificate(certificateBytes) };
+        } catch (RemoteException e) {
+            throw new KeyChainException(e);
+        } catch (RuntimeException e) {
+            // only certain RuntimeExceptions can be propagated across the IKeyChainService call
+            throw new KeyChainException(e);
         } finally {
             keyChainConnection.close();
         }
@@ -185,11 +288,9 @@
             throw new IllegalArgumentException("bytes == null");
         }
         try {
-            KeyFactory keyFactory = KeyFactory.getInstance("RSA");
-            return keyFactory.generatePrivate(new PKCS8EncodedKeySpec(bytes));
-        } catch (NoSuchAlgorithmException e) {
-            throw new AssertionError(e);
-        } catch (InvalidKeySpecException e) {
+            KeyPair keyPair = (KeyPair) Credentials.convertFromPem(bytes).get(0);
+            return keyPair.getPrivate();
+        } catch (IOException e) {
             throw new AssertionError(e);
         }
     }
diff --git a/keystore/java/android/security/KeyChainAliasCallback.java b/keystore/java/android/security/KeyChainAliasCallback.java
new file mode 100644
index 0000000..fc9e64b
--- /dev/null
+++ b/keystore/java/android/security/KeyChainAliasCallback.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package android.security;
+
+import android.content.Intent;
+import java.security.PrivateKey;
+import java.security.cert.X509Certificate;
+
+/**
+ * The KeyChainAliasCallback is the callback for {@link
+ * KeyChain#choosePrivateKeyAlias}.
+ */
+public interface KeyChainAliasCallback {
+
+    /**
+     * Called with the alias of the certificate chosen by the user, or
+     * null if no value was chosen.
+     */
+    public void alias(String alias);
+}
diff --git a/keystore/java/android/security/KeyChainAliasResponse.java b/keystore/java/android/security/KeyChainAliasResponse.java
deleted file mode 100644
index bcca123..0000000
--- a/keystore/java/android/security/KeyChainAliasResponse.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package android.security;
-
-import android.content.Intent;
-import java.security.PrivateKey;
-import java.security.cert.X509Certificate;
-
-/**
- * The KeyChainAliasResponse is the callback for {@link
- * KeyChain#chooseAlias}.
- *
- * @hide
- */
-public interface KeyChainAliasResponse {
-
-    /**
-     * Called with the alias of the certificate chosen by the user, or
-     * null if no value was chosen.
-     */
-    public void alias(String alias);
-}
diff --git a/keystore/java/android/security/KeyChainException.java b/keystore/java/android/security/KeyChainException.java
new file mode 100644
index 0000000..ef97ffb
--- /dev/null
+++ b/keystore/java/android/security/KeyChainException.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.security;
+
+/**
+ * Thrown on problems accessing the {@link KeyChain}.
+ */
+public class KeyChainException extends Exception {
+
+    /**
+     * Constructs a new {@code KeyChainException} that includes the
+     * current stack trace.
+     */
+    public KeyChainException() {
+    }
+
+    /**
+     * Constructs a new {@code KeyChainException} with the current stack
+     * trace and the specified detail message.
+     *
+     * @param detailMessage
+     *            the detail message for this exception.
+     */
+    public KeyChainException(String detailMessage) {
+        super(detailMessage);
+    }
+
+    /**
+     * Constructs a new {@code KeyChainException} with the current stack
+     * trace, the specified detail message and the specified cause.
+     *
+     * @param message
+     *            the detail message for this exception.
+     * @param cause
+     *            the cause of this exception, may be {@code null}.
+     */
+    public KeyChainException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    /**
+     * Constructs a new {@code KeyChainException} with the current stack
+     * trace and the specified cause.
+     *
+     * @param cause
+     *            the cause of this exception, may be {@code null}.
+     */
+    public KeyChainException(Throwable cause) {
+        super((cause == null ? null : cause.toString()), cause);
+    }
+}
diff --git a/keystore/java/android/security/KeyStore.java b/keystore/java/android/security/KeyStore.java
index 7183688..9058cae 100644
--- a/keystore/java/android/security/KeyStore.java
+++ b/keystore/java/android/security/KeyStore.java
@@ -32,6 +32,8 @@
  * preclude the use of hardware crypto.
  */
 public class KeyStore {
+
+    // ResponseCodes
     public static final int NO_ERROR = 1;
     public static final int LOCKED = 2;
     public static final int UNINITIALIZED = 3;
@@ -43,6 +45,9 @@
     public static final int UNDEFINED_ACTION = 9;
     public static final int WRONG_PASSWORD = 10;
 
+    // States
+    public enum State { UNLOCKED, LOCKED, UNINITIALIZED };
+
     private static final LocalSocketAddress sAddress = new LocalSocketAddress(
             "keystore", LocalSocketAddress.Namespace.RESERVED);
 
@@ -54,31 +59,35 @@
         return new KeyStore();
     }
 
-    public int test() {
+    public State state() {
         execute('t');
-        return mError;
+        switch (mError) {
+            case NO_ERROR: return State.UNLOCKED;
+            case LOCKED: return State.LOCKED;
+            case UNINITIALIZED: return State.UNINITIALIZED;
+            default: throw new AssertionError(mError);
+        }
     }
 
-    public byte[] get(byte[] key) {
+    private byte[] get(byte[] key) {
         ArrayList<byte[]> values = execute('g', key);
         return (values == null || values.isEmpty()) ? null : values.get(0);
     }
 
-    public String get(String key) {
-        byte[] value = get(getBytes(key));
-        return (value == null) ? null : toString(value);
+    public byte[] get(String key) {
+        return get(getBytes(key));
     }
 
-    public boolean put(byte[] key, byte[] value) {
+    private boolean put(byte[] key, byte[] value) {
         execute('i', key, value);
         return mError == NO_ERROR;
     }
 
-    public boolean put(String key, String value) {
-        return put(getBytes(key), getBytes(value));
+    public boolean put(String key, byte[] value) {
+        return put(getBytes(key), value);
     }
 
-    public boolean delete(byte[] key) {
+    private boolean delete(byte[] key) {
         execute('d', key);
         return mError == NO_ERROR;
     }
@@ -87,7 +96,7 @@
         return delete(getBytes(key));
     }
 
-    public boolean contains(byte[] key) {
+    private boolean contains(byte[] key) {
         execute('e', key);
         return mError == NO_ERROR;
     }
@@ -118,19 +127,11 @@
         return mError == NO_ERROR;
     }
 
-    public boolean password(byte[] oldPassword, byte[] newPassword) {
-        execute('p', oldPassword, newPassword);
+    private boolean password(byte[] password) {
+        execute('p', password);
         return mError == NO_ERROR;
     }
 
-    public boolean password(String oldPassword, String newPassword) {
-        return password(getBytes(oldPassword), getBytes(newPassword));
-    }
-
-    public boolean password(byte[] password) {
-        return password(password, password);
-    }
-
     public boolean password(String password) {
         return password(getBytes(password));
     }
@@ -140,7 +141,7 @@
         return mError == NO_ERROR;
     }
 
-    public boolean unlock(byte[] password) {
+    private boolean unlock(byte[] password) {
         execute('u', password);
         return mError == NO_ERROR;
     }
@@ -149,6 +150,11 @@
         return unlock(getBytes(password));
     }
 
+    public boolean isEmpty() {
+        execute('z');
+        return mError == KEY_NOT_FOUND;
+    }
+
     public int getLastError() {
         return mError;
     }
diff --git a/keystore/tests/src/android/security/KeyStoreTest.java b/keystore/tests/src/android/security/KeyStoreTest.java
index 6630a4f..4582aa0 100755
--- a/keystore/tests/src/android/security/KeyStoreTest.java
+++ b/keystore/tests/src/android/security/KeyStoreTest.java
@@ -20,6 +20,9 @@
 import android.security.KeyStore;
 import android.test.ActivityUnitTestCase;
 import android.test.suitebuilder.annotation.MediumTest;
+import java.nio.charset.Charsets;
+import java.util.Arrays;
+import java.util.HashSet;
 
 /**
  * Junit / Instrumentation test case for KeyStore class
@@ -31,16 +34,15 @@
 @MediumTest
 public class KeyStoreTest extends ActivityUnitTestCase<Activity> {
     private static final String TEST_PASSWD = "12345678";
-    private static final String TEST_EMPTY_PASSWD = "";
-    private static final String TEST_SHORT_PASSWD = "short";
     private static final String TEST_PASSWD2 = "87654321";
     private static final String TEST_KEYNAME = "testkey";
     private static final String TEST_KEYNAME1 = "testkey1";
     private static final String TEST_KEYNAME2 = "testkey2";
-    private static final String TEST_KEYVALUE = "test value";
+    private static final byte[] TEST_KEYVALUE = "test value".getBytes(Charsets.UTF_8);
 
     // "Hello, World" in Chinese
-    private static final String TEST_I18N = "\u4F60\u597D, \u4E16\u754C";
+    private static final String TEST_I18N_KEY = "\u4F60\u597D, \u4E16\u754C";
+    private static final byte[] TEST_I18N_VALUE = TEST_I18N_KEY.getBytes(Charsets.UTF_8);
 
     private KeyStore mKeyStore = null;
 
@@ -51,8 +53,10 @@
     @Override
     protected void setUp() throws Exception {
         mKeyStore = KeyStore.getInstance();
-        if (mKeyStore.test() != KeyStore.UNINITIALIZED) mKeyStore.reset();
-        assertEquals(KeyStore.UNINITIALIZED, mKeyStore.test());
+        if (mKeyStore.state() != KeyStore.State.UNINITIALIZED) {
+            mKeyStore.reset();
+        }
+        assertEquals(KeyStore.State.UNINITIALIZED, mKeyStore.state());
         super.setUp();
     }
 
@@ -62,21 +66,13 @@
         super.tearDown();
     }
 
-    public void testTest() throws Exception {
-        assertEquals(KeyStore.UNINITIALIZED, mKeyStore.test());
+    public void teststate() throws Exception {
+        assertEquals(KeyStore.State.UNINITIALIZED, mKeyStore.state());
     }
 
     public void testPassword() throws Exception {
-        //assertFalse(mKeyStore.password(TEST_EMPTY_PASSWD));
-        //assertFalse(mKeyStore.password(TEST_SHORT_PASSWD));
-
         assertTrue(mKeyStore.password(TEST_PASSWD));
-        assertEquals(KeyStore.NO_ERROR, mKeyStore.test());
-
-        assertFalse(mKeyStore.password(TEST_PASSWD2, TEST_PASSWD2));
-        //assertFalse(mKeyStore.password(TEST_PASSWD, TEST_SHORT_PASSWD));
-
-        assertTrue(mKeyStore.password(TEST_PASSWD, TEST_PASSWD2));
+        assertEquals(KeyStore.State.UNLOCKED, mKeyStore.state());
     }
 
     public void testPut() throws Exception {
@@ -87,11 +83,11 @@
     }
 
     public void testI18n() throws Exception {
-        assertFalse(mKeyStore.put(TEST_I18N, TEST_I18N));
-        assertFalse(mKeyStore.contains(TEST_I18N));
-        mKeyStore.password(TEST_I18N);
-        assertTrue(mKeyStore.put(TEST_I18N, TEST_I18N));
-        assertTrue(mKeyStore.contains(TEST_I18N));
+        assertFalse(mKeyStore.put(TEST_I18N_KEY, TEST_I18N_VALUE));
+        assertFalse(mKeyStore.contains(TEST_I18N_KEY));
+        mKeyStore.password(TEST_I18N_KEY);
+        assertTrue(mKeyStore.put(TEST_I18N_KEY, TEST_I18N_VALUE));
+        assertTrue(mKeyStore.contains(TEST_I18N_KEY));
     }
 
     public void testDelete() throws Exception {
@@ -114,33 +110,46 @@
     }
 
     public void testSaw() throws Exception {
-        String[] results = mKeyStore.saw(TEST_KEYNAME);
-        assertEquals(0, results.length);
+        String[] emptyResult = mKeyStore.saw(TEST_KEYNAME);
+        assertNotNull(emptyResult);
+        assertEquals(0, emptyResult.length);
 
         mKeyStore.password(TEST_PASSWD);
         mKeyStore.put(TEST_KEYNAME1, TEST_KEYVALUE);
         mKeyStore.put(TEST_KEYNAME2, TEST_KEYVALUE);
 
-        results = mKeyStore.saw(TEST_KEYNAME);
-        assertEquals(2, results.length);
+        String[] results = mKeyStore.saw(TEST_KEYNAME);
+        assertEquals(new HashSet(Arrays.asList(TEST_KEYNAME1.substring(TEST_KEYNAME.length()),
+                                               TEST_KEYNAME2.substring(TEST_KEYNAME.length()))),
+                     new HashSet(Arrays.asList(results)));
     }
 
     public void testLock() throws Exception {
         assertFalse(mKeyStore.lock());
 
         mKeyStore.password(TEST_PASSWD);
-        assertEquals(KeyStore.NO_ERROR, mKeyStore.test());
+        assertEquals(KeyStore.State.UNLOCKED, mKeyStore.state());
 
         assertTrue(mKeyStore.lock());
-        assertEquals(KeyStore.LOCKED, mKeyStore.test());
+        assertEquals(KeyStore.State.LOCKED, mKeyStore.state());
     }
 
     public void testUnlock() throws Exception {
         mKeyStore.password(TEST_PASSWD);
-        assertEquals(KeyStore.NO_ERROR, mKeyStore.test());
+        assertEquals(KeyStore.State.UNLOCKED, mKeyStore.state());
         mKeyStore.lock();
 
         assertFalse(mKeyStore.unlock(TEST_PASSWD2));
         assertTrue(mKeyStore.unlock(TEST_PASSWD));
     }
+
+    public void testIsEmpty() throws Exception {
+        assertTrue(mKeyStore.isEmpty());
+        mKeyStore.password(TEST_PASSWD);
+        assertTrue(mKeyStore.isEmpty());
+        mKeyStore.put(TEST_KEYNAME, TEST_KEYVALUE);
+        assertFalse(mKeyStore.isEmpty());
+        mKeyStore.reset();
+        assertTrue(mKeyStore.isEmpty());
+    }
 }
diff --git a/libs/camera/CameraParameters.cpp b/libs/camera/CameraParameters.cpp
index c295315..9392cf2 100644
--- a/libs/camera/CameraParameters.cpp
+++ b/libs/camera/CameraParameters.cpp
@@ -146,6 +146,7 @@
 const char CameraParameters::PIXEL_FORMAT_YUV422I[] = "yuv422i-yuyv";
 const char CameraParameters::PIXEL_FORMAT_YUV420P[]  = "yuv420p";
 const char CameraParameters::PIXEL_FORMAT_RGB565[] = "rgb565";
+const char CameraParameters::PIXEL_FORMAT_RGBA8888[] = "rgba8888";
 const char CameraParameters::PIXEL_FORMAT_JPEG[] = "jpeg";
 
 // Values for focus mode settings.
diff --git a/libs/gui/Android.mk b/libs/gui/Android.mk
index b5737ff..4070eba 100644
--- a/libs/gui/Android.mk
+++ b/libs/gui/Android.mk
@@ -16,7 +16,6 @@
 	ISurfaceComposerClient.cpp \
 	IGraphicBufferAlloc.cpp \
 	LayerState.cpp \
-	SharedBufferStack.cpp \
 	Surface.cpp \
 	SurfaceComposerClient.cpp \
 
diff --git a/libs/gui/ISurface.cpp b/libs/gui/ISurface.cpp
index 23b90af..96155d7 100644
--- a/libs/gui/ISurface.cpp
+++ b/libs/gui/ISurface.cpp
@@ -22,9 +22,7 @@
 
 #include <binder/Parcel.h>
 
-#include <ui/GraphicBuffer.h>
-
-#include <surfaceflinger/Surface.h>
+#include <gui/ISurfaceTexture.h>
 #include <surfaceflinger/ISurface.h>
 
 namespace android {
@@ -39,30 +37,11 @@
     {
     }
 
-    virtual sp<GraphicBuffer> requestBuffer(int bufferIdx,
-            uint32_t w, uint32_t h, uint32_t format, uint32_t usage)
-    {
+    virtual sp<ISurfaceTexture> getSurfaceTexture() const {
         Parcel data, reply;
         data.writeInterfaceToken(ISurface::getInterfaceDescriptor());
-        data.writeInt32(bufferIdx);
-        data.writeInt32(w);
-        data.writeInt32(h);
-        data.writeInt32(format);
-        data.writeInt32(usage);
-        remote()->transact(REQUEST_BUFFER, data, &reply);
-        sp<GraphicBuffer> buffer = new GraphicBuffer();
-        reply.read(*buffer);
-        return buffer;
-    }
-
-    virtual status_t setBufferCount(int bufferCount)
-    {
-        Parcel data, reply;
-        data.writeInterfaceToken(ISurface::getInterfaceDescriptor());
-        data.writeInt32(bufferCount);
-        remote()->transact(SET_BUFFER_COUNT, data, &reply);
-        status_t err = reply.readInt32();
-        return err;
+        remote()->transact(GET_SURFACE_TEXTURE, data, &reply);
+        return interface_cast<ISurfaceTexture>(reply.readStrongBinder());
     }
 };
 
@@ -74,23 +53,9 @@
     uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
 {
     switch(code) {
-        case REQUEST_BUFFER: {
+        case GET_SURFACE_TEXTURE: {
             CHECK_INTERFACE(ISurface, data, reply);
-            int bufferIdx = data.readInt32();
-            uint32_t w = data.readInt32();
-            uint32_t h = data.readInt32();
-            uint32_t format = data.readInt32();
-            uint32_t usage = data.readInt32();
-            sp<GraphicBuffer> buffer(requestBuffer(bufferIdx, w, h, format, usage));
-            if (buffer == NULL)
-                return BAD_VALUE;
-            return reply->write(*buffer);
-        }
-        case SET_BUFFER_COUNT: {
-            CHECK_INTERFACE(ISurface, data, reply);
-            int bufferCount = data.readInt32();
-            status_t err = setBufferCount(bufferCount);
-            reply->writeInt32(err);
+            reply->writeStrongBinder( getSurfaceTexture()->asBinder() );
             return NO_ERROR;
         }
         default:
diff --git a/libs/gui/ISurfaceComposer.cpp b/libs/gui/ISurfaceComposer.cpp
index 8951c3f..40450a3 100644
--- a/libs/gui/ISurfaceComposer.cpp
+++ b/libs/gui/ISurfaceComposer.cpp
@@ -57,15 +57,6 @@
         return interface_cast<ISurfaceComposerClient>(reply.readStrongBinder());
     }
 
-    virtual sp<ISurfaceComposerClient> createClientConnection()
-    {
-        uint32_t n;
-        Parcel data, reply;
-        data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
-        remote()->transact(BnSurfaceComposer::CREATE_CLIENT_CONNECTION, data, &reply);
-        return interface_cast<ISurfaceComposerClient>(reply.readStrongBinder());
-    }
-
     virtual sp<IGraphicBufferAlloc> createGraphicBufferAlloc()
     {
         uint32_t n;
@@ -174,13 +165,6 @@
         return reply.readInt32();
     }
 
-    virtual void signal() const
-    {
-        Parcel data, reply;
-        data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
-        remote()->transact(BnSurfaceComposer::SIGNAL, data, &reply, IBinder::FLAG_ONEWAY);
-    }
-
     virtual bool authenticateSurface(const sp<ISurface>& surface) const
     {
         Parcel data, reply;
@@ -229,11 +213,6 @@
             sp<IBinder> b = createConnection()->asBinder();
             reply->writeStrongBinder(b);
         } break;
-        case CREATE_CLIENT_CONNECTION: {
-            CHECK_INTERFACE(ISurfaceComposer, data, reply);
-            sp<IBinder> b = createClientConnection()->asBinder();
-            reply->writeStrongBinder(b);
-        } break;
         case CREATE_GRAPHIC_BUFFER_ALLOC: {
             CHECK_INTERFACE(ISurfaceComposer, data, reply);
             sp<IBinder> b = createGraphicBufferAlloc()->asBinder();
@@ -270,10 +249,6 @@
             CHECK_INTERFACE(ISurfaceComposer, data, reply);
             bootFinished();
         } break;
-        case SIGNAL: {
-            CHECK_INTERFACE(ISurfaceComposer, data, reply);
-            signal();
-        } break;
         case GET_CBLK: {
             CHECK_INTERFACE(ISurfaceComposer, data, reply);
             sp<IBinder> b = getCblk()->asBinder();
diff --git a/libs/gui/ISurfaceComposerClient.cpp b/libs/gui/ISurfaceComposerClient.cpp
index ea38e08..8d83392 100644
--- a/libs/gui/ISurfaceComposerClient.cpp
+++ b/libs/gui/ISurfaceComposerClient.cpp
@@ -50,9 +50,7 @@
 namespace android {
 
 enum {
-    GET_CBLK = IBinder::FIRST_CALL_TRANSACTION,
-    GET_TOKEN,
-    CREATE_SURFACE,
+    CREATE_SURFACE = IBinder::FIRST_CALL_TRANSACTION,
     DESTROY_SURFACE,
     SET_STATE
 };
@@ -65,23 +63,6 @@
     {
     }
 
-    virtual sp<IMemoryHeap> getControlBlock() const
-    {
-        Parcel data, reply;
-        data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
-        remote()->transact(GET_CBLK, data, &reply);
-        return interface_cast<IMemoryHeap>(reply.readStrongBinder());
-    }
-
-    virtual ssize_t getTokenForSurface(const sp<ISurface>& sur) const
-    {
-        Parcel data, reply;
-        data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
-        data.writeStrongBinder(sur->asBinder());
-        remote()->transact(GET_TOKEN, data, &reply);
-        return reply.readInt32();
-    }
-
     virtual sp<ISurface> createSurface( surface_data_t* params,
                                         const String8& name,
                                         DisplayID display,
@@ -131,41 +112,6 @@
 status_t BnSurfaceComposerClient::onTransact(
     uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
 {
-    // codes that don't require permission check
-
-    switch(code) {
-        case GET_CBLK: {
-            CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
-            sp<IMemoryHeap> ctl(getControlBlock());
-            reply->writeStrongBinder(ctl->asBinder());
-            return NO_ERROR;
-        } break;
-        case GET_TOKEN: {
-            CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
-            sp<ISurface> sur = interface_cast<ISurface>(data.readStrongBinder());
-            ssize_t token = getTokenForSurface(sur);
-            reply->writeInt32(token);
-            return NO_ERROR;
-        } break;
-    }
-
-    // these must be checked
-
-     IPCThreadState* ipc = IPCThreadState::self();
-     const int pid = ipc->getCallingPid();
-     const int uid = ipc->getCallingUid();
-     const int self_pid = getpid();
-     if (UNLIKELY(pid != self_pid && uid != AID_GRAPHICS && uid != 0)) {
-         // we're called from a different process, do the real check
-         if (!checkCallingPermission(
-                 String16("android.permission.ACCESS_SURFACE_FLINGER")))
-         {
-             LOGE("Permission Denial: "
-                     "can't openGlobalTransaction pid=%d, uid=%d", pid, uid);
-             return PERMISSION_DENIED;
-         }
-     }
-
      switch(code) {
         case CREATE_SURFACE: {
             CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
diff --git a/libs/gui/SharedBufferStack.cpp b/libs/gui/SharedBufferStack.cpp
deleted file mode 100644
index 7505d53..0000000
--- a/libs/gui/SharedBufferStack.cpp
+++ /dev/null
@@ -1,714 +0,0 @@
-/*
- * Copyright (C) 2007 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_TAG "SharedBufferStack"
-
-#include <stdint.h>
-#include <sys/types.h>
-
-#include <utils/Debug.h>
-#include <utils/Log.h>
-#include <utils/threads.h>
-
-#include <private/surfaceflinger/SharedBufferStack.h>
-
-#include <ui/Rect.h>
-#include <ui/Region.h>
-
-#define DEBUG_ATOMICS 0
-
-namespace android {
-// ----------------------------------------------------------------------------
-
-SharedClient::SharedClient()
-    : lock(Mutex::SHARED), cv(Condition::SHARED)
-{
-}
-
-SharedClient::~SharedClient() {
-}
-
-
-// these functions are used by the clients
-status_t SharedClient::validate(size_t i) const {
-    if (uint32_t(i) >= uint32_t(SharedBufferStack::NUM_LAYERS_MAX))
-        return BAD_INDEX;
-    return surfaces[i].status;
-}
-
-// ----------------------------------------------------------------------------
-
-
-SharedBufferStack::SharedBufferStack()
-{
-}
-
-void SharedBufferStack::init(int32_t i)
-{
-    status = NO_ERROR;
-    identity = i;
-}
-
-status_t SharedBufferStack::setCrop(int buffer, const Rect& crop)
-{
-    if (uint32_t(buffer) >= NUM_BUFFER_MAX)
-        return BAD_INDEX;
-
-    buffers[buffer].crop.l = uint16_t(crop.left);
-    buffers[buffer].crop.t = uint16_t(crop.top);
-    buffers[buffer].crop.r = uint16_t(crop.right);
-    buffers[buffer].crop.b = uint16_t(crop.bottom);
-    return NO_ERROR;
-}
-
-status_t SharedBufferStack::setTransform(int buffer, uint8_t transform)
-{
-    if (uint32_t(buffer) >= NUM_BUFFER_MAX)
-        return BAD_INDEX;
-    buffers[buffer].transform = transform;
-    return NO_ERROR;
-}
-
-status_t SharedBufferStack::setDirtyRegion(int buffer, const Region& dirty)
-{
-    if (uint32_t(buffer) >= NUM_BUFFER_MAX)
-        return BAD_INDEX;
-
-    FlatRegion& reg(buffers[buffer].dirtyRegion);
-    if (dirty.isEmpty()) {
-        reg.count = 0;
-        return NO_ERROR;
-    }
-
-    size_t count;
-    Rect const* r = dirty.getArray(&count);
-    if (count > FlatRegion::NUM_RECT_MAX) {
-        const Rect bounds(dirty.getBounds());
-        reg.count = 1;
-        reg.rects[0].l = uint16_t(bounds.left);
-        reg.rects[0].t = uint16_t(bounds.top);
-        reg.rects[0].r = uint16_t(bounds.right);
-        reg.rects[0].b = uint16_t(bounds.bottom);
-    } else {
-        reg.count = count;
-        for (size_t i=0 ; i<count ; i++) {
-            reg.rects[i].l = uint16_t(r[i].left);
-            reg.rects[i].t = uint16_t(r[i].top);
-            reg.rects[i].r = uint16_t(r[i].right);
-            reg.rects[i].b = uint16_t(r[i].bottom);
-        }
-    }
-    return NO_ERROR;
-}
-
-Region SharedBufferStack::getDirtyRegion(int buffer) const
-{
-    Region res;
-    if (uint32_t(buffer) >= NUM_BUFFER_MAX)
-        return res;
-
-    const FlatRegion& reg(buffers[buffer].dirtyRegion);
-    if (reg.count > FlatRegion::NUM_RECT_MAX)
-        return res;
-
-    if (reg.count == 1) {
-        const Rect r(
-                reg.rects[0].l,
-                reg.rects[0].t,
-                reg.rects[0].r,
-                reg.rects[0].b);
-        res.set(r);
-    } else {
-        for (size_t i=0 ; i<reg.count ; i++) {
-            const Rect r(
-                    reg.rects[i].l,
-                    reg.rects[i].t,
-                    reg.rects[i].r,
-                    reg.rects[i].b);
-            res.orSelf(r);
-        }
-    }
-    return res;
-}
-
-Rect SharedBufferStack::getCrop(int buffer) const
-{
-    Rect res(-1, -1);
-    if (uint32_t(buffer) >= NUM_BUFFER_MAX)
-        return res;
-    res.left = buffers[buffer].crop.l;
-    res.top = buffers[buffer].crop.t;
-    res.right = buffers[buffer].crop.r;
-    res.bottom = buffers[buffer].crop.b;
-    return res;
-}
-
-uint32_t SharedBufferStack::getTransform(int buffer) const
-{
-    if (uint32_t(buffer) >= NUM_BUFFER_MAX)
-        return 0;
-    return buffers[buffer].transform;
-}
-
-
-// ----------------------------------------------------------------------------
-
-SharedBufferBase::SharedBufferBase(SharedClient* sharedClient,
-        int surface, int32_t identity)
-    : mSharedClient(sharedClient), 
-      mSharedStack(sharedClient->surfaces + surface),
-      mIdentity(identity)
-{
-}
-
-SharedBufferBase::~SharedBufferBase()
-{
-}
-
-status_t SharedBufferBase::getStatus() const
-{
-    SharedBufferStack& stack( *mSharedStack );
-    return stack.status;
-}
-
-int32_t SharedBufferBase::getIdentity() const
-{
-    SharedBufferStack& stack( *mSharedStack );
-    return stack.identity;
-}
-
-String8 SharedBufferBase::dump(char const* prefix) const
-{
-    const size_t SIZE = 1024;
-    char buffer[SIZE];
-    String8 result;
-    SharedBufferStack& stack( *mSharedStack );
-    snprintf(buffer, SIZE, 
-            "%s[ head=%2d, available=%2d, queued=%2d ] "
-            "reallocMask=%08x, identity=%d, status=%d",
-            prefix, stack.head, stack.available, stack.queued,
-            stack.reallocMask, stack.identity, stack.status);
-    result.append(buffer);
-    result.append("\n");
-    return result;
-}
-
-status_t SharedBufferBase::waitForCondition(const ConditionBase& condition)
-{
-    const SharedBufferStack& stack( *mSharedStack );
-    SharedClient& client( *mSharedClient );
-    const nsecs_t TIMEOUT = s2ns(1);
-    const int identity = mIdentity;
-
-    Mutex::Autolock _l(client.lock);
-    while ((condition()==false) &&
-            (stack.identity == identity) &&
-            (stack.status == NO_ERROR))
-    {
-        status_t err = client.cv.waitRelative(client.lock, TIMEOUT);
-        // handle errors and timeouts
-        if (CC_UNLIKELY(err != NO_ERROR)) {
-            if (err == TIMED_OUT) {
-                if (condition()) {
-                    LOGE("waitForCondition(%s) timed out (identity=%d), "
-                        "but condition is true! We recovered but it "
-                        "shouldn't happen." , condition.name(), stack.identity);
-                    break;
-                } else {
-                    LOGW("waitForCondition(%s) timed out "
-                        "(identity=%d, status=%d). "
-                        "CPU may be pegged. trying again.", condition.name(),
-                        stack.identity, stack.status);
-                }
-            } else {
-                LOGE("waitForCondition(%s) error (%s) ",
-                        condition.name(), strerror(-err));
-                return err;
-            }
-        }
-    }
-    return (stack.identity != mIdentity) ? status_t(BAD_INDEX) : stack.status;
-}
-// ============================================================================
-// conditions and updates
-// ============================================================================
-
-SharedBufferClient::DequeueCondition::DequeueCondition(
-        SharedBufferClient* sbc) : ConditionBase(sbc)  { 
-}
-bool SharedBufferClient::DequeueCondition::operator()() const {
-    return stack.available > 0;
-}
-
-SharedBufferClient::LockCondition::LockCondition(
-        SharedBufferClient* sbc, int buf) : ConditionBase(sbc), buf(buf) { 
-}
-bool SharedBufferClient::LockCondition::operator()() const {
-    // NOTE: if stack.head is messed up, we could crash the client
-    // or cause some drawing artifacts. This is okay, as long as it is
-    // limited to the client.
-    return (buf != stack.index[stack.head]);
-}
-
-SharedBufferServer::BuffersAvailableCondition::BuffersAvailableCondition(
-        SharedBufferServer* sbs, int numBuffers) : ConditionBase(sbs),
-        mNumBuffers(numBuffers) {
-}
-bool SharedBufferServer::BuffersAvailableCondition::operator()() const {
-    return stack.available == mNumBuffers;
-}
-
-// ----------------------------------------------------------------------------
-
-SharedBufferClient::QueueUpdate::QueueUpdate(SharedBufferBase* sbb)
-    : UpdateBase(sbb) {    
-}
-ssize_t SharedBufferClient::QueueUpdate::operator()() {
-    android_atomic_inc(&stack.queued);
-    return NO_ERROR;
-}
-
-SharedBufferClient::DequeueUpdate::DequeueUpdate(SharedBufferBase* sbb)
-    : UpdateBase(sbb) {
-}
-ssize_t SharedBufferClient::DequeueUpdate::operator()() {
-    if (android_atomic_dec(&stack.available) == 0) {
-        LOGW("dequeue probably called from multiple threads!");
-    }
-    return NO_ERROR;
-}
-
-SharedBufferClient::CancelUpdate::CancelUpdate(SharedBufferBase* sbb,
-        int tail, int buf)
-    : UpdateBase(sbb), tail(tail), buf(buf) {
-}
-ssize_t SharedBufferClient::CancelUpdate::operator()() {
-    stack.index[tail] = buf;
-    android_atomic_inc(&stack.available);
-    return NO_ERROR;
-}
-
-SharedBufferServer::RetireUpdate::RetireUpdate(
-        SharedBufferBase* sbb, int numBuffers)
-    : UpdateBase(sbb), numBuffers(numBuffers) {
-}
-ssize_t SharedBufferServer::RetireUpdate::operator()() {
-    int32_t head = stack.head;
-    if (uint32_t(head) >= SharedBufferStack::NUM_BUFFER_MAX)
-        return BAD_VALUE;
-
-    // Decrement the number of queued buffers 
-    int32_t queued;
-    do {
-        queued = stack.queued;
-        if (queued == 0) {
-            return NOT_ENOUGH_DATA;
-        }
-    } while (android_atomic_cmpxchg(queued, queued-1, &stack.queued));
-    
-    // lock the buffer before advancing head, which automatically unlocks
-    // the buffer we preventively locked upon entering this function
-
-    head = (head + 1) % numBuffers;
-    const int8_t headBuf = stack.index[head];
-    stack.headBuf = headBuf;
-
-    // head is only modified here, so we don't need to use cmpxchg
-    android_atomic_write(head, &stack.head);
-
-    // now that head has moved, we can increment the number of available buffers
-    android_atomic_inc(&stack.available);
-    return head;
-}
-
-SharedBufferServer::StatusUpdate::StatusUpdate(
-        SharedBufferBase* sbb, status_t status)
-    : UpdateBase(sbb), status(status) {
-}
-
-ssize_t SharedBufferServer::StatusUpdate::operator()() {
-    android_atomic_write(status, &stack.status);
-    return NO_ERROR;
-}
-
-// ============================================================================
-
-SharedBufferClient::SharedBufferClient(SharedClient* sharedClient,
-        int surface, int num, int32_t identity)
-    : SharedBufferBase(sharedClient, surface, identity),
-      mNumBuffers(num), tail(0)
-{
-    SharedBufferStack& stack( *mSharedStack );
-    tail = computeTail();
-    queued_head = stack.head;
-}
-
-int32_t SharedBufferClient::computeTail() const
-{
-    SharedBufferStack& stack( *mSharedStack );
-    return (mNumBuffers + stack.head - stack.available + 1) % mNumBuffers;
-}
-
-ssize_t SharedBufferClient::dequeue()
-{
-    SharedBufferStack& stack( *mSharedStack );
-
-    RWLock::AutoRLock _rd(mLock);
-
-    const nsecs_t dequeueTime = systemTime(SYSTEM_TIME_THREAD);
-
-    //LOGD("[%d] about to dequeue a buffer",
-    //        mSharedStack->identity);
-    DequeueCondition condition(this);
-    status_t err = waitForCondition(condition);
-    if (err != NO_ERROR)
-        return ssize_t(err);
-
-    DequeueUpdate update(this);
-    updateCondition( update );
-
-    int dequeued = stack.index[tail];
-    tail = ((tail+1 >= mNumBuffers) ? 0 : tail+1);
-    LOGD_IF(DEBUG_ATOMICS, "dequeued=%d, tail++=%d, %s",
-            dequeued, tail, dump("").string());
-
-    mDequeueTime[dequeued] = dequeueTime; 
-
-    return dequeued;
-}
-
-status_t SharedBufferClient::undoDequeue(int buf)
-{
-    return cancel(buf);
-}
-
-status_t SharedBufferClient::cancel(int buf)
-{
-    RWLock::AutoRLock _rd(mLock);
-
-    // calculate the new position of the tail index (essentially tail--)
-    int localTail = (tail + mNumBuffers - 1) % mNumBuffers;
-    CancelUpdate update(this, localTail, buf);
-    status_t err = updateCondition( update );
-    if (err == NO_ERROR) {
-        tail = localTail;
-    }
-    return err;
-}
-
-status_t SharedBufferClient::lock(int buf)
-{
-    RWLock::AutoRLock _rd(mLock);
-
-    SharedBufferStack& stack( *mSharedStack );
-    LockCondition condition(this, buf);
-    status_t err = waitForCondition(condition);
-    return err;
-}
-
-status_t SharedBufferClient::queue(int buf)
-{
-    RWLock::AutoRLock _rd(mLock);
-
-    SharedBufferStack& stack( *mSharedStack );
-
-    queued_head = (queued_head + 1) % mNumBuffers;
-    stack.index[queued_head] = buf;
-
-    QueueUpdate update(this);
-    status_t err = updateCondition( update );
-    LOGD_IF(DEBUG_ATOMICS, "queued=%d, %s", buf, dump("").string());
-
-    const nsecs_t now = systemTime(SYSTEM_TIME_THREAD);
-    stack.stats.totalTime = ns2us(now - mDequeueTime[buf]);
-
-    return err;
-}
-
-bool SharedBufferClient::needNewBuffer(int buf) const
-{
-    SharedBufferStack& stack( *mSharedStack );
-    const uint32_t mask = 1<<(31-buf);
-    return (android_atomic_and(~mask, &stack.reallocMask) & mask) != 0;
-}
-
-status_t SharedBufferClient::setCrop(int buf, const Rect& crop)
-{
-    SharedBufferStack& stack( *mSharedStack );
-    return stack.setCrop(buf, crop);
-}
-
-status_t SharedBufferClient::setTransform(int buf, uint32_t transform)
-{
-    SharedBufferStack& stack( *mSharedStack );
-    return stack.setTransform(buf, uint8_t(transform));
-}
-
-status_t SharedBufferClient::setDirtyRegion(int buf, const Region& reg)
-{
-    SharedBufferStack& stack( *mSharedStack );
-    return stack.setDirtyRegion(buf, reg);
-}
-
-status_t SharedBufferClient::setBufferCount(
-        int bufferCount, const SetBufferCountCallback& ipc)
-{
-    SharedBufferStack& stack( *mSharedStack );
-    if (uint32_t(bufferCount) >= SharedBufferStack::NUM_BUFFER_MAX)
-        return BAD_VALUE;
-
-    if (uint32_t(bufferCount) < SharedBufferStack::NUM_BUFFER_MIN)
-        return BAD_VALUE;
-
-    RWLock::AutoWLock _wr(mLock);
-
-    status_t err = ipc(bufferCount);
-    if (err == NO_ERROR) {
-        mNumBuffers = bufferCount;
-        queued_head = (stack.head + stack.queued) % mNumBuffers;
-        tail = computeTail();
-    }
-    return err;
-}
-
-// ----------------------------------------------------------------------------
-
-SharedBufferServer::SharedBufferServer(SharedClient* sharedClient,
-        int surface, int num, int32_t identity)
-    : SharedBufferBase(sharedClient, surface, identity),
-      mNumBuffers(num)
-{
-    mSharedStack->init(identity);
-    mSharedStack->token = surface;
-    mSharedStack->head = num-1;
-    mSharedStack->available = num;
-    mSharedStack->queued = 0;
-    mSharedStack->reallocMask = 0;
-    memset(mSharedStack->buffers, 0, sizeof(mSharedStack->buffers));
-    for (int i=0 ; i<num ; i++) {
-        mBufferList.add(i);
-        mSharedStack->index[i] = i;
-    }
-}
-
-SharedBufferServer::~SharedBufferServer()
-{
-}
-
-ssize_t SharedBufferServer::retireAndLock()
-{
-    RWLock::AutoRLock _l(mLock);
-
-    RetireUpdate update(this, mNumBuffers);
-    ssize_t buf = updateCondition( update );
-    if (buf >= 0) {
-        if (uint32_t(buf) >= SharedBufferStack::NUM_BUFFER_MAX)
-            return BAD_VALUE;
-        SharedBufferStack& stack( *mSharedStack );
-        buf = stack.index[buf];
-        LOGD_IF(DEBUG_ATOMICS && buf>=0, "retire=%d, %s",
-                int(buf), dump("").string());
-    }
-    return buf;
-}
-
-void SharedBufferServer::setStatus(status_t status)
-{
-    if (status < NO_ERROR) {
-        StatusUpdate update(this, status);
-        updateCondition( update );
-    }
-}
-
-status_t SharedBufferServer::reallocateAll()
-{
-    RWLock::AutoRLock _l(mLock);
-
-    SharedBufferStack& stack( *mSharedStack );
-    uint32_t mask = mBufferList.getMask();
-    android_atomic_or(mask, &stack.reallocMask);
-    return NO_ERROR;
-}
-
-status_t SharedBufferServer::reallocateAllExcept(int buffer)
-{
-    RWLock::AutoRLock _l(mLock);
-
-    SharedBufferStack& stack( *mSharedStack );
-    BufferList temp(mBufferList);
-    temp.remove(buffer);
-    uint32_t mask = temp.getMask();
-    android_atomic_or(mask, &stack.reallocMask);
-    return NO_ERROR;
-}
-
-int32_t SharedBufferServer::getQueuedCount() const
-{
-    SharedBufferStack& stack( *mSharedStack );
-    return stack.queued;
-}
-
-Region SharedBufferServer::getDirtyRegion(int buf) const
-{
-    SharedBufferStack& stack( *mSharedStack );
-    return stack.getDirtyRegion(buf);
-}
-
-Rect SharedBufferServer::getCrop(int buf) const
-{
-    SharedBufferStack& stack( *mSharedStack );
-    return stack.getCrop(buf);
-}
-
-uint32_t SharedBufferServer::getTransform(int buf) const
-{
-    SharedBufferStack& stack( *mSharedStack );
-    return stack.getTransform(buf);
-}
-
-/*
- * NOTE: this is not thread-safe on the server-side, meaning
- * 'head' cannot move during this operation. The client-side
- * can safely operate an usual.
- *
- */
-status_t SharedBufferServer::resize(int newNumBuffers)
-{
-    if ((unsigned int)(newNumBuffers) < SharedBufferStack::NUM_BUFFER_MIN ||
-        (unsigned int)(newNumBuffers) > SharedBufferStack::NUM_BUFFER_MAX) {
-        return BAD_VALUE;
-    }
-
-    RWLock::AutoWLock _l(mLock);
-
-    if (newNumBuffers < mNumBuffers) {
-        return shrink(newNumBuffers);
-    } else {
-        return grow(newNumBuffers);
-    }
-}
-
-status_t SharedBufferServer::grow(int newNumBuffers)
-{
-    SharedBufferStack& stack( *mSharedStack );
-    const int numBuffers = mNumBuffers;
-    const int extra = newNumBuffers - numBuffers;
-
-    // read the head, make sure it's valid
-    int32_t head = stack.head;
-    if (uint32_t(head) >= SharedBufferStack::NUM_BUFFER_MAX)
-        return BAD_VALUE;
-
-    int base = numBuffers;
-    int32_t avail = stack.available;
-    int tail = head - avail + 1;
-
-    if (tail >= 0) {
-        int8_t* const index = const_cast<int8_t*>(stack.index);
-        const int nb = numBuffers - head;
-        memmove(&index[head + extra], &index[head], nb);
-        base = head;
-        // move head 'extra' ahead, this doesn't impact stack.index[head];
-        stack.head = head + extra;
-    }
-    stack.available += extra;
-
-    // fill the new free space with unused buffers
-    BufferList::const_iterator curr(mBufferList.free_begin());
-    for (int i=0 ; i<extra ; i++) {
-        stack.index[base+i] = *curr;
-        mBufferList.add(*curr);
-        ++curr;
-    }
-
-    mNumBuffers = newNumBuffers;
-    return NO_ERROR;
-}
-
-status_t SharedBufferServer::shrink(int newNumBuffers)
-{
-    SharedBufferStack& stack( *mSharedStack );
-
-    // Shrinking is only supported if there are no buffers currently dequeued.
-    int32_t avail = stack.available;
-    int32_t queued = stack.queued;
-    if (avail + queued != mNumBuffers) {
-        return INVALID_OPERATION;
-    }
-
-    // Wait for any queued buffers to be displayed.
-    BuffersAvailableCondition condition(this, mNumBuffers);
-    status_t err = waitForCondition(condition);
-    if (err < 0) {
-        return err;
-    }
-
-    // Reset head to index 0 and make it refer to buffer 0.  The same renaming
-    // (head -> 0) is done in the BufferManager.
-    int32_t head = stack.head;
-    int8_t* index = const_cast<int8_t*>(stack.index);
-    for (int8_t i = 0; i < newNumBuffers; i++) {
-        index[i] = i;
-    }
-    stack.head = 0;
-    stack.headBuf = 0;
-
-    // Free the buffers from the end of the list that are no longer needed.
-    for (int i = newNumBuffers; i < mNumBuffers; i++) {
-        mBufferList.remove(i);
-    }
-
-    // Tell the client to reallocate all the buffers.
-    reallocateAll();
-
-    mNumBuffers = newNumBuffers;
-    stack.available = newNumBuffers;
-
-    return NO_ERROR;
-}
-
-SharedBufferStack::Statistics SharedBufferServer::getStats() const
-{
-    SharedBufferStack& stack( *mSharedStack );
-    return stack.stats;
-}
-
-// ---------------------------------------------------------------------------
-status_t SharedBufferServer::BufferList::add(int value)
-{
-    if (uint32_t(value) >= mCapacity)
-        return BAD_VALUE;
-    uint32_t mask = 1<<(31-value);
-    if (mList & mask)
-        return ALREADY_EXISTS;
-    mList |= mask;
-    return NO_ERROR;
-}
-
-status_t SharedBufferServer::BufferList::remove(int value)
-{
-    if (uint32_t(value) >= mCapacity)
-        return BAD_VALUE;
-    uint32_t mask = 1<<(31-value);
-    if (!(mList & mask))
-        return NAME_NOT_FOUND;
-    mList &= ~mask;
-    return NO_ERROR;
-}
-
-
-// ---------------------------------------------------------------------------
-}; // namespace android
diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp
index 0c5767b..4d1d923 100644
--- a/libs/gui/Surface.cpp
+++ b/libs/gui/Surface.cpp
@@ -21,13 +21,15 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 
-#include <utils/Errors.h>
-#include <utils/threads.h>
 #include <utils/CallStack.h>
+#include <utils/Errors.h>
 #include <utils/Log.h>
+#include <utils/threads.h>
 
-#include <binder/IPCThreadState.h>
 #include <binder/IMemory.h>
+#include <binder/IPCThreadState.h>
+
+#include <gui/SurfaceTextureClient.h>
 
 #include <ui/DisplayInfo.h>
 #include <ui/GraphicBuffer.h>
@@ -35,12 +37,11 @@
 #include <ui/GraphicLog.h>
 #include <ui/Rect.h>
 
-#include <surfaceflinger/Surface.h>
 #include <surfaceflinger/ISurface.h>
 #include <surfaceflinger/ISurfaceComposer.h>
+#include <surfaceflinger/Surface.h>
 #include <surfaceflinger/SurfaceComposerClient.h>
 
-#include <private/surfaceflinger/SharedBufferStack.h>
 #include <private/surfaceflinger/LayerState.h>
 
 namespace android {
@@ -273,58 +274,10 @@
 //  Surface
 // ============================================================================
 
-class SurfaceClient : public Singleton<SurfaceClient>
-{
-    // all these attributes are constants
-    sp<ISurfaceComposer> mComposerService;
-    sp<ISurfaceComposerClient> mClient;
-    status_t mStatus;
-    SharedClient* mControl;
-    sp<IMemoryHeap> mControlMemory;
-
-    SurfaceClient()
-        : Singleton<SurfaceClient>(), mStatus(NO_INIT)
-    {
-        sp<ISurfaceComposer> sf(ComposerService::getComposerService());
-        mComposerService = sf;
-        mClient = sf->createClientConnection();
-        if (mClient != NULL) {
-            mControlMemory = mClient->getControlBlock();
-            if (mControlMemory != NULL) {
-                mControl = static_cast<SharedClient *>(
-                        mControlMemory->getBase());
-                if (mControl) {
-                    mStatus = NO_ERROR;
-                }
-            }
-        }
-    }
-    friend class Singleton<SurfaceClient>;
-public:
-    status_t initCheck() const {
-        return mStatus;
-    }
-    SharedClient* getSharedClient() const {
-        return mControl;
-    }
-    ssize_t getTokenForSurface(const sp<ISurface>& sur) const {
-        // TODO: we could cache a few tokens here to avoid an IPC
-        return mClient->getTokenForSurface(sur);
-    }
-    void signalServer() const {
-        mComposerService->signal();
-    }
-};
-
-ANDROID_SINGLETON_STATIC_INSTANCE(SurfaceClient);
-
 // ---------------------------------------------------------------------------
 
 Surface::Surface(const sp<SurfaceControl>& surface)
-    : mBufferMapper(GraphicBufferMapper::get()),
-      mClient(SurfaceClient::getInstance()),
-      mSharedBufferClient(NULL),
-      mInitCheck(NO_INIT),
+    : mInitCheck(NO_INIT),
       mSurface(surface->mSurface),
       mIdentity(surface->mIdentity),
       mFormat(surface->mFormat), mFlags(surface->mFlags),
@@ -334,10 +287,7 @@
 }
 
 Surface::Surface(const Parcel& parcel, const sp<IBinder>& ref)
-    : mBufferMapper(GraphicBufferMapper::get()),
-      mClient(SurfaceClient::getInstance()),
-      mSharedBufferClient(NULL),
-      mInitCheck(NO_INIT)
+    : mInitCheck(NO_INIT)
 {
     mSurface    = interface_cast<ISurface>(ref);
     mIdentity   = parcel.readInt32();
@@ -382,7 +332,6 @@
 
 }
 
-
 Mutex Surface::sCachedSurfacesLock;
 DefaultKeyedVector<wp<IBinder>, wp<Surface> > Surface::sCachedSurfaces;
 
@@ -422,32 +371,29 @@
     ANativeWindow::query            = query;
     ANativeWindow::perform          = perform;
 
-    DisplayInfo dinfo;
-    SurfaceComposerClient::getDisplayInfo(0, &dinfo);
-    const_cast<float&>(ANativeWindow::xdpi) = dinfo.xdpi;
-    const_cast<float&>(ANativeWindow::ydpi) = dinfo.ydpi;
-    // FIXME: set real values here
-    const_cast<int&>(ANativeWindow::minSwapInterval) = 1;
-    const_cast<int&>(ANativeWindow::maxSwapInterval) = 1;
-    const_cast<uint32_t&>(ANativeWindow::flags) = 0;
+    if (mSurface != NULL) {
+        sp<ISurfaceTexture> surfaceTexture(mSurface->getSurfaceTexture());
+        LOGE_IF(surfaceTexture==0, "got a NULL ISurfaceTexture from ISurface");
+        if (surfaceTexture != NULL) {
+            mSurfaceTextureClient = new SurfaceTextureClient(surfaceTexture);
+            mSurfaceTextureClient->setUsage(GraphicBuffer::USAGE_HW_RENDER);
+        }
 
-    mNextBufferTransform = 0;
-    mConnected = 0;
-    mSwapRectangle.makeInvalid();
-    mNextBufferCrop = Rect(0,0);
-    // two buffers by default
-    mBuffers.setCapacity(2);
-    mBuffers.insertAt(0, 2);
+        DisplayInfo dinfo;
+        SurfaceComposerClient::getDisplayInfo(0, &dinfo);
+        const_cast<float&>(ANativeWindow::xdpi) = dinfo.xdpi;
+        const_cast<float&>(ANativeWindow::ydpi) = dinfo.ydpi;
 
-    if (mSurface != 0 && mClient.initCheck() == NO_ERROR) {
-        int32_t token = mClient.getTokenForSurface(mSurface);
-        if (token >= 0) {
-            mSharedBufferClient = new SharedBufferClient(
-                    mClient.getSharedClient(), token, 2, mIdentity);
-            mInitCheck = mClient.getSharedClient()->validate(token);
-        } else {
-            LOGW("Not initializing the shared buffer client because token = %d",
-                    token);
+        const_cast<int&>(ANativeWindow::minSwapInterval) =
+                mSurfaceTextureClient->minSwapInterval;
+
+        const_cast<int&>(ANativeWindow::maxSwapInterval) =
+                mSurfaceTextureClient->maxSwapInterval;
+
+        const_cast<uint32_t&>(ANativeWindow::flags) = 0;
+
+        if (mSurfaceTextureClient != 0) {
+            mInitCheck = NO_ERROR;
         }
     }
 }
@@ -456,9 +402,8 @@
 {
     // clear all references and trigger an IPC now, to make sure things
     // happen without delay, since these resources are quite heavy.
-    mBuffers.clear();
+    mSurfaceTextureClient.clear();
     mSurface.clear();
-    delete mSharedBufferClient;
     IPCThreadState::self()->flushCommands();
 }
 
@@ -473,32 +418,6 @@
         LOGE("invalid token (identity=%u)", mIdentity);
         return mInitCheck;
     }
-
-    // verify the identity of this surface
-    uint32_t identity = mSharedBufferClient->getIdentity();
-    if (mIdentity != identity) {
-        LOGE("[Surface] using an invalid surface, "
-                "identity=%u should be %d",
-                mIdentity, identity);
-        CallStack stack;
-        stack.update();
-        stack.dump("Surface");
-        return BAD_INDEX;
-    }
-
-    // check the surface didn't become invalid
-    status_t err = mSharedBufferClient->getStatus();
-    if (err != NO_ERROR) {
-        if (!inCancelBuffer) {
-            LOGE("surface (identity=%u) is invalid, err=%d (%s)",
-                    mIdentity, err, strerror(-err));
-            CallStack stack;
-            stack.update();
-            stack.dump("Surface");
-        }
-        return err;
-    }
-
     return NO_ERROR;
 }
 
@@ -509,7 +428,8 @@
 // ----------------------------------------------------------------------------
 
 int Surface::setSwapInterval(ANativeWindow* window, int interval) {
-    return 0;
+    Surface* self = getSelf(window);
+    return self->setSwapInterval(interval);
 }
 
 int Surface::dequeueBuffer(ANativeWindow* window, 
@@ -554,383 +474,52 @@
 
 // ----------------------------------------------------------------------------
 
-bool Surface::needNewBuffer(int bufIdx,
-        uint32_t *pWidth, uint32_t *pHeight,
-        uint32_t *pFormat, uint32_t *pUsage) const
-{
-    Mutex::Autolock _l(mSurfaceLock);
-
-    // Always call needNewBuffer(), since it clears the needed buffers flags
-    bool needNewBuffer = mSharedBufferClient->needNewBuffer(bufIdx);
-    bool validBuffer = mBufferInfo.validateBuffer(mBuffers[bufIdx]);
-    bool newNeewBuffer = needNewBuffer || !validBuffer;
-    if (newNeewBuffer) {
-        mBufferInfo.get(pWidth, pHeight, pFormat, pUsage);
-    }
-    return newNeewBuffer;
+int Surface::setSwapInterval(int interval) {
+    return mSurfaceTextureClient->setSwapInterval(interval);
 }
 
-int Surface::dequeueBuffer(ANativeWindowBuffer** buffer)
-{
-    status_t err = validate();
-    if (err != NO_ERROR)
-        return err;
-
-    GraphicLog& logger(GraphicLog::getInstance());
-    logger.log(GraphicLog::SF_APP_DEQUEUE_BEFORE, mIdentity, -1);
-
-    ssize_t bufIdx = mSharedBufferClient->dequeue();
-
-    logger.log(GraphicLog::SF_APP_DEQUEUE_AFTER, mIdentity, bufIdx);
-
-    if (bufIdx < 0) {
-        LOGE("error dequeuing a buffer (%s)", strerror(bufIdx));
-        return bufIdx;
-    }
-
-    // grow the buffer array if needed
-    const size_t size = mBuffers.size();
-    const size_t needed = bufIdx+1;
-    if (size < needed) {
-        mBuffers.insertAt(size, needed-size);
-    }
-
-    uint32_t w, h, format, usage;
-    if (needNewBuffer(bufIdx, &w, &h, &format, &usage)) {
-        err = getBufferLocked(bufIdx, w, h, format, usage);
-        LOGE_IF(err, "getBufferLocked(%ld, %u, %u, %u, %08x) failed (%s)",
-                bufIdx, w, h, format, usage, strerror(-err));
-        if (err == NO_ERROR) {
-            // reset the width/height with the what we get from the buffer
-            const sp<GraphicBuffer>& backBuffer(mBuffers[bufIdx]);
-            mWidth  = uint32_t(backBuffer->width);
-            mHeight = uint32_t(backBuffer->height);
-        }
-    }
-
-    // if we still don't have a buffer here, we probably ran out of memory
-    const sp<GraphicBuffer>& backBuffer(mBuffers[bufIdx]);
-    if (!err && backBuffer==0) {
-        err = NO_MEMORY;
-    }
-
+int Surface::dequeueBuffer(ANativeWindowBuffer** buffer) {
+    status_t err = mSurfaceTextureClient->dequeueBuffer(buffer);
     if (err == NO_ERROR) {
-        mDirtyRegion.set(backBuffer->width, backBuffer->height);
-        *buffer = backBuffer.get();
-    } else {
-        mSharedBufferClient->undoDequeue(bufIdx);
-    }
-
-    return err;
-}
-
-int Surface::cancelBuffer(ANativeWindowBuffer* buffer)
-{
-    status_t err = validate(true);
-    switch (err) {
-    case NO_ERROR:
-        // no error, common case
-        break;
-    case BAD_INDEX:
-        // legitimate errors here
-        return err;
-    default:
-        // other errors happen because the surface is now invalid,
-        // for instance because it has been destroyed. In this case,
-        // we just fail silently (canceling a buffer is not technically
-        // an error at this point)
-        return NO_ERROR;
-    }
-
-    int32_t bufIdx = getBufferIndex(GraphicBuffer::getSelf(buffer));
-
-    err = mSharedBufferClient->cancel(bufIdx);
-
-    LOGE_IF(err, "error canceling buffer %d (%s)", bufIdx, strerror(-err));
-    return err;
-}
-
-
-int Surface::lockBuffer(ANativeWindowBuffer* buffer)
-{
-    status_t err = validate();
-    if (err != NO_ERROR)
-        return err;
-
-    int32_t bufIdx = getBufferIndex(GraphicBuffer::getSelf(buffer));
-
-    GraphicLog& logger(GraphicLog::getInstance());
-    logger.log(GraphicLog::SF_APP_LOCK_BEFORE, mIdentity, bufIdx);
-
-    err = mSharedBufferClient->lock(bufIdx);
-
-    logger.log(GraphicLog::SF_APP_LOCK_AFTER, mIdentity, bufIdx);
-
-    LOGE_IF(err, "error locking buffer %d (%s)", bufIdx, strerror(-err));
-    return err;
-}
-
-int Surface::queueBuffer(ANativeWindowBuffer* buffer)
-{
-    status_t err = validate();
-    if (err != NO_ERROR)
-        return err;
-
-    if (mSwapRectangle.isValid()) {
-        mDirtyRegion.set(mSwapRectangle);
-    }
-    
-    int32_t bufIdx = getBufferIndex(GraphicBuffer::getSelf(buffer));
-
-    GraphicLog::getInstance().log(GraphicLog::SF_APP_QUEUE, mIdentity, bufIdx);
-
-    mSharedBufferClient->setTransform(bufIdx, mNextBufferTransform);
-    mSharedBufferClient->setCrop(bufIdx, mNextBufferCrop);
-    mSharedBufferClient->setDirtyRegion(bufIdx, mDirtyRegion);
-    err = mSharedBufferClient->queue(bufIdx);
-    LOGE_IF(err, "error queuing buffer %d (%s)", bufIdx, strerror(-err));
-
-    if (err == NO_ERROR) {
-        // TODO: can we avoid this IPC if we know there is one pending?
-        mClient.signalServer();
+        mDirtyRegion.set(buffer[0]->width, buffer[0]->height);
     }
     return err;
 }
 
-int Surface::query(int what, int* value) const
-{
+int Surface::cancelBuffer(ANativeWindowBuffer* buffer) {
+    return mSurfaceTextureClient->cancelBuffer(buffer);
+}
+
+int Surface::lockBuffer(ANativeWindowBuffer* buffer) {
+    return mSurfaceTextureClient->lockBuffer(buffer);
+}
+
+int Surface::queueBuffer(ANativeWindowBuffer* buffer) {
+    return mSurfaceTextureClient->queueBuffer(buffer);
+}
+
+int Surface::query(int what, int* value) const {
     switch (what) {
-    case NATIVE_WINDOW_WIDTH:
-        *value = int(mWidth);
+    case NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER:
+        // TODO: this is not needed anymore
+        *value = 1;
         return NO_ERROR;
-    case NATIVE_WINDOW_HEIGHT:
-        *value = int(mHeight);
-        return NO_ERROR;
-    case NATIVE_WINDOW_FORMAT:
-        *value = int(mFormat);
-        return NO_ERROR;
-    case NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS:
-        *value = MIN_UNDEQUEUED_BUFFERS;
-        return NO_ERROR;
-    case NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER: {
-        sp<ISurfaceComposer> sf(ComposerService::getComposerService());
-        *value = sf->authenticateSurface(mSurface) ? 1 : 0;
-        return NO_ERROR;
-    }
     case NATIVE_WINDOW_CONCRETE_TYPE:
+        // TODO: this is not needed anymore
         *value = NATIVE_WINDOW_SURFACE;
         return NO_ERROR;
     }
-    return BAD_VALUE;
+    return mSurfaceTextureClient->query(what, value);
 }
 
-int Surface::perform(int operation, va_list args)
-{
-    status_t err = validate();
-    if (err != NO_ERROR)
-        return err;
-
-    int res = NO_ERROR;
-    switch (operation) {
-    case NATIVE_WINDOW_SET_USAGE:
-        dispatch_setUsage( args );
-        break;
-    case NATIVE_WINDOW_CONNECT:
-        res = dispatch_connect( args );
-        break;
-    case NATIVE_WINDOW_DISCONNECT:
-        res = dispatch_disconnect( args );
-        break;
-    case NATIVE_WINDOW_SET_CROP:
-        res = dispatch_crop( args );
-        break;
-    case NATIVE_WINDOW_SET_BUFFER_COUNT:
-        res = dispatch_set_buffer_count( args );
-        break;
-    case NATIVE_WINDOW_SET_BUFFERS_GEOMETRY:
-        res = dispatch_set_buffers_geometry( args );
-        break;
-    case NATIVE_WINDOW_SET_BUFFERS_TRANSFORM:
-        res = dispatch_set_buffers_transform( args );
-        break;
-    case NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP:
-        res = dispatch_set_buffers_timestamp( args );
-        break;
-    default:
-        res = NAME_NOT_FOUND;
-        break;
-    }
-    return res;
-}
-
-void Surface::dispatch_setUsage(va_list args) {
-    int usage = va_arg(args, int);
-    setUsage( usage );
-}
-int Surface::dispatch_connect(va_list args) {
-    int api = va_arg(args, int);
-    return connect( api );
-}
-int Surface::dispatch_disconnect(va_list args) {
-    int api = va_arg(args, int);
-    return disconnect( api );
-}
-int Surface::dispatch_crop(va_list args) {
-    android_native_rect_t const* rect = va_arg(args, android_native_rect_t*);
-    return crop( reinterpret_cast<Rect const*>(rect) );
-}
-int Surface::dispatch_set_buffer_count(va_list args) {
-    size_t bufferCount = va_arg(args, size_t);
-    return setBufferCount(bufferCount);
-}
-int Surface::dispatch_set_buffers_geometry(va_list args) {
-    int w = va_arg(args, int);
-    int h = va_arg(args, int);
-    int f = va_arg(args, int);
-    return setBuffersGeometry(w, h, f);
-}
-
-int Surface::dispatch_set_buffers_transform(va_list args) {
-    int transform = va_arg(args, int);
-    return setBuffersTransform(transform);
-}
-
-int Surface::dispatch_set_buffers_timestamp(va_list args) {
-    int64_t timestamp = va_arg(args, int64_t);
-    return setBuffersTimestamp(timestamp);
-}
-
-void Surface::setUsage(uint32_t reqUsage)
-{
-    Mutex::Autolock _l(mSurfaceLock);
-    mBufferInfo.set(reqUsage);
-}
-
-int Surface::connect(int api)
-{
-    Mutex::Autolock _l(mSurfaceLock);
-    int err = NO_ERROR;
-    switch (api) {
-        case NATIVE_WINDOW_API_EGL:
-            if (mConnected) {
-                err = -EINVAL;
-            } else {
-                mConnected = api;
-            }
-            break;
-        default:
-            err = -EINVAL;
-            break;
-    }
-    return err;
-}
-
-int Surface::disconnect(int api)
-{
-    Mutex::Autolock _l(mSurfaceLock);
-    int err = NO_ERROR;
-    switch (api) {
-        case NATIVE_WINDOW_API_EGL:
-            if (mConnected == api) {
-                mConnected = 0;
-            } else {
-                err = -EINVAL;
-            }
-            break;
-        default:
-            err = -EINVAL;
-            break;
-    }
-    return err;
-}
-
-int Surface::crop(Rect const* rect)
-{
-    Mutex::Autolock _l(mSurfaceLock);
-    // TODO: validate rect size
-
-    if (rect == NULL || rect->isEmpty()) {
-        mNextBufferCrop = Rect(0,0);
-    } else {
-        mNextBufferCrop = *rect;
-    }
-
-    return NO_ERROR;
-}
-
-int Surface::setBufferCount(int bufferCount)
-{
-    sp<ISurface> s(mSurface);
-    if (s == 0) return NO_INIT;
-
-    class SetBufferCountIPC : public SharedBufferClient::SetBufferCountCallback {
-        sp<ISurface> surface;
-        virtual status_t operator()(int bufferCount) const {
-            return surface->setBufferCount(bufferCount);
-        }
-    public:
-        SetBufferCountIPC(const sp<ISurface>& surface) : surface(surface) { }
-    } ipc(s);
-
-    status_t err = mSharedBufferClient->setBufferCount(bufferCount, ipc);
-    LOGE_IF(err, "ISurface::setBufferCount(%d) returned %s",
-            bufferCount, strerror(-err));
-
-    if (err == NO_ERROR) {
-        // Clear out any references to the old buffers.
-        mBuffers.clear();
-    }
-
-    return err;
-}
-
-int Surface::setBuffersGeometry(int w, int h, int format)
-{
-    if (w<0 || h<0 || format<0)
-        return BAD_VALUE;
-
-    if ((w && !h) || (!w && h))
-        return BAD_VALUE;
-
-    Mutex::Autolock _l(mSurfaceLock);
-    if (mConnected == NATIVE_WINDOW_API_EGL) {
-        return INVALID_OPERATION;
-    }
-
-    mBufferInfo.set(w, h, format);
-    if (format != 0) {
-        // we update the format of the surface as reported by query().
-        // this is to allow applications to change the format of a surface's
-        // buffer, and have it reflected in EGL; which is needed for
-        // EGLConfig validation.
-        mFormat = format;
-    }
-
-    mNextBufferCrop = Rect(0,0);
-
-    return NO_ERROR;
-}
-
-int Surface::setBuffersTransform(int transform)
-{
-    Mutex::Autolock _l(mSurfaceLock);
-    mNextBufferTransform = transform;
-    return NO_ERROR;
-}
-
-int Surface::setBuffersTimestamp(int64_t timestamp)
-{
-    // Surface doesn't really have anything meaningful to do with timestamps
-    // so they'll just be dropped here.
-    return NO_ERROR;
+int Surface::perform(int operation, va_list args) {
+    return mSurfaceTextureClient->perform(operation, args);
 }
 
 // ----------------------------------------------------------------------------
 
-int Surface::getConnectedApi() const
-{
-    Mutex::Autolock _l(mSurfaceLock);
-    return mConnected;
+int Surface::getConnectedApi() const {
+    return mSurfaceTextureClient->getConnectedApi();
 }
 
 // ----------------------------------------------------------------------------
@@ -967,16 +556,17 @@
     }
 
     // we're intending to do software rendering from this point
-    setUsage(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN);
+    mSurfaceTextureClient->setUsage(
+            GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN);
 
     ANativeWindowBuffer* out;
-    status_t err = dequeueBuffer(&out);
+    status_t err = mSurfaceTextureClient->dequeueBuffer(&out);
     LOGE_IF(err, "dequeueBuffer failed (%s)", strerror(-err));
     if (err == NO_ERROR) {
         sp<GraphicBuffer> backBuffer(GraphicBuffer::getSelf(out));
-        err = lockBuffer(backBuffer.get());
-        LOGE_IF(err, "lockBuffer (idx=%d) failed (%s)",
-                getBufferIndex(backBuffer), strerror(-err));
+        err = mSurfaceTextureClient->lockBuffer(backBuffer.get());
+        LOGE_IF(err, "lockBuffer (handle=%p) failed (%s)",
+                backBuffer->handle, strerror(-err));
         if (err == NO_ERROR) {
             const Rect bounds(backBuffer->width, backBuffer->height);
             const Region boundsRegion(bounds);
@@ -1043,110 +633,14 @@
     status_t err = mLockedBuffer->unlock();
     LOGE_IF(err, "failed unlocking buffer (%p)", mLockedBuffer->handle);
     
-    err = queueBuffer(mLockedBuffer.get());
-    LOGE_IF(err, "queueBuffer (idx=%d) failed (%s)",
-            getBufferIndex(mLockedBuffer), strerror(-err));
+    err = mSurfaceTextureClient->queueBuffer(mLockedBuffer.get());
+    LOGE_IF(err, "queueBuffer (handle=%p) failed (%s)",
+            mLockedBuffer->handle, strerror(-err));
 
     mPostedBuffer = mLockedBuffer;
     mLockedBuffer = 0;
     return err;
 }
 
-void Surface::setSwapRectangle(const Rect& r) {
-    Mutex::Autolock _l(mSurfaceLock);
-    mSwapRectangle = r;
-}
-
-int Surface::getBufferIndex(const sp<GraphicBuffer>& buffer) const
-{
-    int idx = buffer->getIndex();
-    if (idx < 0) {
-        // The buffer doesn't have an index set.  See if the handle the same as
-        // one of the buffers for which we do know the index.  This can happen
-        // e.g. if GraphicBuffer is used to wrap an ANativeWindowBuffer that
-        // was dequeued from an ANativeWindow.
-        for (size_t i = 0; i < mBuffers.size(); i++) {
-            if (mBuffers[i] != 0 && buffer->handle == mBuffers[i]->handle) {
-                idx = mBuffers[i]->getIndex();
-                break;
-            }
-        }
-    }
-    return idx;
-}
-
-status_t Surface::getBufferLocked(int index,
-        uint32_t w, uint32_t h, uint32_t format, uint32_t usage)
-{
-    sp<ISurface> s(mSurface);
-    if (s == 0) return NO_INIT;
-
-    status_t err = NO_MEMORY;
-
-    // free the current buffer
-    sp<GraphicBuffer>& currentBuffer(mBuffers.editItemAt(index));
-    if (currentBuffer != 0) {
-        currentBuffer.clear();
-    }
-
-    sp<GraphicBuffer> buffer = s->requestBuffer(index, w, h, format, usage);
-    LOGE_IF(buffer==0,
-            "ISurface::getBuffer(%d, %08x) returned NULL",
-            index, usage);
-    if (buffer != 0) { // this should always happen by construction
-        LOGE_IF(buffer->handle == NULL, 
-                "Surface (identity=%d) requestBuffer(%d, %u, %u, %u, %08x) "
-                "returned a buffer with a null handle",
-                mIdentity, index, w, h, format, usage);
-        err = mSharedBufferClient->getStatus();
-        LOGE_IF(err,  "Surface (identity=%d) state = %d", mIdentity, err);
-        if (!err && buffer->handle != NULL) {
-            currentBuffer = buffer;
-            currentBuffer->setIndex(index);
-        } else {
-            err = err<0 ? err : status_t(NO_MEMORY);
-        }
-    }
-    return err; 
-}
-
-// ----------------------------------------------------------------------------
-Surface::BufferInfo::BufferInfo()
-    : mWidth(0), mHeight(0), mFormat(0),
-      mUsage(GRALLOC_USAGE_HW_RENDER), mDirty(0)
-{
-}
-
-void Surface::BufferInfo::set(uint32_t w, uint32_t h, uint32_t format) {
-    if ((mWidth != w) || (mHeight != h) || (mFormat != format)) {
-        mWidth = w;
-        mHeight = h;
-        mFormat = format;
-        mDirty |= GEOMETRY;
-    }
-}
-
-void Surface::BufferInfo::set(uint32_t usage) {
-    mUsage = usage;
-}
-
-void Surface::BufferInfo::get(uint32_t *pWidth, uint32_t *pHeight,
-        uint32_t *pFormat, uint32_t *pUsage) const {
-    *pWidth  = mWidth;
-    *pHeight = mHeight;
-    *pFormat = mFormat;
-    *pUsage  = mUsage;
-}
-
-bool Surface::BufferInfo::validateBuffer(const sp<GraphicBuffer>& buffer) const {
-    // make sure we AT LEAST have the usage flags we want
-    if (mDirty || buffer==0 ||
-            ((buffer->usage & mUsage) != mUsage)) {
-        mDirty = 0;
-        return false;
-    }
-    return true;
-}
-
 // ----------------------------------------------------------------------------
 }; // namespace android
diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp
index a1ff2c1..1678711 100644
--- a/libs/gui/SurfaceComposerClient.cpp
+++ b/libs/gui/SurfaceComposerClient.cpp
@@ -20,19 +20,20 @@
 #include <sys/types.h>
 
 #include <utils/Errors.h>
-#include <utils/threads.h>
-#include <utils/SortedVector.h>
 #include <utils/Log.h>
 #include <utils/Singleton.h>
+#include <utils/SortedVector.h>
+#include <utils/String8.h>
+#include <utils/threads.h>
 
-#include <binder/IServiceManager.h>
 #include <binder/IMemory.h>
+#include <binder/IServiceManager.h>
 
 #include <ui/DisplayInfo.h>
 
+#include <surfaceflinger/ISurface.h>
 #include <surfaceflinger/ISurfaceComposer.h>
 #include <surfaceflinger/ISurfaceComposerClient.h>
-#include <surfaceflinger/ISurface.h>
 #include <surfaceflinger/SurfaceComposerClient.h>
 
 #include <private/surfaceflinger/LayerState.h>
@@ -217,7 +218,7 @@
 status_t SurfaceComposerClient::getDisplayInfo(
         DisplayID dpy, DisplayInfo* info)
 {
-    if (uint32_t(dpy)>=SharedBufferStack::NUM_DISPLAY_MAX)
+    if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
         return BAD_VALUE;
 
     volatile surface_flinger_cblk_t const * cblk = get_cblk();
@@ -235,7 +236,7 @@
 
 ssize_t SurfaceComposerClient::getDisplayWidth(DisplayID dpy)
 {
-    if (uint32_t(dpy)>=SharedBufferStack::NUM_DISPLAY_MAX)
+    if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
         return BAD_VALUE;
     volatile surface_flinger_cblk_t const * cblk = get_cblk();
     volatile display_cblk_t const * dcblk = cblk->displays + dpy;
@@ -244,7 +245,7 @@
 
 ssize_t SurfaceComposerClient::getDisplayHeight(DisplayID dpy)
 {
-    if (uint32_t(dpy)>=SharedBufferStack::NUM_DISPLAY_MAX)
+    if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
         return BAD_VALUE;
     volatile surface_flinger_cblk_t const * cblk = get_cblk();
     volatile display_cblk_t const * dcblk = cblk->displays + dpy;
@@ -253,7 +254,7 @@
 
 ssize_t SurfaceComposerClient::getDisplayOrientation(DisplayID dpy)
 {
-    if (uint32_t(dpy)>=SharedBufferStack::NUM_DISPLAY_MAX)
+    if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
         return BAD_VALUE;
     volatile surface_flinger_cblk_t const * cblk = get_cblk();
     volatile display_cblk_t const * dcblk = cblk->displays + dpy;
diff --git a/libs/gui/SurfaceTexture.cpp b/libs/gui/SurfaceTexture.cpp
index ee97dcf..3cecdb4 100644
--- a/libs/gui/SurfaceTexture.cpp
+++ b/libs/gui/SurfaceTexture.cpp
@@ -96,6 +96,7 @@
     sp<ISurfaceComposer> composer(ComposerService::getComposerService());
     mGraphicBufferAlloc = composer->createGraphicBufferAlloc();
     mNextCrop.makeInvalid();
+    memcpy(mCurrentTransformMatrix, mtxIdentity, sizeof(mCurrentTransformMatrix));
 }
 
 SurfaceTexture::~SurfaceTexture() {
@@ -270,7 +271,7 @@
             if (state == BufferSlot::DEQUEUED) {
                 dequeuedCount++;
             }
-            if (state == BufferSlot::FREE || i == mCurrentTexture) {
+            if (state == BufferSlot::FREE /*|| i == mCurrentTexture*/) {
                 foundSync = i;
                 if (i != mCurrentTexture) {
                     found = i;
@@ -547,6 +548,7 @@
         mCurrentCrop = mSlots[buf].mCrop;
         mCurrentTransform = mSlots[buf].mTransform;
         mCurrentTimestamp = mSlots[buf].mTimestamp;
+        computeCurrentTransformMatrix();
         mDequeueCondition.signal();
     } else {
         // We always bind the texture even if we don't update its contents.
@@ -596,8 +598,12 @@
 }
 
 void SurfaceTexture::getTransformMatrix(float mtx[16]) {
-    LOGV("SurfaceTexture::getTransformMatrix");
     Mutex::Autolock lock(mMutex);
+    memcpy(mtx, mCurrentTransformMatrix, sizeof(mCurrentTransformMatrix));
+}
+
+void SurfaceTexture::computeCurrentTransformMatrix() {
+    LOGV("SurfaceTexture::computeCurrentTransformMatrix");
 
     float xform[16];
     for (int i = 0; i < 16; i++) {
@@ -684,7 +690,7 @@
     // coordinate of 0, so SurfaceTexture must behave the same way.  We don't
     // want to expose this to applications, however, so we must add an
     // additional vertical flip to the transform after all the other transforms.
-    mtxMul(mtx, mtxFlipV, mtxBeforeFlipV);
+    mtxMul(mCurrentTransformMatrix, mtxFlipV, mtxBeforeFlipV);
 }
 
 nsecs_t SurfaceTexture::getTimestamp() {
diff --git a/libs/gui/SurfaceTextureClient.cpp b/libs/gui/SurfaceTextureClient.cpp
index c20fcf27..22b0852 100644
--- a/libs/gui/SurfaceTextureClient.cpp
+++ b/libs/gui/SurfaceTextureClient.cpp
@@ -181,6 +181,12 @@
 int SurfaceTextureClient::query(int what, int* value) const {
     LOGV("SurfaceTextureClient::query");
     switch (what) {
+    case NATIVE_WINDOW_FORMAT:
+        if (mReqFormat) {
+            *value = mReqFormat;
+            return NO_ERROR;
+        }
+        break;
     case NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER:
         // TODO: this is not needed anymore
         *value = 0;
diff --git a/libs/gui/tests/SurfaceTextureClient_test.cpp b/libs/gui/tests/SurfaceTextureClient_test.cpp
index 2f704c8..519b40e 100644
--- a/libs/gui/tests/SurfaceTextureClient_test.cpp
+++ b/libs/gui/tests/SurfaceTextureClient_test.cpp
@@ -32,6 +32,7 @@
     virtual void SetUp() {
         mST = new SurfaceTexture(123);
         mSTC = new SurfaceTextureClient(mST);
+        mANW = mSTC;
 
         // We need a valid GL context so we can test updateTexImage()
         // This initializes EGL and create a dummy GL context with a
@@ -69,6 +70,8 @@
     virtual void TearDown() {
         mST.clear();
         mSTC.clear();
+        mANW.clear();
+
         eglMakeCurrent(mEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
         eglDestroyContext(mEglDisplay, mEglContext);
         eglDestroySurface(mEglDisplay, mEglSurface);
@@ -86,6 +89,8 @@
 
     sp<SurfaceTexture> mST;
     sp<SurfaceTextureClient> mSTC;
+    sp<ANativeWindow> mANW;
+
     EGLDisplay mEglDisplay;
     EGLSurface mEglSurface;
     EGLContext mEglContext;
@@ -97,31 +102,26 @@
 }
 
 TEST_F(SurfaceTextureClientTest, QueuesToWindowCompositorIsFalse) {
-    sp<ANativeWindow> anw(mSTC);
     int result = -123;
-    int err = anw->query(anw.get(), NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER,
+    int err = mANW->query(mANW.get(), NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER,
             &result);
     EXPECT_EQ(NO_ERROR, err);
     EXPECT_EQ(0, result);
 }
 
 TEST_F(SurfaceTextureClientTest, ConcreteTypeIsSurfaceTextureClient) {
-    sp<ANativeWindow> anw(mSTC);
     int result = -123;
-    int err = anw->query(anw.get(), NATIVE_WINDOW_CONCRETE_TYPE, &result);
+    int err = mANW->query(mANW.get(), NATIVE_WINDOW_CONCRETE_TYPE, &result);
     EXPECT_EQ(NO_ERROR, err);
     EXPECT_EQ(NATIVE_WINDOW_SURFACE_TEXTURE_CLIENT, result);
 }
 
 TEST_F(SurfaceTextureClientTest, ANativeWindowLockFails) {
-    sp<ANativeWindow> anw(mSTC);
     ANativeWindow_Buffer buf;
-    ASSERT_EQ(BAD_VALUE, ANativeWindow_lock(anw.get(), &buf, NULL));
+    ASSERT_EQ(BAD_VALUE, ANativeWindow_lock(mANW.get(), &buf, NULL));
 }
 
 TEST_F(SurfaceTextureClientTest, EglCreateWindowSurfaceSucceeds) {
-    sp<ANativeWindow> anw(mSTC);
-
     EGLDisplay dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
     ASSERT_EQ(EGL_SUCCESS, eglGetError());
     ASSERT_NE(EGL_NO_DISPLAY, dpy);
@@ -147,7 +147,7 @@
             &numConfigs));
     ASSERT_EQ(EGL_SUCCESS, eglGetError());
 
-    EGLSurface eglSurface = eglCreateWindowSurface(dpy, myConfig, anw.get(),
+    EGLSurface eglSurface = eglCreateWindowSurface(dpy, myConfig, mANW.get(),
             NULL);
     EXPECT_NE(EGL_NO_SURFACE, eglSurface);
     EXPECT_EQ(EGL_SUCCESS, eglGetError());
@@ -156,269 +156,246 @@
 }
 
 TEST_F(SurfaceTextureClientTest, BufferGeometryInvalidSizesFail) {
-    sp<ANativeWindow> anw(mSTC);
-
-    EXPECT_GT(OK, native_window_set_buffers_geometry(anw.get(), -1,  0,  0));
-    EXPECT_GT(OK, native_window_set_buffers_geometry(anw.get(),  0, -1,  0));
-    EXPECT_GT(OK, native_window_set_buffers_geometry(anw.get(),  0,  0, -1));
-    EXPECT_GT(OK, native_window_set_buffers_geometry(anw.get(), -1, -1,  0));
-    EXPECT_GT(OK, native_window_set_buffers_geometry(anw.get(),  0,  8,  0));
-    EXPECT_GT(OK, native_window_set_buffers_geometry(anw.get(),  8,  0,  0));
+    EXPECT_GT(OK, native_window_set_buffers_geometry(mANW.get(), -1,  0,  0));
+    EXPECT_GT(OK, native_window_set_buffers_geometry(mANW.get(),  0, -1,  0));
+    EXPECT_GT(OK, native_window_set_buffers_geometry(mANW.get(),  0,  0, -1));
+    EXPECT_GT(OK, native_window_set_buffers_geometry(mANW.get(), -1, -1,  0));
+    EXPECT_GT(OK, native_window_set_buffers_geometry(mANW.get(),  0,  8,  0));
+    EXPECT_GT(OK, native_window_set_buffers_geometry(mANW.get(),  8,  0,  0));
 }
 
 TEST_F(SurfaceTextureClientTest, DefaultGeometryValues) {
-    sp<ANativeWindow> anw(mSTC);
     ANativeWindowBuffer* buf;
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf));
     EXPECT_EQ(1, buf->width);
     EXPECT_EQ(1, buf->height);
     EXPECT_EQ(PIXEL_FORMAT_RGBA_8888, buf->format);
-    ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf));
+    ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf));
 }
 
 TEST_F(SurfaceTextureClientTest, BufferGeometryCanBeSet) {
-    sp<ANativeWindow> anw(mSTC);
     ANativeWindowBuffer* buf;
-    EXPECT_EQ(OK, native_window_set_buffers_geometry(anw.get(), 16, 8, PIXEL_FORMAT_RGB_565));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf));
+    EXPECT_EQ(OK, native_window_set_buffers_geometry(mANW.get(), 16, 8, PIXEL_FORMAT_RGB_565));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf));
     EXPECT_EQ(16, buf->width);
     EXPECT_EQ(8, buf->height);
     EXPECT_EQ(PIXEL_FORMAT_RGB_565, buf->format);
-    ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf));
+    ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf));
 }
 
 TEST_F(SurfaceTextureClientTest, BufferGeometryDefaultSizeSetFormat) {
-    sp<ANativeWindow> anw(mSTC);
     ANativeWindowBuffer* buf;
-    EXPECT_EQ(OK, native_window_set_buffers_geometry(anw.get(), 0, 0, PIXEL_FORMAT_RGB_565));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf));
+    EXPECT_EQ(OK, native_window_set_buffers_geometry(mANW.get(), 0, 0, PIXEL_FORMAT_RGB_565));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf));
     EXPECT_EQ(1, buf->width);
     EXPECT_EQ(1, buf->height);
     EXPECT_EQ(PIXEL_FORMAT_RGB_565, buf->format);
-    ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf));
+    ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf));
 }
 
 TEST_F(SurfaceTextureClientTest, BufferGeometrySetSizeDefaultFormat) {
-    sp<ANativeWindow> anw(mSTC);
     ANativeWindowBuffer* buf;
-    EXPECT_EQ(OK, native_window_set_buffers_geometry(anw.get(), 16, 8, 0));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf));
+    EXPECT_EQ(OK, native_window_set_buffers_geometry(mANW.get(), 16, 8, 0));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf));
     EXPECT_EQ(16, buf->width);
     EXPECT_EQ(8, buf->height);
     EXPECT_EQ(PIXEL_FORMAT_RGBA_8888, buf->format);
-    ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf));
+    ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf));
 }
 
 TEST_F(SurfaceTextureClientTest, BufferGeometrySizeCanBeUnset) {
-    sp<ANativeWindow> anw(mSTC);
     ANativeWindowBuffer* buf;
-    EXPECT_EQ(OK, native_window_set_buffers_geometry(anw.get(), 16, 8, 0));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf));
+    EXPECT_EQ(OK, native_window_set_buffers_geometry(mANW.get(), 16, 8, 0));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf));
     EXPECT_EQ(16, buf->width);
     EXPECT_EQ(8, buf->height);
     EXPECT_EQ(PIXEL_FORMAT_RGBA_8888, buf->format);
-    ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf));
-    EXPECT_EQ(OK, native_window_set_buffers_geometry(anw.get(), 0, 0, 0));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf));
+    ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf));
+    EXPECT_EQ(OK, native_window_set_buffers_geometry(mANW.get(), 0, 0, 0));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf));
     EXPECT_EQ(1, buf->width);
     EXPECT_EQ(1, buf->height);
     EXPECT_EQ(PIXEL_FORMAT_RGBA_8888, buf->format);
-    ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf));
+    ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf));
 }
 
 TEST_F(SurfaceTextureClientTest, BufferGeometrySizeCanBeChangedWithoutFormat) {
-    sp<ANativeWindow> anw(mSTC);
     ANativeWindowBuffer* buf;
-    EXPECT_EQ(OK, native_window_set_buffers_geometry(anw.get(), 0, 0, PIXEL_FORMAT_RGB_565));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf));
+    EXPECT_EQ(OK, native_window_set_buffers_geometry(mANW.get(), 0, 0, PIXEL_FORMAT_RGB_565));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf));
     EXPECT_EQ(1, buf->width);
     EXPECT_EQ(1, buf->height);
     EXPECT_EQ(PIXEL_FORMAT_RGB_565, buf->format);
-    ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf));
-    EXPECT_EQ(OK, native_window_set_buffers_geometry(anw.get(), 16, 8, 0));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf));
+    ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf));
+    EXPECT_EQ(OK, native_window_set_buffers_geometry(mANW.get(), 16, 8, 0));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf));
     EXPECT_EQ(16, buf->width);
     EXPECT_EQ(8, buf->height);
     EXPECT_EQ(PIXEL_FORMAT_RGB_565, buf->format);
-    ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf));
+    ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf));
 }
 
 TEST_F(SurfaceTextureClientTest, SurfaceTextureSetDefaultSize) {
-    sp<ANativeWindow> anw(mSTC);
     sp<SurfaceTexture> st(mST);
     ANativeWindowBuffer* buf;
     EXPECT_EQ(OK, st->setDefaultBufferSize(16, 8));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf));
     EXPECT_EQ(16, buf->width);
     EXPECT_EQ(8, buf->height);
     EXPECT_EQ(PIXEL_FORMAT_RGBA_8888, buf->format);
-    ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf));
+    ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf));
 }
 
 TEST_F(SurfaceTextureClientTest, SurfaceTextureSetDefaultSizeAfterDequeue) {
-    sp<ANativeWindow> anw(mSTC);
-    sp<SurfaceTexture> st(mST);
     ANativeWindowBuffer* buf[2];
-    ASSERT_EQ(OK, native_window_set_buffer_count(anw.get(), 4));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[1]));
+    ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 4));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
     EXPECT_NE(buf[0], buf[1]);
-    ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[0]));
-    ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[1]));
-    EXPECT_EQ(OK, st->setDefaultBufferSize(16, 8));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[1]));
+    ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[0]));
+    ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[1]));
+    EXPECT_EQ(OK, mST->setDefaultBufferSize(16, 8));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
     EXPECT_NE(buf[0], buf[1]);
     EXPECT_EQ(16, buf[0]->width);
     EXPECT_EQ(16, buf[1]->width);
     EXPECT_EQ(8, buf[0]->height);
     EXPECT_EQ(8, buf[1]->height);
-    ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[0]));
-    ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[1]));
+    ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[0]));
+    ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[1]));
 }
 
 TEST_F(SurfaceTextureClientTest, SurfaceTextureSetDefaultSizeVsGeometry) {
-    sp<ANativeWindow> anw(mSTC);
-    sp<SurfaceTexture> st(mST);
     ANativeWindowBuffer* buf[2];
-    ASSERT_EQ(OK, native_window_set_buffer_count(anw.get(), 4));
-    EXPECT_EQ(OK, st->setDefaultBufferSize(16, 8));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[1]));
+    ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 4));
+    EXPECT_EQ(OK, mST->setDefaultBufferSize(16, 8));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
     EXPECT_NE(buf[0], buf[1]);
     EXPECT_EQ(16, buf[0]->width);
     EXPECT_EQ(16, buf[1]->width);
     EXPECT_EQ(8, buf[0]->height);
     EXPECT_EQ(8, buf[1]->height);
-    ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[0]));
-    ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[1]));
-    EXPECT_EQ(OK, native_window_set_buffers_geometry(anw.get(), 12, 24, 0));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[1]));
+    ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[0]));
+    ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[1]));
+    EXPECT_EQ(OK, native_window_set_buffers_geometry(mANW.get(), 12, 24, 0));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
     EXPECT_NE(buf[0], buf[1]);
     EXPECT_EQ(12, buf[0]->width);
     EXPECT_EQ(12, buf[1]->width);
     EXPECT_EQ(24, buf[0]->height);
     EXPECT_EQ(24, buf[1]->height);
-    ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[0]));
-    ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[1]));
+    ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[0]));
+    ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[1]));
 }
 
 TEST_F(SurfaceTextureClientTest, SurfaceTextureTooManyUpdateTexImage) {
-    sp<ANativeWindow> anw(mSTC);
-    sp<SurfaceTexture> st(mST);
     android_native_buffer_t* buf[3];
-    ASSERT_EQ(OK, st->setSynchronousMode(false));
-    ASSERT_EQ(OK, native_window_set_buffer_count(anw.get(), 4));
+    ASSERT_EQ(OK, mST->setSynchronousMode(false));
+    ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 4));
 
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[0]));
-    EXPECT_EQ(OK, st->updateTexImage());
-    EXPECT_EQ(OK, st->updateTexImage());
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
+    EXPECT_EQ(OK, mST->updateTexImage());
+    EXPECT_EQ(OK, mST->updateTexImage());
 
-    ASSERT_EQ(OK, st->setSynchronousMode(true));
-    ASSERT_EQ(OK, native_window_set_buffer_count(anw.get(), 3));
+    ASSERT_EQ(OK, mST->setSynchronousMode(true));
+    ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 3));
 
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[0]));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[1]));
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[1]));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[1]));
 
-    EXPECT_EQ(OK, st->updateTexImage());
-    EXPECT_EQ(OK, st->updateTexImage());
-    EXPECT_EQ(OK, st->updateTexImage());
+    EXPECT_EQ(OK, mST->updateTexImage());
+    EXPECT_EQ(OK, mST->updateTexImage());
+    EXPECT_EQ(OK, mST->updateTexImage());
 }
 
 TEST_F(SurfaceTextureClientTest, SurfaceTextureSyncModeSlowRetire) {
-    sp<ANativeWindow> anw(mSTC);
-    sp<SurfaceTexture> st(mST);
     android_native_buffer_t* buf[3];
-    ASSERT_EQ(OK, st->setSynchronousMode(true));
-    ASSERT_EQ(OK, native_window_set_buffer_count(anw.get(), 4));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[1]));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[2]));
+    ASSERT_EQ(OK, mST->setSynchronousMode(true));
+    ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 4));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[2]));
     EXPECT_NE(buf[0], buf[1]);
     EXPECT_NE(buf[1], buf[2]);
     EXPECT_NE(buf[2], buf[0]);
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[0]));
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[1]));
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[2]));
-    EXPECT_EQ(OK, st->updateTexImage());
-    EXPECT_EQ(st->getCurrentBuffer().get(), buf[0]);
-    EXPECT_EQ(OK, st->updateTexImage());
-    EXPECT_EQ(st->getCurrentBuffer().get(), buf[1]);
-    EXPECT_EQ(OK, st->updateTexImage());
-    EXPECT_EQ(st->getCurrentBuffer().get(), buf[2]);
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[1]));
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[2]));
+    EXPECT_EQ(OK, mST->updateTexImage());
+    EXPECT_EQ(mST->getCurrentBuffer().get(), buf[0]);
+    EXPECT_EQ(OK, mST->updateTexImage());
+    EXPECT_EQ(mST->getCurrentBuffer().get(), buf[1]);
+    EXPECT_EQ(OK, mST->updateTexImage());
+    EXPECT_EQ(mST->getCurrentBuffer().get(), buf[2]);
 }
 
 TEST_F(SurfaceTextureClientTest, SurfaceTextureSyncModeFastRetire) {
-    sp<ANativeWindow> anw(mSTC);
-    sp<SurfaceTexture> st(mST);
     android_native_buffer_t* buf[3];
-    ASSERT_EQ(OK, st->setSynchronousMode(true));
-    ASSERT_EQ(OK, native_window_set_buffer_count(anw.get(), 4));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[1]));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[2]));
+    ASSERT_EQ(OK, mST->setSynchronousMode(true));
+    ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 4));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[2]));
     EXPECT_NE(buf[0], buf[1]);
     EXPECT_NE(buf[1], buf[2]);
     EXPECT_NE(buf[2], buf[0]);
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[0]));
-    EXPECT_EQ(OK, st->updateTexImage());
-    EXPECT_EQ(st->getCurrentBuffer().get(), buf[0]);
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[1]));
-    EXPECT_EQ(OK, st->updateTexImage());
-    EXPECT_EQ(st->getCurrentBuffer().get(), buf[1]);
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[2]));
-    EXPECT_EQ(OK, st->updateTexImage());
-    EXPECT_EQ(st->getCurrentBuffer().get(), buf[2]);
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
+    EXPECT_EQ(OK, mST->updateTexImage());
+    EXPECT_EQ(mST->getCurrentBuffer().get(), buf[0]);
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[1]));
+    EXPECT_EQ(OK, mST->updateTexImage());
+    EXPECT_EQ(mST->getCurrentBuffer().get(), buf[1]);
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[2]));
+    EXPECT_EQ(OK, mST->updateTexImage());
+    EXPECT_EQ(mST->getCurrentBuffer().get(), buf[2]);
 }
 
 TEST_F(SurfaceTextureClientTest, SurfaceTextureSyncModeDQQR) {
-    sp<ANativeWindow> anw(mSTC);
-    sp<SurfaceTexture> st(mST);
     android_native_buffer_t* buf[3];
-    ASSERT_EQ(OK, st->setSynchronousMode(true));
-    ASSERT_EQ(OK, native_window_set_buffer_count(anw.get(), 3));
+    ASSERT_EQ(OK, mST->setSynchronousMode(true));
+    ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 3));
 
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[0]));
-    EXPECT_EQ(OK, st->updateTexImage());
-    EXPECT_EQ(st->getCurrentBuffer().get(), buf[0]);
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
+    EXPECT_EQ(OK, mST->updateTexImage());
+    EXPECT_EQ(mST->getCurrentBuffer().get(), buf[0]);
 
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[1]));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
     EXPECT_NE(buf[0], buf[1]);
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[1]));
-    EXPECT_EQ(OK, st->updateTexImage());
-    EXPECT_EQ(st->getCurrentBuffer().get(), buf[1]);
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[1]));
+    EXPECT_EQ(OK, mST->updateTexImage());
+    EXPECT_EQ(mST->getCurrentBuffer().get(), buf[1]);
 
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[2]));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[2]));
     EXPECT_NE(buf[1], buf[2]);
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[2]));
-    EXPECT_EQ(OK, st->updateTexImage());
-    EXPECT_EQ(st->getCurrentBuffer().get(), buf[2]);
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[2]));
+    EXPECT_EQ(OK, mST->updateTexImage());
+    EXPECT_EQ(mST->getCurrentBuffer().get(), buf[2]);
 }
 
 // XXX: We currently have no hardware that properly handles dequeuing the
 // buffer that is currently bound to the texture.
 TEST_F(SurfaceTextureClientTest, DISABLED_SurfaceTextureSyncModeDequeueCurrent) {
-    sp<ANativeWindow> anw(mSTC);
-    sp<SurfaceTexture> st(mST);
     android_native_buffer_t* buf[3];
     android_native_buffer_t* firstBuf;
-    ASSERT_EQ(OK, st->setSynchronousMode(true));
-    ASSERT_EQ(OK, native_window_set_buffer_count(anw.get(), 3));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &firstBuf));
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), firstBuf));
-    EXPECT_EQ(OK, st->updateTexImage());
-    EXPECT_EQ(st->getCurrentBuffer().get(), firstBuf);
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[0]));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[1]));
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[1]));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[2]));
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[2]));
+    ASSERT_EQ(OK, mST->setSynchronousMode(true));
+    ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 3));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &firstBuf));
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), firstBuf));
+    EXPECT_EQ(OK, mST->updateTexImage());
+    EXPECT_EQ(mST->getCurrentBuffer().get(), firstBuf);
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[1]));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[2]));
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[2]));
     EXPECT_NE(buf[0], buf[1]);
     EXPECT_NE(buf[1], buf[2]);
     EXPECT_NE(buf[2], buf[0]);
@@ -426,41 +403,36 @@
 }
 
 TEST_F(SurfaceTextureClientTest, SurfaceTextureSyncModeMinUndequeued) {
-    sp<ANativeWindow> anw(mSTC);
-    sp<SurfaceTexture> st(mST);
     android_native_buffer_t* buf[3];
-    ASSERT_EQ(OK, st->setSynchronousMode(true));
-    ASSERT_EQ(OK, native_window_set_buffer_count(anw.get(), 3));
+    ASSERT_EQ(OK, mST->setSynchronousMode(true));
+    ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 3));
 
-    // We should be able to dequeue all the buffers before we've queued any.
-    EXPECT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
-    EXPECT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[1]));
-    EXPECT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[2]));
+    // We should be able to dequeue all the buffers before we've queued mANWy.
+    EXPECT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+    EXPECT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
+    EXPECT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[2]));
 
-    ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[2]));
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[1]));
+    ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[2]));
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[1]));
 
-    EXPECT_EQ(OK, st->updateTexImage());
-    EXPECT_EQ(st->getCurrentBuffer().get(), buf[1]);
+    EXPECT_EQ(OK, mST->updateTexImage());
+    EXPECT_EQ(mST->getCurrentBuffer().get(), buf[1]);
 
-    EXPECT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[2]));
+    EXPECT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[2]));
 
     // Once we've queued a buffer, however we should not be able to dequeue more
     // than (buffer-count - MIN_UNDEQUEUED_BUFFERS), which is 2 in this case.
-    EXPECT_EQ(-EBUSY, anw->dequeueBuffer(anw.get(), &buf[1]));
+    EXPECT_EQ(-EBUSY, mANW->dequeueBuffer(mANW.get(), &buf[1]));
 
-    ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[0]));
-    ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[2]));
+    ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[0]));
+    ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[2]));
 }
 
 // XXX: This is not expected to pass until the synchronization hacks are removed
 // from the SurfaceTexture class.
 TEST_F(SurfaceTextureClientTest, DISABLED_SurfaceTextureSyncModeWaitRetire) {
-    sp<ANativeWindow> anw(mSTC);
-    sp<SurfaceTexture> st(mST);
-
     class MyThread : public Thread {
-        sp<SurfaceTexture> st;
+        sp<SurfaceTexture> mST;
         EGLContext ctx;
         EGLSurface sur;
         EGLDisplay dpy;
@@ -470,14 +442,14 @@
             eglMakeCurrent(dpy, sur, sur, ctx);
             usleep(20000);
             Mutex::Autolock _l(mLock);
-            st->updateTexImage();
+            mST->updateTexImage();
             mBufferRetired = true;
             eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
             return false;
         }
     public:
-        MyThread(const sp<SurfaceTexture>& st)
-            : st(st), mBufferRetired(false) {
+        MyThread(const sp<SurfaceTexture>& mST)
+            : mST(mST), mBufferRetired(false) {
             ctx = eglGetCurrentContext();
             sur = eglGetCurrentSurface(EGL_DRAW);
             dpy = eglGetCurrentDisplay();
@@ -493,25 +465,152 @@
     };
 
     android_native_buffer_t* buf[3];
-    ASSERT_EQ(OK, st->setSynchronousMode(true));
-    ASSERT_EQ(OK, native_window_set_buffer_count(anw.get(), 3));
+    ASSERT_EQ(OK, mST->setSynchronousMode(true));
+    ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 3));
     // dequeue/queue/update so we have a current buffer
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[0]));
-    st->updateTexImage();
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
+    mST->updateTexImage();
 
-    MyThread* thread = new MyThread(st);
+    MyThread* thread = new MyThread(mST);
     sp<Thread> threadBase(thread);
 
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[0]));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[1]));
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[1]));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
     thread->run();
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[2]));
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[2]));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[1]));
+    //ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[2]));
+    //ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[2]));
     thread->bufferDequeued();
     thread->requestExitAndWait();
 }
 
+TEST_F(SurfaceTextureClientTest, GetTransformMatrixReturnsVerticalFlip) {
+    android_native_buffer_t* buf[3];
+    float mtx[16] = {};
+    ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 4));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
+    ASSERT_EQ(OK, mST->updateTexImage());
+    mST->getTransformMatrix(mtx);
+
+    EXPECT_EQ(1.f, mtx[0]);
+    EXPECT_EQ(0.f, mtx[1]);
+    EXPECT_EQ(0.f, mtx[2]);
+    EXPECT_EQ(0.f, mtx[3]);
+
+    EXPECT_EQ(0.f, mtx[4]);
+    EXPECT_EQ(-1.f, mtx[5]);
+    EXPECT_EQ(0.f, mtx[6]);
+    EXPECT_EQ(0.f, mtx[7]);
+
+    EXPECT_EQ(0.f, mtx[8]);
+    EXPECT_EQ(0.f, mtx[9]);
+    EXPECT_EQ(1.f, mtx[10]);
+    EXPECT_EQ(0.f, mtx[11]);
+
+    EXPECT_EQ(0.f, mtx[12]);
+    EXPECT_EQ(1.f, mtx[13]);
+    EXPECT_EQ(0.f, mtx[14]);
+    EXPECT_EQ(1.f, mtx[15]);
 }
+
+TEST_F(SurfaceTextureClientTest, GetTransformMatrixSucceedsAfterFreeingBuffers) {
+    android_native_buffer_t* buf[3];
+    float mtx[16] = {};
+    ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 4));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
+    ASSERT_EQ(OK, mST->updateTexImage());
+    ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 6)); // frees buffers
+    mST->getTransformMatrix(mtx);
+
+    EXPECT_EQ(1.f, mtx[0]);
+    EXPECT_EQ(0.f, mtx[1]);
+    EXPECT_EQ(0.f, mtx[2]);
+    EXPECT_EQ(0.f, mtx[3]);
+
+    EXPECT_EQ(0.f, mtx[4]);
+    EXPECT_EQ(-1.f, mtx[5]);
+    EXPECT_EQ(0.f, mtx[6]);
+    EXPECT_EQ(0.f, mtx[7]);
+
+    EXPECT_EQ(0.f, mtx[8]);
+    EXPECT_EQ(0.f, mtx[9]);
+    EXPECT_EQ(1.f, mtx[10]);
+    EXPECT_EQ(0.f, mtx[11]);
+
+    EXPECT_EQ(0.f, mtx[12]);
+    EXPECT_EQ(1.f, mtx[13]);
+    EXPECT_EQ(0.f, mtx[14]);
+    EXPECT_EQ(1.f, mtx[15]);
+}
+
+TEST_F(SurfaceTextureClientTest, GetTransformMatrixSucceedsAfterFreeingBuffersWithCrop) {
+    android_native_buffer_t* buf[3];
+    float mtx[16] = {};
+    android_native_rect_t crop;
+    crop.left = 0;
+    crop.top = 0;
+    crop.right = 5;
+    crop.bottom = 5;
+
+    ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 4));
+    ASSERT_EQ(OK, native_window_set_buffers_geometry(mANW.get(), 8, 8, 0));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+    ASSERT_EQ(OK, native_window_set_crop(mANW.get(), &crop));
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
+    ASSERT_EQ(OK, mST->updateTexImage());
+    ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 6)); // frees buffers
+    mST->getTransformMatrix(mtx);
+
+    // This accounts for the 1 texel shrink for each edge that's included in the
+    // transform matrix to avoid texturing outside the crop region.
+    EXPECT_EQ(.5f, mtx[0]);
+    EXPECT_EQ(0.f, mtx[1]);
+    EXPECT_EQ(0.f, mtx[2]);
+    EXPECT_EQ(0.f, mtx[3]);
+
+    EXPECT_EQ(0.f, mtx[4]);
+    EXPECT_EQ(-.5f, mtx[5]);
+    EXPECT_EQ(0.f, mtx[6]);
+    EXPECT_EQ(0.f, mtx[7]);
+
+    EXPECT_EQ(0.f, mtx[8]);
+    EXPECT_EQ(0.f, mtx[9]);
+    EXPECT_EQ(1.f, mtx[10]);
+    EXPECT_EQ(0.f, mtx[11]);
+
+    EXPECT_EQ(0.f, mtx[12]);
+    EXPECT_EQ(.5f, mtx[13]);
+    EXPECT_EQ(0.f, mtx[14]);
+    EXPECT_EQ(1.f, mtx[15]);
+}
+
+// This test verifies that the buffer format can be queried immediately after
+// it is set.
+TEST_F(SurfaceTextureClientTest, QueryFormatAfterSettingWorks) {
+    sp<ANativeWindow> anw(mSTC);
+    int fmts[] = {
+        // RGBA_8888 should not come first, as it's the default
+        HAL_PIXEL_FORMAT_RGBX_8888,
+        HAL_PIXEL_FORMAT_RGBA_8888,
+        HAL_PIXEL_FORMAT_RGB_888,
+        HAL_PIXEL_FORMAT_RGB_565,
+        HAL_PIXEL_FORMAT_BGRA_8888,
+        HAL_PIXEL_FORMAT_RGBA_5551,
+        HAL_PIXEL_FORMAT_RGBA_4444,
+        HAL_PIXEL_FORMAT_YV12,
+    };
+
+    const int numFmts = (sizeof(fmts) / sizeof(fmts[0]));
+    for (int i = 0; i < numFmts; i++) {
+      int fmt = -1;
+      ASSERT_EQ(OK, native_window_set_buffers_geometry(anw.get(), 0, 0, fmts[i]));
+      ASSERT_EQ(OK, anw->query(anw.get(), NATIVE_WINDOW_FORMAT, &fmt));
+      EXPECT_EQ(fmts[i], fmt);
+    }
+}
+
+} // namespace android
diff --git a/libs/gui/tests/SurfaceTexture_test.cpp b/libs/gui/tests/SurfaceTexture_test.cpp
index 8747ba5..f6cefa6 100644
--- a/libs/gui/tests/SurfaceTexture_test.cpp
+++ b/libs/gui/tests/SurfaceTexture_test.cpp
@@ -14,11 +14,14 @@
  * limitations under the License.
  */
 
+//#define LOG_NDEBUG 0
+
 #include <gtest/gtest.h>
 #include <gui/SurfaceTexture.h>
 #include <gui/SurfaceTextureClient.h>
 #include <ui/GraphicBuffer.h>
 #include <utils/String8.h>
+#include <utils/threads.h>
 
 #include <surfaceflinger/ISurfaceComposer.h>
 #include <surfaceflinger/Surface.h>
@@ -43,8 +46,6 @@
     }
 
     virtual void SetUp() {
-        EGLBoolean returnValue;
-
         mEglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
         ASSERT_EQ(EGL_SUCCESS, eglGetError());
         ASSERT_NE(EGL_NO_DISPLAY, mEglDisplay);
@@ -56,9 +57,8 @@
         RecordProperty("EglVersionMajor", majorVersion);
         RecordProperty("EglVersionMajor", minorVersion);
 
-        EGLConfig myConfig = {0};
         EGLint numConfigs = 0;
-        EXPECT_TRUE(eglChooseConfig(mEglDisplay, getConfigAttribs(), &myConfig,
+        EXPECT_TRUE(eglChooseConfig(mEglDisplay, getConfigAttribs(), &mGlConfig,
                 1, &numConfigs));
         ASSERT_EQ(EGL_SUCCESS, eglGetError());
 
@@ -85,12 +85,12 @@
             ASSERT_TRUE(mSurfaceControl->isValid());
 
             ASSERT_EQ(NO_ERROR, mComposerClient->openTransaction());
-            ASSERT_EQ(NO_ERROR, mSurfaceControl->setLayer(30000));
+            ASSERT_EQ(NO_ERROR, mSurfaceControl->setLayer(0x7FFFFFFF));
             ASSERT_EQ(NO_ERROR, mSurfaceControl->show());
             ASSERT_EQ(NO_ERROR, mComposerClient->closeTransaction());
 
             sp<ANativeWindow> window = mSurfaceControl->getSurface();
-            mEglSurface = eglCreateWindowSurface(mEglDisplay, myConfig,
+            mEglSurface = eglCreateWindowSurface(mEglDisplay, mGlConfig,
                     window.get(), NULL);
         } else {
             EGLint pbufferAttribs[] = {
@@ -98,13 +98,13 @@
                 EGL_HEIGHT, getSurfaceHeight(),
                 EGL_NONE };
 
-            mEglSurface = eglCreatePbufferSurface(mEglDisplay, myConfig,
+            mEglSurface = eglCreatePbufferSurface(mEglDisplay, mGlConfig,
                     pbufferAttribs);
         }
         ASSERT_EQ(EGL_SUCCESS, eglGetError());
         ASSERT_NE(EGL_NO_SURFACE, mEglSurface);
 
-        mEglContext = eglCreateContext(mEglDisplay, myConfig, EGL_NO_CONTEXT,
+        mEglContext = eglCreateContext(mEglDisplay, mGlConfig, EGL_NO_CONTEXT,
                 getContextAttribs());
         ASSERT_EQ(EGL_SUCCESS, eglGetError());
         ASSERT_NE(EGL_NO_CONTEXT, mEglContext);
@@ -270,8 +270,12 @@
         *outPgm = program;
     }
 
+    static int abs(int value) {
+        return value > 0 ? value : -value;
+    }
+
     ::testing::AssertionResult checkPixel(int x, int y, int r,
-            int g, int b, int a) {
+            int g, int b, int a, int tolerance=2) {
         GLubyte pixel[4];
         String8 msg;
         glReadPixels(x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
@@ -285,22 +289,22 @@
             return ::testing::AssertionFailure(
                     ::testing::Message(msg.string()));
         }
-        if (r >= 0 && GLubyte(r) != pixel[0]) {
+        if (r >= 0 && abs(r - int(pixel[0])) > tolerance) {
             msg += String8::format("r(%d isn't %d)", pixel[0], r);
         }
-        if (g >= 0 && GLubyte(g) != pixel[1]) {
+        if (g >= 0 && abs(g - int(pixel[1])) > tolerance) {
             if (!msg.isEmpty()) {
                 msg += " ";
             }
             msg += String8::format("g(%d isn't %d)", pixel[1], g);
         }
-        if (b >= 0 && GLubyte(b) != pixel[2]) {
+        if (b >= 0 && abs(b - int(pixel[2])) > tolerance) {
             if (!msg.isEmpty()) {
                 msg += " ";
             }
             msg += String8::format("b(%d isn't %d)", pixel[2], b);
         }
-        if (a >= 0 && GLubyte(a) != pixel[3]) {
+        if (a >= 0 && abs(a - int(pixel[3])) > tolerance) {
             if (!msg.isEmpty()) {
                 msg += " ";
             }
@@ -322,6 +326,7 @@
     EGLDisplay mEglDisplay;
     EGLSurface mEglSurface;
     EGLContext mEglContext;
+    EGLConfig  mGlConfig;
 };
 
 // XXX: Code above this point should live elsewhere
@@ -394,6 +399,18 @@
         glBindTexture(GL_TEXTURE_EXTERNAL_OES, TEX_ID);
         ASSERT_EQ(GLenum(GL_NO_ERROR), glGetError());
 
+        // XXX: These calls are not needed for GL_TEXTURE_EXTERNAL_OES as
+        // they're setting the defautls for that target, but when hacking things
+        // to use GL_TEXTURE_2D they are needed to achieve the same behavior.
+        glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+        ASSERT_EQ(GLenum(GL_NO_ERROR), glGetError());
+        glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+        ASSERT_EQ(GLenum(GL_NO_ERROR), glGetError());
+        glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+        ASSERT_EQ(GLenum(GL_NO_ERROR), glGetError());
+        glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+        ASSERT_EQ(GLenum(GL_NO_ERROR), glGetError());
+
         GLfloat texMatrix[16];
         mST->getTransformMatrix(texMatrix);
         glUniformMatrix4fv(mTexMatrixHandle, 1, GL_FALSE, texMatrix);
@@ -467,12 +484,26 @@
     }
 }
 
+void fillRGBA8Buffer(uint8_t* buf, int w, int h, int stride) {
+    const size_t PIXEL_SIZE = 4;
+    for (int x = 0; x < w; x++) {
+        for (int y = 0; y < h; y++) {
+            off_t offset = (y * stride + x) * PIXEL_SIZE;
+            for (int c = 0; c < 4; c++) {
+                int parityX = (x / (1 << (c+2))) & 1;
+                int parityY = (y / (1 << (c+2))) & 1;
+                buf[offset + c] = (parityX ^ parityY) ? 231 : 35;
+            }
+        }
+    }
+}
+
 TEST_F(SurfaceTextureGLTest, TexturingFromCpuFilledYV12BufferNpot) {
-    const int yuvTexWidth = 64;
-    const int yuvTexHeight = 66;
+    const int texWidth = 64;
+    const int texHeight = 66;
 
     ASSERT_EQ(NO_ERROR, native_window_set_buffers_geometry(mANW.get(),
-            yuvTexWidth, yuvTexHeight, HAL_PIXEL_FORMAT_YV12));
+            texWidth, texHeight, HAL_PIXEL_FORMAT_YV12));
     ASSERT_EQ(NO_ERROR, native_window_set_usage(mANW.get(),
             GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN));
 
@@ -486,7 +517,7 @@
     // Fill the buffer with the a checkerboard pattern
     uint8_t* img = NULL;
     buf->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)(&img));
-    fillYV12Buffer(img, yuvTexWidth, yuvTexHeight, buf->getStride());
+    fillYV12Buffer(img, texWidth, texHeight, buf->getStride());
     buf->unlock();
     ASSERT_EQ(NO_ERROR, mANW->queueBuffer(mANW.get(), buf->getNativeBuffer()));
 
@@ -511,16 +542,12 @@
     EXPECT_TRUE(checkPixel(36, 22, 155,  29,   0, 255));
 }
 
-// XXX: This test is disabled because it it currently broken on all devices to
-// which I have access.  Some of the checkPixel calls are not correct because
-// I just copied them from the npot test above and haven't bothered to figure
-// out the correct values.
-TEST_F(SurfaceTextureGLTest, DISABLED_TexturingFromCpuFilledYV12BufferPow2) {
-    const int yuvTexWidth = 64;
-    const int yuvTexHeight = 64;
+TEST_F(SurfaceTextureGLTest, TexturingFromCpuFilledYV12BufferPow2) {
+    const int texWidth = 64;
+    const int texHeight = 64;
 
     ASSERT_EQ(NO_ERROR, native_window_set_buffers_geometry(mANW.get(),
-            yuvTexWidth, yuvTexHeight, HAL_PIXEL_FORMAT_YV12));
+            texWidth, texHeight, HAL_PIXEL_FORMAT_YV12));
     ASSERT_EQ(NO_ERROR, native_window_set_usage(mANW.get(),
             GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN));
 
@@ -534,7 +561,7 @@
     // Fill the buffer with the a checkerboard pattern
     uint8_t* img = NULL;
     buf->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)(&img));
-    fillYV12Buffer(img, yuvTexWidth, yuvTexHeight, buf->getStride());
+    fillYV12Buffer(img, texWidth, texHeight, buf->getStride());
     buf->unlock();
     ASSERT_EQ(NO_ERROR, mANW->queueBuffer(mANW.get(), buf->getNativeBuffer()));
 
@@ -545,26 +572,26 @@
 
     drawTexture();
 
-    EXPECT_TRUE(checkPixel( 0,  0, 255, 127, 255, 255));
-    EXPECT_TRUE(checkPixel(63,  0,   0, 133,   0, 255));
+    EXPECT_TRUE(checkPixel( 0,  0,   0, 133,   0, 255));
+    EXPECT_TRUE(checkPixel(63,  0, 255, 127, 255, 255));
     EXPECT_TRUE(checkPixel(63, 63,   0, 133,   0, 255));
     EXPECT_TRUE(checkPixel( 0, 63, 255, 127, 255, 255));
 
-    EXPECT_TRUE(checkPixel(22, 19, 247,  70, 255, 255));
-    EXPECT_TRUE(checkPixel(45, 11, 209,  32, 235, 255));
-    EXPECT_TRUE(checkPixel(52, 12, 100, 255,  73, 255));
-    EXPECT_TRUE(checkPixel( 7, 32, 155,   0, 118, 255));
-    EXPECT_TRUE(checkPixel(31, 54, 148,  71, 110, 255));
-    EXPECT_TRUE(checkPixel(29, 28, 255, 127, 255, 255));
-    EXPECT_TRUE(checkPixel(36, 41, 155,  29,   0, 255));
+    EXPECT_TRUE(checkPixel(22, 19, 100, 255,  74, 255));
+    EXPECT_TRUE(checkPixel(45, 11, 100, 255,  74, 255));
+    EXPECT_TRUE(checkPixel(52, 12, 155,   0, 181, 255));
+    EXPECT_TRUE(checkPixel( 7, 32, 150, 237, 170, 255));
+    EXPECT_TRUE(checkPixel(31, 54,   0,  71, 117, 255));
+    EXPECT_TRUE(checkPixel(29, 28,   0, 133,   0, 255));
+    EXPECT_TRUE(checkPixel(36, 41, 100, 232, 255, 255));
 }
 
 TEST_F(SurfaceTextureGLTest, TexturingFromCpuFilledYV12BufferWithCrop) {
-    const int yuvTexWidth = 64;
-    const int yuvTexHeight = 66;
+    const int texWidth = 64;
+    const int texHeight = 66;
 
     ASSERT_EQ(NO_ERROR, native_window_set_buffers_geometry(mANW.get(),
-            yuvTexWidth, yuvTexHeight, HAL_PIXEL_FORMAT_YV12));
+            texWidth, texHeight, HAL_PIXEL_FORMAT_YV12));
     ASSERT_EQ(NO_ERROR, native_window_set_usage(mANW.get(),
             GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN));
 
@@ -572,8 +599,8 @@
         {4, 6, 22, 36},
         {0, 6, 22, 36},
         {4, 0, 22, 36},
-        {4, 6, yuvTexWidth, 36},
-        {4, 6, 22, yuvTexHeight},
+        {4, 6, texWidth, 36},
+        {4, 6, 22, texHeight},
     };
 
     for (int i = 0; i < 5; i++) {
@@ -592,7 +619,7 @@
 
         uint8_t* img = NULL;
         buf->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)(&img));
-        fillYV12BufferRect(img, yuvTexWidth, yuvTexHeight, buf->getStride(), crop);
+        fillYV12BufferRect(img, texWidth, texHeight, buf->getStride(), crop);
         buf->unlock();
         ASSERT_EQ(NO_ERROR, mANW->queueBuffer(mANW.get(), buf->getNativeBuffer()));
 
@@ -618,4 +645,453 @@
     }
 }
 
+// XXX: This test is disabled because there are currently no drivers that can
+// handle RGBA textures with the GL_TEXTURE_EXTERNAL_OES target.
+TEST_F(SurfaceTextureGLTest, DISABLED_TexturingFromCpuFilledRGBABufferNpot) {
+    const int texWidth = 64;
+    const int texHeight = 66;
+
+    ASSERT_EQ(NO_ERROR, native_window_set_buffers_geometry(mANW.get(),
+            texWidth, texHeight, HAL_PIXEL_FORMAT_RGBA_8888));
+    ASSERT_EQ(NO_ERROR, native_window_set_usage(mANW.get(),
+            GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN));
+
+    android_native_buffer_t* anb;
+    ASSERT_EQ(NO_ERROR, mANW->dequeueBuffer(mANW.get(), &anb));
+    ASSERT_TRUE(anb != NULL);
+
+    sp<GraphicBuffer> buf(new GraphicBuffer(anb, false));
+    ASSERT_EQ(NO_ERROR, mANW->lockBuffer(mANW.get(), buf->getNativeBuffer()));
+
+    // Fill the buffer with the a checkerboard pattern
+    uint8_t* img = NULL;
+    buf->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)(&img));
+    fillRGBA8Buffer(img, texWidth, texHeight, buf->getStride());
+    buf->unlock();
+    ASSERT_EQ(NO_ERROR, mANW->queueBuffer(mANW.get(), buf->getNativeBuffer()));
+
+    mST->updateTexImage();
+
+    glClearColor(0.2, 0.2, 0.2, 0.2);
+    glClear(GL_COLOR_BUFFER_BIT);
+
+    drawTexture();
+
+    EXPECT_TRUE(checkPixel( 0,  0,  35,  35,  35,  35));
+    EXPECT_TRUE(checkPixel(63,  0, 231, 231, 231, 231));
+    EXPECT_TRUE(checkPixel(63, 63, 231, 231, 231, 231));
+    EXPECT_TRUE(checkPixel( 0, 63,  35,  35,  35,  35));
+
+    EXPECT_TRUE(checkPixel(15, 10,  35, 231, 231, 231));
+    EXPECT_TRUE(checkPixel(24, 63,  35, 231, 231,  35));
+    EXPECT_TRUE(checkPixel(19, 40,  87, 179,  35,  35));
+    EXPECT_TRUE(checkPixel(38, 30, 231,  35,  35,  35));
+    EXPECT_TRUE(checkPixel(42, 54,  35,  35,  35, 231));
+    EXPECT_TRUE(checkPixel(37, 33,  35, 231, 231, 231));
+    EXPECT_TRUE(checkPixel(31,  8, 231,  35,  35, 231));
+    EXPECT_TRUE(checkPixel(36, 47, 231,  35, 231, 231));
+    EXPECT_TRUE(checkPixel(24, 63,  35, 231, 231,  35));
+    EXPECT_TRUE(checkPixel(48,  3, 231, 231,  35,  35));
+    EXPECT_TRUE(checkPixel(54, 50,  35, 231, 231, 231));
+    EXPECT_TRUE(checkPixel(24, 25, 191, 191, 231, 231));
+    EXPECT_TRUE(checkPixel(10,  9,  93,  93, 231, 231));
+    EXPECT_TRUE(checkPixel(29,  4,  35,  35,  35, 231));
+    EXPECT_TRUE(checkPixel(56, 31,  35, 231, 231,  35));
+    EXPECT_TRUE(checkPixel(58, 55,  35,  35, 231, 231));
 }
+
+// XXX: This test is disabled because there are currently no drivers that can
+// handle RGBA textures with the GL_TEXTURE_EXTERNAL_OES target.
+TEST_F(SurfaceTextureGLTest, DISABLED_TexturingFromCpuFilledRGBABufferPow2) {
+    const int texWidth = 64;
+    const int texHeight = 64;
+
+    ASSERT_EQ(NO_ERROR, native_window_set_buffers_geometry(mANW.get(),
+            texWidth, texHeight, HAL_PIXEL_FORMAT_RGBA_8888));
+    ASSERT_EQ(NO_ERROR, native_window_set_usage(mANW.get(),
+            GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN));
+
+    android_native_buffer_t* anb;
+    ASSERT_EQ(NO_ERROR, mANW->dequeueBuffer(mANW.get(), &anb));
+    ASSERT_TRUE(anb != NULL);
+
+    sp<GraphicBuffer> buf(new GraphicBuffer(anb, false));
+    ASSERT_EQ(NO_ERROR, mANW->lockBuffer(mANW.get(), buf->getNativeBuffer()));
+
+    // Fill the buffer with the a checkerboard pattern
+    uint8_t* img = NULL;
+    buf->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)(&img));
+    fillRGBA8Buffer(img, texWidth, texHeight, buf->getStride());
+    buf->unlock();
+    ASSERT_EQ(NO_ERROR, mANW->queueBuffer(mANW.get(), buf->getNativeBuffer()));
+
+    mST->updateTexImage();
+
+    glClearColor(0.2, 0.2, 0.2, 0.2);
+    glClear(GL_COLOR_BUFFER_BIT);
+
+    drawTexture();
+
+    EXPECT_TRUE(checkPixel( 0,  0, 231, 231, 231, 231));
+    EXPECT_TRUE(checkPixel(63,  0,  35,  35,  35,  35));
+    EXPECT_TRUE(checkPixel(63, 63, 231, 231, 231, 231));
+    EXPECT_TRUE(checkPixel( 0, 63,  35,  35,  35,  35));
+
+    EXPECT_TRUE(checkPixel(12, 46, 231, 231, 231,  35));
+    EXPECT_TRUE(checkPixel(16,  1, 231, 231,  35, 231));
+    EXPECT_TRUE(checkPixel(21, 12, 231,  35,  35, 231));
+    EXPECT_TRUE(checkPixel(26, 51, 231,  35, 231,  35));
+    EXPECT_TRUE(checkPixel( 5, 32,  35, 231, 231,  35));
+    EXPECT_TRUE(checkPixel(13,  8,  35, 231, 231, 231));
+    EXPECT_TRUE(checkPixel(46,  3,  35,  35, 231,  35));
+    EXPECT_TRUE(checkPixel(30, 33,  35,  35,  35,  35));
+    EXPECT_TRUE(checkPixel( 6, 52, 231, 231,  35,  35));
+    EXPECT_TRUE(checkPixel(55, 33,  35, 231,  35, 231));
+    EXPECT_TRUE(checkPixel(16, 29,  35,  35, 231, 231));
+    EXPECT_TRUE(checkPixel( 1, 30,  35,  35,  35, 231));
+    EXPECT_TRUE(checkPixel(41, 37,  35,  35, 231, 231));
+    EXPECT_TRUE(checkPixel(46, 29, 231, 231,  35,  35));
+    EXPECT_TRUE(checkPixel(15, 25,  35, 231,  35, 231));
+    EXPECT_TRUE(checkPixel( 3, 52,  35, 231,  35,  35));
+}
+
+// XXX: This test is disabled because there are currently no drivers that can
+// handle RGBA textures with the GL_TEXTURE_EXTERNAL_OES target.
+TEST_F(SurfaceTextureGLTest, DISABLED_TexturingFromGLFilledRGBABufferPow2) {
+    const int texWidth = 64;
+    const int texHeight = 64;
+
+    mST->setDefaultBufferSize(texWidth, texHeight);
+
+    // Do the producer side of things
+    EGLSurface stcEglSurface = eglCreateWindowSurface(mEglDisplay, mGlConfig,
+            mANW.get(), NULL);
+    ASSERT_EQ(EGL_SUCCESS, eglGetError());
+    ASSERT_NE(EGL_NO_SURFACE, mEglSurface);
+
+    EXPECT_TRUE(eglMakeCurrent(mEglDisplay, stcEglSurface, stcEglSurface,
+            mEglContext));
+    ASSERT_EQ(EGL_SUCCESS, eglGetError());
+
+    glClearColor(0.6, 0.6, 0.6, 0.6);
+    glClear(GL_COLOR_BUFFER_BIT);
+
+    glEnable(GL_SCISSOR_TEST);
+    glScissor(4, 4, 4, 4);
+    glClearColor(1.0, 0.0, 0.0, 1.0);
+    glClear(GL_COLOR_BUFFER_BIT);
+
+    glScissor(24, 48, 4, 4);
+    glClearColor(0.0, 1.0, 0.0, 1.0);
+    glClear(GL_COLOR_BUFFER_BIT);
+
+    glScissor(37, 17, 4, 4);
+    glClearColor(0.0, 0.0, 1.0, 1.0);
+    glClear(GL_COLOR_BUFFER_BIT);
+
+    eglSwapBuffers(mEglDisplay, stcEglSurface);
+
+    // Do the consumer side of things
+    EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface,
+            mEglContext));
+    ASSERT_EQ(EGL_SUCCESS, eglGetError());
+
+    glDisable(GL_SCISSOR_TEST);
+
+    mST->updateTexImage();
+
+    glClearColor(0.2, 0.2, 0.2, 0.2);
+    glClear(GL_COLOR_BUFFER_BIT);
+
+    drawTexture();
+
+    EXPECT_TRUE(checkPixel( 0,  0, 153, 153, 153, 153));
+    EXPECT_TRUE(checkPixel(63,  0, 153, 153, 153, 153));
+    EXPECT_TRUE(checkPixel(63, 63, 153, 153, 153, 153));
+    EXPECT_TRUE(checkPixel( 0, 63, 153, 153, 153, 153));
+
+    EXPECT_TRUE(checkPixel( 4,  7, 255,   0,   0, 255));
+    EXPECT_TRUE(checkPixel(25, 51,   0, 255,   0, 255));
+    EXPECT_TRUE(checkPixel(40, 19,   0,   0, 255, 255));
+    EXPECT_TRUE(checkPixel(29, 51, 153, 153, 153, 153));
+    EXPECT_TRUE(checkPixel( 5, 32, 153, 153, 153, 153));
+    EXPECT_TRUE(checkPixel(13,  8, 153, 153, 153, 153));
+    EXPECT_TRUE(checkPixel(46,  3, 153, 153, 153, 153));
+    EXPECT_TRUE(checkPixel(30, 33, 153, 153, 153, 153));
+    EXPECT_TRUE(checkPixel( 6, 52, 153, 153, 153, 153));
+    EXPECT_TRUE(checkPixel(55, 33, 153, 153, 153, 153));
+    EXPECT_TRUE(checkPixel(16, 29, 153, 153, 153, 153));
+    EXPECT_TRUE(checkPixel( 1, 30, 153, 153, 153, 153));
+    EXPECT_TRUE(checkPixel(41, 37, 153, 153, 153, 153));
+    EXPECT_TRUE(checkPixel(46, 29, 153, 153, 153, 153));
+    EXPECT_TRUE(checkPixel(15, 25, 153, 153, 153, 153));
+    EXPECT_TRUE(checkPixel( 3, 52, 153, 153, 153, 153));
+}
+
+/*
+ * This test is for testing GL -> GL texture streaming via SurfaceTexture.  It
+ * contains functionality to create a producer thread that will perform GL
+ * rendering to an ANativeWindow that feeds frames to a SurfaceTexture.
+ * Additionally it supports interlocking the producer and consumer threads so
+ * that a specific sequence of calls can be deterministically created by the
+ * test.
+ *
+ * The intended usage is as follows:
+ *
+ * TEST_F(...) {
+ *     class PT : public ProducerThread {
+ *         virtual void render() {
+ *             ...
+ *             swapBuffers();
+ *         }
+ *     };
+ *
+ *     runProducerThread(new PT());
+ *
+ *     // The order of these calls will vary from test to test and may include
+ *     // multiple frames and additional operations (e.g. GL rendering from the
+ *     // texture).
+ *     fc->waitForFrame();
+ *     mST->updateTexImage();
+ *     fc->finishFrame();
+ * }
+ *
+ */
+class SurfaceTextureGLToGLTest : public SurfaceTextureGLTest {
+protected:
+
+    // ProducerThread is an abstract base class to simplify the creation of
+    // OpenGL ES frame producer threads.
+    class ProducerThread : public Thread {
+    public:
+        virtual ~ProducerThread() {
+        }
+
+        void setEglObjects(EGLDisplay producerEglDisplay,
+                EGLSurface producerEglSurface,
+                EGLContext producerEglContext) {
+            mProducerEglDisplay = producerEglDisplay;
+            mProducerEglSurface = producerEglSurface;
+            mProducerEglContext = producerEglContext;
+        }
+
+        virtual bool threadLoop() {
+            eglMakeCurrent(mProducerEglDisplay, mProducerEglSurface,
+                    mProducerEglSurface, mProducerEglContext);
+            render();
+            eglMakeCurrent(mProducerEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE,
+                    EGL_NO_CONTEXT);
+            return false;
+        }
+
+    protected:
+        virtual void render() = 0;
+
+        void swapBuffers() {
+            eglSwapBuffers(mProducerEglDisplay, mProducerEglSurface);
+        }
+
+        EGLDisplay mProducerEglDisplay;
+        EGLSurface mProducerEglSurface;
+        EGLContext mProducerEglContext;
+    };
+
+    // FrameCondition is a utility class for interlocking between the producer
+    // and consumer threads.  The FrameCondition object should be created and
+    // destroyed in the consumer thread only.  The consumer thread should set
+    // the FrameCondition as the FrameAvailableListener of the SurfaceTexture,
+    // and should call both waitForFrame and finishFrame once for each expected
+    // frame.
+    //
+    // This interlocking relies on the fact that onFrameAvailable gets called
+    // synchronously from SurfaceTexture::queueBuffer.
+    class FrameCondition : public SurfaceTexture::FrameAvailableListener {
+    public:
+        // waitForFrame waits for the next frame to arrive.  This should be
+        // called from the consumer thread once for every frame expected by the
+        // test.
+        void waitForFrame() {
+            LOGV("+waitForFrame");
+            Mutex::Autolock lock(mMutex);
+            status_t result = mFrameAvailableCondition.wait(mMutex);
+            LOGV("-waitForFrame");
+        }
+
+        // Allow the producer to return from its swapBuffers call and continue
+        // on to produce the next frame.  This should be called by the consumer
+        // thread once for every frame expected by the test.
+        void finishFrame() {
+            LOGV("+finishFrame");
+            Mutex::Autolock lock(mMutex);
+            mFrameFinishCondition.signal();
+            LOGV("-finishFrame");
+        }
+
+        // This should be called by SurfaceTexture on the producer thread.
+        virtual void onFrameAvailable() {
+            LOGV("+onFrameAvailable");
+            Mutex::Autolock lock(mMutex);
+            mFrameAvailableCondition.signal();
+            mFrameFinishCondition.wait(mMutex);
+            LOGV("-onFrameAvailable");
+        }
+
+    protected:
+        Mutex mMutex;
+        Condition mFrameAvailableCondition;
+        Condition mFrameFinishCondition;
+    };
+
+    SurfaceTextureGLToGLTest():
+            mProducerEglSurface(EGL_NO_SURFACE),
+            mProducerEglContext(EGL_NO_CONTEXT) {
+    }
+
+    virtual void SetUp() {
+        SurfaceTextureGLTest::SetUp();
+
+        EGLConfig myConfig = {0};
+        EGLint numConfigs = 0;
+        EXPECT_TRUE(eglChooseConfig(mEglDisplay, getConfigAttribs(), &myConfig,
+                1, &numConfigs));
+        ASSERT_EQ(EGL_SUCCESS, eglGetError());
+
+        mProducerEglSurface = eglCreateWindowSurface(mEglDisplay, myConfig,
+                mANW.get(), NULL);
+        ASSERT_EQ(EGL_SUCCESS, eglGetError());
+        ASSERT_NE(EGL_NO_SURFACE, mProducerEglSurface);
+
+        mProducerEglContext = eglCreateContext(mEglDisplay, myConfig,
+                EGL_NO_CONTEXT, getContextAttribs());
+        ASSERT_EQ(EGL_SUCCESS, eglGetError());
+        ASSERT_NE(EGL_NO_CONTEXT, mProducerEglContext);
+
+        mFC = new FrameCondition();
+        mST->setFrameAvailableListener(mFC);
+    }
+
+    virtual void TearDown() {
+        if (mProducerThread != NULL) {
+            mProducerThread->requestExitAndWait();
+        }
+        if (mProducerEglContext != EGL_NO_CONTEXT) {
+            eglDestroyContext(mEglDisplay, mProducerEglContext);
+        }
+        if (mProducerEglSurface != EGL_NO_SURFACE) {
+            eglDestroySurface(mEglDisplay, mProducerEglSurface);
+        }
+        mProducerThread.clear();
+        mFC.clear();
+    }
+
+    void runProducerThread(const sp<ProducerThread> producerThread) {
+        ASSERT_TRUE(mProducerThread == NULL);
+        mProducerThread = producerThread;
+        producerThread->setEglObjects(mEglDisplay, mProducerEglSurface,
+                mProducerEglContext);
+        producerThread->run();
+    }
+
+    EGLSurface mProducerEglSurface;
+    EGLContext mProducerEglContext;
+    sp<ProducerThread> mProducerThread;
+    sp<FrameCondition> mFC;
+};
+
+// XXX: This test is disabled because it causes hangs on some devices.
+TEST_F(SurfaceTextureGLToGLTest, DISABLED_UpdateTexImageBeforeFrameFinishedWorks) {
+    class PT : public ProducerThread {
+        virtual void render() {
+            glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
+            glClear(GL_COLOR_BUFFER_BIT);
+            swapBuffers();
+        }
+    };
+
+    runProducerThread(new PT());
+
+    mFC->waitForFrame();
+    mST->updateTexImage();
+    mFC->finishFrame();
+
+    // TODO: Add frame verification once RGB TEX_EXTERNAL_OES is supported!
+}
+
+// XXX: This test is disabled because it causes hangs on some devices.
+TEST_F(SurfaceTextureGLToGLTest, DISABLED_UpdateTexImageAfterFrameFinishedWorks) {
+    class PT : public ProducerThread {
+        virtual void render() {
+            glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
+            glClear(GL_COLOR_BUFFER_BIT);
+            swapBuffers();
+        }
+    };
+
+    runProducerThread(new PT());
+
+    mFC->waitForFrame();
+    mFC->finishFrame();
+    mST->updateTexImage();
+
+    // TODO: Add frame verification once RGB TEX_EXTERNAL_OES is supported!
+}
+
+// XXX: This test is disabled because it causes hangs on some devices.
+TEST_F(SurfaceTextureGLToGLTest, DISABLED_RepeatedUpdateTexImageBeforeFrameFinishedWorks) {
+    enum { NUM_ITERATIONS = 1024 };
+
+    class PT : public ProducerThread {
+        virtual void render() {
+            for (int i = 0; i < NUM_ITERATIONS; i++) {
+                glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
+                glClear(GL_COLOR_BUFFER_BIT);
+                LOGV("+swapBuffers");
+                swapBuffers();
+                LOGV("-swapBuffers");
+            }
+        }
+    };
+
+    runProducerThread(new PT());
+
+    for (int i = 0; i < NUM_ITERATIONS; i++) {
+        mFC->waitForFrame();
+        LOGV("+updateTexImage");
+        mST->updateTexImage();
+        LOGV("-updateTexImage");
+        mFC->finishFrame();
+
+        // TODO: Add frame verification once RGB TEX_EXTERNAL_OES is supported!
+    }
+}
+
+// XXX: This test is disabled because it causes hangs on some devices.
+TEST_F(SurfaceTextureGLToGLTest, DISABLED_RepeatedUpdateTexImageAfterFrameFinishedWorks) {
+    enum { NUM_ITERATIONS = 1024 };
+
+    class PT : public ProducerThread {
+        virtual void render() {
+            for (int i = 0; i < NUM_ITERATIONS; i++) {
+                glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
+                glClear(GL_COLOR_BUFFER_BIT);
+                LOGV("+swapBuffers");
+                swapBuffers();
+                LOGV("-swapBuffers");
+            }
+        }
+    };
+
+    runProducerThread(new PT());
+
+    for (int i = 0; i < NUM_ITERATIONS; i++) {
+        mFC->waitForFrame();
+        mFC->finishFrame();
+        LOGV("+updateTexImage");
+        mST->updateTexImage();
+        LOGV("-updateTexImage");
+
+        // TODO: Add frame verification once RGB TEX_EXTERNAL_OES is supported!
+    }
+}
+
+} // namespace android
diff --git a/libs/hwui/Caches.h b/libs/hwui/Caches.h
index 596781e..e64d8ac 100644
--- a/libs/hwui/Caches.h
+++ b/libs/hwui/Caches.h
@@ -74,7 +74,7 @@
 
 struct CacheLogger {
     CacheLogger() {
-        LOGD("Creating OpenGL renderer caches");
+        INIT_LOGD("Creating OpenGL renderer caches");
     }
 }; // struct CacheLogger
 
diff --git a/libs/hwui/DisplayListRenderer.cpp b/libs/hwui/DisplayListRenderer.cpp
index f8582d8..afab26a 100644
--- a/libs/hwui/DisplayListRenderer.cpp
+++ b/libs/hwui/DisplayListRenderer.cpp
@@ -1151,6 +1151,7 @@
 
 void DisplayListRenderer::drawText(const char* text, int bytesCount, int count,
         float x, float y, SkPaint* paint) {
+    if (count <= 0) return;
     addOp(DisplayList::DrawText);
     addText(text, bytesCount);
     addInt(count);
diff --git a/libs/hwui/FontRenderer.cpp b/libs/hwui/FontRenderer.cpp
index 1ca0a19..9bf3de8 100644
--- a/libs/hwui/FontRenderer.cpp
+++ b/libs/hwui/FontRenderer.cpp
@@ -35,6 +35,7 @@
 #define DEFAULT_TEXT_CACHE_WIDTH 1024
 #define DEFAULT_TEXT_CACHE_HEIGHT 256
 
+// We should query these values from the GL context
 #define MAX_TEXT_CACHE_WIDTH 2048
 #define MAX_TEXT_CACHE_HEIGHT 2048
 
@@ -58,8 +59,7 @@
     }
 
     for (uint32_t i = 0; i < mCachedGlyphs.size(); i++) {
-        CachedGlyphInfo* glyph = mCachedGlyphs.valueAt(i);
-        delete glyph;
+        delete mCachedGlyphs.valueAt(i);
     }
 }
 
@@ -134,48 +134,49 @@
 
 }
 
-Font::CachedGlyphInfo* Font::getCachedUTFChar(SkPaint* paint, int32_t utfChar) {
+Font::CachedGlyphInfo* Font::getCachedGlyph(SkPaint* paint, glyph_t textUnit) {
     CachedGlyphInfo* cachedGlyph = NULL;
-    ssize_t index = mCachedGlyphs.indexOfKey(utfChar);
+    ssize_t index = mCachedGlyphs.indexOfKey(textUnit);
     if (index >= 0) {
         cachedGlyph = mCachedGlyphs.valueAt(index);
     } else {
-        cachedGlyph = cacheGlyph(paint, utfChar);
+        cachedGlyph = cacheGlyph(paint, textUnit);
     }
 
     // Is the glyph still in texture cache?
     if (!cachedGlyph->mIsValid) {
-        const SkGlyph& skiaGlyph = paint->getUnicharMetrics(utfChar);
+        const SkGlyph& skiaGlyph = GET_METRICS(paint, textUnit);
         updateGlyphCache(paint, skiaGlyph, cachedGlyph);
     }
 
     return cachedGlyph;
 }
 
-void Font::renderUTF(SkPaint* paint, const char* text, uint32_t start, uint32_t len,
+void Font::render(SkPaint* paint, const char* text, uint32_t start, uint32_t len,
         int numGlyphs, int x, int y, uint8_t *bitmap, uint32_t bitmapW, uint32_t bitmapH) {
     if (bitmap != NULL && bitmapW > 0 && bitmapH > 0) {
-        renderUTF(paint, text, start, len, numGlyphs, x, y, BITMAP, bitmap,
+        render(paint, text, start, len, numGlyphs, x, y, BITMAP, bitmap,
                 bitmapW, bitmapH, NULL);
     } else {
-        renderUTF(paint, text, start, len, numGlyphs, x, y, FRAMEBUFFER, NULL, 0, 0, NULL);
+        render(paint, text, start, len, numGlyphs, x, y, FRAMEBUFFER, NULL,
+                0, 0, NULL);
     }
 
 }
 
-void Font::measureUTF(SkPaint* paint, const char* text, uint32_t start, uint32_t len,
+void Font::measure(SkPaint* paint, const char* text, uint32_t start, uint32_t len,
         int numGlyphs, Rect *bounds) {
     if (bounds == NULL) {
         LOGE("No return rectangle provided to measure text");
         return;
     }
     bounds->set(1e6, -1e6, -1e6, 1e6);
-    renderUTF(paint, text, start, len, numGlyphs, 0, 0, MEASURE, NULL, 0, 0, bounds);
+    render(paint, text, start, len, numGlyphs, 0, 0, MEASURE, NULL, 0, 0, bounds);
 }
 
 #define SkAutoKern_AdjustF(prev, next) (((next) - (prev) + 32) >> 6 << 16)
 
-void Font::renderUTF(SkPaint* paint, const char* text, uint32_t start, uint32_t len,
+void Font::render(SkPaint* paint, const char* text, uint32_t start, uint32_t len,
         int numGlyphs, int x, int y, RenderMode mode, uint8_t *bitmap,
         uint32_t bitmapW, uint32_t bitmapH,Rect *bounds) {
     if (numGlyphs == 0 || text == NULL || len == 0) {
@@ -195,14 +196,14 @@
     text += start;
 
     while (glyphsLeft > 0) {
-        int32_t utfChar = SkUTF16_NextUnichar((const uint16_t**) &text);
+        glyph_t glyph = GET_GLYPH(text);
 
         // Reached the end of the string
-        if (utfChar < 0) {
+        if (IS_END_OF_STRING(glyph)) {
             break;
         }
 
-        CachedGlyphInfo* cachedGlyph = getCachedUTFChar(paint, utfChar);
+        CachedGlyphInfo* cachedGlyph = getCachedGlyph(paint, glyph);
         penX += SkAutoKern_AdjustF(prevRsbDelta, cachedGlyph->mLsbDelta);
         prevRsbDelta = cachedGlyph->mRsbDelta;
 
@@ -268,11 +269,11 @@
     mState->mUploadTexture = true;
 }
 
-Font::CachedGlyphInfo* Font::cacheGlyph(SkPaint* paint, int32_t glyph) {
+Font::CachedGlyphInfo* Font::cacheGlyph(SkPaint* paint, glyph_t glyph) {
     CachedGlyphInfo* newGlyph = new CachedGlyphInfo();
     mCachedGlyphs.add(glyph, newGlyph);
 
-    const SkGlyph& skiaGlyph = paint->getUnicharMetrics(glyph);
+    const SkGlyph& skiaGlyph = GET_METRICS(paint, glyph);
     newGlyph->mGlyphIndex = skiaGlyph.fID;
     newGlyph->mIsValid = false;
 
@@ -672,7 +673,7 @@
     uint32_t remainingCapacity = getRemainingCacheCapacity();
     uint32_t precacheIdx = 0;
     while (remainingCapacity > 25 && precacheIdx < mLatinPrecache.size()) {
-        mCurrentFont->getCachedUTFChar(paint, (int32_t) mLatinPrecache[precacheIdx]);
+        mCurrentFont->getCachedGlyph(paint, (int32_t) mLatinPrecache[precacheIdx]);
         remainingCapacity = getRemainingCacheCapacity();
         precacheIdx ++;
     }
@@ -714,7 +715,7 @@
     }
 
     Rect bounds;
-    mCurrentFont->measureUTF(paint, text, startIndex, len, numGlyphs, &bounds);
+    mCurrentFont->measure(paint, text, startIndex, len, numGlyphs, &bounds);
     uint32_t paddedWidth = (uint32_t) (bounds.right - bounds.left) + 2 * radius;
     uint32_t paddedHeight = (uint32_t) (bounds.top - bounds.bottom) + 2 * radius;
     uint8_t* dataBuffer = new uint8_t[paddedWidth * paddedHeight];
@@ -725,7 +726,7 @@
     int penX = radius - bounds.left;
     int penY = radius - bounds.bottom;
 
-    mCurrentFont->renderUTF(paint, text, startIndex, len, numGlyphs, penX, penY,
+    mCurrentFont->render(paint, text, startIndex, len, numGlyphs, penX, penY,
             dataBuffer, paddedWidth, paddedHeight);
     blurImage(dataBuffer, paddedWidth, paddedHeight, radius);
 
@@ -755,7 +756,7 @@
     mDrawn = false;
     mBounds = bounds;
     mClip = clip;
-    mCurrentFont->renderUTF(paint, text, startIndex, len, numGlyphs, x, y);
+    mCurrentFont->render(paint, text, startIndex, len, numGlyphs, x, y);
     mBounds = NULL;
 
     if (mCurrentQuadIndex != 0) {
diff --git a/libs/hwui/FontRenderer.h b/libs/hwui/FontRenderer.h
index 95f714f..24ed6fa 100644
--- a/libs/hwui/FontRenderer.h
+++ b/libs/hwui/FontRenderer.h
@@ -33,8 +33,32 @@
 namespace android {
 namespace uirenderer {
 
+///////////////////////////////////////////////////////////////////////////////
+// Defines
+///////////////////////////////////////////////////////////////////////////////
+
+#if RENDER_TEXT_AS_GLYPHS
+    typedef uint16_t glyph_t;
+    #define GET_METRICS(paint, glyph) paint->getGlyphMetrics(glyph)
+    #define GET_GLYPH(text) nextGlyph((const uint16_t**) &text)
+    #define IS_END_OF_STRING(glyph) false
+#else
+    typedef SkUnichar glyph_t;
+    #define GET_METRICS(paint, glyph) paint->getUnicharMetrics(glyph)
+    #define GET_GLYPH(text) SkUTF16_NextUnichar((const uint16_t**) &text)
+    #define IS_END_OF_STRING(glyph) glyph < 0
+#endif
+
+///////////////////////////////////////////////////////////////////////////////
+// Declarations
+///////////////////////////////////////////////////////////////////////////////
+
 class FontRenderer;
 
+///////////////////////////////////////////////////////////////////////////////
+// Font
+///////////////////////////////////////////////////////////////////////////////
+
 /**
  * Represents a font, defined by a Skia font id and a font size. A font is used
  * to generate glyphs and cache them in the FontState.
@@ -51,9 +75,9 @@
      * Renders the specified string of text.
      * If bitmap is specified, it will be used as the render target
      */
-    void renderUTF(SkPaint* paint, const char *text, uint32_t start, uint32_t len,
-                     int numGlyphs, int x, int y,
-                     uint8_t *bitmap = NULL, uint32_t bitmapW = 0, uint32_t bitmapH = 0);
+    void render(SkPaint* paint, const char *text, uint32_t start, uint32_t len,
+            int numGlyphs, int x, int y, uint8_t *bitmap = NULL,
+            uint32_t bitmapW = 0, uint32_t bitmapH = 0);
     /**
      * Creates a new font associated with the specified font state.
      */
@@ -69,13 +93,12 @@
         MEASURE,
     };
 
-    void renderUTF(SkPaint* paint, const char *text, uint32_t start, uint32_t len,
-                     int numGlyphs, int x, int y, RenderMode mode,
-                     uint8_t *bitmap, uint32_t bitmapW, uint32_t bitmapH,
-                     Rect *bounds);
+    void render(SkPaint* paint, const char *text, uint32_t start, uint32_t len,
+            int numGlyphs, int x, int y, RenderMode mode, uint8_t *bitmap,
+            uint32_t bitmapW, uint32_t bitmapH, Rect *bounds);
 
-    void measureUTF(SkPaint* paint, const char* text, uint32_t start, uint32_t len,
-                      int numGlyphs, Rect *bounds);
+    void measure(SkPaint* paint, const char* text, uint32_t start, uint32_t len,
+            int numGlyphs, Rect *bounds);
 
     struct CachedGlyphInfo {
         // Has the cache been invalidated?
@@ -107,18 +130,26 @@
     Font(FontRenderer* state, uint32_t fontId, float fontSize, int flags, uint32_t italicStyle,
             uint32_t scaleX);
 
-    DefaultKeyedVector<int32_t, CachedGlyphInfo*> mCachedGlyphs;
+    // Cache of glyphs
+    DefaultKeyedVector<glyph_t, CachedGlyphInfo*> mCachedGlyphs;
 
     void invalidateTextureCache();
 
-    CachedGlyphInfo* cacheGlyph(SkPaint* paint, int32_t glyph);
+    CachedGlyphInfo* cacheGlyph(SkPaint* paint, glyph_t glyph);
     void updateGlyphCache(SkPaint* paint, const SkGlyph& skiaGlyph, CachedGlyphInfo *glyph);
     void measureCachedGlyph(CachedGlyphInfo *glyph, int x, int y, Rect *bounds);
     void drawCachedGlyph(CachedGlyphInfo *glyph, int x, int y);
     void drawCachedGlyph(CachedGlyphInfo *glyph, int x, int y,
-                          uint8_t *bitmap, uint32_t bitmapW, uint32_t bitmapH);
+            uint8_t *bitmap, uint32_t bitmapW, uint32_t bitmapH);
 
-    CachedGlyphInfo* getCachedUTFChar(SkPaint* paint, int32_t utfChar);
+    CachedGlyphInfo* getCachedGlyph(SkPaint* paint, glyph_t textUnit);
+
+    static glyph_t nextGlyph(const uint16_t** srcPtr) {
+        const uint16_t* src = *srcPtr;
+        glyph_t g = *src++;
+        *srcPtr = src;
+        return g;
+    }
 
     FontRenderer* mState;
     uint32_t mFontId;
@@ -128,6 +159,10 @@
     uint32_t mScaleX;
 };
 
+///////////////////////////////////////////////////////////////////////////////
+// Renderer
+///////////////////////////////////////////////////////////////////////////////
+
 class FontRenderer {
 public:
     FontRenderer();
diff --git a/libs/hwui/LayerRenderer.cpp b/libs/hwui/LayerRenderer.cpp
index f316ba7..77e63d7 100644
--- a/libs/hwui/LayerRenderer.cpp
+++ b/libs/hwui/LayerRenderer.cpp
@@ -315,5 +315,117 @@
     }
 }
 
+bool LayerRenderer::copyLayer(Layer* layer, SkBitmap* bitmap) {
+    Caches& caches = Caches::getInstance();
+    if (layer && layer->isTextureLayer && bitmap->width() <= caches.maxTextureSize &&
+            bitmap->height() <= caches.maxTextureSize) {
+
+        GLuint fbo = caches.fboCache.get();
+        if (!fbo) {
+            LOGW("Could not obtain an FBO");
+            return false;
+        }
+
+        SkAutoLockPixels alp(*bitmap);
+
+        GLuint texture;
+        GLuint previousFbo;
+
+        GLenum format;
+        GLenum type;
+
+        GLenum error = GL_NO_ERROR;
+        bool status = false;
+
+        switch (bitmap->config()) {
+            case SkBitmap::kA8_Config:
+                format = GL_ALPHA;
+                type = GL_UNSIGNED_BYTE;
+                break;
+            case SkBitmap::kRGB_565_Config:
+                format = GL_RGB;
+                type = GL_UNSIGNED_SHORT_5_6_5;
+                break;
+            case SkBitmap::kARGB_4444_Config:
+                format = GL_RGBA;
+                type = GL_UNSIGNED_SHORT_4_4_4_4;
+                break;
+            case SkBitmap::kARGB_8888_Config:
+            default:
+                format = GL_RGBA;
+                type = GL_UNSIGNED_BYTE;
+                break;
+        }
+
+        float alpha = layer->alpha;
+        SkXfermode::Mode mode = layer->mode;
+
+        layer->mode = SkXfermode::kSrc_Mode;
+        layer->alpha = 255;
+        layer->fbo = fbo;
+
+        glGetIntegerv(GL_FRAMEBUFFER_BINDING, (GLint*) &previousFbo);
+        glBindFramebuffer(GL_FRAMEBUFFER, fbo);
+
+        glGenTextures(1, &texture);
+        if ((error = glGetError()) != GL_NO_ERROR) goto error;
+
+        glActiveTexture(GL_TEXTURE0);
+        glBindTexture(GL_TEXTURE_2D, texture);
+
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+
+        glTexImage2D(GL_TEXTURE_2D, 0, format, bitmap->width(), bitmap->height(),
+                0, format, type, NULL);
+        if ((error = glGetError()) != GL_NO_ERROR) goto error;
+
+        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
+                GL_TEXTURE_2D, texture, 0);
+        if ((error = glGetError()) != GL_NO_ERROR) goto error;
+
+        {
+            LayerRenderer renderer(layer);
+            renderer.setViewport(bitmap->width(), bitmap->height());
+            renderer.OpenGLRenderer::prepareDirty(0.0f, 0.0f,
+                    bitmap->width(), bitmap->height(), !layer->blend);
+            if ((error = glGetError()) != GL_NO_ERROR) goto error;
+
+            {
+                Rect bounds;
+                bounds.set(0.0f, 0.0f, bitmap->width(), bitmap->height());
+                renderer.drawTextureLayer(layer, bounds);
+
+                glReadPixels(0, 0, bitmap->width(), bitmap->height(), format,
+                        type, bitmap->getPixels());
+
+                if ((error = glGetError()) != GL_NO_ERROR) goto error;
+            }
+
+            status = true;
+        }
+
+error:
+#if DEBUG_OPENGL
+        if (error != GL_NO_ERROR) {
+            LOGD("GL error while copying layer into bitmap = 0x%x", error);
+        }
+#endif
+
+        glBindFramebuffer(GL_FRAMEBUFFER, previousFbo);
+        layer->mode = mode;
+        layer->alpha = alpha;
+        layer->fbo = 0;
+        glDeleteTextures(1, &texture);
+        caches.fboCache.put(fbo);
+
+        return status;
+    }
+    return false;
+}
+
 }; // namespace uirenderer
 }; // namespace android
diff --git a/libs/hwui/LayerRenderer.h b/libs/hwui/LayerRenderer.h
index 59cab96..797dfc6 100644
--- a/libs/hwui/LayerRenderer.h
+++ b/libs/hwui/LayerRenderer.h
@@ -20,6 +20,8 @@
 #include "OpenGLRenderer.h"
 #include "Layer.h"
 
+#include <SkBitmap.h>
+
 namespace android {
 namespace uirenderer {
 
@@ -60,6 +62,7 @@
             GLenum renderTarget, float* transform);
     static void destroyLayer(Layer* layer);
     static void destroyLayerDeferred(Layer* layer);
+    static bool copyLayer(Layer* layer, SkBitmap* bitmap);
 
 private:
     void generateMesh();
diff --git a/libs/hwui/Matrix.cpp b/libs/hwui/Matrix.cpp
index e7c0fe3..9fc5131 100644
--- a/libs/hwui/Matrix.cpp
+++ b/libs/hwui/Matrix.cpp
@@ -67,6 +67,10 @@
             ALMOST_EQUAL(data[kScaleX], 1.0f) && ALMOST_EQUAL(data[kScaleY], 1.0f);
 }
 
+bool Matrix4::isSimple() {
+    return mSimpleMatrix;
+}
+
 void Matrix4::load(const float* v) {
     memcpy(data, v, sizeof(data));
     mSimpleMatrix = false;
diff --git a/libs/hwui/Matrix.h b/libs/hwui/Matrix.h
index 08f5d77..2fa6ab7 100644
--- a/libs/hwui/Matrix.h
+++ b/libs/hwui/Matrix.h
@@ -111,6 +111,7 @@
     }
 
     bool isPureTranslate();
+    bool isSimple();
 
     bool changesBounds();
 
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp
index 6243b01..88774c6 100644
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -151,7 +151,6 @@
     mSaveCount = 1;
 
     glViewport(0, 0, mWidth, mHeight);
-
     glDisable(GL_DITHER);
 
     glEnable(GL_SCISSOR_TEST);
@@ -476,13 +475,8 @@
                         snapshot->height - bounds.bottom, bounds.getWidth(), bounds.getHeight());
             }
 
-            // Clear the framebuffer where the layer will draw
-            glScissor(bounds.left, mSnapshot->height - bounds.bottom,
-                    bounds.getWidth(), bounds.getHeight());
-            glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
-            glClear(GL_COLOR_BUFFER_BIT);
-
-            dirtyClip();
+            // Enqueue the buffer coordinates to clear the corresponding region later
+            mLayers.push(new Rect(bounds));
         }
     }
 
@@ -817,6 +811,58 @@
 #endif
 }
 
+void OpenGLRenderer::clearLayerRegions() {
+    const size_t count = mLayers.size();
+    if (count == 0) return;
+
+    if (!mSnapshot->isIgnored()) {
+        // Doing several glScissor/glClear here can negatively impact
+        // GPUs with a tiler architecture, instead we draw quads with
+        // the Clear blending mode
+
+        // The list contains bounds that have already been clipped
+        // against their initial clip rect, and the current clip
+        // is likely different so we need to disable clipping here
+        glDisable(GL_SCISSOR_TEST);
+
+        Vertex mesh[count * 6];
+        Vertex* vertex = mesh;
+
+        for (uint32_t i = 0; i < count; i++) {
+            Rect* bounds = mLayers.itemAt(i);
+
+            Vertex::set(vertex++, bounds->left, bounds->bottom);
+            Vertex::set(vertex++, bounds->left, bounds->top);
+            Vertex::set(vertex++, bounds->right, bounds->top);
+            Vertex::set(vertex++, bounds->left, bounds->bottom);
+            Vertex::set(vertex++, bounds->right, bounds->top);
+            Vertex::set(vertex++, bounds->right, bounds->bottom);
+
+            delete bounds;
+        }
+
+        setupDraw(false);
+        setupDrawColor(0.0f, 0.0f, 0.0f, 1.0f);
+        setupDrawBlending(true, SkXfermode::kClear_Mode);
+        setupDrawProgram();
+        setupDrawPureColorUniforms();
+        setupDrawModelViewTranslate(0.0f, 0.0f, 0.0f, 0.0f, true);
+
+        mCaches.unbindMeshBuffer();
+        glVertexAttribPointer(mCaches.currentProgram->position, 2, GL_FLOAT, GL_FALSE,
+                gVertexStride, &mesh[0].position[0]);
+        glDrawArrays(GL_TRIANGLES, 0, count * 6);
+
+        glEnable(GL_SCISSOR_TEST);
+    } else {
+        for (uint32_t i = 0; i < count; i++) {
+            delete mLayers.itemAt(i);
+        }
+    }
+
+    mLayers.clear();
+}
+
 ///////////////////////////////////////////////////////////////////////////////
 // Transforms
 ///////////////////////////////////////////////////////////////////////////////
@@ -901,7 +947,8 @@
 // Drawing commands
 ///////////////////////////////////////////////////////////////////////////////
 
-void OpenGLRenderer::setupDraw() {
+void OpenGLRenderer::setupDraw(bool clear) {
+    if (clear) clearLayerRegions();
     if (mDirtyClip) {
         setScissorFromClip();
     }
@@ -994,7 +1041,7 @@
     if (mColorSet && mode == SkXfermode::kClear_Mode) {
         mColorA = 1.0f;
         mColorR = mColorG = mColorB = 0.0f;
-        mSetShaderColor = mDescription.setAlpha8Color(mColorR, mColorG, mColorB, mColorA);
+        mSetShaderColor = mDescription.modulate = true;
     }
 }
 
@@ -1478,8 +1525,7 @@
  * within that boundary region and how far into the region it is.
  */
 void OpenGLRenderer::drawAARect(float left, float top, float right, float bottom,
-        int color, SkXfermode::Mode mode)
-{
+        int color, SkXfermode::Mode mode) {
     float inverseScaleX = 1.0f;
     float inverseScaleY = 1.0f;
     // The quad that we use needs to account for scaling.
@@ -1935,7 +1981,7 @@
     }
 
     int color = p->getColor();
-    if (p->isAntiAlias()) {
+    if (p->isAntiAlias() && !mSnapshot->transform->isSimple()) {
         drawAARect(left, top, right, bottom, color, mode);
     } else {
         drawColorRect(left, top, right, bottom, color, mode);
@@ -1949,7 +1995,16 @@
     }
     if (mSnapshot->isIgnored()) return;
 
+    // TODO: We should probably make a copy of the paint instead of modifying
+    //       it; modifying the paint will change its generationID the first
+    //       time, which might impact caches. More investigation needed to
+    //       see if it matters.
+    //       If we make a copy, then drawTextDecorations() should *not* make
+    //       its own copy as it does right now.
     paint->setAntiAlias(true);
+#if RENDER_TEXT_AS_GLYPHS
+    paint->setTextEncoding(SkPaint::kGlyphID_TextEncoding);
+#endif
 
     float length = -1.0f;
     switch (paint->getTextAlign()) {
@@ -1983,8 +2038,8 @@
 
     if (mHasShadow) {
         mCaches.dropShadowCache.setFontRenderer(fontRenderer);
-        const ShadowTexture* shadow = mCaches.dropShadowCache.get(paint, text, bytesCount,
-                count, mShadowRadius);
+        const ShadowTexture* shadow = mCaches.dropShadowCache.get(
+                paint, text, bytesCount, count, mShadowRadius);
         const AutoTexture autoCleanup(shadow);
 
         const float sx = oldX - shadow->left + mShadowDx;
@@ -2073,11 +2128,6 @@
     drawTextDecorations(text, bytesCount, length, oldX, oldY, paint);
 }
 
-void OpenGLRenderer::drawGlyphs(const char* glyphs, int index, int count, float x, float y,
-        SkPaint* paint) {
-    // TODO
-}
-
 void OpenGLRenderer::drawPath(SkPath* path, SkPaint* paint) {
     if (mSnapshot->isIgnored()) return;
 
@@ -2230,14 +2280,15 @@
     // Handle underline and strike-through
     uint32_t flags = paint->getFlags();
     if (flags & (SkPaint::kUnderlineText_Flag | SkPaint::kStrikeThruText_Flag)) {
+        SkPaint paintCopy(*paint);
         float underlineWidth = length;
         // If length is > 0.0f, we already measured the text for the text alignment
         if (length <= 0.0f) {
-            underlineWidth = paint->measureText(text, bytesCount);
+            underlineWidth = paintCopy.measureText(text, bytesCount);
         }
 
         float offsetX = 0;
-        switch (paint->getTextAlign()) {
+        switch (paintCopy.getTextAlign()) {
             case SkPaint::kCenter_Align:
                 offsetX = underlineWidth * 0.5f;
                 break;
@@ -2249,8 +2300,7 @@
         }
 
         if (underlineWidth > 0.0f) {
-            const float textSize = paint->getTextSize();
-            // TODO: Support stroke width < 1.0f when we have AA lines
+            const float textSize = paintCopy.getTextSize();
             const float strokeWidth = fmax(textSize * kStdUnderline_Thickness, 1.0f);
 
             const float left = x - offsetX;
@@ -2280,10 +2330,9 @@
                 points[currentPoint++] = top;
             }
 
-            SkPaint linesPaint(*paint);
-            linesPaint.setStrokeWidth(strokeWidth);
+            paintCopy.setStrokeWidth(strokeWidth);
 
-            drawLines(&points[0], pointsCount, &linesPaint);
+            drawLines(&points[0], pointsCount, &paintCopy);
         }
     }
 }
diff --git a/libs/hwui/OpenGLRenderer.h b/libs/hwui/OpenGLRenderer.h
index e2dbba0..0a3d5090 100644
--- a/libs/hwui/OpenGLRenderer.h
+++ b/libs/hwui/OpenGLRenderer.h
@@ -123,8 +123,6 @@
     virtual void drawPoints(float* points, int count, SkPaint* paint);
     virtual void drawText(const char* text, int bytesCount, int count, float x, float y,
             SkPaint* paint);
-    virtual void drawGlyphs(const char* glyphs, int index, int count, float x, float y,
-            SkPaint* paint);
 
     virtual void resetShader();
     virtual void setupShader(SkiaShader* shader);
@@ -180,6 +178,14 @@
         return 0;
     }
 
+    /**
+     * Renders the specified layer as a textured quad.
+     *
+     * @param layer The layer to render
+     * @param rect The bounds of the layer
+     */
+    void drawTextureLayer(Layer* layer, const Rect& rect);
+
 private:
     /**
      * Saves the current state of the renderer as a new snapshot.
@@ -251,7 +257,11 @@
      */
     void composeLayerRect(Layer* layer, const Rect& rect, bool swap = false);
 
-    void drawTextureLayer(Layer* layer, const Rect& rect);
+    /**
+     * Clears all the regions corresponding to the current list of layers.
+     * This method MUST be invoked before any drawing operation.
+     */
+    void clearLayerRegions();
 
     /**
      * Mark the layer as dirty at the specified coordinates. The coordinates
@@ -282,11 +292,53 @@
     void drawColorRect(float left, float top, float right, float bottom,
             int color, SkXfermode::Mode mode, bool ignoreTransform = false);
 
+    /**
+     * Draws the shape represented by the specified path texture.
+     * This method invokes drawPathTexture() but takes into account
+     * the extra left/top offset and the texture offset to correctly
+     * position the final shape.
+     *
+     * @param left The left coordinate of the shape to render
+     * @param top The top coordinate of the shape to render
+     * @param texture The texture reprsenting the shape
+     * @param paint The paint to draw the shape with
+     */
     void drawShape(float left, float top, const PathTexture* texture, SkPaint* paint);
+
+    /**
+     * Renders the rect defined by the specified bounds as a shape.
+     * This will render the rect using a path texture, which is used to render
+     * rects with stroke effects.
+     *
+     * @param left The left coordinate of the rect to draw
+     * @param top The top coordinate of the rect to draw
+     * @param right The right coordinate of the rect to draw
+     * @param bottom The bottom coordinate of the rect to draw
+     * @param p The paint to draw the rect with
+     */
     void drawRectAsShape(float left, float top, float right, float bottom, SkPaint* p);
 
+    /**
+     * Draws the specified texture as an alpha bitmap. Alpha bitmaps obey
+     * different compositing rules.
+     *
+     * @param texture The texture to draw with
+     * @param left The x coordinate of the bitmap
+     * @param top The y coordinate of the bitmap
+     * @param paint The paint to render with
+     */
     void drawAlphaBitmap(Texture* texture, float left, float top, SkPaint* paint);
 
+    /**
+     * Renders the rect defined by the specified bounds as an anti-aliased rect.
+     *
+     * @param left The left coordinate of the rect to draw
+     * @param top The top coordinate of the rect to draw
+     * @param right The right coordinate of the rect to draw
+     * @param bottom The bottom coordinate of the rect to draw
+     * @param color The color of the rect
+     * @param mode The blending mode to draw the rect
+     */
     void drawAARect(float left, float top, float right, float bottom,
             int color, SkXfermode::Mode mode);
 
@@ -361,6 +413,15 @@
     void drawTextDecorations(const char* text, int bytesCount, float length,
             float x, float y, SkPaint* paint);
 
+    /**
+     * Draws a path texture. Path textures are alpha8 bitmaps that need special
+     * compositing to apply colors/filters/etc.
+     *
+     * @param texture The texture to render
+     * @param x The x coordinate where the texture will be drawn
+     * @param y The y coordinate where the texture will be drawn
+     * @param paint The paint to draw the texture with
+     */
     void drawPathTexture(const PathTexture* texture, float x, float y, SkPaint* paint);
 
     /**
@@ -436,7 +497,7 @@
     /**
      * Invoked before any drawing operation. This sets required state.
      */
-    void setupDraw();
+    void setupDraw(bool clear = true);
     /**
      * Various methods to setup OpenGL rendering.
      */
@@ -524,6 +585,9 @@
     // Various caches
     Caches& mCaches;
 
+    // List of rectagnles to clear after saveLayer() is invoked
+    Vector<Rect*> mLayers;
+
     // Indentity matrix
     const mat4 mIdentity;
 
diff --git a/libs/hwui/Properties.h b/libs/hwui/Properties.h
index 2d8b6f3..7c10518 100644
--- a/libs/hwui/Properties.h
+++ b/libs/hwui/Properties.h
@@ -28,6 +28,9 @@
 // If turned on, layers drawn inside FBOs are optimized with regions
 #define RENDER_LAYERS_AS_REGIONS 1
 
+// If turned on, text is interpreted as glyphs instead of UTF-16
+#define RENDER_TEXT_AS_GLYPHS 1
+
 /**
  * Debug level for app developers.
  */
diff --git a/libs/hwui/ShapeCache.h b/libs/hwui/ShapeCache.h
index b5cc29c..b048469 100644
--- a/libs/hwui/ShapeCache.h
+++ b/libs/hwui/ShapeCache.h
@@ -537,15 +537,16 @@
     const float pathWidth = fmax(bounds.width(), 1.0f);
     const float pathHeight = fmax(bounds.height(), 1.0f);
 
-    if (pathWidth > mMaxTextureSize || pathHeight > mMaxTextureSize) {
+    const float offset = fmax(paint->getStrokeWidth(), 1.0f) * 1.5f;
+
+    const uint32_t width = uint32_t(pathWidth + offset * 2.0 + 0.5);
+    const uint32_t height = uint32_t(pathHeight + offset * 2.0 + 0.5);
+
+    if (width > mMaxTextureSize || height > mMaxTextureSize) {
         LOGW("Shape %s too large to be rendered into a texture", mName);
         return NULL;
     }
 
-    const float offset = paint->getStrokeWidth() * 1.5f;
-    const uint32_t width = uint32_t(pathWidth + offset * 2.0 + 0.5);
-    const uint32_t height = uint32_t(pathHeight + offset * 2.0 + 0.5);
-
     const uint32_t size = width * height;
     // Don't even try to cache a bitmap that's bigger than the cache
     if (size < mMaxSize) {
diff --git a/libs/hwui/TextDropShadowCache.h b/libs/hwui/TextDropShadowCache.h
index d46686d..28dba13 100644
--- a/libs/hwui/TextDropShadowCache.h
+++ b/libs/hwui/TextDropShadowCache.h
@@ -73,7 +73,6 @@
         text = str.string();
     }
 
-    // TODO: Should take into account fake bold and text skew
     bool operator<(const ShadowText& rhs) const {
         LTE_INT(len) {
             LTE_INT(radius) {
diff --git a/libs/rs/Android.mk b/libs/rs/Android.mk
index 9c9fae3..d9cc6b6 100644
--- a/libs/rs/Android.mk
+++ b/libs/rs/Android.mk
@@ -119,6 +119,7 @@
 	driver/rsdBcc.cpp \
 	driver/rsdCore.cpp \
 	driver/rsdFrameBuffer.cpp \
+	driver/rsdFrameBufferObj.cpp \
 	driver/rsdGL.cpp \
 	driver/rsdMesh.cpp \
 	driver/rsdMeshObj.cpp \
@@ -149,24 +150,82 @@
 
 # Now build a host version for serialization
 include $(CLEAR_VARS)
+LOCAL_MODULE:= libRS
+LOCAL_MODULE_TAGS := optional
+
+intermediates := $(call intermediates-dir-for,STATIC_LIBRARIES,libRS,HOST,)
+
+# Generate custom headers
+
+GEN := $(addprefix $(intermediates)/, \
+            rsgApiStructs.h \
+            rsgApiFuncDecl.h \
+        )
+
+$(GEN) : PRIVATE_PATH := $(LOCAL_PATH)
+$(GEN) : PRIVATE_CUSTOM_TOOL = $(RSG_GENERATOR) $< $@ <$(PRIVATE_PATH)/rs.spec
+$(GEN) : $(RSG_GENERATOR) $(LOCAL_PATH)/rs.spec
+$(GEN): $(intermediates)/%.h : $(LOCAL_PATH)/%.h.rsg
+	$(transform-generated-source)
+
+LOCAL_GENERATED_SOURCES += $(GEN)
+
+# Generate custom source files
+
+GEN := $(addprefix $(intermediates)/, \
+            rsgApi.cpp \
+            rsgApiReplay.cpp \
+        )
+
+$(GEN) : PRIVATE_PATH := $(LOCAL_PATH)
+$(GEN) : PRIVATE_CUSTOM_TOOL = $(RSG_GENERATOR) $< $@ <$(PRIVATE_PATH)/rs.spec
+$(GEN) : $(RSG_GENERATOR) $(LOCAL_PATH)/rs.spec
+$(GEN): $(intermediates)/%.cpp : $(LOCAL_PATH)/%.cpp.rsg
+	$(transform-generated-source)
+
+LOCAL_GENERATED_SOURCES += $(GEN)
+
 LOCAL_CFLAGS += -Werror -Wall -Wno-unused-parameter -Wno-unused-variable
 LOCAL_CFLAGS += -DANDROID_RS_SERIALIZE
+LOCAL_CFLAGS += -fPIC
 
 LOCAL_SRC_FILES:= \
+	rsAdapter.cpp \
 	rsAllocation.cpp \
+	rsAnimation.cpp \
 	rsComponent.cpp \
+	rsContext.cpp \
+	rsDevice.cpp \
 	rsElement.cpp \
+	rsFBOCache.cpp \
+	rsFifoSocket.cpp \
 	rsFileA3D.cpp \
+	rsFont.cpp \
+	rsLocklessFifo.cpp \
 	rsObjectBase.cpp \
+	rsMatrix2x2.cpp \
+	rsMatrix3x3.cpp \
+	rsMatrix4x4.cpp \
 	rsMesh.cpp \
+	rsMutex.cpp \
+	rsProgram.cpp \
+	rsProgramFragment.cpp \
+	rsProgramStore.cpp \
+	rsProgramRaster.cpp \
+	rsProgramVertex.cpp \
+	rsSampler.cpp \
+	rsScript.cpp \
+	rsScriptC.cpp \
+	rsScriptC_Lib.cpp \
+	rsScriptC_LibGL.cpp \
+	rsSignal.cpp \
 	rsStream.cpp \
+	rsThreadIO.cpp \
 	rsType.cpp
 
 LOCAL_STATIC_LIBRARIES := libcutils libutils
 
 LOCAL_LDLIBS := -lpthread
-LOCAL_MODULE:= libRSserialize
-LOCAL_MODULE_TAGS := optional
 
 include $(BUILD_HOST_STATIC_LIBRARY)
 
diff --git a/libs/rs/RenderScript.h b/libs/rs/RenderScript.h
index 3f2d67a..535f713 100644
--- a/libs/rs/RenderScript.h
+++ b/libs/rs/RenderScript.h
@@ -55,15 +55,7 @@
 RsContext rsContextCreate(RsDevice dev, uint32_t version);
 RsContext rsContextCreateGL(RsDevice dev, uint32_t version, RsSurfaceConfig sc, uint32_t dpi);
 
-
-
-#ifdef ANDROID_RS_SERIALIZE
-#define NO_RS_FUNCS
-#endif
-
-#ifndef NO_RS_FUNCS
 #include "rsgApiFuncDecl.h"
-#endif
 
 #ifdef __cplusplus
 };
diff --git a/libs/rs/RenderScriptDefines.h b/libs/rs/RenderScriptDefines.h
index ee9645c..d092520 100644
--- a/libs/rs/RenderScriptDefines.h
+++ b/libs/rs/RenderScriptDefines.h
@@ -110,12 +110,12 @@
 };
 
 enum RsAllocationCubemapFace {
-    RS_ALLOCATION_CUBMAP_FACE_POSITVE_X = 0,
-    RS_ALLOCATION_CUBMAP_FACE_NEGATIVE_X = 1,
-    RS_ALLOCATION_CUBMAP_FACE_POSITVE_Y = 2,
-    RS_ALLOCATION_CUBMAP_FACE_NEGATIVE_Y = 3,
-    RS_ALLOCATION_CUBMAP_FACE_POSITVE_Z = 4,
-    RS_ALLOCATION_CUBMAP_FACE_NEGATIVE_Z = 5
+    RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X = 0,
+    RS_ALLOCATION_CUBEMAP_FACE_NEGATIVE_X = 1,
+    RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_Y = 2,
+    RS_ALLOCATION_CUBEMAP_FACE_NEGATIVE_Y = 3,
+    RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_Z = 4,
+    RS_ALLOCATION_CUBEMAP_FACE_NEGATIVE_Z = 5
 };
 
 enum RsDataType {
diff --git a/libs/rs/driver/rsdAllocation.cpp b/libs/rs/driver/rsdAllocation.cpp
index 2e13e9d..01a0cf6 100644
--- a/libs/rs/driver/rsdAllocation.cpp
+++ b/libs/rs/driver/rsdAllocation.cpp
@@ -19,6 +19,7 @@
 #include "rsdBcc.h"
 #include "rsdRuntime.h"
 #include "rsdAllocation.h"
+#include "rsdFrameBufferObj.h"
 
 #include "rsAllocation.h"
 
@@ -244,6 +245,9 @@
     if (alloc->mHal.state.usageFlags & ~RS_ALLOCATION_USAGE_SCRIPT) {
         drv->uploadDeferred = true;
     }
+
+    drv->readBackFBO = NULL;
+
     return true;
 }
 
@@ -269,6 +273,10 @@
         free(drv->mallocPtr);
         drv->mallocPtr = NULL;
     }
+    if (drv->readBackFBO != NULL) {
+        delete drv->readBackFBO;
+        drv->readBackFBO = NULL;
+    }
     free(drv);
     alloc->mHal.drv = NULL;
 }
@@ -292,13 +300,52 @@
     }
 }
 
+static void rsdAllocationSyncFromFBO(const Context *rsc, const Allocation *alloc) {
+    if (!alloc->getIsScript()) {
+        return; // nothing to sync
+    }
+
+    RsdHal *dc = (RsdHal *)rsc->mHal.drv;
+    RsdFrameBufferObj *lastFbo = dc->gl.currentFrameBuffer;
+
+    DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
+    if (!drv->textureID && !drv->renderTargetID) {
+        return; // nothing was rendered here yet, so nothing to sync
+    }
+    if (drv->readBackFBO == NULL) {
+        drv->readBackFBO = new RsdFrameBufferObj();
+        drv->readBackFBO->setColorTarget(drv, 0);
+        drv->readBackFBO->setDimensions(alloc->getType()->getDimX(),
+                                        alloc->getType()->getDimY());
+    }
+
+    // Bind the framebuffer object so we can read back from it
+    drv->readBackFBO->setActive(rsc);
+
+    // Do the readback
+    glReadPixels(0, 0, alloc->getType()->getDimX(), alloc->getType()->getDimY(),
+                 drv->glFormat, drv->glType, alloc->getPtr());
+
+    // Revert framebuffer to its original
+    lastFbo->setActive(rsc);
+}
 
 
 void rsdAllocationSyncAll(const Context *rsc, const Allocation *alloc,
                          RsAllocationUsageType src) {
     DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
 
-    if (!drv->uploadDeferred) {
+    if (src == RS_ALLOCATION_USAGE_GRAPHICS_RENDER_TARGET) {
+        if(!alloc->getIsRenderTarget()) {
+            rsc->setError(RS_ERROR_FATAL_DRIVER,
+                          "Attempting to sync allocation from render target, "
+                          "for non-render target allocation");
+        } else if (alloc->getType()->getElement()->getKind() != RS_KIND_PIXEL_RGBA) {
+            rsc->setError(RS_ERROR_FATAL_DRIVER, "Cannot only sync from RGBA"
+                                                 "render target");
+        } else {
+            rsdAllocationSyncFromFBO(rsc, alloc);
+        }
         return;
     }
 
@@ -378,6 +425,73 @@
 
 }
 
+void rsdAllocationData1D_alloc(const android::renderscript::Context *rsc,
+                               const android::renderscript::Allocation *dstAlloc,
+                               uint32_t dstXoff, uint32_t dstLod, uint32_t count,
+                               const android::renderscript::Allocation *srcAlloc,
+                               uint32_t srcXoff, uint32_t srcLod) {
+}
+
+uint8_t *getOffsetPtr(const android::renderscript::Allocation *alloc,
+                      uint32_t xoff, uint32_t yoff, uint32_t lod,
+                      RsAllocationCubemapFace face) {
+    uint8_t *ptr = static_cast<uint8_t *>(alloc->getPtr());
+    ptr += alloc->getType()->getLODOffset(lod, xoff, yoff);
+
+    if (face != 0) {
+        uint32_t totalSizeBytes = alloc->getType()->getSizeBytes();
+        uint32_t faceOffset = totalSizeBytes / 6;
+        ptr += faceOffset * (uint32_t)face;
+    }
+    return ptr;
+}
+
+
+void rsdAllocationData2D_alloc_script(const android::renderscript::Context *rsc,
+                                      const android::renderscript::Allocation *dstAlloc,
+                                      uint32_t dstXoff, uint32_t dstYoff, uint32_t dstLod,
+                                      RsAllocationCubemapFace dstFace, uint32_t w, uint32_t h,
+                                      const android::renderscript::Allocation *srcAlloc,
+                                      uint32_t srcXoff, uint32_t srcYoff, uint32_t srcLod,
+                                      RsAllocationCubemapFace srcFace) {
+    uint32_t elementSize = dstAlloc->getType()->getElementSizeBytes();
+    for (uint32_t i = 0; i < h; i ++) {
+        uint8_t *dstPtr = getOffsetPtr(dstAlloc, dstXoff, dstYoff + i, dstLod, dstFace);
+        uint8_t *srcPtr = getOffsetPtr(srcAlloc, srcXoff, srcYoff + i, srcLod, srcFace);
+        memcpy(dstPtr, srcPtr, w * elementSize);
+
+        LOGE("COPIED dstXoff(%u), dstYoff(%u), dstLod(%u), dstFace(%u), w(%u), h(%u), srcXoff(%u), srcYoff(%u), srcLod(%u), srcFace(%u)",
+             dstXoff, dstYoff, dstLod, dstFace, w, h, srcXoff, srcYoff, srcLod, srcFace);
+    }
+}
+
+void rsdAllocationData2D_alloc(const android::renderscript::Context *rsc,
+                               const android::renderscript::Allocation *dstAlloc,
+                               uint32_t dstXoff, uint32_t dstYoff, uint32_t dstLod,
+                               RsAllocationCubemapFace dstFace, uint32_t w, uint32_t h,
+                               const android::renderscript::Allocation *srcAlloc,
+                               uint32_t srcXoff, uint32_t srcYoff, uint32_t srcLod,
+                               RsAllocationCubemapFace srcFace) {
+    if (!dstAlloc->getIsScript() && !srcAlloc->getIsScript()) {
+        rsc->setError(RS_ERROR_FATAL_DRIVER, "Non-script allocation copies not "
+                                             "yet implemented.");
+        return;
+    }
+    rsdAllocationData2D_alloc_script(rsc, dstAlloc, dstXoff, dstYoff,
+                                     dstLod, dstFace, w, h, srcAlloc,
+                                     srcXoff, srcYoff, srcLod, srcFace);
+}
+
+void rsdAllocationData3D_alloc(const android::renderscript::Context *rsc,
+                               const android::renderscript::Allocation *dstAlloc,
+                               uint32_t dstXoff, uint32_t dstYoff, uint32_t dstZoff,
+                               uint32_t dstLod, RsAllocationCubemapFace dstFace,
+                               uint32_t w, uint32_t h, uint32_t d,
+                               const android::renderscript::Allocation *srcAlloc,
+                               uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff,
+                               uint32_t srcLod, RsAllocationCubemapFace srcFace) {
+}
+
 void rsdAllocationElementData1D(const Context *rsc, const Allocation *alloc,
                                 uint32_t x,
                                 const void *data, uint32_t cIdx, uint32_t sizeBytes) {
diff --git a/libs/rs/driver/rsdAllocation.h b/libs/rs/driver/rsdAllocation.h
index d7385ce..4fc4419 100644
--- a/libs/rs/driver/rsdAllocation.h
+++ b/libs/rs/driver/rsdAllocation.h
@@ -23,6 +23,8 @@
 #include <GLES/gl.h>
 #include <GLES2/gl2.h>
 
+class RsdFrameBufferObj;
+
 struct DrvAllocation {
     // Is this a legal structure to be used as a texture source.
     // Initially this will require 1D or 2D and color data
@@ -42,8 +44,9 @@
     GLenum glType;
     GLenum glFormat;
 
-
     bool uploadDeferred;
+
+    RsdFrameBufferObj * readBackFBO;
 };
 
 GLenum rsdTypeToGLType(RsDataType t);
@@ -80,6 +83,27 @@
                          uint32_t lod, RsAllocationCubemapFace face,
                          uint32_t w, uint32_t h, uint32_t d, const void *data, uint32_t sizeBytes);
 
+void rsdAllocationData1D_alloc(const android::renderscript::Context *rsc,
+                               const android::renderscript::Allocation *dstAlloc,
+                               uint32_t dstXoff, uint32_t dstLod, uint32_t count,
+                               const android::renderscript::Allocation *srcAlloc,
+                               uint32_t srcXoff, uint32_t srcLod);
+void rsdAllocationData2D_alloc(const android::renderscript::Context *rsc,
+                               const android::renderscript::Allocation *dstAlloc,
+                               uint32_t dstXoff, uint32_t dstYoff, uint32_t dstLod,
+                               RsAllocationCubemapFace dstFace, uint32_t w, uint32_t h,
+                               const android::renderscript::Allocation *srcAlloc,
+                               uint32_t srcXoff, uint32_t srcYoff, uint32_t srcLod,
+                               RsAllocationCubemapFace srcFace);
+void rsdAllocationData3D_alloc(const android::renderscript::Context *rsc,
+                               const android::renderscript::Allocation *dstAlloc,
+                               uint32_t dstXoff, uint32_t dstYoff, uint32_t dstZoff,
+                               uint32_t dstLod, RsAllocationCubemapFace dstFace,
+                               uint32_t w, uint32_t h, uint32_t d,
+                               const android::renderscript::Allocation *srcAlloc,
+                               uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff,
+                               uint32_t srcLod, RsAllocationCubemapFace srcFace);
+
 void rsdAllocationElementData1D(const android::renderscript::Context *rsc,
                                 const android::renderscript::Allocation *alloc,
                                 uint32_t x,
diff --git a/libs/rs/driver/rsdCore.cpp b/libs/rs/driver/rsdCore.cpp
index 94d55a6..38f6895 100644
--- a/libs/rs/driver/rsdCore.cpp
+++ b/libs/rs/driver/rsdCore.cpp
@@ -36,6 +36,7 @@
 #include <cutils/sched_policy.h>
 #include <sys/syscall.h>
 #include <string.h>
+#include <bcc/bcc.h>
 
 using namespace android;
 using namespace android::renderscript;
@@ -73,6 +74,9 @@
         rsdAllocationData1D,
         rsdAllocationData2D,
         rsdAllocationData3D,
+        rsdAllocationData1D_alloc,
+        rsdAllocationData2D_alloc,
+        rsdAllocationData3D_alloc,
         rsdAllocationElementData1D,
         rsdAllocationElementData2D
     },
diff --git a/libs/rs/driver/rsdCore.h b/libs/rs/driver/rsdCore.h
index 422bb1b..f393b60 100644
--- a/libs/rs/driver/rsdCore.h
+++ b/libs/rs/driver/rsdCore.h
@@ -18,7 +18,6 @@
 #define RSD_CORE_H
 
 #include <rs_hal.h>
-#include <bcc/bcc.h>
 
 #include "rsMutex.h"
 #include "rsSignal.h"
diff --git a/libs/rs/driver/rsdFrameBuffer.cpp b/libs/rs/driver/rsdFrameBuffer.cpp
index ce72b5d..8c1b12d 100644
--- a/libs/rs/driver/rsdFrameBuffer.cpp
+++ b/libs/rs/driver/rsdFrameBuffer.cpp
@@ -17,6 +17,7 @@
 
 #include "rsdCore.h"
 #include "rsdFrameBuffer.h"
+#include "rsdFrameBufferObj.h"
 #include "rsdAllocation.h"
 
 #include "rsContext.h"
@@ -28,133 +29,70 @@
 using namespace android;
 using namespace android::renderscript;
 
-struct DrvFrameBuffer {
-    GLuint mFBOId;
-};
-
-void checkError(const Context *rsc) {
-    GLenum status;
-    status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
-    switch (status) {
-    case GL_FRAMEBUFFER_COMPLETE:
-        break;
-    case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
-        rsc->setError(RS_ERROR_BAD_VALUE,
-                      "Unable to set up render Target: RFRAMEBUFFER_INCOMPLETE_ATTACHMENT");
-        break;
-    case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
-        rsc->setError(RS_ERROR_BAD_VALUE,
-                      "Unable to set up render Target: GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT");
-        break;
-    case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS:
-        rsc->setError(RS_ERROR_BAD_VALUE,
-                      "Unable to set up render Target: GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS");
-        break;
-    case GL_FRAMEBUFFER_UNSUPPORTED:
-        rsc->setError(RS_ERROR_BAD_VALUE,
-                      "Unable to set up render Target: GL_FRAMEBUFFER_UNSUPPORTED");
-        break;
-    }
-}
-
-
 void setDepthAttachment(const Context *rsc, const FBOCache *fb) {
-    if (fb->mHal.state.depthTarget.get() != NULL) {
-        DrvAllocation *drv = (DrvAllocation *)fb->mHal.state.depthTarget->mHal.drv;
+    RsdFrameBufferObj *fbo = (RsdFrameBufferObj*)fb->mHal.drv;
 
-        if (drv->textureID) {
-            glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
-                                   GL_TEXTURE_2D, drv->textureID, 0);
-        } else {
-            glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
-                                      GL_RENDERBUFFER, drv->renderTargetID);
+    DrvAllocation *depth = NULL;
+    if (fb->mHal.state.depthTarget.get() != NULL) {
+        depth = (DrvAllocation *)fb->mHal.state.depthTarget->mHal.drv;
+
+        if (depth->uploadDeferred) {
+            rsdAllocationSyncAll(rsc, fb->mHal.state.depthTarget.get(),
+                                 RS_ALLOCATION_USAGE_SCRIPT);
         }
-    } else {
-        // Reset last attachment
-        glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0);
-        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
     }
+    fbo->setDepthTarget(depth);
 }
 
 void setColorAttachment(const Context *rsc, const FBOCache *fb) {
+    RsdFrameBufferObj *fbo = (RsdFrameBufferObj*)fb->mHal.drv;
     // Now attach color targets
     for (uint32_t i = 0; i < fb->mHal.state.colorTargetsCount; i ++) {
-        uint32_t texID = 0;
+        DrvAllocation *color = NULL;
         if (fb->mHal.state.colorTargets[i].get() != NULL) {
-            DrvAllocation *drv = (DrvAllocation *)fb->mHal.state.colorTargets[i]->mHal.drv;
+            color = (DrvAllocation *)fb->mHal.state.colorTargets[i]->mHal.drv;
 
-            if (drv->textureID) {
-                glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i,
-                                       GL_TEXTURE_2D, drv->textureID, 0);
-            } else {
-                glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i,
-                                          GL_RENDERBUFFER, drv->renderTargetID);
+            if (color->uploadDeferred) {
+                rsdAllocationSyncAll(rsc, fb->mHal.state.colorTargets[i].get(),
+                                     RS_ALLOCATION_USAGE_SCRIPT);
             }
-        } else {
-            // Reset last attachment
-            glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i,
-                                      GL_RENDERBUFFER, 0);
-            glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i,
-                                   GL_TEXTURE_2D, 0, 0);
         }
+        fbo->setColorTarget(color, i);
     }
 }
 
-bool renderToFramebuffer(const FBOCache *fb) {
-    if (fb->mHal.state.depthTarget.get() != NULL) {
-        return false;
-    }
-
-    for (uint32_t i = 0; i < fb->mHal.state.colorTargetsCount; i ++) {
-        if (fb->mHal.state.colorTargets[i].get() != NULL) {
-            return false;
-        }
-    }
-    return true;
-}
-
-
 bool rsdFrameBufferInit(const Context *rsc, const FBOCache *fb) {
-    DrvFrameBuffer *drv = (DrvFrameBuffer *)calloc(1, sizeof(DrvFrameBuffer));
-    if (drv == NULL) {
+    RsdFrameBufferObj *fbo = new RsdFrameBufferObj();
+    if (fbo == NULL) {
         return false;
     }
-    fb->mHal.drv = drv;
-    drv->mFBOId = 0;
+    fb->mHal.drv = fbo;
+
+    RsdHal *dc = (RsdHal *)rsc->mHal.drv;
+    dc->gl.currentFrameBuffer = fbo;
 
     return true;
 }
 
 void rsdFrameBufferSetActive(const Context *rsc, const FBOCache *fb) {
-    DrvFrameBuffer *drv = (DrvFrameBuffer *)fb->mHal.drv;
+    setDepthAttachment(rsc, fb);
+    setColorAttachment(rsc, fb);
 
-    bool framebuffer = renderToFramebuffer(fb);
-    if (!framebuffer) {
-        if(drv->mFBOId == 0) {
-            glGenFramebuffers(1, &drv->mFBOId);
-        }
-        glBindFramebuffer(GL_FRAMEBUFFER, drv->mFBOId);
-
-        setDepthAttachment(rsc, fb);
-        setColorAttachment(rsc, fb);
-
-        glViewport(0, 0, fb->mHal.state.colorTargets[0]->getType()->getDimX(),
-                         fb->mHal.state.colorTargets[0]->getType()->getDimY());
-
-        checkError(rsc);
-    } else {
-        glBindFramebuffer(GL_FRAMEBUFFER, 0);
-        glViewport(0, 0, rsc->getWidth(), rsc->getHeight());
+    RsdFrameBufferObj *fbo = (RsdFrameBufferObj *)fb->mHal.drv;
+    if (fb->mHal.state.colorTargets[0].get()) {
+        fbo->setDimensions(fb->mHal.state.colorTargets[0]->getType()->getDimX(),
+                           fb->mHal.state.colorTargets[0]->getType()->getDimY());
+    } else if (fb->mHal.state.depthTarget.get()) {
+        fbo->setDimensions(fb->mHal.state.depthTarget->getType()->getDimX(),
+                           fb->mHal.state.depthTarget->getType()->getDimY());
     }
+
+    fbo->setActive(rsc);
 }
 
 void rsdFrameBufferDestroy(const Context *rsc, const FBOCache *fb) {
-    DrvFrameBuffer *drv = (DrvFrameBuffer *)fb->mHal.drv;
-    if(drv->mFBOId != 0) {
-        glDeleteFramebuffers(1, &drv->mFBOId);
-    }
-
-    free(fb->mHal.drv);
+    RsdFrameBufferObj *fbo = (RsdFrameBufferObj *)fb->mHal.drv;
+    delete fbo;
     fb->mHal.drv = NULL;
 }
 
diff --git a/libs/rs/driver/rsdFrameBufferObj.cpp b/libs/rs/driver/rsdFrameBufferObj.cpp
new file mode 100644
index 0000000..145bf34
--- /dev/null
+++ b/libs/rs/driver/rsdFrameBufferObj.cpp
@@ -0,0 +1,143 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include "rsdFrameBufferObj.h"
+#include "rsdAllocation.h"
+
+#include <GLES2/gl2.h>
+#include <GLES2/gl2ext.h>
+
+using namespace android;
+using namespace android::renderscript;
+
+RsdFrameBufferObj::RsdFrameBufferObj() {
+    mFBOId = 0;
+    mWidth = 0;
+    mHeight = 0;
+    mColorTargetsCount = 1;
+    mColorTargets = new DrvAllocation*[mColorTargetsCount];
+    for (uint32_t i = 0; i < mColorTargetsCount; i ++) {
+        mColorTargets[i] = 0;
+    }
+    mDepthTarget = NULL;
+    mDirty = true;
+}
+
+RsdFrameBufferObj::~RsdFrameBufferObj() {
+    if(mFBOId != 0) {
+        glDeleteFramebuffers(1, &mFBOId);
+    }
+    delete [] mColorTargets;
+}
+
+void RsdFrameBufferObj::checkError(const Context *rsc) {
+    GLenum status;
+    status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
+    switch (status) {
+    case GL_FRAMEBUFFER_COMPLETE:
+        break;
+    case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
+        rsc->setError(RS_ERROR_BAD_VALUE,
+                      "Unable to set up render Target: RFRAMEBUFFER_INCOMPLETE_ATTACHMENT");
+        break;
+    case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
+        rsc->setError(RS_ERROR_BAD_VALUE,
+                      "Unable to set up render Target: GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT");
+        break;
+    case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS:
+        rsc->setError(RS_ERROR_BAD_VALUE,
+                      "Unable to set up render Target: GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS");
+        break;
+    case GL_FRAMEBUFFER_UNSUPPORTED:
+        rsc->setError(RS_ERROR_BAD_VALUE,
+                      "Unable to set up render Target: GL_FRAMEBUFFER_UNSUPPORTED");
+        break;
+    }
+}
+
+
+void RsdFrameBufferObj::setDepthAttachment() {
+    if (mDepthTarget != NULL) {
+        if (mDepthTarget->textureID) {
+            glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
+                                   GL_TEXTURE_2D, mDepthTarget->textureID, 0);
+        } else {
+            glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
+                                      GL_RENDERBUFFER, mDepthTarget->renderTargetID);
+        }
+    } else {
+        // Reset last attachment
+        glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0);
+        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
+    }
+}
+
+void RsdFrameBufferObj::setColorAttachment() {
+    // Now attach color targets
+    for (uint32_t i = 0; i < mColorTargetsCount; i ++) {
+        if (mColorTargets[i] != NULL) {
+            if (mColorTargets[i]->textureID) {
+                glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i,
+                                       GL_TEXTURE_2D, mColorTargets[i]->textureID, 0);
+            } else {
+                glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i,
+                                          GL_RENDERBUFFER, mColorTargets[i]->renderTargetID);
+            }
+        } else {
+            // Reset last attachment
+            glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i,
+                                      GL_RENDERBUFFER, 0);
+            glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i,
+                                   GL_TEXTURE_2D, 0, 0);
+        }
+    }
+}
+
+bool RsdFrameBufferObj::renderToFramebuffer() {
+    if (mDepthTarget != NULL) {
+        return false;
+    }
+
+    for (uint32_t i = 0; i < mColorTargetsCount; i ++) {
+        if (mColorTargets[i] != NULL) {
+            return false;
+        }
+    }
+    return true;
+}
+
+void RsdFrameBufferObj::setActive(const Context *rsc) {
+    bool framebuffer = renderToFramebuffer();
+    if (!framebuffer) {
+        if(mFBOId == 0) {
+            glGenFramebuffers(1, &mFBOId);
+        }
+        glBindFramebuffer(GL_FRAMEBUFFER, mFBOId);
+
+        if (mDirty) {
+            setDepthAttachment();
+            setColorAttachment();
+            mDirty = false;
+        }
+
+        glViewport(0, 0, mWidth, mHeight);
+        checkError(rsc);
+    } else {
+        glBindFramebuffer(GL_FRAMEBUFFER, 0);
+        glViewport(0, 0, rsc->getWidth(), rsc->getHeight());
+    }
+}
diff --git a/libs/rs/driver/rsdFrameBufferObj.h b/libs/rs/driver/rsdFrameBufferObj.h
new file mode 100644
index 0000000..c6e7deb
--- /dev/null
+++ b/libs/rs/driver/rsdFrameBufferObj.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _RSD_FRAMEBUFFER_OBJ_H_
+#define _RSD_FRAMEBUFFER_OBJ_H_
+
+#include <rsContext.h>
+
+class DrvAllocation;
+
+class RsdFrameBufferObj {
+public:
+    RsdFrameBufferObj();
+    ~RsdFrameBufferObj();
+
+    void setActive(const android::renderscript::Context *rsc);
+    void setColorTarget(DrvAllocation *color, uint32_t index) {
+        mColorTargets[index] = color;
+        mDirty = true;
+    }
+    void setDepthTarget(DrvAllocation *depth) {
+        mDepthTarget = depth;
+        mDirty = true;
+    }
+    void setDimensions(uint32_t width, uint32_t height) {
+        mWidth = width;
+        mHeight = height;
+    }
+protected:
+    uint32_t mFBOId;
+    DrvAllocation **mColorTargets;
+    uint32_t mColorTargetsCount;
+    DrvAllocation *mDepthTarget;
+
+    uint32_t mWidth;
+    uint32_t mHeight;
+
+    bool mDirty;
+
+    bool renderToFramebuffer();
+    void checkError(const android::renderscript::Context *rsc);
+    void setColorAttachment();
+    void setDepthAttachment();
+};
+
+#endif //_RSD_FRAMEBUFFER_STATE_H_
diff --git a/libs/rs/driver/rsdGL.cpp b/libs/rs/driver/rsdGL.cpp
index a70589b..3ff03b4 100644
--- a/libs/rs/driver/rsdGL.cpp
+++ b/libs/rs/driver/rsdGL.cpp
@@ -39,6 +39,7 @@
 #include "rsContext.h"
 #include "rsdShaderCache.h"
 #include "rsdVertexArray.h"
+#include "rsdFrameBufferObj.h"
 
 using namespace android;
 using namespace android::renderscript;
@@ -294,6 +295,7 @@
     dc->gl.shaderCache = new RsdShaderCache();
     dc->gl.vertexArrayState = new RsdVertexArrayState();
     dc->gl.vertexArrayState->init(dc->gl.gl.maxVertexAttribs);
+    dc->gl.currentFrameBuffer = NULL;
 
     LOGV("initGLThread end %p", rsc);
     return true;
diff --git a/libs/rs/driver/rsdGL.h b/libs/rs/driver/rsdGL.h
index 01c8438..0d5b7e7 100644
--- a/libs/rs/driver/rsdGL.h
+++ b/libs/rs/driver/rsdGL.h
@@ -22,6 +22,7 @@
 
 class RsdShaderCache;
 class RsdVertexArrayState;
+class RsdFrameBufferObj;
 
 typedef void (* InvokeFunc_t)(void);
 typedef void (*WorkerCallback_t)(void *usr, uint32_t idx);
@@ -68,6 +69,7 @@
     uint32_t height;
     RsdShaderCache *shaderCache;
     RsdVertexArrayState *vertexArrayState;
+    RsdFrameBufferObj *currentFrameBuffer;
 } RsdGL;
 
 
diff --git a/libs/rs/driver/rsdMeshObj.cpp b/libs/rs/driver/rsdMeshObj.cpp
index c220ac1..4315c0d 100644
--- a/libs/rs/driver/rsdMeshObj.cpp
+++ b/libs/rs/driver/rsdMeshObj.cpp
@@ -138,7 +138,10 @@
 
     for (uint32_t ct=0; ct < mRSMesh->mHal.state.vertexBuffersCount; ct++) {
         const Allocation *alloc = mRSMesh->mHal.state.vertexBuffers[ct].get();
-        rsdAllocationSyncAll(rsc, alloc, RS_ALLOCATION_USAGE_SCRIPT);
+        DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
+        if (drv->uploadDeferred) {
+            rsdAllocationSyncAll(rsc, alloc, RS_ALLOCATION_USAGE_SCRIPT);
+        }
     }
 
     // update attributes with either buffer information or data ptr based on their current state
@@ -163,7 +166,9 @@
     const Allocation *idxAlloc = prim->mIndexBuffer.get();
     if (idxAlloc) {
         DrvAllocation *drvAlloc = (DrvAllocation *)idxAlloc->mHal.drv;
-        rsdAllocationSyncAll(rsc, idxAlloc, RS_ALLOCATION_USAGE_SCRIPT);
+        if (drvAlloc->uploadDeferred) {
+            rsdAllocationSyncAll(rsc, idxAlloc, RS_ALLOCATION_USAGE_SCRIPT);
+        }
 
         if (drvAlloc->bufferID) {
             glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, drvAlloc->bufferID);
diff --git a/libs/rs/driver/rsdRuntimeStubs.cpp b/libs/rs/driver/rsdRuntimeStubs.cpp
index 9cbff95..25302aa 100644
--- a/libs/rs/driver/rsdRuntimeStubs.cpp
+++ b/libs/rs/driver/rsdRuntimeStubs.cpp
@@ -88,6 +88,33 @@
     rsrAllocationSyncAll(rsc, sc, a, RS_ALLOCATION_USAGE_SCRIPT);
 }
 
+static void SC_AllocationCopy1DRange(Allocation *dstAlloc,
+                                     uint32_t dstOff,
+                                     uint32_t dstMip,
+                                     uint32_t count,
+                                     Allocation *srcAlloc,
+                                     uint32_t srcOff, uint32_t srcMip) {
+    GET_TLS();
+    rsrAllocationCopy1DRange(rsc, dstAlloc, dstOff, dstMip, count,
+                             srcAlloc, srcOff, srcMip);
+}
+
+static void SC_AllocationCopy2DRange(Allocation *dstAlloc,
+                                     uint32_t dstXoff, uint32_t dstYoff,
+                                     uint32_t dstMip, uint32_t dstFace,
+                                     uint32_t width, uint32_t height,
+                                     Allocation *srcAlloc,
+                                     uint32_t srcXoff, uint32_t srcYoff,
+                                     uint32_t srcMip, uint32_t srcFace) {
+    GET_TLS();
+    rsrAllocationCopy2DRange(rsc, dstAlloc,
+                             dstXoff, dstYoff, dstMip, dstFace,
+                             width, height,
+                             srcAlloc,
+                             srcXoff, srcYoff, srcMip, srcFace);
+}
+
+
 const Allocation * SC_getAllocation(const void *ptr) {
     GET_TLS();
     return rsrGetAllocation(rsc, sc, ptr);
@@ -566,8 +593,11 @@
     { "_Z21rsAllocationMarkDirty13rs_allocation", (void *)&SC_AllocationSyncAll, true },
     { "_Z20rsgAllocationSyncAll13rs_allocation", (void *)&SC_AllocationSyncAll, false },
     { "_Z20rsgAllocationSyncAll13rs_allocationj", (void *)&SC_AllocationSyncAll2, false },
+    { "_Z20rsgAllocationSyncAll13rs_allocation24rs_allocation_usage_type", (void *)&SC_AllocationSyncAll2, false },
     { "_Z15rsGetAllocationPKv", (void *)&SC_GetAllocation, true },
 
+    { "_Z23rsAllocationCopy1DRange13rs_allocationjjjS_jj", (void *)&SC_AllocationCopy1DRange, false },
+    { "_Z23rsAllocationCopy2DRange13rs_allocationjjj26rs_allocation_cubemap_facejjS_jjjS0_", (void *)&SC_AllocationCopy2DRange, false },
 
     // Messaging
 
diff --git a/libs/rs/rs.spec b/libs/rs/rs.spec
index 87d764d..963a6e7 100644
--- a/libs/rs/rs.spec
+++ b/libs/rs/rs.spec
@@ -209,6 +209,21 @@
 	param uint32_t dimY
 	}
 
+AllocationCopy2DRange {
+	param RsAllocation dest
+	param uint32_t destXoff
+	param uint32_t destYoff
+	param uint32_t destMip
+	param uint32_t destFace
+	param uint32_t width
+	param uint32_t height
+	param RsAllocation src
+	param uint32_t srcXoff
+	param uint32_t srcYoff
+	param uint32_t srcMip
+	param uint32_t srcFace
+	}
+
 SamplerCreate {
     param RsSamplerValue magFilter
     param RsSamplerValue minFilter
diff --git a/libs/rs/rsAllocation.cpp b/libs/rs/rsAllocation.cpp
index 05412c7..f3e0c0a 100644
--- a/libs/rs/rsAllocation.cpp
+++ b/libs/rs/rsAllocation.cpp
@@ -168,13 +168,10 @@
 }
 
 void Allocation::addProgramToDirty(const Program *p) {
-#ifndef ANDROID_RS_SERIALIZE
     mToDirtyList.push(p);
-#endif //ANDROID_RS_SERIALIZE
 }
 
 void Allocation::removeProgramToDirty(const Program *p) {
-#ifndef ANDROID_RS_SERIALIZE
     for (size_t ct=0; ct < mToDirtyList.size(); ct++) {
         if (mToDirtyList[ct] == p) {
             mToDirtyList.removeAt(ct);
@@ -182,7 +179,6 @@
         }
     }
     rsAssert(0);
-#endif //ANDROID_RS_SERIALIZE
 }
 
 void Allocation::dumpLOGV(const char *prefix) const {
@@ -254,11 +250,9 @@
 }
 
 void Allocation::sendDirty(const Context *rsc) const {
-#ifndef ANDROID_RS_SERIALIZE
     for (size_t ct=0; ct < mToDirtyList.size(); ct++) {
         mToDirtyList[ct]->forceDirty();
     }
-#endif //ANDROID_RS_SERIALIZE
     mRSC->mHal.funcs.allocation.markDirty(rsc, this);
 }
 
@@ -312,8 +306,6 @@
 
 /////////////////
 //
-#ifndef ANDROID_RS_SERIALIZE
-
 
 namespace android {
 namespace renderscript {
@@ -413,25 +405,25 @@
 }
 
 void rsi_Allocation1DData(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t lod,
-                          uint32_t count, const void *data, uint32_t sizeBytes) {
+                          uint32_t count, const void *data, size_t sizeBytes) {
     Allocation *a = static_cast<Allocation *>(va);
     a->data(rsc, xoff, lod, count, data, sizeBytes);
 }
 
 void rsi_Allocation2DElementData(Context *rsc, RsAllocation va, uint32_t x, uint32_t y, uint32_t lod, RsAllocationCubemapFace face,
-                                 const void *data, uint32_t eoff, uint32_t sizeBytes) {
+                                 const void *data, size_t eoff, uint32_t sizeBytes) { // TODO: this seems wrong, eoff and sizeBytes may be swapped
     Allocation *a = static_cast<Allocation *>(va);
     a->elementData(rsc, x, y, data, eoff, sizeBytes);
 }
 
 void rsi_Allocation1DElementData(Context *rsc, RsAllocation va, uint32_t x, uint32_t lod,
-                                 const void *data, uint32_t eoff, uint32_t sizeBytes) {
+                                 const void *data, size_t eoff, uint32_t sizeBytes) { // TODO: this seems wrong, eoff and sizeBytes may be swapped
     Allocation *a = static_cast<Allocation *>(va);
     a->elementData(rsc, x, data, eoff, sizeBytes);
 }
 
 void rsi_Allocation2DData(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face,
-                          uint32_t w, uint32_t h, const void *data, uint32_t sizeBytes) {
+                          uint32_t w, uint32_t h, const void *data, size_t sizeBytes) {
     Allocation *a = static_cast<Allocation *>(va);
     a->data(rsc, xoff, yoff, lod, face, w, h, data, sizeBytes);
 }
@@ -540,6 +532,23 @@
     return texAlloc;
 }
 
+void rsi_AllocationCopy2DRange(Context *rsc,
+                               RsAllocation dstAlloc,
+                               uint32_t dstXoff, uint32_t dstYoff,
+                               uint32_t dstMip, uint32_t dstFace,
+                               uint32_t width, uint32_t height,
+                               RsAllocation srcAlloc,
+                               uint32_t srcXoff, uint32_t srcYoff,
+                               uint32_t srcMip, uint32_t srcFace) {
+    Allocation *dst = static_cast<Allocation *>(dstAlloc);
+    Allocation *src= static_cast<Allocation *>(srcAlloc);
+    rsc->mHal.funcs.allocation.allocData2D(rsc, dst, dstXoff, dstYoff, dstMip,
+                                           (RsAllocationCubemapFace)dstFace,
+                                           width, height,
+                                           src, srcXoff, srcYoff,srcMip,
+                                           (RsAllocationCubemapFace)srcFace);
+}
+
 }
 }
 
@@ -549,5 +558,3 @@
 
     return a->getType();
 }
-
-#endif //ANDROID_RS_SERIALIZE
diff --git a/libs/rs/rsAllocation.h b/libs/rs/rsAllocation.h
index 5cf6292..f538dd1 100644
--- a/libs/rs/rsAllocation.h
+++ b/libs/rs/rsAllocation.h
@@ -59,7 +59,6 @@
 
     static Allocation * createAllocation(Context *rsc, const Type *, uint32_t usages,
                                   RsAllocationMipmapControl mc = RS_ALLOCATION_MIPMAP_NONE);
-
     virtual ~Allocation();
     void updateCache();
 
@@ -121,14 +120,6 @@
 
 private:
     Allocation(Context *rsc, const Type *, uint32_t usages, RsAllocationMipmapControl mc);
-
-    void upload2DTexture(bool isFirstUpload);
-    void update2DTexture(const void *ptr, uint32_t xoff, uint32_t yoff,
-                         uint32_t lod, RsAllocationCubemapFace face, uint32_t w, uint32_t h);
-
-    void allocScriptMemory();
-    void freeScriptMemory();
-
 };
 
 }
diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp
index bab5c58..44e9d89 100644
--- a/libs/rs/rsContext.cpp
+++ b/libs/rs/rsContext.cpp
@@ -92,9 +92,13 @@
 }
 
 uint64_t Context::getTime() const {
+#ifndef ANDROID_RS_SERIALIZE
     struct timespec t;
     clock_gettime(CLOCK_MONOTONIC, &t);
     return t.tv_nsec + ((uint64_t)t.tv_sec * 1000 * 1000 * 1000);
+#else
+    return 0;
+#endif //ANDROID_RS_SERIALIZE
 }
 
 void Context::timerReset() {
@@ -200,11 +204,11 @@
 
 void * Context::threadProc(void *vrsc) {
     Context *rsc = static_cast<Context *>(vrsc);
+#ifndef ANDROID_RS_SERIALIZE
     rsc->mNativeThreadId = gettid();
-
     setpriority(PRIO_PROCESS, rsc->mNativeThreadId, ANDROID_PRIORITY_DISPLAY);
     rsc->mThreadPriority = ANDROID_PRIORITY_DISPLAY;
-
+#endif //ANDROID_RS_SERIALIZE
     rsc->props.mLogTimes = getProp("debug.rs.profile");
     rsc->props.mLogScripts = getProp("debug.rs.script");
     rsc->props.mLogObjects = getProp("debug.rs.object");
@@ -330,10 +334,16 @@
     mObjHead = NULL;
     mError = RS_ERROR_NONE;
     mDPI = 96;
+    mIsContextLite = false;
 }
 
 Context * Context::createContext(Device *dev, const RsSurfaceConfig *sc) {
     Context * rsc = new Context();
+
+    // Temporary to avoid breaking the tools
+    if (!dev) {
+        return rsc;
+    }
     if (!rsc->initContext(dev, sc)) {
         delete rsc;
         return NULL;
@@ -341,6 +351,12 @@
     return rsc;
 }
 
+Context * Context::createContextLite() {
+    Context * rsc = new Context();
+    rsc->mIsContextLite = true;
+    return rsc;
+}
+
 bool Context::initContext(Device *dev, const RsSurfaceConfig *sc) {
     pthread_mutex_lock(&gInitMutex);
 
@@ -395,26 +411,28 @@
 Context::~Context() {
     LOGV("Context::~Context");
 
-    mIO.coreFlush();
-    rsAssert(mExit);
-    mExit = true;
-    mPaused = false;
-    void *res;
+    if (!mIsContextLite) {
+        mIO.coreFlush();
+        rsAssert(mExit);
+        mExit = true;
+        mPaused = false;
+        void *res;
 
-    mIO.shutdown();
-    int status = pthread_join(mThreadId, &res);
+        mIO.shutdown();
+        int status = pthread_join(mThreadId, &res);
 
-    if (mHal.funcs.shutdownDriver) {
-        mHal.funcs.shutdownDriver(this);
+        if (mHal.funcs.shutdownDriver) {
+            mHal.funcs.shutdownDriver(this);
+        }
+
+        // Global structure cleanup.
+        pthread_mutex_lock(&gInitMutex);
+        if (mDev) {
+            mDev->removeContext(this);
+            mDev = NULL;
+        }
+        pthread_mutex_unlock(&gInitMutex);
     }
-
-    // Global structure cleanup.
-    pthread_mutex_lock(&gInitMutex);
-    if (mDev) {
-        mDev->removeContext(this);
-        mDev = NULL;
-    }
-    pthread_mutex_unlock(&gInitMutex);
     LOGV("Context::~Context done");
 }
 
@@ -542,7 +560,7 @@
 
     LOGE(" RS width %i, height %i", mWidth, mHeight);
     LOGE(" RS running %i, exit %i, paused %i", mRunning, mExit, mPaused);
-    LOGE(" RS pThreadID %li, nativeThreadID %i", mThreadId, mNativeThreadId);
+    LOGE(" RS pThreadID %li, nativeThreadID %i", (long int)mThreadId, mNativeThreadId);
 }
 
 ///////////////////////////////////////////////////////////////////////////////////////////
@@ -595,7 +613,7 @@
     rsc->setFont(font);
 }
 
-void rsi_AssignName(Context *rsc, RsObjectBase obj, const char *name, uint32_t name_length) {
+void rsi_AssignName(Context *rsc, RsObjectBase obj, const char *name, size_t name_length) {
     ObjectBase *ob = static_cast<ObjectBase *>(obj);
     rsc->assignName(ob, name, name_length);
 }
@@ -627,7 +645,7 @@
 }
 
 void rsi_ContextDestroyWorker(Context *rsc) {
-    rsc->destroyWorkerThreadResources();;
+    rsc->destroyWorkerThreadResources();
 }
 
 void rsi_ContextDestroy(Context *rsc) {
diff --git a/libs/rs/rsContext.h b/libs/rs/rsContext.h
index 4ba00fe..309fe95 100644
--- a/libs/rs/rsContext.h
+++ b/libs/rs/rsContext.h
@@ -24,7 +24,6 @@
 
 #include "rs_hal.h"
 
-#ifndef ANDROID_RS_SERIALIZE
 #include "rsMutex.h"
 #include "rsThreadIO.h"
 #include "rsMatrix4x4.h"
@@ -42,8 +41,6 @@
 #include "rsgApiStructs.h"
 #include "rsLocklessFifo.h"
 
-#endif // ANDROID_RS_SERIALIZE
-
 // ---------------------------------------------------------------------------
 namespace android {
 
@@ -67,8 +64,6 @@
 #define CHECK_OBJ_OR_NULL(o)
 #endif
 
-#ifndef ANDROID_RS_SERIALIZE
-
 class Context {
 public:
     struct Hal {
@@ -79,6 +74,7 @@
     Hal mHal;
 
     static Context * createContext(Device *, const RsSurfaceConfig *sc);
+    static Context * createContextLite();
     ~Context();
 
     static pthread_mutex_t gInitMutex;
@@ -243,6 +239,7 @@
     static void * helperThreadProc(void *);
 
     bool mHasSurface;
+    bool mIsContextLite;
 
     Vector<ObjectBase *> mNames;
 
@@ -259,46 +256,6 @@
     uint32_t mAverageFPS;
 };
 
-#else
-
-class Context {
-public:
-    Context() {
-        mObjHead = NULL;
-    }
-    ~Context() {
-        ObjectBase::zeroAllUserRef(this);
-    }
-
-    struct Hal {
-        void * drv;
-
-        RsdHalFunctions funcs;
-    };
-    Hal mHal;
-
-    ElementState mStateElement;
-    TypeState mStateType;
-
-    struct {
-        bool mLogTimes;
-        bool mLogScripts;
-        bool mLogObjects;
-        bool mLogShaders;
-        bool mLogShadersAttr;
-        bool mLogShadersUniforms;
-        bool mLogVisual;
-    } props;
-
-    void setError(RsError e, const char *msg = NULL) {  }
-
-    mutable const ObjectBase * mObjHead;
-
-protected:
-
-};
-#endif //ANDROID_RS_SERIALIZE
-
 } // renderscript
 } // android
 #endif
diff --git a/libs/rs/rsFBOCache.cpp b/libs/rs/rsFBOCache.cpp
index 6960ef2..c5c64c2 100644
--- a/libs/rs/rsFBOCache.cpp
+++ b/libs/rs/rsFBOCache.cpp
@@ -80,16 +80,6 @@
         return;
     }
 
-    if (mHal.state.depthTarget.get() != NULL) {
-        mHal.state.depthTarget->syncAll(rsc, RS_ALLOCATION_USAGE_SCRIPT);
-    }
-
-    for (uint32_t i = 0; i < mHal.state.colorTargetsCount; i ++) {
-        if (mHal.state.colorTargets[i].get() != NULL) {
-            mHal.state.colorTargets[i]->syncAll(rsc, RS_ALLOCATION_USAGE_SCRIPT);
-        }
-    }
-
     rsc->mHal.funcs.framebuffer.setActive(rsc, this);
 
     mDirty = false;
diff --git a/libs/rs/rsFifoSocket.cpp b/libs/rs/rsFifoSocket.cpp
index 848bba5..8b8008d 100644
--- a/libs/rs/rsFifoSocket.cpp
+++ b/libs/rs/rsFifoSocket.cpp
@@ -70,9 +70,9 @@
 }
 
 void FifoSocket::readReturn(const void *data, size_t bytes) {
-    LOGE("readReturn %p %i", data, bytes);
+    LOGE("readReturn %p %Zu", data, bytes);
     size_t ret = ::send(sv[1], data, bytes, 0);
-    LOGE("readReturn %i", ret);
+    LOGE("readReturn %Zu", ret);
     rsAssert(ret == bytes);
 }
 
diff --git a/libs/rs/rsFont.cpp b/libs/rs/rsFont.cpp
index b625504..ce674f4 100644
--- a/libs/rs/rsFont.cpp
+++ b/libs/rs/rsFont.cpp
@@ -21,9 +21,11 @@
 #include "rsProgramFragment.h"
 #include <cutils/properties.h>
 
+#ifndef ANDROID_RS_SERIALIZE
 #include <ft2build.h>
 #include FT_FREETYPE_H
 #include FT_BITMAP_H
+#endif //ANDROID_RS_SERIALIZE
 
 using namespace android;
 using namespace android::renderscript;
@@ -35,6 +37,7 @@
 }
 
 bool Font::init(const char *name, float fontSize, uint32_t dpi, const void *data, uint32_t dataLen) {
+#ifndef ANDROID_RS_SERIALIZE
     if (mInitialized) {
         LOGE("Reinitialization of fonts not supported");
         return false;
@@ -65,6 +68,7 @@
     mHasKerning = FT_HAS_KERNING(mFace);
 
     mInitialized = true;
+#endif //ANDROID_RS_SERIALIZE
     return true;
 }
 
@@ -230,6 +234,7 @@
 }
 
 void Font::updateGlyphCache(CachedGlyphInfo *glyph) {
+#ifndef ANDROID_RS_SERIALIZE
     FT_Error error = FT_Load_Glyph( mFace, glyph->mGlyphIndex, FT_LOAD_RENDER );
     if (error) {
         LOGE("Couldn't load glyph.");
@@ -270,15 +275,16 @@
     glyph->mBitmapMinV = (float)startY / (float)cacheHeight;
     glyph->mBitmapMaxU = (float)endX / (float)cacheWidth;
     glyph->mBitmapMaxV = (float)endY / (float)cacheHeight;
+#endif //ANDROID_RS_SERIALIZE
 }
 
 Font::CachedGlyphInfo *Font::cacheGlyph(uint32_t glyph) {
     CachedGlyphInfo *newGlyph = new CachedGlyphInfo();
     mCachedGlyphs.add(glyph, newGlyph);
-
+#ifndef ANDROID_RS_SERIALIZE
     newGlyph->mGlyphIndex = FT_Get_Char_Index(mFace, glyph);
     newGlyph->mIsValid = false;
-
+#endif //ANDROID_RS_SERIALIZE
     updateGlyphCache(newGlyph);
 
     return newGlyph;
@@ -309,9 +315,11 @@
 }
 
 Font::~Font() {
+#ifndef ANDROID_RS_SERIALIZE
     if (mFace) {
         FT_Done_Face(mFace);
     }
+#endif
 
     for (uint32_t i = 0; i < mCachedGlyphs.size(); i ++) {
         CachedGlyphInfo *glyph = mCachedGlyphs.valueAt(i);
@@ -324,7 +332,9 @@
     mMaxNumberOfQuads = 1024;
     mCurrentQuadIndex = 0;
     mRSC = NULL;
+#ifndef ANDROID_RS_SERIALIZE
     mLibrary = NULL;
+#endif //ANDROID_RS_SERIALIZE
 
     // Get the renderer properties
     char property[PROPERTY_VALUE_MAX];
@@ -363,7 +373,7 @@
 
     rsAssert(!mActiveFonts.size());
 }
-
+#ifndef ANDROID_RS_SERIALIZE
 FT_Library FontState::getLib() {
     if (!mLibrary) {
         FT_Error error = FT_Init_FreeType(&mLibrary);
@@ -375,6 +385,8 @@
 
     return mLibrary;
 }
+#endif //ANDROID_RS_SERIALIZE
+
 
 void FontState::init(Context *rsc) {
     mRSC = rsc;
@@ -393,6 +405,7 @@
     }
 }
 
+#ifndef ANDROID_RS_SERIALIZE
 bool FontState::cacheBitmap(FT_Bitmap *bitmap, uint32_t *retOriginX, uint32_t *retOriginY) {
     // If the glyph is too tall, don't cache it
     if ((uint32_t)bitmap->rows > mCacheLines[mCacheLines.size()-1]->mMaxHeight) {
@@ -466,6 +479,7 @@
 
     return true;
 }
+#endif //ANDROID_RS_SERIALIZE
 
 void FontState::initRenderState() {
     String8 shaderString("varying vec2 varTex0;\n");
@@ -791,13 +805,15 @@
     mCacheLines.clear();
 
     mDefault.clear();
-
+#ifndef ANDROID_RS_SERIALIZE
     if (mLibrary) {
         FT_Done_FreeType( mLibrary );
         mLibrary = NULL;
     }
+#endif //ANDROID_RS_SERIALIZE
 }
 
+#ifndef ANDROID_RS_SERIALIZE
 bool FontState::CacheTextureLine::fitBitmap(FT_Bitmap_ *bitmap, uint32_t *retOriginX, uint32_t *retOriginY) {
     if ((uint32_t)bitmap->rows > mMaxHeight) {
         return false;
@@ -813,6 +829,7 @@
 
     return false;
 }
+#endif //ANDROID_RS_SERIALIZE
 
 namespace android {
 namespace renderscript {
diff --git a/libs/rs/rsFont.h b/libs/rs/rsFont.h
index d18c0d9..b0e1430 100644
--- a/libs/rs/rsFont.h
+++ b/libs/rs/rsFont.h
@@ -199,8 +199,10 @@
     float mWhiteThreshold;
 
     // Free type library, we only need one copy
+#ifndef ANDROID_RS_SERIALIZE
     FT_LibraryRec_ *mLibrary;
     FT_LibraryRec_ *getLib();
+#endif //ANDROID_RS_SERIALIZE
     Vector<Font*> mActiveFonts;
 
     // Render state for the font
@@ -217,7 +219,9 @@
         return (uint8_t*)mTextTexture->getPtr();
     }
 
+#ifndef ANDROID_RS_SERIALIZE
     bool cacheBitmap(FT_Bitmap_ *bitmap, uint32_t *retOriginX, uint32_t *retOriginY);
+#endif //ANDROID_RS_SERIALIZE
     const Type* getCacheTextureType() {
         return mTextTexture->getType();
     }
diff --git a/libs/rs/rsMesh.cpp b/libs/rs/rsMesh.cpp
index 62e388c..359d09f 100644
--- a/libs/rs/rsMesh.cpp
+++ b/libs/rs/rsMesh.cpp
@@ -161,8 +161,6 @@
     return mesh;
 }
 
-#ifndef ANDROID_RS_SERIALIZE
-
 void Mesh::render(Context *rsc) const {
     for (uint32_t ct = 0; ct < mHal.state.primitivesCount; ct ++) {
         renderPrimitive(rsc, ct);
@@ -255,9 +253,9 @@
 namespace renderscript {
 
 RsMesh rsi_MeshCreate(Context *rsc,
-                      RsAllocation *vtx, uint32_t vtxCount,
-                      RsAllocation *idx, uint32_t idxCount,
-                      uint32_t *primType, uint32_t primTypeCount) {
+                      RsAllocation * vtx, size_t vtxCount,
+                      RsAllocation * idx, size_t idxCount,
+                      uint32_t * primType, size_t primTypeCount) {
     rsAssert(idxCount == primTypeCount);
     Mesh *sm = new Mesh(rsc, vtxCount, idxCount);
     sm->incUserRef();
@@ -309,5 +307,3 @@
         }
     }
 }
-
-#endif
diff --git a/libs/rs/rsProgramFragment.cpp b/libs/rs/rsProgramFragment.cpp
index 0823d82..356ff77 100644
--- a/libs/rs/rsProgramFragment.cpp
+++ b/libs/rs/rsProgramFragment.cpp
@@ -127,8 +127,8 @@
 namespace renderscript {
 
 RsProgramFragment rsi_ProgramFragmentCreate(Context *rsc, const char * shaderText,
-                             uint32_t shaderLength, const uint32_t * params,
-                             uint32_t paramLength) {
+                             size_t shaderLength, const uint32_t * params,
+                             size_t paramLength) {
     ProgramFragment *pf = new ProgramFragment(rsc, shaderText, shaderLength, params, paramLength);
     pf->incUserRef();
     //LOGE("rsi_ProgramFragmentCreate %p", pf);
diff --git a/libs/rs/rsProgramVertex.cpp b/libs/rs/rsProgramVertex.cpp
index e6790cb..058a456 100644
--- a/libs/rs/rsProgramVertex.cpp
+++ b/libs/rs/rsProgramVertex.cpp
@@ -223,8 +223,8 @@
 namespace renderscript {
 
 RsProgramVertex rsi_ProgramVertexCreate(Context *rsc, const char * shaderText,
-                             uint32_t shaderLength, const uint32_t * params,
-                             uint32_t paramLength) {
+                             size_t shaderLength, const uint32_t * params,
+                             size_t paramLength) {
     ProgramVertex *pv = new ProgramVertex(rsc, shaderText, shaderLength, params, paramLength);
     pv->incUserRef();
     return pv;
diff --git a/libs/rs/rsRuntime.h b/libs/rs/rsRuntime.h
index 6d45285..cb962a8 100644
--- a/libs/rs/rsRuntime.h
+++ b/libs/rs/rsRuntime.h
@@ -85,6 +85,21 @@
 void rsrColor(Context *, Script *, float r, float g, float b, float a);
 void rsrFinish(Context *, Script *);
 void rsrAllocationSyncAll(Context *, Script *, Allocation *);
+
+void rsrAllocationCopy1DRange(Context *, Allocation *dstAlloc,
+                              uint32_t dstOff,
+                              uint32_t dstMip,
+                              uint32_t count,
+                              Allocation *srcAlloc,
+                              uint32_t srcOff, uint32_t srcMip);
+void rsrAllocationCopy2DRange(Context *, Allocation *dstAlloc,
+                              uint32_t dstXoff, uint32_t dstYoff,
+                              uint32_t dstMip, uint32_t dstFace,
+                              uint32_t width, uint32_t height,
+                              Allocation *srcAlloc,
+                              uint32_t srcXoff, uint32_t srcYoff,
+                              uint32_t srcMip, uint32_t srcFace);
+
 void rsrClearColor(Context *, Script *, float r, float g, float b, float a);
 void rsrClearDepth(Context *, Script *, float v);
 uint32_t rsrGetWidth(Context *, Script *);
diff --git a/libs/rs/rsScript.cpp b/libs/rs/rsScript.cpp
index 7641cab..f62c72e 100644
--- a/libs/rs/rsScript.cpp
+++ b/libs/rs/rsScript.cpp
@@ -53,7 +53,7 @@
     }
 }
 
-void Script::setVar(uint32_t slot, const void *val, uint32_t len) {
+void Script::setVar(uint32_t slot, const void *val, size_t len) {
     //LOGE("setVar %i %p %i", slot, val, len);
     if (slot >= mHal.info.exportedVariableCount) {
         LOGE("Script::setVar unable to set allocation, invalid slot index");
@@ -82,14 +82,14 @@
     //LOGE("rsi_ScriptBindAllocation %i  %p  %p", slot, a, a->getPtr());
 }
 
-void rsi_ScriptSetTimeZone(Context * rsc, RsScript vs, const char * timeZone, uint32_t length) {
+void rsi_ScriptSetTimeZone(Context * rsc, RsScript vs, const char * timeZone, size_t length) {
     Script *s = static_cast<Script *>(vs);
     s->mEnviroment.mTimeZone = timeZone;
 }
 
 void rsi_ScriptForEach(Context *rsc, RsScript vs, uint32_t slot,
                        RsAllocation vain, RsAllocation vaout,
-                       const void *params, uint32_t paramLen) {
+                       const void *params, size_t paramLen) {
     Script *s = static_cast<Script *>(vs);
     s->runForEach(rsc,
                   static_cast<const Allocation *>(vain), static_cast<Allocation *>(vaout),
@@ -108,7 +108,7 @@
     s->Invoke(rsc, slot, NULL, 0);
 }
 
-void rsi_ScriptInvokeV(Context *rsc, RsScript vs, uint32_t slot, const void *data, uint32_t len) {
+void rsi_ScriptInvokeV(Context *rsc, RsScript vs, uint32_t slot, const void *data, size_t len) {
     Script *s = static_cast<Script *>(vs);
     s->Invoke(rsc, slot, data, len);
 }
@@ -139,7 +139,7 @@
     s->setVar(slot, &value, sizeof(value));
 }
 
-void rsi_ScriptSetVarV(Context *rsc, RsScript vs, uint32_t slot, const void *data, uint32_t len) {
+void rsi_ScriptSetVarV(Context *rsc, RsScript vs, uint32_t slot, const void *data, size_t len) {
     Script *s = static_cast<Script *>(vs);
     s->setVar(slot, data, len);
 }
diff --git a/libs/rs/rsScript.h b/libs/rs/rsScript.h
index 088c8d1..c0324dd 100644
--- a/libs/rs/rsScript.h
+++ b/libs/rs/rsScript.h
@@ -70,7 +70,7 @@
 
     void initSlots();
     void setSlot(uint32_t slot, Allocation *a);
-    void setVar(uint32_t slot, const void *val, uint32_t len);
+    void setVar(uint32_t slot, const void *val, size_t len);
     void setVarObj(uint32_t slot, ObjectBase *val);
 
     virtual void runForEach(Context *rsc,
@@ -80,7 +80,7 @@
                             size_t usrBytes,
                             const RsScriptCall *sc = NULL) = 0;
 
-    virtual void Invoke(Context *rsc, uint32_t slot, const void *data, uint32_t len) = 0;
+    virtual void Invoke(Context *rsc, uint32_t slot, const void *data, size_t len) = 0;
     virtual void setupScript(Context *rsc) = 0;
     virtual uint32_t run(Context *) = 0;
 protected:
diff --git a/libs/rs/rsScriptC.cpp b/libs/rs/rsScriptC.cpp
index 6d0701d..b230bb5 100644
--- a/libs/rs/rsScriptC.cpp
+++ b/libs/rs/rsScriptC.cpp
@@ -19,11 +19,6 @@
 #include "utils/Timers.h"
 #include "utils/StopWatch.h"
 
-#include <GLES/gl.h>
-#include <GLES/glext.h>
-
-#include <bcc/bcc.h>
-
 using namespace android;
 using namespace android::renderscript;
 
@@ -129,7 +124,7 @@
     rsc->mHal.funcs.script.invokeForEach(rsc, this, ain, aout, usr, usrBytes, sc);
 }
 
-void ScriptC::Invoke(Context *rsc, uint32_t slot, const void *data, uint32_t len) {
+void ScriptC::Invoke(Context *rsc, uint32_t slot, const void *data, size_t len) {
     if (slot >= mHal.info.exportedFunctionCount) {
         rsc->setError(RS_ERROR_BAD_SCRIPT, "Calling invoke on bad script");
         return;
@@ -269,7 +264,7 @@
 RsScript rsi_ScriptCCreate(Context *rsc,
                            const char *resName, size_t resName_length,
                            const char *cacheDir, size_t cacheDir_length,
-                           const char *text, uint32_t text_length)
+                           const char *text, size_t text_length)
 {
     ScriptC *s = new ScriptC(rsc);
 
diff --git a/libs/rs/rsScriptC.h b/libs/rs/rsScriptC.h
index 4c85745..5c191d9 100644
--- a/libs/rs/rsScriptC.h
+++ b/libs/rs/rsScriptC.h
@@ -39,7 +39,7 @@
     const Allocation *ptrToAllocation(const void *) const;
 
 
-    virtual void Invoke(Context *rsc, uint32_t slot, const void *data, uint32_t len);
+    virtual void Invoke(Context *rsc, uint32_t slot, const void *data, size_t len);
 
     virtual uint32_t run(Context *);
 
diff --git a/libs/rs/rsScriptC_Lib.cpp b/libs/rs/rsScriptC_Lib.cpp
index 4ee0a3e..ec15bc0 100644
--- a/libs/rs/rsScriptC_Lib.cpp
+++ b/libs/rs/rsScriptC_Lib.cpp
@@ -164,6 +164,29 @@
     a->syncAll(rsc, usage);
 }
 
+void rsrAllocationCopy1DRange(Context *rsc, Allocation *dstAlloc,
+                              uint32_t dstOff,
+                              uint32_t dstMip,
+                              uint32_t count,
+                              Allocation *srcAlloc,
+                              uint32_t srcOff, uint32_t srcMip) {
+    rsi_AllocationCopy2DRange(rsc, dstAlloc, dstOff, 0,
+                              dstMip, 0, count, 1,
+                              srcAlloc, srcOff, 0, srcMip, 0);
+}
+
+void rsrAllocationCopy2DRange(Context *rsc, Allocation *dstAlloc,
+                              uint32_t dstXoff, uint32_t dstYoff,
+                              uint32_t dstMip, uint32_t dstFace,
+                              uint32_t width, uint32_t height,
+                              Allocation *srcAlloc,
+                              uint32_t srcXoff, uint32_t srcYoff,
+                              uint32_t srcMip, uint32_t srcFace) {
+    rsi_AllocationCopy2DRange(rsc, dstAlloc, dstXoff, dstYoff,
+                              dstMip, dstFace, width, height,
+                              srcAlloc, srcXoff, srcYoff, srcMip, srcFace);
+}
+
 const Allocation * rsrGetAllocation(Context *rsc, Script *s, const void *ptr) {
     ScriptC *sc = (ScriptC *)s;
     return sc->ptrToAllocation(ptr);
diff --git a/libs/rs/rsThreadIO.cpp b/libs/rs/rsThreadIO.cpp
index 4429556..ab164c3 100644
--- a/libs/rs/rsThreadIO.cpp
+++ b/libs/rs/rsThreadIO.cpp
@@ -149,7 +149,7 @@
         mToClientSocket.read(&mLastClientHeader, sizeof(mLastClientHeader));
     } else {
         size_t bytesData = 0;
-        const uint32_t *d = (const uint32_t *)mToClient.get(&mLastClientHeader.cmdID, &bytesData);
+        const uint32_t *d = (const uint32_t *)mToClient.get(&mLastClientHeader.cmdID, (uint32_t*)&bytesData);
         if (bytesData >= sizeof(uint32_t)) {
             mLastClientHeader.userID = d[0];
             mLastClientHeader.bytes = bytesData - sizeof(uint32_t);
diff --git a/libs/rs/rs_hal.h b/libs/rs/rs_hal.h
index 44c7e71..928dca5 100644
--- a/libs/rs/rs_hal.h
+++ b/libs/rs/rs_hal.h
@@ -18,7 +18,6 @@
 #define RS_HAL_H
 
 #include <RenderScriptDefines.h>
-#include <ui/egl/android_natives.h>
 
 namespace android {
 namespace renderscript {
@@ -113,6 +112,27 @@
                        uint32_t lod, RsAllocationCubemapFace face,
                        uint32_t w, uint32_t h, uint32_t d, const void *data, uint32_t sizeBytes);
 
+        // Allocation to allocation copies
+        void (*allocData1D)(const Context *rsc,
+                            const Allocation *dstAlloc,
+                            uint32_t dstXoff, uint32_t dstLod, uint32_t count,
+                            const Allocation *srcAlloc, uint32_t srcXoff, uint32_t srcLod);
+        void (*allocData2D)(const Context *rsc,
+                            const Allocation *dstAlloc,
+                            uint32_t dstXoff, uint32_t dstYoff, uint32_t dstLod,
+                            RsAllocationCubemapFace dstFace, uint32_t w, uint32_t h,
+                            const Allocation *srcAlloc,
+                            uint32_t srcXoff, uint32_t srcYoff, uint32_t srcLod,
+                            RsAllocationCubemapFace srcFace);
+        void (*allocData3D)(const Context *rsc,
+                            const Allocation *dstAlloc,
+                            uint32_t dstXoff, uint32_t dstYoff, uint32_t dstZoff,
+                            uint32_t dstLod, RsAllocationCubemapFace dstFace,
+                            uint32_t w, uint32_t h, uint32_t d,
+                            const Allocation *srcAlloc,
+                            uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff,
+                            uint32_t srcLod, RsAllocationCubemapFace srcFace);
+
         void (*elementData1D)(const Context *rsc, const Allocation *alloc, uint32_t x,
                               const void *data, uint32_t elementOff, uint32_t sizeBytes);
         void (*elementData2D)(const Context *rsc, const Allocation *alloc, uint32_t x, uint32_t y,
diff --git a/libs/rs/scriptc/rs_graphics.rsh b/libs/rs/scriptc/rs_graphics.rsh
index d53bc95..9a8a4e6 100644
--- a/libs/rs/scriptc/rs_graphics.rsh
+++ b/libs/rs/scriptc/rs_graphics.rsh
@@ -144,6 +144,17 @@
     rsgAllocationSyncAll(rs_allocation alloc);
 
 /**
+ * Sync the contents of an allocation from memory space
+ * specified by source.
+ *
+ * @param alloc
+ * @param source
+ */
+extern void __attribute__((overloadable))
+    rsgAllocationSyncAll(rs_allocation alloc,
+                         rs_allocation_usage_type source);
+
+/**
  * Low performance utility function for drawing a simple rectangle.  Not
  * intended for drawing large quantities of geometry.
  *
diff --git a/libs/rs/scriptc/rs_math.rsh b/libs/rs/scriptc/rs_math.rsh
index 6e3cfdb..584317e 100644
--- a/libs/rs/scriptc/rs_math.rsh
+++ b/libs/rs/scriptc/rs_math.rsh
@@ -136,6 +136,58 @@
 extern uint32_t __attribute__((overloadable))
     rsAllocationGetDimFaces(rs_allocation);
 
+/**
+ * Copy part of an allocation from another allocation.
+ *
+ * @param dstAlloc Allocation to copy data into.
+ * @param dstOff The offset of the first element to be copied in
+ *               the destination allocation.
+ * @param dstMip Mip level in the destination allocation.
+ * @param count The number of elements to be copied.
+ * @param srcAlloc The source data allocation.
+ * @param srcOff The offset of the first element in data to be
+ *               copied in the source allocation.
+ * @param srcMip Mip level in the source allocation.
+ */
+extern void __attribute__((overloadable))
+    rsAllocationCopy1DRange(rs_allocation dstAlloc,
+                            uint32_t dstOff, uint32_t dstMip,
+                            uint32_t count,
+                            rs_allocation srcAlloc,
+                            uint32_t srcOff, uint32_t srcMip);
+
+/**
+ * Copy a rectangular region into the allocation from another
+ * allocation.
+ *
+ * @param dstAlloc allocation to copy data into.
+ * @param dstXoff X offset of the region to update in the
+ *                destination allocation.
+ * @param dstYoff Y offset of the region to update in the
+ *                destination allocation.
+ * @param dstMip Mip level in the destination allocation.
+ * @param dstFace Cubemap face of the destination allocation,
+ *                ignored for allocations that aren't cubemaps.
+ * @param width Width of the incoming region to update.
+ * @param height Height of the incoming region to update.
+ * @param srcAlloc The source data allocation.
+ * @param srcXoff X offset in data of the source allocation.
+ * @param srcYoff Y offset in data of the source allocation.
+ * @param srcMip Mip level in the source allocation.
+ * @param srcFace Cubemap face of the source allocation,
+ *                ignored for allocations that aren't cubemaps.
+ */
+extern void __attribute__((overloadable))
+    rsAllocationCopy2DRange(rs_allocation dstAlloc,
+                            uint32_t dstXoff, uint32_t dstYoff,
+                            uint32_t dstMip,
+                            rs_allocation_cubemap_face dstFace,
+                            uint32_t width, uint32_t height,
+                            rs_allocation srcAlloc,
+                            uint32_t srcXoff, uint32_t srcYoff,
+                            uint32_t srcMip,
+                            rs_allocation_cubemap_face srcFace);
+
 // Extract a single element from an allocation.
 extern const void * __attribute__((overloadable))
     rsGetElementAt(rs_allocation, uint32_t x);
diff --git a/libs/rs/scriptc/rs_types.rsh b/libs/rs/scriptc/rs_types.rsh
index d9f4b4b..536d1f0 100644
--- a/libs/rs/scriptc/rs_types.rsh
+++ b/libs/rs/scriptc/rs_types.rsh
@@ -88,4 +88,21 @@
 
 #define RS_PACKED __attribute__((packed, aligned(4)))
 
+typedef enum {
+    RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X = 0,
+    RS_ALLOCATION_CUBEMAP_FACE_NEGATIVE_X = 1,
+    RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_Y = 2,
+    RS_ALLOCATION_CUBEMAP_FACE_NEGATIVE_Y = 3,
+    RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_Z = 4,
+    RS_ALLOCATION_CUBEMAP_FACE_NEGATIVE_Z = 5
+} rs_allocation_cubemap_face;
+
+typedef enum {
+    RS_ALLOCATION_USAGE_SCRIPT = 0x0001,
+    RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE = 0x0002,
+    RS_ALLOCATION_USAGE_GRAPHICS_VERTEX = 0x0004,
+    RS_ALLOCATION_USAGE_GRAPHICS_CONSTANTS = 0x0008,
+    RS_ALLOCATION_USAGE_GRAPHICS_RENDER_TARGET = 0x0010
+} rs_allocation_usage_type;
+
 #endif
diff --git a/libs/ui/Input.cpp b/libs/ui/Input.cpp
index 1ba38a7..0af7f80 100644
--- a/libs/ui/Input.cpp
+++ b/libs/ui/Input.cpp
@@ -13,6 +13,10 @@
 // Log debug messages about velocity tracking.
 #define DEBUG_VELOCITY 0
 
+// Log debug messages about acceleration.
+#define DEBUG_ACCELERATION 0
+
+
 #include <stdlib.h>
 #include <unistd.h>
 #include <ctype.h>
@@ -20,6 +24,7 @@
 #include <ui/Input.h>
 
 #include <math.h>
+#include <limits.h>
 
 #ifdef HAVE_ANDROID_OS
 #include <binder/Parcel.h>
@@ -693,6 +698,10 @@
 
 // --- VelocityTracker ---
 
+const uint32_t VelocityTracker::HISTORY_SIZE;
+const nsecs_t VelocityTracker::MAX_AGE;
+const nsecs_t VelocityTracker::MIN_DURATION;
+
 VelocityTracker::VelocityTracker() {
     clear();
 }
@@ -881,14 +890,6 @@
 
         // Make sure we used at least one sample.
         if (samplesUsed != 0) {
-            // Scale the velocity linearly if the window of samples is small.
-            nsecs_t totalDuration = newestMovement.eventTime - oldestMovement.eventTime;
-            if (totalDuration < MIN_WINDOW) {
-                float scale = float(totalDuration) / float(MIN_WINDOW);
-                accumVx *= scale;
-                accumVy *= scale;
-            }
-
             *outVx = accumVx;
             *outVy = accumVy;
             return true;
@@ -902,6 +903,85 @@
 }
 
 
+// --- VelocityControl ---
+
+const nsecs_t VelocityControl::STOP_TIME;
+
+VelocityControl::VelocityControl() {
+    reset();
+}
+
+void VelocityControl::setParameters(const VelocityControlParameters& parameters) {
+    mParameters = parameters;
+    reset();
+}
+
+void VelocityControl::reset() {
+    mLastMovementTime = LLONG_MIN;
+    mRawPosition.x = 0;
+    mRawPosition.y = 0;
+    mVelocityTracker.clear();
+}
+
+void VelocityControl::move(nsecs_t eventTime, float* deltaX, float* deltaY) {
+    if ((deltaX && *deltaX) || (deltaY && *deltaY)) {
+        if (eventTime >= mLastMovementTime + STOP_TIME) {
+#if DEBUG_ACCELERATION
+            LOGD("VelocityControl: stopped, last movement was %0.3fms ago",
+                    (eventTime - mLastMovementTime) * 0.000001f);
+#endif
+            reset();
+        }
+
+        mLastMovementTime = eventTime;
+        if (deltaX) {
+            mRawPosition.x += *deltaX;
+        }
+        if (deltaY) {
+            mRawPosition.y += *deltaY;
+        }
+        mVelocityTracker.addMovement(eventTime, BitSet32(BitSet32::valueForBit(0)), &mRawPosition);
+
+        float vx, vy;
+        float scale = mParameters.scale;
+        if (mVelocityTracker.getVelocity(0, &vx, &vy)) {
+            float speed = hypotf(vx, vy) * scale;
+            if (speed >= mParameters.highThreshold) {
+                // Apply full acceleration above the high speed threshold.
+                scale *= mParameters.acceleration;
+            } else if (speed > mParameters.lowThreshold) {
+                // Linearly interpolate the acceleration to apply between the low and high
+                // speed thresholds.
+                scale *= 1 + (speed - mParameters.lowThreshold)
+                        / (mParameters.highThreshold - mParameters.lowThreshold)
+                        * (mParameters.acceleration - 1);
+            }
+
+#if DEBUG_ACCELERATION
+            LOGD("VelocityControl(%0.3f, %0.3f, %0.3f, %0.3f): "
+                    "vx=%0.3f, vy=%0.3f, speed=%0.3f, accel=%0.3f",
+                    mParameters.scale, mParameters.lowThreshold, mParameters.highThreshold,
+                    mParameters.acceleration,
+                    vx, vy, speed, scale / mParameters.scale);
+#endif
+        } else {
+#if DEBUG_ACCELERATION
+            LOGD("VelocityControl(%0.3f, %0.3f, %0.3f, %0.3f): unknown velocity",
+                    mParameters.scale, mParameters.lowThreshold, mParameters.highThreshold,
+                    mParameters.acceleration);
+#endif
+        }
+
+        if (deltaX) {
+            *deltaX *= scale;
+        }
+        if (deltaY) {
+            *deltaY *= scale;
+        }
+    }
+}
+
+
 // --- InputDeviceInfo ---
 
 InputDeviceInfo::InputDeviceInfo() {
diff --git a/libs/utils/Android.mk b/libs/utils/Android.mk
index e8d40ba..093189c 100644
--- a/libs/utils/Android.mk
+++ b/libs/utils/Android.mk
@@ -21,6 +21,7 @@
 	Asset.cpp \
 	AssetDir.cpp \
 	AssetManager.cpp \
+	BlobCache.cpp \
 	BufferedTextOutput.cpp \
 	CallStack.cpp \
 	Debug.cpp \
diff --git a/libs/utils/BackupHelpers.cpp b/libs/utils/BackupHelpers.cpp
index e15875f..87549fe 100644
--- a/libs/utils/BackupHelpers.cpp
+++ b/libs/utils/BackupHelpers.cpp
@@ -503,6 +503,16 @@
         needExtended = true;
     }
 
+    // Non-7bit-clean path also means needing pax extended format
+    if (!needExtended) {
+        for (size_t i = 0; i < filepath.length(); i++) {
+            if ((filepath[i] & 0x80) != 0) {
+                needExtended = true;
+                break;
+            }
+        }
+    }
+
     int err = 0;
     struct stat64 s;
     if (lstat64(filepath.string(), &s) != 0) {
@@ -515,6 +525,7 @@
     String8 prefix;
 
     const int isdir = S_ISDIR(s.st_mode);
+    if (isdir) s.st_size = 0;   // directories get no actual data in the tar stream
 
     // !!! TODO: use mmap when possible to avoid churning the buffer cache
     // !!! TODO: this will break with symlinks; need to use readlink(2)
diff --git a/libs/utils/BlobCache.cpp b/libs/utils/BlobCache.cpp
new file mode 100644
index 0000000..590576a
--- /dev/null
+++ b/libs/utils/BlobCache.cpp
@@ -0,0 +1,244 @@
+/*
+ ** Copyright 2011, The Android Open Source Project
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ **     http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+#define LOG_TAG "BlobCache"
+//#define LOG_NDEBUG 0
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <utils/BlobCache.h>
+#include <utils/Log.h>
+
+namespace android {
+
+BlobCache::BlobCache(size_t maxKeySize, size_t maxValueSize, size_t maxTotalSize):
+        mMaxKeySize(maxKeySize),
+        mMaxValueSize(maxValueSize),
+        mMaxTotalSize(maxTotalSize),
+        mTotalSize(0) {
+    nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
+#ifdef _WIN32
+    srand(now);
+#else
+    mRandState[0] = (now >> 0) & 0xFFFF;
+    mRandState[1] = (now >> 16) & 0xFFFF;
+    mRandState[2] = (now >> 32) & 0xFFFF;
+#endif
+    LOGV("initializing random seed using %lld", now);
+}
+
+void BlobCache::set(const void* key, size_t keySize, const void* value,
+        size_t valueSize) {
+    if (mMaxKeySize < keySize) {
+        LOGV("set: not caching because the key is too large: %d (limit: %d)",
+                keySize, mMaxKeySize);
+        return;
+    }
+    if (mMaxValueSize < valueSize) {
+        LOGV("set: not caching because the value is too large: %d (limit: %d)",
+                valueSize, mMaxValueSize);
+        return;
+    }
+    if (mMaxTotalSize < keySize + valueSize) {
+        LOGV("set: not caching because the combined key/value size is too "
+                "large: %d (limit: %d)", keySize + valueSize, mMaxTotalSize);
+        return;
+    }
+    if (keySize == 0) {
+        LOGW("set: not caching because keySize is 0");
+        return;
+    }
+    if (valueSize <= 0) {
+        LOGW("set: not caching because valueSize is 0");
+        return;
+    }
+
+    Mutex::Autolock lock(mMutex);
+    sp<Blob> dummyKey(new Blob(key, keySize, false));
+    CacheEntry dummyEntry(dummyKey, NULL);
+
+    while (true) {
+
+        ssize_t index = mCacheEntries.indexOf(dummyEntry);
+        if (index < 0) {
+            // Create a new cache entry.
+            sp<Blob> keyBlob(new Blob(key, keySize, true));
+            sp<Blob> valueBlob(new Blob(value, valueSize, true));
+            size_t newTotalSize = mTotalSize + keySize + valueSize;
+            if (mMaxTotalSize < newTotalSize) {
+                if (isCleanable()) {
+                    // Clean the cache and try again.
+                    clean();
+                    continue;
+                } else {
+                    LOGV("set: not caching new key/value pair because the "
+                            "total cache size limit would be exceeded: %d "
+                            "(limit: %d)",
+                            keySize + valueSize, mMaxTotalSize);
+                    break;
+                }
+            }
+            mCacheEntries.add(CacheEntry(keyBlob, valueBlob));
+            mTotalSize = newTotalSize;
+            LOGV("set: created new cache entry with %d byte key and %d byte value",
+                    keySize, valueSize);
+        } else {
+            // Update the existing cache entry.
+            sp<Blob> valueBlob(new Blob(value, valueSize, true));
+            sp<Blob> oldValueBlob(mCacheEntries[index].getValue());
+            size_t newTotalSize = mTotalSize + valueSize - oldValueBlob->getSize();
+            if (mMaxTotalSize < newTotalSize) {
+                if (isCleanable()) {
+                    // Clean the cache and try again.
+                    clean();
+                    continue;
+                } else {
+                    LOGV("set: not caching new value because the total cache "
+                            "size limit would be exceeded: %d (limit: %d)",
+                            keySize + valueSize, mMaxTotalSize);
+                    break;
+                }
+            }
+            mCacheEntries.editItemAt(index).setValue(valueBlob);
+            mTotalSize = newTotalSize;
+            LOGV("set: updated existing cache entry with %d byte key and %d byte "
+                    "value", keySize, valueSize);
+        }
+        break;
+    }
+}
+
+size_t BlobCache::get(const void* key, size_t keySize, void* value,
+        size_t valueSize) {
+    if (mMaxKeySize < keySize) {
+        LOGV("get: not searching because the key is too large: %d (limit %d)",
+                keySize, mMaxKeySize);
+        return 0;
+    }
+    Mutex::Autolock lock(mMutex);
+    sp<Blob> dummyKey(new Blob(key, keySize, false));
+    CacheEntry dummyEntry(dummyKey, NULL);
+    ssize_t index = mCacheEntries.indexOf(dummyEntry);
+    if (index < 0) {
+        LOGV("get: no cache entry found for key of size %d", keySize);
+        return 0;
+    }
+
+    // The key was found. Return the value if the caller's buffer is large
+    // enough.
+    sp<Blob> valueBlob(mCacheEntries[index].getValue());
+    size_t valueBlobSize = valueBlob->getSize();
+    if (valueBlobSize <= valueSize) {
+        LOGV("get: copying %d bytes to caller's buffer", valueBlobSize);
+        memcpy(value, valueBlob->getData(), valueBlobSize);
+    } else {
+        LOGV("get: caller's buffer is too small for value: %d (needs %d)",
+                valueSize, valueBlobSize);
+    }
+    return valueBlobSize;
+}
+
+long int BlobCache::blob_random() {
+#ifdef _WIN32
+    return rand();
+#else
+    return nrand48(mRandState);
+#endif
+}
+
+void BlobCache::clean() {
+    // Remove a random cache entry until the total cache size gets below half
+    // the maximum total cache size.
+    while (mTotalSize > mMaxTotalSize / 2) {
+        size_t i = size_t(blob_random() % (mCacheEntries.size()));
+        const CacheEntry& entry(mCacheEntries[i]);
+        mTotalSize -= entry.getKey()->getSize() + entry.getValue()->getSize();
+        mCacheEntries.removeAt(i);
+    }
+}
+
+bool BlobCache::isCleanable() const {
+    return mTotalSize > mMaxTotalSize / 2;
+}
+
+BlobCache::Blob::Blob(const void* data, size_t size, bool copyData):
+        mData(copyData ? malloc(size) : data),
+        mSize(size),
+        mOwnsData(copyData) {
+    if (copyData) {
+        memcpy(const_cast<void*>(mData), data, size);
+    }
+}
+
+BlobCache::Blob::~Blob() {
+    if (mOwnsData) {
+        free(const_cast<void*>(mData));
+    }
+}
+
+bool BlobCache::Blob::operator<(const Blob& rhs) const {
+    if (mSize == rhs.mSize) {
+        return memcmp(mData, rhs.mData, mSize) < 0;
+    } else {
+        return mSize < rhs.mSize;
+    }
+}
+
+const void* BlobCache::Blob::getData() const {
+    return mData;
+}
+
+size_t BlobCache::Blob::getSize() const {
+    return mSize;
+}
+
+BlobCache::CacheEntry::CacheEntry() {
+}
+
+BlobCache::CacheEntry::CacheEntry(const sp<Blob>& key, const sp<Blob>& value):
+        mKey(key),
+        mValue(value) {
+}
+
+BlobCache::CacheEntry::CacheEntry(const CacheEntry& ce):
+        mKey(ce.mKey),
+        mValue(ce.mValue) {
+}
+
+bool BlobCache::CacheEntry::operator<(const CacheEntry& rhs) const {
+    return *mKey < *rhs.mKey;
+}
+
+const BlobCache::CacheEntry& BlobCache::CacheEntry::operator=(const CacheEntry& rhs) {
+    mKey = rhs.mKey;
+    mValue = rhs.mValue;
+    return *this;
+}
+
+sp<BlobCache::Blob> BlobCache::CacheEntry::getKey() const {
+    return mKey;
+}
+
+sp<BlobCache::Blob> BlobCache::CacheEntry::getValue() const {
+    return mValue;
+}
+
+void BlobCache::CacheEntry::setValue(const sp<Blob>& value) {
+    mValue = value;
+}
+
+} // namespace android
diff --git a/libs/utils/RefBase.cpp b/libs/utils/RefBase.cpp
index dd0052a..8db20095 100644
--- a/libs/utils/RefBase.cpp
+++ b/libs/utils/RefBase.cpp
@@ -49,6 +49,11 @@
 
 // ---------------------------------------------------------------------------
 
+RefBase::Destroyer::~Destroyer() {
+}
+
+// ---------------------------------------------------------------------------
+
 class RefBase::weakref_impl : public RefBase::weakref_type
 {
 public:
@@ -56,7 +61,7 @@
     volatile int32_t    mWeak;
     RefBase* const      mBase;
     volatile int32_t    mFlags;
-
+    Destroyer*          mDestroyer;
 
 #if !DEBUG_REFS
 
@@ -65,6 +70,7 @@
         , mWeak(0)
         , mBase(base)
         , mFlags(0)
+        , mDestroyer(0)
     {
     }
 
@@ -345,10 +351,6 @@
     const_cast<RefBase*>(this)->onFirstRef();
 }
 
-void RefBase::destroy() const {
-    delete this;
-}
-
 void RefBase::decStrong(const void* id) const
 {
     weakref_impl* const refs = mRefs;
@@ -361,7 +363,11 @@
     if (c == 1) {
         const_cast<RefBase*>(this)->onLastStrongRef(id);
         if ((refs->mFlags&OBJECT_LIFETIME_WEAK) != OBJECT_LIFETIME_WEAK) {
-            destroy();
+            if (refs->mDestroyer) {
+                refs->mDestroyer->destroy(this);
+            } else {
+                delete this;
+            }
         }
     }
     refs->decWeak(id);
@@ -394,7 +400,9 @@
     return mRefs->mStrong;
 }
 
-
+void RefBase::setDestroyer(RefBase::Destroyer* destroyer) {
+    mRefs->mDestroyer = destroyer;
+}
 
 RefBase* RefBase::weakref_type::refBase() const
 {
@@ -418,18 +426,28 @@
     if (c != 1) return;
     
     if ((impl->mFlags&OBJECT_LIFETIME_WEAK) != OBJECT_LIFETIME_WEAK) {
-        if (impl->mStrong == INITIAL_STRONG_VALUE)
-            if (impl->mBase)
-                impl->mBase->destroy();
-        else {
+        if (impl->mStrong == INITIAL_STRONG_VALUE) {
+            if (impl->mBase) {
+                if (impl->mDestroyer) {
+                    impl->mDestroyer->destroy(impl->mBase);
+                } else {
+                    delete impl->mBase;
+                }
+            }
+        } else {
             // LOGV("Freeing refs %p of old RefBase %p\n", this, impl->mBase);
             delete impl;
         }
     } else {
         impl->mBase->onLastWeakRef(id);
         if ((impl->mFlags&OBJECT_LIFETIME_FOREVER) != OBJECT_LIFETIME_FOREVER) {
-            if (impl->mBase)
-                impl->mBase->destroy();
+            if (impl->mBase) {
+                if (impl->mDestroyer) {
+                    impl->mDestroyer->destroy(impl->mBase);
+                } else {
+                    delete impl->mBase;
+                }
+            }
         }
     }
 }
@@ -551,8 +569,10 @@
 
 RefBase::~RefBase()
 {
-    if (mRefs->mWeak == 0) {
-        delete mRefs;
+    if ((mRefs->mFlags & OBJECT_LIFETIME_WEAK) == OBJECT_LIFETIME_WEAK) {
+        if (mRefs->mWeak == 0) {
+            delete mRefs;
+        }
     }
 }
 
diff --git a/libs/utils/ResourceTypes.cpp b/libs/utils/ResourceTypes.cpp
index 4a6a3db..cb6c246 100644
--- a/libs/utils/ResourceTypes.cpp
+++ b/libs/utils/ResourceTypes.cpp
@@ -2663,6 +2663,9 @@
                     goto nope;
                 }
             }
+            if (outTypeSpecFlags) {
+                *outTypeSpecFlags = ResTable_typeSpec::SPEC_PUBLIC;
+            }
             return m->id;
 nope:
             ;
@@ -2677,6 +2680,9 @@
                          index);
                     return 0;
                 }
+                if (outTypeSpecFlags) {
+                    *outTypeSpecFlags = ResTable_typeSpec::SPEC_PUBLIC;
+                }
                 return  Res_MAKEARRAY(index);
             }
         }
@@ -2687,6 +2693,8 @@
         return 0;
     }
 
+    bool fakePublic = false;
+
     // Figure out the package and type we are looking in...
 
     const char16_t* packageEnd = NULL;
@@ -2698,7 +2706,13 @@
         else if (*p == '/') typeEnd = p;
         p++;
     }
-    if (*name == '@') name++;
+    if (*name == '@') {
+        name++;
+        if (*name == '*') {
+            fakePublic = true;
+            name++;
+        }
+    }
     if (name >= nameEnd) {
         return 0;
     }
@@ -2803,6 +2817,9 @@
                 if (dtohl(entry->key.index) == (size_t)ei) {
                     if (outTypeSpecFlags) {
                         *outTypeSpecFlags = typeConfigs->typeSpecFlags[i];
+                        if (fakePublic) {
+                            *outTypeSpecFlags |= ResTable_typeSpec::SPEC_PUBLIC;
+                        }
                     }
                     return Res_MAKEID(group->id-1, ti, i);
                 }
@@ -2819,7 +2836,8 @@
                                  String16* outName,
                                  const String16* defType,
                                  const String16* defPackage,
-                                 const char** outErrorMsg)
+                                 const char** outErrorMsg,
+                                 bool* outPublicOnly)
 {
     const char16_t* packageEnd = NULL;
     const char16_t* typeEnd = NULL;
@@ -2836,6 +2854,16 @@
     p = refStr;
     if (*p == '@') p++;
 
+    if (outPublicOnly != NULL) {
+        *outPublicOnly = true;
+    }
+    if (*p == '*') {
+        p++;
+        if (outPublicOnly != NULL) {
+            *outPublicOnly = false;
+        }
+    }
+
     if (packageEnd) {
         *outPackage = String16(p, packageEnd-p);
         p = packageEnd+1;
diff --git a/libs/utils/StreamingZipInflater.cpp b/libs/utils/StreamingZipInflater.cpp
index 5a162cc..00498bd 100644
--- a/libs/utils/StreamingZipInflater.cpp
+++ b/libs/utils/StreamingZipInflater.cpp
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#define LOG_NDEBUG 1
+//#define LOG_NDEBUG 0
 #define LOG_TAG "szipinf"
 #include <utils/Log.h>
 
@@ -77,7 +77,7 @@
 }
 
 void StreamingZipInflater::initInflateState() {
-    LOGD("Initializing inflate state");
+    LOGV("Initializing inflate state");
 
     memset(&mInflateState, 0, sizeof(mInflateState));
     mInflateState.zalloc = Z_NULL;
@@ -152,13 +152,13 @@
             mInflateState.avail_out = mOutBufSize;
 
             /*
-            LOGD("Inflating to outbuf: avail_in=%u avail_out=%u next_in=%p next_out=%p",
+            LOGV("Inflating to outbuf: avail_in=%u avail_out=%u next_in=%p next_out=%p",
                     mInflateState.avail_in, mInflateState.avail_out,
                     mInflateState.next_in, mInflateState.next_out);
             */
             int result = Z_OK;
             if (mStreamNeedsInit) {
-                LOGD("Initializing zlib to inflate");
+                LOGV("Initializing zlib to inflate");
                 result = inflateInit2(&mInflateState, -MAX_WBITS);
                 mStreamNeedsInit = false;
             }
@@ -192,7 +192,7 @@
         size_t toRead = min_of(mInBufSize, mInTotalSize - mInNextChunkOffset);
         if (toRead > 0) {
             ssize_t didRead = ::read(mFd, mInBuf, toRead);
-            //LOGD("Reading input chunk, size %08x didread %08x", toRead, didRead);
+            //LOGV("Reading input chunk, size %08x didread %08x", toRead, didRead);
             if (didRead < 0) {
                 // TODO: error
                 LOGE("Error reading asset data");
diff --git a/libs/utils/Threads.cpp b/libs/utils/Threads.cpp
index 8b5da0e..15bb1d2 100644
--- a/libs/utils/Threads.cpp
+++ b/libs/utils/Threads.cpp
@@ -168,6 +168,9 @@
         return 0;
     }
 
+    // Note that *threadID is directly available to the parent only, as it is
+    // assigned after the child starts.  Use memory barrier / lock if the child
+    // or other threads also need access.
     if (threadId != NULL) {
         *threadId = (android_thread_id_t)thread; // XXX: this is not portable
     }
@@ -332,10 +335,17 @@
 
     pthread_once(&gDoSchedulingGroupOnce, checkDoSchedulingGroup);
     if (gDoSchedulingGroup) {
+        // set_sched_policy does not support tid == 0
+        int policy_tid;
+        if (tid == 0) {
+            policy_tid = androidGetTid();
+        } else {
+            policy_tid = tid;
+        }
         if (pri >= ANDROID_PRIORITY_BACKGROUND) {
-            rc = set_sched_policy(tid, SP_BACKGROUND);
+            rc = set_sched_policy(policy_tid, SP_BACKGROUND);
         } else if (getpriority(PRIO_PROCESS, tid) >= ANDROID_PRIORITY_BACKGROUND) {
-            rc = set_sched_policy(tid, SP_FOREGROUND);
+            rc = set_sched_policy(policy_tid, SP_FOREGROUND);
         }
     }
 
@@ -718,7 +728,6 @@
         res = androidCreateRawThreadEtc(_threadLoop,
                 this, name, priority, stack, &mThread);
     }
-    // The new thread wakes up at _threadLoop, but immediately blocks on mLock
     
     if (res == false) {
         mStatus = UNKNOWN_ERROR;   // something happened!
@@ -742,11 +751,6 @@
 {
     Thread* const self = static_cast<Thread*>(user);
 
-    // force a memory barrier before reading any fields, in particular mHoldSelf
-    {
-    Mutex::Autolock _l(self->mLock);
-    }
-
     sp<Thread> strong(self->mHoldSelf);
     wp<Thread> weak(strong);
     self->mHoldSelf.clear();
@@ -816,6 +820,7 @@
 
 status_t Thread::requestExitAndWait()
 {
+    Mutex::Autolock _l(mLock);
     if (mThread == getThreadId()) {
         LOGW(
         "Thread (this=%p): don't call waitForExit() from this "
@@ -825,9 +830,8 @@
         return WOULD_BLOCK;
     }
     
-    requestExit();
+    mExitPending = true;
 
-    Mutex::Autolock _l(mLock);
     while (mRunning == true) {
         mThreadExitedCondition.wait(mLock);
     }
diff --git a/libs/utils/tests/Android.mk b/libs/utils/tests/Android.mk
index 72d4876..87ad98e 100644
--- a/libs/utils/tests/Android.mk
+++ b/libs/utils/tests/Android.mk
@@ -6,6 +6,7 @@
 
 # Build the unit tests.
 test_src_files := \
+	BlobCache_test.cpp \
 	ObbFile_test.cpp \
 	Looper_test.cpp \
 	String8_test.cpp \
diff --git a/libs/utils/tests/BlobCache_test.cpp b/libs/utils/tests/BlobCache_test.cpp
new file mode 100644
index 0000000..653ea5e
--- /dev/null
+++ b/libs/utils/tests/BlobCache_test.cpp
@@ -0,0 +1,257 @@
+/*
+ ** Copyright 2011, The Android Open Source Project
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ **     http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include <utils/BlobCache.h>
+
+namespace android {
+
+class BlobCacheTest : public ::testing::Test {
+protected:
+    enum {
+        MAX_KEY_SIZE = 6,
+        MAX_VALUE_SIZE = 8,
+        MAX_TOTAL_SIZE = 13,
+    };
+
+    virtual void SetUp() {
+        mBC = new BlobCache(MAX_KEY_SIZE, MAX_VALUE_SIZE, MAX_TOTAL_SIZE);
+    }
+
+    virtual void TearDown() {
+        mBC.clear();
+    }
+
+    sp<BlobCache> mBC;
+};
+
+TEST_F(BlobCacheTest, CacheSingleValueSucceeds) {
+    char buf[4] = { 0xee, 0xee, 0xee, 0xee };
+    mBC->set("abcd", 4, "efgh", 4);
+    ASSERT_EQ(size_t(4), mBC->get("abcd", 4, buf, 4));
+    ASSERT_EQ('e', buf[0]);
+    ASSERT_EQ('f', buf[1]);
+    ASSERT_EQ('g', buf[2]);
+    ASSERT_EQ('h', buf[3]);
+}
+
+TEST_F(BlobCacheTest, CacheTwoValuesSucceeds) {
+    char buf[2] = { 0xee, 0xee };
+    mBC->set("ab", 2, "cd", 2);
+    mBC->set("ef", 2, "gh", 2);
+    ASSERT_EQ(size_t(2), mBC->get("ab", 2, buf, 2));
+    ASSERT_EQ('c', buf[0]);
+    ASSERT_EQ('d', buf[1]);
+    ASSERT_EQ(size_t(2), mBC->get("ef", 2, buf, 2));
+    ASSERT_EQ('g', buf[0]);
+    ASSERT_EQ('h', buf[1]);
+}
+
+TEST_F(BlobCacheTest, GetOnlyWritesInsideBounds) {
+    char buf[6] = { 0xee, 0xee, 0xee, 0xee, 0xee, 0xee };
+    mBC->set("abcd", 4, "efgh", 4);
+    ASSERT_EQ(size_t(4), mBC->get("abcd", 4, buf+1, 4));
+    ASSERT_EQ(0xee, buf[0]);
+    ASSERT_EQ('e', buf[1]);
+    ASSERT_EQ('f', buf[2]);
+    ASSERT_EQ('g', buf[3]);
+    ASSERT_EQ('h', buf[4]);
+    ASSERT_EQ(0xee, buf[5]);
+}
+
+TEST_F(BlobCacheTest, GetOnlyWritesIfBufferIsLargeEnough) {
+    char buf[3] = { 0xee, 0xee, 0xee };
+    mBC->set("abcd", 4, "efgh", 4);
+    ASSERT_EQ(size_t(4), mBC->get("abcd", 4, buf, 3));
+    ASSERT_EQ(0xee, buf[0]);
+    ASSERT_EQ(0xee, buf[1]);
+    ASSERT_EQ(0xee, buf[2]);
+}
+
+TEST_F(BlobCacheTest, GetDoesntAccessNullBuffer) {
+    mBC->set("abcd", 4, "efgh", 4);
+    ASSERT_EQ(size_t(4), mBC->get("abcd", 4, NULL, 0));
+}
+
+TEST_F(BlobCacheTest, MultipleSetsCacheLatestValue) {
+    char buf[4] = { 0xee, 0xee, 0xee, 0xee };
+    mBC->set("abcd", 4, "efgh", 4);
+    mBC->set("abcd", 4, "ijkl", 4);
+    ASSERT_EQ(size_t(4), mBC->get("abcd", 4, buf, 4));
+    ASSERT_EQ('i', buf[0]);
+    ASSERT_EQ('j', buf[1]);
+    ASSERT_EQ('k', buf[2]);
+    ASSERT_EQ('l', buf[3]);
+}
+
+TEST_F(BlobCacheTest, SecondSetKeepsFirstValueIfTooLarge) {
+    char buf[MAX_VALUE_SIZE+1] = { 0xee, 0xee, 0xee, 0xee };
+    mBC->set("abcd", 4, "efgh", 4);
+    mBC->set("abcd", 4, buf, MAX_VALUE_SIZE+1);
+    ASSERT_EQ(size_t(4), mBC->get("abcd", 4, buf, 4));
+    ASSERT_EQ('e', buf[0]);
+    ASSERT_EQ('f', buf[1]);
+    ASSERT_EQ('g', buf[2]);
+    ASSERT_EQ('h', buf[3]);
+}
+
+TEST_F(BlobCacheTest, DoesntCacheIfKeyIsTooBig) {
+    char key[MAX_KEY_SIZE+1];
+    char buf[4] = { 0xee, 0xee, 0xee, 0xee };
+    for (int i = 0; i < MAX_KEY_SIZE+1; i++) {
+        key[i] = 'a';
+    }
+    mBC->set(key, MAX_KEY_SIZE+1, "bbbb", 4);
+    ASSERT_EQ(size_t(0), mBC->get(key, MAX_KEY_SIZE+1, buf, 4));
+    ASSERT_EQ(0xee, buf[0]);
+    ASSERT_EQ(0xee, buf[1]);
+    ASSERT_EQ(0xee, buf[2]);
+    ASSERT_EQ(0xee, buf[3]);
+}
+
+TEST_F(BlobCacheTest, DoesntCacheIfValueIsTooBig) {
+    char buf[MAX_VALUE_SIZE+1];
+    for (int i = 0; i < MAX_VALUE_SIZE+1; i++) {
+        buf[i] = 'b';
+    }
+    mBC->set("abcd", 4, buf, MAX_VALUE_SIZE+1);
+    for (int i = 0; i < MAX_VALUE_SIZE+1; i++) {
+        buf[i] = 0xee;
+    }
+    ASSERT_EQ(size_t(0), mBC->get("abcd", 4, buf, MAX_VALUE_SIZE+1));
+    for (int i = 0; i < MAX_VALUE_SIZE+1; i++) {
+        SCOPED_TRACE(i);
+        ASSERT_EQ(0xee, buf[i]);
+    }
+}
+
+TEST_F(BlobCacheTest, DoesntCacheIfKeyValuePairIsTooBig) {
+    // Check a testing assumptions
+    ASSERT_TRUE(MAX_TOTAL_SIZE < MAX_KEY_SIZE + MAX_VALUE_SIZE);
+    ASSERT_TRUE(MAX_KEY_SIZE < MAX_TOTAL_SIZE);
+
+    enum { bufSize = MAX_TOTAL_SIZE - MAX_KEY_SIZE + 1 };
+
+    char key[MAX_KEY_SIZE];
+    char buf[bufSize];
+    for (int i = 0; i < MAX_KEY_SIZE; i++) {
+        key[i] = 'a';
+    }
+    for (int i = 0; i < bufSize; i++) {
+        buf[i] = 'b';
+    }
+
+    mBC->set(key, MAX_KEY_SIZE, buf, MAX_VALUE_SIZE);
+    ASSERT_EQ(size_t(0), mBC->get(key, MAX_KEY_SIZE, NULL, 0));
+}
+
+TEST_F(BlobCacheTest, CacheMaxKeySizeSucceeds) {
+    char key[MAX_KEY_SIZE];
+    char buf[4] = { 0xee, 0xee, 0xee, 0xee };
+    for (int i = 0; i < MAX_KEY_SIZE; i++) {
+        key[i] = 'a';
+    }
+    mBC->set(key, MAX_KEY_SIZE, "wxyz", 4);
+    ASSERT_EQ(size_t(4), mBC->get(key, MAX_KEY_SIZE, buf, 4));
+    ASSERT_EQ('w', buf[0]);
+    ASSERT_EQ('x', buf[1]);
+    ASSERT_EQ('y', buf[2]);
+    ASSERT_EQ('z', buf[3]);
+}
+
+TEST_F(BlobCacheTest, CacheMaxValueSizeSucceeds) {
+    char buf[MAX_VALUE_SIZE];
+    for (int i = 0; i < MAX_VALUE_SIZE; i++) {
+        buf[i] = 'b';
+    }
+    mBC->set("abcd", 4, buf, MAX_VALUE_SIZE);
+    for (int i = 0; i < MAX_VALUE_SIZE; i++) {
+        buf[i] = 0xee;
+    }
+    ASSERT_EQ(size_t(MAX_VALUE_SIZE), mBC->get("abcd", 4, buf,
+            MAX_VALUE_SIZE));
+    for (int i = 0; i < MAX_VALUE_SIZE; i++) {
+        SCOPED_TRACE(i);
+        ASSERT_EQ('b', buf[i]);
+    }
+}
+
+TEST_F(BlobCacheTest, CacheMaxKeyValuePairSizeSucceeds) {
+    // Check a testing assumption
+    ASSERT_TRUE(MAX_KEY_SIZE < MAX_TOTAL_SIZE);
+
+    enum { bufSize = MAX_TOTAL_SIZE - MAX_KEY_SIZE };
+
+    char key[MAX_KEY_SIZE];
+    char buf[bufSize];
+    for (int i = 0; i < MAX_KEY_SIZE; i++) {
+        key[i] = 'a';
+    }
+    for (int i = 0; i < bufSize; i++) {
+        buf[i] = 'b';
+    }
+
+    mBC->set(key, MAX_KEY_SIZE, buf, bufSize);
+    ASSERT_EQ(size_t(bufSize), mBC->get(key, MAX_KEY_SIZE, NULL, 0));
+}
+
+TEST_F(BlobCacheTest, CacheMinKeyAndValueSizeSucceeds) {
+    char buf[1] = { 0xee };
+    mBC->set("x", 1, "y", 1);
+    ASSERT_EQ(size_t(1), mBC->get("x", 1, buf, 1));
+    ASSERT_EQ('y', buf[0]);
+}
+
+TEST_F(BlobCacheTest, CacheSizeDoesntExceedTotalLimit) {
+    for (int i = 0; i < 256; i++) {
+        uint8_t k = i;
+        mBC->set(&k, 1, "x", 1);
+    }
+    int numCached = 0;
+    for (int i = 0; i < 256; i++) {
+        uint8_t k = i;
+        if (mBC->get(&k, 1, NULL, 0) == 1) {
+            numCached++;
+        }
+    }
+    ASSERT_GE(MAX_TOTAL_SIZE / 2, numCached);
+}
+
+TEST_F(BlobCacheTest, ExceedingTotalLimitHalvesCacheSize) {
+    // Fill up the entire cache with 1 char key/value pairs.
+    const int maxEntries = MAX_TOTAL_SIZE / 2;
+    for (int i = 0; i < maxEntries; i++) {
+        uint8_t k = i;
+        mBC->set(&k, 1, "x", 1);
+    }
+    // Insert one more entry, causing a cache overflow.
+    {
+        uint8_t k = maxEntries;
+        mBC->set(&k, 1, "x", 1);
+    }
+    // Count the number of entries in the cache.
+    int numCached = 0;
+    for (int i = 0; i < maxEntries+1; i++) {
+        uint8_t k = i;
+        if (mBC->get(&k, 1, NULL, 0) == 1) {
+            numCached++;
+        }
+    }
+    ASSERT_EQ(maxEntries/2 + 1, numCached);
+}
+
+} // namespace android
diff --git a/media/java/android/media/MediaFile.java b/media/java/android/media/MediaFile.java
index a54cf28..7634c6c 100644
--- a/media/java/android/media/MediaFile.java
+++ b/media/java/android/media/MediaFile.java
@@ -76,8 +76,9 @@
     public static final int FILE_TYPE_PNG     = 33;
     public static final int FILE_TYPE_BMP     = 34;
     public static final int FILE_TYPE_WBMP    = 35;
+    public static final int FILE_TYPE_WEBP    = 36;
     private static final int FIRST_IMAGE_FILE_TYPE = FILE_TYPE_JPEG;
-    private static final int LAST_IMAGE_FILE_TYPE = FILE_TYPE_WBMP;
+    private static final int LAST_IMAGE_FILE_TYPE = FILE_TYPE_WEBP;
    
     // Playlist file types
     public static final int FILE_TYPE_M3U      = 41;
@@ -213,6 +214,7 @@
         addFileType("PNG", FILE_TYPE_PNG, "image/png", MtpConstants.FORMAT_PNG);
         addFileType("BMP", FILE_TYPE_BMP, "image/x-ms-bmp", MtpConstants.FORMAT_BMP);
         addFileType("WBMP", FILE_TYPE_WBMP, "image/vnd.wap.wbmp");
+        addFileType("WEBP", FILE_TYPE_WBMP, "image/webp");
  
         addFileType("M3U", FILE_TYPE_M3U, "audio/x-mpegurl", MtpConstants.FORMAT_M3U_PLAYLIST);
         addFileType("M3U", FILE_TYPE_M3U, "application/x-mpegurl", MtpConstants.FORMAT_M3U_PLAYLIST);
diff --git a/media/java/android/media/MediaPlayer.java b/media/java/android/media/MediaPlayer.java
index 8f7dd60..2557730 100644
--- a/media/java/android/media/MediaPlayer.java
+++ b/media/java/android/media/MediaPlayer.java
@@ -30,6 +30,7 @@
 import android.view.Surface;
 import android.view.SurfaceHolder;
 import android.graphics.Bitmap;
+import android.graphics.ParcelSurfaceTexture;
 import android.graphics.SurfaceTexture;
 import android.media.AudioManager;
 
@@ -51,6 +52,7 @@
  * <li><a href="#StateDiagram">State Diagram</a>
  * <li><a href="#Valid_and_Invalid_States">Valid and Invalid States</a>
  * <li><a href="#Permissions">Permissions</a>
+ * <li><a href="#Callbacks">Register informational and error callbacks</a>
  * </ol>
  *
  * <a name="StateDiagram"></a>
@@ -458,6 +460,25 @@
  * android.R.styleable#AndroidManifestUsesPermission &lt;uses-permission&gt;}
  * element.
  *
+ * <a name="Callbacks"></a>
+ * <h3>Callbacks</h3>
+ * <p>Applications may want to register for informational and error
+ * events in order to be informed of some internal state update and
+ * possible runtime errors during playback or streaming. Registration for
+ * these events is done by properly setting the appropriate listeners (via calls
+ * to
+ * {@link #setOnPreparedListener(OnPreparedListener)}setOnPreparedListener,
+ * {@link #setOnVideoSizeChangedListener(OnVideoSizeChangedListener)}setOnVideoSizeChangedListener,
+ * {@link #setOnSeekCompleteListener(OnSeekCompleteListener)}setOnSeekCompleteListener,
+ * {@link #setOnCompletionListener(OnCompletionListener)}setOnCompletionListener,
+ * {@link #setOnBufferingUpdateListener(OnBufferingUpdateListener)}setOnBufferingUpdateListener,
+ * {@link #setOnInfoListener(OnInfoListener)}setOnInfoListener,
+ * {@link #setOnErrorListener(OnErrorListener)}setOnErrorListener, etc).
+ * In order to receive the respective callback
+ * associated with these listeners, applications are required to create
+ * MediaPlayer objects on a thread with its own Looper running (main UI
+ * thread by default has a Looper running).
+ *
  */
 public class MediaPlayer
 {
@@ -509,7 +530,7 @@
     private int mListenerContext; // accessed by native methods
     private Surface mSurface; // accessed by native methods
     private SurfaceHolder  mSurfaceHolder;
-    private SurfaceTexture mSurfaceTexture; // accessed by native methods
+    private ParcelSurfaceTexture mParcelSurfaceTexture; // accessed by native methods
     private EventHandler mEventHandler;
     private PowerManager.WakeLock mWakeLock = null;
     private boolean mScreenOnWhilePlaying;
@@ -541,7 +562,7 @@
 
     /*
      * Update the MediaPlayer ISurface and ISurfaceTexture.
-     * Call after updating mSurface and/or mSurfaceTexture.
+     * Call after updating mSurface and/or mParcelSurfaceTexture.
      */
     private native void _setVideoSurfaceOrSurfaceTexture();
 
@@ -607,7 +628,7 @@
         } else {
             mSurface = null;
         }
-        mSurfaceTexture = null;
+        mParcelSurfaceTexture = null;
         _setVideoSurfaceOrSurfaceTexture();
         updateSurfaceScreenOn();
     }
@@ -630,12 +651,32 @@
      * program.
      */
     public void setTexture(SurfaceTexture st) {
-        if (mScreenOnWhilePlaying && st != null && mSurfaceTexture == null) {
+        ParcelSurfaceTexture pst = null;
+        if (st != null) {
+            pst = ParcelSurfaceTexture.fromSurfaceTexture(st);
+        }
+        setParcelSurfaceTexture(pst);
+    }
+
+    /**
+     * Sets the {@link ParcelSurfaceTexture} to be used as the sink for the video portion of
+     * the media. This is similar to {@link #setTexture(SurfaceTexture)}, but supports using
+     * a {@link ParcelSurfaceTexture} to transport the texture to be used via Binder. Setting
+     * a parceled surface texture will un-set any surface or surface texture that was previously
+     * set. See {@link #setTexture(SurfaceTexture)} for more details.
+     *
+     * @param pst The {@link ParcelSurfaceTexture} to be used as the sink for
+     * the video portion of the media.
+     *
+     * @hide Pending review by API council.
+     */
+    public void setParcelSurfaceTexture(ParcelSurfaceTexture pst) {
+        if (mScreenOnWhilePlaying && pst != null && mParcelSurfaceTexture == null) {
             Log.w(TAG, "setScreenOnWhilePlaying(true) is ineffective for SurfaceTexture");
         }
         mSurfaceHolder = null;
         mSurface = null;
-        mSurfaceTexture = st;
+        mParcelSurfaceTexture = pst;
         _setVideoSurfaceOrSurfaceTexture();
         updateSurfaceScreenOn();
     }
@@ -962,7 +1003,7 @@
      */
     public void setScreenOnWhilePlaying(boolean screenOn) {
         if (mScreenOnWhilePlaying != screenOn) {
-            if (screenOn && mSurfaceTexture != null) {
+            if (screenOn && mParcelSurfaceTexture != null) {
                 Log.w(TAG, "setScreenOnWhilePlaying(true) is ineffective for SurfaceTexture");
             }
             mScreenOnWhilePlaying = screenOn;
diff --git a/media/java/android/media/MediaRecorder.java b/media/java/android/media/MediaRecorder.java
index 38202f2..dd45111 100644
--- a/media/java/android/media/MediaRecorder.java
+++ b/media/java/android/media/MediaRecorder.java
@@ -51,6 +51,16 @@
  * recorder.release(); // Now the object cannot be reused
  * </pre>
  *
+ * <p>Applications may want to register for informational and error
+ * events in order to be informed of some internal update and possible
+ * runtime errors during recording. Registration for such events is
+ * done by setting the appropriate listeners (via calls
+ * (to {@link #setOnInfoListener(OnInfoListener)}setOnInfoListener and/or
+ * {@link #setOnErrorListener(OnErrorListener)}setOnErrorListener).
+ * In order to receive the respective callback associated with these listeners,
+ * applications are required to create MediaRecorder objects on threads with a
+ * Looper running (the main UI thread by default already has a Looper running).
+ *
  * <p>See the <a href="{@docRoot}guide/topics/media/index.html">Audio and Video</a>
  * documentation for additional help with using MediaRecorder.
  * <p>Note: Currently, MediaRecorder does not work on the emulator.
@@ -716,6 +726,12 @@
     /**
      * Stops recording. Call this after start(). Once recording is stopped,
      * you will have to configure it again as if it has just been constructed.
+     * Note that a RuntimeException is intentionally thrown to the
+     * application, if no valid audio/video data has been received when stop()
+     * is called. This happens if stop() is called immediately after
+     * start(). The failure lets the application take action accordingly to
+     * clean up the output file (delete the output file, for instance), since
+     * the output file is not properly constructed when this happens.
      *
      * @throws IllegalStateException if it is called before start()
      */
diff --git a/media/java/android/mtp/MtpDatabase.java b/media/java/android/mtp/MtpDatabase.java
index c9e0f6f..4e271c7 100644
--- a/media/java/android/mtp/MtpDatabase.java
+++ b/media/java/android/mtp/MtpDatabase.java
@@ -92,13 +92,18 @@
     };
     private static final String ID_WHERE = Files.FileColumns._ID + "=?";
     private static final String PATH_WHERE = Files.FileColumns.DATA + "=?";
-    private static final String PARENT_WHERE = Files.FileColumns.PARENT + "=?";
-    private static final String PARENT_FORMAT_WHERE = PARENT_WHERE + " AND "
+
+    private static final String STORAGE_WHERE = Files.FileColumns.STORAGE_ID + "=?";
+    private static final String FORMAT_WHERE = Files.FileColumns.PARENT + "=?";
+    private static final String PARENT_WHERE = Files.FileColumns.FORMAT + "=?";
+    private static final String STORAGE_FORMAT_WHERE = STORAGE_WHERE + " AND "
                                             + Files.FileColumns.FORMAT + "=?";
-    private static final String PARENT_STORAGE_WHERE = PARENT_WHERE + " AND "
-                                            + Files.FileColumns.STORAGE_ID + "=?";
-    private static final String PARENT_STORAGE_FORMAT_WHERE = PARENT_STORAGE_WHERE + " AND "
-                                            + Files.FileColumns.FORMAT + "=?";
+    private static final String STORAGE_PARENT_WHERE = STORAGE_WHERE + " AND "
+                                            + Files.FileColumns.PARENT + "=?";
+    private static final String FORMAT_PARENT_WHERE = FORMAT_WHERE + " AND "
+                                            + Files.FileColumns.PARENT + "=?";
+    private static final String STORAGE_FORMAT_PARENT_WHERE = STORAGE_FORMAT_WHERE + " AND "
+                                            + Files.FileColumns.PARENT + "=?";
 
     private final MediaScanner mMediaScanner;
 
@@ -249,26 +254,67 @@
     }
 
     private Cursor createObjectQuery(int storageID, int format, int parent) throws RemoteException {
-        if (storageID != 0) {
-            if (format != 0) {
-                return mMediaProvider.query(mObjectsUri, ID_PROJECTION,
-                        PARENT_STORAGE_FORMAT_WHERE,
-                        new String[] { Integer.toString(parent), Integer.toString(storageID),
-                                Integer.toString(format) }, null);
+        if (storageID == 0xFFFFFFFF) {
+            // query all stores
+            if (format == 0) {
+                // query all formats
+                if (parent == 0) {
+                    // query all objects
+                    return mMediaProvider.query(mObjectsUri, ID_PROJECTION, null, null, null);
+                }
+                if (parent == 0xFFFFFFFF) {
+                    // all objects in root of store
+                    parent = 0;
+                }
+                return mMediaProvider.query(mObjectsUri, ID_PROJECTION, PARENT_WHERE,
+                        new String[] { Integer.toString(parent) }, null);
             } else {
-                return mMediaProvider.query(mObjectsUri, ID_PROJECTION,
-                        PARENT_STORAGE_WHERE, new String[]
-                                { Integer.toString(parent), Integer.toString(storageID) }, null);
+                // query specific format
+                if (parent == 0) {
+                    // query all objects
+                    return mMediaProvider.query(mObjectsUri, ID_PROJECTION, FORMAT_WHERE,
+                            new String[] { Integer.toString(format) }, null);
+                }
+                if (parent == 0xFFFFFFFF) {
+                    // all objects in root of store
+                    parent = 0;
+                }
+                return mMediaProvider.query(mObjectsUri, ID_PROJECTION, FORMAT_PARENT_WHERE,
+                        new String[] { Integer.toString(format), Integer.toString(parent) }, null);
             }
         } else {
-            if (format != 0) {
-                return mMediaProvider.query(mObjectsUri, ID_PROJECTION,
-                            PARENT_FORMAT_WHERE,
-                            new String[] { Integer.toString(parent), Integer.toString(format) },
-                             null);
+            // query specific store
+            if (format == 0) {
+                // query all formats
+                if (parent == 0) {
+                    // query all objects
+                    return mMediaProvider.query(mObjectsUri, ID_PROJECTION, STORAGE_WHERE,
+                            new String[] { Integer.toString(storageID) }, null);
+                }
+                if (parent == 0xFFFFFFFF) {
+                    // all objects in root of store
+                    parent = 0;
+                }
+                return mMediaProvider.query(mObjectsUri, ID_PROJECTION, STORAGE_PARENT_WHERE,
+                        new String[] { Integer.toString(storageID), Integer.toString(parent) },
+                        null);
             } else {
-                return mMediaProvider.query(mObjectsUri, ID_PROJECTION,
-                            PARENT_WHERE, new String[] { Integer.toString(parent) }, null);
+                // query specific format
+                if (parent == 0) {
+                    // query all objects
+                    return mMediaProvider.query(mObjectsUri, ID_PROJECTION, STORAGE_FORMAT_WHERE,
+                            new String[] {  Integer.toString(storageID), Integer.toString(format) },
+                            null);
+                }
+                if (parent == 0xFFFFFFFF) {
+                    // all objects in root of store
+                    parent = 0;
+                }
+                return mMediaProvider.query(mObjectsUri, ID_PROJECTION, STORAGE_FORMAT_PARENT_WHERE,
+                        new String[] { Integer.toString(storageID),
+                                       Integer.toString(format),
+                                       Integer.toString(parent) },
+                        null);
             }
         }
     }
diff --git a/media/java/android/mtp/MtpServer.java b/media/java/android/mtp/MtpServer.java
index c065ca8..687cc44 100644
--- a/media/java/android/mtp/MtpServer.java
+++ b/media/java/android/mtp/MtpServer.java
@@ -61,10 +61,6 @@
         native_send_object_removed(handle);
     }
 
-    public void setPtpMode(boolean usePtp) {
-        native_set_ptp_mode(usePtp);
-    }
-
     public void addStorage(MtpStorage storage) {
         native_add_storage(storage);
     }
@@ -78,7 +74,6 @@
     private native final void native_stop();
     private native final void native_send_object_added(int handle);
     private native final void native_send_object_removed(int handle);
-    private native final void native_set_ptp_mode(boolean usePtp);
     private native final void native_add_storage(MtpStorage storage);
     private native final void native_remove_storage(int storageId);
 }
diff --git a/media/jni/android_media_MediaPlayer.cpp b/media/jni/android_media_MediaPlayer.cpp
index b03aa38..5663683 100644
--- a/media/jni/android_media_MediaPlayer.cpp
+++ b/media/jni/android_media_MediaPlayer.cpp
@@ -30,6 +30,7 @@
 #include "jni.h"
 #include "JNIHelp.h"
 #include "android_runtime/AndroidRuntime.h"
+#include "android_runtime/android_graphics_ParcelSurfaceTexture.h"
 #include "utils/Errors.h"  // for status_t
 #include "utils/KeyedVector.h"
 #include "utils/String8.h"
@@ -37,7 +38,6 @@
 
 #include "android_util_Binder.h"
 #include <binder/Parcel.h>
-#include <gui/SurfaceTexture.h>
 #include <gui/ISurfaceTexture.h>
 #include <surfaceflinger/Surface.h>
 #include <binder/IPCThreadState.h>
@@ -52,11 +52,9 @@
 struct fields_t {
     jfieldID    context;
     jfieldID    surface;
-    jfieldID    surfaceTexture;
+    jfieldID    parcelSurfaceTexture;
     /* actually in android.view.Surface XXX */
     jfieldID    surface_native;
-    // actually in android.graphics.SurfaceTexture
-    jfieldID    surfaceTexture_native;
 
     jmethodID   post_event;
 };
@@ -130,13 +128,6 @@
     return (Surface*)env->GetIntField(clazz, fields.surface_native);
 }
 
-sp<ISurfaceTexture> getSurfaceTexture(JNIEnv* env, jobject clazz)
-{
-    sp<ISurfaceTexture> surfaceTexture(
-        (ISurfaceTexture*)env->GetIntField(clazz, fields.surfaceTexture_native));
-    return surfaceTexture;
-}
-
 static sp<MediaPlayer> getMediaPlayer(JNIEnv* env, jobject thiz)
 {
     Mutex::Autolock l(sLock);
@@ -257,8 +248,8 @@
         const sp<MediaPlayer>& mp, JNIEnv *env, jobject thiz, const char *prefix)
 {
     // The Java MediaPlayer class makes sure that at most one of mSurface and
-    // mSurfaceTexture is non-null.  But just in case, we give priority to
-    // mSurface over mSurfaceTexture.
+    // mParcelSurfaceTexture is non-null.  But just in case, we give priority to
+    // mSurface over mParcelSurfaceTexture.
     jobject surface = env->GetObjectField(thiz, fields.surface);
     if (surface != NULL) {
         sp<Surface> native_surface(get_surface(env, surface));
@@ -266,10 +257,10 @@
              native_surface.get(), native_surface->getIdentity());
         mp->setVideoSurface(native_surface);
     } else {
-        jobject surfaceTexture = env->GetObjectField(thiz, fields.surfaceTexture);
-        if (surfaceTexture != NULL) {
+        jobject parcelSurfaceTexture = env->GetObjectField(thiz, fields.parcelSurfaceTexture);
+        if (parcelSurfaceTexture != NULL) {
             sp<ISurfaceTexture> native_surfaceTexture(
-                    getSurfaceTexture(env, surfaceTexture));
+                    ParcelSurfaceTexture_getISurfaceTexture(env, parcelSurfaceTexture));
             LOGV("%s: texture=%p", prefix, native_surfaceTexture.get());
             mp->setVideoSurfaceTexture(native_surfaceTexture);
         }
@@ -610,23 +601,11 @@
         return;
     }
 
-    fields.surfaceTexture = env->GetFieldID(clazz, "mSurfaceTexture",
-            "Landroid/graphics/SurfaceTexture;");
-    if (fields.surfaceTexture == NULL) {
+    fields.parcelSurfaceTexture = env->GetFieldID(clazz, "mParcelSurfaceTexture",
+            "Landroid/graphics/ParcelSurfaceTexture;");
+    if (fields.parcelSurfaceTexture == NULL) {
         return;
     }
-
-    jclass surfaceTexture = env->FindClass("android/graphics/SurfaceTexture");
-    if (surfaceTexture == NULL) {
-        return;
-    }
-
-    fields.surfaceTexture_native = env->GetFieldID(surfaceTexture,
-            ANDROID_GRAPHICS_SURFACETEXTURE_JNI_ID, "I");
-    if (fields.surfaceTexture_native == NULL) {
-        return;
-    }
-
 }
 
 static void
diff --git a/media/jni/android_mtp_MtpServer.cpp b/media/jni/android_mtp_MtpServer.cpp
index 4d84cb7..e36e6db 100644
--- a/media/jni/android_mtp_MtpServer.cpp
+++ b/media/jni/android_mtp_MtpServer.cpp
@@ -70,14 +70,12 @@
     MtpDatabase*    mDatabase;
     MtpServer*      mServer;
     MtpStorageList  mStorageList;
-    bool            mUsePtp;
     int             mFd;
 
 public:
     MtpThread(MtpDatabase* database)
         :   mDatabase(database),
             mServer(NULL),
-            mUsePtp(false),
             mFd(-1)
     {
     }
@@ -85,10 +83,6 @@
     virtual ~MtpThread() {
     }
 
-    void setPtpMode(bool usePtp) {
-        mUsePtp = usePtp;
-    }
-
     void addStorage(MtpStorage *storage) {
         mStorageList.push(storage);
         if (mServer)
@@ -119,9 +113,6 @@
 
         mFd = open("/dev/mtp_usb", O_RDWR);
         if (mFd >= 0) {
-            ioctl(mFd, MTP_SET_INTERFACE_MODE,
-                    (mUsePtp ? MTP_INTERFACE_MODE_PTP : MTP_INTERFACE_MODE_MTP));
-
             mServer = new MtpServer(mFd, mDatabase, AID_MEDIA_RW, 0664, 0775);
             for (size_t i = 0; i < mStorageList.size(); i++) {
                 mServer->addStorage(mStorageList[i]);
@@ -224,18 +215,6 @@
 }
 
 static void
-android_mtp_MtpServer_set_ptp_mode(JNIEnv *env, jobject thiz, jboolean usePtp)
-{
-#ifdef HAVE_ANDROID_OS
-    sMutex.lock();
-    MtpThread *thread = sThread.get();
-    if (thread)
-        thread->setPtpMode(usePtp);
-    sMutex.unlock();
-#endif
-}
-
-static void
 android_mtp_MtpServer_add_storage(JNIEnv *env, jobject thiz, jobject jstorage)
 {
 #ifdef HAVE_ANDROID_OS
@@ -290,7 +269,6 @@
     {"native_stop",                 "()V",  (void *)android_mtp_MtpServer_stop},
     {"native_send_object_added",    "(I)V", (void *)android_mtp_MtpServer_send_object_added},
     {"native_send_object_removed",  "(I)V", (void *)android_mtp_MtpServer_send_object_removed},
-    {"native_set_ptp_mode",         "(Z)V", (void *)android_mtp_MtpServer_set_ptp_mode},
     {"native_add_storage",          "(Landroid/mtp/MtpStorage;)V",
                                             (void *)android_mtp_MtpServer_add_storage},
     {"native_remove_storage",       "(I)V", (void *)android_mtp_MtpServer_remove_storage},
diff --git a/media/jni/soundpool/SoundPool.cpp b/media/jni/soundpool/SoundPool.cpp
index 3ea13a6..4ffb2c0 100644
--- a/media/jni/soundpool/SoundPool.cpp
+++ b/media/jni/soundpool/SoundPool.cpp
@@ -23,7 +23,6 @@
 // XXX needed for timing latency
 #include <utils/Timers.h>
 
-#include <sys/resource.h>
 #include <media/AudioTrack.h>
 #include <media/mediaplayer.h>
 
diff --git a/media/libeffects/factory/EffectsFactory.c b/media/libeffects/factory/EffectsFactory.c
index b0e8585..a3e76d9 100644
--- a/media/libeffects/factory/EffectsFactory.c
+++ b/media/libeffects/factory/EffectsFactory.c
@@ -257,7 +257,7 @@
     }
 
     // create effect in library
-    l->desc->create_effect(uuid, sessionId, ioId, &itfe);
+    ret = l->desc->create_effect(uuid, sessionId, ioId, &itfe);
     if (ret != 0) {
         LOGW("EffectCreate() library %s: could not create fx %s, error %d", l->name, d->name, ret);
         goto exit;
diff --git a/media/libmedia/AudioRecord.cpp b/media/libmedia/AudioRecord.cpp
index 446e3df..a41d7ab 100644
--- a/media/libmedia/AudioRecord.cpp
+++ b/media/libmedia/AudioRecord.cpp
@@ -88,7 +88,7 @@
         int inputSource,
         uint32_t sampleRate,
         int format,
-        uint32_t channels,
+        uint32_t channelMask,
         int frameCount,
         uint32_t flags,
         callback_t cbf,
@@ -97,7 +97,7 @@
         int sessionId)
     : mStatus(NO_INIT), mSessionId(0)
 {
-    mStatus = set(inputSource, sampleRate, format, channels,
+    mStatus = set(inputSource, sampleRate, format, channelMask,
             frameCount, flags, cbf, user, notificationFrames, sessionId);
 }
 
@@ -121,7 +121,7 @@
         int inputSource,
         uint32_t sampleRate,
         int format,
-        uint32_t channels,
+        uint32_t channelMask,
         int frameCount,
         uint32_t flags,
         callback_t cbf,
@@ -131,7 +131,7 @@
         int sessionId)
 {
 
-    LOGV("set(): sampleRate %d, channels %d, frameCount %d",sampleRate, channels, frameCount);
+    LOGV("set(): sampleRate %d, channelMask %d, frameCount %d",sampleRate, channelMask, frameCount);
 
     AutoMutex lock(mLock);
 
@@ -156,14 +156,14 @@
         return BAD_VALUE;
     }
 
-    if (!audio_is_input_channel(channels)) {
+    if (!audio_is_input_channel(channelMask)) {
         return BAD_VALUE;
     }
 
-    int channelCount = popcount(channels);
+    int channelCount = popcount(channelMask);
 
     audio_io_handle_t input = AudioSystem::getInput(inputSource,
-                                    sampleRate, format, channels, (audio_in_acoustics_t)flags);
+                                    sampleRate, format, channelMask, (audio_in_acoustics_t)flags);
     if (input == 0) {
         LOGE("Could not get audio input for record source %d", inputSource);
         return BAD_VALUE;
@@ -190,7 +190,7 @@
     mSessionId = sessionId;
 
     // create the IAudioRecord
-    status = openRecord_l(sampleRate, format, channelCount,
+    status = openRecord_l(sampleRate, format, channelMask,
                         frameCount, flags, input);
     if (status != NO_ERROR) {
         return status;
@@ -209,7 +209,7 @@
     // Update buffer size in case it has been limited by AudioFlinger during track creation
     mFrameCount = mCblk->frameCount;
     mChannelCount = (uint8_t)channelCount;
-    mChannels = channels;
+    mChannelMask = channelMask;
     mActive = 0;
     mCbf = cbf;
     mNotificationFrames = notificationFrames;
@@ -315,9 +315,9 @@
             cblk->bufferTimeoutMs = MAX_RUN_TIMEOUT_MS;
             cblk->waitTimeMs = 0;
             if (t != 0) {
-               t->run("ClientRecordThread", THREAD_PRIORITY_AUDIO_CLIENT);
+               t->run("ClientRecordThread", ANDROID_PRIORITY_AUDIO);
             } else {
-                setpriority(PRIO_PROCESS, 0, THREAD_PRIORITY_AUDIO_CLIENT);
+                setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_AUDIO);
             }
         } else {
             mActive = 0;
@@ -437,8 +437,8 @@
 // must be called with mLock held
 status_t AudioRecord::openRecord_l(
         uint32_t sampleRate,
-        int format,
-        int channelCount,
+        uint32_t format,
+        uint32_t channelMask,
         int frameCount,
         uint32_t flags,
         audio_io_handle_t input)
@@ -451,7 +451,7 @@
 
     sp<IAudioRecord> record = audioFlinger->openRecord(getpid(), input,
                                                        sampleRate, format,
-                                                       channelCount,
+                                                       channelMask,
                                                        frameCount,
                                                        ((uint16_t)flags) << 16,
                                                        &mSessionId,
@@ -589,7 +589,7 @@
 {
     mInput = AudioSystem::getInput(mInputSource,
                                 mCblk->sampleRate,
-                                mFormat, mChannels,
+                                mFormat, mChannelMask,
                                 (audio_in_acoustics_t)mFlags);
     return mInput;
 }
@@ -756,7 +756,7 @@
         // if the new IAudioRecord is created, openRecord_l() will modify the
         // following member variables: mAudioRecord, mCblkMemory and mCblk.
         // It will also delete the strong references on previous IAudioRecord and IMemory
-        result = openRecord_l(cblk->sampleRate, mFormat, mChannelCount,
+        result = openRecord_l(cblk->sampleRate, mFormat, mChannelMask,
                 mFrameCount, mFlags, getInput_l());
         if (result == NO_ERROR) {
             result = mAudioRecord->start();
diff --git a/media/libmedia/AudioSystem.cpp b/media/libmedia/AudioSystem.cpp
index 8a180d8..6cb3847 100644
--- a/media/libmedia/AudioSystem.cpp
+++ b/media/libmedia/AudioSystem.cpp
@@ -26,13 +26,6 @@
 #include <system/audio.h>
 
 // ----------------------------------------------------------------------------
-// the sim build doesn't have gettid
-
-#ifndef HAVE_GETTID
-# define gettid getpid
-#endif
-
-// ----------------------------------------------------------------------------
 
 namespace android {
 
diff --git a/media/libmedia/AudioTrack.cpp b/media/libmedia/AudioTrack.cpp
index 7520ed9..37fe182 100644
--- a/media/libmedia/AudioTrack.cpp
+++ b/media/libmedia/AudioTrack.cpp
@@ -40,7 +40,7 @@
 #include <cutils/bitops.h>
 
 #include <system/audio.h>
-#include <hardware/audio_policy.h>
+#include <system/audio_policy.h>
 
 #define LIKELY( exp )       (__builtin_expect( (exp) != 0, true  ))
 #define UNLIKELY( exp )     (__builtin_expect( (exp) != 0, false ))
@@ -87,7 +87,7 @@
         int streamType,
         uint32_t sampleRate,
         int format,
-        int channels,
+        int channelMask,
         int frameCount,
         uint32_t flags,
         callback_t cbf,
@@ -96,7 +96,7 @@
         int sessionId)
     : mStatus(NO_INIT)
 {
-    mStatus = set(streamType, sampleRate, format, channels,
+    mStatus = set(streamType, sampleRate, format, channelMask,
             frameCount, flags, cbf, user, notificationFrames,
             0, false, sessionId);
 }
@@ -105,7 +105,7 @@
         int streamType,
         uint32_t sampleRate,
         int format,
-        int channels,
+        int channelMask,
         const sp<IMemory>& sharedBuffer,
         uint32_t flags,
         callback_t cbf,
@@ -114,7 +114,7 @@
         int sessionId)
     : mStatus(NO_INIT)
 {
-    mStatus = set(streamType, sampleRate, format, channels,
+    mStatus = set(streamType, sampleRate, format, channelMask,
             0, flags, cbf, user, notificationFrames,
             sharedBuffer, false, sessionId);
 }
@@ -141,7 +141,7 @@
         int streamType,
         uint32_t sampleRate,
         int format,
-        int channels,
+        int channelMask,
         int frameCount,
         uint32_t flags,
         callback_t cbf,
@@ -180,8 +180,8 @@
     if (format == 0) {
         format = AUDIO_FORMAT_PCM_16_BIT;
     }
-    if (channels == 0) {
-        channels = AUDIO_CHANNEL_OUT_STEREO;
+    if (channelMask == 0) {
+        channelMask = AUDIO_CHANNEL_OUT_STEREO;
     }
 
     // validate parameters
@@ -195,15 +195,15 @@
         flags |= AUDIO_POLICY_OUTPUT_FLAG_DIRECT;
     }
 
-    if (!audio_is_output_channel(channels)) {
+    if (!audio_is_output_channel(channelMask)) {
         LOGE("Invalid channel mask");
         return BAD_VALUE;
     }
-    uint32_t channelCount = popcount(channels);
+    uint32_t channelCount = popcount(channelMask);
 
     audio_io_handle_t output = AudioSystem::getOutput(
                                     (audio_stream_type_t)streamType,
-                                    sampleRate,format, channels,
+                                    sampleRate,format, channelMask,
                                     (audio_policy_output_flags_t)flags);
 
     if (output == 0) {
@@ -222,8 +222,8 @@
     // create the IAudioTrack
     status_t status = createTrack_l(streamType,
                                   sampleRate,
-                                  format,
-                                  channelCount,
+                                  (uint32_t)format,
+                                  (uint32_t)channelMask,
                                   frameCount,
                                   flags,
                                   sharedBuffer,
@@ -245,8 +245,8 @@
     mStatus = NO_ERROR;
 
     mStreamType = streamType;
-    mFormat = format;
-    mChannels = channels;
+    mFormat = (uint32_t)format;
+    mChannelMask = (uint32_t)channelMask;
     mChannelCount = channelCount;
     mSharedBuffer = sharedBuffer;
     mMuted = false;
@@ -342,9 +342,9 @@
         cblk->waitTimeMs = 0;
         android_atomic_and(~CBLK_DISABLED_ON, &cblk->flags);
         if (t != 0) {
-           t->run("AudioTrackThread", THREAD_PRIORITY_AUDIO_CLIENT);
+           t->run("AudioTrackThread", ANDROID_PRIORITY_AUDIO);
         } else {
-            setpriority(PRIO_PROCESS, 0, THREAD_PRIORITY_AUDIO_CLIENT);
+            setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_AUDIO);
         }
 
         LOGV("start %p before lock cblk %p", this, mCblk);
@@ -681,7 +681,7 @@
 audio_io_handle_t AudioTrack::getOutput_l()
 {
     return AudioSystem::getOutput((audio_stream_type_t)mStreamType,
-            mCblk->sampleRate, mFormat, mChannels, (audio_policy_output_flags_t)mFlags);
+            mCblk->sampleRate, mFormat, mChannelMask, (audio_policy_output_flags_t)mFlags);
 }
 
 int AudioTrack::getSessionId()
@@ -705,8 +705,8 @@
 status_t AudioTrack::createTrack_l(
         int streamType,
         uint32_t sampleRate,
-        int format,
-        int channelCount,
+        uint32_t format,
+        uint32_t channelMask,
         int frameCount,
         uint32_t flags,
         const sp<IMemory>& sharedBuffer,
@@ -767,6 +767,7 @@
             }
         } else {
             // Ensure that buffer alignment matches channelcount
+            int channelCount = popcount(channelMask);
             if (((uint32_t)sharedBuffer->pointer() & (channelCount | 1)) != 0) {
                 LOGE("Invalid buffer alignement: address %p, channelCount %d", sharedBuffer->pointer(), channelCount);
                 return BAD_VALUE;
@@ -779,7 +780,7 @@
                                                       streamType,
                                                       sampleRate,
                                                       format,
-                                                      channelCount,
+                                                      channelMask,
                                                       frameCount,
                                                       ((uint16_t)flags) << 16,
                                                       sharedBuffer,
@@ -1164,7 +1165,7 @@
         result = createTrack_l(mStreamType,
                                cblk->sampleRate,
                                mFormat,
-                               mChannelCount,
+                               mChannelMask,
                                mFrameCount,
                                mFlags,
                                mSharedBuffer,
diff --git a/media/libmedia/IAudioFlinger.cpp b/media/libmedia/IAudioFlinger.cpp
index 158d2f5..4a12962 100644
--- a/media/libmedia/IAudioFlinger.cpp
+++ b/media/libmedia/IAudioFlinger.cpp
@@ -82,8 +82,8 @@
                                 pid_t pid,
                                 int streamType,
                                 uint32_t sampleRate,
-                                int format,
-                                int channelCount,
+                                uint32_t format,
+                                uint32_t channelMask,
                                 int frameCount,
                                 uint32_t flags,
                                 const sp<IMemory>& sharedBuffer,
@@ -98,7 +98,7 @@
         data.writeInt32(streamType);
         data.writeInt32(sampleRate);
         data.writeInt32(format);
-        data.writeInt32(channelCount);
+        data.writeInt32(channelMask);
         data.writeInt32(frameCount);
         data.writeInt32(flags);
         data.writeStrongBinder(sharedBuffer->asBinder());
@@ -129,8 +129,8 @@
                                 pid_t pid,
                                 int input,
                                 uint32_t sampleRate,
-                                int format,
-                                int channelCount,
+                                uint32_t format,
+                                uint32_t channelMask,
                                 int frameCount,
                                 uint32_t flags,
                                 int *sessionId,
@@ -143,7 +143,7 @@
         data.writeInt32(input);
         data.writeInt32(sampleRate);
         data.writeInt32(format);
-        data.writeInt32(channelCount);
+        data.writeInt32(channelMask);
         data.writeInt32(frameCount);
         data.writeInt32(flags);
         int lSessionId = 0;
@@ -186,7 +186,7 @@
         return reply.readInt32();
     }
 
-    virtual int format(int output) const
+    virtual uint32_t format(int output) const
     {
         Parcel data, reply;
         data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
diff --git a/media/libmedia/IMediaMetadataRetriever.cpp b/media/libmedia/IMediaMetadataRetriever.cpp
index ebe821f..07152d8 100644
--- a/media/libmedia/IMediaMetadataRetriever.cpp
+++ b/media/libmedia/IMediaMetadataRetriever.cpp
@@ -30,26 +30,6 @@
 // foreground thread.
 #ifndef DISABLE_GROUP_SCHEDULE_HACK
 
-/* desktop Linux needs a little help with gettid() */
-#if defined(HAVE_GETTID) && !defined(HAVE_ANDROID_OS)
-#define __KERNEL__
-# include <linux/unistd.h>
-#ifdef _syscall0
-_syscall0(pid_t,gettid)
-#else
-pid_t gettid() { return syscall(__NR_gettid);}
-#endif
-#undef __KERNEL__
-#endif
-
-static int myTid() {
-#ifdef HAVE_GETTID
-    return gettid();
-#else
-    return getpid();
-#endif
-}
-
 #undef LOG_TAG
 #define LOG_TAG "IMediaMetadataRetriever"
 #include <utils/Log.h>
@@ -60,18 +40,18 @@
 static void sendSchedPolicy(Parcel& data)
 {
     SchedPolicy policy;
-    get_sched_policy(myTid(), &policy);
+    get_sched_policy(gettid(), &policy);
     data.writeInt32(policy);
 }
 
 static void setSchedPolicy(const Parcel& data)
 {
     SchedPolicy policy = (SchedPolicy) data.readInt32();
-    set_sched_policy(myTid(), policy);
+    set_sched_policy(gettid(), policy);
 }
 static void restoreSchedPolicy()
 {
-    set_sched_policy(myTid(), SP_FOREGROUND);
+    set_sched_policy(gettid(), SP_FOREGROUND);
 }
 }; // end namespace android
 #endif
diff --git a/media/libmedia/JetPlayer.cpp b/media/libmedia/JetPlayer.cpp
index 88157d2..8b953e0 100644
--- a/media/libmedia/JetPlayer.cpp
+++ b/media/libmedia/JetPlayer.cpp
@@ -23,13 +23,6 @@
 #include <media/JetPlayer.h>
 
 
-#ifdef HAVE_GETTID
-static pid_t myTid() { return gettid(); }
-#else
-static pid_t myTid() { return getpid(); }
-#endif
-
-
 namespace android
 {
 
@@ -188,7 +181,7 @@
     // signal main thread that we started
     {
         Mutex::Autolock l(mMutex);
-        mTid = myTid();
+        mTid = gettid();
         LOGV("JetPlayer::render(): render thread(%d) signal", mTid);
         mCondition.signal();
     }
diff --git a/media/libmedia/MediaScanner.cpp b/media/libmedia/MediaScanner.cpp
index 28c86426..45bdff4 100644
--- a/media/libmedia/MediaScanner.cpp
+++ b/media/libmedia/MediaScanner.cpp
@@ -89,7 +89,7 @@
     if (pathRemaining >= 8 /* strlen(".nomedia") */ ) {
         strcpy(fileSpot, ".nomedia");
         if (access(path, F_OK) == 0) {
-            LOGD("found .nomedia, setting noMedia flag\n");
+            LOGV("found .nomedia, setting noMedia flag\n");
             noMedia = true;
         }
 
diff --git a/media/libmedia/ToneGenerator.cpp b/media/libmedia/ToneGenerator.cpp
index 9f1b3d6..7c2200e 100644
--- a/media/libmedia/ToneGenerator.cpp
+++ b/media/libmedia/ToneGenerator.cpp
@@ -21,7 +21,6 @@
 #include <stdio.h>
 #include <math.h>
 #include <utils/Log.h>
-#include <sys/resource.h>
 #include <utils/RefBase.h>
 #include <utils/Timers.h>
 #include <cutils/properties.h>
diff --git a/media/libmediaplayerservice/MediaPlayerService.cpp b/media/libmediaplayerservice/MediaPlayerService.cpp
index d51c946..a77dff1 100644
--- a/media/libmediaplayerservice/MediaPlayerService.cpp
+++ b/media/libmediaplayerservice/MediaPlayerService.cpp
@@ -68,18 +68,6 @@
 
 #include <OMX.h>
 
-/* desktop Linux needs a little help with gettid() */
-#if defined(HAVE_GETTID) && !defined(HAVE_ANDROID_OS)
-#define __KERNEL__
-# include <linux/unistd.h>
-#ifdef _syscall0
-_syscall0(pid_t,gettid)
-#else
-pid_t gettid() { return syscall(__NR_gettid);}
-#endif
-#undef __KERNEL__
-#endif
-
 namespace {
 using android::media::Metadata;
 using android::status_t;
@@ -380,6 +368,9 @@
             mPid, mConnId, mStatus, mLoop?"true": "false");
     result.append(buffer);
     write(fd, result.string(), result.size());
+    if (mPlayer != NULL) {
+        mPlayer->dump(fd, args);
+    }
     if (mAudioOutput != 0) {
         mAudioOutput->dump(fd, args);
     }
@@ -387,14 +378,6 @@
     return NO_ERROR;
 }
 
-static int myTid() {
-#ifdef HAVE_GETTID
-    return gettid();
-#else
-    return getpid();
-#endif
-}
-
 status_t MediaPlayerService::dump(int fd, const Vector<String16>& args)
 {
     const size_t SIZE = 256;
@@ -426,7 +409,7 @@
         }
 
         result.append(" Files opened and/or mapped:\n");
-        snprintf(buffer, SIZE, "/proc/%d/maps", myTid());
+        snprintf(buffer, SIZE, "/proc/%d/maps", gettid());
         FILE *f = fopen(buffer, "r");
         if (f) {
             while (!feof(f)) {
@@ -446,13 +429,13 @@
             result.append("\n");
         }
 
-        snprintf(buffer, SIZE, "/proc/%d/fd", myTid());
+        snprintf(buffer, SIZE, "/proc/%d/fd", gettid());
         DIR *d = opendir(buffer);
         if (d) {
             struct dirent *ent;
             while((ent = readdir(d)) != NULL) {
                 if (strcmp(ent->d_name,".") && strcmp(ent->d_name,"..")) {
-                    snprintf(buffer, SIZE, "/proc/%d/fd/%s", myTid(), ent->d_name);
+                    snprintf(buffer, SIZE, "/proc/%d/fd/%s", gettid(), ent->d_name);
                     struct stat s;
                     if (lstat(buffer, &s) == 0) {
                         if ((s.st_mode & S_IFMT) == S_IFLNK) {
@@ -1164,7 +1147,7 @@
     mem = new MemoryBase(cache->getHeap(), 0, cache->size());
     *pSampleRate = cache->sampleRate();
     *pNumChannels = cache->channelCount();
-    *pFormat = cache->format();
+    *pFormat = (int)cache->format();
     LOGV("return memory @ %p, sampleRate=%u, channelCount = %d, format = %d", mem->pointer(), *pSampleRate, *pNumChannels, *pFormat);
 
 Exit:
diff --git a/media/libmediaplayerservice/MetadataRetrieverClient.cpp b/media/libmediaplayerservice/MetadataRetrieverClient.cpp
index 8f776b4..d574ea3 100644
--- a/media/libmediaplayerservice/MetadataRetrieverClient.cpp
+++ b/media/libmediaplayerservice/MetadataRetrieverClient.cpp
@@ -21,7 +21,6 @@
 
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <sys/resource.h>
 #include <dirent.h>
 #include <unistd.h>
 
@@ -40,18 +39,6 @@
 #include "MetadataRetrieverClient.h"
 #include "StagefrightMetadataRetriever.h"
 
-/* desktop Linux needs a little help with gettid() */
-#if defined(HAVE_GETTID) && !defined(HAVE_ANDROID_OS)
-#define __KERNEL__
-# include <linux/unistd.h>
-#ifdef _syscall0
-_syscall0(pid_t,gettid)
-#else
-pid_t gettid() { return syscall(__NR_gettid);}
-#endif
-#undef __KERNEL__
-#endif
-
 namespace android {
 
 extern player_type getPlayerType(const char* url);
diff --git a/media/libmediaplayerservice/MidiFile.cpp b/media/libmediaplayerservice/MidiFile.cpp
index 589c625..7e04523 100644
--- a/media/libmediaplayerservice/MidiFile.cpp
+++ b/media/libmediaplayerservice/MidiFile.cpp
@@ -29,17 +29,12 @@
 #include <libsonivox/eas_reverb.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <unistd.h>
 
 #include <system/audio.h>
 
 #include "MidiFile.h"
 
-#ifdef HAVE_GETTID
-static pid_t myTid() { return gettid(); }
-#else
-static pid_t myTid() { return getpid(); }
-#endif
-
 // ----------------------------------------------------------------------------
 
 namespace android {
@@ -455,7 +450,7 @@
     // signal main thread that we started
     {
         Mutex::Autolock l(mMutex);
-        mTid = myTid();
+        mTid = gettid();
         LOGV("render thread(%d) signal", mTid);
         mCondition.signal();
     }
diff --git a/media/libmediaplayerservice/StagefrightPlayer.cpp b/media/libmediaplayerservice/StagefrightPlayer.cpp
index 02ec911..870e290 100644
--- a/media/libmediaplayerservice/StagefrightPlayer.cpp
+++ b/media/libmediaplayerservice/StagefrightPlayer.cpp
@@ -214,4 +214,8 @@
     return OK;
 }
 
+status_t StagefrightPlayer::dump(int fd, const Vector<String16> &args) const {
+    return mPlayer->dump(fd, args);
+}
+
 }  // namespace android
diff --git a/media/libmediaplayerservice/StagefrightPlayer.h b/media/libmediaplayerservice/StagefrightPlayer.h
index ddd37e4..85a546d 100644
--- a/media/libmediaplayerservice/StagefrightPlayer.h
+++ b/media/libmediaplayerservice/StagefrightPlayer.h
@@ -61,6 +61,8 @@
     virtual status_t getMetadata(
             const media::Metadata::Filter& ids, Parcel *records);
 
+    virtual status_t dump(int fd, const Vector<String16> &args) const;
+
 private:
     AwesomePlayer *mPlayer;
 
diff --git a/media/libstagefright/AACWriter.cpp b/media/libstagefright/AACWriter.cpp
index 8413208..d133e91 100644
--- a/media/libstagefright/AACWriter.cpp
+++ b/media/libstagefright/AACWriter.cpp
@@ -27,7 +27,6 @@
 #include <media/stagefright/MetaData.h>
 #include <media/mediarecorder.h>
 #include <sys/prctl.h>
-#include <sys/resource.h>
 #include <fcntl.h>
 
 namespace android {
diff --git a/media/libstagefright/ACodec.cpp b/media/libstagefright/ACodec.cpp
index 642b3a3..d628301 100644
--- a/media/libstagefright/ACodec.cpp
+++ b/media/libstagefright/ACodec.cpp
@@ -888,8 +888,6 @@
     CHECK_EQ(err, (status_t)OK);
     CHECK_EQ((int)format.eCompressionFormat, (int)OMX_VIDEO_CodingUnused);
 
-    static const int OMX_QCOM_COLOR_FormatYVU420SemiPlanar = 0x7FA30C00;
-
     CHECK(format.eColorFormat == OMX_COLOR_FormatYUV420Planar
            || format.eColorFormat == OMX_COLOR_FormatYUV420SemiPlanar
            || format.eColorFormat == OMX_COLOR_FormatCbYCrY
diff --git a/media/libstagefright/AMRWriter.cpp b/media/libstagefright/AMRWriter.cpp
index b10d52c..6436071 100644
--- a/media/libstagefright/AMRWriter.cpp
+++ b/media/libstagefright/AMRWriter.cpp
@@ -23,7 +23,6 @@
 #include <media/stagefright/MetaData.h>
 #include <media/mediarecorder.h>
 #include <sys/prctl.h>
-#include <sys/resource.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
diff --git a/media/libstagefright/AwesomePlayer.cpp b/media/libstagefright/AwesomePlayer.cpp
index 3d270f89..aa7edcc 100644
--- a/media/libstagefright/AwesomePlayer.cpp
+++ b/media/libstagefright/AwesomePlayer.cpp
@@ -265,7 +265,7 @@
             // This isn't something that should be passed to the server.
             mUriHeaders.removeItemsAt(index);
 
-            mFlags |= INCOGNITO;
+            modifyFlags(INCOGNITO, SET);
         }
     }
 
@@ -279,6 +279,12 @@
     // ::finishSetDataSource_l to avoid blocking the calling thread in
     // setDataSource for any significant time.
 
+    {
+        Mutex::Autolock autoLock(mStatsLock);
+        mStats.mFd = -1;
+        mStats.mURI = mUri;
+    }
+
     return OK;
 }
 
@@ -298,6 +304,12 @@
 
     mFileSource = dataSource;
 
+    {
+        Mutex::Autolock autoLock(mStatsLock);
+        mStats.mFd = fd;
+        mStats.mURI = String8();
+    }
+
     return setDataSource_l(dataSource);
 }
 
@@ -336,6 +348,10 @@
 
         int32_t bitrate;
         if (!meta->findInt32(kKeyBitRate, &bitrate)) {
+            const char *mime;
+            CHECK(meta->findCString(kKeyMIMEType, &mime));
+            LOGW("track of type '%s' does not publish bitrate", mime);
+
             totalBitRate = -1;
             break;
         }
@@ -347,6 +363,14 @@
 
     LOGV("mBitrate = %lld bits/sec", mBitrate);
 
+    {
+        Mutex::Autolock autoLock(mStatsLock);
+        mStats.mBitrate = mBitrate;
+        mStats.mTracks.clear();
+        mStats.mAudioTrackIndex = -1;
+        mStats.mVideoTrackIndex = -1;
+    }
+
     bool haveAudio = false;
     bool haveVideo = false;
     for (size_t i = 0; i < extractor->countTracks(); ++i) {
@@ -370,10 +394,27 @@
                 mDisplayHeight = displayHeight;
             }
 
+            {
+                Mutex::Autolock autoLock(mStatsLock);
+                mStats.mVideoTrackIndex = mStats.mTracks.size();
+                mStats.mTracks.push();
+                TrackStat *stat =
+                    &mStats.mTracks.editItemAt(mStats.mVideoTrackIndex);
+                stat->mMIME = mime;
+            }
         } else if (!haveAudio && !strncasecmp(mime, "audio/", 6)) {
             setAudioSource(extractor->getTrack(i));
             haveAudio = true;
 
+            {
+                Mutex::Autolock autoLock(mStatsLock);
+                mStats.mAudioTrackIndex = mStats.mTracks.size();
+                mStats.mTracks.push();
+                TrackStat *stat =
+                    &mStats.mTracks.editItemAt(mStats.mAudioTrackIndex);
+                stat->mMIME = mime;
+            }
+
             if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_VORBIS)) {
                 // Only do this for vorbis audio, none of the other audio
                 // formats even support this ringtone specific hack and
@@ -383,7 +424,7 @@
                 int32_t loop;
                 if (fileMeta != NULL
                         && fileMeta->findInt32(kKeyAutoLoop, &loop) && loop != 0) {
-                    mFlags |= AUTO_LOOPING;
+                    modifyFlags(AUTO_LOOPING, SET);
                 }
             }
         } else if (!strcasecmp(mime, MEDIA_MIMETYPE_TEXT_3GPP)) {
@@ -431,7 +472,7 @@
     }
 
     if (mFlags & PREPARING) {
-        mFlags |= PREPARE_CANCELLED;
+        modifyFlags(PREPARE_CANCELLED, SET);
         if (mConnectingDataSource != NULL) {
             LOGI("interrupting the connection process");
             mConnectingDataSource->disconnect();
@@ -494,7 +535,7 @@
     }
 
     mDurationUs = -1;
-    mFlags = 0;
+    modifyFlags(0, ASSIGN);
     mExtractorFlags = 0;
     mTimeSourceDeltaUs = 0;
     mVideoTimeUs = 0;
@@ -510,6 +551,22 @@
 
     mBitrate = -1;
     mLastVideoTimeUs = -1;
+
+    {
+        Mutex::Autolock autoLock(mStatsLock);
+        mStats.mFd = -1;
+        mStats.mURI = String8();
+        mStats.mBitrate = -1;
+        mStats.mAudioTrackIndex = -1;
+        mStats.mVideoTrackIndex = -1;
+        mStats.mNumVideoFramesDecoded = 0;
+        mStats.mNumVideoFramesDropped = 0;
+        mStats.mVideoWidth = -1;
+        mStats.mVideoHeight = -1;
+        mStats.mFlags = 0;
+        mStats.mTracks.clear();
+    }
+
 }
 
 void AwesomePlayer::notifyListener_l(int msg, int ext1, int ext2) {
@@ -631,15 +688,16 @@
                         && (cachedDataRemaining < kLowWaterMarkBytes)) {
                     LOGI("cache is running low (< %d) , pausing.",
                          kLowWaterMarkBytes);
-                    mFlags |= CACHE_UNDERRUN;
+                    modifyFlags(CACHE_UNDERRUN, SET);
                     pause_l();
                     ensureCacheIsFetching_l();
+                    sendCacheStats();
                     notifyListener_l(MEDIA_INFO, MEDIA_INFO_BUFFERING_START);
                 } else if (eos || cachedDataRemaining > kHighWaterMarkBytes) {
                     if (mFlags & CACHE_UNDERRUN) {
                         LOGI("cache has filled up (> %d), resuming.",
                              kHighWaterMarkBytes);
-                        mFlags &= ~CACHE_UNDERRUN;
+                        modifyFlags(CACHE_UNDERRUN, CLEAR);
                         play_l();
                         notifyListener_l(MEDIA_INFO, MEDIA_INFO_BUFFERING_END);
                     } else if (mFlags & PREPARING) {
@@ -689,15 +747,16 @@
                 && (cachedDurationUs < kLowWaterMarkUs)) {
             LOGI("cache is running low (%.2f secs) , pausing.",
                  cachedDurationUs / 1E6);
-            mFlags |= CACHE_UNDERRUN;
+            modifyFlags(CACHE_UNDERRUN, SET);
             pause_l();
             ensureCacheIsFetching_l();
+            sendCacheStats();
             notifyListener_l(MEDIA_INFO, MEDIA_INFO_BUFFERING_START);
         } else if (eos || cachedDurationUs > highWaterMarkUs) {
             if (mFlags & CACHE_UNDERRUN) {
                 LOGI("cache has filled up (%.2f secs), resuming.",
                      cachedDurationUs / 1E6);
-                mFlags &= ~CACHE_UNDERRUN;
+                modifyFlags(CACHE_UNDERRUN, CLEAR);
                 play_l();
                 notifyListener_l(MEDIA_INFO, MEDIA_INFO_BUFFERING_END);
             } else if (mFlags & PREPARING) {
@@ -711,6 +770,18 @@
     postBufferingEvent_l();
 }
 
+void AwesomePlayer::sendCacheStats() {
+    sp<MediaPlayerBase> listener = mListener.promote();
+    if (listener != NULL && mCachedSource != NULL) {
+        int32_t kbps = 0;
+        status_t err = mCachedSource->getEstimatedBandwidthKbps(&kbps);
+        if (err == OK) {
+            listener->sendEvent(
+                MEDIA_INFO, MEDIA_INFO_NETWORK_BANDWIDTH, kbps);
+        }
+    }
+}
+
 void AwesomePlayer::onStreamDone() {
     // Posted whenever any stream finishes playing.
 
@@ -728,7 +799,7 @@
 
         pause_l(true /* at eos */);
 
-        mFlags |= AT_EOS;
+        modifyFlags(AT_EOS, SET);
         return;
     }
 
@@ -752,20 +823,20 @@
 
         pause_l(true /* at eos */);
 
-        mFlags |= AT_EOS;
+        modifyFlags(AT_EOS, SET);
     }
 }
 
 status_t AwesomePlayer::play() {
     Mutex::Autolock autoLock(mLock);
 
-    mFlags &= ~CACHE_UNDERRUN;
+    modifyFlags(CACHE_UNDERRUN, CLEAR);
 
     return play_l();
 }
 
 status_t AwesomePlayer::play_l() {
-    mFlags &= ~SEEK_PREVIEW;
+    modifyFlags(SEEK_PREVIEW, CLEAR);
 
     if (mFlags & PLAYING) {
         return OK;
@@ -779,8 +850,8 @@
         }
     }
 
-    mFlags |= PLAYING;
-    mFlags |= FIRST_FRAME;
+    modifyFlags(PLAYING, SET);
+    modifyFlags(FIRST_FRAME, SET);
 
     if (mDecryptHandle != NULL) {
         int64_t position;
@@ -814,7 +885,7 @@
                 delete mAudioPlayer;
                 mAudioPlayer = NULL;
 
-                mFlags &= ~(PLAYING | FIRST_FRAME);
+                modifyFlags((PLAYING | FIRST_FRAME), CLEAR);
 
                 if (mDecryptHandle != NULL) {
                     mDrmManagerClient->setPlaybackStatus(
@@ -866,7 +937,7 @@
     }
 
     if (!(mFlags & AUDIOPLAYER_STARTED)) {
-        mFlags |= AUDIOPLAYER_STARTED;
+        modifyFlags(AUDIOPLAYER_STARTED, SET);
 
         bool wasSeeking = mAudioPlayer->isSeeking();
 
@@ -890,7 +961,7 @@
         mAudioPlayer->resume();
     }
 
-    mFlags |= AUDIO_RUNNING;
+    modifyFlags(AUDIO_RUNNING, SET);
 
     mWatchForAudioEOS = true;
 
@@ -937,6 +1008,12 @@
         usableHeight = mDisplayHeight;
     }
 
+    {
+        Mutex::Autolock autoLock(mStatsLock);
+        mStats.mVideoWidth = usableWidth;
+        mStats.mVideoHeight = usableHeight;
+    }
+
     int32_t rotationDegrees;
     if (!mVideoTrack->getFormat()->findInt32(
                 kKeyRotation, &rotationDegrees)) {
@@ -999,7 +1076,7 @@
 status_t AwesomePlayer::pause() {
     Mutex::Autolock autoLock(mLock);
 
-    mFlags &= ~CACHE_UNDERRUN;
+    modifyFlags(CACHE_UNDERRUN, CLEAR);
 
     return pause_l();
 }
@@ -1021,15 +1098,15 @@
             mAudioPlayer->pause();
         }
 
-        mFlags &= ~AUDIO_RUNNING;
+        modifyFlags(AUDIO_RUNNING, CLEAR);
     }
 
     if (mFlags & TEXTPLAYER_STARTED) {
         mTextPlayer->pause();
-        mFlags &= ~TEXT_RUNNING;
+        modifyFlags(TEXT_RUNNING, CLEAR);
     }
 
-    mFlags &= ~PLAYING;
+    modifyFlags(PLAYING, CLEAR);
 
     if (mDecryptHandle != NULL) {
         mDrmManagerClient->setPlaybackStatus(mDecryptHandle,
@@ -1111,7 +1188,7 @@
         mSeeking = SEEK;
         mSeekNotificationSent = true;
         mSeekTimeUs = mLastVideoTimeUs;
-        mFlags &= ~(AT_EOS | AUDIO_AT_EOS | VIDEO_AT_EOS);
+        modifyFlags((AT_EOS | AUDIO_AT_EOS | VIDEO_AT_EOS), CLEAR);
     }
 
     if (wasPlaying) {
@@ -1129,10 +1206,10 @@
 status_t AwesomePlayer::setLooping(bool shouldLoop) {
     Mutex::Autolock autoLock(mLock);
 
-    mFlags = mFlags & ~LOOPING;
+    modifyFlags(LOOPING, CLEAR);
 
     if (shouldLoop) {
-        mFlags |= LOOPING;
+        modifyFlags(LOOPING, SET);
     }
 
     return OK;
@@ -1186,15 +1263,15 @@
                 return err;
             }
 
-            mFlags |= TEXT_RUNNING;
-            mFlags |= TEXTPLAYER_STARTED;
+            modifyFlags(TEXT_RUNNING, SET);
+            modifyFlags(TEXTPLAYER_STARTED, SET);
             return OK;
         } else { // to turn off the text track display
             if (mFlags  & TEXT_RUNNING) {
-                mFlags &= ~TEXT_RUNNING;
+                modifyFlags(TEXT_RUNNING, CLEAR);
             }
             if (mFlags  & TEXTPLAYER_STARTED) {
-                mFlags &= ~TEXTPLAYER_STARTED;
+                modifyFlags(TEXTPLAYER_STARTED, CLEAR);
             }
 
             return mTextPlayer->setTimedTextTrackIndex(index);
@@ -1221,7 +1298,7 @@
     }
 
     if (mFlags & CACHE_UNDERRUN) {
-        mFlags &= ~CACHE_UNDERRUN;
+        modifyFlags(CACHE_UNDERRUN, CLEAR);
         play_l();
     }
 
@@ -1236,7 +1313,7 @@
     mSeeking = SEEK;
     mSeekNotificationSent = false;
     mSeekTimeUs = timeUs;
-    mFlags &= ~(AT_EOS | AUDIO_AT_EOS | VIDEO_AT_EOS);
+    modifyFlags((AT_EOS | AUDIO_AT_EOS | VIDEO_AT_EOS), CLEAR);
 
     seekAudioIfNecessary_l();
 
@@ -1252,7 +1329,7 @@
         mSeekNotificationSent = true;
 
         if ((mFlags & PREPARED) && mVideoSource != NULL) {
-            mFlags |= SEEK_PREVIEW;
+            modifyFlags(SEEK_PREVIEW, SET);
             postVideoEvent_l();
         }
     }
@@ -1330,6 +1407,19 @@
         return OK;
     }
 
+    if (mAudioSource != NULL) {
+        Mutex::Autolock autoLock(mStatsLock);
+        TrackStat *stat = &mStats.mTracks.editItemAt(mStats.mAudioTrackIndex);
+
+        const char *component;
+        if (!mAudioSource->getFormat()
+                ->findCString(kKeyDecoderComponent, &component)) {
+            component = "none";
+        }
+
+        stat->mDecoderName = component;
+    }
+
     return mAudioSource != NULL ? OK : UNKNOWN_ERROR;
 }
 
@@ -1409,6 +1499,17 @@
         }
     }
 
+    if (mVideoSource != NULL) {
+        Mutex::Autolock autoLock(mStatsLock);
+        TrackStat *stat = &mStats.mTracks.editItemAt(mStats.mVideoTrackIndex);
+
+        const char *component;
+        CHECK(mVideoSource->getFormat()
+                ->findCString(kKeyDecoderComponent, &component));
+
+        stat->mDecoderName = component;
+    }
+
     return mVideoSource != NULL ? OK : UNKNOWN_ERROR;
 }
 
@@ -1438,7 +1539,7 @@
         mSeekNotificationSent = true;
     }
 
-    mFlags |= FIRST_FRAME;
+    modifyFlags(FIRST_FRAME, SET);
     mSeeking = NO_SEEK;
 
     if (mDecryptHandle != NULL) {
@@ -1477,7 +1578,7 @@
             if (mAudioPlayer != NULL && (mFlags & AUDIO_RUNNING)) {
                 mAudioPlayer->pause();
 
-                mFlags &= ~AUDIO_RUNNING;
+                modifyFlags(AUDIO_RUNNING, CLEAR);
             }
             mAudioSource->pause();
         }
@@ -1526,7 +1627,7 @@
                     startAudioPlayer_l();
                 }
 
-                mFlags |= VIDEO_AT_EOS;
+                modifyFlags(VIDEO_AT_EOS, SET);
                 postStreamDoneEvent_l(err);
                 return;
             }
@@ -1542,6 +1643,11 @@
 
             break;
         }
+
+        {
+            Mutex::Autolock autoLock(mStatsLock);
+            ++mStats.mNumVideoFramesDecoded;
+        }
     }
 
     int64_t timeUs;
@@ -1574,13 +1680,13 @@
 
     if ((mFlags & TEXTPLAYER_STARTED) && !(mFlags & (TEXT_RUNNING | SEEK_PREVIEW))) {
         mTextPlayer->resume();
-        mFlags |= TEXT_RUNNING;
+        modifyFlags(TEXT_RUNNING, SET);
     }
 
     TimeSource *ts = (mFlags & AUDIO_AT_EOS) ? &mSystemTimeSource : mTimeSource;
 
     if (mFlags & FIRST_FRAME) {
-        mFlags &= ~FIRST_FRAME;
+        modifyFlags(FIRST_FRAME, CLEAR);
         mTimeSourceDeltaUs = ts->getRealTimeUs() - timeUs;
     }
 
@@ -1632,6 +1738,11 @@
             mVideoBuffer->release();
             mVideoBuffer = NULL;
 
+            {
+                Mutex::Autolock autoLock(mStatsLock);
+                ++mStats.mNumVideoFramesDropped;
+            }
+
             postVideoEvent_l();
             return;
         }
@@ -1658,7 +1769,7 @@
     mVideoBuffer = NULL;
 
     if (wasSeeking != NO_SEEK && (mFlags & SEEK_PREVIEW)) {
-        mFlags &= ~SEEK_PREVIEW;
+        modifyFlags(SEEK_PREVIEW, CLEAR);
         return;
     }
 
@@ -1732,8 +1843,8 @@
     status_t finalStatus;
     if (mWatchForAudioEOS && mAudioPlayer->reachedEOS(&finalStatus)) {
         mWatchForAudioEOS = false;
-        mFlags |= AUDIO_AT_EOS;
-        mFlags |= FIRST_FRAME;
+        modifyFlags(AUDIO_AT_EOS, SET);
+        modifyFlags(FIRST_FRAME, SET);
         postStreamDoneEvent_l(finalStatus);
     }
 }
@@ -1787,7 +1898,7 @@
         mQueueStarted = true;
     }
 
-    mFlags |= PREPARING;
+    modifyFlags(PREPARING, SET);
     mAsyncPrepareEvent = new AwesomeEvent(
             this, &AwesomePlayer::onPrepareAsyncEvent);
 
@@ -1974,7 +2085,7 @@
     }
 
     mPrepareResult = err;
-    mFlags &= ~(PREPARING|PREPARE_CANCELLED|PREPARING_CONNECTED);
+    modifyFlags((PREPARING|PREPARE_CANCELLED|PREPARING_CONNECTED), CLEAR);
     mAsyncPrepareEvent = NULL;
     mPreparedCondition.broadcast();
 }
@@ -2022,7 +2133,7 @@
         }
     }
 
-    mFlags |= PREPARING_CONNECTED;
+    modifyFlags(PREPARING_CONNECTED, SET);
 
     if (isStreamingHTTP() || mRTSPController != NULL) {
         postBufferingEvent_l();
@@ -2043,8 +2154,8 @@
     }
 
     mPrepareResult = OK;
-    mFlags &= ~(PREPARING|PREPARE_CANCELLED|PREPARING_CONNECTED);
-    mFlags |= PREPARED;
+    modifyFlags((PREPARING|PREPARE_CANCELLED|PREPARING_CONNECTED), CLEAR);
+    modifyFlags(PREPARED, SET);
     mAsyncPrepareEvent = NULL;
     mPreparedCondition.broadcast();
 }
@@ -2083,6 +2194,10 @@
 
             return mTextPlayer->setParameter(key, request);
         }
+        case KEY_PARAMETER_CACHE_STAT_COLLECT_FREQ_MS:
+        {
+            return setCacheStatCollectFreq(request);
+        }
         default:
         {
             return ERROR_UNSUPPORTED;
@@ -2090,6 +2205,16 @@
     }
 }
 
+status_t AwesomePlayer::setCacheStatCollectFreq(const Parcel &request) {
+    if (mCachedSource != NULL) {
+        int32_t freqMs = request.readInt32();
+        LOGD("Request to keep cache stats in the past %d ms",
+            freqMs);
+        return mCachedSource->setCacheStatCollectFreq(freqMs);
+    }
+    return ERROR_UNSUPPORTED;
+}
+
 status_t AwesomePlayer::getParameter(int key, Parcel *reply) {
     return OK;
 }
@@ -2098,4 +2223,75 @@
     return mCachedSource != NULL || mWVMExtractor != NULL;
 }
 
+status_t AwesomePlayer::dump(int fd, const Vector<String16> &args) const {
+    Mutex::Autolock autoLock(mStatsLock);
+
+    FILE *out = fdopen(dup(fd), "w");
+
+    fprintf(out, " AwesomePlayer\n");
+    if (mStats.mFd < 0) {
+        fprintf(out, "  URI(%s)", mStats.mURI.string());
+    } else {
+        fprintf(out, "  fd(%d)", mStats.mFd);
+    }
+
+    fprintf(out, ", flags(0x%08x)", mStats.mFlags);
+
+    if (mStats.mBitrate >= 0) {
+        fprintf(out, ", bitrate(%lld bps)", mStats.mBitrate);
+    }
+
+    fprintf(out, "\n");
+
+    for (size_t i = 0; i < mStats.mTracks.size(); ++i) {
+        const TrackStat &stat = mStats.mTracks.itemAt(i);
+
+        fprintf(out, "  Track %d\n", i + 1);
+        fprintf(out, "   MIME(%s)", stat.mMIME.string());
+
+        if (!stat.mDecoderName.isEmpty()) {
+            fprintf(out, ", decoder(%s)", stat.mDecoderName.string());
+        }
+
+        fprintf(out, "\n");
+
+        if ((ssize_t)i == mStats.mVideoTrackIndex) {
+            fprintf(out,
+                    "   videoDimensions(%d x %d), "
+                    "numVideoFramesDecoded(%lld), "
+                    "numVideoFramesDropped(%lld)\n",
+                    mStats.mVideoWidth,
+                    mStats.mVideoHeight,
+                    mStats.mNumVideoFramesDecoded,
+                    mStats.mNumVideoFramesDropped);
+        }
+    }
+
+    fclose(out);
+    out = NULL;
+
+    return OK;
+}
+
+void AwesomePlayer::modifyFlags(unsigned value, FlagMode mode) {
+    switch (mode) {
+        case SET:
+            mFlags |= value;
+            break;
+        case CLEAR:
+            mFlags &= ~value;
+            break;
+        case ASSIGN:
+            mFlags = value;
+            break;
+        default:
+            TRESPASS();
+    }
+
+    {
+        Mutex::Autolock autoLock(mStatsLock);
+        mStats.mFlags = mFlags;
+    }
+}
+
 }  // namespace android
diff --git a/media/libstagefright/CameraSource.cpp b/media/libstagefright/CameraSource.cpp
index a1f04d3..61bb2a8 100644
--- a/media/libstagefright/CameraSource.cpp
+++ b/media/libstagefright/CameraSource.cpp
@@ -701,12 +701,11 @@
         return;
     }
 
-    if (mNumFramesReceived > 0 &&
-        timestampUs - mLastFrameTimestampUs > mGlitchDurationThresholdUs) {
-        if (mNumGlitches % 10 == 0) {  // Don't spam the log
-            LOGV("Long delay detected in video recording");
+    if (mNumFramesReceived > 0) {
+        CHECK(timestampUs > mLastFrameTimestampUs);
+        if (timestampUs - mLastFrameTimestampUs > mGlitchDurationThresholdUs) {
+            ++mNumGlitches;
         }
-        ++mNumGlitches;
     }
 
     // May need to skip frame or modify timestamp. Currently implemented
@@ -732,6 +731,7 @@
     }
     ++mNumFramesReceived;
 
+    CHECK(data != NULL && data->size() > 0);
     mFramesReceived.push_back(data);
     int64_t timeUs = mStartTimeUs + (timestampUs - mFirstFrameTimeUs);
     mFrameTimes.push_back(timeUs);
diff --git a/media/libstagefright/CameraSourceTimeLapse.cpp b/media/libstagefright/CameraSourceTimeLapse.cpp
index 3689557..cc22574 100644
--- a/media/libstagefright/CameraSourceTimeLapse.cpp
+++ b/media/libstagefright/CameraSourceTimeLapse.cpp
@@ -486,7 +486,8 @@
             if (mForceRead) {
                 LOGV("dataCallbackTimestamp timelapse: forced read");
                 mForceRead = false;
-                *timestampUs = mLastFrameTimestampUs;
+                *timestampUs =
+                    mLastFrameTimestampUs + mTimeBetweenTimeLapseVideoFramesUs;
                 return false;
             }
         }
diff --git a/media/libstagefright/HTTPBase.cpp b/media/libstagefright/HTTPBase.cpp
index 58b17a7..c0ae29d 100644
--- a/media/libstagefright/HTTPBase.cpp
+++ b/media/libstagefright/HTTPBase.cpp
@@ -14,6 +14,10 @@
  * limitations under the License.
  */
 
+//#define LOG_NDEBUG 0
+#define LOG_TAG "HTTPBase"
+#include <utils/Log.h>
+
 #include "include/HTTPBase.h"
 
 #if CHROMIUM_AVAILABLE
@@ -22,11 +26,19 @@
 
 #include "include/NuHTTPDataSource.h"
 
+#include <media/stagefright/foundation/ALooper.h>
 #include <cutils/properties.h>
 
 namespace android {
 
-HTTPBase::HTTPBase() {}
+HTTPBase::HTTPBase()
+    : mNumBandwidthHistoryItems(0),
+      mTotalTransferTimeUs(0),
+      mTotalTransferBytes(0),
+      mPrevBandwidthMeasureTimeUs(0),
+      mPrevEstimatedBandWidthKbps(0),
+      mBandWidthCollectFreqMs(5000) {
+}
 
 // static
 sp<HTTPBase> HTTPBase::Create(uint32_t flags) {
@@ -42,4 +54,69 @@
     }
 }
 
+void HTTPBase::addBandwidthMeasurement(
+        size_t numBytes, int64_t delayUs) {
+    Mutex::Autolock autoLock(mLock);
+
+    BandwidthEntry entry;
+    entry.mDelayUs = delayUs;
+    entry.mNumBytes = numBytes;
+    mTotalTransferTimeUs += delayUs;
+    mTotalTransferBytes += numBytes;
+
+    mBandwidthHistory.push_back(entry);
+    if (++mNumBandwidthHistoryItems > 100) {
+        BandwidthEntry *entry = &*mBandwidthHistory.begin();
+        mTotalTransferTimeUs -= entry->mDelayUs;
+        mTotalTransferBytes -= entry->mNumBytes;
+        mBandwidthHistory.erase(mBandwidthHistory.begin());
+        --mNumBandwidthHistoryItems;
+
+        int64_t timeNowUs = ALooper::GetNowUs();
+        if (timeNowUs - mPrevBandwidthMeasureTimeUs >=
+                mBandWidthCollectFreqMs * 1000LL) {
+
+            if (mPrevBandwidthMeasureTimeUs != 0) {
+                mPrevEstimatedBandWidthKbps =
+                    (mTotalTransferBytes * 8E3 / mTotalTransferTimeUs);
+            }
+            mPrevBandwidthMeasureTimeUs = timeNowUs;
+        }
+    }
+
+}
+
+bool HTTPBase::estimateBandwidth(int32_t *bandwidth_bps) {
+    Mutex::Autolock autoLock(mLock);
+
+    if (mNumBandwidthHistoryItems < 2) {
+        return false;
+    }
+
+    *bandwidth_bps = ((double)mTotalTransferBytes * 8E6 / mTotalTransferTimeUs);
+
+    return true;
+}
+
+status_t HTTPBase::getEstimatedBandwidthKbps(int32_t *kbps) {
+    Mutex::Autolock autoLock(mLock);
+    *kbps = mPrevEstimatedBandWidthKbps;
+    return OK;
+}
+
+status_t HTTPBase::setBandwidthStatCollectFreq(int32_t freqMs) {
+    Mutex::Autolock autoLock(mLock);
+
+    if (freqMs < kMinBandwidthCollectFreqMs
+            || freqMs > kMaxBandwidthCollectFreqMs) {
+
+        LOGE("frequency (%d ms) is out of range [1000, 60000]", freqMs);
+        return BAD_VALUE;
+    }
+
+    LOGI("frequency set to %d ms", freqMs);
+    mBandWidthCollectFreqMs = freqMs;
+    return OK;
+}
+
 }  // namespace android
diff --git a/media/libstagefright/HTTPStream.cpp b/media/libstagefright/HTTPStream.cpp
index 2caf211..a156da6 100644
--- a/media/libstagefright/HTTPStream.cpp
+++ b/media/libstagefright/HTTPStream.cpp
@@ -139,6 +139,9 @@
         int s, void *data, size_t size, int flags, bool sendData) {
     ssize_t result = 0;
 
+    if (s < 0) {
+        return -1;
+    }
     while (size > 0) {
         fd_set rs, ws, es;
         FD_ZERO(&rs);
diff --git a/media/libstagefright/MPEG4Writer.cpp b/media/libstagefright/MPEG4Writer.cpp
index f6a8b17..58f6699 100644
--- a/media/libstagefright/MPEG4Writer.cpp
+++ b/media/libstagefright/MPEG4Writer.cpp
@@ -22,7 +22,6 @@
 
 #include <pthread.h>
 #include <sys/prctl.h>
-#include <sys/resource.h>
 
 #include <media/stagefright/MPEG4Writer.h>
 #include <media/stagefright/MediaBuffer.h>
@@ -128,17 +127,28 @@
     size_t        mNumStssTableEntries;
     List<int32_t> mStssTableEntries;
 
-    size_t        mNumSttsTableEntries;
     struct SttsTableEntry {
 
-        SttsTableEntry(uint32_t count, uint32_t durationUs)
-            : sampleCount(count), sampleDurationUs(durationUs) {}
+        SttsTableEntry(uint32_t count, uint32_t duration)
+            : sampleCount(count), sampleDuration(duration) {}
 
         uint32_t sampleCount;
-        uint32_t sampleDurationUs;
+        uint32_t sampleDuration;  // time scale based
     };
+    size_t        mNumSttsTableEntries;
     List<SttsTableEntry> mSttsTableEntries;
 
+    struct CttsTableEntry {
+        CttsTableEntry(uint32_t count, int32_t timescaledDur)
+            : sampleCount(count), sampleDuration(timescaledDur) {}
+
+        uint32_t sampleCount;
+        int32_t sampleDuration;  // time scale based
+    };
+    bool          mHasNegativeCttsDeltaDuration;
+    size_t        mNumCttsTableEntries;
+    List<CttsTableEntry> mCttsTableEntries;
+
     // Sequence parameter set or picture parameter set
     struct AVCParamSet {
         AVCParamSet(uint16_t length, const uint8_t *data)
@@ -216,7 +226,10 @@
     void updateTrackSizeEstimate();
     void addOneStscTableEntry(size_t chunkId, size_t sampleId);
     void addOneStssTableEntry(size_t sampleId);
-    void addOneSttsTableEntry(size_t sampleCount, int64_t durationUs);
+
+    // Duration is time scale based
+    void addOneSttsTableEntry(size_t sampleCount, int32_t timescaledDur);
+    void addOneCttsTableEntry(size_t sampleCount, int32_t timescaledDur);
     void sendTrackSummary(bool hasMultipleTracks);
 
     // Write the boxes
@@ -225,6 +238,7 @@
     void writeStszBox();
     void writeStssBox();
     void writeSttsBox();
+    void writeCttsBox();
     void writeD263Box();
     void writePaspBox();
     void writeAvccBox();
@@ -1145,6 +1159,7 @@
         mEstimatedTrackSizeBytes += mNumStscTableEntries * 12 +  // stsc box size
                                     mNumStssTableEntries * 4 +   // stss box size
                                     mNumSttsTableEntries * 8 +   // stts box size
+                                    mNumCttsTableEntries * 8 +   // ctts box size
                                     stcoBoxSizeBytes +           // stco box size
                                     stszBoxSizeBytes;            // stsz box size
     }
@@ -1164,13 +1179,27 @@
 }
 
 void MPEG4Writer::Track::addOneSttsTableEntry(
-        size_t sampleCount, int64_t durationUs) {
+        size_t sampleCount, int32_t duration) {
 
-    SttsTableEntry sttsEntry(sampleCount, durationUs);
+    SttsTableEntry sttsEntry(sampleCount, duration);
     mSttsTableEntries.push_back(sttsEntry);
     ++mNumSttsTableEntries;
 }
 
+void MPEG4Writer::Track::addOneCttsTableEntry(
+        size_t sampleCount, int32_t duration) {
+
+    if (mIsAudio) {
+        return;
+    }
+    if (duration < 0 && !mHasNegativeCttsDeltaDuration) {
+        mHasNegativeCttsDeltaDuration = true;
+    }
+    CttsTableEntry cttsEntry(sampleCount, duration);
+    mCttsTableEntries.push_back(cttsEntry);
+    ++mNumCttsTableEntries;
+}
+
 void MPEG4Writer::Track::addChunkOffset(off64_t offset) {
     ++mNumStcoTableEntries;
     mChunkOffsets.push_back(offset);
@@ -1308,6 +1337,7 @@
     size_t outstandingChunks = 0;
     Chunk chunk;
     while (findChunkToWrite(&chunk)) {
+        writeChunkToFile(&chunk);
         ++outstandingChunks;
     }
 
@@ -1480,6 +1510,7 @@
     mNumStssTableEntries = 0;
     mNumStscTableEntries = 0;
     mNumSttsTableEntries = 0;
+    mNumCttsTableEntries = 0;
     mMdatSizeBytes = 0;
     mIsMediaTimeAdjustmentOn = false;
     mPrevMediaTimeAdjustTimestampUs = 0;
@@ -1488,6 +1519,7 @@
     mTotalDriftTimeToAdjustUs = 0;
     mPrevTotalAccumDriftTimeUs = 0;
     mMaxChunkDurationUs = 0;
+    mHasNegativeCttsDeltaDuration = false;
 
     pthread_create(&mThread, &attr, ThreadWrapper, this);
     pthread_attr_destroy(&attr);
@@ -1929,21 +1961,36 @@
     int64_t chunkTimestampUs = 0;
     int32_t nChunks = 0;
     int32_t nZeroLengthFrames = 0;
-    int64_t lastTimestampUs = 0;  // Previous sample time stamp in ms
-    int64_t lastDurationUs = 0;   // Between the previous two samples in ms
-    int64_t currDurationTicks = 0;  // Timescale based ticks
-    int64_t lastDurationTicks = 0;  // Timescale based ticks
-    int32_t sampleCount = 1;      // Sample count in the current stts table entry
-    uint32_t previousSampleSize = 0;  // Size of the previous sample
+    int64_t lastTimestampUs = 0;      // Previous sample time stamp
+    int64_t lastCttsTimeUs = 0;       // Previous sample time stamp
+    int64_t lastDurationUs = 0;       // Between the previous two samples
+    int64_t currDurationTicks = 0;    // Timescale based ticks
+    int64_t lastDurationTicks = 0;    // Timescale based ticks
+    int32_t sampleCount = 1;          // Sample count in the current stts table entry
+    int64_t currCttsDurTicks = 0;     // Timescale based ticks
+    int64_t lastCttsDurTicks = 0;     // Timescale based ticks
+    int32_t cttsSampleCount = 1;      // Sample count in the current ctts table entry
+    uint32_t previousSampleSize = 0;      // Size of the previous sample
     int64_t previousPausedDurationUs = 0;
-    int64_t timestampUs;
+    int64_t timestampUs = 0;
+    int64_t cttsDeltaTimeUs = 0;
+    bool hasBFrames = false;
 
+#if 1
+    // XXX: Samsung's video encoder's output buffer timestamp
+    // is not correct. see bug 4724339
+    char value[PROPERTY_VALUE_MAX];
+    if (property_get("rw.media.record.hasb", value, NULL) &&
+        (!strcasecmp(value, "true") || !strcasecmp(value, "1"))) {
+        hasBFrames = true;
+    }
+#endif
     if (mIsAudio) {
         prctl(PR_SET_NAME, (unsigned long)"AudioTrackEncoding", 0, 0, 0);
     } else {
         prctl(PR_SET_NAME, (unsigned long)"VideoTrackEncoding", 0, 0, 0);
     }
-    setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_AUDIO);
+    androidSetThreadPriority(0, ANDROID_PRIORITY_AUDIO);
 
     sp<MetaData> meta_data;
 
@@ -2060,7 +2107,6 @@
          *
          */
         CHECK(meta_data->findInt64(kKeyTime, &timestampUs));
-        LOGV("%s timestampUs: %lld", mIsAudio? "Audio": "Video", timestampUs);
 
 ////////////////////////////////////////////////////////////////////////////////
         if (mNumSamples == 0) {
@@ -2081,6 +2127,24 @@
 
         timestampUs -= previousPausedDurationUs;
         CHECK(timestampUs >= 0);
+        if (!mIsAudio && hasBFrames) {
+            /*
+             * Composition time: timestampUs
+             * Decoding time: decodingTimeUs
+             * Composition time delta = composition time - decoding time
+             *
+             * We save picture decoding time stamp delta in stts table entries,
+             * and composition time delta duration in ctts table entries.
+             */
+            int64_t decodingTimeUs;
+            CHECK(meta_data->findInt64(kKeyDecodingTime, &decodingTimeUs));
+            decodingTimeUs -= previousPausedDurationUs;
+            int64_t timeUs = decodingTimeUs;
+            cttsDeltaTimeUs = timestampUs - decodingTimeUs;
+            timestampUs = decodingTimeUs;
+            LOGV("decoding time: %lld and ctts delta time: %lld",
+                timestampUs, cttsDeltaTimeUs);
+        }
 
         // Media time adjustment for real-time applications
         if (mIsRealTimeRecording) {
@@ -2131,11 +2195,23 @@
             if (mNumSamples == 3 || currDurationTicks != lastDurationTicks) {
                 LOGV("%s lastDurationUs: %lld us, currDurationTicks: %lld us",
                         mIsAudio? "Audio": "Video", lastDurationUs, currDurationTicks);
-                addOneSttsTableEntry(sampleCount, lastDurationUs);
+                addOneSttsTableEntry(sampleCount, lastDurationTicks);
                 sampleCount = 1;
             } else {
                 ++sampleCount;
             }
+
+            if (!mIsAudio) {
+                currCttsDurTicks =
+                     ((cttsDeltaTimeUs * mTimeScale + 500000LL) / 1000000LL -
+                     (lastCttsTimeUs * mTimeScale + 500000LL) / 1000000LL);
+                if (currCttsDurTicks != lastCttsDurTicks) {
+                    addOneCttsTableEntry(cttsSampleCount, lastCttsDurTicks);
+                    cttsSampleCount = 1;
+                } else {
+                    ++cttsSampleCount;
+                }
+            }
         }
         if (mSamplesHaveSameSize) {
             if (mNumSamples >= 2 && previousSampleSize != sampleSize) {
@@ -2149,6 +2225,11 @@
         lastDurationTicks = currDurationTicks;
         lastTimestampUs = timestampUs;
 
+        if (!mIsAudio) {
+            lastCttsDurTicks = currCttsDurTicks;
+            lastCttsTimeUs = cttsDeltaTimeUs;
+        }
+
         if (isSync != 0) {
             addOneStssTableEntry(mNumSamples);
         }
@@ -2217,19 +2298,23 @@
     // frame's duration.
     if (mNumSamples == 1) {
         lastDurationUs = 0;  // A single sample's duration
+        lastDurationTicks = 0;
+        lastCttsDurTicks = 0;
     } else {
         ++sampleCount;  // Count for the last sample
+        ++cttsSampleCount;
     }
 
     if (mNumSamples <= 2) {
-        addOneSttsTableEntry(1, lastDurationUs);
+        addOneSttsTableEntry(1, lastDurationTicks);
         if (sampleCount - 1 > 0) {
-            addOneSttsTableEntry(sampleCount - 1, lastDurationUs);
+            addOneSttsTableEntry(sampleCount - 1, lastDurationTicks);
         }
     } else {
-        addOneSttsTableEntry(sampleCount, lastDurationUs);
+        addOneSttsTableEntry(sampleCount, lastDurationTicks);
     }
 
+    addOneCttsTableEntry(cttsSampleCount, lastCttsDurTicks);
     mTrackDurationUs += lastDurationUs;
     mReachedEOS = true;
 
@@ -2428,6 +2513,7 @@
     }
     mOwner->endBox();  // stsd
     writeSttsBox();
+    writeCttsBox();
     if (!mIsAudio) {
         writeStssBox();
     }
@@ -2772,23 +2858,55 @@
         CHECK(mStartTimestampUs > moovStartTimeUs);
         trackStartTimeOffsetUs = mStartTimestampUs - moovStartTimeUs;
     }
-    int64_t prevTimestampUs = trackStartTimeOffsetUs;
-    for (List<SttsTableEntry>::iterator it = mSttsTableEntries.begin();
-        it != mSttsTableEntries.end(); ++it) {
+    List<SttsTableEntry>::iterator it = mSttsTableEntries.begin();
+    CHECK(it != mSttsTableEntries.end() && it->sampleCount == 1);
+    mOwner->writeInt32(it->sampleCount);
+    int32_t dur = (trackStartTimeOffsetUs * mTimeScale + 500000LL) / 1000000LL;
+    mOwner->writeInt32(dur + it->sampleDuration);
+
+    int64_t totalCount = 1;
+    while (++it != mSttsTableEntries.end()) {
         mOwner->writeInt32(it->sampleCount);
-
-        // Make sure that we are calculating the sample duration the exactly
-        // same way as we made decision on how to create stts entries.
-        int64_t currTimestampUs = prevTimestampUs + it->sampleDurationUs;
-        int32_t dur = ((currTimestampUs * mTimeScale + 500000LL) / 1000000LL -
-            (prevTimestampUs * mTimeScale + 500000LL) / 1000000LL);
-        prevTimestampUs += (it->sampleCount * it->sampleDurationUs);
-
-        mOwner->writeInt32(dur);
+        mOwner->writeInt32(it->sampleDuration);
+        totalCount += it->sampleCount;
     }
+    CHECK(totalCount == mNumSamples);
     mOwner->endBox();  // stts
 }
 
+void MPEG4Writer::Track::writeCttsBox() {
+    if (mIsAudio) {  // ctts is not for audio
+        return;
+    }
+
+    // Do not write ctts box when there is no need to have it.
+    if ((mNumCttsTableEntries == 1 &&
+        mCttsTableEntries.begin()->sampleDuration == 0) ||
+        mNumCttsTableEntries == 0) {
+        return;
+    }
+
+    LOGV("ctts box has %d entries", mNumCttsTableEntries);
+
+    mOwner->beginBox("ctts");
+    if (mHasNegativeCttsDeltaDuration) {
+        mOwner->writeInt32(0x00010000);  // version=1, flags=0
+    } else {
+        mOwner->writeInt32(0);  // version=0, flags=0
+    }
+    mOwner->writeInt32(mNumCttsTableEntries);
+
+    int64_t totalCount = 0;
+    for (List<CttsTableEntry>::iterator it = mCttsTableEntries.begin();
+         it != mCttsTableEntries.end(); ++it) {
+        mOwner->writeInt32(it->sampleCount);
+        mOwner->writeInt32(it->sampleDuration);
+        totalCount += it->sampleCount;
+    }
+    CHECK(totalCount == mNumSamples);
+    mOwner->endBox();  // ctts
+}
+
 void MPEG4Writer::Track::writeStssBox() {
     mOwner->beginBox("stss");
     mOwner->writeInt32(0);  // version=0, flags=0
@@ -2862,8 +2980,8 @@
      * For historical reasons, any user data start
      * with "\0xA9", must be followed by its assoicated
      * language code.
-     * 0x0012: locale en
-     * 0x15c7: language 5575
+     * 0x0012: text string length
+     * 0x15c7: lang (locale) code: en
      */
     writeInt32(0x001215c7);
     writeLatitude(mLatitudex10000);
diff --git a/media/libstagefright/NuCachedSource2.cpp b/media/libstagefright/NuCachedSource2.cpp
index 81f2e47..77a6602 100644
--- a/media/libstagefright/NuCachedSource2.cpp
+++ b/media/libstagefright/NuCachedSource2.cpp
@@ -19,6 +19,7 @@
 #include <utils/Log.h>
 
 #include "include/NuCachedSource2.h"
+#include "include/HTTPBase.h"
 
 #include <media/stagefright/foundation/ADebug.h>
 #include <media/stagefright/foundation/AMessage.h>
@@ -201,6 +202,22 @@
     mCache = NULL;
 }
 
+status_t NuCachedSource2::getEstimatedBandwidthKbps(int32_t *kbps) {
+    if (mSource->flags() & kIsHTTPBasedSource) {
+        HTTPBase* source = static_cast<HTTPBase *>(mSource.get());
+        return source->getEstimatedBandwidthKbps(kbps);
+    }
+    return ERROR_UNSUPPORTED;
+}
+
+status_t NuCachedSource2::setCacheStatCollectFreq(int32_t freqMs) {
+    if (mSource->flags() & kIsHTTPBasedSource) {
+        HTTPBase *source = static_cast<HTTPBase *>(mSource.get());
+        return source->setBandwidthStatCollectFreq(freqMs);
+    }
+    return ERROR_UNSUPPORTED;
+}
+
 status_t NuCachedSource2::initCheck() const {
     return mSource->initCheck();
 }
@@ -210,7 +227,9 @@
 }
 
 uint32_t NuCachedSource2::flags() {
-    return (mSource->flags() & ~kWantsPrefetching) | kIsCachingDataSource;
+    // Remove HTTP related flags since NuCachedSource2 is not HTTP-based.
+    uint32_t flags = mSource->flags() & ~(kWantsPrefetching | kIsHTTPBasedSource);
+    return (flags | kIsCachingDataSource);
 }
 
 void NuCachedSource2::onMessageReceived(const sp<AMessage> &msg) {
diff --git a/media/libstagefright/NuHTTPDataSource.cpp b/media/libstagefright/NuHTTPDataSource.cpp
index 821ba9b..dac2ee4 100644
--- a/media/libstagefright/NuHTTPDataSource.cpp
+++ b/media/libstagefright/NuHTTPDataSource.cpp
@@ -97,9 +97,6 @@
       mContentLengthValid(false),
       mHasChunkedTransferEncoding(false),
       mChunkDataBytesLeft(0),
-      mNumBandwidthHistoryItems(0),
-      mTotalTransferTimeUs(0),
-      mTotalTransferBytes(0),
       mDecryptHandle(NULL),
       mDrmManagerClient(NULL) {
 }
@@ -431,7 +428,7 @@
         }
 
         int64_t delayUs = ALooper::GetNowUs() - startTimeUs;
-        addBandwidthMeasurement_l(n, delayUs);
+        addBandwidthMeasurement(n, delayUs);
 
         numBytesRead += (size_t)n;
 
@@ -467,7 +464,7 @@
 }
 
 uint32_t NuHTTPDataSource::flags() {
-    return kWantsPrefetching;
+    return kWantsPrefetching | kIsHTTPBasedSource;
 }
 
 // static
@@ -517,36 +514,6 @@
     }
 }
 
-bool NuHTTPDataSource::estimateBandwidth(int32_t *bandwidth_bps) {
-    Mutex::Autolock autoLock(mLock);
-
-    if (mNumBandwidthHistoryItems < 2) {
-        return false;
-    }
-
-    *bandwidth_bps = ((double)mTotalTransferBytes * 8E6 / mTotalTransferTimeUs);
-
-    return true;
-}
-
-void NuHTTPDataSource::addBandwidthMeasurement_l(
-        size_t numBytes, int64_t delayUs) {
-    BandwidthEntry entry;
-    entry.mDelayUs = delayUs;
-    entry.mNumBytes = numBytes;
-    mTotalTransferTimeUs += delayUs;
-    mTotalTransferBytes += numBytes;
-
-    mBandwidthHistory.push_back(entry);
-    if (++mNumBandwidthHistoryItems > 100) {
-        BandwidthEntry *entry = &*mBandwidthHistory.begin();
-        mTotalTransferTimeUs -= entry->mDelayUs;
-        mTotalTransferBytes -= entry->mNumBytes;
-        mBandwidthHistory.erase(mBandwidthHistory.begin());
-        --mNumBandwidthHistoryItems;
-    }
-}
-
 sp<DecryptHandle> NuHTTPDataSource::DrmInitialization() {
     if (mDrmManagerClient == NULL) {
         mDrmManagerClient = new DrmManagerClient();
diff --git a/media/libstagefright/OMXCodec.cpp b/media/libstagefright/OMXCodec.cpp
index 6339710..c4fcc79 100644
--- a/media/libstagefright/OMXCodec.cpp
+++ b/media/libstagefright/OMXCodec.cpp
@@ -61,8 +61,6 @@
 
 namespace android {
 
-static const int OMX_QCOM_COLOR_FormatYVU420SemiPlanar = 0x7FA30C00;
-
 struct CodecInfo {
     const char *mime;
     const char *codec;
@@ -200,6 +198,7 @@
     { MEDIA_MIMETYPE_VIDEO_AVC, "OMX.qcom.video.decoder.avc" },
     { MEDIA_MIMETYPE_VIDEO_AVC, "OMX.TI.Video.Decoder" },
     { MEDIA_MIMETYPE_VIDEO_AVC, "OMX.SEC.AVC.Decoder" },
+    { MEDIA_MIMETYPE_VIDEO_AVC, "OMX.google.h264.decoder" },
     { MEDIA_MIMETYPE_VIDEO_AVC, "OMX.google.avc.decoder" },
     { MEDIA_MIMETYPE_VIDEO_AVC, "AVCDecoder" },
     { MEDIA_MIMETYPE_AUDIO_VORBIS, "OMX.google.vorbis.decoder" },
@@ -1388,8 +1387,6 @@
         CHECK_EQ(err, (status_t)OK);
         CHECK_EQ((int)format.eCompressionFormat, (int)OMX_VIDEO_CodingUnused);
 
-        static const int OMX_QCOM_COLOR_FormatYVU420SemiPlanar = 0x7FA30C00;
-
         CHECK(format.eColorFormat == OMX_COLOR_FormatYUV420Planar
                || format.eColorFormat == OMX_COLOR_FormatYUV420SemiPlanar
                || format.eColorFormat == OMX_COLOR_FormatCbYCrY
@@ -1646,17 +1643,7 @@
         return PERMISSION_DENIED;
     }
 
-    OMX_PARAM_PORTDEFINITIONTYPE def;
-    InitOMXParams(&def);
-    def.nPortIndex = portIndex;
-
-    status_t err = mOMX->getParameter(
-            mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));
-
-    if (err != OK) {
-        return err;
-    }
-
+    status_t err = OK;
     if (mIsMetaDataStoredInVideoBuffers && portIndex == kPortIndexInput) {
         err = mOMX->storeMetaDataInBuffers(mNode, kPortIndexInput, OMX_TRUE);
         if (err != OK) {
@@ -1665,6 +1652,17 @@
         }
     }
 
+    OMX_PARAM_PORTDEFINITIONTYPE def;
+    InitOMXParams(&def);
+    def.nPortIndex = portIndex;
+
+    err = mOMX->getParameter(
+            mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));
+
+    if (err != OK) {
+        return err;
+    }
+
     CODEC_LOGI("allocating %lu buffers of size %lu on %s port",
             def.nBufferCountActual, def.nBufferSize,
             portIndex == kPortIndexInput ? "input" : "output");
@@ -1983,6 +1981,20 @@
     return bufInfo;
 }
 
+int64_t OMXCodec::retrieveDecodingTimeUs(bool isCodecSpecific) {
+    CHECK(mIsEncoder);
+    CHECK(!mDecodingTimeList.empty());
+    List<int64_t>::iterator it = mDecodingTimeList.begin();
+    int64_t timeUs = *it;
+
+    // If the output buffer is codec specific configuration,
+    // do not remove the decoding time from the list.
+    if (!isCodecSpecific) {
+        mDecodingTimeList.erase(it);
+    }
+    return timeUs;
+}
+
 void OMXCodec::on_message(const omx_message &msg) {
     if (mState == ERROR) {
         LOGW("Dropping OMX message - we're in ERROR state.");
@@ -2130,14 +2142,21 @@
                 if (msg.u.extended_buffer_data.flags & OMX_BUFFERFLAG_SYNCFRAME) {
                     buffer->meta_data()->setInt32(kKeyIsSyncFrame, true);
                 }
+                bool isCodecSpecific = false;
                 if (msg.u.extended_buffer_data.flags & OMX_BUFFERFLAG_CODECCONFIG) {
                     buffer->meta_data()->setInt32(kKeyIsCodecConfig, true);
+                    isCodecSpecific = true;
                 }
 
                 if (isGraphicBuffer || mQuirks & kOutputBuffersAreUnreadable) {
                     buffer->meta_data()->setInt32(kKeyIsUnreadable, true);
                 }
 
+                if (mIsEncoder) {
+                    int64_t decodingTimeUs = retrieveDecodingTimeUs(isCodecSpecific);
+                    buffer->meta_data()->setInt64(kKeyDecodingTime, decodingTimeUs);
+                }
+
                 buffer->meta_data()->setPointer(
                         kKeyPlatformPrivate,
                         msg.u.extended_buffer_data.platform_private);
@@ -2940,6 +2959,9 @@
         int64_t lastBufferTimeUs;
         CHECK(srcBuffer->meta_data()->findInt64(kKeyTime, &lastBufferTimeUs));
         CHECK(lastBufferTimeUs >= 0);
+        if (mIsEncoder) {
+            mDecodingTimeList.push_back(lastBufferTimeUs);
+        }
 
         if (offset == 0) {
             timestampUs = lastBufferTimeUs;
@@ -4256,9 +4278,11 @@
         if (strncmp(componentName, "OMX.", 4)) {
             // Not an OpenMax component but a software codec.
 
+#if HAVE_SOFTWARE_DECODERS
             results->push();
             CodecCapabilities *caps = &results->editItemAt(results->size() - 1);
             caps->mComponentName = componentName;
+#endif
 
             continue;
         }
diff --git a/media/libstagefright/TimedEventQueue.cpp b/media/libstagefright/TimedEventQueue.cpp
index 5a453e9..100d8a3 100644
--- a/media/libstagefright/TimedEventQueue.cpp
+++ b/media/libstagefright/TimedEventQueue.cpp
@@ -30,7 +30,6 @@
 
 #include <sys/prctl.h>
 #include <sys/time.h>
-#include <sys/resource.h>
 
 #include <media/stagefright/MediaDebug.h>
 
@@ -210,8 +209,7 @@
     vm->AttachCurrentThread(&env, NULL);
 #endif
 
-    setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_FOREGROUND);
-    set_sched_policy(androidGetTid(), SP_FOREGROUND);
+    androidSetThreadPriority(0, ANDROID_PRIORITY_FOREGROUND);
 
     static_cast<TimedEventQueue *>(me)->threadEntry();
 
diff --git a/media/libstagefright/chromium_http/ChromiumHTTPDataSource.cpp b/media/libstagefright/chromium_http/ChromiumHTTPDataSource.cpp
index 1096717..588a74d 100644
--- a/media/libstagefright/chromium_http/ChromiumHTTPDataSource.cpp
+++ b/media/libstagefright/chromium_http/ChromiumHTTPDataSource.cpp
@@ -34,9 +34,6 @@
       mCurrentOffset(0),
       mIOResult(OK),
       mContentSize(-1),
-      mNumBandwidthHistoryItems(0),
-      mTotalTransferTimeUs(0),
-      mTotalTransferBytes(0),
       mDecryptHandle(NULL),
       mDrmManagerClient(NULL) {
     mDelegate->setOwner(this);
@@ -188,7 +185,7 @@
 
         // The read operation was successful, mIOResult contains
         // the number of bytes read.
-        addBandwidthMeasurement_l(mIOResult, delayUs);
+        addBandwidthMeasurement(mIOResult, delayUs);
 
         mCurrentOffset += mIOResult;
         return mIOResult;
@@ -221,7 +218,7 @@
 }
 
 uint32_t ChromiumHTTPDataSource::flags() {
-    return kWantsPrefetching;
+    return kWantsPrefetching | kIsHTTPBasedSource;
 }
 
 // static
@@ -246,36 +243,6 @@
     clearDRMState_l();
 }
 
-void ChromiumHTTPDataSource::addBandwidthMeasurement_l(
-        size_t numBytes, int64_t delayUs) {
-    BandwidthEntry entry;
-    entry.mDelayUs = delayUs;
-    entry.mNumBytes = numBytes;
-    mTotalTransferTimeUs += delayUs;
-    mTotalTransferBytes += numBytes;
-
-    mBandwidthHistory.push_back(entry);
-    if (++mNumBandwidthHistoryItems > 100) {
-        BandwidthEntry *entry = &*mBandwidthHistory.begin();
-        mTotalTransferTimeUs -= entry->mDelayUs;
-        mTotalTransferBytes -= entry->mNumBytes;
-        mBandwidthHistory.erase(mBandwidthHistory.begin());
-        --mNumBandwidthHistoryItems;
-    }
-}
-
-bool ChromiumHTTPDataSource::estimateBandwidth(int32_t *bandwidth_bps) {
-    Mutex::Autolock autoLock(mLock);
-
-    if (mNumBandwidthHistoryItems < 2) {
-        return false;
-    }
-
-    *bandwidth_bps = ((double)mTotalTransferBytes * 8E6 / mTotalTransferTimeUs);
-
-    return true;
-}
-
 sp<DecryptHandle> ChromiumHTTPDataSource::DrmInitialization() {
     Mutex::Autolock autoLock(mLock);
 
diff --git a/media/libstagefright/chromium_http/support.cpp b/media/libstagefright/chromium_http/support.cpp
index 805bd48..ed6846c 100644
--- a/media/libstagefright/chromium_http/support.cpp
+++ b/media/libstagefright/chromium_http/support.cpp
@@ -40,7 +40,7 @@
 
 static Mutex gNetworkThreadLock;
 static base::Thread *gNetworkThread = NULL;
-static scoped_refptr<URLRequestContext> gReqContext;
+static scoped_refptr<net::URLRequestContext> gReqContext;
 
 static void InitializeNetworkThreadIfNecessary() {
     Mutex::Autolock autoLock(gNetworkThreadLock);
@@ -214,7 +214,7 @@
 }
 
 void SfDelegate::OnResponseStarted(net::URLRequest *request) {
-    if (request->status().status() != URLRequestStatus::SUCCESS) {
+    if (request->status().status() != net::URLRequestStatus::SUCCESS) {
         MY_LOGI(StringPrintf(
                     "Request failed with status %d and os_error %d",
                     request->status().status(),
@@ -325,7 +325,7 @@
         } else {
             MY_LOGV("readMore pending read");
 
-            if (request->status().status() != URLRequestStatus::IO_PENDING) {
+            if (request->status().status() != net::URLRequestStatus::IO_PENDING) {
                 MY_LOGI(StringPrintf(
                             "Direct read failed w/ status %d\n",
                             request->status().status()).c_str());
diff --git a/media/libstagefright/chromium_http/support.h b/media/libstagefright/chromium_http/support.h
index 4d03493..8fe8db1 100644
--- a/media/libstagefright/chromium_http/support.h
+++ b/media/libstagefright/chromium_http/support.h
@@ -50,7 +50,7 @@
     DISALLOW_EVIL_CONSTRUCTORS(SfNetLog);
 };
 
-struct SfRequestContext : public URLRequestContext {
+struct SfRequestContext : public net::URLRequestContext {
     SfRequestContext();
 
     virtual const std::string &GetUserAgent(const GURL &url) const;
diff --git a/media/libstagefright/codecs/on2/h264dec/Android.mk b/media/libstagefright/codecs/on2/h264dec/Android.mk
new file mode 100644
index 0000000..5b3c876
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/Android.mk
@@ -0,0 +1,127 @@
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_ARM_MODE := arm
+
+LOCAL_SRC_FILES := \
+	./source/h264bsd_transform.c \
+	./source/h264bsd_util.c \
+	./source/h264bsd_byte_stream.c \
+	./source/h264bsd_seq_param_set.c \
+	./source/h264bsd_pic_param_set.c \
+	./source/h264bsd_slice_header.c \
+	./source/h264bsd_slice_data.c \
+	./source/h264bsd_macroblock_layer.c \
+	./source/h264bsd_stream.c \
+	./source/h264bsd_vlc.c \
+	./source/h264bsd_cavlc.c \
+	./source/h264bsd_nal_unit.c \
+	./source/h264bsd_neighbour.c \
+	./source/h264bsd_storage.c \
+	./source/h264bsd_slice_group_map.c \
+	./source/h264bsd_intra_prediction.c \
+	./source/h264bsd_inter_prediction.c \
+	./source/h264bsd_reconstruct.c \
+	./source/h264bsd_dpb.c \
+	./source/h264bsd_image.c \
+	./source/h264bsd_deblocking.c \
+	./source/h264bsd_conceal.c \
+	./source/h264bsd_vui.c \
+	./source/h264bsd_pic_order_cnt.c \
+	./source/h264bsd_decoder.c \
+	./source/H264SwDecApi.c \
+	SoftAVC.cpp \
+
+LOCAL_C_INCLUDES := $(LOCAL_PATH)/./inc \
+	frameworks/base/media/libstagefright/include \
+	frameworks/base/include/media/stagefright/openmax \
+
+MY_ASM := \
+	./source/arm_neon_asm_gcc/h264bsdWriteMacroblock.S \
+	./source/arm_neon_asm_gcc/h264bsdClearMbLayer.S \
+	./source/arm_neon_asm_gcc/h264bsdFillRow7.S \
+	./source/arm_neon_asm_gcc/h264bsdCountLeadingZeros.S \
+	./source/arm_neon_asm_gcc/h264bsdFlushBits.S
+
+
+MY_OMXDL_C_SRC := \
+	./omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_DeblockChroma_I.c \
+	./omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_DeblockLuma_I.c \
+	./omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_InterpolateChroma.c \
+	./omxdl/arm_neon/vc/m4p10/src/armVCM4P10_CAVLCTables.c \
+	./omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_DecodeChromaDcCoeffsToPairCAVLC.c \
+	./omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_DecodeCoeffsToPairCAVLC.c \
+	./omxdl/arm_neon/src/armCOMM_Bitstream.c \
+	./omxdl/arm_neon/src/armCOMM.c
+
+MY_OMXDL_ASM_SRC := \
+	./omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_DeblockingChroma_unsafe_s.S \
+	./omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_DeblockingLuma_unsafe_s.S \
+	./omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_Interpolate_Chroma_s.S \
+	./omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_InterpolateLuma_Align_unsafe_s.S \
+	./omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_InterpolateLuma_Copy_unsafe_s.S \
+	./omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_InterpolateLuma_DiagCopy_unsafe_s.S \
+	./omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_InterpolateLuma_HalfDiagHorVer4x4_unsafe_s.S \
+	./omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_InterpolateLuma_HalfDiagVerHor4x4_unsafe_s.S \
+	./omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe_s.S \
+	./omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe_s.S \
+	./omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_FilterDeblockingChroma_HorEdge_I_s.S \
+	./omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_FilterDeblockingChroma_VerEdge_I_s.S \
+	./omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_FilterDeblockingLuma_HorEdge_I_s.S \
+	./omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_FilterDeblockingLuma_VerEdge_I_s.S \
+	./omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_InterpolateLuma_s.S \
+	./omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_Average_4x_Align_unsafe_s.S \
+	./omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_DecodeCoeffsToPair_s.S \
+	./omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_DequantTables_s.S \
+	./omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_QuantTables_s.S \
+	./omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_TransformResidual4x4_s.S \
+	./omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_UnpackBlock4x4_s.S \
+	./omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_TransformDequantLumaDCFromPair_s.S \
+	./omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_PredictIntra_16x16_s.S \
+	./omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_PredictIntra_4x4_s.S \
+	./omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_PredictIntraChroma_8x8_s.S \
+	./omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_DequantTransformResidualFromPairAndAdd_s.S \
+	./omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_TransformDequantChromaDCFromPair_s.S \
+
+
+ifeq ($(ARCH_ARM_HAVE_NEON),true)
+    LOCAL_ARM_NEON   := true
+#    LOCAL_CFLAGS     := -std=c99 -D._NEON -D._OMXDL
+    LOCAL_CFLAGS     := -DH264DEC_NEON -DH264DEC_OMXDL
+    LOCAL_SRC_FILES  += $(MY_ASM) $(MY_OMXDL_C_SRC) $(MY_OMXDL_ASM_SRC)
+    LOCAL_C_INCLUDES += $(LOCAL_PATH)/./source/arm_neon_asm_gcc
+    LOCAL_C_INCLUDES += $(LOCAL_PATH)/./omxdl/arm_neon/api \
+                        $(LOCAL_PATH)/./omxdl/arm_neon/vc/api \
+                        $(LOCAL_PATH)/./omxdl/arm_neon/vc/m4p10/api
+endif
+
+LOCAL_SHARED_LIBRARIES := \
+	libstagefright libstagefright_omx libstagefright_foundation libutils \
+
+LOCAL_MODULE := libstagefright_soft_h264dec
+
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_SHARED_LIBRARY)
+
+#####################################################################
+# test utility: decoder
+#####################################################################
+##
+## Test application
+##
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := ./source/DecTestBench.c
+
+LOCAL_C_INCLUDES := $(LOCAL_PATH)/inc
+
+LOCAL_SHARED_LIBRARIES := libstagefright_soft_h264dec
+
+LOCAL_MODULE_TAGS := debug
+
+LOCAL_MODULE := decoder
+
+include $(BUILD_EXECUTABLE)
+
diff --git a/media/libstagefright/codecs/on2/h264dec/SoftAVC.cpp b/media/libstagefright/codecs/on2/h264dec/SoftAVC.cpp
new file mode 100644
index 0000000..830d2e0
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/SoftAVC.cpp
@@ -0,0 +1,517 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//#define LOG_NDEBUG 0
+#define LOG_TAG "SoftAVC"
+#include <utils/Log.h>
+
+#include "SoftAVC.h"
+
+#include <media/stagefright/foundation/ADebug.h>
+#include <media/stagefright/MediaDefs.h>
+#include <media/stagefright/MediaErrors.h>
+
+
+namespace android {
+
+template<class T>
+static void InitOMXParams(T *params) {
+    params->nSize = sizeof(T);
+    params->nVersion.s.nVersionMajor = 1;
+    params->nVersion.s.nVersionMinor = 0;
+    params->nVersion.s.nRevision = 0;
+    params->nVersion.s.nStep = 0;
+}
+
+SoftAVC::SoftAVC(
+        const char *name,
+        const OMX_CALLBACKTYPE *callbacks,
+        OMX_PTR appData,
+        OMX_COMPONENTTYPE **component)
+    : SimpleSoftOMXComponent(name, callbacks, appData, component),
+      mHandle(NULL),
+      mInputBufferCount(0),
+      mWidth(320),
+      mHeight(240),
+      mPictureSize(mWidth * mHeight * 3 / 2),
+      mCropLeft(0),
+      mCropTop(0),
+      mCropWidth(mWidth),
+      mCropHeight(mHeight),
+      mFirstPicture(NULL),
+      mFirstPictureId(-1),
+      mPicId(0),
+      mHeadersDecoded(false),
+      mEOSStatus(INPUT_DATA_AVAILABLE),
+      mOutputPortSettingsChange(NONE) {
+    initPorts();
+    CHECK_EQ(initDecoder(), (status_t)OK);
+}
+
+SoftAVC::~SoftAVC() {
+    H264SwDecRelease(mHandle);
+    mHandle = NULL;
+
+    while (mPicToHeaderMap.size() != 0) {
+        OMX_BUFFERHEADERTYPE *header = mPicToHeaderMap.editValueAt(0);
+        mPicToHeaderMap.removeItemsAt(0);
+        delete header;
+        header = NULL;
+    }
+    List<BufferInfo *> &outQueue = getPortQueue(kOutputPortIndex);
+    List<BufferInfo *> &inQueue = getPortQueue(kInputPortIndex);
+    CHECK(outQueue.empty());
+    CHECK(inQueue.empty());
+
+    delete[] mFirstPicture;
+}
+
+void SoftAVC::initPorts() {
+    OMX_PARAM_PORTDEFINITIONTYPE def;
+    InitOMXParams(&def);
+
+    def.nPortIndex = kInputPortIndex;
+    def.eDir = OMX_DirInput;
+    def.nBufferCountMin = kNumInputBuffers;
+    def.nBufferCountActual = def.nBufferCountMin;
+    def.nBufferSize = 8192;
+    def.bEnabled = OMX_TRUE;
+    def.bPopulated = OMX_FALSE;
+    def.eDomain = OMX_PortDomainVideo;
+    def.bBuffersContiguous = OMX_FALSE;
+    def.nBufferAlignment = 1;
+
+    def.format.video.cMIMEType = const_cast<char *>(MEDIA_MIMETYPE_VIDEO_AVC);
+    def.format.video.pNativeRender = NULL;
+    def.format.video.nFrameWidth = mWidth;
+    def.format.video.nFrameHeight = mHeight;
+    def.format.video.nStride = def.format.video.nFrameWidth;
+    def.format.video.nSliceHeight = def.format.video.nFrameHeight;
+    def.format.video.nBitrate = 0;
+    def.format.video.xFramerate = 0;
+    def.format.video.bFlagErrorConcealment = OMX_FALSE;
+    def.format.video.eCompressionFormat = OMX_VIDEO_CodingAVC;
+    def.format.video.eColorFormat = OMX_COLOR_FormatUnused;
+    def.format.video.pNativeWindow = NULL;
+
+    addPort(def);
+
+    def.nPortIndex = kOutputPortIndex;
+    def.eDir = OMX_DirOutput;
+    def.nBufferCountMin = kNumOutputBuffers;
+    def.nBufferCountActual = def.nBufferCountMin;
+    def.bEnabled = OMX_TRUE;
+    def.bPopulated = OMX_FALSE;
+    def.eDomain = OMX_PortDomainVideo;
+    def.bBuffersContiguous = OMX_FALSE;
+    def.nBufferAlignment = 2;
+
+    def.format.video.cMIMEType = const_cast<char *>(MEDIA_MIMETYPE_VIDEO_RAW);
+    def.format.video.pNativeRender = NULL;
+    def.format.video.nFrameWidth = mWidth;
+    def.format.video.nFrameHeight = mHeight;
+    def.format.video.nStride = def.format.video.nFrameWidth;
+    def.format.video.nSliceHeight = def.format.video.nFrameHeight;
+    def.format.video.nBitrate = 0;
+    def.format.video.xFramerate = 0;
+    def.format.video.bFlagErrorConcealment = OMX_FALSE;
+    def.format.video.eCompressionFormat = OMX_VIDEO_CodingUnused;
+    def.format.video.eColorFormat = OMX_COLOR_FormatYUV420Planar;
+    def.format.video.pNativeWindow = NULL;
+
+    def.nBufferSize =
+        (def.format.video.nFrameWidth * def.format.video.nFrameHeight * 3) / 2;
+
+    addPort(def);
+}
+
+status_t SoftAVC::initDecoder() {
+    if (H264SwDecInit(&mHandle, 1) == H264SWDEC_OK) {
+        return OK;
+    }
+    return UNKNOWN_ERROR;
+}
+
+OMX_ERRORTYPE SoftAVC::internalGetParameter(
+        OMX_INDEXTYPE index, OMX_PTR params) {
+    switch (index) {
+        case OMX_IndexParamVideoPortFormat:
+        {
+            OMX_VIDEO_PARAM_PORTFORMATTYPE *formatParams =
+                (OMX_VIDEO_PARAM_PORTFORMATTYPE *)params;
+
+            if (formatParams->nPortIndex > kOutputPortIndex) {
+                return OMX_ErrorUndefined;
+            }
+
+            if (formatParams->nIndex != 0) {
+                return OMX_ErrorNoMore;
+            }
+
+            if (formatParams->nPortIndex == kInputPortIndex) {
+                formatParams->eCompressionFormat = OMX_VIDEO_CodingAVC;
+                formatParams->eColorFormat = OMX_COLOR_FormatUnused;
+                formatParams->xFramerate = 0;
+            } else {
+                CHECK(formatParams->nPortIndex == kOutputPortIndex);
+
+                formatParams->eCompressionFormat = OMX_VIDEO_CodingUnused;
+                formatParams->eColorFormat = OMX_COLOR_FormatYUV420Planar;
+                formatParams->xFramerate = 0;
+            }
+
+            return OMX_ErrorNone;
+        }
+
+        default:
+            return SimpleSoftOMXComponent::internalGetParameter(index, params);
+    }
+}
+
+OMX_ERRORTYPE SoftAVC::internalSetParameter(
+        OMX_INDEXTYPE index, const OMX_PTR params) {
+    switch (index) {
+        case OMX_IndexParamStandardComponentRole:
+        {
+            const OMX_PARAM_COMPONENTROLETYPE *roleParams =
+                (const OMX_PARAM_COMPONENTROLETYPE *)params;
+
+            if (strncmp((const char *)roleParams->cRole,
+                        "video_decoder.avc",
+                        OMX_MAX_STRINGNAME_SIZE - 1)) {
+                return OMX_ErrorUndefined;
+            }
+
+            return OMX_ErrorNone;
+        }
+
+        case OMX_IndexParamVideoPortFormat:
+        {
+            OMX_VIDEO_PARAM_PORTFORMATTYPE *formatParams =
+                (OMX_VIDEO_PARAM_PORTFORMATTYPE *)params;
+
+            if (formatParams->nPortIndex > kOutputPortIndex) {
+                return OMX_ErrorUndefined;
+            }
+
+            if (formatParams->nIndex != 0) {
+                return OMX_ErrorNoMore;
+            }
+
+            return OMX_ErrorNone;
+        }
+
+        default:
+            return SimpleSoftOMXComponent::internalSetParameter(index, params);
+    }
+}
+
+OMX_ERRORTYPE SoftAVC::getConfig(
+        OMX_INDEXTYPE index, OMX_PTR params) {
+    switch (index) {
+        case OMX_IndexConfigCommonOutputCrop:
+        {
+            OMX_CONFIG_RECTTYPE *rectParams = (OMX_CONFIG_RECTTYPE *)params;
+
+            if (rectParams->nPortIndex != 1) {
+                return OMX_ErrorUndefined;
+            }
+
+            rectParams->nLeft = mCropLeft;
+            rectParams->nTop = mCropTop;
+            rectParams->nWidth = mCropWidth;
+            rectParams->nHeight = mCropHeight;
+
+            return OMX_ErrorNone;
+        }
+
+        default:
+            return OMX_ErrorUnsupportedIndex;
+    }
+}
+
+void SoftAVC::onQueueFilled(OMX_U32 portIndex) {
+    if (mOutputPortSettingsChange != NONE) {
+        return;
+    }
+
+    if (mEOSStatus == OUTPUT_FRAMES_FLUSHED) {
+        return;
+    }
+
+    List<BufferInfo *> &inQueue = getPortQueue(kInputPortIndex);
+    List<BufferInfo *> &outQueue = getPortQueue(kOutputPortIndex);
+    H264SwDecRet ret = H264SWDEC_PIC_RDY;
+    status_t err = OK;
+    bool portSettingsChanged = false;
+    while ((mEOSStatus != INPUT_DATA_AVAILABLE || !inQueue.empty())
+            && outQueue.size() == kNumOutputBuffers) {
+
+        if (mEOSStatus == INPUT_EOS_SEEN) {
+            drainAllOutputBuffers();
+            return;
+        }
+
+        BufferInfo *inInfo = *inQueue.begin();
+        OMX_BUFFERHEADERTYPE *inHeader = inInfo->mHeader;
+        ++mPicId;
+        if (inHeader->nFlags & OMX_BUFFERFLAG_EOS) {
+            inQueue.erase(inQueue.begin());
+            inInfo->mOwnedByUs = false;
+            notifyEmptyBufferDone(inHeader);
+            mEOSStatus = INPUT_EOS_SEEN;
+            continue;
+        }
+
+        OMX_BUFFERHEADERTYPE *header = new OMX_BUFFERHEADERTYPE;
+        memset(header, 0, sizeof(OMX_BUFFERHEADERTYPE));
+        header->nTimeStamp = inHeader->nTimeStamp;
+        header->nFlags = inHeader->nFlags;
+        mPicToHeaderMap.add(mPicId, header);
+        inQueue.erase(inQueue.begin());
+
+        H264SwDecInput inPicture;
+        H264SwDecOutput outPicture;
+        memset(&inPicture, 0, sizeof(inPicture));
+        inPicture.dataLen = inHeader->nFilledLen;
+        inPicture.pStream = inHeader->pBuffer + inHeader->nOffset;
+        inPicture.picId = mPicId;
+        inPicture.intraConcealmentMethod = 1;
+        H264SwDecPicture decodedPicture;
+
+        while (inPicture.dataLen > 0) {
+            ret = H264SwDecDecode(mHandle, &inPicture, &outPicture);
+            if (ret == H264SWDEC_HDRS_RDY_BUFF_NOT_EMPTY ||
+                ret == H264SWDEC_PIC_RDY_BUFF_NOT_EMPTY) {
+                inPicture.dataLen -= (u32)(outPicture.pStrmCurrPos - inPicture.pStream);
+                inPicture.pStream = outPicture.pStrmCurrPos;
+                if (ret == H264SWDEC_HDRS_RDY_BUFF_NOT_EMPTY) {
+                    mHeadersDecoded = true;
+                    H264SwDecInfo decoderInfo;
+                    CHECK(H264SwDecGetInfo(mHandle, &decoderInfo) == H264SWDEC_OK);
+
+                    if (handlePortSettingChangeEvent(&decoderInfo)) {
+                        portSettingsChanged = true;
+                    }
+
+                    if (decoderInfo.croppingFlag &&
+                        handleCropRectEvent(&decoderInfo.cropParams)) {
+                        portSettingsChanged = true;
+                    }
+                }
+            } else {
+                if (portSettingsChanged) {
+                    if (H264SwDecNextPicture(mHandle, &decodedPicture, 0)
+                        == H264SWDEC_PIC_RDY) {
+
+                        // Save this output buffer; otherwise, it will be
+                        // lost during dynamic port reconfiguration because
+                        // OpenMAX client will delete _all_ output buffers
+                        // in the process.
+                        saveFirstOutputBuffer(
+                            decodedPicture.picId,
+                            (uint8_t *)decodedPicture.pOutputPicture);
+                    }
+                }
+                inPicture.dataLen = 0;
+                if (ret < 0) {
+                    LOGE("Decoder failed: %d", ret);
+                    err = ERROR_MALFORMED;
+                }
+            }
+        }
+        inInfo->mOwnedByUs = false;
+        notifyEmptyBufferDone(inHeader);
+
+        if (portSettingsChanged) {
+            portSettingsChanged = false;
+            return;
+        }
+
+        if (mFirstPicture && !outQueue.empty()) {
+            drainOneOutputBuffer(mFirstPictureId, mFirstPicture);
+            delete[] mFirstPicture;
+            mFirstPicture = NULL;
+            mFirstPictureId = -1;
+        }
+
+        while (!outQueue.empty() &&
+                mHeadersDecoded &&
+                H264SwDecNextPicture(mHandle, &decodedPicture, 0)
+                    == H264SWDEC_PIC_RDY) {
+
+            int32_t picId = decodedPicture.picId;
+            uint8_t *data = (uint8_t *) decodedPicture.pOutputPicture;
+            drainOneOutputBuffer(picId, data);
+        }
+
+        if (err != OK) {
+            notify(OMX_EventError, OMX_ErrorUndefined, err, NULL);
+        }
+    }
+}
+
+bool SoftAVC::handlePortSettingChangeEvent(const H264SwDecInfo *info) {
+    if (mWidth != info->picWidth || mHeight != info->picHeight) {
+        mWidth  = info->picWidth;
+        mHeight = info->picHeight;
+        mPictureSize = mWidth * mHeight * 3 / 2;
+        mCropWidth = mWidth;
+        mCropHeight = mHeight;
+        updatePortDefinitions();
+        notify(OMX_EventPortSettingsChanged, 1, 0, NULL);
+        mOutputPortSettingsChange = AWAITING_DISABLED;
+        return true;
+    }
+
+    return false;
+}
+
+bool SoftAVC::handleCropRectEvent(const CropParams *crop) {
+    if (mCropLeft != crop->cropLeftOffset ||
+        mCropTop != crop->cropTopOffset ||
+        mCropWidth != crop->cropOutWidth ||
+        mCropHeight != crop->cropOutHeight) {
+        mCropLeft = crop->cropLeftOffset;
+        mCropTop = crop->cropTopOffset;
+        mCropWidth = crop->cropOutWidth;
+        mCropHeight = crop->cropOutHeight;
+
+        notify(OMX_EventPortSettingsChanged, 1,
+                OMX_IndexConfigCommonOutputCrop, NULL);
+
+        return true;
+    }
+    return false;
+}
+
+void SoftAVC::saveFirstOutputBuffer(int32_t picId, uint8_t *data) {
+    CHECK(mFirstPicture == NULL);
+    mFirstPictureId = picId;
+
+    mFirstPicture = new uint8_t[mPictureSize];
+    memcpy(mFirstPicture, data, mPictureSize);
+}
+
+void SoftAVC::drainOneOutputBuffer(int32_t picId, uint8_t* data) {
+    List<BufferInfo *> &outQueue = getPortQueue(kOutputPortIndex);
+    BufferInfo *outInfo = *outQueue.begin();
+    outQueue.erase(outQueue.begin());
+    OMX_BUFFERHEADERTYPE *outHeader = outInfo->mHeader;
+    OMX_BUFFERHEADERTYPE *header = mPicToHeaderMap.valueFor(picId);
+    outHeader->nTimeStamp = header->nTimeStamp;
+    outHeader->nFlags = header->nFlags;
+    outHeader->nFilledLen = mPictureSize;
+    memcpy(outHeader->pBuffer + outHeader->nOffset,
+            data, mPictureSize);
+    mPicToHeaderMap.removeItem(picId);
+    delete header;
+    outInfo->mOwnedByUs = false;
+    notifyFillBufferDone(outHeader);
+}
+
+bool SoftAVC::drainAllOutputBuffers() {
+    List<BufferInfo *> &outQueue = getPortQueue(kOutputPortIndex);
+    H264SwDecPicture decodedPicture;
+
+    while (!outQueue.empty()) {
+        BufferInfo *outInfo = *outQueue.begin();
+        outQueue.erase(outQueue.begin());
+        OMX_BUFFERHEADERTYPE *outHeader = outInfo->mHeader;
+        if (mHeadersDecoded &&
+            H264SWDEC_PIC_RDY ==
+                H264SwDecNextPicture(mHandle, &decodedPicture, 1 /* flush */)) {
+
+            int32_t picId = decodedPicture.picId;
+            CHECK(mPicToHeaderMap.indexOfKey(picId) >= 0);
+
+            memcpy(outHeader->pBuffer + outHeader->nOffset,
+                decodedPicture.pOutputPicture,
+                mPictureSize);
+
+            OMX_BUFFERHEADERTYPE *header = mPicToHeaderMap.valueFor(picId);
+            outHeader->nTimeStamp = header->nTimeStamp;
+            outHeader->nFlags = header->nFlags;
+            outHeader->nFilledLen = mPictureSize;
+            mPicToHeaderMap.removeItem(picId);
+            delete header;
+        } else {
+            outHeader->nTimeStamp = 0;
+            outHeader->nFilledLen = 0;
+            outHeader->nFlags = OMX_BUFFERFLAG_EOS;
+            mEOSStatus = OUTPUT_FRAMES_FLUSHED;
+        }
+
+        outInfo->mOwnedByUs = false;
+        notifyFillBufferDone(outHeader);
+    }
+
+    return true;
+}
+
+void SoftAVC::onPortFlushCompleted(OMX_U32 portIndex) {
+    if (portIndex == kInputPortIndex) {
+        mEOSStatus = INPUT_DATA_AVAILABLE;
+    }
+}
+
+void SoftAVC::onPortEnableCompleted(OMX_U32 portIndex, bool enabled) {
+    switch (mOutputPortSettingsChange) {
+        case NONE:
+            break;
+
+        case AWAITING_DISABLED:
+        {
+            CHECK(!enabled);
+            mOutputPortSettingsChange = AWAITING_ENABLED;
+            break;
+        }
+
+        default:
+        {
+            CHECK_EQ((int)mOutputPortSettingsChange, (int)AWAITING_ENABLED);
+            CHECK(enabled);
+            mOutputPortSettingsChange = NONE;
+            break;
+        }
+    }
+}
+
+void SoftAVC::updatePortDefinitions() {
+    OMX_PARAM_PORTDEFINITIONTYPE *def = &editPortInfo(0)->mDef;
+    def->format.video.nFrameWidth = mWidth;
+    def->format.video.nFrameHeight = mHeight;
+    def->format.video.nStride = def->format.video.nFrameWidth;
+    def->format.video.nSliceHeight = def->format.video.nFrameHeight;
+
+    def = &editPortInfo(1)->mDef;
+    def->format.video.nFrameWidth = mWidth;
+    def->format.video.nFrameHeight = mHeight;
+    def->format.video.nStride = def->format.video.nFrameWidth;
+    def->format.video.nSliceHeight = def->format.video.nFrameHeight;
+
+    def->nBufferSize =
+        (def->format.video.nFrameWidth
+            * def->format.video.nFrameHeight * 3) / 2;
+}
+
+}  // namespace android
+
+android::SoftOMXComponent *createSoftOMXComponent(
+        const char *name, const OMX_CALLBACKTYPE *callbacks,
+        OMX_PTR appData, OMX_COMPONENTTYPE **component) {
+    return new android::SoftAVC(name, callbacks, appData, component);
+}
diff --git a/media/libstagefright/codecs/on2/h264dec/SoftAVC.h b/media/libstagefright/codecs/on2/h264dec/SoftAVC.h
new file mode 100644
index 0000000..3439efd
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/SoftAVC.h
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef SOFT_AVC_H_
+
+#define SOFT_AVC_H_
+
+#include "SimpleSoftOMXComponent.h"
+#include <utils/KeyedVector.h>
+
+#include "H264SwDecApi.h"
+#include "basetype.h"
+
+namespace android {
+
+struct SoftAVC : public SimpleSoftOMXComponent {
+    SoftAVC(const char *name,
+            const OMX_CALLBACKTYPE *callbacks,
+            OMX_PTR appData,
+            OMX_COMPONENTTYPE **component);
+
+protected:
+    virtual ~SoftAVC();
+
+    virtual OMX_ERRORTYPE internalGetParameter(
+            OMX_INDEXTYPE index, OMX_PTR params);
+
+    virtual OMX_ERRORTYPE internalSetParameter(
+            OMX_INDEXTYPE index, const OMX_PTR params);
+
+    virtual OMX_ERRORTYPE getConfig(OMX_INDEXTYPE index, OMX_PTR params);
+
+    virtual void onQueueFilled(OMX_U32 portIndex);
+    virtual void onPortFlushCompleted(OMX_U32 portIndex);
+    virtual void onPortEnableCompleted(OMX_U32 portIndex, bool enabled);
+
+private:
+    enum {
+        kInputPortIndex   = 0,
+        kOutputPortIndex  = 1,
+        kNumInputBuffers  = 8,
+        kNumOutputBuffers = 16,
+    };
+
+    enum EOSStatus {
+        INPUT_DATA_AVAILABLE,
+        INPUT_EOS_SEEN,
+        OUTPUT_FRAMES_FLUSHED,
+    };
+
+    void *mHandle;
+
+    size_t mInputBufferCount;
+
+    uint32_t mWidth, mHeight, mPictureSize;
+    uint32_t mCropLeft, mCropTop;
+    uint32_t mCropWidth, mCropHeight;
+
+    uint8_t *mFirstPicture;
+    int32_t mFirstPictureId;
+
+    int32_t mPicId;  // Which output picture is for which input buffer?
+
+    // OMX_BUFFERHEADERTYPE may be overkill, but it is convenient
+    // for tracking the following fields: nFlags, nTimeStamp, etc.
+    KeyedVector<int32_t, OMX_BUFFERHEADERTYPE *> mPicToHeaderMap;
+    bool mHeadersDecoded;
+
+    EOSStatus mEOSStatus;
+
+    enum OutputPortSettingChange {
+        NONE,
+        AWAITING_DISABLED,
+        AWAITING_ENABLED
+    };
+    OutputPortSettingChange mOutputPortSettingsChange;
+
+    void initPorts();
+    status_t initDecoder();
+    void updatePortDefinitions();
+    bool drainAllOutputBuffers();
+    void drainOneOutputBuffer(int32_t picId, uint8_t *data);
+    void saveFirstOutputBuffer(int32_t pidId, uint8_t *data);
+    bool handleCropRectEvent(const CropParams* crop);
+    bool handlePortSettingChangeEvent(const H264SwDecInfo *info);
+
+    DISALLOW_EVIL_CONSTRUCTORS(SoftAVC);
+};
+
+}  // namespace android
+
+#endif  // SOFT_AVC_H_
+
diff --git a/media/libstagefright/codecs/on2/h264dec/inc/H264SwDecApi.h b/media/libstagefright/codecs/on2/h264dec/inc/H264SwDecApi.h
new file mode 100755
index 0000000..fe112bc
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/inc/H264SwDecApi.h
@@ -0,0 +1,192 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+    1. Include Headers
+
+    2. Enumerations used as a return value or a parameter.
+        2.1. API's return value enumerations.
+
+    3. User Structures
+        3.1. Structures for H264SwDecDecode() parameters.
+        3.2. Structures for information interchange with
+             DEC API and user application.
+
+    4. Prototypes of Decoder API functions
+
+------------------------------------------------------------------------------*/
+
+#ifndef H264SWDECAPI_H
+#define H264SWDECAPI_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/*------------------------------------------------------------------------------
+    1. Include Headers
+------------------------------------------------------------------------------*/
+
+    #include "basetype.h"
+
+/*------------------------------------------------------------------------------
+    2.1. API's return value enumerations.
+------------------------------------------------------------------------------*/
+
+    typedef enum
+    {
+        H264SWDEC_OK = 0,
+        H264SWDEC_STRM_PROCESSED = 1,
+        H264SWDEC_PIC_RDY,
+        H264SWDEC_PIC_RDY_BUFF_NOT_EMPTY,
+        H264SWDEC_HDRS_RDY_BUFF_NOT_EMPTY,
+        H264SWDEC_PARAM_ERR = -1,
+        H264SWDEC_STRM_ERR = -2,
+        H264SWDEC_NOT_INITIALIZED = -3,
+        H264SWDEC_MEMFAIL = -4,
+        H264SWDEC_INITFAIL = -5,
+        H264SWDEC_HDRS_NOT_RDY = -6,
+        H264SWDEC_EVALUATION_LIMIT_EXCEEDED = -7
+    } H264SwDecRet;
+
+/*------------------------------------------------------------------------------
+    3.1. Structures for H264SwDecDecode() parameters.
+------------------------------------------------------------------------------*/
+
+    /* typedef of the Decoder instance */
+    typedef void *H264SwDecInst;
+
+    /* Input structure */
+    typedef struct
+    {
+        u8  *pStream;            /* Pointer to stream to be decoded          */
+        u32  dataLen;            /* Number of bytes to be decoded            */
+        u32  picId;              /* Identifier for the picture to be decoded */
+        u32 intraConcealmentMethod; /* 0 = Gray concealment for intra
+                                       1 = Reference concealment for intra */
+
+    } H264SwDecInput;
+
+
+    /* Output structure */
+    typedef struct
+    {
+        u8  *pStrmCurrPos;      /* Pointer to stream position where decoder
+                                   ended up */
+    } H264SwDecOutput;
+
+    /* Output structure for H264SwDecNextPicture */
+    typedef struct
+    {
+        u32 *pOutputPicture;    /* Pointer to the picture, YUV format       */
+        u32 picId;              /* Identifier of the picture to be displayed*/
+        u32 isIdrPicture;       /* Flag to indicate if the picture is an
+                                   IDR picture */
+        u32 nbrOfErrMBs;        /* Number of concealed MB's in the picture  */
+    } H264SwDecPicture;
+
+/*------------------------------------------------------------------------------
+    3.2. Structures for information interchange with DEC API
+         and user application.
+------------------------------------------------------------------------------*/
+
+    typedef struct
+    {
+        u32 cropLeftOffset;
+        u32 cropOutWidth;
+        u32 cropTopOffset;
+        u32 cropOutHeight;
+    } CropParams;
+
+    typedef struct
+    {
+        u32 profile;
+        u32 picWidth;
+        u32 picHeight;
+        u32 videoRange;
+        u32 matrixCoefficients;
+        u32 parWidth;
+        u32 parHeight;
+        u32 croppingFlag;
+        CropParams cropParams;
+    } H264SwDecInfo;
+
+    /* Version information */
+    typedef struct
+    {
+        u32 major;    /* Decoder API major version */
+        u32 minor;    /* Dncoder API minor version */
+    } H264SwDecApiVersion;
+
+/*------------------------------------------------------------------------------
+    4. Prototypes of Decoder API functions
+------------------------------------------------------------------------------*/
+
+    H264SwDecRet H264SwDecDecode(H264SwDecInst      decInst,
+                                 H264SwDecInput     *pInput,
+                                 H264SwDecOutput    *pOutput);
+
+    H264SwDecRet H264SwDecInit(H264SwDecInst *decInst,
+                               u32            noOutputReordering);
+
+    H264SwDecRet H264SwDecNextPicture(H264SwDecInst     decInst,
+                                      H264SwDecPicture *pOutput,
+                                      u32               endOfStream);
+
+    H264SwDecRet H264SwDecGetInfo(H264SwDecInst decInst,
+                                  H264SwDecInfo *pDecInfo);
+
+    void  H264SwDecRelease(H264SwDecInst decInst);
+
+    H264SwDecApiVersion H264SwDecGetAPIVersion(void);
+
+    /* function prototype for API trace */
+    void H264SwDecTrace(char *);
+
+    /* function prototype for memory allocation */
+    void* H264SwDecMalloc(u32 size);
+
+    /* function prototype for memory free */
+    void H264SwDecFree(void *ptr);
+
+    /* function prototype for memory copy */
+    void H264SwDecMemcpy(void *dest, void *src, u32 count);
+
+    /* function prototype for memset */
+    void H264SwDecMemset(void *ptr, i32 value, u32 count);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* H264SWDECAPI_H */
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/inc/basetype.h b/media/libstagefright/codecs/on2/h264dec/inc/basetype.h
new file mode 100755
index 0000000..63d5653
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/inc/basetype.h
@@ -0,0 +1,52 @@
+/*
+ * 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 BASETYPE_H_INCLUDED
+#define BASETYPE_H_INCLUDED
+
+
+#ifdef __arm
+#define VOLATILE volatile
+#else
+#define VOLATILE
+#endif
+
+typedef unsigned char   u8;
+typedef signed char     i8;
+typedef unsigned short  u16;
+typedef signed short    i16;
+typedef unsigned int    u32;
+typedef signed int      i32;
+
+#if defined(VC1SWDEC_16BIT) || defined(MP4ENC_ARM11)
+typedef unsigned short  u16x;
+typedef signed short    i16x;
+#else
+typedef unsigned int    u16x;
+typedef signed int      i16x;
+#endif
+
+
+#ifndef NULL
+#ifdef  __cplusplus
+#define NULL 0
+#else
+#define NULL ((void *)0)
+#endif
+#endif
+
+#endif  /* BASETYPE_H_INCLUDED */
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/ARM_DELIVERY.TXT b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/ARM_DELIVERY.TXT
new file mode 100644
index 0000000..5ce70ca
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/ARM_DELIVERY.TXT
@@ -0,0 +1,63 @@
+The contents of this transaction was created by Hedley Francis
+of ARM on 19-Feb-2008.
+
+It contains the ARM data versions listed below.
+
+This data, unless otherwise stated, is ARM Proprietary and access to it
+is subject to the agreements indicated below.
+
+If you experience problems with this data, please contact ARM support
+quoting transaction reference <97413>.
+
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+- OX001-SW-98010-r0p0-00bet1
+  Video codecs - optimised code
+  V6 optimized code release for Hantro (Ver 1.0.2)
+  internal access
+
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+This transaction contains deliverables which are designated as being of
+beta release status (BET).
+
+Beta release status has a particular meaning to ARM of which the recipient
+must be aware. Beta is a pre-release status indicating that the deliverable
+so described is believed to robustly demonstrate specified behaviour, to be
+consistent across its included aspects and be ready for general deployment.
+But Beta also indicates that pre-release reliability trials are ongoing and
+that it is possible residual defects or errors in operation, consistency
+and documentation may still be encountered. The recipient should consider
+this position when using this Beta material supplied. ARM will normally
+attempt to provide fixes or a work-around for defects identified by the
+recipient, but the provision or timeliness of this support cannot be
+guaranteed. ARM shall not be responsible for direct or consequential
+damages as a result of encountering one or more of these residual defects.
+By accepting a Beta release, the recipient agrees to these constraints and
+to providing reasonable information to ARM to enable the replication of the
+defects identified by the recipient. The specific Beta version supplied
+will not be supported after release of a later or higher status version.
+It should be noted that Support for the Beta release of the deliverable
+will only be provided by ARM to a recipient who has a current support and
+maintenance contract for the deliverable.
+
+
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+In addition to the data versions listed above, this transaction contains
+two additional files at the top level.
+
+The first is this file, ARM_DELIVERY_97413.TXT, which is the delivery
+note.
+
+The second is ARM_MANIFEST_97413.TXT which contains a manifest of all the
+files included in this transaction, together with their checksums.
+
+The checksums provided are calculated using the RSA Data Security, Inc.
+MD5 Message-Digest Algorithm.
+
+The checksums can be used to verify the integrity of this data using the
+"md5sum" tool (which is part of the GNU "textutils" package) by running:
+
+  % md5sum --check ARM_MANIFEST_97413.TXT
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/ARM_MANIFEST.TXT b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/ARM_MANIFEST.TXT
new file mode 100644
index 0000000..9b2238b
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/ARM_MANIFEST.TXT
@@ -0,0 +1,91 @@
+				  OX001-SW-98010-r0p0-00bet1/
+				  OX001-SW-98010-r0p0-00bet1/api/
+e049791cfab6060a08cbac7b3ad767d6  OX001-SW-98010-r0p0-00bet1/api/armCOMM_s.h
+ed798face25497b2703ede736d6d52b6  OX001-SW-98010-r0p0-00bet1/api/omxtypes_s.h
+4eebd63af087376811d6749f0646b864  OX001-SW-98010-r0p0-00bet1/api/armCOMM_BitDec_s.h
+43cf46c2cf2fe1f93c615b57bcbe4809  OX001-SW-98010-r0p0-00bet1/api/armCOMM.h
+8f248ceaac8f602e277a521b679dcbbe  OX001-SW-98010-r0p0-00bet1/api/armCOMM_IDCTTable.h
+53f2ae8a98495f05e26a4cf862a7f750  OX001-SW-98010-r0p0-00bet1/api/armCOMM_Version.h
+3a2f420ddf6a1b950470bd0f5ebd5c62  OX001-SW-98010-r0p0-00bet1/api/armCOMM_IDCT_s.h
+511c0bb534fe223599e2c84eff24c9ed  OX001-SW-98010-r0p0-00bet1/api/armCOMM_MaskTable.h
+8971932d56eed6b1ad1ba507f0bff5f0  OX001-SW-98010-r0p0-00bet1/api/armCOMM_Bitstream.h
+f87fedd9ca432fefa757008176864ef8  OX001-SW-98010-r0p0-00bet1/api/armOMX.h
+8e49899a428822c36ef9dd94e0e05f18  OX001-SW-98010-r0p0-00bet1/api/omxtypes.h
+694281d11af52f88e6f9d4cb226ac8a7  OX001-SW-98010-r0p0-00bet1/build_vc.pl
+e72d96c0a415459748df9807f3dae72f  OX001-SW-98010-r0p0-00bet1/filelist_vc.txt
+				  OX001-SW-98010-r0p0-00bet1/src/
+5eeae659a29477f5c52296d24afffd3c  OX001-SW-98010-r0p0-00bet1/src/armCOMM_IDCTTable.c
+d64cdcf38f7749dc7f77465e5b7d356d  OX001-SW-98010-r0p0-00bet1/src/armCOMM_MaskTable.c
+				  OX001-SW-98010-r0p0-00bet1/vc/
+				  OX001-SW-98010-r0p0-00bet1/vc/m4p10/
+				  OX001-SW-98010-r0p0-00bet1/vc/m4p10/src/
+e7e0c320978564a7c9b2c723749a98d6  OX001-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_CAVLCTables.c
+4adcd0df081990bdfc4729041a2a9152  OX001-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_InterpolateChroma.c
+852e0404142965dc1f3aa7f00ee5127b  OX001-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_UnpackBlock4x4_s.s
+7054151c5bfea6b5e74feee86b2d7b01  OX001-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_DecodeCoeffsToPairCAVLC.c
+38944c5e0bba01e32ff349c2c87c71b2  OX001-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_DequantTables_s.s
+32ff4b8be62e2f0f3e764b83c1e5e2fd  OX001-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_DeblockChroma_I.c
+90b0e6a04e764902c0a0903640c10b32  OX001-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_DeblockingLuma_unsafe_s.s
+28a19ae4fe2258628080d6a89bb54b91  OX001-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_DeblockingChroma_unsafe_s.s
+98e196b9e1ffebaf91f62ea9d17fb97d  OX001-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_InterpolateLuma_s.s
+01ba60eff66ea49a4f833ce6279f8e2f  OX001-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_DeblockLuma_I.c
+f301d5a95e07354f593ea5747c01cb0a  OX001-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe_s.s
+44c9ef21e840a100301f7d7a4189957c  OX001-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_InterpolateLuma_HalfDiagVerHor4x4_unsafe_s.s
+a33b03bbd3352d24ed744769e12bb87d  OX001-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe_s.s
+00c20bfda67bb86096b615fc17c94b35  OX001-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_TransformDequantChromaDCFromPair_s.s
+2ddcaf60a8ea1e6e6b77737f768bfb9d  OX001-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_QuantTables_s.s
+c3002aad5600f872b70a5d7fe3915846  OX001-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_InterpolateLuma_Align_unsafe_s.s
+a2900f2c47f1c61d20bd6c1eda33d6d4  OX001-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_InterpolateLuma_Copy_unsafe_s.s
+e4fecd66bc47f07539bc308935e84a1f  OX001-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_PredictIntra_4x4_s.s
+78815c9df50ba53131bb22d2b829e3c3  OX001-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_TransformDequantLumaDCFromPair_s.s
+1909ae312ac79a03a5fac1d1e8bc0291  OX001-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_FilterDeblockingChroma_HorEdge_I_s.s
+3d2c48580655928065de7839866d9bc4  OX001-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_InterpolateLuma_HalfDiagHorVer4x4_unsafe_s.s
+23aa2fdf155d4fa6ff745eab6e01f32b  OX001-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_PredictIntra_16x16_s.s
+97f20a93c481d7f6173d919f41e415bd  OX001-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_FilterDeblockingChroma_VerEdge_I_s.s
+becd512da202436286811b6aec061f47  OX001-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_FilterDeblockingLuma_HorEdge_I_s.s
+dd24a99ae3cd842dcacaf31d47de88b3  OX001-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_FilterDeblockingLuma_VerEdge_I_s.s
+c2d995f787b6f44ef10c751c12d1935f  OX001-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_InterpolateLuma_DiagCopy_unsafe_s.s
+3628fbdf0cd217c287b6ccc94135d06e  OX001-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_PredictIntraChroma_8x8_s.s
+4a52b3e9e268b8a8f07829bf500d03af  OX001-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_DecodeCoeffsToPair_s.s
+11249f8a98c5d4b84cb5575b0e37ca9c  OX001-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_Average_4x_Align_unsafe_s.s
+3599b1074330965c8ca285d164efccff  OX001-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_Interpolate_Chroma_s.s
+3339e026c7de655d9400949eb5e51451  OX001-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_TransformResidual4x4_s.s
+cc4a6f32db0b72a91d3f278f6855df69  OX001-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_DecodeChromaDcCoeffsToPairCAVLC.c
+				  OX001-SW-98010-r0p0-00bet1/vc/m4p10/api/
+6e530ddaa7c2b57ffe88162c020cb662  OX001-SW-98010-r0p0-00bet1/vc/m4p10/api/armVCM4P10_CAVLCTables.h
+				  OX001-SW-98010-r0p0-00bet1/vc/m4p2/
+				  OX001-SW-98010-r0p0-00bet1/vc/m4p2/src/
+cdf412920c2037a725d0420002b6752e  OX001-SW-98010-r0p0-00bet1/vc/m4p2/src/armVCM4P2_Clip8_s.s
+dba9824e959b21d401cac925e68a11a6  OX001-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_Inter_s.s
+b559b71d5c94627f10e616fb72c0cefc  OX001-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_QuantInvIntra_I_s.s
+4fba4c431a783a78a2eb6497a94ac967  OX001-SW-98010-r0p0-00bet1/vc/m4p2/src/armVCM4P2_Zigzag_Tables.c
+1e4c3be8c5eddc00c9f05e83bcf315ef  OX001-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_MCReconBlock_s.s
+1b0b2990c2669dfb87cf6b810611c01b  OX001-SW-98010-r0p0-00bet1/vc/m4p2/src/armVCM4P2_Huff_Tables_VLC.c
+1c9b87abf3283e957816b3937c680701  OX001-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_DecodePadMV_PVOP_s.s
+4fe1afca659a9055fc1172e58f78a506  OX001-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_DecodeBlockCoef_Intra.c
+2ea067f0436f91ba1351edaf411cb4ea  OX001-SW-98010-r0p0-00bet1/vc/m4p2/src/armVCM4P2_Lookup_Tables.c
+acb92be1dbcdb3ebe824cbe9e28d03bf  OX001-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_IDCT8x8blk_s.s
+a6b41f01b1df7dd656ebdba3084bfa2a  OX001-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_FindMVpred_s.s
+293a48a648a3085456e6665bb7366fad  OX001-SW-98010-r0p0-00bet1/vc/m4p2/src/armVCM4P2_SetPredDir_s.s
+ffe6b96c74d4881f4d3c8de8cc737797  OX001-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_QuantInvInter_I_s.s
+437dfa204508850d61d4b87091446e9f  OX001-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_IntraACVLC_s.s
+ff5915d181bfd2cd2f0bd588bd2300dc  OX001-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_IntraDCVLC_s.s
+6775eb0c561dbab965c60f85b08c96fd  OX001-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_PredictReconCoefIntra_s.s
+a0d85f4f517c945a4c9317ac021f2d08  OX001-SW-98010-r0p0-00bet1/vc/m4p2/src/armVCM4P2_DecodeVLCZigzag_AC_unsafe_s.s
+386020dee8b725c7fe2526f1fc211d7d  OX001-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_DecodeBlockCoef_Inter.c
+				  OX001-SW-98010-r0p0-00bet1/vc/m4p2/api/
+4624e7c838e10a249abcc3d3f4f40748  OX001-SW-98010-r0p0-00bet1/vc/m4p2/api/armVCM4P2_Huff_Tables_VLC.h
+65e1057d04e2cb844559dc9f6e09795a  OX001-SW-98010-r0p0-00bet1/vc/m4p2/api/armVCM4P2_ZigZag_Tables.h
+				  OX001-SW-98010-r0p0-00bet1/vc/src/
+e627b3346b0dc9aff14446005ce0fa43  OX001-SW-98010-r0p0-00bet1/vc/src/armVC_Version.c
+				  OX001-SW-98010-r0p0-00bet1/vc/api/
+7ca94b1c33ac0211e17d38baadd7d1dd  OX001-SW-98010-r0p0-00bet1/vc/api/armVC.h
+12cf7596edbbf6048b626d15e8d0ed48  OX001-SW-98010-r0p0-00bet1/vc/api/omxVC.h
+11726e286a81257cb45f5547fb4d374c  OX001-SW-98010-r0p0-00bet1/vc/api/omxVC_s.h
+a5b2af605c319cd2491319e430741377  OX001-SW-98010-r0p0-00bet1/vc/api/armVCCOMM_s.h
+				  OX001-SW-98010-r0p0-00bet1/vc/comm/
+				  OX001-SW-98010-r0p0-00bet1/vc/comm/src/
+50cca6954c447b012ab39ca7872e5e8f  OX001-SW-98010-r0p0-00bet1/vc/comm/src/omxVCCOMM_Copy16x16_s.s
+d1c3bce77fc5774c899b447d13f02cd0  OX001-SW-98010-r0p0-00bet1/vc/comm/src/omxVCCOMM_Copy8x8_s.s
+fdac1d1bad3fd23c880beb39bc2e89aa  OX001-SW-98010-r0p0-00bet1/vc/comm/src/omxVCCOMM_ExpandFrame_I_s.s
+6d9adc2be5bd0311591030d0c6df771c  ARM_DELIVERY_97413.TXT
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/api/armCOMM.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/api/armCOMM.h
new file mode 100644
index 0000000..2ed86a4
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/api/armCOMM.h
@@ -0,0 +1,785 @@
+/**
+ * 
+ * File Name:  armCOMM.h
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *   
+ * File: armCOMM.h
+ * Brief: Declares Common APIs/Data Types used across OpenMAX API's
+ *
+ */
+ 
+  
+#ifndef _armCommon_H_
+#define _armCommon_H_
+
+#include "omxtypes.h"
+
+typedef struct
+{
+  OMX_F32 Re; /** Real part */
+  OMX_F32 Im; /** Imaginary part */	
+        
+} OMX_FC32; /** single precision floating point complex number */
+
+typedef struct
+{
+  OMX_F64 Re; /** Real part */
+  OMX_F64 Im; /** Imaginary part */	
+        
+} OMX_FC64; /** double precision floating point complex number */
+
+
+/* Used by both IP and IC domains for 8x8 JPEG blocks. */
+typedef OMX_S16 ARM_BLOCK8x8[64];
+
+
+#include "armOMX.h"
+
+#define  armPI (OMX_F64)(3.1415926535897932384626433832795)
+
+/***********************************************************************/
+
+/* Compiler extensions */
+#ifdef ARM_DEBUG
+/* debug version */
+#include <stdlib.h>
+#include <assert.h>
+#include <stdio.h>
+#define armError(str) {printf((str)); printf("\n"); exit(-1);}
+#define armWarn(str) {printf((str)); printf("\n");}
+#define armIgnore(a) ((void)a)
+#define armAssert(a) assert(a)
+#else 
+/* release version */
+#define armError(str) ((void) (str))
+#define armWarn(str)  ((void) (str))
+#define armIgnore(a)  ((void) (a))
+#define armAssert(a)  ((void) (a))
+#endif /* ARM_DEBUG */
+
+/* Arithmetic operations */
+
+#define armMin(a,b)             ( (a) > (b) ?  (b):(a) )
+#define armMax(a,b)             ( (a) > (b) ?  (a):(b) )
+#define armAbs(a)               ( (a) <  0  ? -(a):(a) )
+
+/* Alignment operation */
+
+#define armAlignToBytes(Ptr,N)      (Ptr + ( ((N-(int)Ptr)&(N-1)) / sizeof(*Ptr) ))
+#define armAlignTo2Bytes(Ptr)       armAlignToBytes(Ptr,2)
+#define armAlignTo4Bytes(Ptr)       armAlignToBytes(Ptr,4)
+#define armAlignTo8Bytes(Ptr)       armAlignToBytes(Ptr,8)
+#define armAlignTo16Bytes(Ptr)      armAlignToBytes(Ptr,16)
+
+/* Error and Alignment check */
+
+#define armRetArgErrIf(condition, code)  if(condition) { return (code); }
+#define armRetDataErrIf(condition, code) if(condition) { return (code); }
+
+#ifndef ALIGNMENT_DOESNT_MATTER
+#define armIsByteAligned(Ptr,N)     ((((int)(Ptr)) % N)==0)
+#define armNotByteAligned(Ptr,N)    ((((int)(Ptr)) % N)!=0)
+#else
+#define armIsByteAligned(Ptr,N)     (1)
+#define armNotByteAligned(Ptr,N)    (0)
+#endif
+
+#define armIs2ByteAligned(Ptr)      armIsByteAligned(Ptr,2)
+#define armIs4ByteAligned(Ptr)      armIsByteAligned(Ptr,4)
+#define armIs8ByteAligned(Ptr)      armIsByteAligned(Ptr,8)
+#define armIs16ByteAligned(Ptr)     armIsByteAligned(Ptr,16)
+
+#define armNot2ByteAligned(Ptr)     armNotByteAligned(Ptr,2)
+#define armNot4ByteAligned(Ptr)     armNotByteAligned(Ptr,4)
+#define armNot8ByteAligned(Ptr)     armNotByteAligned(Ptr,8)
+#define armNot16ByteAligned(Ptr)    armNotByteAligned(Ptr,16)
+#define armNot32ByteAligned(Ptr)    armNotByteAligned(Ptr,32)
+
+/**
+ * Function: armRoundFloatToS16_ref/armRoundFloatToS32_ref/armRoundFloatToS64
+ *
+ * Description:
+ * Converts a double precision value into a short int/int after rounding
+ *
+ * Parameters:
+ * [in]  Value                 Float value to be converted
+ *
+ * Return Value:
+ * [out] converted value in OMX_S16/OMX_S32 format
+ *
+ */
+
+OMX_S16 armRoundFloatToS16 (OMX_F64 Value);
+OMX_S32 armRoundFloatToS32 (OMX_F64 Value);
+OMX_S64 armRoundFloatToS64 (OMX_F64 Value);
+
+/**
+ * Function: armSatRoundFloatToS16_ref/armSatRoundFloatToS32
+ *
+ * Description:
+ * Converts a double precision value into a short int/int after rounding and saturation
+ *
+ * Parameters:
+ * [in]  Value                 Float value to be converted
+ *
+ * Return Value:
+ * [out] converted value in OMX_S16/OMX_S32 format
+ *
+ */
+
+OMX_S16 armSatRoundFloatToS16 (OMX_F64 Value);
+OMX_S32 armSatRoundFloatToS32 (OMX_F64 Value);
+
+/**
+ * Function: armSatRoundFloatToU16_ref/armSatRoundFloatToU32
+ *
+ * Description:
+ * Converts a double precision value into a unsigned short int/int after rounding and saturation
+ *
+ * Parameters:
+ * [in]  Value                 Float value to be converted
+ *
+ * Return Value:
+ * [out] converted value in OMX_U16/OMX_U32 format
+ *
+ */
+
+OMX_U16 armSatRoundFloatToU16 (OMX_F64 Value);
+OMX_U32 armSatRoundFloatToU32 (OMX_F64 Value);
+
+/**
+ * Function: armSignCheck
+ *
+ * Description:
+ * Checks the sign of a variable:
+ * returns 1 if it is Positive
+ * returns 0 if it is 0
+ * returns -1 if it is Negative 
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	    var     Variable to be checked
+ *
+ * Return Value:
+ * OMX_INT --   returns 1 if it is Positive
+ *              returns 0 if it is 0
+ *              returns -1 if it is Negative 
+ */ 
+ 
+OMX_INT armSignCheck (OMX_S16 var);
+
+/**
+ * Function: armClip
+ *
+ * Description: Clips the input between MAX and MIN value
+ * 
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] Min     lower bound
+ * [in] Max     upper bound
+ * [in] src     variable to the clipped
+ *
+ * Return Value:
+ * OMX_S32 --   returns clipped value
+ */ 
+ 
+OMX_S32 armClip (
+        OMX_INT min,
+        OMX_INT max, 
+        OMX_S32 src
+        );
+
+/**
+ * Function: armClip_F32
+ *
+ * Description: Clips the input between MAX and MIN value
+ * 
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] Min     lower bound
+ * [in] Max     upper bound
+ * [in] src     variable to the clipped
+ *
+ * Return Value:
+ * OMX_F32 --   returns clipped value
+ */ 
+ 
+OMX_F32 armClip_F32 (
+        OMX_F32 min,
+        OMX_F32 max, 
+        OMX_F32 src
+        );
+
+/**
+ * Function: armShiftSat_F32
+ *
+ * Description: Divides a float value by 2^shift and 
+ * saturates it for unsigned value range for satBits.
+ * Second parameter is like "shifting" the corresponding 
+ * integer value. Takes care of rounding while clipping the final 
+ * value.
+ *
+ * Parameters:
+ * [in] v          Number to be operated upon
+ * [in] shift      Divides the input "v" by "2^shift"
+ * [in] satBits    Final range is [0, 2^satBits)
+ *
+ * Return Value:
+ * OMX_S32 --   returns "shifted" saturated value
+ */ 
+ 
+OMX_U32 armShiftSat_F32(
+        OMX_F32 v, 
+        OMX_INT shift, 
+        OMX_INT satBits
+        );
+
+/**
+ * Functions: armSwapElem
+ *
+ * Description:
+ * This function swaps two elements at the specified pointer locations.
+ * The size of each element could be anything as specified by <elemSize>
+ *
+ * Return Value:
+ * OMXResult -- Error status from the function
+ */
+OMXResult armSwapElem(OMX_U8 *pBuf1, OMX_U8 *pBuf2, OMX_INT elemSize);
+
+
+/**
+ * Function: armMedianOf3
+ *
+ * Description: Finds the median of three numbers
+ * 
+ * Remarks:
+ *
+ * Parameters:
+ * [in] fEntry     First entry
+ * [in] sEntry     second entry
+ * [in] tEntry     Third entry
+ *
+ * Return Value:
+ * OMX_S32 --   returns the median value
+ */ 
+ 
+OMX_S32 armMedianOf3 (
+    OMX_S32 fEntry,
+    OMX_S32 sEntry, 
+    OMX_S32 tEntry 
+    );
+
+/**
+ * Function: armLogSize
+ *
+ * Description: Finds the size of a positive value and returns the same
+ * 
+ * Remarks:
+ *
+ * Parameters:
+ * [in] value    Positive value
+ *
+ * Return Value:
+ * OMX_U8 --   returns the size of the positive value
+ */ 
+ 
+OMX_U8 armLogSize (
+    OMX_U16 value 
+    );    
+
+/***********************************************************************/
+                /* Saturating Arithmetic operations */
+
+/**
+ * Function :armSatAdd_S32()
+ *
+ * Description :
+ *   Returns the result of saturated addition of the two inputs Value1, Value2
+ *
+ * Parametrs:
+ * [in] Value1       First Operand
+ * [in] Value2       Second Operand
+ *
+ * Return:
+ * [out]             Result of operation
+ * 
+ *    
+ **/
+
+OMX_S32 armSatAdd_S32(
+                OMX_S32 Value1,
+                OMX_S32 Value2
+                );
+
+/**
+ * Function :armSatAdd_S64()
+ *
+ * Description :
+ *   Returns the result of saturated addition of the two inputs Value1, Value2
+ *
+ * Parametrs:
+ * [in] Value1       First Operand
+ * [in] Value2       Second Operand
+ *
+ * Return:
+ * [out]             Result of operation
+ * 
+ *    
+ **/
+
+OMX_S64 armSatAdd_S64(
+                OMX_S64 Value1,
+                OMX_S64 Value2
+                );
+
+/** Function :armSatSub_S32()
+ * 
+ * Description :
+ *     Returns the result of saturated substraction of the two inputs Value1, Value2
+ *
+ * Parametrs:
+ * [in] Value1       First Operand
+ * [in] Value2       Second Operand
+ *
+ * Return:
+ * [out]             Result of operation
+ * 
+ **/
+
+OMX_S32 armSatSub_S32(
+                    OMX_S32 Value1,
+                    OMX_S32 Value2
+                    );
+
+/**
+ * Function :armSatMac_S32()
+ *
+ * Description :
+ *     Returns the result of Multiplication of Value1 and Value2 and subesquent saturated
+ *     accumulation with Mac
+ *
+ * Parametrs:
+ * [in] Value1       First Operand
+ * [in] Value2       Second Operand
+ * [in] Mac          Accumulator
+ *
+ * Return:
+ * [out]             Result of operation
+ **/
+
+OMX_S32 armSatMac_S32(
+                    OMX_S32 Mac,
+                    OMX_S16 Value1,
+                    OMX_S16 Value2
+                    );
+
+/**
+ * Function :armSatMac_S16S32_S32
+ *
+ * Description :
+ *   Returns the result of saturated MAC operation of the three inputs delayElem, filTap , mac
+ *
+ *   mac = mac + Saturate_in_32Bits(delayElem * filTap)
+ *
+ * Parametrs:
+ * [in] delayElem    First 32 bit Operand
+ * [in] filTap       Second 16 bit Operand
+ * [in] mac          Result of MAC operation
+ *
+ * Return:
+ * [out]  mac        Result of operation
+ *    
+ **/
+ 
+OMX_S32 armSatMac_S16S32_S32(
+                        OMX_S32 mac, 
+                        OMX_S32 delayElem, 
+                        OMX_S16 filTap );
+
+/**
+ * Function :armSatRoundRightShift_S32_S16
+ *
+ * Description :
+ *   Returns the result of rounded right shift operation of input by the scalefactor
+ *
+ *   output = Saturate_in_16Bits( ( RightShift( (Round(input) , scaleFactor ) )
+ *
+ * Parametrs:
+ * [in] input       The input to be operated on
+ * [in] scaleFactor The shift number
+ *
+ * Return:
+ * [out]            Result of operation
+ *    
+ **/
+
+
+OMX_S16 armSatRoundRightShift_S32_S16(
+                        OMX_S32 input, 
+                        OMX_INT scaleFactor);
+
+/**
+ * Function :armSatRoundLeftShift_S32()
+ *
+ * Description :
+ *     Returns the result of saturating left-shift operation on input
+ *     Or rounded Right shift if the input Shift is negative.
+ *
+ * Parametrs:
+ * [in] Value        Operand
+ * [in] shift        Operand for shift operation
+ *
+ * Return:
+ * [out]             Result of operation
+ *    
+ **/
+ 
+OMX_S32 armSatRoundLeftShift_S32(
+                        OMX_S32 Value,
+                        OMX_INT shift
+                        );
+
+/**
+ * Function :armSatRoundLeftShift_S64()
+ *
+ * Description :
+ *     Returns the result of saturating left-shift operation on input
+ *     Or rounded Right shift if the input Shift is negative.
+ *
+ * Parametrs:
+ * [in] Value        Operand
+ * [in] shift        Operand for shift operation
+ *
+ * Return:
+ * [out]             Result of operation
+ *    
+ **/
+ 
+OMX_S64 armSatRoundLeftShift_S64(
+                        OMX_S64 Value,
+                        OMX_INT shift
+                        );
+
+/**
+ * Function :armSatMulS16S32_S32()
+ *
+ * Description :
+ *     Returns the result of a S16 data type multiplied with an S32 data type
+ *     in a S32 container
+ *
+ * Parametrs:
+ * [in] input1       Operand 1
+ * [in] input2       Operand 2
+ *
+ * Return:
+ * [out]             Result of operation
+ *    
+ **/
+
+
+OMX_S32 armSatMulS16S32_S32(
+                    OMX_S16 input1,
+                    OMX_S32 input2);
+
+/**
+ * Function :armSatMulS32S32_S32()
+ *
+ * Description :
+ *     Returns the result of a S32 data type multiplied with an S32 data type
+ *     in a S32 container
+ *
+ * Parametrs:
+ * [in] input1       Operand 1
+ * [in] input2       Operand 2
+ *
+ * Return:
+ * [out]             Result of operation
+ *    
+ **/
+
+OMX_S32 armSatMulS32S32_S32(
+                    OMX_S32 input1,
+                    OMX_S32 input2);
+
+
+/**
+ * Function :armIntDivAwayFromZero()
+ *
+ * Description : Integer division with rounding to the nearest integer. 
+ *               Half-integer values are rounded away from zero
+ *               unless otherwise specified. For example 3//2 is rounded 
+ *               to 2, and -3//2 is rounded to -2.
+ *
+ * Parametrs:
+ * [in] Num        Operand 1
+ * [in] Deno       Operand 2
+ *
+ * Return:
+ * [out]             Result of operation input1//input2
+ *    
+ **/
+
+OMX_S32 armIntDivAwayFromZero (OMX_S32 Num, OMX_S32 Deno);
+
+
+/***********************************************************************/
+/*
+ * Debugging macros
+ *
+ */
+
+
+/*
+ * Definition of output stream - change to stderr if necessary
+ */
+#define DEBUG_STREAM stdout
+
+/*
+ * Debug printf macros, one for each argument count.
+ * Add more if needed.
+ */
+#ifdef DEBUG_ON
+#include <stdio.h>
+
+#define DEBUG_PRINTF_0(a)                                               fprintf(DEBUG_STREAM, a)
+#define DEBUG_PRINTF_1(a, b)                                            fprintf(DEBUG_STREAM, a, b)
+#define DEBUG_PRINTF_2(a, b, c)                                         fprintf(DEBUG_STREAM, a, b, c)
+#define DEBUG_PRINTF_3(a, b, c, d)                                      fprintf(DEBUG_STREAM, a, b, c, d)
+#define DEBUG_PRINTF_4(a, b, c, d, e)                                   fprintf(DEBUG_STREAM, a, b, c, d, e)
+#define DEBUG_PRINTF_5(a, b, c, d, e, f)                                fprintf(DEBUG_STREAM, a, b, c, d, e, f)
+#define DEBUG_PRINTF_6(a, b, c, d, e, f, g)                             fprintf(DEBUG_STREAM, a, b, c, d, e, f, g)
+#define DEBUG_PRINTF_7(a, b, c, d, e, f, g, h)                          fprintf(DEBUG_STREAM, a, b, c, d, e, f, g, h)
+#define DEBUG_PRINTF_8(a, b, c, d, e, f, g, h, i)                       fprintf(DEBUG_STREAM, a, b, c, d, e, f, g, h, i)
+#define DEBUG_PRINTF_9(a, b, c, d, e, f, g, h, i, j)                    fprintf(DEBUG_STREAM, a, b, c, d, e, f, g, h, i, j)
+#define DEBUG_PRINTF_10(a, b, c, d, e, f, g, h, i, j, k)                fprintf(DEBUG_STREAM, a, b, c, d, e, f, g, h, i, j, k)
+#define DEBUG_PRINTF_11(a, b, c, d, e, f, g, h, i, j, k, l)             fprintf(DEBUG_STREAM, a, b, c, d, e, f, g, h, i, j, k, l)
+#define DEBUG_PRINTF_12(a, b, c, d, e, f, g, h, i, j, k, l, m)          fprintf(DEBUG_STREAM, a, b, c, d, e, f, g, h, i, j, k, l, m)
+#define DEBUG_PRINTF_13(a, b, c, d, e, f, g, h, i, j, k, l, m, n)       fprintf(DEBUG_STREAM, a, b, c, d, e, f, g, h, i, j, k, l, m, n)
+#define DEBUG_PRINTF_14(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)    fprintf(DEBUG_STREAM, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
+#else /* DEBUG_ON */
+#define DEBUG_PRINTF_0(a)                                  
+#define DEBUG_PRINTF_1(a, b)                               
+#define DEBUG_PRINTF_2(a, b, c)                            
+#define DEBUG_PRINTF_3(a, b, c, d)                         
+#define DEBUG_PRINTF_4(a, b, c, d, e)                      
+#define DEBUG_PRINTF_5(a, b, c, d, e, f)                   
+#define DEBUG_PRINTF_6(a, b, c, d, e, f, g)                
+#define DEBUG_PRINTF_7(a, b, c, d, e, f, g, h)             
+#define DEBUG_PRINTF_8(a, b, c, d, e, f, g, h, i)          
+#define DEBUG_PRINTF_9(a, b, c, d, e, f, g, h, i, j)       
+#define DEBUG_PRINTF_10(a, b, c, d, e, f, g, h, i, j, k)    
+#define DEBUG_PRINTF_11(a, b, c, d, e, f, g, h, i, j, k, l)             
+#define DEBUG_PRINTF_12(a, b, c, d, e, f, g, h, i, j, k, l, m)          
+#define DEBUG_PRINTF_13(a, b, c, d, e, f, g, h, i, j, k, l, m, n)      
+#define DEBUG_PRINTF_14(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)   
+#endif /* DEBUG_ON */
+
+
+/*
+ * Domain and sub domain definitions
+ *
+ * In order to turn on debug for an entire domain or sub-domain
+ * at compile time, one of the DEBUG_DOMAIN_* below may be defined,
+ * which will activate debug in all of the defines it contains.
+ */
+
+#ifdef DEBUG_DOMAIN_AC
+#define DEBUG_OMXACAAC_DECODECHANPAIRELT_MPEG4
+#define DEBUG_OMXACAAC_DECODECHANPAIRELT
+#define DEBUG_OMXACAAC_DECODEDATSTRELT
+#define DEBUG_OMXACAAC_DECODEFILLELT
+#define DEBUG_OMXACAAC_DECODEISSTEREO_S32
+#define DEBUG_OMXACAAC_DECODEMSPNS_S32
+#define DEBUG_OMXACAAC_DECODEMSSTEREO_S32_I
+#define DEBUG_OMXACAAC_DECODEPRGCFGELT
+#define DEBUG_OMXACAAC_DECODETNS_S32_I
+#define DEBUG_OMXACAAC_DEINTERLEAVESPECTRUM_S32
+#define DEBUG_OMXACAAC_ENCODETNS_S32_I
+#define DEBUG_OMXACAAC_LONGTERMPREDICT_S32
+#define DEBUG_OMXACAAC_LONGTERMRECONSTRUCT_S32
+#define DEBUG_OMXACAAC_MDCTFWD_S32
+#define DEBUG_OMXACAAC_MDCTINV_S32_S16
+#define DEBUG_OMXACAAC_NOISELESSDECODE
+#define DEBUG_OMXACAAC_QUANTINV_S32_I
+#define DEBUG_OMXACAAC_UNPACKADIFHEADER
+#define DEBUG_OMXACAAC_UNPACKADTSFRAMEHEADER
+#define DEBUG_OMXACMP3_HUFFMANDECODESFBMBP_S32
+#define DEBUG_OMXACMP3_HUFFMANDECODESFB_S32
+#define DEBUG_OMXACMP3_HUFFMANDECODE_S32
+#define DEBUG_OMXACMP3_MDCTINV_S32
+#define DEBUG_OMXACMP3_REQUANTIZESFB_S32_I
+#define DEBUG_OMXACMP3_REQUANTIZE_S32_I
+#define DEBUG_OMXACMP3_SYNTHPQMF_S32_S16
+#define DEBUG_OMXACMP3_UNPACKFRAMEHEADER
+#define DEBUG_OMXACMP3_UNPACKSCALEFACTORS_S8
+#define DEBUG_OMXACMP3_UNPACKSIDEINFO
+#endif /* DEBUG_DOMAIN_AC */
+
+
+#ifdef DEBUG_DOMAIN_VC
+#define DEBUG_OMXVCM4P10_AVERAGE_16X
+#define DEBUG_OMXVCM4P10_AVERAGE_4X
+#define DEBUG_OMXVCM4P10_AVERAGE_8X
+#define DEBUG_OMXVCM4P10_DEBLOCKCHROMA_U8_C1IR
+#define DEBUG_OMXVCM4P10_DEBLOCKLUMA_U8_C1IR
+#define DEBUG_OMXVCM4P10_DECODECHROMADCCOEFFSTOPAIRCAVLC_U8
+#define DEBUG_OMXVCM4P10_DECODECOEFFSTOPAIRCAVLC_U8
+#define DEBUG_OMXVCM4P10_DEQUANTTRANSFORMACFROMPAIR_U8_S16_C1_DLX
+#define DEBUG_OMXVCM4P10_EXPANDFRAME
+#define DEBUG_OMXVCM4P10_FILTERDEBLOCKINGCHROMA_HOREDGE_U8_C1IR
+#define DEBUG_OMXVCM4P10_FILTERDEBLOCKINGCHROMA_VEREDGE_U8_C1IR
+#define DEBUG_OMXVCM4P10_FILTERDEBLOCKINGLUMA_HOREDGE_U8_C1IR
+#define DEBUG_OMXVCM4P10_FILTERDEBLOCKINGLUMA_VEREDGE_U8_C1IR
+#define DEBUG_OMXVCM4P10_PREDICTINTRACHROMA8X8_U8_C1R
+#define DEBUG_OMXVCM4P10_PREDICTINTRA_16X16_U8_C1R
+#define DEBUG_OMXVCM4P10_PREDICTINTRA_4X4_U8_C1R
+#define DEBUG_OMXVCM4P10_SADQUAR_16X
+#define DEBUG_OMXVCM4P10_SADQUAR_4X
+#define DEBUG_OMXVCM4P10_SADQUAR_8X
+#define DEBUG_OMXVCM4P10_SAD_16X
+#define DEBUG_OMXVCM4P10_SAD_4X
+#define DEBUG_OMXVCM4P10_SAD_8X
+#define DEBUG_OMXVCM4P10_SATD_4X4
+#define DEBUG_OMXVCM4P10_TRANSFORMDEQUANTCHROMADCFROMPAIR_U8_S16_C1
+#define DEBUG_OMXVCM4P10_TRANSFORMDEQUANTLUMADCFROMPAIR_U8_S16_C1
+#define DEBUG_OMXVCM4P10_TRANSFORMQUANT_CHROMADC
+#define DEBUG_OMXVCM4P10_TRANSFORMQUANT_LUMADC
+#define DEBUG_OMXVCM4P2_BLOCKMATCH_HALF_16X16
+#define DEBUG_OMXVCM4P2_BLOCKMATCH_HALF_8X8
+#define DEBUG_OMXVCM4P2_BLOCKMATCH_INTEGER_16X16
+#define DEBUG_OMXVCM4P2_BLOCKMATCH_INTEGER_8X8
+#define DEBUG_OMXVCM4P2_COMPUTETEXTUREERRORBLOCK_SAD_U8_S16
+#define DEBUG_OMXVCM4P2_COMPUTETEXTUREERRORBLOCK_U8_S16
+#define DEBUG_OMXVCM4P2_DCT8X8BLKDLX
+#define DEBUG_OMXVCM4P2_DECODEBLOCKCOEF_INTER_S16
+#define DEBUG_OMXVCM4P2_DECODEPADMV_PVOP
+#define DEBUG_OMXVCM4P2_DECODEVLCZIGZAG_INTER_S16
+#define DEBUG_OMXVCM4P2_DECODEVLCZIGZAG_INTRAACVLC_S16
+#define DEBUG_OMXVCM4P2_DECODEVLCZIGZAG_INTRADCVLC_S16
+#define DEBUG_OMXVCM4P2_ENCODEMV_U8_S16
+#define DEBUG_OMXVCM4P2_ENCODEVLCZIGZAG_INTER_S16
+#define DEBUG_OMXVCM4P2_ENCODEVLCZIGZAG_INTRAACVLC_S16
+#define DEBUG_OMXVCM4P2_ENCODEVLCZIGZAG_INTRADCVLC_S16
+#define DEBUG_OMXVCM4P2_FINDMVPRED
+#define DEBUG_OMXVCM4P2_IDCT8X8BLKDLX
+#define DEBUG_OMXVCM4P2_LIMITMVTORECT
+#define DEBUG_OMXVCM4P2_MOTIONESTIMATIONMB
+#define DEBUG_OMXVCM4P2_PADMBGRAY_U8
+#define DEBUG_OMXVCM4P2_PADMBHORIZONTAL_U8
+#define DEBUG_OMXVCM4P2_PADMBVERTICAL_U8
+#define DEBUG_OMXVCM4P2_PADMV
+#define DEBUG_OMXVCM4P2_QUANTINTER_S16_I
+#define DEBUG_OMXVCM4P2_QUANTINTRA_S16_I
+#define DEBUG_OMXVCM4P2_QUANTINVINTER_S16_I
+#define DEBUG_OMXVCM4P2_QUANTINVINTRA_S16_I
+#define DEBUG_OMXVCM4P2_TRANSRECBLOCKCEOF_INTER
+#define DEBUG_OMXVCM4P2_TRANSRECBLOCKCEOF_INTRA
+#endif /* DEBUG_DOMAIN_VC */
+
+
+#ifdef DEBUG_DOMAIN_IC
+/* To be filled in */
+#endif /* DEBUG_DOMAIN_IC */
+
+
+#ifdef DEBUG_DOMAIN_SP
+#define DEBUG_OMXACSP_DOTPROD_S16
+#define DEBUG_OMXACSP_BLOCKEXP_S16
+#define DEBUG_OMXACSP_BLOCKEXP_S32
+#define DEBUG_OMXACSP_COPY_S16
+#define DEBUG_OMXACSP_DOTPROD_S16
+#define DEBUG_OMXACSP_DOTPROD_S16_SFS
+#define DEBUG_OMXACSP_FFTFWD_CTOC_SC16_SFS
+#define DEBUG_OMXACSP_FFTFWD_CTOC_SC32_SFS
+#define DEBUG_OMXACSP_FFTFWD_RTOCCS_S16S32_SFS
+#define DEBUG_OMXACSP_FFTFWD_RTOCCS_S32_SFS
+#define DEBUG_OMXACSP_FFTGETBUFSIZE_C_SC16
+#define DEBUG_OMXACSP_FFTGETBUFSIZE_C_SC32
+#define DEBUG_OMXACSP_FFTGETBUFSIZE_R_S16_S32
+#define DEBUG_OMXACSP_FFTGETBUFSIZE_R_S32
+#define DEBUG_OMXACSP_FFTINIT_C_SC16
+#define DEBUG_OMXACSP_FFTINIT_C_SC32
+#define DEBUG_OMXACSP_FFTINIT_R_S16_S32
+#define DEBUG_OMXACSP_FFTINIT_R_S32
+#define DEBUG_OMXACSP_FFTINV_CCSTOR_S32S16_SFS
+#define DEBUG_OMXACSP_FFTINV_CCSTOR_S32_SFS
+#define DEBUG_OMXACSP_FFTINV_CTOC_SC16_SFS
+#define DEBUG_OMXACSP_FFTINV_CTOC_SC32_SFS
+#define DEBUG_OMXACSP_FILTERMEDIAN_S32_I
+#define DEBUG_OMXACSP_FILTERMEDIAN_S32
+#define DEBUG_OMXACSP_FIRONE_DIRECT_S16_ISFS
+#define DEBUG_OMXACSP_FIRONE_DIRECT_S16_I
+#define DEBUG_OMXACSP_FIRONE_DIRECT_S16
+#define DEBUG_OMXACSP_FIRONE_DIRECT_S16_SFS
+#define DEBUG_OMXACSP_FIR_DIRECT_S16_ISFS
+#define DEBUG_OMXACSP_FIR_DIRECT_S16_I
+#define DEBUG_OMXACSP_FIR_DIRECT_S16
+#define DEBUG_OMXACSP_FIR_DIRECT_S16_SFS
+#define DEBUG_OMXACSP_IIRONE_BIQUADDIRECT_S16_I
+#define DEBUG_OMXACSP_IIRONE_BIQUADDIRECT_S16
+#define DEBUG_OMXACSP_IIRONE_DIRECT_S16_I
+#define DEBUG_OMXACSP_IIRONE_DIRECT_S16
+#define DEBUG_OMXACSP_IIR_BIQUADDIRECT_S16_I
+#define DEBUG_OMXACSP_IIR_BIQUADDIRECT_S16
+#define DEBUG_OMXACSP_IIR_DIRECT_S16_I
+#define DEBUG_OMXACSP_IIR_DIRECT_S16
+#endif /* DEBUG_DOMAIN_SP */
+
+
+#ifdef DEBUG_DOMAIN_IP
+#define DEBUG_OMXIPBM_ADDC_U8_C1R_SFS
+#define DEBUG_OMXIPBM_COPY_U8_C1R
+#define DEBUG_OMXIPBM_COPY_U8_C3R
+#define DEBUG_OMXIPBM_MIRROR_U8_C1R
+#define DEBUG_OMXIPBM_MULC_U8_C1R_SFS
+#define DEBUG_OMXIPCS_COLORTWISTQ14_U8_C3R
+#define DEBUG_OMXIPCS_RGB565TOYCBCR420LS_MCU_U16_S16_C3P3R
+#define DEBUG_OMXIPCS_RGB565TOYCBCR422LS_MCU_U16_S16_C3P3R
+#define DEBUG_OMXIPCS_RGB565TOYCBCR444LS_MCU_U16_S16_C3P3R
+#define DEBUG_OMXIPCS_RGBTOYCBCR420LS_MCU_U8_S16_C3P3R
+#define DEBUG_OMXIPCS_RGBTOYCBCR422LS_MCU_U8_S16_C3P3R
+#define DEBUG_OMXIPCS_RGBTOYCBCR444LS_MCU_U8_S16_C3P3R
+#define DEBUG_OMXIPCS_YCBCR420RSZROT_U8_P3R
+#define DEBUG_OMXIPCS_YCBCR420TORGB565LS_MCU_S16_U16_P3C3R
+#define DEBUG_OMXIPCS_YCBCR420TORGB565_U8_U16_P3C3R
+#define DEBUG_OMXIPCS_YCBCR420TORGBLS_MCU_S16_U8_P3C3R
+#define DEBUG_OMXIPCS_YCBCR422RSZCSCROTRGB_U8_C2R
+#define DEBUG_OMXIPCS_YCBCR422RSZROT_U8_P3R
+#define DEBUG_OMXIPCS_YCBCR422TORGB565LS_MCU_S16_U16_P3C3R
+#define DEBUG_OMXIPCS_YCBCR422TORGB565_U8_U16_C2C3R
+#define DEBUG_OMXIPCS_YCBCR422TORGBLS_MCU_S16_U8_P3C3R
+#define DEBUG_OMXIPCS_YCBCR422TORGB_U8_C2C3R
+#define DEBUG_OMXIPCS_YCBCR422TOYCBCR420ROTATE_U8_C2P3R
+#define DEBUG_OMXIPCS_YCBCR422TOYCBCR420ROTATE_U8_P3R
+#define DEBUG_OMXIPCS_YCBCR444TORGB565LS_MCU_S16_U16_P3C3R
+#define DEBUG_OMXIPCS_YCBCR444TORGBLS_MCU_S16_U8_P3C3R
+#define DEBUG_OMXIPCS_YCBCRTORGB565_U8_U16_C3R
+#define DEBUG_OMXIPCS_YCBCRTORGB565_U8_U16_P3C3R
+#define DEBUG_OMXIPCS_YCBCRTORGB_U8_C3R
+#define DEBUG_OMXIPPP_GETCENTRALMOMENT_S64
+#define DEBUG_OMXIPPP_GETSPATIALMOMENT_S64
+#define DEBUG_OMXIPPP_MOMENTGETSTATESIZE_S64
+#define DEBUG_OMXIPPP_MOMENTINIT_S64
+#define DEBUG_OMXIPPP_MOMENTS64S_U8_C1R
+#define DEBUG_OMXIPPP_MOMENTS64S_U8_C3R
+#endif /* DEBUG_DOMAIN_IP */
+
+
+#endif /* _armCommon_H_ */
+
+/*End of File*/
+
+
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/api/armCOMM_BitDec_s.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/api/armCOMM_BitDec_s.h
new file mode 100644
index 0000000..abb98fc
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/api/armCOMM_BitDec_s.h
@@ -0,0 +1,670 @@
+;//
+;// 
+;// File Name:  armCOMM_BitDec_s.h
+;// OpenMAX DL: v1.0.2
+;// Revision:   9641
+;// Date:       Thursday, February 7, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;// 
+;// OpenMAX optimized bitstream decode module
+;//
+;// You must include armCOMM_s.h before including this file
+;//
+;// This module provides macros to perform assembly optimized fixed and
+;// variable length decoding from a read-only bitstream. The variable
+;// length decode modules take as input a pointer to a table of 16-bit
+;// entries of the following format.
+;//
+;// VLD Table Entry format
+;//
+;//        15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
+;//       +------------------------------------------------+
+;//       |  Len   |               Symbol              | 1 |
+;//       +------------------------------------------------+
+;//       |                Offset                      | 0 |
+;//       +------------------------------------------------+
+;//
+;// If the table entry is a leaf entry then bit 0 set:
+;//    Len    = Number of bits overread (0 to 7)
+;//    Symbol = Symbol payload (unsigned 12 bits)
+;//
+;// If the table entry is an internal node then bit 0 is clear:
+;//    Offset = Number of (16-bit) half words from the table
+;//             start to the next table node
+;//
+;// The table is accessed by successive lookup up on the
+;// next Step bits of the input bitstream until a leaf node
+;// is obtained. The Step sizes are supplied to the VLD macro.
+;//
+;// USAGE:
+;//
+;// To use any of the macros in this package, first call:
+;//
+;//    M_BD_INIT ppBitStream, pBitOffset, pBitStream, RBitBuffer, RBitCount, Tmp
+;//
+;// This caches the current bitstream position and next available
+;// bits in registers pBitStream, RBitBuffer, RBitCount. These registers
+;// are reserved for use by the bitstream decode package until you
+;// call M_BD_FINI.
+;//
+;// Next call the following macro(s) as many times as you need:
+;//
+;//    M_BD_LOOK8       - Look ahead constant 1<=N<=8  bits into the bitstream
+;//    M_BD_LOOK16      - Look ahead constant 1<=N<=16 bits into the bitstream
+;//    M_BD_READ8       - Read constant 1<=N<=8  bits from the bitstream
+;//    M_BD_READ16      - Read constant 1<=N<=16 bits from the bitstream
+;//    M_BD_VREAD8      - Read variable 1<=N<=8  bits from the bitstream
+;//    M_BD_VREAD16     - Read variable 1<=N<=16 bits from the bitstream
+;//    M_BD_VLD         - Perform variable length decode using lookup table
+;//
+;// Finally call the macro:
+;//
+;//    M_BD_FINI ppBitStream, pBitOffset
+;//
+;// This writes the bitstream state back to memory.
+;//
+;// The three bitstream cache register names are assigned to the following global
+;// variables:
+;//
+
+        GBLS    pBitStream  ;// Register name for pBitStream
+        GBLS    BitBuffer   ;// Register name for BitBuffer
+        GBLS    BitCount    ;// Register name for BitCount
+   
+;//        
+;// These register variables must have a certain defined state on entry to every bitstream
+;// macro (except M_BD_INIT) and on exit from every bitstream macro (except M_BD_FINI).
+;// The state may depend on implementation.
+;//
+;// For the default (ARM11) implementation the following hold:
+;//    pBitStream - points to the first byte not held in the BitBuffer
+;//    BitBuffer  - is a cache of (4 bytes) 32 bits, bit 31 the first bit
+;//    BitCount   - is offset (from the top bit) to the next unused bitstream bit
+;//    0<=BitCount<=15 (so BitBuffer holds at least 17 unused bits)
+;//
+;//
+
+        ;// Bitstream Decode initialise
+        ;//
+        ;// Initialises the bitstream decode global registers from
+        ;// bitstream pointers. This macro is split into 3 parts to enable
+        ;// scheduling.
+        ;//
+        ;// Input Registers:
+        ;//
+        ;// $ppBitStream    - pointer to pointer to the next bitstream byte
+        ;// $pBitOffset     - pointer to the number of bits used in the current byte (0..7)
+        ;// $RBitStream     - register to use for pBitStream (can be $ppBitStream)
+        ;// $RBitBuffer     - register to use for BitBuffer
+        ;// $RBitCount      - register to use for BitCount   (can be $pBitOffset)
+        ;//
+        ;// Output Registers:
+        ;//
+        ;// $T1,$T2,$T3     - registers that must be preserved between calls to
+        ;//                   M_BD_INIT1 and M_BD_INIT2
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;//
+        MACRO
+        M_BD_INIT0  $ppBitStream, $pBitOffset, $RBitStream, $RBitBuffer, $RBitCount
+
+pBitStream  SETS "$RBitStream"
+BitBuffer   SETS "$RBitBuffer"
+BitCount    SETS "$RBitCount"        
+        
+        ;// load inputs
+        LDR     $pBitStream, [$ppBitStream]
+        LDR     $BitCount, [$pBitOffset]
+        MEND
+        
+        MACRO
+        M_BD_INIT1  $T1, $T2, $T3
+        LDRB    $T2, [$pBitStream, #2]
+        LDRB    $T1, [$pBitStream, #1]
+        LDRB    $BitBuffer,  [$pBitStream], #3
+        ADD     $BitCount, $BitCount, #8
+        MEND
+        
+        MACRO
+        M_BD_INIT2  $T1, $T2, $T3
+        ORR     $T2, $T2, $T1, LSL #8
+        ORR     $BitBuffer, $T2, $BitBuffer, LSL #16
+        MEND    
+        
+        ;//
+        ;// Look ahead fixed 1<=N<=8 bits without consuming any bits
+        ;// The next bits will be placed at bit 31..24 of destination register
+        ;//
+        ;// Input Registers:
+        ;//
+        ;// $N              - number of bits to look
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;// 
+        ;// Output Registers:
+        ;//
+        ;// $Symbol         - the next N bits of the bitstream
+        ;// $T1             - corrupted temp/scratch register
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;//
+        MACRO
+        M_BD_LOOK8  $Symbol, $N
+        ASSERT  ($N>=1):LAND:($N<=8)
+        MOV     $Symbol, $BitBuffer, LSL $BitCount
+        MEND
+        
+        ;//
+        ;// Look ahead fixed 1<=N<=16 bits without consuming any bits
+        ;// The next bits will be placed at bit 31..16 of destination register
+        ;//
+        ;// Input Registers:
+        ;//
+        ;// $N              - number of bits to look
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;// 
+        ;// Output Registers:
+        ;//
+        ;// $Symbol         - the next N bits of the bitstream
+        ;// $T1             - corrupted temp/scratch register
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;//
+        MACRO
+        M_BD_LOOK16  $Symbol, $N, $T1
+        ASSERT  ($N >= 1):LAND:($N <= 16)
+        MOV     $Symbol, $BitBuffer, LSL $BitCount
+        MEND
+        
+        ;//
+        ;// Skips fixed 1<=N<=8 bits from the bitstream, advancing the bitstream pointer
+        ;//
+        ;// Input Registers:
+        ;//
+        ;// $N              - number of bits
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;// 
+        ;// Output Registers:
+        ;//
+        ;// $T1             - corrupted temp/scratch register
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;//
+        MACRO
+        M_BD_SKIP8 $N, $T1
+        ASSERT  ($N>=1):LAND:($N<=8)        
+        SUBS    $BitCount, $BitCount, #(8-$N)
+        LDRCSB  $T1, [$pBitStream], #1   
+        ADDCC   $BitCount, $BitCount, #8
+        ORRCS   $BitBuffer, $T1, $BitBuffer, LSL #8
+        MEND
+        
+        
+        ;//
+        ;// Read fixed 1<=N<=8 bits from the bitstream, advancing the bitstream pointer
+        ;//
+        ;// Input Registers:
+        ;//
+        ;// $N              - number of bits to read
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;// 
+        ;// Output Registers:
+        ;//
+        ;// $Symbol         - the next N bits of the bitstream
+        ;// $T1             - corrupted temp/scratch register
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;//
+        MACRO
+        M_BD_READ8 $Symbol, $N, $T1
+        ASSERT  ($N>=1):LAND:($N<=8)                
+        MOVS    $Symbol, $BitBuffer, LSL $BitCount        
+        SUBS    $BitCount, $BitCount, #(8-$N)
+        LDRCSB  $T1, [$pBitStream], #1   
+        ADDCC   $BitCount, $BitCount, #8
+        MOV     $Symbol, $Symbol, LSR #(32-$N)
+        ORRCS   $BitBuffer, $T1, $BitBuffer, LSL #8
+        MEND
+
+        ;//
+        ;// Read fixed 1<=N<=16 bits from the bitstream, advancing the bitstream pointer
+        ;//
+        ;// Input Registers:
+        ;//
+        ;// $N              - number of bits to read
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;// 
+        ;// Output Registers:
+        ;//
+        ;// $Symbol         - the next N bits of the bitstream
+        ;// $T1             - corrupted temp/scratch register
+        ;// $T2             - corrupted temp/scratch register
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;//
+        MACRO
+        M_BD_READ16 $Symbol, $N, $T1, $T2
+        ASSERT  ($N>=1):LAND:($N<=16)
+        ASSERT  $Symbol<>$T1
+        IF ($N<=8)
+            M_BD_READ8  $Symbol, $N, $T1
+        ELSE        
+            ;// N>8 so we will be able to refill at least one byte            
+            LDRB    $T1, [$pBitStream], #1            
+            MOVS    $Symbol, $BitBuffer, LSL $BitCount
+            ORR     $BitBuffer, $T1, $BitBuffer, LSL #8                       
+            SUBS    $BitCount, $BitCount, #(16-$N)
+            LDRCSB  $T1, [$pBitStream], #1            
+            MOV     $Symbol, $Symbol, LSR #(32-$N)
+            ADDCC   $BitCount, $BitCount, #8
+            ORRCS   $BitBuffer, $T1, $BitBuffer, LSL #8
+        ENDIF
+        MEND
+        
+        ;//
+        ;// Skip variable 1<=N<=8 bits from the bitstream, advancing the bitstream pointer.
+        ;//
+        ;// Input Registers:
+        ;//
+        ;// $N              - number of bits. 1<=N<=8
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;// 
+        ;// Output Registers:
+        ;//
+        ;// $T1             - corrupted temp/scratch register
+        ;// $T2             - corrupted temp/scratch register
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;//
+        MACRO
+        M_BD_VSKIP8 $N, $T1
+        ADD     $BitCount, $BitCount, $N
+        SUBS    $BitCount, $BitCount, #8
+        LDRCSB  $T1, [$pBitStream], #1        
+        ADDCC   $BitCount, $BitCount, #8
+        ORRCS   $BitBuffer, $T1, $BitBuffer, LSL #8
+        MEND        
+        
+        ;//
+        ;// Skip variable 1<=N<=16 bits from the bitstream, advancing the bitstream pointer.
+        ;//
+        ;// Input Registers:
+        ;//
+        ;// $N              - number of bits. 1<=N<=16
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;// 
+        ;// Output Registers:
+        ;//
+        ;// $T1             - corrupted temp/scratch register
+        ;// $T2             - corrupted temp/scratch register
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;//
+        MACRO
+        M_BD_VSKIP16 $N, $T1, $T2
+        ADD     $BitCount, $BitCount, $N
+        SUBS    $BitCount, $BitCount, #8
+        LDRCSB  $T1, [$pBitStream], #1        
+        ORRCS   $BitBuffer, $T1, $BitBuffer, LSL #8
+        SUBCSS  $BitCount, $BitCount, #8        
+        LDRCSB  $T1, [$pBitStream], #1
+        ADDCC   $BitCount, $BitCount, #8
+        ORRCS   $BitBuffer, $T1, $BitBuffer, LSL #8
+        MEND        
+
+        ;//
+        ;// Read variable 1<=N<=8 bits from the bitstream, advancing the bitstream pointer.
+        ;//
+        ;// Input Registers:
+        ;//
+        ;// $N              - number of bits to read. 1<=N<=8
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;// 
+        ;// Output Registers:
+        ;//
+        ;// $Symbol         - the next N bits of the bitstream
+        ;// $T1             - corrupted temp/scratch register
+        ;// $T2             - corrupted temp/scratch register
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;//
+        MACRO
+        M_BD_VREAD8 $Symbol, $N, $T1, $T2
+        MOV     $Symbol, $BitBuffer, LSL $BitCount        
+        ADD     $BitCount, $BitCount, $N
+        SUBS    $BitCount, $BitCount, #8
+        LDRCSB  $T1, [$pBitStream], #1        
+        RSB     $T2, $N, #32        
+        ADDCC   $BitCount, $BitCount, #8
+        MOV     $Symbol, $Symbol, LSR $T2
+        ORRCS   $BitBuffer, $T1, $BitBuffer, LSL #8
+        MEND
+
+
+        ;//
+        ;// Read variable 1<=N<=16 bits from the bitstream, advancing the bitstream pointer.
+        ;//
+        ;// Input Registers:
+        ;//
+        ;// $N              - number of bits to read. 1<=N<=16
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;// 
+        ;// Output Registers:
+        ;//
+        ;// $Symbol         - the next N bits of the bitstream
+        ;// $T1             - corrupted temp/scratch register
+        ;// $T2             - corrupted temp/scratch register
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;//
+        MACRO
+        M_BD_VREAD16 $Symbol, $N, $T1, $T2
+        MOV     $Symbol, $BitBuffer, LSL $BitCount        
+        ADD     $BitCount, $BitCount, $N
+        SUBS    $BitCount, $BitCount, #8
+        LDRCSB  $T1, [$pBitStream], #1        
+        RSB     $T2, $N, #32        
+        ORRCS   $BitBuffer, $T1, $BitBuffer, LSL #8
+        SUBCSS  $BitCount, $BitCount, #8        
+        LDRCSB  $T1, [$pBitStream], #1
+        ADDCC   $BitCount, $BitCount, #8
+        MOV     $Symbol, $Symbol, LSR $T2
+        ORRCS   $BitBuffer, $T1, $BitBuffer, LSL #8
+        MEND
+
+
+        ;//
+        ;// Decode a code of the form 0000...001 where there
+        ;// are N zeros before the 1 and N<=15 (code length<=16)
+        ;//
+        ;// Input Registers:
+        ;//
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;// 
+        ;// Output Registers:
+        ;//
+        ;// $Symbol         - the number of zeros before the next 1
+        ;//                   >=16 is an illegal code
+        ;// $T1             - corrupted temp/scratch register
+        ;// $T2             - corrupted temp/scratch register
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;//        
+        MACRO
+        M_BD_CLZ16 $Symbol, $T1, $T2
+        MOVS    $Symbol, $BitBuffer, LSL $BitCount
+        CLZ     $Symbol, $Symbol                
+        ADD     $BitCount, $BitCount, $Symbol
+        SUBS    $BitCount, $BitCount, #7        ;// length is Symbol+1
+        LDRCSB  $T1, [$pBitStream], #1
+        ORRCS   $BitBuffer, $T1, $BitBuffer, LSL #8
+        SUBCSS  $BitCount, $BitCount, #8        
+        LDRCSB  $T1, [$pBitStream], #1
+        ADDCC   $BitCount, $BitCount, #8
+        ORRCS   $BitBuffer, $T1, $BitBuffer, LSL #8
+        MEND  
+
+        ;//
+        ;// Decode a code of the form 1111...110 where there
+        ;// are N ones before the 0 and N<=15 (code length<=16)
+        ;//
+        ;// Input Registers:
+        ;//
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;// 
+        ;// Output Registers:
+        ;//
+        ;// $Symbol         - the number of zeros before the next 1
+        ;//                   >=16 is an illegal code
+        ;// $T1             - corrupted temp/scratch register
+        ;// $T2             - corrupted temp/scratch register
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;//        
+        MACRO
+        M_BD_CLO16 $Symbol, $T1, $T2
+        MOV     $Symbol, $BitBuffer, LSL $BitCount
+        MVN     $Symbol, $Symbol
+        CLZ     $Symbol, $Symbol                
+        ADD     $BitCount, $BitCount, $Symbol
+        SUBS    $BitCount, $BitCount, #7        ;// length is Symbol+1
+        LDRCSB  $T1, [$pBitStream], #1
+        ORRCS   $BitBuffer, $T1, $BitBuffer, LSL #8
+        SUBCSS  $BitCount, $BitCount, #8        
+        LDRCSB  $T1, [$pBitStream], #1
+        ADDCC   $BitCount, $BitCount, #8
+        ORRCS   $BitBuffer, $T1, $BitBuffer, LSL #8
+        MEND  
+
+
+        ;//
+        ;// Variable Length Decode module
+        ;//
+        ;// Decodes one VLD Symbol from a bitstream and refill the bitstream
+        ;// buffer.
+        ;//
+        ;// Input Registers:
+        ;//
+        ;// $pVLDTable      - pointer to VLD decode table of 16-bit entries.
+        ;//                   The format is described above at the start of
+        ;//                   this file.
+        ;// $S0             - The number of bits to look up for the first step
+        ;//                   1<=$S0<=8
+        ;// $S1             - The number of bits to look up for each subsequent
+        ;//                   step 1<=$S1<=$S0.
+        ;//
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;// 
+        ;// Output Registers:
+        ;//
+        ;// $Symbol         - decoded VLD symbol value
+        ;// $T1             - corrupted temp/scratch register
+        ;// $T2             - corrupted temp/scratch register
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;//
+        MACRO
+        M_BD_VLD $Symbol, $T1, $T2, $pVLDTable, $S0, $S1
+        ASSERT (1<=$S0):LAND:($S0<=8)
+        ASSERT (1<=$S1):LAND:($S1<=$S0)
+        
+        ;// Note 0<=BitCount<=15 on entry and exit
+        
+        MOVS    $T1, $BitBuffer, LSL $BitCount       ;// left align next bits
+        MOVS    $Symbol, #(2<<$S0)-2                 ;// create mask
+        AND     $Symbol, $Symbol, $T1, LSR #(31-$S0) ;// 2*(next $S0 bits)
+        SUBS    $BitCount, $BitCount, #8             ;// CS if buffer can be filled
+01
+        LDRCSB  $T1, [$pBitStream], #1               ;// load refill byte
+        LDRH    $Symbol, [$pVLDTable, $Symbol]       ;// load table entry
+        ADDCC   $BitCount, $BitCount, #8             ;// refill not possible
+        ADD     $BitCount, $BitCount, #$S0           ;// assume $S0 bits used
+        ORRCS   $BitBuffer, $T1, $BitBuffer, LSL #8  ;// merge in refill byte
+        MOVS    $T1, $Symbol, LSR #1                 ;// CS=leaf entry
+        BCS     %FT02
+        
+        MOVS    $T1, $BitBuffer, LSL $BitCount       ;// left align next bit
+        IF (2*$S0-$S1<=8)
+            ;// Can combine refill check and -S0+S1 and keep $BitCount<=15
+            SUBS    $BitCount, $BitCount, #8+($S0-$S1)
+        ELSE
+            ;// Separate refill check and -S0+S1 offset
+            SUBS  $BitCount, $BitCount, #8
+            SUB   $BitCount, $BitCount, #($S0-$S1)
+        ENDIF
+        ADD     $Symbol, $Symbol, $T1, LSR #(31-$S1) ;// add 2*(next $S1 bits) to
+        BIC     $Symbol, $Symbol, #1                 ;//   table offset
+        B       %BT01                                ;// load next table entry
+02
+        ;// BitCount range now depend on the route here
+        ;// if (first step)       S0 <= BitCount <= 7+S0        <=15
+        ;// else if (2*S0-S1<=8)  S0 <= BitCount <= 7+(2*S0-S1) <=15
+        ;// else                  S1 <= BitCount <= 7+S1        <=15
+        
+        SUB     $BitCount, $BitCount, $Symbol, LSR#13
+        BIC     $Symbol, $T1, #0xF000
+        MEND
+        
+
+        ;// Add an offset number of bits
+        ;//
+        ;// Outputs destination byte and bit index values which corresponds to an offset number of bits 
+        ;// from the current location. This is used to compare bitstream positions using. M_BD_CMP.
+        ;//
+        ;// Input Registers:
+        ;//
+        ;// $Offset         - Offset to be added in bits.
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;//
+        ;// Output Registers:
+        ;//
+        ;// $ByteIndex      - Destination pBitStream pointer after adding the Offset. 
+        ;//                   This value will be 4 byte ahead and needs to subtract by 4 to get exact 
+        ;//                   pointer (as in M_BD_FINI). But for using with M_BD_CMP subtract is not needed.
+        ;// $BitIndex       - Destination BitCount after the addition of Offset number of bits
+        ;//
+        MACRO
+        M_BD_ADD  $ByteIndex, $BitIndex, $Offset
+
+        ;// ($ByteIndex,$BitIndex) = Current position + $Offset bits
+        ADD     $Offset, $Offset, $BitCount
+        AND     $BitIndex, $Offset, #7
+        ADD     $ByteIndex, $pBitStream, $Offset, ASR #3        
+        MEND
+
+        ;// Move bitstream pointers to the location given
+        ;//
+        ;// Outputs destination byte and bit index values which corresponds to  
+        ;// the current location given (calculated using M_BD_ADD). 
+        ;//
+        ;// Input Registers:
+        ;//
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;// $ByteIndex      - Destination pBitStream pointer after move. 
+        ;//                   This value will be 4 byte ahead and needs to subtract by 4 to get exact 
+        ;//                   pointer (as in M_BD_FINI).
+        ;// $BitIndex       - Destination BitCount after the move
+        ;//
+        ;// Output Registers:
+        ;//
+        ;// $pBitStream     \ 
+        ;//                  } See description above.  
+        ;// $BitCount       / 
+        ;//
+        MACRO
+        M_BD_MOV  $ByteIndex, $BitIndex
+
+        ;// ($pBitStream, $Offset) = ($ByteIndex,$BitIndex)
+        MOV     $BitCount, $BitIndex
+        MOV     $pBitStream, $ByteIndex
+        MEND
+
+        ;// Bitstream Compare
+        ;//
+        ;// Compares bitstream position with that of a destination position. Destination position 
+        ;// is held in two input registers which are calculated using M_BD_ADD macro
+        ;//
+        ;// Input Registers:
+        ;//
+        ;// $ByteIndex      - Destination pBitStream pointer, (4 byte ahead as described in M_BD_ADD)
+        ;// $BitIndex       - Destination BitCount
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;//
+        ;// Output Registers:
+        ;//
+        ;// FLAGS           - GE if destination is reached, LT = is destination is ahead
+        ;// $T1             - corrupted temp/scratch register
+        ;//
+        MACRO
+        M_BD_CMP  $ByteIndex, $BitIndex, $T1
+        
+        ;// Return flags set by (current positon)-($ByteIndex,$BitIndex)
+        ;// so GE means that we have reached the indicated position
+
+        ADD         $T1, $pBitStream, $BitCount, LSR #3
+        CMP         $T1, $ByteIndex
+        AND         $T1, $BitCount, #7
+        CMPEQ       $T1, $BitIndex        
+        MEND
+
+        
+        ;// Bitstream Decode finalise
+        ;//
+        ;// Writes back the bitstream state to the bitstream pointers
+        ;//
+        ;// Input Registers:
+        ;//
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;//
+        ;// Output Registers:
+        ;//
+        ;// $ppBitStream    - pointer to pointer to the next bitstream byte
+        ;// $pBitOffset     - pointer to the number of bits used in the current byte (0..7)
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } these register are corrupted
+        ;// $BitCount       / 
+        ;//
+        MACRO
+        M_BD_FINI  $ppBitStream, $pBitOffset
+        
+        ;// Advance pointer by the number of free bits in the buffer
+        ADD     $pBitStream, $pBitStream, $BitCount, LSR#3
+        AND     $BitCount, $BitCount, #7
+        
+        ;// Now move back 32 bits to reach the first usued bit
+        SUB     $pBitStream, $pBitStream, #4
+        
+        ;// Store out bitstream state
+        STR     $BitCount, [$pBitOffset]
+        STR     $pBitStream, [$ppBitStream]
+        MEND
+        
+        END
+        
\ No newline at end of file
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/api/armCOMM_Bitstream.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/api/armCOMM_Bitstream.h
new file mode 100644
index 0000000..4f9bc3b
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/api/armCOMM_Bitstream.h
@@ -0,0 +1,212 @@
+/**
+ * 
+ * File Name:  armCOMM_Bitstream.h
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * File: armCOMM_Bitstream.h
+ * Brief: Declares common API's/Data types used across the OpenMax Encoders/Decoders.
+ *
+ */
+
+#ifndef _armCodec_H_
+#define _armCodec_H_
+
+#include "omxtypes.h"
+
+typedef struct {
+    OMX_U8   codeLen;
+    OMX_U32	 codeWord;
+} ARM_VLC32;
+
+/* The above should be renamed as "ARM_VLC32" */
+
+/**
+ * Function: armLookAheadBits()
+ *
+ * Description:
+ * Get the next N bits from the bitstream without advancing the bitstream pointer
+ *
+ * Parameters:
+ * [in]     **ppBitStream
+ * [in]     *pOffset
+ * [in]     N=1...32
+ *
+ * Returns  Value
+ */
+
+OMX_U32 armLookAheadBits(const OMX_U8 **ppBitStream, OMX_INT *pOffset, OMX_INT N);
+
+/**
+ * Function: armGetBits()
+ *
+ * Description:
+ * Read N bits from the bitstream
+ *    
+ * Parameters:
+ * [in]     *ppBitStream
+ * [in]     *pOffset
+ * [in]     N=1..32
+ *
+ * [out]    *ppBitStream
+ * [out]    *pOffset
+ * Returns  Value
+ */
+
+OMX_U32 armGetBits(const OMX_U8 **ppBitStream, OMX_INT *pOffset, OMX_INT N);
+
+/**
+ * Function: armByteAlign()
+ *
+ * Description:
+ * Align the pointer *ppBitStream to the next byte boundary
+ *
+ * Parameters:
+ * [in]     *ppBitStream
+ * [in]     *pOffset
+ *
+ * [out]    *ppBitStream
+ * [out]    *pOffset
+ *
+ **/
+ 
+OMXVoid armByteAlign(const OMX_U8 **ppBitStream,OMX_INT *pOffset);
+
+/** 
+ * Function: armSkipBits()
+ *
+ * Description:
+ * Skip N bits from the value at *ppBitStream
+ *
+ * Parameters:
+ * [in]     *ppBitStream
+ * [in]     *pOffset
+ * [in]     N
+ *
+ * [out]    *ppBitStream
+ * [out]    *pOffset
+ *
+ **/
+
+OMXVoid armSkipBits(const OMX_U8 **ppBitStream,OMX_INT *pOffset,OMX_INT N);
+
+/***************************************
+ * Variable bit length Decode
+ ***************************************/
+
+/**
+ * Function: armUnPackVLC32()
+ *
+ * Description:
+ * Variable length decode of variable length symbol (max size 32 bits) read from
+ * the bit stream pointed by *ppBitStream at *pOffset by using the table
+ * pointed by pCodeBook
+ * 
+ * Parameters:
+ * [in]     **ppBitStream
+ * [in]     *pOffset
+ * [in]     pCodeBook
+ * 
+ * [out]    **ppBitStream
+ * [out]    *pOffset
+ *
+ * Returns : Code Book Index if successfull. 
+ *         : "ARM_NO_CODEBOOK_INDEX = 0xFFFF" if search fails.
+ **/
+
+#define ARM_NO_CODEBOOK_INDEX (OMX_U16)(0xFFFF)
+
+OMX_U16 armUnPackVLC32(
+    const OMX_U8 **ppBitStream,
+    OMX_INT *pOffset,
+    const ARM_VLC32 *pCodeBook
+);
+
+/***************************************
+ * Fixed bit length Encode
+ ***************************************/
+
+/**
+ * Function: armPackBits
+ *
+ * Description:
+ * Pack a VLC code word into the bitstream
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	ppBitStream		pointer to the pointer to the current byte 
+ *                      in the bit stream.
+ * [in]	pOffset	        pointer to the bit position in the byte 
+ *                      pointed by *ppBitStream. Valid within 0
+ *                      to 7.
+ * [in]	codeWord		Code word that need to be inserted in to the
+ *                          bitstream
+ * [in]	codeLength		Length of the code word valid range 1...32
+ *
+ * [out] ppBitStream	*ppBitStream is updated after the block is encoded,
+ *	                        so that it points to the current byte in the bit
+ *							stream buffer.
+ * [out] pBitOffset		*pBitOffset is updated so that it points to the
+ *							current bit position in the byte pointed by
+ *							*ppBitStream.
+ *
+ * Return Value:
+ * Standard OMX_RESULT result. See enumeration for possible result codes.
+ *
+ */
+ 
+OMXResult armPackBits (
+    OMX_U8  **ppBitStream, 
+    OMX_INT *pOffset,
+    OMX_U32 codeWord, 
+    OMX_INT codeLength 
+);
+ 
+/***************************************
+ * Variable bit length Encode
+ ***************************************/
+
+/**
+ * Function: armPackVLC32
+ *
+ * Description:
+ * Pack a VLC code word into the bitstream
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	ppBitStream		pointer to the pointer to the current byte 
+ *                      in the bit stream.
+ * [in]	pBitOffset	    pointer to the bit position in the byte 
+ *                      pointed by *ppBitStream. Valid within 0
+ *                      to 7.
+ * [in]	 code     		VLC code word that need to be inserted in to the
+ *                      bitstream
+ *
+ * [out] ppBitStream	*ppBitStream is updated after the block is encoded,
+ *	                    so that it points to the current byte in the bit
+ *						stream buffer.
+ * [out] pBitOffset		*pBitOffset is updated so that it points to the
+ *						current bit position in the byte pointed by
+ *						*ppBitStream.
+ *
+ * Return Value:
+ * Standard OMX_RESULT result. See enumeration for possible result codes.
+ *
+ */
+ 
+OMXResult armPackVLC32 (
+    OMX_U8 **ppBitStream, 
+    OMX_INT *pBitOffset,
+    ARM_VLC32 code 
+);
+
+#endif      /*_armCodec_H_*/
+
+/*End of File*/
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/api/armCOMM_IDCTTable.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/api/armCOMM_IDCTTable.h
new file mode 100644
index 0000000..d5db32f
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/api/armCOMM_IDCTTable.h
@@ -0,0 +1,40 @@
+/**
+ *
+ * 
+ * File Name:  armCOMM_IDCTTable.h
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * File         : armCOMM_IDCTTable.h
+ * Description  : Contains declarations of tables for IDCT calculation.
+ *
+ */
+  
+#ifndef _armCOMM_IDCTTable_H_
+#define _armCOMM_IDCTTable_H_
+
+#include "omxtypes.h"
+
+     /*  Table of s(u)*A(u)*A(v)/16 at Q15
+      *  s(u)=1.0 0 <= u <= 5
+      *  s(6)=2.0
+      *  s(7)=4.0
+      *  A(0) = 2*sqrt(2)
+      *  A(u) = 4*cos(u*pi/16)  for (u!=0)
+	  */
+extern const OMX_U16 armCOMM_IDCTPreScale [64];
+extern const OMX_U16 armCOMM_IDCTCoef [4];
+
+#endif /* _armCOMM_IDCTTable_H_ */
+
+
+/* End of File */
+
+
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/api/armCOMM_IDCT_s.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/api/armCOMM_IDCT_s.h
new file mode 100644
index 0000000..03f7137
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/api/armCOMM_IDCT_s.h
@@ -0,0 +1,1445 @@
+;//
+;// This confidential and proprietary software may be used only as
+;// authorised by a licensing agreement from ARM Limited
+;//   (C) COPYRIGHT 2004 ARM Limited
+;//       ALL RIGHTS RESERVED
+;// The entire notice above must be reproduced on all authorised
+;// copies and copies may only be made to the extent permitted
+;// by a licensing agreement from ARM Limited.
+;//
+;// IDCT_s.s
+;//
+;// Inverse DCT module
+;//
+;// 
+;// ALGORITHM DESCRIPTION
+;//
+;// The 8x8 2D IDCT is performed by calculating a 1D IDCT for each
+;// column and then a 1D IDCT for each row.
+;//
+;// The 8-point 1D IDCT is defined by
+;//   f(x) = (C(0)*T(0)*c(0,x) + ... + C(7)*T(7)*c(7,x))/2
+;//
+;//   C(u) = 1/sqrt(2) if u=0 or 1 if u!=0
+;//   c(u,x) = cos( (2x+1)*u*pi/16 )
+;//
+;// We compute the 8-point 1D IDCT using the reverse of
+;// the Arai-Agui-Nakajima flow graph which we split into
+;// 5 stages named in reverse order to identify with the
+;// forward DCT. Direct inversion of the forward formulae
+;// in file FDCT_s.s gives:
+;//
+;// IStage 5:   j(u) = T(u)*A(u)  [ A(u)=4*C(u)*c(u,0) ]
+;//             [ A(0) = 2*sqrt(2)
+;//               A(u) = 4*cos(u*pi/16)  for (u!=0) ]
+;//
+;// IStage 4:   i0 = j0             i1 = j4
+;//             i3 = (j2+j6)/2      i2 = (j2-j6)/2
+;//             i7 = (j5+j3)/2      i4 = (j5-j3)/2
+;//             i5 = (j1+j7)/2      i6 = (j1-j7)/2
+;//
+;// IStage 3:   h0 = (i0+i1)/2      h1 = (i0-i1)/2
+;//             h2 = (i2*sqrt2)-i3  h3 = i3
+;//             h4 =  cos(pi/8)*i4 + sin(pi/8)*i6
+;//             h6 = -sin(pi/8)*i4 + cos(pi/8)*i6
+;//             [ The above two lines rotate by -(pi/8) ]
+;//             h5 = (i5-i7)/sqrt2  h7 = (i5+i7)/2 
+;//             
+;// IStage 2:   g0 = (h0+h3)/2      g3 = (h0-h3)/2
+;//             g1 = (h1+h2)/2      g2 = (h1-h2)/2
+;//             g7 = h7             g6 = h6 - h7
+;//             g5 = h5 - g6        g4 = h4 - g5
+;//
+;// IStage 1:   f0 = (g0+g7)/2      f7 = (g0-g7)/2
+;//             f1 = (g1+g6)/2      f6 = (g1-g6)/2
+;//             f2 = (g2+g5)/2      f5 = (g2-g5)/2
+;//             f3 = (g3+g4)/2      f4 = (g3-g4)/2
+;//
+;// Note that most coefficients are halved 3 times during the
+;// above calculation. We can rescale the algorithm dividing
+;// the input by 8 to remove the halvings.
+;//
+;// IStage 5:   j(u) = T(u)*A(u)/8
+;//
+;// IStage 4:   i0 = j0             i1 = j4
+;//             i3 = j2 + j6        i2 = j2 - j6
+;//             i7 = j5 + j3        i4 = j5 - j3
+;//             i5 = j1 + j7        i6 = j1 - j7
+;//
+;// IStage 3:   h0 = i0 + i1        h1 = i0 - i1
+;//             h2 = (i2*sqrt2)-i3  h3 = i3
+;//             h4 = 2*( cos(pi/8)*i4 + sin(pi/8)*i6)
+;//             h6 = 2*(-sin(pi/8)*i4 + cos(pi/8)*i6)
+;//             h5 = (i5-i7)*sqrt2  h7 = i5 + i7 
+;//             
+;// IStage 2:   g0 = h0 + h3        g3 = h0 - h3
+;//             g1 = h1 + h2        g2 = h1 - h2
+;//             g7 = h7             g6 = h6 - h7
+;//             g5 = h5 - g6        g4 = h4 - g5
+;//
+;// IStage 1:   f0 = g0 + g7        f7 = g0 - g7
+;//             f1 = g1 + g6        f6 = g1 - g6
+;//             f2 = g2 + g5        f5 = g2 - g5
+;//             f3 = g3 + g4        f4 = g3 - g4
+;//
+;// Note:
+;// 1. The scaling by A(u)/8 can often be combined with inverse
+;//    quantization. The column and row scalings can be combined.
+;// 2. The flowgraph in the AAN paper has h4,g6 negated compared
+;//    to the above code but is otherwise identical.
+;// 3. The rotation by -pi/8 can be peformed using three multiplies
+;//    Eg  c*i4+s*i6 = (i6-i4)*s + (c+s)*i4
+;//       -s*i4+c*i6 = (i6-i4)*s + (c-s)*i6
+;// 4. If |T(u)|<=1 then from the IDCT definition,
+;//    |f(x)| <= ((1/sqrt2) + |c(1,x)| + .. + |c(7,x)|)/2
+;//            = ((1/sqrt2) + cos(pi/16) + ... + cos(7*pi/16))/2
+;//            = ((1/sqrt2) + (cot(pi/32)-1)/2)/2
+;//            = (1 + cos(pi/16) + cos(2pi/16) + cos(3pi/16))/sqrt(2)
+;//            = (approx)2.64
+;//    So the max gain of the 2D IDCT is ~x7.0 = 3 bits.
+;//    The table below shows input patterns generating the maximum
+;//    value of |f(u)| for input in the range |T(x)|<=1. M=-1, P=+1
+;//    InputPattern      Max |f(x)|
+;//      PPPPPPPP        |f0| =  2.64
+;//      PPPMMMMM        |f1| =  2.64
+;//      PPMMMPPP        |f2| =  2.64
+;//      PPMMPPMM        |f3| =  2.64
+;//      PMMPPMMP        |f4| =  2.64
+;//      PMMPMMPM        |f5| =  2.64
+;//      PMPPMPMP        |f6| =  2.64
+;//      PMPMPMPM        |f7| =  2.64
+;//   Note that this input pattern is the transpose of the
+;//   corresponding max input patter for the FDCT.
+
+;// Arguments
+
+pSrc    RN 0    ;// source data buffer
+Stride  RN 1    ;// destination stride in bytes
+pDest   RN 2    ;// destination data buffer
+pScale  RN 3    ;// pointer to scaling table
+
+
+        ;// DCT Inverse Macro
+        ;// The DCT code should be parametrized according
+        ;// to the following inputs:
+        ;// $outsize = "u8"  :  8-bit unsigned data saturated (0 to +255)
+        ;//            "s9"  : 16-bit signed data saturated to 9-bit (-256 to +255)
+        ;//            "s16" : 16-bit signed data not saturated (max size ~+/-14273)
+        ;// $inscale = "s16" : signed 16-bit aan-scale table, Q15 format, with 4 byte alignment
+        ;//            "s32" : signed 32-bit aan-scale table, Q23 format, with 4 byte alignment
+        ;//
+        ;// Inputs:
+        ;// pSrc   = r0 = Pointer to input data
+        ;//               Range is -256 to +255 (9-bit)
+        ;// Stride = r1 = Stride between input lines
+        ;// pDest  = r2 = Pointer to output data
+        ;// pScale = r3 = Pointer to aan-scale table in the format defined by $inscale
+        
+        
+        
+        MACRO
+        M_IDCT  $outsize, $inscale, $stride
+        LCLA    SHIFT
+        
+        
+        IF ARM1136JS
+        
+;// REGISTER ALLOCATION
+;// This is hard since we have 8 values, 9 free registers and each
+;// butterfly requires a temporary register. We also want to 
+;// maintain register order so we can use LDM/STM. The table below
+;// summarises the register allocation that meets all these criteria.
+;// a=1stcol, b=2ndcol, f,g,h,i are dataflow points described above.
+;//
+;// r1  a01     g0  h0
+;// r4  b01 f0  g1  h1  i0
+;// r5  a23 f1  g2      i1
+;// r6  b23 f2  g3  h2  i2
+;// r7  a45 f3      h3  i3
+;// r8  b45 f4  g4  h4  i4
+;// r9  a67 f5  g5  h5  i5
+;// r10 b67 f6  g6  h6  i6
+;// r11     f7  g7  h7  i7
+;//
+ra01    RN 1
+rb01    RN 4
+ra23    RN 5
+rb23    RN 6
+ra45    RN 7
+rb45    RN 8
+ra67    RN 9
+rb67    RN 10
+rtmp    RN 11
+csPiBy8 RN 12   ;// [ (Sin(pi/8)@Q15), (Cos(pi/8)@Q15) ]
+LoopRR2 RN 14   ;// [ LoopNumber<<13 , (1/Sqrt(2))@Q15 ]
+;// Transpose allocation
+xft     RN ra01
+xf0     RN rb01
+xf1     RN ra23
+xf2     RN rb23
+xf3     RN ra45
+xf4     RN rb45
+xf5     RN ra67
+xf6     RN rb67
+xf7     RN rtmp
+;// IStage 1 allocation
+xg0     RN xft
+xg1     RN xf0
+xg2     RN xf1
+xg3     RN xf2
+xgt     RN xf3
+xg4     RN xf4
+xg5     RN xf5
+xg6     RN xf6
+xg7     RN xf7
+;// IStage 2 allocation
+xh0     RN xg0
+xh1     RN xg1
+xht     RN xg2
+xh2     RN xg3
+xh3     RN xgt
+xh4     RN xg4
+xh5     RN xg5
+xh6     RN xg6
+xh7     RN xg7
+;// IStage 3,4 allocation
+xit     RN xh0
+xi0     RN xh1
+xi1     RN xht
+xi2     RN xh2
+xi3     RN xh3
+xi4     RN xh4
+xi5     RN xh5
+xi6     RN xh6
+xi7     RN xh7
+        
+        M_STR   pDest,  ppDest
+        IF "$stride"="s"
+            M_STR   Stride, pStride
+        ENDIF
+        M_ADR   pDest,  pBlk
+        LDR     csPiBy8, =0x30fc7642
+        LDR     LoopRR2, =0x00005a82
+  
+v6_idct_col$_F
+        ;// Load even values
+        LDR     xi4, [pSrc], #4  ;// j0
+        LDR     xi5, [pSrc, #4*16-4]  ;// j4
+        LDR     xi6, [pSrc, #2*16-4]  ;// j2
+        LDR     xi7, [pSrc, #6*16-4]  ;// j6
+        
+        ;// Scale Even Values
+        IF "$inscale"="s16" ;// 16x16 mul
+SHIFT       SETA    12
+            LDR     xi0, [pScale], #4
+            LDR     xi1, [pScale, #4*16-4]        
+            LDR     xi2, [pScale, #2*16-4]
+            MOV     xit, #1<<(SHIFT-1)
+            SMLABB  xi3, xi0, xi4, xit
+            SMLATT  xi4, xi0, xi4, xit
+            SMLABB  xi0, xi1, xi5, xit
+            SMLATT  xi5, xi1, xi5, xit
+            MOV     xi3, xi3, ASR #SHIFT
+            PKHBT   xi4, xi3, xi4, LSL #(16-SHIFT)
+            LDR     xi3, [pScale, #6*16-4]
+            SMLABB  xi1, xi2, xi6, xit
+            SMLATT  xi6, xi2, xi6, xit
+            MOV     xi0, xi0, ASR #SHIFT
+            PKHBT   xi5, xi0, xi5, LSL #(16-SHIFT)
+            SMLABB  xi2, xi3, xi7, xit
+            SMLATT  xi7, xi3, xi7, xit
+            MOV     xi1, xi1, ASR #SHIFT
+            PKHBT   xi6, xi1, xi6, LSL #(16-SHIFT)
+            MOV     xi2, xi2, ASR #SHIFT
+            PKHBT   xi7, xi2, xi7, LSL #(16-SHIFT)
+        ENDIF
+        IF "$inscale"="s32" ;// 32x16 mul
+SHIFT       SETA    (12+8-16)
+            MOV     xit, #1<<(SHIFT-1)
+            LDR     xi0, [pScale], #8
+            LDR     xi1, [pScale, #0*32+4-8]
+            LDR     xi2, [pScale, #4*32-8]
+            LDR     xi3, [pScale, #4*32+4-8]            
+            SMLAWB  xi0, xi0, xi4, xit
+            SMLAWT  xi1, xi1, xi4, xit
+            SMLAWB  xi2, xi2, xi5, xit
+            SMLAWT  xi3, xi3, xi5, xit            
+            MOV     xi0, xi0, ASR #SHIFT
+            PKHBT   xi4, xi0, xi1, LSL #(16-SHIFT)
+            MOV     xi2, xi2, ASR #SHIFT            
+            PKHBT   xi5, xi2, xi3, LSL #(16-SHIFT)
+            LDR     xi0, [pScale, #2*32-8]
+            LDR     xi1, [pScale, #2*32+4-8]
+            LDR     xi2, [pScale, #6*32-8]
+            LDR     xi3, [pScale, #6*32+4-8]            
+            SMLAWB  xi0, xi0, xi6, xit
+            SMLAWT  xi1, xi1, xi6, xit
+            SMLAWB  xi2, xi2, xi7, xit
+            SMLAWT  xi3, xi3, xi7, xit            
+            MOV     xi0, xi0, ASR #SHIFT
+            PKHBT   xi6, xi0, xi1, LSL #(16-SHIFT)
+            MOV     xi2, xi2, ASR #SHIFT            
+            PKHBT   xi7, xi2, xi3, LSL #(16-SHIFT)
+        ENDIF
+                
+        ;// Load odd values
+        LDR     xi0, [pSrc, #1*16-4]      ;// j1
+        LDR     xi1, [pSrc, #7*16-4]      ;// j7
+        LDR     xi2, [pSrc, #5*16-4]      ;// j5
+        LDR     xi3, [pSrc, #3*16-4]      ;// j3
+        
+        IF  {TRUE}
+            ;// shortcut if odd values 0
+            TEQ     xi0, #0
+            TEQEQ   xi1, #0
+            TEQEQ   xi2, #0
+            TEQEQ   xi3, #0
+            BEQ     v6OddZero$_F
+        ENDIF
+        
+        ;// Store scaled even values
+        STMIA   pDest, {xi4, xi5, xi6, xi7}
+        
+        ;// Scale odd values
+        IF "$inscale"="s16"
+            ;// Perform AAN Scale
+            LDR     xi4, [pScale, #1*16-4]
+            LDR     xi5, [pScale, #7*16-4]        
+            LDR     xi6, [pScale, #5*16-4]
+            SMLABB  xi7, xi0, xi4, xit
+            SMLATT  xi0, xi0, xi4, xit
+            SMLABB  xi4, xi1, xi5, xit
+            SMLATT  xi1, xi1, xi5, xit
+            MOV     xi7, xi7, ASR #SHIFT
+            PKHBT   xi0, xi7, xi0, LSL #(16-SHIFT)
+            LDR     xi7, [pScale, #3*16-4]
+            SMLABB  xi5, xi2, xi6, xit
+            SMLATT  xi2, xi2, xi6, xit
+            MOV     xi4, xi4, ASR #SHIFT
+            PKHBT   xi1, xi4, xi1, LSL #(16-SHIFT)
+            SMLABB  xi6, xi3, xi7, xit
+            SMLATT  xi3, xi3, xi7, xit
+            MOV     xi5, xi5, ASR #SHIFT
+            PKHBT   xi2, xi5, xi2, LSL #(16-SHIFT)
+            MOV     xi6, xi6, ASR #SHIFT
+            PKHBT   xi3, xi6, xi3, LSL #(16-SHIFT)
+        ENDIF
+        IF "$inscale"="s32" ;// 32x16 mul
+            LDR     xi4, [pScale, #1*32-8]
+            LDR     xi5, [pScale, #1*32+4-8]
+            LDR     xi6, [pScale, #7*32-8]
+            LDR     xi7, [pScale, #7*32+4-8]            
+            SMLAWB  xi4, xi4, xi0, xit
+            SMLAWT  xi5, xi5, xi0, xit
+            SMLAWB  xi6, xi6, xi1, xit
+            SMLAWT  xi7, xi7, xi1, xit            
+            MOV     xi4, xi4, ASR #SHIFT
+            PKHBT   xi0, xi4, xi5, LSL #(16-SHIFT)
+            MOV     xi6, xi6, ASR #SHIFT            
+            PKHBT   xi1, xi6, xi7, LSL #(16-SHIFT)
+            LDR     xi4, [pScale, #5*32-8]
+            LDR     xi5, [pScale, #5*32+4-8]
+            LDR     xi6, [pScale, #3*32-8]
+            LDR     xi7, [pScale, #3*32+4-8]            
+            SMLAWB  xi4, xi4, xi2, xit
+            SMLAWT  xi5, xi5, xi2, xit
+            SMLAWB  xi6, xi6, xi3, xit
+            SMLAWT  xi7, xi7, xi3, xit            
+            MOV     xi4, xi4, ASR #SHIFT
+            PKHBT   xi2, xi4, xi5, LSL #(16-SHIFT)
+            MOV     xi6, xi6, ASR #SHIFT            
+            PKHBT   xi3, xi6, xi7, LSL #(16-SHIFT)
+        ENDIF
+        
+        SHADD16 xi5, xi0, xi1           ;// (j1+j7)/2
+        SSUB16  xi6, xi0, xi1           ;// j1-j7
+        SHADD16 xi7, xi2, xi3           ;// (j5+j3)/2
+        SSUB16  xi4, xi2, xi3           ;// j5-j3
+        
+        SSUB16  xi3, xi5, xi7           ;// (i5-i7)/2
+        
+        PKHBT   xi0, xi6, xi4, LSL#16   ;// [i4,i6] row a
+        PKHTB   xi1, xi4, xi6, ASR#16   ;// [i4,i6] row b
+        
+        SMUADX  xi2, xi0, csPiBy8       ;// rowa by [c,s]
+        SMUADX  xi4, xi1, csPiBy8       ;// rowb by [c,s]
+        SMUSD   xi0, xi0, csPiBy8       ;// rowa by [-s,c]   
+        SMUSD   xi6, xi1, csPiBy8       ;// rowb by [-s,c]
+                
+        SMULBB  xi1, xi3, LoopRR2
+        SMULTB  xi3, xi3, LoopRR2
+                
+        PKHTB   xh4, xi4, xi2, ASR#16   ;// h4/4
+        PKHTB   xh6, xi6, xi0, ASR#16   ;// h6/4
+        SHADD16 xh7, xi5, xi7           ;// (i5+i7)/4
+                
+        ;// xi0,xi1,xi2,xi3 now free
+        ;// IStage 4,3, rows 2to3 x1/2
+        
+        MOV     xi3, xi3, LSL #1
+        PKHTB   xh5, xi3, xi1, ASR#15   ;// h5/4
+        LDRD    xi0, [pDest, #8]        ;// j2,j6 scaled
+                
+        ;// IStage 2, rows4to7
+        SSUB16  xg6, xh6, xh7
+        SSUB16  xg5, xh5, xg6        
+        SSUB16  xg4, xh4, xg5
+                
+        SSUB16  xi2, xi0, xi1           ;// (j2-j6)
+        SHADD16 xi3, xi0, xi1           ;// (j2+j6)/2
+        
+        SMULBB  xi0, xi2, LoopRR2
+        SMULTB  xi2, xi2, LoopRR2
+        
+        MOV     xi2, xi2, LSL #1
+        PKHTB   xh2, xi2, xi0, ASR#15   ;// i2*sqrt(2)/4
+        
+        ;// xi0, xi1 now free
+        ;// IStage 4,3 rows 0to1 x 1/2
+        LDRD    xi0, [pDest]            ;// j0, j4 scaled
+        SSUB16  xh2, xh2, xi3
+        ADDS    LoopRR2, LoopRR2, #2<<29    ;// done two rows
+        
+        SHADD16 xh0, xi0, xi1
+        SHSUB16 xh1, xi0, xi1                
+        
+        ;// IStage 2 rows 0to3 x 1/2
+        SHSUB16 xg2, xh1, xh2
+        SHADD16 xg1, xh1, xh2
+        SHSUB16 xg3, xh0, xh3
+        SHADD16 xg0, xh0, xh3
+        
+        ;// IStage 1 all rows
+        SADD16  xf3, xg3, xg4
+        SSUB16  xf4, xg3, xg4
+        SADD16  xf2, xg2, xg5
+        SSUB16  xf5, xg2, xg5
+        SADD16  xf1, xg1, xg6
+        SSUB16  xf6, xg1, xg6
+        SADD16  xf0, xg0, xg7
+        SSUB16  xf7, xg0, xg7
+        
+        ;// Transpose, store and loop
+        PKHBT   ra01, xf0, xf1, LSL #16
+        PKHTB   rb01, xf1, xf0, ASR #16
+        
+        PKHBT   ra23, xf2, xf3, LSL #16
+        PKHTB   rb23, xf3, xf2, ASR #16
+        
+        PKHBT   ra45, xf4, xf5, LSL #16
+        PKHTB   rb45, xf5, xf4, ASR #16
+        
+        PKHBT   ra67, xf6, xf7, LSL #16
+        STMIA   pDest!, {ra01, ra23, ra45, ra67}      
+        PKHTB   rb67, xf7, xf6, ASR #16
+        STMIA   pDest!, {rb01, rb23, rb45, rb67}                              
+        BCC     v6_idct_col$_F
+        
+        SUB     pSrc, pDest, #(64*2)
+        M_LDR   pDest, ppDest
+        IF "$stride"="s"
+            M_LDR   pScale, pStride 
+        ENDIF
+        B       v6_idct_row$_F
+        
+v6OddZero$_F
+        SSUB16  xi2, xi6, xi7           ;// (j2-j6)
+        SHADD16 xi3, xi6, xi7           ;// (j2+j6)/2
+        
+        SMULBB  xi0, xi2, LoopRR2
+        SMULTB  xi2, xi2, LoopRR2
+        
+        MOV     xi2, xi2, LSL #1
+        PKHTB   xh2, xi2, xi0, ASR#15   ;// i2*sqrt(2)/4
+        SSUB16  xh2, xh2, xi3
+        
+        ;// xi0, xi1 now free
+        ;// IStage 4,3 rows 0to1 x 1/2
+        
+        SHADD16 xh0, xi4, xi5
+        SHSUB16 xh1, xi4, xi5                
+        
+        ;// IStage 2 rows 0to3 x 1/2
+        SHSUB16 xg2, xh1, xh2
+        SHADD16 xg1, xh1, xh2
+        SHSUB16 xg3, xh0, xh3
+        SHADD16 xg0, xh0, xh3
+               
+        ;// IStage 1 all rows
+        MOV  xf3, xg3
+        MOV  xf4, xg3
+        MOV  xf2, xg2
+        MOV  xf5, xg2
+        MOV  xf1, xg1
+        MOV  xf6, xg1
+        MOV  xf0, xg0
+        MOV  xf7, xg0
+        
+        ;// Transpose
+        PKHBT   ra01, xf0, xf1, LSL #16
+        PKHTB   rb01, xf1, xf0, ASR #16
+        
+        PKHBT   ra23, xf2, xf3, LSL #16
+        PKHTB   rb23, xf3, xf2, ASR #16
+        
+        PKHBT   ra45, xf4, xf5, LSL #16
+        PKHTB   rb45, xf5, xf4, ASR #16
+        
+        PKHBT   ra67, xf6, xf7, LSL #16
+        PKHTB   rb67, xf7, xf6, ASR #16
+                
+        STMIA   pDest!, {ra01, ra23, ra45, ra67}      
+        ADDS    LoopRR2, LoopRR2, #2<<29    ;// done two rows
+        STMIA   pDest!, {rb01, rb23, rb45, rb67}      
+        
+        BCC     v6_idct_col$_F
+        SUB     pSrc, pDest, #(64*2)
+        M_LDR   pDest, ppDest
+        IF "$stride"="s"
+            M_LDR   pScale, pStride 
+        ENDIF
+               
+        
+v6_idct_row$_F
+        ;// IStage 4,3, rows4to7 x1/4
+        LDR     xit, =0x00010001        ;// rounding constant
+        LDR     xi0, [pSrc, #1*16]      ;// j1
+        LDR     xi1, [pSrc, #7*16]      ;// 4*j7
+        LDR     xi2, [pSrc, #5*16]      ;// j5
+        LDR     xi3, [pSrc, #3*16]      ;// j3
+        
+        SHADD16 xi1, xi1, xit           ;// 2*j7
+        SHADD16 xi1, xi1, xit           ;// j7                
+        
+        SHADD16 xi5, xi0, xi1           ;// (j1+j7)/2
+        SSUB16  xi6, xi0, xi1           ;// j1-j7
+        SHADD16 xi7, xi2, xi3           ;// (j5+j3)/2
+        SSUB16  xi4, xi2, xi3           ;// j5-j3
+        
+        SSUB16  xi3, xi5, xi7           ;// (i5-i7)/2
+        
+        PKHBT   xi0, xi6, xi4, LSL#16   ;// [i4,i6] row a
+        PKHTB   xi1, xi4, xi6, ASR#16   ;// [i4,i6] row b
+        
+        SMUADX  xi2, xi0, csPiBy8       ;// rowa by [c,s]
+        SMUADX  xi4, xi1, csPiBy8       ;// rowb by [c,s]
+        SMUSD   xi0, xi0, csPiBy8       ;// rowa by [-s,c]   
+        SMUSD   xi6, xi1, csPiBy8       ;// rowb by [-s,c]
+                
+        SMULBB  xi1, xi3, LoopRR2
+        SMULTB  xi3, xi3, LoopRR2
+                
+        PKHTB   xh4, xi4, xi2, ASR#16   ;// h4/4
+        PKHTB   xh6, xi6, xi0, ASR#16   ;// h6/4
+        SHADD16 xh7, xi5, xi7           ;// (i5+i7)/4
+        
+        MOV     xi3, xi3, LSL #1
+        PKHTB   xh5, xi3, xi1, ASR#15   ;// h5/4
+               
+        ;// xi0,xi1,xi2,xi3 now free
+        ;// IStage 4,3, rows 2to3 x1/2
+        
+        LDR     xi0, [pSrc, #2*16]      ;// j2
+        LDR     xi1, [pSrc, #6*16]      ;// 2*j6
+        
+        ;// IStage 2, rows4to7
+        SSUB16  xg6, xh6, xh7
+        SSUB16  xg5, xh5, xg6
+        SSUB16  xg4, xh4, xg5
+        
+        SHADD16 xi1, xi1, xit           ;// j6
+        SSUB16  xi2, xi0, xi1           ;// (j2-j6)        
+        SHADD16 xi3, xi0, xi1           ;// (j2+j6)/2
+        
+        SMULBB  xi0, xi2, LoopRR2
+        SMULTB  xi2, xi2, LoopRR2
+        
+        MOV     xi2, xi2, LSL #1
+        
+        PKHTB   xh2, xi2, xi0, ASR#15   ;// i2*sqrt(2)/4
+        
+        ;// xi0, xi1 now free
+        ;// IStage 4,3 rows 0to1 x 1/2
+        LDR     xi1, [pSrc, #4*16]      ;// j4
+        LDR     xi0, [pSrc], #4         ;// j0
+
+        SSUB16  xh2, xh2, xi3
+        ADDS    LoopRR2, LoopRR2, #2<<29    ;// done two rows
+        
+        ADD     xi0, xi0, xit, LSL #2   ;// ensure correct round
+        SHADD16 xh0, xi0, xi1           ;// of DC result
+        SHSUB16 xh1, xi0, xi1
+                
+        ;// IStage 2 rows 0to3 x 1/2
+        SHSUB16 xg2, xh1, xh2
+        SHADD16 xg1, xh1, xh2
+        SHSUB16 xg3, xh0, xh3
+        SHADD16 xg0, xh0, xh3
+        
+        ;// IStage 1 all rows
+        SHADD16 xf3, xg3, xg4
+        SHSUB16 xf4, xg3, xg4
+        SHADD16 xf2, xg2, xg5
+        SHSUB16 xf5, xg2, xg5
+        SHADD16 xf1, xg1, xg6
+        SHSUB16 xf6, xg1, xg6
+        SHADD16 xf0, xg0, xg7
+        SHSUB16 xf7, xg0, xg7
+        
+        ;// Saturate
+        IF ("$outsize"="u8")
+            USAT16  xf0, #8, xf0
+            USAT16  xf1, #8, xf1
+            USAT16  xf2, #8, xf2
+            USAT16  xf3, #8, xf3
+            USAT16  xf4, #8, xf4
+            USAT16  xf5, #8, xf5
+            USAT16  xf6, #8, xf6
+            USAT16  xf7, #8, xf7        
+        ENDIF
+        IF ("$outsize"="s9")
+            SSAT16  xf0, #9, xf0
+            SSAT16  xf1, #9, xf1
+            SSAT16  xf2, #9, xf2
+            SSAT16  xf3, #9, xf3
+            SSAT16  xf4, #9, xf4
+            SSAT16  xf5, #9, xf5
+            SSAT16  xf6, #9, xf6
+            SSAT16  xf7, #9, xf7        
+        ENDIF
+        
+        ;// Transpose to Row, Pack and store
+        IF ("$outsize"="u8")
+            ORR     xf0, xf0, xf1, LSL #8 ;// [ b1 b0 a1 a0 ]
+            ORR     xf2, xf2, xf3, LSL #8 ;// [ b3 b2 a3 a2 ]
+            ORR     xf4, xf4, xf5, LSL #8 ;// [ b5 b4 a5 a4 ]
+            ORR     xf6, xf6, xf7, LSL #8 ;// [ b7 b6 a7 a6 ]
+            PKHBT   ra01, xf0, xf2, LSL #16
+            PKHTB   rb01, xf2, xf0, ASR #16
+            PKHBT   ra23, xf4, xf6, LSL #16
+            PKHTB   rb23, xf6, xf4, ASR #16
+            STMIA   pDest, {ra01, ra23}
+            IF "$stride"="s"
+                ADD     pDest, pDest, pScale
+                STMIA   pDest, {rb01, rb23}
+                ADD     pDest, pDest, pScale
+            ELSE                
+                ADD     pDest, pDest, #($stride)
+                STMIA   pDest, {rb01, rb23}
+                ADD     pDest, pDest, #($stride)
+            ENDIF
+        ENDIF
+        IF ("$outsize"="s9"):LOR:("$outsize"="s16")        
+            PKHBT   ra01, xf0, xf1, LSL #16
+            PKHTB   rb01, xf1, xf0, ASR #16
+        
+            PKHBT   ra23, xf2, xf3, LSL #16
+            PKHTB   rb23, xf3, xf2, ASR #16
+            
+            PKHBT   ra45, xf4, xf5, LSL #16
+            PKHTB   rb45, xf5, xf4, ASR #16
+            
+            PKHBT   ra67, xf6, xf7, LSL #16
+            PKHTB   rb67, xf7, xf6, ASR #16
+            
+            STMIA   pDest, {ra01, ra23, ra45, ra67}      
+            IF "$stride"="s"
+                ADD     pDest, pDest, pScale
+                STMIA   pDest, {rb01, rb23, rb45, rb67}      
+                ADD     pDest, pDest, pScale
+            ELSE                
+                ADD     pDest, pDest, #($stride)
+                STMIA   pDest, {rb01, rb23, rb45, rb67}      
+                ADD     pDest, pDest, #($stride)
+            ENDIF
+        ENDIF
+        
+        BCC     v6_idct_row$_F
+        ENDIF ;// ARM1136JS
+
+
+        IF CortexA8
+        
+Src0            EQU  7              
+Src1            EQU  8              
+Src2            EQU  9              
+Src3            EQU  10              
+Src4            EQU  11              
+Src5            EQU  12              
+Src6            EQU  13
+Src7            EQU  14
+Tmp             EQU  15
+
+qXj0            QN Src0.S16 
+qXj1            QN Src1.S16
+qXj2            QN Src2.S16
+qXj3            QN Src3.S16
+qXj4            QN Src4.S16
+qXj5            QN Src5.S16
+qXj6            QN Src6.S16
+qXj7            QN Src7.S16
+qXjt            QN Tmp.S16
+
+dXj0lo          DN (Src0*2).S16
+dXj0hi          DN (Src0*2+1).S16
+dXj1lo          DN (Src1*2).S16
+dXj1hi          DN (Src1*2+1).S16
+dXj2lo          DN (Src2*2).S16
+dXj2hi          DN (Src2*2+1).S16
+dXj3lo          DN (Src3*2).S16
+dXj3hi          DN (Src3*2+1).S16
+dXj4lo          DN (Src4*2).S16
+dXj4hi          DN (Src4*2+1).S16
+dXj5lo          DN (Src5*2).S16
+dXj5hi          DN (Src5*2+1).S16
+dXj6lo          DN (Src6*2).S16
+dXj6hi          DN (Src6*2+1).S16
+dXj7lo          DN (Src7*2).S16
+dXj7hi          DN (Src7*2+1).S16
+dXjtlo          DN (Tmp*2).S16
+dXjthi          DN (Tmp*2+1).S16
+
+qXi0            QN qXj0
+qXi1            QN qXj4
+qXi2            QN qXj2
+qXi3            QN qXj7
+qXi4            QN qXj5
+qXi5            QN qXjt
+qXi6            QN qXj1
+qXi7            QN qXj6
+qXit            QN qXj3
+
+dXi0lo          DN dXj0lo
+dXi0hi          DN dXj0hi
+dXi1lo          DN dXj4lo
+dXi1hi          DN dXj4hi
+dXi2lo          DN dXj2lo
+dXi2hi          DN dXj2hi
+dXi3lo          DN dXj7lo
+dXi3hi          DN dXj7hi
+dXi4lo          DN dXj5lo
+dXi4hi          DN dXj5hi
+dXi5lo          DN dXjtlo
+dXi5hi          DN dXjthi
+dXi6lo          DN dXj1lo
+dXi6hi          DN dXj1hi
+dXi7lo          DN dXj6lo
+dXi7hi          DN dXj6hi
+dXitlo          DN dXj3lo
+dXithi          DN dXj3hi
+
+qXh0            QN qXit
+qXh1            QN qXi0
+qXh2            QN qXi2
+qXh3            QN qXi3
+qXh4            QN qXi7
+qXh5            QN qXi5
+qXh6            QN qXi4
+qXh7            QN qXi1
+qXht            QN qXi6
+
+dXh0lo          DN dXitlo
+dXh0hi          DN dXithi
+dXh1lo          DN dXi0lo
+dXh1hi          DN dXi0hi
+dXh2lo          DN dXi2lo
+dXh2hi          DN dXi2hi
+dXh3lo          DN dXi3lo
+dXh3hi          DN dXi3hi
+dXh4lo          DN dXi7lo
+dXh4hi          DN dXi7hi
+dXh5lo          DN dXi5lo
+dXh5hi          DN dXi5hi
+dXh6lo          DN dXi4lo
+dXh6hi          DN dXi4hi
+dXh7lo          DN dXi1lo
+dXh7hi          DN dXi1hi
+dXhtlo          DN dXi6lo
+dXhthi          DN dXi6hi
+
+qXg0            QN qXh2
+qXg1            QN qXht
+qXg2            QN qXh1
+qXg3            QN qXh0
+qXg4            QN qXh4
+qXg5            QN qXh5
+qXg6            QN qXh6
+qXg7            QN qXh7
+qXgt            QN qXh3
+
+qXf0            QN qXg6
+qXf1            QN qXg5
+qXf2            QN qXg4
+qXf3            QN qXgt
+qXf4            QN qXg3
+qXf5            QN qXg2
+qXf6            QN qXg1
+qXf7            QN qXg0
+qXft            QN qXg7
+
+
+qXt0            QN 1.S32
+qXt1            QN 2.S32
+qT0lo           QN 1.S32         
+qT0hi           QN 2.S32         
+qT1lo           QN 3.S32         
+qT1hi           QN 4.S32         
+qScalelo        QN 5.S32        ;// used to read post scale values
+qScalehi        QN 6.S32
+qTemp0          QN 5.S32         
+qTemp1          QN 6.S32    
+
+
+Scale1          EQU 6
+Scale2          EQU 15
+qScale1         QN Scale1.S16     
+qScale2         QN Scale2.S16     
+dScale1lo       DN (Scale1*2).S16     
+dScale1hi       DN (Scale1*2+1).S16
+dScale2lo       DN (Scale2*2).S16     
+dScale2hi       DN (Scale2*2+1).S16
+
+dCoefs          DN 0.S16        ;// Scale coefficients in format {[0] [C] [S] [InvSqrt2]}
+InvSqrt2        DN dCoefs[0]    ;// 1/sqrt(2) in Q15
+S               DN dCoefs[1]    ;// Sin(PI/8) in Q15
+C               DN dCoefs[2]    ;// Cos(PI/8) in Q15
+
+pTemp           RN 12
+
+                
+        IMPORT  armCOMM_IDCTCoef
+                    
+        VLD1        {qXj0,qXj1}, [pSrc @64]!
+        VLD1        {qXj2,qXj3}, [pSrc @64]!
+        VLD1        {qXj4,qXj5}, [pSrc @64]!
+        VLD1        {qXj6,qXj7}, [pSrc @64]!
+        
+        ;// Load PreScale and multiply with Src
+        ;// IStage 4
+        
+        IF "$inscale"="s16"                         ;// 16X16 Mul
+            M_IDCT_PRESCALE16
+        ENDIF
+        
+        IF "$inscale"="s32"                         ;// 32X32 ,ul
+            M_IDCT_PRESCALE32
+        ENDIF
+
+        ;// IStage 3
+        VQRDMULH     qXi2, qXi2, InvSqrt2            ;// i2/sqrt(2)
+        VHADD       qXh0, qXi0, qXi1                ;// (i0+i1)/2
+        VHSUB       qXh1, qXi0, qXi1                ;// (i0-i1)/2
+        VHADD       qXh7, qXi5, qXi7                ;// (i5+i7)/4
+        VSUB        qXh5, qXi5, qXi7                ;// (i5-i7)/2
+        VQRDMULH     qXh5, qXh5, InvSqrt2            ;// h5/sqrt(2)
+        VSUB        qXh2, qXi2, qXi3                ;// h2, h3
+
+        VMULL       qXt0, dXi4lo, C                 ;// c*i4
+        VMLAL       qXt0, dXi6lo, S                 ;// c*i4+s*i6
+        VMULL       qXt1, dXi4hi, C
+        VMLAL       qXt1, dXi6hi, S
+        VSHRN       dXh4lo, qXt0, #16               ;// h4
+        VSHRN       dXh4hi, qXt1, #16
+        
+        VMULL       qXt0, dXi6lo, C                 ;// c*i6
+        VMLSL       qXt0, dXi4lo, S                 ;// -s*i4 + c*h6
+        VMULL       qXt1, dXi6hi, C
+        VMLSL       qXt1, dXi4hi, S
+        VSHRN       dXh6lo, qXt0, #16               ;// h6
+        VSHRN       dXh6hi, qXt1, #16
+        
+        ;// IStage 2
+        VSUB        qXg6, qXh6, qXh7
+        VSUB        qXg5, qXh5, qXg6
+        VSUB        qXg4, qXh4, qXg5
+        VHADD       qXg1, qXh1, qXh2        ;// (h1+h2)/2
+        VHSUB       qXg2, qXh1, qXh2        ;// (h1-h2)/2
+        VHADD       qXg0, qXh0, qXh3        ;// (h0+h3)/2
+        VHSUB       qXg3, qXh0, qXh3        ;// (h0-h3)/2
+
+        ;// IStage 1 all rows
+        VADD        qXf3, qXg3, qXg4        
+        VSUB        qXf4, qXg3, qXg4        
+        VADD        qXf2, qXg2, qXg5        
+        VSUB        qXf5, qXg2, qXg5        
+        VADD        qXf1, qXg1, qXg6
+        VSUB        qXf6, qXg1, qXg6        
+        VADD        qXf0, qXg0, qXg7
+        VSUB        qXf7, qXg0, qXg7      
+
+        ;// Transpose, store and loop
+XTR0            EQU Src5
+XTR1            EQU Tmp
+XTR2            EQU Src6
+XTR3            EQU Src7
+XTR4            EQU Src3
+XTR5            EQU Src0
+XTR6            EQU Src1
+XTR7            EQU Src2
+XTRt            EQU Src4
+                
+qA0             QN  XTR0.S32  ;// for XTRpose
+qA1             QN  XTR1.S32
+qA2             QN  XTR2.S32
+qA3             QN  XTR3.S32
+qA4             QN  XTR4.S32
+qA5             QN  XTR5.S32
+qA6             QN  XTR6.S32
+qA7             QN  XTR7.S32
+
+dB0             DN  XTR0*2+1      ;// for using VSWP
+dB1             DN  XTR1*2+1
+dB2             DN  XTR2*2+1
+dB3             DN  XTR3*2+1
+dB4             DN  XTR4*2
+dB5             DN  XTR5*2
+dB6             DN  XTR6*2
+dB7             DN  XTR7*2
+
+          
+        VTRN        qXf0, qXf1
+        VTRN        qXf2, qXf3
+        VTRN        qXf4, qXf5
+        VTRN        qXf6, qXf7
+        VTRN        qA0, qA2
+        VTRN        qA1, qA3
+        VTRN        qA4, qA6
+        VTRN        qA5, qA7        
+        VSWP        dB0, dB4
+        VSWP        dB1, dB5
+        VSWP        dB2, dB6
+        VSWP        dB3, dB7
+        
+
+qYj0            QN qXf0
+qYj1            QN qXf1
+qYj2            QN qXf2
+qYj3            QN qXf3
+qYj4            QN qXf4
+qYj5            QN qXf5
+qYj6            QN qXf6
+qYj7            QN qXf7
+qYjt            QN qXft
+
+dYj0lo          DN (XTR0*2).S16
+dYj0hi          DN (XTR0*2+1).S16
+dYj1lo          DN (XTR1*2).S16
+dYj1hi          DN (XTR1*2+1).S16
+dYj2lo          DN (XTR2*2).S16
+dYj2hi          DN (XTR2*2+1).S16
+dYj3lo          DN (XTR3*2).S16
+dYj3hi          DN (XTR3*2+1).S16
+dYj4lo          DN (XTR4*2).S16
+dYj4hi          DN (XTR4*2+1).S16
+dYj5lo          DN (XTR5*2).S16
+dYj5hi          DN (XTR5*2+1).S16
+dYj6lo          DN (XTR6*2).S16
+dYj6hi          DN (XTR6*2+1).S16
+dYj7lo          DN (XTR7*2).S16
+dYj7hi          DN (XTR7*2+1).S16
+dYjtlo          DN (XTRt*2).S16
+dYjthi          DN (XTRt*2+1).S16
+
+qYi0            QN qYj0
+qYi1            QN qYj4
+qYi2            QN qYj2
+qYi3            QN qYj7
+qYi4            QN qYj5
+qYi5            QN qYjt
+qYi6            QN qYj1
+qYi7            QN qYj6
+qYit            QN qYj3
+
+dYi0lo          DN dYj0lo
+dYi0hi          DN dYj0hi
+dYi1lo          DN dYj4lo
+dYi1hi          DN dYj4hi
+dYi2lo          DN dYj2lo
+dYi2hi          DN dYj2hi
+dYi3lo          DN dYj7lo
+dYi3hi          DN dYj7hi
+dYi4lo          DN dYj5lo
+dYi4hi          DN dYj5hi
+dYi5lo          DN dYjtlo
+dYi5hi          DN dYjthi
+dYi6lo          DN dYj1lo
+dYi6hi          DN dYj1hi
+dYi7lo          DN dYj6lo
+dYi7hi          DN dYj6hi
+dYitlo          DN dYj3lo
+dYithi          DN dYj3hi
+
+qYh0            QN qYit
+qYh1            QN qYi0
+qYh2            QN qYi2
+qYh3            QN qYi3
+qYh4            QN qYi7
+qYh5            QN qYi5
+qYh6            QN qYi4
+qYh7            QN qYi1
+qYht            QN qYi6
+
+dYh0lo          DN dYitlo
+dYh0hi          DN dYithi
+dYh1lo          DN dYi0lo
+dYh1hi          DN dYi0hi
+dYh2lo          DN dYi2lo
+dYh2hi          DN dYi2hi
+dYh3lo          DN dYi3lo
+dYh3hi          DN dYi3hi
+dYh4lo          DN dYi7lo
+dYh4hi          DN dYi7hi
+dYh5lo          DN dYi5lo
+dYh5hi          DN dYi5hi
+dYh6lo          DN dYi4lo
+dYh6hi          DN dYi4hi
+dYh7lo          DN dYi1lo
+dYh7hi          DN dYi1hi
+dYhtlo          DN dYi6lo
+dYhthi          DN dYi6hi
+
+qYg0            QN qYh2
+qYg1            QN qYht
+qYg2            QN qYh1
+qYg3            QN qYh0
+qYg4            QN qYh4
+qYg5            QN qYh5
+qYg6            QN qYh6
+qYg7            QN qYh7
+qYgt            QN qYh3
+
+qYf0            QN qYg6
+qYf1            QN qYg5
+qYf2            QN qYg4
+qYf3            QN qYgt
+qYf4            QN qYg3
+qYf5            QN qYg2
+qYf6            QN qYg1
+qYf7            QN qYg0
+qYft            QN qYg7
+
+        VRSHR       qYj7, qYj7, #2
+        VRSHR       qYj6, qYj6, #1
+        
+        VHADD       qYi5, qYj1, qYj7        ;// i5 = (j1+j7)/2
+        VSUB        qYi6, qYj1, qYj7        ;// i6 = j1-j7
+        VHADD       qYi3, qYj2, qYj6        ;// i3 = (j2+j6)/2
+        VSUB        qYi2, qYj2, qYj6        ;// i2 = j2-j6
+        VHADD       qYi7, qYj5, qYj3        ;// i7 = (j5+j3)/2
+        VSUB        qYi4, qYj5, qYj3        ;// i4 = j5-j3
+
+        VQRDMULH     qYi2, qYi2, InvSqrt2    ;// i2/sqrt(2)
+        ;// IStage 4,3 rows 0to1 x 1/2
+        
+        MOV         pTemp, #0x4             ;// ensure correct round
+        VDUP        qScale1, pTemp           ;// of DC result
+        VADD        qYi0, qYi0, qScale1
+        
+        VHADD       qYh0, qYi0, qYi1        ;// (i0+i1)/2
+        VHSUB       qYh1, qYi0, qYi1        ;// (i0-i1)/2
+
+        VHADD       qYh7, qYi5, qYi7        ;// (i5+i7)/4
+        VSUB        qYh5, qYi5, qYi7        ;// (i5-i7)/2
+        VSUB        qYh2, qYi2, qYi3        ;// h2, h3
+        VQRDMULH     qYh5, qYh5, InvSqrt2    ;// h5/sqrt(2)
+
+        VMULL       qXt0, dYi4lo, C         ;// c*i4
+        VMLAL       qXt0, dYi6lo, S         ;// c*i4+s*i6
+        VMULL       qXt1, dYi4hi, C
+        VMLAL       qXt1, dYi6hi, S
+        VSHRN       dYh4lo, qXt0, #16       ;// h4
+        VSHRN       dYh4hi, qXt1, #16
+        
+        VMULL       qXt0, dYi6lo, C         ;// c*i6
+        VMLSL       qXt0, dYi4lo, S         ;// -s*i4 + c*h6
+        VMULL       qXt1, dYi6hi, C
+        VMLSL       qXt1, dYi4hi, S
+        VSHRN       dYh6lo, qXt0, #16       ;// h6
+        VSHRN       dYh6hi, qXt1, #16
+        
+        VSUB        qYg6, qYh6, qYh7
+        VSUB        qYg5, qYh5, qYg6
+        VSUB        qYg4, qYh4, qYg5
+        
+        ;// IStage 2 rows 0to3 x 1/2
+        VHADD       qYg1, qYh1, qYh2        ;// (h1+h2)/2
+        VHSUB       qYg2, qYh1, qYh2        ;// (h1-h2)/2
+        VHADD       qYg0, qYh0, qYh3        ;// (h0+h3)/2
+        VHSUB       qYg3, qYh0, qYh3        ;// (h0-h3)/2
+        
+
+        ;// IStage 1 all rows
+        VHADD        qYf3, qYg3, qYg4        
+        VHSUB        qYf4, qYg3, qYg4        
+        VHADD        qYf2, qYg2, qYg5        
+        VHSUB        qYf5, qYg2, qYg5        
+        VHADD        qYf1, qYg1, qYg6
+        VHSUB        qYf6, qYg1, qYg6        
+        VHADD        qYf0, qYg0, qYg7
+        VHSUB        qYf7, qYg0, qYg7      
+
+YTR0            EQU Src0
+YTR1            EQU Src4
+YTR2            EQU Src1
+YTR3            EQU Src2
+YTR4            EQU Src7
+YTR5            EQU Src5
+YTR6            EQU Tmp
+YTR7            EQU Src6
+YTRt            EQU Src3
+
+qC0             QN  YTR0.S32                ;// for YTRpose
+qC1             QN  YTR1.S32
+qC2             QN  YTR2.S32
+qC3             QN  YTR3.S32
+qC4             QN  YTR4.S32
+qC5             QN  YTR5.S32
+qC6             QN  YTR6.S32
+qC7             QN  YTR7.S32
+
+dD0             DN  YTR0*2+1                ;// for using VSWP
+dD1             DN  YTR1*2+1
+dD2             DN  YTR2*2+1
+dD3             DN  YTR3*2+1
+dD4             DN  YTR4*2
+dD5             DN  YTR5*2
+dD6             DN  YTR6*2
+dD7             DN  YTR7*2
+          
+        VTRN        qYf0, qYf1
+        VTRN        qYf2, qYf3
+        VTRN        qYf4, qYf5
+        VTRN        qYf6, qYf7
+        VTRN        qC0, qC2
+        VTRN        qC1, qC3
+        VTRN        qC4, qC6
+        VTRN        qC5, qC7        
+        VSWP        dD0, dD4
+        VSWP        dD1, dD5
+        VSWP        dD2, dD6
+        VSWP        dD3, dD7
+
+        
+dYf0U8          DN YTR0*2.U8
+dYf1U8          DN YTR1*2.U8
+dYf2U8          DN YTR2*2.U8
+dYf3U8          DN YTR3*2.U8
+dYf4U8          DN YTR4*2.U8
+dYf5U8          DN YTR5*2.U8
+dYf6U8          DN YTR6*2.U8
+dYf7U8          DN YTR7*2.U8
+        
+        ;//
+        ;// Do saturation if outsize is other than S16
+        ;//
+        
+        IF ("$outsize"="u8")
+            ;// Output range [0-255]
+            VQMOVN            dYf0U8, qYf0
+            VQMOVN            dYf1U8, qYf1
+            VQMOVN            dYf2U8, qYf2
+            VQMOVN            dYf3U8, qYf3
+            VQMOVN            dYf4U8, qYf4
+            VQMOVN            dYf5U8, qYf5
+            VQMOVN            dYf6U8, qYf6
+            VQMOVN            dYf7U8, qYf7
+        ENDIF
+        
+        IF ("$outsize"="s9")
+            ;// Output range [-256 to +255]
+            VQSHL            qYf0, qYf0, #16-9
+            VQSHL            qYf1, qYf1, #16-9
+            VQSHL            qYf2, qYf2, #16-9
+            VQSHL            qYf3, qYf3, #16-9
+            VQSHL            qYf4, qYf4, #16-9
+            VQSHL            qYf5, qYf5, #16-9
+            VQSHL            qYf6, qYf6, #16-9
+            VQSHL            qYf7, qYf7, #16-9
+            
+            VSHR             qYf0, qYf0, #16-9
+            VSHR             qYf1, qYf1, #16-9
+            VSHR             qYf2, qYf2, #16-9
+            VSHR             qYf3, qYf3, #16-9
+            VSHR             qYf4, qYf4, #16-9
+            VSHR             qYf5, qYf5, #16-9
+            VSHR             qYf6, qYf6, #16-9
+            VSHR             qYf7, qYf7, #16-9
+        ENDIF
+
+        ;// Store output depending on the Stride size
+        IF "$stride"="s"
+            VST1        qYf0, [pDest @64], Stride
+            VST1        qYf1, [pDest @64], Stride
+            VST1        qYf2, [pDest @64], Stride
+            VST1        qYf3, [pDest @64], Stride
+            VST1        qYf4, [pDest @64], Stride
+            VST1        qYf5, [pDest @64], Stride
+            VST1        qYf6, [pDest @64], Stride
+            VST1        qYf7, [pDest @64]            
+        ELSE
+            IF ("$outsize"="u8")
+                VST1        dYf0U8, [pDest @64], #8
+                VST1        dYf1U8, [pDest @64], #8
+                VST1        dYf2U8, [pDest @64], #8
+                VST1        dYf3U8, [pDest @64], #8
+                VST1        dYf4U8, [pDest @64], #8
+                VST1        dYf5U8, [pDest @64], #8
+                VST1        dYf6U8, [pDest @64], #8
+                VST1        dYf7U8, [pDest @64]
+            ELSE
+                ;// ("$outsize"="s9") or ("$outsize"="s16")
+                VST1        qYf0, [pDest @64], #16
+                VST1        qYf1, [pDest @64], #16
+                VST1        qYf2, [pDest @64], #16
+                VST1        qYf3, [pDest @64], #16
+                VST1        qYf4, [pDest @64], #16
+                VST1        qYf5, [pDest @64], #16
+                VST1        qYf6, [pDest @64], #16
+                VST1        qYf7, [pDest @64]
+            ENDIF
+        
+        ENDIF
+
+
+
+        ENDIF ;// CortexA8
+
+
+
+        MEND        
+
+        ;// Scale TWO input rows with TWO rows of 16 bit scale values
+        ;//
+        ;// This macro is used by M_IDCT_PRESCALE16 to pre-scale one row
+        ;// input (Eight input values) with one row of scale values. Also 
+        ;// Loads next scale values from pScale, if $LastRow flag is not set.
+        ;//
+        ;// Input Registers:
+        ;//
+        ;// $dAlo           - Input D register with first four S16 values of row n
+        ;// $dAhi           - Input D register with next four S16 values of row n
+        ;// $dBlo           - Input D register with first four S16 values of row n+1
+        ;// $dBhi           - Input D register with next four S16 values of row n+1
+        ;// pScale          - Pointer to next row of scale values
+        ;// qT0lo           - Temporary scratch register
+        ;// qT0hi           - Temporary scratch register
+        ;// qT1lo           - Temporary scratch register
+        ;// qT1hi           - Temporary scratch register
+        ;// dScale1lo       - Scale value of row n
+        ;// dScale1hi       - Scale value of row n
+        ;// dScale2lo       - Scale value of row n+1
+        ;// dScale2hi       - Scale value of row n+1
+        ;//
+        ;// Input Flag
+        ;//
+        ;// $LastRow        - Flag to indicate whether current row is last row
+        ;//
+        ;// Output Registers:
+        ;//
+        ;// $dAlo           - Scaled output values (first four S16 of row n)
+        ;// $dAhi           - Scaled output values (next four S16 of row n)
+        ;// $dBlo           - Scaled output values (first four S16 of row n+1)
+        ;// $dBhi           - Scaled output values (next four S16 of row n+1)
+        ;// qScale1         - Scale values for next row
+        ;// qScale2         - Scale values for next row+1
+        ;// pScale          - Pointer to next row of scale values
+        ;//
+        MACRO
+        M_IDCT_SCALE16 $dAlo, $dAhi, $dBlo, $dBhi, $LastRow
+        VMULL       qT0lo, $dAlo, dScale1lo
+        VMULL       qT0hi, $dAhi, dScale1hi
+        VMULL       qT1lo, $dBlo, dScale2lo
+        VMULL       qT1hi, $dBhi, dScale2hi
+        IF "$LastRow"="0"
+            VLD1        qScale1, [pScale], #16  ;// Load scale for row n+1
+            VLD1        qScale2, [pScale], #16  ;// Load scale for row n+2
+        ENDIF
+        VQRSHRN       $dAlo, qT0lo, #12        
+        VQRSHRN       $dAhi, qT0hi, #12        
+        VQRSHRN       $dBlo, qT1lo, #12        
+        VQRSHRN       $dBhi, qT1hi, #12        
+        MEND
+
+        ;// Scale 8x8 block input values with 16 bit scale values
+        ;//
+        ;// This macro is used to pre-scale block of 8x8 input.
+        ;// This also do the Ist stage transformations of IDCT.
+        ;//
+        ;// Input Registers:
+        ;//
+        ;// dXjnlo          - n th input D register with first four S16 values
+        ;// dXjnhi          - n th input D register with next four S16 values
+        ;// qXjn            - n th input Q register with eight S16 values
+        ;// pScale          - Pointer to scale values
+        ;//
+        ;// Output Registers:
+        ;//
+        ;// qXin            - n th output Q register with eight S16 output values of 1st stage
+        ;//
+        MACRO
+        M_IDCT_PRESCALE16
+        VLD1        qScale1, [pScale], #16      ;// Load Pre scale for row 0
+        VLD1        qScale2, [pScale], #16      ;// Load Pre scale for row 0
+        M_IDCT_SCALE16 dXj0lo, dXj0hi, dXj1lo, dXj1hi, 0        ;// Pre scale row 0 & 1
+        M_IDCT_SCALE16 dXj2lo, dXj2hi, dXj3lo, dXj3hi, 0        
+        M_IDCT_SCALE16 dXj4lo, dXj4hi, dXj5lo, dXj5hi, 0        
+        M_IDCT_SCALE16 dXj6lo, dXj6hi, dXj7lo, dXj7hi, 1        
+        VHADD       qXi5, qXj1, qXj7            ;// (j1+j7)/2
+        VSUB        qXi6, qXj1, qXj7            ;// j1-j7
+        LDR         pSrc, =armCOMM_IDCTCoef ;// Address of DCT inverse AAN constants
+        VHADD       qXi3, qXj2, qXj6            ;// (j2+j6)/2
+        VSUB        qXi2, qXj2, qXj6            ;// j2-j6
+        VLDR        dCoefs, [pSrc]              ;// Load DCT inverse AAN constants
+        VHADD       qXi7, qXj5, qXj3            ;// (j5+j3)/2
+        VSUB        qXi4, qXj5, qXj3            ;// j5-j3
+        MEND    
+        
+        
+        ;// Scale 8x8 block input values with 32 bit scale values
+        ;//
+        ;// This macro is used to pre-scale block of 8x8 input.
+        ;// This also do the Ist stage transformations of IDCT.
+        ;//
+        ;// Input Registers:
+        ;//
+        ;// dXjnlo          - n th input D register with first four S16 values
+        ;// dXjnhi          - n th input D register with next four S16 values
+        ;// qXjn            - n th input Q register with eight S16 values
+        ;// pScale          - Pointer to 32bit scale values in Q23 format
+        ;//
+        ;// Output Registers:
+        ;//
+        ;// dXinlo          - n th output D register with first four S16 output values of 1st stage
+        ;// dXinhi          - n th output D register with next four S16 output values of 1st stage
+        ;//
+        MACRO
+        M_IDCT_PRESCALE32
+qScale0lo       QN 0.S32
+qScale0hi       QN 1.S32
+qScale1lo       QN 2.S32
+qScale1hi       QN 3.S32
+qScale2lo       QN qScale1lo
+qScale2hi       QN qScale1hi
+qScale3lo       QN qScale1lo
+qScale3hi       QN qScale1hi
+qScale4lo       QN qScale1lo
+qScale4hi       QN qScale1hi
+qScale5lo       QN qScale0lo
+qScale5hi       QN qScale0hi
+qScale6lo       QN qScale0lo
+qScale6hi       QN qScale0hi
+qScale7lo       QN qScale0lo
+qScale7hi       QN qScale0hi
+
+qSrc0lo         QN 4.S32
+qSrc0hi         QN 5.S32
+qSrc1lo         QN 6.S32
+qSrc1hi         QN Src4.S32
+qSrc2lo         QN qSrc0lo
+qSrc2hi         QN qSrc0hi
+qSrc3lo         QN qSrc0lo
+qSrc3hi         QN qSrc0hi
+qSrc4lo         QN qSrc0lo
+qSrc4hi         QN qSrc0hi
+qSrc5lo         QN qSrc1lo
+qSrc5hi         QN qSrc1hi
+qSrc6lo         QN qSrc1lo
+qSrc6hi         QN qSrc1hi
+qSrc7lo         QN qSrc0lo
+qSrc7hi         QN qSrc0hi
+
+qRes17lo        QN qScale0lo
+qRes17hi        QN qScale0hi
+qRes26lo        QN qScale0lo
+qRes26hi        QN qScale0hi
+qRes53lo        QN qScale0lo
+qRes53hi        QN qScale0hi
+
+            ADD         pTemp, pScale, #4*8*7           ;// Address of  pScale[7]
+            
+            ;// Row 0
+            VLD1        {qScale0lo, qScale0hi}, [pScale]!
+            VSHLL       qSrc0lo, dXj0lo, #(12-1)
+            VSHLL       qSrc0hi, dXj0hi, #(12-1)            
+            VLD1        {qScale1lo, qScale1hi}, [pScale]!
+            VQRDMULH    qSrc0lo, qScale0lo, qSrc0lo
+            VQRDMULH    qSrc0hi, qScale0hi, qSrc0hi
+            VLD1        {qScale7lo, qScale7hi}, [pTemp]!
+            VSHLL       qSrc1lo, dXj1lo, #(12-1)
+            VSHLL       qSrc1hi, dXj1hi, #(12-1)            
+            VMOVN       dXi0lo, qSrc0lo                 ;// Output i0
+            VMOVN       dXi0hi, qSrc0hi
+            VSHLL       qSrc7lo, dXj7lo, #(12-1)
+            VSHLL       qSrc7hi, dXj7hi, #(12-1)
+            SUB         pTemp, pTemp, #((16*2)+(4*8*1))
+            VQRDMULH    qSrc1lo, qScale1lo, qSrc1lo
+            VQRDMULH    qSrc1hi, qScale1hi, qSrc1hi
+            VQRDMULH    qSrc7lo, qScale7lo, qSrc7lo
+            VQRDMULH    qSrc7hi, qScale7hi, qSrc7hi
+            VLD1        {qScale2lo, qScale2hi}, [pScale]!
+
+            ;// Row 1 & 7
+            VHADD       qRes17lo, qSrc1lo, qSrc7lo      ;// (j1+j7)/2
+            VHADD       qRes17hi, qSrc1hi, qSrc7hi      ;// (j1+j7)/2
+            VMOVN       dXi5lo, qRes17lo                ;// Output i5
+            VMOVN       dXi5hi, qRes17hi              
+            VSUB        qRes17lo, qSrc1lo, qSrc7lo      ;// j1-j7
+            VSUB        qRes17hi, qSrc1hi, qSrc7hi      ;// j1-j7
+            VMOVN       dXi6lo, qRes17lo                ;// Output i6
+            VMOVN       dXi6hi, qRes17hi      
+            VSHLL       qSrc2lo, dXj2lo, #(12-1)
+            VSHLL       qSrc2hi, dXj2hi, #(12-1)
+            VLD1        {qScale6lo, qScale6hi}, [pTemp]!
+            VSHLL       qSrc6lo, dXj6lo, #(12-1)
+            VSHLL       qSrc6hi, dXj6hi, #(12-1)
+            SUB         pTemp, pTemp, #((16*2)+(4*8*1))
+            VQRDMULH    qSrc2lo, qScale2lo, qSrc2lo
+            VQRDMULH    qSrc2hi, qScale2hi, qSrc2hi
+            VQRDMULH    qSrc6lo, qScale6lo, qSrc6lo
+            VQRDMULH    qSrc6hi, qScale6hi, qSrc6hi
+            VLD1        {qScale3lo, qScale3hi}, [pScale]!
+
+            ;// Row 2 & 6
+            VHADD       qRes26lo, qSrc2lo, qSrc6lo      ;// (j2+j6)/2
+            VHADD       qRes26hi, qSrc2hi, qSrc6hi      ;// (j2+j6)/2
+            VMOVN       dXi3lo, qRes26lo                ;// Output i3
+            VMOVN       dXi3hi, qRes26hi              
+            VSUB        qRes26lo, qSrc2lo, qSrc6lo      ;// j2-j6
+            VSUB        qRes26hi, qSrc2hi, qSrc6hi      ;// j2-j6
+            VMOVN       dXi2lo, qRes26lo                ;// Output i2
+            VMOVN       dXi2hi, qRes26hi      
+            VSHLL       qSrc3lo, dXj3lo, #(12-1)
+            VSHLL       qSrc3hi, dXj3hi, #(12-1)
+            VLD1        {qScale5lo, qScale5hi}, [pTemp]!
+            VSHLL       qSrc5lo, dXj5lo, #(12-1)
+            VSHLL       qSrc5hi, dXj5hi, #(12-1)
+            VQRDMULH    qSrc3lo, qScale3lo, qSrc3lo
+            VQRDMULH    qSrc3hi, qScale3hi, qSrc3hi
+            VQRDMULH    qSrc5lo, qScale5lo, qSrc5lo
+            VQRDMULH    qSrc5hi, qScale5hi, qSrc5hi
+            
+            ;// Row 3 & 5
+            VHADD       qRes53lo, qSrc5lo, qSrc3lo      ;// (j5+j3)/2
+            VHADD       qRes53hi, qSrc5hi, qSrc3hi      ;// (j5+j3)/2
+            SUB         pSrc, pSrc, #16*2*2
+            VMOVN       dXi7lo, qRes53lo                ;// Output i7
+            VMOVN       dXi7hi, qRes53hi              
+            VSUB        qRes53lo, qSrc5lo, qSrc3lo      ;// j5-j3
+            VSUB        qRes53hi, qSrc5hi, qSrc3hi      ;// j5-j3
+            VLD1        qXj4, [pSrc @64]
+            VMOVN       dXi4lo, qRes53lo                ;// Output i4
+            VMOVN       dXi4hi, qRes53hi                              
+            VSHLL       qSrc4lo, dXj4lo, #(12-1)
+            VSHLL       qSrc4hi, dXj4hi, #(12-1)
+            VLD1        {qScale4lo, qScale4hi}, [pScale]            
+            LDR         pSrc, =armCOMM_IDCTCoef     ;// Address of DCT inverse AAN constants
+            VQRDMULH    qSrc4lo, qScale4lo, qSrc4lo
+            VQRDMULH    qSrc4hi, qScale4hi, qSrc4hi
+            VLDR        dCoefs, [pSrc]                  ;// Load DCT inverse AAN constants
+            ;// Row 4
+            VMOVN       dXi1lo, qSrc4lo                 ;// Output i1
+            VMOVN       dXi1hi, qSrc4hi              
+        
+        MEND
+                                                
+        END
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/api/armCOMM_MaskTable.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/api/armCOMM_MaskTable.h
new file mode 100644
index 0000000..b5da9dce
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/api/armCOMM_MaskTable.h
@@ -0,0 +1,27 @@
+/**
+ * 
+ * File Name:  armCOMM_MaskTable.h
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Mask Table to mask the end of array
+ */
+ 
+
+
+#ifndef _ARMCOMM_MASKTABLE_H_
+#define _ARMCOMM_MASKTABLE_H_
+
+#define MaskTableSize 72
+  
+/* Mask table */
+
+extern const OMX_U16 armCOMM_qMaskTable16[MaskTableSize];
+extern const OMX_U8 armCOMM_qMaskTable8[MaskTableSize];
+
+#endif
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/api/armCOMM_Version.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/api/armCOMM_Version.h
new file mode 100644
index 0000000..13e5b2b
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/api/armCOMM_Version.h
@@ -0,0 +1,43 @@
+/* Guard the header against multiple inclusion. */
+#ifndef __ARM_COMM_VERSION_H__
+#define __ARM_COMM_VERSION_H__
+
+
+/* The following line should be in omxtypes.h but hasn't been approved by OpenMAX yet */
+#define OMX_VERSION 102
+
+/* We need to define these macros in order to convert a #define number into a #define string. */
+#define ARM_QUOTE(a) #a
+#define ARM_INDIRECT(A) ARM_QUOTE(A)
+
+/* Convert the OMX_VERSION number into a string that can be used, for example, to print it out. */
+#define ARM_VERSION_STRING ARM_INDIRECT(OMX_VERSION)
+
+
+/* Define this in order to turn on ARM version/release/build strings in each domain */
+#define ARM_INCLUDE_VERSION_DESCRIPTIONS
+
+#ifdef ARM_INCLUDE_VERSION_DESCRIPTIONS
+  extern const char * const omxAC_VersionDescription;
+  extern const char * const omxIC_VersionDescription;
+  extern const char * const omxIP_VersionDescription;
+  extern const char * const omxSP_VersionDescription;
+  extern const char * const omxVC_VersionDescription;
+#endif /* ARM_INCLUDE_VERSION_DESCRIPTIONS */
+
+
+/* The following entries should be automatically updated by the release script */
+/* They are used in the ARM version strings defined for each domain.             */
+
+/* The release tag associated with this release of the library. - used for source and object releases */
+#define OMX_ARM_RELEASE_TAG  "r0p0-00bet1"
+
+/* The ARM architecture used to build any objects or executables in this release. */
+#define OMX_ARM_BUILD_ARCHITECTURE "ARM Architecture V6"
+
+/* The ARM Toolchain used to build any objects or executables in this release. */
+#define OMX_ARM_BUILD_TOOLCHAIN    "ARM RVCT 3.1"
+
+
+#endif /* __ARM_COMM_VERSION_H__ */
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/api/armCOMM_s.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/api/armCOMM_s.h
new file mode 100644
index 0000000..2df1fc8
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/api/armCOMM_s.h
@@ -0,0 +1,1154 @@
+;//
+;// 
+;// File Name:  armCOMM_s.h
+;// OpenMAX DL: v1.0.2
+;// Revision:   9641
+;// Date:       Thursday, February 7, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+;// ARM optimized OpenMAX common header file
+;//
+
+;// Protect against multiple inclusion
+ IF :LNOT::DEF:ARMCOMM_S_H
+ GBLL ARMCOMM_S_H
+
+        REQUIRE8            ;// Requires 8-byte stack alignment
+        PRESERVE8           ;// Preserves 8-byte stack alignment
+        
+        GBLL    ARM_ERRORCHECK
+ARM_ERRORCHECK  SETL {FALSE}
+
+;// Globals
+
+        GBLS    _RRegList   ;// R saved register list
+        GBLS    _DRegList   ;// D saved register list
+        GBLS    _Variant    ;// Selected processor variant
+        GBLS    _CPU        ;// CPU name
+        GBLS    _Struct     ;// Structure name
+        
+        GBLL    _InFunc     ;// Inside function assembly flag
+        GBLL    _SwLong     ;// Long switch flag
+        
+        GBLA    _RBytes     ;// Number of register bytes on stack
+        GBLA    _SBytes     ;// Number of scratch bytes on stack 
+        GBLA    _ABytes     ;// Stack offset of next argument
+        GBLA    _Workspace  ;// Stack offset of scratch workspace
+        GBLA    _F          ;// Function number
+        GBLA    _StOff      ;// Struct offset
+        GBLA    _SwNum      ;// Switch number
+        GBLS    _32         ;// Suffix for 32 byte alignmnet
+        GBLS    _16         ;// Suffix for 16 byte alignmnet
+        
+_InFunc         SETL    {FALSE}
+_SBytes         SETA    0
+_F              SETA    0
+_SwNum          SETA    0
+_32             SETS    "ALIGN32"
+_16             SETS    "ALIGN16"
+
+;/////////////////////////////////////////////////////////
+;// Override the tools settings of the CPU if the #define
+;// USECPU is set, otherwise use the CPU defined by the
+;// assembler settings.
+;/////////////////////////////////////////////////////////
+
+       IF :DEF: OVERRIDECPU
+_CPU       SETS  OVERRIDECPU
+       ELSE
+_CPU       SETS    {CPU}       
+       ENDIF
+
+
+
+;/////////////////////////////////////////////////////////
+;// Work out which code to build
+;/////////////////////////////////////////////////////////
+
+        IF :DEF:ARM1136JS:LOR::DEF:CortexA8:LOR::DEF:ARM_GENERIC
+            INFO 1,"Please switch to using M_VARIANTS"
+        ENDIF
+
+        ;// Define and reset all officially recongnised variants
+        MACRO
+        _M_DEF_VARIANTS
+        _M_DEF_VARIANT ARM926EJS
+        _M_DEF_VARIANT ARM1136JS
+        _M_DEF_VARIANT ARM1136JS_U
+        _M_DEF_VARIANT CortexA8
+        _M_DEF_VARIANT ARM7TDMI
+        MEND
+        
+        MACRO
+        _M_DEF_VARIANT $var
+        GBLL $var
+        GBLL _ok$var
+$var    SETL {FALSE}
+        MEND        
+        
+
+        ;// Variant declaration
+        ;//
+        ;// Define a list of code variants supported by this
+        ;// source file. This macro then chooses the most
+        ;// appropriate variant to build for the currently configured
+        ;// core.
+        ;//        
+        MACRO
+        M_VARIANTS $v0,$v1,$v2,$v3,$v4,$v5,$v6,$v7        
+        ;// Set to TRUE variants that are supported
+        _M_DEF_VARIANTS
+        _M_VARIANT $v0
+        _M_VARIANT $v1
+        _M_VARIANT $v2
+        _M_VARIANT $v3
+        _M_VARIANT $v4
+        _M_VARIANT $v5
+        _M_VARIANT $v6
+        _M_VARIANT $v7
+        
+        ;// Look for first available variant to match a CPU
+        ;// _M_TRY cpu, variant fall back list
+_Variant SETS ""                
+        _M_TRY ARM926EJ-S,   ARM926EJS
+        _M_TRY ARM1176JZ-S,  ARM1136JS
+        _M_TRY ARM1176JZF-S, ARM1136JS
+        _M_TRY ARM1156T2-S,  ARM1136JS
+        _M_TRY ARM1156T2F-S, ARM1136JS
+        _M_TRY ARM1136J-S,   ARM1136JS
+        _M_TRY ARM1136JF-S,  ARM1136JS
+        _M_TRY MPCore,       ARM1136JS
+        _M_TRY Cortex-A8,    CortexA8, ARM1136JS
+        _M_TRY Cortex-R4,    ARM1136JS
+        _M_TRY ARM7TDMI
+        
+        ;// Select the correct variant
+        _M_DEF_VARIANTS
+        IF _Variant=""
+            INFO 1, "No match found for CPU '$_CPU'"
+        ELSE
+$_Variant   SETL {TRUE}
+        ENDIF
+        MEND
+        
+        ;// Register a variant as available
+        MACRO
+        _M_VARIANT $var
+        IF "$var"=""
+            MEXIT
+        ENDIF
+        IF :LNOT::DEF:_ok$var
+            INFO 1, "Unrecognized variant '$var'"
+        ENDIF
+$var    SETL {TRUE}
+        MEND
+        
+        ;// For a given CPU, see if any of the variants supporting
+        ;// this CPU are available. The first available variant is
+        ;// chosen
+        MACRO
+        _M_TRY $cpu, $v0,$v1,$v2,$v3,$v4,$v5,$v6,$v7
+        IF "$cpu"<>_CPU
+            MEXIT
+        ENDIF
+        _M_TRY1 $v0
+        _M_TRY1 $v1
+        _M_TRY1 $v2
+        _M_TRY1 $v3
+        _M_TRY1 $v4
+        _M_TRY1 $v5
+        _M_TRY1 $v6
+        _M_TRY1 $v7
+        ;// Check a match was found
+        IF _Variant=""
+            INFO 1, "No variant match found for CPU '$_CPU'"
+        ENDIF
+        MEND
+        
+        MACRO
+        _M_TRY1 $var
+        IF "$var"=""
+            MEXIT
+        ENDIF
+        IF (_Variant=""):LAND:$var
+_Variant SETS "$var"
+        ENDIF
+        MEND
+        
+;////////////////////////////////////////////////////////
+;// Structure definition
+;////////////////////////////////////////////////////////
+
+        ;// Declare a structure of given name
+        MACRO
+        M_STRUCT $sname
+_Struct SETS "$sname"
+_StOff  SETA 0
+        MEND
+        
+        ;// Declare a structure field
+        ;// The field is called $sname_$fname
+        ;// $size   = the size of each entry, must be power of 2 
+        ;// $number = (if provided) the number of entries for an array
+        MACRO
+        M_FIELD $fname, $size, $number
+        IF (_StOff:AND:($size-1))!=0
+_StOff      SETA _StOff + ($size - (_StOff:AND:($size-1)))
+        ENDIF
+$_Struct._$fname EQU _StOff
+        IF "$number"<>""
+_StOff      SETA _StOff + $size*$number
+        ELSE
+_StOff      SETA _StOff + $size
+        ENDIF
+        MEND
+        
+        
+        MACRO
+        M_ENDSTRUCT
+sizeof_$_Struct EQU _StOff
+_Struct SETS ""
+        MEND
+
+;//////////////////////////////////////////////////////////
+;// Switch and table macros
+;//////////////////////////////////////////////////////////
+
+        ;// Start a relative switch table with register to switch on
+        ;//
+        ;// $v = the register to switch on
+        ;// $s = if specified must be "L" to indicate long
+        ;//      this allows a greater range to the case code
+        MACRO
+        M_SWITCH $v, $s
+        ASSERT "$s"="":LOR:"$s"="L"
+_SwLong SETL {FALSE}
+        IF "$s"="L"
+_SwLong     SETL {TRUE}
+        ENDIF
+_SwNum  SETA _SwNum+1        
+        IF {CONFIG}=16
+            ;// Thumb
+            IF _SwLong
+                TBH [pc, $v, LSL#1]
+            ELSE
+                TBB [pc, $v]
+            ENDIF
+_Switch$_SwNum
+        ELSE
+            ;// ARM
+            ADD pc, pc, $v, LSL #2
+            NOP
+        ENDIF
+        MEND
+        
+        ;// Add a case to the switch statement
+        MACRO
+        M_CASE  $label
+        IF {CONFIG}=16
+            ;// Thumb
+            IF _SwLong
+                DCW ($label - _Switch$_SwNum)/2
+            ELSE
+                DCB ($label - _Switch$_SwNum)/2
+            ENDIF
+        ELSE
+            ;// ARM
+            B   $label
+        ENDIF
+        MEND
+        
+        ;// End of switch statement
+        MACRO
+        M_ENDSWITCH
+        ALIGN 2
+        MEND       
+
+
+;////////////////////////////////////////////////////////
+;// Data area allocation
+;////////////////////////////////////////////////////////
+
+        ;// Constant table allocator macro
+        ;//
+        ;// Creates a new section for each constant table
+        ;// $name is symbol through which the table can be accessed.
+        ;// $align is the optional alignment of the table, log2 of 
+        ;//  the byte alignment - $align=4 is 16 byte aligned
+        MACRO
+        M_TABLE  $name, $align
+        ASSERT :LNOT:_InFunc
+        IF "$align"=""
+            AREA |.constdata|, READONLY, DATA
+        ELSE
+            ;// AREAs inherit the alignment of the first declaration.
+            ;// Therefore for each alignment size we must have an area
+            ;// of a different name.
+            AREA constdata_a$align, READONLY, DATA, ALIGN=$align
+            
+            ;// We also force alignment incase we are tagging onto
+            ;// an already started area.
+            ALIGN (1<<$align)
+        ENDIF
+$name
+        MEND
+        
+;/////////////////////////////////////////////////////
+;// Macros to allocate space on the stack
+;//
+;// These all assume that the stack is 8-byte aligned
+;// at entry to the function, which means that the 
+;// 32-byte alignment macro needs to work in a
+;// bit more of a special way...
+;/////////////////////////////////////////////////////
+
+        
+
+
+        ;// Allocate 1-byte aligned area of name
+        ;// $name size $size bytes.
+        MACRO
+        M_ALLOC1  $name, $size
+        ASSERT :LNOT:_InFunc
+$name$_F   EQU _SBytes
+_SBytes SETA _SBytes + ($size)
+        MEND
+            
+        ;// Allocate 2-byte aligned area of name
+        ;// $name size $size bytes.
+        MACRO
+        M_ALLOC2  $name, $size
+        ASSERT :LNOT:_InFunc
+        IF (_SBytes:AND:1)!=0
+_SBytes     SETA _SBytes + (2 - (_SBytes:AND:1))
+        ENDIF
+$name$_F   EQU _SBytes
+_SBytes SETA _SBytes + ($size)
+        MEND
+            
+        ;// Allocate 4-byte aligned area of name
+        ;// $name size $size bytes.
+        MACRO
+        M_ALLOC4  $name, $size
+        ASSERT :LNOT:_InFunc
+        IF (_SBytes:AND:3)!=0
+_SBytes     SETA _SBytes + (4 - (_SBytes:AND:3))
+        ENDIF
+$name$_F   EQU _SBytes
+_SBytes SETA _SBytes + ($size)
+        MEND
+            
+        ;// Allocate 8-byte aligned area of name
+        ;// $name size $size bytes.
+        MACRO
+        M_ALLOC8  $name, $size
+        ASSERT :LNOT:_InFunc
+        IF (_SBytes:AND:7)!=0
+_SBytes     SETA _SBytes + (8 - (_SBytes:AND:7))
+        ENDIF
+$name$_F   EQU _SBytes
+_SBytes SETA _SBytes + ($size)
+        MEND        
+
+        
+        ;// Allocate 8-byte aligned area of name
+        ;// $name size ($size+16) bytes.
+        ;// The extra 16 bytes are later used to align the pointer to 16 bytes
+        
+        MACRO
+        M_ALLOC16  $name, $size
+        ASSERT :LNOT:_InFunc
+        IF (_SBytes:AND:7)!=0
+_SBytes     SETA _SBytes + (8 - (_SBytes:AND:7))
+        ENDIF
+$name$_F$_16   EQU (_SBytes + 8)
+_SBytes SETA _SBytes + ($size) + 8
+        MEND        
+        
+        ;// Allocate 8-byte aligned area of name
+        ;// $name size ($size+32) bytes.
+        ;// The extra 32 bytes are later used to align the pointer to 32 bytes
+        
+        MACRO
+        M_ALLOC32  $name, $size
+        ASSERT :LNOT:_InFunc
+        IF (_SBytes:AND:7)!=0
+_SBytes     SETA _SBytes + (8 - (_SBytes:AND:7))
+        ENDIF
+$name$_F$_32   EQU (_SBytes + 24)
+_SBytes SETA _SBytes + ($size) + 24
+        MEND        
+        
+        
+        
+        
+        ;// Argument Declaration Macro
+        ;//
+        ;// Allocate an argument name $name
+        ;// size $size bytes
+        MACRO
+        M_ARG     $name, $size
+        ASSERT _InFunc
+$name$_F    EQU _ABytes
+_ABytes SETA _ABytes + ($size)
+        MEND        
+        
+;///////////////////////////////////////////////
+;// Macros to access stacked variables
+;///////////////////////////////////////////////
+
+        ;// Macro to perform a data processing operation
+        ;// with a constant second operand
+        MACRO
+        _M_OPC $op,$rd,$rn,$const
+        LCLA    _sh
+        LCLA    _cst
+_sh     SETA    0
+_cst    SETA    $const
+        IF _cst=0
+        $op $rd, $rn, #_cst
+            MEXIT
+        ENDIF
+        WHILE (_cst:AND:3)=0
+_cst        SETA _cst>>2
+_sh         SETA _sh+2
+        WEND
+        $op $rd, $rn, #(_cst:AND:0x000000FF)<<_sh
+        IF _cst>=256
+            $op $rd, $rd, #(_cst:AND:0xFFFFFF00)<<_sh
+        ENDIF
+        MEND
+
+        ;// Macro to perform a data access operation
+        ;// Such as LDR or STR
+        ;// The addressing mode is modified such that
+        ;// 1. If no address is given then the name is taken
+        ;//    as a stack offset
+        ;// 2. If the addressing mode is not available for the
+        ;//    state being assembled for (eg Thumb) then a suitable
+        ;//    addressing mode is substituted.
+        ;//
+        ;// On Entry:
+        ;// $i = Instruction to perform (eg "LDRB")
+        ;// $a = Required byte alignment
+        ;// $r = Register(s) to transfer (eg "r1")
+        ;// $a0,$a1,$a2. Addressing mode and condition. One of:
+        ;//     label {,cc}
+        ;//     [base]                    {,,,cc}
+        ;//     [base, offset]{!}         {,,cc}
+        ;//     [base, offset, shift]{!}  {,cc}
+        ;//     [base], offset            {,,cc}
+        ;//     [base], offset, shift     {,cc}
+        MACRO
+        _M_DATA $i,$a,$r,$a0,$a1,$a2,$a3
+        IF "$a0":LEFT:1="["
+            IF "$a1"=""
+                $i$a3   $r, $a0
+            ELSE
+                IF "$a0":RIGHT:1="]"
+                    IF "$a2"=""
+                        _M_POSTIND $i$a3, "$r", $a0, $a1
+                    ELSE
+                        _M_POSTIND $i$a3, "$r", $a0, "$a1,$a2"
+                    ENDIF
+                ELSE
+                    IF "$a2"=""
+                        _M_PREIND  $i$a3, "$r", $a0, $a1
+                    ELSE
+                        _M_PREIND  $i$a3, "$r", $a0, "$a1,$a2"
+                    ENDIF
+                ENDIF
+            ENDIF
+        ELSE
+            LCLA    _Offset
+_Offset     SETA    _Workspace + $a0$_F
+            ASSERT  (_Offset:AND:($a-1))=0
+            $i$a1   $r, [sp, #_Offset]
+        ENDIF
+        MEND
+        
+        ;// Handle post indexed load/stores
+        ;// op  reg, [base], offset
+        MACRO
+        _M_POSTIND $i,$r,$a0,$a1
+        LCLS _base
+        LCLS _offset
+        IF {CONFIG}=16 ;// Thumb
+_base       SETS ("$a0":LEFT:(:LEN:"$a0"-1)):RIGHT:(:LEN:"$a0"-2)   ;// remove []
+_offset     SETS "$a1"
+            IF _offset:LEFT:1="+"
+_offset         SETS _offset:RIGHT:(:LEN:_offset-1)
+            ENDIF
+            $i  $r, $a0
+            IF _offset:LEFT:1="-"
+_offset         SETS _offset:RIGHT:(:LEN:_offset-1)
+                SUB $_base, $_base, $_offset
+            ELSE                
+                ADD $_base, $_base, $_offset
+            ENDIF
+        ELSE ;// ARM
+            $i  $r, $a0, $a1
+        ENDIF
+        MEND
+        
+        ;// Handle pre indexed load/store
+        ;// op  reg, [base, offset]{!}
+        MACRO
+        _M_PREIND $i,$r,$a0,$a1
+        LCLS _base
+        LCLS _offset
+        IF ({CONFIG}=16):LAND:(("$a1":RIGHT:2)="]!")
+_base       SETS "$a0":RIGHT:(:LEN:("$a0")-1)
+_offset     SETS "$a1":LEFT:(:LEN:("$a1")-2)
+            $i $r, [$_base, $_offset]
+            ADD $_base, $_base, $_offset
+        ELSE
+            $i  $r, $a0, $a1
+        ENDIF
+        MEND
+
+        ;// Load unsigned byte from stack
+        MACRO
+        M_LDRB  $r,$a0,$a1,$a2,$a3
+        _M_DATA "LDRB",1,$r,$a0,$a1,$a2,$a3
+        MEND
+        
+        ;// Load signed byte from stack
+        MACRO
+        M_LDRSB $r,$a0,$a1,$a2,$a3
+        _M_DATA "LDRSB",1,$r,$a0,$a1,$a2,$a3
+        MEND
+        
+        ;// Store byte to stack
+        MACRO
+        M_STRB  $r,$a0,$a1,$a2,$a3
+        _M_DATA "STRB",1,$r,$a0,$a1,$a2,$a3
+        MEND
+        
+        ;// Load unsigned half word from stack
+        MACRO
+        M_LDRH  $r,$a0,$a1,$a2,$a3
+        _M_DATA "LDRH",2,$r,$a0,$a1,$a2,$a3
+        MEND
+        
+        ;// Load signed half word from stack
+        MACRO
+        M_LDRSH $r,$a0,$a1,$a2,$a3
+        _M_DATA "LDRSH",2,$r,$a0,$a1,$a2,$a3
+        MEND
+        
+        ;// Store half word to stack
+        MACRO
+        M_STRH  $r,$a0,$a1,$a2,$a3
+        _M_DATA "STRH",2,$r,$a0,$a1,$a2,$a3
+        MEND
+
+        ;// Load word from stack
+        MACRO
+        M_LDR   $r,$a0,$a1,$a2,$a3
+        _M_DATA "LDR",4,$r,$a0,$a1,$a2,$a3
+        MEND
+        
+        ;// Store word to stack
+        MACRO
+        M_STR   $r,$a0,$a1,$a2,$a3
+        _M_DATA "STR",4,$r,$a0,$a1,$a2,$a3
+        MEND
+
+        ;// Load double word from stack
+        MACRO
+        M_LDRD  $r0,$r1,$a0,$a1,$a2,$a3
+        _M_DATA "LDRD",8,"$r0,$r1",$a0,$a1,$a2,$a3
+        MEND
+                
+        ;// Store double word to stack
+        MACRO
+        M_STRD  $r0,$r1,$a0,$a1,$a2,$a3
+        _M_DATA "STRD",8,"$r0,$r1",$a0,$a1,$a2,$a3
+        MEND
+        
+        ;// Get absolute address of stack allocated location
+        MACRO
+        M_ADR   $a, $b, $cc
+        _M_OPC  ADD$cc, $a, sp, (_Workspace + $b$_F)
+        MEND
+        
+        ;// Get absolute address of stack allocated location and align the address to 16 bytes
+        MACRO
+        M_ADR16 $a, $b, $cc
+            _M_OPC  ADD$cc, $a, sp, (_Workspace + $b$_F$_16)
+        
+            ;// Now align $a to 16 bytes
+            BIC$cc  $a,$a,#0x0F
+        MEND
+        
+        ;// Get absolute address of stack allocated location and align the address to 32 bytes
+        MACRO
+        M_ADR32 $a, $b, $cc
+            _M_OPC  ADD$cc, $a, sp, (_Workspace + $b$_F$_32)
+        
+            ;// Now align $a to 32 bytes
+            BIC$cc  $a,$a,#0x1F
+        MEND
+
+;//////////////////////////////////////////////////////////
+;// Function header and footer macros
+;//////////////////////////////////////////////////////////      
+        
+        ;// Function Header Macro    
+        ;// Generates the function prologue
+        ;// Note that functions should all be "stack-moves-once"
+        ;// The FNSTART and FNEND macros should be the only places
+        ;// where the stack moves.
+        ;//    
+        ;// $name  = function name
+        ;// $rreg  = ""   don't stack any registers
+        ;//          "lr" stack "lr" only
+        ;//          "rN" stack registers "r4-rN,lr"
+        ;// $dreg  = ""   don't stack any D registers
+        ;//          "dN" stack registers "d8-dN"
+        ;//
+        ;// Note: ARM Archicture procedure call standard AAPCS
+        ;// states that r4-r11, sp, d8-d15 must be preserved by
+        ;// a compliant function.
+        MACRO
+        M_START $name, $rreg, $dreg
+        ASSERT :LNOT:_InFunc
+        ASSERT "$name"!=""
+_InFunc SETL {TRUE}
+_RBytes SETA 0
+_Workspace SETA 0
+
+        ;// Create an area for the function        
+        AREA    |.text|, CODE
+        EXPORT  $name
+$name   FUNCTION
+        
+        ;// Save R registers
+        _M_GETRREGLIST $rreg
+        IF _RRegList<>""
+            STMFD   sp!, {$_RRegList, lr}
+        ENDIF
+                
+        ;// Save D registers
+        _M_GETDREGLIST  $dreg        
+        IF _DRegList<>""
+            VSTMFD  sp!, {$_DRegList}
+        ENDIF            
+            
+                    
+        ;// Ensure size claimed on stack is 8-byte aligned
+        IF ((_SBytes:AND:7)!=0)
+_SBytes     SETA _SBytes + (8 - (_SBytes:AND:7))
+        ENDIF
+        
+        IF (_SBytes!=0)
+            _M_OPC SUB, sp, sp, _SBytes
+        ENDIF
+        
+        
+_ABytes SETA _SBytes + _RBytes - _Workspace
+
+                        
+        ;// Print function name if debug enabled
+        M_PRINTF "$name\n",
+        MEND
+        
+        ;// Work out a list of R saved registers
+        MACRO
+        _M_GETRREGLIST $rreg
+        IF "$rreg"=""
+_RRegList   SETS ""
+            MEXIT
+        ENDIF        
+        IF "$rreg"="lr":LOR:"$rreg"="r4"
+_RRegList   SETS "r4"
+_RBytes     SETA _RBytes+8
+            MEXIT
+        ENDIF
+        IF "$rreg"="r5":LOR:"$rreg"="r6"
+_RRegList   SETS "r4-r6"
+_RBytes     SETA _RBytes+16
+            MEXIT
+        ENDIF
+        IF "$rreg"="r7":LOR:"$rreg"="r8"
+_RRegList   SETS "r4-r8"
+_RBytes     SETA _RBytes+24
+            MEXIT
+        ENDIF
+        IF "$rreg"="r9":LOR:"$rreg"="r10"
+_RRegList   SETS "r4-r10"
+_RBytes     SETA _RBytes+32
+            MEXIT
+        ENDIF
+        IF "$rreg"="r11":LOR:"$rreg"="r12"
+_RRegList   SETS "r4-r12"
+_RBytes     SETA _RBytes+40
+            MEXIT
+        ENDIF
+        INFO 1, "Unrecognized saved r register limit '$rreg'"
+        MEND        
+        
+        ;// Work out a list of D saved registers
+        MACRO
+        _M_GETDREGLIST $dreg
+        IF "$dreg"=""
+_DRegList   SETS ""
+            MEXIT
+        ENDIF        
+        IF "$dreg"="d8"
+_DRegList   SETS "d8"
+_RBytes     SETA _RBytes+8
+            MEXIT
+        ENDIF
+        IF "$dreg"="d9"
+_DRegList   SETS "d8-d9"
+_RBytes     SETA _RBytes+16
+            MEXIT
+        ENDIF
+        IF "$dreg"="d10"
+_DRegList   SETS "d8-d10"
+_RBytes     SETA _RBytes+24
+            MEXIT
+        ENDIF
+        IF "$dreg"="d11"
+_DRegList   SETS "d8-d11"
+_RBytes     SETA _RBytes+32
+            MEXIT
+        ENDIF
+        IF "$dreg"="d12"
+_DRegList   SETS "d8-d12"
+_RBytes     SETA _RBytes+40
+            MEXIT
+        ENDIF
+        IF "$dreg"="d13"
+_DRegList   SETS "d8-d13"
+_RBytes     SETA _RBytes+48
+            MEXIT
+        ENDIF
+        IF "$dreg"="d14"
+_DRegList   SETS "d8-d14"
+_RBytes     SETA _RBytes+56
+            MEXIT
+        ENDIF
+        IF "$dreg"="d15"
+_DRegList   SETS "d8-d15"
+_RBytes     SETA _RBytes+64
+            MEXIT
+        ENDIF
+        INFO 1, "Unrecognized saved d register limit '$dreg'"
+        MEND
+        
+        ;// Produce function return instructions
+        MACRO
+        _M_RET $cc
+        IF _DRegList<>""
+            VPOP$cc {$_DRegList}
+        ENDIF
+        IF _RRegList=""
+            BX$cc lr
+        ELSE
+            LDM$cc.FD sp!, {$_RRegList, pc}
+        ENDIF
+        MEND        
+        
+        ;// Early Function Exit Macro
+        ;// $cc = condition to exit with
+        ;// (Example: M_EXIT EQ)
+        MACRO
+        M_EXIT  $cc
+        ASSERT  _InFunc
+        IF  _SBytes!=0
+            ;// Restore stack frame and exit
+            B$cc  _End$_F
+        ELSE
+            ;// Can return directly
+            _M_RET $cc
+        ENDIF        
+        MEND        
+
+        ;// Function Footer Macro        
+        ;// Generates the function epilogue
+        MACRO
+        M_END
+        ASSERT _InFunc
+_InFunc SETL {FALSE}
+_End$_F
+
+        ;// Restore the stack pointer to its original value on function entry
+        IF _SBytes!=0
+            _M_OPC ADD, sp, sp, _SBytes
+        ENDIF
+        _M_RET
+        ENDFUNC
+
+        ;// Reset the global stack tracking variables back to their 
+        ;// initial values, and increment the function count
+_SBytes        SETA 0
+_F             SETA _F+1
+        MEND
+
+                
+;//==========================================================================
+;// Debug Macros
+;//==========================================================================
+
+        GBLL    DEBUG_ON
+DEBUG_ON SETL   {FALSE}
+        GBLL    DEBUG_STALLS_ON
+DEBUG_STALLS_ON SETL {FALSE}
+        
+        ;//==========================================================================
+        ;// Debug call to printf
+        ;//  M_PRINTF $format, $val0, $val1, $val2
+        ;//
+        ;// Examples:
+        ;//  M_PRINTF "x=%08x\n", r0
+        ;//
+        ;// This macro preserves the value of all registers including the
+        ;// flags.
+        ;//==========================================================================
+
+        MACRO
+        M_PRINTF  $format, $val0, $val1, $val2
+        IF DEBUG_ON
+        
+        IMPORT  printf
+        LCLA    nArgs
+nArgs	SETA    0
+        
+        ;// save registers so we don't corrupt them
+        STMFD   sp!, {r0-r12, lr}
+        
+        ;// Drop stack to give us some workspace
+        SUB     sp, sp, #16
+        
+        ;// Save registers we need to print to the stack
+        IF "$val2" <> ""
+            ASSERT "$val1" <> ""
+            STR    $val2, [sp, #8]
+nArgs       SETA   nArgs+1
+        ENDIF
+        IF "$val1" <> ""
+            ASSERT "$val0" <> ""
+            STR    $val1, [sp, #4]
+nArgs	    SETA   nArgs+1
+        ENDIF
+        IF "$val0"<>""
+            STR    $val0, [sp]
+nArgs	    SETA   nArgs+1
+        ENDIF
+        
+        ;// Now we are safe to corrupt registers
+        ADR     r0, %FT00
+        IF nArgs=1
+          LDR   r1, [sp]
+        ENDIF
+        IF nArgs=2
+          LDMIA sp, {r1,r2}
+        ENDIF
+        IF nArgs=3
+          LDMIA sp, {r1,r2,r3}
+        ENDIF
+        
+        ;// print the values
+        MRS     r4, cpsr        ;// preserve flags
+        BL      printf
+        MSR     cpsr_f, r4      ;// restore flags
+        B       %FT01
+00      ;// string to print
+        DCB     "$format", 0
+        ALIGN
+01      ;// Finished
+        ADD     sp, sp, #16
+        ;// Restore registers
+        LDMFD	sp!, {r0-r12,lr}
+
+        ENDIF   ;// DEBUG_ON
+        MEND
+
+
+        ;// Stall Simulation Macro
+        ;// Inserts a given number of NOPs for the currently
+        ;//  defined platform
+        MACRO
+        M_STALL $plat1stall, $plat2stall, $plat3stall, $plat4stall, $plat5stall, $plat6stall
+        IF DEBUG_STALLS_ON
+            _M_STALL_SUB $plat1stall    
+            _M_STALL_SUB $plat2stall    
+            _M_STALL_SUB $plat3stall    
+            _M_STALL_SUB $plat4stall    
+            _M_STALL_SUB $plat5stall    
+            _M_STALL_SUB $plat6stall    
+        ENDIF
+        MEND
+        
+        MACRO
+        _M_STALL_SUB $platstall
+        IF "$platstall"!=""
+            LCLA _pllen
+            LCLS _pl
+            LCLL _pllog
+_pllen      SETA :LEN:"$platstall"
+_pl         SETS "$platstall":LEFT:(_pllen - 2)
+            IF :DEF:$_pl
+                IF $_pl
+                    LCLS _st
+                    LCLA _stnum
+_st                 SETS "$platstall":RIGHT:1        
+_stnum              SETA $_st
+                    WHILE _stnum>0
+			MOV sp, sp
+_stnum                  SETA _stnum - 1
+                    WEND
+                ENDIF
+            ENDIF
+        ENDIF
+        MEND
+        
+        
+        
+;//==========================================================================
+;// Endian Invarience Macros
+;// 
+;// The idea behind these macros is that if an array is
+;// loaded as words then the SMUL00 macro will multiply
+;// array elements 0 regardless of the endianess of the
+;// system. For little endian SMUL00=SMULBB, for big
+;// endian SMUL00=SMULTT and similarly for other packed operations.
+;//
+;//==========================================================================
+
+        MACRO
+        LIBI4   $comli, $combi, $a, $b, $c, $d, $cc
+        IF {ENDIAN}="big"
+        $combi.$cc $a, $b, $c, $d
+        ELSE
+        $comli.$cc $a, $b, $c, $d
+        ENDIF
+        MEND
+        
+        MACRO
+        LIBI3   $comli, $combi, $a, $b, $c, $cc
+        IF {ENDIAN}="big"
+        $combi.$cc $a, $b, $c
+        ELSE
+        $comli.$cc $a, $b, $c
+        ENDIF
+        MEND
+        
+        ;// SMLAxy macros
+        
+        MACRO
+        SMLA00  $a, $b, $c, $d, $cc
+        LIBI4 SMLABB, SMLATT, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLA01  $a, $b, $c, $d, $cc
+        LIBI4 SMLABT, SMLATB, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLA0B  $a, $b, $c, $d, $cc
+        LIBI4 SMLABB, SMLATB, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLA0T  $a, $b, $c, $d, $cc
+        LIBI4 SMLABT, SMLATT, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLA10  $a, $b, $c, $d, $cc
+        LIBI4 SMLATB, SMLABT, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLA11  $a, $b, $c, $d, $cc
+        LIBI4 SMLATT, SMLABB, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLA1B  $a, $b, $c, $d, $cc
+        LIBI4 SMLATB, SMLABB, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLA1T  $a, $b, $c, $d, $cc
+        LIBI4 SMLATT, SMLABT, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLAB0  $a, $b, $c, $d, $cc
+        LIBI4 SMLABB, SMLABT, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLAB1  $a, $b, $c, $d, $cc
+        LIBI4 SMLABT, SMLABB, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLAT0  $a, $b, $c, $d, $cc
+        LIBI4 SMLATB, SMLATT, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLAT1  $a, $b, $c, $d, $cc
+        LIBI4 SMLATT, SMLATB, $a, $b, $c, $d, $cc
+        MEND
+        
+        ;// SMULxy macros
+        
+        MACRO
+        SMUL00  $a, $b, $c, $cc
+        LIBI3 SMULBB, SMULTT, $a, $b, $c, $cc
+        MEND
+        
+        MACRO
+        SMUL01  $a, $b, $c, $cc
+        LIBI3 SMULBT, SMULTB, $a, $b, $c, $cc
+        MEND
+        
+        MACRO
+        SMUL0B  $a, $b, $c, $cc
+        LIBI3 SMULBB, SMULTB, $a, $b, $c, $cc
+        MEND
+        
+        MACRO
+        SMUL0T  $a, $b, $c, $cc
+        LIBI3 SMULBT, SMULTT, $a, $b, $c, $cc
+        MEND
+        
+        MACRO
+        SMUL10  $a, $b, $c, $cc
+        LIBI3 SMULTB, SMULBT, $a, $b, $c, $cc
+        MEND
+        
+        MACRO
+        SMUL11  $a, $b, $c, $cc
+        LIBI3 SMULTT, SMULBB, $a, $b, $c, $cc
+        MEND
+        
+        MACRO
+        SMUL1B  $a, $b, $c, $cc
+        LIBI3 SMULTB, SMULBB, $a, $b, $c, $cc
+        MEND
+        
+        MACRO
+        SMUL1T  $a, $b, $c, $cc
+        LIBI3 SMULTT, SMULBT, $a, $b, $c, $cc
+        MEND
+        
+        MACRO
+        SMULB0  $a, $b, $c, $cc
+        LIBI3 SMULBB, SMULBT, $a, $b, $c, $cc
+        MEND
+        
+        MACRO
+        SMULB1  $a, $b, $c, $cc
+        LIBI3 SMULBT, SMULBB, $a, $b, $c, $cc
+        MEND
+        
+        MACRO
+        SMULT0  $a, $b, $c, $cc
+        LIBI3 SMULTB, SMULTT, $a, $b, $c, $cc
+        MEND
+        
+        MACRO
+        SMULT1  $a, $b, $c, $cc
+        LIBI3 SMULTT, SMULTB, $a, $b, $c, $cc
+        MEND
+        
+        ;// SMLAWx, SMULWx macros
+        
+        MACRO
+        SMLAW0  $a, $b, $c, $d, $cc
+        LIBI4 SMLAWB, SMLAWT, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLAW1  $a, $b, $c, $d, $cc
+        LIBI4 SMLAWT, SMLAWB, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMULW0  $a, $b, $c, $cc
+        LIBI3 SMULWB, SMULWT, $a, $b, $c, $cc
+        MEND
+        
+        MACRO
+        SMULW1  $a, $b, $c, $cc
+        LIBI3 SMULWT, SMULWB, $a, $b, $c, $cc
+        MEND
+
+        ;// SMLALxy macros
+
+
+        MACRO
+        SMLAL00  $a, $b, $c, $d, $cc
+        LIBI4 SMLALBB, SMLALTT, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLAL01  $a, $b, $c, $d, $cc
+        LIBI4 SMLALBT, SMLALTB, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLAL0B  $a, $b, $c, $d, $cc
+        LIBI4 SMLALBB, SMLALTB, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLAL0T  $a, $b, $c, $d, $cc
+        LIBI4 SMLALBT, SMLALTT, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLAL10  $a, $b, $c, $d, $cc
+        LIBI4 SMLALTB, SMLALBT, $a, $b, $c, $d, $cc
+        MEND
+
+        MACRO
+        SMLAL11  $a, $b, $c, $d, $cc
+        LIBI4 SMLALTT, SMLALBB, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLAL1B  $a, $b, $c, $d, $cc
+        LIBI4 SMLALTB, SMLALBB, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLAL1T  $a, $b, $c, $d, $cc
+        LIBI4 SMLALTT, SMLALBT, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLALB0  $a, $b, $c, $d, $cc
+        LIBI4 SMLALBB, SMLALBT, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLALB1  $a, $b, $c, $d, $cc
+        LIBI4 SMLALBT, SMLALBB, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLALT0  $a, $b, $c, $d, $cc
+        LIBI4 SMLALTB, SMLALTT, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLALT1  $a, $b, $c, $d, $cc
+        LIBI4 SMLALTT, SMLALTB, $a, $b, $c, $d, $cc
+        MEND
+        
+  ENDIF ;// ARMCOMM_S_H
+            
+  END
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/api/armOMX.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/api/armOMX.h
new file mode 100644
index 0000000..f629f72
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/api/armOMX.h
@@ -0,0 +1,274 @@
+/* 
+ * 
+ * File Name:  armOMX_ReleaseVersion.h
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * This file allows a version of the OMX DL libraries to be built where some or
+ * all of the function names can be given a user specified suffix. 
+ *
+ * You might want to use it where:
+ *
+ * - you want to rename a function "out of the way" so that you could replace
+ *   a function with a different version (the original version would still be
+ *   in the library just with a different name - so you could debug the new
+ *   version by comparing it to the output of the old)
+ *
+ * - you want to rename all the functions to versions with a suffix so that 
+ *   you can include two versions of the library and choose between functions
+ *   at runtime.
+ *
+ *     e.g. omxIPBM_Copy_U8_C1R could be renamed omxIPBM_Copy_U8_C1R_CortexA8
+ * 
+ */
+
+  
+#ifndef _armOMX_H_
+#define _armOMX_H_
+
+
+/* We need to define these two macros in order to expand and concatenate the names */
+#define OMXCAT2BAR(A, B) omx ## A ## B
+#define OMXCATBAR(A, B) OMXCAT2BAR(A, B)
+
+/* Define the suffix to add to all functions - the default is no suffix */
+#define BARE_SUFFIX 
+
+
+
+/* Define what happens to the bare suffix-less functions, down to the sub-domain accuracy */
+#define OMXACAAC_SUFFIX    BARE_SUFFIX   
+#define OMXACMP3_SUFFIX    BARE_SUFFIX
+#define OMXICJP_SUFFIX     BARE_SUFFIX
+#define OMXIPBM_SUFFIX     BARE_SUFFIX
+#define OMXIPCS_SUFFIX     BARE_SUFFIX
+#define OMXIPPP_SUFFIX     BARE_SUFFIX
+#define OMXSP_SUFFIX       BARE_SUFFIX
+#define OMXVCCOMM_SUFFIX   BARE_SUFFIX
+#define OMXVCM4P10_SUFFIX  BARE_SUFFIX
+#define OMXVCM4P2_SUFFIX   BARE_SUFFIX
+
+
+
+
+/* Define what the each bare, un-suffixed OpenMAX API function names is to be renamed */
+#define omxACAAC_DecodeChanPairElt                        OMXCATBAR(ACAAC_DecodeChanPairElt, OMXACAAC_SUFFIX)
+#define omxACAAC_DecodeDatStrElt                          OMXCATBAR(ACAAC_DecodeDatStrElt, OMXACAAC_SUFFIX)
+#define omxACAAC_DecodeFillElt                            OMXCATBAR(ACAAC_DecodeFillElt, OMXACAAC_SUFFIX)
+#define omxACAAC_DecodeIsStereo_S32                       OMXCATBAR(ACAAC_DecodeIsStereo_S32, OMXACAAC_SUFFIX)
+#define omxACAAC_DecodeMsPNS_S32_I                        OMXCATBAR(ACAAC_DecodeMsPNS_S32_I, OMXACAAC_SUFFIX)
+#define omxACAAC_DecodeMsStereo_S32_I                     OMXCATBAR(ACAAC_DecodeMsStereo_S32_I, OMXACAAC_SUFFIX)
+#define omxACAAC_DecodePrgCfgElt                          OMXCATBAR(ACAAC_DecodePrgCfgElt, OMXACAAC_SUFFIX)
+#define omxACAAC_DecodeTNS_S32_I                          OMXCATBAR(ACAAC_DecodeTNS_S32_I, OMXACAAC_SUFFIX)
+#define omxACAAC_DeinterleaveSpectrum_S32                 OMXCATBAR(ACAAC_DeinterleaveSpectrum_S32, OMXACAAC_SUFFIX)
+#define omxACAAC_EncodeTNS_S32_I                          OMXCATBAR(ACAAC_EncodeTNS_S32_I, OMXACAAC_SUFFIX)
+#define omxACAAC_LongTermPredict_S32                      OMXCATBAR(ACAAC_LongTermPredict_S32, OMXACAAC_SUFFIX)
+#define omxACAAC_LongTermReconstruct_S32_I                OMXCATBAR(ACAAC_LongTermReconstruct_S32_I, OMXACAAC_SUFFIX)
+#define omxACAAC_MDCTFwd_S32                              OMXCATBAR(ACAAC_MDCTFwd_S32, OMXACAAC_SUFFIX)
+#define omxACAAC_MDCTInv_S32_S16                          OMXCATBAR(ACAAC_MDCTInv_S32_S16, OMXACAAC_SUFFIX)
+#define omxACAAC_NoiselessDecode                          OMXCATBAR(ACAAC_NoiselessDecode, OMXACAAC_SUFFIX)
+#define omxACAAC_QuantInv_S32_I                           OMXCATBAR(ACAAC_QuantInv_S32_I, OMXACAAC_SUFFIX)
+#define omxACAAC_UnpackADIFHeader                         OMXCATBAR(ACAAC_UnpackADIFHeader, OMXACAAC_SUFFIX)
+#define omxACAAC_UnpackADTSFrameHeader                    OMXCATBAR(ACAAC_UnpackADTSFrameHeader, OMXACAAC_SUFFIX)
+
+
+#define omxACMP3_HuffmanDecode_S32                        OMXCATBAR(ACMP3_HuffmanDecode_S32, OMXACMP3_SUFFIX)
+#define omxACMP3_HuffmanDecodeSfb_S32                     OMXCATBAR(ACMP3_HuffmanDecodeSfb_S32, OMXACMP3_SUFFIX)
+#define omxACMP3_HuffmanDecodeSfbMbp_S32                  OMXCATBAR(ACMP3_HuffmanDecodeSfbMbp_S32, OMXACMP3_SUFFIX)
+#define omxACMP3_MDCTInv_S32                              OMXCATBAR(ACMP3_MDCTInv_S32, OMXACMP3_SUFFIX)
+#define omxACMP3_ReQuantize_S32_I                         OMXCATBAR(ACMP3_ReQuantize_S32_I, OMXACMP3_SUFFIX)
+#define omxACMP3_ReQuantizeSfb_S32_I                      OMXCATBAR(ACMP3_ReQuantizeSfb_S32_I, OMXACMP3_SUFFIX)
+#define omxACMP3_SynthPQMF_S32_S16                        OMXCATBAR(ACMP3_SynthPQMF_S32_S16, OMXACMP3_SUFFIX)
+#define omxACMP3_UnpackFrameHeader                        OMXCATBAR(ACMP3_UnpackFrameHeader, OMXACMP3_SUFFIX)
+#define omxACMP3_UnpackScaleFactors_S8                    OMXCATBAR(ACMP3_UnpackScaleFactors_S8, OMXACMP3_SUFFIX)
+#define omxACMP3_UnpackSideInfo                           OMXCATBAR(ACMP3_UnpackSideInfo, OMXACMP3_SUFFIX)
+
+#define omxICJP_CopyExpand_U8_C3                          OMXCATBAR(ICJP_CopyExpand_U8_C3, OMXICJP_SUFFIX)
+#define omxICJP_DCTFwd_S16                                OMXCATBAR(ICJP_DCTFwd_S16, OMXICJP_SUFFIX)
+#define omxICJP_DCTFwd_S16_I                              OMXCATBAR(ICJP_DCTFwd_S16_I, OMXICJP_SUFFIX)
+#define omxICJP_DCTInv_S16                                OMXCATBAR(ICJP_DCTInv_S16, OMXICJP_SUFFIX)
+#define omxICJP_DCTInv_S16_I                              OMXCATBAR(ICJP_DCTInv_S16_I, OMXICJP_SUFFIX)
+#define omxICJP_DCTQuantFwd_Multiple_S16                  OMXCATBAR(ICJP_DCTQuantFwd_Multiple_S16, OMXICJP_SUFFIX)
+#define omxICJP_DCTQuantFwd_S16                           OMXCATBAR(ICJP_DCTQuantFwd_S16, OMXICJP_SUFFIX)
+#define omxICJP_DCTQuantFwd_S16_I                         OMXCATBAR(ICJP_DCTQuantFwd_S16_I, OMXICJP_SUFFIX)
+#define omxICJP_DCTQuantFwdTableInit                      OMXCATBAR(ICJP_DCTQuantFwdTableInit, OMXICJP_SUFFIX)
+#define omxICJP_DCTQuantInv_Multiple_S16                  OMXCATBAR(ICJP_DCTQuantInv_Multiple_S16, OMXICJP_SUFFIX)
+#define omxICJP_DCTQuantInv_S16                           OMXCATBAR(ICJP_DCTQuantInv_S16, OMXICJP_SUFFIX)
+#define omxICJP_DCTQuantInv_S16_I                         OMXCATBAR(ICJP_DCTQuantInv_S16_I, OMXICJP_SUFFIX)
+#define omxICJP_DCTQuantInvTableInit                      OMXCATBAR(ICJP_DCTQuantInvTableInit, OMXICJP_SUFFIX)
+#define omxICJP_DecodeHuffman8x8_Direct_S16_C1            OMXCATBAR(ICJP_DecodeHuffman8x8_Direct_S16_C1, OMXICJP_SUFFIX)
+#define omxICJP_DecodeHuffmanSpecGetBufSize_U8            OMXCATBAR(ICJP_DecodeHuffmanSpecGetBufSize_U8, OMXICJP_SUFFIX)
+#define omxICJP_DecodeHuffmanSpecInit_U8                  OMXCATBAR(ICJP_DecodeHuffmanSpecInit_U8, OMXICJP_SUFFIX)
+#define omxICJP_EncodeHuffman8x8_Direct_S16_U1_C1         OMXCATBAR(ICJP_EncodeHuffman8x8_Direct_S16_U1_C1, OMXICJP_SUFFIX)
+#define omxICJP_EncodeHuffmanSpecGetBufSize_U8            OMXCATBAR(ICJP_EncodeHuffmanSpecGetBufSize_U8, OMXICJP_SUFFIX)
+#define omxICJP_EncodeHuffmanSpecInit_U8                  OMXCATBAR(ICJP_EncodeHuffmanSpecInit_U8, OMXICJP_SUFFIX)
+
+#define omxIPBM_AddC_U8_C1R_Sfs                           OMXCATBAR(IPBM_AddC_U8_C1R_Sfs, OMXIPBM_SUFFIX)
+#define omxIPBM_Copy_U8_C1R                               OMXCATBAR(IPBM_Copy_U8_C1R, OMXIPBM_SUFFIX)
+#define omxIPBM_Copy_U8_C3R                               OMXCATBAR(IPBM_Copy_U8_C3R, OMXIPBM_SUFFIX)
+#define omxIPBM_Mirror_U8_C1R                             OMXCATBAR(IPBM_Mirror_U8_C1R, OMXIPBM_SUFFIX)
+#define omxIPBM_MulC_U8_C1R_Sfs                           OMXCATBAR(IPBM_MulC_U8_C1R_Sfs, OMXIPBM_SUFFIX)
+
+#define omxIPCS_ColorTwistQ14_U8_C3R                      OMXCATBAR(IPCS_ColorTwistQ14_U8_C3R, OMXIPCS_SUFFIX)
+#define omxIPCS_BGR565ToYCbCr420LS_MCU_U16_S16_C3P3R      OMXCATBAR(IPCS_BGR565ToYCbCr420LS_MCU_U16_S16_C3P3R, OMXIPCS_SUFFIX)
+#define omxIPCS_BGR565ToYCbCr422LS_MCU_U16_S16_C3P3R      OMXCATBAR(IPCS_BGR565ToYCbCr422LS_MCU_U16_S16_C3P3R, OMXIPCS_SUFFIX)
+#define omxIPCS_BGR565ToYCbCr444LS_MCU_U16_S16_C3P3R      OMXCATBAR(IPCS_BGR565ToYCbCr444LS_MCU_U16_S16_C3P3R, OMXIPCS_SUFFIX)
+#define omxIPCS_BGR888ToYCbCr420LS_MCU_U8_S16_C3P3R       OMXCATBAR(IPCS_BGR888ToYCbCr420LS_MCU_U8_S16_C3P3R, OMXIPCS_SUFFIX)
+#define omxIPCS_BGR888ToYCbCr422LS_MCU_U8_S16_C3P3R       OMXCATBAR(IPCS_BGR888ToYCbCr422LS_MCU_U8_S16_C3P3R, OMXIPCS_SUFFIX)
+#define omxIPCS_BGR888ToYCbCr444LS_MCU_U8_S16_C3P3R       OMXCATBAR(IPCS_BGR888ToYCbCr444LS_MCU_U8_S16_C3P3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr420RszCscRotBGR_U8_P3C3R             OMXCATBAR(IPCS_YCbCr420RszCscRotBGR_U8_P3C3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr420RszRot_U8_P3R                     OMXCATBAR(IPCS_YCbCr420RszRot_U8_P3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr420ToBGR565_U8_U16_P3C3R             OMXCATBAR(IPCS_YCbCr420ToBGR565_U8_U16_P3C3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr420ToBGR565LS_MCU_S16_U16_P3C3R      OMXCATBAR(IPCS_YCbCr420ToBGR565LS_MCU_S16_U16_P3C3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr420ToBGR888LS_MCU_S16_U8_P3C3R       OMXCATBAR(IPCS_YCbCr420ToBGR888LS_MCU_S16_U8_P3C3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr422RszCscRotBGR_U8_P3C3R             OMXCATBAR(IPCS_YCbCr422RszCscRotBGR_U8_P3C3R, OMXIPCS_SUFFIX)
+#define omxIPCS_CbYCrY422RszCscRotBGR_U8_U16_C2R          OMXCATBAR(IPCS_CbYCrY422RszCscRotBGR_U8_U16_C2R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr422RszRot_U8_P3R                     OMXCATBAR(IPCS_YCbCr422RszRot_U8_P3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbYCr422ToBGR565_U8_U16_C2C3R            OMXCATBAR(IPCS_YCbYCr422ToBGR565_U8_U16_C2C3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr422ToBGR565LS_MCU_S16_U16_P3C3R      OMXCATBAR(IPCS_YCbCr422ToBGR565LS_MCU_S16_U16_P3C3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbYCr422ToBGR888_U8_C2C3R                OMXCATBAR(IPCS_YCbYCr422ToBGR888_U8_C2C3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr422ToBGR888LS_MCU_S16_U8_P3C3R       OMXCATBAR(IPCS_YCbCr422ToBGR888LS_MCU_S16_U8_P3C3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr422ToBGR888LS_MCU_S16_U8_P3C3R       OMXCATBAR(IPCS_YCbCr422ToBGR888LS_MCU_S16_U8_P3C3R, OMXIPCS_SUFFIX)
+#define omxIPCS_CbYCrY422ToYCbCr420Rotate_U8_C2P3R        OMXCATBAR(IPCS_CbYCrY422ToYCbCr420Rotate_U8_C2P3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr422ToYCbCr420Rotate_U8_P3R           OMXCATBAR(IPCS_YCbCr422ToYCbCr420Rotate_U8_P3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr444ToBGR565_U8_U16_C3R               OMXCATBAR(IPCS_YCbCr444ToBGR565_U8_U16_C3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr444ToBGR565_U8_U16_P3C3R             OMXCATBAR(IPCS_YCbCr444ToBGR565_U8_U16_P3C3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr444ToBGR565LS_MCU_S16_U16_P3C3R      OMXCATBAR(IPCS_YCbCr444ToBGR565LS_MCU_S16_U16_P3C3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr444ToBGR888_U8_C3R                   OMXCATBAR(IPCS_YCbCr444ToBGR888_U8_C3R, OMXIPCS_SUFFIX)
+
+#define omxIPPP_Deblock_HorEdge_U8_I                      OMXCATBAR(IPPP_Deblock_HorEdge_U8_I, OMXIPPP_SUFFIX)
+#define omxIPPP_Deblock_VerEdge_U8_I                      OMXCATBAR(IPPP_Deblock_VerEdge_U8_I, OMXIPPP_SUFFIX)
+#define omxIPPP_FilterFIR_U8_C1R                          OMXCATBAR(IPPP_FilterFIR_U8_C1R, OMXIPPP_SUFFIX)
+#define omxIPPP_FilterMedian_U8_C1R                       OMXCATBAR(IPPP_FilterMedian_U8_C1R, OMXIPPP_SUFFIX)
+#define omxIPPP_GetCentralMoment_S64                      OMXCATBAR(IPPP_GetCentralMoment_S64, OMXIPPP_SUFFIX)
+#define omxIPPP_GetSpatialMoment_S64                      OMXCATBAR(IPPP_GetSpatialMoment_S64, OMXIPPP_SUFFIX)
+#define omxIPPP_MomentGetStateSize                        OMXCATBAR(IPPP_MomentGetStateSize, OMXIPPP_SUFFIX)
+#define omxIPPP_MomentInit                                OMXCATBAR(IPPP_MomentInit, OMXIPPP_SUFFIX)
+#define omxIPPP_Moments_U8_C1R                            OMXCATBAR(IPPP_Moments_U8_C1R, OMXIPPP_SUFFIX)
+#define omxIPPP_Moments_U8_C3R                            OMXCATBAR(IPPP_Moments_U8_C3R, OMXIPPP_SUFFIX)
+
+#define omxSP_BlockExp_S16                                OMXCATBAR(SP_BlockExp_S16, OMXSP_SUFFIX)
+#define omxSP_BlockExp_S32                                OMXCATBAR(SP_BlockExp_S32, OMXSP_SUFFIX)
+#define omxSP_Copy_S16                                    OMXCATBAR(SP_Copy_S16, OMXSP_SUFFIX)
+#define omxSP_DotProd_S16                                 OMXCATBAR(SP_DotProd_S16, OMXSP_SUFFIX)
+#define omxSP_DotProd_S16_Sfs                             OMXCATBAR(SP_DotProd_S16_Sfs, OMXSP_SUFFIX)
+#define omxSP_FFTFwd_CToC_SC16_Sfs                        OMXCATBAR(SP_FFTFwd_CToC_SC16_Sfs, OMXSP_SUFFIX)
+#define omxSP_FFTFwd_CToC_SC32_Sfs                        OMXCATBAR(SP_FFTFwd_CToC_SC32_Sfs, OMXSP_SUFFIX)
+#define omxSP_FFTFwd_RToCCS_S16S32_Sfs                    OMXCATBAR(SP_FFTFwd_RToCCS_S16S32_Sfs, OMXSP_SUFFIX)
+#define omxSP_FFTFwd_RToCCS_S32_Sfs                       OMXCATBAR(SP_FFTFwd_RToCCS_S32_Sfs, OMXSP_SUFFIX)
+#define omxSP_FFTGetBufSize_C_SC16                        OMXCATBAR(SP_FFTGetBufSize_C_SC16, OMXSP_SUFFIX)
+#define omxSP_FFTGetBufSize_C_SC32                        OMXCATBAR(SP_FFTGetBufSize_C_SC32, OMXSP_SUFFIX)
+#define omxSP_FFTGetBufSize_R_S16S32                      OMXCATBAR(SP_FFTGetBufSize_R_S16S32, OMXSP_SUFFIX)
+#define omxSP_FFTGetBufSize_R_S32                         OMXCATBAR(SP_FFTGetBufSize_R_S32, OMXSP_SUFFIX)
+#define omxSP_FFTInit_C_SC16                              OMXCATBAR(SP_FFTInit_C_SC16, OMXSP_SUFFIX)
+#define omxSP_FFTInit_C_SC32                              OMXCATBAR(SP_FFTInit_C_SC32, OMXSP_SUFFIX)
+#define omxSP_FFTInit_R_S16S32                            OMXCATBAR(SP_FFTInit_R_S16S32, OMXSP_SUFFIX)
+#define omxSP_FFTInit_R_S32                               OMXCATBAR(SP_FFTInit_R_S32, OMXSP_SUFFIX)
+#define omxSP_FFTInv_CCSToR_S32_Sfs                       OMXCATBAR(SP_FFTInv_CCSToR_S32_Sfs, OMXSP_SUFFIX)
+#define omxSP_FFTInv_CCSToR_S32S16_Sfs                    OMXCATBAR(SP_FFTInv_CCSToR_S32S16_Sfs, OMXSP_SUFFIX)
+#define omxSP_FFTInv_CToC_SC16_Sfs                        OMXCATBAR(SP_FFTInv_CToC_SC16_Sfs, OMXSP_SUFFIX)
+#define omxSP_FFTInv_CToC_SC32_Sfs                        OMXCATBAR(SP_FFTInv_CToC_SC32_Sfs, OMXSP_SUFFIX)
+#define omxSP_FilterMedian_S32                            OMXCATBAR(SP_FilterMedian_S32, OMXSP_SUFFIX)
+#define omxSP_FilterMedian_S32_I                          OMXCATBAR(SP_FilterMedian_S32_I, OMXSP_SUFFIX)
+#define omxSP_FIR_Direct_S16                              OMXCATBAR(SP_FIR_Direct_S16, OMXSP_SUFFIX)
+#define omxSP_FIR_Direct_S16_I                            OMXCATBAR(SP_FIR_Direct_S16_I, OMXSP_SUFFIX)
+#define omxSP_FIR_Direct_S16_ISfs                         OMXCATBAR(SP_FIR_Direct_S16_ISfs, OMXSP_SUFFIX)
+#define omxSP_FIR_Direct_S16_Sfs                          OMXCATBAR(SP_FIR_Direct_S16_Sfs, OMXSP_SUFFIX)
+#define omxSP_FIROne_Direct_S16                           OMXCATBAR(SP_FIROne_Direct_S16, OMXSP_SUFFIX)
+#define omxSP_FIROne_Direct_S16_I                         OMXCATBAR(SP_FIROne_Direct_S16_I, OMXSP_SUFFIX)
+#define omxSP_FIROne_Direct_S16_ISfs                      OMXCATBAR(SP_FIROne_Direct_S16_ISfs, OMXSP_SUFFIX)
+#define omxSP_FIROne_Direct_S16_Sfs                       OMXCATBAR(SP_FIROne_Direct_S16_Sfs, OMXSP_SUFFIX)
+#define omxSP_IIR_BiQuadDirect_S16                        OMXCATBAR(SP_IIR_BiQuadDirect_S16, OMXSP_SUFFIX)
+#define omxSP_IIR_BiQuadDirect_S16_I                      OMXCATBAR(SP_IIR_BiQuadDirect_S16_I, OMXSP_SUFFIX)
+#define omxSP_IIR_Direct_S16                              OMXCATBAR(SP_IIR_Direct_S16, OMXSP_SUFFIX)
+#define omxSP_IIR_Direct_S16_I                            OMXCATBAR(SP_IIR_Direct_S16_I, OMXSP_SUFFIX)
+#define omxSP_IIROne_BiQuadDirect_S16                     OMXCATBAR(SP_IIROne_BiQuadDirect_S16, OMXSP_SUFFIX)
+#define omxSP_IIROne_BiQuadDirect_S16_I                   OMXCATBAR(SP_IIROne_BiQuadDirect_S16_I, OMXSP_SUFFIX)
+#define omxSP_IIROne_Direct_S16                           OMXCATBAR(SP_IIROne_Direct_S16, OMXSP_SUFFIX)
+#define omxSP_IIROne_Direct_S16_I                         OMXCATBAR(SP_IIROne_Direct_S16_I, OMXSP_SUFFIX)
+
+#define omxVCCOMM_Average_16x                             OMXCATBAR(VCCOMM_Average_16x, OMXVCCOMM_SUFFIX)
+#define omxVCCOMM_Average_8x                              OMXCATBAR(VCCOMM_Average_8x, OMXVCCOMM_SUFFIX)
+#define omxVCCOMM_ComputeTextureErrorBlock                OMXCATBAR(VCCOMM_ComputeTextureErrorBlock, OMXVCCOMM_SUFFIX)
+#define omxVCCOMM_ComputeTextureErrorBlock_SAD            OMXCATBAR(VCCOMM_ComputeTextureErrorBlock_SAD, OMXVCCOMM_SUFFIX)
+#define omxVCCOMM_Copy16x16                               OMXCATBAR(VCCOMM_Copy16x16, OMXVCCOMM_SUFFIX)
+#define omxVCCOMM_Copy8x8                                 OMXCATBAR(VCCOMM_Copy8x8, OMXVCCOMM_SUFFIX)
+#define omxVCCOMM_ExpandFrame_I                           OMXCATBAR(VCCOMM_ExpandFrame_I, OMXVCCOMM_SUFFIX)
+#define omxVCCOMM_LimitMVToRect                           OMXCATBAR(VCCOMM_LimitMVToRect, OMXVCCOMM_SUFFIX)
+#define omxVCCOMM_SAD_16x                                 OMXCATBAR(VCCOMM_SAD_16x, OMXVCCOMM_SUFFIX)
+#define omxVCCOMM_SAD_8x                                  OMXCATBAR(VCCOMM_SAD_8x, OMXVCCOMM_SUFFIX)
+
+#define omxVCM4P10_Average_4x                             OMXCATBAR(VCM4P10_Average_4x, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_BlockMatch_Half                        OMXCATBAR(VCM4P10_BlockMatch_Half, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_BlockMatch_Integer                     OMXCATBAR(VCM4P10_BlockMatch_Integer, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_BlockMatch_Quarter                     OMXCATBAR(VCM4P10_BlockMatch_Quarter, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_DeblockChroma_I                        OMXCATBAR(VCM4P10_DeblockChroma_I, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_DeblockLuma_I                          OMXCATBAR(VCM4P10_DeblockLuma_I, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_DecodeChromaDcCoeffsToPairCAVLC        OMXCATBAR(VCM4P10_DecodeChromaDcCoeffsToPairCAVLC, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_DecodeCoeffsToPairCAVLC                OMXCATBAR(VCM4P10_DecodeCoeffsToPairCAVLC, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_DequantTransformResidualFromPairAndAdd OMXCATBAR(VCM4P10_DequantTransformResidualFromPairAndAdd, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_FilterDeblockingChroma_HorEdge_I       OMXCATBAR(VCM4P10_FilterDeblockingChroma_HorEdge_I, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_FilterDeblockingChroma_VerEdge_I       OMXCATBAR(VCM4P10_FilterDeblockingChroma_VerEdge_I, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_FilterDeblockingLuma_HorEdge_I         OMXCATBAR(VCM4P10_FilterDeblockingLuma_HorEdge_I, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_FilterDeblockingLuma_VerEdge_I         OMXCATBAR(VCM4P10_FilterDeblockingLuma_VerEdge_I, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_GetVLCInfo                             OMXCATBAR(VCM4P10_GetVLCInfo, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_InterpolateChroma                      OMXCATBAR(VCM4P10_InterpolateChroma, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_InterpolateHalfHor_Luma                OMXCATBAR(VCM4P10_InterpolateHalfHor_Luma, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_InterpolateHalfVer_Luma                OMXCATBAR(VCM4P10_InterpolateHalfVer_Luma, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_InterpolateLuma                        OMXCATBAR(VCM4P10_InterpolateLuma, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_InvTransformDequant_ChromaDC           OMXCATBAR(VCM4P10_InvTransformDequant_ChromaDC, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_InvTransformDequant_LumaDC             OMXCATBAR(VCM4P10_InvTransformDequant_LumaDC, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_InvTransformResidualAndAdd             OMXCATBAR(VCM4P10_InvTransformResidualAndAdd, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_MEGetBufSize                           OMXCATBAR(VCM4P10_MEGetBufSize, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_MEInit                                 OMXCATBAR(VCM4P10_MEInit, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_MotionEstimationMB                     OMXCATBAR(VCM4P10_MotionEstimationMB, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_PredictIntra_16x16                     OMXCATBAR(VCM4P10_PredictIntra_16x16, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_PredictIntra_4x4                       OMXCATBAR(VCM4P10_PredictIntra_4x4, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_PredictIntraChroma_8x8                  OMXCATBAR(VCM4P10_PredictIntraChroma_8x8, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_SAD_4x                                 OMXCATBAR(VCM4P10_SAD_4x, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_SADQuar_16x                            OMXCATBAR(VCM4P10_SADQuar_16x, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_SADQuar_4x                             OMXCATBAR(VCM4P10_SADQuar_4x, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_SADQuar_8x                             OMXCATBAR(VCM4P10_SADQuar_8x, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_SATD_4x4                               OMXCATBAR(VCM4P10_SATD_4x4, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_SubAndTransformQDQResidual             OMXCATBAR(VCM4P10_SubAndTransformQDQResidual, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_TransformDequantChromaDCFromPair       OMXCATBAR(VCM4P10_TransformDequantChromaDCFromPair, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_TransformDequantLumaDCFromPair         OMXCATBAR(VCM4P10_TransformDequantLumaDCFromPair, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_TransformQuant_ChromaDC                OMXCATBAR(VCM4P10_TransformQuant_ChromaDC, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_TransformQuant_LumaDC                  OMXCATBAR(VCM4P10_TransformQuant_LumaDC, OMXVCM4P10_SUFFIX)
+
+#define omxVCM4P2_BlockMatch_Half_16x16                   OMXCATBAR(VCM4P2_BlockMatch_Half_16x16, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_BlockMatch_Half_8x8                     OMXCATBAR(VCM4P2_BlockMatch_Half_8x8, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_BlockMatch_Integer_16x16                OMXCATBAR(VCM4P2_BlockMatch_Integer_16x16, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_BlockMatch_Integer_8x8                  OMXCATBAR(VCM4P2_BlockMatch_Integer_8x8, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_DCT8x8blk                               OMXCATBAR(VCM4P2_DCT8x8blk, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_DecodeBlockCoef_Inter                   OMXCATBAR(VCM4P2_DecodeBlockCoef_Inter, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_DecodeBlockCoef_Intra                   OMXCATBAR(VCM4P2_DecodeBlockCoef_Intra, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_DecodePadMV_PVOP                        OMXCATBAR(VCM4P2_DecodePadMV_PVOP, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_DecodeVLCZigzag_Inter                   OMXCATBAR(VCM4P2_DecodeVLCZigzag_Inter, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_DecodeVLCZigzag_IntraACVLC              OMXCATBAR(VCM4P2_DecodeVLCZigzag_IntraACVLC, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_DecodeVLCZigzag_IntraDCVLC              OMXCATBAR(VCM4P2_DecodeVLCZigzag_IntraDCVLC, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_EncodeMV                                OMXCATBAR(VCM4P2_EncodeMV, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_EncodeVLCZigzag_Inter                   OMXCATBAR(VCM4P2_EncodeVLCZigzag_Inter, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_EncodeVLCZigzag_IntraACVLC              OMXCATBAR(VCM4P2_EncodeVLCZigzag_IntraACVLC, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_EncodeVLCZigzag_IntraDCVLC              OMXCATBAR(VCM4P2_EncodeVLCZigzag_IntraDCVLC, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_FindMVpred                              OMXCATBAR(VCM4P2_FindMVpred, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_IDCT8x8blk                              OMXCATBAR(VCM4P2_IDCT8x8blk, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_MCReconBlock                            OMXCATBAR(VCM4P2_MCReconBlock, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_MEGetBufSize                            OMXCATBAR(VCM4P2_MEGetBufSize, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_MEInit                                  OMXCATBAR(VCM4P2_MEInit, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_MotionEstimationMB                      OMXCATBAR(VCM4P2_MotionEstimationMB, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_PredictReconCoefIntra                   OMXCATBAR(VCM4P2_PredictReconCoefIntra, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_QuantInter_I                            OMXCATBAR(VCM4P2_QuantInter_I, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_QuantIntra_I                            OMXCATBAR(VCM4P2_QuantIntra_I, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_QuantInvInter_I                         OMXCATBAR(VCM4P2_QuantInvInter_I, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_QuantInvIntra_I                         OMXCATBAR(VCM4P2_QuantInvIntra_I, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_TransRecBlockCoef_inter                 OMXCATBAR(VCM4P2_TransRecBlockCoef_inter, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_TransRecBlockCoef_intra                 OMXCATBAR(VCM4P2_TransRecBlockCoef_intra, OMXVCM4P2_SUFFIX)
+
+
+#endif /* _armOMX_h_ */
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/api/omxtypes.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/api/omxtypes.h
new file mode 100644
index 0000000..8b295a6
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/api/omxtypes.h
@@ -0,0 +1,252 @@
+/**
+ * File: omxtypes.h
+ * Brief: Defines basic Data types used in OpenMAX v1.0.2 header files.
+ *
+ * Copyright © 2005-2008 The Khronos Group Inc. All Rights Reserved. 
+ *
+ * These materials are protected by copyright laws and contain material 
+ * proprietary to the Khronos Group, Inc.  You may use these materials 
+ * for implementing Khronos specifications, without altering or removing 
+ * any trademark, copyright or other notice from the specification.
+ * 
+ * Khronos Group makes no, and expressly disclaims any, representations 
+ * or warranties, express or implied, regarding these materials, including, 
+ * without limitation, any implied warranties of merchantability or fitness 
+ * for a particular purpose or non-infringement of any intellectual property. 
+ * Khronos Group makes no, and expressly disclaims any, warranties, express 
+ * or implied, regarding the correctness, accuracy, completeness, timeliness, 
+ * and reliability of these materials. 
+ *
+ * Under no circumstances will the Khronos Group, or any of its Promoters, 
+ * Contributors or Members or their respective partners, officers, directors, 
+ * employees, agents or representatives be liable for any damages, whether 
+ * direct, indirect, special or consequential damages for lost revenues, 
+ * lost profits, or otherwise, arising from or in connection with these 
+ * materials.
+ * 
+ * Khronos and OpenMAX are trademarks of the Khronos Group Inc. 
+ *
+ */
+  
+#ifndef _OMXTYPES_H_
+#define _OMXTYPES_H_
+
+#include <limits.h> 
+
+#define OMX_IN
+#define OMX_OUT
+#define OMX_INOUT
+
+
+typedef enum {
+    
+    /* Mandatory return codes - use cases are explicitly described for each function */
+    OMX_Sts_NoErr                    =  0,    /* No error, the function completed successfully */
+    OMX_Sts_Err                      = -2,    /* Unknown/unspecified error */    
+    OMX_Sts_InvalidBitstreamValErr   = -182,  /* Invalid value detected during bitstream processing */    
+    OMX_Sts_MemAllocErr              = -9,    /* Not enough memory allocated for the operation */
+    OMX_StsACAAC_GainCtrErr    	     = -159,  /* AAC: Unsupported gain control data detected */
+    OMX_StsACAAC_PrgNumErr           = -167,  /* AAC: Invalid number of elements for one program   */
+    OMX_StsACAAC_CoefValErr          = -163,  /* AAC: Invalid quantized coefficient value          */     
+    OMX_StsACAAC_MaxSfbErr           = -162,  /* AAC: Invalid maxSfb value in relation to numSwb */    
+	OMX_StsACAAC_PlsDataErr		     = -160,  /* AAC: pulse escape sequence data error */
+
+    /* Optional return codes - use cases are explicitly described for each function*/
+    OMX_Sts_BadArgErr                = -5,    /* Bad Arguments */
+
+    OMX_StsACAAC_TnsNumFiltErr       = -157,  /* AAC: Invalid number of TNS filters  */
+    OMX_StsACAAC_TnsLenErr           = -156,  /* AAC: Invalid TNS region length  */   
+    OMX_StsACAAC_TnsOrderErr         = -155,  /* AAC: Invalid order of TNS filter  */                  
+    OMX_StsACAAC_TnsCoefResErr       = -154,  /* AAC: Invalid bit-resolution for TNS filter coefficients  */
+    OMX_StsACAAC_TnsCoefErr          = -153,  /* AAC: Invalid TNS filter coefficients  */                  
+    OMX_StsACAAC_TnsDirectErr        = -152,  /* AAC: Invalid TNS filter direction  */  
+
+    OMX_StsICJP_JPEGMarkerErr        = -183,  /* JPEG marker encountered within an entropy-coded block; */
+                                              /* Huffman decoding operation terminated early.           */
+    OMX_StsICJP_JPEGMarker           = -181,  /* JPEG marker encountered; Huffman decoding */
+                                              /* operation terminated early.                         */
+    OMX_StsIPPP_ContextMatchErr      = -17,   /* Context parameter doesn't match to the operation */
+
+    OMX_StsSP_EvenMedianMaskSizeErr  = -180,  /* Even size of the Median Filter mask was replaced by the odd one */
+
+    OMX_Sts_MaximumEnumeration       = INT_MAX  /*Placeholder, forces enum of size OMX_INT*/
+    
+ } OMXResult;          /** Return value or error value returned from a function. Identical to OMX_INT */
+
+ 
+/* OMX_U8 */
+#if UCHAR_MAX == 0xff
+typedef unsigned char OMX_U8;
+#elif USHRT_MAX == 0xff 
+typedef unsigned short int OMX_U8; 
+#else
+#error OMX_U8 undefined
+#endif 
+
+ 
+/* OMX_S8 */
+#if SCHAR_MAX == 0x7f 
+typedef signed char OMX_S8;
+#elif SHRT_MAX == 0x7f 
+typedef signed short int OMX_S8; 
+#else
+#error OMX_S8 undefined
+#endif
+ 
+ 
+/* OMX_U16 */
+#if USHRT_MAX == 0xffff
+typedef unsigned short int OMX_U16;
+#elif UINT_MAX == 0xffff
+typedef unsigned int OMX_U16; 
+#else
+#error OMX_U16 undefined
+#endif
+
+
+/* OMX_S16 */
+#if SHRT_MAX == 0x7fff 
+typedef signed short int OMX_S16;
+#elif INT_MAX == 0x7fff 
+typedef signed int OMX_S16; 
+#else
+#error OMX_S16 undefined
+#endif
+
+
+/* OMX_U32 */
+#if UINT_MAX == 0xffffffff
+typedef unsigned int OMX_U32;
+#elif LONG_MAX == 0xffffffff
+typedef unsigned long int OMX_U32; 
+#else
+#error OMX_U32 undefined
+#endif
+
+
+/* OMX_S32 */
+#if INT_MAX == 0x7fffffff
+typedef signed int OMX_S32;
+#elif LONG_MAX == 0x7fffffff
+typedef long signed int OMX_S32; 
+#else
+#error OMX_S32 undefined
+#endif
+
+
+/* OMX_U64 & OMX_S64 */
+#if defined( _WIN32 ) || defined ( _WIN64 )
+    typedef __int64 OMX_S64; /** Signed 64-bit integer */
+    typedef unsigned __int64 OMX_U64; /** Unsigned 64-bit integer */
+    #define OMX_MIN_S64			(0x8000000000000000i64)
+    #define OMX_MIN_U64			(0x0000000000000000i64)
+    #define OMX_MAX_S64			(0x7FFFFFFFFFFFFFFFi64)
+    #define OMX_MAX_U64			(0xFFFFFFFFFFFFFFFFi64)
+#else
+    typedef long long OMX_S64; /** Signed 64-bit integer */
+    typedef unsigned long long OMX_U64; /** Unsigned 64-bit integer */
+    #define OMX_MIN_S64			(0x8000000000000000LL)
+    #define OMX_MIN_U64			(0x0000000000000000LL)
+    #define OMX_MAX_S64			(0x7FFFFFFFFFFFFFFFLL)
+    #define OMX_MAX_U64			(0xFFFFFFFFFFFFFFFFLL)
+#endif
+
+
+/* OMX_SC8 */
+typedef struct
+{
+  OMX_S8 Re; /** Real part */
+  OMX_S8 Im; /** Imaginary part */	
+	
+} OMX_SC8; /** Signed 8-bit complex number */
+
+
+/* OMX_SC16 */
+typedef struct
+{
+  OMX_S16 Re; /** Real part */
+  OMX_S16 Im; /** Imaginary part */	
+	
+} OMX_SC16; /** Signed 16-bit complex number */
+
+
+/* OMX_SC32 */
+typedef struct
+{
+  OMX_S32 Re; /** Real part */
+  OMX_S32 Im; /** Imaginary part */	
+	
+} OMX_SC32; /** Signed 32-bit complex number */
+
+
+/* OMX_SC64 */
+typedef struct
+{
+  OMX_S64 Re; /** Real part */
+  OMX_S64 Im; /** Imaginary part */	
+	
+} OMX_SC64; /** Signed 64-bit complex number */
+
+
+/* OMX_F32 */
+typedef float OMX_F32; /** Single precision floating point,IEEE 754 */
+
+
+/* OMX_F64 */
+typedef double OMX_F64; /** Double precision floating point,IEEE 754 */
+
+
+/* OMX_INT */
+typedef int OMX_INT; /** signed integer corresponding to machine word length, has maximum signed value INT_MAX*/
+
+
+#define OMX_MIN_S8  	   	(-128)
+#define OMX_MIN_U8  		0
+#define OMX_MIN_S16		 	(-32768)
+#define OMX_MIN_U16			0
+#define OMX_MIN_S32			(-2147483647-1)
+#define OMX_MIN_U32			0
+
+#define OMX_MAX_S8			(127)
+#define OMX_MAX_U8			(255)
+#define OMX_MAX_S16			(32767)
+#define OMX_MAX_U16			(0xFFFF)
+#define OMX_MAX_S32			(2147483647)
+#define OMX_MAX_U32			(0xFFFFFFFF)
+
+typedef void OMXVoid;
+
+#ifndef NULL
+#define NULL ((void*)0)
+#endif
+
+/** Defines the geometric position and size of a rectangle, 
+  * where x,y defines the coordinates of the top left corner
+  * of the rectangle, with dimensions width in the x-direction 
+  * and height in the y-direction */
+typedef struct {
+	OMX_INT x;      /** x-coordinate of top left corner of rectangle */
+	OMX_INT y;      /** y-coordinate of top left corner of rectangle */
+	OMX_INT width;  /** Width in the x-direction. */
+	OMX_INT height; /** Height in the y-direction. */
+}OMXRect;
+
+
+/** Defines the geometric position of a point, */
+typedef struct 
+{
+ OMX_INT x; /** x-coordinate */
+ OMX_INT y;	/** y-coordinate */
+	
+} OMXPoint;
+
+
+/** Defines the dimensions of a rectangle, or region of interest in an image */
+typedef struct 
+{
+ OMX_INT width;  /** Width of the rectangle, in the x-direction */
+ OMX_INT height; /** Height of the rectangle, in the y-direction */
+	
+} OMXSize;
+
+#endif /* _OMXTYPES_H_ */
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/api/omxtypes_s.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/api/omxtypes_s.h
new file mode 100644
index 0000000..8d24b65
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/api/omxtypes_s.h
@@ -0,0 +1,77 @@
+;//
+;// 
+;// File Name:  omxtypes_s.h
+;// OpenMAX DL: v1.0.2
+;// Revision:   9641
+;// Date:       Thursday, February 7, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+;// Mandatory return codes - use cases are explicitly described for each function 
+OMX_Sts_NoErr                    EQU  0    ;// No error the function completed successfully 
+OMX_Sts_Err                      EQU -2    ;// Unknown/unspecified error     
+OMX_Sts_InvalidBitstreamValErr   EQU -182  ;// Invalid value detected during bitstream processing     
+OMX_Sts_MemAllocErr              EQU -9    ;// Not enough memory allocated for the operation 
+OMX_StsACAAC_GainCtrErr    	     EQU -159  ;// AAC: Unsupported gain control data detected 
+OMX_StsACAAC_PrgNumErr           EQU -167  ;// AAC: Invalid number of elements for one program   
+OMX_StsACAAC_CoefValErr          EQU -163  ;// AAC: Invalid quantized coefficient value               
+OMX_StsACAAC_MaxSfbErr           EQU -162  ;// AAC: Invalid maxSfb value in relation to numSwb     
+OMX_StsACAAC_PlsDataErr		     EQU -160  ;// AAC: pulse escape sequence data error 
+
+;// Optional return codes - use cases are explicitly described for each function
+OMX_Sts_BadArgErr                EQU -5    ;// Bad Arguments 
+
+OMX_StsACAAC_TnsNumFiltErr       EQU -157  ;// AAC: Invalid number of TNS filters  
+OMX_StsACAAC_TnsLenErr           EQU -156  ;// AAC: Invalid TNS region length     
+OMX_StsACAAC_TnsOrderErr         EQU -155  ;// AAC: Invalid order of TNS filter                    
+OMX_StsACAAC_TnsCoefResErr       EQU -154  ;// AAC: Invalid bit-resolution for TNS filter coefficients  
+OMX_StsACAAC_TnsCoefErr          EQU -153  ;// AAC: Invalid TNS filter coefficients                    
+OMX_StsACAAC_TnsDirectErr        EQU -152  ;// AAC: Invalid TNS filter direction    
+
+OMX_StsICJP_JPEGMarkerErr        EQU -183  ;// JPEG marker encountered within an entropy-coded block; 
+                                            ;// Huffman decoding operation terminated early.           
+OMX_StsICJP_JPEGMarker           EQU -181  ;// JPEG marker encountered; Huffman decoding 
+                                            ;// operation terminated early.                         
+OMX_StsIPPP_ContextMatchErr      EQU -17   ;// Context parameter doesn't match to the operation 
+
+OMX_StsSP_EvenMedianMaskSizeErr  EQU -180  ;// Even size of the Median Filter mask was replaced by the odd one 
+
+OMX_Sts_MaximumEnumeration       EQU 0x7FFFFFFF
+
+
+
+OMX_MIN_S8      EQU 	   	(-128)
+OMX_MIN_U8  	EQU     	0
+OMX_MIN_S16		EQU      	(-32768)
+OMX_MIN_U16		EQU	        0
+
+
+OMX_MIN_S32		EQU	(-2147483647-1)
+OMX_MIN_U32		EQU	0
+
+OMX_MAX_S8		EQU	(127)
+OMX_MAX_U8		EQU	(255)
+OMX_MAX_S16		EQU	(32767)
+OMX_MAX_U16		EQU	(0xFFFF)
+OMX_MAX_S32		EQU	(2147483647)
+OMX_MAX_U32		EQU	(0xFFFFFFFF)
+
+OMX_VC_UPPER    EQU 0x1                 ;// Used by the PredictIntra functions   
+OMX_VC_LEFT     EQU 0x2                 ;// Used by the PredictIntra functions 
+OMX_VC_UPPER_RIGHT    EQU 0x40          ;// Used by the PredictIntra functions   
+
+NULL    EQU 0
+
+;// Structures
+
+    INCLUDE     armCOMM_s.h
+
+    M_STRUCT    OMXPoint
+    M_FIELD     x, 4
+    M_FIELD     y, 4
+    M_ENDSTRUCT
+
+        END
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/build_vc.pl b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/build_vc.pl
new file mode 100755
index 0000000..1ae7005
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/build_vc.pl
@@ -0,0 +1,111 @@
+#!/usr/bin/perl
+#
+# 
+# File Name:  build_vc.pl
+# OpenMAX DL: v1.0.2
+# Revision:   9641
+# Date:       Thursday, February 7, 2008
+# 
+# (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+# 
+# 
+#
+# This file builds the OpenMAX DL vc domain library omxVC.o.
+#
+
+use File::Spec;
+use strict;
+
+my ($CC, $CC_OPTS, $AS, $AS_OPTS, $LIB, $LIB_OPTS, $LIB_TYPE);
+
+$CC       = 'armcc';
+$CC_OPTS  = '--no_unaligned_access --cpu ARM1136J-S -c';
+$AS       = 'armasm';
+$AS_OPTS  = '--no_unaligned_access --cpu ARM1136J-S';
+# $LIB      = 'armlink';
+# $LIB_OPTS = '--partial -o';
+# $LIB_TYPE = '.o';
+$LIB      = 'armar';
+$LIB_OPTS = '--create -r';
+$LIB_TYPE = '.a';
+
+#------------------------
+
+my (@headerlist, @filelist, $hd, $file, $ofile, $command, $objlist, $libfile, $h);
+
+# Define the list of directories containing included header files.
+@headerlist = qw(api vc/api vc/m4p2/api vc/m4p10/api);
+
+# Define the list of source files to compile.
+open(FILES, '<filelist_vc.txt') or die("Can't open source file list\n");
+@filelist = <FILES>;
+close(FILES);
+
+# Fix the file separators in the header paths
+foreach $h (@headerlist)
+{
+        $h = File::Spec->canonpath($h);
+}
+
+# Create the include path to be passed to the compiler
+$hd = '-I' . join(' -I', @headerlist);
+
+# Create the build directories "/lib/" and "/obj/" (if they are not there already)
+mkdir "obj", 0777 if (! -d "obj");
+mkdir "lib", 0777 if (! -d "lib");
+
+$objlist = '';
+
+# Compile each file
+foreach $file (@filelist)
+{
+	my $f;
+	my $base;
+	my $ext;
+	my $objfile;
+
+	chomp($file);
+	$file = File::Spec->canonpath($file);
+
+	(undef, undef, $f) = File::Spec->splitpath($file);
+	if(($base, $ext) = $f =~ /(.+)\.(\w)$/)
+	{
+		$objfile = File::Spec->catfile('obj', $base.'.o');
+
+		if($ext eq 'c')
+		{
+			$objlist .= "$objfile ";
+			$command = $CC.' '.$CC_OPTS.' '.$hd.' -o '.$objfile.' '.$file;
+			print "$command\n";
+			system($command);
+		}
+		elsif($ext eq 's')
+		{
+			$objlist .= "$objfile ";
+			$command = $AS.' '.$AS_OPTS.' '.$hd.' -o '.$objfile.' '.$file;
+			print "$command\n";
+			system($command);
+		}
+		else
+		{
+			print "Ignoring file: $f\n";
+		}
+	}
+	else
+	{
+		die "No file extension found: $f\n";
+	}
+}
+
+# Do the final link stage to create the libraries.
+$libfile = File::Spec->catfile('lib', 'omxVC'.$LIB_TYPE);
+$command = $LIB.' '.$LIB_OPTS.' '.$libfile.' '.$objlist;
+print "$command\n";
+(system($command) == 0) and print "Build successful\n";
+
+
+
+
+
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/filelist_vc.txt b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/filelist_vc.txt
new file mode 100644
index 0000000..0f1623f
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/filelist_vc.txt
@@ -0,0 +1,74 @@
+./api/armCOMM.h
+./api/armCOMM_BitDec_s.h
+./api/armCOMM_Bitstream.h
+./api/armCOMM_IDCT_s.h
+./api/armCOMM_IDCTTable.h
+./api/armCOMM_MaskTable.h
+./api/armCOMM_s.h
+./api/armCOMM_Version.h
+./api/armOMX_ReleaseVersion.h
+./api/omxtypes.h
+./api/omxtypes_s.h
+./src/armCOMM_IDCTTable.c
+./src/armCOMM_MaskTable.c
+./vc/api/armVC.h
+./vc/api/armVCCOMM_s.h
+./vc/api/omxVC.h
+./vc/api/omxVC_s.h
+./vc/comm/src/omxVCCOMM_Copy16x16_s.s
+./vc/comm/src/omxVCCOMM_Copy8x8_s.s
+./vc/comm/src/omxVCCOMM_ExpandFrame_I_s.s
+./vc/m4p10/api/armVCM4P10_CAVLCTables.h
+./vc/m4p10/src/armVCM4P10_Average_4x_Align_unsafe_s.s
+./vc/m4p10/src/armVCM4P10_CAVLCTables.c
+./vc/m4p10/src/armVCM4P10_DeblockingChroma_unsafe_s.s
+./vc/m4p10/src/armVCM4P10_DeblockingLuma_unsafe_s.s
+./vc/m4p10/src/armVCM4P10_DecodeCoeffsToPair_s.s
+./vc/m4p10/src/armVCM4P10_DequantTables_s.s
+./vc/m4p10/src/armVCM4P10_Interpolate_Chroma_s.s
+./vc/m4p10/src/armVCM4P10_InterpolateLuma_Align_unsafe_s.s
+./vc/m4p10/src/armVCM4P10_InterpolateLuma_Copy_unsafe_s.s
+./vc/m4p10/src/armVCM4P10_InterpolateLuma_DiagCopy_unsafe_s.s
+./vc/m4p10/src/armVCM4P10_InterpolateLuma_HalfDiagHorVer4x4_unsafe_s.s
+./vc/m4p10/src/armVCM4P10_InterpolateLuma_HalfDiagVerHor4x4_unsafe_s.s
+./vc/m4p10/src/armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe_s.s
+./vc/m4p10/src/armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe_s.s
+./vc/m4p10/src/armVCM4P10_QuantTables_s.s
+./vc/m4p10/src/armVCM4P10_TransformResidual4x4_s.s
+./vc/m4p10/src/armVCM4P10_UnpackBlock4x4_s.s
+./vc/m4p10/src/omxVCM4P10_DeblockChroma_I.c
+./vc/m4p10/src/omxVCM4P10_DeblockLuma_I.c
+./vc/m4p10/src/omxVCM4P10_DecodeChromaDcCoeffsToPairCAVLC.c
+./vc/m4p10/src/omxVCM4P10_DecodeCoeffsToPairCAVLC.c
+./vc/m4p10/src/omxVCM4P10_FilterDeblockingChroma_HorEdge_I_s.s
+./vc/m4p10/src/omxVCM4P10_FilterDeblockingChroma_VerEdge_I_s.s
+./vc/m4p10/src/omxVCM4P10_FilterDeblockingLuma_HorEdge_I_s.s
+./vc/m4p10/src/omxVCM4P10_FilterDeblockingLuma_VerEdge_I_s.s
+./vc/m4p10/src/omxVCM4P10_InterpolateChroma.c
+./vc/m4p10/src/omxVCM4P10_InterpolateLuma_s.s
+./vc/m4p10/src/omxVCM4P10_PredictIntra_16x16_s.s
+./vc/m4p10/src/omxVCM4P10_PredictIntra_4x4_s.s
+./vc/m4p10/src/omxVCM4P10_PredictIntraChroma_8x8_s.s
+./vc/m4p10/src/omxVCM4P10_TransformDequantChromaDCFromPair_s.s
+./vc/m4p10/src/omxVCM4P10_TransformDequantLumaDCFromPair_s.s
+./vc/m4p2/api/armVCM4P2_Huff_Tables_VLC.h
+./vc/m4p2/api/armVCM4P2_ZigZag_Tables.h
+./vc/m4p2/src/armVCM4P2_Clip8_s.s
+./vc/m4p2/src/armVCM4P2_DecodeVLCZigzag_AC_unsafe_s.s
+./vc/m4p2/src/armVCM4P2_Huff_Tables_VLC.c
+./vc/m4p2/src/armVCM4P2_Lookup_Tables.c
+./vc/m4p2/src/armVCM4P2_SetPredDir_s.s
+./vc/m4p2/src/armVCM4P2_Zigzag_Tables.c
+./vc/m4p2/src/omxVCM4P2_DecodeBlockCoef_Inter.c
+./vc/m4p2/src/omxVCM4P2_DecodeBlockCoef_Intra.c
+./vc/m4p2/src/omxVCM4P2_DecodePadMV_PVOP_s.s
+./vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_Inter_s.s
+./vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_IntraACVLC_s.s
+./vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_IntraDCVLC_s.s
+./vc/m4p2/src/omxVCM4P2_FindMVpred_s.s
+./vc/m4p2/src/omxVCM4P2_IDCT8x8blk_s.s
+./vc/m4p2/src/omxVCM4P2_MCReconBlock_s.s
+./vc/m4p2/src/omxVCM4P2_PredictReconCoefIntra_s.s
+./vc/m4p2/src/omxVCM4P2_QuantInvInter_I_s.s
+./vc/m4p2/src/omxVCM4P2_QuantInvIntra_I_s.s
+./vc/src/armVC_Version.c
\ No newline at end of file
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/src/armCOMM.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/src/armCOMM.c
new file mode 100644
index 0000000..e572a89
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/src/armCOMM.c
@@ -0,0 +1,936 @@
+/**
+ * 
+ * File Name:  armCOMM.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Defines Common APIs used across OpenMAX API's
+ */
+
+#include "omxtypes.h"
+#include "armCOMM.h"
+
+/***********************************************************************/
+                /* Miscellaneous Arithmetic operations */
+
+/**
+ * Function: armRoundFloatToS16
+ *
+ * Description:
+ * Converts a double precision value into a short int after rounding
+ *
+ * Parameters:
+ * [in]  Value                 Float value to be converted
+ *
+ * Return Value:
+ * [out] converted value in OMX_S16 format
+ *
+ */
+
+OMX_S16 armRoundFloatToS16 (OMX_F64 Value)
+{
+    if (Value > 0)
+    {
+        return (OMX_S16)(Value + .5);
+    }
+    else
+    {
+        return (OMX_S16)(Value - .5);
+    }
+}
+
+/**
+ * Function: armRoundFloatToS32
+ *
+ * Description:
+ * Converts a double precision value into a int after rounding
+ *
+ * Parameters:
+ * [in]  Value                 Float value to be converted
+ *
+ * Return Value:
+ * [out] converted value in OMX_S32 format
+ *
+ */
+
+OMX_S32 armRoundFloatToS32 (OMX_F64 Value)
+{
+    if (Value > 0)
+    {
+        return (OMX_S32)(Value + .5);
+    }
+    else
+    {
+        return (OMX_S32)(Value - .5);
+    }
+}
+/**
+ * Function: armSatRoundFloatToS16
+ *
+ * Description:
+ * Converts a double precision value into a short int after rounding and saturation
+ *
+ * Parameters:
+ * [in]  Value                 Float value to be converted
+ *
+ * Return Value:
+ * [out] converted value in OMX_S16 format
+ *
+ */
+
+OMX_S16 armSatRoundFloatToS16 (OMX_F64 Value)
+{
+    if (Value > 0)
+    {
+        Value += 0.5;
+        
+        if(Value > (OMX_S16)OMX_MAX_S16 )
+        {
+            return (OMX_S16)OMX_MAX_S16;
+        }
+        else
+        {
+            return (OMX_S16)Value;
+        }
+    }
+    else
+    {
+        Value -= 0.5;
+
+        if(Value < (OMX_S16)OMX_MIN_S16 )
+        {
+            return (OMX_S16)OMX_MIN_S16;
+        }
+        else
+        {
+            return (OMX_S16)Value;
+        }
+    }
+}
+
+/**
+ * Function: armSatRoundFloatToS32
+ *
+ * Description:
+ * Converts a double precision value into a int after rounding and saturation
+ *
+ * Parameters:
+ * [in]  Value                 Float value to be converted
+ *
+ * Return Value:
+ * [out] converted value in OMX_S32 format
+ *
+ */
+
+OMX_S32 armSatRoundFloatToS32 (OMX_F64 Value)
+{
+    if (Value > 0)
+    {
+        Value += 0.5;
+        
+        if(Value > (OMX_S32)OMX_MAX_S32 )
+        {
+            return (OMX_S32)OMX_MAX_S32;
+        }
+        else
+        {
+            return (OMX_S32)Value;
+        }
+    }
+    else
+    {
+        Value -= 0.5;
+
+        if(Value < (OMX_S32)OMX_MIN_S32 )
+        {
+            return (OMX_S32)OMX_MIN_S32;
+        }
+        else
+        {
+            return (OMX_S32)Value;
+        }
+    }
+}
+
+/**
+ * Function: armSatRoundFloatToU16
+ *
+ * Description:
+ * Converts a double precision value into a unsigned short int after rounding and saturation
+ *
+ * Parameters:
+ * [in]  Value                 Float value to be converted
+ *
+ * Return Value:
+ * [out] converted value in OMX_U16 format
+ *
+ */
+
+OMX_U16 armSatRoundFloatToU16 (OMX_F64 Value)
+{
+    Value += 0.5;
+    
+    if(Value > (OMX_U16)OMX_MAX_U16 )
+    {
+        return (OMX_U16)OMX_MAX_U16;
+    }
+    else
+    {
+        return (OMX_U16)Value;
+    }
+}
+
+/**
+ * Function: armSatRoundFloatToU32
+ *
+ * Description:
+ * Converts a double precision value into a unsigned int after rounding and saturation
+ *
+ * Parameters:
+ * [in]  Value                 Float value to be converted
+ *
+ * Return Value:
+ * [out] converted value in OMX_U32 format
+ *
+ */
+
+OMX_U32 armSatRoundFloatToU32 (OMX_F64 Value)
+{
+    Value += 0.5;
+    
+    if(Value > (OMX_U32)OMX_MAX_U32 )
+    {
+        return (OMX_U32)OMX_MAX_U32;
+    }
+    else
+    {
+        return (OMX_U32)Value;
+    }
+}
+
+/**
+ * Function: armRoundFloatToS64
+ *
+ * Description:
+ * Converts a double precision value into a 64 bit int after rounding
+ *
+ * Parameters:
+ * [in]  Value                 Float value to be converted
+ *
+ * Return Value:
+ * [out] converted value in OMX_S64 format
+ *
+ */
+
+OMX_S64 armRoundFloatToS64 (OMX_F64 Value)
+{
+    if (Value > 0)
+    {
+        return (OMX_S64)(Value + .5);
+    }
+    else
+    {
+        return (OMX_S64)(Value - .5);
+    }
+}
+
+/**
+ * Function: armSignCheck
+ *
+ * Description:
+ * Checks the sign of a variable:
+ * returns 1 if it is Positive
+ * returns 0 if it is 0
+ * returns -1 if it is Negative 
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	    var     Variable to be checked
+ *
+ * Return Value:
+ * OMX_INT --   returns 1 if it is Positive
+ *              returns 0 if it is 0
+ *              returns -1 if it is Negative 
+ */ 
+
+OMX_INT armSignCheck (
+    OMX_S16 var
+)
+
+{
+    OMX_INT Sign;
+    
+    if (var < 0)
+    {
+        Sign = -1;
+    }
+    else if ( var > 0)
+    {
+        Sign = 1;
+    }
+    else
+    {
+        Sign = 0;
+    }
+    
+    return Sign;
+}
+
+/**
+ * Function: armClip
+ *
+ * Description: Clips the input between MAX and MIN value
+ * 
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] Min     lower bound
+ * [in] Max     upper bound
+ * [in] src     variable to the clipped
+ *
+ * Return Value:
+ * OMX_S32 --   returns clipped value
+ */ 
+ 
+OMX_S32 armClip (
+    OMX_INT min,
+    OMX_INT max, 
+    OMX_S32 src 
+)
+ 
+{
+    if (src > max)
+    {
+        src = max;
+    }
+    else if (src < min)
+    {
+        src = min;
+    }
+    
+    return src;
+}
+
+/**
+ * Function: armClip_F32
+ *
+ * Description: Clips the input between MAX and MIN value
+ * 
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] Min     lower bound
+ * [in] Max     upper bound
+ * [in] src     variable to the clipped
+ *
+ * Return Value:
+ * OMX_F32 --   returns clipped value
+ */ 
+ 
+OMX_F32 armClip_F32 (
+    OMX_F32 min,
+    OMX_F32 max, 
+    OMX_F32 src 
+)
+ 
+{
+    if (src > max)
+    {
+        src = max;
+    }
+    else if (src < min)
+    {
+        src = min;
+    }
+    
+    return src;
+}
+
+/**
+ * Function: armShiftSat_F32
+ *
+ * Description: Divides a float value by 2^shift and 
+ * saturates it for unsigned value range for satBits.
+ * Second parameter is like "shifting" the corresponding 
+ * integer value. Takes care of rounding while clipping the final 
+ * value.
+ *
+ * Parameters:
+ * [in] v          Number to be operated upon
+ * [in] shift      Divides the input "v" by "2^shift"
+ * [in] satBits    Final range is [0, 2^satBits)
+ *
+ * Return Value:
+ * OMX_S32 --   returns "shifted" saturated value
+ */ 
+ 
+OMX_U32 armShiftSat_F32(OMX_F32 v, OMX_INT shift, OMX_INT satBits) 
+{
+    OMX_U32 allOnes = (OMX_U32)(-1);
+    OMX_U32 maxV = allOnes >> (32-satBits);
+    OMX_F32 vShifted, vRounded, shiftDiv = (OMX_F32)(1 << shift);
+    OMX_U32 vInt;
+    OMX_U32 vIntSat;
+    
+    if(v <= 0)
+        return 0;
+    
+    vShifted = v / shiftDiv;
+    vRounded = (OMX_F32)(vShifted + 0.5);
+    vInt = (OMX_U32)vRounded;
+    vIntSat = vInt;
+    if(vIntSat > maxV) 
+        vIntSat = maxV;
+    return vIntSat;
+}
+
+/**
+ * Functions: armSwapElem
+ *
+ * Description:
+ * These function swaps two elements at the specified pointer locations.
+ * The size of each element could be anything as specified by <elemSize>
+ *
+ * Return Value:
+ * OMXResult -- Error status from the function
+ */
+OMXResult armSwapElem(
+        OMX_U8 *pBuf1,
+        OMX_U8 *pBuf2,
+        OMX_INT elemSize
+       )
+{
+    OMX_INT i;
+    OMX_U8 temp;
+    armRetArgErrIf(!pBuf1 || !pBuf2, OMX_Sts_BadArgErr);
+    
+    for(i = 0; i < elemSize; i++)
+    {
+        temp = *(pBuf1 + i);
+        *(pBuf1 + i) = *(pBuf2 + i);
+        *(pBuf2 + i) = temp;
+    }
+    return OMX_Sts_NoErr;
+}
+
+/**
+ * Function: armMedianOf3
+ *
+ * Description: Finds the median of three numbers
+ * 
+ * Remarks:
+ *
+ * Parameters:
+ * [in] fEntry     First entry
+ * [in] sEntry     second entry
+ * [in] tEntry     Third entry
+ *
+ * Return Value:
+ * OMX_S32 --   returns the median value
+ */ 
+ 
+OMX_S32 armMedianOf3 (
+    OMX_S32 fEntry,
+    OMX_S32 sEntry, 
+    OMX_S32 tEntry 
+)
+{
+    OMX_S32 a, b, c;
+    
+    a = armMin (fEntry, sEntry);
+    b = armMax (fEntry, sEntry);
+    c = armMin (b, tEntry);
+    return (armMax (a, c));
+}
+
+/**
+ * Function: armLogSize
+ *
+ * Description: Finds the size of a positive value and returns the same
+ * 
+ * Remarks:
+ *
+ * Parameters:
+ * [in] value    Positive value
+ *
+ * Return Value:
+ * OMX_U8 --     Returns the minimum number of bits required to represent the positive value. 
+                 This is the smallest k>=0 such that that value is less than (1<<k).
+ */ 
+ 
+OMX_U8 armLogSize (
+    OMX_U16 value 
+)
+{
+    OMX_U8 i;    
+    for ( i = 0; value > 0; value = value >> 1) 
+    {
+        i++;
+    }
+    return i;
+}
+
+/***********************************************************************/
+                /* Saturating Arithmetic operations */
+
+/**
+ * Function :armSatAdd_S32()
+ *
+ * Description :
+ *   Returns the result of saturated addition of the two inputs Value1, Value2
+ *
+ * Parametrs:
+ * [in] Value1       First Operand
+ * [in] Value2       Second Operand
+ *
+ * Return:
+ * [out]             Result of operation
+ * 
+ *    
+ **/
+ 
+OMX_S32 armSatAdd_S32(OMX_S32 Value1,OMX_S32 Value2)
+{
+    OMX_S32 Result;
+    
+    Result = Value1 + Value2;
+
+    if( (Value1^Value2) >= 0)
+    {
+        /*Same sign*/
+        if( (Result^Value1) >= 0)
+        {
+            /*Result has not saturated*/
+            return Result;
+        }
+        else
+        {
+            if(Value1 >= 0)
+            {
+                /*Result has saturated in positive side*/
+                return OMX_MAX_S32;
+            }
+            else
+            {
+                /*Result has saturated in negative side*/
+                return OMX_MIN_S32;
+            }
+        
+        }
+   
+    }
+    else
+    {
+        return Result;
+    }
+    
+}
+
+/**
+ * Function :armSatAdd_S64()
+ *
+ * Description :
+ *   Returns the result of saturated addition of the two inputs Value1, Value2
+ *
+ * Parametrs:
+ * [in] Value1       First Operand
+ * [in] Value2       Second Operand
+ *
+ * Return:
+ * [out]             Result of operation
+ * 
+ *    
+ **/
+ 
+OMX_S64 armSatAdd_S64(OMX_S64 Value1,OMX_S64 Value2)
+{
+    OMX_S64 Result;
+    
+    Result = Value1 + Value2;
+
+    if( (Value1^Value2) >= 0)
+    {
+        /*Same sign*/
+        if( (Result^Value1) >= 0)
+        {
+            /*Result has not saturated*/
+            return Result;
+        }
+        else
+        {
+            if(Value1 >= 0)
+            {
+                /*Result has saturated in positive side*/
+                Result = OMX_MAX_S64;
+                return Result;
+            }
+            else
+            {
+                /*Result has saturated in negative side*/
+                return OMX_MIN_S64;
+            }
+        
+        }
+   
+    }
+    else
+    {
+        return Result;
+    }
+    
+}
+
+/** Function :armSatSub_S32()
+ * 
+ * Description :
+ *     Returns the result of saturated substraction of the two inputs Value1, Value2
+ *
+ * Parametrs:
+ * [in] Value1       First Operand
+ * [in] Value2       Second Operand
+ *
+ * Return:
+ * [out]             Result of operation
+ * 
+ **/
+
+OMX_S32 armSatSub_S32(OMX_S32 Value1,OMX_S32 Value2)
+{
+    OMX_S32 Result;
+    
+    Result = Value1 - Value2;
+
+    if( (Value1^Value2) < 0)
+    {
+        /*Opposite sign*/
+        if( (Result^Value1) >= 0)
+        {
+            /*Result has not saturated*/
+            return Result;
+        }
+        else
+        {
+            if(Value1 >= 0)
+            {
+                /*Result has saturated in positive side*/
+                return OMX_MAX_S32;
+            }
+            else
+            {
+                /*Result has saturated in negative side*/
+                return OMX_MIN_S32;
+            }
+        
+        }
+   
+    }
+    else
+    {
+        return Result;
+    }
+    
+}
+
+/**
+ * Function :armSatMac_S32()
+ *
+ * Description :
+ *     Returns the result of Multiplication of Value1 and Value2 and subesquent saturated
+ *     accumulation with Mac
+ *
+ * Parametrs:
+ * [in] Value1       First Operand
+ * [in] Value2       Second Operand
+ * [in] Mac          Accumulator
+ *
+ * Return:
+ * [out]             Result of operation
+ **/
+
+OMX_S32 armSatMac_S32(OMX_S32 Mac,OMX_S16 Value1,OMX_S16 Value2)
+{
+    OMX_S32 Result;
+    
+    Result = (OMX_S32)(Value1*Value2);
+    Result = armSatAdd_S32( Mac , Result );
+
+    return Result;    
+}
+
+/**
+ * Function :armSatMac_S16S32_S32
+ *
+ * Description :
+ *   Returns the result of saturated MAC operation of the three inputs delayElem, filTap , mac
+ *
+ *   mac = mac + Saturate_in_32Bits(delayElem * filTap)
+ *
+ * Parametrs:
+ * [in] delayElem    First 32 bit Operand
+ * [in] filTap       Second 16 bit Operand
+ * [in] mac          Result of MAC operation
+ *
+ * Return:
+ * [out]  mac        Result of operation
+ *    
+ **/
+ 
+OMX_S32 armSatMac_S16S32_S32(OMX_S32 mac, OMX_S32 delayElem, OMX_S16 filTap )
+{
+    
+    OMX_S32 result;
+
+    result = armSatMulS16S32_S32(filTap,delayElem); 
+
+    if ( result > OMX_MAX_S16 )
+    {
+        result = OMX_MAX_S32;
+    }
+    else if( result < OMX_MIN_S16 )
+    {
+        result = OMX_MIN_S32;
+    }
+    else
+    {
+        result = delayElem * filTap;
+    }
+
+    mac = armSatAdd_S32(mac,result);
+    
+    return mac;
+}
+
+
+/**
+ * Function :armSatRoundRightShift_S32_S16
+ *
+ * Description :
+ *   Returns the result of rounded right shift operation of input by the scalefactor
+ *
+ *   output = Saturate_in_16Bits( ( Right/LeftShift( (Round(input) , shift ) )
+ *
+ * Parametrs:
+ * [in] input       The input to be operated on
+ * [in] shift The shift number
+ *
+ * Return:
+ * [out]            Result of operation
+ *    
+ **/
+
+
+OMX_S16 armSatRoundRightShift_S32_S16(OMX_S32 input, OMX_INT shift)
+{
+    input = armSatRoundLeftShift_S32(input,-shift);
+
+    if ( input > OMX_MAX_S16 )
+    {
+        return (OMX_S16)OMX_MAX_S16;
+    }
+    else if (input < OMX_MIN_S16)
+    {
+        return (OMX_S16)OMX_MIN_S16;
+    }
+    else
+    {
+       return (OMX_S16)input;
+    }
+
+}
+
+/**
+ * Function :armSatRoundLeftShift_S32()
+ *
+ * Description :
+ *     Returns the result of saturating left-shift operation on input
+ *     Or rounded Right shift if the input Shift is negative.
+ *     
+ * Parametrs:
+ * [in] Value        Operand
+ * [in] Shift        Operand for shift operation
+ *
+ * Return:
+ * [out]             Result of operation
+ *    
+ **/
+
+OMX_S32 armSatRoundLeftShift_S32(OMX_S32 Value, OMX_INT Shift)
+{
+    OMX_INT i;
+    
+    if (Shift < 0)
+    {
+        Shift = -Shift;
+        Value = armSatAdd_S32(Value, (1 << (Shift - 1)));
+        Value = Value >> Shift;
+    }
+    else
+    {
+        for (i = 0; i < Shift; i++)
+        {
+            Value = armSatAdd_S32(Value, Value);
+        }
+    }
+    return Value;
+}
+
+/**
+ * Function :armSatRoundLeftShift_S64()
+ *
+ * Description :
+ *     Returns the result of saturating left-shift operation on input
+ *     Or rounded Right shift if the input Shift is negative.
+ *
+ * Parametrs:
+ * [in] Value        Operand
+ * [in] shift        Operand for shift operation
+ *
+ * Return:
+ * [out]             Result of operation
+ *    
+ **/
+ 
+OMX_S64 armSatRoundLeftShift_S64(OMX_S64 Value, OMX_INT Shift)
+{
+    OMX_INT i;
+    
+    if (Shift < 0)
+    {
+        Shift = -Shift;
+        Value = armSatAdd_S64(Value, ((OMX_S64)1 << (Shift - 1)));
+        Value = Value >> Shift;
+    }
+    else
+    {
+        for (i = 0; i < Shift; i++)
+        {
+            Value = armSatAdd_S64(Value, Value);
+        }
+    }
+    return Value;
+}
+
+/**
+ * Function :armSatMulS16S32_S32()
+ *
+ * Description :
+ *     Returns the result of a S16 data type multiplied with an S32 data type
+ *     in a S32 container
+ *
+ * Parametrs:
+ * [in] input1       Operand 1
+ * [in] input2       Operand 2
+ *
+ * Return:
+ * [out]             Result of operation
+ *    
+ **/
+
+
+OMX_S32 armSatMulS16S32_S32(OMX_S16 input1,OMX_S32 input2)
+{
+    OMX_S16 hi2,lo1;
+    OMX_U16 lo2;
+    
+    OMX_S32 temp1,temp2;
+    OMX_S32 result;
+    
+    lo1  = input1;
+
+    hi2  = ( input2 >>  16 );
+    lo2  = ( (OMX_U32)( input2 << 16 ) >> 16 );
+    
+    temp1 = hi2 * lo1;
+    temp2 = ( lo2* lo1 ) >> 16;
+
+    result =  armSatAdd_S32(temp1,temp2);
+
+    return result;
+}
+
+/**
+ * Function :armSatMulS32S32_S32()
+ *
+ * Description :
+ *     Returns the result of a S32 data type multiplied with an S32 data type
+ *     in a S32 container
+ *
+ * Parametrs:
+ * [in] input1       Operand 1
+ * [in] input2       Operand 2
+ *
+ * Return:
+ * [out]             Result of operation
+ *    
+ **/
+
+OMX_S32 armSatMulS32S32_S32(OMX_S32 input1,OMX_S32 input2)
+{
+    OMX_S16 hi1,hi2;
+    OMX_U16 lo1,lo2;
+    
+    OMX_S32 temp1,temp2,temp3;
+    OMX_S32 result;
+
+    hi1  = ( input1 >>  16 );
+    lo1  = ( (OMX_U32)( input1 << 16 ) >> 16 );
+
+    hi2  = ( input2 >>  16 );
+    lo2  = ( (OMX_U32)( input2 << 16 ) >> 16 );
+    
+    temp1 =   hi1 * hi2;
+    temp2 = ( hi1* lo2 ) >> 16;
+    temp3 = ( hi2* lo1 ) >> 16;
+
+    result = armSatAdd_S32(temp1,temp2);
+    result = armSatAdd_S32(result,temp3);
+
+    return result;
+}
+
+/**
+ * Function :armIntDivAwayFromZero()
+ *
+ * Description : Integer division with rounding to the nearest integer. 
+ *               Half-integer values are rounded away from zero
+ *               unless otherwise specified. For example 3//2 is rounded 
+ *               to 2, and -3//2 is rounded to -2.
+ *
+ * Parametrs:
+ * [in] Num        Operand 1
+ * [in] Deno       Operand 2
+ *
+ * Return:
+ * [out]             Result of operation input1//input2
+ *    
+ **/
+
+OMX_S32 armIntDivAwayFromZero (OMX_S32 Num, OMX_S32 Deno)
+{
+    OMX_F64 result;
+    
+    result = ((OMX_F64)Num)/((OMX_F64)Deno);
+    
+    if (result >= 0)
+    {
+        result += 0.5;
+    }
+    else
+    {
+        result -= 0.5;
+    }
+
+    return (OMX_S32)(result);
+}
+
+
+/*End of File*/
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/src/armCOMM_Bitstream.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/src/armCOMM_Bitstream.c
new file mode 100644
index 0000000..9ef9319
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/src/armCOMM_Bitstream.c
@@ -0,0 +1,329 @@
+/**
+ * 
+ * File Name:  armCOMM_Bitstream.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Defines bitstream encode and decode functions common to all codecs
+ */
+
+#include "omxtypes.h"
+#include "armCOMM.h"
+#include "armCOMM_Bitstream.h"
+
+/***************************************
+ * Fixed bit length Decode
+ ***************************************/
+
+/**
+ * Function: armLookAheadBits()
+ *
+ * Description:
+ * Get the next N bits from the bitstream without advancing the bitstream pointer
+ *
+ * Parameters:
+ * [in]     **ppBitStream
+ * [in]     *pOffset
+ * [in]     N=1...32
+ *
+ * Returns  Value
+ */
+
+OMX_U32 armLookAheadBits(const OMX_U8 **ppBitStream, OMX_INT *pOffset, OMX_INT N)
+{
+    const OMX_U8 *pBitStream = *ppBitStream;
+    OMX_INT Offset = *pOffset;
+    OMX_U32 Value;
+
+    armAssert(Offset>=0 && Offset<=7);
+    armAssert(N>=1 && N<=32);
+
+    /* Read next 32 bits from stream */
+    Value = (pBitStream[0] << 24 ) | ( pBitStream[1] << 16)  | (pBitStream[2] << 8 ) | (pBitStream[3]) ;
+    Value = (Value << Offset ) | (pBitStream[4] >> (8-Offset));
+
+    /* Return N bits */
+    return Value >> (32-N);
+}
+
+
+/**
+ * Function: armGetBits()
+ *
+ * Description:
+ * Read N bits from the bitstream
+ *    
+ * Parameters:
+ * [in]     *ppBitStream
+ * [in]     *pOffset
+ * [in]     N=1..32
+ *
+ * [out]    *ppBitStream
+ * [out]    *pOffset
+ * Returns  Value
+ */
+
+
+OMX_U32 armGetBits(const OMX_U8 **ppBitStream, OMX_INT *pOffset, OMX_INT N)
+{
+    const OMX_U8 *pBitStream = *ppBitStream;
+    OMX_INT Offset = *pOffset;
+    OMX_U32 Value;
+    
+    if(N == 0)
+    {
+      return 0;
+    }
+
+    armAssert(Offset>=0 && Offset<=7);
+    armAssert(N>=1 && N<=32);
+
+    /* Read next 32 bits from stream */
+    Value = (pBitStream[0] << 24 ) | ( pBitStream[1] << 16)  | (pBitStream[2] << 8 ) | (pBitStream[3]) ;
+    Value = (Value << Offset ) | (pBitStream[4] >> (8-Offset));
+
+    /* Advance bitstream pointer by N bits */
+    Offset += N;
+    *ppBitStream = pBitStream + (Offset>>3);
+    *pOffset = Offset & 7;
+
+    /* Return N bits */
+    return Value >> (32-N);
+}
+
+/**
+ * Function: armByteAlign()
+ *
+ * Description:
+ * Align the pointer *ppBitStream to the next byte boundary
+ *
+ * Parameters:
+ * [in]     *ppBitStream
+ * [in]     *pOffset
+ *
+ * [out]    *ppBitStream
+ * [out]    *pOffset
+ *
+ **/
+ 
+OMXVoid armByteAlign(const OMX_U8 **ppBitStream,OMX_INT *pOffset)
+{
+    if(*pOffset > 0)
+    {
+        *ppBitStream += 1;
+        *pOffset = 0;
+    }    
+}
+
+/** 
+ * Function: armSkipBits()
+ *
+ * Description:
+ * Skip N bits from the value at *ppBitStream
+ *
+ * Parameters:
+ * [in]     *ppBitStream
+ * [in]     *pOffset
+ * [in]     N
+ *
+ * [out]    *ppBitStream
+ * [out]    *pOffset
+ *
+ **/
+
+
+OMXVoid armSkipBits(const OMX_U8 **ppBitStream,OMX_INT *pOffset,OMX_INT N)
+{
+    OMX_INT Offset = *pOffset;
+    const OMX_U8 *pBitStream = *ppBitStream;
+   
+    /* Advance bitstream pointer by N bits */
+    Offset += N;
+    *ppBitStream = pBitStream + (Offset>>3);
+    *pOffset = Offset & 7;
+}
+
+/***************************************
+ * Variable bit length Decode
+ ***************************************/
+
+/**
+ * Function: armUnPackVLC32()
+ *
+ * Description:
+ * Variable length decode of variable length symbol (max size 32 bits) read from
+ * the bit stream pointed by *ppBitStream at *pOffset by using the table
+ * pointed by pCodeBook
+ * 
+ * Parameters:
+ * [in]     *pBitStream
+ * [in]     *pOffset
+ * [in]     pCodeBook
+ * 
+ * [out]    *pBitStream
+ * [out]    *pOffset
+ *
+ * Returns : Code Book Index if successfull. 
+ *         : ARM_NO_CODEBOOK_INDEX = -1 if search fails.
+ **/
+#ifndef C_OPTIMIZED_IMPLEMENTATION 
+
+OMX_U16 armUnPackVLC32(
+    const OMX_U8 **ppBitStream,
+    OMX_INT *pOffset,
+    const ARM_VLC32 *pCodeBook
+)
+{    
+    const OMX_U8 *pBitStream = *ppBitStream;
+    OMX_INT Offset = *pOffset;
+    OMX_U32 Value;
+    OMX_INT Index;
+        
+    armAssert(Offset>=0 && Offset<=7);
+
+    /* Read next 32 bits from stream */
+    Value = (pBitStream[0] << 24 ) | ( pBitStream[1] << 16)  | (pBitStream[2] << 8 ) | (pBitStream[3]) ;
+    Value = (Value << Offset ) | (pBitStream[4] >> (8-Offset));
+
+    /* Search through the codebook */    
+    for (Index=0; pCodeBook->codeLen != 0; Index++)
+    {
+        if (pCodeBook->codeWord == (Value >> (32 - pCodeBook->codeLen)))
+        {
+            Offset       = Offset + pCodeBook->codeLen;
+            *ppBitStream = pBitStream + (Offset >> 3) ;
+            *pOffset     = Offset & 7;
+            
+            return Index;
+        }        
+        pCodeBook++;
+    }
+
+    /* No code match found */
+    return ARM_NO_CODEBOOK_INDEX;
+}
+
+#endif
+
+/***************************************
+ * Fixed bit length Encode
+ ***************************************/
+
+/**
+ * Function: armPackBits
+ *
+ * Description:
+ * Pack a VLC code word into the bitstream
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] ppBitStream     pointer to the pointer to the current byte 
+ *                      in the bit stream.
+ * [in] pOffset         pointer to the bit position in the byte 
+ *                      pointed by *ppBitStream. Valid within 0
+ *                      to 7.
+ * [in] codeWord        Code word that need to be inserted in to the
+ *                          bitstream
+ * [in] codeLength      Length of the code word valid range 1...32
+ *
+ * [out] ppBitStream    *ppBitStream is updated after the block is encoded,
+ *                          so that it points to the current byte in the bit
+ *                          stream buffer.
+ * [out] pBitOffset     *pBitOffset is updated so that it points to the
+ *                          current bit position in the byte pointed by
+ *                          *ppBitStream.
+ *
+ * Return Value:
+ * Standard OMX_RESULT result. See enumeration for possible result codes.
+ *
+ */
+ 
+OMXResult armPackBits (
+    OMX_U8  **ppBitStream, 
+    OMX_INT *pOffset,
+    OMX_U32 codeWord, 
+    OMX_INT codeLength 
+)
+{
+    OMX_U8  *pBitStream = *ppBitStream;
+    OMX_INT Offset = *pOffset;
+    OMX_U32 Value;
+        
+    /* checking argument validity */
+    armRetArgErrIf(Offset < 0, OMX_Sts_BadArgErr);
+    armRetArgErrIf(Offset > 7, OMX_Sts_BadArgErr);
+    armRetArgErrIf(codeLength < 1, OMX_Sts_BadArgErr);
+    armRetArgErrIf(codeLength > 32, OMX_Sts_BadArgErr);
+
+    /* Prepare the first byte */
+    codeWord = codeWord << (32-codeLength);
+    Value = (pBitStream[0] >> (8-Offset)) << (8-Offset);
+    Value = Value | (codeWord >> (24+Offset));
+
+    /* Write out whole bytes */
+    while (8-Offset <= codeLength)
+    {
+        *pBitStream++ = (OMX_U8)Value;
+        codeWord   = codeWord  << (8-Offset);
+        codeLength = codeLength - (8-Offset);
+        Offset = 0;
+        Value = codeWord >> 24;
+    }
+
+    /* Write out final partial byte */
+    *pBitStream  = (OMX_U8)Value;
+    *ppBitStream = pBitStream;
+    *pOffset = Offset + codeLength;
+    
+    return  OMX_Sts_NoErr;
+}
+ 
+/***************************************
+ * Variable bit length Encode
+ ***************************************/
+
+/**
+ * Function: armPackVLC32
+ *
+ * Description:
+ * Pack a VLC code word into the bitstream
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	ppBitStream		pointer to the pointer to the current byte 
+ *                      in the bit stream.
+ * [in]	pBitOffset	    pointer to the bit position in the byte 
+ *                      pointed by *ppBitStream. Valid within 0
+ *                      to 7.
+ * [in]	 code     		VLC code word that need to be inserted in to the
+ *                      bitstream
+ *
+ * [out] ppBitStream	*ppBitStream is updated after the block is encoded,
+ *	                    so that it points to the current byte in the bit
+ *						stream buffer.
+ * [out] pBitOffset		*pBitOffset is updated so that it points to the
+ *						current bit position in the byte pointed by
+ *						*ppBitStream.
+ *
+ * Return Value:
+ * Standard OMX_RESULT result. See enumeration for possible result codes.
+ *
+ */
+ 
+OMXResult armPackVLC32 (
+    OMX_U8 **ppBitStream, 
+    OMX_INT *pBitOffset,
+    ARM_VLC32 code 
+)
+{
+    return (armPackBits(ppBitStream, pBitOffset, code.codeWord, code.codeLen));
+}
+
+/*End of File*/
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/src/armCOMM_IDCTTable.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/src/armCOMM_IDCTTable.c
new file mode 100644
index 0000000..9e4679c
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/src/armCOMM_IDCTTable.c
@@ -0,0 +1,60 @@
+/**
+ * 
+ * File Name:  armCOMM_IDCTTable.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *   
+ * File: armCOMM_IDCTTable.c
+ * Brief: Defines Tables used in IDCT computation
+ *
+ */
+
+#include "armCOMM_IDCTTable.h"
+
+     /*  Table of s(u)*A(u)*A(v)/16 at Q15
+      *  s(u)=1.0 0 <= u <= 5
+      *  s(6)=2.0
+      *  s(7)=4.0
+      *  A(0) = 2*sqrt(2)
+      *  A(u) = 4*cos(u*pi/16)  for (u!=0)
+	  */
+	  
+__align(4) const OMX_U16 armCOMM_IDCTPreScale [64] =
+{
+    0x4000, 0x58c5, 0x539f, 0x4b42, 0x4000, 0x3249, 0x4546, 0x46a1,
+    0x58c5, 0x7b21, 0x73fc, 0x6862, 0x58c5, 0x45bf, 0x6016, 0x61f8,
+    0x539f, 0x73fc, 0x6d41, 0x6254, 0x539f, 0x41b3, 0x5a82, 0x5c48,
+    0x4b42, 0x6862, 0x6254, 0x587e, 0x4b42, 0x3b21, 0x5175, 0x530d,
+    0x4000, 0x58c5, 0x539f, 0x4b42, 0x4000, 0x3249, 0x4546, 0x46a1,
+    0x3249, 0x45bf, 0x41b3, 0x3b21, 0x3249, 0x2782, 0x366d, 0x377e,
+    0x22a3, 0x300b, 0x2d41, 0x28ba, 0x22a3, 0x1b37, 0x257e, 0x263a,
+    0x11a8, 0x187e, 0x1712, 0x14c3, 0x11a8, 0x0de0, 0x131d, 0x137d    
+};
+    /* Above array armCOMM_IDCTPreScale,  in Q23 format */
+const OMX_U32 armCOMM_IDCTPreScaleU32 [64] =
+{
+    0x400000, 0x58c543, 0x539eba, 0x4b418c, 0x400000, 0x3248d4, 0x4545ea, 0x46a157,
+    0x58c543, 0x7b20d8, 0x73fbfc, 0x686214, 0x58c543, 0x45bf1f, 0x6015a5, 0x61f78b,
+    0x539eba, 0x73fbfc, 0x6d413d, 0x6253a6, 0x539eba, 0x41b328, 0x5a827a, 0x5c4869,
+    0x4b418c, 0x686214, 0x6253a6, 0x587de3, 0x4b418c, 0x3b20d8, 0x5174e0, 0x530d69,
+    0x400000, 0x58c543, 0x539eba, 0x4b418c, 0x400000, 0x3248d4, 0x4545ea, 0x46a157,
+    0x3248d4, 0x45bf1f, 0x41b328, 0x3b20d8, 0x3248d4, 0x27821d, 0x366d72, 0x377e6b,
+    0x22a2f5, 0x300ad3, 0x2d413d, 0x28ba70, 0x22a2f5, 0x1b36b9, 0x257d86, 0x26398d,
+    0x11a856, 0x187de3, 0x17121a, 0x14c35a, 0x11a856, 0x0ddf9b, 0x131cc7, 0x137ca2
+};
+   
+const OMX_U16 armCOMM_IDCTCoef [4] =
+{
+    0x5a82, /* InvSqrt2 */
+    0x30fc, /* SinPIBy8 */
+    0x7642, /* CosPIBy8 */
+    0x0000    
+};
+
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/src/armCOMM_MaskTable.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/src/armCOMM_MaskTable.c
new file mode 100644
index 0000000..3241db2
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/src/armCOMM_MaskTable.c
@@ -0,0 +1,45 @@
+/* ----------------------------------------------------------------
+ *
+ * 
+ * File Name:  armCOMM_MaskTable.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Mask Table to mask the end of array.
+ * 
+ */
+ 
+#include "omxtypes.h"
+
+#define MaskTableSize 72
+
+const OMX_U16 armCOMM_qMaskTable16[MaskTableSize] = 
+{
+        0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+        0xFFFF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+        0xFFFF, 0xFFFF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+        0xFFFF, 0xFFFF, 0xFFFF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+        0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x0000, 0x0000, 0x0000, 0x0000,
+        0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x0000, 0x0000, 0x0000, 
+        0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x0000, 0x0000, 
+        0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x0000,
+        0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF    
+};
+
+const OMX_U8 armCOMM_qMaskTable8[MaskTableSize] = 
+{
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+        0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+        0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+        0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 
+        0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 
+        0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00,  
+        0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00,  
+        0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 
+        0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF    
+};
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/api/armVC.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/api/armVC.h
new file mode 100644
index 0000000..7fa7716
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/api/armVC.h
@@ -0,0 +1,1153 @@
+/**
+ * 
+ * File Name:  armVC.h
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * File: armVideo.h
+ * Brief: Declares API's/Basic Data types used across the OpenMAX Video domain
+ *
+ */
+
+
+#ifndef _armVideo_H_
+#define _armVideo_H_
+
+#include "omxVC.h"
+#include "armCOMM_Bitstream.h"
+
+/**
+ * ARM specific state structure to hold Motion Estimation information.
+ */
+ 
+struct m4p2_MESpec
+{
+    OMXVCM4P2MEParams MEParams;
+    OMXVCM4P2MEMode   MEMode;
+};
+
+struct m4p10_MESpec
+{
+    OMXVCM4P10MEParams MEParams;
+    OMXVCM4P10MEMode   MEMode;
+};
+
+typedef struct m4p2_MESpec  ARMVCM4P2_MESpec;
+typedef struct m4p10_MESpec ARMVCM4P10_MESpec;
+
+/**
+ * Function: armVCM4P2_CompareMV
+ *
+ * Description:
+ * Performs comparision of motion vectors and SAD's to decide the
+ * best MV and SAD
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]     mvX     x coordinate of the candidate motion vector
+ * [in]     mvY     y coordinate of the candidate motion vector
+ * [in]     candSAD Candidate SAD
+ * [in]     bestMVX x coordinate of the best motion vector
+ * [in]     bestMVY y coordinate of the best motion vector
+ * [in]     bestSAD best SAD
+ *
+ * Return Value:
+ * OMX_INT -- 1 to indicate that the current sad is the best
+ *            0 to indicate that it is NOT the best SAD
+ */
+
+OMX_INT armVCM4P2_CompareMV (
+    OMX_S16 mvX,
+    OMX_S16 mvY,
+    OMX_INT candSAD,
+    OMX_S16 bestMVX,
+    OMX_S16 bestMVY,
+    OMX_INT bestSAD);
+
+/**
+ * Function: armVCM4P2_ACDCPredict
+ *
+ * Description:
+ * Performs adaptive DC/AC coefficient prediction for an intra block. Prior
+ * to the function call, prediction direction (predDir) should be selected
+ * as specified in subclause 7.4.3.1 of ISO/IEC 14496-2.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] pSrcDst     pointer to the coefficient buffer which contains
+ *                          the quantized coefficient residuals (PQF) of the
+ *                          current block
+ * [in] pPredBufRow pointer to the coefficient row buffer
+ * [in] pPredBufCol pointer to the coefficient column buffer
+ * [in] curQP       quantization parameter of the current block. curQP
+ *                          may equal to predQP especially when the current
+ *                          block and the predictor block are in the same
+ *                          macroblock.
+ * [in] predQP      quantization parameter of the predictor block
+ * [in] predDir     indicates the prediction direction which takes one
+ *                          of the following values:
+ *                          OMX_VIDEO_HORIZONTAL    predict horizontally
+ *                          OMX_VIDEO_VERTICAL      predict vertically
+ * [in] ACPredFlag  a flag indicating if AC prediction should be
+ *                          performed. It is equal to ac_pred_flag in the bit
+ *                          stream syntax of MPEG-4
+ * [in] videoComp   video component type (luminance, chrominance or
+ *                          alpha) of the current block
+ * [in] flag        This flag defines the if one wants to use this functions to
+ *                  calculate PQF (set 1, prediction) or QF (set 0, reconstruction)
+ * [out]    pPreACPredict   pointer to the predicted coefficients buffer.
+ *                          Filled ONLY if it is not NULL
+ * [out]    pSrcDst     pointer to the coefficient buffer which contains
+ *                          the quantized coefficients (QF) of the current
+ *                          block
+ * [out]    pPredBufRow pointer to the updated coefficient row buffer
+ * [out]    pPredBufCol pointer to the updated coefficient column buffer
+ * [out]    pSumErr     pointer to the updated sum of the difference
+ *                      between predicted and unpredicted coefficients
+ *                      If this is NULL, do not update
+ *
+ * Return Value:
+ * Standard OMXResult result. See enumeration for possible result codes.
+ *
+ */
+
+OMXResult armVCM4P2_ACDCPredict(
+     OMX_S16 * pSrcDst,
+     OMX_S16 * pPreACPredict,
+     OMX_S16 * pPredBufRow,
+     OMX_S16 * pPredBufCol,
+     OMX_INT curQP,
+     OMX_INT predQP,
+     OMX_INT predDir,
+     OMX_INT ACPredFlag,
+     OMXVCM4P2VideoComponent  videoComp,
+     OMX_U8 flag,
+     OMX_INT *pSumErr
+);
+
+/**
+ * Function: armVCM4P2_SetPredDir
+ *
+ * Description:
+ * Performs detecting the prediction direction
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] blockIndex  block index indicating the component type and
+ *                          position as defined in subclause 6.1.3.8, of ISO/IEC
+ *                          14496-2. Furthermore, indexes 6 to 9 indicate the
+ *                          alpha blocks spatially corresponding to luminance
+ *                          blocks 0 to 3 in the same macroblock.
+ * [in] pCoefBufRow pointer to the coefficient row buffer
+ * [in] pQpBuf      pointer to the quantization parameter buffer
+ * [out]    predQP      quantization parameter of the predictor block
+ * [out]    predDir     indicates the prediction direction which takes one
+ *                          of the following values:
+ *                          OMX_VIDEO_HORIZONTAL    predict horizontally
+ *                          OMX_VIDEO_VERTICAL      predict vertically
+ *
+ * Return Value:
+ * Standard OMXResult result. See enumeration for possible result codes.
+ *
+ */
+
+OMXResult armVCM4P2_SetPredDir(
+     OMX_INT blockIndex,
+     OMX_S16 *pCoefBufRow,
+     OMX_S16 *pCoefBufCol,
+     OMX_INT *predDir,
+     OMX_INT *predQP,
+     const OMX_U8 *pQpBuf
+);
+
+/**
+ * Function: armVCM4P2_EncodeVLCZigzag_Intra
+ *
+ * Description:
+ * Performs zigzag scanning and VLC encoding for one intra block.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] ppBitStream     pointer to the pointer to the current byte in
+ *                              the bit stream
+ * [in] pBitOffset      pointer to the bit position in the byte pointed
+ *                              by *ppBitStream. Valid within 0 to 7.
+ * [in] pQDctBlkCoef    pointer to the quantized DCT coefficient
+ * [in] predDir         AC prediction direction, which is used to decide
+ *                              the zigzag scan pattern. This takes one of the
+ *                              following values:
+ *                              OMX_VIDEO_NONE          AC prediction not used.
+ *                                                      Performs classical zigzag
+ *                                                      scan.
+ *                              OMX_VIDEO_HORIZONTAL    Horizontal prediction.
+ *                                                      Performs alternate-vertical
+ *                                                      zigzag scan.
+ *                              OMX_VIDEO_VERTICAL      Vertical prediction.
+ *                                                      Performs alternate-horizontal
+ *                                                      zigzag scan.
+ * [in] pattern         block pattern which is used to decide whether
+ *                              this block is encoded
+ * [in] start           start indicates whether the encoding begins with 0th element
+ *                      or 1st.
+ * [out]    ppBitStream     *ppBitStream is updated after the block is encoded,
+ *                              so that it points to the current byte in the bit
+ *                              stream buffer.
+ * [out]    pBitOffset      *pBitOffset is updated so that it points to the
+ *                              current bit position in the byte pointed by
+ *                              *ppBitStream.
+ *
+ * Return Value:
+ * Standard OMXResult result. See enumeration for possible result codes.
+ *
+ */
+
+OMXResult armVCM4P2_EncodeVLCZigzag_Intra(
+     OMX_U8 **ppBitStream,
+     OMX_INT *pBitOffset,
+     const OMX_S16 *pQDctBlkCoef,
+     OMX_U8 predDir,
+     OMX_U8 pattern,
+     OMX_INT shortVideoHeader,
+     OMX_U8 start
+);
+
+/**
+ * Function: armVCM4P2_DecodeVLCZigzag_Intra
+ *
+ * Description:
+ * Performs VLC decoding and inverse zigzag scan for one intra coded block.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] ppBitStream     pointer to the pointer to the current byte in
+ *                              the bitstream buffer
+ * [in] pBitOffset      pointer to the bit position in the byte pointed
+ *                              to by *ppBitStream. *pBitOffset is valid within
+ *                              [0-7].
+ * [in] predDir         AC prediction direction which is used to decide
+ *                              the zigzag scan pattern. It takes one of the
+ *                              following values:
+ *                              OMX_VIDEO_NONE  AC prediction not used;
+ *                                              perform classical zigzag scan;
+ *                              OMX_VIDEO_HORIZONTAL    Horizontal prediction;
+ *                                                      perform alternate-vertical
+ *                                                      zigzag scan;
+ *                              OMX_VIDEO_VERTICAL      Vertical prediction;
+ *                                                      thus perform
+ *                                                      alternate-horizontal
+ *                                                      zigzag scan.
+ * [in] videoComp       video component type (luminance, chrominance or
+ *                              alpha) of the current block
+ * [in] shortVideoHeader binary flag indicating presence of short_video_header; escape modes 0-3 are used if shortVideoHeader==0,
+ *                           and escape mode 4 is used when shortVideoHeader==1.
+ * [in] start           start indicates whether the encoding begins with 0th element
+ *                      or 1st.
+ * [out]    ppBitStream     *ppBitStream is updated after the block is
+ *                              decoded, so that it points to the current byte
+ *                              in the bit stream buffer
+ * [out]    pBitOffset      *pBitOffset is updated so that it points to the
+ *                              current bit position in the byte pointed by
+ *                              *ppBitStream
+ * [out]    pDst            pointer to the coefficient buffer of current
+ *                              block. Should be 32-bit aligned
+ *
+ * Return Value:
+ * Standard OMXResult result. See enumeration for possible result codes.
+ *
+ */
+
+OMXResult armVCM4P2_DecodeVLCZigzag_Intra(
+     const OMX_U8 ** ppBitStream,
+     OMX_INT * pBitOffset,
+     OMX_S16 * pDst,
+     OMX_U8 predDir,
+     OMX_INT shortVideoHeader, 
+     OMX_U8  start
+);
+
+/**
+ * Function: armVCM4P2_FillVLDBuffer
+ *
+ * Description:
+ * Performs filling of the coefficient buffer according to the run, level
+ * and sign, also updates the index
+ * 
+ * Parameters:
+ * [in]  storeRun        Stored Run value (count of zeros)   
+ * [in]  storeLevel      Stored Level value (non-zero value)
+ * [in]  sign            Flag indicating the sign of level
+ * [in]  last            status of the last flag
+ * [in]  pIndex          pointer to coefficient index in 8x8 matrix
+ * [out] pIndex          pointer to updated coefficient index in 8x8 
+ *                       matrix
+ * [in]  pZigzagTable    pointer to the zigzag tables
+ * [out] pDst            pointer to the coefficient buffer of current
+ *                       block. Should be 32-bit aligned
+ * Return Value:
+ * Standard OMXResult result. See enumeration for possible result codes.
+ *
+ */
+
+OMXResult armVCM4P2_FillVLDBuffer(
+    OMX_U32 storeRun,
+    OMX_S16 * pDst,
+    OMX_S16 storeLevel,
+    OMX_U8  sign,
+    OMX_U8  last,
+    OMX_U8  * index,
+    const OMX_U8 * pZigzagTable
+);
+
+/**
+ * Function: armVCM4P2_GetVLCBits
+ *
+ * Description:
+ * Performs escape mode decision based on the run, run+, level, level+ and 
+ * last combinations.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	ppBitStream		pointer to the pointer to the current byte in
+ *								the bit stream
+ * [in]	pBitOffset		pointer to the bit position in the byte pointed
+ *								by *ppBitStream. Valid within 0 to 7
+ * [in] shortVideoHeader binary flag indicating presence of short_video_header; escape modes 0-3 are used if shortVideoHeader==0,
+ *                           and escape mode 4 is used when shortVideoHeader==1.
+ * [in] start           start indicates whether the encoding begins with 
+ *                      0th element or 1st.
+ * [in/out] pLast       pointer to last status flag
+ * [in] runBeginSingleLevelEntriesL0      The run value from which level 
+ *                                        will be equal to 1: last == 0
+ * [in] IndexBeginSingleLevelEntriesL0    Array index in the VLC table 
+ *                                        pointing to the  
+ *                                        runBeginSingleLevelEntriesL0 
+ * [in] runBeginSingleLevelEntriesL1      The run value from which level 
+ *                                        will be equal to 1: last == 1
+ * [in] IndexBeginSingleLevelEntriesL1    Array index in the VLC table 
+ *                                        pointing to the  
+ *                                        runBeginSingleLevelEntriesL0 
+ * [in] pRunIndexTableL0    Run Index table defined in 
+ *                          armVCM4P2_Huff_Tables_VLC.c for last == 0
+ * [in] pVlcTableL0         VLC table for last == 0
+ * [in] pRunIndexTableL1    Run Index table defined in 
+ *                          armVCM4P2_Huff_Tables_VLC.c for last == 1
+ * [in] pVlcTableL1         VLC table for last == 1
+ * [in] pLMAXTableL0        Level MAX table defined in 
+ *                          armVCM4P2_Huff_Tables_VLC.c for last == 0
+ * [in] pLMAXTableL1        Level MAX table defined in 
+ *                          armVCM4P2_Huff_Tables_VLC.c for last == 1
+ * [in] pRMAXTableL0        Run MAX table defined in 
+ *                          armVCM4P2_Huff_Tables_VLC.c for last == 0
+ * [in] pRMAXTableL1        Run MAX table defined in 
+ *                          armVCM4P2_Huff_Tables_VLC.c for last == 1
+ * [out]pDst			    pointer to the coefficient buffer of current
+ *							block. Should be 32-bit aligned
+ *
+ * Return Value:
+ * Standard OMXResult result. See enumeration for possible result codes.
+ *
+ */
+
+OMXResult armVCM4P2_GetVLCBits (
+              const OMX_U8 **ppBitStream,
+              OMX_INT * pBitOffset,
+			  OMX_S16 * pDst,
+			  OMX_INT shortVideoHeader,
+			  OMX_U8    start,			  
+			  OMX_U8  * pLast,
+			  OMX_U8    runBeginSingleLevelEntriesL0,
+			  OMX_U8    maxIndexForMultipleEntriesL0,
+			  OMX_U8    maxRunForMultipleEntriesL1,
+			  OMX_U8    maxIndexForMultipleEntriesL1,
+              const OMX_U8  * pRunIndexTableL0,
+              const ARM_VLC32 *pVlcTableL0,
+			  const OMX_U8  * pRunIndexTableL1,
+              const ARM_VLC32 *pVlcTableL1,
+              const OMX_U8  * pLMAXTableL0,
+              const OMX_U8  * pLMAXTableL1,
+              const OMX_U8  * pRMAXTableL0,
+              const OMX_U8  * pRMAXTableL1,
+              const OMX_U8  * pZigzagTable
+);
+
+/**
+ * Function: armVCM4P2_PutVLCBits
+ *
+ * Description:
+ * Checks the type of Escape Mode and put encoded bits for 
+ * quantized DCT coefficients.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	 ppBitStream      pointer to the pointer to the current byte in
+ *						  the bit stream
+ * [in]	 pBitOffset       pointer to the bit position in the byte pointed
+ *                        by *ppBitStream. Valid within 0 to 7
+ * [in] shortVideoHeader binary flag indicating presence of short_video_header; escape modes 0-3 are used if shortVideoHeader==0,
+ *                           and escape mode 4 is used when shortVideoHeader==1.
+ * [in]  start            start indicates whether the encoding begins with 
+ *                        0th element or 1st.
+ * [in]  maxStoreRunL0    Max store possible (considering last and inter/intra)
+ *                        for last = 0
+ * [in]  maxStoreRunL1    Max store possible (considering last and inter/intra)
+ *                        for last = 1
+ * [in]  maxRunForMultipleEntriesL0 
+ *                        The run value after which level 
+ *                        will be equal to 1: 
+ *                        (considering last and inter/intra status) for last = 0
+ * [in]  maxRunForMultipleEntriesL1 
+ *                        The run value after which level 
+ *                        will be equal to 1: 
+ *                        (considering last and inter/intra status) for last = 1
+ * [in]  pRunIndexTableL0 Run Index table defined in 
+ *                        armVCM4P2_Huff_Tables_VLC.c for last == 0
+ * [in]  pVlcTableL0      VLC table for last == 0
+ * [in]  pRunIndexTableL1 Run Index table defined in 
+ *                        armVCM4P2_Huff_Tables_VLC.c for last == 1
+ * [in]  pVlcTableL1      VLC table for last == 1
+ * [in]  pLMAXTableL0     Level MAX table defined in 
+ *                        armVCM4P2_Huff_Tables_VLC.c for last == 0
+ * [in]  pLMAXTableL1     Level MAX table defined in 
+ *                        armVCM4P2_Huff_Tables_VLC.c for last == 1
+ * [in]  pRMAXTableL0     Run MAX table defined in 
+ *                        armVCM4P2_Huff_Tables_VLC.c for last == 0
+ * [in]  pRMAXTableL1     Run MAX table defined in 
+ *                        armVCM4P2_Huff_Tables_VLC.c for last == 1
+ * [out] pQDctBlkCoef     pointer to the quantized DCT coefficient
+ * [out] ppBitStream      *ppBitStream is updated after the block is encoded
+ *                        so that it points to the current byte in the bit
+ *                        stream buffer.
+ * [out] pBitOffset       *pBitOffset is updated so that it points to the
+ *                        current bit position in the byte pointed by
+ *                        *ppBitStream.
+ *
+ * Return Value:
+ * Standard OMXResult result. See enumeration for possible result codes.
+ *
+ */
+
+
+OMXResult armVCM4P2_PutVLCBits (
+              OMX_U8 **ppBitStream,
+              OMX_INT * pBitOffset,
+              const OMX_S16 *pQDctBlkCoef,
+              OMX_INT shortVideoHeader,
+              OMX_U8 start,
+              OMX_U8 maxStoreRunL0,
+              OMX_U8 maxStoreRunL1,
+              OMX_U8  maxRunForMultipleEntriesL0,
+              OMX_U8  maxRunForMultipleEntriesL1,
+              const OMX_U8  * pRunIndexTableL0,
+              const ARM_VLC32 *pVlcTableL0,
+			  const OMX_U8  * pRunIndexTableL1,
+              const ARM_VLC32 *pVlcTableL1,
+              const OMX_U8  * pLMAXTableL0,
+              const OMX_U8  * pLMAXTableL1,
+              const OMX_U8  * pRMAXTableL0,
+              const OMX_U8  * pRMAXTableL1,
+              const OMX_U8  * pZigzagTable
+);
+/**
+ * Function: armVCM4P2_FillVLCBuffer
+ *
+ * Description:
+ * Performs calculating the VLC bits depending on the escape type and insert 
+ * the same in the bitstream
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	 ppBitStream		pointer to the pointer to the current byte in
+ *	                        the bit stream
+ * [in]	 pBitOffset         pointer to the bit position in the byte pointed
+ *                          by *ppBitStream. Valid within 0 to 7
+ * [in]  run                Run value (count of zeros) to be encoded  
+ * [in]  level              Level value (non-zero value) to be encoded
+ * [in]  runPlus            Calculated as runPlus = run - (RMAX + 1)  
+ * [in]  levelPlus          Calculated as 
+ *                          levelPlus = sign(level)*[abs(level) - LMAX]
+ * [in]  fMode              Flag indicating the escape modes
+ * [in]  last               status of the last flag
+ * [in]  maxRunForMultipleEntries 
+ *                          The run value after which level will be equal to 1: 
+ *                          (considering last and inter/intra status)
+ * [in]  pRunIndexTable     Run Index table defined in
+ *                          armVCM4P2_Huff_tables_VLC.h
+ * [in]  pVlcTable          VLC table defined in armVCM4P2_Huff_tables_VLC.h
+ * [out] ppBitStream		*ppBitStream is updated after the block is encoded
+ *                          so that it points to the current byte in the bit
+ *                          stream buffer.
+ * [out] pBitOffset         *pBitOffset is updated so that it points to the
+ *                          current bit position in the byte pointed by
+ *                          *ppBitStream.
+ *
+ * Return Value:
+ * Standard OMXResult result. See enumeration for possible result codes.
+ *
+ */
+
+OMXResult armVCM4P2_FillVLCBuffer (
+              OMX_U8 **ppBitStream,
+              OMX_INT * pBitOffset,
+              OMX_U32 run,
+              OMX_S16 level, 
+			  OMX_U32 runPlus,
+              OMX_S16 levelPlus, 
+              OMX_U8  fMode,
+			  OMX_U8  last,
+              OMX_U8  maxRunForMultipleEntries, 
+              const OMX_U8  *pRunIndexTable,
+              const ARM_VLC32 *pVlcTable
+);
+
+/**
+ * Function: armVCM4P2_CheckVLCEscapeMode
+ *
+ * Description:
+ * Performs escape mode decision based on the run, run+, level, level+ and 
+ * last combinations.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] run             Run value (count of zeros) to be encoded  
+ * [in] level           Level value (non-zero value) to be encoded
+ * [in] runPlus         Calculated as runPlus = run - (RMAX + 1)  
+ * [in] levelPlus       Calculated as 
+ *                      levelPlus = sign(level)*[abs(level) - LMAX]
+ * [in] maxStoreRun     Max store possible (considering last and inter/intra)
+ * [in] maxRunForMultipleEntries 
+ *                      The run value after which level 
+ *                      will be equal to 1: 
+ *                      (considering last and inter/intra status)
+ * [in] shortVideoHeader binary flag indicating presence of short_video_header; escape modes 0-3 are used if shortVideoHeader==0,
+ *                           and escape mode 4 is used when shortVideoHeader==1.
+ * [in] pRunIndexTable  Run Index table defined in 
+ *                      armVCM4P2_Huff_Tables_VLC.c
+ *                      (considering last and inter/intra status)
+ *
+ *                      
+ * Return Value:
+ * Returns an Escape mode which can take values from 0 to 3
+ * 0 --> no escape mode, 1 --> escape type 1,
+ * 1 --> escape type 2, 3 --> escape type 3, check section 7.4.1.3
+ * in the MPEG ISO standard.
+ *
+ */
+
+OMX_U8 armVCM4P2_CheckVLCEscapeMode(
+     OMX_U32 run,
+     OMX_U32 runPlus,
+     OMX_S16 level,
+     OMX_S16 levelPlus,
+     OMX_U8  maxStoreRun,
+     OMX_U8  maxRunForMultipleEntries,
+     OMX_INT shortVideoHeader,
+     const OMX_U8  *pRunIndexTable
+);
+
+
+/**
+ * Function: armVCM4P2_BlockMatch_Integer
+ *
+ * Description:
+ * Performs a 16x16 block search; estimates motion vector and associated minimum SAD.  
+ * Both the input and output motion vectors are represented using half-pixel units, and 
+ * therefore a shift left or right by 1 bit may be required, respectively, to match the 
+ * input or output MVs with other functions that either generate output MVs or expect 
+ * input MVs represented using integer pixel units. 
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	pSrcRefBuf		pointer to the reference Y plane; points to the reference MB that 
+ *                    corresponds to the location of the current macroblock in the current 
+ *                    plane.
+ * [in]	refWidth		  width of the reference plane
+ * [in]	pRefRect		  pointer to the valid rectangular in reference plane. Relative to image origin. 
+ *                    It's not limited to the image boundary, but depended on the padding. For example, 
+ *                    if you pad 4 pixels outside the image border, then the value for left border 
+ *                    can be -4
+ * [in]	pSrcCurrBuf		pointer to the current macroblock extracted from original plane (linear array, 
+ *                    256 entries); must be aligned on an 8-byte boundary.
+ * [in] pCurrPointPos	position of the current macroblock in the current plane
+ * [in] pSrcPreMV		  pointer to predicted motion vector; NULL indicates no predicted MV
+ * [in] pSrcPreSAD		pointer to SAD associated with the predicted MV (referenced by pSrcPreMV)
+ * [in] searchRange		search range for 16X16 integer block,the units of it is full pixel,the search range 
+ *                    is the same in all directions.It is in inclusive of the boundary and specified in 
+ *                    terms of integer pixel units.
+ * [in] pMESpec			  vendor-specific motion estimation specification structure; must have been allocated 
+ *                    and then initialized using omxVCM4P2_MEInit prior to calling the block matching 
+ *                    function.
+ * [in] BlockSize     MacroBlock Size i.e either 16x16 or 8x8.
+ * [out]	pDstMV			pointer to estimated MV
+ * [out]	pDstSAD			pointer to minimum SAD
+ *
+ * Return Value:
+ * OMX_Sts_NoErr ¨C no error.
+ * OMX_Sts_BadArgErr ¨C bad arguments
+ *
+ */
+
+OMXResult armVCM4P2_BlockMatch_Integer(
+     const OMX_U8 *pSrcRefBuf,
+     OMX_INT refWidth,
+     const OMXRect *pRefRect,
+     const OMX_U8 *pSrcCurrBuf,
+     const OMXVCM4P2Coordinate *pCurrPointPos,
+     const OMXVCMotionVector *pSrcPreMV,
+     const OMX_INT *pSrcPreSAD,
+     void *pMESpec,
+     OMXVCMotionVector *pDstMV,
+     OMX_INT *pDstSAD,
+     OMX_U8 BlockSize
+);
+
+/**
+ * Function: armVCM4P2_BlockMatch_Half
+ *
+ * Description:
+ * Performs a 16x16 block match with half-pixel resolution.  Returns the estimated 
+ * motion vector and associated minimum SAD.  This function estimates the half-pixel 
+ * motion vector by interpolating the integer resolution motion vector referenced 
+ * by the input parameter pSrcDstMV, i.e., the initial integer MV is generated 
+ * externally.  The input parameters pSrcRefBuf and pSearchPointRefPos should be 
+ * shifted by the winning MV of 16x16 integer search prior to calling BlockMatch_Half_16x16.  
+ * The function BlockMatch_Integer_16x16 may be used for integer motion estimation.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	pSrcRefBuf		pointer to the reference Y plane; points to the reference MB 
+ *                    that corresponds to the location of the current macroblock in 
+ *                    the	current plane.
+ * [in]	refWidth		  width of the reference plane
+ * [in]	pRefRect		  reference plane valid region rectangle
+ * [in]	pSrcCurrBuf		pointer to the current macroblock extracted from original plane 
+ *                    (linear array, 256 entries); must be aligned on an 8-byte boundary. 
+ * [in]	pSearchPointRefPos	position of the starting point for half pixel search (specified 
+ *                          in terms of integer pixel units) in the reference plane.
+ * [in]	rndVal			  rounding control bit for half pixel motion estimation; 
+ *                    0=rounding control disabled; 1=rounding control enabled
+ * [in]	pSrcDstMV		pointer to the initial MV estimate; typically generated during a prior 
+ *                  16X16 integer search and its unit is half pixel.
+ * [in] BlockSize     MacroBlock Size i.e either 16x16 or 8x8.
+ * [out]pSrcDstMV		pointer to estimated MV
+ * [out]pDstSAD			pointer to minimum SAD
+ *
+ * Return Value:
+ * OMX_Sts_NoErr ¨C no error
+ * OMX_Sts_BadArgErr ¨C bad arguments
+ *
+ */
+
+OMXResult armVCM4P2_BlockMatch_Half(
+     const OMX_U8 *pSrcRefBuf,
+     OMX_INT refWidth,
+     const OMXRect *pRefRect,
+     const OMX_U8 *pSrcCurrBuf,
+     const OMXVCM4P2Coordinate *pSearchPointRefPos,
+     OMX_INT rndVal,
+     OMXVCMotionVector *pSrcDstMV,
+     OMX_INT *pDstSAD,
+     OMX_U8 BlockSize
+);
+/**
+ * Function: armVCM4P2_PadMV
+ *
+ * Description:
+ * Performs motion vector padding for a macroblock.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] pSrcDstMV       pointer to motion vector buffer of the current
+ *                              macroblock
+ * [in] pTransp         pointer to transparent status buffer of the
+ *                              current macroblock
+ * [out]    pSrcDstMV       pointer to motion vector buffer in which the
+ *                              motion vectors have been padded
+ * Return Value:
+ * Standard OMXResult result. See enumeration for possible result codes.
+ *
+ */
+
+OMXResult armVCM4P2_PadMV(
+     OMXVCMotionVector * pSrcDstMV,
+     OMX_U8 * pTransp
+);
+
+/* 
+ * H.264 Specific Declarations 
+ */
+/* Defines */
+#define ARM_M4P10_Q_OFFSET        (15)
+
+
+/* Dequant tables */
+
+extern const OMX_U8 armVCM4P10_PosToVCol4x4[16];
+extern const OMX_U8 armVCM4P10_PosToVCol2x2[4];
+extern const OMX_U8 armVCM4P10_VMatrix[6][3];
+extern const OMX_U32 armVCM4P10_MFMatrix[6][3];
+
+
+/*
+ * Description:
+ * This function perform the work required by the OpenMAX
+ * DecodeCoeffsToPair function and DecodeChromaDCCoeffsToPair.
+ * Since most of the code is common we share it here.
+ *
+ * Parameters:
+ * [in]	ppBitStream		Double pointer to current byte in bit stream buffer
+ * [in]	pOffset			Pointer to current bit position in the byte pointed
+ *								to by *ppBitStream
+ * [in]	sMaxNumCoeff	Maximum number of non-zero coefficients in current
+ *								block (4,15 or 16)
+ * [in]	nTable          Table number (0 to 4) according to the five columns
+ *                      of Table 9-5 in the H.264 spec
+ * [out]	ppBitStream		*ppBitStream is updated after each block is decoded
+ * [out]	pOffset			*pOffset is updated after each block is decoded
+ * [out]	pNumCoeff		Pointer to the number of nonzero coefficients in
+ *								this block
+ * [out]	ppPosCoefbuf	Double pointer to destination residual
+ *								coefficient-position pair buffer
+ * Return Value:
+ * Standard omxError result. See enumeration for possible result codes.
+
+ */
+
+OMXResult armVCM4P10_DecodeCoeffsToPair(
+     const OMX_U8** ppBitStream,
+     OMX_S32* pOffset,
+     OMX_U8* pNumCoeff,
+     OMX_U8**ppPosCoefbuf,
+     OMX_INT nTable,
+     OMX_INT sMaxNumCoeff        
+ );
+
+/*
+ * Description:
+ * Perform DC style intra prediction, averaging upper and left block
+ *
+ * Parameters:
+ * [in]	pSrcLeft		Pointer to the buffer of 16 left coefficients:
+ *								p[x, y] (x = -1, y = 0..3)
+ * [in]	pSrcAbove		Pointer to the buffer of 16 above coefficients:
+ *								p[x,y] (x = 0..3, y = -1)
+ * [in]	leftStep		Step of left coefficient buffer
+ * [in]	dstStep			Step of the destination buffer
+ * [in]	availability	Neighboring 16x16 MB availability flag
+ * [out]	pDst			Pointer to the destination buffer
+ *
+ * Return Value:
+ * None
+ */
+
+void armVCM4P10_PredictIntraDC4x4(
+     const OMX_U8* pSrcLeft,
+     const OMX_U8 *pSrcAbove,
+     OMX_U8* pDst,
+     OMX_INT leftStep,
+     OMX_INT dstStep,
+     OMX_S32 availability        
+);
+
+/*
+ * Description
+ * Unpack a 4x4 block of coefficient-residual pair values
+ *
+ * Parameters:
+ * [in]	ppSrc	Double pointer to residual coefficient-position pair
+ *						buffer output by CALVC decoding
+ * [out]	ppSrc	*ppSrc is updated to the start of next non empty block
+ * [out]	pDst	Pointer to unpacked 4x4 block
+ */
+
+void armVCM4P10_UnpackBlock4x4(
+     const OMX_U8 **ppSrc,
+     OMX_S16* pDst
+);
+
+/*
+ * Description
+ * Unpack a 2x2 block of coefficient-residual pair values
+ *
+ * Parameters:
+ * [in]	ppSrc	Double pointer to residual coefficient-position pair
+ *						buffer output by CALVC decoding
+ * [out]	ppSrc	*ppSrc is updated to the start of next non empty block
+ * [out]	pDst	Pointer to unpacked 4x4 block
+ */
+
+void armVCM4P10_UnpackBlock2x2(
+     const OMX_U8 **ppSrc,
+     OMX_S16* pDst
+);
+
+/*
+ * Description
+ * Deblock one boundary pixel
+ *
+ * Parameters:
+ * [in]	pQ0         Pointer to pixel q0
+ * [in] Step        Step between pixels q0 and q1
+ * [in] tC0         Edge threshold value
+ * [in] alpha       alpha threshold value
+ * [in] beta        beta threshold value
+ * [in] bS          deblocking strength
+ * [in] ChromaFlag  True for chroma blocks
+ * [out] pQ0        Deblocked pixels
+ * 
+ */
+
+void armVCM4P10_DeBlockPixel(
+    OMX_U8 *pQ0,    /* pointer to the pixel q0 */
+    int Step,       /* step between pixels q0 and q1 */
+    int tC0,        /* edge threshold value */
+    int alpha,      /* alpha */
+    int beta,       /* beta */
+    int bS,         /* deblocking strength */
+    int ChromaFlag
+);
+
+/**
+ * Function: armVCM4P10_InterpolateHalfHor_Luma
+ *
+ * Description:
+ * This function performs interpolation for horizontal 1/2-pel positions
+ *
+ * Remarks:
+ *
+ *	[in]	pSrc			Pointer to top-left corner of block used to interpolate 
+ 													in the reconstructed frame plane
+ *	[in]	iSrcStep	Step of the source buffer.
+ *	[in]	iDstStep	Step of the destination(interpolation) buffer.
+ *	[in]	iWidth		Width of the current block
+ *	[in]	iHeight		Height of the current block
+ *	[out]	pDst	    Pointer to the interpolation buffer of the 1/2-pel 
+ *
+ * Return Value:
+ * Standard OMXResult value.
+ *
+ */
+
+OMXResult armVCM4P10_InterpolateHalfHor_Luma(
+        const OMX_U8*		pSrc, 
+		OMX_U32 	iSrcStep, 
+		OMX_U8* 	pDst, 
+		OMX_U32 	iDstStep, 
+		OMX_U32 	iWidth, 
+		OMX_U32 	iHeight
+);
+
+/**
+ * Function: armVCM4P10_InterpolateHalfVer_Luma
+ * 
+ * Description:
+ * This function performs interpolation for vertical 1/2-pel positions 
+ * around a full-pel position.
+ *
+ * Remarks:
+ *
+ *	[in]	pSrc			Pointer to top-left corner of block used to interpolate 
+ *												in the reconstructed frame plane
+ *	[in]	iSrcStep	Step of the source buffer.
+ *	[in]	iDstStep	Step of the destination(interpolation) buffer.
+ *	[in]	iWidth		Width of the current block
+ *	[in]	iHeight		Height of the current block
+ *	[out]	pDst    	Pointer to the interpolation buffer of the 1/2-pel
+ *
+ * Return Value:
+ * Standard OMXResult value.
+ *
+ */
+
+OMXResult armVCM4P10_InterpolateHalfVer_Luma(	
+	 const OMX_U8* 	pSrc, 
+	 OMX_U32 	iSrcStep, 
+ 	 OMX_U8* 	pDst,
+ 	 OMX_U32 	iDstStep, 
+ 	 OMX_U32 	iWidth, 
+ 	 OMX_U32 	iHeight
+);
+
+/**
+ * Function: armVCM4P10_InterpolateHalfDiag_Luma
+ * 
+ * Description:
+ * This function performs interpolation for (1/2, 1/2)  positions 
+ * around a full-pel position.
+ *
+ * Remarks:
+ *
+ *  [in]    pSrc        Pointer to top-left corner of block used to interpolate 
+ *                      in the reconstructed frame plane
+ *  [in]    iSrcStep    Step of the source buffer.
+ *  [in]    iDstStep    Step of the destination(interpolation) buffer.
+ *  [in]    iWidth      Width of the current block
+ *  [in]    iHeight     Height of the current block
+ *  [out]   pDst        Pointer to the interpolation buffer of the (1/2,1/2)-pel
+ *
+ * Return Value:
+ * Standard OMXResult value.
+ *
+ */
+
+OMXResult armVCM4P10_InterpolateHalfDiag_Luma(  
+        const OMX_U8*     pSrc, 
+        OMX_U32     iSrcStep, 
+        OMX_U8*     pDst, 
+        OMX_U32     iDstStep,
+        OMX_U32     iWidth, 
+        OMX_U32     iHeight
+);
+
+/*
+ * Description:
+ * Transform Residual 4x4 Coefficients
+ *
+ * Parameters:
+ * [in]  pSrc		Source 4x4 block
+ * [out] pDst		Destination 4x4 block
+ *
+ */
+
+void armVCM4P10_TransformResidual4x4(OMX_S16* pDst, OMX_S16 *pSrc);
+
+/*
+ * Description:
+ * Forward Transform Residual 4x4 Coefficients
+ *
+ * Parameters:
+ * [in]  pSrc		Source 4x4 block
+ * [out] pDst		Destination 4x4 block
+ *
+ */
+
+void armVCM4P10_FwdTransformResidual4x4(OMX_S16* pDst, OMX_S16 *pSrc);
+
+OMX_INT armVCM4P10_CompareMotionCostToMV (
+    OMX_S16  mvX,
+    OMX_S16  mvY,
+    OMXVCMotionVector diffMV, 
+    OMX_INT candSAD, 
+    OMXVCMotionVector *bestMV, 
+    OMX_U32 nLamda,
+    OMX_S32 *pBestCost);
+
+/**
+ * Function: armVCCOMM_SAD
+ *
+ * Description:
+ * This function calculate the SAD for NxM blocks.
+ *
+ * Remarks:
+ *
+ * [in]		pSrcOrg		Pointer to the original block
+ * [in]		iStepOrg	Step of the original block buffer
+ * [in]		pSrcRef		Pointer to the reference block
+ * [in]		iStepRef	Step of the reference block buffer
+ * [in]		iHeight		Height of the block
+ * [in]		iWidth		Width of the block
+ * [out]	pDstSAD		Pointer of result SAD
+ *
+ * Return Value:
+ * Standard OMXResult value.
+ *
+ */
+OMXResult armVCCOMM_SAD(	
+	const OMX_U8* 	pSrcOrg,
+	OMX_U32 	iStepOrg,
+	const OMX_U8* 	pSrcRef,
+	OMX_U32 	iStepRef,
+	OMX_S32*	pDstSAD,
+	OMX_U32		iHeight,
+	OMX_U32		iWidth);
+
+/**
+ * Function: armVCCOMM_Average
+ *
+ * Description:
+ * This function calculates the average of two blocks and stores the result.
+ *
+ * Remarks:
+ *
+ *	[in]	pPred0			Pointer to the top-left corner of reference block 0
+ *	[in]	pPred1			Pointer to the top-left corner of reference block 1
+ *	[in]	iPredStep0	    Step of reference block 0
+ *	[in]	iPredStep1	    Step of reference block 1
+ *	[in]	iDstStep 		Step of the destination buffer
+ *	[in]	iWidth			Width of the blocks
+ *	[in]	iHeight			Height of the blocks
+ *	[out]	pDstPred		Pointer to the destination buffer
+ *
+ * Return Value:
+ * Standard OMXResult value.
+ *
+ */
+ OMXResult armVCCOMM_Average (
+	 const OMX_U8* 	    pPred0,
+	 const OMX_U8* 	    pPred1,	
+	 OMX_U32		iPredStep0,
+	 OMX_U32		iPredStep1,
+	 OMX_U8*		pDstPred,
+	 OMX_U32		iDstStep, 
+	 OMX_U32		iWidth,
+	 OMX_U32		iHeight
+);
+
+/**
+ * Function: armVCM4P10_SADQuar
+ *
+ * Description:
+ * This function calculates the SAD between one block (pSrc) and the 
+ * average of the other two (pSrcRef0 and pSrcRef1)
+ *
+ * Remarks:
+ *
+ * [in]		pSrc				Pointer to the original block
+ * [in]		pSrcRef0		Pointer to reference block 0
+ * [in]		pSrcRef1		Pointer to reference block 1
+ * [in]		iSrcStep 		Step of the original block buffer
+ * [in]		iRefStep0		Step of reference block 0 
+ * [in]		iRefStep1 	Step of reference block 1 
+ * [in]		iHeight			Height of the block
+ * [in]		iWidth			Width of the block
+ * [out]	pDstSAD			Pointer of result SAD
+ *
+ * Return Value:
+ * Standard OMXResult value.
+ *
+ */
+OMXResult armVCM4P10_SADQuar(
+	const OMX_U8* 	pSrc,
+    const OMX_U8* 	pSrcRef0,
+	const OMX_U8* 	pSrcRef1,	
+    OMX_U32 	iSrcStep,
+    OMX_U32		iRefStep0,
+    OMX_U32		iRefStep1,
+    OMX_U32*	pDstSAD,
+    OMX_U32     iHeight,
+    OMX_U32     iWidth
+);
+
+/**
+ * Function: armVCM4P10_Interpolate_Chroma
+ *
+ * Description:
+ * This function performs interpolation for chroma components.
+ *
+ * Remarks:
+ *
+ *  [in]    pSrc            Pointer to top-left corner of block used to 
+ *                                              interpolate in the reconstructed frame plane
+ *  [in]    iSrcStep    Step of the source buffer.
+ *  [in]    iDstStep    Step of the destination(interpolation) buffer.
+ *  [in]    iWidth      Width of the current block
+ *  [in]    iHeight     Height of the current block
+ *  [in]    dx              Fractional part of horizontal motion vector 
+ *                                              component in 1/8 pixel unit (0~7) 
+ *  [in]    dy              Fractional part of vertical motion vector 
+ *                                              component in 1/8 pixel unit (0~7)
+ *  [out]   pDst            Pointer to the interpolation buffer
+ *
+ * Return Value:
+ * Standard OMXResult value.
+ *
+ */
+ OMXResult armVCM4P10_Interpolate_Chroma(
+        OMX_U8      *pSrc,
+        OMX_U32     iSrcStep,
+        OMX_U8      *pDst,
+        OMX_U32     iDstStep,
+        OMX_U32     iWidth,
+        OMX_U32     iHeight,
+        OMX_U32     dx,
+        OMX_U32     dy
+);
+
+/**
+ * Function: armVCM4P10_Interpolate_Luma
+ *
+ * Description:
+ * This function performs interpolation for luma components.
+ *
+ * Remarks:
+ *
+ *  [in]    pSrc            Pointer to top-left corner of block used to 
+ *                                              interpolate in the reconstructed frame plane
+ *  [in]    iSrcStep    Step of the source buffer.
+ *  [in]    iDstStep    Step of the destination(interpolation) buffer.
+ *  [in]    iWidth      Width of the current block
+ *  [in]    iHeight     Height of the current block
+ *  [in]    dx              Fractional part of horizontal motion vector 
+ *                                              component in 1/4 pixel unit (0~3) 
+ *  [in]    dy              Fractional part of vertical motion vector 
+ *                                              component in 1/4 pixel unit (0~3) 
+ *  [out]   pDst            Pointer to the interpolation buffer
+ *
+ * Return Value:
+ * Standard OMXResult value.
+ *
+ */
+
+ OMXResult armVCM4P10_Interpolate_Luma(
+     const OMX_U8     *pSrc,
+     OMX_U32    iSrcStep,
+     OMX_U8     *pDst,
+     OMX_U32    iDstStep,
+     OMX_U32    iWidth,
+     OMX_U32    iHeight,
+     OMX_U32    dx,
+     OMX_U32    dy
+);
+
+/**
+ * Function: omxVCH264_DequantTransformACFromPair_U8_S16_C1_DLx
+ *
+ * Description:
+ * Reconstruct the 4x4 residual block from coefficient-position pair buffer,
+ * perform dequantisation and integer inverse transformation for 4x4 block of
+ * residuals and update the pair buffer pointer to next non-empty block.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	ppSrc		Double pointer to residual coefficient-position
+ *							pair buffer output by CALVC decoding
+ * [in]	pDC			Pointer to the DC coefficient of this block, NULL
+ *							if it doesn't exist
+ * [in]	QP			Quantization parameter
+ * [in] AC          Flag indicating if at least one non-zero coefficient exists
+ * [out]	pDst		pointer to the reconstructed 4x4 block data
+ *
+ * Return Value:
+ * Standard omxError result. See enumeration for possible result codes.
+ *
+ */
+
+OMXResult armVCM4P10_DequantTransformACFromPair_U8_S16_C1_DLx(
+     OMX_U8 **ppSrc,
+     OMX_S16 *pDst,
+     OMX_INT QP,
+     OMX_S16* pDC,
+     int AC
+);
+
+#endif  /*_armVideo_H_*/
+
+/*End of File*/
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/api/armVCCOMM_s.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/api/armVCCOMM_s.h
new file mode 100644
index 0000000..7f0a9b8
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/api/armVCCOMM_s.h
@@ -0,0 +1,72 @@
+;//
+;// 
+;// File Name:  armVCCOMM_s.h
+;// OpenMAX DL: v1.0.2
+;// Revision:   9641
+;// Date:       Thursday, February 7, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+;// ARM optimized OpenMAX AC header file
+;// 
+;// Formula used:
+;// MACRO for calculating median for three values.
+
+
+
+    IF :LNOT::DEF:ARMVCCOMM_S_H
+        INCLUDE armCOMM_s.h
+    M_VARIANTS      CortexA8, ARM1136JS
+    
+    IF ARM1136JS :LOR: CortexA8 
+     
+     ;///*
+     ;// * Macro: M_MEDIAN3
+     ;// *
+     ;// * Description: Finds the median of three numbers
+     ;// * 
+     ;// * Remarks:
+     ;// *
+     ;// * Parameters:
+     ;// * [in] x     First entry for the list of three numbers.
+     ;// * [in] y     Second entry for the list of three numbers.
+     ;// *            Input value may be corrupted at the end of
+     ;// *            the execution of this macro.
+     ;// * [in] z     Third entry of the list of three numbers.
+     ;// *            Input value corrupted at the end of the 
+     ;// *            execution of this macro.
+     ;// * [in] t     Temporary scratch  register.
+     ;// * [out]z     Median of the three numbers.       
+     ;// */
+     
+     MACRO
+
+     M_MEDIAN3 $x, $y, $z, $t 
+     
+     SUBS  $t, $y, $z; // if (y < z)
+     ADDLT $z, $z, $t; //  swap y and z
+     SUBLT $y, $y, $t;
+
+     ;// Now z' <= y', so there are three cases for the
+     ;// median value, depending on x.
+
+     ;// 1) x <= z'      <= y'      : median value is z'
+     ;// 2)      z' <= x <= y'      : median value is x
+     ;// 3)      z'      <= y' <= x : median value is y'
+
+     CMP   $z, $x;     // if ( x > min(y,z) )
+     MOVLT $z, $x;     // ans = x 
+
+     CMP   $x, $y;     // if ( x > max(y,z) )
+     MOVGT $z, $y;     // ans = max(y,z)
+     
+     MEND
+    ENDIF      
+    
+    
+        
+    ENDIF ;// ARMACCOMM_S_H
+
+ END
\ No newline at end of file
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/api/omxVC.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/api/omxVC.h
new file mode 100644
index 0000000..7b3cc72
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/api/omxVC.h
@@ -0,0 +1,4381 @@
+/**
+ * File: omxVC.h
+ * Brief: OpenMAX DL v1.0.2 - Video Coding library
+ *
+ * Copyright © 2005-2008 The Khronos Group Inc. All Rights Reserved. 
+ *
+ * These materials are protected by copyright laws and contain material 
+ * proprietary to the Khronos Group, Inc.  You may use these materials 
+ * for implementing Khronos specifications, without altering or removing 
+ * any trademark, copyright or other notice from the specification.
+ * 
+ * Khronos Group makes no, and expressly disclaims any, representations 
+ * or warranties, express or implied, regarding these materials, including, 
+ * without limitation, any implied warranties of merchantability or fitness 
+ * for a particular purpose or non-infringement of any intellectual property. 
+ * Khronos Group makes no, and expressly disclaims any, warranties, express 
+ * or implied, regarding the correctness, accuracy, completeness, timeliness, 
+ * and reliability of these materials. 
+ *
+ * Under no circumstances will the Khronos Group, or any of its Promoters, 
+ * Contributors or Members or their respective partners, officers, directors, 
+ * employees, agents or representatives be liable for any damages, whether 
+ * direct, indirect, special or consequential damages for lost revenues, 
+ * lost profits, or otherwise, arising from or in connection with these 
+ * materials.
+ * 
+ * Khronos and OpenMAX are trademarks of the Khronos Group Inc. 
+ *
+ */
+
+/* *****************************************************************************************/
+
+#ifndef _OMXVC_H_
+#define _OMXVC_H_
+
+#include "omxtypes.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* 6.1.1.1 Motion Vectors  */
+/* In omxVC, motion vectors are represented as follows:  */
+
+typedef struct {
+    OMX_S16 dx;
+    OMX_S16 dy;
+} OMXVCMotionVector;
+
+
+
+/**
+ * Function:  omxVCCOMM_Average_8x   (6.1.3.1.1)
+ *
+ * Description:
+ * This function calculates the average of two 8x4, 8x8, or 8x16 blocks.  The 
+ * result is rounded according to (a+b+1)/2.  The block average function can 
+ * be used in conjunction with half-pixel interpolation to obtain quarter 
+ * pixel motion estimates, as described in [ISO14496-10], subclause 8.4.2.2.1. 
+ *
+ * Input Arguments:
+ *   
+ *   pPred0     - Pointer to the top-left corner of reference block 0 
+ *   pPred1     - Pointer to the top-left corner of reference block 1 
+ *   iPredStep0 - Step of reference block 0 
+ *   iPredStep1 - Step of reference block 1 
+ *   iDstStep   - Step of the destination buffer. 
+ *   iHeight    - Height of the blocks 
+ *
+ * Output Arguments:
+ *   
+ *   pDstPred - Pointer to the destination buffer. 8-byte aligned. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned under any of the following 
+ *              conditions: 
+ *    -   one or more of the following pointers is NULL: pPred0, pPred1, or 
+ *              pDstPred. 
+ *    -   pDstPred is not aligned on an 8-byte boundary. 
+ *    -   iPredStep0 <= 0 or iPredStep0 is not a multiple of 8. 
+ *    -   iPredStep1 <= 0 or iPredStep1 is not a multiple of 8. 
+ *    -   iDstStep   <= 0 or iDstStep is not a multiple of 8. 
+ *    -   iHeight is not 4, 8, or 16. 
+ *
+ */
+OMXResult omxVCCOMM_Average_8x (
+    const OMX_U8 *pPred0,
+    const OMX_U8 *pPred1,
+    OMX_U32 iPredStep0,
+    OMX_U32 iPredStep1,
+    OMX_U8 *pDstPred,
+    OMX_U32 iDstStep,
+    OMX_U32 iHeight
+);
+
+
+
+/**
+ * Function:  omxVCCOMM_Average_16x   (6.1.3.1.2)
+ *
+ * Description:
+ * This function calculates the average of two 16x16 or 16x8 blocks.  The 
+ * result is rounded according to (a+b+1)/2.  The block average function can 
+ * be used in conjunction with half-pixel interpolation to obtain quarter 
+ * pixel motion estimates, as described in [ISO14496-10], subclause 8.4.2.2.1. 
+ *
+ * Input Arguments:
+ *   
+ *   pPred0 - Pointer to the top-left corner of reference block 0 
+ *   pPred1 - Pointer to the top-left corner of reference block 1 
+ *   iPredStep0 - Step of reference block 0 
+ *   iPredStep1 - Step of reference block 1 
+ *   iDstStep - Step of the destination buffer 
+ *   iHeight - Height of the blocks 
+ *
+ * Output Arguments:
+ *   
+ *   pDstPred - Pointer to the destination buffer. 16-byte aligned. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned under any of the following 
+ *              conditions: 
+ *    -   one or more of the following pointers is NULL: pPred0, pPred1, or 
+ *              pDstPred. 
+ *    -   pDstPred is not aligned on a 16-byte boundary. 
+ *    -   iPredStep0 <= 0 or iPredStep0 is not a multiple of 16. 
+ *    -   iPredStep1 <= 0 or iPredStep1 is not a multiple of 16. 
+ *    -   iDstStep <= 0 or iDstStep is not a multiple of 16. 
+ *    -   iHeight is not 8 or 16. 
+ *
+ */
+OMXResult omxVCCOMM_Average_16x (
+    const OMX_U8 *pPred0,
+    const OMX_U8 *pPred1,
+    OMX_U32 iPredStep0,
+    OMX_U32 iPredStep1,
+    OMX_U8 *pDstPred,
+    OMX_U32 iDstStep,
+    OMX_U32 iHeight
+);
+
+
+
+/**
+ * Function:  omxVCCOMM_ExpandFrame_I   (6.1.3.2.1)
+ *
+ * Description:
+ * This function expands a reconstructed frame in-place.  The unexpanded 
+ * source frame should be stored in a plane buffer with sufficient space 
+ * pre-allocated for edge expansion, and the input frame should be located in 
+ * the plane buffer center.  This function executes the pixel expansion by 
+ * replicating source frame edge pixel intensities in the empty pixel 
+ * locations (expansion region) between the source frame edge and the plane 
+ * buffer edge.  The width/height of the expansion regions on the 
+ * horizontal/vertical edges is controlled by the parameter iExpandPels. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDstPlane - pointer to the top-left corner of the frame to be 
+ *            expanded; must be aligned on an 8-byte boundary. 
+ *   iFrameWidth - frame width; must be a multiple of 8. 
+ *   iFrameHeight -frame height; must be a multiple of 8. 
+ *   iExpandPels - number of pixels to be expanded in the horizontal and 
+ *            vertical directions; must be a multiple of 8. 
+ *   iPlaneStep - distance, in bytes, between the start of consecutive lines 
+ *            in the plane buffer; must be larger than or equal to 
+ *            (iFrameWidth + 2 * iExpandPels). 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDstPlane -Pointer to the top-left corner of the frame (NOT the 
+ *            top-left corner of the plane); must be aligned on an 8-byte 
+ *            boundary. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned under any of the following 
+ *              conditions: 
+ *    -    pSrcDstPlane is NULL. 
+ *    -    pSrcDstPlane is not aligned on an 8-byte boundary. 
+ *    -    one of the following parameters is either equal to zero or is a 
+ *              non-multiple of 8: iFrameHeight, iFrameWidth, iPlaneStep, or 
+ *              iExpandPels. 
+ *    -    iPlaneStep < (iFrameWidth + 2 * iExpandPels). 
+ *
+ */
+OMXResult omxVCCOMM_ExpandFrame_I (
+    OMX_U8 *pSrcDstPlane,
+    OMX_U32 iFrameWidth,
+    OMX_U32 iFrameHeight,
+    OMX_U32 iExpandPels,
+    OMX_U32 iPlaneStep
+);
+
+
+
+/**
+ * Function:  omxVCCOMM_Copy8x8   (6.1.3.3.1)
+ *
+ * Description:
+ * Copies the reference 8x8 block to the current block. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - pointer to the reference block in the source frame; must be 
+ *            aligned on an 8-byte boundary. 
+ *   step - distance between the starts of consecutive lines in the reference 
+ *            frame, in bytes; must be a multiple of 8 and must be larger than 
+ *            or equal to 8. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - pointer to the destination block; must be aligned on an 8-byte 
+ *            boundary. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned under any of the following 
+ *              conditions: 
+ *    -   one or more of the following pointers is NULL: pSrc, pDst 
+ *    -   one or more of the following pointers is not aligned on an 8-byte 
+ *              boundary: pSrc, pDst 
+ *    -    step <8 or step is not a multiple of 8. 
+ *
+ */
+OMXResult omxVCCOMM_Copy8x8 (
+    const OMX_U8 *pSrc,
+    OMX_U8 *pDst,
+    OMX_INT step
+);
+
+
+
+/**
+ * Function:  omxVCCOMM_Copy16x16   (6.1.3.3.2)
+ *
+ * Description:
+ * Copies the reference 16x16 macroblock to the current macroblock. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - pointer to the reference macroblock in the source frame; must be 
+ *            aligned on a 16-byte boundary. 
+ *   step - distance between the starts of consecutive lines in the reference 
+ *            frame, in bytes; must be a multiple of 16 and must be larger 
+ *            than or equal to 16. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - pointer to the destination macroblock; must be aligned on a 
+ *            16-byte boundary. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned under any of the following 
+ *              conditions: 
+ *    -   one or more of the following pointers is NULL: pSrc, pDst 
+ *    -   one or more of the following pointers is not aligned on a 16-byte 
+ *              boundary: pSrc, pDst 
+ *    -    step <16 or step is not a multiple of 16. 
+ *
+ */
+OMXResult omxVCCOMM_Copy16x16 (
+    const OMX_U8 *pSrc,
+    OMX_U8 *pDst,
+    OMX_INT step
+);
+
+
+
+/**
+ * Function:  omxVCCOMM_ComputeTextureErrorBlock_SAD   (6.1.4.1.1)
+ *
+ * Description:
+ * Computes texture error of the block; also returns SAD. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - pointer to the source plane; must be aligned on an 8-byte 
+ *            boundary. 
+ *   srcStep - step of the source plane 
+ *   pSrcRef - pointer to the reference buffer, an 8x8 block; must be aligned 
+ *            on an 8-byte boundary. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - pointer to the destination buffer, an 8x8 block; must be aligned 
+ *            on an 8-byte boundary. 
+ *   pDstSAD - pointer to the Sum of Absolute Differences (SAD) value 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments 
+ *    -    At least one of the following 
+ *         pointers is NULL: pSrc, pSrcRef, pDst and pDstSAD. 
+ *    -    pSrc is not 8-byte aligned. 
+ *    -    SrcStep <= 0 or srcStep is not a multiple of 8. 
+ *    -    pSrcRef is not 8-byte aligned. 
+ *    -    pDst is not 8-byte aligned. 
+ *
+ */
+OMXResult omxVCCOMM_ComputeTextureErrorBlock_SAD (
+    const OMX_U8 *pSrc,
+    OMX_INT srcStep,
+    const OMX_U8 *pSrcRef,
+    OMX_S16 *pDst,
+    OMX_INT *pDstSAD
+);
+
+
+
+/**
+ * Function:  omxVCCOMM_ComputeTextureErrorBlock   (6.1.4.1.2)
+ *
+ * Description:
+ * Computes the texture error of the block. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - pointer to the source plane. This should be aligned on an 8-byte 
+ *            boundary. 
+ *   srcStep - step of the source plane 
+ *   pSrcRef - pointer to the reference buffer, an 8x8 block. This should be 
+ *            aligned on an 8-byte boundary. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - pointer to the destination buffer, an 8x8 block. This should be 
+ *            aligned on an 8-byte boundary. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments:
+ *    -    At least one of the following pointers is NULL: 
+ *         pSrc, pSrcRef, pDst. 
+ *    -    pSrc is not 8-byte aligned. 
+ *    -    SrcStep <= 0 or srcStep is not a multiple of 8. 
+ *    -    pSrcRef is not 8-byte aligned. 
+ *    -    pDst is not 8-byte aligned 
+ *
+ */
+OMXResult omxVCCOMM_ComputeTextureErrorBlock (
+    const OMX_U8 *pSrc,
+    OMX_INT srcStep,
+    const OMX_U8 *pSrcRef,
+    OMX_S16 *pDst
+);
+
+
+
+/**
+ * Function:  omxVCCOMM_LimitMVToRect   (6.1.4.1.3)
+ *
+ * Description:
+ * Limits the motion vector associated with the current block/macroblock to 
+ * prevent the motion compensated block/macroblock from moving outside a 
+ * bounding rectangle as shown in Figure 6-1. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcMV - pointer to the motion vector associated with the current block 
+ *            or macroblock 
+ *   pRectVOPRef - pointer to the bounding rectangle 
+ *   Xcoord, Ycoord  - coordinates of the current block or macroblock 
+ *   size - size of the current block or macroblock; must be equal to 8 or 
+ *            16. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstMV - pointer to the limited motion vector 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments.  Returned if one or more of the 
+ *              following conditions is true: 
+ *    -    at least one of the following pointers is NULL: 
+ *         pSrcMV, pDstMV, or pRectVOPRef. 
+ *    -    size is not equal to either 8 or 16. 
+ *    -    the width or height of the bounding rectangle is less than 
+ *         twice the block size.
+ */
+OMXResult omxVCCOMM_LimitMVToRect (
+    const OMXVCMotionVector *pSrcMV,
+    OMXVCMotionVector *pDstMV,
+    const OMXRect *pRectVOPRef,
+    OMX_INT Xcoord,
+    OMX_INT Ycoord,
+    OMX_INT size
+);
+
+
+
+/**
+ * Function:  omxVCCOMM_SAD_16x   (6.1.4.1.4)
+ *
+ * Description:
+ * This function calculates the SAD for 16x16 and 16x8 blocks. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcOrg - Pointer to the original block; must be aligned on a 16-byte 
+ *             boundary. 
+ *   iStepOrg - Step of the original block buffer 
+ *   pSrcRef  - Pointer to the reference block 
+ *   iStepRef - Step of the reference block buffer 
+ *   iHeight  - Height of the block 
+ *
+ * Output Arguments:
+ *   
+ *   pDstSAD - Pointer of result SAD 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments.  Returned if one or more of the 
+ *              following conditions is true: 
+ *    -    at least one of the following pointers is NULL: 
+ *         pSrcOrg, pDstSAD, or pSrcRef 
+ *    -    pSrcOrg is not 16-byte aligned. 
+ *    -    iStepOrg  <= 0 or iStepOrg is not a multiple of 16 
+ *    -    iStepRef <= 0 or iStepRef is not a multiple of 16 
+ *    -    iHeight is not 8 or 16 
+ *
+ */
+OMXResult omxVCCOMM_SAD_16x (
+    const OMX_U8 *pSrcOrg,
+    OMX_U32 iStepOrg,
+    const OMX_U8 *pSrcRef,
+    OMX_U32 iStepRef,
+    OMX_S32 *pDstSAD,
+    OMX_U32 iHeight
+);
+
+
+
+/**
+ * Function:  omxVCCOMM_SAD_8x   (6.1.4.1.5)
+ *
+ * Description:
+ * This function calculates the SAD for 8x16, 8x8, 8x4 blocks. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcOrg  - Pointer to the original block; must be aligned on a 8-byte 
+ *              boundary. 
+ *   iStepOrg - Step of the original block buffer 
+ *   pSrcRef  - Pointer to the reference block 
+ *   iStepRef - Step of the reference block buffer 
+ *   iHeight  - Height of the block 
+ *
+ * Output Arguments:
+ *   
+ *   pDstSAD -Pointer of result SAD 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments.  Returned if one or more of the 
+ *              following conditions is true: 
+ *    -    at least one of the following pointers is NULL: 
+ *         pSrcOrg, pDstSAD, or pSrcRef 
+ *    -    pSrcOrg is not 8-byte aligned. 
+ *    -    iStepOrg  <= 0 or iStepOrg is not a multiple of 8 
+ *    -    iStepRef <= 0 or iStepRef is not a multiple of 8 
+ *    -    iHeight is not 4, 8 or 16 
+ *
+ */
+OMXResult omxVCCOMM_SAD_8x (
+    const OMX_U8 *pSrcOrg,
+    OMX_U32 iStepOrg,
+    const OMX_U8 *pSrcRef,
+    OMX_U32 iStepRef,
+    OMX_S32*pDstSAD,
+    OMX_U32 iHeight
+);
+
+
+
+/* 6.2.1.1 Direction  */
+/* The direction enumerator is used with functions that perform AC/DC prediction and zig-zag scan.  */
+
+enum {
+    OMX_VC_NONE       = 0,
+    OMX_VC_HORIZONTAL = 1,
+    OMX_VC_VERTICAL   = 2 
+};
+
+
+
+/* 6.2.1.2 Bilinear Interpolation  */
+/* The bilinear interpolation enumerator is used with motion estimation, motion compensation, and reconstruction functions.  */
+
+enum {
+    OMX_VC_INTEGER_PIXEL = 0, /* case a */
+    OMX_VC_HALF_PIXEL_X  = 1, /* case b */
+    OMX_VC_HALF_PIXEL_Y  = 2, /* case c */
+    OMX_VC_HALF_PIXEL_XY = 3  /* case d */ 
+};
+
+
+
+/* 6.2.1.3 Neighboring Macroblock Availability  */
+/* Neighboring macroblock availability is indicated using the following flags:   */
+
+enum {
+    OMX_VC_UPPER = 1,        /** above macroblock is available */
+    OMX_VC_LEFT = 2,         /** left macroblock is available */
+    OMX_VC_CENTER = 4,
+    OMX_VC_RIGHT = 8,
+    OMX_VC_LOWER = 16,
+    OMX_VC_UPPER_LEFT = 32,  /** above-left macroblock is available */
+    OMX_VC_UPPER_RIGHT = 64, /** above-right macroblock is available */
+    OMX_VC_LOWER_LEFT = 128,
+    OMX_VC_LOWER_RIGHT = 256 
+};
+
+
+
+/* 6.2.1.4 Video Components  */
+/* A data type that enumerates video components is defined as follows:  */
+
+typedef enum {
+    OMX_VC_LUMINANCE,    /** Luminance component */
+    OMX_VC_CHROMINANCE   /** chrominance component */ 
+} OMXVCM4P2VideoComponent;
+
+
+
+/* 6.2.1.5 MacroblockTypes  */
+/* A data type that enumerates macroblock types is defined as follows:  */
+
+typedef enum {
+    OMX_VC_INTER     = 0, /** P picture or P-VOP */
+    OMX_VC_INTER_Q   = 1, /** P picture or P-VOP */
+    OMX_VC_INTER4V   = 2, /** P picture or P-VOP */
+    OMX_VC_INTRA     = 3, /** I and P picture, I- and P-VOP */
+    OMX_VC_INTRA_Q   = 4, /** I and P picture, I- and P-VOP */
+    OMX_VC_INTER4V_Q = 5  /** P picture or P-VOP (H.263)*/
+} OMXVCM4P2MacroblockType;
+
+
+
+/* 6.2.1.6 Coordinates  */
+/* Coordinates are represented as follows:  */
+
+typedef struct {
+    OMX_INT x;
+    OMX_INT y;
+} OMXVCM4P2Coordinate;
+
+
+
+/* 6.2.1.7 Motion Estimation Algorithms  */
+/* A data type that enumerates motion estimation search methods is defined as follows:  */
+
+typedef enum {
+    OMX_VC_M4P2_FAST_SEARCH = 0,  /** Fast motion search */
+    OMX_VC_M4P2_FULL_SEARCH = 1   /** Full motion search */ 
+} OMXVCM4P2MEMode;
+
+
+
+/* 6.2.1.8 Motion Estimation Parameters  */
+/* A data structure containing control parameters for 
+ * motion estimation functions is defined as follows:  
+ */
+
+typedef struct {
+    OMX_INT searchEnable8x8;     /** enables 8x8 search */
+    OMX_INT halfPelSearchEnable; /** enables half-pel resolution */
+    OMX_INT searchRange;         /** search range */
+    OMX_INT rndVal;              /** rounding control; 0-disabled, 1-enabled*/
+} OMXVCM4P2MEParams;
+
+
+
+/* 6.2.1.9 Macroblock Information   */
+/* A data structure containing macroblock parameters for 
+ * motion estimation functions is defined as follows:  
+ */
+
+typedef struct {
+    OMX_S32 sliceId;                 /* slice number */
+    OMXVCM4P2MacroblockType mbType;  /* MB type: OMX_VC_INTRA, OMX_VC_INTER, or OMX_VC_INTER4 */
+    OMX_S32 qp;                      /* quantization parameter*/
+    OMX_U32 cbpy;                    /* CBP Luma */
+    OMX_U32 cbpc;                    /* CBP Chroma */
+    OMXVCMotionVector pMV0[2][2];    /* motion vector, represented using 1/2-pel units, 
+                                      * pMV0[blocky][blockx] (blocky = 0~1, blockx =0~1) 
+                                      */
+    OMXVCMotionVector pMVPred[2][2]; /* motion vector prediction, represented using 1/2-pel units, 
+                                      * pMVPred[blocky][blockx] (blocky = 0~1, blockx = 0~1) 
+                                      */
+    OMX_U8 pPredDir[2][2];           /* AC prediction direction: 
+                                      *   OMX_VC_NONE, OMX_VC_VERTICAL, OMX_VC_HORIZONTAL 
+                                      */
+} OMXVCM4P2MBInfo, *OMXVCM4P2MBInfoPtr;
+
+
+
+/**
+ * Function:  omxVCM4P2_FindMVpred   (6.2.3.1.1)
+ *
+ * Description:
+ * Predicts a motion vector for the current block using the procedure 
+ * specified in [ISO14496-2], subclause 7.6.5.  The resulting predicted MV is 
+ * returned in pDstMVPred. If the parameter pDstMVPredME if is not NULL then 
+ * the set of three MV candidates used for prediction is also returned, 
+ * otherwise pDstMVPredMEis NULL upon return. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcMVCurMB - pointer to the MV buffer associated with the current Y 
+ *            macroblock; a value of NULL indicates unavailability. 
+ *   pSrcCandMV1 - pointer to the MV buffer containing the 4 MVs associated 
+ *            with the MB located to the left of the current MB; set to NULL 
+ *            if there is no MB to the left. 
+ *   pSrcCandMV2 - pointer to the MV buffer containing the 4 MVs associated 
+ *            with the MB located above the current MB; set to NULL if there 
+ *            is no MB located above the current MB. 
+ *   pSrcCandMV3 - pointer to the MV buffer containing the 4 MVs associated 
+ *            with the MB located to the right and above the current MB; set 
+ *            to NULL if there is no MB located to the above-right. 
+ *   iBlk - the index of block in the current macroblock 
+ *   pDstMVPredME - MV candidate return buffer;  if set to NULL then 
+ *            prediction candidate MVs are not returned and pDstMVPredME will 
+ *            be NULL upon function return; if pDstMVPredME is non-NULL then it 
+ *            must point to a buffer containing sufficient space for three 
+ *            return MVs. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstMVPred - pointer to the predicted motion vector 
+ *   pDstMVPredME - if non-NULL upon input then pDstMVPredME  points upon 
+ *            return to a buffer containing the three motion vector candidates 
+ *            used for prediction as specified in [ISO14496-2], subclause 
+ *            7.6.5, otherwise if NULL upon input then pDstMVPredME is NULL 
+ *            upon output. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned under any of the following 
+ *              conditions: 
+ *    -    the pointer pDstMVPred is NULL 
+ *    -    the parameter iBlk does not fall into the range 0 <= iBlk<=3 
+ *
+ */
+OMXResult omxVCM4P2_FindMVpred (
+    const OMXVCMotionVector *pSrcMVCurMB,
+    const OMXVCMotionVector *pSrcCandMV1,
+    const OMXVCMotionVector *pSrcCandMV2,
+    const OMXVCMotionVector *pSrcCandMV3,
+    OMXVCMotionVector *pDstMVPred,
+    OMXVCMotionVector *pDstMVPredME,
+    OMX_INT iBlk
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_IDCT8x8blk   (6.2.3.2.1)
+ *
+ * Description:
+ * Computes a 2D inverse DCT for a single 8x8 block, as defined in 
+ * [ISO14496-2]. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - pointer to the start of the linearly arranged IDCT input buffer; 
+ *            must be aligned on a 16-byte boundary.  According to 
+ *            [ISO14496-2], the input coefficient values should lie within the 
+ *            range [-2048, 2047]. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - pointer to the start of the linearly arranged IDCT output buffer; 
+ *            must be aligned on a 16-byte boundary. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments:
+ *    -    pSrc or pDst is NULL. 
+ *    -    pSrc or pDst is not 16-byte aligned. 
+ *
+ */
+OMXResult omxVCM4P2_IDCT8x8blk (
+    const OMX_S16 *pSrc,
+    OMX_S16 *pDst
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_MEGetBufSize   (6.2.4.1.1)
+ *
+ * Description:
+ * Computes the size, in bytes, of the vendor-specific specification 
+ * structure for the following motion estimation functions: 
+ * BlockMatch_Integer_8x8, BlockMatch_Integer_16x16, and MotionEstimationMB. 
+ *
+ * Input Arguments:
+ *   
+ *   MEmode - motion estimation mode; available modes are defined by the 
+ *            enumerated type OMXVCM4P2MEMode 
+ *   pMEParams - motion estimation parameters 
+ *
+ * Output Arguments:
+ *   
+ *   pSize - pointer to the number of bytes required for the specification 
+ *            structure 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - one or more of the following is true: 
+ *    -    an invalid value was specified for the parameter MEmode 
+ *    -    a negative or zero value was specified for the 
+ *         parameter pMEParams->searchRange 
+ *
+ */
+OMXResult omxVCM4P2_MEGetBufSize (
+    OMXVCM4P2MEMode MEmode,
+    const OMXVCM4P2MEParams *pMEParams,
+    OMX_U32 *pSize
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_MEInit   (6.2.4.1.2)
+ *
+ * Description:
+ * Initializes the vendor-specific specification structure required for the 
+ * following motion estimation functions:  BlockMatch_Integer_8x8, 
+ * BlockMatch_Integer_16x16, and MotionEstimationMB. Memory for the 
+ * specification structure *pMESpec must be allocated prior to calling the 
+ * function, and should be aligned on a 4-byte boundary.  Following 
+ * initialization by this function, the vendor-specific structure *pMESpec 
+ * should contain an implementation-specific representation of all motion 
+ * estimation parameters received via the structure pMEParams, for example  
+ * rndVal, searchRange, etc.  The number of bytes required for the 
+ * specification structure can be determined using the function 
+ * omxVCM4P2_MEGetBufSize. 
+ *
+ * Input Arguments:
+ *   
+ *   MEmode - motion estimation mode; available modes are defined by the 
+ *            enumerated type OMXVCM4P2MEMode 
+ *   pMEParams - motion estimation parameters 
+ *   pMESpec - pointer to the uninitialized ME specification structure 
+ *
+ * Output Arguments:
+ *   
+ *   pMESpec - pointer to the initialized ME specification structure 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - one or more of the following is true: 
+ *    -    an invalid value was specified for the parameter MEmode 
+ *    -    a negative or zero value was specified for the 
+ *         parameter pMEParams->searchRange 
+ *
+ */
+OMXResult omxVCM4P2_MEInit (
+    OMXVCM4P2MEMode MEmode,
+    const OMXVCM4P2MEParams*pMEParams,
+    void *pMESpec
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_BlockMatch_Integer_16x16   (6.2.4.2.1)
+ *
+ * Description:
+ * Performs a 16x16 block search; estimates motion vector and associated 
+ * minimum SAD. Both the input and output motion vectors are represented using 
+ * half-pixel units, and therefore a shift left or right by 1 bit may be 
+ * required, respectively, to match the input or output MVs with other 
+ * functions that either generate output MVs or expect input MVs represented 
+ * using integer pixel units. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcRefBuf - pointer to the reference Y plane; points to the reference 
+ *            MB that corresponds to the location of the current macroblock in 
+ *            the current plane. 
+ *   refWidth - width of the reference plane 
+ *   pRefRect - pointer to the valid reference plane rectangle; coordinates 
+ *            are specified relative to the image origin.  Rectangle 
+ *            boundaries may extend beyond image boundaries if the image has 
+ *            been padded.  For example, if padding extends 4 pixels beyond 
+ *            frame border, then the value for the left border could be set to 
+ *            -4. 
+ *   pSrcCurrBuf - pointer to the current block in the current macroblock 
+ *            buffer extracted from the original plane (linear array, 256 
+ *            entries); must be aligned on a 16-byte boundary.  The number of 
+ *            bytes between lines (step) is 16. 
+ *   pCurrPointPos - position of the current macroblock in the current plane 
+ *   pSrcPreMV - pointer to predicted motion vector; NULL indicates no 
+ *            predicted MV 
+ *   pSrcPreSAD - pointer to SAD associated with the predicted MV (referenced 
+ *            by pSrcPreMV); may be set to NULL if unavailable. 
+ *   pMESpec - vendor-specific motion estimation specification structure; 
+ *            must have been allocated and then initialized using 
+ *            omxVCM4P2_MEInit prior to calling the block matching function. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstMV - pointer to estimated MV 
+ *   pDstSAD - pointer to minimum SAD 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments.  Returned if one of the following 
+ *              conditions is true: 
+ *    -    at least one of the following pointers is NULL: pSrcRefBuf, 
+ *              pRefRect, pSrcCurrBuff, pCurrPointPos, pDstMV, pDstSAD or 
+ *              pMESpec, or 
+ *    -    pSrcCurrBuf is not 16-byte aligned 
+ *
+ */
+OMXResult omxVCM4P2_BlockMatch_Integer_16x16 (
+    const OMX_U8 *pSrcRefBuf,
+    OMX_INT refWidth,
+    const OMXRect *pRefRect,
+    const OMX_U8 *pSrcCurrBuf,
+    const OMXVCM4P2Coordinate *pCurrPointPos,
+    const OMXVCMotionVector*pSrcPreMV,
+    const OMX_INT *pSrcPreSAD,
+    void *pMESpec,
+    OMXVCMotionVector*pDstMV,
+    OMX_INT *pDstSAD
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_BlockMatch_Integer_8x8   (6.2.4.2.2)
+ *
+ * Description:
+ * Performs an 8x8 block search; estimates motion vector and associated 
+ * minimum SAD.  Both the input and output motion vectors are represented 
+ * using half-pixel units, and therefore a shift left or right by 1 bit may be 
+ * required, respectively, to match the input or output MVs with other 
+ * functions that either generate output MVs or expect input MVs represented 
+ * using integer pixel units. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcRefBuf - pointer to the reference Y plane; points to the reference 
+ *            block that corresponds to the location of the current 8x8 block 
+ *            in the current plane. 
+ *   refWidth - width of the reference plane 
+ *   pRefRect - pointer to the valid reference plane rectangle; coordinates 
+ *            are specified relative to the image origin.  Rectangle 
+ *            boundaries may extend beyond image boundaries if the image has 
+ *            been padded. 
+ *   pSrcCurrBuf - pointer to the current block in the current macroblock 
+ *            buffer extracted from the original plane (linear array, 128 
+ *            entries); must be aligned on an 8-byte boundary.  The number of 
+ *            bytes between lines (step) is 16 bytes. 
+ *   pCurrPointPos - position of the current block in the current plane 
+ *   pSrcPreMV - pointer to predicted motion vector; NULL indicates no 
+ *            predicted MV 
+ *   pSrcPreSAD - pointer to SAD associated with the predicted MV (referenced 
+ *            by pSrcPreMV); may be set to NULL if unavailable. 
+ *   pMESpec - vendor-specific motion estimation specification structure; 
+ *            must have been allocated and then initialized using 
+ *            omxVCM4P2_MEInit prior to calling the block matching function. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstMV - pointer to estimated MV 
+ *   pDstSAD - pointer to minimum SAD 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments.  Returned if one of the following 
+ *              conditions is true: 
+ *    -    at least one of the following pointers is NULL: pSrcRefBuf, 
+ *              pRefRect, pSrcCurrBuff, pCurrPointPos, pDstMV, pDstSAD or 
+ *              pMESpec, or 
+ *    -    pSrcCurrBuf is not 8-byte aligned 
+ *
+ */
+OMXResult omxVCM4P2_BlockMatch_Integer_8x8 (
+    const OMX_U8 *pSrcRefBuf,
+    OMX_INT refWidth,
+    const OMXRect *pRefRect,
+    const OMX_U8 *pSrcCurrBuf,
+    const OMXVCM4P2Coordinate *pCurrPointPos,
+    const OMXVCMotionVector *pSrcPreMV,
+    const OMX_INT *pSrcPreSAD,
+    void *pMESpec,
+    OMXVCMotionVector *pDstMV,
+    OMX_INT *pDstSAD
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_BlockMatch_Half_16x16   (6.2.4.2.3)
+ *
+ * Description:
+ * Performs a 16x16 block match with half-pixel resolution.  Returns the 
+ * estimated motion vector and associated minimum SAD.  This function 
+ * estimates the half-pixel motion vector by interpolating the integer 
+ * resolution motion vector referenced by the input parameter pSrcDstMV, i.e., 
+ * the initial integer MV is generated externally.  The input parameters 
+ * pSrcRefBuf and pSearchPointRefPos should be shifted by the winning MV of 
+ * 16x16 integer search prior to calling BlockMatch_Half_16x16. The function 
+ * BlockMatch_Integer_16x16 may be used for integer motion estimation. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcRefBuf - pointer to the reference Y plane; points to the reference 
+ *            macroblock that corresponds to the location of the current 
+ *            macroblock in the current plane. 
+ *   refWidth - width of the reference plane 
+ *   pRefRect - reference plane valid region rectangle 
+ *   pSrcCurrBuf - pointer to the current block in the current macroblock 
+ *            buffer extracted from the original plane (linear array, 256 
+ *            entries); must be aligned on a 16-byte boundary.  The number of 
+ *            bytes between lines (step) is 16. 
+ *   pSearchPointRefPos - position of the starting point for half pixel 
+ *            search (specified in terms of integer pixel units) in the 
+ *            reference plane, i.e., the reference position pointed to by the 
+ *            predicted motion vector. 
+ *   rndVal - rounding control parameter: 0 - disabled; 1 - enabled. 
+ *   pSrcDstMV - pointer to the initial MV estimate; typically generated 
+ *            during a prior 16X16 integer search; specified in terms of 
+ *            half-pixel units. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDstMV - pointer to estimated MV 
+ *   pDstSAD - pointer to minimum SAD 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments.  Returned if one of the following 
+ *              conditions is true: 
+ *    -    at least one of the following pointers is NULL: pSrcRefBuf, 
+ *         pRefRect, pSrcCurrBuff, pSearchPointRefPos, pSrcDstMV.
+ *    -    pSrcCurrBuf is not 16-byte aligned, or 
+ *
+ */
+OMXResult omxVCM4P2_BlockMatch_Half_16x16 (
+    const OMX_U8 *pSrcRefBuf,
+    OMX_INT refWidth,
+    const OMXRect *pRefRect,
+    const OMX_U8 *pSrcCurrBuf,
+    const OMXVCM4P2Coordinate *pSearchPointRefPos,
+    OMX_INT rndVal,
+    OMXVCMotionVector *pSrcDstMV,
+    OMX_INT *pDstSAD
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_BlockMatch_Half_8x8   (6.2.4.2.4)
+ *
+ * Description:
+ * Performs an 8x8 block match with half-pixel resolution. Returns the 
+ * estimated motion vector and associated minimum SAD.  This function 
+ * estimates the half-pixel motion vector by interpolating the integer 
+ * resolution motion vector referenced by the input parameter pSrcDstMV, i.e., 
+ * the initial integer MV is generated externally.  The input parameters 
+ * pSrcRefBuf and pSearchPointRefPos should be shifted by the winning MV of 
+ * 8x8 integer search prior to calling BlockMatch_Half_8x8. The function 
+ * BlockMatch_Integer_8x8 may be used for integer motion estimation. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcRefBuf - pointer to the reference Y plane; points to the reference 
+ *            block that corresponds to the location of the current 8x8 block 
+ *            in the current plane. 
+ *   refWidth - width of the reference plane 
+ *   pRefRect - reference plane valid region rectangle 
+ *   pSrcCurrBuf - pointer to the current block in the current macroblock 
+ *            buffer extracted from the original plane (linear array, 128 
+ *            entries); must be aligned on a 8-byte boundary.  The number of 
+ *            bytes between lines (step) is 16. 
+ *   pSearchPointRefPos - position of the starting point for half pixel 
+ *            search (specified in terms of integer pixel units) in the 
+ *            reference plane. 
+ *   rndVal - rounding control parameter: 0 - disabled; 1 - enabled. 
+ *   pSrcDstMV - pointer to the initial MV estimate; typically generated 
+ *            during a prior 8x8 integer search, specified in terms of 
+ *            half-pixel units. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDstMV - pointer to estimated MV 
+ *   pDstSAD - pointer to minimum SAD 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments.  Returned if one of the following 
+ *              conditions is true: 
+ *    -    at least one of the following pointers is NULL: 
+ *         pSrcRefBuf, pRefRect, pSrcCurrBuff, pSearchPointRefPos, pSrcDstMV
+ *    -    pSrcCurrBuf is not 8-byte aligned 
+ *
+ */
+OMXResult omxVCM4P2_BlockMatch_Half_8x8 (
+    const OMX_U8 *pSrcRefBuf,
+    OMX_INT refWidth,
+    const OMXRect *pRefRect,
+    const OMX_U8 *pSrcCurrBuf,
+    const OMXVCM4P2Coordinate *pSearchPointRefPos,
+    OMX_INT rndVal,
+    OMXVCMotionVector *pSrcDstMV,
+    OMX_INT *pDstSAD
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_MotionEstimationMB   (6.2.4.3.1)
+ *
+ * Description:
+ * Performs motion search for a 16x16 macroblock.  Selects best motion search 
+ * strategy from among inter-1MV, inter-4MV, and intra modes.  Supports 
+ * integer and half pixel resolution. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcCurrBuf - pointer to the top-left corner of the current MB in the 
+ *            original picture plane; must be aligned on a 16-byte boundary.  
+ *            The function does not expect source data outside the region 
+ *            bounded by the MB to be available; for example it is not 
+ *            necessary for the caller to guarantee the availability of 
+ *            pSrcCurrBuf[-SrcCurrStep], i.e., the row of pixels above the MB 
+ *            to be processed. 
+ *   srcCurrStep - width of the original picture plane, in terms of full 
+ *            pixels; must be a multiple of 16. 
+ *   pSrcRefBuf - pointer to the reference Y plane; points to the reference 
+ *            plane location corresponding to the location of the current 
+ *            macroblock in the current plane; must be aligned on a 16-byte 
+ *            boundary. 
+ *   srcRefStep - width of the reference picture plane, in terms of full 
+ *            pixels; must be a multiple of 16. 
+ *   pRefRect - reference plane valid region rectangle, specified relative to 
+ *            the image origin 
+ *   pCurrPointPos - position of the current macroblock in the current plane 
+ *   pMESpec - pointer to the vendor-specific motion estimation specification 
+ *            structure; must be allocated and then initialized using 
+ *            omxVCM4P2_MEInit prior to calling this function. 
+ *   pMBInfo - array, of dimension four, containing pointers to information 
+ *            associated with four nearby MBs: 
+ *            -   pMBInfo[0] - pointer to left MB information 
+ *            -   pMBInfo[1] - pointer to top MB information 
+ *            -   pMBInfo[2] - pointer to top-left MB information 
+ *            -   pMBInfo[3] - pointer to top-right MB information 
+ *            Any pointer in the array may be set equal to NULL if the 
+ *            corresponding MB doesn't exist.  For each MB, the following structure 
+ *            members are used:    
+ *            -   mbType - macroblock type, either OMX_VC_INTRA, OMX_VC_INTER, or 
+ *                OMX_VC_INTER4V 
+ *            -   pMV0[2][2] - estimated motion vectors; represented 
+ *                in 1/2 pixel units 
+ *            -   sliceID - number of the slice to which the MB belongs 
+ *   pSrcDstMBCurr - pointer to information structure for the current MB.  
+ *            The following entries should be set prior to calling the 
+ *            function: sliceID - the number of the slice the to which the 
+ *            current MB belongs.  The structure elements cbpy and cbpc are 
+ *            ignored. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDstMBCurr - pointer to updated information structure for the current 
+ *            MB after MB-level motion estimation has been completed.  The 
+ *            following structure members are updated by the ME function:   
+ *              -  mbType - macroblock type: OMX_VC_INTRA, OMX_VC_INTER, or 
+ *                 OMX_VC_INTER4V. 
+ *              -  pMV0[2][2] - estimated motion vectors; represented in 
+ *                 terms of 1/2 pel units. 
+ *              -  pMVPred[2][2] - predicted motion vectors; represented 
+ *                 in terms of 1/2 pel units. 
+ *            The structure members cbpy and cbpc are not updated by the function. 
+ *   pDstSAD - pointer to the minimum SAD for INTER1V, or sum of minimum SADs 
+ *            for INTER4V 
+ *   pDstBlockSAD - pointer to an array of SAD values for each of the four 
+ *            8x8 luma blocks in the MB.  The block SADs are in scan order for 
+ *            each MB. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments.  Returned if one or more of the 
+ *              following conditions is true: 
+ *    -    at least one of the following pointers is NULL: pSrcCurrBuf, 
+ *              pSrcRefBuf, pRefRect, pCurrPointPos, pMBInter, pMBIntra, 
+ *              pSrcDstMBCurr, or pDstSAD. 
+ *
+ */
+OMXResult omxVCM4P2_MotionEstimationMB (
+    const OMX_U8 *pSrcCurrBuf,
+    OMX_S32 srcCurrStep,
+    const OMX_U8 *pSrcRefBuf,
+    OMX_S32 srcRefStep,
+    const OMXRect*pRefRect,
+    const OMXVCM4P2Coordinate *pCurrPointPos,
+    void *pMESpec,
+    const OMXVCM4P2MBInfoPtr *pMBInfo,
+    OMXVCM4P2MBInfo *pSrcDstMBCurr,
+    OMX_U16 *pDstSAD,
+    OMX_U16 *pDstBlockSAD
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_DCT8x8blk   (6.2.4.4.1)
+ *
+ * Description:
+ * Computes a 2D forward DCT for a single 8x8 block, as defined in 
+ * [ISO14496-2]. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - pointer to the start of the linearly arranged input buffer; must 
+ *            be aligned on a 16-byte boundary.  Input values (pixel 
+ *            intensities) are valid in the range [-255,255]. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - pointer to the start of the linearly arranged output buffer; must 
+ *            be aligned on a 16-byte boundary. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments, returned if:
+ *    -    pSrc or pDst is NULL. 
+ *    -    pSrc or pDst is not 16-byte aligned. 
+ *
+ */
+OMXResult omxVCM4P2_DCT8x8blk (
+    const OMX_S16 *pSrc,
+    OMX_S16 *pDst
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_QuantIntra_I   (6.2.4.4.2)
+ *
+ * Description:
+ * Performs quantization on intra block coefficients. This function supports 
+ * bits_per_pixel == 8. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - pointer to the input intra block coefficients; must be aligned 
+ *            on a 16-byte boundary. 
+ *   QP - quantization parameter (quantizer_scale). 
+ *   blockIndex - block index indicating the component type and position, 
+ *            valid in the range 0 to 5, as defined in [ISO14496-2], subclause 
+ *            6.1.3.8. 
+ *   shortVideoHeader - binary flag indicating presence of 
+ *            short_video_header; shortVideoHeader==1 selects linear intra DC 
+ *            mode, and shortVideoHeader==0 selects non linear intra DC mode. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst - pointer to the output (quantized) interblock coefficients.  
+ *            When shortVideoHeader==1, AC coefficients are saturated on the 
+ *            interval [-127, 127], and DC coefficients are saturated on the 
+ *            interval [1, 254].  When shortVideoHeader==0, AC coefficients 
+ *            are saturated on the interval [-2047, 2047]. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments:
+ *    -    pSrcDst is NULL. 
+ *    -    blockIndex < 0 or blockIndex >= 10 
+ *    -    QP <= 0 or QP >= 32. 
+ *
+ */
+OMXResult omxVCM4P2_QuantIntra_I (
+    OMX_S16 *pSrcDst,
+    OMX_U8 QP,
+    OMX_INT blockIndex,
+    OMX_INT shortVideoHeader
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_QuantInter_I   (6.2.4.4.3)
+ *
+ * Description:
+ * Performs quantization on an inter coefficient block; supports 
+ * bits_per_pixel == 8. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - pointer to the input inter block coefficients; must be aligned 
+ *            on a 16-byte boundary. 
+ *   QP - quantization parameter (quantizer_scale) 
+ *   shortVideoHeader - binary flag indicating presence of short_video_header; 
+ *            shortVideoHeader==1 selects linear intra DC mode, and 
+ *            shortVideoHeader==0 selects non linear intra DC mode. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst - pointer to the output (quantized) interblock coefficients.  
+ *            When shortVideoHeader==1, AC coefficients are saturated on the 
+ *            interval [-127, 127], and DC coefficients are saturated on the 
+ *            interval [1, 254].  When shortVideoHeader==0, AC coefficients 
+ *            are saturated on the interval [-2047, 2047]. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments:
+ *    -    pSrcDst is NULL. 
+ *    -    QP <= 0 or QP >= 32. 
+ *
+ */
+OMXResult omxVCM4P2_QuantInter_I (
+    OMX_S16 *pSrcDst,
+    OMX_U8 QP,
+    OMX_INT shortVideoHeader
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_TransRecBlockCoef_intra   (6.2.4.4.4)
+ *
+ * Description:
+ * Quantizes the DCT coefficients, implements intra block AC/DC coefficient 
+ * prediction, and reconstructs the current intra block texture for prediction 
+ * on the next frame.  Quantized row and column coefficients are returned in 
+ * the updated coefficient buffers. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - pointer to the pixels of current intra block; must be aligned on 
+ *            an 8-byte boundary. 
+ *   pPredBufRow - pointer to the coefficient row buffer containing 
+ *            ((num_mb_per_row * 2 + 1) * 8) elements of type OMX_S16. 
+ *            Coefficients are organized into blocks of eight as described 
+ *            below (Internal Prediction Coefficient Update Procedures).  The 
+ *            DC coefficient is first, and the remaining buffer locations 
+ *            contain the quantized AC coefficients. Each group of eight row 
+ *            buffer elements combined with one element eight elements ahead 
+ *            contains the coefficient predictors of the neighboring block 
+ *            that is spatially above or to the left of the block currently to 
+ *            be decoded. A negative-valued DC coefficient indicates that this 
+ *            neighboring block is not INTRA-coded or out of bounds, and 
+ *            therefore the AC and DC coefficients are invalid.  Pointer must 
+ *            be aligned on an 8-byte boundary. 
+ *   pPredBufCol - pointer to the prediction coefficient column buffer 
+ *            containing 16 elements of type OMX_S16. Coefficients are 
+ *            organized as described in section 6.2.2.5.  Pointer must be 
+ *            aligned on an 8-byte boundary. 
+ *   pSumErr - pointer to a flag indicating whether or not AC prediction is 
+ *            required; AC prediction is enabled if *pSumErr >=0, but the 
+ *            value is not used for coefficient prediction, i.e., the sum of 
+ *            absolute differences starts from 0 for each call to this 
+ *            function.  Otherwise AC prediction is disabled if *pSumErr < 0 . 
+ *   blockIndex - block index indicating the component type and position, as 
+ *            defined in [ISO14496-2], subclause 6.1.3.8. 
+ *   curQp - quantization parameter of the macroblock to which the current 
+ *            block belongs 
+ *   pQpBuf - pointer to a 2-element quantization parameter buffer; pQpBuf[0] 
+ *            contains the quantization parameter associated with the 8x8 
+ *            block left of the current block (QPa), and pQpBuf[1] contains 
+ *            the quantization parameter associated with the 8x8 block above 
+ *            the current block (QPc).  In the event that the corresponding 
+ *            block is outside of the VOP bound, the Qp value will not affect 
+ *            the intra prediction process, as described in [ISO14496-2], 
+ *            sub-clause 7.4.3.3,  Adaptive AC Coefficient Prediction.  
+ *   srcStep - width of the source buffer; must be a multiple of 8. 
+ *   dstStep - width of the reconstructed destination buffer; must be a 
+ *            multiple of 16. 
+ *   shortVideoHeader - binary flag indicating presence of 
+ *            short_video_header; shortVideoHeader==1 selects linear intra DC 
+ *            mode, and shortVideoHeader==0 selects non linear intra DC mode. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - pointer to the quantized DCT coefficient buffer; pDst[0] contains 
+ *            the predicted DC coefficient; the remaining entries contain the 
+ *            quantized AC coefficients (without prediction).  The pointer 
+ *            pDstmust be aligned on a 16-byte boundary. 
+ *   pRec - pointer to the reconstructed texture; must be aligned on an 
+ *            8-byte boundary. 
+ *   pPredBufRow - pointer to the updated coefficient row buffer 
+ *   pPredBufCol - pointer to the updated coefficient column buffer 
+ *   pPreACPredict - if prediction is enabled, the parameter points to the 
+ *            start of the buffer containing the coefficient differences for 
+ *            VLC encoding. The entry pPreACPredict[0]indicates prediction 
+ *            direction for the current block and takes one of the following 
+ *            values: OMX_VC_NONE (prediction disabled), OMX_VC_HORIZONTAL, or 
+ *            OMX_VC_VERTICAL.  The entries 
+ *            pPreACPredict[1]-pPreACPredict[7]contain predicted AC 
+ *            coefficients.  If prediction is disabled (*pSumErr<0) then the 
+ *            contents of this buffer are undefined upon return from the 
+ *            function 
+ *   pSumErr - pointer to the value of the accumulated AC coefficient errors, 
+ *            i.e., sum of the absolute differences between predicted and 
+ *            unpredicted AC coefficients 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - Bad arguments:
+ *    -    At least one of the following pointers is NULL: pSrc, pDst, pRec, 
+ *         pCoefBufRow, pCoefBufCol, pQpBuf, pPreACPredict, pSumErr. 
+ *    -    blockIndex < 0 or blockIndex >= 10; 
+ *    -    curQP <= 0 or curQP >= 32. 
+ *    -    srcStep, or dstStep <= 0 or not a multiple of 8. 
+ *    -    pDst is not 16-byte aligned: . 
+ *    -    At least one of the following pointers is not 8-byte aligned: 
+ *         pSrc, pRec.  
+ *
+ *  Note: The coefficient buffers must be updated in accordance with the 
+ *        update procedures defined in section in 6.2.2. 
+ *
+ */
+OMXResult omxVCM4P2_TransRecBlockCoef_intra (
+    const OMX_U8 *pSrc,
+    OMX_S16 *pDst,
+    OMX_U8 *pRec,
+    OMX_S16 *pPredBufRow,
+    OMX_S16 *pPredBufCol,
+    OMX_S16 *pPreACPredict,
+    OMX_INT *pSumErr,
+    OMX_INT blockIndex,
+    OMX_U8 curQp,
+    const OMX_U8 *pQpBuf,
+    OMX_INT srcStep,
+    OMX_INT dstStep,
+    OMX_INT shortVideoHeader
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_TransRecBlockCoef_inter   (6.2.4.4.5)
+ *
+ * Description:
+ * Implements DCT, and quantizes the DCT coefficients of the inter block 
+ * while reconstructing the texture residual. There is no boundary check for 
+ * the bit stream buffer. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc -pointer to the residuals to be encoded; must be aligned on an 
+ *            16-byte boundary. 
+ *   QP - quantization parameter. 
+ *   shortVideoHeader - binary flag indicating presence of short_video_header; 
+ *                      shortVideoHeader==1 selects linear intra DC mode, and 
+ *                      shortVideoHeader==0 selects non linear intra DC mode. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - pointer to the quantized DCT coefficients buffer; must be aligned 
+ *            on a 16-byte boundary. 
+ *   pRec - pointer to the reconstructed texture residuals; must be aligned 
+ *            on a 16-byte boundary. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments:
+ *    -    At least one of the following pointers is either NULL or 
+ *         not 16-byte aligned: 
+ *            - pSrc 
+ *            - pDst
+ *            - pRec
+ *    -    QP <= 0 or QP >= 32. 
+ *
+ */
+OMXResult omxVCM4P2_TransRecBlockCoef_inter (
+    const OMX_S16 *pSrc,
+    OMX_S16 *pDst,
+    OMX_S16 *pRec,
+    OMX_U8 QP,
+    OMX_INT shortVideoHeader
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_EncodeVLCZigzag_IntraDCVLC   (6.2.4.5.2)
+ *
+ * Description:
+ * Performs zigzag scan and VLC encoding of AC and DC coefficients for one 
+ * intra block.  Two versions of the function (DCVLC and ACVLC) are provided 
+ * in order to support the two different methods of processing DC 
+ * coefficients, as described in [ISO14496-2], subclause 7.4.1.4, "Intra DC 
+ * Coefficient Decoding for the Case of Switched VLC Encoding".  
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - double pointer to the current byte in the bitstream 
+ *   pBitOffset - pointer to the bit position in the byte pointed by 
+ *            *ppBitStream. Valid within 0 to 7. 
+ *   pQDctBlkCoef - pointer to the quantized DCT coefficient 
+ *   predDir - AC prediction direction, which is used to decide the zigzag 
+ *            scan pattern; takes one of the following values: 
+ *            -  OMX_VC_NONE - AC prediction not used.  
+ *                             Performs classical zigzag scan. 
+ *            -  OMX_VC_HORIZONTAL - Horizontal prediction.  
+ *                             Performs alternate-vertical zigzag scan. 
+ *            -  OMX_VC_VERTICAL - Vertical prediction.  
+ *                             Performs alternate-horizontal zigzag scan. 
+ *   pattern - block pattern which is used to decide whether this block is 
+ *            encoded 
+ *   shortVideoHeader - binary flag indicating presence of 
+ *            short_video_header; escape modes 0-3 are used if 
+ *            shortVideoHeader==0, and escape mode 4 is used when 
+ *            shortVideoHeader==1. 
+ *   videoComp - video component type (luminance, chrominance) of the current 
+ *            block 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after the block is encoded, so 
+ *            that it points to the current byte in the bit stream buffer. 
+ *   pBitOffset - *pBitOffset is updated so that it points to the current bit 
+ *            position in the byte pointed by *ppBitStream. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - Bad arguments:
+ *    -    At least one of the following pointers is NULL: ppBitStream, 
+ *              *ppBitStream, pBitOffset, pQDctBlkCoef. 
+ *    -   *pBitOffset < 0, or *pBitOffset >7. 
+ *    -    PredDir is not one of: OMX_VC_NONE, OMX_VC_HORIZONTAL, or 
+ *         OMX_VC_VERTICAL. 
+ *    -    VideoComp is not one component of enum OMXVCM4P2VideoComponent. 
+ *
+ */
+OMXResult omxVCM4P2_EncodeVLCZigzag_IntraDCVLC (
+    OMX_U8 **ppBitStream,
+    OMX_INT *pBitOffset,
+    const OMX_S16 *pQDctBlkCoef,
+    OMX_U8 predDir,
+    OMX_U8 pattern,
+    OMX_INT shortVideoHeader,
+    OMXVCM4P2VideoComponent videoComp
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_EncodeVLCZigzag_IntraACVLC   (6.2.4.5.2)
+ *
+ * Description:
+ * Performs zigzag scan and VLC encoding of AC and DC coefficients for one 
+ * intra block.  Two versions of the function (DCVLC and ACVLC) are provided 
+ * in order to support the two different methods of processing DC 
+ * coefficients, as described in [ISO14496-2], subclause 7.4.1.4,  Intra DC 
+ * Coefficient Decoding for the Case of Switched VLC Encoding.  
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - double pointer to the current byte in the bitstream 
+ *   pBitOffset - pointer to the bit position in the byte pointed by 
+ *            *ppBitStream. Valid within 0 to 7. 
+ *   pQDctBlkCoef - pointer to the quantized DCT coefficient 
+ *   predDir - AC prediction direction, which is used to decide the zigzag 
+ *            scan pattern; takes one of the following values: 
+ *            -  OMX_VC_NONE - AC prediction not used.  
+ *                             Performs classical zigzag scan. 
+ *            -  OMX_VC_HORIZONTAL - Horizontal prediction.  
+ *                             Performs alternate-vertical zigzag scan. 
+ *            -  OMX_VC_VERTICAL - Vertical prediction.  
+ *                             Performs alternate-horizontal zigzag scan. 
+ *   pattern - block pattern which is used to decide whether this block is 
+ *            encoded 
+ *   shortVideoHeader - binary flag indicating presence of 
+ *            short_video_header; escape modes 0-3 are used if 
+ *            shortVideoHeader==0, and escape mode 4 is used when 
+ *            shortVideoHeader==1. 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after the block is encoded, so 
+ *            that it points to the current byte in the bit stream buffer. 
+ *   pBitOffset - *pBitOffset is updated so that it points to the current bit 
+ *            position in the byte pointed by *ppBitStream. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - Bad arguments:
+ *    -    At least one of the following pointers is NULL: ppBitStream, 
+ *              *ppBitStream, pBitOffset, pQDctBlkCoef. 
+ *    -   *pBitOffset < 0, or *pBitOffset >7. 
+ *    -    PredDir is not one of: OMX_VC_NONE, OMX_VC_HORIZONTAL, or 
+ *         OMX_VC_VERTICAL. 
+ *    -    VideoComp is not one component of enum OMXVCM4P2VideoComponent. 
+ *
+ */
+OMXResult omxVCM4P2_EncodeVLCZigzag_IntraACVLC (
+    OMX_U8 **ppBitStream,
+    OMX_INT *pBitOffset,
+    const OMX_S16 *pQDctBlkCoef,
+    OMX_U8 predDir,
+    OMX_U8 pattern,
+    OMX_INT shortVideoHeader
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_EncodeVLCZigzag_Inter   (6.2.4.5.3)
+ *
+ * Description:
+ * Performs classical zigzag scanning and VLC encoding for one inter block. 
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - pointer to the pointer to the current byte in the bit 
+ *            stream 
+ *   pBitOffset - pointer to the bit position in the byte pointed by 
+ *            *ppBitStream. Valid within 0 to 7 
+ *   pQDctBlkCoef - pointer to the quantized DCT coefficient 
+ *   pattern - block pattern which is used to decide whether this block is 
+ *            encoded 
+ *   shortVideoHeader - binary flag indicating presence of 
+ *            short_video_header; escape modes 0-3 are used if 
+ *            shortVideoHeader==0, and escape mode 4 is used when 
+ *            shortVideoHeader==1. 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after the block is encoded so that 
+ *            it points to the current byte in the bit stream buffer. 
+ *   pBitOffset - *pBitOffset is updated so that it points to the current bit 
+ *            position in the byte pointed by *ppBitStream. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - Bad arguments 
+ *    -    At least one of the pointers: is NULL: ppBitStream, *ppBitStream, 
+ *              pBitOffset, pQDctBlkCoef 
+ *    -   *pBitOffset < 0, or *pBitOffset >7. 
+ *
+ */
+OMXResult omxVCM4P2_EncodeVLCZigzag_Inter (
+    OMX_U8 **ppBitStream,
+    OMX_INT *pBitOffset,
+    const OMX_S16 *pQDctBlkCoef,
+    OMX_U8 pattern,
+    OMX_INT shortVideoHeader
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_EncodeMV   (6.2.4.5.4)
+ *
+ * Description:
+ * Predicts a motion vector for the current macroblock, encodes the 
+ * difference, and writes the output to the stream buffer. The input MVs 
+ * pMVCurMB, pSrcMVLeftMB, pSrcMVUpperMB, and pSrcMVUpperRightMB should lie 
+ * within the ranges associated with the input parameter fcodeForward, as 
+ * described in [ISO14496-2], subclause 7.6.3.  This function provides a 
+ * superset of the functionality associated with the function 
+ * omxVCM4P2_FindMVpred. 
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - double pointer to the current byte in the bitstream buffer 
+ *   pBitOffset - index of the first free (next available) bit in the stream 
+ *            buffer referenced by *ppBitStream, valid in the range 0 to 7. 
+ *   pMVCurMB - pointer to the current macroblock motion vector; a value of 
+ *            NULL indicates unavailability. 
+ *   pSrcMVLeftMB - pointer to the source left macroblock motion vector; a 
+ *            value of  NULLindicates unavailability. 
+ *   pSrcMVUpperMB - pointer to source upper macroblock motion vector; a 
+ *            value of NULL indicates unavailability. 
+ *   pSrcMVUpperRightMB - pointer to source upper right MB motion vector; a 
+ *            value of NULL indicates unavailability. 
+ *   fcodeForward - an integer with values from 1 to 7; used in encoding 
+ *            motion vectors related to search range, as described in 
+ *            [ISO14496-2], subclause 7.6.3. 
+ *   MBType - macro block type, valid in the range 0 to 5 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - updated pointer to the current byte in the bit stream 
+ *            buffer 
+ *   pBitOffset - updated index of the next available bit position in stream 
+ *            buffer referenced by *ppBitStream 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments 
+ *    -    At least one of the following pointers is NULL: ppBitStream, 
+ *              *ppBitStream, pBitOffset, pMVCurMB 
+ *    -    *pBitOffset < 0, or *pBitOffset >7. 
+ *    -    fcodeForward <= 0, or fcodeForward > 7, or MBType < 0. 
+ *
+ */
+OMXResult omxVCM4P2_EncodeMV (
+    OMX_U8 **ppBitStream,
+    OMX_INT *pBitOffset,
+    const OMXVCMotionVector *pMVCurMB,
+    const OMXVCMotionVector*pSrcMVLeftMB,
+    const OMXVCMotionVector *pSrcMVUpperMB,
+    const OMXVCMotionVector *pSrcMVUpperRightMB,
+    OMX_INT fcodeForward,
+    OMXVCM4P2MacroblockType MBType
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_DecodePadMV_PVOP   (6.2.5.1.1)
+ *
+ * Description:
+ * Decodes and pads the four motion vectors associated with a non-intra P-VOP 
+ * macroblock.  For macroblocks of type OMX_VC_INTER4V, the output MV is 
+ * padded as specified in [ISO14496-2], subclause 7.6.1.6. Otherwise, for 
+ * macroblocks of types other than OMX_VC_INTER4V, the decoded MV is copied to 
+ * all four output MV buffer entries. 
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - pointer to the pointer to the current byte in the bit 
+ *            stream buffer 
+ *   pBitOffset - pointer to the bit position in the byte pointed to by 
+ *            *ppBitStream. *pBitOffset is valid within [0-7]. 
+ *   pSrcMVLeftMB, pSrcMVUpperMB, and pSrcMVUpperRightMB - pointers to the 
+ *            motion vector buffers of the macroblocks specially at the left, 
+ *            upper, and upper-right side of the current macroblock, 
+ *            respectively; a value of NULL indicates unavailability.  Note: 
+ *            Any neighborhood macroblock outside the current VOP or video 
+ *            packet or outside the current GOB (when short_video_header is 
+ *             1 ) for which gob_header_empty is  0  is treated as 
+ *            transparent, according to [ISO14496-2], subclause 7.6.5. 
+ *   fcodeForward - a code equal to vop_fcode_forward in MPEG-4 bit stream 
+ *            syntax 
+ *   MBType - the type of the current macroblock. If MBType is not equal to 
+ *            OMX_VC_INTER4V, the destination motion vector buffer is still 
+ *            filled with the same decoded vector. 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after the block is decoded, so 
+ *            that it points to the current byte in the bit stream buffer 
+ *   pBitOffset - *pBitOffset is updated so that it points to the current bit 
+ *            position in the byte pointed by *ppBitStream 
+ *   pDstMVCurMB - pointer to the motion vector buffer for the current 
+ *            macroblock; contains four decoded motion vectors 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments:
+ *    -    At least one of the following pointers is NULL: 
+ *         ppBitStream, *ppBitStream, pBitOffset, pDstMVCurMB 
+ *    -    *pBitOffset exceeds [0,7]
+ *    -    fcodeForward exceeds (0,7]
+ *    -    MBType less than zero
+ *    -    motion vector buffer is not 4-byte aligned. 
+ *    OMX_Sts_Err - status error 
+ *
+ */
+OMXResult omxVCM4P2_DecodePadMV_PVOP (
+    const OMX_U8 **ppBitStream,
+    OMX_INT *pBitOffset,
+    OMXVCMotionVector *pSrcMVLeftMB,
+    OMXVCMotionVector*pSrcMVUpperMB,
+    OMXVCMotionVector *pSrcMVUpperRightMB,
+    OMXVCMotionVector*pDstMVCurMB,
+    OMX_INT fcodeForward,
+    OMXVCM4P2MacroblockType MBType
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_DecodeVLCZigzag_IntraDCVLC   (6.2.5.2.2)
+ *
+ * Description:
+ * Performs VLC decoding and inverse zigzag scan of AC and DC coefficients 
+ * for one intra block.  Two versions of the function (DCVLC and ACVLC) are 
+ * provided in order to support the two different methods of processing DC 
+ * coefficients, as described in [ISO14496-2], subclause 7.4.1.4,  Intra DC 
+ * Coefficient Decoding for the Case of Switched VLC Encoding.  
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - pointer to the pointer to the current byte in the 
+ *            bitstream buffer 
+ *   pBitOffset - pointer to the bit position in the current byte referenced 
+ *            by *ppBitStream.  The parameter *pBitOffset is valid in the 
+ *            range [0-7]. 
+ *            Bit Position in one byte:  |Most      Least| 
+ *                    *pBitOffset        |0 1 2 3 4 5 6 7| 
+ *   predDir - AC prediction direction; used to select the zigzag scan 
+ *            pattern; takes one of the following values: 
+ *            -  OMX_VC_NONE - AC prediction not used; 
+ *                             performs classical zigzag scan. 
+ *            -  OMX_VC_HORIZONTAL - Horizontal prediction; 
+ *                             performs alternate-vertical zigzag scan; 
+ *            -  OMX_VC_VERTICAL - Vertical prediction; 
+ *                             performs alternate-horizontal zigzag scan. 
+ *   shortVideoHeader - binary flag indicating presence of 
+ *            short_video_header; escape modes 0-3 are used if 
+ *            shortVideoHeader==0, and escape mode 4 is used when 
+ *            shortVideoHeader==1. 
+ *   videoComp - video component type (luminance or chrominance) of the 
+ *            current block 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after the block is decoded such 
+ *            that it points to the current byte in the bit stream buffer 
+ *   pBitOffset - *pBitOffset is updated such that it points to the current 
+ *            bit position in the byte pointed by *ppBitStream 
+ *   pDst - pointer to the coefficient buffer of current block; must be 
+ *            4-byte aligned. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments, if:
+ *    -    At least one of the following pointers is NULL: 
+ *         ppBitStream, *ppBitStream, pBitOffset, pDst
+ *    -    *pBitOffset exceeds [0,7]
+ *    -    preDir exceeds [0,2]
+ *    -    pDst is not 4-byte aligned 
+ *    OMX_Sts_Err - if:
+ *    -    In DecodeVLCZigzag_IntraDCVLC, dc_size > 12 
+ *    -    At least one of mark bits equals zero 
+ *    -    Illegal stream encountered; code cannot be located in VLC table 
+ *    -    Forbidden code encountered in the VLC FLC table. 
+ *    -    The number of coefficients is greater than 64 
+ *
+ */
+OMXResult omxVCM4P2_DecodeVLCZigzag_IntraDCVLC (
+    const OMX_U8 **ppBitStream,
+    OMX_INT *pBitOffset,
+    OMX_S16 *pDst,
+    OMX_U8 predDir,
+    OMX_INT shortVideoHeader,
+    OMXVCM4P2VideoComponent videoComp
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_DecodeVLCZigzag_IntraACVLC   (6.2.5.2.2)
+ *
+ * Description:
+ * Performs VLC decoding and inverse zigzag scan of AC and DC coefficients 
+ * for one intra block.  Two versions of the function (DCVLC and ACVLC) are 
+ * provided in order to support the two different methods of processing DC 
+ * coefficients, as described in [ISO14496-2], subclause 7.4.1.4,  Intra DC 
+ * Coefficient Decoding for the Case of Switched VLC Encoding.  
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - pointer to the pointer to the current byte in the 
+ *            bitstream buffer 
+ *   pBitOffset - pointer to the bit position in the current byte referenced 
+ *            by *ppBitStream.  The parameter *pBitOffset is valid in the 
+ *            range [0-7]. Bit Position in one byte:  |Most Least| *pBitOffset 
+ *            |0 1 2 3 4 5 6 7| 
+ *   predDir - AC prediction direction; used to select the zigzag scan 
+ *            pattern; takes one of the following values: OMX_VC_NONE - AC 
+ *            prediction not used; performs classical zigzag scan. 
+ *            OMX_VC_HORIZONTAL - Horizontal prediction; performs 
+ *            alternate-vertical zigzag scan; OMX_VC_VERTICAL - Vertical 
+ *            prediction; performs alternate-horizontal zigzag scan. 
+ *   shortVideoHeader - binary flag indicating presence of 
+ *            short_video_header; escape modes 0-3 are used if 
+ *            shortVideoHeader==0, and escape mode 4 is used when 
+ *            shortVideoHeader==1. 
+ *   videoComp - video component type (luminance or chrominance) of the 
+ *            current block 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after the block is decoded such 
+ *            that it points to the current byte in the bit stream buffer 
+ *   pBitOffset - *pBitOffset is updated such that it points to the current 
+ *            bit position in the byte pointed by *ppBitStream 
+ *   pDst - pointer to the coefficient buffer of current block; must be 
+ *            4-byte aligned. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments At least one of the following 
+ *              pointers is NULL: ppBitStream, *ppBitStream, pBitOffset, pDst, 
+ *              or At least one of the following conditions is true: 
+ *              *pBitOffset exceeds [0,7], preDir exceeds [0,2], or pDst is 
+ *              not 4-byte aligned 
+ *    OMX_Sts_Err In DecodeVLCZigzag_IntraDCVLC, dc_size > 12 At least one of 
+ *              mark bits equals zero Illegal stream encountered; code cannot 
+ *              be located in VLC table Forbidden code encountered in the VLC 
+ *              FLC table The number of coefficients is greater than 64 
+ *
+ */
+OMXResult omxVCM4P2_DecodeVLCZigzag_IntraACVLC (
+    const OMX_U8 **ppBitStream,
+    OMX_INT *pBitOffset,
+    OMX_S16 *pDst,
+    OMX_U8 predDir,
+    OMX_INT shortVideoHeader
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_DecodeVLCZigzag_Inter   (6.2.5.2.3)
+ *
+ * Description:
+ * Performs VLC decoding and inverse zigzag scan for one inter-coded block. 
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - double pointer to the current byte in the stream buffer 
+ *   pBitOffset - pointer to the next available bit in the current stream 
+ *            byte referenced by *ppBitStream. The parameter *pBitOffset is 
+ *            valid within the range [0-7]. 
+ *   shortVideoHeader - binary flag indicating presence of 
+ *            short_video_header; escape modes 0-3 are used if 
+ *            shortVideoHeader==0, and escape mode 4 is used when 
+ *            shortVideoHeader==1. 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after the block is decoded such 
+ *            that it points to the current byte in the stream buffer 
+ *   pBitOffset - *pBitOffset is updated after decoding such that it points 
+ *            to the next available bit in the stream byte referenced by 
+ *            *ppBitStream 
+ *   pDst - pointer to the coefficient buffer of current block; must be 
+ *            4-byte aligned. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_BadArgErr - bad arguments:
+ *    -    At least one of the following pointers is NULL: 
+ *         ppBitStream, *ppBitStream, pBitOffset, pDst
+ *    -    pDst is not 4-byte aligned
+ *    -   *pBitOffset exceeds [0,7]
+ *    OMX_Sts_Err - status error, if:
+ *    -    At least one mark bit is equal to zero 
+ *    -    Encountered an illegal stream code that cannot be found in the VLC table 
+ *    -    Encountered an illegal code in the VLC FLC table 
+ *    -    The number of coefficients is greater than 64 
+ *
+ */
+OMXResult omxVCM4P2_DecodeVLCZigzag_Inter (
+    const OMX_U8 **ppBitStream,
+    OMX_INT *pBitOffset,
+    OMX_S16 *pDst,
+    OMX_INT shortVideoHeader
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_QuantInvIntra_I   (6.2.5.3.2)
+ *
+ * Description:
+ * Performs the second inverse quantization mode on an intra/inter coded 
+ * block. Supports bits_per_pixel = 8. The output coefficients are clipped to 
+ * the range [-2048, 2047]. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - pointer to the input (quantized) intra/inter block; must be 
+ *            aligned on a 16-byte boundary. 
+ *   QP - quantization parameter (quantizer_scale) 
+ *   videoComp - video component type of the current block. Takes one of the 
+ *            following flags: OMX_VC_LUMINANCE, OMX_VC_CHROMINANCE (intra 
+ *            version only). 
+ *   shortVideoHeader - binary flag indicating presence of short_video_header 
+ *            (intra version only). 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst - pointer to the output (dequantized) intra/inter block 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; one or more of the following is 
+ *              true: 
+ *    -    pSrcDst is NULL 
+ *    -    QP <= 0 or QP >=31 
+ *    -    videoComp is neither OMX_VC_LUMINANCE nor OMX_VC_CHROMINANCE. 
+ *
+ */
+OMXResult omxVCM4P2_QuantInvIntra_I (
+    OMX_S16 *pSrcDst,
+    OMX_INT QP,
+    OMXVCM4P2VideoComponent videoComp,
+    OMX_INT shortVideoHeader
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_QuantInvInter_I   (6.2.5.3.2)
+ *
+ * Description:
+ * Performs the second inverse quantization mode on an intra/inter coded 
+ * block. Supports bits_per_pixel = 8. The output coefficients are clipped to 
+ * the range [-2048, 2047]. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - pointer to the input (quantized) intra/inter block; must be 
+ *            aligned on a 16-byte boundary. 
+ *   QP - quantization parameter (quantizer_scale) 
+ *   videoComp - video component type of the current block. Takes one of the 
+ *            following flags: OMX_VC_LUMINANCE, OMX_VC_CHROMINANCE (intra 
+ *            version only). 
+ *   shortVideoHeader - binary flag indicating presence of short_video_header 
+ *            (intra version only). 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst - pointer to the output (dequantized) intra/inter block 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; one or more of the following is 
+ *              true: 
+ *    -    pSrcDst is NULL 
+ *    -    QP <= 0 or QP >=31 
+ *    -    videoComp is neither OMX_VC_LUMINANCE nor OMX_VC_CHROMINANCE. 
+ *
+ */
+OMXResult omxVCM4P2_QuantInvInter_I (
+    OMX_S16 *pSrcDst,
+    OMX_INT QP
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_DecodeBlockCoef_Intra   (6.2.5.4.1)
+ *
+ * Description:
+ * Decodes the INTRA block coefficients. Inverse quantization, inversely 
+ * zigzag positioning, and IDCT, with appropriate clipping on each step, are 
+ * performed on the coefficients. The results are then placed in the output 
+ * frame/plane on a pixel basis.  Note: This function will be used only when 
+ * at least one non-zero AC coefficient of current block exists in the bit 
+ * stream. The DC only condition will be handled in another function. 
+ *
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - pointer to the pointer to the current byte in the bit 
+ *            stream buffer. There is no boundary check for the bit stream 
+ *            buffer. 
+ *   pBitOffset - pointer to the bit position in the byte pointed to by 
+ *            *ppBitStream. *pBitOffset is valid within [0-7]. 
+ *   step - width of the destination plane 
+ *   pCoefBufRow - pointer to the coefficient row buffer; must be aligned on 
+ *            an 8-byte boundary. 
+ *   pCoefBufCol - pointer to the coefficient column buffer; must be aligned 
+ *            on an 8-byte boundary. 
+ *   curQP - quantization parameter of the macroblock which the current block 
+ *            belongs to 
+ *   pQPBuf - pointer to the quantization parameter buffer 
+ *   blockIndex - block index indicating the component type and position as 
+ *            defined in [ISO14496-2], subclause 6.1.3.8, Figure 6-5. 
+ *   intraDCVLC - a code determined by intra_dc_vlc_thr and QP. This allows a 
+ *            mechanism to switch between two VLC for coding of Intra DC 
+ *            coefficients as per [ISO14496-2], Table 6-21. 
+ *   ACPredFlag - a flag equal to ac_pred_flag (of luminance) indicating if 
+ *            the ac coefficients of the first row or first column are 
+ *            differentially coded for intra coded macroblock. 
+ *   shortVideoHeader - binary flag indicating presence of 
+ *            short_video_header; shortVideoHeader==1 selects linear intra DC 
+ *            mode, and shortVideoHeader==0 selects non linear intra DC mode. 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after the block is decoded, so 
+ *            that it points to the current byte in the bit stream buffer 
+ *   pBitOffset - *pBitOffset is updated so that it points to the current bit 
+ *            position in the byte pointed by *ppBitStream 
+ *   pDst - pointer to the block in the destination plane; must be aligned on 
+ *            an 8-byte boundary. 
+ *   pCoefBufRow - pointer to the updated coefficient row buffer. 
+ *   pCoefBufCol - pointer to the updated coefficient column buffer  Note: 
+ *            The coefficient buffers must be updated in accordance with the 
+ *            update procedure defined in section 6.2.2. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments, if:
+ *    -    At least one of the following pointers is NULL: 
+ *         ppBitStream, *ppBitStream, pBitOffset, pCoefBufRow, pCoefBufCol, 
+ *         pQPBuf, pDst. 
+ *    -    *pBitOffset exceeds [0,7] 
+ *    -    curQP exceeds (1, 31)
+ *    -    blockIndex exceeds [0,5]
+ *    -    step is not the multiple of 8
+ *    -    a pointer alignment requirement was violated. 
+ *    OMX_Sts_Err - status error. Refer to OMX_Sts_Err of DecodeVLCZigzag_Intra.  
+ *
+ */
+OMXResult omxVCM4P2_DecodeBlockCoef_Intra (
+    const OMX_U8 **ppBitStream,
+    OMX_INT *pBitOffset,
+    OMX_U8 *pDst,
+    OMX_INT step,
+    OMX_S16 *pCoefBufRow,
+    OMX_S16 *pCoefBufCol,
+    OMX_U8 curQP,
+    const OMX_U8 *pQPBuf,
+    OMX_INT blockIndex,
+    OMX_INT intraDCVLC,
+    OMX_INT ACPredFlag,
+    OMX_INT shortVideoHeader
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_DecodeBlockCoef_Inter   (6.2.5.4.2)
+ *
+ * Description:
+ * Decodes the INTER block coefficients. This function performs inverse 
+ * quantization, inverse zigzag positioning, and IDCT (with appropriate 
+ * clipping on each step) on the coefficients. The results (residuals) are 
+ * placed in a contiguous array of 64 elements. For INTER block, the output 
+ * buffer holds the residuals for further reconstruction. 
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - pointer to the pointer to the current byte in the bit 
+ *            stream buffer. There is no boundary check for the bit stream 
+ *            buffer. 
+ *   pBitOffset - pointer to the bit position in the byte pointed to by 
+ *            *ppBitStream. *pBitOffset is valid within [0-7] 
+ *   QP - quantization parameter 
+ *   shortVideoHeader - binary flag indicating presence of 
+ *            short_video_header; shortVideoHeader==1 selects linear intra DC 
+ *            mode, and shortVideoHeader==0 selects non linear intra DC mode. 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after the block is decoded, so 
+ *            that it points to the current byte in the bit stream buffer 
+ *   pBitOffset - *pBitOffset is updated so that it points to the current bit 
+ *            position in the byte pointed by *ppBitStream 
+ *   pDst - pointer to the decoded residual buffer (a contiguous array of 64 
+ *            elements of OMX_S16 data type); must be aligned on a 16-byte 
+ *            boundary. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments, if:
+ *    -    At least one of the following pointers is Null: 
+ *         ppBitStream, *ppBitStream, pBitOffset , pDst 
+ *    -    *pBitOffset exceeds [0,7]
+ *    -    QP <= 0. 
+ *    -    pDst is not 16-byte aligned 
+ *    OMX_Sts_Err - status error. Refer to OMX_Sts_Err of DecodeVLCZigzag_Inter . 
+ *
+ */
+OMXResult omxVCM4P2_DecodeBlockCoef_Inter (
+    const OMX_U8 **ppBitStream,
+    OMX_INT *pBitOffset,
+    OMX_S16 *pDst,
+    OMX_INT QP,
+    OMX_INT shortVideoHeader
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_PredictReconCoefIntra   (6.2.5.4.3)
+ *
+ * Description:
+ * Performs adaptive DC/AC coefficient prediction for an intra block.  Prior 
+ * to the function call, prediction direction (predDir) should be selected as 
+ * specified in [ISO14496-2], subclause 7.4.3.1. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - pointer to the coefficient buffer which contains the quantized 
+ *            coefficient residuals (PQF) of the current block; must be 
+ *            aligned on a 4-byte boundary.  The output coefficients are 
+ *            saturated to the range [-2048, 2047]. 
+ *   pPredBufRow - pointer to the coefficient row buffer; must be aligned on 
+ *            a 4-byte boundary. 
+ *   pPredBufCol - pointer to the coefficient column buffer; must be aligned 
+ *            on a 4-byte boundary. 
+ *   curQP - quantization parameter of the current block. curQP may equal to 
+ *            predQP especially when the current block and the predictor block 
+ *            are in the same macroblock. 
+ *   predQP - quantization parameter of the predictor block 
+ *   predDir - indicates the prediction direction which takes one of the 
+ *            following values: OMX_VC_HORIZONTAL - predict horizontally 
+ *            OMX_VC_VERTICAL - predict vertically 
+ *   ACPredFlag - a flag indicating if AC prediction should be performed. It 
+ *            is equal to ac_pred_flag in the bit stream syntax of MPEG-4 
+ *   videoComp - video component type (luminance or chrominance) of the 
+ *            current block 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst - pointer to the coefficient buffer which contains the quantized 
+ *            coefficients (QF) of the current block 
+ *   pPredBufRow - pointer to the updated coefficient row buffer 
+ *   pPredBufCol - pointer to the updated coefficient column buffer  Note: 
+ *            Buffer update: Update the AC prediction buffer (both row and 
+ *            column buffer). 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments, if:
+ *        -    At least one of the pointers is NULL: 
+ *              pSrcDst, pPredBufRow, or pPredBufCol. 
+ *        -    curQP <= 0, 
+ *        -    predQP <= 0, 
+ *        -    curQP >31, 
+ *        -    predQP > 31, 
+ *        -    preDir exceeds [1,2]
+ *        -    pSrcDst, pPredBufRow, or pPredBufCol is not 4-byte aligned. 
+ *
+ */
+OMXResult omxVCM4P2_PredictReconCoefIntra (
+    OMX_S16 *pSrcDst,
+    OMX_S16 *pPredBufRow,
+    OMX_S16 *pPredBufCol,
+    OMX_INT curQP,
+    OMX_INT predQP,
+    OMX_INT predDir,
+    OMX_INT ACPredFlag,
+    OMXVCM4P2VideoComponent videoComp
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_MCReconBlock   (6.2.5.5.1)
+ *
+ * Description:
+ * Performs motion compensation prediction for an 8x8 block using 
+ * interpolation described in [ISO14496-2], subclause 7.6.2. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - pointer to the block in the reference plane. 
+ *   srcStep - distance between the start of consecutive lines in the 
+ *            reference plane, in bytes; must be a multiple of 8. 
+ *   dstStep - distance between the start of consecutive lines in the 
+ *            destination plane, in bytes; must be a multiple of 8. 
+ *   pSrcResidue - pointer to a buffer containing the 16-bit prediction 
+ *            residuals; must be 16-byte aligned. If the pointer is NULL, then 
+ *            no prediction is done, only motion compensation, i.e., the block 
+ *            is moved with interpolation. 
+ *   predictType - bilinear interpolation type, as defined in section 
+ *            6.2.1.2. 
+ *   rndVal - rounding control parameter: 0 - disabled; 1 - enabled. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - pointer to the destination buffer; must be 8-byte aligned.  If 
+ *            prediction residuals are added then output intensities are 
+ *            clipped to the range [0,255]. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned under any of the following 
+ *              conditions: 
+ *    -    pDst is not 8-byte aligned. 
+ *    -    pSrcResidue is not 16-byte aligned. 
+ *    -    one or more of the following pointers is NULL: pSrc or pDst. 
+ *    -    either srcStep or dstStep is not a multiple of 8. 
+ *    -    invalid type specified for the parameter predictType. 
+ *    -    the parameter rndVal is not equal either to 0 or 1. 
+ *
+ */
+OMXResult omxVCM4P2_MCReconBlock (
+    const OMX_U8 *pSrc,
+    OMX_INT srcStep,
+    const OMX_S16 *pSrcResidue,
+    OMX_U8 *pDst,
+    OMX_INT dstStep,
+    OMX_INT predictType,
+    OMX_INT rndVal
+);
+
+
+
+/* 6.3.1.1 Intra 16x16 Prediction Modes  */
+/* A data type that enumerates intra_16x16 macroblock prediction modes is defined as follows:  */
+
+typedef enum {
+    OMX_VC_16X16_VERT = 0,  /** Intra_16x16_Vertical */
+    OMX_VC_16X16_HOR = 1,   /** Intra_16x16_Horizontal */
+    OMX_VC_16X16_DC = 2,    /** Intra_16x16_DC */
+    OMX_VC_16X16_PLANE = 3  /** Intra_16x16_Plane */ 
+} OMXVCM4P10Intra16x16PredMode;
+
+
+
+/* 6.3.1.2 Intra 4x4 Prediction Modes  */
+/* A data type that enumerates intra_4x4 macroblock prediction modes is defined as follows:  */
+
+typedef enum {
+    OMX_VC_4X4_VERT = 0,     /** Intra_4x4_Vertical */
+    OMX_VC_4X4_HOR = 1,      /** Intra_4x4_Horizontal */
+    OMX_VC_4X4_DC = 2,       /** Intra_4x4_DC */
+    OMX_VC_4X4_DIAG_DL = 3,  /** Intra_4x4_Diagonal_Down_Left */
+    OMX_VC_4X4_DIAG_DR = 4,  /** Intra_4x4_Diagonal_Down_Right */
+    OMX_VC_4X4_VR = 5,       /** Intra_4x4_Vertical_Right */
+    OMX_VC_4X4_HD = 6,       /** Intra_4x4_Horizontal_Down */
+    OMX_VC_4X4_VL = 7,       /** Intra_4x4_Vertical_Left */
+    OMX_VC_4X4_HU = 8        /** Intra_4x4_Horizontal_Up */ 
+} OMXVCM4P10Intra4x4PredMode;
+
+
+
+/* 6.3.1.3 Chroma Prediction Modes  */
+/* A data type that enumerates intra chroma prediction modes is defined as follows:  */
+
+typedef enum {
+    OMX_VC_CHROMA_DC = 0,    /** Intra_Chroma_DC */
+    OMX_VC_CHROMA_HOR = 1,   /** Intra_Chroma_Horizontal */
+    OMX_VC_CHROMA_VERT = 2,  /** Intra_Chroma_Vertical */
+    OMX_VC_CHROMA_PLANE = 3  /** Intra_Chroma_Plane */ 
+} OMXVCM4P10IntraChromaPredMode;
+
+
+
+/* 6.3.1.4 Motion Estimation Modes  */
+/* A data type that enumerates H.264 motion estimation modes is defined as follows:  */
+
+typedef enum {
+    OMX_VC_M4P10_FAST_SEARCH = 0, /** Fast motion search */
+    OMX_VC_M4P10_FULL_SEARCH = 1  /** Full motion search */ 
+} OMXVCM4P10MEMode;
+
+
+
+/* 6.3.1.5 Macroblock Types  */
+/* A data type that enumerates H.264 macroblock types is defined as follows:  */
+
+typedef enum {
+    OMX_VC_P_16x16  = 0, /* defined by [ISO14496-10] */
+    OMX_VC_P_16x8  = 1,
+    OMX_VC_P_8x16  = 2,
+    OMX_VC_P_8x8  = 3,
+    OMX_VC_PREF0_8x8  = 4,
+    OMX_VC_INTER_SKIP  = 5,
+    OMX_VC_INTRA_4x4  = 8,
+    OMX_VC_INTRA_16x16  = 9,
+    OMX_VC_INTRA_PCM = 10 
+} OMXVCM4P10MacroblockType;
+
+
+
+/* 6.3.1.6 Sub-Macroblock Types  */
+/* A data type that enumerates H.264 sub-macroblock types is defined as follows:  */
+
+typedef enum {
+    OMX_VC_SUB_P_8x8 = 0, /* defined by [ISO14496-10] */
+    OMX_VC_SUB_P_8x4 = 1,
+    OMX_VC_SUB_P_4x8 = 2,
+    OMX_VC_SUB_P_4x4 = 3 
+} OMXVCM4P10SubMacroblockType;
+
+
+
+/* 6.3.1.7 Variable Length Coding (VLC) Information  */
+
+typedef struct {
+    OMX_U8 uTrailing_Ones;      /* Trailing ones; 3 at most */
+    OMX_U8 uTrailing_One_Signs; /* Trailing ones signal */
+    OMX_U8 uNumCoeffs;          /* Total number of non-zero coefs, including trailing ones */
+    OMX_U8 uTotalZeros;         /* Total number of zero coefs */
+    OMX_S16 iLevels[16];        /* Levels of non-zero coefs, in reverse zig-zag order */
+    OMX_U8 uRuns[16];           /* Runs for levels and trailing ones, in reverse zig-zag order */
+} OMXVCM4P10VLCInfo;
+
+
+
+/* 6.3.1.8 Macroblock Information  */
+
+typedef struct {
+    OMX_S32 sliceId;                          /* slice number */
+    OMXVCM4P10MacroblockType mbType;          /* MB type */
+    OMXVCM4P10SubMacroblockType subMBType[4]; /* sub-block type */
+    OMX_S32 qpy;                              /* qp for luma */
+    OMX_S32 qpc;                              /* qp for chroma */
+    OMX_U32 cbpy;                             /* CBP Luma */
+    OMX_U32 cbpc;                             /* CBP Chroma */
+    OMXVCMotionVector pMV0[4][4]; /* motion vector, represented using 1/4-pel units, pMV0[blocky][blockx] (blocky = 0~3, blockx =0~3) */
+    OMXVCMotionVector pMVPred[4][4]; /* motion vector prediction, Represented using 1/4-pel units, pMVPred[blocky][blockx] (blocky = 0~3, blockx = 0~3) */
+    OMX_U8 pRefL0Idx[4];                      /* reference picture indices */
+    OMXVCM4P10Intra16x16PredMode Intra16x16PredMode; /* best intra 16x16 prediction mode */
+    OMXVCM4P10Intra4x4PredMode pIntra4x4PredMode[16]; /* best intra 4x4 prediction mode for each block, pMV0 indexed as above */
+} OMXVCM4P10MBInfo, *OMXVCM4P10MBInfoPtr;
+
+
+
+/* 6.3.1.9 Motion Estimation Parameters  */
+
+typedef struct {
+    OMX_S32 blockSplitEnable8x8; /* enables 16x8, 8x16, 8x8 */
+    OMX_S32 blockSplitEnable4x4; /* enable splitting of 8x4, 4x8, 4x4 blocks */
+    OMX_S32 halfSearchEnable;
+    OMX_S32 quarterSearchEnable;
+    OMX_S32 intraEnable4x4;      /* 1=enable, 0=disable */
+    OMX_S32 searchRange16x16;    /* integer pixel units */
+    OMX_S32 searchRange8x8;
+    OMX_S32 searchRange4x4;
+} OMXVCM4P10MEParams;
+
+
+
+/**
+ * Function:  omxVCM4P10_PredictIntra_4x4   (6.3.3.1.1)
+ *
+ * Description:
+ * Perform Intra_4x4 prediction for luma samples. If the upper-right block is 
+ * not available, then duplication work should be handled inside the function. 
+ * Users need not define them outside. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcLeft -  Pointer to the buffer of 4 left pixels: 
+ *                  p[x, y] (x = -1, y = 0..3) 
+ *   pSrcAbove - Pointer to the buffer of 8 above pixels: 
+ *                  p[x,y] (x = 0..7, y =-1); 
+ *               must be aligned on a 4-byte boundary. 
+ *   pSrcAboveLeft - Pointer to the above left pixels: p[x,y] (x = -1, y = -1) 
+ *   leftStep - Step of left pixel buffer; must be a multiple of 4. 
+ *   dstStep - Step of the destination buffer; must be a multiple of 4. 
+ *   predMode - Intra_4x4 prediction mode. 
+ *   availability - Neighboring 4x4 block availability flag, refer to 
+ *             "Neighboring Macroblock Availability" . 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - Pointer to the destination buffer; must be aligned on a 4-byte 
+ *            boundary. 
+ *
+ * Return Value:
+ *    If the function runs without error, it returns OMX_Sts_NoErr. 
+ *    If one of the following cases occurs, the function returns 
+ *              OMX_Sts_BadArgErr: 
+ *    pDst is NULL. 
+ *    dstStep < 4, or dstStep is not a multiple of 4. 
+ *    leftStep is not a multiple of 4. 
+ *    predMode is not in the valid range of enumeration 
+ *              OMXVCM4P10Intra4x4PredMode. 
+ *    predMode is OMX_VC_4x4_VERT, but availability doesn't set OMX_VC_UPPER 
+ *              indicating p[x,-1] (x = 0..3) is not available. 
+ *    predMode is OMX_VC_4x4_HOR, but availability doesn't set OMX_VC_LEFT 
+ *              indicating p[-1,y] (y = 0..3) is not available. 
+ *    predMode is OMX_VC_4x4_DIAG_DL, but availability doesn't set 
+ *              OMX_VC_UPPER indicating p[x, -1] (x = 0..3) is not available. 
+ *    predMode is OMX_VC_4x4_DIAG_DR, but availability doesn't set 
+ *              OMX_VC_UPPER_LEFT or OMX_VC_UPPER or OMX_VC_LEFT indicating 
+ *              p[x,-1] (x = 0..3), or p[-1,y] (y = 0..3) or p[-1,-1] is not 
+ *              available. 
+ *    predMode is OMX_VC_4x4_VR, but availability doesn't set 
+ *              OMX_VC_UPPER_LEFT or OMX_VC_UPPER or OMX_VC_LEFT indicating 
+ *              p[x,-1] (x = 0..3), or p[-1,y] (y = 0..3) or p[-1,-1] is not 
+ *              available. 
+ *    predMode is OMX_VC_4x4_HD, but availability doesn't set 
+ *              OMX_VC_UPPER_LEFT or OMX_VC_UPPER or OMX_VC_LEFT indicating 
+ *              p[x,-1] (x = 0..3), or p[-1,y] (y = 0..3) or p[-1,-1] is not 
+ *              available. 
+ *    predMode is OMX_VC_4x4_VL, but availability doesn't set OMX_VC_UPPER 
+ *              indicating p[x,-1] (x = 0..3) is not available. 
+ *    predMode is OMX_VC_4x4_HU, but availability doesn't set OMX_VC_LEFT 
+ *              indicating p[-1,y] (y = 0..3) is not available. 
+ *    availability sets OMX_VC_UPPER, but pSrcAbove is NULL. 
+ *    availability sets OMX_VC_LEFT, but pSrcLeft is NULL. 
+ *    availability sets OMX_VC_UPPER_LEFT, but pSrcAboveLeft is NULL. 
+ *    either pSrcAbove or pDst is not aligned on a 4-byte boundary.  
+ *
+ * Note: 
+ *     pSrcAbove, pSrcAbove, pSrcAboveLeft may be invalid pointers if 
+ *     they are not used by intra prediction as implied in predMode. 
+ *
+ */
+OMXResult omxVCM4P10_PredictIntra_4x4 (
+    const OMX_U8 *pSrcLeft,
+    const OMX_U8 *pSrcAbove,
+    const OMX_U8 *pSrcAboveLeft,
+    OMX_U8 *pDst,
+    OMX_INT leftStep,
+    OMX_INT dstStep,
+    OMXVCM4P10Intra4x4PredMode predMode,
+    OMX_S32 availability
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_PredictIntra_16x16   (6.3.3.1.2)
+ *
+ * Description:
+ * Perform Intra_16x16 prediction for luma samples. If the upper-right block 
+ * is not available, then duplication work should be handled inside the 
+ * function. Users need not define them outside. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcLeft - Pointer to the buffer of 16 left pixels: p[x, y] (x = -1, y = 
+ *            0..15) 
+ *   pSrcAbove - Pointer to the buffer of 16 above pixels: p[x,y] (x = 0..15, 
+ *            y= -1); must be aligned on a 16-byte boundary. 
+ *   pSrcAboveLeft - Pointer to the above left pixels: p[x,y] (x = -1, y = -1) 
+ *   leftStep - Step of left pixel buffer; must be a multiple of 16. 
+ *   dstStep - Step of the destination buffer; must be a multiple of 16. 
+ *   predMode - Intra_16x16 prediction mode, please refer to section 3.4.1. 
+ *   availability - Neighboring 16x16 MB availability flag. Refer to 
+ *                  section 3.4.4. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst -Pointer to the destination buffer; must be aligned on a 16-byte 
+ *            boundary. 
+ *
+ * Return Value:
+ *    If the function runs without error, it returns OMX_Sts_NoErr. 
+ *    If one of the following cases occurs, the function returns 
+ *              OMX_Sts_BadArgErr: 
+ *    pDst is NULL. 
+ *    dstStep < 16. or dstStep is not a multiple of 16. 
+ *    leftStep is not a multiple of 16. 
+ *    predMode is not in the valid range of enumeration 
+ *              OMXVCM4P10Intra16x16PredMode 
+ *    predMode is OMX_VC_16X16_VERT, but availability doesn't set 
+ *              OMX_VC_UPPER indicating p[x,-1] (x = 0..15) is not available. 
+ *    predMode is OMX_VC_16X16_HOR, but availability doesn't set OMX_VC_LEFT 
+ *              indicating p[-1,y] (y = 0..15) is not available. 
+ *    predMode is OMX_VC_16X16_PLANE, but availability doesn't set 
+ *              OMX_VC_UPPER_LEFT or OMX_VC_UPPER or OMX_VC_LEFT indicating 
+ *              p[x,-1](x = 0..15), or p[-1,y] (y = 0..15), or p[-1,-1] is not 
+ *              available. 
+ *    availability sets OMX_VC_UPPER, but pSrcAbove is NULL. 
+ *    availability sets OMX_VC_LEFT, but pSrcLeft is NULL. 
+ *    availability sets OMX_VC_UPPER_LEFT, but pSrcAboveLeft is NULL. 
+ *    either pSrcAbove or pDst is not aligned on a 16-byte boundary.  
+ *
+ * Note: 
+ *     pSrcAbove, pSrcAbove, pSrcAboveLeft may be invalid pointers if 
+ *     they are not used by intra prediction implied in predMode. 
+ * Note: 
+ *     OMX_VC_UPPER_RIGHT is not used in intra_16x16 luma prediction. 
+ *
+ */
+OMXResult omxVCM4P10_PredictIntra_16x16 (
+    const OMX_U8 *pSrcLeft,
+    const OMX_U8 *pSrcAbove,
+    const OMX_U8 *pSrcAboveLeft,
+    OMX_U8 *pDst,
+    OMX_INT leftStep,
+    OMX_INT dstStep,
+    OMXVCM4P10Intra16x16PredMode predMode,
+    OMX_S32 availability
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_PredictIntraChroma_8x8   (6.3.3.1.3)
+ *
+ * Description:
+ * Performs intra prediction for chroma samples. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcLeft - Pointer to the buffer of 8 left pixels: p[x, y] (x = -1, y= 
+ *            0..7). 
+ *   pSrcAbove - Pointer to the buffer of 8 above pixels: p[x,y] (x = 0..7, y 
+ *            = -1); must be aligned on an 8-byte boundary. 
+ *   pSrcAboveLeft - Pointer to the above left pixels: p[x,y] (x = -1, y = -1) 
+ *   leftStep - Step of left pixel buffer; must be a multiple of 8. 
+ *   dstStep - Step of the destination buffer; must be a multiple of 8. 
+ *   predMode - Intra chroma prediction mode, please refer to section 3.4.3. 
+ *   availability - Neighboring chroma block availability flag, please refer 
+ *            to  "Neighboring Macroblock Availability". 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - Pointer to the destination buffer; must be aligned on an 8-byte 
+ *            boundary. 
+ *
+ * Return Value:
+ *    If the function runs without error, it returns OMX_Sts_NoErr. 
+ *    If any of the following cases occurs, the function returns 
+ *              OMX_Sts_BadArgErr: 
+ *    pDst is NULL. 
+ *    dstStep < 8 or dstStep is not a multiple of 8. 
+ *    leftStep is not a multiple of 8. 
+ *    predMode is not in the valid range of enumeration 
+ *              OMXVCM4P10IntraChromaPredMode. 
+ *    predMode is OMX_VC_CHROMA_VERT, but availability doesn't set 
+ *              OMX_VC_UPPER indicating p[x,-1] (x = 0..7) is not available. 
+ *    predMode is OMX_VC_CHROMA_HOR, but availability doesn't set OMX_VC_LEFT 
+ *              indicating p[-1,y] (y = 0..7) is not available. 
+ *    predMode is OMX_VC_CHROMA_PLANE, but availability doesn't set 
+ *              OMX_VC_UPPER_LEFT or OMX_VC_UPPER or OMX_VC_LEFT indicating 
+ *              p[x,-1](x = 0..7), or p[-1,y] (y = 0..7), or p[-1,-1] is not 
+ *              available. 
+ *    availability sets OMX_VC_UPPER, but pSrcAbove is NULL. 
+ *    availability sets OMX_VC_LEFT, but pSrcLeft is NULL. 
+ *    availability sets OMX_VC_UPPER_LEFT, but pSrcAboveLeft is NULL. 
+ *    either pSrcAbove or pDst is not aligned on a 8-byte boundary.  
+ *
+ *  Note: pSrcAbove, pSrcAbove, pSrcAboveLeft may be invalid pointer if 
+ *  they are not used by intra prediction implied in predMode. 
+ *
+ *  Note: OMX_VC_UPPER_RIGHT is not used in intra chroma prediction. 
+ *
+ */
+OMXResult omxVCM4P10_PredictIntraChroma_8x8 (
+    const OMX_U8 *pSrcLeft,
+    const OMX_U8 *pSrcAbove,
+    const OMX_U8 *pSrcAboveLeft,
+    OMX_U8 *pDst,
+    OMX_INT leftStep,
+    OMX_INT dstStep,
+    OMXVCM4P10IntraChromaPredMode predMode,
+    OMX_S32 availability
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_InterpolateLuma   (6.3.3.2.1)
+ *
+ * Description:
+ * Performs quarter-pixel interpolation for inter luma MB. It is assumed that 
+ * the frame is already padded when calling this function. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - Pointer to the source reference frame buffer 
+ *   srcStep - reference frame step, in bytes; must be a multiple of roi.width 
+ *   dstStep - destination frame step, in bytes; must be a multiple of 
+ *            roi.width 
+ *   dx - Fractional part of horizontal motion vector component in 1/4 pixel 
+ *            unit; valid in the range [0,3] 
+ *   dy - Fractional part of vertical motion vector y component in 1/4 pixel 
+ *            unit; valid in the range [0,3] 
+ *   roi - Dimension of the interpolation region; the parameters roi.width and 
+ *            roi.height must be equal to either 4, 8, or 16. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - Pointer to the destination frame buffer: 
+ *          if roi.width==4,  4-byte alignment required 
+ *          if roi.width==8,  8-byte alignment required 
+ *          if roi.width==16, 16-byte alignment required 
+ *
+ * Return Value:
+ *    If the function runs without error, it returns OMX_Sts_NoErr. 
+ *    If one of the following cases occurs, the function returns 
+ *              OMX_Sts_BadArgErr: 
+ *    pSrc or pDst is NULL. 
+ *    srcStep or dstStep < roi.width. 
+ *    dx or dy is out of range [0,3]. 
+ *    roi.width or roi.height is out of range {4, 8, 16}. 
+ *    roi.width is equal to 4, but pDst is not 4 byte aligned. 
+ *    roi.width is equal to 8 or 16, but pDst is not 8 byte aligned. 
+ *    srcStep or dstStep is not a multiple of 8. 
+ *
+ */
+OMXResult omxVCM4P10_InterpolateLuma (
+    const OMX_U8 *pSrc,
+    OMX_S32 srcStep,
+    OMX_U8 *pDst,
+    OMX_S32 dstStep,
+    OMX_S32 dx,
+    OMX_S32 dy,
+    OMXSize roi
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_InterpolateChroma   (6.3.3.2.2)
+ *
+ * Description:
+ * Performs 1/8-pixel interpolation for inter chroma MB. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc -Pointer to the source reference frame buffer 
+ *   srcStep -Reference frame step in bytes 
+ *   dstStep -Destination frame step in bytes; must be a multiple of 
+ *            roi.width. 
+ *   dx -Fractional part of horizontal motion vector component in 1/8 pixel 
+ *            unit; valid in the range [0,7] 
+ *   dy -Fractional part of vertical motion vector component in 1/8 pixel 
+ *            unit; valid in the range [0,7] 
+ *   roi -Dimension of the interpolation region; the parameters roi.width and 
+ *            roi.height must be equal to either 2, 4, or 8. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst -Pointer to the destination frame buffer:
+ *         if roi.width==2,  2-byte alignment required 
+ *         if roi.width==4,  4-byte alignment required 
+ *         if roi.width==8, 8-byte alignment required 
+ *
+ * Return Value:
+ *    If the function runs without error, it returns OMX_Sts_NoErr. 
+ *    If one of the following cases occurs, the function returns 
+ *              OMX_Sts_BadArgErr: 
+ *    pSrc or pDst is NULL. 
+ *    srcStep or dstStep < 8. 
+ *    dx or dy is out of range [0-7]. 
+ *    roi.width or roi.height is out of range {2,4,8}. 
+ *    roi.width is equal to 2, but pDst is not 2-byte aligned. 
+ *    roi.width is equal to 4, but pDst is not 4-byte aligned. 
+ *    roi.width is equal to 8, but pDst is not 8 byte aligned. 
+ *    srcStep or dstStep is not a multiple of 8. 
+ *
+ */
+OMXResult omxVCM4P10_InterpolateChroma (
+    const OMX_U8 *pSrc,
+    OMX_S32 srcStep,
+    OMX_U8 *pDst,
+    OMX_S32 dstStep,
+    OMX_S32 dx,
+    OMX_S32 dy,
+    OMXSize roi
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_FilterDeblockingLuma_VerEdge_I   (6.3.3.3.1)
+ *
+ * Description:
+ * Performs in-place deblock filtering on four vertical edges of the luma 
+ * macroblock (16x16). 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - Pointer to the input macroblock; must be 16-byte aligned. 
+ *   srcdstStep -Step of the arrays; must be a multiple of 16. 
+ *   pAlpha -Array of size 2 of alpha thresholds (the first item is the alpha 
+ *            threshold for the external vertical edge, and the second item is 
+ *            for the internal vertical edge); per [ISO14496-10] alpha values 
+ *            must be in the range [0,255]. 
+ *   pBeta -Array of size 2 of beta thresholds (the first item is the beta 
+ *            threshold for the external vertical edge, and the second item is 
+ *            for the internal vertical edge); per [ISO14496-10] beta values 
+ *            must be in the range [0,18]. 
+ *   pThresholds -Array of size 16 of Thresholds (TC0) (values for the left 
+ *            edge of each 4x4 block, arranged in vertical block order); must 
+ *            be aligned on a 4-byte boundary..  Per [ISO14496-10] values must 
+ *            be in the range [0,25]. 
+ *   pBS -Array of size 16 of BS parameters (arranged in vertical block 
+ *            order); valid in the range [0,4] with the following 
+ *            restrictions: i) pBS[i]== 4 may occur only for 0<=i<=3, ii) 
+ *            pBS[i]== 4 if and only if pBS[i^3]== 4.  Must be 4-byte aligned. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst -Pointer to filtered output macroblock. 
+ *
+ * Return Value:
+ *    If the function runs without error, it returns OMX_Sts_NoErr. 
+ *    If one of the following cases occurs, the function returns 
+ *              OMX_Sts_BadArgErr: 
+ *    Either of the pointers in pSrcDst, pAlpha, pBeta, pThresholds, or pBS 
+ *              is NULL. 
+ *    Either pThresholds or pBS is not aligned on a 4-byte boundary. 
+ *    pSrcDst is not 16-byte aligned. 
+ *    srcdstStep is not a multiple of 16. 
+ *    pAlpha[0] and/or pAlpha[1] is outside the range [0,255]. 
+ *    pBeta[0] and/or pBeta[1] is outside the range [0,18]. 
+ *    One or more entries in the table pThresholds[0..15]is outside of the 
+ *              range [0,25]. 
+ *    pBS is out of range, i.e., one of the following conditions is true: 
+ *              pBS[i]<0, pBS[i]>4, pBS[i]==4 for i>=4, or (pBS[i]==4 && 
+ *              pBS[i^3]!=4) for 0<=i<=3. 
+ *
+ */
+OMXResult omxVCM4P10_FilterDeblockingLuma_VerEdge_I (
+    OMX_U8 *pSrcDst,
+    OMX_S32 srcdstStep,
+    const OMX_U8 *pAlpha,
+    const OMX_U8 *pBeta,
+    const OMX_U8 *pThresholds,
+    const OMX_U8 *pBS
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_FilterDeblockingLuma_HorEdge_I   (6.3.3.3.2)
+ *
+ * Description:
+ * Performs in-place deblock filtering on four horizontal edges of the luma 
+ * macroblock (16x16). 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - pointer to the input macroblock; must be 16-byte aligned. 
+ *   srcdstStep - step of the arrays; must be a multiple of 16. 
+ *   pAlpha - array of size 2 of alpha thresholds (the first item is the alpha 
+ *            threshold for the external vertical edge, and the second item is 
+ *            for the internal horizontal edge); per [ISO14496-10] alpha 
+ *            values must be in the range [0,255]. 
+ *   pBeta - array of size 2 of beta thresholds (the first item is the beta 
+ *            threshold for the external horizontal edge, and the second item 
+ *            is for the internal horizontal edge). Per [ISO14496-10] beta 
+ *            values must be in the range [0,18]. 
+ *   pThresholds - array of size 16 containing thresholds, TC0, for the top 
+ *            horizontal edge of each 4x4 block, arranged in horizontal block 
+ *            order; must be aligned on a 4-byte boundary.  Per [ISO14496 10] 
+ *            values must be in the range [0,25]. 
+ *   pBS - array of size 16 of BS parameters (arranged in horizontal block 
+ *            order); valid in the range [0,4] with the following 
+ *            restrictions: i) pBS[i]== 4 may occur only for 0<=i<=3, ii) 
+ *            pBS[i]== 4 if and only if pBS[i^3]== 4.  Must be 4-byte aligned. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst -Pointer to filtered output macroblock. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr, if the function runs without error.
+ * 
+ *    OMX_Sts_BadArgErr, if one of the following cases occurs: 
+ *    -    one or more of the following pointers is NULL: pSrcDst, pAlpha, 
+ *              pBeta, pThresholds, or pBS. 
+ *    -    either pThresholds or pBS is not aligned on a 4-byte boundary. 
+ *    -    pSrcDst is not 16-byte aligned. 
+ *    -    srcdstStep is not a multiple of 16. 
+ *    -    pAlpha[0] and/or pAlpha[1] is outside the range [0,255]. 
+ *    -    pBeta[0] and/or pBeta[1] is outside the range [0,18]. 
+ *    -    One or more entries in the table pThresholds[0..15] is 
+ *         outside of the range [0,25]. 
+ *    -    pBS is out of range, i.e., one of the following conditions is true: 
+ *              pBS[i]<0, pBS[i]>4, pBS[i]==4 for i>=4, or 
+ *              (pBS[i]==4 && pBS[i^3]!=4) for 0<=i<=3. 
+ *
+ */
+OMXResult omxVCM4P10_FilterDeblockingLuma_HorEdge_I (
+    OMX_U8 *pSrcDst,
+    OMX_S32 srcdstStep,
+    const OMX_U8 *pAlpha,
+    const OMX_U8 *pBeta,
+    const OMX_U8 *pThresholds,
+    const OMX_U8 *pBS
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_FilterDeblockingChroma_VerEdge_I   (6.3.3.3.3)
+ *
+ * Description:
+ * Performs in-place deblock filtering on four vertical edges of the chroma 
+ * macroblock (8x8). 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - Pointer to the input macroblock; must be 8-byte aligned. 
+ *   srcdstStep - Step of the arrays; must be a multiple of 8. 
+ *   pAlpha - Array of size 2 of alpha thresholds (the first item is alpha 
+ *            threshold for external vertical edge, and the second item is for 
+ *            internal vertical edge); per [ISO14496-10] alpha values must be 
+ *            in the range [0,255]. 
+ *   pBeta - Array of size 2 of beta thresholds (the first item is the beta 
+ *            threshold for the external vertical edge, and the second item is 
+ *            for the internal vertical edge); per [ISO14496-10] beta values 
+ *            must be in the range [0,18]. 
+ *   pThresholds - Array of size 8 containing thresholds, TC0, for the left 
+ *            vertical edge of each 4x2 chroma block, arranged in vertical 
+ *            block order; must be aligned on a 4-byte boundary.  Per 
+ *            [ISO14496-10] values must be in the range [0,25]. 
+ *   pBS - Array of size 16 of BS parameters (values for each 2x2 chroma 
+ *            block, arranged in vertical block order). This parameter is the 
+ *            same as the pBS parameter passed into FilterDeblockLuma_VerEdge; 
+ *            valid in the range [0,4] with the following restrictions: i) 
+ *            pBS[i]== 4 may occur only for 0<=i<=3, ii) pBS[i]== 4 if and 
+ *            only if pBS[i^3]== 4.  Must be 4 byte aligned. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst -Pointer to filtered output macroblock. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr, if the function runs without error.
+ * 
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    one or more of the following pointers is NULL: pSrcDst, pAlpha, 
+ *              pBeta, pThresholds, or pBS. 
+ *    -    pSrcDst is not 8-byte aligned. 
+ *    -    srcdstStep is not a multiple of 8. 
+ *    -    pThresholds is not 4-byte aligned. 
+ *    -    pAlpha[0] and/or pAlpha[1] is outside the range [0,255]. 
+ *    -    pBeta[0] and/or pBeta[1] is outside the range [0,18]. 
+ *    -    One or more entries in the table pThresholds[0..7] is outside 
+ *         of the range [0,25]. 
+ *    -    pBS is out of range, i.e., one of the following conditions is true: 
+ *         pBS[i]<0, pBS[i]>4, pBS[i]==4 for i>=4, or 
+ *         (pBS[i]==4 && pBS[i^3]!=4) for 0<=i<=3. 
+ *    -    pBS is not 4-byte aligned. 
+ *
+ */
+OMXResult omxVCM4P10_FilterDeblockingChroma_VerEdge_I (
+    OMX_U8 *pSrcDst,
+    OMX_S32 srcdstStep,
+    const OMX_U8 *pAlpha,
+    const OMX_U8 *pBeta,
+    const OMX_U8 *pThresholds,
+    const OMX_U8 *pBS
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_FilterDeblockingChroma_HorEdge_I   (6.3.3.3.4)
+ *
+ * Description:
+ * Performs in-place deblock filtering on the horizontal edges of the chroma 
+ * macroblock (8x8). 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - pointer to the input macroblock; must be 8-byte aligned. 
+ *   srcdstStep - array step; must be a multiple of 8. 
+ *   pAlpha - array of size 2 containing alpha thresholds; the first element 
+ *            contains the threshold for the external horizontal edge, and the 
+ *            second element contains the threshold for internal horizontal 
+ *            edge.  Per [ISO14496-10] alpha values must be in the range 
+ *            [0,255]. 
+ *   pBeta - array of size 2 containing beta thresholds; the first element 
+ *            contains the threshold for the external horizontal edge, and the 
+ *            second element contains the threshold for the internal 
+ *            horizontal edge.  Per [ISO14496-10] beta values must be in the 
+ *            range [0,18]. 
+ *   pThresholds - array of size 8 containing thresholds, TC0, for the top 
+ *            horizontal edge of each 2x4 chroma block, arranged in horizontal 
+ *            block order; must be aligned on a 4-byte boundary.  Per 
+ *            [ISO14496-10] values must be in the range [0,25]. 
+ *   pBS - array of size 16 containing BS parameters for each 2x2 chroma 
+ *            block, arranged in horizontal block order; valid in the range 
+ *            [0,4] with the following restrictions: i) pBS[i]== 4 may occur 
+ *            only for 0<=i<=3, ii) pBS[i]== 4 if and only if pBS[i^3]== 4. 
+ *            Must be 4-byte aligned. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst -Pointer to filtered output macroblock. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr, if the function runs without error.
+ * 
+ *    OMX_Sts_BadArgErr, if one of the following cases occurs: 
+ *    -    any of the following pointers is NULL: 
+ *         pSrcDst, pAlpha, pBeta, pThresholds, or pBS. 
+ *    -    pSrcDst is not 8-byte aligned. 
+ *    -    srcdstStep is not a multiple of 8. 
+ *    -    pThresholds is not 4-byte aligned. 
+ *    -    pAlpha[0] and/or pAlpha[1] is outside the range [0,255]. 
+ *    -    pBeta[0] and/or pBeta[1] is outside the range [0,18]. 
+ *    -    One or more entries in the table pThresholds[0..7] is outside 
+ *         of the range [0,25]. 
+ *    -    pBS is out of range, i.e., one of the following conditions is true: 
+ *              pBS[i]<0, pBS[i]>4, pBS[i]==4 for i>=4, or 
+ *              (pBS[i]==4 && pBS[i^3]!=4) for 0<=i<=3.
+ *    -    pBS is not 4-byte aligned. 
+ *
+ */
+OMXResult omxVCM4P10_FilterDeblockingChroma_HorEdge_I (
+    OMX_U8 *pSrcDst,
+    OMX_S32 srcdstStep,
+    const OMX_U8 *pAlpha,
+    const OMX_U8 *pBeta,
+    const OMX_U8 *pThresholds,
+    const OMX_U8 *pBS
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_DeblockLuma_I   (6.3.3.3.5)
+ *
+ * Description:
+ * This function performs in-place deblock filtering the horizontal and 
+ * vertical edges of a luma macroblock (16x16). 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - pointer to the input macroblock; must be 16-byte aligned. 
+ *   srcdstStep - image width; must be a multiple of 16. 
+ *   pAlpha - pointer to a 2x2 table of alpha thresholds, organized as 
+ *            follows: {external vertical edge, internal vertical edge, 
+ *            external horizontal edge, internal horizontal edge }.  Per 
+ *            [ISO14496-10] alpha values must be in the range [0,255]. 
+ *   pBeta - pointer to a 2x2 table of beta thresholds, organized as follows: 
+ *            {external vertical edge, internal vertical edge, external 
+ *            horizontal edge, internal horizontal edge }.  Per [ISO14496-10] 
+ *            beta values must be in the range [0,18]. 
+ *   pThresholds - pointer to a 16x2 table of threshold (TC0), organized as 
+ *            follows: {values for the left or above edge of each 4x4 block, 
+ *            arranged in vertical block order and then in horizontal block 
+ *            order}; must be aligned on a 4-byte boundary.  Per [ISO14496-10] 
+ *            values must be in the range [0,25]. 
+ *   pBS - pointer to a 16x2 table of BS parameters arranged in scan block 
+ *            order for vertical edges and then horizontal edges; valid in the 
+ *            range [0,4] with the following restrictions: i) pBS[i]== 4 may 
+ *            occur only for 0<=i<=3, ii) pBS[i]== 4 if and only if pBS[i^3]== 
+ *            4. Must be 4-byte aligned. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst - pointer to filtered output macroblock. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments 
+ *    -     one or more of the following pointers is NULL: pSrcDst, pAlpha, 
+ *              pBeta, pThresholds or pBS. 
+ *    -    pSrcDst is not 16-byte aligned. 
+ *    -    either pThresholds or pBS is not aligned on a 4-byte boundary. 
+ *    -    one or more entries in the table pAlpha[0..3] is outside the range 
+ *              [0,255]. 
+ *    -    one or more entries in the table pBeta[0..3] is outside the range 
+ *              [0,18]. 
+ *    -    one or more entries in the table pThresholds[0..31]is outside of 
+ *              the range [0,25]. 
+ *    -    pBS is out of range, i.e., one of the following conditions is true: 
+ *              pBS[i]<0, pBS[i]>4, pBS[i]==4 for i>=4, or 
+ *             (pBS[i]==4 && pBS[i^3]!=4) for 0<=i<=3. 
+ *    -    srcdstStep is not a multiple of 16. 
+ *
+ */
+OMXResult omxVCM4P10_DeblockLuma_I (
+    OMX_U8 *pSrcDst,
+    OMX_S32 srcdstStep,
+    const OMX_U8 *pAlpha,
+    const OMX_U8 *pBeta,
+    const OMX_U8 *pThresholds,
+    const OMX_U8 *pBS
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_DeblockChroma_I   (6.3.3.3.6)
+ *
+ * Description:
+ * Performs in-place deblocking filtering on all edges of the chroma 
+ * macroblock (16x16). 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - pointer to the input macroblock; must be 8-byte aligned. 
+ *   srcdstStep - step of the arrays; must be a multiple of 8. 
+ *   pAlpha - pointer to a 2x2 array of alpha thresholds, organized as 
+ *            follows: {external vertical edge, internal vertical edge, 
+ *            external horizontal edge, internal horizontal edge }.  Per 
+ *            [ISO14496-10] alpha values must be in the range [0,255]. 
+ *   pBeta - pointer to a 2x2 array of Beta Thresholds, organized as follows: 
+ *            { external vertical edge, internal vertical edge, external 
+ *            horizontal edge, internal horizontal edge }.  Per [ISO14496-10] 
+ *            beta values must be in the range [0,18]. 
+ *   pThresholds - array of size 8x2 of Thresholds (TC0) (values for the left 
+ *            or above edge of each 4x2 or 2x4 block, arranged in vertical 
+ *            block order and then in horizontal block order); must be aligned 
+ *            on a 4-byte boundary. Per [ISO14496-10] values must be in the 
+ *            range [0,25]. 
+ *   pBS - array of size 16x2 of BS parameters (arranged in scan block order 
+ *            for vertical edges and then horizontal edges); valid in the 
+ *            range [0,4] with the following restrictions: i) pBS[i]== 4 may 
+ *            occur only for 0<=i<=3, ii) pBS[i]== 4 if and only if pBS[i^3]== 
+ *            4.  Must be 4-byte aligned. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst - pointer to filtered output macroblock. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments 
+ *    -   one or more of the following pointers is NULL: pSrcDst, pAlpha, 
+ *              pBeta, pThresholds, or pBS. 
+ *    -   pSrcDst is not 8-byte aligned. 
+ *    -   either pThresholds or pBS is not 4-byte aligned. 
+ *    -   one or more entries in the table pAlpha[0..3] is outside the range 
+ *              [0,255]. 
+ *    -   one or more entries in the table pBeta[0..3] is outside the range 
+ *              [0,18]. 
+ *    -   one or more entries in the table pThresholds[0..15]is outside of 
+ *              the range [0,25]. 
+ *    -   pBS is out of range, i.e., one of the following conditions is true: 
+ *            pBS[i]<0, pBS[i]>4, pBS[i]==4  for i>=4, or 
+ *            (pBS[i]==4 && pBS[i^3]!=4) for 0<=i<=3. 
+ *    -   srcdstStep is not a multiple of 8. 
+ *
+ */
+OMXResult omxVCM4P10_DeblockChroma_I (
+    OMX_U8 *pSrcDst,
+    OMX_S32 srcdstStep,
+    const OMX_U8 *pAlpha,
+    const OMX_U8 *pBeta,
+    const OMX_U8 *pThresholds,
+    const OMX_U8 *pBS
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_DecodeChromaDcCoeffsToPairCAVLC   (6.3.4.1.1)
+ *
+ * Description:
+ * Performs CAVLC decoding and inverse raster scan for a 2x2 block of 
+ * ChromaDCLevel.  The decoded coefficients in the packed position-coefficient 
+ * buffer are stored in reverse zig-zag order, i.e., the first buffer element 
+ * contains the last non-zero postion-coefficient pair of the block. Within 
+ * each position-coefficient pair, the position entry indicates the 
+ * raster-scan position of the coefficient, while the coefficient entry 
+ * contains the coefficient value. 
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - Double pointer to current byte in bit stream buffer 
+ *   pOffset - Pointer to current bit position in the byte pointed to by 
+ *            *ppBitStream; valid in the range [0,7]. 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after each block is decoded 
+ *   pOffset - *pOffset is updated after each block is decoded 
+ *   pNumCoeff - Pointer to the number of nonzero coefficients in this block 
+ *   ppPosCoefBuf - Double pointer to destination residual 
+ *            coefficient-position pair buffer.  Buffer position 
+ *            (*ppPosCoefBuf) is updated upon return, unless there are only 
+ *            zero coefficients in the currently decoded block.  In this case 
+ *            the caller is expected to bypass the transform/dequantization of 
+ *            the empty blocks. 
+ *
+ * Return Value:
+ *
+ *    OMX_Sts_NoErr, if the function runs without error.
+ * 
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    ppBitStream or pOffset is NULL. 
+ *    -    ppPosCoefBuf or pNumCoeff is NULL. 
+ *    OMX_Sts_Err - if one of the following is true: 
+ *    -    an illegal code is encountered in the bitstream 
+ *
+ */
+OMXResult omxVCM4P10_DecodeChromaDcCoeffsToPairCAVLC (
+    const OMX_U8 **ppBitStream,
+    OMX_S32*pOffset,
+    OMX_U8 *pNumCoeff,
+    OMX_U8 **ppPosCoefbuf
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_DecodeCoeffsToPairCAVLC   (6.3.4.1.2)
+ *
+ * Description:
+ * Performs CAVLC decoding and inverse zigzag scan for 4x4 block of 
+ * Intra16x16DCLevel, Intra16x16ACLevel, LumaLevel, and ChromaACLevel. Inverse 
+ * field scan is not supported. The decoded coefficients in the packed 
+ * position-coefficient buffer are stored in reverse zig-zag order, i.e., the 
+ * first buffer element contains the last non-zero postion-coefficient pair of 
+ * the block. Within each position-coefficient pair, the position entry 
+ * indicates the raster-scan position of the coefficient, while the 
+ * coefficient entry contains the coefficient value. 
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream -Double pointer to current byte in bit stream buffer 
+ *   pOffset - Pointer to current bit position in the byte pointed to by 
+ *            *ppBitStream; valid in the range [0,7]. 
+ *   sMaxNumCoeff - Maximum the number of non-zero coefficients in current 
+ *            block 
+ *   sVLCSelect - VLC table selector, obtained from the number of non-zero 
+ *            coefficients contained in the above and left 4x4 blocks.  It is 
+ *            equivalent to the variable nC described in H.264 standard table 
+ *            9 5, except its value can t be less than zero. 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after each block is decoded.  
+ *            Buffer position (*ppPosCoefBuf) is updated upon return, unless 
+ *            there are only zero coefficients in the currently decoded block. 
+ *             In this case the caller is expected to bypass the 
+ *            transform/dequantization of the empty blocks. 
+ *   pOffset - *pOffset is updated after each block is decoded 
+ *   pNumCoeff - Pointer to the number of nonzero coefficients in this block 
+ *   ppPosCoefBuf - Double pointer to destination residual 
+ *            coefficient-position pair buffer 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ * 
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    ppBitStream or pOffset is NULL. 
+ *    -    ppPosCoefBuf or pNumCoeff is NULL. 
+ *    -    sMaxNumCoeff is not equal to either 15 or 16. 
+ *    -    sVLCSelect is less than 0. 
+ *
+ *    OMX_Sts_Err - if one of the following is true: 
+ *    -    an illegal code is encountered in the bitstream 
+ *
+ */
+OMXResult omxVCM4P10_DecodeCoeffsToPairCAVLC (
+    const OMX_U8 **ppBitStream,
+    OMX_S32 *pOffset,
+    OMX_U8 *pNumCoeff,
+    OMX_U8 **ppPosCoefbuf,
+    OMX_INT sVLCSelect,
+    OMX_INT sMaxNumCoeff
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_TransformDequantLumaDCFromPair   (6.3.4.2.1)
+ *
+ * Description:
+ * Reconstructs the 4x4 LumaDC block from the coefficient-position pair 
+ * buffer, performs integer inverse, and dequantization for 4x4 LumaDC 
+ * coefficients, and updates the pair buffer pointer to the next non-empty 
+ * block. 
+ *
+ * Input Arguments:
+ *   
+ *   ppSrc - Double pointer to residual coefficient-position pair buffer 
+ *            output by CALVC decoding 
+ *   QP - Quantization parameter QpY 
+ *
+ * Output Arguments:
+ *   
+ *   ppSrc - *ppSrc is updated to the start of next non empty block 
+ *   pDst - Pointer to the reconstructed 4x4 LumaDC coefficients buffer; must 
+ *            be aligned on a 8-byte boundary. 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    ppSrc or pDst is NULL. 
+ *    -    pDst is not 8 byte aligned. 
+ *    -    QP is not in the range of [0-51]. 
+ *
+ */
+OMXResult omxVCM4P10_TransformDequantLumaDCFromPair (
+    const OMX_U8 **ppSrc,
+    OMX_S16 *pDst,
+    OMX_INT QP
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_TransformDequantChromaDCFromPair   (6.3.4.2.2)
+ *
+ * Description:
+ * Reconstruct the 2x2 ChromaDC block from coefficient-position pair buffer, 
+ * perform integer inverse transformation, and dequantization for 2x2 chroma 
+ * DC coefficients, and update the pair buffer pointer to next non-empty 
+ * block. 
+ *
+ * Input Arguments:
+ *   
+ *   ppSrc - Double pointer to residual coefficient-position pair buffer 
+ *            output by CALVC decoding 
+ *   QP - Quantization parameter QpC 
+ *
+ * Output Arguments:
+ *   
+ *   ppSrc - *ppSrc is updated to the start of next non empty block 
+ *   pDst - Pointer to the reconstructed 2x2 ChromaDC coefficients buffer; 
+ *            must be aligned on a 4-byte boundary. 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    ppSrc or pDst is NULL. 
+ *    -    pDst is not 4-byte aligned. 
+ *    -    QP is not in the range of [0-51]. 
+ *
+ */
+OMXResult omxVCM4P10_TransformDequantChromaDCFromPair (
+    const OMX_U8 **ppSrc,
+    OMX_S16 *pDst,
+    OMX_INT QP
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_DequantTransformResidualFromPairAndAdd   (6.3.4.2.3)
+ *
+ * Description:
+ * Reconstruct the 4x4 residual block from coefficient-position pair buffer, 
+ * perform dequantization and integer inverse transformation for 4x4 block of 
+ * residuals with previous intra prediction or motion compensation data, and 
+ * update the pair buffer pointer to next non-empty block. If pDC == NULL, 
+ * there re 16 non-zero AC coefficients at most in the packed buffer starting 
+ * from 4x4 block position 0; If pDC != NULL, there re 15 non-zero AC 
+ * coefficients at most in the packet buffer starting from 4x4 block position 
+ * 1. 
+ *
+ * Input Arguments:
+ *   
+ *   ppSrc - Double pointer to residual coefficient-position pair buffer 
+ *            output by CALVC decoding 
+ *   pPred - Pointer to the predicted 4x4 block; must be aligned on a 4-byte 
+ *            boundary 
+ *   predStep - Predicted frame step size in bytes; must be a multiple of 4 
+ *   dstStep - Destination frame step in bytes; must be a multiple of 4 
+ *   pDC - Pointer to the DC coefficient of this block, NULL if it doesn't 
+ *            exist 
+ *   QP - QP Quantization parameter.  It should be QpC in chroma 4x4 block 
+ *            decoding, otherwise it should be QpY. 
+ *   AC - Flag indicating if at least one non-zero AC coefficient exists 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - pointer to the reconstructed 4x4 block data; must be aligned on a 
+ *            4-byte boundary 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    pPred or pDst is NULL. 
+ *    -    pPred or pDst is not 4-byte aligned. 
+ *    -    predStep or dstStep is not a multiple of 4. 
+ *    -    AC !=0 and Qp is not in the range of [0-51] or ppSrc == NULL. 
+ *    -    AC ==0 && pDC ==NULL. 
+ *
+ */
+OMXResult omxVCM4P10_DequantTransformResidualFromPairAndAdd (
+    const OMX_U8 **ppSrc,
+    const OMX_U8 *pPred,
+    const OMX_S16 *pDC,
+    OMX_U8 *pDst,
+    OMX_INT predStep,
+    OMX_INT dstStep,
+    OMX_INT QP,
+    OMX_INT AC
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_MEGetBufSize   (6.3.5.1.1)
+ *
+ * Description:
+ * Computes the size, in bytes, of the vendor-specific specification 
+ * structure for the omxVCM4P10 motion estimation functions BlockMatch_Integer 
+ * and MotionEstimationMB. 
+ *
+ * Input Arguments:
+ *   
+ *   MEmode - motion estimation mode; available modes are defined by the 
+ *            enumerated type OMXVCM4P10MEMode 
+ *   pMEParams -motion estimation parameters 
+ *
+ * Output Arguments:
+ *   
+ *   pSize - pointer to the number of bytes required for the motion 
+ *            estimation specification structure 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    pMEParams or pSize is NULL. 
+ *    -    an invalid MEMode is specified. 
+ *
+ */
+OMXResult omxVCM4P10_MEGetBufSize (
+    OMXVCM4P10MEMode MEmode,
+    const OMXVCM4P10MEParams *pMEParams,
+    OMX_U32 *pSize
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_MEInit   (6.3.5.1.2)
+ *
+ * Description:
+ * Initializes the vendor-specific specification structure required for the 
+ * omxVCM4P10 motion estimation functions:  BlockMatch_Integer and 
+ * MotionEstimationMB. Memory for the specification structure *pMESpec must be 
+ * allocated prior to calling the function, and should be aligned on a 4-byte 
+ * boundary.  The number of bytes required for the specification structure can 
+ * be determined using the function omxVCM4P10_MEGetBufSize. Following 
+ * initialization by this function, the vendor-specific structure *pMESpec 
+ * should contain an implementation-specific representation of all motion 
+ * estimation parameters received via the structure pMEParams, for example  
+ * searchRange16x16, searchRange8x8, etc. 
+ *
+ * Input Arguments:
+ *   
+ *   MEmode - motion estimation mode; available modes are defined by the 
+ *            enumerated type OMXVCM4P10MEMode 
+ *   pMEParams - motion estimation parameters 
+ *   pMESpec - pointer to the uninitialized ME specification structure 
+ *
+ * Output Arguments:
+ *   
+ *   pMESpec - pointer to the initialized ME specification structure 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    pMEParams or pSize is NULL. 
+ *    -    an invalid value was specified for the parameter MEmode 
+ *    -    a negative or zero value was specified for one of the search ranges 
+ *         (e.g.,  pMBParams >searchRange8x8, pMEParams->searchRange16x16, etc.) 
+ *    -    either in isolation or in combination, one or more of the enables or 
+ *         search ranges in the structure *pMEParams were configured such 
+ *         that the requested behavior fails to comply with [ISO14496-10]. 
+ *
+ */
+OMXResult omxVCM4P10_MEInit (
+    OMXVCM4P10MEMode MEmode,
+    const OMXVCM4P10MEParams *pMEParams,
+    void *pMESpec
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_BlockMatch_Integer   (6.3.5.2.1)
+ *
+ * Description:
+ * Performs integer block match.  Returns best MV and associated cost. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcOrgY - Pointer to the top-left corner of the current block:
+ *            If iBlockWidth==4,  4-byte alignment required. 
+ *            If iBlockWidth==8,  8-byte alignment required. 
+ *            If iBlockWidth==16, 16-byte alignment required. 
+ *   pSrcRefY - Pointer to the top-left corner of the co-located block in the 
+ *            reference picture: 
+ *            If iBlockWidth==4,  4-byte alignment required.  
+ *            If iBlockWidth==8,  8-byte alignment required.  
+ *            If iBlockWidth==16, 16-byte alignment required. 
+ *   nSrcOrgStep - Stride of the original picture plane, expressed in terms 
+ *            of integer pixels; must be a multiple of iBlockWidth. 
+ *   nSrcRefStep - Stride of the reference picture plane, expressed in terms 
+ *            of integer pixels 
+ *   pRefRect - pointer to the valid reference rectangle inside the reference 
+ *            picture plane 
+ *   nCurrPointPos - position of the current block in the current plane 
+ *   iBlockWidth - Width of the current block, expressed in terms of integer 
+ *            pixels; must be equal to either 4, 8, or 16. 
+ *   iBlockHeight - Height of the current block, expressed in terms of 
+ *            integer pixels; must be equal to either 4, 8, or 16. 
+ *   nLamda - Lamda factor; used to compute motion cost 
+ *   pMVPred - Predicted MV; used to compute motion cost, expressed in terms 
+ *            of 1/4-pel units 
+ *   pMVCandidate - Candidate MV; used to initialize the motion search, 
+ *            expressed in terms of integer pixels 
+ *   pMESpec - pointer to the ME specification structure 
+ *
+ * Output Arguments:
+ *   
+ *   pDstBestMV - Best MV resulting from integer search, expressed in terms 
+ *            of 1/4-pel units 
+ *   pBestCost - Motion cost associated with the best MV; computed as 
+ *            SAD+Lamda*BitsUsedByMV 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    any of the following pointers are NULL:
+ *         pSrcOrgY, pSrcRefY, pRefRect, pMVPred, pMVCandidate, or pMESpec. 
+ *    -    Either iBlockWidth or iBlockHeight are values other than 4, 8, or 16. 
+ *    -    Any alignment restrictions are violated 
+ *
+ */
+OMXResult omxVCM4P10_BlockMatch_Integer (
+    const OMX_U8 *pSrcOrgY,
+    OMX_S32 nSrcOrgStep,
+    const OMX_U8 *pSrcRefY,
+    OMX_S32 nSrcRefStep,
+    const OMXRect *pRefRect,
+    const OMXVCM4P2Coordinate *pCurrPointPos,
+    OMX_U8 iBlockWidth,
+    OMX_U8 iBlockHeight,
+    OMX_U32 nLamda,
+    const OMXVCMotionVector *pMVPred,
+    const OMXVCMotionVector *pMVCandidate,
+    OMXVCMotionVector *pBestMV,
+    OMX_S32 *pBestCost,
+    void *pMESpec
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_BlockMatch_Half   (6.3.5.2.2)
+ *
+ * Description:
+ * Performs a half-pel block match using results from a prior integer search. 
+ *  Returns the best MV and associated cost.  This function estimates the 
+ * half-pixel motion vector by interpolating the integer resolution motion 
+ * vector referenced by the input parameter pSrcDstBestMV, i.e., the initial 
+ * integer MV is generated externally.  The function 
+ * omxVCM4P10_BlockMatch_Integer may be used for integer motion estimation. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcOrgY - Pointer to the current position in original picture plane:
+ *              If iBlockWidth==4,  4-byte alignment required. 
+ *              If iBlockWidth==8,  8-byte alignment required. 
+ *              If iBlockWidth==16, 16-byte alignment required. 
+ *   pSrcRefY - Pointer to the top-left corner of the co-located block in the 
+ *            reference picture:  
+ *              If iBlockWidth==4,  4-byte alignment required.  
+ *              If iBlockWidth==8,  8-byte alignment required.  
+ *              If iBlockWidth==16, 16-byte alignment required. 
+ *   nSrcOrgStep - Stride of the original picture plane in terms of full 
+ *            pixels; must be a multiple of iBlockWidth. 
+ *   nSrcRefStep - Stride of the reference picture plane in terms of full 
+ *            pixels 
+ *   iBlockWidth - Width of the current block in terms of full pixels; must 
+ *            be equal to either 4, 8, or 16. 
+ *   iBlockHeight - Height of the current block in terms of full pixels; must 
+ *            be equal to either 4, 8, or 16. 
+ *   nLamda - Lamda factor, used to compute motion cost 
+ *   pMVPred - Predicted MV, represented in terms of 1/4-pel units; used to 
+ *            compute motion cost 
+ *   pSrcDstBestMV - The best MV resulting from a prior integer search, 
+ *            represented in terms of 1/4-pel units 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDstBestMV - Best MV resulting from the half-pel search, expressed in 
+ *            terms of 1/4-pel units 
+ *   pBestCost - Motion cost associated with the best MV; computed as 
+ *            SAD+Lamda*BitsUsedByMV 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    any of the following pointers is NULL: pSrcOrgY, pSrcRefY, 
+ *              pSrcDstBestMV, pMVPred, pBestCost 
+ *    -    iBlockWidth or iBlockHeight are equal to values other than 4, 8, or 16. 
+ *    -    Any alignment restrictions are violated 
+ *
+ */
+OMXResult omxVCM4P10_BlockMatch_Half (
+    const OMX_U8 *pSrcOrgY,
+    OMX_S32 nSrcOrgStep,
+    const OMX_U8 *pSrcRefY,
+    OMX_S32 nSrcRefStep,
+    OMX_U8 iBlockWidth,
+    OMX_U8 iBlockHeight,
+    OMX_U32 nLamda,
+    const OMXVCMotionVector *pMVPred,
+    OMXVCMotionVector *pSrcDstBestMV,
+    OMX_S32 *pBestCost
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_BlockMatch_Quarter   (6.3.5.2.3)
+ *
+ * Description:
+ * Performs a quarter-pel block match using results from a prior half-pel 
+ * search.  Returns the best MV and associated cost.  This function estimates 
+ * the quarter-pixel motion vector by interpolating the half-pel resolution 
+ * motion vector referenced by the input parameter pSrcDstBestMV, i.e., the 
+ * initial half-pel MV is generated externally.  The function 
+ * omxVCM4P10_BlockMatch_Half may be used for half-pel motion estimation. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcOrgY - Pointer to the current position in original picture plane:
+ *            If iBlockWidth==4,  4-byte alignment required. 
+ *            If iBlockWidth==8,  8-byte alignment required. 
+ *            If iBlockWidth==16, 16-byte alignment required. 
+ *   pSrcRefY - Pointer to the top-left corner of the co-located block in the 
+ *            reference picture:
+ *            If iBlockWidth==4,  4-byte alignment required.  
+ *            If iBlockWidth==8,  8-byte alignment required.  
+ *            If iBlockWidth==16, 16-byte alignment required. 
+ *   nSrcOrgStep - Stride of the original picture plane in terms of full 
+ *            pixels; must be a multiple of iBlockWidth. 
+ *   nSrcRefStep - Stride of the reference picture plane in terms of full 
+ *            pixels 
+ *   iBlockWidth - Width of the current block in terms of full pixels; must 
+ *            be equal to either 4, 8, or 16. 
+ *   iBlockHeight - Height of the current block in terms of full pixels; must 
+ *            be equal to either 4, 8, or 16. 
+ *   nLamda - Lamda factor, used to compute motion cost 
+ *   pMVPred - Predicted MV, represented in terms of 1/4-pel units; used to 
+ *            compute motion cost 
+ *   pSrcDstBestMV - The best MV resulting from a prior half-pel search, 
+ *            represented in terms of 1/4 pel units 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDstBestMV - Best MV resulting from the quarter-pel search, expressed 
+ *            in terms of 1/4-pel units 
+ *   pBestCost - Motion cost associated with the best MV; computed as 
+ *            SAD+Lamda*BitsUsedByMV 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    One or more of the following pointers is NULL: 
+ *         pSrcOrgY, pSrcRefY, pSrcDstBestMV, pMVPred, pBestCost 
+ *    -    iBlockWidth or iBlockHeight are equal to values other than 4, 8, or 16. 
+ *    -    Any alignment restrictions are violated 
+ *
+ */
+OMXResult omxVCM4P10_BlockMatch_Quarter (
+    const OMX_U8 *pSrcOrgY,
+    OMX_S32 nSrcOrgStep,
+    const OMX_U8 *pSrcRefY,
+    OMX_S32 nSrcRefStep,
+    OMX_U8 iBlockWidth,
+    OMX_U8 iBlockHeight,
+    OMX_U32 nLamda,
+    const OMXVCMotionVector *pMVPred,
+    OMXVCMotionVector *pSrcDstBestMV,
+    OMX_S32 *pBestCost
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_MotionEstimationMB   (6.3.5.3.1)
+ *
+ * Description:
+ * Performs MB-level motion estimation and selects best motion estimation 
+ * strategy from the set of modes supported in baseline profile [ISO14496-10]. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcCurrBuf - Pointer to the current position in original picture plane; 
+ *            16-byte alignment required 
+ *   pSrcRefBufList - Pointer to an array with 16 entries.  Each entry points 
+ *            to the top-left corner of the co-located MB in a reference 
+ *            picture.  The array is filled from low-to-high with valid 
+ *            reference frame pointers; the unused high entries should be set 
+ *            to NULL.  Ordering of the reference frames should follow 
+ *            [ISO14496-10] subclause 8.2.4  Decoding Process for Reference 
+ *            Picture Lists.   The entries must be 16-byte aligned. 
+ *   pSrcRecBuf - Pointer to the top-left corner of the co-located MB in the 
+ *            reconstructed picture; must be 16-byte aligned. 
+ *   SrcCurrStep - Width of the original picture plane in terms of full 
+ *            pixels; must be a multiple of 16. 
+ *   SrcRefStep - Width of the reference picture plane in terms of full 
+ *            pixels; must be a multiple of 16. 
+ *   SrcRecStep - Width of the reconstructed picture plane in terms of full 
+ *            pixels; must be a multiple of 16. 
+ *   pRefRect - Pointer to the valid reference rectangle; relative to the 
+ *            image origin. 
+ *   pCurrPointPos - Position of the current macroblock in the current plane. 
+ *   Lambda - Lagrange factor for computing the cost function 
+ *   pMESpec - Pointer to the motion estimation specification structure; must 
+ *            have been allocated and initialized prior to calling this 
+ *            function. 
+ *   pMBInter - Array, of dimension four, containing pointers to information 
+ *            associated with four adjacent type INTER MBs (Left, Top, 
+ *            Top-Left, Top-Right). Any pointer in the array may be set equal 
+ *            to NULL if the corresponding MB doesn t exist or is not of type 
+ *            INTER. 
+ *            -  pMBInter[0] - Pointer to left MB information 
+ *            -  pMBInter[1] - Pointer to top MB information 
+ *            -  pMBInter[2] - Pointer to top-left MB information 
+ *            -  pMBInter[3] - Pointer to top-right MB information 
+ *   pMBIntra - Array, of dimension four, containing pointers to information 
+ *            associated with four adjacent type INTRA MBs (Left, Top, 
+ *            Top-Left, Top-Right). Any pointer in the array may be set equal 
+ *            to NULL if the corresponding MB doesn t exist or is not of type 
+ *            INTRA. 
+ *            -  pMBIntra[0] - Pointer to left MB information 
+ *            -  pMBIntra[1] - Pointer to top MB information 
+ *            -  pMBIntra[2] - Pointer to top-left MB information 
+ *            -  pMBIntra[3] - Pointer to top-right MB information 
+ *   pSrcDstMBCurr - Pointer to information structure for the current MB.  
+ *            The following entries should be set prior to calling the 
+ *            function:  sliceID - the number of the slice the to which the 
+ *            current MB belongs. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstCost - Pointer to the minimum motion cost for the current MB. 
+ *   pDstBlockSAD - Pointer to the array of SADs for each of the sixteen luma 
+ *            4x4 blocks in each MB.  The block SADs are in scan order for 
+ *            each MB.  For implementations that cannot compute the SAD values 
+ *            individually, the maximum possible value (0xffff) is returned 
+ *            for each of the 16 block SAD entries. 
+ *   pSrcDstMBCurr - Pointer to updated information structure for the current 
+ *            MB after MB-level motion estimation has been completed.  The 
+ *            following fields are updated by the ME function.   The following 
+ *            parameter set quantifies the MB-level ME search results: 
+ *            -  MbType 
+ *            -  subMBType[4] 
+ *            -  pMV0[4][4] 
+ *            -  pMVPred[4][4] 
+ *            -  pRefL0Idx[4] 
+ *            -  Intra16x16PredMode 
+ *            -  pIntra4x4PredMode[4][4] 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -   One or more of the following pointers is NULL: pSrcCurrBuf, 
+ *           pSrcRefBufList, pSrcRecBuf, pRefRect, pCurrPointPos, pMESpec, 
+ *           pMBInter, pMBIntra,pSrcDstMBCurr, pDstCost, pSrcRefBufList[0] 
+ *    -    SrcRefStep, SrcRecStep are not multiples of 16 
+ *    -    iBlockWidth or iBlockHeight are values other than 4, 8, or 16. 
+ *    -    Any alignment restrictions are violated 
+ *
+ */
+OMXResult omxVCM4P10_MotionEstimationMB (
+    const OMX_U8 *pSrcCurrBuf,
+    OMX_S32 SrcCurrStep,
+    const OMX_U8 *pSrcRefBufList[15],
+    OMX_S32 SrcRefStep,
+    const OMX_U8 *pSrcRecBuf,
+    OMX_S32 SrcRecStep,
+    const OMXRect *pRefRect,
+    const OMXVCM4P2Coordinate *pCurrPointPos,
+    OMX_U32 Lambda,
+    void *pMESpec,
+    const OMXVCM4P10MBInfoPtr *pMBInter,
+    const OMXVCM4P10MBInfoPtr *pMBIntra,
+    OMXVCM4P10MBInfoPtr pSrcDstMBCurr,
+    OMX_INT *pDstCost,
+    OMX_U16 *pDstBlockSAD
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_SAD_4x   (6.3.5.4.1)
+ *
+ * Description:
+ * This function calculates the SAD for 4x8 and 4x4 blocks. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcOrg -Pointer to the original block; must be aligned on a 4-byte 
+ *            boundary. 
+ *   iStepOrg -Step of the original block buffer; must be a multiple of 4. 
+ *   pSrcRef -Pointer to the reference block 
+ *   iStepRef -Step of the reference block buffer 
+ *   iHeight -Height of the block; must be equal to either 4 or 8. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstSAD -Pointer of result SAD 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    One or more of the following pointers is NULL: 
+ *         pSrcOrg, pSrcRef, or pDstSAD 
+ *    -    iHeight is not equal to either 4 or 8. 
+ *    -    iStepOrg is not a multiple of 4 
+ *    -    Any alignment restrictions are violated 
+ *
+ */
+OMXResult omxVCM4P10_SAD_4x (
+    const OMX_U8 *pSrcOrg,
+    OMX_U32 iStepOrg,
+    const OMX_U8 *pSrcRef,
+    OMX_U32 iStepRef,
+    OMX_S32 *pDstSAD,
+    OMX_U32 iHeight
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_SADQuar_4x   (6.3.5.4.2)
+ *
+ * Description:
+ * This function calculates the SAD between one block (pSrc) and the average 
+ * of the other two (pSrcRef0 and pSrcRef1) for 4x8 or 4x4 blocks.  Rounding 
+ * is applied according to the convention (a+b+1)>>1. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - Pointer to the original block; must be aligned on a 4-byte 
+ *            boundary. 
+ *   pSrcRef0 - Pointer to reference block 0 
+ *   pSrcRef1 - Pointer to reference block 1 
+ *   iSrcStep - Step of the original block buffer; must be a multiple of 4. 
+ *   iRefStep0 - Step of reference block 0 
+ *   iRefStep1 - Step of reference block 1 
+ *   iHeight - Height of the block; must be equal to either 4 or 8. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstSAD - Pointer of result SAD 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    iHeight is not equal to either 4 or 8. 
+ *    -    One or more of the following pointers is NULL: pSrc, pSrcRef0, 
+ *              pSrcRef1, pDstSAD. 
+ *    -    iSrcStep is not a multiple of 4 
+ *    -    Any alignment restrictions are violated 
+ *
+ */
+OMXResult omxVCM4P10_SADQuar_4x (
+    const OMX_U8 *pSrc,
+    const OMX_U8 *pSrcRef0,
+    const OMX_U8 *pSrcRef1,
+    OMX_U32 iSrcStep,
+    OMX_U32 iRefStep0,
+    OMX_U32 iRefStep1,
+    OMX_U32 *pDstSAD,
+    OMX_U32 iHeight
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_SADQuar_8x   (6.3.5.4.3)
+ *
+ * Description:
+ * This function calculates the SAD between one block (pSrc) and the average 
+ * of the other two (pSrcRef0 and pSrcRef1) for 8x16, 8x8, or 8x4 blocks.  
+ * Rounding is applied according to the convention (a+b+1)>>1. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - Pointer to the original block; must be aligned on an 8-byte 
+ *            boundary. 
+ *   pSrcRef0 - Pointer to reference block 0 
+ *   pSrcRef1 - Pointer to reference block 1 
+ *   iSrcStep - Step of the original block buffer; must be a multiple of 8. 
+ *   iRefStep0 - Step of reference block 0 
+ *   iRefStep1 - Step of reference block 1 
+ *   iHeight - Height of the block; must be equal either 4, 8, or 16. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstSAD - Pointer of result SAD 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    iHeight is not equal to either 4, 8, or 16. 
+ *    -    One or more of the following pointers is NULL: pSrc, pSrcRef0, 
+ *              pSrcRef1, pDstSAD. 
+ *    -    iSrcStep is not a multiple of 8 
+ *    -    Any alignment restrictions are violated 
+ *
+ */
+OMXResult omxVCM4P10_SADQuar_8x (
+    const OMX_U8 *pSrc,
+    const OMX_U8 *pSrcRef0,
+    const OMX_U8 *pSrcRef1,
+    OMX_U32 iSrcStep,
+    OMX_U32 iRefStep0,
+    OMX_U32 iRefStep1,
+    OMX_U32 *pDstSAD,
+    OMX_U32 iHeight
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_SADQuar_16x   (6.3.5.4.4)
+ *
+ * Description:
+ * This function calculates the SAD between one block (pSrc) and the average 
+ * of the other two (pSrcRef0 and pSrcRef1) for 16x16 or 16x8 blocks.  
+ * Rounding is applied according to the convention (a+b+1)>>1. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - Pointer to the original block; must be aligned on a 16-byte 
+ *            boundary. 
+ *   pSrcRef0 - Pointer to reference block 0 
+ *   pSrcRef1 - Pointer to reference block 1 
+ *   iSrcStep - Step of the original block buffer; must be a multiple of 16 
+ *   iRefStep0 - Step of reference block 0 
+ *   iRefStep1 - Step of reference block 1 
+ *   iHeight - Height of the block; must be equal to either 8 or 16 
+ *
+ * Output Arguments:
+ *   
+ *   pDstSAD -Pointer of result SAD 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    iHeight is not equal to either 8 or 16. 
+ *    -    One or more of the following pointers is NULL: pSrc, pSrcRef0, 
+ *              pSrcRef1, pDstSAD. 
+ *    -    iSrcStep is not a multiple of 16 
+ *    -    Any alignment restrictions are violated 
+ *
+ */
+OMXResult omxVCM4P10_SADQuar_16x (
+    const OMX_U8 *pSrc,
+    const OMX_U8 *pSrcRef0,
+    const OMX_U8 *pSrcRef1,
+    OMX_U32 iSrcStep,
+    OMX_U32 iRefStep0,
+    OMX_U32 iRefStep1,
+    OMX_U32 *pDstSAD,
+    OMX_U32 iHeight
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_SATD_4x4   (6.3.5.4.5)
+ *
+ * Description:
+ * This function calculates the sum of absolute transform differences (SATD) 
+ * for a 4x4 block by applying a Hadamard transform to the difference block 
+ * and then calculating the sum of absolute coefficient values. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcOrg - Pointer to the original block; must be aligned on a 4-byte 
+ *            boundary 
+ *   iStepOrg - Step of the original block buffer; must be a multiple of 4 
+ *   pSrcRef - Pointer to the reference block; must be aligned on a 4-byte 
+ *            boundary 
+ *   iStepRef - Step of the reference block buffer; must be a multiple of 4 
+ *
+ * Output Arguments:
+ *   
+ *   pDstSAD - pointer to the resulting SAD 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: 
+ *         pSrcOrg, pSrcRef, or pDstSAD either pSrcOrg 
+ *    -    pSrcRef is not aligned on a 4-byte boundary 
+ *    -    iStepOrg <= 0 or iStepOrg is not a multiple of 4 
+ *    -    iStepRef <= 0 or iStepRef is not a multiple of 4 
+ *
+ */
+OMXResult omxVCM4P10_SATD_4x4 (
+    const OMX_U8 *pSrcOrg,
+    OMX_U32 iStepOrg,
+    const OMX_U8 *pSrcRef,
+    OMX_U32 iStepRef,
+    OMX_U32 *pDstSAD
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_InterpolateHalfHor_Luma   (6.3.5.5.1)
+ *
+ * Description:
+ * This function performs interpolation for two horizontal 1/2-pel positions 
+ * (-1/2,0) and (1/2, 0) - around a full-pel position. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - Pointer to the top-left corner of the block used to interpolate in 
+ *            the reconstruction frame plane. 
+ *   iSrcStep - Step of the source buffer. 
+ *   iDstStep - Step of the destination(interpolation) buffer; must be a 
+ *            multiple of iWidth. 
+ *   iWidth - Width of the current block; must be equal to either 4, 8, or 16 
+ *   iHeight - Height of the current block; must be equal to 4, 8, or 16 
+ *
+ * Output Arguments:
+ *   
+ *   pDstLeft -Pointer to the interpolation buffer of the left -pel position 
+ *            (-1/2, 0) 
+ *                 If iWidth==4,  4-byte alignment required. 
+ *                 If iWidth==8,  8-byte alignment required. 
+ *                 If iWidth==16, 16-byte alignment required. 
+ *   pDstRight -Pointer to the interpolation buffer of the right -pel 
+ *            position (1/2, 0) 
+ *                 If iWidth==4,  4-byte alignment required. 
+ *                 If iWidth==8,  8-byte alignment required. 
+ *                 If iWidth==16, 16-byte alignment required. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: 
+ *             pSrc, pDstLeft, or pDstRight 
+ *    -    iWidth or iHeight have values other than 4, 8, or 16 
+ *    -    iWidth==4 but pDstLeft and/or pDstRight is/are not aligned on a 4-byte boundary 
+ *    -    iWidth==8 but pDstLeft and/or pDstRight is/are not aligned on a 8-byte boundary 
+ *    -    iWidth==16 but pDstLeft and/or pDstRight is/are not aligned on a 16-byte boundary 
+ *    -    any alignment restrictions are violated 
+ *
+ */
+OMXResult omxVCM4P10_InterpolateHalfHor_Luma (
+    const OMX_U8 *pSrc,
+    OMX_U32 iSrcStep,
+    OMX_U8 *pDstLeft,
+    OMX_U8 *pDstRight,
+    OMX_U32 iDstStep,
+    OMX_U32 iWidth,
+    OMX_U32 iHeight
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_InterpolateHalfVer_Luma   (6.3.5.5.2)
+ *
+ * Description:
+ * This function performs interpolation for two vertical 1/2-pel positions - 
+ * (0, -1/2) and (0, 1/2) - around a full-pel position. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - Pointer to top-left corner of block used to interpolate in the 
+ *            reconstructed frame plane 
+ *   iSrcStep - Step of the source buffer. 
+ *   iDstStep - Step of the destination (interpolation) buffer; must be a 
+ *            multiple of iWidth. 
+ *   iWidth - Width of the current block; must be equal to either 4, 8, or 16 
+ *   iHeight - Height of the current block; must be equal to either 4, 8, or 16 
+ *
+ * Output Arguments:
+ *   
+ *   pDstUp -Pointer to the interpolation buffer of the -pel position above 
+ *            the current full-pel position (0, -1/2) 
+ *                If iWidth==4, 4-byte alignment required. 
+ *                If iWidth==8, 8-byte alignment required. 
+ *                If iWidth==16, 16-byte alignment required. 
+ *   pDstDown -Pointer to the interpolation buffer of the -pel position below 
+ *            the current full-pel position (0, 1/2) 
+ *                If iWidth==4, 4-byte alignment required. 
+ *                If iWidth==8, 8-byte alignment required. 
+ *                If iWidth==16, 16-byte alignment required. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: 
+ *            pSrc, pDstUp, or pDstDown 
+ *    -    iWidth or iHeight have values other than 4, 8, or 16 
+ *    -    iWidth==4 but pDstUp and/or pDstDown is/are not aligned on a 4-byte boundary 
+ *    -    iWidth==8 but pDstUp and/or pDstDown is/are not aligned on a 8-byte boundary 
+ *    -    iWidth==16 but pDstUp and/or pDstDown is/are not aligned on a 16-byte boundary 
+ *
+ */
+OMXResult omxVCM4P10_InterpolateHalfVer_Luma (
+    const OMX_U8 *pSrc,
+    OMX_U32 iSrcStep,
+    OMX_U8 *pDstUp,
+    OMX_U8 *pDstDown,
+    OMX_U32 iDstStep,
+    OMX_U32 iWidth,
+    OMX_U32 iHeight
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_Average_4x   (6.3.5.5.3)
+ *
+ * Description:
+ * This function calculates the average of two 4x4, 4x8 blocks.  The result 
+ * is rounded according to (a+b+1)/2. 
+ *
+ * Input Arguments:
+ *   
+ *   pPred0 - Pointer to the top-left corner of reference block 0 
+ *   pPred1 - Pointer to the top-left corner of reference block 1 
+ *   iPredStep0 - Step of reference block 0; must be a multiple of 4. 
+ *   iPredStep1 - Step of reference block 1; must be a multiple of 4. 
+ *   iDstStep - Step of the destination buffer; must be a multiple of 4. 
+ *   iHeight - Height of the blocks; must be either 4 or 8. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstPred - Pointer to the destination buffer. 4-byte alignment required. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: 
+ *           pPred0, pPred1, or pDstPred 
+ *    -    pDstPred is not aligned on a 4-byte boundary 
+ *    -    iPredStep0 <= 0 or iPredStep0 is not a multiple of 4 
+ *    -    iPredStep1 <= 0 or iPredStep1 is not a multiple of 4 
+ *    -    iDstStep <= 0 or iDstStep is not a multiple of 4 
+ *    -    iHeight is not equal to either 4 or 8 
+ *
+ */
+OMXResult omxVCM4P10_Average_4x (
+    const OMX_U8 *pPred0,
+    const OMX_U8 *pPred1,
+    OMX_U32 iPredStep0,
+    OMX_U32 iPredStep1,
+    OMX_U8 *pDstPred,
+    OMX_U32 iDstStep,
+    OMX_U32 iHeight
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_TransformQuant_ChromaDC   (6.3.5.6.1)
+ *
+ * Description:
+ * This function performs 2x2 Hadamard transform of chroma DC coefficients 
+ * and then quantizes the coefficients. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - Pointer to the 2x2 array of chroma DC coefficients.  8-byte 
+ *            alignment required. 
+ *   iQP - Quantization parameter; must be in the range [0,51]. 
+ *   bIntra - Indicate whether this is an INTRA block. 1-INTRA, 0-INTER 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst - Pointer to transformed and quantized coefficients.  8-byte 
+ *            alignment required. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: 
+ *             pSrcDst 
+ *    -    pSrcDst is not aligned on an 8-byte boundary 
+ *
+ */
+OMXResult omxVCM4P10_TransformQuant_ChromaDC (
+    OMX_S16 *pSrcDst,
+    OMX_U32 iQP,
+    OMX_U8 bIntra
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_TransformQuant_LumaDC   (6.3.5.6.2)
+ *
+ * Description:
+ * This function performs a 4x4 Hadamard transform of luma DC coefficients 
+ * and then quantizes the coefficients. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - Pointer to the 4x4 array of luma DC coefficients.  16-byte 
+ *            alignment required. 
+ *   iQP - Quantization parameter; must be in the range [0,51]. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst - Pointer to transformed and quantized coefficients.  16-byte 
+ *             alignment required. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: pSrcDst 
+ *    -    pSrcDst is not aligned on an 16-byte boundary 
+ *
+ */
+OMXResult omxVCM4P10_TransformQuant_LumaDC (
+    OMX_S16 *pSrcDst,
+    OMX_U32 iQP
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_InvTransformDequant_LumaDC   (6.3.5.6.3)
+ *
+ * Description:
+ * This function performs inverse 4x4 Hadamard transform and then dequantizes 
+ * the coefficients. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - Pointer to the 4x4 array of the 4x4 Hadamard-transformed and 
+ *            quantized coefficients.  16 byte alignment required. 
+ *   iQP - Quantization parameter; must be in the range [0,51]. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - Pointer to inverse-transformed and dequantized coefficients.  
+ *            16-byte alignment required. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: pSrc 
+ *    -    pSrc or pDst is not aligned on a 16-byte boundary 
+ *
+ */
+OMXResult omxVCM4P10_InvTransformDequant_LumaDC (
+    const OMX_S16 *pSrc,
+    OMX_S16 *pDst,
+    OMX_U32 iQP
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_InvTransformDequant_ChromaDC   (6.3.5.6.4)
+ *
+ * Description:
+ * This function performs inverse 2x2 Hadamard transform and then dequantizes 
+ * the coefficients. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - Pointer to the 2x2 array of the 2x2 Hadamard-transformed and 
+ *            quantized coefficients.  8 byte alignment required. 
+ *   iQP - Quantization parameter; must be in the range [0,51]. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - Pointer to inverse-transformed and dequantized coefficients.  
+ *            8-byte alignment required. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: pSrc 
+ *    -    pSrc or pDst is not aligned on an 8-byte boundary 
+ *
+ */
+OMXResult omxVCM4P10_InvTransformDequant_ChromaDC (
+    const OMX_S16 *pSrc,
+    OMX_S16 *pDst,
+    OMX_U32 iQP
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_InvTransformResidualAndAdd   (6.3.5.7.1)
+ *
+ * Description:
+ * This function performs inverse an 4x4 integer transformation to produce 
+ * the difference signal and then adds the difference to the prediction to get 
+ * the reconstructed signal. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcPred - Pointer to prediction signal.  4-byte alignment required. 
+ *   pDequantCoeff - Pointer to the transformed coefficients.  8-byte 
+ *            alignment required. 
+ *   iSrcPredStep - Step of the prediction buffer; must be a multiple of 4. 
+ *   iDstReconStep - Step of the destination reconstruction buffer; must be a 
+ *            multiple of 4. 
+ *   bAC - Indicate whether there is AC coefficients in the coefficients 
+ *            matrix. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstRecon -Pointer to the destination reconstruction buffer.  4-byte 
+ *            alignment required. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: 
+ *            pSrcPred, pDequantCoeff, pDstRecon 
+ *    -    pSrcPred is not aligned on a 4-byte boundary 
+ *    -    iSrcPredStep or iDstReconStep is not a multiple of 4. 
+ *    -    pDequantCoeff is not aligned on an 8-byte boundary 
+ *
+ */
+OMXResult omxVCM4P10_InvTransformResidualAndAdd (
+    const OMX_U8 *pSrcPred,
+    const OMX_S16 *pDequantCoeff,
+    OMX_U8 *pDstRecon,
+    OMX_U32 iSrcPredStep,
+    OMX_U32 iDstReconStep,
+    OMX_U8 bAC
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_SubAndTransformQDQResidual   (6.3.5.8.1)
+ *
+ * Description:
+ * This function subtracts the prediction signal from the original signal to 
+ * produce the difference signal and then performs a 4x4 integer transform and 
+ * quantization. The quantized transformed coefficients are stored as 
+ * pDstQuantCoeff. This function can also output dequantized coefficients or 
+ * unquantized DC coefficients optionally by setting the pointers 
+ * pDstDeQuantCoeff, pDCCoeff. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcOrg - Pointer to original signal. 4-byte alignment required. 
+ *   pSrcPred - Pointer to prediction signal. 4-byte alignment required. 
+ *   iSrcOrgStep - Step of the original signal buffer; must be a multiple of 
+ *            4. 
+ *   iSrcPredStep - Step of the prediction signal buffer; must be a multiple 
+ *            of 4. 
+ *   pNumCoeff -Number of non-zero coefficients after quantization. If this 
+ *            parameter is not required, it is set to NULL. 
+ *   nThreshSAD - Zero-block early detection threshold. If this parameter is 
+ *            not required, it is set to 0. 
+ *   iQP - Quantization parameter; must be in the range [0,51]. 
+ *   bIntra - Indicates whether this is an INTRA block, either 1-INTRA or 
+ *            0-INTER 
+ *
+ * Output Arguments:
+ *   
+ *   pDstQuantCoeff - Pointer to the quantized transformed coefficients.  
+ *            8-byte alignment required. 
+ *   pDstDeQuantCoeff - Pointer to the dequantized transformed coefficients 
+ *            if this parameter is not equal to NULL.  8-byte alignment 
+ *            required. 
+ *   pDCCoeff - Pointer to the unquantized DC coefficient if this parameter 
+ *            is not equal to NULL. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: 
+ *            pSrcOrg, pSrcPred, pNumCoeff, pDstQuantCoeff, 
+ *            pDstDeQuantCoeff, pDCCoeff 
+ *    -    pSrcOrg is not aligned on a 4-byte boundary 
+ *    -    pSrcPred is not aligned on a 4-byte boundary 
+ *    -    iSrcOrgStep is not a multiple of 4 
+ *    -    iSrcPredStep is not a multiple of 4 
+ *    -    pDstQuantCoeff or pDstDeQuantCoeff is not aligned on an 8-byte boundary 
+ *
+ */
+OMXResult omxVCM4P10_SubAndTransformQDQResidual (
+    const OMX_U8 *pSrcOrg,
+    const OMX_U8 *pSrcPred,
+    OMX_U32 iSrcOrgStep,
+    OMX_U32 iSrcPredStep,
+    OMX_S16 *pDstQuantCoeff,
+    OMX_S16 *pDstDeQuantCoeff,
+    OMX_S16 *pDCCoeff,
+    OMX_S8 *pNumCoeff,
+    OMX_U32 nThreshSAD,
+    OMX_U32 iQP,
+    OMX_U8 bIntra
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_GetVLCInfo   (6.3.5.9.1)
+ *
+ * Description:
+ * This function extracts run-length encoding (RLE) information from the 
+ * coefficient matrix.  The results are returned in an OMXVCM4P10VLCInfo 
+ * structure. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcCoeff - pointer to the transform coefficient matrix.  8-byte 
+ *            alignment required. 
+ *   pScanMatrix - pointer to the scan order definition matrix.  For a luma 
+ *            block the scan matrix should follow [ISO14496-10] section 8.5.4, 
+ *            and should contain the values 0, 1, 4, 8, 5, 2, 3, 6, 9, 12, 13, 
+ *            10, 7, 11, 14, 15.  For a chroma block, the scan matrix should 
+ *            contain the values 0, 1, 2, 3. 
+ *   bAC - indicates presence of a DC coefficient; 0 = DC coefficient 
+ *            present, 1= DC coefficient absent. 
+ *   MaxNumCoef - specifies the number of coefficients contained in the 
+ *            transform coefficient matrix, pSrcCoeff. The value should be 16 
+ *            for blocks of type LUMADC, LUMAAC, LUMALEVEL, and CHROMAAC. The 
+ *            value should be 4 for blocks of type CHROMADC. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstVLCInfo - pointer to structure that stores information for 
+ *            run-length coding. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: 
+ *            pSrcCoeff, pScanMatrix, pDstVLCInfo 
+ *    -    pSrcCoeff is not aligned on an 8-byte boundary 
+ *
+ */
+OMXResult omxVCM4P10_GetVLCInfo (
+    const OMX_S16 *pSrcCoeff,
+    const OMX_U8 *pScanMatrix,
+    OMX_U8 bAC,
+    OMX_U32 MaxNumCoef,
+    OMXVCM4P10VLCInfo*pDstVLCInfo
+);
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /** end of #define _OMXVC_H_ */
+
+/** EOF */
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/api/omxVC_s.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/api/omxVC_s.h
new file mode 100644
index 0000000..be974d5
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/api/omxVC_s.h
@@ -0,0 +1,129 @@
+;/******************************************************************************
+;// Copyright (c) 1999-2005 The Khronos Group Inc. All Rights Reserved
+;//
+;//
+;//
+;//
+;//
+;//
+;//
+;//
+;******************************************************************************/
+
+;/** =============== Structure Definition for Sample Generation ============== */
+;/** transparent status */
+
+;enum {
+OMX_VIDEO_TRANSPARENT	EQU 0;	/** Wholly transparent */
+OMX_VIDEO_PARTIAL		EQU 1;	/** Partially transparent */
+OMX_VIDEO_OPAQUE		EQU 2;	/** Opaque */
+;}
+
+;/** direction */
+;enum {
+OMX_VIDEO_NONE			EQU 0;
+OMX_VIDEO_HORIZONTAL	EQU 1;
+OMX_VIDEO_VERTICAL		EQU 2;
+;}
+
+;/** bilinear interpolation type */
+;enum {
+OMX_VIDEO_INTEGER_PIXEL EQU 0;	/** case ¡°a¡± */
+OMX_VIDEO_HALF_PIXEL_X  EQU 1;	/** case ¡°b¡± */
+OMX_VIDEO_HALF_PIXEL_Y  EQU 2;	/** case ¡°c¡± */
+OMX_VIDEO_HALF_PIXEL_XY EQU 3;	/** case ¡°d¡± */
+;}
+
+;enum {
+OMX_UPPER  				EQU 1;			/** set if the above macroblock is available */
+OMX_LEFT   				EQU 2;			/** set if the left macroblock is available */
+OMX_CENTER 				EQU 4;
+OMX_RIGHT				EQU 8;
+OMX_LOWER  				EQU	16;
+OMX_UPPER_LEFT  		EQU 32;		/** set if the above-left macroblock is available */
+OMX_UPPER_RIGHT 		EQU 64;		/** set if the above-right macroblock is available */
+OMX_LOWER_LEFT  		EQU 128;
+OMX_LOWER_RIGHT 		EQU 256
+;}
+
+;enum {
+OMX_VIDEO_LUMINANCE  	EQU 0;	/** Luminance component */
+OMX_VIDEO_CHROMINANCE  	EQU 1;	/** chrominance component */
+OMX_VIDEO_ALPHA  		EQU 2;			/** Alpha component */
+;}
+
+;enum {
+OMX_VIDEO_INTER			EQU 0;	/** P picture or P-VOP */
+OMX_VIDEO_INTER_Q		EQU 1;	/** P picture or P-VOP */
+OMX_VIDEO_INTER4V		EQU 2;	/** P picture or P-VOP */
+OMX_VIDEO_INTRA			EQU 3;	/** I and P picture; I- and P-VOP */
+OMX_VIDEO_INTRA_Q		EQU 4;	/** I and P picture; I- and P-VOP */
+OMX_VIDEO_INTER4V_Q		EQU 5;	/** P picture or P-VOP (H.263)*/
+OMX_VIDEO_DIRECT		EQU 6;	/** B picture or B-VOP (MPEG-4 only) */
+OMX_VIDEO_INTERPOLATE	EQU 7;	/** B picture or B-VOP */
+OMX_VIDEO_BACKWARD		EQU 8;	/** B picture or B-VOP */
+OMX_VIDEO_FORWARD		EQU 9;	/** B picture or B-VOP */
+OMX_VIDEO_NOTCODED		EQU 10;	/** B picture or B-VOP */
+;}
+
+;enum {
+OMX_16X16_VERT 			EQU 0;		/** Intra_16x16_Vertical (prediction mode) */
+OMX_16X16_HOR 			EQU 1;		/** Intra_16x16_Horizontal (prediction mode) */
+OMX_16X16_DC 			EQU 2;		/** Intra_16x16_DC (prediction mode) */
+OMX_16X16_PLANE 		EQU 3;	/** Intra_16x16_Plane (prediction mode) */
+;}
+
+;enum {
+OMX_4x4_VERT 			EQU 0;		/** Intra_4x4_Vertical (prediction mode) */
+OMX_4x4_HOR  			EQU 1;		/** Intra_4x4_Horizontal (prediction mode) */
+OMX_4x4_DC   			EQU 2;		/** Intra_4x4_DC (prediction mode) */
+OMX_4x4_DIAG_DL 		EQU 3;	/** Intra_4x4_Diagonal_Down_Left (prediction mode) */
+OMX_4x4_DIAG_DR 		EQU 4;	/** Intra_4x4_Diagonal_Down_Right (prediction mode) */
+OMX_4x4_VR 				EQU 5;			/** Intra_4x4_Vertical_Right (prediction mode) */
+OMX_4x4_HD 				EQU 6;			/** Intra_4x4_Horizontal_Down (prediction mode) */
+OMX_4x4_VL 				EQU 7;			/** Intra_4x4_Vertical_Left (prediction mode) */
+OMX_4x4_HU 				EQU 8;			/** Intra_4x4_Horizontal_Up (prediction mode) */
+;}
+
+;enum {
+OMX_CHROMA_DC 			EQU 0;		/** Intra_Chroma_DC (prediction mode) */
+OMX_CHROMA_HOR 			EQU 1;		/** Intra_Chroma_Horizontal (prediction mode) */
+OMX_CHROMA_VERT 		EQU 2;	/** Intra_Chroma_Vertical (prediction mode) */
+OMX_CHROMA_PLANE 		EQU 3;	/** Intra_Chroma_Plane (prediction mode) */
+;}
+
+;typedef	struct {	
+x	EQU	0;
+y	EQU	4;
+;}OMXCoordinate;
+
+;typedef struct {
+dx	EQU	0;
+dy	EQU	2;
+;}OMXMotionVector;
+
+;typedef struct {
+xx		EQU	0;
+yy		EQU	4;
+width	EQU	8;
+height	EQU	12;
+;}OMXiRect;
+
+;typedef enum {
+OMX_VC_INTER         EQU 0;        /** P picture or P-VOP */
+OMX_VC_INTER_Q       EQU 1;       /** P picture or P-VOP */
+OMX_VC_INTER4V       EQU 2;       /** P picture or P-VOP */
+OMX_VC_INTRA         EQU 3;        /** I and P picture, I- and P-VOP */
+OMX_VC_INTRA_Q       EQU 4;       /** I and P picture, I- and P-VOP */
+OMX_VC_INTER4V_Q     EQU 5;    /** P picture or P-VOP (H.263)*/
+;} OMXVCM4P2MacroblockType;
+
+;enum {
+OMX_VC_NONE          EQU 0
+OMX_VC_HORIZONTAL    EQU 1
+OMX_VC_VERTICAL      EQU 2 
+;};
+
+
+	END
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/comm/src/omxVCCOMM_Copy16x16_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/comm/src/omxVCCOMM_Copy16x16_s.s
new file mode 100644
index 0000000..2663a70
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/comm/src/omxVCCOMM_Copy16x16_s.s
@@ -0,0 +1,148 @@
+ ;/**
+ ; * Function: omxVCCOMM_Copy16x16
+ ; *
+ ; * Description:
+ ; * Copies the reference 16x16 block to the current block.
+ ; * Parameters:
+ ; * [in] pSrc         - pointer to the reference block in the source frame; must be aligned on an 16-byte boundary.
+ ; * [in] step         - distance between the starts of consecutive lines in the reference frame, in bytes;
+ ; *                     must be a multiple of 16 and must be larger than or equal to 16.
+ ; * [out] pDst        - pointer to the destination block; must be aligned on an 8-byte boundary.
+ ; * Return Value:
+ ; * OMX_Sts_NoErr     - no error
+ ; * OMX_Sts_BadArgErr - bad arguments; returned under any of the following conditions:
+ ; *                   - one or more of the following pointers is NULL:  pSrc, pDst
+ ; *                   - one or more of the following pointers is not aligned on an 16-byte boundary:  pSrc, pDst
+ ; *                   - step <16 or step is not a multiple of 16.  
+ ; */
+
+   INCLUDE omxtypes_s.h
+   
+     
+     M_VARIANTS ARM1136JS
+     
+
+
+
+     IF ARM1136JS
+
+;//Input Arguments
+pSrc    RN 0        
+pDst    RN 1        
+step    RN 2
+
+;//Local Variables
+Count   RN 14
+X0      RN 2
+X1      RN 4
+
+Return  RN 0
+     
+     M_START omxVCCOMM_Copy16x16,r5
+        
+        
+        
+        SUB   Count,step,#8                 ;//Count=step-8
+        LDRD  X0,[pSrc],#8                  ;//pSrc after loading pSrc=pSrc+8
+        LDRD  X1,[pSrc],Count               ;//pSrc after loading pSrc=pSrc+step
+        
+        ;// loading 16 bytes and storing
+        STRD  X0,[pDst],#8               
+        LDRD  X0,[pSrc],#8 
+        STRD  X1,[pDst],#8               
+        LDRD  X1,[pSrc],Count
+        
+        ;// loading 16 bytes and storing
+        STRD  X0,[pDst],#8               
+        LDRD  X0,[pSrc],#8
+        STRD  X1,[pDst],#8               
+        LDRD  X1,[pSrc],Count
+        
+        ;// loading 16 bytes and storing
+        STRD  X0,[pDst],#8               
+        LDRD  X0,[pSrc],#8
+        STRD  X1,[pDst],#8               
+        LDRD  X1,[pSrc],Count
+        
+        ;// loading 16 bytes and storing
+        STRD  X0,[pDst],#8               
+        LDRD  X0,[pSrc],#8
+        STRD  X1,[pDst],#8               
+        LDRD  X1,[pSrc],Count
+        
+        ;// loading 16 bytes and storing
+        STRD  X0,[pDst],#8               
+        LDRD  X0,[pSrc],#8
+        STRD  X1,[pDst],#8               
+        LDRD  X1,[pSrc],Count
+       
+        ;// loading 16 bytes and storing
+        STRD  X0,[pDst],#8               
+        LDRD  X0,[pSrc],#8
+        STRD  X1,[pDst],#8               
+        LDRD  X1,[pSrc],Count
+
+        ;// loading 16 bytes and storing
+        STRD  X0,[pDst],#8               
+        LDRD  X0,[pSrc],#8
+        STRD  X1,[pDst],#8               
+        LDRD  X1,[pSrc],Count
+        
+        ;// loading 16 bytes and storing
+        STRD  X0,[pDst],#8              
+        LDRD  X0,[pSrc],#8 
+        STRD  X1,[pDst],#8               
+        LDRD  X1,[pSrc],Count
+        
+        ;// loading 16 bytes and storing
+        STRD  X0,[pDst],#8               
+        LDRD  X0,[pSrc],#8 
+        STRD  X1,[pDst],#8               
+        LDRD  X1,[pSrc],Count
+
+        ;// loading 16 bytes and storing
+        STRD  X0,[pDst],#8               
+        LDRD  X0,[pSrc],#8 
+        STRD  X1,[pDst],#8               
+        LDRD  X1,[pSrc],Count
+
+        ;// loading 16 bytes and storing
+        STRD  X0,[pDst],#8               
+        LDRD  X0,[pSrc],#8 
+        STRD  X1,[pDst],#8               
+        LDRD  X1,[pSrc],Count
+
+        ;// loading 16 bytes and storing
+        STRD  X0,[pDst],#8               
+        LDRD  X0,[pSrc],#8 
+        STRD  X1,[pDst],#8               
+        LDRD  X1,[pSrc],Count
+
+        ;// loading 16 bytes and storing
+        STRD  X0,[pDst],#8               
+        LDRD  X0,[pSrc],#8 
+        STRD  X1,[pDst],#8               
+        LDRD  X1,[pSrc],Count
+
+        ;// loading 16 bytes and storing
+        STRD  X0,[pDst],#8               
+        LDRD  X0,[pSrc],#8 
+        STRD  X1,[pDst],#8               
+        LDRD  X1,[pSrc],Count
+       
+        ;// loading 16 bytes and storing
+        STRD  X0,[pDst],#8               
+        LDRD  X0,[pSrc],#8 
+        STRD  X1,[pDst],#8               
+        LDRD  X1,[pSrc],Count
+
+        STRD  X0,[pDst],#8               
+        MOV   Return,#OMX_Sts_NoErr
+        STRD  X1,[pDst],#8               
+
+       
+        M_END
+        ENDIF
+        
+        END
+       
\ No newline at end of file
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/comm/src/omxVCCOMM_Copy8x8_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/comm/src/omxVCCOMM_Copy8x8_s.s
new file mode 100644
index 0000000..993873c
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/comm/src/omxVCCOMM_Copy8x8_s.s
@@ -0,0 +1,72 @@
+ ;/**
+ ; * Function: omxVCCOMM_Copy8x8
+ ; *
+ ; * Description:
+ ; * Copies the reference 8x8 block to the current block.
+ ; * Parameters:
+ ; * [in] pSrc         - pointer to the reference block in the source frame; must be aligned on an 8-byte boundary.
+ ; * [in] step         - distance between the starts of consecutive lines in the reference frame, in bytes;
+ ; *                     must be a multiple of 8 and must be larger than or equal to 8.
+ ; * [out] pDst        - pointer to the destination block; must be aligned on an 8-byte boundary.
+ ; * Return Value:
+ ; * OMX_Sts_NoErr     - no error
+ ; * OMX_Sts_BadArgErr - bad arguments; returned under any of the following conditions:
+ ; *                   - one or more of the following pointers is NULL:  pSrc, pDst
+ ; *                   - one or more of the following pointers is not aligned on an 8-byte boundary:  pSrc, pDst
+ ; *                   - step <8 or step is not a multiple of 8.  
+ ; */
+
+   INCLUDE omxtypes_s.h
+   
+     
+     M_VARIANTS ARM1136JS
+     
+
+
+
+     IF ARM1136JS
+
+;//Input Arguments
+pSrc    RN 0        
+pDst    RN 1        
+step    RN 2
+
+;//Local Variables
+Count   RN 14
+X0      RN 2
+X1      RN 4
+Return  RN 0
+     M_START omxVCCOMM_Copy8x8,r5
+        
+        
+        
+        MOV   Count,step                 ;//Count=step 
+        
+        LDRD  X0,[pSrc],Count            ;//pSrc after loading : pSrc=pSrc+step
+        LDRD  X1,[pSrc],Count
+        
+        STRD  X0,[pDst],#8               
+        LDRD  X0,[pSrc],Count 
+        STRD  X1,[pDst],#8               
+        LDRD  X1,[pSrc],Count
+        
+        STRD  X0,[pDst],#8               
+        LDRD  X0,[pSrc],Count
+        STRD  X1,[pDst],#8               
+        LDRD  X1,[pSrc],Count
+        
+        STRD  X0,[pDst],#8              
+        LDRD  X0,[pSrc],Count
+        STRD  X1,[pDst],#8               
+        LDRD  X1,[pSrc],Count
+        
+        STRD  X0,[pDst],#8               
+        MOV   Return,#OMX_Sts_NoErr
+        STRD  X1,[pDst],#8               
+        
+        
+        M_END
+        ENDIF
+        
+        END
+        
\ No newline at end of file
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/comm/src/omxVCCOMM_ExpandFrame_I_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/comm/src/omxVCCOMM_ExpandFrame_I_s.s
new file mode 100644
index 0000000..02b4b08
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/comm/src/omxVCCOMM_ExpandFrame_I_s.s
@@ -0,0 +1,189 @@
+;//
+;// 
+;// File Name:  omxVCCOMM_ExpandFrame_I_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   9641
+;// Date:       Thursday, February 7, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+;// Description:
+;// This function will Expand Frame boundary pixels into Plane
+;// 
+;// 
+
+;// Include standard headers
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+        
+        M_VARIANTS ARM1136JS
+
+;// Import symbols required from other files
+;// (For example tables)
+    
+  
+;// Set debugging level        
+DEBUG_ON    SETL {FALSE}
+
+
+    
+
+
+
+        
+;// Guarding implementation by the processor name
+    
+    IF  ARM1136JS
+    
+;//Input Registers
+
+pSrcDstPlane    RN  0
+iFrameWidth     RN  1
+iFrameHeight    RN  2    
+iExpandPels     RN  3
+
+
+;//Output Registers
+
+result          RN  0
+
+;//Local Scratch Registers
+
+iPlaneStep      RN  4
+pTop            RN  5
+pBottom         RN  6
+pBottomIndex    RN  7
+x               RN  8
+y               RN  9
+tempTop         RN  10
+tempBot         RN  11
+ColStep         RN  12
+pLeft           RN  5
+pRight          RN  6
+pRightIndex     RN  7
+tempLeft1       RN  10
+tempRight1      RN  11
+tempLeft2       RN  14
+tempRight2      RN  2
+indexY          RN  14
+RowStep         RN  12
+expandTo4bytes  RN  1                               ;// copy a byte to 4 bytes of a word
+    
+        ;// Allocate stack memory required by the function
+        
+        
+        ;// Write function header
+        M_START omxVCCOMM_ExpandFrame_I,r11
+        
+        ;// Define stack arguments
+        M_ARG   iPlaneStepOnStack, 4
+        
+        ;// Load argument from the stack
+        M_LDR   iPlaneStep, iPlaneStepOnStack
+        
+        MUL     pTop,iExpandPels,iPlaneStep
+        MLA     pBottom,iFrameHeight,iPlaneStep,pSrcDstPlane
+        SUB     x,iFrameWidth,#4
+        MOV     indexY,pTop
+        ADD     ColStep,indexY,#4
+        SUB     pBottomIndex,pBottom,iPlaneStep
+        SUB     pTop,pSrcDstPlane,pTop
+        
+        
+        ADD     pTop,pTop,x
+        ADD     pBottom,pBottom,x
+
+        ;//------------------------------------------------------------------------
+        ;// The following improves upon the C implmentation
+        ;// The x and y loops are interchanged: This ensures that the values of
+        ;// pSrcDstPlane [x] and pSrcDstPlane [(iFrameHeight - 1) * iPlaneStep + x] 
+        ;// which depend only on loop variable 'x' are loaded once and used in 
+        ;// multiple stores in the 'Y' loop
+        ;//------------------------------------------------------------------------
+
+        ;// xloop
+ExpandFrameTopBotXloop
+        
+        LDR     tempTop,[pSrcDstPlane,x]
+        ;//------------------------------------------------------------------------
+        ;// pSrcDstPlane [(iFrameHeight - 1) * iPlaneStep + x] is simplified as:
+        ;// pSrcDstPlane + (iFrameHeight * iPlaneStep) - iPlaneStep + x ==
+        ;// pBottom - iPlaneStep + x == pBottomIndex [x]
+        ;// The value of pBottomIndex is calculated above this 'x' loop
+        ;//------------------------------------------------------------------------
+        LDR     tempBot,[pBottomIndex,x]
+        
+        ;// yloop
+        MOV     y,iExpandPels
+
+ExpandFrameTopBotYloop        
+        SUBS    y,y,#1
+        M_STR   tempTop,[pTop],iPlaneStep
+        M_STR   tempBot,[pBottom],iPlaneStep
+        BGT     ExpandFrameTopBotYloop
+        
+        SUBS    x,x,#4
+        SUB     pTop,pTop,ColStep
+        SUB     pBottom,pBottom,ColStep
+        BGE     ExpandFrameTopBotXloop
+        
+        
+        ;// y loop
+        ;// The product is already calculated above : Reuse
+        ;//MUL     indexY,iExpandPels,iPlaneStep      
+      
+        SUB     pSrcDstPlane,pSrcDstPlane,indexY
+        SUB     pLeft,pSrcDstPlane,iExpandPels                  ;// pLeft->points to the top left of the expanded block
+        ADD     pRight,pSrcDstPlane,iFrameWidth
+        SUB     pRightIndex,pRight,#1 
+        
+        ADD     y,iFrameHeight,iExpandPels,LSL #1
+        LDR     expandTo4bytes,=0x01010101
+        
+        RSB     RowStep,iExpandPels,iPlaneStep,LSL #1
+
+        ;// The Y Loop is unrolled twice
+ExpandFrameLeftRightYloop  
+        LDRB    tempLeft2,[pSrcDstPlane,iPlaneStep]             ;// PreLoad the values
+        LDRB    tempRight2,[pRightIndex,iPlaneStep]
+        M_LDRB  tempLeft1,[pSrcDstPlane],iPlaneStep,LSL #1      ;// PreLoad the values
+        M_LDRB  tempRight1,[pRightIndex],iPlaneStep,LSL #1
+              
+        SUB     x,iExpandPels,#4
+        MUL     tempLeft2,tempLeft2,expandTo4bytes              ;// Copy the single byte to 4 bytes
+        MUL     tempRight2,tempRight2,expandTo4bytes
+        MUL     tempLeft1,tempLeft1,expandTo4bytes              ;// Copy the single byte to 4 bytes
+        MUL     tempRight1,tempRight1,expandTo4bytes
+        
+        
+        ;// x loop
+ExpandFrameLeftRightXloop        
+        SUBS    x,x,#4
+        STR     tempLeft2,[pLeft,iPlaneStep]                     ;// Store the 4 bytes at one go
+        STR     tempRight2,[pRight,iPlaneStep]
+        STR     tempLeft1,[pLeft],#4                             ;// Store the 4 bytes at one go
+        STR     tempRight1,[pRight],#4
+        BGE     ExpandFrameLeftRightXloop
+        
+        SUBS    y,y,#2
+        ADD     pLeft,pLeft,RowStep
+        ADD     pRight,pRight,RowStep
+        BGT     ExpandFrameLeftRightYloop
+        
+                        
+        ;// Set return value
+          
+        MOV         result,#OMX_Sts_NoErr  
+End             
+      
+        ;// Write function tail
+        
+        M_END
+        
+    ENDIF                                                    ;//ARM1136JS        
+ 
+            
+    END
\ No newline at end of file
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/api/armVCM4P10_CAVLCTables.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/api/armVCM4P10_CAVLCTables.h
new file mode 100644
index 0000000..4340f2a
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/api/armVCM4P10_CAVLCTables.h
@@ -0,0 +1,30 @@
+/* ----------------------------------------------------------------
+ * 
+ * 
+ * File Name:  armVCM4P10_CAVLCTables.h
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * 
+ * Header file for optimized H.264 CALVC tables
+ * 
+ */
+ 
+#ifndef ARMVCM4P10_CAVLCTABLES_H
+#define ARMVCM4P10_CAVLCTABLES_H
+  
+/* CAVLC tables */
+
+extern const OMX_U16 *armVCM4P10_CAVLCCoeffTokenTables[18];
+extern const OMX_U16 *armVCM4P10_CAVLCTotalZeroTables[15];
+extern const OMX_U16 *armVCM4P10_CAVLCTotalZeros2x2Tables[3];
+extern const OMX_U16 *armVCM4P10_CAVLCRunBeforeTables[15];
+extern const OMX_U8 armVCM4P10_ZigZag_4x4[16];
+extern const OMX_U8 armVCM4P10_ZigZag_2x2[4];
+extern const OMX_S8 armVCM4P10_SuffixToLevel[7];
+
+#endif
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_Average_4x_Align_unsafe_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_Average_4x_Align_unsafe_s.s
new file mode 100644
index 0000000..b2cd9d1
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_Average_4x_Align_unsafe_s.s
@@ -0,0 +1,222 @@
+;//
+;// 
+;// File Name:  armVCM4P10_Average_4x_Align_unsafe_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   9641
+;// Date:       Thursday, February 7, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+
+;// Functions:
+;//     armVCM4P10_Average_4x4_Align<ALIGNMENT>_unsafe  
+;//
+;// Implements Average of 4x4 with equation c = (a+b+1)>>1.
+;// First operand will be at offset ALIGNMENT from aligned address
+;// Second operand will be at aligned location and will be used as output.
+;// destination pointed by (pDst) for vertical interpolation.
+;// This function needs to copy 4 bytes in horizontal direction 
+;//
+;// Registers used as input for this function
+;// r0,r1,r2,r3 where r2 containings aligned memory pointer and r3 step size
+;//
+;// Registers preserved for top level function
+;// r4,r5,r6,r8,r9,r14
+;//
+;// Registers modified by the function
+;// r7,r10,r11,r12
+;//
+;// Output registers
+;// r2 - pointer to the aligned location
+;// r3 - step size to this aligned location
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+        
+        M_VARIANTS ARM1136JS
+
+        EXPORT armVCM4P10_Average_4x4_Align0_unsafe
+        EXPORT armVCM4P10_Average_4x4_Align2_unsafe
+        EXPORT armVCM4P10_Average_4x4_Align3_unsafe
+
+DEBUG_ON    SETL {FALSE}
+
+;// Declare input registers
+pPred0          RN 0
+iPredStep0      RN 1
+pPred1          RN 2
+iPredStep1      RN 3
+pDstPred        RN 2
+iDstStep        RN 3
+
+;// Declare other intermediate registers
+iPredA0         RN 10
+iPredA1         RN 11
+iPredB0         RN 12
+iPredB1         RN 14
+Temp1           RN 4
+Temp2           RN 5
+ResultA         RN 5
+ResultB         RN 4
+r0x80808080     RN 7
+
+    IF ARM1136JS
+        
+        ;// This function calculates average of 4x4 block 
+        ;// pPred0 is at alignment offset 0 and pPred1 is alignment 4
+
+        ;// Function header
+        M_START armVCM4P10_Average_4x4_Align0_unsafe, r6
+
+        ;// Code start        
+        LDR         r0x80808080, =0x80808080
+
+        ;// 1st load
+        M_LDR       iPredB0, [pPred1]
+        M_LDR       iPredA0, [pPred0], iPredStep0        
+        M_LDR       iPredB1, [pPred1, iPredStep1]
+        M_LDR       iPredA1, [pPred0], iPredStep0
+
+        ;// (a+b+1)/2 = (a+256-(255-b))/2 = (a-(255-b))/2 + 128
+        MVN         iPredB0, iPredB0
+        MVN         iPredB1, iPredB1
+        UHSUB8      ResultA, iPredA0, iPredB0
+        UHSUB8      ResultB, iPredA1, iPredB1
+        EOR         ResultA, ResultA, r0x80808080
+        M_STR       ResultA, [pDstPred], iDstStep        
+        EOR         ResultB, ResultB, r0x80808080
+        M_STR       ResultB, [pDstPred], iDstStep        
+        
+        ;// 2nd load
+        M_LDR       iPredA0, [pPred0], iPredStep0        
+        M_LDR       iPredB0, [pPred1]
+        M_LDR       iPredA1, [pPred0], iPredStep0
+        M_LDR       iPredB1, [pPred1, iPredStep1]
+
+        MVN         iPredB0, iPredB0
+        UHSUB8      ResultA, iPredA0, iPredB0
+        MVN         iPredB1, iPredB1
+        UHSUB8      ResultB, iPredA1, iPredB1
+        EOR         ResultA, ResultA, r0x80808080        
+        M_STR       ResultA, [pDstPred], iDstStep        
+        EOR         ResultB, ResultB, r0x80808080
+        M_STR       ResultB, [pDstPred], iDstStep                
+End0
+        M_END
+
+        ;// This function calculates average of 4x4 block 
+        ;// pPred0 is at alignment offset 2 and pPred1 is alignment 4
+
+        ;// Function header
+        M_START armVCM4P10_Average_4x4_Align2_unsafe, r6
+
+        ;// Code start        
+        LDR         r0x80808080, =0x80808080
+
+        ;// 1st load
+        LDR         Temp1, [pPred0, #4]
+        M_LDR       iPredA0, [pPred0], iPredStep0        
+        M_LDR       iPredB0, [pPred1]
+        M_LDR       iPredB1, [pPred1, iPredStep1]
+        M_LDR       Temp2, [pPred0, #4]
+        M_LDR       iPredA1, [pPred0], iPredStep0
+        MVN         iPredB0, iPredB0
+        MVN         iPredB1, iPredB1        
+        MOV         iPredA0, iPredA0, LSR #16
+        ORR         iPredA0, iPredA0, Temp1, LSL #16        
+        MOV         iPredA1, iPredA1, LSR #16
+        ORR         iPredA1, iPredA1, Temp2, LSL #16
+
+        ;// (a+b+1)/2 = (a+256-(255-b))/2 = (a-(255-b))/2 + 128
+        UHSUB8      ResultA, iPredA0, iPredB0
+        UHSUB8      ResultB, iPredA1, iPredB1
+        EOR         ResultA, ResultA, r0x80808080
+        M_STR       ResultA, [pDstPred], iDstStep        
+        EOR         ResultB, ResultB, r0x80808080
+        M_STR       ResultB, [pDstPred], iDstStep        
+        
+        ;// 2nd load
+        LDR         Temp1, [pPred0, #4]
+        M_LDR         iPredA0, [pPred0], iPredStep0        
+        LDR         iPredB0, [pPred1]
+        LDR         iPredB1, [pPred1, iPredStep1]
+        LDR         Temp2, [pPred0, #4]
+        M_LDR         iPredA1, [pPred0], iPredStep0
+        MVN         iPredB0, iPredB0
+        MVN         iPredB1, iPredB1
+        MOV         iPredA0, iPredA0, LSR #16
+        ORR         iPredA0, iPredA0, Temp1, LSL #16        
+        MOV         iPredA1, iPredA1, LSR #16
+        ORR         iPredA1, iPredA1, Temp2, LSL #16
+
+        UHSUB8      ResultA, iPredA0, iPredB0
+        UHSUB8      ResultB, iPredA1, iPredB1
+        EOR         ResultA, ResultA, r0x80808080        
+        M_STR       ResultA, [pDstPred], iDstStep        
+        EOR         ResultB, ResultB, r0x80808080
+        M_STR       ResultB, [pDstPred], iDstStep                
+End2
+        M_END
+
+
+        ;// This function calculates average of 4x4 block 
+        ;// pPred0 is at alignment offset 3 and pPred1 is alignment 4
+
+        ;// Function header
+        M_START armVCM4P10_Average_4x4_Align3_unsafe, r6
+
+        ;// Code start        
+        LDR         r0x80808080, =0x80808080
+
+        ;// 1st load
+        LDR         Temp1, [pPred0, #4]
+        M_LDR       iPredA0, [pPred0], iPredStep0        
+        LDR         iPredB0, [pPred1]
+        LDR         iPredB1, [pPred1, iPredStep1]
+        LDR         Temp2, [pPred0, #4]
+        M_LDR       iPredA1, [pPred0], iPredStep0
+
+        MVN         iPredB0, iPredB0
+        MVN         iPredB1, iPredB1
+        MOV         iPredA0, iPredA0, LSR #24
+        ORR         iPredA0, iPredA0, Temp1, LSL #8                
+        MOV         iPredA1, iPredA1, LSR #24
+        ORR         iPredA1, iPredA1, Temp2, LSL #8
+        UHSUB8      ResultA, iPredA0, iPredB0
+        UHSUB8      ResultB, iPredA1, iPredB1
+        EOR         ResultA, ResultA, r0x80808080
+        M_STR       ResultA, [pDstPred], iDstStep        
+        EOR         ResultB, ResultB, r0x80808080
+        M_STR       ResultB, [pDstPred], iDstStep        
+        
+        ;// 2nd load
+        LDR         Temp1, [pPred0, #4]
+        M_LDR       iPredA0, [pPred0], iPredStep0        
+        LDR         iPredB0, [pPred1]
+        LDR         iPredB1, [pPred1, iPredStep1]
+        LDR         Temp2, [pPred0, #4]
+        M_LDR       iPredA1, [pPred0], iPredStep0
+
+        MVN         iPredB0, iPredB0
+        MVN         iPredB1, iPredB1
+        MOV         iPredA0, iPredA0, LSR #24
+        ORR         iPredA0, iPredA0, Temp1, LSL #8        
+        MOV         iPredA1, iPredA1, LSR #24
+        ORR         iPredA1, iPredA1, Temp2, LSL #8
+
+        UHSUB8      ResultA, iPredA0, iPredB0
+        UHSUB8      ResultB, iPredA1, iPredB1
+        EOR         ResultA, ResultA, r0x80808080        
+        M_STR       ResultA, [pDstPred], iDstStep        
+        EOR         ResultB, ResultB, r0x80808080
+        M_STR       ResultB, [pDstPred], iDstStep                
+End3
+        M_END
+
+    ENDIF
+    
+    END
+    
\ No newline at end of file
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_CAVLCTables.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_CAVLCTables.c
new file mode 100644
index 0000000..17fe518
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_CAVLCTables.c
@@ -0,0 +1,327 @@
+/* ----------------------------------------------------------------
+ *
+ * 
+ * File Name:  armVCM4P10_CAVLCTables.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * 
+ * Optimized CAVLC tables for H.264
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+
+#include "armVCM4P10_CAVLCTables.h"
+
+/* 4x4 DeZigZag table */
+
+const OMX_U8 armVCM4P10_ZigZag_4x4[16] =
+{
+    0, 1, 4, 8, 5, 2, 3, 6, 9, 12, 13, 10, 7, 11, 14, 15
+};
+
+/* 2x2 DeZigZag table */
+
+const OMX_U8 armVCM4P10_ZigZag_2x2[4] =
+{
+    0, 1, 2, 3
+};
+
+
+/*
+ * Suffix To Level table
+ * We increment the suffix length if 
+ * ((LevelCode>>1)+1)>(3<<(SuffixLength-1)) && SuffixLength<6
+ * (LevelCode>>1)>=(3<<(SuffixLength-1))    && SuffixLength<6
+ *  LevelCode    >= 3<<SuffixLength         && SuffixLength<6
+ * (LevelCode+2) >= (3<<SuffixLength)+2     && SuffixLength<6
+ */
+const OMX_S8 armVCM4P10_SuffixToLevel[7] =
+{
+    (3<<1)+2,       /* SuffixLength=1 */
+    (3<<1)+2,       /* SuffixLength=1 */
+    (3<<2)+2,       /* SuffixLength=2 */
+    (3<<3)+2,       /* SuffixLength=3 */
+    (3<<4)+2,       /* SuffixLength=4 */
+    (3<<5)+2,       /* SuffixLength=5 */
+    -1              /* SuffixLength=6 - never increment */
+};
+
+static const OMX_U16 armVCM4P10_CAVLCCoeffTokenTables_0[132] = {
+    0x0020, 0x0100, 0x2015, 0x2015, 0x400b, 0x400b, 0x400b, 0x400b,
+    0x6001, 0x6001, 0x6001, 0x6001, 0x6001, 0x6001, 0x6001, 0x6001,
+    0x0028, 0x00f0, 0x00f8, 0x0027, 0x0030, 0x00d8, 0x00e0, 0x00e8,
+    0x0038, 0x00a0, 0x00c8, 0x00d0, 0x0040, 0x0068, 0x0090, 0x0098,
+    0x0048, 0x0050, 0x0058, 0x0060, 0x27ff, 0x27ff, 0x206b, 0x206b,
+    0x0081, 0x0085, 0x0083, 0x0079, 0x0087, 0x007d, 0x007b, 0x0071,
+    0x007f, 0x0075, 0x0073, 0x0069, 0x0070, 0x0078, 0x0080, 0x0088,
+    0x2077, 0x2077, 0x206d, 0x206d, 0x2063, 0x2063, 0x2061, 0x2061,
+    0x206f, 0x206f, 0x2065, 0x2065, 0x205b, 0x205b, 0x2059, 0x2059,
+    0x0067, 0x005d, 0x0053, 0x0051, 0x005f, 0x0055, 0x004b, 0x0049,
+    0x00a8, 0x00b0, 0x00b8, 0x00c0, 0x2041, 0x2041, 0x204d, 0x204d,
+    0x2043, 0x2043, 0x2039, 0x2039, 0x2057, 0x2057, 0x2045, 0x2045,
+    0x203b, 0x203b, 0x2031, 0x2031, 0x204f, 0x204f, 0x203d, 0x203d,
+    0x2033, 0x2033, 0x2029, 0x2029, 0x0047, 0x0035, 0x002b, 0x0021,
+    0x203f, 0x203f, 0x202d, 0x202d, 0x2023, 0x2023, 0x2019, 0x2019,
+    0x0037, 0x0025, 0x001b, 0x0011, 0x202f, 0x202f, 0x201d, 0x201d,
+    0x0013, 0x0009, 0x201f, 0x201f
+};
+
+static const OMX_U16 armVCM4P10_CAVLCCoeffTokenTables_1[128] = {
+    0x0020, 0x00e8, 0x00f0, 0x00f8, 0x0027, 0x001f, 0x2015, 0x2015,
+    0x400b, 0x400b, 0x400b, 0x400b, 0x4001, 0x4001, 0x4001, 0x4001,
+    0x0028, 0x00d0, 0x00d8, 0x00e0, 0x0030, 0x0098, 0x00c0, 0x00c8,
+    0x0038, 0x0060, 0x0088, 0x0090, 0x0040, 0x0048, 0x0050, 0x0058,
+    0x27ff, 0x27ff, 0x207f, 0x207f, 0x0087, 0x0085, 0x0083, 0x0081,
+    0x007b, 0x0079, 0x007d, 0x0073, 0x2075, 0x2075, 0x2071, 0x2071,
+    0x0068, 0x0070, 0x0078, 0x0080, 0x2077, 0x2077, 0x206d, 0x206d,
+    0x206b, 0x206b, 0x2069, 0x2069, 0x206f, 0x206f, 0x2065, 0x2065,
+    0x2063, 0x2063, 0x2061, 0x2061, 0x0059, 0x005d, 0x005b, 0x0051,
+    0x0067, 0x0055, 0x0053, 0x0049, 0x00a0, 0x00a8, 0x00b0, 0x00b8,
+    0x205f, 0x205f, 0x204d, 0x204d, 0x204b, 0x204b, 0x2041, 0x2041,
+    0x2057, 0x2057, 0x2045, 0x2045, 0x2043, 0x2043, 0x2039, 0x2039,
+    0x204f, 0x204f, 0x203d, 0x203d, 0x203b, 0x203b, 0x2031, 0x2031,
+    0x0029, 0x0035, 0x0033, 0x0021, 0x2047, 0x2047, 0x202d, 0x202d,
+    0x202b, 0x202b, 0x2019, 0x2019, 0x003f, 0x0025, 0x0023, 0x0011,
+    0x0037, 0x001d, 0x001b, 0x0009, 0x202f, 0x202f, 0x2013, 0x2013
+};
+
+static const OMX_U16 armVCM4P10_CAVLCCoeffTokenTables_2[112] = {
+    0x0020, 0x0088, 0x00b0, 0x00b8, 0x00c0, 0x00c8, 0x00d0, 0x00d8,
+    0x003f, 0x0037, 0x002f, 0x0027, 0x001f, 0x0015, 0x000b, 0x0001,
+    0x0028, 0x0050, 0x0078, 0x0080, 0x0030, 0x0038, 0x0040, 0x0048,
+    0x07ff, 0x0081, 0x0087, 0x0085, 0x0083, 0x0079, 0x007f, 0x007d,
+    0x007b, 0x0071, 0x0077, 0x0075, 0x0073, 0x0069, 0x206b, 0x206b,
+    0x0058, 0x0060, 0x0068, 0x0070, 0x2061, 0x2061, 0x206d, 0x206d,
+    0x2063, 0x2063, 0x2059, 0x2059, 0x206f, 0x206f, 0x2065, 0x2065,
+    0x205b, 0x205b, 0x2051, 0x2051, 0x0067, 0x005d, 0x0053, 0x0049,
+    0x005f, 0x0055, 0x004b, 0x0041, 0x0090, 0x0098, 0x00a0, 0x00a8,
+    0x2039, 0x2039, 0x2031, 0x2031, 0x204d, 0x204d, 0x2029, 0x2029,
+    0x2057, 0x2057, 0x2045, 0x2045, 0x2043, 0x2043, 0x2021, 0x2021,
+    0x0019, 0x003d, 0x003b, 0x0011, 0x004f, 0x0035, 0x0033, 0x0009,
+    0x202b, 0x202b, 0x202d, 0x202d, 0x2023, 0x2023, 0x2025, 0x2025,
+    0x201b, 0x201b, 0x2047, 0x2047, 0x201d, 0x201d, 0x2013, 0x2013
+};
+
+static const OMX_U16 armVCM4P10_CAVLCCoeffTokenTables_3[80] = {
+    0x0020, 0x0028, 0x0030, 0x0038, 0x0040, 0x0048, 0x0050, 0x0058,
+    0x0060, 0x0068, 0x0070, 0x0078, 0x0080, 0x0088, 0x0090, 0x0098,
+    0x0009, 0x000b, 0x07ff, 0x0001, 0x0011, 0x0013, 0x0015, 0x07ff,
+    0x0019, 0x001b, 0x001d, 0x001f, 0x0021, 0x0023, 0x0025, 0x0027,
+    0x0029, 0x002b, 0x002d, 0x002f, 0x0031, 0x0033, 0x0035, 0x0037,
+    0x0039, 0x003b, 0x003d, 0x003f, 0x0041, 0x0043, 0x0045, 0x0047,
+    0x0049, 0x004b, 0x004d, 0x004f, 0x0051, 0x0053, 0x0055, 0x0057,
+    0x0059, 0x005b, 0x005d, 0x005f, 0x0061, 0x0063, 0x0065, 0x0067,
+    0x0069, 0x006b, 0x006d, 0x006f, 0x0071, 0x0073, 0x0075, 0x0077,
+    0x0079, 0x007b, 0x007d, 0x007f, 0x0081, 0x0083, 0x0085, 0x0087
+};
+
+static const OMX_U16 armVCM4P10_CAVLCCoeffTokenTables_4[32] = {
+    0x0020, 0x0038, 0x2015, 0x2015, 0x4001, 0x4001, 0x4001, 0x4001,
+    0x600b, 0x600b, 0x600b, 0x600b, 0x600b, 0x600b, 0x600b, 0x600b,
+    0x0028, 0x0030, 0x0021, 0x0019, 0x2027, 0x2027, 0x0025, 0x0023,
+    0x201d, 0x201d, 0x201b, 0x201b, 0x0011, 0x001f, 0x0013, 0x0009
+};
+
+const OMX_U16 * armVCM4P10_CAVLCCoeffTokenTables[18] = {
+    armVCM4P10_CAVLCCoeffTokenTables_0, /* nC=0 */
+    armVCM4P10_CAVLCCoeffTokenTables_0, /* nC=1 */
+    armVCM4P10_CAVLCCoeffTokenTables_1, /* nC=2 */
+    armVCM4P10_CAVLCCoeffTokenTables_1, /* nC=3 */
+    armVCM4P10_CAVLCCoeffTokenTables_2, /* nC=4 */
+    armVCM4P10_CAVLCCoeffTokenTables_2, /* nC=5 */
+    armVCM4P10_CAVLCCoeffTokenTables_2, /* nC=6 */
+    armVCM4P10_CAVLCCoeffTokenTables_2, /* nC=7 */
+    armVCM4P10_CAVLCCoeffTokenTables_3, /* nC=8 */
+    armVCM4P10_CAVLCCoeffTokenTables_3, /* nC=9 */
+    armVCM4P10_CAVLCCoeffTokenTables_3, /* nC=10 */
+    armVCM4P10_CAVLCCoeffTokenTables_3, /* nC=11 */
+    armVCM4P10_CAVLCCoeffTokenTables_3, /* nC=12 */
+    armVCM4P10_CAVLCCoeffTokenTables_3, /* nC=13 */
+    armVCM4P10_CAVLCCoeffTokenTables_3, /* nC=14 */
+    armVCM4P10_CAVLCCoeffTokenTables_3, /* nC=15 */
+    armVCM4P10_CAVLCCoeffTokenTables_3, /* nC=16 */
+    armVCM4P10_CAVLCCoeffTokenTables_4  /* nC=-1 */
+};
+
+static const OMX_U16 armVCM4P10_CAVLCTotalZeroTables_0[40] = {
+    0x0020, 0x0048, 0x0009, 0x0007, 0x2005, 0x2005, 0x2003, 0x2003,
+    0x6001, 0x6001, 0x6001, 0x6001, 0x6001, 0x6001, 0x6001, 0x6001,
+    0x0028, 0x0040, 0x0011, 0x000f, 0x0030, 0x0038, 0x0019, 0x0017,
+    0x27ff, 0x27ff, 0x201f, 0x201f, 0x201d, 0x201d, 0x201b, 0x201b,
+    0x2015, 0x2015, 0x2013, 0x2013, 0x200d, 0x200d, 0x200b, 0x200b
+};
+
+static const OMX_U16 armVCM4P10_CAVLCTotalZeroTables_1[24] = {
+    0x0020, 0x0028, 0x0011, 0x000f, 0x000d, 0x000b, 0x2009, 0x2009,
+    0x2007, 0x2007, 0x2005, 0x2005, 0x2003, 0x2003, 0x2001, 0x2001,
+    0x001d, 0x001b, 0x0019, 0x0017, 0x2015, 0x2015, 0x2013, 0x2013
+};
+
+static const OMX_U16 armVCM4P10_CAVLCTotalZeroTables_2[24] = {
+    0x0020, 0x0028, 0x0011, 0x000b, 0x0009, 0x0001, 0x200f, 0x200f,
+    0x200d, 0x200d, 0x2007, 0x2007, 0x2005, 0x2005, 0x2003, 0x2003,
+    0x001b, 0x0017, 0x2019, 0x2019, 0x2015, 0x2015, 0x2013, 0x2013
+};
+
+static const OMX_U16 armVCM4P10_CAVLCTotalZeroTables_3[24] = {
+    0x0020, 0x0028, 0x0013, 0x000f, 0x0007, 0x0005, 0x2011, 0x2011,
+    0x200d, 0x200d, 0x200b, 0x200b, 0x2009, 0x2009, 0x2003, 0x2003,
+    0x2019, 0x2019, 0x2017, 0x2017, 0x2015, 0x2015, 0x2001, 0x2001
+};
+
+static const OMX_U16 armVCM4P10_CAVLCTotalZeroTables_4[20] = {
+    0x0020, 0x0015, 0x0011, 0x0005, 0x0003, 0x0001, 0x200f, 0x200f,
+    0x200d, 0x200d, 0x200b, 0x200b, 0x2009, 0x2009, 0x2007, 0x2007,
+    0x2017, 0x2017, 0x2013, 0x2013
+};
+
+static const OMX_U16 armVCM4P10_CAVLCTotalZeroTables_5[20] = {
+    0x0020, 0x0011, 0x2013, 0x2013, 0x200f, 0x200f, 0x200d, 0x200d,
+    0x200b, 0x200b, 0x2009, 0x2009, 0x2007, 0x2007, 0x2005, 0x2005,
+    0x0015, 0x0001, 0x2003, 0x2003
+};
+
+static const OMX_U16 armVCM4P10_CAVLCTotalZeroTables_6[20] = {
+    0x0020, 0x000f, 0x2011, 0x2011, 0x200d, 0x200d, 0x2009, 0x2009,
+    0x2007, 0x2007, 0x2005, 0x2005, 0x400b, 0x400b, 0x400b, 0x400b,
+    0x0013, 0x0001, 0x2003, 0x2003
+};
+
+static const OMX_U16 armVCM4P10_CAVLCTotalZeroTables_7[20] = {
+    0x0020, 0x0003, 0x200f, 0x200f, 0x200d, 0x200d, 0x2007, 0x2007,
+    0x400b, 0x400b, 0x400b, 0x400b, 0x4009, 0x4009, 0x4009, 0x4009,
+    0x0011, 0x0001, 0x2005, 0x2005
+};
+
+static const OMX_U16 armVCM4P10_CAVLCTotalZeroTables_8[20] = {
+    0x0020, 0x0005, 0x200b, 0x200b, 0x400d, 0x400d, 0x400d, 0x400d,
+    0x4009, 0x4009, 0x4009, 0x4009, 0x4007, 0x4007, 0x4007, 0x4007,
+    0x0003, 0x0001, 0x200f, 0x200f
+};
+
+static const OMX_U16 armVCM4P10_CAVLCTotalZeroTables_9[20] = {
+    0x0020, 0x000d, 0x2005, 0x2005, 0x400b, 0x400b, 0x400b, 0x400b,
+    0x4009, 0x4009, 0x4009, 0x4009, 0x4007, 0x4007, 0x4007, 0x4007,
+    0x2003, 0x2003, 0x2001, 0x2001
+};
+
+static const OMX_U16 armVCM4P10_CAVLCTotalZeroTables_10[16] = {
+    0x0001, 0x0003, 0x2005, 0x2005, 0x2007, 0x2007, 0x200b, 0x200b,
+    0x6009, 0x6009, 0x6009, 0x6009, 0x6009, 0x6009, 0x6009, 0x6009
+};
+
+static const OMX_U16 armVCM4P10_CAVLCTotalZeroTables_11[16] = {
+    0x0001, 0x0003, 0x2009, 0x2009, 0x4005, 0x4005, 0x4005, 0x4005,
+    0x6007, 0x6007, 0x6007, 0x6007, 0x6007, 0x6007, 0x6007, 0x6007
+};
+
+static const OMX_U16 armVCM4P10_CAVLCTotalZeroTables_12[16] = {
+    0x2001, 0x2001, 0x2003, 0x2003, 0x4007, 0x4007, 0x4007, 0x4007,
+    0x6005, 0x6005, 0x6005, 0x6005, 0x6005, 0x6005, 0x6005, 0x6005
+};
+
+static const OMX_U16 armVCM4P10_CAVLCTotalZeroTables_13[16] = {
+    0x4001, 0x4001, 0x4001, 0x4001, 0x4003, 0x4003, 0x4003, 0x4003,
+    0x6005, 0x6005, 0x6005, 0x6005, 0x6005, 0x6005, 0x6005, 0x6005
+};
+
+static const OMX_U16 armVCM4P10_CAVLCTotalZeroTables_14[16] = {
+    0x6001, 0x6001, 0x6001, 0x6001, 0x6001, 0x6001, 0x6001, 0x6001,
+    0x6003, 0x6003, 0x6003, 0x6003, 0x6003, 0x6003, 0x6003, 0x6003
+};
+
+const OMX_U16 * armVCM4P10_CAVLCTotalZeroTables[15] = {
+    armVCM4P10_CAVLCTotalZeroTables_0,
+    armVCM4P10_CAVLCTotalZeroTables_1,
+    armVCM4P10_CAVLCTotalZeroTables_2,
+    armVCM4P10_CAVLCTotalZeroTables_3,
+    armVCM4P10_CAVLCTotalZeroTables_4,
+    armVCM4P10_CAVLCTotalZeroTables_5,
+    armVCM4P10_CAVLCTotalZeroTables_6,
+    armVCM4P10_CAVLCTotalZeroTables_7,
+    armVCM4P10_CAVLCTotalZeroTables_8,
+    armVCM4P10_CAVLCTotalZeroTables_9,
+    armVCM4P10_CAVLCTotalZeroTables_10,
+    armVCM4P10_CAVLCTotalZeroTables_11,
+    armVCM4P10_CAVLCTotalZeroTables_12,
+    armVCM4P10_CAVLCTotalZeroTables_13,
+    armVCM4P10_CAVLCTotalZeroTables_14
+};
+
+static const OMX_U16 armVCM4P10_CAVLCTotalZeros2x2Tables_0[16] = {
+    0x2007, 0x2007, 0x2005, 0x2005, 0x4003, 0x4003, 0x4003, 0x4003,
+    0x6001, 0x6001, 0x6001, 0x6001, 0x6001, 0x6001, 0x6001, 0x6001
+};
+
+static const OMX_U16 armVCM4P10_CAVLCTotalZeros2x2Tables_1[16] = {
+    0x4005, 0x4005, 0x4005, 0x4005, 0x4003, 0x4003, 0x4003, 0x4003,
+    0x6001, 0x6001, 0x6001, 0x6001, 0x6001, 0x6001, 0x6001, 0x6001
+};
+
+static const OMX_U16 armVCM4P10_CAVLCTotalZeros2x2Tables_2[16] = {
+    0x6003, 0x6003, 0x6003, 0x6003, 0x6003, 0x6003, 0x6003, 0x6003,
+    0x6001, 0x6001, 0x6001, 0x6001, 0x6001, 0x6001, 0x6001, 0x6001
+};
+
+const OMX_U16 * armVCM4P10_CAVLCTotalZeros2x2Tables[3] = {
+    armVCM4P10_CAVLCTotalZeros2x2Tables_0,
+    armVCM4P10_CAVLCTotalZeros2x2Tables_1,
+    armVCM4P10_CAVLCTotalZeros2x2Tables_2
+};
+
+static const OMX_U16 armVCM4P10_CAVLCRunBeforeTables_0[8] = {
+    0x4003, 0x4003, 0x4003, 0x4003, 0x4001, 0x4001, 0x4001, 0x4001
+};
+
+static const OMX_U16 armVCM4P10_CAVLCRunBeforeTables_1[8] = {
+    0x2005, 0x2005, 0x2003, 0x2003, 0x4001, 0x4001, 0x4001, 0x4001
+};
+
+static const OMX_U16 armVCM4P10_CAVLCRunBeforeTables_2[8] = {
+    0x2007, 0x2007, 0x2005, 0x2005, 0x2003, 0x2003, 0x2001, 0x2001
+};
+
+static const OMX_U16 armVCM4P10_CAVLCRunBeforeTables_3[8] = {
+    0x0009, 0x0007, 0x2005, 0x2005, 0x2003, 0x2003, 0x2001, 0x2001
+};
+
+static const OMX_U16 armVCM4P10_CAVLCRunBeforeTables_4[8] = {
+    0x000b, 0x0009, 0x0007, 0x0005, 0x2003, 0x2003, 0x2001, 0x2001
+};
+
+static const OMX_U16 armVCM4P10_CAVLCRunBeforeTables_5[8] = {
+    0x0003, 0x0005, 0x0009, 0x0007, 0x000d, 0x000b, 0x2001, 0x2001
+};
+
+static const OMX_U16 armVCM4P10_CAVLCRunBeforeTables_6[24] = {
+    0x0010, 0x000d, 0x000b, 0x0009, 0x0007, 0x0005, 0x0003, 0x0001,
+    0x0018, 0x0011, 0x200f, 0x200f, 0x0020, 0x0015, 0x2013, 0x2013,
+    0x0028, 0x0019, 0x2017, 0x2017, 0x07ff, 0x001d, 0x201b, 0x201b
+};
+
+/* Tables 7 to 14 are duplicates of table 6 */
+
+const OMX_U16 * armVCM4P10_CAVLCRunBeforeTables[15] = {
+    armVCM4P10_CAVLCRunBeforeTables_0,  /* ZerosLeft=1 */
+    armVCM4P10_CAVLCRunBeforeTables_1,
+    armVCM4P10_CAVLCRunBeforeTables_2,
+    armVCM4P10_CAVLCRunBeforeTables_3,
+    armVCM4P10_CAVLCRunBeforeTables_4,
+    armVCM4P10_CAVLCRunBeforeTables_5,  /* ZerosLeft=6 */
+    armVCM4P10_CAVLCRunBeforeTables_6,  /* ZerosLeft=7 */
+    armVCM4P10_CAVLCRunBeforeTables_6,  /* ZerosLeft=8 */
+    armVCM4P10_CAVLCRunBeforeTables_6,  /* ZerosLeft=9 */
+    armVCM4P10_CAVLCRunBeforeTables_6,  /* ZerosLeft=10 */
+    armVCM4P10_CAVLCRunBeforeTables_6,  /* ZerosLeft=11 */
+    armVCM4P10_CAVLCRunBeforeTables_6,  /* ZerosLeft=12 */
+    armVCM4P10_CAVLCRunBeforeTables_6,  /* ZerosLeft=13 */
+    armVCM4P10_CAVLCRunBeforeTables_6,  /* ZerosLeft=14 */
+    armVCM4P10_CAVLCRunBeforeTables_6   /* ZerosLeft=15 */
+};
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_DeblockingChroma_unsafe_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_DeblockingChroma_unsafe_s.s
new file mode 100644
index 0000000..dcbcd00
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_DeblockingChroma_unsafe_s.s
@@ -0,0 +1,20 @@
+;//
+;// 
+;// File Name:  armVCM4P10_DeblockingChroma_unsafe_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   9641
+;// Date:       Thursday, February 7, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+        
+        M_VARIANTS ARM1136JS
+
+
+
+        END
\ No newline at end of file
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_DeblockingLuma_unsafe_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_DeblockingLuma_unsafe_s.s
new file mode 100644
index 0000000..14b37fe
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_DeblockingLuma_unsafe_s.s
@@ -0,0 +1,366 @@
+;//
+;// 
+;// File Name:  armVCM4P10_DeblockingLuma_unsafe_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   9641
+;// Date:       Thursday, February 7, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+        
+        M_VARIANTS ARM1136JS
+
+
+
+    IF  ARM1136JS
+
+MASK_1  EQU 0x01010101
+
+;// Declare input registers
+
+pQ0        RN 0
+StepArg    RN 1
+tC0Arg     RN 2
+alpha      RN 6
+
+beta       RN 14
+bS         RN 14
+tC0        RN 14
+ptC0       RN 1
+
+;// Declare Local/Temporary variables
+
+;// Pixels
+p_0     RN 3 
+p_1     RN 5  
+p_2     RN 4  
+p_3     RN 2  
+q_0     RN 8  
+q_1     RN 9  
+q_2     RN 10 
+q_3     RN 12 
+
+
+;// Filtering
+
+ap0q0   RN 1  
+filt    RN 2
+        
+m00     RN 7
+m01     RN 11
+
+apflg   RN 0 
+aqflg   RN 6
+
+tC      RN 1
+
+
+;//Declarations for bSLT4 kernel
+
+pos     RN 7
+neg     RN 12
+
+P0a     RN 1   
+P1a     RN 8   
+Q0a     RN 7  
+Q1a     RN 4   
+
+u1      RN 3   
+max     RN 12
+min     RN 2   
+               
+                
+                
+;//Declarations for bSGE4 kernel
+
+q_3b    RN 9   
+p_3b    RN 0
+apqflg  RN 12
+
+P0b     RN 6
+P1b     RN 7 
+P2b     RN 1
+
+Q0b     RN 9 
+Q1b     RN 0 
+Q2b     RN 2
+
+;// Miscellanous
+
+a       RN 0
+t0      RN 3 
+t1      RN 12
+t2      RN 7
+t3      RN 11
+t4      RN 4   
+t5      RN 1   
+t8      RN 6   
+t9      RN 14  
+t10     RN 5   
+t11     RN 9   
+
+;// Register usage for - armVCM4P10_DeblockingLumabSLT4_unsafe()
+;//
+;// Inputs - 3,4,5,8,9,10 - Input Pixels (p0-p2,q0-q2)
+;//        - 2 - filt, 0 - apflg, 6 - aqflg
+;//        - 11 - m01, 7 - tC0
+;//         
+;// Outputs - 1,8,7,11 - Output Pixels(P0a,P1a,Q0a,Q1a)
+;//
+;// Registers Corrupted - 0-3,5-12,14
+
+
+        M_START armVCM4P10_DeblockingLumabSLT4_unsafe, lr
+
+        ;// Since beta <= 18 and alpha <= 255 we know
+        ;// -254 <= p0-q0 <= 254
+        ;//  -17 <= q1-q0 <= 17
+        ;//  -17 <= p1-p0 <= 17
+
+        ;// delta = Clip3( -tC, tC, ((((q0-p0)<<2) + (p1-q1) + 4)>>3))
+        ;// 
+        ;//    Calculate A = (((q0-p0)<<2) + (p1-q1) + 4)>>3
+        ;//                = (4*q0 - 4*p0 + p1 - q1 + 4)>>3
+        ;//                = ((p1-p0) - (q1-q0) - 3*(p0-q0) + 4)>>3
+        
+        USUB8   t1, p_1, p_0
+        MUL     tC0, t2, m01
+        
+        USUB8   t2, q_1, q_0
+        SSUB8   t1, t1, t2
+
+        USUB8   t2, p_0, q_0
+        AND     t2, t2, m01
+        SHSUB8  t1, t1, t2
+        UHSUB8  t5, p_0, q_0
+        SSUB8   t1, t1, t2
+        SHSUB8  t1, t1, t5
+        MOV     m00, #0
+        SADD8   t1, t1, m01
+        SHSUB8  t1, t1, t5
+        
+        ;// tC = tC0
+        ;// if (ap < beta) tC++;
+        ;// if (aq < beta) tC++;
+        USUB8   t5, filt, m01   
+        SEL     tC0, tC0, m00
+        UQADD8  tC, tC0, apflg
+        SSUB8   t1, t1, m00
+        UQADD8  tC, tC, aqflg
+
+        ;// Split into positive and negative part and clip 
+        SEL     pos, t1, m00
+        USUB8   neg, pos, t1
+        USUB8   t3, pos, tC
+        SEL     pos, tC, pos
+        USUB8   t3, neg, tC
+        SEL     neg, tC, neg
+        
+        ;//Reload m01
+        LDR     m01,=MASK_1
+
+        UQADD8  P0a, p_0, pos
+        UQSUB8  Q0a, q_0, pos
+        UQSUB8  P0a, P0a, neg
+        UQADD8  Q0a, Q0a, neg
+        
+        ;// Choose to store the filtered
+        ;// value or the original pixel
+        USUB8   t1, filt, m01    
+        SEL     P0a, P0a, p_0
+        SEL     Q0a, Q0a, q_0
+    
+        ;// delta = (p2 + ((p0+q0+1)>>1) - (p1<<1))>>1;
+        ;// u1 = (p0 + q0 + 1)>>1
+        ;// u1 = ( (q_0 - p_0')>>1 ) ^ 0x80
+        MVN     p_0, p_0
+        UHSUB8  u1, q_0, p_0 
+        UQADD8  max, p_1, tC0
+        EOR     u1, u1, m01 ,LSL #7
+    
+        ;// Calculate A = (p2+u1)>>1 
+        ;// Then delta = Clip3( -tC0, tC0, A - p1)
+
+        ;// Clip P1
+        UHADD8  P1a, p_2, u1
+        UQSUB8  min, p_1, tC0
+        USUB8   t4, P1a, max
+        SEL     P1a, max, P1a
+        USUB8   t4, P1a, min
+        SEL     P1a, P1a, min
+
+        ;// Clip Q1
+        UHADD8  Q1a, q_2, u1
+        UQADD8  max, q_1, tC0
+        UQSUB8  min, q_1, tC0
+        USUB8   t0, Q1a, max
+        SEL     Q1a, max, Q1a
+        USUB8   t0, Q1a, min
+        SEL     Q1a, Q1a, min
+        
+        ;// Choose to store the filtered
+        ;// value or the original pixel
+        USUB8   t0, apflg, m01
+        SEL     P1a, P1a, p_1
+        USUB8   t0, aqflg, m01
+        SEL     t3, Q1a, q_1
+        
+        M_END
+
+;// Register usage for - armVCM4P10_DeblockingLumabSGE4_unsafe()
+;//
+;// Inputs - 3,4,5,8,9,10 - Input Pixels (p0-p2,q0-q2)
+;//        - 2 - filt, 0 - apflg,aqflg
+;//        - 1 - ap0q0, 6 - alpha
+;//        - 7 - m00, 11 - m01
+;//         
+;// Outputs - 6,7,1,9,0,2 - Output Pixels(P0b,P1b,P2b, Q0b,Q1b,Q2b)
+;// 
+;// Registers Corrupted - 0-3,5-12,14
+
+        M_START armVCM4P10_DeblockingLumabSGE4_unsafe, lr
+    
+        ;// apflg = apflg && |p0-q0|<((alpha>>2)+2) 
+        ;// apflg = aqflg && |p0-q0|<((alpha>>2)+2) 
+
+        M_ARG   pDummy,4
+        M_ARG   pQ_3,4
+        M_ARG   pP_3,4
+        
+        UHADD8  alpha, alpha, m00
+        USUB8   t9, p_2, p_0    ;//t9 = dp2p0
+        UHADD8  alpha, alpha, m00
+        ADD     alpha, alpha, m01, LSL #1        
+        USUB8   ap0q0, ap0q0, alpha
+        SEL     apqflg, m00, apflg
+
+        ;// P0 = (p2 + 2*p1 + 2*p0 + 2*q0 + q1 + 4)>>3 
+        ;//    = ((p2-p0) + 2*(p1-p0) + (q1-q0) + 3*(q0-p0) + 8*p0 + 4)>>3
+        ;//    = p0 + (((p2-p0) + 2*(p1-p0) + (q1-q0) - 3*(p0-q0) + 4)>>3)
+
+        ;// P1 = (p2 + p1 + q0 + p0 + 2)>>2
+        ;//    = p0 + (((p2-p0) + (p1-p0) - (p0-q0) + 2)>>2)
+        
+        ;// P2 = (2*p3 + 3*p2 + p1 + p0 + q0 + 4)>>3
+        ;//    = (2*(p3-p0) + 3*(p2-p0) + (p1-p0) - (p0-q0) + 8*p0 + 4)>>3
+        ;//    = p0 + (((p3-p0) + (p2-p0) + t2 + 2)>>2)
+
+        ;// Compute P0b
+        USUB8   t2, p_0, q_0         
+        SSUB8   t5, t9, t2           
+
+        USUB8   t8, q_1, q_0         
+        SHADD8  t8, t5, t8
+
+        USUB8   t9, p_1, p_0         
+        SADD8   t8, t8, t9
+        SHSUB8  t8, t8, t2
+        SHADD8  t5, t5, t9
+        SHADD8  t8, t8, m01
+        SHADD8  t9, t5, m01
+        SADD8   P0b, p_0, t8         
+        ;// P0b ready
+        
+        ;// Compute P1b
+        M_LDR   p_3b, pP_3
+        SADD8   P1b, p_0, t9         
+        ;// P1b ready
+        
+        ;// Compute P2b
+        USUB8   t9, p_2, p_0         
+        SADD8   t5, t5, t9
+        UHSUB8  t9, p_3b, p_0        
+        EOR     a, p_3b, p_0         
+        AND     a, a, m01
+        SHADD8  t5, t5, a
+        UHADD8  a, p_0, q_1
+        SADD8   t5, t5, m01
+        SHADD8  t5, t5, t9
+        MVN     t9, p_1
+        SADD8   P2b, p_0, t5         
+        ;// P2b ready
+        
+        UHSUB8  a, a, t9
+        ORR     t9, apqflg, m01
+        USUB8   t9, apqflg, t9
+
+        EOR     a, a, m01, LSL #7
+        SEL     P0b, P0b, a
+        SEL     P1b, P1b, p_1
+        SEL     P2b, P2b, p_2
+
+        USUB8   t4, filt, m01
+        SEL     P0b, P0b, p_0
+
+        
+        ;// Q0 = (q2 + 2*q1 + 2*q0 + 2*p0 + p1 + 4)>>3 
+        ;//    = ((q2-q0) + 2*(q1-q0) + (p1-p0) + 3*(p0-q0) + 8*q0 + 4)>>3
+        ;//    = q0 + (((q2-q0) + 2*(q1-q0) + (p1-p0) + 3*(p0-q0) + 4)>>3)
+
+        ;// Q1 = (q2 + q1 + p0 + q0 + 2)>>2
+        ;//    = q0 + (((q2-q0) + (q1-q0) + (p0-q0) + 2)>>2)
+
+        ;// Q2 = (2*q3 + 3*q2 + q1 + q0 + p0 + 4)>>3
+        ;//    = (2*(q3-q0) + 3*(q2-q0) + (q1-q0) + (p0-q0) + 8*q0 + 4)>>3
+        ;//    = q0 + (((q3-q0) + (q2-q0) + t2 + 2)>>2)
+
+
+        ;// Compute Q0b Q1b
+        USUB8   t4, q_2, q_0           
+        USUB8   a, p_0, q_0
+        USUB8   t9, p_1, p_0
+        SADD8   t0, t4, a
+        SHADD8  t9, t0, t9
+        UHADD8  t10, q_0, p_1
+        SADD8   t9, t9, a
+        USUB8   a, q_1, q_0
+        SHADD8  t9, t9, a
+        SHADD8  t0, t0, a
+        SHADD8  t9, t9, m01
+        SHADD8  a, t0, m01
+        SADD8   t9, q_0, t9            
+        ;// Q0b ready - t9
+        
+        MOV     t4, #0
+        UHADD8  apqflg, apqflg, t4
+        
+        SADD8   Q1b, q_0, a 
+        ;// Q1b ready
+       
+        USUB8   t4, apqflg, m01
+        SEL     Q1b, Q1b, q_1
+        MVN     t11, q_1
+        UHSUB8  t10, t10, t11
+        M_LDR   q_3b, pQ_3
+        EOR     t10, t10, m01, LSL #7
+        SEL     t9, t9, t10            
+        
+        ;// Compute Q2b
+        USUB8   t4, q_2, q_0
+        SADD8   t4, t0, t4
+        EOR     t0, q_3b, q_0 
+        AND     t0, t0, m01
+        SHADD8  t4, t4, t0
+        UHSUB8  t10, q_3b, q_0
+        SADD8   t4, t4, m01
+        SHADD8  t4, t4, t10
+
+        USUB8   t10, filt, m01
+        SEL     Q0b, t9, q_0
+
+        SADD8   t4, q_0, t4            
+        ;// Q2b ready - t4
+
+        USUB8   t10, apqflg, m01
+        SEL     Q2b, t4, q_2
+
+        M_END
+    
+    ENDIF
+
+        END
\ No newline at end of file
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_DecodeCoeffsToPair_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_DecodeCoeffsToPair_s.s
new file mode 100644
index 0000000..ac448a0
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_DecodeCoeffsToPair_s.s
@@ -0,0 +1,325 @@
+;//
+;// 
+;// File Name:  armVCM4P10_DecodeCoeffsToPair_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   9641
+;// Date:       Thursday, February 7, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+        INCLUDE armCOMM_BitDec_s.h
+        
+        IMPORT armVCM4P10_CAVLCCoeffTokenTables
+        IMPORT armVCM4P10_CAVLCTotalZeroTables
+        IMPORT armVCM4P10_CAVLCTotalZeros2x2Tables
+        IMPORT armVCM4P10_CAVLCRunBeforeTables
+        IMPORT armVCM4P10_SuffixToLevel
+        IMPORT armVCM4P10_ZigZag_4x4
+        IMPORT armVCM4P10_ZigZag_2x2
+        
+        M_VARIANTS ARM1136JS
+        
+;//DEBUG_ON    SETL {TRUE}
+        
+LAST_COEFF               EQU 0x20        ;// End of block flag
+TWO_BYTE_COEFF           EQU 0x10
+
+;// Declare input registers
+
+ppBitStream     RN 0
+pOffset         RN 1
+pNumCoeff       RN 2
+ppPosCoefbuf    RN 3
+nC              RN 4 ;// number of coeffs or 17 for chroma
+sMaxNumCoeff    RN 5
+
+;// Declare inner loop registers
+
+;// Level loop
+Count           RN 0
+TrailingOnes    RN 1
+pLevel          RN 2
+LevelSuffix     RN 3
+SuffixLength    RN 4
+TotalCoeff      RN 5
+
+pVLDTable       RN 6
+Symbol          RN 7
+T1              RN 8
+T2              RN 9
+RBitStream      RN 10
+RBitBuffer      RN 11
+RBitCount       RN 12
+lr              RN 14
+
+;// Run loop
+Count           RN 0
+ZerosLeft       RN 1
+pLevel          RN 2
+ppRunTable      RN 3
+pRun            RN 4
+TotalCoeff      RN 5
+
+pVLDTable       RN 6
+Symbol          RN 7
+T1              RN 8
+T2              RN 9
+RBitStream      RN 10
+RBitBuffer      RN 11
+RBitCount       RN 12
+lr              RN 14
+
+;// Fill in coefficients loop
+pPosCoefbuf     RN 0
+temp            RN 1
+pLevel          RN 2
+ppPosCoefbuf    RN 3
+pRun            RN 4
+TotalCoeff      RN 5
+pZigZag         RN 6
+
+T1              RN 8
+T2              RN 9
+RBitStream      RN 10
+RBitBuffer      RN 11
+RBitCount       RN 12
+CoeffNum        RN 14
+
+
+
+    IF ARM1136JS
+        
+        ;// Allocate stack memory required by the function
+        M_ALLOC4 pppBitStream, 4
+        M_ALLOC4 ppOffset, 4
+        M_ALLOC4 pppPosCoefbuf, 4
+        M_ALLOC4 ppLevel, 16*2
+        M_ALLOC4 ppRun, 16
+        
+        ;// Write function header
+        M_START armVCM4P10_DecodeCoeffsToPair, r11
+        
+        ;// Define stack arguments
+        M_ARG   pNC, 4
+        M_ARG   pSMaxNumCoeff,4
+        
+        ;// Code start        
+        M_BD_INIT0 ppBitStream, pOffset, RBitStream, RBitBuffer, RBitCount
+        LDR        pVLDTable, =armVCM4P10_CAVLCCoeffTokenTables
+        M_LDR      nC, pNC
+        
+        M_BD_INIT1 T1, T2, lr
+        LDR     pVLDTable, [pVLDTable, nC, LSL #2]  ;// Find VLD table    
+        
+        M_BD_INIT2 T1, T2, lr
+
+        ;// Decode Symbol = TotalCoeff*4 + TrailingOnes
+        M_BD_VLD  Symbol, T1, T2, pVLDTable, 4, 2
+    
+        MOVS    TotalCoeff, Symbol, LSR #2    
+        STRB    TotalCoeff, [pNumCoeff]    
+        M_PRINTF "TotalCoeff=%d\n", TotalCoeff
+        BEQ.W   EndNoError                  ;// Finished if no coefficients
+
+        CMP     Symbol, #17*4
+        BGE.W   EndBadSymbol                ;// Error if bad symbol
+        
+        ;// Save bitstream pointers
+        M_STR   ppBitStream,  pppBitStream
+        M_STR   pOffset,      ppOffset
+        M_STR   ppPosCoefbuf, pppPosCoefbuf                
+        
+        ;// Decode Trailing Ones
+        ANDS    TrailingOnes, Symbol, #3
+        M_ADR   pLevel, ppLevel            
+        M_PRINTF "TrailingOnes=%d\n", TrailingOnes
+        BEQ     TrailingOnesDone    
+        MOV     Count, TrailingOnes
+TrailingOnesLoop    
+        M_BD_READ8 Symbol, 1, T1
+        SUBS    Count, Count, #1
+        MOV     T1, #1
+        SUB     T1, T1, Symbol, LSL #1
+        M_PRINTF "Level=%d\n", T1
+        STRH    T1, [pLevel], #2
+        BGT     TrailingOnesLoop
+TrailingOnesDone    
+    
+        ;// Decode level values    
+        SUBS    Count, TotalCoeff, TrailingOnes     ;// Number of levels to read
+        BEQ     DecodeRuns                          ;// None left
+        
+        MOV     SuffixLength, #1
+        CMP     TotalCoeff, #10
+        MOVLE   SuffixLength, #0
+        CMP     TrailingOnes, #3    ;// if (TrailingOnes<3)
+        MOVLT   TrailingOnes, #4    ;// then TrailingOnes = +4
+        MOVGE   TrailingOnes, #2    ;// else TrailingOnes = +2
+        MOVGE   SuffixLength, #0    ;//      SuffixLength = 0
+        
+LevelLoop
+        M_BD_CLZ16 Symbol, T1, T2   ;// Symbol=LevelPrefix
+        CMP     Symbol,#16
+        BGE     EndBadSymbol
+        
+        MOVS    lr, SuffixLength    ;// if LevelSuffixSize==0
+        TEQEQ   Symbol, #14         ;//   and  LevelPrefix==14
+        MOVEQ   lr, #4              ;//   then LevelSuffixSize=4
+        TEQ     Symbol, #15         ;// if LevelSuffixSize==15
+        MOVEQ   lr, #12             ;//   then LevelSuffixSize=12
+        
+        TEQEQ   SuffixLength,#0
+        ADDEQ   Symbol,Symbol,#15
+        
+        TEQ     lr, #0              ;// if LevelSuffixSize==0
+        BEQ     LevelCodeRead       ;// LevelCode = LevelPrefix
+        
+        M_BD_VREAD16 LevelSuffix, lr, T1, T2  ;// Read Level Suffix
+        
+        MOV     Symbol, Symbol, LSL SuffixLength
+        ADD     Symbol, LevelSuffix, Symbol
+             
+LevelCodeRead        
+        ;// Symbol = LevelCode
+        ADD     Symbol, Symbol, TrailingOnes ;// +4 if level cannot be +/-1, +2 o/w
+        MOV     TrailingOnes, #2
+        MOVS    T1, Symbol, LSR #1
+        RSBCS   T1, T1, #0                  ;// If Symbol odd then negate
+        M_PRINTF "Level=%d\n", T1
+        STRH    T1, [pLevel], #2            ;// Store level.
+        
+        LDR     T2, =armVCM4P10_SuffixToLevel
+        LDRSB   T1, [T2, SuffixLength]      ;// Find increment level        
+        TEQ     SuffixLength, #0
+        MOVEQ   SuffixLength, #1
+        CMP     Symbol, T1
+        ADDCS   SuffixLength, SuffixLength, #1        
+        SUBS    Count, Count, #1        
+        BGT     LevelLoop
+        
+DecodeRuns        
+        ;// Find number of zeros
+        M_LDR   T1, pSMaxNumCoeff           ;// sMaxNumCoeff
+        SUB     Count, TotalCoeff, #1       ;// Number of runs excluding last
+        SUBS    ZerosLeft, T1, TotalCoeff   ;// Maximum number of zeros there could be
+        M_ADR   pRun, ppRun
+        MOV     CoeffNum,TotalCoeff
+        SUB     CoeffNum,CoeffNum,#1
+        BEQ     NoZerosLeft
+        
+        ;// Unpack number of zeros from bitstream
+        TEQ     T1, #4        
+        LDREQ   pVLDTable, =(armVCM4P10_CAVLCTotalZeros2x2Tables-4)
+        LDRNE   pVLDTable, =(armVCM4P10_CAVLCTotalZeroTables-4)
+        LDR     pVLDTable, [pVLDTable, TotalCoeff, LSL #2]
+        
+        M_BD_VLD  Symbol, T1, T2, pVLDTable, 4, 2 ;// Symbol = ZerosLeft
+        CMP     Symbol,#16
+        BGE     EndBadSymbol
+
+        LDR     ppRunTable, =(armVCM4P10_CAVLCRunBeforeTables-4)
+        M_ADR   pRun, ppRun
+        MOVS    ZerosLeft, Symbol
+
+        ADD     CoeffNum,CoeffNum,ZerosLeft        
+
+        BEQ     NoZerosLeft
+        
+        ;// Decode runs while zeros are left and more than one coefficient
+RunLoop 
+        SUBS    Count, Count, #1
+        LDR     pVLDTable, [ppRunTable, ZerosLeft, LSL#2]
+        BLT     LastRun
+        M_BD_VLD  Symbol, T1, T2, pVLDTable, 3, 2 ;// Symbol = Run
+        CMP     Symbol,#15         
+        BGE     EndBadSymbol        
+
+        SUBS    ZerosLeft, ZerosLeft, Symbol
+        M_PRINTF "Run=%d\n", Symbol
+        STRB    Symbol, [pRun], #1
+        BGT     RunLoop
+        
+        ;// Decode runs while no zeros are left
+NoZerosLeft 
+        SUBS    Count, Count, #1
+        M_PRINTF "Run=%d\n", ZerosLeft
+        STRGEB  ZerosLeft, [pRun], #1
+        BGT     NoZerosLeft
+
+LastRun        
+        ;// Final run length is remaining zeros
+        M_PRINTF "LastRun=%d\n", ZerosLeft
+        STRB    ZerosLeft, [pRun], #1        
+        
+        ;// Write coefficients to output array
+        M_LDR   T1, pSMaxNumCoeff                    ;// sMaxNumCoeff
+        TEQ     T1, #15
+        ADDEQ   CoeffNum,CoeffNum,#1
+        
+
+        SUB     pRun,pRun,TotalCoeff
+        SUB     pLevel,pLevel,TotalCoeff  
+        SUB     pLevel,pLevel,TotalCoeff   
+
+        M_LDR   ppPosCoefbuf, pppPosCoefbuf
+        LDR     pPosCoefbuf, [ppPosCoefbuf]
+        TEQ     T1, #4
+        LDREQ   pZigZag, =armVCM4P10_ZigZag_2x2
+        LDRNE   pZigZag, =armVCM4P10_ZigZag_4x4
+
+        
+        
+OutputLoop
+        
+        LDRB    T2, [pRun],#1
+        LDRB    T1, [pZigZag, CoeffNum]
+        SUB     CoeffNum, CoeffNum, #1      ;// Skip Non zero
+        SUB     CoeffNum, CoeffNum, T2      ;// Skip Zero run
+        
+        LDRSH   T2, [pLevel],#2
+        
+        SUBS    TotalCoeff, TotalCoeff, #1       
+        ORREQ   T1, T1, #LAST_COEFF
+        
+        ADD     temp, T2, #128
+        CMP     temp, #256
+        ORRCS   T1, T1, #TWO_BYTE_COEFF
+
+        
+        TEQ     TotalCoeff, #0              ;// Preserves carry        
+        
+        M_PRINTF "Output=%02x %04x\n", T1, T2
+        STRB    T1, [pPosCoefbuf], #1
+        STRB    T2, [pPosCoefbuf], #1
+        MOV     T2, T2, LSR #8
+        STRCSB  T2, [pPosCoefbuf], #1                
+        BNE     OutputLoop
+        
+        ;// Finished
+        STR     pPosCoefbuf, [ppPosCoefbuf]
+        M_LDR   ppBitStream, pppBitStream
+        M_LDR   pOffset, ppOffset
+        B       EndNoError
+            
+EndBadSymbol
+        MOV     r0, #OMX_Sts_Err
+        B       End    
+        
+EndNoError
+        ;// Finished reading from the bitstream                
+        M_BD_FINI ppBitStream, pOffset
+        
+        ;// Set return value
+        MOV     r0, #OMX_Sts_NoErr    
+End
+        M_END
+    
+    ENDIF
+    
+    END
+    
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_DequantTables_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_DequantTables_s.s
new file mode 100644
index 0000000..b16f188
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_DequantTables_s.s
@@ -0,0 +1,123 @@
+;//
+;// 
+;// File Name:  armVCM4P10_DequantTables_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   9641
+;// Date:       Thursday, February 7, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+        
+
+         INCLUDE omxtypes_s.h
+         INCLUDE armCOMM_s.h
+     
+         EXPORT armVCM4P10_QPDivTable
+         EXPORT armVCM4P10_VMatrixQPModTable
+         EXPORT armVCM4P10_PosToVCol4x4
+         EXPORT armVCM4P10_PosToVCol2x2
+         EXPORT armVCM4P10_VMatrix 
+         EXPORT armVCM4P10_QPModuloTable
+         EXPORT armVCM4P10_VMatrixU16
+         
+;// Define the processor variants supported by this file
+         
+         M_VARIANTS ARM1136JS
+           
+         
+;// Guarding implementation by the processor name
+
+    
+    IF ARM1136JS :LOR: CortexA8
+           
+ 
+         M_TABLE armVCM4P10_PosToVCol4x4
+         DCB  0, 2, 0, 2
+         DCB  2, 1, 2, 1
+         DCB  0, 2, 0, 2
+         DCB  2, 1, 2, 1
+
+
+         M_TABLE armVCM4P10_PosToVCol2x2
+         DCB  0, 2
+         DCB  2, 1
+
+
+         M_TABLE armVCM4P10_VMatrix
+         DCB  10, 16, 13
+         DCB  11, 18, 14
+         DCB  13, 20, 16
+         DCB  14, 23, 18
+         DCB  16, 25, 20
+         DCB  18, 29, 23
+
+;//-------------------------------------------------------
+;// This table evaluates the expression [(INT)(QP/6)],
+;// for values of QP from 0 to 51 (inclusive). 
+;//-------------------------------------------------------
+
+         M_TABLE armVCM4P10_QPDivTable
+         DCB  0,  0,  0,  0,  0,  0
+         DCB  1,  1,  1,  1,  1,  1
+         DCB  2,  2,  2,  2,  2,  2
+         DCB  3,  3,  3,  3,  3,  3
+         DCB  4,  4,  4,  4,  4,  4
+         DCB  5,  5,  5,  5,  5,  5
+         DCB  6,  6,  6,  6,  6,  6
+         DCB  7,  7,  7,  7,  7,  7
+         DCB  8,  8,  8,  8,  8,  8
+    
+;//----------------------------------------------------
+;// This table contains armVCM4P10_VMatrix[QP%6][0] entires,
+;// for values of QP from 0 to 51 (inclusive). 
+;//----------------------------------------------------
+
+         M_TABLE armVCM4P10_VMatrixQPModTable
+         DCB 10, 11, 13, 14, 16, 18
+         DCB 10, 11, 13, 14, 16, 18
+         DCB 10, 11, 13, 14, 16, 18
+         DCB 10, 11, 13, 14, 16, 18
+         DCB 10, 11, 13, 14, 16, 18
+         DCB 10, 11, 13, 14, 16, 18
+         DCB 10, 11, 13, 14, 16, 18
+         DCB 10, 11, 13, 14, 16, 18
+         DCB 10, 11, 13, 14, 16, 18
+    
+;//-------------------------------------------------------
+;// This table evaluates the modulus expression [QP%6]*6,
+;// for values of QP from 0 to 51 (inclusive). 
+;//-------------------------------------------------------
+
+         M_TABLE armVCM4P10_QPModuloTable
+         DCB 0, 6, 12, 18, 24, 30
+         DCB 0, 6, 12, 18, 24, 30
+         DCB 0, 6, 12, 18, 24, 30
+         DCB 0, 6, 12, 18, 24, 30
+         DCB 0, 6, 12, 18, 24, 30
+         DCB 0, 6, 12, 18, 24, 30
+         DCB 0, 6, 12, 18, 24, 30
+         DCB 0, 6, 12, 18, 24, 30
+         DCB 0, 6, 12, 18, 24, 30
+        
+;//-------------------------------------------------------
+;// This table contains the invidual byte values stored as
+;// halfwords. This avoids unpacking inside the function
+;//-------------------------------------------------------
+        
+         M_TABLE armVCM4P10_VMatrixU16
+         DCW 10, 16, 13 
+         DCW 11, 18, 14
+         DCW 13, 20, 16
+         DCW 14, 23, 18
+         DCW 16, 25, 20
+         DCW 18, 29, 23 
+         
+    ENDIF                                                           ;//ARM1136JS            
+
+
+                           
+    
+         END
\ No newline at end of file
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_InterpolateLuma_Align_unsafe_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_InterpolateLuma_Align_unsafe_s.s
new file mode 100644
index 0000000..82b9542
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_InterpolateLuma_Align_unsafe_s.s
@@ -0,0 +1,236 @@
+;//
+;// 
+;// File Name:  armVCM4P10_InterpolateLuma_Align_unsafe_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   9641
+;// Date:       Thursday, February 7, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+        
+        M_VARIANTS ARM1136JS
+
+        EXPORT armVCM4P10_InterpolateLuma_HorAlign9x_unsafe
+        EXPORT armVCM4P10_InterpolateLuma_VerAlign4x_unsafe
+
+DEBUG_ON    SETL {FALSE}
+
+    IF ARM1136JS 
+
+;// Declare input registers
+pSrc            RN 0
+srcStep         RN 1
+pDst            RN 8
+iHeight         RN 9
+
+;// Declare inner loop registers
+x               RN 7
+x0              RN 7
+x1              RN 10
+x2              RN 11
+Scratch         RN 12
+
+;// Function: 
+;//     armVCM4P10_InterpolateLuma_HorAlign9x_unsafe
+;//
+;// Implements copy from an arbitrary aligned source memory location (pSrc) to a 4 byte aligned
+;// destination pointed by (pDst) for horizontal interpolation.
+;// This function needs to copy 9 bytes in horizontal direction. 
+;//
+;// Registers used as input for this function
+;// r0,r1,r8,r9 where r8 containings aligned memory pointer and r9 no rows to copy
+;//
+;// Registers preserved for top level function
+;// r2,r3,r4,r5,r6
+;//
+;// Registers modified by the function
+;// r7,r8,r9,r10,r11,r12
+;//
+;// Output registers
+;// r0 - pointer to the new aligned location which will be used as pSrc
+;// r1 - step size to this aligned location
+
+        ;// Function header
+        M_START armVCM4P10_InterpolateLuma_HorAlign9x_unsafe     
+        
+        ;// Copy pDst to scratch
+        MOV     Scratch, pDst
+
+StartAlignedStackCopy
+        AND     x, pSrc, #3
+        BIC     pSrc, pSrc, #3
+        
+        M_SWITCH x
+        M_CASE   Copy0toAligned
+        M_CASE   Copy1toAligned
+        M_CASE   Copy2toAligned
+        M_CASE   Copy3toAligned
+        M_ENDSWITCH
+
+Copy0toAligned  
+        LDM     pSrc, {x0, x1, x2}
+        SUBS    iHeight, iHeight, #1
+        ADD     pSrc, pSrc, srcStep
+        
+        ;// One cycle stall
+
+        STM     pDst!, {x0, x1, x2}                     ;// Store aligned output row
+        BGT     Copy0toAligned
+        B       CopyEnd  
+      
+Copy1toAligned        
+        LDM     pSrc, {x0, x1, x2}
+        SUBS    iHeight, iHeight, #1
+        ADD     pSrc, pSrc, srcStep
+        
+        ;// One cycle stall
+
+        MOV     x0, x0, LSR #8
+        ORR     x0, x0, x1, LSL #24
+        MOV     x1, x1, LSR #8
+        ORR     x1, x1, x2, LSL #24
+        MOV     x2, x2, LSR #8
+        STM     pDst!, {x0, x1, x2}                     ;// Store aligned output row
+        BGT     Copy1toAligned
+        B       CopyEnd  
+
+Copy2toAligned        
+        LDM     pSrc, {x0, x1, x2}
+        SUBS    iHeight, iHeight, #1
+        ADD     pSrc, pSrc, srcStep
+        
+        ;// One cycle stall
+
+        MOV     x0, x0, LSR #16
+        ORR     x0, x0, x1, LSL #16
+        MOV     x1, x1, LSR #16
+        ORR     x1, x1, x2, LSL #16
+        MOV     x2, x2, LSR #16
+        STM     pDst!, {x0, x1, x2}                     ;// Store aligned output row
+        BGT     Copy2toAligned
+        B       CopyEnd  
+
+Copy3toAligned        
+        LDM     pSrc, {x0, x1, x2}
+        SUBS    iHeight, iHeight, #1
+        ADD     pSrc, pSrc, srcStep
+        
+        ;// One cycle stall
+
+        MOV     x0, x0, LSR #24
+        ORR     x0, x0, x1, LSL #8
+        MOV     x1, x1, LSR #24
+        ORR     x1, x1, x2, LSL #8
+        MOV     x2, x2, LSR #24
+        STM     pDst!, {x0, x1, x2}                     ;// Store aligned output row
+        BGT     Copy3toAligned
+
+CopyEnd  
+        
+        MOV     pSrc, Scratch
+        MOV     srcStep, #12
+
+        M_END
+    
+
+;// Function:
+;//     armVCM4P10_InterpolateLuma_VerAlign4x_unsafe
+;//
+;// Implements copy from an arbitrary aligned source memory location (pSrc) to an aligned
+;// destination pointed by (pDst) for vertical interpolation.
+;// This function needs to copy 4 bytes in horizontal direction 
+;//
+;// Registers used as input for this function
+;// r0,r1,r8,r9 where r8 containings aligned memory pointer and r9 no of rows to copy
+;//
+;// Registers preserved for top level function
+;// r2,r3,r4,r5,r6
+;//
+;// Registers modified by the function
+;// r7,r8,r9,r10,r11,r12
+;//
+;// Output registers
+;// r0 - pointer to the new aligned location which will be used as pSrc
+;// r1 - step size to this aligned location
+
+        ;// Function header
+        M_START armVCM4P10_InterpolateLuma_VerAlign4x_unsafe     
+        
+        ;// Copy pSrc to stack
+StartVAlignedStackCopy
+        AND     x, pSrc, #3
+        BIC     pSrc, pSrc, #3                        
+        
+        
+        M_SWITCH x
+        M_CASE   Copy0toVAligned
+        M_CASE   Copy1toVAligned
+        M_CASE   Copy2toVAligned
+        M_CASE   Copy3toVAligned
+        M_ENDSWITCH
+        
+Copy0toVAligned  
+        M_LDR   x0, [pSrc], srcStep
+        SUBS    iHeight, iHeight, #1
+        
+        ;// One cycle stall
+
+        STR     x0, [pDst], #4                              ;// Store aligned output row
+        BGT     Copy0toVAligned
+        B       CopyVEnd  
+      
+Copy1toVAligned        
+        LDR     x1, [pSrc, #4]
+        M_LDR   x0, [pSrc], srcStep
+        SUBS    iHeight, iHeight, #1        
+        
+        ;// One cycle stall
+
+        MOV     x1, x1, LSL #24
+        ORR     x0, x1, x0, LSR #8
+        STR     x0, [pDst], #4                              ;// Store aligned output row
+        BGT     Copy1toVAligned
+        B       CopyVEnd  
+
+Copy2toVAligned        
+        LDR     x1, [pSrc, #4]
+        M_LDR   x0, [pSrc], srcStep
+        SUBS    iHeight, iHeight, #1        
+        
+        ;// One cycle stall
+
+        MOV     x1, x1, LSL #16
+        ORR     x0, x1, x0, LSR #16
+        STR     x0, [pDst], #4                              ;// Store aligned output row
+        BGT     Copy2toVAligned
+        B       CopyVEnd  
+
+Copy3toVAligned        
+        LDR     x1, [pSrc, #4]
+        M_LDR   x0, [pSrc], srcStep
+        SUBS    iHeight, iHeight, #1        
+        
+        ;// One cycle stall
+
+        MOV     x1, x1, LSL #8
+        ORR     x0, x1, x0, LSR #24
+        STR     x0, [pDst], #4                              ;// Store aligned output row
+        BGT     Copy3toVAligned
+
+CopyVEnd  
+
+        SUB     pSrc, pDst, #28
+        MOV     srcStep, #4
+
+        M_END
+
+
+    ENDIF
+
+    END
+    
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_InterpolateLuma_Copy_unsafe_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_InterpolateLuma_Copy_unsafe_s.s
new file mode 100644
index 0000000..bc0b6ec
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_InterpolateLuma_Copy_unsafe_s.s
@@ -0,0 +1,149 @@
+;//
+;// 
+;// File Name:  armVCM4P10_InterpolateLuma_Copy_unsafe_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   9641
+;// Date:       Thursday, February 7, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+;// Function:
+;//     armVCM4P10_InterpolateLuma_Copy4x4_unsafe 
+;//
+;// Implements copy from an arbitrary aligned source memory location (pSrc) to an aligned
+;// destination pointed by (pDst)
+;//
+;// Registers preserved for top level function
+;// r1,r3,r4,r5,r6,r7,r10,r11,r14
+;//
+;// Registers modified by the function
+;// r0,r2,r8,r9,r12
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+        
+        M_VARIANTS ARM1136JS
+
+        EXPORT armVCM4P10_InterpolateLuma_Copy4x4_unsafe
+        
+;// Declare input registers
+pSrc            RN 0
+srcStep         RN 1
+pDst            RN 2
+dstStep         RN 3
+
+;// Declare other intermediate registers
+x0              RN 4
+x1              RN 5
+x2              RN 8
+x3              RN 9
+Temp            RN 12
+
+    IF ARM1136JS
+
+        M_START armVCM4P10_InterpolateLuma_Copy4x4_unsafe, r6
+
+Copy4x4Start
+        ;// Do Copy and branch to EndOfInterpolation
+        AND     Temp, pSrc, #3
+        BIC     pSrc, pSrc, #3                        
+
+        M_SWITCH Temp
+        M_CASE  Copy4x4Align0
+        M_CASE  Copy4x4Align1
+        M_CASE  Copy4x4Align2
+        M_CASE  Copy4x4Align3
+        M_ENDSWITCH
+
+Copy4x4Align0
+        M_LDR   x0, [pSrc], srcStep
+        M_LDR   x1, [pSrc], srcStep
+        M_STR   x0, [pDst], dstStep
+        M_LDR   x2, [pSrc], srcStep
+        M_STR   x1, [pDst], dstStep
+        M_LDR   x3, [pSrc], srcStep
+        M_STR   x2, [pDst], dstStep
+        M_STR   x3, [pDst], dstStep
+        B       Copy4x4End  
+
+Copy4x4Align1
+        LDR     x1, [pSrc, #4]
+        M_LDR   x0, [pSrc], srcStep
+        LDR     x3, [pSrc, #4]
+        M_LDR   x2, [pSrc], srcStep
+        MOV     x0, x0, LSR #8
+        ORR     x0, x0, x1, LSL #24
+        M_STR   x0, [pDst], dstStep
+        MOV     x2, x2, LSR #8
+        ORR     x2, x2, x3, LSL #24
+        LDR     x1, [pSrc, #4]
+        M_LDR   x0, [pSrc], srcStep
+        M_STR   x2, [pDst], dstStep
+        LDR     x3, [pSrc, #4]
+        M_LDR   x2, [pSrc], srcStep
+        MOV     x0, x0, LSR #8
+        ORR     x0, x0, x1, LSL #24
+        M_STR   x0, [pDst], dstStep
+        MOV     x2, x2, LSR #8
+        ORR     x2, x2, x3, LSL #24
+        M_STR   x2, [pDst], dstStep
+        B       Copy4x4End  
+      
+Copy4x4Align2
+        LDR     x1, [pSrc, #4]
+        M_LDR   x0, [pSrc], srcStep
+        LDR     x3, [pSrc, #4]
+        M_LDR   x2, [pSrc], srcStep
+        MOV     x0, x0, LSR #16
+        ORR     x0, x0, x1, LSL #16
+        M_STR   x0, [pDst], dstStep
+        MOV     x2, x2, LSR #16
+        ORR     x2, x2, x3, LSL #16
+        M_STR   x2, [pDst], dstStep        
+
+        LDR     x1, [pSrc, #4]
+        M_LDR   x0, [pSrc], srcStep
+        LDR     x3, [pSrc, #4]
+        M_LDR   x2, [pSrc], srcStep
+        MOV     x0, x0, LSR #16
+        ORR     x0, x0, x1, LSL #16
+        M_STR   x0, [pDst], dstStep
+        MOV     x2, x2, LSR #16
+        ORR     x2, x2, x3, LSL #16
+        M_STR   x2, [pDst], dstStep        
+        B       Copy4x4End  
+
+Copy4x4Align3 
+        LDR     x1, [pSrc, #4]
+        M_LDR   x0, [pSrc], srcStep
+        LDR     x3, [pSrc, #4]
+        M_LDR   x2, [pSrc], srcStep
+        MOV     x0, x0, LSR #24
+        ORR     x0, x0, x1, LSL #8
+        M_STR   x0, [pDst], dstStep
+        MOV     x2, x2, LSR #24
+        ORR     x2, x2, x3, LSL #8
+        M_STR   x2, [pDst], dstStep
+
+        LDR     x1, [pSrc, #4]
+        M_LDR   x0, [pSrc], srcStep
+        LDR     x3, [pSrc, #4]
+        M_LDR   x2, [pSrc], srcStep
+        MOV     x0, x0, LSR #24
+        ORR     x0, x0, x1, LSL #8
+        M_STR   x0, [pDst], dstStep
+        MOV     x2, x2, LSR #24
+        ORR     x2, x2, x3, LSL #8
+        M_STR   x2, [pDst], dstStep
+        B       Copy4x4End  
+
+Copy4x4End
+        M_END
+
+    ENDIF
+
+    END
+    
\ No newline at end of file
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_InterpolateLuma_DiagCopy_unsafe_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_InterpolateLuma_DiagCopy_unsafe_s.s
new file mode 100644
index 0000000..66cfe5e
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_InterpolateLuma_DiagCopy_unsafe_s.s
@@ -0,0 +1,178 @@
+;//
+;// 
+;// File Name:  armVCM4P10_InterpolateLuma_DiagCopy_unsafe_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   9641
+;// Date:       Thursday, February 7, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+        
+        M_VARIANTS ARM1136JS
+
+        EXPORT armVCM4P10_InterpolateLuma_HorDiagCopy_unsafe
+        EXPORT armVCM4P10_InterpolateLuma_VerDiagCopy_unsafe
+
+;// Functions: 
+;//     armVCM4P10_InterpolateLuma_HorDiagCopy_unsafe and
+;//     armVCM4P10_InterpolateLuma_VerDiagCopy_unsafe 
+;//
+;// Implements re-arrangement of data from temporary buffer to a buffer pointed by pBuf.
+;// This will do the convertion of data from 16 bit to 8 bit and it also
+;// remove offset and check for saturation.
+;//
+;// Registers used as input for this function
+;// r0,r1,r7 where r0 is input pointer and r2 its step size, r7 is output pointer
+;//
+;// Registers preserved for top level function
+;// r4,r5,r6,r8,r9,r14
+;//
+;// Registers modified by the function
+;// r7,r10,r11,r12
+;//
+;// Output registers
+;// r0 - pointer to the destination location
+;// r1 - step size to this destination location
+
+
+DEBUG_ON    SETL {FALSE}
+        
+MASK            EQU 0x80808080  ;// Mask is used to implement (a+b+1)/2
+
+;// Declare input registers
+
+pSrc0           RN 0
+srcStep0        RN 1
+
+;// Declare other intermediate registers
+Temp1           RN 4
+Temp2           RN 5
+Temp3           RN 10
+Temp4           RN 11
+pBuf            RN 7
+r0x0fe00fe0     RN 6
+r0x00ff00ff     RN 12
+Count           RN 14
+ValueA0         RN 10
+ValueA1         RN 11
+
+    IF ARM1136JS
+
+
+        ;// Function header
+        M_START armVCM4P10_InterpolateLuma_HorDiagCopy_unsafe, r6
+
+        ;// Code start     
+        MOV         Count, #4   
+        LDR         r0x0fe00fe0, =0x0fe00fe0
+        LDR         r0x00ff00ff, =0x00ff00ff        
+LoopStart1
+        LDR         Temp4, [pSrc0, #12]
+        LDR         Temp3, [pSrc0, #8]        
+        LDR         Temp2, [pSrc0, #4]
+        M_LDR       Temp1, [pSrc0], srcStep0              
+        UQSUB16     Temp4, Temp4, r0x0fe00fe0        
+        UQSUB16     Temp3, Temp3, r0x0fe00fe0                 
+        UQSUB16     Temp2, Temp2, r0x0fe00fe0        
+        UQSUB16     Temp1, Temp1, r0x0fe00fe0                 
+        USAT16      Temp4, #13, Temp4
+        USAT16      Temp3, #13, Temp3                          
+        USAT16      Temp2, #13, Temp2
+        USAT16      Temp1, #13, Temp1                                  
+        AND         Temp4, r0x00ff00ff, Temp4, LSR #5         
+        AND         Temp3, r0x00ff00ff, Temp3, LSR #5         
+        AND         Temp2, r0x00ff00ff, Temp2, LSR #5         
+        AND         Temp1, r0x00ff00ff, Temp1, LSR #5         
+        ORR         ValueA1, Temp3, Temp4, LSL #8             
+        ORR         ValueA0, Temp1, Temp2, LSL #8             
+        SUBS        Count, Count, #1                   
+        STRD        ValueA0, [pBuf], #8 
+        BGT         LoopStart1
+End1
+        SUB        pSrc0, pBuf, #32
+        MOV        srcStep0, #8
+
+        M_END
+
+
+        ;// Function header
+        M_START armVCM4P10_InterpolateLuma_VerDiagCopy_unsafe, r6
+        
+        ;// Code start        
+        LDR         r0x0fe00fe0, =0x0fe00fe0
+        LDR         r0x00ff00ff, =0x00ff00ff
+        MOV         Count, #2
+
+LoopStart    
+        LDR         Temp4, [pSrc0, #12]
+        LDR         Temp3, [pSrc0, #8]        
+        LDR         Temp2, [pSrc0, #4]
+        M_LDR       Temp1, [pSrc0], srcStep0
+        
+        UQSUB16     Temp4, Temp4, r0x0fe00fe0        
+        UQSUB16     Temp3, Temp3, r0x0fe00fe0                 
+        UQSUB16     Temp2, Temp2, r0x0fe00fe0        
+        UQSUB16     Temp1, Temp1, r0x0fe00fe0                 
+        
+        USAT16      Temp4, #13, Temp4
+        USAT16      Temp3, #13, Temp3                          
+        USAT16      Temp2, #13, Temp2
+        USAT16      Temp1, #13, Temp1
+                                  
+        AND         Temp4, r0x00ff00ff, Temp4, LSR #5         
+        AND         Temp3, r0x00ff00ff, Temp3, LSR #5         
+        AND         Temp2, r0x00ff00ff, Temp2, LSR #5         
+        AND         Temp1, r0x00ff00ff, Temp1, LSR #5         
+        ORR         ValueA1, Temp3, Temp4, LSL #8        ;// [d2 c2 d0 c0]             
+        ORR         ValueA0, Temp1, Temp2, LSL #8        ;// [b2 a2 b0 a0]         
+                    
+        PKHBT       Temp1, ValueA0, ValueA1, LSL #16     ;// [d0 c0 b0 a0]
+
+        STR         Temp1, [pBuf], #8 
+        PKHTB       Temp2, ValueA1, ValueA0, ASR #16     ;// [d2 c2 b2 a2]
+        STR         Temp2, [pBuf], #-4  
+
+        LDR         Temp4, [pSrc0, #12]
+        LDR         Temp3, [pSrc0, #8]        
+        LDR         Temp2, [pSrc0, #4]
+        M_LDR       Temp1, [pSrc0], srcStep0
+        
+        UQSUB16     Temp4, Temp4, r0x0fe00fe0        
+        UQSUB16     Temp3, Temp3, r0x0fe00fe0                 
+        UQSUB16     Temp2, Temp2, r0x0fe00fe0        
+        UQSUB16     Temp1, Temp1, r0x0fe00fe0                 
+        
+        USAT16      Temp4, #13, Temp4
+        USAT16      Temp3, #13, Temp3                          
+        USAT16      Temp2, #13, Temp2
+        USAT16      Temp1, #13, Temp1
+                                  
+        AND         Temp4, r0x00ff00ff, Temp4, LSR #5         
+        AND         Temp3, r0x00ff00ff, Temp3, LSR #5         
+        AND         Temp2, r0x00ff00ff, Temp2, LSR #5         
+        AND         Temp1, r0x00ff00ff, Temp1, LSR #5         
+        ORR         ValueA1, Temp3, Temp4, LSL #8        ;// [d2 c2 d0 c0]             
+        ORR         ValueA0, Temp1, Temp2, LSL #8        ;// [b2 a2 b0 a0]         
+                    
+        PKHBT       Temp1, ValueA0, ValueA1, LSL #16     ;// [d0 c0 b0 a0]
+        SUBS        Count, Count, #1
+        STR         Temp1, [pBuf], #8 
+        PKHTB       Temp2, ValueA1, ValueA0, ASR #16     ;// [d2 c2 b2 a2]
+        STR         Temp2, [pBuf], #4  
+        
+        BGT         LoopStart
+End2
+        SUB         pSrc0, pBuf, #32-8
+        MOV         srcStep0, #4
+
+        M_END
+
+    ENDIF
+    
+    END
+    
\ No newline at end of file
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_InterpolateLuma_HalfDiagHorVer4x4_unsafe_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_InterpolateLuma_HalfDiagHorVer4x4_unsafe_s.s
new file mode 100644
index 0000000..851ff6a
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_InterpolateLuma_HalfDiagHorVer4x4_unsafe_s.s
@@ -0,0 +1,296 @@
+;//
+;// 
+;// File Name:  armVCM4P10_InterpolateLuma_HalfDiagHorVer4x4_unsafe_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   9641
+;// Date:       Thursday, February 7, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+        
+        EXPORT armVCM4P10_InterpolateLuma_HalfDiagHorVer4x4_unsafe
+
+        M_VARIANTS ARM1136JS
+
+
+
+    IF ARM1136JS 
+
+
+        M_ALLOC8 ppDstArgs, 8
+        M_ALLOC8 pTempResult1, 8
+        M_ALLOC8 pTempResult2, 8
+        M_ALLOC4 ppSrc, 4
+        M_ALLOC4 ppDst, 4
+        M_ALLOC4 pDstStep, 4
+        M_ALLOC4 pSrcStep, 4
+        M_ALLOC4 pCounter, 4
+
+        ;// Function header
+        ;// Function: 
+        ;//     armVCM4P10_InterpolateLuma_HalfDiagHorVer4x4_unsafe
+        ;//
+        ;// Implements diagonal interpolation for a block of size 4x4. Input and output should 
+        ;// be aligned. 
+        ;//
+        ;// Registers used as input for this function
+        ;// r0,r1,r2,r3, r8 where r0,r2  input pointer and r1,r3 step size, r8 intermediate-buf pointer
+        ;//
+        ;// Registers preserved for top level function
+        ;// r0,r1,r2,r3,r4,r5,r6,r14
+        ;//
+        ;// Registers modified by the function
+        ;// r7,r8,r9,r10,r11,r12
+        ;//
+        ;// Output registers
+        ;// None. Function will preserve r0-r3
+
+        M_START armVCM4P10_InterpolateLuma_HalfDiagHorVer4x4_unsafe, r6
+        
+;// Declare input registers
+pSrc            RN 0
+srcStep         RN 1
+pDst            RN 2
+dstStep         RN 3
+
+;// Declare inner loop registers
+Acc0            RN 4
+Acc1            RN 5
+Acc2            RN 6
+Acc3            RN 7
+
+ValA            RN 4
+ValB            RN 5
+ValC            RN 6
+ValD            RN 7
+ValE            RN 8
+ValF            RN 9
+ValG            RN 12
+ValH            RN 14
+ValI            RN 1
+
+Temp1           RN 3
+Temp2           RN 1
+Temp3           RN 12
+Temp4           RN 7
+Temp5           RN 5
+r0x0fe00fe0     RN 3                                    ;// [0 (16*255 - 16) 0 (16*255 - 16)]
+r0x00ff00ff     RN 10                                   ;// [0 255 0 255] where 255 is offset
+Counter         RN 11
+pInterBuf       RN 8
+
+ValCA           RN 8
+ValDB           RN 9
+ValGE           RN 10
+ValHF           RN 11
+r0x00140001     RN 12
+r0x0014fffb     RN 14
+
+r0x0001fc00     RN 11
+
+Accx            RN 8
+Accy            RN 9
+Temp6           RN 14
+
+        M_STRD      pDst, dstStep, ppDstArgs
+
+        MOV         pDst, pInterBuf                
+        MOV         dstStep, #16
+
+        ;// Set up counter of format, [0]  [0]  [1 (height)]  [8 (width)]                                                                                    
+        MOV         Counter, #4
+        M_STR       dstStep, pDstStep        
+        M_STR       srcStep, pSrcStep        
+        LDR         r0x00ff00ff, =0x00ff00ff               ;// [0 255 0 255] 255 is offset to avoid negative results 
+
+HeightLoop
+NextTwoRowsLoop
+        LDR     ValD, [pSrc, srcStep]                   ;// Load row 1 [d1 c1 b1 a1]
+        LDR     ValA, [pSrc], #4                        ;// Load row 0 [d0 c0 b0 a0]
+        LDR     ValH, [pSrc, srcStep]                   ;// Load  [h1 g1 f1 e1]        
+        LDR     ValE, [pSrc], #4                        ;// Load  [h0 g0 f0 e0]
+        LDRB    Temp2, [pSrc, srcStep]                  ;// Load row 1 [l1 k1 j1 i1]
+        LDRB    Temp1, [pSrc], #-8                      ;// Load row 0 [l0 k0 j0 i0]
+        
+        PKHBT   ValB, ValA, ValD, LSL #16               ;// [b1 a1 b0 a0]
+        PKHTB   ValD, ValD, ValA, ASR #16               ;// [d1 c1 d0 c0]
+        UXTAB16 ValA, r0x00ff00ff, ValB                 ;// [00 a1 00 a0] + [0 255 0 255]
+        UXTAB16 ValC, r0x00ff00ff, ValD                 ;// [00 c1 00 c0] + [0 255 0 255]
+        PKHBT   ValI, Temp1, Temp2, LSL #16             ;// [00 i1 00 i0]            
+        PKHBT   ValF, ValE, ValH, LSL #16               ;// [f1 e1 f0 e0]
+        PKHTB   ValH, ValH, ValE, ASR #16               ;// [h1 g1 h0 g0]
+        UXTAB16 ValE, r0x00ff00ff, ValF                 ;// [00 e1 00 e0] + [0 255 0 255]
+
+        ;// Calculate Acc0
+        ;// Acc0 = a - 5*b + 20*c + 20*d - 5*e + f
+        UXTAB16 Temp1, ValC, ValD, ROR #8
+        UXTAB16 Temp3, ValE, ValB, ROR #8
+        RSB     Temp1, Temp3, Temp1, LSL #2                
+        UXTAB16 Acc0, ValA, ValF, ROR #8
+        ADD     Temp1, Temp1, Temp1, LSL #2        
+        ADD     Acc0, Acc0, Temp1       
+
+        ;// Calculate Acc1
+        ;// Acc1 = b - 5*c + 20*d + 20*e - 5*f + g
+        UXTAB16 Temp1, ValE, ValD, ROR #8
+        UXTAB16 Temp3, ValC, ValF, ROR #8
+        RSB     Temp1, Temp3, Temp1, LSL #2                        
+        UXTAB16 ValG, r0x00ff00ff, ValH                 ;// [00 g1 00 g0] + [0 255 0 255]
+        ADD     Temp1, Temp1, Temp1, LSL #2        
+        UXTAB16 Acc1, ValG, ValB, ROR #8
+        ADD     Acc1, Acc1, Temp1        
+
+        UXTAB16 Acc2, ValC, ValH, ROR #8        
+        ADD     ValI, r0x00ff00ff, ValI                 ;// [00 i1 00 i0] + [0 255 0 255]        
+        
+        ;// Calculate Acc2
+        ;// Acc2 = c - 5*d + 20*e + 20*f - 5*g + h
+        UXTAB16 Temp1, ValG, ValD, ROR #8
+        UXTAB16 Acc3, ValI, ValD, ROR #8
+        UXTAB16 Temp2, ValE, ValF, ROR #8
+        
+        RSB     Temp1, Temp1, Temp2, LSL #2        
+        UXTAB16 Temp2, ValG, ValF, ROR #8
+        ADD     Temp1, Temp1, Temp1, LSL #2        
+        ADD     Acc2, Acc2, Temp1        
+
+        ;// Calculate Acc3
+        ;// Acc3 = d - 5*e + 20*f + 20*g - 5*h + i
+        UXTAB16 Temp1, ValE, ValH, ROR #8
+        RSB     Temp1, Temp1, Temp2, LSL #2
+        ADD     Temp1, Temp1, Temp1, LSL #2        
+        ADD     Acc3, Acc3, Temp1
+        
+        M_LDR   dstStep, pDstStep        
+        M_LDR   srcStep, pSrcStep
+
+        ;// If Counter is even store Acc0-Acc3 in a temporary buffer
+        ;// If Counter is off store Acc0-Acc3 and previous Acc0-Acc3 in a intermediate buf 
+        ANDS        Temp3, Counter, #1
+        BEQ         NoProcessing        
+        
+        ;// Packing previous and current Acc0-Acc3 values
+        M_LDRD      Accx, Accy, pTempResult1
+        PKHBT       Temp6, Accx, Acc0, LSL #16          ;//[0 a2 0 a0] = [0 a3 0 a2] [0 a1 0 a0]
+        PKHTB       Acc0, Acc0, Accx, ASR #16           ;//[0 a3 0 a1] = [0 a1 0 a0] [0 a3 0 a2] 
+        STR         Acc0, [pDst, dstStep]                        
+        STR         Temp6, [pDst], #4                   
+        PKHBT       Temp6, Accy, Acc1, LSL #16          ;//[0 b2 0 b0] = [0 b3 0 b2] [0 b1 0 b0]
+        PKHTB       Acc1, Acc1, Accy, ASR #16            ;//[0 b3 0 b1] = [0 b1 0 b0] [0 b3 0 b2]
+        M_LDRD      Accx, Accy, pTempResult2
+        STR         Acc1, [pDst, dstStep]                        
+        STR         Temp6, [pDst], #4                   
+        
+        PKHBT       Temp6, Accx, Acc2, LSL #16          ;//[0 c2 0 c0] = [0 c3 0 c2] [0 c1 0 c0]
+        PKHTB       Acc2, Acc2, Accx, ASR #16            ;//[0 c3 0 c1] = [0 c1 0 c0] [0 c3 0 c2]
+        STR         Acc2, [pDst, dstStep]                        
+        STR         Temp6, [pDst], #4                   
+        PKHBT       Temp6, Accy, Acc3, LSL #16          ;//[0 d2 0 d0] = [0 d3 0 d2] [0 d1 0 d0]
+        PKHTB       Acc3, Acc3, Accy, ASR #16            ;//[0 d3 0 d1] = [0 d1 0 d0] [0 d3 0 d2]
+        STR         Acc3, [pDst, dstStep]                        
+        STR         Temp6, [pDst], #-12
+        ADD         pDst, pDst, dstStep, LSL #1                   
+        B           AfterStore
+
+NoProcessing
+        M_STRD      Acc0, Acc1, pTempResult1
+        M_STRD      Acc2, Acc3, pTempResult2
+AfterStore
+        SUBS        Counter, Counter, #1                ;// Loop till height is 10
+        ADD         pSrc, pSrc, srcStep, LSL #1
+        BPL         HeightLoop
+
+        STR         Acc0, [pDst], #4                    ;//[0 a1 0 a0]
+        STR         Acc1, [pDst], #4
+        STR         Acc2, [pDst], #4
+        STR         Acc3, [pDst], #-12
+        
+        ;//
+        ;// Horizontal interpolation using multiplication
+        ;//
+    
+        SUB         pSrc, pDst, dstStep, LSL #2
+        MOV         srcStep, #16
+        M_LDRD      pDst, dstStep, ppDstArgs
+
+        MOV         Counter, #4
+        LDR         r0x0014fffb, =0x0014fffb
+        LDR         r0x00140001, =0x00140001
+
+HeightLoop1
+        M_STR       Counter, pCounter
+
+        M_LDR       ValCA, [pSrc], srcStep               ;// Load  [0 c 0 a]
+        M_LDR       ValDB, [pSrc], srcStep               ;// Load  [0 d 0 b]
+        M_LDR       ValGE, [pSrc], srcStep               ;// Load  [0 g 0 e]
+        M_LDR       ValHF, [pSrc], srcStep               ;// Load  [0 h 0 f]
+
+
+        ;// Acc0 = smuad ([0 20 0 1], add([0 c 0 a] + [0 d 0 f])) - (5 * (b + e)) 
+        ;// Acc1 = smuad ([0 20 0 1], add([0 e 0 g] + [0 d 0 b])) - (5 * (c + f)) 
+        ;// Acc2 = smuad ([0 1 0 20], add([0 c 0 e] + [0 h 0 f])) - (5 * (d + g)) 
+        ;// Acc3 = smuad ([0 20 0 1], add([0 d 0 f] + [0 i 0 g])) - (5 * (e + h)) 
+
+        SMUAD       Acc0, ValCA, r0x00140001            ;// Acc0  = [0 c 0 a] * [0 20 0 1]
+        SMUAD       Acc1, ValDB, r0x00140001            ;// Acc1  = [0 c 0 a] * [0 20 0 1]
+        SMUADX      Acc2, ValGE, r0x0014fffb            ;// Acc2  = [0 g 0 e] * [0 20 0 -5]
+        SMUAD       Acc3, ValGE, r0x0014fffb            ;// Acc3  = [0 g 0 e] * [0 20 0 -5]
+
+        SMLAD       Acc0, ValDB, r0x0014fffb, Acc0      ;// Acc0 += [0 d 0 b] * [0 20 0 -5]
+        SMLADX      Acc1, ValGE, r0x00140001, Acc1      ;// Acc1 += [0 g 0 e] * [0 20 0 1]
+        SMLADX      Acc2, ValHF, r0x00140001, Acc2      ;// Acc2 += [0 h 0 f] * [0 20 0 1]
+        SMLADX      Acc3, ValHF, r0x0014fffb, Acc3      ;// Acc3 += [0 h 0 f] * [0 20 0 -5]
+
+        SMLABB      Acc0, ValGE, r0x0014fffb, Acc0      ;// Acc0 += [0 g 0 e] * [0 0 0 -5]
+        SMLATB      Acc1, ValCA, r0x0014fffb, Acc1      ;// Acc1 += [0 d 0 b] * [0 0 0 -5]
+        SMLATB      Acc2, ValCA, r0x00140001, Acc2      ;// Acc2 += [0 c 0 a] * [0 0 0 1]
+        SMLATB      Acc3, ValDB, r0x00140001, Acc3      ;// Acc3 += [0 c 0 a] * [0 0 0 1]
+
+        LDRH        ValCA, [pSrc], #4                   ;// 8 = srcStep - 16
+        SMLABB      Acc0, ValHF, r0x00140001, Acc0      ;// Acc0 += [0 h 0 f] * [0 0 0 1]        
+        SMLABB      Acc1, ValHF, r0x0014fffb, Acc1      ;// Acc1 += [0 h 0 f] * [0 0 0 -5]
+        SMLATB      Acc2, ValDB, r0x0014fffb, Acc2      ;// Acc2 += [0 d 0 b] * [0 0 0 -5]        
+        SMLABB      Acc3, ValCA, r0x00140001, Acc3      ;// Acc3 += [0 d 0 b] * [0 0 0 1]
+        
+        LDR         r0x0001fc00, =0x0001fc00            ;// (0xff * 16 * 32) - 512
+        SUB         Acc0, Acc0, r0x0001fc00        
+        SUB         Acc1, Acc1, r0x0001fc00        
+        SUB         Acc2, Acc2, r0x0001fc00        
+        SUB         Acc3, Acc3, r0x0001fc00        
+
+        USAT        Acc0, #18, Acc0
+        USAT        Acc1, #18, Acc1
+        USAT        Acc2, #18, Acc2
+        USAT        Acc3, #18, Acc3
+        
+        MOV         Acc0, Acc0, LSR #10
+        M_STRB      Acc0, [pDst], dstStep
+        MOV         Acc1, Acc1, LSR #10
+        M_STRB      Acc1, [pDst], dstStep
+        MOV         Acc2, Acc2, LSR #10
+        M_STRB      Acc2, [pDst], dstStep
+        MOV         Acc3, Acc3, LSR #10
+        M_STRB      Acc3, [pDst], dstStep
+
+
+        M_LDR       Counter, pCounter
+        SUB         pDst, pDst, dstStep, LSL #2
+        SUB         pSrc, pSrc, srcStep, LSL #2
+        ADD         pDst, pDst, #1
+        SUBS        Counter, Counter, #1
+        BGT         HeightLoop1
+End
+        SUB         pDst, pDst, #4
+        SUB         pSrc, pSrc, #16
+
+        M_END
+    
+    ENDIF
+    
+    END
+    
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_InterpolateLuma_HalfDiagVerHor4x4_unsafe_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_InterpolateLuma_HalfDiagVerHor4x4_unsafe_s.s
new file mode 100644
index 0000000..2f48e13
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_InterpolateLuma_HalfDiagVerHor4x4_unsafe_s.s
@@ -0,0 +1,276 @@
+;//
+;// 
+;// File Name:  armVCM4P10_InterpolateLuma_HalfDiagVerHor4x4_unsafe_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   9641
+;// Date:       Thursday, February 7, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+
+        EXPORT armVCM4P10_InterpolateLuma_HalfDiagVerHor4x4_unsafe
+
+        M_VARIANTS ARM1136JS
+
+    
+    
+    
+
+    IF ARM1136JS 
+        
+        M_ALLOC8 ppDstArgs, 8
+        M_ALLOC4 ppSrc, 4
+        M_ALLOC4 ppDst, 4
+        M_ALLOC4 pCounter, 4
+
+        ;// Function header
+        ;// Function:
+        ;//     armVCM4P10_InterpolateLuma_HalfDiagVerHor4x4_unsafe
+        ;//
+        ;// Implements diagonal interpolation for a block of size 4x4. Input and output should 
+        ;// be aligned. 
+        ;//
+        ;// Registers used as input for this function
+        ;// r0,r1,r2,r3, r8 where r0,r2  input pointer and r1,r3 step size, r8 intermediate-buf pointer
+        ;//
+        ;// Registers preserved for top level function
+        ;// r0,r1,r2,r3,r4,r5,r6,r14
+        ;//
+        ;// Registers modified by the function
+        ;// r7,r8,r9,r10,r11,r12
+        ;//
+        ;// Output registers
+        ;// None. Function will preserve r0-r3
+
+        M_START armVCM4P10_InterpolateLuma_HalfDiagVerHor4x4_unsafe, r6
+
+;// Declare input registers
+pSrc            RN 0
+srcStep         RN 1
+pDst            RN 2
+dstStep         RN 3
+
+;// Declare inner loop registers
+ValA            RN 5
+ValA0           RN 4
+ValA1           RN 5
+ValAF0          RN 4
+ValAF1          RN 5
+
+ValB            RN 11
+
+ValC            RN 5
+ValC0           RN 4
+ValC1           RN 5
+ValCD0          RN 12
+ValCD1          RN 14
+ValCF0          RN 4
+ValCF1          RN 5
+
+ValD            RN 10
+
+ValE            RN 7
+ValE0           RN 6
+ValE1           RN 7
+ValEB0          RN 10
+ValEB1          RN 11
+ValED0          RN 6
+ValED1          RN 7
+
+ValF            RN 10
+
+ValG            RN 14
+ValG0           RN 12
+ValG1           RN 14
+ValGB0          RN 12
+ValGB1          RN 14
+
+Acc0            RN 4
+Acc1            RN 5
+Acc2            RN 6
+Acc3            RN 7
+
+Temp            RN 7
+Step            RN 6
+
+pInterBuf       RN 8
+Counter         RN 8
+r0x00ff00ff     RN 9                                        ;// [0 255 0 255] where 255 is offset
+r0x0001fc00     RN 10                                       ;// [0 (16*255 - 16) 0 (16*255 - 16)]
+
+    
+;// Declare inner loop registers
+ValCA           RN 8
+ValDB           RN 9
+ValGE           RN 10
+ValHF           RN 11
+r0x00140001     RN 12
+r0x0014fffb     RN 14
+
+r0x00000200     RN 12
+r0x000000ff     RN 12
+        
+        M_STRD      pDst, dstStep, ppDstArgs
+        MOV         pDst, pInterBuf                
+        MOV         dstStep, #24
+
+        ;// Set up counter of format, [0]  [0]  [1 (height)]  [8 (width)]                                                                                    
+        MOV         Counter, #1
+        MOV         Temp, #8                                                        
+        ADD         Counter, Temp, Counter, LSL #8        ;// [0 0 H W]                        
+        
+        LDR         r0x00ff00ff, =0x00ff00ff                ;// [0 255 0 255] 255 is offset to avoid negative results 
+WidthLoop
+        M_STR       pSrc, ppSrc
+        M_STR       pDst, ppDst
+HeightLoop
+TwoRowsLoop
+        M_LDR       ValC, [pSrc], srcStep                   ;// Load  [c3 c2 c1 c0]
+        M_LDR       ValD, [pSrc], srcStep                   ;// Load  [d3 d2 d1 d0]
+        M_LDR       ValE, [pSrc], srcStep                   ;// Load  [e3 e2 e1 e0]        
+        SUB         pSrc, pSrc, srcStep, LSL #2                
+        UXTAB16     ValC0, r0x00ff00ff, ValC                ;// [0 c2 0 c0] + [0 255 0 255]
+        UXTAB16     ValC1, r0x00ff00ff, ValC, ROR #8        ;// [0 c3 0 c1] + [0 255 0 255]        
+        LDR         ValB, [pSrc]                            ;// Load  [b3 b2 b1 b0]        
+        UXTAB16     ValE0, r0x00ff00ff, ValE                ;// [0 e2 0 e0] + [0 255 0 255]
+        UXTAB16     ValE1, r0x00ff00ff, ValE, ROR #8        ;// [0 e3 0 e1] + [0 255 0 255]        
+        UXTAB16     ValCD0, ValC0, ValD                     ;// [0 c2 0 c0] + [0 255 0 255] + [0 d2 0 d0]
+        UXTAB16     ValCD1, ValC1, ValD, ROR #8             ;// [0 c3 0 c1] + [0 255 0 255] + [0 d3 0 d1]                                
+        UXTAB16     ValEB0, ValE0, ValB                     ;// [0 e2 0 e0] + [0 255 0 255] + [0 b2 0 b0]
+        RSB         ValCD0, ValEB0, ValCD0, LSL #2          ;// 4*(Off+C+D) - (Off+B+E)
+        
+        LDR         ValD, [pSrc, srcStep, LSL #1]                       ;// Load  [d3 d2 d1 d0]
+        UXTAB16     ValEB1, ValE1, ValB, ROR #8             ;// [0 e3 0 e1] + [0 255 0 255] + [0 b3 0 b1]                                               
+        RSB         ValCD1, ValEB1, ValCD1, LSL #2                
+        
+        UXTAB16     ValED0, ValE0, ValD                     ;// [0 e2 0 e0] + [0 255 0 255] + [0 d2 0 d0]
+        UXTAB16     ValED1, ValE1, ValD, ROR #8             ;// [0 e3 0 e1] + [0 255 0 255] + [0 d3 0 d1]                                                       
+        LDR         ValF, [pSrc, srcStep, LSL #2]           ;// Load  [f3 f2 f1 f0]
+        M_LDR       ValB, [pSrc], srcStep                   ;// Load  [b3 b2 b1 b0]                
+        ADD         ValCD0, ValCD0, ValCD0, LSL #2          ;// 5 * [4*(Off+C+D) - (Off+B+E)]
+        ADD         ValCD1, ValCD1, ValCD1, LSL #2                          
+        UXTAB16     ValCF1, ValC1, ValF, ROR #8             ;// [0 c3 0 c1] + [0 255 0 255] + [0 f3 0 f1]                                
+        UXTAB16     ValCF0, ValC0, ValF                     ;// [0 c2 0 c0] + [0 255 0 255] + [0 f2 0 f0]        
+        RSB         ValED1, ValCF1, ValED1, LSL #2        
+        
+        SUB         ValA, pSrc, srcStep, LSL #1
+        LDR         ValA, [ValA]                            ;// Load  [a3 a2 a1 a0]
+        RSB         ValED0, ValCF0, ValED0, LSL #2          ;// 4*(Off+E+D) - (Off+C+F)        
+        ADD         ValED1, ValED1, ValED1, LSL #2          
+        ADD         ValED0, ValED0, ValED0, LSL #2          ;// 5 * [4*(Off+E+D) - (Off+C+F)]
+        UXTAB16     ValA0, r0x00ff00ff, ValA                ;// [0 a2 0 a0] + [0 255 0 255]
+        UXTAB16     ValA1, r0x00ff00ff, ValA, ROR #8        ;// [0 a3 0 a1] + [0 255 0 255]
+        UXTAB16     ValAF0, ValA0, ValF                     ;// [0 a2 0 a0] + [0 255 0 255] + [0 f2 0 f0]
+        UXTAB16     ValAF1, ValA1, ValF, ROR #8             ;// [0 a3 0 a1] + [0 255 0 255] + [0 f3 0 f1]                                        
+        ADD         Acc1, ValCD1, ValAF1        
+        
+        LDR         ValG, [pSrc, srcStep, LSL #2]           ;// Load  [g3 g2 g1 g0]
+        ADD         Acc0, ValCD0, ValAF0                    ;// Acc0 = 16*Off + (A+F) + 20*(C+D) - 5*(B+E)        
+        STR         Acc1, [pDst, #4]                        ;// Store result & adjust pointer
+        M_STR       Acc0, [pDst], dstStep                   ;// Store result & adjust pointer
+        UXTAB16     ValG0, r0x00ff00ff, ValG                ;// [0 g2 0 g0] + [0 255 0 255]
+        UXTAB16     ValG1, r0x00ff00ff, ValG, ROR #8        ;// [0 g3 0 g1] + [0 255 0 255]
+        UXTAB16     ValGB0, ValG0, ValB                     ;// [0 g2 0 g0] + [0 255 0 255] + [0 b2 0 b0]
+        UXTAB16     ValGB1, ValG1, ValB, ROR #8             ;// [0 g3 0 g1] + [0 255 0 255] + [0 b3 0 b1]                        
+        ADD         Acc2, ValED0, ValGB0                    ;// Acc2 = 16*Off + (B+G) + 20*(D+E) - 5*(C+F)
+        ADD         Acc3, ValED1, ValGB1        
+        
+        STR         Acc3, [pDst, #4]                        ;// Store result & adjust pointer                                       
+        M_STR       Acc2, [pDst], dstStep                   ;// Store result & adjust pointer                                               
+        
+        SUBS        Counter, Counter, #1 << 8               ;// Loop till height is 10
+        ADD         pSrc, pSrc, srcStep, LSL #1
+        BPL         HeightLoop
+        
+        M_LDR       pSrc, ppSrc
+        M_LDR       pDst, ppDst
+        ADDS        Counter, Counter, #(1 << 8)-4           ;// Loop till width is 12
+        ADD         pSrc, pSrc, #4
+        ADD         pDst, pDst, #8
+        ADD         Counter, Counter, #1<<8
+        BPL         WidthLoop
+    
+        ;//
+        ;// Horizontal interpolation using multiplication
+        ;//
+    
+        SUB         pSrc, pDst, #24
+        MOV         srcStep, #24
+        M_LDRD      pDst, dstStep, ppDstArgs
+
+        MOV         Counter, #4
+        LDR         r0x0014fffb, =0x0014fffb
+        LDR         r0x00140001, =0x00140001
+
+HeightLoop1
+        M_STR       Counter, pCounter
+
+
+        LDR         ValCA, [pSrc], #4                   ;// Load  [0 c 0 a]
+        LDR         ValDB, [pSrc], #4                   ;// Load  [0 d 0 b]
+        LDR         ValGE, [pSrc], #4                   ;// Load  [0 g 0 e]
+        LDR         ValHF, [pSrc], #4                   ;// Load  [0 h 0 f]
+
+        ;// Acc0 = smuad ([0 20 0 1], add([0 c 0 a] + [0 d 0 f])) - (5 * (b + e)) 
+        ;// Acc1 = smuad ([0 20 0 1], add([0 e 0 g] + [0 d 0 b])) - (5 * (c + f)) 
+        ;// Acc2 = smuad ([0 1 0 20], add([0 c 0 e] + [0 h 0 f])) - (5 * (d + g)) 
+        ;// Acc3 = smuad ([0 20 0 1], add([0 d 0 f] + [0 i 0 g])) - (5 * (e + h)) 
+        SMUAD       Acc0, ValCA, r0x00140001            ;// Acc0  = [0 c 0 a] * [0 20 0 1]
+        SMUAD       Acc1, ValDB, r0x00140001            ;// Acc1  = [0 c 0 a] * [0 20 0 1]
+        SMUADX      Acc2, ValGE, r0x0014fffb            ;// Acc2  = [0 g 0 e] * [0 20 0 -5]
+        SMUAD       Acc3, ValGE, r0x0014fffb            ;// Acc3  = [0 g 0 e] * [0 20 0 -5]
+
+        SMLAD       Acc0, ValDB, r0x0014fffb, Acc0      ;// Acc0 += [0 d 0 b] * [0 20 0 -5]
+        SMLADX      Acc1, ValGE, r0x00140001, Acc1      ;// Acc1 += [0 g 0 e] * [0 20 0 1]
+        SMLADX      Acc2, ValHF, r0x00140001, Acc2      ;// Acc2 += [0 h 0 f] * [0 20 0 1]
+        SMLADX      Acc3, ValHF, r0x0014fffb, Acc3      ;// Acc3 += [0 h 0 f] * [0 20 0 -5]
+
+        SMLABB      Acc0, ValGE, r0x0014fffb, Acc0      ;// Acc0 += [0 g 0 e] * [0 0 0 -5]
+        SMLATB      Acc1, ValCA, r0x0014fffb, Acc1      ;// Acc1 += [0 d 0 b] * [0 0 0 -5]
+        SMLATB      Acc2, ValCA, r0x00140001, Acc2      ;// Acc2 += [0 c 0 a] * [0 0 0 1]
+        SMLATB      Acc3, ValDB, r0x00140001, Acc3      ;// Acc3 += [0 c 0 a] * [0 0 0 1]
+
+        LDRH        ValCA, [pSrc], #8                   ;// 8 = srcStep - 16
+        SMLABB      Acc0, ValHF, r0x00140001, Acc0      ;// Acc0 += [0 h 0 f] * [0 0 0 1]        
+        SMLABB      Acc1, ValHF, r0x0014fffb, Acc1      ;// Acc1 += [0 h 0 f] * [0 0 0 -5]
+        SMLATB      Acc2, ValDB, r0x0014fffb, Acc2      ;// Acc2 += [0 d 0 b] * [0 0 0 -5]        
+        SMLABB      Acc3, ValCA, r0x00140001, Acc3      ;// Acc3 += [0 d 0 b] * [0 0 0 1]
+        
+        LDR         r0x0001fc00, =0x0001fc00            ;// (0xff * 16 * 32) - 512
+        SUB         Acc0, Acc0, r0x0001fc00        
+        SUB         Acc1, Acc1, r0x0001fc00        
+        SUB         Acc2, Acc2, r0x0001fc00        
+        SUB         Acc3, Acc3, r0x0001fc00        
+
+        USAT        Acc0, #18, Acc0
+        USAT        Acc1, #18, Acc1
+        USAT        Acc2, #18, Acc2
+        USAT        Acc3, #18, Acc3
+        
+        MOV         Acc0, Acc0, LSR #10
+        MOV         Acc1, Acc1, LSR #10
+        MOV         Acc2, Acc2, LSR #10
+        MOV         Acc3, Acc3, LSR #10
+
+        M_LDR       Counter, pCounter        
+        ORR         Acc0, Acc0, Acc1, LSL #8
+        ORR         Acc2, Acc2, Acc3, LSL #8
+        SUBS        Counter, Counter, #1
+        ORR         Acc0, Acc0, Acc2, LSL #16
+        M_STR       Acc0, [pDst], dstStep
+        BGT         HeightLoop1
+End
+        SUB         pDst, pDst, dstStep, LSL #2
+        SUB         pSrc, pSrc, srcStep, LSL #2
+
+        M_END
+    
+    ENDIF
+    
+    END
+    
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe_s.s
new file mode 100644
index 0000000..6690ced
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe_s.s
@@ -0,0 +1,239 @@
+;//
+;// 
+;// File Name:  armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   9641
+;// Date:       Thursday, February 7, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+
+        M_VARIANTS ARM1136JS
+        
+        EXPORT armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe
+
+DEBUG_ON    SETL {FALSE}
+
+
+    IF ARM1136JS
+
+;// Function: 
+;//     armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe
+;//
+;// Implements horizontal interpolation for a block of size 4x4. Input and output should 
+;// be aligned. 
+;//
+;// Registers used as input for this function
+;// r0,r1,r2,r3 where r0,r2  input pointer and r1,r3 corresponding step size
+;//
+;// Registers preserved for top level function
+;// r0,r1,r2,r3,r4,r5,r6,r14
+;//
+;// Registers modified by the function
+;// r7,r8,r9,r10,r11,r12
+;//
+;// Output registers
+;// None. Function will preserve r0-r3
+
+
+;// Declare input registers
+pSrc            RN 0
+srcStep         RN 1
+pDst            RN 2
+dstStep         RN 3
+
+;// Declare inner loop registers
+Acc0            RN 4
+Acc1            RN 5
+Acc2            RN 6
+Acc3            RN 7
+
+ValA            RN 4
+ValB            RN 5
+ValC            RN 6
+ValD            RN 7
+ValE            RN 8
+ValF            RN 9
+ValG            RN 12
+ValH            RN 14
+ValI            RN 1
+
+Temp1           RN 3
+Temp2           RN 1
+Temp3           RN 12
+Temp4           RN 7
+Temp5           RN 5
+r0x0fe00fe0     RN 3                                    ;// [0 (16*255 - 16) 0 (16*255 - 16)]
+r0x00ff00ff     RN 10                                   ;// [0 255 0 255] where 255 is offset
+Counter         RN 11
+
+Height          RN 3
+
+        M_ALLOC4 pDstStep, 4
+        M_ALLOC4 pSrcStep, 4
+
+        ;// Function header
+        M_START armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe, r6
+        
+        MOV     Counter, #2
+        M_STR   dstStep, pDstStep        
+        M_STR   srcStep, pSrcStep        
+        LDR     r0x00ff00ff, =0x00ff00ff               ;// [0 255 0 255] 255 is offset to avoid negative results 
+
+NextTwoRowsLoop
+        LDR     ValD, [pSrc, srcStep]                   ;// Load row 1 [d1 c1 b1 a1]
+        LDR     ValA, [pSrc], #4                        ;// Load row 0 [d0 c0 b0 a0]
+        LDR     ValH, [pSrc, srcStep]                   ;// Load  [h1 g1 f1 e1]        
+        LDR     ValE, [pSrc], #4                        ;// Load  [h0 g0 f0 e0]
+        LDRB    Temp2, [pSrc, srcStep]                  ;// Load row 1 [l1 k1 j1 i1]
+        LDRB    Temp1, [pSrc], #-8                      ;// Load row 0 [l0 k0 j0 i0]
+        
+        PKHBT   ValB, ValA, ValD, LSL #16               ;// [b1 a1 b0 a0]
+        PKHTB   ValD, ValD, ValA, ASR #16               ;// [d1 c1 d0 c0]
+        UXTAB16 ValA, r0x00ff00ff, ValB                 ;// [00 a1 00 a0] + [0 255 0 255]
+        UXTAB16 ValC, r0x00ff00ff, ValD                 ;// [00 c1 00 c0] + [0 255 0 255]
+        PKHBT   ValI, Temp1, Temp2, LSL #16             ;// [00 i1 00 i0]            
+        PKHBT   ValF, ValE, ValH, LSL #16               ;// [f1 e1 f0 e0]
+        PKHTB   ValH, ValH, ValE, ASR #16               ;// [h1 g1 h0 g0]
+        UXTAB16 ValE, r0x00ff00ff, ValF                 ;// [00 e1 00 e0] + [0 255 0 255]
+
+        ;// Calculate Acc0
+        ;// Acc0 = a - 5*b + 20*c + 20*d - 5*e + f
+        UXTAB16 Temp1, ValC, ValD, ROR #8
+        UXTAB16 Temp3, ValE, ValB, ROR #8
+        RSB     Temp1, Temp3, Temp1, LSL #2                
+        UXTAB16 Acc0, ValA, ValF, ROR #8
+        ADD     Temp1, Temp1, Temp1, LSL #2        
+        ADD     Acc0, Acc0, Temp1       
+
+        ;// Calculate Acc1
+        ;// Acc1 = b - 5*c + 20*d + 20*e - 5*f + g
+        UXTAB16 Temp1, ValE, ValD, ROR #8
+        UXTAB16 Temp3, ValC, ValF, ROR #8
+        RSB     Temp1, Temp3, Temp1, LSL #2                        
+        UXTAB16 ValG, r0x00ff00ff, ValH                 ;// [00 g1 00 g0] + [0 255 0 255]
+        ADD     Temp1, Temp1, Temp1, LSL #2        
+        UXTAB16 Acc1, ValG, ValB, ROR #8
+        ADD     Acc1, Acc1, Temp1        
+
+        LDR     r0x0fe00fe0, =0x0fe00fe0                ;// 0x0fe00fe0 = (16 * Offset) - 16 where Offset is 255        
+        UXTAB16 Acc2, ValC, ValH, ROR #8        
+        ADD     ValI, r0x00ff00ff, ValI                 ;// [00 i1 00 i0] + [0 255 0 255]        
+        UQSUB16 Acc0, Acc0, r0x0fe00fe0                    
+        UQSUB16 Acc1, Acc1, r0x0fe00fe0
+        USAT16  Acc0, #13, Acc0
+        USAT16  Acc1, #13, Acc1        
+        
+        ;// Calculate Acc2
+        ;// Acc2 = c - 5*d + 20*e + 20*f - 5*g + h
+        UXTAB16 Temp1, ValG, ValD, ROR #8
+        UXTAB16 Acc3, ValI, ValD, ROR #8
+        UXTAB16 Temp2, ValE, ValF, ROR #8
+        AND     Acc1, r0x00ff00ff, Acc1, LSR #5
+        AND     Acc0, r0x00ff00ff, Acc0, LSR #5
+        ORR     Acc0, Acc0, Acc1, LSL #8        
+        RSB     Temp5, Temp1, Temp2, LSL #2        
+        UXTAB16 Temp2, ValG, ValF, ROR #8
+        ADD     Temp5, Temp5, Temp5, LSL #2        
+        ADD     Acc2, Acc2, Temp5        
+
+        ;// Calculate Acc3
+        ;// Acc3 = d - 5*e + 20*f + 20*g - 5*h + i
+        UXTAB16 Temp5, ValE, ValH, ROR #8
+        RSB     Temp5, Temp5, Temp2, LSL #2
+        LDR     r0x0fe00fe0, =0x0fe00fe0
+        ADD     Temp5, Temp5, Temp5, LSL #2        
+        ADD     Acc3, Acc3, Temp5
+        
+        UQSUB16 Acc3, Acc3, r0x0fe00fe0        
+        UQSUB16 Acc2, Acc2, r0x0fe00fe0        
+        USAT16  Acc3, #13, Acc3
+        USAT16  Acc2, #13, Acc2        
+
+        M_LDR   dstStep, pDstStep
+        AND     Acc3, r0x00ff00ff, Acc3, LSR #5
+        AND     Acc2, r0x00ff00ff, Acc2, LSR #5
+        ORR     Acc2, Acc2, Acc3, LSL #8
+        
+        SUBS    Counter, Counter, #1
+        M_LDR   srcStep, pSrcStep
+        PKHBT   Acc1, Acc0, Acc2, LSL #16   
+        M_STR   Acc1, [pDst], dstStep                   ;// Store result1
+        PKHTB   Acc2, Acc2, Acc0, ASR #16   
+        M_STR   Acc2, [pDst], dstStep                   ;// Store result2
+        ADD     pSrc, pSrc, srcStep, LSL #1
+        
+        BGT     NextTwoRowsLoop
+End
+        SUB     pDst, pDst, dstStep, LSL #2
+        SUB     pSrc, pSrc, srcStep, LSL #2
+
+        M_END
+    
+    ENDIF
+
+    END
+    
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe_s.s
new file mode 100644
index 0000000..007cd0d
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe_s.s
@@ -0,0 +1,185 @@
+;//
+;// 
+;// File Name:  armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   9641
+;// Date:       Thursday, February 7, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+       
+        M_VARIANTS ARM1136JS
+       
+        EXPORT armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe
+
+
+    
+    IF ARM1136JS
+    
+        ;// Function header
+
+        ;// Function: 
+        ;//     armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe  
+        ;//
+        ;// Implements vertical interpolation for a block of size 4x4. Input and output should 
+        ;// be aligned. 
+        ;//
+        ;// Registers used as input for this function
+        ;// r0,r1,r2,r3 where r0,r2  input pointer and r1,r3 corresponding step size
+        ;//
+        ;// Registers preserved for top level function
+        ;// r0,r1,r2,r3,r4,r5,r6,r14
+        ;//
+        ;// Registers modified by the function
+        ;// r7,r8,r9,r10,r11,r12
+        ;//
+        ;// Output registers
+        ;// None. Function will preserve r0-r3
+        M_START armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe, r6
+
+;// Declare input registers
+pSrc            RN 0
+srcStep         RN 1
+pDst            RN 2
+dstStep         RN 3
+
+;// Declare inner loop registers
+ValA            RN 5
+ValA0           RN 4
+ValA1           RN 5
+ValAF0          RN 4
+ValAF1          RN 5
+
+ValB            RN 11
+
+ValC            RN 5
+ValC0           RN 4
+ValC1           RN 5
+ValCD0          RN 12
+ValCD1          RN 14
+ValCF0          RN 4
+ValCF1          RN 5
+
+ValD            RN 10
+
+ValE            RN 7
+ValE0           RN 6
+ValE1           RN 7
+ValEB0          RN 10
+ValEB1          RN 11
+ValED0          RN 6
+ValED1          RN 7
+
+ValF            RN 10
+
+ValG            RN 14
+ValG0           RN 12
+ValG1           RN 14
+ValGB0          RN 12
+ValGB1          RN 14
+
+Acc0            RN 4
+Acc1            RN 5
+Acc2            RN 6
+Acc3            RN 7
+
+Temp            RN 7
+Height          RN 3
+Step            RN 6
+
+Counter         RN 8
+r0x00ff00ff     RN 9                                        ;// [0 255 0 255] where 255 is offset
+r0x0fe00fe0     RN 10                                       ;// [0 (16*255 - 16) 0 (16*255 - 16)]
+
+        
+        LDR         r0x00ff00ff, =0x00ff00ff                ;// [0 255 0 255] 255 is offset to avoid negative results 
+        MOV         Counter, #2
+        
+TwoRowsLoop
+        M_LDR       ValC, [pSrc], srcStep                   ;// Load  [c3 c2 c1 c0]
+        M_LDR       ValD, [pSrc], srcStep                   ;// Load  [d3 d2 d1 d0]
+        M_LDR       ValE, [pSrc], srcStep                   ;// Load  [e3 e2 e1 e0]        
+        SUB         pSrc, pSrc, srcStep, LSL #2                
+        LDR         ValB, [pSrc]                            ;// Load  [b3 b2 b1 b0]        
+        UXTAB16     ValC0, r0x00ff00ff, ValC                ;// [0 c2 0 c0] + [0 255 0 255]
+        UXTAB16     ValC1, r0x00ff00ff, ValC, ROR #8        ;// [0 c3 0 c1] + [0 255 0 255]        
+        
+        UXTAB16     ValE0, r0x00ff00ff, ValE                ;// [0 e2 0 e0] + [0 255 0 255]
+        UXTAB16     ValE1, r0x00ff00ff, ValE, ROR #8        ;// [0 e3 0 e1] + [0 255 0 255]        
+        UXTAB16     ValCD0, ValC0, ValD                     ;// [0 c2 0 c0] + [0 255 0 255] + [0 d2 0 d0]
+        UXTAB16     ValCD1, ValC1, ValD, ROR #8             ;// [0 c3 0 c1] + [0 255 0 255] + [0 d3 0 d1]                                
+        UXTAB16     ValEB0, ValE0, ValB                     ;// [0 e2 0 e0] + [0 255 0 255] + [0 b2 0 b0]
+        RSB         ValCD0, ValEB0, ValCD0, LSL #2          ;// 4*(Off+C+D) - (Off+B+E)
+        
+        LDR         ValD, [pSrc, srcStep, LSL #1]                       ;// Load  [d3 d2 d1 d0]
+        UXTAB16     ValEB1, ValE1, ValB, ROR #8             ;// [0 e3 0 e1] + [0 255 0 255] + [0 b3 0 b1]                                               
+        RSB         ValCD1, ValEB1, ValCD1, LSL #2                
+        ;// One cycle stall
+        UXTAB16     ValED0, ValE0, ValD                     ;// [0 e2 0 e0] + [0 255 0 255] + [0 d2 0 d0]
+        UXTAB16     ValED1, ValE1, ValD, ROR #8             ;// [0 e3 0 e1] + [0 255 0 255] + [0 d3 0 d1]                                               
+        
+        LDR         ValF, [pSrc, srcStep, LSL #2]           ;// Load  [f3 f2 f1 f0]
+        M_LDR       ValB, [pSrc], srcStep                   ;// Load  [b3 b2 b1 b0]                
+        ADD         ValCD0, ValCD0, ValCD0, LSL #2          ;// 5 * [4*(Off+C+D) - (Off+B+E)]
+        ADD         ValCD1, ValCD1, ValCD1, LSL #2                          
+        UXTAB16     ValCF1, ValC1, ValF, ROR #8             ;// [0 c3 0 c1] + [0 255 0 255] + [0 f3 0 f1]                                
+        UXTAB16     ValCF0, ValC0, ValF                     ;// [0 c2 0 c0] + [0 255 0 255] + [0 f2 0 f0]
+        RSB         ValED1, ValCF1, ValED1, LSL #2        
+        
+        SUB         ValA, pSrc, srcStep, LSL #1
+        LDR         ValA, [ValA]                            ;// Load  [a3 a2 a1 a0]
+        RSB         ValED0, ValCF0, ValED0, LSL #2          ;// 4*(Off+E+D) - (Off+C+F)        
+        ADD         ValED1, ValED1, ValED1, LSL #2          
+        ADD         ValED0, ValED0, ValED0, LSL #2          ;// 5 * [4*(Off+E+D) - (Off+C+F)]
+        UXTAB16     ValA0, r0x00ff00ff, ValA                ;// [0 a2 0 a0] + [0 255 0 255]
+        UXTAB16     ValA1, r0x00ff00ff, ValA, ROR #8        ;// [0 a3 0 a1] + [0 255 0 255]
+        UXTAB16     ValAF0, ValA0, ValF                     ;// [0 a2 0 a0] + [0 255 0 255] + [0 f2 0 f0]
+        UXTAB16     ValAF1, ValA1, ValF, ROR #8             ;// [0 a3 0 a1] + [0 255 0 255] + [0 f3 0 f1]                                
+        
+        LDR         r0x0fe00fe0, =0x0fe00fe0                ;// [0 255 0 255] 255 is offset to avoid negative results 
+        ADD         Acc1, ValCD1, ValAF1        
+        
+        LDR         ValG, [pSrc, srcStep, LSL #2]           ;// Load  [g3 g2 g1 g0]
+        ADD         Acc0, ValCD0, ValAF0                    ;// Acc0 = 16*Off + (A+F) + 20*(C+D) - 5*(B+E)        
+        UQSUB16     Acc1, Acc1, r0x0fe00fe0                 ;// Acc1 -= (16*Off - 16)
+        UQSUB16     Acc0, Acc0, r0x0fe00fe0        
+        UXTAB16     ValG0, r0x00ff00ff, ValG                ;// [0 g2 0 g0] + [0 255 0 255]
+        UXTAB16     ValG1, r0x00ff00ff, ValG, ROR #8        ;// [0 g3 0 g1] + [0 255 0 255]
+        UXTAB16     ValGB0, ValG0, ValB                     ;// [0 g2 0 g0] + [0 255 0 255] + [0 b2 0 b0]
+        UXTAB16     ValGB1, ValG1, ValB, ROR #8             ;// [0 g3 0 g1] + [0 255 0 255] + [0 b3 0 b1]                        
+        ADD         Acc2, ValED0, ValGB0                    ;// Acc2 = 16*Off + (B+G) + 20*(D+E) - 5*(C+F)
+        ADD         Acc3, ValED1, ValGB1        
+        UQSUB16     Acc3, Acc3, r0x0fe00fe0                 ;// Acc3 -= (16*Off - 16)
+        UQSUB16     Acc2, Acc2, r0x0fe00fe0        
+        USAT16      Acc1, #13, Acc1                         ;// Saturate to 8+5 = 13 bits
+        USAT16      Acc0, #13, Acc0
+        USAT16      Acc3, #13, Acc3        
+        USAT16      Acc2, #13, Acc2
+        AND         Acc1, r0x00ff00ff, Acc1, LSR #5         ;// [0 a3 0 a1]
+        AND         Acc0, r0x00ff00ff, Acc0, LSR #5         ;// [0 a2 0 a0]
+        ORR         Acc0, Acc0, Acc1, LSL #8                ;// [a3 a2 a1 a0]
+        AND         Acc3, r0x00ff00ff, Acc3, LSR #5         ;// [0 b3 0 b1]
+        AND         Acc2, r0x00ff00ff, Acc2, LSR #5         ;// [0 b2 0 b0]
+        
+        M_STR       Acc0, [pDst], dstStep                   ;// Store result & adjust pointer
+        ORR         Acc2, Acc2, Acc3, LSL #8                ;// [b3 b2 b1 b0]        
+        M_STR       Acc2, [pDst], dstStep                   ;// Store result & adjust pointer                                       
+        ADD         pSrc, pSrc, srcStep, LSL #1
+        
+        SUBS        Counter, Counter, #1
+        BGT         TwoRowsLoop
+End
+        SUB     pDst, pDst, dstStep, LSL #2
+        SUB     pSrc, pSrc, srcStep, LSL #2
+
+        M_END
+    
+    ENDIF
+    
+    END
+    
\ No newline at end of file
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_Interpolate_Chroma_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_Interpolate_Chroma_s.s
new file mode 100644
index 0000000..b1ad17c
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_Interpolate_Chroma_s.s
@@ -0,0 +1,273 @@
+;//
+;// 
+;// File Name:  armVCM4P10_Interpolate_Chroma_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   9641
+;// Date:       Thursday, February 7, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+        
+        M_VARIANTS ARM1136JS
+        
+    IF ARM1136JS
+
+;// input registers
+
+pSrc                 RN 0
+iSrcStep             RN 1
+pDst                 RN 2
+iDstStep             RN 3
+iWidth               RN 4
+iHeight              RN 5
+dx                   RN 6
+dy                   RN 7
+
+
+;// local variable registers
+temp                 RN 11
+r0x20                RN 12
+tmp0x20              RN 14
+return               RN 0
+dxPlusdy             RN 10
+EightMinusdx         RN 8 
+EightMinusdy         RN 9
+dxEightMinusdx       RN 8
+BACoeff              RN 6
+DCCoeff              RN 7
+                     
+iDstStepx2MinusWidth RN 8
+iSrcStepx2MinusWidth RN 9
+iSrcStep1            RN 10
+
+pSrc1                RN 1
+pSrc2                RN 8
+pDst1                RN 8
+pDst2                RN 12
+                     
+pix00                RN 8
+pix01                RN 9
+pix10                RN 10
+pix11                RN 11
+
+Out0100              RN 8  
+Out1110              RN 10 
+
+x00                  RN 8
+x01                  RN 10
+x02                  RN 12
+x10                  RN 9
+x11                  RN 11
+x12                  RN 14
+x20                  RN 10
+x21                  RN 12
+x22                  RN 14
+                     
+x01x00               RN 8  
+x02x01               RN 10 
+x11x10               RN 9  
+x12x11               RN 11 
+x21x20               RN 10 
+x22x21               RN 12 
+                     
+OutRow00             RN 12
+OutRow01             RN 14
+OutRow10             RN 10
+OutRow11             RN 12
+                     
+OutRow0100           RN 12
+OutRow1110           RN 12
+                     
+;//-----------------------------------------------------------------------------------------------
+;// armVCM4P10_Interpolate_Chroma_asm starts
+;//-----------------------------------------------------------------------------------------------
+        
+        ;// Write function header
+        M_START armVCM4P10_Interpolate_Chroma, r11
+        
+        ;// Define stack arguments
+        M_ARG   Width,      4
+        M_ARG   Height,     4
+        M_ARG   Dx,         4
+        M_ARG   Dy,         4
+        
+        ;// Load argument from the stack
+        ;// M_STALL ARM1136JS=4
+        
+        M_LDR   iWidth,  Width  
+        M_LDR   iHeight, Height  
+        M_LDR   dx,      Dx 
+        M_LDR   dy,      Dy
+        
+        ;// EightMinusdx = 8 - dx
+        ;// EightMinusdy = 8 - dy
+        
+        ;// ACoeff = EightMinusdx * EightMinusdy
+        ;// BCoeff = dx * EightMinusdy
+        ;// CCoeff = EightMinusdx * dy
+        ;// DCoeff = dx * dy
+        
+        ADD     pSrc1, pSrc, iSrcStep
+        SUB     temp, iWidth, #1
+        RSB     EightMinusdx, dx, #8 
+        RSB     EightMinusdy, dy, #8
+        CMN     dx,dy
+        ADD     dxEightMinusdx, EightMinusdx, dx, LSL #16
+        ORR     iWidth, iWidth, temp, LSL #16
+        
+        ;// Packed Coeffs.
+        
+        MUL     BACoeff, dxEightMinusdx, EightMinusdy
+        MUL     DCCoeff, dxEightMinusdx, dy        
+        
+        
+        ;// Checking either of dx and dy being non-zero
+        
+        BEQ     MVIsZero
+        
+;// Pixel layout:
+;//
+;//   x00 x01 x02
+;//   x10 x11 x12
+;//   x20 x21 x22
+
+;// If fractionl mv is not (0, 0)
+        
+OuterLoopMVIsNotZero
+
+InnerLoopMVIsNotZero
+            
+                LDRB    x00, [pSrc,  #+0]                   
+                LDRB    x10, [pSrc1, #+0]                   
+                LDRB    x01, [pSrc,  #+1]                  
+                LDRB    x11, [pSrc1, #+1]                  
+                LDRB    x02, [pSrc,  #+2]!                   
+                LDRB    x12, [pSrc1, #+2]!                   
+                
+                ORR     x01x00, x00, x01, LSL #16        
+                ;// M_STALL ARM1136JS=1
+                ORR     x02x01, x01, x02, LSL #16        
+                MOV     r0x20,  #32
+                ORR     x11x10, x10, x11, LSL #16    
+                ORR     x12x11, x11, x12, LSL #16        
+                
+                SMLAD   x01x00, x01x00, BACoeff, r0x20
+                SMLAD   x02x01, x02x01, BACoeff, r0x20                
+                
+                ;// iWidth packed with MSB (top 16 bits) 
+                ;// as inner loop counter value i.e 
+                ;// (iWidth -1) and LSB (lower 16 bits)
+                ;// as original width
+                
+                SUBS    iWidth, iWidth, #1<<17
+                
+                SMLAD   OutRow00, x11x10, DCCoeff, x01x00            
+                SMLAD   OutRow01, x12x11, DCCoeff, x02x01            
+                
+                RSB     pSrc2, pSrc, pSrc1, LSL #1
+                
+                MOV     OutRow00, OutRow00, LSR #6
+                MOV     OutRow01, OutRow01, LSR #6
+                
+                LDRB    x20,[pSrc2, #-2]
+                
+                ORR     OutRow0100, OutRow00, OutRow01, LSL #8
+                STRH    OutRow0100, [pDst], #2
+                
+                LDRB    x21,[pSrc2, #-1]
+                LDRB    x22,[pSrc2, #+0]
+                
+                ADD     pDst1, pDst, iDstStep
+                
+                ;// M_STALL ARM1136JS=1
+                                
+                ORR     x21x20, x20, x21, LSL #16
+                ORR     x22x21, x21, x22, LSL #16     
+                
+                MOV     tmp0x20, #32
+                
+                ;// Reusing the packed data x11x10 and x12x11
+                
+                SMLAD   x11x10,  x11x10,  BACoeff, tmp0x20
+                SMLAD   x12x11,  x12x11,  BACoeff, tmp0x20
+                SMLAD   OutRow10, x21x20, DCCoeff, x11x10            
+                SMLAD   OutRow11, x22x21, DCCoeff, x12x11
+                
+                MOV     OutRow10, OutRow10, LSR #6
+                MOV     OutRow11, OutRow11, LSR #6
+                
+                ;// M_STALL ARM1136JS=1
+               
+                ORR     OutRow1110, OutRow10, OutRow11, LSL #8
+                
+                STRH    OutRow1110, [pDst1, #-2]
+                
+                BGT     InnerLoopMVIsNotZero
+                
+                SUBS    iHeight, iHeight, #2
+                ADD     iWidth, iWidth, #1<<16
+                RSB     iDstStepx2MinusWidth, iWidth, iDstStep, LSL #1
+                SUB     iSrcStep1, pSrc1, pSrc
+                SUB     temp, iWidth, #1
+                RSB     iSrcStepx2MinusWidth, iWidth, iSrcStep1, LSL #1
+                ADD     pDst, pDst, iDstStepx2MinusWidth
+                ADD     pSrc1, pSrc1, iSrcStepx2MinusWidth
+                ADD     pSrc, pSrc, iSrcStepx2MinusWidth
+                ORR     iWidth, iWidth, temp, LSL #16
+                BGT     OuterLoopMVIsNotZero
+                MOV     return,  #OMX_Sts_NoErr
+                M_EXIT
+
+;// If fractionl mv is (0, 0)
+
+MVIsZero
+                ;// M_STALL ARM1136JS=4
+OuterLoopMVIsZero
+
+InnerLoopMVIsZero
+                                      
+                LDRB    pix00, [pSrc],  #+1
+                LDRB    pix01, [pSrc],  #+1
+                LDRB    pix10, [pSrc1], #+1
+                LDRB    pix11, [pSrc1], #+1
+                
+                ADD     pDst2,  pDst, iDstStep
+                SUBS    iWidth, iWidth, #1<<17                
+                
+                ORR     Out0100, pix00, pix01, LSL #8 
+                ORR     Out1110, pix10, pix11, LSL #8
+                
+                STRH    Out0100, [pDst],  #2
+                STRH    Out1110, [pDst2], #2
+                
+                BGT     InnerLoopMVIsZero
+                
+                SUBS    iHeight, iHeight, #2
+                ADD     iWidth, iWidth, #1<<16
+                RSB     iDstStepx2MinusWidth, iWidth, iDstStep, LSL #1
+                SUB     iSrcStep1, pSrc1, pSrc
+                SUB     temp, iWidth, #1
+                RSB     iSrcStepx2MinusWidth, iWidth, iSrcStep1, LSL #1
+                ADD     pDst, pDst, iDstStepx2MinusWidth
+                ADD     pSrc1, pSrc1, iSrcStepx2MinusWidth
+                ADD     pSrc, pSrc, iSrcStepx2MinusWidth
+                ORR     iWidth, iWidth, temp, LSL #16
+                BGT     OuterLoopMVIsZero
+                MOV     return,  #OMX_Sts_NoErr
+                M_END
+
+        ENDIF ;// ARM1136JS
+
+        
+        END
+
+;//-----------------------------------------------------------------------------------------------
+;// armVCM4P10_Interpolate_Chroma_asm ends
+;//-----------------------------------------------------------------------------------------------
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_QuantTables_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_QuantTables_s.s
new file mode 100644
index 0000000..f962f70
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_QuantTables_s.s
@@ -0,0 +1,74 @@
+;//
+;// 
+;// File Name:  armVCM4P10_QuantTables_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   9641
+;// Date:       Thursday, February 7, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;// Description:
+;// This file contains quantization tables
+;// 
+;// 
+
+         INCLUDE omxtypes_s.h
+         INCLUDE armCOMM_s.h
+     
+         
+         EXPORT armVCM4P10_MFMatrixQPModTable
+         EXPORT armVCM4P10_QPDivIntraTable
+         EXPORT armVCM4P10_QPDivPlusOneTable  
+         
+;//--------------------------------------------------------------
+;// This table contains armVCM4P10_MFMatrix [iQP % 6][0] entires,
+;// for values of iQP from 0 to 51 (inclusive). 
+;//--------------------------------------------------------------
+
+         M_TABLE armVCM4P10_MFMatrixQPModTable
+         DCW 13107, 11916, 10082, 9362, 8192, 7282
+         DCW 13107, 11916, 10082, 9362, 8192, 7282
+         DCW 13107, 11916, 10082, 9362, 8192, 7282
+         DCW 13107, 11916, 10082, 9362, 8192, 7282
+         DCW 13107, 11916, 10082, 9362, 8192, 7282
+         DCW 13107, 11916, 10082, 9362, 8192, 7282
+         DCW 13107, 11916, 10082, 9362, 8192, 7282
+         DCW 13107, 11916, 10082, 9362, 8192, 7282
+         DCW 13107, 11916, 10082, 9362, 8192, 7282
+         
+;//---------------------------------------------------------------
+;// This table contains ARM_M4P10_Q_OFFSET + 1 + (iQP / 6) values,
+;// for values of iQP from 0 to 51 (inclusive). 
+;//---------------------------------------------------------------
+
+         M_TABLE armVCM4P10_QPDivPlusOneTable
+         DCB 16, 16, 16, 16, 16, 16
+         DCB 17, 17, 17, 17, 17, 17
+         DCB 18, 18, 18, 18, 18, 18
+         DCB 19, 19, 19, 19, 19, 19
+         DCB 20, 20, 20, 20, 20, 20
+         DCB 21, 21, 21, 21, 21, 21
+         DCB 22, 22, 22, 22, 22, 22
+         DCB 23, 23, 23, 23, 23, 23
+         DCB 24, 24, 24, 24, 24, 24
+
+;//------------------------------------------------------------------
+;// This table contains (1 << QbitsPlusOne) / 3 Values (Intra case) ,
+;// for values of iQP from 0 to 51 (inclusive). 
+;//------------------------------------------------------------------
+    
+         M_TABLE armVCM4P10_QPDivIntraTable, 2
+         DCD 21845, 21845, 21845, 21845, 21845, 21845
+         DCD 43690, 43690, 43690, 43690, 43690, 43690
+         DCD 87381, 87381, 87381, 87381, 87381, 87381
+         DCD 174762, 174762, 174762, 174762, 174762, 174762
+         DCD 349525, 349525, 349525, 349525, 349525, 349525
+         DCD 699050, 699050, 699050, 699050, 699050, 699050
+         DCD 1398101, 1398101, 1398101, 1398101, 1398101, 1398101
+         DCD 2796202, 2796202, 2796202, 2796202, 2796202, 2796202
+         DCD 5592405, 5592405, 5592405, 5592405, 5592405, 5592405                
+         
+         
+         END
+         
\ No newline at end of file
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_TransformResidual4x4_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_TransformResidual4x4_s.s
new file mode 100644
index 0000000..241d188
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_TransformResidual4x4_s.s
@@ -0,0 +1,407 @@
+;//
+;// 
+;// File Name:  armVCM4P10_TransformResidual4x4_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   9641
+;// Date:       Thursday, February 7, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+;// Description:
+;// Transform Residual 4x4 Coefficients
+;// 
+;// 
+
+        
+;// Include standard headers
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+        
+        M_VARIANTS ARM1136JS
+        
+;// Import symbols required from other files
+;// (For example tables)
+    
+        
+        
+        
+;// Set debugging level        
+;//DEBUG_ON    SETL {TRUE}
+
+
+
+;// Guarding implementation by the processor name
+    
+    IF  ARM1136JS 
+    
+;//Input Registers
+pDst                RN  0
+pSrc                RN  1
+
+;//Output Registers
+
+
+;//Local Scratch Registers
+
+;// Packed Input pixels
+in00                RN  2                   ;// Src[0] & Src[1] 
+in02                RN  3                   ;// Src[2] & Src[3]
+in10                RN  4                   ;// Src[4] & Src[5]
+in12                RN  5                   ;// Src[6] & Src[7]
+in20                RN  6                   ;// Src[8] & Src[9]
+in22                RN  7                   ;// Src[10] & Src[11]
+in30                RN  8                   ;// Src[12] & Src[13]
+in32                RN  9                   ;// Src[14] & Src[15]
+
+;// Transpose for Row operations (Rows to cols)
+trRow00             RN  2
+trRow10             RN  10
+trRow02             RN  3
+trRow12             RN  5
+trRow20             RN  11
+trRow30             RN  12
+trRow32             RN  14
+trRow22             RN  7
+
+;// Intermediate calculations
+e0                  RN  4                   
+e1                  RN  6
+e2                  RN  8
+e3                  RN  9
+constZero           RN  1
+
+;// Row operated pixels
+rowOp00             RN  2
+rowOp10             RN  10
+rowOp20             RN  11
+rowOp30             RN  12
+rowOp02             RN  3
+rowOp12             RN  5
+rowOp22             RN  7
+rowOp32             RN  14
+
+;// Transpose for colulmn operations
+trCol00             RN  2                   
+trCol02             RN  3                   
+trCol10             RN  4                   
+trCol12             RN  5                   
+trCol20             RN  6                   
+trCol22             RN  7                   
+trCol30             RN  8                   
+trCol32             RN  9  
+
+;// Intermediate calculations
+g0                  RN  10
+g1                  RN  11
+g2                  RN  12
+g3                  RN  14   
+
+;// Coloumn operated pixels
+colOp00             RN  2                   
+colOp02             RN  3                   
+colOp10             RN  4                   
+colOp12             RN  5                   
+colOp20             RN  6                   
+colOp22             RN  7                   
+colOp30             RN  8                   
+colOp32             RN  9  
+
+
+temp1               RN  10                  ;// Temporary scratch varaibles
+const1              RN  11      
+const2              RN  12
+mask                RN  14
+
+;// Output pixels
+out00               RN  2                   
+out02               RN  3                   
+out10               RN  4                   
+out12               RN  5                   
+out20               RN  6                   
+out22               RN  7                   
+out30               RN  8                   
+out32               RN  9  
+      
+       
+       
+    ;// Allocate stack memory required by the function
+        
+
+    ;// Write function header
+        M_START armVCM4P10_TransformResidual4x4,r11
+        
+        ;******************************************************************
+        ;// The strategy used in implementing the transform is as follows:*
+        ;// Load the 4x4 block into 8 registers                           *  
+        ;// Transpose the 4x4 matrix                                      *  
+        ;// Perform the row operations (on columns) using SIMD            *  
+        ;// Transpose the 4x4 result matrix                               *  
+        ;// Perform the coloumn operations                                *
+        ;// Store the 4x4 block at one go                                 *  
+        ;******************************************************************
+
+        ;// Load all the 4x4 pixels
+        
+        LDMIA   pSrc,{in00,in02,in10,in12,in20,in22,in30,in32}
+        
+        MOV       constZero,#0                                     ;// Used to right shift by 1 
+        ;LDR       constZero,=0x00000000  
+        
+        ;*****************************************************************
+        ;//
+        ;// Transpose the matrix inorder to perform row ops as coloumn ops
+        ;// Input:   in[][] = original matrix
+        ;// Output:  trRow[][]= transposed matrix
+        ;// Step1: Obtain the LL part of the transposed matrix
+        ;// Step2: Obtain the HL part
+        ;// step3: Obtain the LH part
+        ;// Step4: Obtain the HH part
+        ;//
+        ;*****************************************************************
+        
+        ;// LL 2x2 transposed matrix 
+        ;//   d0 d1 - -
+        ;//   d4 d5 - -
+        ;//   -  -  - -
+        ;//   -  -  - -
+        
+        PKHTB   trRow10,in10,in00,ASR #16               ;// [5 4] = [f5:f1]    
+        PKHBT   trRow00,in00,in10,LSL #16               ;// [1 0] = [f4:f0]  
+        
+        ;// HL 2x2 transposed matrix  
+        ;//    -   -   - -
+        ;//    -   -   - -
+        ;//    d8  d9  - -
+        ;//   d12 d13  - -
+        
+         
+         PKHTB   trRow30,in12,in02,ASR #16              ;// [13 12] = [7 3]
+         PKHBT   trRow20,in02,in12,LSL #16              ;// [9 8] = [6 2] 
+        
+        ;// LH 2x2 transposed matrix 
+        ;//   - - d2 d3 
+        ;//   - - d6 d7 
+        ;//   - - -  -
+        ;//   - - -  -
+        
+        PKHBT   trRow02,in20,in30,LSL #16               ;// [3 2] = [f12:f8]  
+        PKHTB   trRow12,in30,in20,ASR #16               ;// [7 6] = [f13:f9] 
+        
+        
+        
+         
+        ;// HH 2x2 transposed matrix  
+        ;//    - -   -   -
+        ;//    - -   -   -
+        ;//    - -  d10 d11
+        ;//    - -  d14 d15
+        
+        PKHTB   trRow32,in32,in22,ASR #16               ;// [15 14] = [15 11]
+        PKHBT   trRow22,in22,in32,LSL #16               ;// [11 10] = [14 10]
+       
+        
+        ;**************************************** 
+        ;// Row Operations (Performed on columns)
+        ;**************************************** 
+        
+        
+        ;// SIMD operations on first two columns(two rows of the original matrix)
+        
+        
+        SADD16      e0, trRow00,trRow20                   ;//  e0 = d0 + d2 
+        SSUB16    e1, trRow00,trRow20                   ;//  e1 = d0 - d2  
+        SHADD16   e2, trRow10,constZero                 ;// (f1>>1) constZero is a register holding 0
+        SHADD16   e3, trRow30,constZero                 ;//  avoid pipeline stalls for e2 and e3
+        SSUB16    e2, e2, trRow30                       ;//  e2 = (d1>>1) - d3  
+        SADD16    e3, e3, trRow10                       ;//  e3 = d1 + (d3>>1)  
+        SADD16    rowOp00, e0, e3                       ;//  f0 = e0 + e3  
+        SADD16    rowOp10, e1, e2                       ;//  f1 = e1 + e2  
+        SSUB16    rowOp20, e1, e2                       ;//  f2 = e1 - e2  
+        SSUB16    rowOp30, e0, e3                       ;//  f3 = e0 - e3
+        
+        ;// SIMD operations on next two columns(next two rows of the original matrix)
+        
+        SADD16      e0, trRow02,trRow22
+        SSUB16    e1, trRow02,trRow22
+        SHADD16   e2, trRow12,constZero                 ;//(f1>>1) constZero is a register holding 0
+        SHADD16   e3, trRow32,constZero
+        SSUB16    e2, e2, trRow32
+        SADD16    e3, e3, trRow12
+        SADD16    rowOp02, e0, e3
+        SADD16    rowOp12, e1, e2
+        SSUB16    rowOp22, e1, e2
+        SSUB16    rowOp32, e0, e3
+        
+        
+        ;*****************************************************************
+        ;// Transpose the resultant matrix
+        ;// Input:  rowOp[][]
+        ;// Output: trCol[][] 
+        ;*****************************************************************
+        
+        ;// LL 2x2 transposed matrix 
+        ;//   d0 d1 - -
+        ;//   d4 d5 - -
+        ;//   -  -  - -
+        ;//   -  -  - -
+        
+        PKHTB   trCol10,rowOp10,rowOp00,ASR #16           ;// [5 4] = [f5:f1]
+        PKHBT   trCol00,rowOp00,rowOp10,LSL #16           ;// [1 0] = [f4:f0]  
+        
+        ;// HL 2x2 transposed matrix  
+        ;//    -   -   - -
+        ;//    -   -   - -
+        ;//    d8  d9  - -
+        ;//   d12 d13  - -
+        
+         
+         PKHTB   trCol30,rowOp12,rowOp02,ASR #16          ;// [13 12] = [7 3]
+         PKHBT   trCol20,rowOp02,rowOp12,LSL #16          ;// [9 8] = [6 2] 
+        
+        ;// LH 2x2 transposed matrix 
+        ;//   - - d2 d3 
+        ;//   - - d6 d7 
+        ;//   - - -  -
+        ;//   - - -  -
+        
+        PKHBT   trCol02,rowOp20,rowOp30,LSL #16           ;// [3 2] = [f12:f8]  
+        PKHTB   trCol12,rowOp30,rowOp20,ASR #16           ;// [7 6] = [f13:f9] 
+        
+        
+        
+         
+        ;// HH 2x2 transposed matrix  
+        ;//    - -   -   -
+        ;//    - -   -   -
+        ;//    - -  d10 d11
+        ;//    - -  d14 d15
+        
+        PKHTB   trCol32,rowOp32,rowOp22,ASR #16            ;// [15 14] = [15 11]
+        PKHBT   trCol22,rowOp22,rowOp32,LSL #16            ;// [11 10] = [14 10]
+       
+        
+        ;******************************* 
+        ;// Coloumn Operations 
+        ;******************************* 
+        
+        
+        ;// SIMD operations on first two columns
+        
+          
+        SADD16      g0, trCol00,trCol20
+        SSUB16    g1, trCol00,trCol20
+        SHADD16   g2, trCol10,constZero                     ;// (f1>>1) constZero is a register holding 0
+        SHADD16   g3, trCol30,constZero
+        SSUB16    g2, g2, trCol30
+        SADD16    g3, g3, trCol10
+        SADD16    colOp00, g0, g3
+        SADD16    colOp10, g1, g2
+        SSUB16    colOp20, g1, g2
+        SSUB16    colOp30, g0, g3
+        
+        ;// SIMD operations on next two columns
+        
+        SADD16      g0, trCol02,trCol22
+        SSUB16    g1, trCol02,trCol22
+        SHADD16   g2, trCol12,constZero                     ;// (f1>>1) constZero is a register holding 0
+        SHADD16   g3, trCol32,constZero
+        SSUB16    g2, g2, trCol32
+        SADD16    g3, g3, trCol12
+        SADD16    colOp02, g0, g3
+        SADD16    colOp12, g1, g2
+        SSUB16    colOp22, g1, g2
+        SSUB16    colOp32, g0, g3
+        
+        
+             
+                  
+             
+        ;************************************************
+        ;// Calculate final value (colOp[i][j] + 32)>>6
+        ;************************************************
+        
+        ;// const1: Serves dual purpose 
+        ;// (1) Add #32 to both the lower and higher 16bits of the SIMD result 
+        ;// (2) Convert the lower 16 bit value to an unsigned number (Add 32768)
+        
+        LDR     const1, =0x00208020             
+        
+        LDR     mask, =0xffff03ff                       ;// Used to mask the down shifted 6 bits  
+        
+        ;// const2(#512): used to convert the lower 16bit number back to signed value 
+      
+        MOV     const2,#0x200                           ;// const2 = 2^9
+        
+        ;// First Row 
+        
+        SADD16    colOp00, colOp00, const1
+        SADD16    colOp02, colOp02, const1
+        AND     colOp00, mask, colOp00, ASR #6
+        AND     colOp02, mask, colOp02, ASR #6
+        SSUB16  out00,colOp00,const2
+        SSUB16  out02,colOp02,const2    
+        
+
+        ;// Second Row
+        
+        SADD16    colOp10, colOp10, const1
+        SADD16    colOp12, colOp12, const1
+        AND     colOp10, mask, colOp10, ASR #6
+        AND     colOp12, mask, colOp12, ASR #6
+        SSUB16  out10,colOp10,const2
+        SSUB16  out12,colOp12,const2    
+        
+        
+        ;// Third Row
+        
+        SADD16    colOp20, colOp20, const1
+        SADD16    colOp22, colOp22, const1
+        AND     colOp20, mask, colOp20, ASR #6
+        AND     colOp22, mask, colOp22, ASR #6
+        SSUB16  out20,colOp20,const2
+        SSUB16  out22,colOp22,const2
+        
+        
+        ;// Fourth Row   
+        
+        SADD16    colOp30, colOp30, const1
+        SADD16    colOp32, colOp32, const1
+        AND     colOp30, mask, colOp30, ASR #6
+        AND     colOp32, mask, colOp32, ASR #6
+        SSUB16  out30,colOp30,const2
+        SSUB16  out32,colOp32,const2
+        
+        
+        
+                
+        ;***************************
+        ;// Store all the 4x4 pixels
+        ;***************************
+        
+        STMIA   pDst,{out00,out02,out10,out12,out20,out22,out30,out32}
+        
+                               
+       
+        ;// Set return value
+        
+End                
+
+        
+        ;// Write function tail
+        M_END
+        
+    ENDIF                                                           ;//ARM1136JS    
+    
+    
+
+
+
+
+
+;// Guarding implementation by the processor name
+    
+            
+    END
\ No newline at end of file
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_UnpackBlock4x4_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_UnpackBlock4x4_s.s
new file mode 100644
index 0000000..ad16d9cb0
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/armVCM4P10_UnpackBlock4x4_s.s
@@ -0,0 +1,92 @@
+;//
+;// 
+;// File Name:  armVCM4P10_UnpackBlock4x4_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   9641
+;// Date:       Thursday, February 7, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+        
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+        
+;// Define the processor variants supported by this file
+
+        M_VARIANTS ARM1136JS
+        
+                       
+        IF ARM1136JS
+        
+;//--------------------------------------
+;// Input Arguments and their scope/usage
+;//--------------------------------------
+ppSrc           RN 0    ;// Persistent variable
+pDst            RN 1    ;// Persistent variable
+
+;//--------------------------------
+;// Variables and their scope/usage
+;//--------------------------------
+pSrc            RN 2    ;// Persistent variables
+Flag            RN 3    
+Value           RN 4    
+Value2          RN 5    
+strOffset       RN 6    
+cstOffset       RN 7    
+
+        
+        M_START armVCM4P10_UnpackBlock4x4, r7
+        
+        LDR     pSrc, [ppSrc]                       ;// Load pSrc
+        MOV     cstOffset, #31                      ;// To be used in the loop, to compute offset
+        
+        ;//-----------------------------------------------------------------------
+        ; Firstly, fill all the coefficient values on the <pDst> buffer by zero
+        ;//-----------------------------------------------------------------------
+        
+        MOV      Value,  #0                         ;// Initialize the zero value
+        MOV      Value2, #0                         ;// Initialize the zero value
+        LDRB     Flag,  [pSrc], #1                  ;// Preload <Flag> before <unpackLoop>
+        
+        STRD     Value, [pDst, #0]                  ;// pDst[0]  = pDst[1]  = pDst[2]  = pDst[3]  = 0
+        STRD     Value, [pDst, #8]                  ;// pDst[4]  = pDst[5]  = pDst[6]  = pDst[7]  = 0
+        STRD     Value, [pDst, #16]                 ;// pDst[8]  = pDst[9]  = pDst[10] = pDst[11] = 0
+        STRD     Value, [pDst, #24]                 ;// pDst[12] = pDst[13] = pDst[14] = pDst[15] = 0
+        
+        ;//----------------------------------------------------------------------------
+        ;// The loop below parses and unpacks the input stream. The C-model has 
+        ;// a somewhat complicated logic for sign extension.  But in the v6 version,
+        ;// that can be easily taken care by loading the data from <pSrc> stream as 
+        ;// SIGNED byte/halfword. So, based on the first TST instruction, 8-bits or 
+        ;// 16-bits are read.
+        ;//
+        ;// Next, to compute the offset, where the unpacked value needs to be stored,
+        ;// we modify the computation to perform [(Flag & 15) < 1] as [(Flag < 1) & 31]
+        ;// This results in a saving of one cycle.
+        ;//----------------------------------------------------------------------------
+        
+unpackLoop
+        TST      Flag,  #0x10                        ;// Computing (Flag & 0x10)
+        LDRSBNE  Value2,[pSrc,#1]                    ;// Load byte wise to avoid unaligned access   
+        LDRBNE   Value, [pSrc], #2                   
+        AND      strOffset, cstOffset, Flag, LSL #1  ;// strOffset = (Flag & 15) < 1;
+        LDRSBEQ  Value, [pSrc], #1                   ;// Value = (OMX_U8)  *pSrc++
+        ORRNE    Value,Value,Value2, LSL #8          ;// Value = (OMX_U16) *pSrc++
+        
+        TST      Flag,  #0x20                        ;// Computing (Flag & 0x20) to check, if we're done
+        LDRBEQ   Flag,  [pSrc], #1                   ;// Flag  = (OMX_U8) *pSrc++, for next iteration
+        STRH     Value, [pDst, strOffset]            ;// Store <Value> at offset <strOffset>
+        BEQ      unpackLoop                          ;// Branch to the loop beginning
+        
+        STR      pSrc, [ppSrc]                       ;// Update the bitstream pointer
+        M_END
+    
+    ENDIF
+    
+    
+    
+    END
+    
\ No newline at end of file
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_DeblockChroma_I.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_DeblockChroma_I.c
new file mode 100644
index 0000000..c2e6b601
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_DeblockChroma_I.c
@@ -0,0 +1,88 @@
+/* ----------------------------------------------------------------
+ *
+ * 
+ * File Name:  omxVCM4P10_DeblockChroma_I.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * H.264 intra chroma deblock
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+
+/**
+ * Function: omxVCM4P10_DeblockChroma_I
+ *
+ * Description:
+ * Performs deblocking filtering on all edges of the chroma macroblock (16x16).
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	pSrcDst         pointer to the input macroblock. Must be 8-byte aligned.
+ * [in]	srcdstStep      Step of the arrays
+ * [in]	pAlpha          pointer to a 2x2 array of alpha thresholds, organized as follows: { external
+ *                          vertical edge, internal  vertical edge, external
+ *                         horizontal edge, internal horizontal edge }
+ * [in]	pBeta			pointer to a 2x2 array of beta thresholds, organized as follows: { external
+ *                              vertical edge, internal vertical edge, external  horizontal edge,
+ *                              internal  horizontal edge }
+ * [in]	pThresholds		AArray of size  8x2 of Thresholds (TC0) (values for the left or
+ *                               above edge of each 4x2 or 2x4 block, arranged in  vertical block order
+ *                               and then in  horizontal block order)
+ * [in]	pBS				array of size 16x2 of BS parameters (arranged in scan block order for vertical edges and then horizontal edges);
+ *                         valid in the range [0,4] with the following restrictions: i) pBS[i]== 4 may occur only for 0<=i<=3, ii) pBS[i]== 4 if and only if pBS[i^1]== 4.  Must be 4-byte aligned.
+ * [out]	pSrcDst		pointer to filtered output macroblock
+ *
+ * Return Value:
+ * OMX_Sts_NoErr - no error
+ * OMX_Sts_BadArgErr - bad arguments
+ *   - Either of the pointers in pSrcDst, pAlpha, pBeta, pTresholds, or pBS is NULL.
+ *   - pSrcDst is not 8-byte aligned.
+ *   - either pThresholds or pBS is not 4-byte aligned.
+ *   - pBS is out of range, i.e., one of the following conditions is true: pBS[i]<0, pBS[i]>4, pBS[i]==4 for i>=4, or (pBS[i]==4 && pBS[i^1]!=4) for 0<=i<=3.
+ *   - srcdstStep is not a multiple of 8.
+ *
+ */
+OMXResult omxVCM4P10_DeblockChroma_I(
+	OMX_U8* pSrcDst, 
+	OMX_S32 srcdstStep, 
+	const OMX_U8* pAlpha, 
+	const OMX_U8* pBeta, 
+	const OMX_U8* pThresholds,
+    const OMX_U8 *pBS
+)
+{
+    OMXResult errorCode;
+    
+    armRetArgErrIf(pSrcDst == NULL,                 OMX_Sts_BadArgErr);
+    armRetArgErrIf(armNot8ByteAligned(pSrcDst),     OMX_Sts_BadArgErr);
+    armRetArgErrIf(srcdstStep & 7,                  OMX_Sts_BadArgErr);
+    armRetArgErrIf(pAlpha == NULL,                  OMX_Sts_BadArgErr);
+    armRetArgErrIf(pBeta == NULL,                   OMX_Sts_BadArgErr);
+    armRetArgErrIf(pThresholds == NULL,             OMX_Sts_BadArgErr);
+    armRetArgErrIf(armNot4ByteAligned(pThresholds), OMX_Sts_BadArgErr);
+    armRetArgErrIf(pBS == NULL,                     OMX_Sts_BadArgErr);
+    armRetArgErrIf(armNot4ByteAligned(pBS),         OMX_Sts_BadArgErr);
+
+    errorCode = omxVCM4P10_FilterDeblockingChroma_VerEdge_I(
+        pSrcDst, srcdstStep, pAlpha, pBeta, pThresholds, pBS);
+
+    armRetArgErrIf(errorCode != OMX_Sts_NoErr, errorCode)
+    
+    errorCode = omxVCM4P10_FilterDeblockingChroma_HorEdge_I(
+        pSrcDst, srcdstStep, pAlpha+2, pBeta+2, pThresholds+8, pBS+16);
+
+    return errorCode;
+}
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_DeblockLuma_I.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_DeblockLuma_I.c
new file mode 100644
index 0000000..60238622
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_DeblockLuma_I.c
@@ -0,0 +1,91 @@
+/* ----------------------------------------------------------------
+ *
+ * 
+ * File Name:  omxVCM4P10_DeblockLuma_I.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * H.264 luma deblock
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+ 
+
+/**
+ * Function: omxVCM4P10_DeblockLuma_I
+ *
+ * Description:
+ * This function performs deblock filtering the horizontal and vertical edges of a luma macroblock
+ *(16x16).
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	pSrcDst         pointer to the input macroblock. Must be 8-byte aligned.
+ * [in]	srcdstStep      image width
+ * [in]	pAlpha          pointer to a 2x2 table of alpha thresholds, organized as follows: { external
+ *                             vertical edge, internal vertical edge, external horizontal
+ *                             edge, internal horizontal edge }
+ * [in]	pBeta			pointer to a 2x2 table of beta thresholds, organized as follows: { external
+ *                              vertical edge, internal vertical edge, external  horizontal edge,
+ *                              internal  horizontal edge }
+ * [in]	pThresholds		pointer to a 16x2 table of threshold (TC0), organized as follows: { values for
+ *                              the  left or above edge of each 4x4 block, arranged in  vertical block order
+ *                              and then in horizontal block order)
+ * [in]	pBS				 pointer to a 16x2 table of BS parameters arranged in scan block order for vertical edges and then horizontal edges;
+ *                               valid in the range [0,4] with the following restrictions: i) pBS[i]== 4 may occur only for 0<=i<=3, ii) pBS[i]== 4 if and only if pBS[i^1]== 4.  Must be 4-byte aligned.
+ * [out]	pSrcDst		pointer to filtered output macroblock.
+ *
+ * Return Value:
+ * OMX_Sts_NoErr - no error
+ * OMX_Sts_BadArgErr - bad arguments
+ *    - Either of the pointers in pSrcDst, pAlpha, pBeta, pTresholds or pBS is NULL.
+ *    - pSrcDst is not 8-byte aligned.
+ *    - srcdstStep is not a multiple of 8
+ *    - pBS is out of range, i.e., one of the following conditions is true: pBS[i]<0, pBS[i]>4, pBS[i]==4 for i>=4, or (pBS[i]==4 && pBS[i^1]!=4) for 0<=i<=3.
+.
+ *
+ */
+
+OMXResult omxVCM4P10_DeblockLuma_I(
+	OMX_U8* pSrcDst, 
+	OMX_S32 srcdstStep, 
+	const OMX_U8* pAlpha, 
+	const OMX_U8* pBeta, 
+	const OMX_U8* pThresholds, 
+	const OMX_U8 *pBS
+)
+{
+    OMXResult errorCode;
+    
+    armRetArgErrIf(pSrcDst == NULL,             OMX_Sts_BadArgErr);
+    armRetArgErrIf(armNot8ByteAligned(pSrcDst), OMX_Sts_BadArgErr);
+    armRetArgErrIf(srcdstStep & 7,              OMX_Sts_BadArgErr);    
+    armRetArgErrIf(pAlpha == NULL,              OMX_Sts_BadArgErr);
+    armRetArgErrIf(pBeta == NULL,               OMX_Sts_BadArgErr);
+    armRetArgErrIf(pThresholds == NULL,         OMX_Sts_BadArgErr);
+    armRetArgErrIf(armNot4ByteAligned(pThresholds), OMX_Sts_BadArgErr);
+    armRetArgErrIf(pBS == NULL,                     OMX_Sts_BadArgErr);
+    armRetArgErrIf(armNot4ByteAligned(pBS),         OMX_Sts_BadArgErr);
+
+    errorCode = omxVCM4P10_FilterDeblockingLuma_VerEdge_I(
+        pSrcDst, srcdstStep, pAlpha, pBeta, pThresholds, pBS);
+
+    armRetArgErrIf(errorCode != OMX_Sts_NoErr, errorCode)
+    
+    errorCode = omxVCM4P10_FilterDeblockingLuma_HorEdge_I(
+        pSrcDst, srcdstStep, pAlpha+2, pBeta+2, pThresholds+16, pBS+16);
+
+    return errorCode;
+}
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_DecodeChromaDcCoeffsToPairCAVLC.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_DecodeChromaDcCoeffsToPairCAVLC.c
new file mode 100644
index 0000000..a19f277
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_DecodeChromaDcCoeffsToPairCAVLC.c
@@ -0,0 +1,62 @@
+/* ----------------------------------------------------------------
+ *
+ * 
+ * File Name:  omxVCM4P10_DecodeChromaDcCoeffsToPairCAVLC.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * H.264 decode coefficients module
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+
+/**
+ * Function: omxVCM4P10_DecodeChromaDcCoeffsToPairCAVLC
+ *
+ * Description:
+ * Performs CAVLC decoding and inverse raster scan for 2x2 block of 
+ * ChromaDCLevel. The decoded coefficients in packed position-coefficient 
+ * buffer are stored in increasing raster scan order, namely position order.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	ppBitStream		Double pointer to current byte in bit stream
+ *								buffer
+ * [in]	pOffset			Pointer to current bit position in the byte 
+ *								pointed to by *ppBitStream
+ * [out]	ppBitStream		*ppBitStream is updated after each block is decoded
+ * [out]	pOffset			*pOffset is updated after each block is decoded
+ * [out]	pNumCoeff		Pointer to the number of nonzero coefficients
+ *								in this block
+ * [out]	ppPosCoefbuf	Double pointer to destination residual
+ *								coefficient-position pair buffer
+ *
+ * Return Value:
+ * Standard omxError result. See enumeration for possible result codes.
+ *
+ */
+
+OMXResult omxVCM4P10_DecodeChromaDcCoeffsToPairCAVLC (
+     const OMX_U8** ppBitStream,
+     OMX_S32* pOffset,
+     OMX_U8* pNumCoeff,
+     OMX_U8** ppPosCoefbuf        
+ )
+
+{
+    return armVCM4P10_DecodeCoeffsToPair(ppBitStream, pOffset, pNumCoeff,
+                                         ppPosCoefbuf, 17, 4);
+
+}
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_DecodeCoeffsToPairCAVLC.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_DecodeCoeffsToPairCAVLC.c
new file mode 100644
index 0000000..99bb4ce
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_DecodeCoeffsToPairCAVLC.c
@@ -0,0 +1,68 @@
+/* ----------------------------------------------------------------
+ *
+ * 
+ * File Name:  omxVCM4P10_DecodeCoeffsToPairCAVLC.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * H.264 decode coefficients module
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+
+/**
+ * Function: omxVCM4P10_DecodeCoeffsToPairCAVLC
+ *
+ * Description:
+ * Performs CAVLC decoding and inverse zigzag scan for 4x4 block of 
+ * Intra16x16DCLevel, Intra16x16ACLevel,LumaLevel, and ChromaACLevel. 
+ * Inverse field scan is not supported. The decoded coefficients in packed 
+ * position-coefficient buffer are stored in increasing zigzag order instead 
+ * of position order.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	ppBitStream		Double pointer to current byte in bit stream buffer
+ * [in]	pOffset			Pointer to current bit position in the byte pointed
+ *								to by *ppBitStream
+ * [in]	sMaxNumCoeff	Maximum number of non-zero coefficients in current
+ *								block
+ * [in]	sVLCSelect		VLC table selector, obtained from number of non-zero
+ *								AC coefficients of above and left 4x4 blocks. It is 
+ *								equivalent to the variable nC described in H.264 standard 
+ *								table 9-5, except its value can¡¯t be less than zero.
+ * [out]	ppBitStream		*ppBitStream is updated after each block is decoded
+ * [out]	pOffset			*pOffset is updated after each block is decoded
+ * [out]	pNumCoeff		Pointer to the number of nonzero coefficients in
+ *								this block
+ * [out]	ppPosCoefbuf	Double pointer to destination residual
+ *								coefficient-position pair buffer
+ * Return Value:
+ * Standard omxError result. See enumeration for possible result codes.
+ *
+ */
+
+OMXResult omxVCM4P10_DecodeCoeffsToPairCAVLC(
+     const OMX_U8** ppBitStream,
+     OMX_S32* pOffset,
+     OMX_U8* pNumCoeff,
+     OMX_U8**ppPosCoefbuf,
+     OMX_INT sVLCSelect,
+     OMX_INT sMaxNumCoeff        
+ )
+{
+    return armVCM4P10_DecodeCoeffsToPair(ppBitStream, pOffset, pNumCoeff,
+                                         ppPosCoefbuf, sVLCSelect, sMaxNumCoeff);
+}
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_DequantTransformResidualFromPairAndAdd_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_DequantTransformResidualFromPairAndAdd_s.s
new file mode 100644
index 0000000..2b71486
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_DequantTransformResidualFromPairAndAdd_s.s
@@ -0,0 +1,480 @@
+;//
+;// (c) Copyright 2007 ARM Limited. All Rights Reserved.
+;//
+;// Description:
+;// H.264 inverse quantize and transform module
+;// 
+;// 
+
+        
+
+;// Include standard headers
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+        
+;// Import symbols required from other files
+;// (For example tables)
+    
+        IMPORT armVCM4P10_UnpackBlock4x4
+        IMPORT armVCM4P10_TransformResidual4x4
+        IMPORT armVCM4P10_QPDivTable
+        IMPORT armVCM4P10_VMatrixU16
+        IMPORT armVCM4P10_QPModuloTable 
+        
+    M_VARIANTS ARM1136JS, ARM1136JS_U
+        
+;// Set debugging level        
+;//DEBUG_ON    SETL {TRUE}
+
+
+;// Static Function: armVCM4P10_DequantLumaAC4x4
+
+;// Guarding implementation by the processor name
+    
+    IF  ARM1136JS 
+    
+;//Input Registers
+pSrcDst       RN  0
+QP            RN  1
+
+
+;//Output Registers
+
+
+;//Local Scratch Registers
+pQPdiv          RN  4
+pQPmod          RN  5
+pVRow           RN  2
+QPmod           RN  6
+shift           RN  3
+rowLuma01       RN  1
+rowLuma23       RN  4
+
+SrcDst00        RN  5
+SrcDst02        RN  6
+SrcDst10        RN  7
+SrcDst12        RN  8
+SrcDst20        RN  9
+SrcDst22        RN  10
+SrcDst30        RN  11
+SrcDst32        RN  12
+
+temp1           RN  2
+temp2           RN  3
+temp3           RN  14
+    
+    
+        ;// Allocate stack memory required by the function
+        
+        ;// Write function header
+        M_START armVCM4P10_DequantLumaAC4x4,r11
+         
+        LDR    pQPmod,=armVCM4P10_QPModuloTable
+        LDR    pQPdiv,=armVCM4P10_QPDivTable        
+        LDR    pVRow,=armVCM4P10_VMatrixU16
+         
+        LDRSB  QPmod,[pQPmod,QP]                    ;// (QP%6) * 6
+        LDRSB  shift,[pQPdiv,QP]                    ;// Shift = QP / 6
+                
+        LDRH    rowLuma01,[pVRow,QPmod]!             ;// rowLuma01 = [00|0a]
+        LDRH    temp3,[pVRow,#2]                     ;// temp3     = [00|0b]   
+        LDRH    rowLuma23,[pVRow,#4]                 ;// rowLuma23 = [00|0c] 
+        ORR     rowLuma01,rowLuma01,temp3,LSL #16    ;// rowLuma01 = [0b|0a]   
+        
+        ;// Load all the 16 'src' values
+        LDMIA   pSrcDst,{SrcDst00,SrcDst02,SrcDst10,SrcDst12,SrcDst20,SrcDst22,SrcDst30,SrcDst32}
+        
+        
+        ;//*********************************************************************************************
+        ;//
+        ;// 'Shift' ranges between [0,8] 
+        ;// So we can shift the packed rowLuma values [0b|0a] with a single LSL operation
+        ;//
+        ;//*********************************************************************************************
+        
+        LSL    rowLuma01,rowLuma01,shift
+        LSL    rowLuma23,rowLuma23,shift
+        
+        
+        ;//**********************************************************************************************
+        ;//
+        ;// The idea is to unroll the Loop completely
+        ;// All the 16 src values are loaded at once into 8 registers : SrcDst<y><x> (above)
+        ;// 0<= armVCM4P10_PosToVCol4x4[i] <=2 for any 'i<16' 
+        ;// So the only values of pVRow[i] that need to be loaded are for i=0,1,2
+        ;// These 3 values are loaded into rowLuma01 and rowLuma23 (above)
+        ;// We first calculate pVRow[armVCM4P10_PosToVCol4x4[i]]) << Shift which fits into 16 bits (above)
+        ;// Then the product pSrcDst[i] * (pVRow[armVCM4P10_PosToVCol4x4[i]] << Shift) is calculated
+        ;// Here we interleave the PKHBT operations for various rows  to avoide pipeline stalls
+        ;// 
+        ;// We then pack the two 16 bit multiplication result into a word and store at one go
+        ;//
+        ;//**********************************************************************************************
+        
+        
+        ;// Row 1
+        
+        
+        SMULTB  temp1,SrcDst00,rowLuma23                    ;// pSrcDst[1] * (pVRow[2]<<Shift) 
+        SMULBB  SrcDst00,SrcDst00,rowLuma01                 ;// pSrcDst[0] * (pVRow[0]<<Shift)  
+        
+        SMULTB  temp2,SrcDst02,rowLuma23                    ;// pSrcDst[3] * (pVRow[2]<<Shift) 
+        SMULBB  SrcDst02,SrcDst02,rowLuma01                 ;// pSrcDst[2] * (pVRow[0]<<Shift)
+        
+        PKHBT   SrcDst00,SrcDst00,temp1,LSL #16             ;// Pack the first two product values
+        
+                
+        ;// Row 2
+        SMULTT  temp1,SrcDst10,rowLuma01                    ;// pSrcDst[5] * (pVRow[1]<<Shift)
+        SMULBB  SrcDst10,SrcDst10,rowLuma23                 ;// pSrcDst[4] * (pVRow[2]<<Shift)
+        
+        PKHBT   SrcDst02,SrcDst02,temp2,LSL #16             ;// Pack the next two product values
+        SMULTT  temp2,SrcDst12,rowLuma01                    ;// pSrcDst[7] * (pVRow[1]<<Shift)
+        SMULBB  SrcDst12,SrcDst12,rowLuma23                    ;// pSrcDst[6] * (pVRow[2]<<Shift)
+        
+        PKHBT   SrcDst10,SrcDst10,temp1,LSL #16             ;// Pack the next two product values
+        
+               
+        ;// Row 3    
+        
+        SMULTB  temp1,SrcDst20,rowLuma23                    ;// pSrcDst[9] * (pVRow[2]<<Shift)         
+        SMULBB  SrcDst20,SrcDst20,rowLuma01                    ;// pSrcDst[8] * (pVRow[0]<<Shift)  
+       
+        PKHBT   SrcDst12,SrcDst12,temp2,LSL #16               ;// Pack the next two product values
+        SMULTB  temp2,SrcDst22,rowLuma23                    ;// pSrcDst[11] * (pVRow[2]<<Shift) 
+        SMULBB  SrcDst22,SrcDst22,rowLuma01                    ;// pSrcDst[10] * (pVRow[0]<<Shift)
+                                                            
+        PKHBT   SrcDst20,SrcDst20,temp1,LSL #16             ;// Pack the next two product values
+        
+        
+                        
+        ;// Row 4   
+        
+        SMULTT  temp1,SrcDst30,rowLuma01                    ;// pSrcDst[13] * (pVRow[1]<<Shift)
+        SMULBB  SrcDst30,SrcDst30,rowLuma23                    ;// pSrcDst[12] * (pVRow[2]<<Shift)
+        
+        SMULTT  temp3,SrcDst32,rowLuma01                    ;// pSrcDst[15] * (pVRow[1]<<Shift)
+        SMULBB  SrcDst32,SrcDst32,rowLuma23                    ;// pSrcDst[14] * (pVRow[2]<<Shift)
+       
+        PKHBT   SrcDst22,SrcDst22,temp2,LSL #16             ;// Pack the remaining product values
+        PKHBT   SrcDst30,SrcDst30,temp1,LSL #16
+        PKHBT   SrcDst32,SrcDst32,temp3,LSL #16
+        
+        
+        STMIA   pSrcDst,{SrcDst00,SrcDst02,SrcDst10,SrcDst12,SrcDst20,SrcDst22,SrcDst30,SrcDst32}
+        
+        
+        ;// Set return value
+          
+           
+      
+        ;// Write function tail
+        M_END
+        
+    ENDIF                                                    ;//ARM1136JS        
+ 
+
+;// Guarding implementation by the processor name
+    
+    IF  ARM1136JS_U
+    
+;//Input Registers
+pSrcDst       RN  0
+QP            RN  1
+
+
+;//Output Registers
+
+
+;//Local Scratch Registers
+pQPdiv          RN  4
+pQPmod          RN  5
+pVRow           RN  2
+QPmod           RN  6
+shift           RN  3
+rowLuma01       RN  1
+rowLuma23       RN  4
+
+SrcDst00        RN  5
+SrcDst02        RN  6
+SrcDst10        RN  7
+SrcDst12        RN  8
+SrcDst20        RN  9
+SrcDst22        RN  10
+SrcDst30        RN  11
+SrcDst32        RN  12
+
+temp1           RN  2
+temp2           RN  3
+temp3           RN  14
+    
+    
+        ;// Allocate stack memory required by the function
+        
+        ;// Write function header
+        M_START armVCM4P10_DequantLumaAC4x4,r11
+         
+        LDR    pQPmod,=armVCM4P10_QPModuloTable
+        LDR    pQPdiv,=armVCM4P10_QPDivTable        
+        LDR    pVRow,=armVCM4P10_VMatrixU16
+         
+        LDRSB  QPmod,[pQPmod,QP]                    ;// (QP%6) * 6
+        LDRSB  shift,[pQPdiv,QP]                    ;// Shift = QP / 6
+                
+        LDR    rowLuma01,[pVRow,QPmod]!             ;// rowLuma01 = [0b|0a]
+        LDR    rowLuma23,[pVRow,#4]                 ;// rowLuma23 = [0d|0c]    
+
+        ;// Load all the 16 'src' values
+        LDMIA   pSrcDst,{SrcDst00,SrcDst02,SrcDst10,SrcDst12,SrcDst20,SrcDst22,SrcDst30,SrcDst32}
+        
+        
+        ;//*********************************************************************************************
+        ;//
+        ;// 'Shift' ranges between [0,8] 
+        ;// So we can shift the packed rowLuma values [0b|0a] with a single LSL operation
+        ;//
+        ;//*********************************************************************************************
+        
+        LSL    rowLuma01,rowLuma01,shift
+        LSL    rowLuma23,rowLuma23,shift
+        
+        
+        ;//**********************************************************************************************
+        ;//
+        ;// The idea is to unroll the Loop completely
+        ;// All the 16 src values are loaded at once into 8 registers : SrcDst<y><x> (above)
+        ;// 0<= armVCM4P10_PosToVCol4x4[i] <=2 for any 'i<16' 
+        ;// So the only values of pVRow[i] that need to be loaded are for i=0,1,2
+        ;// These 3 values are loaded into rowLuma01 and rowLuma23 (above)
+        ;// We first calculate pVRow[armVCM4P10_PosToVCol4x4[i]]) << Shift which fits into 16 bits (above)
+        ;// Then the product pSrcDst[i] * (pVRow[armVCM4P10_PosToVCol4x4[i]] << Shift) is calculated
+        ;// Here we interleave the PKHBT operations for various rows  to avoide pipeline stalls
+        ;// 
+        ;// We then pack the two 16 bit multiplication result into a word and store at one go
+        ;//
+        ;//**********************************************************************************************
+        
+        
+        ;// Row 1
+        
+        
+        SMULTB  temp1,SrcDst00,rowLuma23                    ;// pSrcDst[1] * (pVRow[2]<<Shift) 
+        SMULBB  SrcDst00,SrcDst00,rowLuma01                 ;// pSrcDst[0] * (pVRow[0]<<Shift)  
+        
+        SMULTB  temp2,SrcDst02,rowLuma23                    ;// pSrcDst[3] * (pVRow[2]<<Shift) 
+        SMULBB  SrcDst02,SrcDst02,rowLuma01                 ;// pSrcDst[2] * (pVRow[0]<<Shift)
+        
+        PKHBT   SrcDst00,SrcDst00,temp1,LSL #16             ;// Pack the first two product values
+        
+                
+        ;// Row 2
+        SMULTT  temp1,SrcDst10,rowLuma01                    ;// pSrcDst[5] * (pVRow[1]<<Shift)
+        SMULBB  SrcDst10,SrcDst10,rowLuma23                 ;// pSrcDst[4] * (pVRow[2]<<Shift)
+        
+        PKHBT   SrcDst02,SrcDst02,temp2,LSL #16             ;// Pack the next two product values
+        SMULTT  temp2,SrcDst12,rowLuma01                    ;// pSrcDst[7] * (pVRow[1]<<Shift)
+        SMULBB  SrcDst12,SrcDst12,rowLuma23                    ;// pSrcDst[6] * (pVRow[2]<<Shift)
+        
+        PKHBT   SrcDst10,SrcDst10,temp1,LSL #16             ;// Pack the next two product values
+        
+               
+        ;// Row 3    
+        
+        SMULTB  temp1,SrcDst20,rowLuma23                    ;// pSrcDst[9] * (pVRow[2]<<Shift)         
+        SMULBB  SrcDst20,SrcDst20,rowLuma01                    ;// pSrcDst[8] * (pVRow[0]<<Shift)  
+       
+        PKHBT   SrcDst12,SrcDst12,temp2,LSL #16               ;// Pack the next two product values
+        SMULTB  temp2,SrcDst22,rowLuma23                    ;// pSrcDst[11] * (pVRow[2]<<Shift) 
+        SMULBB  SrcDst22,SrcDst22,rowLuma01                    ;// pSrcDst[10] * (pVRow[0]<<Shift)
+                                                            
+        PKHBT   SrcDst20,SrcDst20,temp1,LSL #16             ;// Pack the next two product values
+        
+        
+                        
+        ;// Row 4   
+        
+        SMULTT  temp1,SrcDst30,rowLuma01                    ;// pSrcDst[13] * (pVRow[1]<<Shift)
+        SMULBB  SrcDst30,SrcDst30,rowLuma23                    ;// pSrcDst[12] * (pVRow[2]<<Shift)
+        
+        SMULTT  temp3,SrcDst32,rowLuma01                    ;// pSrcDst[15] * (pVRow[1]<<Shift)
+        SMULBB  SrcDst32,SrcDst32,rowLuma23                    ;// pSrcDst[14] * (pVRow[2]<<Shift)
+       
+        PKHBT   SrcDst22,SrcDst22,temp2,LSL #16             ;// Pack the remaining product values
+        PKHBT   SrcDst30,SrcDst30,temp1,LSL #16
+        PKHBT   SrcDst32,SrcDst32,temp3,LSL #16
+        
+        
+        STMIA   pSrcDst,{SrcDst00,SrcDst02,SrcDst10,SrcDst12,SrcDst20,SrcDst22,SrcDst30,SrcDst32}
+        
+        
+        ;// Set return value
+          
+           
+      
+        ;// Write function tail
+        M_END
+        
+    ENDIF                                                    ;//ARM1136JS_U        
+
+
+
+
+
+;// Function: omxVCM4P10_DequantTransformResidualFromPairAndAdd            
+    
+;// Guarding implementation by the processor name
+    
+    IF  ARM1136JS
+    
+;//Input Registers
+ppSrc       RN  0
+pPred       RN  1
+pDC         RN  2
+pDst        RN  3
+   
+
+;//Output Registers
+result      RN  0
+
+;//Local Scratch Registers
+pDelta      RN  4
+pDeltaTmp   RN  6
+AC          RN  5                   ;//Load from stack
+pPredTemp   RN  7
+pDCTemp     RN  8
+pDstTemp    RN  9
+pDeltaArg1  RN  1
+pDeltaArg0  RN  0
+QP          RN  1                   ;//Load from stack
+DCval       RN  10  
+DCvalCopy   RN  11
+predstep    RN  1
+dstStep     RN  10
+ycounter    RN  0
+PredVal1    RN  3
+PredVal2    RN  5
+DeltaVal1   RN  2
+DeltaVal2   RN  11
+PredVal     RN  8
+tmpDeltaVal RN  6
+sum1        RN  12
+sum2        RN  14
+    
+    
+           
+    ;// Allocate stack memory required by the function
+        M_ALLOC8 pBuffer, 32
+               
+
+    ;// Write function header
+        M_START omxVCM4P10_DequantTransformResidualFromPairAndAdd,r11
+        
+        ;// Define stack arguments
+        M_ARG   predStepOnStack, 4
+        M_ARG   dstStepOnStack,4
+        M_ARG   QPOnStack, 4
+        M_ARG   ACOnStack,4
+  
+        
+        M_ADR   pDelta,pBuffer 
+        M_LDR   AC,ACOnStack 
+        
+         
+        ;// Save registers r1,r2,r3 before function call    
+        MOV     pPredTemp,pPred
+        MOV     pDCTemp,pDC
+        MOV     pDstTemp,pDst
+        
+        CMP     AC,#0
+        BEQ     DCcase
+        MOV     pDeltaArg1,pDelta                           ;// Set up r1 for armVCM4P10_UnpackBlock4x4
+    
+        BL      armVCM4P10_UnpackBlock4x4
+    
+        M_LDR   QP,QPOnStack                                ;// Set up r1 for DequantLumaAC4x4
+        MOV     pDeltaArg0,pDelta                           ;// Set up r0 for DequantLumaAC4x4
+
+        BL      armVCM4P10_DequantLumaAC4x4
+        
+        
+        CMP     pDCTemp,#0
+        LDRSHNE DCval,[pDCTemp]
+        MOV     pDeltaArg0,pDelta                           ;// Set up r0 for armVCM4P10_TransformResidual4x4
+        MOV     pDeltaArg1,pDelta                           ;// Set up r1 for armVCM4P10_TransformResidual4x4
+        STRHNE  DCval,[pDelta]
+        
+        BL      armVCM4P10_TransformResidual4x4
+        B       OutDCcase 
+        
+
+DCcase
+        LDRSH   DCval,[pDCTemp] 
+        ADD     DCval,DCval,#32 
+        ASR     DCval,DCval,#6
+        PKHBT   DCval,DCval,DCval,LSL #16                  ;// Duplicating the Lower halfword
+        MOV     DCvalCopy, DCval                           ;// Needed for STRD
+        STRD    DCval, [pDelta, #0]                        ;// pDelta[0]  = pDelta[1]  = pDelta[2]  = pDelta[3] = DCval
+        STRD    DCval, [pDelta, #8]                        ;// pDelta[4]  = pDelta[5]  = pDelta[6]  = pDelta[7] = DCval
+        STRD    DCval, [pDelta, #16]                       ;// pDelta[8]  = pDelta[9]  = pDelta[10] = pDelta[11] = DCval
+        STRD    DCval, [pDelta, #24]   
+        
+               
+OutDCcase      
+        M_LDR   predstep,predStepOnStack
+        M_LDR   dstStep,dstStepOnStack
+        
+        LDMIA   pDelta!,{tmpDeltaVal,DeltaVal2}             ;// Pre load
+        MOV     ycounter,#4                                 ;// Counter for the PredPlusDeltaLoop
+        LDR     PredVal,[pPredTemp]                         ;// Pre load
+
+PredPlusDeltaLoop
+        
+       
+        SUBS    ycounter,ycounter,#1
+        ADD     pPredTemp,pPredTemp,predstep                ;// Increment pPred ptr
+        
+        PKHBT   DeltaVal1,tmpDeltaVal,DeltaVal2,LSL #16     ;// Deltaval1 = [C A]   
+        PKHTB   DeltaVal2,DeltaVal2,tmpDeltaVal,ASR #16     ;// DeltaVal2 = [D B]
+        
+        UXTB16  PredVal1,PredVal                            ;// PredVal1 = [0c0a]
+        UXTB16  PredVal2,PredVal,ROR #8                     ;// PredVal2 = [0d0b]
+        
+        LDRGT   PredVal,[pPredTemp]                         ;// Pre load
+        
+        QADD16  sum2,DeltaVal2,PredVal2                     ;// Add and saturate to 16 bits
+        QADD16  sum1,DeltaVal1,PredVal1
+        
+        USAT16  sum2,#8,sum2                                ;// armClip(0,255,sum2)
+        USAT16  sum1,#8,sum1
+        
+        LDMGTIA   pDelta!,{tmpDeltaVal,DeltaVal2}           ;// Pre load
+          
+        ORR     sum1,sum1,sum2,LSL #8                       ;// sum1 = [dcba]
+        STR     sum1,[pDstTemp]
+        
+        ADD     pDstTemp,pDstTemp,dstStep                   ;// Increment pDst ptr
+        BGT     PredPlusDeltaLoop  
+        
+        
+        ;// Set return value
+        MOV     result,#OMX_Sts_NoErr
+        
+End                
+
+        
+        ;// Write function tail
+        
+        M_END
+        
+    ENDIF                                                    ;//ARM1136JS   
+    
+    
+;// Function: omxVCM4P10_DequantTransformResidualFromPairAndAdd            
+    
+;// Guarding implementation by the processor name
+    
+    
+         
+            
+    END
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_FilterDeblockingChroma_HorEdge_I_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_FilterDeblockingChroma_HorEdge_I_s.s
new file mode 100644
index 0000000..6d960f0f
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_FilterDeblockingChroma_HorEdge_I_s.s
@@ -0,0 +1,336 @@
+;//
+;// 
+;// File Name:  omxVCM4P10_FilterDeblockingChroma_HorEdge_I_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   9641
+;// Date:       Thursday, February 7, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+
+        M_VARIANTS ARM1136JS
+
+        
+        IF ARM1136JS
+        
+MASK_0      EQU 0x00000000   
+MASK_1      EQU 0x01010101
+LOOP_COUNT  EQU 0x50000000
+
+;// Declare input registers
+
+pSrcDst     RN 0
+srcdstStep  RN 1
+pAlphaArg   RN 2
+pBetaArg    RN 3
+
+pThresholds RN 6
+pBS         RN 9
+pQ0         RN 0
+bS          RN 10
+
+alpha       RN 6
+alpha0      RN 6
+alpha1      RN 8
+
+beta        RN 7
+beta0       RN 7
+beta1       RN 9
+
+;// Declare Local/Temporary variables
+
+;// Pixels
+p_0         RN 3  
+p_1         RN 5  
+q_0         RN 8  
+q_1         RN 9  
+
+;// Filtering
+
+dp0q0       RN 12
+dp1p0       RN 12
+dq1q0       RN 12
+
+ap0q0       RN 4  
+filt        RN 2
+        
+m00         RN 14
+m01         RN 11
+            
+pQ0         RN 0
+Step        RN 1
+            
+;// Output
+            
+P_0         RN 6
+Q_0         RN 7 
+
+;//Declarations for bSLT4 kernel
+
+tC          RN 12
+tC0         RN 5
+tC1         RN 12
+pos         RN 5
+neg         RN 9
+
+;//Declarations for bSGE4 kernel
+
+
+;// Miscellanous
+XY          RN 8
+
+a           RN 10
+t1          RN 10
+t2          RN 12
+t3          RN 14
+t4          RN 6
+t5          RN 5
+
+        
+        ;// Allocate stack memory 
+        M_ALLOC4 ppThresholds,4
+        M_ALLOC8 pAlphaBeta0,8
+        M_ALLOC8 pAlphaBeta1,8
+        M_ALLOC8 pXYBS,4
+        M_ALLOC4 ppBS,4
+        
+        ;// Function header
+        M_START omxVCM4P10_FilterDeblockingChroma_HorEdge_I, r11
+        
+        ;//Input arguments on the stack
+        M_ARG   ppThresholdsArg, 4
+        M_ARG   ppBSArg, 4
+        
+        LDRB    alpha1, [pAlphaArg,#1]
+        LDRB    beta1,  [pBetaArg,#1]
+        M_LDR   pThresholds, ppThresholdsArg
+        LDR     a,=MASK_1
+        LDRB    beta0,  [pBetaArg]
+        M_STR   pThresholds, ppThresholds
+        LDRB    alpha0, [pAlphaArg]
+
+        MUL     alpha1, alpha1, a
+        MUL     beta1, beta1, a
+        MUL     alpha0, alpha0, a
+        MUL     beta0, beta0, a
+
+        M_STRD  alpha1, beta1, pAlphaBeta1
+        M_LDR   pBS, ppBSArg
+        M_STRD  alpha0, beta0, pAlphaBeta0
+
+        LDR     XY,=LOOP_COUNT
+        M_STRD  XY, pBS, pXYBS
+
+        SUB     pQ0, pQ0, srcdstStep, LSL #1
+LoopY
+LoopX
+;//---------------Load Pixels-------------------
+        LDRH    bS, [pBS], #2
+        
+        M_STR   pBS, ppBS
+        M_LDR   p_1, [pQ0],srcdstStep
+
+        CMP     bS, #0
+        
+        M_LDR   p_0, [pQ0],srcdstStep
+        M_LDR   q_0, [pQ0],srcdstStep
+        M_LDR   q_1, [pQ0]
+        LDR     m01, =MASK_1                ;//  01010101 mask 
+        BEQ     NoFilterBS0
+
+        
+        ;// p_0 = [r3p0 r2p0 r1p0 r0p0]
+        ;// p_1 = [r3p1 r2p1 r1p1 r0p1]
+        ;// q_0 = [r3q0 r2q0 r1q0 r0q0]
+        ;// q_1 = [r3q1 r2q1 r1q1 r0q1]
+
+;//--------------Filtering Decision -------------------
+        MOV     m00, #MASK_0                ;//  00000000 mask 
+
+        MOV     filt, m01
+        TST     bS, #0xff00
+        MOVEQ   filt, filt, LSR #16
+        TST     bS, #0xff
+        MOVEQ   filt, filt, LSL #16
+        TST     bS, #4
+
+        
+        ;// Check |p0-q0|<Alpha 
+        USUB8   dp0q0, p_0, q_0 
+        USUB8   a, q_0, p_0
+        SEL     ap0q0, a, dp0q0
+        USUB8   a, ap0q0, alpha
+        SEL     filt, m00, filt
+                
+        ;// Check |p1-p0|<Beta 
+        USUB8   dp1p0, p_1, p_0
+        USUB8   a, p_0, p_1
+        SEL     a, a, dp1p0
+        USUB8   a, a, beta
+        SEL     filt, m00, filt
+
+        ;// Check |q1-q0|<Beta 
+        USUB8   dq1q0, q_1, q_0
+        USUB8   a, q_0, q_1
+        SEL     a, a, dq1q0
+        USUB8   a, a, beta
+        SEL     filt, m00, filt
+
+        BEQ     bSLT4        
+;//-------------------Filter--------------------
+bSGE4        
+        ;//---------bSGE4 Execution---------------
+        CMP     filt, #0
+
+        M_LDR   pThresholds, ppThresholds
+
+        ;// Compute P0b
+        UHADD8  t1, p_0, q_1
+        BEQ     NoFilterFilt0
+        MVN     t2, p_1
+        UHSUB8  t1, t1, t2
+        USUB8   t2, filt, m01
+        EOR     t1, t1, m01, LSL #7
+
+        ADD     pThresholds,pThresholds, #2
+        
+        ;// Compute Q0b 
+        UHADD8  t2, q_0, p_1
+        MVN     t3, q_1
+        UHSUB8  t2, t2, t3
+        M_STR   pThresholds, ppThresholds
+        SEL     P_0, t1, p_0
+        EOR     t2, t2, m01, LSL #7
+        SEL     Q_0, t2, q_0
+
+        SUB     pQ0, pQ0, srcdstStep, LSL #1
+        B       StoreResultAndExit
+
+;//---------- Exit of LoopX --------------
+;//---- for the case of no filtering -----
+
+NoFilterFilt0
+NoFilterBS0
+        M_LDR   pThresholds, ppThresholds
+        SUB     pQ0, pQ0, srcdstStep, LSL #1
+        SUB     pQ0, pQ0, srcdstStep
+        ADD     pQ0, pQ0, #4
+        ADD     pThresholds, pThresholds, #2
+
+        ;// Load counter for LoopX
+        M_LDRD  XY, pBS, pXYBS
+        M_STR   pThresholds, ppThresholds
+        M_LDRD  alpha, beta, pAlphaBeta0
+
+        ;// Align the pointer
+        ADDS    XY, XY, XY
+        M_STR   XY, pXYBS
+        BCC     LoopY
+        B       ExitLoopY
+        
+bSLT4         
+        ;//---------bSLT4 Execution---------------
+        M_LDR   pThresholds, ppThresholds
+        CMP     filt, #0
+        
+        ;// Since beta <= 18 and alpha <= 255 we know
+        ;// -254 <= p0-q0 <= 254
+        ;//  -17 <= q1-q0 <= 17
+        ;//  -17 <= p1-p0 <= 17
+
+        ;// delta = Clip3( -tC, tC, ((((q0-p0)<<2) + (p1-q1) + 4)>>3))
+        ;// 
+        ;//    Calculate A = (((q0-p0)<<2) + (p1-q1) + 4)>>3
+        ;//                = (4*q0 - 4*p0 + p1 - q1 + 4)>>3
+        ;//                = ((p1-p0) - (q1-q0) - 3*(p0-q0) + 4)>>3
+
+        USUB8   t1, p_1, p_0
+        USUB8   t2, q_1, q_0
+        BEQ     NoFilterFilt0
+        
+        LDRB    tC0, [pThresholds],#1
+        SSUB8   t1, t1, t2
+        LDRB    tC1, [pThresholds],#1
+        M_STR   pThresholds, ppThresholds
+        UHSUB8  t4, p_0, q_0
+        ORR     tC, tC0, tC1, LSL #16
+        USUB8   t5, p_0, q_0
+        AND     t5, t5, m01
+        SHSUB8  t1, t1, t5
+        ORR     tC, tC, LSL #8        
+        SSUB8   t1, t1, t5
+        SHSUB8  t1, t1, t4
+        UQADD8  tC, tC, m01
+        SADD8   t1, t1, m01
+        USUB8   t5, filt, m01   
+        SHSUB8  t1, t1, t4
+        SEL     tC, tC, m00
+
+        ;// Split into positive and negative part and clip 
+
+        SSUB8   t1, t1, m00
+        SEL     pos, t1, m00
+        USUB8   neg, pos, t1
+        USUB8   t3, pos, tC
+        SEL     pos, tC, pos
+        USUB8   t3, neg, tC
+        SEL     neg, tC, neg
+        UQADD8  P_0, p_0, pos
+        UQSUB8  Q_0, q_0, pos
+        UQSUB8  P_0, P_0, neg
+        UQADD8  Q_0, Q_0, neg
+        
+        SUB     pQ0, pQ0, srcdstStep, LSL #1
+
+        ;// Choose to store the filtered
+        ;// value or the original pixel
+        USUB8   t1, filt, m01    
+        SEL     P_0, P_0, p_0
+        SEL     Q_0, Q_0, q_0
+    
+StoreResultAndExit
+
+        ;//---------Store result---------------
+
+        ;// P_0 = [r0p0 r1p0 r2p0 r3p0]
+        ;// Q_0 = [r0q0 r1q0 r2q0 r3q0]
+
+        M_STR   P_0, [pQ0], srcdstStep
+        STR     Q_0, [pQ0], #4
+
+        M_LDRD  XY, pBS, pXYBS
+        M_LDRD  alpha, beta, pAlphaBeta0
+
+        SUB     pQ0, pQ0, srcdstStep, LSL #1
+
+        ADDS    XY, XY, XY
+        M_STR   XY, pXYBS
+        BCC     LoopX
+
+;//-------- Common Exit of LoopY -----------------
+        ;// Align the pointers 
+
+ExitLoopY
+        ADD     pBS, pBS, #4
+        M_LDRD  alpha, beta, pAlphaBeta1
+        SUB     pQ0, pQ0, #8
+        ADD     pQ0, pQ0, srcdstStep, LSL #2
+        M_STRD  alpha, beta, pAlphaBeta0
+
+        BNE     LoopY
+        MOV     r0, #OMX_Sts_NoErr
+
+;//-----------------End Filter--------------------
+        M_END
+
+    ENDIF        
+
+        END
+        
+        
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_FilterDeblockingChroma_VerEdge_I_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_FilterDeblockingChroma_VerEdge_I_s.s
new file mode 100644
index 0000000..00c8354
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_FilterDeblockingChroma_VerEdge_I_s.s
@@ -0,0 +1,437 @@
+;//
+;// 
+;// File Name:  omxVCM4P10_FilterDeblockingChroma_VerEdge_I_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   9641
+;// Date:       Thursday, February 7, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+
+        M_VARIANTS ARM1136JS
+
+
+        IF ARM1136JS
+        
+        
+MASK_0      EQU 0x00000000   
+MASK_1      EQU 0x01010101
+MASK_2      EQU 0x0000ff00
+LOOP_COUNT  EQU 0x50000000
+
+;// Declare input registers
+
+pSrcDst     RN 0
+srcdstStep  RN 1
+pAlphaArg   RN 2
+pBetaArg    RN 3
+
+pThresholds RN 6
+pBS         RN 9
+pQ0         RN 0
+bS          RN 2
+bSTemp      RN 10
+
+alpha       RN 6
+alpha0      RN 6
+alpha1      RN 8
+
+beta        RN 7
+beta0       RN 7
+beta1       RN 9
+
+;// Declare Local/Temporary variables
+
+;// Pixels
+p_0         RN 3  
+p_1         RN 5  
+q_0         RN 8  
+q_1         RN 9  
+
+;// Unpacking
+mask        RN 11 
+
+row0        RN 2
+row1        RN 4
+row2        RN 5
+row3        RN 3
+
+row4        RN 8
+row5        RN 9
+row6        RN 10
+row7        RN 12
+
+tunpk0      RN 2
+tunpk2      RN 10
+tunpk3      RN 12
+
+tunpk4      RN 4
+tunpk5      RN 5
+tunpk6      RN 14
+tunpk7      RN 2 
+
+;// Filtering
+
+dp0q0       RN 12
+dp1p0       RN 12
+dq1q0       RN 12
+
+ap0q0       RN 4  
+filt        RN 2
+        
+m00         RN 14
+m01         RN 11
+            
+pQ0         RN 0
+Step        RN 1
+            
+;// Output
+            
+P_0         RN 6
+Q_0         RN 7 
+
+;//Declarations for bSLT4 kernel
+
+tC          RN 12
+tC0         RN 5
+tC1         RN 12
+pos         RN 5
+neg         RN 9
+
+;//Declarations for bSGE4 kernel
+
+
+;// Miscellanous
+XY          RN 8
+
+a           RN 10
+t1          RN 10
+t2          RN 12
+t3          RN 14
+t4          RN 6
+t5          RN 5
+
+
+        ;// Allocate stack memory 
+        M_ALLOC4 ppThresholds,4
+        M_ALLOC8 pAlphaBeta0,8
+        M_ALLOC8 pAlphaBeta1,8
+        M_ALLOC8 pXYBS,4
+        M_ALLOC4 ppBS,4
+        
+        ;// Function header
+        M_START omxVCM4P10_FilterDeblockingChroma_VerEdge_I, r11
+        
+        ;//Input arguments on the stack
+        M_ARG   ppThresholdsArg, 4
+        M_ARG   ppBSArg, 4
+        
+        LDRB    alpha1, [pAlphaArg,#1]
+        LDRB    beta1,  [pBetaArg,#1]
+        M_LDR   pThresholds, ppThresholdsArg
+        LDR     a,=MASK_1
+        LDRB    beta0,  [pBetaArg]
+        M_STR   pThresholds, ppThresholds
+        LDRB    alpha0, [pAlphaArg]
+
+        MUL     alpha1, alpha1, a
+        MUL     beta1, beta1, a
+        MUL     alpha0, alpha0, a
+        MUL     beta0, beta0, a
+
+        M_STRD  alpha1, beta1, pAlphaBeta1
+        M_LDR   pBS, ppBSArg
+        M_STRD  alpha0, beta0, pAlphaBeta0
+
+        LDR     XY,=LOOP_COUNT
+        M_STRD  XY, pBS, pXYBS
+        
+        
+LoopY
+LoopX
+;//---------------Load Pixels-------------------
+
+;//----------------Pack q0-q1-----------------------
+        LDRH    bS, [pBS], #8
+        LDR     mask, =MASK_2
+
+        M_LDRH  row4, [pQ0], srcdstStep
+        CMP     bS, #0
+        M_STR   pBS, ppBS
+        M_LDRH  row5, [pQ0], srcdstStep
+        BEQ.W   NoFilterBS0
+        LDRH    row6, [pQ0]
+        LDRH    row7, [pQ0, srcdstStep]
+
+        ;// row4 = [0 0 r0q0 r0q1]
+        ;// row5 = [0 0 r1q0 r1q1]
+        ;// row6 = [0 0 r2q0 r2q1]
+        ;// row7 = [0 0 r3q0 r3q1]
+
+        AND     tunpk4, mask, row4
+        AND     tunpk5, mask, row4, LSL#8
+        UXTAB   tunpk4, tunpk4, row5, ROR#8
+        UXTAB   tunpk5, tunpk5, row5
+        AND     tunpk6, mask, row6
+        AND     tunpk7, mask, row6, LSL#8
+        UXTAB   tunpk6, tunpk6, row7, ROR#8
+        UXTAB   tunpk7, tunpk7, row7
+
+        ;// tunpk4 = [0 0 r0q0 r1q0]
+        ;// tunpk5 = [0 0 r0q1 r1q1]
+        ;// tunpk6 = [0 0 r2q0 r3q0]
+        ;// tunpk7 = [0 0 r2q1 r3q1]
+
+        SUB     pQ0, pQ0, srcdstStep, LSL #1
+        SUB     pQ0, pQ0, #2
+
+        PKHBT   q_1, tunpk6, tunpk4, LSL#16
+        PKHBT   q_0, tunpk7, tunpk5, LSL#16
+
+        ;// q_0 = [r0q0 r1q0 r2q0 r3q0]
+        ;// q_1 = [r0q1 r1q1 r2q1 r3q1]
+
+
+;//----------------Pack p0-p1-----------------------
+
+        M_LDRH  row0, [pQ0], srcdstStep          
+        M_LDRH  row1, [pQ0], srcdstStep          
+        LDRH    row2, [pQ0]
+        LDRH    row3, [pQ0, srcdstStep]
+        
+        ;// row0 = [0 0 r0p0 r0p1]
+        ;// row1 = [0 0 r1p0 r1p1]
+        ;// row2 = [0 0 r2p0 r2p1]
+        ;// row3 = [0 0 r3p0 r3p1]
+
+        AND     tunpk2, mask, row0
+        AND     tunpk6, mask, row0, LSL#8
+        UXTAB   tunpk2, tunpk2, row1, ROR#8
+        UXTAB   tunpk6, tunpk6, row1
+
+        AND     tunpk0, mask, row2
+        AND     tunpk3, mask, row2, LSL#8
+        UXTAB   tunpk0, tunpk0, row3, ROR#8
+        UXTAB   tunpk3, tunpk3, row3
+
+        ;// tunpk2 = [0 0 r0p0 r1p0]
+        ;// tunpk6 = [0 0 r0p1 r1p1]
+        ;// tunpk0 = [0 0 r2p0 r3p0]
+        ;// tunpk3 = [0 0 r2p1 r3p1]
+
+        PKHBT   p_0, tunpk0, tunpk2, LSL#16
+        M_LDR   bSTemp, ppBS
+        PKHBT   p_1, tunpk3, tunpk6, LSL#16
+
+        ;// p_0 = [r0p0 r1p0 r2p0 r3p0]
+        ;// p_1 = [r0p1 r1p1 r2p1 r3p1]
+
+;//--------------Filtering Decision -------------------
+        USUB8   dp0q0, p_0, q_0 
+        LDR     m01, =MASK_1
+        LDRH    bSTemp, [bSTemp ,#-8]
+        MOV     m00, #MASK_0                ;//  00000000 mask 
+        
+        MOV     filt, m01
+        TST     bSTemp, #0xff00
+        MOVEQ   filt, filt, LSL #16
+        TST     bSTemp, #0xff
+        MOVEQ   filt, filt, LSR #16
+        TST     bSTemp, #4
+
+        ;// Check |p0-q0|<Alpha 
+        USUB8   a, q_0, p_0
+        SEL     ap0q0, a, dp0q0
+        USUB8   a, ap0q0, alpha
+        SEL     filt, m00, filt
+        
+        ;// Check |p1-p0|<Beta 
+        USUB8   dp1p0, p_1, p_0
+        USUB8   a, p_0, p_1
+        SEL     a, a, dp1p0
+        USUB8   a, a, beta
+        SEL     filt, m00, filt
+
+        ;// Check |q1-q0|<Beta 
+        USUB8   dq1q0, q_1, q_0
+        USUB8   a, q_0, q_1
+        SEL     a, a, dq1q0
+        USUB8   a, a, beta
+        SEL     filt, m00, filt
+
+        BEQ     bSLT4        
+;//-------------------Filter--------------------
+bSGE4        
+        ;//---------bSGE4 Execution---------------
+        CMP     filt, #0
+
+        M_LDR   pThresholds, ppThresholds
+
+        ;// Compute P0b
+        UHADD8  t1, p_0, q_1
+        BEQ     NoFilterFilt0
+        MVN     t2, p_1
+        UHSUB8  t1, t1, t2
+        USUB8   t2, filt, m01
+        EOR     t1, t1, m01, LSL #7
+
+        ADD     pThresholds,pThresholds, #4
+        
+        ;// Compute Q0b 
+        UHADD8  t2, q_0, p_1
+        MVN     t3, q_1
+        UHSUB8  t2, t2, t3
+        M_STR   pThresholds, ppThresholds
+        SEL     P_0, t1, p_0
+        EOR     t2, t2, m01, LSL #7
+        SEL     Q_0, t2, q_0
+
+        B       StoreResultAndExit
+
+;//---------- Exit of LoopX --------------
+;//---- for the case of no filtering -----
+
+NoFilterFilt0
+        ADD     pQ0, pQ0, #2
+NoFilterBS0
+        M_LDR   pThresholds, ppThresholds
+        SUB     pQ0, pQ0, srcdstStep, LSL #1
+        ADD     pQ0, pQ0, #4
+        ADD     pThresholds, pThresholds, #4
+        ;// Load counter for LoopX
+        M_LDRD  XY, pBS, pXYBS
+        M_STR   pThresholds, ppThresholds
+        M_LDRD  alpha, beta, pAlphaBeta1
+
+        ;// Align the pointer
+        ADDS    XY, XY, XY
+        M_STR   XY, pXYBS
+        BCC     LoopY
+        B       ExitLoopY
+        
+bSLT4        
+        ;//---------bSLT4 Execution---------------
+        M_LDR   pThresholds, ppThresholds
+        CMP     filt, #0
+        
+
+        ;// Since beta <= 18 and alpha <= 255 we know
+        ;// -254 <= p0-q0 <= 254
+        ;//  -17 <= q1-q0 <= 17
+        ;//  -17 <= p1-p0 <= 17
+
+        ;// delta = Clip3( -tC, tC, ((((q0-p0)<<2) + (p1-q1) + 4)>>3))
+        ;// 
+        ;//    Calculate A = (((q0-p0)<<2) + (p1-q1) + 4)>>3
+        ;//                = (4*q0 - 4*p0 + p1 - q1 + 4)>>3
+        ;//                = ((p1-p0) - (q1-q0) - 3*(p0-q0) + 4)>>3
+
+        USUB8   t1, p_1, p_0
+        USUB8   t2, q_1, q_0
+        BEQ     NoFilterFilt0
+        
+        LDRB    tC0, [pThresholds], #1
+        SSUB8   t1, t1, t2
+        LDRB    tC1, [pThresholds], #3
+        M_STR   pThresholds, ppThresholds
+        UHSUB8  t4, p_0, q_0
+        ORR     tC, tC1, tC0, LSL #16
+        USUB8   t5, p_0, q_0
+        AND     t5, t5, m01
+        SHSUB8  t1, t1, t5
+        ORR     tC, tC, LSL #8        
+        SSUB8   t1, t1, t5
+        SHSUB8  t1, t1, t4
+        UQADD8  tC, tC, m01
+        SADD8   t1, t1, m01
+        USUB8   t5, filt, m01   
+        SHSUB8  t1, t1, t4
+        SEL     tC, tC, m00
+
+        ;// Split into positive and negative part and clip 
+
+        SSUB8   t1, t1, m00
+        SEL     pos, t1, m00
+        USUB8   neg, pos, t1
+        USUB8   t3, pos, tC
+        SEL     pos, tC, pos
+        USUB8   t3, neg, tC
+        SEL     neg, tC, neg
+        UQADD8  P_0, p_0, pos
+        UQSUB8  Q_0, q_0, pos
+        UQSUB8  P_0, P_0, neg
+        UQADD8  Q_0, Q_0, neg
+        
+        ;// Choose to store the filtered
+        ;// value or the original pixel
+        USUB8   t1, filt, m01    
+        SEL     P_0, P_0, p_0
+        SEL     Q_0, Q_0, q_0
+    
+StoreResultAndExit
+
+        ;//---------Store result---------------
+
+        ;// P_0 = [r0p0 r1p0 r2p0 r3p0]
+        ;// Q_0 = [r0q0 r1q0 r2q0 r3q0]
+
+        SUB     pQ0, pQ0, srcdstStep, LSL #1
+        ADD        pQ0, pQ0, #1      
+ 
+        MOV     t1, Q_0, LSR #24
+        STRB    t1, [pQ0, #1]
+        MOV     t1, P_0, LSR #24
+        M_STRB  t1, [pQ0], srcdstStep
+
+        MOV     t1, Q_0, LSR #16
+        STRB    t1, [pQ0, #1]
+        MOV     t1, P_0, LSR #16
+        M_STRB  t1, [pQ0], srcdstStep
+
+        MOV     t1, P_0, LSR #8
+        STRB    t1, [pQ0]
+        STRB    P_0, [pQ0, srcdstStep]
+        MOV     t1, Q_0, LSR #8
+        STRB    t1, [pQ0, #1]!
+        STRB    Q_0, [pQ0, srcdstStep]
+
+        M_LDRD  XY, pBS, pXYBS
+        M_LDRD  alpha, beta, pAlphaBeta1
+
+        SUB     pQ0, pQ0, srcdstStep, LSL #1
+        ADD     pQ0, pQ0, #4
+
+        ADDS    XY, XY, XY
+        M_STR   XY, pXYBS
+        BCC     LoopX
+
+;//-------- Common Exit of LoopY -----------------
+        ;// Align the pointers 
+
+ExitLoopY
+
+        M_LDR   pThresholds, ppThresholds
+        SUB     pQ0, pQ0, #8
+        ADD     pQ0, pQ0, srcdstStep, LSL #2
+        SUB     pBS, pBS, #14 
+        SUB     pThresholds, pThresholds, #6
+        M_STR   pThresholds, ppThresholds
+
+        M_LDRD  alpha, beta, pAlphaBeta0
+
+        BNE     LoopY
+        MOV     r0, #OMX_Sts_NoErr
+;//-----------------End Filter--------------------
+
+        M_END
+
+        ENDIF        
+
+        END
+        
+        
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_FilterDeblockingLuma_HorEdge_I_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_FilterDeblockingLuma_HorEdge_I_s.s
new file mode 100644
index 0000000..1b84080
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_FilterDeblockingLuma_HorEdge_I_s.s
@@ -0,0 +1,331 @@
+;//
+;// 
+;// File Name:  omxVCM4P10_FilterDeblockingLuma_HorEdge_I_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   9641
+;// Date:       Thursday, February 7, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+
+        M_VARIANTS ARM1136JS
+
+        IMPORT  armVCM4P10_DeblockingLumabSLT4_unsafe
+        IMPORT  armVCM4P10_DeblockingLumabSGE4_unsafe
+
+    
+
+    IF ARM1136JS
+
+
+MASK_0      EQU 0x00000000   
+MASK_1      EQU 0x01010101
+MASK_2      EQU 0xff00ff00
+LOOP_COUNT  EQU 0x11110000
+
+;// Declare input registers
+
+pSrcDst     RN 0
+srcdstStep  RN 1
+pAlphaArg   RN 2
+pBetaArg    RN 3
+
+pThresholds RN 14
+pBS         RN 9
+pQ0         RN 0
+bS          RN 2
+
+alpha       RN 6
+alpha0      RN 6
+alpha1      RN 8
+
+beta        RN 7
+beta0       RN 7
+beta1       RN 9
+
+;// Declare Local/Temporary variables
+
+;// Pixels
+p_0         RN 3  
+p_1         RN 5  
+p_2         RN 4  
+p_3         RN 2  
+q_0         RN 8  
+q_1         RN 9  
+q_2         RN 10 
+q_3         RN 12 
+
+;// Filtering
+
+dp0q0       RN 12
+dp1p0       RN 12
+dq1q0       RN 12
+dp2p0       RN 12
+dq2q0       RN 12
+            
+ap0q0       RN 1  
+filt        RN 2
+        
+m00         RN 14
+m01         RN 11
+            
+apflg       RN 0 
+aqflg       RN 6
+apqflg      RN 0
+            
+
+;//Declarations for bSLT4 kernel
+
+tC0         RN 7
+ptC0        RN 1
+
+pQ0a        RN 0    
+Stepa       RN 1    
+maska       RN 14
+            
+P0a         RN 1
+P1a         RN 8
+Q0a         RN 7
+Q1a         RN 11
+            
+;//Declarations for bSGE4 kernel
+
+pQ0b        RN 0
+Stepb       RN 1
+maskb       RN 14
+            
+P0b         RN 6
+P1b         RN 7
+P2b         RN 1
+P3b         RN 3
+            
+Q0b         RN 9 
+Q1b         RN 0   
+Q2b         RN 2 
+Q3b         RN 3 
+
+;// Miscellanous
+XY          RN 8
+t0          RN 3 
+t1          RN 12
+t2          RN 14
+t7          RN 7
+t4          RN 4
+t5          RN 1  
+t8          RN 6  
+a           RN 0
+
+            
+
+        
+        ;// Allocate stack memory 
+        M_ALLOC4 ppThresholds,4
+        M_ALLOC4 pQ_3,4
+        M_ALLOC4 pP_3,4
+        M_ALLOC8 pAlphaBeta0,8
+        M_ALLOC8 pAlphaBeta1,8
+        M_ALLOC8 pXYBS,4
+        M_ALLOC4 ppBS,4
+        M_ALLOC8 ppQ0Step,4
+        M_ALLOC4 pStep,4
+        
+        ;// Function header
+        M_START omxVCM4P10_FilterDeblockingLuma_HorEdge_I, r11
+        
+        ;//Input arguments on the stack
+        M_ARG   ppThresholdsArg, 4
+        M_ARG   ppBSArg, 4
+
+        LDR     t4,=MASK_1
+
+        LDRB    alpha0, [pAlphaArg]
+        LDRB    beta0,  [pBetaArg]
+        LDRB    alpha1, [pAlphaArg,#1]
+        LDRB    beta1,  [pBetaArg,#1]
+
+        MUL     alpha0, alpha0, t4
+        MUL     beta0, beta0, t4
+        MUL     alpha1, alpha1, t4
+        MUL     beta1, beta1, t4
+
+        M_STRD  alpha0, beta0, pAlphaBeta0
+        M_STRD  alpha1, beta1, pAlphaBeta1
+
+        LDR     XY,=LOOP_COUNT
+        M_LDR   pBS, ppBSArg
+        M_LDR   pThresholds, ppThresholdsArg
+        M_STR   srcdstStep, pStep
+        M_STRD  XY, pBS, pXYBS
+        SUB     pQ0, pQ0, srcdstStep, LSL #2
+        M_STR   pThresholds, ppThresholds
+LoopY
+LoopX
+;//---------------Load Pixels-------------------
+        M_STR   pQ0, ppQ0Step
+        M_LDR   p_3, [pQ0], srcdstStep
+        M_LDR   p_2, [pQ0], srcdstStep
+        M_STR   p_3, pP_3
+        LDRB    bS, [pBS], #1
+        M_STR   pBS, ppBS
+        M_LDR   p_1, [pQ0], srcdstStep
+        CMP     bS, #0
+        M_LDR   p_0, [pQ0], srcdstStep
+        M_LDR   q_0, [pQ0], srcdstStep
+        M_LDR   q_1, [pQ0], srcdstStep
+        M_LDR   q_2, [pQ0], srcdstStep
+        M_LDR   q_3, [pQ0], srcdstStep
+        BEQ     NoFilterBS0
+        CMP     bS, #4
+        M_STR   q_3, pQ_3
+
+;//--------------Filtering Decision -------------------
+        LDR     m01, =MASK_1                ;//  01010101 mask 
+        MOV     m00, #MASK_0                ;//  00000000 mask 
+
+        ;// Check |p0-q0|<Alpha 
+        USUB8   dp0q0, p_0, q_0 
+        USUB8   a, q_0, p_0
+        SEL     ap0q0, a, dp0q0
+        USUB8   a, ap0q0, alpha
+        SEL     filt, m00, m01
+        
+        ;// Check |p1-p0|<Beta 
+        USUB8   dp1p0, p_1, p_0
+        USUB8   a, p_0, p_1
+        SEL     a, a, dp1p0
+        USUB8   a, a, beta
+        SEL     filt, m00, filt
+
+        ;// Check |q1-q0|<Beta 
+        USUB8   dq1q0, q_1, q_0
+        USUB8   a, q_0, q_1
+        SEL     a, a, dq1q0
+        USUB8   a, a, beta
+        SEL     filt, m00, filt
+
+        ;// Check ap<Beta 
+        USUB8   dp2p0, p_2, p_0
+        USUB8   a, p_0, p_2
+        SEL     a, a, dp2p0
+        USUB8   a, a, beta
+        SEL     apflg, m00, filt            ;// apflg = filt && (ap<beta)
+
+        ;// Check aq<Beta 
+        USUB8   dq2q0, q_2, q_0
+        USUB8   t2, q_0, q_2
+        SEL     t2, t2, dq2q0
+        USUB8   t2, t2, beta
+        MOV     t7,#0
+
+        BLT     bSLT4        
+;//-------------------Filter--------------------
+bSGE4        
+        ;//---------bSGE4 Execution---------------
+        SEL     t1, t7, filt            ;// aqflg = filt && (aq<beta) 
+        CMP     filt, #0
+        ORR     apqflg, apflg, t1, LSL #1
+        M_LDRD  pQ0, srcdstStep, ppQ0Step, EQ
+        BEQ     NoFilterFilt0
+
+        BL      armVCM4P10_DeblockingLumabSGE4_unsafe
+        
+        ;//---------Store result---------------
+        M_LDR   pThresholds, ppThresholds
+        MOV     p_2, Q1b
+        MOV     p_1, P2b
+        M_LDRD  pQ0b, Stepb, ppQ0Step
+        ADD     pThresholds, #1
+        M_STR   pThresholds, ppThresholds
+        M_STR   p_1, [pQ0b, Stepb]!
+        M_STR   P1b, [pQ0b, Stepb]!
+        M_STR   P0b, [pQ0b, Stepb]!
+        M_STR   Q0b, [pQ0b, Stepb]!
+        STR     p_2, [pQ0b, Stepb]
+        STR     Q2b, [pQ0b, Stepb, LSL #1]
+
+
+        M_LDRD  XY, pBS, pXYBS
+        SUB     pQ0, pQ0b, Stepb, LSL #2
+        ADD     pQ0, pQ0, #4
+        M_LDRD  alpha, beta, pAlphaBeta0
+        ADDS    XY, XY, XY
+        M_STR   XY, pXYBS
+        BCC     LoopX
+        B       ExitLoopY
+
+;//---------- Exit of LoopX --------------
+;//---- for the case of no filtering -----
+
+NoFilterBS0
+        SUB     pQ0, pQ0, srcdstStep, LSL #3
+NoFilterFilt0
+        ADD     pQ0, pQ0, #4
+        ;// Load counter for LoopX
+        M_LDRD  XY, pBS, pXYBS
+        M_LDR   pThresholds, ppThresholds
+        M_LDRD  alpha, beta, pAlphaBeta0
+
+        ;// Align the pointers
+        ADDS    XY, XY, XY
+        ADD     pThresholds, pThresholds, #1
+        M_STR   pThresholds, ppThresholds
+        M_STR   XY, pXYBS
+        BCC     LoopX
+        B       ExitLoopY
+
+bSLT4        
+        ;//---------bSLT4 Execution---------------
+        SEL     aqflg, t7, filt            ;// aqflg = filt && (aq<beta) 
+        M_LDR   ptC0, ppThresholds
+        CMP     filt, #0
+        M_LDRD  pQ0, srcdstStep, ppQ0Step, EQ
+        BEQ     NoFilterFilt0
+        
+        LDRB    tC0, [ptC0], #1
+        M_STR   ptC0, ppThresholds
+
+        BL      armVCM4P10_DeblockingLumabSLT4_unsafe
+
+        ;//---------Store result---------------
+        MOV     p_2, P0a
+        M_LDRD  pQ0a, Stepa, ppQ0Step
+        M_STR   P1a, [pQ0a, Stepa, LSL #1]!
+        M_STR   p_2, [pQ0a, Stepa]!
+        M_STR   Q0a, [pQ0a, Stepa]!
+        STR     Q1a, [pQ0a, Stepa]
+       
+        ;// Load counter
+        M_LDRD  XY, pBS, pXYBS
+        M_LDRD  alpha, beta, pAlphaBeta0
+
+        SUB     pQ0, pQ0a, Stepa, LSL #2
+        ADD     pQ0, pQ0, #4
+
+        ADDS    XY, XY, XY
+        M_STR   XY, pXYBS
+        BCC     LoopX
+        
+;//-------- Common Exit of LoopY -----------------
+        ;// Align the pointers 
+ExitLoopY
+        M_LDRD  alpha, beta, pAlphaBeta1
+        SUB     pQ0, pQ0, #16
+        ADD     pQ0, pQ0, srcdstStep, LSL #2
+        M_STRD  alpha, beta, pAlphaBeta0
+
+        BNE     LoopY
+        MOV     r0, #OMX_Sts_NoErr
+;//-----------------End Filter--------------------
+        M_END
+
+    ENDIF        
+        
+
+        END
+        
+        
\ No newline at end of file
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_FilterDeblockingLuma_VerEdge_I_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_FilterDeblockingLuma_VerEdge_I_s.s
new file mode 100644
index 0000000..417ddc2
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_FilterDeblockingLuma_VerEdge_I_s.s
@@ -0,0 +1,550 @@
+;//
+;// 
+;// File Name:  omxVCM4P10_FilterDeblockingLuma_VerEdge_I_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   9641
+;// Date:       Thursday, February 7, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+
+        M_VARIANTS ARM1136JS
+
+        IMPORT  armVCM4P10_DeblockingLumabSLT4_unsafe
+        IMPORT  armVCM4P10_DeblockingLumabSGE4_unsafe
+        
+    
+    IF ARM1136JS
+
+MASK_0      EQU 0x00000000   
+MASK_1      EQU 0x01010101
+MASK_2      EQU 0xff00ff00
+LOOP_COUNT  EQU 0x11110000
+
+;// Declare input registers
+
+pSrcDst     RN 0
+srcdstStep  RN 1
+pAlphaArg   RN 2
+pBetaArg    RN 3
+
+pThresholds RN 14
+pBS         RN 9
+pQ0         RN 0
+bS          RN 2
+
+alpha       RN 6
+alpha0      RN 6
+alpha1      RN 8
+
+beta        RN 7
+beta0       RN 7
+beta1       RN 9
+
+;// Declare Local/Temporary variables
+
+;// Pixels
+p_0         RN 3  
+p_1         RN 5  
+p_2         RN 4  
+p_3         RN 2  
+q_0         RN 8  
+q_1         RN 9  
+q_2         RN 10 
+q_3         RN 12 
+
+;// Unpacking
+mask        RN 11 
+
+row0        RN 2
+row1        RN 4
+row2        RN 5
+row3        RN 3
+
+row4        RN 8
+row5        RN 9
+row6        RN 10
+row7        RN 12
+row8        RN 14
+row9        RN 7
+            
+tunpk0      RN 8
+tunpk1      RN 9
+tunpk2      RN 10
+tunpk3      RN 12
+tunpk4      RN 0
+
+tunpk5      RN 1
+tunpk6      RN 14
+tunpk7      RN 2 
+tunpk8      RN 5 
+tunpk9      RN 6 
+ 
+
+;// Filtering
+
+dp0q0       RN 12
+dp1p0       RN 12
+dq1q0       RN 12
+dp2p0       RN 12
+dq2q0       RN 12
+            
+ap0q0       RN 1  
+filt        RN 2
+        
+m00         RN 14
+m01         RN 11
+            
+apflg       RN 0 
+aqflg       RN 6
+apqflg      RN 0
+            
+
+;//Declarations for bSLT4 kernel
+
+tC0         RN 7
+ptC0        RN 1
+
+pQ0a        RN 0    
+Stepa       RN 1    
+maska       RN 14
+            
+P0a         RN 1
+P1a         RN 8
+Q0a         RN 7
+Q1a         RN 11
+            
+;//Declarations for bSGE4 kernel
+
+pQ0b        RN 0
+Stepb       RN 1
+maskb       RN 14
+            
+P0b         RN 6
+P1b         RN 7
+P2b         RN 1
+P3b         RN 3
+            
+Q0b         RN 9 
+Q1b         RN 0   
+Q2b         RN 2 
+Q3b         RN 3 
+
+;// Miscellanous
+XY          RN 8
+t0          RN 3 
+t1          RN 12
+t2          RN 14
+t7          RN 7
+t4          RN 4
+t5          RN 1  
+t8          RN 6  
+a           RN 0
+
+            
+
+        ;// Allocate stack memory 
+        M_ALLOC4 ppThresholds,4
+        M_ALLOC4 pQ_3,4
+        M_ALLOC4 pP_3,4
+        M_ALLOC8 pAlphaBeta0,8
+        M_ALLOC8 pAlphaBeta1,8
+        M_ALLOC8 pXYBS,4
+        M_ALLOC4 ppBS,4
+        M_ALLOC8 ppQ0Step,4
+        M_ALLOC4 pStep,4
+        
+        ;// Function header
+        M_START omxVCM4P10_FilterDeblockingLuma_VerEdge_I, r11
+        
+        ;//Input arguments on the stack
+        M_ARG   ppThresholdsArg, 4
+        M_ARG   ppBSArg, 4
+        
+        LDR     t4,=MASK_1
+
+        LDRB    alpha0, [pAlphaArg]
+        LDRB    beta0,  [pBetaArg]
+        LDRB    alpha1, [pAlphaArg,#1]
+        LDRB    beta1,  [pBetaArg,#1]
+
+        MUL     alpha0, alpha0, t4
+        MUL     beta0, beta0, t4
+        MUL     alpha1, alpha1, t4
+        MUL     beta1, beta1, t4
+
+        M_STRD  alpha0, beta0, pAlphaBeta0
+        M_STRD  alpha1, beta1, pAlphaBeta1
+
+        LDR     XY,=LOOP_COUNT
+        M_LDR   pBS, ppBSArg
+        M_LDR   pThresholds, ppThresholdsArg
+        M_STR   srcdstStep, pStep
+        M_STRD  XY, pBS, pXYBS
+        M_STR   pThresholds, ppThresholds
+        
+        SUB     pQ0, pQ0, #4
+LoopY
+;//---------------Load Pixels-------------------
+
+;//----------------Pack p0-p3-----------------------
+        LDR     mask, =MASK_2
+        
+        M_LDR   row0, [pQ0], srcdstStep          
+        M_LDR   row1, [pQ0], srcdstStep          
+        LDR     row2, [pQ0]
+        LDR     row3, [pQ0, srcdstStep]
+        SUB     pQ0, pQ0, srcdstStep, LSL #1
+        
+        ;// row0 = [r0p0 r0p1 r0p2 r0p3]
+        ;// row1 = [r1p0 r1p1 r1p2 r1p3]
+        ;// row2 = [r2p0 r2p1 r2p2 r2p3]
+        ;// row3 = [r3p0 r3p1 r3p2 r3p3]
+
+        AND     tunpk0, mask, row0
+        AND     tunpk6, mask, row0, LSL#8
+        UXTAB16 tunpk0, tunpk0, row1, ROR#8
+        UXTAB16 tunpk6, tunpk6, row1
+        AND     tunpk2, mask, row2
+        AND     tunpk3, mask, row2, LSL#8
+        UXTAB16 tunpk2, tunpk2, row3, ROR#8
+        UXTAB16 tunpk3, tunpk3, row3
+
+        ;// tunpk0 = [r0p0 r1p0 r0p2 r1p2]
+        ;// tunpk6 = [r0p1 r1p1 r0p3 r1p3]
+        ;// tunpk2 = [r2p0 r3p0 r2p2 r3p2]
+        ;// tunpk3 = [r2p1 r3p1 r2p3 r3p3]
+
+        PKHTB   p_0, tunpk0, tunpk2, ASR#16
+        PKHTB   p_1, tunpk6, tunpk3, ASR#16
+        PKHBT   p_2, tunpk2, tunpk0, LSL#16
+        PKHBT   p_3, tunpk3, tunpk6, LSL#16
+
+
+        ;// p_0 = [r0p0 r1p0 r2p0 r3p0]
+        ;// p_1 = [r0p1 r1p1 r2p1 r3p1]
+        ;// p_2 = [r0p2 r1p2 r2p1 r3p2]
+        ;// p_3 = [r0p3 r1p3 r2p3 r3p3]
+
+        M_STR   p_3, pP_3
+
+;//----------------Pack q0-q3-----------------------
+LoopX
+        LDRB    bS, [pBS], #4
+        M_STR   pQ0, ppQ0Step
+        LDR     mask, =MASK_2
+        CMP     bS, #0
+        M_STR   pBS, ppBS
+
+        LDR     row4, [pQ0, #4]!
+        BEQ.W   NoFilterBS0
+        M_LDR   row5, [pQ0, srcdstStep]!
+        M_LDR   row6, [pQ0, srcdstStep]!
+        M_LDR   row7, [pQ0, srcdstStep]
+
+        ;// row4 = [r0q3 r0q2 r0q1 r0q0]
+        ;// row5 = [r1q3 r1q2 r1q1 r1q0]
+        ;// row6 = [r2q3 r2q2 r2q1 r2q0]
+        ;// row7 = [r3q3 r3q2 r3q1 r3q0]
+    
+        AND     tunpk4, mask, row4
+        CMP     bS, #4
+        AND     tunpk5, mask, row4, LSL#8
+        UXTAB16 tunpk4, tunpk4, row5, ROR#8
+        UXTAB16 tunpk5, tunpk5, row5
+        AND     tunpk6, mask, row6
+        AND     tunpk7, mask, row6, LSL#8
+        UXTAB16 tunpk6, tunpk6, row7, ROR#8
+        UXTAB16 tunpk7, tunpk7, row7
+
+        ;// tunpk4 = [r0q0 r1q0 r0q2 r1q2]
+        ;// tunpk5 = [r0q1 r1q1 r0q3 r1q3]
+        ;// tunpk6 = [r2q0 r3q0 r2q2 r3q2]
+        ;// tunpk7 = [r2q1 r3q1 r2q3 r3q3]
+
+        PKHTB   q_3, tunpk4, tunpk6, ASR#16
+        PKHTB   q_2, tunpk5, tunpk7, ASR#16
+        PKHBT   q_1, tunpk6, tunpk4, LSL#16
+        M_STR   q_3, pQ_3
+        PKHBT   q_0, tunpk7, tunpk5, LSL#16
+
+
+        ;// q_0 = [r0q0 r1q0 r2q0 r3q0]
+        ;// q_1 = [r0q1 r1q1 r2q1 r3q1]
+        ;// q_2 = [r0q2 r1q2 r2q1 r3q2]
+        ;// q_3 = [r0q3 r1q3 r2q3 r3q3]
+
+
+;//--------------Filtering Decision -------------------
+        LDR     m01, =MASK_1                ;//  01010101 mask 
+        MOV     m00, #MASK_0                ;//  00000000 mask 
+
+        ;// Check |p0-q0|<Alpha 
+        USUB8   dp0q0, p_0, q_0 
+        USUB8   a, q_0, p_0
+        SEL     ap0q0, a, dp0q0
+        USUB8   a, ap0q0, alpha
+        SEL     filt, m00, m01
+        
+        ;// Check |p1-p0|<Beta 
+        USUB8   dp1p0, p_1, p_0
+        USUB8   a, p_0, p_1
+        SEL     a, a, dp1p0
+        USUB8   a, a, beta
+        SEL     filt, m00, filt
+
+        ;// Check |q1-q0|<Beta 
+        USUB8   dq1q0, q_1, q_0
+        USUB8   a, q_0, q_1
+        SEL     a, a, dq1q0
+        USUB8   a, a, beta
+        SEL     filt, m00, filt
+
+        ;// Check ap<Beta 
+        USUB8   dp2p0, p_2, p_0
+        USUB8   a, p_0, p_2
+        SEL     a, a, dp2p0
+        USUB8   a, a, beta
+        SEL     apflg, m00, filt            ;// apflg = filt && (ap<beta)
+
+        ;// Check aq<Beta 
+        USUB8   dq2q0, q_2, q_0
+        USUB8   t2, q_0, q_2
+        SEL     t2, t2, dq2q0
+        USUB8   t2, t2, beta
+        MOV     t7,#0
+        
+
+        BLT     bSLT4        
+;//-------------------Filter--------------------
+bSGE4        
+        ;//---------bSGE4 Execution---------------
+        SEL     t1, t7, filt            ;// aqflg = filt && (aq<beta) 
+        CMP     filt, #0
+        ORR     apqflg, apflg, t1, LSL #1
+        M_LDRD  pQ0, srcdstStep, ppQ0Step, EQ
+        BEQ     NoFilterFilt0
+
+        BL      armVCM4P10_DeblockingLumabSGE4_unsafe
+        
+        ;//---------Store result---------------
+
+        LDR     maskb,=MASK_2
+
+        ;// P0b = [r0p0 r1p0 r2p0 r3p0]
+        ;// P1b = [r0p1 r1p1 r2p1 r3p1]
+        ;// P2b = [r0p2 r1p2 r2p2 r3p2]
+        ;// P3b = [r0p3 r1p3 r2p3 r3p3]
+
+        M_LDR   P3b, pP_3   
+        M_STR   Q0b, pP_3   
+
+        ;//------Pack p0-p3------
+        AND     tunpk0, maskb, P0b
+        AND     tunpk2, maskb, P0b, LSL#8
+        UXTAB16 tunpk0, tunpk0, P1b, ROR#8
+        UXTAB16 tunpk2, tunpk2, P1b
+
+        AND     tunpk3, maskb, P2b
+        AND     tunpk8, maskb, P2b, LSL#8
+        UXTAB16 tunpk3, tunpk3, P3b, ROR#8
+        UXTAB16 tunpk8, tunpk8, P3b
+
+        ;// tunpk0 = [r0p0 r0p1 r2p0 r2p1]
+        ;// tunpk2 = [r1p0 r1p1 r3p0 r3p1]
+        ;// tunpk3 = [r0p2 r0p3 r2p2 r2p3]
+        ;// tunpk8 = [r1p2 r1p3 r3p2 r3p3]
+
+        MOV     p_2, Q1b
+        M_LDRD  pQ0b, Stepb, ppQ0Step
+
+        PKHTB   row9, tunpk0, tunpk3, ASR#16
+        PKHBT   row7, tunpk3, tunpk0, LSL#16
+        PKHTB   row3, tunpk2, tunpk8, ASR#16
+        PKHBT   row6, tunpk8, tunpk2, LSL#16
+
+        ;// row9 = [r0p0 r0p1 r0p2 r0p3]
+        ;// row3 = [r1p0 r1p1 r1p2 r1p3]
+        ;// row7 = [r2p0 r2p1 r2p2 r2p3]
+        ;// row6 = [r3p0 r3p1 r3p2 r3p3]
+
+        M_STR   row9, [pQ0b], Stepb
+        STR     row7, [pQ0b, Stepb]
+        STR     row6, [pQ0b, Stepb, LSL #1]
+        STR     row3, [pQ0b], #4
+        
+        M_LDR   Q3b, pQ_3
+
+        ;// Q0b = [r0q0 r1q0 r2q0 r3q0]
+        ;// Q1b = [r0q1 r1q1 r2q1 r3q1]
+        ;// Q2b = [r0q2 r1q2 r2q2 r3q2]
+        ;// Q3b = [r0q3 r1q3 r2q3 r3q3]
+
+        ;//------Pack q0-q3------
+        AND     tunpk0, maskb, p_2
+        AND     tunpk2, maskb, p_2, LSL#8
+        UXTAB16 tunpk0, tunpk0, Q0b, ROR#8
+        UXTAB16 tunpk2, tunpk2, Q0b
+
+        AND     tunpk3, maskb, Q3b
+        AND     tunpk8, maskb, Q3b, LSL#8
+        UXTAB16 tunpk3, tunpk3, Q2b, ROR#8
+        UXTAB16 tunpk8, tunpk8, Q2b
+
+        ;// tunpk0 = [r0q1 r0q0 r2q1 r2q0]
+        ;// tunpk2 = [r1q1 r1q0 r3q1 r3q0]
+        ;// tunpk3 = [r0q3 r0q2 r2q3 r2q2]
+        ;// tunpk8 = [r1q3 r1q2 r3q3 r3q2]
+
+        PKHTB   row8, tunpk3, tunpk0, ASR#16
+        PKHBT   row7, tunpk0, tunpk3, LSL#16
+        PKHTB   row4, tunpk8, tunpk2, ASR#16
+        PKHBT   row6, tunpk2, tunpk8, LSL#16
+
+        ;// row8 = [r0q0 r0q1 r0q2 r0q3]
+        ;// row4 = [r1q0 r1q1 r1q2 r1q3]
+        ;// row7 = [r2q0 r2q1 r2q2 r2q3]
+        ;// row6 = [r3q0 r3q1 r3q2 r3q3]
+
+        STR     row4, [pQ0b]
+        STR     row7, [pQ0b, Stepb]
+        STR     row6, [pQ0b, Stepb, LSL #1]
+
+        SUB     pQ0, pQ0b, Stepb
+        MOV     p_1, Q2b
+
+        STR     row8, [pQ0]
+
+        M_LDRD  XY, pBS, pXYBS
+        M_LDR   pThresholds, ppThresholds
+        M_LDRD  alpha, beta, pAlphaBeta1
+
+        ADDS    XY, XY, XY
+        ADD     pThresholds, #4
+        M_STR   pThresholds, ppThresholds
+        M_STR   XY, pXYBS
+        BCC     LoopX
+        B       ExitLoopY
+
+;//---------- Exit of LoopX --------------
+;//---- for the case of no filtering -----
+
+NoFilterFilt0
+        ADD     pQ0, pQ0, #4
+NoFilterBS0
+        ;// Load counter for LoopX
+        M_LDRD  XY, pBS, pXYBS
+        M_LDR   pThresholds, ppThresholds
+        M_LDRD  alpha, beta, pAlphaBeta1
+
+        ;// Align the pointer
+        ADDS    XY, XY, XY
+        ADD     pThresholds, pThresholds, #4
+        M_STR   pThresholds, ppThresholds
+        M_STR   XY, pXYBS
+        BCC     LoopY
+        B       ExitLoopY
+        
+bSLT4        
+        ;//---------bSLT4 Execution---------------
+        SEL     aqflg, t7, filt            ;// aqflg = filt && (aq<beta) 
+        M_LDR   ptC0, ppThresholds
+        CMP     filt, #0
+        M_LDRD  pQ0, srcdstStep, ppQ0Step, EQ
+        BEQ     NoFilterFilt0
+        
+        LDRB    tC0, [ptC0], #4
+        M_STR   ptC0, ppThresholds
+
+        BL      armVCM4P10_DeblockingLumabSLT4_unsafe
+
+        ;//---------Store result---------------
+        ;//--------Pack p1,p0,q1,q0------------
+        
+        ;//Load destination pointer
+        LDR     maska,=MASK_2
+        M_STR   Q0a, pP_3
+        MOV     p_1, q_2
+
+        ;// P1a = [r0p1 r1p1 r2p1 r3p1]
+        ;// P0a = [r0p0 r1p0 r2p0 r3p0]
+        ;// Q0a = [r0q0 r1q0 r2q0 r3q0]
+        ;// Q1a = [r0q1 r1q1 r2q1 r3q1]
+
+        AND     tunpk1, maska, P0a
+        AND     tunpk2, maska, P0a, LSL#8
+        UXTAB16 tunpk1, tunpk1, P1a, ROR#8
+        UXTAB16 tunpk2, tunpk2, P1a
+
+        M_LDRD  pQ0a, Stepa, ppQ0Step
+
+        AND     tunpk9, maska, Q1a
+        AND     tunpk3, maska, Q1a, LSL#8
+        UXTAB16 tunpk9, tunpk9, Q0a, ROR#8
+        UXTAB16 tunpk3, tunpk3, Q0a
+
+        ;// tunpk1 = [r0p0 r0p1 r2p0 r2p1]
+        ;// tunpk2 = [r1p0 r1p1 r3p0 r3p1]
+        ;// tunpk9 = [r0q1 r0q0 r2q1 r2q0]
+        ;// tunpk3 = [r1q1 r1q0 r3q1 r3q0]
+
+        MOV     t4, tunpk1, LSR #16
+        MOV     t0, tunpk9, LSR #16
+
+        STRH    t4,[pQ0a, #2]!          ;//Stores [r0p0 r0p1]
+        STRH    t0,[pQ0a, #2]           ;//Stores [r0q0 r0q1]
+
+        MOV     t4, tunpk2, LSR #16
+        MOV     t0, tunpk3, LSR #16
+
+        M_STRH  t4,[pQ0a, Stepa]!       ;//Stores [r1p0 r1p1]
+        STRH    t0,[pQ0a, #2]           ;//Stores [r1q0 r1q1]
+        
+        M_STRH  tunpk1,[pQ0a, Stepa]!   ;//Stores [r2p0 r2p1]
+        STRH    tunpk2,[pQ0a, Stepa]    ;//Stores [r3p0 r3p1]
+        STRH    tunpk9,[pQ0a, #2]!        ;//Stores [r2q0 r2q1]
+        STRH    tunpk3,[pQ0a, Stepa]    ;//Stores [r3q0 r3q1]
+
+        SUB     pQ0, pQ0a, Stepa, LSL #1
+
+        ;// Load counter
+        M_LDRD  XY, pBS, pXYBS
+
+        ;// Reload Pixels
+        M_LDR   p_0, pQ_3
+        MOV     p_2, Q1a
+                
+        M_LDRD  alpha, beta, pAlphaBeta1
+
+        ADDS    XY, XY, XY
+        M_STR   XY, pXYBS
+        BCC     LoopX
+        
+;//-------- Common Exit of LoopY -----------------
+        ;// Align the pointers 
+        M_LDR   pThresholds, ppThresholds
+ExitLoopY
+        SUB     pQ0, pQ0, #16
+        ADD     pQ0, pQ0, srcdstStep, LSL #2
+        SUB     pBS, pBS, #15
+        SUB     pThresholds, pThresholds, #15
+        M_STR   pThresholds, ppThresholds
+
+        M_LDRD  alpha, beta, pAlphaBeta0
+
+        BNE     LoopY
+        MOV     r0, #OMX_Sts_NoErr
+
+        M_END
+;//-----------------End Filter--------------------
+
+    ENDIF        
+        
+        END
+        
+        
\ No newline at end of file
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_InterpolateChroma.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_InterpolateChroma.c
new file mode 100644
index 0000000..de835bd
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_InterpolateChroma.c
@@ -0,0 +1,79 @@
+/**
+ * 
+ * File Name:  omxVCM4P10_InterpolateChroma.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * Description:
+ * This function will calculate 1/8 Pixel interpolation for Chroma Block
+ * 
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armVC.h"
+#include "armCOMM.h"
+
+
+/**
+ * Function: omxVCM4P10_InterpolateChroma,
+ *
+ * Description:
+ * Performs 1/8-pixel interpolation for inter chroma MB.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	pSrc	Pointer to the source reference frame buffer
+ * [in]	srcStep Reference frame step in byte
+ * [in]	dstStep Destination frame step in byte. Must be multiple of roi.width.
+ * [in]	dx		Fractional part of horizontal motion vector component
+ *						in 1/8 pixel unit;valid in the range [0,7]
+ * [in]	dy		Fractional part of vertical motion vector component
+ *						in 1/8 pixel unit;valid in the range [0,7]
+ * [in]	roi		Dimension of the interpolation region;the parameters roi.width and roi.height must
+ *                      be equal to either 2, 4, or 8.
+ * [out]	pDst	Pointer to the destination frame buffer.
+ *                   if roi.width==2,  2-byte alignment required
+ *                   if roi.width==4,  4-byte alignment required
+ *                   if roi.width==8,  8-byte alignment required
+ *
+ * Return Value:
+ * If the function runs without error, it returns OMX_Sts_NoErr.
+ * If one of the following cases occurs, the function returns OMX_Sts_BadArgErr:
+ *	pSrc or pDst is NULL.
+ *	srcStep or dstStep < 8.
+ *	dx or dy is out of range [0-7].
+ *	roi.width or roi.height is out of range {2,4,8}.
+ *	roi.width is equal to 2, but pDst is not 2-byte aligned.
+ *	roi.width is equal to 4, but pDst is not 4-byte aligned.
+ *	roi.width is equal to 8, but pDst is not 8 byte aligned.
+ *	srcStep or dstStep is not a multiple of 8.
+ *
+ */
+
+OMXResult omxVCM4P10_InterpolateChroma (
+     const OMX_U8* pSrc,
+     OMX_S32 srcStep,
+     OMX_U8* pDst,
+     OMX_S32 dstStep,
+     OMX_S32 dx,
+     OMX_S32 dy,
+     OMXSize roi
+ )
+{
+    return armVCM4P10_Interpolate_Chroma 
+        ((OMX_U8*)pSrc, srcStep, pDst, dstStep, roi.width, roi.height, dx, dy);
+}
+
+
+/*****************************************************************************
+ *                              END OF FILE
+ *****************************************************************************/
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_InterpolateLuma_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_InterpolateLuma_s.s
new file mode 100644
index 0000000..cf611a3
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_InterpolateLuma_s.s
@@ -0,0 +1,426 @@
+;//
+;// 
+;// File Name:  omxVCM4P10_InterpolateLuma_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   9641
+;// Date:       Thursday, February 7, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+;// Function:
+;//     omxVCM4P10_InterpolateLuma
+;//
+;// This function implements omxVCM4P10_InterpolateLuma in v6 assembly.
+;// Performs quarter pel interpolation of inter luma MB.
+;// It's assumed that the frame is already padded when calling this function.
+;// Parameters:
+;// [in]    pSrc        Pointer to the source reference frame buffer
+;// [in]    srcStep     Reference frame step in byte
+;// [in]    dstStep     Destination frame step in byte. Must be multiple of roi.width
+;// [in]    dx          Fractional part of horizontal motion vector
+;//                         component in 1/4 pixel unit; valid in the range [0,3]
+;// [in]    dy          Fractional part of vertical motion vector
+;//                         component in 1/4 pixel unit; valid in the range [0,3]
+;// [in]    roi         Dimension of the interpolation region;the parameters roi.width and roi.height must
+;//                         be equal to either 4, 8, or 16.
+;// [out]   pDst        Pointer to the destination frame buffer.
+;//                   if roi.width==4,  4-byte alignment required
+;//                   if roi.width==8,  8-byte alignment required
+;//                   if roi.width==16, 16-byte alignment required
+;//
+;// Return Value:
+;// If the function runs without error, it returns OMX_Sts_NoErr.
+;// It is assued that following cases are satisfied before calling this function:
+;//  pSrc or pDst is not NULL.
+;//  srcStep or dstStep >= roi.width.
+;//     dx or dy is in the range [0-3].
+;//     roi.width or roi.height is not out of range {4, 8, 16}.
+;//     If roi.width is equal to 4, Dst is 4 byte aligned.
+;//     If roi.width is equal to 8, pDst is 8 byte aligned.
+;//     If roi.width is equal to 16, pDst is 16 byte aligned.
+;//     srcStep and dstStep is multiple of 8.
+;//
+;//
+
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+
+        M_VARIANTS ARM1136JS
+
+        EXPORT omxVCM4P10_InterpolateLuma
+        
+    IF ARM1136JS
+        IMPORT armVCM4P10_InterpolateLuma_Copy4x4_unsafe
+        IMPORT armVCM4P10_InterpolateLuma_HorAlign9x_unsafe
+        IMPORT armVCM4P10_InterpolateLuma_VerAlign4x_unsafe
+        IMPORT armVCM4P10_Average_4x4_Align0_unsafe
+        IMPORT armVCM4P10_Average_4x4_Align2_unsafe
+        IMPORT armVCM4P10_Average_4x4_Align3_unsafe
+        IMPORT armVCM4P10_InterpolateLuma_HorDiagCopy_unsafe
+        IMPORT armVCM4P10_InterpolateLuma_VerDiagCopy_unsafe
+    ENDIF
+
+    IF ARM1136JS
+        IMPORT armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe
+        IMPORT armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe
+        IMPORT armVCM4P10_InterpolateLuma_HalfDiagVerHor4x4_unsafe
+        IMPORT armVCM4P10_InterpolateLuma_HalfDiagHorVer4x4_unsafe
+    ENDIF
+    
+    
+
+;// Declare input registers
+pSrc            RN 0
+srcStep         RN 1
+pDst            RN 2
+dstStep         RN 3
+iHeight         RN 4
+iWidth          RN 5
+
+;// Declare other intermediate registers
+idx             RN 6
+idy             RN 7
+index           RN 6
+Temp            RN 12
+pArgs           RN 11
+
+
+        ;// End of CortexA8
+                    
+;//-------------------------------------------------------------------------------------------------------------------------    
+;//-------------------------------------------------------------------------------------------------------------------------    
+    IF ARM1136JS
+
+
+        M_ALLOC4 ppDst, 8
+        M_ALLOC4 ppSrc, 8
+        M_ALLOC4 ppArgs, 16
+        M_ALLOC4 pBuffer, 120                           ;// 120 = 12x10
+        M_ALLOC8 pInterBuf, 120                         ;// 120 = 12*5*2
+        M_ALLOC8 pTempBuf, 32                           ;// 32 =  8*4
+        
+        ;// Function header
+        ;// Interpolation of luma is implemented by processing block of pixels, size 4x4 at a time.
+        ;// Depending on the values of motion vector fractional parts (dx,dy), one out of 16 cases will be processed.
+        ;// Registers r4, r5, r6 to be preserved by internal unsafe functions
+        ;// r4 - iHeight
+        ;// r5 - iWidth
+        ;// r6 - index
+        M_START omxVCM4P10_InterpolateLuma, r11
+
+;// Declare other intermediate registers
+idx             RN 6
+idy             RN 7
+index           RN 6
+Temp            RN 12
+pArgs           RN 11
+
+pBuf            RN 8
+Height          RN 9 
+bufStep         RN 9
+        
+        ;// Define stack arguments
+        M_ARG   ptridx, 4
+        M_ARG   ptridy, 4        
+        M_ARG   ptrWidth, 4
+        M_ARG   ptrHeight, 4        
+
+        ;// Load structure elements of roi 
+        M_LDR   idx, ptridx
+        M_LDR   idy, ptridy
+        M_LDR   iWidth, ptrWidth
+        M_LDR   iHeight, ptrHeight
+        
+        M_PRINTF "roi.width %d\n", iWidth
+        M_PRINTF "roi.height %d\n", iHeight
+
+        ADD     index, idx, idy, LSL #2                 ;//  [index] = [idy][idx]
+        M_ADR   pArgs, ppArgs
+
+InterpolateLuma
+Block4x4WidthLoop
+Block4x4HeightLoop
+
+        STM     pArgs, {pSrc,srcStep,pDst,dstStep} 
+        M_ADR   pBuf, pBuffer                           
+
+        ;// switch table using motion vector as index
+        M_SWITCH index, L
+        M_CASE  Case_0
+        M_CASE  Case_1
+        M_CASE  Case_2
+        M_CASE  Case_3
+        M_CASE  Case_4
+        M_CASE  Case_5
+        M_CASE  Case_6
+        M_CASE  Case_7
+        M_CASE  Case_8
+        M_CASE  Case_9
+        M_CASE  Case_a
+        M_CASE  Case_b
+        M_CASE  Case_c
+        M_CASE  Case_d
+        M_CASE  Case_e
+        M_CASE  Case_f
+        M_ENDSWITCH
+
+Case_0
+        ;// Case G
+        M_PRINTF "Case 0 \n"
+
+        BL      armVCM4P10_InterpolateLuma_Copy4x4_unsafe
+        B       Block4x4LoopEnd
+
+Case_1
+        ;// Case a
+        M_PRINTF "Case 1 \n"
+
+        SUB     pSrc, pSrc, #2
+        MOV     Height, #4
+        BL      armVCM4P10_InterpolateLuma_HorAlign9x_unsafe
+        BL      armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe
+        BL      armVCM4P10_Average_4x4_Align2_unsafe
+        B       Block4x4LoopEnd
+Case_2
+        ;// Case b
+        M_PRINTF "Case 2 \n"
+        
+        SUB     pSrc, pSrc, #2
+        MOV     Height, #4
+        BL      armVCM4P10_InterpolateLuma_HorAlign9x_unsafe
+        BL      armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe        
+        B       Block4x4LoopEnd
+Case_3
+        ;// Case c
+        M_PRINTF "Case 3 \n"
+
+        SUB     pSrc, pSrc, #2
+        MOV     Height, #4
+        BL      armVCM4P10_InterpolateLuma_HorAlign9x_unsafe
+        BL      armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe
+        BL      armVCM4P10_Average_4x4_Align3_unsafe
+        B       Block4x4LoopEnd
+Case_4
+        ;// Case d
+        M_PRINTF "Case 4 \n"
+
+        SUB     pSrc, pSrc, srcStep, LSL #1
+        MOV     Height, #9
+        BL      armVCM4P10_InterpolateLuma_VerAlign4x_unsafe
+        BL      armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe
+        BL      armVCM4P10_Average_4x4_Align0_unsafe
+
+        B       Block4x4LoopEnd
+Case_5
+        ;// Case e
+        M_PRINTF "Case 5 \n"
+
+        SUB     pSrc, pSrc, #2
+        MOV     Height, #4
+        M_ADR   pDst, pTempBuf
+        MOV     dstStep, #4
+        BL      armVCM4P10_InterpolateLuma_HorAlign9x_unsafe
+        BL      armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe
+        M_ADR   pArgs, ppArgs
+        LDM     pArgs, {pSrc, srcStep, pDst, dstStep}
+        SUB     pSrc, pSrc, srcStep, LSL #1
+        M_ADR   pBuf, pBuffer                           
+        MOV     Height, #9
+        BL      armVCM4P10_InterpolateLuma_VerAlign4x_unsafe
+        BL      armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe
+        M_ADR   pSrc, pTempBuf
+        MOV     srcStep, #4
+        BL      armVCM4P10_Average_4x4_Align0_unsafe
+        
+
+        B       Block4x4LoopEnd
+Case_6
+        ;// Case f
+        M_PRINTF "Case 6 \n"
+
+        SUB     pSrc, pSrc, #2
+        SUB     pSrc, pSrc, srcStep, LSL #1
+        MOV     Height, #9
+        BL      armVCM4P10_InterpolateLuma_HorAlign9x_unsafe
+        M_ADR   pBuf, pInterBuf
+        BL      armVCM4P10_InterpolateLuma_HalfDiagHorVer4x4_unsafe
+        M_ADR   idy, pTempBuf
+        BL      armVCM4P10_InterpolateLuma_VerDiagCopy_unsafe    
+        BL      armVCM4P10_Average_4x4_Align0_unsafe
+        B       Block4x4LoopEnd
+Case_7
+        ;// Case g
+        M_PRINTF "Case 7 \n"
+        
+        SUB     pSrc, pSrc, #2
+        MOV     Height, #4
+        M_ADR   pDst, pTempBuf
+        MOV     dstStep, #4
+        BL      armVCM4P10_InterpolateLuma_HorAlign9x_unsafe
+        BL      armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe
+        M_ADR   pArgs, ppArgs
+        LDM     pArgs, {pSrc, srcStep, pDst, dstStep}
+        SUB     pSrc, pSrc, srcStep, LSL #1
+        ADD     pSrc, pSrc, #1
+        M_ADR   pBuf, pBuffer                           
+        MOV     Height, #9
+        BL      armVCM4P10_InterpolateLuma_VerAlign4x_unsafe
+        BL      armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe
+        M_ADR   pSrc, pTempBuf
+        MOV     srcStep, #4
+        BL      armVCM4P10_Average_4x4_Align0_unsafe
+
+        B       Block4x4LoopEnd
+Case_8
+        ;// Case h
+        M_PRINTF "Case 8 \n"
+
+        SUB     pSrc, pSrc, srcStep, LSL #1
+        MOV     Height, #9
+        BL      armVCM4P10_InterpolateLuma_VerAlign4x_unsafe
+        BL      armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe
+        B       Block4x4LoopEnd
+Case_9
+        ;// Case i
+        M_PRINTF "Case 9 \n"
+
+        SUB     pSrc, pSrc, #2
+        SUB     pSrc, pSrc, srcStep, LSL #1
+        MOV     Height, #9
+        BL      armVCM4P10_InterpolateLuma_HorAlign9x_unsafe
+        ADD     pSrc, pSrc, srcStep, LSL #1
+        M_ADR   pBuf, pInterBuf
+        BL      armVCM4P10_InterpolateLuma_HalfDiagVerHor4x4_unsafe
+        M_ADR   idy, pTempBuf
+        BL      armVCM4P10_InterpolateLuma_HorDiagCopy_unsafe    
+        BL      armVCM4P10_Average_4x4_Align2_unsafe
+        B       Block4x4LoopEnd
+Case_a
+        ;// Case j
+        M_PRINTF "Case a \n"
+
+        SUB     pSrc, pSrc, #2
+        SUB     pSrc, pSrc, srcStep, LSL #1
+        MOV     Height, #9
+        BL      armVCM4P10_InterpolateLuma_HorAlign9x_unsafe
+        ADD     pSrc, pSrc, srcStep, LSL #1
+        M_ADR   pBuf, pInterBuf
+        BL      armVCM4P10_InterpolateLuma_HalfDiagVerHor4x4_unsafe
+        B       Block4x4LoopEnd
+Case_b
+        ;// Case k
+        M_PRINTF "Case b \n"
+        SUB     pSrc, pSrc, #2
+        SUB     pSrc, pSrc, srcStep, LSL #1
+        MOV     Height, #9
+        BL      armVCM4P10_InterpolateLuma_HorAlign9x_unsafe
+        ADD     pSrc, pSrc, srcStep, LSL #1
+        M_ADR   pBuf, pInterBuf
+        BL      armVCM4P10_InterpolateLuma_HalfDiagVerHor4x4_unsafe
+        M_ADR   idy, pTempBuf
+        BL      armVCM4P10_InterpolateLuma_HorDiagCopy_unsafe    
+        BL      armVCM4P10_Average_4x4_Align3_unsafe
+        B       Block4x4LoopEnd
+Case_c
+        ;// Case n
+        M_PRINTF "Case c \n"
+
+        SUB     pSrc, pSrc, srcStep, LSL #1
+        MOV     Height, #9
+        BL      armVCM4P10_InterpolateLuma_VerAlign4x_unsafe
+        BL      armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe
+        ADD     pSrc, pSrc, srcStep                     ;// Update pSrc to one row down
+        BL      armVCM4P10_Average_4x4_Align0_unsafe
+        B       Block4x4LoopEnd
+Case_d
+        ;// Case p
+        M_PRINTF "Case d \n"
+        SUB     pSrc, pSrc, #2
+        ADD     pSrc, pSrc, srcStep
+        MOV     Height, #4
+        M_ADR   pDst, pTempBuf
+        MOV     dstStep, #4
+        BL      armVCM4P10_InterpolateLuma_HorAlign9x_unsafe
+        BL      armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe
+        M_ADR   pArgs, ppArgs
+        LDM     pArgs, {pSrc, srcStep, pDst, dstStep}
+        SUB     pSrc, pSrc, srcStep, LSL #1
+        M_ADR   pBuf, pBuffer                           
+        MOV     Height, #9
+        BL      armVCM4P10_InterpolateLuma_VerAlign4x_unsafe
+        BL      armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe
+        M_ADR   pSrc, pTempBuf
+        MOV     srcStep, #4
+        BL      armVCM4P10_Average_4x4_Align0_unsafe
+        B       Block4x4LoopEnd
+Case_e
+        ;// Case q
+        M_PRINTF "Case e \n"
+        
+        SUB     pSrc, pSrc, #2
+        SUB     pSrc, pSrc, srcStep, LSL #1
+        MOV     Height, #9
+        BL      armVCM4P10_InterpolateLuma_HorAlign9x_unsafe
+        M_ADR   pBuf, pInterBuf
+        BL      armVCM4P10_InterpolateLuma_HalfDiagHorVer4x4_unsafe
+        M_ADR   idy, pTempBuf
+        BL      armVCM4P10_InterpolateLuma_VerDiagCopy_unsafe
+        ADD     pSrc, pSrc, #4    
+        BL      armVCM4P10_Average_4x4_Align0_unsafe
+
+        B       Block4x4LoopEnd
+Case_f
+        ;// Case r
+        M_PRINTF "Case f \n"
+        SUB     pSrc, pSrc, #2
+        ADD     pSrc, pSrc, srcStep
+        MOV     Height, #4
+        M_ADR   pDst, pTempBuf
+        MOV     dstStep, #4
+        BL      armVCM4P10_InterpolateLuma_HorAlign9x_unsafe
+        BL      armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe
+        M_ADR   pArgs, ppArgs
+        LDM     pArgs, {pSrc, srcStep, pDst, dstStep}
+        SUB     pSrc, pSrc, srcStep, LSL #1
+        ADD     pSrc, pSrc, #1
+        M_ADR   pBuf, pBuffer                           
+        MOV     Height, #9
+        BL      armVCM4P10_InterpolateLuma_VerAlign4x_unsafe
+        BL      armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe
+        M_ADR   pSrc, pTempBuf
+        MOV     srcStep, #4
+        BL      armVCM4P10_Average_4x4_Align0_unsafe
+
+Block4x4LoopEnd
+
+        ;// Width Loop
+        SUBS    iWidth, iWidth, #4
+        M_ADR   pArgs, ppArgs
+        LDM     pArgs, {pSrc,srcStep,pDst,dstStep}  ;// Load arguments
+        ADD     pSrc, pSrc, #4      
+        ADD     pDst, pDst, #4
+        BGT     Block4x4WidthLoop
+
+        ;// Height Loop
+        SUBS    iHeight, iHeight, #4
+        M_LDR   iWidth, ptrWidth
+        M_ADR   pArgs, ppArgs
+        ADD     pSrc, pSrc, srcStep, LSL #2      
+        ADD     pDst, pDst, dstStep, LSL #2
+        SUB     pSrc, pSrc, iWidth
+        SUB     pDst, pDst, iWidth
+        BGT     Block4x4HeightLoop
+
+EndOfInterpolation
+        MOV     r0, #0
+        M_END
+
+    ENDIF
+                    
+
+    END
+    
\ No newline at end of file
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_PredictIntraChroma_8x8_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_PredictIntraChroma_8x8_s.s
new file mode 100644
index 0000000..34fedd8
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_PredictIntraChroma_8x8_s.s
@@ -0,0 +1,494 @@
+;//
+;// 
+;// File Name:  omxVCM4P10_PredictIntraChroma_8x8_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   9641
+;// Date:       Thursday, February 7, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+  
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+        
+        EXPORT armVCM4P10_pIndexTable8x8
+        
+;// Define the processor variants supported by this file
+         
+         M_VARIANTS ARM1136JS
+     
+     AREA table, DATA    
+;//-------------------------------------------------------
+;// This table for implementing switch case of C in asm by
+;// the mehtod of two levels of indexing.
+;//-------------------------------------------------------
+
+    M_TABLE armVCM4P10_pIndexTable8x8
+    DCD  OMX_VC_CHROMA_DC,     OMX_VC_CHROMA_HOR 
+    DCD  OMX_VC_CHROMA_VERT,   OMX_VC_CHROMA_PLANE  
+    
+    M_TABLE armVCM4P10_MultiplierTableChroma8x8,1
+    DCW   3, 2, 1,4 
+    DCW  -3,-2,-1,0
+    DCW   1, 2, 3,4
+    
+    IF ARM1136JS
+  
+;//--------------------------------------------
+;// Constants
+;//--------------------------------------------  
+
+BLK_SIZE        EQU 0x8
+MUL_CONST0      EQU 0x01010101
+MASK_CONST      EQU 0x00FF00FF
+MUL_CONST1      EQU 0x80808080
+
+;//--------------------------------------------
+;// Scratch variable
+;//--------------------------------------------
+y               RN 12   
+pc              RN 15   
+return          RN 0    
+pSrcLeft2       RN 1    
+pDst2           RN 2    
+sum1            RN 6    
+sum2            RN 7    
+pTable          RN 9    
+dstStepx2       RN 11   
+leftStepx2      RN 14   
+outerCount      RN 14   
+r0x01010101     RN 10   
+r0x00FF00FF     RN 11   
+
+tVal0           RN 0    
+tVal1           RN 1    
+tVal2           RN 2    
+tVal3           RN 3    
+tVal4           RN 4    
+tVal5           RN 5    
+tVal6           RN 6    
+tVal7           RN 7    
+tVal8           RN 8    
+tVal9           RN 9    
+tVal10          RN 10   
+tVal11          RN 11   
+tVal12          RN 12   
+tVal14          RN 14   
+
+b               RN 14   
+c               RN 12   
+
+p2p0            RN 0    
+p3p1            RN 1    
+p6p4            RN 2    
+p7p5            RN 4    
+
+pp2pp0          RN 6    
+pp3pp1          RN 7    
+pp6pp4          RN 8    
+pp7pp5          RN 9    
+
+p3210           RN 10   
+p7654           RN 10   
+
+;//--------------------------------------------
+;// Input Arguments
+;//--------------------------------------------
+pSrcLeft        RN 0    ;// input pointer
+pSrcAbove       RN 1    ;// input pointer
+pSrcAboveLeft   RN 2    ;// input pointer
+pDst            RN 3    ;// output pointer
+leftStep        RN 4    ;// input variable
+dstStep         RN 5    ;// input variable
+predMode        RN 6    ;// input variable
+availability    RN 7    ;// input variable
+
+;//-----------------------------------------------------------------------------------------------
+;// omxVCM4P10_PredictIntraChroma_8x8 starts
+;//-----------------------------------------------------------------------------------------------
+        
+        ;// Write function header
+        M_START omxVCM4P10_PredictIntraChroma_8x8, r11
+        
+        ;// Define stack arguments
+        M_ARG    LeftStep,     4
+        M_ARG    DstStep,      4
+        M_ARG    PredMode,     4
+        M_ARG    Availability, 4
+        
+        ;// M_STALL ARM1136JS=4
+        
+        LDR      pTable,=armVCM4P10_pIndexTable8x8   ;// Load index table for switch case
+        
+        
+        ;// Load argument from the stack
+        M_LDR    predMode, PredMode                  ;// Arg predMode loaded from stack to reg 
+        M_LDR    leftStep, LeftStep                  ;// Arg leftStep loaded from stack to reg 
+        M_LDR    dstStep,  DstStep                   ;// Arg dstStep loaded from stack to reg         
+        M_LDR    availability, Availability          ;// Arg availability loaded from stack to reg 
+        
+        MOV      y, #BLK_SIZE                        ;// Outer Loop Count
+        LDR      pc, [pTable, predMode, LSL #2]      ;// Branch to the case based on preMode
+
+OMX_VC_CHROMA_DC
+        AND      availability, availability,#(OMX_VC_UPPER + OMX_VC_LEFT)
+        CMP      availability, #(OMX_VC_UPPER + OMX_VC_LEFT) ;// if(availability & (#OMX_VC_UPPER | #OMX_VC_LEFT))
+        LDR      r0x01010101, =MUL_CONST0
+        BNE      TST_UPPER                           ;// Jump to Upper if not both
+        LDM      pSrcAbove,{tVal8,tVal9}             ;// tVal 8 to 9 = pSrcAbove[0 to 7]
+        
+        ADD      leftStepx2, leftStep,leftStep       ;// leftStepx2 = 2 * leftStep
+        ADD      pSrcLeft2, pSrcLeft, leftStep       ;// pSrcLeft2 = pSrcLeft + leftStep
+        
+        ;// M_STALL ARM1136JS=1
+       
+        UXTB16   tVal7, tVal8                        ;// pSrcAbove[0, 2]
+        UXTB16   tVal8, tVal8, ROR #8                ;// pSrcAbove[1, 3]
+        UADD16   sum1, tVal7, tVal8                  ;// pSrcAbove[0, 2] + pSrcAbove[1, 3]
+        
+        UXTB16   tVal7, tVal9                        ;// pSrcAbove[4, 6]
+        UXTB16   tVal9, tVal9, ROR #8                ;// pSrcAbove[5, 7]
+        UADD16   sum2, tVal7, tVal9                  ;// pSrcAbove[0, 2] + pSrcAbove[4, 6]
+        ADD      sum1, sum1, sum1, LSR #16           ;// sum(pSrcAbove[0] to pSrcAbove[3])
+        ADD      sum2, sum2, sum2, LSR #16           ;// sum(pSrcAbove[4] to pSrcAbove[7])
+        UXTH     sum1, sum1                          ;// upsum1 (Clear the top junk bits)
+        UXTH     sum2, sum2                          ;// upsum2 (Clear the top junk bits)
+        
+        M_LDRB   tVal8, [pSrcLeft],  +leftStepx2     ;// tVal8 = pSrcLeft[0]
+        M_LDRB   tVal9, [pSrcLeft2], +leftStepx2     ;// tVal9 = pSrcLeft[1]
+        M_LDRB   tVal4, [pSrcLeft],  +leftStepx2     ;// tVal4 = pSrcLeft[2]
+        M_LDRB   tVal12,[pSrcLeft2], +leftStepx2     ;// tVal12= pSrcLeft[3]
+        ADD      tVal2, tVal8, tVal9                 ;// tVal14 = tVal8 + tVal9
+        
+        M_LDRB   tVal8, [pSrcLeft],  +leftStepx2     ;// tVal8 = pSrcLeft[4]
+        M_LDRB   tVal9, [pSrcLeft2], +leftStepx2     ;// tVal9 = pSrcLeft[5]
+        ADD      tVal14, tVal4, tVal12               ;// tVal14 = tVal4 + tVal12
+        
+        LDRB     tVal4, [pSrcLeft]                   ;// tVal4 = pSrcLeft[6]
+        LDRB     tVal12,[pSrcLeft2]                  ;// tVal12= pSrcLeft[7]
+        ADD      tVal8, tVal8, tVal9                 ;// tVal8 = tVal8 + tVal9
+        ADD      tVal2, tVal2, tVal14                ;// leftsum1  = sum(pSrcLeft[0] to pSrcLeft[3])
+        ADD      tVal4, tVal4, tVal12                ;// tVal4 = tVal4 + tVal12
+        ADD      tVal14, tVal8, tVal4                ;// leftsum2  = sum(pSrcLeft[4] to pSrcLeft[7])
+        ADD      tVal8, tVal14, #2                   ;// tVal8 = leftsum2 + 2
+        ADD      tVal9, sum2,   #2                   ;// tVal8 = upsum2 + 2
+        ADD      sum1,  sum1, tVal2                  ;// sum1 = upsum1 + leftsum1
+        ADD      sum2,  sum2, tVal14                 ;// sum2 = upsum2 + leftsum2
+        ADD      sum1, sum1, #4                      ;// (sum1 + 4)
+        ADD      sum2, sum2, #4                      ;// (sum2 + 4)
+        MOV      sum1,  sum1,  LSR #3                ;// (sum1 + 4)>>3
+        MOV      tVal9, tVal9, LSR #2                ;// (tVal9 + 2)>>2
+        MOV      tVal8, tVal8, LSR #2                ;// (tVal8 + 2)>>2
+        MOV      sum2,  sum2,  LSR #3                ;// (sum2 + 4)>>3
+        
+        MUL      tVal0, sum1, r0x01010101            ;// replicate the val in all the bytes
+        MUL      tVal1, tVal9,r0x01010101            ;// replicate the val in all the bytes
+        MUL      tVal8, tVal8,r0x01010101            ;// replicate the val in all the bytes
+        MUL      tVal9, sum2, r0x01010101            ;// replicate the val in all the bytes
+        
+        M_STRD   tVal0, tVal1, [pDst], dstStep       ;// pDst[0 to 7]   = tVal 0 to 1
+        M_STRD   tVal0, tVal1, [pDst], dstStep       ;// pDst[8 to 15]  = tVal 0 to 1
+        M_STRD   tVal0, tVal1, [pDst], dstStep       ;// pDst[16 to 23] = tVal 0 to 1
+        M_STRD   tVal0, tVal1, [pDst], dstStep       ;// pDst[24 to 31] = tVal 0 to 1
+                                       
+        M_STRD   tVal8, tVal9, [pDst], dstStep       ;// pDst[32 to 39] = tVal 8 to 9
+        M_STRD   tVal8, tVal9, [pDst], dstStep       ;// pDst[40 to 47] = tVal 8 to 9
+        M_STRD   tVal8, tVal9, [pDst], dstStep       ;// pDst[48 to 55] = tVal 8 to 9
+        M_STRD   tVal8, tVal9, [pDst], dstStep       ;// pDst[56 to 63] = tVal 8 to 9
+        MOV      return, #OMX_Sts_NoErr
+        M_EXIT
+        
+TST_UPPER
+        
+        ;// M_STALL ARM1136JS=3
+        
+        CMP      availability, #OMX_VC_UPPER         ;// if(availability & #OMX_VC_UPPER)
+        
+        BNE      TST_LEFT                            ;// Jump to Left if not upper
+        LDM      pSrcAbove,{tVal8,tVal9}             ;// tVal 8 to 9 = pSrcAbove[0 to 7]
+        
+        ;// M_STALL ARM1136JS=3
+        
+        UXTB16   tVal7, tVal8                        ;// pSrcAbove[0, 2]
+        UXTB16   tVal8, tVal8, ROR #8                ;// pSrcAbove[1, 3]
+        UADD16   sum1,  tVal7, tVal8                 ;// pSrcAbove[0, 2] + pSrcAbove[1, 3]
+        
+        UXTB16   tVal7, tVal9                        ;// pSrcAbove[4, 6]
+        UXTB16   tVal9, tVal9, ROR #8                ;// pSrcAbove[5, 7]
+        UADD16   sum2,  tVal7, tVal9                 ;// pSrcAbove[0, 2] + pSrcAbove[4, 6]
+        
+        ADD      sum1, sum1, sum1, LSR #16           ;// sum(pSrcAbove[0] to pSrcAbove[3])
+        ADD      sum2, sum2, sum2, LSR #16           ;// sum(pSrcAbove[4] to pSrcAbove[7])
+        
+        UXTH     sum1, sum1                          ;// upsum1 (Clear the top junk bits)
+        UXTH     sum2, sum2                          ;// upsum2 (Clear the top junk bits)
+        
+        ADD      sum1, sum1, #2                      ;// sum1 + 2
+        ADD      sum2, sum2, #2                      ;// sum2 + 2
+        
+        MOV      sum1, sum1, LSR #2                  ;// (sum1 + 2)>>2
+        MOV      sum2, sum2, LSR #2                  ;// (sum2 + 2)>>2
+        
+        MUL      sum1, sum1,r0x01010101              ;// replicate the val in all the bytes
+        MUL      sum2, sum2,r0x01010101              ;// replicate the val in all the bytes
+        
+        M_STRD   tVal6, tVal7, [pDst], dstStep       ;// pDst[0 to 7]   = tVal 6 to 7
+        M_STRD   tVal6, tVal7, [pDst], dstStep       ;// pDst[8 to 15]  = tVal 6 to 7
+        M_STRD   tVal6, tVal7, [pDst], dstStep       ;// pDst[16 to 23] = tVal 6 to 7
+        M_STRD   tVal6, tVal7, [pDst], dstStep       ;// pDst[24 to 31] = tVal 6 to 7
+        M_STRD   tVal6, tVal7, [pDst], dstStep       ;// pDst[32 to 39] = tVal 6 to 7
+        M_STRD   tVal6, tVal7, [pDst], dstStep       ;// pDst[40 to 47] = tVal 6 to 7
+        M_STRD   tVal6, tVal7, [pDst], dstStep       ;// pDst[48 to 55] = tVal 6 to 7
+        M_STRD   tVal6, tVal7, [pDst], dstStep       ;// pDst[56 to 63] = tVal 6 to 7
+        MOV      return, #OMX_Sts_NoErr
+        M_EXIT
+        
+TST_LEFT 
+        ;// M_STALL ARM1136JS=3       
+        
+        CMP      availability, #OMX_VC_LEFT
+        BNE      TST_COUNT0
+        ADD      leftStepx2, leftStep,leftStep       ;// leftStepx2 = 2 * leftStep
+        ADD      pSrcLeft2, pSrcLeft, leftStep       ;// pSrcLeft2 = pSrcLeft + leftStep
+        
+        M_LDRB   tVal8, [pSrcLeft],  +leftStepx2     ;// tVal8 = pSrcLeft[0]
+        M_LDRB   tVal9, [pSrcLeft2], +leftStepx2     ;// tVal9 = pSrcLeft[1]
+        M_LDRB   tVal4, [pSrcLeft],  +leftStepx2     ;// tVal4 = pSrcLeft[2]
+        M_LDRB   tVal12,[pSrcLeft2], +leftStepx2     ;// tVal12= pSrcLeft[3]
+        
+        ADD      tVal6, tVal8, tVal9                 ;// tVal6 = tVal8 + tVal9
+        
+        M_LDRB   tVal8, [pSrcLeft],  +leftStepx2     ;// tVal8 = pSrcLeft[4]
+        ADD      tVal7, tVal4, tVal12                ;// tVal7 = tVal4 + tVal12
+        M_LDRB   tVal9, [pSrcLeft2], +leftStepx2     ;// tVal9 = pSrcLeft[5]
+        M_LDRB   tVal4, [pSrcLeft],  +leftStepx2     ;// tVal4 = pSrcLeft[6]
+        M_LDRB   tVal12,[pSrcLeft2], +leftStepx2     ;// tVal12= pSrcLeft[7]
+        
+        ADD      tVal8, tVal8, tVal9                 ;// tVal8 = tVal8 + tVal9
+        ADD      sum1,  tVal6, tVal7                 ;// sum1  = sum(pSrcLeft[0] to pSrcLeft[3])
+        ADD      tVal4, tVal4, tVal12                ;// tVal4 = tVal4 + tVal12
+        ADD      sum2,  tVal8, tVal4                 ;// sum2  = sum(pSrcLeft[4] to pSrcLeft[7])
+        
+        ADD      sum1, sum1, #2                      ;// sum1 + 2
+        ADD      sum2, sum2, #2                      ;// sum2 + 2
+        
+        MOV      sum1, sum1, LSR #2                  ;// (sum1 + 2)>>2
+        MOV      sum2, sum2, LSR #2                  ;// (sum2 + 2)>>2
+        
+        MUL      tVal6, sum1,r0x01010101             ;// replicate the val in all the bytes
+        MUL      tVal8, sum2,r0x01010101             ;// replicate the val in all the bytes
+        
+        ;// M_STALL ARM1136JS=1
+        MOV      tVal7,tVal6                         ;// tVal7 = sum1
+        MOV      tVal9,tVal8                         ;// tVal9 = sum2
+        
+        M_STRD   tVal6, tVal7, [pDst], dstStep       ;// pDst[0 to 7]   = tVal 6 to 7
+        M_STRD   tVal6, tVal7, [pDst], dstStep       ;// pDst[8 to 15]  = tVal 6 to 7
+        M_STRD   tVal6, tVal7, [pDst], dstStep       ;// pDst[16 to 23] = tVal 6 to 7
+        M_STRD   tVal6, tVal7, [pDst], dstStep       ;// pDst[24 to 31] = tVal 6 to 7
+        
+        M_STRD   tVal8, tVal9, [pDst], dstStep       ;// pDst[32 to 39] = tVal 8 to 9
+        M_STRD   tVal8, tVal9, [pDst], dstStep       ;// pDst[40 to 47] = tVal 8 to 9
+        M_STRD   tVal8, tVal9, [pDst], dstStep       ;// pDst[48 to 55] = tVal 8 to 9
+        M_STRD   tVal8, tVal9, [pDst], dstStep       ;// pDst[56 to 63] = tVal 8 to 9
+        
+        MOV      return, #OMX_Sts_NoErr
+        M_EXIT                                       ;// Macro to exit midway-break frm case
+
+TST_COUNT0
+        LDR      sum1, =MUL_CONST1                  ;// sum1 = 0x80808080 if(count == 0)
+        
+        ;// M_STALL ARM1136JS=2
+        
+        MOV      tVal7, sum1                         ;// tVal7 = sum1
+        
+        M_STRD   tVal6, tVal7, [pDst], dstStep       ;// pDst[0 to 7]   = tVal 6 to 7
+        M_STRD   tVal6, tVal7, [pDst], dstStep       ;// pDst[8 to 15]  = tVal 6 to 7
+        M_STRD   tVal6, tVal7, [pDst], dstStep       ;// pDst[16 to 23] = tVal 6 to 7
+        M_STRD   tVal6, tVal7, [pDst], dstStep       ;// pDst[24 to 31] = tVal 6 to 7
+        M_STRD   tVal6, tVal7, [pDst], dstStep       ;// pDst[32 to 39] = tVal 6 to 7
+        M_STRD   tVal6, tVal7, [pDst], dstStep       ;// pDst[40 to 47] = tVal 6 to 7
+        M_STRD   tVal6, tVal7, [pDst], dstStep       ;// pDst[48 to 55] = tVal 6 to 7
+        M_STRD   tVal6, tVal7, [pDst], dstStep       ;// pDst[56 to 63] = tVal 6 to 7
+        
+        MOV      return, #OMX_Sts_NoErr
+        M_EXIT                                       ;// Macro to exit midway-break frm case
+
+OMX_VC_CHROMA_HOR
+        
+        ;// M_STALL ARM1136JS=2 
+        
+        ADD      pSrcLeft2, pSrcLeft, leftStep       ;// pSrcLeft2 = pSrcLeft + leftStep
+        ADD      leftStepx2, leftStep, leftStep      ;// leftStepx2 = leftStep * 2
+        ADD      pDst2, pDst, dstStep                ;// pDst2 = pDst + dstStep
+        ADD      dstStepx2, dstStep, dstStep         ;// double dstStep
+        SUB      dstStepx2, dstStepx2, #4            ;// double dstStep  minus 4
+        LDR      r0x01010101, =MUL_CONST0            ;// Const to repeat the byte in reg 4 times
+        M_LDRB   tVal6, [pSrcLeft], +leftStepx2      ;// tVal6 = pSrcLeft[0]
+        M_LDRB   tVal7, [pSrcLeft2],+leftStepx2      ;// tVal7 = pSrcLeft[1]
+        M_LDRB   tVal8, [pSrcLeft], +leftStepx2      ;// tVal8 = pSrcLeft[2]
+        M_LDRB   tVal9, [pSrcLeft2],+leftStepx2      ;// tVal9 = pSrcLeft[3]
+        MUL      tVal6, tVal6, r0x01010101           ;// replicate the val in all the bytes
+        MUL      tVal7, tVal7, r0x01010101           ;// replicate the val in all the bytes
+        MUL      tVal8, tVal8, r0x01010101           ;// replicate the val in all the bytes
+        MUL      tVal9, tVal9, r0x01010101           ;// replicate the val in all the bytes
+        STR      tVal6, [pDst],  #+4                 ;// store {tVal6} at pDst [0 to 3] 
+        STR      tVal7, [pDst2], #+4                 ;// store {tVal7} at pDst2[0 to 3]
+        M_STR    tVal6, [pDst],  dstStepx2           ;// store {tVal6} at pDst [4 to 7]
+        M_STR    tVal7, [pDst2], dstStepx2           ;// store {tVal7} at pDst2[4 to 7]
+        STR      tVal8, [pDst],  #+4                 ;// store {tVal6} at pDst [0 to 3]
+        STR      tVal9, [pDst2], #+4                 ;// store {tVal7} at pDst2[0 to 3]
+        M_STR    tVal8, [pDst],  dstStepx2           ;// store {tVal6} at pDst [4 to 7]
+        M_STR    tVal9, [pDst2], dstStepx2           ;// store {tVal7} at pDst2[4 to 7]
+        M_LDRB   tVal6, [pSrcLeft], +leftStepx2      ;// tVal6 = pSrcLeft[4]
+        M_LDRB   tVal7, [pSrcLeft2],+leftStepx2      ;// tVal7 = pSrcLeft[5]
+        M_LDRB   tVal8, [pSrcLeft], +leftStepx2      ;// tVal8 = pSrcLeft[6]
+        M_LDRB   tVal9, [pSrcLeft2],+leftStepx2      ;// tVal9 = pSrcLeft[7]
+        MUL      tVal6, tVal6, r0x01010101           ;// replicate the val in all the bytes
+        MUL      tVal7, tVal7, r0x01010101           ;// replicate the val in all the bytes
+        MUL      tVal8, tVal8, r0x01010101           ;// replicate the val in all the bytes
+        MUL      tVal9, tVal9, r0x01010101           ;// replicate the val in all the bytes
+        STR      tVal6, [pDst],  #+4                 ;// store {tVal6} at pDst [0 to 3] 
+        STR      tVal7, [pDst2], #+4                 ;// store {tVal7} at pDst2[0 to 3]
+        M_STR    tVal6, [pDst],  dstStepx2           ;// store {tVal6} at pDst [4 to 7]
+        M_STR    tVal7, [pDst2], dstStepx2           ;// store {tVal7} at pDst2[4 to 7]
+        STR      tVal8, [pDst],  #+4                 ;// store {tVal6} at pDst [0 to 3]
+        STR      tVal9, [pDst2], #+4                 ;// store {tVal7} at pDst2[0 to 3]
+        M_STR    tVal8, [pDst],  dstStepx2           ;// store {tVal6} at pDst [4 to 7]
+        M_STR    tVal9, [pDst2], dstStepx2           ;// store {tVal7} at pDst2[4 to 7]
+        MOV      return, #OMX_Sts_NoErr
+        M_EXIT
+        
+OMX_VC_CHROMA_VERT
+        
+        ;// M_STALL ARM1136JS=4        
+        
+        LDMIA    pSrcAbove, {tVal6,tVal7}            ;// tVal 6 to 7 = pSrcAbove[0 to 7]
+        MOV      return, #OMX_Sts_NoErr
+        
+        M_STRD   tVal6, tVal7, [pDst], dstStep       ;// pDst[0 to 7]   = tVal 6 to 7
+        M_STRD   tVal6, tVal7, [pDst], dstStep       ;// pDst[8 to 15]  = tVal 6 to 7
+        M_STRD   tVal6, tVal7, [pDst], dstStep       ;// pDst[16 to 23] = tVal 6 to 7
+        M_STRD   tVal6, tVal7, [pDst], dstStep       ;// pDst[24 to 31] = tVal 6 to 7
+        M_STRD   tVal6, tVal7, [pDst], dstStep       ;// pDst[32 to 39] = tVal 6 to 7
+        M_STRD   tVal6, tVal7, [pDst], dstStep       ;// pDst[40 to 47] = tVal 6 to 7
+        M_STRD   tVal6, tVal7, [pDst], dstStep       ;// pDst[48 to 55] = tVal 6 to 7
+        M_STRD   tVal6, tVal7, [pDst], dstStep       ;// pDst[56 to 63] = tVal 6 to 7
+
+        M_EXIT                                       ;// Macro to exit midway-break frm case
+        
+OMX_VC_CHROMA_PLANE
+        
+        ;// M_STALL ARM1136JS=3
+        
+        RSB      tVal14, leftStep, leftStep, LSL #3  ;// 7*leftStep
+        LDRB     tVal7, [pSrcAbove, #+7]             ;// pSrcAbove[7]
+        LDRB     tVal6, [pSrcLeft, +tVal14]          ;// pSrcLeft[7*leftStep]
+        LDRB     tVal8, [pSrcAboveLeft]              ;// pSrcAboveLeft[0]
+        LDRB     tVal9, [pSrcAbove, #+6 ]            ;// pSrcAbove[6]
+        LDRB     tVal10,[pSrcAbove]                  ;// pSrcAbove[0]
+        ADD      tVal2, tVal7, tVal6                 ;// pSrcAbove[7] + pSrcLeft[7*leftStep]
+        SUB      tVal6, tVal6, tVal8                 ;// V0 = pSrcLeft[7*leftStep] - pSrcAboveLeft[0]
+        SUB      tVal7, tVal7, tVal8                 ;// H0 = pSrcAbove[7] - pSrcAboveLeft[0]        
+        LSL      tVal2, tVal2, #4                    ;// a = 16 * (pSrcAbove[15] + pSrcLeft[15*lS])
+        ADD      tVal2, tVal2, #16                   ;// a + 16
+        SUB      tVal9, tVal9,tVal10                 ;// pSrcAbove[6] - pSrcAbove[0]
+        LDRB     tVal8, [pSrcAbove,#+5]              ;// pSrcAbove[5]
+        LDRB     tVal10,[pSrcAbove,#+1]              ;// pSrcAbove[1]
+        ADD      tVal9, tVal9, tVal9, LSL #1         ;// H1 = 3 * (pSrcAbove[6] - pSrcAbove[0])
+        ADD      tVal7, tVal9, tVal7, LSL #2         ;// H = H1 + H0
+        SUB      tVal8, tVal8, tVal10                ;// pSrcAbove[5] - pSrcAbove[1]
+        LDRB     tVal9, [pSrcAbove,#+4]              ;// pSrcAbove[4]
+        LDRB     tVal10,[pSrcAbove,#+2]              ;// pSrcAbove[2]
+        ADD      tVal7, tVal7, tVal8, LSL #1         ;// H = H + H2
+        SUB      tVal11, tVal14,leftStep             ;// 6*leftStep
+        ADD      tVal11, pSrcLeft, tVal11            ;// pSrcLeft + 6*leftStep
+        MOV      tVal12, pSrcLeft                    ;// pSrcLeft
+        SUB      tVal9, tVal9, tVal10                ;// pSrcAbove[4] - pSrcAbove[2]
+        ADD      tVal7, tVal7, tVal9                 ;// H = H + H3
+        M_LDRB   tVal8, [tVal11],-leftStep           ;// pSrcLeft[6*leftStep]
+        M_LDRB   tVal10,[tVal12],+leftStep           ;// pSrcLeft[0]
+        ADD      tVal7, tVal7, tVal7, LSL #4         ;// 17 * H
+        ADD      tVal7, tVal7, #16                   ;// 17 * H + 16
+        SUB      tVal8, tVal8, tVal10                ;// pSrcLeft[6*leftStep] - pSrcLeft[0]
+        ASR      b, tVal7, #5                        ;// b = (17 * H + 16) >> 5
+        ADD      tVal8, tVal8, tVal8, LSL #1         ;// V1 = 3 * (pSrcLeft[6*leftStep] - pSrcLeft[0])
+        ADD      tVal6, tVal8, tVal6, LSL #2         ;// V = V0 +V1
+        M_LDRB   tVal8, [tVal11],-leftStep           ;// pSrcLeft[5*leftStep]
+        M_LDRB   tVal10,[tVal12],+leftStep           ;// pSrcLeft[leftStep]
+        ADD      tVal7, b, b, LSL #1                 ;// 3*b
+        SUB      tVal2, tVal2, tVal7                 ;// a + 16 - 3*b
+        SUB      tVal7, tVal8, tVal10                ;// pSrcLeft[5*leftStep] - pSrcLeft[leftStep]
+        M_LDRB   tVal8, [tVal11],-leftStep           ;// pSrcLeft[4*leftStep]
+        M_LDRB   tVal10,[tVal12],+leftStep           ;// pSrcLeft[2*leftStep]        
+        ADD      tVal6, tVal6, tVal7, LSL #1         ;// V = V + V2
+        LDR      r0x00FF00FF, =MASK_CONST            ;// r0x00FF00FF = 0x00FF00FF
+        SUB      tVal7, tVal8, tVal10                ;// pSrcLeft[4*leftStep] - pSrcLeft[2*leftStep]
+        ADD      tVal6, tVal6, tVal7                 ;// V = V + V7
+        SUB      dstStep, dstStep, #4                ;// dstStep - 4
+        ADD      tVal6, tVal6, tVal6, LSL #4         ;// 17*V
+        ADD      tVal6, tVal6, #16                   ;// 17*V + 16
+        
+        ;// M_STALL ARM1136JS=1
+        
+        ASR      c, tVal6, #5                        ;// c = (17*V + 16)>>5
+        
+        ;// M_STALL ARM1136JS=1
+        
+        ADD      tVal6, c, c, LSL #1                 ;// 3*c
+        UXTH     c, c                                ;// only in half word
+        SUB      tVal6, tVal2, tVal6                 ;// a - 3*b - 3*c + 16
+        ORR      c, c, c, LSL #16                    ;// c c
+        ADD      tVal7, b, b                         ;// 2b
+        ADD      tVal2, tVal6, tVal7                 ;// pp2 = d + 2*b
+        ADD      tVal7, tVal7, b                     ;// 3b
+        ORR      p2p0,   tVal6,  tVal2,  LSL #16     ;// p2p0   = pack {p2, p0}
+        UXTH     b, b
+        UXTH     tVal7, tVal7
+        ORR      b, b, b, LSL #16                    ;// {b,b}
+        ORR      tVal7, tVal7, tVal7, LSL #16        ;// {3b,3b}
+        SADD16   p3p1,   p2p0, b                     ;// p3p1   = p2p0 + {b,b}
+        SADD16   p6p4,   p3p1, tVal7                 ;// p6p4   = p3p1 + {3b,3b}
+        SADD16   p7p5,   p6p4, b                     ;// p7p5   = p6p4 + {b,b}
+        MOV      outerCount, #BLK_SIZE               ;// Outer Loop Count        
+        
+LOOP_PLANE        
+
+        USAT16   p7p5,   #13, p7p5                    ;// clip13(p7) clip13(p5)
+        USAT16   p6p4,   #13, p6p4                    ;// clip13(p6) clip13(p4)
+        USAT16   p3p1,   #13, p3p1                    ;// clip13(p3) clip13(p1)
+        USAT16   p2p0,   #13, p2p0                    ;// clip13(p2) clip13(p0)
+        
+        AND      pp7pp5, r0x00FF00FF, p7p5, ASR #5    ;// clip8(p7) clip8(p5)
+        AND      pp6pp4, r0x00FF00FF, p6p4, ASR #5    ;// clip8(p6) clip8(p4)
+        AND      pp3pp1, r0x00FF00FF, p3p1, ASR #5    ;// clip8(p3) clip8(p1)
+        AND      pp2pp0, r0x00FF00FF, p2p0, ASR #5    ;// clip8(p2) clip8(p0)
+        
+        SUBS     outerCount, outerCount, #1           ;// outerCount--
+      
+        ORR      p3210, pp2pp0, pp3pp1, LSL #8        ;// pack {p3,p2, p1, p0}
+        STR      p3210, [pDst], #4                    ;// store {pDst[0] to pDst[3]}  
+        
+        ORR      p7654, pp6pp4, pp7pp5, LSL #8        ;// pack {p7,p6, p5, p4}
+        M_STR    p7654, [pDst], dstStep               ;// store {pDst[4] to pDst[7]}
+
+        SADD16   p7p5,   p7p5,   c                    ;// {p7 + c}, {p5 + c}
+        SADD16   p6p4,   p6p4,   c                    ;// {p6 + c}, {p4 + c}
+        SADD16   p3p1,   p3p1,   c                    ;// {p3 + c}, {p1 + c}
+        SADD16   p2p0,   p2p0,   c                    ;// {p2 + c}, {p0 + c}
+      
+        BNE      LOOP_PLANE                           ;// Loop for 8 times
+        MOV      return, #OMX_Sts_NoErr
+        M_END
+        
+        ENDIF ;// ARM1136JS
+        
+        
+        
+        END
+;//-----------------------------------------------------------------------------------------------
+;// omxVCM4P10_PredictIntraChroma_8x8 ends
+;//-----------------------------------------------------------------------------------------------
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_PredictIntra_16x16_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_PredictIntra_16x16_s.s
new file mode 100644
index 0000000..1557208
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_PredictIntra_16x16_s.s
@@ -0,0 +1,501 @@
+;//
+;// 
+;// File Name:  omxVCM4P10_PredictIntra_16x16_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   9641
+;// Date:       Thursday, February 7, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+        
+        M_VARIANTS ARM1136JS    
+  
+;//-------------------------------------------------------
+;// This table for implementing switch case of C in asm by
+;// the mehtod of two levels of indexing.
+;//-------------------------------------------------------
+
+    M_TABLE armVCM4P10_pIndexTable16x16
+    DCD  OMX_VC_16X16_VERT, OMX_VC_16X16_HOR 
+    DCD  OMX_VC_16X16_DC,   OMX_VC_16X16_PLANE
+    
+    IF ARM1136JS
+
+;//--------------------------------------------
+;// Constants 
+;//--------------------------------------------  
+BLK_SIZE        EQU 0x10
+MUL_CONST0      EQU 0x01010101
+MUL_CONST1      EQU 0x00060004
+MUL_CONST2      EQU 0x00070005
+MUL_CONST3      EQU 0x00030001
+MASK_CONST      EQU 0x00FF00FF
+
+;//--------------------------------------------
+;// Scratch variable
+;//--------------------------------------------
+y               RN 12   
+pc              RN 15   
+
+return          RN 0    
+innerCount      RN 0    
+outerCount      RN 1    
+pSrcLeft2       RN 1    
+pDst2           RN 2    
+sum             RN 6    
+pTable          RN 9    
+temp1           RN 10   
+temp2           RN 12   
+cMul1           RN 11   
+cMul2           RN 12   
+count           RN 12   
+dstStepx2       RN 11   
+leftStepx2      RN 14   
+r0x01010101     RN 10   
+r0x00FF00FF     RN 11
+
+tVal0           RN 0    
+tVal1           RN 1    
+tVal2           RN 2    
+tVal3           RN 3    
+tVal4           RN 4    
+tVal5           RN 5    
+tVal6           RN 6    
+tVal7           RN 7    
+tVal8           RN 8    
+tVal9           RN 9    
+tVal10          RN 10   
+tVal11          RN 11   
+tVal12          RN 12   
+tVal14          RN 14   
+
+b               RN 12   
+c               RN 14   
+
+p2p0            RN 0    
+p3p1            RN 1    
+p6p4            RN 2    
+p7p5            RN 4    
+p10p8           RN 6    
+p11p9           RN 7    
+p14p12          RN 8    
+p15p13          RN 9    
+
+p3210           RN 10   
+p7654           RN 10   
+p111098         RN 10   
+p15141312       RN 10   
+
+;//--------------------------------------------
+;// Declare input registers
+;//--------------------------------------------
+pSrcLeft        RN 0    ;// input pointer
+pSrcAbove       RN 1    ;// input pointer
+pSrcAboveLeft   RN 2    ;// input pointer
+pDst            RN 3    ;// output pointer
+leftStep        RN 4    ;// input variable
+dstStep         RN 5    ;// input variable
+predMode        RN 6    ;// input variable
+availability    RN 7    ;// input variable
+
+;//-----------------------------------------------------------------------------------------------
+;// omxVCM4P10_PredictIntra_16x16 starts
+;//-----------------------------------------------------------------------------------------------
+        
+        ;// Write function header
+        M_START omxVCM4P10_PredictIntra_16x16, r11
+        
+        ;// Define stack arguments
+        M_ARG    LeftStep,     4
+        M_ARG    DstStep,      4
+        M_ARG    PredMode,     4
+        M_ARG    Availability, 4
+        
+        ;// M_STALL ARM1136JS=4
+        
+        LDR      pTable,=armVCM4P10_pIndexTable16x16 ;// Load index table for switch case
+        
+        ;// Load argument from the stack
+        M_LDR    predMode, PredMode                  ;// Arg predMode loaded from stack to reg 
+        M_LDR    leftStep, LeftStep                  ;// Arg leftStep loaded from stack to reg 
+        M_LDR    dstStep,  DstStep                   ;// Arg dstStep loaded from stack to reg         
+        M_LDR    availability, Availability          ;// Arg availability loaded from stack to reg
+        
+        MOV      y, #BLK_SIZE                        ;// Outer Loop Count
+        LDR      pc, [pTable, predMode, LSL #2]      ;// Branch to the case based on preMode
+        
+OMX_VC_16X16_VERT
+        LDM      pSrcAbove, {tVal6,tVal7,tVal8,tVal9};// tVal 6 to 9 = pSrcAbove[0 to 15]
+        ADD      dstStepx2, dstStep, dstStep         ;// double dstStep
+        ADD      pDst2, pDst, dstStep                ;// pDst2- pDst advanced by dstStep
+        
+        ;// M_STALL ARM1136JS=2                       ;// Stall outside the loop
+
+LOOP_VERT
+        STM      pDst, {tVal6,tVal7,tVal8,tVal9}     ;// pDst[0 to 15] = tVal 6 to 9
+        SUBS     y, y, #2                            ;// y--
+        ADD      pDst, pDst, dstStepx2               ;// pDst advanced by dstStep
+        STM      pDst2, {tVal6,tVal7,tVal8,tVal9}    ;// pDst2[16 to 31] = tVal 6 to 9
+        ADD      pDst2, pDst2, dstStepx2             ;// pDst advanced by dstStep
+        BNE      LOOP_VERT                           ;// Loop for 8 times
+        MOV      return, #OMX_Sts_NoErr
+        M_EXIT
+
+        
+OMX_VC_16X16_HOR
+        
+        ;// M_STALL ARM1136JS=6 
+               
+        LDR      r0x01010101, =MUL_CONST0            ;// Const to repeat the byte in reg 4 times
+        MOV      y, #4                               ;// Outer Loop Count
+        M_LDRB   tVal6, [pSrcLeft], +leftStep        ;// tVal6 = pSrcLeft[0 to 3]
+        ADD      pDst2, pDst, dstStep                ;// pDst2- pDst advanced by dstStep
+        M_LDRB   tVal7, [pSrcLeft], +leftStep        ;// tVal1 = pSrcLeft[4 to 7]
+        ADD      dstStepx2, dstStep, dstStep         ;// double dstStep
+        SUB      dstStepx2, dstStepx2, #12           ;// double dstStep  minus 12
+       
+LOOP_HOR        
+        M_LDRB   tVal8, [pSrcLeft], +leftStep        ;// tVal8 = pSrcLeft[0 to 3]
+        MUL      tVal6, tVal6, r0x01010101           ;// replicate the val in all the bytes
+        M_LDRB   tVal9, [pSrcLeft], +leftStep        ;// tVal9 = pSrcLeft[4 to 7]
+        MUL      tVal7, tVal7, r0x01010101           ;// replicate the val in all the bytes
+        SUBS     y, y, #1                            ;// y--
+        STR      tVal6, [pDst],  #+4                 ;// store {tVal6} at pDst[0 to 3] 
+        STR      tVal7, [pDst2], #+4                 ;// store {tVal7} at pDst2[0 to 3]
+        STR      tVal6, [pDst],  #+4                 ;// store {tVal6} at pDst[4 to 7]
+        STR      tVal7, [pDst2], #+4                 ;// store {tVal7} at pDst2[4 to 7]
+        MUL      tVal8, tVal8, r0x01010101           ;// replicate the val in all the bytes
+        STR      tVal6, [pDst],  #+4                 ;// store {tVal6} at pDst[8 to 11]
+        STR      tVal7, [pDst2], #+4                 ;// store {tVal7} at pDst2[8 to 11]
+        MUL      tVal9, tVal9, r0x01010101           ;// replicate the val in all the bytes
+        M_STR    tVal6, [pDst], dstStepx2            ;// store {tVal6} at pDst[12 to 15]
+        M_STR    tVal7, [pDst2], dstStepx2           ;// store {tVal7} at pDst2[12 to 15]
+        STR      tVal8, [pDst],  #+4                 ;// store {tVal6} at pDst[0 to 3] 
+        STR      tVal9, [pDst2], #+4                 ;// store {tVal7} at pDst2[0 to 3]
+        STR      tVal8, [pDst],  #+4                 ;// store {tVal6} at pDst[4 to 7]
+        STR      tVal9, [pDst2], #+4                 ;// store {tVal7} at pDst2[4 to 7]
+        STR      tVal8, [pDst],  #+4                 ;// store {tVal6} at pDst[8 to 11]
+        STR      tVal9, [pDst2], #+4                 ;// store {tVal7} at pDst2[8 to 11]
+        M_STR    tVal8, [pDst], dstStepx2            ;// store {tVal6} at pDst[12 to 15]
+        M_LDRB   tVal6, [pSrcLeft], +leftStep        ;// tVal6 = pSrcLeft[0 to 3]
+        M_STR    tVal9, [pDst2], dstStepx2           ;// store {tVal7} at pDst2[12 to 15]
+        M_LDRB   tVal7, [pSrcLeft], +leftStep        ;// tVal7 = pSrcLeft[4 to 7]
+        BNE      LOOP_HOR                            ;// Loop for 3 times
+        MOV      return, #OMX_Sts_NoErr
+        M_EXIT
+        
+OMX_VC_16X16_DC
+        
+        ;// M_STALL ARM1136JS=2
+        
+        MOV      count, #0                           ;// count = 0
+        TST      availability, #OMX_VC_UPPER         ;// if(availability & #OMX_VC_UPPER)
+        BEQ      TST_LEFT                            ;// Jump to Left if not upper
+        LDM      pSrcAbove,{tVal8,tVal9,tVal10,tVal11};// tVal 8 to 11 = pSrcAbove[0 to 15]
+        ADD      count, count, #1                    ;// if upper inc count by 1
+        
+        ;// M_STALL ARM1136JS=2
+        
+        UXTB16   tVal2, tVal8                        ;// pSrcAbove[0, 2]
+        UXTB16   tVal6, tVal9                        ;// pSrcAbove[4, 6]
+        UADD16   tVal2, tVal2, tVal6                 ;// pSrcAbove[0, 2] + pSrcAbove[4, 6]
+        UXTB16   tVal8, tVal8, ROR #8                ;// pSrcAbove[1, 3]
+        UXTB16   tVal9, tVal9, ROR #8                ;// pSrcAbove[5, 7]
+        UADD16   tVal8, tVal8, tVal9                 ;// pSrcAbove[1, 3] + pSrcAbove[5, 7]
+        UADD16   tVal2, tVal2, tVal8                 ;// sum(pSrcAbove[0] to pSrcAbove[7])
+        
+        UXTB16   tVal8, tVal10                       ;// pSrcAbove[8, 10]
+        UXTB16   tVal9, tVal11                       ;// pSrcAbove[12, 14]
+        UADD16   tVal8, tVal8, tVal9                 ;// pSrcAbove[8, 10] + pSrcAbove[12, 14]
+        UXTB16   tVal10, tVal10, ROR #8              ;// pSrcAbove[9, 11]
+        UXTB16   tVal11, tVal11, ROR #8              ;// pSrcAbove[13, 15]
+        UADD16   tVal10, tVal10, tVal11              ;// pSrcAbove[9, 11] + pSrcAbove[13, 15]
+        UADD16   tVal8, tVal8, tVal10                ;// sum(pSrcAbove[8] to pSrcAbove[15])
+        
+        UADD16   tVal2, tVal2, tVal8                 ;// sum(pSrcAbove[0] to pSrcAbove[15])
+        
+        ;// M_STALL ARM1136JS=1
+        
+        ADD      tVal2, tVal2, tVal2, LSR #16        ;// sum(pSrcAbove[0] to pSrcAbove[15])
+        
+        ;// M_STALL ARM1136JS=1
+        
+        UXTH     sum, tVal2                          ;// Extract the lower half for result
+        
+TST_LEFT        
+        TST      availability, #OMX_VC_LEFT
+        BEQ      TST_COUNT
+        ADD      leftStepx2, leftStep,leftStep       ;// leftStepx2 = 2 * leftStep
+        ADD      pSrcLeft2, pSrcLeft, leftStep       ;// pSrcLeft2 = pSrcLeft + leftStep
+        
+        M_LDRB   tVal8, [pSrcLeft],  +leftStepx2     ;// tVal8 = pSrcLeft[0]
+        M_LDRB   tVal9, [pSrcLeft2], +leftStepx2     ;// tVal9 = pSrcLeft[1]
+        M_LDRB   tVal10, [pSrcLeft], +leftStepx2     ;// tVal10= pSrcLeft[2]
+        M_LDRB   tVal11, [pSrcLeft2],+leftStepx2     ;// tVal11= pSrcLeft[3]
+        ADD      tVal7, tVal8, tVal9                 ;// tVal7 = tVal8 + tVal9
+        ADD      count, count, #1                    ;// Inc Counter if Left is available
+        ADD      tVal6, tVal10, tVal11               ;// tVal6 = tVal10 + tVal11
+        
+        M_LDRB   tVal8, [pSrcLeft],  +leftStepx2     ;// tVal8 = pSrcLeft[0]
+        M_LDRB   tVal9, [pSrcLeft2], +leftStepx2     ;// tVal9 = pSrcLeft[1]
+        M_LDRB   tVal10, [pSrcLeft], +leftStepx2     ;// tVal10= pSrcLeft[2]
+        M_LDRB   tVal11, [pSrcLeft2],+leftStepx2     ;// tVal11= pSrcLeft[3]
+        ADD      sum, tVal7, tVal6                   ;// sum = tVal8 + tVal10
+        ADD      tVal8, tVal8, tVal9                 ;// tVal8 = tVal8 + tVal9
+        ADD      tVal10, tVal10, tVal11              ;// tVal10= tVal10 + tVal11
+        ADD      tVal7, tVal8, tVal10                ;// tVal7 = tVal8 + tVal10
+        
+        
+        M_LDRB   tVal8, [pSrcLeft],  +leftStepx2     ;// tVal8 = pSrcLeft[0]
+        M_LDRB   tVal9, [pSrcLeft2], +leftStepx2     ;// tVal9 = pSrcLeft[1]
+        M_LDRB   tVal10, [pSrcLeft], +leftStepx2     ;// tVal10= pSrcLeft[2]
+        M_LDRB   tVal11, [pSrcLeft2],+leftStepx2     ;// tVal11= pSrcLeft[3]
+        ADD      sum, sum, tVal7                     ;// sum = sum + tVal7
+        ADD      tVal8, tVal8, tVal9                 ;// tVal8 = tVal8 + tVal9
+        ADD      tVal10, tVal10, tVal11              ;// tVal10= tVal10 + tVal11
+        ADD      tVal7, tVal8, tVal10                ;// tVal7 = tVal8 + tVal10
+        
+        
+        M_LDRB   tVal8, [pSrcLeft],  +leftStepx2     ;// tVal8 = pSrcLeft[0]
+        M_LDRB   tVal9, [pSrcLeft2], +leftStepx2     ;// tVal9 = pSrcLeft[1]
+        M_LDRB   tVal10, [pSrcLeft], +leftStepx2     ;// tVal10= pSrcLeft[2]
+        M_LDRB   tVal11, [pSrcLeft2],+leftStepx2     ;// tVal11= pSrcLeft[3]
+        ADD      sum, sum, tVal7                     ;// sum = sum + tVal7
+        ADD      tVal8, tVal8, tVal9                 ;// tVal8 = tVal8 + tVal9
+        ADD      tVal10, tVal10, tVal11              ;// tVal10= tVal10 + tVal11
+        ADD      tVal7, tVal8, tVal10                ;// tVal7 = tVal8 + tVal10
+        ADD      sum, sum, tVal7                     ;// sum = sum + tVal7
+
+TST_COUNT        
+        CMP      count, #0                           ;// if(count == 0)
+        MOVEQ    sum, #128                           ;// sum = 128 if(count == 0)
+        BEQ      TST_COUNT0                          ;// if(count == 0)
+        CMP      count, #1                           ;// if(count == 1)
+        ADDEQ    sum, sum, #8                        ;// sum += 8 if(count == 1)
+        ADDNE    sum, sum, tVal2                     ;// sum = sumleft + sumupper
+        ADDNE    sum, sum, #16                       ;// sum += 16 if(count == 2)
+        
+        ;// M_STALL ARM1136JS=1
+        
+        UXTH     sum, sum                            ;// sum only byte rest cleared
+        
+        ;// M_STALL ARM1136JS=1
+        
+        LSREQ    sum, sum, #4                        ;// sum >> 4 if(count == 1)
+        
+        ;// M_STALL ARM1136JS=1
+        
+        LSRNE    sum, sum, #5                        ;// sum >> 5 if(count == 2)
+
+TST_COUNT0
+        
+        ;// M_STALL ARM1136JS=1
+        
+        ORR      sum, sum, sum, LSL #8               ;// sum replicated in two halfword
+        
+        ;// M_STALL ARM1136JS=1
+        
+        ORR      tVal6, sum, sum, LSL #16            ;// sum  replicated in all bytes
+        CPY      tVal7, tVal6                        ;// tVal1 = tVal0
+        CPY      tVal8, tVal6                        ;// tVal2 = tVal0
+        CPY      tVal9, tVal6                        ;// tVal3 = tVal0
+        ADD      dstStepx2, dstStep, dstStep         ;// double dstStep
+        ADD      pDst2, pDst, dstStep                ;// pDst2- pDst advanced by dstStep
+        MOV      y, #BLK_SIZE                        ;// Outer Loop Count
+        
+LOOP_DC        
+        STM      pDst, {tVal6,tVal7,tVal8,tVal9}     ;// pDst[0 to 15] = tVal 6 to 9
+        SUBS     y, y, #2                            ;// y--
+        ADD      pDst, pDst, dstStepx2               ;// pDst advanced by dstStep
+        STM      pDst2, {tVal6,tVal7,tVal8,tVal9}    ;// pDst2[16 to 31] = tVal 6 to 9
+        ADD      pDst2, pDst2, dstStepx2             ;// pDst advanced by dstStep
+        BNE      LOOP_DC                             ;// Loop for 8 times
+        
+        MOV      return, #OMX_Sts_NoErr
+        M_EXIT
+
+OMX_VC_16X16_PLANE
+        
+        ;// M_STALL ARM1136JS=3
+        RSB      tVal14, leftStep, leftStep, LSL #4  ;// tVal14 = 15*leftStep
+        
+        ;// M_STALL ARM1136JS=2
+        LDRB     tVal10, [pSrcLeft,  tVal14]         ;// tVal10 = pSrcLeft[15*leftStep]
+        LDRB     tVal11, [pSrcAboveLeft]             ;// tVal11 = pSrcAboveLeft[0]
+        LDRB     tVal12, [pSrcAbove, #15]
+
+        ADD      tVal2,  tVal12,  tVal10             ;// tVal2  = pSrcAbove[15] + pSrcLeft[15*leftStep]
+        SUB      tVal10, tVal10,  tVal11             ;// tVal10 = V0 = pSrcLeft[15*leftStep] - pSrcAboveLeft[0]
+        SUB      tVal11, tVal12,  tVal11             ;// tVal11 = H0 = pSrcAbove[15] - pSrcAboveLeft[0]
+        MOV      tVal2,  tVal2,   LSL #4             ;// tVal2  = a = 16 * (pSrcAbove[15] + pSrcLeft[15*leftStep])
+
+        MOV     tVal11, tVal11, LSL #3              ;// 8*[15]-[-1]
+        LDRB    tVal6, [pSrcAbove, #0]
+        LDRB    tVal7, [pSrcAbove, #14]
+        SUB     tVal8, tVal7, tVal6
+        RSB     tVal8, tVal8, tVal8, LSL #3         ;// 7*[14]-[0]
+        ADD     tVal11, tVal11, tVal8
+        LDRB    tVal6, [pSrcAbove, #1]
+        LDRB    tVal7, [pSrcAbove, #13]
+        SUB     tVal8, tVal7, tVal6
+        ADD     tVal8, tVal8, tVal8
+        ADD     tVal8, tVal8, tVal8, LSL #1         ;// 6*[13]-[1]
+        ADD     tVal11, tVal11, tVal8
+        LDRB    tVal6, [pSrcAbove, #2]
+        LDRB    tVal7, [pSrcAbove, #12]
+        SUB     tVal8, tVal7, tVal6
+        ADD     tVal8, tVal8, tVal8, LSL #2         ;// 5*[12]-[2]
+        ADD     tVal11, tVal11, tVal8
+        LDRB    tVal6, [pSrcAbove, #3]
+        LDRB    tVal7, [pSrcAbove, #11]
+        SUB     tVal8, tVal7, tVal6
+        ADD     tVal11, tVal11, tVal8, LSL #2       ;// + 4*[11]-[3]
+        LDRB    tVal6, [pSrcAbove, #4]
+        LDRB    tVal7, [pSrcAbove, #10]
+        SUB     tVal8, tVal7, tVal6
+        ADD     tVal8, tVal8, tVal8, LSL #1         ;// 3*[10]-[4]
+        ADD     tVal11, tVal11, tVal8
+        LDRB    tVal6, [pSrcAbove, #5]
+        LDRB    tVal7, [pSrcAbove, #9]
+        SUB     tVal8, tVal7, tVal6
+        ADD     tVal11, tVal11, tVal8, LSL #1       ;// + 2*[9]-[5]
+        LDRB    tVal6, [pSrcAbove, #6]
+        LDRB    tVal7, [pSrcAbove, #8]
+        SUB     tVal8, tVal7, tVal6                 ;// 1*[8]-[6]
+        ADD     tVal7, tVal11, tVal8
+
+        ADD      tVal2,  tVal2,   #16                ;// tVal2  = a + 16
+        MOV      tVal1,  pSrcLeft                    ;// tVal4  = pSrcLeft
+        SUB      tVal9,  tVal14,   leftStep          ;// tVal9  = 14*leftStep
+        ADD      tVal9,  pSrcLeft, tVal9             ;// tVal9  = pSrcLeft + 14*leftStep
+        
+        M_LDRB   tVal8,  [tVal9], -leftStep          ;// tVal8  = pSrcLeft[14*leftStep]
+        M_LDRB   tVal11, [tVal1], +leftStep          ;// tVal11 = pSrcLeft[0]
+        ADD      tVal7,  tVal7,  tVal7,  LSL #2      ;// tVal7  = 5 * H
+        ADD      tVal7,  tVal7,  #32                 ;// tVal7  = 5 * H + 32
+        SUB      tVal8,  tVal8,  tVal11              ;// tVal8  = pSrcLeft[14*leftStep] - pSrcLeft[0]
+        ASR      tVal12, tVal7,  #6                  ;// tVal12 = b = (5 * H + 32) >> 6
+        
+        RSB      tVal8,  tVal8,  tVal8,  LSL #3      ;// tVal8  = V1 = 7* (pSrcLeft[14*leftStep]-pSrcLeft[0])
+        ADD      tVal6,  tVal8,  tVal10, LSL #3      ;// tVal6  = V = V0 +V1
+        M_LDRB   tVal8,  [tVal9], -leftStep          ;// tVal8  = pSrcLeft[13*leftStep]
+        M_LDRB   tVal10, [tVal1], +leftStep          ;// tVal10 = pSrcLeft[leftStep]
+        RSB      tVal7,  tVal12,  tVal12,  LSL #3    ;// tVal7  = 7*b
+        SUB      tVal2,  tVal2,   tVal7              ;// tVal2  = a + 16 - 7*b
+        SUB      tVal7,  tVal8,   tVal10             ;// tVal7  = pSrcLeft[13*leftStep] - pSrcLeft[leftStep]
+        M_LDRB   tVal8,  [tVal9], -leftStep          ;// tVal8  = pSrcLeft[12*lS]
+        ADD      tVal7,  tVal7,   tVal7              ;// tVal7  = 2 * (pSrcLeft[13*leftStep] - pSrcLeft[leftStep])
+        M_LDRB   tVal10, [tVal1], +leftStep          ;// tVal10 = pSrcLeft[2*leftStep]        
+        ADD      tVal7,  tVal7,   tVal7,  LSL #1     ;// tVal7  = 6 * (pSrcLeft[13*leftStep] - pSrcLeft[leftStep])
+        ADD      tVal6,  tVal6,   tVal7              ;// tVal6  = V = V + V2
+        SUB      tVal7,  tVal8,   tVal10             ;// tVal7  = pSrcLeft[12*leftStep] - pSrcLeft[2*leftStep]
+        M_LDRB   tVal8,  [tVal9], -leftStep          ;// tVal8  = pSrcLeft[11*leftStep]
+        M_LDRB   tVal10, [tVal1], +leftStep          ;// tVal10 = pSrcLeft[3*leftStep]
+        ADD      tVal7,  tVal7,   tVal7,  LSL #2     ;// tVal7  = 5 * (pSrcLeft[12*leftStep] - pSrcLeft[2*leftStep])
+        ADD      tVal6,  tVal6,   tVal7              ;// tVal6  = V = V + V3
+        SUB      tVal7,  tVal8,   tVal10             ;// tVal7  = pSrcLeft[11*leftStep] - pSrcLeft[3*leftStep]
+        M_LDRB   tVal8,  [tVal9], -leftStep          ;// tVal8  = pSrcLeft[10*leftStep]
+        M_LDRB   tVal10, [tVal1], +leftStep          ;// tVal10 = pSrcLeft[4*leftStep]
+        ADD      tVal6,  tVal6,   tVal7,  LSL #2     ;// tVal6  = V = V + V4
+        SUB      dstStep, dstStep, #16               ;// tVal5  = dstStep - 16
+        SUB      tVal7,  tVal8,   tVal10             ;// tVal7  = pSrcLeft[10*leftStep] - pSrcLeft[4*leftStep]
+        M_LDRB   tVal8,  [tVal9], -leftStep          ;// tVal8  = pSrcLeft[9*leftStep]
+        M_LDRB   tVal10, [tVal1], +leftStep          ;// tVal10 = pSrcLeft[5*leftStep]
+        ADD      tVal7,  tVal7,   tVal7,  LSL #1     ;// tVal7  = 3 * (pSrcLeft[10*leftStep] - pSrcLeft[4*leftStep])
+        ADD      tVal6,  tVal6,   tVal7              ;// tVal6  = V = V + V5
+        SUB      tVal7,  tVal8,   tVal10             ;// tVal7  = pSrcLeft[9*leftStep] - pSrcLeft[5*leftStep]
+        M_LDRB   tVal8,  [tVal9], -leftStep          ;// tVal8  = pSrcLeft[8*leftStep]
+        M_LDRB   tVal10, [tVal1], +leftStep          ;// tVal10 = pSrcLeft[6*leftStep]
+        ADD      tVal6,  tVal6,   tVal7,  LSL #1     ;// tVal6  = V = V + V6
+        
+        ;// M_STALL ARM1136JS=1
+        SUB      tVal7,  tVal8,   tVal10             ;// tVal7  = pSrcLeft[8*leftStep] - pSrcLeft[6*leftStep]
+        ADD      tVal6,  tVal6,   tVal7              ;// tVal6  = V = V + V7
+        
+        ;// M_STALL ARM1136JS=1
+        ADD      tVal6,  tVal6,   tVal6,  LSL #2     ;// tVal6  = 5*V
+        ADD      tVal6,  tVal6,   #32                ;// tVal6  = 5*V + 32
+        
+        ;// M_STALL ARM1136JS=1
+        ASR      tVal14, tVal6,   #6                 ;// tVal14 = c = (5*V + 32)>>6
+        
+        ;// M_STALL ARM1136JS=1
+        RSB      tVal6,  tVal14,  tVal14, LSL #3     ;// tVal6  = 7*c
+        UXTH     tVal14, tVal14                      ;// tVal14 = Cleared the upper half word
+        ADD      tVal10, tVal12,  tVal12             ;// tVal10 = 2*b
+        ORR      tVal14, tVal14,  tVal14, LSL #16    ;// tVal14 = {c  ,  c}
+        SUB      tVal6,  tVal2,   tVal6              ;// tVal6  = d = a - 7*b - 7*c + 16
+        ADD      tVal1,  tVal6,   tVal10             ;// tVal1  = pp2 = d + 2*b
+        ADD      tVal10, tVal10,  tVal12             ;// tVal10 =3*b
+        ORR      tVal0,  tVal6,   tVal1,  LSL #16    ;// tval0  = p2p0   = pack {p2, p0}
+        UXTH     tVal12, tVal12                      ;// tVal12 = Cleared the upper half word
+        UXTH     tVal10, tVal10                      ;// tVal12 = Cleared the upper half word
+        ORR      tVal12, tVal12,  tVal12, LSL #16    ;// tVal12 = {b  ,  b}
+        ORR      tVal10, tVal10,  tVal10, LSL #16    ;// tVal10 = {3b , 3b}
+        SADD16   tVal1,  tVal0,   tVal12             ;// tVal1  = p3p1   = p2p0   + {b,b}
+        SADD16   tVal2,  tVal1,   tVal10             ;// tVal2  = p6p4   = p3p1   + {3b,3b}
+        SADD16   tVal4,  tVal2,   tVal12             ;// tVal4  = p7p5   = p6p4   + {b,b}
+        SADD16   tVal6,  tVal4,   tVal10             ;// tVal6  = p10p8  = p7p5   + {3b,3b}
+        SADD16   tVal7,  tVal6,   tVal12             ;// tVal7  = p11p9  = p10p8  + {b,b}
+        SADD16   tVal8,  tVal7,   tVal10             ;// tVal8  = p14p12 = p11p9  + {3b,3b}
+        SADD16   tVal9,  tVal8,   tVal12             ;// tVal9  = p15p13 = p14p12 + {b,b}
+        LDR      r0x00FF00FF,     =MASK_CONST        ;// r0x00FF00FF = 0x00FF00FF
+        
+LOOP_PLANE        
+
+        USAT16   temp2, #13, p3p1
+        USAT16   temp1, #13, p2p0
+        SADD16   p3p1,   p3p1,   c                    
+        SADD16   p2p0,   p2p0,   c                    
+        AND      temp2, r0x00FF00FF, temp2, ASR #5
+        AND      temp1, r0x00FF00FF, temp1, ASR #5
+        ORR      temp1, temp1, temp2, LSL #8
+        STR      temp1, [pDst], #4
+        
+        USAT16   temp2, #13, p7p5
+        USAT16   temp1, #13, p6p4
+        SADD16   p7p5,   p7p5,   c                    
+        SADD16   p6p4,   p6p4,   c                    
+        AND      temp2, r0x00FF00FF, temp2, ASR #5
+        AND      temp1, r0x00FF00FF, temp1, ASR #5
+        ORR      temp1, temp1, temp2, LSL #8
+        STR      temp1, [pDst], #4
+        
+        USAT16   temp2, #13, p11p9
+        USAT16   temp1, #13, p10p8
+        SADD16   p11p9,  p11p9,  c                    
+        SADD16   p10p8,  p10p8,  c                    
+        AND      temp2, r0x00FF00FF, temp2, ASR #5
+        AND      temp1, r0x00FF00FF, temp1, ASR #5
+        ORR      temp1, temp1, temp2, LSL #8
+        STR      temp1, [pDst], #4
+        
+        USAT16   temp2, #13, p15p13
+        USAT16   temp1, #13, p14p12
+        SADD16   p15p13, p15p13, c                    
+        SADD16   p14p12, p14p12, c                    
+        AND      temp2, r0x00FF00FF, temp2, ASR #5
+        AND      temp1, r0x00FF00FF, temp1, ASR #5
+        ORR      temp1, temp1, temp2, LSL #8
+        STR      temp1, [pDst], #4
+        
+        ADDS     r0x00FF00FF, r0x00FF00FF, #1<<28     ;// Loop counter value in top 4 bits
+        
+        ADD      pDst, pDst, dstStep                   
+        
+        BCC      LOOP_PLANE                           ;// Loop for 16 times
+        MOV      return, #OMX_Sts_NoErr
+        M_END
+        
+        ENDIF ;// ARM1136JS
+
+            
+        END
+;-----------------------------------------------------------------------------------------------
+; omxVCM4P10_PredictIntra_16x16 ends
+;-----------------------------------------------------------------------------------------------
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_PredictIntra_4x4_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_PredictIntra_4x4_s.s
new file mode 100644
index 0000000..a90f4604
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_PredictIntra_4x4_s.s
@@ -0,0 +1,567 @@
+;//
+;// 
+;// File Name:  omxVCM4P10_PredictIntra_4x4_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   9641
+;// Date:       Thursday, February 7, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+        
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+        
+;// Define the processor variants supported by this file
+         
+         M_VARIANTS ARM1136JS
+        
+;//-------------------------------------------------------
+;// This table for implementing switch case of C in asm by
+;// the mehtod of two levels of indexing.
+;//-------------------------------------------------------
+
+    M_TABLE armVCM4P10_pSwitchTable4x4
+    DCD  OMX_VC_4x4_VERT,     OMX_VC_4x4_HOR 
+    DCD  OMX_VC_4x4_DC,       OMX_VC_4x4_DIAG_DL
+    DCD  OMX_VC_4x4_DIAG_DR,  OMX_VC_4x4_VR
+    DCD  OMX_VC_4x4_HD,       OMX_VC_4x4_VL
+    DCD  OMX_VC_4x4_HU   
+    
+    IF ARM1136JS
+  
+;//--------------------------------------------
+;// Constants
+;//--------------------------------------------  
+BLK_SIZE              EQU 0x8
+MUL_CONST0            EQU 0x01010101
+ADD_CONST1            EQU 0x80808080
+
+;//--------------------------------------------
+;// Scratch variable
+;//--------------------------------------------
+return          RN 0
+pTable          RN 9
+pc              RN 15
+r0x01010101     RN 1
+r0x80808080     RN 0
+
+tVal0           RN 0
+tVal1           RN 1
+tVal2           RN 2
+tVal4           RN 4
+tVal6           RN 6
+tVal7           RN 7
+tVal8           RN 8
+tVal9           RN 9
+tVal10          RN 10
+tVal11          RN 11
+tVal12          RN 12
+tVal14          RN 14
+
+Out0            RN 6
+Out1            RN 7
+Out2            RN 8
+Out3            RN 9
+
+Left0           RN 6
+Left1           RN 7
+Left2           RN 8
+Left3           RN 9
+
+Above0123       RN 12
+Above4567       RN 14
+
+AboveLeft       RN 10
+
+;//--------------------------------------------
+;// Declare input registers
+;//--------------------------------------------
+pSrcLeft        RN 0    ;// input pointer
+pSrcAbove       RN 1    ;// input pointer
+pSrcAboveLeft   RN 2    ;// input pointer
+pDst            RN 3    ;// output pointer
+leftStep        RN 4    ;// input variable
+dstStep         RN 5    ;// input variable
+predMode        RN 6    ;// input variable
+availability    RN 7    ;// input variable
+
+;//-----------------------------------------------------------------------------------------------
+;// omxVCM4P10_PredictIntra_4x4 starts
+;//-----------------------------------------------------------------------------------------------
+        
+        ;// Write function header
+        M_START omxVCM4P10_PredictIntra_4x4, r11
+        
+        ;// Define stack arguments
+        M_ARG    LeftStep,     4
+        M_ARG    DstStep,      4
+        M_ARG    PredMode,     4
+        M_ARG    Availability, 4
+        
+        ;// M_STALL ARM1136JS=4
+        
+        LDR      pTable,=armVCM4P10_pSwitchTable4x4  ;// Load index table for switch case
+        
+        ;// Load argument from the stack
+        M_LDR    predMode, PredMode                  ;// Arg predMode loaded from stack to reg 
+        M_LDR    leftStep, LeftStep                  ;// Arg leftStep loaded from stack to reg 
+        M_LDR    dstStep,  DstStep                   ;// Arg dstStep loaded from stack to reg         
+        M_LDR    availability, Availability          ;// Arg availability loaded from stack to reg 
+        
+        LDR      pc, [pTable, predMode, LSL #2]      ;// Branch to the case based on preMode
+
+OMX_VC_4x4_VERT
+        
+        LDR      Above0123,  [pSrcAbove]             ;// Above0123 = pSrcAbove[0 to 3]
+        M_STR    Above0123,  [pDst],  dstStep        ;// pDst[0  to 3]  = Above0123
+        M_STR    Above0123,  [pDst],  dstStep        ;// pDst[4  to 7]  = Above0123
+        M_STR    Above0123,  [pDst],  dstStep        ;// pDst[8  to 11] = Above0123
+        STR      Above0123,  [pDst]                  ;// pDst[12 to 15] = Above0123
+        MOV      return, #OMX_Sts_NoErr
+        M_EXIT                                      ;// Macro to exit midway-break frm case
+
+OMX_VC_4x4_HOR
+        
+        ;// M_STALL ARM1136JS=6 
+        
+        LDR      r0x01010101,  =MUL_CONST0           ;// Const to repeat the byte in reg 4 times
+        M_LDRB   Left0,  [pSrcLeft],  leftStep       ;// Left0 = pSrcLeft[0]
+        M_LDRB   Left1,  [pSrcLeft],  leftStep       ;// Left1 = pSrcLeft[1]
+        M_LDRB   Left2,  [pSrcLeft],  leftStep       ;// Left2 = pSrcLeft[2]
+        LDRB     Left3,  [pSrcLeft]                  ;// Left3 = pSrcLeft[3]
+        MUL      Out0,   Left0,   r0x01010101        ;// replicate the val in all the bytes
+        MUL      Out1,   Left1,   r0x01010101        ;// replicate the val in all the bytes
+        MUL      Out2,   Left2,   r0x01010101        ;// replicate the val in all the bytes
+        MUL      Out3,   Left3,   r0x01010101        ;// replicate the val in all the bytes
+        M_STR    Out0,   [pDst],  dstStep            ;// store {Out0} at pDst [0  to 3 ] 
+        M_STR    Out1,   [pDst],  dstStep            ;// store {Out1} at pDst [4  to 7 ]
+        M_STR    Out2,   [pDst],  dstStep            ;// store {Out2} at pDst [8  to 11]
+        STR      Out3,   [pDst]                      ;// store {Out3} at pDst [12 to 15]
+        MOV      return, #OMX_Sts_NoErr
+        M_EXIT                                       ;// Macro to exit midway-break frm case
+        
+OMX_VC_4x4_DC
+        
+        ;// M_STALL ARM1136JS=6
+        
+        AND      availability,  availability,  #(OMX_VC_UPPER + OMX_VC_LEFT)
+        CMP      availability,  #(OMX_VC_UPPER + OMX_VC_LEFT)
+        BNE      UpperOrLeftOrNoneAvailable          ;// Jump to Upper if not both
+        LDR      Above0123,  [pSrcAbove]             ;// Above0123  = pSrcAbove[0 to 3]
+        
+        ;// M_STALL ARM1136JS=1
+        
+        UXTB16   tVal7,  Above0123                   ;// pSrcAbove[0, 2]
+        UXTB16   tVal6,  Above0123,  ROR #8          ;// pSrcAbove[1, 3]
+        UADD16   tVal11, tVal6,   tVal7              ;// pSrcAbove[0, 2] + pSrcAbove[1, 3]
+        M_LDRB   Left0,  [pSrcLeft],  leftStep       ;// Left0 = pSrcLeft[0]
+        M_LDRB   Left1,  [pSrcLeft],  leftStep       ;// Left1 = pSrcLeft[1]
+        ADD      tVal11, tVal11,  LSR #16            ;// sum(pSrcAbove[0] to pSrcAbove[3])
+        M_LDRB   Left2,  [pSrcLeft],  leftStep       ;// Left2 = pSrcLeft[2]
+        LDRB     Left3,  [pSrcLeft]                  ;// Left3 = pSrcLeft[3]
+        UXTH     tVal11, tVal11                      ;// upsum1 (Clear the top junk bits)
+        ADD      tVal6,  Left0,  Left1               ;// tVal6 = Left0 + Left1
+        ADD      tVal7,  Left2,  Left3               ;// tVal7 = Left2 + Left3
+        ADD      tVal6,  tVal6,  tVal7               ;// tVal6 = tVal6 + tVal7
+        ADD      Out0,   tVal6,  tVal11              ;// Out0  = tVal6 + tVal11   
+        ADD      Out0,   Out0,   #4                  ;// Out0  = Out0 + 4
+        LDR      r0x01010101,   =MUL_CONST0          ;// 0x01010101
+        MOV      Out0,   Out0,  LSR #3               ;// Out0 = (Out0 + 4)>>3
+        
+        ;// M_STALL ARM1136JS=1
+        
+        MUL      Out0,   Out0,  r0x01010101          ;// replicate the val in all the bytes
+        
+        ;// M_STALL ARM1136JS=1
+        
+        MOV      return,  #OMX_Sts_NoErr
+        M_STR    Out0,   [pDst],  dstStep            ;// store {Out0} at pDst [0  to 3 ]
+        M_STR    Out0,   [pDst],  dstStep            ;// store {Out0} at pDst [4  to 7 ]
+        M_STR    Out0,   [pDst],  dstStep            ;// store {Out0} at pDst [8  to 11]
+        STR      Out0,   [pDst]                      ;// store {Out0} at pDst [12 to 15]
+        M_EXIT                                       ;// Macro to exit midway-break frm case
+        
+UpperOrLeftOrNoneAvailable
+        ;// M_STALL ARM1136JS=3
+        
+        CMP      availability,  #OMX_VC_UPPER        ;// if(availability & #OMX_VC_UPPER)
+        BNE      LeftOrNoneAvailable                 ;// Jump to Left if not upper
+        LDR      Above0123,  [pSrcAbove]             ;// Above0123  = pSrcAbove[0 to 3]
+        
+        ;// M_STALL ARM1136JS=3
+        
+        UXTB16   tVal7,  Above0123                   ;// pSrcAbove[0, 2]
+        UXTB16   tVal6,  Above0123,  ROR #8          ;// pSrcAbove[1, 3]
+        UADD16   Out0,   tVal6,  tVal7               ;// pSrcAbove[0, 2] + pSrcAbove[1, 3]
+        LDR      r0x01010101,   =MUL_CONST0          ;// 0x01010101
+        ADD      Out0,   Out0,   LSR #16             ;// sum(pSrcAbove[0] to pSrcAbove[3])
+        
+        ;// M_STALL ARM1136JS=1
+        
+        UXTH     Out0,   Out0                        ;// upsum1 (Clear the top junk bits)
+        ADD      Out0,   Out0,   #2                  ;// Out0  = Out0 + 2
+        
+        ;// M_STALL ARM1136JS=1
+        
+        MOV      Out0,   Out0,   LSR #2              ;// Out0  = (Out0 + 2)>>2
+        
+        ;// M_STALL ARM1136JS=1
+        
+        MUL      Out0,   Out0,   r0x01010101         ;// replicate the val in all the bytes
+        
+        ;// M_STALL ARM1136JS=1
+        
+        MOV      return, #OMX_Sts_NoErr
+        M_STR    Out0,   [pDst],  dstStep            ;// store {tVal6} at pDst [0  to 3 ]
+        M_STR    Out0,   [pDst],  dstStep            ;// store {tVal6} at pDst [4  to 7 ] 
+        M_STR    Out0,   [pDst],  dstStep            ;// store {tVal6} at pDst [8  to 11]
+        STR      Out0,   [pDst]                      ;// store {tVal6} at pDst [12 to 15]
+        
+        M_EXIT                                       ;// Macro to exit midway-break frm case
+        
+LeftOrNoneAvailable        
+        ;// M_STALL ARM1136JS=3
+        
+        LDR      r0x01010101,   =MUL_CONST0          ;// 0x01010101
+        CMP      availability, #OMX_VC_LEFT
+        BNE      NoneAvailable
+        M_LDRB   Left0,  [pSrcLeft],  leftStep       ;// Left0 = pSrcLeft[0]
+        M_LDRB   Left1,  [pSrcLeft],  leftStep       ;// Left1 = pSrcLeft[1]
+        M_LDRB   Left2,  [pSrcLeft],  leftStep       ;// Left2 = pSrcLeft[2]
+        LDRB     Left3,  [pSrcLeft]                  ;// Left3 = pSrcLeft[3]
+        ADD      Out0,   Left0,  Left1               ;// Out0  = Left0 + Left1
+        
+        ;// M_STALL ARM1136JS=1
+        
+        ADD      Out1,   Left2,  Left3               ;// Out1  = Left2 + Left3
+        ADD      Out0,   Out0,   Out1                ;// Out0  = Out0  + Out1
+        ADD      Out0,   Out0,   #2                  ;// Out0  = Out0 + 2
+        
+        ;// M_STALL ARM1136JS=1
+        
+        MOV      Out0,   Out0,   LSR #2              ;// Out0  = (Out0 + 2)>>2
+        
+        ;// M_STALL ARM1136JS=1
+        
+        MUL      Out0,   Out0,   r0x01010101         ;// replicate the val in all the bytes
+        
+        ;// M_STALL ARM1136JS=1
+        
+        MOV      return, #OMX_Sts_NoErr
+        M_STR    Out0,   [pDst],  dstStep            ;// store {Out0} at pDst [0  to 3 ]
+        M_STR    Out0,   [pDst],  dstStep            ;// store {Out0} at pDst [4  to 7 ] 
+        M_STR    Out0,   [pDst],  dstStep            ;// store {Out0} at pDst [8  to 11]
+        STR      Out0,   [pDst]                      ;// store {Out0} at pDst [12 to 15]
+        M_EXIT                                       ;// Macro to exit midway-break frm case
+
+NoneAvailable
+        MOV      Out0,   #128                        ;// Out0 = 128 if(count == 0)
+        
+        ;// M_STALL ARM1136JS=5
+        
+        MUL      Out0,   Out0,  r0x01010101          ;// replicate the val in all the bytes
+        
+        ;// M_STALL ARM1136JS=1
+        
+        MOV      return, #OMX_Sts_NoErr
+        M_STR    Out0,   [pDst],  dstStep            ;// store {Out0} at pDst [0  to 3 ]
+        M_STR    Out0,   [pDst],  dstStep            ;// store {Out0} at pDst [4  to 7 ] 
+        M_STR    Out0,   [pDst],  dstStep            ;// store {Out0} at pDst [8  to 11]
+        STR      Out0,   [pDst]                      ;// store {Out0} at pDst [12 to 15]
+        M_EXIT                                       ;// Macro to exit midway-break frm case
+        
+OMX_VC_4x4_DIAG_DL
+        
+        ;//------------------------------------------------------------------
+        ;// f = (a+2*b+c+2)>>2
+        ;// Calculate as:
+        ;// d = (a + c )>>1
+        ;// e = (d - b')>>1
+        ;// f = e + 128
+        ;//------------------------------------------------------------------
+        
+        ;// M_STALL ARM1136JS=3
+        
+        TST      availability, #OMX_VC_UPPER_RIGHT                  
+        LDMIA    pSrcAbove,  {Above0123, Above4567}  ;// Above0123, Above4567 = pSrcAbove[0 to 7]
+        LDR      r0x80808080,  =ADD_CONST1           ;// 0x80808080
+        BNE      DLUpperRightAvailable
+        LDR      r0x01010101,  =MUL_CONST0           ;// 0x01010101
+        MOV      tVal7,  Above0123,  LSR #24         ;// {00,  00,  00,  U3 }
+        MOV      tVal11, tVal7,  LSL #24             ;// {U3,  00,  00,  00 }
+        MUL      Out3,   tVal7,  r0x01010101         ;// {U3,  U3,  U3,  U3 } 
+        MOV      tVal8,  Above0123,  LSR #16         ;// {00,  00,  U3,  U2 }
+        MOV      tVal10, Above0123,  LSR #8          ;// {00,  U3,  U2,  U1 }
+        MVN      tVal10, tVal10                      ;// {00', U3', U2', U1'}
+        UHADD8   tVal8,  tVal8,  Above0123           ;// {xx,  xx,  d1,  d0 }
+        UHADD8   tVal6,  Above0123,  tVal9           ;// {xx,  d2,  xx,  xx }
+        UHSUB8   tVal8,  tVal8,  tVal10              ;// {xx,  xx,  e1,  e0 }
+        UHSUB8   tVal6,  tVal6,  tVal10              ;// {xx,  e2,  xx,  xx }
+        UADD8    tVal8,  tVal8,  r0x80808080         ;// {xx,  xx,  f1,  f0 }
+        UADD8    tVal6,  tVal6,  r0x80808080         ;// {xx,  f2,  xx,  xx }
+        
+        ;// M_STALL ARM1136JS=1
+        
+        PKHBT    tVal6,  tVal8,  tVal6               ;// {xx,  f2,  f1,  f0 }
+        BIC      tVal6,  tVal6,  #0xFF000000         ;// {00,  f2,  f1,  f0 }
+        ORR      Out0,   tVal6,  tVal11              ;// {U3,  f2,  f1,  f0 }
+        
+        ;// M_STALL ARM1136JS=1
+        
+        PKHTB    Out1,   Out3,   Out0,  ASR #8       ;// {U3,  U3,  f2,  f1 }
+        MOV      return, #OMX_Sts_NoErr
+        PKHTB    Out2,   Out3,   Out1,  ASR #8       ;// {U3,  U3,  U3,  f2 }
+        
+        M_STR    Out0,   [pDst], dstStep             ;// store {f3 to f0} at pDst[3  to 0 ]
+        M_STR    Out1,   [pDst], dstStep             ;// store {f4 to f1} at pDst[7  to 4 ]
+        M_STR    Out2,   [pDst], dstStep             ;// store {f5 to f2} at pDst[11 to 8 ]
+        STR      Out3,   [pDst]                      ;// store {f6 to f3} at pDSt[15 to 12]
+        M_EXIT                                       ;// Macro to exit midway-break frm case
+
+DLUpperRightAvailable        
+        
+        MOV      tVal8,  Above0123,  LSR #24         ;// {00,  00,  00,  U3 }
+        MOV      tVal9,  Above0123,  LSR #16         ;// {00,  00,  U3,  U2 }
+        MOV      tVal10, Above0123,  LSR #8          ;// {00,  U3,  U2,  U1 }
+        ORR      tVal8,  tVal8,  Above4567, LSL #8   ;// {U6,  U5,  U4,  U3 }
+        ORR      tVal10, tVal10, Above4567, LSL #24  ;// {U4,  U3,  U2,  U1 }
+        PKHBT    tVal9,  tVal9,  Above4567, LSL #16  ;// {U5,  U4,  U3,  U2 }
+        MVN      tVal1,  tVal8                       ;// {U6', U5', U4', U3'}
+        MVN      tVal10, tVal10                      ;// {U4', U3', U2', U1'}
+        MVN      tVal2,  Above4567                   ;// {U7', U6', U5', U4'}
+        UHADD8   tVal6,  Above0123,  tVal9           ;// {d3,  d2,  d1,  d0 }
+        UHADD8   tVal9,  tVal9,  Above4567           ;// {d5,  d4,  d3,  d2 }
+        UHADD8   tVal8,  Above4567,  tVal8           ;// {d6,  xx,  xx,  xx }
+        UHSUB8   tVal6,  tVal6,  tVal10              ;// {e3,  e2,  e1,  e0 }
+        UHSUB8   tVal12, tVal9,  tVal1               ;// {e5,  e4,  e3,  e2 }
+        UHSUB8   tVal8,  tVal8,  tVal2               ;// {e6,  xx,  xx,  xx }
+        UADD8    Out0,   tVal6,  r0x80808080         ;// {f3,  f2,  f1,  f0 }
+        UADD8    tVal9,  tVal8,  r0x80808080         ;// {f6,  xx,  xx,  xx }
+        UADD8    Out2,   tVal12, r0x80808080         ;// {f5,  f4,  f3,  f2 }
+        MOV      tVal7,  Out0,   LSR #8              ;// {00,  f3,  f2,  f1 }
+        AND      tVal9,  tVal9,  #0xFF000000         ;// {f6,  00,  00,  00 }
+        PKHBT    Out1,   tVal7,  Out2,  LSL #8       ;// {f4,  f3,  f2,  f1 }
+        ORR      Out3,   tVal9,  Out2,  LSR #8       ;// {f6,  f5,  f4,  f3 }
+        M_STR    Out0,   [pDst], dstStep             ;// store {f3 to f0} at pDst[3  to 0 ]
+        M_STR    Out1,   [pDst], dstStep             ;// store {f4 to f1} at pDst[7  to 4 ]
+        M_STR    Out2,   [pDst], dstStep             ;// store {f5 to f2} at pDst[11 to 8 ]
+        STR      Out3,   [pDst]                      ;// store {f6 to f3} at pDSt[15 to 12]
+        MOV      return, #OMX_Sts_NoErr
+        M_EXIT                                       ;// Macro to exit midway-break frm case
+        
+
+OMX_VC_4x4_DIAG_DR
+        
+        ;// M_STALL ARM1136JS=4
+        
+        M_LDRB   Left0,  [pSrcLeft],  leftStep       ;// Left0 = pSrcLeft[0]
+        M_LDRB   Left1,  [pSrcLeft],  leftStep       ;// Left1 = pSrcLeft[1]
+        M_LDRB   Left2,  [pSrcLeft],  leftStep       ;// Left2 = pSrcLeft[2]
+        LDRB     Left3,  [pSrcLeft]                  ;// Left3 = pSrcLeft[3]
+        LDRB     AboveLeft, [pSrcAboveLeft]          ;// AboveLeft = pSrcAboveLeft[0]
+        ORR      tVal7,  Left1,  Left0,  LSL #8      ;// tVal7 = 00 00 L0 L1
+        LDR      Above0123,  [pSrcAbove]             ;// Above0123 = U3 U2 U1 U0
+        LDR      r0x80808080, =ADD_CONST1            ;// 0x80808080
+        ORR      tVal8,  Left3,  Left2,  LSL #8      ;// tVal8 = 00 00 L2 L3
+        PKHBT    tVal7,  tVal8,  tVal7,  LSL #16     ;// tVal7 = L0 L1 L2 L3
+        MOV      tVal8,  Above0123,  LSL #8          ;// tVal8 = U2 U1 U0 00
+        MOV      tVal9,  tVal7,  LSR #8              ;// tVal9 = 00 L0 L1 L2
+        ORR      tVal8,  tVal8,  AboveLeft           ;// tVal8 = U2 U1 U0 UL
+        ORR      tVal9,  tVal9,  AboveLeft, LSL #24  ;// tVal9 = UL L0 L1 L2
+        MOV      tVal10, Above0123,  LSL #24         ;// tVal10= U0 00 00 00
+        UXTB     tVal11, tVal7,  ROR #24             ;// tVal11= 00 00 00 L0
+        ORR      tVal10, tVal10, tVal9,  LSR #8      ;// tVal10= U0 UL L0 L1
+        ORR      tVal11, tVal11, tVal8,  LSL #8      ;// tVal11= U1 U0 UL L0
+        UHADD8   tVal11, Above0123,  tVal11          ;// tVal11= d1 d0 dL g0
+        UHADD8   tVal10, tVal7,  tVal10              ;// tVal10= g0 g1 g2 g3
+        MVN      tVal8,  tVal8                       ;// tVal8 = U2'U1'U0'UL'
+        MVN      tVal9,  tVal9                       ;// tVal9 = UL'L0'L1'L2'
+        UHSUB8   tVal11, tVal11, tVal8               ;// tVal11= e1 e0 eL h0
+        UHSUB8   tVal10, tVal10, tVal9               ;// tVal10= h0 h1 h2 h3
+        UADD8    Out3,   tVal10, r0x80808080         ;// Out3  = i0 i1 i2 i3
+        UADD8    Out0,   tVal11, r0x80808080         ;// Out0  = f1 f0 fL i0
+        UXTH     tVal11, Out3,   ROR #8              ;// tVal11= 00 00 i1 i2
+        MOV      tVal7,  Out0,   LSL #8              ;// tVal7 = f0 fL i0 00
+        ORR      Out1,   tVal7,  tVal11,  LSR #8     ;// Out1  = f0 fL i0 i1
+        PKHBT    Out2,   tVal11, Out0,    LSL #16    ;// Out2  = fL i0 i1 i2
+        M_STR    Out0,   [pDst], dstStep             ;// store {f1 to i0} at pDst[3  to 0 ]
+        M_STR    Out1,   [pDst], dstStep             ;// store {f0 to i1} at pDst[7  to 4 ]
+        M_STR    Out2,   [pDst], dstStep             ;// store {fL to i2} at pDst[11 to 8 ]
+        STR      Out3,   [pDst]                      ;// store {i0 to i3} at pDst[15 to 12] 
+        MOV      return,  #OMX_Sts_NoErr
+        M_EXIT                                       ;// Macro to exit midway-break frm case
+
+OMX_VC_4x4_VR
+
+        ;// M_STALL ARM1136JS=4
+        
+        LDR      Above0123,  [pSrcAbove]             ;// Above0123 = U3 U2 U1 U0
+        LDRB     AboveLeft,  [pSrcAboveLeft]         ;// AboveLeft = 00 00 00 UL
+        M_LDRB   Left0,  [pSrcLeft],  leftStep       ;// Left0     = 00 00 00 L0
+        M_LDRB   Left1,  [pSrcLeft],  leftStep       ;// Left1     = 00 00 00 L1
+        LDRB     Left2,  [pSrcLeft]                  ;// Left2     = 00 00 00 L2
+        MOV      tVal0,  Above0123,  LSL #8          ;// tVal0     = U2 U1 U0 00
+        MOV      tVal9,  Above0123                   ;// tVal9     = U3 U2 U1 U0 
+        ORR      tVal14, tVal0,   AboveLeft          ;// tVal14    = U2 U1 U0 UL
+        MVN      tVal11, tVal14                      ;// tVal11    = U2'U1'U0'UL'
+        MOV      tVal2,  tVal14,  LSL #8             ;// tVal2     = U1 U0 UL 00
+        UHSUB8   tVal1,  Above0123,  tVal11          ;// tVal1     = d2 d1 d0 dL
+        UHADD8   tVal10, AboveLeft, Left1            ;// tVal10    = 00 00 00 j1       
+        MVN      tVal4,  Left0                       ;// tVal4     = 00 00 00 L0'
+        UHSUB8   tVal4,  tVal10,  tVal4              ;// tVal4     = 00 00 00 k1
+        ORR      tVal12, tVal0,   Left0              ;// tVal12    = U2 U1 U0 L0
+        ORR      tVal14, tVal2,   Left0              ;// tVal14    = U1 U0 UL L0
+        LDR      r0x80808080,  =ADD_CONST1           ;// 0x80808080
+        UHADD8   tVal10, tVal9,   tVal14             ;// tVal10    = g3 g2 g1 g0
+        UADD8    Out0,   tVal1,   r0x80808080        ;// Out0      = e2 e1 e0 eL
+        UHSUB8   tVal10, tVal10,  tVal11             ;// tVal10    = h3 h2 h1 h0
+        M_STR    Out0,   [pDst],  dstStep            ;// store {e2 to eL} at pDst[3  to 0 ]
+        MOV      tVal1,  tVal14,  LSL #8             ;// tVal1     = U0 UL L0 00
+        MOV      tVal6,  Out0,    LSL #8             ;// tVal6     = e1 e0 eL 00
+        ORR      tVal2,  tVal2,   Left1              ;// tVal2     = U1 U0 UL L1
+        UADD8    tVal4,  tVal4,   r0x80808080        ;// tVal4     = 00 00 00 l1        
+        UADD8    Out1,   tVal10,  r0x80808080        ;// Out1      = i3 i2 i1 i0
+        MVN      tVal2,  tVal2                       ;// tVal14    = U1'U0'UL'L1'
+        ORR      tVal1,  tVal1,   Left2              ;// tVal1     = U0 UL L0 L2
+        ORR      Out2,   tVal6,   tVal4              ;// Out2      = e1 e0 eL l1
+        UHADD8   tVal1,  tVal1,   tVal12             ;// tVal1     = g2 g1 g0 j2
+        M_STR    Out1,   [pDst],  dstStep            ;// store {i3 to i0} at pDst[7  to 4 ]
+        M_STR    Out2,   [pDst],  dstStep            ;// store {e1 to l1} at pDst[11 to 8 ]
+        UHSUB8   tVal9,  tVal1,   tVal2              ;// tVal9     = h2 h1 h0 k2
+        UADD8    Out3,   tVal9,   r0x80808080        ;// Out3      = i2 i1 i0 l2
+        STR      Out3,   [pDst]                      ;// store {i2 to l2} at pDst[15 to 12] 
+        MOV      return,  #OMX_Sts_NoErr
+        M_EXIT                                       ;// Macro to exit midway-break frm case
+        
+OMX_VC_4x4_HD
+        
+        ;// M_STALL ARM1136JS=4
+        
+        LDR      Above0123,  [pSrcAbove]             ;// Above0123 = U3 U2 U1 U0
+        LDRB     AboveLeft,  [pSrcAboveLeft]         ;// AboveLeft = 00 00 00 UL
+        M_LDRB   Left0,  [pSrcLeft],  leftStep       ;// Left0 = 00 00 00 L0
+        M_LDRB   Left1,  [pSrcLeft],  leftStep       ;// Left1 = 00 00 00 L1
+        M_LDRB   Left2,  [pSrcLeft],  leftStep       ;// Left2 = 00 00 00 L2
+        LDRB     Left3,  [pSrcLeft]                  ;// Left3 = 00 00 00 L3
+        LDR      r0x80808080,  =ADD_CONST1           ;// 0x80808080
+        ORR      tVal2,  AboveLeft, Above0123, LSL #8;// tVal2 = U2 U1 U0 UL
+        MVN      tVal1,  Left0                       ;// tVal1 = 00 00 00 L0'
+        ORR      tVal4,  Left0,  tVal2,  LSL #8      ;// tVal4 = U1 U0 UL L0
+        MVN      tVal2,  tVal2                       ;// tVal2 = U2'U1'U0'UL'
+        UHADD8   tVal4,  tVal4,  Above0123           ;// tVal4 = g3 g2 g1 g0
+        UHSUB8   tVal1,  AboveLeft,  tVal1           ;// tVal1 = 00 00 00 dL
+        UHSUB8   tVal4,  tVal4,  tVal2               ;// tVal4 = h3 h2 h1 h0
+        UADD8    tVal1,  tVal1,  r0x80808080         ;// tVal1 = 00 00 00 eL
+        UADD8    tVal4,  tVal4,  r0x80808080         ;// tVal4 = i3 i2 i1 i0
+        ORR      tVal2,  Left0,  AboveLeft,  LSL #16 ;// tVal2 = 00 UL 00 L0
+        MOV      tVal4,  tVal4,  LSL #8              ;// tVal4 = i2 i1 i0 00
+        ORR      tVal11, Left1,  Left0,  LSL #16     ;// tVal11= 00 L0 00 L1
+        ORR      tVal7,  Left2,  Left1,  LSL #16     ;// tVal7 = 00 L1 00 L2
+        ORR      tVal10, Left3,  Left2,  LSL #16     ;// tVal10= 00 L2 00 L3
+        ORR      Out0,   tVal4,  tVal1               ;// Out0  = i2 i1 i0 eL
+        M_STR    Out0,   [pDst], dstStep             ;// store {Out0}  at pDst [0  to 3 ] 
+        MOV      tVal4,  Out0,   LSL #16             ;// tVal4 = i1 i0 00 00
+        UHADD8   tVal2,  tVal2,  tVal7               ;// tVal2 = 00 j1 00 j2
+        UHADD8   tVal6,  tVal11, tVal10              ;// tVal11= 00 j2 00 j3
+        MVN      tVal12, tVal11                      ;// tVal12= 00 L0'00 L1'
+        MVN      tVal14, tVal7                       ;// tVal14= 00 L1'00 L2'
+        UHSUB8   tVal2,  tVal2,  tVal12              ;// tVal2 = 00 k1 00 k2
+        UHSUB8   tVal8,  tVal7,  tVal12              ;// tVal8 = 00 d1 00 d2
+        UHSUB8   tVal11, tVal6,  tVal14              ;// tVal11= 00 k2 00 k3
+        UHSUB8   tVal9,  tVal10, tVal14              ;// tVal9 = 00 d2 00 d3
+        UADD8    tVal2,  tVal2,  r0x80808080         ;// tVal2 = 00 l1 00 l2
+        UADD8    tVal8,  tVal8,  r0x80808080         ;// tVal8 = 00 e1 00 e2
+        UADD8    tVal11, tVal11, r0x80808080         ;// tVal11= 00 l2 00 l3
+        UADD8    tVal9,  tVal9,  r0x80808080         ;// tVal9 = 00 e2 00 e3
+        ORR      Out2,   tVal8,  tVal2,  LSL #8      ;// Out2  = l1 e1 l2 e2
+        ORR      Out3,   tVal9,  tVal11, LSL #8      ;// Out3  = l2 e2 l3 e3
+        PKHTB    Out1,   tVal4,  Out2,   ASR #16     ;// Out1  = i1 i0 l1 e1
+        M_STR    Out1,   [pDst], dstStep             ;// store {Out1}  at pDst [4  to 7 ]
+        M_STR    Out2,   [pDst], dstStep             ;// store {Out2}  at pDst [8  to 11]
+        STR      Out3,   [pDst]                      ;// store {Out3}  at pDst [12 to 15]
+        MOV      return,  #OMX_Sts_NoErr
+        M_EXIT                                       ;// Macro to exit midway-break frm case
+        
+OMX_VC_4x4_VL
+        
+        ;// M_STALL ARM1136JS=3
+        
+        LDMIA    pSrcAbove, {Above0123, Above4567}   ;// Above0123, Above4567 = pSrcAbove[0 to 7]
+        TST      availability, #OMX_VC_UPPER_RIGHT
+        LDR      r0x80808080,  =ADD_CONST1           ;// 0x80808080
+        LDR      r0x01010101,  =MUL_CONST0           ;// 0x01010101
+        MOV      tVal11, Above0123,  LSR #24         ;// tVal11= 00 00 00 U3
+        MULEQ    Above4567, tVal11, r0x01010101      ;// Above4567 = U3 U3 U3 U3
+        MOV      tVal9,  Above0123,  LSR #8          ;// tVal9 = 00 U3 U2 U1
+        MVN      tVal10, Above0123                   ;// tVal10= U3'U2'U1'U0'
+        ORR      tVal2,  tVal9,  Above4567,  LSL #24 ;// tVal2 = U4 U3 U2 U1
+        UHSUB8   tVal8,  tVal2,  tVal10              ;// tVal8 = d4 d3 d2 d1
+        UADD8    Out0,   tVal8,  r0x80808080         ;// Out0 = e4 e3 e2 e1
+        M_STR    Out0,   [pDst], dstStep             ;// store {Out0}  at pDst [0  to 3 ]
+        MOV      tVal9,  tVal9,  LSR #8              ;// tVal9 = 00 00 U3 U2
+        MOV      tVal10, Above4567,  LSL #8          ;// tVal10= U6 U5 U4 00
+        PKHBT    tVal9,  tVal9,  Above4567, LSL #16  ;// tVal9 = U5 U4 U3 U2
+        ORR      tVal10, tVal10, tVal11              ;// tVal10= U6 U5 U4 U3
+        UHADD8   tVal11, tVal9,  Above0123           ;// tVal11= g5 g4 g3 g2
+        UHADD8   tVal14, tVal2,  tVal10              ;// tVal14= g6 g5 g4 g3
+        MVN      tVal8,  tVal2                       ;// tVal8 = U4'U3'U2'U1'
+        MVN      tVal7,  tVal9                       ;// tVal7 = U5'U4'U3'U2'
+        UHSUB8   tVal12, tVal9,  tVal8               ;// tVal12= d5 d4 d3 d2
+        UHSUB8   tVal11, tVal11, tVal8               ;// tVal11= h5 h4 h3 h2
+        UHSUB8   tVal2,  tVal14, tVal7               ;// tVal2 = h6 h5 h4 h3
+        UADD8    Out1,   tVal11, r0x80808080         ;// Out1  = i5 i4 i3 i2
+        UADD8    Out2,   tVal12, r0x80808080         ;// Out2  = e5 e4 e3 e2
+        UADD8    Out3,   tVal2,  r0x80808080         ;// Out3  = i6 i5 i4 i3
+        M_STR    Out1,   [pDst], dstStep             ;// store {Out1} at pDst [4  to 7 ]
+        M_STR    Out2,   [pDst], dstStep             ;// store {Out2} at pDst [8  to 11]
+        M_STR    Out3,   [pDst], dstStep             ;// store {Out3} at pDst [12 to 15]
+        MOV      return, #OMX_Sts_NoErr
+        M_EXIT                                       ;// Macro to exit midway-break frm case
+        
+OMX_VC_4x4_HU
+        
+        ;// M_STALL ARM1136JS=2
+        
+        LDR      r0x01010101,  =MUL_CONST0           ;// 0x01010101
+        M_LDRB   Left0,  [pSrcLeft],  leftStep       ;// Left0 = pSrcLeft[0]
+        M_LDRB   Left1,  [pSrcLeft],  leftStep       ;// Left1 = pSrcLeft[1]
+        M_LDRB   Left2,  [pSrcLeft],  leftStep       ;// Left2 = pSrcLeft[2]
+        LDRB     Left3,  [pSrcLeft]                  ;// Left3 = pSrcLeft[3]
+        MOV      r0x80808080,  r0x01010101, LSL #7   ;// 0x80808080
+        ORR      tVal6,  Left0,  Left1,  LSL #16     ;// tVal6 = 00 L1 00 L0
+        ORR      tVal7,  Left1,  Left2,  LSL #16     ;// tVal7 = 00 L2 00 L1
+        ORR      tVal11, Left2,  Left3,  LSL #16     ;// tVal11= 00 L3 00 L2
+        MUL      Out3,   Left3,  r0x01010101         ;// Out3  = L3 L3 L3 L3
+        MVN      tVal8,  tVal7                       ;// tVal8 = 00 L2'00 L1'
+        MVN      tVal10, tVal11                      ;// tVal10= 00 L3'00 L2'
+        UHADD8   tVal4,  tVal6,  tVal11              ;// tVal4 = 00 g3 00 g2
+        UXTB16   tVal12, Out3                        ;// tVal12= 00 L3 00 L3
+        UHSUB8   tVal4,  tVal4,  tVal8               ;// tVal4 = 00 h3 00 h2
+        UHSUB8   tVal6,  tVal6,  tVal8               ;// tVal6 = 00 d2 00 d1
+        UHSUB8   tVal11, tVal11, tVal8               ;// tVal11= 00 d3 00 d2
+        UHADD8   tVal12, tVal12, tVal7               ;// tVal12= 00 g4 00 g3
+        UADD8    tVal4,  tVal4,  r0x80808080         ;// tVal4 = 00 i3 00 i2
+        UHSUB8   tVal12, tVal12, tVal10              ;// tVal12= 00 h4 00 h3
+        UADD8    tVal8,  tVal6,  r0x80808080         ;// tVal8 = 00 e2 00 e1
+        UADD8    tVal11, tVal11, r0x80808080         ;// tVal11= 00 e3 00 e2
+        UADD8    tVal12, tVal12, r0x80808080         ;// tVal12= 00 i4 00 i3
+        ORR      Out0,   tVal8,  tVal4,  LSL #8      ;// Out0  = i3 e2 i2 e1
+        ORR      Out1,   tVal11, tVal12, LSL #8      ;// Out1  = i4 e3 i3 e2
+        M_STR    Out0,   [pDst], dstStep             ;// store {Out0}  at pDst [0  to 3 ]
+        PKHTB    Out2,   Out3,   Out1,   ASR #16     ;// Out2  = L3 L3 i4 e3
+        M_STR    Out1,   [pDst], dstStep             ;// store {Out1}  at pDst [4  to 7 ]
+        M_STR    Out2,   [pDst], dstStep             ;// store {Out2}  at pDst [8  to 11]
+        STR      Out3,   [pDst]                      ;// store {Out3}  at pDst [12 to 15]
+        MOV      return,  #OMX_Sts_NoErr
+        M_END
+
+        ENDIF ;// ARM1136JS
+        
+        
+        END
+;//-----------------------------------------------------------------------------------------------
+;// omxVCM4P10_PredictIntra_4x4 ends
+;//-----------------------------------------------------------------------------------------------
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_TransformDequantChromaDCFromPair_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_TransformDequantChromaDCFromPair_s.s
new file mode 100644
index 0000000..53597a8
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_TransformDequantChromaDCFromPair_s.s
@@ -0,0 +1,128 @@
+;//
+;// 
+;// File Name:  omxVCM4P10_TransformDequantChromaDCFromPair_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   9641
+;// Date:       Thursday, February 7, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+        
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+        
+        IMPORT armVCM4P10_QPDivTable
+        IMPORT armVCM4P10_VMatrixQPModTable
+            
+        M_VARIANTS ARM1136JS
+    
+
+    IF ARM1136JS
+
+;//--------------------------------------
+;// Declare input registers
+;//--------------------------------------
+ppSrc       RN 0
+pDst        RN 1
+QP          RN 2
+
+;//--------------------------------
+;// Scratch variable for Unpack2x2 
+;//--------------------------------
+pSrc        RN 9
+Value       RN 4
+Value2      RN 5
+Flag        RN 6
+strOffset   RN 7
+cstOffset   RN 8
+
+;//--------------------------------
+;// Scratch variable
+;//--------------------------------
+r0w0        RN  3
+r0w1        RN  4
+
+c0w0        RN  5
+c1w0        RN  6
+
+return      RN  0
+pQPDivTable RN  5
+pQPModTable    RN  6
+Shift        RN  9
+Scale        RN  2
+
+Temp1       RN  3
+Temp2       RN  4
+Temp3       RN  7
+Temp4       RN  8
+
+        ;// Write function header
+        M_START omxVCM4P10_TransformDequantChromaDCFromPair, r9
+        
+        
+        LDR     pSrc, [ppSrc]                        ;// Load pSrc
+        MOV     cstOffset, #31                       ;// To be used in the loop, to compute offset
+        
+        ;//-----------------------------------------------------------------------
+        ;// Firstly, fill all the coefficient values on the <pDst> buffer by zero
+        ;//-----------------------------------------------------------------------
+        
+        MOV      Value,  #0                          ;// Initialize the zero value
+        MOV      Value2,  #0                         ;// Initialize the zero value
+        LDRB     Flag,  [pSrc], #1                   ;// Preload <Flag> before <unpackLoop>
+        STRD     Value, [pDst, #0]                   ;// pDst[0]  = pDst[1]  = pDst[2]  = pDst[3]  = 0
+        
+
+unpackLoop
+        TST      Flag,  #0x10                        ;// Computing (Flag & 0x10)
+        LDRSBNE  Value2,[pSrc,#1]                  
+        LDRBNE   Value, [pSrc], #2                   ;// Load byte wise to avoid unaligned access
+        AND      strOffset, cstOffset, Flag, LSL #1  ;// strOffset = (Flag & 15) < 1;
+        LDRSBEQ  Value, [pSrc], #1                   ;// Value = (OMX_U8)  *pSrc++
+        ORRNE    Value,Value,Value2, LSL #8          ;// Value = (OMX_U16) *pSrc++
+        
+        TST      Flag,  #0x20                        ;// Computing (Flag & 0x20) to check, if we're done
+        LDRBEQ   Flag,  [pSrc], #1                   ;// Flag  = (OMX_U8) *pSrc++, for next iteration
+        STRH     Value, [pDst, strOffset]            ;// Store <Value> at offset <strOffset>
+        BEQ      unpackLoop                          ;// Branch to the loop beginning
+        
+        LDMIA    pDst, {r0w0, r0w1}                  ;// r0w0 = |c1|c0| & r0w1 = |c3|c2|
+
+
+        STR      pSrc, [ppSrc]                       ;// Update the bitstream pointer
+        
+        LDR      pQPDivTable, =armVCM4P10_QPDivTable ;// QP Division look-up-table base pointer
+        LDR      pQPModTable, =armVCM4P10_VMatrixQPModTable ;// QP Modulo look-up-table base pointer
+        
+        SADDSUBX r0w0, r0w0,  r0w0                   ;// [ c00+c01, c00-c01 ]
+        SADDSUBX r0w1, r0w1,  r0w1                   ;// [ c10+c11, c10-c11 ]
+        
+        LDRSB    Shift, [pQPDivTable, QP]            ;// Shift = pQPDivTable[QP]
+        LDRSB    Scale, [pQPModTable, QP]            ;// Scale = pQPModTable[QP]
+        
+        SADD16   c0w0, r0w0, r0w1                    ;// [ d00+d10, d01+d11 ]
+        SSUB16   c1w0, r0w0, r0w1                    ;// [ d00-d10, d01-d11 ]
+        
+        LSL      Scale, Scale, Shift                 ;// Scale = Scale << Shift
+        
+        SMULTB   Temp2, c0w0,  Scale                 ;// Temp2 = T(c0w0) * Scale
+        SMULTB   Temp4, c1w0,  Scale                 ;// Temp4 = T(c1w0) * Scale
+        SMULBB   Temp1, c0w0,  Scale                 ;// Temp1 = B(c0w0) * Scale
+        SMULBB   Temp3, c1w0,  Scale                 ;// Temp3 = B(c1w0) * Scale
+        MOV      Temp2, Temp2, ASR #1                ;// Temp2 = Temp2 >> 1 & Temp1 = (Temp1 >> 1) << 16
+        MOV      Temp4, Temp4, ASR #1                ;// Temp4 = Temp4 >> 1 & Temp3 = (Temp3 >> 1) << 16
+        PKHBT    c0w0,  Temp2, Temp1, LSL #15        ;// c0w0  = | Temp1 | Temp2 |
+        PKHBT    c1w0,  Temp4, Temp3, LSL #15        ;// c1w0  = | Temp3 | Temp4 |
+        STMIA    pDst, {c0w0, c1w0}                  ;// Storing all the coefficients at once
+        MOV      return, #OMX_Sts_NoErr
+        M_END
+        
+    ENDIF ;// ARM1136JS
+    
+    
+    
+    
+    END
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_TransformDequantLumaDCFromPair_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_TransformDequantLumaDCFromPair_s.s
new file mode 100644
index 0000000..73caec2
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p10/src/omxVCM4P10_TransformDequantLumaDCFromPair_s.s
@@ -0,0 +1,469 @@
+;//
+;// 
+;// File Name:  omxVCM4P10_TransformDequantLumaDCFromPair_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   9641
+;// Date:       Thursday, February 7, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+;// Description:
+;// H.264 inverse quantize and transform module
+;// 
+;// 
+
+;// Include standard headers
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+        
+;// Import/Export symbols required from/to other files
+;// (For example tables)
+        
+        IMPORT armVCM4P10_UnpackBlock4x4 
+        IMPORT armVCM4P10_QPDivTable
+        IMPORT armVCM4P10_VMatrixQPModTable
+        
+        M_VARIANTS ARM1136JS
+
+;// Set debugging level        
+;//DEBUG_ON    SETL {TRUE}
+
+
+;// Static Function: armVCM4P10_InvTransformDequantLumaDC4x4
+    
+
+;// Guarding implementation by the processor name
+    
+    IF  ARM1136JS 
+
+
+;//Input Registers
+pData               RN  0
+QP                  RN  1
+
+;//Output Registers
+
+
+;//Local Scratch Registers
+
+;// Packed Input pixels
+in00                RN  2                   ;// Src[0] & Src[1] 
+in02                RN  3                   ;// Src[2] & Src[3]
+in10                RN  4                   ;// Src[4] & Src[5]
+in12                RN  5                   ;// Src[6] & Src[7]
+in20                RN  6                   ;// Src[8] & Src[9]
+in22                RN  7                   ;// Src[10] & Src[11]
+in30                RN  8                   ;// Src[12] & Src[13]
+in32                RN  9                   ;// Src[14] & Src[15]
+
+;// Transpose for Row operations (Rows to cols)
+trRow00             RN  2
+trRow10             RN  10
+trRow02             RN  3
+trRow12             RN  5
+trRow20             RN  11
+trRow30             RN  12
+trRow32             RN  14
+trRow22             RN  7
+
+;// Intermediate calculations
+rowSum1             RN  4
+rowSum2             RN  6
+rowDiff1            RN  8
+rowDiff2            RN  9
+
+
+;// Row operated pixels
+rowOp00             RN  2
+rowOp10             RN  10
+rowOp20             RN  11
+rowOp30             RN  12
+rowOp02             RN  3
+rowOp12             RN  5
+rowOp22             RN  7
+rowOp32             RN  14
+
+;// Transpose for colulmn operations
+trCol00             RN  2                   
+trCol02             RN  3                   
+trCol10             RN  4                   
+trCol12             RN  5                   
+trCol20             RN  6                   
+trCol22             RN  7                   
+trCol30             RN  8                   
+trCol32             RN  9  
+
+;// Intermediate calculations
+colSum1             RN  10
+colSum2             RN  11
+colDiff1            RN  12
+colDiff2            RN  14
+
+
+;// Coloumn operated pixels
+colOp00             RN  2                   
+colOp02             RN  3                   
+colOp10             RN  4                   
+colOp12             RN  5                   
+colOp20             RN  6                   
+colOp22             RN  7                   
+colOp30             RN  8                   
+colOp32             RN  9  
+
+;// Temporary scratch varaibles
+pQPDivTable         RN  0
+pQPModTable         RN  11
+Shift               RN  10
+Scale               RN  14
+Round               RN  0
+
+temp1               RN  10
+temp2                RN  11
+temp3               RN  12
+temp4               RN  1
+
+
+
+;// InvTransformed and Dequantized pixels
+out00               RN  2                   
+out02               RN  3                   
+out10               RN  4                   
+out12               RN  5                   
+out20               RN  6                   
+out22               RN  7                   
+out30               RN  8                   
+out32               RN  9  
+      
+        
+
+       
+    ;// Allocate stack memory required by the function
+        M_ALLOC4    pDataOnStack, 4
+
+    ;// Write function header
+        M_START armVCM4P10_InvTransformDequantLumaDC4x4,r11
+        
+        ;******************************************************************
+        ;// The strategy used in implementing the transform is as follows:*
+        ;// Load the 4x4 block into 8 registers                           *  
+        ;// Transpose the 4x4 matrix                                      *  
+        ;// Perform the row operations (on columns) using SIMD            *  
+        ;// Transpose the 4x4 result matrix                               *  
+        ;// Perform the coloumn operations                                *
+        ;// Store the 4x4 block at one go                                 *  
+        ;******************************************************************
+
+        ;// Load all the 4x4 pixels
+        
+        LDMIA   pData,{in00,in02,in10,in12,in20,in22,in30,in32}
+        
+        ;//*****************************************************************
+        ;//
+        ;// Transpose the matrix inorder to perform row ops as coloumn ops
+        ;// Input:   in[][] = original matrix
+        ;// Output:  trRow[][]= transposed matrix
+        ;// Step1: Obtain the LL part of the transposed matrix
+        ;// Step2: Obtain the HL part
+        ;// step3: Obtain the LH part
+        ;// Step4: Obtain the HH part
+        ;//
+        ;//*****************************************************************
+        
+        ;// LL 2x2 transposed matrix 
+        ;//   d0 d1 - -
+        ;//   d4 d5 - -
+        ;//   -  -  - -
+        ;//   -  -  - -
+        
+        PKHTB   trRow10,in10,in00,ASR #16               ;// [5 4] = [f5:f1]    
+        PKHBT   trRow00,in00,in10,LSL #16               ;// [1 0] = [f4:f0]  
+        
+        ;// HL 2x2 transposed matrix  
+        ;//    -   -   - -
+        ;//    -   -   - -
+        ;//    d8  d9  - -
+        ;//   d12 d13  - -
+        
+         
+         PKHTB   trRow30,in12,in02,ASR #16              ;// [13 12] = [7 3]
+         PKHBT   trRow20,in02,in12,LSL #16              ;// [9 8] = [6 2] 
+        
+        ;// LH 2x2 transposed matrix 
+        ;//   - - d2 d3 
+        ;//   - - d6 d7 
+        ;//   - - -  -
+        ;//   - - -  -
+        
+        PKHBT   trRow02,in20,in30,LSL #16               ;// [3 2] = [f12:f8]  
+        PKHTB   trRow12,in30,in20,ASR #16               ;// [7 6] = [f13:f9] 
+        
+        
+        
+         
+        ;// HH 2x2 transposed matrix  
+        ;//    - -   -   -
+        ;//    - -   -   -
+        ;//    - -  d10 d11
+        ;//    - -  d14 d15
+        
+        PKHTB   trRow32,in32,in22,ASR #16               ;// [15 14] = [15 11]
+        PKHBT   trRow22,in22,in32,LSL #16               ;// [11 10] = [14 10]
+       
+        
+        ;**************************************** 
+        ;// Row Operations (Performed on columns)
+        ;**************************************** 
+        
+        
+        ;// SIMD operations on first two columns(two rows of the original matrix)
+        
+        SADD16      rowSum1,trRow00,trRow10                ;// (c0+c1)
+        SADD16      rowSum2,trRow20,trRow30                ;// (c2+c3)
+        SSUB16      rowDiff1,trRow00,trRow10               ;// (c0-c1)
+        SSUB16      rowDiff2,trRow20,trRow30               ;// (c2-c3)
+        SADD16      rowOp00,rowSum1,rowSum2                ;// (c0+c1+c2+c3)
+        SSUB16      rowOp10,rowSum1,rowSum2                ;// (c0+c1-c2-c3)
+        SSUB16      rowOp20,rowDiff1,rowDiff2              ;// (c0-c1-c2+c3)
+        SADD16      rowOp30,rowDiff1,rowDiff2              ;// (c0-c1+c2-c3)
+        
+                
+        ;// SIMD operations on next two columns(next two rows of the original matrix)
+        
+        SADD16      rowSum1,trRow02,trRow12                ;// (c0+c1)
+        SADD16      rowSum2,trRow22,trRow32                ;// (c2+c3)
+        SSUB16      rowDiff1,trRow02,trRow12               ;// (c0-c1)
+        SSUB16      rowDiff2,trRow22,trRow32               ;// (c2-c3)
+        SADD16      rowOp02,rowSum1,rowSum2                ;// (c0+c1+c2+c3)
+        SSUB16      rowOp12,rowSum1,rowSum2                ;// (c0+c1-c2-c3)
+        SSUB16      rowOp22,rowDiff1,rowDiff2              ;// (c0-c1-c2+c3)
+        SADD16      rowOp32,rowDiff1,rowDiff2              ;// (c0-c1+c2-c3)
+        
+        
+        
+        ;*****************************************************************
+        ;// Transpose the resultant matrix
+        ;// Input:  rowOp[][]
+        ;// Output: trCol[][] 
+        ;*****************************************************************
+        
+        ;// LL 2x2 transposed matrix 
+        ;//   d0 d1 - -
+        ;//   d4 d5 - -
+        ;//   -  -  - -
+        ;//   -  -  - -
+        
+        PKHTB   trCol10,rowOp10,rowOp00,ASR #16           ;// [5 4] = [f5:f1]
+        PKHBT   trCol00,rowOp00,rowOp10,LSL #16           ;// [1 0] = [f4:f0]  
+        
+        ;// HL 2x2 transposed matrix  
+        ;//    -   -   - -
+        ;//    -   -   - -
+        ;//    d8  d9  - -
+        ;//   d12 d13  - -
+        
+         
+         PKHTB   trCol30,rowOp12,rowOp02,ASR #16          ;// [13 12] = [7 3]
+         PKHBT   trCol20,rowOp02,rowOp12,LSL #16          ;// [9 8] = [6 2] 
+        
+        ;// LH 2x2 transposed matrix 
+        ;//   - - d2 d3 
+        ;//   - - d6 d7 
+        ;//   - - -  -
+        ;//   - - -  -
+        
+        PKHBT   trCol02,rowOp20,rowOp30,LSL #16           ;// [3 2] = [f12:f8]  
+        PKHTB   trCol12,rowOp30,rowOp20,ASR #16           ;// [7 6] = [f13:f9] 
+        
+        
+        
+         
+        ;// HH 2x2 transposed matrix  
+        ;//    - -   -   -
+        ;//    - -   -   -
+        ;//    - -  d10 d11
+        ;//    - -  d14 d15
+        
+        PKHTB   trCol32,rowOp32,rowOp22,ASR #16            ;// [15 14] = [15 11]
+        PKHBT   trCol22,rowOp22,rowOp32,LSL #16            ;// [11 10] = [14 10]
+       
+        
+        ;******************************* 
+        ;// Coloumn Operations 
+        ;******************************* 
+        
+        ;//--------------------------------------------------------------------------------------
+        ;// Store pData(RN0) on stack and restore it only at the final store back
+        ;// This frees up a register (RN0) which is used to reduce number of intermediate stalls 
+        ;//--------------------------------------------------------------------------------------
+        M_STR       pData,pDataOnStack
+        
+        
+        ;// SIMD operations on first two columns(two rows of the original matrix)
+                
+        SADD16      colSum1,trCol00,trCol10                ;// (c0+c1)
+        SADD16      colSum2,trCol20,trCol30                ;// (c2+c3)
+        SSUB16      colDiff1,trCol00,trCol10               ;// (c0-c1)
+        SSUB16      colDiff2,trCol20,trCol30               ;// (c2-c3)
+        SADD16      colOp00,colSum1,colSum2                ;// (c0+c1+c2+c3)
+        SSUB16      colOp10,colSum1,colSum2                ;// (c0+c1-c2-c3)
+        SSUB16      colOp20,colDiff1,colDiff2              ;// (c0-c1-c2+c3)
+        SADD16      colOp30,colDiff1,colDiff2              ;// (c0-c1+c2-c3)
+        
+                
+        ;// SIMD operations on next two columns(next two rows of the original matrix)
+        
+        LDR         pQPDivTable, =armVCM4P10_QPDivTable    ;// QP Division look-up-table base pointer
+        SADD16      colSum1,trCol02,trCol12                ;// (c0+c1)
+        SADD16      colSum2,trCol22,trCol32                ;// (c2+c3)
+        SSUB16      colDiff1,trCol02,trCol12               ;// (c0-c1)
+        SSUB16      colDiff2,trCol22,trCol32               ;// (c2-c3)
+        SADD16      colOp02,colSum1,colSum2                ;// (c0+c1+c2+c3)
+        SSUB16      colOp12,colSum1,colSum2                ;// (c0+c1-c2-c3)
+        LDR         pQPModTable, =armVCM4P10_VMatrixQPModTable ;// QP Modulo look-up-table base pointer
+        LDRSB       Shift, [pQPDivTable, QP]               ;// Shift = pQPDivTable[QP]
+        SSUB16      colOp22,colDiff1,colDiff2              ;// (c0-c1-c2+c3)
+        SADD16      colOp32,colDiff1,colDiff2              ;// (c0-c1+c2-c3)
+        
+               
+        LDRSB       Scale, [pQPModTable, QP]               ;// Scale = pQPModTable[QP] 
+        
+        ;//----------------------------------------------------------------------
+        ;//
+        ;// <Dequantize> improves on the c-reference code
+        ;// Both the  cases i.e., Shift>=0 and Shift<0 cases are covered together
+        ;// We do not subtract 2 from Shift as in C reference, instead perform a
+        ;// Scale << Shift once in the beginning and do a right shift by a 
+        ;// constant 2 after the Multiplication. The value of Round would be 2 
+        ;// 
+        ;// By doing this we aviod the Branches required and also 
+        ;// reduce the code size substantially
+        ;// 
+        ;//----------------------------------------------------------------------
+        
+        MOV         Round, #2                               ;// Round = 2
+        LSL         Scale, Scale, Shift                     ;// Scale = Scale << Shift
+                
+        
+        ;// Row 1
+        SMLABB  temp1, colOp00, Scale, Round                ;// Temp1 = B(c0w0) * Scale + Round
+        SMLABB  temp3, colOp02, Scale, Round                ;// Temp3 = B(c1w0) * Scale + Round
+        SMLATB  temp2, colOp00, Scale, Round                ;// Temp2 = T(c0w0) * Scale + Round
+        SMLATB  temp4, colOp02, Scale, Round                ;// Temp4 = T(c1w0) * Scale + Round
+        
+        ASR     temp1, temp1, #2                            ;// Temp1 = Temp1 >> 2
+        ASR     temp3, temp3, #2                            ;// Temp3 = Temp3 >> 2
+        PKHBT   out00,  temp1, temp2, LSL #14               ;// c0w0  = | Temp2 | Temp1 |
+        PKHBT   out02,  temp3, temp4, LSL #14               ;// c1w0  = | Temp2 | Temp1 |
+        
+        
+        ;// Row 2
+        SMLABB  temp1, colOp10, Scale, Round                ;// Temp1 = B(c0w0) * Scale + Round
+        SMLABB  temp3, colOp12, Scale, Round                ;// Temp3 = B(c1w0) * Scale + Round
+        SMLATB  temp2, colOp10, Scale, Round                ;// Temp2 = T(c0w0) * Scale + Round
+        SMLATB  temp4, colOp12, Scale, Round                ;// Temp4 = T(c1w0) * Scale + Round
+        
+        ASR     temp1, temp1, #2                            ;// Temp1 = Temp1 >> 2
+        ASR     temp3, temp3, #2                            ;// Temp3 = Temp3 >> 2
+        PKHBT   out10,  temp1, temp2, LSL #14               ;// c0w0  = | Temp2 | Temp1 |
+        PKHBT   out12,  temp3, temp4, LSL #14               ;// c1w0  = | Temp2 | Temp1 |
+        
+        ;// Row 3
+        SMLABB  temp1, colOp20, Scale, Round                ;// Temp1 = B(c0w0) * Scale + Round
+        SMLABB  temp3, colOp22, Scale, Round                ;// Temp3 = B(c1w0) * Scale + Round
+        SMLATB  temp2, colOp20, Scale, Round                ;// Temp2 = T(c0w0) * Scale + Round
+        SMLATB  temp4, colOp22, Scale, Round                ;// Temp4 = T(c1w0) * Scale + Round
+        
+        ASR     temp1, temp1, #2                            ;// Temp1 = Temp1 >> 2 
+        ASR     temp3, temp3, #2                            ;// Temp3 = Temp3 >> 2
+        PKHBT   out20,  temp1, temp2, LSL #14               ;// c0w0  = | Temp2 | Temp1 |
+        PKHBT   out22,  temp3, temp4, LSL #14               ;// c1w0  = | Temp2 | Temp1 |
+        
+        ;// Row 4
+        SMLABB  temp1, colOp30, Scale, Round                ;// Temp1 = B(c0w0) * Scale + Round
+        SMLABB  temp3, colOp32, Scale, Round                ;// Temp3 = B(c1w0) * Scale + Round
+        SMLATB  temp2, colOp30, Scale, Round                ;// Temp2 = T(c0w0) * Scale + Round
+        SMLATB  temp4, colOp32, Scale, Round                ;// Temp4 = T(c1w0) * Scale + Round
+        
+        M_LDR   pData,pDataOnStack                          ;// Restore pData pointer from stack
+        ASR     temp1, temp1, #2                            ;// Temp1 = Temp1 >> 2
+        ASR     temp3, temp3, #2                            ;// Temp3 = Temp3 >> 2
+        PKHBT   out30,  temp1, temp2, LSL #14               ;// c0w0  = | Temp2 | Temp1 |
+        PKHBT   out32,  temp3, temp4, LSL #14               ;// c1w0  = | Temp2 | Temp1 |
+        
+        
+        
+        ;***************************
+        ;// Store all the 4x4 pixels
+        ;***************************
+
+store_coeff
+        
+        STMIA   pData,{out00,out02,out10,out12,out20,out22,out30,out32}
+        
+                               
+       
+        ;// Set return value
+        
+       
+        ;// Write function tail
+        M_END        
+        
+    ENDIF                                                           ;//ARM1136JS        
+    
+
+;// Static Function: armVCM4P10_InvTransformDequantLumaDC4x4
+
+;// Guarding implementation by the processor name
+    
+        
+
+
+;// Function: omxVCM4P10_TransformDequantLumaDCFromPair
+    
+;//Input Registers
+ppSrc               RN  0
+pDst                RN  1
+QPR2                RN  2
+
+;//Output Registers
+result              RN  0
+
+;//Local Scratch Registers
+pDstR4              RN  4
+pDstR0              RN  0
+QPR1                RN  1
+QPR5                RN  5
+
+;// Guarding implementation by the processor name
+    
+    IF ARM1136JS
+       
+    ;// Allocate stack memory required by the function
+        
+
+    ;// Write function header
+        M_START omxVCM4P10_TransformDequantLumaDCFromPair,r5
+        
+        MOV     pDstR4,pDst                         ;// Saving register r1
+        MOV     QPR5,QPR2                           ;// Saving register r2
+        BL      armVCM4P10_UnpackBlock4x4
+        
+        MOV     pDstR0,pDstR4                       ;// Setting up register r0
+        MOV     QPR1,QPR5                           ;// Setting up register r1
+        BL      armVCM4P10_InvTransformDequantLumaDC4x4
+                               
+       
+        ;// Set return value
+        MOV     result,#OMX_Sts_NoErr        
+       
+        ;// Write function tail
+        M_END
+        
+            
+    ENDIF                                                           ;//ARM1136JS  
+    
+
+    END
\ No newline at end of file
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/api/armVCM4P2_Huff_Tables_VLC.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/api/armVCM4P2_Huff_Tables_VLC.h
new file mode 100644
index 0000000..22115d3
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/api/armVCM4P2_Huff_Tables_VLC.h
@@ -0,0 +1,37 @@
+/**
+ * 
+ * File Name:  armVCM4P2_Huff_Tables_VLC.h
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ *
+ * File:        armVCM4P2_Huff_Tables.h
+ * Description: Declares Tables used for Hufffman coding and decoding 
+ *              in MP4P2 codec.
+ *
+ */
+ 
+#ifndef _OMXHUFFTAB_H_
+#define _OMXHUFFTAB_H_
+
+
+extern const OMX_U16 armVCM4P2_IntraVlcL0L1[200];
+
+
+extern const OMX_U16 armVCM4P2_InterVlcL0L1[200];
+
+extern const OMX_U16 armVCM4P2_aIntraDCLumaChromaIndex[64];
+//extern const OMX_U16 armVCM4P2_aIntraDCChromaIndex[32];
+extern const OMX_U16 armVCM4P2_aVlcMVD[124];
+
+extern const OMX_U8 armVCM4P2_InterL0L1LMAX[73];
+extern const OMX_U8 armVCM4P2_InterL0L1RMAX[35];
+extern const OMX_U8 armVCM4P2_IntraL0L1LMAX[53];
+extern const OMX_U8 armVCM4P2_IntraL0L1RMAX[40]
+
+#endif /* _OMXHUFFTAB_H_ */
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/api/armVCM4P2_ZigZag_Tables.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/api/armVCM4P2_ZigZag_Tables.h
new file mode 100644
index 0000000..d5f865c
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/api/armVCM4P2_ZigZag_Tables.h
@@ -0,0 +1,25 @@
+/**
+ * 
+ * File Name:  armVCM4P2_ZigZag_Tables.h
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ *
+ * File:        armVCM4P2_Zigzag_Tables.h
+ * Description: Declares Tables used for Zigzag scan in MP4P2 codec.
+ *
+ */
+ 
+#ifndef _OMXZIGZAGTAB_H
+#define _OMXZIGZAGTAB_H
+
+extern const OMX_U8 armVCM4P2_aClassicalZigzagScan [192];
+//extern const OMX_U8 armVCM4P2_aHorizontalZigzagScan [64];
+//extern const OMX_U8 armVCM4P2_aVerticalZigzagScan [64];
+
+#endif /* _OMXZIGZAGTAB_H_ */
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/armVCM4P2_Clip8_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/armVCM4P2_Clip8_s.s
new file mode 100644
index 0000000..7801e57
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/armVCM4P2_Clip8_s.s
@@ -0,0 +1,75 @@
+; /**
+; * 
+; * File Name:  armVCM4P2_Clip8_s.s
+; * OpenMAX DL: v1.0.2
+; * Revision:   9641
+; * Date:       Thursday, February 7, 2008
+; * 
+; * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+; * 
+; * 
+; *
+; * Description: 
+; * Contains module for Clipping 16 bit value to [0,255] Range
+; */ 
+
+      INCLUDE omxtypes_s.h
+      INCLUDE armCOMM_s.h
+      
+
+      M_VARIANTS ARM1136JS
+
+        
+     
+      IF ARM1136JS
+ 
+;//Input Arguments
+
+pSrc                 RN 0
+pDst                 RN 1
+step                 RN 2
+
+;// Local variables
+
+x0                   RN 3
+x1                   RN 4
+x2                   RN 5
+x3                   RN 6
+
+Count                RN 14
+     
+        
+        M_START armVCM4P2_Clip8,r6
+       
+
+        MOV          Count,#8
+loop
+
+        LDMIA        pSrc!,{x0, x1}
+        SUBS         Count,Count, #1          ;// count down
+        LDMIA        pSrc!,{x2, x3}
+        USAT16       x0, #8, x0                 ;// clip two samples to [0,255]
+        USAT16       x1, #8, x1                 ;// clip two samples to [0,255]
+        STRB         x0, [pDst]
+        MOV          x0, x0, LSR #16
+        STRB         x0, [pDst,#1]
+        STRB         x1, [pDst,#2]
+        MOV          x1, x1, LSR #16
+        STRB         x1, [pDst,#3]
+                
+        USAT16       x2, #8, x2                 ;// clip two samples to [0,255]
+        USAT16       x3, #8, x3                 ;// clip two samples to [0,255]
+        STRB         x2, [pDst,#4]
+        MOV          x2, x2, LSR #16
+        STRB         x2, [pDst,#5]
+        STRB         x3, [pDst,#6]
+        MOV          x3, x3, LSR #16
+        STRB         x3, [pDst,#7]
+        ADD          pDst,pDst,step             ;// Increment pDst by step value
+         
+        BGT          loop                       ;// Continue loop until Count reaches 64 
+
+        M_END
+        ENDIF
+        
+        END
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/armVCM4P2_DecodeVLCZigzag_AC_unsafe_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/armVCM4P2_DecodeVLCZigzag_AC_unsafe_s.s
new file mode 100644
index 0000000..9e30900
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/armVCM4P2_DecodeVLCZigzag_AC_unsafe_s.s
@@ -0,0 +1,398 @@
+;/**
+; * 
+; * File Name:  armVCM4P2_DecodeVLCZigzag_AC_unsafe_s.s
+; * OpenMAX DL: v1.0.2
+; * Revision:   9641
+; * Date:       Thursday, February 7, 2008
+; * 
+; * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+; * 
+; * 
+; *
+; * Description: 
+; * Contains modules for zigzag scanning and VLC decoding
+; * for inter, intra block.
+; *
+; *
+; *
+; * Function: omxVCM4P2_DecodeVLCZigzag_AC_unsafe
+; *
+; * Description:
+; * Performs VLC decoding and inverse zigzag scan 
+; *
+; * 
+; *
+; * 
+; */
+
+
+      INCLUDE omxtypes_s.h
+      INCLUDE armCOMM_s.h
+      INCLUDE armCOMM_BitDec_s.h
+
+
+      M_VARIANTS ARM1136JS
+
+     
+
+
+
+     IF ARM1136JS
+     
+        
+
+
+
+;//Input Arguments
+
+ppBitStream          RN 0
+pBitOffset           RN 1
+pDst                 RN 2
+shortVideoHeader     RN 3
+
+
+;//Local Variables
+
+Return               RN 0
+
+pVlcTableL0L1        RN 4
+pLMAXTableL0L1       RN 4
+pRMAXTableL0L1       RN 4
+pZigzagTable         RN 4
+
+ftype                RN 0
+temp3                RN 4
+temp                 RN 5
+Count                RN 6
+Escape               RN 5
+
+;// armVCM4P2_FillVLDBuffer
+zigzag               RN 0
+storeLevel           RN 1
+temp2                RN 4
+temp1                RN 5
+sign                 RN 5
+Last                 RN 7
+storeRun             RN 14
+
+
+packRetIndex         RN 5
+
+
+markerbit            RN 5
+
+;// Scratch Registers
+
+RBitStream           RN 8
+RBitBuffer           RN 9
+RBitCount            RN 10
+
+T1                   RN 11
+T2                   RN 12
+LR                   RN 14        
+        
+
+
+        M_ALLOC4        pppBitStream,4
+        M_ALLOC4        ppOffset,4
+        M_ALLOC4        pLinkRegister,4       
+        
+        M_START armVCM4P2_DecodeVLCZigzag_AC_unsafe
+
+        ;// get the table addresses from stack       
+        M_ARG           ppVlcTableL0L1,4
+        M_ARG           ppLMAXTableL0L1,4
+        M_ARG           ppRMAXTableL0L1,4
+        M_ARG           ppZigzagTable,4
+        
+        ;// Store ALL zeros at pDst
+        
+        MOV             temp1,#0                                        ;// Initialize Count to zero                                
+        MOV             Last,#0
+        M_STR           LR,pLinkRegister                                ;// Store Link Register on Stack
+        MOV             temp2,#0
+        MOV             LR,#0          
+        
+        ;// Initialize the Macro and Store all zeros to pDst 
+  
+        STM             pDst!,{temp2,temp1,Last,LR}                   
+        M_BD_INIT0      ppBitStream, pBitOffset, RBitStream, RBitBuffer, RBitCount  
+        STM             pDst!,{temp2,temp1,Last,LR}
+        M_BD_INIT1      T1, T2, T2
+        STM             pDst!,{temp2,temp1,Last,LR}
+        M_BD_INIT2      T1, T2, T2
+        STM             pDst!,{temp2,temp1,Last,LR}
+        M_STR           ppBitStream,pppBitStream                        ;// Store ppBitstream on stack                         
+        STM             pDst!,{temp2,temp1,Last,LR}
+        M_STR           pBitOffset,ppOffset                             ;// Store pBitOffset on stack
+        STM             pDst!,{temp2,temp1,Last,LR}
+        
+        STM             pDst!,{temp2,temp1,Last,LR}
+        STM             pDst!,{temp2,temp1,Last,LR}
+ 
+        
+        SUB             pDst,pDst,#128                                  ;// Restore pDst
+
+        ;// The armVCM4P2_GetVLCBits begins
+
+getVLCbits
+        
+        M_BD_LOOK8      Escape,7                                        ;// Load Escape Value
+        LSR             Escape,Escape,#25                                                  
+        CMP             Escape,#3                                       ;// check for escape mode
+        MOVNE           ftype,#0
+        BNE             notEscapemode                                   ;// Branch if not in Escape mode 3
+
+        M_BD_VSKIP8     #7,T1
+        CMP             shortVideoHeader,#0                             ;// Check shortVideoHeader flag to know the type of Escape mode
+        BEQ             endFillVLD                                       
+        
+        ;// Escape Mode 4
+
+        M_BD_READ8      Last,1,T1
+        M_BD_READ8      storeRun,6,T1
+        M_BD_READ8      storeLevel,8,T1
+
+           
+        ;// Check whether the Reserved values for Level are used and Exit with an Error Message if it is so
+
+        TEQ             storeLevel,#0
+        TEQNE           storeLevel,#128                    
+        BEQ             ExitError
+
+        ADD             temp2,storeRun,Count
+        CMP             temp2,#64
+        BGE             ExitError                                       ;// error if Count+storeRun >= 64
+        
+        
+        ;// Load address of zigzagTable
+        
+        M_LDR           pZigzagTable,ppZigzagTable                      ;// Loading the Address of Zigzag table
+               
+                
+        ;// armVCM4P2_FillVLDBuffer
+                
+        SXTB            storeLevel,storeLevel                           ;// Sign Extend storeLevel to 32 bits
+                              
+        
+        ;// To Reflect Runlength
+
+        ADD             Count,Count,storeRun
+        LDRB            zigzag,[pZigzagTable,Count]
+        ADD             Count,Count,#1
+        STRH            storeLevel,[pDst,zigzag]                        ;// store Level
+              
+        B               ExitOk
+       
+        
+
+endFillVLD
+        
+               
+        ;// Load Ftype( Escape Mode) value based on the two successive bits in the bitstream
+     
+        M_BD_READ8      temp1,1,T1           
+        CMP             temp1,#0    
+        MOVEQ           ftype,#1
+        BEQ             notEscapemode
+        M_BD_READ8      temp1,1,T1
+        CMP             temp1,#1
+        MOVEQ           ftype,#3
+        MOVNE           ftype,#2
+        
+
+notEscapemode
+
+        ;// Load optimized packed VLC table with last=0 and Last=1
+        
+        M_LDR           pVlcTableL0L1,ppVlcTableL0L1                    ;// Load Combined VLC Table
+                
+       
+        CMP             ftype,#3                                        ;// If ftype >=3 get perform Fixed Length Decoding (Escape Mode 3)
+        BGE             EscapeMode3                                     ;// Else continue normal VLC Decoding
+        
+        ;// Variable lengh decoding, "armUnPackVLC32" 
+        
+        
+        M_BD_VLD        packRetIndex,T1,T2,pVlcTableL0L1,4,2
+        
+        
+        LDR             temp3,=0xFFF
+        
+        CMP             packRetIndex,temp3                              ;// Check for invalid symbol
+        BEQ             ExitError                                       ;// if invalid symbol occurs exit with an error message
+        
+        AND             Last,packRetIndex,#2                            ;// Get Last from packed Index
+              
+         
+        
+
+        LSR             storeRun,packRetIndex,#7                        ;// Get Run Value from Packed index
+        AND             storeLevel,packRetIndex,#0x7c                   ;// storeLevel=packRetIndex[2-6],storeLevel[0-1]=0 
+                                                                        
+     
+        M_LDR           pLMAXTableL0L1,ppLMAXTableL0L1                  ;// Load LMAX table
+              
+       
+        LSR             storeLevel,storeLevel,#2                        ;// Level value
+
+        CMP             ftype,#1                                    
+        BNE             ftype2
+        
+        ;// ftype==1; Escape mode =1
+          
+        
+        ADD            temp1, pLMAXTableL0L1, Last, LSL#4              ;// If the Last=1 add 32 to table address
+        LDRB            temp1,[temp1,storeRun]
+
+       
+        ADD             storeLevel,temp1,storeLevel                     
+
+ftype2
+
+        ;// ftype =2; Escape mode =2
+        
+        M_LDR           pRMAXTableL0L1,ppRMAXTableL0L1                  ;// Load RMAX Table 
+                
+        CMP             ftype,#2
+        BNE             FillVLDL1
+                  
+        ADD            temp1, pRMAXTableL0L1, Last, LSL#4               ;// If Last=1 add 32 to table address
+        SUB             temp2,storeLevel,#1
+        LDRB            temp1,[temp1,temp2]
+
+       
+        ADD             storeRun,storeRun,#1
+        ADD             storeRun,temp1
+        
+FillVLDL1        
+            
+                
+        ;// armVCM4P2_FillVLDBuffer
+
+        M_LDR           pZigzagTable,ppZigzagTable                     ;// Load address of zigzagTable 
+                
+        M_BD_READ8      sign,1,T1
+
+        CMP             sign,#1
+        RSBEQ           storeLevel,storeLevel,#0
+ 
+        ADD             temp1,storeRun,Count                           ;// Exit with an error message if Run + Count exceeds 63
+        CMP             temp1,#64
+        BGE             ExitError
+
+      
+        
+        
+              
+        
+        ;// To Reflect Runlenght
+
+        ADD             Count,Count,storeRun
+ 
+storeLevelL1
+        
+        LDRB            zigzag,[pZigzagTable,Count]
+        CMP             Last,#2                                         ;// Check if the Level val is Last non zero val
+        ADD             Count,Count,#1
+        LSR             Last,Last,#1
+        STRH            storeLevel,[pDst,zigzag]                  
+           
+        BNE             end
+        
+        B               ExitOk
+ 
+
+
+        ;// Fixed Lengh Decoding Escape Mode 3
+
+EscapeMode3
+
+        M_BD_READ8      Last,1,T1
+        M_BD_READ8      storeRun,6,T1
+        
+        ADD             temp2,storeRun,Count                            ;// Exit with an error message if Run + Count exceeds 63
+        CMP             temp2,#64
+        BGE             ExitError
+
+        M_BD_READ8      markerbit,1,T1
+        TEQ             markerbit,#0                                    ;// Exit with an error message if marker bit is zero
+        BEQ             ExitError
+        
+        M_BD_READ16     storeLevel,12,T1
+
+        TST             storeLevel,#0x800                               ;// test if the level is negative
+        SUBNE           storeLevel,storeLevel,#4096
+        CMP             storeLevel,#0
+        CMPNE           storeLevel,#-2048
+        BEQ             ExitError                                       ;// Exit with an error message if Level==0 or  -2048 
+
+        M_LDR           pZigzagTable,ppZigzagTable                      ;// Load address of zigzagTable
+              
+        M_BD_READ8      markerbit,1,T1
+           
+
+        ;// armVCM4P2_FillVLDBuffer ( Sign not used as storeLevel is preprocessed)
+            
+               
+
+        ;// To Reflect Run Length
+
+        ADD             Count,Count,storeRun
+
+
+ 
+storeLevelLast
+        
+        LDRB            zigzag,[pZigzagTable,Count]
+        CMP             Last,#1
+        ADD             Count,Count,#1
+        STRH            storeLevel,[pDst,zigzag]                          
+                
+        BNE             end 
+      
+        B               ExitOk
+        
+end
+
+        CMP             Count,#64                                       ;//Run the Loop untill Count reaches 64
+
+        BLT             getVLCbits
+
+        
+ExitOk
+        ;// Exit When VLC Decoding is done Successfully 
+   
+        ;// Loading ppBitStream and pBitOffset from stack
+        
+        CMP             Last,#1
+        M_LDR           ppBitStream,pppBitStream
+        M_LDR           pBitOffset,ppOffset
+
+        ;//Ending the macro
+
+        M_BD_FINI       ppBitStream,pBitOffset
+             
+        MOVEQ           Return,#OMX_Sts_NoErr
+        MOVNE           Return,#OMX_Sts_Err
+        M_LDR           LR,pLinkRegister                               ;// Load the Link Register Back
+        B               exit2
+
+ExitError
+        ;// Exit When an Error occurs 
+
+        M_LDR           ppBitStream,pppBitStream
+        M_LDR           pBitOffset,ppOffset
+        ;//Ending the macro
+
+        M_BD_FINI       ppBitStream,pBitOffset
+        M_LDR           LR,pLinkRegister
+        MOV             Return,#OMX_Sts_Err
+
+exit2
+       
+
+        M_END
+        ENDIF
+        
+        END
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/armVCM4P2_Huff_Tables_VLC.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/armVCM4P2_Huff_Tables_VLC.c
new file mode 100644
index 0000000..ba4d058
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/armVCM4P2_Huff_Tables_VLC.c
@@ -0,0 +1,211 @@
+ /**
+ * 
+ * File Name:  armVCM4P2_Huff_Tables_VLC.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * File:        armVCM4P2_Huff_Tables_VLC.c
+ * Description: Contains all the Huffman tables used in MPEG4 codec
+ *
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+
+#include "armCOMM_Bitstream.h"
+
+
+
+
+// Contains optimized and Packed VLC tables with Last=0 and Last=1
+
+//              optimized Packed VLC table Entry Format 
+//              ---------------------------------------
+// 
+//        15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
+//       +------------------------------------------------+
+//       |  Len   |       Run       |     Level    |L | 1 |
+//       +------------------------------------------------+
+//       |                Offset                      | 0 |
+//       +------------------------------------------------+
+// If the table entry is a leaf entry then bit 0 set:
+//    Len    = Number of bits overread  (0 to 7)  3 bits
+//    Run    = RunLength of the Symbol  (0 to 63) 6 bits
+//    Level  = Level of the Symbol      (0 to 31) 5 bits
+//    L      = Last Value of the Symbol (0 or 1)  1 bit
+//
+// If the table entry is an internal node then bit 0 is clear:
+//    Offset = Number of (16-bit) half words from the table
+//             start to the next table node
+//
+// The table is accessed by successive lookup up on the
+// next Step bits of the input bitstream until a leaf node
+// is obtained. The Step sizes are supplied to the VLD macro.
+
+// The VLC tables used for Intra and non inta coefficients in non Escape mode
+// contains symbols with both Last=0 and Last=1.
+// If a symbol is not found in the table it will be coded as 0xFFF
+ 
+
+const OMX_U16 armVCM4P2_InterVlcL0L1[200] = {
+    0x0020, 0x0108, 0x0148, 0x0170, 0x0178, 0x0180, 0x0188, 0x1b09,
+    0x4009, 0x4009, 0x4009, 0x4009, 0x2109, 0x2109, 0x0209, 0x0011,
+    0x0028, 0x0060, 0x00b8, 0x00e0, 0x0030, 0x0048, 0x0050, 0x0058,
+    0x3fff, 0x3fff, 0x0038, 0x0040, 0x2115, 0x2115, 0x201d, 0x201d,
+    0x2059, 0x2059, 0x2051, 0x2051, 0x1c0d, 0x1b0d, 0x1a0d, 0x190d,
+    0x0911, 0x0811, 0x0711, 0x0611, 0x0511, 0x0319, 0x0219, 0x0121,
+    0x0068, 0x0090, 0x3fff, 0x3fff, 0x0070, 0x0078, 0x0080, 0x0088,
+    0x2061, 0x2061, 0x2129, 0x2129, 0x3709, 0x3709, 0x3809, 0x3809,
+    0x3d0d, 0x3d0d, 0x3e0d, 0x3e0d, 0x3f0d, 0x3f0d, 0x200d, 0x200d,
+    0x0098, 0x00a0, 0x00a8, 0x00b0, 0x0131, 0x0221, 0x0419, 0x0519,
+    0x0619, 0x0a11, 0x1909, 0x1a09, 0x210d, 0x220d, 0x230d, 0x240d,
+    0x250d, 0x260d, 0x270d, 0x280d, 0x00c0, 0x00c8, 0x00d0, 0x00d8,
+    0x0049, 0x0041, 0x380d, 0x380d, 0x370d, 0x370d, 0x360d, 0x360d,
+    0x350d, 0x350d, 0x340d, 0x340d, 0x330d, 0x330d, 0x320d, 0x320d,
+    0x00e8, 0x00f0, 0x00f8, 0x0100, 0x310d, 0x310d, 0x2015, 0x2015,
+    0x3609, 0x3609, 0x3509, 0x3509, 0x3409, 0x3409, 0x3309, 0x3309,
+    0x3209, 0x3209, 0x3109, 0x3109, 0x0110, 0x0130, 0x0138, 0x0140,
+    0x0118, 0x0120, 0x0128, 0x100d, 0x3009, 0x3009, 0x2f09, 0x2f09,
+    0x2411, 0x2411, 0x2311, 0x2311, 0x2039, 0x2039, 0x2031, 0x2031,
+    0x0f0d, 0x0e0d, 0x0d0d, 0x0c0d, 0x0b0d, 0x0a0d, 0x090d, 0x0e09,
+    0x0d09, 0x0211, 0x0119, 0x0029, 0x0150, 0x0158, 0x0160, 0x0168,
+    0x280d, 0x280d, 0x270d, 0x270d, 0x260d, 0x260d, 0x250d, 0x250d,
+    0x2c09, 0x2c09, 0xb759, 0xb759, 0x2a09, 0x2a09, 0x2021, 0x2021,
+    0x040d, 0x030d, 0x0b35, 0x010d, 0x0909, 0x0809, 0x0709, 0x0609,
+    0x0111, 0x0019, 0x2509, 0x2509, 0x2409, 0x2409, 0x2309, 0x2309
+};
+
+
+const OMX_U16 armVCM4P2_IntraVlcL0L1[200] = {
+    0x0020, 0x0108, 0x0148, 0x0170, 0x0178, 0x0180, 0x0188, 0x0f09,
+    0x4009, 0x4009, 0x4009, 0x4009, 0x2011, 0x2011, 0x0109, 0x0019,
+    0x0028, 0x0060, 0x00b8, 0x00e0, 0x0030, 0x0048, 0x0050, 0x0058,
+    0x3fff, 0x3fff, 0x0038, 0x0040, 0x203d, 0x203d, 0x2035, 0x2035,
+    0x20b1, 0x20b1, 0x20a9, 0x20a9, 0x0215, 0x011d, 0x002d, 0x0d09,
+    0x0519, 0x0811, 0x0419, 0x0321, 0x0221, 0x0139, 0x00a1, 0x0099,
+    0x0068, 0x0090, 0x3fff, 0x3fff, 0x0070, 0x0078, 0x0080, 0x0088,
+    0x20b9, 0x20b9, 0x20c1, 0x20c1, 0x2141, 0x2141, 0x2911, 0x2911,
+    0x2315, 0x2315, 0x2415, 0x2415, 0x2f0d, 0x2f0d, 0x300d, 0x300d,
+    0x0098, 0x00a0, 0x00a8, 0x00b0, 0x00c9, 0x00d1, 0x00d9, 0x0149,
+    0x0619, 0x0151, 0x0229, 0x0719, 0x0e09, 0x0045, 0x0515, 0x0615,
+    0x110d, 0x120d, 0x130d, 0x140d, 0x00c0, 0x00c8, 0x00d0, 0x00d8,
+    0x0091, 0x0089, 0x2e0d, 0x2e0d, 0x2d0d, 0x2d0d, 0x2c0d, 0x2c0d,
+    0x2b0d, 0x2b0d, 0x2a0d, 0x2a0d, 0x2115, 0x2115, 0x2025, 0x2025,
+    0x00e8, 0x00f0, 0x00f8, 0x0100, 0x2c09, 0x2c09, 0x2b09, 0x2b09,
+    0x2711, 0x2711, 0x2611, 0x2611, 0x2511, 0x2511, 0x2319, 0x2319,
+    0x2219, 0x2219, 0x2131, 0x2131, 0x0110, 0x0130, 0x0138, 0x0140,
+    0x0118, 0x0120, 0x0128, 0x080d, 0x2129, 0x2129, 0x2081, 0x2081,
+    0x2411, 0x2411, 0x2079, 0x2079, 0x2071, 0x2071, 0x2069, 0x2069,
+    0x1bb5, 0x060d, 0x001d, 0xd3f9, 0x0909, 0x0809, 0x090d, 0x0311,
+    0x0121, 0x0061, 0x0059, 0x0051, 0x0150, 0x0158, 0x0160, 0x0168,
+    0x240d, 0x240d, 0x230d, 0x230d, 0x2609, 0x2609, 0x250d, 0x250d,
+    0x2709, 0x2709, 0x2211, 0x2211, 0x2119, 0x2119, 0x2049, 0x2049,
+    0x0015, 0x0509, 0x020d, 0x010d, 0x0409, 0x0309, 0x0041, 0x0039,
+    0x0111, 0x0031, 0x2209, 0x2209, 0x2029, 0x2029, 0x2021, 0x2021
+};
+
+const OMX_U16 armVCM4P2_aIntraDCLumaChromaIndex[64] = {
+    0x0020, 0x000b, 0x2009, 0x2009, 0x2007, 0x2007, 0x2001, 0x2001,
+    0x4005, 0x4005, 0x4005, 0x4005, 0x4003, 0x4003, 0x4003, 0x4003,
+    0x0028, 0x000f, 0x200d, 0x200d, 0x0030, 0x0013, 0x2011, 0x2011,
+    0x0038, 0x0017, 0x2015, 0x2015, 0x3fff, 0x3fff, 0x2019, 0x2019,
+
+	0x0020, 0x0009, 0x2007, 0x2007, 0x4005, 0x4005, 0x4005, 0x4005,
+    0x4003, 0x4003, 0x4003, 0x4003, 0x4001, 0x4001, 0x4001, 0x4001,
+    0x0028, 0x000d, 0x200b, 0x200b, 0x0030, 0x0011, 0x200f, 0x200f,
+    0x0038, 0x0015, 0x2013, 0x2013, 0x1fff, 0x0019, 0x2017, 0x2017
+};
+
+
+const OMX_U16 armVCM4P2_aVlcMVD[124] = {
+    0x0010, 0x00f0, 0x0043, 0x003f, 0x4041, 0x4041, 0x4041, 0x4041,
+    0x0018, 0x00d8, 0x0047, 0x003b, 0x0020, 0x0080, 0x00a8, 0x00d0,
+    0x0028, 0x0048, 0x0070, 0x0078, 0x1fff, 0x0030, 0x0038, 0x0040,
+    0x0081, 0x0001, 0x007f, 0x0003, 0x207d, 0x207d, 0x2005, 0x2005,
+    0x207b, 0x207b, 0x2007, 0x2007, 0x0050, 0x0058, 0x0060, 0x0068,
+    0x2079, 0x2079, 0x2009, 0x2009, 0x2077, 0x2077, 0x200b, 0x200b,
+    0x2075, 0x2075, 0x200d, 0x200d, 0x2073, 0x2073, 0x200f, 0x200f,
+    0x0071, 0x0011, 0x006f, 0x0013, 0x006d, 0x0015, 0x006b, 0x0017,
+    0x0088, 0x0090, 0x0098, 0x00a0, 0x0069, 0x0019, 0x0067, 0x001b,
+    0x0065, 0x001d, 0x0063, 0x001f, 0x0061, 0x0021, 0x005f, 0x0023,
+    0x005d, 0x0025, 0x005b, 0x0027, 0x00b0, 0x00b8, 0x00c0, 0x00c8,
+    0x0059, 0x0029, 0x0057, 0x002b, 0x2055, 0x2055, 0x202d, 0x202d,
+    0x2053, 0x2053, 0x202f, 0x202f, 0x2051, 0x2051, 0x2031, 0x2031,
+    0x204f, 0x204f, 0x2033, 0x2033, 0x00e0, 0x00e8, 0x0049, 0x0039,
+    0x204d, 0x204d, 0x2035, 0x2035, 0x204b, 0x204b, 0x2037, 0x2037,
+    0x2045, 0x2045, 0x203d, 0x203d
+};
+
+/* LMAX table for non Inter (Last == 0 and Last=1)
+   Level - 1 Indexed
+   padded armVCM4P2_InterL0L1LMAX[27-31] with zeros to acess entries for Last=1 effectively
+
+*/
+const OMX_U8 armVCM4P2_InterL0L1LMAX[73] = 
+{
+   12,  6,  4,  3,  3,  3,  3,  2, 
+    2,  2,  2,  1,  1,  1,  1,  1,
+    1,  1,  1,  1,  1,  1,  1,  1,
+    1,  1,  1,  0,  0,  0,  0,  0,
+    3,  2,  1,  1,  1,  1,  1,  1, 
+	1,  1,  1,  1,  1,  1,  1,  1,
+	1,  1,  1,  1,  1,  1,  1,  1,
+	1,  1,  1,  1,  1,  1,  1,  1,
+	1,  1,  1,  1,  1,  1,  1,  1,
+	1
+};
+
+/* RMAX table for non Inter (Last == 0 and Last=1)
+   Level - 1 Indexed 
+ padded armVCM4P2_InterL0L1RMAX[12-31] with zeros to access entries for Last=1 table effectively */
+
+
+const OMX_U8 armVCM4P2_InterL0L1RMAX[35] = 
+{
+   26, 10,  6,  2,  1,  1,   
+    0,  0,  0,  0,  0,  0,
+	0,	0,	0,	0,	0,	0,
+	0,	0,	0,	0,	0,	0,
+	0,	0,	0,	0,
+    0,  0,  0,  0,  40,  1,  0
+};
+
+/* LMAX table for non Intra (Last == 0 and Last=1)
+   Level - 1 Indexed
+   padded armVCM4P2_IntraL0L1LMAX[15-31] with zeros to acess entries for Last=1 effectively
+
+*/
+const OMX_U8 armVCM4P2_IntraL0L1LMAX[53] = 
+{
+   27, 10,  5,  4,  3,  3,  3,  
+    3,  2,  2,  1,  1,  1,  1,  1,	0,
+	0,	0,	0,	0,	0,	0,	0,	0,
+	0,	0,	0,	0,	0,	0,	0,	0,
+
+	8,  3,  2,  2,  2,  2,  2,  1, 
+	1,  1,  1,  1,  1,  1,  1,  1,
+	1,  1,  1,  1,  1
+};
+
+
+/* RMAX table for non Inter (Last == 0 and Last=1)
+   Level - 1 Indexed 
+ padded armVCM4P2_IntraL0L1RMAX[27-31] with zeros to access entries for Last=1 table effectively */
+
+
+const OMX_U8 armVCM4P2_IntraL0L1RMAX[40] =
+{
+   14,  9,  7,  3,  2,  1,	1,  
+    1,  1,  1,  0,  0,  0, 	0,  
+    0,  0,  0,  0,  0,  0,  0,  
+    0,  0,  0,  0,  0,  0,  0,
+	0,	0,	0,	0,
+	
+	20,  6,  1,  0,  0,  0,  0,  0
+
+};
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/armVCM4P2_Lookup_Tables.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/armVCM4P2_Lookup_Tables.c
new file mode 100644
index 0000000..25cf8db
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/armVCM4P2_Lookup_Tables.c
@@ -0,0 +1,75 @@
+ /**
+ * 
+ * File Name:  armVCM4P2_Lookup_Tables.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * File:        armVCM4P2_Lookup_Tables.c
+ * Description: Contains all the Lookup tables used in MPEG4 codec
+ *
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+
+    /* * Table Entries contain Dc Scaler values
+       * armVCM4P2_DCScaler[i]= 8           for i=1  to  4 and i=33 to 36
+       *                      = 2*i         for i=5  to  8
+       *                      = i+8         for i=9  to  25
+       *                      = 2*i-16      for i=26 to  31
+       *                      = (i-32+13)/2 for i=37 to  59
+       *                      = i-6-32      for i=60 to  63
+       *                      = 255         for i=0 and i=32
+       */
+       
+const OMX_U8 armVCM4P2_DCScaler[64]={
+	0xff, 0x8,  0x8,  0x8,  0x8,  0xa,  0xc,  0xe,  
+    0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 
+    0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
+    0x20, 0x22, 0x24, 0x26, 0x28, 0x2a, 0x2c, 0x2e,
+    0xff, 0x8,  0x8,  0x8,  0x8,  0x9,  0x9,  0xa,  
+    0xa,  0xb,  0xb,  0xc,  0xc,  0xd,  0xd,  0xe,  
+    0xe,  0xf,  0xf,  0x10, 0x10, 0x11, 0x11, 0x12, 
+    0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19,
+
+};
+
+              
+     /*  Table Entries Contain reciprocal of 1 to 63
+      *  armVCM4P2_Reciprocal_QP_S16[i]=round(32767/i)
+      *  armVCM4P2_Reciprocal_QP_S16[0]= 0
+      */
+
+const OMX_S16 armVCM4P2_Reciprocal_QP_S16[64]={
+	0x0000,0x7fff,0x4000,0x2aaa,0x2000,0x1999,0x1555,0x1249,
+    0x1000,0x0e39,0x0ccd,0x0ba3,0x0aab,0x09d9,0x0925,0x0888,
+    0x0800,0x0787,0x071c,0x06bd,0x0666,0x0618,0x05d1,0x0591,
+    0x0555,0x051f,0x04ec,0x04be,0x0492,0x046a,0x0444,0x0421,
+    0x0400,0x03e1,0x03c4,0x03a8,0x038e,0x0376,0x035e,0x0348,
+    0x0333,0x031f,0x030c,0x02fa,0x02e9,0x02d8,0x02c8,0x02b9,
+    0x02ab,0x029d,0x028f,0x0282,0x0276,0x026a,0x025f,0x0254,
+    0x0249,0x023f,0x0235,0x022b,0x0222,0x0219,0x0211,0x0208
+	   
+};
+     
+      /* Table Entries Contain reciprocal of 1 to 63
+       * armVCM4P2_Reciprocal_QP_S32[i]=round(131071/i)
+       * armVCM4P2_Reciprocal_QP_S32[0]= 0
+       */
+
+const OMX_S32 armVCM4P2_Reciprocal_QP_S32[64]={
+	0x00000000,0x0001ffff,0x00010000,0x0000aaaa, 0x00008000, 0x00006666, 0x00005555, 0x00004924,
+    0x00004000,0x000038e3,0x00003333,0x00002e8c, 0x00002aab, 0x00002762, 0x00002492, 0x00002222,
+    0x00002000,0x00001e1e,0x00001c72,0x00001af2, 0x0000199a, 0x00001861, 0x00001746, 0x00001643,
+    0x00001555,0x0000147b,0x000013b1,0x000012f6, 0x00001249, 0x000011a8, 0x00001111, 0x00001084,
+    0x00001000,0x00000f84,0x00000f0f,0x00000ea1, 0x00000e39, 0x00000dd6, 0x00000d79, 0x00000d21,
+    0x00000ccd,0x00000c7d,0x00000c31,0x00000be8, 0x00000ba3, 0x00000b61, 0x00000b21, 0x00000ae5,
+    0x00000aab,0x00000a73,0x00000a3d,0x00000a0a, 0x000009d9, 0x000009a9, 0x0000097b, 0x0000094f,
+    0x00000925,0x000008fb,0x000008d4,0x000008ae, 0x00000889, 0x00000865, 0x00000842, 0x00000820
+	
+};
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/armVCM4P2_SetPredDir_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/armVCM4P2_SetPredDir_s.s
new file mode 100644
index 0000000..3f92d85
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/armVCM4P2_SetPredDir_s.s
@@ -0,0 +1,104 @@
+;//
+;// 
+;// File Name:  armVCM4P2_SetPredDir_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   9641
+;// Date:       Thursday, February 7, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+; **
+; * Function: armVCM4P2_SetPredDir
+; *
+; * Description:
+; * Performs detecting the prediction direction
+; *
+; * Remarks:
+; *
+; * Parameters:
+; * [in] blockIndex  block index indicating the component type and
+; *                          position as defined in subclause 6.1.3.8, of ISO/IEC
+; *                          14496-2. Furthermore, indexes 6 to 9 indicate the
+; *                          alpha blocks spatially corresponding to luminance
+; *                          blocks 0 to 3 in the same macroblock.
+; * [in] pCoefBufRow pointer to the coefficient row buffer
+; * [in] pQpBuf      pointer to the quantization parameter buffer
+; * [out]predQP      quantization parameter of the predictor block
+; * [out]predDir     indicates the prediction direction which takes one
+; *                  of the following values:
+; *                  OMX_VC_HORIZONTAL    predict horizontally
+; *                  OMX_VC_VERTICAL      predict vertically
+; *
+; * Return Value:
+; * Standard OMXResult result. See enumeration for possible result codes.
+; *
+; */
+
+       INCLUDE omxtypes_s.h
+       INCLUDE armCOMM_s.h
+       INCLUDE omxVC_s.h
+
+
+       M_VARIANTS ARM1136JS
+
+
+       IF ARM1136JS
+ 
+;// Input Arguments
+BlockIndex         RN 0
+pCoefBufRow        RN 1
+pCoefBufCol        RN 2
+predDir            RN 3
+predQP             RN 4
+pQpBuf             RN 5
+
+;// Local Variables
+
+Return             RN 0
+blockDCLeft        RN 6  
+blockDCTop         RN 7
+blockDCTopLeft     RN 8
+temp1              RN 9
+temp2              RN 14
+
+       M_START    armVCM4P2_SetPredDir,r9
+
+       M_ARG       ppredQP,4
+       M_ARG       ppQpBuf,4
+    
+       LDRH        blockDCTopLeft,[pCoefBufRow,#-16]
+       LDRH        blockDCLeft,[pCoefBufCol]
+       
+       TEQ         BlockIndex,#3
+       LDREQH      blockDCTop,[pCoefBufCol,#-16]
+       LDRNEH      blockDCTop,[pCoefBufRow]
+             
+       SUBS        temp1,blockDCLeft,blockDCTopLeft
+       RSBLT       temp1,temp1,#0
+       SUBS        temp2,blockDCTopLeft,blockDCTop
+       RSBLT       temp2,temp2,#0
+      
+       M_LDR       pQpBuf,ppQpBuf
+       M_LDR       predQP,ppredQP
+       CMP         temp1,temp2
+       MOV         temp2,#OMX_VC_VERTICAL
+       LDRLTB      temp1,[pQpBuf,#1]
+       STRLT       temp2,[predDir]
+       STRLT       temp1,[predQP]
+       MOV         temp2,#OMX_VC_HORIZONTAL           
+       LDRGEB      temp1,[pQpBuf]
+       STRGE       temp2,[predDir]
+       MOV         Return,#OMX_Sts_NoErr
+       STRGE       temp1,[predQP] 
+
+         
+    
+       M_END
+ 
+       ENDIF
+
+       END    
+    
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/armVCM4P2_Zigzag_Tables.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/armVCM4P2_Zigzag_Tables.c
new file mode 100644
index 0000000..ed17f9b
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/armVCM4P2_Zigzag_Tables.c
@@ -0,0 +1,61 @@
+/**
+ * 
+ * File Name:  armVCM4P2_Zigzag_Tables.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * File:        armVCM4P2_ZigZag_Tables.c
+ * Description: Contains the zigzag tables
+ *
+ */
+
+#include "omxtypes.h"
+
+/* Contains Double the values in the reference Zigzag Table
+ * Contains Classical,Vetical and Horizontal Zigzagscan tables in one array  
+ */
+
+const OMX_U8 armVCM4P2_aClassicalZigzagScan [192] = 
+{
+     0,  2,  16, 32,  18,  4,  6, 20,
+    34, 48, 64, 50, 36, 22,  8,  10,
+    24, 38, 52, 66, 80, 96, 82, 68,
+    54, 40, 26,  12,  14, 28, 42, 56, 
+    70, 84, 98, 112, 114, 100, 86, 72,
+    58, 44, 30, 46, 60, 74, 88, 102,
+    116, 118, 104, 90, 76, 62, 78, 92,
+    106, 120, 122, 104, 94, 110, 124, 126,
+
+	0,  16, 32, 48,  2,  18,  4, 20,
+    34, 50, 64, 80, 96, 112, 114, 98,
+    82, 66, 52, 36,  6, 22,  8, 24,
+    38, 54, 68, 84, 100, 116, 70, 86,
+    102, 118, 40, 56,  10, 26,  12, 28,
+    42, 58, 72, 88, 104, 120, 74, 90, 
+    106, 122, 44, 60,  14, 30, 46, 62,
+    76, 92, 108, 124, 78, 94, 110, 126,
+
+    0,  2,  4,  6,  16,  18, 32, 34,
+    20, 22,  8,  10,  12,  14, 30, 28,
+    26, 24, 38, 36, 48, 50, 64, 66,
+    52, 54, 40, 42, 44, 46, 56, 58,
+    60, 62, 68, 70, 80, 82, 96, 98,
+    84, 86, 72, 74, 76, 78, 88, 90, 
+    92, 94, 100, 102, 112, 114, 116, 118,
+    104, 106, 108, 110, 120, 122, 124, 126
+
+
+};
+
+
+
+
+
+/* End of file */
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/omxVCM4P2_DecodeBlockCoef_Inter.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/omxVCM4P2_DecodeBlockCoef_Inter.c
new file mode 100644
index 0000000..b63d295
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/omxVCM4P2_DecodeBlockCoef_Inter.c
@@ -0,0 +1,102 @@
+/**
+ * 
+ * File Name:  omxVCM4P2_DecodeBlockCoef_Inter.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Description: 
+ * Contains modules for inter reconstruction
+ * 
+ */
+ 
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+
+
+/**
+ * Function: omxVCM4P2_DecodeBlockCoef_Inter
+ *
+ * Description:
+ * Decodes the INTER block coefficients. Inverse quantization, inversely zigzag
+ * positioning and IDCT, with appropriate clipping on each step, are performed
+ * on the coefficients. The results (residuals) are placed in a contiguous array
+ * of 64 elements. For INTER block, the output buffer holds the residuals for
+ * further reconstruction.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	ppBitStream		pointer to the pointer to the current byte in
+ *								the bit stream buffer. There is no boundary
+ *								check for the bit stream buffer.
+ * [in]	pBitOffset		pointer to the bit position in the byte pointed
+ *								to by *ppBitStream. *pBitOffset is valid within
+ *								[0-7]
+ * [in]	QP				quantization parameter
+ * [in] shortVideoHeader    a flag indicating presence of short_video_header;
+ *                           shortVideoHeader==1 indicates using quantization method defined in short
+ *                           video header mode, and shortVideoHeader==0 indicates normail quantization method.
+ * [out] ppBitStream 	*ppBitStream is updated after the block is decoded, so that it points to the
+ *                      current byte in the bit stream buffer.
+ * [out] pBitOffset		*pBitOffset is updated so that it points to the current bit position in the
+ *                      byte pointed by *ppBitStream
+ * [out] pDst			pointer to the decoded residual buffer (a contiguous array of 64 elements of
+ *                      OMX_S16 data type). Must be 16-byte aligned.
+ *
+ * Return Value:
+ * OMX_Sts_NoErr - no error
+ * OMX_Sts_BadArgErr - bad arguments
+ *   - At least one of the following pointers is Null: ppBitStream, *ppBitStream, pBitOffset , pDst
+ *   - At least one of the below case:
+ *   - *pBitOffset exceeds [0,7], QP <= 0;
+ *	 - pDst not 16-byte aligned
+ * OMX_Sts_Err - status error
+ *
+ */
+OMXResult omxVCM4P2_DecodeBlockCoef_Inter(
+     const OMX_U8 ** ppBitStream,
+     OMX_INT * pBitOffset,
+     OMX_S16 * pDst,
+     OMX_INT QP,
+     OMX_INT shortVideoHeader
+)
+{
+    /* 64 elements are needed but to align it to 16 bytes need
+    15 more elements of padding */
+    OMX_S16 tempBuf[79];
+    OMX_S16 *pTempBuf1;
+    OMXResult errorCode;
+    /* Aligning the local buffers */
+    pTempBuf1 = armAlignTo16Bytes(tempBuf);
+    
+    
+    /* VLD and zigzag */
+    errorCode = omxVCM4P2_DecodeVLCZigzag_Inter(ppBitStream, pBitOffset, 
+                                        pTempBuf1,shortVideoHeader);
+    armRetDataErrIf((errorCode != OMX_Sts_NoErr), errorCode);
+    
+    /* Dequantization */
+    errorCode = omxVCM4P2_QuantInvInter_I(
+     pTempBuf1,
+     QP);
+    armRetDataErrIf((errorCode != OMX_Sts_NoErr), errorCode);
+    
+    /* Inverse transform */
+    errorCode = omxVCM4P2_IDCT8x8blk(pTempBuf1, pDst);
+    armRetDataErrIf((errorCode != OMX_Sts_NoErr), errorCode);
+	    
+    return OMX_Sts_NoErr;
+}
+
+/* End of file */
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/omxVCM4P2_DecodeBlockCoef_Intra.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/omxVCM4P2_DecodeBlockCoef_Intra.c
new file mode 100644
index 0000000..c609a60
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/omxVCM4P2_DecodeBlockCoef_Intra.c
@@ -0,0 +1,208 @@
+/**
+ * 
+ * File Name:  omxVCM4P2_DecodeBlockCoef_Intra.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Description: 
+ * Contains modules for intra reconstruction
+ * 
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+
+/**
+ * Function: omxVCM4P2_DecodeBlockCoef_Intra
+ *
+ * Description:
+ * Decodes the INTRA block coefficients. Inverse quantization, inversely zigzag
+ * positioning, and IDCT, with appropriate clipping on each step, are performed
+ * on the coefficients. The results are then placed in the output frame/plane on
+ * a pixel basis. For INTRA block, the output values are clipped to [0, 255] and
+ * written to corresponding block buffer within the destination plane.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	ppBitStream		pointer to the pointer to the current byte in
+ *								the bit stream buffer. There is no boundary
+ *								check for the bit stream buffer.
+ * [in]	pBitOffset		pointer to the bit position in the byte pointed
+ *								to by *ppBitStream. *pBitOffset is valid within
+ *								[0-7].
+ * [in]	step			width of the destination plane
+ * [in/out]	pCoefBufRow		[in]  pointer to the coefficient row buffer
+ *                        [out] updated coefficient rwo buffer
+ * [in/out]	pCoefBufCol		[in]  pointer to the coefficient column buffer
+ *                        [out] updated coefficient column buffer
+ * [in]	curQP			quantization parameter of the macroblock which
+ *								the current block belongs to
+ * [in]	pQpBuf		 Pointer to a 2-element QP array. pQpBuf[0] holds the QP of the 8x8 block left to
+ *                   the current block(QPa). pQpBuf[1] holds the QP of the 8x8 block just above the
+ *                   current block(QPc).
+ *                   Note, in case the corresponding block is out of VOP bound, the QP value will have
+ *                   no effect to the intra-prediction process. Refer to subclause  "7.4.3.3 Adaptive
+ *                   ac coefficient prediction" of ISO/IEC 14496-2(MPEG4 Part2) for accurate description.
+ * [in]	blockIndex		block index indicating the component type and
+ *								position as defined in subclause 6.1.3.8,
+ *								Figure 6-5 of ISO/IEC 14496-2. 
+ * [in]	intraDCVLC		a code determined by intra_dc_vlc_thr and QP.
+ *								This allows a mechanism to switch between two VLC
+ *								for coding of Intra DC coefficients as per Table
+ *								6-21 of ISO/IEC 14496-2. 
+ * [in]	ACPredFlag		a flag equal to ac_pred_flag (of luminance) indicating
+ *								if the ac coefficients of the first row or first
+ *								column are differentially coded for intra coded
+ *								macroblock.
+ * [in] shortVideoHeader    a flag indicating presence of short_video_header;
+ *                           shortVideoHeader==1 selects linear intra DC mode,
+ *							and shortVideoHeader==0 selects nonlinear intra DC mode.
+ * [out]	ppBitStream		*ppBitStream is updated after the block is
+ *								decoded, so that it points to the current byte
+ *								in the bit stream buffer
+ * [out]	pBitOffset		*pBitOffset is updated so that it points to the
+ *								current bit position in the byte pointed by
+ *								*ppBitStream
+ * [out]	pDst			pointer to the block in the destination plane.
+ *								pDst should be 16-byte aligned.
+ * [out]	pCoefBufRow		pointer to the updated coefficient row buffer.
+ *
+ * Return Value:
+ * OMX_Sts_NoErr - no error
+ * OMX_Sts_BadArgErr - bad arguments
+ *   -	At least one of the following pointers is NULL: ppBitStream, *ppBitStream, pBitOffset,
+ *                                                      pCoefBufRow, pCoefBufCol, pQPBuf, pDst.
+ *      or
+ *   -  At least one of the below case: *pBitOffset exceeds [0,7], curQP exceeds (1, 31),
+ *      blockIndex exceeds [0,9], step is not the multiple of 8, intraDCVLC is zero while
+ *      blockIndex greater than 5.
+ *      or
+ *   -	pDst is not 16-byte aligned
+ * OMX_Sts_Err - status error
+ *
+ */
+
+OMXResult omxVCM4P2_DecodeBlockCoef_Intra(
+     const OMX_U8 ** ppBitStream,
+     OMX_INT *pBitOffset,
+     OMX_U8 *pDst,
+     OMX_INT step,
+     OMX_S16 *pCoefBufRow,
+     OMX_S16 *pCoefBufCol,
+     OMX_U8 curQP,
+     const OMX_U8 *pQPBuf,
+     OMX_INT blockIndex,
+     OMX_INT intraDCVLC,
+     OMX_INT ACPredFlag,
+	 OMX_INT shortVideoHeader
+ )
+{
+    OMX_S16 tempBuf1[79], tempBuf2[79];
+    OMX_S16 *pTempBuf1, *pTempBuf2;
+    OMX_INT predDir, predACDir;
+    OMX_INT  predQP;
+    OMXVCM4P2VideoComponent videoComp;
+    OMXResult errorCode;
+    
+    
+    /* Aligning the local buffers */
+    pTempBuf1 = armAlignTo16Bytes(tempBuf1);
+    pTempBuf2 = armAlignTo16Bytes(tempBuf2);
+    
+    /* Setting the AC prediction direction and prediction direction */
+    armVCM4P2_SetPredDir(
+        blockIndex,
+        pCoefBufRow,
+        pCoefBufCol,
+        &predDir,
+        &predQP,
+        pQPBuf);
+
+    predACDir = predDir;
+
+    
+    if (ACPredFlag == 0)
+    {
+        predACDir = OMX_VC_NONE;
+    }
+
+    /* Setting the videoComp */
+    if (blockIndex <= 3)
+    {
+        videoComp = OMX_VC_LUMINANCE;
+    }
+    else
+    {
+        videoComp = OMX_VC_CHROMINANCE;
+    }
+    
+
+    /* VLD and zigzag */
+    if (intraDCVLC == 1)
+    {
+        errorCode = omxVCM4P2_DecodeVLCZigzag_IntraDCVLC(
+            ppBitStream,
+            pBitOffset,
+            pTempBuf1,
+            predACDir,
+            shortVideoHeader,
+            videoComp);
+        armRetDataErrIf((errorCode != OMX_Sts_NoErr), errorCode);
+    }
+    else
+    {
+        errorCode = omxVCM4P2_DecodeVLCZigzag_IntraACVLC(
+            ppBitStream,
+            pBitOffset,
+            pTempBuf1,
+            predACDir,
+            shortVideoHeader);
+        armRetDataErrIf((errorCode != OMX_Sts_NoErr), errorCode);
+    }
+
+    /* AC DC prediction */
+    errorCode = omxVCM4P2_PredictReconCoefIntra(
+        pTempBuf1,
+        pCoefBufRow,
+        pCoefBufCol,
+        curQP,
+        predQP,
+        predDir,
+        ACPredFlag,
+        videoComp);
+    armRetDataErrIf((errorCode != OMX_Sts_NoErr), errorCode);
+    
+    /* Dequantization */
+    errorCode = omxVCM4P2_QuantInvIntra_I(
+     pTempBuf1,
+     curQP,
+     videoComp,
+     shortVideoHeader);
+    armRetDataErrIf((errorCode != OMX_Sts_NoErr), errorCode);
+    
+    /* Inverse transform */
+    errorCode = omxVCM4P2_IDCT8x8blk (pTempBuf1, pTempBuf2);
+    armRetDataErrIf((errorCode != OMX_Sts_NoErr), errorCode);
+    
+    /* Placing the linear array into the destination plane and clipping
+       it to 0 to 255 */
+    
+	armVCM4P2_Clip8(pTempBuf2,pDst,step);
+	
+	
+    return OMX_Sts_NoErr;
+}
+
+/* End of file */
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/omxVCM4P2_DecodePadMV_PVOP_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/omxVCM4P2_DecodePadMV_PVOP_s.s
new file mode 100644
index 0000000..a1861da
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/omxVCM4P2_DecodePadMV_PVOP_s.s
@@ -0,0 +1,364 @@
+; **********
+; * 
+; * File Name:  omxVCM4P2_DecodePadMV_PVOP_s.s
+; * OpenMAX DL: v1.0.2
+; * Revision:   9641
+; * Date:       Thursday, February 7, 2008
+; * 
+; * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+; * 
+; * 
+; * 
+; **
+; * Function: omxVCM4P2_DecodePadMV_PVOP
+; *
+; * Description:
+; * Decodes and pads four motion vectors of the non-intra macroblock in P-VOP.
+; * The motion vector padding process is specified in subclause 7.6.1.6 of
+; * ISO/IEC 14496-2.
+; *
+; * Remarks:
+; *
+; *
+; * Parameters:
+; * [in]    ppBitStream        pointer to the pointer to the current byte in
+; *                            the bit stream buffer
+; * [in]    pBitOffset         pointer to the bit position in the byte pointed
+; *                            to by *ppBitStream. *pBitOffset is valid within
+; *                            [0-7].
+; * [in]    pSrcMVLeftMB       pointers to the motion vector buffers of the
+; *                           macroblocks specially at the left side of the current macroblock
+; *                     respectively.
+; * [in]    pSrcMVUpperMB      pointers to the motion vector buffers of the
+; *                     macroblocks specially at the upper side of the current macroblock
+; *                     respectively.
+; * [in]    pSrcMVUpperRightMB pointers to the motion vector buffers of the
+; *                     macroblocks specially at the upper-right side of the current macroblock
+; *                     respectively.
+; * [in]    fcodeForward       a code equal to vop_fcode_forward in MPEG-4
+; *                     bit stream syntax
+; * [in]    MBType         the type of the current macroblock. If MBType
+; *                     is not equal to OMX_VC_INTER4V, the destination
+; *                     motion vector buffer is still filled with the
+; *                     same decoded vector.
+; * [out]   ppBitStream         *ppBitStream is updated after the block is decoded,
+; *                     so that it points to the current byte in the bit
+; *                     stream buffer
+; * [out]   pBitOffset         *pBitOffset is updated so that it points to the
+; *                     current bit position in the byte pointed by
+; *                     *ppBitStream
+; * [out]   pDstMVCurMB         pointer to the motion vector buffer of the current
+; *                     macroblock which contains four decoded motion vectors
+; *
+; * Return Value:
+; * OMX_Sts_NoErr -no error
+; * 
+; *                     
+; * OMX_Sts_Err - status error
+; *
+; *
+     
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+        INCLUDE armCOMM_BitDec_s.h
+        INCLUDE omxVC_s.h
+        
+       M_VARIANTS ARM1136JS
+       
+                
+
+
+        IF ARM1136JS
+
+;//Input Arguments
+
+ppBitStream           RN 0
+pBitOffset            RN 1
+pSrcMVLeftMB          RN 2
+pSrcMVUpperMB         RN 3
+pSrcMVUpperRightMB    RN 4
+pDstMVCurMB           RN 5
+fcodeForward          RN 6
+MBType                RN 7
+
+;//Local Variables
+
+zero                  RN 4
+one                   RN 4
+scaleFactor           RN 1
+
+
+Return                RN 0
+
+VlcMVD                RN 0
+index                 RN 4
+Count                 RN 7
+
+mvHorData             RN 4
+mvHorResidual         RN 0
+
+mvVerData             RN 4             
+mvVerResidual         RN 0
+
+temp                  RN 1
+
+temp1                 RN 3
+High                  RN 4
+Low                   RN 2
+Range                 RN 1
+
+BlkCount              RN 14
+
+diffMVdx              RN 0
+diffMVdy              RN 1
+
+;// Scratch Registers
+
+RBitStream            RN 8
+RBitCount             RN 9
+RBitBuffer            RN 10
+
+T1                    RN 11
+T2                    RN 12
+LR                    RN 14
+
+       IMPORT          armVCM4P2_aVlcMVD
+       IMPORT          omxVCM4P2_FindMVpred
+
+       ;// Allocate stack memory        
+       
+       M_ALLOC4        ppDstMVCurMB,4
+       M_ALLOC4        pDstMVPredME,4
+       M_ALLOC4        pBlkCount,4
+       
+       M_ALLOC4        pppBitStream,4
+       M_ALLOC4        ppBitOffset,4
+       M_ALLOC4        ppSrcMVLeftMB,4
+       M_ALLOC4        ppSrcMVUpperMB,4
+       
+       M_ALLOC4        pdiffMVdx,4
+       M_ALLOC4        pdiffMVdy,4
+       M_ALLOC4        pHigh,4
+       
+              
+
+
+       M_START   omxVCM4P2_DecodePadMV_PVOP,r11
+       
+       M_ARG           pSrcMVUpperRightMBonStack,4           ;// pointer to  pSrcMVUpperRightMB on stack
+       M_ARG           pDstMVCurMBonStack,4                  ;// pointer to pDstMVCurMB on stack
+       M_ARG           fcodeForwardonStack,4                 ;// pointer to fcodeForward on stack 
+       M_ARG           MBTypeonStack,4                       ;// pointer to MBType on stack
+
+      
+       
+       
+       
+       ;// Initializing the BitStream Macro
+
+       M_BD_INIT0      ppBitStream, pBitOffset, RBitStream, RBitBuffer, RBitCount
+       M_LDR           MBType,MBTypeonStack                  ;// Load MBType from stack
+       M_LDR           pDstMVCurMB,pDstMVCurMBonStack        ;// Load pDstMVCurMB from stack
+       MOV             zero,#0
+
+       TEQ             MBType,#OMX_VC_INTRA                  ;// Check if MBType=OMX_VC_INTRA
+       TEQNE           MBType,#OMX_VC_INTRA_Q                ;// check if MBType=OMX_VC_INTRA_Q
+       STREQ           zero,[pDstMVCurMB]
+       M_BD_INIT1      T1, T2, T2
+       STREQ           zero,[pDstMVCurMB,#4]
+       M_BD_INIT2      T1, T2, T2
+       STREQ           zero,[pDstMVCurMB,#4]
+       MOVEQ           Return,#OMX_Sts_NoErr
+       MOV             BlkCount,#0
+       STREQ           zero,[pDstMVCurMB,#4]
+       
+       BEQ             ExitOK
+
+       TEQ             MBType,#OMX_VC_INTER4V                ;// Check if MBType=OMX_VC_INTER4V
+       TEQNE           MBType,#OMX_VC_INTER4V_Q              ;// Check if MBType=OMX_VC_INTER4V_Q
+       MOVEQ           Count,#4
+
+       TEQ             MBType,#OMX_VC_INTER                  ;// Check if MBType=OMX_VC_INTER
+       TEQNE           MBType,#OMX_VC_INTER_Q                ;// Check if MBType=OMX_VC_INTER_Q
+       MOVEQ           Count,#1
+       
+       M_LDR           fcodeForward,fcodeForwardonStack      ;// Load fcodeForward  from stack
+
+       ;// Storing the values temporarily on stack
+
+       M_STR           ppBitStream,pppBitStream              
+       M_STR           pBitOffset,ppBitOffset
+            
+
+       SUB             temp,fcodeForward,#1                  ;// temp=fcodeForward-1
+       MOV             one,#1
+       M_STR           pSrcMVLeftMB,ppSrcMVLeftMB
+       LSL             scaleFactor,one,temp                  ;// scaleFactor=1<<(fcodeForward-1)
+       M_STR           pSrcMVUpperMB,ppSrcMVUpperMB
+       LSL             scaleFactor,scaleFactor,#5            
+       M_STR           scaleFactor,pHigh                     ;// [pHigh]=32*scaleFactor
+              
+       ;// VLD Decoding
+
+
+Loop
+
+       LDR             VlcMVD, =armVCM4P2_aVlcMVD        ;// Load the optimized MVD VLC table
+
+       ;// Horizontal Data and Residual calculation
+
+       LDR             temp,=0xFFF                           
+       M_BD_VLD        index,T1,T2,VlcMVD,3,2                ;// variable lenght decoding using the macro
+      
+       TEQ             index,temp
+       BEQ             ExitError                             ;// Exit with an Error Message if the decoded symbol is an invalied symbol 
+       
+       SUB             mvHorData,index,#32                   ;// mvHorData=index-32             
+       MOV             mvHorResidual,#1                      ;// mvHorResidual=1
+       CMP             fcodeForward,#1
+       TEQNE           mvHorData,#0
+       MOVEQ           diffMVdx,mvHorData                    ;// if scaleFactor=1(fcodeForward=1) or mvHorData=0 diffMVdx=mvHorData         
+       BEQ             VerticalData
+       
+       SUB             temp,fcodeForward,#1
+       M_BD_VREAD8     mvHorResidual,temp,T1,T2              ;// get mvHorResidual from bitstream if fcodeForward>1 and mvHorData!=0              
+       
+       CMP             mvHorData,#0
+       RSBLT           mvHorData,mvHorData,#0                ;// mvHorData=abs(mvHorData)
+       SUB             mvHorResidual,mvHorResidual,fcodeForward
+       SMLABB          diffMVdx,mvHorData,fcodeForward,mvHorResidual ;// diffMVdx=abs(mvHorData)*fcodeForward+mvHorResidual-fcodeForward
+       ADD             diffMVdx,diffMVdx,#1
+       RSBLT           diffMVdx,diffMVdx,#0
+       
+       ;// Vertical Data and Residual calculation
+
+VerticalData
+
+       M_STR           diffMVdx,pdiffMVdx                    ;// Store the diffMVdx on stack
+       LDR             VlcMVD, =armVCM4P2_aVlcMVD        ;// Loading the address of optimized VLC tables
+
+       LDR             temp,=0xFFF
+       M_BD_VLD        index,T1,T2,VlcMVD,3,2                ;// VLC decoding using the macro
+       
+       TEQ             index,temp
+       BEQ             ExitError                             ;// Exit with an Error Message if an Invalied Symbol occurs
+       
+       SUB             mvVerData,index,#32                   ;// mvVerData=index-32             
+       MOV             mvVerResidual,#1     
+       CMP             fcodeForward,#1
+       TEQNE           mvVerData,#0
+       MOVEQ           diffMVdy,mvVerData                    ;// diffMVdy = mvVerData if scaleFactor=1(fcodeForward=1) or mvVerData=0
+       BEQ             FindMVPred
+
+       SUB             temp,fcodeForward,#1
+       M_BD_VREAD8     mvVerResidual,temp,T1,T2              ;// Get mvVerResidual from bit stream if fcodeForward>1 and mnVerData!=0
+             
+
+       CMP             mvVerData,#0
+       RSBLT           mvVerData,mvVerData,#0
+       SUB             mvVerResidual,mvVerResidual,fcodeForward
+       SMLABB          diffMVdy,mvVerData,fcodeForward,mvVerResidual ;// diffMVdy=abs(mvVerData)*fcodeForward+mvVerResidual-fcodeForward
+       ADD             diffMVdy,diffMVdy,#1
+       RSBLT           diffMVdy,diffMVdy,#0
+
+       ;//Calling the Function omxVCM4P2_FindMVpred
+        
+FindMVPred
+
+       M_STR           diffMVdy,pdiffMVdy
+       ADD             temp,pDstMVCurMB,BlkCount,LSL #2      ;// temp=pDstMVCurMB[BlkCount]
+       M_STR           temp,ppDstMVCurMB                     ;// store temp on stack for passing as an argument to FindMVPred
+       
+       MOV             temp,#0
+       M_STR           temp,pDstMVPredME                     ;// Pass pDstMVPredME=NULL as an argument         
+       M_STR           BlkCount,pBlkCount                    ;// Passs BlkCount as Argument through stack
+
+       MOV             temp,pSrcMVLeftMB                     ;// temp (RN 1)=pSrcMVLeftMB
+       M_LDR           pSrcMVUpperRightMB,pSrcMVUpperRightMBonStack
+       MOV             pSrcMVLeftMB,pSrcMVUpperMB            ;// pSrcMVLeftMB ( RN 2) = pSrcMVUpperMB
+       MOV             ppBitStream,pDstMVCurMB               ;// ppBitStream  ( RN 0) = pDstMVCurMB
+       MOV             pSrcMVUpperMB,pSrcMVUpperRightMB      ;// pSrcMVUpperMB( RN 3) = pSrcMVUpperRightMB      
+       BL              omxVCM4P2_FindMVpred              ;// Branch to subroutine omxVCM4P2_FindMVpred
+
+       ;// Store Horizontal Motion Vector
+     
+       M_LDR           BlkCount,pBlkCount                    ;// Load BlkCount from stack
+       M_LDR           High,pHigh                            ;// High=32*scaleFactor
+       LSL             temp1,BlkCount,#2                     ;// temp=BlkCount*4
+       M_LDR           diffMVdx,pdiffMVdx                    ;// Laad diffMVdx
+       
+       LDRSH           temp,[pDstMVCurMB,temp1]              ;// temp=pDstMVCurMB[BlkCount]
+       
+       
+       RSB             Low,High,#0                           ;// Low = -32*scaleFactor
+       ADD             diffMVdx,temp,diffMVdx                ;// diffMVdx=pDstMVCurMB[BlkCount]+diffMVdx
+       ADD             Range,High,High                       ;// Range=64*ScaleFactor
+       SUB             High,High,#1                          ;// High= 32*scaleFactor-1
+
+       CMP             diffMVdx,Low                          ;// If diffMVdx<Low          
+       ADDLT           diffMVdx,diffMVdx,Range               ;// diffMVdx+=Range
+        
+       CMP             diffMVdx,High                         
+       SUBGT           diffMVdx,diffMVdx,Range               ;// If diffMVdx > High diffMVdx-=Range
+       STRH            diffMVdx,[pDstMVCurMB,temp1]
+
+       ;// Store Vertical
+
+       ADD             temp1,temp1,#2                        ;// temp1=4*BlkCount+2
+       M_LDR           diffMVdx,pdiffMVdy                    ;// Laad diffMVdy
+       LDRSH           temp,[pDstMVCurMB,temp1]              ;// temp=pDstMVCurMB[BlkCount].diffMVdy
+       ADD             BlkCount,BlkCount,#1                  ;// BlkCount=BlkCount+1
+       ADD             diffMVdx,temp,diffMVdx                
+       CMP             diffMVdx,Low
+       ADDLT           diffMVdx,diffMVdx,Range               ;// If diffMVdy<Low  diffMVdy+=Range                
+       CMP             diffMVdx,High
+       SUBGT           diffMVdx,diffMVdx,Range               ;// If diffMVdy > High diffMVdy-=Range
+       STRH            diffMVdx,[pDstMVCurMB,temp1]    
+       
+       CMP             BlkCount,Count
+       M_LDR           pSrcMVLeftMB,ppSrcMVLeftMB
+       M_LDR           pSrcMVUpperMB,ppSrcMVUpperMB
+
+       BLT             Loop                                  ;// If BlkCount<Count Continue the Loop
+
+
+       ;// If MBType=OMX_VC_INTER or MBtype=OMX_VC_INTER_Q copy pDstMVCurMB[0] to
+       ;// pDstMVCurMB[1], pDstMVCurMB[2], pDstMVCurMB[3] 
+
+       M_LDR           MBType,MBTypeonStack
+
+       TEQ             MBType,#OMX_VC_INTER                                       
+       TEQNE           MBType,#OMX_VC_INTER_Q                            
+       LDREQ           temp,[pDstMVCurMB]
+       M_LDR           ppBitStream,pppBitStream
+       STREQ           temp,[pDstMVCurMB,#4]
+       
+       STREQ           temp,[pDstMVCurMB,#8]
+       STREQ           temp,[pDstMVCurMB,#12]
+       
+       
+       M_LDR           pBitOffset,ppBitOffset
+       ;//Ending the macro
+       M_BD_FINI       ppBitStream,pBitOffset                 ;// Finishing the Macro       
+
+       
+       MOV             Return,#OMX_Sts_NoErr
+       B               ExitOK
+ 
+ExitError
+
+       M_LDR           ppBitStream,pppBitStream
+       M_LDR           pBitOffset,ppBitOffset
+       ;//Ending the macro
+       M_BD_FINI       ppBitStream,pBitOffset
+       
+       MOV             Return,#OMX_Sts_Err
+
+ExitOK             
+
+       M_END
+       ENDIF
+       END
+
+
+   
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_Inter_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_Inter_s.s
new file mode 100644
index 0000000..c43b253
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_Inter_s.s
@@ -0,0 +1,132 @@
+;/**
+; * 
+; * File Name:  omxVCM4P2_DecodeVLCZigzag_Inter_s.s
+; * OpenMAX DL: v1.0.2
+; * Revision:   9641
+; * Date:       Thursday, February 7, 2008
+; * 
+; * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+; * 
+; * 
+; *
+; * Description: 
+; * Contains modules for zigzag scanning and VLC decoding
+; * for inter block.
+; *
+; *
+; *
+; * Function: omxVCM4P2_DecodeVLCZigzag_Inter
+; *
+; * Description:
+; * Performs VLC decoding and inverse zigzag scan for one inter coded block.
+; *
+; * Remarks:
+; *
+; * Parameters:
+; * [in]    ppBitStream        pointer to the pointer to the current byte in
+; *                    the bitstream buffer
+; * [in]    pBitOffset        pointer to the bit position in the byte pointed
+; *                    to by *ppBitStream. *pBitOffset is valid within    [0-7].
+; * [in] shortVideoHeader     binary flag indicating presence of short_video_header;
+; *                           escape modes 0-3 are used if shortVideoHeader==0,
+; *                           and escape mode 4 is used when shortVideoHeader==1.
+; * [out]    ppBitStream        *ppBitStream is updated after the block is
+; *                    decoded, so that it points to the current byte
+; *                    in the bit stream buffer
+; * [out]    pBitOffset        *pBitOffset is updated so that it points to the
+; *                    current bit position in the byte pointed by
+; *                    *ppBitStream
+; * [out]    pDst            pointer to the coefficient buffer of current
+; *                    block. Must be 16-byte aligned
+; *
+; * Return Value:
+; * OMX_Sts_BadArgErr - bad arguments
+; *   -At least one of the following pointers is NULL: ppBitStream, *ppBitStream, pBitOffset, pDst, or
+; *   -pDst is not 16-byte aligned, or
+; *   -*pBitOffset exceeds [0,7].
+; * OMX_Sts_Err - status error
+; *   -At least one mark bit is equal to zero
+; *   -Encountered an illegal stream code that cannot be found in the VLC table
+; *   -Encountered and illegal code in the VLC FLC table
+; *   -The number of coefficients is greater than 64
+; *
+; */
+
+
+      INCLUDE omxtypes_s.h
+      INCLUDE armCOMM_s.h
+      INCLUDE armCOMM_BitDec_s.h
+
+
+      M_VARIANTS ARM1136JS
+
+     
+
+
+
+     IF ARM1136JS
+     
+        ;// Import various tables needed for the function
+
+        
+        IMPORT          armVCM4P2_InterVlcL0L1             ;// Contains optimized and packed VLC Tables for both Last =1 and last=0
+                                                               ;// Packed in Run:Level:Last format
+        IMPORT          armVCM4P2_InterL0L1LMAX            ;// Contains LMAX table entries with both Last=0 and Last=1
+        IMPORT          armVCM4P2_InterL0L1RMAX            ;// Contains RMAX table entries with both Last=0 and Last=1
+        IMPORT          armVCM4P2_aClassicalZigzagScan     ;// contains classical Zigzag table entries with double the original values
+        IMPORT          armVCM4P2_DecodeVLCZigzag_AC_unsafe
+
+
+
+;//Input Arguments
+
+ppBitStream          RN 0
+pBitOffset           RN 1
+pDst                 RN 2
+shortVideoHeader     RN 3
+
+;//Local Variables
+
+Return               RN 0
+
+pVlcTableL0L1        RN 4
+pLMAXTableL0L1       RN 4
+pRMAXTableL0L1       RN 4
+pZigzagTable         RN 4
+Count                RN 6
+
+
+        
+        ;// Allocate stack memory to store the VLC,Zigzag,LMAX and RMAX tables
+     
+        
+        M_ALLOC4        ppVlcTableL0L1,4
+        M_ALLOC4        ppLMAXTableL0L1,4
+        M_ALLOC4        ppRMAXTableL0L1,4
+        M_ALLOC4        ppZigzagTable,4
+        
+        
+        M_START omxVCM4P2_DecodeVLCZigzag_Inter,r12
+
+        
+
+        
+        LDR             pZigzagTable, =armVCM4P2_aClassicalZigzagScan       ;// Load zigzag table
+        M_STR           pZigzagTable,ppZigzagTable                              ;// Store zigzag table on stack to pass as argument to unsafe function
+        LDR             pVlcTableL0L1, =armVCM4P2_InterVlcL0L1              ;// Load optimized VLC table with both L=0 and L=1 entries
+        M_STR           pVlcTableL0L1,ppVlcTableL0L1                            ;// Store optimized VLC table address on stack
+        LDR             pLMAXTableL0L1, =armVCM4P2_InterL0L1LMAX            ;// Load Interleaved L=0 and L=1 LMAX Tables
+        M_STR           pLMAXTableL0L1,ppLMAXTableL0L1                          ;// Store LMAX table address on stack
+        LDR             pRMAXTableL0L1, =armVCM4P2_InterL0L1RMAX            ;// Load Interleaved L=0 and L=1 RMAX Tables
+        MOV             Count,#0                                                ;// set start=0
+        M_STR           pRMAXTableL0L1,ppRMAXTableL0L1                          ;// store RMAX table address on stack
+                
+
+        BL              armVCM4P2_DecodeVLCZigzag_AC_unsafe                 ;// call Unsafe Function for VLC Zigzag Decoding
+         
+       
+
+        M_END
+        ENDIF
+        
+        END
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_IntraACVLC_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_IntraACVLC_s.s
new file mode 100644
index 0000000..166729e
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_IntraACVLC_s.s
@@ -0,0 +1,136 @@
+;/**
+; * 
+; * File Name:  omxVCM4P2_DecodeVLCZigzag_IntraACVLC_s.s
+; * OpenMAX DL: v1.0.2
+; * Revision:   9641
+; * Date:       Thursday, February 7, 2008
+; * 
+; * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+; * 
+; * 
+; *
+; * Description: 
+; * Contains modules for zigzag scanning and VLC decoding
+; * for inter block.
+; *
+; *
+; *
+; * Function: omxVCM4P2_DecodeVLCZigzag_Inter
+; *
+; * Description:
+; * Performs VLC decoding and inverse zigzag scan for one intra coded block.
+; *
+; * Remarks:
+; *
+; * Parameters:
+; * [in]    ppBitStream        pointer to the pointer to the current byte in
+; *                    the bitstream buffer
+; * [in]    pBitOffset        pointer to the bit position in the byte pointed
+; *                    to by *ppBitStream. *pBitOffset is valid within    [0-7].
+; * [in] shortVideoHeader     binary flag indicating presence of short_video_header;
+; *                           escape modes 0-3 are used if shortVideoHeader==0,
+; *                           and escape mode 4 is used when shortVideoHeader==1.
+; * [out]    ppBitStream        *ppBitStream is updated after the block is
+; *                    decoded, so that it points to the current byte
+; *                    in the bit stream buffer
+; * [out]    pBitOffset        *pBitOffset is updated so that it points to the
+; *                    current bit position in the byte pointed by
+; *                    *ppBitStream
+; * [out]    pDst            pointer to the coefficient buffer of current
+; *                    block. Must be 16-byte aligned
+; *
+; * Return Value:
+; * OMX_Sts_BadArgErr - bad arguments
+; *   -At least one of the following pointers is NULL: ppBitStream, *ppBitStream, pBitOffset, pDst, or
+; *   -pDst is not 16-byte aligned, or
+; *   -*pBitOffset exceeds [0,7].
+; * OMX_Sts_Err - status error
+; *   -At least one mark bit is equal to zero
+; *   -Encountered an illegal stream code that cannot be found in the VLC table
+; *   -Encountered and illegal code in the VLC FLC table
+; *   -The number of coefficients is greater than 64
+; *
+; */
+
+
+      INCLUDE omxtypes_s.h
+      INCLUDE armCOMM_s.h
+      INCLUDE armCOMM_BitDec_s.h
+
+
+      M_VARIANTS ARM1136JS
+
+     
+
+
+
+     IF ARM1136JS
+     
+        ;// Import various tables needed for the function
+
+        
+        IMPORT          armVCM4P2_IntraVlcL0L1             ;// Contains optimized and packed VLC Tables for both Last =1 and last=0
+                                                               ;// Packed in Run:Level:Last format
+        IMPORT          armVCM4P2_IntraL0L1LMAX            ;// Contains LMAX table entries with both Last=0 and Last=1
+        IMPORT          armVCM4P2_IntraL0L1RMAX            ;// Contains RMAX table entries with both Last=0 and Last=1
+        IMPORT          armVCM4P2_aClassicalZigzagScan     ;// contains classical Zigzag table entries with double the original values
+        IMPORT          armVCM4P2_DecodeVLCZigzag_AC_unsafe
+
+;//Input Arguments
+
+ppBitStream          RN 0
+pBitOffset           RN 1
+pDst                 RN 2
+PredDir              RN 3
+shortVideoHeader     RN 3
+
+;//Local Variables
+
+Return               RN 0
+
+pVlcTableL0L1        RN 4
+pLMAXTableL0L1       RN 4
+pRMAXTableL0L1       RN 4
+pZigzagTable         RN 4
+Count                RN 6
+
+
+        
+        ;// Allocate stack memory to store optimized VLC,Zigzag, RMAX, LMAX Table Addresses 
+     
+        M_ALLOC4        ppVlcTableL0L1,4
+        M_ALLOC4        ppLMAXTableL0L1,4
+        M_ALLOC4        ppRMAXTableL0L1,4
+        M_ALLOC4        ppZigzagTable,4
+
+        
+        M_START omxVCM4P2_DecodeVLCZigzag_IntraACVLC,r12
+
+        M_ARG           shortVideoHeaderonStack,4                             ;// pointer to Input Argument on stack           
+
+        LDR             pZigzagTable, =armVCM4P2_aClassicalZigzagScan     ;// Load Address of the Zigzag table    
+        ADD             pZigzagTable, pZigzagTable, PredDir, LSL #6           ;// Loading Different type of zigzag tables based on PredDir
+       
+        M_STR           pZigzagTable,ppZigzagTable                            ;// Store Zigzag table address on stack
+        LDR             pVlcTableL0L1, =armVCM4P2_IntraVlcL0L1            ;// Load optimized packed VLC Table with both L=0 and L=1 entries
+        M_STR           pVlcTableL0L1,ppVlcTableL0L1                          ;// Store VLC Table address on stack
+        LDR             pLMAXTableL0L1, =armVCM4P2_IntraL0L1LMAX          ;// Load LMAX Table
+        M_STR           pLMAXTableL0L1,ppLMAXTableL0L1                        ;// Store LMAX Table address on Stack
+        LDR             pRMAXTableL0L1, =armVCM4P2_IntraL0L1RMAX          ;// Load RMAX Table
+        MOV             Count,#0                                              ;// Set Start=0        
+        
+        M_STR           pRMAXTableL0L1,ppRMAXTableL0L1                        ;// Store RMAX Table address on stack
+              
+
+       
+        M_LDR           shortVideoHeader,shortVideoHeaderonStack              ;// get the Input Argument from stack
+
+        BL              armVCM4P2_DecodeVLCZigzag_AC_unsafe               ;// Call Unsafe Function
+
+
+
+        
+        M_END
+        ENDIF
+        
+        END
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_IntraDCVLC_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_IntraDCVLC_s.s
new file mode 100644
index 0000000..d19cb13
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_IntraDCVLC_s.s
@@ -0,0 +1,224 @@
+;/**
+; * 
+; * File Name:  omxVCM4P2_DecodeVLCZigzag_IntraDCVLC_s.s
+; * OpenMAX DL: v1.0.2
+; * Revision:   9641
+; * Date:       Thursday, February 7, 2008
+; * 
+; * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+; * 
+; * 
+; *
+; * Description: 
+; * Contains modules for zigzag scanning and VLC decoding
+; * for inter block.
+; *
+; *
+; *
+; * Function: omxVCM4P2_DecodeVLCZigzag_Inter
+; *
+; * Description:
+; * Performs VLC decoding and inverse zigzag scan for one intra coded block.
+; *
+; * Remarks:
+; *
+; * Parameters:
+; * [in]    ppBitStream        pointer to the pointer to the current byte in
+; *                    the bitstream buffer
+; * [in]    pBitOffset        pointer to the bit position in the byte pointed
+; *                    to by *ppBitStream. *pBitOffset is valid within    [0-7].
+; * [in] shortVideoHeader     binary flag indicating presence of short_video_header;
+; *                           escape modes 0-3 are used if shortVideoHeader==0,
+; *                           and escape mode 4 is used when shortVideoHeader==1.
+; * [out]    ppBitStream        *ppBitStream is updated after the block is
+; *                    decoded, so that it points to the current byte
+; *                    in the bit stream buffer
+; * [out]    pBitOffset        *pBitOffset is updated so that it points to the
+; *                    current bit position in the byte pointed by
+; *                    *ppBitStream
+; * [out]    pDst            pointer to the coefficient buffer of current
+; *                    block. Must be 16-byte aligned
+; *
+; * Return Value:
+; * OMX_Sts_BadArgErr - bad arguments
+; *   -At least one of the following pointers is NULL: ppBitStream, *ppBitStream, pBitOffset, pDst, or
+; *   -pDst is not 16-byte aligned, or
+; *   -*pBitOffset exceeds [0,7].
+; * OMX_Sts_Err - status error
+; *   -At least one mark bit is equal to zero
+; *   -Encountered an illegal stream code that cannot be found in the VLC table
+; *   -Encountered and illegal code in the VLC FLC table
+; *   -The number of coefficients is greater than 64
+; *
+; */
+
+
+      INCLUDE omxtypes_s.h
+      INCLUDE armCOMM_s.h
+      INCLUDE armCOMM_BitDec_s.h
+
+
+      M_VARIANTS ARM1136JS
+
+     
+      
+
+
+      IF ARM1136JS :LOR: CortexA8
+
+     
+        ;// Import various tables needed for the function
+
+        
+        IMPORT          armVCM4P2_IntraVlcL0L1             ;// Contains optimized and packed VLC Tables for both Last =1 and last=0
+                                                               ;// Packed in Run:Level:Last format
+        IMPORT          armVCM4P2_IntraL0L1LMAX            ;// Contains LMAX table entries with both Last=0 and Last=1
+        IMPORT          armVCM4P2_IntraL0L1RMAX            ;// Contains RMAX table entries with both Last=0 and Last=1
+        IMPORT          armVCM4P2_aClassicalZigzagScan     ;// contains CLassical, Horizontal, Vertical Zigzag table entries with double the original values
+        IMPORT          armVCM4P2_aIntraDCLumaChromaIndex  ;// Contains Optimized DCLuma and DCChroma Index table Entries
+        
+
+        IMPORT          armVCM4P2_DecodeVLCZigzag_AC_unsafe
+
+;//Input Arguments
+
+ppBitStream          RN 0
+pBitOffset           RN 1
+pDst                 RN 2
+PredDir              RN 3
+shortVideoHeader     RN 3
+videoComp            RN 5
+;//Local Variables
+
+Return               RN 0
+
+pDCLumaChromaIndex   RN 4
+pDCChromaIndex       RN 7
+pVlcTableL0L1        RN 4
+pLMAXTableL0L1       RN 4
+pRMAXTableL0L1       RN 4
+pZigzagTable         RN 4
+Count                RN 6
+DCValueSize          RN 6
+powOfSize            RN 7
+temp1                RN 5
+
+
+;// Scratch Registers
+
+RBitStream           RN 8
+RBitBuffer           RN 9
+RBitCount            RN 10
+
+T1                   RN 11
+T2                   RN 12
+DCVal                RN 14
+
+        
+        ;// Allocate stack memory to store optimized VLC,Zigzag, RMAX, LMAX Table Addresses 
+     
+        M_ALLOC4        ppVlcTableL0L1,4
+        M_ALLOC4        ppLMAXTableL0L1,4
+        M_ALLOC4        ppRMAXTableL0L1,4
+        M_ALLOC4        ppZigzagTable,4
+        M_ALLOC4        pDCCoeff,4
+        
+
+        
+        M_START omxVCM4P2_DecodeVLCZigzag_IntraDCVLC,r12
+
+        M_ARG           shortVideoHeaderonStack,4                                  ;// Pointer to argument on stack  
+        M_ARG           videoComponstack,4                                         ;// Pointer to argument on stack
+
+        
+        ;// Decode DC Coefficient
+
+        
+        LDR             pDCLumaChromaIndex, =armVCM4P2_aIntraDCLumaChromaIndex ;// Load Optimized VLC Table for Luminance and Chrominance
+
+        ;// Initializing the Bitstream Macro
+
+        M_BD_INIT0      ppBitStream, pBitOffset, RBitStream, RBitBuffer, RBitCount
+        M_LDR           videoComp,videoComponstack                                 
+        M_BD_INIT1      T1, T2, T2
+        ADD             pDCLumaChromaIndex,pDCLumaChromaIndex,videoComp, LSL #6             
+        M_BD_INIT2      T1, T2, T2
+    
+        
+        M_BD_VLD        DCValueSize,T1,T2,pDCLumaChromaIndex,4,2                    ;// VLC Decode using optimized Luminance and Chrominance VLC Table
+
+    
+       
+
+DecodeDC
+                         
+        CMP             DCValueSize,#12     
+        BGT             ExitError
+        
+        CMP             DCValueSize,#0
+        MOVEQ           DCVal,#0                                                    ;// If DCValueSize is zero then DC coeff =0
+        BEQ             ACDecode                                                    ;// Branch to perform AC Coeff Decoding
+        
+        M_BD_VREAD16    DCVal,DCValueSize,T1,T2                                     ;// Get DC Value From Bit stream
+         
+
+        MOV             powOfSize,#1                                                
+        LSL             powOfSize,DCValueSize                                       ;// powOfSize=pow(2,DCValueSize)
+        CMP             DCVal,powOfSize,LSR #1                                      ;// Compare DCVal with powOfSize/2 
+        ADDLT           DCVal,DCVal,#1
+        SUBLT           DCVal,DCVal,powOfSize                                       ;// If Lessthan powOfSize/2 DCVal=DCVal-powOfSize+1
+                                                                                    ;// Else DCVal= fetchbits from bit stream
+
+CheckDCValueSize
+        
+        CMP             DCValueSize,#8                                              ;// If DCValueSize greater than 8 check marker bit
+
+        BLE             ACDecode
+
+        M_BD_READ8      temp1,1,T1
+        TEQ             temp1,#0                                                    ;// If Marker bit is zero Exit with an Error Message
+        BEQ             ExitError
+
+        
+
+        ;// Decode AC Coefficient
+
+ACDecode
+
+        M_STR           DCVal,pDCCoeff                                             ;// Store Decoded DC Coeff on Stack
+        M_BD_FINI       ppBitStream,pBitOffset                                     ;// Terminating the Bit stream Macro
+         
+        LDR             pZigzagTable, =armVCM4P2_aClassicalZigzagScan          ;// Load Zigzag talbe address   
+        ADD             pZigzagTable, pZigzagTable, PredDir, LSL #6                ;// Modify the Zigzag table adress based on PredDir                
+       
+        M_STR           pZigzagTable,ppZigzagTable                                 ;// Store zigzag table on stack
+        LDR             pVlcTableL0L1, =armVCM4P2_IntraVlcL0L1                 ;// Load Optimized VLC Table With both Last=0 and Last=1 Entries
+        M_STR           pVlcTableL0L1,ppVlcTableL0L1                               ;// Store Optimized VLC Table on stack
+        LDR             pLMAXTableL0L1, =armVCM4P2_IntraL0L1LMAX               ;// Load LMAX Table
+        M_STR           pLMAXTableL0L1,ppLMAXTableL0L1                             ;// Store LMAX table on stack
+        LDR             pRMAXTableL0L1, =armVCM4P2_IntraL0L1RMAX               ;// Load RMAX Table
+        MOV             Count,#1                                                   ;// Set Start =1        
+        
+        M_STR           pRMAXTableL0L1,ppRMAXTableL0L1                             ;// Store RMAX Table on Stack
+        
+       
+        M_LDR           shortVideoHeader,shortVideoHeaderonStack                   ;// Load the Input Argument From Stack
+        
+        BL              armVCM4P2_DecodeVLCZigzag_AC_unsafe                    ;// Call the Unsafe Function
+
+        M_LDR           DCVal,pDCCoeff                                             ;// Get the Decoded DC Value From Stack
+        STRH            DCVal,[pDst]                                               ;// Store the DC Value 
+        B               ExitOK
+        
+              
+
+ExitError
+ 
+        M_BD_FINI       ppBitStream,pBitOffset                                     ;// Terminating the Bit Stream Macro in case of an Error
+        MOV             Return,#OMX_Sts_Err                                        ;// Exit with an Error Message 
+ExitOK
+      
+        M_END
+        ENDIF
+        
+        END
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/omxVCM4P2_FindMVpred_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/omxVCM4P2_FindMVpred_s.s
new file mode 100644
index 0000000..a4bfa71
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/omxVCM4P2_FindMVpred_s.s
@@ -0,0 +1,194 @@
+;//
+;// 
+;// File Name:  omxVCM4P2_FindMVpred_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   9641
+;// Date:       Thursday, February 7, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+;// Function:
+;//     omxVCM4P2_FindMVpred
+;//
+        ;// Include headers
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+        INCLUDE armVCCOMM_s.h
+
+        ;// Define cpu variants
+        M_VARIANTS ARM1136JS
+        
+        
+        IF ARM1136JS
+        
+        M_TABLE armVCM4P2_pBlkIndexTable
+        DCD  OMXVCBlk0, OMXVCBlk1
+        DCD  OMXVCBlk2, OMXVCBlk3
+
+;//--------------------------------------------
+;// Declare input registers
+;//--------------------------------------------
+        
+pSrcMVCurMB            RN 0
+pSrcCandMV1            RN 1
+pSrcCandMV2            RN 2
+pSrcCandMV3            RN 3
+pDstMVPred             RN 4
+pDstMVPredME           RN 5
+iBlk                   RN 6
+
+pTable                 RN 4
+CandMV                 RN 12
+
+pCandMV1               RN 7
+pCandMV2               RN 8
+pCandMV3               RN 9
+
+CandMV1dx              RN 0 
+CandMV1dy              RN 1 
+CandMV2dx              RN 2
+CandMV2dy              RN 3
+CandMV3dx              RN 10
+CandMV3dy              RN 11
+
+temp                   RN 14
+
+zero                   RN 14
+return                 RN 0
+        
+; ----------------------------------------------
+; Main routine
+; ----------------------------------------------        
+
+        M_ALLOC4 MV, 4
+        
+        ;// Function header 
+        M_START omxVCM4P2_FindMVpred, r11
+        
+        ;// Define stack arguments
+        M_ARG   ppDstMVPred,  4
+        M_ARG   ppDstMVPredME, 4
+        M_ARG   Blk, 4
+        
+        M_ADR CandMV, MV
+        MOV   zero, #0
+        M_LDR iBlk, Blk
+        
+        ;// Set the default value for these
+        ;// to be used if pSrcCandMV[1|2|3] == NULL
+        MOV   pCandMV1, CandMV
+        MOV   pCandMV2, CandMV
+        MOV   pCandMV3, CandMV
+    
+        STR   zero, [CandMV]
+
+        ;// Branch to the case based on blk number
+        M_SWITCH iBlk
+        M_CASE   OMXVCBlk0      ;// iBlk=0
+        M_CASE   OMXVCBlk1      ;// iBlk=0
+        M_CASE   OMXVCBlk2      ;// iBlk=0
+        M_CASE   OMXVCBlk3      ;// iBlk=0
+        M_ENDSWITCH
+        
+OMXVCBlk0
+        CMP   pSrcCandMV1, #0
+        ADDNE pCandMV1, pSrcCandMV1, #4
+        
+        CMP   pSrcCandMV2, #0
+        ADDNE pCandMV2, pSrcCandMV2, #8
+
+        CMP   pSrcCandMV3, #0
+        ADDNE pCandMV3, pSrcCandMV3, #8
+        CMPEQ pSrcCandMV1, #0
+    
+        MOVEQ pCandMV3, pCandMV2
+        MOVEQ pCandMV1, pCandMV2
+                
+        CMP   pSrcCandMV1, #0
+        CMPEQ pSrcCandMV2, #0
+    
+        MOVEQ pCandMV1, pCandMV3
+        MOVEQ pCandMV2, pCandMV3
+        
+        CMP   pSrcCandMV2, #0
+        CMPEQ pSrcCandMV3, #0
+    
+        MOVEQ pCandMV2, pCandMV1
+        MOVEQ pCandMV3, pCandMV1
+        
+        B     BlkEnd
+    
+OMXVCBlk1
+        MOV   pCandMV1, pSrcMVCurMB
+        CMP   pSrcCandMV3, #0
+        ADDNE pCandMV3, pSrcCandMV3, #8
+        
+        CMP   pSrcCandMV2, #0
+        ADDNE pCandMV2, pSrcCandMV2, #12
+    
+        CMPEQ pSrcCandMV3, #0
+    
+        MOVEQ pCandMV2, pCandMV1
+        MOVEQ pCandMV3, pCandMV1
+            
+        B     BlkEnd
+
+OMXVCBlk2
+        CMP   pSrcCandMV1, #0
+        MOV   pCandMV2, pSrcMVCurMB
+        ADD   pCandMV3, pSrcMVCurMB, #4
+        ADDNE pCandMV1, pSrcCandMV1, #12
+        B     BlkEnd
+
+OMXVCBlk3
+        ADD   pCandMV1, pSrcMVCurMB, #8
+        MOV   pCandMV2, pSrcMVCurMB
+        ADD   pCandMV3, pSrcMVCurMB, #4
+    
+BlkEnd
+
+        ;// Using the transperancy info, zero
+        ;// out the candidate MV if neccesary
+        LDRSH CandMV1dx, [pCandMV1], #2
+        LDRSH CandMV2dx, [pCandMV2], #2
+        LDRSH CandMV3dx, [pCandMV3], #2
+    
+        ;// Load argument from the stack
+        M_LDR pDstMVPredME, ppDstMVPredME
+
+        LDRSH CandMV1dy, [pCandMV1]
+        LDRSH CandMV2dy, [pCandMV2]
+        LDRSH CandMV3dy, [pCandMV3]
+
+        CMP pDstMVPredME, #0        
+
+        ;// Store the candidate MV's into the pDstMVPredME, 
+        ;// these can be used in the fast algorithm if implemented 
+
+        STRHNE CandMV1dx, [pDstMVPredME], #2
+        STRHNE CandMV1dy, [pDstMVPredME], #2        
+        STRHNE CandMV2dx, [pDstMVPredME], #2
+        STRHNE CandMV2dy, [pDstMVPredME], #2
+        STRHNE CandMV3dx, [pDstMVPredME], #2
+        STRHNE CandMV3dy, [pDstMVPredME]
+           
+        ; Find the median of the 3 candidate MV's
+        M_MEDIAN3 CandMV1dx, CandMV2dx, CandMV3dx, temp
+
+        ;// Load argument from the stack
+        M_LDR pDstMVPred, ppDstMVPred
+
+        M_MEDIAN3 CandMV1dy, CandMV2dy, CandMV3dy, temp
+    
+        STRH CandMV3dx, [pDstMVPred], #2
+        STRH CandMV3dy, [pDstMVPred]
+
+        MOV return, #OMX_Sts_NoErr
+    
+        M_END
+    ENDIF ;// ARM1136JS :LOR: CortexA8
+    
+    END
\ No newline at end of file
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/omxVCM4P2_IDCT8x8blk_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/omxVCM4P2_IDCT8x8blk_s.s
new file mode 100644
index 0000000..bfeb540
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/omxVCM4P2_IDCT8x8blk_s.s
@@ -0,0 +1,73 @@
+;//
+;// 
+;// File Name:  omxVCM4P2_IDCT8x8blk_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   9641
+;// Date:       Thursday, February 7, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+;// Function:
+;//     omxVCM4P2_IDCT8x8blk
+;//
+        ;// Include headers
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+
+        ;// Define cpu variants
+        M_VARIANTS ARM1136JS
+
+        INCLUDE armCOMM_IDCT_s.h        
+        
+        IMPORT armCOMM_IDCTPreScale
+        ;//
+        ;// Function prototype
+        ;//
+        ;//     OMXResult
+        ;//     omxVCM4P2_IDCT8x8blk(const OMX_S16* pSrc,
+        ;//                                       OMX_S16* pDst)
+        ;//    
+        
+    IF ARM1136JS :LOR: CortexA8
+        M_ALLOC4  ppDest, 4
+        M_ALLOC4  pStride, 4
+        M_ALLOC8  pBlk, 2*8*8
+    ENDIF
+    
+    IF ARM1136JS
+        M_START omxVCM4P2_IDCT8x8blk, r11
+    ENDIF
+    
+        
+    IF ARM1136JS :LOR: CortexA8
+        
+;// Declare input registers
+pSrc            RN 0
+pDst            RN 1
+
+;// Declare other intermediate registers
+Result          RN 0
+
+;// Prototype for macro M_IDCT
+;// pSrc            RN 0  ;// source data buffer
+;// Stride          RN 1  ;// destination stride in bytes
+;// pDest           RN 2  ;// destination data buffer
+;// pScale          RN 3  ;// pointer to scaling table
+
+pSrc    RN 0    
+Stride  RN 1    
+pDest   RN 2    
+pScale  RN 3    
+                
+        MOV         pDest, pDst
+        LDR         pScale, =armCOMM_IDCTPreScale        
+        M_IDCT      s9, s16, 16      
+        MOV         Result, #OMX_Sts_NoErr
+        M_END       
+    ENDIF  
+        ;// ARM1136JS :LOR: CortexA8
+
+    END
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/omxVCM4P2_MCReconBlock_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/omxVCM4P2_MCReconBlock_s.s
new file mode 100644
index 0000000..20965bf
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/omxVCM4P2_MCReconBlock_s.s
@@ -0,0 +1,713 @@
+;//
+;// 
+;// File Name:  omxVCM4P2_MCReconBlock_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   9641
+;// Date:       Thursday, February 7, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+;// Description:
+;//
+;//
+
+;// Include standard headers
+    INCLUDE omxtypes_s.h
+    INCLUDE armCOMM_s.h
+
+;// Import symbols required from other files
+
+    M_VARIANTS ARM1136JS
+
+;// ***************************************************************************
+;// ARM1136JS implementation
+;// ***************************************************************************
+    IF  ARM1136JS
+    
+;// ***************************************************************************
+;// MACRO DEFINITIONS
+;// ***************************************************************************
+    ;// Description:
+    ;//
+    ;//   dest[j] = (x[j] + y[j] + round) >> 1,   j=0..3
+    ;//
+    ;// Similar to UHADD8 instruction, but with a rounding value of 1 added to
+    ;// each sum before dividing by two, if round is 1
+    ;//
+    ;// Syntax:
+    ;// M_UHADD8R   $dest, $x, $y, $round, $mask
+    ;//
+    ;// Inputs:
+    ;// $x        four packed bytes,   x[3] :  x[2]  :  x[1]  :  x[0]
+    ;// $y        four packed bytes,   y[3] :  y[2]  :  y[1]  :  y[0]
+    ;// $round    0 if no rounding to be added, 1 if rounding to be done
+    ;// $mask     some register set to 0x80808080
+    ;//
+    ;// Outputs:
+    ;// $dest     four packed bytes,   z[3] :  z[2]  :  z[1]  :  z[0]
+
+    MACRO
+    M_UHADD8R   $dest, $x, $y, $round, $mask
+    IF $round = 1
+        IF  $dest /= $y
+            MVN         $dest, $x
+            UHSUB8      $dest, $y, $dest
+            EOR         $dest, $dest, $mask
+        ELSE
+            MVN         $dest, $y
+            UHSUB8      $dest, $x, $dest
+            EOR         $dest, $dest, $mask
+        ENDIF
+    ELSE
+        UHADD8      $dest, $x, $y
+    ENDIF
+    MEND
+;// ***************************************************************************
+    ;// Description:
+    ;// Load 8 bytes from $pSrc (aligned or unaligned locations)
+    ;//
+    ;// Syntax:
+    ;// M_LOAD_X    $pSrc, $srcStep, $out0, $out1, $scratch, $offset
+    ;// 
+    ;// Inputs:
+    ;// $pSrc       4 byte aligned source pointer to an address just less than 
+    ;//             or equal to the data location
+    ;// $srcStep    The stride on source
+    ;// $scratch    A scratch register, used internally for temp calculations
+    ;// $offset     Difference of source data location to the source pointer
+    ;//             Use when $offset != 0 (unaligned load)
+    ;//
+    ;// Outputs:
+    ;// $pSrc       In case the macro accepts stride, it increments the pSrc by 
+    ;//             that value, else unchanged
+    ;// $out0       four packed bytes,   z[3] :  z[2]  :  z[1]  :  z[0]
+    ;// $out1       four packed bytes,   z[7] :  z[6]  :  z[5]  :  z[4]
+    ;//
+    ;// Note: {$out0, $out1, $scratch} should be registers with ascending
+    ;// register numbering. In case offset is 0, $scratch is not modified.
+
+    MACRO
+    M_LOAD_X    $pSrc, $srcStep, $out0, $out1, $scratch, $offset
+        IF $offset = 0
+            LDM         $pSrc, {$out0, $out1}
+            ADD         $pSrc, $pSrc, $srcStep
+        ELSE
+            LDM         $pSrc, {$out0, $out1, $scratch} 
+            ADD         $pSrc, $pSrc, $srcStep
+            
+            MOV         $out0, $out0, LSR #8 * $offset
+            ORR         $out0, $out0, $out1, LSL #(32 - 8 * ($offset))
+            MOV         $out1, $out1, LSR #8 * $offset
+            ORR         $out1, $out1, $scratch, LSL #(32 - 8 * ($offset))
+        ENDIF
+    MEND
+
+;// ***************************************************************************
+    ;// Description:
+    ;// Loads three words for X interpolation, update pointer to next row. For 
+    ;// X interpolation, given a truncated-4byteAligned source pointer, 
+    ;// invariably three continous words are required from there to get the
+    ;// nine bytes from the source pointer for filtering. 
+    ;//
+    ;// Syntax:
+    ;// M_LOAD_XINT $pSrc, $srcStep, $offset, $word0, $word1, $word2, $word3
+    ;// 
+    ;// Inputs:
+    ;// $pSrc       4 byte aligned source pointer to an address just less than 
+    ;//             or equal to the data location
+    ;//
+    ;// $srcStep    The stride on source
+    ;//
+    ;// $offset     Difference of source data location to the source pointer
+    ;//             Use when $offset != 0 (unaligned load)
+    ;//
+    ;// Outputs:
+    ;// $pSrc       Incremented by $srcStep
+    ;//
+    ;// $word0, $word1, $word2, $word3
+    ;//             Three of these are outputs based on the $offset parameter. 
+    ;//             The outputs are specifically generated to be processed by 
+    ;//             the M_EXT_XINT macro. Following is the illustration to show 
+    ;//             how the nine bytes are spanned for different offsets from 
+    ;//             notTruncatedForAlignmentSourcePointer.
+    ;//
+    ;//              ------------------------------------------------------
+    ;//             | Offset | Aligned Ptr | word0 | word1 | word2 | word3 |
+    ;//             |------------------------------------------------------|
+    ;//             |    0   |       0     | 0123  | 4567  | 8xxx  |       |
+    ;//             |    1   |      -1     | x012  | 3456  | 78xx  |       |
+    ;//             |    2   |      -2     | xx01  | 2345  | 678x  |       |
+    ;//             |    3   |      -3     | xxx0  |       | 1234  | 5678  |
+    ;//              ------------------------------------------------------
+    ;// 
+    ;//             where the numbering (0-8) is to designate the 9 bytes from
+    ;//             start of a particular row. The illustration doesn't take in 
+    ;//             account the positioning of bytes with in the word and the 
+    ;//             macro combination with M_EXT_XINT will work only in little 
+    ;//             endian environs
+    ;// 
+    ;// Note: {$word0, $word1, $word2, $word3} should be registers with ascending
+    ;// register numbering
+
+    MACRO
+    M_LOAD_XINT $pSrc, $srcStep, $offset, $word0, $word1, $word2, $word3
+        IF $offset /= 3
+            LDM         $pSrc, {$word0, $word1, $word2}
+        ELSE
+            LDM         $pSrc, {$word0, $word2, $word3}
+        ENDIF
+        ADD         $pSrc, $pSrc, $srcStep
+    MEND
+
+;// ***************************************************************************
+    ;// Description:
+    ;// Extract four registers of four pixels for X interpolation 
+    ;// 
+    ;// Syntax:
+    ;// M_EXT_XINT $offset, $word0, $word1, $word2, $word3
+    ;// 
+    ;// Inputs:
+    ;// $offset     Difference of source data location to the source pointer
+    ;//             Use when $offset != 0 (unaligned load)
+    ;// 
+    ;// $word0, $word1, $word2, $word3
+    ;//             Three of these are inputs based on the $offset parameter. 
+    ;//             The inputs are specifically selected to be processed by 
+    ;//             the M_EXT_XINT macro.
+    ;//
+    ;//              ------------------------------------------------------
+    ;//             | Offset | Aligned Ptr | word0 | word1 | word2 | word3 |
+    ;//             |------------------------------------------------------|
+    ;//             |    0   |       0     | 0123  | 4567  | 8xxx  | yyyy  |
+    ;//             |    1   |      -1     | x012  | 3456  | 78xx  | yyyy  |
+    ;//             |    2   |      -2     | xx01  | 2345  | 678x  | yyyy  |
+    ;//             |    3   |      -3     | xxx0  | yyyy  | 1234  | 5678  |
+    ;//              ------------------------------------------------------
+    ;// 
+    ;// Outputs:
+    ;// $word0, $word1, $word2, $word3
+    ;//             Bytes from the original source pointer (not truncated for
+    ;//             4 byte alignment) as shown in the table. 
+    ;//              -------------------------------
+    ;//             | word0 | word1 | word2 | word3 |
+    ;//             |-------------------------------|
+    ;//             | 0123  | 4567  | 1234  | 5678  |
+    ;//              -------------------------------
+    ;//
+    ;// Note: {$word0, $word1, $word2, $word3} should be registers with ascending
+    ;// register numbering
+
+    MACRO
+    M_EXT_XINT $offset, $word0, $word1, $word2, $word3
+        IF $offset = 0
+            ; $word0 and $word1 are ok
+            ; $word2, $word3 are just 8 shifted versions
+            MOV         $word3, $word1, LSR #8
+            ORR         $word3, $word3, $word2, LSL #24
+            MOV         $word2, $word0, LSR #8
+            ORR         $word2, $word2, $word1, LSL #24
+        ELIF $offset = 3
+            ; $word2 and $word3 are ok (taken care while loading itself)
+            ; set $word0 & $word1
+            MOV         $word0, $word0, LSR #24
+            ORR         $word0, $word0, $word2, LSL #8
+            MOV         $word1, $word2, LSR #24
+            ORR         $word1, $word1, $word3, LSL #8
+        ELSE
+            MOV         $word0, $word0, LSR #8 * $offset
+            ORR         $word0, $word0, $word1, LSL #(32 - 8 * ($offset))
+            MOV         $word1, $word1, LSR #8 * $offset
+            ORR         $word1, $word1, $word2, LSL #(32 - 8 * ($offset))
+
+            MOV         $word3, $word1, LSR #8
+            ORR         $word3, $word3, $word2, LSL #(32 - 8 * (($offset)+1))
+            MOV         $word2, $word0, LSR #8
+            ORR         $word2, $word2, $word1, LSL #24
+        ENDIF
+    MEND
+
+;// ***************************************************************************
+    ;// Description:
+    ;// Computes half-sum and xor of two inputs and puts them in the input 
+    ;// registers in that order
+    ;//
+    ;// Syntax:
+    ;// M_HSUM_XOR      $v0, $v1, $tmp
+    ;// 
+    ;// Inputs:
+    ;// $v0         a, first input
+    ;// $v1         b, second input
+    ;// $tmp        scratch register
+    ;// 
+    ;// Outputs:
+    ;// $v0         (a + b)/2
+    ;// $v1         a ^ b
+
+    MACRO
+    M_HSUM_XOR      $v0, $v1, $tmp
+        UHADD8      $tmp, $v0, $v1     ;// s0 = a + b
+        EOR         $v1, $v0, $v1      ;// l0 = a ^ b
+        MOV         $v0, $tmp          ;// s0
+    MEND
+;// ***************************************************************************
+    ;// Description:
+    ;// Calculates average of 4 values (a,b,c,d) for HalfPixelXY predict type in 
+    ;// mcReconBlock module. Very specific to the implementation of 
+    ;// M_MCRECONBLOCK_HalfPixelXY done here. Uses "tmp" as scratch register and 
+    ;// "yMask" for mask variable "0x1010101x" set in it. In yMask 4 lsbs are 
+    ;// not significant and are used by the callee for row counter (y)
+    ;//
+    ;// Some points to note are:
+    ;// 1. Input is pair of pair-averages and Xors
+    ;// 2. $sum1 and $lsb1 are not modified and hence can be reused in another 
+    ;//    running average
+    ;// 3. Output is in the first argument
+    ;//
+    ;// Syntax:
+    ;// M_AVG4         $sum0, $lsb0, $sum1, $lsb1, $rndVal
+    ;// 
+    ;// Inputs:
+    ;// $sum0       (a + b) >> 1, where a and b are 1st and 2nd inputs to be averaged
+    ;// $lsb0       (a ^ b)
+    ;// $sum1       (c + d) >> 1. Not modified
+    ;// $lsb1       (c ^ d)       Not modified
+    ;// $rndVal     Assembler Variable. 0 for rounding, 1 for no rounding
+    ;// 
+    ;// Outputs:
+    ;// $sum0       (a + b + c + d + 1) / 4 : If no rounding
+    ;//             (a + b + c + d + 2) / 4 : If rounding
+
+    MACRO
+    M_AVG4          $sum0, $lsb0, $sum1, $lsb1, $rndVal
+        LCLS OP1
+        LCLS OP2
+        IF $rndVal = 0 ;// rounding case
+OP1 SETS "AND"
+OP2 SETS "ORR"
+        ELSE           ;// Not rounding case
+OP1 SETS "ORR"
+OP2 SETS "AND"
+        ENDIF
+        
+        LCLS lsb2
+        LCLS sum2
+        LCLS dest
+    
+lsb2  SETS "tmp"
+sum2  SETS "$lsb0"
+dest  SETS "$sum0"
+
+        $OP1        $lsb0, $lsb0, $lsb1          ;// e0 = e0 & e1
+        EOR         $lsb2, $sum0, $sum1          ;// e2 = s0 ^ s1
+        $OP2        $lsb2, $lsb2, $lsb0          ;// e2 = e2 | e0
+        AND         $lsb2, $lsb2, yMask, LSR # 4 ;// e2 = e2 & mask
+        UHADD8      $sum2, $sum0, $sum1          ;// s2 = (s0 + s1)/2
+        UADD8       $dest, $sum2, $lsb2          ;// dest =  s2 + e2
+    MEND
+;// ***************************************************************************
+;// Motion compensation handler macros
+;// ***************************************************************************
+    ;// Description:
+    ;// Implement motion compensation routines using the named registers in 
+    ;// callee function. Each of the following 4 implement the 4 predict type
+    ;// Each handles 8 cases each ie all the combinations of 4 types of source 
+    ;// alignment offsets and 2 types of rounding flag
+    ;//
+    ;// Syntax:
+    ;// M_MCRECONBLOCK_IntegerPixel $rndVal, $offset
+    ;// M_MCRECONBLOCK_HalfPixelX   $rndVal, $offset
+    ;// M_MCRECONBLOCK_HalfPixelY   $rndVal, $offset
+    ;// M_MCRECONBLOCK_HalfPixelXY  $rndVal, $offset
+    ;// 
+    ;// Inputs:
+    ;// $rndVal     Assembler Variable. 0 for rounding, 1 for no rounding
+    ;// $offset     $pSrc MOD 4 value. Offset from 4 byte aligned location.
+    ;// 
+    ;// Outputs:
+    ;// Outputs come in the named registers of the callee functions
+    ;// The macro loads the data from the source pointer, processes it and 
+    ;// stores in the destination pointer. Does the whole prediction cycle
+    ;// of Motion Compensation routine for a particular predictType
+    ;// After this only residue addition to the predicted values remain
+
+    MACRO
+    M_MCRECONBLOCK_IntegerPixel $rndVal, $offset
+    ;// Algorithmic Description:
+    ;// This handles motion compensation for IntegerPixel predictType. Both
+    ;// rounding cases are handled by the same code base. It is just a copy
+    ;// from source to destination. Two lines are done per loop to reduce 
+    ;// stalls. Loop has been software pipelined as well for that purpose.
+    ;// 
+    ;// M_LOAD_X loads a whole row in two registers and then they are stored
+    
+CaseIntegerPixelRnd0Offset$offset
+CaseIntegerPixelRnd1Offset$offset
+    M_LOAD_X    pSrc, srcStep, tmp1, tmp2, tmp3, $offset
+    M_LOAD_X    pSrc, srcStep, tmp3, tmp4, tmp5, $offset
+YloopIntegerPixelOffset$offset
+    SUBS        y, y, #2
+    STRD        tmp1, tmp2, [pDst], dstStep
+    STRD        tmp3, tmp4, [pDst], dstStep
+    M_LOAD_X    pSrc, srcStep, tmp1, tmp2, tmp3, $offset
+    M_LOAD_X    pSrc, srcStep, tmp3, tmp4, tmp5, $offset
+    BGT         YloopIntegerPixelOffset$offset
+
+    B           SwitchPredictTypeEnd
+    MEND
+;// ***************************************************************************
+    MACRO
+    M_MCRECONBLOCK_HalfPixelX $rndVal, $offset
+    ;// Algorithmic Description:
+    ;// This handles motion compensation for HalfPixelX predictType. The two
+    ;// rounding cases are handled by the different code base and spanned by 
+    ;// different macro calls. Loop has been software pipelined to reduce 
+    ;// stalls.
+    ;// 
+    ;// Filtering involves averaging a pixel with the next horizontal pixel.
+    ;// M_LOAD_XINT and M_EXT_XINT combination generate 4 registers, 2 with 
+    ;// all pixels in a row with 4 pixel in each register and another 2
+    ;// registers with pixels corresponding to one horizontally shifted pixel
+    ;// corresponding to the initial row pixels. These are set of packed 
+    ;// registers appropriate to do 4 lane SIMD.
+    ;// After that M_UHADD8R macro does the averaging taking care of the 
+    ;// rounding as required
+    
+CaseHalfPixelXRnd$rndVal.Offset$offset
+    IF $rndVal = 0
+        LDR mask, =0x80808080
+    ENDIF
+
+    M_LOAD_XINT pSrc, srcStep, $offset, tmp1, tmp2, tmp3, tmp4
+YloopHalfPixelXRnd$rndVal.Offset$offset
+    SUBS        y, y, #1
+    M_EXT_XINT  $offset, tmp1, tmp2, tmp3, tmp4
+    M_UHADD8R   tmp5, tmp1, tmp3, (1-$rndVal), mask
+    M_UHADD8R   tmp6, tmp2, tmp4, (1-$rndVal), mask
+    STRD        tmp5, tmp6, [pDst], dstStep
+    M_LOAD_XINT pSrc, srcStep, $offset, tmp1, tmp2, tmp3, tmp4
+    BGT         YloopHalfPixelXRnd$rndVal.Offset$offset
+
+    B           SwitchPredictTypeEnd
+    MEND
+;// ***************************************************************************
+    MACRO
+    M_MCRECONBLOCK_HalfPixelY $rndVal, $offset
+    ;// Algorithmic Description:
+    ;// This handles motion compensation for HalfPixelY predictType. The two
+    ;// rounding cases are handled by the different code base and spanned by 
+    ;// different macro calls. PreLoading is used to avoid reload of same data. 
+    ;// 
+    ;// Filtering involves averaging a pixel with the next vertical pixel.
+    ;// M_LOAD_X generates 2 registers with all pixels in a row with 4 pixel in 
+    ;// each register. These are set of packed registers appropriate to do 
+    ;// 4 lane SIMD. After that M_UHADD8R macro does the averaging taking care 
+    ;// of the rounding as required
+    
+CaseHalfPixelYRnd$rndVal.Offset$offset
+    IF $rndVal = 0
+        LDR mask, =0x80808080
+    ENDIF
+
+    M_LOAD_X    pSrc, srcStep, tmp1, tmp2, tmp5, $offset ;// Pre-load
+YloopHalfPixelYRnd$rndVal.Offset$offset
+    SUBS        y, y, #2
+    ;// Processing one line
+    M_LOAD_X    pSrc, srcStep, tmp3, tmp4, tmp5, $offset
+    M_UHADD8R   tmp1, tmp1, tmp3, (1-$rndVal), mask
+    M_UHADD8R   tmp2, tmp2, tmp4, (1-$rndVal), mask
+    STRD        tmp1, tmp2, [pDst], dstStep
+    ;// Processing another line
+    M_LOAD_X    pSrc, srcStep, tmp1, tmp2, tmp5, $offset
+    M_UHADD8R   tmp3, tmp3, tmp1, (1-$rndVal), mask
+    M_UHADD8R   tmp4, tmp4, tmp2, (1-$rndVal), mask
+    STRD        tmp3, tmp4, [pDst], dstStep
+
+    BGT         YloopHalfPixelYRnd$rndVal.Offset$offset
+
+    B           SwitchPredictTypeEnd
+    MEND
+;// ***************************************************************************
+    MACRO
+    M_MCRECONBLOCK_HalfPixelXY $rndVal, $offset
+    ;// Algorithmic Description:
+    ;// This handles motion compensation for HalfPixelXY predictType. The two
+    ;// rounding cases are handled by the different code base and spanned by 
+    ;// different macro calls. PreLoading is used to avoid reload of same data. 
+    ;// 
+    ;// Filtering involves averaging a pixel with the next vertical, horizontal 
+    ;// and right-down diagonal pixels. Just as in HalfPixelX case, M_LOAD_XINT
+    ;// and M_EXT_XINT combination generates 4 registers with a row and its
+    ;// 1 pixel right shifted version, with 4 pixels in one register. Another 
+    ;// call of that macro-combination gets another row. Then M_HSUM_XOR is 
+    ;// called to get mutual half-sum and xor combinations of a row with its
+    ;// shifted version as they are inputs to the M_AVG4 macro which computes
+    ;// the 4 element average with rounding. Note that it is the half-sum/xor 
+    ;// values that are preserved for next row as they can be re-used in the 
+    ;// next call to the M_AVG4 and saves recomputation.
+    ;// Due to lack of register, the row counter and a masking value required 
+    ;// in M_AVG4 are packed into a single register yMask where the last nibble
+    ;// holds the row counter values and rest holds the masking variable left 
+    ;// shifted by 4
+    
+CaseHalfPixelXYRnd$rndVal.Offset$offset
+    LDR         yMask, =((0x01010101 << 4) + 8)
+
+    M_LOAD_XINT pSrc, srcStep, $offset, t00, t01, t10, t11 ;// Load a, a', b, b'
+    M_EXT_XINT  $offset, t00, t01, t10, t11
+    M_HSUM_XOR  t00, t10, tmp               ;// s0, l0
+    M_HSUM_XOR  t01, t11, tmp               ;// s0', l0'
+
+YloopHalfPixelXYRnd$rndVal.Offset$offset
+    ;// Processsing one line
+    ;// t00, t01, t10, t11 required from previous loop
+    M_LOAD_XINT pSrc, srcStep, $offset, t20, t21, t30, t31 ;// Load c, c', d, d'
+    SUB         yMask, yMask, #2
+    M_EXT_XINT  $offset, t20, t21, t30, t31
+    M_HSUM_XOR  t20, t30, tmp               ;// s1, l1
+    M_HSUM_XOR  t21, t31, tmp               ;// s1', l1'
+    M_AVG4      t00, t10, t20, t30, $rndVal ;// s0, l0, s1, l1
+    M_AVG4      t01, t11, t21, t31, $rndVal ;// s0', l0', s1', l1'
+    STRD        t00, t01, [pDst], dstStep   ;// store the average
+    
+    ;// Processsing another line
+    ;// t20, t21, t30, t31 required from above
+    M_LOAD_XINT pSrc, srcStep, $offset, t00, t01, t10, t11 ;// Load a, a', b, b'
+    TST         yMask, #7
+    M_EXT_XINT  $offset, t00, t01, t10, t11
+    M_HSUM_XOR  t00, t10, tmp
+    M_HSUM_XOR  t01, t11, tmp
+    M_AVG4      t20, t30, t00, t10, $rndVal
+    M_AVG4      t21, t31, t01, t11, $rndVal
+    STRD        t20, t21, [pDst], dstStep
+
+    BGT         YloopHalfPixelXYRnd$rndVal.Offset$offset
+
+    IF $offset/=3 :LOR: $rndVal/=1
+        B           SwitchPredictTypeEnd
+    ENDIF
+    MEND
+;// ***************************************************************************
+;// Motion compensation handler macros end here
+;// ***************************************************************************
+    ;// Description:
+    ;// Populates all 4 kinds of offsets "cases" for each predictType and rndVal
+    ;// combination in the "switch" to prediction processing code segment
+    ;//
+    ;// Syntax:
+    ;// M_CASE_OFFSET $rnd, $predictType
+    ;// 
+    ;// Inputs:
+    ;// $rnd            0 for rounding, 1 for no rounding
+    ;// $predictType    The prediction mode
+    ;// 
+    ;// Outputs:
+    ;// Populated list of "M_CASE"s for the "M_SWITCH" macro
+
+    MACRO
+    M_CASE_OFFSET $rnd, $predictType
+        M_CASE      Case$predictType.Rnd$rnd.Offset0
+        M_CASE      Case$predictType.Rnd$rnd.Offset1
+        M_CASE      Case$predictType.Rnd$rnd.Offset2
+        M_CASE      Case$predictType.Rnd$rnd.Offset3
+    MEND
+;// ***************************************************************************
+    ;// Description:
+    ;// Populates all 2 kinds of rounding "cases" for each predictType in the 
+    ;// "switch" to prediction processing code segment
+    ;//
+    ;// Syntax:
+    ;// M_CASE_OFFSET $predictType
+    ;// 
+    ;// Inputs:
+    ;// $predictType    The prediction mode
+    ;// 
+    ;// Outputs:
+    ;// Populated list of "M_CASE_OFFSET" macros
+
+    MACRO
+    M_CASE_MCRECONBLOCK $predictType
+        M_CASE_OFFSET  0, $predictType ;// 0 for rounding
+        M_CASE_OFFSET  1, $predictType ;// 1 for no rounding
+    MEND
+;// ***************************************************************************
+    ;// Description:
+    ;// Populates all 8 kinds of rounding and offset combinations handling macros 
+    ;// for the specified predictType. In case of "IntegerPixel" predictType, 
+    ;// rounding is not required so same code segment handles both cases
+    ;//
+    ;// Syntax:
+    ;// M_MCRECONBLOCK    $predictType
+    ;// 
+    ;// Inputs:
+    ;// $predictType    The prediction mode
+    ;// 
+    ;// Outputs:
+    ;// Populated list of "M_MCRECONBLOCK_<predictType>" macros for specified 
+    ;// predictType. Each 
+    ;//                 M_MCRECONBLOCK_<predictType> $rnd, $offset 
+    ;// is an code segment (starting with a label indicating the predictType, 
+    ;// rounding and offset combination)
+    ;// Four calls of this macro with the 4 prediction modes populate all the 32 
+    ;// handlers
+
+    MACRO
+    M_MCRECONBLOCK $predictType
+        M_MCRECONBLOCK_$predictType 0, 0
+        M_MCRECONBLOCK_$predictType 0, 1
+        M_MCRECONBLOCK_$predictType 0, 2
+        M_MCRECONBLOCK_$predictType 0, 3
+    IF "$predictType" /= "IntegerPixel" ;// If not IntegerPixel then rounding makes a difference
+        M_MCRECONBLOCK_$predictType 1, 0
+        M_MCRECONBLOCK_$predictType 1, 1
+        M_MCRECONBLOCK_$predictType 1, 2
+        M_MCRECONBLOCK_$predictType 1, 3
+    ENDIF
+    MEND
+;// ***************************************************************************
+;// Input/Output Registers
+pSrc                  RN 0
+srcStep               RN 1
+arg_pSrcResidue       RN 2
+pSrcResidue           RN 12
+pDst                  RN 3
+dstStep               RN 2
+predictType           RN 10
+rndVal                RN 11
+mask                  RN 11
+
+;// Local Scratch Registers
+zero                  RN 12
+y                     RN 14
+
+tmp1                  RN 4
+tmp2                  RN 5
+tmp3                  RN 6
+tmp4                  RN 7
+tmp5                  RN 8
+tmp6                  RN 9
+tmp7                  RN 10
+tmp8                  RN 11
+tmp9                  RN 12
+
+t00                   RN 4
+t01                   RN 5
+t10                   RN 6
+t11                   RN 7
+t20                   RN 8
+t21                   RN 9
+t30                   RN 10
+t31                   RN 11
+tmp                   RN 12
+
+yMask                 RN 14
+
+dst                   RN 1
+return                RN 0
+
+    ;// Allocate memory on stack
+    M_ALLOC4    Stk_pDst,           4
+    M_ALLOC4    Stk_pSrcResidue,    4
+    ;// Function header
+    M_START     omxVCM4P2_MCReconBlock, r11
+    ;// Define stack arguments
+    M_ARG       Arg_dstStep,        4
+    M_ARG       Arg_predictType,    4
+    M_ARG       Arg_rndVal,         4
+    ;// Save on stack
+    M_STR       pDst, Stk_pDst
+    M_STR       arg_pSrcResidue, Stk_pSrcResidue
+    ;// Load argument from the stack
+    M_LDR       dstStep, Arg_dstStep
+    M_LDR       predictType, Arg_predictType
+    M_LDR       rndVal, Arg_rndVal
+    
+    MOV         y, #8
+    
+    AND         tmp1, pSrc, #3
+    ORR         predictType, tmp1, predictType, LSL #3
+    ORR         predictType, predictType, rndVal, LSL #2
+    ;// Truncating source pointer to align to 4 byte location
+    BIC         pSrc, pSrc, #3
+
+    ;// Implementation takes care of all combinations of different 
+    ;// predictTypes, rounding cases and source pointer offsets to alignment 
+    ;// of 4 bytes in different code bases unless one of these parameter wasn't 
+    ;// making any difference to the implementation. Below M_CASE_MCRECONBLOCK
+    ;// macros branch into 8 M_CASE macros for all combinations of the 2 
+    ;// rounding cases and 4 offsets of the pSrc pointer to the 4 byte 
+    ;// alignment. 
+    M_SWITCH    predictType
+        M_CASE_MCRECONBLOCK IntegerPixel
+        M_CASE_MCRECONBLOCK HalfPixelX
+        M_CASE_MCRECONBLOCK HalfPixelY
+        M_CASE_MCRECONBLOCK HalfPixelXY
+    M_ENDSWITCH
+
+    ;// The M_MCRECONBLOCK macros populate the code bases by calling all 8 
+    ;// particular macros (4 in case of IntegerPixel as rounding makes no 
+    ;// difference there) to generate the code for all cases of rounding and 
+    ;// offsets. LTORG is used to segment the code as code size bloated beyond 
+    ;// 4KB.
+    M_MCRECONBLOCK IntegerPixel
+    M_MCRECONBLOCK HalfPixelX
+    LTORG
+    M_MCRECONBLOCK HalfPixelY
+    M_MCRECONBLOCK HalfPixelXY
+SwitchPredictTypeEnd
+
+    ;// Residue Addition
+    ;// This is done in 2 lane SIMD though loads are further optimized and
+    ;// 4 bytes are loaded in case of destination buffer. Algorithmic 
+    ;// details are in inlined comments
+    M_LDR       pSrcResidue, Stk_pSrcResidue
+    CMP         pSrcResidue, #0
+    BEQ         pSrcResidueConditionEnd
+pSrcResidueNotNull    
+    M_LDR       pDst, Stk_pDst
+    MOV         y, #8
+    SUB         dstStep, dstStep, #4
+Yloop_pSrcResidueNotNull
+    SUBS        y, y, #1
+    LDR         dst, [pDst]                ;// dst = [dcba]
+    LDMIA       pSrcResidue!, {tmp1, tmp2} ;// tmp1=[DC] tmp2=[BA]
+    PKHBT       tmp3, tmp1, tmp2, LSL #16  ;// Deltaval1 = [C A]
+    PKHTB       tmp4, tmp2, tmp1, ASR #16  ;// DeltaVal2 = [D B]
+    UXTB16      tmp1, dst                  ;// tmp1 = [0c0a]
+    UXTB16      tmp2, dst, ROR #8          ;// tmp2 = [0d0b]
+    QADD16      tmp1, tmp1, tmp3           ;// Add and saturate to 16 bits
+    QADD16      tmp2, tmp2, tmp4
+    USAT16      tmp1, #8, tmp1
+    USAT16      tmp2, #8, tmp2             ;// armClip(0, 255, tmp2)
+    ORR         tmp1, tmp1, tmp2, LSL #8   ;// tmp1 = [dcba]
+    STR         tmp1, [pDst], #4
+    
+    LDR         dst, [pDst]
+    LDMIA       pSrcResidue!, {tmp1, tmp2}
+    PKHBT       tmp3, tmp1, tmp2, LSL #16
+    PKHTB       tmp4, tmp2, tmp1, ASR #16
+    UXTB16      tmp1, dst
+    UXTB16      tmp2, dst, ROR #8
+    QADD16      tmp1, tmp1, tmp3
+    QADD16      tmp2, tmp2, tmp4
+    USAT16      tmp1, #8, tmp1
+    USAT16      tmp2, #8, tmp2
+    ORR         tmp1, tmp1, tmp2, LSL #8
+    STR         tmp1, [pDst], dstStep
+    
+    BGT         Yloop_pSrcResidueNotNull
+pSrcResidueConditionEnd
+
+    MOV         return, #OMX_Sts_NoErr
+
+    M_END
+    ENDIF ;// ARM1136JS
+
+;// ***************************************************************************
+;// CortexA8 implementation
+;// ***************************************************************************
+    END
+;// ***************************************************************************
+;// omxVCM4P2_MCReconBlock ends
+;// ***************************************************************************
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/omxVCM4P2_PredictReconCoefIntra_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/omxVCM4P2_PredictReconCoefIntra_s.s
new file mode 100644
index 0000000..213444a
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/omxVCM4P2_PredictReconCoefIntra_s.s
@@ -0,0 +1,283 @@
+; **********
+; * 
+; * File Name:  omxVCM4P2_PredictReconCoefIntra_s.s
+; * OpenMAX DL: v1.0.2
+; * Revision:   9641
+; * Date:       Thursday, February 7, 2008
+; * 
+; * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+; * 
+; * 
+; * 
+; * Description:
+; * Contains module for DC/AC coefficient prediction
+; *
+; * 
+; * Function: omxVCM4P2_PredictReconCoefIntra
+; *
+; * Description:
+; * Performs adaptive DC/AC coefficient prediction for an intra block. Prior
+; * to the function call, prediction direction (predDir) should be selected
+; * as specified in subclause 7.4.3.1 of ISO/IEC 14496-2.
+; *
+; * Remarks:
+; *
+; * Parameters:
+; * [in]  pSrcDst      pointer to the coefficient buffer which contains the 
+; *                    quantized coefficient residuals (PQF) of the current 
+; *                    block; must be aligned on a 4-byte boundary. The 
+; *                    output coefficients are saturated to the range 
+; *                    [-2048, 2047].
+; * [in]  pPredBufRow  pointer to the coefficient row buffer; must be aligned
+; *                    on a 4-byte boundary.
+; * [in]  pPredBufCol  pointer to the coefficient column buffer; must be 
+; *                    aligned on a 4-byte boundary.
+; * [in]  curQP        quantization parameter of the current block. curQP may 
+; *                    equal to predQP especially when the current block and 
+; *                    the predictor block are in the same macroblock.
+; * [in]  predQP       quantization parameter of the predictor block
+; * [in]  predDir      indicates the prediction direction which takes one
+; *                    of the following values:
+; *                    OMX_VIDEO_HORIZONTAL    predict horizontally
+; *                    OMX_VIDEO_VERTICAL        predict vertically
+; * [in]  ACPredFlag   a flag indicating if AC prediction should be
+; *                    performed. It is equal to ac_pred_flag in the bit
+; *                    stream syntax of MPEG-4
+; * [in]  videoComp    video component type (luminance, chrominance or
+; *                    alpha) of the current block
+; * [out] pSrcDst      pointer to the coefficient buffer which contains
+; *                    the quantized coefficients (QF) of the current
+; *                    block
+; * [out] pPredBufRow  pointer to the updated coefficient row buffer
+; * [out] pPredBufCol  pointer to the updated coefficient column buffer
+; * Return Value:
+; * OMX_Sts_NoErr - no error
+; * OMX_Sts_BadArgErr - Bad arguments 
+; * - At least one of the pointers is NULL: pSrcDst, pPredBufRow, or pPredBufCol.
+; * - At least one the following cases: curQP <= 0, predQP <= 0, curQP >31, 
+; *   predQP > 31, preDir exceeds [1,2].
+; * - At least one of the pointers pSrcDst, pPredBufRow, or pPredBufCol is not 
+; *   4-byte aligned.
+; *
+; *********
+     
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+        
+       M_VARIANTS ARM1136JS
+       
+             
+
+       IMPORT        armVCM4P2_Reciprocal_QP_S32
+       IMPORT        armVCM4P2_Reciprocal_QP_S16
+       IMPORT        armVCM4P2_DCScaler
+       
+
+
+        IF ARM1136JS
+
+
+;// Input Arguments
+
+pSrcDst          RN 0
+pPredBufRow      RN 1
+pPredBufCol      RN 2
+curQP            RN 3
+QP               RN 3
+predQP           RN 4
+predDir          RN 5
+ACPredFlag       RN 6
+videoComp        RN 7  
+
+;// Local Variables
+
+temp2            RN 5
+negCurQP         RN 7
+negdcScaler      RN 7
+tempPred         RN 8
+
+dcScaler         RN 4
+CoeffTable       RN 9
+absCoeffDC       RN 9
+temp3            RN 6
+absCoeffAC       RN 6
+
+shortVideoHeader RN 9
+predCoeffTable   RN 10
+Count            RN 10
+temp1            RN 12
+index            RN 12
+Rem              RN 14
+temp             RN 11
+Return           RN 0
+
+       
+
+       M_START   omxVCM4P2_PredictReconCoefIntra,r12
+       
+       ;// Assigning pointers to Input arguments on Stack
+    
+       M_ARG           predQPonStack,4  
+       M_ARG           predDironStack,4
+       M_ARG           ACPredFlagonStack,4
+       M_ARG           videoComponStack,4
+       
+       ;// DC Prediction
+
+       M_LDR           videoComp,videoComponStack                     ;// Load videoComp From Stack               
+       
+       M_LDR           predDir,predDironStack                         ;// Load Prediction direction
+       
+       ;// dcScaler Calculation
+
+       LDR             index, =armVCM4P2_DCScaler
+       ADD             index,index,videoComp,LSL #5
+       LDRB            dcScaler,[index,QP]
+           
+    
+calDCVal
+      
+       
+       LDR             predCoeffTable, =armVCM4P2_Reciprocal_QP_S16   ;// Loading the table with entries 32767/(1 to 63) 
+      
+       CMP             predDir,#2                                     ;// Check if the Prediction direction is vertical
+
+       ;// Caulucate temp pred by performing Division
+            
+       LDREQSH         absCoeffDC,[pPredBufRow]                       ;// If vetical load the coeff from Row Prediction Buffer
+       LDRNESH         absCoeffDC,[pPredBufCol]                       ;// If horizontal load the coeff from column Prediction Buffer
+       
+       RSB             negdcScaler,dcScaler,#0                        ;// negdcScaler=-dcScaler  
+       
+       MOV             temp1,absCoeffDC                               ;// temp1=prediction coeff
+       CMP             temp1,#0
+       RSBLT           absCoeffDC,temp1,#0                            ;//absCoeffDC=abs(temp1)
+       
+       ADD             temp,dcScaler,dcScaler
+       LDRH            temp,[predCoeffTable,temp]                     ;// Load value from coeff table for performing division using multiplication
+       
+       SMULBB          tempPred,temp,absCoeffDC                       ;// tempPred=pPredBufRow(Col)[0]*32767/dcScaler
+       ADD             temp3,dcScaler,#1
+       LSR             tempPred,tempPred,#15                          ;// tempPred=pPredBufRow(Col)[0]/dcScaler          
+       LSR             temp3,temp3,#1                                 ;// temp3=round(dcScaler/2)
+       
+       MLA             Rem,negdcScaler,tempPred,absCoeffDC            ;// Rem = pPredBufRow(Col)[0]-tempPred*dcScaler      
+       
+       
+       LDRH            temp,[pPredBufCol]
+       CMP             Rem,temp3                                      
+       ADDGE           tempPred,#1                                    ;// If Rem>=round(dcScaler/2);tempPred=tempPred+1
+       CMP             temp1,#0
+       RSBLT           tempPred,tempPred,#0                            ;/ if pPredBufRow(Col)[0]<0; tempPred=-tempPred
+             
+       
+       STRH            temp,[pPredBufRow,#-16]      
+
+       LDRH            temp,[pSrcDst]                                 ;// temp=pSrcDst[0]
+       M_LDR           ACPredFlag,ACPredFlagonStack
+       ADD             temp,temp,tempPred                             ;// temp=pSrcDst[0]+tempPred
+       SSAT16          temp,#12,temp                                  ;// clip temp to [-2048,2047]
+       
+       SMULBB          temp1,temp,dcScaler                            ;// temp1=clipped(pSrcDst[0])*dcScaler           
+       M_LDR           predQP,predQPonStack
+       STRH            temp,[pSrcDst]                                 
+       CMP             ACPredFlag,#1                                  ;// Check if the AC prediction flag is set or not
+       STRH            temp1,[pPredBufCol]                            ;// store temp1 to pPredBufCol
+ 
+       ;// AC Prediction
+
+              
+       BNE             Exit                                           ;// If not set Exit
+       
+       LDR             predCoeffTable, =armVCM4P2_Reciprocal_QP_S32   ;// Loading the table with entries 0x1ffff/(1 to 63)
+       MOV             temp1,#4
+       MUL             temp1,curQP,temp1
+       CMP             predDir,#2                                     ;// Check the Prediction direction
+       RSB             negCurQP,curQP,#0                                  
+       LDR             CoeffTable,[predCoeffTable,temp1]              ;// CoeffTable=0x1ffff/curQP
+       ADD             curQP,curQP,#1                                 ;// curQP=curQP+1
+       LSR             curQP,curQP,#1                                 ;// curQP=round(curQP/2)                
+       MOV             Count,#2                                       ;// Initializing the Loop Count
+       BNE             Horizontal                                     ;// If the Prediction direction is horizontal branch to Horizontal
+
+       
+
+loop1       
+       ;// Calculate tempPred
+       
+       LDRSH           absCoeffAC,[pPredBufRow,Count]                 ;// absCoeffAC=pPredBufRow[i], 1=<i<=7
+       MOV             temp1,absCoeffAC
+       CMP             temp1,#0                                       ;// compare pPredBufRow[i] with zero, 1=<i<=7
+       RSBLT           absCoeffAC,temp1,#0                            ;// absCoeffAC= abs(pPredBufRow[i])
+                                            
+       SMULBB          absCoeffAC,absCoeffAC,predQP                   ;// temp1=pPredBufRow[i]*predQP
+       MUL             tempPred,absCoeffAC,CoeffTable                 ;// tempPred=pPredBufRow[i]*predQP*0x1ffff/curQP
+       LSR             tempPred,tempPred,#17          
+             
+       MLA             Rem,negCurQP,tempPred,absCoeffAC               ;// Rem=abs(pPredBufRow[i])-tempPred*curQP
+       LDRH            temp,[pSrcDst,Count]                           ;// temp=pSrcDst[i],1<=i<8
+       
+       CMP             Rem,curQP
+       ADDGE           tempPred,#1                                    ;// if Rem>=round(curQP/2); tempPred=tempPred+1
+       CMP             temp1,#0
+       RSBLT           tempPred,tempPred,#0                           ;// if pPredBufRow[i]<0 ; tempPred=-tempPred
+              
+       ;// Update source and Row Prediction buffers
+       
+       ADD             temp,temp,tempPred                             ;// temp=tempPred+pSrcDst[i]
+       SSAT16          temp,#12,temp                                  ;// Clip temp to [-2048,2047]
+       STRH            temp,[pSrcDst,Count]
+       STRH            temp,[pPredBufRow,Count]                       ;// pPredBufRow[i]=temp
+       ADD             Count,Count,#2                                 ;// i=i+1
+       CMP             Count,#16                                      ;// compare if i=8
+       BLT             loop1
+       B               Exit                                           ;// Branch to exit
+
+Horizontal
+
+       MOV             Count,#16                                      ;// Initializing i=8
+
+loop2  
+     
+       LSR             temp2,Count,#3                                 ;// temp2=i>>3
+       
+       ;// Calculate tempPred
+       
+       LDRH            absCoeffAC,[pPredBufCol,temp2]                 ;// absCoefAC=pPredBufCol[i>>3]                       
+       MOV             temp1,absCoeffAC
+       CMP             temp1,#0                                       ;// compare pPredBufRow[i] with zero, 1=<i<=7
+       RSBLT           absCoeffAC,temp1,#0                            ;// absCoeffAC=abs(pPredBufCol[i>>3])
+                                      
+       SMULBB          absCoeffAC,absCoeffAC,predQP                   ;// temp1=pPredBufCol[i>>3]*predQP
+       MUL             tempPred,absCoeffAC,CoeffTable                 ;// tempPred=pPredBufCol[i>>3]*predQP*0x1ffff/curQP
+       LSR             tempPred,tempPred,#17                          ;// tempPred=pPredBufCol[i>>3]*predQP/curQP
+       
+       MLA             Rem,negCurQP,tempPred,absCoeffAC
+       LDRH            temp,[pSrcDst,Count]                           ;// temp=pSrcDst[i]
+       
+       CMP             Rem,curQP                                      ;// Compare Rem with round(curQP/2)
+       ADDGE           tempPred,#1                                    ;// tempPred=tempPred+1 if Rem>=round(curQP/2)
+       CMP             temp1,#0
+       RSBLT           tempPred,tempPred,#0                           ;// if pPredBufCol[i>>3 <0 tempPred=-tempPred
+       
+       ;// Update source and Row Prediction buffers
+       
+       ADD             temp,temp,tempPred                             ;// temp=pSrcDst[i]+tempPred
+       SSAT16          temp,#12,temp                                  ;// Clip temp to [-2048,2047]
+       STRH            temp,[pSrcDst,Count]                           ;// pSrcDst[0]= clipped value
+       STRH            temp,[pPredBufCol,temp2]                       ;// pPredBufCol[i>>3]=temp
+       ADD             Count,Count,#16                                ;// i=i+8
+       CMP             Count,#128                                     ;// compare i with 64
+       BLT             loop2
+
+             
+Exit
+  
+       MOV             Return,#OMX_Sts_NoErr 
+
+       M_END
+       ENDIF
+       END
+
+
+   
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/omxVCM4P2_QuantInvInter_I_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/omxVCM4P2_QuantInvInter_I_s.s
new file mode 100644
index 0000000..c9591cb
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/omxVCM4P2_QuantInvInter_I_s.s
@@ -0,0 +1,141 @@
+;/**
+; * 
+; * File Name:  omxVCM4P2_QuantInvInter_I_s.s
+; * OpenMAX DL: v1.0.2
+; * Revision:   9641
+; * Date:       Thursday, February 7, 2008
+; * 
+; * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+; * 
+; * 
+; *
+; * Description: 
+; * Contains modules for inter reconstruction
+; * 
+; *
+; *
+; *
+; *
+; * Function: omxVCM4P2_QuantInvInter_I
+; *
+; * Description:
+; * Performs inverse quantization on intra/inter coded block.
+; * This function supports bits_per_pixel = 8. Mismatch control
+; * is performed for the first MPEG-4 mode inverse quantization method.
+; * The output coefficients are clipped to the range: [-2048, 2047].
+; * Mismatch control is performed for the first inverse quantization method.
+; *
+; * Remarks:
+; *
+; * Parameters:
+; * [in] pSrcDst          pointer to the input (quantized) intra/inter block. Must be 16-byte aligned.
+; * [in] QP              quantization parameter (quantiser_scale)
+; * [in] videoComp      (Intra version only.) Video component type of the
+; *                  current block. Takes one of the following flags:
+; *                  OMX_VC_LUMINANCE, OMX_VC_CHROMINANCE,
+; *                  OMX_VC_ALPHA.
+; * [in] shortVideoHeader a flag indicating presence of short_video_header;
+; *                       shortVideoHeader==1 selects linear intra DC mode,
+; *                  and shortVideoHeader==0 selects nonlinear intra DC mode.
+; * [out]    pSrcDst      pointer to the output (dequantized) intra/inter block.  Must be 16-byte aligned.
+; *
+; * Return Value:
+; * OMX_Sts_NoErr - no error
+; * OMX_Sts_BadArgErr - bad arguments
+; *    - If pSrcDst is NULL or is not 16-byte aligned.
+; *      or
+; *    - If QP <= 0.
+; *      or
+; *    - videoComp is none of OMX_VC_LUMINANCE, OMX_VC_CHROMINANCE and OMX_VC_ALPHA.
+; *
+; */
+
+   INCLUDE omxtypes_s.h
+   INCLUDE armCOMM_s.h
+
+   M_VARIANTS ARM1136JS
+
+         
+
+     IF ARM1136JS
+
+;//Input Arguments
+pSrcDst            RN 0
+QP                 RN 1
+
+;//Local Variables
+Return             RN 0
+Count              RN 4      
+tempVal21          RN 2
+tempVal43          RN 3
+QP1                RN 5
+X2                 RN 6
+X3                 RN 14
+Result1            RN 8
+Result2            RN 9
+two                RN 7
+
+    M_START omxVCM4P2_QuantInvInter_I,r9
+       
+        MOV      Count,#64
+        TST      QP,#1
+        LDRD     tempVal21,[pSrcDst]      ;// Loads first two values of pSrcDst to tempVal21,
+                                          ;// next two values to tempVal43
+        SUBEQ    QP1,QP,#1                ;// QP1=QP if QP is odd , QP1=QP-1 if QP is even
+        MOVNE    QP1,QP
+        MOV      two,#2
+        
+        
+
+Loop
+        
+        
+        SMULBB   X2,tempVal21,two         ;// X2= first val(lower 16 bits of tampVal21)*2
+        CMP      X2,#0
+        
+        RSBLT    X2,X2,#0                 ;// X2=absoluteval(first val)
+        SMLABBNE X2,QP,X2,QP1             ;// X2=2*absval(first val)*QP+QP if QP is odd 
+                                          ;// X2=2*absval(first val)*QP+QP-1 if QP is even 
+        SMULTB   X3,tempVal21,two         ;// X3= second val(top 16 bits of tampVal21)*2
+        RSBLT    X2,X2,#0
+        
+        CMP      X3,#0
+               
+        RSBLT    X3,X3,#0
+        SMLABBNE X3,QP,X3,QP1
+        
+        RSBLT    X3,X3,#0
+        PKHBT    Result1,X2,X3,LSL #16    ;// Result1[0-15]=X2[0-15],Result1[16-31]=X3[16-31]
+        SMULBB   X2,tempVal43,two         ;// X2= first val(lower 16 bits of tampVal43)*2
+        SSAT16   Result1,#12,Result1      ;// clip to range [-2048,2047]
+        CMP      X2,#0
+       
+        
+               
+        RSBLE    X2,X2,#0
+        SMLABBNE X2,QP,X2,QP1
+        SMULTB   X3,tempVal43,two         ;// X2= first val(top 16 bits of tampVal21)*2
+        RSBLT    X2,X2,#0
+        CMP      X3,#0
+        
+        LDRD     tempVal21,[pSrcDst,#8]   ;// Load next four Values to tempVal21,tempVal43
+                
+        RSBLT    X3,X3,#0
+        SMLABBNE X3,QP,X3,QP1
+        RSBLT    X3,X3,#0
+        PKHBT    Result2,X2,X3,LSL #16    ;// Result2[0-15]=X2[0-15],Result2[16-31]=X3[0-15]
+        SSAT16   Result2,#12,Result2      ;// clip to range [-2048,2047]
+        
+        SUBS     Count,Count,#4           ;// Decrement Count by 4 and continue if it has not reached 0         
+        STRD     Result1,[pSrcDst],#8     ;// Store Double words and increment the pointer to point the next store address
+        
+        
+               
+        BGT      Loop
+        
+        MOV      Return,#OMX_Sts_NoErr
+        
+        M_END
+        ENDIF        
+        END
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/omxVCM4P2_QuantInvIntra_I_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/omxVCM4P2_QuantInvIntra_I_s.s
new file mode 100644
index 0000000..6328e01
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/m4p2/src/omxVCM4P2_QuantInvIntra_I_s.s
@@ -0,0 +1,188 @@
+;/**
+; * 
+; * File Name:  omxVCM4P2_QuantInvIntra_I_s.s
+; * OpenMAX DL: v1.0.2
+; * Revision:   9641
+; * Date:       Thursday, February 7, 2008
+; * 
+; * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+; * 
+; * 
+; *
+; * Description: 
+; * Contains modules for inter reconstruction
+; * 
+; *
+; *
+; *
+; *
+; * 
+; * Function: omxVCM4P2_QuantInvIntra_I
+; *
+; * Description:
+; * Performs inverse quantization on intra/inter coded block.
+; * This function supports bits_per_pixel = 8. Mismatch control
+; * is performed for the first MPEG-4 mode inverse quantization method.
+; * The output coefficients are clipped to the range: [-2048, 2047].
+; * Mismatch control is performed for the first inverse quantization method.
+; *
+; * Remarks:
+; *
+; * Parameters:
+; * [in]    pSrcDst        pointer to the input (quantized) intra/inter block. Must be 16-byte aligned.
+; * [in]    QP            quantization parameter (quantiser_scale)
+; * [in]    videoComp          (Intra version only.) Video component type of the
+; *                    current block. Takes one of the following flags:
+; *                    OMX_VC_LUMINANCE, OMX_VC_CHROMINANCE,
+; *                    OMX_VC_ALPHA.
+; * [in]    shortVideoHeader  a flag indicating presence of short_video_header;
+; *                           shortVideoHeader==1 selects linear intra DC mode,
+; *                    and shortVideoHeader==0 selects nonlinear intra DC mode.
+; * [out]    pSrcDst        pointer to the output (dequantized) intra/inter block.  Must be 16-byte aligned.
+; *
+; * Return Value:
+; * OMX_Sts_NoErr - no error
+; * OMX_Sts_BadArgErr - bad arguments
+; *    -    If pSrcDst is NULL or is not 16-byte aligned.
+; *      or
+; *    - If QP <= 0.
+; *      or
+; *    - videoComp is none of OMX_VC_LUMINANCE, OMX_VC_CHROMINANCE and OMX_VC_ALPHA.
+; *
+ 
+
+   INCLUDE omxtypes_s.h
+   INCLUDE armCOMM_s.h
+   
+   M_VARIANTS ARM1136JS
+   
+   
+   IMPORT        armVCM4P2_DCScaler
+ 
+         
+
+     IF ARM1136JS
+
+;//Input Arguments
+pSrcDst            RN 0
+QP                 RN 1
+videoComp          RN 2
+shortVideoHeader   RN 3
+
+;//Local Variables
+Return             RN 0
+dcScaler           RN 4
+temp               RN 12
+index              RN 6
+      
+tempVal21          RN 4
+tempVal43          RN 5
+QP1                RN 6
+X2                 RN 7
+X3                 RN 14
+Result1            RN 8
+Result2            RN 9
+two                RN 10
+Count              RN 11
+
+
+
+   
+    M_START omxVCM4P2_QuantInvIntra_I,r11
+
+
+        
+        ;// Perform Inverse Quantization for DC coefficient
+
+        TEQ       shortVideoHeader,#0      ;// Test if short Video Header flag =0             
+        MOVNE     dcScaler,#8              ;// if shortVideoHeader is non zero dcScaler=8
+        BNE       calDCVal
+        LDR       index, =armVCM4P2_DCScaler
+      ADD       index,index,videoComp,LSL #5
+      LDRB      dcScaler,[index,QP]
+
+
+        ;//M_CalDCScalar  shortVideoHeader,videoComp, QP
+
+calDCVal
+
+        LDRH     temp,[pSrcDst]
+        SMULBB   temp,temp,dcScaler       ;// dcCoeff = dcScaler * Quantized DC coefficient(from memory)
+        SSAT     temp,#12,temp            ;// Saturating to 12 bits
+        
+
+        MOV      Count,#64
+        TST      QP,#1
+        LDRD     tempVal21,[pSrcDst]      ;// Loads first two values of pSrcDst to tempVal21,
+                                          ;// next two values to tempVal43
+        SUBEQ    QP1,QP,#1                ;// QP1=QP if QP is odd , QP1=QP-1 if QP is even
+        MOVNE    QP1,QP
+        MOV      two,#2
+
+
+                
+        
+
+Loop
+        
+        
+        SMULBB   X2,tempVal21,two         ;// X2= first val(lower 16 bits of tampVal21)*2
+        CMP      X2,#0
+        
+        RSBLT    X2,X2,#0                 ;// X2=absoluteval(first val)
+        SMLABBNE X2,QP,X2,QP1             ;// X2=2*absval(first val)*QP+QP if QP is odd 
+                                          ;// X2=2*absval(first val)*QP+QP-1 if QP is even 
+        SMULTB   X3,tempVal21,two         ;// X3= second val(top 16 bits of tampVal21)*2
+        RSBLT    X2,X2,#0
+        
+        CMP      X3,#0
+               
+        RSBLT    X3,X3,#0
+        SMLABBNE X3,QP,X3,QP1
+        
+        RSBLT    X3,X3,#0
+        PKHBT    Result1,X2,X3,LSL #16    ;// Result1[0-15]=X2[0-15],Result1[16-31]=X3[16-31]
+        SMULBB   X2,tempVal43,two         ;// X2= first val(lower 16 bits of tampVal43)*2
+        SSAT16   Result1,#12,Result1      ;// clip to range [-2048,2047]
+        CMP      X2,#0
+       
+        
+               
+        RSBLE    X2,X2,#0
+        SMLABBNE X2,QP,X2,QP1
+        SMULTB   X3,tempVal43,two         ;// X2= first val(top 16 bits of tampVal21)*2
+        RSBLT    X2,X2,#0
+        CMP      X3,#0
+        
+        LDRD     tempVal21,[pSrcDst,#8]   ;// Load next four Values to tempVal21,tempVal43
+                
+        RSBLT    X3,X3,#0
+        SMLABBNE X3,QP,X3,QP1
+        RSBLT    X3,X3,#0
+        PKHBT    Result2,X2,X3,LSL #16    ;// Result2[0-15]=X2[0-15],Result2[16-31]=X3[16-31]
+        SSAT16   Result2,#12,Result2      ;// clip to range [-2048,2047]
+        
+        SUBS     Count,Count,#4           ;// Decrement Count by 4 and continue if it has not reached 0         
+        STRD     Result1,[pSrcDst],#8     ;// Store Double words and increment the pointer to point the next store address
+        
+        
+               
+        BGT      Loop
+
+        SUB      pSrcDst,pSrcDst,#128
+        
+        ;// Storing the Inverse Quantized DC coefficient
+
+        STRH     temp,[pSrcDst],#2
+        
+  
+        
+        MOV      Return,#OMX_Sts_NoErr
+             
+        
+        
+        
+        M_END
+        ENDIF        
+        END
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/src/armVC_Version.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/src/armVC_Version.c
new file mode 100644
index 0000000..5d93681
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm11/vc/src/armVC_Version.c
@@ -0,0 +1,6 @@
+#include "omxtypes.h"
+#include "armCOMM_Version.h"
+
+#ifdef ARM_INCLUDE_VERSION_DESCRIPTIONS
+const char * const omxVC_VersionDescription = "ARM OpenMAX DL v" ARM_VERSION_STRING "   Rel=" OMX_ARM_RELEASE_TAG "   Arch=" OMX_ARM_BUILD_ARCHITECTURE "   Tools="  OMX_ARM_BUILD_TOOLCHAIN ;
+#endif /* ARM_INCLUDE_VERSION_DESCRIPTIONS */
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/ARM_DELIVERY.TXT b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/ARM_DELIVERY.TXT
new file mode 100755
index 0000000..cc2d70a
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/ARM_DELIVERY.TXT
@@ -0,0 +1,63 @@
+The contents of this transaction was created by Hedley Francis
+of ARM on 19-Feb-2008.
+
+It contains the ARM data versions listed below.
+
+This data, unless otherwise stated, is ARM Proprietary and access to it
+is subject to the agreements indicated below.
+
+If you experience problems with this data, please contact ARM support
+quoting transaction reference <97414>.
+
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+- OX002-SW-98010-r0p0-00bet1
+  Video codecs - optimised code
+  V7 code release for Hantro (Ver 1.0.2)
+  internal access
+
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+This transaction contains deliverables which are designated as being of
+beta release status (BET).
+
+Beta release status has a particular meaning to ARM of which the recipient
+must be aware. Beta is a pre-release status indicating that the deliverable
+so described is believed to robustly demonstrate specified behaviour, to be
+consistent across its included aspects and be ready for general deployment.
+But Beta also indicates that pre-release reliability trials are ongoing and
+that it is possible residual defects or errors in operation, consistency
+and documentation may still be encountered. The recipient should consider
+this position when using this Beta material supplied. ARM will normally
+attempt to provide fixes or a work-around for defects identified by the
+recipient, but the provision or timeliness of this support cannot be
+guaranteed. ARM shall not be responsible for direct or consequential
+damages as a result of encountering one or more of these residual defects.
+By accepting a Beta release, the recipient agrees to these constraints and
+to providing reasonable information to ARM to enable the replication of the
+defects identified by the recipient. The specific Beta version supplied
+will not be supported after release of a later or higher status version.
+It should be noted that Support for the Beta release of the deliverable
+will only be provided by ARM to a recipient who has a current support and
+maintenance contract for the deliverable.
+
+
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+In addition to the data versions listed above, this transaction contains
+two additional files at the top level.
+
+The first is this file, ARM_DELIVERY_97414.TXT, which is the delivery
+note.
+
+The second is ARM_MANIFEST_97414.TXT which contains a manifest of all the
+files included in this transaction, together with their checksums.
+
+The checksums provided are calculated using the RSA Data Security, Inc.
+MD5 Message-Digest Algorithm.
+
+The checksums can be used to verify the integrity of this data using the
+"md5sum" tool (which is part of the GNU "textutils" package) by running:
+
+  % md5sum --check ARM_MANIFEST_97414.TXT
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/ARM_MANIFEST.TXT b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/ARM_MANIFEST.TXT
new file mode 100755
index 0000000..8310f67
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/ARM_MANIFEST.TXT
@@ -0,0 +1,91 @@
+				  OX002-SW-98010-r0p0-00bet1/
+				  OX002-SW-98010-r0p0-00bet1/api/
+e049791cfab6060a08cbac7b3ad767d6  OX002-SW-98010-r0p0-00bet1/api/armCOMM_s.h
+ed798face25497b2703ede736d6d52b6  OX002-SW-98010-r0p0-00bet1/api/omxtypes_s.h
+4eebd63af087376811d6749f0646b864  OX002-SW-98010-r0p0-00bet1/api/armCOMM_BitDec_s.h
+43cf46c2cf2fe1f93c615b57bcbe4809  OX002-SW-98010-r0p0-00bet1/api/armCOMM.h
+8f248ceaac8f602e277a521b679dcbbe  OX002-SW-98010-r0p0-00bet1/api/armCOMM_IDCTTable.h
+8ac5fa80ea98e391f5730a375280b5bd  OX002-SW-98010-r0p0-00bet1/api/armCOMM_Version.h
+3a2f420ddf6a1b950470bd0f5ebd5c62  OX002-SW-98010-r0p0-00bet1/api/armCOMM_IDCT_s.h
+511c0bb534fe223599e2c84eff24c9ed  OX002-SW-98010-r0p0-00bet1/api/armCOMM_MaskTable.h
+8971932d56eed6b1ad1ba507f0bff5f0  OX002-SW-98010-r0p0-00bet1/api/armCOMM_Bitstream.h
+f87fedd9ca432fefa757008176864ef8  OX002-SW-98010-r0p0-00bet1/api/armOMX.h
+8e49899a428822c36ef9dd94e0e05f18  OX002-SW-98010-r0p0-00bet1/api/omxtypes.h
+323008b72e9f04099a8cb42e99a1face  OX002-SW-98010-r0p0-00bet1/build_vc.pl
+e72d96c0a415459748df9807f3dae72f  OX002-SW-98010-r0p0-00bet1/filelist_vc.txt
+				  OX002-SW-98010-r0p0-00bet1/src/
+5eeae659a29477f5c52296d24afffd3c  OX002-SW-98010-r0p0-00bet1/src/armCOMM_IDCTTable.c
+d64cdcf38f7749dc7f77465e5b7d356d  OX002-SW-98010-r0p0-00bet1/src/armCOMM_MaskTable.c
+				  OX002-SW-98010-r0p0-00bet1/vc/
+				  OX002-SW-98010-r0p0-00bet1/vc/m4p10/
+				  OX002-SW-98010-r0p0-00bet1/vc/m4p10/src/
+e7e0c320978564a7c9b2c723749a98d6  OX002-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_CAVLCTables.c
+4adcd0df081990bdfc4729041a2a9152  OX002-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_InterpolateChroma.c
+852e0404142965dc1f3aa7f00ee5127b  OX002-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_UnpackBlock4x4_s.s
+7054151c5bfea6b5e74feee86b2d7b01  OX002-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_DecodeCoeffsToPairCAVLC.c
+5f7213a4f37627b3c58f6294ba477e30  OX002-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_DequantTables_s.s
+32ff4b8be62e2f0f3e764b83c1e5e2fd  OX002-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_DeblockChroma_I.c
+d066e3c81d82616f37ec1810ea49e7b7  OX002-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_DeblockingLuma_unsafe_s.s
+fe629a3e9d55395a6098bdf2431b5f02  OX002-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_DeblockingChroma_unsafe_s.s
+5b13fb954b7679de20076bb6a7f4ee1d  OX002-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_InterpolateLuma_s.s
+01ba60eff66ea49a4f833ce6279f8e2f  OX002-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_DeblockLuma_I.c
+fa1072cf1d17e9666c9f1e215fa302b1  OX002-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe_s.s
+db387b9e66d32787f47ef9cf0347da2a  OX002-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_InterpolateLuma_HalfDiagVerHor4x4_unsafe_s.s
+ea537e4e2ad03a1940981055fa3ace01  OX002-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe_s.s
+29a4283885b9473a3550a81eff2559d2  OX002-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_TransformDequantChromaDCFromPair_s.s
+2ddcaf60a8ea1e6e6b77737f768bfb9d  OX002-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_QuantTables_s.s
+c3002aad5600f872b70a5d7fe3915846  OX002-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_InterpolateLuma_Align_unsafe_s.s
+a2900f2c47f1c61d20bd6c1eda33d6d4  OX002-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_InterpolateLuma_Copy_unsafe_s.s
+c921df73397a32c947dc996ba6858553  OX002-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_PredictIntra_4x4_s.s
+3769e14f2fc3f514d025fe6ab73ff67a  OX002-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_TransformDequantLumaDCFromPair_s.s
+c029d1cebea0a09e1d235a37e2155002  OX002-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_FilterDeblockingChroma_HorEdge_I_s.s
+076a033f8161750a685756f9f51f04c9  OX002-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_InterpolateLuma_HalfDiagHorVer4x4_unsafe_s.s
+c5b5d22842822e6e5e31094882cbeb46  OX002-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_PredictIntra_16x16_s.s
+f6bdf6d914a4a1479f524951a3409846  OX002-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_FilterDeblockingChroma_VerEdge_I_s.s
+ebeb0713a9b2ea25986360ef262138c4  OX002-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_FilterDeblockingLuma_HorEdge_I_s.s
+78ed9ea200faa7be665445a713859af1  OX002-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_FilterDeblockingLuma_VerEdge_I_s.s
+c2d995f787b6f44ef10c751c12d1935f  OX002-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_InterpolateLuma_DiagCopy_unsafe_s.s
+40bed679a9f6e0d3efe216b7d4a9cf45  OX002-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_PredictIntraChroma_8x8_s.s
+4a52b3e9e268b8a8f07829bf500d03af  OX002-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_DecodeCoeffsToPair_s.s
+11249f8a98c5d4b84cb5575b0e37ca9c  OX002-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_Average_4x_Align_unsafe_s.s
+2513b60559ba71ae495c6053fb779fa9  OX002-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_Interpolate_Chroma_s.s
+2fb1ee17c36e3c1469c170f6dac11bf1  OX002-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_TransformResidual4x4_s.s
+cc4a6f32db0b72a91d3f278f6855df69  OX002-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_DecodeChromaDcCoeffsToPairCAVLC.c
+				  OX002-SW-98010-r0p0-00bet1/vc/m4p10/api/
+6e530ddaa7c2b57ffe88162c020cb662  OX002-SW-98010-r0p0-00bet1/vc/m4p10/api/armVCM4P10_CAVLCTables.h
+				  OX002-SW-98010-r0p0-00bet1/vc/m4p2/
+				  OX002-SW-98010-r0p0-00bet1/vc/m4p2/src/
+bec6de348b113438498867b869001622  OX002-SW-98010-r0p0-00bet1/vc/m4p2/src/armVCM4P2_Clip8_s.s
+dba9824e959b21d401cac925e68a11a6  OX002-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_Inter_s.s
+dfa7e5b58027be3542dda0593b77b2d3  OX002-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_QuantInvIntra_I_s.s
+4fba4c431a783a78a2eb6497a94ac967  OX002-SW-98010-r0p0-00bet1/vc/m4p2/src/armVCM4P2_Zigzag_Tables.c
+39991961179ca03b6381b6e653b1f14b  OX002-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_MCReconBlock_s.s
+1b0b2990c2669dfb87cf6b810611c01b  OX002-SW-98010-r0p0-00bet1/vc/m4p2/src/armVCM4P2_Huff_Tables_VLC.c
+1c9b87abf3283e957816b3937c680701  OX002-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_DecodePadMV_PVOP_s.s
+4fe1afca659a9055fc1172e58f78a506  OX002-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_DecodeBlockCoef_Intra.c
+2ea067f0436f91ba1351edaf411cb4ea  OX002-SW-98010-r0p0-00bet1/vc/m4p2/src/armVCM4P2_Lookup_Tables.c
+6ce363aadc9d65c308b40cca8902e4f6  OX002-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_IDCT8x8blk_s.s
+bf212f786772aed2bc705d22ff4e74f5  OX002-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_FindMVpred_s.s
+293a48a648a3085456e6665bb7366fad  OX002-SW-98010-r0p0-00bet1/vc/m4p2/src/armVCM4P2_SetPredDir_s.s
+2bb47ed9c9e25c5709c6d9b4ad39a38a  OX002-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_QuantInvInter_I_s.s
+437dfa204508850d61d4b87091446e9f  OX002-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_IntraACVLC_s.s
+bc9778898dd41101dc0fb0139eaf83cc  OX002-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_IntraDCVLC_s.s
+fc191eeae43f8ce735dbd311cc7bcb8d  OX002-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_PredictReconCoefIntra_s.s
+a0d85f4f517c945a4c9317ac021f2d08  OX002-SW-98010-r0p0-00bet1/vc/m4p2/src/armVCM4P2_DecodeVLCZigzag_AC_unsafe_s.s
+386020dee8b725c7fe2526f1fc211d7d  OX002-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_DecodeBlockCoef_Inter.c
+				  OX002-SW-98010-r0p0-00bet1/vc/m4p2/api/
+4624e7c838e10a249abcc3d3f4f40748  OX002-SW-98010-r0p0-00bet1/vc/m4p2/api/armVCM4P2_Huff_Tables_VLC.h
+65e1057d04e2cb844559dc9f6e09795a  OX002-SW-98010-r0p0-00bet1/vc/m4p2/api/armVCM4P2_ZigZag_Tables.h
+				  OX002-SW-98010-r0p0-00bet1/vc/src/
+e627b3346b0dc9aff14446005ce0fa43  OX002-SW-98010-r0p0-00bet1/vc/src/armVC_Version.c
+				  OX002-SW-98010-r0p0-00bet1/vc/api/
+7ca94b1c33ac0211e17d38baadd7d1dd  OX002-SW-98010-r0p0-00bet1/vc/api/armVC.h
+12cf7596edbbf6048b626d15e8d0ed48  OX002-SW-98010-r0p0-00bet1/vc/api/omxVC.h
+11726e286a81257cb45f5547fb4d374c  OX002-SW-98010-r0p0-00bet1/vc/api/omxVC_s.h
+a5b2af605c319cd2491319e430741377  OX002-SW-98010-r0p0-00bet1/vc/api/armVCCOMM_s.h
+				  OX002-SW-98010-r0p0-00bet1/vc/comm/
+				  OX002-SW-98010-r0p0-00bet1/vc/comm/src/
+1f81187b48487a8ea6dbc327648e3e4f  OX002-SW-98010-r0p0-00bet1/vc/comm/src/omxVCCOMM_Copy16x16_s.s
+936d3f2038a6f8613ec25e50cc601fe8  OX002-SW-98010-r0p0-00bet1/vc/comm/src/omxVCCOMM_Copy8x8_s.s
+8f6708a249130962e0bc5c044ac6dd93  OX002-SW-98010-r0p0-00bet1/vc/comm/src/omxVCCOMM_ExpandFrame_I_s.s
+aab7713414428e95de0ba799a2679b36  ARM_DELIVERY_97414.TXT
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armCOMM.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armCOMM.h
new file mode 100755
index 0000000..64c1958
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armCOMM.h
@@ -0,0 +1,785 @@
+/**
+ * 
+ * File Name:  armCOMM.h
+ * OpenMAX DL: v1.0.2
+ * Revision:   12290
+ * Date:       Wednesday, April 9, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *   
+ * File: armCOMM.h
+ * Brief: Declares Common APIs/Data Types used across OpenMAX API's
+ *
+ */
+ 
+  
+#ifndef _armCommon_H_
+#define _armCommon_H_
+
+#include "omxtypes.h"
+
+typedef struct
+{
+  OMX_F32 Re; /** Real part */
+  OMX_F32 Im; /** Imaginary part */	
+        
+} OMX_FC32; /** single precision floating point complex number */
+
+typedef struct
+{
+  OMX_F64 Re; /** Real part */
+  OMX_F64 Im; /** Imaginary part */	
+        
+} OMX_FC64; /** double precision floating point complex number */
+
+
+/* Used by both IP and IC domains for 8x8 JPEG blocks. */
+typedef OMX_S16 ARM_BLOCK8x8[64];
+
+
+#include "armOMX.h"
+
+#define  armPI (OMX_F64)(3.1415926535897932384626433832795)
+
+/***********************************************************************/
+
+/* Compiler extensions */
+#ifdef ARM_DEBUG
+/* debug version */
+#include <stdlib.h>
+#include <assert.h>
+#include <stdio.h>
+#define armError(str) {printf((str)); printf("\n"); exit(-1);}
+#define armWarn(str) {printf((str)); printf("\n");}
+#define armIgnore(a) ((void)a)
+#define armAssert(a) assert(a)
+#else 
+/* release version */
+#define armError(str) ((void) (str))
+#define armWarn(str)  ((void) (str))
+#define armIgnore(a)  ((void) (a))
+#define armAssert(a)  ((void) (a))
+#endif /* ARM_DEBUG */
+
+/* Arithmetic operations */
+
+#define armMin(a,b)             ( (a) > (b) ?  (b):(a) )
+#define armMax(a,b)             ( (a) > (b) ?  (a):(b) )
+#define armAbs(a)               ( (a) <  0  ? -(a):(a) )
+
+/* Alignment operation */
+
+#define armAlignToBytes(Ptr,N)      (Ptr + ( ((N-(int)Ptr)&(N-1)) / sizeof(*Ptr) ))
+#define armAlignTo2Bytes(Ptr)       armAlignToBytes(Ptr,2)
+#define armAlignTo4Bytes(Ptr)       armAlignToBytes(Ptr,4)
+#define armAlignTo8Bytes(Ptr)       armAlignToBytes(Ptr,8)
+#define armAlignTo16Bytes(Ptr)      armAlignToBytes(Ptr,16)
+
+/* Error and Alignment check */
+
+#define armRetArgErrIf(condition, code)  if(condition) { return (code); }
+#define armRetDataErrIf(condition, code) if(condition) { return (code); }
+
+#ifndef ALIGNMENT_DOESNT_MATTER
+#define armIsByteAligned(Ptr,N)     ((((int)(Ptr)) % N)==0)
+#define armNotByteAligned(Ptr,N)    ((((int)(Ptr)) % N)!=0)
+#else
+#define armIsByteAligned(Ptr,N)     (1)
+#define armNotByteAligned(Ptr,N)    (0)
+#endif
+
+#define armIs2ByteAligned(Ptr)      armIsByteAligned(Ptr,2)
+#define armIs4ByteAligned(Ptr)      armIsByteAligned(Ptr,4)
+#define armIs8ByteAligned(Ptr)      armIsByteAligned(Ptr,8)
+#define armIs16ByteAligned(Ptr)     armIsByteAligned(Ptr,16)
+
+#define armNot2ByteAligned(Ptr)     armNotByteAligned(Ptr,2)
+#define armNot4ByteAligned(Ptr)     armNotByteAligned(Ptr,4)
+#define armNot8ByteAligned(Ptr)     armNotByteAligned(Ptr,8)
+#define armNot16ByteAligned(Ptr)    armNotByteAligned(Ptr,16)
+#define armNot32ByteAligned(Ptr)    armNotByteAligned(Ptr,32)
+
+/**
+ * Function: armRoundFloatToS16_ref/armRoundFloatToS32_ref/armRoundFloatToS64
+ *
+ * Description:
+ * Converts a double precision value into a short int/int after rounding
+ *
+ * Parameters:
+ * [in]  Value                 Float value to be converted
+ *
+ * Return Value:
+ * [out] converted value in OMX_S16/OMX_S32 format
+ *
+ */
+
+OMX_S16 armRoundFloatToS16 (OMX_F64 Value);
+OMX_S32 armRoundFloatToS32 (OMX_F64 Value);
+OMX_S64 armRoundFloatToS64 (OMX_F64 Value);
+
+/**
+ * Function: armSatRoundFloatToS16_ref/armSatRoundFloatToS32
+ *
+ * Description:
+ * Converts a double precision value into a short int/int after rounding and saturation
+ *
+ * Parameters:
+ * [in]  Value                 Float value to be converted
+ *
+ * Return Value:
+ * [out] converted value in OMX_S16/OMX_S32 format
+ *
+ */
+
+OMX_S16 armSatRoundFloatToS16 (OMX_F64 Value);
+OMX_S32 armSatRoundFloatToS32 (OMX_F64 Value);
+
+/**
+ * Function: armSatRoundFloatToU16_ref/armSatRoundFloatToU32
+ *
+ * Description:
+ * Converts a double precision value into a unsigned short int/int after rounding and saturation
+ *
+ * Parameters:
+ * [in]  Value                 Float value to be converted
+ *
+ * Return Value:
+ * [out] converted value in OMX_U16/OMX_U32 format
+ *
+ */
+
+OMX_U16 armSatRoundFloatToU16 (OMX_F64 Value);
+OMX_U32 armSatRoundFloatToU32 (OMX_F64 Value);
+
+/**
+ * Function: armSignCheck
+ *
+ * Description:
+ * Checks the sign of a variable:
+ * returns 1 if it is Positive
+ * returns 0 if it is 0
+ * returns -1 if it is Negative 
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	    var     Variable to be checked
+ *
+ * Return Value:
+ * OMX_INT --   returns 1 if it is Positive
+ *              returns 0 if it is 0
+ *              returns -1 if it is Negative 
+ */ 
+ 
+OMX_INT armSignCheck (OMX_S16 var);
+
+/**
+ * Function: armClip
+ *
+ * Description: Clips the input between MAX and MIN value
+ * 
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] Min     lower bound
+ * [in] Max     upper bound
+ * [in] src     variable to the clipped
+ *
+ * Return Value:
+ * OMX_S32 --   returns clipped value
+ */ 
+ 
+OMX_S32 armClip (
+        OMX_INT min,
+        OMX_INT max, 
+        OMX_S32 src
+        );
+
+/**
+ * Function: armClip_F32
+ *
+ * Description: Clips the input between MAX and MIN value
+ * 
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] Min     lower bound
+ * [in] Max     upper bound
+ * [in] src     variable to the clipped
+ *
+ * Return Value:
+ * OMX_F32 --   returns clipped value
+ */ 
+ 
+OMX_F32 armClip_F32 (
+        OMX_F32 min,
+        OMX_F32 max, 
+        OMX_F32 src
+        );
+
+/**
+ * Function: armShiftSat_F32
+ *
+ * Description: Divides a float value by 2^shift and 
+ * saturates it for unsigned value range for satBits.
+ * Second parameter is like "shifting" the corresponding 
+ * integer value. Takes care of rounding while clipping the final 
+ * value.
+ *
+ * Parameters:
+ * [in] v          Number to be operated upon
+ * [in] shift      Divides the input "v" by "2^shift"
+ * [in] satBits    Final range is [0, 2^satBits)
+ *
+ * Return Value:
+ * OMX_S32 --   returns "shifted" saturated value
+ */ 
+ 
+OMX_U32 armShiftSat_F32(
+        OMX_F32 v, 
+        OMX_INT shift, 
+        OMX_INT satBits
+        );
+
+/**
+ * Functions: armSwapElem
+ *
+ * Description:
+ * This function swaps two elements at the specified pointer locations.
+ * The size of each element could be anything as specified by <elemSize>
+ *
+ * Return Value:
+ * OMXResult -- Error status from the function
+ */
+OMXResult armSwapElem(OMX_U8 *pBuf1, OMX_U8 *pBuf2, OMX_INT elemSize);
+
+
+/**
+ * Function: armMedianOf3
+ *
+ * Description: Finds the median of three numbers
+ * 
+ * Remarks:
+ *
+ * Parameters:
+ * [in] fEntry     First entry
+ * [in] sEntry     second entry
+ * [in] tEntry     Third entry
+ *
+ * Return Value:
+ * OMX_S32 --   returns the median value
+ */ 
+ 
+OMX_S32 armMedianOf3 (
+    OMX_S32 fEntry,
+    OMX_S32 sEntry, 
+    OMX_S32 tEntry 
+    );
+
+/**
+ * Function: armLogSize
+ *
+ * Description: Finds the size of a positive value and returns the same
+ * 
+ * Remarks:
+ *
+ * Parameters:
+ * [in] value    Positive value
+ *
+ * Return Value:
+ * OMX_U8 --   returns the size of the positive value
+ */ 
+ 
+OMX_U8 armLogSize (
+    OMX_U16 value 
+    );    
+
+/***********************************************************************/
+                /* Saturating Arithmetic operations */
+
+/**
+ * Function :armSatAdd_S32()
+ *
+ * Description :
+ *   Returns the result of saturated addition of the two inputs Value1, Value2
+ *
+ * Parametrs:
+ * [in] Value1       First Operand
+ * [in] Value2       Second Operand
+ *
+ * Return:
+ * [out]             Result of operation
+ * 
+ *    
+ **/
+
+OMX_S32 armSatAdd_S32(
+                OMX_S32 Value1,
+                OMX_S32 Value2
+                );
+
+/**
+ * Function :armSatAdd_S64()
+ *
+ * Description :
+ *   Returns the result of saturated addition of the two inputs Value1, Value2
+ *
+ * Parametrs:
+ * [in] Value1       First Operand
+ * [in] Value2       Second Operand
+ *
+ * Return:
+ * [out]             Result of operation
+ * 
+ *    
+ **/
+
+OMX_S64 armSatAdd_S64(
+                OMX_S64 Value1,
+                OMX_S64 Value2
+                );
+
+/** Function :armSatSub_S32()
+ * 
+ * Description :
+ *     Returns the result of saturated substraction of the two inputs Value1, Value2
+ *
+ * Parametrs:
+ * [in] Value1       First Operand
+ * [in] Value2       Second Operand
+ *
+ * Return:
+ * [out]             Result of operation
+ * 
+ **/
+
+OMX_S32 armSatSub_S32(
+                    OMX_S32 Value1,
+                    OMX_S32 Value2
+                    );
+
+/**
+ * Function :armSatMac_S32()
+ *
+ * Description :
+ *     Returns the result of Multiplication of Value1 and Value2 and subesquent saturated
+ *     accumulation with Mac
+ *
+ * Parametrs:
+ * [in] Value1       First Operand
+ * [in] Value2       Second Operand
+ * [in] Mac          Accumulator
+ *
+ * Return:
+ * [out]             Result of operation
+ **/
+
+OMX_S32 armSatMac_S32(
+                    OMX_S32 Mac,
+                    OMX_S16 Value1,
+                    OMX_S16 Value2
+                    );
+
+/**
+ * Function :armSatMac_S16S32_S32
+ *
+ * Description :
+ *   Returns the result of saturated MAC operation of the three inputs delayElem, filTap , mac
+ *
+ *   mac = mac + Saturate_in_32Bits(delayElem * filTap)
+ *
+ * Parametrs:
+ * [in] delayElem    First 32 bit Operand
+ * [in] filTap       Second 16 bit Operand
+ * [in] mac          Result of MAC operation
+ *
+ * Return:
+ * [out]  mac        Result of operation
+ *    
+ **/
+ 
+OMX_S32 armSatMac_S16S32_S32(
+                        OMX_S32 mac, 
+                        OMX_S32 delayElem, 
+                        OMX_S16 filTap );
+
+/**
+ * Function :armSatRoundRightShift_S32_S16
+ *
+ * Description :
+ *   Returns the result of rounded right shift operation of input by the scalefactor
+ *
+ *   output = Saturate_in_16Bits( ( RightShift( (Round(input) , scaleFactor ) )
+ *
+ * Parametrs:
+ * [in] input       The input to be operated on
+ * [in] scaleFactor The shift number
+ *
+ * Return:
+ * [out]            Result of operation
+ *    
+ **/
+
+
+OMX_S16 armSatRoundRightShift_S32_S16(
+                        OMX_S32 input, 
+                        OMX_INT scaleFactor);
+
+/**
+ * Function :armSatRoundLeftShift_S32()
+ *
+ * Description :
+ *     Returns the result of saturating left-shift operation on input
+ *     Or rounded Right shift if the input Shift is negative.
+ *
+ * Parametrs:
+ * [in] Value        Operand
+ * [in] shift        Operand for shift operation
+ *
+ * Return:
+ * [out]             Result of operation
+ *    
+ **/
+ 
+OMX_S32 armSatRoundLeftShift_S32(
+                        OMX_S32 Value,
+                        OMX_INT shift
+                        );
+
+/**
+ * Function :armSatRoundLeftShift_S64()
+ *
+ * Description :
+ *     Returns the result of saturating left-shift operation on input
+ *     Or rounded Right shift if the input Shift is negative.
+ *
+ * Parametrs:
+ * [in] Value        Operand
+ * [in] shift        Operand for shift operation
+ *
+ * Return:
+ * [out]             Result of operation
+ *    
+ **/
+ 
+OMX_S64 armSatRoundLeftShift_S64(
+                        OMX_S64 Value,
+                        OMX_INT shift
+                        );
+
+/**
+ * Function :armSatMulS16S32_S32()
+ *
+ * Description :
+ *     Returns the result of a S16 data type multiplied with an S32 data type
+ *     in a S32 container
+ *
+ * Parametrs:
+ * [in] input1       Operand 1
+ * [in] input2       Operand 2
+ *
+ * Return:
+ * [out]             Result of operation
+ *    
+ **/
+
+
+OMX_S32 armSatMulS16S32_S32(
+                    OMX_S16 input1,
+                    OMX_S32 input2);
+
+/**
+ * Function :armSatMulS32S32_S32()
+ *
+ * Description :
+ *     Returns the result of a S32 data type multiplied with an S32 data type
+ *     in a S32 container
+ *
+ * Parametrs:
+ * [in] input1       Operand 1
+ * [in] input2       Operand 2
+ *
+ * Return:
+ * [out]             Result of operation
+ *    
+ **/
+
+OMX_S32 armSatMulS32S32_S32(
+                    OMX_S32 input1,
+                    OMX_S32 input2);
+
+
+/**
+ * Function :armIntDivAwayFromZero()
+ *
+ * Description : Integer division with rounding to the nearest integer. 
+ *               Half-integer values are rounded away from zero
+ *               unless otherwise specified. For example 3//2 is rounded 
+ *               to 2, and -3//2 is rounded to -2.
+ *
+ * Parametrs:
+ * [in] Num        Operand 1
+ * [in] Deno       Operand 2
+ *
+ * Return:
+ * [out]             Result of operation input1//input2
+ *    
+ **/
+
+OMX_S32 armIntDivAwayFromZero (OMX_S32 Num, OMX_S32 Deno);
+
+
+/***********************************************************************/
+/*
+ * Debugging macros
+ *
+ */
+
+
+/*
+ * Definition of output stream - change to stderr if necessary
+ */
+#define DEBUG_STREAM stdout
+
+/*
+ * Debug printf macros, one for each argument count.
+ * Add more if needed.
+ */
+#ifdef DEBUG_ON
+#include <stdio.h>
+
+#define DEBUG_PRINTF_0(a)                                               fprintf(DEBUG_STREAM, a)
+#define DEBUG_PRINTF_1(a, b)                                            fprintf(DEBUG_STREAM, a, b)
+#define DEBUG_PRINTF_2(a, b, c)                                         fprintf(DEBUG_STREAM, a, b, c)
+#define DEBUG_PRINTF_3(a, b, c, d)                                      fprintf(DEBUG_STREAM, a, b, c, d)
+#define DEBUG_PRINTF_4(a, b, c, d, e)                                   fprintf(DEBUG_STREAM, a, b, c, d, e)
+#define DEBUG_PRINTF_5(a, b, c, d, e, f)                                fprintf(DEBUG_STREAM, a, b, c, d, e, f)
+#define DEBUG_PRINTF_6(a, b, c, d, e, f, g)                             fprintf(DEBUG_STREAM, a, b, c, d, e, f, g)
+#define DEBUG_PRINTF_7(a, b, c, d, e, f, g, h)                          fprintf(DEBUG_STREAM, a, b, c, d, e, f, g, h)
+#define DEBUG_PRINTF_8(a, b, c, d, e, f, g, h, i)                       fprintf(DEBUG_STREAM, a, b, c, d, e, f, g, h, i)
+#define DEBUG_PRINTF_9(a, b, c, d, e, f, g, h, i, j)                    fprintf(DEBUG_STREAM, a, b, c, d, e, f, g, h, i, j)
+#define DEBUG_PRINTF_10(a, b, c, d, e, f, g, h, i, j, k)                fprintf(DEBUG_STREAM, a, b, c, d, e, f, g, h, i, j, k)
+#define DEBUG_PRINTF_11(a, b, c, d, e, f, g, h, i, j, k, l)             fprintf(DEBUG_STREAM, a, b, c, d, e, f, g, h, i, j, k, l)
+#define DEBUG_PRINTF_12(a, b, c, d, e, f, g, h, i, j, k, l, m)          fprintf(DEBUG_STREAM, a, b, c, d, e, f, g, h, i, j, k, l, m)
+#define DEBUG_PRINTF_13(a, b, c, d, e, f, g, h, i, j, k, l, m, n)       fprintf(DEBUG_STREAM, a, b, c, d, e, f, g, h, i, j, k, l, m, n)
+#define DEBUG_PRINTF_14(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)    fprintf(DEBUG_STREAM, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
+#else /* DEBUG_ON */
+#define DEBUG_PRINTF_0(a)                                  
+#define DEBUG_PRINTF_1(a, b)                               
+#define DEBUG_PRINTF_2(a, b, c)                            
+#define DEBUG_PRINTF_3(a, b, c, d)                         
+#define DEBUG_PRINTF_4(a, b, c, d, e)                      
+#define DEBUG_PRINTF_5(a, b, c, d, e, f)                   
+#define DEBUG_PRINTF_6(a, b, c, d, e, f, g)                
+#define DEBUG_PRINTF_7(a, b, c, d, e, f, g, h)             
+#define DEBUG_PRINTF_8(a, b, c, d, e, f, g, h, i)          
+#define DEBUG_PRINTF_9(a, b, c, d, e, f, g, h, i, j)       
+#define DEBUG_PRINTF_10(a, b, c, d, e, f, g, h, i, j, k)    
+#define DEBUG_PRINTF_11(a, b, c, d, e, f, g, h, i, j, k, l)             
+#define DEBUG_PRINTF_12(a, b, c, d, e, f, g, h, i, j, k, l, m)          
+#define DEBUG_PRINTF_13(a, b, c, d, e, f, g, h, i, j, k, l, m, n)      
+#define DEBUG_PRINTF_14(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)   
+#endif /* DEBUG_ON */
+
+
+/*
+ * Domain and sub domain definitions
+ *
+ * In order to turn on debug for an entire domain or sub-domain
+ * at compile time, one of the DEBUG_DOMAIN_* below may be defined,
+ * which will activate debug in all of the defines it contains.
+ */
+
+#ifdef DEBUG_DOMAIN_AC
+#define DEBUG_OMXACAAC_DECODECHANPAIRELT_MPEG4
+#define DEBUG_OMXACAAC_DECODECHANPAIRELT
+#define DEBUG_OMXACAAC_DECODEDATSTRELT
+#define DEBUG_OMXACAAC_DECODEFILLELT
+#define DEBUG_OMXACAAC_DECODEISSTEREO_S32
+#define DEBUG_OMXACAAC_DECODEMSPNS_S32
+#define DEBUG_OMXACAAC_DECODEMSSTEREO_S32_I
+#define DEBUG_OMXACAAC_DECODEPRGCFGELT
+#define DEBUG_OMXACAAC_DECODETNS_S32_I
+#define DEBUG_OMXACAAC_DEINTERLEAVESPECTRUM_S32
+#define DEBUG_OMXACAAC_ENCODETNS_S32_I
+#define DEBUG_OMXACAAC_LONGTERMPREDICT_S32
+#define DEBUG_OMXACAAC_LONGTERMRECONSTRUCT_S32
+#define DEBUG_OMXACAAC_MDCTFWD_S32
+#define DEBUG_OMXACAAC_MDCTINV_S32_S16
+#define DEBUG_OMXACAAC_NOISELESSDECODE
+#define DEBUG_OMXACAAC_QUANTINV_S32_I
+#define DEBUG_OMXACAAC_UNPACKADIFHEADER
+#define DEBUG_OMXACAAC_UNPACKADTSFRAMEHEADER
+#define DEBUG_OMXACMP3_HUFFMANDECODESFBMBP_S32
+#define DEBUG_OMXACMP3_HUFFMANDECODESFB_S32
+#define DEBUG_OMXACMP3_HUFFMANDECODE_S32
+#define DEBUG_OMXACMP3_MDCTINV_S32
+#define DEBUG_OMXACMP3_REQUANTIZESFB_S32_I
+#define DEBUG_OMXACMP3_REQUANTIZE_S32_I
+#define DEBUG_OMXACMP3_SYNTHPQMF_S32_S16
+#define DEBUG_OMXACMP3_UNPACKFRAMEHEADER
+#define DEBUG_OMXACMP3_UNPACKSCALEFACTORS_S8
+#define DEBUG_OMXACMP3_UNPACKSIDEINFO
+#endif /* DEBUG_DOMAIN_AC */
+
+
+#ifdef DEBUG_DOMAIN_VC
+#define DEBUG_OMXVCM4P10_AVERAGE_16X
+#define DEBUG_OMXVCM4P10_AVERAGE_4X
+#define DEBUG_OMXVCM4P10_AVERAGE_8X
+#define DEBUG_OMXVCM4P10_DEBLOCKCHROMA_U8_C1IR
+#define DEBUG_OMXVCM4P10_DEBLOCKLUMA_U8_C1IR
+#define DEBUG_OMXVCM4P10_DECODECHROMADCCOEFFSTOPAIRCAVLC_U8
+#define DEBUG_OMXVCM4P10_DECODECOEFFSTOPAIRCAVLC_U8
+#define DEBUG_OMXVCM4P10_DEQUANTTRANSFORMACFROMPAIR_U8_S16_C1_DLX
+#define DEBUG_OMXVCM4P10_EXPANDFRAME
+#define DEBUG_OMXVCM4P10_FILTERDEBLOCKINGCHROMA_HOREDGE_U8_C1IR
+#define DEBUG_OMXVCM4P10_FILTERDEBLOCKINGCHROMA_VEREDGE_U8_C1IR
+#define DEBUG_OMXVCM4P10_FILTERDEBLOCKINGLUMA_HOREDGE_U8_C1IR
+#define DEBUG_OMXVCM4P10_FILTERDEBLOCKINGLUMA_VEREDGE_U8_C1IR
+#define DEBUG_OMXVCM4P10_PREDICTINTRACHROMA8X8_U8_C1R
+#define DEBUG_OMXVCM4P10_PREDICTINTRA_16X16_U8_C1R
+#define DEBUG_OMXVCM4P10_PREDICTINTRA_4X4_U8_C1R
+#define DEBUG_OMXVCM4P10_SADQUAR_16X
+#define DEBUG_OMXVCM4P10_SADQUAR_4X
+#define DEBUG_OMXVCM4P10_SADQUAR_8X
+#define DEBUG_OMXVCM4P10_SAD_16X
+#define DEBUG_OMXVCM4P10_SAD_4X
+#define DEBUG_OMXVCM4P10_SAD_8X
+#define DEBUG_OMXVCM4P10_SATD_4X4
+#define DEBUG_OMXVCM4P10_TRANSFORMDEQUANTCHROMADCFROMPAIR_U8_S16_C1
+#define DEBUG_OMXVCM4P10_TRANSFORMDEQUANTLUMADCFROMPAIR_U8_S16_C1
+#define DEBUG_OMXVCM4P10_TRANSFORMQUANT_CHROMADC
+#define DEBUG_OMXVCM4P10_TRANSFORMQUANT_LUMADC
+#define DEBUG_OMXVCM4P2_BLOCKMATCH_HALF_16X16
+#define DEBUG_OMXVCM4P2_BLOCKMATCH_HALF_8X8
+#define DEBUG_OMXVCM4P2_BLOCKMATCH_INTEGER_16X16
+#define DEBUG_OMXVCM4P2_BLOCKMATCH_INTEGER_8X8
+#define DEBUG_OMXVCM4P2_COMPUTETEXTUREERRORBLOCK_SAD_U8_S16
+#define DEBUG_OMXVCM4P2_COMPUTETEXTUREERRORBLOCK_U8_S16
+#define DEBUG_OMXVCM4P2_DCT8X8BLKDLX
+#define DEBUG_OMXVCM4P2_DECODEBLOCKCOEF_INTER_S16
+#define DEBUG_OMXVCM4P2_DECODEPADMV_PVOP
+#define DEBUG_OMXVCM4P2_DECODEVLCZIGZAG_INTER_S16
+#define DEBUG_OMXVCM4P2_DECODEVLCZIGZAG_INTRAACVLC_S16
+#define DEBUG_OMXVCM4P2_DECODEVLCZIGZAG_INTRADCVLC_S16
+#define DEBUG_OMXVCM4P2_ENCODEMV_U8_S16
+#define DEBUG_OMXVCM4P2_ENCODEVLCZIGZAG_INTER_S16
+#define DEBUG_OMXVCM4P2_ENCODEVLCZIGZAG_INTRAACVLC_S16
+#define DEBUG_OMXVCM4P2_ENCODEVLCZIGZAG_INTRADCVLC_S16
+#define DEBUG_OMXVCM4P2_FINDMVPRED
+#define DEBUG_OMXVCM4P2_IDCT8X8BLKDLX
+#define DEBUG_OMXVCM4P2_LIMITMVTORECT
+#define DEBUG_OMXVCM4P2_MOTIONESTIMATIONMB
+#define DEBUG_OMXVCM4P2_PADMBGRAY_U8
+#define DEBUG_OMXVCM4P2_PADMBHORIZONTAL_U8
+#define DEBUG_OMXVCM4P2_PADMBVERTICAL_U8
+#define DEBUG_OMXVCM4P2_PADMV
+#define DEBUG_OMXVCM4P2_QUANTINTER_S16_I
+#define DEBUG_OMXVCM4P2_QUANTINTRA_S16_I
+#define DEBUG_OMXVCM4P2_QUANTINVINTER_S16_I
+#define DEBUG_OMXVCM4P2_QUANTINVINTRA_S16_I
+#define DEBUG_OMXVCM4P2_TRANSRECBLOCKCEOF_INTER
+#define DEBUG_OMXVCM4P2_TRANSRECBLOCKCEOF_INTRA
+#endif /* DEBUG_DOMAIN_VC */
+
+
+#ifdef DEBUG_DOMAIN_IC
+/* To be filled in */
+#endif /* DEBUG_DOMAIN_IC */
+
+
+#ifdef DEBUG_DOMAIN_SP
+#define DEBUG_OMXACSP_DOTPROD_S16
+#define DEBUG_OMXACSP_BLOCKEXP_S16
+#define DEBUG_OMXACSP_BLOCKEXP_S32
+#define DEBUG_OMXACSP_COPY_S16
+#define DEBUG_OMXACSP_DOTPROD_S16
+#define DEBUG_OMXACSP_DOTPROD_S16_SFS
+#define DEBUG_OMXACSP_FFTFWD_CTOC_SC16_SFS
+#define DEBUG_OMXACSP_FFTFWD_CTOC_SC32_SFS
+#define DEBUG_OMXACSP_FFTFWD_RTOCCS_S16S32_SFS
+#define DEBUG_OMXACSP_FFTFWD_RTOCCS_S32_SFS
+#define DEBUG_OMXACSP_FFTGETBUFSIZE_C_SC16
+#define DEBUG_OMXACSP_FFTGETBUFSIZE_C_SC32
+#define DEBUG_OMXACSP_FFTGETBUFSIZE_R_S16_S32
+#define DEBUG_OMXACSP_FFTGETBUFSIZE_R_S32
+#define DEBUG_OMXACSP_FFTINIT_C_SC16
+#define DEBUG_OMXACSP_FFTINIT_C_SC32
+#define DEBUG_OMXACSP_FFTINIT_R_S16_S32
+#define DEBUG_OMXACSP_FFTINIT_R_S32
+#define DEBUG_OMXACSP_FFTINV_CCSTOR_S32S16_SFS
+#define DEBUG_OMXACSP_FFTINV_CCSTOR_S32_SFS
+#define DEBUG_OMXACSP_FFTINV_CTOC_SC16_SFS
+#define DEBUG_OMXACSP_FFTINV_CTOC_SC32_SFS
+#define DEBUG_OMXACSP_FILTERMEDIAN_S32_I
+#define DEBUG_OMXACSP_FILTERMEDIAN_S32
+#define DEBUG_OMXACSP_FIRONE_DIRECT_S16_ISFS
+#define DEBUG_OMXACSP_FIRONE_DIRECT_S16_I
+#define DEBUG_OMXACSP_FIRONE_DIRECT_S16
+#define DEBUG_OMXACSP_FIRONE_DIRECT_S16_SFS
+#define DEBUG_OMXACSP_FIR_DIRECT_S16_ISFS
+#define DEBUG_OMXACSP_FIR_DIRECT_S16_I
+#define DEBUG_OMXACSP_FIR_DIRECT_S16
+#define DEBUG_OMXACSP_FIR_DIRECT_S16_SFS
+#define DEBUG_OMXACSP_IIRONE_BIQUADDIRECT_S16_I
+#define DEBUG_OMXACSP_IIRONE_BIQUADDIRECT_S16
+#define DEBUG_OMXACSP_IIRONE_DIRECT_S16_I
+#define DEBUG_OMXACSP_IIRONE_DIRECT_S16
+#define DEBUG_OMXACSP_IIR_BIQUADDIRECT_S16_I
+#define DEBUG_OMXACSP_IIR_BIQUADDIRECT_S16
+#define DEBUG_OMXACSP_IIR_DIRECT_S16_I
+#define DEBUG_OMXACSP_IIR_DIRECT_S16
+#endif /* DEBUG_DOMAIN_SP */
+
+
+#ifdef DEBUG_DOMAIN_IP
+#define DEBUG_OMXIPBM_ADDC_U8_C1R_SFS
+#define DEBUG_OMXIPBM_COPY_U8_C1R
+#define DEBUG_OMXIPBM_COPY_U8_C3R
+#define DEBUG_OMXIPBM_MIRROR_U8_C1R
+#define DEBUG_OMXIPBM_MULC_U8_C1R_SFS
+#define DEBUG_OMXIPCS_COLORTWISTQ14_U8_C3R
+#define DEBUG_OMXIPCS_RGB565TOYCBCR420LS_MCU_U16_S16_C3P3R
+#define DEBUG_OMXIPCS_RGB565TOYCBCR422LS_MCU_U16_S16_C3P3R
+#define DEBUG_OMXIPCS_RGB565TOYCBCR444LS_MCU_U16_S16_C3P3R
+#define DEBUG_OMXIPCS_RGBTOYCBCR420LS_MCU_U8_S16_C3P3R
+#define DEBUG_OMXIPCS_RGBTOYCBCR422LS_MCU_U8_S16_C3P3R
+#define DEBUG_OMXIPCS_RGBTOYCBCR444LS_MCU_U8_S16_C3P3R
+#define DEBUG_OMXIPCS_YCBCR420RSZROT_U8_P3R
+#define DEBUG_OMXIPCS_YCBCR420TORGB565LS_MCU_S16_U16_P3C3R
+#define DEBUG_OMXIPCS_YCBCR420TORGB565_U8_U16_P3C3R
+#define DEBUG_OMXIPCS_YCBCR420TORGBLS_MCU_S16_U8_P3C3R
+#define DEBUG_OMXIPCS_YCBCR422RSZCSCROTRGB_U8_C2R
+#define DEBUG_OMXIPCS_YCBCR422RSZROT_U8_P3R
+#define DEBUG_OMXIPCS_YCBCR422TORGB565LS_MCU_S16_U16_P3C3R
+#define DEBUG_OMXIPCS_YCBCR422TORGB565_U8_U16_C2C3R
+#define DEBUG_OMXIPCS_YCBCR422TORGBLS_MCU_S16_U8_P3C3R
+#define DEBUG_OMXIPCS_YCBCR422TORGB_U8_C2C3R
+#define DEBUG_OMXIPCS_YCBCR422TOYCBCR420ROTATE_U8_C2P3R
+#define DEBUG_OMXIPCS_YCBCR422TOYCBCR420ROTATE_U8_P3R
+#define DEBUG_OMXIPCS_YCBCR444TORGB565LS_MCU_S16_U16_P3C3R
+#define DEBUG_OMXIPCS_YCBCR444TORGBLS_MCU_S16_U8_P3C3R
+#define DEBUG_OMXIPCS_YCBCRTORGB565_U8_U16_C3R
+#define DEBUG_OMXIPCS_YCBCRTORGB565_U8_U16_P3C3R
+#define DEBUG_OMXIPCS_YCBCRTORGB_U8_C3R
+#define DEBUG_OMXIPPP_GETCENTRALMOMENT_S64
+#define DEBUG_OMXIPPP_GETSPATIALMOMENT_S64
+#define DEBUG_OMXIPPP_MOMENTGETSTATESIZE_S64
+#define DEBUG_OMXIPPP_MOMENTINIT_S64
+#define DEBUG_OMXIPPP_MOMENTS64S_U8_C1R
+#define DEBUG_OMXIPPP_MOMENTS64S_U8_C3R
+#endif /* DEBUG_DOMAIN_IP */
+
+
+#endif /* _armCommon_H_ */
+
+/*End of File*/
+
+
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armCOMM_BitDec_s.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armCOMM_BitDec_s.h
new file mode 100755
index 0000000..c738f72
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armCOMM_BitDec_s.h
@@ -0,0 +1,670 @@
+;//
+;// 
+;// File Name:  armCOMM_BitDec_s.h
+;// OpenMAX DL: v1.0.2
+;// Revision:   12290
+;// Date:       Wednesday, April 9, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;// 
+;// OpenMAX optimized bitstream decode module
+;//
+;// You must include armCOMM_s.h before including this file
+;//
+;// This module provides macros to perform assembly optimized fixed and
+;// variable length decoding from a read-only bitstream. The variable
+;// length decode modules take as input a pointer to a table of 16-bit
+;// entries of the following format.
+;//
+;// VLD Table Entry format
+;//
+;//        15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
+;//       +------------------------------------------------+
+;//       |  Len   |               Symbol              | 1 |
+;//       +------------------------------------------------+
+;//       |                Offset                      | 0 |
+;//       +------------------------------------------------+
+;//
+;// If the table entry is a leaf entry then bit 0 set:
+;//    Len    = Number of bits overread (0 to 7)
+;//    Symbol = Symbol payload (unsigned 12 bits)
+;//
+;// If the table entry is an internal node then bit 0 is clear:
+;//    Offset = Number of (16-bit) half words from the table
+;//             start to the next table node
+;//
+;// The table is accessed by successive lookup up on the
+;// next Step bits of the input bitstream until a leaf node
+;// is obtained. The Step sizes are supplied to the VLD macro.
+;//
+;// USAGE:
+;//
+;// To use any of the macros in this package, first call:
+;//
+;//    M_BD_INIT ppBitStream, pBitOffset, pBitStream, RBitBuffer, RBitCount, Tmp
+;//
+;// This caches the current bitstream position and next available
+;// bits in registers pBitStream, RBitBuffer, RBitCount. These registers
+;// are reserved for use by the bitstream decode package until you
+;// call M_BD_FINI.
+;//
+;// Next call the following macro(s) as many times as you need:
+;//
+;//    M_BD_LOOK8       - Look ahead constant 1<=N<=8  bits into the bitstream
+;//    M_BD_LOOK16      - Look ahead constant 1<=N<=16 bits into the bitstream
+;//    M_BD_READ8       - Read constant 1<=N<=8  bits from the bitstream
+;//    M_BD_READ16      - Read constant 1<=N<=16 bits from the bitstream
+;//    M_BD_VREAD8      - Read variable 1<=N<=8  bits from the bitstream
+;//    M_BD_VREAD16     - Read variable 1<=N<=16 bits from the bitstream
+;//    M_BD_VLD         - Perform variable length decode using lookup table
+;//
+;// Finally call the macro:
+;//
+;//    M_BD_FINI ppBitStream, pBitOffset
+;//
+;// This writes the bitstream state back to memory.
+;//
+;// The three bitstream cache register names are assigned to the following global
+;// variables:
+;//
+
+        GBLS    pBitStream  ;// Register name for pBitStream
+        GBLS    BitBuffer   ;// Register name for BitBuffer
+        GBLS    BitCount    ;// Register name for BitCount
+   
+;//        
+;// These register variables must have a certain defined state on entry to every bitstream
+;// macro (except M_BD_INIT) and on exit from every bitstream macro (except M_BD_FINI).
+;// The state may depend on implementation.
+;//
+;// For the default (ARM11) implementation the following hold:
+;//    pBitStream - points to the first byte not held in the BitBuffer
+;//    BitBuffer  - is a cache of (4 bytes) 32 bits, bit 31 the first bit
+;//    BitCount   - is offset (from the top bit) to the next unused bitstream bit
+;//    0<=BitCount<=15 (so BitBuffer holds at least 17 unused bits)
+;//
+;//
+
+        ;// Bitstream Decode initialise
+        ;//
+        ;// Initialises the bitstream decode global registers from
+        ;// bitstream pointers. This macro is split into 3 parts to enable
+        ;// scheduling.
+        ;//
+        ;// Input Registers:
+        ;//
+        ;// $ppBitStream    - pointer to pointer to the next bitstream byte
+        ;// $pBitOffset     - pointer to the number of bits used in the current byte (0..7)
+        ;// $RBitStream     - register to use for pBitStream (can be $ppBitStream)
+        ;// $RBitBuffer     - register to use for BitBuffer
+        ;// $RBitCount      - register to use for BitCount   (can be $pBitOffset)
+        ;//
+        ;// Output Registers:
+        ;//
+        ;// $T1,$T2,$T3     - registers that must be preserved between calls to
+        ;//                   M_BD_INIT1 and M_BD_INIT2
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;//
+        MACRO
+        M_BD_INIT0  $ppBitStream, $pBitOffset, $RBitStream, $RBitBuffer, $RBitCount
+
+pBitStream  SETS "$RBitStream"
+BitBuffer   SETS "$RBitBuffer"
+BitCount    SETS "$RBitCount"        
+        
+        ;// load inputs
+        LDR     $pBitStream, [$ppBitStream]
+        LDR     $BitCount, [$pBitOffset]
+        MEND
+        
+        MACRO
+        M_BD_INIT1  $T1, $T2, $T3
+        LDRB    $T2, [$pBitStream, #2]
+        LDRB    $T1, [$pBitStream, #1]
+        LDRB    $BitBuffer,  [$pBitStream], #3
+        ADD     $BitCount, $BitCount, #8
+        MEND
+        
+        MACRO
+        M_BD_INIT2  $T1, $T2, $T3
+        ORR     $T2, $T2, $T1, LSL #8
+        ORR     $BitBuffer, $T2, $BitBuffer, LSL #16
+        MEND    
+        
+        ;//
+        ;// Look ahead fixed 1<=N<=8 bits without consuming any bits
+        ;// The next bits will be placed at bit 31..24 of destination register
+        ;//
+        ;// Input Registers:
+        ;//
+        ;// $N              - number of bits to look
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;// 
+        ;// Output Registers:
+        ;//
+        ;// $Symbol         - the next N bits of the bitstream
+        ;// $T1             - corrupted temp/scratch register
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;//
+        MACRO
+        M_BD_LOOK8  $Symbol, $N
+        ASSERT  ($N>=1):LAND:($N<=8)
+        MOV     $Symbol, $BitBuffer, LSL $BitCount
+        MEND
+        
+        ;//
+        ;// Look ahead fixed 1<=N<=16 bits without consuming any bits
+        ;// The next bits will be placed at bit 31..16 of destination register
+        ;//
+        ;// Input Registers:
+        ;//
+        ;// $N              - number of bits to look
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;// 
+        ;// Output Registers:
+        ;//
+        ;// $Symbol         - the next N bits of the bitstream
+        ;// $T1             - corrupted temp/scratch register
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;//
+        MACRO
+        M_BD_LOOK16  $Symbol, $N, $T1
+        ASSERT  ($N >= 1):LAND:($N <= 16)
+        MOV     $Symbol, $BitBuffer, LSL $BitCount
+        MEND
+        
+        ;//
+        ;// Skips fixed 1<=N<=8 bits from the bitstream, advancing the bitstream pointer
+        ;//
+        ;// Input Registers:
+        ;//
+        ;// $N              - number of bits
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;// 
+        ;// Output Registers:
+        ;//
+        ;// $T1             - corrupted temp/scratch register
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;//
+        MACRO
+        M_BD_SKIP8 $N, $T1
+        ASSERT  ($N>=1):LAND:($N<=8)        
+        SUBS    $BitCount, $BitCount, #(8-$N)
+        LDRCSB  $T1, [$pBitStream], #1   
+        ADDCC   $BitCount, $BitCount, #8
+        ORRCS   $BitBuffer, $T1, $BitBuffer, LSL #8
+        MEND
+        
+        
+        ;//
+        ;// Read fixed 1<=N<=8 bits from the bitstream, advancing the bitstream pointer
+        ;//
+        ;// Input Registers:
+        ;//
+        ;// $N              - number of bits to read
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;// 
+        ;// Output Registers:
+        ;//
+        ;// $Symbol         - the next N bits of the bitstream
+        ;// $T1             - corrupted temp/scratch register
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;//
+        MACRO
+        M_BD_READ8 $Symbol, $N, $T1
+        ASSERT  ($N>=1):LAND:($N<=8)                
+        MOVS    $Symbol, $BitBuffer, LSL $BitCount        
+        SUBS    $BitCount, $BitCount, #(8-$N)
+        LDRCSB  $T1, [$pBitStream], #1   
+        ADDCC   $BitCount, $BitCount, #8
+        MOV     $Symbol, $Symbol, LSR #(32-$N)
+        ORRCS   $BitBuffer, $T1, $BitBuffer, LSL #8
+        MEND
+
+        ;//
+        ;// Read fixed 1<=N<=16 bits from the bitstream, advancing the bitstream pointer
+        ;//
+        ;// Input Registers:
+        ;//
+        ;// $N              - number of bits to read
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;// 
+        ;// Output Registers:
+        ;//
+        ;// $Symbol         - the next N bits of the bitstream
+        ;// $T1             - corrupted temp/scratch register
+        ;// $T2             - corrupted temp/scratch register
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;//
+        MACRO
+        M_BD_READ16 $Symbol, $N, $T1, $T2
+        ASSERT  ($N>=1):LAND:($N<=16)
+        ASSERT  $Symbol<>$T1
+        IF ($N<=8)
+            M_BD_READ8  $Symbol, $N, $T1
+        ELSE        
+            ;// N>8 so we will be able to refill at least one byte            
+            LDRB    $T1, [$pBitStream], #1            
+            MOVS    $Symbol, $BitBuffer, LSL $BitCount
+            ORR     $BitBuffer, $T1, $BitBuffer, LSL #8                       
+            SUBS    $BitCount, $BitCount, #(16-$N)
+            LDRCSB  $T1, [$pBitStream], #1            
+            MOV     $Symbol, $Symbol, LSR #(32-$N)
+            ADDCC   $BitCount, $BitCount, #8
+            ORRCS   $BitBuffer, $T1, $BitBuffer, LSL #8
+        ENDIF
+        MEND
+        
+        ;//
+        ;// Skip variable 1<=N<=8 bits from the bitstream, advancing the bitstream pointer.
+        ;//
+        ;// Input Registers:
+        ;//
+        ;// $N              - number of bits. 1<=N<=8
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;// 
+        ;// Output Registers:
+        ;//
+        ;// $T1             - corrupted temp/scratch register
+        ;// $T2             - corrupted temp/scratch register
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;//
+        MACRO
+        M_BD_VSKIP8 $N, $T1
+        ADD     $BitCount, $BitCount, $N
+        SUBS    $BitCount, $BitCount, #8
+        LDRCSB  $T1, [$pBitStream], #1        
+        ADDCC   $BitCount, $BitCount, #8
+        ORRCS   $BitBuffer, $T1, $BitBuffer, LSL #8
+        MEND        
+        
+        ;//
+        ;// Skip variable 1<=N<=16 bits from the bitstream, advancing the bitstream pointer.
+        ;//
+        ;// Input Registers:
+        ;//
+        ;// $N              - number of bits. 1<=N<=16
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;// 
+        ;// Output Registers:
+        ;//
+        ;// $T1             - corrupted temp/scratch register
+        ;// $T2             - corrupted temp/scratch register
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;//
+        MACRO
+        M_BD_VSKIP16 $N, $T1, $T2
+        ADD     $BitCount, $BitCount, $N
+        SUBS    $BitCount, $BitCount, #8
+        LDRCSB  $T1, [$pBitStream], #1        
+        ORRCS   $BitBuffer, $T1, $BitBuffer, LSL #8
+        SUBCSS  $BitCount, $BitCount, #8        
+        LDRCSB  $T1, [$pBitStream], #1
+        ADDCC   $BitCount, $BitCount, #8
+        ORRCS   $BitBuffer, $T1, $BitBuffer, LSL #8
+        MEND        
+
+        ;//
+        ;// Read variable 1<=N<=8 bits from the bitstream, advancing the bitstream pointer.
+        ;//
+        ;// Input Registers:
+        ;//
+        ;// $N              - number of bits to read. 1<=N<=8
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;// 
+        ;// Output Registers:
+        ;//
+        ;// $Symbol         - the next N bits of the bitstream
+        ;// $T1             - corrupted temp/scratch register
+        ;// $T2             - corrupted temp/scratch register
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;//
+        MACRO
+        M_BD_VREAD8 $Symbol, $N, $T1, $T2
+        MOV     $Symbol, $BitBuffer, LSL $BitCount        
+        ADD     $BitCount, $BitCount, $N
+        SUBS    $BitCount, $BitCount, #8
+        LDRCSB  $T1, [$pBitStream], #1        
+        RSB     $T2, $N, #32        
+        ADDCC   $BitCount, $BitCount, #8
+        MOV     $Symbol, $Symbol, LSR $T2
+        ORRCS   $BitBuffer, $T1, $BitBuffer, LSL #8
+        MEND
+
+
+        ;//
+        ;// Read variable 1<=N<=16 bits from the bitstream, advancing the bitstream pointer.
+        ;//
+        ;// Input Registers:
+        ;//
+        ;// $N              - number of bits to read. 1<=N<=16
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;// 
+        ;// Output Registers:
+        ;//
+        ;// $Symbol         - the next N bits of the bitstream
+        ;// $T1             - corrupted temp/scratch register
+        ;// $T2             - corrupted temp/scratch register
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;//
+        MACRO
+        M_BD_VREAD16 $Symbol, $N, $T1, $T2
+        MOV     $Symbol, $BitBuffer, LSL $BitCount        
+        ADD     $BitCount, $BitCount, $N
+        SUBS    $BitCount, $BitCount, #8
+        LDRCSB  $T1, [$pBitStream], #1        
+        RSB     $T2, $N, #32        
+        ORRCS   $BitBuffer, $T1, $BitBuffer, LSL #8
+        SUBCSS  $BitCount, $BitCount, #8        
+        LDRCSB  $T1, [$pBitStream], #1
+        ADDCC   $BitCount, $BitCount, #8
+        MOV     $Symbol, $Symbol, LSR $T2
+        ORRCS   $BitBuffer, $T1, $BitBuffer, LSL #8
+        MEND
+
+
+        ;//
+        ;// Decode a code of the form 0000...001 where there
+        ;// are N zeros before the 1 and N<=15 (code length<=16)
+        ;//
+        ;// Input Registers:
+        ;//
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;// 
+        ;// Output Registers:
+        ;//
+        ;// $Symbol         - the number of zeros before the next 1
+        ;//                   >=16 is an illegal code
+        ;// $T1             - corrupted temp/scratch register
+        ;// $T2             - corrupted temp/scratch register
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;//        
+        MACRO
+        M_BD_CLZ16 $Symbol, $T1, $T2
+        MOVS    $Symbol, $BitBuffer, LSL $BitCount
+        CLZ     $Symbol, $Symbol                
+        ADD     $BitCount, $BitCount, $Symbol
+        SUBS    $BitCount, $BitCount, #7        ;// length is Symbol+1
+        LDRCSB  $T1, [$pBitStream], #1
+        ORRCS   $BitBuffer, $T1, $BitBuffer, LSL #8
+        SUBCSS  $BitCount, $BitCount, #8        
+        LDRCSB  $T1, [$pBitStream], #1
+        ADDCC   $BitCount, $BitCount, #8
+        ORRCS   $BitBuffer, $T1, $BitBuffer, LSL #8
+        MEND  
+
+        ;//
+        ;// Decode a code of the form 1111...110 where there
+        ;// are N ones before the 0 and N<=15 (code length<=16)
+        ;//
+        ;// Input Registers:
+        ;//
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;// 
+        ;// Output Registers:
+        ;//
+        ;// $Symbol         - the number of zeros before the next 1
+        ;//                   >=16 is an illegal code
+        ;// $T1             - corrupted temp/scratch register
+        ;// $T2             - corrupted temp/scratch register
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;//        
+        MACRO
+        M_BD_CLO16 $Symbol, $T1, $T2
+        MOV     $Symbol, $BitBuffer, LSL $BitCount
+        MVN     $Symbol, $Symbol
+        CLZ     $Symbol, $Symbol                
+        ADD     $BitCount, $BitCount, $Symbol
+        SUBS    $BitCount, $BitCount, #7        ;// length is Symbol+1
+        LDRCSB  $T1, [$pBitStream], #1
+        ORRCS   $BitBuffer, $T1, $BitBuffer, LSL #8
+        SUBCSS  $BitCount, $BitCount, #8        
+        LDRCSB  $T1, [$pBitStream], #1
+        ADDCC   $BitCount, $BitCount, #8
+        ORRCS   $BitBuffer, $T1, $BitBuffer, LSL #8
+        MEND  
+
+
+        ;//
+        ;// Variable Length Decode module
+        ;//
+        ;// Decodes one VLD Symbol from a bitstream and refill the bitstream
+        ;// buffer.
+        ;//
+        ;// Input Registers:
+        ;//
+        ;// $pVLDTable      - pointer to VLD decode table of 16-bit entries.
+        ;//                   The format is described above at the start of
+        ;//                   this file.
+        ;// $S0             - The number of bits to look up for the first step
+        ;//                   1<=$S0<=8
+        ;// $S1             - The number of bits to look up for each subsequent
+        ;//                   step 1<=$S1<=$S0.
+        ;//
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;// 
+        ;// Output Registers:
+        ;//
+        ;// $Symbol         - decoded VLD symbol value
+        ;// $T1             - corrupted temp/scratch register
+        ;// $T2             - corrupted temp/scratch register
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;//
+        MACRO
+        M_BD_VLD $Symbol, $T1, $T2, $pVLDTable, $S0, $S1
+        ASSERT (1<=$S0):LAND:($S0<=8)
+        ASSERT (1<=$S1):LAND:($S1<=$S0)
+        
+        ;// Note 0<=BitCount<=15 on entry and exit
+        
+        MOVS    $T1, $BitBuffer, LSL $BitCount       ;// left align next bits
+        MOVS    $Symbol, #(2<<$S0)-2                 ;// create mask
+        AND     $Symbol, $Symbol, $T1, LSR #(31-$S0) ;// 2*(next $S0 bits)
+        SUBS    $BitCount, $BitCount, #8             ;// CS if buffer can be filled
+01
+        LDRCSB  $T1, [$pBitStream], #1               ;// load refill byte
+        LDRH    $Symbol, [$pVLDTable, $Symbol]       ;// load table entry
+        ADDCC   $BitCount, $BitCount, #8             ;// refill not possible
+        ADD     $BitCount, $BitCount, #$S0           ;// assume $S0 bits used
+        ORRCS   $BitBuffer, $T1, $BitBuffer, LSL #8  ;// merge in refill byte
+        MOVS    $T1, $Symbol, LSR #1                 ;// CS=leaf entry
+        BCS     %FT02
+        
+        MOVS    $T1, $BitBuffer, LSL $BitCount       ;// left align next bit
+        IF (2*$S0-$S1<=8)
+            ;// Can combine refill check and -S0+S1 and keep $BitCount<=15
+            SUBS    $BitCount, $BitCount, #8+($S0-$S1)
+        ELSE
+            ;// Separate refill check and -S0+S1 offset
+            SUBS  $BitCount, $BitCount, #8
+            SUB   $BitCount, $BitCount, #($S0-$S1)
+        ENDIF
+        ADD     $Symbol, $Symbol, $T1, LSR #(31-$S1) ;// add 2*(next $S1 bits) to
+        BIC     $Symbol, $Symbol, #1                 ;//   table offset
+        B       %BT01                                ;// load next table entry
+02
+        ;// BitCount range now depend on the route here
+        ;// if (first step)       S0 <= BitCount <= 7+S0        <=15
+        ;// else if (2*S0-S1<=8)  S0 <= BitCount <= 7+(2*S0-S1) <=15
+        ;// else                  S1 <= BitCount <= 7+S1        <=15
+        
+        SUB     $BitCount, $BitCount, $Symbol, LSR#13
+        BIC     $Symbol, $T1, #0xF000
+        MEND
+        
+
+        ;// Add an offset number of bits
+        ;//
+        ;// Outputs destination byte and bit index values which corresponds to an offset number of bits 
+        ;// from the current location. This is used to compare bitstream positions using. M_BD_CMP.
+        ;//
+        ;// Input Registers:
+        ;//
+        ;// $Offset         - Offset to be added in bits.
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;//
+        ;// Output Registers:
+        ;//
+        ;// $ByteIndex      - Destination pBitStream pointer after adding the Offset. 
+        ;//                   This value will be 4 byte ahead and needs to subtract by 4 to get exact 
+        ;//                   pointer (as in M_BD_FINI). But for using with M_BD_CMP subtract is not needed.
+        ;// $BitIndex       - Destination BitCount after the addition of Offset number of bits
+        ;//
+        MACRO
+        M_BD_ADD  $ByteIndex, $BitIndex, $Offset
+
+        ;// ($ByteIndex,$BitIndex) = Current position + $Offset bits
+        ADD     $Offset, $Offset, $BitCount
+        AND     $BitIndex, $Offset, #7
+        ADD     $ByteIndex, $pBitStream, $Offset, ASR #3        
+        MEND
+
+        ;// Move bitstream pointers to the location given
+        ;//
+        ;// Outputs destination byte and bit index values which corresponds to  
+        ;// the current location given (calculated using M_BD_ADD). 
+        ;//
+        ;// Input Registers:
+        ;//
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;// $ByteIndex      - Destination pBitStream pointer after move. 
+        ;//                   This value will be 4 byte ahead and needs to subtract by 4 to get exact 
+        ;//                   pointer (as in M_BD_FINI).
+        ;// $BitIndex       - Destination BitCount after the move
+        ;//
+        ;// Output Registers:
+        ;//
+        ;// $pBitStream     \ 
+        ;//                  } See description above.  
+        ;// $BitCount       / 
+        ;//
+        MACRO
+        M_BD_MOV  $ByteIndex, $BitIndex
+
+        ;// ($pBitStream, $Offset) = ($ByteIndex,$BitIndex)
+        MOV     $BitCount, $BitIndex
+        MOV     $pBitStream, $ByteIndex
+        MEND
+
+        ;// Bitstream Compare
+        ;//
+        ;// Compares bitstream position with that of a destination position. Destination position 
+        ;// is held in two input registers which are calculated using M_BD_ADD macro
+        ;//
+        ;// Input Registers:
+        ;//
+        ;// $ByteIndex      - Destination pBitStream pointer, (4 byte ahead as described in M_BD_ADD)
+        ;// $BitIndex       - Destination BitCount
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;//
+        ;// Output Registers:
+        ;//
+        ;// FLAGS           - GE if destination is reached, LT = is destination is ahead
+        ;// $T1             - corrupted temp/scratch register
+        ;//
+        MACRO
+        M_BD_CMP  $ByteIndex, $BitIndex, $T1
+        
+        ;// Return flags set by (current positon)-($ByteIndex,$BitIndex)
+        ;// so GE means that we have reached the indicated position
+
+        ADD         $T1, $pBitStream, $BitCount, LSR #3
+        CMP         $T1, $ByteIndex
+        AND         $T1, $BitCount, #7
+        CMPEQ       $T1, $BitIndex        
+        MEND
+
+        
+        ;// Bitstream Decode finalise
+        ;//
+        ;// Writes back the bitstream state to the bitstream pointers
+        ;//
+        ;// Input Registers:
+        ;//
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } See description above.
+        ;// $BitCount       / 
+        ;//
+        ;// Output Registers:
+        ;//
+        ;// $ppBitStream    - pointer to pointer to the next bitstream byte
+        ;// $pBitOffset     - pointer to the number of bits used in the current byte (0..7)
+        ;// $pBitStream     \ 
+        ;// $BitBuffer       } these register are corrupted
+        ;// $BitCount       / 
+        ;//
+        MACRO
+        M_BD_FINI  $ppBitStream, $pBitOffset
+        
+        ;// Advance pointer by the number of free bits in the buffer
+        ADD     $pBitStream, $pBitStream, $BitCount, LSR#3
+        AND     $BitCount, $BitCount, #7
+        
+        ;// Now move back 32 bits to reach the first usued bit
+        SUB     $pBitStream, $pBitStream, #4
+        
+        ;// Store out bitstream state
+        STR     $BitCount, [$pBitOffset]
+        STR     $pBitStream, [$ppBitStream]
+        MEND
+        
+        END
+        
\ No newline at end of file
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armCOMM_Bitstream.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armCOMM_Bitstream.h
new file mode 100755
index 0000000..b699034
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armCOMM_Bitstream.h
@@ -0,0 +1,212 @@
+/**
+ * 
+ * File Name:  armCOMM_Bitstream.h
+ * OpenMAX DL: v1.0.2
+ * Revision:   12290
+ * Date:       Wednesday, April 9, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * File: armCOMM_Bitstream.h
+ * Brief: Declares common API's/Data types used across the OpenMax Encoders/Decoders.
+ *
+ */
+
+#ifndef _armCodec_H_
+#define _armCodec_H_
+
+#include "omxtypes.h"
+
+typedef struct {
+    OMX_U8   codeLen;
+    OMX_U32	 codeWord;
+} ARM_VLC32;
+
+/* The above should be renamed as "ARM_VLC32" */
+
+/**
+ * Function: armLookAheadBits()
+ *
+ * Description:
+ * Get the next N bits from the bitstream without advancing the bitstream pointer
+ *
+ * Parameters:
+ * [in]     **ppBitStream
+ * [in]     *pOffset
+ * [in]     N=1...32
+ *
+ * Returns  Value
+ */
+
+OMX_U32 armLookAheadBits(const OMX_U8 **ppBitStream, OMX_INT *pOffset, OMX_INT N);
+
+/**
+ * Function: armGetBits()
+ *
+ * Description:
+ * Read N bits from the bitstream
+ *    
+ * Parameters:
+ * [in]     *ppBitStream
+ * [in]     *pOffset
+ * [in]     N=1..32
+ *
+ * [out]    *ppBitStream
+ * [out]    *pOffset
+ * Returns  Value
+ */
+
+OMX_U32 armGetBits(const OMX_U8 **ppBitStream, OMX_INT *pOffset, OMX_INT N);
+
+/**
+ * Function: armByteAlign()
+ *
+ * Description:
+ * Align the pointer *ppBitStream to the next byte boundary
+ *
+ * Parameters:
+ * [in]     *ppBitStream
+ * [in]     *pOffset
+ *
+ * [out]    *ppBitStream
+ * [out]    *pOffset
+ *
+ **/
+ 
+OMXVoid armByteAlign(const OMX_U8 **ppBitStream,OMX_INT *pOffset);
+
+/** 
+ * Function: armSkipBits()
+ *
+ * Description:
+ * Skip N bits from the value at *ppBitStream
+ *
+ * Parameters:
+ * [in]     *ppBitStream
+ * [in]     *pOffset
+ * [in]     N
+ *
+ * [out]    *ppBitStream
+ * [out]    *pOffset
+ *
+ **/
+
+OMXVoid armSkipBits(const OMX_U8 **ppBitStream,OMX_INT *pOffset,OMX_INT N);
+
+/***************************************
+ * Variable bit length Decode
+ ***************************************/
+
+/**
+ * Function: armUnPackVLC32()
+ *
+ * Description:
+ * Variable length decode of variable length symbol (max size 32 bits) read from
+ * the bit stream pointed by *ppBitStream at *pOffset by using the table
+ * pointed by pCodeBook
+ * 
+ * Parameters:
+ * [in]     **ppBitStream
+ * [in]     *pOffset
+ * [in]     pCodeBook
+ * 
+ * [out]    **ppBitStream
+ * [out]    *pOffset
+ *
+ * Returns : Code Book Index if successfull. 
+ *         : "ARM_NO_CODEBOOK_INDEX = 0xFFFF" if search fails.
+ **/
+
+#define ARM_NO_CODEBOOK_INDEX (OMX_U16)(0xFFFF)
+
+OMX_U16 armUnPackVLC32(
+    const OMX_U8 **ppBitStream,
+    OMX_INT *pOffset,
+    const ARM_VLC32 *pCodeBook
+);
+
+/***************************************
+ * Fixed bit length Encode
+ ***************************************/
+
+/**
+ * Function: armPackBits
+ *
+ * Description:
+ * Pack a VLC code word into the bitstream
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	ppBitStream		pointer to the pointer to the current byte 
+ *                      in the bit stream.
+ * [in]	pOffset	        pointer to the bit position in the byte 
+ *                      pointed by *ppBitStream. Valid within 0
+ *                      to 7.
+ * [in]	codeWord		Code word that need to be inserted in to the
+ *                          bitstream
+ * [in]	codeLength		Length of the code word valid range 1...32
+ *
+ * [out] ppBitStream	*ppBitStream is updated after the block is encoded,
+ *	                        so that it points to the current byte in the bit
+ *							stream buffer.
+ * [out] pBitOffset		*pBitOffset is updated so that it points to the
+ *							current bit position in the byte pointed by
+ *							*ppBitStream.
+ *
+ * Return Value:
+ * Standard OMX_RESULT result. See enumeration for possible result codes.
+ *
+ */
+ 
+OMXResult armPackBits (
+    OMX_U8  **ppBitStream, 
+    OMX_INT *pOffset,
+    OMX_U32 codeWord, 
+    OMX_INT codeLength 
+);
+ 
+/***************************************
+ * Variable bit length Encode
+ ***************************************/
+
+/**
+ * Function: armPackVLC32
+ *
+ * Description:
+ * Pack a VLC code word into the bitstream
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	ppBitStream		pointer to the pointer to the current byte 
+ *                      in the bit stream.
+ * [in]	pBitOffset	    pointer to the bit position in the byte 
+ *                      pointed by *ppBitStream. Valid within 0
+ *                      to 7.
+ * [in]	 code     		VLC code word that need to be inserted in to the
+ *                      bitstream
+ *
+ * [out] ppBitStream	*ppBitStream is updated after the block is encoded,
+ *	                    so that it points to the current byte in the bit
+ *						stream buffer.
+ * [out] pBitOffset		*pBitOffset is updated so that it points to the
+ *						current bit position in the byte pointed by
+ *						*ppBitStream.
+ *
+ * Return Value:
+ * Standard OMX_RESULT result. See enumeration for possible result codes.
+ *
+ */
+ 
+OMXResult armPackVLC32 (
+    OMX_U8 **ppBitStream, 
+    OMX_INT *pBitOffset,
+    ARM_VLC32 code 
+);
+
+#endif      /*_armCodec_H_*/
+
+/*End of File*/
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armCOMM_IDCTTable.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armCOMM_IDCTTable.h
new file mode 100755
index 0000000..e0cfdaa
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armCOMM_IDCTTable.h
@@ -0,0 +1,40 @@
+/**
+ *
+ * 
+ * File Name:  armCOMM_IDCTTable.h
+ * OpenMAX DL: v1.0.2
+ * Revision:   12290
+ * Date:       Wednesday, April 9, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * File         : armCOMM_IDCTTable.h
+ * Description  : Contains declarations of tables for IDCT calculation.
+ *
+ */
+  
+#ifndef _armCOMM_IDCTTable_H_
+#define _armCOMM_IDCTTable_H_
+
+#include "omxtypes.h"
+
+     /*  Table of s(u)*A(u)*A(v)/16 at Q15
+      *  s(u)=1.0 0 <= u <= 5
+      *  s(6)=2.0
+      *  s(7)=4.0
+      *  A(0) = 2*sqrt(2)
+      *  A(u) = 4*cos(u*pi/16)  for (u!=0)
+	  */
+extern const OMX_U16 armCOMM_IDCTPreScale [64];
+extern const OMX_U16 armCOMM_IDCTCoef [4];
+
+#endif /* _armCOMM_IDCTTable_H_ */
+
+
+/* End of File */
+
+
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armCOMM_IDCT_s.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armCOMM_IDCT_s.h
new file mode 100755
index 0000000..0baa087
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armCOMM_IDCT_s.h
@@ -0,0 +1,1451 @@
+;//
+;// This confidential and proprietary software may be used only as
+;// authorised by a licensing agreement from ARM Limited
+;//   (C) COPYRIGHT 2004 ARM Limited
+;//       ALL RIGHTS RESERVED
+;// The entire notice above must be reproduced on all authorised
+;// copies and copies may only be made to the extent permitted
+;// by a licensing agreement from ARM Limited.
+;//
+;// IDCT_s.s
+;//
+;// Inverse DCT module
+;//
+;// 
+;// ALGORITHM DESCRIPTION
+;//
+;// The 8x8 2D IDCT is performed by calculating a 1D IDCT for each
+;// column and then a 1D IDCT for each row.
+;//
+;// The 8-point 1D IDCT is defined by
+;//   f(x) = (C(0)*T(0)*c(0,x) + ... + C(7)*T(7)*c(7,x))/2
+;//
+;//   C(u) = 1/sqrt(2) if u=0 or 1 if u!=0
+;//   c(u,x) = cos( (2x+1)*u*pi/16 )
+;//
+;// We compute the 8-point 1D IDCT using the reverse of
+;// the Arai-Agui-Nakajima flow graph which we split into
+;// 5 stages named in reverse order to identify with the
+;// forward DCT. Direct inversion of the forward formulae
+;// in file FDCT_s.s gives:
+;//
+;// IStage 5:   j(u) = T(u)*A(u)  [ A(u)=4*C(u)*c(u,0) ]
+;//             [ A(0) = 2*sqrt(2)
+;//               A(u) = 4*cos(u*pi/16)  for (u!=0) ]
+;//
+;// IStage 4:   i0 = j0             i1 = j4
+;//             i3 = (j2+j6)/2      i2 = (j2-j6)/2
+;//             i7 = (j5+j3)/2      i4 = (j5-j3)/2
+;//             i5 = (j1+j7)/2      i6 = (j1-j7)/2
+;//
+;// IStage 3:   h0 = (i0+i1)/2      h1 = (i0-i1)/2
+;//             h2 = (i2*sqrt2)-i3  h3 = i3
+;//             h4 =  cos(pi/8)*i4 + sin(pi/8)*i6
+;//             h6 = -sin(pi/8)*i4 + cos(pi/8)*i6
+;//             [ The above two lines rotate by -(pi/8) ]
+;//             h5 = (i5-i7)/sqrt2  h7 = (i5+i7)/2 
+;//             
+;// IStage 2:   g0 = (h0+h3)/2      g3 = (h0-h3)/2
+;//             g1 = (h1+h2)/2      g2 = (h1-h2)/2
+;//             g7 = h7             g6 = h6 - h7
+;//             g5 = h5 - g6        g4 = h4 - g5
+;//
+;// IStage 1:   f0 = (g0+g7)/2      f7 = (g0-g7)/2
+;//             f1 = (g1+g6)/2      f6 = (g1-g6)/2
+;//             f2 = (g2+g5)/2      f5 = (g2-g5)/2
+;//             f3 = (g3+g4)/2      f4 = (g3-g4)/2
+;//
+;// Note that most coefficients are halved 3 times during the
+;// above calculation. We can rescale the algorithm dividing
+;// the input by 8 to remove the halvings.
+;//
+;// IStage 5:   j(u) = T(u)*A(u)/8
+;//
+;// IStage 4:   i0 = j0             i1 = j4
+;//             i3 = j2 + j6        i2 = j2 - j6
+;//             i7 = j5 + j3        i4 = j5 - j3
+;//             i5 = j1 + j7        i6 = j1 - j7
+;//
+;// IStage 3:   h0 = i0 + i1        h1 = i0 - i1
+;//             h2 = (i2*sqrt2)-i3  h3 = i3
+;//             h4 = 2*( cos(pi/8)*i4 + sin(pi/8)*i6)
+;//             h6 = 2*(-sin(pi/8)*i4 + cos(pi/8)*i6)
+;//             h5 = (i5-i7)*sqrt2  h7 = i5 + i7 
+;//             
+;// IStage 2:   g0 = h0 + h3        g3 = h0 - h3
+;//             g1 = h1 + h2        g2 = h1 - h2
+;//             g7 = h7             g6 = h6 - h7
+;//             g5 = h5 - g6        g4 = h4 - g5
+;//
+;// IStage 1:   f0 = g0 + g7        f7 = g0 - g7
+;//             f1 = g1 + g6        f6 = g1 - g6
+;//             f2 = g2 + g5        f5 = g2 - g5
+;//             f3 = g3 + g4        f4 = g3 - g4
+;//
+;// Note:
+;// 1. The scaling by A(u)/8 can often be combined with inverse
+;//    quantization. The column and row scalings can be combined.
+;// 2. The flowgraph in the AAN paper has h4,g6 negated compared
+;//    to the above code but is otherwise identical.
+;// 3. The rotation by -pi/8 can be peformed using three multiplies
+;//    Eg  c*i4+s*i6 = (i6-i4)*s + (c+s)*i4
+;//       -s*i4+c*i6 = (i6-i4)*s + (c-s)*i6
+;// 4. If |T(u)|<=1 then from the IDCT definition,
+;//    |f(x)| <= ((1/sqrt2) + |c(1,x)| + .. + |c(7,x)|)/2
+;//            = ((1/sqrt2) + cos(pi/16) + ... + cos(7*pi/16))/2
+;//            = ((1/sqrt2) + (cot(pi/32)-1)/2)/2
+;//            = (1 + cos(pi/16) + cos(2pi/16) + cos(3pi/16))/sqrt(2)
+;//            = (approx)2.64
+;//    So the max gain of the 2D IDCT is ~x7.0 = 3 bits.
+;//    The table below shows input patterns generating the maximum
+;//    value of |f(u)| for input in the range |T(x)|<=1. M=-1, P=+1
+;//    InputPattern      Max |f(x)|
+;//      PPPPPPPP        |f0| =  2.64
+;//      PPPMMMMM        |f1| =  2.64
+;//      PPMMMPPP        |f2| =  2.64
+;//      PPMMPPMM        |f3| =  2.64
+;//      PMMPPMMP        |f4| =  2.64
+;//      PMMPMMPM        |f5| =  2.64
+;//      PMPPMPMP        |f6| =  2.64
+;//      PMPMPMPM        |f7| =  2.64
+;//   Note that this input pattern is the transpose of the
+;//   corresponding max input patter for the FDCT.
+
+;// Arguments
+
+pSrc    RN 0    ;// source data buffer
+Stride  RN 1    ;// destination stride in bytes
+pDest   RN 2    ;// destination data buffer
+pScale  RN 3    ;// pointer to scaling table
+
+
+        ;// DCT Inverse Macro
+        ;// The DCT code should be parametrized according
+        ;// to the following inputs:
+        ;// $outsize = "u8"  :  8-bit unsigned data saturated (0 to +255)
+        ;//            "s9"  : 16-bit signed data saturated to 9-bit (-256 to +255)
+        ;//            "s16" : 16-bit signed data not saturated (max size ~+/-14273)
+        ;// $inscale = "s16" : signed 16-bit aan-scale table, Q15 format, with 4 byte alignment
+        ;//            "s32" : signed 32-bit aan-scale table, Q23 format, with 4 byte alignment
+        ;//
+        ;// Inputs:
+        ;// pSrc   = r0 = Pointer to input data
+        ;//               Range is -256 to +255 (9-bit)
+        ;// Stride = r1 = Stride between input lines
+        ;// pDest  = r2 = Pointer to output data
+        ;// pScale = r3 = Pointer to aan-scale table in the format defined by $inscale
+        
+        
+        
+        MACRO
+        M_IDCT  $outsize, $inscale, $stride
+        LCLA    SHIFT
+        
+        
+        IF ARM1136JS
+        
+;// REGISTER ALLOCATION
+;// This is hard since we have 8 values, 9 free registers and each
+;// butterfly requires a temporary register. We also want to 
+;// maintain register order so we can use LDM/STM. The table below
+;// summarises the register allocation that meets all these criteria.
+;// a=1stcol, b=2ndcol, f,g,h,i are dataflow points described above.
+;//
+;// r1  a01     g0  h0
+;// r4  b01 f0  g1  h1  i0
+;// r5  a23 f1  g2      i1
+;// r6  b23 f2  g3  h2  i2
+;// r7  a45 f3      h3  i3
+;// r8  b45 f4  g4  h4  i4
+;// r9  a67 f5  g5  h5  i5
+;// r10 b67 f6  g6  h6  i6
+;// r11     f7  g7  h7  i7
+;//
+ra01    RN 1
+rb01    RN 4
+ra23    RN 5
+rb23    RN 6
+ra45    RN 7
+rb45    RN 8
+ra67    RN 9
+rb67    RN 10
+rtmp    RN 11
+csPiBy8 RN 12   ;// [ (Sin(pi/8)@Q15), (Cos(pi/8)@Q15) ]
+LoopRR2 RN 14   ;// [ LoopNumber<<13 , (1/Sqrt(2))@Q15 ]
+;// Transpose allocation
+xft     RN ra01
+xf0     RN rb01
+xf1     RN ra23
+xf2     RN rb23
+xf3     RN ra45
+xf4     RN rb45
+xf5     RN ra67
+xf6     RN rb67
+xf7     RN rtmp
+;// IStage 1 allocation
+xg0     RN xft
+xg1     RN xf0
+xg2     RN xf1
+xg3     RN xf2
+xgt     RN xf3
+xg4     RN xf4
+xg5     RN xf5
+xg6     RN xf6
+xg7     RN xf7
+;// IStage 2 allocation
+xh0     RN xg0
+xh1     RN xg1
+xht     RN xg2
+xh2     RN xg3
+xh3     RN xgt
+xh4     RN xg4
+xh5     RN xg5
+xh6     RN xg6
+xh7     RN xg7
+;// IStage 3,4 allocation
+xit     RN xh0
+xi0     RN xh1
+xi1     RN xht
+xi2     RN xh2
+xi3     RN xh3
+xi4     RN xh4
+xi5     RN xh5
+xi6     RN xh6
+xi7     RN xh7
+        
+        M_STR   pDest,  ppDest
+        IF "$stride"="s"
+            M_STR   Stride, pStride
+        ENDIF
+        M_ADR   pDest,  pBlk
+        LDR     csPiBy8, =0x30fc7642
+        LDR     LoopRR2, =0x00005a82
+  
+v6_idct_col$_F
+        ;// Load even values
+        LDR     xi4, [pSrc], #4  ;// j0
+        LDR     xi5, [pSrc, #4*16-4]  ;// j4
+        LDR     xi6, [pSrc, #2*16-4]  ;// j2
+        LDR     xi7, [pSrc, #6*16-4]  ;// j6
+        
+        ;// Scale Even Values
+        IF "$inscale"="s16" ;// 16x16 mul
+SHIFT       SETA    12
+            LDR     xi0, [pScale], #4
+            LDR     xi1, [pScale, #4*16-4]        
+            LDR     xi2, [pScale, #2*16-4]
+            MOV     xit, #1<<(SHIFT-1)
+            SMLABB  xi3, xi0, xi4, xit
+            SMLATT  xi4, xi0, xi4, xit
+            SMLABB  xi0, xi1, xi5, xit
+            SMLATT  xi5, xi1, xi5, xit
+            MOV     xi3, xi3, ASR #SHIFT
+            PKHBT   xi4, xi3, xi4, LSL #(16-SHIFT)
+            LDR     xi3, [pScale, #6*16-4]
+            SMLABB  xi1, xi2, xi6, xit
+            SMLATT  xi6, xi2, xi6, xit
+            MOV     xi0, xi0, ASR #SHIFT
+            PKHBT   xi5, xi0, xi5, LSL #(16-SHIFT)
+            SMLABB  xi2, xi3, xi7, xit
+            SMLATT  xi7, xi3, xi7, xit
+            MOV     xi1, xi1, ASR #SHIFT
+            PKHBT   xi6, xi1, xi6, LSL #(16-SHIFT)
+            MOV     xi2, xi2, ASR #SHIFT
+            PKHBT   xi7, xi2, xi7, LSL #(16-SHIFT)
+        ENDIF
+        IF "$inscale"="s32" ;// 32x16 mul
+SHIFT       SETA    (12+8-16)
+            MOV     xit, #1<<(SHIFT-1)
+            LDR     xi0, [pScale], #8
+            LDR     xi1, [pScale, #0*32+4-8]
+            LDR     xi2, [pScale, #4*32-8]
+            LDR     xi3, [pScale, #4*32+4-8]            
+            SMLAWB  xi0, xi0, xi4, xit
+            SMLAWT  xi1, xi1, xi4, xit
+            SMLAWB  xi2, xi2, xi5, xit
+            SMLAWT  xi3, xi3, xi5, xit            
+            MOV     xi0, xi0, ASR #SHIFT
+            PKHBT   xi4, xi0, xi1, LSL #(16-SHIFT)
+            MOV     xi2, xi2, ASR #SHIFT            
+            PKHBT   xi5, xi2, xi3, LSL #(16-SHIFT)
+            LDR     xi0, [pScale, #2*32-8]
+            LDR     xi1, [pScale, #2*32+4-8]
+            LDR     xi2, [pScale, #6*32-8]
+            LDR     xi3, [pScale, #6*32+4-8]            
+            SMLAWB  xi0, xi0, xi6, xit
+            SMLAWT  xi1, xi1, xi6, xit
+            SMLAWB  xi2, xi2, xi7, xit
+            SMLAWT  xi3, xi3, xi7, xit            
+            MOV     xi0, xi0, ASR #SHIFT
+            PKHBT   xi6, xi0, xi1, LSL #(16-SHIFT)
+            MOV     xi2, xi2, ASR #SHIFT            
+            PKHBT   xi7, xi2, xi3, LSL #(16-SHIFT)
+        ENDIF
+                
+        ;// Load odd values
+        LDR     xi0, [pSrc, #1*16-4]      ;// j1
+        LDR     xi1, [pSrc, #7*16-4]      ;// j7
+        LDR     xi2, [pSrc, #5*16-4]      ;// j5
+        LDR     xi3, [pSrc, #3*16-4]      ;// j3
+        
+        IF  {TRUE}
+            ;// shortcut if odd values 0
+            TEQ     xi0, #0
+            TEQEQ   xi1, #0
+            TEQEQ   xi2, #0
+            TEQEQ   xi3, #0
+            BEQ     v6OddZero$_F
+        ENDIF
+        
+        ;// Store scaled even values
+        STMIA   pDest, {xi4, xi5, xi6, xi7}
+        
+        ;// Scale odd values
+        IF "$inscale"="s16"
+            ;// Perform AAN Scale
+            LDR     xi4, [pScale, #1*16-4]
+            LDR     xi5, [pScale, #7*16-4]        
+            LDR     xi6, [pScale, #5*16-4]
+            SMLABB  xi7, xi0, xi4, xit
+            SMLATT  xi0, xi0, xi4, xit
+            SMLABB  xi4, xi1, xi5, xit
+            SMLATT  xi1, xi1, xi5, xit
+            MOV     xi7, xi7, ASR #SHIFT
+            PKHBT   xi0, xi7, xi0, LSL #(16-SHIFT)
+            LDR     xi7, [pScale, #3*16-4]
+            SMLABB  xi5, xi2, xi6, xit
+            SMLATT  xi2, xi2, xi6, xit
+            MOV     xi4, xi4, ASR #SHIFT
+            PKHBT   xi1, xi4, xi1, LSL #(16-SHIFT)
+            SMLABB  xi6, xi3, xi7, xit
+            SMLATT  xi3, xi3, xi7, xit
+            MOV     xi5, xi5, ASR #SHIFT
+            PKHBT   xi2, xi5, xi2, LSL #(16-SHIFT)
+            MOV     xi6, xi6, ASR #SHIFT
+            PKHBT   xi3, xi6, xi3, LSL #(16-SHIFT)
+        ENDIF
+        IF "$inscale"="s32" ;// 32x16 mul
+            LDR     xi4, [pScale, #1*32-8]
+            LDR     xi5, [pScale, #1*32+4-8]
+            LDR     xi6, [pScale, #7*32-8]
+            LDR     xi7, [pScale, #7*32+4-8]            
+            SMLAWB  xi4, xi4, xi0, xit
+            SMLAWT  xi5, xi5, xi0, xit
+            SMLAWB  xi6, xi6, xi1, xit
+            SMLAWT  xi7, xi7, xi1, xit            
+            MOV     xi4, xi4, ASR #SHIFT
+            PKHBT   xi0, xi4, xi5, LSL #(16-SHIFT)
+            MOV     xi6, xi6, ASR #SHIFT            
+            PKHBT   xi1, xi6, xi7, LSL #(16-SHIFT)
+            LDR     xi4, [pScale, #5*32-8]
+            LDR     xi5, [pScale, #5*32+4-8]
+            LDR     xi6, [pScale, #3*32-8]
+            LDR     xi7, [pScale, #3*32+4-8]            
+            SMLAWB  xi4, xi4, xi2, xit
+            SMLAWT  xi5, xi5, xi2, xit
+            SMLAWB  xi6, xi6, xi3, xit
+            SMLAWT  xi7, xi7, xi3, xit            
+            MOV     xi4, xi4, ASR #SHIFT
+            PKHBT   xi2, xi4, xi5, LSL #(16-SHIFT)
+            MOV     xi6, xi6, ASR #SHIFT            
+            PKHBT   xi3, xi6, xi7, LSL #(16-SHIFT)
+        ENDIF
+        
+        LDR     xit, =0x00010001        ;// rounding constant
+        SADD16 xi5, xi0, xi1           ;// (j1+j7)/2
+        SHADD16 xi5, xi5, xit
+        
+        SSUB16  xi6, xi0, xi1           ;// j1-j7
+        SADD16 xi7, xi2, xi3           ;// (j5+j3)/2
+        SHADD16 xi7, xi7, xit
+        
+        SSUB16  xi4, xi2, xi3           ;// j5-j3
+        
+        SSUB16  xi3, xi5, xi7           ;// (i5-i7)/2
+        
+        PKHBT   xi0, xi6, xi4, LSL#16   ;// [i4,i6] row a
+        PKHTB   xi1, xi4, xi6, ASR#16   ;// [i4,i6] row b
+        
+        SMUADX  xi2, xi0, csPiBy8       ;// rowa by [c,s]
+        SMUADX  xi4, xi1, csPiBy8       ;// rowb by [c,s]
+        SMUSD   xi0, xi0, csPiBy8       ;// rowa by [-s,c]   
+        SMUSD   xi6, xi1, csPiBy8       ;// rowb by [-s,c]
+                
+        SMULBB  xi1, xi3, LoopRR2
+        SMULTB  xi3, xi3, LoopRR2
+                
+        PKHTB   xh4, xi4, xi2, ASR#16   ;// h4/4
+        PKHTB   xh6, xi6, xi0, ASR#16   ;// h6/4
+        SHADD16 xh7, xi5, xi7           ;// (i5+i7)/4
+                
+        ;// xi0,xi1,xi2,xi3 now free
+        ;// IStage 4,3, rows 2to3 x1/2
+        
+        MOV     xi3, xi3, LSL #1
+        PKHTB   xh5, xi3, xi1, ASR#15   ;// h5/4
+        LDRD    xi0, [pDest, #8]        ;// j2,j6 scaled
+                
+        ;// IStage 2, rows4to7
+        SSUB16  xg6, xh6, xh7
+        SSUB16  xg5, xh5, xg6        
+        SSUB16  xg4, xh4, xg5
+                
+        SSUB16  xi2, xi0, xi1           ;// (j2-j6)
+        
+        SHADD16 xi3, xi0, xi1           ;// (j2+j6)/2
+        
+        SMULBB  xi0, xi2, LoopRR2
+        SMULTB  xi2, xi2, LoopRR2
+        
+        MOV     xi2, xi2, LSL #1
+        PKHTB   xh2, xi2, xi0, ASR#15   ;// i2*sqrt(2)/4
+        
+        ;// xi0, xi1 now free
+        ;// IStage 4,3 rows 0to1 x 1/2
+        LDRD    xi0, [pDest]            ;// j0, j4 scaled
+        SSUB16  xh2, xh2, xi3
+        ADDS    LoopRR2, LoopRR2, #2<<29    ;// done two rows
+        
+        SHADD16 xh0, xi0, xi1
+        SHSUB16 xh1, xi0, xi1                
+        
+        ;// IStage 2 rows 0to3 x 1/2
+        SHSUB16 xg2, xh1, xh2
+        SHADD16 xg1, xh1, xh2
+        SHSUB16 xg3, xh0, xh3
+        SHADD16 xg0, xh0, xh3
+        
+        ;// IStage 1 all rows
+        SADD16  xf3, xg3, xg4
+        SSUB16  xf4, xg3, xg4
+        SADD16  xf2, xg2, xg5
+        SSUB16  xf5, xg2, xg5
+        SADD16  xf1, xg1, xg6
+        SSUB16  xf6, xg1, xg6
+        SADD16  xf0, xg0, xg7
+        SSUB16  xf7, xg0, xg7
+        
+        ;// Transpose, store and loop
+        PKHBT   ra01, xf0, xf1, LSL #16
+        PKHTB   rb01, xf1, xf0, ASR #16
+        
+        PKHBT   ra23, xf2, xf3, LSL #16
+        PKHTB   rb23, xf3, xf2, ASR #16
+        
+        PKHBT   ra45, xf4, xf5, LSL #16
+        PKHTB   rb45, xf5, xf4, ASR #16
+        
+        PKHBT   ra67, xf6, xf7, LSL #16
+        STMIA   pDest!, {ra01, ra23, ra45, ra67}      
+        PKHTB   rb67, xf7, xf6, ASR #16
+        STMIA   pDest!, {rb01, rb23, rb45, rb67}                              
+        BCC     v6_idct_col$_F
+        
+        SUB     pSrc, pDest, #(64*2)
+        M_LDR   pDest, ppDest
+        IF "$stride"="s"
+            M_LDR   pScale, pStride 
+        ENDIF
+        B       v6_idct_row$_F
+        
+v6OddZero$_F
+        SSUB16  xi2, xi6, xi7           ;// (j2-j6)
+        SHADD16 xi3, xi6, xi7           ;// (j2+j6)/2
+        
+        SMULBB  xi0, xi2, LoopRR2
+        SMULTB  xi2, xi2, LoopRR2
+        
+        MOV     xi2, xi2, LSL #1
+        PKHTB   xh2, xi2, xi0, ASR#15   ;// i2*sqrt(2)/4
+        SSUB16  xh2, xh2, xi3
+        
+        ;// xi0, xi1 now free
+        ;// IStage 4,3 rows 0to1 x 1/2
+        
+        SHADD16 xh0, xi4, xi5
+        SHSUB16 xh1, xi4, xi5                
+        
+        ;// IStage 2 rows 0to3 x 1/2
+        SHSUB16 xg2, xh1, xh2
+        SHADD16 xg1, xh1, xh2
+        SHSUB16 xg3, xh0, xh3
+        SHADD16 xg0, xh0, xh3
+               
+        ;// IStage 1 all rows
+        MOV  xf3, xg3
+        MOV  xf4, xg3
+        MOV  xf2, xg2
+        MOV  xf5, xg2
+        MOV  xf1, xg1
+        MOV  xf6, xg1
+        MOV  xf0, xg0
+        MOV  xf7, xg0
+        
+        ;// Transpose
+        PKHBT   ra01, xf0, xf1, LSL #16
+        PKHTB   rb01, xf1, xf0, ASR #16
+        
+        PKHBT   ra23, xf2, xf3, LSL #16
+        PKHTB   rb23, xf3, xf2, ASR #16
+        
+        PKHBT   ra45, xf4, xf5, LSL #16
+        PKHTB   rb45, xf5, xf4, ASR #16
+        
+        PKHBT   ra67, xf6, xf7, LSL #16
+        PKHTB   rb67, xf7, xf6, ASR #16
+                
+        STMIA   pDest!, {ra01, ra23, ra45, ra67}      
+        ADDS    LoopRR2, LoopRR2, #2<<29    ;// done two rows
+        STMIA   pDest!, {rb01, rb23, rb45, rb67}      
+        
+        BCC     v6_idct_col$_F
+        SUB     pSrc, pDest, #(64*2)
+        M_LDR   pDest, ppDest
+        IF "$stride"="s"
+            M_LDR   pScale, pStride 
+        ENDIF
+               
+        
+v6_idct_row$_F
+        ;// IStage 4,3, rows4to7 x1/4
+        LDR     xit, =0x00010001        ;// rounding constant
+        LDR     xi0, [pSrc, #1*16]      ;// j1
+        LDR     xi1, [pSrc, #7*16]      ;// 4*j7
+        LDR     xi2, [pSrc, #5*16]      ;// j5
+        LDR     xi3, [pSrc, #3*16]      ;// j3
+        
+        SHADD16 xi1, xi1, xit           ;// 2*j7
+        SHADD16 xi1, xi1, xit           ;// j7                
+        
+        SHADD16 xi5, xi0, xi1           ;// (j1+j7)/2
+        SSUB16  xi6, xi0, xi1           ;// j1-j7
+        SHADD16 xi7, xi2, xi3           ;// (j5+j3)/2
+        SSUB16  xi4, xi2, xi3           ;// j5-j3
+        
+        SSUB16  xi3, xi5, xi7           ;// (i5-i7)/2
+        
+        PKHBT   xi0, xi6, xi4, LSL#16   ;// [i4,i6] row a
+        PKHTB   xi1, xi4, xi6, ASR#16   ;// [i4,i6] row b
+        
+        SMUADX  xi2, xi0, csPiBy8       ;// rowa by [c,s]
+        SMUADX  xi4, xi1, csPiBy8       ;// rowb by [c,s]
+        SMUSD   xi0, xi0, csPiBy8       ;// rowa by [-s,c]   
+        SMUSD   xi6, xi1, csPiBy8       ;// rowb by [-s,c]
+                
+        SMULBB  xi1, xi3, LoopRR2
+        SMULTB  xi3, xi3, LoopRR2
+                
+        PKHTB   xh4, xi4, xi2, ASR#16   ;// h4/4
+        PKHTB   xh6, xi6, xi0, ASR#16   ;// h6/4
+        SHADD16 xh7, xi5, xi7           ;// (i5+i7)/4
+        
+        MOV     xi3, xi3, LSL #1
+        PKHTB   xh5, xi3, xi1, ASR#15   ;// h5/4
+               
+        ;// xi0,xi1,xi2,xi3 now free
+        ;// IStage 4,3, rows 2to3 x1/2
+        
+        LDR     xi0, [pSrc, #2*16]      ;// j2
+        LDR     xi1, [pSrc, #6*16]      ;// 2*j6
+        
+        ;// IStage 2, rows4to7
+        SSUB16  xg6, xh6, xh7
+        SSUB16  xg5, xh5, xg6
+        SSUB16  xg4, xh4, xg5
+        
+        SHADD16 xi1, xi1, xit           ;// j6
+        SSUB16  xi2, xi0, xi1           ;// (j2-j6)        
+        SHADD16 xi3, xi0, xi1           ;// (j2+j6)/2
+        
+        SMULBB  xi0, xi2, LoopRR2
+        SMULTB  xi2, xi2, LoopRR2
+        
+        MOV     xi2, xi2, LSL #1
+        
+        PKHTB   xh2, xi2, xi0, ASR#15   ;// i2*sqrt(2)/4
+        
+        ;// xi0, xi1 now free
+        ;// IStage 4,3 rows 0to1 x 1/2
+        LDR     xi1, [pSrc, #4*16]      ;// j4
+        LDR     xi0, [pSrc], #4         ;// j0
+
+        SSUB16  xh2, xh2, xi3
+        ADDS    LoopRR2, LoopRR2, #2<<29    ;// done two rows
+        
+        ADD     xi0, xi0, xit, LSL #2   ;// ensure correct round
+        SHADD16 xh0, xi0, xi1           ;// of DC result
+        SHSUB16 xh1, xi0, xi1
+                
+        ;// IStage 2 rows 0to3 x 1/2
+        SHSUB16 xg2, xh1, xh2
+        SHADD16 xg1, xh1, xh2
+        SHSUB16 xg3, xh0, xh3
+        SHADD16 xg0, xh0, xh3
+        
+        ;// IStage 1 all rows
+        SHADD16 xf3, xg3, xg4
+        SHSUB16 xf4, xg3, xg4
+        SHADD16 xf2, xg2, xg5
+        SHSUB16 xf5, xg2, xg5
+        SHADD16 xf1, xg1, xg6
+        SHSUB16 xf6, xg1, xg6
+        SHADD16 xf0, xg0, xg7
+        SHSUB16 xf7, xg0, xg7
+        
+        ;// Saturate
+        IF ("$outsize"="u8")
+            USAT16  xf0, #8, xf0
+            USAT16  xf1, #8, xf1
+            USAT16  xf2, #8, xf2
+            USAT16  xf3, #8, xf3
+            USAT16  xf4, #8, xf4
+            USAT16  xf5, #8, xf5
+            USAT16  xf6, #8, xf6
+            USAT16  xf7, #8, xf7        
+        ENDIF
+        IF ("$outsize"="s9")
+            SSAT16  xf0, #9, xf0
+            SSAT16  xf1, #9, xf1
+            SSAT16  xf2, #9, xf2
+            SSAT16  xf3, #9, xf3
+            SSAT16  xf4, #9, xf4
+            SSAT16  xf5, #9, xf5
+            SSAT16  xf6, #9, xf6
+            SSAT16  xf7, #9, xf7        
+        ENDIF
+        
+        ;// Transpose to Row, Pack and store
+        IF ("$outsize"="u8")
+            ORR     xf0, xf0, xf1, LSL #8 ;// [ b1 b0 a1 a0 ]
+            ORR     xf2, xf2, xf3, LSL #8 ;// [ b3 b2 a3 a2 ]
+            ORR     xf4, xf4, xf5, LSL #8 ;// [ b5 b4 a5 a4 ]
+            ORR     xf6, xf6, xf7, LSL #8 ;// [ b7 b6 a7 a6 ]
+            PKHBT   ra01, xf0, xf2, LSL #16
+            PKHTB   rb01, xf2, xf0, ASR #16
+            PKHBT   ra23, xf4, xf6, LSL #16
+            PKHTB   rb23, xf6, xf4, ASR #16
+            STMIA   pDest, {ra01, ra23}
+            IF "$stride"="s"
+                ADD     pDest, pDest, pScale
+                STMIA   pDest, {rb01, rb23}
+                ADD     pDest, pDest, pScale
+            ELSE                
+                ADD     pDest, pDest, #($stride)
+                STMIA   pDest, {rb01, rb23}
+                ADD     pDest, pDest, #($stride)
+            ENDIF
+        ENDIF
+        IF ("$outsize"="s9"):LOR:("$outsize"="s16")        
+            PKHBT   ra01, xf0, xf1, LSL #16
+            PKHTB   rb01, xf1, xf0, ASR #16
+        
+            PKHBT   ra23, xf2, xf3, LSL #16
+            PKHTB   rb23, xf3, xf2, ASR #16
+            
+            PKHBT   ra45, xf4, xf5, LSL #16
+            PKHTB   rb45, xf5, xf4, ASR #16
+            
+            PKHBT   ra67, xf6, xf7, LSL #16
+            PKHTB   rb67, xf7, xf6, ASR #16
+            
+            STMIA   pDest, {ra01, ra23, ra45, ra67}      
+            IF "$stride"="s"
+                ADD     pDest, pDest, pScale
+                STMIA   pDest, {rb01, rb23, rb45, rb67}      
+                ADD     pDest, pDest, pScale
+            ELSE                
+                ADD     pDest, pDest, #($stride)
+                STMIA   pDest, {rb01, rb23, rb45, rb67}      
+                ADD     pDest, pDest, #($stride)
+            ENDIF
+        ENDIF
+        
+        BCC     v6_idct_row$_F
+        ENDIF ;// ARM1136JS
+
+
+        IF CortexA8
+        
+Src0            EQU  7              
+Src1            EQU  8              
+Src2            EQU  9              
+Src3            EQU  10              
+Src4            EQU  11              
+Src5            EQU  12              
+Src6            EQU  13
+Src7            EQU  14
+Tmp             EQU  15
+
+qXj0            QN Src0.S16 
+qXj1            QN Src1.S16
+qXj2            QN Src2.S16
+qXj3            QN Src3.S16
+qXj4            QN Src4.S16
+qXj5            QN Src5.S16
+qXj6            QN Src6.S16
+qXj7            QN Src7.S16
+qXjt            QN Tmp.S16
+
+dXj0lo          DN (Src0*2).S16
+dXj0hi          DN (Src0*2+1).S16
+dXj1lo          DN (Src1*2).S16
+dXj1hi          DN (Src1*2+1).S16
+dXj2lo          DN (Src2*2).S16
+dXj2hi          DN (Src2*2+1).S16
+dXj3lo          DN (Src3*2).S16
+dXj3hi          DN (Src3*2+1).S16
+dXj4lo          DN (Src4*2).S16
+dXj4hi          DN (Src4*2+1).S16
+dXj5lo          DN (Src5*2).S16
+dXj5hi          DN (Src5*2+1).S16
+dXj6lo          DN (Src6*2).S16
+dXj6hi          DN (Src6*2+1).S16
+dXj7lo          DN (Src7*2).S16
+dXj7hi          DN (Src7*2+1).S16
+dXjtlo          DN (Tmp*2).S16
+dXjthi          DN (Tmp*2+1).S16
+
+qXi0            QN qXj0
+qXi1            QN qXj4
+qXi2            QN qXj2
+qXi3            QN qXj7
+qXi4            QN qXj5
+qXi5            QN qXjt
+qXi6            QN qXj1
+qXi7            QN qXj6
+qXit            QN qXj3
+
+dXi0lo          DN dXj0lo
+dXi0hi          DN dXj0hi
+dXi1lo          DN dXj4lo
+dXi1hi          DN dXj4hi
+dXi2lo          DN dXj2lo
+dXi2hi          DN dXj2hi
+dXi3lo          DN dXj7lo
+dXi3hi          DN dXj7hi
+dXi4lo          DN dXj5lo
+dXi4hi          DN dXj5hi
+dXi5lo          DN dXjtlo
+dXi5hi          DN dXjthi
+dXi6lo          DN dXj1lo
+dXi6hi          DN dXj1hi
+dXi7lo          DN dXj6lo
+dXi7hi          DN dXj6hi
+dXitlo          DN dXj3lo
+dXithi          DN dXj3hi
+
+qXh0            QN qXit
+qXh1            QN qXi0
+qXh2            QN qXi2
+qXh3            QN qXi3
+qXh4            QN qXi7
+qXh5            QN qXi5
+qXh6            QN qXi4
+qXh7            QN qXi1
+qXht            QN qXi6
+
+dXh0lo          DN dXitlo
+dXh0hi          DN dXithi
+dXh1lo          DN dXi0lo
+dXh1hi          DN dXi0hi
+dXh2lo          DN dXi2lo
+dXh2hi          DN dXi2hi
+dXh3lo          DN dXi3lo
+dXh3hi          DN dXi3hi
+dXh4lo          DN dXi7lo
+dXh4hi          DN dXi7hi
+dXh5lo          DN dXi5lo
+dXh5hi          DN dXi5hi
+dXh6lo          DN dXi4lo
+dXh6hi          DN dXi4hi
+dXh7lo          DN dXi1lo
+dXh7hi          DN dXi1hi
+dXhtlo          DN dXi6lo
+dXhthi          DN dXi6hi
+
+qXg0            QN qXh2
+qXg1            QN qXht
+qXg2            QN qXh1
+qXg3            QN qXh0
+qXg4            QN qXh4
+qXg5            QN qXh5
+qXg6            QN qXh6
+qXg7            QN qXh7
+qXgt            QN qXh3
+
+qXf0            QN qXg6
+qXf1            QN qXg5
+qXf2            QN qXg4
+qXf3            QN qXgt
+qXf4            QN qXg3
+qXf5            QN qXg2
+qXf6            QN qXg1
+qXf7            QN qXg0
+qXft            QN qXg7
+
+
+qXt0            QN 1.S32
+qXt1            QN 2.S32
+qT0lo           QN 1.S32         
+qT0hi           QN 2.S32         
+qT1lo           QN 3.S32         
+qT1hi           QN 4.S32         
+qScalelo        QN 5.S32        ;// used to read post scale values
+qScalehi        QN 6.S32
+qTemp0          QN 5.S32         
+qTemp1          QN 6.S32    
+
+
+Scale1          EQU 6
+Scale2          EQU 15
+qScale1         QN Scale1.S16     
+qScale2         QN Scale2.S16     
+dScale1lo       DN (Scale1*2).S16     
+dScale1hi       DN (Scale1*2+1).S16
+dScale2lo       DN (Scale2*2).S16     
+dScale2hi       DN (Scale2*2+1).S16
+
+dCoefs          DN 0.S16        ;// Scale coefficients in format {[0] [C] [S] [InvSqrt2]}
+InvSqrt2        DN dCoefs[0]    ;// 1/sqrt(2) in Q15
+S               DN dCoefs[1]    ;// Sin(PI/8) in Q15
+C               DN dCoefs[2]    ;// Cos(PI/8) in Q15
+
+pTemp           RN 12
+
+                
+        IMPORT  armCOMM_IDCTCoef
+                    
+        VLD1        {qXj0,qXj1}, [pSrc @64]!
+        VLD1        {qXj2,qXj3}, [pSrc @64]!
+        VLD1        {qXj4,qXj5}, [pSrc @64]!
+        VLD1        {qXj6,qXj7}, [pSrc @64]!
+        
+        ;// Load PreScale and multiply with Src
+        ;// IStage 4
+        
+        IF "$inscale"="s16"                         ;// 16X16 Mul
+            M_IDCT_PRESCALE16
+        ENDIF
+        
+        IF "$inscale"="s32"                         ;// 32X32 ,ul
+            M_IDCT_PRESCALE32
+        ENDIF
+
+        ;// IStage 3
+        VQDMULH     qXi2, qXi2, InvSqrt2            ;// i2/sqrt(2)
+        VHADD       qXh0, qXi0, qXi1                ;// (i0+i1)/2
+        VHSUB       qXh1, qXi0, qXi1                ;// (i0-i1)/2
+        VHADD       qXh7, qXi5, qXi7                ;// (i5+i7)/4
+        VSUB        qXh5, qXi5, qXi7                ;// (i5-i7)/2
+        VQDMULH     qXh5, qXh5, InvSqrt2            ;// h5/sqrt(2)
+        VSUB        qXh2, qXi2, qXi3                ;// h2, h3
+
+        VMULL       qXt0, dXi4lo, C                 ;// c*i4
+        VMLAL       qXt0, dXi6lo, S                 ;// c*i4+s*i6
+        VMULL       qXt1, dXi4hi, C
+        VMLAL       qXt1, dXi6hi, S
+        VSHRN       dXh4lo, qXt0, #16               ;// h4
+        VSHRN       dXh4hi, qXt1, #16
+        
+        VMULL       qXt0, dXi6lo, C                 ;// c*i6
+        VMLSL       qXt0, dXi4lo, S                 ;// -s*i4 + c*h6
+        VMULL       qXt1, dXi6hi, C
+        VMLSL       qXt1, dXi4hi, S
+        VSHRN       dXh6lo, qXt0, #16               ;// h6
+        VSHRN       dXh6hi, qXt1, #16
+        
+        ;// IStage 2
+        VSUB        qXg6, qXh6, qXh7
+        VSUB        qXg5, qXh5, qXg6
+        VSUB        qXg4, qXh4, qXg5
+        VHADD       qXg1, qXh1, qXh2        ;// (h1+h2)/2
+        VHSUB       qXg2, qXh1, qXh2        ;// (h1-h2)/2
+        VHADD       qXg0, qXh0, qXh3        ;// (h0+h3)/2
+        VHSUB       qXg3, qXh0, qXh3        ;// (h0-h3)/2
+
+        ;// IStage 1 all rows
+        VADD        qXf3, qXg3, qXg4        
+        VSUB        qXf4, qXg3, qXg4        
+        VADD        qXf2, qXg2, qXg5        
+        VSUB        qXf5, qXg2, qXg5        
+        VADD        qXf1, qXg1, qXg6
+        VSUB        qXf6, qXg1, qXg6        
+        VADD        qXf0, qXg0, qXg7
+        VSUB        qXf7, qXg0, qXg7      
+
+        ;// Transpose, store and loop
+XTR0            EQU Src5
+XTR1            EQU Tmp
+XTR2            EQU Src6
+XTR3            EQU Src7
+XTR4            EQU Src3
+XTR5            EQU Src0
+XTR6            EQU Src1
+XTR7            EQU Src2
+XTRt            EQU Src4
+                
+qA0             QN  XTR0.S32  ;// for XTRpose
+qA1             QN  XTR1.S32
+qA2             QN  XTR2.S32
+qA3             QN  XTR3.S32
+qA4             QN  XTR4.S32
+qA5             QN  XTR5.S32
+qA6             QN  XTR6.S32
+qA7             QN  XTR7.S32
+
+dB0             DN  XTR0*2+1      ;// for using VSWP
+dB1             DN  XTR1*2+1
+dB2             DN  XTR2*2+1
+dB3             DN  XTR3*2+1
+dB4             DN  XTR4*2
+dB5             DN  XTR5*2
+dB6             DN  XTR6*2
+dB7             DN  XTR7*2
+
+          
+        VTRN        qXf0, qXf1
+        VTRN        qXf2, qXf3
+        VTRN        qXf4, qXf5
+        VTRN        qXf6, qXf7
+        VTRN        qA0, qA2
+        VTRN        qA1, qA3
+        VTRN        qA4, qA6
+        VTRN        qA5, qA7        
+        VSWP        dB0, dB4
+        VSWP        dB1, dB5
+        VSWP        dB2, dB6
+        VSWP        dB3, dB7
+        
+
+qYj0            QN qXf0
+qYj1            QN qXf1
+qYj2            QN qXf2
+qYj3            QN qXf3
+qYj4            QN qXf4
+qYj5            QN qXf5
+qYj6            QN qXf6
+qYj7            QN qXf7
+qYjt            QN qXft
+
+dYj0lo          DN (XTR0*2).S16
+dYj0hi          DN (XTR0*2+1).S16
+dYj1lo          DN (XTR1*2).S16
+dYj1hi          DN (XTR1*2+1).S16
+dYj2lo          DN (XTR2*2).S16
+dYj2hi          DN (XTR2*2+1).S16
+dYj3lo          DN (XTR3*2).S16
+dYj3hi          DN (XTR3*2+1).S16
+dYj4lo          DN (XTR4*2).S16
+dYj4hi          DN (XTR4*2+1).S16
+dYj5lo          DN (XTR5*2).S16
+dYj5hi          DN (XTR5*2+1).S16
+dYj6lo          DN (XTR6*2).S16
+dYj6hi          DN (XTR6*2+1).S16
+dYj7lo          DN (XTR7*2).S16
+dYj7hi          DN (XTR7*2+1).S16
+dYjtlo          DN (XTRt*2).S16
+dYjthi          DN (XTRt*2+1).S16
+
+qYi0            QN qYj0
+qYi1            QN qYj4
+qYi2            QN qYj2
+qYi3            QN qYj7
+qYi4            QN qYj5
+qYi5            QN qYjt
+qYi6            QN qYj1
+qYi7            QN qYj6
+qYit            QN qYj3
+
+dYi0lo          DN dYj0lo
+dYi0hi          DN dYj0hi
+dYi1lo          DN dYj4lo
+dYi1hi          DN dYj4hi
+dYi2lo          DN dYj2lo
+dYi2hi          DN dYj2hi
+dYi3lo          DN dYj7lo
+dYi3hi          DN dYj7hi
+dYi4lo          DN dYj5lo
+dYi4hi          DN dYj5hi
+dYi5lo          DN dYjtlo
+dYi5hi          DN dYjthi
+dYi6lo          DN dYj1lo
+dYi6hi          DN dYj1hi
+dYi7lo          DN dYj6lo
+dYi7hi          DN dYj6hi
+dYitlo          DN dYj3lo
+dYithi          DN dYj3hi
+
+qYh0            QN qYit
+qYh1            QN qYi0
+qYh2            QN qYi2
+qYh3            QN qYi3
+qYh4            QN qYi7
+qYh5            QN qYi5
+qYh6            QN qYi4
+qYh7            QN qYi1
+qYht            QN qYi6
+
+dYh0lo          DN dYitlo
+dYh0hi          DN dYithi
+dYh1lo          DN dYi0lo
+dYh1hi          DN dYi0hi
+dYh2lo          DN dYi2lo
+dYh2hi          DN dYi2hi
+dYh3lo          DN dYi3lo
+dYh3hi          DN dYi3hi
+dYh4lo          DN dYi7lo
+dYh4hi          DN dYi7hi
+dYh5lo          DN dYi5lo
+dYh5hi          DN dYi5hi
+dYh6lo          DN dYi4lo
+dYh6hi          DN dYi4hi
+dYh7lo          DN dYi1lo
+dYh7hi          DN dYi1hi
+dYhtlo          DN dYi6lo
+dYhthi          DN dYi6hi
+
+qYg0            QN qYh2
+qYg1            QN qYht
+qYg2            QN qYh1
+qYg3            QN qYh0
+qYg4            QN qYh4
+qYg5            QN qYh5
+qYg6            QN qYh6
+qYg7            QN qYh7
+qYgt            QN qYh3
+
+qYf0            QN qYg6
+qYf1            QN qYg5
+qYf2            QN qYg4
+qYf3            QN qYgt
+qYf4            QN qYg3
+qYf5            QN qYg2
+qYf6            QN qYg1
+qYf7            QN qYg0
+qYft            QN qYg7
+
+        VRSHR       qYj7, qYj7, #2
+        VRSHR       qYj6, qYj6, #1
+        
+        VHADD       qYi5, qYj1, qYj7        ;// i5 = (j1+j7)/2
+        VSUB        qYi6, qYj1, qYj7        ;// i6 = j1-j7
+        VHADD       qYi3, qYj2, qYj6        ;// i3 = (j2+j6)/2
+        VSUB        qYi2, qYj2, qYj6        ;// i2 = j2-j6
+        VHADD       qYi7, qYj5, qYj3        ;// i7 = (j5+j3)/2
+        VSUB        qYi4, qYj5, qYj3        ;// i4 = j5-j3
+
+        VQDMULH     qYi2, qYi2, InvSqrt2    ;// i2/sqrt(2)
+        ;// IStage 4,3 rows 0to1 x 1/2
+        
+        MOV         pTemp, #0x4             ;// ensure correct round
+        VDUP        qScale1, pTemp           ;// of DC result
+        VADD        qYi0, qYi0, qScale1
+        
+        VHADD       qYh0, qYi0, qYi1        ;// (i0+i1)/2
+        VHSUB       qYh1, qYi0, qYi1        ;// (i0-i1)/2
+
+        VHADD       qYh7, qYi5, qYi7        ;// (i5+i7)/4
+        VSUB        qYh5, qYi5, qYi7        ;// (i5-i7)/2
+        VSUB        qYh2, qYi2, qYi3        ;// h2, h3
+        VQDMULH     qYh5, qYh5, InvSqrt2    ;// h5/sqrt(2)
+
+        VMULL       qXt0, dYi4lo, C         ;// c*i4
+        VMLAL       qXt0, dYi6lo, S         ;// c*i4+s*i6
+        VMULL       qXt1, dYi4hi, C
+        VMLAL       qXt1, dYi6hi, S
+        VSHRN       dYh4lo, qXt0, #16       ;// h4
+        VSHRN       dYh4hi, qXt1, #16
+        
+        VMULL       qXt0, dYi6lo, C         ;// c*i6
+        VMLSL       qXt0, dYi4lo, S         ;// -s*i4 + c*h6
+        VMULL       qXt1, dYi6hi, C
+        VMLSL       qXt1, dYi4hi, S
+        VSHRN       dYh6lo, qXt0, #16       ;// h6
+        VSHRN       dYh6hi, qXt1, #16
+        
+        VSUB        qYg6, qYh6, qYh7
+        VSUB        qYg5, qYh5, qYg6
+        VSUB        qYg4, qYh4, qYg5
+        
+        ;// IStage 2 rows 0to3 x 1/2
+        VHADD       qYg1, qYh1, qYh2        ;// (h1+h2)/2
+        VHSUB       qYg2, qYh1, qYh2        ;// (h1-h2)/2
+        VHADD       qYg0, qYh0, qYh3        ;// (h0+h3)/2
+        VHSUB       qYg3, qYh0, qYh3        ;// (h0-h3)/2
+        
+
+        ;// IStage 1 all rows
+        VHADD        qYf3, qYg3, qYg4        
+        VHSUB        qYf4, qYg3, qYg4        
+        VHADD        qYf2, qYg2, qYg5        
+        VHSUB        qYf5, qYg2, qYg5        
+        VHADD        qYf1, qYg1, qYg6
+        VHSUB        qYf6, qYg1, qYg6        
+        VHADD        qYf0, qYg0, qYg7
+        VHSUB        qYf7, qYg0, qYg7      
+
+YTR0            EQU Src0
+YTR1            EQU Src4
+YTR2            EQU Src1
+YTR3            EQU Src2
+YTR4            EQU Src7
+YTR5            EQU Src5
+YTR6            EQU Tmp
+YTR7            EQU Src6
+YTRt            EQU Src3
+
+qC0             QN  YTR0.S32                ;// for YTRpose
+qC1             QN  YTR1.S32
+qC2             QN  YTR2.S32
+qC3             QN  YTR3.S32
+qC4             QN  YTR4.S32
+qC5             QN  YTR5.S32
+qC6             QN  YTR6.S32
+qC7             QN  YTR7.S32
+
+dD0             DN  YTR0*2+1                ;// for using VSWP
+dD1             DN  YTR1*2+1
+dD2             DN  YTR2*2+1
+dD3             DN  YTR3*2+1
+dD4             DN  YTR4*2
+dD5             DN  YTR5*2
+dD6             DN  YTR6*2
+dD7             DN  YTR7*2
+          
+        VTRN        qYf0, qYf1
+        VTRN        qYf2, qYf3
+        VTRN        qYf4, qYf5
+        VTRN        qYf6, qYf7
+        VTRN        qC0, qC2
+        VTRN        qC1, qC3
+        VTRN        qC4, qC6
+        VTRN        qC5, qC7        
+        VSWP        dD0, dD4
+        VSWP        dD1, dD5
+        VSWP        dD2, dD6
+        VSWP        dD3, dD7
+
+        
+dYf0U8          DN YTR0*2.U8
+dYf1U8          DN YTR1*2.U8
+dYf2U8          DN YTR2*2.U8
+dYf3U8          DN YTR3*2.U8
+dYf4U8          DN YTR4*2.U8
+dYf5U8          DN YTR5*2.U8
+dYf6U8          DN YTR6*2.U8
+dYf7U8          DN YTR7*2.U8
+        
+        ;//
+        ;// Do saturation if outsize is other than S16
+        ;//
+        
+        IF ("$outsize"="u8")
+            ;// Output range [0-255]
+            VQMOVN            dYf0U8, qYf0
+            VQMOVN            dYf1U8, qYf1
+            VQMOVN            dYf2U8, qYf2
+            VQMOVN            dYf3U8, qYf3
+            VQMOVN            dYf4U8, qYf4
+            VQMOVN            dYf5U8, qYf5
+            VQMOVN            dYf6U8, qYf6
+            VQMOVN            dYf7U8, qYf7
+        ENDIF
+        
+        IF ("$outsize"="s9")
+            ;// Output range [-256 to +255]
+            VQSHL            qYf0, qYf0, #16-9
+            VQSHL            qYf1, qYf1, #16-9
+            VQSHL            qYf2, qYf2, #16-9
+            VQSHL            qYf3, qYf3, #16-9
+            VQSHL            qYf4, qYf4, #16-9
+            VQSHL            qYf5, qYf5, #16-9
+            VQSHL            qYf6, qYf6, #16-9
+            VQSHL            qYf7, qYf7, #16-9
+            
+            VSHR             qYf0, qYf0, #16-9
+            VSHR             qYf1, qYf1, #16-9
+            VSHR             qYf2, qYf2, #16-9
+            VSHR             qYf3, qYf3, #16-9
+            VSHR             qYf4, qYf4, #16-9
+            VSHR             qYf5, qYf5, #16-9
+            VSHR             qYf6, qYf6, #16-9
+            VSHR             qYf7, qYf7, #16-9
+        ENDIF
+
+        ;// Store output depending on the Stride size
+        IF "$stride"="s"
+            VST1        qYf0, [pDest @64], Stride
+            VST1        qYf1, [pDest @64], Stride
+            VST1        qYf2, [pDest @64], Stride
+            VST1        qYf3, [pDest @64], Stride
+            VST1        qYf4, [pDest @64], Stride
+            VST1        qYf5, [pDest @64], Stride
+            VST1        qYf6, [pDest @64], Stride
+            VST1        qYf7, [pDest @64]            
+        ELSE
+            IF ("$outsize"="u8")
+                VST1        dYf0U8, [pDest @64], #8
+                VST1        dYf1U8, [pDest @64], #8
+                VST1        dYf2U8, [pDest @64], #8
+                VST1        dYf3U8, [pDest @64], #8
+                VST1        dYf4U8, [pDest @64], #8
+                VST1        dYf5U8, [pDest @64], #8
+                VST1        dYf6U8, [pDest @64], #8
+                VST1        dYf7U8, [pDest @64]
+            ELSE
+                ;// ("$outsize"="s9") or ("$outsize"="s16")
+                VST1        qYf0, [pDest @64], #16
+                VST1        qYf1, [pDest @64], #16
+                VST1        qYf2, [pDest @64], #16
+                VST1        qYf3, [pDest @64], #16
+                VST1        qYf4, [pDest @64], #16
+                VST1        qYf5, [pDest @64], #16
+                VST1        qYf6, [pDest @64], #16
+                VST1        qYf7, [pDest @64]
+            ENDIF
+        
+        ENDIF
+
+
+
+        ENDIF ;// CortexA8
+
+
+
+        MEND        
+
+        ;// Scale TWO input rows with TWO rows of 16 bit scale values
+        ;//
+        ;// This macro is used by M_IDCT_PRESCALE16 to pre-scale one row
+        ;// input (Eight input values) with one row of scale values. Also 
+        ;// Loads next scale values from pScale, if $LastRow flag is not set.
+        ;//
+        ;// Input Registers:
+        ;//
+        ;// $dAlo           - Input D register with first four S16 values of row n
+        ;// $dAhi           - Input D register with next four S16 values of row n
+        ;// $dBlo           - Input D register with first four S16 values of row n+1
+        ;// $dBhi           - Input D register with next four S16 values of row n+1
+        ;// pScale          - Pointer to next row of scale values
+        ;// qT0lo           - Temporary scratch register
+        ;// qT0hi           - Temporary scratch register
+        ;// qT1lo           - Temporary scratch register
+        ;// qT1hi           - Temporary scratch register
+        ;// dScale1lo       - Scale value of row n
+        ;// dScale1hi       - Scale value of row n
+        ;// dScale2lo       - Scale value of row n+1
+        ;// dScale2hi       - Scale value of row n+1
+        ;//
+        ;// Input Flag
+        ;//
+        ;// $LastRow        - Flag to indicate whether current row is last row
+        ;//
+        ;// Output Registers:
+        ;//
+        ;// $dAlo           - Scaled output values (first four S16 of row n)
+        ;// $dAhi           - Scaled output values (next four S16 of row n)
+        ;// $dBlo           - Scaled output values (first four S16 of row n+1)
+        ;// $dBhi           - Scaled output values (next four S16 of row n+1)
+        ;// qScale1         - Scale values for next row
+        ;// qScale2         - Scale values for next row+1
+        ;// pScale          - Pointer to next row of scale values
+        ;//
+        MACRO
+        M_IDCT_SCALE16 $dAlo, $dAhi, $dBlo, $dBhi, $LastRow
+        VMULL       qT0lo, $dAlo, dScale1lo
+        VMULL       qT0hi, $dAhi, dScale1hi
+        VMULL       qT1lo, $dBlo, dScale2lo
+        VMULL       qT1hi, $dBhi, dScale2hi
+        IF "$LastRow"="0"
+            VLD1        qScale1, [pScale], #16  ;// Load scale for row n+1
+            VLD1        qScale2, [pScale], #16  ;// Load scale for row n+2
+        ENDIF
+        VQRSHRN       $dAlo, qT0lo, #12        
+        VQRSHRN       $dAhi, qT0hi, #12        
+        VQRSHRN       $dBlo, qT1lo, #12        
+        VQRSHRN       $dBhi, qT1hi, #12        
+        MEND
+
+        ;// Scale 8x8 block input values with 16 bit scale values
+        ;//
+        ;// This macro is used to pre-scale block of 8x8 input.
+        ;// This also do the Ist stage transformations of IDCT.
+        ;//
+        ;// Input Registers:
+        ;//
+        ;// dXjnlo          - n th input D register with first four S16 values
+        ;// dXjnhi          - n th input D register with next four S16 values
+        ;// qXjn            - n th input Q register with eight S16 values
+        ;// pScale          - Pointer to scale values
+        ;//
+        ;// Output Registers:
+        ;//
+        ;// qXin            - n th output Q register with eight S16 output values of 1st stage
+        ;//
+        MACRO
+        M_IDCT_PRESCALE16
+        VLD1        qScale1, [pScale], #16      ;// Load Pre scale for row 0
+        VLD1        qScale2, [pScale], #16      ;// Load Pre scale for row 0
+        M_IDCT_SCALE16 dXj0lo, dXj0hi, dXj1lo, dXj1hi, 0        ;// Pre scale row 0 & 1
+        M_IDCT_SCALE16 dXj2lo, dXj2hi, dXj3lo, dXj3hi, 0        
+        M_IDCT_SCALE16 dXj4lo, dXj4hi, dXj5lo, dXj5hi, 0        
+        M_IDCT_SCALE16 dXj6lo, dXj6hi, dXj7lo, dXj7hi, 1        
+        VHADD       qXi5, qXj1, qXj7            ;// (j1+j7)/2
+        VSUB        qXi6, qXj1, qXj7            ;// j1-j7
+        LDR         pSrc, =armCOMM_IDCTCoef ;// Address of DCT inverse AAN constants
+        VHADD       qXi3, qXj2, qXj6            ;// (j2+j6)/2
+        VSUB        qXi2, qXj2, qXj6            ;// j2-j6
+        VLDR        dCoefs, [pSrc]              ;// Load DCT inverse AAN constants
+        VHADD       qXi7, qXj5, qXj3            ;// (j5+j3)/2
+        VSUB        qXi4, qXj5, qXj3            ;// j5-j3
+        MEND    
+        
+        
+        ;// Scale 8x8 block input values with 32 bit scale values
+        ;//
+        ;// This macro is used to pre-scale block of 8x8 input.
+        ;// This also do the Ist stage transformations of IDCT.
+        ;//
+        ;// Input Registers:
+        ;//
+        ;// dXjnlo          - n th input D register with first four S16 values
+        ;// dXjnhi          - n th input D register with next four S16 values
+        ;// qXjn            - n th input Q register with eight S16 values
+        ;// pScale          - Pointer to 32bit scale values in Q23 format
+        ;//
+        ;// Output Registers:
+        ;//
+        ;// dXinlo          - n th output D register with first four S16 output values of 1st stage
+        ;// dXinhi          - n th output D register with next four S16 output values of 1st stage
+        ;//
+        MACRO
+        M_IDCT_PRESCALE32
+qScale0lo       QN 0.S32
+qScale0hi       QN 1.S32
+qScale1lo       QN 2.S32
+qScale1hi       QN 3.S32
+qScale2lo       QN qScale1lo
+qScale2hi       QN qScale1hi
+qScale3lo       QN qScale1lo
+qScale3hi       QN qScale1hi
+qScale4lo       QN qScale1lo
+qScale4hi       QN qScale1hi
+qScale5lo       QN qScale0lo
+qScale5hi       QN qScale0hi
+qScale6lo       QN qScale0lo
+qScale6hi       QN qScale0hi
+qScale7lo       QN qScale0lo
+qScale7hi       QN qScale0hi
+
+qSrc0lo         QN 4.S32
+qSrc0hi         QN 5.S32
+qSrc1lo         QN 6.S32
+qSrc1hi         QN Src4.S32
+qSrc2lo         QN qSrc0lo
+qSrc2hi         QN qSrc0hi
+qSrc3lo         QN qSrc0lo
+qSrc3hi         QN qSrc0hi
+qSrc4lo         QN qSrc0lo
+qSrc4hi         QN qSrc0hi
+qSrc5lo         QN qSrc1lo
+qSrc5hi         QN qSrc1hi
+qSrc6lo         QN qSrc1lo
+qSrc6hi         QN qSrc1hi
+qSrc7lo         QN qSrc0lo
+qSrc7hi         QN qSrc0hi
+
+qRes17lo        QN qScale0lo
+qRes17hi        QN qScale0hi
+qRes26lo        QN qScale0lo
+qRes26hi        QN qScale0hi
+qRes53lo        QN qScale0lo
+qRes53hi        QN qScale0hi
+
+            ADD         pTemp, pScale, #4*8*7           ;// Address of  pScale[7]
+            
+            ;// Row 0
+            VLD1        {qScale0lo, qScale0hi}, [pScale]!
+            VSHLL       qSrc0lo, dXj0lo, #(12-1)
+            VSHLL       qSrc0hi, dXj0hi, #(12-1)            
+            VLD1        {qScale1lo, qScale1hi}, [pScale]!
+            VQRDMULH    qSrc0lo, qScale0lo, qSrc0lo
+            VQRDMULH    qSrc0hi, qScale0hi, qSrc0hi
+            VLD1        {qScale7lo, qScale7hi}, [pTemp]!
+            VSHLL       qSrc1lo, dXj1lo, #(12-1)
+            VSHLL       qSrc1hi, dXj1hi, #(12-1)            
+            VMOVN       dXi0lo, qSrc0lo                 ;// Output i0
+            VMOVN       dXi0hi, qSrc0hi
+            VSHLL       qSrc7lo, dXj7lo, #(12-1)
+            VSHLL       qSrc7hi, dXj7hi, #(12-1)
+            SUB         pTemp, pTemp, #((16*2)+(4*8*1))
+            VQRDMULH    qSrc1lo, qScale1lo, qSrc1lo
+            VQRDMULH    qSrc1hi, qScale1hi, qSrc1hi
+            VQRDMULH    qSrc7lo, qScale7lo, qSrc7lo
+            VQRDMULH    qSrc7hi, qScale7hi, qSrc7hi
+            VLD1        {qScale2lo, qScale2hi}, [pScale]!
+
+            ;// Row 1 & 7
+            VHADD       qRes17lo, qSrc1lo, qSrc7lo      ;// (j1+j7)/2
+            VHADD       qRes17hi, qSrc1hi, qSrc7hi      ;// (j1+j7)/2
+            VMOVN       dXi5lo, qRes17lo                ;// Output i5
+            VMOVN       dXi5hi, qRes17hi              
+            VSUB        qRes17lo, qSrc1lo, qSrc7lo      ;// j1-j7
+            VSUB        qRes17hi, qSrc1hi, qSrc7hi      ;// j1-j7
+            VMOVN       dXi6lo, qRes17lo                ;// Output i6
+            VMOVN       dXi6hi, qRes17hi      
+            VSHLL       qSrc2lo, dXj2lo, #(12-1)
+            VSHLL       qSrc2hi, dXj2hi, #(12-1)
+            VLD1        {qScale6lo, qScale6hi}, [pTemp]!
+            VSHLL       qSrc6lo, dXj6lo, #(12-1)
+            VSHLL       qSrc6hi, dXj6hi, #(12-1)
+            SUB         pTemp, pTemp, #((16*2)+(4*8*1))
+            VQRDMULH    qSrc2lo, qScale2lo, qSrc2lo
+            VQRDMULH    qSrc2hi, qScale2hi, qSrc2hi
+            VQRDMULH    qSrc6lo, qScale6lo, qSrc6lo
+            VQRDMULH    qSrc6hi, qScale6hi, qSrc6hi
+            VLD1        {qScale3lo, qScale3hi}, [pScale]!
+
+            ;// Row 2 & 6
+            VHADD       qRes26lo, qSrc2lo, qSrc6lo      ;// (j2+j6)/2
+            VHADD       qRes26hi, qSrc2hi, qSrc6hi      ;// (j2+j6)/2
+            VMOVN       dXi3lo, qRes26lo                ;// Output i3
+            VMOVN       dXi3hi, qRes26hi              
+            VSUB        qRes26lo, qSrc2lo, qSrc6lo      ;// j2-j6
+            VSUB        qRes26hi, qSrc2hi, qSrc6hi      ;// j2-j6
+            VMOVN       dXi2lo, qRes26lo                ;// Output i2
+            VMOVN       dXi2hi, qRes26hi      
+            VSHLL       qSrc3lo, dXj3lo, #(12-1)
+            VSHLL       qSrc3hi, dXj3hi, #(12-1)
+            VLD1        {qScale5lo, qScale5hi}, [pTemp]!
+            VSHLL       qSrc5lo, dXj5lo, #(12-1)
+            VSHLL       qSrc5hi, dXj5hi, #(12-1)
+            VQRDMULH    qSrc3lo, qScale3lo, qSrc3lo
+            VQRDMULH    qSrc3hi, qScale3hi, qSrc3hi
+            VQRDMULH    qSrc5lo, qScale5lo, qSrc5lo
+            VQRDMULH    qSrc5hi, qScale5hi, qSrc5hi
+            
+            ;// Row 3 & 5
+            VHADD       qRes53lo, qSrc5lo, qSrc3lo      ;// (j5+j3)/2
+            VHADD       qRes53hi, qSrc5hi, qSrc3hi      ;// (j5+j3)/2
+            SUB         pSrc, pSrc, #16*2*2
+            VMOVN       dXi7lo, qRes53lo                ;// Output i7
+            VMOVN       dXi7hi, qRes53hi              
+            VSUB        qRes53lo, qSrc5lo, qSrc3lo      ;// j5-j3
+            VSUB        qRes53hi, qSrc5hi, qSrc3hi      ;// j5-j3
+            VLD1        qXj4, [pSrc @64]
+            VMOVN       dXi4lo, qRes53lo                ;// Output i4
+            VMOVN       dXi4hi, qRes53hi                              
+            VSHLL       qSrc4lo, dXj4lo, #(12-1)
+            VSHLL       qSrc4hi, dXj4hi, #(12-1)
+            VLD1        {qScale4lo, qScale4hi}, [pScale]            
+            LDR         pSrc, =armCOMM_IDCTCoef     ;// Address of DCT inverse AAN constants
+            VQRDMULH    qSrc4lo, qScale4lo, qSrc4lo
+            VQRDMULH    qSrc4hi, qScale4hi, qSrc4hi
+            VLDR        dCoefs, [pSrc]                  ;// Load DCT inverse AAN constants
+            ;// Row 4
+            VMOVN       dXi1lo, qSrc4lo                 ;// Output i1
+            VMOVN       dXi1hi, qSrc4hi              
+        
+        MEND
+                                                
+        END
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armCOMM_MaskTable.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armCOMM_MaskTable.h
new file mode 100755
index 0000000..51118fd
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armCOMM_MaskTable.h
@@ -0,0 +1,27 @@
+/**
+ * 
+ * File Name:  armCOMM_MaskTable.h
+ * OpenMAX DL: v1.0.2
+ * Revision:   12290
+ * Date:       Wednesday, April 9, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Mask Table to mask the end of array
+ */
+ 
+
+
+#ifndef _ARMCOMM_MASKTABLE_H_
+#define _ARMCOMM_MASKTABLE_H_
+
+#define MaskTableSize 72
+  
+/* Mask table */
+
+extern const OMX_U16 armCOMM_qMaskTable16[MaskTableSize];
+extern const OMX_U8 armCOMM_qMaskTable8[MaskTableSize];
+
+#endif
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armCOMM_Version.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armCOMM_Version.h
new file mode 100755
index 0000000..41b3e1e
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armCOMM_Version.h
@@ -0,0 +1,43 @@
+/* Guard the header against multiple inclusion. */
+#ifndef __ARM_COMM_VERSION_H__
+#define __ARM_COMM_VERSION_H__
+
+
+/* The following line should be in omxtypes.h but hasn't been approved by OpenMAX yet */
+#define OMX_VERSION 102
+
+/* We need to define these macros in order to convert a #define number into a #define string. */
+#define ARM_QUOTE(a) #a
+#define ARM_INDIRECT(A) ARM_QUOTE(A)
+
+/* Convert the OMX_VERSION number into a string that can be used, for example, to print it out. */
+#define ARM_VERSION_STRING ARM_INDIRECT(OMX_VERSION)
+
+
+/* Define this in order to turn on ARM version/release/build strings in each domain */
+#define ARM_INCLUDE_VERSION_DESCRIPTIONS
+
+#ifdef ARM_INCLUDE_VERSION_DESCRIPTIONS
+  extern const char * const omxAC_VersionDescription;
+  extern const char * const omxIC_VersionDescription;
+  extern const char * const omxIP_VersionDescription;
+  extern const char * const omxSP_VersionDescription;
+  extern const char * const omxVC_VersionDescription;
+#endif /* ARM_INCLUDE_VERSION_DESCRIPTIONS */
+
+
+/* The following entries should be automatically updated by the release script */
+/* They are used in the ARM version strings defined for each domain.             */
+
+/* The release tag associated with this release of the library. - used for source and object releases */
+#define OMX_ARM_RELEASE_TAG  "r1p0-00bet0"
+
+/* The ARM architecture used to build any objects or executables in this release. */
+#define OMX_ARM_BUILD_ARCHITECTURE "ARM Architecture V7 with NEON"
+
+/* The ARM Toolchain used to build any objects or executables in this release. */
+#define OMX_ARM_BUILD_TOOLCHAIN    "ARM RVCT 3.1"
+
+
+#endif /* __ARM_COMM_VERSION_H__ */
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armCOMM_s.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armCOMM_s.h
new file mode 100755
index 0000000..0956bd1
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armCOMM_s.h
@@ -0,0 +1,1157 @@
+;//
+;// 
+;// File Name:  armCOMM_s.h
+;// OpenMAX DL: v1.0.2
+;// Revision:   12290
+;// Date:       Wednesday, April 9, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+;// ARM optimized OpenMAX common header file
+;//
+
+;// Protect against multiple inclusion
+ IF :LNOT::DEF:ARMCOMM_S_H
+ GBLL ARMCOMM_S_H
+
+        REQUIRE8            ;// Requires 8-byte stack alignment
+        PRESERVE8           ;// Preserves 8-byte stack alignment
+        
+        GBLL    ARM_ERRORCHECK
+ARM_ERRORCHECK  SETL {FALSE}
+
+;// Globals
+
+        GBLS    _RRegList   ;// R saved register list
+        GBLS    _DRegList   ;// D saved register list
+        GBLS    _Variant    ;// Selected processor variant
+        GBLS    _CPU        ;// CPU name
+        GBLS    _Struct     ;// Structure name
+        
+        GBLL    _InFunc     ;// Inside function assembly flag
+        GBLL    _SwLong     ;// Long switch flag
+        
+        GBLA    _RBytes     ;// Number of register bytes on stack
+        GBLA    _SBytes     ;// Number of scratch bytes on stack 
+        GBLA    _ABytes     ;// Stack offset of next argument
+        GBLA    _Workspace  ;// Stack offset of scratch workspace
+        GBLA    _F          ;// Function number
+        GBLA    _StOff      ;// Struct offset
+        GBLA    _SwNum      ;// Switch number
+        GBLS    _32         ;// Suffix for 32 byte alignmnet
+        GBLS    _16         ;// Suffix for 16 byte alignmnet
+        
+_InFunc         SETL    {FALSE}
+_SBytes         SETA    0
+_F              SETA    0
+_SwNum          SETA    0
+_32             SETS    "ALIGN32"
+_16             SETS    "ALIGN16"
+
+;/////////////////////////////////////////////////////////
+;// Override the tools settings of the CPU if the #define
+;// USECPU is set, otherwise use the CPU defined by the
+;// assembler settings.
+;/////////////////////////////////////////////////////////
+
+       IF :DEF: OVERRIDECPU
+_CPU       SETS  OVERRIDECPU
+       ELSE
+_CPU       SETS    {CPU}       
+       ENDIF
+
+
+
+;/////////////////////////////////////////////////////////
+;// Work out which code to build
+;/////////////////////////////////////////////////////////
+
+        IF :DEF:ARM1136JS:LOR::DEF:CortexA8:LOR::DEF:ARM_GENERIC
+            INFO 1,"Please switch to using M_VARIANTS"
+        ENDIF
+
+        ;// Define and reset all officially recongnised variants
+        MACRO
+        _M_DEF_VARIANTS
+        _M_DEF_VARIANT ARM926EJS
+        _M_DEF_VARIANT ARM1136JS
+        _M_DEF_VARIANT ARM1136JS_U
+        _M_DEF_VARIANT CortexA8
+        _M_DEF_VARIANT ARM7TDMI
+        MEND
+        
+        MACRO
+        _M_DEF_VARIANT $var
+        GBLL $var
+        GBLL _ok$var
+$var    SETL {FALSE}
+        MEND        
+        
+
+        ;// Variant declaration
+        ;//
+        ;// Define a list of code variants supported by this
+        ;// source file. This macro then chooses the most
+        ;// appropriate variant to build for the currently configured
+        ;// core.
+        ;//        
+        MACRO
+        M_VARIANTS $v0,$v1,$v2,$v3,$v4,$v5,$v6,$v7        
+        ;// Set to TRUE variants that are supported
+        _M_DEF_VARIANTS
+        _M_VARIANT $v0
+        _M_VARIANT $v1
+        _M_VARIANT $v2
+        _M_VARIANT $v3
+        _M_VARIANT $v4
+        _M_VARIANT $v5
+        _M_VARIANT $v6
+        _M_VARIANT $v7
+        
+        ;// Look for first available variant to match a CPU
+        ;// _M_TRY cpu, variant fall back list
+_Variant SETS ""                
+        _M_TRY ARM926EJ-S,   ARM926EJS
+        _M_TRY ARM1176JZ-S,  ARM1136JS
+        _M_TRY ARM1176JZF-S, ARM1136JS
+        _M_TRY ARM1156T2-S,  ARM1136JS
+        _M_TRY ARM1156T2F-S, ARM1136JS
+        _M_TRY ARM1136J-S,   ARM1136JS
+        _M_TRY ARM1136JF-S,  ARM1136JS
+        _M_TRY MPCore,       ARM1136JS
+        _M_TRY falcon-vfp, ARM1136JS
+        _M_TRY falcon-full-neon, CortexA8
+        _M_TRY Cortex-A8NoNeon, ARM1136JS
+        _M_TRY Cortex-A8,    CortexA8, ARM1136JS
+        _M_TRY Cortex-R4,    ARM1136JS
+        _M_TRY ARM7TDMI
+        
+        ;// Select the correct variant
+        _M_DEF_VARIANTS
+        IF _Variant=""
+            INFO 1, "No match found for CPU '$_CPU'"
+        ELSE
+$_Variant   SETL {TRUE}
+        ENDIF
+        MEND
+        
+        ;// Register a variant as available
+        MACRO
+        _M_VARIANT $var
+        IF "$var"=""
+            MEXIT
+        ENDIF
+        IF :LNOT::DEF:_ok$var
+            INFO 1, "Unrecognized variant '$var'"
+        ENDIF
+$var    SETL {TRUE}
+        MEND
+        
+        ;// For a given CPU, see if any of the variants supporting
+        ;// this CPU are available. The first available variant is
+        ;// chosen
+        MACRO
+        _M_TRY $cpu, $v0,$v1,$v2,$v3,$v4,$v5,$v6,$v7
+        IF "$cpu"<>_CPU
+            MEXIT
+        ENDIF
+        _M_TRY1 $v0
+        _M_TRY1 $v1
+        _M_TRY1 $v2
+        _M_TRY1 $v3
+        _M_TRY1 $v4
+        _M_TRY1 $v5
+        _M_TRY1 $v6
+        _M_TRY1 $v7
+        ;// Check a match was found
+        IF _Variant=""
+            INFO 1, "No variant match found for CPU '$_CPU'"
+        ENDIF
+        MEND
+        
+        MACRO
+        _M_TRY1 $var
+        IF "$var"=""
+            MEXIT
+        ENDIF
+        IF (_Variant=""):LAND:$var
+_Variant SETS "$var"
+        ENDIF
+        MEND
+        
+;////////////////////////////////////////////////////////
+;// Structure definition
+;////////////////////////////////////////////////////////
+
+        ;// Declare a structure of given name
+        MACRO
+        M_STRUCT $sname
+_Struct SETS "$sname"
+_StOff  SETA 0
+        MEND
+        
+        ;// Declare a structure field
+        ;// The field is called $sname_$fname
+        ;// $size   = the size of each entry, must be power of 2 
+        ;// $number = (if provided) the number of entries for an array
+        MACRO
+        M_FIELD $fname, $size, $number
+        IF (_StOff:AND:($size-1))!=0
+_StOff      SETA _StOff + ($size - (_StOff:AND:($size-1)))
+        ENDIF
+$_Struct._$fname EQU _StOff
+        IF "$number"<>""
+_StOff      SETA _StOff + $size*$number
+        ELSE
+_StOff      SETA _StOff + $size
+        ENDIF
+        MEND
+        
+        
+        MACRO
+        M_ENDSTRUCT
+sizeof_$_Struct EQU _StOff
+_Struct SETS ""
+        MEND
+
+;//////////////////////////////////////////////////////////
+;// Switch and table macros
+;//////////////////////////////////////////////////////////
+
+        ;// Start a relative switch table with register to switch on
+        ;//
+        ;// $v = the register to switch on
+        ;// $s = if specified must be "L" to indicate long
+        ;//      this allows a greater range to the case code
+        MACRO
+        M_SWITCH $v, $s
+        ASSERT "$s"="":LOR:"$s"="L"
+_SwLong SETL {FALSE}
+        IF "$s"="L"
+_SwLong     SETL {TRUE}
+        ENDIF
+_SwNum  SETA _SwNum+1        
+        IF {CONFIG}=16
+            ;// Thumb
+            IF _SwLong
+                TBH [pc, $v, LSL#1]
+            ELSE
+                TBB [pc, $v]
+            ENDIF
+_Switch$_SwNum
+        ELSE
+            ;// ARM
+            ADD pc, pc, $v, LSL #2
+            NOP
+        ENDIF
+        MEND
+        
+        ;// Add a case to the switch statement
+        MACRO
+        M_CASE  $label
+        IF {CONFIG}=16
+            ;// Thumb
+            IF _SwLong
+                DCW ($label - _Switch$_SwNum)/2
+            ELSE
+                DCB ($label - _Switch$_SwNum)/2
+            ENDIF
+        ELSE
+            ;// ARM
+            B   $label
+        ENDIF
+        MEND
+        
+        ;// End of switch statement
+        MACRO
+        M_ENDSWITCH
+        ALIGN 2
+        MEND       
+
+
+;////////////////////////////////////////////////////////
+;// Data area allocation
+;////////////////////////////////////////////////////////
+
+        ;// Constant table allocator macro
+        ;//
+        ;// Creates a new section for each constant table
+        ;// $name is symbol through which the table can be accessed.
+        ;// $align is the optional alignment of the table, log2 of 
+        ;//  the byte alignment - $align=4 is 16 byte aligned
+        MACRO
+        M_TABLE  $name, $align
+        ASSERT :LNOT:_InFunc
+        IF "$align"=""
+            AREA |.constdata|, READONLY, DATA
+        ELSE
+            ;// AREAs inherit the alignment of the first declaration.
+            ;// Therefore for each alignment size we must have an area
+            ;// of a different name.
+            AREA constdata_a$align, READONLY, DATA, ALIGN=$align
+            
+            ;// We also force alignment incase we are tagging onto
+            ;// an already started area.
+            ALIGN (1<<$align)
+        ENDIF
+$name
+        MEND
+        
+;/////////////////////////////////////////////////////
+;// Macros to allocate space on the stack
+;//
+;// These all assume that the stack is 8-byte aligned
+;// at entry to the function, which means that the 
+;// 32-byte alignment macro needs to work in a
+;// bit more of a special way...
+;/////////////////////////////////////////////////////
+
+        
+
+
+        ;// Allocate 1-byte aligned area of name
+        ;// $name size $size bytes.
+        MACRO
+        M_ALLOC1  $name, $size
+        ASSERT :LNOT:_InFunc
+$name$_F   EQU _SBytes
+_SBytes SETA _SBytes + ($size)
+        MEND
+            
+        ;// Allocate 2-byte aligned area of name
+        ;// $name size $size bytes.
+        MACRO
+        M_ALLOC2  $name, $size
+        ASSERT :LNOT:_InFunc
+        IF (_SBytes:AND:1)!=0
+_SBytes     SETA _SBytes + (2 - (_SBytes:AND:1))
+        ENDIF
+$name$_F   EQU _SBytes
+_SBytes SETA _SBytes + ($size)
+        MEND
+            
+        ;// Allocate 4-byte aligned area of name
+        ;// $name size $size bytes.
+        MACRO
+        M_ALLOC4  $name, $size
+        ASSERT :LNOT:_InFunc
+        IF (_SBytes:AND:3)!=0
+_SBytes     SETA _SBytes + (4 - (_SBytes:AND:3))
+        ENDIF
+$name$_F   EQU _SBytes
+_SBytes SETA _SBytes + ($size)
+        MEND
+            
+        ;// Allocate 8-byte aligned area of name
+        ;// $name size $size bytes.
+        MACRO
+        M_ALLOC8  $name, $size
+        ASSERT :LNOT:_InFunc
+        IF (_SBytes:AND:7)!=0
+_SBytes     SETA _SBytes + (8 - (_SBytes:AND:7))
+        ENDIF
+$name$_F   EQU _SBytes
+_SBytes SETA _SBytes + ($size)
+        MEND        
+
+        
+        ;// Allocate 8-byte aligned area of name
+        ;// $name size ($size+16) bytes.
+        ;// The extra 16 bytes are later used to align the pointer to 16 bytes
+        
+        MACRO
+        M_ALLOC16  $name, $size
+        ASSERT :LNOT:_InFunc
+        IF (_SBytes:AND:7)!=0
+_SBytes     SETA _SBytes + (8 - (_SBytes:AND:7))
+        ENDIF
+$name$_F$_16   EQU (_SBytes + 8)
+_SBytes SETA _SBytes + ($size) + 8
+        MEND        
+        
+        ;// Allocate 8-byte aligned area of name
+        ;// $name size ($size+32) bytes.
+        ;// The extra 32 bytes are later used to align the pointer to 32 bytes
+        
+        MACRO
+        M_ALLOC32  $name, $size
+        ASSERT :LNOT:_InFunc
+        IF (_SBytes:AND:7)!=0
+_SBytes     SETA _SBytes + (8 - (_SBytes:AND:7))
+        ENDIF
+$name$_F$_32   EQU (_SBytes + 24)
+_SBytes SETA _SBytes + ($size) + 24
+        MEND        
+        
+        
+        
+        
+        ;// Argument Declaration Macro
+        ;//
+        ;// Allocate an argument name $name
+        ;// size $size bytes
+        MACRO
+        M_ARG     $name, $size
+        ASSERT _InFunc
+$name$_F    EQU _ABytes
+_ABytes SETA _ABytes + ($size)
+        MEND        
+        
+;///////////////////////////////////////////////
+;// Macros to access stacked variables
+;///////////////////////////////////////////////
+
+        ;// Macro to perform a data processing operation
+        ;// with a constant second operand
+        MACRO
+        _M_OPC $op,$rd,$rn,$const
+        LCLA    _sh
+        LCLA    _cst
+_sh     SETA    0
+_cst    SETA    $const
+        IF _cst=0
+        $op $rd, $rn, #_cst
+            MEXIT
+        ENDIF
+        WHILE (_cst:AND:3)=0
+_cst        SETA _cst>>2
+_sh         SETA _sh+2
+        WEND
+        $op $rd, $rn, #(_cst:AND:0x000000FF)<<_sh
+        IF _cst>=256
+            $op $rd, $rd, #(_cst:AND:0xFFFFFF00)<<_sh
+        ENDIF
+        MEND
+
+        ;// Macro to perform a data access operation
+        ;// Such as LDR or STR
+        ;// The addressing mode is modified such that
+        ;// 1. If no address is given then the name is taken
+        ;//    as a stack offset
+        ;// 2. If the addressing mode is not available for the
+        ;//    state being assembled for (eg Thumb) then a suitable
+        ;//    addressing mode is substituted.
+        ;//
+        ;// On Entry:
+        ;// $i = Instruction to perform (eg "LDRB")
+        ;// $a = Required byte alignment
+        ;// $r = Register(s) to transfer (eg "r1")
+        ;// $a0,$a1,$a2. Addressing mode and condition. One of:
+        ;//     label {,cc}
+        ;//     [base]                    {,,,cc}
+        ;//     [base, offset]{!}         {,,cc}
+        ;//     [base, offset, shift]{!}  {,cc}
+        ;//     [base], offset            {,,cc}
+        ;//     [base], offset, shift     {,cc}
+        MACRO
+        _M_DATA $i,$a,$r,$a0,$a1,$a2,$a3
+        IF "$a0":LEFT:1="["
+            IF "$a1"=""
+                $i$a3   $r, $a0
+            ELSE
+                IF "$a0":RIGHT:1="]"
+                    IF "$a2"=""
+                        _M_POSTIND $i$a3, "$r", $a0, $a1
+                    ELSE
+                        _M_POSTIND $i$a3, "$r", $a0, "$a1,$a2"
+                    ENDIF
+                ELSE
+                    IF "$a2"=""
+                        _M_PREIND  $i$a3, "$r", $a0, $a1
+                    ELSE
+                        _M_PREIND  $i$a3, "$r", $a0, "$a1,$a2"
+                    ENDIF
+                ENDIF
+            ENDIF
+        ELSE
+            LCLA    _Offset
+_Offset     SETA    _Workspace + $a0$_F
+            ASSERT  (_Offset:AND:($a-1))=0
+            $i$a1   $r, [sp, #_Offset]
+        ENDIF
+        MEND
+        
+        ;// Handle post indexed load/stores
+        ;// op  reg, [base], offset
+        MACRO
+        _M_POSTIND $i,$r,$a0,$a1
+        LCLS _base
+        LCLS _offset
+        IF {CONFIG}=16 ;// Thumb
+_base       SETS ("$a0":LEFT:(:LEN:"$a0"-1)):RIGHT:(:LEN:"$a0"-2)   ;// remove []
+_offset     SETS "$a1"
+            IF _offset:LEFT:1="+"
+_offset         SETS _offset:RIGHT:(:LEN:_offset-1)
+            ENDIF
+            $i  $r, $a0
+            IF _offset:LEFT:1="-"
+_offset         SETS _offset:RIGHT:(:LEN:_offset-1)
+                SUB $_base, $_base, $_offset
+            ELSE                
+                ADD $_base, $_base, $_offset
+            ENDIF
+        ELSE ;// ARM
+            $i  $r, $a0, $a1
+        ENDIF
+        MEND
+        
+        ;// Handle pre indexed load/store
+        ;// op  reg, [base, offset]{!}
+        MACRO
+        _M_PREIND $i,$r,$a0,$a1
+        LCLS _base
+        LCLS _offset
+        IF ({CONFIG}=16):LAND:(("$a1":RIGHT:2)="]!")
+_base       SETS "$a0":RIGHT:(:LEN:("$a0")-1)
+_offset     SETS "$a1":LEFT:(:LEN:("$a1")-2)
+            $i $r, [$_base, $_offset]
+            ADD $_base, $_base, $_offset
+        ELSE
+            $i  $r, $a0, $a1
+        ENDIF
+        MEND
+
+        ;// Load unsigned byte from stack
+        MACRO
+        M_LDRB  $r,$a0,$a1,$a2,$a3
+        _M_DATA "LDRB",1,$r,$a0,$a1,$a2,$a3
+        MEND
+        
+        ;// Load signed byte from stack
+        MACRO
+        M_LDRSB $r,$a0,$a1,$a2,$a3
+        _M_DATA "LDRSB",1,$r,$a0,$a1,$a2,$a3
+        MEND
+        
+        ;// Store byte to stack
+        MACRO
+        M_STRB  $r,$a0,$a1,$a2,$a3
+        _M_DATA "STRB",1,$r,$a0,$a1,$a2,$a3
+        MEND
+        
+        ;// Load unsigned half word from stack
+        MACRO
+        M_LDRH  $r,$a0,$a1,$a2,$a3
+        _M_DATA "LDRH",2,$r,$a0,$a1,$a2,$a3
+        MEND
+        
+        ;// Load signed half word from stack
+        MACRO
+        M_LDRSH $r,$a0,$a1,$a2,$a3
+        _M_DATA "LDRSH",2,$r,$a0,$a1,$a2,$a3
+        MEND
+        
+        ;// Store half word to stack
+        MACRO
+        M_STRH  $r,$a0,$a1,$a2,$a3
+        _M_DATA "STRH",2,$r,$a0,$a1,$a2,$a3
+        MEND
+
+        ;// Load word from stack
+        MACRO
+        M_LDR   $r,$a0,$a1,$a2,$a3
+        _M_DATA "LDR",4,$r,$a0,$a1,$a2,$a3
+        MEND
+        
+        ;// Store word to stack
+        MACRO
+        M_STR   $r,$a0,$a1,$a2,$a3
+        _M_DATA "STR",4,$r,$a0,$a1,$a2,$a3
+        MEND
+
+        ;// Load double word from stack
+        MACRO
+        M_LDRD  $r0,$r1,$a0,$a1,$a2,$a3
+        _M_DATA "LDRD",8,"$r0,$r1",$a0,$a1,$a2,$a3
+        MEND
+                
+        ;// Store double word to stack
+        MACRO
+        M_STRD  $r0,$r1,$a0,$a1,$a2,$a3
+        _M_DATA "STRD",8,"$r0,$r1",$a0,$a1,$a2,$a3
+        MEND
+        
+        ;// Get absolute address of stack allocated location
+        MACRO
+        M_ADR   $a, $b, $cc
+        _M_OPC  ADD$cc, $a, sp, (_Workspace + $b$_F)
+        MEND
+        
+        ;// Get absolute address of stack allocated location and align the address to 16 bytes
+        MACRO
+        M_ADR16 $a, $b, $cc
+            _M_OPC  ADD$cc, $a, sp, (_Workspace + $b$_F$_16)
+        
+            ;// Now align $a to 16 bytes
+            BIC$cc  $a,$a,#0x0F
+        MEND
+        
+        ;// Get absolute address of stack allocated location and align the address to 32 bytes
+        MACRO
+        M_ADR32 $a, $b, $cc
+            _M_OPC  ADD$cc, $a, sp, (_Workspace + $b$_F$_32)
+        
+            ;// Now align $a to 32 bytes
+            BIC$cc  $a,$a,#0x1F
+        MEND
+
+;//////////////////////////////////////////////////////////
+;// Function header and footer macros
+;//////////////////////////////////////////////////////////      
+        
+        ;// Function Header Macro    
+        ;// Generates the function prologue
+        ;// Note that functions should all be "stack-moves-once"
+        ;// The FNSTART and FNEND macros should be the only places
+        ;// where the stack moves.
+        ;//    
+        ;// $name  = function name
+        ;// $rreg  = ""   don't stack any registers
+        ;//          "lr" stack "lr" only
+        ;//          "rN" stack registers "r4-rN,lr"
+        ;// $dreg  = ""   don't stack any D registers
+        ;//          "dN" stack registers "d8-dN"
+        ;//
+        ;// Note: ARM Archicture procedure call standard AAPCS
+        ;// states that r4-r11, sp, d8-d15 must be preserved by
+        ;// a compliant function.
+        MACRO
+        M_START $name, $rreg, $dreg
+        ASSERT :LNOT:_InFunc
+        ASSERT "$name"!=""
+_InFunc SETL {TRUE}
+_RBytes SETA 0
+_Workspace SETA 0
+
+        ;// Create an area for the function        
+        AREA    |.text|, CODE
+        EXPORT  $name
+$name   FUNCTION
+        
+        ;// Save R registers
+        _M_GETRREGLIST $rreg
+        IF _RRegList<>""
+            STMFD   sp!, {$_RRegList, lr}
+        ENDIF
+                
+        ;// Save D registers
+        _M_GETDREGLIST  $dreg        
+        IF _DRegList<>""
+            VSTMFD  sp!, {$_DRegList}
+        ENDIF            
+            
+                    
+        ;// Ensure size claimed on stack is 8-byte aligned
+        IF ((_SBytes:AND:7)!=0)
+_SBytes     SETA _SBytes + (8 - (_SBytes:AND:7))
+        ENDIF
+        
+        IF (_SBytes!=0)
+            _M_OPC SUB, sp, sp, _SBytes
+        ENDIF
+        
+        
+_ABytes SETA _SBytes + _RBytes - _Workspace
+
+                        
+        ;// Print function name if debug enabled
+        M_PRINTF "$name\n",
+        MEND
+        
+        ;// Work out a list of R saved registers
+        MACRO
+        _M_GETRREGLIST $rreg
+        IF "$rreg"=""
+_RRegList   SETS ""
+            MEXIT
+        ENDIF        
+        IF "$rreg"="lr":LOR:"$rreg"="r4"
+_RRegList   SETS "r4"
+_RBytes     SETA _RBytes+8
+            MEXIT
+        ENDIF
+        IF "$rreg"="r5":LOR:"$rreg"="r6"
+_RRegList   SETS "r4-r6"
+_RBytes     SETA _RBytes+16
+            MEXIT
+        ENDIF
+        IF "$rreg"="r7":LOR:"$rreg"="r8"
+_RRegList   SETS "r4-r8"
+_RBytes     SETA _RBytes+24
+            MEXIT
+        ENDIF
+        IF "$rreg"="r9":LOR:"$rreg"="r10"
+_RRegList   SETS "r4-r10"
+_RBytes     SETA _RBytes+32
+            MEXIT
+        ENDIF
+        IF "$rreg"="r11":LOR:"$rreg"="r12"
+_RRegList   SETS "r4-r12"
+_RBytes     SETA _RBytes+40
+            MEXIT
+        ENDIF
+        INFO 1, "Unrecognized saved r register limit '$rreg'"
+        MEND        
+        
+        ;// Work out a list of D saved registers
+        MACRO
+        _M_GETDREGLIST $dreg
+        IF "$dreg"=""
+_DRegList   SETS ""
+            MEXIT
+        ENDIF        
+        IF "$dreg"="d8"
+_DRegList   SETS "d8"
+_RBytes     SETA _RBytes+8
+            MEXIT
+        ENDIF
+        IF "$dreg"="d9"
+_DRegList   SETS "d8-d9"
+_RBytes     SETA _RBytes+16
+            MEXIT
+        ENDIF
+        IF "$dreg"="d10"
+_DRegList   SETS "d8-d10"
+_RBytes     SETA _RBytes+24
+            MEXIT
+        ENDIF
+        IF "$dreg"="d11"
+_DRegList   SETS "d8-d11"
+_RBytes     SETA _RBytes+32
+            MEXIT
+        ENDIF
+        IF "$dreg"="d12"
+_DRegList   SETS "d8-d12"
+_RBytes     SETA _RBytes+40
+            MEXIT
+        ENDIF
+        IF "$dreg"="d13"
+_DRegList   SETS "d8-d13"
+_RBytes     SETA _RBytes+48
+            MEXIT
+        ENDIF
+        IF "$dreg"="d14"
+_DRegList   SETS "d8-d14"
+_RBytes     SETA _RBytes+56
+            MEXIT
+        ENDIF
+        IF "$dreg"="d15"
+_DRegList   SETS "d8-d15"
+_RBytes     SETA _RBytes+64
+            MEXIT
+        ENDIF
+        INFO 1, "Unrecognized saved d register limit '$dreg'"
+        MEND
+        
+        ;// Produce function return instructions
+        MACRO
+        _M_RET $cc
+        IF _DRegList<>""
+            VPOP$cc {$_DRegList}
+        ENDIF
+        IF _RRegList=""
+            BX$cc lr
+        ELSE
+            LDM$cc.FD sp!, {$_RRegList, pc}
+        ENDIF
+        MEND        
+        
+        ;// Early Function Exit Macro
+        ;// $cc = condition to exit with
+        ;// (Example: M_EXIT EQ)
+        MACRO
+        M_EXIT  $cc
+        ASSERT  _InFunc
+        IF  _SBytes!=0
+            ;// Restore stack frame and exit
+            B$cc  _End$_F
+        ELSE
+            ;// Can return directly
+            _M_RET $cc
+        ENDIF        
+        MEND        
+
+        ;// Function Footer Macro        
+        ;// Generates the function epilogue
+        MACRO
+        M_END
+        ASSERT _InFunc
+_InFunc SETL {FALSE}
+_End$_F
+
+        ;// Restore the stack pointer to its original value on function entry
+        IF _SBytes!=0
+            _M_OPC ADD, sp, sp, _SBytes
+        ENDIF
+        _M_RET
+        ENDFUNC
+
+        ;// Reset the global stack tracking variables back to their 
+        ;// initial values, and increment the function count
+_SBytes        SETA 0
+_F             SETA _F+1
+        MEND
+
+                
+;//==========================================================================
+;// Debug Macros
+;//==========================================================================
+
+        GBLL    DEBUG_ON
+DEBUG_ON SETL   {FALSE}
+        GBLL    DEBUG_STALLS_ON
+DEBUG_STALLS_ON SETL {FALSE}
+        
+        ;//==========================================================================
+        ;// Debug call to printf
+        ;//  M_PRINTF $format, $val0, $val1, $val2
+        ;//
+        ;// Examples:
+        ;//  M_PRINTF "x=%08x\n", r0
+        ;//
+        ;// This macro preserves the value of all registers including the
+        ;// flags.
+        ;//==========================================================================
+
+        MACRO
+        M_PRINTF  $format, $val0, $val1, $val2
+        IF DEBUG_ON
+        
+        IMPORT  printf
+        LCLA    nArgs
+nArgs	SETA    0
+        
+        ;// save registers so we don't corrupt them
+        STMFD   sp!, {r0-r12, lr}
+        
+        ;// Drop stack to give us some workspace
+        SUB     sp, sp, #16
+        
+        ;// Save registers we need to print to the stack
+        IF "$val2" <> ""
+            ASSERT "$val1" <> ""
+            STR    $val2, [sp, #8]
+nArgs       SETA   nArgs+1
+        ENDIF
+        IF "$val1" <> ""
+            ASSERT "$val0" <> ""
+            STR    $val1, [sp, #4]
+nArgs	    SETA   nArgs+1
+        ENDIF
+        IF "$val0"<>""
+            STR    $val0, [sp]
+nArgs	    SETA   nArgs+1
+        ENDIF
+        
+        ;// Now we are safe to corrupt registers
+        ADR     r0, %FT00
+        IF nArgs=1
+          LDR   r1, [sp]
+        ENDIF
+        IF nArgs=2
+          LDMIA sp, {r1,r2}
+        ENDIF
+        IF nArgs=3
+          LDMIA sp, {r1,r2,r3}
+        ENDIF
+        
+        ;// print the values
+        MRS     r4, cpsr        ;// preserve flags
+        BL      printf
+        MSR     cpsr_f, r4      ;// restore flags
+        B       %FT01
+00      ;// string to print
+        DCB     "$format", 0
+        ALIGN
+01      ;// Finished
+        ADD     sp, sp, #16
+        ;// Restore registers
+        LDMFD	sp!, {r0-r12,lr}
+
+        ENDIF   ;// DEBUG_ON
+        MEND
+
+
+        ;// Stall Simulation Macro
+        ;// Inserts a given number of NOPs for the currently
+        ;//  defined platform
+        MACRO
+        M_STALL $plat1stall, $plat2stall, $plat3stall, $plat4stall, $plat5stall, $plat6stall
+        IF DEBUG_STALLS_ON
+            _M_STALL_SUB $plat1stall    
+            _M_STALL_SUB $plat2stall    
+            _M_STALL_SUB $plat3stall    
+            _M_STALL_SUB $plat4stall    
+            _M_STALL_SUB $plat5stall    
+            _M_STALL_SUB $plat6stall    
+        ENDIF
+        MEND
+        
+        MACRO
+        _M_STALL_SUB $platstall
+        IF "$platstall"!=""
+            LCLA _pllen
+            LCLS _pl
+            LCLL _pllog
+_pllen      SETA :LEN:"$platstall"
+_pl         SETS "$platstall":LEFT:(_pllen - 2)
+            IF :DEF:$_pl
+                IF $_pl
+                    LCLS _st
+                    LCLA _stnum
+_st                 SETS "$platstall":RIGHT:1        
+_stnum              SETA $_st
+                    WHILE _stnum>0
+			MOV sp, sp
+_stnum                  SETA _stnum - 1
+                    WEND
+                ENDIF
+            ENDIF
+        ENDIF
+        MEND
+        
+        
+        
+;//==========================================================================
+;// Endian Invarience Macros
+;// 
+;// The idea behind these macros is that if an array is
+;// loaded as words then the SMUL00 macro will multiply
+;// array elements 0 regardless of the endianess of the
+;// system. For little endian SMUL00=SMULBB, for big
+;// endian SMUL00=SMULTT and similarly for other packed operations.
+;//
+;//==========================================================================
+
+        MACRO
+        LIBI4   $comli, $combi, $a, $b, $c, $d, $cc
+        IF {ENDIAN}="big"
+        $combi.$cc $a, $b, $c, $d
+        ELSE
+        $comli.$cc $a, $b, $c, $d
+        ENDIF
+        MEND
+        
+        MACRO
+        LIBI3   $comli, $combi, $a, $b, $c, $cc
+        IF {ENDIAN}="big"
+        $combi.$cc $a, $b, $c
+        ELSE
+        $comli.$cc $a, $b, $c
+        ENDIF
+        MEND
+        
+        ;// SMLAxy macros
+        
+        MACRO
+        SMLA00  $a, $b, $c, $d, $cc
+        LIBI4 SMLABB, SMLATT, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLA01  $a, $b, $c, $d, $cc
+        LIBI4 SMLABT, SMLATB, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLA0B  $a, $b, $c, $d, $cc
+        LIBI4 SMLABB, SMLATB, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLA0T  $a, $b, $c, $d, $cc
+        LIBI4 SMLABT, SMLATT, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLA10  $a, $b, $c, $d, $cc
+        LIBI4 SMLATB, SMLABT, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLA11  $a, $b, $c, $d, $cc
+        LIBI4 SMLATT, SMLABB, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLA1B  $a, $b, $c, $d, $cc
+        LIBI4 SMLATB, SMLABB, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLA1T  $a, $b, $c, $d, $cc
+        LIBI4 SMLATT, SMLABT, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLAB0  $a, $b, $c, $d, $cc
+        LIBI4 SMLABB, SMLABT, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLAB1  $a, $b, $c, $d, $cc
+        LIBI4 SMLABT, SMLABB, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLAT0  $a, $b, $c, $d, $cc
+        LIBI4 SMLATB, SMLATT, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLAT1  $a, $b, $c, $d, $cc
+        LIBI4 SMLATT, SMLATB, $a, $b, $c, $d, $cc
+        MEND
+        
+        ;// SMULxy macros
+        
+        MACRO
+        SMUL00  $a, $b, $c, $cc
+        LIBI3 SMULBB, SMULTT, $a, $b, $c, $cc
+        MEND
+        
+        MACRO
+        SMUL01  $a, $b, $c, $cc
+        LIBI3 SMULBT, SMULTB, $a, $b, $c, $cc
+        MEND
+        
+        MACRO
+        SMUL0B  $a, $b, $c, $cc
+        LIBI3 SMULBB, SMULTB, $a, $b, $c, $cc
+        MEND
+        
+        MACRO
+        SMUL0T  $a, $b, $c, $cc
+        LIBI3 SMULBT, SMULTT, $a, $b, $c, $cc
+        MEND
+        
+        MACRO
+        SMUL10  $a, $b, $c, $cc
+        LIBI3 SMULTB, SMULBT, $a, $b, $c, $cc
+        MEND
+        
+        MACRO
+        SMUL11  $a, $b, $c, $cc
+        LIBI3 SMULTT, SMULBB, $a, $b, $c, $cc
+        MEND
+        
+        MACRO
+        SMUL1B  $a, $b, $c, $cc
+        LIBI3 SMULTB, SMULBB, $a, $b, $c, $cc
+        MEND
+        
+        MACRO
+        SMUL1T  $a, $b, $c, $cc
+        LIBI3 SMULTT, SMULBT, $a, $b, $c, $cc
+        MEND
+        
+        MACRO
+        SMULB0  $a, $b, $c, $cc
+        LIBI3 SMULBB, SMULBT, $a, $b, $c, $cc
+        MEND
+        
+        MACRO
+        SMULB1  $a, $b, $c, $cc
+        LIBI3 SMULBT, SMULBB, $a, $b, $c, $cc
+        MEND
+        
+        MACRO
+        SMULT0  $a, $b, $c, $cc
+        LIBI3 SMULTB, SMULTT, $a, $b, $c, $cc
+        MEND
+        
+        MACRO
+        SMULT1  $a, $b, $c, $cc
+        LIBI3 SMULTT, SMULTB, $a, $b, $c, $cc
+        MEND
+        
+        ;// SMLAWx, SMULWx macros
+        
+        MACRO
+        SMLAW0  $a, $b, $c, $d, $cc
+        LIBI4 SMLAWB, SMLAWT, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLAW1  $a, $b, $c, $d, $cc
+        LIBI4 SMLAWT, SMLAWB, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMULW0  $a, $b, $c, $cc
+        LIBI3 SMULWB, SMULWT, $a, $b, $c, $cc
+        MEND
+        
+        MACRO
+        SMULW1  $a, $b, $c, $cc
+        LIBI3 SMULWT, SMULWB, $a, $b, $c, $cc
+        MEND
+
+        ;// SMLALxy macros
+
+
+        MACRO
+        SMLAL00  $a, $b, $c, $d, $cc
+        LIBI4 SMLALBB, SMLALTT, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLAL01  $a, $b, $c, $d, $cc
+        LIBI4 SMLALBT, SMLALTB, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLAL0B  $a, $b, $c, $d, $cc
+        LIBI4 SMLALBB, SMLALTB, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLAL0T  $a, $b, $c, $d, $cc
+        LIBI4 SMLALBT, SMLALTT, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLAL10  $a, $b, $c, $d, $cc
+        LIBI4 SMLALTB, SMLALBT, $a, $b, $c, $d, $cc
+        MEND
+
+        MACRO
+        SMLAL11  $a, $b, $c, $d, $cc
+        LIBI4 SMLALTT, SMLALBB, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLAL1B  $a, $b, $c, $d, $cc
+        LIBI4 SMLALTB, SMLALBB, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLAL1T  $a, $b, $c, $d, $cc
+        LIBI4 SMLALTT, SMLALBT, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLALB0  $a, $b, $c, $d, $cc
+        LIBI4 SMLALBB, SMLALBT, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLALB1  $a, $b, $c, $d, $cc
+        LIBI4 SMLALBT, SMLALBB, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLALT0  $a, $b, $c, $d, $cc
+        LIBI4 SMLALTB, SMLALTT, $a, $b, $c, $d, $cc
+        MEND
+        
+        MACRO
+        SMLALT1  $a, $b, $c, $d, $cc
+        LIBI4 SMLALTT, SMLALTB, $a, $b, $c, $d, $cc
+        MEND
+        
+  ENDIF ;// ARMCOMM_S_H
+            
+  END
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armOMX.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armOMX.h
new file mode 100755
index 0000000..7a68d14
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armOMX.h
@@ -0,0 +1,274 @@
+/* 
+ * 
+ * File Name:  armOMX_ReleaseVersion.h
+ * OpenMAX DL: v1.0.2
+ * Revision:   12290
+ * Date:       Wednesday, April 9, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * This file allows a version of the OMX DL libraries to be built where some or
+ * all of the function names can be given a user specified suffix. 
+ *
+ * You might want to use it where:
+ *
+ * - you want to rename a function "out of the way" so that you could replace
+ *   a function with a different version (the original version would still be
+ *   in the library just with a different name - so you could debug the new
+ *   version by comparing it to the output of the old)
+ *
+ * - you want to rename all the functions to versions with a suffix so that 
+ *   you can include two versions of the library and choose between functions
+ *   at runtime.
+ *
+ *     e.g. omxIPBM_Copy_U8_C1R could be renamed omxIPBM_Copy_U8_C1R_CortexA8
+ * 
+ */
+
+  
+#ifndef _armOMX_H_
+#define _armOMX_H_
+
+
+/* We need to define these two macros in order to expand and concatenate the names */
+#define OMXCAT2BAR(A, B) omx ## A ## B
+#define OMXCATBAR(A, B) OMXCAT2BAR(A, B)
+
+/* Define the suffix to add to all functions - the default is no suffix */
+#define BARE_SUFFIX 
+
+
+
+/* Define what happens to the bare suffix-less functions, down to the sub-domain accuracy */
+#define OMXACAAC_SUFFIX    BARE_SUFFIX   
+#define OMXACMP3_SUFFIX    BARE_SUFFIX
+#define OMXICJP_SUFFIX     BARE_SUFFIX
+#define OMXIPBM_SUFFIX     BARE_SUFFIX
+#define OMXIPCS_SUFFIX     BARE_SUFFIX
+#define OMXIPPP_SUFFIX     BARE_SUFFIX
+#define OMXSP_SUFFIX       BARE_SUFFIX
+#define OMXVCCOMM_SUFFIX   BARE_SUFFIX
+#define OMXVCM4P10_SUFFIX  BARE_SUFFIX
+#define OMXVCM4P2_SUFFIX   BARE_SUFFIX
+
+
+
+
+/* Define what the each bare, un-suffixed OpenMAX API function names is to be renamed */
+#define omxACAAC_DecodeChanPairElt                        OMXCATBAR(ACAAC_DecodeChanPairElt, OMXACAAC_SUFFIX)
+#define omxACAAC_DecodeDatStrElt                          OMXCATBAR(ACAAC_DecodeDatStrElt, OMXACAAC_SUFFIX)
+#define omxACAAC_DecodeFillElt                            OMXCATBAR(ACAAC_DecodeFillElt, OMXACAAC_SUFFIX)
+#define omxACAAC_DecodeIsStereo_S32                       OMXCATBAR(ACAAC_DecodeIsStereo_S32, OMXACAAC_SUFFIX)
+#define omxACAAC_DecodeMsPNS_S32_I                        OMXCATBAR(ACAAC_DecodeMsPNS_S32_I, OMXACAAC_SUFFIX)
+#define omxACAAC_DecodeMsStereo_S32_I                     OMXCATBAR(ACAAC_DecodeMsStereo_S32_I, OMXACAAC_SUFFIX)
+#define omxACAAC_DecodePrgCfgElt                          OMXCATBAR(ACAAC_DecodePrgCfgElt, OMXACAAC_SUFFIX)
+#define omxACAAC_DecodeTNS_S32_I                          OMXCATBAR(ACAAC_DecodeTNS_S32_I, OMXACAAC_SUFFIX)
+#define omxACAAC_DeinterleaveSpectrum_S32                 OMXCATBAR(ACAAC_DeinterleaveSpectrum_S32, OMXACAAC_SUFFIX)
+#define omxACAAC_EncodeTNS_S32_I                          OMXCATBAR(ACAAC_EncodeTNS_S32_I, OMXACAAC_SUFFIX)
+#define omxACAAC_LongTermPredict_S32                      OMXCATBAR(ACAAC_LongTermPredict_S32, OMXACAAC_SUFFIX)
+#define omxACAAC_LongTermReconstruct_S32_I                OMXCATBAR(ACAAC_LongTermReconstruct_S32_I, OMXACAAC_SUFFIX)
+#define omxACAAC_MDCTFwd_S32                              OMXCATBAR(ACAAC_MDCTFwd_S32, OMXACAAC_SUFFIX)
+#define omxACAAC_MDCTInv_S32_S16                          OMXCATBAR(ACAAC_MDCTInv_S32_S16, OMXACAAC_SUFFIX)
+#define omxACAAC_NoiselessDecode                          OMXCATBAR(ACAAC_NoiselessDecode, OMXACAAC_SUFFIX)
+#define omxACAAC_QuantInv_S32_I                           OMXCATBAR(ACAAC_QuantInv_S32_I, OMXACAAC_SUFFIX)
+#define omxACAAC_UnpackADIFHeader                         OMXCATBAR(ACAAC_UnpackADIFHeader, OMXACAAC_SUFFIX)
+#define omxACAAC_UnpackADTSFrameHeader                    OMXCATBAR(ACAAC_UnpackADTSFrameHeader, OMXACAAC_SUFFIX)
+
+
+#define omxACMP3_HuffmanDecode_S32                        OMXCATBAR(ACMP3_HuffmanDecode_S32, OMXACMP3_SUFFIX)
+#define omxACMP3_HuffmanDecodeSfb_S32                     OMXCATBAR(ACMP3_HuffmanDecodeSfb_S32, OMXACMP3_SUFFIX)
+#define omxACMP3_HuffmanDecodeSfbMbp_S32                  OMXCATBAR(ACMP3_HuffmanDecodeSfbMbp_S32, OMXACMP3_SUFFIX)
+#define omxACMP3_MDCTInv_S32                              OMXCATBAR(ACMP3_MDCTInv_S32, OMXACMP3_SUFFIX)
+#define omxACMP3_ReQuantize_S32_I                         OMXCATBAR(ACMP3_ReQuantize_S32_I, OMXACMP3_SUFFIX)
+#define omxACMP3_ReQuantizeSfb_S32_I                      OMXCATBAR(ACMP3_ReQuantizeSfb_S32_I, OMXACMP3_SUFFIX)
+#define omxACMP3_SynthPQMF_S32_S16                        OMXCATBAR(ACMP3_SynthPQMF_S32_S16, OMXACMP3_SUFFIX)
+#define omxACMP3_UnpackFrameHeader                        OMXCATBAR(ACMP3_UnpackFrameHeader, OMXACMP3_SUFFIX)
+#define omxACMP3_UnpackScaleFactors_S8                    OMXCATBAR(ACMP3_UnpackScaleFactors_S8, OMXACMP3_SUFFIX)
+#define omxACMP3_UnpackSideInfo                           OMXCATBAR(ACMP3_UnpackSideInfo, OMXACMP3_SUFFIX)
+
+#define omxICJP_CopyExpand_U8_C3                          OMXCATBAR(ICJP_CopyExpand_U8_C3, OMXICJP_SUFFIX)
+#define omxICJP_DCTFwd_S16                                OMXCATBAR(ICJP_DCTFwd_S16, OMXICJP_SUFFIX)
+#define omxICJP_DCTFwd_S16_I                              OMXCATBAR(ICJP_DCTFwd_S16_I, OMXICJP_SUFFIX)
+#define omxICJP_DCTInv_S16                                OMXCATBAR(ICJP_DCTInv_S16, OMXICJP_SUFFIX)
+#define omxICJP_DCTInv_S16_I                              OMXCATBAR(ICJP_DCTInv_S16_I, OMXICJP_SUFFIX)
+#define omxICJP_DCTQuantFwd_Multiple_S16                  OMXCATBAR(ICJP_DCTQuantFwd_Multiple_S16, OMXICJP_SUFFIX)
+#define omxICJP_DCTQuantFwd_S16                           OMXCATBAR(ICJP_DCTQuantFwd_S16, OMXICJP_SUFFIX)
+#define omxICJP_DCTQuantFwd_S16_I                         OMXCATBAR(ICJP_DCTQuantFwd_S16_I, OMXICJP_SUFFIX)
+#define omxICJP_DCTQuantFwdTableInit                      OMXCATBAR(ICJP_DCTQuantFwdTableInit, OMXICJP_SUFFIX)
+#define omxICJP_DCTQuantInv_Multiple_S16                  OMXCATBAR(ICJP_DCTQuantInv_Multiple_S16, OMXICJP_SUFFIX)
+#define omxICJP_DCTQuantInv_S16                           OMXCATBAR(ICJP_DCTQuantInv_S16, OMXICJP_SUFFIX)
+#define omxICJP_DCTQuantInv_S16_I                         OMXCATBAR(ICJP_DCTQuantInv_S16_I, OMXICJP_SUFFIX)
+#define omxICJP_DCTQuantInvTableInit                      OMXCATBAR(ICJP_DCTQuantInvTableInit, OMXICJP_SUFFIX)
+#define omxICJP_DecodeHuffman8x8_Direct_S16_C1            OMXCATBAR(ICJP_DecodeHuffman8x8_Direct_S16_C1, OMXICJP_SUFFIX)
+#define omxICJP_DecodeHuffmanSpecGetBufSize_U8            OMXCATBAR(ICJP_DecodeHuffmanSpecGetBufSize_U8, OMXICJP_SUFFIX)
+#define omxICJP_DecodeHuffmanSpecInit_U8                  OMXCATBAR(ICJP_DecodeHuffmanSpecInit_U8, OMXICJP_SUFFIX)
+#define omxICJP_EncodeHuffman8x8_Direct_S16_U1_C1         OMXCATBAR(ICJP_EncodeHuffman8x8_Direct_S16_U1_C1, OMXICJP_SUFFIX)
+#define omxICJP_EncodeHuffmanSpecGetBufSize_U8            OMXCATBAR(ICJP_EncodeHuffmanSpecGetBufSize_U8, OMXICJP_SUFFIX)
+#define omxICJP_EncodeHuffmanSpecInit_U8                  OMXCATBAR(ICJP_EncodeHuffmanSpecInit_U8, OMXICJP_SUFFIX)
+
+#define omxIPBM_AddC_U8_C1R_Sfs                           OMXCATBAR(IPBM_AddC_U8_C1R_Sfs, OMXIPBM_SUFFIX)
+#define omxIPBM_Copy_U8_C1R                               OMXCATBAR(IPBM_Copy_U8_C1R, OMXIPBM_SUFFIX)
+#define omxIPBM_Copy_U8_C3R                               OMXCATBAR(IPBM_Copy_U8_C3R, OMXIPBM_SUFFIX)
+#define omxIPBM_Mirror_U8_C1R                             OMXCATBAR(IPBM_Mirror_U8_C1R, OMXIPBM_SUFFIX)
+#define omxIPBM_MulC_U8_C1R_Sfs                           OMXCATBAR(IPBM_MulC_U8_C1R_Sfs, OMXIPBM_SUFFIX)
+
+#define omxIPCS_ColorTwistQ14_U8_C3R                      OMXCATBAR(IPCS_ColorTwistQ14_U8_C3R, OMXIPCS_SUFFIX)
+#define omxIPCS_BGR565ToYCbCr420LS_MCU_U16_S16_C3P3R      OMXCATBAR(IPCS_BGR565ToYCbCr420LS_MCU_U16_S16_C3P3R, OMXIPCS_SUFFIX)
+#define omxIPCS_BGR565ToYCbCr422LS_MCU_U16_S16_C3P3R      OMXCATBAR(IPCS_BGR565ToYCbCr422LS_MCU_U16_S16_C3P3R, OMXIPCS_SUFFIX)
+#define omxIPCS_BGR565ToYCbCr444LS_MCU_U16_S16_C3P3R      OMXCATBAR(IPCS_BGR565ToYCbCr444LS_MCU_U16_S16_C3P3R, OMXIPCS_SUFFIX)
+#define omxIPCS_BGR888ToYCbCr420LS_MCU_U8_S16_C3P3R       OMXCATBAR(IPCS_BGR888ToYCbCr420LS_MCU_U8_S16_C3P3R, OMXIPCS_SUFFIX)
+#define omxIPCS_BGR888ToYCbCr422LS_MCU_U8_S16_C3P3R       OMXCATBAR(IPCS_BGR888ToYCbCr422LS_MCU_U8_S16_C3P3R, OMXIPCS_SUFFIX)
+#define omxIPCS_BGR888ToYCbCr444LS_MCU_U8_S16_C3P3R       OMXCATBAR(IPCS_BGR888ToYCbCr444LS_MCU_U8_S16_C3P3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr420RszCscRotBGR_U8_P3C3R             OMXCATBAR(IPCS_YCbCr420RszCscRotBGR_U8_P3C3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr420RszRot_U8_P3R                     OMXCATBAR(IPCS_YCbCr420RszRot_U8_P3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr420ToBGR565_U8_U16_P3C3R             OMXCATBAR(IPCS_YCbCr420ToBGR565_U8_U16_P3C3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr420ToBGR565LS_MCU_S16_U16_P3C3R      OMXCATBAR(IPCS_YCbCr420ToBGR565LS_MCU_S16_U16_P3C3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr420ToBGR888LS_MCU_S16_U8_P3C3R       OMXCATBAR(IPCS_YCbCr420ToBGR888LS_MCU_S16_U8_P3C3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr422RszCscRotBGR_U8_P3C3R             OMXCATBAR(IPCS_YCbCr422RszCscRotBGR_U8_P3C3R, OMXIPCS_SUFFIX)
+#define omxIPCS_CbYCrY422RszCscRotBGR_U8_U16_C2R          OMXCATBAR(IPCS_CbYCrY422RszCscRotBGR_U8_U16_C2R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr422RszRot_U8_P3R                     OMXCATBAR(IPCS_YCbCr422RszRot_U8_P3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbYCr422ToBGR565_U8_U16_C2C3R            OMXCATBAR(IPCS_YCbYCr422ToBGR565_U8_U16_C2C3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr422ToBGR565LS_MCU_S16_U16_P3C3R      OMXCATBAR(IPCS_YCbCr422ToBGR565LS_MCU_S16_U16_P3C3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbYCr422ToBGR888_U8_C2C3R                OMXCATBAR(IPCS_YCbYCr422ToBGR888_U8_C2C3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr422ToBGR888LS_MCU_S16_U8_P3C3R       OMXCATBAR(IPCS_YCbCr422ToBGR888LS_MCU_S16_U8_P3C3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr422ToBGR888LS_MCU_S16_U8_P3C3R       OMXCATBAR(IPCS_YCbCr422ToBGR888LS_MCU_S16_U8_P3C3R, OMXIPCS_SUFFIX)
+#define omxIPCS_CbYCrY422ToYCbCr420Rotate_U8_C2P3R        OMXCATBAR(IPCS_CbYCrY422ToYCbCr420Rotate_U8_C2P3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr422ToYCbCr420Rotate_U8_P3R           OMXCATBAR(IPCS_YCbCr422ToYCbCr420Rotate_U8_P3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr444ToBGR565_U8_U16_C3R               OMXCATBAR(IPCS_YCbCr444ToBGR565_U8_U16_C3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr444ToBGR565_U8_U16_P3C3R             OMXCATBAR(IPCS_YCbCr444ToBGR565_U8_U16_P3C3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr444ToBGR565LS_MCU_S16_U16_P3C3R      OMXCATBAR(IPCS_YCbCr444ToBGR565LS_MCU_S16_U16_P3C3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr444ToBGR888_U8_C3R                   OMXCATBAR(IPCS_YCbCr444ToBGR888_U8_C3R, OMXIPCS_SUFFIX)
+
+#define omxIPPP_Deblock_HorEdge_U8_I                      OMXCATBAR(IPPP_Deblock_HorEdge_U8_I, OMXIPPP_SUFFIX)
+#define omxIPPP_Deblock_VerEdge_U8_I                      OMXCATBAR(IPPP_Deblock_VerEdge_U8_I, OMXIPPP_SUFFIX)
+#define omxIPPP_FilterFIR_U8_C1R                          OMXCATBAR(IPPP_FilterFIR_U8_C1R, OMXIPPP_SUFFIX)
+#define omxIPPP_FilterMedian_U8_C1R                       OMXCATBAR(IPPP_FilterMedian_U8_C1R, OMXIPPP_SUFFIX)
+#define omxIPPP_GetCentralMoment_S64                      OMXCATBAR(IPPP_GetCentralMoment_S64, OMXIPPP_SUFFIX)
+#define omxIPPP_GetSpatialMoment_S64                      OMXCATBAR(IPPP_GetSpatialMoment_S64, OMXIPPP_SUFFIX)
+#define omxIPPP_MomentGetStateSize                        OMXCATBAR(IPPP_MomentGetStateSize, OMXIPPP_SUFFIX)
+#define omxIPPP_MomentInit                                OMXCATBAR(IPPP_MomentInit, OMXIPPP_SUFFIX)
+#define omxIPPP_Moments_U8_C1R                            OMXCATBAR(IPPP_Moments_U8_C1R, OMXIPPP_SUFFIX)
+#define omxIPPP_Moments_U8_C3R                            OMXCATBAR(IPPP_Moments_U8_C3R, OMXIPPP_SUFFIX)
+
+#define omxSP_BlockExp_S16                                OMXCATBAR(SP_BlockExp_S16, OMXSP_SUFFIX)
+#define omxSP_BlockExp_S32                                OMXCATBAR(SP_BlockExp_S32, OMXSP_SUFFIX)
+#define omxSP_Copy_S16                                    OMXCATBAR(SP_Copy_S16, OMXSP_SUFFIX)
+#define omxSP_DotProd_S16                                 OMXCATBAR(SP_DotProd_S16, OMXSP_SUFFIX)
+#define omxSP_DotProd_S16_Sfs                             OMXCATBAR(SP_DotProd_S16_Sfs, OMXSP_SUFFIX)
+#define omxSP_FFTFwd_CToC_SC16_Sfs                        OMXCATBAR(SP_FFTFwd_CToC_SC16_Sfs, OMXSP_SUFFIX)
+#define omxSP_FFTFwd_CToC_SC32_Sfs                        OMXCATBAR(SP_FFTFwd_CToC_SC32_Sfs, OMXSP_SUFFIX)
+#define omxSP_FFTFwd_RToCCS_S16S32_Sfs                    OMXCATBAR(SP_FFTFwd_RToCCS_S16S32_Sfs, OMXSP_SUFFIX)
+#define omxSP_FFTFwd_RToCCS_S32_Sfs                       OMXCATBAR(SP_FFTFwd_RToCCS_S32_Sfs, OMXSP_SUFFIX)
+#define omxSP_FFTGetBufSize_C_SC16                        OMXCATBAR(SP_FFTGetBufSize_C_SC16, OMXSP_SUFFIX)
+#define omxSP_FFTGetBufSize_C_SC32                        OMXCATBAR(SP_FFTGetBufSize_C_SC32, OMXSP_SUFFIX)
+#define omxSP_FFTGetBufSize_R_S16S32                      OMXCATBAR(SP_FFTGetBufSize_R_S16S32, OMXSP_SUFFIX)
+#define omxSP_FFTGetBufSize_R_S32                         OMXCATBAR(SP_FFTGetBufSize_R_S32, OMXSP_SUFFIX)
+#define omxSP_FFTInit_C_SC16                              OMXCATBAR(SP_FFTInit_C_SC16, OMXSP_SUFFIX)
+#define omxSP_FFTInit_C_SC32                              OMXCATBAR(SP_FFTInit_C_SC32, OMXSP_SUFFIX)
+#define omxSP_FFTInit_R_S16S32                            OMXCATBAR(SP_FFTInit_R_S16S32, OMXSP_SUFFIX)
+#define omxSP_FFTInit_R_S32                               OMXCATBAR(SP_FFTInit_R_S32, OMXSP_SUFFIX)
+#define omxSP_FFTInv_CCSToR_S32_Sfs                       OMXCATBAR(SP_FFTInv_CCSToR_S32_Sfs, OMXSP_SUFFIX)
+#define omxSP_FFTInv_CCSToR_S32S16_Sfs                    OMXCATBAR(SP_FFTInv_CCSToR_S32S16_Sfs, OMXSP_SUFFIX)
+#define omxSP_FFTInv_CToC_SC16_Sfs                        OMXCATBAR(SP_FFTInv_CToC_SC16_Sfs, OMXSP_SUFFIX)
+#define omxSP_FFTInv_CToC_SC32_Sfs                        OMXCATBAR(SP_FFTInv_CToC_SC32_Sfs, OMXSP_SUFFIX)
+#define omxSP_FilterMedian_S32                            OMXCATBAR(SP_FilterMedian_S32, OMXSP_SUFFIX)
+#define omxSP_FilterMedian_S32_I                          OMXCATBAR(SP_FilterMedian_S32_I, OMXSP_SUFFIX)
+#define omxSP_FIR_Direct_S16                              OMXCATBAR(SP_FIR_Direct_S16, OMXSP_SUFFIX)
+#define omxSP_FIR_Direct_S16_I                            OMXCATBAR(SP_FIR_Direct_S16_I, OMXSP_SUFFIX)
+#define omxSP_FIR_Direct_S16_ISfs                         OMXCATBAR(SP_FIR_Direct_S16_ISfs, OMXSP_SUFFIX)
+#define omxSP_FIR_Direct_S16_Sfs                          OMXCATBAR(SP_FIR_Direct_S16_Sfs, OMXSP_SUFFIX)
+#define omxSP_FIROne_Direct_S16                           OMXCATBAR(SP_FIROne_Direct_S16, OMXSP_SUFFIX)
+#define omxSP_FIROne_Direct_S16_I                         OMXCATBAR(SP_FIROne_Direct_S16_I, OMXSP_SUFFIX)
+#define omxSP_FIROne_Direct_S16_ISfs                      OMXCATBAR(SP_FIROne_Direct_S16_ISfs, OMXSP_SUFFIX)
+#define omxSP_FIROne_Direct_S16_Sfs                       OMXCATBAR(SP_FIROne_Direct_S16_Sfs, OMXSP_SUFFIX)
+#define omxSP_IIR_BiQuadDirect_S16                        OMXCATBAR(SP_IIR_BiQuadDirect_S16, OMXSP_SUFFIX)
+#define omxSP_IIR_BiQuadDirect_S16_I                      OMXCATBAR(SP_IIR_BiQuadDirect_S16_I, OMXSP_SUFFIX)
+#define omxSP_IIR_Direct_S16                              OMXCATBAR(SP_IIR_Direct_S16, OMXSP_SUFFIX)
+#define omxSP_IIR_Direct_S16_I                            OMXCATBAR(SP_IIR_Direct_S16_I, OMXSP_SUFFIX)
+#define omxSP_IIROne_BiQuadDirect_S16                     OMXCATBAR(SP_IIROne_BiQuadDirect_S16, OMXSP_SUFFIX)
+#define omxSP_IIROne_BiQuadDirect_S16_I                   OMXCATBAR(SP_IIROne_BiQuadDirect_S16_I, OMXSP_SUFFIX)
+#define omxSP_IIROne_Direct_S16                           OMXCATBAR(SP_IIROne_Direct_S16, OMXSP_SUFFIX)
+#define omxSP_IIROne_Direct_S16_I                         OMXCATBAR(SP_IIROne_Direct_S16_I, OMXSP_SUFFIX)
+
+#define omxVCCOMM_Average_16x                             OMXCATBAR(VCCOMM_Average_16x, OMXVCCOMM_SUFFIX)
+#define omxVCCOMM_Average_8x                              OMXCATBAR(VCCOMM_Average_8x, OMXVCCOMM_SUFFIX)
+#define omxVCCOMM_ComputeTextureErrorBlock                OMXCATBAR(VCCOMM_ComputeTextureErrorBlock, OMXVCCOMM_SUFFIX)
+#define omxVCCOMM_ComputeTextureErrorBlock_SAD            OMXCATBAR(VCCOMM_ComputeTextureErrorBlock_SAD, OMXVCCOMM_SUFFIX)
+#define omxVCCOMM_Copy16x16                               OMXCATBAR(VCCOMM_Copy16x16, OMXVCCOMM_SUFFIX)
+#define omxVCCOMM_Copy8x8                                 OMXCATBAR(VCCOMM_Copy8x8, OMXVCCOMM_SUFFIX)
+#define omxVCCOMM_ExpandFrame_I                           OMXCATBAR(VCCOMM_ExpandFrame_I, OMXVCCOMM_SUFFIX)
+#define omxVCCOMM_LimitMVToRect                           OMXCATBAR(VCCOMM_LimitMVToRect, OMXVCCOMM_SUFFIX)
+#define omxVCCOMM_SAD_16x                                 OMXCATBAR(VCCOMM_SAD_16x, OMXVCCOMM_SUFFIX)
+#define omxVCCOMM_SAD_8x                                  OMXCATBAR(VCCOMM_SAD_8x, OMXVCCOMM_SUFFIX)
+
+#define omxVCM4P10_Average_4x                             OMXCATBAR(VCM4P10_Average_4x, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_BlockMatch_Half                        OMXCATBAR(VCM4P10_BlockMatch_Half, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_BlockMatch_Integer                     OMXCATBAR(VCM4P10_BlockMatch_Integer, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_BlockMatch_Quarter                     OMXCATBAR(VCM4P10_BlockMatch_Quarter, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_DeblockChroma_I                        OMXCATBAR(VCM4P10_DeblockChroma_I, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_DeblockLuma_I                          OMXCATBAR(VCM4P10_DeblockLuma_I, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_DecodeChromaDcCoeffsToPairCAVLC        OMXCATBAR(VCM4P10_DecodeChromaDcCoeffsToPairCAVLC, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_DecodeCoeffsToPairCAVLC                OMXCATBAR(VCM4P10_DecodeCoeffsToPairCAVLC, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_DequantTransformResidualFromPairAndAdd OMXCATBAR(VCM4P10_DequantTransformResidualFromPairAndAdd, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_FilterDeblockingChroma_HorEdge_I       OMXCATBAR(VCM4P10_FilterDeblockingChroma_HorEdge_I, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_FilterDeblockingChroma_VerEdge_I       OMXCATBAR(VCM4P10_FilterDeblockingChroma_VerEdge_I, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_FilterDeblockingLuma_HorEdge_I         OMXCATBAR(VCM4P10_FilterDeblockingLuma_HorEdge_I, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_FilterDeblockingLuma_VerEdge_I         OMXCATBAR(VCM4P10_FilterDeblockingLuma_VerEdge_I, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_GetVLCInfo                             OMXCATBAR(VCM4P10_GetVLCInfo, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_InterpolateChroma                      OMXCATBAR(VCM4P10_InterpolateChroma, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_InterpolateHalfHor_Luma                OMXCATBAR(VCM4P10_InterpolateHalfHor_Luma, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_InterpolateHalfVer_Luma                OMXCATBAR(VCM4P10_InterpolateHalfVer_Luma, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_InterpolateLuma                        OMXCATBAR(VCM4P10_InterpolateLuma, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_InvTransformDequant_ChromaDC           OMXCATBAR(VCM4P10_InvTransformDequant_ChromaDC, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_InvTransformDequant_LumaDC             OMXCATBAR(VCM4P10_InvTransformDequant_LumaDC, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_InvTransformResidualAndAdd             OMXCATBAR(VCM4P10_InvTransformResidualAndAdd, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_MEGetBufSize                           OMXCATBAR(VCM4P10_MEGetBufSize, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_MEInit                                 OMXCATBAR(VCM4P10_MEInit, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_MotionEstimationMB                     OMXCATBAR(VCM4P10_MotionEstimationMB, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_PredictIntra_16x16                     OMXCATBAR(VCM4P10_PredictIntra_16x16, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_PredictIntra_4x4                       OMXCATBAR(VCM4P10_PredictIntra_4x4, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_PredictIntraChroma_8x8                  OMXCATBAR(VCM4P10_PredictIntraChroma_8x8, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_SAD_4x                                 OMXCATBAR(VCM4P10_SAD_4x, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_SADQuar_16x                            OMXCATBAR(VCM4P10_SADQuar_16x, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_SADQuar_4x                             OMXCATBAR(VCM4P10_SADQuar_4x, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_SADQuar_8x                             OMXCATBAR(VCM4P10_SADQuar_8x, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_SATD_4x4                               OMXCATBAR(VCM4P10_SATD_4x4, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_SubAndTransformQDQResidual             OMXCATBAR(VCM4P10_SubAndTransformQDQResidual, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_TransformDequantChromaDCFromPair       OMXCATBAR(VCM4P10_TransformDequantChromaDCFromPair, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_TransformDequantLumaDCFromPair         OMXCATBAR(VCM4P10_TransformDequantLumaDCFromPair, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_TransformQuant_ChromaDC                OMXCATBAR(VCM4P10_TransformQuant_ChromaDC, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_TransformQuant_LumaDC                  OMXCATBAR(VCM4P10_TransformQuant_LumaDC, OMXVCM4P10_SUFFIX)
+
+#define omxVCM4P2_BlockMatch_Half_16x16                   OMXCATBAR(VCM4P2_BlockMatch_Half_16x16, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_BlockMatch_Half_8x8                     OMXCATBAR(VCM4P2_BlockMatch_Half_8x8, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_BlockMatch_Integer_16x16                OMXCATBAR(VCM4P2_BlockMatch_Integer_16x16, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_BlockMatch_Integer_8x8                  OMXCATBAR(VCM4P2_BlockMatch_Integer_8x8, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_DCT8x8blk                               OMXCATBAR(VCM4P2_DCT8x8blk, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_DecodeBlockCoef_Inter                   OMXCATBAR(VCM4P2_DecodeBlockCoef_Inter, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_DecodeBlockCoef_Intra                   OMXCATBAR(VCM4P2_DecodeBlockCoef_Intra, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_DecodePadMV_PVOP                        OMXCATBAR(VCM4P2_DecodePadMV_PVOP, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_DecodeVLCZigzag_Inter                   OMXCATBAR(VCM4P2_DecodeVLCZigzag_Inter, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_DecodeVLCZigzag_IntraACVLC              OMXCATBAR(VCM4P2_DecodeVLCZigzag_IntraACVLC, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_DecodeVLCZigzag_IntraDCVLC              OMXCATBAR(VCM4P2_DecodeVLCZigzag_IntraDCVLC, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_EncodeMV                                OMXCATBAR(VCM4P2_EncodeMV, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_EncodeVLCZigzag_Inter                   OMXCATBAR(VCM4P2_EncodeVLCZigzag_Inter, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_EncodeVLCZigzag_IntraACVLC              OMXCATBAR(VCM4P2_EncodeVLCZigzag_IntraACVLC, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_EncodeVLCZigzag_IntraDCVLC              OMXCATBAR(VCM4P2_EncodeVLCZigzag_IntraDCVLC, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_FindMVpred                              OMXCATBAR(VCM4P2_FindMVpred, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_IDCT8x8blk                              OMXCATBAR(VCM4P2_IDCT8x8blk, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_MCReconBlock                            OMXCATBAR(VCM4P2_MCReconBlock, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_MEGetBufSize                            OMXCATBAR(VCM4P2_MEGetBufSize, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_MEInit                                  OMXCATBAR(VCM4P2_MEInit, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_MotionEstimationMB                      OMXCATBAR(VCM4P2_MotionEstimationMB, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_PredictReconCoefIntra                   OMXCATBAR(VCM4P2_PredictReconCoefIntra, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_QuantInter_I                            OMXCATBAR(VCM4P2_QuantInter_I, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_QuantIntra_I                            OMXCATBAR(VCM4P2_QuantIntra_I, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_QuantInvInter_I                         OMXCATBAR(VCM4P2_QuantInvInter_I, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_QuantInvIntra_I                         OMXCATBAR(VCM4P2_QuantInvIntra_I, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_TransRecBlockCoef_inter                 OMXCATBAR(VCM4P2_TransRecBlockCoef_inter, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_TransRecBlockCoef_intra                 OMXCATBAR(VCM4P2_TransRecBlockCoef_intra, OMXVCM4P2_SUFFIX)
+
+
+#endif /* _armOMX_h_ */
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/omxtypes.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/omxtypes.h
new file mode 100755
index 0000000..8b295a6
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/omxtypes.h
@@ -0,0 +1,252 @@
+/**
+ * File: omxtypes.h
+ * Brief: Defines basic Data types used in OpenMAX v1.0.2 header files.
+ *
+ * Copyright © 2005-2008 The Khronos Group Inc. All Rights Reserved. 
+ *
+ * These materials are protected by copyright laws and contain material 
+ * proprietary to the Khronos Group, Inc.  You may use these materials 
+ * for implementing Khronos specifications, without altering or removing 
+ * any trademark, copyright or other notice from the specification.
+ * 
+ * Khronos Group makes no, and expressly disclaims any, representations 
+ * or warranties, express or implied, regarding these materials, including, 
+ * without limitation, any implied warranties of merchantability or fitness 
+ * for a particular purpose or non-infringement of any intellectual property. 
+ * Khronos Group makes no, and expressly disclaims any, warranties, express 
+ * or implied, regarding the correctness, accuracy, completeness, timeliness, 
+ * and reliability of these materials. 
+ *
+ * Under no circumstances will the Khronos Group, or any of its Promoters, 
+ * Contributors or Members or their respective partners, officers, directors, 
+ * employees, agents or representatives be liable for any damages, whether 
+ * direct, indirect, special or consequential damages for lost revenues, 
+ * lost profits, or otherwise, arising from or in connection with these 
+ * materials.
+ * 
+ * Khronos and OpenMAX are trademarks of the Khronos Group Inc. 
+ *
+ */
+  
+#ifndef _OMXTYPES_H_
+#define _OMXTYPES_H_
+
+#include <limits.h> 
+
+#define OMX_IN
+#define OMX_OUT
+#define OMX_INOUT
+
+
+typedef enum {
+    
+    /* Mandatory return codes - use cases are explicitly described for each function */
+    OMX_Sts_NoErr                    =  0,    /* No error, the function completed successfully */
+    OMX_Sts_Err                      = -2,    /* Unknown/unspecified error */    
+    OMX_Sts_InvalidBitstreamValErr   = -182,  /* Invalid value detected during bitstream processing */    
+    OMX_Sts_MemAllocErr              = -9,    /* Not enough memory allocated for the operation */
+    OMX_StsACAAC_GainCtrErr    	     = -159,  /* AAC: Unsupported gain control data detected */
+    OMX_StsACAAC_PrgNumErr           = -167,  /* AAC: Invalid number of elements for one program   */
+    OMX_StsACAAC_CoefValErr          = -163,  /* AAC: Invalid quantized coefficient value          */     
+    OMX_StsACAAC_MaxSfbErr           = -162,  /* AAC: Invalid maxSfb value in relation to numSwb */    
+	OMX_StsACAAC_PlsDataErr		     = -160,  /* AAC: pulse escape sequence data error */
+
+    /* Optional return codes - use cases are explicitly described for each function*/
+    OMX_Sts_BadArgErr                = -5,    /* Bad Arguments */
+
+    OMX_StsACAAC_TnsNumFiltErr       = -157,  /* AAC: Invalid number of TNS filters  */
+    OMX_StsACAAC_TnsLenErr           = -156,  /* AAC: Invalid TNS region length  */   
+    OMX_StsACAAC_TnsOrderErr         = -155,  /* AAC: Invalid order of TNS filter  */                  
+    OMX_StsACAAC_TnsCoefResErr       = -154,  /* AAC: Invalid bit-resolution for TNS filter coefficients  */
+    OMX_StsACAAC_TnsCoefErr          = -153,  /* AAC: Invalid TNS filter coefficients  */                  
+    OMX_StsACAAC_TnsDirectErr        = -152,  /* AAC: Invalid TNS filter direction  */  
+
+    OMX_StsICJP_JPEGMarkerErr        = -183,  /* JPEG marker encountered within an entropy-coded block; */
+                                              /* Huffman decoding operation terminated early.           */
+    OMX_StsICJP_JPEGMarker           = -181,  /* JPEG marker encountered; Huffman decoding */
+                                              /* operation terminated early.                         */
+    OMX_StsIPPP_ContextMatchErr      = -17,   /* Context parameter doesn't match to the operation */
+
+    OMX_StsSP_EvenMedianMaskSizeErr  = -180,  /* Even size of the Median Filter mask was replaced by the odd one */
+
+    OMX_Sts_MaximumEnumeration       = INT_MAX  /*Placeholder, forces enum of size OMX_INT*/
+    
+ } OMXResult;          /** Return value or error value returned from a function. Identical to OMX_INT */
+
+ 
+/* OMX_U8 */
+#if UCHAR_MAX == 0xff
+typedef unsigned char OMX_U8;
+#elif USHRT_MAX == 0xff 
+typedef unsigned short int OMX_U8; 
+#else
+#error OMX_U8 undefined
+#endif 
+
+ 
+/* OMX_S8 */
+#if SCHAR_MAX == 0x7f 
+typedef signed char OMX_S8;
+#elif SHRT_MAX == 0x7f 
+typedef signed short int OMX_S8; 
+#else
+#error OMX_S8 undefined
+#endif
+ 
+ 
+/* OMX_U16 */
+#if USHRT_MAX == 0xffff
+typedef unsigned short int OMX_U16;
+#elif UINT_MAX == 0xffff
+typedef unsigned int OMX_U16; 
+#else
+#error OMX_U16 undefined
+#endif
+
+
+/* OMX_S16 */
+#if SHRT_MAX == 0x7fff 
+typedef signed short int OMX_S16;
+#elif INT_MAX == 0x7fff 
+typedef signed int OMX_S16; 
+#else
+#error OMX_S16 undefined
+#endif
+
+
+/* OMX_U32 */
+#if UINT_MAX == 0xffffffff
+typedef unsigned int OMX_U32;
+#elif LONG_MAX == 0xffffffff
+typedef unsigned long int OMX_U32; 
+#else
+#error OMX_U32 undefined
+#endif
+
+
+/* OMX_S32 */
+#if INT_MAX == 0x7fffffff
+typedef signed int OMX_S32;
+#elif LONG_MAX == 0x7fffffff
+typedef long signed int OMX_S32; 
+#else
+#error OMX_S32 undefined
+#endif
+
+
+/* OMX_U64 & OMX_S64 */
+#if defined( _WIN32 ) || defined ( _WIN64 )
+    typedef __int64 OMX_S64; /** Signed 64-bit integer */
+    typedef unsigned __int64 OMX_U64; /** Unsigned 64-bit integer */
+    #define OMX_MIN_S64			(0x8000000000000000i64)
+    #define OMX_MIN_U64			(0x0000000000000000i64)
+    #define OMX_MAX_S64			(0x7FFFFFFFFFFFFFFFi64)
+    #define OMX_MAX_U64			(0xFFFFFFFFFFFFFFFFi64)
+#else
+    typedef long long OMX_S64; /** Signed 64-bit integer */
+    typedef unsigned long long OMX_U64; /** Unsigned 64-bit integer */
+    #define OMX_MIN_S64			(0x8000000000000000LL)
+    #define OMX_MIN_U64			(0x0000000000000000LL)
+    #define OMX_MAX_S64			(0x7FFFFFFFFFFFFFFFLL)
+    #define OMX_MAX_U64			(0xFFFFFFFFFFFFFFFFLL)
+#endif
+
+
+/* OMX_SC8 */
+typedef struct
+{
+  OMX_S8 Re; /** Real part */
+  OMX_S8 Im; /** Imaginary part */	
+	
+} OMX_SC8; /** Signed 8-bit complex number */
+
+
+/* OMX_SC16 */
+typedef struct
+{
+  OMX_S16 Re; /** Real part */
+  OMX_S16 Im; /** Imaginary part */	
+	
+} OMX_SC16; /** Signed 16-bit complex number */
+
+
+/* OMX_SC32 */
+typedef struct
+{
+  OMX_S32 Re; /** Real part */
+  OMX_S32 Im; /** Imaginary part */	
+	
+} OMX_SC32; /** Signed 32-bit complex number */
+
+
+/* OMX_SC64 */
+typedef struct
+{
+  OMX_S64 Re; /** Real part */
+  OMX_S64 Im; /** Imaginary part */	
+	
+} OMX_SC64; /** Signed 64-bit complex number */
+
+
+/* OMX_F32 */
+typedef float OMX_F32; /** Single precision floating point,IEEE 754 */
+
+
+/* OMX_F64 */
+typedef double OMX_F64; /** Double precision floating point,IEEE 754 */
+
+
+/* OMX_INT */
+typedef int OMX_INT; /** signed integer corresponding to machine word length, has maximum signed value INT_MAX*/
+
+
+#define OMX_MIN_S8  	   	(-128)
+#define OMX_MIN_U8  		0
+#define OMX_MIN_S16		 	(-32768)
+#define OMX_MIN_U16			0
+#define OMX_MIN_S32			(-2147483647-1)
+#define OMX_MIN_U32			0
+
+#define OMX_MAX_S8			(127)
+#define OMX_MAX_U8			(255)
+#define OMX_MAX_S16			(32767)
+#define OMX_MAX_U16			(0xFFFF)
+#define OMX_MAX_S32			(2147483647)
+#define OMX_MAX_U32			(0xFFFFFFFF)
+
+typedef void OMXVoid;
+
+#ifndef NULL
+#define NULL ((void*)0)
+#endif
+
+/** Defines the geometric position and size of a rectangle, 
+  * where x,y defines the coordinates of the top left corner
+  * of the rectangle, with dimensions width in the x-direction 
+  * and height in the y-direction */
+typedef struct {
+	OMX_INT x;      /** x-coordinate of top left corner of rectangle */
+	OMX_INT y;      /** y-coordinate of top left corner of rectangle */
+	OMX_INT width;  /** Width in the x-direction. */
+	OMX_INT height; /** Height in the y-direction. */
+}OMXRect;
+
+
+/** Defines the geometric position of a point, */
+typedef struct 
+{
+ OMX_INT x; /** x-coordinate */
+ OMX_INT y;	/** y-coordinate */
+	
+} OMXPoint;
+
+
+/** Defines the dimensions of a rectangle, or region of interest in an image */
+typedef struct 
+{
+ OMX_INT width;  /** Width of the rectangle, in the x-direction */
+ OMX_INT height; /** Height of the rectangle, in the y-direction */
+	
+} OMXSize;
+
+#endif /* _OMXTYPES_H_ */
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/omxtypes_s.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/omxtypes_s.h
new file mode 100755
index 0000000..48703d1
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/omxtypes_s.h
@@ -0,0 +1,77 @@
+;//
+;// 
+;// File Name:  omxtypes_s.h
+;// OpenMAX DL: v1.0.2
+;// Revision:   12290
+;// Date:       Wednesday, April 9, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+;// Mandatory return codes - use cases are explicitly described for each function 
+OMX_Sts_NoErr                    EQU  0    ;// No error the function completed successfully 
+OMX_Sts_Err                      EQU -2    ;// Unknown/unspecified error     
+OMX_Sts_InvalidBitstreamValErr   EQU -182  ;// Invalid value detected during bitstream processing     
+OMX_Sts_MemAllocErr              EQU -9    ;// Not enough memory allocated for the operation 
+OMX_StsACAAC_GainCtrErr    	     EQU -159  ;// AAC: Unsupported gain control data detected 
+OMX_StsACAAC_PrgNumErr           EQU -167  ;// AAC: Invalid number of elements for one program   
+OMX_StsACAAC_CoefValErr          EQU -163  ;// AAC: Invalid quantized coefficient value               
+OMX_StsACAAC_MaxSfbErr           EQU -162  ;// AAC: Invalid maxSfb value in relation to numSwb     
+OMX_StsACAAC_PlsDataErr		     EQU -160  ;// AAC: pulse escape sequence data error 
+
+;// Optional return codes - use cases are explicitly described for each function
+OMX_Sts_BadArgErr                EQU -5    ;// Bad Arguments 
+
+OMX_StsACAAC_TnsNumFiltErr       EQU -157  ;// AAC: Invalid number of TNS filters  
+OMX_StsACAAC_TnsLenErr           EQU -156  ;// AAC: Invalid TNS region length     
+OMX_StsACAAC_TnsOrderErr         EQU -155  ;// AAC: Invalid order of TNS filter                    
+OMX_StsACAAC_TnsCoefResErr       EQU -154  ;// AAC: Invalid bit-resolution for TNS filter coefficients  
+OMX_StsACAAC_TnsCoefErr          EQU -153  ;// AAC: Invalid TNS filter coefficients                    
+OMX_StsACAAC_TnsDirectErr        EQU -152  ;// AAC: Invalid TNS filter direction    
+
+OMX_StsICJP_JPEGMarkerErr        EQU -183  ;// JPEG marker encountered within an entropy-coded block; 
+                                            ;// Huffman decoding operation terminated early.           
+OMX_StsICJP_JPEGMarker           EQU -181  ;// JPEG marker encountered; Huffman decoding 
+                                            ;// operation terminated early.                         
+OMX_StsIPPP_ContextMatchErr      EQU -17   ;// Context parameter doesn't match to the operation 
+
+OMX_StsSP_EvenMedianMaskSizeErr  EQU -180  ;// Even size of the Median Filter mask was replaced by the odd one 
+
+OMX_Sts_MaximumEnumeration       EQU 0x7FFFFFFF
+
+
+
+OMX_MIN_S8      EQU 	   	(-128)
+OMX_MIN_U8  	EQU     	0
+OMX_MIN_S16		EQU      	(-32768)
+OMX_MIN_U16		EQU	        0
+
+
+OMX_MIN_S32		EQU	(-2147483647-1)
+OMX_MIN_U32		EQU	0
+
+OMX_MAX_S8		EQU	(127)
+OMX_MAX_U8		EQU	(255)
+OMX_MAX_S16		EQU	(32767)
+OMX_MAX_U16		EQU	(0xFFFF)
+OMX_MAX_S32		EQU	(2147483647)
+OMX_MAX_U32		EQU	(0xFFFFFFFF)
+
+OMX_VC_UPPER    EQU 0x1                 ;// Used by the PredictIntra functions   
+OMX_VC_LEFT     EQU 0x2                 ;// Used by the PredictIntra functions 
+OMX_VC_UPPER_RIGHT    EQU 0x40          ;// Used by the PredictIntra functions   
+
+NULL    EQU 0
+
+;// Structures
+
+    INCLUDE     armCOMM_s.h
+
+    M_STRUCT    OMXPoint
+    M_FIELD     x, 4
+    M_FIELD     y, 4
+    M_ENDSTRUCT
+
+        END
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/build_vc.pl b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/build_vc.pl
new file mode 100755
index 0000000..649e74c
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/build_vc.pl
@@ -0,0 +1,113 @@
+#!/usr/bin/perl
+#
+# 
+# File Name:  build_vc.pl
+# OpenMAX DL: v1.0.2
+# Revision:   12290
+# Date:       Wednesday, April 9, 2008
+# 
+# (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+# 
+# 
+#
+# This file builds the OpenMAX DL vc domain library omxVC.o.
+#
+
+use File::Spec;
+use strict;
+
+my ($CC, $CC_OPTS, $AS, $AS_OPTS, $LIB, $LIB_OPTS, $LIB_TYPE);
+
+$CC       = 'armcc';
+$CC_OPTS  = '--no_unaligned_access --cpu Cortex-A8 -c';
+$AS       = 'armasm';
+$AS_OPTS  = '--no_unaligned_access --cpu Cortex-A8';
+# $LIB      = 'armlink';
+# $LIB_OPTS = '--partial -o';
+# $LIB_TYPE = '.o';
+$LIB      = 'armar';
+$LIB_OPTS = '--create -r';
+$LIB_TYPE = '.a';
+
+#------------------------
+
+my (@headerlist, @filelist, $hd, $file, $ofile, $command, $objlist, $libfile, $h);
+
+# Define the list of directories containing included header files.
+@headerlist = qw(api vc/api vc/m4p2/api vc/m4p10/api);
+
+# Define the list of source files to compile.
+open(FILES, '<filelist_vc.txt') or die("Can't open source file list\n");
+@filelist = <FILES>;
+close(FILES);
+
+# Fix the file separators in the header paths
+foreach $h (@headerlist)
+{
+        $h = File::Spec->canonpath($h);
+}
+
+# Create the include path to be passed to the compiler
+$hd = '-I' . join(' -I', @headerlist);
+
+# Create the build directories "/lib/" and "/obj/" (if they are not there already)
+mkdir "obj", 0777 if (! -d "obj");
+mkdir "lib", 0777 if (! -d "lib");
+
+$objlist = '';
+
+# Compile each file
+foreach $file (@filelist)
+{
+	my $f;
+	my $base;
+	my $ext;
+	my $objfile;
+
+	chomp($file);
+	$file = File::Spec->canonpath($file);
+
+	(undef, undef, $f) = File::Spec->splitpath($file);
+    $f=~s/[\n\f\r]//g; # Remove any end-of-line characters
+
+	if(($base, $ext) = $f =~ /(.+)\.(\w)$/)
+	{
+		$objfile = File::Spec->catfile('obj', $base.'.o');
+
+		if($ext eq 'c')
+		{
+			$objlist .= "$objfile ";
+			$command = $CC.' '.$CC_OPTS.' '.$hd.' -o '.$objfile.' '.$file;
+			print "$command\n";
+			system($command);
+		}
+		elsif($ext eq 's')
+		{
+			$objlist .= "$objfile ";
+			$command = $AS.' '.$AS_OPTS.' '.$hd.' -o '.$objfile.' '.$file;
+			print "$command\n";
+			system($command);
+		}
+		else
+		{
+			print "Ignoring file: $f\n";
+		}
+	}
+	else
+	{
+		die "No file extension found: $f\n";
+	}
+}
+
+# Do the final link stage to create the libraries.
+$libfile = File::Spec->catfile('lib', 'omxVC'.$LIB_TYPE);
+$command = $LIB.' '.$LIB_OPTS.' '.$libfile.' '.$objlist;
+print "$command\n";
+(system($command) == 0) and print "Build successful\n";
+
+
+
+
+
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/filelist_vc.txt b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/filelist_vc.txt
new file mode 100755
index 0000000..8db8eeb
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/filelist_vc.txt
@@ -0,0 +1,75 @@
+./api/armCOMM.h
+./api/armCOMM_BitDec_s.h
+./api/armCOMM_Bitstream.h
+./api/armCOMM_IDCT_s.h
+./api/armCOMM_IDCTTable.h
+./api/armCOMM_MaskTable.h
+./api/armCOMM_s.h
+./api/armCOMM_Version.h
+./api/armOMX_ReleaseVersion.h
+./api/omxtypes.h
+./api/omxtypes_s.h
+./src/armCOMM_IDCTTable.c
+./src/armCOMM_MaskTable.c
+./vc/api/armVC.h
+./vc/api/armVCCOMM_s.h
+./vc/api/omxVC.h
+./vc/api/omxVC_s.h
+./vc/comm/src/omxVCCOMM_Copy16x16_s.s
+./vc/comm/src/omxVCCOMM_Copy8x8_s.s
+./vc/comm/src/omxVCCOMM_ExpandFrame_I_s.s
+./vc/m4p10/api/armVCM4P10_CAVLCTables.h
+./vc/m4p10/src/armVCM4P10_Average_4x_Align_unsafe_s.s
+./vc/m4p10/src/armVCM4P10_CAVLCTables.c
+./vc/m4p10/src/armVCM4P10_DeblockingChroma_unsafe_s.s
+./vc/m4p10/src/armVCM4P10_DeblockingLuma_unsafe_s.s
+./vc/m4p10/src/armVCM4P10_DecodeCoeffsToPair_s.s
+./vc/m4p10/src/armVCM4P10_DequantTables_s.s
+./vc/m4p10/src/armVCM4P10_Interpolate_Chroma_s.s
+./vc/m4p10/src/armVCM4P10_InterpolateLuma_Align_unsafe_s.s
+./vc/m4p10/src/armVCM4P10_InterpolateLuma_Copy_unsafe_s.s
+./vc/m4p10/src/armVCM4P10_InterpolateLuma_DiagCopy_unsafe_s.s
+./vc/m4p10/src/armVCM4P10_InterpolateLuma_HalfDiagHorVer4x4_unsafe_s.s
+./vc/m4p10/src/armVCM4P10_InterpolateLuma_HalfDiagVerHor4x4_unsafe_s.s
+./vc/m4p10/src/armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe_s.s
+./vc/m4p10/src/armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe_s.s
+./vc/m4p10/src/armVCM4P10_QuantTables_s.s
+./vc/m4p10/src/armVCM4P10_TransformResidual4x4_s.s
+./vc/m4p10/src/armVCM4P10_UnpackBlock4x4_s.s
+./vc/m4p10/src/omxVCM4P10_DeblockChroma_I.c
+./vc/m4p10/src/omxVCM4P10_DeblockLuma_I.c
+./vc/m4p10/src/omxVCM4P10_DecodeChromaDcCoeffsToPairCAVLC.c
+./vc/m4p10/src/omxVCM4P10_DecodeCoeffsToPairCAVLC.c
+./vc/m4p10/src/omxVCM4P10_DequantTransformResidualFromPairAndAdd_s.s
+./vc/m4p10/src/omxVCM4P10_FilterDeblockingChroma_HorEdge_I_s.s
+./vc/m4p10/src/omxVCM4P10_FilterDeblockingChroma_VerEdge_I_s.s
+./vc/m4p10/src/omxVCM4P10_FilterDeblockingLuma_HorEdge_I_s.s
+./vc/m4p10/src/omxVCM4P10_FilterDeblockingLuma_VerEdge_I_s.s
+./vc/m4p10/src/omxVCM4P10_InterpolateChroma.c
+./vc/m4p10/src/omxVCM4P10_InterpolateLuma_s.s
+./vc/m4p10/src/omxVCM4P10_PredictIntra_16x16_s.s
+./vc/m4p10/src/omxVCM4P10_PredictIntra_4x4_s.s
+./vc/m4p10/src/omxVCM4P10_PredictIntraChroma_8x8_s.s
+./vc/m4p10/src/omxVCM4P10_TransformDequantChromaDCFromPair_s.s
+./vc/m4p10/src/omxVCM4P10_TransformDequantLumaDCFromPair_s.s
+./vc/m4p2/api/armVCM4P2_Huff_Tables_VLC.h
+./vc/m4p2/api/armVCM4P2_ZigZag_Tables.h
+./vc/m4p2/src/armVCM4P2_Clip8_s.s
+./vc/m4p2/src/armVCM4P2_DecodeVLCZigzag_AC_unsafe_s.s
+./vc/m4p2/src/armVCM4P2_Huff_Tables_VLC.c
+./vc/m4p2/src/armVCM4P2_Lookup_Tables.c
+./vc/m4p2/src/armVCM4P2_SetPredDir_s.s
+./vc/m4p2/src/armVCM4P2_Zigzag_Tables.c
+./vc/m4p2/src/omxVCM4P2_DecodeBlockCoef_Inter.c
+./vc/m4p2/src/omxVCM4P2_DecodeBlockCoef_Intra.c
+./vc/m4p2/src/omxVCM4P2_DecodePadMV_PVOP_s.s
+./vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_Inter_s.s
+./vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_IntraACVLC_s.s
+./vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_IntraDCVLC_s.s
+./vc/m4p2/src/omxVCM4P2_FindMVpred_s.s
+./vc/m4p2/src/omxVCM4P2_IDCT8x8blk_s.s
+./vc/m4p2/src/omxVCM4P2_MCReconBlock_s.s
+./vc/m4p2/src/omxVCM4P2_PredictReconCoefIntra_s.s
+./vc/m4p2/src/omxVCM4P2_QuantInvInter_I_s.s
+./vc/m4p2/src/omxVCM4P2_QuantInvIntra_I_s.s
+./vc/src/armVC_Version.c
\ No newline at end of file
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/src/armCOMM.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/src/armCOMM.c
new file mode 100755
index 0000000..e572a89
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/src/armCOMM.c
@@ -0,0 +1,936 @@
+/**
+ * 
+ * File Name:  armCOMM.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Defines Common APIs used across OpenMAX API's
+ */
+
+#include "omxtypes.h"
+#include "armCOMM.h"
+
+/***********************************************************************/
+                /* Miscellaneous Arithmetic operations */
+
+/**
+ * Function: armRoundFloatToS16
+ *
+ * Description:
+ * Converts a double precision value into a short int after rounding
+ *
+ * Parameters:
+ * [in]  Value                 Float value to be converted
+ *
+ * Return Value:
+ * [out] converted value in OMX_S16 format
+ *
+ */
+
+OMX_S16 armRoundFloatToS16 (OMX_F64 Value)
+{
+    if (Value > 0)
+    {
+        return (OMX_S16)(Value + .5);
+    }
+    else
+    {
+        return (OMX_S16)(Value - .5);
+    }
+}
+
+/**
+ * Function: armRoundFloatToS32
+ *
+ * Description:
+ * Converts a double precision value into a int after rounding
+ *
+ * Parameters:
+ * [in]  Value                 Float value to be converted
+ *
+ * Return Value:
+ * [out] converted value in OMX_S32 format
+ *
+ */
+
+OMX_S32 armRoundFloatToS32 (OMX_F64 Value)
+{
+    if (Value > 0)
+    {
+        return (OMX_S32)(Value + .5);
+    }
+    else
+    {
+        return (OMX_S32)(Value - .5);
+    }
+}
+/**
+ * Function: armSatRoundFloatToS16
+ *
+ * Description:
+ * Converts a double precision value into a short int after rounding and saturation
+ *
+ * Parameters:
+ * [in]  Value                 Float value to be converted
+ *
+ * Return Value:
+ * [out] converted value in OMX_S16 format
+ *
+ */
+
+OMX_S16 armSatRoundFloatToS16 (OMX_F64 Value)
+{
+    if (Value > 0)
+    {
+        Value += 0.5;
+        
+        if(Value > (OMX_S16)OMX_MAX_S16 )
+        {
+            return (OMX_S16)OMX_MAX_S16;
+        }
+        else
+        {
+            return (OMX_S16)Value;
+        }
+    }
+    else
+    {
+        Value -= 0.5;
+
+        if(Value < (OMX_S16)OMX_MIN_S16 )
+        {
+            return (OMX_S16)OMX_MIN_S16;
+        }
+        else
+        {
+            return (OMX_S16)Value;
+        }
+    }
+}
+
+/**
+ * Function: armSatRoundFloatToS32
+ *
+ * Description:
+ * Converts a double precision value into a int after rounding and saturation
+ *
+ * Parameters:
+ * [in]  Value                 Float value to be converted
+ *
+ * Return Value:
+ * [out] converted value in OMX_S32 format
+ *
+ */
+
+OMX_S32 armSatRoundFloatToS32 (OMX_F64 Value)
+{
+    if (Value > 0)
+    {
+        Value += 0.5;
+        
+        if(Value > (OMX_S32)OMX_MAX_S32 )
+        {
+            return (OMX_S32)OMX_MAX_S32;
+        }
+        else
+        {
+            return (OMX_S32)Value;
+        }
+    }
+    else
+    {
+        Value -= 0.5;
+
+        if(Value < (OMX_S32)OMX_MIN_S32 )
+        {
+            return (OMX_S32)OMX_MIN_S32;
+        }
+        else
+        {
+            return (OMX_S32)Value;
+        }
+    }
+}
+
+/**
+ * Function: armSatRoundFloatToU16
+ *
+ * Description:
+ * Converts a double precision value into a unsigned short int after rounding and saturation
+ *
+ * Parameters:
+ * [in]  Value                 Float value to be converted
+ *
+ * Return Value:
+ * [out] converted value in OMX_U16 format
+ *
+ */
+
+OMX_U16 armSatRoundFloatToU16 (OMX_F64 Value)
+{
+    Value += 0.5;
+    
+    if(Value > (OMX_U16)OMX_MAX_U16 )
+    {
+        return (OMX_U16)OMX_MAX_U16;
+    }
+    else
+    {
+        return (OMX_U16)Value;
+    }
+}
+
+/**
+ * Function: armSatRoundFloatToU32
+ *
+ * Description:
+ * Converts a double precision value into a unsigned int after rounding and saturation
+ *
+ * Parameters:
+ * [in]  Value                 Float value to be converted
+ *
+ * Return Value:
+ * [out] converted value in OMX_U32 format
+ *
+ */
+
+OMX_U32 armSatRoundFloatToU32 (OMX_F64 Value)
+{
+    Value += 0.5;
+    
+    if(Value > (OMX_U32)OMX_MAX_U32 )
+    {
+        return (OMX_U32)OMX_MAX_U32;
+    }
+    else
+    {
+        return (OMX_U32)Value;
+    }
+}
+
+/**
+ * Function: armRoundFloatToS64
+ *
+ * Description:
+ * Converts a double precision value into a 64 bit int after rounding
+ *
+ * Parameters:
+ * [in]  Value                 Float value to be converted
+ *
+ * Return Value:
+ * [out] converted value in OMX_S64 format
+ *
+ */
+
+OMX_S64 armRoundFloatToS64 (OMX_F64 Value)
+{
+    if (Value > 0)
+    {
+        return (OMX_S64)(Value + .5);
+    }
+    else
+    {
+        return (OMX_S64)(Value - .5);
+    }
+}
+
+/**
+ * Function: armSignCheck
+ *
+ * Description:
+ * Checks the sign of a variable:
+ * returns 1 if it is Positive
+ * returns 0 if it is 0
+ * returns -1 if it is Negative 
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	    var     Variable to be checked
+ *
+ * Return Value:
+ * OMX_INT --   returns 1 if it is Positive
+ *              returns 0 if it is 0
+ *              returns -1 if it is Negative 
+ */ 
+
+OMX_INT armSignCheck (
+    OMX_S16 var
+)
+
+{
+    OMX_INT Sign;
+    
+    if (var < 0)
+    {
+        Sign = -1;
+    }
+    else if ( var > 0)
+    {
+        Sign = 1;
+    }
+    else
+    {
+        Sign = 0;
+    }
+    
+    return Sign;
+}
+
+/**
+ * Function: armClip
+ *
+ * Description: Clips the input between MAX and MIN value
+ * 
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] Min     lower bound
+ * [in] Max     upper bound
+ * [in] src     variable to the clipped
+ *
+ * Return Value:
+ * OMX_S32 --   returns clipped value
+ */ 
+ 
+OMX_S32 armClip (
+    OMX_INT min,
+    OMX_INT max, 
+    OMX_S32 src 
+)
+ 
+{
+    if (src > max)
+    {
+        src = max;
+    }
+    else if (src < min)
+    {
+        src = min;
+    }
+    
+    return src;
+}
+
+/**
+ * Function: armClip_F32
+ *
+ * Description: Clips the input between MAX and MIN value
+ * 
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] Min     lower bound
+ * [in] Max     upper bound
+ * [in] src     variable to the clipped
+ *
+ * Return Value:
+ * OMX_F32 --   returns clipped value
+ */ 
+ 
+OMX_F32 armClip_F32 (
+    OMX_F32 min,
+    OMX_F32 max, 
+    OMX_F32 src 
+)
+ 
+{
+    if (src > max)
+    {
+        src = max;
+    }
+    else if (src < min)
+    {
+        src = min;
+    }
+    
+    return src;
+}
+
+/**
+ * Function: armShiftSat_F32
+ *
+ * Description: Divides a float value by 2^shift and 
+ * saturates it for unsigned value range for satBits.
+ * Second parameter is like "shifting" the corresponding 
+ * integer value. Takes care of rounding while clipping the final 
+ * value.
+ *
+ * Parameters:
+ * [in] v          Number to be operated upon
+ * [in] shift      Divides the input "v" by "2^shift"
+ * [in] satBits    Final range is [0, 2^satBits)
+ *
+ * Return Value:
+ * OMX_S32 --   returns "shifted" saturated value
+ */ 
+ 
+OMX_U32 armShiftSat_F32(OMX_F32 v, OMX_INT shift, OMX_INT satBits) 
+{
+    OMX_U32 allOnes = (OMX_U32)(-1);
+    OMX_U32 maxV = allOnes >> (32-satBits);
+    OMX_F32 vShifted, vRounded, shiftDiv = (OMX_F32)(1 << shift);
+    OMX_U32 vInt;
+    OMX_U32 vIntSat;
+    
+    if(v <= 0)
+        return 0;
+    
+    vShifted = v / shiftDiv;
+    vRounded = (OMX_F32)(vShifted + 0.5);
+    vInt = (OMX_U32)vRounded;
+    vIntSat = vInt;
+    if(vIntSat > maxV) 
+        vIntSat = maxV;
+    return vIntSat;
+}
+
+/**
+ * Functions: armSwapElem
+ *
+ * Description:
+ * These function swaps two elements at the specified pointer locations.
+ * The size of each element could be anything as specified by <elemSize>
+ *
+ * Return Value:
+ * OMXResult -- Error status from the function
+ */
+OMXResult armSwapElem(
+        OMX_U8 *pBuf1,
+        OMX_U8 *pBuf2,
+        OMX_INT elemSize
+       )
+{
+    OMX_INT i;
+    OMX_U8 temp;
+    armRetArgErrIf(!pBuf1 || !pBuf2, OMX_Sts_BadArgErr);
+    
+    for(i = 0; i < elemSize; i++)
+    {
+        temp = *(pBuf1 + i);
+        *(pBuf1 + i) = *(pBuf2 + i);
+        *(pBuf2 + i) = temp;
+    }
+    return OMX_Sts_NoErr;
+}
+
+/**
+ * Function: armMedianOf3
+ *
+ * Description: Finds the median of three numbers
+ * 
+ * Remarks:
+ *
+ * Parameters:
+ * [in] fEntry     First entry
+ * [in] sEntry     second entry
+ * [in] tEntry     Third entry
+ *
+ * Return Value:
+ * OMX_S32 --   returns the median value
+ */ 
+ 
+OMX_S32 armMedianOf3 (
+    OMX_S32 fEntry,
+    OMX_S32 sEntry, 
+    OMX_S32 tEntry 
+)
+{
+    OMX_S32 a, b, c;
+    
+    a = armMin (fEntry, sEntry);
+    b = armMax (fEntry, sEntry);
+    c = armMin (b, tEntry);
+    return (armMax (a, c));
+}
+
+/**
+ * Function: armLogSize
+ *
+ * Description: Finds the size of a positive value and returns the same
+ * 
+ * Remarks:
+ *
+ * Parameters:
+ * [in] value    Positive value
+ *
+ * Return Value:
+ * OMX_U8 --     Returns the minimum number of bits required to represent the positive value. 
+                 This is the smallest k>=0 such that that value is less than (1<<k).
+ */ 
+ 
+OMX_U8 armLogSize (
+    OMX_U16 value 
+)
+{
+    OMX_U8 i;    
+    for ( i = 0; value > 0; value = value >> 1) 
+    {
+        i++;
+    }
+    return i;
+}
+
+/***********************************************************************/
+                /* Saturating Arithmetic operations */
+
+/**
+ * Function :armSatAdd_S32()
+ *
+ * Description :
+ *   Returns the result of saturated addition of the two inputs Value1, Value2
+ *
+ * Parametrs:
+ * [in] Value1       First Operand
+ * [in] Value2       Second Operand
+ *
+ * Return:
+ * [out]             Result of operation
+ * 
+ *    
+ **/
+ 
+OMX_S32 armSatAdd_S32(OMX_S32 Value1,OMX_S32 Value2)
+{
+    OMX_S32 Result;
+    
+    Result = Value1 + Value2;
+
+    if( (Value1^Value2) >= 0)
+    {
+        /*Same sign*/
+        if( (Result^Value1) >= 0)
+        {
+            /*Result has not saturated*/
+            return Result;
+        }
+        else
+        {
+            if(Value1 >= 0)
+            {
+                /*Result has saturated in positive side*/
+                return OMX_MAX_S32;
+            }
+            else
+            {
+                /*Result has saturated in negative side*/
+                return OMX_MIN_S32;
+            }
+        
+        }
+   
+    }
+    else
+    {
+        return Result;
+    }
+    
+}
+
+/**
+ * Function :armSatAdd_S64()
+ *
+ * Description :
+ *   Returns the result of saturated addition of the two inputs Value1, Value2
+ *
+ * Parametrs:
+ * [in] Value1       First Operand
+ * [in] Value2       Second Operand
+ *
+ * Return:
+ * [out]             Result of operation
+ * 
+ *    
+ **/
+ 
+OMX_S64 armSatAdd_S64(OMX_S64 Value1,OMX_S64 Value2)
+{
+    OMX_S64 Result;
+    
+    Result = Value1 + Value2;
+
+    if( (Value1^Value2) >= 0)
+    {
+        /*Same sign*/
+        if( (Result^Value1) >= 0)
+        {
+            /*Result has not saturated*/
+            return Result;
+        }
+        else
+        {
+            if(Value1 >= 0)
+            {
+                /*Result has saturated in positive side*/
+                Result = OMX_MAX_S64;
+                return Result;
+            }
+            else
+            {
+                /*Result has saturated in negative side*/
+                return OMX_MIN_S64;
+            }
+        
+        }
+   
+    }
+    else
+    {
+        return Result;
+    }
+    
+}
+
+/** Function :armSatSub_S32()
+ * 
+ * Description :
+ *     Returns the result of saturated substraction of the two inputs Value1, Value2
+ *
+ * Parametrs:
+ * [in] Value1       First Operand
+ * [in] Value2       Second Operand
+ *
+ * Return:
+ * [out]             Result of operation
+ * 
+ **/
+
+OMX_S32 armSatSub_S32(OMX_S32 Value1,OMX_S32 Value2)
+{
+    OMX_S32 Result;
+    
+    Result = Value1 - Value2;
+
+    if( (Value1^Value2) < 0)
+    {
+        /*Opposite sign*/
+        if( (Result^Value1) >= 0)
+        {
+            /*Result has not saturated*/
+            return Result;
+        }
+        else
+        {
+            if(Value1 >= 0)
+            {
+                /*Result has saturated in positive side*/
+                return OMX_MAX_S32;
+            }
+            else
+            {
+                /*Result has saturated in negative side*/
+                return OMX_MIN_S32;
+            }
+        
+        }
+   
+    }
+    else
+    {
+        return Result;
+    }
+    
+}
+
+/**
+ * Function :armSatMac_S32()
+ *
+ * Description :
+ *     Returns the result of Multiplication of Value1 and Value2 and subesquent saturated
+ *     accumulation with Mac
+ *
+ * Parametrs:
+ * [in] Value1       First Operand
+ * [in] Value2       Second Operand
+ * [in] Mac          Accumulator
+ *
+ * Return:
+ * [out]             Result of operation
+ **/
+
+OMX_S32 armSatMac_S32(OMX_S32 Mac,OMX_S16 Value1,OMX_S16 Value2)
+{
+    OMX_S32 Result;
+    
+    Result = (OMX_S32)(Value1*Value2);
+    Result = armSatAdd_S32( Mac , Result );
+
+    return Result;    
+}
+
+/**
+ * Function :armSatMac_S16S32_S32
+ *
+ * Description :
+ *   Returns the result of saturated MAC operation of the three inputs delayElem, filTap , mac
+ *
+ *   mac = mac + Saturate_in_32Bits(delayElem * filTap)
+ *
+ * Parametrs:
+ * [in] delayElem    First 32 bit Operand
+ * [in] filTap       Second 16 bit Operand
+ * [in] mac          Result of MAC operation
+ *
+ * Return:
+ * [out]  mac        Result of operation
+ *    
+ **/
+ 
+OMX_S32 armSatMac_S16S32_S32(OMX_S32 mac, OMX_S32 delayElem, OMX_S16 filTap )
+{
+    
+    OMX_S32 result;
+
+    result = armSatMulS16S32_S32(filTap,delayElem); 
+
+    if ( result > OMX_MAX_S16 )
+    {
+        result = OMX_MAX_S32;
+    }
+    else if( result < OMX_MIN_S16 )
+    {
+        result = OMX_MIN_S32;
+    }
+    else
+    {
+        result = delayElem * filTap;
+    }
+
+    mac = armSatAdd_S32(mac,result);
+    
+    return mac;
+}
+
+
+/**
+ * Function :armSatRoundRightShift_S32_S16
+ *
+ * Description :
+ *   Returns the result of rounded right shift operation of input by the scalefactor
+ *
+ *   output = Saturate_in_16Bits( ( Right/LeftShift( (Round(input) , shift ) )
+ *
+ * Parametrs:
+ * [in] input       The input to be operated on
+ * [in] shift The shift number
+ *
+ * Return:
+ * [out]            Result of operation
+ *    
+ **/
+
+
+OMX_S16 armSatRoundRightShift_S32_S16(OMX_S32 input, OMX_INT shift)
+{
+    input = armSatRoundLeftShift_S32(input,-shift);
+
+    if ( input > OMX_MAX_S16 )
+    {
+        return (OMX_S16)OMX_MAX_S16;
+    }
+    else if (input < OMX_MIN_S16)
+    {
+        return (OMX_S16)OMX_MIN_S16;
+    }
+    else
+    {
+       return (OMX_S16)input;
+    }
+
+}
+
+/**
+ * Function :armSatRoundLeftShift_S32()
+ *
+ * Description :
+ *     Returns the result of saturating left-shift operation on input
+ *     Or rounded Right shift if the input Shift is negative.
+ *     
+ * Parametrs:
+ * [in] Value        Operand
+ * [in] Shift        Operand for shift operation
+ *
+ * Return:
+ * [out]             Result of operation
+ *    
+ **/
+
+OMX_S32 armSatRoundLeftShift_S32(OMX_S32 Value, OMX_INT Shift)
+{
+    OMX_INT i;
+    
+    if (Shift < 0)
+    {
+        Shift = -Shift;
+        Value = armSatAdd_S32(Value, (1 << (Shift - 1)));
+        Value = Value >> Shift;
+    }
+    else
+    {
+        for (i = 0; i < Shift; i++)
+        {
+            Value = armSatAdd_S32(Value, Value);
+        }
+    }
+    return Value;
+}
+
+/**
+ * Function :armSatRoundLeftShift_S64()
+ *
+ * Description :
+ *     Returns the result of saturating left-shift operation on input
+ *     Or rounded Right shift if the input Shift is negative.
+ *
+ * Parametrs:
+ * [in] Value        Operand
+ * [in] shift        Operand for shift operation
+ *
+ * Return:
+ * [out]             Result of operation
+ *    
+ **/
+ 
+OMX_S64 armSatRoundLeftShift_S64(OMX_S64 Value, OMX_INT Shift)
+{
+    OMX_INT i;
+    
+    if (Shift < 0)
+    {
+        Shift = -Shift;
+        Value = armSatAdd_S64(Value, ((OMX_S64)1 << (Shift - 1)));
+        Value = Value >> Shift;
+    }
+    else
+    {
+        for (i = 0; i < Shift; i++)
+        {
+            Value = armSatAdd_S64(Value, Value);
+        }
+    }
+    return Value;
+}
+
+/**
+ * Function :armSatMulS16S32_S32()
+ *
+ * Description :
+ *     Returns the result of a S16 data type multiplied with an S32 data type
+ *     in a S32 container
+ *
+ * Parametrs:
+ * [in] input1       Operand 1
+ * [in] input2       Operand 2
+ *
+ * Return:
+ * [out]             Result of operation
+ *    
+ **/
+
+
+OMX_S32 armSatMulS16S32_S32(OMX_S16 input1,OMX_S32 input2)
+{
+    OMX_S16 hi2,lo1;
+    OMX_U16 lo2;
+    
+    OMX_S32 temp1,temp2;
+    OMX_S32 result;
+    
+    lo1  = input1;
+
+    hi2  = ( input2 >>  16 );
+    lo2  = ( (OMX_U32)( input2 << 16 ) >> 16 );
+    
+    temp1 = hi2 * lo1;
+    temp2 = ( lo2* lo1 ) >> 16;
+
+    result =  armSatAdd_S32(temp1,temp2);
+
+    return result;
+}
+
+/**
+ * Function :armSatMulS32S32_S32()
+ *
+ * Description :
+ *     Returns the result of a S32 data type multiplied with an S32 data type
+ *     in a S32 container
+ *
+ * Parametrs:
+ * [in] input1       Operand 1
+ * [in] input2       Operand 2
+ *
+ * Return:
+ * [out]             Result of operation
+ *    
+ **/
+
+OMX_S32 armSatMulS32S32_S32(OMX_S32 input1,OMX_S32 input2)
+{
+    OMX_S16 hi1,hi2;
+    OMX_U16 lo1,lo2;
+    
+    OMX_S32 temp1,temp2,temp3;
+    OMX_S32 result;
+
+    hi1  = ( input1 >>  16 );
+    lo1  = ( (OMX_U32)( input1 << 16 ) >> 16 );
+
+    hi2  = ( input2 >>  16 );
+    lo2  = ( (OMX_U32)( input2 << 16 ) >> 16 );
+    
+    temp1 =   hi1 * hi2;
+    temp2 = ( hi1* lo2 ) >> 16;
+    temp3 = ( hi2* lo1 ) >> 16;
+
+    result = armSatAdd_S32(temp1,temp2);
+    result = armSatAdd_S32(result,temp3);
+
+    return result;
+}
+
+/**
+ * Function :armIntDivAwayFromZero()
+ *
+ * Description : Integer division with rounding to the nearest integer. 
+ *               Half-integer values are rounded away from zero
+ *               unless otherwise specified. For example 3//2 is rounded 
+ *               to 2, and -3//2 is rounded to -2.
+ *
+ * Parametrs:
+ * [in] Num        Operand 1
+ * [in] Deno       Operand 2
+ *
+ * Return:
+ * [out]             Result of operation input1//input2
+ *    
+ **/
+
+OMX_S32 armIntDivAwayFromZero (OMX_S32 Num, OMX_S32 Deno)
+{
+    OMX_F64 result;
+    
+    result = ((OMX_F64)Num)/((OMX_F64)Deno);
+    
+    if (result >= 0)
+    {
+        result += 0.5;
+    }
+    else
+    {
+        result -= 0.5;
+    }
+
+    return (OMX_S32)(result);
+}
+
+
+/*End of File*/
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/src/armCOMM_Bitstream.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/src/armCOMM_Bitstream.c
new file mode 100755
index 0000000..9ef9319
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/src/armCOMM_Bitstream.c
@@ -0,0 +1,329 @@
+/**
+ * 
+ * File Name:  armCOMM_Bitstream.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Defines bitstream encode and decode functions common to all codecs
+ */
+
+#include "omxtypes.h"
+#include "armCOMM.h"
+#include "armCOMM_Bitstream.h"
+
+/***************************************
+ * Fixed bit length Decode
+ ***************************************/
+
+/**
+ * Function: armLookAheadBits()
+ *
+ * Description:
+ * Get the next N bits from the bitstream without advancing the bitstream pointer
+ *
+ * Parameters:
+ * [in]     **ppBitStream
+ * [in]     *pOffset
+ * [in]     N=1...32
+ *
+ * Returns  Value
+ */
+
+OMX_U32 armLookAheadBits(const OMX_U8 **ppBitStream, OMX_INT *pOffset, OMX_INT N)
+{
+    const OMX_U8 *pBitStream = *ppBitStream;
+    OMX_INT Offset = *pOffset;
+    OMX_U32 Value;
+
+    armAssert(Offset>=0 && Offset<=7);
+    armAssert(N>=1 && N<=32);
+
+    /* Read next 32 bits from stream */
+    Value = (pBitStream[0] << 24 ) | ( pBitStream[1] << 16)  | (pBitStream[2] << 8 ) | (pBitStream[3]) ;
+    Value = (Value << Offset ) | (pBitStream[4] >> (8-Offset));
+
+    /* Return N bits */
+    return Value >> (32-N);
+}
+
+
+/**
+ * Function: armGetBits()
+ *
+ * Description:
+ * Read N bits from the bitstream
+ *    
+ * Parameters:
+ * [in]     *ppBitStream
+ * [in]     *pOffset
+ * [in]     N=1..32
+ *
+ * [out]    *ppBitStream
+ * [out]    *pOffset
+ * Returns  Value
+ */
+
+
+OMX_U32 armGetBits(const OMX_U8 **ppBitStream, OMX_INT *pOffset, OMX_INT N)
+{
+    const OMX_U8 *pBitStream = *ppBitStream;
+    OMX_INT Offset = *pOffset;
+    OMX_U32 Value;
+    
+    if(N == 0)
+    {
+      return 0;
+    }
+
+    armAssert(Offset>=0 && Offset<=7);
+    armAssert(N>=1 && N<=32);
+
+    /* Read next 32 bits from stream */
+    Value = (pBitStream[0] << 24 ) | ( pBitStream[1] << 16)  | (pBitStream[2] << 8 ) | (pBitStream[3]) ;
+    Value = (Value << Offset ) | (pBitStream[4] >> (8-Offset));
+
+    /* Advance bitstream pointer by N bits */
+    Offset += N;
+    *ppBitStream = pBitStream + (Offset>>3);
+    *pOffset = Offset & 7;
+
+    /* Return N bits */
+    return Value >> (32-N);
+}
+
+/**
+ * Function: armByteAlign()
+ *
+ * Description:
+ * Align the pointer *ppBitStream to the next byte boundary
+ *
+ * Parameters:
+ * [in]     *ppBitStream
+ * [in]     *pOffset
+ *
+ * [out]    *ppBitStream
+ * [out]    *pOffset
+ *
+ **/
+ 
+OMXVoid armByteAlign(const OMX_U8 **ppBitStream,OMX_INT *pOffset)
+{
+    if(*pOffset > 0)
+    {
+        *ppBitStream += 1;
+        *pOffset = 0;
+    }    
+}
+
+/** 
+ * Function: armSkipBits()
+ *
+ * Description:
+ * Skip N bits from the value at *ppBitStream
+ *
+ * Parameters:
+ * [in]     *ppBitStream
+ * [in]     *pOffset
+ * [in]     N
+ *
+ * [out]    *ppBitStream
+ * [out]    *pOffset
+ *
+ **/
+
+
+OMXVoid armSkipBits(const OMX_U8 **ppBitStream,OMX_INT *pOffset,OMX_INT N)
+{
+    OMX_INT Offset = *pOffset;
+    const OMX_U8 *pBitStream = *ppBitStream;
+   
+    /* Advance bitstream pointer by N bits */
+    Offset += N;
+    *ppBitStream = pBitStream + (Offset>>3);
+    *pOffset = Offset & 7;
+}
+
+/***************************************
+ * Variable bit length Decode
+ ***************************************/
+
+/**
+ * Function: armUnPackVLC32()
+ *
+ * Description:
+ * Variable length decode of variable length symbol (max size 32 bits) read from
+ * the bit stream pointed by *ppBitStream at *pOffset by using the table
+ * pointed by pCodeBook
+ * 
+ * Parameters:
+ * [in]     *pBitStream
+ * [in]     *pOffset
+ * [in]     pCodeBook
+ * 
+ * [out]    *pBitStream
+ * [out]    *pOffset
+ *
+ * Returns : Code Book Index if successfull. 
+ *         : ARM_NO_CODEBOOK_INDEX = -1 if search fails.
+ **/
+#ifndef C_OPTIMIZED_IMPLEMENTATION 
+
+OMX_U16 armUnPackVLC32(
+    const OMX_U8 **ppBitStream,
+    OMX_INT *pOffset,
+    const ARM_VLC32 *pCodeBook
+)
+{    
+    const OMX_U8 *pBitStream = *ppBitStream;
+    OMX_INT Offset = *pOffset;
+    OMX_U32 Value;
+    OMX_INT Index;
+        
+    armAssert(Offset>=0 && Offset<=7);
+
+    /* Read next 32 bits from stream */
+    Value = (pBitStream[0] << 24 ) | ( pBitStream[1] << 16)  | (pBitStream[2] << 8 ) | (pBitStream[3]) ;
+    Value = (Value << Offset ) | (pBitStream[4] >> (8-Offset));
+
+    /* Search through the codebook */    
+    for (Index=0; pCodeBook->codeLen != 0; Index++)
+    {
+        if (pCodeBook->codeWord == (Value >> (32 - pCodeBook->codeLen)))
+        {
+            Offset       = Offset + pCodeBook->codeLen;
+            *ppBitStream = pBitStream + (Offset >> 3) ;
+            *pOffset     = Offset & 7;
+            
+            return Index;
+        }        
+        pCodeBook++;
+    }
+
+    /* No code match found */
+    return ARM_NO_CODEBOOK_INDEX;
+}
+
+#endif
+
+/***************************************
+ * Fixed bit length Encode
+ ***************************************/
+
+/**
+ * Function: armPackBits
+ *
+ * Description:
+ * Pack a VLC code word into the bitstream
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] ppBitStream     pointer to the pointer to the current byte 
+ *                      in the bit stream.
+ * [in] pOffset         pointer to the bit position in the byte 
+ *                      pointed by *ppBitStream. Valid within 0
+ *                      to 7.
+ * [in] codeWord        Code word that need to be inserted in to the
+ *                          bitstream
+ * [in] codeLength      Length of the code word valid range 1...32
+ *
+ * [out] ppBitStream    *ppBitStream is updated after the block is encoded,
+ *                          so that it points to the current byte in the bit
+ *                          stream buffer.
+ * [out] pBitOffset     *pBitOffset is updated so that it points to the
+ *                          current bit position in the byte pointed by
+ *                          *ppBitStream.
+ *
+ * Return Value:
+ * Standard OMX_RESULT result. See enumeration for possible result codes.
+ *
+ */
+ 
+OMXResult armPackBits (
+    OMX_U8  **ppBitStream, 
+    OMX_INT *pOffset,
+    OMX_U32 codeWord, 
+    OMX_INT codeLength 
+)
+{
+    OMX_U8  *pBitStream = *ppBitStream;
+    OMX_INT Offset = *pOffset;
+    OMX_U32 Value;
+        
+    /* checking argument validity */
+    armRetArgErrIf(Offset < 0, OMX_Sts_BadArgErr);
+    armRetArgErrIf(Offset > 7, OMX_Sts_BadArgErr);
+    armRetArgErrIf(codeLength < 1, OMX_Sts_BadArgErr);
+    armRetArgErrIf(codeLength > 32, OMX_Sts_BadArgErr);
+
+    /* Prepare the first byte */
+    codeWord = codeWord << (32-codeLength);
+    Value = (pBitStream[0] >> (8-Offset)) << (8-Offset);
+    Value = Value | (codeWord >> (24+Offset));
+
+    /* Write out whole bytes */
+    while (8-Offset <= codeLength)
+    {
+        *pBitStream++ = (OMX_U8)Value;
+        codeWord   = codeWord  << (8-Offset);
+        codeLength = codeLength - (8-Offset);
+        Offset = 0;
+        Value = codeWord >> 24;
+    }
+
+    /* Write out final partial byte */
+    *pBitStream  = (OMX_U8)Value;
+    *ppBitStream = pBitStream;
+    *pOffset = Offset + codeLength;
+    
+    return  OMX_Sts_NoErr;
+}
+ 
+/***************************************
+ * Variable bit length Encode
+ ***************************************/
+
+/**
+ * Function: armPackVLC32
+ *
+ * Description:
+ * Pack a VLC code word into the bitstream
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	ppBitStream		pointer to the pointer to the current byte 
+ *                      in the bit stream.
+ * [in]	pBitOffset	    pointer to the bit position in the byte 
+ *                      pointed by *ppBitStream. Valid within 0
+ *                      to 7.
+ * [in]	 code     		VLC code word that need to be inserted in to the
+ *                      bitstream
+ *
+ * [out] ppBitStream	*ppBitStream is updated after the block is encoded,
+ *	                    so that it points to the current byte in the bit
+ *						stream buffer.
+ * [out] pBitOffset		*pBitOffset is updated so that it points to the
+ *						current bit position in the byte pointed by
+ *						*ppBitStream.
+ *
+ * Return Value:
+ * Standard OMX_RESULT result. See enumeration for possible result codes.
+ *
+ */
+ 
+OMXResult armPackVLC32 (
+    OMX_U8 **ppBitStream, 
+    OMX_INT *pBitOffset,
+    ARM_VLC32 code 
+)
+{
+    return (armPackBits(ppBitStream, pBitOffset, code.codeWord, code.codeLen));
+}
+
+/*End of File*/
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/src/armCOMM_IDCTTable.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/src/armCOMM_IDCTTable.c
new file mode 100755
index 0000000..3f5e279
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/src/armCOMM_IDCTTable.c
@@ -0,0 +1,60 @@
+/**
+ * 
+ * File Name:  armCOMM_IDCTTable.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   12290
+ * Date:       Wednesday, April 9, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *   
+ * File: armCOMM_IDCTTable.c
+ * Brief: Defines Tables used in IDCT computation
+ *
+ */
+
+#include "armCOMM_IDCTTable.h"
+
+     /*  Table of s(u)*A(u)*A(v)/16 at Q15
+      *  s(u)=1.0 0 <= u <= 5
+      *  s(6)=2.0
+      *  s(7)=4.0
+      *  A(0) = 2*sqrt(2)
+      *  A(u) = 4*cos(u*pi/16)  for (u!=0)
+	  */
+	  
+__align(4) const OMX_U16 armCOMM_IDCTPreScale [64] =
+{
+    0x4000, 0x58c5, 0x539f, 0x4b42, 0x4000, 0x3249, 0x4546, 0x46a1,
+    0x58c5, 0x7b21, 0x73fc, 0x6862, 0x58c5, 0x45bf, 0x6016, 0x61f8,
+    0x539f, 0x73fc, 0x6d41, 0x6254, 0x539f, 0x41b3, 0x5a82, 0x5c48,
+    0x4b42, 0x6862, 0x6254, 0x587e, 0x4b42, 0x3b21, 0x5175, 0x530d,
+    0x4000, 0x58c5, 0x539f, 0x4b42, 0x4000, 0x3249, 0x4546, 0x46a1,
+    0x3249, 0x45bf, 0x41b3, 0x3b21, 0x3249, 0x2782, 0x366d, 0x377e,
+    0x22a3, 0x300b, 0x2d41, 0x28ba, 0x22a3, 0x1b37, 0x257e, 0x263a,
+    0x11a8, 0x187e, 0x1712, 0x14c3, 0x11a8, 0x0de0, 0x131d, 0x137d    
+};
+    /* Above array armCOMM_IDCTPreScale,  in Q23 format */
+const OMX_U32 armCOMM_IDCTPreScaleU32 [64] =
+{
+    0x400000, 0x58c543, 0x539eba, 0x4b418c, 0x400000, 0x3248d4, 0x4545ea, 0x46a157,
+    0x58c543, 0x7b20d8, 0x73fbfc, 0x686214, 0x58c543, 0x45bf1f, 0x6015a5, 0x61f78b,
+    0x539eba, 0x73fbfc, 0x6d413d, 0x6253a6, 0x539eba, 0x41b328, 0x5a827a, 0x5c4869,
+    0x4b418c, 0x686214, 0x6253a6, 0x587de3, 0x4b418c, 0x3b20d8, 0x5174e0, 0x530d69,
+    0x400000, 0x58c543, 0x539eba, 0x4b418c, 0x400000, 0x3248d4, 0x4545ea, 0x46a157,
+    0x3248d4, 0x45bf1f, 0x41b328, 0x3b20d8, 0x3248d4, 0x27821d, 0x366d72, 0x377e6b,
+    0x22a2f5, 0x300ad3, 0x2d413d, 0x28ba70, 0x22a2f5, 0x1b36b9, 0x257d86, 0x26398d,
+    0x11a856, 0x187de3, 0x17121a, 0x14c35a, 0x11a856, 0x0ddf9b, 0x131cc7, 0x137ca2
+};
+   
+const OMX_U16 armCOMM_IDCTCoef [4] =
+{
+    0x5a82, /* InvSqrt2 */
+    0x30fc, /* SinPIBy8 */
+    0x7642, /* CosPIBy8 */
+    0x0000    
+};
+
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/src/armCOMM_MaskTable.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/src/armCOMM_MaskTable.c
new file mode 100755
index 0000000..09f88c3
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/src/armCOMM_MaskTable.c
@@ -0,0 +1,45 @@
+/* ----------------------------------------------------------------
+ *
+ * 
+ * File Name:  armCOMM_MaskTable.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   12290
+ * Date:       Wednesday, April 9, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Mask Table to mask the end of array.
+ * 
+ */
+ 
+#include "omxtypes.h"
+
+#define MaskTableSize 72
+
+const OMX_U16 armCOMM_qMaskTable16[MaskTableSize] = 
+{
+        0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+        0xFFFF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+        0xFFFF, 0xFFFF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+        0xFFFF, 0xFFFF, 0xFFFF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+        0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x0000, 0x0000, 0x0000, 0x0000,
+        0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x0000, 0x0000, 0x0000, 
+        0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x0000, 0x0000, 
+        0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x0000,
+        0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF    
+};
+
+const OMX_U8 armCOMM_qMaskTable8[MaskTableSize] = 
+{
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+        0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+        0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+        0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 
+        0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 
+        0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00,  
+        0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00,  
+        0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 
+        0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF    
+};
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/api/armVC.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/api/armVC.h
new file mode 100755
index 0000000..35b510b
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/api/armVC.h
@@ -0,0 +1,1153 @@
+/**
+ * 
+ * File Name:  armVC.h
+ * OpenMAX DL: v1.0.2
+ * Revision:   12290
+ * Date:       Wednesday, April 9, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * File: armVideo.h
+ * Brief: Declares API's/Basic Data types used across the OpenMAX Video domain
+ *
+ */
+
+
+#ifndef _armVideo_H_
+#define _armVideo_H_
+
+#include "omxVC.h"
+#include "armCOMM_Bitstream.h"
+
+/**
+ * ARM specific state structure to hold Motion Estimation information.
+ */
+ 
+struct m4p2_MESpec
+{
+    OMXVCM4P2MEParams MEParams;
+    OMXVCM4P2MEMode   MEMode;
+};
+
+struct m4p10_MESpec
+{
+    OMXVCM4P10MEParams MEParams;
+    OMXVCM4P10MEMode   MEMode;
+};
+
+typedef struct m4p2_MESpec  ARMVCM4P2_MESpec;
+typedef struct m4p10_MESpec ARMVCM4P10_MESpec;
+
+/**
+ * Function: armVCM4P2_CompareMV
+ *
+ * Description:
+ * Performs comparision of motion vectors and SAD's to decide the
+ * best MV and SAD
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]     mvX     x coordinate of the candidate motion vector
+ * [in]     mvY     y coordinate of the candidate motion vector
+ * [in]     candSAD Candidate SAD
+ * [in]     bestMVX x coordinate of the best motion vector
+ * [in]     bestMVY y coordinate of the best motion vector
+ * [in]     bestSAD best SAD
+ *
+ * Return Value:
+ * OMX_INT -- 1 to indicate that the current sad is the best
+ *            0 to indicate that it is NOT the best SAD
+ */
+
+OMX_INT armVCM4P2_CompareMV (
+    OMX_S16 mvX,
+    OMX_S16 mvY,
+    OMX_INT candSAD,
+    OMX_S16 bestMVX,
+    OMX_S16 bestMVY,
+    OMX_INT bestSAD);
+
+/**
+ * Function: armVCM4P2_ACDCPredict
+ *
+ * Description:
+ * Performs adaptive DC/AC coefficient prediction for an intra block. Prior
+ * to the function call, prediction direction (predDir) should be selected
+ * as specified in subclause 7.4.3.1 of ISO/IEC 14496-2.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] pSrcDst     pointer to the coefficient buffer which contains
+ *                          the quantized coefficient residuals (PQF) of the
+ *                          current block
+ * [in] pPredBufRow pointer to the coefficient row buffer
+ * [in] pPredBufCol pointer to the coefficient column buffer
+ * [in] curQP       quantization parameter of the current block. curQP
+ *                          may equal to predQP especially when the current
+ *                          block and the predictor block are in the same
+ *                          macroblock.
+ * [in] predQP      quantization parameter of the predictor block
+ * [in] predDir     indicates the prediction direction which takes one
+ *                          of the following values:
+ *                          OMX_VIDEO_HORIZONTAL    predict horizontally
+ *                          OMX_VIDEO_VERTICAL      predict vertically
+ * [in] ACPredFlag  a flag indicating if AC prediction should be
+ *                          performed. It is equal to ac_pred_flag in the bit
+ *                          stream syntax of MPEG-4
+ * [in] videoComp   video component type (luminance, chrominance or
+ *                          alpha) of the current block
+ * [in] flag        This flag defines the if one wants to use this functions to
+ *                  calculate PQF (set 1, prediction) or QF (set 0, reconstruction)
+ * [out]    pPreACPredict   pointer to the predicted coefficients buffer.
+ *                          Filled ONLY if it is not NULL
+ * [out]    pSrcDst     pointer to the coefficient buffer which contains
+ *                          the quantized coefficients (QF) of the current
+ *                          block
+ * [out]    pPredBufRow pointer to the updated coefficient row buffer
+ * [out]    pPredBufCol pointer to the updated coefficient column buffer
+ * [out]    pSumErr     pointer to the updated sum of the difference
+ *                      between predicted and unpredicted coefficients
+ *                      If this is NULL, do not update
+ *
+ * Return Value:
+ * Standard OMXResult result. See enumeration for possible result codes.
+ *
+ */
+
+OMXResult armVCM4P2_ACDCPredict(
+     OMX_S16 * pSrcDst,
+     OMX_S16 * pPreACPredict,
+     OMX_S16 * pPredBufRow,
+     OMX_S16 * pPredBufCol,
+     OMX_INT curQP,
+     OMX_INT predQP,
+     OMX_INT predDir,
+     OMX_INT ACPredFlag,
+     OMXVCM4P2VideoComponent  videoComp,
+     OMX_U8 flag,
+     OMX_INT *pSumErr
+);
+
+/**
+ * Function: armVCM4P2_SetPredDir
+ *
+ * Description:
+ * Performs detecting the prediction direction
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] blockIndex  block index indicating the component type and
+ *                          position as defined in subclause 6.1.3.8, of ISO/IEC
+ *                          14496-2. Furthermore, indexes 6 to 9 indicate the
+ *                          alpha blocks spatially corresponding to luminance
+ *                          blocks 0 to 3 in the same macroblock.
+ * [in] pCoefBufRow pointer to the coefficient row buffer
+ * [in] pQpBuf      pointer to the quantization parameter buffer
+ * [out]    predQP      quantization parameter of the predictor block
+ * [out]    predDir     indicates the prediction direction which takes one
+ *                          of the following values:
+ *                          OMX_VIDEO_HORIZONTAL    predict horizontally
+ *                          OMX_VIDEO_VERTICAL      predict vertically
+ *
+ * Return Value:
+ * Standard OMXResult result. See enumeration for possible result codes.
+ *
+ */
+
+OMXResult armVCM4P2_SetPredDir(
+     OMX_INT blockIndex,
+     OMX_S16 *pCoefBufRow,
+     OMX_S16 *pCoefBufCol,
+     OMX_INT *predDir,
+     OMX_INT *predQP,
+     const OMX_U8 *pQpBuf
+);
+
+/**
+ * Function: armVCM4P2_EncodeVLCZigzag_Intra
+ *
+ * Description:
+ * Performs zigzag scanning and VLC encoding for one intra block.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] ppBitStream     pointer to the pointer to the current byte in
+ *                              the bit stream
+ * [in] pBitOffset      pointer to the bit position in the byte pointed
+ *                              by *ppBitStream. Valid within 0 to 7.
+ * [in] pQDctBlkCoef    pointer to the quantized DCT coefficient
+ * [in] predDir         AC prediction direction, which is used to decide
+ *                              the zigzag scan pattern. This takes one of the
+ *                              following values:
+ *                              OMX_VIDEO_NONE          AC prediction not used.
+ *                                                      Performs classical zigzag
+ *                                                      scan.
+ *                              OMX_VIDEO_HORIZONTAL    Horizontal prediction.
+ *                                                      Performs alternate-vertical
+ *                                                      zigzag scan.
+ *                              OMX_VIDEO_VERTICAL      Vertical prediction.
+ *                                                      Performs alternate-horizontal
+ *                                                      zigzag scan.
+ * [in] pattern         block pattern which is used to decide whether
+ *                              this block is encoded
+ * [in] start           start indicates whether the encoding begins with 0th element
+ *                      or 1st.
+ * [out]    ppBitStream     *ppBitStream is updated after the block is encoded,
+ *                              so that it points to the current byte in the bit
+ *                              stream buffer.
+ * [out]    pBitOffset      *pBitOffset is updated so that it points to the
+ *                              current bit position in the byte pointed by
+ *                              *ppBitStream.
+ *
+ * Return Value:
+ * Standard OMXResult result. See enumeration for possible result codes.
+ *
+ */
+
+OMXResult armVCM4P2_EncodeVLCZigzag_Intra(
+     OMX_U8 **ppBitStream,
+     OMX_INT *pBitOffset,
+     const OMX_S16 *pQDctBlkCoef,
+     OMX_U8 predDir,
+     OMX_U8 pattern,
+     OMX_INT shortVideoHeader,
+     OMX_U8 start
+);
+
+/**
+ * Function: armVCM4P2_DecodeVLCZigzag_Intra
+ *
+ * Description:
+ * Performs VLC decoding and inverse zigzag scan for one intra coded block.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] ppBitStream     pointer to the pointer to the current byte in
+ *                              the bitstream buffer
+ * [in] pBitOffset      pointer to the bit position in the byte pointed
+ *                              to by *ppBitStream. *pBitOffset is valid within
+ *                              [0-7].
+ * [in] predDir         AC prediction direction which is used to decide
+ *                              the zigzag scan pattern. It takes one of the
+ *                              following values:
+ *                              OMX_VIDEO_NONE  AC prediction not used;
+ *                                              perform classical zigzag scan;
+ *                              OMX_VIDEO_HORIZONTAL    Horizontal prediction;
+ *                                                      perform alternate-vertical
+ *                                                      zigzag scan;
+ *                              OMX_VIDEO_VERTICAL      Vertical prediction;
+ *                                                      thus perform
+ *                                                      alternate-horizontal
+ *                                                      zigzag scan.
+ * [in] videoComp       video component type (luminance, chrominance or
+ *                              alpha) of the current block
+ * [in] shortVideoHeader binary flag indicating presence of short_video_header; escape modes 0-3 are used if shortVideoHeader==0,
+ *                           and escape mode 4 is used when shortVideoHeader==1.
+ * [in] start           start indicates whether the encoding begins with 0th element
+ *                      or 1st.
+ * [out]    ppBitStream     *ppBitStream is updated after the block is
+ *                              decoded, so that it points to the current byte
+ *                              in the bit stream buffer
+ * [out]    pBitOffset      *pBitOffset is updated so that it points to the
+ *                              current bit position in the byte pointed by
+ *                              *ppBitStream
+ * [out]    pDst            pointer to the coefficient buffer of current
+ *                              block. Should be 32-bit aligned
+ *
+ * Return Value:
+ * Standard OMXResult result. See enumeration for possible result codes.
+ *
+ */
+
+OMXResult armVCM4P2_DecodeVLCZigzag_Intra(
+     const OMX_U8 ** ppBitStream,
+     OMX_INT * pBitOffset,
+     OMX_S16 * pDst,
+     OMX_U8 predDir,
+     OMX_INT shortVideoHeader, 
+     OMX_U8  start
+);
+
+/**
+ * Function: armVCM4P2_FillVLDBuffer
+ *
+ * Description:
+ * Performs filling of the coefficient buffer according to the run, level
+ * and sign, also updates the index
+ * 
+ * Parameters:
+ * [in]  storeRun        Stored Run value (count of zeros)   
+ * [in]  storeLevel      Stored Level value (non-zero value)
+ * [in]  sign            Flag indicating the sign of level
+ * [in]  last            status of the last flag
+ * [in]  pIndex          pointer to coefficient index in 8x8 matrix
+ * [out] pIndex          pointer to updated coefficient index in 8x8 
+ *                       matrix
+ * [in]  pZigzagTable    pointer to the zigzag tables
+ * [out] pDst            pointer to the coefficient buffer of current
+ *                       block. Should be 32-bit aligned
+ * Return Value:
+ * Standard OMXResult result. See enumeration for possible result codes.
+ *
+ */
+
+OMXResult armVCM4P2_FillVLDBuffer(
+    OMX_U32 storeRun,
+    OMX_S16 * pDst,
+    OMX_S16 storeLevel,
+    OMX_U8  sign,
+    OMX_U8  last,
+    OMX_U8  * index,
+    const OMX_U8 * pZigzagTable
+);
+
+/**
+ * Function: armVCM4P2_GetVLCBits
+ *
+ * Description:
+ * Performs escape mode decision based on the run, run+, level, level+ and 
+ * last combinations.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	ppBitStream		pointer to the pointer to the current byte in
+ *								the bit stream
+ * [in]	pBitOffset		pointer to the bit position in the byte pointed
+ *								by *ppBitStream. Valid within 0 to 7
+ * [in] shortVideoHeader binary flag indicating presence of short_video_header; escape modes 0-3 are used if shortVideoHeader==0,
+ *                           and escape mode 4 is used when shortVideoHeader==1.
+ * [in] start           start indicates whether the encoding begins with 
+ *                      0th element or 1st.
+ * [in/out] pLast       pointer to last status flag
+ * [in] runBeginSingleLevelEntriesL0      The run value from which level 
+ *                                        will be equal to 1: last == 0
+ * [in] IndexBeginSingleLevelEntriesL0    Array index in the VLC table 
+ *                                        pointing to the  
+ *                                        runBeginSingleLevelEntriesL0 
+ * [in] runBeginSingleLevelEntriesL1      The run value from which level 
+ *                                        will be equal to 1: last == 1
+ * [in] IndexBeginSingleLevelEntriesL1    Array index in the VLC table 
+ *                                        pointing to the  
+ *                                        runBeginSingleLevelEntriesL0 
+ * [in] pRunIndexTableL0    Run Index table defined in 
+ *                          armVCM4P2_Huff_Tables_VLC.c for last == 0
+ * [in] pVlcTableL0         VLC table for last == 0
+ * [in] pRunIndexTableL1    Run Index table defined in 
+ *                          armVCM4P2_Huff_Tables_VLC.c for last == 1
+ * [in] pVlcTableL1         VLC table for last == 1
+ * [in] pLMAXTableL0        Level MAX table defined in 
+ *                          armVCM4P2_Huff_Tables_VLC.c for last == 0
+ * [in] pLMAXTableL1        Level MAX table defined in 
+ *                          armVCM4P2_Huff_Tables_VLC.c for last == 1
+ * [in] pRMAXTableL0        Run MAX table defined in 
+ *                          armVCM4P2_Huff_Tables_VLC.c for last == 0
+ * [in] pRMAXTableL1        Run MAX table defined in 
+ *                          armVCM4P2_Huff_Tables_VLC.c for last == 1
+ * [out]pDst			    pointer to the coefficient buffer of current
+ *							block. Should be 32-bit aligned
+ *
+ * Return Value:
+ * Standard OMXResult result. See enumeration for possible result codes.
+ *
+ */
+
+OMXResult armVCM4P2_GetVLCBits (
+              const OMX_U8 **ppBitStream,
+              OMX_INT * pBitOffset,
+			  OMX_S16 * pDst,
+			  OMX_INT shortVideoHeader,
+			  OMX_U8    start,			  
+			  OMX_U8  * pLast,
+			  OMX_U8    runBeginSingleLevelEntriesL0,
+			  OMX_U8    maxIndexForMultipleEntriesL0,
+			  OMX_U8    maxRunForMultipleEntriesL1,
+			  OMX_U8    maxIndexForMultipleEntriesL1,
+              const OMX_U8  * pRunIndexTableL0,
+              const ARM_VLC32 *pVlcTableL0,
+			  const OMX_U8  * pRunIndexTableL1,
+              const ARM_VLC32 *pVlcTableL1,
+              const OMX_U8  * pLMAXTableL0,
+              const OMX_U8  * pLMAXTableL1,
+              const OMX_U8  * pRMAXTableL0,
+              const OMX_U8  * pRMAXTableL1,
+              const OMX_U8  * pZigzagTable
+);
+
+/**
+ * Function: armVCM4P2_PutVLCBits
+ *
+ * Description:
+ * Checks the type of Escape Mode and put encoded bits for 
+ * quantized DCT coefficients.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	 ppBitStream      pointer to the pointer to the current byte in
+ *						  the bit stream
+ * [in]	 pBitOffset       pointer to the bit position in the byte pointed
+ *                        by *ppBitStream. Valid within 0 to 7
+ * [in] shortVideoHeader binary flag indicating presence of short_video_header; escape modes 0-3 are used if shortVideoHeader==0,
+ *                           and escape mode 4 is used when shortVideoHeader==1.
+ * [in]  start            start indicates whether the encoding begins with 
+ *                        0th element or 1st.
+ * [in]  maxStoreRunL0    Max store possible (considering last and inter/intra)
+ *                        for last = 0
+ * [in]  maxStoreRunL1    Max store possible (considering last and inter/intra)
+ *                        for last = 1
+ * [in]  maxRunForMultipleEntriesL0 
+ *                        The run value after which level 
+ *                        will be equal to 1: 
+ *                        (considering last and inter/intra status) for last = 0
+ * [in]  maxRunForMultipleEntriesL1 
+ *                        The run value after which level 
+ *                        will be equal to 1: 
+ *                        (considering last and inter/intra status) for last = 1
+ * [in]  pRunIndexTableL0 Run Index table defined in 
+ *                        armVCM4P2_Huff_Tables_VLC.c for last == 0
+ * [in]  pVlcTableL0      VLC table for last == 0
+ * [in]  pRunIndexTableL1 Run Index table defined in 
+ *                        armVCM4P2_Huff_Tables_VLC.c for last == 1
+ * [in]  pVlcTableL1      VLC table for last == 1
+ * [in]  pLMAXTableL0     Level MAX table defined in 
+ *                        armVCM4P2_Huff_Tables_VLC.c for last == 0
+ * [in]  pLMAXTableL1     Level MAX table defined in 
+ *                        armVCM4P2_Huff_Tables_VLC.c for last == 1
+ * [in]  pRMAXTableL0     Run MAX table defined in 
+ *                        armVCM4P2_Huff_Tables_VLC.c for last == 0
+ * [in]  pRMAXTableL1     Run MAX table defined in 
+ *                        armVCM4P2_Huff_Tables_VLC.c for last == 1
+ * [out] pQDctBlkCoef     pointer to the quantized DCT coefficient
+ * [out] ppBitStream      *ppBitStream is updated after the block is encoded
+ *                        so that it points to the current byte in the bit
+ *                        stream buffer.
+ * [out] pBitOffset       *pBitOffset is updated so that it points to the
+ *                        current bit position in the byte pointed by
+ *                        *ppBitStream.
+ *
+ * Return Value:
+ * Standard OMXResult result. See enumeration for possible result codes.
+ *
+ */
+
+
+OMXResult armVCM4P2_PutVLCBits (
+              OMX_U8 **ppBitStream,
+              OMX_INT * pBitOffset,
+              const OMX_S16 *pQDctBlkCoef,
+              OMX_INT shortVideoHeader,
+              OMX_U8 start,
+              OMX_U8 maxStoreRunL0,
+              OMX_U8 maxStoreRunL1,
+              OMX_U8  maxRunForMultipleEntriesL0,
+              OMX_U8  maxRunForMultipleEntriesL1,
+              const OMX_U8  * pRunIndexTableL0,
+              const ARM_VLC32 *pVlcTableL0,
+			  const OMX_U8  * pRunIndexTableL1,
+              const ARM_VLC32 *pVlcTableL1,
+              const OMX_U8  * pLMAXTableL0,
+              const OMX_U8  * pLMAXTableL1,
+              const OMX_U8  * pRMAXTableL0,
+              const OMX_U8  * pRMAXTableL1,
+              const OMX_U8  * pZigzagTable
+);
+/**
+ * Function: armVCM4P2_FillVLCBuffer
+ *
+ * Description:
+ * Performs calculating the VLC bits depending on the escape type and insert 
+ * the same in the bitstream
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	 ppBitStream		pointer to the pointer to the current byte in
+ *	                        the bit stream
+ * [in]	 pBitOffset         pointer to the bit position in the byte pointed
+ *                          by *ppBitStream. Valid within 0 to 7
+ * [in]  run                Run value (count of zeros) to be encoded  
+ * [in]  level              Level value (non-zero value) to be encoded
+ * [in]  runPlus            Calculated as runPlus = run - (RMAX + 1)  
+ * [in]  levelPlus          Calculated as 
+ *                          levelPlus = sign(level)*[abs(level) - LMAX]
+ * [in]  fMode              Flag indicating the escape modes
+ * [in]  last               status of the last flag
+ * [in]  maxRunForMultipleEntries 
+ *                          The run value after which level will be equal to 1: 
+ *                          (considering last and inter/intra status)
+ * [in]  pRunIndexTable     Run Index table defined in
+ *                          armVCM4P2_Huff_tables_VLC.h
+ * [in]  pVlcTable          VLC table defined in armVCM4P2_Huff_tables_VLC.h
+ * [out] ppBitStream		*ppBitStream is updated after the block is encoded
+ *                          so that it points to the current byte in the bit
+ *                          stream buffer.
+ * [out] pBitOffset         *pBitOffset is updated so that it points to the
+ *                          current bit position in the byte pointed by
+ *                          *ppBitStream.
+ *
+ * Return Value:
+ * Standard OMXResult result. See enumeration for possible result codes.
+ *
+ */
+
+OMXResult armVCM4P2_FillVLCBuffer (
+              OMX_U8 **ppBitStream,
+              OMX_INT * pBitOffset,
+              OMX_U32 run,
+              OMX_S16 level, 
+			  OMX_U32 runPlus,
+              OMX_S16 levelPlus, 
+              OMX_U8  fMode,
+			  OMX_U8  last,
+              OMX_U8  maxRunForMultipleEntries, 
+              const OMX_U8  *pRunIndexTable,
+              const ARM_VLC32 *pVlcTable
+);
+
+/**
+ * Function: armVCM4P2_CheckVLCEscapeMode
+ *
+ * Description:
+ * Performs escape mode decision based on the run, run+, level, level+ and 
+ * last combinations.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] run             Run value (count of zeros) to be encoded  
+ * [in] level           Level value (non-zero value) to be encoded
+ * [in] runPlus         Calculated as runPlus = run - (RMAX + 1)  
+ * [in] levelPlus       Calculated as 
+ *                      levelPlus = sign(level)*[abs(level) - LMAX]
+ * [in] maxStoreRun     Max store possible (considering last and inter/intra)
+ * [in] maxRunForMultipleEntries 
+ *                      The run value after which level 
+ *                      will be equal to 1: 
+ *                      (considering last and inter/intra status)
+ * [in] shortVideoHeader binary flag indicating presence of short_video_header; escape modes 0-3 are used if shortVideoHeader==0,
+ *                           and escape mode 4 is used when shortVideoHeader==1.
+ * [in] pRunIndexTable  Run Index table defined in 
+ *                      armVCM4P2_Huff_Tables_VLC.c
+ *                      (considering last and inter/intra status)
+ *
+ *                      
+ * Return Value:
+ * Returns an Escape mode which can take values from 0 to 3
+ * 0 --> no escape mode, 1 --> escape type 1,
+ * 1 --> escape type 2, 3 --> escape type 3, check section 7.4.1.3
+ * in the MPEG ISO standard.
+ *
+ */
+
+OMX_U8 armVCM4P2_CheckVLCEscapeMode(
+     OMX_U32 run,
+     OMX_U32 runPlus,
+     OMX_S16 level,
+     OMX_S16 levelPlus,
+     OMX_U8  maxStoreRun,
+     OMX_U8  maxRunForMultipleEntries,
+     OMX_INT shortVideoHeader,
+     const OMX_U8  *pRunIndexTable
+);
+
+
+/**
+ * Function: armVCM4P2_BlockMatch_Integer
+ *
+ * Description:
+ * Performs a 16x16 block search; estimates motion vector and associated minimum SAD.  
+ * Both the input and output motion vectors are represented using half-pixel units, and 
+ * therefore a shift left or right by 1 bit may be required, respectively, to match the 
+ * input or output MVs with other functions that either generate output MVs or expect 
+ * input MVs represented using integer pixel units. 
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	pSrcRefBuf		pointer to the reference Y plane; points to the reference MB that 
+ *                    corresponds to the location of the current macroblock in the current 
+ *                    plane.
+ * [in]	refWidth		  width of the reference plane
+ * [in]	pRefRect		  pointer to the valid rectangular in reference plane. Relative to image origin. 
+ *                    It's not limited to the image boundary, but depended on the padding. For example, 
+ *                    if you pad 4 pixels outside the image border, then the value for left border 
+ *                    can be -4
+ * [in]	pSrcCurrBuf		pointer to the current macroblock extracted from original plane (linear array, 
+ *                    256 entries); must be aligned on an 8-byte boundary.
+ * [in] pCurrPointPos	position of the current macroblock in the current plane
+ * [in] pSrcPreMV		  pointer to predicted motion vector; NULL indicates no predicted MV
+ * [in] pSrcPreSAD		pointer to SAD associated with the predicted MV (referenced by pSrcPreMV)
+ * [in] searchRange		search range for 16X16 integer block,the units of it is full pixel,the search range 
+ *                    is the same in all directions.It is in inclusive of the boundary and specified in 
+ *                    terms of integer pixel units.
+ * [in] pMESpec			  vendor-specific motion estimation specification structure; must have been allocated 
+ *                    and then initialized using omxVCM4P2_MEInit prior to calling the block matching 
+ *                    function.
+ * [in] BlockSize     MacroBlock Size i.e either 16x16 or 8x8.
+ * [out]	pDstMV			pointer to estimated MV
+ * [out]	pDstSAD			pointer to minimum SAD
+ *
+ * Return Value:
+ * OMX_Sts_NoErr ¨C no error.
+ * OMX_Sts_BadArgErr ¨C bad arguments
+ *
+ */
+
+OMXResult armVCM4P2_BlockMatch_Integer(
+     const OMX_U8 *pSrcRefBuf,
+     OMX_INT refWidth,
+     const OMXRect *pRefRect,
+     const OMX_U8 *pSrcCurrBuf,
+     const OMXVCM4P2Coordinate *pCurrPointPos,
+     const OMXVCMotionVector *pSrcPreMV,
+     const OMX_INT *pSrcPreSAD,
+     void *pMESpec,
+     OMXVCMotionVector *pDstMV,
+     OMX_INT *pDstSAD,
+     OMX_U8 BlockSize
+);
+
+/**
+ * Function: armVCM4P2_BlockMatch_Half
+ *
+ * Description:
+ * Performs a 16x16 block match with half-pixel resolution.  Returns the estimated 
+ * motion vector and associated minimum SAD.  This function estimates the half-pixel 
+ * motion vector by interpolating the integer resolution motion vector referenced 
+ * by the input parameter pSrcDstMV, i.e., the initial integer MV is generated 
+ * externally.  The input parameters pSrcRefBuf and pSearchPointRefPos should be 
+ * shifted by the winning MV of 16x16 integer search prior to calling BlockMatch_Half_16x16.  
+ * The function BlockMatch_Integer_16x16 may be used for integer motion estimation.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	pSrcRefBuf		pointer to the reference Y plane; points to the reference MB 
+ *                    that corresponds to the location of the current macroblock in 
+ *                    the	current plane.
+ * [in]	refWidth		  width of the reference plane
+ * [in]	pRefRect		  reference plane valid region rectangle
+ * [in]	pSrcCurrBuf		pointer to the current macroblock extracted from original plane 
+ *                    (linear array, 256 entries); must be aligned on an 8-byte boundary. 
+ * [in]	pSearchPointRefPos	position of the starting point for half pixel search (specified 
+ *                          in terms of integer pixel units) in the reference plane.
+ * [in]	rndVal			  rounding control bit for half pixel motion estimation; 
+ *                    0=rounding control disabled; 1=rounding control enabled
+ * [in]	pSrcDstMV		pointer to the initial MV estimate; typically generated during a prior 
+ *                  16X16 integer search and its unit is half pixel.
+ * [in] BlockSize     MacroBlock Size i.e either 16x16 or 8x8.
+ * [out]pSrcDstMV		pointer to estimated MV
+ * [out]pDstSAD			pointer to minimum SAD
+ *
+ * Return Value:
+ * OMX_Sts_NoErr ¨C no error
+ * OMX_Sts_BadArgErr ¨C bad arguments
+ *
+ */
+
+OMXResult armVCM4P2_BlockMatch_Half(
+     const OMX_U8 *pSrcRefBuf,
+     OMX_INT refWidth,
+     const OMXRect *pRefRect,
+     const OMX_U8 *pSrcCurrBuf,
+     const OMXVCM4P2Coordinate *pSearchPointRefPos,
+     OMX_INT rndVal,
+     OMXVCMotionVector *pSrcDstMV,
+     OMX_INT *pDstSAD,
+     OMX_U8 BlockSize
+);
+/**
+ * Function: armVCM4P2_PadMV
+ *
+ * Description:
+ * Performs motion vector padding for a macroblock.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] pSrcDstMV       pointer to motion vector buffer of the current
+ *                              macroblock
+ * [in] pTransp         pointer to transparent status buffer of the
+ *                              current macroblock
+ * [out]    pSrcDstMV       pointer to motion vector buffer in which the
+ *                              motion vectors have been padded
+ * Return Value:
+ * Standard OMXResult result. See enumeration for possible result codes.
+ *
+ */
+
+OMXResult armVCM4P2_PadMV(
+     OMXVCMotionVector * pSrcDstMV,
+     OMX_U8 * pTransp
+);
+
+/* 
+ * H.264 Specific Declarations 
+ */
+/* Defines */
+#define ARM_M4P10_Q_OFFSET        (15)
+
+
+/* Dequant tables */
+
+extern const OMX_U8 armVCM4P10_PosToVCol4x4[16];
+extern const OMX_U8 armVCM4P10_PosToVCol2x2[4];
+extern const OMX_U8 armVCM4P10_VMatrix[6][3];
+extern const OMX_U32 armVCM4P10_MFMatrix[6][3];
+
+
+/*
+ * Description:
+ * This function perform the work required by the OpenMAX
+ * DecodeCoeffsToPair function and DecodeChromaDCCoeffsToPair.
+ * Since most of the code is common we share it here.
+ *
+ * Parameters:
+ * [in]	ppBitStream		Double pointer to current byte in bit stream buffer
+ * [in]	pOffset			Pointer to current bit position in the byte pointed
+ *								to by *ppBitStream
+ * [in]	sMaxNumCoeff	Maximum number of non-zero coefficients in current
+ *								block (4,15 or 16)
+ * [in]	nTable          Table number (0 to 4) according to the five columns
+ *                      of Table 9-5 in the H.264 spec
+ * [out]	ppBitStream		*ppBitStream is updated after each block is decoded
+ * [out]	pOffset			*pOffset is updated after each block is decoded
+ * [out]	pNumCoeff		Pointer to the number of nonzero coefficients in
+ *								this block
+ * [out]	ppPosCoefbuf	Double pointer to destination residual
+ *								coefficient-position pair buffer
+ * Return Value:
+ * Standard omxError result. See enumeration for possible result codes.
+
+ */
+
+OMXResult armVCM4P10_DecodeCoeffsToPair(
+     const OMX_U8** ppBitStream,
+     OMX_S32* pOffset,
+     OMX_U8* pNumCoeff,
+     OMX_U8**ppPosCoefbuf,
+     OMX_INT nTable,
+     OMX_INT sMaxNumCoeff        
+ );
+
+/*
+ * Description:
+ * Perform DC style intra prediction, averaging upper and left block
+ *
+ * Parameters:
+ * [in]	pSrcLeft		Pointer to the buffer of 16 left coefficients:
+ *								p[x, y] (x = -1, y = 0..3)
+ * [in]	pSrcAbove		Pointer to the buffer of 16 above coefficients:
+ *								p[x,y] (x = 0..3, y = -1)
+ * [in]	leftStep		Step of left coefficient buffer
+ * [in]	dstStep			Step of the destination buffer
+ * [in]	availability	Neighboring 16x16 MB availability flag
+ * [out]	pDst			Pointer to the destination buffer
+ *
+ * Return Value:
+ * None
+ */
+
+void armVCM4P10_PredictIntraDC4x4(
+     const OMX_U8* pSrcLeft,
+     const OMX_U8 *pSrcAbove,
+     OMX_U8* pDst,
+     OMX_INT leftStep,
+     OMX_INT dstStep,
+     OMX_S32 availability        
+);
+
+/*
+ * Description
+ * Unpack a 4x4 block of coefficient-residual pair values
+ *
+ * Parameters:
+ * [in]	ppSrc	Double pointer to residual coefficient-position pair
+ *						buffer output by CALVC decoding
+ * [out]	ppSrc	*ppSrc is updated to the start of next non empty block
+ * [out]	pDst	Pointer to unpacked 4x4 block
+ */
+
+void armVCM4P10_UnpackBlock4x4(
+     const OMX_U8 **ppSrc,
+     OMX_S16* pDst
+);
+
+/*
+ * Description
+ * Unpack a 2x2 block of coefficient-residual pair values
+ *
+ * Parameters:
+ * [in]	ppSrc	Double pointer to residual coefficient-position pair
+ *						buffer output by CALVC decoding
+ * [out]	ppSrc	*ppSrc is updated to the start of next non empty block
+ * [out]	pDst	Pointer to unpacked 4x4 block
+ */
+
+void armVCM4P10_UnpackBlock2x2(
+     const OMX_U8 **ppSrc,
+     OMX_S16* pDst
+);
+
+/*
+ * Description
+ * Deblock one boundary pixel
+ *
+ * Parameters:
+ * [in]	pQ0         Pointer to pixel q0
+ * [in] Step        Step between pixels q0 and q1
+ * [in] tC0         Edge threshold value
+ * [in] alpha       alpha threshold value
+ * [in] beta        beta threshold value
+ * [in] bS          deblocking strength
+ * [in] ChromaFlag  True for chroma blocks
+ * [out] pQ0        Deblocked pixels
+ * 
+ */
+
+void armVCM4P10_DeBlockPixel(
+    OMX_U8 *pQ0,    /* pointer to the pixel q0 */
+    int Step,       /* step between pixels q0 and q1 */
+    int tC0,        /* edge threshold value */
+    int alpha,      /* alpha */
+    int beta,       /* beta */
+    int bS,         /* deblocking strength */
+    int ChromaFlag
+);
+
+/**
+ * Function: armVCM4P10_InterpolateHalfHor_Luma
+ *
+ * Description:
+ * This function performs interpolation for horizontal 1/2-pel positions
+ *
+ * Remarks:
+ *
+ *	[in]	pSrc			Pointer to top-left corner of block used to interpolate 
+ 													in the reconstructed frame plane
+ *	[in]	iSrcStep	Step of the source buffer.
+ *	[in]	iDstStep	Step of the destination(interpolation) buffer.
+ *	[in]	iWidth		Width of the current block
+ *	[in]	iHeight		Height of the current block
+ *	[out]	pDst	    Pointer to the interpolation buffer of the 1/2-pel 
+ *
+ * Return Value:
+ * Standard OMXResult value.
+ *
+ */
+
+OMXResult armVCM4P10_InterpolateHalfHor_Luma(
+        const OMX_U8*		pSrc, 
+		OMX_U32 	iSrcStep, 
+		OMX_U8* 	pDst, 
+		OMX_U32 	iDstStep, 
+		OMX_U32 	iWidth, 
+		OMX_U32 	iHeight
+);
+
+/**
+ * Function: armVCM4P10_InterpolateHalfVer_Luma
+ * 
+ * Description:
+ * This function performs interpolation for vertical 1/2-pel positions 
+ * around a full-pel position.
+ *
+ * Remarks:
+ *
+ *	[in]	pSrc			Pointer to top-left corner of block used to interpolate 
+ *												in the reconstructed frame plane
+ *	[in]	iSrcStep	Step of the source buffer.
+ *	[in]	iDstStep	Step of the destination(interpolation) buffer.
+ *	[in]	iWidth		Width of the current block
+ *	[in]	iHeight		Height of the current block
+ *	[out]	pDst    	Pointer to the interpolation buffer of the 1/2-pel
+ *
+ * Return Value:
+ * Standard OMXResult value.
+ *
+ */
+
+OMXResult armVCM4P10_InterpolateHalfVer_Luma(	
+	 const OMX_U8* 	pSrc, 
+	 OMX_U32 	iSrcStep, 
+ 	 OMX_U8* 	pDst,
+ 	 OMX_U32 	iDstStep, 
+ 	 OMX_U32 	iWidth, 
+ 	 OMX_U32 	iHeight
+);
+
+/**
+ * Function: armVCM4P10_InterpolateHalfDiag_Luma
+ * 
+ * Description:
+ * This function performs interpolation for (1/2, 1/2)  positions 
+ * around a full-pel position.
+ *
+ * Remarks:
+ *
+ *  [in]    pSrc        Pointer to top-left corner of block used to interpolate 
+ *                      in the reconstructed frame plane
+ *  [in]    iSrcStep    Step of the source buffer.
+ *  [in]    iDstStep    Step of the destination(interpolation) buffer.
+ *  [in]    iWidth      Width of the current block
+ *  [in]    iHeight     Height of the current block
+ *  [out]   pDst        Pointer to the interpolation buffer of the (1/2,1/2)-pel
+ *
+ * Return Value:
+ * Standard OMXResult value.
+ *
+ */
+
+OMXResult armVCM4P10_InterpolateHalfDiag_Luma(  
+        const OMX_U8*     pSrc, 
+        OMX_U32     iSrcStep, 
+        OMX_U8*     pDst, 
+        OMX_U32     iDstStep,
+        OMX_U32     iWidth, 
+        OMX_U32     iHeight
+);
+
+/*
+ * Description:
+ * Transform Residual 4x4 Coefficients
+ *
+ * Parameters:
+ * [in]  pSrc		Source 4x4 block
+ * [out] pDst		Destination 4x4 block
+ *
+ */
+
+void armVCM4P10_TransformResidual4x4(OMX_S16* pDst, OMX_S16 *pSrc);
+
+/*
+ * Description:
+ * Forward Transform Residual 4x4 Coefficients
+ *
+ * Parameters:
+ * [in]  pSrc		Source 4x4 block
+ * [out] pDst		Destination 4x4 block
+ *
+ */
+
+void armVCM4P10_FwdTransformResidual4x4(OMX_S16* pDst, OMX_S16 *pSrc);
+
+OMX_INT armVCM4P10_CompareMotionCostToMV (
+    OMX_S16  mvX,
+    OMX_S16  mvY,
+    OMXVCMotionVector diffMV, 
+    OMX_INT candSAD, 
+    OMXVCMotionVector *bestMV, 
+    OMX_U32 nLamda,
+    OMX_S32 *pBestCost);
+
+/**
+ * Function: armVCCOMM_SAD
+ *
+ * Description:
+ * This function calculate the SAD for NxM blocks.
+ *
+ * Remarks:
+ *
+ * [in]		pSrcOrg		Pointer to the original block
+ * [in]		iStepOrg	Step of the original block buffer
+ * [in]		pSrcRef		Pointer to the reference block
+ * [in]		iStepRef	Step of the reference block buffer
+ * [in]		iHeight		Height of the block
+ * [in]		iWidth		Width of the block
+ * [out]	pDstSAD		Pointer of result SAD
+ *
+ * Return Value:
+ * Standard OMXResult value.
+ *
+ */
+OMXResult armVCCOMM_SAD(	
+	const OMX_U8* 	pSrcOrg,
+	OMX_U32 	iStepOrg,
+	const OMX_U8* 	pSrcRef,
+	OMX_U32 	iStepRef,
+	OMX_S32*	pDstSAD,
+	OMX_U32		iHeight,
+	OMX_U32		iWidth);
+
+/**
+ * Function: armVCCOMM_Average
+ *
+ * Description:
+ * This function calculates the average of two blocks and stores the result.
+ *
+ * Remarks:
+ *
+ *	[in]	pPred0			Pointer to the top-left corner of reference block 0
+ *	[in]	pPred1			Pointer to the top-left corner of reference block 1
+ *	[in]	iPredStep0	    Step of reference block 0
+ *	[in]	iPredStep1	    Step of reference block 1
+ *	[in]	iDstStep 		Step of the destination buffer
+ *	[in]	iWidth			Width of the blocks
+ *	[in]	iHeight			Height of the blocks
+ *	[out]	pDstPred		Pointer to the destination buffer
+ *
+ * Return Value:
+ * Standard OMXResult value.
+ *
+ */
+ OMXResult armVCCOMM_Average (
+	 const OMX_U8* 	    pPred0,
+	 const OMX_U8* 	    pPred1,	
+	 OMX_U32		iPredStep0,
+	 OMX_U32		iPredStep1,
+	 OMX_U8*		pDstPred,
+	 OMX_U32		iDstStep, 
+	 OMX_U32		iWidth,
+	 OMX_U32		iHeight
+);
+
+/**
+ * Function: armVCM4P10_SADQuar
+ *
+ * Description:
+ * This function calculates the SAD between one block (pSrc) and the 
+ * average of the other two (pSrcRef0 and pSrcRef1)
+ *
+ * Remarks:
+ *
+ * [in]		pSrc				Pointer to the original block
+ * [in]		pSrcRef0		Pointer to reference block 0
+ * [in]		pSrcRef1		Pointer to reference block 1
+ * [in]		iSrcStep 		Step of the original block buffer
+ * [in]		iRefStep0		Step of reference block 0 
+ * [in]		iRefStep1 	Step of reference block 1 
+ * [in]		iHeight			Height of the block
+ * [in]		iWidth			Width of the block
+ * [out]	pDstSAD			Pointer of result SAD
+ *
+ * Return Value:
+ * Standard OMXResult value.
+ *
+ */
+OMXResult armVCM4P10_SADQuar(
+	const OMX_U8* 	pSrc,
+    const OMX_U8* 	pSrcRef0,
+	const OMX_U8* 	pSrcRef1,	
+    OMX_U32 	iSrcStep,
+    OMX_U32		iRefStep0,
+    OMX_U32		iRefStep1,
+    OMX_U32*	pDstSAD,
+    OMX_U32     iHeight,
+    OMX_U32     iWidth
+);
+
+/**
+ * Function: armVCM4P10_Interpolate_Chroma
+ *
+ * Description:
+ * This function performs interpolation for chroma components.
+ *
+ * Remarks:
+ *
+ *  [in]    pSrc            Pointer to top-left corner of block used to 
+ *                                              interpolate in the reconstructed frame plane
+ *  [in]    iSrcStep    Step of the source buffer.
+ *  [in]    iDstStep    Step of the destination(interpolation) buffer.
+ *  [in]    iWidth      Width of the current block
+ *  [in]    iHeight     Height of the current block
+ *  [in]    dx              Fractional part of horizontal motion vector 
+ *                                              component in 1/8 pixel unit (0~7) 
+ *  [in]    dy              Fractional part of vertical motion vector 
+ *                                              component in 1/8 pixel unit (0~7)
+ *  [out]   pDst            Pointer to the interpolation buffer
+ *
+ * Return Value:
+ * Standard OMXResult value.
+ *
+ */
+ OMXResult armVCM4P10_Interpolate_Chroma(
+        OMX_U8      *pSrc,
+        OMX_U32     iSrcStep,
+        OMX_U8      *pDst,
+        OMX_U32     iDstStep,
+        OMX_U32     iWidth,
+        OMX_U32     iHeight,
+        OMX_U32     dx,
+        OMX_U32     dy
+);
+
+/**
+ * Function: armVCM4P10_Interpolate_Luma
+ *
+ * Description:
+ * This function performs interpolation for luma components.
+ *
+ * Remarks:
+ *
+ *  [in]    pSrc            Pointer to top-left corner of block used to 
+ *                                              interpolate in the reconstructed frame plane
+ *  [in]    iSrcStep    Step of the source buffer.
+ *  [in]    iDstStep    Step of the destination(interpolation) buffer.
+ *  [in]    iWidth      Width of the current block
+ *  [in]    iHeight     Height of the current block
+ *  [in]    dx              Fractional part of horizontal motion vector 
+ *                                              component in 1/4 pixel unit (0~3) 
+ *  [in]    dy              Fractional part of vertical motion vector 
+ *                                              component in 1/4 pixel unit (0~3) 
+ *  [out]   pDst            Pointer to the interpolation buffer
+ *
+ * Return Value:
+ * Standard OMXResult value.
+ *
+ */
+
+ OMXResult armVCM4P10_Interpolate_Luma(
+     const OMX_U8     *pSrc,
+     OMX_U32    iSrcStep,
+     OMX_U8     *pDst,
+     OMX_U32    iDstStep,
+     OMX_U32    iWidth,
+     OMX_U32    iHeight,
+     OMX_U32    dx,
+     OMX_U32    dy
+);
+
+/**
+ * Function: omxVCH264_DequantTransformACFromPair_U8_S16_C1_DLx
+ *
+ * Description:
+ * Reconstruct the 4x4 residual block from coefficient-position pair buffer,
+ * perform dequantisation and integer inverse transformation for 4x4 block of
+ * residuals and update the pair buffer pointer to next non-empty block.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	ppSrc		Double pointer to residual coefficient-position
+ *							pair buffer output by CALVC decoding
+ * [in]	pDC			Pointer to the DC coefficient of this block, NULL
+ *							if it doesn't exist
+ * [in]	QP			Quantization parameter
+ * [in] AC          Flag indicating if at least one non-zero coefficient exists
+ * [out]	pDst		pointer to the reconstructed 4x4 block data
+ *
+ * Return Value:
+ * Standard omxError result. See enumeration for possible result codes.
+ *
+ */
+
+OMXResult armVCM4P10_DequantTransformACFromPair_U8_S16_C1_DLx(
+     OMX_U8 **ppSrc,
+     OMX_S16 *pDst,
+     OMX_INT QP,
+     OMX_S16* pDC,
+     int AC
+);
+
+#endif  /*_armVideo_H_*/
+
+/*End of File*/
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/api/armVCCOMM_s.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/api/armVCCOMM_s.h
new file mode 100755
index 0000000..32a0166
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/api/armVCCOMM_s.h
@@ -0,0 +1,72 @@
+;//
+;// 
+;// File Name:  armVCCOMM_s.h
+;// OpenMAX DL: v1.0.2
+;// Revision:   12290
+;// Date:       Wednesday, April 9, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+;// ARM optimized OpenMAX AC header file
+;// 
+;// Formula used:
+;// MACRO for calculating median for three values.
+
+
+
+    IF :LNOT::DEF:ARMVCCOMM_S_H
+        INCLUDE armCOMM_s.h
+    M_VARIANTS      CortexA8, ARM1136JS
+    
+    IF ARM1136JS :LOR: CortexA8 
+     
+     ;///*
+     ;// * Macro: M_MEDIAN3
+     ;// *
+     ;// * Description: Finds the median of three numbers
+     ;// * 
+     ;// * Remarks:
+     ;// *
+     ;// * Parameters:
+     ;// * [in] x     First entry for the list of three numbers.
+     ;// * [in] y     Second entry for the list of three numbers.
+     ;// *            Input value may be corrupted at the end of
+     ;// *            the execution of this macro.
+     ;// * [in] z     Third entry of the list of three numbers.
+     ;// *            Input value corrupted at the end of the 
+     ;// *            execution of this macro.
+     ;// * [in] t     Temporary scratch  register.
+     ;// * [out]z     Median of the three numbers.       
+     ;// */
+     
+     MACRO
+
+     M_MEDIAN3 $x, $y, $z, $t 
+     
+     SUBS  $t, $y, $z; // if (y < z)
+     ADDLT $z, $z, $t; //  swap y and z
+     SUBLT $y, $y, $t;
+
+     ;// Now z' <= y', so there are three cases for the
+     ;// median value, depending on x.
+
+     ;// 1) x <= z'      <= y'      : median value is z'
+     ;// 2)      z' <= x <= y'      : median value is x
+     ;// 3)      z'      <= y' <= x : median value is y'
+
+     CMP   $z, $x;     // if ( x > min(y,z) )
+     MOVLT $z, $x;     // ans = x 
+
+     CMP   $x, $y;     // if ( x > max(y,z) )
+     MOVGT $z, $y;     // ans = max(y,z)
+     
+     MEND
+    ENDIF      
+    
+    
+        
+    ENDIF ;// ARMACCOMM_S_H
+
+ END
\ No newline at end of file
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/api/omxVC.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/api/omxVC.h
new file mode 100755
index 0000000..7b3cc72
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/api/omxVC.h
@@ -0,0 +1,4381 @@
+/**
+ * File: omxVC.h
+ * Brief: OpenMAX DL v1.0.2 - Video Coding library
+ *
+ * Copyright © 2005-2008 The Khronos Group Inc. All Rights Reserved. 
+ *
+ * These materials are protected by copyright laws and contain material 
+ * proprietary to the Khronos Group, Inc.  You may use these materials 
+ * for implementing Khronos specifications, without altering or removing 
+ * any trademark, copyright or other notice from the specification.
+ * 
+ * Khronos Group makes no, and expressly disclaims any, representations 
+ * or warranties, express or implied, regarding these materials, including, 
+ * without limitation, any implied warranties of merchantability or fitness 
+ * for a particular purpose or non-infringement of any intellectual property. 
+ * Khronos Group makes no, and expressly disclaims any, warranties, express 
+ * or implied, regarding the correctness, accuracy, completeness, timeliness, 
+ * and reliability of these materials. 
+ *
+ * Under no circumstances will the Khronos Group, or any of its Promoters, 
+ * Contributors or Members or their respective partners, officers, directors, 
+ * employees, agents or representatives be liable for any damages, whether 
+ * direct, indirect, special or consequential damages for lost revenues, 
+ * lost profits, or otherwise, arising from or in connection with these 
+ * materials.
+ * 
+ * Khronos and OpenMAX are trademarks of the Khronos Group Inc. 
+ *
+ */
+
+/* *****************************************************************************************/
+
+#ifndef _OMXVC_H_
+#define _OMXVC_H_
+
+#include "omxtypes.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* 6.1.1.1 Motion Vectors  */
+/* In omxVC, motion vectors are represented as follows:  */
+
+typedef struct {
+    OMX_S16 dx;
+    OMX_S16 dy;
+} OMXVCMotionVector;
+
+
+
+/**
+ * Function:  omxVCCOMM_Average_8x   (6.1.3.1.1)
+ *
+ * Description:
+ * This function calculates the average of two 8x4, 8x8, or 8x16 blocks.  The 
+ * result is rounded according to (a+b+1)/2.  The block average function can 
+ * be used in conjunction with half-pixel interpolation to obtain quarter 
+ * pixel motion estimates, as described in [ISO14496-10], subclause 8.4.2.2.1. 
+ *
+ * Input Arguments:
+ *   
+ *   pPred0     - Pointer to the top-left corner of reference block 0 
+ *   pPred1     - Pointer to the top-left corner of reference block 1 
+ *   iPredStep0 - Step of reference block 0 
+ *   iPredStep1 - Step of reference block 1 
+ *   iDstStep   - Step of the destination buffer. 
+ *   iHeight    - Height of the blocks 
+ *
+ * Output Arguments:
+ *   
+ *   pDstPred - Pointer to the destination buffer. 8-byte aligned. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned under any of the following 
+ *              conditions: 
+ *    -   one or more of the following pointers is NULL: pPred0, pPred1, or 
+ *              pDstPred. 
+ *    -   pDstPred is not aligned on an 8-byte boundary. 
+ *    -   iPredStep0 <= 0 or iPredStep0 is not a multiple of 8. 
+ *    -   iPredStep1 <= 0 or iPredStep1 is not a multiple of 8. 
+ *    -   iDstStep   <= 0 or iDstStep is not a multiple of 8. 
+ *    -   iHeight is not 4, 8, or 16. 
+ *
+ */
+OMXResult omxVCCOMM_Average_8x (
+    const OMX_U8 *pPred0,
+    const OMX_U8 *pPred1,
+    OMX_U32 iPredStep0,
+    OMX_U32 iPredStep1,
+    OMX_U8 *pDstPred,
+    OMX_U32 iDstStep,
+    OMX_U32 iHeight
+);
+
+
+
+/**
+ * Function:  omxVCCOMM_Average_16x   (6.1.3.1.2)
+ *
+ * Description:
+ * This function calculates the average of two 16x16 or 16x8 blocks.  The 
+ * result is rounded according to (a+b+1)/2.  The block average function can 
+ * be used in conjunction with half-pixel interpolation to obtain quarter 
+ * pixel motion estimates, as described in [ISO14496-10], subclause 8.4.2.2.1. 
+ *
+ * Input Arguments:
+ *   
+ *   pPred0 - Pointer to the top-left corner of reference block 0 
+ *   pPred1 - Pointer to the top-left corner of reference block 1 
+ *   iPredStep0 - Step of reference block 0 
+ *   iPredStep1 - Step of reference block 1 
+ *   iDstStep - Step of the destination buffer 
+ *   iHeight - Height of the blocks 
+ *
+ * Output Arguments:
+ *   
+ *   pDstPred - Pointer to the destination buffer. 16-byte aligned. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned under any of the following 
+ *              conditions: 
+ *    -   one or more of the following pointers is NULL: pPred0, pPred1, or 
+ *              pDstPred. 
+ *    -   pDstPred is not aligned on a 16-byte boundary. 
+ *    -   iPredStep0 <= 0 or iPredStep0 is not a multiple of 16. 
+ *    -   iPredStep1 <= 0 or iPredStep1 is not a multiple of 16. 
+ *    -   iDstStep <= 0 or iDstStep is not a multiple of 16. 
+ *    -   iHeight is not 8 or 16. 
+ *
+ */
+OMXResult omxVCCOMM_Average_16x (
+    const OMX_U8 *pPred0,
+    const OMX_U8 *pPred1,
+    OMX_U32 iPredStep0,
+    OMX_U32 iPredStep1,
+    OMX_U8 *pDstPred,
+    OMX_U32 iDstStep,
+    OMX_U32 iHeight
+);
+
+
+
+/**
+ * Function:  omxVCCOMM_ExpandFrame_I   (6.1.3.2.1)
+ *
+ * Description:
+ * This function expands a reconstructed frame in-place.  The unexpanded 
+ * source frame should be stored in a plane buffer with sufficient space 
+ * pre-allocated for edge expansion, and the input frame should be located in 
+ * the plane buffer center.  This function executes the pixel expansion by 
+ * replicating source frame edge pixel intensities in the empty pixel 
+ * locations (expansion region) between the source frame edge and the plane 
+ * buffer edge.  The width/height of the expansion regions on the 
+ * horizontal/vertical edges is controlled by the parameter iExpandPels. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDstPlane - pointer to the top-left corner of the frame to be 
+ *            expanded; must be aligned on an 8-byte boundary. 
+ *   iFrameWidth - frame width; must be a multiple of 8. 
+ *   iFrameHeight -frame height; must be a multiple of 8. 
+ *   iExpandPels - number of pixels to be expanded in the horizontal and 
+ *            vertical directions; must be a multiple of 8. 
+ *   iPlaneStep - distance, in bytes, between the start of consecutive lines 
+ *            in the plane buffer; must be larger than or equal to 
+ *            (iFrameWidth + 2 * iExpandPels). 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDstPlane -Pointer to the top-left corner of the frame (NOT the 
+ *            top-left corner of the plane); must be aligned on an 8-byte 
+ *            boundary. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned under any of the following 
+ *              conditions: 
+ *    -    pSrcDstPlane is NULL. 
+ *    -    pSrcDstPlane is not aligned on an 8-byte boundary. 
+ *    -    one of the following parameters is either equal to zero or is a 
+ *              non-multiple of 8: iFrameHeight, iFrameWidth, iPlaneStep, or 
+ *              iExpandPels. 
+ *    -    iPlaneStep < (iFrameWidth + 2 * iExpandPels). 
+ *
+ */
+OMXResult omxVCCOMM_ExpandFrame_I (
+    OMX_U8 *pSrcDstPlane,
+    OMX_U32 iFrameWidth,
+    OMX_U32 iFrameHeight,
+    OMX_U32 iExpandPels,
+    OMX_U32 iPlaneStep
+);
+
+
+
+/**
+ * Function:  omxVCCOMM_Copy8x8   (6.1.3.3.1)
+ *
+ * Description:
+ * Copies the reference 8x8 block to the current block. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - pointer to the reference block in the source frame; must be 
+ *            aligned on an 8-byte boundary. 
+ *   step - distance between the starts of consecutive lines in the reference 
+ *            frame, in bytes; must be a multiple of 8 and must be larger than 
+ *            or equal to 8. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - pointer to the destination block; must be aligned on an 8-byte 
+ *            boundary. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned under any of the following 
+ *              conditions: 
+ *    -   one or more of the following pointers is NULL: pSrc, pDst 
+ *    -   one or more of the following pointers is not aligned on an 8-byte 
+ *              boundary: pSrc, pDst 
+ *    -    step <8 or step is not a multiple of 8. 
+ *
+ */
+OMXResult omxVCCOMM_Copy8x8 (
+    const OMX_U8 *pSrc,
+    OMX_U8 *pDst,
+    OMX_INT step
+);
+
+
+
+/**
+ * Function:  omxVCCOMM_Copy16x16   (6.1.3.3.2)
+ *
+ * Description:
+ * Copies the reference 16x16 macroblock to the current macroblock. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - pointer to the reference macroblock in the source frame; must be 
+ *            aligned on a 16-byte boundary. 
+ *   step - distance between the starts of consecutive lines in the reference 
+ *            frame, in bytes; must be a multiple of 16 and must be larger 
+ *            than or equal to 16. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - pointer to the destination macroblock; must be aligned on a 
+ *            16-byte boundary. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned under any of the following 
+ *              conditions: 
+ *    -   one or more of the following pointers is NULL: pSrc, pDst 
+ *    -   one or more of the following pointers is not aligned on a 16-byte 
+ *              boundary: pSrc, pDst 
+ *    -    step <16 or step is not a multiple of 16. 
+ *
+ */
+OMXResult omxVCCOMM_Copy16x16 (
+    const OMX_U8 *pSrc,
+    OMX_U8 *pDst,
+    OMX_INT step
+);
+
+
+
+/**
+ * Function:  omxVCCOMM_ComputeTextureErrorBlock_SAD   (6.1.4.1.1)
+ *
+ * Description:
+ * Computes texture error of the block; also returns SAD. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - pointer to the source plane; must be aligned on an 8-byte 
+ *            boundary. 
+ *   srcStep - step of the source plane 
+ *   pSrcRef - pointer to the reference buffer, an 8x8 block; must be aligned 
+ *            on an 8-byte boundary. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - pointer to the destination buffer, an 8x8 block; must be aligned 
+ *            on an 8-byte boundary. 
+ *   pDstSAD - pointer to the Sum of Absolute Differences (SAD) value 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments 
+ *    -    At least one of the following 
+ *         pointers is NULL: pSrc, pSrcRef, pDst and pDstSAD. 
+ *    -    pSrc is not 8-byte aligned. 
+ *    -    SrcStep <= 0 or srcStep is not a multiple of 8. 
+ *    -    pSrcRef is not 8-byte aligned. 
+ *    -    pDst is not 8-byte aligned. 
+ *
+ */
+OMXResult omxVCCOMM_ComputeTextureErrorBlock_SAD (
+    const OMX_U8 *pSrc,
+    OMX_INT srcStep,
+    const OMX_U8 *pSrcRef,
+    OMX_S16 *pDst,
+    OMX_INT *pDstSAD
+);
+
+
+
+/**
+ * Function:  omxVCCOMM_ComputeTextureErrorBlock   (6.1.4.1.2)
+ *
+ * Description:
+ * Computes the texture error of the block. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - pointer to the source plane. This should be aligned on an 8-byte 
+ *            boundary. 
+ *   srcStep - step of the source plane 
+ *   pSrcRef - pointer to the reference buffer, an 8x8 block. This should be 
+ *            aligned on an 8-byte boundary. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - pointer to the destination buffer, an 8x8 block. This should be 
+ *            aligned on an 8-byte boundary. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments:
+ *    -    At least one of the following pointers is NULL: 
+ *         pSrc, pSrcRef, pDst. 
+ *    -    pSrc is not 8-byte aligned. 
+ *    -    SrcStep <= 0 or srcStep is not a multiple of 8. 
+ *    -    pSrcRef is not 8-byte aligned. 
+ *    -    pDst is not 8-byte aligned 
+ *
+ */
+OMXResult omxVCCOMM_ComputeTextureErrorBlock (
+    const OMX_U8 *pSrc,
+    OMX_INT srcStep,
+    const OMX_U8 *pSrcRef,
+    OMX_S16 *pDst
+);
+
+
+
+/**
+ * Function:  omxVCCOMM_LimitMVToRect   (6.1.4.1.3)
+ *
+ * Description:
+ * Limits the motion vector associated with the current block/macroblock to 
+ * prevent the motion compensated block/macroblock from moving outside a 
+ * bounding rectangle as shown in Figure 6-1. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcMV - pointer to the motion vector associated with the current block 
+ *            or macroblock 
+ *   pRectVOPRef - pointer to the bounding rectangle 
+ *   Xcoord, Ycoord  - coordinates of the current block or macroblock 
+ *   size - size of the current block or macroblock; must be equal to 8 or 
+ *            16. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstMV - pointer to the limited motion vector 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments.  Returned if one or more of the 
+ *              following conditions is true: 
+ *    -    at least one of the following pointers is NULL: 
+ *         pSrcMV, pDstMV, or pRectVOPRef. 
+ *    -    size is not equal to either 8 or 16. 
+ *    -    the width or height of the bounding rectangle is less than 
+ *         twice the block size.
+ */
+OMXResult omxVCCOMM_LimitMVToRect (
+    const OMXVCMotionVector *pSrcMV,
+    OMXVCMotionVector *pDstMV,
+    const OMXRect *pRectVOPRef,
+    OMX_INT Xcoord,
+    OMX_INT Ycoord,
+    OMX_INT size
+);
+
+
+
+/**
+ * Function:  omxVCCOMM_SAD_16x   (6.1.4.1.4)
+ *
+ * Description:
+ * This function calculates the SAD for 16x16 and 16x8 blocks. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcOrg - Pointer to the original block; must be aligned on a 16-byte 
+ *             boundary. 
+ *   iStepOrg - Step of the original block buffer 
+ *   pSrcRef  - Pointer to the reference block 
+ *   iStepRef - Step of the reference block buffer 
+ *   iHeight  - Height of the block 
+ *
+ * Output Arguments:
+ *   
+ *   pDstSAD - Pointer of result SAD 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments.  Returned if one or more of the 
+ *              following conditions is true: 
+ *    -    at least one of the following pointers is NULL: 
+ *         pSrcOrg, pDstSAD, or pSrcRef 
+ *    -    pSrcOrg is not 16-byte aligned. 
+ *    -    iStepOrg  <= 0 or iStepOrg is not a multiple of 16 
+ *    -    iStepRef <= 0 or iStepRef is not a multiple of 16 
+ *    -    iHeight is not 8 or 16 
+ *
+ */
+OMXResult omxVCCOMM_SAD_16x (
+    const OMX_U8 *pSrcOrg,
+    OMX_U32 iStepOrg,
+    const OMX_U8 *pSrcRef,
+    OMX_U32 iStepRef,
+    OMX_S32 *pDstSAD,
+    OMX_U32 iHeight
+);
+
+
+
+/**
+ * Function:  omxVCCOMM_SAD_8x   (6.1.4.1.5)
+ *
+ * Description:
+ * This function calculates the SAD for 8x16, 8x8, 8x4 blocks. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcOrg  - Pointer to the original block; must be aligned on a 8-byte 
+ *              boundary. 
+ *   iStepOrg - Step of the original block buffer 
+ *   pSrcRef  - Pointer to the reference block 
+ *   iStepRef - Step of the reference block buffer 
+ *   iHeight  - Height of the block 
+ *
+ * Output Arguments:
+ *   
+ *   pDstSAD -Pointer of result SAD 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments.  Returned if one or more of the 
+ *              following conditions is true: 
+ *    -    at least one of the following pointers is NULL: 
+ *         pSrcOrg, pDstSAD, or pSrcRef 
+ *    -    pSrcOrg is not 8-byte aligned. 
+ *    -    iStepOrg  <= 0 or iStepOrg is not a multiple of 8 
+ *    -    iStepRef <= 0 or iStepRef is not a multiple of 8 
+ *    -    iHeight is not 4, 8 or 16 
+ *
+ */
+OMXResult omxVCCOMM_SAD_8x (
+    const OMX_U8 *pSrcOrg,
+    OMX_U32 iStepOrg,
+    const OMX_U8 *pSrcRef,
+    OMX_U32 iStepRef,
+    OMX_S32*pDstSAD,
+    OMX_U32 iHeight
+);
+
+
+
+/* 6.2.1.1 Direction  */
+/* The direction enumerator is used with functions that perform AC/DC prediction and zig-zag scan.  */
+
+enum {
+    OMX_VC_NONE       = 0,
+    OMX_VC_HORIZONTAL = 1,
+    OMX_VC_VERTICAL   = 2 
+};
+
+
+
+/* 6.2.1.2 Bilinear Interpolation  */
+/* The bilinear interpolation enumerator is used with motion estimation, motion compensation, and reconstruction functions.  */
+
+enum {
+    OMX_VC_INTEGER_PIXEL = 0, /* case a */
+    OMX_VC_HALF_PIXEL_X  = 1, /* case b */
+    OMX_VC_HALF_PIXEL_Y  = 2, /* case c */
+    OMX_VC_HALF_PIXEL_XY = 3  /* case d */ 
+};
+
+
+
+/* 6.2.1.3 Neighboring Macroblock Availability  */
+/* Neighboring macroblock availability is indicated using the following flags:   */
+
+enum {
+    OMX_VC_UPPER = 1,        /** above macroblock is available */
+    OMX_VC_LEFT = 2,         /** left macroblock is available */
+    OMX_VC_CENTER = 4,
+    OMX_VC_RIGHT = 8,
+    OMX_VC_LOWER = 16,
+    OMX_VC_UPPER_LEFT = 32,  /** above-left macroblock is available */
+    OMX_VC_UPPER_RIGHT = 64, /** above-right macroblock is available */
+    OMX_VC_LOWER_LEFT = 128,
+    OMX_VC_LOWER_RIGHT = 256 
+};
+
+
+
+/* 6.2.1.4 Video Components  */
+/* A data type that enumerates video components is defined as follows:  */
+
+typedef enum {
+    OMX_VC_LUMINANCE,    /** Luminance component */
+    OMX_VC_CHROMINANCE   /** chrominance component */ 
+} OMXVCM4P2VideoComponent;
+
+
+
+/* 6.2.1.5 MacroblockTypes  */
+/* A data type that enumerates macroblock types is defined as follows:  */
+
+typedef enum {
+    OMX_VC_INTER     = 0, /** P picture or P-VOP */
+    OMX_VC_INTER_Q   = 1, /** P picture or P-VOP */
+    OMX_VC_INTER4V   = 2, /** P picture or P-VOP */
+    OMX_VC_INTRA     = 3, /** I and P picture, I- and P-VOP */
+    OMX_VC_INTRA_Q   = 4, /** I and P picture, I- and P-VOP */
+    OMX_VC_INTER4V_Q = 5  /** P picture or P-VOP (H.263)*/
+} OMXVCM4P2MacroblockType;
+
+
+
+/* 6.2.1.6 Coordinates  */
+/* Coordinates are represented as follows:  */
+
+typedef struct {
+    OMX_INT x;
+    OMX_INT y;
+} OMXVCM4P2Coordinate;
+
+
+
+/* 6.2.1.7 Motion Estimation Algorithms  */
+/* A data type that enumerates motion estimation search methods is defined as follows:  */
+
+typedef enum {
+    OMX_VC_M4P2_FAST_SEARCH = 0,  /** Fast motion search */
+    OMX_VC_M4P2_FULL_SEARCH = 1   /** Full motion search */ 
+} OMXVCM4P2MEMode;
+
+
+
+/* 6.2.1.8 Motion Estimation Parameters  */
+/* A data structure containing control parameters for 
+ * motion estimation functions is defined as follows:  
+ */
+
+typedef struct {
+    OMX_INT searchEnable8x8;     /** enables 8x8 search */
+    OMX_INT halfPelSearchEnable; /** enables half-pel resolution */
+    OMX_INT searchRange;         /** search range */
+    OMX_INT rndVal;              /** rounding control; 0-disabled, 1-enabled*/
+} OMXVCM4P2MEParams;
+
+
+
+/* 6.2.1.9 Macroblock Information   */
+/* A data structure containing macroblock parameters for 
+ * motion estimation functions is defined as follows:  
+ */
+
+typedef struct {
+    OMX_S32 sliceId;                 /* slice number */
+    OMXVCM4P2MacroblockType mbType;  /* MB type: OMX_VC_INTRA, OMX_VC_INTER, or OMX_VC_INTER4 */
+    OMX_S32 qp;                      /* quantization parameter*/
+    OMX_U32 cbpy;                    /* CBP Luma */
+    OMX_U32 cbpc;                    /* CBP Chroma */
+    OMXVCMotionVector pMV0[2][2];    /* motion vector, represented using 1/2-pel units, 
+                                      * pMV0[blocky][blockx] (blocky = 0~1, blockx =0~1) 
+                                      */
+    OMXVCMotionVector pMVPred[2][2]; /* motion vector prediction, represented using 1/2-pel units, 
+                                      * pMVPred[blocky][blockx] (blocky = 0~1, blockx = 0~1) 
+                                      */
+    OMX_U8 pPredDir[2][2];           /* AC prediction direction: 
+                                      *   OMX_VC_NONE, OMX_VC_VERTICAL, OMX_VC_HORIZONTAL 
+                                      */
+} OMXVCM4P2MBInfo, *OMXVCM4P2MBInfoPtr;
+
+
+
+/**
+ * Function:  omxVCM4P2_FindMVpred   (6.2.3.1.1)
+ *
+ * Description:
+ * Predicts a motion vector for the current block using the procedure 
+ * specified in [ISO14496-2], subclause 7.6.5.  The resulting predicted MV is 
+ * returned in pDstMVPred. If the parameter pDstMVPredME if is not NULL then 
+ * the set of three MV candidates used for prediction is also returned, 
+ * otherwise pDstMVPredMEis NULL upon return. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcMVCurMB - pointer to the MV buffer associated with the current Y 
+ *            macroblock; a value of NULL indicates unavailability. 
+ *   pSrcCandMV1 - pointer to the MV buffer containing the 4 MVs associated 
+ *            with the MB located to the left of the current MB; set to NULL 
+ *            if there is no MB to the left. 
+ *   pSrcCandMV2 - pointer to the MV buffer containing the 4 MVs associated 
+ *            with the MB located above the current MB; set to NULL if there 
+ *            is no MB located above the current MB. 
+ *   pSrcCandMV3 - pointer to the MV buffer containing the 4 MVs associated 
+ *            with the MB located to the right and above the current MB; set 
+ *            to NULL if there is no MB located to the above-right. 
+ *   iBlk - the index of block in the current macroblock 
+ *   pDstMVPredME - MV candidate return buffer;  if set to NULL then 
+ *            prediction candidate MVs are not returned and pDstMVPredME will 
+ *            be NULL upon function return; if pDstMVPredME is non-NULL then it 
+ *            must point to a buffer containing sufficient space for three 
+ *            return MVs. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstMVPred - pointer to the predicted motion vector 
+ *   pDstMVPredME - if non-NULL upon input then pDstMVPredME  points upon 
+ *            return to a buffer containing the three motion vector candidates 
+ *            used for prediction as specified in [ISO14496-2], subclause 
+ *            7.6.5, otherwise if NULL upon input then pDstMVPredME is NULL 
+ *            upon output. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned under any of the following 
+ *              conditions: 
+ *    -    the pointer pDstMVPred is NULL 
+ *    -    the parameter iBlk does not fall into the range 0 <= iBlk<=3 
+ *
+ */
+OMXResult omxVCM4P2_FindMVpred (
+    const OMXVCMotionVector *pSrcMVCurMB,
+    const OMXVCMotionVector *pSrcCandMV1,
+    const OMXVCMotionVector *pSrcCandMV2,
+    const OMXVCMotionVector *pSrcCandMV3,
+    OMXVCMotionVector *pDstMVPred,
+    OMXVCMotionVector *pDstMVPredME,
+    OMX_INT iBlk
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_IDCT8x8blk   (6.2.3.2.1)
+ *
+ * Description:
+ * Computes a 2D inverse DCT for a single 8x8 block, as defined in 
+ * [ISO14496-2]. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - pointer to the start of the linearly arranged IDCT input buffer; 
+ *            must be aligned on a 16-byte boundary.  According to 
+ *            [ISO14496-2], the input coefficient values should lie within the 
+ *            range [-2048, 2047]. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - pointer to the start of the linearly arranged IDCT output buffer; 
+ *            must be aligned on a 16-byte boundary. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments:
+ *    -    pSrc or pDst is NULL. 
+ *    -    pSrc or pDst is not 16-byte aligned. 
+ *
+ */
+OMXResult omxVCM4P2_IDCT8x8blk (
+    const OMX_S16 *pSrc,
+    OMX_S16 *pDst
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_MEGetBufSize   (6.2.4.1.1)
+ *
+ * Description:
+ * Computes the size, in bytes, of the vendor-specific specification 
+ * structure for the following motion estimation functions: 
+ * BlockMatch_Integer_8x8, BlockMatch_Integer_16x16, and MotionEstimationMB. 
+ *
+ * Input Arguments:
+ *   
+ *   MEmode - motion estimation mode; available modes are defined by the 
+ *            enumerated type OMXVCM4P2MEMode 
+ *   pMEParams - motion estimation parameters 
+ *
+ * Output Arguments:
+ *   
+ *   pSize - pointer to the number of bytes required for the specification 
+ *            structure 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - one or more of the following is true: 
+ *    -    an invalid value was specified for the parameter MEmode 
+ *    -    a negative or zero value was specified for the 
+ *         parameter pMEParams->searchRange 
+ *
+ */
+OMXResult omxVCM4P2_MEGetBufSize (
+    OMXVCM4P2MEMode MEmode,
+    const OMXVCM4P2MEParams *pMEParams,
+    OMX_U32 *pSize
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_MEInit   (6.2.4.1.2)
+ *
+ * Description:
+ * Initializes the vendor-specific specification structure required for the 
+ * following motion estimation functions:  BlockMatch_Integer_8x8, 
+ * BlockMatch_Integer_16x16, and MotionEstimationMB. Memory for the 
+ * specification structure *pMESpec must be allocated prior to calling the 
+ * function, and should be aligned on a 4-byte boundary.  Following 
+ * initialization by this function, the vendor-specific structure *pMESpec 
+ * should contain an implementation-specific representation of all motion 
+ * estimation parameters received via the structure pMEParams, for example  
+ * rndVal, searchRange, etc.  The number of bytes required for the 
+ * specification structure can be determined using the function 
+ * omxVCM4P2_MEGetBufSize. 
+ *
+ * Input Arguments:
+ *   
+ *   MEmode - motion estimation mode; available modes are defined by the 
+ *            enumerated type OMXVCM4P2MEMode 
+ *   pMEParams - motion estimation parameters 
+ *   pMESpec - pointer to the uninitialized ME specification structure 
+ *
+ * Output Arguments:
+ *   
+ *   pMESpec - pointer to the initialized ME specification structure 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - one or more of the following is true: 
+ *    -    an invalid value was specified for the parameter MEmode 
+ *    -    a negative or zero value was specified for the 
+ *         parameter pMEParams->searchRange 
+ *
+ */
+OMXResult omxVCM4P2_MEInit (
+    OMXVCM4P2MEMode MEmode,
+    const OMXVCM4P2MEParams*pMEParams,
+    void *pMESpec
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_BlockMatch_Integer_16x16   (6.2.4.2.1)
+ *
+ * Description:
+ * Performs a 16x16 block search; estimates motion vector and associated 
+ * minimum SAD. Both the input and output motion vectors are represented using 
+ * half-pixel units, and therefore a shift left or right by 1 bit may be 
+ * required, respectively, to match the input or output MVs with other 
+ * functions that either generate output MVs or expect input MVs represented 
+ * using integer pixel units. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcRefBuf - pointer to the reference Y plane; points to the reference 
+ *            MB that corresponds to the location of the current macroblock in 
+ *            the current plane. 
+ *   refWidth - width of the reference plane 
+ *   pRefRect - pointer to the valid reference plane rectangle; coordinates 
+ *            are specified relative to the image origin.  Rectangle 
+ *            boundaries may extend beyond image boundaries if the image has 
+ *            been padded.  For example, if padding extends 4 pixels beyond 
+ *            frame border, then the value for the left border could be set to 
+ *            -4. 
+ *   pSrcCurrBuf - pointer to the current block in the current macroblock 
+ *            buffer extracted from the original plane (linear array, 256 
+ *            entries); must be aligned on a 16-byte boundary.  The number of 
+ *            bytes between lines (step) is 16. 
+ *   pCurrPointPos - position of the current macroblock in the current plane 
+ *   pSrcPreMV - pointer to predicted motion vector; NULL indicates no 
+ *            predicted MV 
+ *   pSrcPreSAD - pointer to SAD associated with the predicted MV (referenced 
+ *            by pSrcPreMV); may be set to NULL if unavailable. 
+ *   pMESpec - vendor-specific motion estimation specification structure; 
+ *            must have been allocated and then initialized using 
+ *            omxVCM4P2_MEInit prior to calling the block matching function. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstMV - pointer to estimated MV 
+ *   pDstSAD - pointer to minimum SAD 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments.  Returned if one of the following 
+ *              conditions is true: 
+ *    -    at least one of the following pointers is NULL: pSrcRefBuf, 
+ *              pRefRect, pSrcCurrBuff, pCurrPointPos, pDstMV, pDstSAD or 
+ *              pMESpec, or 
+ *    -    pSrcCurrBuf is not 16-byte aligned 
+ *
+ */
+OMXResult omxVCM4P2_BlockMatch_Integer_16x16 (
+    const OMX_U8 *pSrcRefBuf,
+    OMX_INT refWidth,
+    const OMXRect *pRefRect,
+    const OMX_U8 *pSrcCurrBuf,
+    const OMXVCM4P2Coordinate *pCurrPointPos,
+    const OMXVCMotionVector*pSrcPreMV,
+    const OMX_INT *pSrcPreSAD,
+    void *pMESpec,
+    OMXVCMotionVector*pDstMV,
+    OMX_INT *pDstSAD
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_BlockMatch_Integer_8x8   (6.2.4.2.2)
+ *
+ * Description:
+ * Performs an 8x8 block search; estimates motion vector and associated 
+ * minimum SAD.  Both the input and output motion vectors are represented 
+ * using half-pixel units, and therefore a shift left or right by 1 bit may be 
+ * required, respectively, to match the input or output MVs with other 
+ * functions that either generate output MVs or expect input MVs represented 
+ * using integer pixel units. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcRefBuf - pointer to the reference Y plane; points to the reference 
+ *            block that corresponds to the location of the current 8x8 block 
+ *            in the current plane. 
+ *   refWidth - width of the reference plane 
+ *   pRefRect - pointer to the valid reference plane rectangle; coordinates 
+ *            are specified relative to the image origin.  Rectangle 
+ *            boundaries may extend beyond image boundaries if the image has 
+ *            been padded. 
+ *   pSrcCurrBuf - pointer to the current block in the current macroblock 
+ *            buffer extracted from the original plane (linear array, 128 
+ *            entries); must be aligned on an 8-byte boundary.  The number of 
+ *            bytes between lines (step) is 16 bytes. 
+ *   pCurrPointPos - position of the current block in the current plane 
+ *   pSrcPreMV - pointer to predicted motion vector; NULL indicates no 
+ *            predicted MV 
+ *   pSrcPreSAD - pointer to SAD associated with the predicted MV (referenced 
+ *            by pSrcPreMV); may be set to NULL if unavailable. 
+ *   pMESpec - vendor-specific motion estimation specification structure; 
+ *            must have been allocated and then initialized using 
+ *            omxVCM4P2_MEInit prior to calling the block matching function. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstMV - pointer to estimated MV 
+ *   pDstSAD - pointer to minimum SAD 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments.  Returned if one of the following 
+ *              conditions is true: 
+ *    -    at least one of the following pointers is NULL: pSrcRefBuf, 
+ *              pRefRect, pSrcCurrBuff, pCurrPointPos, pDstMV, pDstSAD or 
+ *              pMESpec, or 
+ *    -    pSrcCurrBuf is not 8-byte aligned 
+ *
+ */
+OMXResult omxVCM4P2_BlockMatch_Integer_8x8 (
+    const OMX_U8 *pSrcRefBuf,
+    OMX_INT refWidth,
+    const OMXRect *pRefRect,
+    const OMX_U8 *pSrcCurrBuf,
+    const OMXVCM4P2Coordinate *pCurrPointPos,
+    const OMXVCMotionVector *pSrcPreMV,
+    const OMX_INT *pSrcPreSAD,
+    void *pMESpec,
+    OMXVCMotionVector *pDstMV,
+    OMX_INT *pDstSAD
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_BlockMatch_Half_16x16   (6.2.4.2.3)
+ *
+ * Description:
+ * Performs a 16x16 block match with half-pixel resolution.  Returns the 
+ * estimated motion vector and associated minimum SAD.  This function 
+ * estimates the half-pixel motion vector by interpolating the integer 
+ * resolution motion vector referenced by the input parameter pSrcDstMV, i.e., 
+ * the initial integer MV is generated externally.  The input parameters 
+ * pSrcRefBuf and pSearchPointRefPos should be shifted by the winning MV of 
+ * 16x16 integer search prior to calling BlockMatch_Half_16x16. The function 
+ * BlockMatch_Integer_16x16 may be used for integer motion estimation. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcRefBuf - pointer to the reference Y plane; points to the reference 
+ *            macroblock that corresponds to the location of the current 
+ *            macroblock in the current plane. 
+ *   refWidth - width of the reference plane 
+ *   pRefRect - reference plane valid region rectangle 
+ *   pSrcCurrBuf - pointer to the current block in the current macroblock 
+ *            buffer extracted from the original plane (linear array, 256 
+ *            entries); must be aligned on a 16-byte boundary.  The number of 
+ *            bytes between lines (step) is 16. 
+ *   pSearchPointRefPos - position of the starting point for half pixel 
+ *            search (specified in terms of integer pixel units) in the 
+ *            reference plane, i.e., the reference position pointed to by the 
+ *            predicted motion vector. 
+ *   rndVal - rounding control parameter: 0 - disabled; 1 - enabled. 
+ *   pSrcDstMV - pointer to the initial MV estimate; typically generated 
+ *            during a prior 16X16 integer search; specified in terms of 
+ *            half-pixel units. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDstMV - pointer to estimated MV 
+ *   pDstSAD - pointer to minimum SAD 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments.  Returned if one of the following 
+ *              conditions is true: 
+ *    -    at least one of the following pointers is NULL: pSrcRefBuf, 
+ *         pRefRect, pSrcCurrBuff, pSearchPointRefPos, pSrcDstMV.
+ *    -    pSrcCurrBuf is not 16-byte aligned, or 
+ *
+ */
+OMXResult omxVCM4P2_BlockMatch_Half_16x16 (
+    const OMX_U8 *pSrcRefBuf,
+    OMX_INT refWidth,
+    const OMXRect *pRefRect,
+    const OMX_U8 *pSrcCurrBuf,
+    const OMXVCM4P2Coordinate *pSearchPointRefPos,
+    OMX_INT rndVal,
+    OMXVCMotionVector *pSrcDstMV,
+    OMX_INT *pDstSAD
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_BlockMatch_Half_8x8   (6.2.4.2.4)
+ *
+ * Description:
+ * Performs an 8x8 block match with half-pixel resolution. Returns the 
+ * estimated motion vector and associated minimum SAD.  This function 
+ * estimates the half-pixel motion vector by interpolating the integer 
+ * resolution motion vector referenced by the input parameter pSrcDstMV, i.e., 
+ * the initial integer MV is generated externally.  The input parameters 
+ * pSrcRefBuf and pSearchPointRefPos should be shifted by the winning MV of 
+ * 8x8 integer search prior to calling BlockMatch_Half_8x8. The function 
+ * BlockMatch_Integer_8x8 may be used for integer motion estimation. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcRefBuf - pointer to the reference Y plane; points to the reference 
+ *            block that corresponds to the location of the current 8x8 block 
+ *            in the current plane. 
+ *   refWidth - width of the reference plane 
+ *   pRefRect - reference plane valid region rectangle 
+ *   pSrcCurrBuf - pointer to the current block in the current macroblock 
+ *            buffer extracted from the original plane (linear array, 128 
+ *            entries); must be aligned on a 8-byte boundary.  The number of 
+ *            bytes between lines (step) is 16. 
+ *   pSearchPointRefPos - position of the starting point for half pixel 
+ *            search (specified in terms of integer pixel units) in the 
+ *            reference plane. 
+ *   rndVal - rounding control parameter: 0 - disabled; 1 - enabled. 
+ *   pSrcDstMV - pointer to the initial MV estimate; typically generated 
+ *            during a prior 8x8 integer search, specified in terms of 
+ *            half-pixel units. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDstMV - pointer to estimated MV 
+ *   pDstSAD - pointer to minimum SAD 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments.  Returned if one of the following 
+ *              conditions is true: 
+ *    -    at least one of the following pointers is NULL: 
+ *         pSrcRefBuf, pRefRect, pSrcCurrBuff, pSearchPointRefPos, pSrcDstMV
+ *    -    pSrcCurrBuf is not 8-byte aligned 
+ *
+ */
+OMXResult omxVCM4P2_BlockMatch_Half_8x8 (
+    const OMX_U8 *pSrcRefBuf,
+    OMX_INT refWidth,
+    const OMXRect *pRefRect,
+    const OMX_U8 *pSrcCurrBuf,
+    const OMXVCM4P2Coordinate *pSearchPointRefPos,
+    OMX_INT rndVal,
+    OMXVCMotionVector *pSrcDstMV,
+    OMX_INT *pDstSAD
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_MotionEstimationMB   (6.2.4.3.1)
+ *
+ * Description:
+ * Performs motion search for a 16x16 macroblock.  Selects best motion search 
+ * strategy from among inter-1MV, inter-4MV, and intra modes.  Supports 
+ * integer and half pixel resolution. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcCurrBuf - pointer to the top-left corner of the current MB in the 
+ *            original picture plane; must be aligned on a 16-byte boundary.  
+ *            The function does not expect source data outside the region 
+ *            bounded by the MB to be available; for example it is not 
+ *            necessary for the caller to guarantee the availability of 
+ *            pSrcCurrBuf[-SrcCurrStep], i.e., the row of pixels above the MB 
+ *            to be processed. 
+ *   srcCurrStep - width of the original picture plane, in terms of full 
+ *            pixels; must be a multiple of 16. 
+ *   pSrcRefBuf - pointer to the reference Y plane; points to the reference 
+ *            plane location corresponding to the location of the current 
+ *            macroblock in the current plane; must be aligned on a 16-byte 
+ *            boundary. 
+ *   srcRefStep - width of the reference picture plane, in terms of full 
+ *            pixels; must be a multiple of 16. 
+ *   pRefRect - reference plane valid region rectangle, specified relative to 
+ *            the image origin 
+ *   pCurrPointPos - position of the current macroblock in the current plane 
+ *   pMESpec - pointer to the vendor-specific motion estimation specification 
+ *            structure; must be allocated and then initialized using 
+ *            omxVCM4P2_MEInit prior to calling this function. 
+ *   pMBInfo - array, of dimension four, containing pointers to information 
+ *            associated with four nearby MBs: 
+ *            -   pMBInfo[0] - pointer to left MB information 
+ *            -   pMBInfo[1] - pointer to top MB information 
+ *            -   pMBInfo[2] - pointer to top-left MB information 
+ *            -   pMBInfo[3] - pointer to top-right MB information 
+ *            Any pointer in the array may be set equal to NULL if the 
+ *            corresponding MB doesn't exist.  For each MB, the following structure 
+ *            members are used:    
+ *            -   mbType - macroblock type, either OMX_VC_INTRA, OMX_VC_INTER, or 
+ *                OMX_VC_INTER4V 
+ *            -   pMV0[2][2] - estimated motion vectors; represented 
+ *                in 1/2 pixel units 
+ *            -   sliceID - number of the slice to which the MB belongs 
+ *   pSrcDstMBCurr - pointer to information structure for the current MB.  
+ *            The following entries should be set prior to calling the 
+ *            function: sliceID - the number of the slice the to which the 
+ *            current MB belongs.  The structure elements cbpy and cbpc are 
+ *            ignored. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDstMBCurr - pointer to updated information structure for the current 
+ *            MB after MB-level motion estimation has been completed.  The 
+ *            following structure members are updated by the ME function:   
+ *              -  mbType - macroblock type: OMX_VC_INTRA, OMX_VC_INTER, or 
+ *                 OMX_VC_INTER4V. 
+ *              -  pMV0[2][2] - estimated motion vectors; represented in 
+ *                 terms of 1/2 pel units. 
+ *              -  pMVPred[2][2] - predicted motion vectors; represented 
+ *                 in terms of 1/2 pel units. 
+ *            The structure members cbpy and cbpc are not updated by the function. 
+ *   pDstSAD - pointer to the minimum SAD for INTER1V, or sum of minimum SADs 
+ *            for INTER4V 
+ *   pDstBlockSAD - pointer to an array of SAD values for each of the four 
+ *            8x8 luma blocks in the MB.  The block SADs are in scan order for 
+ *            each MB. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments.  Returned if one or more of the 
+ *              following conditions is true: 
+ *    -    at least one of the following pointers is NULL: pSrcCurrBuf, 
+ *              pSrcRefBuf, pRefRect, pCurrPointPos, pMBInter, pMBIntra, 
+ *              pSrcDstMBCurr, or pDstSAD. 
+ *
+ */
+OMXResult omxVCM4P2_MotionEstimationMB (
+    const OMX_U8 *pSrcCurrBuf,
+    OMX_S32 srcCurrStep,
+    const OMX_U8 *pSrcRefBuf,
+    OMX_S32 srcRefStep,
+    const OMXRect*pRefRect,
+    const OMXVCM4P2Coordinate *pCurrPointPos,
+    void *pMESpec,
+    const OMXVCM4P2MBInfoPtr *pMBInfo,
+    OMXVCM4P2MBInfo *pSrcDstMBCurr,
+    OMX_U16 *pDstSAD,
+    OMX_U16 *pDstBlockSAD
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_DCT8x8blk   (6.2.4.4.1)
+ *
+ * Description:
+ * Computes a 2D forward DCT for a single 8x8 block, as defined in 
+ * [ISO14496-2]. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - pointer to the start of the linearly arranged input buffer; must 
+ *            be aligned on a 16-byte boundary.  Input values (pixel 
+ *            intensities) are valid in the range [-255,255]. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - pointer to the start of the linearly arranged output buffer; must 
+ *            be aligned on a 16-byte boundary. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments, returned if:
+ *    -    pSrc or pDst is NULL. 
+ *    -    pSrc or pDst is not 16-byte aligned. 
+ *
+ */
+OMXResult omxVCM4P2_DCT8x8blk (
+    const OMX_S16 *pSrc,
+    OMX_S16 *pDst
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_QuantIntra_I   (6.2.4.4.2)
+ *
+ * Description:
+ * Performs quantization on intra block coefficients. This function supports 
+ * bits_per_pixel == 8. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - pointer to the input intra block coefficients; must be aligned 
+ *            on a 16-byte boundary. 
+ *   QP - quantization parameter (quantizer_scale). 
+ *   blockIndex - block index indicating the component type and position, 
+ *            valid in the range 0 to 5, as defined in [ISO14496-2], subclause 
+ *            6.1.3.8. 
+ *   shortVideoHeader - binary flag indicating presence of 
+ *            short_video_header; shortVideoHeader==1 selects linear intra DC 
+ *            mode, and shortVideoHeader==0 selects non linear intra DC mode. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst - pointer to the output (quantized) interblock coefficients.  
+ *            When shortVideoHeader==1, AC coefficients are saturated on the 
+ *            interval [-127, 127], and DC coefficients are saturated on the 
+ *            interval [1, 254].  When shortVideoHeader==0, AC coefficients 
+ *            are saturated on the interval [-2047, 2047]. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments:
+ *    -    pSrcDst is NULL. 
+ *    -    blockIndex < 0 or blockIndex >= 10 
+ *    -    QP <= 0 or QP >= 32. 
+ *
+ */
+OMXResult omxVCM4P2_QuantIntra_I (
+    OMX_S16 *pSrcDst,
+    OMX_U8 QP,
+    OMX_INT blockIndex,
+    OMX_INT shortVideoHeader
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_QuantInter_I   (6.2.4.4.3)
+ *
+ * Description:
+ * Performs quantization on an inter coefficient block; supports 
+ * bits_per_pixel == 8. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - pointer to the input inter block coefficients; must be aligned 
+ *            on a 16-byte boundary. 
+ *   QP - quantization parameter (quantizer_scale) 
+ *   shortVideoHeader - binary flag indicating presence of short_video_header; 
+ *            shortVideoHeader==1 selects linear intra DC mode, and 
+ *            shortVideoHeader==0 selects non linear intra DC mode. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst - pointer to the output (quantized) interblock coefficients.  
+ *            When shortVideoHeader==1, AC coefficients are saturated on the 
+ *            interval [-127, 127], and DC coefficients are saturated on the 
+ *            interval [1, 254].  When shortVideoHeader==0, AC coefficients 
+ *            are saturated on the interval [-2047, 2047]. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments:
+ *    -    pSrcDst is NULL. 
+ *    -    QP <= 0 or QP >= 32. 
+ *
+ */
+OMXResult omxVCM4P2_QuantInter_I (
+    OMX_S16 *pSrcDst,
+    OMX_U8 QP,
+    OMX_INT shortVideoHeader
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_TransRecBlockCoef_intra   (6.2.4.4.4)
+ *
+ * Description:
+ * Quantizes the DCT coefficients, implements intra block AC/DC coefficient 
+ * prediction, and reconstructs the current intra block texture for prediction 
+ * on the next frame.  Quantized row and column coefficients are returned in 
+ * the updated coefficient buffers. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - pointer to the pixels of current intra block; must be aligned on 
+ *            an 8-byte boundary. 
+ *   pPredBufRow - pointer to the coefficient row buffer containing 
+ *            ((num_mb_per_row * 2 + 1) * 8) elements of type OMX_S16. 
+ *            Coefficients are organized into blocks of eight as described 
+ *            below (Internal Prediction Coefficient Update Procedures).  The 
+ *            DC coefficient is first, and the remaining buffer locations 
+ *            contain the quantized AC coefficients. Each group of eight row 
+ *            buffer elements combined with one element eight elements ahead 
+ *            contains the coefficient predictors of the neighboring block 
+ *            that is spatially above or to the left of the block currently to 
+ *            be decoded. A negative-valued DC coefficient indicates that this 
+ *            neighboring block is not INTRA-coded or out of bounds, and 
+ *            therefore the AC and DC coefficients are invalid.  Pointer must 
+ *            be aligned on an 8-byte boundary. 
+ *   pPredBufCol - pointer to the prediction coefficient column buffer 
+ *            containing 16 elements of type OMX_S16. Coefficients are 
+ *            organized as described in section 6.2.2.5.  Pointer must be 
+ *            aligned on an 8-byte boundary. 
+ *   pSumErr - pointer to a flag indicating whether or not AC prediction is 
+ *            required; AC prediction is enabled if *pSumErr >=0, but the 
+ *            value is not used for coefficient prediction, i.e., the sum of 
+ *            absolute differences starts from 0 for each call to this 
+ *            function.  Otherwise AC prediction is disabled if *pSumErr < 0 . 
+ *   blockIndex - block index indicating the component type and position, as 
+ *            defined in [ISO14496-2], subclause 6.1.3.8. 
+ *   curQp - quantization parameter of the macroblock to which the current 
+ *            block belongs 
+ *   pQpBuf - pointer to a 2-element quantization parameter buffer; pQpBuf[0] 
+ *            contains the quantization parameter associated with the 8x8 
+ *            block left of the current block (QPa), and pQpBuf[1] contains 
+ *            the quantization parameter associated with the 8x8 block above 
+ *            the current block (QPc).  In the event that the corresponding 
+ *            block is outside of the VOP bound, the Qp value will not affect 
+ *            the intra prediction process, as described in [ISO14496-2], 
+ *            sub-clause 7.4.3.3,  Adaptive AC Coefficient Prediction.  
+ *   srcStep - width of the source buffer; must be a multiple of 8. 
+ *   dstStep - width of the reconstructed destination buffer; must be a 
+ *            multiple of 16. 
+ *   shortVideoHeader - binary flag indicating presence of 
+ *            short_video_header; shortVideoHeader==1 selects linear intra DC 
+ *            mode, and shortVideoHeader==0 selects non linear intra DC mode. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - pointer to the quantized DCT coefficient buffer; pDst[0] contains 
+ *            the predicted DC coefficient; the remaining entries contain the 
+ *            quantized AC coefficients (without prediction).  The pointer 
+ *            pDstmust be aligned on a 16-byte boundary. 
+ *   pRec - pointer to the reconstructed texture; must be aligned on an 
+ *            8-byte boundary. 
+ *   pPredBufRow - pointer to the updated coefficient row buffer 
+ *   pPredBufCol - pointer to the updated coefficient column buffer 
+ *   pPreACPredict - if prediction is enabled, the parameter points to the 
+ *            start of the buffer containing the coefficient differences for 
+ *            VLC encoding. The entry pPreACPredict[0]indicates prediction 
+ *            direction for the current block and takes one of the following 
+ *            values: OMX_VC_NONE (prediction disabled), OMX_VC_HORIZONTAL, or 
+ *            OMX_VC_VERTICAL.  The entries 
+ *            pPreACPredict[1]-pPreACPredict[7]contain predicted AC 
+ *            coefficients.  If prediction is disabled (*pSumErr<0) then the 
+ *            contents of this buffer are undefined upon return from the 
+ *            function 
+ *   pSumErr - pointer to the value of the accumulated AC coefficient errors, 
+ *            i.e., sum of the absolute differences between predicted and 
+ *            unpredicted AC coefficients 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - Bad arguments:
+ *    -    At least one of the following pointers is NULL: pSrc, pDst, pRec, 
+ *         pCoefBufRow, pCoefBufCol, pQpBuf, pPreACPredict, pSumErr. 
+ *    -    blockIndex < 0 or blockIndex >= 10; 
+ *    -    curQP <= 0 or curQP >= 32. 
+ *    -    srcStep, or dstStep <= 0 or not a multiple of 8. 
+ *    -    pDst is not 16-byte aligned: . 
+ *    -    At least one of the following pointers is not 8-byte aligned: 
+ *         pSrc, pRec.  
+ *
+ *  Note: The coefficient buffers must be updated in accordance with the 
+ *        update procedures defined in section in 6.2.2. 
+ *
+ */
+OMXResult omxVCM4P2_TransRecBlockCoef_intra (
+    const OMX_U8 *pSrc,
+    OMX_S16 *pDst,
+    OMX_U8 *pRec,
+    OMX_S16 *pPredBufRow,
+    OMX_S16 *pPredBufCol,
+    OMX_S16 *pPreACPredict,
+    OMX_INT *pSumErr,
+    OMX_INT blockIndex,
+    OMX_U8 curQp,
+    const OMX_U8 *pQpBuf,
+    OMX_INT srcStep,
+    OMX_INT dstStep,
+    OMX_INT shortVideoHeader
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_TransRecBlockCoef_inter   (6.2.4.4.5)
+ *
+ * Description:
+ * Implements DCT, and quantizes the DCT coefficients of the inter block 
+ * while reconstructing the texture residual. There is no boundary check for 
+ * the bit stream buffer. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc -pointer to the residuals to be encoded; must be aligned on an 
+ *            16-byte boundary. 
+ *   QP - quantization parameter. 
+ *   shortVideoHeader - binary flag indicating presence of short_video_header; 
+ *                      shortVideoHeader==1 selects linear intra DC mode, and 
+ *                      shortVideoHeader==0 selects non linear intra DC mode. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - pointer to the quantized DCT coefficients buffer; must be aligned 
+ *            on a 16-byte boundary. 
+ *   pRec - pointer to the reconstructed texture residuals; must be aligned 
+ *            on a 16-byte boundary. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments:
+ *    -    At least one of the following pointers is either NULL or 
+ *         not 16-byte aligned: 
+ *            - pSrc 
+ *            - pDst
+ *            - pRec
+ *    -    QP <= 0 or QP >= 32. 
+ *
+ */
+OMXResult omxVCM4P2_TransRecBlockCoef_inter (
+    const OMX_S16 *pSrc,
+    OMX_S16 *pDst,
+    OMX_S16 *pRec,
+    OMX_U8 QP,
+    OMX_INT shortVideoHeader
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_EncodeVLCZigzag_IntraDCVLC   (6.2.4.5.2)
+ *
+ * Description:
+ * Performs zigzag scan and VLC encoding of AC and DC coefficients for one 
+ * intra block.  Two versions of the function (DCVLC and ACVLC) are provided 
+ * in order to support the two different methods of processing DC 
+ * coefficients, as described in [ISO14496-2], subclause 7.4.1.4, "Intra DC 
+ * Coefficient Decoding for the Case of Switched VLC Encoding".  
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - double pointer to the current byte in the bitstream 
+ *   pBitOffset - pointer to the bit position in the byte pointed by 
+ *            *ppBitStream. Valid within 0 to 7. 
+ *   pQDctBlkCoef - pointer to the quantized DCT coefficient 
+ *   predDir - AC prediction direction, which is used to decide the zigzag 
+ *            scan pattern; takes one of the following values: 
+ *            -  OMX_VC_NONE - AC prediction not used.  
+ *                             Performs classical zigzag scan. 
+ *            -  OMX_VC_HORIZONTAL - Horizontal prediction.  
+ *                             Performs alternate-vertical zigzag scan. 
+ *            -  OMX_VC_VERTICAL - Vertical prediction.  
+ *                             Performs alternate-horizontal zigzag scan. 
+ *   pattern - block pattern which is used to decide whether this block is 
+ *            encoded 
+ *   shortVideoHeader - binary flag indicating presence of 
+ *            short_video_header; escape modes 0-3 are used if 
+ *            shortVideoHeader==0, and escape mode 4 is used when 
+ *            shortVideoHeader==1. 
+ *   videoComp - video component type (luminance, chrominance) of the current 
+ *            block 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after the block is encoded, so 
+ *            that it points to the current byte in the bit stream buffer. 
+ *   pBitOffset - *pBitOffset is updated so that it points to the current bit 
+ *            position in the byte pointed by *ppBitStream. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - Bad arguments:
+ *    -    At least one of the following pointers is NULL: ppBitStream, 
+ *              *ppBitStream, pBitOffset, pQDctBlkCoef. 
+ *    -   *pBitOffset < 0, or *pBitOffset >7. 
+ *    -    PredDir is not one of: OMX_VC_NONE, OMX_VC_HORIZONTAL, or 
+ *         OMX_VC_VERTICAL. 
+ *    -    VideoComp is not one component of enum OMXVCM4P2VideoComponent. 
+ *
+ */
+OMXResult omxVCM4P2_EncodeVLCZigzag_IntraDCVLC (
+    OMX_U8 **ppBitStream,
+    OMX_INT *pBitOffset,
+    const OMX_S16 *pQDctBlkCoef,
+    OMX_U8 predDir,
+    OMX_U8 pattern,
+    OMX_INT shortVideoHeader,
+    OMXVCM4P2VideoComponent videoComp
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_EncodeVLCZigzag_IntraACVLC   (6.2.4.5.2)
+ *
+ * Description:
+ * Performs zigzag scan and VLC encoding of AC and DC coefficients for one 
+ * intra block.  Two versions of the function (DCVLC and ACVLC) are provided 
+ * in order to support the two different methods of processing DC 
+ * coefficients, as described in [ISO14496-2], subclause 7.4.1.4,  Intra DC 
+ * Coefficient Decoding for the Case of Switched VLC Encoding.  
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - double pointer to the current byte in the bitstream 
+ *   pBitOffset - pointer to the bit position in the byte pointed by 
+ *            *ppBitStream. Valid within 0 to 7. 
+ *   pQDctBlkCoef - pointer to the quantized DCT coefficient 
+ *   predDir - AC prediction direction, which is used to decide the zigzag 
+ *            scan pattern; takes one of the following values: 
+ *            -  OMX_VC_NONE - AC prediction not used.  
+ *                             Performs classical zigzag scan. 
+ *            -  OMX_VC_HORIZONTAL - Horizontal prediction.  
+ *                             Performs alternate-vertical zigzag scan. 
+ *            -  OMX_VC_VERTICAL - Vertical prediction.  
+ *                             Performs alternate-horizontal zigzag scan. 
+ *   pattern - block pattern which is used to decide whether this block is 
+ *            encoded 
+ *   shortVideoHeader - binary flag indicating presence of 
+ *            short_video_header; escape modes 0-3 are used if 
+ *            shortVideoHeader==0, and escape mode 4 is used when 
+ *            shortVideoHeader==1. 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after the block is encoded, so 
+ *            that it points to the current byte in the bit stream buffer. 
+ *   pBitOffset - *pBitOffset is updated so that it points to the current bit 
+ *            position in the byte pointed by *ppBitStream. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - Bad arguments:
+ *    -    At least one of the following pointers is NULL: ppBitStream, 
+ *              *ppBitStream, pBitOffset, pQDctBlkCoef. 
+ *    -   *pBitOffset < 0, or *pBitOffset >7. 
+ *    -    PredDir is not one of: OMX_VC_NONE, OMX_VC_HORIZONTAL, or 
+ *         OMX_VC_VERTICAL. 
+ *    -    VideoComp is not one component of enum OMXVCM4P2VideoComponent. 
+ *
+ */
+OMXResult omxVCM4P2_EncodeVLCZigzag_IntraACVLC (
+    OMX_U8 **ppBitStream,
+    OMX_INT *pBitOffset,
+    const OMX_S16 *pQDctBlkCoef,
+    OMX_U8 predDir,
+    OMX_U8 pattern,
+    OMX_INT shortVideoHeader
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_EncodeVLCZigzag_Inter   (6.2.4.5.3)
+ *
+ * Description:
+ * Performs classical zigzag scanning and VLC encoding for one inter block. 
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - pointer to the pointer to the current byte in the bit 
+ *            stream 
+ *   pBitOffset - pointer to the bit position in the byte pointed by 
+ *            *ppBitStream. Valid within 0 to 7 
+ *   pQDctBlkCoef - pointer to the quantized DCT coefficient 
+ *   pattern - block pattern which is used to decide whether this block is 
+ *            encoded 
+ *   shortVideoHeader - binary flag indicating presence of 
+ *            short_video_header; escape modes 0-3 are used if 
+ *            shortVideoHeader==0, and escape mode 4 is used when 
+ *            shortVideoHeader==1. 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after the block is encoded so that 
+ *            it points to the current byte in the bit stream buffer. 
+ *   pBitOffset - *pBitOffset is updated so that it points to the current bit 
+ *            position in the byte pointed by *ppBitStream. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - Bad arguments 
+ *    -    At least one of the pointers: is NULL: ppBitStream, *ppBitStream, 
+ *              pBitOffset, pQDctBlkCoef 
+ *    -   *pBitOffset < 0, or *pBitOffset >7. 
+ *
+ */
+OMXResult omxVCM4P2_EncodeVLCZigzag_Inter (
+    OMX_U8 **ppBitStream,
+    OMX_INT *pBitOffset,
+    const OMX_S16 *pQDctBlkCoef,
+    OMX_U8 pattern,
+    OMX_INT shortVideoHeader
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_EncodeMV   (6.2.4.5.4)
+ *
+ * Description:
+ * Predicts a motion vector for the current macroblock, encodes the 
+ * difference, and writes the output to the stream buffer. The input MVs 
+ * pMVCurMB, pSrcMVLeftMB, pSrcMVUpperMB, and pSrcMVUpperRightMB should lie 
+ * within the ranges associated with the input parameter fcodeForward, as 
+ * described in [ISO14496-2], subclause 7.6.3.  This function provides a 
+ * superset of the functionality associated with the function 
+ * omxVCM4P2_FindMVpred. 
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - double pointer to the current byte in the bitstream buffer 
+ *   pBitOffset - index of the first free (next available) bit in the stream 
+ *            buffer referenced by *ppBitStream, valid in the range 0 to 7. 
+ *   pMVCurMB - pointer to the current macroblock motion vector; a value of 
+ *            NULL indicates unavailability. 
+ *   pSrcMVLeftMB - pointer to the source left macroblock motion vector; a 
+ *            value of  NULLindicates unavailability. 
+ *   pSrcMVUpperMB - pointer to source upper macroblock motion vector; a 
+ *            value of NULL indicates unavailability. 
+ *   pSrcMVUpperRightMB - pointer to source upper right MB motion vector; a 
+ *            value of NULL indicates unavailability. 
+ *   fcodeForward - an integer with values from 1 to 7; used in encoding 
+ *            motion vectors related to search range, as described in 
+ *            [ISO14496-2], subclause 7.6.3. 
+ *   MBType - macro block type, valid in the range 0 to 5 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - updated pointer to the current byte in the bit stream 
+ *            buffer 
+ *   pBitOffset - updated index of the next available bit position in stream 
+ *            buffer referenced by *ppBitStream 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments 
+ *    -    At least one of the following pointers is NULL: ppBitStream, 
+ *              *ppBitStream, pBitOffset, pMVCurMB 
+ *    -    *pBitOffset < 0, or *pBitOffset >7. 
+ *    -    fcodeForward <= 0, or fcodeForward > 7, or MBType < 0. 
+ *
+ */
+OMXResult omxVCM4P2_EncodeMV (
+    OMX_U8 **ppBitStream,
+    OMX_INT *pBitOffset,
+    const OMXVCMotionVector *pMVCurMB,
+    const OMXVCMotionVector*pSrcMVLeftMB,
+    const OMXVCMotionVector *pSrcMVUpperMB,
+    const OMXVCMotionVector *pSrcMVUpperRightMB,
+    OMX_INT fcodeForward,
+    OMXVCM4P2MacroblockType MBType
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_DecodePadMV_PVOP   (6.2.5.1.1)
+ *
+ * Description:
+ * Decodes and pads the four motion vectors associated with a non-intra P-VOP 
+ * macroblock.  For macroblocks of type OMX_VC_INTER4V, the output MV is 
+ * padded as specified in [ISO14496-2], subclause 7.6.1.6. Otherwise, for 
+ * macroblocks of types other than OMX_VC_INTER4V, the decoded MV is copied to 
+ * all four output MV buffer entries. 
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - pointer to the pointer to the current byte in the bit 
+ *            stream buffer 
+ *   pBitOffset - pointer to the bit position in the byte pointed to by 
+ *            *ppBitStream. *pBitOffset is valid within [0-7]. 
+ *   pSrcMVLeftMB, pSrcMVUpperMB, and pSrcMVUpperRightMB - pointers to the 
+ *            motion vector buffers of the macroblocks specially at the left, 
+ *            upper, and upper-right side of the current macroblock, 
+ *            respectively; a value of NULL indicates unavailability.  Note: 
+ *            Any neighborhood macroblock outside the current VOP or video 
+ *            packet or outside the current GOB (when short_video_header is 
+ *             1 ) for which gob_header_empty is  0  is treated as 
+ *            transparent, according to [ISO14496-2], subclause 7.6.5. 
+ *   fcodeForward - a code equal to vop_fcode_forward in MPEG-4 bit stream 
+ *            syntax 
+ *   MBType - the type of the current macroblock. If MBType is not equal to 
+ *            OMX_VC_INTER4V, the destination motion vector buffer is still 
+ *            filled with the same decoded vector. 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after the block is decoded, so 
+ *            that it points to the current byte in the bit stream buffer 
+ *   pBitOffset - *pBitOffset is updated so that it points to the current bit 
+ *            position in the byte pointed by *ppBitStream 
+ *   pDstMVCurMB - pointer to the motion vector buffer for the current 
+ *            macroblock; contains four decoded motion vectors 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments:
+ *    -    At least one of the following pointers is NULL: 
+ *         ppBitStream, *ppBitStream, pBitOffset, pDstMVCurMB 
+ *    -    *pBitOffset exceeds [0,7]
+ *    -    fcodeForward exceeds (0,7]
+ *    -    MBType less than zero
+ *    -    motion vector buffer is not 4-byte aligned. 
+ *    OMX_Sts_Err - status error 
+ *
+ */
+OMXResult omxVCM4P2_DecodePadMV_PVOP (
+    const OMX_U8 **ppBitStream,
+    OMX_INT *pBitOffset,
+    OMXVCMotionVector *pSrcMVLeftMB,
+    OMXVCMotionVector*pSrcMVUpperMB,
+    OMXVCMotionVector *pSrcMVUpperRightMB,
+    OMXVCMotionVector*pDstMVCurMB,
+    OMX_INT fcodeForward,
+    OMXVCM4P2MacroblockType MBType
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_DecodeVLCZigzag_IntraDCVLC   (6.2.5.2.2)
+ *
+ * Description:
+ * Performs VLC decoding and inverse zigzag scan of AC and DC coefficients 
+ * for one intra block.  Two versions of the function (DCVLC and ACVLC) are 
+ * provided in order to support the two different methods of processing DC 
+ * coefficients, as described in [ISO14496-2], subclause 7.4.1.4,  Intra DC 
+ * Coefficient Decoding for the Case of Switched VLC Encoding.  
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - pointer to the pointer to the current byte in the 
+ *            bitstream buffer 
+ *   pBitOffset - pointer to the bit position in the current byte referenced 
+ *            by *ppBitStream.  The parameter *pBitOffset is valid in the 
+ *            range [0-7]. 
+ *            Bit Position in one byte:  |Most      Least| 
+ *                    *pBitOffset        |0 1 2 3 4 5 6 7| 
+ *   predDir - AC prediction direction; used to select the zigzag scan 
+ *            pattern; takes one of the following values: 
+ *            -  OMX_VC_NONE - AC prediction not used; 
+ *                             performs classical zigzag scan. 
+ *            -  OMX_VC_HORIZONTAL - Horizontal prediction; 
+ *                             performs alternate-vertical zigzag scan; 
+ *            -  OMX_VC_VERTICAL - Vertical prediction; 
+ *                             performs alternate-horizontal zigzag scan. 
+ *   shortVideoHeader - binary flag indicating presence of 
+ *            short_video_header; escape modes 0-3 are used if 
+ *            shortVideoHeader==0, and escape mode 4 is used when 
+ *            shortVideoHeader==1. 
+ *   videoComp - video component type (luminance or chrominance) of the 
+ *            current block 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after the block is decoded such 
+ *            that it points to the current byte in the bit stream buffer 
+ *   pBitOffset - *pBitOffset is updated such that it points to the current 
+ *            bit position in the byte pointed by *ppBitStream 
+ *   pDst - pointer to the coefficient buffer of current block; must be 
+ *            4-byte aligned. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments, if:
+ *    -    At least one of the following pointers is NULL: 
+ *         ppBitStream, *ppBitStream, pBitOffset, pDst
+ *    -    *pBitOffset exceeds [0,7]
+ *    -    preDir exceeds [0,2]
+ *    -    pDst is not 4-byte aligned 
+ *    OMX_Sts_Err - if:
+ *    -    In DecodeVLCZigzag_IntraDCVLC, dc_size > 12 
+ *    -    At least one of mark bits equals zero 
+ *    -    Illegal stream encountered; code cannot be located in VLC table 
+ *    -    Forbidden code encountered in the VLC FLC table. 
+ *    -    The number of coefficients is greater than 64 
+ *
+ */
+OMXResult omxVCM4P2_DecodeVLCZigzag_IntraDCVLC (
+    const OMX_U8 **ppBitStream,
+    OMX_INT *pBitOffset,
+    OMX_S16 *pDst,
+    OMX_U8 predDir,
+    OMX_INT shortVideoHeader,
+    OMXVCM4P2VideoComponent videoComp
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_DecodeVLCZigzag_IntraACVLC   (6.2.5.2.2)
+ *
+ * Description:
+ * Performs VLC decoding and inverse zigzag scan of AC and DC coefficients 
+ * for one intra block.  Two versions of the function (DCVLC and ACVLC) are 
+ * provided in order to support the two different methods of processing DC 
+ * coefficients, as described in [ISO14496-2], subclause 7.4.1.4,  Intra DC 
+ * Coefficient Decoding for the Case of Switched VLC Encoding.  
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - pointer to the pointer to the current byte in the 
+ *            bitstream buffer 
+ *   pBitOffset - pointer to the bit position in the current byte referenced 
+ *            by *ppBitStream.  The parameter *pBitOffset is valid in the 
+ *            range [0-7]. Bit Position in one byte:  |Most Least| *pBitOffset 
+ *            |0 1 2 3 4 5 6 7| 
+ *   predDir - AC prediction direction; used to select the zigzag scan 
+ *            pattern; takes one of the following values: OMX_VC_NONE - AC 
+ *            prediction not used; performs classical zigzag scan. 
+ *            OMX_VC_HORIZONTAL - Horizontal prediction; performs 
+ *            alternate-vertical zigzag scan; OMX_VC_VERTICAL - Vertical 
+ *            prediction; performs alternate-horizontal zigzag scan. 
+ *   shortVideoHeader - binary flag indicating presence of 
+ *            short_video_header; escape modes 0-3 are used if 
+ *            shortVideoHeader==0, and escape mode 4 is used when 
+ *            shortVideoHeader==1. 
+ *   videoComp - video component type (luminance or chrominance) of the 
+ *            current block 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after the block is decoded such 
+ *            that it points to the current byte in the bit stream buffer 
+ *   pBitOffset - *pBitOffset is updated such that it points to the current 
+ *            bit position in the byte pointed by *ppBitStream 
+ *   pDst - pointer to the coefficient buffer of current block; must be 
+ *            4-byte aligned. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments At least one of the following 
+ *              pointers is NULL: ppBitStream, *ppBitStream, pBitOffset, pDst, 
+ *              or At least one of the following conditions is true: 
+ *              *pBitOffset exceeds [0,7], preDir exceeds [0,2], or pDst is 
+ *              not 4-byte aligned 
+ *    OMX_Sts_Err In DecodeVLCZigzag_IntraDCVLC, dc_size > 12 At least one of 
+ *              mark bits equals zero Illegal stream encountered; code cannot 
+ *              be located in VLC table Forbidden code encountered in the VLC 
+ *              FLC table The number of coefficients is greater than 64 
+ *
+ */
+OMXResult omxVCM4P2_DecodeVLCZigzag_IntraACVLC (
+    const OMX_U8 **ppBitStream,
+    OMX_INT *pBitOffset,
+    OMX_S16 *pDst,
+    OMX_U8 predDir,
+    OMX_INT shortVideoHeader
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_DecodeVLCZigzag_Inter   (6.2.5.2.3)
+ *
+ * Description:
+ * Performs VLC decoding and inverse zigzag scan for one inter-coded block. 
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - double pointer to the current byte in the stream buffer 
+ *   pBitOffset - pointer to the next available bit in the current stream 
+ *            byte referenced by *ppBitStream. The parameter *pBitOffset is 
+ *            valid within the range [0-7]. 
+ *   shortVideoHeader - binary flag indicating presence of 
+ *            short_video_header; escape modes 0-3 are used if 
+ *            shortVideoHeader==0, and escape mode 4 is used when 
+ *            shortVideoHeader==1. 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after the block is decoded such 
+ *            that it points to the current byte in the stream buffer 
+ *   pBitOffset - *pBitOffset is updated after decoding such that it points 
+ *            to the next available bit in the stream byte referenced by 
+ *            *ppBitStream 
+ *   pDst - pointer to the coefficient buffer of current block; must be 
+ *            4-byte aligned. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_BadArgErr - bad arguments:
+ *    -    At least one of the following pointers is NULL: 
+ *         ppBitStream, *ppBitStream, pBitOffset, pDst
+ *    -    pDst is not 4-byte aligned
+ *    -   *pBitOffset exceeds [0,7]
+ *    OMX_Sts_Err - status error, if:
+ *    -    At least one mark bit is equal to zero 
+ *    -    Encountered an illegal stream code that cannot be found in the VLC table 
+ *    -    Encountered an illegal code in the VLC FLC table 
+ *    -    The number of coefficients is greater than 64 
+ *
+ */
+OMXResult omxVCM4P2_DecodeVLCZigzag_Inter (
+    const OMX_U8 **ppBitStream,
+    OMX_INT *pBitOffset,
+    OMX_S16 *pDst,
+    OMX_INT shortVideoHeader
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_QuantInvIntra_I   (6.2.5.3.2)
+ *
+ * Description:
+ * Performs the second inverse quantization mode on an intra/inter coded 
+ * block. Supports bits_per_pixel = 8. The output coefficients are clipped to 
+ * the range [-2048, 2047]. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - pointer to the input (quantized) intra/inter block; must be 
+ *            aligned on a 16-byte boundary. 
+ *   QP - quantization parameter (quantizer_scale) 
+ *   videoComp - video component type of the current block. Takes one of the 
+ *            following flags: OMX_VC_LUMINANCE, OMX_VC_CHROMINANCE (intra 
+ *            version only). 
+ *   shortVideoHeader - binary flag indicating presence of short_video_header 
+ *            (intra version only). 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst - pointer to the output (dequantized) intra/inter block 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; one or more of the following is 
+ *              true: 
+ *    -    pSrcDst is NULL 
+ *    -    QP <= 0 or QP >=31 
+ *    -    videoComp is neither OMX_VC_LUMINANCE nor OMX_VC_CHROMINANCE. 
+ *
+ */
+OMXResult omxVCM4P2_QuantInvIntra_I (
+    OMX_S16 *pSrcDst,
+    OMX_INT QP,
+    OMXVCM4P2VideoComponent videoComp,
+    OMX_INT shortVideoHeader
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_QuantInvInter_I   (6.2.5.3.2)
+ *
+ * Description:
+ * Performs the second inverse quantization mode on an intra/inter coded 
+ * block. Supports bits_per_pixel = 8. The output coefficients are clipped to 
+ * the range [-2048, 2047]. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - pointer to the input (quantized) intra/inter block; must be 
+ *            aligned on a 16-byte boundary. 
+ *   QP - quantization parameter (quantizer_scale) 
+ *   videoComp - video component type of the current block. Takes one of the 
+ *            following flags: OMX_VC_LUMINANCE, OMX_VC_CHROMINANCE (intra 
+ *            version only). 
+ *   shortVideoHeader - binary flag indicating presence of short_video_header 
+ *            (intra version only). 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst - pointer to the output (dequantized) intra/inter block 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; one or more of the following is 
+ *              true: 
+ *    -    pSrcDst is NULL 
+ *    -    QP <= 0 or QP >=31 
+ *    -    videoComp is neither OMX_VC_LUMINANCE nor OMX_VC_CHROMINANCE. 
+ *
+ */
+OMXResult omxVCM4P2_QuantInvInter_I (
+    OMX_S16 *pSrcDst,
+    OMX_INT QP
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_DecodeBlockCoef_Intra   (6.2.5.4.1)
+ *
+ * Description:
+ * Decodes the INTRA block coefficients. Inverse quantization, inversely 
+ * zigzag positioning, and IDCT, with appropriate clipping on each step, are 
+ * performed on the coefficients. The results are then placed in the output 
+ * frame/plane on a pixel basis.  Note: This function will be used only when 
+ * at least one non-zero AC coefficient of current block exists in the bit 
+ * stream. The DC only condition will be handled in another function. 
+ *
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - pointer to the pointer to the current byte in the bit 
+ *            stream buffer. There is no boundary check for the bit stream 
+ *            buffer. 
+ *   pBitOffset - pointer to the bit position in the byte pointed to by 
+ *            *ppBitStream. *pBitOffset is valid within [0-7]. 
+ *   step - width of the destination plane 
+ *   pCoefBufRow - pointer to the coefficient row buffer; must be aligned on 
+ *            an 8-byte boundary. 
+ *   pCoefBufCol - pointer to the coefficient column buffer; must be aligned 
+ *            on an 8-byte boundary. 
+ *   curQP - quantization parameter of the macroblock which the current block 
+ *            belongs to 
+ *   pQPBuf - pointer to the quantization parameter buffer 
+ *   blockIndex - block index indicating the component type and position as 
+ *            defined in [ISO14496-2], subclause 6.1.3.8, Figure 6-5. 
+ *   intraDCVLC - a code determined by intra_dc_vlc_thr and QP. This allows a 
+ *            mechanism to switch between two VLC for coding of Intra DC 
+ *            coefficients as per [ISO14496-2], Table 6-21. 
+ *   ACPredFlag - a flag equal to ac_pred_flag (of luminance) indicating if 
+ *            the ac coefficients of the first row or first column are 
+ *            differentially coded for intra coded macroblock. 
+ *   shortVideoHeader - binary flag indicating presence of 
+ *            short_video_header; shortVideoHeader==1 selects linear intra DC 
+ *            mode, and shortVideoHeader==0 selects non linear intra DC mode. 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after the block is decoded, so 
+ *            that it points to the current byte in the bit stream buffer 
+ *   pBitOffset - *pBitOffset is updated so that it points to the current bit 
+ *            position in the byte pointed by *ppBitStream 
+ *   pDst - pointer to the block in the destination plane; must be aligned on 
+ *            an 8-byte boundary. 
+ *   pCoefBufRow - pointer to the updated coefficient row buffer. 
+ *   pCoefBufCol - pointer to the updated coefficient column buffer  Note: 
+ *            The coefficient buffers must be updated in accordance with the 
+ *            update procedure defined in section 6.2.2. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments, if:
+ *    -    At least one of the following pointers is NULL: 
+ *         ppBitStream, *ppBitStream, pBitOffset, pCoefBufRow, pCoefBufCol, 
+ *         pQPBuf, pDst. 
+ *    -    *pBitOffset exceeds [0,7] 
+ *    -    curQP exceeds (1, 31)
+ *    -    blockIndex exceeds [0,5]
+ *    -    step is not the multiple of 8
+ *    -    a pointer alignment requirement was violated. 
+ *    OMX_Sts_Err - status error. Refer to OMX_Sts_Err of DecodeVLCZigzag_Intra.  
+ *
+ */
+OMXResult omxVCM4P2_DecodeBlockCoef_Intra (
+    const OMX_U8 **ppBitStream,
+    OMX_INT *pBitOffset,
+    OMX_U8 *pDst,
+    OMX_INT step,
+    OMX_S16 *pCoefBufRow,
+    OMX_S16 *pCoefBufCol,
+    OMX_U8 curQP,
+    const OMX_U8 *pQPBuf,
+    OMX_INT blockIndex,
+    OMX_INT intraDCVLC,
+    OMX_INT ACPredFlag,
+    OMX_INT shortVideoHeader
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_DecodeBlockCoef_Inter   (6.2.5.4.2)
+ *
+ * Description:
+ * Decodes the INTER block coefficients. This function performs inverse 
+ * quantization, inverse zigzag positioning, and IDCT (with appropriate 
+ * clipping on each step) on the coefficients. The results (residuals) are 
+ * placed in a contiguous array of 64 elements. For INTER block, the output 
+ * buffer holds the residuals for further reconstruction. 
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - pointer to the pointer to the current byte in the bit 
+ *            stream buffer. There is no boundary check for the bit stream 
+ *            buffer. 
+ *   pBitOffset - pointer to the bit position in the byte pointed to by 
+ *            *ppBitStream. *pBitOffset is valid within [0-7] 
+ *   QP - quantization parameter 
+ *   shortVideoHeader - binary flag indicating presence of 
+ *            short_video_header; shortVideoHeader==1 selects linear intra DC 
+ *            mode, and shortVideoHeader==0 selects non linear intra DC mode. 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after the block is decoded, so 
+ *            that it points to the current byte in the bit stream buffer 
+ *   pBitOffset - *pBitOffset is updated so that it points to the current bit 
+ *            position in the byte pointed by *ppBitStream 
+ *   pDst - pointer to the decoded residual buffer (a contiguous array of 64 
+ *            elements of OMX_S16 data type); must be aligned on a 16-byte 
+ *            boundary. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments, if:
+ *    -    At least one of the following pointers is Null: 
+ *         ppBitStream, *ppBitStream, pBitOffset , pDst 
+ *    -    *pBitOffset exceeds [0,7]
+ *    -    QP <= 0. 
+ *    -    pDst is not 16-byte aligned 
+ *    OMX_Sts_Err - status error. Refer to OMX_Sts_Err of DecodeVLCZigzag_Inter . 
+ *
+ */
+OMXResult omxVCM4P2_DecodeBlockCoef_Inter (
+    const OMX_U8 **ppBitStream,
+    OMX_INT *pBitOffset,
+    OMX_S16 *pDst,
+    OMX_INT QP,
+    OMX_INT shortVideoHeader
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_PredictReconCoefIntra   (6.2.5.4.3)
+ *
+ * Description:
+ * Performs adaptive DC/AC coefficient prediction for an intra block.  Prior 
+ * to the function call, prediction direction (predDir) should be selected as 
+ * specified in [ISO14496-2], subclause 7.4.3.1. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - pointer to the coefficient buffer which contains the quantized 
+ *            coefficient residuals (PQF) of the current block; must be 
+ *            aligned on a 4-byte boundary.  The output coefficients are 
+ *            saturated to the range [-2048, 2047]. 
+ *   pPredBufRow - pointer to the coefficient row buffer; must be aligned on 
+ *            a 4-byte boundary. 
+ *   pPredBufCol - pointer to the coefficient column buffer; must be aligned 
+ *            on a 4-byte boundary. 
+ *   curQP - quantization parameter of the current block. curQP may equal to 
+ *            predQP especially when the current block and the predictor block 
+ *            are in the same macroblock. 
+ *   predQP - quantization parameter of the predictor block 
+ *   predDir - indicates the prediction direction which takes one of the 
+ *            following values: OMX_VC_HORIZONTAL - predict horizontally 
+ *            OMX_VC_VERTICAL - predict vertically 
+ *   ACPredFlag - a flag indicating if AC prediction should be performed. It 
+ *            is equal to ac_pred_flag in the bit stream syntax of MPEG-4 
+ *   videoComp - video component type (luminance or chrominance) of the 
+ *            current block 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst - pointer to the coefficient buffer which contains the quantized 
+ *            coefficients (QF) of the current block 
+ *   pPredBufRow - pointer to the updated coefficient row buffer 
+ *   pPredBufCol - pointer to the updated coefficient column buffer  Note: 
+ *            Buffer update: Update the AC prediction buffer (both row and 
+ *            column buffer). 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments, if:
+ *        -    At least one of the pointers is NULL: 
+ *              pSrcDst, pPredBufRow, or pPredBufCol. 
+ *        -    curQP <= 0, 
+ *        -    predQP <= 0, 
+ *        -    curQP >31, 
+ *        -    predQP > 31, 
+ *        -    preDir exceeds [1,2]
+ *        -    pSrcDst, pPredBufRow, or pPredBufCol is not 4-byte aligned. 
+ *
+ */
+OMXResult omxVCM4P2_PredictReconCoefIntra (
+    OMX_S16 *pSrcDst,
+    OMX_S16 *pPredBufRow,
+    OMX_S16 *pPredBufCol,
+    OMX_INT curQP,
+    OMX_INT predQP,
+    OMX_INT predDir,
+    OMX_INT ACPredFlag,
+    OMXVCM4P2VideoComponent videoComp
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_MCReconBlock   (6.2.5.5.1)
+ *
+ * Description:
+ * Performs motion compensation prediction for an 8x8 block using 
+ * interpolation described in [ISO14496-2], subclause 7.6.2. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - pointer to the block in the reference plane. 
+ *   srcStep - distance between the start of consecutive lines in the 
+ *            reference plane, in bytes; must be a multiple of 8. 
+ *   dstStep - distance between the start of consecutive lines in the 
+ *            destination plane, in bytes; must be a multiple of 8. 
+ *   pSrcResidue - pointer to a buffer containing the 16-bit prediction 
+ *            residuals; must be 16-byte aligned. If the pointer is NULL, then 
+ *            no prediction is done, only motion compensation, i.e., the block 
+ *            is moved with interpolation. 
+ *   predictType - bilinear interpolation type, as defined in section 
+ *            6.2.1.2. 
+ *   rndVal - rounding control parameter: 0 - disabled; 1 - enabled. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - pointer to the destination buffer; must be 8-byte aligned.  If 
+ *            prediction residuals are added then output intensities are 
+ *            clipped to the range [0,255]. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned under any of the following 
+ *              conditions: 
+ *    -    pDst is not 8-byte aligned. 
+ *    -    pSrcResidue is not 16-byte aligned. 
+ *    -    one or more of the following pointers is NULL: pSrc or pDst. 
+ *    -    either srcStep or dstStep is not a multiple of 8. 
+ *    -    invalid type specified for the parameter predictType. 
+ *    -    the parameter rndVal is not equal either to 0 or 1. 
+ *
+ */
+OMXResult omxVCM4P2_MCReconBlock (
+    const OMX_U8 *pSrc,
+    OMX_INT srcStep,
+    const OMX_S16 *pSrcResidue,
+    OMX_U8 *pDst,
+    OMX_INT dstStep,
+    OMX_INT predictType,
+    OMX_INT rndVal
+);
+
+
+
+/* 6.3.1.1 Intra 16x16 Prediction Modes  */
+/* A data type that enumerates intra_16x16 macroblock prediction modes is defined as follows:  */
+
+typedef enum {
+    OMX_VC_16X16_VERT = 0,  /** Intra_16x16_Vertical */
+    OMX_VC_16X16_HOR = 1,   /** Intra_16x16_Horizontal */
+    OMX_VC_16X16_DC = 2,    /** Intra_16x16_DC */
+    OMX_VC_16X16_PLANE = 3  /** Intra_16x16_Plane */ 
+} OMXVCM4P10Intra16x16PredMode;
+
+
+
+/* 6.3.1.2 Intra 4x4 Prediction Modes  */
+/* A data type that enumerates intra_4x4 macroblock prediction modes is defined as follows:  */
+
+typedef enum {
+    OMX_VC_4X4_VERT = 0,     /** Intra_4x4_Vertical */
+    OMX_VC_4X4_HOR = 1,      /** Intra_4x4_Horizontal */
+    OMX_VC_4X4_DC = 2,       /** Intra_4x4_DC */
+    OMX_VC_4X4_DIAG_DL = 3,  /** Intra_4x4_Diagonal_Down_Left */
+    OMX_VC_4X4_DIAG_DR = 4,  /** Intra_4x4_Diagonal_Down_Right */
+    OMX_VC_4X4_VR = 5,       /** Intra_4x4_Vertical_Right */
+    OMX_VC_4X4_HD = 6,       /** Intra_4x4_Horizontal_Down */
+    OMX_VC_4X4_VL = 7,       /** Intra_4x4_Vertical_Left */
+    OMX_VC_4X4_HU = 8        /** Intra_4x4_Horizontal_Up */ 
+} OMXVCM4P10Intra4x4PredMode;
+
+
+
+/* 6.3.1.3 Chroma Prediction Modes  */
+/* A data type that enumerates intra chroma prediction modes is defined as follows:  */
+
+typedef enum {
+    OMX_VC_CHROMA_DC = 0,    /** Intra_Chroma_DC */
+    OMX_VC_CHROMA_HOR = 1,   /** Intra_Chroma_Horizontal */
+    OMX_VC_CHROMA_VERT = 2,  /** Intra_Chroma_Vertical */
+    OMX_VC_CHROMA_PLANE = 3  /** Intra_Chroma_Plane */ 
+} OMXVCM4P10IntraChromaPredMode;
+
+
+
+/* 6.3.1.4 Motion Estimation Modes  */
+/* A data type that enumerates H.264 motion estimation modes is defined as follows:  */
+
+typedef enum {
+    OMX_VC_M4P10_FAST_SEARCH = 0, /** Fast motion search */
+    OMX_VC_M4P10_FULL_SEARCH = 1  /** Full motion search */ 
+} OMXVCM4P10MEMode;
+
+
+
+/* 6.3.1.5 Macroblock Types  */
+/* A data type that enumerates H.264 macroblock types is defined as follows:  */
+
+typedef enum {
+    OMX_VC_P_16x16  = 0, /* defined by [ISO14496-10] */
+    OMX_VC_P_16x8  = 1,
+    OMX_VC_P_8x16  = 2,
+    OMX_VC_P_8x8  = 3,
+    OMX_VC_PREF0_8x8  = 4,
+    OMX_VC_INTER_SKIP  = 5,
+    OMX_VC_INTRA_4x4  = 8,
+    OMX_VC_INTRA_16x16  = 9,
+    OMX_VC_INTRA_PCM = 10 
+} OMXVCM4P10MacroblockType;
+
+
+
+/* 6.3.1.6 Sub-Macroblock Types  */
+/* A data type that enumerates H.264 sub-macroblock types is defined as follows:  */
+
+typedef enum {
+    OMX_VC_SUB_P_8x8 = 0, /* defined by [ISO14496-10] */
+    OMX_VC_SUB_P_8x4 = 1,
+    OMX_VC_SUB_P_4x8 = 2,
+    OMX_VC_SUB_P_4x4 = 3 
+} OMXVCM4P10SubMacroblockType;
+
+
+
+/* 6.3.1.7 Variable Length Coding (VLC) Information  */
+
+typedef struct {
+    OMX_U8 uTrailing_Ones;      /* Trailing ones; 3 at most */
+    OMX_U8 uTrailing_One_Signs; /* Trailing ones signal */
+    OMX_U8 uNumCoeffs;          /* Total number of non-zero coefs, including trailing ones */
+    OMX_U8 uTotalZeros;         /* Total number of zero coefs */
+    OMX_S16 iLevels[16];        /* Levels of non-zero coefs, in reverse zig-zag order */
+    OMX_U8 uRuns[16];           /* Runs for levels and trailing ones, in reverse zig-zag order */
+} OMXVCM4P10VLCInfo;
+
+
+
+/* 6.3.1.8 Macroblock Information  */
+
+typedef struct {
+    OMX_S32 sliceId;                          /* slice number */
+    OMXVCM4P10MacroblockType mbType;          /* MB type */
+    OMXVCM4P10SubMacroblockType subMBType[4]; /* sub-block type */
+    OMX_S32 qpy;                              /* qp for luma */
+    OMX_S32 qpc;                              /* qp for chroma */
+    OMX_U32 cbpy;                             /* CBP Luma */
+    OMX_U32 cbpc;                             /* CBP Chroma */
+    OMXVCMotionVector pMV0[4][4]; /* motion vector, represented using 1/4-pel units, pMV0[blocky][blockx] (blocky = 0~3, blockx =0~3) */
+    OMXVCMotionVector pMVPred[4][4]; /* motion vector prediction, Represented using 1/4-pel units, pMVPred[blocky][blockx] (blocky = 0~3, blockx = 0~3) */
+    OMX_U8 pRefL0Idx[4];                      /* reference picture indices */
+    OMXVCM4P10Intra16x16PredMode Intra16x16PredMode; /* best intra 16x16 prediction mode */
+    OMXVCM4P10Intra4x4PredMode pIntra4x4PredMode[16]; /* best intra 4x4 prediction mode for each block, pMV0 indexed as above */
+} OMXVCM4P10MBInfo, *OMXVCM4P10MBInfoPtr;
+
+
+
+/* 6.3.1.9 Motion Estimation Parameters  */
+
+typedef struct {
+    OMX_S32 blockSplitEnable8x8; /* enables 16x8, 8x16, 8x8 */
+    OMX_S32 blockSplitEnable4x4; /* enable splitting of 8x4, 4x8, 4x4 blocks */
+    OMX_S32 halfSearchEnable;
+    OMX_S32 quarterSearchEnable;
+    OMX_S32 intraEnable4x4;      /* 1=enable, 0=disable */
+    OMX_S32 searchRange16x16;    /* integer pixel units */
+    OMX_S32 searchRange8x8;
+    OMX_S32 searchRange4x4;
+} OMXVCM4P10MEParams;
+
+
+
+/**
+ * Function:  omxVCM4P10_PredictIntra_4x4   (6.3.3.1.1)
+ *
+ * Description:
+ * Perform Intra_4x4 prediction for luma samples. If the upper-right block is 
+ * not available, then duplication work should be handled inside the function. 
+ * Users need not define them outside. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcLeft -  Pointer to the buffer of 4 left pixels: 
+ *                  p[x, y] (x = -1, y = 0..3) 
+ *   pSrcAbove - Pointer to the buffer of 8 above pixels: 
+ *                  p[x,y] (x = 0..7, y =-1); 
+ *               must be aligned on a 4-byte boundary. 
+ *   pSrcAboveLeft - Pointer to the above left pixels: p[x,y] (x = -1, y = -1) 
+ *   leftStep - Step of left pixel buffer; must be a multiple of 4. 
+ *   dstStep - Step of the destination buffer; must be a multiple of 4. 
+ *   predMode - Intra_4x4 prediction mode. 
+ *   availability - Neighboring 4x4 block availability flag, refer to 
+ *             "Neighboring Macroblock Availability" . 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - Pointer to the destination buffer; must be aligned on a 4-byte 
+ *            boundary. 
+ *
+ * Return Value:
+ *    If the function runs without error, it returns OMX_Sts_NoErr. 
+ *    If one of the following cases occurs, the function returns 
+ *              OMX_Sts_BadArgErr: 
+ *    pDst is NULL. 
+ *    dstStep < 4, or dstStep is not a multiple of 4. 
+ *    leftStep is not a multiple of 4. 
+ *    predMode is not in the valid range of enumeration 
+ *              OMXVCM4P10Intra4x4PredMode. 
+ *    predMode is OMX_VC_4x4_VERT, but availability doesn't set OMX_VC_UPPER 
+ *              indicating p[x,-1] (x = 0..3) is not available. 
+ *    predMode is OMX_VC_4x4_HOR, but availability doesn't set OMX_VC_LEFT 
+ *              indicating p[-1,y] (y = 0..3) is not available. 
+ *    predMode is OMX_VC_4x4_DIAG_DL, but availability doesn't set 
+ *              OMX_VC_UPPER indicating p[x, -1] (x = 0..3) is not available. 
+ *    predMode is OMX_VC_4x4_DIAG_DR, but availability doesn't set 
+ *              OMX_VC_UPPER_LEFT or OMX_VC_UPPER or OMX_VC_LEFT indicating 
+ *              p[x,-1] (x = 0..3), or p[-1,y] (y = 0..3) or p[-1,-1] is not 
+ *              available. 
+ *    predMode is OMX_VC_4x4_VR, but availability doesn't set 
+ *              OMX_VC_UPPER_LEFT or OMX_VC_UPPER or OMX_VC_LEFT indicating 
+ *              p[x,-1] (x = 0..3), or p[-1,y] (y = 0..3) or p[-1,-1] is not 
+ *              available. 
+ *    predMode is OMX_VC_4x4_HD, but availability doesn't set 
+ *              OMX_VC_UPPER_LEFT or OMX_VC_UPPER or OMX_VC_LEFT indicating 
+ *              p[x,-1] (x = 0..3), or p[-1,y] (y = 0..3) or p[-1,-1] is not 
+ *              available. 
+ *    predMode is OMX_VC_4x4_VL, but availability doesn't set OMX_VC_UPPER 
+ *              indicating p[x,-1] (x = 0..3) is not available. 
+ *    predMode is OMX_VC_4x4_HU, but availability doesn't set OMX_VC_LEFT 
+ *              indicating p[-1,y] (y = 0..3) is not available. 
+ *    availability sets OMX_VC_UPPER, but pSrcAbove is NULL. 
+ *    availability sets OMX_VC_LEFT, but pSrcLeft is NULL. 
+ *    availability sets OMX_VC_UPPER_LEFT, but pSrcAboveLeft is NULL. 
+ *    either pSrcAbove or pDst is not aligned on a 4-byte boundary.  
+ *
+ * Note: 
+ *     pSrcAbove, pSrcAbove, pSrcAboveLeft may be invalid pointers if 
+ *     they are not used by intra prediction as implied in predMode. 
+ *
+ */
+OMXResult omxVCM4P10_PredictIntra_4x4 (
+    const OMX_U8 *pSrcLeft,
+    const OMX_U8 *pSrcAbove,
+    const OMX_U8 *pSrcAboveLeft,
+    OMX_U8 *pDst,
+    OMX_INT leftStep,
+    OMX_INT dstStep,
+    OMXVCM4P10Intra4x4PredMode predMode,
+    OMX_S32 availability
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_PredictIntra_16x16   (6.3.3.1.2)
+ *
+ * Description:
+ * Perform Intra_16x16 prediction for luma samples. If the upper-right block 
+ * is not available, then duplication work should be handled inside the 
+ * function. Users need not define them outside. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcLeft - Pointer to the buffer of 16 left pixels: p[x, y] (x = -1, y = 
+ *            0..15) 
+ *   pSrcAbove - Pointer to the buffer of 16 above pixels: p[x,y] (x = 0..15, 
+ *            y= -1); must be aligned on a 16-byte boundary. 
+ *   pSrcAboveLeft - Pointer to the above left pixels: p[x,y] (x = -1, y = -1) 
+ *   leftStep - Step of left pixel buffer; must be a multiple of 16. 
+ *   dstStep - Step of the destination buffer; must be a multiple of 16. 
+ *   predMode - Intra_16x16 prediction mode, please refer to section 3.4.1. 
+ *   availability - Neighboring 16x16 MB availability flag. Refer to 
+ *                  section 3.4.4. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst -Pointer to the destination buffer; must be aligned on a 16-byte 
+ *            boundary. 
+ *
+ * Return Value:
+ *    If the function runs without error, it returns OMX_Sts_NoErr. 
+ *    If one of the following cases occurs, the function returns 
+ *              OMX_Sts_BadArgErr: 
+ *    pDst is NULL. 
+ *    dstStep < 16. or dstStep is not a multiple of 16. 
+ *    leftStep is not a multiple of 16. 
+ *    predMode is not in the valid range of enumeration 
+ *              OMXVCM4P10Intra16x16PredMode 
+ *    predMode is OMX_VC_16X16_VERT, but availability doesn't set 
+ *              OMX_VC_UPPER indicating p[x,-1] (x = 0..15) is not available. 
+ *    predMode is OMX_VC_16X16_HOR, but availability doesn't set OMX_VC_LEFT 
+ *              indicating p[-1,y] (y = 0..15) is not available. 
+ *    predMode is OMX_VC_16X16_PLANE, but availability doesn't set 
+ *              OMX_VC_UPPER_LEFT or OMX_VC_UPPER or OMX_VC_LEFT indicating 
+ *              p[x,-1](x = 0..15), or p[-1,y] (y = 0..15), or p[-1,-1] is not 
+ *              available. 
+ *    availability sets OMX_VC_UPPER, but pSrcAbove is NULL. 
+ *    availability sets OMX_VC_LEFT, but pSrcLeft is NULL. 
+ *    availability sets OMX_VC_UPPER_LEFT, but pSrcAboveLeft is NULL. 
+ *    either pSrcAbove or pDst is not aligned on a 16-byte boundary.  
+ *
+ * Note: 
+ *     pSrcAbove, pSrcAbove, pSrcAboveLeft may be invalid pointers if 
+ *     they are not used by intra prediction implied in predMode. 
+ * Note: 
+ *     OMX_VC_UPPER_RIGHT is not used in intra_16x16 luma prediction. 
+ *
+ */
+OMXResult omxVCM4P10_PredictIntra_16x16 (
+    const OMX_U8 *pSrcLeft,
+    const OMX_U8 *pSrcAbove,
+    const OMX_U8 *pSrcAboveLeft,
+    OMX_U8 *pDst,
+    OMX_INT leftStep,
+    OMX_INT dstStep,
+    OMXVCM4P10Intra16x16PredMode predMode,
+    OMX_S32 availability
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_PredictIntraChroma_8x8   (6.3.3.1.3)
+ *
+ * Description:
+ * Performs intra prediction for chroma samples. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcLeft - Pointer to the buffer of 8 left pixels: p[x, y] (x = -1, y= 
+ *            0..7). 
+ *   pSrcAbove - Pointer to the buffer of 8 above pixels: p[x,y] (x = 0..7, y 
+ *            = -1); must be aligned on an 8-byte boundary. 
+ *   pSrcAboveLeft - Pointer to the above left pixels: p[x,y] (x = -1, y = -1) 
+ *   leftStep - Step of left pixel buffer; must be a multiple of 8. 
+ *   dstStep - Step of the destination buffer; must be a multiple of 8. 
+ *   predMode - Intra chroma prediction mode, please refer to section 3.4.3. 
+ *   availability - Neighboring chroma block availability flag, please refer 
+ *            to  "Neighboring Macroblock Availability". 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - Pointer to the destination buffer; must be aligned on an 8-byte 
+ *            boundary. 
+ *
+ * Return Value:
+ *    If the function runs without error, it returns OMX_Sts_NoErr. 
+ *    If any of the following cases occurs, the function returns 
+ *              OMX_Sts_BadArgErr: 
+ *    pDst is NULL. 
+ *    dstStep < 8 or dstStep is not a multiple of 8. 
+ *    leftStep is not a multiple of 8. 
+ *    predMode is not in the valid range of enumeration 
+ *              OMXVCM4P10IntraChromaPredMode. 
+ *    predMode is OMX_VC_CHROMA_VERT, but availability doesn't set 
+ *              OMX_VC_UPPER indicating p[x,-1] (x = 0..7) is not available. 
+ *    predMode is OMX_VC_CHROMA_HOR, but availability doesn't set OMX_VC_LEFT 
+ *              indicating p[-1,y] (y = 0..7) is not available. 
+ *    predMode is OMX_VC_CHROMA_PLANE, but availability doesn't set 
+ *              OMX_VC_UPPER_LEFT or OMX_VC_UPPER or OMX_VC_LEFT indicating 
+ *              p[x,-1](x = 0..7), or p[-1,y] (y = 0..7), or p[-1,-1] is not 
+ *              available. 
+ *    availability sets OMX_VC_UPPER, but pSrcAbove is NULL. 
+ *    availability sets OMX_VC_LEFT, but pSrcLeft is NULL. 
+ *    availability sets OMX_VC_UPPER_LEFT, but pSrcAboveLeft is NULL. 
+ *    either pSrcAbove or pDst is not aligned on a 8-byte boundary.  
+ *
+ *  Note: pSrcAbove, pSrcAbove, pSrcAboveLeft may be invalid pointer if 
+ *  they are not used by intra prediction implied in predMode. 
+ *
+ *  Note: OMX_VC_UPPER_RIGHT is not used in intra chroma prediction. 
+ *
+ */
+OMXResult omxVCM4P10_PredictIntraChroma_8x8 (
+    const OMX_U8 *pSrcLeft,
+    const OMX_U8 *pSrcAbove,
+    const OMX_U8 *pSrcAboveLeft,
+    OMX_U8 *pDst,
+    OMX_INT leftStep,
+    OMX_INT dstStep,
+    OMXVCM4P10IntraChromaPredMode predMode,
+    OMX_S32 availability
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_InterpolateLuma   (6.3.3.2.1)
+ *
+ * Description:
+ * Performs quarter-pixel interpolation for inter luma MB. It is assumed that 
+ * the frame is already padded when calling this function. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - Pointer to the source reference frame buffer 
+ *   srcStep - reference frame step, in bytes; must be a multiple of roi.width 
+ *   dstStep - destination frame step, in bytes; must be a multiple of 
+ *            roi.width 
+ *   dx - Fractional part of horizontal motion vector component in 1/4 pixel 
+ *            unit; valid in the range [0,3] 
+ *   dy - Fractional part of vertical motion vector y component in 1/4 pixel 
+ *            unit; valid in the range [0,3] 
+ *   roi - Dimension of the interpolation region; the parameters roi.width and 
+ *            roi.height must be equal to either 4, 8, or 16. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - Pointer to the destination frame buffer: 
+ *          if roi.width==4,  4-byte alignment required 
+ *          if roi.width==8,  8-byte alignment required 
+ *          if roi.width==16, 16-byte alignment required 
+ *
+ * Return Value:
+ *    If the function runs without error, it returns OMX_Sts_NoErr. 
+ *    If one of the following cases occurs, the function returns 
+ *              OMX_Sts_BadArgErr: 
+ *    pSrc or pDst is NULL. 
+ *    srcStep or dstStep < roi.width. 
+ *    dx or dy is out of range [0,3]. 
+ *    roi.width or roi.height is out of range {4, 8, 16}. 
+ *    roi.width is equal to 4, but pDst is not 4 byte aligned. 
+ *    roi.width is equal to 8 or 16, but pDst is not 8 byte aligned. 
+ *    srcStep or dstStep is not a multiple of 8. 
+ *
+ */
+OMXResult omxVCM4P10_InterpolateLuma (
+    const OMX_U8 *pSrc,
+    OMX_S32 srcStep,
+    OMX_U8 *pDst,
+    OMX_S32 dstStep,
+    OMX_S32 dx,
+    OMX_S32 dy,
+    OMXSize roi
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_InterpolateChroma   (6.3.3.2.2)
+ *
+ * Description:
+ * Performs 1/8-pixel interpolation for inter chroma MB. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc -Pointer to the source reference frame buffer 
+ *   srcStep -Reference frame step in bytes 
+ *   dstStep -Destination frame step in bytes; must be a multiple of 
+ *            roi.width. 
+ *   dx -Fractional part of horizontal motion vector component in 1/8 pixel 
+ *            unit; valid in the range [0,7] 
+ *   dy -Fractional part of vertical motion vector component in 1/8 pixel 
+ *            unit; valid in the range [0,7] 
+ *   roi -Dimension of the interpolation region; the parameters roi.width and 
+ *            roi.height must be equal to either 2, 4, or 8. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst -Pointer to the destination frame buffer:
+ *         if roi.width==2,  2-byte alignment required 
+ *         if roi.width==4,  4-byte alignment required 
+ *         if roi.width==8, 8-byte alignment required 
+ *
+ * Return Value:
+ *    If the function runs without error, it returns OMX_Sts_NoErr. 
+ *    If one of the following cases occurs, the function returns 
+ *              OMX_Sts_BadArgErr: 
+ *    pSrc or pDst is NULL. 
+ *    srcStep or dstStep < 8. 
+ *    dx or dy is out of range [0-7]. 
+ *    roi.width or roi.height is out of range {2,4,8}. 
+ *    roi.width is equal to 2, but pDst is not 2-byte aligned. 
+ *    roi.width is equal to 4, but pDst is not 4-byte aligned. 
+ *    roi.width is equal to 8, but pDst is not 8 byte aligned. 
+ *    srcStep or dstStep is not a multiple of 8. 
+ *
+ */
+OMXResult omxVCM4P10_InterpolateChroma (
+    const OMX_U8 *pSrc,
+    OMX_S32 srcStep,
+    OMX_U8 *pDst,
+    OMX_S32 dstStep,
+    OMX_S32 dx,
+    OMX_S32 dy,
+    OMXSize roi
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_FilterDeblockingLuma_VerEdge_I   (6.3.3.3.1)
+ *
+ * Description:
+ * Performs in-place deblock filtering on four vertical edges of the luma 
+ * macroblock (16x16). 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - Pointer to the input macroblock; must be 16-byte aligned. 
+ *   srcdstStep -Step of the arrays; must be a multiple of 16. 
+ *   pAlpha -Array of size 2 of alpha thresholds (the first item is the alpha 
+ *            threshold for the external vertical edge, and the second item is 
+ *            for the internal vertical edge); per [ISO14496-10] alpha values 
+ *            must be in the range [0,255]. 
+ *   pBeta -Array of size 2 of beta thresholds (the first item is the beta 
+ *            threshold for the external vertical edge, and the second item is 
+ *            for the internal vertical edge); per [ISO14496-10] beta values 
+ *            must be in the range [0,18]. 
+ *   pThresholds -Array of size 16 of Thresholds (TC0) (values for the left 
+ *            edge of each 4x4 block, arranged in vertical block order); must 
+ *            be aligned on a 4-byte boundary..  Per [ISO14496-10] values must 
+ *            be in the range [0,25]. 
+ *   pBS -Array of size 16 of BS parameters (arranged in vertical block 
+ *            order); valid in the range [0,4] with the following 
+ *            restrictions: i) pBS[i]== 4 may occur only for 0<=i<=3, ii) 
+ *            pBS[i]== 4 if and only if pBS[i^3]== 4.  Must be 4-byte aligned. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst -Pointer to filtered output macroblock. 
+ *
+ * Return Value:
+ *    If the function runs without error, it returns OMX_Sts_NoErr. 
+ *    If one of the following cases occurs, the function returns 
+ *              OMX_Sts_BadArgErr: 
+ *    Either of the pointers in pSrcDst, pAlpha, pBeta, pThresholds, or pBS 
+ *              is NULL. 
+ *    Either pThresholds or pBS is not aligned on a 4-byte boundary. 
+ *    pSrcDst is not 16-byte aligned. 
+ *    srcdstStep is not a multiple of 16. 
+ *    pAlpha[0] and/or pAlpha[1] is outside the range [0,255]. 
+ *    pBeta[0] and/or pBeta[1] is outside the range [0,18]. 
+ *    One or more entries in the table pThresholds[0..15]is outside of the 
+ *              range [0,25]. 
+ *    pBS is out of range, i.e., one of the following conditions is true: 
+ *              pBS[i]<0, pBS[i]>4, pBS[i]==4 for i>=4, or (pBS[i]==4 && 
+ *              pBS[i^3]!=4) for 0<=i<=3. 
+ *
+ */
+OMXResult omxVCM4P10_FilterDeblockingLuma_VerEdge_I (
+    OMX_U8 *pSrcDst,
+    OMX_S32 srcdstStep,
+    const OMX_U8 *pAlpha,
+    const OMX_U8 *pBeta,
+    const OMX_U8 *pThresholds,
+    const OMX_U8 *pBS
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_FilterDeblockingLuma_HorEdge_I   (6.3.3.3.2)
+ *
+ * Description:
+ * Performs in-place deblock filtering on four horizontal edges of the luma 
+ * macroblock (16x16). 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - pointer to the input macroblock; must be 16-byte aligned. 
+ *   srcdstStep - step of the arrays; must be a multiple of 16. 
+ *   pAlpha - array of size 2 of alpha thresholds (the first item is the alpha 
+ *            threshold for the external vertical edge, and the second item is 
+ *            for the internal horizontal edge); per [ISO14496-10] alpha 
+ *            values must be in the range [0,255]. 
+ *   pBeta - array of size 2 of beta thresholds (the first item is the beta 
+ *            threshold for the external horizontal edge, and the second item 
+ *            is for the internal horizontal edge). Per [ISO14496-10] beta 
+ *            values must be in the range [0,18]. 
+ *   pThresholds - array of size 16 containing thresholds, TC0, for the top 
+ *            horizontal edge of each 4x4 block, arranged in horizontal block 
+ *            order; must be aligned on a 4-byte boundary.  Per [ISO14496 10] 
+ *            values must be in the range [0,25]. 
+ *   pBS - array of size 16 of BS parameters (arranged in horizontal block 
+ *            order); valid in the range [0,4] with the following 
+ *            restrictions: i) pBS[i]== 4 may occur only for 0<=i<=3, ii) 
+ *            pBS[i]== 4 if and only if pBS[i^3]== 4.  Must be 4-byte aligned. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst -Pointer to filtered output macroblock. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr, if the function runs without error.
+ * 
+ *    OMX_Sts_BadArgErr, if one of the following cases occurs: 
+ *    -    one or more of the following pointers is NULL: pSrcDst, pAlpha, 
+ *              pBeta, pThresholds, or pBS. 
+ *    -    either pThresholds or pBS is not aligned on a 4-byte boundary. 
+ *    -    pSrcDst is not 16-byte aligned. 
+ *    -    srcdstStep is not a multiple of 16. 
+ *    -    pAlpha[0] and/or pAlpha[1] is outside the range [0,255]. 
+ *    -    pBeta[0] and/or pBeta[1] is outside the range [0,18]. 
+ *    -    One or more entries in the table pThresholds[0..15] is 
+ *         outside of the range [0,25]. 
+ *    -    pBS is out of range, i.e., one of the following conditions is true: 
+ *              pBS[i]<0, pBS[i]>4, pBS[i]==4 for i>=4, or 
+ *              (pBS[i]==4 && pBS[i^3]!=4) for 0<=i<=3. 
+ *
+ */
+OMXResult omxVCM4P10_FilterDeblockingLuma_HorEdge_I (
+    OMX_U8 *pSrcDst,
+    OMX_S32 srcdstStep,
+    const OMX_U8 *pAlpha,
+    const OMX_U8 *pBeta,
+    const OMX_U8 *pThresholds,
+    const OMX_U8 *pBS
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_FilterDeblockingChroma_VerEdge_I   (6.3.3.3.3)
+ *
+ * Description:
+ * Performs in-place deblock filtering on four vertical edges of the chroma 
+ * macroblock (8x8). 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - Pointer to the input macroblock; must be 8-byte aligned. 
+ *   srcdstStep - Step of the arrays; must be a multiple of 8. 
+ *   pAlpha - Array of size 2 of alpha thresholds (the first item is alpha 
+ *            threshold for external vertical edge, and the second item is for 
+ *            internal vertical edge); per [ISO14496-10] alpha values must be 
+ *            in the range [0,255]. 
+ *   pBeta - Array of size 2 of beta thresholds (the first item is the beta 
+ *            threshold for the external vertical edge, and the second item is 
+ *            for the internal vertical edge); per [ISO14496-10] beta values 
+ *            must be in the range [0,18]. 
+ *   pThresholds - Array of size 8 containing thresholds, TC0, for the left 
+ *            vertical edge of each 4x2 chroma block, arranged in vertical 
+ *            block order; must be aligned on a 4-byte boundary.  Per 
+ *            [ISO14496-10] values must be in the range [0,25]. 
+ *   pBS - Array of size 16 of BS parameters (values for each 2x2 chroma 
+ *            block, arranged in vertical block order). This parameter is the 
+ *            same as the pBS parameter passed into FilterDeblockLuma_VerEdge; 
+ *            valid in the range [0,4] with the following restrictions: i) 
+ *            pBS[i]== 4 may occur only for 0<=i<=3, ii) pBS[i]== 4 if and 
+ *            only if pBS[i^3]== 4.  Must be 4 byte aligned. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst -Pointer to filtered output macroblock. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr, if the function runs without error.
+ * 
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    one or more of the following pointers is NULL: pSrcDst, pAlpha, 
+ *              pBeta, pThresholds, or pBS. 
+ *    -    pSrcDst is not 8-byte aligned. 
+ *    -    srcdstStep is not a multiple of 8. 
+ *    -    pThresholds is not 4-byte aligned. 
+ *    -    pAlpha[0] and/or pAlpha[1] is outside the range [0,255]. 
+ *    -    pBeta[0] and/or pBeta[1] is outside the range [0,18]. 
+ *    -    One or more entries in the table pThresholds[0..7] is outside 
+ *         of the range [0,25]. 
+ *    -    pBS is out of range, i.e., one of the following conditions is true: 
+ *         pBS[i]<0, pBS[i]>4, pBS[i]==4 for i>=4, or 
+ *         (pBS[i]==4 && pBS[i^3]!=4) for 0<=i<=3. 
+ *    -    pBS is not 4-byte aligned. 
+ *
+ */
+OMXResult omxVCM4P10_FilterDeblockingChroma_VerEdge_I (
+    OMX_U8 *pSrcDst,
+    OMX_S32 srcdstStep,
+    const OMX_U8 *pAlpha,
+    const OMX_U8 *pBeta,
+    const OMX_U8 *pThresholds,
+    const OMX_U8 *pBS
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_FilterDeblockingChroma_HorEdge_I   (6.3.3.3.4)
+ *
+ * Description:
+ * Performs in-place deblock filtering on the horizontal edges of the chroma 
+ * macroblock (8x8). 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - pointer to the input macroblock; must be 8-byte aligned. 
+ *   srcdstStep - array step; must be a multiple of 8. 
+ *   pAlpha - array of size 2 containing alpha thresholds; the first element 
+ *            contains the threshold for the external horizontal edge, and the 
+ *            second element contains the threshold for internal horizontal 
+ *            edge.  Per [ISO14496-10] alpha values must be in the range 
+ *            [0,255]. 
+ *   pBeta - array of size 2 containing beta thresholds; the first element 
+ *            contains the threshold for the external horizontal edge, and the 
+ *            second element contains the threshold for the internal 
+ *            horizontal edge.  Per [ISO14496-10] beta values must be in the 
+ *            range [0,18]. 
+ *   pThresholds - array of size 8 containing thresholds, TC0, for the top 
+ *            horizontal edge of each 2x4 chroma block, arranged in horizontal 
+ *            block order; must be aligned on a 4-byte boundary.  Per 
+ *            [ISO14496-10] values must be in the range [0,25]. 
+ *   pBS - array of size 16 containing BS parameters for each 2x2 chroma 
+ *            block, arranged in horizontal block order; valid in the range 
+ *            [0,4] with the following restrictions: i) pBS[i]== 4 may occur 
+ *            only for 0<=i<=3, ii) pBS[i]== 4 if and only if pBS[i^3]== 4. 
+ *            Must be 4-byte aligned. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst -Pointer to filtered output macroblock. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr, if the function runs without error.
+ * 
+ *    OMX_Sts_BadArgErr, if one of the following cases occurs: 
+ *    -    any of the following pointers is NULL: 
+ *         pSrcDst, pAlpha, pBeta, pThresholds, or pBS. 
+ *    -    pSrcDst is not 8-byte aligned. 
+ *    -    srcdstStep is not a multiple of 8. 
+ *    -    pThresholds is not 4-byte aligned. 
+ *    -    pAlpha[0] and/or pAlpha[1] is outside the range [0,255]. 
+ *    -    pBeta[0] and/or pBeta[1] is outside the range [0,18]. 
+ *    -    One or more entries in the table pThresholds[0..7] is outside 
+ *         of the range [0,25]. 
+ *    -    pBS is out of range, i.e., one of the following conditions is true: 
+ *              pBS[i]<0, pBS[i]>4, pBS[i]==4 for i>=4, or 
+ *              (pBS[i]==4 && pBS[i^3]!=4) for 0<=i<=3.
+ *    -    pBS is not 4-byte aligned. 
+ *
+ */
+OMXResult omxVCM4P10_FilterDeblockingChroma_HorEdge_I (
+    OMX_U8 *pSrcDst,
+    OMX_S32 srcdstStep,
+    const OMX_U8 *pAlpha,
+    const OMX_U8 *pBeta,
+    const OMX_U8 *pThresholds,
+    const OMX_U8 *pBS
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_DeblockLuma_I   (6.3.3.3.5)
+ *
+ * Description:
+ * This function performs in-place deblock filtering the horizontal and 
+ * vertical edges of a luma macroblock (16x16). 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - pointer to the input macroblock; must be 16-byte aligned. 
+ *   srcdstStep - image width; must be a multiple of 16. 
+ *   pAlpha - pointer to a 2x2 table of alpha thresholds, organized as 
+ *            follows: {external vertical edge, internal vertical edge, 
+ *            external horizontal edge, internal horizontal edge }.  Per 
+ *            [ISO14496-10] alpha values must be in the range [0,255]. 
+ *   pBeta - pointer to a 2x2 table of beta thresholds, organized as follows: 
+ *            {external vertical edge, internal vertical edge, external 
+ *            horizontal edge, internal horizontal edge }.  Per [ISO14496-10] 
+ *            beta values must be in the range [0,18]. 
+ *   pThresholds - pointer to a 16x2 table of threshold (TC0), organized as 
+ *            follows: {values for the left or above edge of each 4x4 block, 
+ *            arranged in vertical block order and then in horizontal block 
+ *            order}; must be aligned on a 4-byte boundary.  Per [ISO14496-10] 
+ *            values must be in the range [0,25]. 
+ *   pBS - pointer to a 16x2 table of BS parameters arranged in scan block 
+ *            order for vertical edges and then horizontal edges; valid in the 
+ *            range [0,4] with the following restrictions: i) pBS[i]== 4 may 
+ *            occur only for 0<=i<=3, ii) pBS[i]== 4 if and only if pBS[i^3]== 
+ *            4. Must be 4-byte aligned. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst - pointer to filtered output macroblock. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments 
+ *    -     one or more of the following pointers is NULL: pSrcDst, pAlpha, 
+ *              pBeta, pThresholds or pBS. 
+ *    -    pSrcDst is not 16-byte aligned. 
+ *    -    either pThresholds or pBS is not aligned on a 4-byte boundary. 
+ *    -    one or more entries in the table pAlpha[0..3] is outside the range 
+ *              [0,255]. 
+ *    -    one or more entries in the table pBeta[0..3] is outside the range 
+ *              [0,18]. 
+ *    -    one or more entries in the table pThresholds[0..31]is outside of 
+ *              the range [0,25]. 
+ *    -    pBS is out of range, i.e., one of the following conditions is true: 
+ *              pBS[i]<0, pBS[i]>4, pBS[i]==4 for i>=4, or 
+ *             (pBS[i]==4 && pBS[i^3]!=4) for 0<=i<=3. 
+ *    -    srcdstStep is not a multiple of 16. 
+ *
+ */
+OMXResult omxVCM4P10_DeblockLuma_I (
+    OMX_U8 *pSrcDst,
+    OMX_S32 srcdstStep,
+    const OMX_U8 *pAlpha,
+    const OMX_U8 *pBeta,
+    const OMX_U8 *pThresholds,
+    const OMX_U8 *pBS
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_DeblockChroma_I   (6.3.3.3.6)
+ *
+ * Description:
+ * Performs in-place deblocking filtering on all edges of the chroma 
+ * macroblock (16x16). 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - pointer to the input macroblock; must be 8-byte aligned. 
+ *   srcdstStep - step of the arrays; must be a multiple of 8. 
+ *   pAlpha - pointer to a 2x2 array of alpha thresholds, organized as 
+ *            follows: {external vertical edge, internal vertical edge, 
+ *            external horizontal edge, internal horizontal edge }.  Per 
+ *            [ISO14496-10] alpha values must be in the range [0,255]. 
+ *   pBeta - pointer to a 2x2 array of Beta Thresholds, organized as follows: 
+ *            { external vertical edge, internal vertical edge, external 
+ *            horizontal edge, internal horizontal edge }.  Per [ISO14496-10] 
+ *            beta values must be in the range [0,18]. 
+ *   pThresholds - array of size 8x2 of Thresholds (TC0) (values for the left 
+ *            or above edge of each 4x2 or 2x4 block, arranged in vertical 
+ *            block order and then in horizontal block order); must be aligned 
+ *            on a 4-byte boundary. Per [ISO14496-10] values must be in the 
+ *            range [0,25]. 
+ *   pBS - array of size 16x2 of BS parameters (arranged in scan block order 
+ *            for vertical edges and then horizontal edges); valid in the 
+ *            range [0,4] with the following restrictions: i) pBS[i]== 4 may 
+ *            occur only for 0<=i<=3, ii) pBS[i]== 4 if and only if pBS[i^3]== 
+ *            4.  Must be 4-byte aligned. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst - pointer to filtered output macroblock. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments 
+ *    -   one or more of the following pointers is NULL: pSrcDst, pAlpha, 
+ *              pBeta, pThresholds, or pBS. 
+ *    -   pSrcDst is not 8-byte aligned. 
+ *    -   either pThresholds or pBS is not 4-byte aligned. 
+ *    -   one or more entries in the table pAlpha[0..3] is outside the range 
+ *              [0,255]. 
+ *    -   one or more entries in the table pBeta[0..3] is outside the range 
+ *              [0,18]. 
+ *    -   one or more entries in the table pThresholds[0..15]is outside of 
+ *              the range [0,25]. 
+ *    -   pBS is out of range, i.e., one of the following conditions is true: 
+ *            pBS[i]<0, pBS[i]>4, pBS[i]==4  for i>=4, or 
+ *            (pBS[i]==4 && pBS[i^3]!=4) for 0<=i<=3. 
+ *    -   srcdstStep is not a multiple of 8. 
+ *
+ */
+OMXResult omxVCM4P10_DeblockChroma_I (
+    OMX_U8 *pSrcDst,
+    OMX_S32 srcdstStep,
+    const OMX_U8 *pAlpha,
+    const OMX_U8 *pBeta,
+    const OMX_U8 *pThresholds,
+    const OMX_U8 *pBS
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_DecodeChromaDcCoeffsToPairCAVLC   (6.3.4.1.1)
+ *
+ * Description:
+ * Performs CAVLC decoding and inverse raster scan for a 2x2 block of 
+ * ChromaDCLevel.  The decoded coefficients in the packed position-coefficient 
+ * buffer are stored in reverse zig-zag order, i.e., the first buffer element 
+ * contains the last non-zero postion-coefficient pair of the block. Within 
+ * each position-coefficient pair, the position entry indicates the 
+ * raster-scan position of the coefficient, while the coefficient entry 
+ * contains the coefficient value. 
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - Double pointer to current byte in bit stream buffer 
+ *   pOffset - Pointer to current bit position in the byte pointed to by 
+ *            *ppBitStream; valid in the range [0,7]. 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after each block is decoded 
+ *   pOffset - *pOffset is updated after each block is decoded 
+ *   pNumCoeff - Pointer to the number of nonzero coefficients in this block 
+ *   ppPosCoefBuf - Double pointer to destination residual 
+ *            coefficient-position pair buffer.  Buffer position 
+ *            (*ppPosCoefBuf) is updated upon return, unless there are only 
+ *            zero coefficients in the currently decoded block.  In this case 
+ *            the caller is expected to bypass the transform/dequantization of 
+ *            the empty blocks. 
+ *
+ * Return Value:
+ *
+ *    OMX_Sts_NoErr, if the function runs without error.
+ * 
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    ppBitStream or pOffset is NULL. 
+ *    -    ppPosCoefBuf or pNumCoeff is NULL. 
+ *    OMX_Sts_Err - if one of the following is true: 
+ *    -    an illegal code is encountered in the bitstream 
+ *
+ */
+OMXResult omxVCM4P10_DecodeChromaDcCoeffsToPairCAVLC (
+    const OMX_U8 **ppBitStream,
+    OMX_S32*pOffset,
+    OMX_U8 *pNumCoeff,
+    OMX_U8 **ppPosCoefbuf
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_DecodeCoeffsToPairCAVLC   (6.3.4.1.2)
+ *
+ * Description:
+ * Performs CAVLC decoding and inverse zigzag scan for 4x4 block of 
+ * Intra16x16DCLevel, Intra16x16ACLevel, LumaLevel, and ChromaACLevel. Inverse 
+ * field scan is not supported. The decoded coefficients in the packed 
+ * position-coefficient buffer are stored in reverse zig-zag order, i.e., the 
+ * first buffer element contains the last non-zero postion-coefficient pair of 
+ * the block. Within each position-coefficient pair, the position entry 
+ * indicates the raster-scan position of the coefficient, while the 
+ * coefficient entry contains the coefficient value. 
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream -Double pointer to current byte in bit stream buffer 
+ *   pOffset - Pointer to current bit position in the byte pointed to by 
+ *            *ppBitStream; valid in the range [0,7]. 
+ *   sMaxNumCoeff - Maximum the number of non-zero coefficients in current 
+ *            block 
+ *   sVLCSelect - VLC table selector, obtained from the number of non-zero 
+ *            coefficients contained in the above and left 4x4 blocks.  It is 
+ *            equivalent to the variable nC described in H.264 standard table 
+ *            9 5, except its value can t be less than zero. 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after each block is decoded.  
+ *            Buffer position (*ppPosCoefBuf) is updated upon return, unless 
+ *            there are only zero coefficients in the currently decoded block. 
+ *             In this case the caller is expected to bypass the 
+ *            transform/dequantization of the empty blocks. 
+ *   pOffset - *pOffset is updated after each block is decoded 
+ *   pNumCoeff - Pointer to the number of nonzero coefficients in this block 
+ *   ppPosCoefBuf - Double pointer to destination residual 
+ *            coefficient-position pair buffer 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ * 
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    ppBitStream or pOffset is NULL. 
+ *    -    ppPosCoefBuf or pNumCoeff is NULL. 
+ *    -    sMaxNumCoeff is not equal to either 15 or 16. 
+ *    -    sVLCSelect is less than 0. 
+ *
+ *    OMX_Sts_Err - if one of the following is true: 
+ *    -    an illegal code is encountered in the bitstream 
+ *
+ */
+OMXResult omxVCM4P10_DecodeCoeffsToPairCAVLC (
+    const OMX_U8 **ppBitStream,
+    OMX_S32 *pOffset,
+    OMX_U8 *pNumCoeff,
+    OMX_U8 **ppPosCoefbuf,
+    OMX_INT sVLCSelect,
+    OMX_INT sMaxNumCoeff
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_TransformDequantLumaDCFromPair   (6.3.4.2.1)
+ *
+ * Description:
+ * Reconstructs the 4x4 LumaDC block from the coefficient-position pair 
+ * buffer, performs integer inverse, and dequantization for 4x4 LumaDC 
+ * coefficients, and updates the pair buffer pointer to the next non-empty 
+ * block. 
+ *
+ * Input Arguments:
+ *   
+ *   ppSrc - Double pointer to residual coefficient-position pair buffer 
+ *            output by CALVC decoding 
+ *   QP - Quantization parameter QpY 
+ *
+ * Output Arguments:
+ *   
+ *   ppSrc - *ppSrc is updated to the start of next non empty block 
+ *   pDst - Pointer to the reconstructed 4x4 LumaDC coefficients buffer; must 
+ *            be aligned on a 8-byte boundary. 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    ppSrc or pDst is NULL. 
+ *    -    pDst is not 8 byte aligned. 
+ *    -    QP is not in the range of [0-51]. 
+ *
+ */
+OMXResult omxVCM4P10_TransformDequantLumaDCFromPair (
+    const OMX_U8 **ppSrc,
+    OMX_S16 *pDst,
+    OMX_INT QP
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_TransformDequantChromaDCFromPair   (6.3.4.2.2)
+ *
+ * Description:
+ * Reconstruct the 2x2 ChromaDC block from coefficient-position pair buffer, 
+ * perform integer inverse transformation, and dequantization for 2x2 chroma 
+ * DC coefficients, and update the pair buffer pointer to next non-empty 
+ * block. 
+ *
+ * Input Arguments:
+ *   
+ *   ppSrc - Double pointer to residual coefficient-position pair buffer 
+ *            output by CALVC decoding 
+ *   QP - Quantization parameter QpC 
+ *
+ * Output Arguments:
+ *   
+ *   ppSrc - *ppSrc is updated to the start of next non empty block 
+ *   pDst - Pointer to the reconstructed 2x2 ChromaDC coefficients buffer; 
+ *            must be aligned on a 4-byte boundary. 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    ppSrc or pDst is NULL. 
+ *    -    pDst is not 4-byte aligned. 
+ *    -    QP is not in the range of [0-51]. 
+ *
+ */
+OMXResult omxVCM4P10_TransformDequantChromaDCFromPair (
+    const OMX_U8 **ppSrc,
+    OMX_S16 *pDst,
+    OMX_INT QP
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_DequantTransformResidualFromPairAndAdd   (6.3.4.2.3)
+ *
+ * Description:
+ * Reconstruct the 4x4 residual block from coefficient-position pair buffer, 
+ * perform dequantization and integer inverse transformation for 4x4 block of 
+ * residuals with previous intra prediction or motion compensation data, and 
+ * update the pair buffer pointer to next non-empty block. If pDC == NULL, 
+ * there re 16 non-zero AC coefficients at most in the packed buffer starting 
+ * from 4x4 block position 0; If pDC != NULL, there re 15 non-zero AC 
+ * coefficients at most in the packet buffer starting from 4x4 block position 
+ * 1. 
+ *
+ * Input Arguments:
+ *   
+ *   ppSrc - Double pointer to residual coefficient-position pair buffer 
+ *            output by CALVC decoding 
+ *   pPred - Pointer to the predicted 4x4 block; must be aligned on a 4-byte 
+ *            boundary 
+ *   predStep - Predicted frame step size in bytes; must be a multiple of 4 
+ *   dstStep - Destination frame step in bytes; must be a multiple of 4 
+ *   pDC - Pointer to the DC coefficient of this block, NULL if it doesn't 
+ *            exist 
+ *   QP - QP Quantization parameter.  It should be QpC in chroma 4x4 block 
+ *            decoding, otherwise it should be QpY. 
+ *   AC - Flag indicating if at least one non-zero AC coefficient exists 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - pointer to the reconstructed 4x4 block data; must be aligned on a 
+ *            4-byte boundary 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    pPred or pDst is NULL. 
+ *    -    pPred or pDst is not 4-byte aligned. 
+ *    -    predStep or dstStep is not a multiple of 4. 
+ *    -    AC !=0 and Qp is not in the range of [0-51] or ppSrc == NULL. 
+ *    -    AC ==0 && pDC ==NULL. 
+ *
+ */
+OMXResult omxVCM4P10_DequantTransformResidualFromPairAndAdd (
+    const OMX_U8 **ppSrc,
+    const OMX_U8 *pPred,
+    const OMX_S16 *pDC,
+    OMX_U8 *pDst,
+    OMX_INT predStep,
+    OMX_INT dstStep,
+    OMX_INT QP,
+    OMX_INT AC
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_MEGetBufSize   (6.3.5.1.1)
+ *
+ * Description:
+ * Computes the size, in bytes, of the vendor-specific specification 
+ * structure for the omxVCM4P10 motion estimation functions BlockMatch_Integer 
+ * and MotionEstimationMB. 
+ *
+ * Input Arguments:
+ *   
+ *   MEmode - motion estimation mode; available modes are defined by the 
+ *            enumerated type OMXVCM4P10MEMode 
+ *   pMEParams -motion estimation parameters 
+ *
+ * Output Arguments:
+ *   
+ *   pSize - pointer to the number of bytes required for the motion 
+ *            estimation specification structure 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    pMEParams or pSize is NULL. 
+ *    -    an invalid MEMode is specified. 
+ *
+ */
+OMXResult omxVCM4P10_MEGetBufSize (
+    OMXVCM4P10MEMode MEmode,
+    const OMXVCM4P10MEParams *pMEParams,
+    OMX_U32 *pSize
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_MEInit   (6.3.5.1.2)
+ *
+ * Description:
+ * Initializes the vendor-specific specification structure required for the 
+ * omxVCM4P10 motion estimation functions:  BlockMatch_Integer and 
+ * MotionEstimationMB. Memory for the specification structure *pMESpec must be 
+ * allocated prior to calling the function, and should be aligned on a 4-byte 
+ * boundary.  The number of bytes required for the specification structure can 
+ * be determined using the function omxVCM4P10_MEGetBufSize. Following 
+ * initialization by this function, the vendor-specific structure *pMESpec 
+ * should contain an implementation-specific representation of all motion 
+ * estimation parameters received via the structure pMEParams, for example  
+ * searchRange16x16, searchRange8x8, etc. 
+ *
+ * Input Arguments:
+ *   
+ *   MEmode - motion estimation mode; available modes are defined by the 
+ *            enumerated type OMXVCM4P10MEMode 
+ *   pMEParams - motion estimation parameters 
+ *   pMESpec - pointer to the uninitialized ME specification structure 
+ *
+ * Output Arguments:
+ *   
+ *   pMESpec - pointer to the initialized ME specification structure 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    pMEParams or pSize is NULL. 
+ *    -    an invalid value was specified for the parameter MEmode 
+ *    -    a negative or zero value was specified for one of the search ranges 
+ *         (e.g.,  pMBParams >searchRange8x8, pMEParams->searchRange16x16, etc.) 
+ *    -    either in isolation or in combination, one or more of the enables or 
+ *         search ranges in the structure *pMEParams were configured such 
+ *         that the requested behavior fails to comply with [ISO14496-10]. 
+ *
+ */
+OMXResult omxVCM4P10_MEInit (
+    OMXVCM4P10MEMode MEmode,
+    const OMXVCM4P10MEParams *pMEParams,
+    void *pMESpec
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_BlockMatch_Integer   (6.3.5.2.1)
+ *
+ * Description:
+ * Performs integer block match.  Returns best MV and associated cost. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcOrgY - Pointer to the top-left corner of the current block:
+ *            If iBlockWidth==4,  4-byte alignment required. 
+ *            If iBlockWidth==8,  8-byte alignment required. 
+ *            If iBlockWidth==16, 16-byte alignment required. 
+ *   pSrcRefY - Pointer to the top-left corner of the co-located block in the 
+ *            reference picture: 
+ *            If iBlockWidth==4,  4-byte alignment required.  
+ *            If iBlockWidth==8,  8-byte alignment required.  
+ *            If iBlockWidth==16, 16-byte alignment required. 
+ *   nSrcOrgStep - Stride of the original picture plane, expressed in terms 
+ *            of integer pixels; must be a multiple of iBlockWidth. 
+ *   nSrcRefStep - Stride of the reference picture plane, expressed in terms 
+ *            of integer pixels 
+ *   pRefRect - pointer to the valid reference rectangle inside the reference 
+ *            picture plane 
+ *   nCurrPointPos - position of the current block in the current plane 
+ *   iBlockWidth - Width of the current block, expressed in terms of integer 
+ *            pixels; must be equal to either 4, 8, or 16. 
+ *   iBlockHeight - Height of the current block, expressed in terms of 
+ *            integer pixels; must be equal to either 4, 8, or 16. 
+ *   nLamda - Lamda factor; used to compute motion cost 
+ *   pMVPred - Predicted MV; used to compute motion cost, expressed in terms 
+ *            of 1/4-pel units 
+ *   pMVCandidate - Candidate MV; used to initialize the motion search, 
+ *            expressed in terms of integer pixels 
+ *   pMESpec - pointer to the ME specification structure 
+ *
+ * Output Arguments:
+ *   
+ *   pDstBestMV - Best MV resulting from integer search, expressed in terms 
+ *            of 1/4-pel units 
+ *   pBestCost - Motion cost associated with the best MV; computed as 
+ *            SAD+Lamda*BitsUsedByMV 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    any of the following pointers are NULL:
+ *         pSrcOrgY, pSrcRefY, pRefRect, pMVPred, pMVCandidate, or pMESpec. 
+ *    -    Either iBlockWidth or iBlockHeight are values other than 4, 8, or 16. 
+ *    -    Any alignment restrictions are violated 
+ *
+ */
+OMXResult omxVCM4P10_BlockMatch_Integer (
+    const OMX_U8 *pSrcOrgY,
+    OMX_S32 nSrcOrgStep,
+    const OMX_U8 *pSrcRefY,
+    OMX_S32 nSrcRefStep,
+    const OMXRect *pRefRect,
+    const OMXVCM4P2Coordinate *pCurrPointPos,
+    OMX_U8 iBlockWidth,
+    OMX_U8 iBlockHeight,
+    OMX_U32 nLamda,
+    const OMXVCMotionVector *pMVPred,
+    const OMXVCMotionVector *pMVCandidate,
+    OMXVCMotionVector *pBestMV,
+    OMX_S32 *pBestCost,
+    void *pMESpec
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_BlockMatch_Half   (6.3.5.2.2)
+ *
+ * Description:
+ * Performs a half-pel block match using results from a prior integer search. 
+ *  Returns the best MV and associated cost.  This function estimates the 
+ * half-pixel motion vector by interpolating the integer resolution motion 
+ * vector referenced by the input parameter pSrcDstBestMV, i.e., the initial 
+ * integer MV is generated externally.  The function 
+ * omxVCM4P10_BlockMatch_Integer may be used for integer motion estimation. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcOrgY - Pointer to the current position in original picture plane:
+ *              If iBlockWidth==4,  4-byte alignment required. 
+ *              If iBlockWidth==8,  8-byte alignment required. 
+ *              If iBlockWidth==16, 16-byte alignment required. 
+ *   pSrcRefY - Pointer to the top-left corner of the co-located block in the 
+ *            reference picture:  
+ *              If iBlockWidth==4,  4-byte alignment required.  
+ *              If iBlockWidth==8,  8-byte alignment required.  
+ *              If iBlockWidth==16, 16-byte alignment required. 
+ *   nSrcOrgStep - Stride of the original picture plane in terms of full 
+ *            pixels; must be a multiple of iBlockWidth. 
+ *   nSrcRefStep - Stride of the reference picture plane in terms of full 
+ *            pixels 
+ *   iBlockWidth - Width of the current block in terms of full pixels; must 
+ *            be equal to either 4, 8, or 16. 
+ *   iBlockHeight - Height of the current block in terms of full pixels; must 
+ *            be equal to either 4, 8, or 16. 
+ *   nLamda - Lamda factor, used to compute motion cost 
+ *   pMVPred - Predicted MV, represented in terms of 1/4-pel units; used to 
+ *            compute motion cost 
+ *   pSrcDstBestMV - The best MV resulting from a prior integer search, 
+ *            represented in terms of 1/4-pel units 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDstBestMV - Best MV resulting from the half-pel search, expressed in 
+ *            terms of 1/4-pel units 
+ *   pBestCost - Motion cost associated with the best MV; computed as 
+ *            SAD+Lamda*BitsUsedByMV 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    any of the following pointers is NULL: pSrcOrgY, pSrcRefY, 
+ *              pSrcDstBestMV, pMVPred, pBestCost 
+ *    -    iBlockWidth or iBlockHeight are equal to values other than 4, 8, or 16. 
+ *    -    Any alignment restrictions are violated 
+ *
+ */
+OMXResult omxVCM4P10_BlockMatch_Half (
+    const OMX_U8 *pSrcOrgY,
+    OMX_S32 nSrcOrgStep,
+    const OMX_U8 *pSrcRefY,
+    OMX_S32 nSrcRefStep,
+    OMX_U8 iBlockWidth,
+    OMX_U8 iBlockHeight,
+    OMX_U32 nLamda,
+    const OMXVCMotionVector *pMVPred,
+    OMXVCMotionVector *pSrcDstBestMV,
+    OMX_S32 *pBestCost
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_BlockMatch_Quarter   (6.3.5.2.3)
+ *
+ * Description:
+ * Performs a quarter-pel block match using results from a prior half-pel 
+ * search.  Returns the best MV and associated cost.  This function estimates 
+ * the quarter-pixel motion vector by interpolating the half-pel resolution 
+ * motion vector referenced by the input parameter pSrcDstBestMV, i.e., the 
+ * initial half-pel MV is generated externally.  The function 
+ * omxVCM4P10_BlockMatch_Half may be used for half-pel motion estimation. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcOrgY - Pointer to the current position in original picture plane:
+ *            If iBlockWidth==4,  4-byte alignment required. 
+ *            If iBlockWidth==8,  8-byte alignment required. 
+ *            If iBlockWidth==16, 16-byte alignment required. 
+ *   pSrcRefY - Pointer to the top-left corner of the co-located block in the 
+ *            reference picture:
+ *            If iBlockWidth==4,  4-byte alignment required.  
+ *            If iBlockWidth==8,  8-byte alignment required.  
+ *            If iBlockWidth==16, 16-byte alignment required. 
+ *   nSrcOrgStep - Stride of the original picture plane in terms of full 
+ *            pixels; must be a multiple of iBlockWidth. 
+ *   nSrcRefStep - Stride of the reference picture plane in terms of full 
+ *            pixels 
+ *   iBlockWidth - Width of the current block in terms of full pixels; must 
+ *            be equal to either 4, 8, or 16. 
+ *   iBlockHeight - Height of the current block in terms of full pixels; must 
+ *            be equal to either 4, 8, or 16. 
+ *   nLamda - Lamda factor, used to compute motion cost 
+ *   pMVPred - Predicted MV, represented in terms of 1/4-pel units; used to 
+ *            compute motion cost 
+ *   pSrcDstBestMV - The best MV resulting from a prior half-pel search, 
+ *            represented in terms of 1/4 pel units 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDstBestMV - Best MV resulting from the quarter-pel search, expressed 
+ *            in terms of 1/4-pel units 
+ *   pBestCost - Motion cost associated with the best MV; computed as 
+ *            SAD+Lamda*BitsUsedByMV 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    One or more of the following pointers is NULL: 
+ *         pSrcOrgY, pSrcRefY, pSrcDstBestMV, pMVPred, pBestCost 
+ *    -    iBlockWidth or iBlockHeight are equal to values other than 4, 8, or 16. 
+ *    -    Any alignment restrictions are violated 
+ *
+ */
+OMXResult omxVCM4P10_BlockMatch_Quarter (
+    const OMX_U8 *pSrcOrgY,
+    OMX_S32 nSrcOrgStep,
+    const OMX_U8 *pSrcRefY,
+    OMX_S32 nSrcRefStep,
+    OMX_U8 iBlockWidth,
+    OMX_U8 iBlockHeight,
+    OMX_U32 nLamda,
+    const OMXVCMotionVector *pMVPred,
+    OMXVCMotionVector *pSrcDstBestMV,
+    OMX_S32 *pBestCost
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_MotionEstimationMB   (6.3.5.3.1)
+ *
+ * Description:
+ * Performs MB-level motion estimation and selects best motion estimation 
+ * strategy from the set of modes supported in baseline profile [ISO14496-10]. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcCurrBuf - Pointer to the current position in original picture plane; 
+ *            16-byte alignment required 
+ *   pSrcRefBufList - Pointer to an array with 16 entries.  Each entry points 
+ *            to the top-left corner of the co-located MB in a reference 
+ *            picture.  The array is filled from low-to-high with valid 
+ *            reference frame pointers; the unused high entries should be set 
+ *            to NULL.  Ordering of the reference frames should follow 
+ *            [ISO14496-10] subclause 8.2.4  Decoding Process for Reference 
+ *            Picture Lists.   The entries must be 16-byte aligned. 
+ *   pSrcRecBuf - Pointer to the top-left corner of the co-located MB in the 
+ *            reconstructed picture; must be 16-byte aligned. 
+ *   SrcCurrStep - Width of the original picture plane in terms of full 
+ *            pixels; must be a multiple of 16. 
+ *   SrcRefStep - Width of the reference picture plane in terms of full 
+ *            pixels; must be a multiple of 16. 
+ *   SrcRecStep - Width of the reconstructed picture plane in terms of full 
+ *            pixels; must be a multiple of 16. 
+ *   pRefRect - Pointer to the valid reference rectangle; relative to the 
+ *            image origin. 
+ *   pCurrPointPos - Position of the current macroblock in the current plane. 
+ *   Lambda - Lagrange factor for computing the cost function 
+ *   pMESpec - Pointer to the motion estimation specification structure; must 
+ *            have been allocated and initialized prior to calling this 
+ *            function. 
+ *   pMBInter - Array, of dimension four, containing pointers to information 
+ *            associated with four adjacent type INTER MBs (Left, Top, 
+ *            Top-Left, Top-Right). Any pointer in the array may be set equal 
+ *            to NULL if the corresponding MB doesn t exist or is not of type 
+ *            INTER. 
+ *            -  pMBInter[0] - Pointer to left MB information 
+ *            -  pMBInter[1] - Pointer to top MB information 
+ *            -  pMBInter[2] - Pointer to top-left MB information 
+ *            -  pMBInter[3] - Pointer to top-right MB information 
+ *   pMBIntra - Array, of dimension four, containing pointers to information 
+ *            associated with four adjacent type INTRA MBs (Left, Top, 
+ *            Top-Left, Top-Right). Any pointer in the array may be set equal 
+ *            to NULL if the corresponding MB doesn t exist or is not of type 
+ *            INTRA. 
+ *            -  pMBIntra[0] - Pointer to left MB information 
+ *            -  pMBIntra[1] - Pointer to top MB information 
+ *            -  pMBIntra[2] - Pointer to top-left MB information 
+ *            -  pMBIntra[3] - Pointer to top-right MB information 
+ *   pSrcDstMBCurr - Pointer to information structure for the current MB.  
+ *            The following entries should be set prior to calling the 
+ *            function:  sliceID - the number of the slice the to which the 
+ *            current MB belongs. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstCost - Pointer to the minimum motion cost for the current MB. 
+ *   pDstBlockSAD - Pointer to the array of SADs for each of the sixteen luma 
+ *            4x4 blocks in each MB.  The block SADs are in scan order for 
+ *            each MB.  For implementations that cannot compute the SAD values 
+ *            individually, the maximum possible value (0xffff) is returned 
+ *            for each of the 16 block SAD entries. 
+ *   pSrcDstMBCurr - Pointer to updated information structure for the current 
+ *            MB after MB-level motion estimation has been completed.  The 
+ *            following fields are updated by the ME function.   The following 
+ *            parameter set quantifies the MB-level ME search results: 
+ *            -  MbType 
+ *            -  subMBType[4] 
+ *            -  pMV0[4][4] 
+ *            -  pMVPred[4][4] 
+ *            -  pRefL0Idx[4] 
+ *            -  Intra16x16PredMode 
+ *            -  pIntra4x4PredMode[4][4] 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -   One or more of the following pointers is NULL: pSrcCurrBuf, 
+ *           pSrcRefBufList, pSrcRecBuf, pRefRect, pCurrPointPos, pMESpec, 
+ *           pMBInter, pMBIntra,pSrcDstMBCurr, pDstCost, pSrcRefBufList[0] 
+ *    -    SrcRefStep, SrcRecStep are not multiples of 16 
+ *    -    iBlockWidth or iBlockHeight are values other than 4, 8, or 16. 
+ *    -    Any alignment restrictions are violated 
+ *
+ */
+OMXResult omxVCM4P10_MotionEstimationMB (
+    const OMX_U8 *pSrcCurrBuf,
+    OMX_S32 SrcCurrStep,
+    const OMX_U8 *pSrcRefBufList[15],
+    OMX_S32 SrcRefStep,
+    const OMX_U8 *pSrcRecBuf,
+    OMX_S32 SrcRecStep,
+    const OMXRect *pRefRect,
+    const OMXVCM4P2Coordinate *pCurrPointPos,
+    OMX_U32 Lambda,
+    void *pMESpec,
+    const OMXVCM4P10MBInfoPtr *pMBInter,
+    const OMXVCM4P10MBInfoPtr *pMBIntra,
+    OMXVCM4P10MBInfoPtr pSrcDstMBCurr,
+    OMX_INT *pDstCost,
+    OMX_U16 *pDstBlockSAD
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_SAD_4x   (6.3.5.4.1)
+ *
+ * Description:
+ * This function calculates the SAD for 4x8 and 4x4 blocks. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcOrg -Pointer to the original block; must be aligned on a 4-byte 
+ *            boundary. 
+ *   iStepOrg -Step of the original block buffer; must be a multiple of 4. 
+ *   pSrcRef -Pointer to the reference block 
+ *   iStepRef -Step of the reference block buffer 
+ *   iHeight -Height of the block; must be equal to either 4 or 8. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstSAD -Pointer of result SAD 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    One or more of the following pointers is NULL: 
+ *         pSrcOrg, pSrcRef, or pDstSAD 
+ *    -    iHeight is not equal to either 4 or 8. 
+ *    -    iStepOrg is not a multiple of 4 
+ *    -    Any alignment restrictions are violated 
+ *
+ */
+OMXResult omxVCM4P10_SAD_4x (
+    const OMX_U8 *pSrcOrg,
+    OMX_U32 iStepOrg,
+    const OMX_U8 *pSrcRef,
+    OMX_U32 iStepRef,
+    OMX_S32 *pDstSAD,
+    OMX_U32 iHeight
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_SADQuar_4x   (6.3.5.4.2)
+ *
+ * Description:
+ * This function calculates the SAD between one block (pSrc) and the average 
+ * of the other two (pSrcRef0 and pSrcRef1) for 4x8 or 4x4 blocks.  Rounding 
+ * is applied according to the convention (a+b+1)>>1. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - Pointer to the original block; must be aligned on a 4-byte 
+ *            boundary. 
+ *   pSrcRef0 - Pointer to reference block 0 
+ *   pSrcRef1 - Pointer to reference block 1 
+ *   iSrcStep - Step of the original block buffer; must be a multiple of 4. 
+ *   iRefStep0 - Step of reference block 0 
+ *   iRefStep1 - Step of reference block 1 
+ *   iHeight - Height of the block; must be equal to either 4 or 8. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstSAD - Pointer of result SAD 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    iHeight is not equal to either 4 or 8. 
+ *    -    One or more of the following pointers is NULL: pSrc, pSrcRef0, 
+ *              pSrcRef1, pDstSAD. 
+ *    -    iSrcStep is not a multiple of 4 
+ *    -    Any alignment restrictions are violated 
+ *
+ */
+OMXResult omxVCM4P10_SADQuar_4x (
+    const OMX_U8 *pSrc,
+    const OMX_U8 *pSrcRef0,
+    const OMX_U8 *pSrcRef1,
+    OMX_U32 iSrcStep,
+    OMX_U32 iRefStep0,
+    OMX_U32 iRefStep1,
+    OMX_U32 *pDstSAD,
+    OMX_U32 iHeight
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_SADQuar_8x   (6.3.5.4.3)
+ *
+ * Description:
+ * This function calculates the SAD between one block (pSrc) and the average 
+ * of the other two (pSrcRef0 and pSrcRef1) for 8x16, 8x8, or 8x4 blocks.  
+ * Rounding is applied according to the convention (a+b+1)>>1. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - Pointer to the original block; must be aligned on an 8-byte 
+ *            boundary. 
+ *   pSrcRef0 - Pointer to reference block 0 
+ *   pSrcRef1 - Pointer to reference block 1 
+ *   iSrcStep - Step of the original block buffer; must be a multiple of 8. 
+ *   iRefStep0 - Step of reference block 0 
+ *   iRefStep1 - Step of reference block 1 
+ *   iHeight - Height of the block; must be equal either 4, 8, or 16. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstSAD - Pointer of result SAD 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    iHeight is not equal to either 4, 8, or 16. 
+ *    -    One or more of the following pointers is NULL: pSrc, pSrcRef0, 
+ *              pSrcRef1, pDstSAD. 
+ *    -    iSrcStep is not a multiple of 8 
+ *    -    Any alignment restrictions are violated 
+ *
+ */
+OMXResult omxVCM4P10_SADQuar_8x (
+    const OMX_U8 *pSrc,
+    const OMX_U8 *pSrcRef0,
+    const OMX_U8 *pSrcRef1,
+    OMX_U32 iSrcStep,
+    OMX_U32 iRefStep0,
+    OMX_U32 iRefStep1,
+    OMX_U32 *pDstSAD,
+    OMX_U32 iHeight
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_SADQuar_16x   (6.3.5.4.4)
+ *
+ * Description:
+ * This function calculates the SAD between one block (pSrc) and the average 
+ * of the other two (pSrcRef0 and pSrcRef1) for 16x16 or 16x8 blocks.  
+ * Rounding is applied according to the convention (a+b+1)>>1. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - Pointer to the original block; must be aligned on a 16-byte 
+ *            boundary. 
+ *   pSrcRef0 - Pointer to reference block 0 
+ *   pSrcRef1 - Pointer to reference block 1 
+ *   iSrcStep - Step of the original block buffer; must be a multiple of 16 
+ *   iRefStep0 - Step of reference block 0 
+ *   iRefStep1 - Step of reference block 1 
+ *   iHeight - Height of the block; must be equal to either 8 or 16 
+ *
+ * Output Arguments:
+ *   
+ *   pDstSAD -Pointer of result SAD 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    iHeight is not equal to either 8 or 16. 
+ *    -    One or more of the following pointers is NULL: pSrc, pSrcRef0, 
+ *              pSrcRef1, pDstSAD. 
+ *    -    iSrcStep is not a multiple of 16 
+ *    -    Any alignment restrictions are violated 
+ *
+ */
+OMXResult omxVCM4P10_SADQuar_16x (
+    const OMX_U8 *pSrc,
+    const OMX_U8 *pSrcRef0,
+    const OMX_U8 *pSrcRef1,
+    OMX_U32 iSrcStep,
+    OMX_U32 iRefStep0,
+    OMX_U32 iRefStep1,
+    OMX_U32 *pDstSAD,
+    OMX_U32 iHeight
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_SATD_4x4   (6.3.5.4.5)
+ *
+ * Description:
+ * This function calculates the sum of absolute transform differences (SATD) 
+ * for a 4x4 block by applying a Hadamard transform to the difference block 
+ * and then calculating the sum of absolute coefficient values. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcOrg - Pointer to the original block; must be aligned on a 4-byte 
+ *            boundary 
+ *   iStepOrg - Step of the original block buffer; must be a multiple of 4 
+ *   pSrcRef - Pointer to the reference block; must be aligned on a 4-byte 
+ *            boundary 
+ *   iStepRef - Step of the reference block buffer; must be a multiple of 4 
+ *
+ * Output Arguments:
+ *   
+ *   pDstSAD - pointer to the resulting SAD 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: 
+ *         pSrcOrg, pSrcRef, or pDstSAD either pSrcOrg 
+ *    -    pSrcRef is not aligned on a 4-byte boundary 
+ *    -    iStepOrg <= 0 or iStepOrg is not a multiple of 4 
+ *    -    iStepRef <= 0 or iStepRef is not a multiple of 4 
+ *
+ */
+OMXResult omxVCM4P10_SATD_4x4 (
+    const OMX_U8 *pSrcOrg,
+    OMX_U32 iStepOrg,
+    const OMX_U8 *pSrcRef,
+    OMX_U32 iStepRef,
+    OMX_U32 *pDstSAD
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_InterpolateHalfHor_Luma   (6.3.5.5.1)
+ *
+ * Description:
+ * This function performs interpolation for two horizontal 1/2-pel positions 
+ * (-1/2,0) and (1/2, 0) - around a full-pel position. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - Pointer to the top-left corner of the block used to interpolate in 
+ *            the reconstruction frame plane. 
+ *   iSrcStep - Step of the source buffer. 
+ *   iDstStep - Step of the destination(interpolation) buffer; must be a 
+ *            multiple of iWidth. 
+ *   iWidth - Width of the current block; must be equal to either 4, 8, or 16 
+ *   iHeight - Height of the current block; must be equal to 4, 8, or 16 
+ *
+ * Output Arguments:
+ *   
+ *   pDstLeft -Pointer to the interpolation buffer of the left -pel position 
+ *            (-1/2, 0) 
+ *                 If iWidth==4,  4-byte alignment required. 
+ *                 If iWidth==8,  8-byte alignment required. 
+ *                 If iWidth==16, 16-byte alignment required. 
+ *   pDstRight -Pointer to the interpolation buffer of the right -pel 
+ *            position (1/2, 0) 
+ *                 If iWidth==4,  4-byte alignment required. 
+ *                 If iWidth==8,  8-byte alignment required. 
+ *                 If iWidth==16, 16-byte alignment required. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: 
+ *             pSrc, pDstLeft, or pDstRight 
+ *    -    iWidth or iHeight have values other than 4, 8, or 16 
+ *    -    iWidth==4 but pDstLeft and/or pDstRight is/are not aligned on a 4-byte boundary 
+ *    -    iWidth==8 but pDstLeft and/or pDstRight is/are not aligned on a 8-byte boundary 
+ *    -    iWidth==16 but pDstLeft and/or pDstRight is/are not aligned on a 16-byte boundary 
+ *    -    any alignment restrictions are violated 
+ *
+ */
+OMXResult omxVCM4P10_InterpolateHalfHor_Luma (
+    const OMX_U8 *pSrc,
+    OMX_U32 iSrcStep,
+    OMX_U8 *pDstLeft,
+    OMX_U8 *pDstRight,
+    OMX_U32 iDstStep,
+    OMX_U32 iWidth,
+    OMX_U32 iHeight
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_InterpolateHalfVer_Luma   (6.3.5.5.2)
+ *
+ * Description:
+ * This function performs interpolation for two vertical 1/2-pel positions - 
+ * (0, -1/2) and (0, 1/2) - around a full-pel position. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - Pointer to top-left corner of block used to interpolate in the 
+ *            reconstructed frame plane 
+ *   iSrcStep - Step of the source buffer. 
+ *   iDstStep - Step of the destination (interpolation) buffer; must be a 
+ *            multiple of iWidth. 
+ *   iWidth - Width of the current block; must be equal to either 4, 8, or 16 
+ *   iHeight - Height of the current block; must be equal to either 4, 8, or 16 
+ *
+ * Output Arguments:
+ *   
+ *   pDstUp -Pointer to the interpolation buffer of the -pel position above 
+ *            the current full-pel position (0, -1/2) 
+ *                If iWidth==4, 4-byte alignment required. 
+ *                If iWidth==8, 8-byte alignment required. 
+ *                If iWidth==16, 16-byte alignment required. 
+ *   pDstDown -Pointer to the interpolation buffer of the -pel position below 
+ *            the current full-pel position (0, 1/2) 
+ *                If iWidth==4, 4-byte alignment required. 
+ *                If iWidth==8, 8-byte alignment required. 
+ *                If iWidth==16, 16-byte alignment required. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: 
+ *            pSrc, pDstUp, or pDstDown 
+ *    -    iWidth or iHeight have values other than 4, 8, or 16 
+ *    -    iWidth==4 but pDstUp and/or pDstDown is/are not aligned on a 4-byte boundary 
+ *    -    iWidth==8 but pDstUp and/or pDstDown is/are not aligned on a 8-byte boundary 
+ *    -    iWidth==16 but pDstUp and/or pDstDown is/are not aligned on a 16-byte boundary 
+ *
+ */
+OMXResult omxVCM4P10_InterpolateHalfVer_Luma (
+    const OMX_U8 *pSrc,
+    OMX_U32 iSrcStep,
+    OMX_U8 *pDstUp,
+    OMX_U8 *pDstDown,
+    OMX_U32 iDstStep,
+    OMX_U32 iWidth,
+    OMX_U32 iHeight
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_Average_4x   (6.3.5.5.3)
+ *
+ * Description:
+ * This function calculates the average of two 4x4, 4x8 blocks.  The result 
+ * is rounded according to (a+b+1)/2. 
+ *
+ * Input Arguments:
+ *   
+ *   pPred0 - Pointer to the top-left corner of reference block 0 
+ *   pPred1 - Pointer to the top-left corner of reference block 1 
+ *   iPredStep0 - Step of reference block 0; must be a multiple of 4. 
+ *   iPredStep1 - Step of reference block 1; must be a multiple of 4. 
+ *   iDstStep - Step of the destination buffer; must be a multiple of 4. 
+ *   iHeight - Height of the blocks; must be either 4 or 8. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstPred - Pointer to the destination buffer. 4-byte alignment required. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: 
+ *           pPred0, pPred1, or pDstPred 
+ *    -    pDstPred is not aligned on a 4-byte boundary 
+ *    -    iPredStep0 <= 0 or iPredStep0 is not a multiple of 4 
+ *    -    iPredStep1 <= 0 or iPredStep1 is not a multiple of 4 
+ *    -    iDstStep <= 0 or iDstStep is not a multiple of 4 
+ *    -    iHeight is not equal to either 4 or 8 
+ *
+ */
+OMXResult omxVCM4P10_Average_4x (
+    const OMX_U8 *pPred0,
+    const OMX_U8 *pPred1,
+    OMX_U32 iPredStep0,
+    OMX_U32 iPredStep1,
+    OMX_U8 *pDstPred,
+    OMX_U32 iDstStep,
+    OMX_U32 iHeight
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_TransformQuant_ChromaDC   (6.3.5.6.1)
+ *
+ * Description:
+ * This function performs 2x2 Hadamard transform of chroma DC coefficients 
+ * and then quantizes the coefficients. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - Pointer to the 2x2 array of chroma DC coefficients.  8-byte 
+ *            alignment required. 
+ *   iQP - Quantization parameter; must be in the range [0,51]. 
+ *   bIntra - Indicate whether this is an INTRA block. 1-INTRA, 0-INTER 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst - Pointer to transformed and quantized coefficients.  8-byte 
+ *            alignment required. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: 
+ *             pSrcDst 
+ *    -    pSrcDst is not aligned on an 8-byte boundary 
+ *
+ */
+OMXResult omxVCM4P10_TransformQuant_ChromaDC (
+    OMX_S16 *pSrcDst,
+    OMX_U32 iQP,
+    OMX_U8 bIntra
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_TransformQuant_LumaDC   (6.3.5.6.2)
+ *
+ * Description:
+ * This function performs a 4x4 Hadamard transform of luma DC coefficients 
+ * and then quantizes the coefficients. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - Pointer to the 4x4 array of luma DC coefficients.  16-byte 
+ *            alignment required. 
+ *   iQP - Quantization parameter; must be in the range [0,51]. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst - Pointer to transformed and quantized coefficients.  16-byte 
+ *             alignment required. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: pSrcDst 
+ *    -    pSrcDst is not aligned on an 16-byte boundary 
+ *
+ */
+OMXResult omxVCM4P10_TransformQuant_LumaDC (
+    OMX_S16 *pSrcDst,
+    OMX_U32 iQP
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_InvTransformDequant_LumaDC   (6.3.5.6.3)
+ *
+ * Description:
+ * This function performs inverse 4x4 Hadamard transform and then dequantizes 
+ * the coefficients. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - Pointer to the 4x4 array of the 4x4 Hadamard-transformed and 
+ *            quantized coefficients.  16 byte alignment required. 
+ *   iQP - Quantization parameter; must be in the range [0,51]. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - Pointer to inverse-transformed and dequantized coefficients.  
+ *            16-byte alignment required. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: pSrc 
+ *    -    pSrc or pDst is not aligned on a 16-byte boundary 
+ *
+ */
+OMXResult omxVCM4P10_InvTransformDequant_LumaDC (
+    const OMX_S16 *pSrc,
+    OMX_S16 *pDst,
+    OMX_U32 iQP
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_InvTransformDequant_ChromaDC   (6.3.5.6.4)
+ *
+ * Description:
+ * This function performs inverse 2x2 Hadamard transform and then dequantizes 
+ * the coefficients. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - Pointer to the 2x2 array of the 2x2 Hadamard-transformed and 
+ *            quantized coefficients.  8 byte alignment required. 
+ *   iQP - Quantization parameter; must be in the range [0,51]. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - Pointer to inverse-transformed and dequantized coefficients.  
+ *            8-byte alignment required. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: pSrc 
+ *    -    pSrc or pDst is not aligned on an 8-byte boundary 
+ *
+ */
+OMXResult omxVCM4P10_InvTransformDequant_ChromaDC (
+    const OMX_S16 *pSrc,
+    OMX_S16 *pDst,
+    OMX_U32 iQP
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_InvTransformResidualAndAdd   (6.3.5.7.1)
+ *
+ * Description:
+ * This function performs inverse an 4x4 integer transformation to produce 
+ * the difference signal and then adds the difference to the prediction to get 
+ * the reconstructed signal. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcPred - Pointer to prediction signal.  4-byte alignment required. 
+ *   pDequantCoeff - Pointer to the transformed coefficients.  8-byte 
+ *            alignment required. 
+ *   iSrcPredStep - Step of the prediction buffer; must be a multiple of 4. 
+ *   iDstReconStep - Step of the destination reconstruction buffer; must be a 
+ *            multiple of 4. 
+ *   bAC - Indicate whether there is AC coefficients in the coefficients 
+ *            matrix. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstRecon -Pointer to the destination reconstruction buffer.  4-byte 
+ *            alignment required. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: 
+ *            pSrcPred, pDequantCoeff, pDstRecon 
+ *    -    pSrcPred is not aligned on a 4-byte boundary 
+ *    -    iSrcPredStep or iDstReconStep is not a multiple of 4. 
+ *    -    pDequantCoeff is not aligned on an 8-byte boundary 
+ *
+ */
+OMXResult omxVCM4P10_InvTransformResidualAndAdd (
+    const OMX_U8 *pSrcPred,
+    const OMX_S16 *pDequantCoeff,
+    OMX_U8 *pDstRecon,
+    OMX_U32 iSrcPredStep,
+    OMX_U32 iDstReconStep,
+    OMX_U8 bAC
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_SubAndTransformQDQResidual   (6.3.5.8.1)
+ *
+ * Description:
+ * This function subtracts the prediction signal from the original signal to 
+ * produce the difference signal and then performs a 4x4 integer transform and 
+ * quantization. The quantized transformed coefficients are stored as 
+ * pDstQuantCoeff. This function can also output dequantized coefficients or 
+ * unquantized DC coefficients optionally by setting the pointers 
+ * pDstDeQuantCoeff, pDCCoeff. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcOrg - Pointer to original signal. 4-byte alignment required. 
+ *   pSrcPred - Pointer to prediction signal. 4-byte alignment required. 
+ *   iSrcOrgStep - Step of the original signal buffer; must be a multiple of 
+ *            4. 
+ *   iSrcPredStep - Step of the prediction signal buffer; must be a multiple 
+ *            of 4. 
+ *   pNumCoeff -Number of non-zero coefficients after quantization. If this 
+ *            parameter is not required, it is set to NULL. 
+ *   nThreshSAD - Zero-block early detection threshold. If this parameter is 
+ *            not required, it is set to 0. 
+ *   iQP - Quantization parameter; must be in the range [0,51]. 
+ *   bIntra - Indicates whether this is an INTRA block, either 1-INTRA or 
+ *            0-INTER 
+ *
+ * Output Arguments:
+ *   
+ *   pDstQuantCoeff - Pointer to the quantized transformed coefficients.  
+ *            8-byte alignment required. 
+ *   pDstDeQuantCoeff - Pointer to the dequantized transformed coefficients 
+ *            if this parameter is not equal to NULL.  8-byte alignment 
+ *            required. 
+ *   pDCCoeff - Pointer to the unquantized DC coefficient if this parameter 
+ *            is not equal to NULL. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: 
+ *            pSrcOrg, pSrcPred, pNumCoeff, pDstQuantCoeff, 
+ *            pDstDeQuantCoeff, pDCCoeff 
+ *    -    pSrcOrg is not aligned on a 4-byte boundary 
+ *    -    pSrcPred is not aligned on a 4-byte boundary 
+ *    -    iSrcOrgStep is not a multiple of 4 
+ *    -    iSrcPredStep is not a multiple of 4 
+ *    -    pDstQuantCoeff or pDstDeQuantCoeff is not aligned on an 8-byte boundary 
+ *
+ */
+OMXResult omxVCM4P10_SubAndTransformQDQResidual (
+    const OMX_U8 *pSrcOrg,
+    const OMX_U8 *pSrcPred,
+    OMX_U32 iSrcOrgStep,
+    OMX_U32 iSrcPredStep,
+    OMX_S16 *pDstQuantCoeff,
+    OMX_S16 *pDstDeQuantCoeff,
+    OMX_S16 *pDCCoeff,
+    OMX_S8 *pNumCoeff,
+    OMX_U32 nThreshSAD,
+    OMX_U32 iQP,
+    OMX_U8 bIntra
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_GetVLCInfo   (6.3.5.9.1)
+ *
+ * Description:
+ * This function extracts run-length encoding (RLE) information from the 
+ * coefficient matrix.  The results are returned in an OMXVCM4P10VLCInfo 
+ * structure. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcCoeff - pointer to the transform coefficient matrix.  8-byte 
+ *            alignment required. 
+ *   pScanMatrix - pointer to the scan order definition matrix.  For a luma 
+ *            block the scan matrix should follow [ISO14496-10] section 8.5.4, 
+ *            and should contain the values 0, 1, 4, 8, 5, 2, 3, 6, 9, 12, 13, 
+ *            10, 7, 11, 14, 15.  For a chroma block, the scan matrix should 
+ *            contain the values 0, 1, 2, 3. 
+ *   bAC - indicates presence of a DC coefficient; 0 = DC coefficient 
+ *            present, 1= DC coefficient absent. 
+ *   MaxNumCoef - specifies the number of coefficients contained in the 
+ *            transform coefficient matrix, pSrcCoeff. The value should be 16 
+ *            for blocks of type LUMADC, LUMAAC, LUMALEVEL, and CHROMAAC. The 
+ *            value should be 4 for blocks of type CHROMADC. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstVLCInfo - pointer to structure that stores information for 
+ *            run-length coding. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: 
+ *            pSrcCoeff, pScanMatrix, pDstVLCInfo 
+ *    -    pSrcCoeff is not aligned on an 8-byte boundary 
+ *
+ */
+OMXResult omxVCM4P10_GetVLCInfo (
+    const OMX_S16 *pSrcCoeff,
+    const OMX_U8 *pScanMatrix,
+    OMX_U8 bAC,
+    OMX_U32 MaxNumCoef,
+    OMXVCM4P10VLCInfo*pDstVLCInfo
+);
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /** end of #define _OMXVC_H_ */
+
+/** EOF */
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/api/omxVC_s.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/api/omxVC_s.h
new file mode 100755
index 0000000..89f3040
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/api/omxVC_s.h
@@ -0,0 +1,129 @@
+;/******************************************************************************
+;// Copyright (c) 1999-2005 The Khronos Group Inc. All Rights Reserved
+;//
+;//
+;//
+;//
+;//
+;//
+;//
+;//
+;******************************************************************************/
+
+;/** =============== Structure Definition for Sample Generation ============== */
+;/** transparent status */
+
+;enum {
+OMX_VIDEO_TRANSPARENT	EQU 0;	/** Wholly transparent */
+OMX_VIDEO_PARTIAL		EQU 1;	/** Partially transparent */
+OMX_VIDEO_OPAQUE		EQU 2;	/** Opaque */
+;}
+
+;/** direction */
+;enum {
+OMX_VIDEO_NONE			EQU 0;
+OMX_VIDEO_HORIZONTAL	EQU 1;
+OMX_VIDEO_VERTICAL		EQU 2;
+;}
+
+;/** bilinear interpolation type */
+;enum {
+OMX_VIDEO_INTEGER_PIXEL EQU 0;	/** case a */
+OMX_VIDEO_HALF_PIXEL_X  EQU 1;	/** case b */
+OMX_VIDEO_HALF_PIXEL_Y  EQU 2;	/** case c */
+OMX_VIDEO_HALF_PIXEL_XY EQU 3;	/** case d */
+;}
+
+;enum {
+OMX_UPPER  				EQU 1;		/** set if the above macroblock is available */
+OMX_LEFT   				EQU 2;		/** set if the left macroblock is available */
+OMX_CENTER 				EQU 4;
+OMX_RIGHT				EQU 8;
+OMX_LOWER  				EQU	16;
+OMX_UPPER_LEFT  		EQU 32;		/** set if the above-left macroblock is available */
+OMX_UPPER_RIGHT 		EQU 64;		/** set if the above-right macroblock is available */
+OMX_LOWER_LEFT  		EQU 128;
+OMX_LOWER_RIGHT 		EQU 256
+;}
+
+;enum {
+OMX_VIDEO_LUMINANCE  	EQU 0;	/** Luminance component */
+OMX_VIDEO_CHROMINANCE  	EQU 1;	/** chrominance component */
+OMX_VIDEO_ALPHA  		EQU 2;	/** Alpha component */
+;}
+
+;enum {
+OMX_VIDEO_INTER			EQU 0;	/** P picture or P-VOP */
+OMX_VIDEO_INTER_Q		EQU 1;	/** P picture or P-VOP */
+OMX_VIDEO_INTER4V		EQU 2;	/** P picture or P-VOP */
+OMX_VIDEO_INTRA			EQU 3;	/** I and P picture; I- and P-VOP */
+OMX_VIDEO_INTRA_Q		EQU 4;	/** I and P picture; I- and P-VOP */
+OMX_VIDEO_INTER4V_Q		EQU 5;	/** P picture or P-VOP (H.263)*/
+OMX_VIDEO_DIRECT		EQU 6;	/** B picture or B-VOP (MPEG-4 only) */
+OMX_VIDEO_INTERPOLATE	EQU 7;	/** B picture or B-VOP */
+OMX_VIDEO_BACKWARD		EQU 8;	/** B picture or B-VOP */
+OMX_VIDEO_FORWARD		EQU 9;	/** B picture or B-VOP */
+OMX_VIDEO_NOTCODED		EQU 10;	/** B picture or B-VOP */
+;}
+
+;enum {
+OMX_16X16_VERT 			EQU 0;		/** Intra_16x16_Vertical (prediction mode) */
+OMX_16X16_HOR 			EQU 1;		/** Intra_16x16_Horizontal (prediction mode) */
+OMX_16X16_DC 			EQU 2;		/** Intra_16x16_DC (prediction mode) */
+OMX_16X16_PLANE 		EQU 3;	/** Intra_16x16_Plane (prediction mode) */
+;}
+
+;enum {
+OMX_4x4_VERT 			EQU 0;		/** Intra_4x4_Vertical (prediction mode) */
+OMX_4x4_HOR  			EQU 1;		/** Intra_4x4_Horizontal (prediction mode) */
+OMX_4x4_DC   			EQU 2;		/** Intra_4x4_DC (prediction mode) */
+OMX_4x4_DIAG_DL 		EQU 3;	/** Intra_4x4_Diagonal_Down_Left (prediction mode) */
+OMX_4x4_DIAG_DR 		EQU 4;	/** Intra_4x4_Diagonal_Down_Right (prediction mode) */
+OMX_4x4_VR 				EQU 5;			/** Intra_4x4_Vertical_Right (prediction mode) */
+OMX_4x4_HD 				EQU 6;			/** Intra_4x4_Horizontal_Down (prediction mode) */
+OMX_4x4_VL 				EQU 7;			/** Intra_4x4_Vertical_Left (prediction mode) */
+OMX_4x4_HU 				EQU 8;			/** Intra_4x4_Horizontal_Up (prediction mode) */
+;}
+
+;enum {
+OMX_CHROMA_DC 			EQU 0;		/** Intra_Chroma_DC (prediction mode) */
+OMX_CHROMA_HOR 			EQU 1;		/** Intra_Chroma_Horizontal (prediction mode) */
+OMX_CHROMA_VERT 		EQU 2;	/** Intra_Chroma_Vertical (prediction mode) */
+OMX_CHROMA_PLANE 		EQU 3;	/** Intra_Chroma_Plane (prediction mode) */
+;}
+
+;typedef	struct {	
+x	EQU	0;
+y	EQU	4;
+;}OMXCoordinate;
+
+;typedef struct {
+dx	EQU	0;
+dy	EQU	2;
+;}OMXMotionVector;
+
+;typedef struct {
+xx		EQU	0;
+yy		EQU	4;
+width	EQU	8;
+height	EQU	12;
+;}OMXiRect;
+
+;typedef enum {
+OMX_VC_INTER         EQU 0;        /** P picture or P-VOP */
+OMX_VC_INTER_Q       EQU 1;       /** P picture or P-VOP */
+OMX_VC_INTER4V       EQU 2;       /** P picture or P-VOP */
+OMX_VC_INTRA         EQU 3;        /** I and P picture, I- and P-VOP */
+OMX_VC_INTRA_Q       EQU 4;       /** I and P picture, I- and P-VOP */
+OMX_VC_INTER4V_Q     EQU 5;    /** P picture or P-VOP (H.263)*/
+;} OMXVCM4P2MacroblockType;
+
+;enum {
+OMX_VC_NONE          EQU 0
+OMX_VC_HORIZONTAL    EQU 1
+OMX_VC_VERTICAL      EQU 2 
+;};
+
+
+	END
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/comm/src/omxVCCOMM_Copy16x16_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/comm/src/omxVCCOMM_Copy16x16_s.s
new file mode 100755
index 0000000..296d59d
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/comm/src/omxVCCOMM_Copy16x16_s.s
@@ -0,0 +1,95 @@
+ ;/**
+ ; * Function: omxVCCOMM_Copy16x16
+ ; *
+ ; * Description:
+ ; * Copies the reference 16x16 block to the current block.
+ ; * Parameters:
+ ; * [in] pSrc         - pointer to the reference block in the source frame; must be aligned on an 16-byte boundary.
+ ; * [in] step         - distance between the starts of consecutive lines in the reference frame, in bytes;
+ ; *                     must be a multiple of 16 and must be larger than or equal to 16.
+ ; * [out] pDst        - pointer to the destination block; must be aligned on an 8-byte boundary.
+ ; * Return Value:
+ ; * OMX_Sts_NoErr     - no error
+ ; * OMX_Sts_BadArgErr - bad arguments; returned under any of the following conditions:
+ ; *                   - one or more of the following pointers is NULL:  pSrc, pDst
+ ; *                   - one or more of the following pointers is not aligned on an 16-byte boundary:  pSrc, pDst
+ ; *                   - step <16 or step is not a multiple of 16.  
+ ; */
+
+   INCLUDE omxtypes_s.h
+   
+     
+     M_VARIANTS CortexA8
+     
+     IF CortexA8
+     
+     
+ ;//Input Arguments
+pSrc    RN 0        
+pDst    RN 1        
+step    RN 2
+
+;//Local Variables
+Return  RN 0
+;// Neon Registers
+
+X0      DN D0.S8 
+X1      DN D1.S8 
+X2      DN D2.S8
+X3      DN D3.S8
+X4      DN D4.S8
+X5      DN D5.S8
+X6      DN D6.S8
+X7      DN D7.S8 
+ 
+     M_START omxVCCOMM_Copy16x16
+         
+        
+        VLD1  {X0,X1},[pSrc@128],step       ;// Load 16 bytes from 16 byte aligned pSrc and pSrc=pSrc + step after loading
+        VLD1  {X2,X3},[pSrc@128],step
+        VLD1  {X4,X5},[pSrc@128],step
+        VLD1  {X6,X7},[pSrc@128],step
+        
+        VST1  {X0,X1,X2,X3},[pDst@128]!     ;// Store 32 bytes to 16 byte aligned pDst   
+        VST1  {X4,X5,X6,X7},[pDst@128]!        
+               
+         
+        VLD1  {X0,X1},[pSrc@128],step
+        VLD1  {X2,X3},[pSrc@128],step
+        VLD1  {X4,X5},[pSrc@128],step
+        VLD1  {X6,X7},[pSrc@128],step
+        
+        VST1  {X0,X1,X2,X3},[pDst@128]!
+        VST1  {X4,X5,X6,X7},[pDst@128]!
+         
+      
+        VLD1  {X0,X1},[pSrc@128],step
+        VLD1  {X2,X3},[pSrc@128],step
+        VLD1  {X4,X5},[pSrc@128],step
+        VLD1  {X6,X7},[pSrc@128],step
+        
+        VST1  {X0,X1,X2,X3},[pDst@128]!              
+        VST1  {X4,X5,X6,X7},[pDst@128]!        
+        
+        
+        VLD1  {X0,X1},[pSrc@128],step
+        VLD1  {X2,X3},[pSrc@128],step
+        VLD1  {X4,X5},[pSrc@128],step
+        VLD1  {X6,X7},[pSrc@128],step
+        
+        VST1  {X0,X1,X2,X3},[pDst@128]!
+        VST1  {X4,X5,X6,X7},[pDst@128]!
+
+        
+        MOV   Return,#OMX_Sts_NoErr
+
+     
+        
+        M_END
+        ENDIF
+
+
+
+        
+        END
+       
\ No newline at end of file
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/comm/src/omxVCCOMM_Copy8x8_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/comm/src/omxVCCOMM_Copy8x8_s.s
new file mode 100755
index 0000000..db9e5ef
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/comm/src/omxVCCOMM_Copy8x8_s.s
@@ -0,0 +1,70 @@
+ ;/**
+ ; * Function: omxVCCOMM_Copy8x8
+ ; *
+ ; * Description:
+ ; * Copies the reference 8x8 block to the current block.
+ ; * Parameters:
+ ; * [in] pSrc         - pointer to the reference block in the source frame; must be aligned on an 8-byte boundary.
+ ; * [in] step         - distance between the starts of consecutive lines in the reference frame, in bytes;
+ ; *                     must be a multiple of 8 and must be larger than or equal to 8.
+ ; * [out] pDst        - pointer to the destination block; must be aligned on an 8-byte boundary.
+ ; * Return Value:
+ ; * OMX_Sts_NoErr     - no error
+ ; * OMX_Sts_BadArgErr - bad arguments; returned under any of the following conditions:
+ ; *                   - one or more of the following pointers is NULL:  pSrc, pDst
+ ; *                   - one or more of the following pointers is not aligned on an 8-byte boundary:  pSrc, pDst
+ ; *                   - step <8 or step is not a multiple of 8.  
+ ; */
+
+   INCLUDE omxtypes_s.h
+   
+     
+     M_VARIANTS CortexA8
+     
+     IF CortexA8
+     
+     
+ ;//Input Arguments
+pSrc    RN 0        
+pDst    RN 1        
+step    RN 2
+
+;//Local Variables
+Count   RN 3
+Return  RN 0
+;// Neon Registers
+
+X0      DN D0.S8 
+X1      DN D1.S8
+X2      DN D2.S8
+X3      DN D3.S8
+     M_START omxVCCOMM_Copy8x8
+        
+            
+        
+        VLD1  {X0},[pSrc],step            ;// Load 8 bytes from 8 byte aligned pSrc, pSrc=pSrc+step after load
+        VLD1  {X1},[pSrc],step
+        VLD1  {X2},[pSrc],step
+        VLD1  {X3},[pSrc],step
+        
+        VST1  {X0,X1},[pDst]!            ;// Store 16 bytes to 8 byte aligned pDst  
+        VST1  {X2,X3},[pDst]!              
+        
+        VLD1  {X0},[pSrc],step
+        VLD1  {X1},[pSrc],step
+        VLD1  {X2},[pSrc],step
+        VLD1  {X3},[pSrc],step
+        
+        VST1  {X0,X1},[pDst]!              
+        VST1  {X2,X3},[pDst]!             
+                
+        MOV   Return,#OMX_Sts_NoErr
+             
+        M_END
+        ENDIF
+
+
+
+        
+        END
+        
\ No newline at end of file
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/comm/src/omxVCCOMM_ExpandFrame_I_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/comm/src/omxVCCOMM_ExpandFrame_I_s.s
new file mode 100755
index 0000000..5c5b7d8
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/comm/src/omxVCCOMM_ExpandFrame_I_s.s
@@ -0,0 +1,236 @@
+;//
+;// 
+;// File Name:  omxVCCOMM_ExpandFrame_I_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   12290
+;// Date:       Wednesday, April 9, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+;// Description:
+;// This function will Expand Frame boundary pixels into Plane
+;// 
+;// 
+
+;// Include standard headers
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+        
+        M_VARIANTS CortexA8
+
+;// Import symbols required from other files
+;// (For example tables)
+    
+  
+;// Set debugging level        
+DEBUG_ON    SETL {FALSE}
+
+
+    
+    IF CortexA8
+    
+        M_START omxVCCOMM_ExpandFrame_I,r11
+
+;//Input registers
+
+pSrcDstPlane    RN  0
+iFrameWidth     RN  1
+iFrameHeight    RN  2    
+iExpandPels     RN  3
+iPlaneStep      RN  4
+pTop            RN  5
+pBot            RN  6
+pDstTop         RN  7
+pDstBot         RN  8
+pLeft           RN  5
+pRight          RN  6
+pDstLeft        RN  9
+pDstRight       RN  10
+Offset          RN  11
+Temp            RN  14
+Counter         RN  12
+Tmp             RN  7
+;//Output registers
+
+result          RN  0
+;// Neon registers
+qData0          QN  0.U8
+qData1          QN  1.U8
+dData0          DN  0.U8
+dData1          DN  1.U8
+dData2          DN  2.U8
+dData3          DN  3.U8
+
+        ;// Define stack arguments
+        M_ARG       pPlaneStep, 4
+        
+        ;// Load argument from the stack
+        M_LDR       iPlaneStep, pPlaneStep
+        
+        SUB         pTop, pSrcDstPlane, #0              ;// Top row pointer of the frame
+        MUL         Offset, iExpandPels, iPlaneStep     ;// E*Step        
+        SUB         Temp, iFrameHeight, #1              ;// H-1
+        MUL         Temp, iPlaneStep, Temp              ;// (H-1)*Step
+        ADD         pBot, Temp, pSrcDstPlane            ;// BPtr = TPtr + (H-1)*Step
+        MOV         Temp, iFrameWidth                   ;// Outer loop counter
+        
+        ;// Check if pSrcDstPlane and iPlaneStep are 16 byte aligned
+        TST         pSrcDstPlane, #0xf
+        TSTEQ       iPlaneStep, #0xf        
+        BNE         Hor8Loop00
+        
+        ;//
+        ;// Copy top and bottom region of the plane as follows
+        ;// top region = top row elements from the frame
+        ;// bottom region = last row elements from the frame
+        ;//
+
+        ;// Case for 16 byte alignment
+Hor16Loop00
+        SUB         pDstTop, pTop, Offset
+        VLD1        qData0, [pTop @128]!
+        MOV         Counter, iExpandPels                ;// Inner loop counter
+        ADD         pDstBot, pBot, iPlaneStep
+        VLD1        qData1, [pBot @128]!
+Ver16Loop0
+        VST1        qData0, [pDstTop @128], iPlaneStep
+        VST1        qData0, [pDstTop @128], iPlaneStep
+        VST1        qData0, [pDstTop @128], iPlaneStep
+        VST1        qData0, [pDstTop @128], iPlaneStep
+        VST1        qData0, [pDstTop @128], iPlaneStep
+        VST1        qData0, [pDstTop @128], iPlaneStep
+        VST1        qData0, [pDstTop @128], iPlaneStep
+        VST1        qData0, [pDstTop @128], iPlaneStep
+        SUBS        Counter, Counter, #8
+        VST1        qData1, [pDstBot @128], iPlaneStep
+        VST1        qData1, [pDstBot @128], iPlaneStep
+        VST1        qData1, [pDstBot @128], iPlaneStep
+        VST1        qData1, [pDstBot @128], iPlaneStep
+        VST1        qData1, [pDstBot @128], iPlaneStep
+        VST1        qData1, [pDstBot @128], iPlaneStep
+        VST1        qData1, [pDstBot @128], iPlaneStep
+        VST1        qData1, [pDstBot @128], iPlaneStep        
+        BGT         Ver16Loop0
+
+        SUBS        Temp, Temp, #16
+        BGT         Hor16Loop00
+        B           EndAlignedLoop
+        
+        ;// Case for 8 byte alignment
+Hor8Loop00
+        SUB         pDstTop, pTop, Offset
+        VLD1        qData0, [pTop @64]!
+        MOV         Counter, iExpandPels                ;// Inner loop counter
+        ADD         pDstBot, pBot, iPlaneStep
+        VLD1        qData1, [pBot @64]!
+Ver8Loop0
+        VST1        qData0, [pDstTop @64], iPlaneStep
+        VST1        qData0, [pDstTop @64], iPlaneStep
+        VST1        qData0, [pDstTop @64], iPlaneStep
+        VST1        qData0, [pDstTop @64], iPlaneStep
+        VST1        qData0, [pDstTop @64], iPlaneStep
+        VST1        qData0, [pDstTop @64], iPlaneStep
+        VST1        qData0, [pDstTop @64], iPlaneStep
+        VST1        qData0, [pDstTop @64], iPlaneStep
+        SUBS        Counter, Counter, #8
+        VST1        qData1, [pDstBot @64], iPlaneStep
+        VST1        qData1, [pDstBot @64], iPlaneStep
+        VST1        qData1, [pDstBot @64], iPlaneStep
+        VST1        qData1, [pDstBot @64], iPlaneStep
+        VST1        qData1, [pDstBot @64], iPlaneStep
+        VST1        qData1, [pDstBot @64], iPlaneStep
+        VST1        qData1, [pDstBot @64], iPlaneStep
+        VST1        qData1, [pDstBot @64], iPlaneStep        
+        BGT         Ver8Loop0
+
+        SUBS        Temp, Temp, #16
+        BGT         Hor8Loop00
+
+EndAlignedLoop
+        ADD         Temp, pSrcDstPlane, iFrameWidth
+        SUB         pDstRight, Temp, Offset
+        SUB         pRight, Temp, #1
+        SUB         pDstLeft, pSrcDstPlane, Offset    
+        SUB         pDstLeft, pDstLeft, iExpandPels    
+        ADD         pLeft, pSrcDstPlane, #0
+        
+        VLD1        {dData0 []}, [pLeft], iPlaneStep        ;// Top-Left corner pixel from frame duplicated in dData0
+        SUB         Offset, iPlaneStep, iExpandPels
+        VLD1        {dData1 []}, [pRight], iPlaneStep       ;// Top-Right corner pixel from frame duplicated in dData1
+        MOV         Temp, iExpandPels
+
+        ;//
+        ;// Copy top-left and top-right region of the plane as follows
+        ;// top-left region = top-left corner pixel from the frame
+        ;// top-right region = top-right corner pixel from the frame
+        ;//
+HorLoop11
+        MOV         Counter, iExpandPels
+VerLoop1
+        VST1        dData0, [pDstLeft], #8
+        SUBS        Counter, Counter, #8
+        VST1        dData1, [pDstRight], #8        
+        BGT         VerLoop1
+
+        SUBS        Temp, Temp, #1
+        ADD         pDstLeft, pDstLeft, Offset
+        ADD         pDstRight, pDstRight, Offset
+        BPL         HorLoop11
+
+        SUB         iFrameHeight, iFrameHeight, #1
+        ;//
+        ;// Copy left and right region of the plane as follows
+        ;// Left region = copy the row with left start pixel from the frame
+        ;// Right region = copy the row with right end pixel from the frame
+        ;//
+HorLoop22
+        VLD1        {dData0 []}, [pLeft], iPlaneStep
+        MOV         Counter, iExpandPels
+        VLD1        {dData1 []}, [pRight], iPlaneStep
+VerLoop2
+        VST1        dData0, [pDstLeft], #8
+        SUBS        Counter, Counter, #8
+        VST1        dData1, [pDstRight], #8        
+        BGT         VerLoop2
+
+        SUBS        iFrameHeight, iFrameHeight, #1
+        ADD         pDstLeft, pDstLeft, Offset
+        ADD         pDstRight, pDstRight, Offset
+        BGT         HorLoop22
+                
+        MOV         Temp, iExpandPels
+        ;//
+        ;// Copy bottom-left and bottom-right region of the plane as follows
+        ;// bottom-left region = bottom-left corner pixel from the frame
+        ;// bottom-right region = bottom-right corner pixel from the frame
+        ;//
+HorLoop33
+        MOV         Counter, iExpandPels
+VerLoop3
+        VST1        dData0, [pDstLeft], #8
+        SUBS        Counter, Counter, #8
+        VST1        dData1, [pDstRight], #8        
+        BGT         VerLoop3
+
+        SUBS        Temp, Temp, #1
+        ADD         pDstLeft, pDstLeft, Offset
+        ADD         pDstRight, pDstRight, Offset
+        BGT         HorLoop33
+End
+        MOV         r0, #OMX_Sts_NoErr
+        
+        M_END    
+    
+    ENDIF
+
+
+
+        
+;// Guarding implementation by the processor name
+    
+ 
+            
+    END
\ No newline at end of file
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/api/armVCM4P10_CAVLCTables.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/api/armVCM4P10_CAVLCTables.h
new file mode 100755
index 0000000..547a2d9
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/api/armVCM4P10_CAVLCTables.h
@@ -0,0 +1,30 @@
+/* ----------------------------------------------------------------
+ * 
+ * 
+ * File Name:  armVCM4P10_CAVLCTables.h
+ * OpenMAX DL: v1.0.2
+ * Revision:   12290
+ * Date:       Wednesday, April 9, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * 
+ * Header file for optimized H.264 CALVC tables
+ * 
+ */
+ 
+#ifndef ARMVCM4P10_CAVLCTABLES_H
+#define ARMVCM4P10_CAVLCTABLES_H
+  
+/* CAVLC tables */
+
+extern const OMX_U16 *armVCM4P10_CAVLCCoeffTokenTables[18];
+extern const OMX_U16 *armVCM4P10_CAVLCTotalZeroTables[15];
+extern const OMX_U16 *armVCM4P10_CAVLCTotalZeros2x2Tables[3];
+extern const OMX_U16 *armVCM4P10_CAVLCRunBeforeTables[15];
+extern const OMX_U8 armVCM4P10_ZigZag_4x4[16];
+extern const OMX_U8 armVCM4P10_ZigZag_2x2[4];
+extern const OMX_S8 armVCM4P10_SuffixToLevel[7];
+
+#endif
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_Average_4x_Align_unsafe_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_Average_4x_Align_unsafe_s.s
new file mode 100755
index 0000000..4f0892d
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_Average_4x_Align_unsafe_s.s
@@ -0,0 +1,222 @@
+;//
+;// 
+;// File Name:  armVCM4P10_Average_4x_Align_unsafe_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   12290
+;// Date:       Wednesday, April 9, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+
+;// Functions:
+;//     armVCM4P10_Average_4x4_Align<ALIGNMENT>_unsafe  
+;//
+;// Implements Average of 4x4 with equation c = (a+b+1)>>1.
+;// First operand will be at offset ALIGNMENT from aligned address
+;// Second operand will be at aligned location and will be used as output.
+;// destination pointed by (pDst) for vertical interpolation.
+;// This function needs to copy 4 bytes in horizontal direction 
+;//
+;// Registers used as input for this function
+;// r0,r1,r2,r3 where r2 containings aligned memory pointer and r3 step size
+;//
+;// Registers preserved for top level function
+;// r4,r5,r6,r8,r9,r14
+;//
+;// Registers modified by the function
+;// r7,r10,r11,r12
+;//
+;// Output registers
+;// r2 - pointer to the aligned location
+;// r3 - step size to this aligned location
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+        
+        M_VARIANTS ARM1136JS
+
+        EXPORT armVCM4P10_Average_4x4_Align0_unsafe
+        EXPORT armVCM4P10_Average_4x4_Align2_unsafe
+        EXPORT armVCM4P10_Average_4x4_Align3_unsafe
+
+DEBUG_ON    SETL {FALSE}
+
+;// Declare input registers
+pPred0          RN 0
+iPredStep0      RN 1
+pPred1          RN 2
+iPredStep1      RN 3
+pDstPred        RN 2
+iDstStep        RN 3
+
+;// Declare other intermediate registers
+iPredA0         RN 10
+iPredA1         RN 11
+iPredB0         RN 12
+iPredB1         RN 14
+Temp1           RN 4
+Temp2           RN 5
+ResultA         RN 5
+ResultB         RN 4
+r0x80808080     RN 7
+
+    IF ARM1136JS
+        
+        ;// This function calculates average of 4x4 block 
+        ;// pPred0 is at alignment offset 0 and pPred1 is alignment 4
+
+        ;// Function header
+        M_START armVCM4P10_Average_4x4_Align0_unsafe, r6
+
+        ;// Code start        
+        LDR         r0x80808080, =0x80808080
+
+        ;// 1st load
+        M_LDR       iPredB0, [pPred1]
+        M_LDR       iPredA0, [pPred0], iPredStep0        
+        M_LDR       iPredB1, [pPred1, iPredStep1]
+        M_LDR       iPredA1, [pPred0], iPredStep0
+
+        ;// (a+b+1)/2 = (a+256-(255-b))/2 = (a-(255-b))/2 + 128
+        MVN         iPredB0, iPredB0
+        MVN         iPredB1, iPredB1
+        UHSUB8      ResultA, iPredA0, iPredB0
+        UHSUB8      ResultB, iPredA1, iPredB1
+        EOR         ResultA, ResultA, r0x80808080
+        M_STR       ResultA, [pDstPred], iDstStep        
+        EOR         ResultB, ResultB, r0x80808080
+        M_STR       ResultB, [pDstPred], iDstStep        
+        
+        ;// 2nd load
+        M_LDR       iPredA0, [pPred0], iPredStep0        
+        M_LDR       iPredB0, [pPred1]
+        M_LDR       iPredA1, [pPred0], iPredStep0
+        M_LDR       iPredB1, [pPred1, iPredStep1]
+
+        MVN         iPredB0, iPredB0
+        UHSUB8      ResultA, iPredA0, iPredB0
+        MVN         iPredB1, iPredB1
+        UHSUB8      ResultB, iPredA1, iPredB1
+        EOR         ResultA, ResultA, r0x80808080        
+        M_STR       ResultA, [pDstPred], iDstStep        
+        EOR         ResultB, ResultB, r0x80808080
+        M_STR       ResultB, [pDstPred], iDstStep                
+End0
+        M_END
+
+        ;// This function calculates average of 4x4 block 
+        ;// pPred0 is at alignment offset 2 and pPred1 is alignment 4
+
+        ;// Function header
+        M_START armVCM4P10_Average_4x4_Align2_unsafe, r6
+
+        ;// Code start        
+        LDR         r0x80808080, =0x80808080
+
+        ;// 1st load
+        LDR         Temp1, [pPred0, #4]
+        M_LDR       iPredA0, [pPred0], iPredStep0        
+        M_LDR       iPredB0, [pPred1]
+        M_LDR       iPredB1, [pPred1, iPredStep1]
+        M_LDR       Temp2, [pPred0, #4]
+        M_LDR       iPredA1, [pPred0], iPredStep0
+        MVN         iPredB0, iPredB0
+        MVN         iPredB1, iPredB1        
+        MOV         iPredA0, iPredA0, LSR #16
+        ORR         iPredA0, iPredA0, Temp1, LSL #16        
+        MOV         iPredA1, iPredA1, LSR #16
+        ORR         iPredA1, iPredA1, Temp2, LSL #16
+
+        ;// (a+b+1)/2 = (a+256-(255-b))/2 = (a-(255-b))/2 + 128
+        UHSUB8      ResultA, iPredA0, iPredB0
+        UHSUB8      ResultB, iPredA1, iPredB1
+        EOR         ResultA, ResultA, r0x80808080
+        M_STR       ResultA, [pDstPred], iDstStep        
+        EOR         ResultB, ResultB, r0x80808080
+        M_STR       ResultB, [pDstPred], iDstStep        
+        
+        ;// 2nd load
+        LDR         Temp1, [pPred0, #4]
+        M_LDR         iPredA0, [pPred0], iPredStep0        
+        LDR         iPredB0, [pPred1]
+        LDR         iPredB1, [pPred1, iPredStep1]
+        LDR         Temp2, [pPred0, #4]
+        M_LDR         iPredA1, [pPred0], iPredStep0
+        MVN         iPredB0, iPredB0
+        MVN         iPredB1, iPredB1
+        MOV         iPredA0, iPredA0, LSR #16
+        ORR         iPredA0, iPredA0, Temp1, LSL #16        
+        MOV         iPredA1, iPredA1, LSR #16
+        ORR         iPredA1, iPredA1, Temp2, LSL #16
+
+        UHSUB8      ResultA, iPredA0, iPredB0
+        UHSUB8      ResultB, iPredA1, iPredB1
+        EOR         ResultA, ResultA, r0x80808080        
+        M_STR       ResultA, [pDstPred], iDstStep        
+        EOR         ResultB, ResultB, r0x80808080
+        M_STR       ResultB, [pDstPred], iDstStep                
+End2
+        M_END
+
+
+        ;// This function calculates average of 4x4 block 
+        ;// pPred0 is at alignment offset 3 and pPred1 is alignment 4
+
+        ;// Function header
+        M_START armVCM4P10_Average_4x4_Align3_unsafe, r6
+
+        ;// Code start        
+        LDR         r0x80808080, =0x80808080
+
+        ;// 1st load
+        LDR         Temp1, [pPred0, #4]
+        M_LDR       iPredA0, [pPred0], iPredStep0        
+        LDR         iPredB0, [pPred1]
+        LDR         iPredB1, [pPred1, iPredStep1]
+        LDR         Temp2, [pPred0, #4]
+        M_LDR       iPredA1, [pPred0], iPredStep0
+
+        MVN         iPredB0, iPredB0
+        MVN         iPredB1, iPredB1
+        MOV         iPredA0, iPredA0, LSR #24
+        ORR         iPredA0, iPredA0, Temp1, LSL #8                
+        MOV         iPredA1, iPredA1, LSR #24
+        ORR         iPredA1, iPredA1, Temp2, LSL #8
+        UHSUB8      ResultA, iPredA0, iPredB0
+        UHSUB8      ResultB, iPredA1, iPredB1
+        EOR         ResultA, ResultA, r0x80808080
+        M_STR       ResultA, [pDstPred], iDstStep        
+        EOR         ResultB, ResultB, r0x80808080
+        M_STR       ResultB, [pDstPred], iDstStep        
+        
+        ;// 2nd load
+        LDR         Temp1, [pPred0, #4]
+        M_LDR       iPredA0, [pPred0], iPredStep0        
+        LDR         iPredB0, [pPred1]
+        LDR         iPredB1, [pPred1, iPredStep1]
+        LDR         Temp2, [pPred0, #4]
+        M_LDR       iPredA1, [pPred0], iPredStep0
+
+        MVN         iPredB0, iPredB0
+        MVN         iPredB1, iPredB1
+        MOV         iPredA0, iPredA0, LSR #24
+        ORR         iPredA0, iPredA0, Temp1, LSL #8        
+        MOV         iPredA1, iPredA1, LSR #24
+        ORR         iPredA1, iPredA1, Temp2, LSL #8
+
+        UHSUB8      ResultA, iPredA0, iPredB0
+        UHSUB8      ResultB, iPredA1, iPredB1
+        EOR         ResultA, ResultA, r0x80808080        
+        M_STR       ResultA, [pDstPred], iDstStep        
+        EOR         ResultB, ResultB, r0x80808080
+        M_STR       ResultB, [pDstPred], iDstStep                
+End3
+        M_END
+
+    ENDIF
+    
+    END
+    
\ No newline at end of file
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_CAVLCTables.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_CAVLCTables.c
new file mode 100755
index 0000000..137495d
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_CAVLCTables.c
@@ -0,0 +1,327 @@
+/* ----------------------------------------------------------------
+ *
+ * 
+ * File Name:  armVCM4P10_CAVLCTables.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   12290
+ * Date:       Wednesday, April 9, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * 
+ * Optimized CAVLC tables for H.264
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+
+#include "armVCM4P10_CAVLCTables.h"
+
+/* 4x4 DeZigZag table */
+
+const OMX_U8 armVCM4P10_ZigZag_4x4[16] =
+{
+    0, 1, 4, 8, 5, 2, 3, 6, 9, 12, 13, 10, 7, 11, 14, 15
+};
+
+/* 2x2 DeZigZag table */
+
+const OMX_U8 armVCM4P10_ZigZag_2x2[4] =
+{
+    0, 1, 2, 3
+};
+
+
+/*
+ * Suffix To Level table
+ * We increment the suffix length if 
+ * ((LevelCode>>1)+1)>(3<<(SuffixLength-1)) && SuffixLength<6
+ * (LevelCode>>1)>=(3<<(SuffixLength-1))    && SuffixLength<6
+ *  LevelCode    >= 3<<SuffixLength         && SuffixLength<6
+ * (LevelCode+2) >= (3<<SuffixLength)+2     && SuffixLength<6
+ */
+const OMX_S8 armVCM4P10_SuffixToLevel[7] =
+{
+    (3<<1)+2,       /* SuffixLength=1 */
+    (3<<1)+2,       /* SuffixLength=1 */
+    (3<<2)+2,       /* SuffixLength=2 */
+    (3<<3)+2,       /* SuffixLength=3 */
+    (3<<4)+2,       /* SuffixLength=4 */
+    (3<<5)+2,       /* SuffixLength=5 */
+    -1              /* SuffixLength=6 - never increment */
+};
+
+static const OMX_U16 armVCM4P10_CAVLCCoeffTokenTables_0[132] = {
+    0x0020, 0x0100, 0x2015, 0x2015, 0x400b, 0x400b, 0x400b, 0x400b,
+    0x6001, 0x6001, 0x6001, 0x6001, 0x6001, 0x6001, 0x6001, 0x6001,
+    0x0028, 0x00f0, 0x00f8, 0x0027, 0x0030, 0x00d8, 0x00e0, 0x00e8,
+    0x0038, 0x00a0, 0x00c8, 0x00d0, 0x0040, 0x0068, 0x0090, 0x0098,
+    0x0048, 0x0050, 0x0058, 0x0060, 0x27ff, 0x27ff, 0x206b, 0x206b,
+    0x0081, 0x0085, 0x0083, 0x0079, 0x0087, 0x007d, 0x007b, 0x0071,
+    0x007f, 0x0075, 0x0073, 0x0069, 0x0070, 0x0078, 0x0080, 0x0088,
+    0x2077, 0x2077, 0x206d, 0x206d, 0x2063, 0x2063, 0x2061, 0x2061,
+    0x206f, 0x206f, 0x2065, 0x2065, 0x205b, 0x205b, 0x2059, 0x2059,
+    0x0067, 0x005d, 0x0053, 0x0051, 0x005f, 0x0055, 0x004b, 0x0049,
+    0x00a8, 0x00b0, 0x00b8, 0x00c0, 0x2041, 0x2041, 0x204d, 0x204d,
+    0x2043, 0x2043, 0x2039, 0x2039, 0x2057, 0x2057, 0x2045, 0x2045,
+    0x203b, 0x203b, 0x2031, 0x2031, 0x204f, 0x204f, 0x203d, 0x203d,
+    0x2033, 0x2033, 0x2029, 0x2029, 0x0047, 0x0035, 0x002b, 0x0021,
+    0x203f, 0x203f, 0x202d, 0x202d, 0x2023, 0x2023, 0x2019, 0x2019,
+    0x0037, 0x0025, 0x001b, 0x0011, 0x202f, 0x202f, 0x201d, 0x201d,
+    0x0013, 0x0009, 0x201f, 0x201f
+};
+
+static const OMX_U16 armVCM4P10_CAVLCCoeffTokenTables_1[128] = {
+    0x0020, 0x00e8, 0x00f0, 0x00f8, 0x0027, 0x001f, 0x2015, 0x2015,
+    0x400b, 0x400b, 0x400b, 0x400b, 0x4001, 0x4001, 0x4001, 0x4001,
+    0x0028, 0x00d0, 0x00d8, 0x00e0, 0x0030, 0x0098, 0x00c0, 0x00c8,
+    0x0038, 0x0060, 0x0088, 0x0090, 0x0040, 0x0048, 0x0050, 0x0058,
+    0x27ff, 0x27ff, 0x207f, 0x207f, 0x0087, 0x0085, 0x0083, 0x0081,
+    0x007b, 0x0079, 0x007d, 0x0073, 0x2075, 0x2075, 0x2071, 0x2071,
+    0x0068, 0x0070, 0x0078, 0x0080, 0x2077, 0x2077, 0x206d, 0x206d,
+    0x206b, 0x206b, 0x2069, 0x2069, 0x206f, 0x206f, 0x2065, 0x2065,
+    0x2063, 0x2063, 0x2061, 0x2061, 0x0059, 0x005d, 0x005b, 0x0051,
+    0x0067, 0x0055, 0x0053, 0x0049, 0x00a0, 0x00a8, 0x00b0, 0x00b8,
+    0x205f, 0x205f, 0x204d, 0x204d, 0x204b, 0x204b, 0x2041, 0x2041,
+    0x2057, 0x2057, 0x2045, 0x2045, 0x2043, 0x2043, 0x2039, 0x2039,
+    0x204f, 0x204f, 0x203d, 0x203d, 0x203b, 0x203b, 0x2031, 0x2031,
+    0x0029, 0x0035, 0x0033, 0x0021, 0x2047, 0x2047, 0x202d, 0x202d,
+    0x202b, 0x202b, 0x2019, 0x2019, 0x003f, 0x0025, 0x0023, 0x0011,
+    0x0037, 0x001d, 0x001b, 0x0009, 0x202f, 0x202f, 0x2013, 0x2013
+};
+
+static const OMX_U16 armVCM4P10_CAVLCCoeffTokenTables_2[112] = {
+    0x0020, 0x0088, 0x00b0, 0x00b8, 0x00c0, 0x00c8, 0x00d0, 0x00d8,
+    0x003f, 0x0037, 0x002f, 0x0027, 0x001f, 0x0015, 0x000b, 0x0001,
+    0x0028, 0x0050, 0x0078, 0x0080, 0x0030, 0x0038, 0x0040, 0x0048,
+    0x07ff, 0x0081, 0x0087, 0x0085, 0x0083, 0x0079, 0x007f, 0x007d,
+    0x007b, 0x0071, 0x0077, 0x0075, 0x0073, 0x0069, 0x206b, 0x206b,
+    0x0058, 0x0060, 0x0068, 0x0070, 0x2061, 0x2061, 0x206d, 0x206d,
+    0x2063, 0x2063, 0x2059, 0x2059, 0x206f, 0x206f, 0x2065, 0x2065,
+    0x205b, 0x205b, 0x2051, 0x2051, 0x0067, 0x005d, 0x0053, 0x0049,
+    0x005f, 0x0055, 0x004b, 0x0041, 0x0090, 0x0098, 0x00a0, 0x00a8,
+    0x2039, 0x2039, 0x2031, 0x2031, 0x204d, 0x204d, 0x2029, 0x2029,
+    0x2057, 0x2057, 0x2045, 0x2045, 0x2043, 0x2043, 0x2021, 0x2021,
+    0x0019, 0x003d, 0x003b, 0x0011, 0x004f, 0x0035, 0x0033, 0x0009,
+    0x202b, 0x202b, 0x202d, 0x202d, 0x2023, 0x2023, 0x2025, 0x2025,
+    0x201b, 0x201b, 0x2047, 0x2047, 0x201d, 0x201d, 0x2013, 0x2013
+};
+
+static const OMX_U16 armVCM4P10_CAVLCCoeffTokenTables_3[80] = {
+    0x0020, 0x0028, 0x0030, 0x0038, 0x0040, 0x0048, 0x0050, 0x0058,
+    0x0060, 0x0068, 0x0070, 0x0078, 0x0080, 0x0088, 0x0090, 0x0098,
+    0x0009, 0x000b, 0x07ff, 0x0001, 0x0011, 0x0013, 0x0015, 0x07ff,
+    0x0019, 0x001b, 0x001d, 0x001f, 0x0021, 0x0023, 0x0025, 0x0027,
+    0x0029, 0x002b, 0x002d, 0x002f, 0x0031, 0x0033, 0x0035, 0x0037,
+    0x0039, 0x003b, 0x003d, 0x003f, 0x0041, 0x0043, 0x0045, 0x0047,
+    0x0049, 0x004b, 0x004d, 0x004f, 0x0051, 0x0053, 0x0055, 0x0057,
+    0x0059, 0x005b, 0x005d, 0x005f, 0x0061, 0x0063, 0x0065, 0x0067,
+    0x0069, 0x006b, 0x006d, 0x006f, 0x0071, 0x0073, 0x0075, 0x0077,
+    0x0079, 0x007b, 0x007d, 0x007f, 0x0081, 0x0083, 0x0085, 0x0087
+};
+
+static const OMX_U16 armVCM4P10_CAVLCCoeffTokenTables_4[32] = {
+    0x0020, 0x0038, 0x2015, 0x2015, 0x4001, 0x4001, 0x4001, 0x4001,
+    0x600b, 0x600b, 0x600b, 0x600b, 0x600b, 0x600b, 0x600b, 0x600b,
+    0x0028, 0x0030, 0x0021, 0x0019, 0x2027, 0x2027, 0x0025, 0x0023,
+    0x201d, 0x201d, 0x201b, 0x201b, 0x0011, 0x001f, 0x0013, 0x0009
+};
+
+const OMX_U16 * armVCM4P10_CAVLCCoeffTokenTables[18] = {
+    armVCM4P10_CAVLCCoeffTokenTables_0, /* nC=0 */
+    armVCM4P10_CAVLCCoeffTokenTables_0, /* nC=1 */
+    armVCM4P10_CAVLCCoeffTokenTables_1, /* nC=2 */
+    armVCM4P10_CAVLCCoeffTokenTables_1, /* nC=3 */
+    armVCM4P10_CAVLCCoeffTokenTables_2, /* nC=4 */
+    armVCM4P10_CAVLCCoeffTokenTables_2, /* nC=5 */
+    armVCM4P10_CAVLCCoeffTokenTables_2, /* nC=6 */
+    armVCM4P10_CAVLCCoeffTokenTables_2, /* nC=7 */
+    armVCM4P10_CAVLCCoeffTokenTables_3, /* nC=8 */
+    armVCM4P10_CAVLCCoeffTokenTables_3, /* nC=9 */
+    armVCM4P10_CAVLCCoeffTokenTables_3, /* nC=10 */
+    armVCM4P10_CAVLCCoeffTokenTables_3, /* nC=11 */
+    armVCM4P10_CAVLCCoeffTokenTables_3, /* nC=12 */
+    armVCM4P10_CAVLCCoeffTokenTables_3, /* nC=13 */
+    armVCM4P10_CAVLCCoeffTokenTables_3, /* nC=14 */
+    armVCM4P10_CAVLCCoeffTokenTables_3, /* nC=15 */
+    armVCM4P10_CAVLCCoeffTokenTables_3, /* nC=16 */
+    armVCM4P10_CAVLCCoeffTokenTables_4  /* nC=-1 */
+};
+
+static const OMX_U16 armVCM4P10_CAVLCTotalZeroTables_0[40] = {
+    0x0020, 0x0048, 0x0009, 0x0007, 0x2005, 0x2005, 0x2003, 0x2003,
+    0x6001, 0x6001, 0x6001, 0x6001, 0x6001, 0x6001, 0x6001, 0x6001,
+    0x0028, 0x0040, 0x0011, 0x000f, 0x0030, 0x0038, 0x0019, 0x0017,
+    0x27ff, 0x27ff, 0x201f, 0x201f, 0x201d, 0x201d, 0x201b, 0x201b,
+    0x2015, 0x2015, 0x2013, 0x2013, 0x200d, 0x200d, 0x200b, 0x200b
+};
+
+static const OMX_U16 armVCM4P10_CAVLCTotalZeroTables_1[24] = {
+    0x0020, 0x0028, 0x0011, 0x000f, 0x000d, 0x000b, 0x2009, 0x2009,
+    0x2007, 0x2007, 0x2005, 0x2005, 0x2003, 0x2003, 0x2001, 0x2001,
+    0x001d, 0x001b, 0x0019, 0x0017, 0x2015, 0x2015, 0x2013, 0x2013
+};
+
+static const OMX_U16 armVCM4P10_CAVLCTotalZeroTables_2[24] = {
+    0x0020, 0x0028, 0x0011, 0x000b, 0x0009, 0x0001, 0x200f, 0x200f,
+    0x200d, 0x200d, 0x2007, 0x2007, 0x2005, 0x2005, 0x2003, 0x2003,
+    0x001b, 0x0017, 0x2019, 0x2019, 0x2015, 0x2015, 0x2013, 0x2013
+};
+
+static const OMX_U16 armVCM4P10_CAVLCTotalZeroTables_3[24] = {
+    0x0020, 0x0028, 0x0013, 0x000f, 0x0007, 0x0005, 0x2011, 0x2011,
+    0x200d, 0x200d, 0x200b, 0x200b, 0x2009, 0x2009, 0x2003, 0x2003,
+    0x2019, 0x2019, 0x2017, 0x2017, 0x2015, 0x2015, 0x2001, 0x2001
+};
+
+static const OMX_U16 armVCM4P10_CAVLCTotalZeroTables_4[20] = {
+    0x0020, 0x0015, 0x0011, 0x0005, 0x0003, 0x0001, 0x200f, 0x200f,
+    0x200d, 0x200d, 0x200b, 0x200b, 0x2009, 0x2009, 0x2007, 0x2007,
+    0x2017, 0x2017, 0x2013, 0x2013
+};
+
+static const OMX_U16 armVCM4P10_CAVLCTotalZeroTables_5[20] = {
+    0x0020, 0x0011, 0x2013, 0x2013, 0x200f, 0x200f, 0x200d, 0x200d,
+    0x200b, 0x200b, 0x2009, 0x2009, 0x2007, 0x2007, 0x2005, 0x2005,
+    0x0015, 0x0001, 0x2003, 0x2003
+};
+
+static const OMX_U16 armVCM4P10_CAVLCTotalZeroTables_6[20] = {
+    0x0020, 0x000f, 0x2011, 0x2011, 0x200d, 0x200d, 0x2009, 0x2009,
+    0x2007, 0x2007, 0x2005, 0x2005, 0x400b, 0x400b, 0x400b, 0x400b,
+    0x0013, 0x0001, 0x2003, 0x2003
+};
+
+static const OMX_U16 armVCM4P10_CAVLCTotalZeroTables_7[20] = {
+    0x0020, 0x0003, 0x200f, 0x200f, 0x200d, 0x200d, 0x2007, 0x2007,
+    0x400b, 0x400b, 0x400b, 0x400b, 0x4009, 0x4009, 0x4009, 0x4009,
+    0x0011, 0x0001, 0x2005, 0x2005
+};
+
+static const OMX_U16 armVCM4P10_CAVLCTotalZeroTables_8[20] = {
+    0x0020, 0x0005, 0x200b, 0x200b, 0x400d, 0x400d, 0x400d, 0x400d,
+    0x4009, 0x4009, 0x4009, 0x4009, 0x4007, 0x4007, 0x4007, 0x4007,
+    0x0003, 0x0001, 0x200f, 0x200f
+};
+
+static const OMX_U16 armVCM4P10_CAVLCTotalZeroTables_9[20] = {
+    0x0020, 0x000d, 0x2005, 0x2005, 0x400b, 0x400b, 0x400b, 0x400b,
+    0x4009, 0x4009, 0x4009, 0x4009, 0x4007, 0x4007, 0x4007, 0x4007,
+    0x2003, 0x2003, 0x2001, 0x2001
+};
+
+static const OMX_U16 armVCM4P10_CAVLCTotalZeroTables_10[16] = {
+    0x0001, 0x0003, 0x2005, 0x2005, 0x2007, 0x2007, 0x200b, 0x200b,
+    0x6009, 0x6009, 0x6009, 0x6009, 0x6009, 0x6009, 0x6009, 0x6009
+};
+
+static const OMX_U16 armVCM4P10_CAVLCTotalZeroTables_11[16] = {
+    0x0001, 0x0003, 0x2009, 0x2009, 0x4005, 0x4005, 0x4005, 0x4005,
+    0x6007, 0x6007, 0x6007, 0x6007, 0x6007, 0x6007, 0x6007, 0x6007
+};
+
+static const OMX_U16 armVCM4P10_CAVLCTotalZeroTables_12[16] = {
+    0x2001, 0x2001, 0x2003, 0x2003, 0x4007, 0x4007, 0x4007, 0x4007,
+    0x6005, 0x6005, 0x6005, 0x6005, 0x6005, 0x6005, 0x6005, 0x6005
+};
+
+static const OMX_U16 armVCM4P10_CAVLCTotalZeroTables_13[16] = {
+    0x4001, 0x4001, 0x4001, 0x4001, 0x4003, 0x4003, 0x4003, 0x4003,
+    0x6005, 0x6005, 0x6005, 0x6005, 0x6005, 0x6005, 0x6005, 0x6005
+};
+
+static const OMX_U16 armVCM4P10_CAVLCTotalZeroTables_14[16] = {
+    0x6001, 0x6001, 0x6001, 0x6001, 0x6001, 0x6001, 0x6001, 0x6001,
+    0x6003, 0x6003, 0x6003, 0x6003, 0x6003, 0x6003, 0x6003, 0x6003
+};
+
+const OMX_U16 * armVCM4P10_CAVLCTotalZeroTables[15] = {
+    armVCM4P10_CAVLCTotalZeroTables_0,
+    armVCM4P10_CAVLCTotalZeroTables_1,
+    armVCM4P10_CAVLCTotalZeroTables_2,
+    armVCM4P10_CAVLCTotalZeroTables_3,
+    armVCM4P10_CAVLCTotalZeroTables_4,
+    armVCM4P10_CAVLCTotalZeroTables_5,
+    armVCM4P10_CAVLCTotalZeroTables_6,
+    armVCM4P10_CAVLCTotalZeroTables_7,
+    armVCM4P10_CAVLCTotalZeroTables_8,
+    armVCM4P10_CAVLCTotalZeroTables_9,
+    armVCM4P10_CAVLCTotalZeroTables_10,
+    armVCM4P10_CAVLCTotalZeroTables_11,
+    armVCM4P10_CAVLCTotalZeroTables_12,
+    armVCM4P10_CAVLCTotalZeroTables_13,
+    armVCM4P10_CAVLCTotalZeroTables_14
+};
+
+static const OMX_U16 armVCM4P10_CAVLCTotalZeros2x2Tables_0[16] = {
+    0x2007, 0x2007, 0x2005, 0x2005, 0x4003, 0x4003, 0x4003, 0x4003,
+    0x6001, 0x6001, 0x6001, 0x6001, 0x6001, 0x6001, 0x6001, 0x6001
+};
+
+static const OMX_U16 armVCM4P10_CAVLCTotalZeros2x2Tables_1[16] = {
+    0x4005, 0x4005, 0x4005, 0x4005, 0x4003, 0x4003, 0x4003, 0x4003,
+    0x6001, 0x6001, 0x6001, 0x6001, 0x6001, 0x6001, 0x6001, 0x6001
+};
+
+static const OMX_U16 armVCM4P10_CAVLCTotalZeros2x2Tables_2[16] = {
+    0x6003, 0x6003, 0x6003, 0x6003, 0x6003, 0x6003, 0x6003, 0x6003,
+    0x6001, 0x6001, 0x6001, 0x6001, 0x6001, 0x6001, 0x6001, 0x6001
+};
+
+const OMX_U16 * armVCM4P10_CAVLCTotalZeros2x2Tables[3] = {
+    armVCM4P10_CAVLCTotalZeros2x2Tables_0,
+    armVCM4P10_CAVLCTotalZeros2x2Tables_1,
+    armVCM4P10_CAVLCTotalZeros2x2Tables_2
+};
+
+static const OMX_U16 armVCM4P10_CAVLCRunBeforeTables_0[8] = {
+    0x4003, 0x4003, 0x4003, 0x4003, 0x4001, 0x4001, 0x4001, 0x4001
+};
+
+static const OMX_U16 armVCM4P10_CAVLCRunBeforeTables_1[8] = {
+    0x2005, 0x2005, 0x2003, 0x2003, 0x4001, 0x4001, 0x4001, 0x4001
+};
+
+static const OMX_U16 armVCM4P10_CAVLCRunBeforeTables_2[8] = {
+    0x2007, 0x2007, 0x2005, 0x2005, 0x2003, 0x2003, 0x2001, 0x2001
+};
+
+static const OMX_U16 armVCM4P10_CAVLCRunBeforeTables_3[8] = {
+    0x0009, 0x0007, 0x2005, 0x2005, 0x2003, 0x2003, 0x2001, 0x2001
+};
+
+static const OMX_U16 armVCM4P10_CAVLCRunBeforeTables_4[8] = {
+    0x000b, 0x0009, 0x0007, 0x0005, 0x2003, 0x2003, 0x2001, 0x2001
+};
+
+static const OMX_U16 armVCM4P10_CAVLCRunBeforeTables_5[8] = {
+    0x0003, 0x0005, 0x0009, 0x0007, 0x000d, 0x000b, 0x2001, 0x2001
+};
+
+static const OMX_U16 armVCM4P10_CAVLCRunBeforeTables_6[24] = {
+    0x0010, 0x000d, 0x000b, 0x0009, 0x0007, 0x0005, 0x0003, 0x0001,
+    0x0018, 0x0011, 0x200f, 0x200f, 0x0020, 0x0015, 0x2013, 0x2013,
+    0x0028, 0x0019, 0x2017, 0x2017, 0x07ff, 0x001d, 0x201b, 0x201b
+};
+
+/* Tables 7 to 14 are duplicates of table 6 */
+
+const OMX_U16 * armVCM4P10_CAVLCRunBeforeTables[15] = {
+    armVCM4P10_CAVLCRunBeforeTables_0,  /* ZerosLeft=1 */
+    armVCM4P10_CAVLCRunBeforeTables_1,
+    armVCM4P10_CAVLCRunBeforeTables_2,
+    armVCM4P10_CAVLCRunBeforeTables_3,
+    armVCM4P10_CAVLCRunBeforeTables_4,
+    armVCM4P10_CAVLCRunBeforeTables_5,  /* ZerosLeft=6 */
+    armVCM4P10_CAVLCRunBeforeTables_6,  /* ZerosLeft=7 */
+    armVCM4P10_CAVLCRunBeforeTables_6,  /* ZerosLeft=8 */
+    armVCM4P10_CAVLCRunBeforeTables_6,  /* ZerosLeft=9 */
+    armVCM4P10_CAVLCRunBeforeTables_6,  /* ZerosLeft=10 */
+    armVCM4P10_CAVLCRunBeforeTables_6,  /* ZerosLeft=11 */
+    armVCM4P10_CAVLCRunBeforeTables_6,  /* ZerosLeft=12 */
+    armVCM4P10_CAVLCRunBeforeTables_6,  /* ZerosLeft=13 */
+    armVCM4P10_CAVLCRunBeforeTables_6,  /* ZerosLeft=14 */
+    armVCM4P10_CAVLCRunBeforeTables_6   /* ZerosLeft=15 */
+};
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_DeblockingChroma_unsafe_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_DeblockingChroma_unsafe_s.s
new file mode 100755
index 0000000..4c3a77c
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_DeblockingChroma_unsafe_s.s
@@ -0,0 +1,198 @@
+;//
+;// 
+;// File Name:  armVCM4P10_DeblockingChroma_unsafe_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   12290
+;// Date:       Wednesday, April 9, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+        
+        M_VARIANTS CortexA8
+
+
+    IF  CortexA8
+        
+pAlpha      RN 2
+pBeta       RN 3
+
+pThresholds RN 5
+pBS         RN 4
+bS3210      RN 6
+
+;// Pixels
+dP_0        DN D4.U8
+dP_1        DN D5.U8  
+dP_2        DN D6.U8  
+dP_3        DN D7.U8  
+dQ_0        DN D8.U8  
+dQ_1        DN D9.U8  
+dQ_2        DN D10.U8 
+dQ_3        DN D11.U8 
+
+
+;// Filtering Decision
+dAlpha      DN D0.U8
+dBeta       DN D2.U8
+
+dFilt       DN D16.U8
+dAqflg      DN D12.U8
+dApflg      DN D17.U8 
+
+dAp0q0      DN D13.U8
+
+;// bSLT4
+dTC3210     DN D18.U8   
+dTCs        DN D31.S8
+dTC         DN D31.U8
+
+dMask_0     DN D14.U8
+dMask_1     DN D15.U8    
+dMask_4     DN D26.U16
+
+dTemp       DN D28.U8
+dDummy      DN D17.U8
+
+;// Computing P0,Q0
+qDq0p0      QN Q10.S16
+qDp1q1      QN Q11.S16
+qDelta      QN Q10.S16  ; reuse qDq0p0
+dDelta      DN D20.S8
+
+
+;// Computing P1,Q1
+qP_0n       QN Q14.S16
+qQ_0n       QN Q12.S16
+
+dQ_0n       DN D24.U8
+dP_0n       DN D29.U8
+
+;// bSGE4
+
+dHSp0q1     DN D13.U8
+dHSq0p1     DN D31.U8   
+
+dBS3210     DN D28.U16
+
+dP_0t       DN D13.U8   ;dHSp0q1        
+dQ_0t       DN D31.U8   ;Temp1        
+
+dP_0n       DN D29.U8
+dQ_0n       DN D24.U8   ;Temp2        
+
+;// Register usage for - armVCM4P10_DeblockingLumabSLT4_unsafe
+;//
+;// Inputs - Pixels             - p0-p3: D4-D7, q0-q3: D8-D11
+;//        - Filter masks       - filt: D16, aqflg: D12, apflg: D17
+;//        - Additional Params  - pThresholds: r5
+;//         
+;// Outputs - Pixels            - P0-P1: D29-D30, Q0-Q1: D24-D25
+;//         - Additional Params - pThresholds: r5
+
+;// Registers Corrupted         - D18-D31
+
+
+        M_START armVCM4P10_DeblockingChromabSLT4_unsafe
+
+        
+        ;dTC3210 -18
+        ;dTemp-28
+
+        VLD1        d18.U32[0], [pThresholds]! ;here
+
+        ;// delta = (((q0-p0)<<2) + (p1-q1) + 4) >> 3;
+        ;// dDelta = (qDp1q1 >> 2 + qDq0p0 + 1)>> 1
+
+        ;// qDp1q1-11
+        ;// qDq0p0-10
+        VSUBL       qDp1q1, dP_1, dQ_1      
+        VMOV        dTemp, dTC3210
+        VSUBL       qDq0p0, dQ_0, dP_0      
+        VSHR        qDp1q1, qDp1q1, #2      
+        VZIP.8      dTC3210, dTemp
+    
+        ;// qDelta-qDq0p0-10
+
+        ;// dTC = dTC01 + (dAplg & 1) + (dAqflg & 1)
+
+        ;// dTC3210-18
+        ;// dTemp-28
+        ;// dTC-31
+        VBIF        dTC3210, dMask_0, dFilt
+        VRHADD      qDelta, qDp1q1, qDq0p0  
+        VADD        dTC, dTC3210, dMask_1
+        VQMOVN      dDelta, qDelta
+        ;// dDelta-d20
+
+        ;// dDelta = (OMX_U8)armClip(0, 255, q0 - delta);
+        VLD1        {dAlpha[]}, [pAlpha]
+        VMIN        dDelta, dDelta, dTCs
+        VNEG        dTCs, dTCs
+        VLD1        {dBeta[]}, [pBeta]
+        ;1
+        VMAX        dDelta, dDelta, dTCs
+
+        ;// dP_0n - 29
+        ;// dQ_0n - 24
+
+        ;// pQ0[-1*Step] = (OMX_U8)armClip(0, 255, dP_0 - delta);
+        ;// pQ0[0*Step] = (OMX_U8)armClip(0, 255, dQ_0 - delta);
+
+        ;// dP_0n = (OMX_U8)armClip(0, 255, dP_0 - dDelta);
+        ;// dQ_0n = (OMX_U8)armClip(0, 255, dP_0 - dDelta);
+        
+        ;// qP_0n - 14
+        ;// qQ_0n - 12
+        
+        VMOVL       qP_0n, dP_0
+        VMOVL       qQ_0n, dQ_0
+
+        ;1
+        VADDW       qP_0n, qP_0n, dDelta
+        VSUBW       qQ_0n, qQ_0n, dDelta
+        
+        VQMOVUN     dP_0n, qP_0n
+        VQMOVUN     dQ_0n, qQ_0n
+
+        M_END
+
+;// Register usage for - armVCM4P10_DeblockingLumabSGE4_unsafe()
+;//
+;// Inputs - Pixels             - p0-p3: D4-D7, q0-q3: D8-D11
+;//        - Filter masks       - filt: D16, aqflg: D12, apflg: D17
+;//        - Additional Params  - alpha: D0, dMask_1: D15
+;//         
+;// Outputs - Pixels            - P0-P2: D29-D31, Q0-Q2: D24,D25,D28
+
+;// Registers Corrupted         - D18-D31
+
+        M_START armVCM4P10_DeblockingChromabSGE4_unsafe
+    
+        ;dHSq0p1 - 31
+        ;dHSp0q1 - 13
+        VHADD       dHSp0q1, dP_0, dQ_1     
+        VHADD       dHSq0p1, dQ_0, dP_1         
+
+        ;// Prepare the bS mask
+
+        ;// dHSp0q1-13
+        ;// dP_0t-dHSp0q1-13
+        ;// dHSq0p1-31
+        ;// dQ_0t-Temp1-31
+        VLD1        {dAlpha[]}, [pAlpha]
+        ADD         pThresholds, pThresholds, #4
+        VLD1        {dBeta[]}, [pBeta]
+
+        VRHADD      dP_0t, dHSp0q1, dP_1    
+        VRHADD      dQ_0t, dHSq0p1, dQ_1
+        
+        M_END
+        
+        ENDIF  
+
+        END
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_DeblockingLuma_unsafe_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_DeblockingLuma_unsafe_s.s
new file mode 100755
index 0000000..0afe4fd
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_DeblockingLuma_unsafe_s.s
@@ -0,0 +1,396 @@
+;//
+;// 
+;// File Name:  armVCM4P10_DeblockingLuma_unsafe_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   12290
+;// Date:       Wednesday, April 9, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+        
+        M_VARIANTS CortexA8
+
+
+    IF  CortexA8
+        
+pThresholds RN 5
+
+;// Pixels
+dP_0        DN D4.U8
+dP_1        DN D5.U8  
+dP_2        DN D6.U8  
+dP_3        DN D7.U8  
+dQ_0        DN D8.U8  
+dQ_1        DN D9.U8  
+dQ_2        DN D10.U8 
+dQ_3        DN D11.U8 
+
+
+;// Filtering Decision
+dAlpha      DN D0.U8
+
+dFilt       DN D16.U8
+dAqflg      DN D12.U8
+dApflg      DN D17.U8 
+
+dAp0q0      DN D13.U8
+
+;// bSLT4
+dTC0        DN D18.U8   
+dTC1        DN D19.U8   
+dTC01       DN D18.U8   
+
+dTCs        DN D31.S8
+dTC         DN D31.U8
+
+dMask_0     DN D14.U8
+dMask_1     DN D15.U8    
+
+dTemp       DN D19.U8
+
+;// Computing P0,Q0
+qDq0p0      QN Q10.S16
+qDp1q1      QN Q11.S16
+qDelta      QN Q10.S16  ; reuse qDq0p0
+dDelta      DN D20.S8
+
+
+;// Computing P1,Q1
+dRp0q0      DN D24.U8
+
+dMaxP       DN D23.U8
+dMinP       DN D22.U8
+
+dMaxQ       DN D19.U8
+dMinQ       DN D21.U8
+
+dDeltaP     DN D26.U8
+dDeltaQ     DN D27.U8
+
+qP_0n       QN Q14.S16
+qQ_0n       QN Q12.S16
+
+dQ_0n       DN D24.U8
+dQ_1n       DN D25.U8
+dP_0n       DN D29.U8
+dP_1n       DN D30.U8
+
+;// bSGE4
+
+qSp0q0      QN Q10.U16
+
+qSp2q1      QN Q11.U16
+qSp0q0p1    QN Q12.U16
+qSp3p2      QN Q13.U16
+dHSp0q1     DN D28.U8
+
+qSq2p1      QN Q11.U16
+qSp0q0q1    QN Q12.U16
+qSq3q2      QN Q13.U16  ;!!
+dHSq0p1     DN D28.U8   ;!!
+
+qTemp1      QN Q11.U16  ;!!;qSp2q1 
+qTemp2      QN Q12.U16  ;!!;qSp0q0p1        
+
+dP_0t       DN D28.U8   ;!!;dHSp0q1        
+dQ_0t       DN D22.U8   ;!!;Temp1        
+
+dP_0n       DN D29.U8
+dP_1n       DN D30.U8
+dP_2n       DN D31.U8
+
+dQ_0n       DN D24.U8   ;!!;Temp2        
+dQ_1n       DN D25.U8   ;!!;Temp2        
+dQ_2n       DN D28.U8   ;!!;dQ_0t        
+
+;// Register usage for - armVCM4P10_DeblockingLumabSLT4_unsafe
+;//
+;// Inputs - Pixels             - p0-p3: D4-D7, q0-q3: D8-D11
+;//        - Filter masks       - filt: D16, aqflg: D12, apflg: D17
+;//        - Additional Params  - pThresholds: r5
+;//         
+;// Outputs - Pixels            - P0-P1: D29-D30, Q0-Q1: D24-D25
+;//         - Additional Params - pThresholds: r5
+
+;// Registers Corrupted         - D18-D31
+
+
+        M_START armVCM4P10_DeblockingLumabSLT4_unsafe
+
+        
+        ;// qDq0p0-10
+        VSUBL       qDp1q1, dP_1, dQ_1      
+        VLD1        {dTC0[]}, [pThresholds]!
+        ;// qDp1q1-11
+        VSUBL       qDq0p0, dQ_0, dP_0      
+        VLD1        {dTC1[]}, [pThresholds]!
+
+        ;// dRp0q0-24
+        VSHR        qDp1q1, qDp1q1, #2      
+    
+        ;// dTC01 = (dTC1 << 4) | dTC0
+        ;// dTC01-18
+        VEXT        dTC01, dTC0, dTC1, #4
+        ;// dTemp-19
+        VAND        dTemp, dApflg, dMask_1
+        
+        VBIF        dTC01, dMask_0, dFilt
+    
+
+        ;// delta = (((q0-p0)<<2) + (p1-q1) + 4) >> 3;
+        ;// dDelta = (qDp1q1 >> 2 + qDq0p0 + 1)>> 1
+
+        ;// qDelta-qDq0p0-10
+        VRHADD      qDelta, qDp1q1, qDq0p0  
+        VRHADD      dRp0q0, dP_0, dQ_0      
+        VADD        dTC, dTC01, dTemp
+
+        ;// dTC = dTC01 + (dAplg & 1) + (dAqflg & 1)
+        
+        VAND        dTemp, dAqflg, dMask_1
+        VQADD       dMaxP, dP_1, dTC01      
+        VQMOVN      dDelta, qDelta
+        VADD        dTC, dTC, dTemp
+
+        ;// dMaxP = QADD(dP_1, dTC01)
+        ;// dMinP = QSUB(dP_1, dTC01)
+ 
+        ;// dMaxP-d23
+        ;// dMinP-d22
+        VQSUB       dMinP, dP_1, dTC01      
+
+        ;// dDelta-d20
+
+        ;// dMaxQ = QADD(dQ_1, dTC01)
+        ;// dMinQ = QSUB(dQ_1, dTC01)
+ 
+        ;// dMaxQ-19
+        ;// dMinQ-21
+        VQADD       dMaxQ, dQ_1, dTC01
+        VHADD       dDeltaP, dRp0q0, dP_2   
+        VMIN        dDelta, dDelta, dTCs
+
+        ;// dDelta = (OMX_U8)armClip(0, 255, q0 - delta);
+        VNEG        dTCs, dTCs
+        
+        VQSUB       dMinQ, dQ_1, dTC01
+
+        ;// delta = (p2 + ((p0+q0+1)>>1) - (p1<<1))>>1;
+        ;// delta = armClip(-tC0, tC0, delta);
+        ;// pQ0[-2*Step] = (OMX_U8)(p1 + delta);
+
+        ;// dDeltaP = (dP_2 + dRp0q0)>>1;
+        ;// dP_1n = armClip(dP_1 - dTC01, dP_1 + dTC01, dDeltaP);
+        ;// dP_1n = armClip(MinP, MaxP, dDeltaP);
+        
+        ;// delta = (q2 + ((p0+q0+1)>>1) - (q1<<1))>>1;
+        ;// delta = armClip(-tC0, tC0, delta);
+        ;// pQ0[1*Step] = (OMX_U8)(q1 + delta);
+
+        ;// dDeltaQ = (dQ_2 + dRp0q0)>>1;
+        ;// dQ_1n = armClip(dQ_1 - dTC01, dQ_1 + dTC01, dDeltaQ);
+        ;// dQ_1n = armClip(MinQ, MaxQ, dDeltaQ);
+        
+        ;// dDeltaP-26
+        VHADD       dDeltaQ, dRp0q0, dQ_2   
+
+        ;// dDeltaQ-27
+        
+        ;// dP_0n - 29
+        ;// dP_1n - 30
+        ;// dQ_0n - 24
+        ;// dQ_1n - 25
+        
+        ;// delta = (q2 + ((p0+q0+1)>>1) - (q1<<1))>>1;
+        ;// dDeltaQ = (dQ_2 + dRp0q0)>>1;
+
+        VMAX        dP_1n, dDeltaP, dMinP   
+        VMAX        dDelta, dDelta, dTCs
+
+        ;// pQ0[-1*Step] = (OMX_U8)armClip(0, 255, dP_0 - delta);
+        ;// pQ0[0*Step] = (OMX_U8)armClip(0, 255, dQ_0 - delta);
+
+        ;// dP_0n = (OMX_U8)armClip(0, 255, dP_0 - dDelta);
+        ;// dQ_0n = (OMX_U8)armClip(0, 255, dP_0 - dDelta);
+        
+        ;// qP_0n - 14
+        ;// qQ_0n - 12
+        
+        VMOVL       qP_0n, dP_0
+        VMOVL       qQ_0n, dQ_0
+
+        VADDW       qP_0n, qP_0n, dDelta
+        VSUBW       qQ_0n, qQ_0n, dDelta
+        
+        VQMOVUN     dP_0n, qP_0n
+        VQMOVUN     dQ_0n, qQ_0n
+        
+        VMAX        dQ_1n, dDeltaQ, dMinQ
+
+        VMIN        dP_1n, dP_1n, dMaxP
+        VMIN        dQ_1n, dQ_1n, dMaxQ
+        VBIF        dP_0n, dP_0, dFilt      
+
+        VBIF        dP_1n, dP_1, dApflg
+        VBIF        dQ_0n, dQ_0, dFilt  
+        VBIF        dQ_1n, dQ_1, dAqflg
+
+        M_END
+
+;// Register usage for - armVCM4P10_DeblockingLumabSGE4_unsafe()
+;//
+;// Inputs - Pixels             - p0-p3: D4-D7, q0-q3: D8-D11
+;//        - Filter masks       - filt: D16, aqflg: D12, apflg: D17
+;//        - Additional Params  - alpha: D0, dMask_1: D15
+;//         
+;// Outputs - Pixels            - P0-P2: D29-D31, Q0-Q2: D24,D25,D28
+
+;// Registers Corrupted         - D18-D31
+
+        M_START armVCM4P10_DeblockingLumabSGE4_unsafe
+    
+
+        ;// ap<beta && armAbs(p0-q0)<((alpha>>2)+2)        
+        ;// aq<beta && armAbs(p0-q0)<((alpha>>2)+2)        
+
+        ;// ( dApflg & dAp0q0 < (dAlpha >> 2 + 2) )
+        ;// ( dAqflg & dAp0q0 < (dAlpha >> 2 + 2) )
+
+        ;// ( dApflg = dApflg & dAp0q0 < (dTemp + dMask_1 + dMask_1) )
+        ;// ( dAqflg = dAqflg & dAp0q0 < (dTemp + dMask_1 + dMask_1) )
+
+        ;// P Filter
+
+        VSHR        dTemp, dAlpha, #2
+        VADD        dTemp, dTemp, dMask_1
+
+        ;// qSp0q0-10
+        VADDL       qSp0q0, dQ_0, dP_0      
+        VADD        dTemp, dTemp, dMask_1
+
+        ;// qSp2q1-11
+        ;// qSp0q0p1-12
+        VADDL       qSp2q1, dP_2, dQ_1      
+        VADDW       qSp0q0p1, qSp0q0, dP_1  
+
+        VCGT        dTemp, dTemp, dAp0q0
+        VSHR        qSp2q1, #1              
+
+        ;// pQ0[-1*Step] = (OMX_U8)((p2 + 2*p1 + 2*p0 + 2*q0 + q1 + 4)>>3);
+        ;// pQ0[-1*Step] = ( ( (p0 + q0 + p1) + (p2 + q1)>>1 ) >> 1 + 1 ) >> 1
+
+        ;// dP_0n = ( ( (qSp0q0 + dP_1) + qSp2q1>>1 ) >> 1 + 1 ) >> 1
+        ;// dP_0n = ( ( qSp0q0p1 + qSp2q1>>1 ) >> 1 + 1 ) >> 1
+        ;// dP_0n = ( qTemp1 + 1 ) >> 1
+        
+        ;// pQ0[-2*Step] = (OMX_U8)((p2 + p1 + p0 + q0 + 2)>>2);
+        
+        ;// dP_1n = (OMX_U8)((dP_2 + qSp0q0p1 + 2)>>2);
+        ;// dP_1n = (OMX_U8)((qTemp2 + 2)>>2);
+        
+        ;// pQ0[-3*Step] = (OMX_U8)((2*p3 + 3*p2 + p1 + p0 + q0 + 4)>>3);
+        ;// pQ0[-3*Step] = (OMX_U8)(( (p3 + p2) + (p1 + p0 + q0 + p2) >> 1 + 2)>>2);
+
+        ;// dP_2n = (OMX_U8)(( qSp3p2 + (dP_2 + qSp0q0p1) >> 1 + 2) >> 2);
+        ;// dP_2n = (OMX_U8)(( qSp3p2 + qTemp2 >> 1 + 2) >> 2);
+
+        ;// qTemp1-qSp2q1-11
+        ;// qTemp2-qSp0q0p1-12
+        VHADD       qTemp1, qSp0q0p1, qSp2q1
+        VADDW       qTemp2, qSp0q0p1, dP_2  
+        
+        ;// qSp3p2-13
+        VADDL       qSp3p2, dP_3, dP_2      
+
+        VAND        dApflg, dApflg, dTemp
+        VHADD       dHSp0q1, dP_0, dQ_1     
+        VSRA        qSp3p2, qTemp2, #1      
+        ;// dHSp0q1-28
+        VAND        dAqflg, dAqflg, dTemp
+
+        ;// dP_0n-29
+        ;// dP_0t-dHSp0q1-28
+        VQRSHRN     dP_0n, qTemp1, #1
+        VRHADD      dP_0t, dHSp0q1, dP_1    
+
+        ;// dP_1n-30
+        VQRSHRN     dP_1n, qTemp2, #2
+        
+        VADDL       qSq2p1, dQ_2, dP_1          
+        VADDW       qSp0q0q1, qSp0q0, dQ_1      
+        
+        VBIF        dP_0n, dP_0t, dApflg    
+
+        ;// Q Filter
+
+        ;// pQ0[0*Step] = (OMX_U8)((q2 + 2*q1 + 2*q0 + 2*p0 + p1 + 4)>>3);
+        ;// pQ0[0*Step] = ( ( (p0 + q0 + q1) + (q2 + p1)>>1 ) >> 1 + 1 ) >> 1
+
+        ;// dQ_0n = ( ( (qSp0q0 + dQ_1) + qSq2p1>>1 ) >> 1 + 1 ) >> 1
+        ;// dQ_0n = ( ( qSp0q0q1 + qSq2p1>>1 ) >> 1 + 1 ) >> 1
+        ;// dQ_0n = ( qTemp1 + 1 ) >> 1
+        
+        ;// pQ0[1*Step] = (OMX_U8)((q2 + q1 + q0 + q0 + 2)>>2);
+        
+        ;// dQ_1n = (OMX_U8)((dQ_2 + qSp0q0q1 + 2)>>2);
+        ;// dQ_1n = (OMX_U8)((qTemp2 + 2)>>2);
+        
+        ;// pQ0[2*Step] = (OMX_U8)((2*q3 + 3*q2 + q1 + q0 + p0 + 4)>>3);
+        ;// pQ0[2*Step] = (OMX_U8)(( (q3 + q2) + (q1 + p0 + q0 + q2) >> 1 + 2)>>2);
+
+        ;// dQ_2n = (OMX_U8)(( qSq3q2 + (dQ_2 + qSp0q0q1) >> 1 + 2) >> 2);
+        ;// dQ_2n = (OMX_U8)(( qSq3q2 + qTemp2 >> 1 + 2) >> 2);
+
+        ;// qTemp1-qSp2q1-11
+        ;// qTemp2-qSp0q0p1-12
+        ;// qSq2p1-11
+        ;// qSp0q0q1-12
+
+
+        ;// qTemp2-qSp0q0p1-12
+        ;// qTemp1-qSq2p1-11
+        ;// qSq3q2-13
+        ;// dP_2n-31
+        
+        VQRSHRN     dP_2n, qSp3p2, #2
+        VADDL       qSq3q2, dQ_3, dQ_2          
+
+        VSHR        qSq2p1, #1                  
+
+        VHADD       qTemp1, qSp0q0q1, qSq2p1
+        VADDW       qTemp2, qSp0q0q1, dQ_2      
+
+        ;// dHSq0p1-28
+        VHADD       dHSq0p1, dQ_0, dP_1         
+
+        VBIF        dP_0n, dP_0, dFilt
+        VBIF        dP_1n, dP_1, dApflg
+
+        VSRA        qSq3q2, qTemp2, #1          
+
+        ;// dQ_1-Temp2-25
+        ;// dQ_0-Temp2-24
+        VQRSHRN     dQ_1n, qTemp2, #2
+        VQRSHRN     dQ_0n, qTemp1, #1
+
+        ;// dQ_0t-Temp1-22
+        VRHADD      dQ_0t, dHSq0p1, dQ_1
+        VBIF        dQ_1n, dQ_1, dAqflg         
+
+        VBIF        dP_2n, dP_2, dApflg        
+        VBIF        dQ_0n, dQ_0t, dAqflg        
+        VQRSHRN     dQ_2n, qSq3q2, #2
+        VBIF        dQ_0n, dQ_0, dFilt
+        VBIF        dQ_2n, dQ_2, dAqflg       
+
+        M_END
+        
+    ENDIF  
+
+
+        END
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_DecodeCoeffsToPair_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_DecodeCoeffsToPair_s.s
new file mode 100755
index 0000000..10a89e9
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_DecodeCoeffsToPair_s.s
@@ -0,0 +1,325 @@
+;//
+;// 
+;// File Name:  armVCM4P10_DecodeCoeffsToPair_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   12290
+;// Date:       Wednesday, April 9, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+        INCLUDE armCOMM_BitDec_s.h
+        
+        IMPORT armVCM4P10_CAVLCCoeffTokenTables
+        IMPORT armVCM4P10_CAVLCTotalZeroTables
+        IMPORT armVCM4P10_CAVLCTotalZeros2x2Tables
+        IMPORT armVCM4P10_CAVLCRunBeforeTables
+        IMPORT armVCM4P10_SuffixToLevel
+        IMPORT armVCM4P10_ZigZag_4x4
+        IMPORT armVCM4P10_ZigZag_2x2
+        
+        M_VARIANTS ARM1136JS
+        
+;//DEBUG_ON    SETL {TRUE}
+        
+LAST_COEFF               EQU 0x20        ;// End of block flag
+TWO_BYTE_COEFF           EQU 0x10
+
+;// Declare input registers
+
+ppBitStream     RN 0
+pOffset         RN 1
+pNumCoeff       RN 2
+ppPosCoefbuf    RN 3
+nC              RN 4 ;// number of coeffs or 17 for chroma
+sMaxNumCoeff    RN 5
+
+;// Declare inner loop registers
+
+;// Level loop
+Count           RN 0
+TrailingOnes    RN 1
+pLevel          RN 2
+LevelSuffix     RN 3
+SuffixLength    RN 4
+TotalCoeff      RN 5
+
+pVLDTable       RN 6
+Symbol          RN 7
+T1              RN 8
+T2              RN 9
+RBitStream      RN 10
+RBitBuffer      RN 11
+RBitCount       RN 12
+lr              RN 14
+
+;// Run loop
+Count           RN 0
+ZerosLeft       RN 1
+pLevel          RN 2
+ppRunTable      RN 3
+pRun            RN 4
+TotalCoeff      RN 5
+
+pVLDTable       RN 6
+Symbol          RN 7
+T1              RN 8
+T2              RN 9
+RBitStream      RN 10
+RBitBuffer      RN 11
+RBitCount       RN 12
+lr              RN 14
+
+;// Fill in coefficients loop
+pPosCoefbuf     RN 0
+temp            RN 1
+pLevel          RN 2
+ppPosCoefbuf    RN 3
+pRun            RN 4
+TotalCoeff      RN 5
+pZigZag         RN 6
+
+T1              RN 8
+T2              RN 9
+RBitStream      RN 10
+RBitBuffer      RN 11
+RBitCount       RN 12
+CoeffNum        RN 14
+
+
+
+    IF ARM1136JS
+        
+        ;// Allocate stack memory required by the function
+        M_ALLOC4 pppBitStream, 4
+        M_ALLOC4 ppOffset, 4
+        M_ALLOC4 pppPosCoefbuf, 4
+        M_ALLOC4 ppLevel, 16*2
+        M_ALLOC4 ppRun, 16
+        
+        ;// Write function header
+        M_START armVCM4P10_DecodeCoeffsToPair, r11
+        
+        ;// Define stack arguments
+        M_ARG   pNC, 4
+        M_ARG   pSMaxNumCoeff,4
+        
+        ;// Code start        
+        M_BD_INIT0 ppBitStream, pOffset, RBitStream, RBitBuffer, RBitCount
+        LDR        pVLDTable, =armVCM4P10_CAVLCCoeffTokenTables
+        M_LDR      nC, pNC
+        
+        M_BD_INIT1 T1, T2, lr
+        LDR     pVLDTable, [pVLDTable, nC, LSL #2]  ;// Find VLD table    
+        
+        M_BD_INIT2 T1, T2, lr
+
+        ;// Decode Symbol = TotalCoeff*4 + TrailingOnes
+        M_BD_VLD  Symbol, T1, T2, pVLDTable, 4, 2
+    
+        MOVS    TotalCoeff, Symbol, LSR #2    
+        STRB    TotalCoeff, [pNumCoeff]    
+        M_PRINTF "TotalCoeff=%d\n", TotalCoeff
+        BEQ.W   EndNoError                  ;// Finished if no coefficients
+
+        CMP     Symbol, #17*4
+        BGE.W   EndBadSymbol                ;// Error if bad symbol
+        
+        ;// Save bitstream pointers
+        M_STR   ppBitStream,  pppBitStream
+        M_STR   pOffset,      ppOffset
+        M_STR   ppPosCoefbuf, pppPosCoefbuf                
+        
+        ;// Decode Trailing Ones
+        ANDS    TrailingOnes, Symbol, #3
+        M_ADR   pLevel, ppLevel            
+        M_PRINTF "TrailingOnes=%d\n", TrailingOnes
+        BEQ     TrailingOnesDone    
+        MOV     Count, TrailingOnes
+TrailingOnesLoop    
+        M_BD_READ8 Symbol, 1, T1
+        SUBS    Count, Count, #1
+        MOV     T1, #1
+        SUB     T1, T1, Symbol, LSL #1
+        M_PRINTF "Level=%d\n", T1
+        STRH    T1, [pLevel], #2
+        BGT     TrailingOnesLoop
+TrailingOnesDone    
+    
+        ;// Decode level values    
+        SUBS    Count, TotalCoeff, TrailingOnes     ;// Number of levels to read
+        BEQ     DecodeRuns                          ;// None left
+        
+        MOV     SuffixLength, #1
+        CMP     TotalCoeff, #10
+        MOVLE   SuffixLength, #0
+        CMP     TrailingOnes, #3    ;// if (TrailingOnes<3)
+        MOVLT   TrailingOnes, #4    ;// then TrailingOnes = +4
+        MOVGE   TrailingOnes, #2    ;// else TrailingOnes = +2
+        MOVGE   SuffixLength, #0    ;//      SuffixLength = 0
+        
+LevelLoop
+        M_BD_CLZ16 Symbol, T1, T2   ;// Symbol=LevelPrefix
+        CMP     Symbol,#16
+        BGE     EndBadSymbol
+        
+        MOVS    lr, SuffixLength    ;// if LevelSuffixSize==0
+        TEQEQ   Symbol, #14         ;//   and  LevelPrefix==14
+        MOVEQ   lr, #4              ;//   then LevelSuffixSize=4
+        TEQ     Symbol, #15         ;// if LevelSuffixSize==15
+        MOVEQ   lr, #12             ;//   then LevelSuffixSize=12
+        
+        TEQEQ   SuffixLength,#0
+        ADDEQ   Symbol,Symbol,#15
+        
+        TEQ     lr, #0              ;// if LevelSuffixSize==0
+        BEQ     LevelCodeRead       ;// LevelCode = LevelPrefix
+        
+        M_BD_VREAD16 LevelSuffix, lr, T1, T2  ;// Read Level Suffix
+        
+        MOV     Symbol, Symbol, LSL SuffixLength
+        ADD     Symbol, LevelSuffix, Symbol
+             
+LevelCodeRead        
+        ;// Symbol = LevelCode
+        ADD     Symbol, Symbol, TrailingOnes ;// +4 if level cannot be +/-1, +2 o/w
+        MOV     TrailingOnes, #2
+        MOVS    T1, Symbol, LSR #1
+        RSBCS   T1, T1, #0                  ;// If Symbol odd then negate
+        M_PRINTF "Level=%d\n", T1
+        STRH    T1, [pLevel], #2            ;// Store level.
+        
+        LDR     T2, =armVCM4P10_SuffixToLevel
+        LDRSB   T1, [T2, SuffixLength]      ;// Find increment level        
+        TEQ     SuffixLength, #0
+        MOVEQ   SuffixLength, #1
+        CMP     Symbol, T1
+        ADDCS   SuffixLength, SuffixLength, #1        
+        SUBS    Count, Count, #1        
+        BGT     LevelLoop
+        
+DecodeRuns        
+        ;// Find number of zeros
+        M_LDR   T1, pSMaxNumCoeff           ;// sMaxNumCoeff
+        SUB     Count, TotalCoeff, #1       ;// Number of runs excluding last
+        SUBS    ZerosLeft, T1, TotalCoeff   ;// Maximum number of zeros there could be
+        M_ADR   pRun, ppRun
+        MOV     CoeffNum,TotalCoeff
+        SUB     CoeffNum,CoeffNum,#1
+        BEQ     NoZerosLeft
+        
+        ;// Unpack number of zeros from bitstream
+        TEQ     T1, #4        
+        LDREQ   pVLDTable, =(armVCM4P10_CAVLCTotalZeros2x2Tables-4)
+        LDRNE   pVLDTable, =(armVCM4P10_CAVLCTotalZeroTables-4)
+        LDR     pVLDTable, [pVLDTable, TotalCoeff, LSL #2]
+        
+        M_BD_VLD  Symbol, T1, T2, pVLDTable, 4, 2 ;// Symbol = ZerosLeft
+        CMP     Symbol,#16
+        BGE     EndBadSymbol
+
+        LDR     ppRunTable, =(armVCM4P10_CAVLCRunBeforeTables-4)
+        M_ADR   pRun, ppRun
+        MOVS    ZerosLeft, Symbol
+
+        ADD     CoeffNum,CoeffNum,ZerosLeft        
+
+        BEQ     NoZerosLeft
+        
+        ;// Decode runs while zeros are left and more than one coefficient
+RunLoop 
+        SUBS    Count, Count, #1
+        LDR     pVLDTable, [ppRunTable, ZerosLeft, LSL#2]
+        BLT     LastRun
+        M_BD_VLD  Symbol, T1, T2, pVLDTable, 3, 2 ;// Symbol = Run
+        CMP     Symbol,#15         
+        BGE     EndBadSymbol        
+
+        SUBS    ZerosLeft, ZerosLeft, Symbol
+        M_PRINTF "Run=%d\n", Symbol
+        STRB    Symbol, [pRun], #1
+        BGT     RunLoop
+        
+        ;// Decode runs while no zeros are left
+NoZerosLeft 
+        SUBS    Count, Count, #1
+        M_PRINTF "Run=%d\n", ZerosLeft
+        STRGEB  ZerosLeft, [pRun], #1
+        BGT     NoZerosLeft
+
+LastRun        
+        ;// Final run length is remaining zeros
+        M_PRINTF "LastRun=%d\n", ZerosLeft
+        STRB    ZerosLeft, [pRun], #1        
+        
+        ;// Write coefficients to output array
+        M_LDR   T1, pSMaxNumCoeff                    ;// sMaxNumCoeff
+        TEQ     T1, #15
+        ADDEQ   CoeffNum,CoeffNum,#1
+        
+
+        SUB     pRun,pRun,TotalCoeff
+        SUB     pLevel,pLevel,TotalCoeff  
+        SUB     pLevel,pLevel,TotalCoeff   
+
+        M_LDR   ppPosCoefbuf, pppPosCoefbuf
+        LDR     pPosCoefbuf, [ppPosCoefbuf]
+        TEQ     T1, #4
+        LDREQ   pZigZag, =armVCM4P10_ZigZag_2x2
+        LDRNE   pZigZag, =armVCM4P10_ZigZag_4x4
+
+        
+        
+OutputLoop
+        
+        LDRB    T2, [pRun],#1
+        LDRB    T1, [pZigZag, CoeffNum]
+        SUB     CoeffNum, CoeffNum, #1      ;// Skip Non zero
+        SUB     CoeffNum, CoeffNum, T2      ;// Skip Zero run
+        
+        LDRSH   T2, [pLevel],#2
+        
+        SUBS    TotalCoeff, TotalCoeff, #1       
+        ORREQ   T1, T1, #LAST_COEFF
+        
+        ADD     temp, T2, #128
+        CMP     temp, #256
+        ORRCS   T1, T1, #TWO_BYTE_COEFF
+
+        
+        TEQ     TotalCoeff, #0              ;// Preserves carry        
+        
+        M_PRINTF "Output=%02x %04x\n", T1, T2
+        STRB    T1, [pPosCoefbuf], #1
+        STRB    T2, [pPosCoefbuf], #1
+        MOV     T2, T2, LSR #8
+        STRCSB  T2, [pPosCoefbuf], #1                
+        BNE     OutputLoop
+        
+        ;// Finished
+        STR     pPosCoefbuf, [ppPosCoefbuf]
+        M_LDR   ppBitStream, pppBitStream
+        M_LDR   pOffset, ppOffset
+        B       EndNoError
+            
+EndBadSymbol
+        MOV     r0, #OMX_Sts_Err
+        B       End    
+        
+EndNoError
+        ;// Finished reading from the bitstream                
+        M_BD_FINI ppBitStream, pOffset
+        
+        ;// Set return value
+        MOV     r0, #OMX_Sts_NoErr    
+End
+        M_END
+    
+    ENDIF
+    
+    END
+    
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_DequantTables_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_DequantTables_s.s
new file mode 100755
index 0000000..2761600
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_DequantTables_s.s
@@ -0,0 +1,123 @@
+;//
+;// 
+;// File Name:  armVCM4P10_DequantTables_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   12290
+;// Date:       Wednesday, April 9, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+        
+
+         INCLUDE omxtypes_s.h
+         INCLUDE armCOMM_s.h
+     
+         EXPORT armVCM4P10_QPDivTable
+         EXPORT armVCM4P10_VMatrixQPModTable
+         EXPORT armVCM4P10_PosToVCol4x4
+         EXPORT armVCM4P10_PosToVCol2x2
+         EXPORT armVCM4P10_VMatrix 
+         EXPORT armVCM4P10_QPModuloTable
+         EXPORT armVCM4P10_VMatrixU16
+         
+;// Define the processor variants supported by this file
+         
+         M_VARIANTS CortexA8
+           
+         
+;// Guarding implementation by the processor name
+
+    
+    IF CortexA8
+           
+ 
+         M_TABLE armVCM4P10_PosToVCol4x4
+         DCB  0, 2, 0, 2
+         DCB  2, 1, 2, 1
+         DCB  0, 2, 0, 2
+         DCB  2, 1, 2, 1
+
+
+         M_TABLE armVCM4P10_PosToVCol2x2
+         DCB  0, 2
+         DCB  2, 1
+
+
+         M_TABLE armVCM4P10_VMatrix
+         DCB  10, 16, 13
+         DCB  11, 18, 14
+         DCB  13, 20, 16
+         DCB  14, 23, 18
+         DCB  16, 25, 20
+         DCB  18, 29, 23
+
+;//-------------------------------------------------------
+;// This table evaluates the expression [(INT)(QP/6)],
+;// for values of QP from 0 to 51 (inclusive). 
+;//-------------------------------------------------------
+
+         M_TABLE armVCM4P10_QPDivTable
+         DCB  0,  0,  0,  0,  0,  0
+         DCB  1,  1,  1,  1,  1,  1
+         DCB  2,  2,  2,  2,  2,  2
+         DCB  3,  3,  3,  3,  3,  3
+         DCB  4,  4,  4,  4,  4,  4
+         DCB  5,  5,  5,  5,  5,  5
+         DCB  6,  6,  6,  6,  6,  6
+         DCB  7,  7,  7,  7,  7,  7
+         DCB  8,  8,  8,  8,  8,  8
+    
+;//----------------------------------------------------
+;// This table contains armVCM4P10_VMatrix[QP%6][0] entires,
+;// for values of QP from 0 to 51 (inclusive). 
+;//----------------------------------------------------
+
+         M_TABLE armVCM4P10_VMatrixQPModTable
+         DCB 10, 11, 13, 14, 16, 18
+         DCB 10, 11, 13, 14, 16, 18
+         DCB 10, 11, 13, 14, 16, 18
+         DCB 10, 11, 13, 14, 16, 18
+         DCB 10, 11, 13, 14, 16, 18
+         DCB 10, 11, 13, 14, 16, 18
+         DCB 10, 11, 13, 14, 16, 18
+         DCB 10, 11, 13, 14, 16, 18
+         DCB 10, 11, 13, 14, 16, 18
+    
+;//-------------------------------------------------------
+;// This table evaluates the modulus expression [QP%6]*6,
+;// for values of QP from 0 to 51 (inclusive). 
+;//-------------------------------------------------------
+
+         M_TABLE armVCM4P10_QPModuloTable
+         DCB 0, 6, 12, 18, 24, 30
+         DCB 0, 6, 12, 18, 24, 30
+         DCB 0, 6, 12, 18, 24, 30
+         DCB 0, 6, 12, 18, 24, 30
+         DCB 0, 6, 12, 18, 24, 30
+         DCB 0, 6, 12, 18, 24, 30
+         DCB 0, 6, 12, 18, 24, 30
+         DCB 0, 6, 12, 18, 24, 30
+         DCB 0, 6, 12, 18, 24, 30
+        
+;//-------------------------------------------------------
+;// This table contains the invidual byte values stored as
+;// halfwords. This avoids unpacking inside the function
+;//-------------------------------------------------------
+        
+         M_TABLE armVCM4P10_VMatrixU16
+         DCW 10, 16, 13 
+         DCW 11, 18, 14
+         DCW 13, 20, 16
+         DCW 14, 23, 18
+         DCW 16, 25, 20
+         DCW 18, 29, 23 
+         
+    ENDIF                                                           ;//ARM1136JS            
+
+
+                           
+    
+         END
\ No newline at end of file
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_InterpolateLuma_Align_unsafe_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_InterpolateLuma_Align_unsafe_s.s
new file mode 100755
index 0000000..6e912d7
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_InterpolateLuma_Align_unsafe_s.s
@@ -0,0 +1,236 @@
+;//
+;// 
+;// File Name:  armVCM4P10_InterpolateLuma_Align_unsafe_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   12290
+;// Date:       Wednesday, April 9, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+        
+        M_VARIANTS ARM1136JS
+
+        EXPORT armVCM4P10_InterpolateLuma_HorAlign9x_unsafe
+        EXPORT armVCM4P10_InterpolateLuma_VerAlign4x_unsafe
+
+DEBUG_ON    SETL {FALSE}
+
+    IF ARM1136JS 
+
+;// Declare input registers
+pSrc            RN 0
+srcStep         RN 1
+pDst            RN 8
+iHeight         RN 9
+
+;// Declare inner loop registers
+x               RN 7
+x0              RN 7
+x1              RN 10
+x2              RN 11
+Scratch         RN 12
+
+;// Function: 
+;//     armVCM4P10_InterpolateLuma_HorAlign9x_unsafe
+;//
+;// Implements copy from an arbitrary aligned source memory location (pSrc) to a 4 byte aligned
+;// destination pointed by (pDst) for horizontal interpolation.
+;// This function needs to copy 9 bytes in horizontal direction. 
+;//
+;// Registers used as input for this function
+;// r0,r1,r8,r9 where r8 containings aligned memory pointer and r9 no rows to copy
+;//
+;// Registers preserved for top level function
+;// r2,r3,r4,r5,r6
+;//
+;// Registers modified by the function
+;// r7,r8,r9,r10,r11,r12
+;//
+;// Output registers
+;// r0 - pointer to the new aligned location which will be used as pSrc
+;// r1 - step size to this aligned location
+
+        ;// Function header
+        M_START armVCM4P10_InterpolateLuma_HorAlign9x_unsafe     
+        
+        ;// Copy pDst to scratch
+        MOV     Scratch, pDst
+
+StartAlignedStackCopy
+        AND     x, pSrc, #3
+        BIC     pSrc, pSrc, #3
+        
+        M_SWITCH x
+        M_CASE   Copy0toAligned
+        M_CASE   Copy1toAligned
+        M_CASE   Copy2toAligned
+        M_CASE   Copy3toAligned
+        M_ENDSWITCH
+
+Copy0toAligned  
+        LDM     pSrc, {x0, x1, x2}
+        SUBS    iHeight, iHeight, #1
+        ADD     pSrc, pSrc, srcStep
+        
+        ;// One cycle stall
+
+        STM     pDst!, {x0, x1, x2}                     ;// Store aligned output row
+        BGT     Copy0toAligned
+        B       CopyEnd  
+      
+Copy1toAligned        
+        LDM     pSrc, {x0, x1, x2}
+        SUBS    iHeight, iHeight, #1
+        ADD     pSrc, pSrc, srcStep
+        
+        ;// One cycle stall
+
+        MOV     x0, x0, LSR #8
+        ORR     x0, x0, x1, LSL #24
+        MOV     x1, x1, LSR #8
+        ORR     x1, x1, x2, LSL #24
+        MOV     x2, x2, LSR #8
+        STM     pDst!, {x0, x1, x2}                     ;// Store aligned output row
+        BGT     Copy1toAligned
+        B       CopyEnd  
+
+Copy2toAligned        
+        LDM     pSrc, {x0, x1, x2}
+        SUBS    iHeight, iHeight, #1
+        ADD     pSrc, pSrc, srcStep
+        
+        ;// One cycle stall
+
+        MOV     x0, x0, LSR #16
+        ORR     x0, x0, x1, LSL #16
+        MOV     x1, x1, LSR #16
+        ORR     x1, x1, x2, LSL #16
+        MOV     x2, x2, LSR #16
+        STM     pDst!, {x0, x1, x2}                     ;// Store aligned output row
+        BGT     Copy2toAligned
+        B       CopyEnd  
+
+Copy3toAligned        
+        LDM     pSrc, {x0, x1, x2}
+        SUBS    iHeight, iHeight, #1
+        ADD     pSrc, pSrc, srcStep
+        
+        ;// One cycle stall
+
+        MOV     x0, x0, LSR #24
+        ORR     x0, x0, x1, LSL #8
+        MOV     x1, x1, LSR #24
+        ORR     x1, x1, x2, LSL #8
+        MOV     x2, x2, LSR #24
+        STM     pDst!, {x0, x1, x2}                     ;// Store aligned output row
+        BGT     Copy3toAligned
+
+CopyEnd  
+        
+        MOV     pSrc, Scratch
+        MOV     srcStep, #12
+
+        M_END
+    
+
+;// Function:
+;//     armVCM4P10_InterpolateLuma_VerAlign4x_unsafe
+;//
+;// Implements copy from an arbitrary aligned source memory location (pSrc) to an aligned
+;// destination pointed by (pDst) for vertical interpolation.
+;// This function needs to copy 4 bytes in horizontal direction 
+;//
+;// Registers used as input for this function
+;// r0,r1,r8,r9 where r8 containings aligned memory pointer and r9 no of rows to copy
+;//
+;// Registers preserved for top level function
+;// r2,r3,r4,r5,r6
+;//
+;// Registers modified by the function
+;// r7,r8,r9,r10,r11,r12
+;//
+;// Output registers
+;// r0 - pointer to the new aligned location which will be used as pSrc
+;// r1 - step size to this aligned location
+
+        ;// Function header
+        M_START armVCM4P10_InterpolateLuma_VerAlign4x_unsafe     
+        
+        ;// Copy pSrc to stack
+StartVAlignedStackCopy
+        AND     x, pSrc, #3
+        BIC     pSrc, pSrc, #3                        
+        
+        
+        M_SWITCH x
+        M_CASE   Copy0toVAligned
+        M_CASE   Copy1toVAligned
+        M_CASE   Copy2toVAligned
+        M_CASE   Copy3toVAligned
+        M_ENDSWITCH
+        
+Copy0toVAligned  
+        M_LDR   x0, [pSrc], srcStep
+        SUBS    iHeight, iHeight, #1
+        
+        ;// One cycle stall
+
+        STR     x0, [pDst], #4                              ;// Store aligned output row
+        BGT     Copy0toVAligned
+        B       CopyVEnd  
+      
+Copy1toVAligned        
+        LDR     x1, [pSrc, #4]
+        M_LDR   x0, [pSrc], srcStep
+        SUBS    iHeight, iHeight, #1        
+        
+        ;// One cycle stall
+
+        MOV     x1, x1, LSL #24
+        ORR     x0, x1, x0, LSR #8
+        STR     x0, [pDst], #4                              ;// Store aligned output row
+        BGT     Copy1toVAligned
+        B       CopyVEnd  
+
+Copy2toVAligned        
+        LDR     x1, [pSrc, #4]
+        M_LDR   x0, [pSrc], srcStep
+        SUBS    iHeight, iHeight, #1        
+        
+        ;// One cycle stall
+
+        MOV     x1, x1, LSL #16
+        ORR     x0, x1, x0, LSR #16
+        STR     x0, [pDst], #4                              ;// Store aligned output row
+        BGT     Copy2toVAligned
+        B       CopyVEnd  
+
+Copy3toVAligned        
+        LDR     x1, [pSrc, #4]
+        M_LDR   x0, [pSrc], srcStep
+        SUBS    iHeight, iHeight, #1        
+        
+        ;// One cycle stall
+
+        MOV     x1, x1, LSL #8
+        ORR     x0, x1, x0, LSR #24
+        STR     x0, [pDst], #4                              ;// Store aligned output row
+        BGT     Copy3toVAligned
+
+CopyVEnd  
+
+        SUB     pSrc, pDst, #28
+        MOV     srcStep, #4
+
+        M_END
+
+
+    ENDIF
+
+    END
+    
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_InterpolateLuma_Copy_unsafe_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_InterpolateLuma_Copy_unsafe_s.s
new file mode 100755
index 0000000..d2758912
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_InterpolateLuma_Copy_unsafe_s.s
@@ -0,0 +1,149 @@
+;//
+;// 
+;// File Name:  armVCM4P10_InterpolateLuma_Copy_unsafe_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   12290
+;// Date:       Wednesday, April 9, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+;// Function:
+;//     armVCM4P10_InterpolateLuma_Copy4x4_unsafe 
+;//
+;// Implements copy from an arbitrary aligned source memory location (pSrc) to an aligned
+;// destination pointed by (pDst)
+;//
+;// Registers preserved for top level function
+;// r1,r3,r4,r5,r6,r7,r10,r11,r14
+;//
+;// Registers modified by the function
+;// r0,r2,r8,r9,r12
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+        
+        M_VARIANTS ARM1136JS
+
+        EXPORT armVCM4P10_InterpolateLuma_Copy4x4_unsafe
+        
+;// Declare input registers
+pSrc            RN 0
+srcStep         RN 1
+pDst            RN 2
+dstStep         RN 3
+
+;// Declare other intermediate registers
+x0              RN 4
+x1              RN 5
+x2              RN 8
+x3              RN 9
+Temp            RN 12
+
+    IF ARM1136JS
+
+        M_START armVCM4P10_InterpolateLuma_Copy4x4_unsafe, r6
+
+Copy4x4Start
+        ;// Do Copy and branch to EndOfInterpolation
+        AND     Temp, pSrc, #3
+        BIC     pSrc, pSrc, #3                        
+
+        M_SWITCH Temp
+        M_CASE  Copy4x4Align0
+        M_CASE  Copy4x4Align1
+        M_CASE  Copy4x4Align2
+        M_CASE  Copy4x4Align3
+        M_ENDSWITCH
+
+Copy4x4Align0
+        M_LDR   x0, [pSrc], srcStep
+        M_LDR   x1, [pSrc], srcStep
+        M_STR   x0, [pDst], dstStep
+        M_LDR   x2, [pSrc], srcStep
+        M_STR   x1, [pDst], dstStep
+        M_LDR   x3, [pSrc], srcStep
+        M_STR   x2, [pDst], dstStep
+        M_STR   x3, [pDst], dstStep
+        B       Copy4x4End  
+
+Copy4x4Align1
+        LDR     x1, [pSrc, #4]
+        M_LDR   x0, [pSrc], srcStep
+        LDR     x3, [pSrc, #4]
+        M_LDR   x2, [pSrc], srcStep
+        MOV     x0, x0, LSR #8
+        ORR     x0, x0, x1, LSL #24
+        M_STR   x0, [pDst], dstStep
+        MOV     x2, x2, LSR #8
+        ORR     x2, x2, x3, LSL #24
+        LDR     x1, [pSrc, #4]
+        M_LDR   x0, [pSrc], srcStep
+        M_STR   x2, [pDst], dstStep
+        LDR     x3, [pSrc, #4]
+        M_LDR   x2, [pSrc], srcStep
+        MOV     x0, x0, LSR #8
+        ORR     x0, x0, x1, LSL #24
+        M_STR   x0, [pDst], dstStep
+        MOV     x2, x2, LSR #8
+        ORR     x2, x2, x3, LSL #24
+        M_STR   x2, [pDst], dstStep
+        B       Copy4x4End  
+      
+Copy4x4Align2
+        LDR     x1, [pSrc, #4]
+        M_LDR   x0, [pSrc], srcStep
+        LDR     x3, [pSrc, #4]
+        M_LDR   x2, [pSrc], srcStep
+        MOV     x0, x0, LSR #16
+        ORR     x0, x0, x1, LSL #16
+        M_STR   x0, [pDst], dstStep
+        MOV     x2, x2, LSR #16
+        ORR     x2, x2, x3, LSL #16
+        M_STR   x2, [pDst], dstStep        
+
+        LDR     x1, [pSrc, #4]
+        M_LDR   x0, [pSrc], srcStep
+        LDR     x3, [pSrc, #4]
+        M_LDR   x2, [pSrc], srcStep
+        MOV     x0, x0, LSR #16
+        ORR     x0, x0, x1, LSL #16
+        M_STR   x0, [pDst], dstStep
+        MOV     x2, x2, LSR #16
+        ORR     x2, x2, x3, LSL #16
+        M_STR   x2, [pDst], dstStep        
+        B       Copy4x4End  
+
+Copy4x4Align3 
+        LDR     x1, [pSrc, #4]
+        M_LDR   x0, [pSrc], srcStep
+        LDR     x3, [pSrc, #4]
+        M_LDR   x2, [pSrc], srcStep
+        MOV     x0, x0, LSR #24
+        ORR     x0, x0, x1, LSL #8
+        M_STR   x0, [pDst], dstStep
+        MOV     x2, x2, LSR #24
+        ORR     x2, x2, x3, LSL #8
+        M_STR   x2, [pDst], dstStep
+
+        LDR     x1, [pSrc, #4]
+        M_LDR   x0, [pSrc], srcStep
+        LDR     x3, [pSrc, #4]
+        M_LDR   x2, [pSrc], srcStep
+        MOV     x0, x0, LSR #24
+        ORR     x0, x0, x1, LSL #8
+        M_STR   x0, [pDst], dstStep
+        MOV     x2, x2, LSR #24
+        ORR     x2, x2, x3, LSL #8
+        M_STR   x2, [pDst], dstStep
+        B       Copy4x4End  
+
+Copy4x4End
+        M_END
+
+    ENDIF
+
+    END
+    
\ No newline at end of file
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_InterpolateLuma_DiagCopy_unsafe_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_InterpolateLuma_DiagCopy_unsafe_s.s
new file mode 100755
index 0000000..4e5a39d
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_InterpolateLuma_DiagCopy_unsafe_s.s
@@ -0,0 +1,178 @@
+;//
+;// 
+;// File Name:  armVCM4P10_InterpolateLuma_DiagCopy_unsafe_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   12290
+;// Date:       Wednesday, April 9, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+        
+        M_VARIANTS ARM1136JS
+
+        EXPORT armVCM4P10_InterpolateLuma_HorDiagCopy_unsafe
+        EXPORT armVCM4P10_InterpolateLuma_VerDiagCopy_unsafe
+
+;// Functions: 
+;//     armVCM4P10_InterpolateLuma_HorDiagCopy_unsafe and
+;//     armVCM4P10_InterpolateLuma_VerDiagCopy_unsafe 
+;//
+;// Implements re-arrangement of data from temporary buffer to a buffer pointed by pBuf.
+;// This will do the convertion of data from 16 bit to 8 bit and it also
+;// remove offset and check for saturation.
+;//
+;// Registers used as input for this function
+;// r0,r1,r7 where r0 is input pointer and r2 its step size, r7 is output pointer
+;//
+;// Registers preserved for top level function
+;// r4,r5,r6,r8,r9,r14
+;//
+;// Registers modified by the function
+;// r7,r10,r11,r12
+;//
+;// Output registers
+;// r0 - pointer to the destination location
+;// r1 - step size to this destination location
+
+
+DEBUG_ON    SETL {FALSE}
+        
+MASK            EQU 0x80808080  ;// Mask is used to implement (a+b+1)/2
+
+;// Declare input registers
+
+pSrc0           RN 0
+srcStep0        RN 1
+
+;// Declare other intermediate registers
+Temp1           RN 4
+Temp2           RN 5
+Temp3           RN 10
+Temp4           RN 11
+pBuf            RN 7
+r0x0fe00fe0     RN 6
+r0x00ff00ff     RN 12
+Count           RN 14
+ValueA0         RN 10
+ValueA1         RN 11
+
+    IF ARM1136JS
+
+
+        ;// Function header
+        M_START armVCM4P10_InterpolateLuma_HorDiagCopy_unsafe, r6
+
+        ;// Code start     
+        MOV         Count, #4   
+        LDR         r0x0fe00fe0, =0x0fe00fe0
+        LDR         r0x00ff00ff, =0x00ff00ff        
+LoopStart1
+        LDR         Temp4, [pSrc0, #12]
+        LDR         Temp3, [pSrc0, #8]        
+        LDR         Temp2, [pSrc0, #4]
+        M_LDR       Temp1, [pSrc0], srcStep0              
+        UQSUB16     Temp4, Temp4, r0x0fe00fe0        
+        UQSUB16     Temp3, Temp3, r0x0fe00fe0                 
+        UQSUB16     Temp2, Temp2, r0x0fe00fe0        
+        UQSUB16     Temp1, Temp1, r0x0fe00fe0                 
+        USAT16      Temp4, #13, Temp4
+        USAT16      Temp3, #13, Temp3                          
+        USAT16      Temp2, #13, Temp2
+        USAT16      Temp1, #13, Temp1                                  
+        AND         Temp4, r0x00ff00ff, Temp4, LSR #5         
+        AND         Temp3, r0x00ff00ff, Temp3, LSR #5         
+        AND         Temp2, r0x00ff00ff, Temp2, LSR #5         
+        AND         Temp1, r0x00ff00ff, Temp1, LSR #5         
+        ORR         ValueA1, Temp3, Temp4, LSL #8             
+        ORR         ValueA0, Temp1, Temp2, LSL #8             
+        SUBS        Count, Count, #1                   
+        STRD        ValueA0, [pBuf], #8 
+        BGT         LoopStart1
+End1
+        SUB        pSrc0, pBuf, #32
+        MOV        srcStep0, #8
+
+        M_END
+
+
+        ;// Function header
+        M_START armVCM4P10_InterpolateLuma_VerDiagCopy_unsafe, r6
+        
+        ;// Code start        
+        LDR         r0x0fe00fe0, =0x0fe00fe0
+        LDR         r0x00ff00ff, =0x00ff00ff
+        MOV         Count, #2
+
+LoopStart    
+        LDR         Temp4, [pSrc0, #12]
+        LDR         Temp3, [pSrc0, #8]        
+        LDR         Temp2, [pSrc0, #4]
+        M_LDR       Temp1, [pSrc0], srcStep0
+        
+        UQSUB16     Temp4, Temp4, r0x0fe00fe0        
+        UQSUB16     Temp3, Temp3, r0x0fe00fe0                 
+        UQSUB16     Temp2, Temp2, r0x0fe00fe0        
+        UQSUB16     Temp1, Temp1, r0x0fe00fe0                 
+        
+        USAT16      Temp4, #13, Temp4
+        USAT16      Temp3, #13, Temp3                          
+        USAT16      Temp2, #13, Temp2
+        USAT16      Temp1, #13, Temp1
+                                  
+        AND         Temp4, r0x00ff00ff, Temp4, LSR #5         
+        AND         Temp3, r0x00ff00ff, Temp3, LSR #5         
+        AND         Temp2, r0x00ff00ff, Temp2, LSR #5         
+        AND         Temp1, r0x00ff00ff, Temp1, LSR #5         
+        ORR         ValueA1, Temp3, Temp4, LSL #8        ;// [d2 c2 d0 c0]             
+        ORR         ValueA0, Temp1, Temp2, LSL #8        ;// [b2 a2 b0 a0]         
+                    
+        PKHBT       Temp1, ValueA0, ValueA1, LSL #16     ;// [d0 c0 b0 a0]
+
+        STR         Temp1, [pBuf], #8 
+        PKHTB       Temp2, ValueA1, ValueA0, ASR #16     ;// [d2 c2 b2 a2]
+        STR         Temp2, [pBuf], #-4  
+
+        LDR         Temp4, [pSrc0, #12]
+        LDR         Temp3, [pSrc0, #8]        
+        LDR         Temp2, [pSrc0, #4]
+        M_LDR       Temp1, [pSrc0], srcStep0
+        
+        UQSUB16     Temp4, Temp4, r0x0fe00fe0        
+        UQSUB16     Temp3, Temp3, r0x0fe00fe0                 
+        UQSUB16     Temp2, Temp2, r0x0fe00fe0        
+        UQSUB16     Temp1, Temp1, r0x0fe00fe0                 
+        
+        USAT16      Temp4, #13, Temp4
+        USAT16      Temp3, #13, Temp3                          
+        USAT16      Temp2, #13, Temp2
+        USAT16      Temp1, #13, Temp1
+                                  
+        AND         Temp4, r0x00ff00ff, Temp4, LSR #5         
+        AND         Temp3, r0x00ff00ff, Temp3, LSR #5         
+        AND         Temp2, r0x00ff00ff, Temp2, LSR #5         
+        AND         Temp1, r0x00ff00ff, Temp1, LSR #5         
+        ORR         ValueA1, Temp3, Temp4, LSL #8        ;// [d2 c2 d0 c0]             
+        ORR         ValueA0, Temp1, Temp2, LSL #8        ;// [b2 a2 b0 a0]         
+                    
+        PKHBT       Temp1, ValueA0, ValueA1, LSL #16     ;// [d0 c0 b0 a0]
+        SUBS        Count, Count, #1
+        STR         Temp1, [pBuf], #8 
+        PKHTB       Temp2, ValueA1, ValueA0, ASR #16     ;// [d2 c2 b2 a2]
+        STR         Temp2, [pBuf], #4  
+        
+        BGT         LoopStart
+End2
+        SUB         pSrc0, pBuf, #32-8
+        MOV         srcStep0, #4
+
+        M_END
+
+    ENDIF
+    
+    END
+    
\ No newline at end of file
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_InterpolateLuma_HalfDiagHorVer4x4_unsafe_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_InterpolateLuma_HalfDiagHorVer4x4_unsafe_s.s
new file mode 100755
index 0000000..d1684cb
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_InterpolateLuma_HalfDiagHorVer4x4_unsafe_s.s
@@ -0,0 +1,313 @@
+;//
+;// 
+;// File Name:  armVCM4P10_InterpolateLuma_HalfDiagHorVer4x4_unsafe_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   12290
+;// Date:       Wednesday, April 9, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+        
+        EXPORT armVCM4P10_InterpolateLuma_HalfDiagHorVer4x4_unsafe
+
+        M_VARIANTS CortexA8
+
+    IF CortexA8
+
+        M_START armVCM4P10_InterpolateLuma_HalfDiagHorVer4x4_unsafe, r11
+
+;// Declare input registers
+pSrc            RN 0
+srcStep         RN 1
+pDst            RN 2
+dstStep         RN 3
+
+;// Declare Neon registers
+dCoeff5         DN 30.S16
+dCoeff20        DN 31.S16
+qCoeff5         QN 14.S32
+qCoeff20        QN 15.S32
+        
+qSrc01          QN 0.U8
+dSrc0           DN 0.U8
+dSrc1           DN 1.U8                
+                
+dSrcb           DN 4.U8
+dSrcc           DN 2.U8
+dSrcd           DN 3.U8
+dSrce           DN 5.U8
+dSrcf           DN 1.U8
+
+qSrcb           QN 2.S16
+qSrcc           QN 1.S16
+dSrcB           DN 4.S16
+dSrcC           DN 2.S16
+
+qRes0           QN 5.S16
+qRes1           QN 6.S16
+qRes2           QN 7.S16
+qRes3           QN 8.S16
+qRes4           QN 9.S16
+qRes5           QN 10.S16
+qRes6           QN 11.S16
+qRes7           QN 12.S16
+qRes8           QN 13.S16
+    
+dRes0           DN 10.S16
+dRes1           DN 12.S16
+dRes2           DN 14.S16
+dRes3           DN 16.S16
+dRes4           DN 18.S16
+dRes5           DN 20.S16
+dRes6           DN 22.S16
+dRes7           DN 24.S16
+dRes8           DN 26.S16
+    
+qAcc01          QN 5.S32
+qAcc23          QN 6.S32
+qAcc45          QN 2.S32
+qAcc67          QN 3.S32
+qSumBE          QN 0.S32
+qSumCD          QN 1.S32
+
+dTempAcc0       DN 0.U16
+dTempAcc1       DN 2.U16
+dTempAcc2       DN 4.U16
+dTempAcc3       DN 6.U16
+
+qTAcc0          QN 0.U16
+qTAcc1          QN 1.U16
+qTAcc2          QN 2.U16
+qTAcc3          QN 3.U16
+
+dAcc0           DN 0.U8
+dAcc1           DN 2.U8
+dAcc2           DN 4.U8
+dAcc3           DN 6.U8
+
+dTmp0           DN 8.S16
+dTmp1           DN 9.S16
+qTmp0           QN 4.S32
+
+        VLD1        qSrc01, [pSrc], srcStep     ;// [a0 a1 a2 a3 ..]
+        VMOV        dCoeff20, #20
+        VMOV        dCoeff5, #5
+
+        ;// Row0
+        VEXT        dSrcb, dSrc0, dSrc1, #1     ;// [b0 b1 b2 b3 ..]
+        VEXT        dSrcc, dSrc0, dSrc1, #2
+        VEXT        dSrcd, dSrc0, dSrc1, #3
+        VEXT        dSrce, dSrc0, dSrc1, #4
+        VEXT        dSrcf, dSrc0, dSrc1, #5     ;// [f0 f1 f2 f3 ..]
+        VADDL       qSrcc, dSrcc, dSrcd         ;// c+d                
+        VADDL       qSrcb, dSrcb, dSrce         ;// b+e        
+        VADDL       qRes0, dSrc0, dSrcf         ;// Acc=a+f
+        VLD1        qSrc01, [pSrc], srcStep     ;// [a0 a1 a2 a3 ..]
+        VMLA        dRes0, dSrcC, dCoeff20      ;// Acc += 20*(c+d)
+;        VMLS        dRes0, dSrcB, dCoeff5       ;// Acc -= 5*(b+e)
+        VMUL        dTmp0, dSrcB, dCoeff5       ;// Acc -= 5*(b+e)
+        
+        ;// Row1
+        VEXT        dSrcb, dSrc0, dSrc1, #1     ;// [b0 b1 b2 b3 ..]
+        VEXT        dSrcc, dSrc0, dSrc1, #2
+        VEXT        dSrcd, dSrc0, dSrc1, #3
+        VEXT        dSrce, dSrc0, dSrc1, #4
+        VEXT        dSrcf, dSrc0, dSrc1, #5     ;// [f0 f1 f2 f3 ..]
+        VADDL       qSrcc, dSrcc, dSrcd         ;// c+d                
+        VADDL       qSrcb, dSrcb, dSrce         ;// b+e        
+        VADDL       qRes1, dSrc0, dSrcf         ;// Acc=a+f
+        VLD1        qSrc01, [pSrc], srcStep     ;// [a0 a1 a2 a3 ..]
+        
+        VSUB        dRes0, dRes0, dTmp0 ;// TeRi
+        
+        VMLA        dRes1, dSrcC, dCoeff20      ;// Acc += 20*(c+d)
+;        VMLS        dRes1, dSrcB, dCoeff5       ;// Acc -= 5*(b+e)
+        VMUL        dTmp0, dSrcB, dCoeff5       ;// Acc -= 5*(b+e)
+
+        ;// Row2
+        VEXT        dSrcb, dSrc0, dSrc1, #1     ;// [b0 b1 b2 b3 ..]
+        VEXT        dSrcc, dSrc0, dSrc1, #2
+        VEXT        dSrcd, dSrc0, dSrc1, #3
+        VEXT        dSrce, dSrc0, dSrc1, #4
+        VEXT        dSrcf, dSrc0, dSrc1, #5     ;// [f0 f1 f2 f3 ..]
+        VADDL       qSrcc, dSrcc, dSrcd         ;// c+d                
+        VADDL       qSrcb, dSrcb, dSrce         ;// b+e        
+        VADDL       qRes2, dSrc0, dSrcf         ;// Acc=a+f
+        VLD1        qSrc01, [pSrc], srcStep     ;// [a0 a1 a2 a3 ..]
+        
+        VSUB        dRes1, dRes1, dTmp0
+
+        VMLA        dRes2, dSrcC, dCoeff20      ;// Acc += 20*(c+d)
+;        VMLS        dRes2, dSrcB, dCoeff5       ;// Acc -= 5*(b+e)
+        VMUL        dTmp0, dSrcB, dCoeff5       ;// Acc -= 5*(b+e)
+
+        ;// Row3
+        VEXT        dSrcb, dSrc0, dSrc1, #1     ;// [b0 b1 b2 b3 ..]
+        VEXT        dSrcc, dSrc0, dSrc1, #2
+        VEXT        dSrcd, dSrc0, dSrc1, #3
+        VEXT        dSrce, dSrc0, dSrc1, #4
+        VEXT        dSrcf, dSrc0, dSrc1, #5     ;// [f0 f1 f2 f3 ..]
+        VADDL       qSrcc, dSrcc, dSrcd         ;// c+d                
+        VADDL       qSrcb, dSrcb, dSrce         ;// b+e        
+        VADDL       qRes3, dSrc0, dSrcf         ;// Acc=a+f
+        VLD1        qSrc01, [pSrc], srcStep     ;// [a0 a1 a2 a3 ..]
+
+        VSUB        dRes2, dRes2, dTmp0
+
+        VMLA        dRes3, dSrcC, dCoeff20      ;// Acc += 20*(c+d)
+;        VMLS        dRes3, dSrcB, dCoeff5       ;// Acc -= 5*(b+e)
+        VMUL        dTmp0, dSrcB, dCoeff5       ;// Acc -= 5*(b+e)
+
+        ;// Row4
+        VEXT        dSrcb, dSrc0, dSrc1, #1     ;// [b0 b1 b2 b3 ..]
+        VEXT        dSrcc, dSrc0, dSrc1, #2
+        VEXT        dSrcd, dSrc0, dSrc1, #3
+        VEXT        dSrce, dSrc0, dSrc1, #4
+        VEXT        dSrcf, dSrc0, dSrc1, #5     ;// [f0 f1 f2 f3 ..]
+        VADDL       qSrcc, dSrcc, dSrcd         ;// c+d                
+        VADDL       qSrcb, dSrcb, dSrce         ;// b+e        
+        VADDL       qRes4, dSrc0, dSrcf         ;// Acc=a+f
+        VLD1        qSrc01, [pSrc], srcStep     ;// [a0 a1 a2 a3 ..]
+
+        VSUB        dRes3, dRes3, dTmp0
+
+        VMLA        dRes4, dSrcC, dCoeff20      ;// Acc += 20*(c+d)
+;        VMLS        dRes4, dSrcB, dCoeff5       ;// Acc -= 5*(b+e)
+        VMUL        dTmp0, dSrcB, dCoeff5       ;// Acc -= 5*(b+e)
+
+        ;// Row5
+        VEXT        dSrcb, dSrc0, dSrc1, #1     ;// [b0 b1 b2 b3 ..]
+        VEXT        dSrcc, dSrc0, dSrc1, #2
+        VEXT        dSrcd, dSrc0, dSrc1, #3
+        VEXT        dSrce, dSrc0, dSrc1, #4
+        VEXT        dSrcf, dSrc0, dSrc1, #5     ;// [f0 f1 f2 f3 ..]
+        VADDL       qSrcc, dSrcc, dSrcd         ;// c+d                
+        VADDL       qSrcb, dSrcb, dSrce         ;// b+e        
+        VADDL       qRes5, dSrc0, dSrcf         ;// Acc=a+f
+        VLD1        qSrc01, [pSrc], srcStep     ;// [a0 a1 a2 a3 ..]
+
+        VSUB        dRes4, dRes4, dTmp0
+
+        VMLA        dRes5, dSrcC, dCoeff20      ;// Acc += 20*(c+d)
+;        VMLS        dRes5, dSrcB, dCoeff5       ;// Acc -= 5*(b+e)
+        VMUL        dTmp0, dSrcB, dCoeff5       ;// Acc -= 5*(b+e)
+
+        ;// Row6
+        VEXT        dSrcb, dSrc0, dSrc1, #1     ;// [b0 b1 b2 b3 ..]
+        VEXT        dSrcc, dSrc0, dSrc1, #2
+        VEXT        dSrcd, dSrc0, dSrc1, #3
+        VEXT        dSrce, dSrc0, dSrc1, #4
+        VEXT        dSrcf, dSrc0, dSrc1, #5     ;// [f0 f1 f2 f3 ..]
+        VADDL       qSrcc, dSrcc, dSrcd         ;// c+d                
+        VADDL       qSrcb, dSrcb, dSrce         ;// b+e        
+        VADDL       qRes6, dSrc0, dSrcf         ;// Acc=a+f
+        VLD1        qSrc01, [pSrc], srcStep     ;// [a0 a1 a2 a3 ..]
+
+        VSUB        dRes5, dRes5, dTmp0
+
+        VMLA        dRes6, dSrcC, dCoeff20      ;// Acc += 20*(c+d)
+;        VMLS        dRes6, dSrcB, dCoeff5       ;// Acc -= 5*(b+e)
+        VMUL        dTmp0, dSrcB, dCoeff5       ;// Acc -= 5*(b+e)
+
+        ;// Row7
+        VEXT        dSrcb, dSrc0, dSrc1, #1     ;// [b0 b1 b2 b3 ..]
+        VEXT        dSrcc, dSrc0, dSrc1, #2
+        VEXT        dSrcd, dSrc0, dSrc1, #3
+        VEXT        dSrce, dSrc0, dSrc1, #4
+        VEXT        dSrcf, dSrc0, dSrc1, #5     ;// [f0 f1 f2 f3 ..]
+        VADDL       qSrcc, dSrcc, dSrcd         ;// c+d                
+        VADDL       qSrcb, dSrcb, dSrce         ;// b+e        
+        VADDL       qRes7, dSrc0, dSrcf         ;// Acc=a+f
+        VLD1        qSrc01, [pSrc], srcStep     ;// [a0 a1 a2 a3 ..]
+
+        VSUB        dRes6, dRes6, dTmp0
+
+        VMLA        dRes7, dSrcC, dCoeff20      ;// Acc += 20*(c+d)
+;        VMLS        dRes7, dSrcB, dCoeff5       ;// Acc -= 5*(b+e)
+        VMUL        dTmp0, dSrcB, dCoeff5       ;// Acc -= 5*(b+e)
+
+        ;// Row8
+        VEXT        dSrcb, dSrc0, dSrc1, #1     ;// [b0 b1 b2 b3 ..]
+        VEXT        dSrcc, dSrc0, dSrc1, #2
+        VEXT        dSrcd, dSrc0, dSrc1, #3
+        VEXT        dSrce, dSrc0, dSrc1, #4
+        VEXT        dSrcf, dSrc0, dSrc1, #5     ;// [f0 f1 f2 f3 ..]
+        VADDL       qSrcc, dSrcc, dSrcd         ;// c+d                
+        VADDL       qSrcb, dSrcb, dSrce         ;// b+e        
+        VADDL       qRes8, dSrc0, dSrcf         ;// Acc=a+f
+
+        VSUB        dRes7, dRes7, dTmp0
+
+        VMLA        dRes8, dSrcC, dCoeff20      ;// Acc += 20*(c+d)
+;        VMLS        dRes8, dSrcB, dCoeff5       ;// Acc -= 5*(b+e)
+        VMUL        dTmp0, dSrcB, dCoeff5       ;// Acc -= 5*(b+e)
+
+        VMOV        qCoeff20, #20
+        VMOV        qCoeff5, #5
+
+        ;// Col0
+        VADDL       qAcc01, dRes0, dRes5        ;// Acc = a+f
+        VADDL       qSumCD, dRes2, dRes3        ;// c+d
+        VADDL       qSumBE, dRes1, dRes4        ;// b+e
+
+        VSUB        dRes8, dRes8, dTmp0
+
+        VMLA        qAcc01, qSumCD, qCoeff20    ;// Acc += 20*(c+d)
+;        VMLS        qAcc01, qSumBE, qCoeff5     ;// Acc -= 20*(b+e)        
+        VMUL        qTmp0, qSumBE, qCoeff5     ;// Acc -= 20*(b+e)        
+
+        ;// Col1
+        VADDL       qAcc23, dRes1, dRes6        ;// Acc = a+f
+        VADDL       qSumCD, dRes3, dRes4        ;// c+d
+        VADDL       qSumBE, dRes2, dRes5        ;// b+e
+        VMLA        qAcc23, qSumCD, qCoeff20    ;// Acc += 20*(c+d)
+
+        VSUB        qAcc01, qAcc01, qTmp0
+
+;        VMLS        qAcc23, qSumBE, qCoeff5     ;// Acc -= 20*(b+e)        
+        VMUL        qTmp0, qSumBE, qCoeff5     ;// Acc -= 20*(b+e)        
+
+        ;// Col2
+        VADDL       qAcc45, dRes2, dRes7        ;// Acc = a+f
+        VADDL       qSumCD, dRes4, dRes5        ;// c+d
+        VADDL       qSumBE, dRes3, dRes6        ;// b+e
+        VMLA        qAcc45, qSumCD, qCoeff20    ;// Acc += 20*(c+d)
+
+        VSUB        qAcc23, qAcc23, qTmp0
+
+;        VMLS        qAcc45, qSumBE, qCoeff5     ;// Acc -= 20*(b+e)        
+        VMUL        qTmp0, qSumBE, qCoeff5     ;// Acc -= 20*(b+e)        
+        
+        ;// Col3
+        VADDL       qAcc67, dRes3, dRes8        ;// Acc = a+f
+        VADDL       qSumCD, dRes5, dRes6        ;// c+d
+        VADDL       qSumBE, dRes4, dRes7        ;// b+e
+        VMLA        qAcc67, qSumCD, qCoeff20    ;// Acc += 20*(c+d)
+
+        VSUB        qAcc45, qAcc45, qTmp0
+
+        VMLS        qAcc67, qSumBE, qCoeff5     ;// Acc -= 20*(b+e)        
+
+        VQRSHRUN    dTempAcc0, qAcc01, #10
+        VQRSHRUN    dTempAcc1, qAcc23, #10
+        VQRSHRUN    dTempAcc2, qAcc45, #10
+        VQRSHRUN    dTempAcc3, qAcc67, #10
+        
+        VQMOVN      dAcc0, qTAcc0
+        VQMOVN      dAcc1, qTAcc1
+        VQMOVN      dAcc2, qTAcc2
+        VQMOVN      dAcc3, qTAcc3
+                
+        M_END
+    
+    ENDIF
+
+
+    
+    END
+    
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_InterpolateLuma_HalfDiagVerHor4x4_unsafe_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_InterpolateLuma_HalfDiagVerHor4x4_unsafe_s.s
new file mode 100755
index 0000000..7bc091f
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_InterpolateLuma_HalfDiagVerHor4x4_unsafe_s.s
@@ -0,0 +1,266 @@
+;//
+;// 
+;// File Name:  armVCM4P10_InterpolateLuma_HalfDiagVerHor4x4_unsafe_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   12290
+;// Date:       Wednesday, April 9, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+
+        EXPORT armVCM4P10_InterpolateLuma_HalfDiagVerHor4x4_unsafe
+
+        M_VARIANTS CortexA8
+
+    IF CortexA8
+        M_START armVCM4P10_InterpolateLuma_HalfDiagVerHor4x4_unsafe, r11
+
+;// Declare input registers
+pSrc            RN 0
+srcStep         RN 1
+pDst            RN 2
+dstStep         RN 3
+
+;// Declare Neon registers
+dTCoeff5        DN 30.U8
+dTCoeff20       DN 31.U8
+dCoeff5         DN 30.S16
+dCoeff20        DN 31.S16
+
+qSrcA01         QN 0.U8
+qSrcB23         QN 1.U8
+qSrcC45         QN 2.U8
+qSrcD67         QN 3.U8
+qSrcE89         QN 4.U8
+qSrcF1011       QN 5.U8
+qSrcG1213       QN 6.U8
+qSrcH1415       QN 7.U8
+qSrcI1617       QN 8.U8
+
+dSrcA0          DN 0.U8
+dSrcB2          DN 2.U8
+dSrcC4          DN 4.U8
+dSrcD6          DN 6.U8
+dSrcE8          DN 8.U8
+dSrcF10         DN 10.U8
+dSrcG12         DN 12.U8
+dSrcH14         DN 14.U8
+dSrcI16         DN 16.U8
+
+dSrcA1          DN 1.U8
+dSrcB3          DN 3.U8
+dSrcC5          DN 5.U8
+dSrcD7          DN 7.U8
+dSrcE9          DN 9.U8
+dSrcF11         DN 11.U8
+dSrcG13         DN 13.U8
+dSrcH15         DN 15.U8
+dSrcI17         DN 17.U8
+
+qTempP01        QN 9.S16
+qTempQ01        QN 10.S16
+qTempR01        QN 11.S16
+qTempS01        QN 12.S16
+
+qTempP23        QN 0.S16
+qTempQ23        QN 1.S16
+qTempR23        QN 2.S16
+qTempS23        QN 3.S16
+
+dTempP0         DN 18.S16
+dTempP1         DN 19.S16
+dTempP2         DN 0.S16
+
+dTempQ0         DN 20.S16
+dTempQ1         DN 21.S16
+dTempQ2         DN 2.S16
+
+dTempR0         DN 22.S16
+dTempR1         DN 23.S16
+dTempR2         DN 4.S16
+
+dTempS0         DN 24.S16
+dTempS1         DN 25.S16
+dTempS2         DN 6.S16
+ 
+dTempB0         DN 26.S16
+dTempC0         DN 27.S16
+dTempD0         DN 28.S16
+dTempF0         DN 29.S16
+
+dTempAcc0       DN 0.U16
+dTempAcc1       DN 2.U16
+dTempAcc2       DN 4.U16
+dTempAcc3       DN 6.U16
+
+dAcc0           DN 0.U8
+dAcc1           DN 2.U8
+dAcc2           DN 4.U8
+dAcc3           DN 6.U8
+
+qAcc0           QN 0.S32
+qAcc1           QN 1.S32
+qAcc2           QN 2.S32
+qAcc3           QN 3.S32
+
+qTAcc0          QN 0.U16
+qTAcc1          QN 1.U16
+qTAcc2          QN 2.U16
+qTAcc3          QN 3.U16                
+
+qTmp            QN 4.S16
+dTmp            DN 8.S16
+
+        VLD1        qSrcA01, [pSrc], srcStep                 ;// [a0 a1 a2 a3 .. a15]   
+        ADD         r12, pSrc, srcStep, LSL #2
+        VMOV        dTCoeff5, #5
+        VMOV        dTCoeff20, #20
+        VLD1        qSrcF1011, [r12], srcStep
+        VLD1        qSrcB23, [pSrc], srcStep                 ;// [b0 b1 b2 b3 .. b15]
+        
+        VLD1        qSrcG1213, [r12], srcStep
+        VADDL       qTempP01, dSrcA0, dSrcF10           
+        VLD1        qSrcC45, [pSrc], srcStep                 ;// [c0 c1 c2 c3 .. c15]
+        VADDL       qTempP23, dSrcA1, dSrcF11   
+        VLD1        qSrcD67, [pSrc], srcStep
+        VADDL       qTempQ01, dSrcB2, dSrcG12                   
+        VLD1        qSrcE89, [pSrc], srcStep
+        
+        ;//t0
+        VMLAL       qTempP01, dSrcC4, dTCoeff20
+        
+        VLD1        qSrcH1415, [r12], srcStep
+
+        VMLAL       qTempP23, dSrcC5, dTCoeff20
+        
+        VLD1        qSrcI1617, [r12], srcStep                 ;// [i0 i1 i2 i3 .. ]
+        
+        VMLAL       qTempP01, dSrcD6, dTCoeff20
+        VMLAL       qTempQ01, dSrcD6, dTCoeff20
+        VMLSL       qTempP23, dSrcB3, dTCoeff5
+        
+        VADDL       qTempR01, dSrcC4, dSrcH14   
+        
+        VMLSL       qTempP01, dSrcB2, dTCoeff5
+
+        VADDL       qTempQ23, dSrcB3, dSrcG13   
+
+        VMLAL       qTempP23, dSrcD7, dTCoeff20
+        VMLAL       qTempQ01, dSrcE8, dTCoeff20
+
+        VMLSL       qTempP01, dSrcE8, dTCoeff5
+        VMLAL       qTempQ23, dSrcD7, dTCoeff20
+
+        VMLSL       qTempP23, dSrcE9, dTCoeff5
+
+        ;//t1
+
+        VMLAL       qTempR01, dSrcE8, dTCoeff20
+        VMLSL       qTempQ01, dSrcC4, dTCoeff5
+        VMLSL       qTempQ23, dSrcC5, dTCoeff5
+        VADDL       qTempR23, dSrcC5, dSrcH15   
+
+        VMLAL       qTempR01, dSrcF10, dTCoeff20
+        VMLSL       qTempQ01, dSrcF10, dTCoeff5
+        VMLAL       qTempQ23, dSrcE9, dTCoeff20
+        VMLAL       qTempR23, dSrcE9, dTCoeff20
+        VADDL       qTempS01, dSrcD6, dSrcI16   
+
+
+        VMLSL       qTempR01, dSrcD6, dTCoeff5
+        VMLSL       qTempQ23, dSrcF11, dTCoeff5
+        VMLSL       qTempR23, dSrcD7, dTCoeff5
+
+        ;//t2
+        VADDL       qTempS23, dSrcD7, dSrcI17   
+        VMLAL       qTempS01, dSrcF10, dTCoeff20
+        VMLSL       qTempR01, dSrcG12, dTCoeff5
+        VMLSL       qTempR23, dSrcG13, dTCoeff5
+
+        VMLAL       qTempS23, dSrcF11, dTCoeff20
+        VMLAL       qTempS01, dSrcG12, dTCoeff20
+        VEXT        dTempB0, dTempP0, dTempP1, #1
+        VMLAL       qTempR23, dSrcF11, dTCoeff20
+
+
+        ;//t3
+        VMLAL       qTempS23, dSrcG13, dTCoeff20
+        VMLSL       qTempS01, dSrcE8, dTCoeff5
+        VEXT        dTempC0, dTempP0, dTempP1, #2
+        VMOV        dCoeff20, #20
+        VMLSL       qTempS23, dSrcE9, dTCoeff5
+        VMLSL       qTempS01, dSrcH14, dTCoeff5
+        VEXT        dTempF0, dTempP1, dTempP2, #1
+        VEXT        dTempD0, dTempP0, dTempP1, #3
+        VMLSL       qTempS23, dSrcH15, dTCoeff5
+        
+        VADDL       qAcc0, dTempP0, dTempF0
+        VADD        dTempC0, dTempC0, dTempD0
+        ;//h 
+        VMOV        dCoeff5, #5
+        
+        ;// res0
+        VADD        dTempB0, dTempB0, dTempP1
+        VMLAL       qAcc0, dTempC0, dCoeff20
+        VEXT        dTempC0, dTempQ0, dTempQ1, #2
+        VEXT        dTempD0, dTempQ0, dTempQ1, #3
+        VEXT        dTempF0, dTempQ1, dTempQ2, #1
+        VMLSL       qAcc0, dTempB0, dCoeff5
+
+        ;// res1
+        VEXT        dTempB0, dTempQ0, dTempQ1, #1
+        VADDL       qAcc1, dTempQ0, dTempF0
+        VADD        dTempC0, dTempC0, dTempD0
+        VADD        dTempB0, dTempB0, dTempQ1
+        VEXT        dTempD0, dTempR0, dTempR1, #3
+        VMLAL       qAcc1, dTempC0, dCoeff20
+        VEXT        dTempF0, dTempR1, dTempR2, #1
+        VEXT        dTempC0, dTempR0, dTempR1, #2
+        VEXT        dTmp, dTempR0, dTempR1, #1
+        VADDL       qAcc2, dTempR0, dTempF0
+        VMLSL       qAcc1, dTempB0, dCoeff5
+;        VEXT        dTempB0, dTempR0, dTempR1, #1
+        VADD        dTempC0, dTempC0, dTempD0
+        
+        ;// res2
+        VADD        dTempB0, dTmp, dTempR1
+        VEXT        dTempD0, dTempS0, dTempS1, #3
+        VMLAL       qAcc2, dTempC0, dCoeff20
+;        VADD        dTempB0, dTempB0, dTempR1
+        
+        ;// res3
+        VEXT        dTempC0, dTempS0, dTempS1, #2
+        VEXT        dTempF0, dTempS1, dTempS2, #1
+        VADD        dTempC0, dTempC0, dTempD0
+        VEXT        dTmp, dTempS0, dTempS1, #1
+        VADDL       qAcc3, dTempS0, dTempF0
+        VMLSL       qAcc2, dTempB0, dCoeff5
+        VMLAL       qAcc3, dTempC0, dCoeff20
+        VADD        dTmp, dTmp, dTempS1
+        VMLSL       qAcc3, dTmp, dCoeff5
+                
+        VQRSHRUN    dTempAcc0, qAcc0, #10
+        VQRSHRUN    dTempAcc1, qAcc1, #10
+        VQRSHRUN    dTempAcc2, qAcc2, #10
+        VQRSHRUN    dTempAcc3, qAcc3, #10
+
+        VQMOVN      dAcc0, qTAcc0
+        VQMOVN      dAcc1, qTAcc1
+        VQMOVN      dAcc2, qTAcc2
+        VQMOVN      dAcc3, qTAcc3
+        
+        M_END
+    
+    ENDIF
+    
+    
+    
+
+    
+    END
+    
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe_s.s
new file mode 100755
index 0000000..babe8ad
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe_s.s
@@ -0,0 +1,228 @@
+;//
+;// 
+;// File Name:  armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   12290
+;// Date:       Wednesday, April 9, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+
+        M_VARIANTS CortexA8
+        
+        EXPORT armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe
+
+DEBUG_ON    SETL {FALSE}
+
+    IF CortexA8
+        
+        M_START armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe, r11
+
+;// Declare input registers
+pSrc            RN 0
+srcStep         RN 1
+pDst            RN 2
+dstStep         RN 3
+
+;// Declare Neon registers
+dCoeff5         DN 30.S16
+dCoeff20        DN 31.S16
+
+qSrcA01         QN 11.U8
+qSrcB01         QN 12.U8
+qSrcC01         QN 13.U8
+qSrcD01         QN 14.U8
+
+dSrcA0          DN 22.U8
+dSrcA1          DN 23.U8
+dSrcB0          DN 24.U8
+dSrcB1          DN 25.U8
+dSrcC0          DN 26.U8
+dSrcC1          DN 27.U8
+dSrcD0          DN 28.U8
+dSrcD1          DN 29.U8
+
+dSrcb           DN 12.U8
+dSrce           DN 13.U8
+dSrcf           DN 10.U8
+
+dSrc0c          DN 14.U8
+dSrc1c          DN 16.U8
+dSrc2c          DN 18.U8
+dSrc3c          DN 20.U8
+                   
+dSrc0d          DN 15.U8
+dSrc1d          DN 17.U8
+dSrc2d          DN 19.U8
+dSrc3d          DN 21.U8
+
+qTemp01         QN 4.S16
+qTemp23         QN 6.S16
+dTemp0          DN 8.S16
+dTemp2          DN 12.S16
+
+qRes01          QN 11.S16
+qRes23          QN 12.S16
+qRes45          QN 13.S16
+qRes67          QN 14.S16
+
+dRes0           DN 22.S16
+dRes2           DN 24.S16
+dRes4           DN 26.S16
+dRes6           DN 28.S16
+
+dAcc0           DN 22.U8
+dAcc2           DN 24.U8
+dAcc4           DN 26.U8
+dAcc6           DN 28.U8
+
+dResult0        DN 22.U32
+dResult2        DN 24.U32
+dResult4        DN 26.U32
+dResult6        DN 28.U32
+
+        VLD1        qSrcA01, [pSrc], srcStep    ;// Load A register [a0 a1 a2 a3 ..]
+        ;// One cycle stall
+        VEXT        dSrcf, dSrcA0, dSrcA1, #5   ;// [f0 f1 f2 f3 ..]
+        VEXT        dSrcb, dSrcA0, dSrcA1, #1   ;// [b0 b1 b2 b3 ..]
+;        VLD1        qSrcB01, [pSrc], srcStep    ;// Load B register [a0 a1 a2 a3 ..]
+        VEXT        dSrc0c, dSrcA0, dSrcA1, #2
+        VEXT        dSrc0d, dSrcA0, dSrcA1, #3
+        VEXT        dSrce, dSrcA0, dSrcA1, #4
+        VADDL       qRes01, dSrcA0, dSrcf       ;// Acc=a+f
+        VADDL       qTemp01, dSrc0c, dSrc0d     ;// c+d                
+        VADDL       qTemp23, dSrcb, dSrce       ;// b+e
+        
+        VLD1        qSrcB01, [pSrc], srcStep    ;// Load B register [a0 a1 a2 a3 ..]
+;        VLD1        qSrcC01, [pSrc], srcStep    ;// Load C register [a0 a1 a2 a3 ..]           
+        VMLA        dRes0, dTemp0, dCoeff20     ;// Acc += 20*(c+d)
+;        VMLS        dRes0, dTemp2, dCoeff5      ;// Acc -= 5*(b+e)
+        VMUL        dTemp0, dTemp2, dCoeff5 ;// TeRi
+        
+        VEXT        dSrcf, dSrcB0, dSrcB1, #5   ;// [f0 f1 f2 f3 ..]
+        VEXT        dSrcb, dSrcB0, dSrcB1, #1   ;// [b0 b1 b2 b3 ..]
+        VEXT        dSrc1c, dSrcB0, dSrcB1, #2
+        VEXT        dSrc1d, dSrcB0, dSrcB1, #3
+        VEXT        dSrce, dSrcB0, dSrcB1, #4
+        VADDL       qRes23, dSrcB0, dSrcf       ;// Acc=a+f
+
+        VSUB        dRes0, dRes0, dTemp0    ;// TeRi
+
+        VADDL       qTemp01, dSrc1c, dSrc1d     ;// c+d                
+        VADDL       qTemp23, dSrcb, dSrce       ;// b+e
+        
+        VLD1        qSrcC01, [pSrc], srcStep    ;// Load C register [a0 a1 a2 a3 ..]           
+;        VLD1        qSrcD01, [pSrc], srcStep    ;// Load D register [a0 a1 a2 a3 ..]  
+        
+        VMLA        dRes2, dTemp0, dCoeff20     ;// Acc += 20*(c+d)
+;        VMLS        dRes2, dTemp2, dCoeff5      ;// Acc -= 5*(b+e)
+        VMUL        dTemp0, dTemp2, dCoeff5 ;// TeRi
+
+        VEXT        dSrcf, dSrcC0, dSrcC1, #5   ;// [f0 f1 f2 f3 ..]
+        VEXT        dSrcb, dSrcC0, dSrcC1, #1   ;// [b0 b1 b2 b3 ..]
+        VEXT        dSrc2c, dSrcC0, dSrcC1, #2
+        VEXT        dSrc2d, dSrcC0, dSrcC1, #3
+        VEXT        dSrce, dSrcC0, dSrcC1, #4
+        VADDL       qRes45, dSrcC0, dSrcf       ;// Acc=a+f
+        
+        VSUB        dRes2, dRes2, dTemp0  ;// TeRi
+        
+        VADDL       qTemp01, dSrc2c, dSrc2d     ;// c+d                
+        VADDL       qTemp23, dSrcb, dSrce       ;// b+e
+
+        VLD1        qSrcD01, [pSrc], srcStep    ;// Load D register [a0 a1 a2 a3 ..]  
+
+        VMLA        dRes4, dTemp0, dCoeff20     ;// Acc += 20*(c+d)
+;        VMLS        dRes4, dTemp2, dCoeff5      ;// Acc -= 5*(b+e)
+        VMUL        dTemp0, dTemp2, dCoeff5      ;// Acc -= 5*(b+e) TeRi
+        
+
+        VEXT        dSrcf, dSrcD0, dSrcD1, #5   ;// [f0 f1 f2 f3 ..]
+        VEXT        dSrcb, dSrcD0, dSrcD1, #1   ;// [b0 b1 b2 b3 ..]
+        VEXT        dSrc3c, dSrcD0, dSrcD1, #2
+        VEXT        dSrc3d, dSrcD0, dSrcD1, #3
+        VEXT        dSrce, dSrcD0, dSrcD1, #4
+        VADDL       qRes67, dSrcD0, dSrcf       ;// Acc=a+f
+
+        VSUB        dRes4, dRes4, dTemp0 ;// TeRi
+
+        VADDL       qTemp01, dSrc3c, dSrc3d     ;// c+d                
+        VADDL       qTemp23, dSrcb, dSrce       ;// b+e
+        VMLA        dRes6, dTemp0, dCoeff20     ;// Acc += 20*(c+d)
+        VMLS        dRes6, dTemp2, dCoeff5      ;// Acc -= 5*(b+e)
+
+        VQRSHRUN    dAcc0, qRes01, #5           ;// Acc = Sat ((Acc + 16) / 32)
+        VQRSHRUN    dAcc2, qRes23, #5           ;// Acc = Sat ((Acc + 16) / 32)
+        VQRSHRUN    dAcc4, qRes45, #5           ;// Acc = Sat ((Acc + 16) / 32)
+        VQRSHRUN    dAcc6, qRes67, #5           ;// Acc = Sat ((Acc + 16) / 32)
+        
+        M_END
+    
+    ENDIF
+
+
+    END
+    
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe_s.s
new file mode 100755
index 0000000..89c90aa
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe_s.s
@@ -0,0 +1,134 @@
+;//
+;// 
+;// File Name:  armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   12290
+;// Date:       Wednesday, April 9, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+       
+        M_VARIANTS CortexA8
+       
+        EXPORT armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe
+
+    IF CortexA8
+        
+        M_START armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe, r11
+
+;// Declare input registers
+pSrc            RN 0
+srcStep         RN 1
+pDst            RN 2
+dstStep         RN 3
+
+Temp            RN 12
+
+;// Declare Neon registers
+dCoeff5         DN 30.S16
+dCoeff20        DN 31.S16
+
+dSrc0           DN 7.U8
+dSrc1           DN 8.U8
+dSrc2           DN 9.U8
+dSrc3           DN 10.U8
+dSrc4           DN 11.U8
+dSrc5           DN 12.U8
+dSrc6           DN 13.U8
+dSrc7           DN 14.U8
+dSrc8           DN 15.U8
+
+qSumBE01        QN 8.S16
+qSumCD01        QN 9.S16
+dSumBE0         DN 16.S16
+dSumCD0         DN 18.S16
+
+qAcc01          QN 0.S16
+qAcc23          QN 1.S16
+qAcc45          QN 2.S16
+qAcc67          QN 3.S16
+
+dRes0           DN 0.S16
+dRes1           DN 2.S16
+dRes2           DN 4.S16
+dRes3           DN 6.S16
+
+dAcc0           DN 0.U8
+dAcc1           DN 2.U8
+dAcc2           DN 4.U8
+dAcc3           DN 6.U8        
+        
+
+dTmp0           DN 20.S16
+dTmp1           DN 21.S16
+dTmp2           DN 22.S16
+dTmp3           DN 23.S16
+
+
+        VLD1        dSrc0, [pSrc], srcStep     ;// [a0 a1 a2 a3 .. ] 
+        ADD         Temp, pSrc, srcStep, LSL #2
+        VLD1        dSrc1, [pSrc], srcStep     ;// [b0 b1 b2 b3 .. ]
+        ;// One cycle stall
+        VLD1        dSrc5, [Temp], srcStep        
+        ;// One cycle stall
+        VLD1        dSrc2, [pSrc], srcStep     ;// [c0 c1 c2 c3 .. ]
+        VADDL       qAcc01, dSrc0, dSrc5       ;// Acc = a+f
+        VLD1        dSrc3, [pSrc], srcStep
+        ;// One cycle stall
+        VLD1        dSrc6, [Temp], srcStep ;// TeRi
+        
+        VLD1        dSrc4, [pSrc], srcStep
+        VLD1        dSrc7, [Temp], srcStep ;// TeRi
+        VADDL       qSumBE01, dSrc1, dSrc4     ;// b+e
+        VADDL       qSumCD01, dSrc2, dSrc3     ;// c+d        
+        VLD1        dSrc8, [Temp], srcStep ;// TeRi
+        VMLS        dRes0, dSumBE0, dCoeff5    ;// Acc -= 20*(b+e)        
+;        VMLA        dRes0, dSumCD0, dCoeff20   ;// Acc += 20*(c+d)
+        VMUL        dTmp0, dSumCD0, dCoeff20   ;// Acc += 20*(c+d)
+        
+;        VLD1        dSrc6, [Temp], srcStep
+        VADDL       qSumBE01, dSrc2, dSrc5     ;// b+e
+        VADDL       qSumCD01, dSrc3, dSrc4     ;// c+d
+        VADDL       qAcc23, dSrc1, dSrc6       ;// Acc = a+f
+        VMLS        dRes1, dSumBE0, dCoeff5    ;// Acc -= 20*(b+e)
+;        VMLA        dRes1, dSumCD0, dCoeff20   ;// Acc += 20*(c+d)
+        VMUL        dTmp1, dSumCD0, dCoeff20   ;// Acc += 20*(c+d)
+
+;        VLD1        dSrc7, [Temp], srcStep
+        VADDL       qSumBE01, dSrc3, dSrc6     ;// b+e
+        VADDL       qSumCD01, dSrc4, dSrc5     ;// c+d
+        VADDL       qAcc45, dSrc2, dSrc7       ;// Acc = a+f
+        VMLS        dRes2, dSumBE0, dCoeff5    ;// Acc -= 20*(b+e)        
+;        VMLA        dRes2, dSumCD0, dCoeff20   ;// Acc += 20*(c+d)
+        VMUL        dTmp2, dSumCD0, dCoeff20   ;// Acc += 20*(c+d)
+
+;        VLD1        dSrc8, [Temp], srcStep     ;// [i0 i1 i2 i3 .. ]        
+        VADDL       qSumBE01, dSrc4, dSrc7     ;// b+e
+        VADDL       qAcc67, dSrc3, dSrc8       ;// Acc = a+f
+        VADDL       qSumCD01, dSrc5, dSrc6     ;// c+d
+        VMLS        dRes3, dSumBE0, dCoeff5    ;// Acc -= 20*(b+e)        
+        VADD        dRes0, dRes0, dTmp0
+        VADD        dRes1, dRes1, dTmp1
+        VADD        dRes2, dRes2, dTmp2
+        VMLA        dRes3, dSumCD0, dCoeff20   ;// Acc += 20*(c+d)
+;        VMUL        dTmp3, dSumCD0, dCoeff20   ;// Acc += 20*(c+d)
+;        VADD        dRes3, dRes3, dTmp3
+
+        VQRSHRUN    dAcc0, qAcc01, #5        
+        VQRSHRUN    dAcc1, qAcc23, #5        
+        VQRSHRUN    dAcc2, qAcc45, #5        
+        VQRSHRUN    dAcc3, qAcc67, #5        
+
+        M_END
+    
+    ENDIF
+
+    
+    
+    END
+    
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_Interpolate_Chroma_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_Interpolate_Chroma_s.s
new file mode 100755
index 0000000..0f0ec78
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_Interpolate_Chroma_s.s
@@ -0,0 +1,318 @@
+;//
+;// 
+;// File Name:  armVCM4P10_Interpolate_Chroma_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   9641
+;// Date:       Thursday, February 7, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+        
+        M_VARIANTS CortexA8
+        
+
+    IF CortexA8
+
+    M_TABLE armVCM4P10_WidthBranchTableMVIsNotZero      
+    
+    DCD   WidthIs2MVIsNotZero, WidthIs2MVIsNotZero
+    DCD   WidthIs4MVIsNotZero, WidthIs4MVIsNotZero
+    DCD   WidthIs8MVIsNotZero
+    
+    M_TABLE armVCM4P10_WidthBranchTableMVIsZero      
+    
+    DCD   WidthIs2MVIsZero, WidthIs2MVIsZero
+    DCD   WidthIs4MVIsZero, WidthIs4MVIsZero
+    DCD   WidthIs8MVIsZero
+    
+    
+;// input registers
+
+pSrc                 RN 0
+iSrcStep             RN 1
+pDst                 RN 2
+iDstStep             RN 3
+iWidth               RN 4
+iHeight              RN 5
+dx                   RN 6
+dy                   RN 7
+
+;// local variable registers
+pc                   RN 15
+return               RN 0
+EightMinusdx         RN 8 
+EightMinusdy         RN 9
+
+ACoeff               RN 12
+BCoeff               RN 9
+CCoeff               RN 8
+DCoeff               RN 6
+
+pTable               RN 11
+
+Step1                RN 10
+SrcStepMinus1        RN 14
+
+dACoeff              DN D12.U8
+dBCoeff              DN D13.U8
+dCCoeff              DN D14.U8
+dDCoeff              DN D15.U8
+
+dRow0a               DN D0.U8
+dRow0b               DN D1.U8
+dRow1a               DN D2.U8
+dRow1b               DN D3.U8
+
+qRow0a               QN Q2.S16
+qRow0b               QN Q3.S16
+
+;//dIndex               DN    D16.U8                 
+qRow1a               QN Q11.S16
+qRow1b               QN Q12.S16
+
+dRow2a               DN D16.U8
+dRow2b               DN D17.U8
+dRow3a               DN D18.U8
+dRow3b               DN D19.U8
+
+qOutRow2             QN Q11.U16
+qOutRow3             QN Q12.U16
+dOutRow2             DN D20.U8
+dOutRow3             DN D21.U8
+dOutRow2U64          DN D20.U64
+dOutRow3U64          DN D21.U64
+
+qOutRow0             QN Q2.U16
+qOutRow1             QN Q3.U16
+dOutRow0             DN D8.U8
+dOutRow1             DN D9.U8
+
+dOutRow0U64          DN D8.U64
+dOutRow1U64          DN D9.U64
+
+dOutRow0U32          DN D8.U32
+dOutRow1U32          DN D9.U32
+
+dOutRow0U16          DN D8.U16
+dOutRow1U16          DN D9.U16
+
+
+dOut0U64             DN D0.U64
+dOut1U64             DN D1.U64
+
+dOut00U32            DN D0.U32
+dOut01U32            DN D1.U32
+dOut10U32            DN D2.U32
+dOut11U32            DN D3.U32
+
+dOut0U16             DN D0.U16
+dOut1U16             DN D1.U16
+
+;//-----------------------------------------------------------------------------------------------
+;// armVCM4P10_Interpolate_Chroma_asm starts
+;//-----------------------------------------------------------------------------------------------
+        
+        ;// Write function header
+        M_START armVCM4P10_Interpolate_Chroma, r11, d15
+        
+        ;// Define stack arguments
+        M_ARG   Width,      4
+        M_ARG   Height,     4
+        M_ARG   Dx,         4
+        M_ARG   Dy,         4
+        
+        ;// Load argument from the stack
+        ;// M_STALL ARM1136JS=4
+        
+        M_LDRD   dx, dy, Dx
+        M_LDRD   iWidth, iHeight, Width
+        
+        ;// EightMinusdx = 8 - dx
+        ;// EightMinusdy = 8 - dy
+        
+        ;// ACoeff = EightMinusdx * EightMinusdy
+        ;// BCoeff = dx * EightMinusdy
+        ;// CCoeff = EightMinusdx * dy
+        ;// DCoeff = dx * dy
+        
+        RSB     EightMinusdx, dx, #8 
+        RSB     EightMinusdy, dy, #8
+        CMN     dx,dy
+        MOV     Step1, #1
+        LDREQ   pTable, =armVCM4P10_WidthBranchTableMVIsZero
+        SUB     SrcStepMinus1, iSrcStep, Step1
+        LDRNE   pTable, =armVCM4P10_WidthBranchTableMVIsNotZero
+        
+        VLD1    dRow0a, [pSrc], Step1                   ;// 0a
+        
+        SMULBB  ACoeff, EightMinusdx, EightMinusdy
+        SMULBB  BCoeff, dx, EightMinusdy
+        VLD1    dRow0b, [pSrc], SrcStepMinus1           ;// 0b
+        SMULBB  CCoeff, EightMinusdx, dy
+        SMULBB  DCoeff, dx, dy
+        
+        VDUP    dACoeff, ACoeff
+        VDUP    dBCoeff, BCoeff
+        VDUP    dCCoeff, CCoeff
+        VDUP    dDCoeff, DCoeff
+        
+        LDR     pc, [pTable, iWidth, LSL #1]      ;// Branch to the case based on iWidth
+        
+;// Pixel layout:
+;//
+;//   x00 x01 x02
+;//   x10 x11 x12
+;//   x20 x21 x22
+
+;// If fractionl mv is not (0, 0)
+WidthIs8MVIsNotZero
+
+                VLD1   dRow1a, [pSrc], Step1            ;// 1a
+                VMULL  qRow0a, dRow0a, dACoeff
+                VLD1   dRow1b, [pSrc], SrcStepMinus1    ;// 1b
+                VMULL  qRow0b, dRow1a, dACoeff
+                VLD1   dRow2a, [pSrc], Step1            ;// 2a
+                VMLAL  qRow0a, dRow0b, dBCoeff
+                VLD1   dRow2b, [pSrc], SrcStepMinus1    ;// 2b
+                VMULL  qRow1a, dRow2a, dACoeff
+                VMLAL  qRow0b, dRow1b, dBCoeff
+                VLD1   dRow3a, [pSrc], Step1            ;// 3a
+                VMLAL  qRow0a, dRow1a, dCCoeff
+                VMLAL  qRow1a, dRow2b, dBCoeff
+                VMULL  qRow1b, dRow3a, dACoeff
+                VLD1   dRow3b, [pSrc], SrcStepMinus1    ;// 3b
+                VMLAL  qRow0b, dRow2a, dCCoeff
+                VLD1   dRow0a, [pSrc], Step1            ;// 0a
+                VMLAL  qRow1b, dRow3b, dBCoeff
+                VMLAL  qRow1a, dRow3a, dCCoeff
+                VMLAL  qRow0a, dRow1b, dDCoeff
+                VLD1   dRow0b, [pSrc], SrcStepMinus1    ;// 0b
+                VMLAL  qRow1b, dRow0a, dCCoeff
+                VMLAL  qRow0b, dRow2b, dDCoeff
+                VMLAL  qRow1a, dRow3b, dDCoeff
+                
+                
+                SUBS   iHeight, iHeight, #4
+                VMLAL  qRow1b, dRow0b, dDCoeff
+
+                VQRSHRN dOutRow0, qOutRow0, #6
+                VQRSHRN dOutRow1, qOutRow1, #6
+                VQRSHRN dOutRow2, qOutRow2, #6
+                VST1   dOutRow0U64, [pDst], iDstStep
+                VQRSHRN dOutRow3, qOutRow3, #6
+                
+                VST1   dOutRow1U64, [pDst], iDstStep  
+                VST1   dOutRow2U64, [pDst], iDstStep
+                VST1   dOutRow3U64, [pDst], iDstStep  
+                
+
+                BGT     WidthIs8MVIsNotZero
+                MOV     return,  #OMX_Sts_NoErr
+                M_EXIT
+
+WidthIs4MVIsNotZero
+
+                VLD1   dRow1a, [pSrc], Step1
+                VMULL  qRow0a, dRow0a, dACoeff
+                VMULL  qRow0b, dRow1a, dACoeff
+                VLD1   dRow1b, [pSrc], SrcStepMinus1
+                VMLAL  qRow0a, dRow0b, dBCoeff
+                VMLAL  qRow0b, dRow1b, dBCoeff
+                VLD1   dRow0a, [pSrc], Step1
+                VMLAL  qRow0a, dRow1a, dCCoeff
+                VMLAL  qRow0b, dRow0a, dCCoeff
+                VLD1   dRow0b, [pSrc], SrcStepMinus1
+                SUBS   iHeight, iHeight, #2
+                VMLAL  qRow0b, dRow0b, dDCoeff
+                VMLAL  qRow0a, dRow1b, dDCoeff
+                
+                VQRSHRN dOutRow1, qOutRow1, #6
+                VQRSHRN dOutRow0, qOutRow0, #6
+                
+                VST1   dOutRow0U32[0], [pDst], iDstStep
+                VST1   dOutRow1U32[0], [pDst], iDstStep  
+                
+                BGT     WidthIs4MVIsNotZero
+                MOV     return,  #OMX_Sts_NoErr
+                M_EXIT
+
+WidthIs2MVIsNotZero
+
+                VLD1   dRow1a, [pSrc], Step1
+                VMULL  qRow0a, dRow0a, dACoeff
+                VMULL  qRow0b, dRow1a, dACoeff
+                VLD1   dRow1b, [pSrc], SrcStepMinus1
+                VMLAL  qRow0a, dRow0b, dBCoeff
+                VMLAL  qRow0b, dRow1b, dBCoeff
+                VLD1   dRow0a, [pSrc], Step1
+                VMLAL  qRow0a, dRow1a, dCCoeff
+                VMLAL  qRow0b, dRow0a, dCCoeff
+                VLD1   dRow0b, [pSrc], SrcStepMinus1
+                SUBS   iHeight, iHeight, #2
+                VMLAL  qRow0b, dRow0b, dDCoeff
+                VMLAL  qRow0a, dRow1b, dDCoeff
+                
+                VQRSHRN dOutRow1, qOutRow1, #6
+                VQRSHRN dOutRow0, qOutRow0, #6
+                
+                VST1   dOutRow0U16[0], [pDst], iDstStep
+                VST1   dOutRow1U16[0], [pDst], iDstStep  
+
+                BGT     WidthIs2MVIsNotZero 
+                MOV     return,  #OMX_Sts_NoErr
+                M_EXIT                
+                
+;// If fractionl mv is (0, 0)
+WidthIs8MVIsZero
+                SUB     pSrc, pSrc, iSrcStep
+
+WidthIs8LoopMVIsZero
+                VLD1    dRow0a, [pSrc], iSrcStep
+                SUBS    iHeight, iHeight, #2
+                VLD1    dRow0b, [pSrc], iSrcStep
+                VST1    dOut0U64, [pDst], iDstStep
+                VST1    dOut1U64, [pDst], iDstStep
+                BGT     WidthIs8LoopMVIsZero
+
+                MOV     return,  #OMX_Sts_NoErr
+                M_EXIT
+
+WidthIs4MVIsZero                
+                VLD1    dRow0b, [pSrc], iSrcStep
+                
+                SUBS    iHeight, iHeight, #2
+                
+                VST1    dOut00U32[0], [pDst], iDstStep
+                VLD1    dRow0a, [pSrc], iSrcStep
+                VST1    dOut01U32[0], [pDst], iDstStep
+                
+                BGT     WidthIs4MVIsZero 
+                MOV     return,  #OMX_Sts_NoErr
+                M_EXIT
+                
+WidthIs2MVIsZero                
+                VLD1    dRow0b, [pSrc], iSrcStep
+                SUBS    iHeight, iHeight, #2
+                
+                VST1    dOut0U16[0], [pDst], iDstStep
+                VLD1    dRow0a, [pSrc], iSrcStep
+                VST1    dOut1U16[0], [pDst], iDstStep
+                
+                BGT     WidthIs2MVIsZero 
+                MOV     return,  #OMX_Sts_NoErr                                
+                M_END
+                    
+        ENDIF ;// CortexA8
+        
+        END
+
+;//-----------------------------------------------------------------------------------------------
+;// armVCM4P10_Interpolate_Chroma_asm ends
+;//-----------------------------------------------------------------------------------------------
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_QuantTables_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_QuantTables_s.s
new file mode 100755
index 0000000..7e2642b
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_QuantTables_s.s
@@ -0,0 +1,74 @@
+;//
+;// 
+;// File Name:  armVCM4P10_QuantTables_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   12290
+;// Date:       Wednesday, April 9, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;// Description:
+;// This file contains quantization tables
+;// 
+;// 
+
+         INCLUDE omxtypes_s.h
+         INCLUDE armCOMM_s.h
+     
+         
+         EXPORT armVCM4P10_MFMatrixQPModTable
+         EXPORT armVCM4P10_QPDivIntraTable
+         EXPORT armVCM4P10_QPDivPlusOneTable  
+         
+;//--------------------------------------------------------------
+;// This table contains armVCM4P10_MFMatrix [iQP % 6][0] entires,
+;// for values of iQP from 0 to 51 (inclusive). 
+;//--------------------------------------------------------------
+
+         M_TABLE armVCM4P10_MFMatrixQPModTable
+         DCW 13107, 11916, 10082, 9362, 8192, 7282
+         DCW 13107, 11916, 10082, 9362, 8192, 7282
+         DCW 13107, 11916, 10082, 9362, 8192, 7282
+         DCW 13107, 11916, 10082, 9362, 8192, 7282
+         DCW 13107, 11916, 10082, 9362, 8192, 7282
+         DCW 13107, 11916, 10082, 9362, 8192, 7282
+         DCW 13107, 11916, 10082, 9362, 8192, 7282
+         DCW 13107, 11916, 10082, 9362, 8192, 7282
+         DCW 13107, 11916, 10082, 9362, 8192, 7282
+         
+;//---------------------------------------------------------------
+;// This table contains ARM_M4P10_Q_OFFSET + 1 + (iQP / 6) values,
+;// for values of iQP from 0 to 51 (inclusive). 
+;//---------------------------------------------------------------
+
+         M_TABLE armVCM4P10_QPDivPlusOneTable
+         DCB 16, 16, 16, 16, 16, 16
+         DCB 17, 17, 17, 17, 17, 17
+         DCB 18, 18, 18, 18, 18, 18
+         DCB 19, 19, 19, 19, 19, 19
+         DCB 20, 20, 20, 20, 20, 20
+         DCB 21, 21, 21, 21, 21, 21
+         DCB 22, 22, 22, 22, 22, 22
+         DCB 23, 23, 23, 23, 23, 23
+         DCB 24, 24, 24, 24, 24, 24
+
+;//------------------------------------------------------------------
+;// This table contains (1 << QbitsPlusOne) / 3 Values (Intra case) ,
+;// for values of iQP from 0 to 51 (inclusive). 
+;//------------------------------------------------------------------
+    
+         M_TABLE armVCM4P10_QPDivIntraTable, 2
+         DCD 21845, 21845, 21845, 21845, 21845, 21845
+         DCD 43690, 43690, 43690, 43690, 43690, 43690
+         DCD 87381, 87381, 87381, 87381, 87381, 87381
+         DCD 174762, 174762, 174762, 174762, 174762, 174762
+         DCD 349525, 349525, 349525, 349525, 349525, 349525
+         DCD 699050, 699050, 699050, 699050, 699050, 699050
+         DCD 1398101, 1398101, 1398101, 1398101, 1398101, 1398101
+         DCD 2796202, 2796202, 2796202, 2796202, 2796202, 2796202
+         DCD 5592405, 5592405, 5592405, 5592405, 5592405, 5592405                
+         
+         
+         END
+         
\ No newline at end of file
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_TransformResidual4x4_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_TransformResidual4x4_s.s
new file mode 100755
index 0000000..ee9c339
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_TransformResidual4x4_s.s
@@ -0,0 +1,186 @@
+;//
+;// 
+;// File Name:  armVCM4P10_TransformResidual4x4_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   12290
+;// Date:       Wednesday, April 9, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+;// Description:
+;// Transform Residual 4x4 Coefficients
+;// 
+;// 
+
+        
+;// Include standard headers
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+        
+        M_VARIANTS CortexA8
+        
+;// Import symbols required from other files
+;// (For example tables)
+    
+        
+        
+        
+;// Set debugging level        
+;//DEBUG_ON    SETL {TRUE}
+
+
+
+;// Guarding implementation by the processor name
+    
+    
+    
+
+
+
+
+
+;// Guarding implementation by the processor name
+    
+    IF  CortexA8
+
+;// ARM Registers
+    
+;//Input Registers
+pDst                RN  0
+pSrc                RN  1
+
+
+;// Neon Registers
+      
+;// Packed Input pixels
+dIn0                DN  D0.S16       
+dIn1                DN  D1.S16       
+dIn2                DN  D2.S16       
+dIn3                DN  D3.S16
+
+;// Intermediate calculations       
+dZero               DN  D4.S16
+de0                 DN  D5.S16
+de1                 DN  D6.S16
+de2                 DN  D7.S16
+de3                 DN  D8.S16
+dIn1RS              DN  D7.S16
+dIn3RS              DN  D8.S16
+df0                 DN  D0.S16
+df1                 DN  D1.S16
+df2                 DN  D2.S16
+df3                 DN  D3.S16
+qf01                QN  Q0.32
+qf23                QN  Q1.32
+dg0                 DN  D5.S16
+dg1                 DN  D6.S16
+dg2                 DN  D7.S16
+dg3                 DN  D8.S16
+df1RS               DN  D7.S16
+df3RS               DN  D8.S16
+
+;// Output pixels
+dh0                 DN  D0.S16
+dh1                 DN  D1.S16
+dh2                 DN  D2.S16
+dh3                 DN  D3.S16
+
+       
+    ;// Allocate stack memory required by the function
+        
+
+    ;// Write function header
+        M_START armVCM4P10_TransformResidual4x4, ,d8
+        
+        ;******************************************************************
+        ;// The strategy used in implementing the transform is as follows:*
+        ;// Load the 4x4 block into 8 registers                           *  
+        ;// Transpose the 4x4 matrix                                      *  
+        ;// Perform the row operations (on columns) using SIMD            *  
+        ;// Transpose the 4x4 result matrix                               *  
+        ;// Perform the coloumn operations                                *
+        ;// Store the 4x4 block at one go                                 *  
+        ;******************************************************************
+
+        ;// Load all the 4x4 pixels in transposed form
+        
+        VLD4    {dIn0,dIn1,dIn2,dIn3},[pSrc]
+        
+        VMOV    dZero,#0                                    ;// Used to right shift by 1 
+        
+        
+        ;**************************************** 
+        ;// Row Operations (Performed on columns)
+        ;**************************************** 
+        
+        
+        VADD        de0,dIn0,dIn2                       ;//  e0 = d0 + d2 
+        VSUB        de1,dIn0,dIn2                        ;//  e1 = d0 - d2 
+        VHADD       dIn1RS,dIn1,dZero                   ;// (f1>>1) constZero is a register holding 0
+        VHADD       dIn3RS,dIn3,dZero
+        VSUB        de2,dIn1RS,dIn3                     ;//  e2 = (d1>>1) - d3 
+        VADD        de3,dIn1,dIn3RS                        ;//  e3 = d1 + (d3>>1) 
+        VADD        df0,de0,de3                         ;//  f0 = e0 + e3
+        VADD        df1,de1,de2                            ;//  f1 = e1 + e2
+        VSUB        df2,de1,de2                            ;//  f2 = e1 - e2
+        VSUB        df3,de0,de3                            ;//  f3 = e0 - e3
+        
+        
+        
+        ;*****************************************************************
+        ;// Transpose the resultant matrix
+        ;*****************************************************************
+        
+        VTRN    df0,df1
+        VTRN    df2,df3
+        VTRN    qf01,qf23 
+        
+        
+        ;******************************* 
+        ;// Coloumn Operations 
+        ;******************************* 
+        
+        
+        VADD        dg0,df0,df2                         ;//  e0 = d0 + d2 
+        VSUB        dg1,df0,df2                            ;//  e1 = d0 - d2 
+        VHADD       df1RS,df1,dZero                     ;// (f1>>1) constZero is a register holding 0
+        VHADD       df3RS,df3,dZero
+        VSUB        dg2,df1RS,df3                       ;//  e2 = (d1>>1) - d3 
+        VADD        dg3,df1,df3RS                        ;//  e3 = d1 + (d3>>1) 
+        VADD        dh0,dg0,dg3                         ;//  f0 = e0 + e3
+        VADD        dh1,dg1,dg2                            ;//  f1 = e1 + e2
+        VSUB        dh2,dg1,dg2                            ;//  f2 = e1 - e2
+        VSUB        dh3,dg0,dg3                            ;//  f3 = e0 - e3
+        
+             
+        ;************************************************
+        ;// Calculate final value (colOp[i][j] + 32)>>6
+        ;************************************************
+        
+        VRSHR       dh0,#6
+        VRSHR       dh1,#6
+        VRSHR       dh2,#6
+        VRSHR       dh3,#6
+        
+                
+        ;***************************
+        ;// Store all the 4x4 pixels
+        ;***************************
+        
+        VST1   {dh0,dh1,dh2,dh3},[pDst]
+            
+        
+        ;// Set return value
+        
+End                
+
+        
+        ;// Write function tail
+        M_END
+        
+    ENDIF                                                           ;//CortexA8            
+            
+    END
\ No newline at end of file
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_UnpackBlock4x4_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_UnpackBlock4x4_s.s
new file mode 100755
index 0000000..4c52e22
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_UnpackBlock4x4_s.s
@@ -0,0 +1,92 @@
+;//
+;// 
+;// File Name:  armVCM4P10_UnpackBlock4x4_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   12290
+;// Date:       Wednesday, April 9, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+        
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+        
+;// Define the processor variants supported by this file
+
+        M_VARIANTS ARM1136JS
+        
+                       
+        IF ARM1136JS
+        
+;//--------------------------------------
+;// Input Arguments and their scope/usage
+;//--------------------------------------
+ppSrc           RN 0    ;// Persistent variable
+pDst            RN 1    ;// Persistent variable
+
+;//--------------------------------
+;// Variables and their scope/usage
+;//--------------------------------
+pSrc            RN 2    ;// Persistent variables
+Flag            RN 3    
+Value           RN 4    
+Value2          RN 5    
+strOffset       RN 6    
+cstOffset       RN 7    
+
+        
+        M_START armVCM4P10_UnpackBlock4x4, r7
+        
+        LDR     pSrc, [ppSrc]                       ;// Load pSrc
+        MOV     cstOffset, #31                      ;// To be used in the loop, to compute offset
+        
+        ;//-----------------------------------------------------------------------
+        ; Firstly, fill all the coefficient values on the <pDst> buffer by zero
+        ;//-----------------------------------------------------------------------
+        
+        MOV      Value,  #0                         ;// Initialize the zero value
+        MOV      Value2, #0                         ;// Initialize the zero value
+        LDRB     Flag,  [pSrc], #1                  ;// Preload <Flag> before <unpackLoop>
+        
+        STRD     Value, [pDst, #0]                  ;// pDst[0]  = pDst[1]  = pDst[2]  = pDst[3]  = 0
+        STRD     Value, [pDst, #8]                  ;// pDst[4]  = pDst[5]  = pDst[6]  = pDst[7]  = 0
+        STRD     Value, [pDst, #16]                 ;// pDst[8]  = pDst[9]  = pDst[10] = pDst[11] = 0
+        STRD     Value, [pDst, #24]                 ;// pDst[12] = pDst[13] = pDst[14] = pDst[15] = 0
+        
+        ;//----------------------------------------------------------------------------
+        ;// The loop below parses and unpacks the input stream. The C-model has 
+        ;// a somewhat complicated logic for sign extension.  But in the v6 version,
+        ;// that can be easily taken care by loading the data from <pSrc> stream as 
+        ;// SIGNED byte/halfword. So, based on the first TST instruction, 8-bits or 
+        ;// 16-bits are read.
+        ;//
+        ;// Next, to compute the offset, where the unpacked value needs to be stored,
+        ;// we modify the computation to perform [(Flag & 15) < 1] as [(Flag < 1) & 31]
+        ;// This results in a saving of one cycle.
+        ;//----------------------------------------------------------------------------
+        
+unpackLoop
+        TST      Flag,  #0x10                        ;// Computing (Flag & 0x10)
+        LDRSBNE  Value2,[pSrc,#1]                    ;// Load byte wise to avoid unaligned access   
+        LDRBNE   Value, [pSrc], #2                   
+        AND      strOffset, cstOffset, Flag, LSL #1  ;// strOffset = (Flag & 15) < 1;
+        LDRSBEQ  Value, [pSrc], #1                   ;// Value = (OMX_U8)  *pSrc++
+        ORRNE    Value,Value,Value2, LSL #8          ;// Value = (OMX_U16) *pSrc++
+        
+        TST      Flag,  #0x20                        ;// Computing (Flag & 0x20) to check, if we're done
+        LDRBEQ   Flag,  [pSrc], #1                   ;// Flag  = (OMX_U8) *pSrc++, for next iteration
+        STRH     Value, [pDst, strOffset]            ;// Store <Value> at offset <strOffset>
+        BEQ      unpackLoop                          ;// Branch to the loop beginning
+        
+        STR      pSrc, [ppSrc]                       ;// Update the bitstream pointer
+        M_END
+    
+    ENDIF
+    
+    
+    
+    END
+    
\ No newline at end of file
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_DeblockChroma_I.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_DeblockChroma_I.c
new file mode 100755
index 0000000..40d4d5e
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_DeblockChroma_I.c
@@ -0,0 +1,88 @@
+/* ----------------------------------------------------------------
+ *
+ * 
+ * File Name:  omxVCM4P10_DeblockChroma_I.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   12290
+ * Date:       Wednesday, April 9, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * H.264 intra chroma deblock
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+
+/**
+ * Function: omxVCM4P10_DeblockChroma_I
+ *
+ * Description:
+ * Performs deblocking filtering on all edges of the chroma macroblock (16x16).
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	pSrcDst         pointer to the input macroblock. Must be 8-byte aligned.
+ * [in]	srcdstStep      Step of the arrays
+ * [in]	pAlpha          pointer to a 2x2 array of alpha thresholds, organized as follows: { external
+ *                          vertical edge, internal  vertical edge, external
+ *                         horizontal edge, internal horizontal edge }
+ * [in]	pBeta			pointer to a 2x2 array of beta thresholds, organized as follows: { external
+ *                              vertical edge, internal vertical edge, external  horizontal edge,
+ *                              internal  horizontal edge }
+ * [in]	pThresholds		AArray of size  8x2 of Thresholds (TC0) (values for the left or
+ *                               above edge of each 4x2 or 2x4 block, arranged in  vertical block order
+ *                               and then in  horizontal block order)
+ * [in]	pBS				array of size 16x2 of BS parameters (arranged in scan block order for vertical edges and then horizontal edges);
+ *                         valid in the range [0,4] with the following restrictions: i) pBS[i]== 4 may occur only for 0<=i<=3, ii) pBS[i]== 4 if and only if pBS[i^1]== 4.  Must be 4-byte aligned.
+ * [out]	pSrcDst		pointer to filtered output macroblock
+ *
+ * Return Value:
+ * OMX_Sts_NoErr - no error
+ * OMX_Sts_BadArgErr - bad arguments
+ *   - Either of the pointers in pSrcDst, pAlpha, pBeta, pTresholds, or pBS is NULL.
+ *   - pSrcDst is not 8-byte aligned.
+ *   - either pThresholds or pBS is not 4-byte aligned.
+ *   - pBS is out of range, i.e., one of the following conditions is true: pBS[i]<0, pBS[i]>4, pBS[i]==4 for i>=4, or (pBS[i]==4 && pBS[i^1]!=4) for 0<=i<=3.
+ *   - srcdstStep is not a multiple of 8.
+ *
+ */
+OMXResult omxVCM4P10_DeblockChroma_I(
+	OMX_U8* pSrcDst, 
+	OMX_S32 srcdstStep, 
+	const OMX_U8* pAlpha, 
+	const OMX_U8* pBeta, 
+	const OMX_U8* pThresholds,
+    const OMX_U8 *pBS
+)
+{
+    OMXResult errorCode;
+    
+    armRetArgErrIf(pSrcDst == NULL,                 OMX_Sts_BadArgErr);
+    armRetArgErrIf(armNot8ByteAligned(pSrcDst),     OMX_Sts_BadArgErr);
+    armRetArgErrIf(srcdstStep & 7,                  OMX_Sts_BadArgErr);
+    armRetArgErrIf(pAlpha == NULL,                  OMX_Sts_BadArgErr);
+    armRetArgErrIf(pBeta == NULL,                   OMX_Sts_BadArgErr);
+    armRetArgErrIf(pThresholds == NULL,             OMX_Sts_BadArgErr);
+    armRetArgErrIf(armNot4ByteAligned(pThresholds), OMX_Sts_BadArgErr);
+    armRetArgErrIf(pBS == NULL,                     OMX_Sts_BadArgErr);
+    armRetArgErrIf(armNot4ByteAligned(pBS),         OMX_Sts_BadArgErr);
+
+    errorCode = omxVCM4P10_FilterDeblockingChroma_VerEdge_I(
+        pSrcDst, srcdstStep, pAlpha, pBeta, pThresholds, pBS);
+
+    armRetArgErrIf(errorCode != OMX_Sts_NoErr, errorCode)
+    
+    errorCode = omxVCM4P10_FilterDeblockingChroma_HorEdge_I(
+        pSrcDst, srcdstStep, pAlpha+2, pBeta+2, pThresholds+8, pBS+16);
+
+    return errorCode;
+}
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_DeblockLuma_I.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_DeblockLuma_I.c
new file mode 100755
index 0000000..619365f
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_DeblockLuma_I.c
@@ -0,0 +1,91 @@
+/* ----------------------------------------------------------------
+ *
+ * 
+ * File Name:  omxVCM4P10_DeblockLuma_I.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   12290
+ * Date:       Wednesday, April 9, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * H.264 luma deblock
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+ 
+
+/**
+ * Function: omxVCM4P10_DeblockLuma_I
+ *
+ * Description:
+ * This function performs deblock filtering the horizontal and vertical edges of a luma macroblock
+ *(16x16).
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	pSrcDst         pointer to the input macroblock. Must be 8-byte aligned.
+ * [in]	srcdstStep      image width
+ * [in]	pAlpha          pointer to a 2x2 table of alpha thresholds, organized as follows: { external
+ *                             vertical edge, internal vertical edge, external horizontal
+ *                             edge, internal horizontal edge }
+ * [in]	pBeta			pointer to a 2x2 table of beta thresholds, organized as follows: { external
+ *                              vertical edge, internal vertical edge, external  horizontal edge,
+ *                              internal  horizontal edge }
+ * [in]	pThresholds		pointer to a 16x2 table of threshold (TC0), organized as follows: { values for
+ *                              the  left or above edge of each 4x4 block, arranged in  vertical block order
+ *                              and then in horizontal block order)
+ * [in]	pBS				 pointer to a 16x2 table of BS parameters arranged in scan block order for vertical edges and then horizontal edges;
+ *                               valid in the range [0,4] with the following restrictions: i) pBS[i]== 4 may occur only for 0<=i<=3, ii) pBS[i]== 4 if and only if pBS[i^1]== 4.  Must be 4-byte aligned.
+ * [out]	pSrcDst		pointer to filtered output macroblock.
+ *
+ * Return Value:
+ * OMX_Sts_NoErr - no error
+ * OMX_Sts_BadArgErr - bad arguments
+ *    - Either of the pointers in pSrcDst, pAlpha, pBeta, pTresholds or pBS is NULL.
+ *    - pSrcDst is not 8-byte aligned.
+ *    - srcdstStep is not a multiple of 8
+ *    - pBS is out of range, i.e., one of the following conditions is true: pBS[i]<0, pBS[i]>4, pBS[i]==4 for i>=4, or (pBS[i]==4 && pBS[i^1]!=4) for 0<=i<=3.
+.
+ *
+ */
+
+OMXResult omxVCM4P10_DeblockLuma_I(
+	OMX_U8* pSrcDst, 
+	OMX_S32 srcdstStep, 
+	const OMX_U8* pAlpha, 
+	const OMX_U8* pBeta, 
+	const OMX_U8* pThresholds, 
+	const OMX_U8 *pBS
+)
+{
+    OMXResult errorCode;
+    
+    armRetArgErrIf(pSrcDst == NULL,             OMX_Sts_BadArgErr);
+    armRetArgErrIf(armNot8ByteAligned(pSrcDst), OMX_Sts_BadArgErr);
+    armRetArgErrIf(srcdstStep & 7,              OMX_Sts_BadArgErr);    
+    armRetArgErrIf(pAlpha == NULL,              OMX_Sts_BadArgErr);
+    armRetArgErrIf(pBeta == NULL,               OMX_Sts_BadArgErr);
+    armRetArgErrIf(pThresholds == NULL,         OMX_Sts_BadArgErr);
+    armRetArgErrIf(armNot4ByteAligned(pThresholds), OMX_Sts_BadArgErr);
+    armRetArgErrIf(pBS == NULL,                     OMX_Sts_BadArgErr);
+    armRetArgErrIf(armNot4ByteAligned(pBS),         OMX_Sts_BadArgErr);
+
+    errorCode = omxVCM4P10_FilterDeblockingLuma_VerEdge_I(
+        pSrcDst, srcdstStep, pAlpha, pBeta, pThresholds, pBS);
+
+    armRetArgErrIf(errorCode != OMX_Sts_NoErr, errorCode)
+    
+    errorCode = omxVCM4P10_FilterDeblockingLuma_HorEdge_I(
+        pSrcDst, srcdstStep, pAlpha+2, pBeta+2, pThresholds+16, pBS+16);
+
+    return errorCode;
+}
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_DecodeChromaDcCoeffsToPairCAVLC.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_DecodeChromaDcCoeffsToPairCAVLC.c
new file mode 100755
index 0000000..4e871bf
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_DecodeChromaDcCoeffsToPairCAVLC.c
@@ -0,0 +1,62 @@
+/* ----------------------------------------------------------------
+ *
+ * 
+ * File Name:  omxVCM4P10_DecodeChromaDcCoeffsToPairCAVLC.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   12290
+ * Date:       Wednesday, April 9, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * H.264 decode coefficients module
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+
+/**
+ * Function: omxVCM4P10_DecodeChromaDcCoeffsToPairCAVLC
+ *
+ * Description:
+ * Performs CAVLC decoding and inverse raster scan for 2x2 block of 
+ * ChromaDCLevel. The decoded coefficients in packed position-coefficient 
+ * buffer are stored in increasing raster scan order, namely position order.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	ppBitStream		Double pointer to current byte in bit stream
+ *								buffer
+ * [in]	pOffset			Pointer to current bit position in the byte 
+ *								pointed to by *ppBitStream
+ * [out]	ppBitStream		*ppBitStream is updated after each block is decoded
+ * [out]	pOffset			*pOffset is updated after each block is decoded
+ * [out]	pNumCoeff		Pointer to the number of nonzero coefficients
+ *								in this block
+ * [out]	ppPosCoefbuf	Double pointer to destination residual
+ *								coefficient-position pair buffer
+ *
+ * Return Value:
+ * Standard omxError result. See enumeration for possible result codes.
+ *
+ */
+
+OMXResult omxVCM4P10_DecodeChromaDcCoeffsToPairCAVLC (
+     const OMX_U8** ppBitStream,
+     OMX_S32* pOffset,
+     OMX_U8* pNumCoeff,
+     OMX_U8** ppPosCoefbuf        
+ )
+
+{
+    return armVCM4P10_DecodeCoeffsToPair(ppBitStream, pOffset, pNumCoeff,
+                                         ppPosCoefbuf, 17, 4);
+
+}
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_DecodeCoeffsToPairCAVLC.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_DecodeCoeffsToPairCAVLC.c
new file mode 100755
index 0000000..b29e576
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_DecodeCoeffsToPairCAVLC.c
@@ -0,0 +1,68 @@
+/* ----------------------------------------------------------------
+ *
+ * 
+ * File Name:  omxVCM4P10_DecodeCoeffsToPairCAVLC.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   12290
+ * Date:       Wednesday, April 9, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * H.264 decode coefficients module
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+
+/**
+ * Function: omxVCM4P10_DecodeCoeffsToPairCAVLC
+ *
+ * Description:
+ * Performs CAVLC decoding and inverse zigzag scan for 4x4 block of 
+ * Intra16x16DCLevel, Intra16x16ACLevel,LumaLevel, and ChromaACLevel. 
+ * Inverse field scan is not supported. The decoded coefficients in packed 
+ * position-coefficient buffer are stored in increasing zigzag order instead 
+ * of position order.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	ppBitStream		Double pointer to current byte in bit stream buffer
+ * [in]	pOffset			Pointer to current bit position in the byte pointed
+ *								to by *ppBitStream
+ * [in]	sMaxNumCoeff	Maximum number of non-zero coefficients in current
+ *								block
+ * [in]	sVLCSelect		VLC table selector, obtained from number of non-zero
+ *								AC coefficients of above and left 4x4 blocks. It is 
+ *								equivalent to the variable nC described in H.264 standard 
+ *								table 9-5, except its value can¡¯t be less than zero.
+ * [out]	ppBitStream		*ppBitStream is updated after each block is decoded
+ * [out]	pOffset			*pOffset is updated after each block is decoded
+ * [out]	pNumCoeff		Pointer to the number of nonzero coefficients in
+ *								this block
+ * [out]	ppPosCoefbuf	Double pointer to destination residual
+ *								coefficient-position pair buffer
+ * Return Value:
+ * Standard omxError result. See enumeration for possible result codes.
+ *
+ */
+
+OMXResult omxVCM4P10_DecodeCoeffsToPairCAVLC(
+     const OMX_U8** ppBitStream,
+     OMX_S32* pOffset,
+     OMX_U8* pNumCoeff,
+     OMX_U8**ppPosCoefbuf,
+     OMX_INT sVLCSelect,
+     OMX_INT sMaxNumCoeff        
+ )
+{
+    return armVCM4P10_DecodeCoeffsToPair(ppBitStream, pOffset, pNumCoeff,
+                                         ppPosCoefbuf, sVLCSelect, sMaxNumCoeff);
+}
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_DequantTransformResidualFromPairAndAdd_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_DequantTransformResidualFromPairAndAdd_s.s
new file mode 100755
index 0000000..485a488
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_DequantTransformResidualFromPairAndAdd_s.s
@@ -0,0 +1,396 @@
+;//
+;// 
+;// File Name:  omxVCM4P10_DequantTransformResidualFromPairAndAdd_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   12290
+;// Date:       Wednesday, April 9, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+;// Description:
+;// H.264 inverse quantize and transform module
+;// 
+;// 
+
+        
+
+;// Include standard headers
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+        
+;// Import symbols required from other files
+;// (For example tables)
+    
+        IMPORT armVCM4P10_UnpackBlock4x4
+        IMPORT armVCM4P10_TransformResidual4x4
+        IMPORT armVCM4P10_QPDivTable
+        IMPORT armVCM4P10_VMatrixU16
+        IMPORT armVCM4P10_QPModuloTable 
+        
+        M_VARIANTS CortexA8
+        
+;// Set debugging level        
+;//DEBUG_ON    SETL {TRUE}
+
+
+;// Static Function: armVCM4P10_DequantLumaAC4x4
+
+;// Guarding implementation by the processor name
+    
+ 
+
+;// Guarding implementation by the processor name
+    
+
+
+
+
+
+;// Function: omxVCM4P10_DequantTransformResidualFromPairAndAdd            
+    
+;// Guarding implementation by the processor name
+    
+    
+    
+;// Function: omxVCM4P10_DequantTransformResidualFromPairAndAdd            
+    
+;// Guarding implementation by the processor name
+    
+    IF  CortexA8
+    
+
+;// ARM Registers
+
+;//Input Registers
+ppSrc       RN  0
+pPred       RN  1
+pDC         RN  2
+pDst        RN  3
+   
+
+;//Output Registers
+result      RN  0
+
+;//Local Scratch Registers
+
+;//Registers used in armVCM4P10_DequantLumaAC4x4
+pQPdiv      RN  10
+pQPmod      RN  11
+pVRow       RN  2
+QPmod       RN  12
+shift       RN  14
+index0      RN  1 
+index1      RN  10 
+
+;//Registers used in DequantTransformResidualFromPairAndAdd
+pDelta      RN  4
+pDeltaTmp   RN  6
+AC          RN  5                   ;//Load from stack
+pPredTemp   RN  7
+pDCTemp     RN  8
+pDstTemp    RN  9
+pDeltaArg1  RN  1
+pDeltaArg0  RN  0
+QP          RN  1                   ;//Load from stack
+DCval       RN  10  
+predstep    RN  1
+dstStep     RN  10
+PredVal1    RN  3
+PredVal2    RN  5
+
+
+
+
+;// Neon Registers
+
+;// Registers used in armVCM4P10_DequantLumaAC4x4
+
+dVmatrix            DN  D6.8  
+dindexRow0          DN  D7.32 
+dindexRow1          DN  D9.32 
+dByteIndexRow0      DN  D7.8
+dByteIndexRow1      DN  D9.8
+dVRow0              DN  D8.8  
+dVRow1              DN  D4.8
+dVRow0U16           DN  D8.U16
+dVRow1U16           DN  D4.U16
+dVRow2U16           DN  D8.U16
+dVRow3U16           DN  D4.U16
+
+dShift              DN  D5.U16
+dSrcRow0            DN  D0.I16
+dSrcRow1            DN  D1.I16
+dSrcRow2            DN  D2.I16    
+dSrcRow3            DN  D3.I16
+dDqntRow0           DN  D0.I16  
+dDqntRow1           DN  D1.I16 
+dDqntRow2           DN  D2.I16 
+dDqntRow3           DN  D3.I16  
+
+;// Registers used in TransformResidual4x4
+
+;// Packed Input pixels
+dIn0                DN  D0.S16       
+dIn1                DN  D1.S16       
+dIn2                DN  D2.S16       
+dIn3                DN  D3.S16
+qIn01               QN  Q0.32
+qIn23               QN  Q1.32
+
+;// Intermediate calculations       
+dZero               DN  D4.S16
+de0                 DN  D5.S16
+de1                 DN  D6.S16
+de2                 DN  D7.S16
+de3                 DN  D8.S16
+dIn1RS              DN  D7.S16
+dIn3RS              DN  D8.S16
+df0                 DN  D0.S16
+df1                 DN  D1.S16
+df2                 DN  D2.S16
+df3                 DN  D3.S16
+qf01                QN  Q0.32
+qf23                QN  Q1.32
+dg0                 DN  D5.S16
+dg1                 DN  D6.S16
+dg2                 DN  D7.S16
+dg3                 DN  D8.S16
+df1RS               DN  D7.S16
+df3RS               DN  D8.S16
+
+;// Output pixels
+dh0                 DN  D0.S16
+dh1                 DN  D1.S16
+dh2                 DN  D2.S16
+dh3                 DN  D3.S16 
+
+;// Registers used in DequantTransformResidualFromPairAndAdd
+
+dDeltaRow0          DN  D0.S16
+dDeltaRow1          DN  D1.S16
+dDeltaRow2          DN  D2.S16
+dDeltaRow3          DN  D3.S16
+qDeltaRow01         QN  Q0.S16
+qDeltaRow23         QN  Q1.S16
+
+dPredValRow01       DN  D4.U8
+dPredValRow23       DN  D5.U8
+
+qSumRow01           QN  Q3.S16
+qSumRow23           QN  Q4.S16
+dDstRow01           DN  D0.U8
+dDstRow23           DN  D1.U8
+dDstRow0            DN  D0.32[0]
+dDstRow1            DN  D0.32[1]
+dDstRow2            DN  D1.32[0]
+dDstRow3            DN  D1.32[1]
+    
+           
+    ;// Allocate stack memory required by the function
+        M_ALLOC8 pBuffer, 32
+               
+
+    ;// Write function header
+        M_START omxVCM4P10_DequantTransformResidualFromPairAndAdd,r11,d9
+        
+        ;// Define stack arguments
+        M_ARG   predStepOnStack, 4
+        M_ARG   dstStepOnStack,4
+        M_ARG   QPOnStack, 4
+        M_ARG   ACOnStack,4
+  
+        
+        M_ADR   pDelta,pBuffer 
+        M_LDR   AC,ACOnStack 
+        
+         
+        ;// Save registers r1,r2,r3 before function call    
+        MOV     pPredTemp,pPred
+        MOV     pDCTemp,pDC
+        MOV     pDstTemp,pDst
+        
+        CMP     AC,#0
+        BEQ     DCcase
+        MOV     pDeltaArg1,pDelta                           ;// Set up r1 for armVCM4P10_UnpackBlock4x4
+    
+        BL      armVCM4P10_UnpackBlock4x4
+    
+        ;//--------------------------------------------------------
+        ;// armVCM4P10_DequantLumaAC4x4 : static function inlined
+        ;//--------------------------------------------------------
+        
+        ;//BL      armVCM4P10_DequantLumaAC4x4
+        M_LDR   QP,QPOnStack                                ;// Set up r1 for armVCM4P10_DequantLumaAC4x4
+                
+        LDR    pQPmod,=armVCM4P10_QPModuloTable
+        LDR    pQPdiv,=armVCM4P10_QPDivTable        
+        LDR    pVRow,=armVCM4P10_VMatrixU16
+        
+        
+        LDRSB  QPmod,[pQPmod,QP]                    ;// (QP%6) * 6
+        LDRSB  shift,[pQPdiv,QP]                    ;// Shift = QP / 6
+                
+        LDR    index1,=0x03020504 
+        LDR    index0,=0x05040100                   ;// Indexes into dVmatrix
+        ADD    pVRow,pVRow,QPmod
+        VDUP   dindexRow0,index0 
+        VDUP   dindexRow1,index1
+        VDUP   dShift,shift 
+        
+        ;// Load all 4x4 pVRow[] values
+        VLD1   dVmatrix,[pVRow]                     ;// dVmatrix = [0d|0c|0b|0a]
+        
+        
+        VTBL   dVRow0,dVmatrix,dByteIndexRow0       ;// row0 = row2 = [pVRow[2] | pVRow[0] | pVRow[2] | pVRow[0]]
+        VTBL   dVRow1,dVmatrix,dByteIndexRow1       ;// row1 = row3 = [pVRow[1] | pVRow[2] | pVRow[1] | pVRow[2]]
+        CMP     pDCTemp,#0
+        ;// Load all the 4x4 'src' values  
+        VLD1   { dSrcRow0,dSrcRow1,dSrcRow2,dSrcRow3 },[pDelta] 
+        
+        VSHL   dVRow0U16,dVRow0U16,dShift 
+        VSHL   dVRow1U16,dVRow1U16,dShift 
+        LDRSHNE DCval,[pDCTemp]
+        
+        
+        ;// Multiply src[] with pVRow[]
+        VMUL    dDqntRow0,dSrcRow0,dVRow0U16
+        VMUL    dDqntRow1,dSrcRow1,dVRow1U16
+        VMUL    dDqntRow2,dSrcRow2,dVRow2U16
+        VMUL    dDqntRow3,dSrcRow3,dVRow3U16
+        
+        
+        
+        ;//-------------------------------------------------------------
+        ;// TransformResidual4x4 : Inlined to avoid Load/Stores
+        ;//-------------------------------------------------------------
+        
+        
+        ;//BL      armVCM4P10_TransformResidual4x4
+        ;//STRHNE  DCval,[pDelta]
+        VMOVNE    dIn0[0],DCval
+        
+        
+        
+        ;//*****************************************************************
+        ;// Transpose the input pixels : perform Row ops as Col ops
+        ;//*****************************************************************
+        
+        VTRN    dIn0,dIn1
+        VTRN    dIn2,dIn3
+        VTRN    qIn01,qIn23 
+         
+        
+        VMOV    dZero,#0                                    ;// Used to right shift by 1 
+        
+        
+        ;//**************************************** 
+        ;// Row Operations (Performed on columns)
+        ;//**************************************** 
+        
+        
+        VADD        de0,dIn0,dIn2                       ;//  e0 = d0 + d2 
+        VSUB        de1,dIn0,dIn2                        ;//  e1 = d0 - d2 
+        VHADD       dIn1RS,dIn1,dZero                   ;// (f1>>1) constZero is a register holding 0
+        VHADD       dIn3RS,dIn3,dZero
+        VSUB        de2,dIn1RS,dIn3                     ;//  e2 = (d1>>1) - d3 
+        VADD        de3,dIn1,dIn3RS                        ;//  e3 = d1 + (d3>>1) 
+        VADD        df0,de0,de3                         ;//  f0 = e0 + e3
+        VADD        df1,de1,de2                            ;//  f1 = e1 + e2
+        VSUB        df2,de1,de2                            ;//  f2 = e1 - e2
+        VSUB        df3,de0,de3                            ;//  f3 = e0 - e3
+        
+        
+        
+        ;//*****************************************************************
+        ;// Transpose the resultant matrix
+        ;//*****************************************************************
+        
+        VTRN    df0,df1
+        VTRN    df2,df3
+        VTRN    qf01,qf23 
+        
+        
+        ;//******************************* 
+        ;// Coloumn Operations 
+        ;//******************************* 
+        
+        
+        VADD        dg0,df0,df2                         ;//  e0 = d0 + d2 
+        VSUB        dg1,df0,df2                            ;//  e1 = d0 - d2 
+        VHADD       df1RS,df1,dZero                     ;// (f1>>1) constZero is a register holding 0
+        VHADD       df3RS,df3,dZero
+        VSUB        dg2,df1RS,df3                       ;//  e2 = (d1>>1) - d3 
+        VADD        dg3,df1,df3RS                        ;//  e3 = d1 + (d3>>1) 
+        VADD        dh0,dg0,dg3                         ;//  f0 = e0 + e3
+        VADD        dh1,dg1,dg2                            ;//  f1 = e1 + e2
+        VSUB        dh2,dg1,dg2                            ;//  f2 = e1 - e2
+        VSUB        dh3,dg0,dg3                            ;//  f3 = e0 - e3
+        
+             
+        ;//************************************************
+        ;// Calculate final value (colOp[i][j] + 32)>>6
+        ;//************************************************
+        
+        VRSHR       dh0,#6
+        VRSHR       dh1,#6
+        VRSHR       dh2,#6
+        VRSHR       dh3,#6
+        
+               
+        B       OutDCcase 
+        
+
+DCcase
+        ;// Calculate the Transformed DCvalue : (DCval+32)>>6
+        LDRSH   DCval,[pDCTemp] 
+        ADD     DCval,DCval,#32 
+        ASR     DCval,DCval,#6
+        
+        VDUP    dDeltaRow0, DCval                       ;// pDelta[0]  = pDelta[1]  = pDelta[2]  = pDelta[3] = DCval
+        VDUP    dDeltaRow1, DCval                        ;// pDelta[4]  = pDelta[5]  = pDelta[6]  = pDelta[7] = DCval
+        VDUP    dDeltaRow2, DCval                        ;// pDelta[8]  = pDelta[9]  = pDelta[10] = pDelta[11] = DCval
+        VDUP    dDeltaRow3, DCval
+            
+                
+OutDCcase      
+        M_LDR   predstep,predStepOnStack
+        M_LDR   dstStep,dstStepOnStack
+        
+        LDR     PredVal1,[pPredTemp],predstep
+        LDR     PredVal2,[pPredTemp],predstep
+        VMOV    dPredValRow01,PredVal1,PredVal2
+        
+        LDR     PredVal1,[pPredTemp],predstep
+        LDR     PredVal2,[pPredTemp]
+        VMOV    dPredValRow23,PredVal1,PredVal2
+ 
+        
+        VADDW   qSumRow01,qDeltaRow01,dPredValRow01
+        VADDW   qSumRow23,qDeltaRow23,dPredValRow23
+        VQMOVUN dDstRow01,qSumRow01
+        VQMOVUN dDstRow23,qSumRow23
+        
+ 
+        VST1    dDstRow0,[pDstTemp],dstStep
+        VST1    dDstRow1,[pDstTemp],dstStep
+        VST1    dDstRow2,[pDstTemp],dstStep
+        VST1    dDstRow3,[pDstTemp]
+        
+        ;// Set return value
+        MOV     result,#OMX_Sts_NoErr
+        
+End                
+
+        
+        ;// Write function tail
+        
+        M_END
+        
+    ENDIF                                                    ;//CORTEXA8   
+    
+         
+            
+    END
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_FilterDeblockingChroma_HorEdge_I_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_FilterDeblockingChroma_HorEdge_I_s.s
new file mode 100644
index 0000000..4606197
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_FilterDeblockingChroma_HorEdge_I_s.s
@@ -0,0 +1,202 @@
+;//
+;// 
+;// File Name:  omxVCM4P10_FilterDeblockingChroma_HorEdge_I_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   12290
+;// Date:       Wednesday, April 9, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+
+        M_VARIANTS CortexA8
+
+        IF CortexA8
+
+        IMPORT  armVCM4P10_DeblockingChromabSGE4_unsafe
+        IMPORT  armVCM4P10_DeblockingChromabSLT4_unsafe
+        
+LOOP_COUNT  EQU 0x40000000
+MASK_3      EQU 0x03030303
+MASK_4      EQU 0x04040404
+
+;// Function arguments
+
+pSrcDst     RN 0
+srcdstStep  RN 1
+pAlpha      RN 2
+pBeta       RN 3
+
+pThresholds RN 5
+pBS         RN 4
+bS3210      RN 6
+
+;// Loop 
+
+XY          RN 7
+
+;// Pixels
+dP_0        DN D4.U8
+dP_1        DN D5.U8  
+dP_2        DN D6.U8  
+dQ_0        DN D8.U8  
+dQ_1        DN D9.U8  
+dQ_2        DN D10.U8 
+
+;// Filtering Decision
+dAlpha      DN D0.U8
+dBeta       DN D2.U8
+
+dFilt       DN D16.U8
+dAqflg      DN D12.U8
+dApflg      DN D17.U8 
+
+dAp0q0      DN D13.U8
+dAp1p0      DN D12.U8
+dAq1q0      DN D18.U8
+dAp2p0      DN D19.U8
+dAq2q0      DN D17.U8
+
+qBS3210     QN Q13.U16
+dBS3210     DN D26
+dMask_bs    DN D27
+dFilt_bs    DN D26.U16
+
+;// bSLT4
+dMask_0     DN D14.U8
+dMask_1     DN D15.U8    
+dMask_4     DN D1.U16
+
+Mask_4      RN 8
+Mask_3      RN 9
+
+dTemp       DN D19.U8
+
+;// Result
+dP_0t       DN D13.U8   
+dQ_0t       DN D31.U8   
+
+dP_0n       DN D29.U8
+dQ_0n       DN D24.U8
+
+        
+        ;// Function header
+        M_START omxVCM4P10_FilterDeblockingChroma_HorEdge_I, r9, d15
+        
+        ;//Arguments on the stack
+        M_ARG   ppThresholds, 4
+        M_ARG   ppBS, 4
+        
+        ;// d0-dAlpha_0
+        ;// d2-dBeta_0
+
+        ;load alpha1,beta1 somewhere to avoid more loads
+        VLD1        {dAlpha[]}, [pAlpha]!
+        SUB         pSrcDst, pSrcDst, srcdstStep, LSL #1 ;?
+        SUB         pSrcDst, pSrcDst, srcdstStep
+        VLD1        {dBeta[]}, [pBeta]! 
+        
+        M_LDR       pBS, ppBS
+        M_LDR       pThresholds, ppThresholds 
+
+        LDR         Mask_3, =MASK_3
+        LDR         Mask_4, =MASK_4
+
+        VMOV        dMask_0, #0     
+        VMOV        dMask_1, #1     
+        VMOV        dMask_4, #4     
+        
+        LDR         XY, =LOOP_COUNT
+
+        ;// p0-p3 - d4-d7
+        ;// q0-q3 - d8-d11
+LoopY        
+        LDR         bS3210, [pBS], #8
+        
+        VLD1        dP_2, [pSrcDst], srcdstStep
+        ;1
+        VLD1        dP_1, [pSrcDst], srcdstStep
+        CMP         bS3210, #0
+        VLD1        dP_0, [pSrcDst], srcdstStep
+        ;1
+        VLD1        dQ_0, [pSrcDst], srcdstStep
+        VABD        dAp2p0, dP_2, dP_0
+        VLD1        dQ_1, [pSrcDst], srcdstStep
+        VABD        dAp0q0, dP_0, dQ_0
+        VLD1        dQ_2, [pSrcDst], srcdstStep
+        BEQ         NoFilterBS0
+
+        VABD        dAp1p0, dP_1, dP_0
+        VABD        dAq1q0, dQ_1, dQ_0
+
+        VCGT        dFilt, dAlpha, dAp0q0
+        VMOV.U32    dBS3210[0], bS3210
+        VMAX        dAp1p0, dAq1q0, dAp1p0
+        VMOVL       qBS3210, dBS3210.U8
+        VABD        dAq2q0, dQ_2, dQ_0
+        VCGT        dMask_bs.S16, dBS3210.S16, #0
+
+        VCGT        dAp1p0, dBeta, dAp1p0 
+        VCGT        dAp2p0, dBeta, dAp2p0
+        
+        VAND        dFilt, dMask_bs.U8
+
+        TST         bS3210, Mask_3
+
+        VCGT        dAq2q0, dBeta, dAq2q0
+        VAND        dFilt, dFilt, dAp1p0
+
+        VAND        dAqflg, dFilt, dAq2q0
+        VAND        dApflg, dFilt, dAp2p0
+        
+        ;// bS < 4 Filtering
+        BLNE        armVCM4P10_DeblockingChromabSLT4_unsafe
+
+        TST         bS3210, Mask_4        
+
+        SUB         pSrcDst, pSrcDst, srcdstStep, LSL #2
+        VTST        dFilt_bs, dFilt_bs, dMask_4
+
+        ;// bS == 4 Filtering
+        BLNE        armVCM4P10_DeblockingChromabSGE4_unsafe
+                    
+        VBIT        dP_0n, dP_0t, dFilt_bs
+        VBIT        dQ_0n, dQ_0t, dFilt_bs
+        
+        VBIF        dP_0n, dP_0, dFilt      
+        VBIF        dQ_0n, dQ_0, dFilt  
+
+        ;// Result Storage
+        VST1        dP_0n, [pSrcDst], srcdstStep
+        ADDS        XY, XY, XY
+        VST1        dQ_0n, [pSrcDst], srcdstStep
+
+        BNE         LoopY        
+        
+        MOV         r0, #OMX_Sts_NoErr
+
+        M_EXIT
+        
+NoFilterBS0
+
+        VLD1        {dAlpha[]}, [pAlpha]
+        SUB         pSrcDst, pSrcDst, srcdstStep, LSL #1
+        ADDS        XY, XY, XY
+        VLD1        {dBeta[]}, [pBeta]
+        ADD         pThresholds, pThresholds, #4
+        BNE         LoopY        
+
+        MOV         r0, #OMX_Sts_NoErr
+        M_END
+        
+        ENDIF
+        
+
+        END
+        
+        
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_FilterDeblockingChroma_VerEdge_I_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_FilterDeblockingChroma_VerEdge_I_s.s
new file mode 100644
index 0000000..18e6c1d
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_FilterDeblockingChroma_VerEdge_I_s.s
@@ -0,0 +1,282 @@
+;//
+;// 
+;// File Name:  omxVCM4P10_FilterDeblockingChroma_VerEdge_I_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   12290
+;// Date:       Wednesday, April 9, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+
+        M_VARIANTS CortexA8
+
+        IF CortexA8
+
+        IMPORT  armVCM4P10_DeblockingChromabSGE4_unsafe
+        IMPORT  armVCM4P10_DeblockingChromabSLT4_unsafe
+        
+LOOP_COUNT  EQU 0x40000000
+MASK_3      EQU 0x03030303
+MASK_4      EQU 0x04040404
+
+;// Function arguments
+
+pSrcDst     RN 0
+srcdstStep  RN 1
+pAlpha      RN 2
+pBeta       RN 3
+
+pThresholds RN 5
+pBS         RN 4
+bS3210      RN 6
+pSrcDst_P   RN 10
+pSrcDst_Q   RN 12
+
+pTmp        RN 10
+pTmp2       RN 12
+step        RN 14
+
+;// Loop 
+
+XY          RN 7
+
+;// Rows input
+dRow0       DN D7.U8
+dRow1       DN D8.U8  
+dRow2       DN D5.U8  
+dRow3       DN D10.U8  
+dRow4       DN D6.U8  
+dRow5       DN D9.U8  
+dRow6       DN D4.U8 
+dRow7       DN D11.U8 
+
+
+;// Pixels
+dP_0        DN D4.U8
+dP_1        DN D5.U8  
+dP_2        DN D6.U8  
+dQ_0        DN D8.U8  
+dQ_1        DN D9.U8  
+dQ_2        DN D10.U8 
+
+;// Filtering Decision
+dAlpha      DN D0.U8
+dBeta       DN D2.U8
+
+dFilt       DN D16.U8
+dAqflg      DN D12.U8
+dApflg      DN D17.U8 
+
+dAp0q0      DN D13.U8
+dAp1p0      DN D12.U8
+dAq1q0      DN D18.U8
+dAp2p0      DN D19.U8
+dAq2q0      DN D17.U8
+
+qBS3210     QN Q13.U16
+dBS3210     DN D26
+dMask_bs    DN D27
+dFilt_bs    DN D26.U16
+
+;// bSLT4
+dMask_0     DN D14.U8
+dMask_1     DN D15.U8    
+dMask_4     DN D1.U16
+
+Mask_4      RN 8
+Mask_3      RN 9
+
+dTemp       DN D19.U8
+
+;// Result
+dP_0t       DN D13.U8   
+dQ_0t       DN D31.U8   
+
+dP_0n       DN D29.U8
+dQ_0n       DN D24.U8
+
+        
+        ;// Function header
+        M_START omxVCM4P10_FilterDeblockingChroma_VerEdge_I, r12, d15
+        
+        ;//Arguments on the stack
+        M_ARG   ppThresholds, 4
+        M_ARG   ppBS, 4
+        
+        ;// d0-dAlpha_0
+        ;// d2-dBeta_0
+
+        ;load alpha1,beta1 somewhere to avoid more loads
+        VLD1        {dAlpha[]}, [pAlpha]!
+        SUB         pSrcDst, pSrcDst, #4
+        VLD1        {dBeta[]}, [pBeta]! 
+        
+        M_LDR       pBS, ppBS
+        M_LDR       pThresholds, ppThresholds 
+
+        LDR         Mask_4, =MASK_4
+        LDR         Mask_3, =MASK_3
+
+        ;dMask_0-14
+        ;dMask_1-15
+        ;dMask_4-19
+
+        VMOV        dMask_0, #0     
+        VMOV        dMask_1, #1     
+        VMOV        dMask_4, #4     
+        
+        LDR         XY, =LOOP_COUNT
+
+        ;// p0-p3 - d4-d7
+        ;// q0-q3 - d8-d11
+
+
+LoopY        
+        LDR         bS3210, [pBS], #8
+        ADD         pTmp, pSrcDst, srcdstStep
+        ADD         step, srcdstStep, srcdstStep
+        
+        ;1
+        VLD1        dRow0, [pSrcDst], step
+        ;1
+        VLD1        dRow1, [pTmp], step
+        VLD1        dRow2, [pSrcDst], step
+        VLD1        dRow3, [pTmp], step
+        VLD1        dRow4, [pSrcDst], step
+        VLD1        dRow5, [pTmp], step
+        VLD1        dRow6, [pSrcDst], step
+        VLD1        dRow7, [pTmp], step
+        
+        
+        ;// dRow0 = [q3r0 q2r0 q1r0 q0r0 p0r0 p1r0 p2r0 p3r0]
+        ;// dRow1 = [q3r1 q2r1 q1r1 q0r1 p0r1 p1r1 p2r1 p3r1]
+        ;// dRow2 = [q3r2 q2r2 q1r2 q0r2 p0r2 p1r2 p2r2 p3r2]
+        ;// dRow3 = [q3r3 q2r3 q1r3 q0r3 p0r3 p1r3 p2r3 p3r3]
+        ;// dRow4 = [q3r4 q2r4 q1r4 q0r4 p0r4 p1r4 p2r4 p3r4]
+        ;// dRow5 = [q3r5 q2r5 q1r5 q0r5 p0r5 p1r5 p2r5 p3r5]
+        ;// dRow6 = [q3r6 q2r6 q1r6 q0r6 p0r6 p1r6 p2r6 p3r6]
+        ;// dRow7 = [q3r7 q2r7 q1r7 q0r7 p0r7 p1r7 p2r7 p3r7]
+
+        ;// 8x8 Transpose
+        VZIP.8      dRow0, dRow1
+        VZIP.8      dRow2, dRow3
+        VZIP.8      dRow4, dRow5
+        VZIP.8      dRow6, dRow7
+
+        VZIP.16     dRow0, dRow2
+        VZIP.16     dRow1, dRow3
+        VZIP.16     dRow4, dRow6
+        VZIP.16     dRow5, dRow7
+
+        VZIP.32     dRow0, dRow4
+        VZIP.32     dRow2, dRow6
+        VZIP.32     dRow3, dRow7
+        VZIP.32     dRow1, dRow5
+
+
+        ;Realign the pointers
+
+        CMP         bS3210, #0
+        VABD        dAp2p0, dP_2, dP_0
+        VABD        dAp0q0, dP_0, dQ_0
+        BEQ         NoFilterBS0
+
+        VABD        dAp1p0, dP_1, dP_0
+        VABD        dAq1q0, dQ_1, dQ_0
+
+        VMOV.U32    dBS3210[0], bS3210
+        VCGT        dFilt, dAlpha, dAp0q0
+        VMAX        dAp1p0, dAq1q0, dAp1p0
+        VMOVL       qBS3210, dBS3210.U8
+        VABD        dAq2q0, dQ_2, dQ_0
+        VCGT        dMask_bs.S16, dBS3210.S16, #0
+
+        VCGT        dAp1p0, dBeta, dAp1p0
+        VCGT        dAp2p0, dBeta, dAp2p0
+        VAND        dFilt, dMask_bs.U8
+
+        TST         bS3210, Mask_3
+
+        VCGT        dAq2q0, dBeta, dAq2q0
+        VAND        dFilt, dFilt, dAp1p0
+
+        VAND        dAqflg, dFilt, dAq2q0
+        VAND        dApflg, dFilt, dAp2p0
+
+        ;// bS < 4 Filtering
+        BLNE        armVCM4P10_DeblockingChromabSLT4_unsafe
+
+        TST         bS3210, Mask_4        
+
+        SUB         pSrcDst, pSrcDst, srcdstStep, LSL #3
+        VTST        dFilt_bs, dFilt_bs, dMask_4
+
+        ;// bS == 4 Filtering
+        BLNE        armVCM4P10_DeblockingChromabSGE4_unsafe
+
+        VBIT        dP_0n, dP_0t, dFilt_bs
+        VBIT        dQ_0n, dQ_0t, dFilt_bs
+
+        ;// Result Storage
+        ADD         pSrcDst_P, pSrcDst, #3
+        VBIF        dP_0n, dP_0, dFilt      
+        
+        ADD         pTmp2, pSrcDst_P, srcdstStep
+        ADD         step, srcdstStep, srcdstStep
+        VBIF        dQ_0n, dQ_0, dFilt  
+
+        ADDS        XY, XY, XY
+        
+        VST1        {dP_0n[0]}, [pSrcDst_P], step
+        VST1        {dP_0n[1]}, [pTmp2], step
+        VST1        {dP_0n[2]}, [pSrcDst_P], step
+        VST1        {dP_0n[3]}, [pTmp2], step
+        VST1        {dP_0n[4]}, [pSrcDst_P], step
+        VST1        {dP_0n[5]}, [pTmp2], step
+        VST1        {dP_0n[6]}, [pSrcDst_P], step
+        VST1        {dP_0n[7]}, [pTmp2], step
+        
+        ADD         pSrcDst_Q, pSrcDst, #4
+        ADD         pTmp, pSrcDst_Q, srcdstStep
+        
+        VST1        {dQ_0n[0]}, [pSrcDst_Q], step
+        VST1        {dQ_0n[1]}, [pTmp], step
+        VST1        {dQ_0n[2]}, [pSrcDst_Q], step
+        VST1        {dQ_0n[3]}, [pTmp], step
+        VST1        {dQ_0n[4]}, [pSrcDst_Q], step
+        VST1        {dQ_0n[5]}, [pTmp], step
+        VST1        {dQ_0n[6]}, [pSrcDst_Q], step
+        VST1        {dQ_0n[7]}, [pTmp], step
+        
+        ADD         pSrcDst, pSrcDst, #4
+
+        BNE         LoopY        
+        
+        MOV         r0, #OMX_Sts_NoErr
+        
+        M_EXIT
+        
+NoFilterBS0
+        VLD1        {dAlpha[]}, [pAlpha]
+        ADD         pSrcDst, pSrcDst, #4
+        SUB         pSrcDst, pSrcDst, srcdstStep, LSL #3
+        ADDS        XY, XY, XY
+        VLD1        {dBeta[]}, [pBeta]
+        ADD         pThresholds, pThresholds, #4
+        BNE         LoopY        
+
+        MOV         r0, #OMX_Sts_NoErr
+
+        M_END
+        
+        ENDIF
+
+
+        END
+        
+        
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_FilterDeblockingLuma_HorEdge_I_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_FilterDeblockingLuma_HorEdge_I_s.s
new file mode 100755
index 0000000..0c3f4f2
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_FilterDeblockingLuma_HorEdge_I_s.s
@@ -0,0 +1,288 @@
+;//
+;// 
+;// File Name:  omxVCM4P10_FilterDeblockingLuma_HorEdge_I_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   12290
+;// Date:       Wednesday, April 9, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+
+        M_VARIANTS CortexA8
+
+        IMPORT  armVCM4P10_DeblockingLumabSLT4_unsafe
+        IMPORT  armVCM4P10_DeblockingLumabSGE4_unsafe
+
+        IF CortexA8
+
+LOOP_COUNT  EQU 0x55000000
+
+
+;// Function arguments
+
+pSrcDst     RN 0
+srcdstStep  RN 1
+pAlpha      RN 2
+pBeta       RN 3
+
+pThresholds RN 5
+pBS         RN 4
+bS10        RN 12
+
+pAlpha_0    RN 2
+pBeta_0     RN 3
+
+pAlpha_1    RN 7
+pBeta_1     RN 8
+
+
+
+;// Loop 
+
+XY          RN 9
+
+pTmp        RN 6
+step        RN 10
+
+;// Pixels
+dP_0        DN D4.U8
+dP_1        DN D5.U8  
+dP_2        DN D6.U8  
+dP_3        DN D7.U8  
+dQ_0        DN D8.U8  
+dQ_1        DN D9.U8  
+dQ_2        DN D10.U8 
+dQ_3        DN D11.U8 
+
+
+;// Filtering Decision
+dAlpha      DN D0.U8
+dBeta       DN D2.U8
+
+dFilt       DN D16.U8
+dAqflg      DN D12.U8
+dApflg      DN D17.U8 
+
+dAp0q0      DN D13.U8
+dAp1p0      DN D12.U8
+dAq1q0      DN D18.U8
+dAp2p0      DN D19.U8
+dAq2q0      DN D17.U8
+
+;// bSLT4
+dTC0        DN D18.U8   
+dTC1        DN D19.U8   
+dTC01       DN D18.U8   
+
+dTCs        DN D31.S8
+dTC         DN D31.U8
+
+dMask_0     DN D14.U8
+dMask_1     DN D15.U8    
+
+Mask_0      RN 11
+
+dTemp       DN D19.U8
+
+;// Computing P0,Q0
+qDq0p0      QN Q10.S16
+qDp1q1      QN Q11.S16
+qDelta      QN Q10.S16  ; reuse qDq0p0
+dDelta      DN D20.S8
+
+
+;// Computing P1,Q1
+dRp0q0      DN D24.U8
+
+dMaxP       DN D23.U8
+dMinP       DN D22.U8
+
+dMaxQ       DN D19.U8
+dMinQ       DN D21.U8
+
+dDeltaP     DN D26.U8
+dDeltaQ     DN D27.U8
+
+qP_0n       QN Q14.S16
+qQ_0n       QN Q12.S16
+
+dQ_0n       DN D24.U8
+dQ_1n       DN D25.U8
+dP_0n       DN D29.U8
+dP_1n       DN D30.U8
+
+;// bSGE4
+
+qSp0q0      QN Q10.U16
+
+qSp2q1      QN Q11.U16
+qSp0q0p1    QN Q12.U16
+qSp3p2      QN Q13.U16
+dHSp0q1     DN D28.U8
+
+qSq2p1      QN Q11.U16
+qSp0q0q1    QN Q12.U16
+qSq3q2      QN Q13.U16  ;!!
+dHSq0p1     DN D28.U8   ;!!
+
+qTemp1      QN Q11.U16  ;!!;qSp2q1 
+qTemp2      QN Q12.U16  ;!!;qSp0q0p1        
+
+dP_0t       DN D28.U8   ;!!;dHSp0q1        
+dQ_0t       DN D22.U8   ;!!;Temp1        
+
+dP_0n       DN D29.U8
+dP_1n       DN D30.U8
+dP_2n       DN D31.U8
+
+dQ_0n       DN D24.U8   ;!!;Temp2        
+dQ_1n       DN D25.U8   ;!!;Temp2        
+dQ_2n       DN D28.U8   ;!!;dQ_0t        
+
+        
+        ;// Function header
+        M_START omxVCM4P10_FilterDeblockingLuma_HorEdge_I, r11, d15
+        
+        ;//Arguments on the stack
+        M_ARG   ppThresholds, 4
+        M_ARG   ppBS, 4
+        
+        ;// d0-dAlpha_0
+        ;// d2-dBeta_0
+
+        ADD         pAlpha_1, pAlpha_0, #1
+        ADD         pBeta_1, pBeta_0, #1
+        
+        VLD1        {dAlpha[]}, [pAlpha_0]
+        SUB         pSrcDst, pSrcDst, srcdstStep, LSL #2
+        VLD1        {dBeta[]}, [pBeta_0] 
+        
+        M_LDR       pBS, ppBS
+        M_LDR       pThresholds, ppThresholds 
+
+        MOV         Mask_0,#0
+
+        ;dMask_0-14
+        ;dMask_1-15
+
+        VMOV        dMask_0, #0     
+        VMOV        dMask_1, #1     
+        
+        ADD         step, srcdstStep, srcdstStep
+
+        LDR         XY,=LOOP_COUNT
+
+        ;// p0-p3 - d4-d7
+        ;// q0-q3 - d8-d11
+LoopY        
+LoopX        
+        LDRH        bS10, [pBS], #2
+        ADD         pTmp, pSrcDst, srcdstStep
+        CMP         bS10, #0
+        BEQ         NoFilterBS0
+
+        VLD1        dP_3, [pSrcDst], step
+        VLD1        dP_2, [pTmp], step
+        VLD1        dP_1, [pSrcDst], step
+        VLD1        dP_0, [pTmp], step
+        VLD1        dQ_0, [pSrcDst], step
+        VABD        dAp1p0, dP_0, dP_1
+        VLD1        dQ_1, [pTmp]
+        VABD        dAp0q0, dQ_0, dP_0
+        VLD1        dQ_2, [pSrcDst], srcdstStep
+        
+        VABD        dAq1q0, dQ_1, dQ_0
+        VABD        dAp2p0, dP_2, dP_0
+        VCGT        dFilt, dAlpha, dAp0q0
+
+        TST         bS10, #0xff
+        VMAX        dAp1p0, dAq1q0, dAp1p0
+        VABD        dAq2q0, dQ_2, dQ_0
+
+        VMOVEQ.U32  dFilt[0], Mask_0
+        TST         bS10, #0xff00
+
+        VCGT        dAp2p0, dBeta, dAp2p0
+        VCGT        dAp1p0, dBeta, dAp1p0
+
+        VMOVEQ.U32  dFilt[1], Mask_0
+
+        VCGT        dAq2q0, dBeta, dAq2q0
+        VLD1        dQ_3, [pSrcDst]
+        VAND        dFilt, dFilt, dAp1p0
+        TST         bS10, #4 
+
+        VAND        dAqflg, dFilt, dAq2q0
+        VAND        dApflg, dFilt, dAp2p0
+    
+        BNE         bSGE4        
+bSLT4
+        ;// bS < 4 Filtering
+        SUB         pSrcDst, pSrcDst, srcdstStep, LSL #2
+        SUB         pSrcDst, pSrcDst, srcdstStep
+
+        BL          armVCM4P10_DeblockingLumabSLT4_unsafe
+
+        ;// Result Storage
+        VST1        dP_1n, [pSrcDst], srcdstStep
+        VST1        dP_0n, [pSrcDst], srcdstStep
+        SUB         pTmp, pSrcDst, srcdstStep, LSL #2
+        VST1        dQ_0n, [pSrcDst], srcdstStep
+        ADDS        XY, XY, XY
+        VST1        dQ_1n, [pSrcDst]
+        ADD         pSrcDst, pTmp, #8
+
+        BCC         LoopX
+        B           ExitLoopY        
+
+NoFilterBS0
+        ADD         pSrcDst, pSrcDst, #8
+        ADDS        XY, XY, XY
+        ADD         pThresholds, pThresholds, #2
+        BCC         LoopX
+        B           ExitLoopY        
+bSGE4        
+        ;// bS >= 4 Filtering
+        SUB         pSrcDst, pSrcDst, srcdstStep, LSL #2
+        SUB         pSrcDst, pSrcDst, srcdstStep, LSL #1
+        BL          armVCM4P10_DeblockingLumabSGE4_unsafe
+
+        ;// Result Storage
+        VST1        dP_2n, [pSrcDst], srcdstStep
+        VST1        dP_1n, [pSrcDst], srcdstStep
+        VST1        dP_0n, [pSrcDst], srcdstStep
+        SUB         pTmp, pSrcDst, srcdstStep, LSL #2
+        VST1        dQ_0n, [pSrcDst], srcdstStep
+        ADDS        XY,XY,XY
+        VST1        dQ_1n, [pSrcDst], srcdstStep
+        ADD         pThresholds, pThresholds, #2
+        VST1        dQ_2n, [pSrcDst]
+        
+        ADD         pSrcDst, pTmp, #8
+        BCC         LoopX
+
+ExitLoopY        
+
+        SUB         pSrcDst, pSrcDst, #16
+        VLD1        {dAlpha[]}, [pAlpha_1]
+        ADD         pSrcDst, pSrcDst, srcdstStep, LSL #2 
+        VLD1        {dBeta[]}, [pBeta_1]
+        BNE         LoopY
+
+        MOV         r0, #OMX_Sts_NoErr
+
+        M_END
+        
+    ENDIF
+    
+
+        
+
+        END
+        
+        
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_FilterDeblockingLuma_VerEdge_I_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_FilterDeblockingLuma_VerEdge_I_s.s
new file mode 100755
index 0000000..e6fbb34
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_FilterDeblockingLuma_VerEdge_I_s.s
@@ -0,0 +1,436 @@
+;//
+;// 
+;// File Name:  omxVCM4P10_FilterDeblockingLuma_VerEdge_I_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   12290
+;// Date:       Wednesday, April 9, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+
+        M_VARIANTS CortexA8
+
+        IMPORT  armVCM4P10_DeblockingLumabSLT4_unsafe
+        IMPORT  armVCM4P10_DeblockingLumabSGE4_unsafe
+        
+        IF CortexA8
+
+LOOP_COUNT  EQU 0x11000000
+
+
+;// Function arguments
+
+pSrcDst     RN 0
+srcdstStep  RN 1
+pAlpha      RN 2
+pBeta       RN 3
+
+pThresholds RN 5
+pBS         RN 4
+bS10        RN 12
+
+pAlpha_0    RN 2
+pBeta_0     RN 3
+
+pAlpha_1    RN 7
+pBeta_1     RN 8
+
+pTmp        RN 10
+pTmpStep    RN 11
+
+;// Loop 
+
+XY          RN 9
+
+;// Rows input
+dRow0       DN D7.U8
+dRow1       DN D8.U8  
+dRow2       DN D5.U8  
+dRow3       DN D10.U8  
+dRow4       DN D6.U8  
+dRow5       DN D9.U8  
+dRow6       DN D4.U8 
+dRow7       DN D11.U8 
+
+;// dRow0 - dP_3, dRow1 - dQ_0, dRow2 - dP_1, dRow3 - dQ_2
+;// dRow4 - dP_2, dRow5 - dQ_1, dRow6 - dP_0, dRow7 - dQ_3
+
+;// Rows output
+dRown0      DN D7.U8
+dRown1      DN D24.U8
+dRown2      DN D30.U8
+dRown3      DN D10.U8
+dRown4      DN D6.U8
+dRown5      DN D25.U8
+dRown6      DN D29.U8
+dRown7      DN D11.U8
+
+;// dP_0n       DN D29.U8
+;// dP_1n       DN D30.U8
+;// dP_2n       DN D31.U8
+;// 
+;// dQ_0n       DN D24.U8   ;!!;Temp2        
+;// dQ_1n       DN D25.U8   ;!!;Temp2        
+;// dQ_2n       DN D28.U8   ;!!;dQ_0t        
+;// 
+;// dRown0 - dP_3,  dRown1 - dQ_0n
+;// dRown2 - dP_1n, dRown3 - dQ_2
+;// dRown4 - dP_2,  dRown5 - dQ_1n
+;// dRown6 - dP_0n, dRown7 - dQ_3
+
+dRow0n      DN D7.U8
+dRow1n      DN D24.U8
+dRow2n      DN D30.U8
+dRow3n      DN D28.U8
+dRow4n      DN D31.U8
+dRow5n      DN D25.U8
+dRow6n      DN D29.U8
+dRow7n      DN D11.U8
+
+;// dRow0n - dP_3, dRow1n - dQ_0n, dRow2n - dP_1n, dRow3n - dQ_2n
+;// dRow4n - dP_2, dRow5n - dQ_1n, dRow6n - dP_0n, dRow7n - dQ_3
+
+;// Pixels
+dP_0        DN D4.U8
+dP_1        DN D5.U8  
+dP_2        DN D6.U8  
+dP_3        DN D7.U8  
+dQ_0        DN D8.U8  
+dQ_1        DN D9.U8  
+dQ_2        DN D10.U8 
+dQ_3        DN D11.U8 
+
+
+;// Filtering Decision
+dAlpha      DN D0.U8
+dBeta       DN D2.U8
+
+dFilt       DN D16.U8
+dAqflg      DN D12.U8
+dApflg      DN D17.U8 
+
+dAp0q0      DN D13.U8
+dAp1p0      DN D12.U8
+dAq1q0      DN D18.U8
+dAp2p0      DN D19.U8
+dAq2q0      DN D17.U8
+
+;// bSLT4
+dTC0        DN D18.U8   
+dTC1        DN D19.U8   
+dTC01       DN D18.U8   
+
+dTCs        DN D31.S8
+dTC         DN D31.U8
+
+dMask_0     DN D14.U8
+dMask_1     DN D15.U8    
+
+Mask_0      RN 6
+
+dTemp       DN D19.U8
+
+;// Computing P0,Q0
+qDq0p0      QN Q10.S16
+qDp1q1      QN Q11.S16
+qDelta      QN Q10.S16  ; reuse qDq0p0
+dDelta      DN D20.S8
+
+
+;// Computing P1,Q1
+dRp0q0      DN D24.U8
+
+dMaxP       DN D23.U8
+dMinP       DN D22.U8
+
+dMaxQ       DN D19.U8
+dMinQ       DN D21.U8
+
+dDeltaP     DN D26.U8
+dDeltaQ     DN D27.U8
+
+qP_0n       QN Q14.S16
+qQ_0n       QN Q12.S16
+
+dQ_0n       DN D24.U8
+dQ_1n       DN D25.U8
+dP_0n       DN D29.U8
+dP_1n       DN D30.U8
+
+;// bSGE4
+
+qSp0q0      QN Q10.U16
+
+qSp2q1      QN Q11.U16
+qSp0q0p1    QN Q12.U16
+qSp3p2      QN Q13.U16
+dHSp0q1     DN D28.U8
+
+qSq2p1      QN Q11.U16
+qSp0q0q1    QN Q12.U16
+qSq3q2      QN Q13.U16  ;!!
+dHSq0p1     DN D28.U8   ;!!
+
+qTemp1      QN Q11.U16  ;!!;qSp2q1 
+qTemp2      QN Q12.U16  ;!!;qSp0q0p1        
+
+dP_0t       DN D28.U8   ;!!;dHSp0q1        
+dQ_0t       DN D22.U8   ;!!;Temp1        
+
+dP_0n       DN D29.U8
+dP_1n       DN D30.U8
+dP_2n       DN D31.U8
+
+dQ_0n       DN D24.U8   ;!!;Temp2        
+dQ_1n       DN D25.U8   ;!!;Temp2        
+dQ_2n       DN D28.U8   ;!!;dQ_0t        
+
+        
+        ;// Function header
+        M_START omxVCM4P10_FilterDeblockingLuma_VerEdge_I, r11, d15
+        
+        ;//Arguments on the stack
+        M_ARG   ppThresholds, 4
+        M_ARG   ppBS, 4
+        
+        ;// d0-dAlpha_0
+        ;// d2-dBeta_0
+
+        ADD         pAlpha_1, pAlpha_0, #1
+        ADD         pBeta_1, pBeta_0, #1
+        
+        VLD1        {dAlpha[]}, [pAlpha_0]
+        SUB         pSrcDst, pSrcDst, #4
+        VLD1        {dBeta[]}, [pBeta_0] 
+        
+        M_LDR       pBS, ppBS
+        M_LDR       pThresholds, ppThresholds 
+
+        MOV         Mask_0,#0
+
+        ;dMask_0-14
+        ;dMask_1-15
+
+        VMOV        dMask_0, #0     
+        VMOV        dMask_1, #1     
+
+        LDR         XY,=LOOP_COUNT
+    
+        ADD         pTmpStep, srcdstStep, srcdstStep
+
+        ;// p0-p3 - d4-d7
+        ;// q0-q3 - d8-d11
+LoopY        
+LoopX        
+        LDRH        bS10, [pBS], #4
+
+        CMP         bS10, #0
+        BEQ         NoFilterBS0
+
+        ;// Load 8 rows of data
+        ADD         pTmp, pSrcDst, srcdstStep
+        VLD1        dRow0, [pSrcDst], pTmpStep
+        VLD1        dRow1, [pTmp], pTmpStep
+        VLD1        dRow2, [pSrcDst], pTmpStep
+        VZIP.8      dRow0, dRow1
+        VLD1        dRow3, [pTmp], pTmpStep
+        VLD1        dRow4, [pSrcDst], pTmpStep
+        VZIP.8      dRow2, dRow3
+        VLD1        dRow5, [pTmp], pTmpStep
+        VLD1        dRow6, [pSrcDst], pTmpStep
+        VLD1        dRow7, [pTmp], pTmpStep
+        VZIP.8      dRow4, dRow5
+        VZIP.16     dRow1, dRow3
+    
+
+        ;// dRow0 = [q3r0 q2r0 q1r0 q0r0 p0r0 p1r0 p2r0 p3r0]
+        ;// dRow1 = [q3r1 q2r1 q1r1 q0r1 p0r1 p1r1 p2r1 p3r1]
+        ;// dRow2 = [q3r2 q2r2 q1r2 q0r2 p0r2 p1r2 p2r2 p3r2]
+        ;// dRow3 = [q3r3 q2r3 q1r3 q0r3 p0r3 p1r3 p2r3 p3r3]
+        ;// dRow4 = [q3r4 q2r4 q1r4 q0r4 p0r4 p1r4 p2r4 p3r4]
+        ;// dRow5 = [q3r5 q2r5 q1r5 q0r5 p0r5 p1r5 p2r5 p3r5]
+        ;// dRow6 = [q3r6 q2r6 q1r6 q0r6 p0r6 p1r6 p2r6 p3r6]
+        ;// dRow7 = [q3r7 q2r7 q1r7 q0r7 p0r7 p1r7 p2r7 p3r7]
+
+        ;// 8x8 Transpose
+
+        VZIP.8      dRow6, dRow7
+
+        SUB         pSrcDst, pSrcDst, srcdstStep, LSL #3
+        VZIP.16     dRow0, dRow2
+        VZIP.16     dRow5, dRow7
+        
+
+        VZIP.16     dRow4, dRow6
+        VZIP.32     dRow1, dRow5
+        VZIP.32     dRow2, dRow6
+        VZIP.32     dRow3, dRow7
+        VZIP.32     dRow0, dRow4
+        
+
+        ;// dRow0 - dP_3, dRow1 - dQ_0, dRow2 - dP_1, dRow3 - dQ_2
+        ;// dRow4 - dP_2, dRow5 - dQ_1, dRow6 - dP_0, dRow7 - dQ_3
+
+        ;// dQ_0 = [q0r7 q0r6 q0r5 q0r4 q0r3 q0r2 q0r1 q0r0]
+        ;// dQ_1 = [q1r7 q1r6 q1r5 q1r4 q1r3 q1r2 q1r1 q1r0]
+        ;// dQ_2 = [q2r7 q2r6 q2r5 q2r4 q2r3 q2r2 q2r1 q2r0]
+        ;// dQ_3 = [q3r7 q3r6 q3r5 q3r4 q3r3 q3r2 q3r1 q3r0]
+
+        ;// dP_0 = [p0r7 p0r6 p0r5 p0r4 p0r3 p0r2 p0r1 p0r0]
+        ;// dP_1 = [p1r7 p1r6 p1r5 p1r4 p1r3 p1r2 p1r1 p1r0]
+        ;// dP_2 = [p2r7 p2r6 p2r5 p2r4 p2r3 p2r2 p2r1 p2r0]
+        ;// dP_3 = [p3r7 p3r6 p3r5 p3r4 p3r3 p3r2 p3r1 p3r0]
+
+        VABD        dAp0q0, dP_0, dQ_0
+        VABD        dAp1p0, dP_1, dP_0
+
+        VABD        dAq1q0, dQ_1, dQ_0
+        VABD        dAp2p0, dP_2, dP_0
+        
+        TST         bS10, #0xff
+        VCGT        dFilt, dAlpha, dAp0q0
+
+        VMAX        dAp1p0, dAq1q0, dAp1p0
+        VABD        dAq2q0, dQ_2, dQ_0
+
+        VMOVEQ.U32  dFilt[0], Mask_0
+        TST         bS10, #0xff00
+
+        VCGT        dAp2p0, dBeta, dAp2p0
+        VCGT        dAp1p0, dBeta, dAp1p0
+
+        VMOVEQ.U32  dFilt[1], Mask_0
+
+        VCGT        dAq2q0, dBeta, dAq2q0
+        VAND        dFilt, dFilt, dAp1p0
+        TST         bS10, #4 
+
+        VAND        dAqflg, dFilt, dAq2q0
+        VAND        dApflg, dFilt, dAp2p0
+    
+        BNE         bSGE4        
+bSLT4
+        ;// bS < 4 Filtering
+
+        BL          armVCM4P10_DeblockingLumabSLT4_unsafe
+
+        ;// Transpose
+
+        VZIP.8      dP_3,  dP_2  
+        VZIP.8      dP_1n, dP_0n
+        VZIP.8      dQ_0n, dQ_1n
+        VZIP.8      dQ_2,  dQ_3
+
+        
+        VZIP.16     dP_3,  dP_1n
+        ADD         pTmp, pSrcDst, srcdstStep
+        VZIP.16     dQ_0n, dQ_2
+        VZIP.16     dQ_1n, dQ_3
+        VZIP.16     dP_2,  dP_0n
+
+        VZIP.32     dP_3,  dQ_0n
+        VZIP.32     dP_1n, dQ_2
+        VZIP.32     dP_2,  dQ_1n
+        VZIP.32     dP_0n, dQ_3
+
+        ;// dRown0 - dP_3,  dRown1 - dQ_0n
+        ;// dRown2 - dP_1n, dRown3 - dQ_2
+        ;// dRown4 - dP_2,  dRown5 - dQ_1n
+        ;// dRown6 - dP_0n, dRown7 - dQ_3
+
+        VST1        dRown0, [pSrcDst], pTmpStep
+        VST1        dRown1, [pTmp], pTmpStep
+        VST1        dRown2, [pSrcDst], pTmpStep
+        VST1        dRown3, [pTmp], pTmpStep
+        ;1
+        VST1        dRown4, [pSrcDst], pTmpStep
+        VST1        dRown5, [pTmp], pTmpStep
+        ADDS        XY, XY, XY
+        VST1        dRown6, [pSrcDst], pTmpStep
+        ADD         pThresholds, pThresholds, #2
+        VST1        dRown7, [pTmp], srcdstStep
+
+        SUB         pSrcDst, pSrcDst, srcdstStep, LSL #3
+        VLD1        {dAlpha[]}, [pAlpha_1]
+        ADD         pSrcDst, pSrcDst, #4
+        VLD1        {dBeta[]}, [pBeta_1]
+
+        BCC         LoopX
+        B           ExitLoopY        
+
+NoFilterBS0
+        ADD         pSrcDst, pSrcDst, #4
+        ADDS        XY, XY, XY
+        VLD1        {dAlpha[]}, [pAlpha_1]
+        ADD         pThresholds, pThresholds, #4
+        VLD1        {dBeta[]}, [pBeta_1]
+        BCC         LoopX
+        B           ExitLoopY        
+bSGE4        
+        ;// bS >= 4 Filtering
+        
+        BL          armVCM4P10_DeblockingLumabSGE4_unsafe
+
+        ;// Transpose
+
+        VZIP.8      dP_3,  dP_2n   
+        VZIP.8      dP_1n, dP_0n
+        VZIP.8      dQ_0n, dQ_1n
+        VZIP.8      dQ_2n, dQ_3
+
+        VZIP.16     dP_3,  dP_1n
+        ADD         pTmp, pSrcDst, srcdstStep
+        VZIP.16     dQ_0n, dQ_2n
+        VZIP.16     dQ_1n, dQ_3
+        VZIP.16     dP_2n, dP_0n
+
+        VZIP.32     dP_3,  dQ_0n
+        VZIP.32     dP_1n, dQ_2n
+        VZIP.32     dP_2n, dQ_1n
+        VZIP.32     dP_0n, dQ_3
+
+        ;// dRow0n - dP_3, dRow1n - dQ_0n, dRow2n - dP_1n, dRow3n - dQ_2n
+        ;// dRow4n - dP_2, dRow5n - dQ_1n, dRow6n - dP_0n, dRow7n - dQ_3
+        
+        VST1        dRow0n, [pSrcDst], pTmpStep
+        VST1        dRow1n, [pTmp], pTmpStep
+        VST1        dRow2n, [pSrcDst], pTmpStep
+        VST1        dRow3n, [pTmp], pTmpStep
+        VST1        dRow4n, [pSrcDst], pTmpStep
+        VST1        dRow5n, [pTmp], pTmpStep
+        ADDS        XY,XY,XY
+        VST1        dRow6n, [pSrcDst], pTmpStep
+        ADD         pThresholds, pThresholds, #4
+        VST1        dRow7n, [pTmp], pTmpStep
+
+        SUB         pSrcDst, pSrcDst, srcdstStep, LSL #3
+        VLD1        {dAlpha[]}, [pAlpha_1]
+        ADD         pSrcDst, pSrcDst, #4
+        VLD1        {dBeta[]}, [pBeta_1]
+
+        BCC         LoopX
+
+ExitLoopY        
+        SUB         pBS, pBS, #14
+        SUB         pThresholds, pThresholds, #14
+        SUB         pSrcDst, pSrcDst, #16
+        VLD1        {dAlpha[]}, [pAlpha_0]
+        ADD         pSrcDst, pSrcDst, srcdstStep, LSL #3 
+        VLD1        {dBeta[]}, [pBeta_0]
+        BNE         LoopY
+
+        MOV         r0, #OMX_Sts_NoErr
+
+        M_END
+        
+    ENDIF
+    
+        
+        END
+        
+        
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_InterpolateChroma.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_InterpolateChroma.c
new file mode 100755
index 0000000..3ce41be
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_InterpolateChroma.c
@@ -0,0 +1,79 @@
+/**
+ * 
+ * File Name:  omxVCM4P10_InterpolateChroma.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   12290
+ * Date:       Wednesday, April 9, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * Description:
+ * This function will calculate 1/8 Pixel interpolation for Chroma Block
+ * 
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armVC.h"
+#include "armCOMM.h"
+
+
+/**
+ * Function: omxVCM4P10_InterpolateChroma,
+ *
+ * Description:
+ * Performs 1/8-pixel interpolation for inter chroma MB.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	pSrc	Pointer to the source reference frame buffer
+ * [in]	srcStep Reference frame step in byte
+ * [in]	dstStep Destination frame step in byte. Must be multiple of roi.width.
+ * [in]	dx		Fractional part of horizontal motion vector component
+ *						in 1/8 pixel unit;valid in the range [0,7]
+ * [in]	dy		Fractional part of vertical motion vector component
+ *						in 1/8 pixel unit;valid in the range [0,7]
+ * [in]	roi		Dimension of the interpolation region;the parameters roi.width and roi.height must
+ *                      be equal to either 2, 4, or 8.
+ * [out]	pDst	Pointer to the destination frame buffer.
+ *                   if roi.width==2,  2-byte alignment required
+ *                   if roi.width==4,  4-byte alignment required
+ *                   if roi.width==8,  8-byte alignment required
+ *
+ * Return Value:
+ * If the function runs without error, it returns OMX_Sts_NoErr.
+ * If one of the following cases occurs, the function returns OMX_Sts_BadArgErr:
+ *	pSrc or pDst is NULL.
+ *	srcStep or dstStep < 8.
+ *	dx or dy is out of range [0-7].
+ *	roi.width or roi.height is out of range {2,4,8}.
+ *	roi.width is equal to 2, but pDst is not 2-byte aligned.
+ *	roi.width is equal to 4, but pDst is not 4-byte aligned.
+ *	roi.width is equal to 8, but pDst is not 8 byte aligned.
+ *	srcStep or dstStep is not a multiple of 8.
+ *
+ */
+
+OMXResult omxVCM4P10_InterpolateChroma (
+     const OMX_U8* pSrc,
+     OMX_S32 srcStep,
+     OMX_U8* pDst,
+     OMX_S32 dstStep,
+     OMX_S32 dx,
+     OMX_S32 dy,
+     OMXSize roi
+ )
+{
+    return armVCM4P10_Interpolate_Chroma 
+        ((OMX_U8*)pSrc, srcStep, pDst, dstStep, roi.width, roi.height, dx, dy);
+}
+
+
+/*****************************************************************************
+ *                              END OF FILE
+ *****************************************************************************/
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_InterpolateLuma_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_InterpolateLuma_s.s
new file mode 100755
index 0000000..942ebc6
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_InterpolateLuma_s.s
@@ -0,0 +1,553 @@
+;//
+;// 
+;// File Name:  omxVCM4P10_InterpolateLuma_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   12290
+;// Date:       Wednesday, April 9, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+;// Function:
+;//     omxVCM4P10_InterpolateLuma
+;//
+;// This function implements omxVCM4P10_InterpolateLuma in v6 assembly.
+;// Performs quarter pel interpolation of inter luma MB.
+;// It's assumed that the frame is already padded when calling this function.
+;// Parameters:
+;// [in]    pSrc        Pointer to the source reference frame buffer
+;// [in]    srcStep     Reference frame step in byte
+;// [in]    dstStep     Destination frame step in byte. Must be multiple of roi.width
+;// [in]    dx          Fractional part of horizontal motion vector
+;//                         component in 1/4 pixel unit; valid in the range [0,3]
+;// [in]    dy          Fractional part of vertical motion vector
+;//                         component in 1/4 pixel unit; valid in the range [0,3]
+;// [in]    roi         Dimension of the interpolation region;the parameters roi.width and roi.height must
+;//                         be equal to either 4, 8, or 16.
+;// [out]   pDst        Pointer to the destination frame buffer.
+;//                   if roi.width==4,  4-byte alignment required
+;//                   if roi.width==8,  8-byte alignment required
+;//                   if roi.width==16, 16-byte alignment required
+;//
+;// Return Value:
+;// If the function runs without error, it returns OMX_Sts_NoErr.
+;// It is assued that following cases are satisfied before calling this function:
+;//  pSrc or pDst is not NULL.
+;//  srcStep or dstStep >= roi.width.
+;//     dx or dy is in the range [0-3].
+;//     roi.width or roi.height is not out of range {4, 8, 16}.
+;//     If roi.width is equal to 4, Dst is 4 byte aligned.
+;//     If roi.width is equal to 8, pDst is 8 byte aligned.
+;//     If roi.width is equal to 16, pDst is 16 byte aligned.
+;//     srcStep and dstStep is multiple of 8.
+;//
+;//
+
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+
+        M_VARIANTS CortexA8
+
+        EXPORT omxVCM4P10_InterpolateLuma
+        
+
+    IF CortexA8
+        IMPORT armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe
+        IMPORT armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe
+        IMPORT armVCM4P10_InterpolateLuma_HalfDiagVerHor4x4_unsafe
+        IMPORT armVCM4P10_InterpolateLuma_HalfDiagHorVer4x4_unsafe
+    ENDIF
+    
+    
+
+;// Declare input registers
+pSrc            RN 0
+srcStep         RN 1
+pDst            RN 2
+dstStep         RN 3
+iHeight         RN 4
+iWidth          RN 5
+
+;// Declare other intermediate registers
+idx             RN 6
+idy             RN 7
+index           RN 6
+Temp            RN 12
+pArgs           RN 11
+
+
+    IF CortexA8
+
+        ;//
+        ;// Interpolation of luma is implemented by processing block of pixels, size 4x4 at a time.
+        ;//
+        M_ALLOC4    ppArgs, 16
+        
+        ;// Function header
+        M_START omxVCM4P10_InterpolateLuma, r11, d15
+
+pSrcBK          RN 8
+
+;// Declare Neon registers
+dCoeff5         DN 30.S16
+dCoeff20        DN 31.S16
+
+;// Registers used for implementing Horizontal interpolation
+dSrc0c          DN 14.U8
+dSrc1c          DN 16.U8
+dSrc2c          DN 18.U8
+dSrc3c          DN 20.U8                   
+dSrc0d          DN 15.U8
+dSrc1d          DN 17.U8
+dSrc2d          DN 19.U8
+dSrc3d          DN 21.U8
+dAccH0          DN 22.U8
+dAccH1          DN 24.U8
+dAccH2          DN 26.U8
+dAccH3          DN 28.U8
+dResultH0       DN 22.U32
+dResultH1       DN 24.U32
+dResultH2       DN 26.U32
+dResultH3       DN 28.U32
+
+;// Registers used for implementing Vertical interpolation
+dSrc0           DN 9.U8
+dSrc1           DN 10.U8
+dSrc2           DN 11.U8
+dSrc3           DN 12.U8
+dSrc4           DN 13.U8
+dAccV0          DN 0.U8
+dAccV1          DN 2.U8
+dAccV2          DN 4.U8
+dAccV3          DN 6.U8
+dResultV0       DN 0.U32
+dResultV1       DN 2.U32
+dResultV2       DN 4.U32
+dResultV3       DN 6.U32
+        
+;// Registers used for implementing Diagonal interpolation
+dTAcc0          DN 0.U8
+dTAcc1          DN 2.U8
+dTAcc2          DN 4.U8
+dTAcc3          DN 6.U8
+dTRes0          DN 0.32
+dTRes1          DN 2.32
+dTRes2          DN 4.32
+dTRes3          DN 6.32
+dTResult0       DN 14.U8
+dTResult1       DN 16.U8
+dTResult2       DN 18.U8
+dTResult3       DN 20.U8
+dTempP0         DN 18.S16
+dTempP1         DN 19.S16
+dTempQ0         DN 20.S16
+dTempQ1         DN 21.S16
+dTempR0         DN 22.S16
+dTempR1         DN 23.S16
+dTempS0         DN 24.S16
+dTempS1         DN 25.S16
+qTempP01        QN 9.S16
+qTempQ01        QN 10.S16
+qTempR01        QN 11.S16
+qTempS01        QN 12.S16
+
+;// Intermediate values for averaging
+qRes2           QN 7.S16
+qRes3           QN 8.S16
+qRes4           QN 9.S16
+qRes5           QN 10.S16
+qRes6           QN 11.S16
+       
+;// For implementing copy
+dDst0            DN 9.32
+dDst1            DN 10.32
+dDst2            DN 11.32
+dDst3            DN 12.32
+
+        ;// Define stack arguments
+        M_ARG       ptridx, 4
+        M_ARG       ptridy, 4        
+        M_ARG       ptrWidth, 4
+        M_ARG       ptrHeight, 4        
+
+        ;// Load structure elements of roi 
+        M_LDR       idx, ptridx
+        M_LDR       idy, ptridy
+        M_LDR       iWidth, ptrWidth
+        M_LDR       iHeight, ptrHeight
+        
+        ADD         index, idx, idy, LSL #2                 ;//  [index] = [idy][idx]
+        M_ADR       pArgs, ppArgs
+                    
+        ;// Move coefficients Neon registers
+        VMOV        dCoeff20, #20
+        VMOV        dCoeff5, #5
+                                        
+Block4x4WidthLoop
+Block4x4HeightLoop
+
+        STM         pArgs, {pSrc,srcStep,pDst,dstStep} 
+                                                            
+        ;// switch table using motion vector as index
+        ADD         pc, pc, index, LSL #2
+        B           Case_f
+        B           Case_0        
+        B           Case_1        
+        B           Case_2        
+        B           Case_3        
+        B           Case_4        
+        B           Case_5        
+        B           Case_6        
+        B           Case_7        
+        B           Case_8        
+        B           Case_9        
+        B           Case_a        
+        B           Case_b        
+        B           Case_c        
+        B           Case_d
+        B           Case_e        
+        B           Case_f
+                    
+Case_0                
+        ;// Case G
+        M_PRINTF "Case 0 \n"
+        
+        ;// Loads a 4x4 block of .8 and stores as .32
+        ADD         Temp, pSrc, srcStep, LSL #1 
+        VLD1        dSrc0, [pSrc], srcStep
+        VLD1        dSrc2, [Temp], srcStep
+        VLD1        dSrc1, [pSrc]
+        VLD1        dSrc3, [Temp]
+        
+        ADD         Temp, pDst, dstStep, LSL #1 
+        VST1        dDst0[0], [pDst], dstStep
+        VST1        dDst2[0], [Temp], dstStep
+        VST1        dDst1[0], [pDst]
+        VST1        dDst3[0], [Temp]
+        M_ADR       pArgs, ppArgs
+        B           Block4x4LoopEnd
+Case_1
+        ;// Case a
+        M_PRINTF "Case 1 \n"
+
+        SUB         pSrc, pSrc, #2
+        BL          armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe        
+        VRHADD      dAccH0, dAccH0, dSrc0c
+        VRHADD      dAccH2, dAccH2, dSrc2c
+        VRHADD      dAccH1, dAccH1, dSrc1c
+        VRHADD      dAccH3, dAccH3, dSrc3c
+        ADD         Temp, pDst, dstStep, LSL #1 
+        VST1        dResultH0[0], [pDst], dstStep
+        VST1        dResultH2[0], [Temp], dstStep
+        VST1        dResultH1[0], [pDst]
+        VST1        dResultH3[0], [Temp]
+        M_ADR       pArgs, ppArgs
+        B           Block4x4LoopEnd        
+Case_2
+        ;// Case b
+        M_PRINTF "Case 2 \n"
+
+        SUB         pSrc, pSrc, #2        
+        BL          armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe
+        ADD         Temp, pDst, dstStep, LSL #1 
+        VST1        dResultH0[0], [pDst], dstStep
+        VST1        dResultH2[0], [Temp], dstStep
+        VST1        dResultH1[0], [pDst]
+        VST1        dResultH3[0], [Temp]
+        M_ADR       pArgs, ppArgs
+        B           Block4x4LoopEnd        
+Case_3
+        ;// Case c
+        M_PRINTF "Case 3 \n"
+
+        SUB         pSrc, pSrc, #2
+        BL          armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe        
+        VRHADD      dAccH0, dAccH0, dSrc0d
+        VRHADD      dAccH2, dAccH2, dSrc2d
+        VRHADD      dAccH1, dAccH1, dSrc1d
+        VRHADD      dAccH3, dAccH3, dSrc3d
+        ADD         Temp, pDst, dstStep, LSL #1 
+        VST1        dResultH0[0], [pDst], dstStep
+        VST1        dResultH2[0], [Temp], dstStep
+        VST1        dResultH1[0], [pDst]
+        VST1        dResultH3[0], [Temp]
+        M_ADR       pArgs, ppArgs
+        B           Block4x4LoopEnd        
+Case_4
+        ;// Case d
+        M_PRINTF "Case 4 \n"
+
+        SUB         pSrc, pSrc, srcStep, LSL #1
+        BL          armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe        
+        VRHADD      dAccV0, dAccV0, dSrc0
+        VRHADD      dAccV2, dAccV2, dSrc2
+        VRHADD      dAccV1, dAccV1, dSrc1
+        VRHADD      dAccV3, dAccV3, dSrc3
+        ADD         Temp, pDst, dstStep, LSL #1 
+        VST1        dResultV0[0], [pDst], dstStep
+        VST1        dResultV2[0], [Temp], dstStep
+        VST1        dResultV1[0], [pDst]
+        VST1        dResultV3[0], [Temp]
+        M_ADR       pArgs, ppArgs
+        B           Block4x4LoopEnd        
+Case_5
+        ;// Case e
+        M_PRINTF "Case 5 \n"
+        
+        MOV         pSrcBK, pSrc
+        SUB         pSrc, pSrc, srcStep, LSL #1
+        BL          armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe        
+        SUB         pSrc, pSrcBK, #2
+        BL          armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe        
+        VRHADD      dAccH0, dAccH0, dAccV0
+        VRHADD      dAccH2, dAccH2, dAccV2
+        VRHADD      dAccH1, dAccH1, dAccV1
+        VRHADD      dAccH3, dAccH3, dAccV3        
+        ADD         Temp, pDst, dstStep, LSL #1 
+        VST1        dResultH0[0], [pDst], dstStep
+        VST1        dResultH2[0], [Temp], dstStep
+        VST1        dResultH1[0], [pDst]
+        VST1        dResultH3[0], [Temp]
+        
+        M_ADR       pArgs, ppArgs
+        B       Block4x4LoopEnd        
+Case_6
+        ;// Case f
+        M_PRINTF "Case 6 \n"
+
+        SUB         pSrc, pSrc, srcStep, LSL #1
+        SUB         pSrc, pSrc, #2
+        BL          armVCM4P10_InterpolateLuma_HalfDiagHorVer4x4_unsafe
+        VQRSHRUN    dTResult0, qRes2, #5        
+        VQRSHRUN    dTResult1, qRes3, #5        
+        VQRSHRUN    dTResult2, qRes4, #5        
+        VQRSHRUN    dTResult3, qRes5, #5        
+        VRHADD      dTAcc0, dTAcc0, dTResult0
+        VRHADD      dTAcc2, dTAcc2, dTResult2
+        VRHADD      dTAcc1, dTAcc1, dTResult1
+        VRHADD      dTAcc3, dTAcc3, dTResult3
+        ADD         Temp, pDst, dstStep, LSL #1 
+        VST1        dTRes0[0], [pDst], dstStep
+        VST1        dTRes2[0], [Temp], dstStep
+        VST1        dTRes1[0], [pDst]
+        VST1        dTRes3[0], [Temp]
+        
+        M_ADR       pArgs, ppArgs
+        B       Block4x4LoopEnd        
+Case_7
+        ;// Case g
+        M_PRINTF "Case 7 \n"
+        MOV         pSrcBK, pSrc
+        ADD         pSrc, pSrc, #1
+        SUB         pSrc, pSrc, srcStep, LSL #1
+        BL          armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe        
+        SUB         pSrc, pSrcBK, #2
+        BL          armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe        
+        VRHADD      dAccH0, dAccH0, dAccV0
+        VRHADD      dAccH2, dAccH2, dAccV2
+        VRHADD      dAccH1, dAccH1, dAccV1
+        VRHADD      dAccH3, dAccH3, dAccV3        
+        ADD         Temp, pDst, dstStep, LSL #1 
+        VST1        dResultH0[0], [pDst], dstStep
+        VST1        dResultH2[0], [Temp], dstStep
+        VST1        dResultH1[0], [pDst]
+        VST1        dResultH3[0], [Temp]
+        
+        M_ADR       pArgs, ppArgs
+        B       Block4x4LoopEnd
+Case_8
+        ;// Case h
+        M_PRINTF "Case 8 \n"
+
+        SUB         pSrc, pSrc, srcStep, LSL #1
+        BL          armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe        
+        ADD         Temp, pDst, dstStep, LSL #1 
+        VST1        dResultV0[0], [pDst], dstStep
+        VST1        dResultV2[0], [Temp], dstStep
+        VST1        dResultV1[0], [pDst]
+        VST1        dResultV3[0], [Temp]
+        M_ADR       pArgs, ppArgs
+        B           Block4x4LoopEnd
+Case_9
+        ;// Case i
+        M_PRINTF "Case 9 \n"
+        SUB         pSrc, pSrc, srcStep, LSL #1
+        SUB         pSrc, pSrc, #2
+        BL          armVCM4P10_InterpolateLuma_HalfDiagVerHor4x4_unsafe
+        VEXT        dTempP0, dTempP0, dTempP1, #2
+        VEXT        dTempQ0, dTempQ0, dTempQ1, #2
+        VEXT        dTempR0, dTempR0, dTempR1, #2
+        VEXT        dTempS0, dTempS0, dTempS1, #2
+        
+        VQRSHRUN    dTResult0, qTempP01, #5        
+        VQRSHRUN    dTResult1, qTempQ01, #5        
+        VQRSHRUN    dTResult2, qTempR01, #5        
+        VQRSHRUN    dTResult3, qTempS01, #5        
+
+        VRHADD      dTAcc0, dTAcc0, dTResult0
+        VRHADD      dTAcc2, dTAcc2, dTResult2
+        VRHADD      dTAcc1, dTAcc1, dTResult1
+        VRHADD      dTAcc3, dTAcc3, dTResult3
+        ADD         Temp, pDst, dstStep, LSL #1 
+        VST1        dTRes0[0], [pDst], dstStep
+        VST1        dTRes2[0], [Temp], dstStep
+        VST1        dTRes1[0], [pDst]
+        VST1        dTRes3[0], [Temp]
+        M_ADR       pArgs, ppArgs
+        B       Block4x4LoopEnd
+Case_a
+        ;// Case j
+        M_PRINTF "Case a \n"
+
+        SUB         pSrc, pSrc, srcStep, LSL #1
+        SUB         pSrc, pSrc, #2
+        BL          armVCM4P10_InterpolateLuma_HalfDiagHorVer4x4_unsafe
+        ADD         Temp, pDst, dstStep, LSL #1 
+        VST1        dTRes0[0], [pDst], dstStep
+        VST1        dTRes2[0], [Temp], dstStep
+        VST1        dTRes1[0], [pDst]
+        VST1        dTRes3[0], [Temp]
+        M_ADR       pArgs, ppArgs
+        B       Block4x4LoopEnd
+Case_b
+        ;// Case k
+        M_PRINTF "Case b \n"
+        SUB         pSrc, pSrc, srcStep, LSL #1
+        SUB         pSrc, pSrc, #2
+        BL          armVCM4P10_InterpolateLuma_HalfDiagVerHor4x4_unsafe
+        VEXT        dTempP0, dTempP0, dTempP1, #3
+        VEXT        dTempQ0, dTempQ0, dTempQ1, #3
+        VEXT        dTempR0, dTempR0, dTempR1, #3
+        VEXT        dTempS0, dTempS0, dTempS1, #3
+        
+        VQRSHRUN    dTResult0, qTempP01, #5        
+        VQRSHRUN    dTResult1, qTempQ01, #5        
+        VQRSHRUN    dTResult2, qTempR01, #5        
+        VQRSHRUN    dTResult3, qTempS01, #5        
+
+        VRHADD      dTAcc0, dTAcc0, dTResult0
+        VRHADD      dTAcc2, dTAcc2, dTResult2
+        VRHADD      dTAcc1, dTAcc1, dTResult1
+        VRHADD      dTAcc3, dTAcc3, dTResult3
+        ADD         Temp, pDst, dstStep, LSL #1 
+        VST1        dTRes0[0], [pDst], dstStep
+        VST1        dTRes2[0], [Temp], dstStep
+        VST1        dTRes1[0], [pDst]
+        VST1        dTRes3[0], [Temp]
+        M_ADR       pArgs, ppArgs
+        B       Block4x4LoopEnd
+Case_c
+        ;// Case n
+        M_PRINTF "Case c \n"
+
+        SUB         pSrc, pSrc, srcStep, LSL #1
+        BL          armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe        
+        VRHADD      dAccV0, dAccV0, dSrc1
+        VRHADD      dAccV2, dAccV2, dSrc3
+        VRHADD      dAccV1, dAccV1, dSrc2
+        VRHADD      dAccV3, dAccV3, dSrc4
+        ADD         Temp, pDst, dstStep, LSL #1 
+        VST1        dResultV0[0], [pDst], dstStep
+        VST1        dResultV2[0], [Temp], dstStep
+        VST1        dResultV1[0], [pDst]
+        VST1        dResultV3[0], [Temp]
+        M_ADR       pArgs, ppArgs
+        B           Block4x4LoopEnd
+Case_d
+        ;// Case p
+        M_PRINTF "Case d \n"
+        
+        MOV         pSrcBK, pSrc
+        SUB         pSrc, pSrc, srcStep, LSL #1
+        BL          armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe        
+        ADD         pSrc, pSrcBK, srcStep
+        SUB         pSrc, pSrc, #2
+        BL          armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe        
+        VRHADD      dAccH0, dAccH0, dAccV0
+        VRHADD      dAccH2, dAccH2, dAccV2
+        VRHADD      dAccH1, dAccH1, dAccV1
+        VRHADD      dAccH3, dAccH3, dAccV3        
+        ADD         Temp, pDst, dstStep, LSL #1 
+        VST1        dResultH0[0], [pDst], dstStep
+        VST1        dResultH2[0], [Temp], dstStep
+        VST1        dResultH1[0], [pDst]
+        VST1        dResultH3[0], [Temp]
+        M_ADR       pArgs, ppArgs
+        B       Block4x4LoopEnd
+Case_e
+        ;// Case q
+        M_PRINTF "Case e \n"
+        
+        SUB         pSrc, pSrc, srcStep, LSL #1
+        SUB         pSrc, pSrc, #2
+        BL          armVCM4P10_InterpolateLuma_HalfDiagHorVer4x4_unsafe
+        VQRSHRUN    dTResult0, qRes3, #5        
+        VQRSHRUN    dTResult1, qRes4, #5        
+        VQRSHRUN    dTResult2, qRes5, #5        
+        VQRSHRUN    dTResult3, qRes6, #5        
+
+        VRHADD      dTAcc0, dTAcc0, dTResult0
+        VRHADD      dTAcc2, dTAcc2, dTResult2
+        VRHADD      dTAcc1, dTAcc1, dTResult1
+        VRHADD      dTAcc3, dTAcc3, dTResult3
+        ADD         Temp, pDst, dstStep, LSL #1 
+        VST1        dTRes0[0], [pDst], dstStep
+        VST1        dTRes2[0], [Temp], dstStep
+        VST1        dTRes1[0], [pDst]
+        VST1        dTRes3[0], [Temp]
+        M_ADR       pArgs, ppArgs
+        B       Block4x4LoopEnd
+Case_f
+        ;// Case r
+        M_PRINTF "Case f \n"
+        MOV         pSrcBK, pSrc
+        ADD         pSrc, pSrc, #1
+        SUB         pSrc, pSrc, srcStep, LSL #1
+        BL          armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe        
+        ADD         pSrc, pSrcBK, srcStep
+        SUB         pSrc, pSrc, #2
+        BL          armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe        
+        VRHADD      dAccH0, dAccH0, dAccV0
+        VRHADD      dAccH2, dAccH2, dAccV2
+        VRHADD      dAccH1, dAccH1, dAccV1
+        VRHADD      dAccH3, dAccH3, dAccV3        
+        ADD         Temp, pDst, dstStep, LSL #1 
+        VST1        dResultH0[0], [pDst], dstStep
+        VST1        dResultH2[0], [Temp], dstStep
+        VST1        dResultH1[0], [pDst]
+        VST1        dResultH3[0], [Temp]
+        M_ADR       pArgs, ppArgs
+
+
+Block4x4LoopEnd
+
+        ;// Width Loop
+        ;//M_ADR       pArgs, ppArgs
+        LDM         pArgs, {pSrc,srcStep,pDst,dstStep}  ;// Load arguments
+        SUBS        iWidth, iWidth, #4
+        ADD         pSrc, pSrc, #4      
+        ADD         pDst, pDst, #4
+        BGT         Block4x4WidthLoop
+                    
+        ;// Height Loop
+        SUBS        iHeight, iHeight, #4
+        M_LDR       iWidth, ptrWidth
+        M_ADR       pArgs, ppArgs
+        ADD         pSrc, pSrc, srcStep, LSL #2      
+        ADD         pDst, pDst, dstStep, LSL #2
+        SUB         pSrc, pSrc, iWidth
+        SUB         pDst, pDst, iWidth
+        BGT         Block4x4HeightLoop
+
+EndOfInterpolation
+        MOV         r0, #0
+        M_END       
+
+    ENDIF  
+        ;// End of CortexA8
+                    
+    END
+    
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_PredictIntraChroma_8x8_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_PredictIntraChroma_8x8_s.s
new file mode 100755
index 0000000..3a60705
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_PredictIntraChroma_8x8_s.s
@@ -0,0 +1,436 @@
+;//
+;// 
+;// File Name:  omxVCM4P10_PredictIntraChroma_8x8_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   12290
+;// Date:       Wednesday, April 9, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+  
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+        
+        EXPORT armVCM4P10_pIndexTable8x8
+        
+;// Define the processor variants supported by this file
+         
+         M_VARIANTS CortexA8
+     
+     AREA table, DATA    
+;//-------------------------------------------------------
+;// This table for implementing switch case of C in asm by
+;// the mehtod of two levels of indexing.
+;//-------------------------------------------------------
+
+    M_TABLE armVCM4P10_pIndexTable8x8
+    DCD  OMX_VC_CHROMA_DC,     OMX_VC_CHROMA_HOR 
+    DCD  OMX_VC_CHROMA_VERT,   OMX_VC_CHROMA_PLANE  
+    
+    M_TABLE armVCM4P10_MultiplierTableChroma8x8,1
+    DCW   3, 2, 1,4 
+    DCW  -3,-2,-1,0
+    DCW   1, 2, 3,4
+    
+        
+        
+    IF CortexA8
+
+;//--------------------------------------------
+;// Scratch variable
+;//--------------------------------------------
+ 
+pc              RN 15   
+return          RN 0  
+pTable          RN 8 
+  
+;//--------------------------------------------
+;// Input Arguments
+;//--------------------------------------------
+pSrcLeft        RN 0    ;// input pointer
+pSrcAbove       RN 1    ;// input pointer
+pSrcAboveLeft   RN 2    ;// input pointer
+pDst            RN 3    ;// output pointer
+leftStep        RN 4    ;// input variable
+dstStep         RN 5    ;// input variable
+predMode        RN 6    ;// input variable
+availability    RN 7    ;// input variable
+pMultiplierTable    RN  2     
+
+pTmp            RN 9
+step            RN 10
+
+;//---------------------
+;// Neon Registers
+;//---------------------
+
+;// OMX_VC_CHROMA_HOR
+
+dLeftVal0       DN  D0.8
+dLeftVal1       DN  D1.8
+dLeftVal2       DN  D2.8
+dLeftVal3       DN  D3.8
+dLeftVal4       DN  D4.8
+dLeftVal5       DN  D5.8
+dLeftVal6       DN  D6.8
+dLeftVal7       DN  D7.8
+
+;// OMX_VC_CHROMA_VERT
+
+dAboveVal       DN  D0.U8
+
+;// OMX_VC_CHROMA_DC
+
+dLeftVal        DN  D1.U8
+dSumAboveValU16 DN  D2.U16
+dSumAboveValU32 DN  D3.U32
+dSumAboveValU8  DN  D3.U8
+dSumLeftValU16  DN  D2.U16
+dSumLeftValU32  DN  D1.U32
+dSumLeftValU8   DN  D1.U8
+dSumAboveLeft   DN  D2.U32
+dSumAboveLeftU8 DN  D2.U8
+dIndexRow0U8    DN  D5.U8
+dIndexRow0      DN  D5.U64
+dIndexRow4U8    DN  D6.U8
+dIndexRow4      DN  D6.U64
+dDstRow0        DN  D0.U8
+dDstRow4        DN  D4.U8
+dConst128U8     DN  D0.U8
+
+;// OMX_VC_CHROMA_PLANE
+
+dRevAboveVal    DN  D3.U8  
+dRevAboveValU64 DN  D3.U64  
+dAboveLeftVal   DN  D2.U8
+qAbove7minus0   QN  Q3.S16 
+qAboveDiff      QN  Q2.S16 
+dIndex          DN  D8.U8  
+dDiffAboveU8    DN  D9.U8  
+dDiffAboveS16   DN  D9.S16 
+dAboveDiff0U8   DN  D4.U8  
+dAboveDiff0U64  DN  D4.U64
+dAbove7minus0U8 DN  D6.U8  
+dMultiplier     DN  D10.S16 
+dHorPred        DN  D11.S16 
+dRevLeftVal     DN  D3.U8
+dRevLeftValU64  DN  D3.U64
+qLeft7minus0    QN  Q7.S16
+qLeftDiff       QN  Q6.S16
+dDiffLeftU8     DN  D16.U8
+dDiffLeftS16    DN  D16.S16
+dLeftDiff0U8    DN  D12.U8
+dLeftDiff0U64   DN  D12.U64
+dLeft7minus0U8  DN  D14.U8
+dVerPred        DN  D3.S16 
+dHVValS16       DN  D3.S16
+dHVValS32       DN  D3.S32
+dHVTempS32      DN  D2.S32
+qA              QN  Q0.S16
+qB              QN  Q2.S16
+qC              QN  Q3.S16
+qMultiplier     QN  Q5.S16
+dMultiplier0    DN  D10.S16
+dMultiplier1    DN  D11.S16
+qC0             QN  Q0.S16
+qC1             QN  Q1.S16
+qC2             QN  Q4.S16
+qC3             QN  Q5.S16
+qC4             QN  Q6.S16
+qC5             QN  Q7.S16
+qC6             QN  Q8.S16
+qC7             QN  Q9.S16
+qSum0           QN  Q0.S16
+qSum1           QN  Q1.S16
+qSum2           QN  Q4.S16
+qSum3           QN  Q5.S16
+qSum4           QN  Q6.S16
+qSum5           QN  Q7.S16
+qSum6           QN  Q8.S16
+qSum7           QN  Q9.S16
+dSum0           DN  D0.U8
+dSum1           DN  D1.U8
+dSum2           DN  D2.U8
+dSum3           DN  D3.U8
+dSum4           DN  D4.U8
+dSum5           DN  D5.U8
+dSum6           DN  D6.U8
+dSum7           DN  D7.U8
+
+;//-----------------------------------------------------------------------------------------------
+;// omxVCM4P10_PredictIntraChroma_8x8 starts
+;//-----------------------------------------------------------------------------------------------
+        
+        ;// Write function header
+        M_START omxVCM4P10_PredictIntraChroma_8x8, r10, d15
+        
+        ;// Define stack arguments
+        M_ARG    LeftStep,     4
+        M_ARG    DstStep,      4
+        M_ARG    PredMode,     4
+        M_ARG    Availability, 4
+        
+        LDR      pTable,=armVCM4P10_pIndexTable8x8   ;// Load index table for switch case
+        
+        ;// Load argument from the stack
+        M_LDR    predMode, PredMode                  ;// Arg predMode loaded from stack to reg 
+        M_LDR    leftStep, LeftStep                  ;// Arg leftStep loaded from stack to reg 
+        M_LDR    dstStep,  DstStep                   ;// Arg dstStep loaded from stack to reg         
+        M_LDR    availability, Availability          ;// Arg availability loaded from stack to reg 
+        
+        
+        LDR      pc, [pTable, predMode, LSL #2]      ;// Branch to the case based on preMode
+
+OMX_VC_CHROMA_DC
+        
+        TST     availability, #OMX_VC_LEFT
+        BEQ     DCChroma8x8LeftNotAvailable
+
+        ADD     pTmp, pSrcLeft, leftStep
+        ADD     step, leftStep, leftStep
+
+        ;// Load Left Edge
+        VLD1    {dLeftVal[0]},[pSrcLeft],step               ;// pSrcLeft[0*leftStep]
+        VLD1    {dLeftVal[1]},[pTmp],step                   ;// pSrcLeft[1*leftStep]
+        VLD1    {dLeftVal[2]},[pSrcLeft],step               ;// pSrcLeft[2*leftStep]
+        VLD1    {dLeftVal[3]},[pTmp],step                   ;// pSrcLeft[3*leftStep]
+        VLD1    {dLeftVal[4]},[pSrcLeft],step               ;// pSrcLeft[4*leftStep]
+        VLD1    {dLeftVal[5]},[pTmp],step                   ;// pSrcLeft[5*leftStep]
+        VLD1    {dLeftVal[6]},[pSrcLeft],step               ;// pSrcLeft[6*leftStep]
+        VLD1    {dLeftVal[7]},[pTmp]                        ;// pSrcLeft[7*leftStep]      
+        
+        TST     availability, #OMX_VC_UPPER
+        BEQ     DCChroma8x8LeftOnlyAvailable
+
+        ;// Load Upper Edge also
+        VLD1     dAboveVal,[pSrcAbove]                      ;// pSrcAbove[0 to 7]  
+        
+        MOV      return, #OMX_Sts_NoErr                     ;// returnNoError
+        
+        VPADDL   dSumAboveValU16, dAboveVal                 ;// pSrcAbove[ 6+7 | 4+5 | 2+3 | 0+1 ]             
+        VPADDL   dSumAboveValU32, dSumAboveValU16           ;// pSrcAbove[ 4+5+6+7 |  0+1+2+3 ] 
+                
+        VPADDL   dSumLeftValU16, dLeftVal                   ;// pSrcLeft[ 6+7 | 4+5 | 2+3 | 0+1 ]             
+        VPADDL   dSumLeftValU32, dSumLeftValU16             ;// pSrcLeft[ 4+5+6+7 |  0+1+2+3 ]             
+        
+        VADD     dSumAboveLeft,dSumAboveValU32,dSumLeftValU32
+        VRSHR    dSumAboveLeft,dSumAboveLeft,#3             ;// Sum = (Sum + 4) >> 3
+        VRSHR    dSumAboveValU32,dSumAboveValU32,#2         ;// Sum = (Sum + 2) >> 2
+        VRSHR    dSumLeftValU32,dSumLeftValU32,#2           ;// Sum = (Sum + 2) >> 2
+        
+        VMOV     dIndexRow0U8,#0x0c                         
+        VMOV     dIndexRow4U8,#0x04
+        VSHL     dIndexRow0,dIndexRow0,#32                  ;// index0 = 0x0c0c0c0c00000000 
+        VSHR     dIndexRow4,dIndexRow4,#32                  ;// index4 = 0x0000000004040404
+        VADD     dIndexRow4U8,dIndexRow4U8,dIndexRow0U8     ;// index4 = 0x0c0c0c0c04040404
+        VTBL     dDstRow0,{dSumAboveLeftU8,dSumAboveValU8},dIndexRow0U8
+        VTBL     dDstRow4,{dSumLeftValU8,dSumAboveLeftU8},dIndexRow4U8
+ 
+DCChroma8x8LeftStore       
+        ADD     pTmp, pDst, dstStep
+        ADD     step, dstStep, dstStep
+        
+        VST1     dDstRow0,[pDst],step                    ;// pDst[0*dstStep+x] :0<= x <= 7
+        VST1     dDstRow0,[pTmp],step                    ;// pDst[1*dstStep+x] :0<= x <= 7
+        VST1     dDstRow0,[pDst],step                    ;// pDst[2*dstStep+x] :0<= x <= 7
+        VST1     dDstRow0,[pTmp],step                    ;// pDst[3*dstStep+x] :0<= x <= 7
+        VST1     dDstRow4,[pDst],step                    ;// pDst[4*dstStep+x] :0<= x <= 7
+        VST1     dDstRow4,[pTmp],step                    ;// pDst[5*dstStep+x] :0<= x <= 7
+        VST1     dDstRow4,[pDst],step                    ;// pDst[6*dstStep+x] :0<= x <= 7
+        VST1     dDstRow4,[pTmp]                         ;// pDst[7*dstStep+x] :0<= x <= 7
+
+        M_EXIT
+        
+
+DCChroma8x8LeftOnlyAvailable
+
+        MOV      return, #OMX_Sts_NoErr
+        
+        VPADDL   dSumLeftValU16, dLeftVal                   ;// pSrcLeft[ 6+7 | 4+5 | 2+3 | 0+1 ]             
+        VPADDL   dSumLeftValU32, dSumLeftValU16             ;// pSrcLeft[ 4+5+6+7 |  0+1+2+3 ]   
+        VRSHR    dSumLeftValU32,dSumLeftValU32,#2           ;// Sum = (Sum + 2) >> 2
+        
+        VDUP     dDstRow0,dSumLeftValU8[0]
+        VDUP     dDstRow4,dSumLeftValU8[4]
+        
+        B        DCChroma8x8LeftStore  
+        
+
+DCChroma8x8LeftNotAvailable
+                 
+        TST     availability, #OMX_VC_UPPER
+        BEQ     DCChroma8x8NoneAvailable
+
+        ;// Load Upper Edge 
+        VLD1     dAboveVal,[pSrcAbove]                      ;// pSrcAbove[0 to 7]  
+        MOV      return, #OMX_Sts_NoErr                     ;// returnNoError
+        
+        VPADDL   dSumAboveValU16, dAboveVal                 ;// pSrcAbove[ 6+7 | 4+5 | 2+3 | 0+1 ]             
+        VPADDL   dSumAboveValU32, dSumAboveValU16           ;// pSrcAbove[ 4+5+6+7 |  0+1+2+3 ] 
+        VRSHR    dSumAboveValU32,dSumAboveValU32,#2         ;// Sum = (Sum + 2) >> 2
+        VMOV     dIndexRow0U8,#0x04
+        VSHL     dIndexRow0,dIndexRow0,#32                  ;// index = 0x0404040400000000
+        VTBL     dDstRow0,{dSumAboveValU8},dIndexRow0U8 
+        
+        B        DCChroma8x8UpperStore
+        
+
+DCChroma8x8NoneAvailable        
+        
+        VMOV     dConst128U8,#0x80                          ;// 0x8080808080808080 if(count == 0)
+        MOV      return, #OMX_Sts_NoErr                     ;// returnNoError
+
+DCChroma8x8UpperStore        
+        
+        ADD     pTmp, pDst, dstStep
+        ADD     step, dstStep, dstStep
+        
+        VST1     dDstRow0,[pDst],step                    ;// pDst[0*dstStep+x] :0<= x <= 7
+        VST1     dDstRow0,[pTmp],step                    ;// pDst[1*dstStep+x] :0<= x <= 7
+        VST1     dDstRow0,[pDst],step                    ;// pDst[2*dstStep+x] :0<= x <= 7
+        VST1     dDstRow0,[pTmp],step                    ;// pDst[3*dstStep+x] :0<= x <= 7
+        VST1     dDstRow0,[pDst],step                    ;// pDst[4*dstStep+x] :0<= x <= 7
+        VST1     dDstRow0,[pTmp],step                    ;// pDst[5*dstStep+x] :0<= x <= 7
+        VST1     dDstRow0,[pDst],step                    ;// pDst[6*dstStep+x] :0<= x <= 7
+        VST1     dDstRow0,[pTmp]                         ;// pDst[7*dstStep+x] :0<= x <= 7
+        
+        M_EXIT
+
+
+OMX_VC_CHROMA_VERT
+        
+        VLD1     dAboveVal,[pSrcAbove]                      ;// pSrcAbove[x]      :0<= x <= 7   
+        MOV      return, #OMX_Sts_NoErr
+        
+        B        DCChroma8x8UpperStore
+        
+
+OMX_VC_CHROMA_HOR
+        
+        ADD     pTmp, pSrcLeft, leftStep
+        ADD     step, leftStep, leftStep
+        
+        VLD1    {dLeftVal0[]},[pSrcLeft],step           ;// pSrcLeft[0*leftStep]
+        VLD1    {dLeftVal1[]},[pTmp],step               ;// pSrcLeft[1*leftStep]
+        VLD1    {dLeftVal2[]},[pSrcLeft],step           ;// pSrcLeft[2*leftStep]
+        VLD1    {dLeftVal3[]},[pTmp],step               ;// pSrcLeft[3*leftStep]
+        VLD1    {dLeftVal4[]},[pSrcLeft],step           ;// pSrcLeft[4*leftStep]
+        VLD1    {dLeftVal5[]},[pTmp],step               ;// pSrcLeft[5*leftStep]
+        VLD1    {dLeftVal6[]},[pSrcLeft],step           ;// pSrcLeft[6*leftStep]
+        VLD1    {dLeftVal7[]},[pTmp]                    ;// pSrcLeft[7*leftStep]
+        
+        B        DCChroma8x8PlaneStore
+        
+        
+OMX_VC_CHROMA_PLANE
+        ADD     pTmp, pSrcLeft, leftStep
+        ADD     step, leftStep, leftStep
+        
+        VLD1    dAboveVal,[pSrcAbove]                       ;// pSrcAbove[x]      :0<= x <= 7   
+        VLD1    dAboveLeftVal[0],[pSrcAboveLeft]
+        
+        VLD1    {dLeftVal[0]},[pSrcLeft],step               ;// pSrcLeft[0*leftStep]
+        VLD1    {dLeftVal[1]},[pTmp],step                   ;// pSrcLeft[1*leftStep]
+        VLD1    {dLeftVal[2]},[pSrcLeft],step               ;// pSrcLeft[2*leftStep]
+        VLD1    {dLeftVal[3]},[pTmp],step                   ;// pSrcLeft[3*leftStep]
+        VLD1    {dLeftVal[4]},[pSrcLeft],step               ;// pSrcLeft[4*leftStep]
+        VLD1    {dLeftVal[5]},[pTmp],step                   ;// pSrcLeft[5*leftStep]
+        VLD1    {dLeftVal[6]},[pSrcLeft],step               ;// pSrcLeft[6*leftStep]
+        VLD1    {dLeftVal[7]},[pTmp]                        ;// pSrcLeft[7*leftStep] 
+        
+        
+        VREV64  dRevAboveVal,dAboveVal                      ;// Reverse order of bytes = pSrcAbove[0:1:2:3:4:5:6:7]
+        VSUBL   qAbove7minus0,dRevAboveVal,dAboveLeftVal    ;// qAbove7minus0[0] = pSrcAbove[7] - pSrcAboveLeft[0]
+        VSHR    dRevAboveValU64,dRevAboveValU64,#8          ;// pSrcAbove[X:0:1:2:3:4:5:6]
+        VSUBL   qAboveDiff,dRevAboveVal,dAboveVal           ;// pSrcAbove[6] - pSrcAbove[0]
+                                                            ;// pSrcAbove[5] - pSrcAbove[1]
+                                                            ;// pSrcAbove[4] - pSrcAbove[2]
+        
+        VREV64  dRevLeftVal,dLeftVal                        ;// Reverse order of bytes = pSrcLeft[0:1:2:3:4:5:6:7]
+        VSUBL   qLeft7minus0,dRevLeftVal,dAboveLeftVal      ;// qAbove7minus0[0] = pSrcLeft[7] - pSrcAboveLeft[0]
+        VSHR    dRevLeftValU64,dRevLeftValU64,#8            ;// pSrcLeft[X:0:1:2:3:4:5:6]
+        VSUBL   qLeftDiff,dRevLeftVal,dLeftVal              ;// pSrcLeft[6] - pSrcLeft[0]
+                                                            ;// pSrcLeft[5] - pSrcLeft[1]
+                                                            ;// pSrcLeft[4] - pSrcLeft[2]
+        
+        LDR     pMultiplierTable,=armVCM4P10_MultiplierTableChroma8x8   ;// Used to calculate Hval & Vval  
+        VSHL    dAboveDiff0U64,dAboveDiff0U64,#16  
+        VEXT    dDiffAboveU8,dAboveDiff0U8,dAbove7minus0U8,#2           ;// pSrcAbove[ 7-0 | 4-2 | 5-1 | 6-0 ]
+        VLD1    dMultiplier,[pMultiplierTable]! 
+        VSHL    dLeftDiff0U64,dLeftDiff0U64,#16  
+        VEXT    dDiffLeftU8,dLeftDiff0U8,dLeft7minus0U8,#2              ;// pSrcLeft[ 7-0 | 4-2 | 5-1 | 6-0 ]                                                   
+                                                                    
+        
+        VMUL    dHorPred,dDiffAboveS16,dMultiplier                      ;// pSrcAbove[ 4*(7-0) | 1*(4-2) | 2*(5-1) | 3*(6-0) ]
+        VMUL    dVerPred,dDiffLeftS16,dMultiplier
+        VPADD   dHVValS16,dHorPred,dVerPred
+        
+        
+        VPADDL  dHVValS32,dHVValS16                                     ;// [V|H] in 32 bits each
+        VSHL    dHVTempS32,dHVValS32,#4                                 ;// 17*H = 16*H + H = (H<<4)+H
+        VADD    dHVValS32,dHVValS32,dHVTempS32                          ;// [ 17*V  | 17*H ]in 32 bits each
+        VLD1    {dMultiplier0,dMultiplier1},[pMultiplierTable]          ;// qMultiplier = [ 4|3|2|1|0|-1|-2|-3 ]  
+        VRSHR   dHVValS32,dHVValS32,#5                                  ;// [c|b] in 16bits each
+        VADDL   qA,dAboveVal,dLeftVal
+        VDUP    qA,qA[7]
+        VSHL    qA,qA,#4                                                ;// [a|a|a|a|a|a|a|a]
+        VDUP    qB,dHVValS16[0]                                         ;// [b|b|b|b|b|b|b|b]
+        VDUP    qC,dHVValS16[2]                                         ;// [c|c|c|c|c|c|c|c]
+        
+        
+        VMUL    qB,qB,qMultiplier
+        VMUL    qC,qC,qMultiplier
+        VADD    qB,qB,qA 
+        
+        VDUP    qC0,qC[0]
+        VDUP    qC1,qC[1]
+        VDUP    qC2,qC[2]
+        VDUP    qC3,qC[3]
+        VDUP    qC4,qC[4]
+        VDUP    qC5,qC[5]
+        VDUP    qC6,qC[6]
+        VDUP    qC7,qC[7]
+        
+        VADD    qSum0,qB,qC0
+        VADD    qSum1,qB,qC1
+        VADD    qSum2,qB,qC2
+        VADD    qSum3,qB,qC3
+        VADD    qSum4,qB,qC4
+        VADD    qSum5,qB,qC5
+        VADD    qSum6,qB,qC6
+        VADD    qSum7,qB,qC7
+        
+        VQRSHRUN dSum0,qSum0,#5                         ;// (OMX_U8)armClip(0,255,(Sum+16)>>5)
+        VQRSHRUN dSum1,qSum1,#5
+        VQRSHRUN dSum2,qSum2,#5
+        VQRSHRUN dSum3,qSum3,#5
+        VQRSHRUN dSum4,qSum4,#5
+        VQRSHRUN dSum5,qSum5,#5
+        VQRSHRUN dSum6,qSum6,#5
+        VQRSHRUN dSum7,qSum7,#5      
+
+DCChroma8x8PlaneStore        
+        ADD     pTmp, pDst, dstStep
+        ADD     step, dstStep, dstStep
+        
+        VST1    dSum0,[pDst],step                    ;// pDst[0*dstStep+x] :0<= x <= 7
+        VST1    dSum1,[pTmp],step                    ;// pDst[1*dstStep+x] :0<= x <= 7
+        VST1    dSum2,[pDst],step                    ;// pDst[2*dstStep+x] :0<= x <= 7
+        VST1    dSum3,[pTmp],step                    ;// pDst[3*dstStep+x] :0<= x <= 7
+        VST1    dSum4,[pDst],step                    ;// pDst[4*dstStep+x] :0<= x <= 7
+        VST1    dSum5,[pTmp],step                    ;// pDst[5*dstStep+x] :0<= x <= 7
+        VST1    dSum6,[pDst],step                    ;// pDst[6*dstStep+x] :0<= x <= 7
+        VST1    dSum7,[pTmp]                         ;// pDst[7*dstStep+x] :0<= x <= 7       
+        
+        MOV     return, #OMX_Sts_NoErr
+        M_END
+        
+        ENDIF ;// CortexA8
+        
+        END
+;//-----------------------------------------------------------------------------------------------
+;// omxVCM4P10_PredictIntraChroma_8x8 ends
+;//-----------------------------------------------------------------------------------------------
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_PredictIntra_16x16_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_PredictIntra_16x16_s.s
new file mode 100755
index 0000000..e9c0eee
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_PredictIntra_16x16_s.s
@@ -0,0 +1,424 @@
+;//
+;// 
+;// File Name:  omxVCM4P10_PredictIntra_16x16_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   12290
+;// Date:       Wednesday, April 9, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+        
+        M_VARIANTS CortexA8
+     
+  
+;//-------------------------------------------------------
+;// This table for implementing switch case of C in asm by
+;// the mehtod of two levels of indexing.
+;//-------------------------------------------------------
+
+    M_TABLE armVCM4P10_pIndexTable16x16
+    DCD  OMX_VC_16X16_VERT, OMX_VC_16X16_HOR 
+    DCD  OMX_VC_16X16_DC,   OMX_VC_16X16_PLANE
+    
+
+    IF CortexA8
+
+    M_TABLE armVCM4P10_MultiplierTable16x16,1
+    DCW   7,  6,  5,  4,  3,  2,  1,  8 
+    DCW   0,  1,  2,  3,  4,  5,  6,  7
+    DCW   8,  9, 10, 11, 12, 13, 14, 15
+        
+;//--------------------------------------------
+;// Constants 
+;//--------------------------------------------  
+BLK_SIZE        EQU 0x10
+MUL_CONST0      EQU 0x01010101
+MUL_CONST1      EQU 0x00060004
+MUL_CONST2      EQU 0x00070005
+MUL_CONST3      EQU 0x00030001
+MASK_CONST      EQU 0x00FF00FF
+
+;//--------------------------------------------
+;// Scratch variable
+;//--------------------------------------------
+y               RN 12   
+pc              RN 15   
+
+return          RN 0    
+pTable          RN 9    
+count           RN 11   
+pMultTable      RN 9
+; ----------------------------------------------
+; Neon registers
+; ----------------------------------------------
+qAbove          QN Q0.U8
+qLeft           QN Q1.U8
+qSum8           QN Q0.U16
+dSum80          DN D0.U16
+dSum81          DN D1.U16
+dSum4           DN D0.U16
+dSum2           DN D0.U32
+dSum1           DN D0.U64
+qOut            QN Q3.U8
+dSumLeft        DN D6.U64
+dSumAbove       DN D7.U64
+dSum            DN D8.U64
+dSum0           DN D8.U8[0]
+
+qH              QN Q11.S32
+qV              QN Q12.S32
+qA              QN Q11.S16
+qB              QN Q6.S16
+qC              QN Q7.S16
+
+qB0             QN Q5.S16
+qB1             QN Q6.S16
+dA1             DN D23.S16
+
+dH0             DN D22.S32
+dH1             DN D23.S32
+dV0             DN D24.S32
+dV1             DN D25.S32
+
+qHV             QN Q11.S64
+qHV0            QN Q11.S32
+qHV1            QN Q12.S64
+
+dHV00           DN D22.S32
+dHV01           DN D23.S32
+
+dHV0            DN D22.S16[0]
+dHV1            DN D23.S16[0]
+dHV10           DN D24.S64
+dHV11           DN D25.S64
+
+qSum0           QN Q0.S16
+qSum1           QN Q1.S16
+
+dOut0           DN D6.U8
+dOut1           DN D7.U8
+
+dLeft0          DN D2.U8
+dLeft1          DN D3.U8
+qConst          QN Q13.S16
+
+dAbove0         DN D0.U8
+dAbove1         DN D1.U8
+
+dRevLeft64      DN D12.U64
+dRevLeft        DN D12.U8
+dRevAbove64     DN D5.U64
+dRevAbove       DN D5.U8
+qLeftDiff       QN Q8.S16
+dLeftDiff1      DN D17.S16
+dLeftDiff64     DN D17.S64
+qDiffLeft       QN Q8.S16
+qDiffAbove      QN Q4.S16
+dAboveDiff1     DN D9.S16
+dAboveDiff64    DN D9.S64
+qAboveDiff      QN Q4.S16
+
+dAboveLeft      DN D4.U8
+
+dDiffLeft0      DN D16.S16
+dDiffLeft1      DN D17.S16
+dDiffAbove0     DN D8.S16
+dDiffAbove1     DN D9.S16
+
+qLeft15minus0   QN Q7.S16
+dLeft15minus0   DN D14.S16
+qAbove15minus0  QN Q3.S16
+dAbove15minus0  DN D6.S16
+
+qMultiplier     QN Q10.S16
+qMultiplier0    QN Q10.S16
+qMultiplier1    QN Q12.S16
+dMultiplier0    DN D20.S16
+dMultiplier1    DN D21.S16
+
+dBPlusCMult7    DN D1.S64
+dBPlusCMult7S16 DN D1.S16
+
+qTmp            QN Q0.U8
+
+;//--------------------------------------------
+;// Declare input registers
+;//--------------------------------------------
+pSrcLeft        RN 0    ;// input pointer
+pSrcAbove       RN 1    ;// input pointer
+pSrcAboveLeft   RN 2    ;// input pointer
+pDst            RN 3    ;// output pointer
+leftStep        RN 4    ;// input variable
+dstStep         RN 5    ;// input variable
+predMode        RN 6    ;// input variable
+availability    RN 7    ;// input variable
+
+pTmp            RN 8
+step            RN 10
+pTmp2           RN 11
+
+;//-----------------------------------------------------------------------------------------------
+;// omxVCM4P10_PredictIntra_16x16 starts
+;//-----------------------------------------------------------------------------------------------
+        
+        ;// Write function header
+        M_START omxVCM4P10_PredictIntra_16x16, r11, d15
+        
+        ;// Define stack arguments
+        M_ARG    LeftStep,     4
+        M_ARG    DstStep,      4
+        M_ARG    PredMode,     4
+        M_ARG    Availability, 4
+        
+        ;// M_STALL ARM1136JS=4
+        
+        LDR      pTable,=armVCM4P10_pIndexTable16x16 ;// Load index table for switch case
+        
+        ;// Load argument from the stack
+        M_LDR    predMode, PredMode                  ;// Arg predMode loaded from stack to reg 
+        M_LDR    leftStep, LeftStep                  ;// Arg leftStep loaded from stack to reg 
+        M_LDR    dstStep,  DstStep                   ;// Arg dstStep loaded from stack to reg         
+        M_LDR    availability, Availability          ;// Arg availability loaded from stack to reg
+        
+        MOV      y, #BLK_SIZE                        ;// Outer Loop Count
+        LDR      pc, [pTable, predMode, LSL #2]      ;// Branch to the case based on preMode
+        
+OMX_VC_16X16_VERT
+        VLD1    qAbove,  [pSrcAbove]
+        ADD     pTmp, pDst, dstStep
+        ADD     step, dstStep, dstStep
+        VST1    qAbove, [pDst], step
+        VST1    qAbove, [pTmp], step
+        VST1    qAbove, [pDst], step
+        VST1    qAbove, [pTmp], step
+        VST1    qAbove, [pDst], step
+        VST1    qAbove, [pTmp], step
+        VST1    qAbove, [pDst], step
+        VST1    qAbove, [pTmp], step
+        VST1    qAbove, [pDst], step
+        VST1    qAbove, [pTmp], step
+        VST1    qAbove, [pDst], step
+        VST1    qAbove, [pTmp], step
+        VST1    qAbove, [pDst], step
+        VST1    qAbove, [pTmp], step
+        VST1    qAbove, [pDst]
+        VST1    qAbove, [pTmp]
+        MOV     return, #OMX_Sts_NoErr               ;// returnNoError
+        M_EXIT
+        
+OMX_VC_16X16_HOR
+        ADD     pTmp, pSrcLeft, leftStep
+        ADD     leftStep, leftStep, leftStep
+        ADD     pTmp2, pDst, dstStep
+        ADD     dstStep, dstStep, dstStep
+LoopHor 
+        VLD1     {qLeft[]}, [pSrcLeft], leftStep       
+        VLD1     {qTmp[]}, [pTmp], leftStep       
+        SUBS     y, y, #8
+        VST1     qLeft, [pDst], dstStep
+        VST1     qTmp, [pTmp2], dstStep
+        VLD1     {qLeft[]}, [pSrcLeft], leftStep       
+        VLD1     {qTmp[]}, [pTmp], leftStep       
+        VST1     qLeft, [pDst], dstStep
+        VST1     qTmp, [pTmp2], dstStep
+        VLD1     {qLeft[]}, [pSrcLeft], leftStep       
+        VLD1     {qTmp[]}, [pTmp], leftStep       
+        VST1     qLeft, [pDst], dstStep
+        VST1     qTmp, [pTmp2], dstStep
+        VLD1     {qLeft[]}, [pSrcLeft], leftStep       
+        VLD1     {qTmp[]}, [pTmp], leftStep       
+        VST1     qLeft, [pDst], dstStep
+        VST1     qTmp, [pTmp2], dstStep
+        
+        BNE      LoopHor                                  ;// Loop for 16 times
+        MOV      return, #OMX_Sts_NoErr
+        M_EXIT
+        
+OMX_VC_16X16_DC
+        MOV      count, #0                                 ;// count = 0
+        TST      availability, #OMX_VC_LEFT
+        BEQ      UpperOrNoneAvailable                      ;// Jump to Upper if not left
+
+        ADD     pTmp, pSrcLeft, leftStep
+        ADD     step, leftStep, leftStep
+
+        VLD1    {qLeft[0]}, [pSrcLeft],step    
+        VLD1    {qLeft[1]}, [pTmp],step   
+        VLD1    {qLeft[2]}, [pSrcLeft],step   
+        VLD1    {qLeft[3]}, [pTmp],step
+        VLD1    {qLeft[4]}, [pSrcLeft],step   
+        VLD1    {qLeft[5]}, [pTmp],step   
+        VLD1    {qLeft[6]}, [pSrcLeft],step    
+        VLD1    {qLeft[7]}, [pTmp],step
+        VLD1    {qLeft[8]}, [pSrcLeft],step    
+        VLD1    {qLeft[9]}, [pTmp],step   
+        VLD1    {qLeft[10]},[pSrcLeft],step   
+        VLD1    {qLeft[11]},[pTmp],step    
+        VLD1    {qLeft[12]},[pSrcLeft],step   
+        VLD1    {qLeft[13]},[pTmp],step   
+        VLD1    {qLeft[14]},[pSrcLeft],step    
+        VLD1    {qLeft[15]},[pTmp] 
+        
+        VPADDL   qSum8, qLeft
+        ADD     count, count, #1    
+        VPADD    dSum4, dSum80, dSum81
+        VPADDL   dSum2, dSum4
+        VPADDL   dSumLeft, dSum2
+        VRSHR    dSum, dSumLeft, #4
+        
+UpperOrNoneAvailable
+        TST      availability,  #OMX_VC_UPPER              ;// if(availability & #OMX_VC_UPPER)
+        BEQ      BothOrNoneAvailable                       ;// Jump to Left if not upper
+        VLD1     qAbove, [pSrcAbove]
+        ADD      count, count, #1                          ;// if upper inc count by 1
+        VPADDL   qSum8, qAbove
+        VPADD    dSum4, dSum80, dSum81
+        VPADDL   dSum2, dSum4
+        VPADDL   dSumAbove, dSum2
+        VRSHR    dSum, dSumAbove, #4
+        
+BothOrNoneAvailable
+        CMP      count, #2                                  ;// check if both available
+        BNE      NoneAvailable
+        VADD     dSum, dSumAbove, dSumLeft
+        VRSHR    dSum, dSum, #5
+        
+
+NoneAvailable
+        VDUP     qOut, dSum0        
+        CMP      count, #0                                  ;// check if none available
+        ADD      pTmp, pDst, dstStep
+        ADD      step, dstStep, dstStep
+        BNE      LoopDC
+        VMOV     qOut, #128
+LoopDC        
+        VST1    qOut, [pDst], step
+        VST1    qOut, [pTmp], step
+        VST1    qOut, [pDst], step
+        VST1    qOut, [pTmp], step
+        VST1    qOut, [pDst], step
+        VST1    qOut, [pTmp], step
+        VST1    qOut, [pDst], step
+        VST1    qOut, [pTmp], step
+        VST1    qOut, [pDst], step
+        VST1    qOut, [pTmp], step
+        VST1    qOut, [pDst], step
+        VST1    qOut, [pTmp], step
+        VST1    qOut, [pDst], step
+        VST1    qOut, [pTmp], step
+        VST1    qOut, [pDst], step
+        VST1    qOut, [pTmp], step
+        MOV     return, #OMX_Sts_NoErr
+        M_EXIT
+
+OMX_VC_16X16_PLANE
+        LDR     pMultTable, =armVCM4P10_MultiplierTable16x16
+        VLD1    qAbove, [pSrcAbove]                         ;// pSrcAbove[x]      :0<= x <= 7    
+        VLD1    dAboveLeft[0],[pSrcAboveLeft]                                               
+        ADD     pTmp, pSrcLeft, leftStep
+        ADD     step, leftStep, leftStep
+        VLD1    {qLeft[0]},  [pSrcLeft],step                                             
+        VLD1    {qLeft[1]},  [pTmp],step      
+        VLD1    {qLeft[2]},  [pSrcLeft],step  
+        VLD1    {qLeft[3]},  [pTmp],step       
+        VLD1    {qLeft[4]},  [pSrcLeft],step  
+        VLD1    {qLeft[5]},  [pTmp],step      
+        VLD1    {qLeft[6]},  [pSrcLeft],step   
+        VLD1    {qLeft[7]},  [pTmp],step
+        VLD1    {qLeft[8]},  [pSrcLeft],step   
+        VLD1    {qLeft[9]},  [pTmp],step      
+        VLD1    {qLeft[10]}, [pSrcLeft],step  
+        VLD1    {qLeft[11]}, [pTmp],step       
+        VLD1    {qLeft[12]}, [pSrcLeft],step  
+        VLD1    {qLeft[13]}, [pTmp],step      
+        VLD1    {qLeft[14]}, [pSrcLeft],step   
+        VLD1    {qLeft[15]}, [pTmp]   
+
+        VREV64  dRevAbove, dAbove1                          ;// pSrcAbove[15:14:13:12:11:10:9:8] 
+        VSUBL   qAbove15minus0, dRevAbove, dAboveLeft       ;// qAbove7minus0[0] = pSrcAbove[15] - pSrcAboveLeft[0] 
+        VSHR    dRevAbove64, dRevAbove64, #8                ;// pSrcAbove[14:13:12:11:10:9:8:X] 
+        VSUBL   qAboveDiff, dRevAbove, dAbove0              
+        
+        VSHL    dAboveDiff64, dAboveDiff64, #16 
+        VEXT    dDiffAbove1, dAboveDiff1, dAbove15minus0, #1  
+
+        VREV64  dRevLeft,dLeft1                             ;// pSrcLeft[15:14:13:12:11:10:9:8] 
+        VSUBL   qLeft15minus0,dRevLeft, dAboveLeft          ;// qAbove7minus0[0] = pSrcLeft[7] - pSrcAboveLeft[0] 
+        VSHR    dRevLeft64, dRevLeft64, #8                  ;// pSrcLeft[14:13:12:11:10:9:8:X] 
+        VSUBL   qLeftDiff,dRevLeft, dLeft0                  
+        
+        ;// Multiplier = [8|1|2|...|6|7]
+        VLD1    qMultiplier, [pMultTable]!                  
+        
+        VSHL    dLeftDiff64, dLeftDiff64, #16
+        VEXT    dDiffLeft1, dLeftDiff1, dLeft15minus0, #1     
+        
+        VMULL   qH,dDiffAbove0, dMultiplier0                
+        VMULL   qV,dDiffLeft0,  dMultiplier0                
+        VMLAL   qH,dDiffAbove1, dMultiplier1 
+        VMLAL   qV,dDiffLeft1,  dMultiplier1
+        
+        VPADD   dHV00,dH1,dH0                                 
+        VPADD   dHV01,dV1,dV0                                 
+        VPADDL  qHV, qHV0
+        VSHL    qHV1,qHV,#2
+        VADD    qHV,qHV,qHV1 
+        
+        ;// HV = [c = ((5*V+32)>>6) | b = ((5*H+32)>>6)]
+        VRSHR   qHV,qHV,#6
+        
+        ;// HV1 = [c*7|b*7]
+        VSHL    qHV1,qHV,#3
+        VSUB    qHV1,qHV1,qHV                             
+        
+        ;// Multiplier1 = [0|1|2|...|7]
+        VLD1    qMultiplier0, [pMultTable]!    
+        VDUP    qB, dHV0                                  
+        VDUP    qC, dHV1 
+        
+        VADDL   qA,dAbove1,dLeft1
+        VSHL    qA,qA, #4
+        VDUP    qA,dA1[3]  
+        VADD    dBPlusCMult7, dHV10, dHV11
+        
+        ;// Multiplier1 = [8|9|10|...|15]
+        VLD1    qMultiplier1, [pMultTable]
+        ;// Const = a - 7*(b+c)
+        VDUP    qConst, dBPlusCMult7S16[0]
+        VSUB    qConst, qA, qConst
+        
+        ;// B0 = [0*b|1*b|2*b|3*b|......|7*b]
+        VMUL    qB0,qB,qMultiplier0
+        
+        ;// B0 = [8*b|9*b|10*b|11*b|....|15*b]
+        VMUL    qB1,qB,qMultiplier1
+        
+        VADD    qSum0, qB0, qConst
+        VADD    qSum1, qB1, qConst  
+        
+        ;// Loops for 16 times
+LoopPlane       
+        ;// (b*x + c*y + C)>>5
+        VQRSHRUN dOut0, qSum0,#5
+        VQRSHRUN dOut1, qSum1,#5      
+        SUBS     y, y, #1
+        VST1     qOut,[pDst],dstStep
+        VADD     qSum0,qSum0,qC 
+        VADD     qSum1,qSum1,qC 
+        BNE      LoopPlane
+        
+        MOV      return, #OMX_Sts_NoErr
+
+        M_END
+        
+        ENDIF ;// CortexA8
+            
+        END
+;-----------------------------------------------------------------------------------------------
+; omxVCM4P10_PredictIntra_16x16 ends
+;-----------------------------------------------------------------------------------------------
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_PredictIntra_4x4_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_PredictIntra_4x4_s.s
new file mode 100755
index 0000000..39eb8a4
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_PredictIntra_4x4_s.s
@@ -0,0 +1,531 @@
+;//
+;// 
+;// File Name:  omxVCM4P10_PredictIntra_4x4_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   12290
+;// Date:       Wednesday, April 9, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+        
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+        
+;// Define the processor variants supported by this file
+         
+         M_VARIANTS CortexA8
+        
+;//-------------------------------------------------------
+;// This table for implementing switch case of C in asm by
+;// the mehtod of two levels of indexing.
+;//-------------------------------------------------------
+
+    M_TABLE armVCM4P10_pSwitchTable4x4
+    DCD  OMX_VC_4x4_VERT,     OMX_VC_4x4_HOR 
+    DCD  OMX_VC_4x4_DC,       OMX_VC_4x4_DIAG_DL
+    DCD  OMX_VC_4x4_DIAG_DR,  OMX_VC_4x4_VR
+    DCD  OMX_VC_4x4_HD,       OMX_VC_4x4_VL
+    DCD  OMX_VC_4x4_HU   
+    
+        
+        IF CortexA8
+        
+;//--------------------------------------------
+;// Scratch variable
+;//--------------------------------------------
+return          RN 0
+pTable          RN 8
+pc              RN 15
+
+;//--------------------------------------------
+;// Declare input registers
+;//--------------------------------------------
+pSrcLeft        RN 0    ;// input pointer
+pSrcAbove       RN 1    ;// input pointer
+pSrcAboveLeft   RN 2    ;// input pointer
+pDst            RN 3    ;// output pointer
+leftStep        RN 4    ;// input variable
+dstStep         RN 5    ;// input variable
+predMode        RN 6    ;// input variable
+availability    RN 7    ;// input variable
+pDst1           RN 1 
+pDst2           RN 4 
+pDst3           RN 6 
+
+pSrcTmp         RN 9
+srcStep         RN 10
+pDstTmp         RN 11
+dstep           RN 12
+
+;//-------------------
+;// Neon registers
+;//-------------------
+
+;// OMX_VC_CHROMA_VERT
+dAboveU32       DN  D0.U32
+
+;// OMX_VC_CHROMA_HOR
+dLeftVal0       DN  D0.8
+dLeftVal1       DN  D1.8
+dLeftVal2       DN  D2.8
+dLeftVal3       DN  D3.8
+dLeftVal0U32    DN  D0.U32
+dLeftVal1U32    DN  D1.U32
+dLeftVal2U32    DN  D2.U32
+dLeftVal3U32    DN  D3.U32
+
+;// OMX_VC_4x4_DC
+dLeftVal        DN  D0.U8
+dLeftValU32     DN  D0.U32
+dSumAboveLeftU16  DN  D1.U16
+dSumAboveLeftU32  DN  D1.U32
+dSumAboveLeftU64  DN  D1.U64
+dSumAboveLeftU8 DN  D1.U8
+dSum            DN  D0.U8
+
+dSumLeftValU16  DN  D1.U16
+dSumLeftValU32  DN  D1.U32
+dSumLeftValU64  DN  D1.U64
+dSumLeftValU8   DN  D1.U8
+
+dAboveVal       DN  D0.U8
+dSumAboveValU16  DN  D1.U16
+dSumAboveValU32  DN  D1.U32
+dSumAboveValU64  DN  D1.U64
+dSumAboveValU8   DN  D1.U8
+dConst128U8     DN  D0.U8
+
+
+;//OMX_VC_4x4_DIAG_DL
+
+dAbove          DN  D0.U8
+dU7             DN  D2.U8
+dU3             DN  D2.U8
+dAbove0         DN  D3.U8
+dAbove1         DN  D4.U8
+dAbove2         DN  D5.U8
+dTmp            DN  D6.U8
+dTmp0           DN  D7.U8
+dTmp1           DN  D8.U8
+dTmp2            DN  D9.U8
+dTmp3            DN  D10.U8
+dTmpU32         DN  D6.U32
+
+
+;//OMX_VC_4x4_DIAG_DR
+dLeft           DN  D1.U8
+dUL             DN  D2.U8
+
+;//OMX_VC_4x4_VR
+dLeft0          DN  D1.U8
+dLeft1          DN  D2.U8
+dEven0          DN  D3.U8
+dEven1          DN  D4.U8
+dEven2          DN  D5.U8
+dOdd0           DN  D6.U8
+dOdd1           DN  D11.U8
+dOdd2           DN  D12.U8
+dTmp3U32        DN  D10.U32    
+dTmp2U32        DN  D9.U32
+
+
+;//OMX_VC_4x4_HD
+dTmp1U64        DN  D8.U64
+dTmp0U64        DN  D7.U64
+dTmpU64         DN  D6.U64
+dTmpU32         DN  D6.U32
+dTmp1U32        DN  D8.U32
+
+;//OMX_VC_4x4_HU
+dL3             DN  D2.U8
+dLeftHU0        DN  D3.U8
+dLeftHU1        DN  D4.U8
+dLeftHU2        DN  D5.U8
+dTmp0U32        DN  D7.U32
+
+
+
+
+;//-----------------------------------------------------------------------------------------------
+;// omxVCM4P10_PredictIntra_4x4 starts
+;//-----------------------------------------------------------------------------------------------
+        
+        ;// Write function header
+        M_START omxVCM4P10_PredictIntra_4x4, r12,d12
+        
+        ;// Define stack arguments
+        M_ARG    LeftStep,     4
+        M_ARG    DstStep,      4
+        M_ARG    PredMode,     4
+        M_ARG    Availability, 4
+        
+                
+        LDR      pTable,=armVCM4P10_pSwitchTable4x4  ;// Load index table for switch case
+        
+        ;// Load argument from the stack
+        M_LDRD   predMode,availability,PredMode     ;// Arg predMode & availability loaded from stack to reg 
+        M_LDRD   leftStep,dstStep,LeftStep          ;// Arg leftStep & dstStep loaded from stack to reg 
+        
+        
+        LDR      pc, [pTable, predMode, LSL #2]      ;// Branch to the case based on preMode
+
+
+OMX_VC_4x4_HOR
+        
+        ADD     pSrcTmp, pSrcLeft, leftStep
+        ADD     srcStep, leftStep, leftStep
+        ;// Load Left Edge
+        VLD1    {dLeftVal0[]},[pSrcLeft],srcStep           ;// pSrcLeft[0*leftStep]
+        VLD1    {dLeftVal1[]},[pSrcTmp],srcStep            ;//    pSrcLeft[1*leftStep]
+        VLD1    {dLeftVal2[]},[pSrcLeft]                   ;//    pSrcLeft[2*leftStep]
+        VLD1    {dLeftVal3[]},[pSrcTmp]                    ;//    pSrcLeft[3*leftStep]
+        
+        ADD     pDstTmp, pDst, dstStep
+        ADD     dstep, dstStep, dstStep
+        
+        VST1    dLeftVal0U32[0],[pDst],dstep                ;// pDst[0*dstStep+x] :0<= x <= 7
+        VST1    dLeftVal1U32[0],[pDstTmp],dstep             ;// pDst[1*dstStep+x] :0<= x <= 7
+        VST1    dLeftVal2U32[0],[pDst]                      ;// pDst[2*dstStep+x] :0<= x <= 7
+        VST1    dLeftVal3U32[0],[pDstTmp]                   ;// pDst[3*dstStep+x] :0<= x <= 7
+        
+        B        ExitPredict4x4                             ;// Branch to exit code
+        
+OMX_VC_4x4_VERT
+        
+        ;// Load Upper Edge
+        VLD1     dAboveU32[0],[pSrcAbove]
+        ADD     pDstTmp, pDst, dstStep
+        ADD     dstep, dstStep, dstStep
+        
+DCPredict4x4VertStore         
+        
+        VST1     dAboveU32[0],[pDst],dstep
+        VST1     dAboveU32[0],[pDstTmp],dstep
+        VST1     dAboveU32[0],[pDst]
+        VST1     dAboveU32[0],[pDstTmp]
+
+        B        ExitPredict4x4                             ;// Branch to exit code
+
+OMX_VC_4x4_DC
+        
+        
+        TST     availability, #OMX_VC_LEFT
+        BEQ     DCPredict4x4LeftNotAvailable
+
+        ADD     pSrcTmp, pSrcLeft, leftStep
+        ADD     srcStep, leftStep, leftStep
+        ;// Load Left Edge
+        VLD1    {dLeftVal[0]},[pSrcLeft],srcStep            ;// pSrcLeft[0*leftStep]
+        VLD1    {dLeftVal[1]},[pSrcTmp],srcStep             ;//    pSrcLeft[1*leftStep]
+        VLD1    {dLeftVal[2]},[pSrcLeft]                    ;//    pSrcLeft[2*leftStep]
+        VLD1    {dLeftVal[3]},[pSrcTmp]                     ;//    pSrcLeft[3*leftStep]
+        
+        TST     availability, #OMX_VC_UPPER
+        BEQ     DCPredict4x4LeftOnlyAvailable
+
+        ;// Load Upper Edge also
+        VLD1     dLeftValU32[1],[pSrcAbove]                 ;// pSrcAbove[0 to 3]
+        MOV      return, #OMX_Sts_NoErr
+        
+        VPADDL   dSumAboveLeftU16, dLeftVal                 ;// [pSrcAbove[2+3 | 0+1] | pSrcLeft[2+3 | 0+1]]             
+        VPADDL   dSumAboveLeftU32, dSumAboveLeftU16         ;// [pSrcAbove[2+3+0+1] | pSrcLeft[2+3+0+1]] 
+        VPADDL   dSumAboveLeftU64, dSumAboveLeftU32         ;// [pSrcAbove[2+3+0+1] + pSrcLeft[2+3+0+1]]                          
+        VRSHR    dSumAboveLeftU64,dSumAboveLeftU64,#3       ;// Sum = (Sum + 4) >> 3
+        ADD     pDstTmp, pDst, dstStep
+        ADD     dstep, dstStep, dstStep
+        VDUP     dSum,dSumAboveLeftU8[0]
+        
+        B        DCPredict4x4VertStore  
+        
+DCPredict4x4LeftOnlyAvailable
+
+        MOV      return, #OMX_Sts_NoErr                     ;// returnNoError
+        
+        VPADDL   dSumLeftValU16, dLeftVal                   ;// [ XX | pSrcLeft[2+3 | 0+1]]             
+        VPADDL   dSumLeftValU32, dSumLeftValU16             ;// [ XXXX | pSrcLeft[2+3+0+1]] 
+        
+        VRSHR    dSumLeftValU32,dSumLeftValU32,#2           ;// Sum = (Sum + 2) >> 2
+        ADD     pDstTmp, pDst, dstStep
+        ADD     dstep, dstStep, dstStep
+        VDUP     dSum,dSumLeftValU8[0]
+        
+        B        DCPredict4x4VertStore   
+        
+DCPredict4x4LeftNotAvailable
+                 
+        TST     availability, #OMX_VC_UPPER
+        BEQ     DCPredict4x4NoneAvailable
+
+        ;// Load Upper Edge 
+        VLD1     dAboveU32[0],[pSrcAbove]                   ;// pSrcAbove[0 to 3]  
+        MOV      return, #OMX_Sts_NoErr
+        
+        VPADDL   dSumAboveValU16, dAboveVal                 ;// [ XX | pSrcAbove[2+3 | 0+1]]             
+        VPADDL   dSumAboveValU32, dSumAboveValU16           ;// [ XXXX | pSrcAbove[2+3+0+1]] 
+        
+        VRSHR    dSumAboveValU32,dSumAboveValU32,#2         ;// Sum = (Sum + 2) >> 2
+        ADD     pDstTmp, pDst, dstStep
+        ADD     dstep, dstStep, dstStep
+        VDUP     dSum,dSumAboveValU8[0]
+        
+        B        DCPredict4x4VertStore   
+        
+DCPredict4x4NoneAvailable        
+        
+        VMOV     dConst128U8,#0x80                          ;// 0x8080808080808080 if(count == 0)
+        MOV      return, #OMX_Sts_NoErr
+        
+        ADD     pDstTmp, pDst, dstStep
+        ADD     dstep, dstStep, dstStep
+        B        DCPredict4x4VertStore   
+        
+        
+        
+OMX_VC_4x4_DIAG_DL
+        
+        TST     availability, #OMX_VC_UPPER_RIGHT
+        BEQ     DiagDLUpperRightNotAvailable
+       
+        VLD1    dAbove0,[pSrcAbove]                     ;// [U7|U6|U5|U4|U3|U2|U1|U0] 
+        VDUP    dU7, dAbove0[7]                         ;// [U7|U7|U7|U7|U7|U7|U7|U7]
+        VEXT    dAbove1, dAbove0, dU7, #1               ;// [U7|U7|U6|U5|U4|U3|U2|U1]
+        VEXT    dAbove2, dAbove0, dU7, #2               ;// [U7|U7|U7|U6|U5|U4|U3|U2] 
+        B       DiagDLPredict4x4Store         
+       
+DiagDLUpperRightNotAvailable
+        VLD1    dAboveU32[1],[pSrcAbove]                ;// [U3|U2|U1|U0|-|-|-|-] 
+        VDUP    dU3, dAbove[7]                          ;// [U3 U3 U3 U3 U3 U3 U3 U3]
+
+        VEXT    dAbove0, dAbove, dU3, #4                ;// [U3 U3 U3 U3 U3 U2 U1 U0]
+        VEXT    dAbove1, dAbove, dU3, #5                ;// [U3 U3 U3 U3 U3 U3 U2 U1]
+        VEXT    dAbove2, dAbove, dU3, #6                ;// [U3 U3 U3 U3 U3 U3 U3 U2]
+       
+DiagDLPredict4x4Store  
+        
+        VHADD   dTmp, dAbove0, dAbove2
+        VRHADD  dTmp, dTmp, dAbove1                     ;// (a+2*b+c+2)>>2
+        
+
+        VST1    dTmpU32[0],[pDst],dstStep
+        VEXT    dTmp,dTmp,dTmp,#1
+        VST1    dTmpU32[0],[pDst],dstStep
+        VEXT    dTmp,dTmp,dTmp,#1
+        VST1    dTmpU32[0],[pDst],dstStep
+        VEXT    dTmp,dTmp,dTmp,#1
+        VST1    dTmpU32[0],[pDst]
+        
+        B        ExitPredict4x4                         ;// Branch to exit code
+        
+
+OMX_VC_4x4_DIAG_DR
+        
+        
+        ;// Load U0,U1,U2,U3
+        
+        VLD1    dAboveU32[0],[pSrcAbove]                ;// [X|X|X|X|U3|U2|U1|U0]
+                
+        ;// Load UL,L0,L1,L2,L3                         ;// dLeft = [UL|L0|L1|L2|L3|X|X|X]    
+        VLD1    {dLeft[7]},[pSrcAboveLeft]              
+        ADD     pSrcTmp, pSrcLeft, leftStep
+        ADD     srcStep, leftStep, leftStep
+        ADD     pDst1,pDst,dstStep
+        
+        VLD1    {dLeft[6]},[pSrcLeft],srcStep           ;// pSrcLeft[0*leftStep]
+        VLD1    {dLeft[5]},[pSrcTmp],srcStep            ;// pSrcLeft[1*leftStep]
+        VLD1    {dLeft[4]},[pSrcLeft]                   ;// pSrcLeft[2*leftStep]
+        VLD1    {dLeft[3]},[pSrcTmp]                    ;// pSrcLeft[3*leftStep]
+        
+        
+        VEXT    dAbove0,dLeft,dAbove,#3                 ;// [U2|U1|U0|UL|L0|L1|L2|L3]   
+        ADD     pDst2,pDst1,dstStep
+        VEXT    dAbove1,dLeft,dAbove,#4                 ;// [U3|U2|U1|U0|UL|L0|L1|L2]   
+        ADD     pDst3,pDst2,dstStep
+        VEXT    dAbove2,dLeft,dAbove,#5                 ;// [ X|U3|U2|U1|U0|UL|L0|L1]   
+        
+        VHADD   dTmp, dAbove0, dAbove2
+        VRHADD  dTmp, dTmp, dAbove1                     ;// (a+2*b+c+2)>>2
+        
+        
+        VST1    dTmpU32[0],[pDst3]                      ;// Store pTmp[0],[1],[2],[3] @ pDst3
+        VEXT    dTmp,dTmp,dTmp,#1
+        VST1    dTmpU32[0],[pDst2]                      ;// Store pTmp[1],[2],[3],[4] @ pDst2
+        VEXT    dTmp,dTmp,dTmp,#1
+        VST1    dTmpU32[0],[pDst1]                      ;// Store pTmp[2],[3],[4],[5] @ pDst1
+        VEXT    dTmp,dTmp,dTmp,#1
+        VST1    dTmpU32[0],[pDst]                       ;// Store pTmp[3],[4],[5],[6] @ pDst
+        
+        B        ExitPredict4x4                         ;// Branch to exit code
+
+OMX_VC_4x4_VR
+
+        
+        ;// Load UL,U0,U1,U2,U3
+        VLD1    dAboveU32[0],[pSrcAbove]
+        VLD1    dAbove[7],[pSrcAboveLeft]               ;// [UL|X|X|X|U3|U2|U1|U0]
+        
+        ;// Load L0,L1,L2                               ;// dLeft0 = [L0|L2|X|X|X|X|X|X]
+                                                        ;// dLeft1 = [L1| X|X|X|X|X|X|X]    
+        VLD1    {dLeft0[7]},[pSrcLeft],leftStep         ;// pSrcLeft[0*leftStep]
+        VLD1    {dLeft1[7]},[pSrcLeft],leftStep         ;// pSrcLeft[1*leftStep]
+        VLD1    {dLeft0[6]},[pSrcLeft]                  ;// pSrcLeft[2*leftStep]
+        
+        
+        VEXT    dOdd2,dAbove,dAbove,#7                  ;// [ x x x U3 U2 U1 U0 UL ]
+        VEXT    dEven0,dLeft0,dOdd2,#6                  ;// [ x x x U1 U0 UL L0 L2 ]
+        VEXT    dEven1,dLeft1,dOdd2,#7                  ;// [ x x x U2 U1 U0 UL L1 ]
+        VEXT    dEven2,dLeft0,dAbove,#7                 ;// [ x x x U3 U2 U1 U0 L0 ]
+        VEXT    dOdd0,dLeft1,dAbove,#7                  ;// [ x x x U3 U2 U1 U0 L1 ]
+        VEXT    dOdd1,dLeft0,dOdd2,#7                   ;// [ x x x U2 U1 U0 UL L0 ]
+        
+        VHADD   dTmp1, dOdd0, dOdd2
+        VRHADD  dTmp1, dTmp1, dOdd1                     ;// Tmp[ x x x 9 7 5 3 1 ]
+        
+        VHADD   dTmp0, dEven0, dEven2
+        VRHADD  dTmp0, dTmp0, dEven1                    ;// Tmp[ x x x 8 6 4 2 0 ]
+        
+        
+        VEXT    dTmp3,dTmp1,dTmp1,#1                    ;// Tmp[ x x x x 9 7 5 3 ] 
+        ADD     pDstTmp, pDst, dstStep
+        ADD     dstep, dstStep, dstStep
+        VEXT    dTmp2,dTmp0,dTmp0,#1                    ;// Tmp[ x x x x 8 6 4 2 ]
+        
+        
+        VST1    dTmp3U32[0],[pDst],dstep                ;// Tmp[9],[7],[5],[3]
+        VST1    dTmp2U32[0],[pDstTmp],dstep             ;// Tmp[8],[6],[4],[2]
+        VST1    dTmp1U32[0],[pDst],dstep                ;// Tmp[7],[5],[3],[1]
+        VST1    dTmp0U32[0],[pDstTmp]                   ;// Tmp[6],[4],[2],[0]
+        
+        B        ExitPredict4x4                         ;// Branch to exit code
+        
+OMX_VC_4x4_HD
+        
+        
+        ;// Load U0,U1,U2,U3
+        VLD1    dAbove,[pSrcAbove]                      ;//dAboveLeftVal = [U7|U6|U5|U4|U3|U2|U1|U0]
+        
+        ;// Load UL,L0,L1,L2,L3                         ;// dLeft = [UL|L0|L1|L2|L3|X|X|X] 
+        VLD1    {dLeft[7]},[pSrcAboveLeft]   
+        ADD     pSrcTmp, pSrcLeft, leftStep
+        ADD     srcStep, leftStep, leftStep
+        
+        VLD1    {dLeft[6]},[pSrcLeft],srcStep           ;// pSrcLeft[0*leftStep]
+        VLD1    {dLeft[5]},[pSrcTmp],srcStep            ;// pSrcLeft[1*leftStep]
+        VLD1    {dLeft[4]},[pSrcLeft]                   ;// pSrcLeft[2*leftStep]
+        VLD1    {dLeft[3]},[pSrcTmp]                    ;// pSrcLeft[3*leftStep]
+        
+        VEXT    dAbove0,dLeft,dAbove,#3                 ;// [ U2|U1|U0|UL|L0|L1|L2|L3 ]  
+        VEXT    dAbove1,dLeft,dAbove,#2                 ;// [ U1|U0|UL|L0|L1|L2|L3|X ]   
+        VEXT    dAbove2,dLeft,dAbove,#1                 ;// [ U0|UL|L0|L1|L2|L3|X|X ]     
+        
+        VHADD   dTmp0, dAbove0, dAbove2
+        VRHADD  dTmp0, dTmp0, dAbove1                   ;// Tmp[ 0 | 1 | 2 | 4 | 6 | 8 | X | X ]
+        
+        
+        VRHADD  dTmp1, dAbove1, dAbove0                 ;// (a+b+1)>>1
+        VSHL    dTmp1U64,dTmp1U64,#24                   ;// Tmp[ 3|5| 7 |9 | X | X | X | X ]
+        
+        
+        VSHL    dTmpU64,dTmp0U64,#16                    ;// Tmp[ 2|4|6|8| X | X | X | X ]
+        VZIP    dTmp1,dTmp                              ;// dTmp = [ 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 ]
+        VEXT    dTmp0,dTmp0,dTmp0,#6                    ;// Tmp[  X| X| X| X| X| X| 0 | 1 ]
+        VEXT    dTmp1,dTmp,dTmp0,#2                     ;// Tmp[ 0 | 1 | 2 | 3 | 4 | 5 | 6 |7 ]
+       
+        ADD     pDstTmp, pDst, dstStep
+        ADD     dstep, dstStep, dstStep
+        
+        VST1    dTmp1U32[1],[pDst],dstep                ;// Store pTmp[0|1|2|3]
+        VST1    dTmpU32[1],[pDstTmp],dstep              ;// Store pTmp[2|3|4|5]
+        VST1    dTmp1U32[0],[pDst]                      ;// Store pTmp[4|5|6|7]
+        VST1    dTmpU32[0],[pDstTmp]                    ;// Store pTmp[6|7|8|9]
+        
+        B        ExitPredict4x4                         ;// Branch to exit code
+        
+OMX_VC_4x4_VL
+
+        
+        TST     availability, #OMX_VC_UPPER_RIGHT
+        BEQ     DiagVLUpperRightNotAvailable
+       
+        VLD1    dAbove0,[pSrcAbove]                      ;// [U7|U6|U5|U4|U3|U2|U1|U0] 
+        VEXT    dAbove1,dAbove0,dAbove0,#1               ;// [ X|U7|U6|U5|U4|U3|U2|U1]
+        VEXT    dAbove2,dAbove1,dAbove1,#1               ;// [ X| X|U7|U6|U5|U4|U3|U2]
+        
+        B       DiagVLPredict4x4Store         
+       
+DiagVLUpperRightNotAvailable
+        VLD1    dAboveU32[1],[pSrcAbove]                 ;// [U3|U2|U1|U0|-|-|-|-] 
+        VDUP    dU3, dAbove[7]                           ;// [U3 U3 U3 U3 U3 U3 U3 U3]
+
+        VEXT    dAbove0, dAbove, dU3, #4                 ;// [U3 U3 U3 U3 U3 U2 U1 U0]
+        VEXT    dAbove1, dAbove, dU3, #5                 ;// [U3 U3 U3 U3 U3 U3 U2 U1]
+        VEXT    dAbove2, dAbove, dU3, #6                 ;// [U3 U3 U3 U3 U3 U3 U3 U2]
+       
+DiagVLPredict4x4Store  
+        
+        VRHADD  dTmp0, dAbove1, dAbove0                 ;// (a+b+1)>>1
+                                                        ;// Tmp[ X| X| X| 8| 6| 4| 2| 0 ]
+        
+        VHADD   dTmp3, dAbove0, dAbove2
+        VRHADD  dTmp3, dTmp3, dAbove1                   ;// (a+2*b+c+2)>>2
+                                                        ;// Tmp[ X| X| X| 9| 7| 5| 3| 1 ]
+                                                         
+        VEXT    dTmp1,dTmp0,dTmp0,#1                    ;// Tmp[ X| X| X| X| 8| 6| 4| 2 ]
+        ADD     pDstTmp, pDst, dstStep
+        ADD     dstep, dstStep, dstStep
+        VEXT    dTmp2,dTmp3,dTmp1,#1                    ;// Tmp[ X| X| X| X| 9| 7| 5| 3 ]
+        
+        VST1    dTmp0U32[0],[pDst],dstep                ;// Tmp[6],[4],[2],[0]
+        VST1    dTmp3U32[0],[pDstTmp],dstep             ;// Tmp[7],[5],[3],[1]
+        VST1    dTmp1U32[0],[pDst]                      ;// Tmp[8],[6],[4],[2]
+        VST1    dTmp2U32[0],[pDstTmp]                   ;// Tmp[9],[7],[5],[3]
+        
+        B        ExitPredict4x4                         ;// Branch to exit code
+        
+OMX_VC_4x4_HU
+        ADD     pSrcTmp, pSrcLeft, leftStep
+        ADD     srcStep, leftStep, leftStep
+
+        ;// Load Left Edge                              ;// [L3|L2|L1|L0|X|X|X|X]
+        VLD1    {dLeft[4]},[pSrcLeft],srcStep           ;// pSrcLeft[0*leftStep]
+        VLD1    {dLeft[5]},[pSrcTmp],srcStep            ;// pSrcLeft[1*leftStep]
+        VLD1    {dLeft[6]},[pSrcLeft]                   ;// pSrcLeft[2*leftStep]
+        VLD1    {dLeft[7]},[pSrcTmp]                    ;// pSrcLeft[3*leftStep]
+        
+        VDUP    dL3,dLeft[7]                            ;// [L3|L3|L3|L3|L3|L3|L3|L3]
+        
+        VEXT    dLeftHU0,dLeft,dL3,#4                   ;// [L3|L3|L3|L3|L3|L2|L1|L0]
+        VEXT    dLeftHU1,dLeft,dL3,#5                   ;// [L3|L3|L3|L3|L3|L3|L2|L1]
+        VEXT    dLeftHU2,dLeft,dL3,#6                   ;// [L3|L3|L3|L3|L3|L3|L3|L2]
+        
+        VHADD   dTmp0, dLeftHU0, dLeftHU2
+        VRHADD  dTmp0, dTmp0, dLeftHU1                  ;// Tmp[ L3 | L3 | L3 | L3 | L3 | 5 | 3 | 1 ]
+        
+        VRHADD  dTmp1, dLeftHU1, dLeftHU0               ;// (a+b+1)>>1 
+                                                        ;//  Tmp[ L3 | L3 | L3 | L3 | L3 | 4 | 2 | 0 ]
+                                                      
+        VZIP    dTmp1,dTmp0                             ;// dTmp1 = Tmp[7| 6| 5| 4| 3| 2| 1| 0]  
+                                                        ;// dTmp0 = [L3|L3|L3|L3|L3|L3|L3|L3]
+                                                                                                                            
+        
+        VST1    dTmp1U32[0],[pDst],dstStep              ;// [3|2|1|0] 
+        VEXT    dTmp1,dTmp1,dTmp1,#2
+        VST1    dTmp1U32[0],[pDst],dstStep              ;// [5|4|3|2] 
+        VEXT    dTmp1,dTmp1,dTmp1,#2
+        VST1    dTmp1U32[0],[pDst],dstStep              ;// [7|6|5|4]  
+        VST1    dTmp0U32[0],[pDst]                      ;// [9|8|7|6] 
+        
+        
+ExitPredict4x4
+        
+        MOV      return,  #OMX_Sts_NoErr
+        M_END
+
+        ENDIF ;// CortexA8
+        
+        END
+;//-----------------------------------------------------------------------------------------------
+;// omxVCM4P10_PredictIntra_4x4 ends
+;//-----------------------------------------------------------------------------------------------
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_TransformDequantChromaDCFromPair_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_TransformDequantChromaDCFromPair_s.s
new file mode 100755
index 0000000..e394339
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_TransformDequantChromaDCFromPair_s.s
@@ -0,0 +1,140 @@
+;//
+;// 
+;// File Name:  omxVCM4P10_TransformDequantChromaDCFromPair_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   12290
+;// Date:       Wednesday, April 9, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+        
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+        
+        IMPORT armVCM4P10_QPDivTable
+        IMPORT armVCM4P10_VMatrixQPModTable
+            
+        M_VARIANTS CortexA8
+    
+
+    
+    
+    IF CortexA8
+
+;// ARM Registers
+;//--------------------------------------
+;// Declare input registers
+;//--------------------------------------
+ppSrc       RN 0
+pDst        RN 1
+QP          RN 2
+
+;//--------------------------------
+;// Scratch variable for Unpack2x2 
+;//--------------------------------
+pSrc        RN 9
+Value       RN 4
+Value2      RN 5
+Flag        RN 6
+strOffset   RN 7
+cstOffset   RN 8
+
+;//--------------------------------
+;// Scratch variable
+;//--------------------------------
+r0w0        RN  3
+r0w1        RN  4
+
+c0w0        RN  5
+c1w0        RN  6
+
+return      RN  0
+pQPDivTable RN  5
+pQPModTable    RN  6
+Shift        RN  9
+Scale        RN  2
+
+
+
+;// Neon Registers
+
+dZero       DN  D0.U16
+dInvTrCoeff DN  D0.S16
+dScale      DN  D1.S16
+qDqntCoeff  QN  Q1.S32
+dDqntCoeff  DN  D2.S16
+
+
+        ;// Write function header
+        M_START omxVCM4P10_TransformDequantChromaDCFromPair, r9
+        
+        LDR     pSrc, [ppSrc]                        ;// Load pSrc
+        VMOV    dZero, #0
+        MOV     cstOffset, #31                       ;// To be used in the loop, to compute offset
+        
+        ;//-----------------------------------------------------------------------
+        ;// Firstly, fill all the coefficient values on the <pDst> buffer by zero
+        ;//-----------------------------------------------------------------------
+        
+        VST1    dZero,[pDst]                         ;// pDst[0]  = pDst[1]  = pDst[2]  = pDst[3]  = 0   
+        LDRB     Flag,  [pSrc], #1                   ;// Preload <Flag> before <unpackLoop>
+
+
+unpackLoop
+        TST      Flag,  #0x10                        ;// Computing (Flag & 0x10)
+        LDRSBNE  Value2,[pSrc,#1]                  
+        LDRBNE   Value, [pSrc], #2                   ;// Load byte wise to avoid unaligned access
+        AND      strOffset, cstOffset, Flag, LSL #1  ;// strOffset = (Flag & 15) < 1;
+        LDRSBEQ  Value, [pSrc], #1                   ;// Value = (OMX_U8)  *pSrc++
+        ORRNE    Value,Value,Value2, LSL #8          ;// Value = (OMX_U16) *pSrc++
+        
+        TST      Flag,  #0x20                        ;// Computing (Flag & 0x20) to check, if we're done
+        LDRBEQ   Flag,  [pSrc], #1                   ;// Flag  = (OMX_U8) *pSrc++, for next iteration
+        STRH     Value, [pDst, strOffset]            ;// Store <Value> at offset <strOffset>
+        BEQ      unpackLoop                          ;// Branch to the loop beginning
+        
+        ;//--------------------------------------------------
+        ;//InvTransformDC2x2: Inlined (Implemented in ARM V6)
+        ;//--------------------------------------------------
+        
+        LDMIA    pDst, {r0w0, r0w1}                  ;// r0w0 = |c1|c0| & r0w1 = |c3|c2|
+
+        STR      pSrc, [ppSrc]                       ;// Update the bitstream pointer
+        
+        LDR      pQPDivTable, =armVCM4P10_QPDivTable ;// QP Division look-up-table base pointer
+        LDR      pQPModTable, =armVCM4P10_VMatrixQPModTable ;// QP Modulo look-up-table base pointer
+        
+        SADDSUBX r0w0, r0w0,  r0w0                   ;// [ c00+c01, c00-c01 ]
+        SADDSUBX r0w1, r0w1,  r0w1                   ;// [ c10+c11, c10-c11 ]
+        
+        LDRSB    Shift, [pQPDivTable, QP]            ;// Shift = pQPDivTable[QP]
+        LDRSB    Scale, [pQPModTable, QP]            ;// Scale = pQPModTable[QP]
+        
+        SADD16   c0w0, r0w0, r0w1                    ;// [ d00+d10, d01+d11 ]
+        SSUB16   c1w0, r0w0, r0w1                    ;// [ d00-d10, d01-d11 ]
+        
+        ;//-------------------------------------------------
+        ;//DequantChromaDC2x2: Inlined (Neon Implementation)
+        ;//-------------------------------------------------
+        
+        LSL      Scale, Scale, Shift                 ;// Scale = Scale << Shift
+        VMOV     dInvTrCoeff, c0w0, c1w0  
+        VREV32   dInvTrCoeff,dInvTrCoeff  
+        VDUP     dScale,Scale 
+        
+        VMULL    qDqntCoeff,dInvTrCoeff,dScale
+        VSHRN    dDqntCoeff,qDqntCoeff,#1
+        
+        
+        VST1     dDqntCoeff,[pDst]                   ;// Storing all the coefficients at once
+        
+        MOV      return, #OMX_Sts_NoErr
+        M_END
+        
+    ENDIF ;// CortexA8
+    
+    
+    END
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_TransformDequantLumaDCFromPair_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_TransformDequantLumaDCFromPair_s.s
new file mode 100755
index 0000000..2529959
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_TransformDequantLumaDCFromPair_s.s
@@ -0,0 +1,264 @@
+;//
+;// 
+;// File Name:  omxVCM4P10_TransformDequantLumaDCFromPair_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   12290
+;// Date:       Wednesday, April 9, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+;// Description:
+;// H.264 inverse quantize and transform module
+;// 
+;// 
+
+;// Include standard headers
+
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+        
+;// Import/Export symbols required from/to other files
+;// (For example tables)
+        
+        IMPORT armVCM4P10_UnpackBlock4x4 
+        IMPORT armVCM4P10_QPDivTable
+        IMPORT armVCM4P10_VMatrixQPModTable
+        
+        M_VARIANTS CortexA8
+
+;// Set debugging level        
+;//DEBUG_ON    SETL {TRUE}
+
+
+;// Static Function: armVCM4P10_InvTransformDequantLumaDC4x4
+    
+
+;// Guarding implementation by the processor name
+    
+    
+
+;// Static Function: armVCM4P10_InvTransformDequantLumaDC4x4
+
+;// Guarding implementation by the processor name
+    
+    IF  CortexA8
+    
+;//Input Registers
+pData               RN  0
+QP                  RN  1    
+
+
+;//Local Scratch Registers
+
+;// ARM Registers
+
+pQPDivTable         RN  2
+pQPModTable         RN  3
+Shift               RN  4
+Scale               RN  5
+
+;// NEON Registers
+
+;// Packed Input pixels
+dIn0                DN  D0.S16
+dIn1                DN  D1.S16
+dIn2                DN  D2.S16
+dIn3                DN  D3.S16   
+
+;// Intermediate calculations
+dRowSum1            DN  D4.S16
+dRowSum2            DN  D5.S16
+dRowDiff1           DN  D6.S16
+dRowDiff2           DN  D7.S16
+
+;// Row operated pixels
+dRowOp0             DN  D0.S16
+dRowOp1                DN  D1.S16
+dRowOp2                DN  D2.S16
+dRowOp3                DN  D3.S16
+qRowOp01            QN  Q0.32
+qRowOp23            QN  Q1.32
+
+;// Intermediate calculations
+dColSum1            DN  D4.S16
+dColSum2            DN  D5.S16
+dColDiff1           DN  D6.S16
+dColDiff2           DN  D7.S16
+
+;// Coloumn operated pixels
+dColOp0             DN  D0.S16
+dColOp1                DN  D1.S16
+dColOp2                DN  D2.S16
+dColOp3                DN  D3.S16
+
+;// Temporary scratch varaibles
+
+dScale              DN  D5.S16
+qRound0             QN  Q3.S32
+qRound1             QN  Q4.S32
+qRound2             QN  Q5.S32
+qRound3             QN  Q6.S32
+
+;// InvTransformed and Dequantized pixels
+dOut0               DN  D0.S16
+dOut1                DN  D1.S16
+dOut2                DN  D2.S16
+dOut3                DN  D3.S16
+
+       
+    ;// Allocate stack memory required by the function
+        
+
+    ;// Write function header
+    M_START armVCM4P10_InvTransformDequantLumaDC4x4,r5,d13
+    
+    ;******************************************************************
+    ;// The strategy used in implementing the transform is as follows:*
+    ;// Load the 4x4 block into 4 D-registers                         *  
+    ;// Transpose the 4x4 matrix                                      *  
+    ;// Perform the row operations (on columns) using SIMD            *  
+    ;// Transpose the 4x4 result matrix                               *  
+    ;// Perform the coloumn operations                                *
+    ;******************************************************************
+
+        ;// Load all the 4x4 pixels in Transposed form
+        
+        VLD4    {dIn0,dIn1,dIn2,dIn3},[pData]
+        LDR     pQPDivTable, =armVCM4P10_QPDivTable        ;// QP Division look-up-table base pointer
+        LDR     pQPModTable, =armVCM4P10_VMatrixQPModTable ;// QP Modulo look-up-table base pointer
+        
+        ;**************************************** 
+        ;// Row Operations (Performed on columns)
+        ;**************************************** 
+        ;// Scale factor calculation is done using ARM instructions
+        ;// Interleaved with NEON instructions inorder to Dual issue
+        
+        VADD    dRowSum1,dIn0,dIn1
+        VADD    dRowSum2,dIn2,dIn3
+        VSUB    dRowDiff1,dIn0,dIn1
+        LDRSB   Shift, [pQPDivTable, QP]               ;// ARM CODE: Shift = pQPDivTable[QP]
+        VSUB    dRowDiff2,dIn2,dIn3
+        LDRSB   Scale, [pQPModTable, QP]               ;// ARM CODE: Scale = pQPModTable[QP] 
+        VADD    dRowOp0,dRowSum1,dRowSum2
+        VSUB    dRowOp1,dRowSum1,dRowSum2
+        VSUB    dRowOp2,dRowDiff1,dRowDiff2
+        LSL     Scale, Scale, Shift                    ;// ARM CODE: Scale = Scale << Shift
+        VADD    dRowOp3,dRowDiff1,dRowDiff2
+        
+        ;****************************************
+        ;// Transpose the resultant matrix
+        ;****************************************
+        
+        VTRN    dRowOp0,dRowOp1
+        VTRN    dRowOp2,dRowOp3
+        VTRN    qRowOp01,qRowOp23 
+        
+        ;**************************************** 
+        ;// Coloumn Operations 
+        ;**************************************** 
+        
+        VADD    dColSum1,dRowOp0,dRowOp1
+        VADD    dColSum2,dRowOp2,dRowOp3
+        VSUB    dColDiff1,dRowOp0,dRowOp1
+        VSUB    dColDiff2,dRowOp2,dRowOp3
+        VADD    dColOp0,dColSum1,dColSum2
+        VSUB    dColOp1,dColSum1,dColSum2
+        VSUB    dColOp2,dColDiff1,dColDiff2
+        VADD    dColOp3,dColDiff1,dColDiff2
+        
+        ;//----------------------------------------------------------------------
+        ;//
+        ;// <Dequantize> improves on the c-reference code
+        ;// Both the  cases i.e., Shift>=0 and Shift<0 cases are covered together
+        ;// We do not subtract 2 from Shift as in C reference, instead perform a
+        ;// Scale << Shift once in the beginning and do a right shift by a 
+        ;// constant 2 after the Multiplication. The value of Round would be 2 
+        ;// 
+        ;// By doing this we aviod the Branches required and also 
+        ;// reduce the code size substantially
+        ;// 
+        ;//----------------------------------------------------------------------
+        
+        
+        VDUP    dScale, Scale                            ;// ARM -> NEON  copy 'scale' to vector
+               
+                
+        VMOV    qRound0,#2                               ;// Set the Round Value 
+        VMOV    qRound1,#2
+        VMOV    qRound2,#2
+        VMOV    qRound3,#2
+        
+        VMLAL   qRound0,dColOp0,dScale                   ;// pDst[i] * Scale + Round 
+        VMLAL   qRound1,dColOp1,dScale
+        VMLAL   qRound2,dColOp2,dScale
+        VMLAL   qRound3,dColOp3,dScale
+        
+        VSHRN   dOut0,qRound0,#2                          ;// Right shift by 2 & (OMX_S16)Value
+        VSHRN   dOut1,qRound1,#2
+        VSHRN   dOut2,qRound2,#2
+        VSHRN   dOut3,qRound3,#2
+        
+        ;***************************
+        ;// Store all the 4x4 pixels
+        ;***************************
+        
+        VST1  {dOut0,dOut1,dOut2,dOut3}, [pData]
+
+        
+        ;// Set return value
+        
+        ;// Write function tail
+        M_END        
+        
+    ENDIF                                                           ;//CORTEXA8   
+        
+
+
+;// Function: omxVCM4P10_TransformDequantLumaDCFromPair
+    
+;//Input Registers
+ppSrc               RN  0
+pDst                RN  1
+QPR2                RN  2
+
+;//Output Registers
+result              RN  0
+
+;//Local Scratch Registers
+pDstR4              RN  4
+pDstR0              RN  0
+QPR1                RN  1
+QPR5                RN  5
+
+;// Guarding implementation by the processor name
+    
+    IF CortexA8
+       
+    ;// Allocate stack memory required by the function
+        
+
+    ;// Write function header
+        M_START omxVCM4P10_TransformDequantLumaDCFromPair,r5
+        
+        MOV     pDstR4,pDst                         ;// Saving register r1
+        MOV     QPR5,QPR2                           ;// Saving register r2
+        BL      armVCM4P10_UnpackBlock4x4
+        
+        MOV     pDstR0,pDstR4                       ;// Setting up register r0
+        MOV     QPR1,QPR5                           ;// Setting up register r1
+        BL      armVCM4P10_InvTransformDequantLumaDC4x4
+                               
+       
+        ;// Set return value
+        MOV     result,#OMX_Sts_NoErr        
+       
+        ;// Write function tail
+        M_END
+        
+            
+    ENDIF                                                           ;//ARM1136JS  
+    
+
+    END
\ No newline at end of file
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_Average_4x_Align_unsafe_s.S b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_Average_4x_Align_unsafe_s.S
new file mode 100644
index 0000000..aca2df4
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_Average_4x_Align_unsafe_s.S
@@ -0,0 +1,134 @@
+/*
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ *
+ */
+
+    .eabi_attribute 24, 1
+    .eabi_attribute 25, 1
+
+    .arm
+    .fpu neon
+    .text
+
+    .global armVCM4P10_Average_4x4_Align0_unsafe
+    .func   armVCM4P10_Average_4x4_Align0_unsafe
+armVCM4P10_Average_4x4_Align0_unsafe:
+    PUSH     {r4-r6,lr}
+    LDR      r7, =0x80808080
+    LDR      r12,[r2,#0]
+    LDR      r10,[r0],r1
+    LDR      lr,[r2,r3]
+    LDR      r11,[r0],r1
+    MVN      r12,r12
+    MVN      lr,lr
+    UHSUB8   r5,r10,r12
+    UHSUB8   r4,r11,lr
+    EOR      r5,r5,r7
+    STR      r5,[r2],r3
+    EOR      r4,r4,r7
+    STR      r4,[r2],r3
+    LDR      r10,[r0],r1
+    LDR      r12,[r2,#0]
+    LDR      r11,[r0],r1
+    LDR      lr,[r2,r3]
+    MVN      r12,r12
+    UHSUB8   r5,r10,r12
+    MVN      lr,lr
+    UHSUB8   r4,r11,lr
+    EOR      r5,r5,r7
+    STR      r5,[r2],r3
+    EOR      r4,r4,r7
+    STR      r4,[r2],r3
+    POP      {r4-r6,pc}
+    .endfunc
+
+    .global armVCM4P10_Average_4x4_Align2_unsafe
+    .func   armVCM4P10_Average_4x4_Align2_unsafe
+armVCM4P10_Average_4x4_Align2_unsafe:
+    PUSH     {r4-r6,lr}
+    LDR      r7, =0x80808080
+    LDR      r4,[r0,#4]
+    LDR      r10,[r0],r1
+    LDR      r12,[r2,#0]
+    LDR      lr,[r2,r3]
+    LDR      r5,[r0,#4]
+    LDR      r11,[r0],r1
+    MVN      r12,r12
+    MVN      lr,lr
+    LSR      r10,r10,#16
+    ORR      r10,r10,r4,LSL #16
+    LSR      r11,r11,#16
+    ORR      r11,r11,r5,LSL #16
+    UHSUB8   r5,r10,r12
+    UHSUB8   r4,r11,lr
+    EOR      r5,r5,r7
+    STR      r5,[r2],r3
+    EOR      r4,r4,r7
+    STR      r4,[r2],r3
+    LDR      r4,[r0,#4]
+    LDR      r10,[r0],r1
+    LDR      r12,[r2,#0]
+    LDR      lr,[r2,r3]
+    LDR      r5,[r0,#4]
+    LDR      r11,[r0],r1
+    MVN      r12,r12
+    MVN      lr,lr
+    LSR      r10,r10,#16
+    ORR      r10,r10,r4,LSL #16
+    LSR      r11,r11,#16
+    ORR      r11,r11,r5,LSL #16
+    UHSUB8   r5,r10,r12
+    UHSUB8   r4,r11,lr
+    EOR      r5,r5,r7
+    STR      r5,[r2],r3
+    EOR      r4,r4,r7
+    STR      r4,[r2],r3
+    POP      {r4-r6,pc}
+    .endfunc
+
+    .global armVCM4P10_Average_4x4_Align3_unsafe
+    .func   armVCM4P10_Average_4x4_Align3_unsafe
+armVCM4P10_Average_4x4_Align3_unsafe:
+    PUSH     {r4-r6,lr}
+    LDR      r7, =0x80808080
+    LDR      r4,[r0,#4]
+    LDR      r10,[r0],r1
+    LDR      r12,[r2,#0]
+    LDR      lr,[r2,r3]
+    LDR      r5,[r0,#4]
+    LDR      r11,[r0],r1
+    MVN      r12,r12
+    MVN      lr,lr
+    LSR      r10,r10,#24
+    ORR      r10,r10,r4,LSL #8
+    LSR      r11,r11,#24
+    ORR      r11,r11,r5,LSL #8
+    UHSUB8   r5,r10,r12
+    UHSUB8   r4,r11,lr
+    EOR      r5,r5,r7
+    STR      r5,[r2],r3
+    EOR      r4,r4,r7
+    STR      r4,[r2],r3
+    LDR      r4,[r0,#4]
+    LDR      r10,[r0],r1
+    LDR      r12,[r2,#0]
+    LDR      lr,[r2,r3]
+    LDR      r5,[r0,#4]
+    LDR      r11,[r0],r1
+    MVN      r12,r12
+    MVN      lr,lr
+    LSR      r10,r10,#24
+    ORR      r10,r10,r4,LSL #8
+    LSR      r11,r11,#24
+    ORR      r11,r11,r5,LSL #8
+    UHSUB8   r5,r10,r12
+    UHSUB8   r4,r11,lr
+    EOR      r5,r5,r7
+    STR      r5,[r2],r3
+    EOR      r4,r4,r7
+    STR      r4,[r2],r3
+    POP      {r4-r6,pc}
+    .endfunc
+
+    .end
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_DeblockingChroma_unsafe_s.S b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_DeblockingChroma_unsafe_s.S
new file mode 100644
index 0000000..b9ee221
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_DeblockingChroma_unsafe_s.S
@@ -0,0 +1,54 @@
+/*
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ *
+ */
+
+    .eabi_attribute 24, 1
+    .eabi_attribute 25, 1
+
+    .arm
+    .fpu neon
+    .text
+
+    .global armVCM4P10_DeblockingChromabSLT4_unsafe
+    .func   armVCM4P10_DeblockingChromabSLT4_unsafe
+armVCM4P10_DeblockingChromabSLT4_unsafe:
+    VLD1.32  {d18[0]},[r5]!
+    VSUBL.U8 q11,d5,d9
+    VMOV     d28,d18
+    VSUBL.U8 q10,d8,d4
+    VSHR.S16 q11,q11,#2
+    VZIP.8   d18,d28
+    VBIF     d18,d14,d16
+    VRHADD.S16 q10,q11,q10
+    VADD.I8  d31,d18,d15
+    VQMOVN.S16 d20,q10
+    VLD1.8   {d0[]},[r2]
+    VMIN.S8  d20,d20,d31
+    VNEG.S8  d31,d31
+    VLD1.8   {d2[]},[r3]
+    VMAX.S8  d20,d20,d31
+    VMOVL.U8 q14,d4
+    VMOVL.U8 q12,d8
+    VADDW.S8 q14,q14,d20
+    VSUBW.S8 q12,q12,d20
+    VQMOVUN.S16 d29,q14
+    VQMOVUN.S16 d24,q12
+    BX       lr
+    .endfunc
+
+    .global armVCM4P10_DeblockingChromabSGE4_unsafe
+    .func   armVCM4P10_DeblockingChromabSGE4_unsafe
+armVCM4P10_DeblockingChromabSGE4_unsafe:
+    VHADD.U8 d13,d4,d9
+    VHADD.U8 d31,d8,d5
+    VLD1.8   {d0[]},[r2]
+    ADD      r5,r5,#4
+    VLD1.8   {d2[]},[r3]
+    VRHADD.U8 d13,d13,d5
+    VRHADD.U8 d31,d31,d9
+    BX       lr
+    .endfunc
+
+    .end
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_DeblockingLuma_unsafe_s.S b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_DeblockingLuma_unsafe_s.S
new file mode 100644
index 0000000..47f3d44
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_DeblockingLuma_unsafe_s.S
@@ -0,0 +1,102 @@
+/*
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ *
+ */
+
+    .eabi_attribute 24, 1
+    .eabi_attribute 25, 1
+
+    .arm
+    .fpu neon
+    .text
+
+    .global armVCM4P10_DeblockingLumabSLT4_unsafe
+    .func   armVCM4P10_DeblockingLumabSLT4_unsafe
+armVCM4P10_DeblockingLumabSLT4_unsafe:
+    VSUBL.U8 q11,d5,d9
+    VLD1.8   {d18[]},[r5]!
+    VSUBL.U8 q10,d8,d4
+    VLD1.8   {d19[]},[r5]!
+    VSHR.S16 q11,q11,#2
+    VEXT.8   d18,d18,d19,#4
+    VAND     d19,d17,d15
+    VBIF     d18,d14,d16
+    VRHADD.S16 q10,q11,q10
+    VRHADD.U8 d24,d4,d8
+    VADD.I8  d31,d18,d19
+    VAND     d19,d12,d15
+    VQADD.U8 d23,d5,d18
+    VQMOVN.S16 d20,q10
+    VADD.I8  d31,d31,d19
+    VQSUB.U8 d22,d5,d18
+    VQADD.U8 d19,d9,d18
+    VHADD.U8 d26,d24,d6
+    VMIN.S8  d20,d20,d31
+    VNEG.S8  d31,d31
+    VQSUB.U8 d21,d9,d18
+    VHADD.U8 d27,d24,d10
+    VMAX.U8  d30,d26,d22
+    VMAX.S8  d20,d20,d31
+    VMOVL.U8 q14,d4
+    VMOVL.U8 q12,d8
+    VADDW.S8 q14,q14,d20
+    VSUBW.S8 q12,q12,d20
+    VQMOVUN.S16 d29,q14
+    VQMOVUN.S16 d24,q12
+    VMAX.U8  d25,d27,d21
+    VMIN.U8  d30,d30,d23
+    VMIN.U8  d25,d25,d19
+    VBIF     d29,d4,d16
+    VBIF     d30,d5,d17
+    VBIF     d24,d8,d16
+    VBIF     d25,d9,d12
+    BX       lr
+    .endfunc
+
+    .global armVCM4P10_DeblockingLumabSGE4_unsafe
+    .func   armVCM4P10_DeblockingLumabSGE4_unsafe
+armVCM4P10_DeblockingLumabSGE4_unsafe:
+    VSHR.U8  d19,d0,#2
+    VADD.I8  d19,d19,d15
+    VADDL.U8 q10,d8,d4
+    VADD.I8  d19,d19,d15
+    VADDL.U8 q11,d6,d9
+    VADDW.U8 q12,q10,d5
+    VCGT.U8  d19,d19,d13
+    VSHR.U16 q11,q11,#1
+    VHADD.U16 q11,q12,q11
+    VADDW.U8 q12,q12,d6
+    VADDL.U8 q13,d7,d6
+    VAND     d17,d17,d19
+    VHADD.U8 d28,d4,d9
+    VSRA.U16 q13,q12,#1
+    VAND     d12,d12,d19
+    VQRSHRN.U16 d29,q11,#1
+    VRHADD.U8 d28,d28,d5
+    VQRSHRN.U16 d30,q12,#2
+    VADDL.U8 q11,d10,d5
+    VADDW.U8 q12,q10,d9
+    VBIF     d29,d28,d17
+    VQRSHRN.U16 d31,q13,#2
+    VADDL.U8 q13,d11,d10
+    VSHR.U16 q11,q11,#1
+    VHADD.U16 q11,q12,q11
+    VADDW.U8 q12,q12,d10
+    VHADD.U8 d28,d8,d5
+    VBIF     d29,d4,d16
+    VBIF     d30,d5,d17
+    VSRA.U16 q13,q12,#1
+    VQRSHRN.U16 d25,q12,#2
+    VQRSHRN.U16 d24,q11,#1
+    VRHADD.U8 d22,d28,d9
+    VBIF     d25,d9,d12
+    VBIF     d31,d6,d17
+    VBIF     d24,d22,d12
+    VQRSHRN.U16 d28,q13,#2
+    VBIF     d24,d8,d16
+    VBIF     d28,d10,d12
+    BX       lr
+    .endfunc
+
+    .end
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_DecodeCoeffsToPair_s.S b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_DecodeCoeffsToPair_s.S
new file mode 100644
index 0000000..e68bd8e
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_DecodeCoeffsToPair_s.S
@@ -0,0 +1,272 @@
+/*
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ *
+ */
+
+    .eabi_attribute 24, 1
+    .eabi_attribute 25, 1
+
+    .arm
+    .fpu neon
+    .text
+
+    .global armVCM4P10_DecodeCoeffsToPair
+    .func   armVCM4P10_DecodeCoeffsToPair
+armVCM4P10_DecodeCoeffsToPair:
+    PUSH     {r4-r12,lr}
+    SUB      sp,sp,#0x40
+    LDR      r10,[r0,#0]
+    LDR      r12,[r1,#0]
+    LDR      r6, =armVCM4P10_CAVLCCoeffTokenTables
+    LDR      r4,[sp,#0x68]
+    LDRB     r9,[r10,#2]
+    LDRB     r8,[r10,#1]
+    LDRB     r11,[r10],#3
+    ADD      r12,r12,#8
+    LDR      r6,[r6,r4,LSL #2]
+    ORR      r9,r9,r8,LSL #8
+    ORR      r11,r9,r11,LSL #16
+    LSLS     r8,r11,r12
+    MOVS     r7,#0x1e
+    AND      r7,r7,r8,LSR #27
+    SUBS     r12,r12,#8
+L0x44:
+    BCC      L1
+    LDRB     r8,[r10],#1
+L1:
+    LDRH     r7,[r6,r7]
+    ADDCC    r12,r12,#8
+    ADD      r12,r12,#4
+    ORRCS    r11,r8,r11,LSL #8
+    LSRS     r8,r7,#1
+    BCS      L0x74
+    LSLS     r8,r11,r12
+    SUBS     r12,r12,#0xa
+    ADD      r7,r7,r8,LSR #29
+    BIC      r7,r7,#1
+    B        L0x44
+L0x74:
+    SUB      r12,r12,r7,LSR #13
+    BIC      r7,r8,#0xf000
+    LSRS     r5,r7,#2
+    STRB     r5,[r2,#0]
+    BEQ      L0x344
+    CMP      r7,#0x44
+    BGE      L0x33c
+    STR      r0,[sp,#0]
+    STR      r1,[sp,#4]
+    STR      r3,[sp,#8]
+    ANDS     r1,r7,#3
+    ADD      r2,sp,#0xc
+    BEQ      L0xd8
+    MOV      r0,r1
+L0xac:
+    LSLS     r7,r11,r12
+    SUBS     r12,r12,#7
+    BCC      L2
+    LDRB     r8,[r10],#1
+L2:
+    ADDCC    r12,r12,#8
+    LSR      r7,r7,#31
+    ORRCS    r11,r8,r11,LSL #8
+    SUBS     r0,r0,#1
+    MOV      r8,#1
+    SUB      r8,r8,r7,LSL #1
+    STRH     r8,[r2],#2
+    BGT      L0xac
+L0xd8:
+    SUBS     r0,r5,r1
+    BEQ      L0x1b8
+    MOV      r4,#1
+    CMP      r5,#0xa
+    MOVLE    r4,#0
+    CMP      r1,#3
+    MOVLT    r1,#4
+    MOVGE    r1,#2
+    MOVGE    r4,#0
+L0xfc:
+    LSLS     r7,r11,r12
+    CLZ      r7,r7
+    ADD      r12,r12,r7
+    SUBS     r12,r12,#7
+    BCC      L3
+    LDRB     r8,[r10],#1
+    ORR      r11,r8,r11,LSL #8
+    SUBS     r12,r12,#8
+    BCC      L3
+    LDRB     r8,[r10],#1
+L3:
+    ADDCC    r12,r12,#8
+    ORRCS    r11,r8,r11,LSL #8
+    CMP      r7,#0x10
+    BGE      L0x33c
+    MOVS     lr,r4
+    TEQEQ    r7,#0xe
+    MOVEQ    lr,#4
+    TEQ      r7,#0xf
+    MOVEQ    lr,#0xc
+    TEQEQ    r4,#0
+    ADDEQ    r7,r7,#0xf
+    TEQ      lr,#0
+    BEQ      L0x184
+    LSL      r3,r11,r12
+    ADD      r12,r12,lr
+    SUBS     r12,r12,#8
+    RSB      r9,lr,#0x20
+    BCC      L4
+    LDRB     r8,[r10],#1
+    ORR      r11,r8,r11,LSL #8
+    SUBS     r12,r12,#8
+    BCC      L4
+    LDRB     r8,[r10],#1
+L4:
+    ADDCC    r12,r12,#8
+    LSR      r3,r3,r9
+    ORRCS    r11,r8,r11,LSL #8
+    LSL      r7,r7,r4
+    ADD      r7,r3,r7
+L0x184:
+    ADD      r7,r7,r1
+    MOV      r1,#2
+    LSRS     r8,r7,#1
+    RSBCS    r8,r8,#0
+    STRH     r8,[r2],#2
+    LDR      r9, =armVCM4P10_SuffixToLevel
+    LDRSB    r8,[r9,r4]
+    TEQ      r4,#0
+    MOVEQ    r4,#1
+    CMP      r7,r8
+    ADDCS    r4,r4,#1
+    SUBS     r0,r0,#1
+    BGT      L0xfc
+L0x1b8:
+    LDR      r8,[sp,#0x6c]
+    SUB      r0,r5,#1
+    SUBS     r1,r8,r5
+    ADD      r4,sp,#0x2c
+    MOV      lr,r5
+    SUB      lr,lr,#1
+    BEQ      L0x2b0
+    TEQ      r8,#4
+    LDREQ    r6, =(armVCM4P10_CAVLCTotalZeros2x2Tables - 4)
+    LDRNE    r6, =(armVCM4P10_CAVLCTotalZeroTables - 4)
+    LDR      r6,[r6,r5,LSL #2]
+    LSLS     r8,r11,r12
+    MOVS     r7,#0x1e
+    AND      r7,r7,r8,LSR #27
+    SUBS     r12,r12,#8
+L0x1f4:
+    BCC      L5
+    LDRB     r8,[r10],#1
+L5:
+    LDRH     r7,[r6,r7]
+    ADDCC    r12,r12,#8
+    ADD      r12,r12,#4
+    ORRCS    r11,r8,r11,LSL #8
+    LSRS     r8,r7,#1
+    BCS      L0x224
+    LSLS     r8,r11,r12
+    SUBS     r12,r12,#0xa
+    ADD      r7,r7,r8,LSR #29
+    BIC      r7,r7,#1
+    B        L0x1f4
+L0x224:
+    SUB      r12,r12,r7,LSR #13
+    BIC      r7,r8,#0xf000
+    CMP      r7,#0x10
+    BGE      L0x33c
+    LDR      r3, =(armVCM4P10_CAVLCRunBeforeTables - 4)
+    ADD      r4,sp,#0x2c
+    MOVS     r1,r7
+    ADD      lr,lr,r1
+    BEQ      L0x2b0
+L0x248:
+    SUBS     r0,r0,#1
+    LDR      r6,[r3,r1,LSL #2]
+    BLT      L0x2bc
+    LSLS     r8,r11,r12
+    MOVS     r7,#0xe
+    AND      r7,r7,r8,LSR #28
+    SUBS     r12,r12,#8
+L0x264:
+    BCC      L6
+    LDRB     r8,[r10],#1
+L6:
+    LDRH     r7,[r6,r7]
+    ADDCC    r12,r12,#8
+    ADD      r12,r12,#3
+    ORRCS    r11,r8,r11,LSL #8
+    LSRS     r8,r7,#1
+    BCS      L0x294
+    LSLS     r8,r11,r12
+    SUBS     r12,r12,#9
+    ADD      r7,r7,r8,LSR #29
+    BIC      r7,r7,#1
+    B        L0x264
+L0x294:
+    SUB      r12,r12,r7,LSR #13
+    BIC      r7,r8,#0xf000
+    CMP      r7,#0xf
+    BGE      L0x33c
+    SUBS     r1,r1,r7
+    STRB     r7,[r4],#1
+    BGT      L0x248
+L0x2b0:
+    SUBS     r0,r0,#1
+    BLT      L7
+    STRB     r1,[r4],#1
+L7:
+    BGT      L0x2b0
+L0x2bc:
+    STRB     r1,[r4],#1
+    LDR      r8,[sp,#0x6c]
+    TEQ      r8,#0xf
+    ADDEQ    lr,lr,#1
+    SUB      r4,r4,r5
+    SUB      r2,r2,r5
+    SUB      r2,r2,r5
+    LDR      r3,[sp,#8]
+    LDR      r0,[r3,#0]
+    TEQ      r8,#4
+    LDREQ    r6, =armVCM4P10_ZigZag_2x2
+    LDRNE    r6, =armVCM4P10_ZigZag_4x4
+L0x2ec:
+    LDRB     r9,[r4],#1
+    LDRB     r8,[r6,lr]
+    SUB      lr,lr,#1
+    SUB      lr,lr,r9
+    LDRSH    r9,[r2],#2
+    SUBS     r5,r5,#1
+    ORREQ    r8,r8,#0x20
+    ADD      r1,r9,#0x80
+    CMP      r1,#0x100
+    ORRCS    r8,r8,#0x10
+    TEQ      r5,#0
+    STRB     r8,[r0],#1
+    STRB     r9,[r0],#1
+    LSR      r9,r9,#8
+    BCC      L8
+    STRB     r9,[r0],#1
+L8:
+    BNE      L0x2ec
+    STR      r0,[r3,#0]
+    LDR      r0,[sp,#0]
+    LDR      r1,[sp,#4]
+    B        L0x344
+L0x33c:
+    MVN      r0,#1
+    B        L0x35c
+L0x344:
+    ADD      r10,r10,r12,LSR #3
+    AND      r12,r12,#7
+    SUB      r10,r10,#4
+    STR      r12,[r1,#0]
+    STR      r10,[r0,#0]
+    MOV      r0,#0
+L0x35c:
+    ADD      sp,sp,#0x40
+    POP      {r4-r12,pc}
+    .endfunc
+
+    .end
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_DequantTables_s.S b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_DequantTables_s.S
new file mode 100644
index 0000000..44eb428
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_DequantTables_s.S
@@ -0,0 +1,103 @@
+/*
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ *
+ */
+
+    .eabi_attribute 24, 1
+    .eabi_attribute 25, 1
+
+    .arm
+    .fpu neon
+    .section .rodata
+    .align 4
+
+
+    .global armVCM4P10_QPDivTable
+    .global armVCM4P10_VMatrixQPModTable
+    .global armVCM4P10_PosToVCol4x4
+    .global armVCM4P10_PosToVCol2x2
+    .global armVCM4P10_VMatrix
+    .global armVCM4P10_QPModuloTable
+    .global armVCM4P10_VMatrixU16
+
+armVCM4P10_PosToVCol4x4:
+    .byte  0, 2, 0, 2
+    .byte  2, 1, 2, 1
+    .byte  0, 2, 0, 2
+    .byte  2, 1, 2, 1
+
+armVCM4P10_PosToVCol2x2:
+    .byte  0, 2
+    .byte  2, 1
+
+armVCM4P10_VMatrix:
+    .byte  10, 16, 13
+    .byte  11, 18, 14
+    .byte  13, 20, 16
+    .byte  14, 23, 18
+    .byte  16, 25, 20
+    .byte  18, 29, 23
+
+;//-------------------------------------------------------
+;// This table evaluates the expression [(INT)(QP/6)],
+;// for values of QP from 0 to 51 (inclusive).
+;//-------------------------------------------------------
+
+armVCM4P10_QPDivTable:
+    .byte  0,  0,  0,  0,  0,  0
+    .byte  1,  1,  1,  1,  1,  1
+    .byte  2,  2,  2,  2,  2,  2
+    .byte  3,  3,  3,  3,  3,  3
+    .byte  4,  4,  4,  4,  4,  4
+    .byte  5,  5,  5,  5,  5,  5
+    .byte  6,  6,  6,  6,  6,  6
+    .byte  7,  7,  7,  7,  7,  7
+    .byte  8,  8,  8,  8,  8,  8
+
+;//----------------------------------------------------
+;// This table contains armVCM4P10_VMatrix[QP%6][0] entires,
+;// for values of QP from 0 to 51 (inclusive).
+;//----------------------------------------------------
+
+armVCM4P10_VMatrixQPModTable:
+    .byte 10, 11, 13, 14, 16, 18
+    .byte 10, 11, 13, 14, 16, 18
+    .byte 10, 11, 13, 14, 16, 18
+    .byte 10, 11, 13, 14, 16, 18
+    .byte 10, 11, 13, 14, 16, 18
+    .byte 10, 11, 13, 14, 16, 18
+    .byte 10, 11, 13, 14, 16, 18
+    .byte 10, 11, 13, 14, 16, 18
+    .byte 10, 11, 13, 14, 16, 18
+
+;//-------------------------------------------------------
+;// This table evaluates the modulus expression [QP%6]*6,
+;// for values of QP from 0 to 51 (inclusive).
+;//-------------------------------------------------------
+
+armVCM4P10_QPModuloTable:
+    .byte 0, 6, 12, 18, 24, 30
+    .byte 0, 6, 12, 18, 24, 30
+    .byte 0, 6, 12, 18, 24, 30
+    .byte 0, 6, 12, 18, 24, 30
+    .byte 0, 6, 12, 18, 24, 30
+    .byte 0, 6, 12, 18, 24, 30
+    .byte 0, 6, 12, 18, 24, 30
+    .byte 0, 6, 12, 18, 24, 30
+    .byte 0, 6, 12, 18, 24, 30
+
+;//-------------------------------------------------------
+;// This table contains the invidual byte values stored as
+;// halfwords. This avoids unpacking inside the function
+;//-------------------------------------------------------
+
+armVCM4P10_VMatrixU16:
+    .hword 10, 16, 13
+    .hword 11, 18, 14
+    .hword 13, 20, 16
+    .hword 14, 23, 18
+    .hword 16, 25, 20
+    .hword 18, 29, 23
+
+    .end
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_InterpolateLuma_Align_unsafe_s.S b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_InterpolateLuma_Align_unsafe_s.S
new file mode 100644
index 0000000..37bc69b
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_InterpolateLuma_Align_unsafe_s.S
@@ -0,0 +1,123 @@
+/*
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ *
+ */
+
+    .eabi_attribute 24, 1
+    .eabi_attribute 25, 1
+
+    .arm
+    .fpu neon
+    .text
+
+    .global armVCM4P10_InterpolateLuma_HorAlign9x_unsafe
+    .func   armVCM4P10_InterpolateLuma_HorAlign9x_unsafe
+armVCM4P10_InterpolateLuma_HorAlign9x_unsafe:
+    MOV      r12,r8
+    AND      r7,r0,#3
+    BIC      r0,r0,#3
+    ADD      pc,pc,r7,LSL #2
+    NOP
+    B        Copy0toAligned
+    B        Copy1toAligned
+    B        Copy2toAligned
+    B        Copy3toAligned
+Copy0toAligned:
+    LDM      r0,{r7,r10,r11}
+    SUBS     r9,r9,#1
+    ADD      r0,r0,r1
+    STM      r8!,{r7,r10,r11}
+    BGT      Copy0toAligned
+    B        CopyEnd
+Copy1toAligned:
+    LDM      r0,{r7,r10,r11}
+    SUBS     r9,r9,#1
+    ADD      r0,r0,r1
+    LSR      r7,r7,#8
+    ORR      r7,r7,r10,LSL #24
+    LSR      r10,r10,#8
+    ORR      r10,r10,r11,LSL #24
+    LSR      r11,r11,#8
+    STM      r8!,{r7,r10,r11}
+    BGT      Copy1toAligned
+    B        CopyEnd
+Copy2toAligned:
+    LDM      r0,{r7,r10,r11}
+    SUBS     r9,r9,#1
+    ADD      r0,r0,r1
+    LSR      r7,r7,#16
+    ORR      r7,r7,r10,LSL #16
+    LSR      r10,r10,#16
+    ORR      r10,r10,r11,LSL #16
+    LSR      r11,r11,#16
+    STM      r8!,{r7,r10,r11}
+    BGT      Copy2toAligned
+    B        CopyEnd
+Copy3toAligned:
+    LDM      r0,{r7,r10,r11}
+    SUBS     r9,r9,#1
+    ADD      r0,r0,r1
+    LSR      r7,r7,#24
+    ORR      r7,r7,r10,LSL #8
+    LSR      r10,r10,#24
+    ORR      r10,r10,r11,LSL #8
+    LSR      r11,r11,#24
+    STM      r8!,{r7,r10,r11}
+    BGT      Copy3toAligned
+CopyEnd:
+    MOV      r0,r12
+    MOV      r1,#0xc
+    BX       lr
+    .endfunc
+
+    .global armVCM4P10_InterpolateLuma_VerAlign4x_unsafe
+    .func   armVCM4P10_InterpolateLuma_VerAlign4x_unsafe
+armVCM4P10_InterpolateLuma_VerAlign4x_unsafe:
+    AND      r7,r0,#3
+    BIC      r0,r0,#3
+    ADD      pc,pc,r7,LSL #2
+    NOP
+    B        Copy0toVAligned
+    B        Copy1toVAligned
+    B        Copy2toVAligned
+    B        Copy3toVAligned
+Copy0toVAligned:
+    LDR      r7,[r0],r1
+    SUBS     r9,r9,#1
+    STR      r7,[r8],#4
+    BGT      Copy0toVAligned
+    B        CopyVEnd
+Copy1toVAligned:
+    LDR      r10,[r0,#4]
+    LDR      r7,[r0],r1
+    SUBS     r9,r9,#1
+    LSL      r10,r10,#24
+    ORR      r7,r10,r7,LSR #8
+    STR      r7,[r8],#4
+    BGT      Copy1toVAligned
+    B        CopyVEnd
+Copy2toVAligned:
+    LDR      r10,[r0,#4]
+    LDR      r7,[r0],r1
+    SUBS     r9,r9,#1
+    LSL      r10,r10,#16
+    ORR      r7,r10,r7,LSR #16
+    STR      r7,[r8],#4
+    BGT      Copy2toVAligned
+    B        CopyVEnd
+Copy3toVAligned:
+    LDR      r10,[r0,#4]
+    LDR      r7,[r0],r1
+    SUBS     r9,r9,#1
+    LSL      r10,r10,#8
+    ORR      r7,r10,r7,LSR #24
+    STR      r7,[r8],#4
+    BGT      Copy3toVAligned
+CopyVEnd:
+    SUB      r0,r8,#0x1c
+    MOV      r1,#4
+    BX       lr
+    .endfunc
+
+    .end
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_InterpolateLuma_Copy_unsafe_s.S b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_InterpolateLuma_Copy_unsafe_s.S
new file mode 100644
index 0000000..fe92201
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_InterpolateLuma_Copy_unsafe_s.S
@@ -0,0 +1,105 @@
+/*
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ *
+ */
+
+    .eabi_attribute 24, 1
+    .eabi_attribute 25, 1
+
+    .arm
+    .fpu neon
+    .text
+
+    .global armVCM4P10_InterpolateLuma_Copy4x4_unsafe
+    .func   armVCM4P10_InterpolateLuma_Copy4x4_unsafe
+armVCM4P10_InterpolateLuma_Copy4x4_unsafe:
+    PUSH     {r4-r6,lr}
+    AND      r12,r0,#3
+    BIC      r0,r0,#3
+    ADD      pc,pc,r12,LSL #2
+    NOP
+    B        Copy4x4Align0
+    B        Copy4x4Align1
+    B        Copy4x4Align2
+    B        Copy4x4Align3
+Copy4x4Align0:
+    LDR      r4,[r0],r1
+    LDR      r5,[r0],r1
+    STR      r4,[r2],r3
+    LDR      r8,[r0],r1
+    STR      r5,[r2],r3
+    LDR      r9,[r0],r1
+    STR      r8,[r2],r3
+    STR      r9,[r2],r3
+    B        Copy4x4End
+Copy4x4Align1:
+    LDR      r5,[r0,#4]
+    LDR      r4,[r0],r1
+    LDR      r9,[r0,#4]
+    LDR      r8,[r0],r1
+    LSR      r4,r4,#8
+    ORR      r4,r4,r5,LSL #24
+    STR      r4,[r2],r3
+    LSR      r8,r8,#8
+    ORR      r8,r8,r9,LSL #24
+    LDR      r5,[r0,#4]
+    LDR      r4,[r0],r1
+    STR      r8,[r2],r3
+    LDR      r9,[r0,#4]
+    LDR      r8,[r0],r1
+    LSR      r4,r4,#8
+    ORR      r4,r4,r5,LSL #24
+    STR      r4,[r2],r3
+    LSR      r8,r8,#8
+    ORR      r8,r8,r9,LSL #24
+    STR      r8,[r2],r3
+    B        Copy4x4End
+Copy4x4Align2:
+    LDR      r5,[r0,#4]
+    LDR      r4,[r0],r1
+    LDR      r9,[r0,#4]
+    LDR      r8,[r0],r1
+    LSR      r4,r4,#16
+    ORR      r4,r4,r5,LSL #16
+    STR      r4,[r2],r3
+    LSR      r8,r8,#16
+    ORR      r8,r8,r9,LSL #16
+    STR      r8,[r2],r3
+    LDR      r5,[r0,#4]
+    LDR      r4,[r0],r1
+    LDR      r9,[r0,#4]
+    LDR      r8,[r0],r1
+    LSR      r4,r4,#16
+    ORR      r4,r4,r5,LSL #16
+    STR      r4,[r2],r3
+    LSR      r8,r8,#16
+    ORR      r8,r8,r9,LSL #16
+    STR      r8,[r2],r3
+    B        Copy4x4End
+Copy4x4Align3:
+    LDR      r5,[r0,#4]
+    LDR      r4,[r0],r1
+    LDR      r9,[r0,#4]
+    LDR      r8,[r0],r1
+    LSR      r4,r4,#24
+    ORR      r4,r4,r5,LSL #8
+    STR      r4,[r2],r3
+    LSR      r8,r8,#24
+    ORR      r8,r8,r9,LSL #8
+    STR      r8,[r2],r3
+    LDR      r5,[r0,#4]
+    LDR      r4,[r0],r1
+    LDR      r9,[r0,#4]
+    LDR      r8,[r0],r1
+    LSR      r4,r4,#24
+    ORR      r4,r4,r5,LSL #8
+    STR      r4,[r2],r3
+    LSR      r8,r8,#24
+    ORR      r8,r8,r9,LSL #8
+    STR      r8,[r2],r3
+Copy4x4End:
+    POP      {r4-r6,pc}
+    .endfunc
+
+    .end
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_InterpolateLuma_DiagCopy_unsafe_s.S b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_InterpolateLuma_DiagCopy_unsafe_s.S
new file mode 100644
index 0000000..544abe8
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_InterpolateLuma_DiagCopy_unsafe_s.S
@@ -0,0 +1,107 @@
+/*
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ *
+ */
+
+    .eabi_attribute 24, 1
+    .eabi_attribute 25, 1
+
+    .arm
+    .fpu neon
+    .text
+
+    .global armVCM4P10_InterpolateLuma_HorDiagCopy_unsafe
+    .func   armVCM4P10_InterpolateLuma_HorDiagCopy_unsafe
+armVCM4P10_InterpolateLuma_HorDiagCopy_unsafe:
+    PUSH     {r4-r6,lr}
+    MOV      lr,#4
+    LDR      r6, =0xfe00fe0
+    LDR      r12, =0xff00ff
+LoopStart1:
+    LDR      r11,[r0,#0xc]
+    LDR      r10,[r0,#8]
+    LDR      r5,[r0,#4]
+    LDR      r4,[r0],r1
+    UQSUB16  r11,r11,r6
+    UQSUB16  r10,r10,r6
+    UQSUB16  r5,r5,r6
+    UQSUB16  r4,r4,r6
+    USAT16   r11,#13,r11
+    USAT16   r10,#13,r10
+    USAT16   r5,#13,r5
+    USAT16   r4,#13,r4
+    AND      r11,r12,r11,LSR #5
+    AND      r10,r12,r10,LSR #5
+    AND      r5,r12,r5,LSR #5
+    AND      r4,r12,r4,LSR #5
+    ORR      r11,r10,r11,LSL #8
+    ORR      r10,r4,r5,LSL #8
+    SUBS     lr,lr,#1
+    STRD     r10,r11,[r7],#8
+    BGT      LoopStart1
+    SUB      r0,r7,#0x20
+    MOV      r1,#8
+    POP      {r4-r6,pc}
+    .endfunc
+
+    .global armVCM4P10_InterpolateLuma_VerDiagCopy_unsafe
+    .func   armVCM4P10_InterpolateLuma_VerDiagCopy_unsafe
+armVCM4P10_InterpolateLuma_VerDiagCopy_unsafe:
+    PUSH     {r4-r6,lr}
+    LDR      r6, =0xfe00fe0
+    LDR      r12, =0xff00ff
+    MOV      lr,#2
+LoopStart:
+    LDR      r11,[r0,#0xc]
+    LDR      r10,[r0,#8]
+    LDR      r5,[r0,#4]
+    LDR      r4,[r0],r1
+    UQSUB16  r11,r11,r6
+    UQSUB16  r10,r10,r6
+    UQSUB16  r5,r5,r6
+    UQSUB16  r4,r4,r6
+    USAT16   r11,#13,r11
+    USAT16   r10,#13,r10
+    USAT16   r5,#13,r5
+    USAT16   r4,#13,r4
+    AND      r11,r12,r11,LSR #5
+    AND      r10,r12,r10,LSR #5
+    AND      r5,r12,r5,LSR #5
+    AND      r4,r12,r4,LSR #5
+    ORR      r11,r10,r11,LSL #8
+    ORR      r10,r4,r5,LSL #8
+    PKHBT    r4,r10,r11,LSL #16
+    STR      r4,[r7],#8
+    PKHTB    r5,r11,r10,ASR #16
+    STR      r5,[r7],#-4
+    LDR      r11,[r0,#0xc]
+    LDR      r10,[r0,#8]
+    LDR      r5,[r0,#4]
+    LDR      r4,[r0],r1
+    UQSUB16  r11,r11,r6
+    UQSUB16  r10,r10,r6
+    UQSUB16  r5,r5,r6
+    UQSUB16  r4,r4,r6
+    USAT16   r11,#13,r11
+    USAT16   r10,#13,r10
+    USAT16   r5,#13,r5
+    USAT16   r4,#13,r4
+    AND      r11,r12,r11,LSR #5
+    AND      r10,r12,r10,LSR #5
+    AND      r5,r12,r5,LSR #5
+    AND      r4,r12,r4,LSR #5
+    ORR      r11,r10,r11,LSL #8
+    ORR      r10,r4,r5,LSL #8
+    PKHBT    r4,r10,r11,LSL #16
+    SUBS     lr,lr,#1
+    STR      r4,[r7],#8
+    PKHTB    r5,r11,r10,ASR #16
+    STR      r5,[r7],#4
+    BGT      LoopStart
+    SUB      r0,r7,#0x18
+    MOV      r1,#4
+    POP      {r4-r6,pc}
+    .endfunc
+
+    .end
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_InterpolateLuma_HalfDiagHorVer4x4_unsafe_s.S b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_InterpolateLuma_HalfDiagHorVer4x4_unsafe_s.S
new file mode 100644
index 0000000..a330972
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_InterpolateLuma_HalfDiagHorVer4x4_unsafe_s.S
@@ -0,0 +1,164 @@
+/*
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ *
+ */
+
+    .eabi_attribute 24, 1
+    .eabi_attribute 25, 1
+
+    .arm
+    .fpu neon
+    .text
+
+    .global armVCM4P10_InterpolateLuma_HalfDiagHorVer4x4_unsafe
+    .func   armVCM4P10_InterpolateLuma_HalfDiagHorVer4x4_unsafe
+armVCM4P10_InterpolateLuma_HalfDiagHorVer4x4_unsafe:
+    PUSH     {r4-r12,lr}
+    VLD1.8   {d0,d1},[r0],r1
+    VMOV.I16 d31,#0x14
+    VMOV.I16 d30,#0x5
+    VEXT.8   d4,d0,d1,#1
+    VEXT.8   d2,d0,d1,#2
+    VEXT.8   d3,d0,d1,#3
+    VEXT.8   d5,d0,d1,#4
+    VEXT.8   d1,d0,d1,#5
+    VADDL.U8 q1,d2,d3
+    VADDL.U8 q2,d4,d5
+    VADDL.U8 q5,d0,d1
+    VLD1.8   {d0,d1},[r0],r1
+    VMLA.I16 d10,d2,d31
+    VMUL.I16 d8,d4,d30
+    VEXT.8   d4,d0,d1,#1
+    VEXT.8   d2,d0,d1,#2
+    VEXT.8   d3,d0,d1,#3
+    VEXT.8   d5,d0,d1,#4
+    VEXT.8   d1,d0,d1,#5
+    VADDL.U8 q1,d2,d3
+    VADDL.U8 q2,d4,d5
+    VADDL.U8 q6,d0,d1
+    VLD1.8   {d0,d1},[r0],r1
+    VSUB.I16 d10,d10,d8
+    VMLA.I16 d12,d2,d31
+    VMUL.I16 d8,d4,d30
+    VEXT.8   d4,d0,d1,#1
+    VEXT.8   d2,d0,d1,#2
+    VEXT.8   d3,d0,d1,#3
+    VEXT.8   d5,d0,d1,#4
+    VEXT.8   d1,d0,d1,#5
+    VADDL.U8 q1,d2,d3
+    VADDL.U8 q2,d4,d5
+    VADDL.U8 q7,d0,d1
+    VLD1.8   {d0,d1},[r0],r1
+    VSUB.I16 d12,d12,d8
+    VMLA.I16 d14,d2,d31
+    VMUL.I16 d8,d4,d30
+    VEXT.8   d4,d0,d1,#1
+    VEXT.8   d2,d0,d1,#2
+    VEXT.8   d3,d0,d1,#3
+    VEXT.8   d5,d0,d1,#4
+    VEXT.8   d1,d0,d1,#5
+    VADDL.U8 q1,d2,d3
+    VADDL.U8 q2,d4,d5
+    VADDL.U8 q8,d0,d1
+    VLD1.8   {d0,d1},[r0],r1
+    VSUB.I16 d14,d14,d8
+    VMLA.I16 d16,d2,d31
+    VMUL.I16 d8,d4,d30
+    VEXT.8   d4,d0,d1,#1
+    VEXT.8   d2,d0,d1,#2
+    VEXT.8   d3,d0,d1,#3
+    VEXT.8   d5,d0,d1,#4
+    VEXT.8   d1,d0,d1,#5
+    VADDL.U8 q1,d2,d3
+    VADDL.U8 q2,d4,d5
+    VADDL.U8 q9,d0,d1
+    VLD1.8   {d0,d1},[r0],r1
+    VSUB.I16 d16,d16,d8
+    VMLA.I16 d18,d2,d31
+    VMUL.I16 d8,d4,d30
+    VEXT.8   d4,d0,d1,#1
+    VEXT.8   d2,d0,d1,#2
+    VEXT.8   d3,d0,d1,#3
+    VEXT.8   d5,d0,d1,#4
+    VEXT.8   d1,d0,d1,#5
+    VADDL.U8 q1,d2,d3
+    VADDL.U8 q2,d4,d5
+    VADDL.U8 q10,d0,d1
+    VLD1.8   {d0,d1},[r0],r1
+    VSUB.I16 d18,d18,d8
+    VMLA.I16 d20,d2,d31
+    VMUL.I16 d8,d4,d30
+    VEXT.8   d4,d0,d1,#1
+    VEXT.8   d2,d0,d1,#2
+    VEXT.8   d3,d0,d1,#3
+    VEXT.8   d5,d0,d1,#4
+    VEXT.8   d1,d0,d1,#5
+    VADDL.U8 q1,d2,d3
+    VADDL.U8 q2,d4,d5
+    VADDL.U8 q11,d0,d1
+    VLD1.8   {d0,d1},[r0],r1
+    VSUB.I16 d20,d20,d8
+    VMLA.I16 d22,d2,d31
+    VMUL.I16 d8,d4,d30
+    VEXT.8   d4,d0,d1,#1
+    VEXT.8   d2,d0,d1,#2
+    VEXT.8   d3,d0,d1,#3
+    VEXT.8   d5,d0,d1,#4
+    VEXT.8   d1,d0,d1,#5
+    VADDL.U8 q1,d2,d3
+    VADDL.U8 q2,d4,d5
+    VADDL.U8 q12,d0,d1
+    VLD1.8   {d0,d1},[r0],r1
+    VSUB.I16 d22,d22,d8
+    VMLA.I16 d24,d2,d31
+    VMUL.I16 d8,d4,d30
+    VEXT.8   d4,d0,d1,#1
+    VEXT.8   d2,d0,d1,#2
+    VEXT.8   d3,d0,d1,#3
+    VEXT.8   d5,d0,d1,#4
+    VEXT.8   d1,d0,d1,#5
+    VADDL.U8 q1,d2,d3
+    VADDL.U8 q2,d4,d5
+    VADDL.U8 q13,d0,d1
+    VSUB.I16 d24,d24,d8
+    VMLA.I16 d26,d2,d31
+    VMUL.I16 d8,d4,d30
+    VMOV.I32 q15,#0x14
+    VMOV.I32 q14,#0x5
+    VADDL.S16 q5,d10,d20
+    VADDL.S16 q1,d14,d16
+    VADDL.S16 q0,d12,d18
+    VSUB.I16 d26,d26,d8
+    VMLA.I32 q5,q1,q15
+    VMUL.I32 q4,q0,q14
+    VADDL.S16 q6,d12,d22
+    VADDL.S16 q1,d16,d18
+    VADDL.S16 q0,d14,d20
+    VMLA.I32 q6,q1,q15
+    VSUB.I32 q5,q5,q4
+    VMUL.I32 q4,q0,q14
+    VADDL.S16 q2,d14,d24
+    VADDL.S16 q1,d18,d20
+    VADDL.S16 q0,d16,d22
+    VMLA.I32 q2,q1,q15
+    VSUB.I32 q6,q6,q4
+    VMUL.I32 q4,q0,q14
+    VADDL.S16 q3,d16,d26
+    VADDL.S16 q1,d20,d22
+    VADDL.S16 q0,d18,d24
+    VMLA.I32 q3,q1,q15
+    VSUB.I32 q2,q2,q4
+    VMLS.I32 q3,q0,q14
+    VQRSHRUN.S32 d0,q5,#10
+    VQRSHRUN.S32 d2,q6,#10
+    VQRSHRUN.S32 d4,q2,#10
+    VQRSHRUN.S32 d6,q3,#10
+    VQMOVN.U16 d0,q0
+    VQMOVN.U16 d2,q1
+    VQMOVN.U16 d4,q2
+    VQMOVN.U16 d6,q3
+    POP      {r4-r12,pc}
+    .endfunc
+
+    .end
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_InterpolateLuma_HalfDiagVerHor4x4_unsafe_s.S b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_InterpolateLuma_HalfDiagVerHor4x4_unsafe_s.S
new file mode 100644
index 0000000..991c33f
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_InterpolateLuma_HalfDiagVerHor4x4_unsafe_s.S
@@ -0,0 +1,119 @@
+/*
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ *
+ */
+
+    .eabi_attribute 24, 1
+    .eabi_attribute 25, 1
+
+    .arm
+    .fpu neon
+    .text
+
+    .global armVCM4P10_InterpolateLuma_HalfDiagVerHor4x4_unsafe
+    .func   armVCM4P10_InterpolateLuma_HalfDiagVerHor4x4_unsafe
+armVCM4P10_InterpolateLuma_HalfDiagVerHor4x4_unsafe:
+    PUSH     {r4-r12,lr}
+    VLD1.8   {d0,d1},[r0],r1
+    ADD      r12,r0,r1,LSL #2
+    VMOV.I8  d30,#0x5
+    VMOV.I8  d31,#0x14
+    VLD1.8   {d10,d11},[r12],r1
+    VLD1.8   {d2,d3},[r0],r1
+    VLD1.8   {d12,d13},[r12],r1
+    VADDL.U8 q9,d0,d10
+    VLD1.8   {d4,d5},[r0],r1
+    VADDL.U8 q0,d1,d11
+    VLD1.8   {d6,d7},[r0],r1
+    VADDL.U8 q10,d2,d12
+    VLD1.8   {d8,d9},[r0],r1
+    VMLAL.U8 q9,d4,d31
+    VLD1.8   {d14,d15},[r12],r1
+    VMLAL.U8 q0,d5,d31
+    VLD1.8   {d16,d17},[r12],r1
+    VMLAL.U8 q9,d6,d31
+    VMLAL.U8 q10,d6,d31
+    VMLSL.U8 q0,d3,d30
+    VADDL.U8 q11,d4,d14
+    VMLSL.U8 q9,d2,d30
+    VADDL.U8 q1,d3,d13
+    VMLAL.U8 q0,d7,d31
+    VMLAL.U8 q10,d8,d31
+    VMLSL.U8 q9,d8,d30
+    VMLAL.U8 q1,d7,d31
+    VMLSL.U8 q0,d9,d30
+    VMLAL.U8 q11,d8,d31
+    VMLSL.U8 q10,d4,d30
+    VMLSL.U8 q1,d5,d30
+    VADDL.U8 q2,d5,d15
+    VMLAL.U8 q11,d10,d31
+    VMLSL.U8 q10,d10,d30
+    VMLAL.U8 q1,d9,d31
+    VMLAL.U8 q2,d9,d31
+    VADDL.U8 q12,d6,d16
+    VMLSL.U8 q11,d6,d30
+    VMLSL.U8 q1,d11,d30
+    VMLSL.U8 q2,d7,d30
+    VADDL.U8 q3,d7,d17
+    VMLAL.U8 q12,d10,d31
+    VMLSL.U8 q11,d12,d30
+    VMLSL.U8 q2,d13,d30
+    VMLAL.U8 q3,d11,d31
+    VMLAL.U8 q12,d12,d31
+    VEXT.8   d26,d18,d19,#2
+    VMLAL.U8 q2,d11,d31
+    VMLAL.U8 q3,d13,d31
+    VMLSL.U8 q12,d8,d30
+    VEXT.8   d27,d18,d19,#4
+    VMOV.I16 d31,#0x14
+    VMLSL.U8 q3,d9,d30
+    VMLSL.U8 q12,d14,d30
+    VEXT.8   d29,d19,d0,#2
+    VEXT.8   d28,d18,d19,#6
+    VMLSL.U8 q3,d15,d30
+    VADDL.S16 q0,d18,d29
+    VADD.I16 d27,d27,d28
+    VMOV.I16 d30,#0x5
+    VADD.I16 d26,d26,d19
+    VMLAL.S16 q0,d27,d31
+    VEXT.8   d27,d20,d21,#4
+    VEXT.8   d28,d20,d21,#6
+    VEXT.8   d29,d21,d2,#2
+    VMLSL.S16 q0,d26,d30
+    VEXT.8   d26,d20,d21,#2
+    VADDL.S16 q1,d20,d29
+    VADD.I16 d27,d27,d28
+    VADD.I16 d26,d26,d21
+    VEXT.8   d28,d22,d23,#6
+    VMLAL.S16 q1,d27,d31
+    VEXT.8   d29,d23,d4,#2
+    VEXT.8   d27,d22,d23,#4
+    VEXT.8   d8,d22,d23,#2
+    VADDL.S16 q2,d22,d29
+    VMLSL.S16 q1,d26,d30
+    VADD.I16 d27,d27,d28
+    VADD.I16 d26,d8,d23
+    VEXT.8   d28,d24,d25,#6
+    VMLAL.S16 q2,d27,d31
+    VEXT.8   d27,d24,d25,#4
+    VEXT.8   d29,d25,d6,#2
+    VADD.I16 d27,d27,d28
+    VEXT.8   d8,d24,d25,#2
+    VADDL.S16 q3,d24,d29
+    VMLSL.S16 q2,d26,d30
+    VMLAL.S16 q3,d27,d31
+    VADD.I16 d8,d8,d25
+    VMLSL.S16 q3,d8,d30
+    VQRSHRUN.S32 d0,q0,#10
+    VQRSHRUN.S32 d2,q1,#10
+    VQRSHRUN.S32 d4,q2,#10
+    VQRSHRUN.S32 d6,q3,#10
+    VQMOVN.U16 d0,q0
+    VQMOVN.U16 d2,q1
+    VQMOVN.U16 d4,q2
+    VQMOVN.U16 d6,q3
+    POP      {r4-r12,pc}
+    .endfunc
+
+    .end
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe_s.S b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe_s.S
new file mode 100644
index 0000000..40e141b
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe_s.S
@@ -0,0 +1,72 @@
+/*
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ *
+ */
+
+    .eabi_attribute 24, 1
+    .eabi_attribute 25, 1
+
+    .arm
+    .fpu neon
+    .text
+
+    .global armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe
+    .func   armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe
+armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe:
+    PUSH     {r4-r12,lr}
+    VLD1.8   {d22,d23},[r0],r1
+    VEXT.8   d10,d22,d23,#5
+    VEXT.8   d12,d22,d23,#1
+    VEXT.8   d14,d22,d23,#2
+    VEXT.8   d15,d22,d23,#3
+    VEXT.8   d13,d22,d23,#4
+    VADDL.U8 q11,d22,d10
+    VADDL.U8 q4,d14,d15
+    VADDL.U8 q6,d12,d13
+    VLD1.8   {d24,d25},[r0],r1
+    VMLA.I16 d22,d8,d31
+    VMUL.I16 d8,d12,d30
+    VEXT.8   d10,d24,d25,#5
+    VEXT.8   d12,d24,d25,#1
+    VEXT.8   d16,d24,d25,#2
+    VEXT.8   d17,d24,d25,#3
+    VEXT.8   d13,d24,d25,#4
+    VADDL.U8 q12,d24,d10
+    VSUB.I16 d22,d22,d8
+    VADDL.U8 q4,d16,d17
+    VADDL.U8 q6,d12,d13
+    VLD1.8   {d26,d27},[r0],r1
+    VMLA.I16 d24,d8,d31
+    VMUL.I16 d8,d12,d30
+    VEXT.8   d10,d26,d27,#5
+    VEXT.8   d12,d26,d27,#1
+    VEXT.8   d18,d26,d27,#2
+    VEXT.8   d19,d26,d27,#3
+    VEXT.8   d13,d26,d27,#4
+    VADDL.U8 q13,d26,d10
+    VSUB.I16 d24,d24,d8
+    VADDL.U8 q4,d18,d19
+    VADDL.U8 q6,d12,d13
+    VLD1.8   {d28,d29},[r0],r1
+    VMLA.I16 d26,d8,d31
+    VMUL.I16 d8,d12,d30
+    VEXT.8   d10,d28,d29,#5
+    VEXT.8   d12,d28,d29,#1
+    VEXT.8   d20,d28,d29,#2
+    VEXT.8   d21,d28,d29,#3
+    VEXT.8   d13,d28,d29,#4
+    VADDL.U8 q14,d28,d10
+    VSUB.I16 d26,d26,d8
+    VADDL.U8 q4,d20,d21
+    VADDL.U8 q6,d12,d13
+    VMLA.I16 d28,d8,d31
+    VMLS.I16 d28,d12,d30
+    VQRSHRUN.S16 d22,q11,#5
+    VQRSHRUN.S16 d24,q12,#5
+    VQRSHRUN.S16 d26,q13,#5
+    VQRSHRUN.S16 d28,q14,#5
+    POP      {r4-r12,pc}
+    .endfunc
+
+    .end
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe_s.S b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe_s.S
new file mode 100644
index 0000000..955846f
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe_s.S
@@ -0,0 +1,58 @@
+/*
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ *
+ */
+
+    .eabi_attribute 24, 1
+    .eabi_attribute 25, 1
+
+    .arm
+    .fpu neon
+    .text
+
+    .global armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe
+    .func   armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe
+armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe:
+    PUSH     {r4-r12,lr}
+    VLD1.8   {d7},[r0],r1
+    ADD      r12,r0,r1,LSL #2
+    VLD1.8   {d8},[r0],r1
+    VLD1.8   {d12},[r12],r1
+    VLD1.8   {d9},[r0],r1
+    VADDL.U8 q0,d7,d12
+    VLD1.8   {d10},[r0],r1
+    VLD1.8   {d13},[r12],r1
+    VLD1.8   {d11},[r0],r1
+    VLD1.8   {d14},[r12],r1
+    VADDL.U8 q8,d8,d11
+    VADDL.U8 q9,d9,d10
+    VLD1.8   {d15},[r12],r1
+    VMLS.I16 d0,d16,d30
+    VMUL.I16 d20,d18,d31
+    VADDL.U8 q8,d9,d12
+    VADDL.U8 q9,d10,d11
+    VADDL.U8 q1,d8,d13
+    VMLS.I16 d2,d16,d30
+    VMUL.I16 d21,d18,d31
+    VADDL.U8 q8,d10,d13
+    VADDL.U8 q9,d11,d12
+    VADDL.U8 q2,d9,d14
+    VMLS.I16 d4,d16,d30
+    VMUL.I16 d22,d18,d31
+    VADDL.U8 q8,d11,d14
+    VADDL.U8 q3,d10,d15
+    VADDL.U8 q9,d12,d13
+    VMLS.I16 d6,d16,d30
+    VADD.I16 d0,d0,d20
+    VADD.I16 d2,d2,d21
+    VADD.I16 d4,d4,d22
+    VMLA.I16 d6,d18,d31
+    VQRSHRUN.S16 d0,q0,#5
+    VQRSHRUN.S16 d2,q1,#5
+    VQRSHRUN.S16 d4,q2,#5
+    VQRSHRUN.S16 d6,q3,#5
+    POP      {r4-r12,pc}
+    .endfunc
+
+    .end
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_Interpolate_Chroma_s.S b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_Interpolate_Chroma_s.S
new file mode 100644
index 0000000..66520da
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_Interpolate_Chroma_s.S
@@ -0,0 +1,175 @@
+/*
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ *
+ */
+
+    .eabi_attribute 24, 1
+    .eabi_attribute 25, 1
+
+    .arm
+    .fpu neon
+
+    .section .rodata
+    .align 4
+
+armVCM4P10_WidthBranchTableMVIsNotZero:
+    .word   WidthIs2MVIsNotZero, WidthIs2MVIsNotZero
+    .word   WidthIs4MVIsNotZero, WidthIs4MVIsNotZero
+    .word   WidthIs8MVIsNotZero
+
+armVCM4P10_WidthBranchTableMVIsZero:
+    .word   WidthIs2MVIsZero, WidthIs2MVIsZero
+    .word   WidthIs4MVIsZero, WidthIs4MVIsZero
+    .word   WidthIs8MVIsZero
+
+    .text
+
+    .global armVCM4P10_Interpolate_Chroma
+    .func   armVCM4P10_Interpolate_Chroma
+armVCM4P10_Interpolate_Chroma:
+    PUSH     {r4-r12,lr}
+    VPUSH    {d8-d15}
+    LDRD     r6,r7,[sp,#0x70]
+    LDRD     r4,r5,[sp,#0x68]
+    RSB      r8,r6,#8
+    RSB      r9,r7,#8
+    CMN      r6,r7
+    MOV      r10,#1
+    LDREQ    r11, =armVCM4P10_WidthBranchTableMVIsZero
+    SUB      lr,r1,r10
+    LDRNE    r11, =armVCM4P10_WidthBranchTableMVIsNotZero
+    VLD1.8   {d0},[r0],r10
+    SMULBB   r12,r8,r9
+    SMULBB   r9,r6,r9
+    VLD1.8   {d1},[r0],lr
+    SMULBB   r8,r8,r7
+    SMULBB   r6,r6,r7
+    VDUP.8   d12,r12
+    VDUP.8   d13,r9
+    VDUP.8   d14,r8
+    VDUP.8   d15,r6
+    LDR      pc,[r11,r4,LSL #1]
+
+WidthIs8MVIsNotZero:
+    VLD1.8   {d2},[r0],r10
+    VMULL.U8 q2,d0,d12
+    VLD1.8   {d3},[r0],lr
+    VMULL.U8 q3,d2,d12
+    VLD1.8   {d16},[r0],r10
+    VMLAL.U8 q2,d1,d13
+    VLD1.8   {d17},[r0],lr
+    VMULL.U8 q11,d16,d12
+    VMLAL.U8 q3,d3,d13
+    VLD1.8   {d18},[r0],r10
+    VMLAL.U8 q2,d2,d14
+    VMLAL.U8 q11,d17,d13
+    VMULL.U8 q12,d18,d12
+    VLD1.8   {d19},[r0],lr
+    VMLAL.U8 q3,d16,d14
+    VLD1.8   {d0},[r0],r10
+    VMLAL.U8 q12,d19,d13
+    VMLAL.U8 q11,d18,d14
+    VMLAL.U8 q2,d3,d15
+    VLD1.8   {d1},[r0],lr
+    VMLAL.U8 q12,d0,d14
+    VMLAL.U8 q3,d17,d15
+    VMLAL.U8 q11,d19,d15
+    SUBS     r5,r5,#4
+    VMLAL.U8 q12,d1,d15
+    VQRSHRN.U16 d8,q2,#6
+    VQRSHRN.U16 d9,q3,#6
+    VQRSHRN.U16 d20,q11,#6
+    VST1.64  {d8},[r2],r3
+    VQRSHRN.U16 d21,q12,#6
+    VST1.64  {d9},[r2],r3
+    VST1.64  {d20},[r2],r3
+    VST1.64  {d21},[r2],r3
+    BGT      WidthIs8MVIsNotZero
+    MOV      r0,#0
+    VPOP     {d8-d15}
+    POP      {r4-r12,pc}
+
+WidthIs4MVIsNotZero:
+    VLD1.8   {d2},[r0],r10
+    VMULL.U8 q2,d0,d12
+    VMULL.U8 q3,d2,d12
+    VLD1.8   {d3},[r0],lr
+    VMLAL.U8 q2,d1,d13
+    VMLAL.U8 q3,d3,d13
+    VLD1.8   {d0},[r0],r10
+    VMLAL.U8 q2,d2,d14
+    VMLAL.U8 q3,d0,d14
+    VLD1.8   {d1},[r0],lr
+    SUBS     r5,r5,#2
+    VMLAL.U8 q3,d1,d15
+    VMLAL.U8 q2,d3,d15
+    VQRSHRN.U16 d9,q3,#6
+    VQRSHRN.U16 d8,q2,#6
+    VST1.32  {d8[0]},[r2],r3
+    VST1.32  {d9[0]},[r2],r3
+    BGT      WidthIs4MVIsNotZero
+    MOV      r0,#0
+    VPOP     {d8-d15}
+    POP      {r4-r12,pc}
+
+WidthIs2MVIsNotZero:
+    VLD1.8   {d2},[r0],r10
+    VMULL.U8 q2,d0,d12
+    VMULL.U8 q3,d2,d12
+    VLD1.8   {d3},[r0],lr
+    VMLAL.U8 q2,d1,d13
+    VMLAL.U8 q3,d3,d13
+    VLD1.8   {d0},[r0],r10
+    VMLAL.U8 q2,d2,d14
+    VMLAL.U8 q3,d0,d14
+    VLD1.8   {d1},[r0],lr
+    SUBS     r5,r5,#2
+    VMLAL.U8 q3,d1,d15
+    VMLAL.U8 q2,d3,d15
+    VQRSHRN.U16 d9,q3,#6
+    VQRSHRN.U16 d8,q2,#6
+    VST1.16  {d8[0]},[r2],r3
+    VST1.16  {d9[0]},[r2],r3
+    BGT      WidthIs2MVIsNotZero
+    MOV      r0,#0
+    VPOP     {d8-d15}
+    POP      {r4-r12,pc}
+
+WidthIs8MVIsZero:
+    SUB      r0,r0,r1
+WidthIs8LoopMVIsZero:
+    VLD1.8   {d0},[r0],r1
+    SUBS     r5,r5,#2
+    VLD1.8   {d1},[r0],r1
+    VST1.64  {d0},[r2],r3
+    VST1.64  {d1},[r2],r3
+    BGT      WidthIs8LoopMVIsZero
+    MOV      r0,#0
+    VPOP     {d8-d15}
+    POP      {r4-r12,pc}
+
+WidthIs4MVIsZero:
+    VLD1.8   {d1},[r0],r1
+    SUBS     r5,r5,#2
+    VST1.32  {d0[0]},[r2],r3
+    VLD1.8   {d0},[r0],r1
+    VST1.32  {d1[0]},[r2],r3
+    BGT      WidthIs4MVIsZero
+    MOV      r0,#0
+    VPOP     {d8-d15}
+    POP      {r4-r12,pc}
+
+WidthIs2MVIsZero:
+    VLD1.8   {d1},[r0],r1
+    SUBS     r5,r5,#2
+    VST1.16  {d0[0]},[r2],r3
+    VLD1.8   {d0},[r0],r1
+    VST1.16  {d1[0]},[r2],r3
+    BGT      WidthIs2MVIsZero
+    MOV      r0,#0
+    VPOP     {d8-d15}
+    POP      {r4-r12,pc}
+    .endfunc
+
+    .end
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_QuantTables_s.S b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_QuantTables_s.S
new file mode 100644
index 0000000..f5d6d1f
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_QuantTables_s.S
@@ -0,0 +1,68 @@
+/*
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ *
+ */
+
+    .eabi_attribute 24, 1
+    .eabi_attribute 25, 1
+
+    .arm
+    .fpu neon
+    .section .rodata
+    .align 4
+
+    .global armVCM4P10_MFMatrixQPModTable
+    .global armVCM4P10_QPDivIntraTable
+    .global armVCM4P10_QPDivPlusOneTable
+
+;//------------------------------------------------------------------
+;// This table contains (1 << QbitsPlusOne) / 3 Values (Intra case) ,
+;// for values of iQP from 0 to 51 (inclusive).
+;//------------------------------------------------------------------
+
+
+armVCM4P10_QPDivIntraTable:
+    .word 21845, 21845, 21845, 21845, 21845, 21845
+    .word 43690, 43690, 43690, 43690, 43690, 43690
+    .word 87381, 87381, 87381, 87381, 87381, 87381
+    .word 174762, 174762, 174762, 174762, 174762, 174762
+    .word 349525, 349525, 349525, 349525, 349525, 349525
+    .word 699050, 699050, 699050, 699050, 699050, 699050
+    .word 1398101, 1398101, 1398101, 1398101, 1398101, 1398101
+    .word 2796202, 2796202, 2796202, 2796202, 2796202, 2796202
+
+
+;//--------------------------------------------------------------
+;// This table contains armVCM4P10_MFMatrix [iQP % 6][0] entires,
+;// for values of iQP from 0 to 51 (inclusive).
+;//--------------------------------------------------------------
+
+armVCM4P10_MFMatrixQPModTable:
+    .hword 13107, 11916, 10082, 9362, 8192, 7282
+    .hword 13107, 11916, 10082, 9362, 8192, 7282
+    .hword 13107, 11916, 10082, 9362, 8192, 7282
+    .hword 13107, 11916, 10082, 9362, 8192, 7282
+    .hword 13107, 11916, 10082, 9362, 8192, 7282
+    .hword 13107, 11916, 10082, 9362, 8192, 7282
+    .hword 13107, 11916, 10082, 9362, 8192, 7282
+    .hword 13107, 11916, 10082, 9362, 8192, 7282
+    .hword 13107, 11916, 10082, 9362, 8192, 7282
+
+;//---------------------------------------------------------------
+;// This table contains ARM_M4P10_Q_OFFSET + 1 + (iQP / 6) values,
+;// for values of iQP from 0 to 51 (inclusive).
+;//---------------------------------------------------------------
+
+armVCM4P10_QPDivPlusOneTable:
+    .byte 16, 16, 16, 16, 16, 16
+    .byte 17, 17, 17, 17, 17, 17
+    .byte 18, 18, 18, 18, 18, 18
+    .byte 19, 19, 19, 19, 19, 19
+    .byte 20, 20, 20, 20, 20, 20
+    .byte 21, 21, 21, 21, 21, 21
+    .byte 22, 22, 22, 22, 22, 22
+    .byte 23, 23, 23, 23, 23, 23
+    .byte 24, 24, 24, 24, 24, 24
+
+    .end
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_TransformResidual4x4_s.S b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_TransformResidual4x4_s.S
new file mode 100644
index 0000000..c24d717
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_TransformResidual4x4_s.S
@@ -0,0 +1,52 @@
+/*
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ *
+ */
+
+    .eabi_attribute 24, 1
+    .eabi_attribute 25, 1
+
+    .arm
+    .fpu neon
+    .text
+
+    .global armVCM4P10_TransformResidual4x4
+    .func   armVCM4P10_TransformResidual4x4
+armVCM4P10_TransformResidual4x4:
+    VPUSH    {d8}
+    VLD4.16  {d0,d1,d2,d3},[r1]
+    VMOV.I16 d4,#0
+    VADD.I16 d5,d0,d2
+    VSUB.I16 d6,d0,d2
+    VHADD.S16 d7,d1,d4
+    VHADD.S16 d8,d3,d4
+    VSUB.I16 d7,d7,d3
+    VADD.I16 d8,d1,d8
+    VADD.I16 d0,d5,d8
+    VADD.I16 d1,d6,d7
+    VSUB.I16 d2,d6,d7
+    VSUB.I16 d3,d5,d8
+    VTRN.16  d0,d1
+    VTRN.16  d2,d3
+    VTRN.32  q0,q1
+    VADD.I16 d5,d0,d2
+    VSUB.I16 d6,d0,d2
+    VHADD.S16 d7,d1,d4
+    VHADD.S16 d8,d3,d4
+    VSUB.I16 d7,d7,d3
+    VADD.I16 d8,d1,d8
+    VADD.I16 d0,d5,d8
+    VADD.I16 d1,d6,d7
+    VSUB.I16 d2,d6,d7
+    VSUB.I16 d3,d5,d8
+    VRSHR.S16 d0,d0,#6
+    VRSHR.S16 d1,d1,#6
+    VRSHR.S16 d2,d2,#6
+    VRSHR.S16 d3,d3,#6
+    VST1.16  {d0,d1,d2,d3},[r0]
+    VPOP     {d8}
+    BX       lr
+    .endfunc
+
+    .end
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_UnpackBlock4x4_s.S b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_UnpackBlock4x4_s.S
new file mode 100644
index 0000000..c552f8d
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_UnpackBlock4x4_s.S
@@ -0,0 +1,40 @@
+/*
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ *
+ */
+
+    .eabi_attribute 24, 1
+    .eabi_attribute 25, 1
+
+    .arm
+    .fpu neon
+    .text
+
+    .global armVCM4P10_UnpackBlock4x4
+    .func   armVCM4P10_UnpackBlock4x4
+armVCM4P10_UnpackBlock4x4:
+    PUSH     {r4-r8,lr}
+    LDR      r2,[r0,#0]
+    MOV      r7,#0x1f
+    MOV      r4,#0
+    MOV      r5,#0
+    LDRB     r3,[r2],#1
+    STRD     r4,r5,[r1,#0]
+    STRD     r4,r5,[r1,#8]
+    STRD     r4,r5,[r1,#0x10]
+    STRD     r4,r5,[r1,#0x18]
+unpackLoop:
+    TST      r3,#0x10
+    LDRNESB  r5,[r2,#1]
+    LDRNEB   r4,[r2],#2
+    AND      r6,r7,r3,LSL #1
+    LDREQSB  r4,[r2],#1
+    ORRNE    r4,r4,r5,LSL #8
+    TST      r3,#0x20
+    LDREQB   r3,[r2],#1
+    STRH     r4,[r1,r6]
+    BEQ      unpackLoop
+    STR      r2,[r0,#0]
+    POP      {r4-r8,pc}
+    .endfunc
+    .end
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_DeblockLuma_I.S b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_DeblockLuma_I.S
new file mode 100644
index 0000000..ba61059
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_DeblockLuma_I.S
@@ -0,0 +1,67 @@
+/*
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ *
+ */
+
+    .eabi_attribute 24, 1
+    .eabi_attribute 25, 1
+
+    .arm
+    .fpu neon
+    .text
+
+    .global omxVCM4P10_DeblockLuma_I
+    .func   omxVCM4P10_DeblockLuma_I
+omxVCM4P10_DeblockLuma_I:
+    PUSH     {r4-r9,lr}
+    MOVS     r6,r0
+    SUB      sp,sp,#0xc
+    MOV      r9,r1
+    MOV      r7,r2
+    MOV      r8,r3
+    LDR      r4,[sp,#0x28]
+    LDR      r5,[sp,#0x2c]
+    BEQ      L0x58
+    TST      r6,#7
+    TSTEQ    r9,#7
+    BNE      L0x58
+    CMP      r7,#0
+    CMPNE    r8,#0
+    CMPNE    r4,#0
+    BEQ      L0x58
+    TST      r4,#3
+    BNE      L0x58
+    CMP      r5,#0
+    BEQ      L0x58
+    TST      r5,#3
+    BEQ      L0x64
+L0x58:
+    MVN      r0,#4
+L0x5c:
+    ADD      sp,sp,#0xc
+    POP      {r4-r9,pc}
+L0x64:
+    STR      r4,[sp,#0]
+    MOV      r3,r8
+    STR      r5,[sp,#4]
+    MOV      r2,r7
+    MOV      r1,r9
+    MOV      r0,r6
+    BL       omxVCM4P10_FilterDeblockingLuma_VerEdge_I
+    CMP      r0,#0
+    BNE      L0x5c
+    ADD      r3,r5,#0x10
+    ADD      r2,r4,#0x10
+    STR      r3,[sp,#4]
+    STR      r2,[sp,#0]
+    ADD      r3,r8,#2
+    ADD      r2,r7,#2
+    MOV      r1,r9
+    MOV      r0,r6
+    BL       omxVCM4P10_FilterDeblockingLuma_HorEdge_I
+    ADD      sp,sp,#0xc
+    POP      {r4-r9,pc}
+    .endfunc
+
+    .end
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_DequantTransformResidualFromPairAndAdd_s.S b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_DequantTransformResidualFromPairAndAdd_s.S
new file mode 100644
index 0000000..be21ee7
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_DequantTransformResidualFromPairAndAdd_s.S
@@ -0,0 +1,119 @@
+/*
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ *
+ */
+
+    .eabi_attribute 24, 1
+    .eabi_attribute 25, 1
+
+    .arm
+    .fpu neon
+    .text
+
+    .global omxVCM4P10_DequantTransformResidualFromPairAndAdd
+    .func   omxVCM4P10_DequantTransformResidualFromPairAndAdd
+omxVCM4P10_DequantTransformResidualFromPairAndAdd:
+    PUSH     {r4-r12,lr}
+    VPUSH    {d8-d9}
+    SUB      sp,sp,#0x20
+    ADD      r4,sp,#0
+    LDR      r5,[sp,#0x64]
+    MOV      r7,r1
+    MOV      r8,r2
+    MOV      r9,r3
+    CMP      r5,#0
+    BEQ      L0x114
+    MOV      r1,r4
+    BL       armVCM4P10_UnpackBlock4x4  ;//
+    LDR      r1,[sp,#0x60]
+    LDR      r11, =armVCM4P10_QPModuloTable
+    LDR      r10, =armVCM4P10_QPDivTable
+    LDR      r2,  =armVCM4P10_VMatrixU16
+    LDRSB    r12,[r11,r1]
+    LDRSB    lr,[r10,r1]
+    LDR      r10, =0x3020504
+    LDR      r1, =0x5040100
+    ADD      r2,r2,r12
+    VDUP.32  d7,r1
+    VDUP.32  d9,r10
+    VDUP.16  d5,lr
+    VLD1.8   {d6},[r2]
+    VTBL.8   d8,{d6},d7
+    VTBL.8   d4,{d6},d9
+    CMP      r8,#0
+    VLD1.16  {d0,d1,d2,d3},[r4]
+    VSHL.U16 d8,d8,d5
+    VSHL.U16 d4,d4,d5
+    BEQ      L1
+    LDRSH    r10,[r8,#0]
+L1:
+    VMUL.I16 d0,d0,d8
+    VMUL.I16 d1,d1,d4
+    VMUL.I16 d2,d2,d8
+    VMUL.I16 d3,d3,d4
+    VMOVNE.16 d0[0],r10
+    VTRN.16  d0,d1
+    VTRN.16  d2,d3
+    VTRN.32  q0,q1
+    VMOV.I16 d4,#0
+    VADD.I16 d5,d0,d2
+    VSUB.I16 d6,d0,d2
+    VHADD.S16 d7,d1,d4
+    VHADD.S16 d8,d3,d4
+    VSUB.I16 d7,d7,d3
+    VADD.I16 d8,d1,d8
+    VADD.I16 d0,d5,d8
+    VADD.I16 d1,d6,d7
+    VSUB.I16 d2,d6,d7
+    VSUB.I16 d3,d5,d8
+    VTRN.16  d0,d1
+    VTRN.16  d2,d3
+    VTRN.32  q0,q1
+    VADD.I16 d5,d0,d2
+    VSUB.I16 d6,d0,d2
+    VHADD.S16 d7,d1,d4
+    VHADD.S16 d8,d3,d4
+    VSUB.I16 d7,d7,d3
+    VADD.I16 d8,d1,d8
+    VADD.I16 d0,d5,d8
+    VADD.I16 d1,d6,d7
+    VSUB.I16 d2,d6,d7
+    VSUB.I16 d3,d5,d8
+    VRSHR.S16 d0,d0,#6
+    VRSHR.S16 d1,d1,#6
+    VRSHR.S16 d2,d2,#6
+    VRSHR.S16 d3,d3,#6
+    B        L0x130
+L0x114:
+    LDRSH    r10,[r8,#0]
+    ADD      r10,r10,#0x20
+    ASR      r10,r10,#6
+    VDUP.16  d0,r10
+    VDUP.16  d1,r10
+    VDUP.16  d2,r10
+    VDUP.16  d3,r10
+L0x130:
+    LDR      r1,[sp,#0x58]
+    LDR      r10,[sp,#0x5c]
+    LDR      r3,[r7],r1
+    LDR      r5,[r7],r1
+    VMOV     d4,r3,r5
+    LDR      r3,[r7],r1
+    LDR      r5,[r7,#0]
+    VMOV     d5,r3,r5
+    VADDW.U8 q3,q0,d4
+    VADDW.U8 q4,q1,d5
+    VQMOVUN.S16 d0,q3
+    VQMOVUN.S16 d1,q4
+    VST1.32  {d0[0]},[r9],r10
+    VST1.32  {d0[1]},[r9],r10
+    VST1.32  {d1[0]},[r9],r10
+    VST1.32  {d1[1]},[r9]
+    MOV      r0,#0
+    ADD      sp,sp,#0x20
+    VPOP     {d8-d9}
+    POP      {r4-r12,pc}
+    .endfunc
+
+    .end
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_FilterDeblockingChroma_HorEdge_I_s.S b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_FilterDeblockingChroma_HorEdge_I_s.S
new file mode 100644
index 0000000..79ba538
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_FilterDeblockingChroma_HorEdge_I_s.S
@@ -0,0 +1,87 @@
+/*
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ *
+ */
+
+    .eabi_attribute 24, 1
+    .eabi_attribute 25, 1
+
+    .arm
+    .fpu neon
+    .text
+
+    .global omxVCM4P10_FilterDeblockingChroma_HorEdge_I
+    .func   omxVCM4P10_FilterDeblockingChroma_HorEdge_I
+omxVCM4P10_FilterDeblockingChroma_HorEdge_I:
+    PUSH     {r4-r10,lr}
+    VPUSH    {d8-d15}
+    VLD1.8   {d0[]},[r2]!
+    SUB      r0,r0,r1,LSL #1
+    SUB      r0,r0,r1
+    VLD1.8   {d2[]},[r3]!
+    LDR      r4,[sp,#0x64]
+    LDR      r5,[sp,#0x60]
+    LDR      r9, =0x3030303
+    LDR      r8, =0x4040404
+    VMOV.I8  d14,#0
+    VMOV.I8  d15,#0x1
+    VMOV.I16 d1,#0x4
+    MOV      r7,#0x40000000
+L0x38:
+    LDR      r6,[r4],#8
+    VLD1.8   {d6},[r0],r1
+    VLD1.8   {d5},[r0],r1
+    CMP      r6,#0
+    VLD1.8   {d4},[r0],r1
+    VLD1.8   {d8},[r0],r1
+    VABD.U8  d19,d6,d4
+    VLD1.8   {d9},[r0],r1
+    VABD.U8  d13,d4,d8
+    VLD1.8   {d10},[r0],r1
+    BEQ      L0xe4
+    VABD.U8  d12,d5,d4
+    VABD.U8  d18,d9,d8
+    VCGT.U8  d16,d0,d13
+    VMOV.32  d26[0],r6
+    VMAX.U8  d12,d18,d12
+    VMOVL.U8 q13,d26
+    VABD.U8  d17,d10,d8
+    VCGT.S16 d27,d26,#0
+    VCGT.U8  d12,d2,d12
+    VCGT.U8  d19,d2,d19
+    VAND     d16,d16,d27
+    TST      r6,r9
+    VCGT.U8  d17,d2,d17
+    VAND     d16,d16,d12
+    VAND     d12,d16,d17
+    VAND     d17,d16,d19
+    BLNE     armVCM4P10_DeblockingChromabSLT4_unsafe
+    TST      r6,r8
+    SUB      r0,r0,r1,LSL #2
+    VTST.16  d26,d26,d1
+    BLNE     armVCM4P10_DeblockingChromabSGE4_unsafe
+    VBIT     d29,d13,d26
+    VBIT     d24,d31,d26
+    VBIF     d29,d4,d16
+    VBIF     d24,d8,d16
+    VST1.8   {d29},[r0],r1
+    ADDS     r7,r7,r7
+    VST1.8   {d24},[r0],r1
+    BNE      L0x38
+    MOV      r0,#0
+    VPOP     {d8-d15}
+    POP      {r4-r10,pc}
+L0xe4:
+    VLD1.8   {d0[]},[r2]
+    SUB      r0,r0,r1,LSL #1
+    ADDS     r7,r7,r7
+    VLD1.8   {d2[]},[r3]
+    ADD      r5,r5,#4
+    BNE      L0x38
+    MOV      r0,#0
+    VPOP     {d8-d15}
+    POP      {r4-r10,pc}
+    .endfunc
+
+    .end
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_FilterDeblockingChroma_VerEdge_I_s.S b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_FilterDeblockingChroma_VerEdge_I_s.S
new file mode 100644
index 0000000..dcdddbe
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_FilterDeblockingChroma_VerEdge_I_s.S
@@ -0,0 +1,123 @@
+/*
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ *
+ */
+
+    .eabi_attribute 24, 1
+    .eabi_attribute 25, 1
+
+    .arm
+    .fpu neon
+    .text
+
+    .global omxVCM4P10_FilterDeblockingChroma_VerEdge_I
+    .func   omxVCM4P10_FilterDeblockingChroma_VerEdge_I
+omxVCM4P10_FilterDeblockingChroma_VerEdge_I:
+    PUSH     {r4-r12,lr}
+    VPUSH    {d8-d15}
+    VLD1.8   {d0[]},[r2]!
+    SUB      r0,r0,#4
+    VLD1.8   {d2[]},[r3]!
+    LDR      r4,[sp,#0x6c]
+    LDR      r5,[sp,#0x68]
+    LDR      r8, =0x4040404
+    LDR      r9, =0x3030303
+    VMOV.I8  d14,#0
+    VMOV.I8  d15,#0x1
+    VMOV.I16 d1,#0x4
+    MOV      r7,#0x40000000
+L0x34:
+    LDR      r6,[r4],#8
+    ADD      r10,r0,r1
+    ADD      lr,r1,r1
+    VLD1.8   {d7},[r0],lr
+    VLD1.8   {d8},[r10],lr
+    VLD1.8   {d5},[r0],lr
+    VLD1.8   {d10},[r10],lr
+    VLD1.8   {d6},[r0],lr
+    VLD1.8   {d9},[r10],lr
+    VLD1.8   {d4},[r0],lr
+    VLD1.8   {d11},[r10],lr
+    VZIP.8   d7,d8
+    VZIP.8   d5,d10
+    VZIP.8   d6,d9
+    VZIP.8   d4,d11
+    VZIP.16  d7,d5
+    VZIP.16  d8,d10
+    VZIP.16  d6,d4
+    VZIP.16  d9,d11
+    VTRN.32  d7,d6
+    VTRN.32  d5,d4
+    VTRN.32  d10,d11
+    VTRN.32  d8,d9
+    CMP      r6,#0
+    VABD.U8  d19,d6,d4
+    VABD.U8  d13,d4,d8
+    BEQ      L0x170
+    VABD.U8  d12,d5,d4
+    VABD.U8  d18,d9,d8
+    VMOV.32  d26[0],r6
+    VCGT.U8  d16,d0,d13
+    VMAX.U8  d12,d18,d12
+    VMOVL.U8 q13,d26
+    VABD.U8  d17,d10,d8
+    VCGT.S16 d27,d26,#0
+    VCGT.U8  d12,d2,d12
+    VCGT.U8  d19,d2,d19
+    VAND     d16,d16,d27
+    TST      r6,r9
+    VCGT.U8  d17,d2,d17
+    VAND     d16,d16,d12
+    VAND     d12,d16,d17
+    VAND     d17,d16,d19
+    BLNE     armVCM4P10_DeblockingChromabSLT4_unsafe
+    TST      r6,r8
+    SUB      r0,r0,r1,LSL #3
+    VTST.16  d26,d26,d1
+    BLNE     armVCM4P10_DeblockingChromabSGE4_unsafe
+    VBIT     d29,d13,d26
+    VBIT     d24,d31,d26
+    ADD      r10,r0,#3
+    VBIF     d29,d4,d16
+    ADD      r12,r10,r1
+    ADD      lr,r1,r1
+    VBIF     d24,d8,d16
+    ADDS     r7,r7,r7
+    VST1.8   {d29[0]},[r10],lr
+    VST1.8   {d29[1]},[r12],lr
+    VST1.8   {d29[2]},[r10],lr
+    VST1.8   {d29[3]},[r12],lr
+    VST1.8   {d29[4]},[r10],lr
+    VST1.8   {d29[5]},[r12],lr
+    VST1.8   {d29[6]},[r10],lr
+    VST1.8   {d29[7]},[r12],lr
+    ADD      r12,r0,#4
+    ADD      r10,r12,r1
+    VST1.8   {d24[0]},[r12],lr
+    VST1.8   {d24[1]},[r10],lr
+    VST1.8   {d24[2]},[r12],lr
+    VST1.8   {d24[3]},[r10],lr
+    VST1.8   {d24[4]},[r12],lr
+    VST1.8   {d24[5]},[r10],lr
+    VST1.8   {d24[6]},[r12],lr
+    VST1.8   {d24[7]},[r10],lr
+    ADD      r0,r0,#4
+    BNE      L0x34
+    MOV      r0,#0
+    VPOP     {d8-d15}
+    POP      {r4-r12,pc}
+L0x170:
+    VLD1.8   {d0[]},[r2]
+    ADD      r0,r0,#4
+    SUB      r0,r0,r1,LSL #3
+    ADDS     r7,r7,r7
+    VLD1.8   {d2[]},[r3]
+    ADD      r5,r5,#4
+    BNE      L0x34
+    MOV      r0,#0
+    VPOP     {d8-d15}
+    POP      {r4-r12,pc}
+    .endfunc
+
+    .end
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_FilterDeblockingLuma_HorEdge_I_s.S b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_FilterDeblockingLuma_HorEdge_I_s.S
new file mode 100644
index 0000000..9755899
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_FilterDeblockingLuma_HorEdge_I_s.S
@@ -0,0 +1,107 @@
+/*
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ *
+ */
+
+    .eabi_attribute 24, 1
+    .eabi_attribute 25, 1
+
+    .arm
+    .fpu neon
+    .text
+
+    .global omxVCM4P10_FilterDeblockingLuma_HorEdge_I
+    .func   omxVCM4P10_FilterDeblockingLuma_HorEdge_I
+omxVCM4P10_FilterDeblockingLuma_HorEdge_I:
+    PUSH     {r4-r12,lr}
+    VPUSH    {d8-d15}
+    ADD      r7,r2,#1
+    ADD      r8,r3,#1
+    VLD1.8   {d0[]},[r2]
+    SUB      r0,r0,r1,LSL #2
+    VLD1.8   {d2[]},[r3]
+    LDR      r4,[sp,#0x6c]
+    LDR      r5,[sp,#0x68]
+    MOV      r11,#0
+    VMOV.I8  d14,#0
+    VMOV.I8  d15,#0x1
+    ADD      r10,r1,r1
+    MOV      r9,#0x55000000
+L0x38:
+    LDRH     r12,[r4],#2
+    ADD      r6,r0,r1
+    CMP      r12,#0
+    BEQ      L0xe4
+    VLD1.8   {d7},[r0],r10
+    VLD1.8   {d6},[r6],r10
+    VLD1.8   {d5},[r0],r10
+    VLD1.8   {d4},[r6],r10
+    VLD1.8   {d8},[r0],r10
+    VABD.U8  d12,d4,d5
+    VLD1.8   {d9},[r6]
+    VABD.U8  d13,d8,d4
+    VLD1.8   {d10},[r0],r1
+    VABD.U8  d18,d9,d8
+    VABD.U8  d19,d6,d4
+    VCGT.U8  d16,d0,d13
+    TST      r12,#0xff
+    VMAX.U8  d12,d18,d12
+    VABD.U8  d17,d10,d8
+    VMOVEQ.32 d16[0],r11
+    TST      r12,#0xff00
+    VCGT.U8  d19,d2,d19
+    VCGT.U8  d12,d2,d12
+    VMOVEQ.32 d16[1],r11
+    VCGT.U8  d17,d2,d17
+    VLD1.8   {d11},[r0]
+    VAND     d16,d16,d12
+    TST      r12,#4
+    VAND     d12,d16,d17
+    VAND     d17,d16,d19
+    BNE      L0xf8
+    SUB      r0,r0,r1,LSL #2
+    SUB      r0,r0,r1
+    BL       armVCM4P10_DeblockingLumabSLT4_unsafe
+    VST1.8   {d30},[r0],r1
+    VST1.8   {d29},[r0],r1
+    SUB      r6,r0,r1,LSL #2
+    VST1.8   {d24},[r0],r1
+    ADDS     r9,r9,r9
+    VST1.8   {d25},[r0]
+    ADD      r0,r6,#8
+    BCC      L0x38
+    B        L0x130
+L0xe4:
+    ADD      r0,r0,#8
+    ADDS     r9,r9,r9
+    ADD      r5,r5,#2
+    BCC      L0x38
+    B        L0x130
+L0xf8:
+    SUB      r0,r0,r1,LSL #2
+    SUB      r0,r0,r1,LSL #1
+    BL       armVCM4P10_DeblockingLumabSGE4_unsafe
+    VST1.8   {d31},[r0],r1
+    VST1.8   {d30},[r0],r1
+    VST1.8   {d29},[r0],r1
+    SUB      r6,r0,r1,LSL #2
+    VST1.8   {d24},[r0],r1
+    ADDS     r9,r9,r9
+    VST1.8   {d25},[r0],r1
+    ADD      r5,r5,#2
+    VST1.8   {d28},[r0]
+    ADD      r0,r6,#8
+    BCC      L0x38
+L0x130:
+    SUB      r0,r0,#0x10
+    VLD1.8   {d0[]},[r7]
+    ADD      r0,r0,r1,LSL #2
+    VLD1.8   {d2[]},[r8]
+    BNE      L0x38
+    MOV      r0,#0
+    VPOP     {d8-d15}
+    POP      {r4-r12,pc}
+    .endfunc
+
+    .end
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_FilterDeblockingLuma_VerEdge_I_s.S b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_FilterDeblockingLuma_VerEdge_I_s.S
new file mode 100644
index 0000000..66cc32ea
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_FilterDeblockingLuma_VerEdge_I_s.S
@@ -0,0 +1,157 @@
+/*
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ *
+ */
+
+    .eabi_attribute 24, 1
+    .eabi_attribute 25, 1
+
+    .arm
+    .fpu neon
+    .text
+
+    .global omxVCM4P10_FilterDeblockingLuma_VerEdge_I
+    .func   omxVCM4P10_FilterDeblockingLuma_VerEdge_I
+omxVCM4P10_FilterDeblockingLuma_VerEdge_I:
+    PUSH     {r4-r12,lr}
+    VPUSH    {d8-d15}
+    ADD      r7,r2,#1
+    ADD      r8,r3,#1
+    VLD1.8   {d0[]},[r2]
+    SUB      r0,r0,#4
+    VLD1.8   {d2[]},[r3]
+    LDR      r4,[sp,#0x6c]
+    LDR      r5,[sp,#0x68]
+    MOV      r6,#0
+    VMOV.I8  d14,#0
+    VMOV.I8  d15,#0x1
+    MOV      r9,#0x11000000
+    ADD      r11,r1,r1
+L0x38:
+    LDRH     r12,[r4],#4
+    CMP      r12,#0
+    BEQ      L0x160
+    ADD      r10,r0,r1
+    VLD1.8   {d7},[r0],r11
+    VLD1.8   {d8},[r10],r11
+    VLD1.8   {d5},[r0],r11
+    VZIP.8   d7,d8
+    VLD1.8   {d10},[r10],r11
+    VLD1.8   {d6},[r0],r11
+    VZIP.8   d5,d10
+    VLD1.8   {d9},[r10],r11
+    VLD1.8   {d4},[r0],r11
+    VLD1.8   {d11},[r10],r11
+    VZIP.8   d6,d9
+    VZIP.16  d8,d10
+    VZIP.8   d4,d11
+    SUB      r0,r0,r1,LSL #3
+    VZIP.16  d7,d5
+    VZIP.16  d9,d11
+    VZIP.16  d6,d4
+    VTRN.32  d8,d9
+    VTRN.32  d5,d4
+    VTRN.32  d10,d11
+    VTRN.32  d7,d6
+    VABD.U8  d13,d4,d8
+    VABD.U8  d12,d5,d4
+    VABD.U8  d18,d9,d8
+    VABD.U8  d19,d6,d4
+    TST      r12,#0xff
+    VCGT.U8  d16,d0,d13
+    VMAX.U8  d12,d18,d12
+    VABD.U8  d17,d10,d8
+    VMOVEQ.32 d16[0],r6
+    TST      r12,#0xff00
+    VCGT.U8  d19,d2,d19
+    VCGT.U8  d12,d2,d12
+    VMOVEQ.32 d16[1],r6
+    VCGT.U8  d17,d2,d17
+    VAND     d16,d16,d12
+    TST      r12,#4
+    VAND     d12,d16,d17
+    VAND     d17,d16,d19
+    BNE      L0x17c
+    BL       armVCM4P10_DeblockingLumabSLT4_unsafe
+    VZIP.8   d7,d6
+    VZIP.8   d30,d29
+    VZIP.8   d24,d25
+    VZIP.8   d10,d11
+    VZIP.16  d7,d30
+    ADD      r10,r0,r1
+    VZIP.16  d24,d10
+    VZIP.16  d25,d11
+    VZIP.16  d6,d29
+    VTRN.32  d7,d24
+    VTRN.32  d30,d10
+    VTRN.32  d6,d25
+    VTRN.32  d29,d11
+    VST1.8   {d7},[r0],r11
+    VST1.8   {d24},[r10],r11
+    VST1.8   {d30},[r0],r11
+    VST1.8   {d10},[r10],r11
+    VST1.8   {d6},[r0],r11
+    VST1.8   {d25},[r10],r11
+    ADDS     r9,r9,r9
+    VST1.8   {d29},[r0],r11
+    ADD      r5,r5,#2
+    VST1.8   {d11},[r10],r1
+    SUB      r0,r0,r1,LSL #3
+    VLD1.8   {d0[]},[r7]
+    ADD      r0,r0,#4
+    VLD1.8   {d2[]},[r8]
+    BCC      L0x38
+    B        L0x1f0
+L0x160:
+    ADD      r0,r0,#4
+    ADDS     r9,r9,r9
+    VLD1.8   {d0[]},[r7]
+    ADD      r5,r5,#4
+    VLD1.8   {d2[]},[r8]
+    BCC      L0x38
+    B        L0x1f0
+L0x17c:
+    BL       armVCM4P10_DeblockingLumabSGE4_unsafe
+    VZIP.8   d7,d31
+    VZIP.8   d30,d29
+    VZIP.8   d24,d25
+    VZIP.8   d28,d11
+    VZIP.16  d7,d30
+    ADD      r10,r0,r1
+    VZIP.16  d24,d28
+    VZIP.16  d25,d11
+    VZIP.16  d31,d29
+    VTRN.32  d7,d24
+    VTRN.32  d30,d28
+    VTRN.32  d31,d25
+    VTRN.32  d29,d11
+    VST1.8   {d7},[r0],r11
+    VST1.8   {d24},[r10],r11
+    VST1.8   {d30},[r0],r11
+    VST1.8   {d28},[r10],r11
+    VST1.8   {d31},[r0],r11
+    VST1.8   {d25},[r10],r11
+    ADDS     r9,r9,r9
+    VST1.8   {d29},[r0],r11
+    ADD      r5,r5,#4
+    VST1.8   {d11},[r10],r11
+    SUB      r0,r0,r1,LSL #3
+    VLD1.8   {d0[]},[r7]
+    ADD      r0,r0,#4
+    VLD1.8   {d2[]},[r8]
+    BCC      L0x38
+L0x1f0:
+    SUB      r4,r4,#0xe
+    SUB      r5,r5,#0xe
+    SUB      r0,r0,#0x10
+    VLD1.8   {d0[]},[r2]
+    ADD      r0,r0,r1,LSL #3
+    VLD1.8   {d2[]},[r3]
+    BNE      L0x38
+    MOV      r0,#0
+    VPOP     {d8-d15}
+    POP      {r4-r12,pc}
+    .endfunc
+
+    .end
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_InterpolateLuma_s.S b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_InterpolateLuma_s.S
new file mode 100644
index 0000000..76c3d7d
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_InterpolateLuma_s.S
@@ -0,0 +1,323 @@
+/*
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ *
+ */
+
+    .eabi_attribute 24, 1
+    .eabi_attribute 25, 1
+
+    .arm
+    .fpu neon
+    .text
+
+    .global omxVCM4P10_InterpolateLuma
+    .func   omxVCM4P10_InterpolateLuma
+omxVCM4P10_InterpolateLuma:
+    PUSH     {r4-r12,lr}
+    VPUSH    {d8-d15}
+    SUB      sp,sp,#0x10
+    LDR      r6,[sp,#0x78]
+    LDR      r7,[sp,#0x7c]
+    LDR      r5,[sp,#0x80]
+    LDR      r4,[sp,#0x84]
+    ADD      r6,r6,r7,LSL #2
+    ADD      r11,sp,#0
+    VMOV.I16 d31,#0x14
+    VMOV.I16 d30,#0x5
+L0x2c:
+    STM      r11,{r0-r3}
+    ADD      pc,pc,r6,LSL #2
+    B        L0x3f0
+    B        L0x78
+    B        L0xa8
+    B        L0xdc
+    B        L0x100
+    B        L0x134
+    B        L0x168
+    B        L0x1a8
+    B        L0x1f0
+    B        L0x234
+    B        L0x258
+    B        L0x2b0
+    B        L0x2d8
+    B        L0x330
+    B        L0x364
+    B        L0x3a8
+    B        L0x3f0
+L0x78:
+    ADD      r12,r0,r1,LSL #1
+    VLD1.8   {d9},[r0],r1
+    VLD1.8   {d11},[r12],r1
+    VLD1.8   {d10},[r0]
+    VLD1.8   {d12},[r12]
+    ADD      r12,r2,r3,LSL #1
+    VST1.32  {d9[0]},[r2],r3
+    VST1.32  {d11[0]},[r12],r3
+    VST1.32  {d10[0]},[r2]
+    VST1.32  {d12[0]},[r12]
+    ADD      r11,sp,#0
+    B        L0x434
+L0xa8:
+    SUB      r0,r0,#2
+    BL       armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe
+    VRHADD.U8 d22,d22,d14
+    VRHADD.U8 d26,d26,d18
+    VRHADD.U8 d24,d24,d16
+    VRHADD.U8 d28,d28,d20
+    ADD      r12,r2,r3,LSL #1
+    VST1.32  {d22[0]},[r2],r3
+    VST1.32  {d26[0]},[r12],r3
+    VST1.32  {d24[0]},[r2]
+    VST1.32  {d28[0]},[r12]
+    ADD      r11,sp,#0
+    B        L0x434
+L0xdc:
+    SUB      r0,r0,#2
+    BL       armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe
+    ADD      r12,r2,r3,LSL #1
+    VST1.32  {d22[0]},[r2],r3
+    VST1.32  {d26[0]},[r12],r3
+    VST1.32  {d24[0]},[r2]
+    VST1.32  {d28[0]},[r12]
+    ADD      r11,sp,#0
+    B        L0x434
+L0x100:
+    SUB      r0,r0,#2
+    BL       armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe
+    VRHADD.U8 d22,d22,d15
+    VRHADD.U8 d26,d26,d19
+    VRHADD.U8 d24,d24,d17
+    VRHADD.U8 d28,d28,d21
+    ADD      r12,r2,r3,LSL #1
+    VST1.32  {d22[0]},[r2],r3
+    VST1.32  {d26[0]},[r12],r3
+    VST1.32  {d24[0]},[r2]
+    VST1.32  {d28[0]},[r12]
+    ADD      r11,sp,#0
+    B        L0x434
+L0x134:
+    SUB      r0,r0,r1,LSL #1
+    BL       armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe
+    VRHADD.U8 d0,d0,d9
+    VRHADD.U8 d4,d4,d11
+    VRHADD.U8 d2,d2,d10
+    VRHADD.U8 d6,d6,d12
+    ADD      r12,r2,r3,LSL #1
+    VST1.32  {d0[0]},[r2],r3
+    VST1.32  {d4[0]},[r12],r3
+    VST1.32  {d2[0]},[r2]
+    VST1.32  {d6[0]},[r12]
+    ADD      r11,sp,#0
+    B        L0x434
+L0x168:
+    MOV      r8,r0
+    SUB      r0,r0,r1,LSL #1
+    BL       armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe
+    SUB      r0,r8,#2
+    BL       armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe
+    VRHADD.U8 d22,d22,d0
+    VRHADD.U8 d26,d26,d4
+    VRHADD.U8 d24,d24,d2
+    VRHADD.U8 d28,d28,d6
+    ADD      r12,r2,r3,LSL #1
+    VST1.32  {d22[0]},[r2],r3
+    VST1.32  {d26[0]},[r12],r3
+    VST1.32  {d24[0]},[r2]
+    VST1.32  {d28[0]},[r12]
+    ADD      r11,sp,#0
+    B        L0x434
+L0x1a8:
+    SUB      r0,r0,r1,LSL #1
+    SUB      r0,r0,#2
+    BL       armVCM4P10_InterpolateLuma_HalfDiagHorVer4x4_unsafe
+    VQRSHRUN.S16 d14,q7,#5
+    VQRSHRUN.S16 d16,q8,#5
+    VQRSHRUN.S16 d18,q9,#5
+    VQRSHRUN.S16 d20,q10,#5
+    VRHADD.U8 d0,d0,d14
+    VRHADD.U8 d4,d4,d18
+    VRHADD.U8 d2,d2,d16
+    VRHADD.U8 d6,d6,d20
+    ADD      r12,r2,r3,LSL #1
+    VST1.32  {d0[0]},[r2],r3
+    VST1.32  {d4[0]},[r12],r3
+    VST1.32  {d2[0]},[r2]
+    VST1.32  {d6[0]},[r12]
+    ADD      r11,sp,#0
+    B        L0x434
+L0x1f0:
+    MOV      r8,r0
+    ADD      r0,r0,#1
+    SUB      r0,r0,r1,LSL #1
+    BL       armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe
+    SUB      r0,r8,#2
+    BL       armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe
+    VRHADD.U8 d22,d22,d0
+    VRHADD.U8 d26,d26,d4
+    VRHADD.U8 d24,d24,d2
+    VRHADD.U8 d28,d28,d6
+    ADD      r12,r2,r3,LSL #1
+    VST1.32  {d22[0]},[r2],r3
+    VST1.32  {d26[0]},[r12],r3
+    VST1.32  {d24[0]},[r2]
+    VST1.32  {d28[0]},[r12]
+    ADD      r11,sp,#0
+    B        L0x434
+L0x234:
+    SUB      r0,r0,r1,LSL #1
+    BL       armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe
+    ADD      r12,r2,r3,LSL #1
+    VST1.32  {d0[0]},[r2],r3
+    VST1.32  {d4[0]},[r12],r3
+    VST1.32  {d2[0]},[r2]
+    VST1.32  {d6[0]},[r12]
+    ADD      r11,sp,#0
+    B        L0x434
+L0x258:
+    SUB      r0,r0,r1,LSL #1
+    SUB      r0,r0,#2
+    BL       armVCM4P10_InterpolateLuma_HalfDiagVerHor4x4_unsafe
+    VEXT.8   d18,d18,d19,#4
+    VEXT.8   d20,d20,d21,#4
+    VEXT.8   d22,d22,d23,#4
+    VEXT.8   d24,d24,d25,#4
+    VQRSHRUN.S16 d14,q9,#5
+    VQRSHRUN.S16 d16,q10,#5
+    VQRSHRUN.S16 d18,q11,#5
+    VQRSHRUN.S16 d20,q12,#5
+    VRHADD.U8 d0,d0,d14
+    VRHADD.U8 d4,d4,d18
+    VRHADD.U8 d2,d2,d16
+    VRHADD.U8 d6,d6,d20
+    ADD      r12,r2,r3,LSL #1
+    VST1.32  {d0[0]},[r2],r3
+    VST1.32  {d4[0]},[r12],r3
+    VST1.32  {d2[0]},[r2]
+    VST1.32  {d6[0]},[r12]
+    ADD      r11,sp,#0
+    B        L0x434
+L0x2b0:
+    SUB      r0,r0,r1,LSL #1
+    SUB      r0,r0,#2
+    BL       armVCM4P10_InterpolateLuma_HalfDiagHorVer4x4_unsafe
+    ADD      r12,r2,r3,LSL #1
+    VST1.32  {d0[0]},[r2],r3
+    VST1.32  {d4[0]},[r12],r3
+    VST1.32  {d2[0]},[r2]
+    VST1.32  {d6[0]},[r12]
+    ADD      r11,sp,#0
+    B        L0x434
+L0x2d8:
+    SUB      r0,r0,r1,LSL #1
+    SUB      r0,r0,#2
+    BL       armVCM4P10_InterpolateLuma_HalfDiagVerHor4x4_unsafe
+    VEXT.8   d18,d18,d19,#6
+    VEXT.8   d20,d20,d21,#6
+    VEXT.8   d22,d22,d23,#6
+    VEXT.8   d24,d24,d25,#6
+    VQRSHRUN.S16 d14,q9,#5
+    VQRSHRUN.S16 d16,q10,#5
+    VQRSHRUN.S16 d18,q11,#5
+    VQRSHRUN.S16 d20,q12,#5
+    VRHADD.U8 d0,d0,d14
+    VRHADD.U8 d4,d4,d18
+    VRHADD.U8 d2,d2,d16
+    VRHADD.U8 d6,d6,d20
+    ADD      r12,r2,r3,LSL #1
+    VST1.32  {d0[0]},[r2],r3
+    VST1.32  {d4[0]},[r12],r3
+    VST1.32  {d2[0]},[r2]
+    VST1.32  {d6[0]},[r12]
+    ADD      r11,sp,#0
+    B        L0x434
+L0x330:
+    SUB      r0,r0,r1,LSL #1
+    BL       armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe
+    VRHADD.U8 d0,d0,d10
+    VRHADD.U8 d4,d4,d12
+    VRHADD.U8 d2,d2,d11
+    VRHADD.U8 d6,d6,d13
+    ADD      r12,r2,r3,LSL #1
+    VST1.32  {d0[0]},[r2],r3
+    VST1.32  {d4[0]},[r12],r3
+    VST1.32  {d2[0]},[r2]
+    VST1.32  {d6[0]},[r12]
+    ADD      r11,sp,#0
+    B        L0x434
+L0x364:
+    MOV      r8,r0
+    SUB      r0,r0,r1,LSL #1
+    BL       armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe
+    ADD      r0,r8,r1
+    SUB      r0,r0,#2
+    BL       armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe
+    VRHADD.U8 d22,d22,d0
+    VRHADD.U8 d26,d26,d4
+    VRHADD.U8 d24,d24,d2
+    VRHADD.U8 d28,d28,d6
+    ADD      r12,r2,r3,LSL #1
+    VST1.32  {d22[0]},[r2],r3
+    VST1.32  {d26[0]},[r12],r3
+    VST1.32  {d24[0]},[r2]
+    VST1.32  {d28[0]},[r12]
+    ADD      r11,sp,#0
+    B        L0x434
+L0x3a8:
+    SUB      r0,r0,r1,LSL #1
+    SUB      r0,r0,#2
+    BL       armVCM4P10_InterpolateLuma_HalfDiagHorVer4x4_unsafe
+    VQRSHRUN.S16 d14,q8,#5
+    VQRSHRUN.S16 d16,q9,#5
+    VQRSHRUN.S16 d18,q10,#5
+    VQRSHRUN.S16 d20,q11,#5
+    VRHADD.U8 d0,d0,d14
+    VRHADD.U8 d4,d4,d18
+    VRHADD.U8 d2,d2,d16
+    VRHADD.U8 d6,d6,d20
+    ADD      r12,r2,r3,LSL #1
+    VST1.32  {d0[0]},[r2],r3
+    VST1.32  {d4[0]},[r12],r3
+    VST1.32  {d2[0]},[r2]
+    VST1.32  {d6[0]},[r12]
+    ADD      r11,sp,#0
+    B        L0x434
+L0x3f0:
+    MOV      r8,r0
+    ADD      r0,r0,#1
+    SUB      r0,r0,r1,LSL #1
+    BL       armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe
+    ADD      r0,r8,r1
+    SUB      r0,r0,#2
+    BL       armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe
+    VRHADD.U8 d22,d22,d0
+    VRHADD.U8 d26,d26,d4
+    VRHADD.U8 d24,d24,d2
+    VRHADD.U8 d28,d28,d6
+    ADD      r12,r2,r3,LSL #1
+    VST1.32  {d22[0]},[r2],r3
+    VST1.32  {d26[0]},[r12],r3
+    VST1.32  {d24[0]},[r2]
+    VST1.32  {d28[0]},[r12]
+    ADD      r11,sp,#0
+L0x434:
+    LDM      r11,{r0-r3}
+    SUBS     r5,r5,#4
+    ADD      r0,r0,#4
+    ADD      r2,r2,#4
+    BGT      L0x2c
+    SUBS     r4,r4,#4
+    LDR      r5,[sp,#0x80]
+    ADD      r11,sp,#0
+    ADD      r0,r0,r1,LSL #2
+    ADD      r2,r2,r3,LSL #2
+    SUB      r0,r0,r5
+    SUB      r2,r2,r5
+    BGT      L0x2c
+    MOV      r0,#0
+    ADD      sp,sp,#0x10
+    VPOP     {d8-d15}
+    POP      {r4-r12,pc}
+    .endfunc
+
+    .end
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_PredictIntraChroma_8x8_s.S b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_PredictIntraChroma_8x8_s.S
new file mode 100644
index 0000000..0d49e4b
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_PredictIntraChroma_8x8_s.S
@@ -0,0 +1,217 @@
+/*
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ *
+ */
+
+    .eabi_attribute 24, 1
+    .eabi_attribute 25, 1
+
+    .arm
+    .fpu neon
+    .section .rodata
+    .align 4
+
+armVCM4P10_pIndexTable8x8:
+    .word  OMX_VC_CHROMA_DC,     OMX_VC_CHROMA_HOR
+    .word  OMX_VC_CHROMA_VERT,   OMX_VC_CHROMA_PLANE
+
+armVCM4P10_MultiplierTableChroma8x8:
+    .hword   3, 2, 1,4
+    .hword  -3,-2,-1,0
+    .hword   1, 2, 3,4
+
+
+    .text
+    .global omxVCM4P10_PredictIntraChroma_8x8
+    .func   omxVCM4P10_PredictIntraChroma_8x8
+omxVCM4P10_PredictIntraChroma_8x8:
+    PUSH     {r4-r10,lr}
+    VPUSH    {d8-d15}
+    LDR      r8, =armVCM4P10_pIndexTable8x8
+    LDR      r6,[sp,#0x68]
+    LDR      r4,[sp,#0x60]
+    LDR      r5,[sp,#0x64]
+    LDR      r7,[sp,#0x6c]
+    LDR      pc,[r8,r6,LSL #2]
+OMX_VC_CHROMA_DC:
+    TST      r7,#2
+    BEQ      L0xe8
+    ADD      r9,r0,r4
+    ADD      r10,r4,r4
+    VLD1.8   {d1[0]},[r0],r10
+    VLD1.8   {d1[1]},[r9],r10
+    VLD1.8   {d1[2]},[r0],r10
+    VLD1.8   {d1[3]},[r9],r10
+    VLD1.8   {d1[4]},[r0],r10
+    VLD1.8   {d1[5]},[r9],r10
+    VLD1.8   {d1[6]},[r0],r10
+    VLD1.8   {d1[7]},[r9]
+    TST      r7,#1
+    BEQ      L0xcc
+    VLD1.8   {d0},[r1]
+    MOV      r0,#0
+    VPADDL.U8 d2,d0
+    VPADDL.U16 d3,d2
+    VPADDL.U8 d2,d1
+    VPADDL.U16 d1,d2
+    VADD.I32 d2,d3,d1
+    VRSHR.U32 d2,d2,#3
+    VRSHR.U32 d3,d3,#2
+    VRSHR.U32 d1,d1,#2
+    VMOV.I8  d5,#0xc
+    VMOV.I8  d6,#0x4
+    VSHL.I64 d5,d5,#32
+    VSHR.U64 d6,d6,#32
+    VADD.I8  d6,d6,d5
+    VTBL.8   d0,{d2-d3},d5
+    VTBL.8   d4,{d1-d2},d6
+L0x9c:
+    ADD      r9,r3,r5
+    ADD      r10,r5,r5
+    VST1.8   {d0},[r3],r10
+    VST1.8   {d0},[r9],r10
+    VST1.8   {d0},[r3],r10
+    VST1.8   {d0},[r9],r10
+    VST1.8   {d4},[r3],r10
+    VST1.8   {d4},[r9],r10
+    VST1.8   {d4},[r3],r10
+    VST1.8   {d4},[r9]
+    VPOP     {d8-d15}
+    POP      {r4-r10,pc}
+L0xcc:
+    MOV      r0,#0
+    VPADDL.U8 d2,d1
+    VPADDL.U16 d1,d2
+    VRSHR.U32 d1,d1,#2
+    VDUP.8   d0,d1[0]
+    VDUP.8   d4,d1[4]
+    B        L0x9c
+L0xe8:
+    TST      r7,#1
+    BEQ      L0x114
+    VLD1.8   {d0},[r1]
+    MOV      r0,#0
+    VPADDL.U8 d2,d0
+    VPADDL.U16 d3,d2
+    VRSHR.U32 d3,d3,#2
+    VMOV.I8  d5,#0x4
+    VSHL.I64 d5,d5,#32
+    VTBL.8   d0,{d3},d5
+    B        L0x11c
+L0x114:
+    VMOV.I8  d0,#0x80
+    MOV      r0,#0
+L0x11c:
+    ADD      r9,r3,r5
+    ADD      r10,r5,r5
+    VST1.8   {d0},[r3],r10
+    VST1.8   {d0},[r9],r10
+    VST1.8   {d0},[r3],r10
+    VST1.8   {d0},[r9],r10
+    VST1.8   {d0},[r3],r10
+    VST1.8   {d0},[r9],r10
+    VST1.8   {d0},[r3],r10
+    VST1.8   {d0},[r9]
+    VPOP     {d8-d15}
+    POP      {r4-r10,pc}
+OMX_VC_CHROMA_VERT:
+    VLD1.8   {d0},[r1]
+    MOV      r0,#0
+    B        L0x11c
+OMX_VC_CHROMA_HOR:
+    ADD      r9,r0,r4
+    ADD      r10,r4,r4
+    VLD1.8   {d0[]},[r0],r10
+    VLD1.8   {d1[]},[r9],r10
+    VLD1.8   {d2[]},[r0],r10
+    VLD1.8   {d3[]},[r9],r10
+    VLD1.8   {d4[]},[r0],r10
+    VLD1.8   {d5[]},[r9],r10
+    VLD1.8   {d6[]},[r0],r10
+    VLD1.8   {d7[]},[r9]
+    B        L0x28c
+OMX_VC_CHROMA_PLANE:
+    ADD      r9,r0,r4
+    ADD      r10,r4,r4
+    VLD1.8   {d0},[r1]
+    VLD1.8   {d2[0]},[r2]
+    VLD1.8   {d1[0]},[r0],r10
+    VLD1.8   {d1[1]},[r9],r10
+    VLD1.8   {d1[2]},[r0],r10
+    VLD1.8   {d1[3]},[r9],r10
+    VLD1.8   {d1[4]},[r0],r10
+    VLD1.8   {d1[5]},[r9],r10
+    VLD1.8   {d1[6]},[r0],r10
+    VLD1.8   {d1[7]},[r9]
+    VREV64.8 d3,d0
+    VSUBL.U8 q3,d3,d2
+    VSHR.U64 d3,d3,#8
+    VSUBL.U8 q2,d3,d0
+    VREV64.8 d3,d1
+    VSUBL.U8 q7,d3,d2
+    VSHR.U64 d3,d3,#8
+    VSUBL.U8 q6,d3,d1
+    LDR      r2, =armVCM4P10_MultiplierTableChroma8x8
+    VSHL.I64 d4,d4,#16
+    VEXT.8   d9,d4,d6,#2
+    VLD1.16  {d10},[r2]!
+    VSHL.I64 d12,d12,#16
+    VEXT.8   d16,d12,d14,#2
+    VMUL.I16 d11,d9,d10
+    VMUL.I16 d3,d16,d10
+    VPADD.I16 d3,d11,d3
+    VPADDL.S16 d3,d3
+    VSHL.I32 d2,d3,#4
+    VADD.I32 d3,d3,d2
+    VLD1.16  {d10,d11},[r2]
+    VRSHR.S32 d3,d3,#5
+    VADDL.U8 q0,d0,d1
+    VDUP.16  q0,d1[3]
+    VSHL.I16 q0,q0,#4
+    VDUP.16  q2,d3[0]
+    VDUP.16  q3,d3[2]
+    VMUL.I16 q2,q2,q5
+    VMUL.I16 q3,q3,q5
+    VADD.I16 q2,q2,q0
+    VDUP.16  q0,d6[0]
+    VDUP.16  q1,d6[1]
+    VDUP.16  q4,d6[2]
+    VDUP.16  q5,d6[3]
+    VDUP.16  q6,d7[0]
+    VDUP.16  q7,d7[1]
+    VDUP.16  q8,d7[2]
+    VDUP.16  q9,d7[3]
+    VADD.I16 q0,q2,q0
+    VADD.I16 q1,q2,q1
+    VADD.I16 q4,q2,q4
+    VADD.I16 q5,q2,q5
+    VADD.I16 q6,q2,q6
+    VADD.I16 q7,q2,q7
+    VADD.I16 q8,q2,q8
+    VADD.I16 q9,q2,q9
+    VQRSHRUN.S16 d0,q0,#5
+    VQRSHRUN.S16 d1,q1,#5
+    VQRSHRUN.S16 d2,q4,#5
+    VQRSHRUN.S16 d3,q5,#5
+    VQRSHRUN.S16 d4,q6,#5
+    VQRSHRUN.S16 d5,q7,#5
+    VQRSHRUN.S16 d6,q8,#5
+    VQRSHRUN.S16 d7,q9,#5
+L0x28c:
+    ADD      r9,r3,r5
+    ADD      r10,r5,r5
+    VST1.8   {d0},[r3],r10
+    VST1.8   {d1},[r9],r10
+    VST1.8   {d2},[r3],r10
+    VST1.8   {d3},[r9],r10
+    VST1.8   {d4},[r3],r10
+    VST1.8   {d5},[r9],r10
+    VST1.8   {d6},[r3],r10
+    VST1.8   {d7},[r9]
+    MOV      r0,#0
+    VPOP     {d8-d15}
+    POP      {r4-r10,pc}
+    .endfunc
+
+    .end
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_PredictIntra_16x16_s.S b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_PredictIntra_16x16_s.S
new file mode 100644
index 0000000..53268f6
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_PredictIntra_16x16_s.S
@@ -0,0 +1,239 @@
+/*
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ *
+ */
+
+    .eabi_attribute 24, 1
+    .eabi_attribute 25, 1
+
+    .arm
+    .fpu neon
+
+    .section .rodata
+    .align 4
+;//-------------------------------------------------------
+;// This table for implementing switch case of C in asm by
+;// the mehtod of two levels of indexing.
+;//-------------------------------------------------------
+
+armVCM4P10_pIndexTable16x16:
+    .word  OMX_VC_16X16_VERT, OMX_VC_16X16_HOR
+    .word  OMX_VC_16X16_DC,   OMX_VC_16X16_PLANE
+
+
+
+armVCM4P10_MultiplierTable16x16:
+    .hword   7,  6,  5,  4,  3,  2,  1,  8
+    .hword   0,  1,  2,  3,  4,  5,  6,  7
+    .hword   8,  9, 10, 11, 12, 13, 14, 15
+
+    .text
+
+    .global omxVCM4P10_PredictIntra_16x16
+    .func   omxVCM4P10_PredictIntra_16x16
+omxVCM4P10_PredictIntra_16x16:
+    PUSH     {r4-r12,lr}
+    VPUSH    {d8-d15}
+    LDR      r9, =armVCM4P10_pIndexTable16x16
+    LDR      r6,[sp,#0x70]
+    LDR      r4,[sp,#0x68]
+    LDR      r5,[sp,#0x6c]
+    LDR      r7,[sp,#0x74]
+    MOV      r12,#0x10
+    LDR      pc,[r9,r6,LSL #2]
+OMX_VC_16X16_VERT:
+    VLD1.8   {d0,d1},[r1]
+    ADD      r8,r3,r5
+    ADD      r10,r5,r5
+    VST1.8   {d0,d1},[r3],r10
+    VST1.8   {d0,d1},[r8],r10
+    VST1.8   {d0,d1},[r3],r10
+    VST1.8   {d0,d1},[r8],r10
+    VST1.8   {d0,d1},[r3],r10
+    VST1.8   {d0,d1},[r8],r10
+    VST1.8   {d0,d1},[r3],r10
+    VST1.8   {d0,d1},[r8],r10
+    VST1.8   {d0,d1},[r3],r10
+    VST1.8   {d0,d1},[r8],r10
+    VST1.8   {d0,d1},[r3],r10
+    VST1.8   {d0,d1},[r8],r10
+    VST1.8   {d0,d1},[r3],r10
+    VST1.8   {d0,d1},[r8],r10
+    VST1.8   {d0,d1},[r3]
+    VST1.8   {d0,d1},[r8]
+    MOV      r0,#0
+    VPOP     {d8-d15}
+    POP      {r4-r12,pc}
+OMX_VC_16X16_HOR:
+    ADD      r8,r0,r4
+    ADD      r4,r4,r4
+    ADD      r11,r3,r5
+    ADD      r5,r5,r5
+L0x8c:
+    VLD1.8   {d2[],d3[]},[r0],r4
+    VLD1.8   {d0[],d1[]},[r8],r4
+    SUBS     r12,r12,#8
+    VST1.8   {d2,d3},[r3],r5
+    VST1.8   {d0,d1},[r11],r5
+    VLD1.8   {d2[],d3[]},[r0],r4
+    VLD1.8   {d0[],d1[]},[r8],r4
+    VST1.8   {d2,d3},[r3],r5
+    VST1.8   {d0,d1},[r11],r5
+    VLD1.8   {d2[],d3[]},[r0],r4
+    VLD1.8   {d0[],d1[]},[r8],r4
+    VST1.8   {d2,d3},[r3],r5
+    VST1.8   {d0,d1},[r11],r5
+    VLD1.8   {d2[],d3[]},[r0],r4
+    VLD1.8   {d0[],d1[]},[r8],r4
+    VST1.8   {d2,d3},[r3],r5
+    VST1.8   {d0,d1},[r11],r5
+    BNE      L0x8c
+    MOV      r0,#0
+    VPOP     {d8-d15}
+    POP      {r4-r12,pc}
+OMX_VC_16X16_DC:
+    MOV      r11,#0
+    TST      r7,#2
+    BEQ      L0x14c
+    ADD      r8,r0,r4
+    ADD      r10,r4,r4
+    VLD1.8   {d2[0]},[r0],r10
+    VLD1.8   {d2[1]},[r8],r10
+    VLD1.8   {d2[2]},[r0],r10
+    VLD1.8   {d2[3]},[r8],r10
+    VLD1.8   {d2[4]},[r0],r10
+    VLD1.8   {d2[5]},[r8],r10
+    VLD1.8   {d2[6]},[r0],r10
+    VLD1.8   {d2[7]},[r8],r10
+    VLD1.8   {d3[0]},[r0],r10
+    VLD1.8   {d3[1]},[r8],r10
+    VLD1.8   {d3[2]},[r0],r10
+    VLD1.8   {d3[3]},[r8],r10
+    VLD1.8   {d3[4]},[r0],r10
+    VLD1.8   {d3[5]},[r8],r10
+    VLD1.8   {d3[6]},[r0],r10
+    VLD1.8   {d3[7]},[r8]
+    VPADDL.U8 q0,q1
+    ADD      r11,r11,#1
+    VPADD.I16 d0,d0,d1
+    VPADDL.U16 d0,d0
+    VPADDL.U32 d6,d0
+    VRSHR.U64 d8,d6,#4
+L0x14c:
+    TST      r7,#1
+    BEQ      L0x170
+    VLD1.8   {d0,d1},[r1]
+    ADD      r11,r11,#1
+    VPADDL.U8 q0,q0
+    VPADD.I16 d0,d0,d1
+    VPADDL.U16 d0,d0
+    VPADDL.U32 d7,d0
+    VRSHR.U64 d8,d7,#4
+L0x170:
+    CMP      r11,#2
+    BNE      L0x180
+    VADD.I64 d8,d7,d6
+    VRSHR.U64 d8,d8,#5
+L0x180:
+    VDUP.8   q3,d8[0]
+    CMP      r11,#0
+    ADD      r8,r3,r5
+    ADD      r10,r5,r5
+    BNE      L0x198
+    VMOV.I8  q3,#0x80
+L0x198:
+    VST1.8   {d6,d7},[r3],r10
+    VST1.8   {d6,d7},[r8],r10
+    VST1.8   {d6,d7},[r3],r10
+    VST1.8   {d6,d7},[r8],r10
+    VST1.8   {d6,d7},[r3],r10
+    VST1.8   {d6,d7},[r8],r10
+    VST1.8   {d6,d7},[r3],r10
+    VST1.8   {d6,d7},[r8],r10
+    VST1.8   {d6,d7},[r3],r10
+    VST1.8   {d6,d7},[r8],r10
+    VST1.8   {d6,d7},[r3],r10
+    VST1.8   {d6,d7},[r8],r10
+    VST1.8   {d6,d7},[r3],r10
+    VST1.8   {d6,d7},[r8],r10
+    VST1.8   {d6,d7},[r3],r10
+    VST1.8   {d6,d7},[r8],r10
+    MOV      r0,#0
+    VPOP     {d8-d15}
+    POP      {r4-r12,pc}
+OMX_VC_16X16_PLANE:
+    LDR      r9, =armVCM4P10_MultiplierTable16x16
+    VLD1.8   {d0,d1},[r1]
+    VLD1.8   {d4[0]},[r2]
+    ADD      r8,r0,r4
+    ADD      r10,r4,r4
+    VLD1.8   {d2[0]},[r0],r10
+    VLD1.8   {d2[1]},[r8],r10
+    VLD1.8   {d2[2]},[r0],r10
+    VLD1.8   {d2[3]},[r8],r10
+    VLD1.8   {d2[4]},[r0],r10
+    VLD1.8   {d2[5]},[r8],r10
+    VLD1.8   {d2[6]},[r0],r10
+    VLD1.8   {d2[7]},[r8],r10
+    VLD1.8   {d3[0]},[r0],r10
+    VLD1.8   {d3[1]},[r8],r10
+    VLD1.8   {d3[2]},[r0],r10
+    VLD1.8   {d3[3]},[r8],r10
+    VLD1.8   {d3[4]},[r0],r10
+    VLD1.8   {d3[5]},[r8],r10
+    VLD1.8   {d3[6]},[r0],r10
+    VLD1.8   {d3[7]},[r8]
+    VREV64.8 d5,d1
+    VSUBL.U8 q3,d5,d4
+    VSHR.U64 d5,d5,#8
+    VSUBL.U8 q4,d5,d0
+    VSHL.I64 d9,d9,#16
+    VEXT.8   d9,d9,d6,#2
+    VREV64.8 d12,d3
+    VSUBL.U8 q7,d12,d4
+    VSHR.U64 d12,d12,#8
+    VSUBL.U8 q8,d12,d2
+    VLD1.16  {d20,d21},[r9]!
+    VSHL.I64 d17,d17,#16
+    VEXT.8   d17,d17,d14,#2
+    VMULL.S16 q11,d8,d20
+    VMULL.S16 q12,d16,d20
+    VMLAL.S16 q11,d9,d21
+    VMLAL.S16 q12,d17,d21
+    VPADD.I32 d22,d23,d22
+    VPADD.I32 d23,d25,d24
+    VPADDL.S32 q11,q11
+    VSHL.I64 q12,q11,#2
+    VADD.I64 q11,q11,q12
+    VRSHR.S64 q11,q11,#6
+    VSHL.I64 q12,q11,#3
+    VSUB.I64 q12,q12,q11
+    VLD1.16  {d20,d21},[r9]!
+    VDUP.16  q6,d22[0]
+    VDUP.16  q7,d23[0]
+    VADDL.U8 q11,d1,d3
+    VSHL.I16 q11,q11,#4
+    VDUP.16  q11,d23[3]
+    VADD.I64 d1,d24,d25
+    VLD1.16  {d24,d25},[r9]
+    VDUP.16  q13,d1[0]
+    VSUB.I16 q13,q11,q13
+    VMUL.I16 q5,q6,q10
+    VMUL.I16 q6,q6,q12
+    VADD.I16 q0,q5,q13
+    VADD.I16 q1,q6,q13
+L0x2d4:
+    VQRSHRUN.S16 d6,q0,#5
+    VQRSHRUN.S16 d7,q1,#5
+    SUBS     r12,r12,#1
+    VST1.8   {d6,d7},[r3],r5
+    VADD.I16 q0,q0,q7
+    VADD.I16 q1,q1,q7
+    BNE      L0x2d4
+    MOV      r0,#0
+    VPOP     {d8-d15}
+    POP      {r4-r12,pc}
+    .endfunc
+
+    .end
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_PredictIntra_4x4_s.S b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_PredictIntra_4x4_s.S
new file mode 100644
index 0000000..aa6d7ef
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_PredictIntra_4x4_s.S
@@ -0,0 +1,261 @@
+/*
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ *
+ */
+
+    .eabi_attribute 24, 1
+    .eabi_attribute 25, 1
+
+    .arm
+    .fpu neon
+
+    .section .rodata
+    .align 4
+
+armVCM4P10_pSwitchTable4x4:
+    .word OMX_VC_4x4_VERT,     OMX_VC_4x4_HOR
+    .word OMX_VC_4x4_DC,       OMX_VC_4x4_DIAG_DL
+    .word OMX_VC_4x4_DIAG_DR,  OMX_VC_4x4_VR
+    .word OMX_VC_4x4_HD,       OMX_VC_4x4_VL
+    .word OMX_VC_4x4_HU
+
+    .text
+
+    .global omxVCM4P10_PredictIntra_4x4
+    .func   omxVCM4P10_PredictIntra_4x4
+omxVCM4P10_PredictIntra_4x4:
+    PUSH     {r4-r12,lr}
+    VPUSH    {d8-d12}
+    LDR      r8, =armVCM4P10_pSwitchTable4x4
+    LDRD     r6,r7,[sp,#0x58]
+    LDRD     r4,r5,[sp,#0x50]
+    LDR      pc,[r8,r6,LSL #2]
+OMX_VC_4x4_HOR:
+    ADD      r9,r0,r4
+    ADD      r10,r4,r4
+    VLD1.8   {d0[]},[r0],r10
+    VLD1.8   {d1[]},[r9],r10
+    VLD1.8   {d2[]},[r0]
+    VLD1.8   {d3[]},[r9]
+    ADD      r11,r3,r5
+    ADD      r12,r5,r5
+    VST1.32  {d0[0]},[r3],r12
+    VST1.32  {d1[0]},[r11],r12
+    VST1.32  {d2[0]},[r3]
+    VST1.32  {d3[0]},[r11]
+    B        L0x348
+OMX_VC_4x4_VERT:
+    VLD1.32  {d0[0]},[r1]
+    ADD      r11,r3,r5
+    ADD      r12,r5,r5
+L0x58:
+    VST1.32  {d0[0]},[r3],r12
+    VST1.32  {d0[0]},[r11],r12
+    VST1.32  {d0[0]},[r3]
+    VST1.32  {d0[0]},[r11]
+    B        L0x348
+OMX_VC_4x4_DC:
+    TST      r7,#2
+    BEQ      L0xdc
+    ADD      r9,r0,r4
+    ADD      r10,r4,r4
+    VLD1.8   {d0[0]},[r0],r10
+    VLD1.8   {d0[1]},[r9],r10
+    VLD1.8   {d0[2]},[r0]
+    VLD1.8   {d0[3]},[r9]
+    TST      r7,#1
+    BEQ      L0xbc
+    VLD1.32  {d0[1]},[r1]
+    MOV      r0,#0
+    VPADDL.U8 d1,d0
+    VPADDL.U16 d1,d1
+    VPADDL.U32 d1,d1
+    VRSHR.U64 d1,d1,#3
+    ADD      r11,r3,r5
+    ADD      r12,r5,r5
+    VDUP.8   d0,d1[0]
+    B        L0x58
+L0xbc:
+    MOV      r0,#0
+    VPADDL.U8 d1,d0
+    VPADDL.U16 d1,d1
+    VRSHR.U32 d1,d1,#2
+    ADD      r11,r3,r5
+    ADD      r12,r5,r5
+    VDUP.8   d0,d1[0]
+    B        L0x58
+L0xdc:
+    TST      r7,#1
+    BEQ      L0x108
+    VLD1.32  {d0[0]},[r1]
+    MOV      r0,#0
+    VPADDL.U8 d1,d0
+    VPADDL.U16 d1,d1
+    VRSHR.U32 d1,d1,#2
+    ADD      r11,r3,r5
+    ADD      r12,r5,r5
+    VDUP.8   d0,d1[0]
+    B        L0x58
+L0x108:
+    VMOV.I8  d0,#0x80
+    MOV      r0,#0
+    ADD      r11,r3,r5
+    ADD      r12,r5,r5
+    B        L0x58
+OMX_VC_4x4_DIAG_DL:
+    TST      r7,#0x40
+    BEQ      L0x138
+    VLD1.8   {d3},[r1]
+    VDUP.8   d2,d3[7]
+    VEXT.8   d4,d3,d2,#1
+    VEXT.8   d5,d3,d2,#2
+    B        L0x14c
+L0x138:
+    VLD1.32  {d0[1]},[r1]
+    VDUP.8   d2,d0[7]
+    VEXT.8   d3,d0,d2,#4
+    VEXT.8   d4,d0,d2,#5
+    VEXT.8   d5,d0,d2,#6
+L0x14c:
+    VHADD.U8 d6,d3,d5
+    VRHADD.U8 d6,d6,d4
+    VST1.32  {d6[0]},[r3],r5
+    VEXT.8   d6,d6,d6,#1
+    VST1.32  {d6[0]},[r3],r5
+    VEXT.8   d6,d6,d6,#1
+    VST1.32  {d6[0]},[r3],r5
+    VEXT.8   d6,d6,d6,#1
+    VST1.32  {d6[0]},[r3]
+    B        L0x348
+OMX_VC_4x4_DIAG_DR:
+    VLD1.32  {d0[0]},[r1]
+    VLD1.8   {d1[7]},[r2]
+    ADD      r9,r0,r4
+    ADD      r10,r4,r4
+    ADD      r1,r3,r5
+    VLD1.8   {d1[6]},[r0],r10
+    VLD1.8   {d1[5]},[r9],r10
+    VLD1.8   {d1[4]},[r0]
+    VLD1.8   {d1[3]},[r9]
+    VEXT.8   d3,d1,d0,#3
+    ADD      r4,r1,r5
+    VEXT.8   d4,d1,d0,#4
+    ADD      r6,r4,r5
+    VEXT.8   d5,d1,d0,#5
+    VHADD.U8 d6,d3,d5
+    VRHADD.U8 d6,d6,d4
+    VST1.32  {d6[0]},[r6]
+    VEXT.8   d6,d6,d6,#1
+    VST1.32  {d6[0]},[r4]
+    VEXT.8   d6,d6,d6,#1
+    VST1.32  {d6[0]},[r1]
+    VEXT.8   d6,d6,d6,#1
+    VST1.32  {d6[0]},[r3]
+    B        L0x348
+OMX_VC_4x4_VR:
+    VLD1.32  {d0[0]},[r1]
+    VLD1.8   {d0[7]},[r2]
+    VLD1.8   {d1[7]},[r0],r4
+    VLD1.8   {d2[7]},[r0],r4
+    VLD1.8   {d1[6]},[r0]
+    VEXT.8   d12,d0,d0,#7
+    VEXT.8   d3,d1,d12,#6
+    VEXT.8   d4,d2,d12,#7
+    VEXT.8   d5,d1,d0,#7
+    VEXT.8   d6,d2,d0,#7
+    VEXT.8   d11,d1,d12,#7
+    VHADD.U8 d8,d6,d12
+    VRHADD.U8 d8,d8,d11
+    VHADD.U8 d7,d3,d5
+    VRHADD.U8 d7,d7,d4
+    VEXT.8   d10,d8,d8,#1
+    ADD      r11,r3,r5
+    ADD      r12,r5,r5
+    VEXT.8   d9,d7,d7,#1
+    VST1.32  {d10[0]},[r3],r12
+    VST1.32  {d9[0]},[r11],r12
+    VST1.32  {d8[0]},[r3],r12
+    VST1.32  {d7[0]},[r11]
+    B        L0x348
+OMX_VC_4x4_HD:
+    VLD1.8   {d0},[r1]
+    VLD1.8   {d1[7]},[r2]
+    ADD      r9,r0,r4
+    ADD      r10,r4,r4
+    VLD1.8   {d1[6]},[r0],r10
+    VLD1.8   {d1[5]},[r9],r10
+    VLD1.8   {d1[4]},[r0]
+    VLD1.8   {d1[3]},[r9]
+    VEXT.8   d3,d1,d0,#3
+    VEXT.8   d4,d1,d0,#2
+    VEXT.8   d5,d1,d0,#1
+    VHADD.U8 d7,d3,d5
+    VRHADD.U8 d7,d7,d4
+    VRHADD.U8 d8,d4,d3
+    VSHL.I64 d8,d8,#24
+    VSHL.I64 d6,d7,#16
+    VZIP.8   d8,d6
+    VEXT.8   d7,d7,d7,#6
+    VEXT.8   d8,d6,d7,#2
+    ADD      r11,r3,r5
+    ADD      r12,r5,r5
+    VST1.32  {d8[1]},[r3],r12
+    VST1.32  {d6[1]},[r11],r12
+    VST1.32  {d8[0]},[r3]
+    VST1.32  {d6[0]},[r11]
+    B        L0x348
+OMX_VC_4x4_VL:
+    TST      r7,#0x40
+    BEQ      L0x2b4
+    VLD1.8   {d3},[r1]
+    VEXT.8   d4,d3,d3,#1
+    VEXT.8   d5,d4,d4,#1
+    B        L0x2c8
+L0x2b4:
+    VLD1.32  {d0[1]},[r1]
+    VDUP.8   d2,d0[7]
+    VEXT.8   d3,d0,d2,#4
+    VEXT.8   d4,d0,d2,#5
+    VEXT.8   d5,d0,d2,#6
+L0x2c8:
+    VRHADD.U8 d7,d4,d3
+    VHADD.U8 d10,d3,d5
+    VRHADD.U8 d10,d10,d4
+    VEXT.8   d8,d7,d7,#1
+    ADD      r11,r3,r5
+    ADD      r12,r5,r5
+    VEXT.8   d9,d10,d8,#1
+    VST1.32  {d7[0]},[r3],r12
+    VST1.32  {d10[0]},[r11],r12
+    VST1.32  {d8[0]},[r3]
+    VST1.32  {d9[0]},[r11]
+    B        L0x348
+OMX_VC_4x4_HU:
+    ADD      r9,r0,r4
+    ADD      r10,r4,r4
+    VLD1.8   {d1[4]},[r0],r10
+    VLD1.8   {d1[5]},[r9],r10
+    VLD1.8   {d1[6]},[r0]
+    VLD1.8   {d1[7]},[r9]
+    VDUP.8   d2,d1[7]
+    VEXT.8   d3,d1,d2,#4
+    VEXT.8   d4,d1,d2,#5
+    VEXT.8   d5,d1,d2,#6
+    VHADD.U8 d7,d3,d5
+    VRHADD.U8 d7,d7,d4
+    VRHADD.U8 d8,d4,d3
+    VZIP.8   d8,d7
+    VST1.32  {d8[0]},[r3],r5
+    VEXT.8   d8,d8,d8,#2
+    VST1.32  {d8[0]},[r3],r5
+    VEXT.8   d8,d8,d8,#2
+    VST1.32  {d8[0]},[r3],r5
+    VST1.32  {d7[0]},[r3]
+L0x348:
+    MOV      r0,#0
+    VPOP     {d8-d12}
+    POP      {r4-r12,pc}
+    .endfunc
+
+    .end
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_TransformDequantChromaDCFromPair_s.S b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_TransformDequantChromaDCFromPair_s.S
new file mode 100644
index 0000000..28a89cb
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_TransformDequantChromaDCFromPair_s.S
@@ -0,0 +1,54 @@
+/*
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ *
+ */
+
+    .eabi_attribute 24, 1
+    .eabi_attribute 25, 1
+
+    .arm
+    .fpu neon
+    .text
+
+    .global omxVCM4P10_TransformDequantChromaDCFromPair
+    .func   omxVCM4P10_TransformDequantChromaDCFromPair
+omxVCM4P10_TransformDequantChromaDCFromPair:
+    push    {r4-r10, lr}
+    ldr     r9, [r0,#0]
+    vmov.i16    d0, #0
+    mov     r8, #0x1f
+    vst1.16    {d0}, [r1]
+    ldrb    r6, [r9], #1
+unpackLoop:
+    tst     r6, #0x10
+    ldrnesb r5, [r9, #1]
+    ldrneb  r4, [r9], #2
+    and     r7, r8, r6, lsl #1
+    ldreqsb r4, [r9], #1
+    orrne   r4, r4, r5, lsl #8
+    tst     r6, #0x20
+    ldreqb  r6, [r9], #1
+    strh    r4, [r1, r7]
+    beq     unpackLoop
+    ldmia   r1, {r3, r4}
+    str     r9, [r0, #0]
+    ldr     r5, =armVCM4P10_QPDivTable
+    ldr     r6, =armVCM4P10_VMatrixQPModTable
+    saddsubx        r3, r3, r3
+    saddsubx        r4, r4, r4
+    ldrsb   r9, [r5, r2]
+    ldrsb   r2, [r6, r2]
+    sadd16  r5, r3, r4
+    ssub16  r6, r3, r4
+    lsl     r2, r2, r9
+    vmov    d0, r5, r6
+    vrev32.16  d0, d0
+    vdup.16    d1, r2
+    vmull.s16   q1, d0, d1
+    vshrn.i32   d2, q1, #1
+    vst1.16    {d2}, [r1]
+    mov     r0, #0
+    pop     {r4-r10, pc}
+    .endfunc
+
+    .end
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_TransformDequantLumaDCFromPair_s.S b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_TransformDequantLumaDCFromPair_s.S
new file mode 100644
index 0000000..a3a0715
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_TransformDequantLumaDCFromPair_s.S
@@ -0,0 +1,76 @@
+/*
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ *
+ */
+
+    .eabi_attribute 24, 1
+    .eabi_attribute 25, 1
+
+    .arm
+    .fpu neon
+    .text
+
+    .global armVCM4P10_InvTransformDequantLumaDC4x4
+    .func   armVCM4P10_InvTransformDequantLumaDC4x4
+armVCM4P10_InvTransformDequantLumaDC4x4:
+    PUSH     {r4-r6,lr}
+    VPUSH    {d8-d13}
+    VLD4.16  {d0,d1,d2,d3},[r0]
+    LDR      r2, =armVCM4P10_QPDivTable
+    LDR      r3, =armVCM4P10_VMatrixQPModTable
+    VADD.I16 d4,d0,d1
+    VADD.I16 d5,d2,d3
+    VSUB.I16 d6,d0,d1
+    LDRSB    r4,[r2,r1]
+    VSUB.I16 d7,d2,d3
+    LDRSB    r5,[r3,r1]
+    VADD.I16 d0,d4,d5
+    VSUB.I16 d1,d4,d5
+    VSUB.I16 d2,d6,d7
+    LSL      r5,r5,r4
+    VADD.I16 d3,d6,d7
+    VTRN.16  d0,d1
+    VTRN.16  d2,d3
+    VTRN.32  q0,q1
+    VADD.I16 d4,d0,d1
+    VADD.I16 d5,d2,d3
+    VSUB.I16 d6,d0,d1
+    VSUB.I16 d7,d2,d3
+    VADD.I16 d0,d4,d5
+    VSUB.I16 d1,d4,d5
+    VSUB.I16 d2,d6,d7
+    VADD.I16 d3,d6,d7
+    VDUP.16  d5,r5
+    VMOV.I32 q3,#0x2
+    VMOV.I32 q4,#0x2
+    VMOV.I32 q5,#0x2
+    VMOV.I32 q6,#0x2
+    VMLAL.S16 q3,d0,d5
+    VMLAL.S16 q4,d1,d5
+    VMLAL.S16 q5,d2,d5
+    VMLAL.S16 q6,d3,d5
+    VSHRN.I32 d0,q3,#2
+    VSHRN.I32 d1,q4,#2
+    VSHRN.I32 d2,q5,#2
+    VSHRN.I32 d3,q6,#2
+    VST1.16  {d0,d1,d2,d3},[r0]
+    VPOP     {d8-d13}
+    POP      {r4-r6,pc}
+    .endfunc
+
+.global omxVCM4P10_TransformDequantLumaDCFromPair
+.func   omxVCM4P10_TransformDequantLumaDCFromPair
+omxVCM4P10_TransformDequantLumaDCFromPair:
+    PUSH     {r4-r6,lr}
+    MOV      r4,r1
+    MOV      r5,r2
+    BL       armVCM4P10_UnpackBlock4x4
+    MOV      r0,r4
+    MOV      r1,r5
+    BL       armVCM4P10_InvTransformDequantLumaDC4x4
+    MOV      r0,#0
+    POP      {r4-r6,pc}
+    .endfunc
+
+    .end
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/api/armVCM4P2_Huff_Tables_VLC.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/api/armVCM4P2_Huff_Tables_VLC.h
new file mode 100755
index 0000000..74b5505
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/api/armVCM4P2_Huff_Tables_VLC.h
@@ -0,0 +1,37 @@
+/**
+ * 
+ * File Name:  armVCM4P2_Huff_Tables_VLC.h
+ * OpenMAX DL: v1.0.2
+ * Revision:   12290
+ * Date:       Wednesday, April 9, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ *
+ * File:        armVCM4P2_Huff_Tables.h
+ * Description: Declares Tables used for Hufffman coding and decoding 
+ *              in MP4P2 codec.
+ *
+ */
+ 
+#ifndef _OMXHUFFTAB_H_
+#define _OMXHUFFTAB_H_
+
+
+extern const OMX_U16 armVCM4P2_IntraVlcL0L1[200];
+
+
+extern const OMX_U16 armVCM4P2_InterVlcL0L1[200];
+
+extern const OMX_U16 armVCM4P2_aIntraDCLumaChromaIndex[64];
+//extern const OMX_U16 armVCM4P2_aIntraDCChromaIndex[32];
+extern const OMX_U16 armVCM4P2_aVlcMVD[124];
+
+extern const OMX_U8 armVCM4P2_InterL0L1LMAX[73];
+extern const OMX_U8 armVCM4P2_InterL0L1RMAX[35];
+extern const OMX_U8 armVCM4P2_IntraL0L1LMAX[53];
+extern const OMX_U8 armVCM4P2_IntraL0L1RMAX[40]
+
+#endif /* _OMXHUFFTAB_H_ */
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/api/armVCM4P2_ZigZag_Tables.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/api/armVCM4P2_ZigZag_Tables.h
new file mode 100755
index 0000000..e95203a
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/api/armVCM4P2_ZigZag_Tables.h
@@ -0,0 +1,25 @@
+/**
+ * 
+ * File Name:  armVCM4P2_ZigZag_Tables.h
+ * OpenMAX DL: v1.0.2
+ * Revision:   12290
+ * Date:       Wednesday, April 9, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ *
+ * File:        armVCM4P2_Zigzag_Tables.h
+ * Description: Declares Tables used for Zigzag scan in MP4P2 codec.
+ *
+ */
+ 
+#ifndef _OMXZIGZAGTAB_H
+#define _OMXZIGZAGTAB_H
+
+extern const OMX_U8 armVCM4P2_aClassicalZigzagScan [192];
+//extern const OMX_U8 armVCM4P2_aHorizontalZigzagScan [64];
+//extern const OMX_U8 armVCM4P2_aVerticalZigzagScan [64];
+
+#endif /* _OMXZIGZAGTAB_H_ */
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/armVCM4P2_Clip8_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/armVCM4P2_Clip8_s.s
new file mode 100755
index 0000000..95fe6d2
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/armVCM4P2_Clip8_s.s
@@ -0,0 +1,82 @@
+; /**
+; * 
+; * File Name:  armVCM4P2_Clip8_s.s
+; * OpenMAX DL: v1.0.2
+; * Revision:   12290
+; * Date:       Wednesday, April 9, 2008
+; * 
+; * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+; * 
+; * 
+; *
+; * Description: 
+; * Contains module for Clipping 16 bit value to [0,255] Range
+; */ 
+
+      INCLUDE omxtypes_s.h
+      INCLUDE armCOMM_s.h
+      
+
+      M_VARIANTS CortexA8
+
+      IF CortexA8
+;//Input Arguments
+
+pSrc                 RN 0
+pDst                 RN 1
+step                 RN 2
+
+;// Neon Registers
+
+qx0                  QN  Q0.S16                  
+dx00                 DN  D0.S16
+dx01                 DN  D1.S16
+qx1                  QN  Q1.S16
+dx10                 DN  D2.S16
+dx11                 DN  D3.S16
+
+qx2                  QN  Q2.S16                  
+dx20                 DN  D4.S16
+dx21                 DN  D5.S16
+qx3                  QN  Q3.S16
+dx30                 DN  D6.S16
+dx31                 DN  D7.S16
+
+
+dclip0               DN  D0.U8
+dclip1               DN  D2.U8 
+dclip2               DN  D4.U8
+dclip3               DN  D6.U8
+ 
+       M_START armVCM4P2_Clip8
+
+       VLD1          {dx00,dx01,dx10,dx11},[pSrc]!          ;// Load 16 entries from pSrc
+       VLD1          {dx20,dx21,dx30,dx31},[pSrc]!          ;// Load next 16 entries from pSrc  
+       VQSHRUN       dclip0,qx0,#0                          ;// dclip0[i]=clip qx0[i] to [0,255]
+       VQSHRUN       dclip1,qx1,#0                          ;// dclip1[i]=clip qx1[i] to [0,255]
+       VST1          {dclip0},[pDst],step                   ;// store 8 bytes and pDst=pDst+step
+       VST1          {dclip1},[pDst],step                   ;// store 8 bytes and pDst=pDst+step
+       VQSHRUN       dclip2,qx2,#0
+       VQSHRUN       dclip3,qx3,#0
+       VST1          {dclip2},[pDst],step
+       VST1          {dclip3},[pDst],step
+       
+       VLD1          {dx00,dx01,dx10,dx11},[pSrc]!          ;// Load 16 entries from pSrc
+       VLD1          {dx20,dx21,dx30,dx31},[pSrc]!          ;// Load next 16 entries from pSrc  
+       VQSHRUN       dclip0,qx0,#0                          ;// dclip0[i]=clip qx0[i] to [0,255]
+       VQSHRUN       dclip1,qx1,#0                          ;// dclip1[i]=clip qx1[i] to [0,255]
+       VST1          {dclip0},[pDst],step                   ;// store 8 bytes and pDst=pDst+step
+       VST1          {dclip1},[pDst],step                   ;// store 8 bytes and pDst=pDst+step
+       VQSHRUN       dclip2,qx2,#0
+       VQSHRUN       dclip3,qx3,#0
+       VST1          {dclip2},[pDst],step
+       VST1          {dclip3},[pDst],step
+
+
+       
+        M_END
+        ENDIF
+        
+     
+        
+        END
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/armVCM4P2_DecodeVLCZigzag_AC_unsafe_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/armVCM4P2_DecodeVLCZigzag_AC_unsafe_s.s
new file mode 100755
index 0000000..e4a7f33
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/armVCM4P2_DecodeVLCZigzag_AC_unsafe_s.s
@@ -0,0 +1,398 @@
+;/**
+; * 
+; * File Name:  armVCM4P2_DecodeVLCZigzag_AC_unsafe_s.s
+; * OpenMAX DL: v1.0.2
+; * Revision:   12290
+; * Date:       Wednesday, April 9, 2008
+; * 
+; * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+; * 
+; * 
+; *
+; * Description: 
+; * Contains modules for zigzag scanning and VLC decoding
+; * for inter, intra block.
+; *
+; *
+; *
+; * Function: omxVCM4P2_DecodeVLCZigzag_AC_unsafe
+; *
+; * Description:
+; * Performs VLC decoding and inverse zigzag scan 
+; *
+; * 
+; *
+; * 
+; */
+
+
+      INCLUDE omxtypes_s.h
+      INCLUDE armCOMM_s.h
+      INCLUDE armCOMM_BitDec_s.h
+
+
+      M_VARIANTS ARM1136JS
+
+     
+
+
+
+     IF ARM1136JS
+     
+        
+
+
+
+;//Input Arguments
+
+ppBitStream          RN 0
+pBitOffset           RN 1
+pDst                 RN 2
+shortVideoHeader     RN 3
+
+
+;//Local Variables
+
+Return               RN 0
+
+pVlcTableL0L1        RN 4
+pLMAXTableL0L1       RN 4
+pRMAXTableL0L1       RN 4
+pZigzagTable         RN 4
+
+ftype                RN 0
+temp3                RN 4
+temp                 RN 5
+Count                RN 6
+Escape               RN 5
+
+;// armVCM4P2_FillVLDBuffer
+zigzag               RN 0
+storeLevel           RN 1
+temp2                RN 4
+temp1                RN 5
+sign                 RN 5
+Last                 RN 7
+storeRun             RN 14
+
+
+packRetIndex         RN 5
+
+
+markerbit            RN 5
+
+;// Scratch Registers
+
+RBitStream           RN 8
+RBitBuffer           RN 9
+RBitCount            RN 10
+
+T1                   RN 11
+T2                   RN 12
+LR                   RN 14        
+        
+
+
+        M_ALLOC4        pppBitStream,4
+        M_ALLOC4        ppOffset,4
+        M_ALLOC4        pLinkRegister,4       
+        
+        M_START armVCM4P2_DecodeVLCZigzag_AC_unsafe
+
+        ;// get the table addresses from stack       
+        M_ARG           ppVlcTableL0L1,4
+        M_ARG           ppLMAXTableL0L1,4
+        M_ARG           ppRMAXTableL0L1,4
+        M_ARG           ppZigzagTable,4
+        
+        ;// Store ALL zeros at pDst
+        
+        MOV             temp1,#0                                        ;// Initialize Count to zero                                
+        MOV             Last,#0
+        M_STR           LR,pLinkRegister                                ;// Store Link Register on Stack
+        MOV             temp2,#0
+        MOV             LR,#0          
+        
+        ;// Initialize the Macro and Store all zeros to pDst 
+  
+        STM             pDst!,{temp2,temp1,Last,LR}                   
+        M_BD_INIT0      ppBitStream, pBitOffset, RBitStream, RBitBuffer, RBitCount  
+        STM             pDst!,{temp2,temp1,Last,LR}
+        M_BD_INIT1      T1, T2, T2
+        STM             pDst!,{temp2,temp1,Last,LR}
+        M_BD_INIT2      T1, T2, T2
+        STM             pDst!,{temp2,temp1,Last,LR}
+        M_STR           ppBitStream,pppBitStream                        ;// Store ppBitstream on stack                         
+        STM             pDst!,{temp2,temp1,Last,LR}
+        M_STR           pBitOffset,ppOffset                             ;// Store pBitOffset on stack
+        STM             pDst!,{temp2,temp1,Last,LR}
+        
+        STM             pDst!,{temp2,temp1,Last,LR}
+        STM             pDst!,{temp2,temp1,Last,LR}
+ 
+        
+        SUB             pDst,pDst,#128                                  ;// Restore pDst
+
+        ;// The armVCM4P2_GetVLCBits begins
+
+getVLCbits
+        
+        M_BD_LOOK8      Escape,7                                        ;// Load Escape Value
+        LSR             Escape,Escape,#25                                                  
+        CMP             Escape,#3                                       ;// check for escape mode
+        MOVNE           ftype,#0
+        BNE             notEscapemode                                   ;// Branch if not in Escape mode 3
+
+        M_BD_VSKIP8     #7,T1
+        CMP             shortVideoHeader,#0                             ;// Check shortVideoHeader flag to know the type of Escape mode
+        BEQ             endFillVLD                                       
+        
+        ;// Escape Mode 4
+
+        M_BD_READ8      Last,1,T1
+        M_BD_READ8      storeRun,6,T1
+        M_BD_READ8      storeLevel,8,T1
+
+           
+        ;// Check whether the Reserved values for Level are used and Exit with an Error Message if it is so
+
+        TEQ             storeLevel,#0
+        TEQNE           storeLevel,#128                    
+        BEQ             ExitError
+
+        ADD             temp2,storeRun,Count
+        CMP             temp2,#64
+        BGE             ExitError                                       ;// error if Count+storeRun >= 64
+        
+        
+        ;// Load address of zigzagTable
+        
+        M_LDR           pZigzagTable,ppZigzagTable                      ;// Loading the Address of Zigzag table
+               
+                
+        ;// armVCM4P2_FillVLDBuffer
+                
+        SXTB            storeLevel,storeLevel                           ;// Sign Extend storeLevel to 32 bits
+                              
+        
+        ;// To Reflect Runlength
+
+        ADD             Count,Count,storeRun
+        LDRB            zigzag,[pZigzagTable,Count]
+        ADD             Count,Count,#1
+        STRH            storeLevel,[pDst,zigzag]                        ;// store Level
+              
+        B               ExitOk
+       
+        
+
+endFillVLD
+        
+               
+        ;// Load Ftype( Escape Mode) value based on the two successive bits in the bitstream
+     
+        M_BD_READ8      temp1,1,T1           
+        CMP             temp1,#0    
+        MOVEQ           ftype,#1
+        BEQ             notEscapemode
+        M_BD_READ8      temp1,1,T1
+        CMP             temp1,#1
+        MOVEQ           ftype,#3
+        MOVNE           ftype,#2
+        
+
+notEscapemode
+
+        ;// Load optimized packed VLC table with last=0 and Last=1
+        
+        M_LDR           pVlcTableL0L1,ppVlcTableL0L1                    ;// Load Combined VLC Table
+                
+       
+        CMP             ftype,#3                                        ;// If ftype >=3 get perform Fixed Length Decoding (Escape Mode 3)
+        BGE             EscapeMode3                                     ;// Else continue normal VLC Decoding
+        
+        ;// Variable lengh decoding, "armUnPackVLC32" 
+        
+        
+        M_BD_VLD        packRetIndex,T1,T2,pVlcTableL0L1,4,2
+        
+        
+        LDR             temp3,=0xFFF
+        
+        CMP             packRetIndex,temp3                              ;// Check for invalid symbol
+        BEQ             ExitError                                       ;// if invalid symbol occurs exit with an error message
+        
+        AND             Last,packRetIndex,#2                            ;// Get Last from packed Index
+              
+         
+        
+
+        LSR             storeRun,packRetIndex,#7                        ;// Get Run Value from Packed index
+        AND             storeLevel,packRetIndex,#0x7c                   ;// storeLevel=packRetIndex[2-6],storeLevel[0-1]=0 
+                                                                        
+     
+        M_LDR           pLMAXTableL0L1,ppLMAXTableL0L1                  ;// Load LMAX table
+              
+       
+        LSR             storeLevel,storeLevel,#2                        ;// Level value
+
+        CMP             ftype,#1                                    
+        BNE             ftype2
+        
+        ;// ftype==1; Escape mode =1
+          
+        
+        ADD            temp1, pLMAXTableL0L1, Last, LSL#4              ;// If the Last=1 add 32 to table address
+        LDRB            temp1,[temp1,storeRun]
+
+       
+        ADD             storeLevel,temp1,storeLevel                     
+
+ftype2
+
+        ;// ftype =2; Escape mode =2
+        
+        M_LDR           pRMAXTableL0L1,ppRMAXTableL0L1                  ;// Load RMAX Table 
+                
+        CMP             ftype,#2
+        BNE             FillVLDL1
+                  
+        ADD            temp1, pRMAXTableL0L1, Last, LSL#4               ;// If Last=1 add 32 to table address
+        SUB             temp2,storeLevel,#1
+        LDRB            temp1,[temp1,temp2]
+
+       
+        ADD             storeRun,storeRun,#1
+        ADD             storeRun,temp1
+        
+FillVLDL1        
+            
+                
+        ;// armVCM4P2_FillVLDBuffer
+
+        M_LDR           pZigzagTable,ppZigzagTable                     ;// Load address of zigzagTable 
+                
+        M_BD_READ8      sign,1,T1
+
+        CMP             sign,#1
+        RSBEQ           storeLevel,storeLevel,#0
+ 
+        ADD             temp1,storeRun,Count                           ;// Exit with an error message if Run + Count exceeds 63
+        CMP             temp1,#64
+        BGE             ExitError
+
+      
+        
+        
+              
+        
+        ;// To Reflect Runlenght
+
+        ADD             Count,Count,storeRun
+ 
+storeLevelL1
+        
+        LDRB            zigzag,[pZigzagTable,Count]
+        CMP             Last,#2                                         ;// Check if the Level val is Last non zero val
+        ADD             Count,Count,#1
+        LSR             Last,Last,#1
+        STRH            storeLevel,[pDst,zigzag]                  
+           
+        BNE             end
+        
+        B               ExitOk
+ 
+
+
+        ;// Fixed Lengh Decoding Escape Mode 3
+
+EscapeMode3
+
+        M_BD_READ8      Last,1,T1
+        M_BD_READ8      storeRun,6,T1
+        
+        ADD             temp2,storeRun,Count                            ;// Exit with an error message if Run + Count exceeds 63
+        CMP             temp2,#64
+        BGE             ExitError
+
+        M_BD_READ8      markerbit,1,T1
+        TEQ             markerbit,#0                                    ;// Exit with an error message if marker bit is zero
+        BEQ             ExitError
+        
+        M_BD_READ16     storeLevel,12,T1
+
+        TST             storeLevel,#0x800                               ;// test if the level is negative
+        SUBNE           storeLevel,storeLevel,#4096
+        CMP             storeLevel,#0
+        CMPNE           storeLevel,#-2048
+        BEQ             ExitError                                       ;// Exit with an error message if Level==0 or  -2048 
+
+        M_LDR           pZigzagTable,ppZigzagTable                      ;// Load address of zigzagTable
+              
+        M_BD_READ8      markerbit,1,T1
+           
+
+        ;// armVCM4P2_FillVLDBuffer ( Sign not used as storeLevel is preprocessed)
+            
+               
+
+        ;// To Reflect Run Length
+
+        ADD             Count,Count,storeRun
+
+
+ 
+storeLevelLast
+        
+        LDRB            zigzag,[pZigzagTable,Count]
+        CMP             Last,#1
+        ADD             Count,Count,#1
+        STRH            storeLevel,[pDst,zigzag]                          
+                
+        BNE             end 
+      
+        B               ExitOk
+        
+end
+
+        CMP             Count,#64                                       ;//Run the Loop untill Count reaches 64
+
+        BLT             getVLCbits
+
+        
+ExitOk
+        ;// Exit When VLC Decoding is done Successfully 
+   
+        ;// Loading ppBitStream and pBitOffset from stack
+        
+        CMP             Last,#1
+        M_LDR           ppBitStream,pppBitStream
+        M_LDR           pBitOffset,ppOffset
+
+        ;//Ending the macro
+
+        M_BD_FINI       ppBitStream,pBitOffset
+             
+        MOVEQ           Return,#OMX_Sts_NoErr
+        MOVNE           Return,#OMX_Sts_Err
+        M_LDR           LR,pLinkRegister                               ;// Load the Link Register Back
+        B               exit2
+
+ExitError
+        ;// Exit When an Error occurs 
+
+        M_LDR           ppBitStream,pppBitStream
+        M_LDR           pBitOffset,ppOffset
+        ;//Ending the macro
+
+        M_BD_FINI       ppBitStream,pBitOffset
+        M_LDR           LR,pLinkRegister
+        MOV             Return,#OMX_Sts_Err
+
+exit2
+       
+
+        M_END
+        ENDIF
+        
+        END
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/armVCM4P2_Huff_Tables_VLC.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/armVCM4P2_Huff_Tables_VLC.c
new file mode 100755
index 0000000..38af975
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/armVCM4P2_Huff_Tables_VLC.c
@@ -0,0 +1,211 @@
+ /**
+ * 
+ * File Name:  armVCM4P2_Huff_Tables_VLC.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   12290
+ * Date:       Wednesday, April 9, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * File:        armVCM4P2_Huff_Tables_VLC.c
+ * Description: Contains all the Huffman tables used in MPEG4 codec
+ *
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+
+#include "armCOMM_Bitstream.h"
+
+
+
+
+// Contains optimized and Packed VLC tables with Last=0 and Last=1
+
+//              optimized Packed VLC table Entry Format 
+//              ---------------------------------------
+// 
+//        15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
+//       +------------------------------------------------+
+//       |  Len   |       Run       |     Level    |L | 1 |
+//       +------------------------------------------------+
+//       |                Offset                      | 0 |
+//       +------------------------------------------------+
+// If the table entry is a leaf entry then bit 0 set:
+//    Len    = Number of bits overread  (0 to 7)  3 bits
+//    Run    = RunLength of the Symbol  (0 to 63) 6 bits
+//    Level  = Level of the Symbol      (0 to 31) 5 bits
+//    L      = Last Value of the Symbol (0 or 1)  1 bit
+//
+// If the table entry is an internal node then bit 0 is clear:
+//    Offset = Number of (16-bit) half words from the table
+//             start to the next table node
+//
+// The table is accessed by successive lookup up on the
+// next Step bits of the input bitstream until a leaf node
+// is obtained. The Step sizes are supplied to the VLD macro.
+
+// The VLC tables used for Intra and non inta coefficients in non Escape mode
+// contains symbols with both Last=0 and Last=1.
+// If a symbol is not found in the table it will be coded as 0xFFF
+ 
+
+const OMX_U16 armVCM4P2_InterVlcL0L1[200] = {
+    0x0020, 0x0108, 0x0148, 0x0170, 0x0178, 0x0180, 0x0188, 0x1b09,
+    0x4009, 0x4009, 0x4009, 0x4009, 0x2109, 0x2109, 0x0209, 0x0011,
+    0x0028, 0x0060, 0x00b8, 0x00e0, 0x0030, 0x0048, 0x0050, 0x0058,
+    0x3fff, 0x3fff, 0x0038, 0x0040, 0x2115, 0x2115, 0x201d, 0x201d,
+    0x2059, 0x2059, 0x2051, 0x2051, 0x1c0d, 0x1b0d, 0x1a0d, 0x190d,
+    0x0911, 0x0811, 0x0711, 0x0611, 0x0511, 0x0319, 0x0219, 0x0121,
+    0x0068, 0x0090, 0x3fff, 0x3fff, 0x0070, 0x0078, 0x0080, 0x0088,
+    0x2061, 0x2061, 0x2129, 0x2129, 0x3709, 0x3709, 0x3809, 0x3809,
+    0x3d0d, 0x3d0d, 0x3e0d, 0x3e0d, 0x3f0d, 0x3f0d, 0x200d, 0x200d,
+    0x0098, 0x00a0, 0x00a8, 0x00b0, 0x0131, 0x0221, 0x0419, 0x0519,
+    0x0619, 0x0a11, 0x1909, 0x1a09, 0x210d, 0x220d, 0x230d, 0x240d,
+    0x250d, 0x260d, 0x270d, 0x280d, 0x00c0, 0x00c8, 0x00d0, 0x00d8,
+    0x0049, 0x0041, 0x380d, 0x380d, 0x370d, 0x370d, 0x360d, 0x360d,
+    0x350d, 0x350d, 0x340d, 0x340d, 0x330d, 0x330d, 0x320d, 0x320d,
+    0x00e8, 0x00f0, 0x00f8, 0x0100, 0x310d, 0x310d, 0x2015, 0x2015,
+    0x3609, 0x3609, 0x3509, 0x3509, 0x3409, 0x3409, 0x3309, 0x3309,
+    0x3209, 0x3209, 0x3109, 0x3109, 0x0110, 0x0130, 0x0138, 0x0140,
+    0x0118, 0x0120, 0x0128, 0x100d, 0x3009, 0x3009, 0x2f09, 0x2f09,
+    0x2411, 0x2411, 0x2311, 0x2311, 0x2039, 0x2039, 0x2031, 0x2031,
+    0x0f0d, 0x0e0d, 0x0d0d, 0x0c0d, 0x0b0d, 0x0a0d, 0x090d, 0x0e09,
+    0x0d09, 0x0211, 0x0119, 0x0029, 0x0150, 0x0158, 0x0160, 0x0168,
+    0x280d, 0x280d, 0x270d, 0x270d, 0x260d, 0x260d, 0x250d, 0x250d,
+    0x2c09, 0x2c09, 0xb759, 0xb759, 0x2a09, 0x2a09, 0x2021, 0x2021,
+    0x040d, 0x030d, 0x0b35, 0x010d, 0x0909, 0x0809, 0x0709, 0x0609,
+    0x0111, 0x0019, 0x2509, 0x2509, 0x2409, 0x2409, 0x2309, 0x2309
+};
+
+
+const OMX_U16 armVCM4P2_IntraVlcL0L1[200] = {
+    0x0020, 0x0108, 0x0148, 0x0170, 0x0178, 0x0180, 0x0188, 0x0f09,
+    0x4009, 0x4009, 0x4009, 0x4009, 0x2011, 0x2011, 0x0109, 0x0019,
+    0x0028, 0x0060, 0x00b8, 0x00e0, 0x0030, 0x0048, 0x0050, 0x0058,
+    0x3fff, 0x3fff, 0x0038, 0x0040, 0x203d, 0x203d, 0x2035, 0x2035,
+    0x20b1, 0x20b1, 0x20a9, 0x20a9, 0x0215, 0x011d, 0x002d, 0x0d09,
+    0x0519, 0x0811, 0x0419, 0x0321, 0x0221, 0x0139, 0x00a1, 0x0099,
+    0x0068, 0x0090, 0x3fff, 0x3fff, 0x0070, 0x0078, 0x0080, 0x0088,
+    0x20b9, 0x20b9, 0x20c1, 0x20c1, 0x2141, 0x2141, 0x2911, 0x2911,
+    0x2315, 0x2315, 0x2415, 0x2415, 0x2f0d, 0x2f0d, 0x300d, 0x300d,
+    0x0098, 0x00a0, 0x00a8, 0x00b0, 0x00c9, 0x00d1, 0x00d9, 0x0149,
+    0x0619, 0x0151, 0x0229, 0x0719, 0x0e09, 0x0045, 0x0515, 0x0615,
+    0x110d, 0x120d, 0x130d, 0x140d, 0x00c0, 0x00c8, 0x00d0, 0x00d8,
+    0x0091, 0x0089, 0x2e0d, 0x2e0d, 0x2d0d, 0x2d0d, 0x2c0d, 0x2c0d,
+    0x2b0d, 0x2b0d, 0x2a0d, 0x2a0d, 0x2115, 0x2115, 0x2025, 0x2025,
+    0x00e8, 0x00f0, 0x00f8, 0x0100, 0x2c09, 0x2c09, 0x2b09, 0x2b09,
+    0x2711, 0x2711, 0x2611, 0x2611, 0x2511, 0x2511, 0x2319, 0x2319,
+    0x2219, 0x2219, 0x2131, 0x2131, 0x0110, 0x0130, 0x0138, 0x0140,
+    0x0118, 0x0120, 0x0128, 0x080d, 0x2129, 0x2129, 0x2081, 0x2081,
+    0x2411, 0x2411, 0x2079, 0x2079, 0x2071, 0x2071, 0x2069, 0x2069,
+    0x1bb5, 0x060d, 0x001d, 0xd3f9, 0x0909, 0x0809, 0x090d, 0x0311,
+    0x0121, 0x0061, 0x0059, 0x0051, 0x0150, 0x0158, 0x0160, 0x0168,
+    0x240d, 0x240d, 0x230d, 0x230d, 0x2609, 0x2609, 0x250d, 0x250d,
+    0x2709, 0x2709, 0x2211, 0x2211, 0x2119, 0x2119, 0x2049, 0x2049,
+    0x0015, 0x0509, 0x020d, 0x010d, 0x0409, 0x0309, 0x0041, 0x0039,
+    0x0111, 0x0031, 0x2209, 0x2209, 0x2029, 0x2029, 0x2021, 0x2021
+};
+
+const OMX_U16 armVCM4P2_aIntraDCLumaChromaIndex[64] = {
+    0x0020, 0x000b, 0x2009, 0x2009, 0x2007, 0x2007, 0x2001, 0x2001,
+    0x4005, 0x4005, 0x4005, 0x4005, 0x4003, 0x4003, 0x4003, 0x4003,
+    0x0028, 0x000f, 0x200d, 0x200d, 0x0030, 0x0013, 0x2011, 0x2011,
+    0x0038, 0x0017, 0x2015, 0x2015, 0x3fff, 0x3fff, 0x2019, 0x2019,
+
+	0x0020, 0x0009, 0x2007, 0x2007, 0x4005, 0x4005, 0x4005, 0x4005,
+    0x4003, 0x4003, 0x4003, 0x4003, 0x4001, 0x4001, 0x4001, 0x4001,
+    0x0028, 0x000d, 0x200b, 0x200b, 0x0030, 0x0011, 0x200f, 0x200f,
+    0x0038, 0x0015, 0x2013, 0x2013, 0x1fff, 0x0019, 0x2017, 0x2017
+};
+
+
+const OMX_U16 armVCM4P2_aVlcMVD[124] = {
+    0x0010, 0x00f0, 0x0043, 0x003f, 0x4041, 0x4041, 0x4041, 0x4041,
+    0x0018, 0x00d8, 0x0047, 0x003b, 0x0020, 0x0080, 0x00a8, 0x00d0,
+    0x0028, 0x0048, 0x0070, 0x0078, 0x1fff, 0x0030, 0x0038, 0x0040,
+    0x0081, 0x0001, 0x007f, 0x0003, 0x207d, 0x207d, 0x2005, 0x2005,
+    0x207b, 0x207b, 0x2007, 0x2007, 0x0050, 0x0058, 0x0060, 0x0068,
+    0x2079, 0x2079, 0x2009, 0x2009, 0x2077, 0x2077, 0x200b, 0x200b,
+    0x2075, 0x2075, 0x200d, 0x200d, 0x2073, 0x2073, 0x200f, 0x200f,
+    0x0071, 0x0011, 0x006f, 0x0013, 0x006d, 0x0015, 0x006b, 0x0017,
+    0x0088, 0x0090, 0x0098, 0x00a0, 0x0069, 0x0019, 0x0067, 0x001b,
+    0x0065, 0x001d, 0x0063, 0x001f, 0x0061, 0x0021, 0x005f, 0x0023,
+    0x005d, 0x0025, 0x005b, 0x0027, 0x00b0, 0x00b8, 0x00c0, 0x00c8,
+    0x0059, 0x0029, 0x0057, 0x002b, 0x2055, 0x2055, 0x202d, 0x202d,
+    0x2053, 0x2053, 0x202f, 0x202f, 0x2051, 0x2051, 0x2031, 0x2031,
+    0x204f, 0x204f, 0x2033, 0x2033, 0x00e0, 0x00e8, 0x0049, 0x0039,
+    0x204d, 0x204d, 0x2035, 0x2035, 0x204b, 0x204b, 0x2037, 0x2037,
+    0x2045, 0x2045, 0x203d, 0x203d
+};
+
+/* LMAX table for non Inter (Last == 0 and Last=1)
+   Level - 1 Indexed
+   padded armVCM4P2_InterL0L1LMAX[27-31] with zeros to acess entries for Last=1 effectively
+
+*/
+const OMX_U8 armVCM4P2_InterL0L1LMAX[73] = 
+{
+   12,  6,  4,  3,  3,  3,  3,  2, 
+    2,  2,  2,  1,  1,  1,  1,  1,
+    1,  1,  1,  1,  1,  1,  1,  1,
+    1,  1,  1,  0,  0,  0,  0,  0,
+    3,  2,  1,  1,  1,  1,  1,  1, 
+	1,  1,  1,  1,  1,  1,  1,  1,
+	1,  1,  1,  1,  1,  1,  1,  1,
+	1,  1,  1,  1,  1,  1,  1,  1,
+	1,  1,  1,  1,  1,  1,  1,  1,
+	1
+};
+
+/* RMAX table for non Inter (Last == 0 and Last=1)
+   Level - 1 Indexed 
+ padded armVCM4P2_InterL0L1RMAX[12-31] with zeros to access entries for Last=1 table effectively */
+
+
+const OMX_U8 armVCM4P2_InterL0L1RMAX[35] = 
+{
+   26, 10,  6,  2,  1,  1,   
+    0,  0,  0,  0,  0,  0,
+	0,	0,	0,	0,	0,	0,
+	0,	0,	0,	0,	0,	0,
+	0,	0,	0,	0,
+    0,  0,  0,  0,  40,  1,  0
+};
+
+/* LMAX table for non Intra (Last == 0 and Last=1)
+   Level - 1 Indexed
+   padded armVCM4P2_IntraL0L1LMAX[15-31] with zeros to acess entries for Last=1 effectively
+
+*/
+const OMX_U8 armVCM4P2_IntraL0L1LMAX[53] = 
+{
+   27, 10,  5,  4,  3,  3,  3,  
+    3,  2,  2,  1,  1,  1,  1,  1,	0,
+	0,	0,	0,	0,	0,	0,	0,	0,
+	0,	0,	0,	0,	0,	0,	0,	0,
+
+	8,  3,  2,  2,  2,  2,  2,  1, 
+	1,  1,  1,  1,  1,  1,  1,  1,
+	1,  1,  1,  1,  1
+};
+
+
+/* RMAX table for non Inter (Last == 0 and Last=1)
+   Level - 1 Indexed 
+ padded armVCM4P2_IntraL0L1RMAX[27-31] with zeros to access entries for Last=1 table effectively */
+
+
+const OMX_U8 armVCM4P2_IntraL0L1RMAX[40] =
+{
+   14,  9,  7,  3,  2,  1,	1,  
+    1,  1,  1,  0,  0,  0, 	0,  
+    0,  0,  0,  0,  0,  0,  0,  
+    0,  0,  0,  0,  0,  0,  0,
+	0,	0,	0,	0,
+	
+	20,  6,  1,  0,  0,  0,  0,  0
+
+};
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/armVCM4P2_Lookup_Tables.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/armVCM4P2_Lookup_Tables.c
new file mode 100755
index 0000000..6948f80
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/armVCM4P2_Lookup_Tables.c
@@ -0,0 +1,75 @@
+ /**
+ * 
+ * File Name:  armVCM4P2_Lookup_Tables.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   12290
+ * Date:       Wednesday, April 9, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * File:        armVCM4P2_Lookup_Tables.c
+ * Description: Contains all the Lookup tables used in MPEG4 codec
+ *
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+
+    /* * Table Entries contain Dc Scaler values
+       * armVCM4P2_DCScaler[i]= 8           for i=1  to  4 and i=33 to 36
+       *                      = 2*i         for i=5  to  8
+       *                      = i+8         for i=9  to  25
+       *                      = 2*i-16      for i=26 to  31
+       *                      = (i-32+13)/2 for i=37 to  59
+       *                      = i-6-32      for i=60 to  63
+       *                      = 255         for i=0 and i=32
+       */
+       
+const OMX_U8 armVCM4P2_DCScaler[64]={
+	0xff, 0x8,  0x8,  0x8,  0x8,  0xa,  0xc,  0xe,  
+    0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 
+    0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
+    0x20, 0x22, 0x24, 0x26, 0x28, 0x2a, 0x2c, 0x2e,
+    0xff, 0x8,  0x8,  0x8,  0x8,  0x9,  0x9,  0xa,  
+    0xa,  0xb,  0xb,  0xc,  0xc,  0xd,  0xd,  0xe,  
+    0xe,  0xf,  0xf,  0x10, 0x10, 0x11, 0x11, 0x12, 
+    0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19,
+
+};
+
+              
+     /*  Table Entries Contain reciprocal of 1 to 63
+      *  armVCM4P2_Reciprocal_QP_S16[i]=round(32767/i)
+      *  armVCM4P2_Reciprocal_QP_S16[0]= 0
+      */
+
+const OMX_S16 armVCM4P2_Reciprocal_QP_S16[64]={
+	0x0000,0x7fff,0x4000,0x2aaa,0x2000,0x1999,0x1555,0x1249,
+    0x1000,0x0e39,0x0ccd,0x0ba3,0x0aab,0x09d9,0x0925,0x0888,
+    0x0800,0x0787,0x071c,0x06bd,0x0666,0x0618,0x05d1,0x0591,
+    0x0555,0x051f,0x04ec,0x04be,0x0492,0x046a,0x0444,0x0421,
+    0x0400,0x03e1,0x03c4,0x03a8,0x038e,0x0376,0x035e,0x0348,
+    0x0333,0x031f,0x030c,0x02fa,0x02e9,0x02d8,0x02c8,0x02b9,
+    0x02ab,0x029d,0x028f,0x0282,0x0276,0x026a,0x025f,0x0254,
+    0x0249,0x023f,0x0235,0x022b,0x0222,0x0219,0x0211,0x0208
+	   
+};
+     
+      /* Table Entries Contain reciprocal of 1 to 63
+       * armVCM4P2_Reciprocal_QP_S32[i]=round(131071/i)
+       * armVCM4P2_Reciprocal_QP_S32[0]= 0
+       */
+
+const OMX_S32 armVCM4P2_Reciprocal_QP_S32[64]={
+	0x00000000,0x0001ffff,0x00010000,0x0000aaaa, 0x00008000, 0x00006666, 0x00005555, 0x00004924,
+    0x00004000,0x000038e3,0x00003333,0x00002e8c, 0x00002aab, 0x00002762, 0x00002492, 0x00002222,
+    0x00002000,0x00001e1e,0x00001c72,0x00001af2, 0x0000199a, 0x00001861, 0x00001746, 0x00001643,
+    0x00001555,0x0000147b,0x000013b1,0x000012f6, 0x00001249, 0x000011a8, 0x00001111, 0x00001084,
+    0x00001000,0x00000f84,0x00000f0f,0x00000ea1, 0x00000e39, 0x00000dd6, 0x00000d79, 0x00000d21,
+    0x00000ccd,0x00000c7d,0x00000c31,0x00000be8, 0x00000ba3, 0x00000b61, 0x00000b21, 0x00000ae5,
+    0x00000aab,0x00000a73,0x00000a3d,0x00000a0a, 0x000009d9, 0x000009a9, 0x0000097b, 0x0000094f,
+    0x00000925,0x000008fb,0x000008d4,0x000008ae, 0x00000889, 0x00000865, 0x00000842, 0x00000820
+	
+};
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/armVCM4P2_SetPredDir_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/armVCM4P2_SetPredDir_s.s
new file mode 100755
index 0000000..44f2460
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/armVCM4P2_SetPredDir_s.s
@@ -0,0 +1,104 @@
+;//
+;// 
+;// File Name:  armVCM4P2_SetPredDir_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   12290
+;// Date:       Wednesday, April 9, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+; **
+; * Function: armVCM4P2_SetPredDir
+; *
+; * Description:
+; * Performs detecting the prediction direction
+; *
+; * Remarks:
+; *
+; * Parameters:
+; * [in] blockIndex  block index indicating the component type and
+; *                          position as defined in subclause 6.1.3.8, of ISO/IEC
+; *                          14496-2. Furthermore, indexes 6 to 9 indicate the
+; *                          alpha blocks spatially corresponding to luminance
+; *                          blocks 0 to 3 in the same macroblock.
+; * [in] pCoefBufRow pointer to the coefficient row buffer
+; * [in] pQpBuf      pointer to the quantization parameter buffer
+; * [out]predQP      quantization parameter of the predictor block
+; * [out]predDir     indicates the prediction direction which takes one
+; *                  of the following values:
+; *                  OMX_VC_HORIZONTAL    predict horizontally
+; *                  OMX_VC_VERTICAL      predict vertically
+; *
+; * Return Value:
+; * Standard OMXResult result. See enumeration for possible result codes.
+; *
+; */
+
+       INCLUDE omxtypes_s.h
+       INCLUDE armCOMM_s.h
+       INCLUDE omxVC_s.h
+
+
+       M_VARIANTS ARM1136JS
+
+
+       IF ARM1136JS
+ 
+;// Input Arguments
+BlockIndex         RN 0
+pCoefBufRow        RN 1
+pCoefBufCol        RN 2
+predDir            RN 3
+predQP             RN 4
+pQpBuf             RN 5
+
+;// Local Variables
+
+Return             RN 0
+blockDCLeft        RN 6  
+blockDCTop         RN 7
+blockDCTopLeft     RN 8
+temp1              RN 9
+temp2              RN 14
+
+       M_START    armVCM4P2_SetPredDir,r9
+
+       M_ARG       ppredQP,4
+       M_ARG       ppQpBuf,4
+    
+       LDRH        blockDCTopLeft,[pCoefBufRow,#-16]
+       LDRH        blockDCLeft,[pCoefBufCol]
+       
+       TEQ         BlockIndex,#3
+       LDREQH      blockDCTop,[pCoefBufCol,#-16]
+       LDRNEH      blockDCTop,[pCoefBufRow]
+             
+       SUBS        temp1,blockDCLeft,blockDCTopLeft
+       RSBLT       temp1,temp1,#0
+       SUBS        temp2,blockDCTopLeft,blockDCTop
+       RSBLT       temp2,temp2,#0
+      
+       M_LDR       pQpBuf,ppQpBuf
+       M_LDR       predQP,ppredQP
+       CMP         temp1,temp2
+       MOV         temp2,#OMX_VC_VERTICAL
+       LDRLTB      temp1,[pQpBuf,#1]
+       STRLT       temp2,[predDir]
+       STRLT       temp1,[predQP]
+       MOV         temp2,#OMX_VC_HORIZONTAL           
+       LDRGEB      temp1,[pQpBuf]
+       STRGE       temp2,[predDir]
+       MOV         Return,#OMX_Sts_NoErr
+       STRGE       temp1,[predQP] 
+
+         
+    
+       M_END
+ 
+       ENDIF
+
+       END    
+    
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/armVCM4P2_Zigzag_Tables.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/armVCM4P2_Zigzag_Tables.c
new file mode 100755
index 0000000..21fa715
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/armVCM4P2_Zigzag_Tables.c
@@ -0,0 +1,61 @@
+/**
+ * 
+ * File Name:  armVCM4P2_Zigzag_Tables.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   12290
+ * Date:       Wednesday, April 9, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * File:        armVCM4P2_ZigZag_Tables.c
+ * Description: Contains the zigzag tables
+ *
+ */
+
+#include "omxtypes.h"
+
+/* Contains Double the values in the reference Zigzag Table
+ * Contains Classical,Vetical and Horizontal Zigzagscan tables in one array  
+ */
+
+const OMX_U8 armVCM4P2_aClassicalZigzagScan [192] = 
+{
+     0,  2,  16, 32,  18,  4,  6, 20,
+    34, 48, 64, 50, 36, 22,  8,  10,
+    24, 38, 52, 66, 80, 96, 82, 68,
+    54, 40, 26,  12,  14, 28, 42, 56, 
+    70, 84, 98, 112, 114, 100, 86, 72,
+    58, 44, 30, 46, 60, 74, 88, 102,
+    116, 118, 104, 90, 76, 62, 78, 92,
+    106, 120, 122, 104, 94, 110, 124, 126,
+
+	0,  16, 32, 48,  2,  18,  4, 20,
+    34, 50, 64, 80, 96, 112, 114, 98,
+    82, 66, 52, 36,  6, 22,  8, 24,
+    38, 54, 68, 84, 100, 116, 70, 86,
+    102, 118, 40, 56,  10, 26,  12, 28,
+    42, 58, 72, 88, 104, 120, 74, 90, 
+    106, 122, 44, 60,  14, 30, 46, 62,
+    76, 92, 108, 124, 78, 94, 110, 126,
+
+    0,  2,  4,  6,  16,  18, 32, 34,
+    20, 22,  8,  10,  12,  14, 30, 28,
+    26, 24, 38, 36, 48, 50, 64, 66,
+    52, 54, 40, 42, 44, 46, 56, 58,
+    60, 62, 68, 70, 80, 82, 96, 98,
+    84, 86, 72, 74, 76, 78, 88, 90, 
+    92, 94, 100, 102, 112, 114, 116, 118,
+    104, 106, 108, 110, 120, 122, 124, 126
+
+
+};
+
+
+
+
+
+/* End of file */
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/omxVCM4P2_DecodeBlockCoef_Inter.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/omxVCM4P2_DecodeBlockCoef_Inter.c
new file mode 100755
index 0000000..796ad6e
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/omxVCM4P2_DecodeBlockCoef_Inter.c
@@ -0,0 +1,102 @@
+/**
+ * 
+ * File Name:  omxVCM4P2_DecodeBlockCoef_Inter.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   12290
+ * Date:       Wednesday, April 9, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Description: 
+ * Contains modules for inter reconstruction
+ * 
+ */
+ 
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+
+
+/**
+ * Function: omxVCM4P2_DecodeBlockCoef_Inter
+ *
+ * Description:
+ * Decodes the INTER block coefficients. Inverse quantization, inversely zigzag
+ * positioning and IDCT, with appropriate clipping on each step, are performed
+ * on the coefficients. The results (residuals) are placed in a contiguous array
+ * of 64 elements. For INTER block, the output buffer holds the residuals for
+ * further reconstruction.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	ppBitStream		pointer to the pointer to the current byte in
+ *								the bit stream buffer. There is no boundary
+ *								check for the bit stream buffer.
+ * [in]	pBitOffset		pointer to the bit position in the byte pointed
+ *								to by *ppBitStream. *pBitOffset is valid within
+ *								[0-7]
+ * [in]	QP				quantization parameter
+ * [in] shortVideoHeader    a flag indicating presence of short_video_header;
+ *                           shortVideoHeader==1 indicates using quantization method defined in short
+ *                           video header mode, and shortVideoHeader==0 indicates normail quantization method.
+ * [out] ppBitStream 	*ppBitStream is updated after the block is decoded, so that it points to the
+ *                      current byte in the bit stream buffer.
+ * [out] pBitOffset		*pBitOffset is updated so that it points to the current bit position in the
+ *                      byte pointed by *ppBitStream
+ * [out] pDst			pointer to the decoded residual buffer (a contiguous array of 64 elements of
+ *                      OMX_S16 data type). Must be 16-byte aligned.
+ *
+ * Return Value:
+ * OMX_Sts_NoErr - no error
+ * OMX_Sts_BadArgErr - bad arguments
+ *   - At least one of the following pointers is Null: ppBitStream, *ppBitStream, pBitOffset , pDst
+ *   - At least one of the below case:
+ *   - *pBitOffset exceeds [0,7], QP <= 0;
+ *	 - pDst not 16-byte aligned
+ * OMX_Sts_Err - status error
+ *
+ */
+OMXResult omxVCM4P2_DecodeBlockCoef_Inter(
+     const OMX_U8 ** ppBitStream,
+     OMX_INT * pBitOffset,
+     OMX_S16 * pDst,
+     OMX_INT QP,
+     OMX_INT shortVideoHeader
+)
+{
+    /* 64 elements are needed but to align it to 16 bytes need
+    15 more elements of padding */
+    OMX_S16 tempBuf[79];
+    OMX_S16 *pTempBuf1;
+    OMXResult errorCode;
+    /* Aligning the local buffers */
+    pTempBuf1 = armAlignTo16Bytes(tempBuf);
+    
+    
+    /* VLD and zigzag */
+    errorCode = omxVCM4P2_DecodeVLCZigzag_Inter(ppBitStream, pBitOffset, 
+                                        pTempBuf1,shortVideoHeader);
+    armRetDataErrIf((errorCode != OMX_Sts_NoErr), errorCode);
+    
+    /* Dequantization */
+    errorCode = omxVCM4P2_QuantInvInter_I(
+     pTempBuf1,
+     QP);
+    armRetDataErrIf((errorCode != OMX_Sts_NoErr), errorCode);
+    
+    /* Inverse transform */
+    errorCode = omxVCM4P2_IDCT8x8blk(pTempBuf1, pDst);
+    armRetDataErrIf((errorCode != OMX_Sts_NoErr), errorCode);
+	    
+    return OMX_Sts_NoErr;
+}
+
+/* End of file */
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/omxVCM4P2_DecodeBlockCoef_Intra.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/omxVCM4P2_DecodeBlockCoef_Intra.c
new file mode 100755
index 0000000..b28657c
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/omxVCM4P2_DecodeBlockCoef_Intra.c
@@ -0,0 +1,214 @@
+/**
+ * 
+ * File Name:  omxVCM4P2_DecodeBlockCoef_Intra.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   12290
+ * Date:       Wednesday, April 9, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Description: 
+ * Contains modules for intra reconstruction
+ * 
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+
+/* Function for saturating 16 bit values to the [0,255] range and  */
+/* writing out as 8 bit values.  Does 64 entries                   */
+void armVCM4P2_Clip8(OMX_S16 *pSrc, OMX_U8 *pDst, OMX_INT dstStep );
+
+
+
+/**
+ * Function: omxVCM4P2_DecodeBlockCoef_Intra
+ *
+ * Description:
+ * Decodes the INTRA block coefficients. Inverse quantization, inversely zigzag
+ * positioning, and IDCT, with appropriate clipping on each step, are performed
+ * on the coefficients. The results are then placed in the output frame/plane on
+ * a pixel basis. For INTRA block, the output values are clipped to [0, 255] and
+ * written to corresponding block buffer within the destination plane.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	ppBitStream		pointer to the pointer to the current byte in
+ *								the bit stream buffer. There is no boundary
+ *								check for the bit stream buffer.
+ * [in]	pBitOffset		pointer to the bit position in the byte pointed
+ *								to by *ppBitStream. *pBitOffset is valid within
+ *								[0-7].
+ * [in]	step			width of the destination plane
+ * [in/out]	pCoefBufRow		[in]  pointer to the coefficient row buffer
+ *                        [out] updated coefficient rwo buffer
+ * [in/out]	pCoefBufCol		[in]  pointer to the coefficient column buffer
+ *                        [out] updated coefficient column buffer
+ * [in]	curQP			quantization parameter of the macroblock which
+ *								the current block belongs to
+ * [in]	pQpBuf		 Pointer to a 2-element QP array. pQpBuf[0] holds the QP of the 8x8 block left to
+ *                   the current block(QPa). pQpBuf[1] holds the QP of the 8x8 block just above the
+ *                   current block(QPc).
+ *                   Note, in case the corresponding block is out of VOP bound, the QP value will have
+ *                   no effect to the intra-prediction process. Refer to subclause  "7.4.3.3 Adaptive
+ *                   ac coefficient prediction" of ISO/IEC 14496-2(MPEG4 Part2) for accurate description.
+ * [in]	blockIndex		block index indicating the component type and
+ *								position as defined in subclause 6.1.3.8,
+ *								Figure 6-5 of ISO/IEC 14496-2. 
+ * [in]	intraDCVLC		a code determined by intra_dc_vlc_thr and QP.
+ *								This allows a mechanism to switch between two VLC
+ *								for coding of Intra DC coefficients as per Table
+ *								6-21 of ISO/IEC 14496-2. 
+ * [in]	ACPredFlag		a flag equal to ac_pred_flag (of luminance) indicating
+ *								if the ac coefficients of the first row or first
+ *								column are differentially coded for intra coded
+ *								macroblock.
+ * [in] shortVideoHeader    a flag indicating presence of short_video_header;
+ *                           shortVideoHeader==1 selects linear intra DC mode,
+ *							and shortVideoHeader==0 selects nonlinear intra DC mode.
+ * [out]	ppBitStream		*ppBitStream is updated after the block is
+ *								decoded, so that it points to the current byte
+ *								in the bit stream buffer
+ * [out]	pBitOffset		*pBitOffset is updated so that it points to the
+ *								current bit position in the byte pointed by
+ *								*ppBitStream
+ * [out]	pDst			pointer to the block in the destination plane.
+ *								pDst should be 16-byte aligned.
+ * [out]	pCoefBufRow		pointer to the updated coefficient row buffer.
+ *
+ * Return Value:
+ * OMX_Sts_NoErr - no error
+ * OMX_Sts_BadArgErr - bad arguments
+ *   -	At least one of the following pointers is NULL: ppBitStream, *ppBitStream, pBitOffset,
+ *                                                      pCoefBufRow, pCoefBufCol, pQPBuf, pDst.
+ *      or
+ *   -  At least one of the below case: *pBitOffset exceeds [0,7], curQP exceeds (1, 31),
+ *      blockIndex exceeds [0,9], step is not the multiple of 8, intraDCVLC is zero while
+ *      blockIndex greater than 5.
+ *      or
+ *   -	pDst is not 16-byte aligned
+ * OMX_Sts_Err - status error
+ *
+ */
+
+OMXResult omxVCM4P2_DecodeBlockCoef_Intra(
+     const OMX_U8 ** ppBitStream,
+     OMX_INT *pBitOffset,
+     OMX_U8 *pDst,
+     OMX_INT step,
+     OMX_S16 *pCoefBufRow,
+     OMX_S16 *pCoefBufCol,
+     OMX_U8 curQP,
+     const OMX_U8 *pQPBuf,
+     OMX_INT blockIndex,
+     OMX_INT intraDCVLC,
+     OMX_INT ACPredFlag,
+	 OMX_INT shortVideoHeader
+ )
+{
+    OMX_S16 tempBuf1[79], tempBuf2[79];
+    OMX_S16 *pTempBuf1, *pTempBuf2;
+    OMX_INT predDir, predACDir;
+    OMX_INT  predQP;
+    OMXVCM4P2VideoComponent videoComp;
+    OMXResult errorCode;
+    
+    
+    /* Aligning the local buffers */
+    pTempBuf1 = armAlignTo16Bytes(tempBuf1);
+    pTempBuf2 = armAlignTo16Bytes(tempBuf2);
+    
+    /* Setting the AC prediction direction and prediction direction */
+    armVCM4P2_SetPredDir(
+        blockIndex,
+        pCoefBufRow,
+        pCoefBufCol,
+        &predDir,
+        &predQP,
+        pQPBuf);
+
+    predACDir = predDir;
+
+    
+    if (ACPredFlag == 0)
+    {
+        predACDir = OMX_VC_NONE;
+    }
+
+    /* Setting the videoComp */
+    if (blockIndex <= 3)
+    {
+        videoComp = OMX_VC_LUMINANCE;
+    }
+    else
+    {
+        videoComp = OMX_VC_CHROMINANCE;
+    }
+    
+
+    /* VLD and zigzag */
+    if (intraDCVLC == 1)
+    {
+        errorCode = omxVCM4P2_DecodeVLCZigzag_IntraDCVLC(
+            ppBitStream,
+            pBitOffset,
+            pTempBuf1,
+            predACDir,
+            shortVideoHeader,
+            videoComp);
+        armRetDataErrIf((errorCode != OMX_Sts_NoErr), errorCode);
+    }
+    else
+    {
+        errorCode = omxVCM4P2_DecodeVLCZigzag_IntraACVLC(
+            ppBitStream,
+            pBitOffset,
+            pTempBuf1,
+            predACDir,
+            shortVideoHeader);
+        armRetDataErrIf((errorCode != OMX_Sts_NoErr), errorCode);
+    }
+
+    /* AC DC prediction */
+    errorCode = omxVCM4P2_PredictReconCoefIntra(
+        pTempBuf1,
+        pCoefBufRow,
+        pCoefBufCol,
+        curQP,
+        predQP,
+        predDir,
+        ACPredFlag,
+        videoComp);
+    armRetDataErrIf((errorCode != OMX_Sts_NoErr), errorCode);
+    
+    /* Dequantization */
+    errorCode = omxVCM4P2_QuantInvIntra_I(
+     pTempBuf1,
+     curQP,
+     videoComp,
+     shortVideoHeader);
+    armRetDataErrIf((errorCode != OMX_Sts_NoErr), errorCode);
+    
+    /* Inverse transform */
+    errorCode = omxVCM4P2_IDCT8x8blk (pTempBuf1, pTempBuf2);
+    armRetDataErrIf((errorCode != OMX_Sts_NoErr), errorCode);
+    
+    /* Placing the linear array into the destination plane and clipping
+       it to 0 to 255 */
+    
+	armVCM4P2_Clip8(pTempBuf2,pDst,step);
+	
+	
+    return OMX_Sts_NoErr;
+}
+
+/* End of file */
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/omxVCM4P2_DecodePadMV_PVOP_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/omxVCM4P2_DecodePadMV_PVOP_s.s
new file mode 100755
index 0000000..cc16f5a
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/omxVCM4P2_DecodePadMV_PVOP_s.s
@@ -0,0 +1,364 @@
+; **********
+; * 
+; * File Name:  omxVCM4P2_DecodePadMV_PVOP_s.s
+; * OpenMAX DL: v1.0.2
+; * Revision:   12290
+; * Date:       Wednesday, April 9, 2008
+; * 
+; * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+; * 
+; * 
+; * 
+; **
+; * Function: omxVCM4P2_DecodePadMV_PVOP
+; *
+; * Description:
+; * Decodes and pads four motion vectors of the non-intra macroblock in P-VOP.
+; * The motion vector padding process is specified in subclause 7.6.1.6 of
+; * ISO/IEC 14496-2.
+; *
+; * Remarks:
+; *
+; *
+; * Parameters:
+; * [in]    ppBitStream        pointer to the pointer to the current byte in
+; *                            the bit stream buffer
+; * [in]    pBitOffset         pointer to the bit position in the byte pointed
+; *                            to by *ppBitStream. *pBitOffset is valid within
+; *                            [0-7].
+; * [in]    pSrcMVLeftMB       pointers to the motion vector buffers of the
+; *                           macroblocks specially at the left side of the current macroblock
+; *                     respectively.
+; * [in]    pSrcMVUpperMB      pointers to the motion vector buffers of the
+; *                     macroblocks specially at the upper side of the current macroblock
+; *                     respectively.
+; * [in]    pSrcMVUpperRightMB pointers to the motion vector buffers of the
+; *                     macroblocks specially at the upper-right side of the current macroblock
+; *                     respectively.
+; * [in]    fcodeForward       a code equal to vop_fcode_forward in MPEG-4
+; *                     bit stream syntax
+; * [in]    MBType         the type of the current macroblock. If MBType
+; *                     is not equal to OMX_VC_INTER4V, the destination
+; *                     motion vector buffer is still filled with the
+; *                     same decoded vector.
+; * [out]   ppBitStream         *ppBitStream is updated after the block is decoded,
+; *                     so that it points to the current byte in the bit
+; *                     stream buffer
+; * [out]   pBitOffset         *pBitOffset is updated so that it points to the
+; *                     current bit position in the byte pointed by
+; *                     *ppBitStream
+; * [out]   pDstMVCurMB         pointer to the motion vector buffer of the current
+; *                     macroblock which contains four decoded motion vectors
+; *
+; * Return Value:
+; * OMX_Sts_NoErr -no error
+; * 
+; *                     
+; * OMX_Sts_Err - status error
+; *
+; *
+     
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+        INCLUDE armCOMM_BitDec_s.h
+        INCLUDE omxVC_s.h
+        
+       M_VARIANTS ARM1136JS
+       
+                
+
+
+        IF ARM1136JS
+
+;//Input Arguments
+
+ppBitStream           RN 0
+pBitOffset            RN 1
+pSrcMVLeftMB          RN 2
+pSrcMVUpperMB         RN 3
+pSrcMVUpperRightMB    RN 4
+pDstMVCurMB           RN 5
+fcodeForward          RN 6
+MBType                RN 7
+
+;//Local Variables
+
+zero                  RN 4
+one                   RN 4
+scaleFactor           RN 1
+
+
+Return                RN 0
+
+VlcMVD                RN 0
+index                 RN 4
+Count                 RN 7
+
+mvHorData             RN 4
+mvHorResidual         RN 0
+
+mvVerData             RN 4             
+mvVerResidual         RN 0
+
+temp                  RN 1
+
+temp1                 RN 3
+High                  RN 4
+Low                   RN 2
+Range                 RN 1
+
+BlkCount              RN 14
+
+diffMVdx              RN 0
+diffMVdy              RN 1
+
+;// Scratch Registers
+
+RBitStream            RN 8
+RBitCount             RN 9
+RBitBuffer            RN 10
+
+T1                    RN 11
+T2                    RN 12
+LR                    RN 14
+
+       IMPORT          armVCM4P2_aVlcMVD
+       IMPORT          omxVCM4P2_FindMVpred
+
+       ;// Allocate stack memory        
+       
+       M_ALLOC4        ppDstMVCurMB,4
+       M_ALLOC4        pDstMVPredME,4
+       M_ALLOC4        pBlkCount,4
+       
+       M_ALLOC4        pppBitStream,4
+       M_ALLOC4        ppBitOffset,4
+       M_ALLOC4        ppSrcMVLeftMB,4
+       M_ALLOC4        ppSrcMVUpperMB,4
+       
+       M_ALLOC4        pdiffMVdx,4
+       M_ALLOC4        pdiffMVdy,4
+       M_ALLOC4        pHigh,4
+       
+              
+
+
+       M_START   omxVCM4P2_DecodePadMV_PVOP,r11
+       
+       M_ARG           pSrcMVUpperRightMBonStack,4           ;// pointer to  pSrcMVUpperRightMB on stack
+       M_ARG           pDstMVCurMBonStack,4                  ;// pointer to pDstMVCurMB on stack
+       M_ARG           fcodeForwardonStack,4                 ;// pointer to fcodeForward on stack 
+       M_ARG           MBTypeonStack,4                       ;// pointer to MBType on stack
+
+      
+       
+       
+       
+       ;// Initializing the BitStream Macro
+
+       M_BD_INIT0      ppBitStream, pBitOffset, RBitStream, RBitBuffer, RBitCount
+       M_LDR           MBType,MBTypeonStack                  ;// Load MBType from stack
+       M_LDR           pDstMVCurMB,pDstMVCurMBonStack        ;// Load pDstMVCurMB from stack
+       MOV             zero,#0
+
+       TEQ             MBType,#OMX_VC_INTRA                  ;// Check if MBType=OMX_VC_INTRA
+       TEQNE           MBType,#OMX_VC_INTRA_Q                ;// check if MBType=OMX_VC_INTRA_Q
+       STREQ           zero,[pDstMVCurMB]
+       M_BD_INIT1      T1, T2, T2
+       STREQ           zero,[pDstMVCurMB,#4]
+       M_BD_INIT2      T1, T2, T2
+       STREQ           zero,[pDstMVCurMB,#4]
+       MOVEQ           Return,#OMX_Sts_NoErr
+       MOV             BlkCount,#0
+       STREQ           zero,[pDstMVCurMB,#4]
+       
+       BEQ             ExitOK
+
+       TEQ             MBType,#OMX_VC_INTER4V                ;// Check if MBType=OMX_VC_INTER4V
+       TEQNE           MBType,#OMX_VC_INTER4V_Q              ;// Check if MBType=OMX_VC_INTER4V_Q
+       MOVEQ           Count,#4
+
+       TEQ             MBType,#OMX_VC_INTER                  ;// Check if MBType=OMX_VC_INTER
+       TEQNE           MBType,#OMX_VC_INTER_Q                ;// Check if MBType=OMX_VC_INTER_Q
+       MOVEQ           Count,#1
+       
+       M_LDR           fcodeForward,fcodeForwardonStack      ;// Load fcodeForward  from stack
+
+       ;// Storing the values temporarily on stack
+
+       M_STR           ppBitStream,pppBitStream              
+       M_STR           pBitOffset,ppBitOffset
+            
+
+       SUB             temp,fcodeForward,#1                  ;// temp=fcodeForward-1
+       MOV             one,#1
+       M_STR           pSrcMVLeftMB,ppSrcMVLeftMB
+       LSL             scaleFactor,one,temp                  ;// scaleFactor=1<<(fcodeForward-1)
+       M_STR           pSrcMVUpperMB,ppSrcMVUpperMB
+       LSL             scaleFactor,scaleFactor,#5            
+       M_STR           scaleFactor,pHigh                     ;// [pHigh]=32*scaleFactor
+              
+       ;// VLD Decoding
+
+
+Loop
+
+       LDR             VlcMVD, =armVCM4P2_aVlcMVD        ;// Load the optimized MVD VLC table
+
+       ;// Horizontal Data and Residual calculation
+
+       LDR             temp,=0xFFF                           
+       M_BD_VLD        index,T1,T2,VlcMVD,3,2                ;// variable lenght decoding using the macro
+      
+       TEQ             index,temp
+       BEQ             ExitError                             ;// Exit with an Error Message if the decoded symbol is an invalied symbol 
+       
+       SUB             mvHorData,index,#32                   ;// mvHorData=index-32             
+       MOV             mvHorResidual,#1                      ;// mvHorResidual=1
+       CMP             fcodeForward,#1
+       TEQNE           mvHorData,#0
+       MOVEQ           diffMVdx,mvHorData                    ;// if scaleFactor=1(fcodeForward=1) or mvHorData=0 diffMVdx=mvHorData         
+       BEQ             VerticalData
+       
+       SUB             temp,fcodeForward,#1
+       M_BD_VREAD8     mvHorResidual,temp,T1,T2              ;// get mvHorResidual from bitstream if fcodeForward>1 and mvHorData!=0              
+       
+       CMP             mvHorData,#0
+       RSBLT           mvHorData,mvHorData,#0                ;// mvHorData=abs(mvHorData)
+       SUB             mvHorResidual,mvHorResidual,fcodeForward
+       SMLABB          diffMVdx,mvHorData,fcodeForward,mvHorResidual ;// diffMVdx=abs(mvHorData)*fcodeForward+mvHorResidual-fcodeForward
+       ADD             diffMVdx,diffMVdx,#1
+       RSBLT           diffMVdx,diffMVdx,#0
+       
+       ;// Vertical Data and Residual calculation
+
+VerticalData
+
+       M_STR           diffMVdx,pdiffMVdx                    ;// Store the diffMVdx on stack
+       LDR             VlcMVD, =armVCM4P2_aVlcMVD        ;// Loading the address of optimized VLC tables
+
+       LDR             temp,=0xFFF
+       M_BD_VLD        index,T1,T2,VlcMVD,3,2                ;// VLC decoding using the macro
+       
+       TEQ             index,temp
+       BEQ             ExitError                             ;// Exit with an Error Message if an Invalied Symbol occurs
+       
+       SUB             mvVerData,index,#32                   ;// mvVerData=index-32             
+       MOV             mvVerResidual,#1     
+       CMP             fcodeForward,#1
+       TEQNE           mvVerData,#0
+       MOVEQ           diffMVdy,mvVerData                    ;// diffMVdy = mvVerData if scaleFactor=1(fcodeForward=1) or mvVerData=0
+       BEQ             FindMVPred
+
+       SUB             temp,fcodeForward,#1
+       M_BD_VREAD8     mvVerResidual,temp,T1,T2              ;// Get mvVerResidual from bit stream if fcodeForward>1 and mnVerData!=0
+             
+
+       CMP             mvVerData,#0
+       RSBLT           mvVerData,mvVerData,#0
+       SUB             mvVerResidual,mvVerResidual,fcodeForward
+       SMLABB          diffMVdy,mvVerData,fcodeForward,mvVerResidual ;// diffMVdy=abs(mvVerData)*fcodeForward+mvVerResidual-fcodeForward
+       ADD             diffMVdy,diffMVdy,#1
+       RSBLT           diffMVdy,diffMVdy,#0
+
+       ;//Calling the Function omxVCM4P2_FindMVpred
+        
+FindMVPred
+
+       M_STR           diffMVdy,pdiffMVdy
+       ADD             temp,pDstMVCurMB,BlkCount,LSL #2      ;// temp=pDstMVCurMB[BlkCount]
+       M_STR           temp,ppDstMVCurMB                     ;// store temp on stack for passing as an argument to FindMVPred
+       
+       MOV             temp,#0
+       M_STR           temp,pDstMVPredME                     ;// Pass pDstMVPredME=NULL as an argument         
+       M_STR           BlkCount,pBlkCount                    ;// Passs BlkCount as Argument through stack
+
+       MOV             temp,pSrcMVLeftMB                     ;// temp (RN 1)=pSrcMVLeftMB
+       M_LDR           pSrcMVUpperRightMB,pSrcMVUpperRightMBonStack
+       MOV             pSrcMVLeftMB,pSrcMVUpperMB            ;// pSrcMVLeftMB ( RN 2) = pSrcMVUpperMB
+       MOV             ppBitStream,pDstMVCurMB               ;// ppBitStream  ( RN 0) = pDstMVCurMB
+       MOV             pSrcMVUpperMB,pSrcMVUpperRightMB      ;// pSrcMVUpperMB( RN 3) = pSrcMVUpperRightMB      
+       BL              omxVCM4P2_FindMVpred              ;// Branch to subroutine omxVCM4P2_FindMVpred
+
+       ;// Store Horizontal Motion Vector
+     
+       M_LDR           BlkCount,pBlkCount                    ;// Load BlkCount from stack
+       M_LDR           High,pHigh                            ;// High=32*scaleFactor
+       LSL             temp1,BlkCount,#2                     ;// temp=BlkCount*4
+       M_LDR           diffMVdx,pdiffMVdx                    ;// Laad diffMVdx
+       
+       LDRSH           temp,[pDstMVCurMB,temp1]              ;// temp=pDstMVCurMB[BlkCount]
+       
+       
+       RSB             Low,High,#0                           ;// Low = -32*scaleFactor
+       ADD             diffMVdx,temp,diffMVdx                ;// diffMVdx=pDstMVCurMB[BlkCount]+diffMVdx
+       ADD             Range,High,High                       ;// Range=64*ScaleFactor
+       SUB             High,High,#1                          ;// High= 32*scaleFactor-1
+
+       CMP             diffMVdx,Low                          ;// If diffMVdx<Low          
+       ADDLT           diffMVdx,diffMVdx,Range               ;// diffMVdx+=Range
+        
+       CMP             diffMVdx,High                         
+       SUBGT           diffMVdx,diffMVdx,Range               ;// If diffMVdx > High diffMVdx-=Range
+       STRH            diffMVdx,[pDstMVCurMB,temp1]
+
+       ;// Store Vertical
+
+       ADD             temp1,temp1,#2                        ;// temp1=4*BlkCount+2
+       M_LDR           diffMVdx,pdiffMVdy                    ;// Laad diffMVdy
+       LDRSH           temp,[pDstMVCurMB,temp1]              ;// temp=pDstMVCurMB[BlkCount].diffMVdy
+       ADD             BlkCount,BlkCount,#1                  ;// BlkCount=BlkCount+1
+       ADD             diffMVdx,temp,diffMVdx                
+       CMP             diffMVdx,Low
+       ADDLT           diffMVdx,diffMVdx,Range               ;// If diffMVdy<Low  diffMVdy+=Range                
+       CMP             diffMVdx,High
+       SUBGT           diffMVdx,diffMVdx,Range               ;// If diffMVdy > High diffMVdy-=Range
+       STRH            diffMVdx,[pDstMVCurMB,temp1]    
+       
+       CMP             BlkCount,Count
+       M_LDR           pSrcMVLeftMB,ppSrcMVLeftMB
+       M_LDR           pSrcMVUpperMB,ppSrcMVUpperMB
+
+       BLT             Loop                                  ;// If BlkCount<Count Continue the Loop
+
+
+       ;// If MBType=OMX_VC_INTER or MBtype=OMX_VC_INTER_Q copy pDstMVCurMB[0] to
+       ;// pDstMVCurMB[1], pDstMVCurMB[2], pDstMVCurMB[3] 
+
+       M_LDR           MBType,MBTypeonStack
+
+       TEQ             MBType,#OMX_VC_INTER                                       
+       TEQNE           MBType,#OMX_VC_INTER_Q                            
+       LDREQ           temp,[pDstMVCurMB]
+       M_LDR           ppBitStream,pppBitStream
+       STREQ           temp,[pDstMVCurMB,#4]
+       
+       STREQ           temp,[pDstMVCurMB,#8]
+       STREQ           temp,[pDstMVCurMB,#12]
+       
+       
+       M_LDR           pBitOffset,ppBitOffset
+       ;//Ending the macro
+       M_BD_FINI       ppBitStream,pBitOffset                 ;// Finishing the Macro       
+
+       
+       MOV             Return,#OMX_Sts_NoErr
+       B               ExitOK
+ 
+ExitError
+
+       M_LDR           ppBitStream,pppBitStream
+       M_LDR           pBitOffset,ppBitOffset
+       ;//Ending the macro
+       M_BD_FINI       ppBitStream,pBitOffset
+       
+       MOV             Return,#OMX_Sts_Err
+
+ExitOK             
+
+       M_END
+       ENDIF
+       END
+
+
+   
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_Inter_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_Inter_s.s
new file mode 100755
index 0000000..7208c21
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_Inter_s.s
@@ -0,0 +1,132 @@
+;/**
+; * 
+; * File Name:  omxVCM4P2_DecodeVLCZigzag_Inter_s.s
+; * OpenMAX DL: v1.0.2
+; * Revision:   12290
+; * Date:       Wednesday, April 9, 2008
+; * 
+; * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+; * 
+; * 
+; *
+; * Description: 
+; * Contains modules for zigzag scanning and VLC decoding
+; * for inter block.
+; *
+; *
+; *
+; * Function: omxVCM4P2_DecodeVLCZigzag_Inter
+; *
+; * Description:
+; * Performs VLC decoding and inverse zigzag scan for one inter coded block.
+; *
+; * Remarks:
+; *
+; * Parameters:
+; * [in]    ppBitStream        pointer to the pointer to the current byte in
+; *                    the bitstream buffer
+; * [in]    pBitOffset        pointer to the bit position in the byte pointed
+; *                    to by *ppBitStream. *pBitOffset is valid within    [0-7].
+; * [in] shortVideoHeader     binary flag indicating presence of short_video_header;
+; *                           escape modes 0-3 are used if shortVideoHeader==0,
+; *                           and escape mode 4 is used when shortVideoHeader==1.
+; * [out]    ppBitStream        *ppBitStream is updated after the block is
+; *                    decoded, so that it points to the current byte
+; *                    in the bit stream buffer
+; * [out]    pBitOffset        *pBitOffset is updated so that it points to the
+; *                    current bit position in the byte pointed by
+; *                    *ppBitStream
+; * [out]    pDst            pointer to the coefficient buffer of current
+; *                    block. Must be 16-byte aligned
+; *
+; * Return Value:
+; * OMX_Sts_BadArgErr - bad arguments
+; *   -At least one of the following pointers is NULL: ppBitStream, *ppBitStream, pBitOffset, pDst, or
+; *   -pDst is not 16-byte aligned, or
+; *   -*pBitOffset exceeds [0,7].
+; * OMX_Sts_Err - status error
+; *   -At least one mark bit is equal to zero
+; *   -Encountered an illegal stream code that cannot be found in the VLC table
+; *   -Encountered and illegal code in the VLC FLC table
+; *   -The number of coefficients is greater than 64
+; *
+; */
+
+
+      INCLUDE omxtypes_s.h
+      INCLUDE armCOMM_s.h
+      INCLUDE armCOMM_BitDec_s.h
+
+
+      M_VARIANTS ARM1136JS
+
+     
+
+
+
+     IF ARM1136JS
+     
+        ;// Import various tables needed for the function
+
+        
+        IMPORT          armVCM4P2_InterVlcL0L1             ;// Contains optimized and packed VLC Tables for both Last =1 and last=0
+                                                               ;// Packed in Run:Level:Last format
+        IMPORT          armVCM4P2_InterL0L1LMAX            ;// Contains LMAX table entries with both Last=0 and Last=1
+        IMPORT          armVCM4P2_InterL0L1RMAX            ;// Contains RMAX table entries with both Last=0 and Last=1
+        IMPORT          armVCM4P2_aClassicalZigzagScan     ;// contains classical Zigzag table entries with double the original values
+        IMPORT          armVCM4P2_DecodeVLCZigzag_AC_unsafe
+
+
+
+;//Input Arguments
+
+ppBitStream          RN 0
+pBitOffset           RN 1
+pDst                 RN 2
+shortVideoHeader     RN 3
+
+;//Local Variables
+
+Return               RN 0
+
+pVlcTableL0L1        RN 4
+pLMAXTableL0L1       RN 4
+pRMAXTableL0L1       RN 4
+pZigzagTable         RN 4
+Count                RN 6
+
+
+        
+        ;// Allocate stack memory to store the VLC,Zigzag,LMAX and RMAX tables
+     
+        
+        M_ALLOC4        ppVlcTableL0L1,4
+        M_ALLOC4        ppLMAXTableL0L1,4
+        M_ALLOC4        ppRMAXTableL0L1,4
+        M_ALLOC4        ppZigzagTable,4
+        
+        
+        M_START omxVCM4P2_DecodeVLCZigzag_Inter,r12
+
+        
+
+        
+        LDR             pZigzagTable, =armVCM4P2_aClassicalZigzagScan       ;// Load zigzag table
+        M_STR           pZigzagTable,ppZigzagTable                              ;// Store zigzag table on stack to pass as argument to unsafe function
+        LDR             pVlcTableL0L1, =armVCM4P2_InterVlcL0L1              ;// Load optimized VLC table with both L=0 and L=1 entries
+        M_STR           pVlcTableL0L1,ppVlcTableL0L1                            ;// Store optimized VLC table address on stack
+        LDR             pLMAXTableL0L1, =armVCM4P2_InterL0L1LMAX            ;// Load Interleaved L=0 and L=1 LMAX Tables
+        M_STR           pLMAXTableL0L1,ppLMAXTableL0L1                          ;// Store LMAX table address on stack
+        LDR             pRMAXTableL0L1, =armVCM4P2_InterL0L1RMAX            ;// Load Interleaved L=0 and L=1 RMAX Tables
+        MOV             Count,#0                                                ;// set start=0
+        M_STR           pRMAXTableL0L1,ppRMAXTableL0L1                          ;// store RMAX table address on stack
+                
+
+        BL              armVCM4P2_DecodeVLCZigzag_AC_unsafe                 ;// call Unsafe Function for VLC Zigzag Decoding
+         
+       
+
+        M_END
+        ENDIF
+        
+        END
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_IntraACVLC_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_IntraACVLC_s.s
new file mode 100755
index 0000000..9a37ec9
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_IntraACVLC_s.s
@@ -0,0 +1,136 @@
+;/**
+; * 
+; * File Name:  omxVCM4P2_DecodeVLCZigzag_IntraACVLC_s.s
+; * OpenMAX DL: v1.0.2
+; * Revision:   12290
+; * Date:       Wednesday, April 9, 2008
+; * 
+; * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+; * 
+; * 
+; *
+; * Description: 
+; * Contains modules for zigzag scanning and VLC decoding
+; * for inter block.
+; *
+; *
+; *
+; * Function: omxVCM4P2_DecodeVLCZigzag_Inter
+; *
+; * Description:
+; * Performs VLC decoding and inverse zigzag scan for one intra coded block.
+; *
+; * Remarks:
+; *
+; * Parameters:
+; * [in]    ppBitStream        pointer to the pointer to the current byte in
+; *                    the bitstream buffer
+; * [in]    pBitOffset        pointer to the bit position in the byte pointed
+; *                    to by *ppBitStream. *pBitOffset is valid within    [0-7].
+; * [in] shortVideoHeader     binary flag indicating presence of short_video_header;
+; *                           escape modes 0-3 are used if shortVideoHeader==0,
+; *                           and escape mode 4 is used when shortVideoHeader==1.
+; * [out]    ppBitStream        *ppBitStream is updated after the block is
+; *                    decoded, so that it points to the current byte
+; *                    in the bit stream buffer
+; * [out]    pBitOffset        *pBitOffset is updated so that it points to the
+; *                    current bit position in the byte pointed by
+; *                    *ppBitStream
+; * [out]    pDst            pointer to the coefficient buffer of current
+; *                    block. Must be 16-byte aligned
+; *
+; * Return Value:
+; * OMX_Sts_BadArgErr - bad arguments
+; *   -At least one of the following pointers is NULL: ppBitStream, *ppBitStream, pBitOffset, pDst, or
+; *   -pDst is not 16-byte aligned, or
+; *   -*pBitOffset exceeds [0,7].
+; * OMX_Sts_Err - status error
+; *   -At least one mark bit is equal to zero
+; *   -Encountered an illegal stream code that cannot be found in the VLC table
+; *   -Encountered and illegal code in the VLC FLC table
+; *   -The number of coefficients is greater than 64
+; *
+; */
+
+
+      INCLUDE omxtypes_s.h
+      INCLUDE armCOMM_s.h
+      INCLUDE armCOMM_BitDec_s.h
+
+
+      M_VARIANTS ARM1136JS
+
+     
+
+
+
+     IF ARM1136JS
+     
+        ;// Import various tables needed for the function
+
+        
+        IMPORT          armVCM4P2_IntraVlcL0L1             ;// Contains optimized and packed VLC Tables for both Last =1 and last=0
+                                                               ;// Packed in Run:Level:Last format
+        IMPORT          armVCM4P2_IntraL0L1LMAX            ;// Contains LMAX table entries with both Last=0 and Last=1
+        IMPORT          armVCM4P2_IntraL0L1RMAX            ;// Contains RMAX table entries with both Last=0 and Last=1
+        IMPORT          armVCM4P2_aClassicalZigzagScan     ;// contains classical Zigzag table entries with double the original values
+        IMPORT          armVCM4P2_DecodeVLCZigzag_AC_unsafe
+
+;//Input Arguments
+
+ppBitStream          RN 0
+pBitOffset           RN 1
+pDst                 RN 2
+PredDir              RN 3
+shortVideoHeader     RN 3
+
+;//Local Variables
+
+Return               RN 0
+
+pVlcTableL0L1        RN 4
+pLMAXTableL0L1       RN 4
+pRMAXTableL0L1       RN 4
+pZigzagTable         RN 4
+Count                RN 6
+
+
+        
+        ;// Allocate stack memory to store optimized VLC,Zigzag, RMAX, LMAX Table Addresses 
+     
+        M_ALLOC4        ppVlcTableL0L1,4
+        M_ALLOC4        ppLMAXTableL0L1,4
+        M_ALLOC4        ppRMAXTableL0L1,4
+        M_ALLOC4        ppZigzagTable,4
+
+        
+        M_START omxVCM4P2_DecodeVLCZigzag_IntraACVLC,r12
+
+        M_ARG           shortVideoHeaderonStack,4                             ;// pointer to Input Argument on stack           
+
+        LDR             pZigzagTable, =armVCM4P2_aClassicalZigzagScan     ;// Load Address of the Zigzag table    
+        ADD             pZigzagTable, pZigzagTable, PredDir, LSL #6           ;// Loading Different type of zigzag tables based on PredDir
+       
+        M_STR           pZigzagTable,ppZigzagTable                            ;// Store Zigzag table address on stack
+        LDR             pVlcTableL0L1, =armVCM4P2_IntraVlcL0L1            ;// Load optimized packed VLC Table with both L=0 and L=1 entries
+        M_STR           pVlcTableL0L1,ppVlcTableL0L1                          ;// Store VLC Table address on stack
+        LDR             pLMAXTableL0L1, =armVCM4P2_IntraL0L1LMAX          ;// Load LMAX Table
+        M_STR           pLMAXTableL0L1,ppLMAXTableL0L1                        ;// Store LMAX Table address on Stack
+        LDR             pRMAXTableL0L1, =armVCM4P2_IntraL0L1RMAX          ;// Load RMAX Table
+        MOV             Count,#0                                              ;// Set Start=0        
+        
+        M_STR           pRMAXTableL0L1,ppRMAXTableL0L1                        ;// Store RMAX Table address on stack
+              
+
+       
+        M_LDR           shortVideoHeader,shortVideoHeaderonStack              ;// get the Input Argument from stack
+
+        BL              armVCM4P2_DecodeVLCZigzag_AC_unsafe               ;// Call Unsafe Function
+
+
+
+        
+        M_END
+        ENDIF
+        
+        END
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_IntraDCVLC_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_IntraDCVLC_s.s
new file mode 100755
index 0000000..778aaf2
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_IntraDCVLC_s.s
@@ -0,0 +1,224 @@
+;/**
+; * 
+; * File Name:  omxVCM4P2_DecodeVLCZigzag_IntraDCVLC_s.s
+; * OpenMAX DL: v1.0.2
+; * Revision:   12290
+; * Date:       Wednesday, April 9, 2008
+; * 
+; * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+; * 
+; * 
+; *
+; * Description: 
+; * Contains modules for zigzag scanning and VLC decoding
+; * for inter block.
+; *
+; *
+; *
+; * Function: omxVCM4P2_DecodeVLCZigzag_Inter
+; *
+; * Description:
+; * Performs VLC decoding and inverse zigzag scan for one intra coded block.
+; *
+; * Remarks:
+; *
+; * Parameters:
+; * [in]    ppBitStream        pointer to the pointer to the current byte in
+; *                    the bitstream buffer
+; * [in]    pBitOffset        pointer to the bit position in the byte pointed
+; *                    to by *ppBitStream. *pBitOffset is valid within    [0-7].
+; * [in] shortVideoHeader     binary flag indicating presence of short_video_header;
+; *                           escape modes 0-3 are used if shortVideoHeader==0,
+; *                           and escape mode 4 is used when shortVideoHeader==1.
+; * [out]    ppBitStream        *ppBitStream is updated after the block is
+; *                    decoded, so that it points to the current byte
+; *                    in the bit stream buffer
+; * [out]    pBitOffset        *pBitOffset is updated so that it points to the
+; *                    current bit position in the byte pointed by
+; *                    *ppBitStream
+; * [out]    pDst            pointer to the coefficient buffer of current
+; *                    block. Must be 16-byte aligned
+; *
+; * Return Value:
+; * OMX_Sts_BadArgErr - bad arguments
+; *   -At least one of the following pointers is NULL: ppBitStream, *ppBitStream, pBitOffset, pDst, or
+; *   -pDst is not 16-byte aligned, or
+; *   -*pBitOffset exceeds [0,7].
+; * OMX_Sts_Err - status error
+; *   -At least one mark bit is equal to zero
+; *   -Encountered an illegal stream code that cannot be found in the VLC table
+; *   -Encountered and illegal code in the VLC FLC table
+; *   -The number of coefficients is greater than 64
+; *
+; */
+
+
+      INCLUDE omxtypes_s.h
+      INCLUDE armCOMM_s.h
+      INCLUDE armCOMM_BitDec_s.h
+
+
+      M_VARIANTS CortexA8
+
+     
+      
+
+
+      IF CortexA8
+
+     
+        ;// Import various tables needed for the function
+
+        
+        IMPORT          armVCM4P2_IntraVlcL0L1             ;// Contains optimized and packed VLC Tables for both Last =1 and last=0
+                                                               ;// Packed in Run:Level:Last format
+        IMPORT          armVCM4P2_IntraL0L1LMAX            ;// Contains LMAX table entries with both Last=0 and Last=1
+        IMPORT          armVCM4P2_IntraL0L1RMAX            ;// Contains RMAX table entries with both Last=0 and Last=1
+        IMPORT          armVCM4P2_aClassicalZigzagScan     ;// contains CLassical, Horizontal, Vertical Zigzag table entries with double the original values
+        IMPORT          armVCM4P2_aIntraDCLumaChromaIndex  ;// Contains Optimized DCLuma and DCChroma Index table Entries
+        
+
+        IMPORT          armVCM4P2_DecodeVLCZigzag_AC_unsafe
+
+;//Input Arguments
+
+ppBitStream          RN 0
+pBitOffset           RN 1
+pDst                 RN 2
+PredDir              RN 3
+shortVideoHeader     RN 3
+videoComp            RN 5
+;//Local Variables
+
+Return               RN 0
+
+pDCLumaChromaIndex   RN 4
+pDCChromaIndex       RN 7
+pVlcTableL0L1        RN 4
+pLMAXTableL0L1       RN 4
+pRMAXTableL0L1       RN 4
+pZigzagTable         RN 4
+Count                RN 6
+DCValueSize          RN 6
+powOfSize            RN 7
+temp1                RN 5
+
+
+;// Scratch Registers
+
+RBitStream           RN 8
+RBitBuffer           RN 9
+RBitCount            RN 10
+
+T1                   RN 11
+T2                   RN 12
+DCVal                RN 14
+
+        
+        ;// Allocate stack memory to store optimized VLC,Zigzag, RMAX, LMAX Table Addresses 
+     
+        M_ALLOC4        ppVlcTableL0L1,4
+        M_ALLOC4        ppLMAXTableL0L1,4
+        M_ALLOC4        ppRMAXTableL0L1,4
+        M_ALLOC4        ppZigzagTable,4
+        M_ALLOC4        pDCCoeff,4
+        
+
+        
+        M_START omxVCM4P2_DecodeVLCZigzag_IntraDCVLC,r12
+
+        M_ARG           shortVideoHeaderonStack,4                                  ;// Pointer to argument on stack  
+        M_ARG           videoComponstack,4                                         ;// Pointer to argument on stack
+
+        
+        ;// Decode DC Coefficient
+
+        
+        LDR             pDCLumaChromaIndex, =armVCM4P2_aIntraDCLumaChromaIndex ;// Load Optimized VLC Table for Luminance and Chrominance
+
+        ;// Initializing the Bitstream Macro
+
+        M_BD_INIT0      ppBitStream, pBitOffset, RBitStream, RBitBuffer, RBitCount
+        M_LDR           videoComp,videoComponstack                                 
+        M_BD_INIT1      T1, T2, T2
+        ADD             pDCLumaChromaIndex,pDCLumaChromaIndex,videoComp, LSL #6             
+        M_BD_INIT2      T1, T2, T2
+    
+        
+        M_BD_VLD        DCValueSize,T1,T2,pDCLumaChromaIndex,4,2                    ;// VLC Decode using optimized Luminance and Chrominance VLC Table
+
+    
+       
+
+DecodeDC
+                         
+        CMP             DCValueSize,#12     
+        BGT             ExitError
+        
+        CMP             DCValueSize,#0
+        MOVEQ           DCVal,#0                                                    ;// If DCValueSize is zero then DC coeff =0
+        BEQ             ACDecode                                                    ;// Branch to perform AC Coeff Decoding
+        
+        M_BD_VREAD16    DCVal,DCValueSize,T1,T2                                     ;// Get DC Value From Bit stream
+         
+
+        MOV             powOfSize,#1                                                
+        LSL             powOfSize,DCValueSize                                       ;// powOfSize=pow(2,DCValueSize)
+        CMP             DCVal,powOfSize,LSR #1                                      ;// Compare DCVal with powOfSize/2 
+        ADDLT           DCVal,DCVal,#1
+        SUBLT           DCVal,DCVal,powOfSize                                       ;// If Lessthan powOfSize/2 DCVal=DCVal-powOfSize+1
+                                                                                    ;// Else DCVal= fetchbits from bit stream
+
+CheckDCValueSize
+        
+        CMP             DCValueSize,#8                                              ;// If DCValueSize greater than 8 check marker bit
+
+        BLE             ACDecode
+
+        M_BD_READ8      temp1,1,T1
+        TEQ             temp1,#0                                                    ;// If Marker bit is zero Exit with an Error Message
+        BEQ             ExitError
+
+        
+
+        ;// Decode AC Coefficient
+
+ACDecode
+
+        M_STR           DCVal,pDCCoeff                                             ;// Store Decoded DC Coeff on Stack
+        M_BD_FINI       ppBitStream,pBitOffset                                     ;// Terminating the Bit stream Macro
+         
+        LDR             pZigzagTable, =armVCM4P2_aClassicalZigzagScan          ;// Load Zigzag talbe address   
+        ADD             pZigzagTable, pZigzagTable, PredDir, LSL #6                ;// Modify the Zigzag table adress based on PredDir                
+       
+        M_STR           pZigzagTable,ppZigzagTable                                 ;// Store zigzag table on stack
+        LDR             pVlcTableL0L1, =armVCM4P2_IntraVlcL0L1                 ;// Load Optimized VLC Table With both Last=0 and Last=1 Entries
+        M_STR           pVlcTableL0L1,ppVlcTableL0L1                               ;// Store Optimized VLC Table on stack
+        LDR             pLMAXTableL0L1, =armVCM4P2_IntraL0L1LMAX               ;// Load LMAX Table
+        M_STR           pLMAXTableL0L1,ppLMAXTableL0L1                             ;// Store LMAX table on stack
+        LDR             pRMAXTableL0L1, =armVCM4P2_IntraL0L1RMAX               ;// Load RMAX Table
+        MOV             Count,#1                                                   ;// Set Start =1        
+        
+        M_STR           pRMAXTableL0L1,ppRMAXTableL0L1                             ;// Store RMAX Table on Stack
+        
+       
+        M_LDR           shortVideoHeader,shortVideoHeaderonStack                   ;// Load the Input Argument From Stack
+        
+        BL              armVCM4P2_DecodeVLCZigzag_AC_unsafe                    ;// Call the Unsafe Function
+
+        M_LDR           DCVal,pDCCoeff                                             ;// Get the Decoded DC Value From Stack
+        STRH            DCVal,[pDst]                                               ;// Store the DC Value 
+        B               ExitOK
+        
+              
+
+ExitError
+ 
+        M_BD_FINI       ppBitStream,pBitOffset                                     ;// Terminating the Bit Stream Macro in case of an Error
+        MOV             Return,#OMX_Sts_Err                                        ;// Exit with an Error Message 
+ExitOK
+      
+        M_END
+        ENDIF
+        
+        END
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/omxVCM4P2_FindMVpred_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/omxVCM4P2_FindMVpred_s.s
new file mode 100755
index 0000000..caf7121
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/omxVCM4P2_FindMVpred_s.s
@@ -0,0 +1,194 @@
+;//
+;// 
+;// File Name:  omxVCM4P2_FindMVpred_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   12290
+;// Date:       Wednesday, April 9, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+;// Function:
+;//     omxVCM4P2_FindMVpred
+;//
+        ;// Include headers
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+        INCLUDE armVCCOMM_s.h
+
+        ;// Define cpu variants
+        M_VARIANTS CortexA8
+        
+        
+        IF CortexA8
+        
+        M_TABLE armVCM4P2_pBlkIndexTable
+        DCD  OMXVCBlk0, OMXVCBlk1
+        DCD  OMXVCBlk2, OMXVCBlk3
+
+;//--------------------------------------------
+;// Declare input registers
+;//--------------------------------------------
+        
+pSrcMVCurMB            RN 0
+pSrcCandMV1            RN 1
+pSrcCandMV2            RN 2
+pSrcCandMV3            RN 3
+pDstMVPred             RN 4
+pDstMVPredME           RN 5
+iBlk                   RN 6
+
+pTable                 RN 4
+CandMV                 RN 12
+
+pCandMV1               RN 7
+pCandMV2               RN 8
+pCandMV3               RN 9
+
+CandMV1dx              RN 0 
+CandMV1dy              RN 1 
+CandMV2dx              RN 2
+CandMV2dy              RN 3
+CandMV3dx              RN 10
+CandMV3dy              RN 11
+
+temp                   RN 14
+
+zero                   RN 14
+return                 RN 0
+        
+; ----------------------------------------------
+; Main routine
+; ----------------------------------------------        
+
+        M_ALLOC4 MV, 4
+        
+        ;// Function header 
+        M_START omxVCM4P2_FindMVpred, r11
+        
+        ;// Define stack arguments
+        M_ARG   ppDstMVPred,  4
+        M_ARG   ppDstMVPredME, 4
+        M_ARG   Blk, 4
+        
+        M_ADR CandMV, MV
+        MOV   zero, #0
+        M_LDR iBlk, Blk
+        
+        ;// Set the default value for these
+        ;// to be used if pSrcCandMV[1|2|3] == NULL
+        MOV   pCandMV1, CandMV
+        MOV   pCandMV2, CandMV
+        MOV   pCandMV3, CandMV
+    
+        STR   zero, [CandMV]
+
+        ;// Branch to the case based on blk number
+        M_SWITCH iBlk
+        M_CASE   OMXVCBlk0      ;// iBlk=0
+        M_CASE   OMXVCBlk1      ;// iBlk=0
+        M_CASE   OMXVCBlk2      ;// iBlk=0
+        M_CASE   OMXVCBlk3      ;// iBlk=0
+        M_ENDSWITCH
+        
+OMXVCBlk0
+        CMP   pSrcCandMV1, #0
+        ADDNE pCandMV1, pSrcCandMV1, #4
+        
+        CMP   pSrcCandMV2, #0
+        ADDNE pCandMV2, pSrcCandMV2, #8
+
+        CMP   pSrcCandMV3, #0
+        ADDNE pCandMV3, pSrcCandMV3, #8
+        CMPEQ pSrcCandMV1, #0
+    
+        MOVEQ pCandMV3, pCandMV2
+        MOVEQ pCandMV1, pCandMV2
+                
+        CMP   pSrcCandMV1, #0
+        CMPEQ pSrcCandMV2, #0
+    
+        MOVEQ pCandMV1, pCandMV3
+        MOVEQ pCandMV2, pCandMV3
+        
+        CMP   pSrcCandMV2, #0
+        CMPEQ pSrcCandMV3, #0
+    
+        MOVEQ pCandMV2, pCandMV1
+        MOVEQ pCandMV3, pCandMV1
+        
+        B     BlkEnd
+    
+OMXVCBlk1
+        MOV   pCandMV1, pSrcMVCurMB
+        CMP   pSrcCandMV3, #0
+        ADDNE pCandMV3, pSrcCandMV3, #8
+        
+        CMP   pSrcCandMV2, #0
+        ADDNE pCandMV2, pSrcCandMV2, #12
+    
+        CMPEQ pSrcCandMV3, #0
+    
+        MOVEQ pCandMV2, pCandMV1
+        MOVEQ pCandMV3, pCandMV1
+            
+        B     BlkEnd
+
+OMXVCBlk2
+        CMP   pSrcCandMV1, #0
+        MOV   pCandMV2, pSrcMVCurMB
+        ADD   pCandMV3, pSrcMVCurMB, #4
+        ADDNE pCandMV1, pSrcCandMV1, #12
+        B     BlkEnd
+
+OMXVCBlk3
+        ADD   pCandMV1, pSrcMVCurMB, #8
+        MOV   pCandMV2, pSrcMVCurMB
+        ADD   pCandMV3, pSrcMVCurMB, #4
+    
+BlkEnd
+
+        ;// Using the transperancy info, zero
+        ;// out the candidate MV if neccesary
+        LDRSH CandMV1dx, [pCandMV1], #2
+        LDRSH CandMV2dx, [pCandMV2], #2
+        LDRSH CandMV3dx, [pCandMV3], #2
+    
+        ;// Load argument from the stack
+        M_LDR pDstMVPredME, ppDstMVPredME
+
+        LDRSH CandMV1dy, [pCandMV1]
+        LDRSH CandMV2dy, [pCandMV2]
+        LDRSH CandMV3dy, [pCandMV3]
+
+        CMP pDstMVPredME, #0        
+
+        ;// Store the candidate MV's into the pDstMVPredME, 
+        ;// these can be used in the fast algorithm if implemented 
+
+        STRHNE CandMV1dx, [pDstMVPredME], #2
+        STRHNE CandMV1dy, [pDstMVPredME], #2        
+        STRHNE CandMV2dx, [pDstMVPredME], #2
+        STRHNE CandMV2dy, [pDstMVPredME], #2
+        STRHNE CandMV3dx, [pDstMVPredME], #2
+        STRHNE CandMV3dy, [pDstMVPredME]
+           
+        ; Find the median of the 3 candidate MV's
+        M_MEDIAN3 CandMV1dx, CandMV2dx, CandMV3dx, temp
+
+        ;// Load argument from the stack
+        M_LDR pDstMVPred, ppDstMVPred
+
+        M_MEDIAN3 CandMV1dy, CandMV2dy, CandMV3dy, temp
+    
+        STRH CandMV3dx, [pDstMVPred], #2
+        STRH CandMV3dy, [pDstMVPred]
+
+        MOV return, #OMX_Sts_NoErr
+    
+        M_END
+    ENDIF ;// ARM1136JS :LOR: CortexA8
+    
+    END
\ No newline at end of file
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/omxVCM4P2_IDCT8x8blk_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/omxVCM4P2_IDCT8x8blk_s.s
new file mode 100755
index 0000000..b5e3d0d
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/omxVCM4P2_IDCT8x8blk_s.s
@@ -0,0 +1,73 @@
+;//
+;// 
+;// File Name:  omxVCM4P2_IDCT8x8blk_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   12290
+;// Date:       Wednesday, April 9, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+
+;// Function:
+;//     omxVCM4P2_IDCT8x8blk
+;//
+        ;// Include headers
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+
+        ;// Define cpu variants
+        M_VARIANTS CortexA8
+
+        INCLUDE armCOMM_IDCT_s.h        
+        
+        IMPORT armCOMM_IDCTPreScale
+        ;//
+        ;// Function prototype
+        ;//
+        ;//     OMXResult
+        ;//     omxVCM4P2_IDCT8x8blk(const OMX_S16* pSrc,
+        ;//                                       OMX_S16* pDst)
+        ;//    
+        
+    IF CortexA8
+        M_ALLOC4  ppDest, 4
+        M_ALLOC4  pStride, 4
+        M_ALLOC8  pBlk, 2*8*8
+    ENDIF
+    
+    
+    IF CortexA8
+        M_START omxVCM4P2_IDCT8x8blk, r11, d15
+    ENDIF
+        
+    IF CortexA8
+        
+;// Declare input registers
+pSrc            RN 0
+pDst            RN 1
+
+;// Declare other intermediate registers
+Result          RN 0
+
+;// Prototype for macro M_IDCT
+;// pSrc            RN 0  ;// source data buffer
+;// Stride          RN 1  ;// destination stride in bytes
+;// pDest           RN 2  ;// destination data buffer
+;// pScale          RN 3  ;// pointer to scaling table
+
+pSrc    RN 0    
+Stride  RN 1    
+pDest   RN 2    
+pScale  RN 3    
+                
+        MOV         pDest, pDst
+        LDR         pScale, =armCOMM_IDCTPreScale        
+        M_IDCT      s9, s16, 16      
+        MOV         Result, #OMX_Sts_NoErr
+        M_END       
+    ENDIF  
+        ;// ARM1136JS :LOR: CortexA8
+
+    END
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/omxVCM4P2_MCReconBlock_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/omxVCM4P2_MCReconBlock_s.s
new file mode 100755
index 0000000..dd00df5
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/omxVCM4P2_MCReconBlock_s.s
@@ -0,0 +1,444 @@
+;//
+;// 
+;// File Name:  omxVCM4P2_MCReconBlock_s.s
+;// OpenMAX DL: v1.0.2
+;// Revision:   12290
+;// Date:       Wednesday, April 9, 2008
+;// 
+;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+;// 
+;// 
+;//
+;// Description:
+;//
+;//
+
+;// Include standard headers
+    INCLUDE omxtypes_s.h
+    INCLUDE armCOMM_s.h
+
+;// Import symbols required from other files
+
+    M_VARIANTS CortexA8
+
+;// ***************************************************************************
+;// ARM1136JS implementation
+;// ***************************************************************************
+
+;// ***************************************************************************
+;// CortexA8 implementation
+;// ***************************************************************************
+    IF  CortexA8
+;// ***************************************************************************
+;// MACRO DEFINITIONS
+;// ***************************************************************************
+    ;// Description:
+    ;// Does interpolation for the case of "IntegerPixel" predictType. Both 
+    ;// rounding cases are handled. Just copies a block from pSrc to pDst
+    ;//
+    ;// Syntax:
+    ;// M_MCRECONBLOCK_IntegerPixel
+    ;// 
+    ;// Inputs: None
+    ;// Outputs: None
+
+    MACRO 
+    M_MCRECONBLOCK_IntegerPixel
+CaseIntegerPixel_Rnd0
+CaseIntegerPixel_Rnd1
+
+    VLD1        dRow0, [pSrc], srcStep
+    VLD1        dRow1, [pSrc], srcStep
+    VLD1        dRow2, [pSrc], srcStep
+    VLD1        dRow3, [pSrc], srcStep
+    VLD1        dRow4, [pSrc], srcStep
+    VLD1        dRow5, [pSrc], srcStep
+    VLD1        dRow6, [pSrc], srcStep
+    VLD1        dRow7, [pSrc], srcStep
+
+    VST1        dRow0, [pDst@64], dstStep
+    VST1        dRow1, [pDst@64], dstStep
+    VST1        dRow2, [pDst@64], dstStep
+    VST1        dRow3, [pDst@64], dstStep
+    VST1        dRow4, [pDst@64], dstStep
+    VST1        dRow5, [pDst@64], dstStep
+    VST1        dRow6, [pDst@64], dstStep
+    VST1        dRow7, [pDst@64], dstStep
+
+    B           SwitchPredictTypeEnd
+    MEND
+;// ***************************************************************************
+    ;// Description:
+    ;// Does interpolation for the case of "HalfPixelX" predictType. The two 
+    ;// rounding cases are handled by the parameter "$rndVal". Averages between
+    ;// a pixel and pixel right to it, rounding it based on $rndVal. The 
+    ;// rounding is implemented by using opCode switching between "VRHADD" and 
+    ;// "VHADD" instructions.
+    ;//
+    ;// Syntax:
+    ;// M_MCRECONBLOCK_HalfPixelX $rndVal
+    ;// 
+    ;// Inputs: 
+    ;//     $rndVal: 0 for rounding and 1 for no rounding
+    ;// Outputs: None
+
+    MACRO 
+    M_MCRECONBLOCK_HalfPixelX $rndVal
+
+    LCLS M_VHADDR
+    IF $rndVal = 0
+M_VHADDR SETS "VRHADD"
+    ELSE
+M_VHADDR SETS "VHADD"
+    ENDIF
+
+CaseHalfPixelX_Rnd$rndVal
+
+    VLD1        {dRow0, dRow0Shft}, [pSrc], srcStep
+    VEXT        dRow0Shft, dRow0, dRow0Shft, #1
+    VLD1        {dRow1, dRow1Shft}, [pSrc], srcStep
+    VEXT        dRow1Shft, dRow1, dRow1Shft, #1
+    VLD1        {dRow2, dRow2Shft}, [pSrc], srcStep
+    VEXT        dRow2Shft, dRow2, dRow2Shft, #1
+    VLD1        {dRow3, dRow3Shft}, [pSrc], srcStep
+    VEXT        dRow3Shft, dRow3, dRow3Shft, #1
+    VLD1        {dRow4, dRow4Shft}, [pSrc], srcStep
+    VEXT        dRow4Shft, dRow4, dRow4Shft, #1
+    VLD1        {dRow5, dRow5Shft}, [pSrc], srcStep
+    VEXT        dRow5Shft, dRow5, dRow5Shft, #1
+    VLD1        {dRow6, dRow6Shft}, [pSrc], srcStep
+    VEXT        dRow6Shft, dRow6, dRow6Shft, #1
+    VLD1        {dRow7, dRow7Shft}, [pSrc], srcStep
+    VEXT        dRow7Shft, dRow7, dRow7Shft, #1
+    $M_VHADDR   dRow0, dRow0, dRow0Shft
+    $M_VHADDR   dRow1, dRow1, dRow1Shft
+    VST1        dRow0, [pDst@64], dstStep
+    $M_VHADDR   dRow2, dRow2, dRow2Shft
+    VST1        dRow1, [pDst@64], dstStep
+    $M_VHADDR   dRow3, dRow3, dRow3Shft
+    VST1        dRow2, [pDst@64], dstStep
+    $M_VHADDR   dRow4, dRow4, dRow4Shft
+    VST1        dRow3, [pDst@64], dstStep
+    $M_VHADDR   dRow5, dRow5, dRow5Shft
+    VST1        dRow4, [pDst@64], dstStep
+    $M_VHADDR   dRow6, dRow6, dRow6Shft
+    VST1        dRow5, [pDst@64], dstStep
+    $M_VHADDR   dRow7, dRow7, dRow7Shft
+    VST1        dRow6, [pDst@64], dstStep
+    VST1        dRow7, [pDst@64], dstStep
+    
+    B           SwitchPredictTypeEnd
+    MEND
+;// ***************************************************************************
+    ;// Description:
+    ;// Does interpolation for the case of "HalfPixelY" predictType. The two 
+    ;// rounding cases are handled by the parameter "$rndVal". Averages between
+    ;// a pixel and pixel below it, rounding it based on $rndVal. The 
+    ;// rounding is implemented by using opCode switching between "VRHADD" and 
+    ;// "VHADD" instructions.
+    ;//
+    ;// Syntax:
+    ;// M_MCRECONBLOCK_HalfPixelY $rndVal
+    ;// 
+    ;// Inputs: 
+    ;//     $rndVal: 0 for rounding and 1 for no rounding
+    ;// Outputs: None
+
+    MACRO 
+    M_MCRECONBLOCK_HalfPixelY $rndVal
+
+    LCLS M_VHADDR
+    IF $rndVal = 0
+M_VHADDR SETS "VRHADD"
+    ELSE
+M_VHADDR SETS "VHADD"
+    ENDIF
+
+CaseHalfPixelY_Rnd$rndVal
+    VLD1        dRow0, [pSrc], srcStep
+    VLD1        dRow1, [pSrc], srcStep
+    VLD1        dRow2, [pSrc], srcStep
+    VLD1        dRow3, [pSrc], srcStep
+    VLD1        dRow4, [pSrc], srcStep
+    VLD1        dRow5, [pSrc], srcStep
+    VLD1        dRow6, [pSrc], srcStep
+    VLD1        dRow7, [pSrc], srcStep
+    $M_VHADDR   dRow0, dRow0, dRow1
+    VLD1        dRow8, [pSrc], srcStep
+    $M_VHADDR   dRow1, dRow1, dRow2
+    VST1        dRow0, [pDst@64], dstStep
+    $M_VHADDR   dRow2, dRow2, dRow3
+    VST1        dRow1, [pDst@64], dstStep
+    $M_VHADDR   dRow3, dRow3, dRow4
+    VST1        dRow2, [pDst@64], dstStep
+    $M_VHADDR   dRow4, dRow4, dRow5
+    VST1        dRow3, [pDst@64], dstStep
+    $M_VHADDR   dRow5, dRow5, dRow6
+    VST1        dRow4, [pDst@64], dstStep
+    $M_VHADDR   dRow6, dRow6, dRow7
+    VST1        dRow5, [pDst@64], dstStep
+    $M_VHADDR   dRow7, dRow7, dRow8
+    VST1        dRow6, [pDst@64], dstStep
+    VST1        dRow7, [pDst@64], dstStep
+
+    B           SwitchPredictTypeEnd
+    MEND
+;// ***************************************************************************
+    ;// Description:
+    ;// Does interpolation for the case of "IntegerPixel" predictType. Both 
+    ;// rounding cases are handled. 
+    ;// Typical computation for a row goes like this
+    ;//     1. VLD1        {dRow0, dRow0Shft}, [pSrc], srcStep ;// Load the row and next 8 bytes
+    ;//     2. VEXT        dRow0Shft, dRow0, dRow0Shft, #1     ;// Generate the shifted row
+    ;//     3. VADDL       qSum0, dRow0, dRow0Shft             ;// Generate the sum of row and shifted row
+    ;//     5. VADD        qSum0, qSum0, qSum1                 ;// Add to the sum of next row (odd row sum has rounding value added to it)
+    ;//     6. VSHRN       dRow0, qSum0, #2                    ;// Divide by 4
+    ;//     7. VST1        dRow0, [pDst@64], dstStep           ;// Store
+    ;// Odd rows undergo following computation after step 3
+    ;//     4. VADD        qSum1, qSum1, qRound
+    ;// This saves for adding rounding value to each final sum (overall saves 4 
+    ;// instructions).
+    ;// There is reuse of registers for qSum6, qSum7 & qSum8. Overall scheduling takes 
+    ;// care of this and also minimizes stalls. Rounding value was modified in 
+    ;// ARM register rndVal (originally used for rounding flag) before the switch.
+    ;// It is then populated into all lanes in this macro. No branching out to 
+    ;// label "SwitchPredictTypeEnd" is required in the end of the macro as these 
+    ;// are the last of switch cases.
+    ;// 
+    ;// Syntax:
+    ;// M_MCRECONBLOCK_HalfPixelXY
+    ;// 
+    ;// Inputs: None
+    ;// Outputs: None
+
+    MACRO 
+    M_MCRECONBLOCK_HalfPixelXY
+
+CaseHalfPixelXY_Rnd0
+CaseHalfPixelXY_Rnd1
+    VLD1        {dRow0, dRow0Shft}, [pSrc], srcStep
+    VDUP        qRound, rndVal
+    VLD1        {dRow1, dRow1Shft}, [pSrc], srcStep
+    VEXT        dRow0Shft, dRow0, dRow0Shft, #1
+    VLD1        {dRow2, dRow2Shft}, [pSrc], srcStep
+    VEXT        dRow1Shft, dRow1, dRow1Shft, #1
+    VLD1        {dRow3, dRow3Shft}, [pSrc], srcStep
+    VEXT        dRow2Shft, dRow2, dRow2Shft, #1
+    VLD1        {dRow4, dRow4Shft}, [pSrc], srcStep
+    VADDL       qSum0, dRow0, dRow0Shft
+    VLD1        {dRow5, dRow5Shft}, [pSrc], srcStep
+    VADDL       qSum1, dRow1, dRow1Shft
+    VLD1        {dRow6, dRow6Shft}, [pSrc], srcStep
+    VEXT        dRow3Shft, dRow3, dRow3Shft, #1
+    VLD1        {dRow7, dRow7Shft}, [pSrc], srcStep
+    VEXT        dRow4Shft, dRow4, dRow4Shft, #1
+    VLD1        {dRow8, dRow8Shft}, [pSrc], srcStep
+    VADD        qSum1, qSum1, qRound
+    VADDL       qSum2, dRow2, dRow2Shft
+    VEXT        dRow5Shft, dRow5, dRow5Shft, #1
+    VADD        qSum0, qSum0, qSum1
+    VADDL       qSum3, dRow3, dRow3Shft
+    VEXT        dRow6Shft, dRow6, dRow6Shft, #1
+    VADD        qSum1, qSum1, qSum2
+    VSHRN       dRow0, qSum0, #2
+    VADDL       qSum4, dRow4, dRow4Shft
+    VSHRN       dRow1, qSum1, #2
+    VADD        qSum3, qSum3, qRound
+    VADDL       qSum5, dRow5, dRow5Shft
+    VST1        dRow0, [pDst@64], dstStep
+    VEXT        dRow7Shft, dRow7, dRow7Shft, #1
+    VST1        dRow1, [pDst@64], dstStep
+    VEXT        dRow8Shft, dRow8, dRow8Shft, #1
+    VADD        qSum5, qSum5, qRound
+    VADD        qSum2, qSum2, qSum3
+    VADD        qSum3, qSum3, qSum4
+    VADD        qSum4, qSum4, qSum5
+    VSHRN       dRow2, qSum2, #2
+    VSHRN       dRow3, qSum3, #2
+    VSHRN       dRow4, qSum4, #2
+    VADDL       qSum6, dRow6, dRow6Shft
+    VADDL       qSum7, dRow7, dRow7Shft
+    VST1        dRow2, [pDst@64], dstStep
+    VADDL       qSum8, dRow8, dRow8Shft
+    VADD        qSum7, qSum7, qRound
+    VST1        dRow3, [pDst@64], dstStep
+    VST1        dRow4, [pDst@64], dstStep
+    VADD        qSum5, qSum5, qSum6
+    VADD        qSum6, qSum6, qSum7
+    VADD        qSum7, qSum7, qSum8
+    VSHRN       dRow5, qSum5, #2
+    VSHRN       dRow6, qSum6, #2
+    VSHRN       dRow7, qSum7, #2
+    VST1        dRow5, [pDst@64], dstStep
+    VST1        dRow6, [pDst@64], dstStep
+    VST1        dRow7, [pDst@64], dstStep
+
+    MEND
+;// ***************************************************************************
+
+;// Input/Output Registers
+pSrc                  RN 0
+srcStep               RN 1
+pSrcResidue           RN 2
+pDst                  RN 3
+dstStep               RN 4
+predictType           RN 5
+rndVal                RN 6
+
+;// Local Scratch Registers
+pDstCopy              RN 0
+return                RN 0
+
+;// Neon Registers
+dRow0                 DN D0.U8
+dRow0Shft             DN D1.U8
+dRow1                 DN D2.U8
+dRow1Shft             DN D3.U8
+dRow2                 DN D4.U8
+dRow2Shft             DN D5.U8
+dRow3                 DN D6.U8
+dRow3Shft             DN D7.U8
+dRow4                 DN D8.U8
+dRow4Shft             DN D9.U8
+dRow5                 DN D10.U8
+dRow5Shft             DN D11.U8
+dRow6                 DN D12.U8
+dRow6Shft             DN D13.U8
+dRow7                 DN D14.U8
+dRow7Shft             DN D15.U8
+dRow8                 DN D16.U8
+dRow8Shft             DN D17.U8
+
+
+qSum0                 QN Q9.U16
+qSum1                 QN Q10.U16
+qSum2                 QN Q11.U16
+qSum3                 QN Q12.U16
+qSum4                 QN Q13.U16
+qSum5                 QN Q14.U16
+qSum6                 QN Q0.U16
+qSum7                 QN Q1.U16
+qSum8                 QN Q2.U16
+
+qRound                QN Q15.U16
+
+dDst0                 DN D0.U8
+dDst1                 DN D1.U8
+dDst2                 DN D2.U8
+dDst3                 DN D3.U8
+dDst4                 DN D4.U8
+dDst5                 DN D5.U8
+dDst6                 DN D6.U8
+dDst7                 DN D7.U8
+
+qRes0                 QN Q4.S16
+qRes1                 QN Q5.S16
+qRes2                 QN Q6.S16
+qRes3                 QN Q7.S16
+qRes4                 QN Q8.S16
+qRes5                 QN Q9.S16
+qRes6                 QN Q10.S16
+qRes7                 QN Q11.S16
+
+    ;// Function header
+    M_START     omxVCM4P2_MCReconBlock, r6, d15
+    ;// Define stack arguments
+    M_ARG       Arg_dstStep,        4
+    M_ARG       Arg_predictType,    4
+    M_ARG       Arg_rndVal,         4
+    ;// Load argument from the stack
+    M_LDR       dstStep, Arg_dstStep
+    M_LDR       predictType, Arg_predictType
+    M_LDR       rndVal, Arg_rndVal
+    ADD         predictType, rndVal, predictType, LSL #1
+    RSB         rndVal, rndVal, #2              ;// preparing rndVal for HalfPixelXY
+    
+    ;// The following is implementation of switching to different code segments
+    ;// based on different predictType and rndVal flags. The corresponding 
+    ;// labels (e.g. CaseIntegerPixel_Rnd0) are embedded in the macros following
+    ;// M_ENDSWITCH (e.g. M_MCRECONBLOCK_IntegerPixel). While "M_MCRECONBLOCK_IntegerPixel" 
+    ;// and "M_MCRECONBLOCK_HalfPixelXY" handle for both rounding cases; 
+    ;// "M_MCRECONBLOCK_HalfPixelX" and "M_MCRECONBLOCK_HalfPixelY" macros handle 
+    ;// the two rounding cases in separate code bases.
+    ;// All these together implement the interpolation functionality
+    
+    M_SWITCH    predictType
+        M_CASE      CaseIntegerPixel_Rnd0
+        M_CASE      CaseIntegerPixel_Rnd1
+        M_CASE      CaseHalfPixelX_Rnd0
+        M_CASE      CaseHalfPixelX_Rnd1
+        M_CASE      CaseHalfPixelY_Rnd0
+        M_CASE      CaseHalfPixelY_Rnd1
+        M_CASE      CaseHalfPixelXY_Rnd0
+        M_CASE      CaseHalfPixelXY_Rnd1
+    M_ENDSWITCH
+
+    M_MCRECONBLOCK_IntegerPixel
+    M_MCRECONBLOCK_HalfPixelX 0
+    M_MCRECONBLOCK_HalfPixelX 1
+    M_MCRECONBLOCK_HalfPixelY 0
+    M_MCRECONBLOCK_HalfPixelY 1
+    M_MCRECONBLOCK_HalfPixelXY
+SwitchPredictTypeEnd
+
+    ;// After interpolation is done, residue needs to be added. This is done 
+    ;// only in case "pSrcResidue" parameter to the function is not NULL.
+    ;// Following is a completely unrolled code to do so. Each row and 
+    ;// corresponding residue is loaded and residue is added and value 
+    ;// stored
+    
+    CMP         pSrcResidue, #0
+    SUBNE       pDst, pDst, dstStep, LSL #3     ;// Restoring pDst
+    MOVNE       pDstCopy, pDst
+    BEQ         pSrcResidueConditionEnd
+pSrcResidueNotNull    
+    VLD1        dDst0, [pDst@64], dstStep
+    VLD1        qRes0, [pSrcResidue@128]!
+    VLD1        dDst1, [pDst@64], dstStep
+    VLD1        qRes1, [pSrcResidue@128]!
+    VLD1        dDst2, [pDst@64], dstStep
+    VLD1        qRes2, [pSrcResidue@128]!
+    VADDW       qRes0, qRes0, dDst0
+    VLD1        dDst3, [pDst@64], dstStep
+    VADDW       qRes1, qRes1, dDst1
+    VLD1        qRes3, [pSrcResidue@128]!
+    VADDW       qRes2, qRes2, dDst2
+    VLD1        dDst4, [pDst@64], dstStep
+    VQMOVUN     dDst0, qRes0
+    VLD1        qRes4, [pSrcResidue@128]!
+    VADDW       qRes3, qRes3, dDst3
+    VLD1        dDst5, [pDst@64], dstStep
+    VQMOVUN     dDst1, qRes1
+    VLD1        qRes5, [pSrcResidue@128]!
+    VADDW       qRes4, qRes4, dDst4
+    VLD1        dDst6, [pDst@64], dstStep
+    VQMOVUN     dDst2, qRes2
+    VLD1        qRes6, [pSrcResidue@128]!
+    VADDW       qRes5, qRes5, dDst5
+    VLD1        dDst7, [pDst@64], dstStep
+    VQMOVUN     dDst3, qRes3
+    VLD1        qRes7, [pSrcResidue@128]!
+    VADDW       qRes6, qRes6, dDst6
+    VST1        dDst0, [pDstCopy@64], dstStep
+    VQMOVUN     dDst4, qRes4
+    VST1        dDst1, [pDstCopy@64], dstStep
+    VADDW       qRes7, qRes7, dDst7
+    VST1        dDst2, [pDstCopy@64], dstStep
+    VQMOVUN     dDst5, qRes5
+    VST1        dDst3, [pDstCopy@64], dstStep
+    VQMOVUN     dDst6, qRes6
+    VST1        dDst4, [pDstCopy@64], dstStep
+    VQMOVUN     dDst7, qRes7
+    VST1        dDst5, [pDstCopy@64], dstStep
+    VST1        dDst6, [pDstCopy@64], dstStep
+    VST1        dDst7, [pDstCopy@64], dstStep
+    
+pSrcResidueConditionEnd
+    MOV         return, #OMX_Sts_NoErr
+
+    M_END
+    ENDIF ;// CortexA8
+    END
+;// ***************************************************************************
+;// omxVCM4P2_MCReconBlock ends
+;// ***************************************************************************
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/omxVCM4P2_PredictReconCoefIntra_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/omxVCM4P2_PredictReconCoefIntra_s.s
new file mode 100755
index 0000000..a73f64a
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/omxVCM4P2_PredictReconCoefIntra_s.s
@@ -0,0 +1,320 @@
+; **********
+; * 
+; * File Name:  omxVCM4P2_PredictReconCoefIntra_s.s
+; * OpenMAX DL: v1.0.2
+; * Revision:   12290
+; * Date:       Wednesday, April 9, 2008
+; * 
+; * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+; * 
+; * 
+; * 
+; * Description:
+; * Contains module for DC/AC coefficient prediction
+; *
+; * 
+; * Function: omxVCM4P2_PredictReconCoefIntra
+; *
+; * Description:
+; * Performs adaptive DC/AC coefficient prediction for an intra block. Prior
+; * to the function call, prediction direction (predDir) should be selected
+; * as specified in subclause 7.4.3.1 of ISO/IEC 14496-2.
+; *
+; * Remarks:
+; *
+; * Parameters:
+; * [in]  pSrcDst      pointer to the coefficient buffer which contains the 
+; *                    quantized coefficient residuals (PQF) of the current 
+; *                    block; must be aligned on a 4-byte boundary. The 
+; *                    output coefficients are saturated to the range 
+; *                    [-2048, 2047].
+; * [in]  pPredBufRow  pointer to the coefficient row buffer; must be aligned
+; *                    on a 4-byte boundary.
+; * [in]  pPredBufCol  pointer to the coefficient column buffer; must be 
+; *                    aligned on a 4-byte boundary.
+; * [in]  curQP        quantization parameter of the current block. curQP may 
+; *                    equal to predQP especially when the current block and 
+; *                    the predictor block are in the same macroblock.
+; * [in]  predQP       quantization parameter of the predictor block
+; * [in]  predDir      indicates the prediction direction which takes one
+; *                    of the following values:
+; *                    OMX_VIDEO_HORIZONTAL    predict horizontally
+; *                    OMX_VIDEO_VERTICAL        predict vertically
+; * [in]  ACPredFlag   a flag indicating if AC prediction should be
+; *                    performed. It is equal to ac_pred_flag in the bit
+; *                    stream syntax of MPEG-4
+; * [in]  videoComp    video component type (luminance, chrominance or
+; *                    alpha) of the current block
+; * [out] pSrcDst      pointer to the coefficient buffer which contains
+; *                    the quantized coefficients (QF) of the current
+; *                    block
+; * [out] pPredBufRow  pointer to the updated coefficient row buffer
+; * [out] pPredBufCol  pointer to the updated coefficient column buffer
+; * Return Value:
+; * OMX_Sts_NoErr - no error
+; * OMX_Sts_BadArgErr - Bad arguments 
+; * - At least one of the pointers is NULL: pSrcDst, pPredBufRow, or pPredBufCol.
+; * - At least one the following cases: curQP <= 0, predQP <= 0, curQP >31, 
+; *   predQP > 31, preDir exceeds [1,2].
+; * - At least one of the pointers pSrcDst, pPredBufRow, or pPredBufCol is not 
+; *   4-byte aligned.
+; *
+; *********
+     
+        INCLUDE omxtypes_s.h
+        INCLUDE armCOMM_s.h
+        
+       M_VARIANTS CortexA8
+       
+             
+
+       IMPORT        armVCM4P2_Reciprocal_QP_S32
+       IMPORT        armVCM4P2_Reciprocal_QP_S16
+       IMPORT        armVCM4P2_DCScaler
+       
+        IF CortexA8
+;// Input Arguments
+
+pSrcDst          RN 0
+pPredBufRow      RN 1
+pPredBufCol      RN 2
+curQP            RN 3
+QP               RN 3
+predQP           RN 4
+predDir          RN 5
+ACPredFlag       RN 6
+videoComp        RN 7
+
+;// Local Variables
+
+shortVideoHeader RN 4
+dcScaler         RN 4
+index            RN 6
+predCoeffTable   RN 7
+temp1            RN 6
+temp2            RN 9
+temp             RN 14
+Const            RN 8
+temppPredColBuf  RN 8
+tempPred         RN 9
+
+absCoeffDC       RN 8
+negdcScaler      RN 10
+Rem              RN 11
+temp3            RN 12
+
+dcRowbufCoeff    RN 10
+dcColBuffCoeff   RN 11
+Return           RN 0
+
+;//NEON Registers
+
+qPredRowBuf       QN Q0.S16
+dPredRowBuf0      DN D0.S16
+dPredRowBuf1      DN D1.S16
+
+
+
+
+qCoeffTab         QN Q1.S32
+
+qPredQP           QN Q2.S16
+dPredQP0          DN D4.S16
+dPredQP1          DN D5.S16
+
+
+qtemp1            QN Q3.S32
+qtemp             QN Q3.S16
+
+dtemp0            DN D6.S16
+dtemp1            DN D7.S16
+
+dtemp2            DN D8.S16
+dtemp3            DN D9.S16
+
+dtemp4            DN D2.S16
+dtemp5            DN D3.S16
+dtemp6            DN D4.S16
+dtemp7            DN D5.S16
+ 
+qtempPred1        QN Q5.S32
+qtempPred         QN Q5.S16
+
+dtempPred0        DN D10.S16
+dtempPred1        DN D11.S16
+ 
+  
+
+      M_START   omxVCM4P2_PredictReconCoefIntra,r11,d11
+
+      ;// Assigning pointers to Input arguments on Stack
+    
+      M_ARG           predQPonStack,4  
+      M_ARG           predDironStack,4
+      M_ARG           ACPredFlagonStack,4
+      M_ARG           videoComponStack,4
+      
+      ;// DC Prediction
+
+      M_LDR           videoComp,videoComponStack                     ;// Load videoComp From Stack               
+            
+      M_LDR           predDir,predDironStack                         ;// Load Prediction direction
+      ;// DC Scaler calculation   
+      LDR             index, =armVCM4P2_DCScaler
+      ADD             index,index,videoComp,LSL #5
+      LDRB            dcScaler,[index,QP]
+
+       
+      LDR             predCoeffTable, =armVCM4P2_Reciprocal_QP_S16   ;// Loading the table with entries 32767/(1 to 63) 
+      CMP             predDir,#2                                     ;// Check if the Prediction direction is vertical
+
+      ;// Caulucate tempPred
+            
+      LDREQSH         absCoeffDC,[pPredBufRow]                       ;// If vetical load the coeff from Row Prediction Buffer
+      LDRNESH         absCoeffDC,[pPredBufCol]                       ;// If horizontal load the coeff from column Prediction Buffer
+      
+      RSB             negdcScaler,dcScaler,#0                        ;// negdcScaler=-dcScaler   
+      MOV             temp1,absCoeffDC                               ;// Load the Prediction coeff to temp for comparision                               
+      CMP             temp1,#0                                       
+      RSBLT           absCoeffDC,temp1,#0                            ;// calculate absolute val of prediction coeff
+      
+      ADD             temp,dcScaler,dcScaler
+      LDRH            temp,[predCoeffTable,temp]                     ;// Load value from coeff table for performing division using multiplication
+      SMULBB          tempPred,temp,absCoeffDC                       ;// tempped=pPredBufRow(Col)[0]*32767/dcScaler
+      ADD             temp3,dcScaler,#1
+      LSR             tempPred,tempPred,#15                          ;// tempped=pPredBufRow(Col)[0]/dcScaler                  
+      LSR             temp3,temp3,#1                                 ;// temp3=round(dcScaler/2)           
+      MLA             Rem,negdcScaler,tempPred,absCoeffDC            ;// Remainder Rem=abs(pPredBufRow(Col)[0])-tempPred*dcScaler
+      
+      LDRH            dcRowbufCoeff,[pPredBufCol]            
+      
+      CMP             Rem,temp3                                      ;// compare Rem with (dcScaler/2)
+      ADDGE           tempPred,#1                                    ;// tempPred=tempPred+1 if Rem>=(dcScaler/2)
+      CMP             temp1,#0
+      RSBLT           tempPred,tempPred,#0                           ;// tempPred=-tempPred if 
+       
+      STRH            dcRowbufCoeff,[pPredBufRow,#-16]      
+       
+
+      LDRH            temp,[pSrcDst]                                 ;// temp=pSrcDst[0]
+      ADD             temp,temp,tempPred                             ;// temp=pSrcDst[0]+tempPred
+      SSAT16          temp,#12,temp                                  ;// clip temp to [-2048,2047]
+      SMULBB          dcColBuffCoeff,temp,dcScaler                   ;// temp1=clipped(pSrcDst[0])*dcScaler           
+      M_LDR           ACPredFlag,ACPredFlagonStack
+      STRH            dcColBuffCoeff,[pPredBufCol]      
+      
+
+       ;// AC Prediction
+      
+      M_LDR           predQP,predQPonStack
+      
+      CMP             ACPredFlag,#1                                  ;// Check if the AC prediction flag is set or not
+      BNE             Exit                                           ;// If not set Exit
+      CMP             predDir,#2                                     ;// Check the Prediction direction                       
+      LDR             predCoeffTable, =armVCM4P2_Reciprocal_QP_S32   ;// Loading the table with entries 0x1ffff/(1 to 63) 
+      MOV             Const,#4
+      MUL             curQP,curQP,Const                              ;// curQP=4*curQP
+      VDUP            dPredQP0,predQP
+      LDR             temp2,[predCoeffTable,curQP]                   ;// temp=0x1ffff/curQP
+      VDUP            qCoeffTab,temp2
+      BNE             Horizontal                                     ;// If the Prediction direction is horizontal branch to Horizontal
+      
+     
+      
+      ;// Vertical
+      ;//Calculating tempPred
+
+      VLD1            {dPredRowBuf0,dPredRowBuf1},[pPredBufRow]      ;// Loading pPredBufRow[i]:i=0 t0 7
+      
+      VMULL           qtemp1,dPredRowBuf0,dPredQP0                   ;//qtemp1[i]=pPredBufRow[i]*dPredQP[i]: i=0 t0 3
+      VMUL            qtempPred1,qtemp1,qCoeffTab                    ;//qtempPred1[i]=pPredBufRow[i]*dPredQP[i]*0x1ffff/curQP : i=0 t0 3
+      
+      VMULL           qtemp1,dPredRowBuf1,dPredQP0                   ;//qtemp1[i]=pPredBufRow[i]*dPredQP[i] : i=4 t0 7      
+
+      VRSHR           qtempPred1,qtempPred1,#17                      ;//qtempPred1[i]=round(pPredBufRow[i]*dPredQP[i]/curQP) : i=0 t0 3
+      VSHRN           dPredQP1,qtempPred1,#0                         ;// narrow qtempPred1[i] to 16 bits
+      
+      
+      VMUL            qtempPred1,qtemp1,qCoeffTab                    ;//qtempPred1[i]=pPredBufRow[i]*dPredQP[i]*0x1ffff/curQP : i=4 t0 7
+      VRSHR           qtempPred1,qtempPred1,#17                      ;//qtempPred1[i]=round(pPredBufRow[i]*dPredQP[i]/curQP)  : i=4 t0 7
+      VLD1            {dtemp0,dtemp1},[pSrcDst]                      ;//Loading pSrcDst[i] : i=0 to 7
+      VSHRN           dtempPred1,qtempPred1,#0                       ;// narrow qtempPred1[i] to 16 bits
+      VMOV            dtempPred0,dPredQP1
+      
+      ;//updating source and row prediction buffer contents      
+      VADD            qtemp,qtemp,qtempPred                          ;//pSrcDst[i]=pSrcDst[i]+qtempPred[i]: i=0 to 7 
+      VQSHL           qtemp,qtemp,#4                                 ;//Clip to [-2048,2047]
+      LDRH            dcRowbufCoeff,[pPredBufRow]                    ;//Loading Dc Value of Row Prediction buffer
+      VSHR            qtemp,qtemp,#4
+      
+      VST1            {dtemp0,dtemp1},[pSrcDst]                      ;//storing back the updated values 
+      VST1            {dtemp0,dtemp1},[pPredBufRow]                  ;//storing back the updated row prediction values                      
+      STRH            dcRowbufCoeff,[pPredBufRow]                    ;// storing the updated DC Row Prediction coeff
+      
+      B               Exit
+
+Horizontal
+
+      ;// Calculating Temppred
+
+            
+
+      VLD1            {dPredRowBuf0,dPredRowBuf1},[pPredBufCol]      ;// Loading pPredBufCol[i]:i=0 t0 7
+      VMULL           qtemp1,dPredRowBuf0,dPredQP0                   ;//qtemp1[i]=pPredBufCol[i]*dPredQP[i]: i=0 t0 3
+      VMUL            qtempPred1,qtemp1,qCoeffTab                    ;//qtempPred1[i]=pPredBufCol[i]*dPredQP[i]*0x1ffff/curQP : i=0 t0 3
+      
+      VMULL           qtemp1,dPredRowBuf1,dPredQP0                   ;//qtemp1[i]=pPredBufCol[i]*dPredQP[i] : i=4 t0 7      
+
+      VRSHR           qtempPred1,qtempPred1,#17                      ;//qtempPred1[i]=round(pPredBufCol[i]*dPredQP[i]/curQP) : i=0 t0 3
+      VSHRN           dPredQP1,qtempPred1,#0                         ;// narrow qtempPred1[i] to 16 bits
+      
+      
+      VMUL            qtempPred1,qtemp1,qCoeffTab                    ;//qtempPred1[i]=pPredBufCol[i]*dPredQP[i]*0x1ffff/curQP : i=4 t0 7
+      
+      MOV             temppPredColBuf,pPredBufCol
+      VRSHR           qtempPred1,qtempPred1,#17                      ;//qtempPred1[i]=round(pPredBufCol[i]*dPredQP[i]/curQP)  : i=4 t0 7
+      VLD4            {dtemp0,dtemp1,dtemp2,dtemp3},[pSrcDst]        ;// Loading coefficients Interleaving by 4
+      VSHRN           dtempPred1,qtempPred1,#0                       ;// narrow qtempPred1[i] to 16 bits
+      VMOV            dtempPred0,dPredQP1
+      
+      ;// Updating source and column prediction buffer contents     
+      ADD             temp2,pSrcDst,#32                                  
+      VLD4            {dtemp4,dtemp5,dtemp6,dtemp7},[temp2]          ;// Loading next 16 coefficients Interleaving by 4
+      VUZP            dtemp0,dtemp4                                  ;// Interleaving by 8
+      VADD            dtemp0,dtemp0,dtempPred0                       ;// Adding tempPred to coeffs
+      VQSHL           dtemp0,dtemp0,#4                               ;// Clip to [-2048,2047]
+      VSHR            dtemp0,dtemp0,#4
+      VST1            {dtemp0},[pPredBufCol]!                        ;// Updating Pridiction column buffer
+      VZIP            dtemp0,dtemp4                                  ;// deinterleaving
+      VST4            {dtemp0,dtemp1,dtemp2,dtemp3},[pSrcDst]        ;// Updating source coeffs         
+      VST4            {dtemp4,dtemp5,dtemp6,dtemp7},[temp2]!
+      
+      MOV             temp1,temp2                                     
+      VLD4            {dtemp0,dtemp1,dtemp2,dtemp3},[temp2]!         ;// Loading  coefficients Interleaving by 4
+      
+      VLD4            {dtemp4,dtemp5,dtemp6,dtemp7},[temp2]
+      VUZP            dtemp0,dtemp4                                  ;// Interleaving by 8
+      VADD            dtemp0,dtemp0,dtempPred1
+      VQSHL           dtemp0,dtemp0,#4                               ;// Clip to [-2048,2047]
+      VSHR            dtemp0,dtemp0,#4
+      VST1            {dtemp0},[pPredBufCol]!
+      VZIP            dtemp0,dtemp4
+      VST4            {dtemp0,dtemp1,dtemp2,dtemp3},[temp1]
+      STRH            dcColBuffCoeff,[temppPredColBuf] 
+      VST4            {dtemp4,dtemp5,dtemp6,dtemp7},[temp2]
+      
+Exit
+
+      STRH            temp,[pSrcDst]
+          
+ 
+      MOV             Return,#OMX_Sts_NoErr 
+ 
+      M_END
+      ENDIF
+
+
+       END
+
+
+   
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/omxVCM4P2_QuantInvInter_I_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/omxVCM4P2_QuantInvInter_I_s.s
new file mode 100755
index 0000000..bd0ad1f
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/omxVCM4P2_QuantInvInter_I_s.s
@@ -0,0 +1,162 @@
+;/**
+; * 
+; * File Name:  omxVCM4P2_QuantInvInter_I_s.s
+; * OpenMAX DL: v1.0.2
+; * Revision:   12290
+; * Date:       Wednesday, April 9, 2008
+; * 
+; * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+; * 
+; * 
+; *
+; * Description: 
+; * Contains modules for inter reconstruction
+; * 
+; *
+; *
+; *
+; *
+; * Function: omxVCM4P2_QuantInvInter_I
+; *
+; * Description:
+; * Performs inverse quantization on intra/inter coded block.
+; * This function supports bits_per_pixel = 8. Mismatch control
+; * is performed for the first MPEG-4 mode inverse quantization method.
+; * The output coefficients are clipped to the range: [-2048, 2047].
+; * Mismatch control is performed for the first inverse quantization method.
+; *
+; * Remarks:
+; *
+; * Parameters:
+; * [in] pSrcDst          pointer to the input (quantized) intra/inter block. Must be 16-byte aligned.
+; * [in] QP              quantization parameter (quantiser_scale)
+; * [in] videoComp      (Intra version only.) Video component type of the
+; *                  current block. Takes one of the following flags:
+; *                  OMX_VC_LUMINANCE, OMX_VC_CHROMINANCE,
+; *                  OMX_VC_ALPHA.
+; * [in] shortVideoHeader a flag indicating presence of short_video_header;
+; *                       shortVideoHeader==1 selects linear intra DC mode,
+; *                  and shortVideoHeader==0 selects nonlinear intra DC mode.
+; * [out]    pSrcDst      pointer to the output (dequantized) intra/inter block.  Must be 16-byte aligned.
+; *
+; * Return Value:
+; * OMX_Sts_NoErr - no error
+; * OMX_Sts_BadArgErr - bad arguments
+; *    - If pSrcDst is NULL or is not 16-byte aligned.
+; *      or
+; *    - If QP <= 0.
+; *      or
+; *    - videoComp is none of OMX_VC_LUMINANCE, OMX_VC_CHROMINANCE and OMX_VC_ALPHA.
+; *
+; */
+
+   INCLUDE omxtypes_s.h
+   INCLUDE armCOMM_s.h
+
+   M_VARIANTS CortexA8
+
+     IF CortexA8
+     
+     
+;//Input Arguments
+pSrcDst            RN 0
+QP                 RN 1
+     
+
+;//Local Variables
+Count              RN 3
+doubleQP           RN 4
+Return             RN 0
+;// Neon registers
+
+
+dQP10              DN D0.S32[0]
+qQP1               QN Q0.S32
+
+dQP1               DN D0.S16
+dMinusQP1          DN D1.S16
+
+dCoeff0            DN D2.S16
+dCoeff1            DN D3.S16   
+
+qResult0           QN Q3.S32
+dResult0           DN D7.S16
+qSign0             QN Q3.S32
+dSign0             DN D6.S16
+
+qResult1           QN Q4.S32
+dResult1           DN D8.S16
+qSign1             QN Q4.S32
+dSign1             DN D8.S16
+
+d2QP0              DN D10.S32[0]
+q2QP0              QN Q5.S32
+d2QP               DN D10.S16
+
+dZero0             DN D11.S16
+dZero1             DN D12.S16
+dConst0            DN D13.S16
+
+    
+     M_START omxVCM4P2_QuantInvInter_I,r4,d13
+     
+         
+         
+         ADD      doubleQP,QP,QP                   ;// doubleQP= 2*QP
+         VMOV     d2QP0,doubleQP
+         VDUP     q2QP0,d2QP0                      ;// Move doubleQP in to a scalar
+         TST      QP,#1                   
+         VLD1     {dCoeff0,dCoeff1},[pSrcDst]      ;// Load first 8 values to Coeff0,Coeff1
+         SUBEQ    QP,QP,#1                            
+         VMOV     dQP10,QP                         ;// If QP is even then QP1=QP-1 else QP1=QP     
+         MOV      Count,#64
+         VDUP     qQP1,dQP10                       ;// Duplicate tempResult with QP1
+         VSHRN    d2QP,q2QP0,#0
+         VEOR     dConst0,dConst0,dConst0
+         VSHRN    dQP1,qQP1,#0                     ;// QP1 truncated to 16 bits
+         VSUB     dMinusQP1,dConst0,dQP1           ;// dMinusQP1=-QP1
+
+Loop                       
+         
+        ;//Performing Inverse Quantization
+         
+         VCLT     dSign0,dCoeff0, #0               ;// Compare Coefficient 0 against 0
+         VCLT     dSign1,dCoeff1, #0               ;// Compare Coefficient 1 against 0
+         VCEQ     dZero0,dCoeff0,#0                ;// Compare Coefficient 0 against zero
+         VBSL     dSign0,dMinusQP1,dQP1            ;// dSign0 = -QP1 if Coeff0< 0 else QP1
+         VCEQ     dZero1,dCoeff1,#0                ;// Compare Coefficient 1 against zero
+         VBSL     dSign1,dMinusQP1,dQP1            ;// dSign1 = -QP1 if Coeff1< 0 else QP1
+         VMOVL    qSign0,dSign0                    ;// Sign extend qSign0 to 32 bits
+         VMOVL    qSign1,dSign1
+         VMLAL    qResult0,dCoeff0,d2QP            ;// qResult0[i]= qCoeff0[i]+qCoeff0[i]*(-2) if Coeff <0 
+                                                   ;// qResult0[i]= qCoeff0[i]                 if Coeff >=0 
+         VMLAL    qResult1,dCoeff1,d2QP            ;// qResult1[i]= qCoeff1[i]+qCoeff1[i]*(-2) if Coeff <0 
+                                                   ;// qResult1[i]= qCoeff1[i]                 if Coeff >=0 
+         ;// Clip Result to [-2048,2047]                     
+         
+         VQSHL    qResult0,qResult0,#20            ;// clip to [-2048,2047]
+         VQSHL    qResult1,qResult1,#20
+                 
+         VSHR     qResult0,qResult0,#4  
+         VSHR     qResult1,qResult1,#4
+         VSHRN    dResult0,qResult0,#16            ;// Narrow the clipped Value to Halfword
+         VSHRN    dResult1,qResult1,#16 
+         VBIT     dResult0,dConst0,dZero0  
+         VBIT     dResult1,dConst0,dZero1     
+         
+         VST1     {dResult0,dResult1},[pSrcDst]!   ;// Store the result
+         SUBS     Count,Count,#8
+         VLD1     {dCoeff0,dCoeff1},[pSrcDst]
+         
+         
+         BGT      Loop
+
+         MOV      Return,#OMX_Sts_NoErr
+
+
+         M_END
+         ENDIF
+         
+
+        END
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/omxVCM4P2_QuantInvIntra_I_s.s b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/omxVCM4P2_QuantInvIntra_I_s.s
new file mode 100755
index 0000000..e00591f
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/omxVCM4P2_QuantInvIntra_I_s.s
@@ -0,0 +1,210 @@
+;/**
+; * 
+; * File Name:  omxVCM4P2_QuantInvIntra_I_s.s
+; * OpenMAX DL: v1.0.2
+; * Revision:   12290
+; * Date:       Wednesday, April 9, 2008
+; * 
+; * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+; * 
+; * 
+; *
+; * Description: 
+; * Contains modules for inter reconstruction
+; * 
+; *
+; *
+; *
+; *
+; * 
+; * Function: omxVCM4P2_QuantInvIntra_I
+; *
+; * Description:
+; * Performs inverse quantization on intra/inter coded block.
+; * This function supports bits_per_pixel = 8. Mismatch control
+; * is performed for the first MPEG-4 mode inverse quantization method.
+; * The output coefficients are clipped to the range: [-2048, 2047].
+; * Mismatch control is performed for the first inverse quantization method.
+; *
+; * Remarks:
+; *
+; * Parameters:
+; * [in]    pSrcDst        pointer to the input (quantized) intra/inter block. Must be 16-byte aligned.
+; * [in]    QP            quantization parameter (quantiser_scale)
+; * [in]    videoComp          (Intra version only.) Video component type of the
+; *                    current block. Takes one of the following flags:
+; *                    OMX_VC_LUMINANCE, OMX_VC_CHROMINANCE,
+; *                    OMX_VC_ALPHA.
+; * [in]    shortVideoHeader  a flag indicating presence of short_video_header;
+; *                           shortVideoHeader==1 selects linear intra DC mode,
+; *                    and shortVideoHeader==0 selects nonlinear intra DC mode.
+; * [out]    pSrcDst        pointer to the output (dequantized) intra/inter block.  Must be 16-byte aligned.
+; *
+; * Return Value:
+; * OMX_Sts_NoErr - no error
+; * OMX_Sts_BadArgErr - bad arguments
+; *    -    If pSrcDst is NULL or is not 16-byte aligned.
+; *      or
+; *    - If QP <= 0.
+; *      or
+; *    - videoComp is none of OMX_VC_LUMINANCE, OMX_VC_CHROMINANCE and OMX_VC_ALPHA.
+; *
+ 
+
+   INCLUDE omxtypes_s.h
+   INCLUDE armCOMM_s.h
+   
+   M_VARIANTS CortexA8
+   
+   
+   IMPORT        armVCM4P2_DCScaler
+ 
+     IF CortexA8
+     
+     
+;//Input Arguments
+pSrcDst            RN 0
+QP                 RN 1
+videoComp          RN 2
+shortVideoHeader   RN 3
+     
+
+;//Local Variables
+
+dcScaler           RN 4
+temp               RN 14
+index              RN 5
+
+
+Count              RN 5
+doubleQP           RN 4
+Return             RN 0
+
+
+;// Neon registers
+
+
+dQP10              DN D0.S32[0]
+qQP1               QN Q0.S32
+
+dQP1               DN D0.S16
+dMinusQP1          DN D1.S16
+
+dCoeff0            DN D2.S16
+dCoeff1            DN D3.S16   
+
+qResult0           QN Q3.S32
+dResult0           DN D7.S16
+qSign0             QN Q3.S32
+dSign0             DN D6.S16
+
+qResult1           QN Q4.S32
+dResult1           DN D8.S16
+qSign1             QN Q4.S32
+dSign1             DN D8.S16
+
+d2QP0              DN D10.S32[0]
+q2QP0              QN Q5.S32
+d2QP               DN D10.S16
+
+dZero0             DN D11.S16
+dZero1             DN D4.S16
+dConst0            DN D5.S16
+
+
+
+
+     
+     
+     M_START omxVCM4P2_QuantInvIntra_I,r5,d11
+
+
+        ;// Perform Inverse Quantization for DC coefficient
+
+        TEQ       shortVideoHeader,#0      ;// Test if short Video Header flag =0             
+        MOVNE     dcScaler,#8              ;// if shortVideoHeader is non zero dcScaler=8
+        BNE       calDCVal
+        
+        LDR       index, =armVCM4P2_DCScaler
+      ADD       index,index,videoComp,LSL #5
+      LDRB      dcScaler,[index,QP]
+
+        ;//M_CalDCScalar  shortVideoHeader,videoComp, QP
+
+calDCVal
+
+        LDRH     temp,[pSrcDst]
+        SMULBB   temp,temp,dcScaler       ;// dcCoeff = dcScaler * Quantized DC coefficient(from memory)
+        SSAT     temp,#12,temp            ;// Saturating to 12 bits
+      
+
+
+        ;// Perform Inverse Quantization for Ac Coefficients
+     
+         
+         
+         ADD      doubleQP,QP,QP                   ;// doubleQP= 2*QP
+         VMOV     d2QP0,doubleQP
+         VDUP     q2QP0,d2QP0                      ;// Move doubleQP in to a scalar
+         TST      QP,#1                   
+         VLD1     {dCoeff0,dCoeff1},[pSrcDst]      ;// Load first 8 values to Coeff0,Coeff1
+         SUBEQ    QP,QP,#1                            
+         VMOV     dQP10,QP                         ;// If QP is even then QP1=QP-1 else QP1=QP     
+         MOV      Count,#64
+         VDUP     qQP1,dQP10                       ;// Duplicate tempResult with QP1
+         VSHRN    d2QP,q2QP0,#0
+         VEOR     dConst0,dConst0,dConst0
+         VSHRN    dQP1,qQP1,#0                     ;// QP1 truncated to 16 bits
+         VSUB     dMinusQP1,dConst0,dQP1           ;// dMinusQP1=-QP1
+
+Loop                       
+         
+        ;//Performing Inverse Quantization
+         
+         VCLT     dSign0,dCoeff0, #0               ;// Compare Coefficient 0 against 0
+         VCLT     dSign1,dCoeff1, #0               ;// Compare Coefficient 1 against 0
+         VCEQ     dZero0,dCoeff0,#0                ;// Compare Coefficient 0 against zero
+         VBSL     dSign0,dMinusQP1,dQP1            ;// dSign0 = -QP1 if Coeff0< 0 else QP1
+         VCEQ     dZero1,dCoeff1,#0                ;// Compare Coefficient 1 against zero
+         VBSL     dSign1,dMinusQP1,dQP1            ;// dSign1 = -QP1 if Coeff1< 0 else QP1
+         VMOVL    qSign0,dSign0                    ;// Sign extend qSign0 to 32 bits
+         VMOVL    qSign1,dSign1
+         VMLAL    qResult0,dCoeff0,d2QP            ;// qResult0[i]= qCoeff0[i]+qCoeff0[i]*(-2) if Coeff <0 
+                                                   ;// qResult0[i]= qCoeff0[i]                 if Coeff >=0 
+         VMLAL    qResult1,dCoeff1,d2QP            ;// qResult1[i]= qCoeff1[i]+qCoeff1[i]*(-2) if Coeff <0 
+                                                   ;// qResult1[i]= qCoeff1[i]                 if Coeff >=0 
+         ;// Clip Result to [-2048,2047]                     
+         
+         VQSHL    qResult0,qResult0,#20            ;// clip to [-2048,2047]
+         VQSHL    qResult1,qResult1,#20
+                 
+         VSHR     qResult0,qResult0,#4  
+         VSHR     qResult1,qResult1,#4
+         VSHRN    dResult0,qResult0,#16            ;// Narrow the clipped Value to Halfword
+         VSHRN    dResult1,qResult1,#16 
+         VBIT     dResult0,dConst0,dZero0  
+         VBIT     dResult1,dConst0,dZero1     
+         
+         VST1     {dResult0,dResult1},[pSrcDst]!   ;// Store the result
+         SUBS     Count,Count,#8
+         VLD1     {dCoeff0,dCoeff1},[pSrcDst]
+         
+         
+         BGT      Loop
+         
+         SUB      pSrcDst,pSrcDst,#128
+         
+         ;// Store the Inverse quantized Dc coefficient
+         
+         STRH     temp,[pSrcDst],#2
+        
+         MOV      Return,#OMX_Sts_NoErr
+         
+
+
+         M_END
+         ENDIF
+         
+
+        END
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/src/armVC_Version.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/src/armVC_Version.c
new file mode 100755
index 0000000..5d93681
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/src/armVC_Version.c
@@ -0,0 +1,6 @@
+#include "omxtypes.h"
+#include "armCOMM_Version.h"
+
+#ifdef ARM_INCLUDE_VERSION_DESCRIPTIONS
+const char * const omxVC_VersionDescription = "ARM OpenMAX DL v" ARM_VERSION_STRING "   Rel=" OMX_ARM_RELEASE_TAG "   Arch=" OMX_ARM_BUILD_ARCHITECTURE "   Tools="  OMX_ARM_BUILD_TOOLCHAIN ;
+#endif /* ARM_INCLUDE_VERSION_DESCRIPTIONS */
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/ARM_DELIVERY.TXT b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/ARM_DELIVERY.TXT
new file mode 100644
index 0000000..7801f3dd
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/ARM_DELIVERY.TXT
@@ -0,0 +1,63 @@
+The contents of this transaction was created by Hedley Francis
+of ARM on 19-Feb-2008.
+
+It contains the ARM data versions listed below.
+
+This data, unless otherwise stated, is ARM Proprietary and access to it
+is subject to the agreements indicated below.
+
+If you experience problems with this data, please contact ARM support
+quoting transaction reference <97412>.
+
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+- OX000-SW-98010-r0p0-00bet1
+  Video codecs - sample code
+  Sample code release for Hantro (Ver 1.0.2)
+  internal access
+
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+This transaction contains deliverables which are designated as being of
+beta release status (BET).
+
+Beta release status has a particular meaning to ARM of which the recipient
+must be aware. Beta is a pre-release status indicating that the deliverable
+so described is believed to robustly demonstrate specified behaviour, to be
+consistent across its included aspects and be ready for general deployment.
+But Beta also indicates that pre-release reliability trials are ongoing and
+that it is possible residual defects or errors in operation, consistency
+and documentation may still be encountered. The recipient should consider
+this position when using this Beta material supplied. ARM will normally
+attempt to provide fixes or a work-around for defects identified by the
+recipient, but the provision or timeliness of this support cannot be
+guaranteed. ARM shall not be responsible for direct or consequential
+damages as a result of encountering one or more of these residual defects.
+By accepting a Beta release, the recipient agrees to these constraints and
+to providing reasonable information to ARM to enable the replication of the
+defects identified by the recipient. The specific Beta version supplied
+will not be supported after release of a later or higher status version.
+It should be noted that Support for the Beta release of the deliverable
+will only be provided by ARM to a recipient who has a current support and
+maintenance contract for the deliverable.
+
+
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+In addition to the data versions listed above, this transaction contains
+two additional files at the top level.
+
+The first is this file, ARM_DELIVERY_97412.TXT, which is the delivery
+note.
+
+The second is ARM_MANIFEST_97412.TXT which contains a manifest of all the
+files included in this transaction, together with their checksums.
+
+The checksums provided are calculated using the RSA Data Security, Inc.
+MD5 Message-Digest Algorithm.
+
+The checksums can be used to verify the integrity of this data using the
+"md5sum" tool (which is part of the GNU "textutils" package) by running:
+
+  % md5sum --check ARM_MANIFEST_97412.TXT
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/ARM_MANIFEST.TXT b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/ARM_MANIFEST.TXT
new file mode 100644
index 0000000..8e01b1e
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/ARM_MANIFEST.TXT
@@ -0,0 +1,140 @@
+				  OX000-SW-98010-r0p0-00bet1/
+				  OX000-SW-98010-r0p0-00bet1/api/
+8971932d56eed6b1ad1ba507f0bff5f0  OX000-SW-98010-r0p0-00bet1/api/armCOMM_Bitstream.h
+e88ec84e122534092b90c67841549d6f  OX000-SW-98010-r0p0-00bet1/api/armCOMM_Version.h
+43cf46c2cf2fe1f93c615b57bcbe4809  OX000-SW-98010-r0p0-00bet1/api/armCOMM.h
+f87fedd9ca432fefa757008176864ef8  OX000-SW-98010-r0p0-00bet1/api/armOMX.h
+8e49899a428822c36ef9dd94e0e05f18  OX000-SW-98010-r0p0-00bet1/api/omxtypes.h
+a06983abb39c476b081e87ea271361a5  OX000-SW-98010-r0p0-00bet1/build_vc.pl
+c01f8b93ab73d8c00ddf2499f01da5ff  OX000-SW-98010-r0p0-00bet1/filelist_vc.txt
+				  OX000-SW-98010-r0p0-00bet1/src/
+26e2ff3f633764eb720deb340978dc2d  OX000-SW-98010-r0p0-00bet1/src/armCOMM_Bitstream.c
+79aa23d9817efd11d0c4c2be36ec1e5c  OX000-SW-98010-r0p0-00bet1/src/armCOMM.c
+				  OX000-SW-98010-r0p0-00bet1/vc/
+				  OX000-SW-98010-r0p0-00bet1/vc/m4p10/
+				  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/
+e45297704d72302d4a947d0798c666fb  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_CAVLCTables.c
+205dfafe1fe7bb160bf36d2600e1100a  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_DeblockLuma_I.c
+bf92641e8548577b77e04e03ec04c358  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_MEGetBufSize.c
+f5ee6f7be822d87471cef3b1801dbfc2  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_FilterDeblockingChroma_VerEdge_I.c
+28110b3a13cecf4f216d10bcc761c401  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_Interpolate_Chroma.c
+9a1a25245c975d641e1c6378834aea4d  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_InterpolateHalfVer_Luma.c
+3a643eaaaeb12e8d274dc59a7357a586  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_FilterDeblockingLuma_HorEdge_I.c
+4c4de5973a6b74250ce91ac0b317a617  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_InvTransformDequant_LumaDC.c
+4ecdbe9193aaba1f9bb0e24c938b34f9  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_UnpackBlock2x2.c
+66e912f8c88f6019cba3ede27150a407  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_InterpolateLuma.c
+266da42f4e3015e67b2cbb58169d437f  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_InterpolateHalfDiag_Luma.c
+d905247eeaa52d4e2cf5f6bc3f61b348  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_DecodeCoeffsToPair.c
+5b29448db0495cd1717a4b925f13377c  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_PredictIntra_16x16.c
+f6451df27f6dcc99036b4b1253c23bb6  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_FilterDeblockingChroma_HorEdge_I.c
+892787d850eef09dc2148d45b416b062  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_TransformQuant_ChromaDC.c
+33da1c01a31f47c0f3aea9a7a5eaa9be  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_BlockMatch_Quarter.c
+e9fb11b066775283dcfeae8d12a6c97a  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_InterpolateHalfVer_Luma.c
+add97bec08e5e1a538aa8607168e61ba  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_PredictIntraChroma_8x8.c
+b695ecfc917b39470d1f40773b923972  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_PredictIntraDC4x4.c
+51bc596fd2ff61ad5450d7138461f4a1  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_MEInit.c
+dc6baa0a388dc5ea8ff65c24b179e670  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_GetVLCInfo.c
+a5499902996576f6712849db34d5ad65  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_FilterDeblockingLuma_VerEdge_I.c
+0c3b76745d53e74a8e64e80def31faba  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_PredictIntra_4x4.c
+4f2742ba5a3c2208f53bc0f6a443be14  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_SADQuar_4x.c
+b4ae2dc948e8ca64831fe3bbfbd89523  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_InterpolateChroma.c
+e15118cbe372db7cadba225c9456f189  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_SADQuar.c
+623cf336cfce7d0174f4e54072456f33  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_InvTransformResidualAndAdd.c
+89e452c80e30357cadfb04c05b6fe00c  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_InterpolateHalfHor_Luma.c
+3a5551cc54e85bbe34fc966c7dc00f1c  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_BlockMatch_Integer.c
+114030fa0d8f00af6d3289f47a5e85bf  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_DecodeCoeffsToPairCAVLC.c
+9e373ab296fb85bb45565a6c384f6ed8  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_DequantTables.c
+2d200f7cc230f302da48c589da42c02f  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_UnpackBlock4x4.c
+ea3f1d1d1507b55610b1349c7b5946e8  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_TransformDequantChromaDCFromPair.c
+bd2bf1743aef2a9396545ed025362be2  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_Average_4x.c
+ca68e809567bf89044631b67d228c7ce  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_DeblockChroma_I.c
+77caf2b5cbee96d360a919f27e1f14f4  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_QuantTables.c
+26081e384ec627fedad474a0e7dad877  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_SADQuar_8x.c
+1c83ae9207a54944936f4a63c665bd99  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_MotionEstimationMB.c
+4c36e04db20200f4ec72e5aba57446fd  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_SATD_4x4.c
+f75b7c5a80d8bf33e315380e4ef0ab8a  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_InterpolateHalfHor_Luma.c
+488925bb7aeeae0ccf93ec44af9fce35  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_SADQuar_16x.c
+c91a5345b5f877b3831ed1abcc60d579  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_BlockMatch_Half.c
+35515a115a32fcac8479072a9a5b0db9  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_Interpolate_Luma.c
+fdcf4622bc5f0ae75bdb0a51dcd03397  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_TransformQuant_LumaDC.c
+74c9278177400a1f7cc6d799a8c8ab34  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_SAD_4x.c
+56aa2d506d0cfdb4ebd366c07adb2d85  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_DeBlockPixel.c
+36b2165fd4d2a7f3f3e1f8daff4f94e5  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_SubAndTransformQDQResidual.c
+4b6b1b933fc7bc8f14a184c02c028085  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_TransformResidual4x4.c
+cf0ff093a9b372dd3271e3e5c28984d4  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_TransformDequantLumaDCFromPair.c
+9ccad9f894fbd32194f5b53da217072a  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_InvTransformDequant_ChromaDC.c
+4943a7a2df7e9d700675f8c1debf4d90  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_CompareMotionCostToMV.c
+29e4a7f38f8c2e8246ed756db03c012e  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/armVCM4P10_FwdTransformResidual4x4.c
+27bc64e7c18da0aab9c987a388f61608  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_DecodeChromaDcCoeffsToPairCAVLC.c
+859185614bb9d0013861e454d7b918f2  OX000-SW-98010-r0p0-00bet1/vc/m4p10/src/omxVCM4P10_DequantTransformResidualFromPairAndAdd.c
+				  OX000-SW-98010-r0p0-00bet1/vc/m4p10/api/
+63e3b64b96cc42a235c04f3a0f991316  OX000-SW-98010-r0p0-00bet1/vc/m4p10/api/armVCM4P10_CAVLCTables.h
+				  OX000-SW-98010-r0p0-00bet1/vc/m4p2/
+				  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/
+0aae4f683d8903cba9956d3301ed9ffe  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/armVCM4P2_ACDCPredict.c
+8d6c1b44915329165df643081cc11a97  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_MCReconBlock.c
+0435eca930eacda0f2a59e843d405eff  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_MotionEstimationMB.c
+9a82dd0b1f05f798567436a009d02969  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_DecodePadMV_PVOP.c
+e1e24646c4bd03f5df78295452dd4eb2  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_BlockMatch_Integer_8x8.c
+746e6b334e4a26d4a9bfae6d735826f6  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_DCT8x8blk.c
+8b1d87b74d80ff13a16215b61d5e52ba  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_IDCT8x8blk.c
+309358d357baafc38d2b37bf1e9768a9  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_QuantInvInter_I.c
+cc77c7242b53c153f8d09527583f2771  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_FindMVpred.c
+7cd8e7796017e3dd00b494d34f629f3f  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_MEGetBufSize.c
+a4905cb5f8d4b244454ee4f60d18358b  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/armVCM4P2_PutVLCBits.c
+5596b31e433222c1e4860deebfa98ef2  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/armVCM4P2_DCT_Table.c
+365d072be6eab201f6e040058a3bacfc  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/armVCM4P2_BlockMatch_Integer.c
+78ed2212585b0cca75913a473b2ec430  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_EncodeVLCZigzag_IntraACVLC.c
+50b2d8da8f20f6b1d39b8d3df38af55d  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_EncodeMV.c
+4a851a2ad6d357cdc233d9c0bf475e02  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/armVCM4P2_BlockMatch_Half.c
+0d6d63878f2827e00e5f85b1e8e26017  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/armVCM4P2_Zigzag_Tables.c
+48b865a983fe5bf3075eddf652950722  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_PredictReconCoefIntra.c
+5f48fa7941835c46ac767e63fc29403b  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_EncodeVLCZigzag_IntraDCVLC.c
+bbaf454b64b32b2c42a76a7ec393d977  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/armVCM4P2_CompareMV.c
+eebff772f87a414436c5c5286f2cd213  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_MEInit.c
+65ae242eb8cb6d1027677c8ef8f77ca0  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/armVCM4P2_FillVLCBuffer.c
+125642b1ea0c1256d79af1e0ddecae93  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_QuantInter_I.c
+ce24ba3d83da4cb791485d3128268bf6  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_TransRecBlockCoef_intra.c
+09bc09a2e6fd962e719944582e38a8fd  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_DecodeBlockCoef_Intra.c
+6b0ee7a116471a4dadbe5bc8dbf425b0  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/armVCM4P2_FillVLDBuffer.c
+21322dca027c28353e3e7eb8f3620062  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/armVCM4P2_CheckVLCEscapeMode.c
+ef353d83244288d8c37e0f70249177cc  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/armVCM4P2_GetVLCBits.c
+541de824f8aebe4a5cac6f15da943efa  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_BlockMatch_Half_8x8.c
+0b40b154b591c7f8842cffe4042d17c5  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/armVCM4P2_Huff_Tables_VLC.c
+2ffcec88d3fcb372543a8f4508ea1ac6  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_QuantIntra_I.c
+e06d85ca000afcbb50580f98f0203ac8  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_IntraACVLC.c
+ae82b6fcfcf731a61d70e1aa42e6277a  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_BlockMatch_Integer_16x16.c
+1d04395e231b597562257e98cda6cfb0  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_DecodeBlockCoef_Inter.c
+72c0a36327b6b9b436d3bce7c896c520  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_IntraDCVLC.c
+1b65aa7f311124ea6fb47e384ec06a50  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_QuantInvIntra_I.c
+714957104a6ef71341fbe6a9ec65c136  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/armVCM4P2_SetPredDir.c
+86493f0ee853f653354a7389f1727f73  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_TransRecBlockCoef_inter.c
+5de8afcfb3052968794782a7c3a0b41a  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_EncodeVLCZigzag_Inter.c
+50bcc228cc660dbda037725309de3f8b  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/armVCM4P2_EncodeVLCZigzag_intra.c
+4f5cfa1ecc668913dde94e3caf97a2e1  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/armVCM4P2_DecodeVLCZigzag_intra.c
+c2ec804ddf64ee841146e39c3a783451  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_BlockMatch_Half_16x16.c
+4087f6a827912ee5b45ed4217f1a6d77  OX000-SW-98010-r0p0-00bet1/vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_Inter.c
+				  OX000-SW-98010-r0p0-00bet1/vc/m4p2/api/
+5c711702dddcec85298003860d760cec  OX000-SW-98010-r0p0-00bet1/vc/m4p2/api/armVCM4P2_DCT_Table.h
+1b92c94b785c03ec76d4fae2f2bbdb8a  OX000-SW-98010-r0p0-00bet1/vc/m4p2/api/armVCM4P2_ZigZag_Tables.h
+ad9c6986d2a3200dd5e1f6103a54a99b  OX000-SW-98010-r0p0-00bet1/vc/m4p2/api/armVCM4P2_Huff_Tables_VLC.h
+				  OX000-SW-98010-r0p0-00bet1/vc/src/
+e627b3346b0dc9aff14446005ce0fa43  OX000-SW-98010-r0p0-00bet1/vc/src/armVC_Version.c
+				  OX000-SW-98010-r0p0-00bet1/vc/api/
+7ca94b1c33ac0211e17d38baadd7d1dd  OX000-SW-98010-r0p0-00bet1/vc/api/armVC.h
+12cf7596edbbf6048b626d15e8d0ed48  OX000-SW-98010-r0p0-00bet1/vc/api/omxVC.h
+				  OX000-SW-98010-r0p0-00bet1/vc/comm/
+				  OX000-SW-98010-r0p0-00bet1/vc/comm/src/
+3a6df0085736cbcbe2e3f45d08af4221  OX000-SW-98010-r0p0-00bet1/vc/comm/src/armVCCOMM_Average.c
+0bf3cb52863c829b28c0352835170211  OX000-SW-98010-r0p0-00bet1/vc/comm/src/omxVCCOMM_Copy8x8.c
+538b62f510b5a8bdced4a39fa12d9a23  OX000-SW-98010-r0p0-00bet1/vc/comm/src/omxVCCOMM_ComputeTextureErrorBlock_SAD.c
+66993edd9d441bf3b5b6c912f6400b6e  OX000-SW-98010-r0p0-00bet1/vc/comm/src/omxVCCOMM_ExpandFrame_I.c
+8e526a9007eb0d43ebf362c498b37415  OX000-SW-98010-r0p0-00bet1/vc/comm/src/omxVCCOMM_LimitMVToRect.c
+87f8f26e6e9178df0ab7419334d5a3db  OX000-SW-98010-r0p0-00bet1/vc/comm/src/omxVCCOMM_SAD_16x.c
+1a8577646132ad9b63a1477fdaec2464  OX000-SW-98010-r0p0-00bet1/vc/comm/src/omxVCCOMM_Average_16x.c
+48529c4f70c7e954e832eece1aee57bd  OX000-SW-98010-r0p0-00bet1/vc/comm/src/omxVCCOMM_SAD_8x.c
+252977764d4f38282b6a56c59ccf4f09  OX000-SW-98010-r0p0-00bet1/vc/comm/src/armVCCOMM_SAD.c
+cc78cfaed9502c2e0282c91fb95eeac4  OX000-SW-98010-r0p0-00bet1/vc/comm/src/omxVCCOMM_Average_8x.c
+e468751c15a581ebd22da031e22117d1  OX000-SW-98010-r0p0-00bet1/vc/comm/src/omxVCCOMM_Copy16x16.c
+3f448d191eaeb82ecb7e27ef8ba27875  OX000-SW-98010-r0p0-00bet1/vc/comm/src/omxVCCOMM_ComputeTextureErrorBlock.c
+b1291c307808631fa833684abb9c34ce  ARM_DELIVERY_97412.TXT
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/api/armCOMM.h b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/api/armCOMM.h
new file mode 100644
index 0000000..2ed86a4
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/api/armCOMM.h
@@ -0,0 +1,785 @@
+/**
+ * 
+ * File Name:  armCOMM.h
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *   
+ * File: armCOMM.h
+ * Brief: Declares Common APIs/Data Types used across OpenMAX API's
+ *
+ */
+ 
+  
+#ifndef _armCommon_H_
+#define _armCommon_H_
+
+#include "omxtypes.h"
+
+typedef struct
+{
+  OMX_F32 Re; /** Real part */
+  OMX_F32 Im; /** Imaginary part */	
+        
+} OMX_FC32; /** single precision floating point complex number */
+
+typedef struct
+{
+  OMX_F64 Re; /** Real part */
+  OMX_F64 Im; /** Imaginary part */	
+        
+} OMX_FC64; /** double precision floating point complex number */
+
+
+/* Used by both IP and IC domains for 8x8 JPEG blocks. */
+typedef OMX_S16 ARM_BLOCK8x8[64];
+
+
+#include "armOMX.h"
+
+#define  armPI (OMX_F64)(3.1415926535897932384626433832795)
+
+/***********************************************************************/
+
+/* Compiler extensions */
+#ifdef ARM_DEBUG
+/* debug version */
+#include <stdlib.h>
+#include <assert.h>
+#include <stdio.h>
+#define armError(str) {printf((str)); printf("\n"); exit(-1);}
+#define armWarn(str) {printf((str)); printf("\n");}
+#define armIgnore(a) ((void)a)
+#define armAssert(a) assert(a)
+#else 
+/* release version */
+#define armError(str) ((void) (str))
+#define armWarn(str)  ((void) (str))
+#define armIgnore(a)  ((void) (a))
+#define armAssert(a)  ((void) (a))
+#endif /* ARM_DEBUG */
+
+/* Arithmetic operations */
+
+#define armMin(a,b)             ( (a) > (b) ?  (b):(a) )
+#define armMax(a,b)             ( (a) > (b) ?  (a):(b) )
+#define armAbs(a)               ( (a) <  0  ? -(a):(a) )
+
+/* Alignment operation */
+
+#define armAlignToBytes(Ptr,N)      (Ptr + ( ((N-(int)Ptr)&(N-1)) / sizeof(*Ptr) ))
+#define armAlignTo2Bytes(Ptr)       armAlignToBytes(Ptr,2)
+#define armAlignTo4Bytes(Ptr)       armAlignToBytes(Ptr,4)
+#define armAlignTo8Bytes(Ptr)       armAlignToBytes(Ptr,8)
+#define armAlignTo16Bytes(Ptr)      armAlignToBytes(Ptr,16)
+
+/* Error and Alignment check */
+
+#define armRetArgErrIf(condition, code)  if(condition) { return (code); }
+#define armRetDataErrIf(condition, code) if(condition) { return (code); }
+
+#ifndef ALIGNMENT_DOESNT_MATTER
+#define armIsByteAligned(Ptr,N)     ((((int)(Ptr)) % N)==0)
+#define armNotByteAligned(Ptr,N)    ((((int)(Ptr)) % N)!=0)
+#else
+#define armIsByteAligned(Ptr,N)     (1)
+#define armNotByteAligned(Ptr,N)    (0)
+#endif
+
+#define armIs2ByteAligned(Ptr)      armIsByteAligned(Ptr,2)
+#define armIs4ByteAligned(Ptr)      armIsByteAligned(Ptr,4)
+#define armIs8ByteAligned(Ptr)      armIsByteAligned(Ptr,8)
+#define armIs16ByteAligned(Ptr)     armIsByteAligned(Ptr,16)
+
+#define armNot2ByteAligned(Ptr)     armNotByteAligned(Ptr,2)
+#define armNot4ByteAligned(Ptr)     armNotByteAligned(Ptr,4)
+#define armNot8ByteAligned(Ptr)     armNotByteAligned(Ptr,8)
+#define armNot16ByteAligned(Ptr)    armNotByteAligned(Ptr,16)
+#define armNot32ByteAligned(Ptr)    armNotByteAligned(Ptr,32)
+
+/**
+ * Function: armRoundFloatToS16_ref/armRoundFloatToS32_ref/armRoundFloatToS64
+ *
+ * Description:
+ * Converts a double precision value into a short int/int after rounding
+ *
+ * Parameters:
+ * [in]  Value                 Float value to be converted
+ *
+ * Return Value:
+ * [out] converted value in OMX_S16/OMX_S32 format
+ *
+ */
+
+OMX_S16 armRoundFloatToS16 (OMX_F64 Value);
+OMX_S32 armRoundFloatToS32 (OMX_F64 Value);
+OMX_S64 armRoundFloatToS64 (OMX_F64 Value);
+
+/**
+ * Function: armSatRoundFloatToS16_ref/armSatRoundFloatToS32
+ *
+ * Description:
+ * Converts a double precision value into a short int/int after rounding and saturation
+ *
+ * Parameters:
+ * [in]  Value                 Float value to be converted
+ *
+ * Return Value:
+ * [out] converted value in OMX_S16/OMX_S32 format
+ *
+ */
+
+OMX_S16 armSatRoundFloatToS16 (OMX_F64 Value);
+OMX_S32 armSatRoundFloatToS32 (OMX_F64 Value);
+
+/**
+ * Function: armSatRoundFloatToU16_ref/armSatRoundFloatToU32
+ *
+ * Description:
+ * Converts a double precision value into a unsigned short int/int after rounding and saturation
+ *
+ * Parameters:
+ * [in]  Value                 Float value to be converted
+ *
+ * Return Value:
+ * [out] converted value in OMX_U16/OMX_U32 format
+ *
+ */
+
+OMX_U16 armSatRoundFloatToU16 (OMX_F64 Value);
+OMX_U32 armSatRoundFloatToU32 (OMX_F64 Value);
+
+/**
+ * Function: armSignCheck
+ *
+ * Description:
+ * Checks the sign of a variable:
+ * returns 1 if it is Positive
+ * returns 0 if it is 0
+ * returns -1 if it is Negative 
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	    var     Variable to be checked
+ *
+ * Return Value:
+ * OMX_INT --   returns 1 if it is Positive
+ *              returns 0 if it is 0
+ *              returns -1 if it is Negative 
+ */ 
+ 
+OMX_INT armSignCheck (OMX_S16 var);
+
+/**
+ * Function: armClip
+ *
+ * Description: Clips the input between MAX and MIN value
+ * 
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] Min     lower bound
+ * [in] Max     upper bound
+ * [in] src     variable to the clipped
+ *
+ * Return Value:
+ * OMX_S32 --   returns clipped value
+ */ 
+ 
+OMX_S32 armClip (
+        OMX_INT min,
+        OMX_INT max, 
+        OMX_S32 src
+        );
+
+/**
+ * Function: armClip_F32
+ *
+ * Description: Clips the input between MAX and MIN value
+ * 
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] Min     lower bound
+ * [in] Max     upper bound
+ * [in] src     variable to the clipped
+ *
+ * Return Value:
+ * OMX_F32 --   returns clipped value
+ */ 
+ 
+OMX_F32 armClip_F32 (
+        OMX_F32 min,
+        OMX_F32 max, 
+        OMX_F32 src
+        );
+
+/**
+ * Function: armShiftSat_F32
+ *
+ * Description: Divides a float value by 2^shift and 
+ * saturates it for unsigned value range for satBits.
+ * Second parameter is like "shifting" the corresponding 
+ * integer value. Takes care of rounding while clipping the final 
+ * value.
+ *
+ * Parameters:
+ * [in] v          Number to be operated upon
+ * [in] shift      Divides the input "v" by "2^shift"
+ * [in] satBits    Final range is [0, 2^satBits)
+ *
+ * Return Value:
+ * OMX_S32 --   returns "shifted" saturated value
+ */ 
+ 
+OMX_U32 armShiftSat_F32(
+        OMX_F32 v, 
+        OMX_INT shift, 
+        OMX_INT satBits
+        );
+
+/**
+ * Functions: armSwapElem
+ *
+ * Description:
+ * This function swaps two elements at the specified pointer locations.
+ * The size of each element could be anything as specified by <elemSize>
+ *
+ * Return Value:
+ * OMXResult -- Error status from the function
+ */
+OMXResult armSwapElem(OMX_U8 *pBuf1, OMX_U8 *pBuf2, OMX_INT elemSize);
+
+
+/**
+ * Function: armMedianOf3
+ *
+ * Description: Finds the median of three numbers
+ * 
+ * Remarks:
+ *
+ * Parameters:
+ * [in] fEntry     First entry
+ * [in] sEntry     second entry
+ * [in] tEntry     Third entry
+ *
+ * Return Value:
+ * OMX_S32 --   returns the median value
+ */ 
+ 
+OMX_S32 armMedianOf3 (
+    OMX_S32 fEntry,
+    OMX_S32 sEntry, 
+    OMX_S32 tEntry 
+    );
+
+/**
+ * Function: armLogSize
+ *
+ * Description: Finds the size of a positive value and returns the same
+ * 
+ * Remarks:
+ *
+ * Parameters:
+ * [in] value    Positive value
+ *
+ * Return Value:
+ * OMX_U8 --   returns the size of the positive value
+ */ 
+ 
+OMX_U8 armLogSize (
+    OMX_U16 value 
+    );    
+
+/***********************************************************************/
+                /* Saturating Arithmetic operations */
+
+/**
+ * Function :armSatAdd_S32()
+ *
+ * Description :
+ *   Returns the result of saturated addition of the two inputs Value1, Value2
+ *
+ * Parametrs:
+ * [in] Value1       First Operand
+ * [in] Value2       Second Operand
+ *
+ * Return:
+ * [out]             Result of operation
+ * 
+ *    
+ **/
+
+OMX_S32 armSatAdd_S32(
+                OMX_S32 Value1,
+                OMX_S32 Value2
+                );
+
+/**
+ * Function :armSatAdd_S64()
+ *
+ * Description :
+ *   Returns the result of saturated addition of the two inputs Value1, Value2
+ *
+ * Parametrs:
+ * [in] Value1       First Operand
+ * [in] Value2       Second Operand
+ *
+ * Return:
+ * [out]             Result of operation
+ * 
+ *    
+ **/
+
+OMX_S64 armSatAdd_S64(
+                OMX_S64 Value1,
+                OMX_S64 Value2
+                );
+
+/** Function :armSatSub_S32()
+ * 
+ * Description :
+ *     Returns the result of saturated substraction of the two inputs Value1, Value2
+ *
+ * Parametrs:
+ * [in] Value1       First Operand
+ * [in] Value2       Second Operand
+ *
+ * Return:
+ * [out]             Result of operation
+ * 
+ **/
+
+OMX_S32 armSatSub_S32(
+                    OMX_S32 Value1,
+                    OMX_S32 Value2
+                    );
+
+/**
+ * Function :armSatMac_S32()
+ *
+ * Description :
+ *     Returns the result of Multiplication of Value1 and Value2 and subesquent saturated
+ *     accumulation with Mac
+ *
+ * Parametrs:
+ * [in] Value1       First Operand
+ * [in] Value2       Second Operand
+ * [in] Mac          Accumulator
+ *
+ * Return:
+ * [out]             Result of operation
+ **/
+
+OMX_S32 armSatMac_S32(
+                    OMX_S32 Mac,
+                    OMX_S16 Value1,
+                    OMX_S16 Value2
+                    );
+
+/**
+ * Function :armSatMac_S16S32_S32
+ *
+ * Description :
+ *   Returns the result of saturated MAC operation of the three inputs delayElem, filTap , mac
+ *
+ *   mac = mac + Saturate_in_32Bits(delayElem * filTap)
+ *
+ * Parametrs:
+ * [in] delayElem    First 32 bit Operand
+ * [in] filTap       Second 16 bit Operand
+ * [in] mac          Result of MAC operation
+ *
+ * Return:
+ * [out]  mac        Result of operation
+ *    
+ **/
+ 
+OMX_S32 armSatMac_S16S32_S32(
+                        OMX_S32 mac, 
+                        OMX_S32 delayElem, 
+                        OMX_S16 filTap );
+
+/**
+ * Function :armSatRoundRightShift_S32_S16
+ *
+ * Description :
+ *   Returns the result of rounded right shift operation of input by the scalefactor
+ *
+ *   output = Saturate_in_16Bits( ( RightShift( (Round(input) , scaleFactor ) )
+ *
+ * Parametrs:
+ * [in] input       The input to be operated on
+ * [in] scaleFactor The shift number
+ *
+ * Return:
+ * [out]            Result of operation
+ *    
+ **/
+
+
+OMX_S16 armSatRoundRightShift_S32_S16(
+                        OMX_S32 input, 
+                        OMX_INT scaleFactor);
+
+/**
+ * Function :armSatRoundLeftShift_S32()
+ *
+ * Description :
+ *     Returns the result of saturating left-shift operation on input
+ *     Or rounded Right shift if the input Shift is negative.
+ *
+ * Parametrs:
+ * [in] Value        Operand
+ * [in] shift        Operand for shift operation
+ *
+ * Return:
+ * [out]             Result of operation
+ *    
+ **/
+ 
+OMX_S32 armSatRoundLeftShift_S32(
+                        OMX_S32 Value,
+                        OMX_INT shift
+                        );
+
+/**
+ * Function :armSatRoundLeftShift_S64()
+ *
+ * Description :
+ *     Returns the result of saturating left-shift operation on input
+ *     Or rounded Right shift if the input Shift is negative.
+ *
+ * Parametrs:
+ * [in] Value        Operand
+ * [in] shift        Operand for shift operation
+ *
+ * Return:
+ * [out]             Result of operation
+ *    
+ **/
+ 
+OMX_S64 armSatRoundLeftShift_S64(
+                        OMX_S64 Value,
+                        OMX_INT shift
+                        );
+
+/**
+ * Function :armSatMulS16S32_S32()
+ *
+ * Description :
+ *     Returns the result of a S16 data type multiplied with an S32 data type
+ *     in a S32 container
+ *
+ * Parametrs:
+ * [in] input1       Operand 1
+ * [in] input2       Operand 2
+ *
+ * Return:
+ * [out]             Result of operation
+ *    
+ **/
+
+
+OMX_S32 armSatMulS16S32_S32(
+                    OMX_S16 input1,
+                    OMX_S32 input2);
+
+/**
+ * Function :armSatMulS32S32_S32()
+ *
+ * Description :
+ *     Returns the result of a S32 data type multiplied with an S32 data type
+ *     in a S32 container
+ *
+ * Parametrs:
+ * [in] input1       Operand 1
+ * [in] input2       Operand 2
+ *
+ * Return:
+ * [out]             Result of operation
+ *    
+ **/
+
+OMX_S32 armSatMulS32S32_S32(
+                    OMX_S32 input1,
+                    OMX_S32 input2);
+
+
+/**
+ * Function :armIntDivAwayFromZero()
+ *
+ * Description : Integer division with rounding to the nearest integer. 
+ *               Half-integer values are rounded away from zero
+ *               unless otherwise specified. For example 3//2 is rounded 
+ *               to 2, and -3//2 is rounded to -2.
+ *
+ * Parametrs:
+ * [in] Num        Operand 1
+ * [in] Deno       Operand 2
+ *
+ * Return:
+ * [out]             Result of operation input1//input2
+ *    
+ **/
+
+OMX_S32 armIntDivAwayFromZero (OMX_S32 Num, OMX_S32 Deno);
+
+
+/***********************************************************************/
+/*
+ * Debugging macros
+ *
+ */
+
+
+/*
+ * Definition of output stream - change to stderr if necessary
+ */
+#define DEBUG_STREAM stdout
+
+/*
+ * Debug printf macros, one for each argument count.
+ * Add more if needed.
+ */
+#ifdef DEBUG_ON
+#include <stdio.h>
+
+#define DEBUG_PRINTF_0(a)                                               fprintf(DEBUG_STREAM, a)
+#define DEBUG_PRINTF_1(a, b)                                            fprintf(DEBUG_STREAM, a, b)
+#define DEBUG_PRINTF_2(a, b, c)                                         fprintf(DEBUG_STREAM, a, b, c)
+#define DEBUG_PRINTF_3(a, b, c, d)                                      fprintf(DEBUG_STREAM, a, b, c, d)
+#define DEBUG_PRINTF_4(a, b, c, d, e)                                   fprintf(DEBUG_STREAM, a, b, c, d, e)
+#define DEBUG_PRINTF_5(a, b, c, d, e, f)                                fprintf(DEBUG_STREAM, a, b, c, d, e, f)
+#define DEBUG_PRINTF_6(a, b, c, d, e, f, g)                             fprintf(DEBUG_STREAM, a, b, c, d, e, f, g)
+#define DEBUG_PRINTF_7(a, b, c, d, e, f, g, h)                          fprintf(DEBUG_STREAM, a, b, c, d, e, f, g, h)
+#define DEBUG_PRINTF_8(a, b, c, d, e, f, g, h, i)                       fprintf(DEBUG_STREAM, a, b, c, d, e, f, g, h, i)
+#define DEBUG_PRINTF_9(a, b, c, d, e, f, g, h, i, j)                    fprintf(DEBUG_STREAM, a, b, c, d, e, f, g, h, i, j)
+#define DEBUG_PRINTF_10(a, b, c, d, e, f, g, h, i, j, k)                fprintf(DEBUG_STREAM, a, b, c, d, e, f, g, h, i, j, k)
+#define DEBUG_PRINTF_11(a, b, c, d, e, f, g, h, i, j, k, l)             fprintf(DEBUG_STREAM, a, b, c, d, e, f, g, h, i, j, k, l)
+#define DEBUG_PRINTF_12(a, b, c, d, e, f, g, h, i, j, k, l, m)          fprintf(DEBUG_STREAM, a, b, c, d, e, f, g, h, i, j, k, l, m)
+#define DEBUG_PRINTF_13(a, b, c, d, e, f, g, h, i, j, k, l, m, n)       fprintf(DEBUG_STREAM, a, b, c, d, e, f, g, h, i, j, k, l, m, n)
+#define DEBUG_PRINTF_14(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)    fprintf(DEBUG_STREAM, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
+#else /* DEBUG_ON */
+#define DEBUG_PRINTF_0(a)                                  
+#define DEBUG_PRINTF_1(a, b)                               
+#define DEBUG_PRINTF_2(a, b, c)                            
+#define DEBUG_PRINTF_3(a, b, c, d)                         
+#define DEBUG_PRINTF_4(a, b, c, d, e)                      
+#define DEBUG_PRINTF_5(a, b, c, d, e, f)                   
+#define DEBUG_PRINTF_6(a, b, c, d, e, f, g)                
+#define DEBUG_PRINTF_7(a, b, c, d, e, f, g, h)             
+#define DEBUG_PRINTF_8(a, b, c, d, e, f, g, h, i)          
+#define DEBUG_PRINTF_9(a, b, c, d, e, f, g, h, i, j)       
+#define DEBUG_PRINTF_10(a, b, c, d, e, f, g, h, i, j, k)    
+#define DEBUG_PRINTF_11(a, b, c, d, e, f, g, h, i, j, k, l)             
+#define DEBUG_PRINTF_12(a, b, c, d, e, f, g, h, i, j, k, l, m)          
+#define DEBUG_PRINTF_13(a, b, c, d, e, f, g, h, i, j, k, l, m, n)      
+#define DEBUG_PRINTF_14(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)   
+#endif /* DEBUG_ON */
+
+
+/*
+ * Domain and sub domain definitions
+ *
+ * In order to turn on debug for an entire domain or sub-domain
+ * at compile time, one of the DEBUG_DOMAIN_* below may be defined,
+ * which will activate debug in all of the defines it contains.
+ */
+
+#ifdef DEBUG_DOMAIN_AC
+#define DEBUG_OMXACAAC_DECODECHANPAIRELT_MPEG4
+#define DEBUG_OMXACAAC_DECODECHANPAIRELT
+#define DEBUG_OMXACAAC_DECODEDATSTRELT
+#define DEBUG_OMXACAAC_DECODEFILLELT
+#define DEBUG_OMXACAAC_DECODEISSTEREO_S32
+#define DEBUG_OMXACAAC_DECODEMSPNS_S32
+#define DEBUG_OMXACAAC_DECODEMSSTEREO_S32_I
+#define DEBUG_OMXACAAC_DECODEPRGCFGELT
+#define DEBUG_OMXACAAC_DECODETNS_S32_I
+#define DEBUG_OMXACAAC_DEINTERLEAVESPECTRUM_S32
+#define DEBUG_OMXACAAC_ENCODETNS_S32_I
+#define DEBUG_OMXACAAC_LONGTERMPREDICT_S32
+#define DEBUG_OMXACAAC_LONGTERMRECONSTRUCT_S32
+#define DEBUG_OMXACAAC_MDCTFWD_S32
+#define DEBUG_OMXACAAC_MDCTINV_S32_S16
+#define DEBUG_OMXACAAC_NOISELESSDECODE
+#define DEBUG_OMXACAAC_QUANTINV_S32_I
+#define DEBUG_OMXACAAC_UNPACKADIFHEADER
+#define DEBUG_OMXACAAC_UNPACKADTSFRAMEHEADER
+#define DEBUG_OMXACMP3_HUFFMANDECODESFBMBP_S32
+#define DEBUG_OMXACMP3_HUFFMANDECODESFB_S32
+#define DEBUG_OMXACMP3_HUFFMANDECODE_S32
+#define DEBUG_OMXACMP3_MDCTINV_S32
+#define DEBUG_OMXACMP3_REQUANTIZESFB_S32_I
+#define DEBUG_OMXACMP3_REQUANTIZE_S32_I
+#define DEBUG_OMXACMP3_SYNTHPQMF_S32_S16
+#define DEBUG_OMXACMP3_UNPACKFRAMEHEADER
+#define DEBUG_OMXACMP3_UNPACKSCALEFACTORS_S8
+#define DEBUG_OMXACMP3_UNPACKSIDEINFO
+#endif /* DEBUG_DOMAIN_AC */
+
+
+#ifdef DEBUG_DOMAIN_VC
+#define DEBUG_OMXVCM4P10_AVERAGE_16X
+#define DEBUG_OMXVCM4P10_AVERAGE_4X
+#define DEBUG_OMXVCM4P10_AVERAGE_8X
+#define DEBUG_OMXVCM4P10_DEBLOCKCHROMA_U8_C1IR
+#define DEBUG_OMXVCM4P10_DEBLOCKLUMA_U8_C1IR
+#define DEBUG_OMXVCM4P10_DECODECHROMADCCOEFFSTOPAIRCAVLC_U8
+#define DEBUG_OMXVCM4P10_DECODECOEFFSTOPAIRCAVLC_U8
+#define DEBUG_OMXVCM4P10_DEQUANTTRANSFORMACFROMPAIR_U8_S16_C1_DLX
+#define DEBUG_OMXVCM4P10_EXPANDFRAME
+#define DEBUG_OMXVCM4P10_FILTERDEBLOCKINGCHROMA_HOREDGE_U8_C1IR
+#define DEBUG_OMXVCM4P10_FILTERDEBLOCKINGCHROMA_VEREDGE_U8_C1IR
+#define DEBUG_OMXVCM4P10_FILTERDEBLOCKINGLUMA_HOREDGE_U8_C1IR
+#define DEBUG_OMXVCM4P10_FILTERDEBLOCKINGLUMA_VEREDGE_U8_C1IR
+#define DEBUG_OMXVCM4P10_PREDICTINTRACHROMA8X8_U8_C1R
+#define DEBUG_OMXVCM4P10_PREDICTINTRA_16X16_U8_C1R
+#define DEBUG_OMXVCM4P10_PREDICTINTRA_4X4_U8_C1R
+#define DEBUG_OMXVCM4P10_SADQUAR_16X
+#define DEBUG_OMXVCM4P10_SADQUAR_4X
+#define DEBUG_OMXVCM4P10_SADQUAR_8X
+#define DEBUG_OMXVCM4P10_SAD_16X
+#define DEBUG_OMXVCM4P10_SAD_4X
+#define DEBUG_OMXVCM4P10_SAD_8X
+#define DEBUG_OMXVCM4P10_SATD_4X4
+#define DEBUG_OMXVCM4P10_TRANSFORMDEQUANTCHROMADCFROMPAIR_U8_S16_C1
+#define DEBUG_OMXVCM4P10_TRANSFORMDEQUANTLUMADCFROMPAIR_U8_S16_C1
+#define DEBUG_OMXVCM4P10_TRANSFORMQUANT_CHROMADC
+#define DEBUG_OMXVCM4P10_TRANSFORMQUANT_LUMADC
+#define DEBUG_OMXVCM4P2_BLOCKMATCH_HALF_16X16
+#define DEBUG_OMXVCM4P2_BLOCKMATCH_HALF_8X8
+#define DEBUG_OMXVCM4P2_BLOCKMATCH_INTEGER_16X16
+#define DEBUG_OMXVCM4P2_BLOCKMATCH_INTEGER_8X8
+#define DEBUG_OMXVCM4P2_COMPUTETEXTUREERRORBLOCK_SAD_U8_S16
+#define DEBUG_OMXVCM4P2_COMPUTETEXTUREERRORBLOCK_U8_S16
+#define DEBUG_OMXVCM4P2_DCT8X8BLKDLX
+#define DEBUG_OMXVCM4P2_DECODEBLOCKCOEF_INTER_S16
+#define DEBUG_OMXVCM4P2_DECODEPADMV_PVOP
+#define DEBUG_OMXVCM4P2_DECODEVLCZIGZAG_INTER_S16
+#define DEBUG_OMXVCM4P2_DECODEVLCZIGZAG_INTRAACVLC_S16
+#define DEBUG_OMXVCM4P2_DECODEVLCZIGZAG_INTRADCVLC_S16
+#define DEBUG_OMXVCM4P2_ENCODEMV_U8_S16
+#define DEBUG_OMXVCM4P2_ENCODEVLCZIGZAG_INTER_S16
+#define DEBUG_OMXVCM4P2_ENCODEVLCZIGZAG_INTRAACVLC_S16
+#define DEBUG_OMXVCM4P2_ENCODEVLCZIGZAG_INTRADCVLC_S16
+#define DEBUG_OMXVCM4P2_FINDMVPRED
+#define DEBUG_OMXVCM4P2_IDCT8X8BLKDLX
+#define DEBUG_OMXVCM4P2_LIMITMVTORECT
+#define DEBUG_OMXVCM4P2_MOTIONESTIMATIONMB
+#define DEBUG_OMXVCM4P2_PADMBGRAY_U8
+#define DEBUG_OMXVCM4P2_PADMBHORIZONTAL_U8
+#define DEBUG_OMXVCM4P2_PADMBVERTICAL_U8
+#define DEBUG_OMXVCM4P2_PADMV
+#define DEBUG_OMXVCM4P2_QUANTINTER_S16_I
+#define DEBUG_OMXVCM4P2_QUANTINTRA_S16_I
+#define DEBUG_OMXVCM4P2_QUANTINVINTER_S16_I
+#define DEBUG_OMXVCM4P2_QUANTINVINTRA_S16_I
+#define DEBUG_OMXVCM4P2_TRANSRECBLOCKCEOF_INTER
+#define DEBUG_OMXVCM4P2_TRANSRECBLOCKCEOF_INTRA
+#endif /* DEBUG_DOMAIN_VC */
+
+
+#ifdef DEBUG_DOMAIN_IC
+/* To be filled in */
+#endif /* DEBUG_DOMAIN_IC */
+
+
+#ifdef DEBUG_DOMAIN_SP
+#define DEBUG_OMXACSP_DOTPROD_S16
+#define DEBUG_OMXACSP_BLOCKEXP_S16
+#define DEBUG_OMXACSP_BLOCKEXP_S32
+#define DEBUG_OMXACSP_COPY_S16
+#define DEBUG_OMXACSP_DOTPROD_S16
+#define DEBUG_OMXACSP_DOTPROD_S16_SFS
+#define DEBUG_OMXACSP_FFTFWD_CTOC_SC16_SFS
+#define DEBUG_OMXACSP_FFTFWD_CTOC_SC32_SFS
+#define DEBUG_OMXACSP_FFTFWD_RTOCCS_S16S32_SFS
+#define DEBUG_OMXACSP_FFTFWD_RTOCCS_S32_SFS
+#define DEBUG_OMXACSP_FFTGETBUFSIZE_C_SC16
+#define DEBUG_OMXACSP_FFTGETBUFSIZE_C_SC32
+#define DEBUG_OMXACSP_FFTGETBUFSIZE_R_S16_S32
+#define DEBUG_OMXACSP_FFTGETBUFSIZE_R_S32
+#define DEBUG_OMXACSP_FFTINIT_C_SC16
+#define DEBUG_OMXACSP_FFTINIT_C_SC32
+#define DEBUG_OMXACSP_FFTINIT_R_S16_S32
+#define DEBUG_OMXACSP_FFTINIT_R_S32
+#define DEBUG_OMXACSP_FFTINV_CCSTOR_S32S16_SFS
+#define DEBUG_OMXACSP_FFTINV_CCSTOR_S32_SFS
+#define DEBUG_OMXACSP_FFTINV_CTOC_SC16_SFS
+#define DEBUG_OMXACSP_FFTINV_CTOC_SC32_SFS
+#define DEBUG_OMXACSP_FILTERMEDIAN_S32_I
+#define DEBUG_OMXACSP_FILTERMEDIAN_S32
+#define DEBUG_OMXACSP_FIRONE_DIRECT_S16_ISFS
+#define DEBUG_OMXACSP_FIRONE_DIRECT_S16_I
+#define DEBUG_OMXACSP_FIRONE_DIRECT_S16
+#define DEBUG_OMXACSP_FIRONE_DIRECT_S16_SFS
+#define DEBUG_OMXACSP_FIR_DIRECT_S16_ISFS
+#define DEBUG_OMXACSP_FIR_DIRECT_S16_I
+#define DEBUG_OMXACSP_FIR_DIRECT_S16
+#define DEBUG_OMXACSP_FIR_DIRECT_S16_SFS
+#define DEBUG_OMXACSP_IIRONE_BIQUADDIRECT_S16_I
+#define DEBUG_OMXACSP_IIRONE_BIQUADDIRECT_S16
+#define DEBUG_OMXACSP_IIRONE_DIRECT_S16_I
+#define DEBUG_OMXACSP_IIRONE_DIRECT_S16
+#define DEBUG_OMXACSP_IIR_BIQUADDIRECT_S16_I
+#define DEBUG_OMXACSP_IIR_BIQUADDIRECT_S16
+#define DEBUG_OMXACSP_IIR_DIRECT_S16_I
+#define DEBUG_OMXACSP_IIR_DIRECT_S16
+#endif /* DEBUG_DOMAIN_SP */
+
+
+#ifdef DEBUG_DOMAIN_IP
+#define DEBUG_OMXIPBM_ADDC_U8_C1R_SFS
+#define DEBUG_OMXIPBM_COPY_U8_C1R
+#define DEBUG_OMXIPBM_COPY_U8_C3R
+#define DEBUG_OMXIPBM_MIRROR_U8_C1R
+#define DEBUG_OMXIPBM_MULC_U8_C1R_SFS
+#define DEBUG_OMXIPCS_COLORTWISTQ14_U8_C3R
+#define DEBUG_OMXIPCS_RGB565TOYCBCR420LS_MCU_U16_S16_C3P3R
+#define DEBUG_OMXIPCS_RGB565TOYCBCR422LS_MCU_U16_S16_C3P3R
+#define DEBUG_OMXIPCS_RGB565TOYCBCR444LS_MCU_U16_S16_C3P3R
+#define DEBUG_OMXIPCS_RGBTOYCBCR420LS_MCU_U8_S16_C3P3R
+#define DEBUG_OMXIPCS_RGBTOYCBCR422LS_MCU_U8_S16_C3P3R
+#define DEBUG_OMXIPCS_RGBTOYCBCR444LS_MCU_U8_S16_C3P3R
+#define DEBUG_OMXIPCS_YCBCR420RSZROT_U8_P3R
+#define DEBUG_OMXIPCS_YCBCR420TORGB565LS_MCU_S16_U16_P3C3R
+#define DEBUG_OMXIPCS_YCBCR420TORGB565_U8_U16_P3C3R
+#define DEBUG_OMXIPCS_YCBCR420TORGBLS_MCU_S16_U8_P3C3R
+#define DEBUG_OMXIPCS_YCBCR422RSZCSCROTRGB_U8_C2R
+#define DEBUG_OMXIPCS_YCBCR422RSZROT_U8_P3R
+#define DEBUG_OMXIPCS_YCBCR422TORGB565LS_MCU_S16_U16_P3C3R
+#define DEBUG_OMXIPCS_YCBCR422TORGB565_U8_U16_C2C3R
+#define DEBUG_OMXIPCS_YCBCR422TORGBLS_MCU_S16_U8_P3C3R
+#define DEBUG_OMXIPCS_YCBCR422TORGB_U8_C2C3R
+#define DEBUG_OMXIPCS_YCBCR422TOYCBCR420ROTATE_U8_C2P3R
+#define DEBUG_OMXIPCS_YCBCR422TOYCBCR420ROTATE_U8_P3R
+#define DEBUG_OMXIPCS_YCBCR444TORGB565LS_MCU_S16_U16_P3C3R
+#define DEBUG_OMXIPCS_YCBCR444TORGBLS_MCU_S16_U8_P3C3R
+#define DEBUG_OMXIPCS_YCBCRTORGB565_U8_U16_C3R
+#define DEBUG_OMXIPCS_YCBCRTORGB565_U8_U16_P3C3R
+#define DEBUG_OMXIPCS_YCBCRTORGB_U8_C3R
+#define DEBUG_OMXIPPP_GETCENTRALMOMENT_S64
+#define DEBUG_OMXIPPP_GETSPATIALMOMENT_S64
+#define DEBUG_OMXIPPP_MOMENTGETSTATESIZE_S64
+#define DEBUG_OMXIPPP_MOMENTINIT_S64
+#define DEBUG_OMXIPPP_MOMENTS64S_U8_C1R
+#define DEBUG_OMXIPPP_MOMENTS64S_U8_C3R
+#endif /* DEBUG_DOMAIN_IP */
+
+
+#endif /* _armCommon_H_ */
+
+/*End of File*/
+
+
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/api/armCOMM_Bitstream.h b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/api/armCOMM_Bitstream.h
new file mode 100644
index 0000000..4f9bc3b
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/api/armCOMM_Bitstream.h
@@ -0,0 +1,212 @@
+/**
+ * 
+ * File Name:  armCOMM_Bitstream.h
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * File: armCOMM_Bitstream.h
+ * Brief: Declares common API's/Data types used across the OpenMax Encoders/Decoders.
+ *
+ */
+
+#ifndef _armCodec_H_
+#define _armCodec_H_
+
+#include "omxtypes.h"
+
+typedef struct {
+    OMX_U8   codeLen;
+    OMX_U32	 codeWord;
+} ARM_VLC32;
+
+/* The above should be renamed as "ARM_VLC32" */
+
+/**
+ * Function: armLookAheadBits()
+ *
+ * Description:
+ * Get the next N bits from the bitstream without advancing the bitstream pointer
+ *
+ * Parameters:
+ * [in]     **ppBitStream
+ * [in]     *pOffset
+ * [in]     N=1...32
+ *
+ * Returns  Value
+ */
+
+OMX_U32 armLookAheadBits(const OMX_U8 **ppBitStream, OMX_INT *pOffset, OMX_INT N);
+
+/**
+ * Function: armGetBits()
+ *
+ * Description:
+ * Read N bits from the bitstream
+ *    
+ * Parameters:
+ * [in]     *ppBitStream
+ * [in]     *pOffset
+ * [in]     N=1..32
+ *
+ * [out]    *ppBitStream
+ * [out]    *pOffset
+ * Returns  Value
+ */
+
+OMX_U32 armGetBits(const OMX_U8 **ppBitStream, OMX_INT *pOffset, OMX_INT N);
+
+/**
+ * Function: armByteAlign()
+ *
+ * Description:
+ * Align the pointer *ppBitStream to the next byte boundary
+ *
+ * Parameters:
+ * [in]     *ppBitStream
+ * [in]     *pOffset
+ *
+ * [out]    *ppBitStream
+ * [out]    *pOffset
+ *
+ **/
+ 
+OMXVoid armByteAlign(const OMX_U8 **ppBitStream,OMX_INT *pOffset);
+
+/** 
+ * Function: armSkipBits()
+ *
+ * Description:
+ * Skip N bits from the value at *ppBitStream
+ *
+ * Parameters:
+ * [in]     *ppBitStream
+ * [in]     *pOffset
+ * [in]     N
+ *
+ * [out]    *ppBitStream
+ * [out]    *pOffset
+ *
+ **/
+
+OMXVoid armSkipBits(const OMX_U8 **ppBitStream,OMX_INT *pOffset,OMX_INT N);
+
+/***************************************
+ * Variable bit length Decode
+ ***************************************/
+
+/**
+ * Function: armUnPackVLC32()
+ *
+ * Description:
+ * Variable length decode of variable length symbol (max size 32 bits) read from
+ * the bit stream pointed by *ppBitStream at *pOffset by using the table
+ * pointed by pCodeBook
+ * 
+ * Parameters:
+ * [in]     **ppBitStream
+ * [in]     *pOffset
+ * [in]     pCodeBook
+ * 
+ * [out]    **ppBitStream
+ * [out]    *pOffset
+ *
+ * Returns : Code Book Index if successfull. 
+ *         : "ARM_NO_CODEBOOK_INDEX = 0xFFFF" if search fails.
+ **/
+
+#define ARM_NO_CODEBOOK_INDEX (OMX_U16)(0xFFFF)
+
+OMX_U16 armUnPackVLC32(
+    const OMX_U8 **ppBitStream,
+    OMX_INT *pOffset,
+    const ARM_VLC32 *pCodeBook
+);
+
+/***************************************
+ * Fixed bit length Encode
+ ***************************************/
+
+/**
+ * Function: armPackBits
+ *
+ * Description:
+ * Pack a VLC code word into the bitstream
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	ppBitStream		pointer to the pointer to the current byte 
+ *                      in the bit stream.
+ * [in]	pOffset	        pointer to the bit position in the byte 
+ *                      pointed by *ppBitStream. Valid within 0
+ *                      to 7.
+ * [in]	codeWord		Code word that need to be inserted in to the
+ *                          bitstream
+ * [in]	codeLength		Length of the code word valid range 1...32
+ *
+ * [out] ppBitStream	*ppBitStream is updated after the block is encoded,
+ *	                        so that it points to the current byte in the bit
+ *							stream buffer.
+ * [out] pBitOffset		*pBitOffset is updated so that it points to the
+ *							current bit position in the byte pointed by
+ *							*ppBitStream.
+ *
+ * Return Value:
+ * Standard OMX_RESULT result. See enumeration for possible result codes.
+ *
+ */
+ 
+OMXResult armPackBits (
+    OMX_U8  **ppBitStream, 
+    OMX_INT *pOffset,
+    OMX_U32 codeWord, 
+    OMX_INT codeLength 
+);
+ 
+/***************************************
+ * Variable bit length Encode
+ ***************************************/
+
+/**
+ * Function: armPackVLC32
+ *
+ * Description:
+ * Pack a VLC code word into the bitstream
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	ppBitStream		pointer to the pointer to the current byte 
+ *                      in the bit stream.
+ * [in]	pBitOffset	    pointer to the bit position in the byte 
+ *                      pointed by *ppBitStream. Valid within 0
+ *                      to 7.
+ * [in]	 code     		VLC code word that need to be inserted in to the
+ *                      bitstream
+ *
+ * [out] ppBitStream	*ppBitStream is updated after the block is encoded,
+ *	                    so that it points to the current byte in the bit
+ *						stream buffer.
+ * [out] pBitOffset		*pBitOffset is updated so that it points to the
+ *						current bit position in the byte pointed by
+ *						*ppBitStream.
+ *
+ * Return Value:
+ * Standard OMX_RESULT result. See enumeration for possible result codes.
+ *
+ */
+ 
+OMXResult armPackVLC32 (
+    OMX_U8 **ppBitStream, 
+    OMX_INT *pBitOffset,
+    ARM_VLC32 code 
+);
+
+#endif      /*_armCodec_H_*/
+
+/*End of File*/
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/api/armCOMM_Version.h b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/api/armCOMM_Version.h
new file mode 100644
index 0000000..e99a450
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/api/armCOMM_Version.h
@@ -0,0 +1,43 @@
+/* Guard the header against multiple inclusion. */
+#ifndef __ARM_COMM_VERSION_H__
+#define __ARM_COMM_VERSION_H__
+
+
+/* The following line should be in omxtypes.h but hasn't been approved by OpenMAX yet */
+#define OMX_VERSION 102
+
+/* We need to define these macros in order to convert a #define number into a #define string. */
+#define ARM_QUOTE(a) #a
+#define ARM_INDIRECT(A) ARM_QUOTE(A)
+
+/* Convert the OMX_VERSION number into a string that can be used, for example, to print it out. */
+#define ARM_VERSION_STRING ARM_INDIRECT(OMX_VERSION)
+
+
+/* Define this in order to turn on ARM version/release/build strings in each domain */
+#define ARM_INCLUDE_VERSION_DESCRIPTIONS
+
+#ifdef ARM_INCLUDE_VERSION_DESCRIPTIONS
+  extern const char * const omxAC_VersionDescription;
+  extern const char * const omxIC_VersionDescription;
+  extern const char * const omxIP_VersionDescription;
+  extern const char * const omxSP_VersionDescription;
+  extern const char * const omxVC_VersionDescription;
+#endif /* ARM_INCLUDE_VERSION_DESCRIPTIONS */
+
+
+/* The following entries should be automatically updated by the release script */
+/* They are used in the ARM version strings defined for each domain.             */
+
+/* The release tag associated with this release of the library. - used for source and object releases */
+#define OMX_ARM_RELEASE_TAG  "r0p0-00bet1"
+
+/* The ARM architecture used to build any objects or executables in this release. */
+#define OMX_ARM_BUILD_ARCHITECTURE "ANSI C"
+
+/* The ARM Toolchain used to build any objects or executables in this release. */
+#define OMX_ARM_BUILD_TOOLCHAIN    "ARM RVCT 3.1"
+
+
+#endif /* __ARM_COMM_VERSION_H__ */
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/api/armOMX.h b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/api/armOMX.h
new file mode 100644
index 0000000..f629f72
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/api/armOMX.h
@@ -0,0 +1,274 @@
+/* 
+ * 
+ * File Name:  armOMX_ReleaseVersion.h
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * This file allows a version of the OMX DL libraries to be built where some or
+ * all of the function names can be given a user specified suffix. 
+ *
+ * You might want to use it where:
+ *
+ * - you want to rename a function "out of the way" so that you could replace
+ *   a function with a different version (the original version would still be
+ *   in the library just with a different name - so you could debug the new
+ *   version by comparing it to the output of the old)
+ *
+ * - you want to rename all the functions to versions with a suffix so that 
+ *   you can include two versions of the library and choose between functions
+ *   at runtime.
+ *
+ *     e.g. omxIPBM_Copy_U8_C1R could be renamed omxIPBM_Copy_U8_C1R_CortexA8
+ * 
+ */
+
+  
+#ifndef _armOMX_H_
+#define _armOMX_H_
+
+
+/* We need to define these two macros in order to expand and concatenate the names */
+#define OMXCAT2BAR(A, B) omx ## A ## B
+#define OMXCATBAR(A, B) OMXCAT2BAR(A, B)
+
+/* Define the suffix to add to all functions - the default is no suffix */
+#define BARE_SUFFIX 
+
+
+
+/* Define what happens to the bare suffix-less functions, down to the sub-domain accuracy */
+#define OMXACAAC_SUFFIX    BARE_SUFFIX   
+#define OMXACMP3_SUFFIX    BARE_SUFFIX
+#define OMXICJP_SUFFIX     BARE_SUFFIX
+#define OMXIPBM_SUFFIX     BARE_SUFFIX
+#define OMXIPCS_SUFFIX     BARE_SUFFIX
+#define OMXIPPP_SUFFIX     BARE_SUFFIX
+#define OMXSP_SUFFIX       BARE_SUFFIX
+#define OMXVCCOMM_SUFFIX   BARE_SUFFIX
+#define OMXVCM4P10_SUFFIX  BARE_SUFFIX
+#define OMXVCM4P2_SUFFIX   BARE_SUFFIX
+
+
+
+
+/* Define what the each bare, un-suffixed OpenMAX API function names is to be renamed */
+#define omxACAAC_DecodeChanPairElt                        OMXCATBAR(ACAAC_DecodeChanPairElt, OMXACAAC_SUFFIX)
+#define omxACAAC_DecodeDatStrElt                          OMXCATBAR(ACAAC_DecodeDatStrElt, OMXACAAC_SUFFIX)
+#define omxACAAC_DecodeFillElt                            OMXCATBAR(ACAAC_DecodeFillElt, OMXACAAC_SUFFIX)
+#define omxACAAC_DecodeIsStereo_S32                       OMXCATBAR(ACAAC_DecodeIsStereo_S32, OMXACAAC_SUFFIX)
+#define omxACAAC_DecodeMsPNS_S32_I                        OMXCATBAR(ACAAC_DecodeMsPNS_S32_I, OMXACAAC_SUFFIX)
+#define omxACAAC_DecodeMsStereo_S32_I                     OMXCATBAR(ACAAC_DecodeMsStereo_S32_I, OMXACAAC_SUFFIX)
+#define omxACAAC_DecodePrgCfgElt                          OMXCATBAR(ACAAC_DecodePrgCfgElt, OMXACAAC_SUFFIX)
+#define omxACAAC_DecodeTNS_S32_I                          OMXCATBAR(ACAAC_DecodeTNS_S32_I, OMXACAAC_SUFFIX)
+#define omxACAAC_DeinterleaveSpectrum_S32                 OMXCATBAR(ACAAC_DeinterleaveSpectrum_S32, OMXACAAC_SUFFIX)
+#define omxACAAC_EncodeTNS_S32_I                          OMXCATBAR(ACAAC_EncodeTNS_S32_I, OMXACAAC_SUFFIX)
+#define omxACAAC_LongTermPredict_S32                      OMXCATBAR(ACAAC_LongTermPredict_S32, OMXACAAC_SUFFIX)
+#define omxACAAC_LongTermReconstruct_S32_I                OMXCATBAR(ACAAC_LongTermReconstruct_S32_I, OMXACAAC_SUFFIX)
+#define omxACAAC_MDCTFwd_S32                              OMXCATBAR(ACAAC_MDCTFwd_S32, OMXACAAC_SUFFIX)
+#define omxACAAC_MDCTInv_S32_S16                          OMXCATBAR(ACAAC_MDCTInv_S32_S16, OMXACAAC_SUFFIX)
+#define omxACAAC_NoiselessDecode                          OMXCATBAR(ACAAC_NoiselessDecode, OMXACAAC_SUFFIX)
+#define omxACAAC_QuantInv_S32_I                           OMXCATBAR(ACAAC_QuantInv_S32_I, OMXACAAC_SUFFIX)
+#define omxACAAC_UnpackADIFHeader                         OMXCATBAR(ACAAC_UnpackADIFHeader, OMXACAAC_SUFFIX)
+#define omxACAAC_UnpackADTSFrameHeader                    OMXCATBAR(ACAAC_UnpackADTSFrameHeader, OMXACAAC_SUFFIX)
+
+
+#define omxACMP3_HuffmanDecode_S32                        OMXCATBAR(ACMP3_HuffmanDecode_S32, OMXACMP3_SUFFIX)
+#define omxACMP3_HuffmanDecodeSfb_S32                     OMXCATBAR(ACMP3_HuffmanDecodeSfb_S32, OMXACMP3_SUFFIX)
+#define omxACMP3_HuffmanDecodeSfbMbp_S32                  OMXCATBAR(ACMP3_HuffmanDecodeSfbMbp_S32, OMXACMP3_SUFFIX)
+#define omxACMP3_MDCTInv_S32                              OMXCATBAR(ACMP3_MDCTInv_S32, OMXACMP3_SUFFIX)
+#define omxACMP3_ReQuantize_S32_I                         OMXCATBAR(ACMP3_ReQuantize_S32_I, OMXACMP3_SUFFIX)
+#define omxACMP3_ReQuantizeSfb_S32_I                      OMXCATBAR(ACMP3_ReQuantizeSfb_S32_I, OMXACMP3_SUFFIX)
+#define omxACMP3_SynthPQMF_S32_S16                        OMXCATBAR(ACMP3_SynthPQMF_S32_S16, OMXACMP3_SUFFIX)
+#define omxACMP3_UnpackFrameHeader                        OMXCATBAR(ACMP3_UnpackFrameHeader, OMXACMP3_SUFFIX)
+#define omxACMP3_UnpackScaleFactors_S8                    OMXCATBAR(ACMP3_UnpackScaleFactors_S8, OMXACMP3_SUFFIX)
+#define omxACMP3_UnpackSideInfo                           OMXCATBAR(ACMP3_UnpackSideInfo, OMXACMP3_SUFFIX)
+
+#define omxICJP_CopyExpand_U8_C3                          OMXCATBAR(ICJP_CopyExpand_U8_C3, OMXICJP_SUFFIX)
+#define omxICJP_DCTFwd_S16                                OMXCATBAR(ICJP_DCTFwd_S16, OMXICJP_SUFFIX)
+#define omxICJP_DCTFwd_S16_I                              OMXCATBAR(ICJP_DCTFwd_S16_I, OMXICJP_SUFFIX)
+#define omxICJP_DCTInv_S16                                OMXCATBAR(ICJP_DCTInv_S16, OMXICJP_SUFFIX)
+#define omxICJP_DCTInv_S16_I                              OMXCATBAR(ICJP_DCTInv_S16_I, OMXICJP_SUFFIX)
+#define omxICJP_DCTQuantFwd_Multiple_S16                  OMXCATBAR(ICJP_DCTQuantFwd_Multiple_S16, OMXICJP_SUFFIX)
+#define omxICJP_DCTQuantFwd_S16                           OMXCATBAR(ICJP_DCTQuantFwd_S16, OMXICJP_SUFFIX)
+#define omxICJP_DCTQuantFwd_S16_I                         OMXCATBAR(ICJP_DCTQuantFwd_S16_I, OMXICJP_SUFFIX)
+#define omxICJP_DCTQuantFwdTableInit                      OMXCATBAR(ICJP_DCTQuantFwdTableInit, OMXICJP_SUFFIX)
+#define omxICJP_DCTQuantInv_Multiple_S16                  OMXCATBAR(ICJP_DCTQuantInv_Multiple_S16, OMXICJP_SUFFIX)
+#define omxICJP_DCTQuantInv_S16                           OMXCATBAR(ICJP_DCTQuantInv_S16, OMXICJP_SUFFIX)
+#define omxICJP_DCTQuantInv_S16_I                         OMXCATBAR(ICJP_DCTQuantInv_S16_I, OMXICJP_SUFFIX)
+#define omxICJP_DCTQuantInvTableInit                      OMXCATBAR(ICJP_DCTQuantInvTableInit, OMXICJP_SUFFIX)
+#define omxICJP_DecodeHuffman8x8_Direct_S16_C1            OMXCATBAR(ICJP_DecodeHuffman8x8_Direct_S16_C1, OMXICJP_SUFFIX)
+#define omxICJP_DecodeHuffmanSpecGetBufSize_U8            OMXCATBAR(ICJP_DecodeHuffmanSpecGetBufSize_U8, OMXICJP_SUFFIX)
+#define omxICJP_DecodeHuffmanSpecInit_U8                  OMXCATBAR(ICJP_DecodeHuffmanSpecInit_U8, OMXICJP_SUFFIX)
+#define omxICJP_EncodeHuffman8x8_Direct_S16_U1_C1         OMXCATBAR(ICJP_EncodeHuffman8x8_Direct_S16_U1_C1, OMXICJP_SUFFIX)
+#define omxICJP_EncodeHuffmanSpecGetBufSize_U8            OMXCATBAR(ICJP_EncodeHuffmanSpecGetBufSize_U8, OMXICJP_SUFFIX)
+#define omxICJP_EncodeHuffmanSpecInit_U8                  OMXCATBAR(ICJP_EncodeHuffmanSpecInit_U8, OMXICJP_SUFFIX)
+
+#define omxIPBM_AddC_U8_C1R_Sfs                           OMXCATBAR(IPBM_AddC_U8_C1R_Sfs, OMXIPBM_SUFFIX)
+#define omxIPBM_Copy_U8_C1R                               OMXCATBAR(IPBM_Copy_U8_C1R, OMXIPBM_SUFFIX)
+#define omxIPBM_Copy_U8_C3R                               OMXCATBAR(IPBM_Copy_U8_C3R, OMXIPBM_SUFFIX)
+#define omxIPBM_Mirror_U8_C1R                             OMXCATBAR(IPBM_Mirror_U8_C1R, OMXIPBM_SUFFIX)
+#define omxIPBM_MulC_U8_C1R_Sfs                           OMXCATBAR(IPBM_MulC_U8_C1R_Sfs, OMXIPBM_SUFFIX)
+
+#define omxIPCS_ColorTwistQ14_U8_C3R                      OMXCATBAR(IPCS_ColorTwistQ14_U8_C3R, OMXIPCS_SUFFIX)
+#define omxIPCS_BGR565ToYCbCr420LS_MCU_U16_S16_C3P3R      OMXCATBAR(IPCS_BGR565ToYCbCr420LS_MCU_U16_S16_C3P3R, OMXIPCS_SUFFIX)
+#define omxIPCS_BGR565ToYCbCr422LS_MCU_U16_S16_C3P3R      OMXCATBAR(IPCS_BGR565ToYCbCr422LS_MCU_U16_S16_C3P3R, OMXIPCS_SUFFIX)
+#define omxIPCS_BGR565ToYCbCr444LS_MCU_U16_S16_C3P3R      OMXCATBAR(IPCS_BGR565ToYCbCr444LS_MCU_U16_S16_C3P3R, OMXIPCS_SUFFIX)
+#define omxIPCS_BGR888ToYCbCr420LS_MCU_U8_S16_C3P3R       OMXCATBAR(IPCS_BGR888ToYCbCr420LS_MCU_U8_S16_C3P3R, OMXIPCS_SUFFIX)
+#define omxIPCS_BGR888ToYCbCr422LS_MCU_U8_S16_C3P3R       OMXCATBAR(IPCS_BGR888ToYCbCr422LS_MCU_U8_S16_C3P3R, OMXIPCS_SUFFIX)
+#define omxIPCS_BGR888ToYCbCr444LS_MCU_U8_S16_C3P3R       OMXCATBAR(IPCS_BGR888ToYCbCr444LS_MCU_U8_S16_C3P3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr420RszCscRotBGR_U8_P3C3R             OMXCATBAR(IPCS_YCbCr420RszCscRotBGR_U8_P3C3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr420RszRot_U8_P3R                     OMXCATBAR(IPCS_YCbCr420RszRot_U8_P3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr420ToBGR565_U8_U16_P3C3R             OMXCATBAR(IPCS_YCbCr420ToBGR565_U8_U16_P3C3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr420ToBGR565LS_MCU_S16_U16_P3C3R      OMXCATBAR(IPCS_YCbCr420ToBGR565LS_MCU_S16_U16_P3C3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr420ToBGR888LS_MCU_S16_U8_P3C3R       OMXCATBAR(IPCS_YCbCr420ToBGR888LS_MCU_S16_U8_P3C3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr422RszCscRotBGR_U8_P3C3R             OMXCATBAR(IPCS_YCbCr422RszCscRotBGR_U8_P3C3R, OMXIPCS_SUFFIX)
+#define omxIPCS_CbYCrY422RszCscRotBGR_U8_U16_C2R          OMXCATBAR(IPCS_CbYCrY422RszCscRotBGR_U8_U16_C2R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr422RszRot_U8_P3R                     OMXCATBAR(IPCS_YCbCr422RszRot_U8_P3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbYCr422ToBGR565_U8_U16_C2C3R            OMXCATBAR(IPCS_YCbYCr422ToBGR565_U8_U16_C2C3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr422ToBGR565LS_MCU_S16_U16_P3C3R      OMXCATBAR(IPCS_YCbCr422ToBGR565LS_MCU_S16_U16_P3C3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbYCr422ToBGR888_U8_C2C3R                OMXCATBAR(IPCS_YCbYCr422ToBGR888_U8_C2C3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr422ToBGR888LS_MCU_S16_U8_P3C3R       OMXCATBAR(IPCS_YCbCr422ToBGR888LS_MCU_S16_U8_P3C3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr422ToBGR888LS_MCU_S16_U8_P3C3R       OMXCATBAR(IPCS_YCbCr422ToBGR888LS_MCU_S16_U8_P3C3R, OMXIPCS_SUFFIX)
+#define omxIPCS_CbYCrY422ToYCbCr420Rotate_U8_C2P3R        OMXCATBAR(IPCS_CbYCrY422ToYCbCr420Rotate_U8_C2P3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr422ToYCbCr420Rotate_U8_P3R           OMXCATBAR(IPCS_YCbCr422ToYCbCr420Rotate_U8_P3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr444ToBGR565_U8_U16_C3R               OMXCATBAR(IPCS_YCbCr444ToBGR565_U8_U16_C3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr444ToBGR565_U8_U16_P3C3R             OMXCATBAR(IPCS_YCbCr444ToBGR565_U8_U16_P3C3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr444ToBGR565LS_MCU_S16_U16_P3C3R      OMXCATBAR(IPCS_YCbCr444ToBGR565LS_MCU_S16_U16_P3C3R, OMXIPCS_SUFFIX)
+#define omxIPCS_YCbCr444ToBGR888_U8_C3R                   OMXCATBAR(IPCS_YCbCr444ToBGR888_U8_C3R, OMXIPCS_SUFFIX)
+
+#define omxIPPP_Deblock_HorEdge_U8_I                      OMXCATBAR(IPPP_Deblock_HorEdge_U8_I, OMXIPPP_SUFFIX)
+#define omxIPPP_Deblock_VerEdge_U8_I                      OMXCATBAR(IPPP_Deblock_VerEdge_U8_I, OMXIPPP_SUFFIX)
+#define omxIPPP_FilterFIR_U8_C1R                          OMXCATBAR(IPPP_FilterFIR_U8_C1R, OMXIPPP_SUFFIX)
+#define omxIPPP_FilterMedian_U8_C1R                       OMXCATBAR(IPPP_FilterMedian_U8_C1R, OMXIPPP_SUFFIX)
+#define omxIPPP_GetCentralMoment_S64                      OMXCATBAR(IPPP_GetCentralMoment_S64, OMXIPPP_SUFFIX)
+#define omxIPPP_GetSpatialMoment_S64                      OMXCATBAR(IPPP_GetSpatialMoment_S64, OMXIPPP_SUFFIX)
+#define omxIPPP_MomentGetStateSize                        OMXCATBAR(IPPP_MomentGetStateSize, OMXIPPP_SUFFIX)
+#define omxIPPP_MomentInit                                OMXCATBAR(IPPP_MomentInit, OMXIPPP_SUFFIX)
+#define omxIPPP_Moments_U8_C1R                            OMXCATBAR(IPPP_Moments_U8_C1R, OMXIPPP_SUFFIX)
+#define omxIPPP_Moments_U8_C3R                            OMXCATBAR(IPPP_Moments_U8_C3R, OMXIPPP_SUFFIX)
+
+#define omxSP_BlockExp_S16                                OMXCATBAR(SP_BlockExp_S16, OMXSP_SUFFIX)
+#define omxSP_BlockExp_S32                                OMXCATBAR(SP_BlockExp_S32, OMXSP_SUFFIX)
+#define omxSP_Copy_S16                                    OMXCATBAR(SP_Copy_S16, OMXSP_SUFFIX)
+#define omxSP_DotProd_S16                                 OMXCATBAR(SP_DotProd_S16, OMXSP_SUFFIX)
+#define omxSP_DotProd_S16_Sfs                             OMXCATBAR(SP_DotProd_S16_Sfs, OMXSP_SUFFIX)
+#define omxSP_FFTFwd_CToC_SC16_Sfs                        OMXCATBAR(SP_FFTFwd_CToC_SC16_Sfs, OMXSP_SUFFIX)
+#define omxSP_FFTFwd_CToC_SC32_Sfs                        OMXCATBAR(SP_FFTFwd_CToC_SC32_Sfs, OMXSP_SUFFIX)
+#define omxSP_FFTFwd_RToCCS_S16S32_Sfs                    OMXCATBAR(SP_FFTFwd_RToCCS_S16S32_Sfs, OMXSP_SUFFIX)
+#define omxSP_FFTFwd_RToCCS_S32_Sfs                       OMXCATBAR(SP_FFTFwd_RToCCS_S32_Sfs, OMXSP_SUFFIX)
+#define omxSP_FFTGetBufSize_C_SC16                        OMXCATBAR(SP_FFTGetBufSize_C_SC16, OMXSP_SUFFIX)
+#define omxSP_FFTGetBufSize_C_SC32                        OMXCATBAR(SP_FFTGetBufSize_C_SC32, OMXSP_SUFFIX)
+#define omxSP_FFTGetBufSize_R_S16S32                      OMXCATBAR(SP_FFTGetBufSize_R_S16S32, OMXSP_SUFFIX)
+#define omxSP_FFTGetBufSize_R_S32                         OMXCATBAR(SP_FFTGetBufSize_R_S32, OMXSP_SUFFIX)
+#define omxSP_FFTInit_C_SC16                              OMXCATBAR(SP_FFTInit_C_SC16, OMXSP_SUFFIX)
+#define omxSP_FFTInit_C_SC32                              OMXCATBAR(SP_FFTInit_C_SC32, OMXSP_SUFFIX)
+#define omxSP_FFTInit_R_S16S32                            OMXCATBAR(SP_FFTInit_R_S16S32, OMXSP_SUFFIX)
+#define omxSP_FFTInit_R_S32                               OMXCATBAR(SP_FFTInit_R_S32, OMXSP_SUFFIX)
+#define omxSP_FFTInv_CCSToR_S32_Sfs                       OMXCATBAR(SP_FFTInv_CCSToR_S32_Sfs, OMXSP_SUFFIX)
+#define omxSP_FFTInv_CCSToR_S32S16_Sfs                    OMXCATBAR(SP_FFTInv_CCSToR_S32S16_Sfs, OMXSP_SUFFIX)
+#define omxSP_FFTInv_CToC_SC16_Sfs                        OMXCATBAR(SP_FFTInv_CToC_SC16_Sfs, OMXSP_SUFFIX)
+#define omxSP_FFTInv_CToC_SC32_Sfs                        OMXCATBAR(SP_FFTInv_CToC_SC32_Sfs, OMXSP_SUFFIX)
+#define omxSP_FilterMedian_S32                            OMXCATBAR(SP_FilterMedian_S32, OMXSP_SUFFIX)
+#define omxSP_FilterMedian_S32_I                          OMXCATBAR(SP_FilterMedian_S32_I, OMXSP_SUFFIX)
+#define omxSP_FIR_Direct_S16                              OMXCATBAR(SP_FIR_Direct_S16, OMXSP_SUFFIX)
+#define omxSP_FIR_Direct_S16_I                            OMXCATBAR(SP_FIR_Direct_S16_I, OMXSP_SUFFIX)
+#define omxSP_FIR_Direct_S16_ISfs                         OMXCATBAR(SP_FIR_Direct_S16_ISfs, OMXSP_SUFFIX)
+#define omxSP_FIR_Direct_S16_Sfs                          OMXCATBAR(SP_FIR_Direct_S16_Sfs, OMXSP_SUFFIX)
+#define omxSP_FIROne_Direct_S16                           OMXCATBAR(SP_FIROne_Direct_S16, OMXSP_SUFFIX)
+#define omxSP_FIROne_Direct_S16_I                         OMXCATBAR(SP_FIROne_Direct_S16_I, OMXSP_SUFFIX)
+#define omxSP_FIROne_Direct_S16_ISfs                      OMXCATBAR(SP_FIROne_Direct_S16_ISfs, OMXSP_SUFFIX)
+#define omxSP_FIROne_Direct_S16_Sfs                       OMXCATBAR(SP_FIROne_Direct_S16_Sfs, OMXSP_SUFFIX)
+#define omxSP_IIR_BiQuadDirect_S16                        OMXCATBAR(SP_IIR_BiQuadDirect_S16, OMXSP_SUFFIX)
+#define omxSP_IIR_BiQuadDirect_S16_I                      OMXCATBAR(SP_IIR_BiQuadDirect_S16_I, OMXSP_SUFFIX)
+#define omxSP_IIR_Direct_S16                              OMXCATBAR(SP_IIR_Direct_S16, OMXSP_SUFFIX)
+#define omxSP_IIR_Direct_S16_I                            OMXCATBAR(SP_IIR_Direct_S16_I, OMXSP_SUFFIX)
+#define omxSP_IIROne_BiQuadDirect_S16                     OMXCATBAR(SP_IIROne_BiQuadDirect_S16, OMXSP_SUFFIX)
+#define omxSP_IIROne_BiQuadDirect_S16_I                   OMXCATBAR(SP_IIROne_BiQuadDirect_S16_I, OMXSP_SUFFIX)
+#define omxSP_IIROne_Direct_S16                           OMXCATBAR(SP_IIROne_Direct_S16, OMXSP_SUFFIX)
+#define omxSP_IIROne_Direct_S16_I                         OMXCATBAR(SP_IIROne_Direct_S16_I, OMXSP_SUFFIX)
+
+#define omxVCCOMM_Average_16x                             OMXCATBAR(VCCOMM_Average_16x, OMXVCCOMM_SUFFIX)
+#define omxVCCOMM_Average_8x                              OMXCATBAR(VCCOMM_Average_8x, OMXVCCOMM_SUFFIX)
+#define omxVCCOMM_ComputeTextureErrorBlock                OMXCATBAR(VCCOMM_ComputeTextureErrorBlock, OMXVCCOMM_SUFFIX)
+#define omxVCCOMM_ComputeTextureErrorBlock_SAD            OMXCATBAR(VCCOMM_ComputeTextureErrorBlock_SAD, OMXVCCOMM_SUFFIX)
+#define omxVCCOMM_Copy16x16                               OMXCATBAR(VCCOMM_Copy16x16, OMXVCCOMM_SUFFIX)
+#define omxVCCOMM_Copy8x8                                 OMXCATBAR(VCCOMM_Copy8x8, OMXVCCOMM_SUFFIX)
+#define omxVCCOMM_ExpandFrame_I                           OMXCATBAR(VCCOMM_ExpandFrame_I, OMXVCCOMM_SUFFIX)
+#define omxVCCOMM_LimitMVToRect                           OMXCATBAR(VCCOMM_LimitMVToRect, OMXVCCOMM_SUFFIX)
+#define omxVCCOMM_SAD_16x                                 OMXCATBAR(VCCOMM_SAD_16x, OMXVCCOMM_SUFFIX)
+#define omxVCCOMM_SAD_8x                                  OMXCATBAR(VCCOMM_SAD_8x, OMXVCCOMM_SUFFIX)
+
+#define omxVCM4P10_Average_4x                             OMXCATBAR(VCM4P10_Average_4x, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_BlockMatch_Half                        OMXCATBAR(VCM4P10_BlockMatch_Half, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_BlockMatch_Integer                     OMXCATBAR(VCM4P10_BlockMatch_Integer, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_BlockMatch_Quarter                     OMXCATBAR(VCM4P10_BlockMatch_Quarter, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_DeblockChroma_I                        OMXCATBAR(VCM4P10_DeblockChroma_I, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_DeblockLuma_I                          OMXCATBAR(VCM4P10_DeblockLuma_I, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_DecodeChromaDcCoeffsToPairCAVLC        OMXCATBAR(VCM4P10_DecodeChromaDcCoeffsToPairCAVLC, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_DecodeCoeffsToPairCAVLC                OMXCATBAR(VCM4P10_DecodeCoeffsToPairCAVLC, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_DequantTransformResidualFromPairAndAdd OMXCATBAR(VCM4P10_DequantTransformResidualFromPairAndAdd, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_FilterDeblockingChroma_HorEdge_I       OMXCATBAR(VCM4P10_FilterDeblockingChroma_HorEdge_I, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_FilterDeblockingChroma_VerEdge_I       OMXCATBAR(VCM4P10_FilterDeblockingChroma_VerEdge_I, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_FilterDeblockingLuma_HorEdge_I         OMXCATBAR(VCM4P10_FilterDeblockingLuma_HorEdge_I, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_FilterDeblockingLuma_VerEdge_I         OMXCATBAR(VCM4P10_FilterDeblockingLuma_VerEdge_I, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_GetVLCInfo                             OMXCATBAR(VCM4P10_GetVLCInfo, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_InterpolateChroma                      OMXCATBAR(VCM4P10_InterpolateChroma, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_InterpolateHalfHor_Luma                OMXCATBAR(VCM4P10_InterpolateHalfHor_Luma, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_InterpolateHalfVer_Luma                OMXCATBAR(VCM4P10_InterpolateHalfVer_Luma, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_InterpolateLuma                        OMXCATBAR(VCM4P10_InterpolateLuma, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_InvTransformDequant_ChromaDC           OMXCATBAR(VCM4P10_InvTransformDequant_ChromaDC, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_InvTransformDequant_LumaDC             OMXCATBAR(VCM4P10_InvTransformDequant_LumaDC, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_InvTransformResidualAndAdd             OMXCATBAR(VCM4P10_InvTransformResidualAndAdd, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_MEGetBufSize                           OMXCATBAR(VCM4P10_MEGetBufSize, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_MEInit                                 OMXCATBAR(VCM4P10_MEInit, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_MotionEstimationMB                     OMXCATBAR(VCM4P10_MotionEstimationMB, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_PredictIntra_16x16                     OMXCATBAR(VCM4P10_PredictIntra_16x16, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_PredictIntra_4x4                       OMXCATBAR(VCM4P10_PredictIntra_4x4, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_PredictIntraChroma_8x8                  OMXCATBAR(VCM4P10_PredictIntraChroma_8x8, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_SAD_4x                                 OMXCATBAR(VCM4P10_SAD_4x, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_SADQuar_16x                            OMXCATBAR(VCM4P10_SADQuar_16x, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_SADQuar_4x                             OMXCATBAR(VCM4P10_SADQuar_4x, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_SADQuar_8x                             OMXCATBAR(VCM4P10_SADQuar_8x, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_SATD_4x4                               OMXCATBAR(VCM4P10_SATD_4x4, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_SubAndTransformQDQResidual             OMXCATBAR(VCM4P10_SubAndTransformQDQResidual, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_TransformDequantChromaDCFromPair       OMXCATBAR(VCM4P10_TransformDequantChromaDCFromPair, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_TransformDequantLumaDCFromPair         OMXCATBAR(VCM4P10_TransformDequantLumaDCFromPair, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_TransformQuant_ChromaDC                OMXCATBAR(VCM4P10_TransformQuant_ChromaDC, OMXVCM4P10_SUFFIX)
+#define omxVCM4P10_TransformQuant_LumaDC                  OMXCATBAR(VCM4P10_TransformQuant_LumaDC, OMXVCM4P10_SUFFIX)
+
+#define omxVCM4P2_BlockMatch_Half_16x16                   OMXCATBAR(VCM4P2_BlockMatch_Half_16x16, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_BlockMatch_Half_8x8                     OMXCATBAR(VCM4P2_BlockMatch_Half_8x8, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_BlockMatch_Integer_16x16                OMXCATBAR(VCM4P2_BlockMatch_Integer_16x16, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_BlockMatch_Integer_8x8                  OMXCATBAR(VCM4P2_BlockMatch_Integer_8x8, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_DCT8x8blk                               OMXCATBAR(VCM4P2_DCT8x8blk, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_DecodeBlockCoef_Inter                   OMXCATBAR(VCM4P2_DecodeBlockCoef_Inter, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_DecodeBlockCoef_Intra                   OMXCATBAR(VCM4P2_DecodeBlockCoef_Intra, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_DecodePadMV_PVOP                        OMXCATBAR(VCM4P2_DecodePadMV_PVOP, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_DecodeVLCZigzag_Inter                   OMXCATBAR(VCM4P2_DecodeVLCZigzag_Inter, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_DecodeVLCZigzag_IntraACVLC              OMXCATBAR(VCM4P2_DecodeVLCZigzag_IntraACVLC, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_DecodeVLCZigzag_IntraDCVLC              OMXCATBAR(VCM4P2_DecodeVLCZigzag_IntraDCVLC, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_EncodeMV                                OMXCATBAR(VCM4P2_EncodeMV, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_EncodeVLCZigzag_Inter                   OMXCATBAR(VCM4P2_EncodeVLCZigzag_Inter, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_EncodeVLCZigzag_IntraACVLC              OMXCATBAR(VCM4P2_EncodeVLCZigzag_IntraACVLC, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_EncodeVLCZigzag_IntraDCVLC              OMXCATBAR(VCM4P2_EncodeVLCZigzag_IntraDCVLC, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_FindMVpred                              OMXCATBAR(VCM4P2_FindMVpred, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_IDCT8x8blk                              OMXCATBAR(VCM4P2_IDCT8x8blk, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_MCReconBlock                            OMXCATBAR(VCM4P2_MCReconBlock, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_MEGetBufSize                            OMXCATBAR(VCM4P2_MEGetBufSize, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_MEInit                                  OMXCATBAR(VCM4P2_MEInit, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_MotionEstimationMB                      OMXCATBAR(VCM4P2_MotionEstimationMB, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_PredictReconCoefIntra                   OMXCATBAR(VCM4P2_PredictReconCoefIntra, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_QuantInter_I                            OMXCATBAR(VCM4P2_QuantInter_I, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_QuantIntra_I                            OMXCATBAR(VCM4P2_QuantIntra_I, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_QuantInvInter_I                         OMXCATBAR(VCM4P2_QuantInvInter_I, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_QuantInvIntra_I                         OMXCATBAR(VCM4P2_QuantInvIntra_I, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_TransRecBlockCoef_inter                 OMXCATBAR(VCM4P2_TransRecBlockCoef_inter, OMXVCM4P2_SUFFIX)
+#define omxVCM4P2_TransRecBlockCoef_intra                 OMXCATBAR(VCM4P2_TransRecBlockCoef_intra, OMXVCM4P2_SUFFIX)
+
+
+#endif /* _armOMX_h_ */
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/api/omxtypes.h b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/api/omxtypes.h
new file mode 100644
index 0000000..8b295a6
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/api/omxtypes.h
@@ -0,0 +1,252 @@
+/**
+ * File: omxtypes.h
+ * Brief: Defines basic Data types used in OpenMAX v1.0.2 header files.
+ *
+ * Copyright © 2005-2008 The Khronos Group Inc. All Rights Reserved. 
+ *
+ * These materials are protected by copyright laws and contain material 
+ * proprietary to the Khronos Group, Inc.  You may use these materials 
+ * for implementing Khronos specifications, without altering or removing 
+ * any trademark, copyright or other notice from the specification.
+ * 
+ * Khronos Group makes no, and expressly disclaims any, representations 
+ * or warranties, express or implied, regarding these materials, including, 
+ * without limitation, any implied warranties of merchantability or fitness 
+ * for a particular purpose or non-infringement of any intellectual property. 
+ * Khronos Group makes no, and expressly disclaims any, warranties, express 
+ * or implied, regarding the correctness, accuracy, completeness, timeliness, 
+ * and reliability of these materials. 
+ *
+ * Under no circumstances will the Khronos Group, or any of its Promoters, 
+ * Contributors or Members or their respective partners, officers, directors, 
+ * employees, agents or representatives be liable for any damages, whether 
+ * direct, indirect, special or consequential damages for lost revenues, 
+ * lost profits, or otherwise, arising from or in connection with these 
+ * materials.
+ * 
+ * Khronos and OpenMAX are trademarks of the Khronos Group Inc. 
+ *
+ */
+  
+#ifndef _OMXTYPES_H_
+#define _OMXTYPES_H_
+
+#include <limits.h> 
+
+#define OMX_IN
+#define OMX_OUT
+#define OMX_INOUT
+
+
+typedef enum {
+    
+    /* Mandatory return codes - use cases are explicitly described for each function */
+    OMX_Sts_NoErr                    =  0,    /* No error, the function completed successfully */
+    OMX_Sts_Err                      = -2,    /* Unknown/unspecified error */    
+    OMX_Sts_InvalidBitstreamValErr   = -182,  /* Invalid value detected during bitstream processing */    
+    OMX_Sts_MemAllocErr              = -9,    /* Not enough memory allocated for the operation */
+    OMX_StsACAAC_GainCtrErr    	     = -159,  /* AAC: Unsupported gain control data detected */
+    OMX_StsACAAC_PrgNumErr           = -167,  /* AAC: Invalid number of elements for one program   */
+    OMX_StsACAAC_CoefValErr          = -163,  /* AAC: Invalid quantized coefficient value          */     
+    OMX_StsACAAC_MaxSfbErr           = -162,  /* AAC: Invalid maxSfb value in relation to numSwb */    
+	OMX_StsACAAC_PlsDataErr		     = -160,  /* AAC: pulse escape sequence data error */
+
+    /* Optional return codes - use cases are explicitly described for each function*/
+    OMX_Sts_BadArgErr                = -5,    /* Bad Arguments */
+
+    OMX_StsACAAC_TnsNumFiltErr       = -157,  /* AAC: Invalid number of TNS filters  */
+    OMX_StsACAAC_TnsLenErr           = -156,  /* AAC: Invalid TNS region length  */   
+    OMX_StsACAAC_TnsOrderErr         = -155,  /* AAC: Invalid order of TNS filter  */                  
+    OMX_StsACAAC_TnsCoefResErr       = -154,  /* AAC: Invalid bit-resolution for TNS filter coefficients  */
+    OMX_StsACAAC_TnsCoefErr          = -153,  /* AAC: Invalid TNS filter coefficients  */                  
+    OMX_StsACAAC_TnsDirectErr        = -152,  /* AAC: Invalid TNS filter direction  */  
+
+    OMX_StsICJP_JPEGMarkerErr        = -183,  /* JPEG marker encountered within an entropy-coded block; */
+                                              /* Huffman decoding operation terminated early.           */
+    OMX_StsICJP_JPEGMarker           = -181,  /* JPEG marker encountered; Huffman decoding */
+                                              /* operation terminated early.                         */
+    OMX_StsIPPP_ContextMatchErr      = -17,   /* Context parameter doesn't match to the operation */
+
+    OMX_StsSP_EvenMedianMaskSizeErr  = -180,  /* Even size of the Median Filter mask was replaced by the odd one */
+
+    OMX_Sts_MaximumEnumeration       = INT_MAX  /*Placeholder, forces enum of size OMX_INT*/
+    
+ } OMXResult;          /** Return value or error value returned from a function. Identical to OMX_INT */
+
+ 
+/* OMX_U8 */
+#if UCHAR_MAX == 0xff
+typedef unsigned char OMX_U8;
+#elif USHRT_MAX == 0xff 
+typedef unsigned short int OMX_U8; 
+#else
+#error OMX_U8 undefined
+#endif 
+
+ 
+/* OMX_S8 */
+#if SCHAR_MAX == 0x7f 
+typedef signed char OMX_S8;
+#elif SHRT_MAX == 0x7f 
+typedef signed short int OMX_S8; 
+#else
+#error OMX_S8 undefined
+#endif
+ 
+ 
+/* OMX_U16 */
+#if USHRT_MAX == 0xffff
+typedef unsigned short int OMX_U16;
+#elif UINT_MAX == 0xffff
+typedef unsigned int OMX_U16; 
+#else
+#error OMX_U16 undefined
+#endif
+
+
+/* OMX_S16 */
+#if SHRT_MAX == 0x7fff 
+typedef signed short int OMX_S16;
+#elif INT_MAX == 0x7fff 
+typedef signed int OMX_S16; 
+#else
+#error OMX_S16 undefined
+#endif
+
+
+/* OMX_U32 */
+#if UINT_MAX == 0xffffffff
+typedef unsigned int OMX_U32;
+#elif LONG_MAX == 0xffffffff
+typedef unsigned long int OMX_U32; 
+#else
+#error OMX_U32 undefined
+#endif
+
+
+/* OMX_S32 */
+#if INT_MAX == 0x7fffffff
+typedef signed int OMX_S32;
+#elif LONG_MAX == 0x7fffffff
+typedef long signed int OMX_S32; 
+#else
+#error OMX_S32 undefined
+#endif
+
+
+/* OMX_U64 & OMX_S64 */
+#if defined( _WIN32 ) || defined ( _WIN64 )
+    typedef __int64 OMX_S64; /** Signed 64-bit integer */
+    typedef unsigned __int64 OMX_U64; /** Unsigned 64-bit integer */
+    #define OMX_MIN_S64			(0x8000000000000000i64)
+    #define OMX_MIN_U64			(0x0000000000000000i64)
+    #define OMX_MAX_S64			(0x7FFFFFFFFFFFFFFFi64)
+    #define OMX_MAX_U64			(0xFFFFFFFFFFFFFFFFi64)
+#else
+    typedef long long OMX_S64; /** Signed 64-bit integer */
+    typedef unsigned long long OMX_U64; /** Unsigned 64-bit integer */
+    #define OMX_MIN_S64			(0x8000000000000000LL)
+    #define OMX_MIN_U64			(0x0000000000000000LL)
+    #define OMX_MAX_S64			(0x7FFFFFFFFFFFFFFFLL)
+    #define OMX_MAX_U64			(0xFFFFFFFFFFFFFFFFLL)
+#endif
+
+
+/* OMX_SC8 */
+typedef struct
+{
+  OMX_S8 Re; /** Real part */
+  OMX_S8 Im; /** Imaginary part */	
+	
+} OMX_SC8; /** Signed 8-bit complex number */
+
+
+/* OMX_SC16 */
+typedef struct
+{
+  OMX_S16 Re; /** Real part */
+  OMX_S16 Im; /** Imaginary part */	
+	
+} OMX_SC16; /** Signed 16-bit complex number */
+
+
+/* OMX_SC32 */
+typedef struct
+{
+  OMX_S32 Re; /** Real part */
+  OMX_S32 Im; /** Imaginary part */	
+	
+} OMX_SC32; /** Signed 32-bit complex number */
+
+
+/* OMX_SC64 */
+typedef struct
+{
+  OMX_S64 Re; /** Real part */
+  OMX_S64 Im; /** Imaginary part */	
+	
+} OMX_SC64; /** Signed 64-bit complex number */
+
+
+/* OMX_F32 */
+typedef float OMX_F32; /** Single precision floating point,IEEE 754 */
+
+
+/* OMX_F64 */
+typedef double OMX_F64; /** Double precision floating point,IEEE 754 */
+
+
+/* OMX_INT */
+typedef int OMX_INT; /** signed integer corresponding to machine word length, has maximum signed value INT_MAX*/
+
+
+#define OMX_MIN_S8  	   	(-128)
+#define OMX_MIN_U8  		0
+#define OMX_MIN_S16		 	(-32768)
+#define OMX_MIN_U16			0
+#define OMX_MIN_S32			(-2147483647-1)
+#define OMX_MIN_U32			0
+
+#define OMX_MAX_S8			(127)
+#define OMX_MAX_U8			(255)
+#define OMX_MAX_S16			(32767)
+#define OMX_MAX_U16			(0xFFFF)
+#define OMX_MAX_S32			(2147483647)
+#define OMX_MAX_U32			(0xFFFFFFFF)
+
+typedef void OMXVoid;
+
+#ifndef NULL
+#define NULL ((void*)0)
+#endif
+
+/** Defines the geometric position and size of a rectangle, 
+  * where x,y defines the coordinates of the top left corner
+  * of the rectangle, with dimensions width in the x-direction 
+  * and height in the y-direction */
+typedef struct {
+	OMX_INT x;      /** x-coordinate of top left corner of rectangle */
+	OMX_INT y;      /** y-coordinate of top left corner of rectangle */
+	OMX_INT width;  /** Width in the x-direction. */
+	OMX_INT height; /** Height in the y-direction. */
+}OMXRect;
+
+
+/** Defines the geometric position of a point, */
+typedef struct 
+{
+ OMX_INT x; /** x-coordinate */
+ OMX_INT y;	/** y-coordinate */
+	
+} OMXPoint;
+
+
+/** Defines the dimensions of a rectangle, or region of interest in an image */
+typedef struct 
+{
+ OMX_INT width;  /** Width of the rectangle, in the x-direction */
+ OMX_INT height; /** Height of the rectangle, in the y-direction */
+	
+} OMXSize;
+
+#endif /* _OMXTYPES_H_ */
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/build_vc.pl b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/build_vc.pl
new file mode 100755
index 0000000..f0b43e01
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/build_vc.pl
@@ -0,0 +1,111 @@
+#!/usr/bin/perl
+#
+# 
+# File Name:  build_vc.pl
+# OpenMAX DL: v1.0.2
+# Revision:   9641
+# Date:       Thursday, February 7, 2008
+# 
+# (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+# 
+# 
+#
+# This file builds the OpenMAX DL vc domain library omxVC.o.
+#
+
+use File::Spec;
+use strict;
+
+my ($CC, $CC_OPTS, $AS, $AS_OPTS, $LIB, $LIB_OPTS, $LIB_TYPE);
+
+$CC       = 'armcc';
+$CC_OPTS  = '--no_unaligned_access --cpu ARM7TDMI -c';
+$AS       = 'armasm';
+$AS_OPTS  = '--no_unaligned_access --cpu ARM7TDMI';
+# $LIB      = 'armlink';
+# $LIB_OPTS = '--partial -o';
+# $LIB_TYPE = '.o';
+$LIB      = 'armar';
+$LIB_OPTS = '--create -r';
+$LIB_TYPE = '.a';
+
+#------------------------
+
+my (@headerlist, @filelist, $hd, $file, $ofile, $command, $objlist, $libfile, $h);
+
+# Define the list of directories containing included header files.
+@headerlist = qw(api vc/api vc/m4p2/api vc/m4p10/api);
+
+# Define the list of source files to compile.
+open(FILES, '<filelist_vc.txt') or die("Can't open source file list\n");
+@filelist = <FILES>;
+close(FILES);
+
+# Fix the file separators in the header paths
+foreach $h (@headerlist)
+{
+        $h = File::Spec->canonpath($h);
+}
+
+# Create the include path to be passed to the compiler
+$hd = '-I' . join(' -I', @headerlist);
+
+# Create the build directories "/lib/" and "/obj/" (if they are not there already)
+mkdir "obj", 0777 if (! -d "obj");
+mkdir "lib", 0777 if (! -d "lib");
+
+$objlist = '';
+
+# Compile each file
+foreach $file (@filelist)
+{
+	my $f;
+	my $base;
+	my $ext;
+	my $objfile;
+
+	chomp($file);
+	$file = File::Spec->canonpath($file);
+
+	(undef, undef, $f) = File::Spec->splitpath($file);
+	if(($base, $ext) = $f =~ /(.+)\.(\w)$/)
+	{
+		$objfile = File::Spec->catfile('obj', $base.'.o');
+
+		if($ext eq 'c')
+		{
+			$objlist .= "$objfile ";
+			$command = $CC.' '.$CC_OPTS.' '.$hd.' -o '.$objfile.' '.$file;
+			print "$command\n";
+			system($command);
+		}
+		elsif($ext eq 's')
+		{
+			$objlist .= "$objfile ";
+			$command = $AS.' '.$AS_OPTS.' '.$hd.' -o '.$objfile.' '.$file;
+			print "$command\n";
+			system($command);
+		}
+		else
+		{
+			print "Ignoring file: $f\n";
+		}
+	}
+	else
+	{
+		die "No file extension found: $f\n";
+	}
+}
+
+# Do the final link stage to create the libraries.
+$libfile = File::Spec->catfile('lib', 'omxVC'.$LIB_TYPE);
+$command = $LIB.' '.$LIB_OPTS.' '.$libfile.' '.$objlist;
+print "$command\n";
+(system($command) == 0) and print "Build successful\n";
+
+
+
+
+
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/filelist_vc.txt b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/filelist_vc.txt
new file mode 100644
index 0000000..66f34ac
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/filelist_vc.txt
@@ -0,0 +1,123 @@
+./api/armCOMM.h
+./api/armCOMM_Bitstream.h
+./api/armCOMM_Version.h
+./api/armOMX_ReleaseVersion.h
+./api/omxtypes.h
+./src/armCOMM.c
+./src/armCOMM_Bitstream.c
+./vc/api/armVC.h
+./vc/api/omxVC.h
+./vc/comm/src/armVCCOMM_Average.c
+./vc/comm/src/armVCCOMM_SAD.c
+./vc/comm/src/omxVCCOMM_Average_16x.c
+./vc/comm/src/omxVCCOMM_Average_8x.c
+./vc/comm/src/omxVCCOMM_ComputeTextureErrorBlock.c
+./vc/comm/src/omxVCCOMM_ComputeTextureErrorBlock_SAD.c
+./vc/comm/src/omxVCCOMM_Copy16x16.c
+./vc/comm/src/omxVCCOMM_Copy8x8.c
+./vc/comm/src/omxVCCOMM_ExpandFrame_I.c
+./vc/comm/src/omxVCCOMM_LimitMVToRect.c
+./vc/comm/src/omxVCCOMM_SAD_16x.c
+./vc/comm/src/omxVCCOMM_SAD_8x.c
+./vc/m4p10/api/armVCM4P10_CAVLCTables.h
+./vc/m4p10/src/armVCM4P10_CAVLCTables.c
+./vc/m4p10/src/armVCM4P10_CompareMotionCostToMV.c
+./vc/m4p10/src/armVCM4P10_DeBlockPixel.c
+./vc/m4p10/src/armVCM4P10_DecodeCoeffsToPair.c
+./vc/m4p10/src/armVCM4P10_DequantTables.c
+./vc/m4p10/src/armVCM4P10_FwdTransformResidual4x4.c
+./vc/m4p10/src/armVCM4P10_Interpolate_Chroma.c
+./vc/m4p10/src/armVCM4P10_Interpolate_Luma.c
+./vc/m4p10/src/armVCM4P10_InterpolateHalfDiag_Luma.c
+./vc/m4p10/src/armVCM4P10_InterpolateHalfHor_Luma.c
+./vc/m4p10/src/armVCM4P10_InterpolateHalfVer_Luma.c
+./vc/m4p10/src/armVCM4P10_PredictIntraDC4x4.c
+./vc/m4p10/src/armVCM4P10_QuantTables.c
+./vc/m4p10/src/armVCM4P10_SADQuar.c
+./vc/m4p10/src/armVCM4P10_TransformResidual4x4.c
+./vc/m4p10/src/armVCM4P10_UnpackBlock2x2.c
+./vc/m4p10/src/armVCM4P10_UnpackBlock4x4.c
+./vc/m4p10/src/omxVCM4P10_Average_4x.c
+./vc/m4p10/src/omxVCM4P10_BlockMatch_Half.c
+./vc/m4p10/src/omxVCM4P10_BlockMatch_Integer.c
+./vc/m4p10/src/omxVCM4P10_BlockMatch_Quarter.c
+./vc/m4p10/src/omxVCM4P10_DeblockChroma_I.c
+./vc/m4p10/src/omxVCM4P10_DeblockLuma_I.c
+./vc/m4p10/src/omxVCM4P10_DecodeChromaDcCoeffsToPairCAVLC.c
+./vc/m4p10/src/omxVCM4P10_DecodeCoeffsToPairCAVLC.c
+./vc/m4p10/src/omxVCM4P10_DequantTransformResidualFromPairAndAdd.c
+./vc/m4p10/src/omxVCM4P10_FilterDeblockingChroma_HorEdge_I.c
+./vc/m4p10/src/omxVCM4P10_FilterDeblockingChroma_VerEdge_I.c
+./vc/m4p10/src/omxVCM4P10_FilterDeblockingLuma_HorEdge_I.c
+./vc/m4p10/src/omxVCM4P10_FilterDeblockingLuma_VerEdge_I.c
+./vc/m4p10/src/omxVCM4P10_GetVLCInfo.c
+./vc/m4p10/src/omxVCM4P10_InterpolateChroma.c
+./vc/m4p10/src/omxVCM4P10_InterpolateHalfHor_Luma.c
+./vc/m4p10/src/omxVCM4P10_InterpolateHalfVer_Luma.c
+./vc/m4p10/src/omxVCM4P10_InterpolateLuma.c
+./vc/m4p10/src/omxVCM4P10_InvTransformDequant_ChromaDC.c
+./vc/m4p10/src/omxVCM4P10_InvTransformDequant_LumaDC.c
+./vc/m4p10/src/omxVCM4P10_InvTransformResidualAndAdd.c
+./vc/m4p10/src/omxVCM4P10_MEGetBufSize.c
+./vc/m4p10/src/omxVCM4P10_MEInit.c
+./vc/m4p10/src/omxVCM4P10_MotionEstimationMB.c
+./vc/m4p10/src/omxVCM4P10_PredictIntra_16x16.c
+./vc/m4p10/src/omxVCM4P10_PredictIntra_4x4.c
+./vc/m4p10/src/omxVCM4P10_PredictIntraChroma_8x8.c
+./vc/m4p10/src/omxVCM4P10_SAD_4x.c
+./vc/m4p10/src/omxVCM4P10_SADQuar_16x.c
+./vc/m4p10/src/omxVCM4P10_SADQuar_4x.c
+./vc/m4p10/src/omxVCM4P10_SADQuar_8x.c
+./vc/m4p10/src/omxVCM4P10_SATD_4x4.c
+./vc/m4p10/src/omxVCM4P10_SubAndTransformQDQResidual.c
+./vc/m4p10/src/omxVCM4P10_TransformDequantChromaDCFromPair.c
+./vc/m4p10/src/omxVCM4P10_TransformDequantLumaDCFromPair.c
+./vc/m4p10/src/omxVCM4P10_TransformQuant_ChromaDC.c
+./vc/m4p10/src/omxVCM4P10_TransformQuant_LumaDC.c
+./vc/m4p2/api/armVCM4P2_DCT_Table.h
+./vc/m4p2/api/armVCM4P2_Huff_Tables_VLC.h
+./vc/m4p2/api/armVCM4P2_ZigZag_Tables.h
+./vc/m4p2/src/armVCM4P2_ACDCPredict.c
+./vc/m4p2/src/armVCM4P2_BlockMatch_Half.c
+./vc/m4p2/src/armVCM4P2_BlockMatch_Integer.c
+./vc/m4p2/src/armVCM4P2_CheckVLCEscapeMode.c
+./vc/m4p2/src/armVCM4P2_CompareMV.c
+./vc/m4p2/src/armVCM4P2_DCT_Table.c
+./vc/m4p2/src/armVCM4P2_DecodeVLCZigzag_intra.c
+./vc/m4p2/src/armVCM4P2_EncodeVLCZigzag_intra.c
+./vc/m4p2/src/armVCM4P2_FillVLCBuffer.c
+./vc/m4p2/src/armVCM4P2_FillVLDBuffer.c
+./vc/m4p2/src/armVCM4P2_GetVLCBits.c
+./vc/m4p2/src/armVCM4P2_Huff_Tables_VLC.c
+./vc/m4p2/src/armVCM4P2_PutVLCBits.c
+./vc/m4p2/src/armVCM4P2_SetPredDir.c
+./vc/m4p2/src/armVCM4P2_Zigzag_Tables.c
+./vc/m4p2/src/omxVCM4P2_BlockMatch_Half_16x16.c
+./vc/m4p2/src/omxVCM4P2_BlockMatch_Half_8x8.c
+./vc/m4p2/src/omxVCM4P2_BlockMatch_Integer_16x16.c
+./vc/m4p2/src/omxVCM4P2_BlockMatch_Integer_8x8.c
+./vc/m4p2/src/omxVCM4P2_DCT8x8blk.c
+./vc/m4p2/src/omxVCM4P2_DecodeBlockCoef_Inter.c
+./vc/m4p2/src/omxVCM4P2_DecodeBlockCoef_Intra.c
+./vc/m4p2/src/omxVCM4P2_DecodePadMV_PVOP.c
+./vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_Inter.c
+./vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_IntraACVLC.c
+./vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_IntraDCVLC.c
+./vc/m4p2/src/omxVCM4P2_EncodeMV.c
+./vc/m4p2/src/omxVCM4P2_EncodeVLCZigzag_Inter.c
+./vc/m4p2/src/omxVCM4P2_EncodeVLCZigzag_IntraACVLC.c
+./vc/m4p2/src/omxVCM4P2_EncodeVLCZigzag_IntraDCVLC.c
+./vc/m4p2/src/omxVCM4P2_FindMVpred.c
+./vc/m4p2/src/omxVCM4P2_IDCT8x8blk.c
+./vc/m4p2/src/omxVCM4P2_MCReconBlock.c
+./vc/m4p2/src/omxVCM4P2_MEGetBufSize.c
+./vc/m4p2/src/omxVCM4P2_MEInit.c
+./vc/m4p2/src/omxVCM4P2_MotionEstimationMB.c
+./vc/m4p2/src/omxVCM4P2_PredictReconCoefIntra.c
+./vc/m4p2/src/omxVCM4P2_QuantInter_I.c
+./vc/m4p2/src/omxVCM4P2_QuantIntra_I.c
+./vc/m4p2/src/omxVCM4P2_QuantInvInter_I.c
+./vc/m4p2/src/omxVCM4P2_QuantInvIntra_I.c
+./vc/m4p2/src/omxVCM4P2_TransRecBlockCoef_inter.c
+./vc/m4p2/src/omxVCM4P2_TransRecBlockCoef_intra.c
+./vc/src/armVC_Version.c
\ No newline at end of file
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/src/armCOMM.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/src/armCOMM.c
new file mode 100644
index 0000000..e572a89
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/src/armCOMM.c
@@ -0,0 +1,936 @@
+/**
+ * 
+ * File Name:  armCOMM.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Defines Common APIs used across OpenMAX API's
+ */
+
+#include "omxtypes.h"
+#include "armCOMM.h"
+
+/***********************************************************************/
+                /* Miscellaneous Arithmetic operations */
+
+/**
+ * Function: armRoundFloatToS16
+ *
+ * Description:
+ * Converts a double precision value into a short int after rounding
+ *
+ * Parameters:
+ * [in]  Value                 Float value to be converted
+ *
+ * Return Value:
+ * [out] converted value in OMX_S16 format
+ *
+ */
+
+OMX_S16 armRoundFloatToS16 (OMX_F64 Value)
+{
+    if (Value > 0)
+    {
+        return (OMX_S16)(Value + .5);
+    }
+    else
+    {
+        return (OMX_S16)(Value - .5);
+    }
+}
+
+/**
+ * Function: armRoundFloatToS32
+ *
+ * Description:
+ * Converts a double precision value into a int after rounding
+ *
+ * Parameters:
+ * [in]  Value                 Float value to be converted
+ *
+ * Return Value:
+ * [out] converted value in OMX_S32 format
+ *
+ */
+
+OMX_S32 armRoundFloatToS32 (OMX_F64 Value)
+{
+    if (Value > 0)
+    {
+        return (OMX_S32)(Value + .5);
+    }
+    else
+    {
+        return (OMX_S32)(Value - .5);
+    }
+}
+/**
+ * Function: armSatRoundFloatToS16
+ *
+ * Description:
+ * Converts a double precision value into a short int after rounding and saturation
+ *
+ * Parameters:
+ * [in]  Value                 Float value to be converted
+ *
+ * Return Value:
+ * [out] converted value in OMX_S16 format
+ *
+ */
+
+OMX_S16 armSatRoundFloatToS16 (OMX_F64 Value)
+{
+    if (Value > 0)
+    {
+        Value += 0.5;
+        
+        if(Value > (OMX_S16)OMX_MAX_S16 )
+        {
+            return (OMX_S16)OMX_MAX_S16;
+        }
+        else
+        {
+            return (OMX_S16)Value;
+        }
+    }
+    else
+    {
+        Value -= 0.5;
+
+        if(Value < (OMX_S16)OMX_MIN_S16 )
+        {
+            return (OMX_S16)OMX_MIN_S16;
+        }
+        else
+        {
+            return (OMX_S16)Value;
+        }
+    }
+}
+
+/**
+ * Function: armSatRoundFloatToS32
+ *
+ * Description:
+ * Converts a double precision value into a int after rounding and saturation
+ *
+ * Parameters:
+ * [in]  Value                 Float value to be converted
+ *
+ * Return Value:
+ * [out] converted value in OMX_S32 format
+ *
+ */
+
+OMX_S32 armSatRoundFloatToS32 (OMX_F64 Value)
+{
+    if (Value > 0)
+    {
+        Value += 0.5;
+        
+        if(Value > (OMX_S32)OMX_MAX_S32 )
+        {
+            return (OMX_S32)OMX_MAX_S32;
+        }
+        else
+        {
+            return (OMX_S32)Value;
+        }
+    }
+    else
+    {
+        Value -= 0.5;
+
+        if(Value < (OMX_S32)OMX_MIN_S32 )
+        {
+            return (OMX_S32)OMX_MIN_S32;
+        }
+        else
+        {
+            return (OMX_S32)Value;
+        }
+    }
+}
+
+/**
+ * Function: armSatRoundFloatToU16
+ *
+ * Description:
+ * Converts a double precision value into a unsigned short int after rounding and saturation
+ *
+ * Parameters:
+ * [in]  Value                 Float value to be converted
+ *
+ * Return Value:
+ * [out] converted value in OMX_U16 format
+ *
+ */
+
+OMX_U16 armSatRoundFloatToU16 (OMX_F64 Value)
+{
+    Value += 0.5;
+    
+    if(Value > (OMX_U16)OMX_MAX_U16 )
+    {
+        return (OMX_U16)OMX_MAX_U16;
+    }
+    else
+    {
+        return (OMX_U16)Value;
+    }
+}
+
+/**
+ * Function: armSatRoundFloatToU32
+ *
+ * Description:
+ * Converts a double precision value into a unsigned int after rounding and saturation
+ *
+ * Parameters:
+ * [in]  Value                 Float value to be converted
+ *
+ * Return Value:
+ * [out] converted value in OMX_U32 format
+ *
+ */
+
+OMX_U32 armSatRoundFloatToU32 (OMX_F64 Value)
+{
+    Value += 0.5;
+    
+    if(Value > (OMX_U32)OMX_MAX_U32 )
+    {
+        return (OMX_U32)OMX_MAX_U32;
+    }
+    else
+    {
+        return (OMX_U32)Value;
+    }
+}
+
+/**
+ * Function: armRoundFloatToS64
+ *
+ * Description:
+ * Converts a double precision value into a 64 bit int after rounding
+ *
+ * Parameters:
+ * [in]  Value                 Float value to be converted
+ *
+ * Return Value:
+ * [out] converted value in OMX_S64 format
+ *
+ */
+
+OMX_S64 armRoundFloatToS64 (OMX_F64 Value)
+{
+    if (Value > 0)
+    {
+        return (OMX_S64)(Value + .5);
+    }
+    else
+    {
+        return (OMX_S64)(Value - .5);
+    }
+}
+
+/**
+ * Function: armSignCheck
+ *
+ * Description:
+ * Checks the sign of a variable:
+ * returns 1 if it is Positive
+ * returns 0 if it is 0
+ * returns -1 if it is Negative 
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	    var     Variable to be checked
+ *
+ * Return Value:
+ * OMX_INT --   returns 1 if it is Positive
+ *              returns 0 if it is 0
+ *              returns -1 if it is Negative 
+ */ 
+
+OMX_INT armSignCheck (
+    OMX_S16 var
+)
+
+{
+    OMX_INT Sign;
+    
+    if (var < 0)
+    {
+        Sign = -1;
+    }
+    else if ( var > 0)
+    {
+        Sign = 1;
+    }
+    else
+    {
+        Sign = 0;
+    }
+    
+    return Sign;
+}
+
+/**
+ * Function: armClip
+ *
+ * Description: Clips the input between MAX and MIN value
+ * 
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] Min     lower bound
+ * [in] Max     upper bound
+ * [in] src     variable to the clipped
+ *
+ * Return Value:
+ * OMX_S32 --   returns clipped value
+ */ 
+ 
+OMX_S32 armClip (
+    OMX_INT min,
+    OMX_INT max, 
+    OMX_S32 src 
+)
+ 
+{
+    if (src > max)
+    {
+        src = max;
+    }
+    else if (src < min)
+    {
+        src = min;
+    }
+    
+    return src;
+}
+
+/**
+ * Function: armClip_F32
+ *
+ * Description: Clips the input between MAX and MIN value
+ * 
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] Min     lower bound
+ * [in] Max     upper bound
+ * [in] src     variable to the clipped
+ *
+ * Return Value:
+ * OMX_F32 --   returns clipped value
+ */ 
+ 
+OMX_F32 armClip_F32 (
+    OMX_F32 min,
+    OMX_F32 max, 
+    OMX_F32 src 
+)
+ 
+{
+    if (src > max)
+    {
+        src = max;
+    }
+    else if (src < min)
+    {
+        src = min;
+    }
+    
+    return src;
+}
+
+/**
+ * Function: armShiftSat_F32
+ *
+ * Description: Divides a float value by 2^shift and 
+ * saturates it for unsigned value range for satBits.
+ * Second parameter is like "shifting" the corresponding 
+ * integer value. Takes care of rounding while clipping the final 
+ * value.
+ *
+ * Parameters:
+ * [in] v          Number to be operated upon
+ * [in] shift      Divides the input "v" by "2^shift"
+ * [in] satBits    Final range is [0, 2^satBits)
+ *
+ * Return Value:
+ * OMX_S32 --   returns "shifted" saturated value
+ */ 
+ 
+OMX_U32 armShiftSat_F32(OMX_F32 v, OMX_INT shift, OMX_INT satBits) 
+{
+    OMX_U32 allOnes = (OMX_U32)(-1);
+    OMX_U32 maxV = allOnes >> (32-satBits);
+    OMX_F32 vShifted, vRounded, shiftDiv = (OMX_F32)(1 << shift);
+    OMX_U32 vInt;
+    OMX_U32 vIntSat;
+    
+    if(v <= 0)
+        return 0;
+    
+    vShifted = v / shiftDiv;
+    vRounded = (OMX_F32)(vShifted + 0.5);
+    vInt = (OMX_U32)vRounded;
+    vIntSat = vInt;
+    if(vIntSat > maxV) 
+        vIntSat = maxV;
+    return vIntSat;
+}
+
+/**
+ * Functions: armSwapElem
+ *
+ * Description:
+ * These function swaps two elements at the specified pointer locations.
+ * The size of each element could be anything as specified by <elemSize>
+ *
+ * Return Value:
+ * OMXResult -- Error status from the function
+ */
+OMXResult armSwapElem(
+        OMX_U8 *pBuf1,
+        OMX_U8 *pBuf2,
+        OMX_INT elemSize
+       )
+{
+    OMX_INT i;
+    OMX_U8 temp;
+    armRetArgErrIf(!pBuf1 || !pBuf2, OMX_Sts_BadArgErr);
+    
+    for(i = 0; i < elemSize; i++)
+    {
+        temp = *(pBuf1 + i);
+        *(pBuf1 + i) = *(pBuf2 + i);
+        *(pBuf2 + i) = temp;
+    }
+    return OMX_Sts_NoErr;
+}
+
+/**
+ * Function: armMedianOf3
+ *
+ * Description: Finds the median of three numbers
+ * 
+ * Remarks:
+ *
+ * Parameters:
+ * [in] fEntry     First entry
+ * [in] sEntry     second entry
+ * [in] tEntry     Third entry
+ *
+ * Return Value:
+ * OMX_S32 --   returns the median value
+ */ 
+ 
+OMX_S32 armMedianOf3 (
+    OMX_S32 fEntry,
+    OMX_S32 sEntry, 
+    OMX_S32 tEntry 
+)
+{
+    OMX_S32 a, b, c;
+    
+    a = armMin (fEntry, sEntry);
+    b = armMax (fEntry, sEntry);
+    c = armMin (b, tEntry);
+    return (armMax (a, c));
+}
+
+/**
+ * Function: armLogSize
+ *
+ * Description: Finds the size of a positive value and returns the same
+ * 
+ * Remarks:
+ *
+ * Parameters:
+ * [in] value    Positive value
+ *
+ * Return Value:
+ * OMX_U8 --     Returns the minimum number of bits required to represent the positive value. 
+                 This is the smallest k>=0 such that that value is less than (1<<k).
+ */ 
+ 
+OMX_U8 armLogSize (
+    OMX_U16 value 
+)
+{
+    OMX_U8 i;    
+    for ( i = 0; value > 0; value = value >> 1) 
+    {
+        i++;
+    }
+    return i;
+}
+
+/***********************************************************************/
+                /* Saturating Arithmetic operations */
+
+/**
+ * Function :armSatAdd_S32()
+ *
+ * Description :
+ *   Returns the result of saturated addition of the two inputs Value1, Value2
+ *
+ * Parametrs:
+ * [in] Value1       First Operand
+ * [in] Value2       Second Operand
+ *
+ * Return:
+ * [out]             Result of operation
+ * 
+ *    
+ **/
+ 
+OMX_S32 armSatAdd_S32(OMX_S32 Value1,OMX_S32 Value2)
+{
+    OMX_S32 Result;
+    
+    Result = Value1 + Value2;
+
+    if( (Value1^Value2) >= 0)
+    {
+        /*Same sign*/
+        if( (Result^Value1) >= 0)
+        {
+            /*Result has not saturated*/
+            return Result;
+        }
+        else
+        {
+            if(Value1 >= 0)
+            {
+                /*Result has saturated in positive side*/
+                return OMX_MAX_S32;
+            }
+            else
+            {
+                /*Result has saturated in negative side*/
+                return OMX_MIN_S32;
+            }
+        
+        }
+   
+    }
+    else
+    {
+        return Result;
+    }
+    
+}
+
+/**
+ * Function :armSatAdd_S64()
+ *
+ * Description :
+ *   Returns the result of saturated addition of the two inputs Value1, Value2
+ *
+ * Parametrs:
+ * [in] Value1       First Operand
+ * [in] Value2       Second Operand
+ *
+ * Return:
+ * [out]             Result of operation
+ * 
+ *    
+ **/
+ 
+OMX_S64 armSatAdd_S64(OMX_S64 Value1,OMX_S64 Value2)
+{
+    OMX_S64 Result;
+    
+    Result = Value1 + Value2;
+
+    if( (Value1^Value2) >= 0)
+    {
+        /*Same sign*/
+        if( (Result^Value1) >= 0)
+        {
+            /*Result has not saturated*/
+            return Result;
+        }
+        else
+        {
+            if(Value1 >= 0)
+            {
+                /*Result has saturated in positive side*/
+                Result = OMX_MAX_S64;
+                return Result;
+            }
+            else
+            {
+                /*Result has saturated in negative side*/
+                return OMX_MIN_S64;
+            }
+        
+        }
+   
+    }
+    else
+    {
+        return Result;
+    }
+    
+}
+
+/** Function :armSatSub_S32()
+ * 
+ * Description :
+ *     Returns the result of saturated substraction of the two inputs Value1, Value2
+ *
+ * Parametrs:
+ * [in] Value1       First Operand
+ * [in] Value2       Second Operand
+ *
+ * Return:
+ * [out]             Result of operation
+ * 
+ **/
+
+OMX_S32 armSatSub_S32(OMX_S32 Value1,OMX_S32 Value2)
+{
+    OMX_S32 Result;
+    
+    Result = Value1 - Value2;
+
+    if( (Value1^Value2) < 0)
+    {
+        /*Opposite sign*/
+        if( (Result^Value1) >= 0)
+        {
+            /*Result has not saturated*/
+            return Result;
+        }
+        else
+        {
+            if(Value1 >= 0)
+            {
+                /*Result has saturated in positive side*/
+                return OMX_MAX_S32;
+            }
+            else
+            {
+                /*Result has saturated in negative side*/
+                return OMX_MIN_S32;
+            }
+        
+        }
+   
+    }
+    else
+    {
+        return Result;
+    }
+    
+}
+
+/**
+ * Function :armSatMac_S32()
+ *
+ * Description :
+ *     Returns the result of Multiplication of Value1 and Value2 and subesquent saturated
+ *     accumulation with Mac
+ *
+ * Parametrs:
+ * [in] Value1       First Operand
+ * [in] Value2       Second Operand
+ * [in] Mac          Accumulator
+ *
+ * Return:
+ * [out]             Result of operation
+ **/
+
+OMX_S32 armSatMac_S32(OMX_S32 Mac,OMX_S16 Value1,OMX_S16 Value2)
+{
+    OMX_S32 Result;
+    
+    Result = (OMX_S32)(Value1*Value2);
+    Result = armSatAdd_S32( Mac , Result );
+
+    return Result;    
+}
+
+/**
+ * Function :armSatMac_S16S32_S32
+ *
+ * Description :
+ *   Returns the result of saturated MAC operation of the three inputs delayElem, filTap , mac
+ *
+ *   mac = mac + Saturate_in_32Bits(delayElem * filTap)
+ *
+ * Parametrs:
+ * [in] delayElem    First 32 bit Operand
+ * [in] filTap       Second 16 bit Operand
+ * [in] mac          Result of MAC operation
+ *
+ * Return:
+ * [out]  mac        Result of operation
+ *    
+ **/
+ 
+OMX_S32 armSatMac_S16S32_S32(OMX_S32 mac, OMX_S32 delayElem, OMX_S16 filTap )
+{
+    
+    OMX_S32 result;
+
+    result = armSatMulS16S32_S32(filTap,delayElem); 
+
+    if ( result > OMX_MAX_S16 )
+    {
+        result = OMX_MAX_S32;
+    }
+    else if( result < OMX_MIN_S16 )
+    {
+        result = OMX_MIN_S32;
+    }
+    else
+    {
+        result = delayElem * filTap;
+    }
+
+    mac = armSatAdd_S32(mac,result);
+    
+    return mac;
+}
+
+
+/**
+ * Function :armSatRoundRightShift_S32_S16
+ *
+ * Description :
+ *   Returns the result of rounded right shift operation of input by the scalefactor
+ *
+ *   output = Saturate_in_16Bits( ( Right/LeftShift( (Round(input) , shift ) )
+ *
+ * Parametrs:
+ * [in] input       The input to be operated on
+ * [in] shift The shift number
+ *
+ * Return:
+ * [out]            Result of operation
+ *    
+ **/
+
+
+OMX_S16 armSatRoundRightShift_S32_S16(OMX_S32 input, OMX_INT shift)
+{
+    input = armSatRoundLeftShift_S32(input,-shift);
+
+    if ( input > OMX_MAX_S16 )
+    {
+        return (OMX_S16)OMX_MAX_S16;
+    }
+    else if (input < OMX_MIN_S16)
+    {
+        return (OMX_S16)OMX_MIN_S16;
+    }
+    else
+    {
+       return (OMX_S16)input;
+    }
+
+}
+
+/**
+ * Function :armSatRoundLeftShift_S32()
+ *
+ * Description :
+ *     Returns the result of saturating left-shift operation on input
+ *     Or rounded Right shift if the input Shift is negative.
+ *     
+ * Parametrs:
+ * [in] Value        Operand
+ * [in] Shift        Operand for shift operation
+ *
+ * Return:
+ * [out]             Result of operation
+ *    
+ **/
+
+OMX_S32 armSatRoundLeftShift_S32(OMX_S32 Value, OMX_INT Shift)
+{
+    OMX_INT i;
+    
+    if (Shift < 0)
+    {
+        Shift = -Shift;
+        Value = armSatAdd_S32(Value, (1 << (Shift - 1)));
+        Value = Value >> Shift;
+    }
+    else
+    {
+        for (i = 0; i < Shift; i++)
+        {
+            Value = armSatAdd_S32(Value, Value);
+        }
+    }
+    return Value;
+}
+
+/**
+ * Function :armSatRoundLeftShift_S64()
+ *
+ * Description :
+ *     Returns the result of saturating left-shift operation on input
+ *     Or rounded Right shift if the input Shift is negative.
+ *
+ * Parametrs:
+ * [in] Value        Operand
+ * [in] shift        Operand for shift operation
+ *
+ * Return:
+ * [out]             Result of operation
+ *    
+ **/
+ 
+OMX_S64 armSatRoundLeftShift_S64(OMX_S64 Value, OMX_INT Shift)
+{
+    OMX_INT i;
+    
+    if (Shift < 0)
+    {
+        Shift = -Shift;
+        Value = armSatAdd_S64(Value, ((OMX_S64)1 << (Shift - 1)));
+        Value = Value >> Shift;
+    }
+    else
+    {
+        for (i = 0; i < Shift; i++)
+        {
+            Value = armSatAdd_S64(Value, Value);
+        }
+    }
+    return Value;
+}
+
+/**
+ * Function :armSatMulS16S32_S32()
+ *
+ * Description :
+ *     Returns the result of a S16 data type multiplied with an S32 data type
+ *     in a S32 container
+ *
+ * Parametrs:
+ * [in] input1       Operand 1
+ * [in] input2       Operand 2
+ *
+ * Return:
+ * [out]             Result of operation
+ *    
+ **/
+
+
+OMX_S32 armSatMulS16S32_S32(OMX_S16 input1,OMX_S32 input2)
+{
+    OMX_S16 hi2,lo1;
+    OMX_U16 lo2;
+    
+    OMX_S32 temp1,temp2;
+    OMX_S32 result;
+    
+    lo1  = input1;
+
+    hi2  = ( input2 >>  16 );
+    lo2  = ( (OMX_U32)( input2 << 16 ) >> 16 );
+    
+    temp1 = hi2 * lo1;
+    temp2 = ( lo2* lo1 ) >> 16;
+
+    result =  armSatAdd_S32(temp1,temp2);
+
+    return result;
+}
+
+/**
+ * Function :armSatMulS32S32_S32()
+ *
+ * Description :
+ *     Returns the result of a S32 data type multiplied with an S32 data type
+ *     in a S32 container
+ *
+ * Parametrs:
+ * [in] input1       Operand 1
+ * [in] input2       Operand 2
+ *
+ * Return:
+ * [out]             Result of operation
+ *    
+ **/
+
+OMX_S32 armSatMulS32S32_S32(OMX_S32 input1,OMX_S32 input2)
+{
+    OMX_S16 hi1,hi2;
+    OMX_U16 lo1,lo2;
+    
+    OMX_S32 temp1,temp2,temp3;
+    OMX_S32 result;
+
+    hi1  = ( input1 >>  16 );
+    lo1  = ( (OMX_U32)( input1 << 16 ) >> 16 );
+
+    hi2  = ( input2 >>  16 );
+    lo2  = ( (OMX_U32)( input2 << 16 ) >> 16 );
+    
+    temp1 =   hi1 * hi2;
+    temp2 = ( hi1* lo2 ) >> 16;
+    temp3 = ( hi2* lo1 ) >> 16;
+
+    result = armSatAdd_S32(temp1,temp2);
+    result = armSatAdd_S32(result,temp3);
+
+    return result;
+}
+
+/**
+ * Function :armIntDivAwayFromZero()
+ *
+ * Description : Integer division with rounding to the nearest integer. 
+ *               Half-integer values are rounded away from zero
+ *               unless otherwise specified. For example 3//2 is rounded 
+ *               to 2, and -3//2 is rounded to -2.
+ *
+ * Parametrs:
+ * [in] Num        Operand 1
+ * [in] Deno       Operand 2
+ *
+ * Return:
+ * [out]             Result of operation input1//input2
+ *    
+ **/
+
+OMX_S32 armIntDivAwayFromZero (OMX_S32 Num, OMX_S32 Deno)
+{
+    OMX_F64 result;
+    
+    result = ((OMX_F64)Num)/((OMX_F64)Deno);
+    
+    if (result >= 0)
+    {
+        result += 0.5;
+    }
+    else
+    {
+        result -= 0.5;
+    }
+
+    return (OMX_S32)(result);
+}
+
+
+/*End of File*/
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/src/armCOMM_Bitstream.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/src/armCOMM_Bitstream.c
new file mode 100644
index 0000000..9ef9319
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/src/armCOMM_Bitstream.c
@@ -0,0 +1,329 @@
+/**
+ * 
+ * File Name:  armCOMM_Bitstream.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Defines bitstream encode and decode functions common to all codecs
+ */
+
+#include "omxtypes.h"
+#include "armCOMM.h"
+#include "armCOMM_Bitstream.h"
+
+/***************************************
+ * Fixed bit length Decode
+ ***************************************/
+
+/**
+ * Function: armLookAheadBits()
+ *
+ * Description:
+ * Get the next N bits from the bitstream without advancing the bitstream pointer
+ *
+ * Parameters:
+ * [in]     **ppBitStream
+ * [in]     *pOffset
+ * [in]     N=1...32
+ *
+ * Returns  Value
+ */
+
+OMX_U32 armLookAheadBits(const OMX_U8 **ppBitStream, OMX_INT *pOffset, OMX_INT N)
+{
+    const OMX_U8 *pBitStream = *ppBitStream;
+    OMX_INT Offset = *pOffset;
+    OMX_U32 Value;
+
+    armAssert(Offset>=0 && Offset<=7);
+    armAssert(N>=1 && N<=32);
+
+    /* Read next 32 bits from stream */
+    Value = (pBitStream[0] << 24 ) | ( pBitStream[1] << 16)  | (pBitStream[2] << 8 ) | (pBitStream[3]) ;
+    Value = (Value << Offset ) | (pBitStream[4] >> (8-Offset));
+
+    /* Return N bits */
+    return Value >> (32-N);
+}
+
+
+/**
+ * Function: armGetBits()
+ *
+ * Description:
+ * Read N bits from the bitstream
+ *    
+ * Parameters:
+ * [in]     *ppBitStream
+ * [in]     *pOffset
+ * [in]     N=1..32
+ *
+ * [out]    *ppBitStream
+ * [out]    *pOffset
+ * Returns  Value
+ */
+
+
+OMX_U32 armGetBits(const OMX_U8 **ppBitStream, OMX_INT *pOffset, OMX_INT N)
+{
+    const OMX_U8 *pBitStream = *ppBitStream;
+    OMX_INT Offset = *pOffset;
+    OMX_U32 Value;
+    
+    if(N == 0)
+    {
+      return 0;
+    }
+
+    armAssert(Offset>=0 && Offset<=7);
+    armAssert(N>=1 && N<=32);
+
+    /* Read next 32 bits from stream */
+    Value = (pBitStream[0] << 24 ) | ( pBitStream[1] << 16)  | (pBitStream[2] << 8 ) | (pBitStream[3]) ;
+    Value = (Value << Offset ) | (pBitStream[4] >> (8-Offset));
+
+    /* Advance bitstream pointer by N bits */
+    Offset += N;
+    *ppBitStream = pBitStream + (Offset>>3);
+    *pOffset = Offset & 7;
+
+    /* Return N bits */
+    return Value >> (32-N);
+}
+
+/**
+ * Function: armByteAlign()
+ *
+ * Description:
+ * Align the pointer *ppBitStream to the next byte boundary
+ *
+ * Parameters:
+ * [in]     *ppBitStream
+ * [in]     *pOffset
+ *
+ * [out]    *ppBitStream
+ * [out]    *pOffset
+ *
+ **/
+ 
+OMXVoid armByteAlign(const OMX_U8 **ppBitStream,OMX_INT *pOffset)
+{
+    if(*pOffset > 0)
+    {
+        *ppBitStream += 1;
+        *pOffset = 0;
+    }    
+}
+
+/** 
+ * Function: armSkipBits()
+ *
+ * Description:
+ * Skip N bits from the value at *ppBitStream
+ *
+ * Parameters:
+ * [in]     *ppBitStream
+ * [in]     *pOffset
+ * [in]     N
+ *
+ * [out]    *ppBitStream
+ * [out]    *pOffset
+ *
+ **/
+
+
+OMXVoid armSkipBits(const OMX_U8 **ppBitStream,OMX_INT *pOffset,OMX_INT N)
+{
+    OMX_INT Offset = *pOffset;
+    const OMX_U8 *pBitStream = *ppBitStream;
+   
+    /* Advance bitstream pointer by N bits */
+    Offset += N;
+    *ppBitStream = pBitStream + (Offset>>3);
+    *pOffset = Offset & 7;
+}
+
+/***************************************
+ * Variable bit length Decode
+ ***************************************/
+
+/**
+ * Function: armUnPackVLC32()
+ *
+ * Description:
+ * Variable length decode of variable length symbol (max size 32 bits) read from
+ * the bit stream pointed by *ppBitStream at *pOffset by using the table
+ * pointed by pCodeBook
+ * 
+ * Parameters:
+ * [in]     *pBitStream
+ * [in]     *pOffset
+ * [in]     pCodeBook
+ * 
+ * [out]    *pBitStream
+ * [out]    *pOffset
+ *
+ * Returns : Code Book Index if successfull. 
+ *         : ARM_NO_CODEBOOK_INDEX = -1 if search fails.
+ **/
+#ifndef C_OPTIMIZED_IMPLEMENTATION 
+
+OMX_U16 armUnPackVLC32(
+    const OMX_U8 **ppBitStream,
+    OMX_INT *pOffset,
+    const ARM_VLC32 *pCodeBook
+)
+{    
+    const OMX_U8 *pBitStream = *ppBitStream;
+    OMX_INT Offset = *pOffset;
+    OMX_U32 Value;
+    OMX_INT Index;
+        
+    armAssert(Offset>=0 && Offset<=7);
+
+    /* Read next 32 bits from stream */
+    Value = (pBitStream[0] << 24 ) | ( pBitStream[1] << 16)  | (pBitStream[2] << 8 ) | (pBitStream[3]) ;
+    Value = (Value << Offset ) | (pBitStream[4] >> (8-Offset));
+
+    /* Search through the codebook */    
+    for (Index=0; pCodeBook->codeLen != 0; Index++)
+    {
+        if (pCodeBook->codeWord == (Value >> (32 - pCodeBook->codeLen)))
+        {
+            Offset       = Offset + pCodeBook->codeLen;
+            *ppBitStream = pBitStream + (Offset >> 3) ;
+            *pOffset     = Offset & 7;
+            
+            return Index;
+        }        
+        pCodeBook++;
+    }
+
+    /* No code match found */
+    return ARM_NO_CODEBOOK_INDEX;
+}
+
+#endif
+
+/***************************************
+ * Fixed bit length Encode
+ ***************************************/
+
+/**
+ * Function: armPackBits
+ *
+ * Description:
+ * Pack a VLC code word into the bitstream
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] ppBitStream     pointer to the pointer to the current byte 
+ *                      in the bit stream.
+ * [in] pOffset         pointer to the bit position in the byte 
+ *                      pointed by *ppBitStream. Valid within 0
+ *                      to 7.
+ * [in] codeWord        Code word that need to be inserted in to the
+ *                          bitstream
+ * [in] codeLength      Length of the code word valid range 1...32
+ *
+ * [out] ppBitStream    *ppBitStream is updated after the block is encoded,
+ *                          so that it points to the current byte in the bit
+ *                          stream buffer.
+ * [out] pBitOffset     *pBitOffset is updated so that it points to the
+ *                          current bit position in the byte pointed by
+ *                          *ppBitStream.
+ *
+ * Return Value:
+ * Standard OMX_RESULT result. See enumeration for possible result codes.
+ *
+ */
+ 
+OMXResult armPackBits (
+    OMX_U8  **ppBitStream, 
+    OMX_INT *pOffset,
+    OMX_U32 codeWord, 
+    OMX_INT codeLength 
+)
+{
+    OMX_U8  *pBitStream = *ppBitStream;
+    OMX_INT Offset = *pOffset;
+    OMX_U32 Value;
+        
+    /* checking argument validity */
+    armRetArgErrIf(Offset < 0, OMX_Sts_BadArgErr);
+    armRetArgErrIf(Offset > 7, OMX_Sts_BadArgErr);
+    armRetArgErrIf(codeLength < 1, OMX_Sts_BadArgErr);
+    armRetArgErrIf(codeLength > 32, OMX_Sts_BadArgErr);
+
+    /* Prepare the first byte */
+    codeWord = codeWord << (32-codeLength);
+    Value = (pBitStream[0] >> (8-Offset)) << (8-Offset);
+    Value = Value | (codeWord >> (24+Offset));
+
+    /* Write out whole bytes */
+    while (8-Offset <= codeLength)
+    {
+        *pBitStream++ = (OMX_U8)Value;
+        codeWord   = codeWord  << (8-Offset);
+        codeLength = codeLength - (8-Offset);
+        Offset = 0;
+        Value = codeWord >> 24;
+    }
+
+    /* Write out final partial byte */
+    *pBitStream  = (OMX_U8)Value;
+    *ppBitStream = pBitStream;
+    *pOffset = Offset + codeLength;
+    
+    return  OMX_Sts_NoErr;
+}
+ 
+/***************************************
+ * Variable bit length Encode
+ ***************************************/
+
+/**
+ * Function: armPackVLC32
+ *
+ * Description:
+ * Pack a VLC code word into the bitstream
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	ppBitStream		pointer to the pointer to the current byte 
+ *                      in the bit stream.
+ * [in]	pBitOffset	    pointer to the bit position in the byte 
+ *                      pointed by *ppBitStream. Valid within 0
+ *                      to 7.
+ * [in]	 code     		VLC code word that need to be inserted in to the
+ *                      bitstream
+ *
+ * [out] ppBitStream	*ppBitStream is updated after the block is encoded,
+ *	                    so that it points to the current byte in the bit
+ *						stream buffer.
+ * [out] pBitOffset		*pBitOffset is updated so that it points to the
+ *						current bit position in the byte pointed by
+ *						*ppBitStream.
+ *
+ * Return Value:
+ * Standard OMX_RESULT result. See enumeration for possible result codes.
+ *
+ */
+ 
+OMXResult armPackVLC32 (
+    OMX_U8 **ppBitStream, 
+    OMX_INT *pBitOffset,
+    ARM_VLC32 code 
+)
+{
+    return (armPackBits(ppBitStream, pBitOffset, code.codeWord, code.codeLen));
+}
+
+/*End of File*/
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/api/armVC.h b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/api/armVC.h
new file mode 100644
index 0000000..7fa7716
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/api/armVC.h
@@ -0,0 +1,1153 @@
+/**
+ * 
+ * File Name:  armVC.h
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * File: armVideo.h
+ * Brief: Declares API's/Basic Data types used across the OpenMAX Video domain
+ *
+ */
+
+
+#ifndef _armVideo_H_
+#define _armVideo_H_
+
+#include "omxVC.h"
+#include "armCOMM_Bitstream.h"
+
+/**
+ * ARM specific state structure to hold Motion Estimation information.
+ */
+ 
+struct m4p2_MESpec
+{
+    OMXVCM4P2MEParams MEParams;
+    OMXVCM4P2MEMode   MEMode;
+};
+
+struct m4p10_MESpec
+{
+    OMXVCM4P10MEParams MEParams;
+    OMXVCM4P10MEMode   MEMode;
+};
+
+typedef struct m4p2_MESpec  ARMVCM4P2_MESpec;
+typedef struct m4p10_MESpec ARMVCM4P10_MESpec;
+
+/**
+ * Function: armVCM4P2_CompareMV
+ *
+ * Description:
+ * Performs comparision of motion vectors and SAD's to decide the
+ * best MV and SAD
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]     mvX     x coordinate of the candidate motion vector
+ * [in]     mvY     y coordinate of the candidate motion vector
+ * [in]     candSAD Candidate SAD
+ * [in]     bestMVX x coordinate of the best motion vector
+ * [in]     bestMVY y coordinate of the best motion vector
+ * [in]     bestSAD best SAD
+ *
+ * Return Value:
+ * OMX_INT -- 1 to indicate that the current sad is the best
+ *            0 to indicate that it is NOT the best SAD
+ */
+
+OMX_INT armVCM4P2_CompareMV (
+    OMX_S16 mvX,
+    OMX_S16 mvY,
+    OMX_INT candSAD,
+    OMX_S16 bestMVX,
+    OMX_S16 bestMVY,
+    OMX_INT bestSAD);
+
+/**
+ * Function: armVCM4P2_ACDCPredict
+ *
+ * Description:
+ * Performs adaptive DC/AC coefficient prediction for an intra block. Prior
+ * to the function call, prediction direction (predDir) should be selected
+ * as specified in subclause 7.4.3.1 of ISO/IEC 14496-2.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] pSrcDst     pointer to the coefficient buffer which contains
+ *                          the quantized coefficient residuals (PQF) of the
+ *                          current block
+ * [in] pPredBufRow pointer to the coefficient row buffer
+ * [in] pPredBufCol pointer to the coefficient column buffer
+ * [in] curQP       quantization parameter of the current block. curQP
+ *                          may equal to predQP especially when the current
+ *                          block and the predictor block are in the same
+ *                          macroblock.
+ * [in] predQP      quantization parameter of the predictor block
+ * [in] predDir     indicates the prediction direction which takes one
+ *                          of the following values:
+ *                          OMX_VIDEO_HORIZONTAL    predict horizontally
+ *                          OMX_VIDEO_VERTICAL      predict vertically
+ * [in] ACPredFlag  a flag indicating if AC prediction should be
+ *                          performed. It is equal to ac_pred_flag in the bit
+ *                          stream syntax of MPEG-4
+ * [in] videoComp   video component type (luminance, chrominance or
+ *                          alpha) of the current block
+ * [in] flag        This flag defines the if one wants to use this functions to
+ *                  calculate PQF (set 1, prediction) or QF (set 0, reconstruction)
+ * [out]    pPreACPredict   pointer to the predicted coefficients buffer.
+ *                          Filled ONLY if it is not NULL
+ * [out]    pSrcDst     pointer to the coefficient buffer which contains
+ *                          the quantized coefficients (QF) of the current
+ *                          block
+ * [out]    pPredBufRow pointer to the updated coefficient row buffer
+ * [out]    pPredBufCol pointer to the updated coefficient column buffer
+ * [out]    pSumErr     pointer to the updated sum of the difference
+ *                      between predicted and unpredicted coefficients
+ *                      If this is NULL, do not update
+ *
+ * Return Value:
+ * Standard OMXResult result. See enumeration for possible result codes.
+ *
+ */
+
+OMXResult armVCM4P2_ACDCPredict(
+     OMX_S16 * pSrcDst,
+     OMX_S16 * pPreACPredict,
+     OMX_S16 * pPredBufRow,
+     OMX_S16 * pPredBufCol,
+     OMX_INT curQP,
+     OMX_INT predQP,
+     OMX_INT predDir,
+     OMX_INT ACPredFlag,
+     OMXVCM4P2VideoComponent  videoComp,
+     OMX_U8 flag,
+     OMX_INT *pSumErr
+);
+
+/**
+ * Function: armVCM4P2_SetPredDir
+ *
+ * Description:
+ * Performs detecting the prediction direction
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] blockIndex  block index indicating the component type and
+ *                          position as defined in subclause 6.1.3.8, of ISO/IEC
+ *                          14496-2. Furthermore, indexes 6 to 9 indicate the
+ *                          alpha blocks spatially corresponding to luminance
+ *                          blocks 0 to 3 in the same macroblock.
+ * [in] pCoefBufRow pointer to the coefficient row buffer
+ * [in] pQpBuf      pointer to the quantization parameter buffer
+ * [out]    predQP      quantization parameter of the predictor block
+ * [out]    predDir     indicates the prediction direction which takes one
+ *                          of the following values:
+ *                          OMX_VIDEO_HORIZONTAL    predict horizontally
+ *                          OMX_VIDEO_VERTICAL      predict vertically
+ *
+ * Return Value:
+ * Standard OMXResult result. See enumeration for possible result codes.
+ *
+ */
+
+OMXResult armVCM4P2_SetPredDir(
+     OMX_INT blockIndex,
+     OMX_S16 *pCoefBufRow,
+     OMX_S16 *pCoefBufCol,
+     OMX_INT *predDir,
+     OMX_INT *predQP,
+     const OMX_U8 *pQpBuf
+);
+
+/**
+ * Function: armVCM4P2_EncodeVLCZigzag_Intra
+ *
+ * Description:
+ * Performs zigzag scanning and VLC encoding for one intra block.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] ppBitStream     pointer to the pointer to the current byte in
+ *                              the bit stream
+ * [in] pBitOffset      pointer to the bit position in the byte pointed
+ *                              by *ppBitStream. Valid within 0 to 7.
+ * [in] pQDctBlkCoef    pointer to the quantized DCT coefficient
+ * [in] predDir         AC prediction direction, which is used to decide
+ *                              the zigzag scan pattern. This takes one of the
+ *                              following values:
+ *                              OMX_VIDEO_NONE          AC prediction not used.
+ *                                                      Performs classical zigzag
+ *                                                      scan.
+ *                              OMX_VIDEO_HORIZONTAL    Horizontal prediction.
+ *                                                      Performs alternate-vertical
+ *                                                      zigzag scan.
+ *                              OMX_VIDEO_VERTICAL      Vertical prediction.
+ *                                                      Performs alternate-horizontal
+ *                                                      zigzag scan.
+ * [in] pattern         block pattern which is used to decide whether
+ *                              this block is encoded
+ * [in] start           start indicates whether the encoding begins with 0th element
+ *                      or 1st.
+ * [out]    ppBitStream     *ppBitStream is updated after the block is encoded,
+ *                              so that it points to the current byte in the bit
+ *                              stream buffer.
+ * [out]    pBitOffset      *pBitOffset is updated so that it points to the
+ *                              current bit position in the byte pointed by
+ *                              *ppBitStream.
+ *
+ * Return Value:
+ * Standard OMXResult result. See enumeration for possible result codes.
+ *
+ */
+
+OMXResult armVCM4P2_EncodeVLCZigzag_Intra(
+     OMX_U8 **ppBitStream,
+     OMX_INT *pBitOffset,
+     const OMX_S16 *pQDctBlkCoef,
+     OMX_U8 predDir,
+     OMX_U8 pattern,
+     OMX_INT shortVideoHeader,
+     OMX_U8 start
+);
+
+/**
+ * Function: armVCM4P2_DecodeVLCZigzag_Intra
+ *
+ * Description:
+ * Performs VLC decoding and inverse zigzag scan for one intra coded block.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] ppBitStream     pointer to the pointer to the current byte in
+ *                              the bitstream buffer
+ * [in] pBitOffset      pointer to the bit position in the byte pointed
+ *                              to by *ppBitStream. *pBitOffset is valid within
+ *                              [0-7].
+ * [in] predDir         AC prediction direction which is used to decide
+ *                              the zigzag scan pattern. It takes one of the
+ *                              following values:
+ *                              OMX_VIDEO_NONE  AC prediction not used;
+ *                                              perform classical zigzag scan;
+ *                              OMX_VIDEO_HORIZONTAL    Horizontal prediction;
+ *                                                      perform alternate-vertical
+ *                                                      zigzag scan;
+ *                              OMX_VIDEO_VERTICAL      Vertical prediction;
+ *                                                      thus perform
+ *                                                      alternate-horizontal
+ *                                                      zigzag scan.
+ * [in] videoComp       video component type (luminance, chrominance or
+ *                              alpha) of the current block
+ * [in] shortVideoHeader binary flag indicating presence of short_video_header; escape modes 0-3 are used if shortVideoHeader==0,
+ *                           and escape mode 4 is used when shortVideoHeader==1.
+ * [in] start           start indicates whether the encoding begins with 0th element
+ *                      or 1st.
+ * [out]    ppBitStream     *ppBitStream is updated after the block is
+ *                              decoded, so that it points to the current byte
+ *                              in the bit stream buffer
+ * [out]    pBitOffset      *pBitOffset is updated so that it points to the
+ *                              current bit position in the byte pointed by
+ *                              *ppBitStream
+ * [out]    pDst            pointer to the coefficient buffer of current
+ *                              block. Should be 32-bit aligned
+ *
+ * Return Value:
+ * Standard OMXResult result. See enumeration for possible result codes.
+ *
+ */
+
+OMXResult armVCM4P2_DecodeVLCZigzag_Intra(
+     const OMX_U8 ** ppBitStream,
+     OMX_INT * pBitOffset,
+     OMX_S16 * pDst,
+     OMX_U8 predDir,
+     OMX_INT shortVideoHeader, 
+     OMX_U8  start
+);
+
+/**
+ * Function: armVCM4P2_FillVLDBuffer
+ *
+ * Description:
+ * Performs filling of the coefficient buffer according to the run, level
+ * and sign, also updates the index
+ * 
+ * Parameters:
+ * [in]  storeRun        Stored Run value (count of zeros)   
+ * [in]  storeLevel      Stored Level value (non-zero value)
+ * [in]  sign            Flag indicating the sign of level
+ * [in]  last            status of the last flag
+ * [in]  pIndex          pointer to coefficient index in 8x8 matrix
+ * [out] pIndex          pointer to updated coefficient index in 8x8 
+ *                       matrix
+ * [in]  pZigzagTable    pointer to the zigzag tables
+ * [out] pDst            pointer to the coefficient buffer of current
+ *                       block. Should be 32-bit aligned
+ * Return Value:
+ * Standard OMXResult result. See enumeration for possible result codes.
+ *
+ */
+
+OMXResult armVCM4P2_FillVLDBuffer(
+    OMX_U32 storeRun,
+    OMX_S16 * pDst,
+    OMX_S16 storeLevel,
+    OMX_U8  sign,
+    OMX_U8  last,
+    OMX_U8  * index,
+    const OMX_U8 * pZigzagTable
+);
+
+/**
+ * Function: armVCM4P2_GetVLCBits
+ *
+ * Description:
+ * Performs escape mode decision based on the run, run+, level, level+ and 
+ * last combinations.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	ppBitStream		pointer to the pointer to the current byte in
+ *								the bit stream
+ * [in]	pBitOffset		pointer to the bit position in the byte pointed
+ *								by *ppBitStream. Valid within 0 to 7
+ * [in] shortVideoHeader binary flag indicating presence of short_video_header; escape modes 0-3 are used if shortVideoHeader==0,
+ *                           and escape mode 4 is used when shortVideoHeader==1.
+ * [in] start           start indicates whether the encoding begins with 
+ *                      0th element or 1st.
+ * [in/out] pLast       pointer to last status flag
+ * [in] runBeginSingleLevelEntriesL0      The run value from which level 
+ *                                        will be equal to 1: last == 0
+ * [in] IndexBeginSingleLevelEntriesL0    Array index in the VLC table 
+ *                                        pointing to the  
+ *                                        runBeginSingleLevelEntriesL0 
+ * [in] runBeginSingleLevelEntriesL1      The run value from which level 
+ *                                        will be equal to 1: last == 1
+ * [in] IndexBeginSingleLevelEntriesL1    Array index in the VLC table 
+ *                                        pointing to the  
+ *                                        runBeginSingleLevelEntriesL0 
+ * [in] pRunIndexTableL0    Run Index table defined in 
+ *                          armVCM4P2_Huff_Tables_VLC.c for last == 0
+ * [in] pVlcTableL0         VLC table for last == 0
+ * [in] pRunIndexTableL1    Run Index table defined in 
+ *                          armVCM4P2_Huff_Tables_VLC.c for last == 1
+ * [in] pVlcTableL1         VLC table for last == 1
+ * [in] pLMAXTableL0        Level MAX table defined in 
+ *                          armVCM4P2_Huff_Tables_VLC.c for last == 0
+ * [in] pLMAXTableL1        Level MAX table defined in 
+ *                          armVCM4P2_Huff_Tables_VLC.c for last == 1
+ * [in] pRMAXTableL0        Run MAX table defined in 
+ *                          armVCM4P2_Huff_Tables_VLC.c for last == 0
+ * [in] pRMAXTableL1        Run MAX table defined in 
+ *                          armVCM4P2_Huff_Tables_VLC.c for last == 1
+ * [out]pDst			    pointer to the coefficient buffer of current
+ *							block. Should be 32-bit aligned
+ *
+ * Return Value:
+ * Standard OMXResult result. See enumeration for possible result codes.
+ *
+ */
+
+OMXResult armVCM4P2_GetVLCBits (
+              const OMX_U8 **ppBitStream,
+              OMX_INT * pBitOffset,
+			  OMX_S16 * pDst,
+			  OMX_INT shortVideoHeader,
+			  OMX_U8    start,			  
+			  OMX_U8  * pLast,
+			  OMX_U8    runBeginSingleLevelEntriesL0,
+			  OMX_U8    maxIndexForMultipleEntriesL0,
+			  OMX_U8    maxRunForMultipleEntriesL1,
+			  OMX_U8    maxIndexForMultipleEntriesL1,
+              const OMX_U8  * pRunIndexTableL0,
+              const ARM_VLC32 *pVlcTableL0,
+			  const OMX_U8  * pRunIndexTableL1,
+              const ARM_VLC32 *pVlcTableL1,
+              const OMX_U8  * pLMAXTableL0,
+              const OMX_U8  * pLMAXTableL1,
+              const OMX_U8  * pRMAXTableL0,
+              const OMX_U8  * pRMAXTableL1,
+              const OMX_U8  * pZigzagTable
+);
+
+/**
+ * Function: armVCM4P2_PutVLCBits
+ *
+ * Description:
+ * Checks the type of Escape Mode and put encoded bits for 
+ * quantized DCT coefficients.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	 ppBitStream      pointer to the pointer to the current byte in
+ *						  the bit stream
+ * [in]	 pBitOffset       pointer to the bit position in the byte pointed
+ *                        by *ppBitStream. Valid within 0 to 7
+ * [in] shortVideoHeader binary flag indicating presence of short_video_header; escape modes 0-3 are used if shortVideoHeader==0,
+ *                           and escape mode 4 is used when shortVideoHeader==1.
+ * [in]  start            start indicates whether the encoding begins with 
+ *                        0th element or 1st.
+ * [in]  maxStoreRunL0    Max store possible (considering last and inter/intra)
+ *                        for last = 0
+ * [in]  maxStoreRunL1    Max store possible (considering last and inter/intra)
+ *                        for last = 1
+ * [in]  maxRunForMultipleEntriesL0 
+ *                        The run value after which level 
+ *                        will be equal to 1: 
+ *                        (considering last and inter/intra status) for last = 0
+ * [in]  maxRunForMultipleEntriesL1 
+ *                        The run value after which level 
+ *                        will be equal to 1: 
+ *                        (considering last and inter/intra status) for last = 1
+ * [in]  pRunIndexTableL0 Run Index table defined in 
+ *                        armVCM4P2_Huff_Tables_VLC.c for last == 0
+ * [in]  pVlcTableL0      VLC table for last == 0
+ * [in]  pRunIndexTableL1 Run Index table defined in 
+ *                        armVCM4P2_Huff_Tables_VLC.c for last == 1
+ * [in]  pVlcTableL1      VLC table for last == 1
+ * [in]  pLMAXTableL0     Level MAX table defined in 
+ *                        armVCM4P2_Huff_Tables_VLC.c for last == 0
+ * [in]  pLMAXTableL1     Level MAX table defined in 
+ *                        armVCM4P2_Huff_Tables_VLC.c for last == 1
+ * [in]  pRMAXTableL0     Run MAX table defined in 
+ *                        armVCM4P2_Huff_Tables_VLC.c for last == 0
+ * [in]  pRMAXTableL1     Run MAX table defined in 
+ *                        armVCM4P2_Huff_Tables_VLC.c for last == 1
+ * [out] pQDctBlkCoef     pointer to the quantized DCT coefficient
+ * [out] ppBitStream      *ppBitStream is updated after the block is encoded
+ *                        so that it points to the current byte in the bit
+ *                        stream buffer.
+ * [out] pBitOffset       *pBitOffset is updated so that it points to the
+ *                        current bit position in the byte pointed by
+ *                        *ppBitStream.
+ *
+ * Return Value:
+ * Standard OMXResult result. See enumeration for possible result codes.
+ *
+ */
+
+
+OMXResult armVCM4P2_PutVLCBits (
+              OMX_U8 **ppBitStream,
+              OMX_INT * pBitOffset,
+              const OMX_S16 *pQDctBlkCoef,
+              OMX_INT shortVideoHeader,
+              OMX_U8 start,
+              OMX_U8 maxStoreRunL0,
+              OMX_U8 maxStoreRunL1,
+              OMX_U8  maxRunForMultipleEntriesL0,
+              OMX_U8  maxRunForMultipleEntriesL1,
+              const OMX_U8  * pRunIndexTableL0,
+              const ARM_VLC32 *pVlcTableL0,
+			  const OMX_U8  * pRunIndexTableL1,
+              const ARM_VLC32 *pVlcTableL1,
+              const OMX_U8  * pLMAXTableL0,
+              const OMX_U8  * pLMAXTableL1,
+              const OMX_U8  * pRMAXTableL0,
+              const OMX_U8  * pRMAXTableL1,
+              const OMX_U8  * pZigzagTable
+);
+/**
+ * Function: armVCM4P2_FillVLCBuffer
+ *
+ * Description:
+ * Performs calculating the VLC bits depending on the escape type and insert 
+ * the same in the bitstream
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	 ppBitStream		pointer to the pointer to the current byte in
+ *	                        the bit stream
+ * [in]	 pBitOffset         pointer to the bit position in the byte pointed
+ *                          by *ppBitStream. Valid within 0 to 7
+ * [in]  run                Run value (count of zeros) to be encoded  
+ * [in]  level              Level value (non-zero value) to be encoded
+ * [in]  runPlus            Calculated as runPlus = run - (RMAX + 1)  
+ * [in]  levelPlus          Calculated as 
+ *                          levelPlus = sign(level)*[abs(level) - LMAX]
+ * [in]  fMode              Flag indicating the escape modes
+ * [in]  last               status of the last flag
+ * [in]  maxRunForMultipleEntries 
+ *                          The run value after which level will be equal to 1: 
+ *                          (considering last and inter/intra status)
+ * [in]  pRunIndexTable     Run Index table defined in
+ *                          armVCM4P2_Huff_tables_VLC.h
+ * [in]  pVlcTable          VLC table defined in armVCM4P2_Huff_tables_VLC.h
+ * [out] ppBitStream		*ppBitStream is updated after the block is encoded
+ *                          so that it points to the current byte in the bit
+ *                          stream buffer.
+ * [out] pBitOffset         *pBitOffset is updated so that it points to the
+ *                          current bit position in the byte pointed by
+ *                          *ppBitStream.
+ *
+ * Return Value:
+ * Standard OMXResult result. See enumeration for possible result codes.
+ *
+ */
+
+OMXResult armVCM4P2_FillVLCBuffer (
+              OMX_U8 **ppBitStream,
+              OMX_INT * pBitOffset,
+              OMX_U32 run,
+              OMX_S16 level, 
+			  OMX_U32 runPlus,
+              OMX_S16 levelPlus, 
+              OMX_U8  fMode,
+			  OMX_U8  last,
+              OMX_U8  maxRunForMultipleEntries, 
+              const OMX_U8  *pRunIndexTable,
+              const ARM_VLC32 *pVlcTable
+);
+
+/**
+ * Function: armVCM4P2_CheckVLCEscapeMode
+ *
+ * Description:
+ * Performs escape mode decision based on the run, run+, level, level+ and 
+ * last combinations.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] run             Run value (count of zeros) to be encoded  
+ * [in] level           Level value (non-zero value) to be encoded
+ * [in] runPlus         Calculated as runPlus = run - (RMAX + 1)  
+ * [in] levelPlus       Calculated as 
+ *                      levelPlus = sign(level)*[abs(level) - LMAX]
+ * [in] maxStoreRun     Max store possible (considering last and inter/intra)
+ * [in] maxRunForMultipleEntries 
+ *                      The run value after which level 
+ *                      will be equal to 1: 
+ *                      (considering last and inter/intra status)
+ * [in] shortVideoHeader binary flag indicating presence of short_video_header; escape modes 0-3 are used if shortVideoHeader==0,
+ *                           and escape mode 4 is used when shortVideoHeader==1.
+ * [in] pRunIndexTable  Run Index table defined in 
+ *                      armVCM4P2_Huff_Tables_VLC.c
+ *                      (considering last and inter/intra status)
+ *
+ *                      
+ * Return Value:
+ * Returns an Escape mode which can take values from 0 to 3
+ * 0 --> no escape mode, 1 --> escape type 1,
+ * 1 --> escape type 2, 3 --> escape type 3, check section 7.4.1.3
+ * in the MPEG ISO standard.
+ *
+ */
+
+OMX_U8 armVCM4P2_CheckVLCEscapeMode(
+     OMX_U32 run,
+     OMX_U32 runPlus,
+     OMX_S16 level,
+     OMX_S16 levelPlus,
+     OMX_U8  maxStoreRun,
+     OMX_U8  maxRunForMultipleEntries,
+     OMX_INT shortVideoHeader,
+     const OMX_U8  *pRunIndexTable
+);
+
+
+/**
+ * Function: armVCM4P2_BlockMatch_Integer
+ *
+ * Description:
+ * Performs a 16x16 block search; estimates motion vector and associated minimum SAD.  
+ * Both the input and output motion vectors are represented using half-pixel units, and 
+ * therefore a shift left or right by 1 bit may be required, respectively, to match the 
+ * input or output MVs with other functions that either generate output MVs or expect 
+ * input MVs represented using integer pixel units. 
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	pSrcRefBuf		pointer to the reference Y plane; points to the reference MB that 
+ *                    corresponds to the location of the current macroblock in the current 
+ *                    plane.
+ * [in]	refWidth		  width of the reference plane
+ * [in]	pRefRect		  pointer to the valid rectangular in reference plane. Relative to image origin. 
+ *                    It's not limited to the image boundary, but depended on the padding. For example, 
+ *                    if you pad 4 pixels outside the image border, then the value for left border 
+ *                    can be -4
+ * [in]	pSrcCurrBuf		pointer to the current macroblock extracted from original plane (linear array, 
+ *                    256 entries); must be aligned on an 8-byte boundary.
+ * [in] pCurrPointPos	position of the current macroblock in the current plane
+ * [in] pSrcPreMV		  pointer to predicted motion vector; NULL indicates no predicted MV
+ * [in] pSrcPreSAD		pointer to SAD associated with the predicted MV (referenced by pSrcPreMV)
+ * [in] searchRange		search range for 16X16 integer block,the units of it is full pixel,the search range 
+ *                    is the same in all directions.It is in inclusive of the boundary and specified in 
+ *                    terms of integer pixel units.
+ * [in] pMESpec			  vendor-specific motion estimation specification structure; must have been allocated 
+ *                    and then initialized using omxVCM4P2_MEInit prior to calling the block matching 
+ *                    function.
+ * [in] BlockSize     MacroBlock Size i.e either 16x16 or 8x8.
+ * [out]	pDstMV			pointer to estimated MV
+ * [out]	pDstSAD			pointer to minimum SAD
+ *
+ * Return Value:
+ * OMX_Sts_NoErr ¨C no error.
+ * OMX_Sts_BadArgErr ¨C bad arguments
+ *
+ */
+
+OMXResult armVCM4P2_BlockMatch_Integer(
+     const OMX_U8 *pSrcRefBuf,
+     OMX_INT refWidth,
+     const OMXRect *pRefRect,
+     const OMX_U8 *pSrcCurrBuf,
+     const OMXVCM4P2Coordinate *pCurrPointPos,
+     const OMXVCMotionVector *pSrcPreMV,
+     const OMX_INT *pSrcPreSAD,
+     void *pMESpec,
+     OMXVCMotionVector *pDstMV,
+     OMX_INT *pDstSAD,
+     OMX_U8 BlockSize
+);
+
+/**
+ * Function: armVCM4P2_BlockMatch_Half
+ *
+ * Description:
+ * Performs a 16x16 block match with half-pixel resolution.  Returns the estimated 
+ * motion vector and associated minimum SAD.  This function estimates the half-pixel 
+ * motion vector by interpolating the integer resolution motion vector referenced 
+ * by the input parameter pSrcDstMV, i.e., the initial integer MV is generated 
+ * externally.  The input parameters pSrcRefBuf and pSearchPointRefPos should be 
+ * shifted by the winning MV of 16x16 integer search prior to calling BlockMatch_Half_16x16.  
+ * The function BlockMatch_Integer_16x16 may be used for integer motion estimation.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	pSrcRefBuf		pointer to the reference Y plane; points to the reference MB 
+ *                    that corresponds to the location of the current macroblock in 
+ *                    the	current plane.
+ * [in]	refWidth		  width of the reference plane
+ * [in]	pRefRect		  reference plane valid region rectangle
+ * [in]	pSrcCurrBuf		pointer to the current macroblock extracted from original plane 
+ *                    (linear array, 256 entries); must be aligned on an 8-byte boundary. 
+ * [in]	pSearchPointRefPos	position of the starting point for half pixel search (specified 
+ *                          in terms of integer pixel units) in the reference plane.
+ * [in]	rndVal			  rounding control bit for half pixel motion estimation; 
+ *                    0=rounding control disabled; 1=rounding control enabled
+ * [in]	pSrcDstMV		pointer to the initial MV estimate; typically generated during a prior 
+ *                  16X16 integer search and its unit is half pixel.
+ * [in] BlockSize     MacroBlock Size i.e either 16x16 or 8x8.
+ * [out]pSrcDstMV		pointer to estimated MV
+ * [out]pDstSAD			pointer to minimum SAD
+ *
+ * Return Value:
+ * OMX_Sts_NoErr ¨C no error
+ * OMX_Sts_BadArgErr ¨C bad arguments
+ *
+ */
+
+OMXResult armVCM4P2_BlockMatch_Half(
+     const OMX_U8 *pSrcRefBuf,
+     OMX_INT refWidth,
+     const OMXRect *pRefRect,
+     const OMX_U8 *pSrcCurrBuf,
+     const OMXVCM4P2Coordinate *pSearchPointRefPos,
+     OMX_INT rndVal,
+     OMXVCMotionVector *pSrcDstMV,
+     OMX_INT *pDstSAD,
+     OMX_U8 BlockSize
+);
+/**
+ * Function: armVCM4P2_PadMV
+ *
+ * Description:
+ * Performs motion vector padding for a macroblock.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] pSrcDstMV       pointer to motion vector buffer of the current
+ *                              macroblock
+ * [in] pTransp         pointer to transparent status buffer of the
+ *                              current macroblock
+ * [out]    pSrcDstMV       pointer to motion vector buffer in which the
+ *                              motion vectors have been padded
+ * Return Value:
+ * Standard OMXResult result. See enumeration for possible result codes.
+ *
+ */
+
+OMXResult armVCM4P2_PadMV(
+     OMXVCMotionVector * pSrcDstMV,
+     OMX_U8 * pTransp
+);
+
+/* 
+ * H.264 Specific Declarations 
+ */
+/* Defines */
+#define ARM_M4P10_Q_OFFSET        (15)
+
+
+/* Dequant tables */
+
+extern const OMX_U8 armVCM4P10_PosToVCol4x4[16];
+extern const OMX_U8 armVCM4P10_PosToVCol2x2[4];
+extern const OMX_U8 armVCM4P10_VMatrix[6][3];
+extern const OMX_U32 armVCM4P10_MFMatrix[6][3];
+
+
+/*
+ * Description:
+ * This function perform the work required by the OpenMAX
+ * DecodeCoeffsToPair function and DecodeChromaDCCoeffsToPair.
+ * Since most of the code is common we share it here.
+ *
+ * Parameters:
+ * [in]	ppBitStream		Double pointer to current byte in bit stream buffer
+ * [in]	pOffset			Pointer to current bit position in the byte pointed
+ *								to by *ppBitStream
+ * [in]	sMaxNumCoeff	Maximum number of non-zero coefficients in current
+ *								block (4,15 or 16)
+ * [in]	nTable          Table number (0 to 4) according to the five columns
+ *                      of Table 9-5 in the H.264 spec
+ * [out]	ppBitStream		*ppBitStream is updated after each block is decoded
+ * [out]	pOffset			*pOffset is updated after each block is decoded
+ * [out]	pNumCoeff		Pointer to the number of nonzero coefficients in
+ *								this block
+ * [out]	ppPosCoefbuf	Double pointer to destination residual
+ *								coefficient-position pair buffer
+ * Return Value:
+ * Standard omxError result. See enumeration for possible result codes.
+
+ */
+
+OMXResult armVCM4P10_DecodeCoeffsToPair(
+     const OMX_U8** ppBitStream,
+     OMX_S32* pOffset,
+     OMX_U8* pNumCoeff,
+     OMX_U8**ppPosCoefbuf,
+     OMX_INT nTable,
+     OMX_INT sMaxNumCoeff        
+ );
+
+/*
+ * Description:
+ * Perform DC style intra prediction, averaging upper and left block
+ *
+ * Parameters:
+ * [in]	pSrcLeft		Pointer to the buffer of 16 left coefficients:
+ *								p[x, y] (x = -1, y = 0..3)
+ * [in]	pSrcAbove		Pointer to the buffer of 16 above coefficients:
+ *								p[x,y] (x = 0..3, y = -1)
+ * [in]	leftStep		Step of left coefficient buffer
+ * [in]	dstStep			Step of the destination buffer
+ * [in]	availability	Neighboring 16x16 MB availability flag
+ * [out]	pDst			Pointer to the destination buffer
+ *
+ * Return Value:
+ * None
+ */
+
+void armVCM4P10_PredictIntraDC4x4(
+     const OMX_U8* pSrcLeft,
+     const OMX_U8 *pSrcAbove,
+     OMX_U8* pDst,
+     OMX_INT leftStep,
+     OMX_INT dstStep,
+     OMX_S32 availability        
+);
+
+/*
+ * Description
+ * Unpack a 4x4 block of coefficient-residual pair values
+ *
+ * Parameters:
+ * [in]	ppSrc	Double pointer to residual coefficient-position pair
+ *						buffer output by CALVC decoding
+ * [out]	ppSrc	*ppSrc is updated to the start of next non empty block
+ * [out]	pDst	Pointer to unpacked 4x4 block
+ */
+
+void armVCM4P10_UnpackBlock4x4(
+     const OMX_U8 **ppSrc,
+     OMX_S16* pDst
+);
+
+/*
+ * Description
+ * Unpack a 2x2 block of coefficient-residual pair values
+ *
+ * Parameters:
+ * [in]	ppSrc	Double pointer to residual coefficient-position pair
+ *						buffer output by CALVC decoding
+ * [out]	ppSrc	*ppSrc is updated to the start of next non empty block
+ * [out]	pDst	Pointer to unpacked 4x4 block
+ */
+
+void armVCM4P10_UnpackBlock2x2(
+     const OMX_U8 **ppSrc,
+     OMX_S16* pDst
+);
+
+/*
+ * Description
+ * Deblock one boundary pixel
+ *
+ * Parameters:
+ * [in]	pQ0         Pointer to pixel q0
+ * [in] Step        Step between pixels q0 and q1
+ * [in] tC0         Edge threshold value
+ * [in] alpha       alpha threshold value
+ * [in] beta        beta threshold value
+ * [in] bS          deblocking strength
+ * [in] ChromaFlag  True for chroma blocks
+ * [out] pQ0        Deblocked pixels
+ * 
+ */
+
+void armVCM4P10_DeBlockPixel(
+    OMX_U8 *pQ0,    /* pointer to the pixel q0 */
+    int Step,       /* step between pixels q0 and q1 */
+    int tC0,        /* edge threshold value */
+    int alpha,      /* alpha */
+    int beta,       /* beta */
+    int bS,         /* deblocking strength */
+    int ChromaFlag
+);
+
+/**
+ * Function: armVCM4P10_InterpolateHalfHor_Luma
+ *
+ * Description:
+ * This function performs interpolation for horizontal 1/2-pel positions
+ *
+ * Remarks:
+ *
+ *	[in]	pSrc			Pointer to top-left corner of block used to interpolate 
+ 													in the reconstructed frame plane
+ *	[in]	iSrcStep	Step of the source buffer.
+ *	[in]	iDstStep	Step of the destination(interpolation) buffer.
+ *	[in]	iWidth		Width of the current block
+ *	[in]	iHeight		Height of the current block
+ *	[out]	pDst	    Pointer to the interpolation buffer of the 1/2-pel 
+ *
+ * Return Value:
+ * Standard OMXResult value.
+ *
+ */
+
+OMXResult armVCM4P10_InterpolateHalfHor_Luma(
+        const OMX_U8*		pSrc, 
+		OMX_U32 	iSrcStep, 
+		OMX_U8* 	pDst, 
+		OMX_U32 	iDstStep, 
+		OMX_U32 	iWidth, 
+		OMX_U32 	iHeight
+);
+
+/**
+ * Function: armVCM4P10_InterpolateHalfVer_Luma
+ * 
+ * Description:
+ * This function performs interpolation for vertical 1/2-pel positions 
+ * around a full-pel position.
+ *
+ * Remarks:
+ *
+ *	[in]	pSrc			Pointer to top-left corner of block used to interpolate 
+ *												in the reconstructed frame plane
+ *	[in]	iSrcStep	Step of the source buffer.
+ *	[in]	iDstStep	Step of the destination(interpolation) buffer.
+ *	[in]	iWidth		Width of the current block
+ *	[in]	iHeight		Height of the current block
+ *	[out]	pDst    	Pointer to the interpolation buffer of the 1/2-pel
+ *
+ * Return Value:
+ * Standard OMXResult value.
+ *
+ */
+
+OMXResult armVCM4P10_InterpolateHalfVer_Luma(	
+	 const OMX_U8* 	pSrc, 
+	 OMX_U32 	iSrcStep, 
+ 	 OMX_U8* 	pDst,
+ 	 OMX_U32 	iDstStep, 
+ 	 OMX_U32 	iWidth, 
+ 	 OMX_U32 	iHeight
+);
+
+/**
+ * Function: armVCM4P10_InterpolateHalfDiag_Luma
+ * 
+ * Description:
+ * This function performs interpolation for (1/2, 1/2)  positions 
+ * around a full-pel position.
+ *
+ * Remarks:
+ *
+ *  [in]    pSrc        Pointer to top-left corner of block used to interpolate 
+ *                      in the reconstructed frame plane
+ *  [in]    iSrcStep    Step of the source buffer.
+ *  [in]    iDstStep    Step of the destination(interpolation) buffer.
+ *  [in]    iWidth      Width of the current block
+ *  [in]    iHeight     Height of the current block
+ *  [out]   pDst        Pointer to the interpolation buffer of the (1/2,1/2)-pel
+ *
+ * Return Value:
+ * Standard OMXResult value.
+ *
+ */
+
+OMXResult armVCM4P10_InterpolateHalfDiag_Luma(  
+        const OMX_U8*     pSrc, 
+        OMX_U32     iSrcStep, 
+        OMX_U8*     pDst, 
+        OMX_U32     iDstStep,
+        OMX_U32     iWidth, 
+        OMX_U32     iHeight
+);
+
+/*
+ * Description:
+ * Transform Residual 4x4 Coefficients
+ *
+ * Parameters:
+ * [in]  pSrc		Source 4x4 block
+ * [out] pDst		Destination 4x4 block
+ *
+ */
+
+void armVCM4P10_TransformResidual4x4(OMX_S16* pDst, OMX_S16 *pSrc);
+
+/*
+ * Description:
+ * Forward Transform Residual 4x4 Coefficients
+ *
+ * Parameters:
+ * [in]  pSrc		Source 4x4 block
+ * [out] pDst		Destination 4x4 block
+ *
+ */
+
+void armVCM4P10_FwdTransformResidual4x4(OMX_S16* pDst, OMX_S16 *pSrc);
+
+OMX_INT armVCM4P10_CompareMotionCostToMV (
+    OMX_S16  mvX,
+    OMX_S16  mvY,
+    OMXVCMotionVector diffMV, 
+    OMX_INT candSAD, 
+    OMXVCMotionVector *bestMV, 
+    OMX_U32 nLamda,
+    OMX_S32 *pBestCost);
+
+/**
+ * Function: armVCCOMM_SAD
+ *
+ * Description:
+ * This function calculate the SAD for NxM blocks.
+ *
+ * Remarks:
+ *
+ * [in]		pSrcOrg		Pointer to the original block
+ * [in]		iStepOrg	Step of the original block buffer
+ * [in]		pSrcRef		Pointer to the reference block
+ * [in]		iStepRef	Step of the reference block buffer
+ * [in]		iHeight		Height of the block
+ * [in]		iWidth		Width of the block
+ * [out]	pDstSAD		Pointer of result SAD
+ *
+ * Return Value:
+ * Standard OMXResult value.
+ *
+ */
+OMXResult armVCCOMM_SAD(	
+	const OMX_U8* 	pSrcOrg,
+	OMX_U32 	iStepOrg,
+	const OMX_U8* 	pSrcRef,
+	OMX_U32 	iStepRef,
+	OMX_S32*	pDstSAD,
+	OMX_U32		iHeight,
+	OMX_U32		iWidth);
+
+/**
+ * Function: armVCCOMM_Average
+ *
+ * Description:
+ * This function calculates the average of two blocks and stores the result.
+ *
+ * Remarks:
+ *
+ *	[in]	pPred0			Pointer to the top-left corner of reference block 0
+ *	[in]	pPred1			Pointer to the top-left corner of reference block 1
+ *	[in]	iPredStep0	    Step of reference block 0
+ *	[in]	iPredStep1	    Step of reference block 1
+ *	[in]	iDstStep 		Step of the destination buffer
+ *	[in]	iWidth			Width of the blocks
+ *	[in]	iHeight			Height of the blocks
+ *	[out]	pDstPred		Pointer to the destination buffer
+ *
+ * Return Value:
+ * Standard OMXResult value.
+ *
+ */
+ OMXResult armVCCOMM_Average (
+	 const OMX_U8* 	    pPred0,
+	 const OMX_U8* 	    pPred1,	
+	 OMX_U32		iPredStep0,
+	 OMX_U32		iPredStep1,
+	 OMX_U8*		pDstPred,
+	 OMX_U32		iDstStep, 
+	 OMX_U32		iWidth,
+	 OMX_U32		iHeight
+);
+
+/**
+ * Function: armVCM4P10_SADQuar
+ *
+ * Description:
+ * This function calculates the SAD between one block (pSrc) and the 
+ * average of the other two (pSrcRef0 and pSrcRef1)
+ *
+ * Remarks:
+ *
+ * [in]		pSrc				Pointer to the original block
+ * [in]		pSrcRef0		Pointer to reference block 0
+ * [in]		pSrcRef1		Pointer to reference block 1
+ * [in]		iSrcStep 		Step of the original block buffer
+ * [in]		iRefStep0		Step of reference block 0 
+ * [in]		iRefStep1 	Step of reference block 1 
+ * [in]		iHeight			Height of the block
+ * [in]		iWidth			Width of the block
+ * [out]	pDstSAD			Pointer of result SAD
+ *
+ * Return Value:
+ * Standard OMXResult value.
+ *
+ */
+OMXResult armVCM4P10_SADQuar(
+	const OMX_U8* 	pSrc,
+    const OMX_U8* 	pSrcRef0,
+	const OMX_U8* 	pSrcRef1,	
+    OMX_U32 	iSrcStep,
+    OMX_U32		iRefStep0,
+    OMX_U32		iRefStep1,
+    OMX_U32*	pDstSAD,
+    OMX_U32     iHeight,
+    OMX_U32     iWidth
+);
+
+/**
+ * Function: armVCM4P10_Interpolate_Chroma
+ *
+ * Description:
+ * This function performs interpolation for chroma components.
+ *
+ * Remarks:
+ *
+ *  [in]    pSrc            Pointer to top-left corner of block used to 
+ *                                              interpolate in the reconstructed frame plane
+ *  [in]    iSrcStep    Step of the source buffer.
+ *  [in]    iDstStep    Step of the destination(interpolation) buffer.
+ *  [in]    iWidth      Width of the current block
+ *  [in]    iHeight     Height of the current block
+ *  [in]    dx              Fractional part of horizontal motion vector 
+ *                                              component in 1/8 pixel unit (0~7) 
+ *  [in]    dy              Fractional part of vertical motion vector 
+ *                                              component in 1/8 pixel unit (0~7)
+ *  [out]   pDst            Pointer to the interpolation buffer
+ *
+ * Return Value:
+ * Standard OMXResult value.
+ *
+ */
+ OMXResult armVCM4P10_Interpolate_Chroma(
+        OMX_U8      *pSrc,
+        OMX_U32     iSrcStep,
+        OMX_U8      *pDst,
+        OMX_U32     iDstStep,
+        OMX_U32     iWidth,
+        OMX_U32     iHeight,
+        OMX_U32     dx,
+        OMX_U32     dy
+);
+
+/**
+ * Function: armVCM4P10_Interpolate_Luma
+ *
+ * Description:
+ * This function performs interpolation for luma components.
+ *
+ * Remarks:
+ *
+ *  [in]    pSrc            Pointer to top-left corner of block used to 
+ *                                              interpolate in the reconstructed frame plane
+ *  [in]    iSrcStep    Step of the source buffer.
+ *  [in]    iDstStep    Step of the destination(interpolation) buffer.
+ *  [in]    iWidth      Width of the current block
+ *  [in]    iHeight     Height of the current block
+ *  [in]    dx              Fractional part of horizontal motion vector 
+ *                                              component in 1/4 pixel unit (0~3) 
+ *  [in]    dy              Fractional part of vertical motion vector 
+ *                                              component in 1/4 pixel unit (0~3) 
+ *  [out]   pDst            Pointer to the interpolation buffer
+ *
+ * Return Value:
+ * Standard OMXResult value.
+ *
+ */
+
+ OMXResult armVCM4P10_Interpolate_Luma(
+     const OMX_U8     *pSrc,
+     OMX_U32    iSrcStep,
+     OMX_U8     *pDst,
+     OMX_U32    iDstStep,
+     OMX_U32    iWidth,
+     OMX_U32    iHeight,
+     OMX_U32    dx,
+     OMX_U32    dy
+);
+
+/**
+ * Function: omxVCH264_DequantTransformACFromPair_U8_S16_C1_DLx
+ *
+ * Description:
+ * Reconstruct the 4x4 residual block from coefficient-position pair buffer,
+ * perform dequantisation and integer inverse transformation for 4x4 block of
+ * residuals and update the pair buffer pointer to next non-empty block.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	ppSrc		Double pointer to residual coefficient-position
+ *							pair buffer output by CALVC decoding
+ * [in]	pDC			Pointer to the DC coefficient of this block, NULL
+ *							if it doesn't exist
+ * [in]	QP			Quantization parameter
+ * [in] AC          Flag indicating if at least one non-zero coefficient exists
+ * [out]	pDst		pointer to the reconstructed 4x4 block data
+ *
+ * Return Value:
+ * Standard omxError result. See enumeration for possible result codes.
+ *
+ */
+
+OMXResult armVCM4P10_DequantTransformACFromPair_U8_S16_C1_DLx(
+     OMX_U8 **ppSrc,
+     OMX_S16 *pDst,
+     OMX_INT QP,
+     OMX_S16* pDC,
+     int AC
+);
+
+#endif  /*_armVideo_H_*/
+
+/*End of File*/
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/api/omxVC.h b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/api/omxVC.h
new file mode 100644
index 0000000..7b3cc72
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/api/omxVC.h
@@ -0,0 +1,4381 @@
+/**
+ * File: omxVC.h
+ * Brief: OpenMAX DL v1.0.2 - Video Coding library
+ *
+ * Copyright © 2005-2008 The Khronos Group Inc. All Rights Reserved. 
+ *
+ * These materials are protected by copyright laws and contain material 
+ * proprietary to the Khronos Group, Inc.  You may use these materials 
+ * for implementing Khronos specifications, without altering or removing 
+ * any trademark, copyright or other notice from the specification.
+ * 
+ * Khronos Group makes no, and expressly disclaims any, representations 
+ * or warranties, express or implied, regarding these materials, including, 
+ * without limitation, any implied warranties of merchantability or fitness 
+ * for a particular purpose or non-infringement of any intellectual property. 
+ * Khronos Group makes no, and expressly disclaims any, warranties, express 
+ * or implied, regarding the correctness, accuracy, completeness, timeliness, 
+ * and reliability of these materials. 
+ *
+ * Under no circumstances will the Khronos Group, or any of its Promoters, 
+ * Contributors or Members or their respective partners, officers, directors, 
+ * employees, agents or representatives be liable for any damages, whether 
+ * direct, indirect, special or consequential damages for lost revenues, 
+ * lost profits, or otherwise, arising from or in connection with these 
+ * materials.
+ * 
+ * Khronos and OpenMAX are trademarks of the Khronos Group Inc. 
+ *
+ */
+
+/* *****************************************************************************************/
+
+#ifndef _OMXVC_H_
+#define _OMXVC_H_
+
+#include "omxtypes.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* 6.1.1.1 Motion Vectors  */
+/* In omxVC, motion vectors are represented as follows:  */
+
+typedef struct {
+    OMX_S16 dx;
+    OMX_S16 dy;
+} OMXVCMotionVector;
+
+
+
+/**
+ * Function:  omxVCCOMM_Average_8x   (6.1.3.1.1)
+ *
+ * Description:
+ * This function calculates the average of two 8x4, 8x8, or 8x16 blocks.  The 
+ * result is rounded according to (a+b+1)/2.  The block average function can 
+ * be used in conjunction with half-pixel interpolation to obtain quarter 
+ * pixel motion estimates, as described in [ISO14496-10], subclause 8.4.2.2.1. 
+ *
+ * Input Arguments:
+ *   
+ *   pPred0     - Pointer to the top-left corner of reference block 0 
+ *   pPred1     - Pointer to the top-left corner of reference block 1 
+ *   iPredStep0 - Step of reference block 0 
+ *   iPredStep1 - Step of reference block 1 
+ *   iDstStep   - Step of the destination buffer. 
+ *   iHeight    - Height of the blocks 
+ *
+ * Output Arguments:
+ *   
+ *   pDstPred - Pointer to the destination buffer. 8-byte aligned. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned under any of the following 
+ *              conditions: 
+ *    -   one or more of the following pointers is NULL: pPred0, pPred1, or 
+ *              pDstPred. 
+ *    -   pDstPred is not aligned on an 8-byte boundary. 
+ *    -   iPredStep0 <= 0 or iPredStep0 is not a multiple of 8. 
+ *    -   iPredStep1 <= 0 or iPredStep1 is not a multiple of 8. 
+ *    -   iDstStep   <= 0 or iDstStep is not a multiple of 8. 
+ *    -   iHeight is not 4, 8, or 16. 
+ *
+ */
+OMXResult omxVCCOMM_Average_8x (
+    const OMX_U8 *pPred0,
+    const OMX_U8 *pPred1,
+    OMX_U32 iPredStep0,
+    OMX_U32 iPredStep1,
+    OMX_U8 *pDstPred,
+    OMX_U32 iDstStep,
+    OMX_U32 iHeight
+);
+
+
+
+/**
+ * Function:  omxVCCOMM_Average_16x   (6.1.3.1.2)
+ *
+ * Description:
+ * This function calculates the average of two 16x16 or 16x8 blocks.  The 
+ * result is rounded according to (a+b+1)/2.  The block average function can 
+ * be used in conjunction with half-pixel interpolation to obtain quarter 
+ * pixel motion estimates, as described in [ISO14496-10], subclause 8.4.2.2.1. 
+ *
+ * Input Arguments:
+ *   
+ *   pPred0 - Pointer to the top-left corner of reference block 0 
+ *   pPred1 - Pointer to the top-left corner of reference block 1 
+ *   iPredStep0 - Step of reference block 0 
+ *   iPredStep1 - Step of reference block 1 
+ *   iDstStep - Step of the destination buffer 
+ *   iHeight - Height of the blocks 
+ *
+ * Output Arguments:
+ *   
+ *   pDstPred - Pointer to the destination buffer. 16-byte aligned. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned under any of the following 
+ *              conditions: 
+ *    -   one or more of the following pointers is NULL: pPred0, pPred1, or 
+ *              pDstPred. 
+ *    -   pDstPred is not aligned on a 16-byte boundary. 
+ *    -   iPredStep0 <= 0 or iPredStep0 is not a multiple of 16. 
+ *    -   iPredStep1 <= 0 or iPredStep1 is not a multiple of 16. 
+ *    -   iDstStep <= 0 or iDstStep is not a multiple of 16. 
+ *    -   iHeight is not 8 or 16. 
+ *
+ */
+OMXResult omxVCCOMM_Average_16x (
+    const OMX_U8 *pPred0,
+    const OMX_U8 *pPred1,
+    OMX_U32 iPredStep0,
+    OMX_U32 iPredStep1,
+    OMX_U8 *pDstPred,
+    OMX_U32 iDstStep,
+    OMX_U32 iHeight
+);
+
+
+
+/**
+ * Function:  omxVCCOMM_ExpandFrame_I   (6.1.3.2.1)
+ *
+ * Description:
+ * This function expands a reconstructed frame in-place.  The unexpanded 
+ * source frame should be stored in a plane buffer with sufficient space 
+ * pre-allocated for edge expansion, and the input frame should be located in 
+ * the plane buffer center.  This function executes the pixel expansion by 
+ * replicating source frame edge pixel intensities in the empty pixel 
+ * locations (expansion region) between the source frame edge and the plane 
+ * buffer edge.  The width/height of the expansion regions on the 
+ * horizontal/vertical edges is controlled by the parameter iExpandPels. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDstPlane - pointer to the top-left corner of the frame to be 
+ *            expanded; must be aligned on an 8-byte boundary. 
+ *   iFrameWidth - frame width; must be a multiple of 8. 
+ *   iFrameHeight -frame height; must be a multiple of 8. 
+ *   iExpandPels - number of pixels to be expanded in the horizontal and 
+ *            vertical directions; must be a multiple of 8. 
+ *   iPlaneStep - distance, in bytes, between the start of consecutive lines 
+ *            in the plane buffer; must be larger than or equal to 
+ *            (iFrameWidth + 2 * iExpandPels). 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDstPlane -Pointer to the top-left corner of the frame (NOT the 
+ *            top-left corner of the plane); must be aligned on an 8-byte 
+ *            boundary. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned under any of the following 
+ *              conditions: 
+ *    -    pSrcDstPlane is NULL. 
+ *    -    pSrcDstPlane is not aligned on an 8-byte boundary. 
+ *    -    one of the following parameters is either equal to zero or is a 
+ *              non-multiple of 8: iFrameHeight, iFrameWidth, iPlaneStep, or 
+ *              iExpandPels. 
+ *    -    iPlaneStep < (iFrameWidth + 2 * iExpandPels). 
+ *
+ */
+OMXResult omxVCCOMM_ExpandFrame_I (
+    OMX_U8 *pSrcDstPlane,
+    OMX_U32 iFrameWidth,
+    OMX_U32 iFrameHeight,
+    OMX_U32 iExpandPels,
+    OMX_U32 iPlaneStep
+);
+
+
+
+/**
+ * Function:  omxVCCOMM_Copy8x8   (6.1.3.3.1)
+ *
+ * Description:
+ * Copies the reference 8x8 block to the current block. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - pointer to the reference block in the source frame; must be 
+ *            aligned on an 8-byte boundary. 
+ *   step - distance between the starts of consecutive lines in the reference 
+ *            frame, in bytes; must be a multiple of 8 and must be larger than 
+ *            or equal to 8. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - pointer to the destination block; must be aligned on an 8-byte 
+ *            boundary. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned under any of the following 
+ *              conditions: 
+ *    -   one or more of the following pointers is NULL: pSrc, pDst 
+ *    -   one or more of the following pointers is not aligned on an 8-byte 
+ *              boundary: pSrc, pDst 
+ *    -    step <8 or step is not a multiple of 8. 
+ *
+ */
+OMXResult omxVCCOMM_Copy8x8 (
+    const OMX_U8 *pSrc,
+    OMX_U8 *pDst,
+    OMX_INT step
+);
+
+
+
+/**
+ * Function:  omxVCCOMM_Copy16x16   (6.1.3.3.2)
+ *
+ * Description:
+ * Copies the reference 16x16 macroblock to the current macroblock. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - pointer to the reference macroblock in the source frame; must be 
+ *            aligned on a 16-byte boundary. 
+ *   step - distance between the starts of consecutive lines in the reference 
+ *            frame, in bytes; must be a multiple of 16 and must be larger 
+ *            than or equal to 16. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - pointer to the destination macroblock; must be aligned on a 
+ *            16-byte boundary. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned under any of the following 
+ *              conditions: 
+ *    -   one or more of the following pointers is NULL: pSrc, pDst 
+ *    -   one or more of the following pointers is not aligned on a 16-byte 
+ *              boundary: pSrc, pDst 
+ *    -    step <16 or step is not a multiple of 16. 
+ *
+ */
+OMXResult omxVCCOMM_Copy16x16 (
+    const OMX_U8 *pSrc,
+    OMX_U8 *pDst,
+    OMX_INT step
+);
+
+
+
+/**
+ * Function:  omxVCCOMM_ComputeTextureErrorBlock_SAD   (6.1.4.1.1)
+ *
+ * Description:
+ * Computes texture error of the block; also returns SAD. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - pointer to the source plane; must be aligned on an 8-byte 
+ *            boundary. 
+ *   srcStep - step of the source plane 
+ *   pSrcRef - pointer to the reference buffer, an 8x8 block; must be aligned 
+ *            on an 8-byte boundary. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - pointer to the destination buffer, an 8x8 block; must be aligned 
+ *            on an 8-byte boundary. 
+ *   pDstSAD - pointer to the Sum of Absolute Differences (SAD) value 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments 
+ *    -    At least one of the following 
+ *         pointers is NULL: pSrc, pSrcRef, pDst and pDstSAD. 
+ *    -    pSrc is not 8-byte aligned. 
+ *    -    SrcStep <= 0 or srcStep is not a multiple of 8. 
+ *    -    pSrcRef is not 8-byte aligned. 
+ *    -    pDst is not 8-byte aligned. 
+ *
+ */
+OMXResult omxVCCOMM_ComputeTextureErrorBlock_SAD (
+    const OMX_U8 *pSrc,
+    OMX_INT srcStep,
+    const OMX_U8 *pSrcRef,
+    OMX_S16 *pDst,
+    OMX_INT *pDstSAD
+);
+
+
+
+/**
+ * Function:  omxVCCOMM_ComputeTextureErrorBlock   (6.1.4.1.2)
+ *
+ * Description:
+ * Computes the texture error of the block. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - pointer to the source plane. This should be aligned on an 8-byte 
+ *            boundary. 
+ *   srcStep - step of the source plane 
+ *   pSrcRef - pointer to the reference buffer, an 8x8 block. This should be 
+ *            aligned on an 8-byte boundary. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - pointer to the destination buffer, an 8x8 block. This should be 
+ *            aligned on an 8-byte boundary. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments:
+ *    -    At least one of the following pointers is NULL: 
+ *         pSrc, pSrcRef, pDst. 
+ *    -    pSrc is not 8-byte aligned. 
+ *    -    SrcStep <= 0 or srcStep is not a multiple of 8. 
+ *    -    pSrcRef is not 8-byte aligned. 
+ *    -    pDst is not 8-byte aligned 
+ *
+ */
+OMXResult omxVCCOMM_ComputeTextureErrorBlock (
+    const OMX_U8 *pSrc,
+    OMX_INT srcStep,
+    const OMX_U8 *pSrcRef,
+    OMX_S16 *pDst
+);
+
+
+
+/**
+ * Function:  omxVCCOMM_LimitMVToRect   (6.1.4.1.3)
+ *
+ * Description:
+ * Limits the motion vector associated with the current block/macroblock to 
+ * prevent the motion compensated block/macroblock from moving outside a 
+ * bounding rectangle as shown in Figure 6-1. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcMV - pointer to the motion vector associated with the current block 
+ *            or macroblock 
+ *   pRectVOPRef - pointer to the bounding rectangle 
+ *   Xcoord, Ycoord  - coordinates of the current block or macroblock 
+ *   size - size of the current block or macroblock; must be equal to 8 or 
+ *            16. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstMV - pointer to the limited motion vector 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments.  Returned if one or more of the 
+ *              following conditions is true: 
+ *    -    at least one of the following pointers is NULL: 
+ *         pSrcMV, pDstMV, or pRectVOPRef. 
+ *    -    size is not equal to either 8 or 16. 
+ *    -    the width or height of the bounding rectangle is less than 
+ *         twice the block size.
+ */
+OMXResult omxVCCOMM_LimitMVToRect (
+    const OMXVCMotionVector *pSrcMV,
+    OMXVCMotionVector *pDstMV,
+    const OMXRect *pRectVOPRef,
+    OMX_INT Xcoord,
+    OMX_INT Ycoord,
+    OMX_INT size
+);
+
+
+
+/**
+ * Function:  omxVCCOMM_SAD_16x   (6.1.4.1.4)
+ *
+ * Description:
+ * This function calculates the SAD for 16x16 and 16x8 blocks. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcOrg - Pointer to the original block; must be aligned on a 16-byte 
+ *             boundary. 
+ *   iStepOrg - Step of the original block buffer 
+ *   pSrcRef  - Pointer to the reference block 
+ *   iStepRef - Step of the reference block buffer 
+ *   iHeight  - Height of the block 
+ *
+ * Output Arguments:
+ *   
+ *   pDstSAD - Pointer of result SAD 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments.  Returned if one or more of the 
+ *              following conditions is true: 
+ *    -    at least one of the following pointers is NULL: 
+ *         pSrcOrg, pDstSAD, or pSrcRef 
+ *    -    pSrcOrg is not 16-byte aligned. 
+ *    -    iStepOrg  <= 0 or iStepOrg is not a multiple of 16 
+ *    -    iStepRef <= 0 or iStepRef is not a multiple of 16 
+ *    -    iHeight is not 8 or 16 
+ *
+ */
+OMXResult omxVCCOMM_SAD_16x (
+    const OMX_U8 *pSrcOrg,
+    OMX_U32 iStepOrg,
+    const OMX_U8 *pSrcRef,
+    OMX_U32 iStepRef,
+    OMX_S32 *pDstSAD,
+    OMX_U32 iHeight
+);
+
+
+
+/**
+ * Function:  omxVCCOMM_SAD_8x   (6.1.4.1.5)
+ *
+ * Description:
+ * This function calculates the SAD for 8x16, 8x8, 8x4 blocks. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcOrg  - Pointer to the original block; must be aligned on a 8-byte 
+ *              boundary. 
+ *   iStepOrg - Step of the original block buffer 
+ *   pSrcRef  - Pointer to the reference block 
+ *   iStepRef - Step of the reference block buffer 
+ *   iHeight  - Height of the block 
+ *
+ * Output Arguments:
+ *   
+ *   pDstSAD -Pointer of result SAD 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments.  Returned if one or more of the 
+ *              following conditions is true: 
+ *    -    at least one of the following pointers is NULL: 
+ *         pSrcOrg, pDstSAD, or pSrcRef 
+ *    -    pSrcOrg is not 8-byte aligned. 
+ *    -    iStepOrg  <= 0 or iStepOrg is not a multiple of 8 
+ *    -    iStepRef <= 0 or iStepRef is not a multiple of 8 
+ *    -    iHeight is not 4, 8 or 16 
+ *
+ */
+OMXResult omxVCCOMM_SAD_8x (
+    const OMX_U8 *pSrcOrg,
+    OMX_U32 iStepOrg,
+    const OMX_U8 *pSrcRef,
+    OMX_U32 iStepRef,
+    OMX_S32*pDstSAD,
+    OMX_U32 iHeight
+);
+
+
+
+/* 6.2.1.1 Direction  */
+/* The direction enumerator is used with functions that perform AC/DC prediction and zig-zag scan.  */
+
+enum {
+    OMX_VC_NONE       = 0,
+    OMX_VC_HORIZONTAL = 1,
+    OMX_VC_VERTICAL   = 2 
+};
+
+
+
+/* 6.2.1.2 Bilinear Interpolation  */
+/* The bilinear interpolation enumerator is used with motion estimation, motion compensation, and reconstruction functions.  */
+
+enum {
+    OMX_VC_INTEGER_PIXEL = 0, /* case a */
+    OMX_VC_HALF_PIXEL_X  = 1, /* case b */
+    OMX_VC_HALF_PIXEL_Y  = 2, /* case c */
+    OMX_VC_HALF_PIXEL_XY = 3  /* case d */ 
+};
+
+
+
+/* 6.2.1.3 Neighboring Macroblock Availability  */
+/* Neighboring macroblock availability is indicated using the following flags:   */
+
+enum {
+    OMX_VC_UPPER = 1,        /** above macroblock is available */
+    OMX_VC_LEFT = 2,         /** left macroblock is available */
+    OMX_VC_CENTER = 4,
+    OMX_VC_RIGHT = 8,
+    OMX_VC_LOWER = 16,
+    OMX_VC_UPPER_LEFT = 32,  /** above-left macroblock is available */
+    OMX_VC_UPPER_RIGHT = 64, /** above-right macroblock is available */
+    OMX_VC_LOWER_LEFT = 128,
+    OMX_VC_LOWER_RIGHT = 256 
+};
+
+
+
+/* 6.2.1.4 Video Components  */
+/* A data type that enumerates video components is defined as follows:  */
+
+typedef enum {
+    OMX_VC_LUMINANCE,    /** Luminance component */
+    OMX_VC_CHROMINANCE   /** chrominance component */ 
+} OMXVCM4P2VideoComponent;
+
+
+
+/* 6.2.1.5 MacroblockTypes  */
+/* A data type that enumerates macroblock types is defined as follows:  */
+
+typedef enum {
+    OMX_VC_INTER     = 0, /** P picture or P-VOP */
+    OMX_VC_INTER_Q   = 1, /** P picture or P-VOP */
+    OMX_VC_INTER4V   = 2, /** P picture or P-VOP */
+    OMX_VC_INTRA     = 3, /** I and P picture, I- and P-VOP */
+    OMX_VC_INTRA_Q   = 4, /** I and P picture, I- and P-VOP */
+    OMX_VC_INTER4V_Q = 5  /** P picture or P-VOP (H.263)*/
+} OMXVCM4P2MacroblockType;
+
+
+
+/* 6.2.1.6 Coordinates  */
+/* Coordinates are represented as follows:  */
+
+typedef struct {
+    OMX_INT x;
+    OMX_INT y;
+} OMXVCM4P2Coordinate;
+
+
+
+/* 6.2.1.7 Motion Estimation Algorithms  */
+/* A data type that enumerates motion estimation search methods is defined as follows:  */
+
+typedef enum {
+    OMX_VC_M4P2_FAST_SEARCH = 0,  /** Fast motion search */
+    OMX_VC_M4P2_FULL_SEARCH = 1   /** Full motion search */ 
+} OMXVCM4P2MEMode;
+
+
+
+/* 6.2.1.8 Motion Estimation Parameters  */
+/* A data structure containing control parameters for 
+ * motion estimation functions is defined as follows:  
+ */
+
+typedef struct {
+    OMX_INT searchEnable8x8;     /** enables 8x8 search */
+    OMX_INT halfPelSearchEnable; /** enables half-pel resolution */
+    OMX_INT searchRange;         /** search range */
+    OMX_INT rndVal;              /** rounding control; 0-disabled, 1-enabled*/
+} OMXVCM4P2MEParams;
+
+
+
+/* 6.2.1.9 Macroblock Information   */
+/* A data structure containing macroblock parameters for 
+ * motion estimation functions is defined as follows:  
+ */
+
+typedef struct {
+    OMX_S32 sliceId;                 /* slice number */
+    OMXVCM4P2MacroblockType mbType;  /* MB type: OMX_VC_INTRA, OMX_VC_INTER, or OMX_VC_INTER4 */
+    OMX_S32 qp;                      /* quantization parameter*/
+    OMX_U32 cbpy;                    /* CBP Luma */
+    OMX_U32 cbpc;                    /* CBP Chroma */
+    OMXVCMotionVector pMV0[2][2];    /* motion vector, represented using 1/2-pel units, 
+                                      * pMV0[blocky][blockx] (blocky = 0~1, blockx =0~1) 
+                                      */
+    OMXVCMotionVector pMVPred[2][2]; /* motion vector prediction, represented using 1/2-pel units, 
+                                      * pMVPred[blocky][blockx] (blocky = 0~1, blockx = 0~1) 
+                                      */
+    OMX_U8 pPredDir[2][2];           /* AC prediction direction: 
+                                      *   OMX_VC_NONE, OMX_VC_VERTICAL, OMX_VC_HORIZONTAL 
+                                      */
+} OMXVCM4P2MBInfo, *OMXVCM4P2MBInfoPtr;
+
+
+
+/**
+ * Function:  omxVCM4P2_FindMVpred   (6.2.3.1.1)
+ *
+ * Description:
+ * Predicts a motion vector for the current block using the procedure 
+ * specified in [ISO14496-2], subclause 7.6.5.  The resulting predicted MV is 
+ * returned in pDstMVPred. If the parameter pDstMVPredME if is not NULL then 
+ * the set of three MV candidates used for prediction is also returned, 
+ * otherwise pDstMVPredMEis NULL upon return. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcMVCurMB - pointer to the MV buffer associated with the current Y 
+ *            macroblock; a value of NULL indicates unavailability. 
+ *   pSrcCandMV1 - pointer to the MV buffer containing the 4 MVs associated 
+ *            with the MB located to the left of the current MB; set to NULL 
+ *            if there is no MB to the left. 
+ *   pSrcCandMV2 - pointer to the MV buffer containing the 4 MVs associated 
+ *            with the MB located above the current MB; set to NULL if there 
+ *            is no MB located above the current MB. 
+ *   pSrcCandMV3 - pointer to the MV buffer containing the 4 MVs associated 
+ *            with the MB located to the right and above the current MB; set 
+ *            to NULL if there is no MB located to the above-right. 
+ *   iBlk - the index of block in the current macroblock 
+ *   pDstMVPredME - MV candidate return buffer;  if set to NULL then 
+ *            prediction candidate MVs are not returned and pDstMVPredME will 
+ *            be NULL upon function return; if pDstMVPredME is non-NULL then it 
+ *            must point to a buffer containing sufficient space for three 
+ *            return MVs. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstMVPred - pointer to the predicted motion vector 
+ *   pDstMVPredME - if non-NULL upon input then pDstMVPredME  points upon 
+ *            return to a buffer containing the three motion vector candidates 
+ *            used for prediction as specified in [ISO14496-2], subclause 
+ *            7.6.5, otherwise if NULL upon input then pDstMVPredME is NULL 
+ *            upon output. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned under any of the following 
+ *              conditions: 
+ *    -    the pointer pDstMVPred is NULL 
+ *    -    the parameter iBlk does not fall into the range 0 <= iBlk<=3 
+ *
+ */
+OMXResult omxVCM4P2_FindMVpred (
+    const OMXVCMotionVector *pSrcMVCurMB,
+    const OMXVCMotionVector *pSrcCandMV1,
+    const OMXVCMotionVector *pSrcCandMV2,
+    const OMXVCMotionVector *pSrcCandMV3,
+    OMXVCMotionVector *pDstMVPred,
+    OMXVCMotionVector *pDstMVPredME,
+    OMX_INT iBlk
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_IDCT8x8blk   (6.2.3.2.1)
+ *
+ * Description:
+ * Computes a 2D inverse DCT for a single 8x8 block, as defined in 
+ * [ISO14496-2]. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - pointer to the start of the linearly arranged IDCT input buffer; 
+ *            must be aligned on a 16-byte boundary.  According to 
+ *            [ISO14496-2], the input coefficient values should lie within the 
+ *            range [-2048, 2047]. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - pointer to the start of the linearly arranged IDCT output buffer; 
+ *            must be aligned on a 16-byte boundary. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments:
+ *    -    pSrc or pDst is NULL. 
+ *    -    pSrc or pDst is not 16-byte aligned. 
+ *
+ */
+OMXResult omxVCM4P2_IDCT8x8blk (
+    const OMX_S16 *pSrc,
+    OMX_S16 *pDst
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_MEGetBufSize   (6.2.4.1.1)
+ *
+ * Description:
+ * Computes the size, in bytes, of the vendor-specific specification 
+ * structure for the following motion estimation functions: 
+ * BlockMatch_Integer_8x8, BlockMatch_Integer_16x16, and MotionEstimationMB. 
+ *
+ * Input Arguments:
+ *   
+ *   MEmode - motion estimation mode; available modes are defined by the 
+ *            enumerated type OMXVCM4P2MEMode 
+ *   pMEParams - motion estimation parameters 
+ *
+ * Output Arguments:
+ *   
+ *   pSize - pointer to the number of bytes required for the specification 
+ *            structure 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - one or more of the following is true: 
+ *    -    an invalid value was specified for the parameter MEmode 
+ *    -    a negative or zero value was specified for the 
+ *         parameter pMEParams->searchRange 
+ *
+ */
+OMXResult omxVCM4P2_MEGetBufSize (
+    OMXVCM4P2MEMode MEmode,
+    const OMXVCM4P2MEParams *pMEParams,
+    OMX_U32 *pSize
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_MEInit   (6.2.4.1.2)
+ *
+ * Description:
+ * Initializes the vendor-specific specification structure required for the 
+ * following motion estimation functions:  BlockMatch_Integer_8x8, 
+ * BlockMatch_Integer_16x16, and MotionEstimationMB. Memory for the 
+ * specification structure *pMESpec must be allocated prior to calling the 
+ * function, and should be aligned on a 4-byte boundary.  Following 
+ * initialization by this function, the vendor-specific structure *pMESpec 
+ * should contain an implementation-specific representation of all motion 
+ * estimation parameters received via the structure pMEParams, for example  
+ * rndVal, searchRange, etc.  The number of bytes required for the 
+ * specification structure can be determined using the function 
+ * omxVCM4P2_MEGetBufSize. 
+ *
+ * Input Arguments:
+ *   
+ *   MEmode - motion estimation mode; available modes are defined by the 
+ *            enumerated type OMXVCM4P2MEMode 
+ *   pMEParams - motion estimation parameters 
+ *   pMESpec - pointer to the uninitialized ME specification structure 
+ *
+ * Output Arguments:
+ *   
+ *   pMESpec - pointer to the initialized ME specification structure 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - one or more of the following is true: 
+ *    -    an invalid value was specified for the parameter MEmode 
+ *    -    a negative or zero value was specified for the 
+ *         parameter pMEParams->searchRange 
+ *
+ */
+OMXResult omxVCM4P2_MEInit (
+    OMXVCM4P2MEMode MEmode,
+    const OMXVCM4P2MEParams*pMEParams,
+    void *pMESpec
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_BlockMatch_Integer_16x16   (6.2.4.2.1)
+ *
+ * Description:
+ * Performs a 16x16 block search; estimates motion vector and associated 
+ * minimum SAD. Both the input and output motion vectors are represented using 
+ * half-pixel units, and therefore a shift left or right by 1 bit may be 
+ * required, respectively, to match the input or output MVs with other 
+ * functions that either generate output MVs or expect input MVs represented 
+ * using integer pixel units. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcRefBuf - pointer to the reference Y plane; points to the reference 
+ *            MB that corresponds to the location of the current macroblock in 
+ *            the current plane. 
+ *   refWidth - width of the reference plane 
+ *   pRefRect - pointer to the valid reference plane rectangle; coordinates 
+ *            are specified relative to the image origin.  Rectangle 
+ *            boundaries may extend beyond image boundaries if the image has 
+ *            been padded.  For example, if padding extends 4 pixels beyond 
+ *            frame border, then the value for the left border could be set to 
+ *            -4. 
+ *   pSrcCurrBuf - pointer to the current block in the current macroblock 
+ *            buffer extracted from the original plane (linear array, 256 
+ *            entries); must be aligned on a 16-byte boundary.  The number of 
+ *            bytes between lines (step) is 16. 
+ *   pCurrPointPos - position of the current macroblock in the current plane 
+ *   pSrcPreMV - pointer to predicted motion vector; NULL indicates no 
+ *            predicted MV 
+ *   pSrcPreSAD - pointer to SAD associated with the predicted MV (referenced 
+ *            by pSrcPreMV); may be set to NULL if unavailable. 
+ *   pMESpec - vendor-specific motion estimation specification structure; 
+ *            must have been allocated and then initialized using 
+ *            omxVCM4P2_MEInit prior to calling the block matching function. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstMV - pointer to estimated MV 
+ *   pDstSAD - pointer to minimum SAD 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments.  Returned if one of the following 
+ *              conditions is true: 
+ *    -    at least one of the following pointers is NULL: pSrcRefBuf, 
+ *              pRefRect, pSrcCurrBuff, pCurrPointPos, pDstMV, pDstSAD or 
+ *              pMESpec, or 
+ *    -    pSrcCurrBuf is not 16-byte aligned 
+ *
+ */
+OMXResult omxVCM4P2_BlockMatch_Integer_16x16 (
+    const OMX_U8 *pSrcRefBuf,
+    OMX_INT refWidth,
+    const OMXRect *pRefRect,
+    const OMX_U8 *pSrcCurrBuf,
+    const OMXVCM4P2Coordinate *pCurrPointPos,
+    const OMXVCMotionVector*pSrcPreMV,
+    const OMX_INT *pSrcPreSAD,
+    void *pMESpec,
+    OMXVCMotionVector*pDstMV,
+    OMX_INT *pDstSAD
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_BlockMatch_Integer_8x8   (6.2.4.2.2)
+ *
+ * Description:
+ * Performs an 8x8 block search; estimates motion vector and associated 
+ * minimum SAD.  Both the input and output motion vectors are represented 
+ * using half-pixel units, and therefore a shift left or right by 1 bit may be 
+ * required, respectively, to match the input or output MVs with other 
+ * functions that either generate output MVs or expect input MVs represented 
+ * using integer pixel units. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcRefBuf - pointer to the reference Y plane; points to the reference 
+ *            block that corresponds to the location of the current 8x8 block 
+ *            in the current plane. 
+ *   refWidth - width of the reference plane 
+ *   pRefRect - pointer to the valid reference plane rectangle; coordinates 
+ *            are specified relative to the image origin.  Rectangle 
+ *            boundaries may extend beyond image boundaries if the image has 
+ *            been padded. 
+ *   pSrcCurrBuf - pointer to the current block in the current macroblock 
+ *            buffer extracted from the original plane (linear array, 128 
+ *            entries); must be aligned on an 8-byte boundary.  The number of 
+ *            bytes between lines (step) is 16 bytes. 
+ *   pCurrPointPos - position of the current block in the current plane 
+ *   pSrcPreMV - pointer to predicted motion vector; NULL indicates no 
+ *            predicted MV 
+ *   pSrcPreSAD - pointer to SAD associated with the predicted MV (referenced 
+ *            by pSrcPreMV); may be set to NULL if unavailable. 
+ *   pMESpec - vendor-specific motion estimation specification structure; 
+ *            must have been allocated and then initialized using 
+ *            omxVCM4P2_MEInit prior to calling the block matching function. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstMV - pointer to estimated MV 
+ *   pDstSAD - pointer to minimum SAD 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments.  Returned if one of the following 
+ *              conditions is true: 
+ *    -    at least one of the following pointers is NULL: pSrcRefBuf, 
+ *              pRefRect, pSrcCurrBuff, pCurrPointPos, pDstMV, pDstSAD or 
+ *              pMESpec, or 
+ *    -    pSrcCurrBuf is not 8-byte aligned 
+ *
+ */
+OMXResult omxVCM4P2_BlockMatch_Integer_8x8 (
+    const OMX_U8 *pSrcRefBuf,
+    OMX_INT refWidth,
+    const OMXRect *pRefRect,
+    const OMX_U8 *pSrcCurrBuf,
+    const OMXVCM4P2Coordinate *pCurrPointPos,
+    const OMXVCMotionVector *pSrcPreMV,
+    const OMX_INT *pSrcPreSAD,
+    void *pMESpec,
+    OMXVCMotionVector *pDstMV,
+    OMX_INT *pDstSAD
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_BlockMatch_Half_16x16   (6.2.4.2.3)
+ *
+ * Description:
+ * Performs a 16x16 block match with half-pixel resolution.  Returns the 
+ * estimated motion vector and associated minimum SAD.  This function 
+ * estimates the half-pixel motion vector by interpolating the integer 
+ * resolution motion vector referenced by the input parameter pSrcDstMV, i.e., 
+ * the initial integer MV is generated externally.  The input parameters 
+ * pSrcRefBuf and pSearchPointRefPos should be shifted by the winning MV of 
+ * 16x16 integer search prior to calling BlockMatch_Half_16x16. The function 
+ * BlockMatch_Integer_16x16 may be used for integer motion estimation. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcRefBuf - pointer to the reference Y plane; points to the reference 
+ *            macroblock that corresponds to the location of the current 
+ *            macroblock in the current plane. 
+ *   refWidth - width of the reference plane 
+ *   pRefRect - reference plane valid region rectangle 
+ *   pSrcCurrBuf - pointer to the current block in the current macroblock 
+ *            buffer extracted from the original plane (linear array, 256 
+ *            entries); must be aligned on a 16-byte boundary.  The number of 
+ *            bytes between lines (step) is 16. 
+ *   pSearchPointRefPos - position of the starting point for half pixel 
+ *            search (specified in terms of integer pixel units) in the 
+ *            reference plane, i.e., the reference position pointed to by the 
+ *            predicted motion vector. 
+ *   rndVal - rounding control parameter: 0 - disabled; 1 - enabled. 
+ *   pSrcDstMV - pointer to the initial MV estimate; typically generated 
+ *            during a prior 16X16 integer search; specified in terms of 
+ *            half-pixel units. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDstMV - pointer to estimated MV 
+ *   pDstSAD - pointer to minimum SAD 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments.  Returned if one of the following 
+ *              conditions is true: 
+ *    -    at least one of the following pointers is NULL: pSrcRefBuf, 
+ *         pRefRect, pSrcCurrBuff, pSearchPointRefPos, pSrcDstMV.
+ *    -    pSrcCurrBuf is not 16-byte aligned, or 
+ *
+ */
+OMXResult omxVCM4P2_BlockMatch_Half_16x16 (
+    const OMX_U8 *pSrcRefBuf,
+    OMX_INT refWidth,
+    const OMXRect *pRefRect,
+    const OMX_U8 *pSrcCurrBuf,
+    const OMXVCM4P2Coordinate *pSearchPointRefPos,
+    OMX_INT rndVal,
+    OMXVCMotionVector *pSrcDstMV,
+    OMX_INT *pDstSAD
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_BlockMatch_Half_8x8   (6.2.4.2.4)
+ *
+ * Description:
+ * Performs an 8x8 block match with half-pixel resolution. Returns the 
+ * estimated motion vector and associated minimum SAD.  This function 
+ * estimates the half-pixel motion vector by interpolating the integer 
+ * resolution motion vector referenced by the input parameter pSrcDstMV, i.e., 
+ * the initial integer MV is generated externally.  The input parameters 
+ * pSrcRefBuf and pSearchPointRefPos should be shifted by the winning MV of 
+ * 8x8 integer search prior to calling BlockMatch_Half_8x8. The function 
+ * BlockMatch_Integer_8x8 may be used for integer motion estimation. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcRefBuf - pointer to the reference Y plane; points to the reference 
+ *            block that corresponds to the location of the current 8x8 block 
+ *            in the current plane. 
+ *   refWidth - width of the reference plane 
+ *   pRefRect - reference plane valid region rectangle 
+ *   pSrcCurrBuf - pointer to the current block in the current macroblock 
+ *            buffer extracted from the original plane (linear array, 128 
+ *            entries); must be aligned on a 8-byte boundary.  The number of 
+ *            bytes between lines (step) is 16. 
+ *   pSearchPointRefPos - position of the starting point for half pixel 
+ *            search (specified in terms of integer pixel units) in the 
+ *            reference plane. 
+ *   rndVal - rounding control parameter: 0 - disabled; 1 - enabled. 
+ *   pSrcDstMV - pointer to the initial MV estimate; typically generated 
+ *            during a prior 8x8 integer search, specified in terms of 
+ *            half-pixel units. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDstMV - pointer to estimated MV 
+ *   pDstSAD - pointer to minimum SAD 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments.  Returned if one of the following 
+ *              conditions is true: 
+ *    -    at least one of the following pointers is NULL: 
+ *         pSrcRefBuf, pRefRect, pSrcCurrBuff, pSearchPointRefPos, pSrcDstMV
+ *    -    pSrcCurrBuf is not 8-byte aligned 
+ *
+ */
+OMXResult omxVCM4P2_BlockMatch_Half_8x8 (
+    const OMX_U8 *pSrcRefBuf,
+    OMX_INT refWidth,
+    const OMXRect *pRefRect,
+    const OMX_U8 *pSrcCurrBuf,
+    const OMXVCM4P2Coordinate *pSearchPointRefPos,
+    OMX_INT rndVal,
+    OMXVCMotionVector *pSrcDstMV,
+    OMX_INT *pDstSAD
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_MotionEstimationMB   (6.2.4.3.1)
+ *
+ * Description:
+ * Performs motion search for a 16x16 macroblock.  Selects best motion search 
+ * strategy from among inter-1MV, inter-4MV, and intra modes.  Supports 
+ * integer and half pixel resolution. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcCurrBuf - pointer to the top-left corner of the current MB in the 
+ *            original picture plane; must be aligned on a 16-byte boundary.  
+ *            The function does not expect source data outside the region 
+ *            bounded by the MB to be available; for example it is not 
+ *            necessary for the caller to guarantee the availability of 
+ *            pSrcCurrBuf[-SrcCurrStep], i.e., the row of pixels above the MB 
+ *            to be processed. 
+ *   srcCurrStep - width of the original picture plane, in terms of full 
+ *            pixels; must be a multiple of 16. 
+ *   pSrcRefBuf - pointer to the reference Y plane; points to the reference 
+ *            plane location corresponding to the location of the current 
+ *            macroblock in the current plane; must be aligned on a 16-byte 
+ *            boundary. 
+ *   srcRefStep - width of the reference picture plane, in terms of full 
+ *            pixels; must be a multiple of 16. 
+ *   pRefRect - reference plane valid region rectangle, specified relative to 
+ *            the image origin 
+ *   pCurrPointPos - position of the current macroblock in the current plane 
+ *   pMESpec - pointer to the vendor-specific motion estimation specification 
+ *            structure; must be allocated and then initialized using 
+ *            omxVCM4P2_MEInit prior to calling this function. 
+ *   pMBInfo - array, of dimension four, containing pointers to information 
+ *            associated with four nearby MBs: 
+ *            -   pMBInfo[0] - pointer to left MB information 
+ *            -   pMBInfo[1] - pointer to top MB information 
+ *            -   pMBInfo[2] - pointer to top-left MB information 
+ *            -   pMBInfo[3] - pointer to top-right MB information 
+ *            Any pointer in the array may be set equal to NULL if the 
+ *            corresponding MB doesn't exist.  For each MB, the following structure 
+ *            members are used:    
+ *            -   mbType - macroblock type, either OMX_VC_INTRA, OMX_VC_INTER, or 
+ *                OMX_VC_INTER4V 
+ *            -   pMV0[2][2] - estimated motion vectors; represented 
+ *                in 1/2 pixel units 
+ *            -   sliceID - number of the slice to which the MB belongs 
+ *   pSrcDstMBCurr - pointer to information structure for the current MB.  
+ *            The following entries should be set prior to calling the 
+ *            function: sliceID - the number of the slice the to which the 
+ *            current MB belongs.  The structure elements cbpy and cbpc are 
+ *            ignored. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDstMBCurr - pointer to updated information structure for the current 
+ *            MB after MB-level motion estimation has been completed.  The 
+ *            following structure members are updated by the ME function:   
+ *              -  mbType - macroblock type: OMX_VC_INTRA, OMX_VC_INTER, or 
+ *                 OMX_VC_INTER4V. 
+ *              -  pMV0[2][2] - estimated motion vectors; represented in 
+ *                 terms of 1/2 pel units. 
+ *              -  pMVPred[2][2] - predicted motion vectors; represented 
+ *                 in terms of 1/2 pel units. 
+ *            The structure members cbpy and cbpc are not updated by the function. 
+ *   pDstSAD - pointer to the minimum SAD for INTER1V, or sum of minimum SADs 
+ *            for INTER4V 
+ *   pDstBlockSAD - pointer to an array of SAD values for each of the four 
+ *            8x8 luma blocks in the MB.  The block SADs are in scan order for 
+ *            each MB. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments.  Returned if one or more of the 
+ *              following conditions is true: 
+ *    -    at least one of the following pointers is NULL: pSrcCurrBuf, 
+ *              pSrcRefBuf, pRefRect, pCurrPointPos, pMBInter, pMBIntra, 
+ *              pSrcDstMBCurr, or pDstSAD. 
+ *
+ */
+OMXResult omxVCM4P2_MotionEstimationMB (
+    const OMX_U8 *pSrcCurrBuf,
+    OMX_S32 srcCurrStep,
+    const OMX_U8 *pSrcRefBuf,
+    OMX_S32 srcRefStep,
+    const OMXRect*pRefRect,
+    const OMXVCM4P2Coordinate *pCurrPointPos,
+    void *pMESpec,
+    const OMXVCM4P2MBInfoPtr *pMBInfo,
+    OMXVCM4P2MBInfo *pSrcDstMBCurr,
+    OMX_U16 *pDstSAD,
+    OMX_U16 *pDstBlockSAD
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_DCT8x8blk   (6.2.4.4.1)
+ *
+ * Description:
+ * Computes a 2D forward DCT for a single 8x8 block, as defined in 
+ * [ISO14496-2]. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - pointer to the start of the linearly arranged input buffer; must 
+ *            be aligned on a 16-byte boundary.  Input values (pixel 
+ *            intensities) are valid in the range [-255,255]. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - pointer to the start of the linearly arranged output buffer; must 
+ *            be aligned on a 16-byte boundary. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments, returned if:
+ *    -    pSrc or pDst is NULL. 
+ *    -    pSrc or pDst is not 16-byte aligned. 
+ *
+ */
+OMXResult omxVCM4P2_DCT8x8blk (
+    const OMX_S16 *pSrc,
+    OMX_S16 *pDst
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_QuantIntra_I   (6.2.4.4.2)
+ *
+ * Description:
+ * Performs quantization on intra block coefficients. This function supports 
+ * bits_per_pixel == 8. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - pointer to the input intra block coefficients; must be aligned 
+ *            on a 16-byte boundary. 
+ *   QP - quantization parameter (quantizer_scale). 
+ *   blockIndex - block index indicating the component type and position, 
+ *            valid in the range 0 to 5, as defined in [ISO14496-2], subclause 
+ *            6.1.3.8. 
+ *   shortVideoHeader - binary flag indicating presence of 
+ *            short_video_header; shortVideoHeader==1 selects linear intra DC 
+ *            mode, and shortVideoHeader==0 selects non linear intra DC mode. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst - pointer to the output (quantized) interblock coefficients.  
+ *            When shortVideoHeader==1, AC coefficients are saturated on the 
+ *            interval [-127, 127], and DC coefficients are saturated on the 
+ *            interval [1, 254].  When shortVideoHeader==0, AC coefficients 
+ *            are saturated on the interval [-2047, 2047]. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments:
+ *    -    pSrcDst is NULL. 
+ *    -    blockIndex < 0 or blockIndex >= 10 
+ *    -    QP <= 0 or QP >= 32. 
+ *
+ */
+OMXResult omxVCM4P2_QuantIntra_I (
+    OMX_S16 *pSrcDst,
+    OMX_U8 QP,
+    OMX_INT blockIndex,
+    OMX_INT shortVideoHeader
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_QuantInter_I   (6.2.4.4.3)
+ *
+ * Description:
+ * Performs quantization on an inter coefficient block; supports 
+ * bits_per_pixel == 8. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - pointer to the input inter block coefficients; must be aligned 
+ *            on a 16-byte boundary. 
+ *   QP - quantization parameter (quantizer_scale) 
+ *   shortVideoHeader - binary flag indicating presence of short_video_header; 
+ *            shortVideoHeader==1 selects linear intra DC mode, and 
+ *            shortVideoHeader==0 selects non linear intra DC mode. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst - pointer to the output (quantized) interblock coefficients.  
+ *            When shortVideoHeader==1, AC coefficients are saturated on the 
+ *            interval [-127, 127], and DC coefficients are saturated on the 
+ *            interval [1, 254].  When shortVideoHeader==0, AC coefficients 
+ *            are saturated on the interval [-2047, 2047]. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments:
+ *    -    pSrcDst is NULL. 
+ *    -    QP <= 0 or QP >= 32. 
+ *
+ */
+OMXResult omxVCM4P2_QuantInter_I (
+    OMX_S16 *pSrcDst,
+    OMX_U8 QP,
+    OMX_INT shortVideoHeader
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_TransRecBlockCoef_intra   (6.2.4.4.4)
+ *
+ * Description:
+ * Quantizes the DCT coefficients, implements intra block AC/DC coefficient 
+ * prediction, and reconstructs the current intra block texture for prediction 
+ * on the next frame.  Quantized row and column coefficients are returned in 
+ * the updated coefficient buffers. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - pointer to the pixels of current intra block; must be aligned on 
+ *            an 8-byte boundary. 
+ *   pPredBufRow - pointer to the coefficient row buffer containing 
+ *            ((num_mb_per_row * 2 + 1) * 8) elements of type OMX_S16. 
+ *            Coefficients are organized into blocks of eight as described 
+ *            below (Internal Prediction Coefficient Update Procedures).  The 
+ *            DC coefficient is first, and the remaining buffer locations 
+ *            contain the quantized AC coefficients. Each group of eight row 
+ *            buffer elements combined with one element eight elements ahead 
+ *            contains the coefficient predictors of the neighboring block 
+ *            that is spatially above or to the left of the block currently to 
+ *            be decoded. A negative-valued DC coefficient indicates that this 
+ *            neighboring block is not INTRA-coded or out of bounds, and 
+ *            therefore the AC and DC coefficients are invalid.  Pointer must 
+ *            be aligned on an 8-byte boundary. 
+ *   pPredBufCol - pointer to the prediction coefficient column buffer 
+ *            containing 16 elements of type OMX_S16. Coefficients are 
+ *            organized as described in section 6.2.2.5.  Pointer must be 
+ *            aligned on an 8-byte boundary. 
+ *   pSumErr - pointer to a flag indicating whether or not AC prediction is 
+ *            required; AC prediction is enabled if *pSumErr >=0, but the 
+ *            value is not used for coefficient prediction, i.e., the sum of 
+ *            absolute differences starts from 0 for each call to this 
+ *            function.  Otherwise AC prediction is disabled if *pSumErr < 0 . 
+ *   blockIndex - block index indicating the component type and position, as 
+ *            defined in [ISO14496-2], subclause 6.1.3.8. 
+ *   curQp - quantization parameter of the macroblock to which the current 
+ *            block belongs 
+ *   pQpBuf - pointer to a 2-element quantization parameter buffer; pQpBuf[0] 
+ *            contains the quantization parameter associated with the 8x8 
+ *            block left of the current block (QPa), and pQpBuf[1] contains 
+ *            the quantization parameter associated with the 8x8 block above 
+ *            the current block (QPc).  In the event that the corresponding 
+ *            block is outside of the VOP bound, the Qp value will not affect 
+ *            the intra prediction process, as described in [ISO14496-2], 
+ *            sub-clause 7.4.3.3,  Adaptive AC Coefficient Prediction.  
+ *   srcStep - width of the source buffer; must be a multiple of 8. 
+ *   dstStep - width of the reconstructed destination buffer; must be a 
+ *            multiple of 16. 
+ *   shortVideoHeader - binary flag indicating presence of 
+ *            short_video_header; shortVideoHeader==1 selects linear intra DC 
+ *            mode, and shortVideoHeader==0 selects non linear intra DC mode. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - pointer to the quantized DCT coefficient buffer; pDst[0] contains 
+ *            the predicted DC coefficient; the remaining entries contain the 
+ *            quantized AC coefficients (without prediction).  The pointer 
+ *            pDstmust be aligned on a 16-byte boundary. 
+ *   pRec - pointer to the reconstructed texture; must be aligned on an 
+ *            8-byte boundary. 
+ *   pPredBufRow - pointer to the updated coefficient row buffer 
+ *   pPredBufCol - pointer to the updated coefficient column buffer 
+ *   pPreACPredict - if prediction is enabled, the parameter points to the 
+ *            start of the buffer containing the coefficient differences for 
+ *            VLC encoding. The entry pPreACPredict[0]indicates prediction 
+ *            direction for the current block and takes one of the following 
+ *            values: OMX_VC_NONE (prediction disabled), OMX_VC_HORIZONTAL, or 
+ *            OMX_VC_VERTICAL.  The entries 
+ *            pPreACPredict[1]-pPreACPredict[7]contain predicted AC 
+ *            coefficients.  If prediction is disabled (*pSumErr<0) then the 
+ *            contents of this buffer are undefined upon return from the 
+ *            function 
+ *   pSumErr - pointer to the value of the accumulated AC coefficient errors, 
+ *            i.e., sum of the absolute differences between predicted and 
+ *            unpredicted AC coefficients 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - Bad arguments:
+ *    -    At least one of the following pointers is NULL: pSrc, pDst, pRec, 
+ *         pCoefBufRow, pCoefBufCol, pQpBuf, pPreACPredict, pSumErr. 
+ *    -    blockIndex < 0 or blockIndex >= 10; 
+ *    -    curQP <= 0 or curQP >= 32. 
+ *    -    srcStep, or dstStep <= 0 or not a multiple of 8. 
+ *    -    pDst is not 16-byte aligned: . 
+ *    -    At least one of the following pointers is not 8-byte aligned: 
+ *         pSrc, pRec.  
+ *
+ *  Note: The coefficient buffers must be updated in accordance with the 
+ *        update procedures defined in section in 6.2.2. 
+ *
+ */
+OMXResult omxVCM4P2_TransRecBlockCoef_intra (
+    const OMX_U8 *pSrc,
+    OMX_S16 *pDst,
+    OMX_U8 *pRec,
+    OMX_S16 *pPredBufRow,
+    OMX_S16 *pPredBufCol,
+    OMX_S16 *pPreACPredict,
+    OMX_INT *pSumErr,
+    OMX_INT blockIndex,
+    OMX_U8 curQp,
+    const OMX_U8 *pQpBuf,
+    OMX_INT srcStep,
+    OMX_INT dstStep,
+    OMX_INT shortVideoHeader
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_TransRecBlockCoef_inter   (6.2.4.4.5)
+ *
+ * Description:
+ * Implements DCT, and quantizes the DCT coefficients of the inter block 
+ * while reconstructing the texture residual. There is no boundary check for 
+ * the bit stream buffer. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc -pointer to the residuals to be encoded; must be aligned on an 
+ *            16-byte boundary. 
+ *   QP - quantization parameter. 
+ *   shortVideoHeader - binary flag indicating presence of short_video_header; 
+ *                      shortVideoHeader==1 selects linear intra DC mode, and 
+ *                      shortVideoHeader==0 selects non linear intra DC mode. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - pointer to the quantized DCT coefficients buffer; must be aligned 
+ *            on a 16-byte boundary. 
+ *   pRec - pointer to the reconstructed texture residuals; must be aligned 
+ *            on a 16-byte boundary. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments:
+ *    -    At least one of the following pointers is either NULL or 
+ *         not 16-byte aligned: 
+ *            - pSrc 
+ *            - pDst
+ *            - pRec
+ *    -    QP <= 0 or QP >= 32. 
+ *
+ */
+OMXResult omxVCM4P2_TransRecBlockCoef_inter (
+    const OMX_S16 *pSrc,
+    OMX_S16 *pDst,
+    OMX_S16 *pRec,
+    OMX_U8 QP,
+    OMX_INT shortVideoHeader
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_EncodeVLCZigzag_IntraDCVLC   (6.2.4.5.2)
+ *
+ * Description:
+ * Performs zigzag scan and VLC encoding of AC and DC coefficients for one 
+ * intra block.  Two versions of the function (DCVLC and ACVLC) are provided 
+ * in order to support the two different methods of processing DC 
+ * coefficients, as described in [ISO14496-2], subclause 7.4.1.4, "Intra DC 
+ * Coefficient Decoding for the Case of Switched VLC Encoding".  
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - double pointer to the current byte in the bitstream 
+ *   pBitOffset - pointer to the bit position in the byte pointed by 
+ *            *ppBitStream. Valid within 0 to 7. 
+ *   pQDctBlkCoef - pointer to the quantized DCT coefficient 
+ *   predDir - AC prediction direction, which is used to decide the zigzag 
+ *            scan pattern; takes one of the following values: 
+ *            -  OMX_VC_NONE - AC prediction not used.  
+ *                             Performs classical zigzag scan. 
+ *            -  OMX_VC_HORIZONTAL - Horizontal prediction.  
+ *                             Performs alternate-vertical zigzag scan. 
+ *            -  OMX_VC_VERTICAL - Vertical prediction.  
+ *                             Performs alternate-horizontal zigzag scan. 
+ *   pattern - block pattern which is used to decide whether this block is 
+ *            encoded 
+ *   shortVideoHeader - binary flag indicating presence of 
+ *            short_video_header; escape modes 0-3 are used if 
+ *            shortVideoHeader==0, and escape mode 4 is used when 
+ *            shortVideoHeader==1. 
+ *   videoComp - video component type (luminance, chrominance) of the current 
+ *            block 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after the block is encoded, so 
+ *            that it points to the current byte in the bit stream buffer. 
+ *   pBitOffset - *pBitOffset is updated so that it points to the current bit 
+ *            position in the byte pointed by *ppBitStream. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - Bad arguments:
+ *    -    At least one of the following pointers is NULL: ppBitStream, 
+ *              *ppBitStream, pBitOffset, pQDctBlkCoef. 
+ *    -   *pBitOffset < 0, or *pBitOffset >7. 
+ *    -    PredDir is not one of: OMX_VC_NONE, OMX_VC_HORIZONTAL, or 
+ *         OMX_VC_VERTICAL. 
+ *    -    VideoComp is not one component of enum OMXVCM4P2VideoComponent. 
+ *
+ */
+OMXResult omxVCM4P2_EncodeVLCZigzag_IntraDCVLC (
+    OMX_U8 **ppBitStream,
+    OMX_INT *pBitOffset,
+    const OMX_S16 *pQDctBlkCoef,
+    OMX_U8 predDir,
+    OMX_U8 pattern,
+    OMX_INT shortVideoHeader,
+    OMXVCM4P2VideoComponent videoComp
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_EncodeVLCZigzag_IntraACVLC   (6.2.4.5.2)
+ *
+ * Description:
+ * Performs zigzag scan and VLC encoding of AC and DC coefficients for one 
+ * intra block.  Two versions of the function (DCVLC and ACVLC) are provided 
+ * in order to support the two different methods of processing DC 
+ * coefficients, as described in [ISO14496-2], subclause 7.4.1.4,  Intra DC 
+ * Coefficient Decoding for the Case of Switched VLC Encoding.  
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - double pointer to the current byte in the bitstream 
+ *   pBitOffset - pointer to the bit position in the byte pointed by 
+ *            *ppBitStream. Valid within 0 to 7. 
+ *   pQDctBlkCoef - pointer to the quantized DCT coefficient 
+ *   predDir - AC prediction direction, which is used to decide the zigzag 
+ *            scan pattern; takes one of the following values: 
+ *            -  OMX_VC_NONE - AC prediction not used.  
+ *                             Performs classical zigzag scan. 
+ *            -  OMX_VC_HORIZONTAL - Horizontal prediction.  
+ *                             Performs alternate-vertical zigzag scan. 
+ *            -  OMX_VC_VERTICAL - Vertical prediction.  
+ *                             Performs alternate-horizontal zigzag scan. 
+ *   pattern - block pattern which is used to decide whether this block is 
+ *            encoded 
+ *   shortVideoHeader - binary flag indicating presence of 
+ *            short_video_header; escape modes 0-3 are used if 
+ *            shortVideoHeader==0, and escape mode 4 is used when 
+ *            shortVideoHeader==1. 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after the block is encoded, so 
+ *            that it points to the current byte in the bit stream buffer. 
+ *   pBitOffset - *pBitOffset is updated so that it points to the current bit 
+ *            position in the byte pointed by *ppBitStream. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - Bad arguments:
+ *    -    At least one of the following pointers is NULL: ppBitStream, 
+ *              *ppBitStream, pBitOffset, pQDctBlkCoef. 
+ *    -   *pBitOffset < 0, or *pBitOffset >7. 
+ *    -    PredDir is not one of: OMX_VC_NONE, OMX_VC_HORIZONTAL, or 
+ *         OMX_VC_VERTICAL. 
+ *    -    VideoComp is not one component of enum OMXVCM4P2VideoComponent. 
+ *
+ */
+OMXResult omxVCM4P2_EncodeVLCZigzag_IntraACVLC (
+    OMX_U8 **ppBitStream,
+    OMX_INT *pBitOffset,
+    const OMX_S16 *pQDctBlkCoef,
+    OMX_U8 predDir,
+    OMX_U8 pattern,
+    OMX_INT shortVideoHeader
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_EncodeVLCZigzag_Inter   (6.2.4.5.3)
+ *
+ * Description:
+ * Performs classical zigzag scanning and VLC encoding for one inter block. 
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - pointer to the pointer to the current byte in the bit 
+ *            stream 
+ *   pBitOffset - pointer to the bit position in the byte pointed by 
+ *            *ppBitStream. Valid within 0 to 7 
+ *   pQDctBlkCoef - pointer to the quantized DCT coefficient 
+ *   pattern - block pattern which is used to decide whether this block is 
+ *            encoded 
+ *   shortVideoHeader - binary flag indicating presence of 
+ *            short_video_header; escape modes 0-3 are used if 
+ *            shortVideoHeader==0, and escape mode 4 is used when 
+ *            shortVideoHeader==1. 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after the block is encoded so that 
+ *            it points to the current byte in the bit stream buffer. 
+ *   pBitOffset - *pBitOffset is updated so that it points to the current bit 
+ *            position in the byte pointed by *ppBitStream. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - Bad arguments 
+ *    -    At least one of the pointers: is NULL: ppBitStream, *ppBitStream, 
+ *              pBitOffset, pQDctBlkCoef 
+ *    -   *pBitOffset < 0, or *pBitOffset >7. 
+ *
+ */
+OMXResult omxVCM4P2_EncodeVLCZigzag_Inter (
+    OMX_U8 **ppBitStream,
+    OMX_INT *pBitOffset,
+    const OMX_S16 *pQDctBlkCoef,
+    OMX_U8 pattern,
+    OMX_INT shortVideoHeader
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_EncodeMV   (6.2.4.5.4)
+ *
+ * Description:
+ * Predicts a motion vector for the current macroblock, encodes the 
+ * difference, and writes the output to the stream buffer. The input MVs 
+ * pMVCurMB, pSrcMVLeftMB, pSrcMVUpperMB, and pSrcMVUpperRightMB should lie 
+ * within the ranges associated with the input parameter fcodeForward, as 
+ * described in [ISO14496-2], subclause 7.6.3.  This function provides a 
+ * superset of the functionality associated with the function 
+ * omxVCM4P2_FindMVpred. 
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - double pointer to the current byte in the bitstream buffer 
+ *   pBitOffset - index of the first free (next available) bit in the stream 
+ *            buffer referenced by *ppBitStream, valid in the range 0 to 7. 
+ *   pMVCurMB - pointer to the current macroblock motion vector; a value of 
+ *            NULL indicates unavailability. 
+ *   pSrcMVLeftMB - pointer to the source left macroblock motion vector; a 
+ *            value of  NULLindicates unavailability. 
+ *   pSrcMVUpperMB - pointer to source upper macroblock motion vector; a 
+ *            value of NULL indicates unavailability. 
+ *   pSrcMVUpperRightMB - pointer to source upper right MB motion vector; a 
+ *            value of NULL indicates unavailability. 
+ *   fcodeForward - an integer with values from 1 to 7; used in encoding 
+ *            motion vectors related to search range, as described in 
+ *            [ISO14496-2], subclause 7.6.3. 
+ *   MBType - macro block type, valid in the range 0 to 5 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - updated pointer to the current byte in the bit stream 
+ *            buffer 
+ *   pBitOffset - updated index of the next available bit position in stream 
+ *            buffer referenced by *ppBitStream 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments 
+ *    -    At least one of the following pointers is NULL: ppBitStream, 
+ *              *ppBitStream, pBitOffset, pMVCurMB 
+ *    -    *pBitOffset < 0, or *pBitOffset >7. 
+ *    -    fcodeForward <= 0, or fcodeForward > 7, or MBType < 0. 
+ *
+ */
+OMXResult omxVCM4P2_EncodeMV (
+    OMX_U8 **ppBitStream,
+    OMX_INT *pBitOffset,
+    const OMXVCMotionVector *pMVCurMB,
+    const OMXVCMotionVector*pSrcMVLeftMB,
+    const OMXVCMotionVector *pSrcMVUpperMB,
+    const OMXVCMotionVector *pSrcMVUpperRightMB,
+    OMX_INT fcodeForward,
+    OMXVCM4P2MacroblockType MBType
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_DecodePadMV_PVOP   (6.2.5.1.1)
+ *
+ * Description:
+ * Decodes and pads the four motion vectors associated with a non-intra P-VOP 
+ * macroblock.  For macroblocks of type OMX_VC_INTER4V, the output MV is 
+ * padded as specified in [ISO14496-2], subclause 7.6.1.6. Otherwise, for 
+ * macroblocks of types other than OMX_VC_INTER4V, the decoded MV is copied to 
+ * all four output MV buffer entries. 
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - pointer to the pointer to the current byte in the bit 
+ *            stream buffer 
+ *   pBitOffset - pointer to the bit position in the byte pointed to by 
+ *            *ppBitStream. *pBitOffset is valid within [0-7]. 
+ *   pSrcMVLeftMB, pSrcMVUpperMB, and pSrcMVUpperRightMB - pointers to the 
+ *            motion vector buffers of the macroblocks specially at the left, 
+ *            upper, and upper-right side of the current macroblock, 
+ *            respectively; a value of NULL indicates unavailability.  Note: 
+ *            Any neighborhood macroblock outside the current VOP or video 
+ *            packet or outside the current GOB (when short_video_header is 
+ *             1 ) for which gob_header_empty is  0  is treated as 
+ *            transparent, according to [ISO14496-2], subclause 7.6.5. 
+ *   fcodeForward - a code equal to vop_fcode_forward in MPEG-4 bit stream 
+ *            syntax 
+ *   MBType - the type of the current macroblock. If MBType is not equal to 
+ *            OMX_VC_INTER4V, the destination motion vector buffer is still 
+ *            filled with the same decoded vector. 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after the block is decoded, so 
+ *            that it points to the current byte in the bit stream buffer 
+ *   pBitOffset - *pBitOffset is updated so that it points to the current bit 
+ *            position in the byte pointed by *ppBitStream 
+ *   pDstMVCurMB - pointer to the motion vector buffer for the current 
+ *            macroblock; contains four decoded motion vectors 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments:
+ *    -    At least one of the following pointers is NULL: 
+ *         ppBitStream, *ppBitStream, pBitOffset, pDstMVCurMB 
+ *    -    *pBitOffset exceeds [0,7]
+ *    -    fcodeForward exceeds (0,7]
+ *    -    MBType less than zero
+ *    -    motion vector buffer is not 4-byte aligned. 
+ *    OMX_Sts_Err - status error 
+ *
+ */
+OMXResult omxVCM4P2_DecodePadMV_PVOP (
+    const OMX_U8 **ppBitStream,
+    OMX_INT *pBitOffset,
+    OMXVCMotionVector *pSrcMVLeftMB,
+    OMXVCMotionVector*pSrcMVUpperMB,
+    OMXVCMotionVector *pSrcMVUpperRightMB,
+    OMXVCMotionVector*pDstMVCurMB,
+    OMX_INT fcodeForward,
+    OMXVCM4P2MacroblockType MBType
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_DecodeVLCZigzag_IntraDCVLC   (6.2.5.2.2)
+ *
+ * Description:
+ * Performs VLC decoding and inverse zigzag scan of AC and DC coefficients 
+ * for one intra block.  Two versions of the function (DCVLC and ACVLC) are 
+ * provided in order to support the two different methods of processing DC 
+ * coefficients, as described in [ISO14496-2], subclause 7.4.1.4,  Intra DC 
+ * Coefficient Decoding for the Case of Switched VLC Encoding.  
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - pointer to the pointer to the current byte in the 
+ *            bitstream buffer 
+ *   pBitOffset - pointer to the bit position in the current byte referenced 
+ *            by *ppBitStream.  The parameter *pBitOffset is valid in the 
+ *            range [0-7]. 
+ *            Bit Position in one byte:  |Most      Least| 
+ *                    *pBitOffset        |0 1 2 3 4 5 6 7| 
+ *   predDir - AC prediction direction; used to select the zigzag scan 
+ *            pattern; takes one of the following values: 
+ *            -  OMX_VC_NONE - AC prediction not used; 
+ *                             performs classical zigzag scan. 
+ *            -  OMX_VC_HORIZONTAL - Horizontal prediction; 
+ *                             performs alternate-vertical zigzag scan; 
+ *            -  OMX_VC_VERTICAL - Vertical prediction; 
+ *                             performs alternate-horizontal zigzag scan. 
+ *   shortVideoHeader - binary flag indicating presence of 
+ *            short_video_header; escape modes 0-3 are used if 
+ *            shortVideoHeader==0, and escape mode 4 is used when 
+ *            shortVideoHeader==1. 
+ *   videoComp - video component type (luminance or chrominance) of the 
+ *            current block 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after the block is decoded such 
+ *            that it points to the current byte in the bit stream buffer 
+ *   pBitOffset - *pBitOffset is updated such that it points to the current 
+ *            bit position in the byte pointed by *ppBitStream 
+ *   pDst - pointer to the coefficient buffer of current block; must be 
+ *            4-byte aligned. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments, if:
+ *    -    At least one of the following pointers is NULL: 
+ *         ppBitStream, *ppBitStream, pBitOffset, pDst
+ *    -    *pBitOffset exceeds [0,7]
+ *    -    preDir exceeds [0,2]
+ *    -    pDst is not 4-byte aligned 
+ *    OMX_Sts_Err - if:
+ *    -    In DecodeVLCZigzag_IntraDCVLC, dc_size > 12 
+ *    -    At least one of mark bits equals zero 
+ *    -    Illegal stream encountered; code cannot be located in VLC table 
+ *    -    Forbidden code encountered in the VLC FLC table. 
+ *    -    The number of coefficients is greater than 64 
+ *
+ */
+OMXResult omxVCM4P2_DecodeVLCZigzag_IntraDCVLC (
+    const OMX_U8 **ppBitStream,
+    OMX_INT *pBitOffset,
+    OMX_S16 *pDst,
+    OMX_U8 predDir,
+    OMX_INT shortVideoHeader,
+    OMXVCM4P2VideoComponent videoComp
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_DecodeVLCZigzag_IntraACVLC   (6.2.5.2.2)
+ *
+ * Description:
+ * Performs VLC decoding and inverse zigzag scan of AC and DC coefficients 
+ * for one intra block.  Two versions of the function (DCVLC and ACVLC) are 
+ * provided in order to support the two different methods of processing DC 
+ * coefficients, as described in [ISO14496-2], subclause 7.4.1.4,  Intra DC 
+ * Coefficient Decoding for the Case of Switched VLC Encoding.  
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - pointer to the pointer to the current byte in the 
+ *            bitstream buffer 
+ *   pBitOffset - pointer to the bit position in the current byte referenced 
+ *            by *ppBitStream.  The parameter *pBitOffset is valid in the 
+ *            range [0-7]. Bit Position in one byte:  |Most Least| *pBitOffset 
+ *            |0 1 2 3 4 5 6 7| 
+ *   predDir - AC prediction direction; used to select the zigzag scan 
+ *            pattern; takes one of the following values: OMX_VC_NONE - AC 
+ *            prediction not used; performs classical zigzag scan. 
+ *            OMX_VC_HORIZONTAL - Horizontal prediction; performs 
+ *            alternate-vertical zigzag scan; OMX_VC_VERTICAL - Vertical 
+ *            prediction; performs alternate-horizontal zigzag scan. 
+ *   shortVideoHeader - binary flag indicating presence of 
+ *            short_video_header; escape modes 0-3 are used if 
+ *            shortVideoHeader==0, and escape mode 4 is used when 
+ *            shortVideoHeader==1. 
+ *   videoComp - video component type (luminance or chrominance) of the 
+ *            current block 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after the block is decoded such 
+ *            that it points to the current byte in the bit stream buffer 
+ *   pBitOffset - *pBitOffset is updated such that it points to the current 
+ *            bit position in the byte pointed by *ppBitStream 
+ *   pDst - pointer to the coefficient buffer of current block; must be 
+ *            4-byte aligned. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments At least one of the following 
+ *              pointers is NULL: ppBitStream, *ppBitStream, pBitOffset, pDst, 
+ *              or At least one of the following conditions is true: 
+ *              *pBitOffset exceeds [0,7], preDir exceeds [0,2], or pDst is 
+ *              not 4-byte aligned 
+ *    OMX_Sts_Err In DecodeVLCZigzag_IntraDCVLC, dc_size > 12 At least one of 
+ *              mark bits equals zero Illegal stream encountered; code cannot 
+ *              be located in VLC table Forbidden code encountered in the VLC 
+ *              FLC table The number of coefficients is greater than 64 
+ *
+ */
+OMXResult omxVCM4P2_DecodeVLCZigzag_IntraACVLC (
+    const OMX_U8 **ppBitStream,
+    OMX_INT *pBitOffset,
+    OMX_S16 *pDst,
+    OMX_U8 predDir,
+    OMX_INT shortVideoHeader
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_DecodeVLCZigzag_Inter   (6.2.5.2.3)
+ *
+ * Description:
+ * Performs VLC decoding and inverse zigzag scan for one inter-coded block. 
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - double pointer to the current byte in the stream buffer 
+ *   pBitOffset - pointer to the next available bit in the current stream 
+ *            byte referenced by *ppBitStream. The parameter *pBitOffset is 
+ *            valid within the range [0-7]. 
+ *   shortVideoHeader - binary flag indicating presence of 
+ *            short_video_header; escape modes 0-3 are used if 
+ *            shortVideoHeader==0, and escape mode 4 is used when 
+ *            shortVideoHeader==1. 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after the block is decoded such 
+ *            that it points to the current byte in the stream buffer 
+ *   pBitOffset - *pBitOffset is updated after decoding such that it points 
+ *            to the next available bit in the stream byte referenced by 
+ *            *ppBitStream 
+ *   pDst - pointer to the coefficient buffer of current block; must be 
+ *            4-byte aligned. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_BadArgErr - bad arguments:
+ *    -    At least one of the following pointers is NULL: 
+ *         ppBitStream, *ppBitStream, pBitOffset, pDst
+ *    -    pDst is not 4-byte aligned
+ *    -   *pBitOffset exceeds [0,7]
+ *    OMX_Sts_Err - status error, if:
+ *    -    At least one mark bit is equal to zero 
+ *    -    Encountered an illegal stream code that cannot be found in the VLC table 
+ *    -    Encountered an illegal code in the VLC FLC table 
+ *    -    The number of coefficients is greater than 64 
+ *
+ */
+OMXResult omxVCM4P2_DecodeVLCZigzag_Inter (
+    const OMX_U8 **ppBitStream,
+    OMX_INT *pBitOffset,
+    OMX_S16 *pDst,
+    OMX_INT shortVideoHeader
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_QuantInvIntra_I   (6.2.5.3.2)
+ *
+ * Description:
+ * Performs the second inverse quantization mode on an intra/inter coded 
+ * block. Supports bits_per_pixel = 8. The output coefficients are clipped to 
+ * the range [-2048, 2047]. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - pointer to the input (quantized) intra/inter block; must be 
+ *            aligned on a 16-byte boundary. 
+ *   QP - quantization parameter (quantizer_scale) 
+ *   videoComp - video component type of the current block. Takes one of the 
+ *            following flags: OMX_VC_LUMINANCE, OMX_VC_CHROMINANCE (intra 
+ *            version only). 
+ *   shortVideoHeader - binary flag indicating presence of short_video_header 
+ *            (intra version only). 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst - pointer to the output (dequantized) intra/inter block 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; one or more of the following is 
+ *              true: 
+ *    -    pSrcDst is NULL 
+ *    -    QP <= 0 or QP >=31 
+ *    -    videoComp is neither OMX_VC_LUMINANCE nor OMX_VC_CHROMINANCE. 
+ *
+ */
+OMXResult omxVCM4P2_QuantInvIntra_I (
+    OMX_S16 *pSrcDst,
+    OMX_INT QP,
+    OMXVCM4P2VideoComponent videoComp,
+    OMX_INT shortVideoHeader
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_QuantInvInter_I   (6.2.5.3.2)
+ *
+ * Description:
+ * Performs the second inverse quantization mode on an intra/inter coded 
+ * block. Supports bits_per_pixel = 8. The output coefficients are clipped to 
+ * the range [-2048, 2047]. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - pointer to the input (quantized) intra/inter block; must be 
+ *            aligned on a 16-byte boundary. 
+ *   QP - quantization parameter (quantizer_scale) 
+ *   videoComp - video component type of the current block. Takes one of the 
+ *            following flags: OMX_VC_LUMINANCE, OMX_VC_CHROMINANCE (intra 
+ *            version only). 
+ *   shortVideoHeader - binary flag indicating presence of short_video_header 
+ *            (intra version only). 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst - pointer to the output (dequantized) intra/inter block 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; one or more of the following is 
+ *              true: 
+ *    -    pSrcDst is NULL 
+ *    -    QP <= 0 or QP >=31 
+ *    -    videoComp is neither OMX_VC_LUMINANCE nor OMX_VC_CHROMINANCE. 
+ *
+ */
+OMXResult omxVCM4P2_QuantInvInter_I (
+    OMX_S16 *pSrcDst,
+    OMX_INT QP
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_DecodeBlockCoef_Intra   (6.2.5.4.1)
+ *
+ * Description:
+ * Decodes the INTRA block coefficients. Inverse quantization, inversely 
+ * zigzag positioning, and IDCT, with appropriate clipping on each step, are 
+ * performed on the coefficients. The results are then placed in the output 
+ * frame/plane on a pixel basis.  Note: This function will be used only when 
+ * at least one non-zero AC coefficient of current block exists in the bit 
+ * stream. The DC only condition will be handled in another function. 
+ *
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - pointer to the pointer to the current byte in the bit 
+ *            stream buffer. There is no boundary check for the bit stream 
+ *            buffer. 
+ *   pBitOffset - pointer to the bit position in the byte pointed to by 
+ *            *ppBitStream. *pBitOffset is valid within [0-7]. 
+ *   step - width of the destination plane 
+ *   pCoefBufRow - pointer to the coefficient row buffer; must be aligned on 
+ *            an 8-byte boundary. 
+ *   pCoefBufCol - pointer to the coefficient column buffer; must be aligned 
+ *            on an 8-byte boundary. 
+ *   curQP - quantization parameter of the macroblock which the current block 
+ *            belongs to 
+ *   pQPBuf - pointer to the quantization parameter buffer 
+ *   blockIndex - block index indicating the component type and position as 
+ *            defined in [ISO14496-2], subclause 6.1.3.8, Figure 6-5. 
+ *   intraDCVLC - a code determined by intra_dc_vlc_thr and QP. This allows a 
+ *            mechanism to switch between two VLC for coding of Intra DC 
+ *            coefficients as per [ISO14496-2], Table 6-21. 
+ *   ACPredFlag - a flag equal to ac_pred_flag (of luminance) indicating if 
+ *            the ac coefficients of the first row or first column are 
+ *            differentially coded for intra coded macroblock. 
+ *   shortVideoHeader - binary flag indicating presence of 
+ *            short_video_header; shortVideoHeader==1 selects linear intra DC 
+ *            mode, and shortVideoHeader==0 selects non linear intra DC mode. 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after the block is decoded, so 
+ *            that it points to the current byte in the bit stream buffer 
+ *   pBitOffset - *pBitOffset is updated so that it points to the current bit 
+ *            position in the byte pointed by *ppBitStream 
+ *   pDst - pointer to the block in the destination plane; must be aligned on 
+ *            an 8-byte boundary. 
+ *   pCoefBufRow - pointer to the updated coefficient row buffer. 
+ *   pCoefBufCol - pointer to the updated coefficient column buffer  Note: 
+ *            The coefficient buffers must be updated in accordance with the 
+ *            update procedure defined in section 6.2.2. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments, if:
+ *    -    At least one of the following pointers is NULL: 
+ *         ppBitStream, *ppBitStream, pBitOffset, pCoefBufRow, pCoefBufCol, 
+ *         pQPBuf, pDst. 
+ *    -    *pBitOffset exceeds [0,7] 
+ *    -    curQP exceeds (1, 31)
+ *    -    blockIndex exceeds [0,5]
+ *    -    step is not the multiple of 8
+ *    -    a pointer alignment requirement was violated. 
+ *    OMX_Sts_Err - status error. Refer to OMX_Sts_Err of DecodeVLCZigzag_Intra.  
+ *
+ */
+OMXResult omxVCM4P2_DecodeBlockCoef_Intra (
+    const OMX_U8 **ppBitStream,
+    OMX_INT *pBitOffset,
+    OMX_U8 *pDst,
+    OMX_INT step,
+    OMX_S16 *pCoefBufRow,
+    OMX_S16 *pCoefBufCol,
+    OMX_U8 curQP,
+    const OMX_U8 *pQPBuf,
+    OMX_INT blockIndex,
+    OMX_INT intraDCVLC,
+    OMX_INT ACPredFlag,
+    OMX_INT shortVideoHeader
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_DecodeBlockCoef_Inter   (6.2.5.4.2)
+ *
+ * Description:
+ * Decodes the INTER block coefficients. This function performs inverse 
+ * quantization, inverse zigzag positioning, and IDCT (with appropriate 
+ * clipping on each step) on the coefficients. The results (residuals) are 
+ * placed in a contiguous array of 64 elements. For INTER block, the output 
+ * buffer holds the residuals for further reconstruction. 
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - pointer to the pointer to the current byte in the bit 
+ *            stream buffer. There is no boundary check for the bit stream 
+ *            buffer. 
+ *   pBitOffset - pointer to the bit position in the byte pointed to by 
+ *            *ppBitStream. *pBitOffset is valid within [0-7] 
+ *   QP - quantization parameter 
+ *   shortVideoHeader - binary flag indicating presence of 
+ *            short_video_header; shortVideoHeader==1 selects linear intra DC 
+ *            mode, and shortVideoHeader==0 selects non linear intra DC mode. 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after the block is decoded, so 
+ *            that it points to the current byte in the bit stream buffer 
+ *   pBitOffset - *pBitOffset is updated so that it points to the current bit 
+ *            position in the byte pointed by *ppBitStream 
+ *   pDst - pointer to the decoded residual buffer (a contiguous array of 64 
+ *            elements of OMX_S16 data type); must be aligned on a 16-byte 
+ *            boundary. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments, if:
+ *    -    At least one of the following pointers is Null: 
+ *         ppBitStream, *ppBitStream, pBitOffset , pDst 
+ *    -    *pBitOffset exceeds [0,7]
+ *    -    QP <= 0. 
+ *    -    pDst is not 16-byte aligned 
+ *    OMX_Sts_Err - status error. Refer to OMX_Sts_Err of DecodeVLCZigzag_Inter . 
+ *
+ */
+OMXResult omxVCM4P2_DecodeBlockCoef_Inter (
+    const OMX_U8 **ppBitStream,
+    OMX_INT *pBitOffset,
+    OMX_S16 *pDst,
+    OMX_INT QP,
+    OMX_INT shortVideoHeader
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_PredictReconCoefIntra   (6.2.5.4.3)
+ *
+ * Description:
+ * Performs adaptive DC/AC coefficient prediction for an intra block.  Prior 
+ * to the function call, prediction direction (predDir) should be selected as 
+ * specified in [ISO14496-2], subclause 7.4.3.1. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - pointer to the coefficient buffer which contains the quantized 
+ *            coefficient residuals (PQF) of the current block; must be 
+ *            aligned on a 4-byte boundary.  The output coefficients are 
+ *            saturated to the range [-2048, 2047]. 
+ *   pPredBufRow - pointer to the coefficient row buffer; must be aligned on 
+ *            a 4-byte boundary. 
+ *   pPredBufCol - pointer to the coefficient column buffer; must be aligned 
+ *            on a 4-byte boundary. 
+ *   curQP - quantization parameter of the current block. curQP may equal to 
+ *            predQP especially when the current block and the predictor block 
+ *            are in the same macroblock. 
+ *   predQP - quantization parameter of the predictor block 
+ *   predDir - indicates the prediction direction which takes one of the 
+ *            following values: OMX_VC_HORIZONTAL - predict horizontally 
+ *            OMX_VC_VERTICAL - predict vertically 
+ *   ACPredFlag - a flag indicating if AC prediction should be performed. It 
+ *            is equal to ac_pred_flag in the bit stream syntax of MPEG-4 
+ *   videoComp - video component type (luminance or chrominance) of the 
+ *            current block 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst - pointer to the coefficient buffer which contains the quantized 
+ *            coefficients (QF) of the current block 
+ *   pPredBufRow - pointer to the updated coefficient row buffer 
+ *   pPredBufCol - pointer to the updated coefficient column buffer  Note: 
+ *            Buffer update: Update the AC prediction buffer (both row and 
+ *            column buffer). 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments, if:
+ *        -    At least one of the pointers is NULL: 
+ *              pSrcDst, pPredBufRow, or pPredBufCol. 
+ *        -    curQP <= 0, 
+ *        -    predQP <= 0, 
+ *        -    curQP >31, 
+ *        -    predQP > 31, 
+ *        -    preDir exceeds [1,2]
+ *        -    pSrcDst, pPredBufRow, or pPredBufCol is not 4-byte aligned. 
+ *
+ */
+OMXResult omxVCM4P2_PredictReconCoefIntra (
+    OMX_S16 *pSrcDst,
+    OMX_S16 *pPredBufRow,
+    OMX_S16 *pPredBufCol,
+    OMX_INT curQP,
+    OMX_INT predQP,
+    OMX_INT predDir,
+    OMX_INT ACPredFlag,
+    OMXVCM4P2VideoComponent videoComp
+);
+
+
+
+/**
+ * Function:  omxVCM4P2_MCReconBlock   (6.2.5.5.1)
+ *
+ * Description:
+ * Performs motion compensation prediction for an 8x8 block using 
+ * interpolation described in [ISO14496-2], subclause 7.6.2. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - pointer to the block in the reference plane. 
+ *   srcStep - distance between the start of consecutive lines in the 
+ *            reference plane, in bytes; must be a multiple of 8. 
+ *   dstStep - distance between the start of consecutive lines in the 
+ *            destination plane, in bytes; must be a multiple of 8. 
+ *   pSrcResidue - pointer to a buffer containing the 16-bit prediction 
+ *            residuals; must be 16-byte aligned. If the pointer is NULL, then 
+ *            no prediction is done, only motion compensation, i.e., the block 
+ *            is moved with interpolation. 
+ *   predictType - bilinear interpolation type, as defined in section 
+ *            6.2.1.2. 
+ *   rndVal - rounding control parameter: 0 - disabled; 1 - enabled. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - pointer to the destination buffer; must be 8-byte aligned.  If 
+ *            prediction residuals are added then output intensities are 
+ *            clipped to the range [0,255]. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned under any of the following 
+ *              conditions: 
+ *    -    pDst is not 8-byte aligned. 
+ *    -    pSrcResidue is not 16-byte aligned. 
+ *    -    one or more of the following pointers is NULL: pSrc or pDst. 
+ *    -    either srcStep or dstStep is not a multiple of 8. 
+ *    -    invalid type specified for the parameter predictType. 
+ *    -    the parameter rndVal is not equal either to 0 or 1. 
+ *
+ */
+OMXResult omxVCM4P2_MCReconBlock (
+    const OMX_U8 *pSrc,
+    OMX_INT srcStep,
+    const OMX_S16 *pSrcResidue,
+    OMX_U8 *pDst,
+    OMX_INT dstStep,
+    OMX_INT predictType,
+    OMX_INT rndVal
+);
+
+
+
+/* 6.3.1.1 Intra 16x16 Prediction Modes  */
+/* A data type that enumerates intra_16x16 macroblock prediction modes is defined as follows:  */
+
+typedef enum {
+    OMX_VC_16X16_VERT = 0,  /** Intra_16x16_Vertical */
+    OMX_VC_16X16_HOR = 1,   /** Intra_16x16_Horizontal */
+    OMX_VC_16X16_DC = 2,    /** Intra_16x16_DC */
+    OMX_VC_16X16_PLANE = 3  /** Intra_16x16_Plane */ 
+} OMXVCM4P10Intra16x16PredMode;
+
+
+
+/* 6.3.1.2 Intra 4x4 Prediction Modes  */
+/* A data type that enumerates intra_4x4 macroblock prediction modes is defined as follows:  */
+
+typedef enum {
+    OMX_VC_4X4_VERT = 0,     /** Intra_4x4_Vertical */
+    OMX_VC_4X4_HOR = 1,      /** Intra_4x4_Horizontal */
+    OMX_VC_4X4_DC = 2,       /** Intra_4x4_DC */
+    OMX_VC_4X4_DIAG_DL = 3,  /** Intra_4x4_Diagonal_Down_Left */
+    OMX_VC_4X4_DIAG_DR = 4,  /** Intra_4x4_Diagonal_Down_Right */
+    OMX_VC_4X4_VR = 5,       /** Intra_4x4_Vertical_Right */
+    OMX_VC_4X4_HD = 6,       /** Intra_4x4_Horizontal_Down */
+    OMX_VC_4X4_VL = 7,       /** Intra_4x4_Vertical_Left */
+    OMX_VC_4X4_HU = 8        /** Intra_4x4_Horizontal_Up */ 
+} OMXVCM4P10Intra4x4PredMode;
+
+
+
+/* 6.3.1.3 Chroma Prediction Modes  */
+/* A data type that enumerates intra chroma prediction modes is defined as follows:  */
+
+typedef enum {
+    OMX_VC_CHROMA_DC = 0,    /** Intra_Chroma_DC */
+    OMX_VC_CHROMA_HOR = 1,   /** Intra_Chroma_Horizontal */
+    OMX_VC_CHROMA_VERT = 2,  /** Intra_Chroma_Vertical */
+    OMX_VC_CHROMA_PLANE = 3  /** Intra_Chroma_Plane */ 
+} OMXVCM4P10IntraChromaPredMode;
+
+
+
+/* 6.3.1.4 Motion Estimation Modes  */
+/* A data type that enumerates H.264 motion estimation modes is defined as follows:  */
+
+typedef enum {
+    OMX_VC_M4P10_FAST_SEARCH = 0, /** Fast motion search */
+    OMX_VC_M4P10_FULL_SEARCH = 1  /** Full motion search */ 
+} OMXVCM4P10MEMode;
+
+
+
+/* 6.3.1.5 Macroblock Types  */
+/* A data type that enumerates H.264 macroblock types is defined as follows:  */
+
+typedef enum {
+    OMX_VC_P_16x16  = 0, /* defined by [ISO14496-10] */
+    OMX_VC_P_16x8  = 1,
+    OMX_VC_P_8x16  = 2,
+    OMX_VC_P_8x8  = 3,
+    OMX_VC_PREF0_8x8  = 4,
+    OMX_VC_INTER_SKIP  = 5,
+    OMX_VC_INTRA_4x4  = 8,
+    OMX_VC_INTRA_16x16  = 9,
+    OMX_VC_INTRA_PCM = 10 
+} OMXVCM4P10MacroblockType;
+
+
+
+/* 6.3.1.6 Sub-Macroblock Types  */
+/* A data type that enumerates H.264 sub-macroblock types is defined as follows:  */
+
+typedef enum {
+    OMX_VC_SUB_P_8x8 = 0, /* defined by [ISO14496-10] */
+    OMX_VC_SUB_P_8x4 = 1,
+    OMX_VC_SUB_P_4x8 = 2,
+    OMX_VC_SUB_P_4x4 = 3 
+} OMXVCM4P10SubMacroblockType;
+
+
+
+/* 6.3.1.7 Variable Length Coding (VLC) Information  */
+
+typedef struct {
+    OMX_U8 uTrailing_Ones;      /* Trailing ones; 3 at most */
+    OMX_U8 uTrailing_One_Signs; /* Trailing ones signal */
+    OMX_U8 uNumCoeffs;          /* Total number of non-zero coefs, including trailing ones */
+    OMX_U8 uTotalZeros;         /* Total number of zero coefs */
+    OMX_S16 iLevels[16];        /* Levels of non-zero coefs, in reverse zig-zag order */
+    OMX_U8 uRuns[16];           /* Runs for levels and trailing ones, in reverse zig-zag order */
+} OMXVCM4P10VLCInfo;
+
+
+
+/* 6.3.1.8 Macroblock Information  */
+
+typedef struct {
+    OMX_S32 sliceId;                          /* slice number */
+    OMXVCM4P10MacroblockType mbType;          /* MB type */
+    OMXVCM4P10SubMacroblockType subMBType[4]; /* sub-block type */
+    OMX_S32 qpy;                              /* qp for luma */
+    OMX_S32 qpc;                              /* qp for chroma */
+    OMX_U32 cbpy;                             /* CBP Luma */
+    OMX_U32 cbpc;                             /* CBP Chroma */
+    OMXVCMotionVector pMV0[4][4]; /* motion vector, represented using 1/4-pel units, pMV0[blocky][blockx] (blocky = 0~3, blockx =0~3) */
+    OMXVCMotionVector pMVPred[4][4]; /* motion vector prediction, Represented using 1/4-pel units, pMVPred[blocky][blockx] (blocky = 0~3, blockx = 0~3) */
+    OMX_U8 pRefL0Idx[4];                      /* reference picture indices */
+    OMXVCM4P10Intra16x16PredMode Intra16x16PredMode; /* best intra 16x16 prediction mode */
+    OMXVCM4P10Intra4x4PredMode pIntra4x4PredMode[16]; /* best intra 4x4 prediction mode for each block, pMV0 indexed as above */
+} OMXVCM4P10MBInfo, *OMXVCM4P10MBInfoPtr;
+
+
+
+/* 6.3.1.9 Motion Estimation Parameters  */
+
+typedef struct {
+    OMX_S32 blockSplitEnable8x8; /* enables 16x8, 8x16, 8x8 */
+    OMX_S32 blockSplitEnable4x4; /* enable splitting of 8x4, 4x8, 4x4 blocks */
+    OMX_S32 halfSearchEnable;
+    OMX_S32 quarterSearchEnable;
+    OMX_S32 intraEnable4x4;      /* 1=enable, 0=disable */
+    OMX_S32 searchRange16x16;    /* integer pixel units */
+    OMX_S32 searchRange8x8;
+    OMX_S32 searchRange4x4;
+} OMXVCM4P10MEParams;
+
+
+
+/**
+ * Function:  omxVCM4P10_PredictIntra_4x4   (6.3.3.1.1)
+ *
+ * Description:
+ * Perform Intra_4x4 prediction for luma samples. If the upper-right block is 
+ * not available, then duplication work should be handled inside the function. 
+ * Users need not define them outside. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcLeft -  Pointer to the buffer of 4 left pixels: 
+ *                  p[x, y] (x = -1, y = 0..3) 
+ *   pSrcAbove - Pointer to the buffer of 8 above pixels: 
+ *                  p[x,y] (x = 0..7, y =-1); 
+ *               must be aligned on a 4-byte boundary. 
+ *   pSrcAboveLeft - Pointer to the above left pixels: p[x,y] (x = -1, y = -1) 
+ *   leftStep - Step of left pixel buffer; must be a multiple of 4. 
+ *   dstStep - Step of the destination buffer; must be a multiple of 4. 
+ *   predMode - Intra_4x4 prediction mode. 
+ *   availability - Neighboring 4x4 block availability flag, refer to 
+ *             "Neighboring Macroblock Availability" . 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - Pointer to the destination buffer; must be aligned on a 4-byte 
+ *            boundary. 
+ *
+ * Return Value:
+ *    If the function runs without error, it returns OMX_Sts_NoErr. 
+ *    If one of the following cases occurs, the function returns 
+ *              OMX_Sts_BadArgErr: 
+ *    pDst is NULL. 
+ *    dstStep < 4, or dstStep is not a multiple of 4. 
+ *    leftStep is not a multiple of 4. 
+ *    predMode is not in the valid range of enumeration 
+ *              OMXVCM4P10Intra4x4PredMode. 
+ *    predMode is OMX_VC_4x4_VERT, but availability doesn't set OMX_VC_UPPER 
+ *              indicating p[x,-1] (x = 0..3) is not available. 
+ *    predMode is OMX_VC_4x4_HOR, but availability doesn't set OMX_VC_LEFT 
+ *              indicating p[-1,y] (y = 0..3) is not available. 
+ *    predMode is OMX_VC_4x4_DIAG_DL, but availability doesn't set 
+ *              OMX_VC_UPPER indicating p[x, -1] (x = 0..3) is not available. 
+ *    predMode is OMX_VC_4x4_DIAG_DR, but availability doesn't set 
+ *              OMX_VC_UPPER_LEFT or OMX_VC_UPPER or OMX_VC_LEFT indicating 
+ *              p[x,-1] (x = 0..3), or p[-1,y] (y = 0..3) or p[-1,-1] is not 
+ *              available. 
+ *    predMode is OMX_VC_4x4_VR, but availability doesn't set 
+ *              OMX_VC_UPPER_LEFT or OMX_VC_UPPER or OMX_VC_LEFT indicating 
+ *              p[x,-1] (x = 0..3), or p[-1,y] (y = 0..3) or p[-1,-1] is not 
+ *              available. 
+ *    predMode is OMX_VC_4x4_HD, but availability doesn't set 
+ *              OMX_VC_UPPER_LEFT or OMX_VC_UPPER or OMX_VC_LEFT indicating 
+ *              p[x,-1] (x = 0..3), or p[-1,y] (y = 0..3) or p[-1,-1] is not 
+ *              available. 
+ *    predMode is OMX_VC_4x4_VL, but availability doesn't set OMX_VC_UPPER 
+ *              indicating p[x,-1] (x = 0..3) is not available. 
+ *    predMode is OMX_VC_4x4_HU, but availability doesn't set OMX_VC_LEFT 
+ *              indicating p[-1,y] (y = 0..3) is not available. 
+ *    availability sets OMX_VC_UPPER, but pSrcAbove is NULL. 
+ *    availability sets OMX_VC_LEFT, but pSrcLeft is NULL. 
+ *    availability sets OMX_VC_UPPER_LEFT, but pSrcAboveLeft is NULL. 
+ *    either pSrcAbove or pDst is not aligned on a 4-byte boundary.  
+ *
+ * Note: 
+ *     pSrcAbove, pSrcAbove, pSrcAboveLeft may be invalid pointers if 
+ *     they are not used by intra prediction as implied in predMode. 
+ *
+ */
+OMXResult omxVCM4P10_PredictIntra_4x4 (
+    const OMX_U8 *pSrcLeft,
+    const OMX_U8 *pSrcAbove,
+    const OMX_U8 *pSrcAboveLeft,
+    OMX_U8 *pDst,
+    OMX_INT leftStep,
+    OMX_INT dstStep,
+    OMXVCM4P10Intra4x4PredMode predMode,
+    OMX_S32 availability
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_PredictIntra_16x16   (6.3.3.1.2)
+ *
+ * Description:
+ * Perform Intra_16x16 prediction for luma samples. If the upper-right block 
+ * is not available, then duplication work should be handled inside the 
+ * function. Users need not define them outside. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcLeft - Pointer to the buffer of 16 left pixels: p[x, y] (x = -1, y = 
+ *            0..15) 
+ *   pSrcAbove - Pointer to the buffer of 16 above pixels: p[x,y] (x = 0..15, 
+ *            y= -1); must be aligned on a 16-byte boundary. 
+ *   pSrcAboveLeft - Pointer to the above left pixels: p[x,y] (x = -1, y = -1) 
+ *   leftStep - Step of left pixel buffer; must be a multiple of 16. 
+ *   dstStep - Step of the destination buffer; must be a multiple of 16. 
+ *   predMode - Intra_16x16 prediction mode, please refer to section 3.4.1. 
+ *   availability - Neighboring 16x16 MB availability flag. Refer to 
+ *                  section 3.4.4. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst -Pointer to the destination buffer; must be aligned on a 16-byte 
+ *            boundary. 
+ *
+ * Return Value:
+ *    If the function runs without error, it returns OMX_Sts_NoErr. 
+ *    If one of the following cases occurs, the function returns 
+ *              OMX_Sts_BadArgErr: 
+ *    pDst is NULL. 
+ *    dstStep < 16. or dstStep is not a multiple of 16. 
+ *    leftStep is not a multiple of 16. 
+ *    predMode is not in the valid range of enumeration 
+ *              OMXVCM4P10Intra16x16PredMode 
+ *    predMode is OMX_VC_16X16_VERT, but availability doesn't set 
+ *              OMX_VC_UPPER indicating p[x,-1] (x = 0..15) is not available. 
+ *    predMode is OMX_VC_16X16_HOR, but availability doesn't set OMX_VC_LEFT 
+ *              indicating p[-1,y] (y = 0..15) is not available. 
+ *    predMode is OMX_VC_16X16_PLANE, but availability doesn't set 
+ *              OMX_VC_UPPER_LEFT or OMX_VC_UPPER or OMX_VC_LEFT indicating 
+ *              p[x,-1](x = 0..15), or p[-1,y] (y = 0..15), or p[-1,-1] is not 
+ *              available. 
+ *    availability sets OMX_VC_UPPER, but pSrcAbove is NULL. 
+ *    availability sets OMX_VC_LEFT, but pSrcLeft is NULL. 
+ *    availability sets OMX_VC_UPPER_LEFT, but pSrcAboveLeft is NULL. 
+ *    either pSrcAbove or pDst is not aligned on a 16-byte boundary.  
+ *
+ * Note: 
+ *     pSrcAbove, pSrcAbove, pSrcAboveLeft may be invalid pointers if 
+ *     they are not used by intra prediction implied in predMode. 
+ * Note: 
+ *     OMX_VC_UPPER_RIGHT is not used in intra_16x16 luma prediction. 
+ *
+ */
+OMXResult omxVCM4P10_PredictIntra_16x16 (
+    const OMX_U8 *pSrcLeft,
+    const OMX_U8 *pSrcAbove,
+    const OMX_U8 *pSrcAboveLeft,
+    OMX_U8 *pDst,
+    OMX_INT leftStep,
+    OMX_INT dstStep,
+    OMXVCM4P10Intra16x16PredMode predMode,
+    OMX_S32 availability
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_PredictIntraChroma_8x8   (6.3.3.1.3)
+ *
+ * Description:
+ * Performs intra prediction for chroma samples. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcLeft - Pointer to the buffer of 8 left pixels: p[x, y] (x = -1, y= 
+ *            0..7). 
+ *   pSrcAbove - Pointer to the buffer of 8 above pixels: p[x,y] (x = 0..7, y 
+ *            = -1); must be aligned on an 8-byte boundary. 
+ *   pSrcAboveLeft - Pointer to the above left pixels: p[x,y] (x = -1, y = -1) 
+ *   leftStep - Step of left pixel buffer; must be a multiple of 8. 
+ *   dstStep - Step of the destination buffer; must be a multiple of 8. 
+ *   predMode - Intra chroma prediction mode, please refer to section 3.4.3. 
+ *   availability - Neighboring chroma block availability flag, please refer 
+ *            to  "Neighboring Macroblock Availability". 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - Pointer to the destination buffer; must be aligned on an 8-byte 
+ *            boundary. 
+ *
+ * Return Value:
+ *    If the function runs without error, it returns OMX_Sts_NoErr. 
+ *    If any of the following cases occurs, the function returns 
+ *              OMX_Sts_BadArgErr: 
+ *    pDst is NULL. 
+ *    dstStep < 8 or dstStep is not a multiple of 8. 
+ *    leftStep is not a multiple of 8. 
+ *    predMode is not in the valid range of enumeration 
+ *              OMXVCM4P10IntraChromaPredMode. 
+ *    predMode is OMX_VC_CHROMA_VERT, but availability doesn't set 
+ *              OMX_VC_UPPER indicating p[x,-1] (x = 0..7) is not available. 
+ *    predMode is OMX_VC_CHROMA_HOR, but availability doesn't set OMX_VC_LEFT 
+ *              indicating p[-1,y] (y = 0..7) is not available. 
+ *    predMode is OMX_VC_CHROMA_PLANE, but availability doesn't set 
+ *              OMX_VC_UPPER_LEFT or OMX_VC_UPPER or OMX_VC_LEFT indicating 
+ *              p[x,-1](x = 0..7), or p[-1,y] (y = 0..7), or p[-1,-1] is not 
+ *              available. 
+ *    availability sets OMX_VC_UPPER, but pSrcAbove is NULL. 
+ *    availability sets OMX_VC_LEFT, but pSrcLeft is NULL. 
+ *    availability sets OMX_VC_UPPER_LEFT, but pSrcAboveLeft is NULL. 
+ *    either pSrcAbove or pDst is not aligned on a 8-byte boundary.  
+ *
+ *  Note: pSrcAbove, pSrcAbove, pSrcAboveLeft may be invalid pointer if 
+ *  they are not used by intra prediction implied in predMode. 
+ *
+ *  Note: OMX_VC_UPPER_RIGHT is not used in intra chroma prediction. 
+ *
+ */
+OMXResult omxVCM4P10_PredictIntraChroma_8x8 (
+    const OMX_U8 *pSrcLeft,
+    const OMX_U8 *pSrcAbove,
+    const OMX_U8 *pSrcAboveLeft,
+    OMX_U8 *pDst,
+    OMX_INT leftStep,
+    OMX_INT dstStep,
+    OMXVCM4P10IntraChromaPredMode predMode,
+    OMX_S32 availability
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_InterpolateLuma   (6.3.3.2.1)
+ *
+ * Description:
+ * Performs quarter-pixel interpolation for inter luma MB. It is assumed that 
+ * the frame is already padded when calling this function. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - Pointer to the source reference frame buffer 
+ *   srcStep - reference frame step, in bytes; must be a multiple of roi.width 
+ *   dstStep - destination frame step, in bytes; must be a multiple of 
+ *            roi.width 
+ *   dx - Fractional part of horizontal motion vector component in 1/4 pixel 
+ *            unit; valid in the range [0,3] 
+ *   dy - Fractional part of vertical motion vector y component in 1/4 pixel 
+ *            unit; valid in the range [0,3] 
+ *   roi - Dimension of the interpolation region; the parameters roi.width and 
+ *            roi.height must be equal to either 4, 8, or 16. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - Pointer to the destination frame buffer: 
+ *          if roi.width==4,  4-byte alignment required 
+ *          if roi.width==8,  8-byte alignment required 
+ *          if roi.width==16, 16-byte alignment required 
+ *
+ * Return Value:
+ *    If the function runs without error, it returns OMX_Sts_NoErr. 
+ *    If one of the following cases occurs, the function returns 
+ *              OMX_Sts_BadArgErr: 
+ *    pSrc or pDst is NULL. 
+ *    srcStep or dstStep < roi.width. 
+ *    dx or dy is out of range [0,3]. 
+ *    roi.width or roi.height is out of range {4, 8, 16}. 
+ *    roi.width is equal to 4, but pDst is not 4 byte aligned. 
+ *    roi.width is equal to 8 or 16, but pDst is not 8 byte aligned. 
+ *    srcStep or dstStep is not a multiple of 8. 
+ *
+ */
+OMXResult omxVCM4P10_InterpolateLuma (
+    const OMX_U8 *pSrc,
+    OMX_S32 srcStep,
+    OMX_U8 *pDst,
+    OMX_S32 dstStep,
+    OMX_S32 dx,
+    OMX_S32 dy,
+    OMXSize roi
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_InterpolateChroma   (6.3.3.2.2)
+ *
+ * Description:
+ * Performs 1/8-pixel interpolation for inter chroma MB. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc -Pointer to the source reference frame buffer 
+ *   srcStep -Reference frame step in bytes 
+ *   dstStep -Destination frame step in bytes; must be a multiple of 
+ *            roi.width. 
+ *   dx -Fractional part of horizontal motion vector component in 1/8 pixel 
+ *            unit; valid in the range [0,7] 
+ *   dy -Fractional part of vertical motion vector component in 1/8 pixel 
+ *            unit; valid in the range [0,7] 
+ *   roi -Dimension of the interpolation region; the parameters roi.width and 
+ *            roi.height must be equal to either 2, 4, or 8. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst -Pointer to the destination frame buffer:
+ *         if roi.width==2,  2-byte alignment required 
+ *         if roi.width==4,  4-byte alignment required 
+ *         if roi.width==8, 8-byte alignment required 
+ *
+ * Return Value:
+ *    If the function runs without error, it returns OMX_Sts_NoErr. 
+ *    If one of the following cases occurs, the function returns 
+ *              OMX_Sts_BadArgErr: 
+ *    pSrc or pDst is NULL. 
+ *    srcStep or dstStep < 8. 
+ *    dx or dy is out of range [0-7]. 
+ *    roi.width or roi.height is out of range {2,4,8}. 
+ *    roi.width is equal to 2, but pDst is not 2-byte aligned. 
+ *    roi.width is equal to 4, but pDst is not 4-byte aligned. 
+ *    roi.width is equal to 8, but pDst is not 8 byte aligned. 
+ *    srcStep or dstStep is not a multiple of 8. 
+ *
+ */
+OMXResult omxVCM4P10_InterpolateChroma (
+    const OMX_U8 *pSrc,
+    OMX_S32 srcStep,
+    OMX_U8 *pDst,
+    OMX_S32 dstStep,
+    OMX_S32 dx,
+    OMX_S32 dy,
+    OMXSize roi
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_FilterDeblockingLuma_VerEdge_I   (6.3.3.3.1)
+ *
+ * Description:
+ * Performs in-place deblock filtering on four vertical edges of the luma 
+ * macroblock (16x16). 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - Pointer to the input macroblock; must be 16-byte aligned. 
+ *   srcdstStep -Step of the arrays; must be a multiple of 16. 
+ *   pAlpha -Array of size 2 of alpha thresholds (the first item is the alpha 
+ *            threshold for the external vertical edge, and the second item is 
+ *            for the internal vertical edge); per [ISO14496-10] alpha values 
+ *            must be in the range [0,255]. 
+ *   pBeta -Array of size 2 of beta thresholds (the first item is the beta 
+ *            threshold for the external vertical edge, and the second item is 
+ *            for the internal vertical edge); per [ISO14496-10] beta values 
+ *            must be in the range [0,18]. 
+ *   pThresholds -Array of size 16 of Thresholds (TC0) (values for the left 
+ *            edge of each 4x4 block, arranged in vertical block order); must 
+ *            be aligned on a 4-byte boundary..  Per [ISO14496-10] values must 
+ *            be in the range [0,25]. 
+ *   pBS -Array of size 16 of BS parameters (arranged in vertical block 
+ *            order); valid in the range [0,4] with the following 
+ *            restrictions: i) pBS[i]== 4 may occur only for 0<=i<=3, ii) 
+ *            pBS[i]== 4 if and only if pBS[i^3]== 4.  Must be 4-byte aligned. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst -Pointer to filtered output macroblock. 
+ *
+ * Return Value:
+ *    If the function runs without error, it returns OMX_Sts_NoErr. 
+ *    If one of the following cases occurs, the function returns 
+ *              OMX_Sts_BadArgErr: 
+ *    Either of the pointers in pSrcDst, pAlpha, pBeta, pThresholds, or pBS 
+ *              is NULL. 
+ *    Either pThresholds or pBS is not aligned on a 4-byte boundary. 
+ *    pSrcDst is not 16-byte aligned. 
+ *    srcdstStep is not a multiple of 16. 
+ *    pAlpha[0] and/or pAlpha[1] is outside the range [0,255]. 
+ *    pBeta[0] and/or pBeta[1] is outside the range [0,18]. 
+ *    One or more entries in the table pThresholds[0..15]is outside of the 
+ *              range [0,25]. 
+ *    pBS is out of range, i.e., one of the following conditions is true: 
+ *              pBS[i]<0, pBS[i]>4, pBS[i]==4 for i>=4, or (pBS[i]==4 && 
+ *              pBS[i^3]!=4) for 0<=i<=3. 
+ *
+ */
+OMXResult omxVCM4P10_FilterDeblockingLuma_VerEdge_I (
+    OMX_U8 *pSrcDst,
+    OMX_S32 srcdstStep,
+    const OMX_U8 *pAlpha,
+    const OMX_U8 *pBeta,
+    const OMX_U8 *pThresholds,
+    const OMX_U8 *pBS
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_FilterDeblockingLuma_HorEdge_I   (6.3.3.3.2)
+ *
+ * Description:
+ * Performs in-place deblock filtering on four horizontal edges of the luma 
+ * macroblock (16x16). 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - pointer to the input macroblock; must be 16-byte aligned. 
+ *   srcdstStep - step of the arrays; must be a multiple of 16. 
+ *   pAlpha - array of size 2 of alpha thresholds (the first item is the alpha 
+ *            threshold for the external vertical edge, and the second item is 
+ *            for the internal horizontal edge); per [ISO14496-10] alpha 
+ *            values must be in the range [0,255]. 
+ *   pBeta - array of size 2 of beta thresholds (the first item is the beta 
+ *            threshold for the external horizontal edge, and the second item 
+ *            is for the internal horizontal edge). Per [ISO14496-10] beta 
+ *            values must be in the range [0,18]. 
+ *   pThresholds - array of size 16 containing thresholds, TC0, for the top 
+ *            horizontal edge of each 4x4 block, arranged in horizontal block 
+ *            order; must be aligned on a 4-byte boundary.  Per [ISO14496 10] 
+ *            values must be in the range [0,25]. 
+ *   pBS - array of size 16 of BS parameters (arranged in horizontal block 
+ *            order); valid in the range [0,4] with the following 
+ *            restrictions: i) pBS[i]== 4 may occur only for 0<=i<=3, ii) 
+ *            pBS[i]== 4 if and only if pBS[i^3]== 4.  Must be 4-byte aligned. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst -Pointer to filtered output macroblock. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr, if the function runs without error.
+ * 
+ *    OMX_Sts_BadArgErr, if one of the following cases occurs: 
+ *    -    one or more of the following pointers is NULL: pSrcDst, pAlpha, 
+ *              pBeta, pThresholds, or pBS. 
+ *    -    either pThresholds or pBS is not aligned on a 4-byte boundary. 
+ *    -    pSrcDst is not 16-byte aligned. 
+ *    -    srcdstStep is not a multiple of 16. 
+ *    -    pAlpha[0] and/or pAlpha[1] is outside the range [0,255]. 
+ *    -    pBeta[0] and/or pBeta[1] is outside the range [0,18]. 
+ *    -    One or more entries in the table pThresholds[0..15] is 
+ *         outside of the range [0,25]. 
+ *    -    pBS is out of range, i.e., one of the following conditions is true: 
+ *              pBS[i]<0, pBS[i]>4, pBS[i]==4 for i>=4, or 
+ *              (pBS[i]==4 && pBS[i^3]!=4) for 0<=i<=3. 
+ *
+ */
+OMXResult omxVCM4P10_FilterDeblockingLuma_HorEdge_I (
+    OMX_U8 *pSrcDst,
+    OMX_S32 srcdstStep,
+    const OMX_U8 *pAlpha,
+    const OMX_U8 *pBeta,
+    const OMX_U8 *pThresholds,
+    const OMX_U8 *pBS
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_FilterDeblockingChroma_VerEdge_I   (6.3.3.3.3)
+ *
+ * Description:
+ * Performs in-place deblock filtering on four vertical edges of the chroma 
+ * macroblock (8x8). 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - Pointer to the input macroblock; must be 8-byte aligned. 
+ *   srcdstStep - Step of the arrays; must be a multiple of 8. 
+ *   pAlpha - Array of size 2 of alpha thresholds (the first item is alpha 
+ *            threshold for external vertical edge, and the second item is for 
+ *            internal vertical edge); per [ISO14496-10] alpha values must be 
+ *            in the range [0,255]. 
+ *   pBeta - Array of size 2 of beta thresholds (the first item is the beta 
+ *            threshold for the external vertical edge, and the second item is 
+ *            for the internal vertical edge); per [ISO14496-10] beta values 
+ *            must be in the range [0,18]. 
+ *   pThresholds - Array of size 8 containing thresholds, TC0, for the left 
+ *            vertical edge of each 4x2 chroma block, arranged in vertical 
+ *            block order; must be aligned on a 4-byte boundary.  Per 
+ *            [ISO14496-10] values must be in the range [0,25]. 
+ *   pBS - Array of size 16 of BS parameters (values for each 2x2 chroma 
+ *            block, arranged in vertical block order). This parameter is the 
+ *            same as the pBS parameter passed into FilterDeblockLuma_VerEdge; 
+ *            valid in the range [0,4] with the following restrictions: i) 
+ *            pBS[i]== 4 may occur only for 0<=i<=3, ii) pBS[i]== 4 if and 
+ *            only if pBS[i^3]== 4.  Must be 4 byte aligned. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst -Pointer to filtered output macroblock. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr, if the function runs without error.
+ * 
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    one or more of the following pointers is NULL: pSrcDst, pAlpha, 
+ *              pBeta, pThresholds, or pBS. 
+ *    -    pSrcDst is not 8-byte aligned. 
+ *    -    srcdstStep is not a multiple of 8. 
+ *    -    pThresholds is not 4-byte aligned. 
+ *    -    pAlpha[0] and/or pAlpha[1] is outside the range [0,255]. 
+ *    -    pBeta[0] and/or pBeta[1] is outside the range [0,18]. 
+ *    -    One or more entries in the table pThresholds[0..7] is outside 
+ *         of the range [0,25]. 
+ *    -    pBS is out of range, i.e., one of the following conditions is true: 
+ *         pBS[i]<0, pBS[i]>4, pBS[i]==4 for i>=4, or 
+ *         (pBS[i]==4 && pBS[i^3]!=4) for 0<=i<=3. 
+ *    -    pBS is not 4-byte aligned. 
+ *
+ */
+OMXResult omxVCM4P10_FilterDeblockingChroma_VerEdge_I (
+    OMX_U8 *pSrcDst,
+    OMX_S32 srcdstStep,
+    const OMX_U8 *pAlpha,
+    const OMX_U8 *pBeta,
+    const OMX_U8 *pThresholds,
+    const OMX_U8 *pBS
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_FilterDeblockingChroma_HorEdge_I   (6.3.3.3.4)
+ *
+ * Description:
+ * Performs in-place deblock filtering on the horizontal edges of the chroma 
+ * macroblock (8x8). 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - pointer to the input macroblock; must be 8-byte aligned. 
+ *   srcdstStep - array step; must be a multiple of 8. 
+ *   pAlpha - array of size 2 containing alpha thresholds; the first element 
+ *            contains the threshold for the external horizontal edge, and the 
+ *            second element contains the threshold for internal horizontal 
+ *            edge.  Per [ISO14496-10] alpha values must be in the range 
+ *            [0,255]. 
+ *   pBeta - array of size 2 containing beta thresholds; the first element 
+ *            contains the threshold for the external horizontal edge, and the 
+ *            second element contains the threshold for the internal 
+ *            horizontal edge.  Per [ISO14496-10] beta values must be in the 
+ *            range [0,18]. 
+ *   pThresholds - array of size 8 containing thresholds, TC0, for the top 
+ *            horizontal edge of each 2x4 chroma block, arranged in horizontal 
+ *            block order; must be aligned on a 4-byte boundary.  Per 
+ *            [ISO14496-10] values must be in the range [0,25]. 
+ *   pBS - array of size 16 containing BS parameters for each 2x2 chroma 
+ *            block, arranged in horizontal block order; valid in the range 
+ *            [0,4] with the following restrictions: i) pBS[i]== 4 may occur 
+ *            only for 0<=i<=3, ii) pBS[i]== 4 if and only if pBS[i^3]== 4. 
+ *            Must be 4-byte aligned. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst -Pointer to filtered output macroblock. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr, if the function runs without error.
+ * 
+ *    OMX_Sts_BadArgErr, if one of the following cases occurs: 
+ *    -    any of the following pointers is NULL: 
+ *         pSrcDst, pAlpha, pBeta, pThresholds, or pBS. 
+ *    -    pSrcDst is not 8-byte aligned. 
+ *    -    srcdstStep is not a multiple of 8. 
+ *    -    pThresholds is not 4-byte aligned. 
+ *    -    pAlpha[0] and/or pAlpha[1] is outside the range [0,255]. 
+ *    -    pBeta[0] and/or pBeta[1] is outside the range [0,18]. 
+ *    -    One or more entries in the table pThresholds[0..7] is outside 
+ *         of the range [0,25]. 
+ *    -    pBS is out of range, i.e., one of the following conditions is true: 
+ *              pBS[i]<0, pBS[i]>4, pBS[i]==4 for i>=4, or 
+ *              (pBS[i]==4 && pBS[i^3]!=4) for 0<=i<=3.
+ *    -    pBS is not 4-byte aligned. 
+ *
+ */
+OMXResult omxVCM4P10_FilterDeblockingChroma_HorEdge_I (
+    OMX_U8 *pSrcDst,
+    OMX_S32 srcdstStep,
+    const OMX_U8 *pAlpha,
+    const OMX_U8 *pBeta,
+    const OMX_U8 *pThresholds,
+    const OMX_U8 *pBS
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_DeblockLuma_I   (6.3.3.3.5)
+ *
+ * Description:
+ * This function performs in-place deblock filtering the horizontal and 
+ * vertical edges of a luma macroblock (16x16). 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - pointer to the input macroblock; must be 16-byte aligned. 
+ *   srcdstStep - image width; must be a multiple of 16. 
+ *   pAlpha - pointer to a 2x2 table of alpha thresholds, organized as 
+ *            follows: {external vertical edge, internal vertical edge, 
+ *            external horizontal edge, internal horizontal edge }.  Per 
+ *            [ISO14496-10] alpha values must be in the range [0,255]. 
+ *   pBeta - pointer to a 2x2 table of beta thresholds, organized as follows: 
+ *            {external vertical edge, internal vertical edge, external 
+ *            horizontal edge, internal horizontal edge }.  Per [ISO14496-10] 
+ *            beta values must be in the range [0,18]. 
+ *   pThresholds - pointer to a 16x2 table of threshold (TC0), organized as 
+ *            follows: {values for the left or above edge of each 4x4 block, 
+ *            arranged in vertical block order and then in horizontal block 
+ *            order}; must be aligned on a 4-byte boundary.  Per [ISO14496-10] 
+ *            values must be in the range [0,25]. 
+ *   pBS - pointer to a 16x2 table of BS parameters arranged in scan block 
+ *            order for vertical edges and then horizontal edges; valid in the 
+ *            range [0,4] with the following restrictions: i) pBS[i]== 4 may 
+ *            occur only for 0<=i<=3, ii) pBS[i]== 4 if and only if pBS[i^3]== 
+ *            4. Must be 4-byte aligned. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst - pointer to filtered output macroblock. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments 
+ *    -     one or more of the following pointers is NULL: pSrcDst, pAlpha, 
+ *              pBeta, pThresholds or pBS. 
+ *    -    pSrcDst is not 16-byte aligned. 
+ *    -    either pThresholds or pBS is not aligned on a 4-byte boundary. 
+ *    -    one or more entries in the table pAlpha[0..3] is outside the range 
+ *              [0,255]. 
+ *    -    one or more entries in the table pBeta[0..3] is outside the range 
+ *              [0,18]. 
+ *    -    one or more entries in the table pThresholds[0..31]is outside of 
+ *              the range [0,25]. 
+ *    -    pBS is out of range, i.e., one of the following conditions is true: 
+ *              pBS[i]<0, pBS[i]>4, pBS[i]==4 for i>=4, or 
+ *             (pBS[i]==4 && pBS[i^3]!=4) for 0<=i<=3. 
+ *    -    srcdstStep is not a multiple of 16. 
+ *
+ */
+OMXResult omxVCM4P10_DeblockLuma_I (
+    OMX_U8 *pSrcDst,
+    OMX_S32 srcdstStep,
+    const OMX_U8 *pAlpha,
+    const OMX_U8 *pBeta,
+    const OMX_U8 *pThresholds,
+    const OMX_U8 *pBS
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_DeblockChroma_I   (6.3.3.3.6)
+ *
+ * Description:
+ * Performs in-place deblocking filtering on all edges of the chroma 
+ * macroblock (16x16). 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - pointer to the input macroblock; must be 8-byte aligned. 
+ *   srcdstStep - step of the arrays; must be a multiple of 8. 
+ *   pAlpha - pointer to a 2x2 array of alpha thresholds, organized as 
+ *            follows: {external vertical edge, internal vertical edge, 
+ *            external horizontal edge, internal horizontal edge }.  Per 
+ *            [ISO14496-10] alpha values must be in the range [0,255]. 
+ *   pBeta - pointer to a 2x2 array of Beta Thresholds, organized as follows: 
+ *            { external vertical edge, internal vertical edge, external 
+ *            horizontal edge, internal horizontal edge }.  Per [ISO14496-10] 
+ *            beta values must be in the range [0,18]. 
+ *   pThresholds - array of size 8x2 of Thresholds (TC0) (values for the left 
+ *            or above edge of each 4x2 or 2x4 block, arranged in vertical 
+ *            block order and then in horizontal block order); must be aligned 
+ *            on a 4-byte boundary. Per [ISO14496-10] values must be in the 
+ *            range [0,25]. 
+ *   pBS - array of size 16x2 of BS parameters (arranged in scan block order 
+ *            for vertical edges and then horizontal edges); valid in the 
+ *            range [0,4] with the following restrictions: i) pBS[i]== 4 may 
+ *            occur only for 0<=i<=3, ii) pBS[i]== 4 if and only if pBS[i^3]== 
+ *            4.  Must be 4-byte aligned. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst - pointer to filtered output macroblock. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments 
+ *    -   one or more of the following pointers is NULL: pSrcDst, pAlpha, 
+ *              pBeta, pThresholds, or pBS. 
+ *    -   pSrcDst is not 8-byte aligned. 
+ *    -   either pThresholds or pBS is not 4-byte aligned. 
+ *    -   one or more entries in the table pAlpha[0..3] is outside the range 
+ *              [0,255]. 
+ *    -   one or more entries in the table pBeta[0..3] is outside the range 
+ *              [0,18]. 
+ *    -   one or more entries in the table pThresholds[0..15]is outside of 
+ *              the range [0,25]. 
+ *    -   pBS is out of range, i.e., one of the following conditions is true: 
+ *            pBS[i]<0, pBS[i]>4, pBS[i]==4  for i>=4, or 
+ *            (pBS[i]==4 && pBS[i^3]!=4) for 0<=i<=3. 
+ *    -   srcdstStep is not a multiple of 8. 
+ *
+ */
+OMXResult omxVCM4P10_DeblockChroma_I (
+    OMX_U8 *pSrcDst,
+    OMX_S32 srcdstStep,
+    const OMX_U8 *pAlpha,
+    const OMX_U8 *pBeta,
+    const OMX_U8 *pThresholds,
+    const OMX_U8 *pBS
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_DecodeChromaDcCoeffsToPairCAVLC   (6.3.4.1.1)
+ *
+ * Description:
+ * Performs CAVLC decoding and inverse raster scan for a 2x2 block of 
+ * ChromaDCLevel.  The decoded coefficients in the packed position-coefficient 
+ * buffer are stored in reverse zig-zag order, i.e., the first buffer element 
+ * contains the last non-zero postion-coefficient pair of the block. Within 
+ * each position-coefficient pair, the position entry indicates the 
+ * raster-scan position of the coefficient, while the coefficient entry 
+ * contains the coefficient value. 
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - Double pointer to current byte in bit stream buffer 
+ *   pOffset - Pointer to current bit position in the byte pointed to by 
+ *            *ppBitStream; valid in the range [0,7]. 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after each block is decoded 
+ *   pOffset - *pOffset is updated after each block is decoded 
+ *   pNumCoeff - Pointer to the number of nonzero coefficients in this block 
+ *   ppPosCoefBuf - Double pointer to destination residual 
+ *            coefficient-position pair buffer.  Buffer position 
+ *            (*ppPosCoefBuf) is updated upon return, unless there are only 
+ *            zero coefficients in the currently decoded block.  In this case 
+ *            the caller is expected to bypass the transform/dequantization of 
+ *            the empty blocks. 
+ *
+ * Return Value:
+ *
+ *    OMX_Sts_NoErr, if the function runs without error.
+ * 
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    ppBitStream or pOffset is NULL. 
+ *    -    ppPosCoefBuf or pNumCoeff is NULL. 
+ *    OMX_Sts_Err - if one of the following is true: 
+ *    -    an illegal code is encountered in the bitstream 
+ *
+ */
+OMXResult omxVCM4P10_DecodeChromaDcCoeffsToPairCAVLC (
+    const OMX_U8 **ppBitStream,
+    OMX_S32*pOffset,
+    OMX_U8 *pNumCoeff,
+    OMX_U8 **ppPosCoefbuf
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_DecodeCoeffsToPairCAVLC   (6.3.4.1.2)
+ *
+ * Description:
+ * Performs CAVLC decoding and inverse zigzag scan for 4x4 block of 
+ * Intra16x16DCLevel, Intra16x16ACLevel, LumaLevel, and ChromaACLevel. Inverse 
+ * field scan is not supported. The decoded coefficients in the packed 
+ * position-coefficient buffer are stored in reverse zig-zag order, i.e., the 
+ * first buffer element contains the last non-zero postion-coefficient pair of 
+ * the block. Within each position-coefficient pair, the position entry 
+ * indicates the raster-scan position of the coefficient, while the 
+ * coefficient entry contains the coefficient value. 
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream -Double pointer to current byte in bit stream buffer 
+ *   pOffset - Pointer to current bit position in the byte pointed to by 
+ *            *ppBitStream; valid in the range [0,7]. 
+ *   sMaxNumCoeff - Maximum the number of non-zero coefficients in current 
+ *            block 
+ *   sVLCSelect - VLC table selector, obtained from the number of non-zero 
+ *            coefficients contained in the above and left 4x4 blocks.  It is 
+ *            equivalent to the variable nC described in H.264 standard table 
+ *            9 5, except its value can t be less than zero. 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after each block is decoded.  
+ *            Buffer position (*ppPosCoefBuf) is updated upon return, unless 
+ *            there are only zero coefficients in the currently decoded block. 
+ *             In this case the caller is expected to bypass the 
+ *            transform/dequantization of the empty blocks. 
+ *   pOffset - *pOffset is updated after each block is decoded 
+ *   pNumCoeff - Pointer to the number of nonzero coefficients in this block 
+ *   ppPosCoefBuf - Double pointer to destination residual 
+ *            coefficient-position pair buffer 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ * 
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    ppBitStream or pOffset is NULL. 
+ *    -    ppPosCoefBuf or pNumCoeff is NULL. 
+ *    -    sMaxNumCoeff is not equal to either 15 or 16. 
+ *    -    sVLCSelect is less than 0. 
+ *
+ *    OMX_Sts_Err - if one of the following is true: 
+ *    -    an illegal code is encountered in the bitstream 
+ *
+ */
+OMXResult omxVCM4P10_DecodeCoeffsToPairCAVLC (
+    const OMX_U8 **ppBitStream,
+    OMX_S32 *pOffset,
+    OMX_U8 *pNumCoeff,
+    OMX_U8 **ppPosCoefbuf,
+    OMX_INT sVLCSelect,
+    OMX_INT sMaxNumCoeff
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_TransformDequantLumaDCFromPair   (6.3.4.2.1)
+ *
+ * Description:
+ * Reconstructs the 4x4 LumaDC block from the coefficient-position pair 
+ * buffer, performs integer inverse, and dequantization for 4x4 LumaDC 
+ * coefficients, and updates the pair buffer pointer to the next non-empty 
+ * block. 
+ *
+ * Input Arguments:
+ *   
+ *   ppSrc - Double pointer to residual coefficient-position pair buffer 
+ *            output by CALVC decoding 
+ *   QP - Quantization parameter QpY 
+ *
+ * Output Arguments:
+ *   
+ *   ppSrc - *ppSrc is updated to the start of next non empty block 
+ *   pDst - Pointer to the reconstructed 4x4 LumaDC coefficients buffer; must 
+ *            be aligned on a 8-byte boundary. 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    ppSrc or pDst is NULL. 
+ *    -    pDst is not 8 byte aligned. 
+ *    -    QP is not in the range of [0-51]. 
+ *
+ */
+OMXResult omxVCM4P10_TransformDequantLumaDCFromPair (
+    const OMX_U8 **ppSrc,
+    OMX_S16 *pDst,
+    OMX_INT QP
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_TransformDequantChromaDCFromPair   (6.3.4.2.2)
+ *
+ * Description:
+ * Reconstruct the 2x2 ChromaDC block from coefficient-position pair buffer, 
+ * perform integer inverse transformation, and dequantization for 2x2 chroma 
+ * DC coefficients, and update the pair buffer pointer to next non-empty 
+ * block. 
+ *
+ * Input Arguments:
+ *   
+ *   ppSrc - Double pointer to residual coefficient-position pair buffer 
+ *            output by CALVC decoding 
+ *   QP - Quantization parameter QpC 
+ *
+ * Output Arguments:
+ *   
+ *   ppSrc - *ppSrc is updated to the start of next non empty block 
+ *   pDst - Pointer to the reconstructed 2x2 ChromaDC coefficients buffer; 
+ *            must be aligned on a 4-byte boundary. 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    ppSrc or pDst is NULL. 
+ *    -    pDst is not 4-byte aligned. 
+ *    -    QP is not in the range of [0-51]. 
+ *
+ */
+OMXResult omxVCM4P10_TransformDequantChromaDCFromPair (
+    const OMX_U8 **ppSrc,
+    OMX_S16 *pDst,
+    OMX_INT QP
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_DequantTransformResidualFromPairAndAdd   (6.3.4.2.3)
+ *
+ * Description:
+ * Reconstruct the 4x4 residual block from coefficient-position pair buffer, 
+ * perform dequantization and integer inverse transformation for 4x4 block of 
+ * residuals with previous intra prediction or motion compensation data, and 
+ * update the pair buffer pointer to next non-empty block. If pDC == NULL, 
+ * there re 16 non-zero AC coefficients at most in the packed buffer starting 
+ * from 4x4 block position 0; If pDC != NULL, there re 15 non-zero AC 
+ * coefficients at most in the packet buffer starting from 4x4 block position 
+ * 1. 
+ *
+ * Input Arguments:
+ *   
+ *   ppSrc - Double pointer to residual coefficient-position pair buffer 
+ *            output by CALVC decoding 
+ *   pPred - Pointer to the predicted 4x4 block; must be aligned on a 4-byte 
+ *            boundary 
+ *   predStep - Predicted frame step size in bytes; must be a multiple of 4 
+ *   dstStep - Destination frame step in bytes; must be a multiple of 4 
+ *   pDC - Pointer to the DC coefficient of this block, NULL if it doesn't 
+ *            exist 
+ *   QP - QP Quantization parameter.  It should be QpC in chroma 4x4 block 
+ *            decoding, otherwise it should be QpY. 
+ *   AC - Flag indicating if at least one non-zero AC coefficient exists 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - pointer to the reconstructed 4x4 block data; must be aligned on a 
+ *            4-byte boundary 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    pPred or pDst is NULL. 
+ *    -    pPred or pDst is not 4-byte aligned. 
+ *    -    predStep or dstStep is not a multiple of 4. 
+ *    -    AC !=0 and Qp is not in the range of [0-51] or ppSrc == NULL. 
+ *    -    AC ==0 && pDC ==NULL. 
+ *
+ */
+OMXResult omxVCM4P10_DequantTransformResidualFromPairAndAdd (
+    const OMX_U8 **ppSrc,
+    const OMX_U8 *pPred,
+    const OMX_S16 *pDC,
+    OMX_U8 *pDst,
+    OMX_INT predStep,
+    OMX_INT dstStep,
+    OMX_INT QP,
+    OMX_INT AC
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_MEGetBufSize   (6.3.5.1.1)
+ *
+ * Description:
+ * Computes the size, in bytes, of the vendor-specific specification 
+ * structure for the omxVCM4P10 motion estimation functions BlockMatch_Integer 
+ * and MotionEstimationMB. 
+ *
+ * Input Arguments:
+ *   
+ *   MEmode - motion estimation mode; available modes are defined by the 
+ *            enumerated type OMXVCM4P10MEMode 
+ *   pMEParams -motion estimation parameters 
+ *
+ * Output Arguments:
+ *   
+ *   pSize - pointer to the number of bytes required for the motion 
+ *            estimation specification structure 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    pMEParams or pSize is NULL. 
+ *    -    an invalid MEMode is specified. 
+ *
+ */
+OMXResult omxVCM4P10_MEGetBufSize (
+    OMXVCM4P10MEMode MEmode,
+    const OMXVCM4P10MEParams *pMEParams,
+    OMX_U32 *pSize
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_MEInit   (6.3.5.1.2)
+ *
+ * Description:
+ * Initializes the vendor-specific specification structure required for the 
+ * omxVCM4P10 motion estimation functions:  BlockMatch_Integer and 
+ * MotionEstimationMB. Memory for the specification structure *pMESpec must be 
+ * allocated prior to calling the function, and should be aligned on a 4-byte 
+ * boundary.  The number of bytes required for the specification structure can 
+ * be determined using the function omxVCM4P10_MEGetBufSize. Following 
+ * initialization by this function, the vendor-specific structure *pMESpec 
+ * should contain an implementation-specific representation of all motion 
+ * estimation parameters received via the structure pMEParams, for example  
+ * searchRange16x16, searchRange8x8, etc. 
+ *
+ * Input Arguments:
+ *   
+ *   MEmode - motion estimation mode; available modes are defined by the 
+ *            enumerated type OMXVCM4P10MEMode 
+ *   pMEParams - motion estimation parameters 
+ *   pMESpec - pointer to the uninitialized ME specification structure 
+ *
+ * Output Arguments:
+ *   
+ *   pMESpec - pointer to the initialized ME specification structure 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    pMEParams or pSize is NULL. 
+ *    -    an invalid value was specified for the parameter MEmode 
+ *    -    a negative or zero value was specified for one of the search ranges 
+ *         (e.g.,  pMBParams >searchRange8x8, pMEParams->searchRange16x16, etc.) 
+ *    -    either in isolation or in combination, one or more of the enables or 
+ *         search ranges in the structure *pMEParams were configured such 
+ *         that the requested behavior fails to comply with [ISO14496-10]. 
+ *
+ */
+OMXResult omxVCM4P10_MEInit (
+    OMXVCM4P10MEMode MEmode,
+    const OMXVCM4P10MEParams *pMEParams,
+    void *pMESpec
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_BlockMatch_Integer   (6.3.5.2.1)
+ *
+ * Description:
+ * Performs integer block match.  Returns best MV and associated cost. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcOrgY - Pointer to the top-left corner of the current block:
+ *            If iBlockWidth==4,  4-byte alignment required. 
+ *            If iBlockWidth==8,  8-byte alignment required. 
+ *            If iBlockWidth==16, 16-byte alignment required. 
+ *   pSrcRefY - Pointer to the top-left corner of the co-located block in the 
+ *            reference picture: 
+ *            If iBlockWidth==4,  4-byte alignment required.  
+ *            If iBlockWidth==8,  8-byte alignment required.  
+ *            If iBlockWidth==16, 16-byte alignment required. 
+ *   nSrcOrgStep - Stride of the original picture plane, expressed in terms 
+ *            of integer pixels; must be a multiple of iBlockWidth. 
+ *   nSrcRefStep - Stride of the reference picture plane, expressed in terms 
+ *            of integer pixels 
+ *   pRefRect - pointer to the valid reference rectangle inside the reference 
+ *            picture plane 
+ *   nCurrPointPos - position of the current block in the current plane 
+ *   iBlockWidth - Width of the current block, expressed in terms of integer 
+ *            pixels; must be equal to either 4, 8, or 16. 
+ *   iBlockHeight - Height of the current block, expressed in terms of 
+ *            integer pixels; must be equal to either 4, 8, or 16. 
+ *   nLamda - Lamda factor; used to compute motion cost 
+ *   pMVPred - Predicted MV; used to compute motion cost, expressed in terms 
+ *            of 1/4-pel units 
+ *   pMVCandidate - Candidate MV; used to initialize the motion search, 
+ *            expressed in terms of integer pixels 
+ *   pMESpec - pointer to the ME specification structure 
+ *
+ * Output Arguments:
+ *   
+ *   pDstBestMV - Best MV resulting from integer search, expressed in terms 
+ *            of 1/4-pel units 
+ *   pBestCost - Motion cost associated with the best MV; computed as 
+ *            SAD+Lamda*BitsUsedByMV 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    any of the following pointers are NULL:
+ *         pSrcOrgY, pSrcRefY, pRefRect, pMVPred, pMVCandidate, or pMESpec. 
+ *    -    Either iBlockWidth or iBlockHeight are values other than 4, 8, or 16. 
+ *    -    Any alignment restrictions are violated 
+ *
+ */
+OMXResult omxVCM4P10_BlockMatch_Integer (
+    const OMX_U8 *pSrcOrgY,
+    OMX_S32 nSrcOrgStep,
+    const OMX_U8 *pSrcRefY,
+    OMX_S32 nSrcRefStep,
+    const OMXRect *pRefRect,
+    const OMXVCM4P2Coordinate *pCurrPointPos,
+    OMX_U8 iBlockWidth,
+    OMX_U8 iBlockHeight,
+    OMX_U32 nLamda,
+    const OMXVCMotionVector *pMVPred,
+    const OMXVCMotionVector *pMVCandidate,
+    OMXVCMotionVector *pBestMV,
+    OMX_S32 *pBestCost,
+    void *pMESpec
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_BlockMatch_Half   (6.3.5.2.2)
+ *
+ * Description:
+ * Performs a half-pel block match using results from a prior integer search. 
+ *  Returns the best MV and associated cost.  This function estimates the 
+ * half-pixel motion vector by interpolating the integer resolution motion 
+ * vector referenced by the input parameter pSrcDstBestMV, i.e., the initial 
+ * integer MV is generated externally.  The function 
+ * omxVCM4P10_BlockMatch_Integer may be used for integer motion estimation. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcOrgY - Pointer to the current position in original picture plane:
+ *              If iBlockWidth==4,  4-byte alignment required. 
+ *              If iBlockWidth==8,  8-byte alignment required. 
+ *              If iBlockWidth==16, 16-byte alignment required. 
+ *   pSrcRefY - Pointer to the top-left corner of the co-located block in the 
+ *            reference picture:  
+ *              If iBlockWidth==4,  4-byte alignment required.  
+ *              If iBlockWidth==8,  8-byte alignment required.  
+ *              If iBlockWidth==16, 16-byte alignment required. 
+ *   nSrcOrgStep - Stride of the original picture plane in terms of full 
+ *            pixels; must be a multiple of iBlockWidth. 
+ *   nSrcRefStep - Stride of the reference picture plane in terms of full 
+ *            pixels 
+ *   iBlockWidth - Width of the current block in terms of full pixels; must 
+ *            be equal to either 4, 8, or 16. 
+ *   iBlockHeight - Height of the current block in terms of full pixels; must 
+ *            be equal to either 4, 8, or 16. 
+ *   nLamda - Lamda factor, used to compute motion cost 
+ *   pMVPred - Predicted MV, represented in terms of 1/4-pel units; used to 
+ *            compute motion cost 
+ *   pSrcDstBestMV - The best MV resulting from a prior integer search, 
+ *            represented in terms of 1/4-pel units 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDstBestMV - Best MV resulting from the half-pel search, expressed in 
+ *            terms of 1/4-pel units 
+ *   pBestCost - Motion cost associated with the best MV; computed as 
+ *            SAD+Lamda*BitsUsedByMV 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    any of the following pointers is NULL: pSrcOrgY, pSrcRefY, 
+ *              pSrcDstBestMV, pMVPred, pBestCost 
+ *    -    iBlockWidth or iBlockHeight are equal to values other than 4, 8, or 16. 
+ *    -    Any alignment restrictions are violated 
+ *
+ */
+OMXResult omxVCM4P10_BlockMatch_Half (
+    const OMX_U8 *pSrcOrgY,
+    OMX_S32 nSrcOrgStep,
+    const OMX_U8 *pSrcRefY,
+    OMX_S32 nSrcRefStep,
+    OMX_U8 iBlockWidth,
+    OMX_U8 iBlockHeight,
+    OMX_U32 nLamda,
+    const OMXVCMotionVector *pMVPred,
+    OMXVCMotionVector *pSrcDstBestMV,
+    OMX_S32 *pBestCost
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_BlockMatch_Quarter   (6.3.5.2.3)
+ *
+ * Description:
+ * Performs a quarter-pel block match using results from a prior half-pel 
+ * search.  Returns the best MV and associated cost.  This function estimates 
+ * the quarter-pixel motion vector by interpolating the half-pel resolution 
+ * motion vector referenced by the input parameter pSrcDstBestMV, i.e., the 
+ * initial half-pel MV is generated externally.  The function 
+ * omxVCM4P10_BlockMatch_Half may be used for half-pel motion estimation. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcOrgY - Pointer to the current position in original picture plane:
+ *            If iBlockWidth==4,  4-byte alignment required. 
+ *            If iBlockWidth==8,  8-byte alignment required. 
+ *            If iBlockWidth==16, 16-byte alignment required. 
+ *   pSrcRefY - Pointer to the top-left corner of the co-located block in the 
+ *            reference picture:
+ *            If iBlockWidth==4,  4-byte alignment required.  
+ *            If iBlockWidth==8,  8-byte alignment required.  
+ *            If iBlockWidth==16, 16-byte alignment required. 
+ *   nSrcOrgStep - Stride of the original picture plane in terms of full 
+ *            pixels; must be a multiple of iBlockWidth. 
+ *   nSrcRefStep - Stride of the reference picture plane in terms of full 
+ *            pixels 
+ *   iBlockWidth - Width of the current block in terms of full pixels; must 
+ *            be equal to either 4, 8, or 16. 
+ *   iBlockHeight - Height of the current block in terms of full pixels; must 
+ *            be equal to either 4, 8, or 16. 
+ *   nLamda - Lamda factor, used to compute motion cost 
+ *   pMVPred - Predicted MV, represented in terms of 1/4-pel units; used to 
+ *            compute motion cost 
+ *   pSrcDstBestMV - The best MV resulting from a prior half-pel search, 
+ *            represented in terms of 1/4 pel units 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDstBestMV - Best MV resulting from the quarter-pel search, expressed 
+ *            in terms of 1/4-pel units 
+ *   pBestCost - Motion cost associated with the best MV; computed as 
+ *            SAD+Lamda*BitsUsedByMV 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    One or more of the following pointers is NULL: 
+ *         pSrcOrgY, pSrcRefY, pSrcDstBestMV, pMVPred, pBestCost 
+ *    -    iBlockWidth or iBlockHeight are equal to values other than 4, 8, or 16. 
+ *    -    Any alignment restrictions are violated 
+ *
+ */
+OMXResult omxVCM4P10_BlockMatch_Quarter (
+    const OMX_U8 *pSrcOrgY,
+    OMX_S32 nSrcOrgStep,
+    const OMX_U8 *pSrcRefY,
+    OMX_S32 nSrcRefStep,
+    OMX_U8 iBlockWidth,
+    OMX_U8 iBlockHeight,
+    OMX_U32 nLamda,
+    const OMXVCMotionVector *pMVPred,
+    OMXVCMotionVector *pSrcDstBestMV,
+    OMX_S32 *pBestCost
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_MotionEstimationMB   (6.3.5.3.1)
+ *
+ * Description:
+ * Performs MB-level motion estimation and selects best motion estimation 
+ * strategy from the set of modes supported in baseline profile [ISO14496-10]. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcCurrBuf - Pointer to the current position in original picture plane; 
+ *            16-byte alignment required 
+ *   pSrcRefBufList - Pointer to an array with 16 entries.  Each entry points 
+ *            to the top-left corner of the co-located MB in a reference 
+ *            picture.  The array is filled from low-to-high with valid 
+ *            reference frame pointers; the unused high entries should be set 
+ *            to NULL.  Ordering of the reference frames should follow 
+ *            [ISO14496-10] subclause 8.2.4  Decoding Process for Reference 
+ *            Picture Lists.   The entries must be 16-byte aligned. 
+ *   pSrcRecBuf - Pointer to the top-left corner of the co-located MB in the 
+ *            reconstructed picture; must be 16-byte aligned. 
+ *   SrcCurrStep - Width of the original picture plane in terms of full 
+ *            pixels; must be a multiple of 16. 
+ *   SrcRefStep - Width of the reference picture plane in terms of full 
+ *            pixels; must be a multiple of 16. 
+ *   SrcRecStep - Width of the reconstructed picture plane in terms of full 
+ *            pixels; must be a multiple of 16. 
+ *   pRefRect - Pointer to the valid reference rectangle; relative to the 
+ *            image origin. 
+ *   pCurrPointPos - Position of the current macroblock in the current plane. 
+ *   Lambda - Lagrange factor for computing the cost function 
+ *   pMESpec - Pointer to the motion estimation specification structure; must 
+ *            have been allocated and initialized prior to calling this 
+ *            function. 
+ *   pMBInter - Array, of dimension four, containing pointers to information 
+ *            associated with four adjacent type INTER MBs (Left, Top, 
+ *            Top-Left, Top-Right). Any pointer in the array may be set equal 
+ *            to NULL if the corresponding MB doesn t exist or is not of type 
+ *            INTER. 
+ *            -  pMBInter[0] - Pointer to left MB information 
+ *            -  pMBInter[1] - Pointer to top MB information 
+ *            -  pMBInter[2] - Pointer to top-left MB information 
+ *            -  pMBInter[3] - Pointer to top-right MB information 
+ *   pMBIntra - Array, of dimension four, containing pointers to information 
+ *            associated with four adjacent type INTRA MBs (Left, Top, 
+ *            Top-Left, Top-Right). Any pointer in the array may be set equal 
+ *            to NULL if the corresponding MB doesn t exist or is not of type 
+ *            INTRA. 
+ *            -  pMBIntra[0] - Pointer to left MB information 
+ *            -  pMBIntra[1] - Pointer to top MB information 
+ *            -  pMBIntra[2] - Pointer to top-left MB information 
+ *            -  pMBIntra[3] - Pointer to top-right MB information 
+ *   pSrcDstMBCurr - Pointer to information structure for the current MB.  
+ *            The following entries should be set prior to calling the 
+ *            function:  sliceID - the number of the slice the to which the 
+ *            current MB belongs. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstCost - Pointer to the minimum motion cost for the current MB. 
+ *   pDstBlockSAD - Pointer to the array of SADs for each of the sixteen luma 
+ *            4x4 blocks in each MB.  The block SADs are in scan order for 
+ *            each MB.  For implementations that cannot compute the SAD values 
+ *            individually, the maximum possible value (0xffff) is returned 
+ *            for each of the 16 block SAD entries. 
+ *   pSrcDstMBCurr - Pointer to updated information structure for the current 
+ *            MB after MB-level motion estimation has been completed.  The 
+ *            following fields are updated by the ME function.   The following 
+ *            parameter set quantifies the MB-level ME search results: 
+ *            -  MbType 
+ *            -  subMBType[4] 
+ *            -  pMV0[4][4] 
+ *            -  pMVPred[4][4] 
+ *            -  pRefL0Idx[4] 
+ *            -  Intra16x16PredMode 
+ *            -  pIntra4x4PredMode[4][4] 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -   One or more of the following pointers is NULL: pSrcCurrBuf, 
+ *           pSrcRefBufList, pSrcRecBuf, pRefRect, pCurrPointPos, pMESpec, 
+ *           pMBInter, pMBIntra,pSrcDstMBCurr, pDstCost, pSrcRefBufList[0] 
+ *    -    SrcRefStep, SrcRecStep are not multiples of 16 
+ *    -    iBlockWidth or iBlockHeight are values other than 4, 8, or 16. 
+ *    -    Any alignment restrictions are violated 
+ *
+ */
+OMXResult omxVCM4P10_MotionEstimationMB (
+    const OMX_U8 *pSrcCurrBuf,
+    OMX_S32 SrcCurrStep,
+    const OMX_U8 *pSrcRefBufList[15],
+    OMX_S32 SrcRefStep,
+    const OMX_U8 *pSrcRecBuf,
+    OMX_S32 SrcRecStep,
+    const OMXRect *pRefRect,
+    const OMXVCM4P2Coordinate *pCurrPointPos,
+    OMX_U32 Lambda,
+    void *pMESpec,
+    const OMXVCM4P10MBInfoPtr *pMBInter,
+    const OMXVCM4P10MBInfoPtr *pMBIntra,
+    OMXVCM4P10MBInfoPtr pSrcDstMBCurr,
+    OMX_INT *pDstCost,
+    OMX_U16 *pDstBlockSAD
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_SAD_4x   (6.3.5.4.1)
+ *
+ * Description:
+ * This function calculates the SAD for 4x8 and 4x4 blocks. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcOrg -Pointer to the original block; must be aligned on a 4-byte 
+ *            boundary. 
+ *   iStepOrg -Step of the original block buffer; must be a multiple of 4. 
+ *   pSrcRef -Pointer to the reference block 
+ *   iStepRef -Step of the reference block buffer 
+ *   iHeight -Height of the block; must be equal to either 4 or 8. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstSAD -Pointer of result SAD 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    One or more of the following pointers is NULL: 
+ *         pSrcOrg, pSrcRef, or pDstSAD 
+ *    -    iHeight is not equal to either 4 or 8. 
+ *    -    iStepOrg is not a multiple of 4 
+ *    -    Any alignment restrictions are violated 
+ *
+ */
+OMXResult omxVCM4P10_SAD_4x (
+    const OMX_U8 *pSrcOrg,
+    OMX_U32 iStepOrg,
+    const OMX_U8 *pSrcRef,
+    OMX_U32 iStepRef,
+    OMX_S32 *pDstSAD,
+    OMX_U32 iHeight
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_SADQuar_4x   (6.3.5.4.2)
+ *
+ * Description:
+ * This function calculates the SAD between one block (pSrc) and the average 
+ * of the other two (pSrcRef0 and pSrcRef1) for 4x8 or 4x4 blocks.  Rounding 
+ * is applied according to the convention (a+b+1)>>1. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - Pointer to the original block; must be aligned on a 4-byte 
+ *            boundary. 
+ *   pSrcRef0 - Pointer to reference block 0 
+ *   pSrcRef1 - Pointer to reference block 1 
+ *   iSrcStep - Step of the original block buffer; must be a multiple of 4. 
+ *   iRefStep0 - Step of reference block 0 
+ *   iRefStep1 - Step of reference block 1 
+ *   iHeight - Height of the block; must be equal to either 4 or 8. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstSAD - Pointer of result SAD 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    iHeight is not equal to either 4 or 8. 
+ *    -    One or more of the following pointers is NULL: pSrc, pSrcRef0, 
+ *              pSrcRef1, pDstSAD. 
+ *    -    iSrcStep is not a multiple of 4 
+ *    -    Any alignment restrictions are violated 
+ *
+ */
+OMXResult omxVCM4P10_SADQuar_4x (
+    const OMX_U8 *pSrc,
+    const OMX_U8 *pSrcRef0,
+    const OMX_U8 *pSrcRef1,
+    OMX_U32 iSrcStep,
+    OMX_U32 iRefStep0,
+    OMX_U32 iRefStep1,
+    OMX_U32 *pDstSAD,
+    OMX_U32 iHeight
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_SADQuar_8x   (6.3.5.4.3)
+ *
+ * Description:
+ * This function calculates the SAD between one block (pSrc) and the average 
+ * of the other two (pSrcRef0 and pSrcRef1) for 8x16, 8x8, or 8x4 blocks.  
+ * Rounding is applied according to the convention (a+b+1)>>1. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - Pointer to the original block; must be aligned on an 8-byte 
+ *            boundary. 
+ *   pSrcRef0 - Pointer to reference block 0 
+ *   pSrcRef1 - Pointer to reference block 1 
+ *   iSrcStep - Step of the original block buffer; must be a multiple of 8. 
+ *   iRefStep0 - Step of reference block 0 
+ *   iRefStep1 - Step of reference block 1 
+ *   iHeight - Height of the block; must be equal either 4, 8, or 16. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstSAD - Pointer of result SAD 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    iHeight is not equal to either 4, 8, or 16. 
+ *    -    One or more of the following pointers is NULL: pSrc, pSrcRef0, 
+ *              pSrcRef1, pDstSAD. 
+ *    -    iSrcStep is not a multiple of 8 
+ *    -    Any alignment restrictions are violated 
+ *
+ */
+OMXResult omxVCM4P10_SADQuar_8x (
+    const OMX_U8 *pSrc,
+    const OMX_U8 *pSrcRef0,
+    const OMX_U8 *pSrcRef1,
+    OMX_U32 iSrcStep,
+    OMX_U32 iRefStep0,
+    OMX_U32 iRefStep1,
+    OMX_U32 *pDstSAD,
+    OMX_U32 iHeight
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_SADQuar_16x   (6.3.5.4.4)
+ *
+ * Description:
+ * This function calculates the SAD between one block (pSrc) and the average 
+ * of the other two (pSrcRef0 and pSrcRef1) for 16x16 or 16x8 blocks.  
+ * Rounding is applied according to the convention (a+b+1)>>1. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - Pointer to the original block; must be aligned on a 16-byte 
+ *            boundary. 
+ *   pSrcRef0 - Pointer to reference block 0 
+ *   pSrcRef1 - Pointer to reference block 1 
+ *   iSrcStep - Step of the original block buffer; must be a multiple of 16 
+ *   iRefStep0 - Step of reference block 0 
+ *   iRefStep1 - Step of reference block 1 
+ *   iHeight - Height of the block; must be equal to either 8 or 16 
+ *
+ * Output Arguments:
+ *   
+ *   pDstSAD -Pointer of result SAD 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    iHeight is not equal to either 8 or 16. 
+ *    -    One or more of the following pointers is NULL: pSrc, pSrcRef0, 
+ *              pSrcRef1, pDstSAD. 
+ *    -    iSrcStep is not a multiple of 16 
+ *    -    Any alignment restrictions are violated 
+ *
+ */
+OMXResult omxVCM4P10_SADQuar_16x (
+    const OMX_U8 *pSrc,
+    const OMX_U8 *pSrcRef0,
+    const OMX_U8 *pSrcRef1,
+    OMX_U32 iSrcStep,
+    OMX_U32 iRefStep0,
+    OMX_U32 iRefStep1,
+    OMX_U32 *pDstSAD,
+    OMX_U32 iHeight
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_SATD_4x4   (6.3.5.4.5)
+ *
+ * Description:
+ * This function calculates the sum of absolute transform differences (SATD) 
+ * for a 4x4 block by applying a Hadamard transform to the difference block 
+ * and then calculating the sum of absolute coefficient values. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcOrg - Pointer to the original block; must be aligned on a 4-byte 
+ *            boundary 
+ *   iStepOrg - Step of the original block buffer; must be a multiple of 4 
+ *   pSrcRef - Pointer to the reference block; must be aligned on a 4-byte 
+ *            boundary 
+ *   iStepRef - Step of the reference block buffer; must be a multiple of 4 
+ *
+ * Output Arguments:
+ *   
+ *   pDstSAD - pointer to the resulting SAD 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: 
+ *         pSrcOrg, pSrcRef, or pDstSAD either pSrcOrg 
+ *    -    pSrcRef is not aligned on a 4-byte boundary 
+ *    -    iStepOrg <= 0 or iStepOrg is not a multiple of 4 
+ *    -    iStepRef <= 0 or iStepRef is not a multiple of 4 
+ *
+ */
+OMXResult omxVCM4P10_SATD_4x4 (
+    const OMX_U8 *pSrcOrg,
+    OMX_U32 iStepOrg,
+    const OMX_U8 *pSrcRef,
+    OMX_U32 iStepRef,
+    OMX_U32 *pDstSAD
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_InterpolateHalfHor_Luma   (6.3.5.5.1)
+ *
+ * Description:
+ * This function performs interpolation for two horizontal 1/2-pel positions 
+ * (-1/2,0) and (1/2, 0) - around a full-pel position. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - Pointer to the top-left corner of the block used to interpolate in 
+ *            the reconstruction frame plane. 
+ *   iSrcStep - Step of the source buffer. 
+ *   iDstStep - Step of the destination(interpolation) buffer; must be a 
+ *            multiple of iWidth. 
+ *   iWidth - Width of the current block; must be equal to either 4, 8, or 16 
+ *   iHeight - Height of the current block; must be equal to 4, 8, or 16 
+ *
+ * Output Arguments:
+ *   
+ *   pDstLeft -Pointer to the interpolation buffer of the left -pel position 
+ *            (-1/2, 0) 
+ *                 If iWidth==4,  4-byte alignment required. 
+ *                 If iWidth==8,  8-byte alignment required. 
+ *                 If iWidth==16, 16-byte alignment required. 
+ *   pDstRight -Pointer to the interpolation buffer of the right -pel 
+ *            position (1/2, 0) 
+ *                 If iWidth==4,  4-byte alignment required. 
+ *                 If iWidth==8,  8-byte alignment required. 
+ *                 If iWidth==16, 16-byte alignment required. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: 
+ *             pSrc, pDstLeft, or pDstRight 
+ *    -    iWidth or iHeight have values other than 4, 8, or 16 
+ *    -    iWidth==4 but pDstLeft and/or pDstRight is/are not aligned on a 4-byte boundary 
+ *    -    iWidth==8 but pDstLeft and/or pDstRight is/are not aligned on a 8-byte boundary 
+ *    -    iWidth==16 but pDstLeft and/or pDstRight is/are not aligned on a 16-byte boundary 
+ *    -    any alignment restrictions are violated 
+ *
+ */
+OMXResult omxVCM4P10_InterpolateHalfHor_Luma (
+    const OMX_U8 *pSrc,
+    OMX_U32 iSrcStep,
+    OMX_U8 *pDstLeft,
+    OMX_U8 *pDstRight,
+    OMX_U32 iDstStep,
+    OMX_U32 iWidth,
+    OMX_U32 iHeight
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_InterpolateHalfVer_Luma   (6.3.5.5.2)
+ *
+ * Description:
+ * This function performs interpolation for two vertical 1/2-pel positions - 
+ * (0, -1/2) and (0, 1/2) - around a full-pel position. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - Pointer to top-left corner of block used to interpolate in the 
+ *            reconstructed frame plane 
+ *   iSrcStep - Step of the source buffer. 
+ *   iDstStep - Step of the destination (interpolation) buffer; must be a 
+ *            multiple of iWidth. 
+ *   iWidth - Width of the current block; must be equal to either 4, 8, or 16 
+ *   iHeight - Height of the current block; must be equal to either 4, 8, or 16 
+ *
+ * Output Arguments:
+ *   
+ *   pDstUp -Pointer to the interpolation buffer of the -pel position above 
+ *            the current full-pel position (0, -1/2) 
+ *                If iWidth==4, 4-byte alignment required. 
+ *                If iWidth==8, 8-byte alignment required. 
+ *                If iWidth==16, 16-byte alignment required. 
+ *   pDstDown -Pointer to the interpolation buffer of the -pel position below 
+ *            the current full-pel position (0, 1/2) 
+ *                If iWidth==4, 4-byte alignment required. 
+ *                If iWidth==8, 8-byte alignment required. 
+ *                If iWidth==16, 16-byte alignment required. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: 
+ *            pSrc, pDstUp, or pDstDown 
+ *    -    iWidth or iHeight have values other than 4, 8, or 16 
+ *    -    iWidth==4 but pDstUp and/or pDstDown is/are not aligned on a 4-byte boundary 
+ *    -    iWidth==8 but pDstUp and/or pDstDown is/are not aligned on a 8-byte boundary 
+ *    -    iWidth==16 but pDstUp and/or pDstDown is/are not aligned on a 16-byte boundary 
+ *
+ */
+OMXResult omxVCM4P10_InterpolateHalfVer_Luma (
+    const OMX_U8 *pSrc,
+    OMX_U32 iSrcStep,
+    OMX_U8 *pDstUp,
+    OMX_U8 *pDstDown,
+    OMX_U32 iDstStep,
+    OMX_U32 iWidth,
+    OMX_U32 iHeight
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_Average_4x   (6.3.5.5.3)
+ *
+ * Description:
+ * This function calculates the average of two 4x4, 4x8 blocks.  The result 
+ * is rounded according to (a+b+1)/2. 
+ *
+ * Input Arguments:
+ *   
+ *   pPred0 - Pointer to the top-left corner of reference block 0 
+ *   pPred1 - Pointer to the top-left corner of reference block 1 
+ *   iPredStep0 - Step of reference block 0; must be a multiple of 4. 
+ *   iPredStep1 - Step of reference block 1; must be a multiple of 4. 
+ *   iDstStep - Step of the destination buffer; must be a multiple of 4. 
+ *   iHeight - Height of the blocks; must be either 4 or 8. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstPred - Pointer to the destination buffer. 4-byte alignment required. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: 
+ *           pPred0, pPred1, or pDstPred 
+ *    -    pDstPred is not aligned on a 4-byte boundary 
+ *    -    iPredStep0 <= 0 or iPredStep0 is not a multiple of 4 
+ *    -    iPredStep1 <= 0 or iPredStep1 is not a multiple of 4 
+ *    -    iDstStep <= 0 or iDstStep is not a multiple of 4 
+ *    -    iHeight is not equal to either 4 or 8 
+ *
+ */
+OMXResult omxVCM4P10_Average_4x (
+    const OMX_U8 *pPred0,
+    const OMX_U8 *pPred1,
+    OMX_U32 iPredStep0,
+    OMX_U32 iPredStep1,
+    OMX_U8 *pDstPred,
+    OMX_U32 iDstStep,
+    OMX_U32 iHeight
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_TransformQuant_ChromaDC   (6.3.5.6.1)
+ *
+ * Description:
+ * This function performs 2x2 Hadamard transform of chroma DC coefficients 
+ * and then quantizes the coefficients. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - Pointer to the 2x2 array of chroma DC coefficients.  8-byte 
+ *            alignment required. 
+ *   iQP - Quantization parameter; must be in the range [0,51]. 
+ *   bIntra - Indicate whether this is an INTRA block. 1-INTRA, 0-INTER 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst - Pointer to transformed and quantized coefficients.  8-byte 
+ *            alignment required. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: 
+ *             pSrcDst 
+ *    -    pSrcDst is not aligned on an 8-byte boundary 
+ *
+ */
+OMXResult omxVCM4P10_TransformQuant_ChromaDC (
+    OMX_S16 *pSrcDst,
+    OMX_U32 iQP,
+    OMX_U8 bIntra
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_TransformQuant_LumaDC   (6.3.5.6.2)
+ *
+ * Description:
+ * This function performs a 4x4 Hadamard transform of luma DC coefficients 
+ * and then quantizes the coefficients. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - Pointer to the 4x4 array of luma DC coefficients.  16-byte 
+ *            alignment required. 
+ *   iQP - Quantization parameter; must be in the range [0,51]. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst - Pointer to transformed and quantized coefficients.  16-byte 
+ *             alignment required. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: pSrcDst 
+ *    -    pSrcDst is not aligned on an 16-byte boundary 
+ *
+ */
+OMXResult omxVCM4P10_TransformQuant_LumaDC (
+    OMX_S16 *pSrcDst,
+    OMX_U32 iQP
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_InvTransformDequant_LumaDC   (6.3.5.6.3)
+ *
+ * Description:
+ * This function performs inverse 4x4 Hadamard transform and then dequantizes 
+ * the coefficients. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - Pointer to the 4x4 array of the 4x4 Hadamard-transformed and 
+ *            quantized coefficients.  16 byte alignment required. 
+ *   iQP - Quantization parameter; must be in the range [0,51]. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - Pointer to inverse-transformed and dequantized coefficients.  
+ *            16-byte alignment required. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: pSrc 
+ *    -    pSrc or pDst is not aligned on a 16-byte boundary 
+ *
+ */
+OMXResult omxVCM4P10_InvTransformDequant_LumaDC (
+    const OMX_S16 *pSrc,
+    OMX_S16 *pDst,
+    OMX_U32 iQP
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_InvTransformDequant_ChromaDC   (6.3.5.6.4)
+ *
+ * Description:
+ * This function performs inverse 2x2 Hadamard transform and then dequantizes 
+ * the coefficients. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - Pointer to the 2x2 array of the 2x2 Hadamard-transformed and 
+ *            quantized coefficients.  8 byte alignment required. 
+ *   iQP - Quantization parameter; must be in the range [0,51]. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - Pointer to inverse-transformed and dequantized coefficients.  
+ *            8-byte alignment required. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: pSrc 
+ *    -    pSrc or pDst is not aligned on an 8-byte boundary 
+ *
+ */
+OMXResult omxVCM4P10_InvTransformDequant_ChromaDC (
+    const OMX_S16 *pSrc,
+    OMX_S16 *pDst,
+    OMX_U32 iQP
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_InvTransformResidualAndAdd   (6.3.5.7.1)
+ *
+ * Description:
+ * This function performs inverse an 4x4 integer transformation to produce 
+ * the difference signal and then adds the difference to the prediction to get 
+ * the reconstructed signal. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcPred - Pointer to prediction signal.  4-byte alignment required. 
+ *   pDequantCoeff - Pointer to the transformed coefficients.  8-byte 
+ *            alignment required. 
+ *   iSrcPredStep - Step of the prediction buffer; must be a multiple of 4. 
+ *   iDstReconStep - Step of the destination reconstruction buffer; must be a 
+ *            multiple of 4. 
+ *   bAC - Indicate whether there is AC coefficients in the coefficients 
+ *            matrix. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstRecon -Pointer to the destination reconstruction buffer.  4-byte 
+ *            alignment required. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: 
+ *            pSrcPred, pDequantCoeff, pDstRecon 
+ *    -    pSrcPred is not aligned on a 4-byte boundary 
+ *    -    iSrcPredStep or iDstReconStep is not a multiple of 4. 
+ *    -    pDequantCoeff is not aligned on an 8-byte boundary 
+ *
+ */
+OMXResult omxVCM4P10_InvTransformResidualAndAdd (
+    const OMX_U8 *pSrcPred,
+    const OMX_S16 *pDequantCoeff,
+    OMX_U8 *pDstRecon,
+    OMX_U32 iSrcPredStep,
+    OMX_U32 iDstReconStep,
+    OMX_U8 bAC
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_SubAndTransformQDQResidual   (6.3.5.8.1)
+ *
+ * Description:
+ * This function subtracts the prediction signal from the original signal to 
+ * produce the difference signal and then performs a 4x4 integer transform and 
+ * quantization. The quantized transformed coefficients are stored as 
+ * pDstQuantCoeff. This function can also output dequantized coefficients or 
+ * unquantized DC coefficients optionally by setting the pointers 
+ * pDstDeQuantCoeff, pDCCoeff. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcOrg - Pointer to original signal. 4-byte alignment required. 
+ *   pSrcPred - Pointer to prediction signal. 4-byte alignment required. 
+ *   iSrcOrgStep - Step of the original signal buffer; must be a multiple of 
+ *            4. 
+ *   iSrcPredStep - Step of the prediction signal buffer; must be a multiple 
+ *            of 4. 
+ *   pNumCoeff -Number of non-zero coefficients after quantization. If this 
+ *            parameter is not required, it is set to NULL. 
+ *   nThreshSAD - Zero-block early detection threshold. If this parameter is 
+ *            not required, it is set to 0. 
+ *   iQP - Quantization parameter; must be in the range [0,51]. 
+ *   bIntra - Indicates whether this is an INTRA block, either 1-INTRA or 
+ *            0-INTER 
+ *
+ * Output Arguments:
+ *   
+ *   pDstQuantCoeff - Pointer to the quantized transformed coefficients.  
+ *            8-byte alignment required. 
+ *   pDstDeQuantCoeff - Pointer to the dequantized transformed coefficients 
+ *            if this parameter is not equal to NULL.  8-byte alignment 
+ *            required. 
+ *   pDCCoeff - Pointer to the unquantized DC coefficient if this parameter 
+ *            is not equal to NULL. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: 
+ *            pSrcOrg, pSrcPred, pNumCoeff, pDstQuantCoeff, 
+ *            pDstDeQuantCoeff, pDCCoeff 
+ *    -    pSrcOrg is not aligned on a 4-byte boundary 
+ *    -    pSrcPred is not aligned on a 4-byte boundary 
+ *    -    iSrcOrgStep is not a multiple of 4 
+ *    -    iSrcPredStep is not a multiple of 4 
+ *    -    pDstQuantCoeff or pDstDeQuantCoeff is not aligned on an 8-byte boundary 
+ *
+ */
+OMXResult omxVCM4P10_SubAndTransformQDQResidual (
+    const OMX_U8 *pSrcOrg,
+    const OMX_U8 *pSrcPred,
+    OMX_U32 iSrcOrgStep,
+    OMX_U32 iSrcPredStep,
+    OMX_S16 *pDstQuantCoeff,
+    OMX_S16 *pDstDeQuantCoeff,
+    OMX_S16 *pDCCoeff,
+    OMX_S8 *pNumCoeff,
+    OMX_U32 nThreshSAD,
+    OMX_U32 iQP,
+    OMX_U8 bIntra
+);
+
+
+
+/**
+ * Function:  omxVCM4P10_GetVLCInfo   (6.3.5.9.1)
+ *
+ * Description:
+ * This function extracts run-length encoding (RLE) information from the 
+ * coefficient matrix.  The results are returned in an OMXVCM4P10VLCInfo 
+ * structure. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcCoeff - pointer to the transform coefficient matrix.  8-byte 
+ *            alignment required. 
+ *   pScanMatrix - pointer to the scan order definition matrix.  For a luma 
+ *            block the scan matrix should follow [ISO14496-10] section 8.5.4, 
+ *            and should contain the values 0, 1, 4, 8, 5, 2, 3, 6, 9, 12, 13, 
+ *            10, 7, 11, 14, 15.  For a chroma block, the scan matrix should 
+ *            contain the values 0, 1, 2, 3. 
+ *   bAC - indicates presence of a DC coefficient; 0 = DC coefficient 
+ *            present, 1= DC coefficient absent. 
+ *   MaxNumCoef - specifies the number of coefficients contained in the 
+ *            transform coefficient matrix, pSrcCoeff. The value should be 16 
+ *            for blocks of type LUMADC, LUMAAC, LUMALEVEL, and CHROMAAC. The 
+ *            value should be 4 for blocks of type CHROMADC. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstVLCInfo - pointer to structure that stores information for 
+ *            run-length coding. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: 
+ *            pSrcCoeff, pScanMatrix, pDstVLCInfo 
+ *    -    pSrcCoeff is not aligned on an 8-byte boundary 
+ *
+ */
+OMXResult omxVCM4P10_GetVLCInfo (
+    const OMX_S16 *pSrcCoeff,
+    const OMX_U8 *pScanMatrix,
+    OMX_U8 bAC,
+    OMX_U32 MaxNumCoef,
+    OMXVCM4P10VLCInfo*pDstVLCInfo
+);
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /** end of #define _OMXVC_H_ */
+
+/** EOF */
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/comm/src/armVCCOMM_Average.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/comm/src/armVCCOMM_Average.c
new file mode 100644
index 0000000..1e51077
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/comm/src/armVCCOMM_Average.c
@@ -0,0 +1,78 @@
+/**
+ * 
+ * File Name:  armVCCOMM_Average.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * Description:
+ * This function will calculate Average of two blocks if size iWidth X iHeight
+ * 
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+
+/**
+ * Function: armVCCOMM_Average
+ *
+ * Description:
+ * This function calculates the average of two blocks and stores the result.
+ *
+ * Remarks:
+ *
+ *	[in]	pPred0			Pointer to the top-left corner of reference block 0
+ *	[in]	pPred1			Pointer to the top-left corner of reference block 1
+ *	[in]	iPredStep0	    Step of reference block 0
+ *	[in]	iPredStep1	    Step of reference block 1
+ *	[in]	iDstStep 		Step of the destination buffer
+ *	[in]	iWidth			Width of the blocks
+ *	[in]	iHeight			Height of the blocks
+ *	[out]	pDstPred		Pointer to the destination buffer
+ *
+ * Return Value:
+ * Standard OMXResult value.
+ *
+ */
+ OMXResult armVCCOMM_Average (
+	 const OMX_U8* 	    pPred0,
+	 const OMX_U8* 	    pPred1,	
+	 OMX_U32		iPredStep0,
+	 OMX_U32		iPredStep1,
+	 OMX_U8*		pDstPred,
+	 OMX_U32		iDstStep, 
+	 OMX_U32		iWidth,
+	 OMX_U32		iHeight
+)
+{
+    OMX_U32     x, y;
+
+    /* check for argument error */
+    armRetArgErrIf(pPred0 == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pPred1 == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pDstPred == NULL, OMX_Sts_BadArgErr)
+
+    for (y = 0; y < iHeight; y++)
+    {
+        for (x = 0; x < iWidth; x++)
+        {
+            pDstPred [y * iDstStep + x] = 
+                (OMX_U8)(((OMX_U32)pPred0 [y * iPredStep0 + x] + 
+                                  pPred1 [y * iPredStep1 + x] + 1) >> 1);
+        }
+    }
+
+    return OMX_Sts_NoErr;
+}
+
+/*****************************************************************************
+ *                              END OF FILE
+ *****************************************************************************/
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/comm/src/armVCCOMM_SAD.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/comm/src/armVCCOMM_SAD.c
new file mode 100644
index 0000000..d41ac9a
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/comm/src/armVCCOMM_SAD.c
@@ -0,0 +1,75 @@
+/**
+ * 
+ * File Name:  armVCCOMM_SAD.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * Description:
+ * This function will calculate SAD for NxM blocks
+ * 
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+
+/**
+ * Function: armVCCOMM_SAD
+ *
+ * Description:
+ * This function calculate the SAD for NxM blocks.
+ *
+ * Remarks:
+ *
+ * [in]		pSrcOrg		Pointer to the original block
+ * [in]		iStepOrg	Step of the original block buffer
+ * [in]		pSrcRef		Pointer to the reference block
+ * [in]		iStepRef	Step of the reference block buffer
+ * [in]		iHeight		Height of the block
+ * [in]		iWidth		Width of the block
+ * [out]	pDstSAD		Pointer of result SAD
+ *
+ * Return Value:
+ * Standard OMXResult value.
+ *
+ */
+OMXResult armVCCOMM_SAD(	
+	const OMX_U8* 	pSrcOrg,
+	OMX_U32 	iStepOrg,
+	const OMX_U8* 	pSrcRef,
+	OMX_U32 	iStepRef,
+	OMX_S32*	pDstSAD,
+	OMX_U32		iHeight,
+	OMX_U32		iWidth
+)
+{
+    OMX_INT     x, y;
+    
+    /* check for argument error */
+    armRetArgErrIf(pSrcOrg == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pSrcRef == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pDstSAD == NULL, OMX_Sts_BadArgErr)
+    
+    *pDstSAD = 0;
+    for (y = 0; y < iHeight; y++)
+    {
+        for (x = 0; x < iWidth; x++)
+        {
+            *pDstSAD += armAbs(pSrcOrg [(y * iStepOrg) + x] - 
+                       pSrcRef [(y * iStepRef) + x]);
+        }
+    }
+    
+    return OMX_Sts_NoErr;
+}
+
+/*****************************************************************************
+ *                              END OF FILE
+ *****************************************************************************/
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/comm/src/omxVCCOMM_Average_16x.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/comm/src/omxVCCOMM_Average_16x.c
new file mode 100644
index 0000000..6d1447e
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/comm/src/omxVCCOMM_Average_16x.c
@@ -0,0 +1,86 @@
+/**
+ * 
+ * File Name:  omxVCCOMM_Average_16x.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * Description:
+ * This function will calculate Average of two 16x16 or 16x8 blocks
+ * 
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+
+/**
+ * Function:  omxVCCOMM_Average_16x   (6.1.3.1.2)
+ *
+ * Description:
+ * This function calculates the average of two 16x16 or 16x8 blocks.  The 
+ * result is rounded according to (a+b+1)/2.  The block average function can 
+ * be used in conjunction with half-pixel interpolation to obtain quarter 
+ * pixel motion estimates, as described in [ISO14496-10], subclause 8.4.2.2.1. 
+ *
+ * Input Arguments:
+ *   
+ *   pPred0 - Pointer to the top-left corner of reference block 0 
+ *   pPred1 - Pointer to the top-left corner of reference block 1 
+ *   iPredStep0 - Step of reference block 0 
+ *   iPredStep1 - Step of reference block 1 
+ *   iDstStep - Step of the destination buffer 
+ *   iHeight - Height of the blocks 
+ *
+ * Output Arguments:
+ *   
+ *   pDstPred - Pointer to the destination buffer. 16-byte aligned. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned under any of the following 
+ *              conditions: 
+ *    -   one or more of the following pointers is NULL: pPred0, pPred1, or 
+ *              pDstPred. 
+ *    -   pDstPred is not aligned on a 16-byte boundary. 
+ *    -   iPredStep0 <= 0 or iPredStep0 is not a multiple of 16. 
+ *    -   iPredStep1 <= 0 or iPredStep1 is not a multiple of 16. 
+ *    -   iDstStep <= 0 or iDstStep is not a multiple of 16. 
+ *    -   iHeight is not 8 or 16. 
+ *
+ */
+ OMXResult omxVCCOMM_Average_16x (
+	 const OMX_U8* 	    pPred0,
+	 const OMX_U8* 	    pPred1,	
+	 OMX_U32		iPredStep0,
+	 OMX_U32		iPredStep1,
+	 OMX_U8*		pDstPred,
+	 OMX_U32		iDstStep, 
+	 OMX_U32		iHeight
+)
+{
+    /* check for argument error */
+    armRetArgErrIf(pPred0 == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pPred1 == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pDstPred == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf((iHeight != 8) && (iHeight != 16), OMX_Sts_BadArgErr)
+    armRetArgErrIf(armNot16ByteAligned(pDstPred), OMX_Sts_BadArgErr)
+    armRetArgErrIf((iPredStep0 == 0) || (iPredStep0 & 15), OMX_Sts_BadArgErr)
+    armRetArgErrIf((iPredStep1 == 0) || (iPredStep1 & 15), OMX_Sts_BadArgErr)
+    armRetArgErrIf((iDstStep == 0) || (iDstStep & 15), OMX_Sts_BadArgErr)
+
+    return armVCCOMM_Average 
+        (pPred0, pPred1, iPredStep0, iPredStep1, pDstPred, iDstStep, 16, iHeight);
+}
+
+/*****************************************************************************
+ *                              END OF FILE
+ *****************************************************************************/
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/comm/src/omxVCCOMM_Average_8x.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/comm/src/omxVCCOMM_Average_8x.c
new file mode 100644
index 0000000..17b1326
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/comm/src/omxVCCOMM_Average_8x.c
@@ -0,0 +1,87 @@
+/**
+ * 
+ * File Name:  omxVCCOMM_Average_8x.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * Description:
+ * This function will calculate Average of two 8x4 or 8x8 or 8x16 blocks
+ * 
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+
+/**
+ * Function:  omxVCCOMM_Average_8x   (6.1.3.1.1)
+ *
+ * Description:
+ * This function calculates the average of two 8x4, 8x8, or 8x16 blocks.  The 
+ * result is rounded according to (a+b+1)/2.  The block average function can 
+ * be used in conjunction with half-pixel interpolation to obtain quarter 
+ * pixel motion estimates, as described in [ISO14496-10], subclause 8.4.2.2.1. 
+ *
+ * Input Arguments:
+ *   
+ *   pPred0     - Pointer to the top-left corner of reference block 0 
+ *   pPred1     - Pointer to the top-left corner of reference block 1 
+ *   iPredStep0 - Step of reference block 0 
+ *   iPredStep1 - Step of reference block 1 
+ *   iDstStep   - Step of the destination buffer. 
+ *   iHeight    - Height of the blocks 
+ *
+ * Output Arguments:
+ *   
+ *   pDstPred - Pointer to the destination buffer. 8-byte aligned. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned under any of the following 
+ *              conditions: 
+ *    -   one or more of the following pointers is NULL: pPred0, pPred1, or 
+ *              pDstPred. 
+ *    -   pDstPred is not aligned on an 8-byte boundary. 
+ *    -   iPredStep0 <= 0 or iPredStep0 is not a multiple of 8. 
+ *    -   iPredStep1 <= 0 or iPredStep1 is not a multiple of 8. 
+ *    -   iDstStep   <= 0 or iDstStep is not a multiple of 8. 
+ *    -   iHeight is not 4, 8, or 16. 
+ *
+ */
+ OMXResult omxVCCOMM_Average_8x (	
+	 const OMX_U8* 	    pPred0,
+	 const OMX_U8* 	    pPred1,	
+     OMX_U32		iPredStep0,
+     OMX_U32		iPredStep1,
+	 OMX_U8*		pDstPred,
+     OMX_U32		iDstStep, 
+	 OMX_U32		iHeight
+)
+{
+    /* check for argument error */
+    armRetArgErrIf(pPred0 == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pPred1 == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pDstPred == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf((iPredStep0 == 0) || (iPredStep0 & 7), OMX_Sts_BadArgErr)
+    armRetArgErrIf((iPredStep1 == 0) || (iPredStep1 & 7), OMX_Sts_BadArgErr)
+    armRetArgErrIf((iDstStep == 0) || (iDstStep & 7), OMX_Sts_BadArgErr)
+    armRetArgErrIf((iHeight != 4) && (iHeight != 8) && (iHeight != 16), OMX_Sts_BadArgErr)
+    armRetArgErrIf(armNot8ByteAligned(pDstPred), OMX_Sts_BadArgErr)
+
+    return armVCCOMM_Average 
+        (pPred0, pPred1, iPredStep0, iPredStep1, pDstPred, iDstStep, 8, iHeight);
+}
+
+
+/*****************************************************************************
+ *                              END OF FILE
+ *****************************************************************************/
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/comm/src/omxVCCOMM_ComputeTextureErrorBlock.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/comm/src/omxVCCOMM_ComputeTextureErrorBlock.c
new file mode 100644
index 0000000..e559adf
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/comm/src/omxVCCOMM_ComputeTextureErrorBlock.c
@@ -0,0 +1,88 @@
+/**
+ * 
+ * File Name:  omxVCCOMM_ComputeTextureErrorBlock.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Description:
+ * Contains module computing the error for a MB of size 8x8
+ * 
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+#include "armCOMM.h"
+
+/**
+ * Function:  omxVCCOMM_ComputeTextureErrorBlock   (6.1.4.1.2)
+ *
+ * Description:
+ * Computes the texture error of the block. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - pointer to the source plane. This should be aligned on an 8-byte 
+ *            boundary. 
+ *   srcStep - step of the source plane 
+ *   pSrcRef - pointer to the reference buffer, an 8x8 block. This should be 
+ *            aligned on an 8-byte boundary. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - pointer to the destination buffer, an 8x8 block. This should be 
+ *            aligned on an 8-byte boundary. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments:
+ *    -    At least one of the following pointers is NULL: 
+ *         pSrc, pSrcRef, pDst. 
+ *    -    pSrc is not 8-byte aligned. 
+ *    -    SrcStep <= 0 or srcStep is not a multiple of 8. 
+ *    -    pSrcRef is not 8-byte aligned. 
+ *    -    pDst is not 8-byte aligned 
+ *
+ */
+
+OMXResult omxVCCOMM_ComputeTextureErrorBlock(
+     const OMX_U8 *pSrc,
+     OMX_INT srcStep,
+     const OMX_U8 *pSrcRef,
+     OMX_S16 * pDst
+)
+{
+
+    OMX_INT     x, y, count;
+
+    /* Argument error checks */
+    armRetArgErrIf(pSrc == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pSrcRef == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pDst == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(!armIs8ByteAligned(pSrc), OMX_Sts_BadArgErr);
+    armRetArgErrIf(!armIs8ByteAligned(pSrcRef), OMX_Sts_BadArgErr);
+    armRetArgErrIf(!armIs8ByteAligned(pDst), OMX_Sts_BadArgErr);
+    armRetArgErrIf((srcStep <= 0) || (srcStep & 7), OMX_Sts_BadArgErr);
+
+    /* Calculate the error block */
+    for (y = 0, count = 0;
+         y < 8;
+         y++, pSrc += srcStep)
+    {
+        for (x = 0; x < 8; x++, count++)
+        {
+            pDst[count] = pSrc[x] - pSrcRef[count];
+        }
+    }
+
+    return OMX_Sts_NoErr;
+
+}
+
+/* End of file */
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/comm/src/omxVCCOMM_ComputeTextureErrorBlock_SAD.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/comm/src/omxVCCOMM_ComputeTextureErrorBlock_SAD.c
new file mode 100644
index 0000000..c4731aad
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/comm/src/omxVCCOMM_ComputeTextureErrorBlock_SAD.c
@@ -0,0 +1,93 @@
+/**
+ * 
+ * File Name:  omxVCCOMM_ComputeTextureErrorBlock_SAD.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Description:
+ * Contains module computing the error for a MB of size 8x8
+ * 
+ */
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+
+
+/**
+ * Function:  omxVCCOMM_ComputeTextureErrorBlock_SAD   (6.1.4.1.1)
+ *
+ * Description:
+ * Computes texture error of the block; also returns SAD. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - pointer to the source plane; must be aligned on an 8-byte 
+ *            boundary. 
+ *   srcStep - step of the source plane 
+ *   pSrcRef - pointer to the reference buffer, an 8x8 block; must be aligned 
+ *            on an 8-byte boundary. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - pointer to the destination buffer, an 8x8 block; must be aligned 
+ *            on an 8-byte boundary. 
+ *   pDstSAD - pointer to the Sum of Absolute Differences (SAD) value 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments 
+ *    -    At least one of the following 
+ *         pointers is NULL: pSrc, pSrcRef, pDst and pDstSAD. 
+ *    -    pSrc is not 8-byte aligned. 
+ *    -    SrcStep <= 0 or srcStep is not a multiple of 8. 
+ *    -    pSrcRef is not 8-byte aligned. 
+ *    -    pDst is not 8-byte aligned. 
+ *
+ */
+
+OMXResult omxVCCOMM_ComputeTextureErrorBlock_SAD(
+     const OMX_U8 *pSrc,
+     OMX_INT srcStep,
+     const OMX_U8 *pSrcRef,
+     OMX_S16 * pDst,
+     OMX_INT *pDstSAD
+)
+{
+
+    OMX_INT     x, y, count;
+
+    /* Argument error checks */
+    armRetArgErrIf(pSrc == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pSrcRef == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pDst == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pDstSAD == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(!armIs8ByteAligned(pSrc), OMX_Sts_BadArgErr);
+    armRetArgErrIf(!armIs8ByteAligned(pSrcRef), OMX_Sts_BadArgErr);
+    armRetArgErrIf(!armIs8ByteAligned(pDst), OMX_Sts_BadArgErr);
+    armRetArgErrIf((srcStep <= 0) || (srcStep & 7), OMX_Sts_BadArgErr);
+
+    /* Calculate the error block */
+    for (y = 0, count = 0, *pDstSAD = 0;
+         y < 8;
+         y++, pSrc += srcStep)
+    {
+        for (x = 0; x < 8; x++, count++)
+        {
+            pDst[count] = pSrc[x] - pSrcRef[count];
+            *pDstSAD += armAbs(pDst[count]);
+        }
+    }
+
+    return OMX_Sts_NoErr;
+
+}
+
+/* End of file */
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/comm/src/omxVCCOMM_Copy16x16.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/comm/src/omxVCCOMM_Copy16x16.c
new file mode 100644
index 0000000..4857024
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/comm/src/omxVCCOMM_Copy16x16.c
@@ -0,0 +1,79 @@
+/**
+ * 
+ * File Name:  omxVCCOMM_Copy16x16.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * Description:
+ * MPEG4 16x16 Copy module
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+
+/**
+ * Function:  omxVCCOMM_Copy16x16   (6.1.3.3.2)
+ *
+ * Description:
+ * Copies the reference 16x16 macroblock to the current macroblock. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - pointer to the reference macroblock in the source frame; must be 
+ *            aligned on a 16-byte boundary. 
+ *   step - distance between the starts of consecutive lines in the reference 
+ *            frame, in bytes; must be a multiple of 16 and must be larger 
+ *            than or equal to 16. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - pointer to the destination macroblock; must be aligned on a 
+ *            16-byte boundary. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned under any of the following 
+ *              conditions: 
+ *    -   one or more of the following pointers is NULL: pSrc, pDst 
+ *    -   one or more of the following pointers is not aligned on a 16-byte 
+ *              boundary: pSrc, pDst 
+ *    -    step <16 or step is not a multiple of 16. 
+ *
+ */
+
+OMXResult omxVCCOMM_Copy16x16(
+		const OMX_U8 *pSrc, 
+		OMX_U8 *pDst, 
+		OMX_INT step)
+ {
+    /* Definitions and Initializations*/
+
+    OMX_INT count,index, x, y;
+    
+    /* Argument error checks */
+    armRetArgErrIf(pSrc == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pDst == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(!armIs16ByteAligned(pSrc), OMX_Sts_BadArgErr);
+    armRetArgErrIf(!armIs16ByteAligned(pDst), OMX_Sts_BadArgErr);
+    armRetArgErrIf(((step < 16) || (step % 16)), OMX_Sts_BadArgErr);
+    
+    
+    /* Copying the ref 16x16 blk to the curr blk */
+    for (y = 0, count = 0, index = 0; y < 16; y++, count = count + step - 16)
+    {
+        for (x = 0; x < 16; x++, count++, index++)
+        {
+            pDst[index] = pSrc[count];
+        }       
+    }
+    return OMX_Sts_NoErr;
+ }
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/comm/src/omxVCCOMM_Copy8x8.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/comm/src/omxVCCOMM_Copy8x8.c
new file mode 100644
index 0000000..a4f9dde
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/comm/src/omxVCCOMM_Copy8x8.c
@@ -0,0 +1,79 @@
+/**
+ * 
+ * File Name:  omxVCCOMM_Copy8x8.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * Description:
+ * MPEG4 8x8 Copy module
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+
+/**
+ * Function:  omxVCCOMM_Copy8x8   (6.1.3.3.1)
+ *
+ * Description:
+ * Copies the reference 8x8 block to the current block. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - pointer to the reference block in the source frame; must be 
+ *            aligned on an 8-byte boundary. 
+ *   step - distance between the starts of consecutive lines in the reference 
+ *            frame, in bytes; must be a multiple of 8 and must be larger than 
+ *            or equal to 8. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - pointer to the destination block; must be aligned on an 8-byte 
+ *            boundary. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned under any of the following 
+ *              conditions: 
+ *    -   one or more of the following pointers is NULL: pSrc, pDst 
+ *    -   one or more of the following pointers is not aligned on an 8-byte 
+ *              boundary: pSrc, pDst 
+ *    -    step <8 or step is not a multiple of 8. 
+ *
+ */
+
+OMXResult omxVCCOMM_Copy8x8(
+		const OMX_U8 *pSrc, 
+		OMX_U8 *pDst, 
+		OMX_INT step)
+ {
+    /* Definitions and Initializations*/
+
+    OMX_INT count,index, x, y;
+    
+    /* Argument error checks */
+    armRetArgErrIf(pSrc == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pDst == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(!armIs8ByteAligned(pSrc), OMX_Sts_BadArgErr);
+    armRetArgErrIf(!armIs8ByteAligned(pDst), OMX_Sts_BadArgErr);
+    armRetArgErrIf(((step < 8) || (step % 8)), OMX_Sts_BadArgErr);
+    
+    
+    /* Copying the ref 8x8 blk to the curr blk */
+    for (y = 0, count = 0, index = 0; y < 8; y++, count = count + step - 8)
+    {
+        for (x = 0; x < 8; x++, count++, index++)
+        {
+            pDst[index] = pSrc[count];
+        }       
+    }
+    return OMX_Sts_NoErr;
+ }
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/comm/src/omxVCCOMM_ExpandFrame_I.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/comm/src/omxVCCOMM_ExpandFrame_I.c
new file mode 100644
index 0000000..9536df7
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/comm/src/omxVCCOMM_ExpandFrame_I.c
@@ -0,0 +1,126 @@
+/**
+ * 
+ * File Name:  omxVCCOMM_ExpandFrame_I.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * Description:
+ * This function will Expand Frame boundary pixels into Plane
+ * 
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+
+/**
+ * Function:  omxVCCOMM_ExpandFrame_I   (6.1.3.2.1)
+ *
+ * Description:
+ * This function expands a reconstructed frame in-place.  The unexpanded 
+ * source frame should be stored in a plane buffer with sufficient space 
+ * pre-allocated for edge expansion, and the input frame should be located in 
+ * the plane buffer center.  This function executes the pixel expansion by 
+ * replicating source frame edge pixel intensities in the empty pixel 
+ * locations (expansion region) between the source frame edge and the plane 
+ * buffer edge.  The width/height of the expansion regions on the 
+ * horizontal/vertical edges is controlled by the parameter iExpandPels. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDstPlane - pointer to the top-left corner of the frame to be 
+ *            expanded; must be aligned on an 8-byte boundary. 
+ *   iFrameWidth - frame width; must be a multiple of 8. 
+ *   iFrameHeight -frame height; must be a multiple of 8. 
+ *   iExpandPels - number of pixels to be expanded in the horizontal and 
+ *            vertical directions; must be a multiple of 8. 
+ *   iPlaneStep - distance, in bytes, between the start of consecutive lines 
+ *            in the plane buffer; must be larger than or equal to 
+ *            (iFrameWidth + 2 * iExpandPels). 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDstPlane -Pointer to the top-left corner of the frame (NOT the 
+ *            top-left corner of the plane); must be aligned on an 8-byte 
+ *            boundary. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned under any of the following 
+ *              conditions: 
+ *    -    pSrcDstPlane is NULL. 
+ *    -    pSrcDstPlane is not aligned on an 8-byte boundary. 
+ *    -    one of the following parameters is either equal to zero or is a 
+ *              non-multiple of 8: iFrameHeight, iFrameWidth, iPlaneStep, or 
+ *              iExpandPels. 
+ *    -    iPlaneStep < (iFrameWidth + 2 * iExpandPels). 
+ *
+ */
+OMXResult omxVCCOMM_ExpandFrame_I(
+	OMX_U8*	pSrcDstPlane, 
+	OMX_U32	iFrameWidth, 
+	OMX_U32	iFrameHeight, 
+	OMX_U32	iExpandPels, 
+	OMX_U32	iPlaneStep
+)
+{
+    OMX_INT     x, y;
+    OMX_U8*     pLeft;
+    OMX_U8*     pRight;
+    OMX_U8*     pTop;
+    OMX_U8*     pBottom;
+
+    /* check for argument error */
+    armRetArgErrIf(pSrcDstPlane == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(armNot8ByteAligned(pSrcDstPlane), OMX_Sts_BadArgErr)
+    armRetArgErrIf(iFrameWidth == 0 || iFrameWidth & 7, OMX_Sts_BadArgErr)
+    armRetArgErrIf(iFrameHeight== 0 || iFrameHeight & 7, OMX_Sts_BadArgErr)
+    armRetArgErrIf(iExpandPels == 0 || iExpandPels & 7, OMX_Sts_BadArgErr)
+    armRetArgErrIf(iPlaneStep == 0 || iPlaneStep & 7, OMX_Sts_BadArgErr)
+    armRetArgErrIf(iPlaneStep < (iFrameWidth + 2 * iExpandPels), 
+                   OMX_Sts_BadArgErr)
+
+    /* Top and Bottom */
+    pTop = pSrcDstPlane - (iExpandPels * iPlaneStep);
+    pBottom = pSrcDstPlane + (iFrameHeight * iPlaneStep);
+
+    for (y = 0; y < (OMX_INT)iExpandPels; y++)
+    {
+        for (x = 0; x < (OMX_INT)iFrameWidth; x++)
+        {
+            pTop [y * iPlaneStep + x] = 
+                pSrcDstPlane [x];
+            pBottom [y * iPlaneStep + x] = 
+                pSrcDstPlane [(iFrameHeight - 1) * iPlaneStep + x];
+        }
+    }
+
+    /* Left, Right and Corners */
+    pLeft = pSrcDstPlane - iExpandPels;
+    pRight = pSrcDstPlane + iFrameWidth;
+
+    for (y = -(OMX_INT)iExpandPels; y < (OMX_INT)(iFrameHeight + iExpandPels); y++)
+    {
+        for (x = 0; x < (OMX_INT)iExpandPels; x++)
+        {
+            pLeft [y * iPlaneStep + x] = 
+                pSrcDstPlane [y * iPlaneStep + 0];
+            pRight [y * iPlaneStep + x] = 
+                pSrcDstPlane [y * iPlaneStep + (iFrameWidth - 1)];
+        }
+    }
+
+    return OMX_Sts_NoErr;
+}
+
+/*****************************************************************************
+ *                              END OF FILE
+ *****************************************************************************/
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/comm/src/omxVCCOMM_LimitMVToRect.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/comm/src/omxVCCOMM_LimitMVToRect.c
new file mode 100644
index 0000000..af04582
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/comm/src/omxVCCOMM_LimitMVToRect.c
@@ -0,0 +1,81 @@
+/**
+ * 
+ * File Name:  omxVCCOMM_LimitMVToRect.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Description:
+ * Contains module for limiting the MV
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+
+/**
+ * Function:  omxVCCOMM_LimitMVToRect   (6.1.4.1.3)
+ *
+ * Description:
+ * Limits the motion vector associated with the current block/macroblock to 
+ * prevent the motion compensated block/macroblock from moving outside a 
+ * bounding rectangle as shown in Figure 6-1. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcMV - pointer to the motion vector associated with the current block 
+ *            or macroblock 
+ *   pRectVOPRef - pointer to the bounding rectangle 
+ *   Xcoord, Ycoord  - coordinates of the current block or macroblock 
+ *   size - size of the current block or macroblock; must be equal to 8 or 
+ *            16. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstMV - pointer to the limited motion vector 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments.  Returned if one or more of the 
+ *              following conditions is true: 
+ *    -    at least one of the following pointers is NULL: 
+ *         pSrcMV, pDstMV, or pRectVOPRef. 
+ *    -    size is not equal to either 8 or 16. 
+ *    -    the width or height of the bounding rectangle is less than 
+ *         twice the block size.
+ */
+OMXResult omxVCCOMM_LimitMVToRect(
+     const OMXVCMotionVector * pSrcMV,
+     OMXVCMotionVector *pDstMV,
+     const OMXRect * pRectVOPRef,
+     OMX_INT Xcoord,
+     OMX_INT Ycoord,
+     OMX_INT size
+)
+{
+    /* Argument error checks */
+    armRetArgErrIf(pSrcMV == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pDstMV == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pRectVOPRef == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf((size != 8) && (size != 16), OMX_Sts_BadArgErr);
+    armRetArgErrIf((pRectVOPRef->width < (2* size)), OMX_Sts_BadArgErr);
+    armRetArgErrIf((pRectVOPRef->height < (2* size)), OMX_Sts_BadArgErr);
+    
+    pDstMV->dx = armMin (armMax (pSrcMV->dx, 2*pRectVOPRef->x - Xcoord),
+                    (2*pRectVOPRef->x + pRectVOPRef->width - Xcoord - size));
+    pDstMV->dy = armMin (armMax (pSrcMV->dy, 2*pRectVOPRef->y - Ycoord),
+                    (2*pRectVOPRef->y + pRectVOPRef->height - Ycoord - size));
+
+
+    return OMX_Sts_NoErr;
+}
+
+/* End of file */
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/comm/src/omxVCCOMM_SAD_16x.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/comm/src/omxVCCOMM_SAD_16x.c
new file mode 100644
index 0000000..0f0cedb
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/comm/src/omxVCCOMM_SAD_16x.c
@@ -0,0 +1,80 @@
+/**
+ * 
+ * File Name:  omxVCCOMM_SAD_16x.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * Description:
+ * This function will calculate SAD for 16x16 and 16x8 blocks
+ * 
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armVC.h"
+#include "armCOMM.h"
+
+/**
+ * Function:  omxVCCOMM_SAD_16x   (6.1.4.1.4)
+ *
+ * Description:
+ * This function calculates the SAD for 16x16 and 16x8 blocks. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcOrg - Pointer to the original block; must be aligned on a 16-byte 
+ *             boundary. 
+ *   iStepOrg - Step of the original block buffer 
+ *   pSrcRef  - Pointer to the reference block 
+ *   iStepRef - Step of the reference block buffer 
+ *   iHeight  - Height of the block 
+ *
+ * Output Arguments:
+ *   
+ *   pDstSAD - Pointer of result SAD 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments.  Returned if one or more of the 
+ *              following conditions is true: 
+ *    -    at least one of the following pointers is NULL: 
+ *         pSrcOrg, pDstSAD, or pSrcRef 
+ *    -    pSrcOrg is not 16-byte aligned. 
+ *    -    iStepOrg  <= 0 or iStepOrg is not a multiple of 16 
+ *    -    iStepRef <= 0 or iStepRef is not a multiple of 16 
+ *    -    iHeight is not 8 or 16 
+ *
+ */
+OMXResult omxVCCOMM_SAD_16x(
+			const OMX_U8* 	pSrcOrg,
+			OMX_U32 	iStepOrg,
+			const OMX_U8* 	pSrcRef,
+			OMX_U32 	iStepRef,
+			OMX_S32*	pDstSAD,
+			OMX_U32		iHeight
+)
+{
+    /* check for argument error */
+    armRetArgErrIf(pSrcOrg == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pSrcRef == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pDstSAD == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf((iHeight != 16) && (iHeight != 8), OMX_Sts_BadArgErr)
+    armRetArgErrIf(armNot16ByteAligned(pSrcOrg), OMX_Sts_BadArgErr)
+    armRetArgErrIf((iStepOrg == 0) || (iStepOrg & 15), OMX_Sts_BadArgErr)
+    armRetArgErrIf((iStepRef == 0) || (iStepRef & 15), OMX_Sts_BadArgErr)
+
+    return armVCCOMM_SAD 
+        (pSrcOrg, iStepOrg, pSrcRef, iStepRef, pDstSAD, iHeight, 16);
+}
+
+/*****************************************************************************
+ *                              END OF FILE
+ *****************************************************************************/
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/comm/src/omxVCCOMM_SAD_8x.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/comm/src/omxVCCOMM_SAD_8x.c
new file mode 100644
index 0000000..1421d99
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/comm/src/omxVCCOMM_SAD_8x.c
@@ -0,0 +1,80 @@
+/**
+ * 
+ * File Name:  omxVCCOMM_SAD_8x.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * Description:
+ * This function will calculate SAD for 8x16, 8x8, 8x4 blocks
+ * 
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armVC.h"
+#include "armCOMM.h"
+
+/**
+ * Function:  omxVCCOMM_SAD_8x   (6.1.4.1.5)
+ *
+ * Description:
+ * This function calculates the SAD for 8x16, 8x8, 8x4 blocks. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcOrg  - Pointer to the original block; must be aligned on a 8-byte 
+ *              boundary. 
+ *   iStepOrg - Step of the original block buffer 
+ *   pSrcRef  - Pointer to the reference block 
+ *   iStepRef - Step of the reference block buffer 
+ *   iHeight  - Height of the block 
+ *
+ * Output Arguments:
+ *   
+ *   pDstSAD -Pointer of result SAD 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments.  Returned if one or more of the 
+ *              following conditions is true: 
+ *    -    at least one of the following pointers is NULL: 
+ *         pSrcOrg, pDstSAD, or pSrcRef 
+ *    -    pSrcOrg is not 8-byte aligned. 
+ *    -    iStepOrg  <= 0 or iStepOrg is not a multiple of 8 
+ *    -    iStepRef <= 0 or iStepRef is not a multiple of 8 
+ *    -    iHeight is not 4, 8 or 16 
+ *
+ */
+OMXResult omxVCCOMM_SAD_8x(	
+	const OMX_U8* 	pSrcOrg,
+	OMX_U32 	iStepOrg,
+	const OMX_U8* 	pSrcRef,
+	OMX_U32 	iStepRef,
+	OMX_S32*	pDstSAD,
+	OMX_U32		iHeight
+)
+{
+    /* check for argument error */
+    armRetArgErrIf(pSrcOrg == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pSrcRef == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pDstSAD == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf((iHeight != 16) && (iHeight != 8) && (iHeight != 4), OMX_Sts_BadArgErr)
+    armRetArgErrIf(armNot8ByteAligned(pSrcOrg), OMX_Sts_BadArgErr)
+    armRetArgErrIf((iStepOrg == 0) || (iStepOrg & 7), OMX_Sts_BadArgErr)
+    armRetArgErrIf((iStepRef == 0) || (iStepRef & 7), OMX_Sts_BadArgErr)
+
+    return armVCCOMM_SAD 
+        (pSrcOrg, iStepOrg, pSrcRef, iStepRef, pDstSAD, iHeight, 8);
+}
+
+/*****************************************************************************
+ *                              END OF FILE
+ *****************************************************************************/
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/api/armVCM4P10_CAVLCTables.h b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/api/armVCM4P10_CAVLCTables.h
new file mode 100644
index 0000000..8d18a8f
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/api/armVCM4P10_CAVLCTables.h
@@ -0,0 +1,34 @@
+/* ----------------------------------------------------------------
+ * 
+ * 
+ * File Name:  armVCM4P10_CAVLCTables.h
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * ----------------------------------------------------------------
+ * File:     armVCM4P10_CAVLCTables.h
+ * ----------------------------------------------------------------
+ * 
+ * Header file for ARM implementation of OpenMAX VCM4P10
+ * 
+ */
+ 
+#ifndef ARMVCM4P10_CAVLCTABLES_H
+#define ARMVCM4P10_CAVLCTABLES_H
+  
+/* CAVLC tables */
+
+extern const OMX_U8 armVCM4P10_CAVLCTrailingOnes[62];
+extern const OMX_U8 armVCM4P10_CAVLCTotalCoeff[62];
+extern const ARM_VLC32 *armVCM4P10_CAVLCCoeffTokenTables[5];
+extern const ARM_VLC32 armVCM4P10_CAVLCLevelPrefix[17];
+extern const ARM_VLC32 *armVCM4P10_CAVLCTotalZeroTables[15];
+extern const ARM_VLC32 *armVCM4P10_CAVLCTotalZeros2x2Tables[3];
+extern const ARM_VLC32 *armVCM4P10_CAVLCRunBeforeTables[7];
+
+#endif
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_CAVLCTables.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_CAVLCTables.c
new file mode 100644
index 0000000..f4e36ad
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_CAVLCTables.c
@@ -0,0 +1,703 @@
+/* ----------------------------------------------------------------
+ *
+ * 
+ * File Name:  armVCM4P10_CAVLCTables.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * 
+ * CAVLC tables for H.264
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM_Bitstream.h"
+#include "armVC.h"
+#include "armVCM4P10_CAVLCTables.h"
+
+/* Tables mapping a code to TrailingOnes and TotalCoeff */
+
+const OMX_U8 armVCM4P10_CAVLCTrailingOnes[62] = {
+ 0,
+ 0, 1,
+ 0, 1, 2,
+ 0, 1, 2, 3,
+ 0, 1, 2, 3,
+ 0, 1, 2, 3,
+ 0, 1, 2, 3,
+ 0, 1, 2, 3,
+ 0, 1, 2, 3,
+ 0, 1, 2, 3,
+ 0, 1, 2, 3,
+ 0, 1, 2, 3,
+ 0, 1, 2, 3,
+ 0, 1, 2, 3,
+ 0, 1, 2, 3,
+ 0, 1, 2, 3,
+ 0, 1, 2, 3
+};
+
+const OMX_U8 armVCM4P10_CAVLCTotalCoeff[62] = {
+ 0,
+ 1, 1,
+ 2, 2, 2,
+ 3, 3, 3, 3,
+ 4, 4, 4, 4,
+ 5, 5, 5, 5,
+ 6, 6, 6, 6,
+ 7, 7, 7, 7,
+ 8, 8, 8, 8,
+ 9, 9, 9, 9,
+ 10, 10, 10, 10,
+ 11, 11, 11, 11,
+ 12, 12, 12, 12,
+ 13, 13, 13, 13,
+ 14, 14, 14, 14,
+ 15, 15, 15, 15,
+ 16, 16, 16, 16
+};
+
+static const ARM_VLC32 armVCM4P10_CAVLCCoeffToken0[63] = {
+    {  1, 0x0001 },
+    {  6, 0x0005 },
+    {  2, 0x0001 },
+    {  8, 0x0007 },
+    {  6, 0x0004 },
+    {  3, 0x0001 },
+    {  9, 0x0007 },
+    {  8, 0x0006 },
+    {  7, 0x0005 },
+    {  5, 0x0003 },
+    { 10, 0x0007 },
+    {  9, 0x0006 },
+    {  8, 0x0005 },
+    {  6, 0x0003 },
+    { 11, 0x0007 },
+    { 10, 0x0006 },
+    {  9, 0x0005 },
+    {  7, 0x0004 },
+    { 13, 0x000f },
+    { 11, 0x0006 },
+    { 10, 0x0005 },
+    {  8, 0x0004 },
+    { 13, 0x000b },
+    { 13, 0x000e },
+    { 11, 0x0005 },
+    {  9, 0x0004 },
+    { 13, 0x0008 },
+    { 13, 0x000a },
+    { 13, 0x000d },
+    { 10, 0x0004 },
+    { 14, 0x000f },
+    { 14, 0x000e },
+    { 13, 0x0009 },
+    { 11, 0x0004 },
+    { 14, 0x000b },
+    { 14, 0x000a },
+    { 14, 0x000d },
+    { 13, 0x000c },
+    { 15, 0x000f },
+    { 15, 0x000e },
+    { 14, 0x0009 },
+    { 14, 0x000c },
+    { 15, 0x000b },
+    { 15, 0x000a },
+    { 15, 0x000d },
+    { 14, 0x0008 },
+    { 16, 0x000f },
+    { 15, 0x0001 },
+    { 15, 0x0009 },
+    { 15, 0x000c },
+    { 16, 0x000b },
+    { 16, 0x000e },
+    { 16, 0x000d },
+    { 15, 0x0008 },
+    { 16, 0x0007 },
+    { 16, 0x000a },
+    { 16, 0x0009 },
+    { 16, 0x000c },
+    { 16, 0x0004 },
+    { 16, 0x0006 },
+    { 16, 0x0005 },
+    { 16, 0x0008 },
+    {  0, 0x0000 }
+};
+
+static const ARM_VLC32 armVCM4P10_CAVLCCoeffToken1[63] = {
+    {  2, 0x0003 },
+    {  6, 0x000b },
+    {  2, 0x0002 },
+    {  6, 0x0007 },
+    {  5, 0x0007 },
+    {  3, 0x0003 },
+    {  7, 0x0007 },
+    {  6, 0x000a },
+    {  6, 0x0009 },
+    {  4, 0x0005 },
+    {  8, 0x0007 },
+    {  6, 0x0006 },
+    {  6, 0x0005 },
+    {  4, 0x0004 },
+    {  8, 0x0004 },
+    {  7, 0x0006 },
+    {  7, 0x0005 },
+    {  5, 0x0006 },
+    {  9, 0x0007 },
+    {  8, 0x0006 },
+    {  8, 0x0005 },
+    {  6, 0x0008 },
+    { 11, 0x000f },
+    {  9, 0x0006 },
+    {  9, 0x0005 },
+    {  6, 0x0004 },
+    { 11, 0x000b },
+    { 11, 0x000e },
+    { 11, 0x000d },
+    {  7, 0x0004 },
+    { 12, 0x000f },
+    { 11, 0x000a },
+    { 11, 0x0009 },
+    {  9, 0x0004 },
+    { 12, 0x000b },
+    { 12, 0x000e },
+    { 12, 0x000d },
+    { 11, 0x000c },
+    { 12, 0x0008 },
+    { 12, 0x000a },
+    { 12, 0x0009 },
+    { 11, 0x0008 },
+    { 13, 0x000f },
+    { 13, 0x000e },
+    { 13, 0x000d },
+    { 12, 0x000c },
+    { 13, 0x000b },
+    { 13, 0x000a },
+    { 13, 0x0009 },
+    { 13, 0x000c },
+    { 13, 0x0007 },
+    { 14, 0x000b },
+    { 13, 0x0006 },
+    { 13, 0x0008 },
+    { 14, 0x0009 },
+    { 14, 0x0008 },
+    { 14, 0x000a },
+    { 13, 0x0001 },
+    { 14, 0x0007 },
+    { 14, 0x0006 },
+    { 14, 0x0005 },
+    { 14, 0x0004 },
+    {  0, 0x0000 }
+};
+
+static const ARM_VLC32 armVCM4P10_CAVLCCoeffToken2[63] = {
+    {  4, 0x000f },
+    {  6, 0x000f },
+    {  4, 0x000e },
+    {  6, 0x000b },
+    {  5, 0x000f },
+    {  4, 0x000d },
+    {  6, 0x0008 },
+    {  5, 0x000c },
+    {  5, 0x000e },
+    {  4, 0x000c },
+    {  7, 0x000f },
+    {  5, 0x000a },
+    {  5, 0x000b },
+    {  4, 0x000b },
+    {  7, 0x000b },
+    {  5, 0x0008 },
+    {  5, 0x0009 },
+    {  4, 0x000a },
+    {  7, 0x0009 },
+    {  6, 0x000e },
+    {  6, 0x000d },
+    {  4, 0x0009 },
+    {  7, 0x0008 },
+    {  6, 0x000a },
+    {  6, 0x0009 },
+    {  4, 0x0008 },
+    {  8, 0x000f },
+    {  7, 0x000e },
+    {  7, 0x000d },
+    {  5, 0x000d },
+    {  8, 0x000b },
+    {  8, 0x000e },
+    {  7, 0x000a },
+    {  6, 0x000c },
+    {  9, 0x000f },
+    {  8, 0x000a },
+    {  8, 0x000d },
+    {  7, 0x000c },
+    {  9, 0x000b },
+    {  9, 0x000e },
+    {  8, 0x0009 },
+    {  8, 0x000c },
+    {  9, 0x0008 },
+    {  9, 0x000a },
+    {  9, 0x000d },
+    {  8, 0x0008 },
+    { 10, 0x000d },
+    {  9, 0x0007 },
+    {  9, 0x0009 },
+    {  9, 0x000c },
+    { 10, 0x0009 },
+    { 10, 0x000c },
+    { 10, 0x000b },
+    { 10, 0x000a },
+    { 10, 0x0005 },
+    { 10, 0x0008 },
+    { 10, 0x0007 },
+    { 10, 0x0006 },
+    { 10, 0x0001 },
+    { 10, 0x0004 },
+    { 10, 0x0003 },
+    { 10, 0x0002 },
+    {  0, 0x0000 }
+};
+
+static const ARM_VLC32 armVCM4P10_CAVLCCoeffToken3[63] = {
+    {  6, 0x0003 },
+    {  6, 0x0000 },
+    {  6, 0x0001 },
+    {  6, 0x0004 },
+    {  6, 0x0005 },
+    {  6, 0x0006 },
+    {  6, 0x0008 },
+    {  6, 0x0009 },
+    {  6, 0x000a },
+    {  6, 0x000b },
+    {  6, 0x000c },
+    {  6, 0x000d },
+    {  6, 0x000e },
+    {  6, 0x000f },
+    {  6, 0x0010 },
+    {  6, 0x0011 },
+    {  6, 0x0012 },
+    {  6, 0x0013 },
+    {  6, 0x0014 },
+    {  6, 0x0015 },
+    {  6, 0x0016 },
+    {  6, 0x0017 },
+    {  6, 0x0018 },
+    {  6, 0x0019 },
+    {  6, 0x001a },
+    {  6, 0x001b },
+    {  6, 0x001c },
+    {  6, 0x001d },
+    {  6, 0x001e },
+    {  6, 0x001f },
+    {  6, 0x0020 },
+    {  6, 0x0021 },
+    {  6, 0x0022 },
+    {  6, 0x0023 },
+    {  6, 0x0024 },
+    {  6, 0x0025 },
+    {  6, 0x0026 },
+    {  6, 0x0027 },
+    {  6, 0x0028 },
+    {  6, 0x0029 },
+    {  6, 0x002a },
+    {  6, 0x002b },
+    {  6, 0x002c },
+    {  6, 0x002d },
+    {  6, 0x002e },
+    {  6, 0x002f },
+    {  6, 0x0030 },
+    {  6, 0x0031 },
+    {  6, 0x0032 },
+    {  6, 0x0033 },
+    {  6, 0x0034 },
+    {  6, 0x0035 },
+    {  6, 0x0036 },
+    {  6, 0x0037 },
+    {  6, 0x0038 },
+    {  6, 0x0039 },
+    {  6, 0x003a },
+    {  6, 0x003b },
+    {  6, 0x003c },
+    {  6, 0x003d },
+    {  6, 0x003e },
+    {  6, 0x003f },
+    {  0, 0x0000 }
+};
+
+static const ARM_VLC32 armVCM4P10_CAVLCCoeffToken4[15] = {
+    {  2, 0x0001 },
+    {  6, 0x0007 },
+    {  1, 0x0001 },
+    {  6, 0x0004 },
+    {  6, 0x0006 },
+    {  3, 0x0001 },
+    {  6, 0x0003 },
+    {  7, 0x0003 },
+    {  7, 0x0002 },
+    {  6, 0x0005 },
+    {  6, 0x0002 },
+    {  8, 0x0003 },
+    {  8, 0x0002 },
+    {  7, 0x0000 },
+    {  0, 0x0000 }
+};
+
+
+const ARM_VLC32 *armVCM4P10_CAVLCCoeffTokenTables[5] = {
+     armVCM4P10_CAVLCCoeffToken0, 
+     armVCM4P10_CAVLCCoeffToken1,
+     armVCM4P10_CAVLCCoeffToken2, 
+     armVCM4P10_CAVLCCoeffToken3, 
+     armVCM4P10_CAVLCCoeffToken4
+};
+
+/* Table for level_prefix */
+
+const ARM_VLC32 armVCM4P10_CAVLCLevelPrefix[17] = {
+    {  1, 1},
+    {  2, 1},
+    {  3, 1},
+    {  4, 1},
+    {  5, 1},
+    {  6, 1},
+    {  7, 1},
+    {  8, 1},
+    {  9, 1},
+    { 10, 1},
+    { 11, 1},
+    { 12, 1},
+    { 13, 1},
+    { 14, 1},
+    { 15, 1},
+    { 16, 1},
+    {  0, 0}
+};
+
+/* Tables for total_zeros */
+
+static const ARM_VLC32 armVCM4P10_CAVLCTotalZeros1[17] = {
+    {  1, 0x0001 },
+    {  3, 0x0003 },
+    {  3, 0x0002 },
+    {  4, 0x0003 },
+    {  4, 0x0002 },
+    {  5, 0x0003 },
+    {  5, 0x0002 },
+    {  6, 0x0003 },
+    {  6, 0x0002 },
+    {  7, 0x0003 },
+    {  7, 0x0002 },
+    {  8, 0x0003 },
+    {  8, 0x0002 },
+    {  9, 0x0003 },
+    {  9, 0x0002 },
+    {  9, 0x0001 },
+    {  0, 0x0000 }
+};
+
+static const ARM_VLC32 armVCM4P10_CAVLCTotalZeros2[16] = {
+    {  3, 0x0007 },
+    {  3, 0x0006 },
+    {  3, 0x0005 },
+    {  3, 0x0004 },
+    {  3, 0x0003 },
+    {  4, 0x0005 },
+    {  4, 0x0004 },
+    {  4, 0x0003 },
+    {  4, 0x0002 },
+    {  5, 0x0003 },
+    {  5, 0x0002 },
+    {  6, 0x0003 },
+    {  6, 0x0002 },
+    {  6, 0x0001 },
+    {  6, 0x0000 },
+    {  0, 0x0000 }
+};
+
+static const ARM_VLC32 armVCM4P10_CAVLCTotalZeros3[15] = {
+    {  4, 0x0005 },
+    {  3, 0x0007 },
+    {  3, 0x0006 },
+    {  3, 0x0005 },
+    {  4, 0x0004 },
+    {  4, 0x0003 },
+    {  3, 0x0004 },
+    {  3, 0x0003 },
+    {  4, 0x0002 },
+    {  5, 0x0003 },
+    {  5, 0x0002 },
+    {  6, 0x0001 },
+    {  5, 0x0001 },
+    {  6, 0x0000 },
+    {  0, 0x0000 }
+};
+
+static const ARM_VLC32 armVCM4P10_CAVLCTotalZeros4[14] = {
+    {  5, 0x0003 },
+    {  3, 0x0007 },
+    {  4, 0x0005 },
+    {  4, 0x0004 },
+    {  3, 0x0006 },
+    {  3, 0x0005 },
+    {  3, 0x0004 },
+    {  4, 0x0003 },
+    {  3, 0x0003 },
+    {  4, 0x0002 },
+    {  5, 0x0002 },
+    {  5, 0x0001 },
+    {  5, 0x0000 },
+    {  0, 0x0000 }
+};
+
+static const ARM_VLC32 armVCM4P10_CAVLCTotalZeros5[13] = {
+    {  4, 0x0005 },
+    {  4, 0x0004 },
+    {  4, 0x0003 },
+    {  3, 0x0007 },
+    {  3, 0x0006 },
+    {  3, 0x0005 },
+    {  3, 0x0004 },
+    {  3, 0x0003 },
+    {  4, 0x0002 },
+    {  5, 0x0001 },
+    {  4, 0x0001 },
+    {  5, 0x0000 },
+    {  0, 0x0000 }
+};
+
+static const ARM_VLC32 armVCM4P10_CAVLCTotalZeros6[12] = {
+    {  6, 0x0001 },
+    {  5, 0x0001 },
+    {  3, 0x0007 },
+    {  3, 0x0006 },
+    {  3, 0x0005 },
+    {  3, 0x0004 },
+    {  3, 0x0003 },
+    {  3, 0x0002 },
+    {  4, 0x0001 },
+    {  3, 0x0001 },
+    {  6, 0x0000 },
+    {  0, 0x0000 }
+};
+
+static const ARM_VLC32 armVCM4P10_CAVLCTotalZeros7[11] = {
+    {  6, 0x0001 },
+    {  5, 0x0001 },
+    {  3, 0x0005 },
+    {  3, 0x0004 },
+    {  3, 0x0003 },
+    {  2, 0x0003 },
+    {  3, 0x0002 },
+    {  4, 0x0001 },
+    {  3, 0x0001 },
+    {  6, 0x0000 },
+    {  0, 0x0000 }
+};
+
+static const ARM_VLC32 armVCM4P10_CAVLCTotalZeros8[10] = {
+    {  6, 0x0001 },
+    {  4, 0x0001 },
+    {  5, 0x0001 },
+    {  3, 0x0003 },
+    {  2, 0x0003 },
+    {  2, 0x0002 },
+    {  3, 0x0002 },
+    {  3, 0x0001 },
+    {  6, 0x0000 },
+    {  0, 0x0000 }
+};
+
+static const ARM_VLC32 armVCM4P10_CAVLCTotalZeros9[9] = {
+    {  6, 0x0001 },
+    {  6, 0x0000 },
+    {  4, 0x0001 },
+    {  2, 0x0003 },
+    {  2, 0x0002 },
+    {  3, 0x0001 },
+    {  2, 0x0001 },
+    {  5, 0x0001 },
+    {  0, 0x0000 }
+};
+
+static const ARM_VLC32 armVCM4P10_CAVLCTotalZeros10[8] = {
+    {  5, 0x0001 },
+    {  5, 0x0000 },
+    {  3, 0x0001 },
+    {  2, 0x0003 },
+    {  2, 0x0002 },
+    {  2, 0x0001 },
+    {  4, 0x0001 },
+    {  0, 0x0000 }
+};
+
+static const ARM_VLC32 armVCM4P10_CAVLCTotalZeros11[7] = {
+    {  4, 0x0000 },
+    {  4, 0x0001 },
+    {  3, 0x0001 },
+    {  3, 0x0002 },
+    {  1, 0x0001 },
+    {  3, 0x0003 },
+    {  0, 0x0000 }
+};
+
+static const ARM_VLC32 armVCM4P10_CAVLCTotalZeros12[6] = {
+    {  4, 0x0000 },
+    {  4, 0x0001 },
+    {  2, 0x0001 },
+    {  1, 0x0001 },
+    {  3, 0x0001 },
+    {  0, 0x0000 }
+};
+
+static const ARM_VLC32 armVCM4P10_CAVLCTotalZeros13[5] = {
+    {  3, 0x0000 },
+    {  3, 0x0001 },
+    {  1, 0x0001 },
+    {  2, 0x0001 },
+    {  0, 0x0000 }
+};
+
+static const ARM_VLC32 armVCM4P10_CAVLCTotalZeros14[4] = {
+    {  2, 0x0000 },
+    {  2, 0x0001 },
+    {  1, 0x0001 },
+    {  0, 0x0000 }
+};
+
+static const ARM_VLC32 armVCM4P10_CAVLCTotalZeros15[3] = {
+    {  1, 0x0000 },
+    {  1, 0x0001 },
+    {  0, 0x0000 }
+};
+
+const ARM_VLC32 *armVCM4P10_CAVLCTotalZeroTables[15] = {
+     armVCM4P10_CAVLCTotalZeros1, 
+     armVCM4P10_CAVLCTotalZeros2,
+     armVCM4P10_CAVLCTotalZeros3, 
+     armVCM4P10_CAVLCTotalZeros4, 
+     armVCM4P10_CAVLCTotalZeros5, 
+     armVCM4P10_CAVLCTotalZeros6, 
+     armVCM4P10_CAVLCTotalZeros7, 
+     armVCM4P10_CAVLCTotalZeros8, 
+     armVCM4P10_CAVLCTotalZeros9, 
+     armVCM4P10_CAVLCTotalZeros10, 
+     armVCM4P10_CAVLCTotalZeros11, 
+     armVCM4P10_CAVLCTotalZeros12, 
+     armVCM4P10_CAVLCTotalZeros13, 
+     armVCM4P10_CAVLCTotalZeros14, 
+     armVCM4P10_CAVLCTotalZeros15 
+};
+
+static const ARM_VLC32 armVCM4P10_CAVLCTotalZeros2x2_1[5] = {
+    {  1, 1 },
+    {  2, 1 },
+    {  3, 1 },
+    {  3, 0 },
+    {  0, 0 }
+};
+
+static const ARM_VLC32 armVCM4P10_CAVLCTotalZeros2x2_2[4] = {
+    {  1, 1 },
+    {  2, 1 },
+    {  2, 0 },
+    {  0, 0 }
+};
+
+static const ARM_VLC32 armVCM4P10_CAVLCTotalZeros2x2_3[3] = {
+    {  1, 1 },
+    {  1, 0 },
+    {  0, 0 }
+};
+
+const ARM_VLC32 *armVCM4P10_CAVLCTotalZeros2x2Tables[3] = {
+     armVCM4P10_CAVLCTotalZeros2x2_1, 
+     armVCM4P10_CAVLCTotalZeros2x2_2, 
+     armVCM4P10_CAVLCTotalZeros2x2_3
+};
+
+
+/* Tables for run_before */
+
+static const ARM_VLC32 armVCM4P10_CAVLCRunBefore1[3] = {
+    {  1, 0x0001 },
+    {  1, 0x0000 },
+    {  0, 0x0000 }
+};
+
+static const ARM_VLC32 armVCM4P10_CAVLCRunBefore2[4] = {
+    {  1, 0x0001 },
+    {  2, 0x0001 },
+    {  2, 0x0000 },
+    {  0, 0x0000 }
+};
+
+static const ARM_VLC32 armVCM4P10_CAVLCRunBefore3[5] = {
+    {  2, 0x0003 },
+    {  2, 0x0002 },
+    {  2, 0x0001 },
+    {  2, 0x0000 },
+    {  0, 0x0000 }
+};
+
+static const ARM_VLC32 armVCM4P10_CAVLCRunBefore4[6] = {
+    {  2, 0x0003 },
+    {  2, 0x0002 },
+    {  2, 0x0001 },
+    {  3, 0x0001 },
+    {  3, 0x0000 },
+    {  0, 0x0000 }
+};
+
+static const ARM_VLC32 armVCM4P10_CAVLCRunBefore5[7] = {
+    {  2, 0x0003 },
+    {  2, 0x0002 },
+    {  3, 0x0003 },
+    {  3, 0x0002 },
+    {  3, 0x0001 },
+    {  3, 0x0000 },
+    {  0, 0x0000 }
+};
+
+static const ARM_VLC32 armVCM4P10_CAVLCRunBefore6[8] = {
+    {  2, 0x0003 },
+    {  3, 0x0000 },
+    {  3, 0x0001 },
+    {  3, 0x0003 },
+    {  3, 0x0002 },
+    {  3, 0x0005 },
+    {  3, 0x0004 },
+    {  0, 0x0000 }
+};
+
+static const ARM_VLC32 armVCM4P10_CAVLCRunBefore7[16] = {
+    {  3, 0x0007 },
+    {  3, 0x0006 },
+    {  3, 0x0005 },
+    {  3, 0x0004 },
+    {  3, 0x0003 },
+    {  3, 0x0002 },
+    {  3, 0x0001 },
+    {  4, 0x0001 },
+    {  5, 0x0001 },
+    {  6, 0x0001 },
+    {  7, 0x0001 },
+    {  8, 0x0001 },
+    {  9, 0x0001 },
+    { 10, 0x0001 },
+    { 11, 0x0001 },
+    {  0, 0x0000 }
+};
+
+const ARM_VLC32 *armVCM4P10_CAVLCRunBeforeTables[7] = {
+     armVCM4P10_CAVLCRunBefore1, 
+     armVCM4P10_CAVLCRunBefore2, 
+     armVCM4P10_CAVLCRunBefore3, 
+     armVCM4P10_CAVLCRunBefore4, 
+     armVCM4P10_CAVLCRunBefore5, 
+     armVCM4P10_CAVLCRunBefore6, 
+     armVCM4P10_CAVLCRunBefore7
+};
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_CompareMotionCostToMV.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_CompareMotionCostToMV.c
new file mode 100644
index 0000000..e4bedc2
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_CompareMotionCostToMV.c
@@ -0,0 +1,133 @@
+/**
+ * 
+ * File Name:  armVCM4P10_CompareMotionCostToMV.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * 
+ * Description:
+ * Contains module for comparing motion vectors and SAD's to decide 
+ * the best MV and SAD
+ *
+ */
+  
+#include "omxtypes.h"
+#include "armOMX.h"
+
+#include "armVC.h"
+#include "armCOMM.h"
+
+/**
+ * Function: armVCM4P10_ExpGolBitsUsed
+ *
+ * Description:
+ * Performs calculating Exp-Golomb code length for a given values
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	         val	Signed number for which Exp-Golomb code length has
+ *                      to be calculated
+ *
+ * Return Value: 
+ *             Returns the length of the Exp-Golomb code for val
+ */
+
+static OMX_U16 armVCM4P10_ExpGolBitsUsed (OMX_S16 val)
+{
+    OMX_U16 sizeCodeNum, codeNum;
+    
+    /* Mapping val to codeNum */
+    codeNum = armAbs (val);
+    if (val > 0)
+    {
+        codeNum = (2 * codeNum) - 1;
+    }
+    else
+    {
+        codeNum = 2 * codeNum;
+    }
+    
+    /* Size of the exp-golomb code */
+    sizeCodeNum = (2 * armLogSize (codeNum + 1)) - 1;
+    
+    return sizeCodeNum;
+}
+                
+
+/**
+ * Function: armVCM4P10_CompareMotionCostToMV
+ *
+ * Description:
+ * Performs comparision of motion vectors and Motion cost to decide the 
+ * best MV and best MC
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	         mvX	x coordinate of the candidate motion vector in 1/4 pel units
+ * [in]	         mvY	y coordinate of the candidate motion vector in 1/4 pel units
+ * [in]	      diffMV	differential MV
+ * [in]	     candSAD	Candidate SAD
+ * [in]	      bestMV	Best MV, contains best MV till the previous interation.
+ * [in]       nLamda    Lamda factor; used to compute motion cost 
+ * [in]   *pBestCost    Contains the current best motion cost.
+ * [out]  *pBestCost    pBestCost Motion cost will be associated with the best MV 
+ *                      after judgement; 
+ *                      computed as SAD+Lamda*BitsUsedByMV, if the candCost is less 
+ *                      than the best cost passed then the *pBestCost will be equal to candCost
+ * [out]	  bestMV	Finally will have the best MV after the judgement.
+ *
+ * Return Value:
+ * OMX_INT -- 1 to indicate that the current motion cost is the best 
+ *            0 to indicate that it is NOT the best motion cost
+ */
+
+OMX_INT armVCM4P10_CompareMotionCostToMV (
+    OMX_S16  mvX,
+    OMX_S16  mvY,
+    OMXVCMotionVector diffMV, 
+    OMX_INT candSAD, 
+    OMXVCMotionVector *bestMV, 
+    OMX_U32 nLamda,
+    OMX_S32 *pBestCost
+) 
+{
+    OMX_S32 candCost;
+    OMX_U16 sizeCodeNum;
+    
+    sizeCodeNum = armVCM4P10_ExpGolBitsUsed (diffMV.dx);
+    sizeCodeNum += armVCM4P10_ExpGolBitsUsed (diffMV.dy);
+    
+    /* Motion cost = SAD +  lamda * ((bitsused(diffMVx) + (bitsused(diffMVy))*/
+    candCost = candSAD + (nLamda * sizeCodeNum);
+        
+    /* Calculate candCost */
+    if (candCost < *pBestCost)
+    {
+        *pBestCost = candCost;
+        bestMV->dx = mvX;
+        bestMV->dy = mvY;
+        return 1;
+    }
+    if (candCost > *pBestCost)
+    {
+        return 0;
+    }
+    /* shorter motion vector */
+    if ( (mvX * mvX + mvY * mvY) < ((bestMV->dx * bestMV->dx) + (bestMV->dy * bestMV->dy)) )
+    {
+        *pBestCost = candCost;
+        bestMV->dx = mvX;
+        bestMV->dy = mvY;
+        return 1;
+    }
+    
+    return 0;
+}
+
+/*End of File*/
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_DeBlockPixel.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_DeBlockPixel.c
new file mode 100644
index 0000000..f4fb1d9
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_DeBlockPixel.c
@@ -0,0 +1,151 @@
+/* ----------------------------------------------------------------
+ *
+ * 
+ * File Name:  armVCM4P10_DeBlockPixel.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * 
+ * H.264 luma deblock module
+ * 
+ */
+
+#ifdef DEBUG_ARMVCM4P10_DEBLOCKPIXEL
+#undef DEBUG_ON
+#define DEBUG_ON
+#endif /* DEBUG_ARMVCM4P10_DEBLOCKPIXEL */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+
+/*
+ * Description
+ * Deblock one boundary pixel
+ *
+ * Parameters:
+ * [in]	pQ0         Pointer to pixel q0
+ * [in] Step        Step between pixels q0 and q1
+ * [in] tC0         Edge threshold value
+ * [in] alpha       alpha threshold value
+ * [in] beta        beta threshold value
+ * [in] bS          deblocking strength
+ * [in] ChromaFlag  True for chroma blocks
+ * [out] pQ0        Deblocked pixels
+ * 
+ */
+
+void armVCM4P10_DeBlockPixel(
+    OMX_U8 *pQ0,    /* pointer to the pixel q0 */
+    int Step,       /* step between pixels q0 and q1 */
+    int tC0,        /* edge threshold value */
+    int alpha,      /* alpha */
+    int beta,       /* beta */
+    int bS,         /* deblocking strength */
+    int ChromaFlag
+)
+{
+    int p3, p2, p1, p0, q0, q1, q2, q3;
+    int ap, aq, delta;
+
+    if (bS==0)
+    {
+        return;
+    }
+
+    p3 = pQ0[-4*Step];
+    p2 = pQ0[-3*Step];
+    p1 = pQ0[-2*Step];
+    p0 = pQ0[-1*Step];
+    q0 = pQ0[ 0*Step];
+    q1 = pQ0[ 1*Step];
+    q2 = pQ0[ 2*Step];
+    q3 = pQ0[ 3*Step];
+
+    if (armAbs(p0-q0)>=alpha || armAbs(p1-p0)>=beta || armAbs(q1-q0)>=beta)
+    {
+        DEBUG_PRINTF_10("DeBlockPixel: %02x %02x %02x %02x | %02x %02x %02x %02x alpha=%d beta=%d\n",
+            p3, p2, p1, p0, q0, q1, q2, q3, alpha, beta);
+        return;
+    }
+
+    ap = armAbs(p2 - p0);
+    aq = armAbs(q2 - q0);
+
+    if (bS < 4)
+    {
+        int tC = tC0;
+
+        if (ChromaFlag)
+        {
+            tC++;
+        }
+        else
+        {
+            if (ap < beta)
+            {
+                tC++;
+            }
+            if (aq < beta)
+            {
+                tC++;
+            }
+        }
+    
+        delta = (((q0-p0)<<2) + (p1-q1) + 4) >> 3;
+        delta = armClip(-tC, tC, delta);
+
+        pQ0[-1*Step] = (OMX_U8)armClip(0, 255, p0 + delta);
+        pQ0[ 0*Step] = (OMX_U8)armClip(0, 255, q0 - delta);
+
+        if (ChromaFlag==0 && ap<beta)
+        {
+            delta = (p2 + ((p0+q0+1)>>1) - (p1<<1))>>1;
+            delta = armClip(-tC0, tC0, delta);
+            pQ0[-2*Step] = (OMX_U8)(p1 + delta);
+        }
+
+        if (ChromaFlag==0 && aq<beta)
+        {
+            delta = (q2 + ((p0+q0+1)>>1) - (q1<<1))>>1;
+            delta = armClip(-tC0, tC0, delta);
+            pQ0[ 1*Step] = (OMX_U8)(q1 + delta);
+        }
+    }
+    else /* bS==4 */
+    {
+        if (ChromaFlag==0 && ap<beta && armAbs(p0-q0)<((alpha>>2)+2))
+        {
+            pQ0[-1*Step] = (OMX_U8)((p2 + 2*p1 + 2*p0 + 2*q0 + q1 + 4)>>3);
+            pQ0[-2*Step] = (OMX_U8)((p2 + p1 + p0 + q0 + 2)>>2);
+            pQ0[-3*Step] = (OMX_U8)((2*p3 + 3*p2 + p1 + p0 + q0 + 4)>>3);
+        }
+        else
+        {
+            pQ0[-1*Step] = (OMX_U8)((2*p1 + p0 + q1 + 2)>>2);
+        }
+
+        if (ChromaFlag==0 && aq<beta && armAbs(p0-q0)<((alpha>>2)+2))
+        {
+            pQ0[ 0*Step] = (OMX_U8)((q2 + 2*q1 + 2*q0 + 2*p0 + p1 + 4)>>3);
+            pQ0[ 1*Step] = (OMX_U8)((q2 + q1 + p0 + q0 + 2)>>2);
+            pQ0[ 2*Step] = (OMX_U8)((2*q3 + 3*q2 + q1 + q0 + p0 + 4)>>3);
+        }
+        else
+        {
+            pQ0[ 0*Step] = (OMX_U8)((2*q1 + q0 + p1 + 2)>>2);
+        }
+    }
+
+    DEBUG_PRINTF_13("DeBlockPixel: %02x %02x %02x %02x | %02x %02x %02x %02x bS=%d -> %02x %02x %02x %02x\n",
+        p3, p2, p1, p0, q0, q1, q2, q3, bS,
+        pQ0[-2*Step], pQ0[-1*Step],pQ0[0*Step],pQ0[1*Step]);
+
+}
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_DecodeCoeffsToPair.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_DecodeCoeffsToPair.c
new file mode 100644
index 0000000..7616add
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_DecodeCoeffsToPair.c
@@ -0,0 +1,267 @@
+/* ----------------------------------------------------------------
+ *
+ * 
+ * File Name:  armVCM4P10_DecodeCoeffsToPair.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * 
+ * H.264 decode coefficients module
+ * 
+ */
+ 
+#ifdef DEBUG_ARMVCM4P10_DECODECOEFFSTOPAIR
+#undef DEBUG_ON
+#define DEBUG_ON
+#endif
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armCOMM_Bitstream.h"
+#include "armVCM4P10_CAVLCTables.h"
+
+/* 4x4 DeZigZag table */
+
+static const OMX_U8 armVCM4P10_ZigZag[16] =
+{
+    0, 1, 4, 8, 5, 2, 3, 6, 9, 12, 13, 10, 7, 11, 14, 15
+};
+
+/*
+ * Description:
+ * This function perform the work required by the OpenMAX
+ * DecodeCoeffsToPair function and DecodeChromaDCCoeffsToPair.
+ * Since most of the code is common we share it here.
+ *
+ * Parameters:
+ * [in]	ppBitStream		Double pointer to current byte in bit stream buffer
+ * [in]	pOffset			Pointer to current bit position in the byte pointed
+ *								to by *ppBitStream
+ * [in]	sMaxNumCoeff	Maximum number of non-zero coefficients in current
+ *								block (4,15 or 16)
+ * [in]	nTable          Table number (0 to 4) according to the five columns
+ *                      of Table 9-5 in the H.264 spec
+ * [out]	ppBitStream		*ppBitStream is updated after each block is decoded
+ * [out]	pOffset			*pOffset is updated after each block is decoded
+ * [out]	pNumCoeff		Pointer to the number of nonzero coefficients in
+ *								this block
+ * [out]	ppPosCoefbuf	Double pointer to destination residual
+ *								coefficient-position pair buffer
+ * Return Value:
+ * Standard omxError result. See enumeration for possible result codes.
+
+ */
+
+OMXResult armVCM4P10_DecodeCoeffsToPair(
+     const OMX_U8** ppBitStream,
+     OMX_S32* pOffset,
+     OMX_U8* pNumCoeff,
+     OMX_U8  **ppPosCoefbuf,
+     OMX_INT nTable,
+     OMX_INT sMaxNumCoeff        
+ )
+{
+    int CoeffToken, TotalCoeff, TrailingOnes;
+    int Level, LevelCode, LevelPrefix, LevelSuffix, LevelSuffixSize;
+    int SuffixLength, Run, ZerosLeft,CoeffNum;
+    int i, Flags;
+    OMX_U8 *pPosCoefbuf = *ppPosCoefbuf;
+    OMX_S16 pLevel[16];
+    OMX_U8  pRun[16];
+
+    CoeffToken = armUnPackVLC32(ppBitStream, pOffset, armVCM4P10_CAVLCCoeffTokenTables[nTable]);
+    armRetDataErrIf(CoeffToken == ARM_NO_CODEBOOK_INDEX, OMX_Sts_Err);
+
+    TrailingOnes = armVCM4P10_CAVLCTrailingOnes[CoeffToken];
+    TotalCoeff   = armVCM4P10_CAVLCTotalCoeff[CoeffToken];
+    *pNumCoeff   = (OMX_U8)TotalCoeff;
+
+    DEBUG_PRINTF_2("TotalCoeff = %d, TrailingOnes = %d\n", TotalCoeff, TrailingOnes);
+
+    if (TotalCoeff == 0)
+    {
+        /* Nothing to do */
+        return OMX_Sts_NoErr;
+    }
+
+    /* Decode trailing ones */
+    for (i=TotalCoeff-1; i>=TotalCoeff-TrailingOnes; i--)
+    {
+        if (armGetBits(ppBitStream, pOffset, 1))
+        {
+            Level = -1;
+        }
+        else
+        {
+            Level = +1;
+        }
+        pLevel[i] = (OMX_S16)Level;
+
+        DEBUG_PRINTF_2("Level[%d] = %d\n", i, pLevel[i]);
+    }
+
+    /* Decode (non zero) level values */
+    SuffixLength = 0;
+    if (TotalCoeff>10 && TrailingOnes<3)
+    {
+        SuffixLength=1;
+    }
+    for ( ; i>=0; i--)
+    {
+        LevelPrefix = armUnPackVLC32(ppBitStream, pOffset, armVCM4P10_CAVLCLevelPrefix);
+        armRetDataErrIf(LevelPrefix == ARM_NO_CODEBOOK_INDEX, OMX_Sts_Err);
+
+        LevelSuffixSize = SuffixLength;
+        if (LevelPrefix==14 && SuffixLength==0)
+        {
+            LevelSuffixSize = 4;
+        }
+        if (LevelPrefix==15)
+        {
+            LevelSuffixSize = 12;
+        }
+        
+        LevelSuffix = 0;
+        if (LevelSuffixSize > 0)
+        {
+            LevelSuffix = armGetBits(ppBitStream, pOffset, LevelSuffixSize);
+        }
+
+        LevelCode = (LevelPrefix << SuffixLength) + LevelSuffix;
+
+
+        if (LevelPrefix==15 && SuffixLength==0)
+        {
+            LevelCode += 15;
+        }
+
+        /* LevelCode = 2*(magnitude-1) + sign */
+
+        if (i==TotalCoeff-1-TrailingOnes && TrailingOnes<3)
+        {
+            /* Level magnitude can't be 1 */
+            LevelCode += 2;
+        }
+        if (LevelCode & 1)
+        {
+            /* 2a+1 maps to -a-1 */
+            Level = (-LevelCode-1)>>1;
+        }
+        else
+        {
+            /* 2a+0 maps to +a+1 */
+            Level = (LevelCode+2)>>1;
+        }
+        pLevel[i] = (OMX_S16)Level;
+
+        DEBUG_PRINTF_2("Level[%d] = %d\n", i, pLevel[i]);
+
+        if (SuffixLength==0)
+        {
+            SuffixLength=1;
+        }
+        if ( ((LevelCode>>1)+1)>(3<<(SuffixLength-1)) && SuffixLength<6 )
+        {
+            SuffixLength++;
+        }
+    }
+
+    /* Decode run values */
+    ZerosLeft = 0;
+    if (TotalCoeff < sMaxNumCoeff)
+    {
+        /* Decode TotalZeros VLC */
+        if (sMaxNumCoeff==4)
+        {
+            ZerosLeft = armUnPackVLC32(ppBitStream, pOffset, armVCM4P10_CAVLCTotalZeros2x2Tables[TotalCoeff-1]);
+            armRetDataErrIf(ZerosLeft ==ARM_NO_CODEBOOK_INDEX , OMX_Sts_Err);
+        }
+        else
+        {
+            ZerosLeft = armUnPackVLC32(ppBitStream, pOffset, armVCM4P10_CAVLCTotalZeroTables[TotalCoeff-1]);
+             armRetDataErrIf(ZerosLeft ==ARM_NO_CODEBOOK_INDEX , OMX_Sts_Err);
+	    }
+    }
+
+    DEBUG_PRINTF_1("TotalZeros = %d\n", ZerosLeft);
+
+	CoeffNum=ZerosLeft+TotalCoeff-1;
+
+    for (i=TotalCoeff-1; i>0; i--)
+    {
+        Run = 0;
+        if (ZerosLeft > 0)
+        {
+            int Table = ZerosLeft;
+            if (Table > 6)
+            {
+                Table = 7;
+            }
+            Run = armUnPackVLC32(ppBitStream, pOffset, armVCM4P10_CAVLCRunBeforeTables[Table-1]);
+            armRetDataErrIf(Run == ARM_NO_CODEBOOK_INDEX, OMX_Sts_Err);
+        }
+        pRun[i] = (OMX_U8)Run;
+
+        DEBUG_PRINTF_2("Run[%d] = %d\n", i, pRun[i]);
+
+        ZerosLeft -= Run;
+    }
+    pRun[0] = (OMX_U8)ZerosLeft;
+
+    DEBUG_PRINTF_1("Run[0] = %d\n", pRun[i]);
+
+
+    /* Fill in coefficients */
+	    
+    if (sMaxNumCoeff==15)
+    {
+        CoeffNum++; /* Skip the DC position */
+    }
+	
+	/*for (i=0;i<TotalCoeff;i++)
+		CoeffNum += pRun[i]+1;*/
+    
+	for (i=(TotalCoeff-1); i>=0; i--)
+    {
+        /*CoeffNum += pRun[i]+1;*/
+        Level     = pLevel[i];
+
+        DEBUG_PRINTF_2("Coef[%d] = %d\n", CoeffNum, Level);
+
+        Flags = CoeffNum;
+		CoeffNum -= (pRun[i]+1);
+        if (sMaxNumCoeff>4)
+        {
+            /* Perform 4x4 DeZigZag */
+            Flags = armVCM4P10_ZigZag[Flags];
+        }
+        if (i==0)
+        {   
+            /* End of block flag */
+            Flags += 0x20;
+        }
+        if (Level<-128 || Level>127)
+        {
+            /* Overflow flag */
+            Flags += 0x10;
+        }
+        
+        *pPosCoefbuf++ = (OMX_U8)(Flags);
+        *pPosCoefbuf++ = (OMX_U8)(Level & 0xFF);
+        if (Flags & 0x10)
+        {
+            *pPosCoefbuf++ = (OMX_U8)(Level>>8);
+        }
+    }
+
+    *ppPosCoefbuf = pPosCoefbuf;
+
+    return OMX_Sts_NoErr;
+}
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_DequantTables.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_DequantTables.c
new file mode 100644
index 0000000..d9c2541
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_DequantTables.c
@@ -0,0 +1,45 @@
+/* ----------------------------------------------------------------
+ *
+ * 
+ * File Name:  armVCM4P10_DequantTables.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * H.264 inverse quantize tables
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+#include "armVC.h"
+
+
+const OMX_U8 armVCM4P10_PosToVCol4x4[16] = 
+{
+    0, 2, 0, 2,
+    2, 1, 2, 1,
+    0, 2, 0, 2,
+    2, 1, 2, 1
+};
+
+const OMX_U8 armVCM4P10_PosToVCol2x2[4] = 
+{
+    0, 2,
+    2, 1
+};
+
+const OMX_U8 armVCM4P10_VMatrix[6][3] =
+{
+    { 10, 16, 13 },
+    { 11, 18, 14 },
+    { 13, 20, 16 },
+    { 14, 23, 18 },
+    { 16, 25, 20 },
+    { 18, 29, 23 }
+};
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_FwdTransformResidual4x4.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_FwdTransformResidual4x4.c
new file mode 100644
index 0000000..93d54c3
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_FwdTransformResidual4x4.c
@@ -0,0 +1,78 @@
+/* ----------------------------------------------------------------
+ *
+ * 
+ * File Name:  armVCM4P10_FwdTransformResidual4x4.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * H.264 transform module
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+ 
+/*
+ * Description:
+ * Forward Transform Residual 4x4 Coefficients
+ *
+ * Parameters:
+ * [in]  pSrc		Source 4x4 block
+ * [out] pDst		Destination 4x4 block
+ *
+ */
+void armVCM4P10_FwdTransformResidual4x4(OMX_S16* pDst, OMX_S16 *pSrc)
+{
+    int i;
+
+    /* Transform rows */
+    for (i=0; i<16; i+=4)
+    {
+        int d0 = pSrc[i+0];
+        int d1 = pSrc[i+1];
+        int d2 = pSrc[i+2];
+        int d3 = pSrc[i+3];
+        int e0 = d0 + d3;
+        int e1 = d0 - d3;
+        int e2 = d1 + d2;
+        int e3 = d1 - d2;
+        int f0 = e0 + e2;
+        int f1 = (e1 << 1) + e3;
+        int f2 = e0 - e2;
+        int f3 = e1 - (e3 << 1);
+        pDst[i+0] = (OMX_S16)f0;
+        pDst[i+1] = (OMX_S16)f1;
+        pDst[i+2] = (OMX_S16)f2;
+        pDst[i+3] = (OMX_S16)f3;
+    }
+
+    /* Transform columns */
+    for (i=0; i<4; i++)
+    {
+        int f0 = pDst[i+0];
+        int f1 = pDst[i+4];
+        int f2 = pDst[i+8];
+        int f3 = pDst[i+12];
+        int g0 = f0 + f3;
+        int g1 = f0 - f3;
+        int g2 = f1 + f2;
+        int g3 = f1 - f2;
+        int h0 = g0 + g2;
+        int h1 = (g1 << 1) + g3;
+        int h2 = g0 - g2;
+        int h3 = g1 - (g3 << 1);
+        pDst[i+0] = (OMX_S16) h0;
+        pDst[i+4] = (OMX_S16) h1;
+        pDst[i+8] = (OMX_S16) h2;
+        pDst[i+12] = (OMX_S16) h3;
+    }
+}
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_InterpolateHalfDiag_Luma.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_InterpolateHalfDiag_Luma.c
new file mode 100644
index 0000000..8732f4f
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_InterpolateHalfDiag_Luma.c
@@ -0,0 +1,106 @@
+/**
+ * 
+ * File Name:  armVCM4P10_InterpolateHalfDiag_Luma.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * Description:
+ * This functions will help to calculate Half Pel luma interpolation
+ * 
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+
+
+/**
+ * Function: armVCM4P10_InterpolateHalfDiag_Luma
+ * 
+ * Description:
+ * This function performs interpolation for (1/2, 1/2)  positions 
+ * around a full-pel position.
+ *
+ * Remarks:
+ *
+ *  [in]    pSrc        Pointer to top-left corner of block used to interpolate 
+ *                      in the reconstructed frame plane
+ *  [in]    iSrcStep    Step of the source buffer.
+ *  [in]    iDstStep    Step of the destination(interpolation) buffer.
+ *  [in]    iWidth      Width of the current block
+ *  [in]    iHeight     Height of the current block
+ *  [out]   pDst        Pointer to the interpolation buffer of the (1/2,1/2)-pel
+ *
+ * Return Value:
+ * Standard OMXResult value.
+ *
+ */
+
+OMXResult armVCM4P10_InterpolateHalfDiag_Luma(  
+        const OMX_U8*     pSrc, 
+        OMX_U32     iSrcStep, 
+        OMX_U8*     pDst, 
+        OMX_U32     iDstStep,
+        OMX_U32     iWidth, 
+        OMX_U32     iHeight
+)
+{
+    OMX_S32     HalfCoeff, pos;
+    OMX_S16     Buf [21 * 16];  /* 21 rows by 16 pixels per row */
+    OMX_U32     y, x;
+
+    /* check for argument error */
+    armRetArgErrIf(pSrc == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pDst == NULL, OMX_Sts_BadArgErr)
+
+    /*
+     * Intermediate values will be 1/2 pel at Horizontal direction
+     * Starting at (0.5, -2) at top extending to (0.5, height + 3) at bottom
+     * Buf contains a 2D array of size (iWidth)X(iHeight + 5)
+     */
+    for (y = 0; y < iHeight + 5; y++)
+    {
+        for (x = 0; x < iWidth; x++)
+        {
+            pos = (y-2) * iSrcStep + x;
+            HalfCoeff = 
+                pSrc [pos - 2] - 
+                5 * pSrc [pos - 1] + 
+                20 * pSrc [pos] + 
+                20 * pSrc [pos + 1] - 
+                5 * pSrc [pos + 2] + 
+                pSrc [pos + 3];
+            Buf [y * iWidth + x] = (OMX_S16)HalfCoeff;
+        } /* x */
+    } /* y */
+
+    /* Vertical interpolate */
+    for (y = 0; y < iHeight; y++)
+    {
+        for (x = 0; x < iWidth; x++)
+        {
+            pos = y * iWidth + x;
+            HalfCoeff = 
+                Buf [pos] - 
+                5 * Buf [pos + 1 * iWidth] + 
+                20 * Buf [pos + 2 * iWidth] + 
+                20 * Buf [pos + 3 * iWidth] - 
+                5 * Buf [pos + 4 * iWidth] + 
+                Buf [pos + 5 * iWidth];
+
+            HalfCoeff = (HalfCoeff + 512) >> 10;
+            HalfCoeff = armClip(0, 255, HalfCoeff);
+
+            pDst [y * iDstStep + x] = (OMX_U8) HalfCoeff;
+        }
+    }
+        
+    return OMX_Sts_NoErr;
+}
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_InterpolateHalfHor_Luma.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_InterpolateHalfHor_Luma.c
new file mode 100644
index 0000000..89c0079
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_InterpolateHalfHor_Luma.c
@@ -0,0 +1,82 @@
+/**
+ * 
+ * File Name:  armVCM4P10_InterpolateHalfHor_Luma.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * Description:
+ * This functions will help to calculate Half Pel luma interpolation
+ * 
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+
+/**
+ * Function: armVCM4P10_InterpolateHalfHor_Luma
+ *
+ * Description:
+ * This function performs interpolation for horizontal 1/2-pel positions
+ *
+ * Remarks:
+ *
+ *  [in]    pSrc        Pointer to top-left corner of block used to interpolate 
+ *                      in the reconstructed frame plane
+ *  [in]    iSrcStep    Step of the source buffer.
+ *  [in]    iDstStep    Step of the destination(interpolation) buffer.
+ *  [in]    iWidth      Width of the current block
+ *  [in]    iHeight     Height of the current block
+ *  [out]   pDst        Pointer to the interpolation buffer of the 1/2-pel 
+ *
+ * Return Value:
+ * Standard OMXResult value.
+ *
+ */
+
+OMXResult armVCM4P10_InterpolateHalfHor_Luma(
+        const OMX_U8*     pSrc, 
+        OMX_U32     iSrcStep, 
+        OMX_U8*     pDst, 
+        OMX_U32     iDstStep, 
+        OMX_U32     iWidth, 
+        OMX_U32     iHeight
+)
+{
+    OMX_INT     x, y;
+    OMX_S32     HalfCoeff, pos;
+
+    /* check for argument error */
+    armRetArgErrIf(pSrc == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pDst == NULL, OMX_Sts_BadArgErr)
+
+    for (y = 0; y < iHeight; y++)
+    {
+        for (x = 0; x < iWidth; x++)
+        {
+            pos = y * iSrcStep + x;
+            HalfCoeff = 
+                pSrc [pos - 2] - 
+                5 * pSrc [pos - 1] + 
+                20 * pSrc [pos] + 
+                20 * pSrc [pos + 1] - 
+                5 * pSrc [pos + 2] + 
+                pSrc [pos + 3];
+
+            HalfCoeff = (HalfCoeff + 16) >> 5;
+            HalfCoeff = armClip(0, 255, HalfCoeff);
+
+            pDst [y * iDstStep + x] = HalfCoeff;
+        } /* x */
+    } /* y */
+
+    return OMX_Sts_NoErr;
+}
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_InterpolateHalfVer_Luma.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_InterpolateHalfVer_Luma.c
new file mode 100644
index 0000000..f7ecfc5
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_InterpolateHalfVer_Luma.c
@@ -0,0 +1,84 @@
+/**
+ * 
+ * File Name:  armVCM4P10_InterpolateHalfVer_Luma.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * Description:
+ * This functions will help to calculate Half Pel luma interpolation
+ * 
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+
+/**
+ * Function: armVCM4P10_InterpolateHalfVer_Luma
+ * 
+ * Description:
+ * This function performs interpolation for vertical 1/2-pel positions 
+ * around a full-pel position.
+ *
+ * Remarks:
+ *
+ *  [in]    pSrc        Pointer to top-left corner of block used to interpolate 
+ *                      in the reconstructed frame plane
+ *  [in]    iSrcStep    Step of the source buffer.
+ *  [in]    iDstStep    Step of the destination(interpolation) buffer.
+ *  [in]    iWidth      Width of the current block
+ *  [in]    iHeight     Height of the current block
+ *  [out]   pDst        Pointer to the interpolation buffer of the 1/2-pel
+ *
+ * Return Value:
+ * Standard OMXResult value.
+ *
+ */
+
+OMXResult armVCM4P10_InterpolateHalfVer_Luma(   
+     const OMX_U8*    pSrc, 
+     OMX_U32    iSrcStep, 
+     OMX_U8*    pDst,
+     OMX_U32    iDstStep, 
+     OMX_U32    iWidth, 
+     OMX_U32    iHeight
+)
+{
+    OMX_S32     HalfCoeff, pos;
+    OMX_INT     y, x;
+
+    /* check for argument error */
+    armRetArgErrIf(pSrc == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pDst == NULL, OMX_Sts_BadArgErr)
+
+
+    for (y = 0; y < iHeight; y++)
+    {
+        for (x = 0; x < iWidth; x++)
+        {
+            pos = y * iSrcStep + x;
+            HalfCoeff = 
+                pSrc [pos - 2 * iSrcStep] - 
+                5 * pSrc [pos - 1 * iSrcStep] + 
+                20 * pSrc [pos] + 
+                20 * pSrc [pos + 1 * iSrcStep] - 
+                5 * pSrc [pos + 2 * iSrcStep] + 
+                pSrc [pos + 3 * iSrcStep];
+
+            HalfCoeff = (HalfCoeff + 16) >> 5;
+            HalfCoeff = armClip(0, 255, HalfCoeff);
+
+            pDst [y * iDstStep + x] = (OMX_U8) HalfCoeff;
+        }
+    }
+    
+    return OMX_Sts_NoErr;
+}
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_Interpolate_Chroma.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_Interpolate_Chroma.c
new file mode 100644
index 0000000..1507d23
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_Interpolate_Chroma.c
@@ -0,0 +1,109 @@
+/**
+ * 
+ * File Name:  armVCM4P10_Interpolate_Chroma.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * Description:
+ * This function will calculate interpolation for chroma components
+ * 
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+
+#include "armCOMM.h"
+
+/**
+ * Function: armVCM4P10_Interpolate_Chroma
+ *
+ * Description:
+ * This function performs interpolation for chroma components.
+ *
+ * Remarks:
+ *
+ *  [in]    pSrc            Pointer to top-left corner of block used to 
+ *                                              interpolate in the reconstructed frame plane
+ *  [in]    iSrcStep    Step of the source buffer.
+ *  [in]    iDstStep    Step of the destination(interpolation) buffer.
+ *  [in]    iWidth      Width of the current block
+ *  [in]    iHeight     Height of the current block
+ *  [in]    dx              Fractional part of horizontal motion vector 
+ *                                              component in 1/8 pixel unit (0~7) 
+ *  [in]    dy              Fractional part of vertical motion vector 
+ *                                              component in 1/8 pixel unit (0~7)
+ *  [out]   pDst            Pointer to the interpolation buffer
+ *
+ * Return Value:
+ * Standard OMXResult value.
+ *
+ */
+ OMXResult armVCM4P10_Interpolate_Chroma(
+        OMX_U8      *pSrc,
+        OMX_U32     iSrcStep,
+        OMX_U8      *pDst,
+        OMX_U32     iDstStep,
+        OMX_U32     iWidth,
+        OMX_U32     iHeight,
+        OMX_U32     dx,
+        OMX_U32     dy
+)
+{
+    OMX_U32     EightMinusdx = 8 - dx;
+    OMX_U32     EightMinusdy = 8 - dy;
+    OMX_U32     ACoeff, BCoeff, CCoeff, DCoeff;
+    OMX_U32     x, y;
+
+    /* check for argument error */
+    armRetArgErrIf(pSrc == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pDst == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(dx > 7, OMX_Sts_BadArgErr)
+    armRetArgErrIf(dy > 7, OMX_Sts_BadArgErr)
+    armRetArgErrIf(iSrcStep == 0, OMX_Sts_BadArgErr)
+    armRetArgErrIf(iDstStep == 0, OMX_Sts_BadArgErr)
+    armRetArgErrIf(iWidth == 0, OMX_Sts_BadArgErr)
+    armRetArgErrIf(iHeight == 0, OMX_Sts_BadArgErr)
+    
+    /* if fractionl mv is not (0, 0) */
+    if (dx != 0 || dy != 0)
+    {
+        ACoeff = EightMinusdx * EightMinusdy;
+        BCoeff = dx * EightMinusdy;
+        CCoeff = EightMinusdx * dy;
+        DCoeff = dx * dy;
+
+        for (y = 0; y < iHeight; y++)
+        {
+            for (x = 0; x < iWidth; x++)
+            {
+                pDst [y * iDstStep + x] = (
+                    ACoeff * pSrc [y * iSrcStep + x] +
+                    BCoeff * pSrc [y * iSrcStep + x + 1] +
+                    CCoeff * pSrc [(y + 1) * iSrcStep + x] +
+                    DCoeff * pSrc [(y + 1) * iSrcStep + x + 1] +
+                    32) >> 6;
+            }
+        }
+    }
+    else
+    {
+        for (y = 0; y < iHeight; y++)
+        {
+            for (x = 0; x < iWidth; x++)
+            {
+                pDst [y * iDstStep + x] = pSrc [y * iSrcStep + x];
+            }
+        }
+    }
+
+    return OMX_Sts_NoErr;
+}
+
+/*****************************************************************************
+ *                              END OF FILE
+ *****************************************************************************/
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_Interpolate_Luma.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_Interpolate_Luma.c
new file mode 100644
index 0000000..89978dd
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_Interpolate_Luma.c
@@ -0,0 +1,195 @@
+/**
+ * 
+ * File Name:  armVCM4P10_Interpolate_Luma.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * Description:
+ * This function will calculate interpolation for luma components
+ * 
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+
+/**
+ * Function: armM4P10_Copy
+ *
+ * Description:
+ * This function performs copy a block of data from source to destination
+ *
+ * Remarks:
+ *
+ *  [in]    pSrc            Pointer to top-left corner of block
+ *  [in]    iSrcStep    Step of the source buffer.
+ *  [in]    iDstStep    Step of the destination  buffer.
+ *  [in]    iWidth      Width of the current block
+ *  [in]    iHeight     Height of the current block
+ *  [out]   pDst            Pointer to the interpolation buffer
+ *
+ * Return Value:
+ * Standard OMXResult value.
+ *
+ */
+static OMXResult armM4P10_Copy(  
+    const OMX_U8*     pSrc,
+    OMX_U32     iSrcStep,
+    OMX_U8*     pDst,
+    OMX_U32     iDstStep, 
+    OMX_U32     iWidth,
+    OMX_U32     iHeight
+)
+{
+    OMX_U32     x, y;
+
+    for (y = 0; y < iHeight; y++)
+    {
+        for (x = 0; x < iWidth; x++)
+        {
+            pDst [y * iDstStep + x] = pSrc [y * iSrcStep + x];
+        }
+    }
+
+    return OMX_Sts_NoErr;
+}
+
+/**
+ * Function: armVCM4P10_Interpolate_Luma
+ *
+ * Description:
+ * This function performs interpolation for luma components.
+ *
+ * Remarks:
+ *
+ *  [in]    pSrc            Pointer to top-left corner of block used to 
+ *                                              interpolate in the reconstructed frame plane
+ *  [in]    iSrcStep    Step of the source buffer.
+ *  [in]    iDstStep    Step of the destination(interpolation) buffer.
+ *  [in]    iWidth      Width of the current block
+ *  [in]    iHeight     Height of the current block
+ *  [in]    dx              Fractional part of horizontal motion vector 
+ *                                              component in 1/4 pixel unit (0~3) 
+ *  [in]    dy              Fractional part of vertical motion vector 
+ *                                              component in 1/4 pixel unit (0~3) 
+ *  [out]   pDst            Pointer to the interpolation buffer
+ *
+ * Return Value:
+ * Standard OMXResult value.
+ *
+ */
+
+ OMXResult armVCM4P10_Interpolate_Luma(
+     const OMX_U8     *pSrc,
+     OMX_U32    iSrcStep,
+     OMX_U8     *pDst,
+     OMX_U32    iDstStep,
+     OMX_U32    iWidth,
+     OMX_U32    iHeight,
+     OMX_U32    dx,
+     OMX_U32    dy
+)
+{
+    OMX_U8      pBuf1 [16*16];
+    const OMX_U8      *pSrcHalfHor = pSrc;
+    const OMX_U8      *pSrcHalfVer = pSrc;
+
+    /* check for argument error */
+    armRetArgErrIf(pSrc == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pDst == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(dx > 3, OMX_Sts_BadArgErr)
+    armRetArgErrIf(dy > 3, OMX_Sts_BadArgErr)
+
+    /* Work out positions for half pixel interpolation */
+    if (dx == 3)
+    {
+        pSrcHalfVer += 1;
+    }
+    if (dy == 3)
+    {
+        pSrcHalfHor += iSrcStep;
+    }
+
+    /* Switch on type of pixel
+     * Pixels are named 'a' to 's' as in the H.264 standard
+     */
+    if (dx == 0 && dy == 0)
+    {
+        /* G */
+        armM4P10_Copy(pSrc, iSrcStep, pDst, iDstStep, iWidth, iHeight);
+    }
+    else if (dy == 0)
+    {
+        /* a, b, c */
+        armVCM4P10_InterpolateHalfHor_Luma
+            (pSrcHalfHor, iSrcStep, pDst, iDstStep, iWidth, iHeight);            
+        
+        if (dx == 1 || dx == 3)
+        {
+            armVCCOMM_Average 
+                (pDst, pSrcHalfVer, iDstStep, iSrcStep, pDst, iDstStep, iWidth, iHeight);
+        }
+    }
+    else if (dx == 0)
+    {
+        /* d, h, n */
+        armVCM4P10_InterpolateHalfVer_Luma
+            (pSrcHalfVer, iSrcStep, pDst, iDstStep, iWidth, iHeight);
+
+        if (dy == 1 || dy == 3)
+        {
+            armVCCOMM_Average 
+                (pDst, pSrcHalfHor, iDstStep, iSrcStep, pDst, iDstStep, iWidth, iHeight);
+        }
+    }
+    else if (dx == 2 || dy == 2)
+    {
+        /* j */
+        armVCM4P10_InterpolateHalfDiag_Luma
+            (pSrc, iSrcStep, pDst, iDstStep, iWidth, iHeight);
+
+        if (dx == 1 || dx == 3)
+        {
+            /* i, k */
+            armVCM4P10_InterpolateHalfVer_Luma
+                (pSrcHalfVer, iSrcStep, pBuf1, iWidth, iWidth, iHeight);
+                
+            armVCCOMM_Average 
+                (pDst, pBuf1, iDstStep, iWidth, pDst, iDstStep, iWidth, iHeight);
+        }
+        if (dy == 1 || dy == 3)
+        {
+            /* f,q */
+            armVCM4P10_InterpolateHalfHor_Luma
+                (pSrcHalfHor, iSrcStep, pBuf1, iWidth, iWidth, iHeight);
+
+            armVCCOMM_Average 
+                (pDst, pBuf1, iDstStep, iWidth, pDst, iDstStep, iWidth, iHeight);
+        }
+    }
+    else /* dx=1,3 and dy=1,3 */
+    {
+        /* e, g, p, r */
+        armVCM4P10_InterpolateHalfHor_Luma
+            (pSrcHalfHor, iSrcStep, pBuf1, iWidth, iWidth, iHeight);
+
+        armVCM4P10_InterpolateHalfVer_Luma
+            (pSrcHalfVer, iSrcStep, pDst, iDstStep, iWidth, iHeight);
+
+        armVCCOMM_Average 
+            (pBuf1, pDst, iWidth, iDstStep, pDst, iDstStep, iWidth, iHeight);
+    }
+
+    return OMX_Sts_NoErr;
+}
+
+/*****************************************************************************
+ *                              END OF FILE
+ *****************************************************************************/
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_PredictIntraDC4x4.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_PredictIntraDC4x4.c
new file mode 100644
index 0000000..b713073
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_PredictIntraDC4x4.c
@@ -0,0 +1,88 @@
+/* ----------------------------------------------------------------
+ *
+ * 
+ * File Name:  armVCM4P10_PredictIntraDC4x4.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * H.264 4x4 intra prediction module
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+
+/*
+ * Description:
+ * Perform DC style intra prediction, averaging upper and left block
+ *
+ * Parameters:
+ * [in]	pSrcLeft		Pointer to the buffer of 16 left coefficients:
+ *								p[x, y] (x = -1, y = 0..3)
+ * [in]	pSrcAbove		Pointer to the buffer of 16 above coefficients:
+ *								p[x,y] (x = 0..3, y = -1)
+ * [in]	leftStep		Step of left coefficient buffer
+ * [in]	dstStep			Step of the destination buffer
+ * [in]	availability	Neighboring 16x16 MB availability flag
+ * [out]	pDst			Pointer to the destination buffer
+ *
+ * Return Value:
+ * None
+ */
+
+void armVCM4P10_PredictIntraDC4x4(
+     const OMX_U8* pSrcLeft,
+     const OMX_U8 *pSrcAbove,
+     OMX_U8* pDst,
+     OMX_INT leftStep,
+     OMX_INT dstStep,
+     OMX_S32 availability        
+)
+{
+    int x, y, Sum=0, Count = 0;
+
+    if (availability & OMX_VC_LEFT)
+    {
+        for (y=0; y<4; y++)
+        {
+            Sum += pSrcLeft[y*leftStep];
+        }
+        Count++;
+    }
+    if (availability & OMX_VC_UPPER)
+    {
+        for (x=0; x<4; x++)
+        {
+            Sum += pSrcAbove[x];
+        }
+        Count++;
+    }
+    if (Count==0)
+    {
+        Sum = 128;
+    }
+    else if (Count==1)
+    {
+        Sum = (Sum + 2) >> 2;
+    }
+    else /* Count = 2 */
+    {
+        Sum = (Sum + 4) >> 3;
+    }
+    for (y=0; y<4; y++)
+    {
+        for (x=0; x<4; x++)
+        {
+            pDst[y*dstStep+x] = (OMX_U8)Sum;
+        }
+    }
+}
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_QuantTables.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_QuantTables.c
new file mode 100644
index 0000000..f0b5bb0
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_QuantTables.c
@@ -0,0 +1,31 @@
+/* ----------------------------------------------------------------
+ *
+ * 
+ * File Name:  armVCM4P10_QuantTables.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * H.264 inverse quantize tables
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armVC.h"
+
+const OMX_U32 armVCM4P10_MFMatrix[6][3] =
+{
+    {13107, 5243, 8066},
+    {11916, 4660, 7490},
+    {10082, 4194, 6554},
+    { 9362, 3647, 5825},
+    { 8192, 3355, 5243},
+    { 7282, 2893, 4559}
+}; 
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_SADQuar.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_SADQuar.c
new file mode 100644
index 0000000..a41e04b
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_SADQuar.c
@@ -0,0 +1,84 @@
+/**
+ * 
+ * File Name:  armVCM4P10_SADQuar.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * Description:
+ * This function will calculate SAD of pSrc with average of two Ref blocks
+ * 
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+
+#include "armVC.h"
+#include "armCOMM.h"
+
+/**
+ * Function: armVCM4P10_SADQuar
+ *
+ * Description:
+ * This function calculates the SAD between one block (pSrc) and the 
+ * average of the other two (pSrcRef0 and pSrcRef1)
+ *
+ * Remarks:
+ *
+ * [in]		pSrc				Pointer to the original block
+ * [in]		pSrcRef0		Pointer to reference block 0
+ * [in]		pSrcRef1		Pointer to reference block 1
+ * [in]		iSrcStep 		Step of the original block buffer
+ * [in]		iRefStep0		Step of reference block 0 
+ * [in]		iRefStep1 	Step of reference block 1 
+ * [in]		iHeight			Height of the block
+ * [in]		iWidth			Width of the block
+ * [out]	pDstSAD			Pointer of result SAD
+ *
+ * Return Value:
+ * Standard OMXResult value.
+ *
+ */
+OMXResult armVCM4P10_SADQuar(
+	const OMX_U8* 	pSrc,
+    const OMX_U8* 	pSrcRef0,
+	const OMX_U8* 	pSrcRef1,	
+    OMX_U32 	iSrcStep,
+    OMX_U32		iRefStep0,
+    OMX_U32		iRefStep1,
+    OMX_U32*	pDstSAD,
+    OMX_U32     iHeight,
+    OMX_U32     iWidth
+)
+{
+    OMX_INT     x, y;
+    OMX_S32     SAD = 0;
+
+    /* check for argument error */
+    armRetArgErrIf(pSrc == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pSrcRef0 == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pSrcRef1 == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pDstSAD == NULL, OMX_Sts_BadArgErr)
+
+    for (y = 0; y < iHeight; y++)
+    {
+        for (x = 0; x < iWidth; x++)
+        {
+            SAD += armAbs(pSrc [y * iSrcStep + x] - ((
+                    pSrcRef0 [y * iRefStep0 + x] + 
+                    pSrcRef1 [y * iRefStep1 + x] + 1) >> 1));
+        }
+    }
+        
+    *pDstSAD = SAD;
+
+    return OMX_Sts_NoErr;
+}
+
+/*****************************************************************************
+ *                              END OF FILE
+ *****************************************************************************/
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_TransformResidual4x4.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_TransformResidual4x4.c
new file mode 100644
index 0000000..f9f756a
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_TransformResidual4x4.c
@@ -0,0 +1,80 @@
+/* ----------------------------------------------------------------
+ *
+ * 
+ * File Name:  armVCM4P10_TransformResidual4x4.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * H.264 transform module
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+ 
+/*
+ * Description:
+ * Transform Residual 4x4 Coefficients
+ *
+ * Parameters:
+ * [in]  pSrc		Source 4x4 block
+ * [out] pDst		Destination 4x4 block
+ *
+ */
+
+void armVCM4P10_TransformResidual4x4(OMX_S16* pDst, OMX_S16 *pSrc)
+{
+    int i;
+
+    /* Transform rows */
+    for (i=0; i<16; i+=4)
+    {
+        int d0 = pSrc[i+0];
+        int d1 = pSrc[i+1];
+        int d2 = pSrc[i+2];
+        int d3 = pSrc[i+3];
+        int e0 = d0 + d2;
+        int e1 = d0 - d2;
+        int e2 = (d1>>1) - d3;
+        int e3 = d1 + (d3>>1);
+        int f0 = e0 + e3;
+        int f1 = e1 + e2;
+        int f2 = e1 - e2;
+        int f3 = e0 - e3;
+        pDst[i+0] = (OMX_S16)f0;
+        pDst[i+1] = (OMX_S16)f1;
+        pDst[i+2] = (OMX_S16)f2;
+        pDst[i+3] = (OMX_S16)f3;
+    }
+
+    /* Transform columns */
+    for (i=0; i<4; i++)
+    {
+        int f0 = pDst[i+0];
+        int f1 = pDst[i+4];
+        int f2 = pDst[i+8];
+        int f3 = pDst[i+12];
+        int g0 = f0 + f2;
+        int g1 = f0 - f2;
+        int g2 = (f1>>1) - f3;
+        int g3 = f1 + (f3>>1);
+        int h0 = g0 + g3;
+        int h1 = g1 + g2;
+        int h2 = g1 - g2;
+        int h3 = g0 - g3;
+        pDst[i+0] = (OMX_S16)((h0+32)>>6);
+        pDst[i+4] = (OMX_S16)((h1+32)>>6);
+        pDst[i+8] = (OMX_S16)((h2+32)>>6);
+        pDst[i+12] = (OMX_S16)((h3+32)>>6);
+    }
+}
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_UnpackBlock2x2.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_UnpackBlock2x2.c
new file mode 100644
index 0000000..dda49f6
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_UnpackBlock2x2.c
@@ -0,0 +1,78 @@
+/* ----------------------------------------------------------------
+ * 
+ * 
+ * File Name:  armVCM4P10_UnpackBlock2x2.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * H.264 inverse quantize and transform helper module
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armVC.h"
+
+/*
+ * Description
+ * Unpack a 2x2 block of coefficient-residual pair values
+ *
+ * Parameters:
+ * [in]	ppSrc	Double pointer to residual coefficient-position pair
+ *						buffer output by CALVC decoding
+ * [out]	ppSrc	*ppSrc is updated to the start of next non empty block
+ * [out]	pDst	Pointer to unpacked 4x4 block
+ */
+
+void armVCM4P10_UnpackBlock2x2(
+     const OMX_U8 **ppSrc,
+     OMX_S16* pDst
+)
+{
+    const OMX_U8 *pSrc = *ppSrc;
+    int i;
+    int Flag, Value;
+
+    for (i=0; i<4; i++)
+    {
+        pDst[i] = 0;
+    }
+
+    do
+    {
+        Flag  = *pSrc++;
+        if (Flag & 0x10)
+        {
+            /* 16 bit */
+            Value = *pSrc++;
+            Value = Value | ((*pSrc++)<<8);
+            if (Value & 0x8000)
+            {
+                Value -= 0x10000;
+            }
+        }
+        else
+        {
+            /* 8 bit */
+            Value = *pSrc++;
+            if (Value & 0x80)
+            {
+                Value -= 0x100;
+            }
+        }
+        i = Flag & 15;
+        pDst[i] = (OMX_S16)Value;
+    }
+    while ((Flag & 0x20)==0);
+
+    *ppSrc = pSrc;
+}
+
+/* End of file */
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_UnpackBlock4x4.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_UnpackBlock4x4.c
new file mode 100644
index 0000000..3c0dcbd
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/armVCM4P10_UnpackBlock4x4.c
@@ -0,0 +1,78 @@
+/* ----------------------------------------------------------------
+ *
+ * 
+ * File Name:  armVCM4P10_UnpackBlock4x4.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * H.264 inverse quantize and transform helper module
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armVC.h"
+
+/*
+ * Description
+ * Unpack a 4x4 block of coefficient-residual pair values
+ *
+ * Parameters:
+ * [in]	ppSrc	Double pointer to residual coefficient-position pair
+ *						buffer output by CALVC decoding
+ * [out]	ppSrc	*ppSrc is updated to the start of next non empty block
+ * [out]	pDst	Pointer to unpacked 4x4 block
+ */
+
+void armVCM4P10_UnpackBlock4x4(
+     const OMX_U8 **ppSrc,
+     OMX_S16* pDst
+)
+{
+    const OMX_U8 *pSrc = *ppSrc;
+    int i;
+    int Flag, Value;
+
+    for (i=0; i<16; i++)
+    {
+        pDst[i] = 0;
+    }
+
+    do
+    {
+        Flag  = *pSrc++;
+        if (Flag & 0x10)
+        {
+            /* 16 bit */
+            Value = *pSrc++;
+            Value = Value | ((*pSrc++)<<8);
+            if (Value & 0x8000)
+            {
+                Value -= 0x10000;
+            }
+        }
+        else
+        {
+            /* 8 bit */
+            Value = *pSrc++;
+            if (Value & 0x80)
+            {
+                Value -= 0x100;
+            }
+        }
+        i = Flag & 15;
+        pDst[i] = (OMX_S16)Value;
+    }
+    while ((Flag & 0x20)==0);
+
+    *ppSrc = pSrc;
+}
+
+/* End of file */
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_Average_4x.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_Average_4x.c
new file mode 100644
index 0000000..ac0d523
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_Average_4x.c
@@ -0,0 +1,84 @@
+/**
+ * 
+ * File Name:  omxVCM4P10_Average_4x.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * Description:
+ * This function will calculate Average of two 4x4 or 4x8 blocks
+ * 
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+
+/**
+ * Function:  omxVCM4P10_Average_4x   (6.3.5.5.3)
+ *
+ * Description:
+ * This function calculates the average of two 4x4, 4x8 blocks.  The result 
+ * is rounded according to (a+b+1)/2. 
+ *
+ * Input Arguments:
+ *   
+ *   pPred0 - Pointer to the top-left corner of reference block 0 
+ *   pPred1 - Pointer to the top-left corner of reference block 1 
+ *   iPredStep0 - Step of reference block 0; must be a multiple of 4. 
+ *   iPredStep1 - Step of reference block 1; must be a multiple of 4. 
+ *   iDstStep - Step of the destination buffer; must be a multiple of 4. 
+ *   iHeight - Height of the blocks; must be either 4 or 8. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstPred - Pointer to the destination buffer. 4-byte alignment required. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: 
+ *           pPred0, pPred1, or pDstPred 
+ *    -    pDstPred is not aligned on a 4-byte boundary 
+ *    -    iPredStep0 <= 0 or iPredStep0 is not a multiple of 4 
+ *    -    iPredStep1 <= 0 or iPredStep1 is not a multiple of 4 
+ *    -    iDstStep <= 0 or iDstStep is not a multiple of 4 
+ *    -    iHeight is not equal to either 4 or 8 
+ *
+ */
+ OMXResult omxVCM4P10_Average_4x (
+	 const OMX_U8* 	    pPred0,
+	 const OMX_U8* 	    pPred1,	
+	 OMX_U32		iPredStep0,
+	 OMX_U32		iPredStep1,
+	 OMX_U8*		pDstPred,
+	 OMX_U32		iDstStep, 
+	 OMX_U32		iHeight
+)
+{
+    /* check for argument error */
+    armRetArgErrIf(pPred0 == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pPred1 == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pDstPred == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf((iHeight != 4) && (iHeight != 8), OMX_Sts_BadArgErr)
+    armRetArgErrIf((iPredStep0 == 0) || (iPredStep0 & 3), OMX_Sts_BadArgErr)
+    armRetArgErrIf((iPredStep1 == 0) || (iPredStep1 & 3), OMX_Sts_BadArgErr)
+    armRetArgErrIf((iDstStep == 0) || (iDstStep & 3), OMX_Sts_BadArgErr)
+    armRetArgErrIf(armNot4ByteAligned(pDstPred), OMX_Sts_BadArgErr)
+
+    return armVCCOMM_Average 
+        (pPred0, pPred1, iPredStep0, iPredStep1, pDstPred, iDstStep, 4, iHeight);
+}
+
+/*****************************************************************************
+ *                              END OF FILE
+ *****************************************************************************/
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_BlockMatch_Half.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_BlockMatch_Half.c
new file mode 100644
index 0000000..c490e10
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_BlockMatch_Half.c
@@ -0,0 +1,191 @@
+/**
+ * 
+ * File Name:  omxVCM4P10_BlockMatch_Half.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Description:
+ * Contains modules for half pel Block matching, 
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armVC.h"
+#include "armCOMM.h"
+
+    
+/**
+ * Function:  omxVCM4P10_BlockMatch_Half   (6.3.5.2.2)
+ *
+ * Description:
+ * Performs a half-pel block match using results from a prior integer search. 
+ *  Returns the best MV and associated cost.  This function estimates the 
+ * half-pixel motion vector by interpolating the integer resolution motion 
+ * vector referenced by the input parameter pSrcDstBestMV, i.e., the initial 
+ * integer MV is generated externally.  The function 
+ * omxVCM4P10_BlockMatch_Integer may be used for integer motion estimation. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcOrgY - Pointer to the current position in original picture plane. If 
+ *            iBlockWidth==4,  4-byte alignment required. If iBlockWidth==8,  
+ *            8-byte alignment required. If iBlockWidth==16, 16-byte alignment 
+ *            required. 
+ *   pSrcRefY - Pointer to the top-left corner of the co-located block in the 
+ *            reference picture  If iBlockWidth==4,  4-byte alignment 
+ *            required.  If iBlockWidth==8,  8-byte alignment required.  If 
+ *            iBlockWidth==16, 16-byte alignment required. 
+ *   nSrcOrgStep - Stride of the original picture plane in terms of full 
+ *            pixels; must be a multiple of iBlockWidth. 
+ *   nSrcRefStep - Stride of the reference picture plane in terms of full 
+ *            pixels 
+ *   iBlockWidth - Width of the current block in terms of full pixels; must 
+ *            be equal to either 4, 8, or 16. 
+ *   iBlockHeight - Height of the current block in terms of full pixels; must 
+ *            be equal to either 4, 8, or 16. 
+ *   nLamda - Lamda factor, used to compute motion cost 
+ *   pMVPred - Predicted MV, represented in terms of 1/4-pel units; used to 
+ *            compute motion cost 
+ *   pSrcDstBestMV - The best MV resulting from a prior integer search, 
+ *            represented in terms of 1/4-pel units 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDstBestMV - Best MV resulting from the half-pel search, expressed in 
+ *            terms of 1/4-pel units 
+ *   pBestCost - Motion cost associated with the best MV; computed as 
+ *            SAD+Lamda*BitsUsedByMV 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    any of the following pointers is NULL: pSrcOrgY, pSrcRefY, 
+ *              pSrcDstBestMV, pMVPred, pBestCost 
+ *    -    iBlockWidth or iBlockHeight are equal to values other than 4, 8, or 16. 
+ *    -    Any alignment restrictions are violated 
+ *
+ */
+ 
+OMXResult omxVCM4P10_BlockMatch_Half(
+    const OMX_U8* pSrcOrgY, 
+    OMX_S32 nSrcOrgStep, 
+    const OMX_U8* pSrcRefY, 
+    OMX_S32 nSrcRefStep, 
+    OMX_U8 iBlockWidth, 
+    OMX_U8 iBlockHeight, 
+    OMX_U32 nLamda, 
+    const OMXVCMotionVector* pMVPred, 
+    OMXVCMotionVector* pSrcDstBestMV, 
+    OMX_S32* pBestCost
+)
+{
+    /* Definitions and Initializations*/
+    OMX_INT     candSAD;
+    OMX_INT     fromX, toX, fromY, toY;
+    /* Offset to the reference at the begining of the bounding box */
+    const OMX_U8      *pTempSrcRefY, *pTempSrcOrgY;
+    OMX_S16     x, y;
+    OMXVCMotionVector diffMV, candMV, integerMV;
+    OMX_U8      interpolY[256];
+
+    /* Argument error checks */
+    armRetArgErrIf((iBlockWidth ==  4) && (!armIs4ByteAligned(pSrcOrgY)), OMX_Sts_BadArgErr);
+    armRetArgErrIf((iBlockWidth ==  8) && (!armIs8ByteAligned(pSrcOrgY)), OMX_Sts_BadArgErr);
+    armRetArgErrIf((iBlockWidth == 16) && (!armIs16ByteAligned(pSrcOrgY)), OMX_Sts_BadArgErr);
+	armRetArgErrIf((iBlockWidth ==  4) && (!armIs4ByteAligned(pSrcRefY)), OMX_Sts_BadArgErr);
+    armRetArgErrIf((iBlockWidth ==  8) && (!armIs8ByteAligned(pSrcRefY)), OMX_Sts_BadArgErr);
+    armRetArgErrIf((iBlockWidth == 16) && (!armIs16ByteAligned(pSrcRefY)), OMX_Sts_BadArgErr);
+    armRetArgErrIf((nSrcOrgStep % iBlockWidth), OMX_Sts_BadArgErr);
+    armRetArgErrIf(pSrcOrgY == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pSrcRefY == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pMVPred == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pSrcDstBestMV == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pBestCost == NULL, OMX_Sts_BadArgErr);
+	armRetArgErrIf(((iBlockWidth!=4)&&(iBlockWidth!=8)&&(iBlockWidth!=16)) , OMX_Sts_BadArgErr);
+	armRetArgErrIf(((iBlockHeight!=4)&&(iBlockHeight!=8)&&(iBlockHeight!=16)) , OMX_Sts_BadArgErr);
+        
+            
+    /* Check for valid region */ 
+    fromX = 1;
+    toX   = 1;
+    fromY = 1;
+    toY   = 1;
+    
+    /* Initialize to max value as a start point */
+    *pBestCost = 0x7fffffff;
+    
+    integerMV.dx = pSrcDstBestMV->dx;
+    integerMV.dy = pSrcDstBestMV->dy;
+    
+    /* Looping on y- axis */
+    for (y = -fromY; y <= toY; y++)
+    {
+        /* Looping on x- axis */
+        for (x = -fromX; x <= toX; x++)
+        {
+            /* Positioning the pointer */
+            pTempSrcRefY = pSrcRefY + (nSrcRefStep * (integerMV.dy/4)) + (integerMV.dx/4);
+            if (x < 0)
+            {
+                pTempSrcRefY = pTempSrcRefY + x;
+            }
+            if (y < 0)
+            {
+                pTempSrcRefY = pTempSrcRefY + (y * nSrcRefStep);
+            }
+            pTempSrcOrgY = pSrcOrgY;
+            
+            /* Prepare cand MV */
+            candMV.dx = integerMV.dx + x * 2;
+            candMV.dy = integerMV.dy + y * 2;
+            
+            /* Interpolate half pel for the current position*/
+            armVCM4P10_Interpolate_Luma(
+                        pTempSrcRefY,
+                        nSrcRefStep,
+                        interpolY,
+                        iBlockWidth,
+                        iBlockWidth,
+                        iBlockHeight,
+                        armAbs(x) * 2,
+                        armAbs(y) * 2);
+            
+            /* Calculate the SAD */
+            armVCCOMM_SAD(	
+                        pTempSrcOrgY,
+                        nSrcOrgStep,
+                        interpolY,
+                        iBlockWidth,
+                        &candSAD,
+                        iBlockHeight,
+                        iBlockWidth);
+ 
+            diffMV.dx = candMV.dx - pMVPred->dx;
+            diffMV.dy = candMV.dy - pMVPred->dy;
+            
+            /* Result calculations */
+            armVCM4P10_CompareMotionCostToMV (
+                        candMV.dx, 
+                        candMV.dy, 
+                        diffMV, 
+                        candSAD, 
+                        pSrcDstBestMV, 
+                        nLamda, 
+                        pBestCost);
+
+        } /* End of x- axis */
+    } /* End of y-axis */
+
+    return OMX_Sts_NoErr;
+
+}
+
+/* End of file */
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_BlockMatch_Integer.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_BlockMatch_Integer.c
new file mode 100644
index 0000000..f7764e1
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_BlockMatch_Integer.c
@@ -0,0 +1,196 @@
+/**
+ * 
+ * File Name:  omxVCM4P10_BlockMatch_Integer.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Description:
+ * Contains modules for Block matching, a full search algorithm
+ * is implemented
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armVC.h"
+#include "armCOMM.h"
+
+/**
+ * Function:  omxVCM4P10_BlockMatch_Integer   (6.3.5.2.1)
+ *
+ * Description:
+ * Performs integer block match.  Returns best MV and associated cost. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcOrgY - Pointer to the top-left corner of the current block. If 
+ *            iBlockWidth==4,  4-byte alignment required. If iBlockWidth==8,  
+ *            8-byte alignment required. If iBlockWidth==16, 16-byte alignment 
+ *            required. 
+ *   pSrcRefY - Pointer to the top-left corner of the co-located block in the 
+ *            reference picture. If iBlockWidth==4,  4-byte alignment 
+ *            required.  If iBlockWidth==8,  8-byte alignment required.  If 
+ *            iBlockWidth==16, 16-byte alignment required. 
+ *   nSrcOrgStep - Stride of the original picture plane, expressed in terms 
+ *            of integer pixels; must be a multiple of iBlockWidth. 
+ *   nSrcRefStep - Stride of the reference picture plane, expressed in terms 
+ *            of integer pixels 
+ *   pRefRect - pointer to the valid reference rectangle inside the reference 
+ *            picture plane 
+ *   nCurrPointPos - position of the current block in the current plane 
+ *   iBlockWidth - Width of the current block, expressed in terms of integer 
+ *            pixels; must be equal to either 4, 8, or 16. 
+ *   iBlockHeight - Height of the current block, expressed in terms of 
+ *            integer pixels; must be equal to either 4, 8, or 16. 
+ *   nLamda - Lamda factor; used to compute motion cost 
+ *   pMVPred - Predicted MV; used to compute motion cost, expressed in terms 
+ *            of 1/4-pel units 
+ *   pMVCandidate - Candidate MV; used to initialize the motion search, 
+ *            expressed in terms of integer pixels 
+ *   pMESpec - pointer to the ME specification structure 
+ *
+ * Output Arguments:
+ *   
+ *   pDstBestMV - Best MV resulting from integer search, expressed in terms 
+ *            of 1/4-pel units 
+ *   pBestCost - Motion cost associated with the best MV; computed as 
+ *            SAD+Lamda*BitsUsedByMV 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    any of the following poitners are NULL:
+ *         pSrcOrgY, pSrcRefY, pRefRect, pMVPred, pMVCandidate, or pMESpec. 
+ *    -    Either iBlockWidth or iBlockHeight are values other than 4, 8, or 16. 
+ *    -    Any alignment restrictions are violated 
+ *
+ */
+ 
+ OMXResult omxVCM4P10_BlockMatch_Integer (
+     const OMX_U8 *pSrcOrgY,
+     OMX_S32 nSrcOrgStep,
+     const OMX_U8 *pSrcRefY,
+     OMX_S32 nSrcRefStep,
+	 const OMXRect *pRefRect,
+	 const OMXVCM4P2Coordinate *pCurrPointPos,
+     OMX_U8 iBlockWidth,
+     OMX_U8 iBlockHeight,
+     OMX_U32 nLamda,
+     const OMXVCMotionVector *pMVPred,
+     const OMXVCMotionVector *pMVCandidate,
+     OMXVCMotionVector *pBestMV,
+     OMX_S32 *pBestCost,
+     void *pMESpec
+)
+{
+    /* Definitions and Initializations*/
+    OMX_INT candSAD;
+    OMX_INT fromX, toX, fromY, toY;
+    /* Offset to the reference at the begining of the bounding box */
+    const OMX_U8 *pTempSrcRefY, *pTempSrcOrgY;
+    OMX_S16 x, y;
+    OMXVCMotionVector diffMV;
+    OMX_S32 nSearchRange;
+    ARMVCM4P10_MESpec *armMESpec = (ARMVCM4P10_MESpec *) pMESpec;
+
+    /* Argument error checks */
+    armRetArgErrIf((iBlockWidth ==  4) && (!armIs4ByteAligned(pSrcOrgY)), OMX_Sts_BadArgErr);
+    armRetArgErrIf((iBlockWidth ==  8) && (!armIs8ByteAligned(pSrcOrgY)), OMX_Sts_BadArgErr);
+    armRetArgErrIf((iBlockWidth == 16) && (!armIs16ByteAligned(pSrcOrgY)), OMX_Sts_BadArgErr);
+	armRetArgErrIf((iBlockWidth ==  4) && (!armIs4ByteAligned(pSrcRefY)), OMX_Sts_BadArgErr);
+    armRetArgErrIf((iBlockWidth ==  8) && (!armIs8ByteAligned(pSrcRefY)), OMX_Sts_BadArgErr);
+    armRetArgErrIf((iBlockWidth == 16) && (!armIs16ByteAligned(pSrcRefY)), OMX_Sts_BadArgErr);
+    armRetArgErrIf(pSrcOrgY == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pSrcRefY == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pMVPred == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pMVCandidate == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pBestMV == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pBestCost == NULL, OMX_Sts_BadArgErr);
+	armRetArgErrIf(((iBlockWidth!=4)&&(iBlockWidth!=8)&&(iBlockWidth!=16)) , OMX_Sts_BadArgErr);
+	armRetArgErrIf(((iBlockHeight!=4)&&(iBlockHeight!=8)&&(iBlockHeight!=16)) , OMX_Sts_BadArgErr);
+    armIgnore (pMESpec);
+
+    if(iBlockWidth == 4)
+    {
+        nSearchRange = armMESpec->MEParams.searchRange4x4;
+    }
+    else if(iBlockWidth == 8)
+    {
+        nSearchRange = armMESpec->MEParams.searchRange8x8;
+    }
+    else
+    {
+        nSearchRange = armMESpec->MEParams.searchRange16x16;
+    }
+    /* Check for valid region */ 
+    fromX = nSearchRange;
+    toX   = nSearchRange;
+    fromY = nSearchRange;
+    toY   = nSearchRange;
+    
+    if ((pCurrPointPos->x - nSearchRange) < pRefRect->x)
+    {
+        fromX =  pCurrPointPos->x - pRefRect->x;
+    }
+
+    if ((pCurrPointPos->x + iBlockWidth + nSearchRange) > (pRefRect->x + pRefRect->width))
+    {
+        toX   = pRefRect->width - (pCurrPointPos->x - pRefRect->x) - iBlockWidth;
+    }
+
+    if ((pCurrPointPos->y - nSearchRange) < pRefRect->y)
+    {
+        fromY = pCurrPointPos->y - pRefRect->y;
+    }
+
+    if ((pCurrPointPos->y + iBlockWidth + nSearchRange) > (pRefRect->y + pRefRect->height))
+    {
+        toY   = pRefRect->width - (pCurrPointPos->y - pRefRect->y) - iBlockWidth;
+    }
+    
+    pBestMV->dx = -fromX * 4;
+    pBestMV->dy = -fromY * 4;
+    /* Initialize to max value as a start point */
+    *pBestCost = 0x7fffffff;
+    
+    /* Looping on y- axis */
+    for (y = -fromY; y <= toY; y++)
+    {
+        /* Looping on x- axis */
+        for (x = -fromX; x <= toX; x++)
+        {
+            /* Positioning the pointer */
+            pTempSrcRefY = pSrcRefY + (nSrcRefStep * y) + x;
+            pTempSrcOrgY = pSrcOrgY;
+            
+            /* Calculate the SAD */
+            armVCCOMM_SAD(	
+    	        pTempSrcOrgY,
+    	        nSrcOrgStep,
+    	        pTempSrcRefY,
+    	        nSrcRefStep,
+    	        &candSAD,
+    	        iBlockHeight,
+    	        iBlockWidth);
+    	    
+            diffMV.dx = (x * 4) - pMVPred->dx;
+            diffMV.dy = (y * 4) - pMVPred->dy;
+            
+            /* Result calculations */
+            armVCM4P10_CompareMotionCostToMV ((x * 4), (y * 4), diffMV, candSAD, pBestMV, nLamda, pBestCost);
+
+        } /* End of x- axis */
+    } /* End of y-axis */
+
+    return OMX_Sts_NoErr;
+
+}
+
+/* End of file */
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_BlockMatch_Quarter.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_BlockMatch_Quarter.c
new file mode 100644
index 0000000..513ee25
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_BlockMatch_Quarter.c
@@ -0,0 +1,199 @@
+/**
+ * 
+ * File Name:  omxVCM4P10_BlockMatch_Quarter.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Description:
+ * Contains modules for quater pel Block matching, 
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armVC.h"
+#include "armCOMM.h"
+ 
+    
+/**
+ * Function:  omxVCM4P10_BlockMatch_Quarter   (6.3.5.2.3)
+ *
+ * Description:
+ * Performs a quarter-pel block match using results from a prior half-pel 
+ * search.  Returns the best MV and associated cost.  This function estimates 
+ * the quarter-pixel motion vector by interpolating the half-pel resolution 
+ * motion vector referenced by the input parameter pSrcDstBestMV, i.e., the 
+ * initial half-pel MV is generated externally.  The function 
+ * omxVCM4P10_BlockMatch_Half may be used for half-pel motion estimation. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcOrgY - Pointer to the current position in original picture plane. If 
+ *            iBlockWidth==4,  4-byte alignment required. If iBlockWidth==8,  
+ *            8-byte alignment required. If iBlockWidth==16, 16-byte alignment 
+ *            required. 
+ *   pSrcRefY - Pointer to the top-left corner of the co-located block in the 
+ *            reference picture  If iBlockWidth==4,  4-byte alignment 
+ *            required.  If iBlockWidth==8,  8-byte alignment required.  If 
+ *            iBlockWidth==16, 16-byte alignment required. 
+ *   nSrcOrgStep - Stride of the original picture plane in terms of full 
+ *            pixels; must be a multiple of iBlockWidth. 
+ *   nSrcRefStep - Stride of the reference picture plane in terms of full 
+ *            pixels 
+ *   iBlockWidth - Width of the current block in terms of full pixels; must 
+ *            be equal to either 4, 8, or 16. 
+ *   iBlockHeight - Height of the current block in terms of full pixels; must 
+ *            be equal to either 4, 8, or 16. 
+ *   nLamda - Lamda factor, used to compute motion cost 
+ *   pMVPred - Predicted MV, represented in terms of 1/4-pel units; used to 
+ *            compute motion cost 
+ *   pSrcDstBestMV - The best MV resulting from a prior half-pel search, 
+ *            represented in terms of 1/4 pel units 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDstBestMV - Best MV resulting from the quarter-pel search, expressed 
+ *            in terms of 1/4-pel units 
+ *   pBestCost - Motion cost associated with the best MV; computed as 
+ *            SAD+Lamda*BitsUsedByMV 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    One of more of the following pointers is NULL: 
+ *         pSrcOrgY, pSrcRefY, pSrcDstBestMV, pMVPred, pBestCost 
+ *    -    iBlockWidth or iBlockHeight are equal to values other than 4, 8, or 16. 
+ *    -    Any alignment restrictions are violated 
+ *
+ */
+ 
+OMXResult omxVCM4P10_BlockMatch_Quarter(
+    const OMX_U8* pSrcOrgY, 
+    OMX_S32 nSrcOrgStep, 
+    const OMX_U8* pSrcRefY, 
+    OMX_S32 nSrcRefStep, 
+    OMX_U8 iBlockWidth, 
+    OMX_U8 iBlockHeight, 
+    OMX_U32 nLamda, 
+    const OMXVCMotionVector* pMVPred, 
+    OMXVCMotionVector* pSrcDstBestMV, 
+    OMX_S32* pBestCost
+)
+{
+    /* Definitions and Initializations*/
+    OMX_INT     candSAD;
+    OMX_INT     fromX, toX, fromY, toY;
+    /* Offset to the reference at the begining of the bounding box */
+    const OMX_U8      *pTempSrcRefY, *pTempSrcOrgY;
+    OMX_S16     x, y;
+    OMXVCMotionVector diffMV, candMV, initialMV;
+    OMX_U8      interpolY[256];
+    OMX_S32     pelPosX, pelPosY;
+
+    /* Argument error checks */
+    armRetArgErrIf((iBlockWidth ==  4) && (!armIs4ByteAligned(pSrcOrgY)), OMX_Sts_BadArgErr);
+    armRetArgErrIf((iBlockWidth ==  8) && (!armIs8ByteAligned(pSrcOrgY)), OMX_Sts_BadArgErr);
+    armRetArgErrIf((iBlockWidth == 16) && (!armIs16ByteAligned(pSrcOrgY)), OMX_Sts_BadArgErr);
+	armRetArgErrIf((iBlockWidth ==  4) && (!armIs4ByteAligned(pSrcRefY)), OMX_Sts_BadArgErr);
+    armRetArgErrIf((iBlockWidth ==  8) && (!armIs8ByteAligned(pSrcRefY)), OMX_Sts_BadArgErr);
+    armRetArgErrIf((iBlockWidth == 16) && (!armIs16ByteAligned(pSrcRefY)), OMX_Sts_BadArgErr);
+    armRetArgErrIf((nSrcOrgStep % iBlockWidth), OMX_Sts_BadArgErr);
+    armRetArgErrIf(pSrcOrgY == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pSrcRefY == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pMVPred == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pSrcDstBestMV == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pBestCost == NULL, OMX_Sts_BadArgErr);
+	armRetArgErrIf(((iBlockWidth!=4)&&(iBlockWidth!=8)&&(iBlockWidth!=16)) , OMX_Sts_BadArgErr);
+	armRetArgErrIf(((iBlockHeight!=4)&&(iBlockHeight!=8)&&(iBlockHeight!=16)) , OMX_Sts_BadArgErr);
+        
+            
+    /* Check for valid region */ 
+    fromX = 1;
+    toX   = 1;
+    fromY = 1;
+    toY   = 1;
+    
+    /* Initialize to max value as a start point */
+    *pBestCost = 0x7fffffff;
+    
+    initialMV.dx = pSrcDstBestMV->dx;
+    initialMV.dy = pSrcDstBestMV->dy;
+    
+    /* Looping on y- axis */
+    for (y = -fromY; y <= toY; y++)
+    {
+        /* Looping on x- axis */
+        for (x = -fromX; x <= toX; x++)
+        {
+            /* Positioning the pointer */
+            pTempSrcRefY = pSrcRefY + (nSrcRefStep * (initialMV.dy/4)) + (initialMV.dx/4);
+            
+            /* Calculating the fract pel position */
+            pelPosX = (initialMV.dx % 4) + x;
+            if (pelPosX < 0) 
+            {
+                pTempSrcRefY = pTempSrcRefY - 1;
+                pelPosX += 4;
+            }
+            pelPosY = (initialMV.dy % 4) + y;
+            if (pelPosY < 0) 
+            {
+                pTempSrcRefY = pTempSrcRefY - (1 * nSrcRefStep);
+                pelPosY += 4;
+            }
+            
+            pTempSrcOrgY = pSrcOrgY; 
+            
+            /* Prepare cand MV */
+            candMV.dx = initialMV.dx + x;
+            candMV.dy = initialMV.dy + y;
+             
+            /* Interpolate Quater pel for the current position*/
+            armVCM4P10_Interpolate_Luma(
+                        pTempSrcRefY,
+                        nSrcRefStep,
+                        interpolY,
+                        iBlockWidth,
+                        iBlockWidth,
+                        iBlockHeight,
+                        pelPosX,
+                        pelPosY);
+            
+            /* Calculate the SAD */
+            armVCCOMM_SAD(	
+                        pTempSrcOrgY,
+                        nSrcOrgStep,
+                        interpolY,
+                        iBlockWidth,
+                        &candSAD,
+                        iBlockHeight,
+                        iBlockWidth);
+ 
+            diffMV.dx = candMV.dx - pMVPred->dx;
+            diffMV.dy = candMV.dy - pMVPred->dy;
+            
+            /* Result calculations */
+            armVCM4P10_CompareMotionCostToMV (
+                        candMV.dx, 
+                        candMV.dy, 
+                        diffMV, 
+                        candSAD, 
+                        pSrcDstBestMV, 
+                        nLamda, 
+                        pBestCost);
+
+        } /* End of x- axis */
+    } /* End of y-axis */
+
+    return OMX_Sts_NoErr;
+
+}
+
+/* End of file */
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_DeblockChroma_I.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_DeblockChroma_I.c
new file mode 100644
index 0000000..a07b1bb
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_DeblockChroma_I.c
@@ -0,0 +1,107 @@
+/* ----------------------------------------------------------------
+ *
+ * 
+ * File Name:  omxVCM4P10_DeblockChroma_I.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * H.264 intra chroma deblock
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+
+/**
+ * Function:  omxVCM4P10_DeblockChroma_I   (6.3.3.3.6)
+ *
+ * Description:
+ * Performs in-place deblocking filtering on all edges of the chroma 
+ * macroblock (16x16). 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - pointer to the input macroblock; must be 8-byte aligned. 
+ *   srcdstStep - step of the arrays; must be a multiple of 8. 
+ *   pAlpha - pointer to a 2x2 array of alpha thresholds, organized as 
+ *            follows: {external vertical edge, internal vertical edge, 
+ *            external horizontal edge, internal horizontal edge }.  Per 
+ *            [ISO14496-10] alpha values must be in the range [0,255]. 
+ *   pBeta - pointer to a 2x2 array of Beta Thresholds, organized as follows: 
+ *            { external vertical edge, internal vertical edge, external 
+ *            horizontal edge, internal horizontal edge }.  Per [ISO14496-10] 
+ *            beta values must be in the range [0,18]. 
+ *   pThresholds - array of size 8x2 of Thresholds (TC0) (values for the left 
+ *            or above edge of each 4x2 or 2x4 block, arranged in vertical 
+ *            block order and then in horizontal block order); must be aligned 
+ *            on a 4-byte boundary. Per [ISO14496-10] values must be in the 
+ *            range [0,25]. 
+ *   pBS - array of size 16x2 of BS parameters (arranged in scan block order 
+ *            for vertical edges and then horizontal edges); valid in the 
+ *            range [0,4] with the following restrictions: i) pBS[i]== 4 may 
+ *            occur only for 0<=i<=3, ii) pBS[i]== 4 if and only if pBS[i^3]== 
+ *            4.  Must be 4-byte aligned. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst - pointer to filtered output macroblock. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments 
+ *    -    one or more of the following pointers is NULL: pSrcDst, pAlpha, 
+ *              pBeta, pThresholds, or pBS. pSrcDst is not 8-byte aligned. 
+ *              either pThresholds or pBS is not 4-byte aligned. 
+ *    -   one or more entries in the table pAlpha[0..3] is outside the range 
+ *              [0,255]. 
+ *    -   one or more entries in the table pBeta[0..3] is outside the range 
+ *              [0,18]. 
+ *    -   one or more entries in the table pThresholds[0..15]is outside of 
+ *              the range [0,25]. 
+ *    -   pBS is out of range, i.e., one of the following conditions is true: 
+ *            pBS[i]<0, pBS[i]>4, pBS[i]==4  for i>=4, or 
+ *            (pBS[i]==4 && pBS[i^3]!=4) for 0<=i<=3. 
+ *    -   srcdstStep is not a multiple of 8. 
+ *
+ */
+OMXResult omxVCM4P10_DeblockChroma_I(
+	OMX_U8* pSrcDst, 
+	OMX_S32 srcdstStep, 
+	const OMX_U8* pAlpha, 
+	const OMX_U8* pBeta, 
+	const OMX_U8* pThresholds,
+    const OMX_U8 *pBS
+)
+{
+    OMXResult errorCode;
+    
+    armRetArgErrIf(pSrcDst == NULL,                 OMX_Sts_BadArgErr);
+    armRetArgErrIf(armNot8ByteAligned(pSrcDst),     OMX_Sts_BadArgErr);
+    armRetArgErrIf(srcdstStep & 7,                  OMX_Sts_BadArgErr);
+    armRetArgErrIf(pAlpha == NULL,                  OMX_Sts_BadArgErr);
+    armRetArgErrIf(pBeta == NULL,                   OMX_Sts_BadArgErr);
+    armRetArgErrIf(pThresholds == NULL,             OMX_Sts_BadArgErr);
+    armRetArgErrIf(armNot4ByteAligned(pThresholds), OMX_Sts_BadArgErr);
+    armRetArgErrIf(pBS == NULL,                     OMX_Sts_BadArgErr);
+    armRetArgErrIf(armNot4ByteAligned(pBS),         OMX_Sts_BadArgErr);
+
+    errorCode = omxVCM4P10_FilterDeblockingChroma_VerEdge_I(
+        pSrcDst, srcdstStep, pAlpha, pBeta, pThresholds, pBS);
+
+    armRetArgErrIf(errorCode != OMX_Sts_NoErr, errorCode)
+    
+    errorCode = omxVCM4P10_FilterDeblockingChroma_HorEdge_I(
+        pSrcDst, srcdstStep, pAlpha+2, pBeta+2, pThresholds+8, pBS+16);
+
+    return errorCode;
+}
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_DeblockLuma_I.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_DeblockLuma_I.c
new file mode 100644
index 0000000..1f3a646
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_DeblockLuma_I.c
@@ -0,0 +1,109 @@
+/* ----------------------------------------------------------------
+ *
+ * 
+ * File Name:  omxVCM4P10_DeblockLuma_I.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * H.264 luma deblock
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+ 
+
+/**
+ * Function:  omxVCM4P10_DeblockLuma_I   (6.3.3.3.5)
+ *
+ * Description:
+ * This function performs in-place deblock filtering the horizontal and 
+ * vertical edges of a luma macroblock (16x16). 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - pointer to the input macroblock; must be 16-byte aligned. 
+ *   srcdstStep - image width; must be a multiple of 16. 
+ *   pAlpha - pointer to a 2x2 table of alpha thresholds, organized as 
+ *            follows: {external vertical edge, internal vertical edge, 
+ *            external horizontal edge, internal horizontal edge }.  Per 
+ *            [ISO14496-10] alpha values must be in the range [0,255]. 
+ *   pBeta - pointer to a 2x2 table of beta thresholds, organized as follows: 
+ *            {external vertical edge, internal vertical edge, external 
+ *            horizontal edge, internal horizontal edge }.  Per [ISO14496-10] 
+ *            beta values must be in the range [0,18]. 
+ *   pThresholds - pointer to a 16x2 table of threshold (TC0), organized as 
+ *            follows: {values for the left or above edge of each 4x4 block, 
+ *            arranged in vertical block order and then in horizontal block 
+ *            order}; must be aligned on a 4-byte boundary.  Per [ISO14496-10] 
+ *            values must be in the range [0,25]. 
+ *   pBS - pointer to a 16x2 table of BS parameters arranged in scan block 
+ *            order for vertical edges and then horizontal edges; valid in the 
+ *            range [0,4] with the following restrictions: i) pBS[i]== 4 may 
+ *            occur only for 0<=i<=3, ii) pBS[i]== 4 if and only if pBS[i^3]== 
+ *            4. Must be 4-byte aligned. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst - pointer to filtered output macroblock. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments 
+ *    -     one or more of the following pointers is NULL: pSrcDst, pAlpha, 
+ *              pBeta, pThresholds or pBS. pSrcDst is not 16-byte aligned. 
+ *              either pThresholds or pBS is not aligned on a 4-byte boundary. 
+ *    -    one or more entries in the table pAlpha[0..3] is outside the range 
+ *              [0,255]. 
+ *    -    one or more entries in the table pBeta[0..3] is outside the range 
+ *              [0,18]. 
+ *    -    one or more entries in the table pThresholds[0..31]is outside of 
+ *              the range [0,25]. 
+ *    -    pBS is out of range, i.e., one of the following conditions is true: 
+ *              pBS[i]<0, pBS[i]>4, pBS[i]==4 for i>=4, or 
+ *             (pBS[i]==4 && pBS[i^3]!=4) for 0<=i<=3. 
+ *    -    srcdstStep is not a multiple of 16. 
+ *
+ */
+
+OMXResult omxVCM4P10_DeblockLuma_I(
+	OMX_U8* pSrcDst, 
+	OMX_S32 srcdstStep, 
+	const OMX_U8* pAlpha, 
+	const OMX_U8* pBeta, 
+	const OMX_U8* pThresholds, 
+	const OMX_U8 *pBS
+)
+{
+    OMXResult errorCode;
+    
+    armRetArgErrIf(pSrcDst == NULL,             OMX_Sts_BadArgErr);
+    armRetArgErrIf(armNot16ByteAligned(pSrcDst), OMX_Sts_BadArgErr);
+    armRetArgErrIf(srcdstStep & 15,              OMX_Sts_BadArgErr);    
+    armRetArgErrIf(pAlpha == NULL,              OMX_Sts_BadArgErr);
+    armRetArgErrIf(pBeta == NULL,               OMX_Sts_BadArgErr);
+    armRetArgErrIf(pThresholds == NULL,         OMX_Sts_BadArgErr);
+    armRetArgErrIf(armNot4ByteAligned(pThresholds), OMX_Sts_BadArgErr);
+    armRetArgErrIf(pBS == NULL,                     OMX_Sts_BadArgErr);
+    armRetArgErrIf(armNot4ByteAligned(pBS),         OMX_Sts_BadArgErr);
+
+    errorCode = omxVCM4P10_FilterDeblockingLuma_VerEdge_I(
+        pSrcDst, srcdstStep, pAlpha, pBeta, pThresholds, pBS);
+
+    armRetArgErrIf(errorCode != OMX_Sts_NoErr, errorCode)
+    
+    errorCode = omxVCM4P10_FilterDeblockingLuma_HorEdge_I(
+        pSrcDst, srcdstStep, pAlpha+2, pBeta+2, pThresholds+16, pBS+16);
+
+    return errorCode;
+}
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_DecodeChromaDcCoeffsToPairCAVLC.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_DecodeChromaDcCoeffsToPairCAVLC.c
new file mode 100644
index 0000000..830ddc7
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_DecodeChromaDcCoeffsToPairCAVLC.c
@@ -0,0 +1,86 @@
+/* ----------------------------------------------------------------
+ *
+ * 
+ * File Name:  omxVCM4P10_DecodeChromaDcCoeffsToPairCAVLC.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * H.264 decode coefficients module
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+
+/**
+ * Function:  omxVCM4P10_DecodeChromaDcCoeffsToPairCAVLC   (6.3.4.1.1)
+ *
+ * Description:
+ * Performs CAVLC decoding and inverse raster scan for a 2x2 block of 
+ * ChromaDCLevel.  The decoded coefficients in the packed position-coefficient 
+ * buffer are stored in reverse zig-zag order, i.e., the first buffer element 
+ * contains the last non-zero postion-coefficient pair of the block. Within 
+ * each position-coefficient pair, the position entry indicates the 
+ * raster-scan position of the coefficient, while the coefficient entry 
+ * contains the coefficient value. 
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - Double pointer to current byte in bit stream buffer 
+ *   pOffset - Pointer to current bit position in the byte pointed to by 
+ *            *ppBitStream; valid in the range [0,7]. 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after each block is decoded 
+ *   pOffset - *pOffset is updated after each block is decoded 
+ *   pNumCoeff - Pointer to the number of nonzero coefficients in this block 
+ *   ppPosCoefBuf - Double pointer to destination residual 
+ *            coefficient-position pair buffer.  Buffer position 
+ *            (*ppPosCoefBuf) is updated upon return, unless there are only 
+ *            zero coefficients in the currently decoded block.  In this case 
+ *            the caller is expected to bypass the transform/dequantization of 
+ *            the empty blocks. 
+ *
+ * Return Value:
+ *
+ *    OMX_Sts_NoErr, if the function runs without error.
+ * 
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    ppBitStream or pOffset is NULL. 
+ *    -    ppPosCoefBuf or pNumCoeff is NULL. 
+ *    OMX_Sts_Err - if one of the following is true: 
+ *    -    an illegal code is encountered in the bitstream 
+ *
+ */
+
+OMXResult omxVCM4P10_DecodeChromaDcCoeffsToPairCAVLC (
+     const OMX_U8** ppBitStream,
+     OMX_S32* pOffset,
+     OMX_U8* pNumCoeff,
+     OMX_U8** ppPosCoefbuf        
+ )
+
+{
+    armRetArgErrIf(ppBitStream==NULL   , OMX_Sts_BadArgErr);
+    armRetArgErrIf(*ppBitStream==NULL  , OMX_Sts_BadArgErr);
+    armRetArgErrIf(pOffset==NULL       , OMX_Sts_BadArgErr);
+    armRetArgErrIf(*pOffset<0          , OMX_Sts_BadArgErr);
+    armRetArgErrIf(*pOffset>7          , OMX_Sts_BadArgErr);
+    armRetArgErrIf(pNumCoeff==NULL     , OMX_Sts_BadArgErr);
+    armRetArgErrIf(ppPosCoefbuf==NULL  , OMX_Sts_BadArgErr);
+    armRetArgErrIf(*ppPosCoefbuf==NULL , OMX_Sts_BadArgErr);
+
+    return armVCM4P10_DecodeCoeffsToPair(ppBitStream, pOffset, pNumCoeff,
+                                         ppPosCoefbuf, 4, 4);
+
+}
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_DecodeCoeffsToPairCAVLC.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_DecodeCoeffsToPairCAVLC.c
new file mode 100644
index 0000000..7e83d1e
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_DecodeCoeffsToPairCAVLC.c
@@ -0,0 +1,117 @@
+/* ----------------------------------------------------------------
+ *
+ * 
+ * File Name:  omxVCM4P10_DecodeCoeffsToPairCAVLC.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * H.264 decode coefficients module
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+#include "armCOMM.h"
+#include "armVC.h"
+
+/**
+ * Function:  omxVCM4P10_DecodeCoeffsToPairCAVLC   (6.3.4.1.2)
+ *
+ * Description:
+ * Performs CAVLC decoding and inverse zigzag scan for 4x4 block of 
+ * Intra16x16DCLevel, Intra16x16ACLevel, LumaLevel, and ChromaACLevel. Inverse 
+ * field scan is not supported. The decoded coefficients in the packed 
+ * position-coefficient buffer are stored in reverse zig-zag order, i.e., the 
+ * first buffer element contains the last non-zero postion-coefficient pair of 
+ * the block. Within each position-coefficient pair, the position entry 
+ * indicates the raster-scan position of the coefficient, while the 
+ * coefficient entry contains the coefficient value. 
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream -Double pointer to current byte in bit stream buffer 
+ *   pOffset - Pointer to current bit position in the byte pointed to by 
+ *            *ppBitStream; valid in the range [0,7]. 
+ *   sMaxNumCoeff - Maximum the number of non-zero coefficients in current 
+ *            block 
+ *   sVLCSelect - VLC table selector, obtained from the number of non-zero 
+ *            coefficients contained in the above and left 4x4 blocks.  It is 
+ *            equivalent to the variable nC described in H.264 standard table 
+ *            9 5, except its value can t be less than zero. 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after each block is decoded.  
+ *            Buffer position (*ppPosCoefBuf) is updated upon return, unless 
+ *            there are only zero coefficients in the currently decoded block. 
+ *             In this case the caller is expected to bypass the 
+ *            transform/dequantization of the empty blocks. 
+ *   pOffset - *pOffset is updated after each block is decoded 
+ *   pNumCoeff - Pointer to the number of nonzero coefficients in this block 
+ *   ppPosCoefBuf - Double pointer to destination residual 
+ *            coefficient-position pair buffer 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ * 
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    ppBitStream or pOffset is NULL. 
+ *    -    ppPosCoefBuf or pNumCoeff is NULL. 
+ *    -    sMaxNumCoeff is not equal to either 15 or 16. 
+ *    -    sVLCSelect is less than 0. 
+ *
+ *    OMX_Sts_Err - if one of the following is true: 
+ *    -    an illegal code is encountered in the bitstream 
+ *
+ */
+
+OMXResult omxVCM4P10_DecodeCoeffsToPairCAVLC(
+     const OMX_U8** ppBitStream,
+     OMX_S32* pOffset,
+     OMX_U8* pNumCoeff,
+     OMX_U8**ppPosCoefbuf,
+     OMX_INT sVLCSelect,
+     OMX_INT sMaxNumCoeff        
+ )
+{
+    int nTable;
+
+    armRetArgErrIf(ppBitStream==NULL   , OMX_Sts_BadArgErr);
+    armRetArgErrIf(*ppBitStream==NULL  , OMX_Sts_BadArgErr);
+    armRetArgErrIf(pOffset==NULL       , OMX_Sts_BadArgErr);
+    armRetArgErrIf(*pOffset<0          , OMX_Sts_BadArgErr);
+    armRetArgErrIf(*pOffset>7          , OMX_Sts_BadArgErr);
+    armRetArgErrIf(pNumCoeff==NULL     , OMX_Sts_BadArgErr);
+    armRetArgErrIf(ppPosCoefbuf==NULL  , OMX_Sts_BadArgErr);
+    armRetArgErrIf(*ppPosCoefbuf==NULL , OMX_Sts_BadArgErr);
+    armRetArgErrIf(sVLCSelect<0        , OMX_Sts_BadArgErr);
+    armRetArgErrIf(sMaxNumCoeff<15     , OMX_Sts_BadArgErr);
+    armRetArgErrIf(sMaxNumCoeff>16     , OMX_Sts_BadArgErr);
+    
+    /* Find VLC table number */
+    if (sVLCSelect<2)
+    {
+        nTable = 0;
+    }
+    else if (sVLCSelect<4)
+    {
+        nTable = 1;
+    }
+    else if (sVLCSelect<8)
+    {
+        nTable = 2;
+    }
+    else /* sVLCSelect >= 8 */
+    {
+        nTable = 3;
+    }
+
+    return armVCM4P10_DecodeCoeffsToPair(ppBitStream, pOffset, pNumCoeff,
+                                         ppPosCoefbuf, nTable, sMaxNumCoeff);
+}
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_DequantTransformResidualFromPairAndAdd.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_DequantTransformResidualFromPairAndAdd.c
new file mode 100644
index 0000000..ed5a158
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_DequantTransformResidualFromPairAndAdd.c
@@ -0,0 +1,145 @@
+/* ----------------------------------------------------------------
+ *
+ * 
+ * File Name:  omxVCM4P10_DequantTransformResidualFromPairAndAdd.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * H.264 inverse quantize and transform module
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+
+/*
+ * Description:
+ * Dequantize Luma AC block
+ */
+
+static void DequantLumaAC4x4(
+     OMX_S16* pSrcDst,
+     OMX_INT QP        
+)
+{
+    const OMX_U8 *pVRow = &armVCM4P10_VMatrix[QP%6][0];
+    int Shift = QP / 6;
+    int i;
+    OMX_S32 Value;
+
+    for (i=0; i<16; i++)
+    {
+
+        Value = (pSrcDst[i] * pVRow[armVCM4P10_PosToVCol4x4[i]]) << Shift;
+        pSrcDst[i] = (OMX_S16)Value;
+    }
+}
+
+/**
+ * Function:  omxVCM4P10_DequantTransformResidualFromPairAndAdd   (6.3.4.2.3)
+ *
+ * Description:
+ * Reconstruct the 4x4 residual block from coefficient-position pair buffer, 
+ * perform dequantization and integer inverse transformation for 4x4 block of 
+ * residuals with previous intra prediction or motion compensation data, and 
+ * update the pair buffer pointer to next non-empty block. If pDC == NULL, 
+ * there re 16 non-zero AC coefficients at most in the packed buffer starting 
+ * from 4x4 block position 0; If pDC != NULL, there re 15 non-zero AC 
+ * coefficients at most in the packet buffer starting from 4x4 block position 
+ * 1. 
+ *
+ * Input Arguments:
+ *   
+ *   ppSrc - Double pointer to residual coefficient-position pair buffer 
+ *            output by CALVC decoding 
+ *   pPred - Pointer to the predicted 4x4 block; must be aligned on a 4-byte 
+ *            boundary 
+ *   predStep - Predicted frame step size in bytes; must be a multiple of 4 
+ *   dstStep - Destination frame step in bytes; must be a multiple of 4 
+ *   pDC - Pointer to the DC coefficient of this block, NULL if it doesn't 
+ *            exist 
+ *   QP - QP Quantization parameter.  It should be QpC in chroma 4x4 block 
+ *            decoding, otherwise it should be QpY. 
+ *   AC - Flag indicating if at least one non-zero AC coefficient exists 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - pointer to the reconstructed 4x4 block data; must be aligned on a 
+ *            4-byte boundary 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    pPred or pDst is NULL. 
+ *    -    pPred or pDst is not 4-byte aligned. 
+ *    -    predStep or dstStep is not a multiple of 4. 
+ *    -    AC !=0 and Qp is not in the range of [0-51] or ppSrc == NULL. 
+ *    -    AC ==0 && pDC ==NULL. 
+ *
+ */
+
+OMXResult omxVCM4P10_DequantTransformResidualFromPairAndAdd(
+     const OMX_U8 **ppSrc,
+     const OMX_U8 *pPred,
+     const OMX_S16 *pDC,
+     OMX_U8 *pDst,
+     OMX_INT predStep,
+     OMX_INT dstStep,
+     OMX_INT QP,
+     OMX_INT AC        
+)
+{
+    OMX_S16 pBuffer[16+4];
+    OMX_S16 *pDelta;
+    int i,x,y;
+    
+    armRetArgErrIf(pPred == NULL,            OMX_Sts_BadArgErr);
+    armRetArgErrIf(armNot4ByteAligned(pPred),OMX_Sts_BadArgErr);
+    armRetArgErrIf(pDst   == NULL,           OMX_Sts_BadArgErr);
+    armRetArgErrIf(armNot4ByteAligned(pDst), OMX_Sts_BadArgErr);
+    armRetArgErrIf(predStep & 3,             OMX_Sts_BadArgErr);
+    armRetArgErrIf(dstStep & 3,              OMX_Sts_BadArgErr);
+    armRetArgErrIf(AC!=0 && (QP<0),          OMX_Sts_BadArgErr);
+    armRetArgErrIf(AC!=0 && (QP>51),         OMX_Sts_BadArgErr);
+    armRetArgErrIf(AC!=0 && ppSrc==NULL,     OMX_Sts_BadArgErr);
+    armRetArgErrIf(AC!=0 && *ppSrc==NULL,    OMX_Sts_BadArgErr);
+    armRetArgErrIf(AC==0 && pDC==NULL,       OMX_Sts_BadArgErr);
+    
+    pDelta = armAlignTo8Bytes(pBuffer);    
+
+    for (i=0; i<16; i++)
+    {
+        pDelta[i] = 0;
+    }
+    if (AC)
+    {
+        armVCM4P10_UnpackBlock4x4(ppSrc, pDelta);
+        DequantLumaAC4x4(pDelta, QP);
+    }
+    if (pDC)
+    {
+        pDelta[0] = pDC[0];
+    }
+    armVCM4P10_TransformResidual4x4(pDelta,pDelta);
+
+    for (y=0; y<4; y++)
+    {
+        for (x=0; x<4; x++)
+        {
+            pDst[y*dstStep+x] = (OMX_U8)armClip(0,255,pPred[y*predStep+x] + pDelta[4*y+x]);
+        }
+    }
+
+    return OMX_Sts_NoErr;
+}
+
+/* End of file */
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_FilterDeblockingChroma_HorEdge_I.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_FilterDeblockingChroma_HorEdge_I.c
new file mode 100644
index 0000000..75edee2
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_FilterDeblockingChroma_HorEdge_I.c
@@ -0,0 +1,130 @@
+/* ----------------------------------------------------------------
+ *
+ * 
+ * File Name:  omxVCM4P10_FilterDeblockingChroma_HorEdge_I.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * H.264 chroma deblock module
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+
+/**
+ * Function:  omxVCM4P10_FilterDeblockingChroma_HorEdge_I   (6.3.3.3.4)
+ *
+ * Description:
+ * Performs in-place deblock filtering on the horizontal edges of the chroma 
+ * macroblock (8x8). 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - pointer to the input macroblock; must be 8-byte aligned. 
+ *   srcdstStep - array step; must be a multiple of 8. 
+ *   pAlpha - array of size 2 containing alpha thresholds; the first element 
+ *            contains the threshold for the external horizontal edge, and the 
+ *            second element contains the threshold for internal horizontal 
+ *            edge.  Per [ISO14496-10] alpha values must be in the range 
+ *            [0,255]. 
+ *   pBeta - array of size 2 containing beta thresholds; the first element 
+ *            contains the threshold for the external horizontal edge, and the 
+ *            second element contains the threshold for the internal 
+ *            horizontal edge.  Per [ISO14496-10] beta values must be in the 
+ *            range [0,18]. 
+ *   pThresholds - array of size 8 containing thresholds, TC0, for the top 
+ *            horizontal edge of each 2x4 chroma block, arranged in horizontal 
+ *            block order; must be aligned on a 4-byte boundary.  Per 
+ *            [ISO14496-10] values must be in the range [0,25]. 
+ *   pBS - array of size 16 containing BS parameters for each 2x2 chroma 
+ *            block, arranged in horizontal block order; valid in the range 
+ *            [0,4] with the following restrictions: i) pBS[i]== 4 may occur 
+ *            only for 0<=i<=3, ii) pBS[i]== 4 if and only if pBS[i^3]== 4. 
+ *            Must be 4-byte aligned. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst -Pointer to filtered output macroblock. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr, if the function runs without error.
+ * 
+ *    OMX_Sts_BadArgErr, if one of the following cases occurs: 
+ *    -    any of the following pointers is NULL: 
+ *         pSrcDst, pAlpha, pBeta, pThresholds, or pBS. 
+ *    -    pSrcDst is not 8-byte aligned. 
+ *    -    srcdstStep is not a multiple of 8. 
+ *    -    pThresholds is not 4-byte aligned. 
+ *    -    pAlpha[0] and/or pAlpha[1] is outside the range [0,255]. 
+ *    -    pBeta[0] and/or pBeta[1] is outside the range [0,18]. 
+ *    -    One or more entries in the table pThresholds[0..7] is outside 
+ *         of the range [0,25]. 
+ *    -    pBS is out of range, i.e., one of the following conditions is true: 
+ *              pBS[i]<0, pBS[i]>4, pBS[i]==4 for i>=4, or 
+ *              (pBS[i]==4 && pBS[i^3]!=4) for 0<=i<=3.
+ *    -    pBS is not 4-byte aligned. 
+ *
+ */
+
+OMXResult omxVCM4P10_FilterDeblockingChroma_HorEdge_I(
+     OMX_U8* pSrcDst,
+     OMX_S32 srcdstStep,
+     const OMX_U8* pAlpha,
+     const OMX_U8* pBeta,
+     const OMX_U8* pThresholds,
+     const OMX_U8 *pBS        
+ )
+{
+    int I, X, Y, Internal=0;
+
+    armRetArgErrIf(pSrcDst == NULL,                 OMX_Sts_BadArgErr);
+    armRetArgErrIf(armNot8ByteAligned(pSrcDst),     OMX_Sts_BadArgErr);
+    armRetArgErrIf(srcdstStep & 7,                  OMX_Sts_BadArgErr);
+    armRetArgErrIf(pAlpha == NULL,                  OMX_Sts_BadArgErr);
+    armRetArgErrIf(pBeta == NULL,                   OMX_Sts_BadArgErr);
+    armRetArgErrIf(pThresholds == NULL,             OMX_Sts_BadArgErr);
+    armRetArgErrIf(armNot4ByteAligned(pThresholds), OMX_Sts_BadArgErr);
+    armRetArgErrIf(pBS == NULL,                     OMX_Sts_BadArgErr);
+    armRetArgErrIf(armNot4ByteAligned(pBS),         OMX_Sts_BadArgErr);
+
+    for (Y=0; Y<8; Y+=4, Internal=1)
+    {
+        for (X=0; X<8; X++)
+        {
+            I = (X>>1)+4*(Y>>1);
+            
+            armRetArgErrIf(pBS[I] > 4, OMX_Sts_BadArgErr)
+            
+            armRetArgErrIf( (I > 3) && (pBS[I] == 4),
+                            OMX_Sts_BadArgErr)
+            
+            armRetArgErrIf( (I < 4)       && 
+                          ( (pBS[I] == 4) && (pBS[I^1] != 4) ),
+                            OMX_Sts_BadArgErr)
+            
+
+            /* Filter horizontal edge with q0 at (X,Y) */
+            armVCM4P10_DeBlockPixel(
+                pSrcDst + Y*srcdstStep + X,
+                srcdstStep,
+                pThresholds[(X>>1)+4*(Y>>2)],
+                pAlpha[Internal],
+                pBeta[Internal],
+                pBS[I],
+                1);
+        }
+    }
+
+    return OMX_Sts_NoErr;
+}
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_FilterDeblockingChroma_VerEdge_I.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_FilterDeblockingChroma_VerEdge_I.c
new file mode 100644
index 0000000..10b2592
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_FilterDeblockingChroma_VerEdge_I.c
@@ -0,0 +1,131 @@
+/* ----------------------------------------------------------------
+ *
+ * 
+ * File Name:  omxVCM4P10_FilterDeblockingChroma_VerEdge_I.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * H.264 deblocking module
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+
+/**
+ * Function:  omxVCM4P10_FilterDeblockingChroma_VerEdge_I   (6.3.3.3.3)
+ *
+ * Description:
+ * Performs in-place deblock filtering on four vertical edges of the chroma 
+ * macroblock (8x8). 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - Pointer to the input macroblock; must be 8-byte aligned. 
+ *   srcdstStep - Step of the arrays; must be a multiple of 8. 
+ *   pAlpha - Array of size 2 of alpha thresholds (the first item is alpha 
+ *            threshold for external vertical edge, and the second item is for 
+ *            internal vertical edge); per [ISO14496-10] alpha values must be 
+ *            in the range [0,255]. 
+ *   pBeta - Array of size 2 of beta thresholds (the first item is the beta 
+ *            threshold for the external vertical edge, and the second item is 
+ *            for the internal vertical edge); per [ISO14496-10] beta values 
+ *            must be in the range [0,18]. 
+ *   pThresholds - Array of size 8 containing thresholds, TC0, for the left 
+ *            vertical edge of each 4x2 chroma block, arranged in vertical 
+ *            block order; must be aligned on a 4-byte boundary.  Per 
+ *            [ISO14496-10] values must be in the range [0,25]. 
+ *   pBS - Array of size 16 of BS parameters (values for each 2x2 chroma 
+ *            block, arranged in vertical block order). This parameter is the 
+ *            same as the pBSparameter passed into FilterDeblockLuma_VerEdge; 
+ *            valid in the range [0,4] with the following restrictions: i) 
+ *            pBS[i]== 4 may occur only for 0<=i<=3, ii) pBS[i]== 4 if and 
+ *            only if pBS[i^3]== 4.  Must be 4 byte aligned. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst -Pointer to filtered output macroblock. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr, if the function runs without error.
+ * 
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    one or more of the following pointers is NULL: pSrcDst, pAlpha, 
+ *              pBeta, pThresholds, or pBS. 
+ *    -    pSrcDst is not 8-byte aligned. 
+ *    -    srcdstStep is not a multiple of 8. 
+ *    -    pThresholds is not 4-byte aligned. 
+ *    -    pAlpha[0] and/or pAlpha[1] is outside the range [0,255]. 
+ *    -    pBeta[0] and/or pBeta[1] is outside the range [0,18]. 
+ *    -    One or more entries in the table pThresholds[0..7] is outside 
+ *         of the range [0,25]. 
+ *    -    pBS is out of range, i.e., one of the following conditions is true: 
+ *         pBS[i]<0, pBS[i]>4, pBS[i]==4 for i>=4, or 
+ *         (pBS[i]==4 && pBS[i^3]!=4) for 0<=i<=3. 
+ *    -    pBS is not 4-byte aligned. 
+ *
+ */
+
+OMXResult omxVCM4P10_FilterDeblockingChroma_VerEdge_I(
+     OMX_U8* pSrcDst,
+     OMX_S32 srcdstStep,
+     const OMX_U8* pAlpha,
+     const OMX_U8* pBeta,
+     const OMX_U8* pThresholds,
+     const OMX_U8 *pBS        
+ )
+{
+    int I, X, Y, Internal=0;
+
+    armRetArgErrIf(pSrcDst == NULL,                 OMX_Sts_BadArgErr);
+    armRetArgErrIf(armNot8ByteAligned(pSrcDst),     OMX_Sts_BadArgErr);
+    armRetArgErrIf(srcdstStep & 7,                  OMX_Sts_BadArgErr);
+    armRetArgErrIf(pAlpha == NULL,                  OMX_Sts_BadArgErr);
+    armRetArgErrIf(pBeta == NULL,                   OMX_Sts_BadArgErr);
+    armRetArgErrIf(pThresholds == NULL,             OMX_Sts_BadArgErr);
+    armRetArgErrIf(armNot4ByteAligned(pThresholds), OMX_Sts_BadArgErr);
+    armRetArgErrIf(pBS == NULL,                     OMX_Sts_BadArgErr);
+    armRetArgErrIf(armNot4ByteAligned(pBS),         OMX_Sts_BadArgErr);
+    armRetArgErrIf(pBeta[0] > 18,  OMX_Sts_BadArgErr);
+    armRetArgErrIf(pBeta[1] > 18,  OMX_Sts_BadArgErr);
+
+    for (X=0; X<8; X+=4, Internal=1)
+    {
+        for (Y=0; Y<8; Y++)
+        {
+            I = (Y>>1)+4*(X>>1);
+            
+            armRetArgErrIf(pBS[I] > 4, OMX_Sts_BadArgErr);
+            
+            armRetArgErrIf( (I > 3) && (pBS[I] == 4),
+                            OMX_Sts_BadArgErr);
+            
+            armRetArgErrIf( ( (pBS[I] == 4) && (pBS[I^3] != 4) ),
+                            OMX_Sts_BadArgErr);
+            armRetArgErrIf(pThresholds[Y] > 25, OMX_Sts_BadArgErr);
+            
+
+            /* Filter vertical edge with q0 at (X,Y) */
+            armVCM4P10_DeBlockPixel(
+                pSrcDst + Y*srcdstStep + X,
+                1,
+                pThresholds[(Y>>1)+4*(X>>2)],
+                pAlpha[Internal],
+                pBeta[Internal],
+                pBS[I],
+                1);
+        }
+    }
+
+    return OMX_Sts_NoErr;
+}
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_FilterDeblockingLuma_HorEdge_I.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_FilterDeblockingLuma_HorEdge_I.c
new file mode 100644
index 0000000..30a37da
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_FilterDeblockingLuma_HorEdge_I.c
@@ -0,0 +1,125 @@
+/* ----------------------------------------------------------------
+ *
+ * 
+ * File Name:  omxVCM4P10_FilterDeblockingLuma_HorEdge_I.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * H.264 luma deblock module
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+
+/**
+ * Function:  omxVCM4P10_FilterDeblockingLuma_HorEdge_I   (6.3.3.3.2)
+ *
+ * Description:
+ * Performs in-place deblock filtering on four horizontal edges of the luma 
+ * macroblock (16x16). 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - pointer to the input macroblock; must be 16-byte aligned. 
+ *   srcdstStep -s tep of the arrays; must be a multiple of 16. 
+ *   pAlpha - array of size 2 of alpha thresholds (the first item is the alpha 
+ *            threshold for the external vertical edge, and the second item is 
+ *            for the internal horizontal edge); per [ISO14496-10] alpha 
+ *            values must be in the range [0,255]. 
+ *   pBeta - array of size 2 of beta thresholds (the first item is the beta 
+ *            threshold for the external horizontal edge, and the second item 
+ *            is for the internal horizontal edge). Per [ISO14496-10] beta 
+ *            values must be in the range [0,18]. 
+ *   pThresholds - array of size 16 containing thresholds, TC0, for the top 
+ *            horizontal edge of each 4x4 block, arranged in horizontal block 
+ *            order; must be aligned on a 4-byte boundary.  Per [ISO14496 10] 
+ *            values must be in the range [0,25]. 
+ *   pBS - array of size 16 of BS parameters (arranged in horizontal block 
+ *            order); valid in the range [0,4] with the following 
+ *            restrictions: i) pBS[i]== 4 may occur only for 0<=i<=3, ii) 
+ *            pBS[i]== 4 if and only if pBS[i^3]== 4.  Must be 4-byte aligned. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst -Pointer to filtered output macroblock. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr, if the function runs without error.
+ * 
+ *    OMX_Sts_BadArgErr, if one of the following cases occurs: 
+ *    -    one or more of the following pointers is NULL: pSrcDst, pAlpha, 
+ *              pBeta, pThresholds, or pBS. 
+ *    -    either pThresholds or pBS is not aligned on a 4-byte boundary. 
+ *    -    pSrcDst is not 16-byte aligned. 
+ *    -    srcdstStep is not a multiple of 16. 
+ *    -    pAlpha[0] and/or pAlpha[1] is outside the range [0,255]. 
+ *    -    pBeta[0] and/or pBeta[1] is outside the range [0,18]. 
+ *    -    One or more entries in the table pThresholds[0..15] is 
+ *         outside of the range [0,25]. 
+ *    -    pBS is out of range, i.e., one of the following conditions is true: 
+ *              pBS[i]<0, pBS[i]>4, pBS[i]==4 for i>=4, or 
+ *              (pBS[i]==4 && pBS[i^3]!=4) for 0<=i<=3. 
+ *
+ */
+
+OMXResult omxVCM4P10_FilterDeblockingLuma_HorEdge_I(
+     OMX_U8* pSrcDst,
+     OMX_S32 srcdstStep,
+     const OMX_U8* pAlpha,
+     const OMX_U8* pBeta,
+     const OMX_U8* pThresholds,
+     const OMX_U8 *pBS        
+ )
+{
+    int I, X, Y, Internal=0;
+
+    armRetArgErrIf(pSrcDst == NULL,             OMX_Sts_BadArgErr);
+    armRetArgErrIf(armNot8ByteAligned(pSrcDst), OMX_Sts_BadArgErr);
+    armRetArgErrIf(srcdstStep & 7,              OMX_Sts_BadArgErr);    
+    armRetArgErrIf(pAlpha == NULL,              OMX_Sts_BadArgErr);
+    armRetArgErrIf(pBeta == NULL,               OMX_Sts_BadArgErr);
+    armRetArgErrIf(pThresholds == NULL,         OMX_Sts_BadArgErr);
+    armRetArgErrIf(armNot4ByteAligned(pThresholds), OMX_Sts_BadArgErr);
+    armRetArgErrIf(pBS == NULL,                     OMX_Sts_BadArgErr);
+    armRetArgErrIf(armNot4ByteAligned(pBS),         OMX_Sts_BadArgErr);
+    
+    for (Y=0; Y<16; Y+=4, Internal=1)
+    {
+        for (X=0; X<16; X++)
+        {
+            I = (X>>2)+4*(Y>>2);
+            
+            armRetArgErrIf(pBS[I] > 4, OMX_Sts_BadArgErr)
+            
+            armRetArgErrIf( (I > 3) && (pBS[I] == 4),
+                            OMX_Sts_BadArgErr)
+            
+            armRetArgErrIf( (I < 4)       && 
+                          ( (pBS[I] == 4) && (pBS[I^1] != 4) ),
+                            OMX_Sts_BadArgErr)
+            
+            /* Filter horizontal edge with q0 at (X,Y) */
+            armVCM4P10_DeBlockPixel(
+                pSrcDst + Y*srcdstStep + X,
+                srcdstStep,
+                pThresholds[I],
+                pAlpha[Internal],
+                pBeta[Internal],
+                pBS[I],
+                0);
+        }
+    }
+
+    return OMX_Sts_NoErr;
+}
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_FilterDeblockingLuma_VerEdge_I.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_FilterDeblockingLuma_VerEdge_I.c
new file mode 100644
index 0000000..8733427
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_FilterDeblockingLuma_VerEdge_I.c
@@ -0,0 +1,128 @@
+/* ----------------------------------------------------------------
+ *
+ * 
+ * File Name:  omxVCM4P10_FilterDeblockingLuma_VerEdge_I.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * H.264 luma deblock module
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+
+/**
+ * Function:  omxVCM4P10_FilterDeblockingLuma_VerEdge_I   (6.3.3.3.1)
+ *
+ * Description:
+ * Performs in-place deblock filtering on four vertical edges of the luma 
+ * macroblock (16x16). 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - Pointer to the input macroblock; must be 16-byte aligned. 
+ *   srcdstStep -Step of the arrays; must be a multiple of 16. 
+ *   pAlpha -Array of size 2 of alpha thresholds (the first item is the alpha 
+ *            threshold for the external vertical edge, and the second item is 
+ *            for the internal vertical edge); per [ISO14496-10] alpha values 
+ *            must be in the range [0,255]. 
+ *   pBeta -Array of size 2 of beta thresholds (the first item is the beta 
+ *            threshold for the external vertical edge, and the second item is 
+ *            for the internal vertical edge); per [ISO14496-10] beta values 
+ *            must be in the range [0,18]. 
+ *   pThresholds -Array of size 16 of Thresholds (TC0) (values for the left 
+ *            edge of each 4x4 block, arranged in vertical block order); must 
+ *            be aligned on a 4-byte boundary..  Per [ISO14496-10] values must 
+ *            be in the range [0,25]. 
+ *   pBS -Array of size 16 of BS parameters (arranged in vertical block 
+ *            order); valid in the range [0,4] with the following 
+ *            restrictions: i) pBS[i]== 4 may occur only for 0<=i<=3, ii) 
+ *            pBS[i]== 4 if and only if pBS[i^3]== 4.  Must be 4-byte aligned. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst -Pointer to filtered output macroblock. 
+ *
+ * Return Value:
+ *    If the function runs without error, it returns OMX_Sts_NoErr. 
+ *    If one of the following cases occurs, the function returns 
+ *              OMX_Sts_BadArgErr: 
+ *    Either of the pointers in pSrcDst, pAlpha, pBeta, pThresholds, or pBS 
+ *              is NULL. 
+ *    Either pThresholds or pBS is not aligned on a 4-byte boundary. 
+ *    pSrcDst is not 16-byte aligned. 
+ *    srcdstStep is not a multiple of 16. 
+ *    pAlpha[0] and/or pAlpha[1] is outside the range [0,255]. 
+ *    pBeta[0] and/or pBeta[1] is outside the range [0,18]. 
+ *    One or more entries in the table pThresholds[0..15]is outside of the 
+ *              range [0,25]. 
+ *    pBS is out of range, i.e., one of the following conditions is true: 
+ *              pBS[i]<0, pBS[i]>4, pBS[i]==4 for i>=4, or (pBS[i]==4 && 
+ *              pBS[i^3]!=4) for 0<=i<=3. 
+ *
+ */
+
+OMXResult omxVCM4P10_FilterDeblockingLuma_VerEdge_I(
+     OMX_U8* pSrcDst,
+     OMX_S32 srcdstStep,
+     const OMX_U8* pAlpha,
+     const OMX_U8* pBeta,
+     const OMX_U8* pThresholds,
+     const OMX_U8 *pBS        
+ )
+{
+    int X, Y, I, Internal=0;
+
+    armRetArgErrIf(pSrcDst == NULL,             OMX_Sts_BadArgErr);
+    armRetArgErrIf(armNot16ByteAligned(pSrcDst),OMX_Sts_BadArgErr);
+    armRetArgErrIf(srcdstStep & 15,             OMX_Sts_BadArgErr);    
+    armRetArgErrIf(pAlpha == NULL,              OMX_Sts_BadArgErr);
+    armRetArgErrIf(pBeta == NULL,               OMX_Sts_BadArgErr);
+    armRetArgErrIf(pThresholds == NULL,         OMX_Sts_BadArgErr);
+    armRetArgErrIf(armNot4ByteAligned(pThresholds), OMX_Sts_BadArgErr);
+    armRetArgErrIf(pBS == NULL,                     OMX_Sts_BadArgErr);
+    armRetArgErrIf(armNot4ByteAligned(pBS),         OMX_Sts_BadArgErr);
+    armRetArgErrIf(pBeta[0] > 18,  OMX_Sts_BadArgErr);
+    armRetArgErrIf(pBeta[1] > 18,  OMX_Sts_BadArgErr);
+    
+
+    for (X=0; X<16; X+=4, Internal=1)
+    {
+        for (Y=0; Y<16; Y++)
+        {
+            I = (Y>>2)+4*(X>>2);
+            
+            armRetArgErrIf(pBS[Y] > 4, OMX_Sts_BadArgErr);
+            
+            armRetArgErrIf((pBS[Y] == 4) && (Y > 3),
+                            OMX_Sts_BadArgErr);
+            
+            armRetArgErrIf(( (pBS[Y] == 4) && (pBS[Y^3] != 4) ),
+                            OMX_Sts_BadArgErr);
+                            
+            armRetArgErrIf(pThresholds[Y] > 25, OMX_Sts_BadArgErr);
+            
+            /* Filter vertical edge with q0 at (X,Y) */
+            armVCM4P10_DeBlockPixel(
+                pSrcDst + Y*srcdstStep + X,
+                1,
+                pThresholds[I],
+                pAlpha[Internal],
+                pBeta[Internal],
+                pBS[I],
+                0);
+        }
+    }
+
+    return OMX_Sts_NoErr;
+}
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_GetVLCInfo.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_GetVLCInfo.c
new file mode 100644
index 0000000..81c59d6
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_GetVLCInfo.c
@@ -0,0 +1,192 @@
+/**
+ * 
+ * File Name:  omxVCM4P10_GetVLCInfo.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * Description:
+ * 
+ * This function extracts run-length encoding (RLE) information
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+
+/**
+ * Function:  omxVCM4P10_GetVLCInfo   (6.3.5.9.1)
+ *
+ * Description:
+ * This function extracts run-length encoding (RLE) information from the 
+ * coefficient matrix.  The results are returned in an OMXVCM4P10VLCInfo 
+ * structure. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcCoeff - pointer to the transform coefficient matrix.  8-byte 
+ *            alignment required. 
+ *   pScanMatrix - pointer to the scan order definition matrix.  For a luma 
+ *            block the scan matrix should follow [ISO14496-10] section 8.5.4, 
+ *            and should contain the values 0, 1, 4, 8, 5, 2, 3, 6, 9, 12, 13, 
+ *            10, 7, 11, 14, 15.  For a chroma block, the scan matrix should 
+ *            contain the values 0, 1, 2, 3. 
+ *   bAC - indicates presence of a DC coefficient; 0 = DC coefficient 
+ *            present, 1= DC coefficient absent. 
+ *   MaxNumCoef - specifies the number of coefficients contained in the 
+ *            transform coefficient matrix, pSrcCoeff. The value should be 16 
+ *            for blocks of type LUMADC, LUMAAC, LUMALEVEL, and CHROMAAC. The 
+ *            value should be 4 for blocks of type CHROMADC. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstVLCInfo - pointer to structure that stores information for 
+ *            run-length coding. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: 
+ *            pSrcCoeff, pScanMatrix, pDstVLCInfo 
+ *    -    pSrcCoeff is not aligned on an 8-byte boundary 
+ *
+ */
+OMXResult omxVCM4P10_GetVLCInfo (
+	const OMX_S16*		    pSrcCoeff,
+	const OMX_U8*			    pScanMatrix,
+	OMX_U8			    bAC,
+	OMX_U32			    MaxNumCoef,
+	OMXVCM4P10VLCInfo*	pDstVLCInfo
+)
+{
+    OMX_INT     i, MinIndex;
+    OMX_S32     Value;
+    OMX_U32     Mask = 4, RunBefore;
+    OMX_S16     *pLevel;
+    OMX_U8      *pRun;
+    OMX_S16     Buf [16];
+
+    /* check for argument error */
+    armRetArgErrIf(pSrcCoeff == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(armNot8ByteAligned(pSrcCoeff), OMX_Sts_BadArgErr)
+    armRetArgErrIf(pScanMatrix == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pDstVLCInfo == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(bAC > 1, OMX_Sts_BadArgErr)
+    armRetArgErrIf(MaxNumCoef > 16, OMX_Sts_BadArgErr)
+
+    /* Initialize RLE Info structure */
+    pDstVLCInfo->uTrailing_Ones = 0;
+    pDstVLCInfo->uTrailing_One_Signs = 0;
+    pDstVLCInfo->uNumCoeffs = 0;
+    pDstVLCInfo->uTotalZeros = 0;
+
+    for (i = 0; i < 16; i++)
+    {
+        pDstVLCInfo->iLevels [i] = 0;
+        pDstVLCInfo->uRuns [i] = 0;
+    }
+    
+    MinIndex = (bAC == 0 && MaxNumCoef == 15) ? 1 : 0;
+    for (i = MinIndex; i < (MaxNumCoef + MinIndex); i++)
+    {        
+        /* Scan */
+        Buf [i - MinIndex] = pSrcCoeff [pScanMatrix [i]];
+    }
+
+    /* skip zeros at the end */
+    i = MaxNumCoef - 1;
+    while (!Buf [i] && i >= 0)
+    {
+        i--;
+    }
+    
+    if (i < 0)
+    {
+        return OMX_Sts_NoErr;
+    }
+
+    /* Fill RLE Info structure */
+    pLevel = pDstVLCInfo->iLevels;
+    pRun = pDstVLCInfo->uRuns;
+    RunBefore = 0;
+
+    /* Handle first non zero separate */
+    pDstVLCInfo->uNumCoeffs++;
+    Value = Buf [i];
+    if (Value == 1 || Value == -1)
+    {
+        pDstVLCInfo->uTrailing_Ones++;
+        
+        pDstVLCInfo->uTrailing_One_Signs |= 
+            Value == -1 ? Mask : 0;
+        Mask >>= 1;
+    }
+    else
+    {
+        Value -= (Value > 0 ? 1 : -1);
+        *pLevel++ = Value;
+        Mask = 0;
+    }
+
+    /* Remaining non zero */
+    while (--i >= 0)
+    {
+        Value = Buf [i];
+        if (Value)
+        {
+            pDstVLCInfo->uNumCoeffs++;
+
+            /* Mask becomes zero after entering */
+            if (Mask &&
+                (Value == 1 || 
+                 Value == -1))
+            {
+                pDstVLCInfo->uTrailing_Ones++;
+                
+                pDstVLCInfo->uTrailing_One_Signs |= 
+                    Value == -1 ? Mask : 0;
+                Mask >>= 1;
+                *pRun++ = RunBefore;
+                RunBefore = 0;
+            }
+            else
+            {
+                /* If 3 trailing ones are not completed */
+                if (Mask)
+                {
+                    Mask = 0;
+                    Value -= (Value > 0 ? 1 : -1);
+                }
+                *pLevel++ = Value;
+                *pRun++ = RunBefore;
+                RunBefore = 0;
+            }
+        }
+        else
+        {
+            pDstVLCInfo->uTotalZeros++;
+            RunBefore++;
+        }        
+    }
+    
+    /* Update last run */
+    if (RunBefore)
+    {
+        *pRun++ = RunBefore;
+    }
+
+    return OMX_Sts_NoErr;
+}
+
+/*****************************************************************************
+ *                              END OF FILE
+ *****************************************************************************/
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_InterpolateChroma.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_InterpolateChroma.c
new file mode 100644
index 0000000..8824de2
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_InterpolateChroma.c
@@ -0,0 +1,99 @@
+/**
+ * 
+ * File Name:  omxVCM4P10_InterpolateChroma.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * Description:
+ * This function will calculate 1/8 Pixel interpolation for Chroma Block
+ * 
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armVC.h"
+#include "armCOMM.h"
+
+
+/**
+ * Function:  omxVCM4P10_InterpolateChroma   (6.3.3.2.2)
+ *
+ * Description:
+ * Performs 1/8-pixel interpolation for inter chroma MB. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc -Pointer to the source reference frame buffer 
+ *   srcStep -Reference frame step in bytes 
+ *   dstStep -Destination frame step in bytes; must be a multiple of 
+ *            roi.width. 
+ *   dx -Fractional part of horizontal motion vector component in 1/8 pixel 
+ *            unit; valid in the range [0,7] 
+ *   dy -Fractional part of vertical motion vector component in 1/8 pixel 
+ *            unit; valid in the range [0,7] 
+ *   roi -Dimension of the interpolation region; the parameters roi.width and 
+ *            roi.height must be equal to either 2, 4, or 8. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst -Pointer to the destination frame buffer if roi.width==2,  2-byte 
+ *            alignment required if roi.width==4,  4-byte alignment required 
+ *            if roi.width==8, 8-byte alignment required 
+ *
+ * Return Value:
+ *    If the function runs without error, it returns OMX_Sts_NoErr. 
+ *    If one of the following cases occurs, the function returns 
+ *              OMX_Sts_BadArgErr: 
+ *    pSrc or pDst is NULL. 
+ *    srcStep or dstStep < 8. 
+ *    dx or dy is out of range [0-7]. 
+ *    roi.width or roi.height is out of range {2,4,8}. 
+ *    roi.width is equal to 2, but pDst is not 2-byte aligned. 
+ *    roi.width is equal to 4, but pDst is not 4-byte aligned. 
+ *    roi.width is equal to 8, but pDst is not 8 byte aligned. 
+ *    srcStep or dstStep is not a multiple of 8. 
+ *
+ */
+
+OMXResult omxVCM4P10_InterpolateChroma (
+     const OMX_U8* pSrc,
+     OMX_S32 srcStep,
+     OMX_U8* pDst,
+     OMX_S32 dstStep,
+     OMX_S32 dx,
+     OMX_S32 dy,
+     OMXSize roi
+ )
+{
+    /* check for argument error */
+    armRetArgErrIf(pSrc == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pDst == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(srcStep < 8, OMX_Sts_BadArgErr)
+    armRetArgErrIf(dstStep < 8, OMX_Sts_BadArgErr)
+    armRetArgErrIf(dx < 0, OMX_Sts_BadArgErr)
+    armRetArgErrIf(dx > 7, OMX_Sts_BadArgErr)
+    armRetArgErrIf(dy < 0, OMX_Sts_BadArgErr)
+    armRetArgErrIf(dy > 7, OMX_Sts_BadArgErr)
+    armRetArgErrIf((roi.width != 2) && (roi.width != 4) && (roi.width != 8), OMX_Sts_BadArgErr)
+    armRetArgErrIf((roi.height != 2) && (roi.height != 4) && (roi.height != 8), OMX_Sts_BadArgErr)
+    armRetArgErrIf((roi.width == 2) && armNot2ByteAligned(pDst), OMX_Sts_BadArgErr)
+    armRetArgErrIf((roi.width == 4) && armNot4ByteAligned(pDst), OMX_Sts_BadArgErr)
+    armRetArgErrIf((roi.width == 8) && armNot8ByteAligned(pDst), OMX_Sts_BadArgErr)
+    armRetArgErrIf(srcStep & 7, OMX_Sts_BadArgErr)
+    armRetArgErrIf(dstStep & 7, OMX_Sts_BadArgErr)
+
+    return armVCM4P10_Interpolate_Chroma 
+        ((OMX_U8*)pSrc, srcStep, pDst, dstStep, roi.width, roi.height, dx, dy);
+}
+
+
+/*****************************************************************************
+ *                              END OF FILE
+ *****************************************************************************/
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_InterpolateHalfHor_Luma.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_InterpolateHalfHor_Luma.c
new file mode 100644
index 0000000..ef0befa
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_InterpolateHalfHor_Luma.c
@@ -0,0 +1,124 @@
+/**
+ * 
+ * File Name:  omxVCM4P10_InterpolateHalfHor_Luma.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * Description:
+ * This function will calculate Half horizontal luma interpolation
+ * 
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+
+/**
+ * Function:  omxVCM4P10_InterpolateHalfHor_Luma   (6.3.5.5.1)
+ *
+ * Description:
+ * This function performs interpolation for two horizontal 1/2-pel positions 
+ * (-1/2,0) and (1/2, 0) - around a full-pel position. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - Pointer to the top-left corner of the block used to interpolate in 
+ *            the reconstruction frame plane. 
+ *   iSrcStep - Step of the source buffer. 
+ *   iDstStep - Step of the destination(interpolation) buffer; must be a 
+ *            multiple of iWidth. 
+ *   iWidth - Width of the current block; must be equal to either 4, 8, or 16 
+ *   iHeight - Height of the current block; must be equal to 4, 8, or 16 
+ *
+ * Output Arguments:
+ *   
+ *   pDstLeft -Pointer to the interpolation buffer of the left -pel position 
+ *            (-1/2, 0) 
+ *                 If iWidth==4,  4-byte alignment required. 
+ *                 If iWidth==8,  8-byte alignment required. 
+ *                 If iWidth==16, 16-byte alignment required. 
+ *   pDstRight -Pointer to the interpolation buffer of the right -pel 
+ *            position (1/2, 0) 
+ *                 If iWidth==4,  4-byte alignment required. 
+ *                 If iWidth==8,  8-byte alignment required. 
+ *                 If iWidth==16, 16-byte alignment required. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: 
+ *             pSrc, pDstLeft, or pDstRight 
+ *    -    iWidth or iHeight have values other than 4, 8, or 16 
+ *    -    iWidth==4 but pDstLeft and/or pDstRight is/are not aligned on a 4-byte boundary 
+ *    -    iWidth==8 but pDstLeft and/or pDstRight is/are not aligned on a 8-byte boundary 
+ *    -    iWidth==16 but pDstLeft and/or pDstRight is/are not aligned on a 16-byte boundary 
+ *    -    any alignment restrictions are violated 
+ *
+ */
+
+OMXResult omxVCM4P10_InterpolateHalfHor_Luma(
+        const OMX_U8*     pSrc, 
+        OMX_U32     iSrcStep, 
+        OMX_U8*     pDstLeft, 
+        OMX_U8*     pDstRight, 
+        OMX_U32     iDstStep, 
+        OMX_U32     iWidth, 
+        OMX_U32     iHeight
+)
+{
+    OMXResult   RetValue;    
+
+    /* check for argument error */
+    armRetArgErrIf(pSrc == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pDstLeft == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pDstRight == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf((iWidth == 4) && 
+                   armNot4ByteAligned(pDstLeft) &&
+                   armNot4ByteAligned(pDstRight), OMX_Sts_BadArgErr)
+    armRetArgErrIf((iWidth == 8) && 
+                   armNot8ByteAligned(pDstLeft) &&
+                   armNot8ByteAligned(pDstRight), OMX_Sts_BadArgErr)
+    armRetArgErrIf((iWidth == 16) && 
+                   armNot16ByteAligned(pDstLeft) &&
+                   armNot16ByteAligned(pDstRight), OMX_Sts_BadArgErr)
+
+    armRetArgErrIf((iHeight != 16) && (iHeight != 8)&& (iHeight != 4), OMX_Sts_BadArgErr)
+	armRetArgErrIf((iWidth != 16) && (iWidth != 8)&& (iWidth != 4), OMX_Sts_BadArgErr)
+
+    RetValue = armVCM4P10_InterpolateHalfHor_Luma (
+        pSrc - 1,     
+        iSrcStep, 
+        pDstLeft,     
+        iDstStep, 
+        iWidth,   
+        iHeight);
+
+    if (RetValue != OMX_Sts_NoErr)
+    {
+        return RetValue;
+    }
+
+    RetValue = armVCM4P10_InterpolateHalfHor_Luma (
+        pSrc,     
+        iSrcStep, 
+        pDstRight,     
+        iDstStep, 
+        iWidth,   
+        iHeight);
+
+    return RetValue;
+}
+
+/*****************************************************************************
+ *                              END OF FILE
+ *****************************************************************************/
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_InterpolateHalfVer_Luma.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_InterpolateHalfVer_Luma.c
new file mode 100644
index 0000000..3560ff8
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_InterpolateHalfVer_Luma.c
@@ -0,0 +1,123 @@
+/**
+ * 
+ * File Name:  omxVCM4P10_InterpolateHalfVer_Luma.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * Description:
+ * This function will calculate SAD for 4x4 blocks
+ * 
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+
+
+/**
+ * Function:  omxVCM4P10_InterpolateHalfVer_Luma   (6.3.5.5.2)
+ *
+ * Description:
+ * This function performs interpolation for two vertical 1/2-pel positions - 
+ * (0, -1/2) and (0, 1/2) - around a full-pel position. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - Pointer to top-left corner of block used to interpolate in the 
+ *            reconstructed frame plane 
+ *   iSrcStep - Step of the source buffer. 
+ *   iDstStep - Step of the destination (interpolation) buffer; must be a 
+ *            multiple of iWidth. 
+ *   iWidth - Width of the current block; must be equal to either 4, 8, or 16 
+ *   iHeight - Height of the current block; must be equal to either 4, 8, or 16 
+ *
+ * Output Arguments:
+ *   
+ *   pDstUp -Pointer to the interpolation buffer of the -pel position above 
+ *            the current full-pel position (0, -1/2) 
+ *                If iWidth==4, 4-byte alignment required. 
+ *                If iWidth==8, 8-byte alignment required. 
+ *                If iWidth==16, 16-byte alignment required. 
+ *   pDstDown -Pointer to the interpolation buffer of the -pel position below 
+ *            the current full-pel position (0, 1/2) 
+ *                If iWidth==4, 4-byte alignment required. 
+ *                If iWidth==8, 8-byte alignment required. 
+ *                If iWidth==16, 16-byte alignment required. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: 
+ *            pSrc, pDstUp, or pDstDown 
+ *    -    iWidth or iHeight have values other than 4, 8, or 16 
+ *    -    iWidth==4 but pDstUp and/or pDstDown is/are not aligned on a 4-byte boundary 
+ *    -    iWidth==8 but pDstUp and/or pDstDown is/are not aligned on a 8-byte boundary 
+ *    -    iWidth==16 but pDstUp and/or pDstDown is/are not aligned on a 16-byte boundary 
+ *
+ */
+ OMXResult omxVCM4P10_InterpolateHalfVer_Luma(  
+     const OMX_U8*    pSrc, 
+     OMX_U32    iSrcStep, 
+     OMX_U8*    pDstUp, 
+     OMX_U8*    pDstDown, 
+     OMX_U32    iDstStep, 
+     OMX_U32    iWidth, 
+     OMX_U32    iHeight
+)
+{
+    OMXResult   RetValue;
+
+    /* check for argument error */
+    armRetArgErrIf(pSrc == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pDstUp == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pDstDown == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf((iWidth == 4) && 
+                   armNot4ByteAligned(pDstUp) &&
+                   armNot4ByteAligned(pDstDown), OMX_Sts_BadArgErr)
+    armRetArgErrIf((iWidth == 8) && 
+                   armNot8ByteAligned(pDstUp) &&
+                   armNot8ByteAligned(pDstDown), OMX_Sts_BadArgErr)
+    armRetArgErrIf((iWidth == 16) && 
+                   armNot16ByteAligned(pDstUp) &&
+                   armNot16ByteAligned(pDstDown), OMX_Sts_BadArgErr)
+
+    armRetArgErrIf((iHeight != 16) && (iHeight != 8)&& (iHeight != 4), OMX_Sts_BadArgErr)
+	armRetArgErrIf((iWidth != 16) && (iWidth != 8)&& (iWidth != 4), OMX_Sts_BadArgErr)
+
+    RetValue = armVCM4P10_InterpolateHalfVer_Luma(  
+        pSrc - iSrcStep, 
+        iSrcStep, 
+        pDstUp,
+        iDstStep, 
+        iWidth, 
+        iHeight);
+    
+    if (RetValue != OMX_Sts_NoErr)
+    {
+        return RetValue;
+    }
+
+    RetValue = armVCM4P10_InterpolateHalfVer_Luma(  
+        pSrc, 
+        iSrcStep, 
+        pDstDown,
+        iDstStep, 
+        iWidth, 
+        iHeight);
+    
+    return RetValue;
+}
+
+/*****************************************************************************
+ *                              END OF FILE
+ *****************************************************************************/
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_InterpolateLuma.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_InterpolateLuma.c
new file mode 100644
index 0000000..d233735
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_InterpolateLuma.c
@@ -0,0 +1,99 @@
+/**
+ * 
+ * File Name:  omxVCM4P10_InterpolateLuma.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * Description:
+ * This function will calculate Performs quarter-pixel interpolation 
+ * 
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armVC.h"
+#include "armCOMM.h"
+
+/**
+ * Function:  omxVCM4P10_InterpolateLuma   (6.3.3.2.1)
+ *
+ * Description:
+ * Performs quarter-pixel interpolation for inter luma MB. It is assumed that 
+ * the frame is already padded when calling this function. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc -Pointer to the source reference frame buffer 
+ *   srcStep -reference frame step, in bytes; must be a multiple of roi.width 
+ *   dstStep -destination frame step, in bytes; must be a multiple of 
+ *            roi.width 
+ *   dx -Fractional part of horizontal motion vector component in 1/4 pixel 
+ *            unit; valid in the range [0,3] 
+ *   dy -Fractional part of vertical motion vector y component in 1/4 pixel 
+ *            unit; valid in the range [0,3] 
+ *   roi -Dimension of the interpolation region; the parameters roi.width and 
+ *            roi.height must be equal to either 4, 8, or 16. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst -Pointer to the destination frame buffer if roi.width==4,  4-byte 
+ *            alignment required if roi.width==8,  8-byte alignment required 
+ *            if roi.width==16, 16-byte alignment required 
+ *
+ * Return Value:
+ *    If the function runs without error, it returns OMX_Sts_NoErr. 
+ *    If one of the following cases occurs, the function returns 
+ *              OMX_Sts_BadArgErr: 
+ *    pSrc or pDst is NULL. 
+ *    srcStep or dstStep < roi.width. 
+ *    dx or dy is out of range [0,3]. 
+ *    roi.width or roi.height is out of range {4, 8, 16}. 
+ *    roi.width is equal to 4, but pDst is not 4 byte aligned. 
+ *    roi.width is equal to 8 or 16, but pDst is not 8 byte aligned. 
+ *    srcStep or dstStep is not a multiple of 8. 
+ *
+ */
+
+OMXResult omxVCM4P10_InterpolateLuma (
+     const OMX_U8* pSrc,
+     OMX_S32 srcStep,
+     OMX_U8* pDst,
+     OMX_S32 dstStep,
+     OMX_S32 dx,
+     OMX_S32 dy,
+     OMXSize roi        
+ )
+{
+    /* check for argument error */
+    armRetArgErrIf(pSrc == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pDst == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(srcStep < roi.width, OMX_Sts_BadArgErr)
+    armRetArgErrIf(dstStep < roi.width, OMX_Sts_BadArgErr)
+    armRetArgErrIf(dx < 0, OMX_Sts_BadArgErr)
+    armRetArgErrIf(dx > 3, OMX_Sts_BadArgErr)
+    armRetArgErrIf(dy < 0, OMX_Sts_BadArgErr)
+    armRetArgErrIf(dy > 3, OMX_Sts_BadArgErr)
+    armRetArgErrIf((roi.width != 4) && (roi.width != 8) && (roi.width != 16), OMX_Sts_BadArgErr)
+    armRetArgErrIf((roi.height != 4) && (roi.height != 8) && (roi.height != 16), OMX_Sts_BadArgErr)
+    armRetArgErrIf((roi.width == 4) && armNot4ByteAligned(pDst), OMX_Sts_BadArgErr)
+    armRetArgErrIf((roi.width == 8) && armNot8ByteAligned(pDst), OMX_Sts_BadArgErr)
+    armRetArgErrIf((roi.width == 16) && armNot16ByteAligned(pDst), OMX_Sts_BadArgErr)
+    armRetArgErrIf(srcStep & 7, OMX_Sts_BadArgErr)
+    armRetArgErrIf(dstStep & 7, OMX_Sts_BadArgErr) 
+
+    return armVCM4P10_Interpolate_Luma 
+        (pSrc, srcStep, pDst, dstStep, roi.width, roi.height, dx, dy);
+
+}
+
+
+/*****************************************************************************
+ *                              END OF FILE
+ *****************************************************************************/
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_InvTransformDequant_ChromaDC.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_InvTransformDequant_ChromaDC.c
new file mode 100644
index 0000000..92ba031
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_InvTransformDequant_ChromaDC.c
@@ -0,0 +1,102 @@
+/**
+ * 
+ * File Name:  omxVCM4P10_InvTransformDequant_ChromaDC.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * Description:
+ * This function will calculate 4x4 hadamard transform of chroma DC  
+ * coefficients and quantization
+ * 
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armVC.h"
+#include "armCOMM.h"
+
+/**
+ * Function:  omxVCM4P10_InvTransformDequant_ChromaDC   (6.3.5.6.4)
+ *
+ * Description:
+ * This function performs inverse 2x2 Hadamard transform and then dequantizes 
+ * the coefficients. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - Pointer to the 2x2 array of the 2x2 Hadamard-transformed and 
+ *            quantized coefficients.  8 byte alignment required. 
+ *   iQP - Quantization parameter; must be in the range [0,51]. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - Pointer to inverse-transformed and dequantized coefficients.  
+ *            8-byte alignment required. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: pSrc 
+ *    -    pSrc or pDst is not aligned on an 8-byte boundary 
+ *
+ */
+OMXResult omxVCM4P10_InvTransformDequant_ChromaDC(
+	const OMX_S16* 	pSrc,
+	OMX_S16*	pDst,
+	OMX_U32		iQP
+)
+{
+    OMX_INT     i, j;
+    OMX_S32     m[2][2];
+    OMX_S32     QPer, V00, Value;
+
+    /* check for argument error */
+    armRetArgErrIf(pSrc == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(armNot8ByteAligned(pSrc), OMX_Sts_BadArgErr);
+    armRetArgErrIf(pDst == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(armNot8ByteAligned(pDst), OMX_Sts_BadArgErr);
+    armRetArgErrIf(iQP > 51, OMX_Sts_BadArgErr)
+
+    /* Inv Hadamard Transform for 2x2 block */
+    m[0][0] = pSrc[0] + pSrc[1] +  pSrc[2] + pSrc[3];
+    m[0][1] = pSrc[0] - pSrc[1] +  pSrc[2] - pSrc[3];
+    m[1][0] = pSrc[0] + pSrc[1] -  pSrc[2] - pSrc[3];
+    m[1][1] = pSrc[0] - pSrc[1] -  pSrc[2] + pSrc[3];
+
+    /* Quantization */
+    /* Scaling */
+    QPer = iQP / 6;
+    V00 = armVCM4P10_VMatrix [iQP % 6][0];
+
+    for (j = 0; j < 2; j++)
+    {
+        for (i = 0; i < 2; i++)
+        {
+            if (QPer < 1)
+            {
+                Value = (m[j][i] * V00) >> 1;
+            }
+            else
+            {
+                Value = (m[j][i] * V00) << (QPer - 1);
+            }
+
+            pDst[j * 2 + i] = (OMX_S16) Value;
+        }
+    }
+
+    return OMX_Sts_NoErr;
+}
+
+/*****************************************************************************
+ *                              END OF FILE
+ *****************************************************************************/
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_InvTransformDequant_LumaDC.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_InvTransformDequant_LumaDC.c
new file mode 100644
index 0000000..a3b1200
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_InvTransformDequant_LumaDC.c
@@ -0,0 +1,128 @@
+/**
+ * 
+ * File Name:  omxVCM4P10_InvTransformDequant_LumaDC.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * Description:
+ * This function will calculate 4x4 hadamard transform of luma DC coefficients 
+ * and quantization
+ * 
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+
+/**
+ * Function:  omxVCM4P10_InvTransformDequant_LumaDC   (6.3.5.6.3)
+ *
+ * Description:
+ * This function performs inverse 4x4 Hadamard transform and then dequantizes 
+ * the coefficients. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - Pointer to the 4x4 array of the 4x4 Hadamard-transformed and 
+ *            quantized coefficients.  16 byte alignment required. 
+ *   iQP - Quantization parameter; must be in the range [0,51]. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - Pointer to inverse-transformed and dequantized coefficients.  
+ *            16-byte alignment required. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: pSrc 
+ *    -    pSrc or pDst is not aligned on a 16-byte boundary 
+ *
+ */
+OMXResult omxVCM4P10_InvTransformDequant_LumaDC(	
+	const OMX_S16* 	pSrc,
+	OMX_S16*	pDst,
+	OMX_U32		iQP
+)
+{
+    OMX_INT     i, j;
+    OMX_S32     m1[4][4], m2[4][4], Value;
+    OMX_S32     QPer, V;
+
+    /* check for argument error */
+    armRetArgErrIf(pSrc == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pDst == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(iQP > 51, OMX_Sts_BadArgErr)
+    armRetArgErrIf(armNot16ByteAligned(pSrc), OMX_Sts_BadArgErr)
+    armRetArgErrIf(armNot16ByteAligned(pDst), OMX_Sts_BadArgErr)
+
+    /* Inv Hadamard Transform for DC Luma 4x4 block */
+    /* Horizontal */
+    for (i = 0; i < 4; i++)
+    {
+        j = i * 4;
+        
+        m1[i][0] = pSrc[j + 0] + pSrc[j + 2]; /* a+c */
+        m1[i][1] = pSrc[j + 1] + pSrc[j + 3]; /* b+d */
+        m1[i][2] = pSrc[j + 0] - pSrc[j + 2]; /* a-c */
+        m1[i][3] = pSrc[j + 1] - pSrc[j + 3]; /* b-d */
+
+        m2[i][0] = m1[i][0] + m1[i][1]; /* a+b+c+d */
+        m2[i][1] = m1[i][2] + m1[i][3]; /* a+b-c-d */
+        m2[i][2] = m1[i][2] - m1[i][3]; /* a-b-c+d */
+        m2[i][3] = m1[i][0] - m1[i][1]; /* a-b+c-d */
+
+    }
+
+    /* Vertical */
+    for (i = 0; i < 4; i++)
+    {
+        m1[0][i] = m2[0][i] + m2[2][i];
+        m1[1][i] = m2[1][i] + m2[3][i];
+        m1[2][i] = m2[0][i] - m2[2][i];
+        m1[3][i] = m2[1][i] - m2[3][i];
+
+        m2[0][i] = m1[0][i] + m1[1][i];
+        m2[1][i] = m1[2][i] + m1[3][i];
+        m2[2][i] = m1[2][i] - m1[3][i];
+        m2[3][i] = m1[0][i] - m1[1][i];
+    }
+
+    
+    /* Scaling */
+    QPer = iQP / 6;
+    V = armVCM4P10_VMatrix [iQP % 6][0];
+
+    for (j = 0; j < 4; j++)
+    {
+        for (i = 0; i < 4; i++)
+        {
+            if (QPer < 2)
+            {
+                Value = (m2[j][i] * V + (1 << (1 - QPer))) >> (2 - QPer);
+            }
+            else
+            {
+                Value = m2[j][i] * V * (1 << (QPer - 2));
+            }
+                        
+            pDst[j * 4 + i] = (OMX_S16) Value;
+            
+        }
+    }
+    return OMX_Sts_NoErr;
+}
+
+/*****************************************************************************
+ *                              END OF FILE
+ *****************************************************************************/
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_InvTransformResidualAndAdd.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_InvTransformResidualAndAdd.c
new file mode 100644
index 0000000..3303997
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_InvTransformResidualAndAdd.c
@@ -0,0 +1,124 @@
+/**
+ * 
+ * File Name:  omxVCM4P10_InvTransformResidualAndAdd.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * Description:
+ * This function will inverse integer 4x4 transform
+ * 
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+
+/**
+ * Function:  omxVCM4P10_InvTransformResidualAndAdd   (6.3.5.7.1)
+ *
+ * Description:
+ * This function performs inverse an 4x4 integer transformation to produce 
+ * the difference signal and then adds the difference to the prediction to get 
+ * the reconstructed signal. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcPred - Pointer to prediction signal.  4-byte alignment required. 
+ *   pDequantCoeff - Pointer to the transformed coefficients.  8-byte 
+ *            alignment required. 
+ *   iSrcPredStep - Step of the prediction buffer; must be a multiple of 4. 
+ *   iDstReconStep - Step of the destination reconstruction buffer; must be a 
+ *            multiple of 4. 
+ *   bAC - Indicate whether there is AC coefficients in the coefficients 
+ *            matrix. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstRecon -Pointer to the destination reconstruction buffer.  4-byte 
+ *            alignment required. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: 
+ *            pSrcPred, pDequantCoeff, pDstRecon 
+ *    -    pSrcPred is not aligned on a 4-byte boundary 
+ *    -    iSrcPredStep or iDstReconStep is not a multiple of 4. 
+ *    -    pDequantCoeff is not aligned on an 8-byte boundary 
+ *
+ */
+OMXResult omxVCM4P10_InvTransformResidualAndAdd(
+	const OMX_U8* 	pSrcPred, 
+	const OMX_S16* 	pDequantCoeff, 
+	OMX_U8* 	pDstRecon,
+	OMX_U32 	iSrcPredStep, 
+	OMX_U32		iDstReconStep, 
+	OMX_U8		bAC
+)
+{
+    OMX_INT     i, j;
+    OMX_S16     In[16], Out[16];
+    OMX_S32     Value;
+
+    /* check for argument error */
+    armRetArgErrIf(pSrcPred == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(armNot4ByteAligned(pSrcPred), OMX_Sts_BadArgErr)
+    armRetArgErrIf(pDequantCoeff == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(armNot8ByteAligned(pDequantCoeff), OMX_Sts_BadArgErr)
+    armRetArgErrIf(pDstRecon == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(armNot4ByteAligned(pDstRecon), OMX_Sts_BadArgErr)
+    armRetArgErrIf(bAC > 1, OMX_Sts_BadArgErr)
+    armRetArgErrIf(iSrcPredStep == 0 || iSrcPredStep & 3, OMX_Sts_BadArgErr)
+    armRetArgErrIf(iDstReconStep == 0 || iDstReconStep & 3, OMX_Sts_BadArgErr)
+
+    if (bAC)
+    {
+        for (i = 0; i < 16; i++)
+        {
+            In[i] = pDequantCoeff [i];
+        }
+    }
+    else
+    {
+        /* Copy DC */
+        In[0] = pDequantCoeff [0];
+    
+        for (i = 1; i < 16; i++)
+        {
+            In[i] = 0;
+        }
+    }
+
+    /* Residual Transform */
+    armVCM4P10_TransformResidual4x4 (Out, In);    
+    
+    for (j = 0; j < 4; j++)
+    {
+        for (i = 0; i < 4; i++)
+        {
+            /* Add predition */
+            Value = (OMX_S32) Out [j * 4 + i] + pSrcPred [j * iSrcPredStep + i];
+            
+            /* Saturate Value to OMX_U8 */
+            Value = armClip (0, 255, Value);
+
+            pDstRecon[j * iDstReconStep + i] = (OMX_U8) Value;
+        }
+    }
+
+    return OMX_Sts_NoErr;
+}
+
+/*****************************************************************************
+ *                              END OF FILE
+ *****************************************************************************/
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_MEGetBufSize.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_MEGetBufSize.c
new file mode 100644
index 0000000..8c3a5c3
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_MEGetBufSize.c
@@ -0,0 +1,70 @@
+/**
+ * 
+ * File Name:  omxVCM4P10_MEGetBufSize.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Description:
+ * Initialization modules for the vendor specific Motion Estimation structure.
+ * 
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armVC.h"
+#include "armCOMM.h"
+
+/**
+ * Function:  omxVCM4P10_MEGetBufSize   (6.3.5.1.1)
+ *
+ * Description:
+ * Computes the size, in bytes, of the vendor-specific specification 
+ * structure for the omxVCM4P10 motion estimation functions BlockMatch_Integer 
+ * and MotionEstimationMB. 
+ *
+ * Input Arguments:
+ *   
+ *   MEmode - motion estimation mode; available modes are defined by the 
+ *            enumerated type OMXVCM4P10MEMode 
+ *   pMEParams -motion estimation parameters 
+ *
+ * Output Arguments:
+ *   
+ *   pSize - pointer to the number of bytes required for the motion 
+ *            estimation specification structure 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    pMEParams or pSize is NULL. 
+ *    -    an invalid MEMode is specified. 
+ *
+ */
+
+OMXResult omxVCM4P10_MEGetBufSize(
+    OMXVCM4P10MEMode MEMode,
+    const OMXVCM4P10MEParams *pMEParams,
+    OMX_U32 *pSize
+    )
+{
+    armRetArgErrIf(!pMEParams, OMX_Sts_BadArgErr);
+    armRetArgErrIf(!pSize, OMX_Sts_BadArgErr);
+    armRetArgErrIf((MEMode != OMX_VC_M4P10_FAST_SEARCH) && 
+                   (MEMode != OMX_VC_M4P10_FULL_SEARCH), OMX_Sts_BadArgErr);
+    armRetArgErrIf((pMEParams->searchRange16x16 <= 0) || 
+                   (pMEParams->searchRange8x8 <= 0) || 
+                   (pMEParams->searchRange4x4 <= 0), OMX_Sts_BadArgErr);
+                   
+    *pSize = (OMX_INT) sizeof(ARMVCM4P10_MESpec);
+    
+    return OMX_Sts_NoErr;
+}
+
+/* End of file */
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_MEInit.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_MEInit.c
new file mode 100644
index 0000000..58ecc88
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_MEInit.c
@@ -0,0 +1,92 @@
+/**
+ * 
+ * File Name:  omxVCM4P10_MEInit.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Description:
+ * Initialization modules for the vendor specific Motion Estimation structure.
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armVC.h"
+#include "armCOMM.h"
+
+/**
+ * Function:  omxVCM4P10_MEInit   (6.3.5.1.2)
+ *
+ * Description:
+ * Initializes the vendor-specific specification structure required for the 
+ * omxVCM4P10 motion estimation functions:  BlockMatch_Integer and 
+ * MotionEstimationMB. Memory for the specification structure *pMESpec must be 
+ * allocated prior to calling the function, and should be aligned on a 4-byte 
+ * boundary.  The number of bytes required for the specification structure can 
+ * be determined using the function omxVCM4P10_MEGetBufSize. Following 
+ * initialization by this function, the vendor-specific structure *pMESpec 
+ * should contain an implementation-specific representation of all motion 
+ * estimation parameters received via the structure pMEParams, for example  
+ * searchRange16x16, searchRange8x8, etc. 
+ *
+ * Input Arguments:
+ *   
+ *   MEmode - motion estimation mode; available modes are defined by the 
+ *            enumerated type OMXVCM4P10MEMode 
+ *   pMEParams - motion estimation parameters 
+ *   pMESpec - pointer to the uninitialized ME specification structure 
+ *
+ * Output Arguments:
+ *   
+ *   pMESpec - pointer to the initialized ME specification structure 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    pMEParams or pSize is NULL. 
+ *    -    an invalid value was specified for the parameter MEmode 
+ *    -    a negative or zero value was specified for one of the search ranges 
+ *         (e.g.,  pMBParams >searchRange8x8, pMEParams->searchRange16x16, etc.) 
+ *    -    either in isolation or in combination, one or more of the enables or 
+ *         search ranges in the structure *pMEParams were configured such 
+ *         that the requested behavior fails to comply with [ISO14496-10]. 
+ *
+ */
+
+OMXResult omxVCM4P10_MEInit(
+        OMXVCM4P10MEMode MEMode,
+        const OMXVCM4P10MEParams *pMEParams,
+        void *pMESpec
+       )
+{
+    ARMVCM4P10_MESpec *armMESpec = (ARMVCM4P10_MESpec *) pMESpec;
+    
+    armRetArgErrIf(!pMEParams, OMX_Sts_BadArgErr);
+    armRetArgErrIf(!pMESpec, OMX_Sts_BadArgErr);
+    armRetArgErrIf((MEMode != OMX_VC_M4P10_FAST_SEARCH) && 
+                   (MEMode != OMX_VC_M4P10_FULL_SEARCH), OMX_Sts_BadArgErr);
+    armRetArgErrIf((pMEParams->searchRange16x16 <= 0) || 
+                   (pMEParams->searchRange8x8 <= 0) || 
+                   (pMEParams->searchRange4x4 <= 0), OMX_Sts_BadArgErr);
+    
+    armMESpec->MEParams.blockSplitEnable8x8 = pMEParams->blockSplitEnable8x8;
+    armMESpec->MEParams.blockSplitEnable4x4 = pMEParams->blockSplitEnable4x4;
+    armMESpec->MEParams.halfSearchEnable    = pMEParams->halfSearchEnable;
+    armMESpec->MEParams.quarterSearchEnable = pMEParams->quarterSearchEnable;
+    armMESpec->MEParams.intraEnable4x4      = pMEParams->intraEnable4x4;     
+    armMESpec->MEParams.searchRange16x16    = pMEParams->searchRange16x16;   
+    armMESpec->MEParams.searchRange8x8      = pMEParams->searchRange8x8;
+    armMESpec->MEParams.searchRange4x4      = pMEParams->searchRange4x4;
+    armMESpec->MEMode                       = MEMode;
+    
+    return OMX_Sts_NoErr;
+}
+
+/* End of file */
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_MotionEstimationMB.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_MotionEstimationMB.c
new file mode 100644
index 0000000..33dbf3f
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_MotionEstimationMB.c
@@ -0,0 +1,1892 @@
+/**                                                                            x
+ * 
+ * File Name:  omxVCM4P10_MotionEstimationMB.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * Description:
+ * This function perform MB level motion estimation
+ * 
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+
+#define  ARM_VCM4P10_MAX_FRAMES     (15)
+#define  ARM_VCM4P10_MAX_4x4_SAD		(0xffff)
+#define  ARM_VCM4P10_MAX_MODE_VALUE     (0xffffffff)
+#define  ARM_VCM4P10_MAX_MODES          (16)
+#define  ARM_VCM4P10_MB_BLOCK_SIZE      (16)
+#define  ARM_VCM4P10_MEDIAN(a,b,c)      (a>b?a>c?b>c?b:c:a:b>c?a>c?a:c:b)
+#define  ARM_VCM4P10_SHIFT_QP           (12)
+
+#define  ARM_VCM4P10_MVPRED_MEDIAN      (0)
+#define  ARM_VCM4P10_MVPRED_L           (1)
+#define  ARM_VCM4P10_MVPRED_U           (2)
+#define  ARM_VCM4P10_MVPRED_UR          (3)
+
+#define ARM_VCM4P10_MB_BLOCK_SIZE       (16)
+#define ARM_VCM4P10_BLOCK_SIZE          (4)
+#define ARM_VCM4P10_MAX_COST            (1 << 30)
+#define  ARM_VCM4P10_INVALID_BLOCK      (-2)
+
+
+/**
+ * Function: armVCM4P10_CalculateBlockSAD
+ *
+ * Description:
+ *    Calculate SAD value for the selected MB encoding mode and update 
+ * pDstBlockSAD parameter. These SAD values are calculated 4x4 blocks at
+ * a time and in the scan order.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] pSrcMBInfo    - 
+ * [in] pSrcCurrBuf   - 
+ * [in] SrcCurrStep   - 
+ * [in] pSrcRefBufList- 
+ * [in] SrcRefStep    - 
+ * [in] pSrcRecBuf    - 
+ * [in] SrcRecStep    - 
+ * [in] pRefRect      - 
+ * [in] pCurrPointPos - 
+ * [in] Lambda        - 
+ * [in] pMESpec       - 
+ * [in] pMBInter      - 
+ * [in] pMBIntra      - 
+ * [out] pDstBlockSAD - pointer to 16 element array for SAD corresponding to 4x4 blocks
+ * Return Value:
+ * None
+ *
+ */
+
+static OMXResult armVCM4P10_CalculateBlockSAD(
+	OMXVCM4P10MBInfo *pSrcMBInfo, 
+    const OMX_U8 *pSrcCurrBuf,                                  
+	OMX_S32 SrcCurrStep, 
+	const OMX_U8 *pSrcRefBufList[ARM_VCM4P10_MAX_FRAMES],
+	OMX_S32 SrcRefStep,
+	const OMX_U8 *pSrcRecBuf, 
+	OMX_S32 SrcRecStep,
+	const OMXRect *pRefRect,
+	const OMXVCM4P2Coordinate *pCurrPointPos,
+	const OMXVCM4P10MBInfoPtr *pMBInter, 
+	const OMXVCM4P10MBInfoPtr *pMBIntra,
+	OMX_U16 *pDstBlockSAD)
+{
+	OMX_INT		InvalidSAD = 0;
+	OMX_INT		i;
+
+	OMX_U8		Buffer [16*16 + 15];
+	OMX_U8		*pTempDstBuf;
+	OMX_S32		TempDstStep;
+	OMX_U8		*pTempRefBuf;
+	OMX_S32		TempRefStep; 
+
+	/* Temporary buffer to store the predicted mb coefficients */
+	pTempDstBuf = armAlignTo16Bytes(Buffer);
+	TempDstStep = 16;
+
+	/* Update pDstBlockSAD if MB is a valid type */
+	if (pSrcMBInfo)
+	{
+	    OMX_U32     Width=0, Height=0, MaxXPart, MaxYPart,MaxSubXPart,MaxSubYPart;
+	    
+		/* Depending on type of MB, do prediction and fill temp buffer */
+		switch (pSrcMBInfo->mbType)
+		{
+		case OMX_VC_P_16x16:
+				Width = 16;
+				Height = 16;
+				break;
+		case OMX_VC_P_16x8:
+				Width = 16;
+				Height = 8;
+				break;
+		case OMX_VC_P_8x16:
+				Width = 8;
+				Height = 16;
+				break;
+		case OMX_VC_P_8x8:
+				Width = 8;
+				Height = 8;
+				break;
+		case OMX_VC_INTRA_4x4:
+			{
+				/* Create predicted MB Intra4x4 mode */
+				OMX_S32     PredIntra4x4Mode [5][9];
+				OMX_S32		x, y, Block8x8, Block4x4, BlockX, BlockY;
+				OMX_U8      pSrcYBuff [(16*3)*(16*2)];
+				OMX_U8		*pSrcY;
+				OMX_S32     StepSrcY;
+				OMX_S32		availability;
+
+				for (y = 0; y < 5; y++)
+				{
+					for (x = 0; x < 9; x++)
+					{
+						/* 
+						 * Initialize with value of ARM_VCM4P10_INVALID_BLOCK, to mean this 
+						 * 4x4 block is not available 
+						 */
+						PredIntra4x4Mode [y][x] = ARM_VCM4P10_INVALID_BLOCK;
+					}
+				}
+
+				/* Replace ARM_VCM4P10_INVALID_BLOCK value with available MBs values*/
+				for (x = 0; x < 4; x++)
+				{
+					/* Store values of b0, b1, b2, b3 */
+					if (pMBIntra[1] != NULL)
+					{
+						PredIntra4x4Mode [0][x + 1] = 
+							pMBIntra[1]->pIntra4x4PredMode[3*4 + x];            
+					}
+			        
+					/* Store values of d0, d1, d2, d3 */
+					if (pMBIntra[3] != NULL)
+					{
+						PredIntra4x4Mode [0][x + 5] = 
+							pMBIntra[3]->pIntra4x4PredMode[3*4 + x];
+					}
+				}
+		    
+				/* Store values of c3 */
+				if (pMBIntra[2] != NULL)
+				{
+					PredIntra4x4Mode [0][0] = pMBIntra[2]->pIntra4x4PredMode[15];
+				}
+		    
+				for (y = 0; y < 4; y++)
+				{
+					/* Store values of a0, a1, a2, a3 */
+					if (pMBIntra[0] != NULL)
+					{
+						PredIntra4x4Mode [y + 1][0] = 
+							pMBIntra[0]->pIntra4x4PredMode[y*4 + 3];
+					}
+				}
+		        
+				/*
+				 * Update neighbouring Pred mode array which will be used for
+				 * prediction of Intra4x4 modes.
+				 */
+			    
+				pSrcY = pSrcYBuff;
+				StepSrcY = 16 * 3;
+				for (y = 0; y < (16 * 2); y++)
+				{
+					for (x = 0; x < (16 * 3); x++)
+					{
+						pSrcY [StepSrcY * y + x] = 
+							pSrcRecBuf [SrcRecStep * (y - 16) + x - 16];
+					}
+				}
+
+		    
+				/* for each 8x8 block */
+				for (Block8x8 = 0; Block8x8 < 4; Block8x8++)
+				{
+					/* for each 4x4 block inside 8x8 block */
+					for (Block4x4 = 0; Block4x4 < 4; Block4x4++)
+					{
+						/* Get block cordinates from 8x8 block index and 4x4 block index */
+						BlockX = ((Block8x8 & 1) << 1) + (Block4x4 & 1);
+						BlockY = ((Block8x8 >> 1) << 1) + (Block4x4 >> 1);
+					    
+						/* Add offset to point to start of current MB in the array pIntra4x4PredMode */
+						x = BlockX + 1;
+						y = BlockY + 1;
+
+						availability = 0;
+
+						/* Check for availability of LEFT Block */
+						if (PredIntra4x4Mode [y][x - 1] != ARM_VCM4P10_INVALID_BLOCK)
+						{
+							availability |= OMX_VC_LEFT;        
+						}
+
+						/* Check for availability of UPPER Block */
+						if (PredIntra4x4Mode [y - 1][x] != ARM_VCM4P10_INVALID_BLOCK)
+						{
+							availability |= OMX_VC_UPPER;        
+						}
+
+						/* Check for availability of UPPER LEFT Block */
+						if (PredIntra4x4Mode [y - 1][x - 1] != ARM_VCM4P10_INVALID_BLOCK)
+						{
+							availability |= OMX_VC_UPPER_LEFT;        
+						}
+						
+						PredIntra4x4Mode [y][x] = pSrcMBInfo->pIntra4x4PredMode[BlockY*4+BlockX];
+						x = BlockX * 4;
+						y = BlockY * 4;
+
+						pSrcY = pSrcYBuff + 16 * StepSrcY + 16 + y * StepSrcY + x;
+
+						omxVCM4P10_PredictIntra_4x4(
+							 pSrcY - 1,
+							 pSrcY - StepSrcY,
+							 pSrcY - StepSrcY - 1,
+							 pTempDstBuf + x + y * TempDstStep,
+							 StepSrcY,
+							 TempDstStep,
+							 pSrcMBInfo->pIntra4x4PredMode[BlockY*4+BlockX],
+							 availability);
+
+						for (BlockY=0;BlockY<4;BlockY++)
+						{
+							for(BlockX=0;BlockX<4;BlockX++)
+							{
+								pSrcY [BlockY * StepSrcY + BlockX] = 
+									(OMX_U8)(*(pTempDstBuf + x + y * TempDstStep + BlockY * TempDstStep + BlockX));
+							}
+						}
+
+					}
+				}
+				break;
+			}
+		case OMX_VC_INTRA_16x16:
+			{
+				OMX_U32     MBPosX = pCurrPointPos->x >> 4;        
+				OMX_U32     MBPosY = pCurrPointPos->y >> 4;        
+				OMX_U32		availability = 0;
+
+				/* Check for availability of LEFT MB */
+				if ((MBPosX != 0) && (pMBIntra [0] != 0 || pMBInter [0] != 0))
+				{
+					availability |= OMX_VC_LEFT;        
+				}
+
+				/* Check for availability of UP MB */
+				if ((MBPosY != 0) && (pMBIntra [1] != 0 || pMBInter [1] != 0))
+				{
+					availability |= OMX_VC_UPPER;        
+				}
+
+				/* Check for availability of UP-LEFT MB */
+				if ((MBPosX > 0) && (MBPosY > 0) && 
+					(pMBIntra [2] != 0 || pMBInter [2] != 0))
+				{
+					availability |= OMX_VC_UPPER_LEFT;        
+				}
+
+				omxVCM4P10_PredictIntra_16x16(
+						pSrcRecBuf - 1, 
+						pSrcRecBuf - SrcRecStep, 
+						pSrcRecBuf - SrcRecStep - 1, 
+						pTempDstBuf, 
+						SrcRecStep, 
+						TempDstStep, 
+						pSrcMBInfo->Intra16x16PredMode, 
+						availability);
+				
+				break;
+			}
+
+		case OMX_VC_INTER_SKIP:
+		case OMX_VC_PREF0_8x8:
+		case OMX_VC_INTRA_PCM:
+		default:
+			/* These cases will update pDstBlockSAD with MAX value */
+			InvalidSAD = 1;
+			break;
+		}
+
+		/* INTER MB */
+		if ((pSrcMBInfo->mbType == OMX_VC_P_16x16) ||
+			(pSrcMBInfo->mbType == OMX_VC_P_8x16) ||
+			(pSrcMBInfo->mbType == OMX_VC_P_16x8) ||
+			(pSrcMBInfo->mbType == OMX_VC_P_8x8))
+		{
+        	const OMX_U8		*pTempSrcBuf;
+        	OMX_S32		TempSrcStep;
+        	OMX_S32		mvx,mvy;
+        	OMX_U32		PartX, PartY, SubPartX, SubPartY;
+        	
+			TempSrcStep = SrcRefStep;
+
+			MaxXPart = 16/Width;
+			MaxYPart = 16/Height;
+
+
+			for (PartY = 0; PartY < MaxYPart; PartY++)
+			{
+				for (PartX = 0; PartX < MaxXPart; PartX++)
+				{
+
+					pTempSrcBuf = pSrcRefBufList[pSrcMBInfo->pRefL0Idx[PartY * 2 + PartX]];
+
+					if (MaxXPart == 2 && MaxYPart == 2)
+					{
+        				switch (pSrcMBInfo->subMBType[PartY*2+PartX])
+        				{
+        				    case OMX_VC_SUB_P_8x8:
+								Width = 8;
+								Height = 8;
+            				    break;
+        				    case OMX_VC_SUB_P_8x4:
+								Width = 8;
+								Height = 4;
+            				    break;
+        				    case OMX_VC_SUB_P_4x8:
+								Width = 4;
+								Height = 8;
+            				    break;
+        				    case OMX_VC_SUB_P_4x4:
+								Width = 4;
+								Height = 4;
+            				    break;
+        				    default:
+								/* Default */
+								Width = 4;
+								Height = 4;
+        				    break;
+        				}
+					
+    				    MaxSubXPart = 8/Width;
+    				    MaxSubYPart = 8/Height;
+
+						for (SubPartY = 0; SubPartY < MaxSubYPart; SubPartY++)
+						{
+							for (SubPartX = 0; SubPartX < MaxSubXPart; SubPartX++)
+							{
+								mvx = pSrcMBInfo->pMV0 [2*PartY + SubPartY][2*PartX + SubPartX].dx;
+								mvy = pSrcMBInfo->pMV0 [2*PartY + SubPartY][2*PartX + SubPartX].dy;
+								armVCM4P10_Interpolate_Luma(
+									pTempSrcBuf + (8*PartX + 4*SubPartX + (mvx/4)) + (8*PartY + 4*SubPartY + (mvy/4)) * TempSrcStep,
+									TempSrcStep,
+									pTempDstBuf + (8*PartX + 4*SubPartX) + (8*PartY + 4*SubPartY) * TempDstStep,
+									TempDstStep,
+									Width,
+									Height,
+									mvx & 3,
+									mvy & 3
+									);
+							}
+						}
+					}
+					else
+					{
+
+						mvx = pSrcMBInfo->pMV0 [2*PartY][2*PartX].dx;
+						mvy = pSrcMBInfo->pMV0 [2*PartY][2*PartX].dy;
+						armVCM4P10_Interpolate_Luma(
+							pTempSrcBuf + (8*PartX + (mvx/4)) + (8*PartY + (mvy/4)) * TempSrcStep,
+							TempSrcStep,
+							pTempDstBuf + (8*PartX) + (8*PartY) * TempDstStep,
+							TempDstStep,
+							Width,
+							Height,
+							mvx & 3,
+							mvy & 3
+							);
+
+					}
+				}
+			}
+		}
+	}
+	else
+	{
+		InvalidSAD = 1;
+	}
+
+	/* Calculate SAD from predicted buffer */
+	if (!InvalidSAD)
+	{
+	    OMX_U32     x8x8, y8x8, x4x4, y4x4, Block8x8, Block4x4;
+	    OMX_S32     SAD;
+	    
+		pTempRefBuf = pTempDstBuf;
+		TempRefStep = 16;
+
+		/* SAD for each 4x4 block in scan order */
+		for (Block8x8 = 0; Block8x8 < 4; Block8x8++)
+		{
+			x8x8 = 8*(Block8x8 & 1);
+			y8x8 = 8*(Block8x8 >> 1);
+			for (Block4x4 = 0; Block4x4 < 4; Block4x4++)
+			{
+				x4x4 = 4*(Block4x4 & 1);
+				y4x4 = 4*(Block4x4 >> 1);
+
+				armVCCOMM_SAD(	
+					pSrcCurrBuf + (x8x8 + x4x4) + (y8x8 + y4x4) * SrcCurrStep, 
+					SrcCurrStep,
+					pTempRefBuf + (x8x8 + x4x4) + (y8x8 + y4x4) * TempRefStep,
+					TempRefStep,
+    				&SAD,
+    				4, /* Height */
+    				4); /* Width */
+                *(pDstBlockSAD + 4 * Block8x8 + Block4x4) = (SAD < 0x7fff) ? (OMX_U16) SAD : ARM_VCM4P10_MAX_MODE_VALUE;   			    
+ 			}
+		}
+	}
+	else
+	{
+		/* Fill SADs with max values and return*/
+		for (i = 0; i < 16; i++)
+		{
+			pDstBlockSAD [i] = ARM_VCM4P10_MAX_4x4_SAD;
+		}
+	}
+	return OMX_Sts_NoErr;
+}
+
+
+
+/**
+ * Function: armVCM4P10_Mode4x4Decision
+ *
+ * Description:
+ *    Intra 4x4 Mode decision by calculating cost for all possible modes and
+ * choosing the best mode
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] pSrcCurrBuf    - Pointer to the start of current Macroblock
+ * [in] SrcCurrStep - Step size of the pointer pSrcCurrBuf
+ * [in/out] pSrcDstMBCurr - Pointer to the OMXVCM4P10MBInfo which will be updated for
+ *                    field pIntra4x4PredMode of the current block.
+ * [in] Block8x8    - Index 8x8 block in which current 4x4 block belongs
+ * [in] Block4x4    - Index of current 4x4 block
+ * [in/out] pPredIntra4x4SrcY - Pointer to current block location in buffer 
+ *                    with reconstructed values. This will be modified by this
+ *                    function with best mode predicted values 
+ * [in] StepPredIntra4x4SrcY  - Step size of the pointer pPredIntra4x4SrcY
+ * [in] pIntra4x4PredMode     - Array of Intra 4x4 prediction mode for the MB.
+ *                              Current MB modes starts at [1,1].
+ * [in] pBestCost   - Cost for the Best Intra 4x4 mode
+ * Return Value:
+ * None
+ *
+ */
+static OMXVoid armVCM4P10_Mode4x4Decision (
+    const OMX_U8* pSrcCurrBuf,   
+    OMX_S32 SrcCurrStep,
+    OMXVCM4P10MBInfo *pSrcDstMBCurr,
+    OMX_S32 Block8x8,
+    OMX_S32 Block4x4,
+    OMX_U8  *pPredIntra4x4SrcY,
+    OMX_S32 StepPredIntra4x4SrcY,
+    OMX_S32 pIntra4x4PredMode [][9],
+    OMX_S32 *pBestCost
+)
+{
+    OMX_S32     i, j, x, y, BlockX, BlockY, mode;
+    OMX_S32     Cost, BestCost;
+    OMX_U8      *pSrcY;
+    OMX_S32     StepSrcY;
+    OMX_S32     availability = 0;
+    OMX_U8      pPredBlock [4*4];
+    OMXResult   Ret = OMX_Sts_Err;
+
+    /* Get block cordinates from 8x8 block index and 4x4 block index */
+    BlockX = ((Block8x8 & 1) << 1) + (Block4x4 & 1);
+    BlockY = ((Block8x8 >> 1) << 1) + (Block4x4 >> 1);
+    
+    /* Add offset to point to start of current MB in the array pIntra4x4PredMode */
+    x = BlockX + 1;
+    y = BlockY + 1;
+
+    /* Check for availability of LEFT Block */
+    if (pIntra4x4PredMode [y][x - 1] != ARM_VCM4P10_INVALID_BLOCK)
+    {
+        availability |= OMX_VC_LEFT;        
+    }
+
+    /* Check for availability of UPPER Block */
+    if (pIntra4x4PredMode [y - 1][x] != ARM_VCM4P10_INVALID_BLOCK)
+    {
+        availability |= OMX_VC_UPPER;        
+    }
+
+    /* Check for availability of UPPER LEFT Block */
+    if (pIntra4x4PredMode [y - 1][x - 1] != ARM_VCM4P10_INVALID_BLOCK)
+    {
+        availability |= OMX_VC_UPPER_LEFT;        
+    }
+
+    pSrcY = pPredIntra4x4SrcY + 
+            StepPredIntra4x4SrcY * (BlockY << 2) + 
+            (BlockX << 2);
+            
+    StepSrcY = StepPredIntra4x4SrcY;
+              
+    x = BlockX * 4;
+    y = BlockY * 4;
+
+    Cost = BestCost = ARM_VCM4P10_MAX_COST;
+    
+    /* Go through each mode for minim cost */
+    for (mode = 0; mode < 9; mode++)
+    {
+        Ret = omxVCM4P10_PredictIntra_4x4(
+             pSrcY - 1,
+             pSrcY - StepSrcY,
+             pSrcY - StepSrcY - 1,
+             pPredBlock,
+             StepSrcY,
+             4,
+             (OMXVCM4P10Intra4x4PredMode) mode,
+             availability);
+             
+        if (Ret == OMX_Sts_NoErr)
+        {            
+            armVCCOMM_SAD(    
+                pSrcCurrBuf + (y * SrcCurrStep) + x,
+                SrcCurrStep,
+                pPredBlock,
+                4,
+                &Cost,
+                4,
+                4);
+            
+            if (Cost < BestCost)
+            {
+                BestCost = Cost;
+                
+                pIntra4x4PredMode [BlockY + 1][BlockX + 1] = 
+                    (OMXVCM4P10Intra4x4PredMode) mode;                
+                pSrcDstMBCurr->pIntra4x4PredMode [BlockY * 4 + BlockX] = 
+                    (OMXVCM4P10Intra4x4PredMode) mode;
+
+                for (j = 0; j < 4; j++)
+                {
+                    for (i = 0; i < 4; i++)
+                    {
+                        pSrcY [StepSrcY * j + i] = pPredBlock [4 * j + i];
+                    }
+                }
+            }
+        }
+    }
+
+    *pBestCost = BestCost;
+    return;
+}
+
+/**
+ * Function: armVCM4P10_SetMotionVectorPredictor
+ *
+ * Description:
+ *    This function will do the MV Prediction for Inter MBs
+ *
+ * Parameters:
+ * [in] BlockStartX - Start X index in integer pels in current Block
+ * [in] BlockStartY - Start Y index in integer pels in current Block
+ * [in] BlockSizeX  - Width of current block
+ * [in] BlockSizeY  - Height of current block
+ * [in] RefFrame    - Index of the reference frame for prediction
+ * [in] pRefFrArr   - Pointer to Ref array storing neighbouring MVs for MV prediction
+ * [in] pMVArr      - Pointer to MV array storing neighbouring MVs for MV prediction
+ * [out] pMVPred    - Pointer to predicted MVs
+ * Remarks:
+ *
+ * Return Value:
+ * None
+ *
+ */
+static OMXVoid armVCM4P10_SetMotionVectorPredictor(
+    OMX_U32 BlockStartX, 
+    OMX_U32 BlockStartY,
+    OMX_U32 BlockSizex,
+    OMX_U32 BlockSizey,
+    OMX_S32 RefFrame,
+    OMX_S32 pRefFrArr[][6], 
+    OMXVCMotionVector pMVArr[][12],
+    OMXVCMotionVector *pMVPred
+)
+{
+    OMX_S32     RFrameL;       /* Left */
+    OMX_S32     RFrameU;       /* Up */
+    OMX_S32     RFrameUR;      /* Up-Right */
+
+    OMX_S32     BlockX, BlockY, BlockXFr, BlockYFr, MVPredType;
+    OMX_S32     BlockXPlusOff, BlockXPlusOffFr, BlockXMin1Fr, BlockYMin1Fr;
+    
+    BlockX = 4 + (BlockStartX >> 2);
+    BlockY = 4 + (BlockStartY >> 2); 
+    BlockXPlusOff = BlockX + (BlockSizex >> 2);
+    
+    BlockXFr = BlockX >> 1;  
+    BlockYFr = BlockY >> 1;  
+    BlockXMin1Fr = (BlockX - 1) >> 1;  
+    BlockYMin1Fr = (BlockY - 1) >> 1;  
+    BlockXPlusOffFr = BlockXPlusOff >> 1;
+    
+    MVPredType = ARM_VCM4P10_MVPRED_MEDIAN;
+
+    RFrameL = pRefFrArr [BlockYFr][BlockXMin1Fr];
+    RFrameU = pRefFrArr [BlockYMin1Fr][BlockXFr];
+    RFrameUR = pRefFrArr [BlockYMin1Fr][BlockXPlusOffFr];
+
+    if (RFrameUR == ARM_VCM4P10_INVALID_BLOCK)
+    {
+        RFrameUR = pRefFrArr [BlockYMin1Fr][BlockXMin1Fr];
+    }
+
+    /* 
+     * Prediction if only one of the neighbors uses the reference frame
+     * we are checking
+     */
+  
+    if (RFrameL == RefFrame && RFrameU != RefFrame && RFrameUR != RefFrame)
+    {
+        MVPredType = ARM_VCM4P10_MVPRED_L;
+    }
+    else if(RFrameL != RefFrame && RFrameU == RefFrame && RFrameUR != RefFrame)
+    {
+        MVPredType = ARM_VCM4P10_MVPRED_U;
+    }
+    else if(RFrameL != RefFrame && RFrameU != RefFrame && RFrameUR == RefFrame)
+    {
+        MVPredType = ARM_VCM4P10_MVPRED_UR;
+    }
+
+    /* Directional predictions  */
+    else if(BlockSizex == 8 && BlockSizey == 16)
+    {
+        if(BlockStartX == 0)
+        {
+            if(RFrameL == RefFrame)
+            {
+                MVPredType = ARM_VCM4P10_MVPRED_L;
+            }
+        }
+        else
+        {
+            if (RFrameUR == RefFrame)
+            {
+                MVPredType = ARM_VCM4P10_MVPRED_UR;
+            }
+        }
+    }
+    else if(BlockSizex == 16 && BlockSizey == 8)
+    {
+        if(BlockStartY == 0)
+        {
+            if(RFrameU == RefFrame)
+            {
+                MVPredType = ARM_VCM4P10_MVPRED_U;
+            }
+        }
+        else
+        {
+            if(RFrameL == RefFrame)
+            {
+                MVPredType = ARM_VCM4P10_MVPRED_L;
+            }
+        }
+    }
+
+    switch (MVPredType)
+    {
+    case ARM_VCM4P10_MVPRED_MEDIAN:
+        if (!(pRefFrArr [BlockYMin1Fr][BlockXMin1Fr] == ARM_VCM4P10_INVALID_BLOCK || 
+              pRefFrArr [BlockYMin1Fr][BlockXFr] == ARM_VCM4P10_INVALID_BLOCK || 
+              pRefFrArr [BlockYMin1Fr][BlockXPlusOffFr] == ARM_VCM4P10_INVALID_BLOCK))
+        {
+            pMVPred->dx = pMVArr [BlockY][BlockX - 1].dx;
+            pMVPred->dy = pMVArr [BlockY][BlockX - 1].dy;
+        }
+        else
+        {
+            pMVPred->dx = 
+                ARM_VCM4P10_MEDIAN(pMVArr [BlockY][BlockX - 1].dx, 
+                pMVArr [BlockY - 1][BlockX].dx, 
+                pMVArr [BlockY - 1][BlockXPlusOff].dx);
+            pMVPred->dy = 
+                ARM_VCM4P10_MEDIAN(pMVArr [BlockY][BlockX - 1].dy, 
+                pMVArr [BlockY - 1][BlockX].dy, 
+                pMVArr [BlockY - 1][BlockXPlusOff].dy);
+        }
+        break;
+      
+    case ARM_VCM4P10_MVPRED_L:
+        pMVPred->dx = pMVArr [BlockY][BlockX - 1].dx;
+        pMVPred->dy = pMVArr [BlockY][BlockX - 1].dy;
+        break;
+    case ARM_VCM4P10_MVPRED_U:
+        pMVPred->dx = pMVArr [BlockY - 1][BlockX].dx;
+        pMVPred->dy = pMVArr [BlockY - 1][BlockX].dy;
+        break;
+    case ARM_VCM4P10_MVPRED_UR:
+        if (pRefFrArr [BlockYMin1Fr][BlockXPlusOffFr] != ARM_VCM4P10_INVALID_BLOCK)
+        {
+            pMVPred->dx = pMVArr [BlockY - 1][BlockXPlusOff].dx;
+            pMVPred->dy = pMVArr [BlockY - 1][BlockXPlusOff].dy;
+        }
+        else
+        {
+            pMVPred->dx = pMVArr [BlockY - 1][BlockX - 1].dx;
+            pMVPred->dy = pMVArr [BlockY - 1][BlockX - 1].dy;
+        }
+        break;
+    default:
+        break;
+    }
+    
+    return;
+}
+
+/**
+ * Function: armVCM4P10_BlockMotionSearch
+ *
+ * Description:
+ *    Gets best MV for the current block
+ *
+ * Parameters:
+ * [in] pSrcCurrBuf    - Pointer to the start of luma component of current Macroblock 
+ * [in] SrcCurrStep - Step size for the pointer pSrcCurrBuf 
+ * [in] pSrcRefY    - Pointer to the start of luma component of co-located reference MB
+ * [in] nSrcRefStep - Step size for the pointer pSrcRefY 
+ * [in] pRefRect   Pointer to the valid reference rectangle; relative to the image origin.
+ * [in] pCurrPointPos   Position of the current macroblock in the current plane.
+ * [in] pMESpec     - Motion estimation structure
+ * [in] pMBInter    - Array, of dimension four, containing pointers to information associated with four
+ *                    adjacent type INTER MBs (Left, Top, Top-Left, Top-Right). 
+ * [in] nLamda      - For calculating the cost
+ * [out] pBestCost  - Minimum cost for encoding current block 
+ * [out] pBestMV    - MV corresponding to best cost
+ * [in] BlockStartX - Block start X index in integer pels
+ * [in] BlockStartY - Block start Y index in integer pels
+ * [in] BlockSizeX  - Width of current block
+ * [in] BlockSizeY  - Height of current block
+ * [in] RefFrame    - Index of the reference frame for prediction
+ * [in] pRefFrArr   - Pointer to reference frame array storing neighbouring MVs for prediction
+ * [in] pMVArr      - Pointer to MV array storing neighbouring MVs for MV prediction
+ * [in] pMVPred     - Pointer to MV predicted from neighbour MVs
+ * Remarks:
+ *
+ * Return Value:
+ * OMXResult
+ *
+ */
+static OMXResult armVCM4P10_BlockMotionSearch(
+    const OMX_U8* pSrcCurrBuf, 
+    OMX_S32 SrcCurrStep, 
+    const OMX_U8* pSrcRefY, 
+    OMX_S32 nSrcRefStep, 
+	const OMXRect *pRefRect,
+	const OMXVCM4P2Coordinate *pCurrPointPos,
+    void* pMESpec, 
+
+    OMX_S32 nLamda,
+    OMX_S32* pBestCost, 
+    OMXVCMotionVector *pBestMV,
+    
+    OMX_U32 BlockStartX, 
+    OMX_U32 BlockStartY,
+    OMX_U32 BlockSizeX,
+    OMX_U32 BlockSizeY,
+    OMX_S32 RefFrame,
+    OMX_S32 pRefFrArr [][6], 
+    OMXVCMotionVector pMVArr [][12],
+    OMXVCMotionVector *pMVPred
+   )
+{
+
+    OMXVCMotionVector   MVCalculated, MVCandidate;
+    OMX_S32             Cost;
+    OMXResult           RetValue;
+    OMXVCM4P10MEParams  *pMEParams;    
+	OMXVCM4P2Coordinate CurrBlockPos;
+
+    /* Get Predicted Motion Vectors */
+    armVCM4P10_SetMotionVectorPredictor (
+        BlockStartX, 
+        BlockStartY,
+        BlockSizeX, 
+        BlockSizeY,
+        RefFrame,
+        pRefFrArr,   
+        pMVArr,      
+        pMVPred);
+
+    /* Initialize candidate MV */
+    MVCandidate.dx = 0;
+    MVCandidate.dy = 0;
+    
+    CurrBlockPos.x = pCurrPointPos->x + BlockStartX;
+    CurrBlockPos.y = pCurrPointPos->y + BlockStartY;
+
+    /* Block Match Integer */
+    RetValue = omxVCM4P10_BlockMatch_Integer (
+        pSrcCurrBuf, 
+        SrcCurrStep, 
+        pSrcRefY, 
+        nSrcRefStep, 
+        pRefRect, 
+        &CurrBlockPos, 
+        BlockSizeX, 
+        BlockSizeY, 
+        nLamda, 
+        pMVPred, 
+        &MVCandidate, 
+        &MVCalculated, 
+        &Cost, 
+        pMESpec);
+    
+    /* updated BestMV*/
+    /**pBestCost = Cost;
+    pBestMV->dx = MVCalculated.dx;
+    pBestMV->dy = MVCalculated.dy;*/
+
+    pMEParams = (OMXVCM4P10MEParams *) pMESpec;
+    
+    /* Block Match Half pel */
+    if (pMEParams->halfSearchEnable)
+    {
+        RetValue = omxVCM4P10_BlockMatch_Half(
+            pSrcCurrBuf, 
+            SrcCurrStep, 
+            pSrcRefY, 
+            nSrcRefStep, 
+            BlockSizeX, 
+            BlockSizeY, 
+            nLamda, 
+            pMVPred, 
+            &MVCalculated,        /* input/output*/
+            &Cost);
+    }
+
+    /* Block Match Quarter pel */
+    if (pMEParams->quarterSearchEnable)
+    {
+        RetValue = omxVCM4P10_BlockMatch_Quarter(
+            pSrcCurrBuf, 
+            SrcCurrStep, 
+            pSrcRefY, 
+            nSrcRefStep, 
+            BlockSizeX, 
+            BlockSizeY, 
+            nLamda, 
+            pMVPred, 
+            &MVCalculated, 
+            &Cost);
+    }
+
+    /* updated Best Cost and Best MV */
+    *pBestCost = Cost;
+    pBestMV->dx = MVCalculated.dx;
+    pBestMV->dy = MVCalculated.dy;
+
+    /*
+     * Skip MB cost calculations of 16x16 inter mode
+     */
+    return RetValue;
+}
+
+/**
+ * Function: armVCM4P10_PartitionME
+ *
+ * Description:
+ *    Gets best cost for the current partition
+ *
+ * Parameters:
+ * [in] pSrcCurrBuf    - Pointer to the start of luma component of current Macroblock 
+ * [in] SrcCurrStep - Step size for the pointer pSrcCurrBuf 
+ * [in] pSrcRefBufList    - Pointer to List of ref buffer of co-located reference MB
+ * [in] nSrcRefStep - Step size for the pointer pSrcRefY 
+ * [in] pRefRect   Pointer to the valid reference rectangle; relative to the image origin.
+ * [in] pCurrPointPos   Position of the current macroblock in the current plane.
+ * [in] pMESpec     - Motion estimation structure
+ * [in] PartWidth   - Width of current partition
+ * [in] PartHeight  - Height of current partition
+ * [in] BlockWidth  - Width of current block
+ * [in] BlockHeight - Height of current block
+ * [in] PartStartX  - Partition start X index in integer pels
+ * [in] PartStartY  - Partition start Y index in integer pels
+ * [in] pMVArr      - Pointer to MV array storing neighbouring MVs for MV prediction
+ * [in] pRefFrArr   - Pointer to reference frame array storing neighbouring MVs for prediction
+ * [in] Lambda      - For calculating the cost
+ * [out] pCost      - Pointer to cost for Inter MB
+ *
+ * Return Value:
+ * OMXResult
+ *
+ */
+static OMXResult armVCM4P10_PartitionME (
+    const OMX_U8* pSrcCurrBuf,   
+    OMX_S32 SrcCurrStep,
+	const OMX_U8 *pSrcRefBufList[ARM_VCM4P10_MAX_FRAMES],
+	OMX_S32 SrcRefStep,
+	const OMXRect *pRefRect,
+	const OMXVCM4P2Coordinate *pCurrPointPos,
+    void* pMESpec, 
+
+    OMX_S32 PartWidth,
+    OMX_S32 PartHeight,
+    OMX_S32 BlockWidth,
+    OMX_S32 BlockHeight,
+    OMX_S32 PartStartX, 
+    OMX_S32 PartStartY,
+
+    OMXVCMotionVector pMVArr [][12],
+    OMX_S32 pRefFrArr [][6],
+    OMXVCMotionVector pMVPredArr [][4],
+
+    OMX_S32 Lambda,
+    OMX_S32 *pCost
+)
+{
+    OMX_U32     x, y, i, j, ref, OffX, OffY, OffSrc, OffRef;
+    OMX_S32     BlockCost, PartitionCost, BestCost;
+    OMX_S32     BestRefFrame=0;
+    OMXVCMotionVector   BestMV [4][4];
+    OMXVCMotionVector   BestMVPred [4][4];
+    OMXVCMotionVector   MVPred;
+    OMXVCMotionVector   DstMV;
+
+    BestCost = ARM_VCM4P10_MAX_COST;
+    
+    for (ref = 0; ref < ARM_VCM4P10_MAX_FRAMES; ref++)
+    {
+        if (pSrcRefBufList [ref] == NULL)
+        {
+        	/* No reference frame, continue */
+        	continue;
+        }
+
+        PartitionCost = 0;
+        
+        for (y = 0; y < PartHeight; y += BlockHeight)
+        {
+            for (x = 0; x < PartWidth; x += BlockWidth)
+            {
+            	OffSrc = SrcCurrStep * (PartStartY + y) + PartStartX + x;
+            	OffRef = SrcRefStep * (PartStartY + y) + PartStartX + x;
+                armVCM4P10_BlockMotionSearch (
+                    pSrcCurrBuf + OffSrc, 
+                    SrcCurrStep, 
+                    pSrcRefBufList [ref] + OffRef, 
+                    SrcRefStep, 
+                    pRefRect,
+                    pCurrPointPos,
+                    pMESpec, 
+
+                    Lambda,
+                    &BlockCost, 
+                    &DstMV,
+                    
+                    x + PartStartX, 
+                    y + PartStartY,
+                    BlockWidth,
+                    BlockHeight,
+                    ref,
+                    pRefFrArr, 
+                    pMVArr,
+                    &MVPred);
+
+                PartitionCost += BlockCost;
+				
+				OffX = (PartStartX + x) >> 2;
+				OffY = (PartStartY + y) >> 2;
+				
+	            for (j = 0; j < (BlockHeight >> 2); j++)
+	            {
+	                for (i = 0; i < (BlockWidth >> 2); i++)
+	                {
+	                    pMVArr [4 + OffY + j][4 + OffX + i].dx = DstMV.dx;
+	                    pMVArr [4 + OffY + j][4 + OffX + i].dy = DstMV.dy;
+	                    pMVPredArr [OffY + j][OffX + i].dx = MVPred.dx;
+	                    pMVPredArr [OffY + j][OffX + i].dy = MVPred.dy;
+	                }
+	            }
+
+				pRefFrArr [2 + (OffY >> 1)][2 + (OffX >> 1)] = ref;
+	            for (j = 0; j < (BlockHeight >> 3); j++)
+	            {
+	                for (i = 0; i < (BlockWidth >> 3); i++)
+	                {
+			            pRefFrArr [2 + (OffY >> 1) + j][2 + (OffX >> 1) + i] = ref;
+	                }
+	            }
+
+            }
+        }
+
+		/*
+		 * If PartitionCost is less for this reference frame, motion vectors needs to be backedup
+		 */
+        if (PartitionCost <= BestCost)
+        {
+            BestCost = PartitionCost;            
+            BestRefFrame = ref;
+            
+            for (y = 0; y < (PartHeight/BlockHeight); y++)
+            {
+                for (x = 0; x < (PartWidth/BlockWidth); x++)
+                {
+					OffX = (PartStartX + x * BlockWidth) >> 2;
+					OffY = (PartStartY + y * BlockHeight) >> 2;
+				
+                    BestMV[y][x].dx = pMVArr [4 + OffY][4 + OffX].dx;
+                    BestMV[y][x].dy = pMVArr [4 + OffY][4 + OffX].dy;
+                    BestMVPred[y][x].dx = pMVPredArr [OffY][OffX].dx;
+                    BestMVPred[y][x].dy = pMVPredArr [OffY][OffX].dy;
+                }
+            }
+        }
+
+    }
+
+	/*
+	 * Copy back best reference frame, motion vectors and cost.
+	 */
+    for (y = 0; y < (PartHeight/BlockHeight); y++)
+    {
+        for (x = 0; x < (PartWidth/BlockWidth); x++)
+        {
+			OffX = (PartStartX + x * BlockWidth) >> 2;
+			OffY = (PartStartY + y * BlockHeight) >> 2;            
+            
+            for (j = 0; j < (BlockHeight >> 2); j++)
+            {
+                for (i = 0; i < (BlockWidth >> 2); i++)
+                {
+                    pMVArr [4 + OffY + j][4 + OffX + i].dx = BestMV[y][x].dx;
+                    pMVArr [4 + OffY + j][4 + OffX + i].dy = BestMV[y][x].dy;
+                    pMVPredArr [OffY + j][OffX + i].dx = BestMVPred[y][x].dx;
+                    pMVPredArr [OffY + j][OffX + i].dy = BestMVPred[y][x].dy;
+                }
+            }
+            
+            for (j = 0; j < (BlockHeight >> 3); j++)
+            {
+                for (i = 0; i < (BlockWidth >> 3); i++)
+                {
+		            pRefFrArr [2 + (OffY >> 1) + j][2 + (OffX >> 1) + i] = BestRefFrame;
+                }
+            }
+        }
+    }
+
+	*pCost = BestCost;
+    return OMX_Sts_NoErr;
+
+}
+
+/**
+ * Function: armVCM4P10_Intra16x16Estimation
+ *
+ * Description:
+ * Performs MB-level motion estimation for INTER MB type and selects best motion estimation strategy from 
+ * the set of modes supported in baseline profile ISO/IEC 14496-10.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] pSrcCurrBuf    - Pointer to the start of luma component of current Macroblock 
+ * [in] SrcCurrStep - Step size for the pointer pSrcCurrBuf 
+ * [in] pSrcRecBuf    - Pointer to the start of luma component of co-located reconstructed MB 
+ * [in] SrcRecStep - Step size for the pointer pSrcRecBuf 
+ * [in] nMBPosX     - Position of MB in the frame w.r.t X axis
+ * [in] nMBPosY     - Position of MB in the frame w.r.t Y axis
+ * [in] pMBInter    - Array, of dimension four, containing pointers to information associated with four
+ *                    adjacent type INTER MBs (Left, Top, Top-Left, Top-Right). 
+ * [in] pMBIntra    - Array, of dimension four, containing pointers to information associated with four
+ *                    adjacent type INTRA MBs (Left, Top, Top-Left, Top-Right). 
+ * [in/out] pSrcDstMBCurr - Pointer to information structure for the current MB.  Following member should be set 
+ *                    before calling this function
+ * [in] Lambda      - For calculating the cost
+ * [out] pCost      - Pointer to cost for Intra16x16
+ * Return Value:
+ * OMX_Sts_NoErr - No Error
+ * OMX_Sts_BadArgErr - Bad arguments:
+ *
+ */
+
+static OMXResult armVCM4P10_Intra16x16Estimation(
+    const OMX_U8* pSrcCurrBuf,   
+    OMX_S32 SrcCurrStep,
+    const OMX_U8* pSrcRecBuf,   
+    OMX_S32 SrcRecStep,
+	const OMXVCM4P2Coordinate *pCurrPointPos,
+    const OMXVCM4P10MBInfoPtr *pMBInter,
+    const OMXVCM4P10MBInfoPtr *pMBIntra,
+    OMXVCM4P10MBInfo *pSrcDstMBCurr,
+    OMX_U32 *pCost)
+{
+    OMX_U8      PredBuf [16*16 + 16];
+    OMX_U8      *pPred;
+    OMX_S32     mode;
+    OMX_S32     Cost;
+    OMX_S32     availability = 0;
+    OMXResult   Ret;
+    OMXVCM4P10Intra16x16PredMode    IntraMode16x16 [4] = 
+        {OMX_VC_16X16_VERT, OMX_VC_16X16_HOR, 
+        OMX_VC_16X16_DC, OMX_VC_16X16_PLANE};        
+    OMX_U32     MBPosX = pCurrPointPos->x >> 4;        
+    OMX_U32     MBPosY = pCurrPointPos->y >> 4;        
+
+	pPred = armAlignTo16Bytes(PredBuf);
+    
+	/* Check for availability of LEFT MB */
+    if ((MBPosX != 0) && (pMBIntra [0] != 0 || pMBInter [0] != 0))
+    {
+        availability |= OMX_VC_LEFT;        
+    }
+
+    /* Check for availability of UP MB */
+    if ((MBPosY != 0) && (pMBIntra [1] != 0 || pMBInter [1] != 0))
+    {
+        availability |= OMX_VC_UPPER;        
+    }
+
+    /* Check for availability of UP-LEFT MB */
+    if ((MBPosX > 0) && (MBPosY > 0) && 
+        (pMBIntra [2] != 0 || pMBInter [2] != 0))
+    {
+        availability |= OMX_VC_UPPER_LEFT;        
+    }
+
+    *pCost = ARM_VCM4P10_MAX_COST;
+    for (mode = 0; mode < 4; mode++)
+    {
+        Ret = omxVCM4P10_PredictIntra_16x16(
+                pSrcRecBuf - 1, 
+                pSrcRecBuf - SrcRecStep, 
+                pSrcRecBuf - SrcRecStep - 1, 
+                pPred, 
+                SrcRecStep, 
+                16, 
+                IntraMode16x16 [mode], 
+                availability);
+        if (Ret == OMX_Sts_NoErr)                         
+        {
+            armVCCOMM_SAD(    
+                pSrcCurrBuf,
+                SrcCurrStep,
+                pPred,
+                16,
+                &Cost,
+                16,
+                16);
+            if (Cost < *pCost)
+            {
+                *pCost = Cost;
+                pSrcDstMBCurr->Intra16x16PredMode = IntraMode16x16 [mode];
+            }
+            
+        }
+        
+    }
+
+    return OMX_Sts_NoErr;
+}
+
+/**
+ * Function: armVCM4P10_Intra4x4Estimation
+ *
+ * Description:
+ * Performs MB-level motion estimation for Intra 4x4 MB type and selects
+ * the best set of modes supported in baseline profile.
+ *
+ * Parameters:
+ * [in] pSrcCurrBuf    - Pointer to the start of luma component of current Macroblock 
+ * [in] SrcCurrStep - Step size for the pointer pSrcCurrBuf 
+ * [in] pSrcRecBuf    - Pointer to the start of luma component of co-located reconstructed MB 
+ * [in] SrcRecStep - Step size for the pointer pSrcRecBuf 
+ * [in] nMBPosX     - Position of MB in the frame w.r.t X axis
+ * [in] nMBPosY     - Position of MB in the frame w.r.t Y axis
+ * [in] pMBIntra    - Array, of dimension four, containing pointers to information associated with four
+ *                    adjacent type INTRA MBs (Left, Top, Top-Left, Top-Right). 
+ * [in/out] pSrcDstMBCurr - Pointer to information structure for the current MB.  Following member should be set 
+ *                    before calling this function
+ * [in] Lambda      - For calculating the cost
+ * [out] pCost      - Pointer to cost for Intra4x4
+ * Return Value:
+ * OMX_Sts_NoErr - No Error
+ * OMX_Sts_BadArgErr - Bad arguments:
+ *
+ */
+
+static OMXResult armVCM4P10_Intra4x4Estimation(
+    const OMX_U8* pSrcCurrBuf,   
+    OMX_S32 SrcCurrStep,
+    const OMX_U8* pSrcRecBuf,   
+    OMX_S32 SrcRecStep,
+    const OMXVCM4P10MBInfoPtr *pMBIntra,
+    OMXVCM4P10MBInfo *pSrcDstMBCurr,
+    OMX_U32 *pCost)
+{
+    OMX_S32     x, y, Block4x4, Block8x8;
+    OMX_S32     Cost;
+
+    /*
+     * PredIntra4x4Mode will store prediction modes of 4x4 blocks. 
+     * Modes for current MB starts at index [1][1].   
+     * Modes of nighbouring MB's will be as shown below
+     * A value of ARM_VCM4P10_INVALID_BLOCK for any block in this array means 
+     * that block is not available for prediction.
+     *
+     * c3 b0 b1 b2 b3 d0 d1 d2 d3
+     * a0 xx xx xx xx -  -  -  -
+     * a1 xx xx xx xx -  -  -  -
+     * a2 xx xx xx xx -  -  -  -
+     * a3 xx xx xx xx -  -  -  -
+     *
+     */
+    OMX_S32     PredIntra4x4Mode [5][9];
+
+    /*
+     * pSrcY stores re-construsted source array of size 3MB X 2MB as below
+     *
+     * MB11 MB12 MB13 
+     * MB21 MB22 MB23
+     *
+     * This array will be used for local reconstruction of 4x4 blocks 
+     * with best prediction mode within an MB
+     */    
+    OMX_U8      pSrcY [(16*3)*(16*2)];
+    OMX_S32     StepSrcY;
+    
+    /* init */
+    *pCost = 0;
+
+    for (y = 0; y < 5; y++)
+    {
+        for (x = 0; x < 9; x++)
+        {
+            /* 
+             * Initialize with value of ARM_VCM4P10_INVALID_BLOCK, to mean this 
+             * 4x4 block is not available 
+             */
+            PredIntra4x4Mode [y][x] = ARM_VCM4P10_INVALID_BLOCK;
+        }
+    }
+
+    /* Replace ARM_VCM4P10_INVALID_BLOCK value with available MBs values*/
+    for (x = 0; x < 4; x++)
+    {
+        /* Store values of b0, b1, b2, b3 */
+        if (pMBIntra[1] != NULL)
+        {
+            PredIntra4x4Mode [0][x + 1] = 
+                pMBIntra[1]->pIntra4x4PredMode[3*4 + x];            
+        }
+        
+        /* Store values of d0, d1, d2, d3 */
+        if (pMBIntra[3] != NULL)
+        {
+            PredIntra4x4Mode [0][x + 5] = 
+                pMBIntra[3]->pIntra4x4PredMode[3*4 + x];
+        }
+    }
+    
+    /* Store values of c3 */
+    if (pMBIntra[2] != NULL)
+    {
+        PredIntra4x4Mode [0][0] = pMBIntra[2]->pIntra4x4PredMode[15];
+    }
+    
+    for (y = 0; y < 4; y++)
+    {
+        /* Store values of a0, a1, a2, a3 */
+        if (pMBIntra[0] != NULL)
+        {
+            PredIntra4x4Mode [y + 1][0] = 
+                pMBIntra[0]->pIntra4x4PredMode[y*4 + 3];
+        }
+    }
+        
+    /*
+     * Update neighbouring Pred mode array which will be used for
+     * prediction of Intra4x4 modes.
+     */
+    
+    StepSrcY = 16 * 3;
+    for (y = 0; y < (16 * 2); y++)
+    {
+        for (x = 0; x < (16 * 3); x++)
+        {
+            pSrcY [StepSrcY * y + x] = 
+                pSrcRecBuf [SrcRecStep * (y - 16) + x - 16];
+        }
+    }
+    
+    /* for each 8x8 block */
+    for (Block8x8 = 0; Block8x8 < 4; Block8x8++)
+    {
+        /* for each 4x4 block inside 8x8 block */
+        for (Block4x4 = 0; Block4x4 < 4; Block4x4++)
+        {
+            armVCM4P10_Mode4x4Decision (
+                pSrcCurrBuf,   
+                SrcCurrStep,
+                pSrcDstMBCurr,
+                Block8x8, 
+                Block4x4,
+                pSrcY + 16 * StepSrcY + 16,
+                StepSrcY,
+                PredIntra4x4Mode, 
+                &Cost);
+
+            *pCost += Cost;
+        }
+    }
+    return OMX_Sts_NoErr;
+}
+
+/**
+ * Function: armVCM4P10_InterMEMB
+ *
+ * Description:
+ * Performs MB-level motion estimation for INTER MB type and selects best motion estimation strategy from 
+ * the set of modes supported in baseline profile ISO/IEC 14496-10.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] pSrcCurrBuf    - Pointer to the start of luma component of current Macroblock 
+ * [in] SrcCurrStep - Step size for the pointer pSrcCurrBuf 
+ * [in] pSrcRefBufList    - Pointer to the start of luma component of co-located reference MB
+ * [in] SrcRefStep - Step size for the pointer pSrcRefY 
+ * [in] pRefRect   Pointer to the valid reference rectangle; relative to the image origin.
+ * [in] pCurrPointPos   Position of the current macroblock in the current plane.
+ * [in] pMESpec     - Motion estimation structure
+ * [in] pMBInter    - Array, of dimension four, containing pointers to information associated with four
+ *                    adjacent type INTER MBs (Left, Top, Top-Left, Top-Right). 
+ * [in/out] pSrcDstMBCurr - Pointer to information structure for the current MB.  Following member should be set 
+ *                    before calling this function
+ * [in] Lambda      - For calculating the cost
+ * [out] pDstCost      - Pointer to cost for Inter MB
+ * Return Value:
+ * OMX_Sts_NoErr - No Error
+ * OMX_Sts_BadArgErr - Bad arguments:
+ *
+ */
+
+static OMXResult armVCM4P10_InterMEMB(
+    const OMX_U8 *pSrcCurrBuf, 
+	OMX_S32 SrcCurrStep, 
+	const OMX_U8 *pSrcRefBufList[ARM_VCM4P10_MAX_FRAMES],
+	OMX_S32 SrcRefStep,
+	const OMXRect *pRefRect,
+	const OMXVCM4P2Coordinate *pCurrPointPos,
+	OMX_U32 Lambda,
+	void *pMESpec,
+	const OMXVCM4P10MBInfoPtr *pMBInter, 
+    OMXVCM4P10MBInfoPtr pSrcDstMBCurr,
+	OMX_U32 *pDstCost)
+{
+    OMX_S32     i, j, x, y, mode;
+    OMX_U32     Block8x8, XPerMB, YPerMB, Block2x, Block2y;
+    OMX_S32     PartStartX = 0, PartStartY = 0;
+    OMX_S32     PartWidth = 8, PartHeight = 8, BlockWidth = 4, BlockHeight = 4;
+    const OMX_U32     BlkSz [4][2] = {{4,4}, {4,8}, {8,4}};
+    const OMX_U32     PartSz [4][2] = {{8,8}, {8,16}, {16,8}, {16,16}};
+    const OMXVCM4P10SubMacroblockType     
+                ModeSubMBType4x4 [] = {OMX_VC_SUB_P_4x4, OMX_VC_SUB_P_4x8, 
+                              OMX_VC_SUB_P_8x4, OMX_VC_SUB_P_8x8};
+    const OMXVCM4P10MacroblockType
+                ModeMBType [] = {OMX_VC_P_8x8, OMX_VC_P_8x16, OMX_VC_P_16x8, OMX_VC_P_16x16};
+    
+    OMXVCM4P10MEParams  *pMBOptions;
+    /*
+     * RefFrArr and  MVArr will be used for temporary storage of Reference frame index and MVs
+     * It will store RefIndex and MVs of 6 MBs as shown below
+     * 
+     *     |------|------|------|
+     *     |Tp-Lt |Top   |Tp-R  |
+     *     | MB   | MB   | MB   |
+     *     |------|------|------|
+     *     |Left  | Curr |      |
+     *     | MB   | MB   |      |
+     *     |------|------|------|
+     */
+    OMX_S32     RefFrArr [4][6]; 
+    OMXVCMotionVector MVArr [8][12];
+    OMXVCMotionVector MVPredArr [4][4];
+    
+    /*
+     * IndexToLoc will translate pMBInter index into spacial arrangement of MBs
+     */
+    OMX_S32     IndexToLoc [] = {2,1,3,0};
+    OMX_U32     part, MaxPart;
+    OMX_S32     Cost, MotionCost8x8 [4], MBCost, BestCost;
+
+    /*
+     * Update neighbouring MV array and Ref frame array which will be used for
+     * prediction of MVs and Ref frames.
+     */
+
+    /* Set cost to a high value */
+    Cost = BestCost = ARM_VCM4P10_MAX_COST;
+    
+    for (y = 0; y < 8; y++)
+    {
+        for (x = 0; x < 12; x++)
+        {
+            i = 3 * (y >> 2) + (x >> 2);
+            if ((y < 4 || x < 4) && (pMBInter[IndexToLoc[i]] != NULL))
+            {
+                MVArr [y][x].dx = 
+                    pMBInter[IndexToLoc[i]]->pMV0[y % 4][x % 4].dx;
+                MVArr [y][x].dy = 
+                    pMBInter[IndexToLoc[i]]->pMV0[y % 4][x % 4].dy;
+            }
+            else
+            {
+                MVArr [y][x].dx = 0;
+                MVArr [y][x].dy = 0;
+            }
+        }
+    }    
+
+    for (y = 0; y < 4; y++)
+    {
+        for (x = 0; x < 6; x++)
+        {
+            i = 3 * (y >> 1) + (x >> 1);
+            if ((y < 2 || x < 2) && (pMBInter[IndexToLoc[i]] != NULL))
+            {
+                RefFrArr [y][x] = 
+                    pMBInter[IndexToLoc[i]]->pRefL0Idx [(y % 2) * 2 + (x % 2)];
+            }
+            else
+            {
+                RefFrArr [y][x] = ARM_VCM4P10_INVALID_BLOCK;
+            }
+        }
+    }    
+
+    for (y = 0; y < 4; y++)
+    {
+        for (x = 0; x < 4; x++)
+        {
+            MVPredArr [y][x].dx = 0;
+            MVPredArr [y][x].dy = 0;
+        }
+    }
+    /*
+     * Motion Estimation for 8x8 MB Partition 
+     */
+
+    for (i = 0; i < 4; i++)
+    {
+        MotionCost8x8 [i] = 0;
+    }        
+    
+    pMBOptions = (OMXVCM4P10MEParams *) pMESpec;
+    
+    if (pMBOptions->blockSplitEnable8x8 == 1 && 
+        pMBOptions->blockSplitEnable4x4 == 1)
+    {
+        pSrcDstMBCurr->mbType = OMX_VC_P_8x8;
+
+        PartWidth = PartSz [0][0];
+        PartHeight = PartSz [0][1];
+        
+        /* For each 8x8 partitions */
+        for (Block8x8 = 0; Block8x8 < 4; Block8x8++)
+        {
+            PartStartX = (Block8x8 % 2) << 3;
+            PartStartY = (Block8x8 / 2) << 3;
+
+            Block2x = (Block8x8 & 1) << 1;
+            Block2y = (Block8x8 >> 1) << 1;
+            
+            BestCost = ARM_VCM4P10_MAX_COST;
+            for (mode = 0; mode < 3; mode++)
+            {
+                BlockWidth = BlkSz [mode][0];
+                BlockHeight = BlkSz [mode][1];
+
+                armVCM4P10_PartitionME (
+                    pSrcCurrBuf,   
+                    SrcCurrStep,
+                    pSrcRefBufList,   
+                    SrcRefStep,
+                    pRefRect,
+                    pCurrPointPos,
+                    pMESpec,
+
+                    PartWidth,
+                    PartHeight,
+                    BlockWidth,
+                    BlockHeight,
+                    PartStartX,
+                    PartStartY,
+
+                    MVArr,
+                    RefFrArr,
+                    MVPredArr,
+
+                    Lambda,
+                    &Cost);
+                    
+                if (Cost <= BestCost)
+                {
+                    /* Update cost */
+                    BestCost = Cost;
+                    
+                    /* Update MBCurr struct */
+                    pSrcDstMBCurr->subMBType [Block8x8] = ModeSubMBType4x4 [mode];
+                    
+                    pSrcDstMBCurr->pRefL0Idx [Block8x8] = RefFrArr [2 + (PartStartY >> 3)][2 + (PartStartX >> 3)];
+
+                    /* Update pMV0 and pMVPred of MBCurr struct */
+                    for (j = 0; j < 2; j++)
+                    {
+                        for (i = 0; i < 2; i++)
+                        {
+                            pSrcDstMBCurr->pMV0 [Block2y + j][Block2x + i].dx =
+                                MVArr [4 + Block2y + j][4 + Block2x + i].dx;
+                            pSrcDstMBCurr->pMV0 [Block2y + j][Block2x + i].dy =
+                                MVArr [4 + Block2y + j][4 + Block2x + i].dy;
+                            
+                            pSrcDstMBCurr->pMVPred [Block2y + j][Block2x + i].dx =
+                                MVPredArr [Block2y + j][Block2x + i].dx;
+                            pSrcDstMBCurr->pMVPred [Block2y + j][Block2x + i].dy =
+                                MVPredArr [Block2y + j][Block2x + i].dy;
+                        }
+                    }
+                }
+            }
+            
+            /* Update cost */
+            MotionCost8x8 [Block8x8] = BestCost;
+        }
+        
+        /* Cost for mbType OMX_VC_P_8x8 */
+        BestCost = 0;
+        for (i = 0; i < 4; i++)
+        {
+            BestCost += MotionCost8x8 [i];
+        }
+    }
+    else
+    {
+        /* Set sub MB type to 8x8 */
+        for (i = 0; i < 4; i++)
+        {
+            pSrcDstMBCurr->subMBType [i] = OMX_VC_SUB_P_8x8;
+        }
+    }
+
+    /*
+     * Motion Estimation for 8x8, 8x16, 16x8 and 16x16 MB Partition
+     * If pMBOptions->b8x8BlockSplitEnable is 0, do only 16x16 ME (mode 3)
+     */
+    for (mode = (pMBOptions->blockSplitEnable8x8 == 1 ? 0 : 3); mode < 4; mode++)
+    {
+        BlockWidth = PartWidth = PartSz [mode][0];
+        BlockHeight = PartHeight = PartSz [mode][1];
+        
+        XPerMB = 16 / PartWidth;
+        YPerMB = 16 / PartHeight;
+        MaxPart = XPerMB * YPerMB;
+        
+        MBCost = 0;
+        
+        /* part size 4, 2, 2 and 1 corresponding to 8x8, 8x16, 16x8 and 16x16 MB */
+        for (part = 0; part < MaxPart; part++)
+        {
+        	PartStartX = (part % XPerMB) * PartWidth;
+        	PartStartY = (part / XPerMB) * PartHeight;
+        	
+            armVCM4P10_PartitionME (
+                pSrcCurrBuf,
+                SrcCurrStep,
+                pSrcRefBufList,   
+                SrcRefStep,
+                pRefRect,
+                pCurrPointPos,
+                pMESpec,
+
+                PartWidth,
+                PartHeight,
+                BlockWidth,
+                BlockHeight,
+                PartStartX,
+                PartStartY,
+
+                MVArr,
+                RefFrArr,
+                MVPredArr,
+
+                Lambda,
+                &Cost);
+                
+                MBCost += Cost;
+        }
+
+        if (MBCost <= BestCost)
+        {
+            /* Update cost */
+            BestCost = MBCost;
+            
+            /* Update mbType of MBCurr struct */
+            pSrcDstMBCurr->mbType = ModeMBType [mode];
+            
+            /* Update pMV0 and pMVPred of MBCurr struct */
+            for (j = 0; j < 4; j++)
+            {
+                for (i = 0; i < 4; i++)
+                {
+                    pSrcDstMBCurr->pMV0 [j][i].dx = MVArr [4+j][4+i].dx;
+                    pSrcDstMBCurr->pMV0 [j][i].dy = MVArr [4+j][4+i].dy;
+                    pSrcDstMBCurr->pMVPred [j][i].dx = MVPredArr [j][i].dx;
+                    pSrcDstMBCurr->pMVPred [j][i].dy = MVPredArr [j][i].dy;
+                }
+            }
+            for (j = 0; j < 2; j++)
+            {
+                for (i = 0; i < 2; i++)
+                {
+                    pSrcDstMBCurr->pRefL0Idx [j*2+i] = RefFrArr [2+j][2+i];
+                }
+            }
+        }
+
+    }
+
+    /* Update Best Cost */
+    *pDstCost = BestCost;
+    
+    return OMX_Sts_NoErr;
+}
+
+/**
+ * Function:  omxVCM4P10_MotionEstimationMB   (6.3.5.3.1)
+ *
+ * Description:
+ * Performs MB-level motion estimation and selects best motion estimation 
+ * strategy from the set of modes supported in baseline profile [ISO14496-10]. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcCurrBuf - Pointer to the current position in original picture plane; 
+ *            16-byte alignment required 
+ *   pSrcRefBufList - Pointer to an array with 16 entries.  Each entry points 
+ *            to the top-left corner of the co-located MB in a reference 
+ *            picture.  The array is filled from low-to-high with valid 
+ *            reference frame pointers; the unused high entries should be set 
+ *            to NULL.  Ordering of the reference frames should follow 
+ *            [ISO14496-10] subclause 8.2.4  Decoding Process for Reference 
+ *            Picture Lists.   The entries must be 16-byte aligned. 
+ *   pSrcRecBuf - Pointer to the top-left corner of the co-located MB in the 
+ *            reconstructed picture; must be 16-byte aligned. 
+ *   SrcCurrStep - Width of the original picture plane in terms of full 
+ *            pixels; must be a multiple of 16. 
+ *   SrcRefStep - Width of the reference picture plane in terms of full 
+ *            pixels; must be a multiple of 16. 
+ *   SrcRecStep - Width of the reconstructed picture plane in terms of full 
+ *            pixels; must be a multiple of 16. 
+ *   pRefRect - Pointer to the valid reference rectangle; relative to the 
+ *            image origin. 
+ *   pCurrPointPos - Position of the current macroblock in the current plane. 
+ *   Lambda - Lagrange factor for computing the cost function 
+ *   pMESpec - Pointer to the motion estimation specification structure; must 
+ *            have been allocated and initialized prior to calling this 
+ *            function. 
+ *   pMBInter - Array, of dimension four, containing pointers to information 
+ *            associated with four adjacent type INTER MBs (Left, Top, 
+ *            Top-Left, Top-Right). Any pointer in the array may be set equal 
+ *            to NULL if the corresponding MB doesn t exist or is not of type 
+ *            INTER. pMBInter[0] - Pointer to left MB information pMBInter[1] 
+ *            - Pointer to top MB information pMBInter[2] - Pointer to 
+ *            top-left MB information pMBInter[3] - Pointer to top-right MB 
+ *            information 
+ *   pMBIntra - Array, of dimension four, containing pointers to information 
+ *            associated with four adjacent type INTRA MBs (Left, Top, 
+ *            Top-Left, Top-Right). Any pointer in the array may be set equal 
+ *            to NULL if the corresponding MB doesn t exist or is not of type 
+ *            INTRA. pMBIntra[0] - Pointer to left MB information pMBIntra[1] 
+ *            - Pointer to top MB information pMBIntra[2] - Pointer to 
+ *            top-left MB information pMBIntra[3] - Pointer to top-right MB 
+ *            information 
+ *   pSrcDstMBCurr - Pointer to information structure for the current MB.  
+ *            The following entries should be set prior to calling the 
+ *            function:  sliceID - the number of the slice the to which the 
+ *            current MB belongs. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstCost - Pointer to the minimum motion cost for the current MB. 
+ *   pDstBlockSAD - Pointer to the array of SADs for each of the sixteen luma 
+ *            4x4 blocks in each MB.  The block SADs are in scan order for 
+ *            each MB.  For implementations that cannot compute the SAD values 
+ *            individually, the maximum possible value (0xffff) is returned 
+ *            for each of the 16 block SAD entries. 
+ *   pSrcDstMBCurr - Pointer to updated information structure for the current 
+ *            MB after MB-level motion estimation has been completed.  The 
+ *            following fields are updated by the ME function.   The following 
+ *            parameter set quantifies the MB-level ME search results: MbType 
+ *            subMBType[4] pMV0[4][4] pMVPred[4][4] pRefL0Idx[4] 
+ *            Intra16x16PredMode pIntra4x4PredMode[4][4] 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -   One of more of the following pointers is NULL: pSrcCurrBuf, 
+ *           pSrcRefBufList, pSrcRecBuf, pRefRect, pCurrPointPos, pMESpec, 
+ *           pMBInter, pMBIntra,pSrcDstMBCurr, pDstCost, pSrcRefBufList[0] 
+ *    -    SrcRefStep, SrcRecStep are not multiples of 16 
+ *    -    iBlockWidth or iBlockHeight are values other than 4, 8, or 16. 
+ *    -    Any alignment restrictions are violated 
+ *
+ */
+ 
+OMXResult omxVCM4P10_MotionEstimationMB(                    
+    const OMX_U8 *pSrcCurrBuf,                                  
+	OMX_S32 SrcCurrStep, 
+	const OMX_U8 *pSrcRefBufList[ARM_VCM4P10_MAX_FRAMES],
+	OMX_S32 SrcRefStep,
+	const OMX_U8 *pSrcRecBuf, 
+	OMX_S32 SrcRecStep,
+	const OMXRect *pRefRect,
+	const OMXVCM4P2Coordinate *pCurrPointPos,
+	OMX_U32 Lambda,
+	void *pMESpec,
+	const OMXVCM4P10MBInfoPtr *pMBInter, 
+	const OMXVCM4P10MBInfoPtr *pMBIntra,
+    OMXVCM4P10MBInfo *pSrcDstMBCurr,
+	OMX_INT *pDstCost,
+    OMX_U16 *pDstBlockSAD)
+{
+    OMX_U32     Cost, i, IntraFlag = 1;
+    OMXVCM4P10MEParams  *pMEParams; 
+
+    /* check for argument error */
+    armRetArgErrIf(pSrcCurrBuf == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pSrcRefBufList == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pSrcRecBuf == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pRefRect == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pCurrPointPos == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pMESpec == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pMBInter == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pMBIntra == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pSrcDstMBCurr == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pDstCost == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(SrcRefStep <= 0 || SrcRefStep & 15, OMX_Sts_BadArgErr)
+    armRetArgErrIf(SrcRecStep <= 0 || SrcRecStep & 15, OMX_Sts_BadArgErr)
+    armRetArgErrIf(SrcCurrStep <= 0 || SrcCurrStep & 15, OMX_Sts_BadArgErr)
+    
+    armRetArgErrIf(armNot16ByteAligned(pSrcCurrBuf), OMX_Sts_BadArgErr)    
+    armRetArgErrIf(armNot16ByteAligned(pSrcRecBuf), OMX_Sts_BadArgErr)
+
+    for (i = 0; i < ARM_VCM4P10_MAX_FRAMES; i++)
+    {
+        armRetArgErrIf(pSrcRefBufList [i] != NULL &&
+            armNot16ByteAligned(pSrcRefBufList [i]), OMX_Sts_BadArgErr)
+            
+        /* Check if current MB needs INTER cost calculations */
+        if (pSrcRefBufList [i] != NULL && IntraFlag == 1)
+        {
+            IntraFlag = 0;
+        }
+    }
+
+    *pDstCost = ARM_VCM4P10_MAX_COST;
+    /*
+     * Inter cost calculations 
+     */
+
+     /* check this MB can be Inter */
+    if (IntraFlag != 1)
+    {
+         armVCM4P10_InterMEMB(
+             pSrcCurrBuf,   
+             SrcCurrStep,
+             pSrcRefBufList,   
+             SrcRefStep,
+             pRefRect,    
+             pCurrPointPos,
+             Lambda,
+             pMESpec,
+             pMBInter,
+             pSrcDstMBCurr,
+             &Cost
+             );
+        
+        *pDstCost = Cost;
+    }     
+
+    pMEParams = (OMXVCM4P10MEParams *)pMESpec;
+    
+    if (pMEParams->intraEnable4x4 == 1)
+    {
+        /*
+         * Intra 4x4 cost calculations
+         */
+        armVCM4P10_Intra4x4Estimation(
+            pSrcCurrBuf,   
+            SrcCurrStep,
+            pSrcRecBuf,   
+            SrcRecStep,
+            pMBIntra,
+            pSrcDstMBCurr,
+            &Cost
+            );
+
+        if (Cost <= *pDstCost)
+        {
+            *pDstCost = Cost;
+            pSrcDstMBCurr->mbType = OMX_VC_INTRA_4x4;
+
+        }
+        
+    }
+
+    /*
+     * Cost for Intra 16x16 mode
+     */
+
+    armVCM4P10_Intra16x16Estimation(
+        pSrcCurrBuf,   
+        SrcCurrStep,
+        pSrcRecBuf,   
+        SrcRecStep,
+        pCurrPointPos,
+        pMBInter,
+        pMBIntra,
+        pSrcDstMBCurr,
+        &Cost
+        );
+
+    if (Cost <= *pDstCost)
+    {
+        *pDstCost = Cost;
+        pSrcDstMBCurr->mbType = OMX_VC_INTRA_16x16;
+    }
+
+    /*
+     * Update pDstBlockSAD to max value
+     */
+	armVCM4P10_CalculateBlockSAD(	pSrcDstMBCurr, 
+        pSrcCurrBuf,                                  
+    	SrcCurrStep, 
+    	pSrcRefBufList,
+    	SrcRefStep,
+    	pSrcRecBuf, 
+    	SrcRecStep,
+    	pRefRect,
+    	pCurrPointPos,
+    	pMBInter, 
+    	pMBIntra,
+    	pDstBlockSAD);
+
+
+	return OMX_Sts_NoErr;
+}
+
+
+/*****************************************************************************
+ *                              END OF FILE
+ *****************************************************************************/
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_PredictIntraChroma_8x8.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_PredictIntraChroma_8x8.c
new file mode 100644
index 0000000..d6ca783
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_PredictIntraChroma_8x8.c
@@ -0,0 +1,284 @@
+/* ----------------------------------------------------------------
+ *
+ * 
+ * File Name:  omxVCM4P10_PredictIntraChroma_8x8.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * H.264 Chroma 8x8 intra prediction module
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+
+/*
+ * Description:
+ * Perform DC style intra prediction, upper block has priority
+ *
+ * Parameters:
+ * [in]	pSrcLeft		Pointer to the buffer of 16 left coefficients:
+ *								p[x, y] (x = -1, y = 0..3)
+ * [in]	pSrcAbove		Pointer to the buffer of 16 above coefficients:
+ *								p[x,y] (x = 0..3, y = -1)
+ * [in]	leftStep		Step of left coefficient buffer
+ * [in]	dstStep			Step of the destination buffer
+ * [in]	availability	Neighboring 16x16 MB availability flag
+ * [out]	pDst			Pointer to the destination buffer
+ *
+ * Return Value:
+ * None
+ */
+
+static void armVCM4P10_PredictIntraDCUp4x4(
+     const OMX_U8* pSrcLeft,
+     const OMX_U8 *pSrcAbove,
+     OMX_U8* pDst,
+     OMX_INT leftStep,
+     OMX_INT dstStep,
+     OMX_S32 availability        
+)
+{
+    int x, y, Sum=0, Count = 0;
+
+    if (availability & OMX_VC_UPPER)
+    {
+        for (x=0; x<4; x++)
+        {
+            Sum += pSrcAbove[x];
+        }
+        Count++;
+    }
+    else if (availability & OMX_VC_LEFT)
+    {
+        for (y=0; y<4; y++)
+        {
+            Sum += pSrcLeft[y*leftStep];
+        }
+        Count++;
+    }
+    if (Count==0)
+    {
+        Sum = 128;
+    }
+    else
+    {
+        Sum = (Sum + 2) >> 2;
+    }
+    for (y=0; y<4; y++)
+    {
+        for (x=0; x<4; x++)
+        {
+            pDst[y*dstStep+x] = (OMX_U8)Sum;
+        }
+    }
+}
+
+/*
+ * Description:
+ * Perform DC style intra prediction, left block has priority
+ *
+ * Parameters:
+ * [in]	pSrcLeft		Pointer to the buffer of 16 left coefficients:
+ *								p[x, y] (x = -1, y = 0..3)
+ * [in]	pSrcAbove		Pointer to the buffer of 16 above coefficients:
+ *								p[x,y] (x = 0..3, y = -1)
+ * [in]	leftStep		Step of left coefficient buffer
+ * [in]	dstStep			Step of the destination buffer
+ * [in]	availability	Neighboring 16x16 MB availability flag
+ * [out]	pDst			Pointer to the destination buffer
+ *
+ * Return Value:
+ * None
+ */
+
+static void armVCM4P10_PredictIntraDCLeft4x4(
+     const OMX_U8* pSrcLeft,
+     const OMX_U8 *pSrcAbove,
+     OMX_U8* pDst,
+     OMX_INT leftStep,
+     OMX_INT dstStep,
+     OMX_S32 availability        
+)
+{
+    int x, y, Sum=0, Count = 0;
+
+    if (availability & OMX_VC_LEFT)
+    {
+        for (y=0; y<4; y++)
+        {
+            Sum += pSrcLeft[y*leftStep];
+        }
+        Count++;
+    }
+    else if (availability & OMX_VC_UPPER)
+    {
+        for (x=0; x<4; x++)
+        {
+            Sum += pSrcAbove[x];
+        }
+        Count++;
+    }
+    if (Count==0)
+    {
+        Sum = 128;
+    }
+    else
+    {
+        Sum = (Sum + 2) >> 2;
+    }
+    for (y=0; y<4; y++)
+    {
+        for (x=0; x<4; x++)
+        {
+            pDst[y*dstStep+x] = (OMX_U8)Sum;
+        }
+    }
+}
+
+/**
+ * Function:  omxVCM4P10_PredictIntraChroma_8x8   (6.3.3.1.3)
+ *
+ * Description:
+ * Performs intra prediction for chroma samples. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcLeft - Pointer to the buffer of 8 left pixels: p[x, y] (x = -1, y= 
+ *            0..7). 
+ *   pSrcAbove - Pointer to the buffer of 8 above pixels: p[x,y] (x = 0..7, y 
+ *            = -1); must be aligned on an 8-byte boundary. 
+ *   pSrcAboveLeft - Pointer to the above left pixels: p[x,y] (x = -1, y = -1) 
+ *   leftStep - Step of left pixel buffer; must be a multiple of 8. 
+ *   dstStep - Step of the destination buffer; must be a multiple of 8. 
+ *   predMode - Intra chroma prediction mode, please refer to section 3.4.3. 
+ *   availability - Neighboring chroma block availability flag, please refer 
+ *            to  "Neighboring Macroblock Availability". 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - Pointer to the destination buffer; must be aligned on an 8-byte 
+ *            boundary. 
+ *
+ * Return Value:
+ *    If the function runs without error, it returns OMX_Sts_NoErr. 
+ *    If any of the following cases occurs, the function returns 
+ *              OMX_Sts_BadArgErr: 
+ *    pDst is NULL. 
+ *    dstStep < 8 or dstStep is not a multiple of 8. 
+ *    leftStep is not a multiple of 8. 
+ *    predMode is not in the valid range of enumeration 
+ *              OMXVCM4P10IntraChromaPredMode. 
+ *    predMode is OMX_VC_CHROMA_VERT, but availability doesn't set 
+ *              OMX_VC_UPPER indicating p[x,-1] (x = 0..7) is not available. 
+ *    predMode is OMX_VC_CHROMA_HOR, but availability doesn't set OMX_VC_LEFT 
+ *              indicating p[-1,y] (y = 0..7) is not available. 
+ *    predMode is OMX_VC_CHROMA_PLANE, but availability doesn't set 
+ *              OMX_VC_UPPER_LEFT or OMX_VC_UPPER or OMX_VC_LEFT indicating 
+ *              p[x,-1](x = 0..7), or p[-1,y] (y = 0..7), or p[-1,-1] is not 
+ *              available. 
+ *    availability sets OMX_VC_UPPER, but pSrcAbove is NULL. 
+ *    availability sets OMX_VC_LEFT, but pSrcLeft is NULL. 
+ *    availability sets OMX_VC_UPPER_LEFT, but pSrcAboveLeft is NULL. 
+ *    either pSrcAbove or pDst is not aligned on a 8-byte boundary.  Note: 
+ *              pSrcAbove, pSrcAbove, pSrcAboveLeft may be invalid pointer if 
+ *              they are not used by intra prediction implied in predMode. 
+ *               Note: OMX_VC_UPPER_RIGHT is not used in intra chroma 
+ *              prediction. 
+ *
+ */
+OMXResult omxVCM4P10_PredictIntraChroma_8x8(
+     const OMX_U8* pSrcLeft,
+     const OMX_U8 *pSrcAbove,
+     const OMX_U8 *pSrcAboveLeft,
+     OMX_U8* pDst,
+     OMX_INT leftStep,
+     OMX_INT dstStep,
+     OMXVCM4P10IntraChromaPredMode predMode,
+     OMX_S32 availability        
+ )
+{
+    int x, y, Sum;
+    int H, V, a, b, c;
+
+    armRetArgErrIf(pDst == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(dstStep < 8,  OMX_Sts_BadArgErr);
+    armRetArgErrIf((dstStep % 8) != 0,  OMX_Sts_BadArgErr);
+    armRetArgErrIf((leftStep % 8) != 0,  OMX_Sts_BadArgErr);
+    armRetArgErrIf(armNot8ByteAligned(pSrcAbove), OMX_Sts_BadArgErr);
+    armRetArgErrIf(armNot8ByteAligned(pDst), OMX_Sts_BadArgErr);
+    armRetArgErrIf((availability & OMX_VC_UPPER)      && pSrcAbove     == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf((availability & OMX_VC_LEFT )      && pSrcLeft      == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf((availability & OMX_VC_UPPER_LEFT) && pSrcAboveLeft == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(predMode==OMX_VC_CHROMA_VERT  && !(availability & OMX_VC_UPPER),      OMX_Sts_BadArgErr);
+    armRetArgErrIf(predMode==OMX_VC_CHROMA_HOR   && !(availability & OMX_VC_LEFT),       OMX_Sts_BadArgErr);
+    armRetArgErrIf(predMode==OMX_VC_CHROMA_PLANE && !(availability & OMX_VC_UPPER),      OMX_Sts_BadArgErr);
+    armRetArgErrIf(predMode==OMX_VC_CHROMA_PLANE && !(availability & OMX_VC_UPPER_LEFT), OMX_Sts_BadArgErr);
+    armRetArgErrIf(predMode==OMX_VC_CHROMA_PLANE && !(availability & OMX_VC_LEFT),       OMX_Sts_BadArgErr);
+    armRetArgErrIf((unsigned)predMode > OMX_VC_CHROMA_PLANE,   OMX_Sts_BadArgErr);    
+
+    switch (predMode)
+    {
+    case OMX_VC_CHROMA_DC:
+        armVCM4P10_PredictIntraDC4x4(       pSrcLeft,            pSrcAbove,   pDst,             leftStep, dstStep, availability);
+        armVCM4P10_PredictIntraDCUp4x4(     pSrcLeft,            pSrcAbove+4, pDst+4,           leftStep, dstStep, availability);
+        armVCM4P10_PredictIntraDCLeft4x4(   pSrcLeft+4*leftStep, pSrcAbove,   pDst+4*dstStep,   leftStep, dstStep, availability);
+        armVCM4P10_PredictIntraDC4x4(       pSrcLeft+4*leftStep, pSrcAbove+4, pDst+4+4*dstStep, leftStep, dstStep, availability);
+        break;
+
+    case OMX_VC_CHROMA_HOR:
+        for (y=0; y<8; y++)
+        {
+            for (x=0; x<8; x++)
+            {
+                pDst[y*dstStep+x] = pSrcLeft[y*leftStep];
+            }
+        }
+        break;
+
+    case OMX_VC_CHROMA_VERT:
+        for (y=0; y<8; y++)
+        {
+            for (x=0; x<8; x++)
+            {
+                pDst[y*dstStep+x] = pSrcAbove[x];
+            }
+        }
+        break;
+
+    case OMX_VC_CHROMA_PLANE:
+        H = 4*(pSrcAbove[7] - pSrcAboveLeft[0]);
+        for (x=2; x>=0; x--)
+        {
+            H += (x+1)*(pSrcAbove[4+x] - pSrcAbove[2-x]);
+        }
+        V = 4*(pSrcLeft[7*leftStep] - pSrcAboveLeft[0]);
+        for (y=2; y>=0; y--)
+        {
+            V += (y+1)*(pSrcLeft[(4+y)*leftStep] - pSrcLeft[(2-y)*leftStep]);
+        }
+        a = 16*(pSrcAbove[7] + pSrcLeft[7*leftStep]);
+        b = (17*H+16)>>5;
+        c = (17*V+16)>>5;
+        for (y=0; y<8; y++)
+        {
+            for (x=0; x<8; x++)
+            {
+                Sum = (a + b*(x-3) + c*(y-3) + 16)>>5;
+                pDst[y*dstStep+x] = (OMX_U8)armClip(0,255,Sum);
+            }
+        }
+        break;
+    }
+
+    return OMX_Sts_NoErr;
+}
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_PredictIntra_16x16.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_PredictIntra_16x16.c
new file mode 100644
index 0000000..c90cb4c
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_PredictIntra_16x16.c
@@ -0,0 +1,198 @@
+/* ----------------------------------------------------------------
+ *
+ * 
+ * File Name:  omxVCM4P10_PredictIntra_16x16.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * H.264 16x16 intra prediction module
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+
+/**
+ * Function:  omxVCM4P10_PredictIntra_16x16   (6.3.3.1.2)
+ *
+ * Description:
+ * Perform Intra_16x16 prediction for luma samples. If the upper-right block 
+ * is not available, then duplication work should be handled inside the 
+ * function. Users need not define them outside. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcLeft - Pointer to the buffer of 16 left pixels: p[x, y] (x = -1, y = 
+ *            0..15) 
+ *   pSrcAbove - Pointer to the buffer of 16 above pixels: p[x,y] (x = 0..15, 
+ *            y= -1); must be aligned on a 16-byte boundary. 
+ *   pSrcAboveLeft - Pointer to the above left pixels: p[x,y] (x = -1, y = -1) 
+ *   leftStep - Step of left pixel buffer; must be a multiple of 16. 
+ *   dstStep - Step of the destination buffer; must be a multiple of 16. 
+ *   predMode - Intra_16x16 prediction mode, please refer to section 3.4.1. 
+ *   availability - Neighboring 16x16 MB availability flag. Refer to 
+ *                  section 3.4.4. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst -Pointer to the destination buffer; must be aligned on a 16-byte 
+ *            boundary. 
+ *
+ * Return Value:
+ *    If the function runs without error, it returns OMX_Sts_NoErr. 
+ *    If one of the following cases occurs, the function returns 
+ *              OMX_Sts_BadArgErr: 
+ *    pDst is NULL. 
+ *    dstStep < 16. or dstStep is not a multiple of 16. 
+ *    leftStep is not a multiple of 16. 
+ *    predMode is not in the valid range of enumeration 
+ *              OMXVCM4P10Intra16x16PredMode 
+ *    predMode is OMX_VC_16X16_VERT, but availability doesn't set 
+ *              OMX_VC_UPPER indicating p[x,-1] (x = 0..15) is not available. 
+ *    predMode is OMX_VC_16X16_HOR, but availability doesn't set OMX_VC_LEFT 
+ *              indicating p[-1,y] (y = 0..15) is not available. 
+ *    predMode is OMX_VC_16X16_PLANE, but availability doesn't set 
+ *              OMX_VC_UPPER_LEFT or OMX_VC_UPPER or OMX_VC_LEFT indicating 
+ *              p[x,-1](x = 0..15), or p[-1,y] (y = 0..15), or p[-1,-1] is not 
+ *              available. 
+ *    availability sets OMX_VC_UPPER, but pSrcAbove is NULL. 
+ *    availability sets OMX_VC_LEFT, but pSrcLeft is NULL. 
+ *    availability sets OMX_VC_UPPER_LEFT, but pSrcAboveLeft is NULL. 
+ *    either pSrcAbove or pDst is not aligned on a 16-byte boundary.  
+ *
+ * Note: 
+ *     pSrcAbove, pSrcAbove, pSrcAboveLeft may be invalid pointers if 
+ *     they are not used by intra prediction implied in predMode. 
+ * Note: 
+ *     OMX_VC_UPPER_RIGHT is not used in intra_16x16 luma prediction. 
+ *
+ */
+OMXResult omxVCM4P10_PredictIntra_16x16(
+    const OMX_U8* pSrcLeft, 
+    const OMX_U8 *pSrcAbove, 
+    const OMX_U8 *pSrcAboveLeft, 
+    OMX_U8* pDst, 
+    OMX_INT leftStep, 
+    OMX_INT dstStep, 
+    OMXVCM4P10Intra16x16PredMode predMode, 
+    OMX_S32 availability)
+{
+    int x,y,Sum,Count;
+    int H,V,a,b,c;
+
+    armRetArgErrIf(pDst == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(dstStep < 16,  OMX_Sts_BadArgErr);
+    armRetArgErrIf((dstStep % 16) != 0,  OMX_Sts_BadArgErr);
+    armRetArgErrIf((leftStep % 16) != 0,  OMX_Sts_BadArgErr);
+    armRetArgErrIf(armNot16ByteAligned(pSrcAbove), OMX_Sts_BadArgErr);
+    armRetArgErrIf(armNot16ByteAligned(pDst), OMX_Sts_BadArgErr);        
+    armRetArgErrIf((availability & OMX_VC_UPPER)      && pSrcAbove     == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf((availability & OMX_VC_LEFT )      && pSrcLeft      == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf((availability & OMX_VC_UPPER_LEFT) && pSrcAboveLeft == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(predMode==OMX_VC_16X16_VERT  && !(availability & OMX_VC_UPPER),      OMX_Sts_BadArgErr);
+    armRetArgErrIf(predMode==OMX_VC_16X16_HOR   && !(availability & OMX_VC_LEFT),       OMX_Sts_BadArgErr);
+    armRetArgErrIf(predMode==OMX_VC_16X16_PLANE && !(availability & OMX_VC_UPPER),      OMX_Sts_BadArgErr);
+    armRetArgErrIf(predMode==OMX_VC_16X16_PLANE && !(availability & OMX_VC_UPPER_LEFT), OMX_Sts_BadArgErr);
+    armRetArgErrIf(predMode==OMX_VC_16X16_PLANE && !(availability & OMX_VC_LEFT),       OMX_Sts_BadArgErr);
+    armRetArgErrIf((unsigned)predMode > OMX_VC_16X16_PLANE,  OMX_Sts_BadArgErr);
+
+    switch (predMode)
+    {
+    case OMX_VC_16X16_VERT:
+        for (y=0; y<16; y++)
+        {
+            for (x=0; x<16; x++)
+            {
+                pDst[y*dstStep+x] = pSrcAbove[x];
+            }
+        }
+        break;
+
+    case OMX_VC_16X16_HOR:
+        for (y=0; y<16; y++)
+        {
+            for (x=0; x<16; x++)
+            {
+                pDst[y*dstStep+x] = pSrcLeft[y*leftStep];
+            }
+        }
+        break;
+
+    case OMX_VC_16X16_DC:
+        /* This can always be used even if no blocks available */
+        Sum = 0;
+        Count = 0;
+        if (availability & OMX_VC_LEFT)
+        {
+            for (y=0; y<16; y++)
+            {
+                Sum += pSrcLeft[y*leftStep];
+            }
+            Count++;
+        }
+        if (availability & OMX_VC_UPPER)
+        {
+            for (x=0; x<16; x++)
+            {
+                Sum += pSrcAbove[x];
+            }
+            Count++;
+        }
+        if (Count==0)
+        {
+            Sum = 128;
+        }
+        else if (Count==1)
+        {
+            Sum = (Sum + 8) >> 4;
+        }
+        else /* Count = 2 */
+        {
+            Sum = (Sum + 16) >> 5;
+        }
+        for (y=0; y<16; y++)
+        {
+            for (x=0; x<16; x++)
+            {
+                pDst[y*dstStep+x] = (OMX_U8)Sum;
+            }
+        }
+        break;
+
+    case OMX_VC_16X16_PLANE:
+        H = 8*(pSrcAbove[15] - pSrcAboveLeft[0]);
+        for (x=6; x>=0; x--)
+        {
+            H += (x+1)*(pSrcAbove[8+x] - pSrcAbove[6-x]);
+        }
+        V = 8*(pSrcLeft[15*leftStep] - pSrcAboveLeft[0]);
+        for (y=6; y>=0; y--)
+        {
+            V += (y+1)*(pSrcLeft[(8+y)*leftStep] - pSrcLeft[(6-y)*leftStep]);
+        }
+        a = 16*(pSrcAbove[15] + pSrcLeft[15*leftStep]);
+        b = (5*H+32)>>6;
+        c = (5*V+32)>>6;
+        for (y=0; y<16; y++)
+        {
+            for (x=0; x<16; x++)
+            {
+                Sum = (a + b*(x-7) + c*(y-7) + 16)>>5;
+                pDst[y*dstStep+x] = (OMX_U8)armClip(0,255,Sum);
+            }
+        }
+        break;
+    }
+
+    return OMX_Sts_NoErr;
+}
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_PredictIntra_4x4.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_PredictIntra_4x4.c
new file mode 100644
index 0000000..3fa8212
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_PredictIntra_4x4.c
@@ -0,0 +1,338 @@
+/* ----------------------------------------------------------------
+ *
+ * 
+ * File Name:  omxVCM4P10_PredictIntra_4x4.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * H.264 4x4 intra prediction module
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+
+/**
+ * Function:  omxVCM4P10_PredictIntra_4x4   (6.3.3.1.1)
+ *
+ * Description:
+ * Perform Intra_4x4 prediction for luma samples. If the upper-right block is 
+ * not available, then duplication work should be handled inside the function. 
+ * Users need not define them outside. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcLeft -  Pointer to the buffer of 4 left pixels: 
+ *                  p[x, y] (x = -1, y = 0..3) 
+ *   pSrcAbove - Pointer to the buffer of 8 above pixels: 
+ *                  p[x,y] (x = 0..7, y =-1); 
+ *               must be aligned on a 4-byte boundary. 
+ *   pSrcAboveLeft - Pointer to the above left pixels: p[x,y] (x = -1, y = -1) 
+ *   leftStep - Step of left pixel buffer; must be a multiple of 4. 
+ *   dstStep - Step of the destination buffer; must be a multiple of 4. 
+ *   predMode - Intra_4x4 prediction mode. 
+ *   availability - Neighboring 4x4 block availability flag, refer to 
+ *             "Neighboring Macroblock Availability" . 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - Pointer to the destination buffer; must be aligned on a 4-byte 
+ *            boundary. 
+ *
+ * Return Value:
+ *    If the function runs without error, it returns OMX_Sts_NoErr. 
+ *    If one of the following cases occurs, the function returns 
+ *              OMX_Sts_BadArgErr: 
+ *    pDst is NULL. 
+ *    dstStep < 4, or dstStep is not a multiple of 4. 
+ *    leftStep is not a multiple of 4. 
+ *    predMode is not in the valid range of enumeration 
+ *              OMXVCM4P10Intra4x4PredMode. 
+ *    predMode is OMX_VC_4x4_VERT, but availability doesn't set OMX_VC_UPPER 
+ *              indicating p[x,-1] (x = 0..3) is not available. 
+ *    predMode is OMX_VC_4x4_HOR, but availability doesn't set OMX_VC_LEFT 
+ *              indicating p[-1,y] (y = 0..3) is not available. 
+ *    predMode is OMX_VC_4x4_DIAG_DL, but availability doesn't set 
+ *              OMX_VC_UPPER indicating p[x, 1] (x = 0..3) is not available. 
+ *    predMode is OMX_VC_4x4_DIAG_DR, but availability doesn't set 
+ *              OMX_VC_UPPER_LEFT or OMX_VC_UPPER or OMX_VC_LEFT indicating 
+ *              p[x,-1] (x = 0..3), or p[-1,y] (y = 0..3) or p[-1,-1] is not 
+ *              available. 
+ *    predMode is OMX_VC_4x4_VR, but availability doesn't set 
+ *              OMX_VC_UPPER_LEFT or OMX_VC_UPPER or OMX_VC_LEFT indicating 
+ *              p[x,-1] (x = 0..3), or p[-1,y] (y = 0..3) or p[-1,-1] is not 
+ *              available. 
+ *    predMode is OMX_VC_4x4_HD, but availability doesn't set 
+ *              OMX_VC_UPPER_LEFT or OMX_VC_UPPER or OMX_VC_LEFT indicating 
+ *              p[x,-1] (x = 0..3), or p[-1,y] (y = 0..3) or p[-1,-1] is not 
+ *              available. 
+ *    predMode is OMX_VC_4x4_VL, but availability doesn't set OMX_VC_UPPER 
+ *              indicating p[x,-1] (x = 0..3) is not available. 
+ *    predMode is OMX_VC_4x4_HU, but availability doesn't set OMX_VC_LEFT 
+ *              indicating p[-1,y] (y = 0..3) is not available. 
+ *    availability sets OMX_VC_UPPER, but pSrcAbove is NULL. 
+ *    availability sets OMX_VC_LEFT, but pSrcLeft is NULL. 
+ *    availability sets OMX_VC_UPPER_LEFT, but pSrcAboveLeft is NULL. 
+ *    either pSrcAbove or pDst is not aligned on a 4-byte boundary.  
+ *
+ * Note: 
+ *     pSrcAbove, pSrcAbove, pSrcAboveLeft may be invalid pointers if 
+ *     they are not used by intra prediction as implied in predMode. 
+ *
+ */
+
+OMXResult omxVCM4P10_PredictIntra_4x4(
+     const OMX_U8* pSrcLeft,
+     const OMX_U8 *pSrcAbove,
+     const OMX_U8 *pSrcAboveLeft,
+     OMX_U8* pDst,
+     OMX_INT leftStep,
+     OMX_INT dstStep,
+     OMXVCM4P10Intra4x4PredMode predMode,
+     OMX_S32 availability        
+ )
+{
+    int x, y;
+    OMX_U8 pTmp[10];
+
+    armRetArgErrIf(pDst == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf((leftStep % 4) != 0,  OMX_Sts_BadArgErr);
+    armRetArgErrIf((dstStep % 4) != 0,  OMX_Sts_BadArgErr);
+    armRetArgErrIf((dstStep < 4),  OMX_Sts_BadArgErr);
+    armRetArgErrIf(armNot4ByteAligned(pSrcAbove), OMX_Sts_BadArgErr);
+    armRetArgErrIf(armNot4ByteAligned(pDst), OMX_Sts_BadArgErr);    
+    armRetArgErrIf((availability & OMX_VC_UPPER)      && pSrcAbove     == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf((availability & OMX_VC_LEFT )      && pSrcLeft      == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf((availability & OMX_VC_UPPER_LEFT) && pSrcAboveLeft == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(predMode==OMX_VC_4X4_VERT    && !(availability & OMX_VC_UPPER),      OMX_Sts_BadArgErr);
+    armRetArgErrIf(predMode==OMX_VC_4X4_HOR     && !(availability & OMX_VC_LEFT),       OMX_Sts_BadArgErr);
+    armRetArgErrIf(predMode==OMX_VC_4X4_DIAG_DL && !(availability & OMX_VC_UPPER),      OMX_Sts_BadArgErr);
+    armRetArgErrIf(predMode==OMX_VC_4X4_DIAG_DR && !(availability & OMX_VC_UPPER),      OMX_Sts_BadArgErr);
+    armRetArgErrIf(predMode==OMX_VC_4X4_DIAG_DR && !(availability & OMX_VC_UPPER_LEFT), OMX_Sts_BadArgErr);
+    armRetArgErrIf(predMode==OMX_VC_4X4_DIAG_DR && !(availability & OMX_VC_LEFT),       OMX_Sts_BadArgErr);
+    armRetArgErrIf(predMode==OMX_VC_4X4_VR      && !(availability & OMX_VC_UPPER),      OMX_Sts_BadArgErr);
+    armRetArgErrIf(predMode==OMX_VC_4X4_VR      && !(availability & OMX_VC_UPPER_LEFT), OMX_Sts_BadArgErr);
+    armRetArgErrIf(predMode==OMX_VC_4X4_VR      && !(availability & OMX_VC_LEFT),       OMX_Sts_BadArgErr);
+    armRetArgErrIf(predMode==OMX_VC_4X4_HD      && !(availability & OMX_VC_UPPER),      OMX_Sts_BadArgErr);
+    armRetArgErrIf(predMode==OMX_VC_4X4_HD      && !(availability & OMX_VC_UPPER_LEFT), OMX_Sts_BadArgErr);
+    armRetArgErrIf(predMode==OMX_VC_4X4_HD      && !(availability & OMX_VC_LEFT),       OMX_Sts_BadArgErr);
+    armRetArgErrIf(predMode==OMX_VC_4X4_VL      && !(availability & OMX_VC_UPPER),      OMX_Sts_BadArgErr);
+    armRetArgErrIf(predMode==OMX_VC_4X4_HU      && !(availability & OMX_VC_LEFT),       OMX_Sts_BadArgErr);
+    armRetArgErrIf((unsigned)predMode > OMX_VC_4X4_HU,   OMX_Sts_BadArgErr);    
+    
+    /* Note: This code must not read the pSrc arrays unless the corresponding
+     * block is marked as available. If the block is not avaibable then pSrc
+     * may not be a valid pointer.
+     *
+     * Note: To make the code more readable we refer to the neighbouring pixels
+     * in variables named as below:
+     *
+     *    UL U0 U1 U2 U3 U4 U5 U6 U7
+     *    L0 xx xx xx xx
+     *    L1 xx xx xx xx
+     *    L2 xx xx xx xx
+     *    L3 xx xx xx xx
+     */
+     
+#define UL pSrcAboveLeft[0]
+#define U0 pSrcAbove[0]
+#define U1 pSrcAbove[1]
+#define U2 pSrcAbove[2]
+#define U3 pSrcAbove[3]
+#define U4 pSrcAbove[4]
+#define U5 pSrcAbove[5]
+#define U6 pSrcAbove[6]
+#define U7 pSrcAbove[7]
+#define L0 pSrcLeft[0*leftStep]
+#define L1 pSrcLeft[1*leftStep]
+#define L2 pSrcLeft[2*leftStep]
+#define L3 pSrcLeft[3*leftStep]
+
+    switch (predMode)
+    {
+    case OMX_VC_4X4_VERT:
+        for (y=0; y<4; y++)
+        {
+            pDst[y*dstStep+0] = U0;
+            pDst[y*dstStep+1] = U1;
+            pDst[y*dstStep+2] = U2;
+            pDst[y*dstStep+3] = U3;
+        }
+        break;
+
+    case OMX_VC_4X4_HOR:
+        for (x=0; x<4; x++)
+        {
+            pDst[0*dstStep+x] = L0;
+            pDst[1*dstStep+x] = L1;
+            pDst[2*dstStep+x] = L2;
+            pDst[3*dstStep+x] = L3;
+        }
+        break;
+    
+    case OMX_VC_4X4_DC:
+        /* This can always be used even if no blocks available */
+        armVCM4P10_PredictIntraDC4x4(pSrcLeft, pSrcAbove, pDst, leftStep, dstStep, availability);
+        break;
+        
+    case OMX_VC_4X4_DIAG_DL:
+        pTmp[0] = (OMX_U8)((U0 + 2*U1 + U2 + 2)>>2);
+        pTmp[1] = (OMX_U8)((U1 + 2*U2 + U3 + 2)>>2);
+        if (availability & OMX_VC_UPPER_RIGHT)
+        {
+            pTmp[2] = (OMX_U8)((U2 + 2*U3 + U4 + 2)>>2);
+            pTmp[3] = (OMX_U8)((U3 + 2*U4 + U5 + 2)>>2);
+            pTmp[4] = (OMX_U8)((U4 + 2*U5 + U6 + 2)>>2);
+            pTmp[5] = (OMX_U8)((U5 + 2*U6 + U7 + 2)>>2);
+            pTmp[6] = (OMX_U8)((U6 + 3*U7      + 2)>>2);
+        }
+        else
+        {
+            pTmp[2] = (OMX_U8)((U2 + 3*U3      + 2)>>2);
+            pTmp[3] = U3;
+            pTmp[4] = U3;
+            pTmp[5] = U3;
+            pTmp[6] = U3;
+        }
+        for (y=0; y<4; y++)
+        {
+            for (x=0; x<4; x++)
+            {
+                pDst[y*dstStep+x] = pTmp[x+y];
+            }
+        }
+        break;
+
+    case OMX_VC_4X4_DIAG_DR:        
+        /* x-y = -3, -2, -1, 0, 1, 2, 3 */
+        pTmp[0] = (OMX_U8)((L1 + 2*L2 + L3 + 2)>>2);
+        pTmp[1] = (OMX_U8)((L0 + 2*L1 + L2 + 2)>>2);
+        pTmp[2] = (OMX_U8)((UL + 2*L0 + L1 + 2)>>2);
+        pTmp[3] = (OMX_U8)((U0 + 2*UL + L0 + 2)>>2);
+        pTmp[4] = (OMX_U8)((U1 + 2*U0 + UL + 2)>>2);
+        pTmp[5] = (OMX_U8)((U2 + 2*U1 + U0 + 2)>>2);
+        pTmp[6] = (OMX_U8)((U3 + 2*U2 + U1 + 2)>>2);
+        for (y=0; y<4; y++)
+        {
+            for (x=0; x<4; x++)
+            {
+                pDst[y*dstStep+x] = pTmp[3+x-y];
+            }
+        }
+        break;
+
+    case OMX_VC_4X4_VR:
+        /* zVR=2x-y = -3, -2, -1, 0, 1, 2, 3, 4, 5, 6
+         * x-(y>>1) = -1, -1,  0, 0, 1, 1, 2, 2, 3, 3
+         * y        =  3,  2,  ?, ?, ?, ?, ?, ?, 1, 0
+         */
+        pTmp[0] = (OMX_U8)((L2 + 2*L1 + L0 + 2)>>2);
+        pTmp[1] = (OMX_U8)((L1 + 2*L0 + UL + 2)>>2);
+        pTmp[2] = (OMX_U8)((L0 + 2*UL + U0 + 2)>>2);
+        pTmp[3] = (OMX_U8)((UL + U0 + 1)>>1);
+        pTmp[4] = (OMX_U8)((UL + 2*U0 + U1 + 2)>>2);
+        pTmp[5] = (OMX_U8)((U0 + U1 + 1)>>1);
+        pTmp[6] = (OMX_U8)((U0 + 2*U1 + U2 + 2)>>2);
+        pTmp[7] = (OMX_U8)((U1 + U2 + 1)>>1);
+        pTmp[8] = (OMX_U8)((U1 + 2*U2 + U3 + 2)>>2);
+        pTmp[9] = (OMX_U8)((U2 + U3 + 1)>>1);
+        for (y=0; y<4; y++)
+        {
+            for (x=0; x<4; x++)
+            {
+                pDst[y*dstStep+x] = pTmp[3+2*x-y];
+            }
+        }
+        break;
+
+    case OMX_VC_4X4_HD:
+        /* zHD=2y-x = -3 -2 -1  0  1  2  3  4  5  6
+         * y-(x>>1) = -1 -1  0  0  1  1  2  2  3  3
+         * x        =  3  2                    1  0
+         */
+        pTmp[0] = (OMX_U8)((U2 + 2*U1 + U0 + 2)>>2);
+        pTmp[1] = (OMX_U8)((U1 + 2*U0 + UL + 2)>>2);
+        pTmp[2] = (OMX_U8)((U0 + 2*UL + L0 + 2)>>2);
+        pTmp[3] = (OMX_U8)((UL + L0 + 1)>>1);
+        pTmp[4] = (OMX_U8)((UL + 2*L0 + L1 + 2)>>2);
+        pTmp[5] = (OMX_U8)((L0 + L1 + 1)>>1);
+        pTmp[6] = (OMX_U8)((L0 + 2*L1 + L2 + 2)>>2);
+        pTmp[7] = (OMX_U8)((L1 + L2 + 1)>>1);
+        pTmp[8] = (OMX_U8)((L1 + 2*L2 + L3 + 2)>>2);
+        pTmp[9] = (OMX_U8)((L2 + L3 + 1)>>1);
+        for (y=0; y<4; y++)
+        {
+            for (x=0; x<4; x++)
+            {
+                pDst[y*dstStep+x] = pTmp[3+2*y-x];
+            }
+        }
+        break;
+
+    case OMX_VC_4X4_VL:
+        /* Note: x+(y>>1) = (2*x+y)>>1
+         * 2x+y = 0 1 2 3 4 5 6 7 8 9
+         */
+        pTmp[0] = (OMX_U8)((U0 + U1 + 1)>>1);
+        pTmp[1] = (OMX_U8)((U0 + 2*U1 + U2 + 2)>>2);
+        pTmp[2] = (OMX_U8)((U1 + U2 + 1)>>1);
+        pTmp[3] = (OMX_U8)((U1 + 2*U2 + U3 + 2)>>2);
+        pTmp[4] = (OMX_U8)((U2 + U3 + 1)>>1);
+        if (availability & OMX_VC_UPPER_RIGHT)
+        {
+            pTmp[5] = (OMX_U8)((U2 + 2*U3 + U4 + 2)>>2);
+            pTmp[6] = (OMX_U8)((U3 + U4 + 1)>>1);
+            pTmp[7] = (OMX_U8)((U3 + 2*U4 + U5 + 2)>>2);
+            pTmp[8] = (OMX_U8)((U4 + U5 + 1)>>1);
+            pTmp[9] = (OMX_U8)((U4 + 2*U5 + U6 + 2)>>2);
+        }
+        else
+        {
+            pTmp[5] = (OMX_U8)((U2 + 3*U3 + 2)>>2);
+            pTmp[6] = U3;
+            pTmp[7] = U3;
+            pTmp[8] = U3;
+            pTmp[9] = U3;
+        }
+        for (y=0; y<4; y++)
+        {
+            for (x=0; x<4; x++)
+            {
+                pDst[y*dstStep+x] = pTmp[2*x+y];
+            }
+        }
+        break;
+
+    case OMX_VC_4X4_HU:
+        /* zHU = x+2*y */
+        pTmp[0] = (OMX_U8)((L0 + L1 + 1)>>1);
+        pTmp[1] = (OMX_U8)((L0 + 2*L1 + L2 + 2)>>2);
+        pTmp[2] = (OMX_U8)((L1 + L2 + 1)>>1);
+        pTmp[3] = (OMX_U8)((L1 + 2*L2 + L3 + 2)>>2);
+        pTmp[4] = (OMX_U8)((L2 + L3 + 1)>>1);
+        pTmp[5] = (OMX_U8)((L2 + 3*L3 + 2)>>2);
+        pTmp[6] = L3;
+        pTmp[7] = L3;
+        pTmp[8] = L3;
+        pTmp[9] = L3;
+        for (y=0; y<4; y++)
+        {
+            for (x=0; x<4; x++)
+            {
+                pDst[y*dstStep+x] = pTmp[x+2*y];
+            }
+        }
+        break;
+    }
+
+    return OMX_Sts_NoErr;
+}
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_SADQuar_16x.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_SADQuar_16x.c
new file mode 100644
index 0000000..c8114ee
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_SADQuar_16x.c
@@ -0,0 +1,86 @@
+/**
+ * 
+ * File Name:  omxVCM4P10_SADQuar_16x.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * Description:
+ * This function will calculate SAD of pSrc with average of two Ref blocks
+ * of 16x16 or 16x8
+ * 
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armVC.h"
+#include "armCOMM.h"
+
+/**
+ * Function:  omxVCM4P10_SADQuar_16x   (6.3.5.4.4)
+ *
+ * Description:
+ * This function calculates the SAD between one block (pSrc) and the average 
+ * of the other two (pSrcRef0 and pSrcRef1) for 16x16 or 16x8 blocks.  
+ * Rounding is applied according to the convention (a+b+1)>>1. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - Pointer to the original block; must be aligned on a 16-byte 
+ *            boundary. 
+ *   pSrcRef0 - Pointer to reference block 0 
+ *   pSrcRef1 - Pointer to reference block 1 
+ *   iSrcStep - Step of the original block buffer; must be a multiple of 16 
+ *   iRefStep0 - Step of reference block 0 
+ *   iRefStep1 - Step of reference block 1 
+ *   iHeight - Height of the block; must be equal to either 8 or 16 
+ *
+ * Output Arguments:
+ *   
+ *   pDstSAD -Pointer of result SAD 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    iHeight is not equal to either 8 or 16. 
+ *    -    One of more of the following pointers is NULL: pSrc, pSrcRef0, 
+ *              pSrcRef1, pDstSAD. 
+ *    -    iSrcStep is not a multiple of 16 
+ *    -    Any alignment restrictions are violated 
+ *
+ */
+OMXResult omxVCM4P10_SADQuar_16x(
+	const OMX_U8* 	pSrc,
+    const OMX_U8* 	pSrcRef0,
+	const OMX_U8* 	pSrcRef1,	
+    OMX_U32 	iSrcStep,
+    OMX_U32		iRefStep0,
+    OMX_U32		iRefStep1,
+    OMX_U32*	pDstSAD,
+    OMX_U32     iHeight
+)
+{
+    /* check for argument error */
+    armRetArgErrIf(pSrc == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pSrcRef0 == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pSrcRef1 == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pDstSAD == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf((iHeight != 16) && (iHeight != 8), OMX_Sts_BadArgErr)
+    armRetArgErrIf(armNot16ByteAligned(pSrc), OMX_Sts_BadArgErr)
+    armRetArgErrIf((iSrcStep == 0) || (iSrcStep & 15), OMX_Sts_BadArgErr)
+    
+
+    return armVCM4P10_SADQuar
+        (pSrc, pSrcRef0, pSrcRef1, iSrcStep, 
+        iRefStep0, iRefStep1, pDstSAD, iHeight, 16);
+}
+
+/*****************************************************************************
+ *                              END OF FILE
+ *****************************************************************************/
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_SADQuar_4x.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_SADQuar_4x.c
new file mode 100644
index 0000000..4b330ba
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_SADQuar_4x.c
@@ -0,0 +1,85 @@
+/**
+ * 
+ * File Name:  omxVCM4P10_SADQuar_4x.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * Description:
+ * This function will calculate SAD of pSrc with average of two Ref blocks
+ * of 4x8 or 4x4 blocks
+ * 
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armVC.h"
+#include "armCOMM.h"
+
+/**
+ * Function:  omxVCM4P10_SADQuar_4x   (6.3.5.4.2)
+ *
+ * Description:
+ * This function calculates the SAD between one block (pSrc) and the average 
+ * of the other two (pSrcRef0 and pSrcRef1) for 4x8 or 4x4 blocks.  Rounding 
+ * is applied according to the convention (a+b+1)>>1. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - Pointer to the original block; must be aligned on a 4-byte 
+ *            boundary. 
+ *   pSrcRef0 - Pointer to reference block 0 
+ *   pSrcRef1 - Pointer to reference block 1 
+ *   iSrcStep - Step of the original block buffer; must be a multiple of 4. 
+ *   iRefStep0 - Step of reference block 0 
+ *   iRefStep1 - Step of reference block 1 
+ *   iHeight - Height of the block; must be equal to either 4 or 8. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstSAD - Pointer of result SAD 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    iHeight is not equal to either 4 or 8. 
+ *    -    One of more of the following pointers is NULL: pSrc, pSrcRef0, 
+ *              pSrcRef1, pDstSAD. 
+ *    -    iSrcStep is not a multiple of 4 
+ *    -    Any alignment restrictions are violated 
+ *
+ */
+OMXResult omxVCM4P10_SADQuar_4x( 
+	  const OMX_U8* 	pSrc,
+      const OMX_U8* 	pSrcRef0,
+	  const OMX_U8* 	pSrcRef1,	
+      OMX_U32 	iSrcStep,
+      OMX_U32	iRefStep0,
+      OMX_U32	iRefStep1,
+      OMX_U32*	pDstSAD,
+      OMX_U32   iHeight
+)
+{
+    /* check for argument error */
+    armRetArgErrIf(pSrc == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pSrcRef0 == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pSrcRef1 == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pDstSAD == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf((iHeight != 8) && (iHeight != 4), OMX_Sts_BadArgErr);
+    armRetArgErrIf(armNot4ByteAligned(pSrc), OMX_Sts_BadArgErr);
+    armRetArgErrIf((iSrcStep == 0) || (iSrcStep & 3), OMX_Sts_BadArgErr);
+    
+    return armVCM4P10_SADQuar
+        (pSrc, pSrcRef0, pSrcRef1, iSrcStep, 
+        iRefStep0, iRefStep1, pDstSAD, iHeight, 4);
+}
+
+/*****************************************************************************
+ *                              END OF FILE
+ *****************************************************************************/
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_SADQuar_8x.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_SADQuar_8x.c
new file mode 100644
index 0000000..c9e9c24
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_SADQuar_8x.c
@@ -0,0 +1,87 @@
+/**
+ * 
+ * File Name:  omxVCM4P10_SADQuar_8x.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * Description:
+ * This function will calculate SAD of pSrc with average of two Ref blocks
+ * of 8x16 or 8x8 or 8x4
+ * 
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armVC.h"
+#include "armCOMM.h"
+
+/**
+ * Function:  omxVCM4P10_SADQuar_8x   (6.3.5.4.3)
+ *
+ * Description:
+ * This function calculates the SAD between one block (pSrc) and the average 
+ * of the other two (pSrcRef0 and pSrcRef1) for 8x16, 8x8, or 8x4 blocks.  
+ * Rounding is applied according to the convention (a+b+1)>>1. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - Pointer to the original block; must be aligned on an 8-byte 
+ *            boundary. 
+ *   pSrcRef0 - Pointer to reference block 0 
+ *   pSrcRef1 - Pointer to reference block 1 
+ *   iSrcStep - Step of the original block buffer; must be a multiple of 8. 
+ *   iRefStep0 - Step of reference block 0 
+ *   iRefStep1 - Step of reference block 1 
+ *   iHeight - Height of the block; must be equal either 4, 8, or 16. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstSAD - Pointer of result SAD 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    iHeight is not equal to either 4, 8, or 16. 
+ *    -    One of more of the following pointers is NULL: pSrc, pSrcRef0, 
+ *              pSrcRef1, pDstSAD. 
+ *    -    iSrcStep is not a multiple of 8 
+ *    -    Any alignment restrictions are violated 
+ *
+ */
+OMXResult omxVCM4P10_SADQuar_8x( 
+	const OMX_U8* 	pSrc,
+    const OMX_U8* 	pSrcRef0,
+	const OMX_U8* 	pSrcRef1,	
+    OMX_U32 	iSrcStep,
+    OMX_U32		iRefStep0,
+    OMX_U32		iRefStep1,
+    OMX_U32*	pDstSAD,
+    OMX_U32     iHeight
+)
+{
+    /* check for argument error */
+    armRetArgErrIf(pSrc == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pSrcRef0 == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pSrcRef1 == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pDstSAD == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf((iHeight != 16) && (iHeight != 8) && 
+        (iHeight != 4), OMX_Sts_BadArgErr)
+    armRetArgErrIf(armNot8ByteAligned(pSrc), OMX_Sts_BadArgErr)
+    armRetArgErrIf((iSrcStep == 0) || (iSrcStep & 7), OMX_Sts_BadArgErr)
+    
+
+    return armVCM4P10_SADQuar
+        (pSrc, pSrcRef0, pSrcRef1, iSrcStep, 
+        iRefStep0, iRefStep1, pDstSAD, iHeight, 8);
+}
+
+/*****************************************************************************
+ *                              END OF FILE
+ *****************************************************************************/
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_SAD_4x.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_SAD_4x.c
new file mode 100644
index 0000000..927c454
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_SAD_4x.c
@@ -0,0 +1,77 @@
+/**
+ * 
+ * File Name:  omxVCM4P10_SAD_4x.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * Description:
+ * This function will calculate SAD for 4x8 and 4x4 blocks
+ * 
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armVC.h"
+#include "armCOMM.h"
+
+/**
+ * Function:  omxVCM4P10_SAD_4x   (6.3.5.4.1)
+ *
+ * Description:
+ * This function calculates the SAD for 4x8 and 4x4 blocks. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcOrg -Pointer to the original block; must be aligned on a 4-byte 
+ *            boundary. 
+ *   iStepOrg -Step of the original block buffer; must be a multiple of 4. 
+ *   pSrcRef -Pointer to the reference block 
+ *   iStepRef -Step of the reference block buffer 
+ *   iHeight -Height of the block; must be equal to either 4 or 8. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstSAD -Pointer of result SAD 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    One of more of the following pointers is NULL: 
+ *         pSrcOrg, pSrcRef, or pDstSAD 
+ *    -    iHeight is not equal to either 4 or 8. 
+ *    -    iStepOrg is not a multiple of 4 
+ *    -    Any alignment restrictions are violated 
+ *
+ */
+OMXResult omxVCM4P10_SAD_4x(	
+	const OMX_U8* 	pSrcOrg,
+	OMX_U32 	iStepOrg,
+	const OMX_U8* 	pSrcRef,
+	OMX_U32 	iStepRef,
+	OMX_S32*	pDstSAD,
+	OMX_U32		iHeight
+)
+{
+    /* check for argument error */
+    armRetArgErrIf(pSrcOrg == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pSrcRef == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pDstSAD == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf((iHeight != 8) && (iHeight != 4), OMX_Sts_BadArgErr)
+    armRetArgErrIf(armNot4ByteAligned(pSrcOrg), OMX_Sts_BadArgErr)
+    armRetArgErrIf((iStepOrg == 0) || (iStepOrg & 3), OMX_Sts_BadArgErr)
+    armRetArgErrIf((iStepRef == 0) || (iStepRef & 3), OMX_Sts_BadArgErr)
+
+    return armVCCOMM_SAD 
+        (pSrcOrg, iStepOrg, pSrcRef, iStepRef, pDstSAD, iHeight, 4);
+}
+
+/*****************************************************************************
+ *                              END OF FILE
+ *****************************************************************************/
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_SATD_4x4.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_SATD_4x4.c
new file mode 100644
index 0000000..a91ae66
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_SATD_4x4.c
@@ -0,0 +1,132 @@
+/**
+ * 
+ * File Name:  omxVCM4P10_SATD_4x4.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * Description:
+ * This function will calculate SAD for 4x4 blocks
+ * 
+ */
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+
+/**
+ * Function:  omxVCM4P10_SATD_4x4   (6.3.5.4.5)
+ *
+ * Description:
+ * This function calculates the sum of absolute transform differences (SATD) 
+ * for a 4x4 block by applying a Hadamard transform to the difference block 
+ * and then calculating the sum of absolute coefficient values. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcOrg - Pointer to the original block; must be aligned on a 4-byte 
+ *            boundary 
+ *   iStepOrg - Step of the original block buffer; must be a multiple of 4 
+ *   pSrcRef - Pointer to the reference block; must be aligned on a 4-byte 
+ *            boundary 
+ *   iStepRef - Step of the reference block buffer; must be a multiple of 4 
+ *
+ * Output Arguments:
+ *   
+ *   pDstSAD - pointer to the resulting SAD 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: 
+ *         pSrcOrg, pSrcRef, or pDstSAD either pSrcOrg 
+ *    -    pSrcRef is not aligned on a 4-byte boundary 
+ *    -    iStepOrg <= 0 or iStepOrg is not a multiple of 4 
+ *    -    iStepRef <= 0 or iStepRef is not a multiple of 4 
+ *
+ */
+OMXResult omxVCM4P10_SATD_4x4( 
+	const OMX_U8*		pSrcOrg,
+	OMX_U32     iStepOrg,                         
+	const OMX_U8*		pSrcRef,
+	OMX_U32		iStepRef,
+	OMX_U32*    pDstSAD
+)
+{
+    OMX_INT     i, j;
+    OMX_S32     SATD = 0;
+    OMX_S32     d [4][4], m1[4][4], m2[4][4];
+
+    /* check for argument error */
+    armRetArgErrIf(pSrcOrg == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pSrcRef == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(pDstSAD == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf((iStepOrg == 0) || (iStepOrg & 3), OMX_Sts_BadArgErr)
+    armRetArgErrIf((iStepRef == 0) || (iStepRef & 3), OMX_Sts_BadArgErr)
+    armRetArgErrIf(armNot4ByteAligned(pSrcOrg), OMX_Sts_BadArgErr)
+    armRetArgErrIf(armNot4ByteAligned(pSrcRef), OMX_Sts_BadArgErr)
+
+    /* Calculate the difference */
+    for (j = 0; j < 4; j++)
+    {
+        for (i = 0; i < 4; i++)
+        {
+            d [j][i] = pSrcOrg [j * iStepOrg + i] - pSrcRef [j * iStepRef + i];
+        }
+    }
+
+    /* Hadamard Transfor for 4x4 block */
+
+    /* Horizontal */
+    for (i = 0; i < 4; i++)
+    {
+        m1[i][0] = d[i][0] + d[i][2]; /* a+c */
+        m1[i][1] = d[i][1] + d[i][3]; /* b+d */
+        m1[i][2] = d[i][0] - d[i][2]; /* a-c */
+        m1[i][3] = d[i][1] - d[i][3]; /* b-d */
+
+        m2[i][0] = m1[i][0] + m1[i][1]; /* a+b+c+d */
+        m2[i][1] = m1[i][2] + m1[i][3]; /* a+b-c-d */
+        m2[i][2] = m1[i][2] - m1[i][3]; /* a-b-c+d */
+        m2[i][3] = m1[i][0] - m1[i][1]; /* a-b+c-d */
+
+    }
+
+    /* Vertical */
+    for (i = 0; i < 4; i++)
+    {
+        m1[0][i] = m2[0][i] + m2[2][i];
+        m1[1][i] = m2[1][i] + m2[3][i];
+        m1[2][i] = m2[0][i] - m2[2][i];
+        m1[3][i] = m2[1][i] - m2[3][i];
+
+        m2[0][i] = m1[0][i] + m1[1][i];
+        m2[1][i] = m1[2][i] + m1[3][i];
+        m2[2][i] = m1[2][i] - m1[3][i];
+        m2[3][i] = m1[0][i] - m1[1][i];
+    }
+    
+    /* calculate SAD for Transformed coefficients */
+    for (j = 0; j < 4; j++)
+    {
+        for (i = 0; i < 4; i++)
+        {
+            SATD += armAbs(m2 [j][i]);
+        }
+    }
+        
+    *pDstSAD = (SATD + 1) / 2;
+
+    return OMX_Sts_NoErr;
+}
+
+/*****************************************************************************
+ *                              END OF FILE
+ *****************************************************************************/
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_SubAndTransformQDQResidual.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_SubAndTransformQDQResidual.c
new file mode 100644
index 0000000..23a5662
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_SubAndTransformQDQResidual.c
@@ -0,0 +1,220 @@
+/**
+ * 
+ * File Name:  omxVCM4P10_SubAndTransformQDQResidual.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * Description:
+ * This function will calculate SAD for 4x4 blocks
+ * 
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+
+/**
+ * Function:  omxVCM4P10_SubAndTransformQDQResidual   (6.3.5.8.1)
+ *
+ * Description:
+ * This function subtracts the prediction signal from the original signal to 
+ * produce the difference signal and then performs a 4x4 integer transform and 
+ * quantization. The quantized transformed coefficients are stored as 
+ * pDstQuantCoeff. This function can also output dequantized coefficients or 
+ * unquantized DC coefficients optionally by setting the pointers 
+ * pDstDeQuantCoeff, pDCCoeff. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcOrg - Pointer to original signal. 4-byte alignment required. 
+ *   pSrcPred - Pointer to prediction signal. 4-byte alignment required. 
+ *   iSrcOrgStep - Step of the original signal buffer; must be a multiple of 
+ *            4. 
+ *   iSrcPredStep - Step of the prediction signal buffer; must be a multiple 
+ *            of 4. 
+ *   pNumCoeff -Number of non-zero coefficients after quantization. If this 
+ *            parameter is not required, it is set to NULL. 
+ *   nThreshSAD - Zero-block early detection threshold. If this parameter is 
+ *            not required, it is set to 0. 
+ *   iQP - Quantization parameter; must be in the range [0,51]. 
+ *   bIntra - Indicates whether this is an INTRA block, either 1-INTRA or 
+ *            0-INTER 
+ *
+ * Output Arguments:
+ *   
+ *   pDstQuantCoeff - Pointer to the quantized transformed coefficients.  
+ *            8-byte alignment required. 
+ *   pDstDeQuantCoeff - Pointer to the dequantized transformed coefficients 
+ *            if this parameter is not equal to NULL.  8-byte alignment 
+ *            required. 
+ *   pDCCoeff - Pointer to the unquantized DC coefficient if this parameter 
+ *            is not equal to NULL. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: 
+ *            pSrcOrg, pSrcPred, pNumCoeff, pDstQuantCoeff, 
+ *            pDstDeQuantCoeff, pDCCoeff 
+ *    -    pSrcOrg is not aligned on a 4-byte boundary 
+ *    -    pSrcPred is not aligned on a 4-byte boundary 
+ *    -    iSrcOrgStep is not a multiple of 4 
+ *    -    iSrcPredStep is not a multiple of 4 
+ *    -    pDstQuantCoeff or pDstDeQuantCoeff is not aligned on an 8-byte boundary 
+ *
+ */
+ OMXResult omxVCM4P10_SubAndTransformQDQResidual (
+	 const OMX_U8*		pSrcOrg,
+	 const OMX_U8*		pSrcPred,
+	 OMX_U32		iSrcOrgStep,
+	 OMX_U32		iSrcPredStep,
+	 OMX_S16*	    pDstQuantCoeff,
+	 OMX_S16* 	    pDstDeQuantCoeff,
+	 OMX_S16*	    pDCCoeff,
+	 OMX_S8*		pNumCoeff,
+	 OMX_U32		nThreshSAD,
+	 OMX_U32		iQP,
+	 OMX_U8		    bIntra
+)
+{
+    OMX_INT     i, j;
+    OMX_S8      NumCoeff = 0;
+    OMX_S16     Buf[16], m[16];
+    OMX_U32     QBits, QPper, QPmod, f;
+    OMX_S32     Value, MF, ThreshDC;
+
+    /* check for argument error */
+    armRetArgErrIf(pSrcOrg == NULL, OMX_Sts_BadArgErr)
+	armRetArgErrIf(pDstDeQuantCoeff == NULL, OMX_Sts_BadArgErr)
+	armRetArgErrIf(pNumCoeff == NULL, OMX_Sts_BadArgErr)
+	armRetArgErrIf(pDCCoeff == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(armNot4ByteAligned(pSrcOrg), OMX_Sts_BadArgErr)
+    armRetArgErrIf(pSrcPred == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(armNot4ByteAligned(pSrcPred), OMX_Sts_BadArgErr)
+    armRetArgErrIf(pDstQuantCoeff == NULL, OMX_Sts_BadArgErr)
+    armRetArgErrIf(armNot8ByteAligned(pDstQuantCoeff), OMX_Sts_BadArgErr)
+    armRetArgErrIf((pDstDeQuantCoeff != NULL) && 
+			armNot8ByteAligned(pDstDeQuantCoeff), OMX_Sts_BadArgErr)
+    armRetArgErrIf((bIntra != 0) && (bIntra != 1), OMX_Sts_BadArgErr)
+    armRetArgErrIf(iQP > 51, OMX_Sts_BadArgErr)
+    armRetArgErrIf(iSrcOrgStep == 0, OMX_Sts_BadArgErr)
+    armRetArgErrIf(iSrcPredStep == 0, OMX_Sts_BadArgErr)
+    armRetArgErrIf(iSrcOrgStep & 3, OMX_Sts_BadArgErr)
+    armRetArgErrIf(iSrcPredStep & 3, OMX_Sts_BadArgErr)
+
+    /* 
+     * Zero-Block Early detection using nThreshSAD param 
+     */
+
+    QPper = iQP / 6;
+    QPmod = iQP % 6;    
+    QBits = 15 + QPper;
+    
+    f = (1 << QBits) / (bIntra ? 3 : 6);
+    
+    /* Do Zero-Block Early detection if enabled */
+    if (nThreshSAD)
+    {
+        ThreshDC = ((1 << QBits) - f) / armVCM4P10_MFMatrix[QPmod][0];
+        if (nThreshSAD < ThreshDC)
+        {
+            /* Set block to zero */
+            if (pDCCoeff != NULL)
+            {
+                *pDCCoeff = 0;
+            }
+
+            for (j = 0; j < 4; j++)
+            {
+                for (i = 0; i < 4; i++)
+                {
+                    pDstQuantCoeff [4 * j + i] = 0;
+                    if (pDstDeQuantCoeff != NULL)
+                    {
+                        pDstDeQuantCoeff [4 * j + i] = 0;    
+                    }                    
+                }
+            }
+
+            if (pNumCoeff != NULL)
+            {
+                *pNumCoeff = 0;
+            }
+            return OMX_Sts_NoErr;
+        }
+    }
+
+
+   /* Calculate difference */
+    for (j = 0; j < 4; j++)
+    {
+        for (i = 0; i < 4; i++)
+        {
+            Buf [j * 4 + i] = 
+                pSrcOrg [j * iSrcOrgStep + i] - pSrcPred [j * iSrcPredStep + i];
+        }
+    }
+
+    /* Residual Transform */
+    armVCM4P10_FwdTransformResidual4x4 (m, Buf);
+
+    if (pDCCoeff != NULL)
+    {
+        /* Copy unquantized DC value into pointer */
+        *pDCCoeff = m[0];
+    }
+
+    /* Quantization */
+    for (j = 0; j < 4; j++)
+    {
+        for (i = 0; i < 4; i++)
+        {
+            MF = armVCM4P10_MFMatrix[QPmod][armVCM4P10_PosToVCol4x4[j * 4 + i]];
+            Value = armAbs(m[j * 4 + i]) * MF + f;
+            Value >>= QBits;
+            Value = m[j * 4 + i] < 0 ? -Value : Value;
+            Buf[4 * j + i] = pDstQuantCoeff [4 * j + i] = (OMX_S16)Value;
+            if ((pNumCoeff != NULL) && Value)
+            {
+                NumCoeff++;
+            }
+        }
+    }
+
+    /* Output number of non-zero Coeffs */
+    if (pNumCoeff != NULL)
+    {
+        *pNumCoeff = NumCoeff;
+    }
+    
+    /* Residual Inv Transform */
+    if (pDstDeQuantCoeff != NULL)
+    {    
+        /* Re Scale */
+        for (j = 0; j < 4; j++)
+        {
+            for (i = 0; i < 4; i++)
+            {
+                m [j * 4 + i]  = Buf [j * 4 + i] * (1 << QPper) *
+                    armVCM4P10_VMatrix[QPmod][armVCM4P10_PosToVCol4x4[j * 4 + i]];
+            }
+        }
+        armVCM4P10_TransformResidual4x4 (pDstDeQuantCoeff, m);        
+    }
+        
+    return OMX_Sts_NoErr;
+}
+
+/*****************************************************************************
+ *                              END OF FILE
+ *****************************************************************************/
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_TransformDequantChromaDCFromPair.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_TransformDequantChromaDCFromPair.c
new file mode 100644
index 0000000..9ad0e81
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_TransformDequantChromaDCFromPair.c
@@ -0,0 +1,131 @@
+/* ----------------------------------------------------------------
+ *
+ * 
+ * File Name:  omxVCM4P10_TransformDequantChromaDCFromPair.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * H.264 inverse quantize and transform module
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+
+/*
+ * Description:
+ * Dequantize Chroma 2x2 DC block
+ */
+
+static void DequantChromaDC2x2(
+     OMX_S16* pDst,
+     OMX_INT QP        
+)
+{
+    int Shift = (QP/6)-1 ;
+    int Scale = armVCM4P10_VMatrix[QP%6][0];
+    int i, Value;
+
+    if (Shift >= 0)
+    {
+        for (i=0; i<4; i++)
+        {
+            Value = (pDst[i] * Scale) << Shift;
+            pDst[i] = (OMX_S16)Value;
+        }
+    }
+    else
+    {
+        for (i=0; i<4; i++)
+        {
+            Value = (pDst[i] * Scale) >> 1;
+            pDst[i] = (OMX_S16)Value;
+        }
+    }
+}
+ 
+
+/*
+ * Description:
+ * Inverse Transform DC 2x2 Coefficients
+ */
+
+static void InvTransformDC2x2(OMX_S16* pData)
+{
+    int c00 = pData[0];
+    int c01 = pData[1];
+    int c10 = pData[2];
+    int c11 = pData[3];
+
+    int d00 = c00 + c01;
+    int d01 = c00 - c01;
+    int d10 = c10 + c11;
+    int d11 = c10 - c11;
+
+    pData[0] = (OMX_S16)(d00 + d10);
+    pData[1] = (OMX_S16)(d01 + d11);
+    pData[2] = (OMX_S16)(d00 - d10);
+    pData[3] = (OMX_S16)(d01 - d11);
+}
+
+
+/**
+ * Function:  omxVCM4P10_TransformDequantChromaDCFromPair   (6.3.4.2.2)
+ *
+ * Description:
+ * Reconstruct the 2x2 ChromaDC block from coefficient-position pair buffer, 
+ * perform integer inverse transformation, and dequantization for 2x2 chroma 
+ * DC coefficients, and update the pair buffer pointer to next non-empty 
+ * block. 
+ *
+ * Input Arguments:
+ *   
+ *   ppSrc - Double pointer to residual coefficient-position pair buffer 
+ *            output by CALVC decoding 
+ *   QP - Quantization parameter QpC 
+ *
+ * Output Arguments:
+ *   
+ *   ppSrc - *ppSrc is updated to the start of next non empty block 
+ *   pDst - Pointer to the reconstructed 2x2 ChromaDC coefficients buffer; 
+ *            must be aligned on a 4-byte boundary. 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    ppSrc or pDst is NULL. 
+ *    -    pDst is not 4-byte aligned. 
+ *    -    QP is not in the range of [0-51]. 
+ *
+ */
+
+OMXResult omxVCM4P10_TransformDequantChromaDCFromPair(
+     const OMX_U8 **ppSrc,
+     OMX_S16* pDst,
+     OMX_INT QP        
+ )
+{
+    armRetArgErrIf(ppSrc  == NULL,           OMX_Sts_BadArgErr);
+    armRetArgErrIf(*ppSrc == NULL,           OMX_Sts_BadArgErr);
+    armRetArgErrIf(pDst   == NULL,           OMX_Sts_BadArgErr);
+    armRetArgErrIf(armNot4ByteAligned(pDst), OMX_Sts_BadArgErr);
+    armRetArgErrIf(QP<0,                     OMX_Sts_BadArgErr);
+    armRetArgErrIf(QP>51,                    OMX_Sts_BadArgErr);
+
+    armVCM4P10_UnpackBlock2x2(ppSrc, pDst);
+    InvTransformDC2x2(pDst);
+    DequantChromaDC2x2(pDst, QP);
+
+    return OMX_Sts_NoErr;
+}
+
+/* End of file */
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_TransformDequantLumaDCFromPair.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_TransformDequantLumaDCFromPair.c
new file mode 100644
index 0000000..16c8be1
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_TransformDequantLumaDCFromPair.c
@@ -0,0 +1,148 @@
+/* ----------------------------------------------------------------
+ *
+ * 
+ * File Name:  omxVCM4P10_TransformDequantLumaDCFromPair.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * H.264 inverse quantize and transform module
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+
+/*
+ * Description:
+ * Dequantize Luma DC block
+ */
+
+static void DequantLumaDC4x4(
+     OMX_S16* pDst,
+     OMX_INT QP        
+)
+{
+    int Shift = (QP/6)-2 ;
+    int Scale = armVCM4P10_VMatrix[QP%6][0];
+    int i, Round, Value;
+
+    if (Shift >= 0)
+    {
+        for (i=0; i<16; i++)
+        {
+            Value = (pDst[i] * Scale) << Shift;
+            pDst[i] = (OMX_S16)Value;
+        }
+    }
+    else
+    {
+        Shift = -Shift;;
+        Round = 1<<(Shift-1);
+
+        for (i=0; i<16; i++)
+        {
+            Value = (pDst[i] * Scale + Round) >> Shift;
+            pDst[i] = (OMX_S16)Value;
+        }
+    }
+}
+
+ 
+
+/*
+ * Description:
+ * Inverse Transform DC 4x4 Coefficients
+ */
+static void InvTransformDC4x4(OMX_S16* pData)
+{
+    int i;
+
+    /* Transform rows */
+    for (i=0; i<16; i+=4)
+    {
+        int c0 = pData[i+0];
+        int c1 = pData[i+1];
+        int c2 = pData[i+2];
+        int c3 = pData[i+3];
+        pData[i+0] = (OMX_S16)(c0+c1+c2+c3);
+        pData[i+1] = (OMX_S16)(c0+c1-c2-c3);
+        pData[i+2] = (OMX_S16)(c0-c1-c2+c3);
+        pData[i+3] = (OMX_S16)(c0-c1+c2-c3);
+    }
+
+    /* Transform columns */
+    for (i=0; i<4; i++)
+    {
+        int c0 = pData[i+0];
+        int c1 = pData[i+4];
+        int c2 = pData[i+8];
+        int c3 = pData[i+12];
+        pData[i+0] = (OMX_S16)(c0+c1+c2+c3);
+        pData[i+4] = (OMX_S16)(c0+c1-c2-c3);
+        pData[i+8] = (OMX_S16)(c0-c1-c2+c3);
+        pData[i+12] = (OMX_S16)(c0-c1+c2-c3);
+    }
+}
+
+
+/**
+ * Function:  omxVCM4P10_TransformDequantLumaDCFromPair   (6.3.4.2.1)
+ *
+ * Description:
+ * Reconstructs the 4x4 LumaDC block from the coefficient-position pair 
+ * buffer, performs integer inverse, and dequantization for 4x4 LumaDC 
+ * coefficients, and updates the pair buffer pointer to the next non-empty 
+ * block. 
+ *
+ * Input Arguments:
+ *   
+ *   ppSrc - Double pointer to residual coefficient-position pair buffer 
+ *            output by CALVC decoding 
+ *   QP - Quantization parameter QpY 
+ *
+ * Output Arguments:
+ *   
+ *   ppSrc - *ppSrc is updated to the start of next non empty block 
+ *   pDst - Pointer to the reconstructed 4x4 LumaDC coefficients buffer; must 
+ *            be aligned on a 8-byte boundary. 
+ *
+ * Return Value:
+ *    OMX_Sts_NoErr, if the function runs without error.
+ *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
+ *    -    ppSrc or pDst is NULL. 
+ *    -    pDst is not 8 byte aligned. 
+ *    -    QP is not in the range of [0-51]. 
+ *
+ */
+
+OMXResult omxVCM4P10_TransformDequantLumaDCFromPair(
+     const OMX_U8 **ppSrc,
+     OMX_S16* pDst,
+     OMX_INT QP        
+ )
+{
+    armRetArgErrIf(ppSrc  == NULL,           OMX_Sts_BadArgErr);
+    armRetArgErrIf(*ppSrc == NULL,           OMX_Sts_BadArgErr);
+    armRetArgErrIf(pDst   == NULL,           OMX_Sts_BadArgErr);
+    armRetArgErrIf(armNot8ByteAligned(pDst), OMX_Sts_BadArgErr);
+    armRetArgErrIf(QP<0,                     OMX_Sts_BadArgErr);
+    armRetArgErrIf(QP>51,                    OMX_Sts_BadArgErr);
+
+    armVCM4P10_UnpackBlock4x4(ppSrc, pDst);
+    /*InvTransformDequantLumaDC4x4(pDst, QP);*/
+    InvTransformDC4x4(pDst);
+    DequantLumaDC4x4(pDst, QP);
+
+    return OMX_Sts_NoErr;
+}
+
+/* End of file */
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_TransformQuant_ChromaDC.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_TransformQuant_ChromaDC.c
new file mode 100644
index 0000000..b5544dd
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_TransformQuant_ChromaDC.c
@@ -0,0 +1,97 @@
+/**
+ * 
+ * File Name:  omxVCM4P10_TransformQuant_ChromaDC.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * Description:
+ * This function will calculate 4x4 hadamard transform of chroma DC  
+ * coefficients and quantization
+ * 
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armVC.h"
+#include "armCOMM.h"
+
+/**
+ * Function:  omxVCM4P10_TransformQuant_ChromaDC   (6.3.5.6.1)
+ *
+ * Description:
+ * This function performs 2x2 Hadamard transform of chroma DC coefficients 
+ * and then quantizes the coefficients. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - Pointer to the 2x2 array of chroma DC coefficients.  8-byte 
+ *            alignment required. 
+ *   iQP - Quantization parameter; must be in the range [0,51]. 
+ *   bIntra - Indicate whether this is an INTRA block. 1-INTRA, 0-INTER 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst - Pointer to transformed and quantized coefficients.  8-byte 
+ *            alignment required. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: 
+ *             pSrcDst 
+ *    -    pSrcDst is not aligned on an 8-byte boundary 
+ *
+ */
+OMXResult omxVCM4P10_TransformQuant_ChromaDC(
+	OMX_S16* 	pSrcDst,
+	OMX_U32		iQP,
+	OMX_U8		bIntra
+)
+{
+    OMX_INT     i, j;
+    OMX_S32     m[2][2];
+    OMX_S32     Value;
+    OMX_S32     QbitsPlusOne, Two_f, MF00;
+
+    /* Check for argument error */
+    armRetArgErrIf(pSrcDst == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(armNot8ByteAligned(pSrcDst), OMX_Sts_BadArgErr);
+    armRetArgErrIf(iQP > 51, OMX_Sts_BadArgErr);
+
+    /* Hadamard Transform for 2x2 block */
+    m[0][0] = pSrcDst[0] + pSrcDst[1] +  pSrcDst[2] + pSrcDst[3];
+    m[0][1] = pSrcDst[0] - pSrcDst[1] +  pSrcDst[2] - pSrcDst[3];
+    m[1][0] = pSrcDst[0] + pSrcDst[1] -  pSrcDst[2] - pSrcDst[3];
+    m[1][1] = pSrcDst[0] - pSrcDst[1] -  pSrcDst[2] + pSrcDst[3];
+
+    /* Quantization */
+    QbitsPlusOne = ARM_M4P10_Q_OFFSET + 1 + (iQP / 6); /*floor (QP/6)*/
+    MF00 = armVCM4P10_MFMatrix [iQP % 6][0];
+
+    Two_f = (1 << QbitsPlusOne) / (bIntra ? 3 : 6); /* 3->INTRA, 6->INTER */
+
+    /* Scaling */
+    for (j = 0; j < 2; j++)
+    {
+        for (i = 0; i < 2; i++)
+        {
+            Value = (armAbs(m[j][i]) * MF00 + Two_f) >> QbitsPlusOne;
+            pSrcDst[j * 2 + i] = (OMX_S16)((m[j][i] < 0) ? -Value : Value);
+        }
+    }
+
+    return OMX_Sts_NoErr;
+}
+
+/*****************************************************************************
+ *                              END OF FILE
+ *****************************************************************************/
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_TransformQuant_LumaDC.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_TransformQuant_LumaDC.c
new file mode 100644
index 0000000..2ccf7f0
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_TransformQuant_LumaDC.c
@@ -0,0 +1,119 @@
+/**
+ * 
+ * File Name:  omxVCM4P10_TransformQuant_LumaDC.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * Description:
+ * This function will calculate 4x4 hadamard transform of luma DC coefficients 
+ * and quantization
+ * 
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+
+/**
+ * Function:  omxVCM4P10_TransformQuant_LumaDC   (6.3.5.6.2)
+ *
+ * Description:
+ * This function performs a 4x4 Hadamard transform of luma DC coefficients 
+ * and then quantizes the coefficients. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - Pointer to the 4x4 array of luma DC coefficients.  16-byte 
+ *            alignment required. 
+ *   iQP - Quantization parameter; must be in the range [0,51]. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst - Pointer to transformed and quantized coefficients.  16-byte 
+ *             alignment required. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following 
+ *              conditions are true: 
+ *    -    at least one of the following pointers is NULL: pSrcDst 
+ *    -    pSrcDst is not aligned on an 16-byte boundary 
+ *
+ */
+OMXResult omxVCM4P10_TransformQuant_LumaDC(
+	OMX_S16* 	pSrcDst,
+	OMX_U32		iQP
+)
+{
+    OMX_INT     i, j;
+    OMX_S32     m1[4][4], m2[4][4];
+    OMX_S32     Value;
+    OMX_U32     QbitsPlusOne, Two_f, MF;
+
+    /* Check for argument error */
+    armRetArgErrIf(pSrcDst == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(armNot16ByteAligned(pSrcDst), OMX_Sts_BadArgErr);
+    armRetArgErrIf(iQP > 51, OMX_Sts_BadArgErr);
+
+    /* Hadamard Transform for 4x4 block */
+    /* Horizontal Hadamard */
+    for (i = 0; i < 4; i++)
+    {
+        j = i * 4;
+        
+        m1[i][0] = pSrcDst[j + 0] + pSrcDst[j + 2]; /* a+c */
+        m1[i][1] = pSrcDst[j + 1] + pSrcDst[j + 3]; /* b+d */
+        m1[i][2] = pSrcDst[j + 0] - pSrcDst[j + 2]; /* a-c */
+        m1[i][3] = pSrcDst[j + 1] - pSrcDst[j + 3]; /* b-d */
+
+        m2[i][0] = m1[i][0] + m1[i][1]; /* a+b+c+d */
+        m2[i][1] = m1[i][2] + m1[i][3]; /* a+b-c-d */
+        m2[i][2] = m1[i][2] - m1[i][3]; /* a-b-c+d */
+        m2[i][3] = m1[i][0] - m1[i][1]; /* a-b+c-d */
+
+    }
+
+    /* Vertical */
+    for (i = 0; i < 4; i++)
+    {
+        m1[0][i] = m2[0][i] + m2[2][i];
+        m1[1][i] = m2[1][i] + m2[3][i];
+        m1[2][i] = m2[0][i] - m2[2][i];
+        m1[3][i] = m2[1][i] - m2[3][i];
+
+        m2[0][i] = m1[0][i] + m1[1][i];
+        m2[1][i] = m1[2][i] + m1[3][i];
+        m2[2][i] = m1[2][i] - m1[3][i];
+        m2[3][i] = m1[0][i] - m1[1][i];
+    }
+
+    
+    /* Quantization */
+    QbitsPlusOne = ARM_M4P10_Q_OFFSET + 1 + (iQP / 6); /*floor (QP/6)*/
+    Two_f = (1 << QbitsPlusOne) / 3; /* 3->INTRA, 6->INTER */
+    MF = armVCM4P10_MFMatrix [iQP % 6][0];
+
+    /* Scaling */
+    for (j = 0; j < 4; j++)
+    {
+        for (i = 0; i < 4; i++)
+        {
+            Value = (armAbs((m2[j][i]/* + 1*/) / 2) * MF + Two_f) >> QbitsPlusOne;
+            pSrcDst[j * 4 + i] = (OMX_S16)((m2[j][i] < 0) ? -Value : Value);
+        }
+    }
+    return OMX_Sts_NoErr;
+}
+
+/*****************************************************************************
+ *                              END OF FILE
+ *****************************************************************************/
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/api/armVCM4P2_DCT_Table.h b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/api/armVCM4P2_DCT_Table.h
new file mode 100644
index 0000000..3255b61
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/api/armVCM4P2_DCT_Table.h
@@ -0,0 +1,30 @@
+/**
+ * 
+ * File Name:  armVCM4P2_DCT_Table.h
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ *
+ * File:        armVCM4P2_DCT_Table.h
+ * Description: Declares Tables used for DCT/IDCT module
+ *              in MP4P2 codec.
+ *
+ */
+ 
+#ifndef _OMXDCTTAB_H_
+#define _OMXDCTTAB_H_
+
+extern const OMX_F64 armVCM4P2_preCalcDCTCos[8][8];
+
+#endif /* _OMXDCTTAB_H_ */
+
+
+/* End of file */
+
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/api/armVCM4P2_Huff_Tables_VLC.h b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/api/armVCM4P2_Huff_Tables_VLC.h
new file mode 100644
index 0000000..92ecc05
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/api/armVCM4P2_Huff_Tables_VLC.h
@@ -0,0 +1,42 @@
+/**
+ * 
+ * File Name:  armVCM4P2_Huff_Tables_VLC.h
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ *
+ * File:        armVCM4P2_Huff_Tables.h
+ * Description: Declares Tables used for Hufffman coding and decoding 
+ *              in MP4P2 codec.
+ *
+ */
+ 
+#ifndef _OMXHUFFTAB_H_
+#define _OMXHUFFTAB_H_
+
+extern const OMX_U8 armVCM4P2_IntraL0RunIdx[11];
+extern const ARM_VLC32 armVCM4P2_IntraVlcL0[68];
+extern const OMX_U8 armVCM4P2_IntraL1RunIdx[7];
+extern const ARM_VLC32 armVCM4P2_IntraVlcL1[36];
+extern const OMX_U8 armVCM4P2_IntraL0LMAX[15];
+extern const OMX_U8 armVCM4P2_IntraL1LMAX[21];
+extern const OMX_U8 armVCM4P2_IntraL0RMAX[27];
+extern const OMX_U8 armVCM4P2_IntraL1RMAX[8];
+extern const OMX_U8 armVCM4P2_InterL0RunIdx[12];
+extern const ARM_VLC32 armVCM4P2_InterVlcL0[59];
+extern const OMX_U8 armVCM4P2_InterL1RunIdx[3];
+extern const ARM_VLC32 armVCM4P2_InterVlcL1[45];
+extern const OMX_U8 armVCM4P2_InterL0LMAX[27];
+extern const OMX_U8 armVCM4P2_InterL1LMAX[41];
+extern const OMX_U8 armVCM4P2_InterL0RMAX[12];
+extern const OMX_U8 armVCM4P2_InterL1RMAX[3];
+extern const ARM_VLC32 armVCM4P2_aIntraDCLumaIndex[14];
+extern const ARM_VLC32 armVCM4P2_aIntraDCChromaIndex[14];
+extern const ARM_VLC32 armVCM4P2_aVlcMVD[66];
+
+#endif /* _OMXHUFFTAB_H_ */
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/api/armVCM4P2_ZigZag_Tables.h b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/api/armVCM4P2_ZigZag_Tables.h
new file mode 100644
index 0000000..c75ed89
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/api/armVCM4P2_ZigZag_Tables.h
@@ -0,0 +1,25 @@
+/**
+ * 
+ * File Name:  armVCM4P2_ZigZag_Tables.h
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ *
+ * File:        armVCM4P2_Zigzag_Tables.h
+ * Description: Declares Tables used for Zigzag scan in MP4P2 codec.
+ *
+ */
+ 
+#ifndef _OMXZIGZAGTAB_H_
+#define _OMXZIGZAGTAB_H_
+
+extern const OMX_U8 armVCM4P2_aClassicalZigzagScan [64];
+extern const OMX_U8 armVCM4P2_aHorizontalZigzagScan [64];
+extern const OMX_U8 armVCM4P2_aVerticalZigzagScan [64];
+
+#endif /* _OMXZIGZAGTAB_H_ */
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_ACDCPredict.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_ACDCPredict.c
new file mode 100644
index 0000000..b6a396a
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_ACDCPredict.c
@@ -0,0 +1,253 @@
+/**
+ * 
+ * File Name:  armVCM4P2_ACDCPredict.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * 
+ * Description:
+ * Contains module for DC/AC coefficient prediction
+ *
+ */ 
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+
+#include "armVC.h"
+#include "armCOMM.h"
+
+/**
+ * Function: armVCM4P2_ACDCPredict
+ *
+ * Description:
+ * Performs adaptive DC/AC coefficient prediction for an intra block. Prior
+ * to the function call, prediction direction (predDir) should be selected
+ * as specified in subclause 7.4.3.1 of ISO/IEC 14496-2.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] pSrcDst     pointer to the coefficient buffer which contains
+ *                          the quantized coefficient residuals (PQF) of the
+ *                          current block
+ * [in] pPredBufRow pointer to the coefficient row buffer
+ * [in] pPredBufCol pointer to the coefficient column buffer
+ * [in] curQP       quantization parameter of the current block. curQP
+ *                          may equal to predQP especially when the current
+ *                          block and the predictor block are in the same
+ *                          macroblock.
+ * [in] predQP      quantization parameter of the predictor block
+ * [in] predDir     indicates the prediction direction which takes one
+ *                          of the following values:
+ *                          OMX_VC_HORIZONTAL    predict horizontally
+ *                          OMX_VC_VERTICAL      predict vertically
+ * [in] ACPredFlag  a flag indicating if AC prediction should be
+ *                          performed. It is equal to ac_pred_flag in the bit
+ *                          stream syntax of MPEG-4
+ * [in] videoComp   video component type (luminance, chrominance or
+ *                          alpha) of the current block
+ * [in] flag        This flag defines the if one wants to use this functions to
+ *                  calculate PQF (set 1, prediction) or QF (set 0, reconstruction)
+ * [out]    pPreACPredict   pointer to the predicted coefficients buffer.
+ *                          Filled ONLY if it is not NULL
+ * [out]    pSrcDst     pointer to the coefficient buffer which contains
+ *                          the quantized coefficients (QF) of the current
+ *                          block
+ * [out]    pPredBufRow pointer to the updated coefficient row buffer
+ * [out]    pPredBufCol pointer to the updated coefficient column buffer
+ * [out]    pSumErr     pointer to the updated sum of the difference
+ *                      between predicted and unpredicted coefficients
+ *                      If this is NULL, do not update
+ *
+ * Return Value:
+ * Standard OMXResult result. See enumeration for possible result codes.
+ *
+ */
+
+OMXResult armVCM4P2_ACDCPredict(
+     OMX_S16 * pSrcDst,
+     OMX_S16 * pPreACPredict,
+     OMX_S16 * pPredBufRow,
+     OMX_S16 * pPredBufCol,
+     OMX_INT curQP,
+     OMX_INT predQP,
+     OMX_INT predDir,
+     OMX_INT ACPredFlag,
+     OMXVCM4P2VideoComponent videoComp,
+     OMX_U8 flag,
+     OMX_INT *pSumErr
+)
+{
+    OMX_INT dcScaler, i;
+    OMX_S16 tempPred;
+
+    /* Argument error checks */
+    armRetArgErrIf(pSrcDst == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pPredBufRow == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pPredBufCol == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(curQP <= 0, OMX_Sts_BadArgErr);
+    armRetArgErrIf(predQP <= 0, OMX_Sts_BadArgErr);
+    armRetArgErrIf((predDir != 1) && (predDir != 2), OMX_Sts_BadArgErr);
+    armRetArgErrIf(!armIs4ByteAligned(pSrcDst), OMX_Sts_BadArgErr);
+    armRetArgErrIf(!armIs4ByteAligned(pPredBufRow), OMX_Sts_BadArgErr);
+    armRetArgErrIf(!armIs4ByteAligned(pPredBufCol), OMX_Sts_BadArgErr);
+
+    
+    /* Set DC scaler value to avoid some compilers giving a warning. */
+    dcScaler=0;
+    
+    /* Calculate the DC scaler value */
+    if (videoComp == OMX_VC_LUMINANCE)
+    {
+        if (curQP >= 1 && curQP <= 4)
+        {
+            dcScaler = 8;
+        }
+        else if (curQP >= 5 && curQP <= 8)
+        {
+            dcScaler = 2 * curQP;
+        }
+        else if (curQP >= 9 && curQP <= 24)
+        {
+            dcScaler = curQP + 8;
+        }
+        else
+        {
+            dcScaler = (2 * curQP) - 16;
+        }
+    }
+    else if (videoComp == OMX_VC_CHROMINANCE)
+    {
+        if (curQP >= 1 && curQP <= 4)
+        {
+            dcScaler = 8;
+        }
+        else if (curQP >= 5 && curQP <= 24)
+        {
+            dcScaler = (curQP + 13)/2;
+        }
+        else
+        {
+            dcScaler = curQP - 6;
+        }
+    }
+
+    if (pPreACPredict != NULL)
+    {
+        pPreACPredict[0] = predDir;
+    }
+
+    if (predDir == OMX_VC_VERTICAL)
+    {
+        /* F[0][0]//dc_scaler */
+        tempPred = armIntDivAwayFromZero(pPredBufRow[0], dcScaler);
+    }
+    else
+    {
+        /* F[0][0]//dc_scaler */
+        tempPred = armIntDivAwayFromZero(pPredBufCol[0], dcScaler);
+    }
+
+    /* Updating the DC value to the row and col buffer */
+    *(pPredBufRow - 8) = *pPredBufCol;
+
+    if (flag)
+    {
+        /* Cal and store F[0][0] into the col buffer */
+        *pPredBufCol = pSrcDst[0] * dcScaler;
+
+        /* PQF = QF - F[0][0]//dc_scaler */
+        pSrcDst[0] -= tempPred;
+    }
+    else
+    {
+        /* QF = PQF + F[0][0]//dc_scaler */
+        pSrcDst[0] += tempPred;
+        
+        /* Saturate */
+        pSrcDst[0] = armClip (-2048, 2047, pSrcDst[0]);
+
+        /* Cal and store F[0][0] into the col buffer */
+        *pPredBufCol = pSrcDst[0] * dcScaler;
+    }
+
+
+    if (ACPredFlag == 1)
+    {
+        if (predDir == OMX_VC_VERTICAL)
+        {
+            for (i = 1; i < 8; i++)
+            {
+                tempPred = armIntDivAwayFromZero \
+                              (pPredBufRow[i] * predQP, curQP);
+                if (flag)
+                {
+                    /* Updating QF to the row buff */
+                    pPredBufRow[i] = pSrcDst[i];
+                    /*PQFX[v][0] = QFX[v][0] - (QFA[v][0] * QPA) // QPX */
+                    pSrcDst[i] -= tempPred;
+                    /* Sum of absolute values of AC prediction error, this can
+                    be used as a reference to choose whether to use
+                    AC prediction */
+                    *pSumErr += armAbs(pSrcDst[i]);
+                    /* pPreACPredict[1~7] store the error signal
+                    after AC prediction */
+                    pPreACPredict[i] = pSrcDst[i];
+                }
+                else
+                {
+                    /*QFX[v][0] = PQFX[v][0] + (QFA[v][0] * QPA) // QPX */
+                    pSrcDst[i] += tempPred;
+                    
+                    /* Saturate */
+                    pSrcDst[i] = armClip (-2048, 2047, pSrcDst[i]);
+                    
+                    /* Updating QF to the row buff */
+                    pPredBufRow[i] = pSrcDst[i];
+                }
+            }
+        }
+        else
+        {
+            for (i = 8; i < 64; i += 8)
+            {
+                tempPred = armIntDivAwayFromZero \
+                              (pPredBufCol[i>>3] * predQP, curQP);
+                if (flag)
+                {
+                    /* Updating QF to col buff */
+                    pPredBufCol[i>>3] = pSrcDst[i];
+                    /*PQFX[0][u] = QFX[0][u] - (QFA[0][u] * QPA) // QPX */
+                    pSrcDst[i] -= tempPred;
+                    /* Sum of absolute values of AC prediction error, this can
+                    be used as a reference to choose whether to use AC
+                    prediction */
+                    *pSumErr += armAbs(pSrcDst[i]);
+                    /* pPreACPredict[1~7] store the error signal
+                    after AC prediction */
+                    pPreACPredict[i>>3] = pSrcDst[i];
+                }
+                else
+                {
+                    /*QFX[0][u] = PQFX[0][u] + (QFA[0][u] * QPA) // QPX */
+                    pSrcDst[i] += tempPred;
+                    
+                    /* Saturate */
+                    pSrcDst[i] = armClip (-2048, 2047, pSrcDst[i]);
+                    
+                    /* Updating QF to col buff */
+                    pPredBufCol[i>>3] = pSrcDst[i];
+                }
+            }
+        }
+    }
+
+    return OMX_Sts_NoErr;
+}
+
+/*End of File*/
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_BlockMatch_Half.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_BlockMatch_Half.c
new file mode 100644
index 0000000..1b69a33
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_BlockMatch_Half.c
@@ -0,0 +1,187 @@
+/**
+ * 
+ * File Name:  armVCM4P2_BlockMatch_Half.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * 
+ * Description:
+ * Contains modules for Block matching, a full search algorithm
+ * is implemented
+ *
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armVC.h"
+#include "armCOMM.h"
+
+/**
+ * Function: armVCM4P2_BlockMatch_Half
+ *
+ * Description:
+ * Performs a 16x16 block match with half-pixel resolution.  Returns the estimated 
+ * motion vector and associated minimum SAD.  This function estimates the half-pixel 
+ * motion vector by interpolating the integer resolution motion vector referenced 
+ * by the input parameter pSrcDstMV, i.e., the initial integer MV is generated 
+ * externally.  The input parameters pSrcRefBuf and pSearchPointRefPos should be 
+ * shifted by the winning MV of 16x16 integer search prior to calling BlockMatch_Half_16x16.  
+ * The function BlockMatch_Integer_16x16 may be used for integer motion estimation.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	pSrcRefBuf		pointer to the reference Y plane; points to the reference MB 
+ *                    that corresponds to the location of the current macroblock in 
+ *                    the	current plane.
+ * [in]	refWidth		  width of the reference plane
+ * [in]	pRefRect		  reference plane valid region rectangle
+ * [in]	pSrcCurrBuf		pointer to the current macroblock extracted from original plane 
+ *                    (linear array, 256 entries); must be aligned on an 8-byte boundary. 
+ * [in]	pSearchPointRefPos	position of the starting point for half pixel search (specified 
+ *                          in terms of integer pixel units) in the reference plane.
+ * [in]	rndVal			  rounding control bit for half pixel motion estimation; 
+ *                    0=rounding control disabled; 1=rounding control enabled
+ * [in]	pSrcDstMV		pointer to the initial MV estimate; typically generated during a prior 
+ *                  16X16 integer search and its unit is half pixel.
+ * [in] BlockSize     MacroBlock Size i.e either 16x16 or 8x8.
+ * [out]pSrcDstMV		pointer to estimated MV
+ * [out]pDstSAD			pointer to minimum SAD
+ *
+ * Return Value:
+ * OMX_Sts_NoErr ¨C no error
+ * OMX_Sts_BadArgErr ¨C bad arguments
+ *
+ */
+
+OMXResult armVCM4P2_BlockMatch_Half(
+     const OMX_U8 *pSrcRefBuf,
+     OMX_INT refWidth,
+     const OMXRect *pRefRect,
+     const OMX_U8 *pSrcCurrBuf,
+     const OMXVCM4P2Coordinate *pSearchPointRefPos,
+     OMX_INT rndVal,
+     OMXVCMotionVector *pSrcDstMV,
+     OMX_INT *pDstSAD,
+     OMX_U8 BlockSize
+)
+{
+    OMX_INT     outer, inner, count, index;
+    OMX_S16     halfPelX = 0, halfPelY = 0, x, y;
+    OMX_INT     candSAD, refSAD = 0;
+    OMX_INT     minSAD, fromX, toX, fromY, toY;
+    /* Offset to the reference at the begining of the bounding box */
+    const OMX_U8      *pTempSrcRefBuf;
+    OMX_U8 tempPel;
+        
+    /* Argument error checks */
+    armRetArgErrIf(pSrcRefBuf == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pRefRect == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pSrcCurrBuf == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pSearchPointRefPos == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pSrcDstMV == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pDstSAD == NULL, OMX_Sts_BadArgErr);
+
+    /* Positioning the pointer */
+    pTempSrcRefBuf = pSrcRefBuf + (refWidth * (pSrcDstMV->dy/2)) + (pSrcDstMV->dx/2);
+
+    /* Copy the candidate to the temporary linear array */
+    for (outer = 0, count = 0,index = 0;
+         outer < BlockSize;
+         outer++, index += refWidth - BlockSize)
+    {
+        for (inner = 0; inner < BlockSize; inner++, count++, index++)
+        {
+            refSAD += armAbs (pTempSrcRefBuf[index] - pSrcCurrBuf[count]);
+        }
+    }
+
+    /* Set the minSad as reference SAD */
+    minSAD = refSAD;
+    *pDstSAD = refSAD;
+
+    /* Check for valid region */
+    fromX = 1;
+    toX   = 1;
+    fromY = 1;
+    toY   = 1;
+    if ((pSearchPointRefPos->x - 1) < pRefRect->x)
+    {
+        fromX = 0;
+    }
+
+    if ((pSearchPointRefPos->x + BlockSize + 1) > (pRefRect->x + pRefRect->width))
+    {
+        toX   = 0;
+    }
+
+    if ((pSearchPointRefPos->y - 1) < pRefRect->y)
+    {
+        fromY = 0;
+    }
+
+    if ((pSearchPointRefPos->y + BlockSize + 1) > (pRefRect->y + pRefRect->height))
+    {
+        toY   = 0;
+    }
+
+    /* Looping on y- axis */
+    for (y = -fromY; y <= toY; y++)
+    {
+        /* Looping on x- axis */
+        for (x = -fromX; x <= toX; x++)
+        {
+            /* check for integer position */
+            if ( x == 0 && y == 0)
+            {
+                continue;
+            }
+            /* Positioning the pointer */
+            pTempSrcRefBuf = pSrcRefBuf + (refWidth * (pSrcDstMV->dy/2))
+                             + (pSrcDstMV->dx/2);
+
+            /* Interpolate the pixel and calculate the SAD*/
+            for (outer = 0, count = 0, candSAD = 0,index = 0;
+                 outer < BlockSize;
+                 outer++, index += refWidth - BlockSize)
+            {
+                for (inner = 0; inner < BlockSize; inner++, count++,index++)
+                {
+                    tempPel = (
+                                pTempSrcRefBuf[index]
+                                + pTempSrcRefBuf[index + x] * armAbs(x)
+                                + pTempSrcRefBuf[index + refWidth * y] * armAbs(y)
+                                + pTempSrcRefBuf[index + refWidth * y + x]
+                                  * armAbs(x*y)
+                                + armAbs (x) + armAbs (y) - rndVal
+                              ) / (2 * (armAbs (x) + armAbs (y)));
+                    candSAD += armAbs (tempPel - pSrcCurrBuf[count]);
+                }
+            }
+
+            /* Result calculations */
+            if (armVCM4P2_CompareMV (x, y, candSAD, halfPelX, halfPelY, minSAD))
+            {
+                *pDstSAD = candSAD;
+                minSAD   = candSAD;
+                halfPelX = x;
+                halfPelY = y;
+            }
+
+        } /* End of x- axis */
+    } /* End of y-axis */
+
+    pSrcDstMV->dx += halfPelX;
+    pSrcDstMV->dy += halfPelY;
+
+    return OMX_Sts_NoErr;
+
+}
+
+/* End of file */
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_BlockMatch_Integer.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_BlockMatch_Integer.c
new file mode 100644
index 0000000..77fe358
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_BlockMatch_Integer.c
@@ -0,0 +1,167 @@
+/**
+ * 
+ * File Name:  armVCM4P2_BlockMatch_Integer.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Description:
+ * Contains modules for Block matching, a full search algorithm
+ * is implemented
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armVC.h"
+#include "armCOMM.h"
+
+/**
+ * Function: armVCM4P2_BlockMatch_Integer
+ *
+ * Description:
+ * Performs a 16x16 block search; estimates motion vector and associated minimum SAD.  
+ * Both the input and output motion vectors are represented using half-pixel units, and 
+ * therefore a shift left or right by 1 bit may be required, respectively, to match the 
+ * input or output MVs with other functions that either generate output MVs or expect 
+ * input MVs represented using integer pixel units. 
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	pSrcRefBuf		pointer to the reference Y plane; points to the reference MB that 
+ *                    corresponds to the location of the current macroblock in the current 
+ *                    plane.
+ * [in]	refWidth		  width of the reference plane
+ * [in]	pRefRect		  pointer to the valid rectangular in reference plane. Relative to image origin. 
+ *                    It's not limited to the image boundary, but depended on the padding. For example, 
+ *                    if you pad 4 pixels outside the image border, then the value for left border 
+ *                    can be -4
+ * [in]	pSrcCurrBuf		pointer to the current macroblock extracted from original plane (linear array, 
+ *                    256 entries); must be aligned on an 8-byte boundary.
+ * [in] pCurrPointPos	position of the current macroblock in the current plane
+ * [in] pSrcPreMV		  pointer to predicted motion vector; NULL indicates no predicted MV
+ * [in] pSrcPreSAD		pointer to SAD associated with the predicted MV (referenced by pSrcPreMV)
+ * [in] searchRange		search range for 16X16 integer block,the units of it is full pixel,the search range 
+ *                    is the same in all directions.It is in inclusive of the boundary and specified in 
+ *                    terms of integer pixel units.
+ * [in] pMESpec			  vendor-specific motion estimation specification structure; must have been allocated 
+ *                    and then initialized using omxVCM4P2_MEInit prior to calling the block matching 
+ *                    function.
+ * [out]	pDstMV			pointer to estimated MV
+ * [out]	pDstSAD			pointer to minimum SAD
+ *
+ * Return Value:
+ * OMX_Sts_NoErr ¨C no error.
+ * OMX_Sts_BadArgErr ¨C bad arguments
+ *
+ */
+
+OMXResult armVCM4P2_BlockMatch_Integer(
+     const OMX_U8 *pSrcRefBuf,
+     OMX_INT refWidth,
+     const OMXRect *pRefRect,
+     const OMX_U8 *pSrcCurrBuf,
+     const OMXVCM4P2Coordinate *pCurrPointPos,
+     const OMXVCMotionVector *pSrcPreMV,
+     const OMX_INT *pSrcPreSAD,
+     void *pMESpec,
+     OMXVCMotionVector *pDstMV,
+     OMX_INT *pDstSAD,
+     OMX_U8 BlockSize
+)
+{
+
+    /* Definitions and Initializations*/
+
+    OMX_INT     outer, inner, count,index;
+    OMX_INT     candSAD;
+    /*(256*256 +1) this is to make the SAD max initially*/
+    OMX_INT     minSAD = 0x10001, fromX, toX, fromY, toY;
+    /* Offset to the reference at the begining of the bounding box */
+    const OMX_U8      *pTempSrcRefBuf;
+    OMX_S16     x, y;
+    OMX_INT searchRange;
+   
+    /* Argument error checks */
+    armRetArgErrIf(pSrcRefBuf == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pRefRect == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pSrcCurrBuf == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pCurrPointPos == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pMESpec == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pDstMV == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pDstSAD == NULL, OMX_Sts_BadArgErr);
+        
+    searchRange = ((OMXVCM4P2MEParams *)pMESpec)->searchRange;
+    /* Check for valid region */
+    fromX = searchRange;
+    toX   = searchRange;
+    fromY = searchRange;
+    toY   = searchRange;
+
+    if ((pCurrPointPos->x - searchRange) < pRefRect->x)
+    {
+        fromX =  pCurrPointPos->x - pRefRect->x;
+    }
+
+    if ((pCurrPointPos->x + BlockSize + searchRange) > (pRefRect->x + pRefRect->width))
+    {
+        toX   = pRefRect->width - (pCurrPointPos->x - pRefRect->x) - BlockSize;
+    }
+
+    if ((pCurrPointPos->y - searchRange) < pRefRect->y)
+    {
+        fromY = pCurrPointPos->y - pRefRect->y;
+    }
+
+    if ((pCurrPointPos->y + BlockSize + searchRange) > (pRefRect->y + pRefRect->height))
+    {
+        toY   = pRefRect->width - (pCurrPointPos->y - pRefRect->y) - BlockSize;
+    }
+
+    pDstMV->dx = -fromX;
+    pDstMV->dy = -fromY;
+    /* Looping on y- axis */
+    for (y = -fromY; y <= toY; y++)
+    {
+
+        /* Looping on x- axis */
+        for (x = -fromX; x <= toX; x++)
+        {
+            /* Positioning the pointer */
+            pTempSrcRefBuf = pSrcRefBuf + (refWidth * y) + x;
+
+            /* Calculate the SAD */
+            for (outer = 0, count = 0, index = 0, candSAD = 0;
+                 outer < BlockSize;
+                 outer++, index += refWidth - BlockSize)
+            {
+                for (inner = 0; inner < BlockSize; inner++, count++, index++)
+                {
+                    candSAD += armAbs (pTempSrcRefBuf[index] - pSrcCurrBuf[count]);                    
+                }
+            }
+
+            /* Result calculations */
+            if (armVCM4P2_CompareMV (x, y, candSAD, pDstMV->dx/2, pDstMV->dy/2, minSAD))
+            {
+                *pDstSAD = candSAD;
+                minSAD   = candSAD;
+                pDstMV->dx = x*2;
+                pDstMV->dy = y*2;
+            }
+
+        } /* End of x- axis */
+    } /* End of y-axis */
+
+    return OMX_Sts_NoErr;
+
+}
+
+/* End of file */
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_CheckVLCEscapeMode.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_CheckVLCEscapeMode.c
new file mode 100644
index 0000000..94e8639
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_CheckVLCEscapeMode.c
@@ -0,0 +1,156 @@
+/**
+ * 
+ * File Name:  armVCM4P2_CheckVLCEscapeMode.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * 
+ * Description:
+ * Contains module for VLC escape mode check 
+ *
+ */ 
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+
+#include "armVC.h"
+#include "armCOMM.h"
+
+/**
+ * Function: armVCM4P2_CheckVLCEscapeMode
+ *
+ * Description:
+ * Performs escape mode decision based on the run, run+, level, level+ and 
+ * last combinations.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] run             Run value (count of zeros) to be encoded  
+ * [in] level           Level value (non-zero value) to be encoded
+ * [in] runPlus         Calculated as runPlus = run - (RMAX + 1)  
+ * [in] levelPlus       Calculated as 
+ *                      levelPlus = sign(level)*[abs(level) - LMAX]
+ * [in] maxStoreRun     Max store possible (considering last and inter/intra)
+ * [in] maxRunForMultipleEntries 
+ *                      The run value after which level 
+ *                      will be equal to 1: 
+ *                      (considering last and inter/intra status)
+ * [in] pRunIndexTable  Run Index table defined in 
+ *                      armVCM4P2_Huff_Tables_VLC.c
+ *                      (considering last and inter/intra status)
+ *
+ *                      
+ * Return Value:
+ * Returns an Escape mode which can take values from 0 to 3
+ * 0 --> no escape mode, 1 --> escape type 1,
+ * 1 --> escape type 2, 3 --> escape type 3, check section 7.4.1.3
+ * in the MPEG ISO standard.
+ *
+ */
+
+OMX_U8 armVCM4P2_CheckVLCEscapeMode(
+     OMX_U32 run,
+     OMX_U32 runPlus,
+     OMX_S16 level,
+     OMX_S16 levelPlus,
+     OMX_U8  maxStoreRun,
+     OMX_U8  maxRunForMultipleEntries,
+     OMX_INT shortVideoHeader,
+     const OMX_U8  *pRunIndexTable
+)
+{
+    OMX_U8 escape = 0, fMode = 0, entries;
+    
+    level = armAbs (level);
+    levelPlus = armAbs (levelPlus);
+    
+    /* Check for a valid entry with run, level and Last combination 
+       Mode 0 check */
+    if (run <= maxStoreRun)
+    {
+        entries = pRunIndexTable[run + 1]
+                  - pRunIndexTable[run];
+        if (run > maxRunForMultipleEntries)
+        {
+            entries = 1;
+        }
+        if (level > entries)
+        {
+            escape = 1;
+        }
+    }
+    else
+    {
+        escape = 1;
+    }
+    if(escape && shortVideoHeader)
+    {
+        escape = 0;
+        fMode = 4;
+    }
+    /* Check for a valid entry with run, levelPlus and Last combination 
+       Mode 1 check */    
+    if (escape)
+    {
+        escape = 0;
+        fMode = 1;
+        if (run <= maxStoreRun)
+        {
+            entries = pRunIndexTable[run + 1]
+                      - pRunIndexTable[run];
+            if (run > maxRunForMultipleEntries)
+            {
+                entries = 1;
+            }
+            if (levelPlus > entries)
+            {
+                escape = 1;
+            }
+        }
+        else
+        {
+            escape = 1;
+        }
+    }
+    
+    /* Check for a valid entry with runPlus, level and Last combination 
+       Mode 2 check */    
+    if (escape)
+    {
+        escape = 0;
+        fMode = 2;
+        if (runPlus <= maxStoreRun)
+        {
+            entries = pRunIndexTable[runPlus + 1]
+                      - pRunIndexTable[runPlus];
+            if (runPlus > maxRunForMultipleEntries)
+            {
+                entries = 1;
+            }
+            if (level > entries)
+            {
+                escape = 1;
+            }
+        }
+        else
+        {
+            escape = 1;
+        }
+    }
+    
+    /* select mode 3 --> FLC */
+    if (escape)
+    {
+        fMode = 3;
+    }
+    
+    return fMode;
+}
+
+/*End of File*/
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_CompareMV.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_CompareMV.c
new file mode 100644
index 0000000..3b8845e
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_CompareMV.c
@@ -0,0 +1,71 @@
+/**
+ * 
+ * File Name:  armVCM4P2_CompareMV.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * 
+ * Description:
+ * Contains module for comparing motion vectors and SAD's to decide 
+ * the best MV and SAD
+ *
+ */
+  
+#include "omxtypes.h"
+#include "armOMX.h"
+
+#include "armVC.h"
+#include "armCOMM.h"
+
+/**
+ * Function: armVCM4P2_CompareMV
+ *
+ * Description:
+ * Performs comparision of motion vectors and SAD's to decide the 
+ * best MV and SAD
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	    mvX		x coordinate of the candidate motion vector
+ * [in]	    mvY		y coordinate of the candidate motion vector
+ * [in]	    candSAD	Candidate SAD
+ * [in]	    bestMVX	x coordinate of the best motion vector
+ * [in]	    bestMVY	y coordinate of the best motion vector
+ * [in]	    bestSAD	best SAD
+ *
+ * Return Value:
+ * OMX_INT -- 1 to indicate that the current sad is the best 
+ *            0 to indicate that it is NOT the best SAD
+ */
+
+OMX_INT armVCM4P2_CompareMV (
+    OMX_S16 mvX, 
+    OMX_S16 mvY, 
+    OMX_INT candSAD, 
+    OMX_S16 bestMVX, 
+    OMX_S16 bestMVY, 
+    OMX_INT bestSAD
+) 
+{
+    if (candSAD < bestSAD)
+    {
+        return 1;
+    }
+    if (candSAD > bestSAD)
+    {
+        return 0;
+    }
+    /* shorter motion vector */
+    if ( (mvX * mvX + mvY * mvY) < (bestMVX*bestMVX+bestMVY*bestMVY) )
+    {
+         return 1;
+    }
+    return 0;
+}
+
+/*End of File*/
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_DCT_Table.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_DCT_Table.c
new file mode 100644
index 0000000..a6f713e
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_DCT_Table.c
@@ -0,0 +1,112 @@
+ /**
+ * 
+ * File Name:  armVCM4P2_DCT_Table.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * File:        armVCM4P2_DCT_Table.c
+ * Description: Contains the DCT/IDCT coefficent matrix
+ *
+ */
+
+#ifndef _OMXDCTCOSTAB_C_
+#define _OMXDCTCOSTAB_C_
+
+#include "omxtypes.h"
+#include "armOMX.h"
+
+const OMX_F64 armVCM4P2_preCalcDCTCos[8][8] =
+{
+        {
+                0.353553390593273730, 
+                0.490392640201615220, 
+                0.461939766255643370, 
+                0.415734806151272620, 
+                0.353553390593273790, 
+                0.277785116509801140, 
+                0.191341716182544920, 
+                0.097545161008064152 
+        },
+        {
+                0.353553390593273730, 
+                0.415734806151272620, 
+                0.191341716182544920, 
+                -0.097545161008064096, 
+                -0.353553390593273730, 
+                -0.490392640201615220, 
+                -0.461939766255643420, 
+                -0.277785116509801090
+        },
+        {
+                0.353553390593273730, 
+                0.277785116509801140, 
+                -0.191341716182544860, 
+                -0.490392640201615220, 
+                -0.353553390593273840, 
+                0.097545161008064138, 
+                0.461939766255643260, 
+                0.415734806151272730 
+        },
+        {
+                0.353553390593273730, 
+                0.097545161008064152, 
+                -0.461939766255643370, 
+                -0.277785116509801090, 
+                0.353553390593273680, 
+                0.415734806151272730, 
+                -0.191341716182544920, 
+                -0.490392640201615330
+        },
+        {
+                0.353553390593273730, 
+                -0.097545161008064096, 
+                -0.461939766255643420, 
+                0.277785116509800920, 
+                0.353553390593273840, 
+                -0.415734806151272620, 
+                -0.191341716182545280, 
+                0.490392640201615220 
+        },
+        {
+                0.353553390593273730, 
+                -0.277785116509800980, 
+                -0.191341716182545170, 
+                0.490392640201615220, 
+                -0.353553390593273340, 
+                -0.097545161008064013, 
+                0.461939766255643370, 
+                -0.415734806151272510
+        },
+        {
+                0.353553390593273730, 
+                -0.415734806151272670, 
+                0.191341716182545000, 
+                0.097545161008064388, 
+                -0.353553390593273620, 
+                0.490392640201615330, 
+                -0.461939766255643200, 
+                0.277785116509800760 
+        },
+        {
+                0.353553390593273730, 
+                -0.490392640201615220, 
+                0.461939766255643260, 
+                -0.415734806151272620, 
+                0.353553390593273290, 
+                -0.277785116509800760, 
+                0.191341716182544780, 
+                -0.097545161008064277
+        }
+};
+
+#endif /*_OMXDCTCOSTAB_C_*/
+
+
+/* End of file */
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_DecodeVLCZigzag_intra.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_DecodeVLCZigzag_intra.c
new file mode 100644
index 0000000..a2572e0
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_DecodeVLCZigzag_intra.c
@@ -0,0 +1,144 @@
+/**
+ * 
+ * File Name:  armVCM4P2_DecodeVLCZigzag_intra.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * 
+ * Description:
+ * Contains modules for filling of the coefficient buffer
+ *
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armVC.h"
+#include "armCOMM_Bitstream.h"
+#include "armCOMM.h"
+#include "armVCM4P2_Huff_Tables_VLC.h"
+#include "armVCM4P2_ZigZag_Tables.h"
+
+
+
+/**
+ * Function: armVCM4P2_DecodeVLCZigzag_Intra
+ *
+ * Description:
+ * Performs VLC decoding and inverse zigzag scan for one intra coded block.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] ppBitStream     pointer to the pointer to the current byte in
+ *                              the bitstream buffer
+ * [in] pBitOffset      pointer to the bit position in the byte pointed
+ *                              to by *ppBitStream. *pBitOffset is valid within
+ *                              [0-7].
+ * [in] predDir         AC prediction direction which is used to decide
+ *                              the zigzag scan pattern. It takes one of the
+ *                              following values:
+ *                              OMX_VC_NONE  AC prediction not used;
+ *                                              perform classical zigzag scan;
+ *                              OMX_VC_HORIZONTAL    Horizontal prediction;
+ *                                                      perform alternate-vertical
+ *                                                      zigzag scan;
+ *                              OMX_VC_VERTICAL      Vertical prediction;
+ *                                                      thus perform
+ *                                                      alternate-horizontal
+ *                                                      zigzag scan.
+ * [in] start           start indicates whether the encoding begins with 0th element
+ *                      or 1st.
+ * [out]    ppBitStream     *ppBitStream is updated after the block is
+ *                              decoded, so that it points to the current byte
+ *                              in the bit stream buffer
+ * [out]    pBitOffset      *pBitOffset is updated so that it points to the
+ *                              current bit position in the byte pointed by
+ *                              *ppBitStream
+ * [out]    pDst            pointer to the coefficient buffer of current
+ *                              block. Should be 32-bit aligned
+ *
+ * Return Value:
+ * Standard OMXResult result. See enumeration for possible result codes.
+ *
+ */
+
+OMXResult armVCM4P2_DecodeVLCZigzag_Intra(
+     const OMX_U8 ** ppBitStream,
+     OMX_INT * pBitOffset,
+     OMX_S16 * pDst,
+     OMX_U8 predDir,
+     OMX_INT shortVideoHeader,
+     OMX_U8  start
+)
+{
+    OMX_U8  last = 0;
+    const OMX_U8  *pZigzagTable = armVCM4P2_aClassicalZigzagScan;
+    OMXResult errorCode;
+    
+    /* Argument error checks */
+    armRetArgErrIf(ppBitStream == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(*ppBitStream == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pBitOffset == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pDst == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(!armIs4ByteAligned(pDst), OMX_Sts_BadArgErr);
+    armRetArgErrIf((*pBitOffset < 0) || (*pBitOffset >7), OMX_Sts_BadArgErr);
+    armRetArgErrIf((predDir > 2), OMX_Sts_BadArgErr);
+
+    switch (predDir)
+    {
+        case OMX_VC_NONE:
+        {
+            pZigzagTable = armVCM4P2_aClassicalZigzagScan;
+            break;
+        }
+
+        case OMX_VC_HORIZONTAL:
+        {
+            pZigzagTable = armVCM4P2_aVerticalZigzagScan;
+            break;
+        }
+
+        case OMX_VC_VERTICAL:
+        {
+            pZigzagTable = armVCM4P2_aHorizontalZigzagScan;
+            break;
+        }
+    }
+    
+    errorCode = armVCM4P2_GetVLCBits (
+              ppBitStream,
+              pBitOffset,
+			  pDst,
+			  shortVideoHeader,
+			  start,
+			  &last,
+			  10,
+			  62,
+			   7,
+			  21,
+              armVCM4P2_IntraL0RunIdx,
+              armVCM4P2_IntraVlcL0,
+			  armVCM4P2_IntraL1RunIdx,
+              armVCM4P2_IntraVlcL1,
+              armVCM4P2_IntraL0LMAX,
+              armVCM4P2_IntraL1LMAX,
+              armVCM4P2_IntraL0RMAX,
+              armVCM4P2_IntraL1RMAX,
+              pZigzagTable );
+    armRetDataErrIf((errorCode != OMX_Sts_NoErr), errorCode);
+    
+    if (last == 0)
+    {
+        return OMX_Sts_Err;
+    }
+    return OMX_Sts_NoErr;
+}
+
+/* End of file */
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_EncodeVLCZigzag_intra.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_EncodeVLCZigzag_intra.c
new file mode 100644
index 0000000..cd6b56d
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_EncodeVLCZigzag_intra.c
@@ -0,0 +1,145 @@
+/**
+ * 
+ * File Name:  armVCM4P2_EncodeVLCZigzag_intra.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * 
+ * Description:
+ * Contains modules for zigzag scanning and VLC encoding
+ * for intra block.
+ *
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armVC.h"
+#include "armCOMM_Bitstream.h"
+#include "armCOMM.h"
+#include "armVCM4P2_Huff_Tables_VLC.h"
+#include "armVCM4P2_ZigZag_Tables.h"
+
+
+
+/**
+ * Function: armVCM4P2_EncodeVLCZigzag_Intra
+ *
+ * Description:
+ * Performs zigzag scanning and VLC encoding for one intra block.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] ppBitStream     pointer to the pointer to the current byte in
+ *                              the bit stream
+ * [in] pBitOffset      pointer to the bit position in the byte pointed
+ *                              by *ppBitStream. Valid within 0 to 7.
+ * [in] pQDctBlkCoef    pointer to the quantized DCT coefficient
+ * [in] predDir         AC prediction direction, which is used to decide
+ *                              the zigzag scan pattern. This takes one of the
+ *                              following values:
+ *                              OMX_VC_NONE          AC prediction not used.
+ *                                                      Performs classical zigzag
+ *                                                      scan.
+ *                              OMX_VC_HORIZONTAL    Horizontal prediction.
+ *                                                      Performs alternate-vertical
+ *                                                      zigzag scan.
+ *                              OMX_VC_VERTICAL      Vertical prediction.
+ *                                                      Performs alternate-horizontal
+ *                                                      zigzag scan.
+ * [in] pattern         block pattern which is used to decide whether
+ *                              this block is encoded
+ * [in] start           start indicates whether the encoding begins with 0th element
+ *                      or 1st.
+ * [out]    ppBitStream     *ppBitStream is updated after the block is encoded,
+ *                              so that it points to the current byte in the bit
+ *                              stream buffer.
+ * [out]    pBitOffset      *pBitOffset is updated so that it points to the
+ *                              current bit position in the byte pointed by
+ *                              *ppBitStream.
+ *
+ * Return Value:
+ * Standard OMXResult result. See enumeration for possible result codes.
+ *
+ */
+
+OMXResult armVCM4P2_EncodeVLCZigzag_Intra(
+     OMX_U8 **ppBitStream,
+     OMX_INT *pBitOffset,
+     const OMX_S16 *pQDctBlkCoef,
+     OMX_U8 predDir,
+     OMX_U8 pattern,
+     OMX_INT shortVideoHeader,
+     OMX_U8 start
+)
+{
+    const OMX_U8  *pZigzagTable = armVCM4P2_aClassicalZigzagScan;
+    OMXResult errorCode;
+    
+    /* Argument error checks */
+    armRetArgErrIf(ppBitStream == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(*ppBitStream == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pBitOffset == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pQDctBlkCoef == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf((*pBitOffset < 0) || (*pBitOffset >7), OMX_Sts_BadArgErr);
+    armRetArgErrIf(start > 1, OMX_Sts_BadArgErr);
+    armRetArgErrIf(predDir > 2, OMX_Sts_BadArgErr);
+
+    if (pattern)
+    {
+        switch (predDir)
+        {
+            case OMX_VC_NONE:
+            {
+                pZigzagTable = armVCM4P2_aClassicalZigzagScan;
+                break;
+            }
+
+            case OMX_VC_HORIZONTAL:
+            {
+                pZigzagTable = armVCM4P2_aVerticalZigzagScan;
+                break;
+            }
+
+            case OMX_VC_VERTICAL:
+            {
+                pZigzagTable = armVCM4P2_aHorizontalZigzagScan;
+                break;
+            }
+        }
+        
+        errorCode = armVCM4P2_PutVLCBits (
+              ppBitStream,
+              pBitOffset,
+              pQDctBlkCoef,
+              shortVideoHeader,
+              start,
+              14,
+              20,
+              9,
+              6,
+              armVCM4P2_IntraL0RunIdx,
+              armVCM4P2_IntraVlcL0,
+			  armVCM4P2_IntraL1RunIdx,
+              armVCM4P2_IntraVlcL1,
+              armVCM4P2_IntraL0LMAX,
+              armVCM4P2_IntraL1LMAX,
+              armVCM4P2_IntraL0RMAX,
+              armVCM4P2_IntraL1RMAX,
+              pZigzagTable
+        );
+        armRetDataErrIf((errorCode != OMX_Sts_NoErr), errorCode);
+        
+    } /* Pattern check ends*/
+
+    return (OMX_Sts_NoErr);
+
+}
+
+/* End of file */
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_FillVLCBuffer.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_FillVLCBuffer.c
new file mode 100644
index 0000000..93c9504
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_FillVLCBuffer.c
@@ -0,0 +1,153 @@
+/**
+ * 
+ * File Name:  armVCM4P2_FillVLCBuffer.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * 
+ * Description:
+ * Contains module for putting VLC bits
+ *
+ */ 
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+
+#include "armVC.h"
+#include "armCOMM.h"
+#include "armCOMM_Bitstream.h"
+
+/**
+ * Function: armVCM4P2_FillVLCBuffer
+ *
+ * Description:
+ * Performs calculating the VLC bits depending on the escape type and insert 
+ * the same in the bitstream
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	 ppBitStream		pointer to the pointer to the current byte in
+ *	                        the bit stream
+ * [in]	 pBitOffset         pointer to the bit position in the byte pointed
+ *                          by *ppBitStream. Valid within 0 to 7
+ * [in]  run                Run value (count of zeros) to be encoded  
+ * [in]  level              Level value (non-zero value) to be encoded
+ * [in]  runPlus            Calculated as runPlus = run - (RMAX + 1)  
+ * [in]  levelPlus          Calculated as 
+ *                          levelPlus = sign(level)*[abs(level) - LMAX]
+ * [in]  fMode              Flag indicating the escape modes
+ * [in]  last               status of the last flag
+ * [in]  maxRunForMultipleEntries 
+ *                          The run value after which level will be equal to 1: 
+ *                          (considering last and inter/intra status)
+ * [in]  pRunIndexTable     Run Index table defined in
+ *                          armVCM4P2_Huff_Tables_VLC.h
+ * [in]  pVlcTable          VLC table defined in armVCM4P2_Huff_Tables_VLC.h
+ * [out] ppBitStream		*ppBitStream is updated after the block is encoded
+ *                          so that it points to the current byte in the bit
+ *                          stream buffer.
+ * [out] pBitOffset         *pBitOffset is updated so that it points to the
+ *                          current bit position in the byte pointed by
+ *                          *ppBitStream.
+ *
+ * Return Value:
+ * Standard OMXResult result. See enumeration for possible result codes.
+ *
+ */
+
+OMXResult armVCM4P2_FillVLCBuffer (
+              OMX_U8 **ppBitStream,
+              OMX_INT * pBitOffset,
+              OMX_U32 run,
+              OMX_S16 level, 
+			  OMX_U32 runPlus,
+              OMX_S16 levelPlus, 
+              OMX_U8  fMode,
+			  OMX_U8  last,
+              OMX_U8  maxRunForMultipleEntries, 
+              const OMX_U8  *pRunIndexTable,
+              const ARM_VLC32 *pVlcTable
+)
+{
+    OMX_INT tempIndex;
+	OMX_U32 tempRun = run, sign = 0;
+    OMX_S16 tempLevel = level; 
+    
+    /* Escape sequence addition */
+    if (fMode == 1)
+    {
+        armPackBits(ppBitStream, pBitOffset, 3, 7);
+        armPackBits(ppBitStream, pBitOffset, 0, 1);
+		tempLevel = levelPlus;
+
+    }
+    else if(fMode == 2)
+    {
+        armPackBits(ppBitStream, pBitOffset, 3, 7);
+        armPackBits(ppBitStream, pBitOffset, 2, 2);
+		tempRun = runPlus;
+    }
+    else if (fMode == 3)
+    {
+        armPackBits(ppBitStream, pBitOffset, 3, 7);
+        armPackBits(ppBitStream, pBitOffset, 3, 2);
+    }
+    else if (fMode == 4)
+    {
+        armPackBits(ppBitStream, pBitOffset, 3, 7);
+        armPackBits(ppBitStream, pBitOffset, (OMX_U32)last, 1);
+		armPackBits(ppBitStream, pBitOffset, tempRun, 6);
+		if((tempLevel != 0) && (tempLevel != -128))
+		{
+		    armPackBits(ppBitStream, pBitOffset,
+			   (OMX_U32) tempLevel, 8);
+		}
+		return OMX_Sts_NoErr;		
+    }
+    
+    if (tempLevel < 0)
+    {
+        sign = 1;
+        tempLevel = armAbs(tempLevel);
+    }
+    /* Putting VLC bits in the stream */
+	if (fMode < 3)
+	{
+		if (tempRun > maxRunForMultipleEntries)
+		{
+			tempIndex = pRunIndexTable [maxRunForMultipleEntries + 1] + 
+						(tempRun - maxRunForMultipleEntries - 1);
+		}
+		else
+		{
+			tempIndex = pRunIndexTable [tempRun] + (tempLevel -1);
+		}
+    
+		armPackVLC32 (ppBitStream, pBitOffset,
+					  pVlcTable [tempIndex]);
+		armPackBits(ppBitStream, pBitOffset, (OMX_U32)sign, 1);
+	}
+    else
+	{
+		if (sign)
+		{
+			tempLevel = -tempLevel;
+		}
+		tempRun  = run;
+		armPackBits(ppBitStream, pBitOffset, (OMX_U32)last, 1);
+		armPackBits(ppBitStream, pBitOffset, tempRun, 6);
+		armPackBits(ppBitStream, pBitOffset, 1, 1);
+		armPackBits(ppBitStream, pBitOffset,
+			   (OMX_U32) tempLevel, 12);
+		armPackBits(ppBitStream, pBitOffset, 1, 1);
+	}
+    return OMX_Sts_NoErr;
+}
+
+/*End of File*/
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_FillVLDBuffer.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_FillVLDBuffer.c
new file mode 100644
index 0000000..1712c3a4
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_FillVLDBuffer.c
@@ -0,0 +1,84 @@
+/**
+ * 
+ * File Name:  armVCM4P2_FillVLDBuffer.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * 
+ * Description:
+ * Contains module for VLC get bits from the stream 
+ *
+ */ 
+
+#include "omxtypes.h"
+#include "armOMX.h"
+
+#include "armVCM4P2_ZigZag_Tables.h"
+
+
+/**
+ * Function: armVCM4P2_FillVLDBuffer
+ *
+ * Description:
+ * Performs filling of the coefficient buffer according to the run, level
+ * and sign, also updates the index
+ * 
+ * Parameters:
+ * [in]  storeRun        Stored Run value (count of zeros)   
+ * [in]  storeLevel      Stored Level value (non-zero value)
+ * [in]  sign            Flag indicating the sign of level
+ * [in]  last            status of the last flag
+ * [in]  pIndex          pointer to coefficient index in 8x8 matrix
+ * [out] pIndex          pointer to updated coefficient index in 8x8 
+ *                       matrix
+ * [in]  pZigzagTable    pointer to the zigzag tables
+ * [out] pDst            pointer to the coefficient buffer of current
+ *                       block. Should be 32-bit aligned
+ * Return Value:
+ * Standard OMXResult result. See enumeration for possible result codes.
+ *
+ */
+
+OMXResult armVCM4P2_FillVLDBuffer(
+    OMX_U32 storeRun,
+    OMX_S16 * pDst,
+    OMX_S16 storeLevel,
+    OMX_U8  sign,
+    OMX_U8  last,
+    OMX_U8  * pIndex,
+    const OMX_U8 * pZigzagTable
+)
+{
+    /* Store the zero's as per the run length count */
+    for (;storeRun > 0; storeRun--, (*pIndex)++)
+    {
+        pDst[pZigzagTable[*pIndex]] = 0;
+    }
+    /* Store the level depending on the sign*/
+    if (sign == 1)
+    {
+        pDst[pZigzagTable[*pIndex]] = -storeLevel;
+    }
+    else
+    {
+        pDst[pZigzagTable[*pIndex]] = storeLevel;
+    }
+    (*pIndex)++;
+
+    /* If last is 1, fill the remaining elments of the buffer with zeros */
+    if (last == 1)
+    {
+        while (*pIndex < 64)
+        {
+            pDst[pZigzagTable[*pIndex]] = 0;
+            (*pIndex)++;
+        }
+    }
+
+    return OMX_Sts_NoErr;
+}
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_GetVLCBits.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_GetVLCBits.c
new file mode 100644
index 0000000..953f597
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_GetVLCBits.c
@@ -0,0 +1,278 @@
+/**
+ * 
+ * File Name:  armVCM4P2_GetVLCBits.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * 
+ * Description:
+ * Contains module for VLC get bits from the stream 
+ *
+ */ 
+
+#include "omxtypes.h"
+#include "armOMX.h"
+
+#include "armVC.h"
+#include "armCOMM.h"
+#include "armCOMM_Bitstream.h"
+#include "armVCM4P2_ZigZag_Tables.h"
+#include "armVCM4P2_Huff_Tables_VLC.h"
+
+ 
+/**
+ * Function: armVCM4P2_GetVLCBits
+ *
+ * Description:
+ * Performs escape mode decision based on the run, run+, level, level+ and 
+ * last combinations.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	ppBitStream		pointer to the pointer to the current byte in
+ *								the bit stream
+ * [in]	pBitOffset		pointer to the bit position in the byte pointed
+ *								by *ppBitStream. Valid within 0 to 7
+ * [in] start           start indicates whether the encoding begins with 
+ *                      0th element or 1st.
+ * [in/out] pLast       pointer to last status flag
+ * [in] runBeginSingleLevelEntriesL0      The run value from which level 
+ *                                        will be equal to 1: last == 0
+ * [in] IndexBeginSingleLevelEntriesL0    Array index in the VLC table 
+ *                                        pointing to the  
+ *                                        runBeginSingleLevelEntriesL0 
+ * [in] runBeginSingleLevelEntriesL1      The run value from which level 
+ *                                        will be equal to 1: last == 1
+ * [in] IndexBeginSingleLevelEntriesL1    Array index in the VLC table 
+ *                                        pointing to the  
+ *                                        runBeginSingleLevelEntriesL0 
+ * [in] pRunIndexTableL0    Run Index table defined in 
+ *                          armVCM4P2_Huff_Tables_VLC.c for last == 0
+ * [in] pVlcTableL0         VLC table for last == 0
+ * [in] pRunIndexTableL1    Run Index table defined in 
+ *                          armVCM4P2_Huff_Tables_VLC.c for last == 1
+ * [in] pVlcTableL1         VLC table for last == 1
+ * [in] pLMAXTableL0        Level MAX table defined in 
+ *                          armVCM4P2_Huff_Tables_VLC.c for last == 0
+ * [in] pLMAXTableL1        Level MAX table defined in 
+ *                          armVCM4P2_Huff_Tables_VLC.c for last == 1
+ * [in] pRMAXTableL0        Run MAX table defined in 
+ *                          armVCM4P2_Huff_Tables_VLC.c for last == 0
+ * [in] pRMAXTableL1        Run MAX table defined in 
+ *                          armVCM4P2_Huff_Tables_VLC.c for last == 1
+ * [out]pDst			    pointer to the coefficient buffer of current
+ *							block. Should be 32-bit aligned
+ *
+ * Return Value:
+ * Standard OMXResult result. See enumeration for possible result codes.
+ *
+ */
+
+OMXResult armVCM4P2_GetVLCBits (
+              const OMX_U8 **ppBitStream,
+              OMX_INT * pBitOffset,
+			  OMX_S16 * pDst,
+			  OMX_INT shortVideoHeader,
+			  OMX_U8    start,			  
+			  OMX_U8  * pLast,
+			  OMX_U8    runBeginSingleLevelEntriesL0,
+			  OMX_U8    maxIndexForMultipleEntriesL0,
+			  OMX_U8    maxRunForMultipleEntriesL1,
+			  OMX_U8    maxIndexForMultipleEntriesL1,
+              const OMX_U8  * pRunIndexTableL0,
+              const ARM_VLC32 *pVlcTableL0,
+			  const OMX_U8  * pRunIndexTableL1,
+              const ARM_VLC32 *pVlcTableL1,
+              const OMX_U8  * pLMAXTableL0,
+              const OMX_U8  * pLMAXTableL1,
+              const OMX_U8  * pRMAXTableL0,
+              const OMX_U8  * pRMAXTableL1,
+              const OMX_U8  * pZigzagTable
+)
+{
+    OMX_U32 storeRun;
+    OMX_U8  tabIndex, markerBit;
+    OMX_S16 storeLevel;
+    OMX_U16 unpackRetIndex;
+	OMX_U8  i, fType, escape;	
+	OMX_U8  sign = 0;
+	
+	/* Unpacking the bitstream and RLD */
+    for (i = start; i < 64;)
+    {
+		escape = armLookAheadBits(ppBitStream, pBitOffset, 7);
+		if (escape != 3)
+		{	
+			fType = 0; /* Not in escape mode */
+		}
+		else
+		{
+			armSkipBits (ppBitStream, pBitOffset, 7);
+			if(shortVideoHeader)
+			{
+			  *pLast = armGetBits(ppBitStream, pBitOffset, 1);
+			  storeRun = armGetBits(ppBitStream, pBitOffset, 6);
+			  storeLevel = armGetBits(ppBitStream, pBitOffset, 8);
+			  
+			  /* Ref to Table B-18 (c) in MPEG4 Standard- FLC code for  */
+			  /* LEVEL when short_video_header is 1, the storeLevel is  */
+			  /* a signed value and the sign and the unsigned value for */
+			  /* storeLevel need to be extracted and passed to arm      */
+			  /* FillVLDBuffer function                                 */
+			     
+			  sign = (storeLevel & 0x80);
+			  if(sign==0x80)
+			  {
+			  	storeLevel=(storeLevel^0xff)+1;			  
+			  	sign=1;
+			  	
+			  }
+			  
+			  armRetDataErrIf( storeLevel == 0 || sign*storeLevel == 128 , OMX_Sts_Err); /* Invalid FLC */
+			  armRetDataErrIf((i + storeRun) >= 64, OMX_Sts_Err);
+			  armVCM4P2_FillVLDBuffer(
+			    storeRun,
+			    pDst,
+			    storeLevel,
+			    sign,
+			    *pLast,
+			    &i,
+			    pZigzagTable);
+			    return OMX_Sts_NoErr;
+			    
+			}
+			if (armGetBits(ppBitStream, pBitOffset, 1))
+			{
+				if (armGetBits(ppBitStream, pBitOffset, 1))
+				{
+					fType = 3;
+				}
+				else
+				{
+					fType = 2;
+				}
+			}
+			else
+			{
+				fType = 1;
+			}
+		}
+
+	    if (fType < 3)
+	    {
+	        unpackRetIndex = armUnPackVLC32(ppBitStream, pBitOffset,
+										pVlcTableL0);
+			if (unpackRetIndex != ARM_NO_CODEBOOK_INDEX)
+		    {
+			    /* Decode run and level from the index */
+			    /* last = 0 */
+			    *pLast = 0;
+			    if (unpackRetIndex > maxIndexForMultipleEntriesL0)
+			    {
+				    storeLevel = 1;
+				    storeRun = (unpackRetIndex - maxIndexForMultipleEntriesL0) 
+							+ runBeginSingleLevelEntriesL0;
+			    }
+			    else
+			    {
+				    tabIndex = 1;
+				    while (pRunIndexTableL0[tabIndex] <= unpackRetIndex)
+				    {
+					    tabIndex++;
+				    }
+				    storeRun = tabIndex - 1;
+				    storeLevel = unpackRetIndex - pRunIndexTableL0[tabIndex - 1] + 1;
+			    }
+			    sign = (OMX_U8) armGetBits(ppBitStream, pBitOffset, 1);
+			
+			    if (fType == 1)
+			    {
+				    storeLevel = (armAbs(storeLevel) + pLMAXTableL0[storeRun]);
+			    }
+			    else if (fType == 2)
+			    {
+				    storeRun = storeRun + pRMAXTableL0[storeLevel-1] + 1;
+			    }
+		    }
+		    else
+		    {
+			    unpackRetIndex = armUnPackVLC32(ppBitStream, pBitOffset, 
+											pVlcTableL1);
+
+			    armRetDataErrIf(unpackRetIndex == ARM_NO_CODEBOOK_INDEX, OMX_Sts_Err);
+
+			    /* Decode run and level from the index */
+			    /* last = 1 */
+			    *pLast = 1;
+			    if (unpackRetIndex > maxIndexForMultipleEntriesL1)
+			    {
+				    storeLevel = 1;
+				    storeRun = (unpackRetIndex - maxIndexForMultipleEntriesL1) 
+							+ maxRunForMultipleEntriesL1;
+		        }
+		        else
+			    {
+				    tabIndex = 1;
+				    while (pRunIndexTableL1[tabIndex] <= unpackRetIndex)
+				    {
+					    tabIndex++;
+				    }
+				    storeRun = tabIndex - 1;
+				    storeLevel = unpackRetIndex - pRunIndexTableL1[tabIndex - 1] + 1;
+			    }
+			    sign = (OMX_U8) armGetBits(ppBitStream, pBitOffset, 1);
+
+			    if (fType == 1)
+			    {
+			        storeLevel = (armAbs(storeLevel) + pLMAXTableL1[storeRun]);				
+			    }
+			    else if (fType == 2)
+			    {
+				    storeRun = storeRun + pRMAXTableL1[storeLevel-1] + 1;
+			    }
+		    }
+            armRetDataErrIf((i + storeRun) >= 64, OMX_Sts_Err);
+		    armVCM4P2_FillVLDBuffer(
+			    storeRun,
+			    pDst,
+			    storeLevel,
+			    sign,
+			    *pLast,
+			    &i,
+			    pZigzagTable);		
+	    }
+	    else
+	    {
+		    *pLast = armGetBits(ppBitStream, pBitOffset, 1);
+		    storeRun  = armGetBits(ppBitStream, pBitOffset, 6);
+		    armRetDataErrIf((i + storeRun) >= 64, OMX_Sts_Err);
+		    markerBit = armGetBits(ppBitStream, pBitOffset, 1);
+		    armRetDataErrIf( markerBit == 0, OMX_Sts_Err);
+		    storeLevel  = armGetBits(ppBitStream, pBitOffset, 12);
+		    if (storeLevel & 0x800)
+		    {
+			    storeLevel -= 4096;
+		    }			
+		    armRetDataErrIf( storeLevel == 0 || storeLevel == -2048 , OMX_Sts_Err); /* Invalid FLC */
+		    armGetBits(ppBitStream, pBitOffset, 1);
+		    armVCM4P2_FillVLDBuffer(
+			    storeRun,
+			    pDst,
+			    storeLevel,
+			    0, /* Sign is not used, preprocessing done */
+			    *pLast,
+			    &i,
+			    pZigzagTable);
+
+	    }
+    } /* End of forloop for i */
+	return OMX_Sts_NoErr;
+}
+
+/* End of File */
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_Huff_Tables_VLC.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_Huff_Tables_VLC.c
new file mode 100644
index 0000000..cd7e9e4
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_Huff_Tables_VLC.c
@@ -0,0 +1,495 @@
+ /**
+ * 
+ * File Name:  armVCM4P2_Huff_Tables_VLC.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * File:        armVCM4P2_Huff_Tables_VLC.c
+ * Description: Contains all the Huffman tables used in MPEG4 codec
+ *
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+
+#include "armCOMM_Bitstream.h"
+
+/* 
+*  For Intra
+*  last = 0 
+*/
+const OMX_U8 armVCM4P2_IntraL0RunIdx[11] = 
+{ 
+    0, 27, 37, 42, 46, 49, 52, 
+    55, 58, 60, 62
+};
+
+/* Entry defined for all values 
+*  for run = 0 to 14
+*  Note: the last entry is to terminate while decoding
+*/
+const ARM_VLC32 armVCM4P2_IntraVlcL0[68] = 
+{
+        {2,    2},
+        {3,    6},
+        {4,    15},
+        {5,    13},
+        {5,    12},
+        {6,    21},
+        {6,    19},
+        {6,    18},
+        {7,    23},
+        {8,    31},
+        {8,    30},
+        {8,    29},
+        {9,    37},
+        {9,    36},
+        {9,    35},
+        {9,    33},
+        {10,   33},
+        {10,   32},
+        {10,   15},
+        {10,   14},
+        {11,    7},
+        {11,    6},
+        {11,   32},
+        {11,   33},
+        {12,   80},
+        {12,   81},
+        {12,   82},
+        {4,    14},
+        {6,    20},
+        {7,    22},
+        {8,    28},
+        {9,    32},
+        {9,    31},
+        {10,   13},
+        {11,   34},
+        {12,   83},
+        {12,   85},
+        {5,    11},
+        {7,    21},
+        {9,    30},
+        {10,   12},
+        {12,   86},
+        {6,    17},
+        {8,    27},
+        {9,    29},
+        {10,   11},
+        {6,    16},
+        {9,    34},
+        {10,   10},
+        {6,    13},
+        {9,    28},
+        {10,    8},
+        {7,    18},
+        {9,    27},
+        {12,   84},
+        {7,    20},
+        {9,    26},
+        {12,   87},
+        {8,    25},
+        {10,    9},
+        {8,    24},
+        {11,   35},
+        {8,    23},
+        {9,    25},
+        {9,    24},
+        {10,    7},
+        {12,   88},
+        {0,     0}
+};
+
+/* 
+*  For Intra
+*  last = 1 
+*/
+
+const OMX_U8 armVCM4P2_IntraL1RunIdx[8] = 
+{
+    0,  8, 11, 13, 15, 17, 19, 21
+};
+
+/* Entry defined for all values 
+*  for run = 0 to 20
+*  *  Note: the last entry is to terminate while decoding
+*/
+const ARM_VLC32 armVCM4P2_IntraVlcL1[36] = 
+{
+        {4,     7},
+        {6,    12},
+        {8,    22},
+        {9,    23},
+        {10,    6},
+        {11,    5},
+        {11,    4},
+        {12,   89},
+        {6,    15},
+        {9,    22},
+        {10,    5},
+        {6,    14},
+        {10,    4},
+        {7,    17},
+        {11,   36},
+        {7,    16},
+        {11,   37},
+        {7,    19},
+        {12,   90},
+        {8,    21},
+        {12,   91},
+        {8,    20},
+        {8,    19},
+        {8,    26},
+        {9,    21},
+        {9,    20},
+        {9,    19},
+        {9,    18},
+        {9,    17},
+        {11,   38},
+        {11,   39},
+        {12,   92},
+        {12,   93},
+        {12,   94},
+        {12,   95},  
+        {0,     0}
+};
+
+/* LMAX table for Intra (Last == 0)*/
+const OMX_U8 armVCM4P2_IntraL0LMAX[15] = 
+{
+   27, 10,  5,  4,  3,  3,  3,  
+    3,  2,  2,  1,  1,  1,  1,  1
+};
+
+/* LMAX table for Intra (Last == 1)*/
+const OMX_U8 armVCM4P2_IntraL1LMAX[21] = 
+{
+    8,  3,  2,  2,  2,  2,  2,  1, 
+	1,  1,  1,  1,  1,  1,  1,  1,
+	1,  1,  1,  1,  1
+};
+
+/* RMAX table for Intra (Last == 0)
+   Level - 1 Indexed 
+*/
+const OMX_U8 armVCM4P2_IntraL0RMAX[27] =
+{
+   14,  9,  7,  3,  2,  1,	1,  
+    1,  1,  1,  0,  0,  0, 	0,  
+    0,  0,  0,  0,  0,  0,  0,  
+    0,  0,  0,  0,  0,  0
+};
+
+/* RMAX table for Intra (Last == 1)
+   Level - 1 Indexed 
+*/
+const OMX_U8 armVCM4P2_IntraL1RMAX[8] =
+{
+   20,  6,  1,  0,  0,  0,  0,  0
+};
+
+/* 
+*  For Inter
+*  last = 0 
+*/
+const OMX_U8 armVCM4P2_InterL0RunIdx[12] = 
+{ 
+     0,  12,  18,  22,  25,  28,  
+    31,  34,  36,  38,  40,  42
+};
+
+/* Entry defined for all values 
+*  for run = 0 to 26
+*  Note: the last entry is to terminate while decoding
+*/
+const ARM_VLC32 armVCM4P2_InterVlcL0[59] = 
+{
+        {2,     2},
+        {4,    15},
+        {6,    21},
+        {7,    23},
+        {8,    31},
+        {9,    37},
+        {9,    36},
+        {10,   33},
+        {10,   32},
+        {11,    7},
+        {11,    6},
+        {11,   32},
+        {3,     6},
+        {6,    20},
+        {8,    30},
+        {10,   15},
+        {11,   33},
+        {12,   80},
+        {4,    14},
+        {8,    29},
+        {10,   14},
+        {12,   81},
+        {5,    13},
+        {9,    35},
+        {10,   13},
+        {5,    12},
+        {9,    34},
+        {12,   82},
+        {5,    11},
+        {10,   12},
+        {12,   83},
+        {6,    19},
+        {10,   11},
+        {12,   84},
+        {6,    18},
+        {10,   10},
+        {6,    17},
+        {10,    9},
+        {6,    16},
+        {10,    8},
+        {7,    22},
+        {12,   85},
+        {7,    21},
+        {7,    20},
+        {8,    28},
+        {8,    27},
+        {9,    33},
+        {9,    32},
+        {9,    31},
+        {9,    30},
+        {9,    29},
+        {9,    28},
+        {9,    27},
+        {9,    26},
+        {11,   34},
+        {11,   35},
+        {12,   86},
+        {12,   87},
+        {0,     0}
+};
+ 
+
+/* 
+*  For Intra
+*  last = 1 
+*/
+
+const OMX_U8 armVCM4P2_InterL1RunIdx[3] = 
+{
+    0, 3, 5
+};
+
+/* Entry defined for all values 
+*  for run = 0 to 40
+*  Note: the last entry is to terminate while decoding
+*/
+const ARM_VLC32 armVCM4P2_InterVlcL1[45] = 
+{
+        {4,     7},
+        {9,    25},
+        {11,    5},
+        {6,    15},
+        {11,    4},
+        {6,    14},
+        {6,    13},
+        {6,    12},
+        {7,    19},
+        {7,    18},
+        {7,    17},
+        {7,    16},
+        {8,    26},
+        {8,    25},
+        {8,    24},
+        {8,    23},
+        {8,    22},
+        {8,    21},
+        {8,    20},
+        {8,    19},
+        {9,    24},
+        {9,    23},
+        {9,    22},
+        {9,    21},
+        {9,    20},
+        {9,    19},
+        {9,    18},
+        {9,    17},
+        {10,    7},
+        {10,    6},
+        {10,    5},
+        {10,    4},
+        {11,   36},
+        {11,   37},
+        {11,   38},
+        {11,   39},
+        {12,   88},
+        {12,   89},
+        {12,   90},
+        {12,   91},
+        {12,   92},
+        {12,   93},
+        {12,   94},
+        {12,   95},
+        { 0,    0}
+};
+
+/* LMAX table for Intra (Last == 0)*/
+const OMX_U8 armVCM4P2_InterL0LMAX[27] = 
+{
+   12,  6,  4,  3,  3,  3,  3,  2, 
+    2,  2,  2,  1,  1,  1,  1,  1,
+    1,  1,  1,  1,  1,  1,  1,  1,
+    1,  1,  1,
+};
+
+/* LMAX table for Intra (Last == 1)*/
+const OMX_U8 armVCM4P2_InterL1LMAX[41] = 
+{
+    3,  2,  1,  1,  1,  1,  1,  1, 
+	1,  1,  1,  1,  1,  1,  1,  1,
+	1,  1,  1,  1,  1,  1,  1,  1,
+	1,  1,  1,  1,  1,  1,  1,  1,
+	1,  1,  1,  1,  1,  1,  1,  1,
+	1,  
+};
+
+/* RMAX table for Intra (Last == 0)
+   Level - 1 Indexed 
+*/
+const OMX_U8 armVCM4P2_InterL0RMAX[12] = 
+{
+   26, 10,  6,  2,  1,  1,   
+    0,  0,  0,  0,  0,  0
+};
+
+/* RMAX table for Intra (Last == 1)
+   Level - 1 Indexed 
+*/
+const OMX_U8 armVCM4P2_InterL1RMAX[3] = 
+{
+   40,  1,  0
+};
+
+/* 
+*  For Intra - Luminance
+*/
+
+const ARM_VLC32 armVCM4P2_aIntraDCLumaIndex[14] = 
+{
+        {3,     3},
+        {2,     3},
+        {2,     2},
+        {3,     2},
+        {3,     1},
+        {4,     1},
+        {5,     1},
+        {6,     1},
+        {7,     1},
+        {8,     1},
+        {9,     1},
+        {10,    1},
+        {11,    1},
+        {0,     0}
+};
+
+/* 
+*  For Intra - Chrominance
+*/
+ 
+const ARM_VLC32 armVCM4P2_aIntraDCChromaIndex[14] = 
+{
+        {2,     3},
+        {2,     2},
+        {2,     1},
+        {3,     1},
+        {4,     1},
+        {5,     1},
+        {6,     1},
+        {7,     1},
+        {8,     1},
+        {9,     1},
+        {10,    1},
+        {11,    1},
+        {12,    1},
+        {0,     0}
+};
+
+/* 
+ *  Motion vector decoding table
+ */
+ 
+const ARM_VLC32 armVCM4P2_aVlcMVD[66] =
+{
+        {13,     5},
+        {13,     7},
+        {12,     5},
+        {12,     7},
+        {12,     9},
+        {12,    11},
+        {12,    13},
+        {12,    15},
+        {11,     9},
+        {11,    11},
+        {11,    13},
+        {11,    15},
+        {11,    17},
+        {11,    19},
+        {11,    21},
+        {11,    23},
+        {11,    25},
+        {11,    27},
+        {11,    29},
+        {11,    31},
+        {11,    33},
+        {11,    35},
+        {10,    19},
+        {10,    21},
+        {10,    23},
+        {8,      7},
+        {8,      9},
+        {8,     11},
+        {7,      7},
+        {5,      3},
+        {4,      3},
+        {3,      3},
+        {1,      1},
+        {3,      2},
+        {4,      2},
+        {5,      2},
+        {7,      6},
+        {8,     10},
+        {8,      8},
+        {8,      6},
+        {10,    22},
+        {10,    20},
+        {10,    18},
+        {11,    34},
+        {11,    32},
+        {11,    30},
+        {11,    28},
+        {11,    26},
+        {11,    24},
+        {11,    22},
+        {11,    20},
+        {11,    18},
+        {11,    16},
+        {11,    14},
+        {11,    12},
+        {11,    10},
+        {11,     8},
+        {12,    14},
+        {12,    12},
+        {12,    10},
+        {12,     8},
+        {12,     6},
+        {12,     4},
+        {13,     6},
+        {13,     4},
+        { 0,     0}
+};
+
+/* End of file */
+
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_PutVLCBits.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_PutVLCBits.c
new file mode 100644
index 0000000..ca9efec
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_PutVLCBits.c
@@ -0,0 +1,200 @@
+/**
+ * 
+ * File Name:  armVCM4P2_PutVLCBits.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * 
+ * Description:
+ * Contains module for VLC put bits to bitstream 
+ *
+ */ 
+
+#include "omxtypes.h"
+#include "armOMX.h"
+
+#include "armVC.h"
+#include "armCOMM.h"
+#include "armCOMM_Bitstream.h"
+#include "armVCM4P2_ZigZag_Tables.h"
+#include "armVCM4P2_Huff_Tables_VLC.h"
+
+ 
+/**
+ * Function: armVCM4P2_PutVLCBits
+ *
+ * Description:
+ * Checks the type of Escape Mode and put encoded bits for 
+ * quantized DCT coefficients.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	 ppBitStream      pointer to the pointer to the current byte in
+ *						  the bit stream
+ * [in]	 pBitOffset       pointer to the bit position in the byte pointed
+ *                        by *ppBitStream. Valid within 0 to 7
+ * [in] shortVideoHeader binary flag indicating presence of short_video_header; escape modes 0-3 are used if shortVideoHeader==0,
+ *                           and escape mode 4 is used when shortVideoHeader==1.
+ * [in]  start            start indicates whether the encoding begins with 
+ *                        0th element or 1st.
+ * [in]  maxStoreRunL0    Max store possible (considering last and inter/intra)
+ *                        for last = 0
+ * [in]  maxStoreRunL1    Max store possible (considering last and inter/intra)
+ *                        for last = 1
+ * [in]  maxRunForMultipleEntriesL0 
+ *                        The run value after which level 
+ *                        will be equal to 1: 
+ *                        (considering last and inter/intra status) for last = 0
+ * [in]  maxRunForMultipleEntriesL1 
+ *                        The run value after which level 
+ *                        will be equal to 1: 
+ *                        (considering last and inter/intra status) for last = 1
+ * [in]  pRunIndexTableL0 Run Index table defined in 
+ *                        armVCM4P2_Huff_Tables_VLC.c for last == 0
+ * [in]  pVlcTableL0      VLC table for last == 0
+ * [in]  pRunIndexTableL1 Run Index table defined in 
+ *                        armVCM4P2_Huff_Tables_VLC.c for last == 1
+ * [in]  pVlcTableL1      VLC table for last == 1
+ * [in]  pLMAXTableL0     Level MAX table defined in 
+ *                        armVCM4P2_Huff_Tables_VLC.c for last == 0
+ * [in]  pLMAXTableL1     Level MAX table defined in 
+ *                        armVCM4P2_Huff_Tables_VLC.c for last == 1
+ * [in]  pRMAXTableL0     Run MAX table defined in 
+ *                        armVCM4P2_Huff_Tables_VLC.c for last == 0
+ * [in]  pRMAXTableL1     Run MAX table defined in 
+ *                        armVCM4P2_Huff_Tables_VLC.c for last == 1
+ * [out] pQDctBlkCoef     pointer to the quantized DCT coefficient
+ * [out] ppBitStream      *ppBitStream is updated after the block is encoded
+ *                        so that it points to the current byte in the bit
+ *                        stream buffer.
+ * [out] pBitOffset       *pBitOffset is updated so that it points to the
+ *                        current bit position in the byte pointed by
+ *                        *ppBitStream.
+ *
+ * Return Value:
+ * Standard OMXResult result. See enumeration for possible result codes.
+ *
+ */
+
+
+OMXResult armVCM4P2_PutVLCBits (
+              OMX_U8 **ppBitStream,
+              OMX_INT * pBitOffset,
+              const OMX_S16 *pQDctBlkCoef,
+              OMX_INT shortVideoHeader,
+              OMX_U8 start,
+              OMX_U8 maxStoreRunL0,
+              OMX_U8 maxStoreRunL1,
+              OMX_U8  maxRunForMultipleEntriesL0,
+              OMX_U8  maxRunForMultipleEntriesL1,
+              const OMX_U8  * pRunIndexTableL0,
+              const ARM_VLC32 *pVlcTableL0,
+			  const OMX_U8  * pRunIndexTableL1,
+              const ARM_VLC32 *pVlcTableL1,
+              const OMX_U8  * pLMAXTableL0,
+              const OMX_U8  * pLMAXTableL1,
+              const OMX_U8  * pRMAXTableL0,
+              const OMX_U8  * pRMAXTableL1,
+              const OMX_U8  * pZigzagTable
+)
+{
+
+    OMX_U32 storeRun = 0, run, storeRunPlus;
+    OMX_U8  last = 0, first = 1, fMode;
+    OMX_S16 level, storeLevel = 0, storeLevelPlus;
+    OMX_INT i;
+    
+        /* RLE encoding and packing the bits into the streams */
+        for (i = start, run=0; i < 64; i++)
+        {
+            level   = pQDctBlkCoef[pZigzagTable[i]];
+
+            /* Counting the run */
+            if (level == 0)
+            {
+                run++;
+            }
+
+            /* Found a non-zero coeff */
+            else
+            {
+                if (first == 0)
+                {
+                    last = 0;
+                    
+                    /* Check for a valid entry in the VLC table */
+                    storeLevelPlus = armSignCheck(storeLevel) * 
+                      (armAbs(storeLevel) - pLMAXTableL0[storeRun]);
+                    storeRunPlus = storeRun - 
+                                  (pRMAXTableL0[armAbs(storeLevel) - 1] + 1);
+                                                      
+                    fMode = armVCM4P2_CheckVLCEscapeMode(
+                                             storeRun,
+                                             storeRunPlus,
+                                             storeLevel,
+                                             storeLevelPlus,
+                                             maxStoreRunL0,
+                                             maxRunForMultipleEntriesL0,
+                                             shortVideoHeader,
+                                             pRunIndexTableL0);
+                    
+                    armVCM4P2_FillVLCBuffer (
+                                      ppBitStream, 
+                                      pBitOffset,
+                                      storeRun,
+                                      storeLevel, 
+									  storeRunPlus,
+                                      storeLevelPlus, 
+                                      fMode,
+									  last,
+                                      maxRunForMultipleEntriesL0, 
+                                      pRunIndexTableL0,
+                                      pVlcTableL0);                                                  
+                }
+                storeLevel = level;
+                storeRun   = run;
+                first = 0;
+                run = 0;
+            }
+
+        } /* end of for loop for 64 elements */
+
+        /* writing the last element */
+        last = 1;
+        
+        /* Check for a valid entry in the VLC table */
+        storeLevelPlus = armSignCheck(storeLevel) * 
+                        (armAbs(storeLevel) - pLMAXTableL1[run]);
+        storeRunPlus = storeRun - 
+                      (pRMAXTableL1[armAbs(storeLevel) - 1] + 1);
+        fMode = armVCM4P2_CheckVLCEscapeMode(
+                                 storeRun,
+                                 storeRunPlus,
+                                 storeLevel,
+                                 storeLevelPlus,
+                                 maxStoreRunL1,
+                                 maxRunForMultipleEntriesL1,
+                                 shortVideoHeader,
+                                 pRunIndexTableL1);
+        
+        armVCM4P2_FillVLCBuffer (
+                          ppBitStream, 
+                          pBitOffset,
+                          storeRun,
+                          storeLevel, 
+						  storeRunPlus,
+                          storeLevelPlus,
+                          fMode,
+						  last,
+                          maxRunForMultipleEntriesL1,
+                          pRunIndexTableL1,
+                          pVlcTableL1);
+	return OMX_Sts_NoErr;                          
+}
+
+/* End of File */
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_SetPredDir.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_SetPredDir.c
new file mode 100644
index 0000000..a9cd008
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_SetPredDir.c
@@ -0,0 +1,89 @@
+/**
+ * 
+ * File Name:  armVCM4P2_SetPredDir.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * 
+ * Description:
+ * Contains module for detecting the prediction direction
+ *
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+
+#include "armVC.h"
+#include "armCOMM.h"
+
+/**
+ * Function: armVCM4P2_SetPredDir
+ *
+ * Description:
+ * Performs detecting the prediction direction
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] blockIndex  block index indicating the component type and
+ *                          position as defined in subclause 6.1.3.8, of ISO/IEC
+ *                          14496-2. Furthermore, indexes 6 to 9 indicate the
+ *                          alpha blocks spatially corresponding to luminance
+ *                          blocks 0 to 3 in the same macroblock.
+ * [in] pCoefBufRow pointer to the coefficient row buffer
+ * [in] pQpBuf      pointer to the quantization parameter buffer
+ * [out]    predQP      quantization parameter of the predictor block
+ * [out]    predDir     indicates the prediction direction which takes one
+ *                          of the following values:
+ *                          OMX_VC_HORIZONTAL    predict horizontally
+ *                          OMX_VC_VERTICAL      predict vertically
+ *
+ * Return Value:
+ * Standard OMXResult result. See enumeration for possible result codes.
+ *
+ */
+
+OMXResult armVCM4P2_SetPredDir(
+     OMX_INT blockIndex,
+     OMX_S16 *pCoefBufRow,
+     OMX_S16 *pCoefBufCol,
+     OMX_INT *predDir,
+     OMX_INT *predQP,
+     const OMX_U8 *pQpBuf
+)
+{
+    OMX_U8  blockDCLeft;
+    OMX_U8  blockDCTop;
+    OMX_U8  blockDCTopLeft;
+
+    if (blockIndex == 3)
+    {
+        blockDCTop = *(pCoefBufCol - 8);
+    }
+    else
+    {
+        blockDCTop = *pCoefBufRow;
+    }
+    blockDCLeft = *pCoefBufCol;
+    blockDCTopLeft = *(pCoefBufRow - 8);
+
+    if (armAbs(blockDCLeft - blockDCTopLeft) < armAbs(blockDCTopLeft \
+                                                        - blockDCTop))
+    {
+        *predDir = OMX_VC_VERTICAL;
+        *predQP = pQpBuf[1];
+    }
+    else
+    {
+        *predDir = OMX_VC_HORIZONTAL;
+        *predQP = pQpBuf[0];
+    }
+    return OMX_Sts_NoErr;
+}
+
+
+/*End of File*/
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_Zigzag_Tables.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_Zigzag_Tables.c
new file mode 100644
index 0000000..a247c69
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/armVCM4P2_Zigzag_Tables.c
@@ -0,0 +1,58 @@
+ /**
+ * 
+ * File Name:  armVCM4P2_Zigzag_Tables.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * File:        armVCM4P2_ZigZag_Tables.c
+ * Description: Contains the zigzag tables
+ *
+ */
+
+#include "omxtypes.h"
+
+const OMX_U8 armVCM4P2_aClassicalZigzagScan [64] = 
+{
+     0,  1,  8, 16,  9,  2,  3, 10,
+    17, 24, 32, 25, 18, 11,  4,  5,
+    12, 19, 26, 33, 40, 48, 41, 34,
+    27, 20, 13,  6,  7, 14, 21, 28, 
+    35, 42, 49, 56, 57, 50, 43, 36,
+    29, 22, 15, 23, 30, 37, 44, 51,
+    58, 59, 52, 45, 38, 31, 39, 46,
+    53, 60, 61, 54, 47, 55, 62, 63
+};
+
+const OMX_U8 armVCM4P2_aHorizontalZigzagScan [64] = 
+{
+     0,  1,  2,  3,  8,  9, 16, 17,
+    10, 11,  4,  5,  6,  7, 15, 14,
+    13, 12, 19, 18, 24, 25, 32, 33,
+    26, 27, 20, 21, 22, 23, 28, 29,
+    30, 31, 34, 35, 40, 41, 48, 49,
+    42, 43, 36, 37, 38, 39, 44, 45, 
+    46, 47, 50, 51, 56, 57, 58, 59,
+    52, 53, 54, 55, 60, 61, 62, 63
+};
+
+const OMX_U8 armVCM4P2_aVerticalZigzagScan [64] = 
+{
+     0,  8, 16, 24,  1,  9,  2, 10,
+     17, 25, 32, 40, 48, 56, 57, 49,
+     41, 33, 26, 18,  3, 11,  4, 12,
+     19, 27, 34, 42, 50, 58, 35, 43,
+     51, 59, 20, 28,  5, 13,  6, 14,
+     21, 29, 36, 44, 52, 60, 37, 45, 
+     53, 61, 22, 30,  7, 15, 23, 31,
+     38, 46, 54, 62, 39, 47, 55, 63
+};
+
+
+/* End of file */
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_BlockMatch_Half_16x16.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_BlockMatch_Half_16x16.c
new file mode 100644
index 0000000..dcd3ce1
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_BlockMatch_Half_16x16.c
@@ -0,0 +1,111 @@
+/**
+ * 
+ * File Name:  omxVCM4P2_BlockMatch_Half_16x16.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * 
+ * Description:
+ * Contains modules for Block matching, a full search algorithm
+ * is implemented
+ *
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armVC.h"
+#include "armCOMM.h"
+
+/**
+ * Function:  omxVCM4P2_BlockMatch_Half_16x16   (6.2.4.2.3)
+ *
+ * Description:
+ * Performs a 16x16 block match with half-pixel resolution.  Returns the 
+ * estimated motion vector and associated minimum SAD.  This function 
+ * estimates the half-pixel motion vector by interpolating the integer 
+ * resolution motion vector referenced by the input parameter pSrcDstMV, i.e., 
+ * the initial integer MV is generated externally.  The input parameters 
+ * pSrcRefBuf and pSearchPointRefPos should be shifted by the winning MV of 
+ * 16x16 integer search prior to calling BlockMatch_Half_16x16. The function 
+ * BlockMatch_Integer_16x16 may be used for integer motion estimation. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcRefBuf - pointer to the reference Y plane; points to the reference 
+ *            macroblock that corresponds to the location of the current 
+ *            macroblock in the current plane. 
+ *   refWidth - width of the reference plane 
+ *   pRefRect - reference plane valid region rectangle 
+ *   pSrcCurrBuf - pointer to the current block in the current macroblock 
+ *            buffer extracted from the original plane (linear array, 256 
+ *            entries); must be aligned on a 16-byte boundary.  The number of 
+ *            bytes between lines (step) is 16. 
+ *   pSearchPointRefPos - position of the starting point for half pixel 
+ *            search (specified in terms of integer pixel units) in the 
+ *            reference plane, i.e., the reference position pointed to by the 
+ *            predicted motion vector. 
+ *   rndVal - rounding control parameter: 0 - disabled; 1 - enabled. 
+ *   pSrcDstMV - pointer to the initial MV estimate; typically generated 
+ *            during a prior 16X16 integer search; specified in terms of 
+ *            half-pixel units. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDstMV - pointer to estimated MV 
+ *   pDstSAD - pointer to minimum SAD 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments.  Returned if one of the following 
+ *              conditions is true: 
+ *    -    at least one of the following pointers is NULL: pSrcRefBuf, 
+ *         pRefRect, pSrcCurrBuff, pSearchPointRefPos, pSrcDstMV.
+ *    -    pSrcCurrBuf is not 16-byte aligned, or 
+ *
+ */
+
+OMXResult omxVCM4P2_BlockMatch_Half_16x16(
+     const OMX_U8 *pSrcRefBuf,
+     OMX_INT refWidth,
+     const OMXRect *pRefRect,
+     const OMX_U8 *pSrcCurrBuf,
+     const OMXVCM4P2Coordinate *pSearchPointRefPos,
+     OMX_INT rndVal,
+     OMXVCMotionVector *pSrcDstMV,
+     OMX_INT *pDstSAD
+)
+{
+
+    /* For a blocksize of 16x16 */
+    OMX_U8 BlockSize = 16;
+    
+    /* Argument error checks */  
+    armRetArgErrIf(pSrcRefBuf         == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pRefRect           == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pSrcCurrBuf        == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pSearchPointRefPos == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pSrcDstMV          == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(!armIs16ByteAligned(pSrcCurrBuf), OMX_Sts_BadArgErr);
+   
+    return (armVCM4P2_BlockMatch_Half(
+                                pSrcRefBuf,
+                                refWidth,
+                                pRefRect,
+                                pSrcCurrBuf,
+                                pSearchPointRefPos,
+                                rndVal,
+                                pSrcDstMV,
+                                pDstSAD,
+                                BlockSize));
+
+
+}
+
+/* End of file */
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_BlockMatch_Half_8x8.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_BlockMatch_Half_8x8.c
new file mode 100644
index 0000000..6996e6d
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_BlockMatch_Half_8x8.c
@@ -0,0 +1,109 @@
+/**
+ * 
+ * File Name:  omxVCM4P2_BlockMatch_Half_8x8.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Description:
+ * Contains modules for Block matching, a full search algorithm
+ * is implemented
+ * 
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armVC.h"
+#include "armCOMM.h"
+
+
+/**
+ * Function:  omxVCM4P2_BlockMatch_Half_8x8   (6.2.4.2.4)
+ *
+ * Description:
+ * Performs an 8x8 block match with half-pixel resolution. Returns the 
+ * estimated motion vector and associated minimum SAD.  This function 
+ * estimates the half-pixel motion vector by interpolating the integer 
+ * resolution motion vector referenced by the input parameter pSrcDstMV, i.e., 
+ * the initial integer MV is generated externally.  The input parameters 
+ * pSrcRefBuf and pSearchPointRefPos should be shifted by the winning MV of 
+ * 8x8 integer search prior to calling BlockMatch_Half_8x8. The function 
+ * BlockMatch_Integer_8x8 may be used for integer motion estimation. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcRefBuf - pointer to the reference Y plane; points to the reference 
+ *            block that corresponds to the location of the current 8x8 block 
+ *            in the current plane. 
+ *   refWidth - width of the reference plane 
+ *   pRefRect - reference plane valid region rectangle 
+ *   pSrcCurrBuf - pointer to the current block in the current macroblock 
+ *            buffer extracted from the original plane (linear array, 128 
+ *            entries); must be aligned on a 8-byte boundary.  The number of 
+ *            bytes between lines (step) is 16. 
+ *   pSearchPointRefPos - position of the starting point for half pixel 
+ *            search (specified in terms of integer pixel units) in the 
+ *            reference plane. 
+ *   rndVal - rounding control parameter: 0 - disabled; 1 - enabled. 
+ *   pSrcDstMV - pointer to the initial MV estimate; typically generated 
+ *            during a prior 8x8 integer search, specified in terms of 
+ *            half-pixel units. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDstMV - pointer to estimated MV 
+ *   pDstSAD - pointer to minimum SAD 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments.  Returned if one of the following 
+ *              conditions is true: 
+ *    -    at least one of the following pointers is NULL: 
+ *         pSrcRefBuf, pRefRect, pSrcCurrBuff, pSearchPointRefPos, pSrcDstMV
+ *    -    pSrcCurrBuf is not 8-byte aligned 
+ *
+ */
+
+OMXResult omxVCM4P2_BlockMatch_Half_8x8(
+     const OMX_U8 *pSrcRefBuf,
+     OMX_INT refWidth,
+     const OMXRect *pRefRect,
+     const OMX_U8 *pSrcCurrBuf,
+     const OMXVCM4P2Coordinate *pSearchPointRefPos,
+     OMX_INT rndVal,
+     OMXVCMotionVector *pSrcDstMV,
+     OMX_INT *pDstSAD
+)
+{
+    /* For a blocksize of 8x8 */
+    OMX_U8 BlockSize = 8;
+    
+    /* Argument error checks */  
+    armRetArgErrIf(pSrcRefBuf         == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pRefRect           == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pSrcCurrBuf        == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pSearchPointRefPos == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pSrcDstMV          == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(!armIs8ByteAligned(pSrcCurrBuf), OMX_Sts_BadArgErr);
+   
+    return (armVCM4P2_BlockMatch_Half(
+                                pSrcRefBuf,
+                                refWidth,
+                                pRefRect,
+                                pSrcCurrBuf,
+                                pSearchPointRefPos,
+                                rndVal,
+                                pSrcDstMV,
+                                pDstSAD,
+                                BlockSize));
+
+}
+
+/* End of file */
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_BlockMatch_Integer_16x16.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_BlockMatch_Integer_16x16.c
new file mode 100644
index 0000000..e714ef1
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_BlockMatch_Integer_16x16.c
@@ -0,0 +1,114 @@
+/**
+ * 
+ * File Name:  omxVCM4P2_BlockMatch_Integer_16x16.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Description:
+ * Contains modules for Block matching, a full search algorithm
+ * is implemented
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armVC.h"
+#include "armCOMM.h"
+
+/**
+ * Function:  omxVCM4P2_BlockMatch_Integer_16x16   (6.2.4.2.1)
+ *
+ * Description:
+ * Performs a 16x16 block search; estimates motion vector and associated 
+ * minimum SAD. Both the input and output motion vectors are represented using 
+ * half-pixel units, and therefore a shift left or right by 1 bit may be 
+ * required, respectively, to match the input or output MVs with other 
+ * functions that either generate output MVs or expect input MVs represented 
+ * using integer pixel units. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcRefBuf - pointer to the reference Y plane; points to the reference 
+ *            MB that corresponds to the location of the current macroblock in 
+ *            the current plane. 
+ *   refWidth - width of the reference plane 
+ *   pRefRect - pointer to the valid reference plane rectangle; coordinates 
+ *            are specified relative to the image origin.  Rectangle 
+ *            boundaries may extend beyond image boundaries if the image has 
+ *            been padded.  For example, if padding extends 4 pixels beyond 
+ *            frame border, then the value for the left border could be set to 
+ *            -4. 
+ *   pSrcCurrBuf - pointer to the current block in the current macroblock 
+ *            buffer extracted from the original plane (linear array, 256 
+ *            entries); must be aligned on a 16-byte boundary.  The number of 
+ *            bytes between lines (step) is 16. 
+ *   pCurrPointPos - position of the current macroblock in the current plane 
+ *   pSrcPreMV - pointer to predicted motion vector; NULL indicates no 
+ *            predicted MV 
+ *   pSrcPreSAD - pointer to SAD associated with the predicted MV (referenced 
+ *            by pSrcPreMV); may be set to NULL if unavailable. 
+ *   pMESpec - vendor-specific motion estimation specification structure; 
+ *            must have been allocated and then initialized using 
+ *            omxVCM4P2_MEInit prior to calling the block matching function. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstMV - pointer to estimated MV 
+ *   pDstSAD - pointer to minimum SAD 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments.  Returned if one of the following 
+ *              conditions is true: 
+ *    -    at least one of the following pointers is NULL: pSrcRefBuf, 
+ *              pRefRect, pSrcCurrBuff, pCurrPointPos, pDstMV, pDstSAD or 
+ *              pMESpec, or 
+ *    -    pSrcCurrBuf is not 16-byte aligned 
+ *
+ */
+
+OMXResult omxVCM4P2_BlockMatch_Integer_16x16(
+     const OMX_U8 *pSrcRefBuf,
+     OMX_INT refWidth,
+     const OMXRect *pRefRect,
+     const OMX_U8 *pSrcCurrBuf,
+     const OMXVCM4P2Coordinate *pCurrPointPos,
+     const OMXVCMotionVector *pSrcPreMV,
+     const OMX_INT *pSrcPreSAD,
+     void *pMESpec,
+     OMXVCMotionVector *pDstMV,
+     OMX_INT *pDstSAD
+)
+{
+
+   OMX_U8 BlockSize = 16;
+   
+   /* Argument error checks */  
+   armRetArgErrIf(!armIs16ByteAligned(pSrcCurrBuf), OMX_Sts_BadArgErr);
+   
+   return ( armVCM4P2_BlockMatch_Integer(
+     pSrcRefBuf,
+     refWidth,
+     pRefRect,
+     pSrcCurrBuf,
+     pCurrPointPos,
+     pSrcPreMV,
+     pSrcPreSAD,
+     pMESpec,
+     pDstMV,
+     pDstSAD,
+     BlockSize)
+     );
+
+
+}
+
+/* End of file */
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_BlockMatch_Integer_8x8.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_BlockMatch_Integer_8x8.c
new file mode 100644
index 0000000..607e64c
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_BlockMatch_Integer_8x8.c
@@ -0,0 +1,110 @@
+/**
+ * 
+ * File Name:  omxVCM4P2_BlockMatch_Integer_8x8.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Description:
+ * Contains modules for Block matching, a full search algorithm
+ * is implemented
+ * 
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armVC.h"
+#include "armCOMM.h"
+
+/**
+ * Function:  omxVCM4P2_BlockMatch_Integer_8x8   (6.2.4.2.2)
+ *
+ * Description:
+ * Performs an 8x8 block search; estimates motion vector and associated 
+ * minimum SAD.  Both the input and output motion vectors are represented 
+ * using half-pixel units, and therefore a shift left or right by 1 bit may be 
+ * required, respectively, to match the input or output MVs with other 
+ * functions that either generate output MVs or expect input MVs represented 
+ * using integer pixel units. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcRefBuf - pointer to the reference Y plane; points to the reference 
+ *            block that corresponds to the location of the current 8x8 block 
+ *            in the current plane. 
+ *   refWidth - width of the reference plane 
+ *   pRefRect - pointer to the valid reference plane rectangle; coordinates 
+ *            are specified relative to the image origin.  Rectangle 
+ *            boundaries may extend beyond image boundaries if the image has 
+ *            been padded. 
+ *   pSrcCurrBuf - pointer to the current block in the current macroblock 
+ *            buffer extracted from the original plane (linear array, 128 
+ *            entries); must be aligned on an 8-byte boundary.  The number of 
+ *            bytes between lines (step) is 16 bytes. 
+ *   pCurrPointPos - position of the current block in the current plane 
+ *   pSrcPreMV - pointer to predicted motion vector; NULL indicates no 
+ *            predicted MV 
+ *   pSrcPreSAD - pointer to SAD associated with the predicted MV (referenced 
+ *            by pSrcPreMV); may be set to NULL if unavailable. 
+ *   pMESpec - vendor-specific motion estimation specification structure; 
+ *            must have been allocated and then initialized using 
+ *            omxVCM4P2_MEInit prior to calling the block matching function. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstMV - pointer to estimated MV 
+ *   pDstSAD - pointer to minimum SAD 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments.  Returned if one of the following 
+ *              conditions is true: 
+ *    -    at least one of the following pointers is NULL: pSrcRefBuf, 
+ *              pRefRect, pSrcCurrBuff, pCurrPointPos, pDstMV, pDstSAD or 
+ *              pMESpec, or 
+ *    -    pSrcCurrBuf is not 8-byte aligned 
+ *
+ */
+
+OMXResult omxVCM4P2_BlockMatch_Integer_8x8(
+     const OMX_U8 *pSrcRefBuf,
+     OMX_INT refWidth,
+     const OMXRect *pRefRect,
+     const OMX_U8 *pSrcCurrBuf,
+     const OMXVCM4P2Coordinate *pCurrPointPos,
+     const OMXVCMotionVector *pSrcPreMV,
+     const OMX_INT *pSrcPreSAD,
+     void *pMESpec,
+     OMXVCMotionVector *pDstMV,
+     OMX_INT *pDstSAD
+)
+{
+   OMX_U8 BlockSize = 8;
+   
+   /* Argument error checks */  
+   armRetArgErrIf(!armIs8ByteAligned(pSrcCurrBuf), OMX_Sts_BadArgErr);
+   
+   return ( armVCM4P2_BlockMatch_Integer(
+     pSrcRefBuf,
+     refWidth,
+     pRefRect,
+     pSrcCurrBuf,
+     pCurrPointPos,
+     pSrcPreMV,
+     pSrcPreSAD,
+     pMESpec,
+     pDstMV,
+     pDstSAD,
+     BlockSize)
+     );
+
+}
+
+/* End of file */
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_DCT8x8blk.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_DCT8x8blk.c
new file mode 100644
index 0000000..a077ac8
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_DCT8x8blk.c
@@ -0,0 +1,87 @@
+/**
+ * 
+ * File Name:  omxVCM4P2_DCT8x8blk.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Description:
+ * Contains modules for 8x8 block DCT
+ * 
+ */
+ 
+#include <math.h>
+#include "omxtypes.h"
+#include "armOMX.h"
+
+#include "armCOMM.h"
+#include "armVCM4P2_DCT_Table.h"
+
+/**
+ * Function:  omxVCM4P2_DCT8x8blk   (6.2.4.4.1)
+ *
+ * Description:
+ * Computes a 2D forward DCT for a single 8x8 block, as defined in 
+ * [ISO14496-2]. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - pointer to the start of the linearly arranged input buffer; must 
+ *            be aligned on a 16-byte boundary.  Input values (pixel 
+ *            intensities) are valid in the range [-255,255]. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - pointer to the start of the linearly arranged output buffer; must 
+ *            be aligned on a 16-byte boundary. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments, returned if:
+ *    -    pSrc or pDst is NULL. 
+ *    -    pSrc or pDst is not 16-byte aligned. 
+ *
+ */
+
+OMXResult omxVCM4P2_DCT8x8blk (const OMX_S16 *pSrc, OMX_S16 *pDst)
+{
+    OMX_INT x, y, u, v;
+    
+    /* Argument error checks */
+    armRetArgErrIf(pSrc == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(!armIs16ByteAligned(pSrc), OMX_Sts_BadArgErr);
+    armRetArgErrIf(pDst == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(!armIs16ByteAligned(pDst), OMX_Sts_BadArgErr);
+
+
+    for (u = 0; u < 8; u++)
+    {
+        for (v = 0; v < 8; v++)
+        {
+            OMX_F64 sum = 0.0;
+            for (x = 0; x < 8; x++)
+            {
+                for (y = 0; y < 8; y++)
+                {
+                    sum += pSrc[(x * 8) + y] *
+                       armVCM4P2_preCalcDCTCos[x][u] *
+                       armVCM4P2_preCalcDCTCos[y][v];
+                }
+            }
+            pDst[(u * 8) + v]= armRoundFloatToS16 (sum);            
+        }
+    }
+
+    return OMX_Sts_NoErr;
+}
+
+
+
+/* End of file */
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_DecodeBlockCoef_Inter.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_DecodeBlockCoef_Inter.c
new file mode 100644
index 0000000..51f7bab
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_DecodeBlockCoef_Inter.c
@@ -0,0 +1,115 @@
+/**
+ * 
+ * File Name:  omxVCM4P2_DecodeBlockCoef_Inter.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Description: 
+ * Contains modules for inter reconstruction
+ * 
+ */
+ 
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+
+
+/**
+ * Function:  omxVCM4P2_DecodeBlockCoef_Inter   (6.2.5.4.2)
+ *
+ * Description:
+ * Decodes the INTER block coefficients. This function performs inverse 
+ * quantization, inverse zigzag positioning, and IDCT (with appropriate 
+ * clipping on each step) on the coefficients. The results (residuals) are 
+ * placed in a contiguous array of 64 elements. For INTER block, the output 
+ * buffer holds the residuals for further reconstruction. 
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - pointer to the pointer to the current byte in the bit 
+ *            stream buffer. There is no boundary check for the bit stream 
+ *            buffer. 
+ *   pBitOffset - pointer to the bit position in the byte pointed to by 
+ *            *ppBitStream. *pBitOffset is valid within [0-7] 
+ *   QP - quantization parameter 
+ *   shortVideoHeader - binary flag indicating presence of 
+ *            short_video_header; shortVideoHeader==1 selects linear intra DC 
+ *            mode, and shortVideoHeader==0 selects non linear intra DC mode. 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after the block is decoded, so 
+ *            that it points to the current byte in the bit stream buffer 
+ *   pBitOffset - *pBitOffset is updated so that it points to the current bit 
+ *            position in the byte pointed by *ppBitStream 
+ *   pDst - pointer to the decoded residual buffer (a contiguous array of 64 
+ *            elements of OMX_S16 data type); must be aligned on a 16-byte 
+ *            boundary. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments, if:
+ *    -    At least one of the following pointers is Null: 
+ *         ppBitStream, *ppBitStream, pBitOffset , pDst 
+ *    -    *pBitOffset exceeds [0,7]
+ *    -    QP <= 0. 
+ *    -    pDst is not 16-byte aligned 
+ *    OMX_Sts_Err - status error. Refer to OMX_Sts_Err of DecodeVLCZigzag_Inter . 
+ *
+ */
+OMXResult omxVCM4P2_DecodeBlockCoef_Inter(
+     const OMX_U8 ** ppBitStream,
+     OMX_INT * pBitOffset,
+     OMX_S16 * pDst,
+     OMX_INT QP,
+     OMX_INT shortVideoHeader
+)
+{
+    /* 64 elements are needed but to align it to 16 bytes need
+    15 more elements of padding */
+    OMX_S16 tempBuf[79];
+    OMX_S16 *pTempBuf1;
+    OMXResult errorCode;
+    /* Aligning the local buffers */
+    pTempBuf1 = armAlignTo16Bytes(tempBuf);
+    
+    /* Argument error checks */
+    armRetArgErrIf(ppBitStream == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(*ppBitStream == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pBitOffset == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pDst == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(!armIs16ByteAligned(pDst), OMX_Sts_BadArgErr);
+    armRetArgErrIf(((QP <= 0) || (QP >= 32)), OMX_Sts_BadArgErr);
+	armRetArgErrIf(((*pBitOffset < 0) || (*pBitOffset > 7)), OMX_Sts_BadArgErr);
+
+
+    /* VLD and zigzag */
+    errorCode = omxVCM4P2_DecodeVLCZigzag_Inter(ppBitStream, pBitOffset, 
+                                        pTempBuf1,shortVideoHeader);
+    armRetDataErrIf((errorCode != OMX_Sts_NoErr), errorCode);
+    
+    /* Dequantization */
+    errorCode = omxVCM4P2_QuantInvInter_I(
+     pTempBuf1,
+     QP);
+    armRetDataErrIf((errorCode != OMX_Sts_NoErr), errorCode);
+    
+    /* Inverse transform */
+    errorCode = omxVCM4P2_IDCT8x8blk(pTempBuf1, pDst);
+    armRetDataErrIf((errorCode != OMX_Sts_NoErr), errorCode);
+    
+    return OMX_Sts_NoErr;
+}
+
+/* End of file */
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_DecodeBlockCoef_Intra.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_DecodeBlockCoef_Intra.c
new file mode 100644
index 0000000..a0b2376
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_DecodeBlockCoef_Intra.c
@@ -0,0 +1,225 @@
+/**
+ * 
+ * File Name:  omxVCM4P2_DecodeBlockCoef_Intra.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Description: 
+ * Contains modules for intra reconstruction
+ * 
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+
+/**
+ * Function:  omxVCM4P2_DecodeBlockCoef_Intra   (6.2.5.4.1)
+ *
+ * Description:
+ * Decodes the INTRA block coefficients. Inverse quantization, inversely 
+ * zigzag positioning, and IDCT, with appropriate clipping on each step, are 
+ * performed on the coefficients. The results are then placed in the output 
+ * frame/plane on a pixel basis.  Note: This function will be used only when 
+ * at least one non-zero AC coefficient of current block exists in the bit 
+ * stream. The DC only condition will be handled in another function. 
+ *
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - pointer to the pointer to the current byte in the bit 
+ *            stream buffer. There is no boundary check for the bit stream 
+ *            buffer. 
+ *   pBitOffset - pointer to the bit position in the byte pointed to by 
+ *            *ppBitStream. *pBitOffset is valid within [0-7]. 
+ *   step - width of the destination plane 
+ *   pCoefBufRow - pointer to the coefficient row buffer; must be aligned on 
+ *            an 8-byte boundary. 
+ *   pCoefBufCol - pointer to the coefficient column buffer; must be aligned 
+ *            on an 8-byte boundary. 
+ *   curQP - quantization parameter of the macroblock which the current block 
+ *            belongs to 
+ *   pQPBuf - pointer to the quantization parameter buffer 
+ *   blockIndex - block index indicating the component type and position as 
+ *            defined in [ISO14496-2], subclause 6.1.3.8, Figure 6-5. 
+ *   intraDCVLC - a code determined by intra_dc_vlc_thr and QP. This allows a 
+ *            mechanism to switch between two VLC for coding of Intra DC 
+ *            coefficients as per [ISO14496-2], Table 6-21. 
+ *   ACPredFlag - a flag equal to ac_pred_flag (of luminance) indicating if 
+ *            the ac coefficients of the first row or first column are 
+ *            differentially coded for intra coded macroblock. 
+ *   shortVideoHeader - binary flag indicating presence of 
+ *            short_video_header; shortVideoHeader==1 selects linear intra DC 
+ *            mode, and shortVideoHeader==0 selects non linear intra DC mode. 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after the block is decoded, so 
+ *            that it points to the current byte in the bit stream buffer 
+ *   pBitOffset - *pBitOffset is updated so that it points to the current bit 
+ *            position in the byte pointed by *ppBitStream 
+ *   pDst - pointer to the block in the destination plane; must be aligned on 
+ *            an 8-byte boundary. 
+ *   pCoefBufRow - pointer to the updated coefficient row buffer. 
+ *   pCoefBufCol - pointer to the updated coefficient column buffer  Note: 
+ *            The coefficient buffers must be updated in accordance with the 
+ *            update procedure defined in section 6.2.2. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments, if:
+ *    -    At least one of the following pointers is NULL: 
+ *         ppBitStream, *ppBitStream, pBitOffset, pCoefBufRow, pCoefBufCol, 
+ *         pQPBuf, pDst. 
+ *    -    *pBitOffset exceeds [0,7] 
+ *    -    curQP exceeds (1, 31)
+ *    -    blockIndex exceeds [0,5]
+ *    -    step is not the multiple of 8
+ *    -    a pointer alignment requirement was violated. 
+ *    OMX_Sts_Err - status error. Refer to OMX_Sts_Err of DecodeVLCZigzag_Intra.  
+ *
+ */
+
+OMXResult omxVCM4P2_DecodeBlockCoef_Intra(
+     const OMX_U8 ** ppBitStream,
+     OMX_INT *pBitOffset,
+     OMX_U8 *pDst,
+     OMX_INT step,
+     OMX_S16 *pCoefBufRow,
+     OMX_S16 *pCoefBufCol,
+     OMX_U8 curQP,
+     const OMX_U8 *pQPBuf,
+     OMX_INT blockIndex,
+     OMX_INT intraDCVLC,
+     OMX_INT ACPredFlag,
+	 OMX_INT shortVideoHeader
+ )
+{
+    OMX_S16 tempBuf1[79], tempBuf2[79];
+    OMX_S16 *pTempBuf1, *pTempBuf2;
+    OMX_INT predDir, predACDir, i, j, count;
+    OMX_INT  predQP;
+    OMXVCM4P2VideoComponent videoComp;
+    OMXResult errorCode;
+    
+    /* Argument error checks */
+    armRetArgErrIf(ppBitStream == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(*ppBitStream == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pBitOffset == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pDst == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pCoefBufRow == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pCoefBufCol == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pQPBuf == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(!armIs8ByteAligned(pDst), OMX_Sts_BadArgErr);
+    armRetArgErrIf(((curQP <= 0) || (curQP >= 32)), OMX_Sts_BadArgErr);
+    armRetArgErrIf((*pBitOffset < 0) || (*pBitOffset >7), OMX_Sts_BadArgErr);
+    armRetArgErrIf((blockIndex < 0) || (blockIndex > 5), OMX_Sts_BadArgErr);
+    armRetArgErrIf((step % 8) != 0, OMX_Sts_BadArgErr);
+    
+
+    /* Aligning the local buffers */
+    pTempBuf1 = armAlignTo16Bytes(tempBuf1);
+    pTempBuf2 = armAlignTo16Bytes(tempBuf2);
+    
+    /* Setting the AC prediction direction and prediction direction */
+    armVCM4P2_SetPredDir(
+        blockIndex,
+        pCoefBufRow,
+        pCoefBufCol,
+        &predDir,
+        &predQP,
+        pQPBuf);
+
+    predACDir = predDir;
+
+    armRetArgErrIf(((predQP <= 0) || (predQP >= 32)), OMX_Sts_BadArgErr);
+
+    if (ACPredFlag == 0)
+    {
+        predACDir = OMX_VC_NONE;
+    }
+
+    /* Setting the videoComp */
+    if (blockIndex <= 3)
+    {
+        videoComp = OMX_VC_LUMINANCE;
+    }
+    else
+    {
+        videoComp = OMX_VC_CHROMINANCE;
+    }
+    
+
+    /* VLD and zigzag */
+    if (intraDCVLC == 1)
+    {
+        errorCode = omxVCM4P2_DecodeVLCZigzag_IntraDCVLC(
+            ppBitStream,
+            pBitOffset,
+            pTempBuf1,
+            predACDir,
+            shortVideoHeader,
+            videoComp);
+        armRetDataErrIf((errorCode != OMX_Sts_NoErr), errorCode);
+    }
+    else
+    {
+        errorCode = omxVCM4P2_DecodeVLCZigzag_IntraACVLC(
+            ppBitStream,
+            pBitOffset,
+            pTempBuf1,
+            predACDir,
+            shortVideoHeader);
+        armRetDataErrIf((errorCode != OMX_Sts_NoErr), errorCode);
+    }
+
+    /* AC DC prediction */
+    errorCode = omxVCM4P2_PredictReconCoefIntra(
+        pTempBuf1,
+        pCoefBufRow,
+        pCoefBufCol,
+        curQP,
+        predQP,
+        predDir,
+        ACPredFlag,
+        videoComp);
+    armRetDataErrIf((errorCode != OMX_Sts_NoErr), errorCode);
+    
+    /* Dequantization */
+    errorCode = omxVCM4P2_QuantInvIntra_I(
+     pTempBuf1,
+     curQP,
+     videoComp,
+     shortVideoHeader);
+    armRetDataErrIf((errorCode != OMX_Sts_NoErr), errorCode);
+    
+    /* Inverse transform */
+    errorCode = omxVCM4P2_IDCT8x8blk (pTempBuf1, pTempBuf2);
+    armRetDataErrIf((errorCode != OMX_Sts_NoErr), errorCode);
+    
+    /* Placing the linear array into the destination plane and clipping
+       it to 0 to 255 */
+    for (j = 0, count = 0; j < 8; j++)
+    {
+        for(i = 0; i < 8; i++, count++)
+        {
+            pDst[i] = armClip (0, 255, pTempBuf2[count]);
+        }
+        pDst += step;
+    }
+
+    return OMX_Sts_NoErr;
+}
+
+/* End of file */
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_DecodePadMV_PVOP.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_DecodePadMV_PVOP.c
new file mode 100644
index 0000000..7e159b7
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_DecodePadMV_PVOP.c
@@ -0,0 +1,243 @@
+/**
+ * 
+ * File Name:  omxVCM4P2_DecodePadMV_PVOP.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Description: 
+ * Contains module for decoding MV and padding the same
+ * 
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM_Bitstream.h"
+#include "armCOMM.h"
+#include "armVCM4P2_Huff_Tables_VLC.h"
+
+
+
+/**
+ * Function:  omxVCM4P2_DecodePadMV_PVOP   (6.2.5.1.1)
+ *
+ * Description:
+ * Decodes and pads the four motion vectors associated with a non-intra P-VOP 
+ * macroblock.  For macroblocks of type OMX_VC_INTER4V, the output MV is 
+ * padded as specified in [ISO14496-2], subclause 7.6.1.6. Otherwise, for 
+ * macroblocks of types other than OMX_VC_INTER4V, the decoded MV is copied to 
+ * all four output MV buffer entries. 
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - pointer to the pointer to the current byte in the bit 
+ *            stream buffer 
+ *   pBitOffset - pointer to the bit position in the byte pointed to by 
+ *            *ppBitStream. *pBitOffset is valid within [0-7]. 
+ *   pSrcMVLeftMB, pSrcMVUpperMB, and pSrcMVUpperRightMB - pointers to the 
+ *            motion vector buffers of the macroblocks specially at the left, 
+ *            upper, and upper-right side of the current macroblock, 
+ *            respectively; a value of NULL indicates unavailability.  Note: 
+ *            Any neighborhood macroblock outside the current VOP or video 
+ *            packet or outside the current GOB (when short_video_header is 
+ *             1 ) for which gob_header_empty is  0  is treated as 
+ *            transparent, according to [ISO14496-2], subclause 7.6.5. 
+ *   fcodeForward - a code equal to vop_fcode_forward in MPEG-4 bit stream 
+ *            syntax 
+ *   MBType - the type of the current macroblock. If MBType is not equal to 
+ *            OMX_VC_INTER4V, the destination motion vector buffer is still 
+ *            filled with the same decoded vector. 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after the block is decoded, so 
+ *            that it points to the current byte in the bit stream buffer 
+ *   pBitOffset - *pBitOffset is updated so that it points to the current bit 
+ *            position in the byte pointed by *ppBitStream 
+ *   pDstMVCurMB - pointer to the motion vector buffer for the current 
+ *            macroblock; contains four decoded motion vectors 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments:
+ *    -    At least one of the following pointers is NULL: 
+ *         ppBitStream, *ppBitStream, pBitOffset, pDstMVCurMB 
+ *    -    *pBitOffset exceeds [0,7]
+ *    -    fcodeForward exceeds (0,7]
+ *    -    MBType less than zero
+ *    -    motion vector buffer is not 4-byte aligned. 
+ *    OMX_Sts_Err - status error 
+ *
+ */
+
+OMXResult omxVCM4P2_DecodePadMV_PVOP(
+     const OMX_U8 ** ppBitStream,
+     OMX_INT * pBitOffset,
+     OMXVCMotionVector * pSrcMVLeftMB,
+     OMXVCMotionVector *pSrcMVUpperMB,
+     OMXVCMotionVector * pSrcMVUpperRightMB,
+     OMXVCMotionVector * pDstMVCurMB,
+     OMX_INT fcodeForward,
+     OMXVCM4P2MacroblockType MBType
+ )
+{
+    OMXVCMotionVector diffMV;
+    OMXVCMotionVector dstMVPredME[12];
+    OMX_INT iBlk, i, count = 1;
+    OMX_S32 mvHorResidual = 1, mvVerResidual = 1, mvHorData, mvVerData;
+    OMX_S8 scaleFactor, index;
+    OMX_S16 high, low, range;
+
+
+    /* Argument error checks */
+    armRetArgErrIf(ppBitStream == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(*ppBitStream == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pBitOffset == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pDstMVCurMB == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(((*pBitOffset < 0) || (*pBitOffset > 7)), OMX_Sts_BadArgErr);
+    armRetArgErrIf(((fcodeForward < 1) || (fcodeForward > 7)), \
+                    OMX_Sts_BadArgErr);
+    armRetArgErrIf(!armIs4ByteAligned(pDstMVCurMB), OMX_Sts_BadArgErr);
+    
+    if ((MBType == OMX_VC_INTRA) ||
+        (MBType == OMX_VC_INTRA_Q)
+       )
+    {
+        /* All MV's are zero */
+        for (i = 0; i < 4; i++)
+        {
+            pDstMVCurMB[i].dx = 0;
+            pDstMVCurMB[i].dy = 0;
+        }
+
+        return OMX_Sts_NoErr;
+    }
+
+    if ((MBType == OMX_VC_INTER4V) || (MBType == OMX_VC_INTER4V_Q))
+    {
+        count = 4;
+    }
+    else if ((MBType == OMX_VC_INTER) || (MBType == OMX_VC_INTER_Q))
+    {
+        count = 1;
+    }
+
+    /* Calculating the scale factor */
+    scaleFactor = 1 << (fcodeForward -1);
+    high =  ( 32 * scaleFactor) - 1;
+    low =   ( (-32) * scaleFactor);
+    range = ( 64 * scaleFactor);
+
+    /* Huffman decoding and MV reconstruction */
+    for (iBlk = 0; iBlk < count; iBlk++)
+    {
+
+        /* Huffman decoding to get Horizontal data and residual */
+        index = armUnPackVLC32(ppBitStream, pBitOffset,
+                                            armVCM4P2_aVlcMVD);
+        armRetDataErrIf(index == -1, OMX_Sts_Err);
+
+        mvHorData = index - 32;
+
+        if ((fcodeForward > 1) && (mvHorData != 0))
+        {
+            mvHorResidual = (OMX_S32) armGetBits(ppBitStream,
+                                            pBitOffset, (fcodeForward -1));
+        }
+
+        /* Huffman decoding to get Vertical data and residual */
+        index = armUnPackVLC32(ppBitStream, pBitOffset, armVCM4P2_aVlcMVD);
+        armRetDataErrIf(index == -1, OMX_Sts_Err);
+
+        mvVerData = index - 32;
+
+        if ((fcodeForward > 1) && (mvVerData != 0))
+        {
+            mvVerResidual = (OMX_S32) armGetBits(ppBitStream,
+                                            pBitOffset, (fcodeForward -1));
+        }
+
+        /* Calculating the differtial MV */
+        if ( (scaleFactor == 1) || (mvHorData == 0) )
+        {
+            diffMV.dx = mvHorData;
+        }
+        else
+        {
+            diffMV.dx = ((armAbs(mvHorData) - 1) * fcodeForward)
+                         + mvHorResidual + 1;
+            if (mvHorData < 0)
+            {
+                diffMV.dx = -diffMV.dx;
+            }
+        }
+
+        if ( (scaleFactor == 1) || (mvVerData == 0) )
+        {
+            diffMV.dy = mvVerData;
+        }
+        else
+        {
+            diffMV.dy = ((armAbs(mvVerData) - 1) * fcodeForward)
+                         + mvVerResidual + 1;
+            if (mvVerData < 0)
+            {
+                diffMV.dy = -diffMV.dy;
+            }
+        }
+
+        /* Find the predicted vector */
+        omxVCM4P2_FindMVpred (
+            pDstMVCurMB,
+            pSrcMVLeftMB,
+            pSrcMVUpperMB,
+            pSrcMVUpperRightMB,
+            &pDstMVCurMB[iBlk],
+            dstMVPredME,
+            iBlk);
+
+        /* Adding the difference to the predicted MV to reconstruct MV */
+        pDstMVCurMB[iBlk].dx += diffMV.dx;
+        pDstMVCurMB[iBlk].dy += diffMV.dy;
+
+        /* Checking the range and keeping it within the limits */
+        if ( pDstMVCurMB[iBlk].dx < low )
+        {
+            pDstMVCurMB[iBlk].dx += range;
+        }
+        if (pDstMVCurMB[iBlk].dx > high)
+        {
+            pDstMVCurMB[iBlk].dx -= range;
+        }
+
+        if ( pDstMVCurMB[iBlk].dy < low )
+        {
+            pDstMVCurMB[iBlk].dy += range;
+        }
+        if (pDstMVCurMB[iBlk].dy > high)
+        {
+            pDstMVCurMB[iBlk].dy -= range;
+        }
+    }
+
+    if ((MBType == OMX_VC_INTER) || (MBType == OMX_VC_INTER_Q))
+    {
+        pDstMVCurMB[1] = pDstMVCurMB[0];
+        pDstMVCurMB[2] = pDstMVCurMB[0];
+        pDstMVCurMB[3] = pDstMVCurMB[0];
+    }
+
+    return OMX_Sts_NoErr;
+}
+
+
+/* End of file */
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_Inter.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_Inter.c
new file mode 100644
index 0000000..88a8d04
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_Inter.c
@@ -0,0 +1,120 @@
+/**
+ * 
+ * File Name:  omxVCM4P2_DecodeVLCZigzag_Inter.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Description: 
+ * Contains modules for zigzag scanning and VLC decoding
+ * for inter block.
+ *
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armVC.h"
+#include "armCOMM_Bitstream.h"
+#include "armCOMM.h"
+#include "armVCM4P2_Huff_Tables_VLC.h"
+#include "armVCM4P2_ZigZag_Tables.h"
+
+
+
+/**
+ * Function:  omxVCM4P2_DecodeVLCZigzag_Inter   (6.2.5.2.3)
+ *
+ * Description:
+ * Performs VLC decoding and inverse zigzag scan for one inter-coded block. 
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - double pointer to the current byte in the stream buffer 
+ *   pBitOffset - pointer to the next available bit in the current stream 
+ *            byte referenced by *ppBitStream. The parameter *pBitOffset is 
+ *            valid within the range [0-7]. 
+ *   shortVideoHeader - binary flag indicating presence of 
+ *            short_video_header; escape modes 0-3 are used if 
+ *            shortVideoHeader==0, and escape mode 4 is used when 
+ *            shortVideoHeader==1. 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after the block is decoded such 
+ *            that it points to the current byte in the stream buffer 
+ *   pBitOffset - *pBitOffset is updated after decoding such that it points 
+ *            to the next available bit in the stream byte referenced by 
+ *            *ppBitStream 
+ *   pDst - pointer to the coefficient buffer of current block; must be 
+ *            4-byte aligned. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_BadArgErr - bad arguments:
+ *    -    At least one of the following pointers is NULL: 
+ *         ppBitStream, *ppBitStream, pBitOffset, pDst
+ *    -    pDst is not 4-byte aligned
+ *    -   *pBitOffset exceeds [0,7]
+ *    OMX_Sts_Err - status error, if:
+ *    -    At least one mark bit is equal to zero 
+ *    -    Encountered an illegal stream code that cannot be found in the VLC table 
+ *    -    Encountered an illegal code in the VLC FLC table 
+ *    -    The number of coefficients is greater than 64 
+ *
+ */
+
+OMXResult omxVCM4P2_DecodeVLCZigzag_Inter(
+     const OMX_U8 ** ppBitStream,
+     OMX_INT * pBitOffset,
+     OMX_S16 * pDst,
+     OMX_INT shortVideoHeader
+)
+{
+    OMX_U8  last,start = 0;
+    const OMX_U8  *pZigzagTable = armVCM4P2_aClassicalZigzagScan;
+    OMXResult errorCode;
+    
+    /* Argument error checks */
+    armRetArgErrIf(ppBitStream == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(*ppBitStream == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pBitOffset == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pDst == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(!armIs4ByteAligned(pDst), OMX_Sts_BadArgErr);
+
+    errorCode = armVCM4P2_GetVLCBits (
+              ppBitStream,
+              pBitOffset,
+			  pDst,
+			  shortVideoHeader,
+              start,
+			  &last,
+			  11,
+			  42,
+			   2,
+			   5,
+              armVCM4P2_InterL0RunIdx,
+              armVCM4P2_InterVlcL0,
+			  armVCM4P2_InterL1RunIdx,
+              armVCM4P2_InterVlcL1,
+              armVCM4P2_InterL0LMAX,
+              armVCM4P2_InterL1LMAX,
+              armVCM4P2_InterL0RMAX,
+              armVCM4P2_InterL1RMAX,
+              pZigzagTable );
+    armRetDataErrIf((errorCode != OMX_Sts_NoErr), errorCode);
+    
+    if (last == 0)
+    {
+        return OMX_Sts_Err;
+    }
+    return OMX_Sts_NoErr;
+}
+
+/* End of file */
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_IntraACVLC.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_IntraACVLC.c
new file mode 100644
index 0000000..96593d1
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_IntraACVLC.c
@@ -0,0 +1,103 @@
+/**
+ * 
+ * File Name:  omxVCM4P2_DecodeVLCZigzag_IntraACVLC.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Description: 
+ * Contains modules for zigzag scanning and VLC decoding
+ * for intra block.
+ *
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armVC.h"
+#include "armCOMM.h"
+
+
+
+/**
+ * Function:  omxVCM4P2_DecodeVLCZigzag_IntraACVLC   (6.2.5.2.2)
+ *
+ * Description:
+ * Performs VLC decoding and inverse zigzag scan of AC and DC coefficients 
+ * for one intra block.  Two versions of the function (DCVLC and ACVLC) are 
+ * provided in order to support the two different methods of processing DC 
+ * coefficients, as described in [ISO14496-2], subclause 7.4.1.4,  Intra DC 
+ * Coefficient Decoding for the Case of Switched VLC Encoding.  
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - pointer to the pointer to the current byte in the 
+ *            bitstream buffer 
+ *   pBitOffset - pointer to the bit position in the current byte referenced 
+ *            by *ppBitStream.  The parameter *pBitOffset is valid in the 
+ *            range [0-7]. Bit Position in one byte:  |Most Least| *pBitOffset 
+ *            |0 1 2 3 4 5 6 7| 
+ *   predDir - AC prediction direction; used to select the zigzag scan 
+ *            pattern; takes one of the following values: OMX_VC_NONE - AC 
+ *            prediction not used; performs classical zigzag scan. 
+ *            OMX_VC_HORIZONTAL - Horizontal prediction; performs 
+ *            alternate-vertical zigzag scan; OMX_VC_VERTICAL - Vertical 
+ *            prediction; performs alternate-horizontal zigzag scan. 
+ *   shortVideoHeader - binary flag indicating presence of 
+ *            short_video_header; escape modes 0-3 are used if 
+ *            shortVideoHeader==0, and escape mode 4 is used when 
+ *            shortVideoHeader==1. 
+ *   videoComp - video component type (luminance or chrominance) of the 
+ *            current block 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after the block is decoded such 
+ *            that it points to the current byte in the bit stream buffer 
+ *   pBitOffset - *pBitOffset is updated such that it points to the current 
+ *            bit position in the byte pointed by *ppBitStream 
+ *   pDst - pointer to the coefficient buffer of current block; must be 
+ *            4-byte aligned. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments At least one of the following 
+ *              pointers is NULL: ppBitStream, *ppBitStream, pBitOffset, pDst, 
+ *              or At least one of the following conditions is true: 
+ *              *pBitOffset exceeds [0,7], preDir exceeds [0,2], or pDst is 
+ *              not 4-byte aligned 
+ *    OMX_Sts_Err In DecodeVLCZigzag_IntraDCVLC, dc_size > 12 At least one of 
+ *              mark bits equals zero Illegal stream encountered; code cannot 
+ *              be located in VLC table Forbidden code encountered in the VLC 
+ *              FLC table The number of coefficients is greater than 64 
+ *
+ */
+
+
+OMXResult omxVCM4P2_DecodeVLCZigzag_IntraACVLC(
+     const OMX_U8 ** ppBitStream,
+     OMX_INT * pBitOffset,
+     OMX_S16 * pDst,
+     OMX_U8 predDir,
+     OMX_INT shortVideoHeader
+)
+{
+    OMX_U8 start = 0;
+
+    return armVCM4P2_DecodeVLCZigzag_Intra(
+     ppBitStream,
+     pBitOffset,
+     pDst,
+     predDir,
+     shortVideoHeader,
+     start);
+}
+
+/* End of file */
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_IntraDCVLC.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_IntraDCVLC.c
new file mode 100644
index 0000000..95e00d7
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_DecodeVLCZigzag_IntraDCVLC.c
@@ -0,0 +1,170 @@
+/**
+ * 
+ * File Name:  omxVCM4P2_DecodeVLCZigzag_IntraDCVLC.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Description: 
+ * Contains modules for zigzag scanning and VLC decoding
+ * for intra block.
+ *
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armVC.h"
+#include "armCOMM_Bitstream.h"
+#include "armCOMM.h"
+#include "armVCM4P2_Huff_Tables_VLC.h"
+#include "armVCM4P2_ZigZag_Tables.h"
+
+
+
+
+/**
+ * Function:  omxVCM4P2_DecodeVLCZigzag_IntraDCVLC   (6.2.5.2.2)
+ *
+ * Description:
+ * Performs VLC decoding and inverse zigzag scan of AC and DC coefficients 
+ * for one intra block.  Two versions of the function (DCVLC and ACVLC) are 
+ * provided in order to support the two different methods of processing DC 
+ * coefficients, as described in [ISO14496-2], subclause 7.4.1.4,  Intra DC 
+ * Coefficient Decoding for the Case of Switched VLC Encoding.  
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - pointer to the pointer to the current byte in the 
+ *            bitstream buffer 
+ *   pBitOffset - pointer to the bit position in the current byte referenced 
+ *            by *ppBitStream.  The parameter *pBitOffset is valid in the 
+ *            range [0-7]. 
+ *            Bit Position in one byte:  |Most      Least| 
+ *                    *pBitOffset        |0 1 2 3 4 5 6 7| 
+ *   predDir - AC prediction direction; used to select the zigzag scan 
+ *            pattern; takes one of the following values: 
+ *            -  OMX_VC_NONE - AC prediction not used; 
+ *                             performs classical zigzag scan. 
+ *            -  OMX_VC_HORIZONTAL - Horizontal prediction; 
+ *                             performs alternate-vertical zigzag scan; 
+ *            -  OMX_VC_VERTICAL - Vertical prediction; 
+ *                             performs alternate-horizontal zigzag scan. 
+ *   shortVideoHeader - binary flag indicating presence of 
+ *            short_video_header; escape modes 0-3 are used if 
+ *            shortVideoHeader==0, and escape mode 4 is used when 
+ *            shortVideoHeader==1. 
+ *   videoComp - video component type (luminance or chrominance) of the 
+ *            current block 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after the block is decoded such 
+ *            that it points to the current byte in the bit stream buffer 
+ *   pBitOffset - *pBitOffset is updated such that it points to the current 
+ *            bit position in the byte pointed by *ppBitStream 
+ *   pDst - pointer to the coefficient buffer of current block; must be 
+ *            4-byte aligned. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments, if:
+ *    -    At least one of the following pointers is NULL: 
+ *         ppBitStream, *ppBitStream, pBitOffset, pDst
+ *    -    *pBitOffset exceeds [0,7]
+ *    -    preDir exceeds [0,2]
+ *    -    pDst is not 4-byte aligned 
+ *    OMX_Sts_Err - if:
+ *    -    In DecodeVLCZigzag_IntraDCVLC, dc_size > 12 
+ *    -    At least one of mark bits equals zero 
+ *    -    Illegal stream encountered; code cannot be located in VLC table 
+ *    -    Forbidden code encountered in the VLC FLC table. 
+ *    -    The number of coefficients is greater than 64 
+ *
+ */
+
+OMXResult omxVCM4P2_DecodeVLCZigzag_IntraDCVLC(
+     const OMX_U8 ** ppBitStream,
+     OMX_INT * pBitOffset,
+     OMX_S16 * pDst,
+     OMX_U8 predDir,
+     OMX_INT shortVideoHeader,
+     OMXVCM4P2VideoComponent videoComp
+)
+{
+    /* Dummy initilaization to remove compilation error */
+    OMX_S8  DCValueSize = 0;
+    OMX_U16 powOfSize, fetchDCbits;
+    OMX_U8 start = 1;
+
+    /* Argument error checks */
+    armRetArgErrIf(ppBitStream == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(*ppBitStream == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pBitOffset == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pDst == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(!armIs4ByteAligned(pDst), OMX_Sts_BadArgErr);
+    armRetArgErrIf((*pBitOffset < 0) || (*pBitOffset > 7), OMX_Sts_BadArgErr);
+    armRetArgErrIf((predDir > 2), OMX_Sts_BadArgErr);
+
+    /* Insert the code into the bitstream */
+    if (videoComp == OMX_VC_LUMINANCE)
+    {
+        DCValueSize = armUnPackVLC32(ppBitStream,
+                            pBitOffset, armVCM4P2_aIntraDCLumaIndex);
+    }
+    else if (videoComp == OMX_VC_CHROMINANCE)
+    {
+        DCValueSize = armUnPackVLC32(ppBitStream,
+                            pBitOffset, armVCM4P2_aIntraDCChromaIndex);
+    }
+    armRetDataErrIf(DCValueSize == -1, OMX_Sts_Err);
+    armRetDataErrIf(DCValueSize > 12, OMX_Sts_Err);
+
+
+    if (DCValueSize == 0)
+    {
+        pDst[0] = 0;
+    }
+    else
+    {
+        fetchDCbits = (OMX_U16) armGetBits(ppBitStream, pBitOffset, \
+                                           DCValueSize);
+
+        if ( (fetchDCbits >> (DCValueSize - 1)) == 0)
+        {
+            /* calulate pow */
+            powOfSize = (1 << DCValueSize);
+
+            pDst[0] =  (OMX_S16) (fetchDCbits ^ (powOfSize - 1));
+            pDst[0] = -pDst[0];
+        }
+        else
+        {
+            pDst[0] = fetchDCbits;
+        }
+
+        if (DCValueSize > 8)
+        {
+            /* reading and checking the marker bit*/
+            armRetDataErrIf (armGetBits(ppBitStream, pBitOffset, 1) == 0, \
+                             OMX_Sts_Err);
+        }
+    }
+
+    return armVCM4P2_DecodeVLCZigzag_Intra(
+                ppBitStream,
+                pBitOffset,
+                pDst,
+                predDir,
+                shortVideoHeader,
+                start);
+}
+
+/* End of file */
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_EncodeMV.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_EncodeMV.c
new file mode 100644
index 0000000..def2b6d
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_EncodeMV.c
@@ -0,0 +1,212 @@
+/**
+ * 
+ * File Name:  omxVCM4P2_EncodeMV.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Description: 
+ * Contains module for predicting MV of MB
+ *
+ */ 
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armCOMM_Bitstream.h"
+#include "armVCM4P2_Huff_Tables_VLC.h"
+
+
+
+/**
+ * Function:  omxVCM4P2_EncodeMV   (6.2.4.5.4)
+ *
+ * Description:
+ * Predicts a motion vector for the current macroblock, encodes the 
+ * difference, and writes the output to the stream buffer. The input MVs 
+ * pMVCurMB, pSrcMVLeftMB, pSrcMVUpperMB, and pSrcMVUpperRightMB should lie 
+ * within the ranges associated with the input parameter fcodeForward, as 
+ * described in [ISO14496-2], subclause 7.6.3.  This function provides a 
+ * superset of the functionality associated with the function 
+ * omxVCM4P2_FindMVpred. 
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - double pointer to the current byte in the bitstream buffer 
+ *   pBitOffset - index of the first free (next available) bit in the stream 
+ *            buffer referenced by *ppBitStream, valid in the range 0 to 7. 
+ *   pMVCurMB - pointer to the current macroblock motion vector; a value of 
+ *            NULL indicates unavailability. 
+ *   pSrcMVLeftMB - pointer to the source left macroblock motion vector; a 
+ *            value of  NULLindicates unavailability. 
+ *   pSrcMVUpperMB - pointer to source upper macroblock motion vector; a 
+ *            value of NULL indicates unavailability. 
+ *   pSrcMVUpperRightMB - pointer to source upper right MB motion vector; a 
+ *            value of NULL indicates unavailability. 
+ *   fcodeForward - an integer with values from 1 to 7; used in encoding 
+ *            motion vectors related to search range, as described in 
+ *            [ISO14496-2], subclause 7.6.3. 
+ *   MBType - macro block type, valid in the range 0 to 5 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - updated pointer to the current byte in the bit stream 
+ *            buffer 
+ *   pBitOffset - updated index of the next available bit position in stream 
+ *            buffer referenced by *ppBitStream 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments 
+ *    -    At least one of the following pointers is NULL: ppBitStream, 
+ *              *ppBitStream, pBitOffset, pMVCurMB 
+ *    -    *pBitOffset < 0, or *pBitOffset >7. 
+ *    -    fcodeForward <= 0, or fcodeForward > 7, or MBType < 0. 
+ *
+ */
+
+OMXResult omxVCM4P2_EncodeMV(
+     OMX_U8 **ppBitStream,
+     OMX_INT *pBitOffset,
+     const OMXVCMotionVector * pMVCurMB,
+     const OMXVCMotionVector * pSrcMVLeftMB,
+     const OMXVCMotionVector * pSrcMVUpperMB,
+     const OMXVCMotionVector * pSrcMVUpperRightMB,
+     OMX_INT fcodeForward,
+     OMXVCM4P2MacroblockType MBType
+)
+{
+    OMXVCMotionVector dstMVPred, diffMV;
+    OMXVCMotionVector dstMVPredME[12];
+    /* Initialized to remove compilation warning */
+    OMX_INT iBlk, i, count = 1;
+    OMX_S32 mvHorResidual, mvVerResidual, mvHorData, mvVerData;
+    OMX_U8 scaleFactor, index;
+
+    /* Argument error checks */
+    armRetArgErrIf(ppBitStream == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(*ppBitStream == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pBitOffset == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pMVCurMB == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(((*pBitOffset < 0) || (*pBitOffset > 7)), OMX_Sts_BadArgErr);
+    armRetArgErrIf(((fcodeForward < 1) || (fcodeForward > 7)), \
+                    OMX_Sts_BadArgErr);
+    
+    if ((MBType == OMX_VC_INTRA) ||
+        (MBType == OMX_VC_INTRA_Q)
+       )
+    {
+        /* No candidate vectors hence make them zero */
+        for (i = 0; i < 12; i++)
+        {
+            dstMVPredME[i].dx = 0;
+            dstMVPredME[i].dy = 0;
+        }
+
+        return OMX_Sts_NoErr;
+    }
+
+    if ((MBType == OMX_VC_INTER4V) || (MBType == OMX_VC_INTER4V_Q))
+    {
+        count = 4;
+    }
+    else if ((MBType == OMX_VC_INTER) || (MBType == OMX_VC_INTER_Q))
+    {
+        count = 1;
+    }
+
+    /* Calculating the scale factor */
+    scaleFactor = 1 << (fcodeForward -1);
+
+    for (iBlk = 0; iBlk < count; iBlk++)
+    {
+
+        /* Find the predicted vector */
+        omxVCM4P2_FindMVpred (
+            pMVCurMB,
+            pSrcMVLeftMB,
+            pSrcMVUpperMB,
+            pSrcMVUpperRightMB,
+            &dstMVPred,
+            dstMVPredME,
+            iBlk );
+
+        /* Calculating the differential motion vector (diffMV) */
+        diffMV.dx = pMVCurMB[iBlk].dx - dstMVPred.dx;
+        diffMV.dy = pMVCurMB[iBlk].dy - dstMVPred.dy;
+
+        /* Calculating the mv_data and mv_residual for Horizantal MV */
+        if (diffMV.dx == 0)
+        {
+            mvHorResidual = 0;
+            mvHorData = 0;
+        }
+        else
+        {
+            mvHorResidual = ( armAbs(diffMV.dx) - 1) % scaleFactor;
+            mvHorData = (armAbs(diffMV.dx) - mvHorResidual + (scaleFactor - 1))
+                     / scaleFactor;
+            if (diffMV.dx < 0)
+            {
+                mvHorData = -mvHorData;
+            }
+        }
+
+        /* Calculating the mv_data and mv_residual for Vertical MV */
+        if (diffMV.dy == 0)
+        {
+            mvVerResidual = 0;
+            mvVerData = 0;
+        }
+        else
+        {
+            mvVerResidual = ( armAbs(diffMV.dy) - 1) % scaleFactor;
+            mvVerData = (armAbs(diffMV.dy) - mvVerResidual + (scaleFactor - 1))
+                     / scaleFactor;
+            if (diffMV.dy < 0)
+            {
+                mvVerData = -mvVerData;
+            }
+        }
+
+        /* Huffman encoding */
+
+        /* The index is actually calculate as
+           index = ((float) (mvHorData/2) + 16) * 2,
+           meaning the MV data is halfed and then normalized
+           to begin with zero and then doubled to take care of indexing
+           the fractional part included */
+        index = mvHorData + 32;
+        armPackVLC32 (ppBitStream, pBitOffset, armVCM4P2_aVlcMVD[index]);
+        if ((fcodeForward > 1) && (diffMV.dx != 0))
+        {
+            armPackBits (ppBitStream, pBitOffset, mvHorResidual, (fcodeForward -1));
+        }
+
+        /* The index is actually calculate as
+           index = ((float) (mvVerData/2) + 16) * 2,
+           meaning the MV data is halfed and then normalized
+           to begin with zero and then doubled to take care of indexing
+           the fractional part included */
+        index = mvVerData + 32;
+        armPackVLC32 (ppBitStream, pBitOffset, armVCM4P2_aVlcMVD[index]);
+        if ((fcodeForward > 1) && (diffMV.dy != 0))
+        {
+            armPackBits (ppBitStream, pBitOffset, mvVerResidual, (fcodeForward -1));
+        }
+    }
+
+    return OMX_Sts_NoErr;
+}
+
+
+/* End of file */
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_EncodeVLCZigzag_Inter.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_EncodeVLCZigzag_Inter.c
new file mode 100644
index 0000000..b6c73ea
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_EncodeVLCZigzag_Inter.c
@@ -0,0 +1,112 @@
+/**
+ * 
+ * File Name:  omxVCM4P2_EncodeVLCZigzag_Inter.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Description: 
+ * Contains modules for zigzag scanning and VLC encoding
+ * for inter block.
+ *
+ */ 
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armVC.h"
+#include "armCOMM_Bitstream.h"
+#include "armCOMM.h"
+#include "armVCM4P2_Huff_Tables_VLC.h"
+#include "armVCM4P2_ZigZag_Tables.h"
+
+
+
+/**
+ * Function:  omxVCM4P2_EncodeVLCZigzag_Inter   (6.2.4.5.3)
+ *
+ * Description:
+ * Performs classical zigzag scanning and VLC encoding for one inter block. 
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - pointer to the pointer to the current byte in the bit 
+ *            stream 
+ *   pBitOffset - pointer to the bit position in the byte pointed by 
+ *            *ppBitStream. Valid within 0 to 7 
+ *   pQDctBlkCoef - pointer to the quantized DCT coefficient 
+ *   pattern - block pattern which is used to decide whether this block is 
+ *            encoded 
+ *   shortVideoHeader - binary flag indicating presence of 
+ *            short_video_header; escape modes 0-3 are used if 
+ *            shortVideoHeader==0, and escape mode 4 is used when 
+ *            shortVideoHeader==1. 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after the block is encoded so that 
+ *            it points to the current byte in the bit stream buffer. 
+ *   pBitOffset - *pBitOffset is updated so that it points to the current bit 
+ *            position in the byte pointed by *ppBitStream. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - Bad arguments 
+ *    -    At least one of the pointers: is NULL: ppBitStream, *ppBitStream, 
+ *              pBitOffset, pQDctBlkCoef 
+ *    -   *pBitOffset < 0, or *pBitOffset >7. 
+ *
+ */
+OMXResult omxVCM4P2_EncodeVLCZigzag_Inter(
+     OMX_U8 **ppBitStream,
+     OMX_INT * pBitOffset,
+     const OMX_S16 *pQDctBlkCoef,
+     OMX_U8 pattern,
+	 OMX_INT shortVideoHeader
+)
+{
+    OMX_U8 start = 0;
+    const OMX_U8  *pZigzagTable = armVCM4P2_aClassicalZigzagScan;
+
+    /* Argument error checks */
+    armRetArgErrIf(ppBitStream == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(*ppBitStream == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pBitOffset == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pQDctBlkCoef == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf((*pBitOffset < 0) || (*pBitOffset >7), OMX_Sts_BadArgErr);
+
+    if (pattern)
+    {
+        armVCM4P2_PutVLCBits (
+              ppBitStream,
+              pBitOffset,
+              pQDctBlkCoef,
+              shortVideoHeader,
+              start,
+              26,
+              40,
+              10,
+              1,
+              armVCM4P2_InterL0RunIdx,
+              armVCM4P2_InterVlcL0,
+			  armVCM4P2_InterL1RunIdx,
+              armVCM4P2_InterVlcL1,
+              armVCM4P2_InterL0LMAX,
+              armVCM4P2_InterL1LMAX,
+              armVCM4P2_InterL0RMAX,
+              armVCM4P2_InterL1RMAX,
+              pZigzagTable
+        );
+    } /* Pattern check ends*/
+
+    return OMX_Sts_NoErr;
+
+}
+
+/* End of file */
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_EncodeVLCZigzag_IntraACVLC.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_EncodeVLCZigzag_IntraACVLC.c
new file mode 100644
index 0000000..d047942
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_EncodeVLCZigzag_IntraACVLC.c
@@ -0,0 +1,97 @@
+/**
+ * 
+ * File Name:  omxVCM4P2_EncodeVLCZigzag_IntraACVLC.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Description: 
+ * Contains modules for zigzag scanning and VLC encoding
+ * for intra block.
+ *
+ */ 
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armVC.h"
+
+
+/**
+ * Function:  omxVCM4P2_EncodeVLCZigzag_IntraACVLC   (6.2.4.5.2)
+ *
+ * Description:
+ * Performs zigzag scan and VLC encoding of AC and DC coefficients for one 
+ * intra block.  Two versions of the function (DCVLC and ACVLC) are provided 
+ * in order to support the two different methods of processing DC 
+ * coefficients, as described in [ISO14496-2], subclause 7.4.1.4,  Intra DC 
+ * Coefficient Decoding for the Case of Switched VLC Encoding.  
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - double pointer to the current byte in the bitstream 
+ *   pBitOffset - pointer to the bit position in the byte pointed by 
+ *            *ppBitStream. Valid within 0 to 7. 
+ *   pQDctBlkCoef - pointer to the quantized DCT coefficient 
+ *   predDir - AC prediction direction, which is used to decide the zigzag 
+ *            scan pattern; takes one of the following values: 
+ *            -  OMX_VC_NONE - AC prediction not used.  
+ *                             Performs classical zigzag scan. 
+ *            -  OMX_VC_HORIZONTAL - Horizontal prediction.  
+ *                             Performs alternate-vertical zigzag scan. 
+ *            -  OMX_VC_VERTICAL - Vertical prediction.  
+ *                             Performs alternate-horizontal zigzag scan. 
+ *   pattern - block pattern which is used to decide whether this block is 
+ *            encoded 
+ *   shortVideoHeader - binary flag indicating presence of 
+ *            short_video_header; escape modes 0-3 are used if 
+ *            shortVideoHeader==0, and escape mode 4 is used when 
+ *            shortVideoHeader==1. 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after the block is encoded, so 
+ *            that it points to the current byte in the bit stream buffer. 
+ *   pBitOffset - *pBitOffset is updated so that it points to the current bit 
+ *            position in the byte pointed by *ppBitStream. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - Bad arguments:
+ *    -    At least one of the following pointers is NULL: ppBitStream, 
+ *              *ppBitStream, pBitOffset, pQDctBlkCoef. 
+ *    -   *pBitOffset < 0, or *pBitOffset >7. 
+ *    -    PredDir is not one of: OMX_VC_NONE, OMX_VC_HORIZONTAL, or 
+ *         OMX_VC_VERTICAL. 
+ *    -    VideoComp is not one component of enum OMXVCM4P2VideoComponent. 
+ *
+ */
+
+OMXResult omxVCM4P2_EncodeVLCZigzag_IntraACVLC(
+     OMX_U8 **ppBitStream,
+     OMX_INT *pBitOffset,
+     const OMX_S16 *pQDctBlkCoef,
+     OMX_U8 predDir,
+     OMX_U8 pattern,
+     OMX_INT shortVideoHeader
+)
+{
+    OMX_U8 start = 0;
+
+    return armVCM4P2_EncodeVLCZigzag_Intra(
+     ppBitStream,
+     pBitOffset,
+     pQDctBlkCoef,
+     predDir,
+     pattern,
+     shortVideoHeader,
+     start);
+}
+
+/* End of file */
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_EncodeVLCZigzag_IntraDCVLC.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_EncodeVLCZigzag_IntraDCVLC.c
new file mode 100644
index 0000000..c57acd2
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_EncodeVLCZigzag_IntraDCVLC.c
@@ -0,0 +1,160 @@
+/**
+ * 
+ * File Name:  omxVCM4P2_EncodeVLCZigzag_IntraDCVLC.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Description: 
+ * Contains modules for zigzag scanning and VLC encoding
+ * for intra block.
+ *
+ */ 
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armVC.h"
+#include "armCOMM_Bitstream.h"
+#include "armCOMM.h"
+#include "armVCM4P2_Huff_Tables_VLC.h"
+#include "armVCM4P2_ZigZag_Tables.h"
+
+
+
+/**
+ * Function:  omxVCM4P2_EncodeVLCZigzag_IntraDCVLC   (6.2.4.5.2)
+ *
+ * Description:
+ * Performs zigzag scan and VLC encoding of AC and DC coefficients for one 
+ * intra block.  Two versions of the function (DCVLC and ACVLC) are provided 
+ * in order to support the two different methods of processing DC 
+ * coefficients, as described in [ISO14496-2], subclause 7.4.1.4, "Intra DC 
+ * Coefficient Decoding for the Case of Switched VLC Encoding".  
+ *
+ * Input Arguments:
+ *   
+ *   ppBitStream - double pointer to the current byte in the bitstream 
+ *   pBitOffset - pointer to the bit position in the byte pointed by 
+ *            *ppBitStream. Valid within 0 to 7. 
+ *   pQDctBlkCoef - pointer to the quantized DCT coefficient 
+ *   predDir - AC prediction direction, which is used to decide the zigzag 
+ *            scan pattern; takes one of the following values: 
+ *            -  OMX_VC_NONE - AC prediction not used.  
+ *                             Performs classical zigzag scan. 
+ *            -  OMX_VC_HORIZONTAL - Horizontal prediction.  
+ *                             Performs alternate-vertical zigzag scan. 
+ *            -  OMX_VC_VERTICAL - Vertical prediction.  
+ *                             Performs alternate-horizontal zigzag scan. 
+ *   pattern - block pattern which is used to decide whether this block is 
+ *            encoded 
+ *   shortVideoHeader - binary flag indicating presence of 
+ *            short_video_header; escape modes 0-3 are used if 
+ *            shortVideoHeader==0, and escape mode 4 is used when 
+ *            shortVideoHeader==1. 
+ *   videoComp - video component type (luminance, chrominance) of the current 
+ *            block 
+ *
+ * Output Arguments:
+ *   
+ *   ppBitStream - *ppBitStream is updated after the block is encoded, so 
+ *            that it points to the current byte in the bit stream buffer. 
+ *   pBitOffset - *pBitOffset is updated so that it points to the current bit 
+ *            position in the byte pointed by *ppBitStream. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - Bad arguments:
+ *    -    At least one of the following pointers is NULL: ppBitStream, 
+ *              *ppBitStream, pBitOffset, pQDctBlkCoef. 
+ *    -   *pBitOffset < 0, or *pBitOffset >7. 
+ *    -    PredDir is not one of: OMX_VC_NONE, OMX_VC_HORIZONTAL, or 
+ *         OMX_VC_VERTICAL. 
+ *    -    VideoComp is not one component of enum OMXVCM4P2VideoComponent. 
+ *
+ */
+
+OMXResult omxVCM4P2_EncodeVLCZigzag_IntraDCVLC(
+     OMX_U8 **ppBitStream,
+     OMX_INT *pBitOffset,
+     const OMX_S16 *pQDctBlkCoef,
+     OMX_U8 predDir,
+     OMX_U8 pattern,
+     OMX_INT shortVideoHeader,
+     OMXVCM4P2VideoComponent videoComp
+)
+{
+    OMX_S16 dcValue, powOfSize;
+    OMX_U8  DCValueSize, start = 1;
+    OMX_U16 absDCValue;
+
+    /* Argument error checks */
+    armRetArgErrIf(ppBitStream == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(*ppBitStream == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pBitOffset == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pQDctBlkCoef == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf((*pBitOffset < 0) || (*pBitOffset >7), OMX_Sts_BadArgErr);
+	armRetArgErrIf((videoComp != OMX_VC_LUMINANCE) && (videoComp != OMX_VC_CHROMINANCE), OMX_Sts_BadArgErr);
+	armRetArgErrIf((predDir != OMX_VC_NONE) && (predDir != OMX_VC_HORIZONTAL) && (predDir != OMX_VC_VERTICAL) , OMX_Sts_BadArgErr);
+    
+    if (pattern)
+    {
+        dcValue = pQDctBlkCoef[0];
+        absDCValue = armAbs(dcValue);
+
+        /* Find the size */
+        DCValueSize = armLogSize (absDCValue);
+        absDCValue = armAbs(dcValue);
+
+        /* Insert the code into the bitstream */
+        if (videoComp == OMX_VC_LUMINANCE)
+        {
+
+            armPackVLC32 (ppBitStream, pBitOffset,
+                          armVCM4P2_aIntraDCLumaIndex[DCValueSize]);
+        }
+        else if (videoComp == OMX_VC_CHROMINANCE)
+        {
+
+            armPackVLC32 (ppBitStream, pBitOffset,
+                          armVCM4P2_aIntraDCChromaIndex[DCValueSize]);
+        }
+
+        /* Additional code generation in case of negative
+           dc value the additional */
+        if (DCValueSize > 0)
+        {
+            if (dcValue < 0)
+            {
+                /* calulate 2 pow */
+                powOfSize = (1 << DCValueSize);
+
+                absDCValue =  absDCValue ^ (powOfSize - 1);
+            }
+            armPackBits(ppBitStream, pBitOffset, (OMX_U32)absDCValue, \
+                        DCValueSize);
+
+            if (DCValueSize > 8)
+            {
+                armPackBits(ppBitStream, pBitOffset, 1, 1);
+            }
+        }
+    }
+
+    return armVCM4P2_EncodeVLCZigzag_Intra(
+                ppBitStream,
+                pBitOffset,
+                pQDctBlkCoef,
+                predDir,
+                pattern,
+                shortVideoHeader,
+                start);
+}
+
+/* End of file */
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_FindMVpred.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_FindMVpred.c
new file mode 100644
index 0000000..a0cff48
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_FindMVpred.c
@@ -0,0 +1,188 @@
+/**
+ * 
+ * File Name:  omxVCM4P2_FindMVpred.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Description: 
+ * Contains module for predicting MV of MB
+ *
+ */
+  
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+
+/**
+ * Function:  omxVCM4P2_FindMVpred   (6.2.3.1.1)
+ *
+ * Description:
+ * Predicts a motion vector for the current block using the procedure 
+ * specified in [ISO14496-2], subclause 7.6.5.  The resulting predicted MV is 
+ * returned in pDstMVPred. If the parameter pDstMVPredME if is not NULL then 
+ * the set of three MV candidates used for prediction is also returned, 
+ * otherwise pDstMVPredMEis NULL upon return. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcMVCurMB - pointer to the MV buffer associated with the current Y 
+ *            macroblock; a value of NULL indicates unavailability. 
+ *   pSrcCandMV1 - pointer to the MV buffer containing the 4 MVs associated 
+ *            with the MB located to the left of the current MB; set to NULL 
+ *            if there is no MB to the left. 
+ *   pSrcCandMV2 - pointer to the MV buffer containing the 4 MVs associated 
+ *            with the MB located above the current MB; set to NULL if there 
+ *            is no MB located above the current MB. 
+ *   pSrcCandMV3 - pointer to the MV buffer containing the 4 MVs associated 
+ *            with the MB located to the right and above the current MB; set 
+ *            to NULL if there is no MB located to the above-right. 
+ *   iBlk - the index of block in the current macroblock 
+ *   pDstMVPredME - MV candidate return buffer;  if set to NULL then 
+ *            prediction candidate MVs are not returned and pDstMVPredME will 
+ *            be NULL upon function return; if pDstMVPredME is non-NULL then it 
+ *            must point to a buffer containing sufficient space for three 
+ *            return MVs. 
+ *
+ * Output Arguments:
+ *   
+ *   pDstMVPred - pointer to the predicted motion vector 
+ *   pDstMVPredME - if non-NULL upon input then pDstMVPredME  points upon 
+ *            return to a buffer containing the three motion vector candidates 
+ *            used for prediction as specified in [ISO14496-2], subclause 
+ *            7.6.5, otherwise if NULL upon input then pDstMVPredME is NULL 
+ *            upon output. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned under any of the following 
+ *              conditions: 
+ *    -    the pointer pDstMVPred is NULL 
+ *    -    the parameter iBlk does not fall into the range 0 <= iBlk<=3 
+ *
+ */
+
+OMXResult omxVCM4P2_FindMVpred(
+     const OMXVCMotionVector* pSrcMVCurMB,
+     const OMXVCMotionVector* pSrcCandMV1,
+     const OMXVCMotionVector* pSrcCandMV2,
+     const OMXVCMotionVector* pSrcCandMV3,
+     OMXVCMotionVector* pDstMVPred,
+     OMXVCMotionVector* pDstMVPredME,
+     OMX_INT iBlk
+ )
+{
+    OMXVCMotionVector CandMV;
+	const OMXVCMotionVector *pCandMV1;
+    const OMXVCMotionVector *pCandMV2;
+    const OMXVCMotionVector *pCandMV3;
+    
+    /* Argument error checks */
+	armRetArgErrIf(iBlk!=0 && pSrcMVCurMB == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pDstMVPred == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf((iBlk < 0) || (iBlk > 3), OMX_Sts_BadArgErr); 
+
+    CandMV.dx = CandMV.dy = 0;
+	/* Based on the position of the block extract the motion vectors and
+       the tranperancy status */
+   
+    
+    /* Set the default value for these to be used if pSrcCandMV[1|2|3] == NULL */
+    pCandMV1 = pCandMV2 = pCandMV3 = &CandMV;
+
+    
+    switch (iBlk)
+    {
+        case 0:
+        {
+            if(pSrcCandMV1 != NULL)
+            {
+			    pCandMV1 = &pSrcCandMV1[1];
+			}
+			if(pSrcCandMV2 != NULL)
+            {
+				pCandMV2 = &pSrcCandMV2[2];
+			}
+			if(pSrcCandMV3 != NULL)
+            {
+				pCandMV3 = &pSrcCandMV3[2];
+			}
+			if ((pSrcCandMV1 == NULL) && (pSrcCandMV2 == NULL))
+            {
+                pCandMV1 = pCandMV2 = pCandMV3;
+            }
+            else if((pSrcCandMV1 == NULL) && (pSrcCandMV3 == NULL))
+            {
+                pCandMV1 = pCandMV3 = pCandMV2;
+            }
+            else if((pSrcCandMV2 == NULL) && (pSrcCandMV3 == NULL))
+            {
+                pCandMV2 = pCandMV3 = pCandMV1;
+            }
+            break;
+        }
+        case 1:
+        {
+            pCandMV1 = &pSrcMVCurMB[0];
+			if(pSrcCandMV2 != NULL)
+            {
+				pCandMV2 = &pSrcCandMV2[3];
+			}
+			if(pSrcCandMV3 != NULL)
+            {
+				pCandMV3 = &pSrcCandMV3[2];
+			}
+			if((pSrcCandMV2 == NULL) && (pSrcCandMV3 == NULL))
+            {
+                pCandMV2 = pCandMV3 = pCandMV1;
+            }
+            break;
+        }
+        case 2:
+        {
+            if(pSrcCandMV1 != NULL)
+            {
+				pCandMV1 = &pSrcCandMV1[3];
+			}
+			pCandMV2 = &pSrcMVCurMB[0];
+			pCandMV3 = &pSrcMVCurMB[1];
+			break;
+        }
+        case 3:
+        {
+            pCandMV1 = &pSrcMVCurMB[2];
+			pCandMV2 = &pSrcMVCurMB[0];
+			pCandMV3 = &pSrcMVCurMB[1];
+			break;
+        }
+    }
+
+    /* Find the median of the 3 candidate MV's */
+    pDstMVPred->dx = armMedianOf3 (pCandMV1->dx, pCandMV2->dx, pCandMV3->dx);
+    pDstMVPred->dy = armMedianOf3 (pCandMV1->dy, pCandMV2->dy, pCandMV3->dy);
+        
+    if (pDstMVPredME != NULL)
+    {
+        /* Store the candidate MV's into the pDstMVPredME, these can be used
+           in the fast algorithm if implemented */
+        pDstMVPredME[0].dx = pCandMV1->dx;
+        pDstMVPredME[0].dy = pCandMV1->dy;
+        pDstMVPredME[1].dx = pCandMV2->dx;
+        pDstMVPredME[1].dy = pCandMV2->dy;
+        pDstMVPredME[2].dx = pCandMV3->dx;
+        pDstMVPredME[2].dy = pCandMV3->dy;
+    }
+
+    return OMX_Sts_NoErr;
+}
+
+
+/* End of file */
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_IDCT8x8blk.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_IDCT8x8blk.c
new file mode 100644
index 0000000..1886d92
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_IDCT8x8blk.c
@@ -0,0 +1,92 @@
+/**
+ * 
+ * File Name:  omxVCM4P2_IDCT8x8blk.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Description:
+ * Contains modules for 8x8 block IDCT
+ * 
+ */
+
+
+#include <math.h>
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVCM4P2_DCT_Table.h"
+
+/**
+ * Function:  omxVCM4P2_IDCT8x8blk   (6.2.3.2.1)
+ *
+ * Description:
+ * Computes a 2D inverse DCT for a single 8x8 block, as defined in 
+ * [ISO14496-2]. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - pointer to the start of the linearly arranged IDCT input buffer; 
+ *            must be aligned on a 16-byte boundary.  According to 
+ *            [ISO14496-2], the input coefficient values should lie within the 
+ *            range [-2048, 2047]. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - pointer to the start of the linearly arranged IDCT output buffer; 
+ *            must be aligned on a 16-byte boundary. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments:
+ *    -    pSrc or pDst is NULL. 
+ *    -    pSrc or pDst is not 16-byte aligned. 
+ *
+ */
+OMXResult omxVCM4P2_IDCT8x8blk (const OMX_S16 *pSrc, OMX_S16 *pDst)
+{
+    OMX_INT x, y, u, v;
+
+    /* Argument error checks */
+    armRetArgErrIf(pSrc == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(!armIs16ByteAligned(pSrc), OMX_Sts_BadArgErr);
+    armRetArgErrIf(pDst == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(!armIs16ByteAligned(pDst), OMX_Sts_BadArgErr);
+
+    for (x = 0; x < 8; x++)
+    {
+        for (y = 0; y < 8; y++)
+        {
+            OMX_F64 sum = 0.0;
+            for (u = 0; u < 8; u++)
+            {
+                for (v = 0; v < 8; v++)
+                {
+                    sum += pSrc[(u * 8) + v] *
+                        armVCM4P2_preCalcDCTCos[x][u] *
+                        armVCM4P2_preCalcDCTCos[y][v];
+                }
+            }
+            pDst[(x * 8) + y] = (OMX_S16) floor(sum + 0.5);
+
+            /* Saturate to [-256, 255] */
+            pDst[(x * 8) + y] = armClip (
+                                            -256,
+                                            255,
+                                            pDst[(x * 8) + y]);
+        }
+    }
+
+    return OMX_Sts_NoErr;
+}
+
+/* End of file */
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_MCReconBlock.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_MCReconBlock.c
new file mode 100644
index 0000000..7b3faee
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_MCReconBlock.c
@@ -0,0 +1,357 @@
+/**
+ * 
+ * File Name:  omxVCM4P2_MCReconBlock.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ * Description:
+ * MPEG4 motion compensation prediction for an 8x8 block using 
+ * interpolation
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+
+/**
+ * Function: armVCM4P2_HalfPelVer
+ *
+ * Description:
+ * Performs half pel motion compensation for an 8x8 block using vertical 
+ * interpolation described in ISO/IEC 14496-2, subclause 7.6.2.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] pSrc        pointer to the block in the reference plane.
+ * [in] srcStep     distance between the start of consecutive lines
+ *                  in the reference plane, in bytes; must be a multiple
+ *                  of 8.
+ * [in] rndVal      rounding control parameter: 0 - disabled; 1 - enabled.
+ * [out] pDst       pointer to the linaer 8x8 destination buffer;
+ *
+ */
+static OMXVoid armVCM4P2_HalfPelVer(
+      const OMX_U8 *pSrc,
+      OMX_INT srcStep, 
+      OMX_U8 *pDst,
+      OMX_INT rndVal)
+{
+  const OMX_U8 *pTempSrc1;
+  const OMX_U8 *pTempSrc2;
+  OMX_INT y, x;
+  
+  pTempSrc1 = pSrc;  
+  pTempSrc2 = pSrc + srcStep;
+  srcStep -= 8;
+  for (y = 0; y < 8; y++)
+  {
+    for (x = 0; x < 8; x++)
+    {
+      *pDst++ = ((*pTempSrc1++ + *pTempSrc2++) + 1 - rndVal) >> 1;
+    }
+    pTempSrc1 += srcStep;
+    pTempSrc2 += srcStep;
+  }
+}
+
+/**
+ * Function: armVCM4P2_HalfPelHor
+ *
+ * Description:
+ * Performs half pel motion compensation for an 8x8 block using horizontal 
+ * interpolation described in ISO/IEC 14496-2, subclause 7.6.2.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] pSrc        pointer to the block in the reference plane.
+ * [in] srcStep     distance between the start of consecutive lines
+ *                  in the reference plane, in bytes; must be a multiple
+ *                  of 8.
+ * [in] rndVal      rounding control parameter: 0 - disabled; 1 - enabled.
+ * [out] pDst       pointer to the linaer 8x8 destination buffer;
+ *
+ */
+static OMXVoid armVCM4P2_HalfPelHor(
+      const OMX_U8 *pSrc,
+      OMX_INT srcStep, 
+      OMX_U8 *pDst,
+      OMX_INT rndVal)
+{
+  const OMX_U8 *pTempSrc1;
+  const OMX_U8 *pTempSrc2;
+  OMX_INT y, x;
+  
+  pTempSrc1 = pSrc;
+  pTempSrc2 = pTempSrc1 + 1;
+
+  srcStep -= 8;
+  for (y=0; y<8; y++)
+  {
+    for (x=0; x<8; x++)
+    {
+      *pDst++ = ((*pTempSrc1++ + *pTempSrc2++) + 1 - rndVal) >> 1;
+    }
+    pTempSrc1 += srcStep;
+    pTempSrc2 += srcStep;
+  }
+}
+
+
+/**
+ * Function: armVCM4P2_HalfPelVerHor
+ *
+ * Description:
+ * Performs half pel motion compensation for an 8x8 block using both 
+ * horizontal and vertical interpolation described in ISO/IEC 14496-2,
+ * subclause 7.6.2.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] pSrc        pointer to the block in the reference plane.
+ * [in] srcStep     distance between the start of consecutive lines
+ *                  in the reference plane, in bytes; must be a multiple
+ *                  of 8.
+ * [in] rndVal      rounding control parameter: 0 - disabled; 1 - enabled.
+ * [out] pDst       pointer to the linaer 8x8 destination buffer;
+ *
+ */
+static OMXVoid armVCM4P2_HalfPelVerHor(
+      const OMX_U8 *pSrc,
+      OMX_INT srcStep, 
+      OMX_U8 *pDst,
+      OMX_INT rndVal)
+{
+  const OMX_U8 *pTempSrc1;
+  const OMX_U8 *pTempSrc2;
+  const OMX_U8 *pTempSrc3;
+  const OMX_U8 *pTempSrc4;
+  OMX_INT y, x;
+
+  pTempSrc1 = pSrc;
+  pTempSrc2 = pSrc + srcStep;
+  pTempSrc3 = pSrc + 1;
+  pTempSrc4 = pSrc + srcStep + 1;
+
+  srcStep -= 8;
+  for (y=0; y<8; y++)
+  {
+    for (x=0; x<8; x++)
+	{
+	  *pDst++ = ((*pTempSrc1++ + *pTempSrc2++ + *pTempSrc3++ + *pTempSrc4++) + 
+	                  2 - rndVal) >> 2;
+	}
+    pTempSrc1 += srcStep;
+    pTempSrc2 += srcStep;
+    pTempSrc3 += srcStep;
+    pTempSrc4 += srcStep;
+  }
+}
+
+/**
+ * Function: armVCM4P2_MCReconBlock_NoRes
+ *
+ * Description:
+ * Do motion compensation and copy the result to the current block.
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] pSrc        pointer to the block in the reference plane.
+ * [in] srcStep     distance between the start of consecutive lines
+ *                  in the reference plane, in bytes; must be a multiple
+ *                  of 8.
+ * [in] dstStep     distance between the start of consecutive lines in the
+ *                  destination plane, in bytes; must be a multiple of 8.
+ * [in] predictType bilinear interpolation type, as defined in section 6.2.1.2.
+ * [in] rndVal      rounding control parameter: 0 - disabled; 1 - enabled.
+ * [out] pDst       pointer to the destination buffer; must be 8-byte aligned.
+ *                  If prediction residuals are added then output intensities
+ *                  are clipped to the range [0,255].
+ *
+ */
+static OMXVoid armVCM4P2_MCReconBlock_NoRes(
+      const OMX_U8 *pSrc, 
+      OMX_INT srcStep,
+      OMX_U8 *pDst,
+      OMX_INT dstStep)
+{
+    OMX_U8 x,y,count,index;
+    
+    /* Copying the ref 8x8 blk to the curr blk */
+    for (y = 0, count = 0, index = 0; y < 8; y++,index += (srcStep -8), count += (dstStep - 8))
+    {
+        for (x = 0; x < 8; x++, count++,index++)
+        {
+            pDst[count] = pSrc[index];
+        }       
+    }
+}
+
+/**
+ * Function: armVCM4P2_MCReconBlock_Res
+ *
+ * Description:
+ * Reconstructs INTER block by summing the motion compensation results
+ * and the results of the inverse transformation (prediction residuals).
+ * Output intensities are clipped to the range [0,255].
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in] pSrc        pointer to the block in the reference plane.
+ * [in] pSrcResidue pointer to a buffer containing the 16-bit prediction
+ *                  residuals. If the pointer is NULL,then no prediction
+ *                  is done, only motion compensation, i.e., the block is
+ *                  moved with interpolation.
+ * [in] dstStep     distance between the start of consecutive lines in the
+ *                  destination plane, in bytes; must be a multiple of 8.
+ * [out] pDst       pointer to the destination buffer; must be 8-byte aligned.
+ *                  If prediction residuals are added then output intensities
+ *                  are clipped to the range [0,255].
+ *
+ */
+static OMXVoid armVCM4P2_MCReconBlock_Res(
+      const OMX_U8 *pSrc, 
+      const OMX_S16 *pSrcResidue,
+      OMX_U8 *pDst,
+      OMX_INT dstStep)
+{
+      
+  OMX_U8 x,y;
+  OMX_INT temp;
+  
+  for(y = 0; y < 8; y++)
+  {
+    for(x = 0; x < 8; x++)
+    {
+      temp = pSrc[x] + pSrcResidue[x];         
+      pDst[x] = armClip(0,255,temp);
+    }
+    pDst += dstStep;
+    pSrc += 8;
+    pSrcResidue += 8;
+  }
+}
+
+/**
+ * Function:  omxVCM4P2_MCReconBlock   (6.2.5.5.1)
+ *
+ * Description:
+ * Performs motion compensation prediction for an 8x8 block using 
+ * interpolation described in [ISO14496-2], subclause 7.6.2. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - pointer to the block in the reference plane. 
+ *   srcStep - distance between the start of consecutive lines in the 
+ *            reference plane, in bytes; must be a multiple of 8. 
+ *   dstStep - distance between the start of consecutive lines in the 
+ *            destination plane, in bytes; must be a multiple of 8. 
+ *   pSrcResidue - pointer to a buffer containing the 16-bit prediction 
+ *            residuals; must be 16-byte aligned. If the pointer is NULL, then 
+ *            no prediction is done, only motion compensation, i.e., the block 
+ *            is moved with interpolation. 
+ *   predictType - bilinear interpolation type, as defined in section 
+ *            6.2.1.2. 
+ *   rndVal - rounding control parameter: 0 - disabled; 1 - enabled. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - pointer to the destination buffer; must be 8-byte aligned.  If 
+ *            prediction residuals are added then output intensities are 
+ *            clipped to the range [0,255]. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; returned under any of the following 
+ *              conditions: 
+ *    -    pDst is not 8-byte aligned. 
+ *    -    pSrcResidue is not 16-byte aligned. 
+ *    -    one or more of the following pointers is NULL: pSrc or pDst. 
+ *    -    either srcStep or dstStep is not a multiple of 8. 
+ *    -    invalid type specified for the parameter predictType. 
+ *    -    the parameter rndVal is not equal either to 0 or 1. 
+ *
+ */
+OMXResult omxVCM4P2_MCReconBlock(
+		const OMX_U8 *pSrc,
+		OMX_INT srcStep,
+		const OMX_S16 *pSrcResidue,
+		OMX_U8 *pDst, 
+		OMX_INT dstStep,
+		OMX_INT predictType,
+		OMX_INT rndVal)
+{
+    /* Definitions and Initializations*/
+    OMX_U8 pTempDst[64];
+    
+    /* Argument error checks */
+    armRetArgErrIf(pSrc == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pDst == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(!armIs8ByteAligned(pDst), OMX_Sts_BadArgErr);
+    armRetArgErrIf(!armIs16ByteAligned(pSrcResidue), OMX_Sts_BadArgErr);
+    armRetArgErrIf(((dstStep % 8) || (srcStep % 8)), OMX_Sts_BadArgErr);
+    armRetArgErrIf(((predictType != OMX_VC_INTEGER_PIXEL) &&
+                    (predictType != OMX_VC_HALF_PIXEL_X) &&
+                    (predictType != OMX_VC_HALF_PIXEL_Y) &&
+                    (predictType != OMX_VC_HALF_PIXEL_XY)
+                   ),OMX_Sts_BadArgErr); 
+    armRetArgErrIf(((rndVal != 0) && (rndVal != 1)),OMX_Sts_BadArgErr);
+    
+    switch(predictType)
+    {
+        case OMX_VC_INTEGER_PIXEL:
+                                   armVCM4P2_MCReconBlock_NoRes(pSrc,
+                                                                    srcStep,
+                                                                    &(pTempDst[0]),
+                                                                    8);
+                                   break;
+        case OMX_VC_HALF_PIXEL_X:
+                                   armVCM4P2_HalfPelHor(pSrc,
+                                                            srcStep,
+                                                            &(pTempDst[0]),
+                                                            rndVal);
+                                   break;
+        case OMX_VC_HALF_PIXEL_Y:
+                                   armVCM4P2_HalfPelVer(pSrc,
+                                                            srcStep,
+                                                            &(pTempDst[0]),
+                                                            rndVal);
+                                   break;
+        case OMX_VC_HALF_PIXEL_XY:
+                                   armVCM4P2_HalfPelVerHor(pSrc,
+                                                            srcStep,
+                                                            &(pTempDst[0]),
+                                                            rndVal);
+                                   break;
+    }
+    
+    if(pSrcResidue == NULL)
+    {
+      armVCM4P2_MCReconBlock_NoRes(&(pTempDst[0]),
+                                         8,
+                                         pDst,
+                                         dstStep);    
+    }
+    else
+    {
+      armVCM4P2_MCReconBlock_Res(&(pTempDst[0]),
+                                          pSrcResidue,
+                                          pDst,
+                                          dstStep);    
+    }
+    
+    return OMX_Sts_NoErr;
+}
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_MEGetBufSize.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_MEGetBufSize.c
new file mode 100644
index 0000000..a8e51da
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_MEGetBufSize.c
@@ -0,0 +1,70 @@
+/**
+ * 
+ * File Name:  omxVCM4P2_MEGetBufSize.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Description:
+ * Initialization modules for the vendor specific Motion Estimation structure.
+ * 
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armVC.h"
+#include "armCOMM.h"
+
+/**
+ * Function:  omxVCM4P2_MEGetBufSize   (6.2.4.1.1)
+ *
+ * Description:
+ * Computes the size, in bytes, of the vendor-specific specification 
+ * structure for the following motion estimation functions: 
+ * BlockMatch_Integer_8x8, BlockMatch_Integer_16x16, and MotionEstimationMB. 
+ *
+ * Input Arguments:
+ *   
+ *   MEmode - motion estimation mode; available modes are defined by the 
+ *            enumerated type OMXVCM4P2MEMode 
+ *   pMEParams - motion estimation parameters 
+ *
+ * Output Arguments:
+ *   
+ *   pSize - pointer to the number of bytes required for the specification 
+ *            structure 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - one or more of the following is true: 
+ *    -    an invalid value was specified for the parameter MEmode 
+ *    -    a negative or zero value was specified for the 
+ *         parameter pMEParams->searchRange 
+ *
+ */
+
+OMXResult omxVCM4P2_MEGetBufSize(
+    OMXVCM4P2MEMode MEMode, 
+    const OMXVCM4P2MEParams *pMEParams, 
+    OMX_U32 *pSize
+   )
+{
+    armRetArgErrIf(!pMEParams, OMX_Sts_BadArgErr);
+    armRetArgErrIf(!pSize, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pMEParams->searchRange <= 0, OMX_Sts_BadArgErr);
+    armRetArgErrIf((MEMode != OMX_VC_M4P10_FAST_SEARCH) &&
+                   (MEMode != OMX_VC_M4P10_FULL_SEARCH), OMX_Sts_BadArgErr);
+    
+    *pSize = (OMX_INT) sizeof(ARMVCM4P2_MESpec);
+
+    return OMX_Sts_NoErr;
+}
+
+/* End of file */
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_MEInit.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_MEInit.c
new file mode 100644
index 0000000..419e71a
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_MEInit.c
@@ -0,0 +1,84 @@
+/**
+ * 
+ * File Name:  omxVCM4P2_MEInit.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Description:
+ * Initialization modules for the vendor specific Motion Estimation structure.
+ * 
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armVC.h"
+#include "armCOMM.h"
+
+/**
+ * Function:  omxVCM4P2_MEInit   (6.2.4.1.2)
+ *
+ * Description:
+ * Initializes the vendor-specific specification structure required for the 
+ * following motion estimation functions:  BlockMatch_Integer_8x8, 
+ * BlockMatch_Integer_16x16, and MotionEstimationMB. Memory for the 
+ * specification structure *pMESpec must be allocated prior to calling the 
+ * function, and should be aligned on a 4-byte boundary.  Following 
+ * initialization by this function, the vendor-specific structure *pMESpec 
+ * should contain an implementation-specific representation of all motion 
+ * estimation parameters received via the structure pMEParams, for example  
+ * rndVal, searchRange, etc.  The number of bytes required for the 
+ * specification structure can be determined using the function 
+ * omxVCM4P2_MEGetBufSize. 
+ *
+ * Input Arguments:
+ *   
+ *   MEmode - motion estimation mode; available modes are defined by the 
+ *            enumerated type OMXVCM4P2MEMode 
+ *   pMEParams - motion estimation parameters 
+ *   pMESpec - pointer to the uninitialized ME specification structure 
+ *
+ * Output Arguments:
+ *   
+ *   pMESpec - pointer to the initialized ME specification structure 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - one or more of the following is true: 
+ *    -    an invalid value was specified for the parameter MEmode 
+ *    -    a negative or zero value was specified for the 
+ *         parameter pMEParams->searchRange 
+ *
+ */
+
+OMXResult omxVCM4P2_MEInit(
+    OMXVCM4P2MEMode MEMode, 
+    const OMXVCM4P2MEParams *pMEParams, 
+    void *pMESpec
+   )
+{
+    ARMVCM4P2_MESpec *armMESpec = (ARMVCM4P2_MESpec *) pMESpec;
+    
+    armRetArgErrIf(!pMEParams, OMX_Sts_BadArgErr);
+    armRetArgErrIf(!pMESpec, OMX_Sts_BadArgErr);
+    armRetArgErrIf((MEMode != OMX_VC_M4P2_FAST_SEARCH) && 
+                   (MEMode != OMX_VC_M4P2_FULL_SEARCH), OMX_Sts_BadArgErr);
+    armRetArgErrIf(pMEParams->searchRange <= 0, OMX_Sts_BadArgErr);
+    
+    armMESpec->MEParams.searchEnable8x8     = pMEParams->searchEnable8x8;
+    armMESpec->MEParams.halfPelSearchEnable = pMEParams->halfPelSearchEnable;
+    armMESpec->MEParams.searchRange         = pMEParams->searchRange;        
+    armMESpec->MEParams.rndVal              = pMEParams->rndVal;
+    armMESpec->MEMode                       = MEMode;
+    
+    return OMX_Sts_NoErr;
+}
+
+/* End of file */
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_MotionEstimationMB.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_MotionEstimationMB.c
new file mode 100644
index 0000000..9549050
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_MotionEstimationMB.c
@@ -0,0 +1,630 @@
+/**
+ * 
+ * File Name:  omxVCM4P2_MotionEstimationMB.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Description:
+ * Contains module for motion search 16x16 macroblock
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armVC.h"
+#include "armCOMM.h"
+
+/**
+ * Function: armVCM4P2_BlockMatch_16x16
+ *
+ * Description:
+ * 16x16 block match wrapper function, calls omxVCM4P2_BlockMatch_Integer_16x16.
+ * If half pel search is enabled it also calls omxVCM4P2_BlockMatch_Half_16x16
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	pSrcRefBuf	  pointer to the reference Y plane; points to the reference MB that
+ *                    corresponds to the location of the current macroblock in the current
+ *                    plane.
+ * [in]	srcRefStep	  width of the reference plane
+ * [in]	pRefRect	  pointer to the valid rectangular in reference plane. Relative to image origin.
+ *                    It's not limited to the image boundary, but depended on the padding. For example,
+ *                    if you pad 4 pixels outside the image border, then the value for left border
+ *                    can be -4
+ * [in]	pSrcCurrBuf	  pointer to the current macroblock extracted from original plane (linear array,
+ *                    256 entries); must be aligned on an 16-byte boundary.
+ * [in] pCurrPointPos position of the current macroblock in the current plane
+ * [in] pSrcPreMV	  pointer to predicted motion vector; NULL indicates no predicted MV
+ * [in] pSrcPreSAD	  pointer to SAD associated with the predicted MV (referenced by pSrcPreMV); may be set to NULL if unavailable.
+ * [in] pMESpec		  vendor-specific motion estimation specification structure; must have been allocated
+ *                    and then initialized using omxVCM4P2_MEInit prior to calling the block matching
+ *                    function.
+ * [out] pDstMV	      pointer to estimated MV
+ * [out] pDstSAD	  pointer to minimum SAD
+ * *
+ * Return Value:
+ * OMX_Sts_NoErr - no error
+ * OMX_Sts_BadArgErr - bad arguments
+ *
+ */
+static OMXResult armVCM4P2_BlockMatch_16x16(
+     const OMX_U8 *pSrcRefBuf,
+     const OMX_INT srcRefStep,
+     const OMXRect *pRefRect,
+     const OMX_U8 *pSrcCurrBuf,
+     const OMXVCM4P2Coordinate *pCurrPointPos,
+     OMXVCMotionVector *pSrcPreMV,
+     OMX_INT *pSrcPreSAD,
+     void *pMESpec,
+     OMXVCMotionVector *pDstMV,
+     OMX_INT *pDstSAD
+)
+{
+    OMXVCM4P2MEParams *pMEParams = (OMXVCM4P2MEParams *)pMESpec;
+    OMX_INT rndVal;
+    
+    rndVal = pMEParams->rndVal;
+    
+    omxVCM4P2_BlockMatch_Integer_16x16(
+        pSrcRefBuf,
+        srcRefStep,
+        pRefRect,
+        pSrcCurrBuf,
+        pCurrPointPos,
+        pSrcPreMV,
+        pSrcPreSAD,
+        pMEParams,
+        pDstMV,
+        pDstSAD);
+    
+    if (pMEParams->halfPelSearchEnable)
+    {
+        omxVCM4P2_BlockMatch_Half_16x16(
+            pSrcRefBuf,
+            srcRefStep,
+            pRefRect,
+            pSrcCurrBuf,
+            pCurrPointPos,
+            rndVal,
+            pDstMV,
+            pDstSAD);
+    }
+ 
+    return OMX_Sts_NoErr;        
+}
+
+/**
+ * Function: armVCM4P2_BlockMatch_8x8
+ *
+ * Description:
+ * 8x8 block match wrapper function, calls omxVCM4P2_BlockMatch_Integer_8x8.
+ * If half pel search is enabled it also calls omxVCM4P2_BlockMatch_Half_8x8
+ *
+ * Remarks:
+ *
+ * Parameters:
+ * [in]	pSrcRefBuf	  pointer to the reference Y plane; points to the reference MB that
+ *                    corresponds to the location of the current macroblock in the current
+ *                    plane.
+ * [in]	srcRefStep	  width of the reference plane
+ * [in]	pRefRect	  pointer to the valid rectangular in reference plane. Relative to image origin.
+ *                    It's not limited to the image boundary, but depended on the padding. For example,
+ *                    if you pad 4 pixels outside the image border, then the value for left border
+ *                    can be -4
+ * [in]	pSrcCurrBuf	  pointer to the current macroblock extracted from original plane (linear array,
+ *                    256 entries); must be aligned on an 16-byte boundary.
+ * [in] pCurrPointPos position of the current macroblock in the current plane
+ * [in] pSrcPreMV	  pointer to predicted motion vector; NULL indicates no predicted MV
+ * [in] pSrcPreSAD	  pointer to SAD associated with the predicted MV (referenced by pSrcPreMV); may be set to NULL if unavailable.
+ * [in] pMESpec		  vendor-specific motion estimation specification structure; must have been allocated
+ *                    and then initialized using omxVCM4P2_MEInit prior to calling the block matching
+ *                    function.
+ * [out] pDstMV	      pointer to estimated MV
+ * [out] pDstSAD	  pointer to minimum SAD
+ * *
+ * Return Value:
+ * OMX_Sts_NoErr - no error
+ * OMX_Sts_BadArgErr - bad arguments
+ *
+ */
+static OMXResult armVCM4P2_BlockMatch_8x8(
+     const OMX_U8 *pSrcRefBuf,
+     OMX_INT srcRefStep,
+     const OMXRect *pRefRect,
+     const OMX_U8 *pSrcCurrBuf,
+     const OMXVCM4P2Coordinate *pCurrPointPos,
+     OMXVCMotionVector *pSrcPreMV,
+     OMX_INT *pSrcPreSAD,
+     void *pMESpec,
+     OMXVCMotionVector *pSrcDstMV,
+     OMX_INT *pDstSAD
+)
+{
+    OMXVCM4P2MEParams *pMEParams = (OMXVCM4P2MEParams *)pMESpec;
+    OMX_INT rndVal;
+    
+    rndVal = pMEParams->rndVal;
+    
+    omxVCM4P2_BlockMatch_Integer_8x8(
+        pSrcRefBuf,
+        srcRefStep,
+        pRefRect,
+        pSrcCurrBuf,
+        pCurrPointPos,
+        pSrcPreMV,
+        pSrcPreSAD,
+        pMEParams,
+        pSrcDstMV,
+        pDstSAD);
+    
+    if (pMEParams->halfPelSearchEnable)
+    {
+        omxVCM4P2_BlockMatch_Half_8x8(
+            pSrcRefBuf,
+            srcRefStep,
+            pRefRect,
+            pSrcCurrBuf,
+            pCurrPointPos,
+            rndVal,
+            pSrcDstMV,
+            pDstSAD);
+    }
+    
+    return OMX_Sts_NoErr;        
+}
+
+
+/**
+ * Function:  omxVCM4P2_MotionEstimationMB   (6.2.4.3.1)
+ *
+ * Description:
+ * Performs motion search for a 16x16 macroblock.  Selects best motion search 
+ * strategy from among inter-1MV, inter-4MV, and intra modes.  Supports 
+ * integer and half pixel resolution. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcCurrBuf - pointer to the top-left corner of the current MB in the 
+ *            original picture plane; must be aligned on a 16-byte boundary.  
+ *            The function does not expect source data outside the region 
+ *            bounded by the MB to be available; for example it is not 
+ *            necessary for the caller to guarantee the availability of 
+ *            pSrcCurrBuf[-SrcCurrStep], i.e., the row of pixels above the MB 
+ *            to be processed. 
+ *   srcCurrStep - width of the original picture plane, in terms of full 
+ *            pixels; must be a multiple of 16. 
+ *   pSrcRefBuf - pointer to the reference Y plane; points to the reference 
+ *            plane location corresponding to the location of the current 
+ *            macroblock in the current plane; must be aligned on a 16-byte 
+ *            boundary. 
+ *   srcRefStep - width of the reference picture plane, in terms of full 
+ *            pixels; must be a multiple of 16. 
+ *   pRefRect - reference plane valid region rectangle, specified relative to 
+ *            the image origin 
+ *   pCurrPointPos - position of the current macroblock in the current plane 
+ *   pMESpec - pointer to the vendor-specific motion estimation specification 
+ *            structure; must be allocated and then initialized using 
+ *            omxVCM4P2_MEInit prior to calling this function. 
+ *   pMBInfo - array, of dimension four, containing pointers to information 
+ *            associated with four nearby MBs: 
+ *            -   pMBInfo[0] - pointer to left MB information 
+ *            -   pMBInfo[1] - pointer to top MB information 
+ *            -   pMBInfo[2] - pointer to top-left MB information 
+ *            -   pMBInfo[3] - pointer to top-right MB information 
+ *            Any pointer in the array may be set equal to NULL if the 
+ *            corresponding MB doesn't exist.  For each MB, the following structure 
+ *            members are used:    
+ *            -   mbType - macroblock type, either OMX_VC_INTRA, OMX_VC_INTER, or 
+ *                OMX_VC_INTER4V 
+ *            -   pMV0[2][2] - estimated motion vectors; represented 
+ *                in 1/2 pixel units 
+ *            -   sliceID - number of the slice to which the MB belongs 
+ *   pSrcDstMBCurr - pointer to information structure for the current MB.  
+ *            The following entries should be set prior to calling the 
+ *            function: sliceID - the number of the slice the to which the 
+ *            current MB belongs.  The structure elements cbpy and cbpc are 
+ *            ignored. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDstMBCurr - pointer to updated information structure for the current 
+ *            MB after MB-level motion estimation has been completed.  The 
+ *            following structure members are updated by the ME function:   
+ *              -  mbType - macroblock type: OMX_VC_INTRA, OMX_VC_INTER, or 
+ *                 OMX_VC_INTER4V. 
+ *              -  pMV0[2][2] - estimated motion vectors; represented in 
+ *                 terms of 1/2 pel units. 
+ *              -  pMVPred[2][2] - predicted motion vectors; represented 
+ *                 in terms of 1/2 pel units. 
+ *            The structure members cbpy and cbpc are not updated by the function. 
+ *   pDstSAD - pointer to the minimum SAD for INTER1V, or sum of minimum SADs 
+ *            for INTER4V 
+ *   pDstBlockSAD - pointer to an array of SAD values for each of the four 
+ *            8x8 luma blocks in the MB.  The block SADs are in scan order for 
+ *            each MB. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments.  Returned if one or more of the 
+ *              following conditions is true: 
+ *    -    at least one of the following pointers is NULL: pSrcCurrBuf, 
+ *              pSrcRefBuf, pRefRect, pCurrPointPos, pMBInter, pMBIntra, 
+ *              pSrcDstMBCurr, or pDstSAD. 
+ *
+ */
+
+OMXResult omxVCM4P2_MotionEstimationMB (
+    const OMX_U8 *pSrcCurrBuf,
+    OMX_S32 srcCurrStep,
+    const OMX_U8 *pSrcRefBuf,
+    OMX_S32 srcRefStep,
+    const OMXRect*pRefRect,
+    const OMXVCM4P2Coordinate *pCurrPointPos,
+    void *pMESpec,
+    const OMXVCM4P2MBInfoPtr *pMBInfo,
+    OMXVCM4P2MBInfo *pSrcDstMBCurr,
+    OMX_U16 *pDstSAD,
+    OMX_U16 *pDstBlockSAD
+)
+{
+ 
+    OMX_INT intraSAD, average, count, index, x, y;
+    OMXVCMotionVector dstMV16x16;
+    OMX_INT           dstSAD16x16;
+    OMX_INT           dstSAD8x8;
+    OMXVCM4P2MEParams  *pMEParams; 
+	OMXVCM4P2Coordinate TempCurrPointPos; 
+    OMXVCM4P2Coordinate *pTempCurrPointPos; 
+    OMX_U8 aTempSrcCurrBuf[271];
+    OMX_U8 *pTempSrcCurrBuf;
+    OMX_U8 *pDst;
+    OMX_U8 aDst[71];
+    OMX_S32 dstStep = 8;
+    OMX_INT predictType;
+	OMX_S32 Sad;
+    const OMX_U8 *pTempSrcRefBuf;
+    OMXVCMotionVector* pSrcCandMV1[4];
+    OMXVCMotionVector* pSrcCandMV2[4];
+    OMXVCMotionVector* pSrcCandMV3[4];
+        
+    /* Argument error checks */
+    armRetArgErrIf(!armIs16ByteAligned(pSrcCurrBuf), OMX_Sts_BadArgErr);
+	armRetArgErrIf(!armIs16ByteAligned(pSrcRefBuf), OMX_Sts_BadArgErr);
+    armRetArgErrIf(((srcCurrStep % 16) || (srcRefStep % 16)), OMX_Sts_BadArgErr);
+	armRetArgErrIf(pSrcCurrBuf == NULL, OMX_Sts_BadArgErr);
+	armRetArgErrIf(pSrcRefBuf == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pRefRect == NULL, OMX_Sts_BadArgErr);    
+    armRetArgErrIf(pCurrPointPos == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pSrcDstMBCurr == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pDstSAD == NULL, OMX_Sts_BadArgErr);
+    
+    
+    pTempCurrPointPos = &(TempCurrPointPos);
+    pTempSrcCurrBuf = armAlignTo16Bytes(aTempSrcCurrBuf);
+    pMEParams = (OMXVCM4P2MEParams *)pMESpec;
+    pTempCurrPointPos->x = pCurrPointPos->x;
+    pTempCurrPointPos->y = pCurrPointPos->y;
+    pSrcDstMBCurr->mbType = OMX_VC_INTER;
+    
+    /* Preparing a linear buffer for block match */
+    for (y = 0, index = count = 0; y < 16; y++, index += srcCurrStep - 16)
+    {
+        for(x = 0; x < 16; x++, count++, index++)
+        {
+            pTempSrcCurrBuf[count] = pSrcCurrBuf[index];
+        }
+    }
+    for(y = 0, index = 0; y < 2; y++)
+    {
+        for(x = 0; x < 2; x++,index++)
+        {
+            if((pMBInfo[0] != NULL) && (pMBInfo[0]->mbType != OMX_VC_INTRA))
+            {
+               pSrcCandMV1[index] = &(pMBInfo[0]->pMV0[y][x]); 
+            }
+            else
+            {
+               pSrcCandMV1[index] = NULL;
+            }
+            if((pMBInfo[1] != NULL) && (pMBInfo[1]->mbType != OMX_VC_INTRA))
+            {
+               pSrcCandMV2[index] = &(pMBInfo[1]->pMV0[y][x]);
+            }
+            else
+            {
+               pSrcCandMV2[index] = NULL; 
+            }
+            if((pMBInfo[3] != NULL) && (pMBInfo[3]->mbType != OMX_VC_INTRA))
+            {
+               pSrcCandMV3[index] = &(pMBInfo[3]->pMV0[y][x]);
+            }
+            else
+            {
+               pSrcCandMV3[index] = NULL; 
+            }
+        }
+    }
+	/* Calculating SAD at MV(0,0) */
+	armVCCOMM_SAD(pTempSrcCurrBuf,
+					  16,
+					  pSrcRefBuf,
+					  srcRefStep,
+					  &Sad,
+					  16,
+					  16);
+	*pDstSAD = Sad;
+
+    /* Mode decision for NOT_CODED MB */
+	if(*pDstSAD == 0)
+	{
+        pSrcDstMBCurr->pMV0[0][0].dx = 0;
+        pSrcDstMBCurr->pMV0[0][0].dy = 0;
+        *pDstSAD   = 0;
+		return OMX_Sts_NoErr;
+	}
+
+    omxVCM4P2_FindMVpred(
+                    &(pSrcDstMBCurr->pMV0[0][0]),
+                    pSrcCandMV1[0],
+                    pSrcCandMV2[0],
+                    pSrcCandMV3[0],
+                    &(pSrcDstMBCurr->pMVPred[0][0]),
+                    NULL,
+                    0);
+                    
+    /* Inter 1 MV */
+    armVCM4P2_BlockMatch_16x16(
+        pSrcRefBuf,
+        srcRefStep,
+        pRefRect,
+        pTempSrcCurrBuf,
+        pCurrPointPos,
+        &(pSrcDstMBCurr->pMVPred[0][0]),
+        NULL,
+        pMEParams,
+        &dstMV16x16,
+        &dstSAD16x16);
+    
+    /* Initialize all with 1 MV values */
+    pSrcDstMBCurr->pMV0[0][0].dx = dstMV16x16.dx;
+    pSrcDstMBCurr->pMV0[0][0].dy = dstMV16x16.dy;
+    pSrcDstMBCurr->pMV0[0][1].dx = dstMV16x16.dx;
+    pSrcDstMBCurr->pMV0[0][1].dy = dstMV16x16.dy;
+    pSrcDstMBCurr->pMV0[1][0].dx = dstMV16x16.dx;
+    pSrcDstMBCurr->pMV0[1][0].dy = dstMV16x16.dy;
+    pSrcDstMBCurr->pMV0[1][1].dx = dstMV16x16.dx;
+    pSrcDstMBCurr->pMV0[1][1].dy = dstMV16x16.dy; 
+    
+    *pDstSAD   = dstSAD16x16;       
+    
+    if (pMEParams->searchEnable8x8)
+    {
+        /* Inter 4MV */
+        armVCM4P2_BlockMatch_8x8 (pSrcRefBuf,
+                                      srcRefStep, pRefRect,
+                                      pTempSrcCurrBuf, pTempCurrPointPos,
+                                      &(pSrcDstMBCurr->pMVPred[0][0]), NULL,
+                                      pMEParams, &(pSrcDstMBCurr->pMV0[0][0]),
+                                      &dstSAD8x8
+                                      );
+        pDstBlockSAD[0] = dstSAD8x8;
+        *pDstSAD = dstSAD8x8;
+        pTempCurrPointPos->x += 8;
+        pSrcRefBuf += 8;
+        omxVCM4P2_FindMVpred(
+                    &(pSrcDstMBCurr->pMV0[0][1]),
+                    pSrcCandMV1[1],
+                    pSrcCandMV2[1],
+                    pSrcCandMV3[1],
+                    &(pSrcDstMBCurr->pMVPred[0][1]),
+                    NULL,
+                    1);
+        
+        armVCM4P2_BlockMatch_8x8 (pSrcRefBuf,
+                                      srcRefStep, pRefRect,
+                                      pTempSrcCurrBuf, pTempCurrPointPos,
+                                      &(pSrcDstMBCurr->pMVPred[0][1]), NULL,
+                                      pMEParams, &(pSrcDstMBCurr->pMV0[0][1]),
+                                      &dstSAD8x8
+                                      );
+        pDstBlockSAD[1] = dstSAD8x8;
+        *pDstSAD += dstSAD8x8;
+        pTempCurrPointPos->x -= 8;
+        pTempCurrPointPos->y += 8;
+        pSrcRefBuf += (srcRefStep * 8) - 8;
+        
+        omxVCM4P2_FindMVpred(
+                    &(pSrcDstMBCurr->pMV0[1][0]),
+                    pSrcCandMV1[2],
+                    pSrcCandMV2[2],
+                    pSrcCandMV3[2],
+                    &(pSrcDstMBCurr->pMVPred[1][0]),
+                    NULL,
+                    2);
+        armVCM4P2_BlockMatch_8x8 (pSrcRefBuf,
+                                      srcRefStep, pRefRect,
+                                      pTempSrcCurrBuf, pTempCurrPointPos,
+                                      &(pSrcDstMBCurr->pMVPred[1][0]), NULL,
+                                      pMEParams, &(pSrcDstMBCurr->pMV0[1][0]),
+                                      &dstSAD8x8
+                                      );
+        pDstBlockSAD[2] = dstSAD8x8;
+        *pDstSAD += dstSAD8x8;
+        pTempCurrPointPos->x += 8;
+        pSrcRefBuf += 8;
+        omxVCM4P2_FindMVpred(
+                    &(pSrcDstMBCurr->pMV0[1][1]),
+                    pSrcCandMV1[3],
+                    pSrcCandMV2[3],
+                    pSrcCandMV3[3],
+                    &(pSrcDstMBCurr->pMVPred[1][1]),
+                    NULL,
+                    3);
+        armVCM4P2_BlockMatch_8x8 (pSrcRefBuf,
+                                      srcRefStep, pRefRect,
+                                      pTempSrcCurrBuf, pTempCurrPointPos,
+                                      &(pSrcDstMBCurr->pMVPred[1][1]), NULL,
+                                      pMEParams, &(pSrcDstMBCurr->pMV0[1][1]),
+                                      &dstSAD8x8
+                                      );
+        pDstBlockSAD[3] = dstSAD8x8;
+        *pDstSAD += dstSAD8x8;   
+        
+        
+        /* Checking if 4MV is equal to 1MV */
+        if (
+            (pSrcDstMBCurr->pMV0[0][0].dx != dstMV16x16.dx) ||
+            (pSrcDstMBCurr->pMV0[0][0].dy != dstMV16x16.dy) ||
+            (pSrcDstMBCurr->pMV0[0][1].dx != dstMV16x16.dx) ||
+            (pSrcDstMBCurr->pMV0[0][1].dy != dstMV16x16.dy) ||
+            (pSrcDstMBCurr->pMV0[1][0].dx != dstMV16x16.dx) ||
+            (pSrcDstMBCurr->pMV0[1][0].dy != dstMV16x16.dy) ||
+            (pSrcDstMBCurr->pMV0[1][1].dx != dstMV16x16.dx) ||
+            (pSrcDstMBCurr->pMV0[1][1].dy != dstMV16x16.dy)
+           )
+        {
+            /* select the 4 MV */
+            pSrcDstMBCurr->mbType = OMX_VC_INTER4V;
+        }                                      
+    }
+                                         
+    /* finding the error in intra mode */
+    for (count = 0, average = 0; count < 256 ; count++)
+    {
+        average = average + pTempSrcCurrBuf[count];
+    }
+    average = average/256;
+    
+	intraSAD = 0;
+
+    /* Intra SAD calculation */
+    for (count = 0; count < 256 ; count++)
+    {
+        intraSAD += armAbs ((pTempSrcCurrBuf[count]) - (average));
+    }
+    
+	/* Using the MPEG4 VM formula for intra/inter mode decision 
+	   Var < (SAD - 2*NB) where NB = N^2 is the number of pixels
+	   of the macroblock.*/
+
+    if (intraSAD <= (*pDstSAD - 512))
+    {
+        pSrcDstMBCurr->mbType = OMX_VC_INTRA;
+        pSrcDstMBCurr->pMV0[0][0].dx = 0;
+        pSrcDstMBCurr->pMV0[0][0].dy = 0;
+        *pDstSAD   = intraSAD;
+        pDstBlockSAD[0] = 0xFFFF;
+        pDstBlockSAD[1] = 0xFFFF;
+        pDstBlockSAD[2] = 0xFFFF;
+        pDstBlockSAD[3] = 0xFFFF;
+    }
+
+    if(pSrcDstMBCurr->mbType == OMX_VC_INTER)
+    {
+      pTempSrcRefBuf = pSrcRefBuf + (srcRefStep * dstMV16x16.dy) + dstMV16x16.dx;
+    
+      if((dstMV16x16.dx & 0x1) && (dstMV16x16.dy & 0x1))
+      {
+        predictType = OMX_VC_HALF_PIXEL_XY;
+      }
+      else if(dstMV16x16.dx & 0x1)
+      {
+        predictType = OMX_VC_HALF_PIXEL_X;
+      }
+      else if(dstMV16x16.dy & 0x1)
+      {
+        predictType = OMX_VC_HALF_PIXEL_Y;
+      }
+      else
+      {
+        predictType = OMX_VC_INTEGER_PIXEL;
+      }
+      
+      pDst = armAlignTo8Bytes(&(aDst[0]));
+      /* Calculating Block SAD at MV(dstMV16x16.dx,dstMV16x16.dy) */
+	  /* Block 0 */
+      omxVCM4P2_MCReconBlock(pTempSrcRefBuf,
+	                             srcRefStep,
+                                 NULL,
+                                 pDst, 
+                                 dstStep,
+                                 predictType,
+                                 pMEParams->rndVal);
+    
+      armVCCOMM_SAD(pTempSrcCurrBuf,
+                        16,
+                        pDst,
+                        dstStep,
+                        &Sad,
+                        8,
+                        8);
+      pDstBlockSAD[0] = Sad;
+   
+      /* Block 1 */
+      omxVCM4P2_MCReconBlock(pTempSrcRefBuf + 8,
+                                 srcRefStep,
+                                 NULL,
+                                 pDst, 
+                                 dstStep,
+                                 predictType,
+                                 pMEParams->rndVal);					  
+
+      armVCCOMM_SAD(pTempSrcCurrBuf + 8,
+                        16,
+                        pDst,
+                        dstStep,
+                        &Sad,
+                        8,
+                        8);
+      pDstBlockSAD[1] = Sad;
+	
+      /* Block 2 */
+      omxVCM4P2_MCReconBlock(pTempSrcRefBuf + (srcRefStep*8),
+                                 srcRefStep,
+                                 NULL,
+                                 pDst, 
+                                 dstStep,
+                                 predictType,
+                                 pMEParams->rndVal);
+
+      armVCCOMM_SAD(pTempSrcCurrBuf + (16*8),
+                        16,
+                        pDst,
+                        dstStep,
+                        &Sad,
+                        8,
+                        8);
+      pDstBlockSAD[2] = Sad;
+
+	  /* Block 3 */
+      omxVCM4P2_MCReconBlock(pTempSrcRefBuf + (srcRefStep*8) + 8,
+                                 srcRefStep,
+                                 NULL,
+                                 pDst, 
+                                 dstStep,
+                                 predictType,
+                                 pMEParams->rndVal);
+
+      armVCCOMM_SAD(pTempSrcCurrBuf + (16*8) + 8,
+                        16,
+                        pDst,
+                        dstStep,
+                        &Sad,
+                        8,
+                        8);
+      pDstBlockSAD[3] = Sad;
+    }
+    return OMX_Sts_NoErr;
+}
+
+/* End of file */
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_PredictReconCoefIntra.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_PredictReconCoefIntra.c
new file mode 100644
index 0000000..1613f47
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_PredictReconCoefIntra.c
@@ -0,0 +1,121 @@
+ /**
+ * 
+ * File Name:  omxVCM4P2_PredictReconCoefIntra.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * File:        omxVCM4P2_PredictReconCoefIntra_S16.c
+ * Description: Contains modules for AC DC prediction
+ *
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+
+/**
+ * Function:  omxVCM4P2_PredictReconCoefIntra   (6.2.5.4.3)
+ *
+ * Description:
+ * Performs adaptive DC/AC coefficient prediction for an intra block.  Prior 
+ * to the function call, prediction direction (predDir) should be selected as 
+ * specified in [ISO14496-2], subclause 7.4.3.1. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - pointer to the coefficient buffer which contains the quantized 
+ *            coefficient residuals (PQF) of the current block; must be 
+ *            aligned on a 4-byte boundary.  The output coefficients are 
+ *            saturated to the range [-2048, 2047]. 
+ *   pPredBufRow - pointer to the coefficient row buffer; must be aligned on 
+ *            a 4-byte boundary. 
+ *   pPredBufCol - pointer to the coefficient column buffer; must be aligned 
+ *            on a 4-byte boundary. 
+ *   curQP - quantization parameter of the current block. curQP may equal to 
+ *            predQP especially when the current block and the predictor block 
+ *            are in the same macroblock. 
+ *   predQP - quantization parameter of the predictor block 
+ *   predDir - indicates the prediction direction which takes one of the 
+ *            following values: OMX_VC_HORIZONTAL - predict horizontally 
+ *            OMX_VC_VERTICAL - predict vertically 
+ *   ACPredFlag - a flag indicating if AC prediction should be performed. It 
+ *            is equal to ac_pred_flag in the bit stream syntax of MPEG-4 
+ *   videoComp - video component type (luminance or chrominance) of the 
+ *            current block 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst - pointer to the coefficient buffer which contains the quantized 
+ *            coefficients (QF) of the current block 
+ *   pPredBufRow - pointer to the updated coefficient row buffer 
+ *   pPredBufCol - pointer to the updated coefficient column buffer  Note: 
+ *            Buffer update: Update the AC prediction buffer (both row and 
+ *            column buffer). 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments, if:
+ *        -    At least one of the pointers is NULL: 
+ *              pSrcDst, pPredBufRow, or pPredBufCol. 
+ *        -    curQP <= 0, 
+ *        -    predQP <= 0, 
+ *        -    curQP >31, 
+ *        -    predQP > 31, 
+ *        -    preDir exceeds [1,2]
+ *        -    pSrcDst, pPredBufRow, or pPredBufCol is not 4-byte aligned. 
+ *
+ */
+
+OMXResult omxVCM4P2_PredictReconCoefIntra(
+     OMX_S16 * pSrcDst,
+     OMX_S16 * pPredBufRow,
+     OMX_S16 * pPredBufCol,
+     OMX_INT curQP,
+     OMX_INT predQP,
+     OMX_INT predDir,
+     OMX_INT ACPredFlag,
+     OMXVCM4P2VideoComponent videoComp
+ )
+{
+    OMX_U8 flag;
+    /* Argument error checks */
+    armRetArgErrIf(pSrcDst == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pPredBufRow == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pPredBufCol == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(curQP <= 0, OMX_Sts_BadArgErr);
+    armRetArgErrIf(predQP <= 0, OMX_Sts_BadArgErr);
+    armRetArgErrIf(curQP > 31, OMX_Sts_BadArgErr);
+    armRetArgErrIf(predQP > 31, OMX_Sts_BadArgErr);
+    armRetArgErrIf((predDir != 1) && (predDir != 2), OMX_Sts_BadArgErr);
+    armRetArgErrIf(!armIs4ByteAligned(pSrcDst), OMX_Sts_BadArgErr);
+    armRetArgErrIf(!armIs4ByteAligned(pPredBufRow), OMX_Sts_BadArgErr);
+    armRetArgErrIf(!armIs4ByteAligned(pPredBufCol), OMX_Sts_BadArgErr);
+
+    flag = 0;
+    return armVCM4P2_ACDCPredict(
+        pSrcDst,
+        NULL,
+        pPredBufRow,
+        pPredBufCol,
+        curQP,
+        predQP,
+        predDir,
+        ACPredFlag,
+        videoComp,
+        flag,
+        NULL);
+
+}
+
+/* End of file */
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_QuantInter_I.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_QuantInter_I.c
new file mode 100644
index 0000000..5964f73
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_QuantInter_I.c
@@ -0,0 +1,117 @@
+/**
+ * 
+ * File Name:  omxVCM4P2_QuantInter_I.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Description:
+ * Contains modules for inter Quantization
+ * 
+ */
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+
+/**
+ * Function:  omxVCM4P2_QuantInter_I   (6.2.4.4.3)
+ *
+ * Description:
+ * Performs quantization on an inter coefficient block; supports 
+ * bits_per_pixel == 8. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - pointer to the input inter block coefficients; must be aligned 
+ *            on a 16-byte boundary. 
+ *   QP - quantization parameter (quantizer_scale) 
+ *   shortVideoHeader - binary flag indicating presence of short_video_header; 
+ *            shortVideoHeader==1 selects linear intra DC mode, and 
+ *            shortVideoHeader==0 selects non linear intra DC mode. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst - pointer to the output (quantized) interblock coefficients.  
+ *            When shortVideoHeader==1, AC coefficients are saturated on the 
+ *            interval [-127, 127], and DC coefficients are saturated on the 
+ *            interval [1, 254].  When shortVideoHeader==0, AC coefficients 
+ *            are saturated on the interval [-2047, 2047]. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments:
+ *    -    pSrcDst is NULL. 
+ *    -    QP <= 0 or QP >= 32. 
+ *
+ */
+
+OMXResult omxVCM4P2_QuantInter_I(
+     OMX_S16 * pSrcDst,
+     OMX_U8 QP,
+	 OMX_INT shortVideoHeader
+)
+{
+
+    /* Definitions and Initializations*/
+    OMX_INT coeffCount;
+    OMX_INT fSign;
+    OMX_INT maxClpAC = 0, minClpAC = 0;
+    OMX_INT maxClpDC = 0, minClpDC = 0;
+    
+    /* Argument error checks */
+    armRetArgErrIf(pSrcDst == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(((QP <= 0) || (QP >= 32)), OMX_Sts_BadArgErr);
+   /* One argument check is delayed until we have ascertained that  */
+   /* pQMatrix is not NULL.                                         */
+                
+    /* Set the Clip Range based on SVH on/off */
+    if(shortVideoHeader == 1)
+    {
+       maxClpDC = 254;
+       minClpDC = 1;
+       maxClpAC = 127;
+       minClpAC = -127;        
+    }
+    else
+    {
+        maxClpDC = 2047;
+        minClpDC = -2047;
+        maxClpAC = 2047;
+        minClpAC = -2047;   
+    }
+                
+    /* Second Inverse quantisation method */
+    for (coeffCount = 0; coeffCount < 64; coeffCount++)
+    {
+        fSign =  armSignCheck (pSrcDst[coeffCount]);  
+        pSrcDst[coeffCount] = (armAbs(pSrcDst[coeffCount]) 
+                              - (QP/2))/(2 * QP);
+        pSrcDst[coeffCount] *= fSign;
+        
+        /* Clip */
+        if (coeffCount == 0)
+        {
+           pSrcDst[coeffCount] =
+           (OMX_S16) armClip (minClpDC, maxClpDC, pSrcDst[coeffCount]);
+        }
+        else
+        {
+           pSrcDst[coeffCount] =
+           (OMX_S16) armClip (minClpAC, maxClpAC, pSrcDst[coeffCount]);
+        }
+    }
+    return OMX_Sts_NoErr;
+
+}
+
+/* End of file */
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_QuantIntra_I.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_QuantIntra_I.c
new file mode 100644
index 0000000..a10da68
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_QuantIntra_I.c
@@ -0,0 +1,153 @@
+/**
+ * 
+ * File Name:  omxVCM4P2_QuantIntra_I.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Description:
+ * Contains modules for intra Quantization
+ * 
+ */
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+/**
+ * Function:  omxVCM4P2_QuantIntra_I   (6.2.4.4.2)
+ *
+ * Description:
+ * Performs quantization on intra block coefficients. This function supports 
+ * bits_per_pixel == 8. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - pointer to the input intra block coefficients; must be aligned 
+ *            on a 16-byte boundary. 
+ *   QP - quantization parameter (quantizer_scale). 
+ *   blockIndex - block index indicating the component type and position, 
+ *            valid in the range 0 to 5, as defined in [ISO14496-2], subclause 
+ *            6.1.3.8. 
+ *   shortVideoHeader - binary flag indicating presence of 
+ *            short_video_header; shortVideoHeader==1 selects linear intra DC 
+ *            mode, and shortVideoHeader==0 selects non linear intra DC mode. 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst - pointer to the output (quantized) interblock coefficients.  
+ *            When shortVideoHeader==1, AC coefficients are saturated on the 
+ *            interval [-127, 127], and DC coefficients are saturated on the 
+ *            interval [1, 254].  When shortVideoHeader==0, AC coefficients 
+ *            are saturated on the interval [-2047, 2047]. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments:
+ *    -    pSrcDst is NULL. 
+ *    -    blockIndex < 0 or blockIndex >= 10 
+ *    -    QP <= 0 or QP >= 32. 
+ *
+ */
+
+OMXResult omxVCM4P2_QuantIntra_I(
+     OMX_S16 * pSrcDst,
+     OMX_U8 QP,
+     OMX_INT blockIndex,
+	 OMX_INT shortVideoHeader
+ )
+{
+
+    /* Definitions and Initializations*/
+    /* Initialized to remove compilation error */
+    OMX_INT dcScaler = 0, coeffCount,fSign;
+    OMX_INT maxClpAC, minClpAC;
+
+    /* Argument error checks */
+    armRetArgErrIf(pSrcDst == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(((blockIndex < 0) || (blockIndex >= 10)), OMX_Sts_BadArgErr);
+    armRetArgErrIf(((QP <= 0) || (QP >= 32)), OMX_Sts_BadArgErr);
+   /* One argument check is delayed until we have ascertained that  */
+   /* pQMatrix is not NULL.                                         */
+
+    
+    /* Set the Clip Range based on SVH on/off */
+    if(shortVideoHeader == 1)
+    {
+        maxClpAC = 127;
+        minClpAC = -127;
+        dcScaler = 8;
+        /* Dequant the DC value, this applies to both the methods */
+        pSrcDst[0] = armIntDivAwayFromZero (pSrcDst[0], dcScaler);
+    
+        /* Clip between 1 and 254 */
+        pSrcDst[0] = (OMX_S16) armClip (1, 254, pSrcDst[0]);
+    }
+    else
+    {
+        maxClpAC = 2047;
+        minClpAC = -2047;   
+        /* Calculate the DC scaler value */
+        if ((blockIndex  < 4) || (blockIndex  > 5))
+        {
+            if (QP >= 1 && QP <= 4)
+            {
+                dcScaler = 8;
+            }
+            else if (QP >= 5 && QP <= 8)
+            {
+                dcScaler = 2 * QP;
+            }
+            else if (QP >= 9 && QP <= 24)
+            {
+                dcScaler = QP + 8;
+            }
+            else
+            {
+                dcScaler = (2 * QP) - 16;
+            }
+        }
+        else if (blockIndex < 6)
+        {
+            if (QP >= 1 && QP <= 4)
+            {
+                dcScaler = 8;
+            }
+            else if (QP >= 5 && QP <= 24)
+            {
+                dcScaler = (QP + 13)/2;
+            }
+            else
+            {
+                dcScaler = QP - 6;
+            }
+        }
+        
+        /* Dequant the DC value, this applies to both the methods */
+        pSrcDst[0] = armIntDivAwayFromZero (pSrcDst[0], dcScaler);
+    }
+    
+    /* Second Inverse quantisation method */
+    for (coeffCount = 1; coeffCount < 64; coeffCount++)
+    {
+        fSign =  armSignCheck (pSrcDst[coeffCount]);  
+        pSrcDst[coeffCount] = armAbs(pSrcDst[coeffCount])/(2 * QP);
+        pSrcDst[coeffCount] *= fSign;
+
+        /* Clip */
+        pSrcDst[coeffCount] =
+        (OMX_S16) armClip (minClpAC, maxClpAC, pSrcDst[coeffCount]);
+    }
+    return OMX_Sts_NoErr;
+
+}
+
+/* End of file */
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_QuantInvInter_I.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_QuantInvInter_I.c
new file mode 100644
index 0000000..6e0de5c
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_QuantInvInter_I.c
@@ -0,0 +1,96 @@
+/**
+ * 
+ * File Name:  omxVCM4P2_QuantInvInter_I.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Description:
+ * Contains modules for inter inverse Quantization
+ * 
+ */ 
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+
+
+/**
+ * Function:  omxVCM4P2_QuantInvInter_I   (6.2.5.3.2)
+ *
+ * Description:
+ * Performs the second inverse quantization mode on an intra/inter coded 
+ * block. Supports bits_per_pixel = 8. The output coefficients are clipped to 
+ * the range [-2048, 2047]. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - pointer to the input (quantized) intra/inter block; must be 
+ *            aligned on a 16-byte boundary. 
+ *   QP - quantization parameter (quantizer_scale) 
+ *   videoComp - video component type of the current block. Takes one of the 
+ *            following flags: OMX_VC_LUMINANCE, OMX_VC_CHROMINANCE (intra 
+ *            version only). 
+ *   shortVideoHeader - binary flag indicating presence of short_video_header 
+ *            (intra version only). 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst - pointer to the output (dequantized) intra/inter block 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; one or more of the following is 
+ *              true: 
+ *    -    pSrcDst is NULL 
+ *    -    QP <= 0 or QP >=31 
+ *    -    videoComp is neither OMX_VC_LUMINANCE nor OMX_VC_CHROMINANCE. 
+ *
+ */
+
+OMXResult omxVCM4P2_QuantInvInter_I(
+     OMX_S16 * pSrcDst,
+     OMX_INT QP
+	 )
+{
+
+    OMX_INT coeffCount, Sign;
+    
+    /* Argument error checks */
+    armRetArgErrIf(pSrcDst == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(((QP <= 0) || (QP >= 32)), OMX_Sts_BadArgErr);
+
+    /* Second Inverse quantisation method */
+    for (coeffCount = 0; coeffCount < 64; coeffCount++)
+    {
+        /* check sign */
+        Sign =  armSignCheck (pSrcDst[coeffCount]);
+              
+        /* Quantize the coeff */
+        if (QP & 0x1)
+        {
+            pSrcDst[coeffCount] = (2* armAbs(pSrcDst[coeffCount]) + 1) * QP;
+            pSrcDst[coeffCount] *= Sign;
+        }
+        else
+        {
+            pSrcDst[coeffCount] = (2* armAbs(pSrcDst[coeffCount]) + 1)
+                                                                * QP - 1;
+            pSrcDst[coeffCount] *= Sign;
+        }
+        /* Saturate */
+        pSrcDst[coeffCount] = armClip (-2048, 2047, pSrcDst[coeffCount]);
+    }
+    return OMX_Sts_NoErr;
+}
+
+/* End of file */
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_QuantInvIntra_I.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_QuantInvIntra_I.c
new file mode 100644
index 0000000..a946d7b
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_QuantInvIntra_I.c
@@ -0,0 +1,153 @@
+/**
+ * 
+ * File Name:  omxVCM4P2_QuantInvIntra_I.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Description:
+ * Contains modules for intra inverse Quantization
+ * 
+ */ 
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+
+/**
+ * Function:  omxVCM4P2_QuantInvIntra_I   (6.2.5.3.2)
+ *
+ * Description:
+ * Performs the second inverse quantization mode on an intra/inter coded 
+ * block. Supports bits_per_pixel = 8. The output coefficients are clipped to 
+ * the range [-2048, 2047]. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrcDst - pointer to the input (quantized) intra/inter block; must be 
+ *            aligned on a 16-byte boundary. 
+ *   QP - quantization parameter (quantizer_scale) 
+ *   videoComp - video component type of the current block. Takes one of the 
+ *            following flags: OMX_VC_LUMINANCE, OMX_VC_CHROMINANCE (intra 
+ *            version only). 
+ *   shortVideoHeader - binary flag indicating presence of short_video_header 
+ *            (intra version only). 
+ *
+ * Output Arguments:
+ *   
+ *   pSrcDst - pointer to the output (dequantized) intra/inter block 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments; one or more of the following is 
+ *              true: 
+ *    -    pSrcDst is NULL 
+ *    -    QP <= 0 or QP >=31 
+ *    -    videoComp is neither OMX_VC_LUMINANCE nor OMX_VC_CHROMINANCE. 
+ *
+ */
+
+OMXResult omxVCM4P2_QuantInvIntra_I(
+     OMX_S16 * pSrcDst,
+     OMX_INT QP,
+     OMXVCM4P2VideoComponent videoComp,
+	 OMX_INT shortVideoHeader
+)
+{
+
+    /* Initialized to remove compilation error */
+    OMX_INT dcScaler = 0, coeffCount, Sign;
+
+    /* Argument error checks */
+    armRetArgErrIf(pSrcDst == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(((QP <= 0) || (QP >= 32)), OMX_Sts_BadArgErr);
+	armRetArgErrIf(((videoComp != OMX_VC_LUMINANCE) && (videoComp != OMX_VC_CHROMINANCE)), OMX_Sts_BadArgErr);
+    
+    /* Calculate the DC scaler value */
+    
+    /* linear intra DC mode */
+    if(shortVideoHeader)
+    {
+        dcScaler = 8;
+    }
+    /* nonlinear intra DC mode */
+    else
+    {
+    
+        if (videoComp == OMX_VC_LUMINANCE)
+        {
+            if (QP >= 1 && QP <= 4)
+            {
+                dcScaler = 8;
+            }
+            else if (QP >= 5 && QP <= 8)
+            {
+                dcScaler = 2 * QP;
+            }
+            else if (QP >= 9 && QP <= 24)
+            {
+                dcScaler = QP + 8;
+            }
+            else
+            {
+                dcScaler = (2 * QP) - 16;
+            }
+        }
+
+        else if (videoComp == OMX_VC_CHROMINANCE)
+        {
+            if (QP >= 1 && QP <= 4)
+            {
+                dcScaler = 8;
+            }
+            else if (QP >= 5 && QP <= 24)
+            {
+                dcScaler = (QP + 13)/2;
+            }
+            else
+            {
+                dcScaler = QP - 6;
+            }
+        }
+    }
+    /* Dequant the DC value, this applies to both the methods */
+    pSrcDst[0] = pSrcDst[0] * dcScaler;
+
+    /* Saturate */
+    pSrcDst[0] = armClip (-2048, 2047, pSrcDst[0]);
+
+    /* Second Inverse quantisation method */
+    for (coeffCount = 1; coeffCount < 64; coeffCount++)
+    {
+        /* check sign */
+        Sign =  armSignCheck (pSrcDst[coeffCount]);  
+
+        if (QP & 0x1)
+        {
+            pSrcDst[coeffCount] = (2* armAbs(pSrcDst[coeffCount]) + 1) * QP;
+            pSrcDst[coeffCount] *= Sign;
+        }
+        else
+        {
+            pSrcDst[coeffCount] =
+                                (2* armAbs(pSrcDst[coeffCount]) + 1) * QP - 1;
+            pSrcDst[coeffCount] *= Sign;
+        }
+
+        /* Saturate */
+        pSrcDst[coeffCount] = armClip (-2048, 2047, pSrcDst[coeffCount]);
+    }
+    return OMX_Sts_NoErr;
+
+}
+
+/* End of file */
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_TransRecBlockCoef_inter.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_TransRecBlockCoef_inter.c
new file mode 100644
index 0000000..6e0c59b
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_TransRecBlockCoef_inter.c
@@ -0,0 +1,108 @@
+/**
+ * 
+ * File Name:  omxVCM4P2_TransRecBlockCoef_inter.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Description:
+ * Contains modules DCT->quant and reconstructing the inter texture data
+ * 
+ */ 
+
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+
+
+/**
+ * Function:  omxVCM4P2_TransRecBlockCoef_inter   (6.2.4.4.5)
+ *
+ * Description:
+ * Implements DCT, and quantizes the DCT coefficients of the inter block 
+ * while reconstructing the texture residual. There is no boundary check for 
+ * the bit stream buffer. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc -pointer to the residuals to be encoded; must be aligned on an 
+ *            16-byte boundary. 
+ *   QP - quantization parameter. 
+ *   shortVideoHeader - binary flag indicating presence of short_video_header; 
+ *                      shortVideoHeader==1 selects linear intra DC mode, and 
+ *                      shortVideoHeader==0 selects non linear intra DC mode. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - pointer to the quantized DCT coefficients buffer; must be aligned 
+ *            on a 16-byte boundary. 
+ *   pRec - pointer to the reconstructed texture residuals; must be aligned 
+ *            on a 16-byte boundary. 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - bad arguments:
+ *    -    At least one of the following pointers is either NULL or 
+ *         not 16-byte aligned: 
+ *            - pSrc 
+ *            - pDst
+ *            - pRec
+ *    -    QP <= 0 or QP >= 32. 
+ *
+ */
+
+OMXResult omxVCM4P2_TransRecBlockCoef_inter(
+     const OMX_S16 *pSrc,
+     OMX_S16 * pDst,
+     OMX_S16 * pRec,
+     OMX_U8 QP,
+     OMX_INT shortVideoHeader
+)
+{
+    /* 64 elements are needed but to align it to 16 bytes need 
+    8 more elements of padding */
+    OMX_S16 tempBuffer[72];
+    OMX_S16 *pTempBuffer;
+    OMX_INT i;
+        
+    /* Aligning the local buffers */
+    pTempBuffer = armAlignTo16Bytes(tempBuffer);
+
+    /* Argument error checks */
+    armRetArgErrIf(pSrc == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pRec == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pDst == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(!armIs16ByteAligned(pSrc), OMX_Sts_BadArgErr);
+    armRetArgErrIf(!armIs16ByteAligned(pRec), OMX_Sts_BadArgErr);
+    armRetArgErrIf(!armIs16ByteAligned(pDst), OMX_Sts_BadArgErr);
+    armRetArgErrIf(((QP <= 0) || (QP >= 32)), OMX_Sts_BadArgErr);
+    
+    omxVCM4P2_DCT8x8blk (pSrc, pDst);
+    omxVCM4P2_QuantInter_I(
+     pDst,
+     QP,
+     shortVideoHeader);
+
+    for (i = 0; i < 64; i++)
+    {
+        pTempBuffer[i] = pDst[i];
+    }
+
+    omxVCM4P2_QuantInvInter_I(
+     pTempBuffer,
+     QP);
+    omxVCM4P2_IDCT8x8blk (pTempBuffer, pRec);
+
+    return OMX_Sts_NoErr;
+}
+
+/* End of file */
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_TransRecBlockCoef_intra.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_TransRecBlockCoef_intra.c
new file mode 100644
index 0000000..dd444f9
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p2/src/omxVCM4P2_TransRecBlockCoef_intra.c
@@ -0,0 +1,260 @@
+/**
+ * 
+ * File Name:  omxVCM4P2_TransRecBlockCoef_intra.c
+ * OpenMAX DL: v1.0.2
+ * Revision:   9641
+ * Date:       Thursday, February 7, 2008
+ * 
+ * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
+ * 
+ * 
+ *
+ * Description:
+ * Contains modules DCT->quant and reconstructing the intra texture data
+ * 
+ */ 
+ 
+#include "omxtypes.h"
+#include "armOMX.h"
+#include "omxVC.h"
+
+#include "armCOMM.h"
+#include "armVC.h"
+
+
+/**
+ * Function:  omxVCM4P2_TransRecBlockCoef_intra   (6.2.4.4.4)
+ *
+ * Description:
+ * Quantizes the DCT coefficients, implements intra block AC/DC coefficient 
+ * prediction, and reconstructs the current intra block texture for prediction 
+ * on the next frame.  Quantized row and column coefficients are returned in 
+ * the updated coefficient buffers. 
+ *
+ * Input Arguments:
+ *   
+ *   pSrc - pointer to the pixels of current intra block; must be aligned on 
+ *            an 8-byte boundary. 
+ *   pPredBufRow - pointer to the coefficient row buffer containing 
+ *            ((num_mb_per_row * 2 + 1) * 8) elements of type OMX_S16. 
+ *            Coefficients are organized into blocks of eight as described 
+ *            below (Internal Prediction Coefficient Update Procedures).  The 
+ *            DC coefficient is first, and the remaining buffer locations 
+ *            contain the quantized AC coefficients. Each group of eight row 
+ *            buffer elements combined with one element eight elements ahead 
+ *            contains the coefficient predictors of the neighboring block 
+ *            that is spatially above or to the left of the block currently to 
+ *            be decoded. A negative-valued DC coefficient indicates that this 
+ *            neighboring block is not INTRA-coded or out of bounds, and 
+ *            therefore the AC and DC coefficients are invalid.  Pointer must 
+ *            be aligned on an 8-byte boundary. 
+ *   pPredBufCol - pointer to the prediction coefficient column buffer 
+ *            containing 16 elements of type OMX_S16. Coefficients are 
+ *            organized as described in section 6.2.2.5.  Pointer must be 
+ *            aligned on an 8-byte boundary. 
+ *   pSumErr - pointer to a flag indicating whether or not AC prediction is 
+ *            required; AC prediction is enabled if *pSumErr >=0, but the 
+ *            value is not used for coefficient prediction, i.e., the sum of 
+ *            absolute differences starts from 0 for each call to this 
+ *            function.  Otherwise AC prediction is disabled if *pSumErr < 0 . 
+ *   blockIndex - block index indicating the component type and position, as 
+ *            defined in [ISO14496-2], subclause 6.1.3.8. 
+ *   curQp - quantization parameter of the macroblock to which the current 
+ *            block belongs 
+ *   pQpBuf - pointer to a 2-element quantization parameter buffer; pQpBuf[0] 
+ *            contains the quantization parameter associated with the 8x8 
+ *            block left of the current block (QPa), and pQpBuf[1] contains 
+ *            the quantization parameter associated with the 8x8 block above 
+ *            the current block (QPc).  In the event that the corresponding 
+ *            block is outside of the VOP bound, the Qp value will not affect 
+ *            the intra prediction process, as described in [ISO14496-2], 
+ *            sub-clause 7.4.3.3,  Adaptive AC Coefficient Prediction.  
+ *   srcStep - width of the source buffer; must be a multiple of 8. 
+ *   dstStep - width of the reconstructed destination buffer; must be a 
+ *            multiple of 16. 
+ *   shortVideoHeader - binary flag indicating presence of 
+ *            short_video_header; shortVideoHeader==1 selects linear intra DC 
+ *            mode, and shortVideoHeader==0 selects non linear intra DC mode. 
+ *
+ * Output Arguments:
+ *   
+ *   pDst - pointer to the quantized DCT coefficient buffer; pDst[0] contains 
+ *            the predicted DC coefficient; the remaining entries contain the 
+ *            quantized AC coefficients (without prediction).  The pointer 
+ *            pDstmust be aligned on a 16-byte boundary. 
+ *   pRec - pointer to the reconstructed texture; must be aligned on an 
+ *            8-byte boundary. 
+ *   pPredBufRow - pointer to the updated coefficient row buffer 
+ *   pPredBufCol - pointer to the updated coefficient column buffer 
+ *   pPreACPredict - if prediction is enabled, the parameter points to the 
+ *            start of the buffer containing the coefficient differences for 
+ *            VLC encoding. The entry pPreACPredict[0]indicates prediction 
+ *            direction for the current block and takes one of the following 
+ *            values: OMX_VC_NONE (prediction disabled), OMX_VC_HORIZONTAL, or 
+ *            OMX_VC_VERTICAL.  The entries 
+ *            pPreACPredict[1]-pPreACPredict[7]contain predicted AC 
+ *            coefficients.  If prediction is disabled (*pSumErr<0) then the 
+ *            contents of this buffer are undefined upon return from the 
+ *            function 
+ *   pSumErr - pointer to the value of the accumulated AC coefficient errors, 
+ *            i.e., sum of the absolute differences between predicted and 
+ *            unpredicted AC coefficients 
+ *
+ * Return Value:
+ *    
+ *    OMX_Sts_NoErr - no error 
+ *    OMX_Sts_BadArgErr - Bad arguments:
+ *    -    At least one of the following pointers is NULL: pSrc, pDst, pRec, 
+ *         pCoefBufRow, pCoefBufCol, pQpBuf, pPreACPredict, pSumErr. 
+ *    -    blockIndex < 0 or blockIndex >= 10; 
+ *    -    curQP <= 0 or curQP >= 32. 
+ *    -    srcStep, or dstStep <= 0 or not a multiple of 8. 
+ *    -    pDst is not 16-byte aligned: . 
+ *    -    At least one of the following pointers is not 8-byte aligned: 
+ *         pSrc, pRec.  
+ *
+ *  Note: The coefficient buffers must be updated in accordance with the 
+ *        update procedures defined in section in 6.2.2. 
+ *
+ */
+
+OMXResult omxVCM4P2_TransRecBlockCoef_intra(
+     const OMX_U8 *pSrc,
+     OMX_S16 * pDst,
+     OMX_U8 * pRec,
+     OMX_S16 *pPredBufRow,
+     OMX_S16 *pPredBufCol,
+     OMX_S16 * pPreACPredict,
+     OMX_INT *pSumErr,
+     OMX_INT blockIndex,
+     OMX_U8 curQp,
+     const OMX_U8 *pQpBuf,
+     OMX_INT srcStep,
+     OMX_INT dstStep,
+	 OMX_INT shortVideoHeader
+)
+{
+    /* 64 elements are needed but to align it to 16 bytes need
+    8 more elements of padding */
+    OMX_S16 tempBuf1[79], tempBuf2[79];
+    OMX_S16 tempBuf3[79];
+    OMX_S16 *pTempBuf1, *pTempBuf2,*pTempBuf3;
+    OMXVCM4P2VideoComponent videoComp;
+    OMX_U8  flag;
+    OMX_INT x, y, count, predDir;
+    OMX_INT predQP, ACPredFlag;
+    
+
+    /* Aligning the local buffers */
+    pTempBuf1 = armAlignTo16Bytes(tempBuf1);
+    pTempBuf2 = armAlignTo16Bytes(tempBuf2);
+    pTempBuf3 = armAlignTo16Bytes(tempBuf3);
+
+    /* Argument error checks */
+    armRetArgErrIf(pSrc == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pRec == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pDst == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(!armIs8ByteAligned(pSrc), OMX_Sts_BadArgErr);
+    armRetArgErrIf(!armIs8ByteAligned(pRec), OMX_Sts_BadArgErr);
+    armRetArgErrIf(!armIs16ByteAligned(pDst), OMX_Sts_BadArgErr);
+    armRetArgErrIf(pPredBufRow == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pPredBufCol == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pPreACPredict == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pSumErr == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf(pQpBuf == NULL, OMX_Sts_BadArgErr);
+    armRetArgErrIf((srcStep <= 0) || (dstStep <= 0) ||
+                (dstStep & 7) || (srcStep & 7)
+                , OMX_Sts_BadArgErr);
+    armRetArgErrIf((blockIndex < 0) || (blockIndex > 9), OMX_Sts_BadArgErr);
+
+    armRetArgErrIf((curQp <= 0) || (curQp >=32), OMX_Sts_BadArgErr);
+
+
+   /* Setting the videoComp */
+    if (blockIndex <= 3)
+    {
+        videoComp = OMX_VC_LUMINANCE;
+    }
+    else
+    {
+        videoComp = OMX_VC_CHROMINANCE;
+    }
+    /* Converting from 2-d to 1-d buffer */
+    for (y = 0, count = 0; y < 8; y++)
+    {
+        for(x= 0; x < 8; x++, count++)
+        {
+            pTempBuf1[count] = pSrc[(y*srcStep) + x];
+        }
+    }
+
+    omxVCM4P2_DCT8x8blk  (pTempBuf1, pTempBuf2);
+    omxVCM4P2_QuantIntra_I(
+        pTempBuf2,
+        curQp,
+        blockIndex,
+        shortVideoHeader);
+
+    /* Converting from 1-D to 2-D buffer */
+    for (y = 0, count = 0; y < 8; y++)
+    {
+        for(x = 0; x < 8; x++, count++)
+        {
+            /* storing tempbuf2 to tempbuf1 */
+            pTempBuf1[count] = pTempBuf2[count];
+            pDst[(y*dstStep) + x] = pTempBuf2[count];
+        }
+    }
+
+    /* AC and DC prediction */
+    armVCM4P2_SetPredDir(
+        blockIndex,
+        pPredBufRow,
+        pPredBufCol,
+        &predDir,
+        &predQP,
+        pQpBuf);
+
+    armRetDataErrIf(((predQP <= 0) || (predQP >= 32)), OMX_Sts_BadArgErr);
+
+    flag = 1;
+    if (*pSumErr < 0)
+    {
+        ACPredFlag = 0;
+    }
+    else
+    {
+        ACPredFlag = 1;
+    }
+
+    armVCM4P2_ACDCPredict(
+        pTempBuf2,
+        pPreACPredict,
+        pPredBufRow,
+        pPredBufCol,
+        curQp,
+        predQP,
+        predDir,
+        ACPredFlag,
+        videoComp,
+        flag,
+        pSumErr);
+
+    /* Reconstructing the texture data */
+    omxVCM4P2_QuantInvIntra_I(
+        pTempBuf1,
+        curQp,
+        videoComp,
+        shortVideoHeader);
+    omxVCM4P2_IDCT8x8blk (pTempBuf1, pTempBuf3);
+    for(count = 0; count < 64; count++)
+    {
+        pRec[count] = armMax(0,pTempBuf3[count]);
+    }
+
+    return OMX_Sts_NoErr;
+}
+
+/* End of file */
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/src/armVC_Version.c b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/src/armVC_Version.c
new file mode 100644
index 0000000..5d93681
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/src/armVC_Version.c
@@ -0,0 +1,6 @@
+#include "omxtypes.h"
+#include "armCOMM_Version.h"
+
+#ifdef ARM_INCLUDE_VERSION_DESCRIPTIONS
+const char * const omxVC_VersionDescription = "ARM OpenMAX DL v" ARM_VERSION_STRING "   Rel=" OMX_ARM_RELEASE_TAG "   Arch=" OMX_ARM_BUILD_ARCHITECTURE "   Tools="  OMX_ARM_BUILD_TOOLCHAIN ;
+#endif /* ARM_INCLUDE_VERSION_DESCRIPTIONS */
diff --git a/media/libstagefright/codecs/on2/h264dec/source/DecTestBench.c b/media/libstagefright/codecs/on2/h264dec/source/DecTestBench.c
new file mode 100755
index 0000000..dcf2ef6
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/DecTestBench.c
@@ -0,0 +1,761 @@
+/*
+ * 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.
+ */
+
+#include "H264SwDecApi.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/*------------------------------------------------------------------------------
+    Module defines
+------------------------------------------------------------------------------*/
+
+/* CHECK_MEMORY_USAGE prints and sums the memory allocated in calls to
+ * H264SwDecMalloc() */
+/* #define CHECK_MEMORY_USAGE */
+
+/* _NO_OUT disables output file writing */
+/* #define _NO_OUT */
+
+/* Debug prints */
+#define DEBUG(argv) printf argv
+
+/* CVS tag name for identification */
+const char tagName[256] = "$Name: FIRST_ANDROID_COPYRIGHT $";
+
+void WriteOutput(char *filename, u8 *data, u32 picSize);
+u32 NextPacket(u8 **pStrm);
+u32 CropPicture(u8 *pOutImage, u8 *pInImage,
+    u32 picWidth, u32 picHeight, CropParams *pCropParams);
+
+/* Global variables for stream handling */
+u8 *streamStop = NULL;
+u32 packetize = 0;
+u32 nalUnitStream = 0;
+FILE *foutput = NULL;
+
+#ifdef SOC_DESIGNER
+
+// Initialisation function defined in InitCache.s
+extern void cache_init(void);
+
+/*------------------------------------------------------------------------------
+
+    Function name:  $Sub$$main
+
+    Purpose:
+        This function is called at the end of the C library initialisation and
+        before main. Its purpose is to do any further initialisation before the
+        application start.
+
+------------------------------------------------------------------------------*/
+int $Sub$$main(char argc, char * argv[])
+{
+  cache_init();                    // does some extra setup work setting up caches
+  return $Super$$main(argc, argv); // calls the original function
+}
+#endif
+
+/*------------------------------------------------------------------------------
+
+    Function name:  main
+
+    Purpose:
+        main function of decoder testbench. Provides command line interface
+        with file I/O for H.264 decoder. Prints out the usage information
+        when executed without arguments.
+
+------------------------------------------------------------------------------*/
+
+int main(int argc, char **argv)
+{
+
+    u32 i, tmp;
+    u32 maxNumPics = 0;
+    u8 *byteStrmStart;
+    u8 *imageData;
+    u8 *tmpImage = NULL;
+    u32 strmLen;
+    u32 picSize;
+    H264SwDecInst decInst;
+    H264SwDecRet ret;
+    H264SwDecInput decInput;
+    H264SwDecOutput decOutput;
+    H264SwDecPicture decPicture;
+    H264SwDecInfo decInfo;
+    H264SwDecApiVersion decVer;
+    u32 picDecodeNumber;
+    u32 picDisplayNumber;
+    u32 numErrors = 0;
+    u32 cropDisplay = 0;
+    u32 disableOutputReordering = 0;
+
+    FILE *finput;
+
+    char outFileName[256] = "";
+
+    /* Print API version number */
+    decVer = H264SwDecGetAPIVersion();
+    DEBUG(("H.264 Decoder API v%d.%d\n", decVer.major, decVer.minor));
+
+    /* Print tag name if '-T' argument present */
+    if ( argc > 1 && strcmp(argv[1], "-T") == 0 )
+    {
+        DEBUG(("%s\n", tagName));
+        return 0;
+    }
+
+    /* Check that enough command line arguments given, if not -> print usage
+     * information out */
+    if (argc < 2)
+    {
+        DEBUG((
+            "Usage: %s [-Nn] [-Ooutfile] [-P] [-U] [-C] [-R] [-T] file.h264\n",
+            argv[0]));
+        DEBUG(("\t-Nn forces decoding to stop after n pictures\n"));
+#if defined(_NO_OUT)
+        DEBUG(("\t-Ooutfile output writing disabled at compile time\n"));
+#else
+        DEBUG(("\t-Ooutfile write output to \"outfile\" (default out_wxxxhyyy.yuv)\n"));
+        DEBUG(("\t-Onone does not write output\n"));
+#endif
+        DEBUG(("\t-P packet-by-packet mode\n"));
+        DEBUG(("\t-U NAL unit stream mode\n"));
+        DEBUG(("\t-C display cropped image (default decoded image)\n"));
+        DEBUG(("\t-R disable DPB output reordering\n"));
+        DEBUG(("\t-T to print tag name and exit\n"));
+        return 0;
+    }
+
+    /* read command line arguments */
+    for (i = 1; i < (u32)(argc-1); i++)
+    {
+        if ( strncmp(argv[i], "-N", 2) == 0 )
+        {
+            maxNumPics = (u32)atoi(argv[i]+2);
+        }
+        else if ( strncmp(argv[i], "-O", 2) == 0 )
+        {
+            strcpy(outFileName, argv[i]+2);
+        }
+        else if ( strcmp(argv[i], "-P") == 0 )
+        {
+            packetize = 1;
+        }
+        else if ( strcmp(argv[i], "-U") == 0 )
+        {
+            nalUnitStream = 1;
+        }
+        else if ( strcmp(argv[i], "-C") == 0 )
+        {
+            cropDisplay = 1;
+        }
+        else if ( strcmp(argv[i], "-R") == 0 )
+        {
+            disableOutputReordering = 1;
+        }
+    }
+
+    /* open input file for reading, file name given by user. If file open
+     * fails -> exit */
+    finput = fopen(argv[argc-1],"rb");
+    if (finput == NULL)
+    {
+        DEBUG(("UNABLE TO OPEN INPUT FILE\n"));
+        return -1;
+    }
+
+    /* check size of the input file -> length of the stream in bytes */
+    fseek(finput,0L,SEEK_END);
+    strmLen = (u32)ftell(finput);
+    rewind(finput);
+
+    /* allocate memory for stream buffer. if unsuccessful -> exit */
+    byteStrmStart = (u8 *)malloc(sizeof(u8)*strmLen);
+    if (byteStrmStart == NULL)
+    {
+        DEBUG(("UNABLE TO ALLOCATE MEMORY\n"));
+        return -1;
+    }
+
+    /* read input stream from file to buffer and close input file */
+    fread(byteStrmStart, sizeof(u8), strmLen, finput);
+    fclose(finput);
+
+    /* initialize decoder. If unsuccessful -> exit */
+    ret = H264SwDecInit(&decInst, disableOutputReordering);
+    if (ret != H264SWDEC_OK)
+    {
+        DEBUG(("DECODER INITIALIZATION FAILED\n"));
+        free(byteStrmStart);
+        return -1;
+    }
+
+    /* initialize H264SwDecDecode() input structure */
+    streamStop = byteStrmStart + strmLen;
+    decInput.pStream = byteStrmStart;
+    decInput.dataLen = strmLen;
+    decInput.intraConcealmentMethod = 0;
+
+    /* get pointer to next packet and the size of packet
+     * (for packetize or nalUnitStream modes) */
+    if ( (tmp = NextPacket(&decInput.pStream)) != 0 )
+        decInput.dataLen = tmp;
+
+    picDecodeNumber = picDisplayNumber = 1;
+    /* main decoding loop */
+    do
+    {
+        /* Picture ID is the picture number in decoding order */
+        decInput.picId = picDecodeNumber;
+
+        /* call API function to perform decoding */
+        ret = H264SwDecDecode(decInst, &decInput, &decOutput);
+
+        switch(ret)
+        {
+
+            case H264SWDEC_HDRS_RDY_BUFF_NOT_EMPTY:
+                /* Stream headers were successfully decoded
+                 * -> stream information is available for query now */
+
+                ret = H264SwDecGetInfo(decInst, &decInfo);
+                if (ret != H264SWDEC_OK)
+                    return -1;
+
+                DEBUG(("Profile %d\n", decInfo.profile));
+
+                DEBUG(("Width %d Height %d\n",
+                    decInfo.picWidth, decInfo.picHeight));
+
+                if (cropDisplay && decInfo.croppingFlag)
+                {
+                    DEBUG(("Cropping params: (%d, %d) %dx%d\n",
+                        decInfo.cropParams.cropLeftOffset,
+                        decInfo.cropParams.cropTopOffset,
+                        decInfo.cropParams.cropOutWidth,
+                        decInfo.cropParams.cropOutHeight));
+
+                    /* Cropped frame size in planar YUV 4:2:0 */
+                    picSize = decInfo.cropParams.cropOutWidth *
+                              decInfo.cropParams.cropOutHeight;
+                    picSize = (3 * picSize)/2;
+                    tmpImage = malloc(picSize);
+                    if (tmpImage == NULL)
+                        return -1;
+                }
+                else
+                {
+                    /* Decoder output frame size in planar YUV 4:2:0 */
+                    picSize = decInfo.picWidth * decInfo.picHeight;
+                    picSize = (3 * picSize)/2;
+                }
+
+                DEBUG(("videoRange %d, matrixCoefficients %d\n",
+                    decInfo.videoRange, decInfo.matrixCoefficients));
+
+                /* update H264SwDecDecode() input structure, number of bytes
+                 * "consumed" is computed as difference between the new stream
+                 * pointer and old stream pointer */
+                decInput.dataLen -=
+                    (u32)(decOutput.pStrmCurrPos - decInput.pStream);
+                decInput.pStream = decOutput.pStrmCurrPos;
+
+                /* If -O option not used, generate default file name */
+                if (outFileName[0] == 0)
+                    sprintf(outFileName, "out_w%dh%d.yuv",
+                            decInfo.picWidth, decInfo.picHeight);
+                break;
+
+            case H264SWDEC_PIC_RDY_BUFF_NOT_EMPTY:
+                /* Picture is ready and more data remains in input buffer
+                 * -> update H264SwDecDecode() input structure, number of bytes
+                 * "consumed" is computed as difference between the new stream
+                 * pointer and old stream pointer */
+                decInput.dataLen -=
+                    (u32)(decOutput.pStrmCurrPos - decInput.pStream);
+                decInput.pStream = decOutput.pStrmCurrPos;
+                /* fall through */
+
+            case H264SWDEC_PIC_RDY:
+
+                /*lint -esym(644,tmpImage,picSize) variable initialized at
+                 * H264SWDEC_HDRS_RDY_BUFF_NOT_EMPTY case */
+
+                if (ret == H264SWDEC_PIC_RDY)
+                    decInput.dataLen = NextPacket(&decInput.pStream);
+
+                /* If enough pictures decoded -> force decoding to end
+                 * by setting that no more stream is available */
+                if (maxNumPics && picDecodeNumber == maxNumPics)
+                    decInput.dataLen = 0;
+
+                /* Increment decoding number for every decoded picture */
+                picDecodeNumber++;
+
+                /* use function H264SwDecNextPicture() to obtain next picture
+                 * in display order. Function is called until no more images
+                 * are ready for display */
+                while ( H264SwDecNextPicture(decInst, &decPicture, 0) ==
+                        H264SWDEC_PIC_RDY )
+                {
+                    DEBUG(("PIC %d, type %s", picDisplayNumber,
+                        decPicture.isIdrPicture ? "IDR" : "NON-IDR"));
+                    if (picDisplayNumber != decPicture.picId)
+                        DEBUG((", decoded pic %d", decPicture.picId));
+                    if (decPicture.nbrOfErrMBs)
+                    {
+                        DEBUG((", concealed %d\n", decPicture.nbrOfErrMBs));
+                    }
+                    else
+                        DEBUG(("\n"));
+                    fflush(stdout);
+
+                    numErrors += decPicture.nbrOfErrMBs;
+
+                    /* Increment display number for every displayed picture */
+                    picDisplayNumber++;
+
+                    /*lint -esym(644,decInfo) always initialized if pictures
+                     * available for display */
+
+                    /* Write output picture to file */
+                    imageData = (u8*)decPicture.pOutputPicture;
+                    if (cropDisplay && decInfo.croppingFlag)
+                    {
+                        tmp = CropPicture(tmpImage, imageData,
+                            decInfo.picWidth, decInfo.picHeight,
+                            &decInfo.cropParams);
+                        if (tmp)
+                            return -1;
+                        WriteOutput(outFileName, tmpImage, picSize);
+                    }
+                    else
+                    {
+                        WriteOutput(outFileName, imageData, picSize);
+                    }
+                }
+
+                break;
+
+            case H264SWDEC_STRM_PROCESSED:
+            case H264SWDEC_STRM_ERR:
+                /* Input stream was decoded but no picture is ready
+                 * -> Get more data */
+                decInput.dataLen = NextPacket(&decInput.pStream);
+                break;
+
+            default:
+                DEBUG(("FATAL ERROR\n"));
+                return -1;
+
+        }
+    /* keep decoding until all data from input stream buffer consumed */
+    } while (decInput.dataLen > 0);
+
+    /* if output in display order is preferred, the decoder shall be forced
+     * to output pictures remaining in decoded picture buffer. Use function
+     * H264SwDecNextPicture() to obtain next picture in display order. Function
+     * is called until no more images are ready for display. Second parameter
+     * for the function is set to '1' to indicate that this is end of the
+     * stream and all pictures shall be output */
+    while (H264SwDecNextPicture(decInst, &decPicture, 1) == H264SWDEC_PIC_RDY)
+    {
+        DEBUG(("PIC %d, type %s", picDisplayNumber,
+            decPicture.isIdrPicture ? "IDR" : "NON-IDR"));
+        if (picDisplayNumber != decPicture.picId)
+            DEBUG((", decoded pic %d", decPicture.picId));
+        if (decPicture.nbrOfErrMBs)
+        {
+            DEBUG((", concealed %d\n", decPicture.nbrOfErrMBs));
+        }
+        else
+            DEBUG(("\n"));
+        fflush(stdout);
+
+        numErrors += decPicture.nbrOfErrMBs;
+
+        /* Increment display number for every displayed picture */
+        picDisplayNumber++;
+
+        /* Write output picture to file */
+        imageData = (u8*)decPicture.pOutputPicture;
+        if (cropDisplay && decInfo.croppingFlag)
+        {
+            tmp = CropPicture(tmpImage, imageData,
+                decInfo.picWidth, decInfo.picHeight,
+                &decInfo.cropParams);
+            if (tmp)
+                return -1;
+            WriteOutput(outFileName, tmpImage, picSize);
+        }
+        else
+        {
+            WriteOutput(outFileName, imageData, picSize);
+        }
+    }
+
+    /* release decoder instance */
+    H264SwDecRelease(decInst);
+
+    if (foutput)
+        fclose(foutput);
+
+    /* free allocated buffers */
+    free(byteStrmStart);
+    free(tmpImage);
+
+    DEBUG(("Output file: %s\n", outFileName));
+
+    DEBUG(("DECODING DONE\n"));
+    if (numErrors || picDecodeNumber == 1)
+    {
+        DEBUG(("ERRORS FOUND\n"));
+        return 1;
+    }
+
+    return 0;
+}
+
+/*------------------------------------------------------------------------------
+
+    Function name:  WriteOutput
+
+    Purpose:
+        Write picture pointed by data to file. Size of the
+        picture in pixels is indicated by picSize.
+
+------------------------------------------------------------------------------*/
+void WriteOutput(char *filename, u8 *data, u32 picSize)
+{
+
+    /* foutput is global file pointer */
+    if (foutput == NULL)
+    {
+        /* open output file for writing, can be disabled with define.
+         * If file open fails -> exit */
+        if (strcmp(filename, "none") != 0)
+        {
+#if !defined(_NO_OUT)
+            foutput = fopen(filename, "wb");
+            if (foutput == NULL)
+            {
+                DEBUG(("UNABLE TO OPEN OUTPUT FILE\n"));
+                exit(100);
+            }
+#endif
+        }
+    }
+
+    if (foutput && data)
+        fwrite(data, 1, picSize, foutput);
+}
+
+/*------------------------------------------------------------------------------
+
+    Function name: NextPacket
+
+    Purpose:
+        Get the pointer to start of next packet in input stream. Uses
+        global variables 'packetize' and 'nalUnitStream' to determine the
+        decoder input stream mode and 'streamStop' to determine the end
+        of stream. There are three possible stream modes:
+            default - the whole stream at once
+            packetize - a single NAL-unit with start code prefix
+            nalUnitStream - a single NAL-unit without start code prefix
+
+        pStrm stores pointer to the start of previous decoder input and is
+        replaced with pointer to the start of the next decoder input.
+
+        Returns the packet size in bytes
+
+------------------------------------------------------------------------------*/
+u32 NextPacket(u8 **pStrm)
+{
+
+    u32 index;
+    u32 maxIndex;
+    u32 zeroCount;
+    u8 *stream;
+    u8 byte;
+    static u32 prevIndex=0;
+
+    /* For default stream mode all the stream is in first packet */
+    if (!packetize && !nalUnitStream)
+        return 0;
+
+    index = 0;
+    stream = *pStrm + prevIndex;
+    maxIndex = (u32)(streamStop - stream);
+
+    if (maxIndex == 0)
+        return(0);
+
+    /* leading zeros of first NAL unit */
+    do
+    {
+        byte = stream[index++];
+    } while (byte != 1 && index < maxIndex);
+
+    /* invalid start code prefix */
+    if (index == maxIndex || index < 3)
+    {
+        DEBUG(("INVALID BYTE STREAM\n"));
+        exit(100);
+    }
+
+    /* nalUnitStream is without start code prefix */
+    if (nalUnitStream)
+    {
+        stream += index;
+        maxIndex -= index;
+        index = 0;
+    }
+
+    zeroCount = 0;
+
+    /* Search stream for next start code prefix */
+    /*lint -e(716) while(1) used consciously */
+    while (1)
+    {
+        byte = stream[index++];
+        if (!byte)
+            zeroCount++;
+
+        if ( (byte == 0x01) && (zeroCount >= 2) )
+        {
+            /* Start code prefix has two zeros
+             * Third zero is assumed to be leading zero of next packet
+             * Fourth and more zeros are assumed to be trailing zeros of this
+             * packet */
+            if (zeroCount > 3)
+            {
+                index -= 4;
+                zeroCount -= 3;
+            }
+            else
+            {
+                index -= zeroCount+1;
+                zeroCount = 0;
+            }
+            break;
+        }
+        else if (byte)
+            zeroCount = 0;
+
+        if (index == maxIndex)
+        {
+            break;
+        }
+
+    }
+
+    /* Store pointer to the beginning of the packet */
+    *pStrm = stream;
+    prevIndex = index;
+
+    /* nalUnitStream is without trailing zeros */
+    if (nalUnitStream)
+        index -= zeroCount;
+
+    return(index);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function name: CropPicture
+
+    Purpose:
+        Perform cropping for picture. Input picture pInImage with dimensions
+        picWidth x picHeight is cropped with pCropParams and the resulting
+        picture is stored in pOutImage.
+
+------------------------------------------------------------------------------*/
+u32 CropPicture(u8 *pOutImage, u8 *pInImage,
+    u32 picWidth, u32 picHeight, CropParams *pCropParams)
+{
+
+    u32 i, j;
+    u32 outWidth, outHeight;
+    u8 *pOut, *pIn;
+
+    if (pOutImage == NULL || pInImage == NULL || pCropParams == NULL ||
+        !picWidth || !picHeight)
+    {
+        /* just to prevent lint warning, returning non-zero will result in
+         * return without freeing the memory */
+        free(pOutImage);
+        return(1);
+    }
+
+    if ( ((pCropParams->cropLeftOffset + pCropParams->cropOutWidth) >
+           picWidth ) ||
+         ((pCropParams->cropTopOffset + pCropParams->cropOutHeight) >
+           picHeight ) )
+    {
+        /* just to prevent lint warning, returning non-zero will result in
+         * return without freeing the memory */
+        free(pOutImage);
+        return(1);
+    }
+
+    outWidth = pCropParams->cropOutWidth;
+    outHeight = pCropParams->cropOutHeight;
+
+    /* Calculate starting pointer for luma */
+    pIn = pInImage + pCropParams->cropTopOffset*picWidth +
+        pCropParams->cropLeftOffset;
+    pOut = pOutImage;
+
+    /* Copy luma pixel values */
+    for (i = outHeight; i; i--)
+    {
+        for (j = outWidth; j; j--)
+        {
+            *pOut++ = *pIn++;
+        }
+        pIn += picWidth - outWidth;
+    }
+
+    outWidth >>= 1;
+    outHeight >>= 1;
+
+    /* Calculate starting pointer for cb */
+    pIn = pInImage + picWidth*picHeight +
+        pCropParams->cropTopOffset*picWidth/4 + pCropParams->cropLeftOffset/2;
+
+    /* Copy cb pixel values */
+    for (i = outHeight; i; i--)
+    {
+        for (j = outWidth; j; j--)
+        {
+            *pOut++ = *pIn++;
+        }
+        pIn += picWidth/2 - outWidth;
+    }
+
+    /* Calculate starting pointer for cr */
+    pIn = pInImage + 5*picWidth*picHeight/4 +
+        pCropParams->cropTopOffset*picWidth/4 + pCropParams->cropLeftOffset/2;
+
+    /* Copy cr pixel values */
+    for (i = outHeight; i; i--)
+    {
+        for (j = outWidth; j; j--)
+        {
+            *pOut++ = *pIn++;
+        }
+        pIn += picWidth/2 - outWidth;
+    }
+
+    return (0);
+}
+
+/*------------------------------------------------------------------------------
+
+    Function name:  H264SwDecTrace
+
+    Purpose:
+        Example implementation of H264SwDecTrace function. Prototype of this
+        function is given in H264SwDecApi.h. This implementation appends
+        trace messages to file named 'dec_api.trc'.
+
+------------------------------------------------------------------------------*/
+void H264SwDecTrace(char *string)
+{
+    FILE *fp;
+
+    fp = fopen("dec_api.trc", "at");
+
+    if (!fp)
+        return;
+
+    fwrite(string, 1, strlen(string), fp);
+    fwrite("\n", 1,1, fp);
+
+    fclose(fp);
+}
+
+/*------------------------------------------------------------------------------
+
+    Function name:  H264SwDecMalloc
+
+    Purpose:
+        Example implementation of H264SwDecMalloc function. Prototype of this
+        function is given in H264SwDecApi.h. This implementation uses
+        library function malloc for allocation of memory.
+
+------------------------------------------------------------------------------*/
+void* H264SwDecMalloc(u32 size)
+{
+
+#if defined(CHECK_MEMORY_USAGE)
+    /* Note that if the decoder has to free and reallocate some of the buffers
+     * the total value will be invalid */
+    static u32 numBytes = 0;
+    numBytes += size;
+    DEBUG(("Allocated %d bytes, total %d\n", size, numBytes));
+#endif
+
+    return malloc(size);
+}
+
+/*------------------------------------------------------------------------------
+
+    Function name:  H264SwDecFree
+
+    Purpose:
+        Example implementation of H264SwDecFree function. Prototype of this
+        function is given in H264SwDecApi.h. This implementation uses
+        library function free for freeing of memory.
+
+------------------------------------------------------------------------------*/
+void H264SwDecFree(void *ptr)
+{
+    free(ptr);
+}
+
+/*------------------------------------------------------------------------------
+
+    Function name:  H264SwDecMemcpy
+
+    Purpose:
+        Example implementation of H264SwDecMemcpy function. Prototype of this
+        function is given in H264SwDecApi.h. This implementation uses
+        library function memcpy to copy src to dest.
+
+------------------------------------------------------------------------------*/
+void H264SwDecMemcpy(void *dest, void *src, u32 count)
+{
+    memcpy(dest, src, count);
+}
+
+/*------------------------------------------------------------------------------
+
+    Function name:  H264SwDecMemset
+
+    Purpose:
+        Example implementation of H264SwDecMemset function. Prototype of this
+        function is given in H264SwDecApi.h. This implementation uses
+        library function memset to set content of memory area pointed by ptr.
+
+------------------------------------------------------------------------------*/
+void H264SwDecMemset(void *ptr, i32 value, u32 count)
+{
+    memset(ptr, value, count);
+}
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/EvaluationTestBench.c b/media/libstagefright/codecs/on2/h264dec/source/EvaluationTestBench.c
new file mode 100755
index 0000000..aadc75f
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/EvaluationTestBench.c
@@ -0,0 +1,350 @@
+/*
+ * 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.
+ */
+
+#include "H264SwDecApi.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+void WriteOutput(FILE *fid, u8 *data, u32 picSize);
+
+/*------------------------------------------------------------------------------
+
+    Function name:  main
+
+    Purpose:
+        main function. Assuming that executable is named 'decoder' the usage
+        is as follows
+
+            decoder inputFileName
+
+        , where inputFileName shall be name of file containing h264 stream
+        data.
+
+------------------------------------------------------------------------------*/
+int main(int argc, char **argv)
+{
+
+    u8 *byteStrmStart;
+    u8 *byteStrm;
+    u32 strmLen;
+    u32 picSize;
+    H264SwDecInst decInst;
+    H264SwDecRet ret;
+    H264SwDecInput decInput;
+    H264SwDecOutput decOutput;
+    H264SwDecPicture decPicture;
+    H264SwDecInfo decInfo;
+    u32 picNumber;
+
+    FILE *finput;
+    FILE *foutput;
+
+    /* Check that enough command line arguments given, if not -> print usage
+     * information out */
+    if (argc < 2)
+    {
+        printf( "Usage: %s file.h264\n", argv[0]);
+        return -1;
+    }
+
+    /* open output file for writing, output file named out.yuv. If file open
+     * fails -> exit */
+    foutput = fopen("out.yuv", "wb");
+    if (foutput == NULL)
+    {
+        printf("UNABLE TO OPEN OUTPUT FILE\n");
+        return -1;
+    }
+
+    /* open input file for reading, file name given by user. If file open
+     * fails -> exit */
+    finput = fopen(argv[argc-1], "rb");
+    if (finput == NULL)
+    {
+        printf("UNABLE TO OPEN INPUT FILE\n");
+        return -1;
+    }
+
+    /* check size of the input file -> length of the stream in bytes */
+    fseek(finput, 0L, SEEK_END);
+    strmLen = (u32)ftell(finput);
+    rewind(finput);
+
+    /* allocate memory for stream buffer, exit if unsuccessful */
+    byteStrm = byteStrmStart = (u8 *)H264SwDecMalloc(sizeof(u8)*strmLen);
+    if (byteStrm == NULL)
+    {
+        printf("UNABLE TO ALLOCATE MEMORY\n");
+        return -1;
+    }
+
+    /* read input stream from file to buffer and close input file */
+    fread(byteStrm, sizeof(u8), strmLen, finput);
+    fclose(finput);
+
+    /* initialize decoder. If unsuccessful -> exit */
+    ret = H264SwDecInit(&decInst, 0);
+    if (ret != H264SWDEC_OK)
+    {
+        printf("DECODER INITIALIZATION FAILED\n");
+        return -1;
+    }
+
+    /* initialize H264SwDecDecode() input structure */
+    decInput.pStream = byteStrmStart;
+    decInput.dataLen = strmLen;
+    decInput.intraConcealmentMethod = 0;
+
+    picNumber = 0;
+
+    /* For performance measurements, read the start time (in seconds) here.
+     * The decoding time should be measured over several frames and after
+     * that average fps (frames/second) can be calculated.
+     *
+     * startTime = GetTime();
+     *
+     * To prevent calculating file I/O latensies as a decoding time,
+     * comment out WriteOutput function call. Also prints to stdout might
+     * consume considerable amount of cycles during measurement */
+
+    /* main decoding loop */
+    do
+    {
+        /* call API function to perform decoding */
+        ret = H264SwDecDecode(decInst, &decInput, &decOutput);
+
+        switch(ret)
+        {
+
+            case H264SWDEC_HDRS_RDY_BUFF_NOT_EMPTY:
+
+                /* picture dimensions are available for query now */
+                ret = H264SwDecGetInfo(decInst, &decInfo);
+                if (ret != H264SWDEC_OK)
+                    return -1;
+
+                /* picture size in pixels */
+                picSize = decInfo.picWidth * decInfo.picHeight;
+                /* memory needed for YCbCr 4:2:0 picture in bytes */
+                picSize = (3 * picSize)/2;
+                /* memory needed for 16-bit RGB picture in bytes
+                 * picSize = (decInfo.picWidth * decInfo.picHeight) * 2; */
+
+                printf("Width %d Height %d\n",
+                    decInfo.picWidth, decInfo.picHeight);
+
+                /* update H264SwDecDecode() input structure, number of bytes
+                 * "consumed" is computed as difference between the new stream
+                 * pointer and old stream pointer */
+                decInput.dataLen -=
+                    (u32)(decOutput.pStrmCurrPos - decInput.pStream);
+                decInput.pStream = decOutput.pStrmCurrPos;
+                break;
+
+            case H264SWDEC_PIC_RDY_BUFF_NOT_EMPTY:
+            case H264SWDEC_PIC_RDY:
+
+                /* update H264SwDecDecode() input structure, number of bytes
+                 * "consumed" is computed as difference between the new stream
+                 * pointer and old stream pointer */
+                decInput.dataLen -=
+                    (u32)(decOutput.pStrmCurrPos - decInput.pStream);
+                decInput.pStream = decOutput.pStrmCurrPos;
+
+                /* use function H264SwDecNextPicture() to obtain next picture
+                 * in display order. Function is called until no more images
+                 * are ready for display */
+                while (H264SwDecNextPicture(decInst, &decPicture, 0) ==
+                    H264SWDEC_PIC_RDY) { picNumber++;
+
+                    printf("PIC %d, type %s, concealed %d\n", picNumber,
+                        decPicture.isIdrPicture ? "IDR" : "NON-IDR",
+                        decPicture.nbrOfErrMBs);
+                    fflush(stdout);
+
+                    /* Do color conversion if needed to get display image
+                     * in RGB-format
+                     *
+                     * YuvToRgb( decPicture.pOutputPicture, pRgbPicture ); */
+
+                    /* write next display image to output file */
+                    WriteOutput(foutput, (u8*)decPicture.pOutputPicture,
+                        picSize);
+                }
+
+                break;
+
+            case H264SWDEC_EVALUATION_LIMIT_EXCEEDED:
+                /* evaluation version of the decoder has limited decoding
+                 * capabilities */
+                printf("EVALUATION LIMIT REACHED\n");
+                goto end;
+
+            default:
+                printf("UNRECOVERABLE ERROR\n");
+                return -1;
+        }
+    /* keep decoding until all data from input stream buffer consumed */
+    } while (decInput.dataLen > 0);
+
+end:
+
+    /* if output in display order is preferred, the decoder shall be forced
+     * to output pictures remaining in decoded picture buffer. Use function
+     * H264SwDecNextPicture() to obtain next picture in display order. Function
+     * is called until no more images are ready for display. Second parameter
+     * for the function is set to '1' to indicate that this is end of the
+     * stream and all pictures shall be output */
+    while (H264SwDecNextPicture(decInst, &decPicture, 1) ==
+        H264SWDEC_PIC_RDY) {
+
+        picNumber++;
+
+        printf("PIC %d, type %s, concealed %d\n", picNumber,
+            decPicture.isIdrPicture ? "IDR" : "NON-IDR",
+            decPicture.nbrOfErrMBs);
+        fflush(stdout);
+
+        /* Do color conversion if needed to get display image
+         * in RGB-format
+         *
+         * YuvToRgb( decPicture.pOutputPicture, pRgbPicture ); */
+
+        /* write next display image to output file */
+        WriteOutput(foutput, (u8*)decPicture.pOutputPicture, picSize);
+    }
+
+    /* For performance measurements, read the end time (in seconds) here.
+     *
+     * endTime = GetTime();
+     *
+     * Now the performance can be calculated as frames per second:
+     * fps = picNumber / (endTime - startTime); */
+
+
+    /* release decoder instance */
+    H264SwDecRelease(decInst);
+
+    /* close output file */
+    fclose(foutput);
+
+    /* free byte stream buffer */
+    free(byteStrmStart);
+
+    return 0;
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function name:  WriteOutput
+
+    Purpose:
+        Write picture pointed by data to file pointed by fid. Size of the
+        picture in pixels is indicated by picSize.
+
+------------------------------------------------------------------------------*/
+void WriteOutput(FILE *fid, u8 *data, u32 picSize)
+{
+    fwrite(data, 1, picSize, fid);
+}
+
+/*------------------------------------------------------------------------------
+
+    Function name:  H264SwDecTrace
+
+    Purpose:
+        Example implementation of H264SwDecTrace function. Prototype of this
+        function is given in H264SwDecApi.h. This implementation appends
+        trace messages to file named 'dec_api.trc'.
+
+------------------------------------------------------------------------------*/
+void H264SwDecTrace(char *string)
+{
+    FILE *fp;
+
+    fp = fopen("dec_api.trc", "at");
+
+    if (!fp)
+        return;
+
+    fwrite(string, 1, strlen(string), fp);
+    fwrite("\n", 1,1, fp);
+
+    fclose(fp);
+}
+
+/*------------------------------------------------------------------------------
+
+    Function name:  H264SwDecmalloc
+
+    Purpose:
+        Example implementation of H264SwDecMalloc function. Prototype of this
+        function is given in H264SwDecApi.h. This implementation uses
+        library function malloc for allocation of memory.
+
+------------------------------------------------------------------------------*/
+void* H264SwDecMalloc(u32 size)
+{
+    return malloc(size);
+}
+
+/*------------------------------------------------------------------------------
+
+    Function name:  H264SwDecFree
+
+    Purpose:
+        Example implementation of H264SwDecFree function. Prototype of this
+        function is given in H264SwDecApi.h. This implementation uses
+        library function free for freeing of memory.
+
+------------------------------------------------------------------------------*/
+void H264SwDecFree(void *ptr)
+{
+    free(ptr);
+}
+
+/*------------------------------------------------------------------------------
+
+    Function name:  H264SwDecMemcpy
+
+    Purpose:
+        Example implementation of H264SwDecMemcpy function. Prototype of this
+        function is given in H264SwDecApi.h. This implementation uses
+        library function memcpy to copy src to dest.
+
+------------------------------------------------------------------------------*/
+void H264SwDecMemcpy(void *dest, void *src, u32 count)
+{
+    memcpy(dest, src, count);
+}
+
+/*------------------------------------------------------------------------------
+
+    Function name:  H264SwDecMemset
+
+    Purpose:
+        Example implementation of H264SwDecMemset function. Prototype of this
+        function is given in H264SwDecApi.h. This implementation uses
+        library function memset to set content of memory area pointed by ptr.
+
+------------------------------------------------------------------------------*/
+void H264SwDecMemset(void *ptr, i32 value, u32 count)
+{
+    memset(ptr, value, count);
+}
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/H264SwDecApi.c b/media/libstagefright/codecs/on2/h264dec/source/H264SwDecApi.c
new file mode 100644
index 0000000..2bb4c4d
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/H264SwDecApi.c
@@ -0,0 +1,567 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+     1. Include headers
+     2. External compiler flags
+     3. Module defines
+     4. Local function prototypes
+     5. Functions
+          H264SwDecInit
+          H264SwDecGetInfo
+          H264SwDecRelease
+          H264SwDecDecode
+          H264SwDecGetAPIVersion
+          H264SwDecNextPicture
+
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+#include <stdlib.h>
+#include "basetype.h"
+#include "h264bsd_container.h"
+#include "H264SwDecApi.h"
+#include "h264bsd_decoder.h"
+#include "h264bsd_util.h"
+
+/*------------------------------------------------------------------------------
+       Version Information
+------------------------------------------------------------------------------*/
+
+#define H264SWDEC_MAJOR_VERSION 2
+#define H264SWDEC_MINOR_VERSION 3
+
+/*------------------------------------------------------------------------------
+    2. External compiler flags
+--------------------------------------------------------------------------------
+
+H264DEC_TRACE           Trace H264 Decoder API function calls.
+H264DEC_EVALUATION      Compile evaluation version, restricts number of frames
+                        that can be decoded
+
+--------------------------------------------------------------------------------
+    3. Module defines
+------------------------------------------------------------------------------*/
+
+#ifdef H264DEC_TRACE
+#include <stdio.h>
+#define DEC_API_TRC(str)    H264SwDecTrace(str)
+#else
+#define DEC_API_TRC(str)
+#endif
+
+#ifdef H264DEC_EVALUATION
+#define H264DEC_EVALUATION_LIMIT   500
+#endif
+
+void H264SwDecTrace(char *string) {
+}
+
+void* H264SwDecMalloc(u32 size) {
+    return malloc(size);
+}
+
+void H264SwDecFree(void *ptr) {
+    free(ptr);
+}
+
+void H264SwDecMemcpy(void *dest, void *src, u32 count) {
+    memcpy(dest, src, count);
+}
+
+void H264SwDecMemset(void *ptr, i32 value, u32 count) {
+    memset(ptr, value, count);
+}
+
+
+/*------------------------------------------------------------------------------
+
+    Function: H264SwDecInit()
+
+        Functional description:
+            Initialize decoder software. Function reserves memory for the
+            decoder instance and calls h264bsdInit to initialize the
+            instance data.
+
+        Inputs:
+            noOutputReordering  flag to indicate decoder that it doesn't have
+                                to try to provide output pictures in display
+                                order, saves memory
+
+        Outputs:
+            decInst             pointer to initialized instance is stored here
+
+        Returns:
+            H264SWDEC_OK        successfully initialized the instance
+            H264SWDEC_INITFAIL  initialization failed
+            H264SWDEC_PARAM_ERR invalid parameters
+            H264SWDEC_MEM_FAIL  memory allocation failed
+
+------------------------------------------------------------------------------*/
+
+H264SwDecRet H264SwDecInit(H264SwDecInst *decInst, u32 noOutputReordering)
+{
+    u32 rv = 0;
+
+    decContainer_t *pDecCont;
+
+    DEC_API_TRC("H264SwDecInit#");
+
+    /* check that right shift on negative numbers is performed signed */
+    /*lint -save -e* following check causes multiple lint messages */
+    if ( ((-1)>>1) != (-1) )
+    {
+        DEC_API_TRC("H264SwDecInit# ERROR: Right shift is not signed");
+        return(H264SWDEC_INITFAIL);
+    }
+    /*lint -restore */
+
+    if (decInst == NULL)
+    {
+        DEC_API_TRC("H264SwDecInit# ERROR: decInst == NULL");
+        return(H264SWDEC_PARAM_ERR);
+    }
+
+    pDecCont = (decContainer_t *)H264SwDecMalloc(sizeof(decContainer_t));
+
+    if (pDecCont == NULL)
+    {
+        DEC_API_TRC("H264SwDecInit# ERROR: Memory allocation failed");
+        return(H264SWDEC_MEMFAIL);
+    }
+
+#ifdef H264DEC_TRACE
+    sprintf(pDecCont->str, "H264SwDecInit# decInst %p noOutputReordering %d",
+            (void*)decInst, noOutputReordering);
+    DEC_API_TRC(pDecCont->str);
+#endif
+
+    rv = h264bsdInit(&pDecCont->storage, noOutputReordering);
+    if (rv != HANTRO_OK)
+    {
+        H264SwDecRelease(pDecCont);
+        return(H264SWDEC_MEMFAIL);
+    }
+
+    pDecCont->decStat  = INITIALIZED;
+    pDecCont->picNumber = 0;
+
+#ifdef H264DEC_TRACE
+    sprintf(pDecCont->str, "H264SwDecInit# OK: return %p", (void*)pDecCont);
+    DEC_API_TRC(pDecCont->str);
+#endif
+
+    *decInst = (decContainer_t *)pDecCont;
+
+    return(H264SWDEC_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: H264SwDecGetInfo()
+
+        Functional description:
+            This function provides read access to decoder information. This
+            function should not be called before H264SwDecDecode function has
+            indicated that headers are ready.
+
+        Inputs:
+            decInst     decoder instance
+
+        Outputs:
+            pDecInfo    pointer to info struct where data is written
+
+        Returns:
+            H264SWDEC_OK            success
+            H264SWDEC_PARAM_ERR     invalid parameters
+            H264SWDEC_HDRS_NOT_RDY  information not available yet
+
+------------------------------------------------------------------------------*/
+
+H264SwDecRet H264SwDecGetInfo(H264SwDecInst decInst, H264SwDecInfo *pDecInfo)
+{
+
+    storage_t *pStorage;
+
+    DEC_API_TRC("H264SwDecGetInfo#");
+
+    if (decInst == NULL || pDecInfo == NULL)
+    {
+        DEC_API_TRC("H264SwDecGetInfo# ERROR: decInst or pDecInfo is NULL");
+        return(H264SWDEC_PARAM_ERR);
+    }
+
+    pStorage = &(((decContainer_t *)decInst)->storage);
+
+    if (pStorage->activeSps == NULL || pStorage->activePps == NULL)
+    {
+        DEC_API_TRC("H264SwDecGetInfo# ERROR: Headers not decoded yet");
+        return(H264SWDEC_HDRS_NOT_RDY);
+    }
+
+#ifdef H264DEC_TRACE
+    sprintf(((decContainer_t*)decInst)->str,
+        "H264SwDecGetInfo# decInst %p  pDecInfo %p", decInst, (void*)pDecInfo);
+    DEC_API_TRC(((decContainer_t*)decInst)->str);
+#endif
+
+    /* h264bsdPicWidth and -Height return dimensions in macroblock units,
+     * picWidth and -Height in pixels */
+    pDecInfo->picWidth        = h264bsdPicWidth(pStorage) << 4;
+    pDecInfo->picHeight       = h264bsdPicHeight(pStorage) << 4;
+    pDecInfo->videoRange      = h264bsdVideoRange(pStorage);
+    pDecInfo->matrixCoefficients = h264bsdMatrixCoefficients(pStorage);
+
+    h264bsdCroppingParams(pStorage,
+        &pDecInfo->croppingFlag,
+        &pDecInfo->cropParams.cropLeftOffset,
+        &pDecInfo->cropParams.cropOutWidth,
+        &pDecInfo->cropParams.cropTopOffset,
+        &pDecInfo->cropParams.cropOutHeight);
+
+    /* sample aspect ratio */
+    h264bsdSampleAspectRatio(pStorage,
+                             &pDecInfo->parWidth,
+                             &pDecInfo->parHeight);
+
+    /* profile */
+    pDecInfo->profile = h264bsdProfile(pStorage);
+
+    DEC_API_TRC("H264SwDecGetInfo# OK");
+
+    return(H264SWDEC_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: H264SwDecRelease()
+
+        Functional description:
+            Release the decoder instance. Function calls h264bsdShutDown to
+            release instance data and frees the memory allocated for the
+            instance.
+
+        Inputs:
+            decInst     Decoder instance
+
+        Outputs:
+            none
+
+        Returns:
+            none
+
+------------------------------------------------------------------------------*/
+
+void H264SwDecRelease(H264SwDecInst decInst)
+{
+
+    decContainer_t *pDecCont;
+
+    DEC_API_TRC("H264SwDecRelease#");
+
+    if (decInst == NULL)
+    {
+        DEC_API_TRC("H264SwDecRelease# ERROR: decInst == NULL");
+        return;
+    }
+
+    pDecCont = (decContainer_t*)decInst;
+
+#ifdef H264DEC_TRACE
+    sprintf(pDecCont->str, "H264SwDecRelease# decInst %p",decInst);
+    DEC_API_TRC(pDecCont->str);
+#endif
+
+    h264bsdShutdown(&pDecCont->storage);
+
+    H264SwDecFree(pDecCont);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: H264SwDecDecode
+
+        Functional description:
+            Decode stream data. Calls h264bsdDecode to do the actual decoding.
+
+        Input:
+            decInst     decoder instance
+            pInput      pointer to input struct
+
+        Outputs:
+            pOutput     pointer to output struct
+
+        Returns:
+            H264SWDEC_NOT_INITIALIZED   decoder instance not initialized yet
+            H264SWDEC_PARAM_ERR         invalid parameters
+
+            H264SWDEC_STRM_PROCESSED    stream buffer decoded
+            H264SWDEC_HDRS_RDY_BUFF_NOT_EMPTY   headers decoded,
+                                                stream buffer not finished
+            H264SWDEC_PIC_RDY                   decoding of a picture finished
+            H264SWDEC_PIC_RDY_BUFF_NOT_EMPTY    decoding of a picture finished,
+                                                stream buffer not finished
+            H264SWDEC_STRM_ERR                  serious error in decoding, no
+                                                valid parameter sets available
+                                                to decode picture data
+            H264SWDEC_EVALUATION_LIMIT_EXCEEDED this can only occur when
+                                                evaluation version is used,
+                                                max number of frames reached
+
+------------------------------------------------------------------------------*/
+
+H264SwDecRet H264SwDecDecode(H264SwDecInst decInst, H264SwDecInput *pInput,
+                  H264SwDecOutput *pOutput)
+{
+
+    decContainer_t *pDecCont;
+    u32 strmLen;
+    u32 numReadBytes;
+    u8 *tmpStream;
+    u32 decResult = 0;
+    H264SwDecRet returnValue = H264SWDEC_STRM_PROCESSED;
+
+    DEC_API_TRC("H264SwDecDecode#");
+
+    /* Check that function input parameters are valid */
+    if (pInput == NULL || pOutput == NULL)
+    {
+        DEC_API_TRC("H264SwDecDecode# ERROR: pInput or pOutput is NULL");
+        return(H264SWDEC_PARAM_ERR);
+    }
+
+    if ((pInput->pStream == NULL) || (pInput->dataLen == 0))
+    {
+        DEC_API_TRC("H264SwDecDecode# ERROR: Invalid input parameters");
+        return(H264SWDEC_PARAM_ERR);
+    }
+
+    pDecCont = (decContainer_t *)decInst;
+
+    /* Check if decoder is in an incorrect mode */
+    if (decInst == NULL || pDecCont->decStat == UNINITIALIZED)
+    {
+        DEC_API_TRC("H264SwDecDecode# ERROR: Decoder not initialized");
+        return(H264SWDEC_NOT_INITIALIZED);
+    }
+
+#ifdef H264DEC_EVALUATION
+    if (pDecCont->picNumber >= H264DEC_EVALUATION_LIMIT)
+        return(H264SWDEC_EVALUATION_LIMIT_EXCEEDED);
+#endif
+
+#ifdef H264DEC_TRACE
+    sprintf(pDecCont->str, "H264SwDecDecode# decInst %p  pInput %p  pOutput %p",
+            decInst, (void*)pInput, (void*)pOutput);
+    DEC_API_TRC(pDecCont->str);
+#endif
+
+    pOutput->pStrmCurrPos   = NULL;
+
+    numReadBytes = 0;
+    strmLen = pInput->dataLen;
+    tmpStream = pInput->pStream;
+    pDecCont->storage.intraConcealmentFlag = pInput->intraConcealmentMethod;
+
+    do
+    {
+        /* Return HDRS_RDY after DPB flush caused by new SPS */
+        if (pDecCont->decStat == NEW_HEADERS)
+        {
+            decResult = H264BSD_HDRS_RDY;
+            pDecCont->decStat = INITIALIZED;
+        }
+        else /* Continue decoding normally */
+        {
+            decResult = h264bsdDecode(&pDecCont->storage, tmpStream, strmLen,
+                pInput->picId, &numReadBytes);
+        }
+        tmpStream += numReadBytes;
+        /* check if too many bytes are read from stream */
+        if ( (i32)(strmLen - numReadBytes) >= 0 )
+            strmLen -= numReadBytes;
+        else
+            strmLen = 0;
+
+        pOutput->pStrmCurrPos = tmpStream;
+
+        switch (decResult)
+        {
+            case H264BSD_HDRS_RDY:
+
+                if(pDecCont->storage.dpb->flushed &&
+                   pDecCont->storage.dpb->numOut !=
+                   pDecCont->storage.dpb->outIndex)
+                {
+                    /* output first all DPB stored pictures
+                     * DPB flush caused by new SPS */
+                    pDecCont->storage.dpb->flushed = 0;
+                    pDecCont->decStat = NEW_HEADERS;
+                    returnValue = H264SWDEC_PIC_RDY_BUFF_NOT_EMPTY;
+                    strmLen = 0;
+                }
+                else
+                {
+                    returnValue = H264SWDEC_HDRS_RDY_BUFF_NOT_EMPTY;
+                    strmLen = 0;
+                }
+                break;
+
+            case H264BSD_PIC_RDY:
+                pDecCont->picNumber++;
+
+                if (strmLen == 0)
+                    returnValue = H264SWDEC_PIC_RDY;
+                else
+                    returnValue = H264SWDEC_PIC_RDY_BUFF_NOT_EMPTY;
+
+                strmLen = 0;
+                break;
+
+            case H264BSD_PARAM_SET_ERROR:
+                if ( !h264bsdCheckValidParamSets(&pDecCont->storage) &&
+                     strmLen == 0 )
+                {
+                    returnValue = H264SWDEC_STRM_ERR;
+                }
+                break;
+            case H264BSD_MEMALLOC_ERROR:
+                {
+                    returnValue = H264SWDEC_MEMFAIL;
+                    strmLen = 0;
+                }
+                break;
+            default:
+                break;
+        }
+
+    } while (strmLen);
+
+#ifdef H264DEC_TRACE
+    sprintf(pDecCont->str, "H264SwDecDecode# OK: DecResult %d",
+            returnValue);
+    DEC_API_TRC(pDecCont->str);
+#endif
+
+    return(returnValue);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: H264SwDecGetAPIVersion
+
+        Functional description:
+            Return version information of the API
+
+        Inputs:
+            none
+
+        Outputs:
+            none
+
+        Returns:
+            API version
+
+------------------------------------------------------------------------------*/
+
+H264SwDecApiVersion H264SwDecGetAPIVersion()
+{
+    H264SwDecApiVersion ver;
+
+    ver.major = H264SWDEC_MAJOR_VERSION;
+    ver.minor = H264SWDEC_MINOR_VERSION;
+
+    return(ver);
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: H264SwDecNextPicture
+
+        Functional description:
+            Get next picture in display order if any available.
+
+        Input:
+            decInst     decoder instance.
+            flushBuffer force output of all buffered pictures
+
+        Output:
+            pOutput     pointer to output structure
+
+        Returns:
+            H264SWDEC_OK            no pictures available for display
+            H264SWDEC_PIC_RDY       picture available for display
+            H264SWDEC_PARAM_ERR     invalid parameters
+
+------------------------------------------------------------------------------*/
+
+H264SwDecRet H264SwDecNextPicture(H264SwDecInst decInst,
+    H264SwDecPicture *pOutput, u32 flushBuffer)
+{
+
+    decContainer_t *pDecCont;
+    u32 numErrMbs, isIdrPic, picId;
+    u32 *pOutPic;
+
+    DEC_API_TRC("H264SwDecNextPicture#");
+
+    if (decInst == NULL || pOutput == NULL)
+    {
+        DEC_API_TRC("H264SwDecNextPicture# ERROR: decInst or pOutput is NULL");
+        return(H264SWDEC_PARAM_ERR);
+    }
+
+    pDecCont = (decContainer_t*)decInst;
+
+#ifdef H264DEC_TRACE
+    sprintf(pDecCont->str, "H264SwDecNextPicture# decInst %p pOutput %p %s %d",
+            decInst, (void*)pOutput, "flushBuffer", flushBuffer);
+    DEC_API_TRC(pDecCont->str);
+#endif
+
+    if (flushBuffer)
+        h264bsdFlushBuffer(&pDecCont->storage);
+
+    pOutPic = (u32*)h264bsdNextOutputPicture(&pDecCont->storage, &picId,
+                                             &isIdrPic, &numErrMbs);
+
+    if (pOutPic == NULL)
+    {
+        DEC_API_TRC("H264SwDecNextPicture# OK: return H264SWDEC_OK");
+        return(H264SWDEC_OK);
+    }
+    else
+    {
+        pOutput->pOutputPicture = pOutPic;
+        pOutput->picId          = picId;
+        pOutput->isIdrPicture   = isIdrPic;
+        pOutput->nbrOfErrMBs    = numErrMbs;
+        DEC_API_TRC("H264SwDecNextPicture# OK: return H264SWDEC_PIC_RDY");
+        return(H264SWDEC_PIC_RDY);
+    }
+
+}
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/TestBenchMultipleInstance.c b/media/libstagefright/codecs/on2/h264dec/source/TestBenchMultipleInstance.c
new file mode 100755
index 0000000..42170d3
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/TestBenchMultipleInstance.c
@@ -0,0 +1,531 @@
+/*
+ * 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.
+ */
+
+/* CVS tag name for identification */
+const char tagName[256] = "$Name: FIRST_ANDROID_COPYRIGHT $";
+
+#include "H264SwDecApi.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define DEBUG(argv) printf argv
+
+/* _NO_OUT disables output file writing */
+#ifdef __arm
+#define _NO_OUT
+#endif
+
+/*------------------------------------------------------------------------------
+
+------------------------------------------------------------------------------*/
+void WriteOutput(FILE *fid, u8 *data, u32 picSize);
+
+u32 CropPicture(u8 *pOutImage, u8 *pInImage,
+    u32 picWidth, u32 picHeight, CropParams *pCropParams);
+
+void CropWriteOutput(FILE *fid, u8 *imageData, u32 cropDisplay,
+        H264SwDecInfo *decInfo);
+
+typedef struct
+{
+    H264SwDecInst decInst;
+    H264SwDecInput decInput;
+    H264SwDecOutput decOutput;
+    H264SwDecPicture decPicture;
+    H264SwDecInfo decInfo;
+    FILE *foutput;
+    char outFileName[256];
+    u8 *byteStrmStart;
+    u32 picNumber;
+} Decoder;
+
+
+/*------------------------------------------------------------------------------
+
+------------------------------------------------------------------------------*/
+int main(int argc, char **argv)
+{
+
+    i32 instCount, instRunning;
+    i32 i;
+    u32 maxNumPics;
+    u32 strmLen;
+    H264SwDecRet ret;
+    u32 numErrors = 0;
+    u32 cropDisplay = 0;
+    u32 disableOutputReordering = 0;
+    FILE *finput;
+    Decoder **decoder;
+    char outFileName[256] = "out.yuv";
+
+
+    if ( argc > 1 && strcmp(argv[1], "-T") == 0 )
+    {
+        fprintf(stderr, "%s\n", tagName);
+        return 0;
+    }
+
+    if (argc < 2)
+    {
+        DEBUG((
+            "Usage: %s [-Nn] [-Ooutfile] [-P] [-U] [-C] [-R] [-T] file1.264 [file2.264] .. [fileN.264]\n",
+            argv[0]));
+        DEBUG(("\t-Nn forces decoding to stop after n pictures\n"));
+#if defined(_NO_OUT)
+        DEBUG(("\t-Ooutfile output writing disabled at compile time\n"));
+#else
+        DEBUG(("\t-Ooutfile write output to \"outfile\" (default out.yuv)\n"));
+        DEBUG(("\t-Onone does not write output\n"));
+#endif
+        DEBUG(("\t-C display cropped image (default decoded image)\n"));
+        DEBUG(("\t-R disable DPB output reordering\n"));
+        DEBUG(("\t-T to print tag name and exit\n"));
+        exit(100);
+    }
+
+    instCount = argc - 1;
+
+    /* read command line arguments */
+    maxNumPics = 0;
+    for (i = 1; i < (argc-1); i++)
+    {
+        if ( strncmp(argv[i], "-N", 2) == 0 )
+        {
+            maxNumPics = (u32)atoi(argv[i]+2);
+            instCount--;
+        }
+        else if ( strncmp(argv[i], "-O", 2) == 0 )
+        {
+            strcpy(outFileName, argv[i]+2);
+            instCount--;
+        }
+        else if ( strcmp(argv[i], "-C") == 0 )
+        {
+            cropDisplay = 1;
+            instCount--;
+        }
+        else if ( strcmp(argv[i], "-R") == 0 )
+        {
+            disableOutputReordering = 1;
+            instCount--;
+        }
+    }
+
+    if (instCount < 1)
+    {
+        DEBUG(("No input files\n"));
+        exit(100);
+    }
+
+    /* allocate memory for multiple decoder instances
+     * one instance for every stream file */
+    decoder = (Decoder **)malloc(sizeof(Decoder*)*(u32)instCount);
+    if (decoder == NULL)
+    {
+        DEBUG(("Unable to allocate memory\n"));
+        exit(100);
+    }
+
+    /* prepare each decoder instance */
+    for (i = 0; i < instCount; i++)
+    {
+        decoder[i] = (Decoder *)calloc(1, sizeof(Decoder));
+
+        /* open input file */
+        finput = fopen(argv[argc-instCount+i],"rb");
+        if (finput == NULL)
+        {
+            DEBUG(("Unable to open input file <%s>\n", argv[argc-instCount+i]));
+            exit(100);
+        }
+
+        DEBUG(("Reading input file[%d] %s\n", i, argv[argc-instCount+i]));
+
+        /* read input stream to buffer */
+        fseek(finput,0L,SEEK_END);
+        strmLen = (u32)ftell(finput);
+        rewind(finput);
+        decoder[i]->byteStrmStart = (u8 *)malloc(sizeof(u8)*strmLen);
+        if (decoder[i]->byteStrmStart == NULL)
+        {
+            DEBUG(("Unable to allocate memory\n"));
+            exit(100);
+        }
+        fread(decoder[i]->byteStrmStart, sizeof(u8), strmLen, finput);
+        fclose(finput);
+
+        /* open output file */
+        if (strcmp(outFileName, "none") != 0)
+        {
+#if defined(_NO_OUT)
+            decoder[i]->foutput = NULL;
+#else
+            sprintf(decoder[i]->outFileName, "%s%i", outFileName, i);
+            decoder[i]->foutput = fopen(decoder[i]->outFileName, "wb");
+            if (decoder[i]->foutput == NULL)
+            {
+                DEBUG(("Unable to open output file\n"));
+                exit(100);
+            }
+#endif
+        }
+
+        ret = H264SwDecInit(&(decoder[i]->decInst), disableOutputReordering);
+
+        if (ret != H264SWDEC_OK)
+        {
+            DEBUG(("Init failed %d\n", ret));
+            exit(100);
+        }
+
+        decoder[i]->decInput.pStream = decoder[i]->byteStrmStart;
+        decoder[i]->decInput.dataLen = strmLen;
+        decoder[i]->decInput.intraConcealmentMethod = 0;
+
+    }
+
+    /* main decoding loop */
+    do
+    {
+        /* decode once using each instance */
+        for (i = 0; i < instCount; i++)
+        {
+            ret = H264SwDecDecode(decoder[i]->decInst,
+                                &(decoder[i]->decInput),
+                                &(decoder[i]->decOutput));
+
+            switch(ret)
+            {
+
+                case H264SWDEC_HDRS_RDY_BUFF_NOT_EMPTY:
+
+                    ret = H264SwDecGetInfo(decoder[i]->decInst,
+                            &(decoder[i]->decInfo));
+                    if (ret != H264SWDEC_OK)
+                        exit(1);
+
+                    if (cropDisplay && decoder[i]->decInfo.croppingFlag)
+                    {
+                        DEBUG(("Decoder[%d] Cropping params: (%d, %d) %dx%d\n",
+                            i,
+                            decoder[i]->decInfo.cropParams.cropLeftOffset,
+                            decoder[i]->decInfo.cropParams.cropTopOffset,
+                            decoder[i]->decInfo.cropParams.cropOutWidth,
+                            decoder[i]->decInfo.cropParams.cropOutHeight));
+                    }
+
+                    DEBUG(("Decoder[%d] Width %d Height %d\n", i,
+                        decoder[i]->decInfo.picWidth,
+                        decoder[i]->decInfo.picHeight));
+
+                    DEBUG(("Decoder[%d] videoRange %d, matricCoefficients %d\n",
+                        i, decoder[i]->decInfo.videoRange,
+                        decoder[i]->decInfo.matrixCoefficients));
+                    decoder[i]->decInput.dataLen -=
+                        (u32)(decoder[i]->decOutput.pStrmCurrPos -
+                              decoder[i]->decInput.pStream);
+                    decoder[i]->decInput.pStream =
+                        decoder[i]->decOutput.pStrmCurrPos;
+                    break;
+
+                case H264SWDEC_PIC_RDY_BUFF_NOT_EMPTY:
+                    decoder[i]->decInput.dataLen -=
+                        (u32)(decoder[i]->decOutput.pStrmCurrPos -
+                              decoder[i]->decInput.pStream);
+                    decoder[i]->decInput.pStream =
+                        decoder[i]->decOutput.pStrmCurrPos;
+                    /* fall through */
+                case H264SWDEC_PIC_RDY:
+                    if (ret == H264SWDEC_PIC_RDY)
+                        decoder[i]->decInput.dataLen = 0;
+
+                    ret = H264SwDecGetInfo(decoder[i]->decInst,
+                            &(decoder[i]->decInfo));
+                    if (ret != H264SWDEC_OK)
+                        exit(1);
+
+                    while (H264SwDecNextPicture(decoder[i]->decInst,
+                            &(decoder[i]->decPicture), 0) == H264SWDEC_PIC_RDY)
+                    {
+                        decoder[i]->picNumber++;
+
+                        numErrors += decoder[i]->decPicture.nbrOfErrMBs;
+
+                        DEBUG(("Decoder[%d] PIC %d, type %s, concealed %d\n",
+                            i, decoder[i]->picNumber,
+                            decoder[i]->decPicture.isIdrPicture
+                                ? "IDR" : "NON-IDR",
+                            decoder[i]->decPicture.nbrOfErrMBs));
+                        fflush(stdout);
+
+                        CropWriteOutput(decoder[i]->foutput,
+                                (u8*)decoder[i]->decPicture.pOutputPicture,
+                                cropDisplay, &(decoder[i]->decInfo));
+                    }
+
+                    if (maxNumPics && decoder[i]->picNumber == maxNumPics)
+                        decoder[i]->decInput.dataLen = 0;
+                    break;
+
+                case H264SWDEC_STRM_PROCESSED:
+                case H264SWDEC_STRM_ERR:
+                case H264SWDEC_PARAM_ERR:
+                    decoder[i]->decInput.dataLen = 0;
+                    break;
+
+                default:
+                    DEBUG(("Decoder[%d] FATAL ERROR\n", i));
+                    exit(10);
+                    break;
+
+            }
+        }
+
+        /* check if any of the instances is still running (=has more data) */
+        instRunning = instCount;
+        for (i = 0; i < instCount; i++)
+        {
+            if (decoder[i]->decInput.dataLen == 0)
+                instRunning--;
+        }
+
+    } while (instRunning);
+
+
+    /* get last frames and close each instance */
+    for (i = 0; i < instCount; i++)
+    {
+        while (H264SwDecNextPicture(decoder[i]->decInst,
+                &(decoder[i]->decPicture), 1) == H264SWDEC_PIC_RDY)
+        {
+            decoder[i]->picNumber++;
+
+            DEBUG(("Decoder[%d] PIC %d, type %s, concealed %d\n",
+                i, decoder[i]->picNumber,
+                decoder[i]->decPicture.isIdrPicture
+                    ? "IDR" : "NON-IDR",
+                decoder[i]->decPicture.nbrOfErrMBs));
+            fflush(stdout);
+
+            CropWriteOutput(decoder[i]->foutput,
+                    (u8*)decoder[i]->decPicture.pOutputPicture,
+                    cropDisplay, &(decoder[i]->decInfo));
+        }
+
+        H264SwDecRelease(decoder[i]->decInst);
+
+        if (decoder[i]->foutput)
+            fclose(decoder[i]->foutput);
+
+        free(decoder[i]->byteStrmStart);
+
+        free(decoder[i]);
+    }
+
+    free(decoder);
+
+    if (numErrors)
+        return 1;
+    else
+        return 0;
+
+}
+
+/*------------------------------------------------------------------------------
+
+------------------------------------------------------------------------------*/
+void CropWriteOutput(FILE *foutput, u8 *imageData, u32 cropDisplay,
+        H264SwDecInfo *decInfo)
+{
+    u8 *tmpImage = NULL;
+    u32 tmp, picSize;
+
+    if (cropDisplay && decInfo->croppingFlag)
+    {
+        picSize = decInfo->cropParams.cropOutWidth *
+                  decInfo->cropParams.cropOutHeight;
+        picSize = (3 * picSize)/2;
+        tmpImage = malloc(picSize);
+        if (tmpImage == NULL)
+            exit(1);
+        tmp = CropPicture(tmpImage, imageData,
+            decInfo->picWidth, decInfo->picHeight,
+            &(decInfo->cropParams));
+        if (tmp)
+            exit(1);
+        WriteOutput(foutput, tmpImage, picSize);
+        free(tmpImage);
+    }
+    else
+    {
+        picSize = decInfo->picWidth * decInfo->picHeight;
+        picSize = (3 * picSize)/2;
+        WriteOutput(foutput, imageData, picSize);
+    }
+
+}
+
+/*------------------------------------------------------------------------------
+
+------------------------------------------------------------------------------*/
+void WriteOutput(FILE *fid, u8 *data, u32 picSize)
+{
+    if (fid)
+        fwrite(data, 1, picSize, fid);
+}
+
+/*------------------------------------------------------------------------------
+
+    Function name:  H264SwDecTrace
+
+------------------------------------------------------------------------------*/
+void H264SwDecTrace(char *string)
+{
+    FILE *fp;
+
+    fp = fopen("dec_api.trc", "at");
+
+    if (!fp)
+        return;
+
+    fwrite(string, 1, strlen(string), fp);
+    fwrite("\n", 1,1, fp);
+
+    fclose(fp);
+}
+
+/*------------------------------------------------------------------------------
+
+    Function name:  H264SwDecmalloc
+
+------------------------------------------------------------------------------*/
+void* H264SwDecMalloc(u32 size)
+{
+    return malloc(size);
+}
+
+/*------------------------------------------------------------------------------
+
+    Function name:  H264SwDecFree
+
+------------------------------------------------------------------------------*/
+void H264SwDecFree(void *ptr)
+{
+    free(ptr);
+}
+
+/*------------------------------------------------------------------------------
+
+    Function name:  H264SwDecMemcpy
+
+------------------------------------------------------------------------------*/
+void H264SwDecMemcpy(void *dest, void *src, u32 count)
+{
+    memcpy(dest, src, count);
+}
+
+/*------------------------------------------------------------------------------
+
+    Function name:  H264SwDecMemset
+
+------------------------------------------------------------------------------*/
+void H264SwDecMemset(void *ptr, i32 value, u32 count)
+{
+    memset(ptr, value, count);
+}
+
+/*------------------------------------------------------------------------------
+
+    Function name: CropPicture
+
+------------------------------------------------------------------------------*/
+u32 CropPicture(u8 *pOutImage, u8 *pInImage,
+    u32 picWidth, u32 picHeight, CropParams *pCropParams)
+{
+
+    u32 i, j;
+    u32 outWidth, outHeight;
+    u8 *pOut, *pIn;
+
+    if (pOutImage == NULL || pInImage == NULL || pCropParams == NULL ||
+        !picWidth || !picHeight)
+    {
+        /* due to lint warning */
+        free(pOutImage);
+        return(1);
+    }
+
+    if ( ((pCropParams->cropLeftOffset + pCropParams->cropOutWidth) >
+           picWidth ) ||
+         ((pCropParams->cropTopOffset + pCropParams->cropOutHeight) >
+           picHeight ) )
+    {
+        /* due to lint warning */
+        free(pOutImage);
+        return(1);
+    }
+
+    outWidth = pCropParams->cropOutWidth;
+    outHeight = pCropParams->cropOutHeight;
+
+    pIn = pInImage + pCropParams->cropTopOffset*picWidth +
+        pCropParams->cropLeftOffset;
+    pOut = pOutImage;
+
+    /* luma */
+    for (i = outHeight; i; i--)
+    {
+        for (j = outWidth; j; j--)
+        {
+            *pOut++ = *pIn++;
+        }
+        pIn += picWidth - outWidth;
+    }
+
+    outWidth >>= 1;
+    outHeight >>= 1;
+
+    pIn = pInImage + picWidth*picHeight +
+        pCropParams->cropTopOffset*picWidth/4 + pCropParams->cropLeftOffset/2;
+
+    /* cb */
+    for (i = outHeight; i; i--)
+    {
+        for (j = outWidth; j; j--)
+        {
+            *pOut++ = *pIn++;
+        }
+        pIn += picWidth/2 - outWidth;
+    }
+
+    pIn = pInImage + 5*picWidth*picHeight/4 +
+        pCropParams->cropTopOffset*picWidth/4 + pCropParams->cropLeftOffset/2;
+
+    /* cr */
+    for (i = outHeight; i; i--)
+    {
+        for (j = outWidth; j; j--)
+        {
+            *pOut++ = *pIn++;
+        }
+        pIn += picWidth/2 - outWidth;
+    }
+
+    return (0);
+
+}
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/arm11_asm/h264bsd_interpolate_chroma_hor.s b/media/libstagefright/codecs/on2/h264dec/source/arm11_asm/h264bsd_interpolate_chroma_hor.s
new file mode 100755
index 0000000..634a484
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/arm11_asm/h264bsd_interpolate_chroma_hor.s
@@ -0,0 +1,298 @@
+; 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.
+
+;-------------------------------------------------------------------------------
+;--
+;-- Abstract : ARMv6 optimized version of h264bsdInterpolateChromaHor function
+;--
+;-------------------------------------------------------------------------------
+
+
+    IF  :DEF: H264DEC_WINASM
+        ;// We dont use REQUIRE8 and PRESERVE8 for winasm
+    ELSE
+        REQUIRE8
+        PRESERVE8
+    ENDIF
+
+    AREA    |.text|, CODE
+
+
+;// h264bsdInterpolateChromaHor register allocation
+
+ref     RN 0
+ptrA    RN 0
+
+mb      RN 1
+block   RN 1
+
+x0      RN 2
+count   RN 2
+
+y0      RN 3
+valX    RN 3
+
+width   RN 4
+
+height  RN 5
+tmp7    RN 5
+
+chrPW   RN 6
+tmp8    RN 6
+
+tmp1    RN 7
+chrPH   RN 7
+
+tmp2    RN 8
+
+tmp3    RN 9
+
+tmp4    RN 10
+
+tmp5    RN 11
+
+tmp6    RN 12
+
+c32     RN 14
+xFrac   RN 14
+
+;// Function exports and imports
+
+    IMPORT  h264bsdFillBlock
+
+    EXPORT  h264bsdInterpolateChromaHor
+
+;//  Function arguments
+;//
+;//  u8 *ref,                   : 0xc4
+;//  u8 *predPartChroma,        : 0xc8
+;//  i32 x0,                    : 0xcc
+;//  i32 y0,                    : 0xd0
+;//  u32 width,                 : 0xf8
+;//  u32 height,                : 0xfc
+;//  u32 xFrac,                 : 0x100
+;//  u32 chromaPartWidth,       : 0x104
+;//  u32 chromaPartHeight       : 0x108
+
+h264bsdInterpolateChromaHor
+    STMFD   sp!, {r0-r11,lr}
+    SUB     sp, sp, #0xc4
+
+    LDR     chrPW, [sp, #0x104]     ;// chromaPartWidth
+    LDR     width, [sp, #0xf8]      ;// width
+    CMP     x0, #0
+    BLT     do_fill
+
+    ADD     tmp6, x0, chrPW         ;// tmp6 = x0+ chromaPartWidth
+    ADD     tmp6, tmp6, #1          ;// tmp6 = x0 + chromaPartWidth + 1
+    CMP     tmp6, width             ;// x0+chromaPartWidth+1 > width
+    BHI     do_fill
+
+    CMP     y0, #0
+    BLT     do_fill
+    LDR     chrPH, [sp, #0x108]     ;// chromaPartHeight
+    LDR     height, [sp, #0xfc]     ;// height
+    ADD     tmp6, y0, chrPH         ;// tmp6 = y0 + chromaPartHeight
+    CMP     tmp6, height
+    BLS     skip_fill
+
+do_fill
+    LDR     chrPH, [sp, #0x108]     ;// chromaPartHeight
+    LDR     height, [sp, #0xfc]     ;// height
+    ADD     tmp8, chrPW, #1         ;// tmp8 = chromaPartWidth+1
+    MOV     tmp2, tmp8              ;// tmp2 = chromaPartWidth+1
+    STMIA   sp,{width,height,tmp8,chrPH,tmp2}
+    ADD     block, sp, #0x1c        ;// block
+    BL      h264bsdFillBlock
+
+    LDR     x0, [sp, #0xcc]
+    LDR     y0, [sp, #0xd0]
+    LDR     ref, [sp, #0xc4]        ;// ref
+    STMIA   sp,{width,height,tmp8,chrPH,tmp2}
+    ADD     block, sp, #0x1c        ;// block
+    MLA     ref, height, width, ref ;// ref += width * height; 
+    MLA     block, chrPH, tmp8, block;// block + (chromaPH)*(chromaPW+1)
+    BL      h264bsdFillBlock
+
+    MOV     x0, #0                  ;// x0 = 0
+    MOV     y0, #0                  ;// y0 = 0
+    STR     x0, [sp, #0xcc]
+    STR     y0, [sp, #0xd0]
+    ADD     ref, sp, #0x1c          ;// ref = block
+    STR     ref, [sp, #0xc4]        ;// ref
+
+    STR     chrPH, [sp, #0xfc]      ;// height
+    STR     tmp8, [sp, #0xf8]       ;// width
+    MOV     width, tmp8
+    SUB     chrPW, chrPW, #1
+
+skip_fill
+    MLA     tmp3, y0, width, x0     ;// tmp3 = y0*width+x0
+    LDR     xFrac, [sp, #0x100]     ;// xFrac
+    ADD     ptrA, ref, tmp3         ;// ptrA = ref + y0*width+x0
+    RSB     valX, xFrac, #8         ;// valX = 8-xFrac
+
+    LDR     mb, [sp, #0xc8]         ;// predPartChroma
+
+
+    ;// pack values to count register
+    ;// [31:28] loop_x (chromaPartWidth-1)
+    ;// [27:24] loop_y (chromaPartHeight-1)
+    ;// [23:20] chromaPartWidth-1
+    ;// [19:16] chromaPartHeight-1
+    ;// [15:00] nothing
+
+    SUB     tmp2, chrPH, #1             ;// chromaPartHeight-1
+    SUB     tmp1, chrPW, #1             ;// chromaPartWidth-1
+    ADD     count, count, tmp2, LSL #16 ;// chromaPartHeight-1
+    ADD     count, count, tmp2, LSL #24 ;// loop_y
+    ADD     count, count, tmp1, LSL #20 ;// chromaPartWidth-1
+    AND     tmp2, count, #0x00F00000    ;// loop_x
+    PKHBT   valX, valX, xFrac, LSL #16  ;// |xFrac|valX |
+    MOV     valX, valX, LSL #3          ;// multiply by 8 in advance
+    MOV     c32, #32
+
+
+    ;///////////////////////////////////////////////////////////////////////////
+    ;// Cb
+    ;///////////////////////////////////////////////////////////////////////////
+
+    ;// 2x2 pels per iteration
+    ;// bilinear vertical interpolation
+
+loop1_y
+    ADD     count, count, tmp2, LSL #8
+    LDRB    tmp1, [ptrA, width]
+    LDRB    tmp2, [ptrA], #1
+
+loop1_x
+    LDRB    tmp3, [ptrA, width]
+    LDRB    tmp4, [ptrA], #1
+
+    PKHBT   tmp5, tmp1, tmp3, LSL #16
+    PKHBT   tmp6, tmp2, tmp4, LSL #16
+
+    LDRB    tmp1, [ptrA, width]
+    LDRB    tmp2, [ptrA], #1
+
+    SMLAD   tmp5, tmp5, valX, c32       ;// multiply
+    SMLAD   tmp6, tmp6, valX, c32       ;// multiply
+
+    PKHBT   tmp7, tmp3, tmp1, LSL #16
+    PKHBT   tmp8, tmp4, tmp2, LSL #16
+
+    SMLAD   tmp7, tmp7, valX, c32       ;// multiply
+    SMLAD   tmp8, tmp8, valX, c32       ;// multiply
+
+    MOV     tmp5, tmp5, LSR #6          ;// scale down
+    STRB    tmp5, [mb,#8]               ;// store row 2 col 1
+
+    MOV     tmp6, tmp6, LSR #6          ;// scale down
+    STRB    tmp6, [mb],#1               ;// store row 1 col 1
+
+    MOV     tmp7, tmp7, LSR #6          ;// scale down
+    STRB    tmp7, [mb,#8]               ;// store row 2 col 2
+
+    MOV     tmp8, tmp8, LSR #6          ;// scale down
+    STRB    tmp8, [mb],#1               ;// store row 1 col 2
+
+    SUBS    count, count, #2<<28
+    BCS     loop1_x
+
+    AND     tmp2, count, #0x00F00000
+
+    ADDS    mb, mb, #16
+    SBC     mb, mb, tmp2, LSR #20
+    ADD     ptrA, ptrA, width, LSL #1
+    SBC     ptrA, ptrA, tmp2, LSR #20
+    SUB     ptrA, ptrA, #1
+
+    ADDS    count, count, #0xE << 24
+    BGE     loop1_y
+
+    ;///////////////////////////////////////////////////////////////////////////
+    ;// Cr
+    ;///////////////////////////////////////////////////////////////////////////
+    LDR     height, [sp,#0xfc]          ;// height
+    LDR     ref, [sp, #0xc4]            ;// ref
+    LDR     tmp1, [sp, #0xd0]           ;// y0
+    LDR     tmp2, [sp, #0xcc]           ;// x0
+    LDR     mb, [sp, #0xc8]             ;// predPartChroma
+
+    ADD     tmp1, height, tmp1
+    MLA     tmp3, tmp1, width, tmp2
+    ADD     ptrA, ref, tmp3
+    ADD     mb, mb, #64
+
+    AND     count, count, #0x00FFFFFF
+    AND     tmp1, count, #0x000F0000
+    ADD     count, count, tmp1, LSL #8
+    AND     tmp2, count, #0x00F00000
+
+    ;// 2x2 pels per iteration
+    ;// bilinear vertical interpolation
+loop2_y
+    ADD     count, count, tmp2, LSL #8
+    LDRB    tmp1, [ptrA, width]
+    LDRB    tmp2, [ptrA], #1
+
+loop2_x
+    LDRB    tmp3, [ptrA, width]
+    LDRB    tmp4, [ptrA], #1
+
+    PKHBT   tmp5, tmp1, tmp3, LSL #16
+    PKHBT   tmp6, tmp2, tmp4, LSL #16
+
+    LDRB    tmp1, [ptrA, width]
+    LDRB    tmp2, [ptrA], #1
+
+    SMLAD   tmp5, tmp5, valX, c32       ;// multiply
+    SMLAD   tmp6, tmp6, valX, c32       ;// multiply
+
+    PKHBT   tmp7, tmp3, tmp1, LSL #16
+    PKHBT   tmp8, tmp4, tmp2, LSL #16
+
+    SMLAD   tmp7, tmp7, valX, c32       ;// multiply
+    SMLAD   tmp8, tmp8, valX, c32       ;// multiply
+
+    MOV     tmp5, tmp5, LSR #6          ;// scale down
+    STRB    tmp5, [mb,#8]               ;// store row 2 col 1
+
+    MOV     tmp6, tmp6, LSR #6          ;// scale down
+    STRB    tmp6, [mb],#1               ;// store row 1 col 1
+
+    MOV     tmp7, tmp7, LSR #6          ;// scale down
+    STRB    tmp7, [mb,#8]               ;// store row 2 col 2
+
+    MOV     tmp8, tmp8, LSR #6          ;// scale down
+    STRB    tmp8, [mb],#1               ;// store row 1 col 2
+
+    SUBS    count, count, #2<<28
+    BCS     loop2_x
+
+    AND     tmp2, count, #0x00F00000
+
+    ADDS    mb, mb, #16
+    SBC     mb, mb, tmp2, LSR #20
+    ADD     ptrA, ptrA, width, LSL #1
+    SBC     ptrA, ptrA, tmp2, LSR #20
+    SUB     ptrA, ptrA, #1
+
+    ADDS    count, count, #0xE << 24
+    BGE     loop2_y
+
+    ADD     sp,sp,#0xd4
+    LDMFD   sp!, {r4-r11,pc}
+
+    END
diff --git a/media/libstagefright/codecs/on2/h264dec/source/arm11_asm/h264bsd_interpolate_chroma_hor_ver.s b/media/libstagefright/codecs/on2/h264dec/source/arm11_asm/h264bsd_interpolate_chroma_hor_ver.s
new file mode 100755
index 0000000..7420ad3
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/arm11_asm/h264bsd_interpolate_chroma_hor_ver.s
@@ -0,0 +1,339 @@
+; 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.
+
+;-------------------------------------------------------------------------------
+;--
+;-- Abstract : ARMv6 optimized version of h264bsdInterpolateChromaHorVer 
+;--            function
+;--
+;-------------------------------------------------------------------------------
+
+
+    IF  :DEF: H264DEC_WINASM
+        ;// We dont use REQUIRE8 and PRESERVE8 for winasm
+    ELSE
+        REQUIRE8
+        PRESERVE8
+    ENDIF
+
+    AREA    |.text|, CODE
+
+
+;// h264bsdInterpolateChromaHorVer register allocation
+
+ref     RN 0
+ptrA    RN 0
+
+mb      RN 1
+block   RN 1
+
+x0      RN 2
+count   RN 2
+
+y0      RN 3
+valY    RN 3
+
+width   RN 4
+
+tmp4    RN 5
+height  RN 5
+
+tmp1    RN 6
+
+tmp2    RN 7
+
+tmp3    RN 8
+
+valX    RN 9
+
+tmp5    RN 10
+chrPW   RN 10
+
+tmp6    RN 11
+chrPH   RN 11
+
+xFrac   RN 12
+
+c32     RN 14
+yFrac   RN 14
+
+;// function exports and imports
+
+    IMPORT  h264bsdFillBlock
+
+    EXPORT  h264bsdInterpolateChromaHorVer
+
+;//  Function arguments
+;//
+;//  u8 *ref,                   : 0xc4
+;//  u8 *predPartChroma,        : 0xc8
+;//  i32 x0,                    : 0xcc
+;//  i32 y0,                    : 0xd0
+;//  u32 width,                 : 0xf8
+;//  u32 height,                : 0xfc
+;//  u32 xFrac,                 : 0x100
+;//  u32 yFrac,                 : 0x104
+;//  u32 chromaPartWidth,       : 0x108
+;//  u32 chromaPartHeight       : 0x10c
+
+h264bsdInterpolateChromaHorVer
+    STMFD   sp!, {r0-r11,lr}
+    SUB     sp, sp, #0xc4
+
+    LDR     chrPW, [sp, #0x108]     ;// chromaPartWidth
+    LDR     xFrac, [sp, #0x100]     ;// xFrac
+    LDR     width, [sp, #0xf8]      ;// width
+    CMP     x0, #0
+    BLT     do_fill
+
+    ADD     tmp1, x0, chrPW         ;// tmp1 = x0+ chromaPartWidth
+    ADD     tmp1, tmp1, #1          ;// tmp1 = x0+ chromaPartWidth+1
+    CMP     tmp1, width             ;// x0+chromaPartWidth+1 > width
+    BHI     do_fill
+
+    CMP     y0, #0
+    BLT     do_fill
+    LDR     chrPH, [sp, #0x10c]     ;// chromaPartHeight
+    LDR     height, [sp, #0xfc]     ;// height
+    ADD     tmp1, y0, chrPH         ;// tmp1 = y0 + chromaPartHeight
+    ADD     tmp1, tmp1, #1          ;// tmp1 = y0 + chromaPartHeight + 1
+    CMP     tmp1, height
+    BLS     skip_fill
+
+do_fill
+    LDR     chrPH, [sp, #0x10c]     ;// chromaPartHeight
+    LDR     height, [sp, #0xfc]     ;// height
+    ADD     tmp3, chrPW, #1         ;// tmp3 = chromaPartWidth+1
+    ADD     tmp1, chrPW, #1         ;// tmp1 = chromaPartWidth+1
+    ADD     tmp2, chrPH, #1         ;// tmp2 = chromaPartHeight+1
+    STMIA   sp,{width,height,tmp1,tmp2,tmp3}
+    ADD     block, sp, #0x1c        ;// block
+    BL      h264bsdFillBlock
+
+    LDR     x0, [sp, #0xcc]
+    LDR     y0, [sp, #0xd0]
+    LDR     ref, [sp, #0xc4]        ;// ref
+    STMIA   sp,{width,height,tmp1,tmp2,tmp3}
+    ADD     block, sp, #0x1c        ;// block
+    MLA     ref, height, width, ref ;// ref += width * height; 
+    MLA     block, tmp2, tmp1, block;// block + (chromaPW+1)*(chromaPH+1)
+    BL      h264bsdFillBlock
+
+    MOV     x0, #0                  ;// x0 = 0
+    MOV     y0, #0                  ;// y0 = 0
+    STR     x0, [sp, #0xcc]
+    STR     y0, [sp, #0xd0]
+    ADD     ref, sp, #0x1c          ;// ref = block
+    STR     ref, [sp, #0xc4]        ;// ref
+
+    STR     tmp2, [sp, #0xfc]       ;// height
+    STR     tmp1, [sp, #0xf8]       ;// width
+    MOV     width, tmp1
+
+skip_fill
+    MLA     tmp3, y0, width, x0     ;// tmp3 = y0*width+x0
+    LDR     yFrac, [sp, #0x104]     ;// yFrac
+    LDR     xFrac, [sp, #0x100]
+    ADD     ptrA, ref, tmp3         ;// ptrA = ref + y0*width+x0
+    RSB     valX, xFrac, #8         ;// valX = 8-xFrac
+    RSB     valY, yFrac, #8         ;// valY = 8-yFrac
+
+    LDR     mb, [sp, #0xc8]         ;// predPartChroma
+
+
+    ;// pack values to count register
+    ;// [31:28] loop_x (chromaPartWidth-1)
+    ;// [27:24] loop_y (chromaPartHeight-1)
+    ;// [23:20] chromaPartWidth-1
+    ;// [19:16] chromaPartHeight-1
+    ;// [15:00] nothing
+
+    SUB     tmp2, chrPH, #1             ;// chromaPartHeight-1
+    SUB     tmp1, chrPW, #1             ;// chromaPartWidth-1
+    ADD     count, count, tmp2, LSL #16 ;// chromaPartHeight-1
+    ADD     count, count, tmp2, LSL #24 ;// loop_y
+    ADD     count, count, tmp1, LSL #20 ;// chromaPartWidth-1
+    AND     tmp2, count, #0x00F00000    ;// loop_x
+    PKHBT   valY, valY, yFrac, LSL #16  ;// |yFrac|valY |
+    MOV     c32, #32
+
+
+    ;///////////////////////////////////////////////////////////////////////////
+    ;// Cb
+    ;///////////////////////////////////////////////////////////////////////////
+
+    ;// 2x2 pels per iteration
+    ;// bilinear vertical and horizontal interpolation
+
+loop1_y
+    LDRB    tmp1, [ptrA]
+    LDRB    tmp3, [ptrA, width]
+    LDRB    tmp5, [ptrA, width, LSL #1]
+
+    PKHBT   tmp1, tmp1, tmp3, LSL #16   ;// |t3|t1|
+    PKHBT   tmp3, tmp3, tmp5, LSL #16   ;// |t5|t3|
+
+    SMUAD   tmp1, tmp1, valY            ;// t1=(t1*valY + t3*yFrac)
+    SMUAD   tmp3, tmp3, valY            ;// t3=(t3*valY + t5*yFrac)
+
+    ADD     count, count, tmp2, LSL #8
+loop1_x
+    ;// first
+    LDRB    tmp2, [ptrA, #1]!
+    LDRB    tmp4, [ptrA, width]
+    LDRB    tmp6, [ptrA, width, LSL #1]
+
+    PKHBT   tmp2, tmp2, tmp4, LSL #16   ;// |t4|t2|
+    PKHBT   tmp4, tmp4, tmp6, LSL #16   ;// |t6|t4|
+
+    SMUAD   tmp2, tmp2, valY            ;// t2=(t2*valY + t4*yFrac)
+    MLA     tmp5, tmp1, valX, c32       ;// t5=t1*valX+32
+    MLA     tmp5, tmp2, xFrac, tmp5     ;// t5=t2*xFrac+t5
+
+    SMUAD   tmp4, tmp4, valY            ;// t4=(t4*valY + t6*yFrac)
+    MLA     tmp6, tmp3, valX, c32       ;// t3=t3*valX+32
+    MLA     tmp6, tmp4, xFrac, tmp6     ;// t6=t4*xFrac+t6
+
+    MOV     tmp6, tmp6, LSR #6          ;// scale down
+    STRB    tmp6, [mb, #8]              ;// store pixel
+    MOV     tmp5, tmp5, LSR #6          ;// scale down
+    STRB    tmp5, [mb], #1              ;// store pixel
+
+    ;// second
+    LDRB    tmp1, [ptrA, #1]!
+    LDRB    tmp3, [ptrA, width]
+    LDRB    tmp5, [ptrA, width, LSL #1]
+
+    PKHBT   tmp1, tmp1, tmp3, LSL #16   ;// |t3|t1|
+    PKHBT   tmp3, tmp3, tmp5, LSL #16   ;// |t5|t3|
+
+    SMUAD   tmp1, tmp1, valY            ;// t1=(t1*valY + t3*yFrac)
+    MLA     tmp5, tmp1, xFrac, c32      ;// t1=t1*xFrac+32
+    MLA     tmp5, tmp2, valX, tmp5      ;// t5=t2*valX+t5
+
+    SMUAD   tmp3, tmp3, valY            ;// t3=(t3*valY + t5*yFrac)
+    MLA     tmp6, tmp3, xFrac, c32      ;// t3=t3*xFrac+32
+    MLA     tmp6, tmp4, valX, tmp6      ;// t6=t4*valX+t6
+
+    MOV     tmp6, tmp6, LSR #6          ;// scale down
+    STRB    tmp6, [mb, #8]              ;// store pixel
+    MOV     tmp5, tmp5, LSR #6          ;// scale down
+    STRB    tmp5, [mb], #1              ;// store pixel
+
+    SUBS    count, count, #2<<28
+    BCS     loop1_x
+
+    AND     tmp2, count, #0x00F00000
+
+    ADDS    mb, mb, #16
+    SBC     mb, mb, tmp2, LSR #20
+    ADD     ptrA, ptrA, width, LSL #1
+    SBC     ptrA, ptrA, tmp2, LSR #20
+
+    ADDS    count, count, #0xE << 24
+    BGE     loop1_y
+
+    ;///////////////////////////////////////////////////////////////////////////
+    ;// Cr
+    ;///////////////////////////////////////////////////////////////////////////
+    LDR     height, [sp,#0xfc]          ;// height
+    LDR     ref, [sp, #0xc4]            ;// ref
+    LDR     tmp1, [sp, #0xd0]           ;// y0
+    LDR     tmp2, [sp, #0xcc]           ;// x0
+    LDR     mb, [sp, #0xc8]             ;// predPartChroma
+
+    ADD     tmp1, height, tmp1
+    MLA     tmp3, tmp1, width, tmp2
+    ADD     ptrA, ref, tmp3
+    ADD     mb, mb, #64
+
+    AND     count, count, #0x00FFFFFF
+    AND     tmp1, count, #0x000F0000
+    ADD     count, count, tmp1, LSL #8
+    AND     tmp2, count, #0x00F00000
+
+    ;// 2x2 pels per iteration
+    ;// bilinear vertical and horizontal interpolation
+loop2_y
+    LDRB    tmp1, [ptrA]
+    LDRB    tmp3, [ptrA, width]
+    LDRB    tmp5, [ptrA, width, LSL #1]
+
+    PKHBT   tmp1, tmp1, tmp3, LSL #16   ;// |t3|t1|
+    PKHBT   tmp3, tmp3, tmp5, LSL #16   ;// |t5|t3|
+
+    SMUAD   tmp1, tmp1, valY            ;// t1=(t1*valY + t3*yFrac)
+    SMUAD   tmp3, tmp3, valY            ;// t3=(t3*valY + t5*yFrac)
+
+    ADD     count, count, tmp2, LSL #8
+loop2_x
+    ;// first
+    LDRB    tmp2, [ptrA, #1]!
+    LDRB    tmp4, [ptrA, width]
+    LDRB    tmp6, [ptrA, width, LSL #1]
+
+    PKHBT   tmp2, tmp2, tmp4, LSL #16   ;// |t4|t2|
+    PKHBT   tmp4, tmp4, tmp6, LSL #16   ;// |t6|t4|
+
+    SMUAD   tmp2, tmp2, valY            ;// t2=(t2*valY + t4*yFrac)
+    MLA     tmp5, tmp1, valX, c32       ;// t5=t1*valX+32
+    MLA     tmp5, tmp2, xFrac, tmp5     ;// t5=t2*xFrac+t5
+
+    SMUAD   tmp4, tmp4, valY            ;// t4=(t4*valY + t6*yFrac)
+    MLA     tmp6, tmp3, valX, c32       ;// t3=t3*valX+32
+    MLA     tmp6, tmp4, xFrac, tmp6     ;// t6=t4*xFrac+t6
+
+    MOV     tmp6, tmp6, LSR #6          ;// scale down
+    STRB    tmp6, [mb, #8]              ;// store pixel
+    MOV     tmp5, tmp5, LSR #6          ;// scale down
+    STRB    tmp5, [mb], #1              ;// store pixel
+
+    ;// second 
+    LDRB    tmp1, [ptrA, #1]!
+    LDRB    tmp3, [ptrA, width]
+    LDRB    tmp5, [ptrA, width, LSL #1]
+
+    PKHBT   tmp1, tmp1, tmp3, LSL #16   ;// |t3|t1|
+    PKHBT   tmp3, tmp3, tmp5, LSL #16   ;// |t5|t3|
+
+    SMUAD   tmp1, tmp1, valY            ;// t1=(t1*valY + t3*yFrac)
+    MLA     tmp5, tmp1, xFrac, c32      ;// t1=t1*xFrac+32
+    MLA     tmp5, tmp2, valX, tmp5      ;// t5=t2*valX+t5
+
+    SMUAD   tmp3, tmp3, valY            ;// t3=(t3*valY + t5*yFrac)
+    MLA     tmp6, tmp3, xFrac, c32      ;// t3=t3*xFrac+32
+    MLA     tmp6, tmp4, valX, tmp6      ;// t6=t4*valX+t6
+
+    MOV     tmp6, tmp6, LSR #6          ;// scale down
+    STRB    tmp6, [mb, #8]              ;// store pixel
+    MOV     tmp5, tmp5, LSR #6          ;// scale down
+    STRB    tmp5, [mb], #1              ;// store pixel
+
+    SUBS    count, count, #2<<28
+    BCS     loop2_x
+
+    AND     tmp2, count, #0x00F00000
+
+    ADDS    mb, mb, #16
+    SBC     mb, mb, tmp2, LSR #20
+    ADD     ptrA, ptrA, width, LSL #1
+    SBC     ptrA, ptrA, tmp2, LSR #20
+
+    ADDS    count, count, #0xE << 24
+    BGE     loop2_y
+
+    ADD     sp,sp,#0xd4
+    LDMFD   sp!,{r4-r11,pc}
+
+    END
diff --git a/media/libstagefright/codecs/on2/h264dec/source/arm11_asm/h264bsd_interpolate_chroma_ver.s b/media/libstagefright/codecs/on2/h264dec/source/arm11_asm/h264bsd_interpolate_chroma_ver.s
new file mode 100755
index 0000000..af9df1b
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/arm11_asm/h264bsd_interpolate_chroma_ver.s
@@ -0,0 +1,288 @@
+; 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.
+
+;-------------------------------------------------------------------------------
+;--
+;-- Abstract : ARMv6 optimized version of h264bsdInterpolateChromaVer function
+;--
+;-------------------------------------------------------------------------------
+
+
+    IF :DEF: H264DEC_WINASM
+        ;// We dont use REQUIRE8 and PRESERVE8 for winasm
+    ELSE
+        REQUIRE8
+        PRESERVE8
+    ENDIF
+
+    AREA    |.text|, CODE
+
+;// h264bsdInterpolateChromaVer register allocation
+
+ref     RN 0
+ptrA    RN 0
+
+mb      RN 1
+block   RN 1
+
+x0      RN 2
+count   RN 2
+
+y0      RN 3
+valY    RN 3
+
+width   RN 4
+
+height  RN 5
+tmp7    RN 5
+
+chrPW   RN 6
+tmp8    RN 6
+
+tmp1    RN 7
+
+tmp2    RN 8
+
+tmp3    RN 9
+
+tmp4    RN 10
+
+tmp5    RN 11
+chrPH   RN 11
+
+tmp6    RN 12
+
+c32     RN 14
+yFrac   RN 14
+
+;// Function exports and imports
+
+    IMPORT  h264bsdFillBlock
+
+    EXPORT  h264bsdInterpolateChromaVer
+
+;//  Function arguments
+;//
+;//  u8 *ref,                   : 0xc4
+;//  u8 *predPartChroma,        : 0xc8
+;//  i32 x0,                    : 0xcc
+;//  i32 y0,                    : 0xd0
+;//  u32 width,                 : 0xf8
+;//  u32 height,                : 0xfc
+;//  u32 yFrac,                 : 0x100
+;//  u32 chromaPartWidth,       : 0x104
+;//  u32 chromaPartHeight       : 0x108
+
+h264bsdInterpolateChromaVer
+    STMFD   sp!, {r0-r11,lr}
+    SUB     sp, sp, #0xc4
+
+    LDR     chrPW, [sp, #0x104]     ;// chromaPartWidth
+    LDR     width, [sp, #0xf8]      ;// width
+    CMP     x0, #0
+    BLT     do_fill
+
+    ADD     tmp1, x0, chrPW         ;// tmp1 = x0+ chromaPartWidth
+    CMP     tmp1, width             ;// x0+chromaPartWidth > width
+    BHI     do_fill
+
+    CMP     y0, #0
+    BLT     do_fill
+    LDR     chrPH, [sp, #0x108]     ;// chromaPartHeight
+    LDR     height, [sp, #0xfc]     ;// height
+    ADD     tmp1, y0, chrPH         ;// tmp1 = y0 + chromaPartHeight
+    ADD     tmp1, tmp1, #1          ;// tmp1 = y0 + chromaPartHeight + 1
+    CMP     tmp1, height
+    BLS     skip_fill
+
+do_fill
+    LDR     chrPH, [sp, #0x108]     ;// chromaPartHeight
+    LDR     height, [sp, #0xfc]     ;// height
+    ADD     tmp1, chrPH, #1         ;// tmp1 = chromaPartHeight+1
+    MOV     tmp2, chrPW             ;// tmp2 = chromaPartWidth
+    STMIA   sp,{width,height,chrPW,tmp1,tmp2}
+    ADD     block, sp, #0x1c        ;// block
+    BL      h264bsdFillBlock
+
+    LDR     x0, [sp, #0xcc]
+    LDR     y0, [sp, #0xd0]
+    LDR     ref, [sp, #0xc4]        ;// ref
+    STMIA   sp,{width,height,chrPW,tmp1,tmp2}
+    ADD     block, sp, #0x1c        ;// block
+    MLA     ref, height, width, ref ;// ref += width * height; 
+    MLA     block, chrPW, tmp1, block;// block + (chromaPW)*(chromaPH+1)
+    BL      h264bsdFillBlock
+
+    MOV     x0, #0                  ;// x0 = 0
+    MOV     y0, #0                  ;// y0 = 0
+    STR     x0, [sp, #0xcc]
+    STR     y0, [sp, #0xd0]
+    ADD     ref, sp, #0x1c          ;// ref = block
+    STR     ref, [sp, #0xc4]        ;// ref
+
+    STR     tmp1, [sp, #0xfc]       ;// height
+    STR     chrPW, [sp, #0xf8]      ;// width
+    MOV     width, chrPW
+
+skip_fill
+    MLA     tmp3, y0, width, x0     ;// tmp3 = y0*width+x0
+    LDR     yFrac, [sp, #0x100]     ;// yFrac
+    ADD     ptrA, ref, tmp3         ;// ptrA = ref + y0*width+x0
+    RSB     valY, yFrac, #8         ;// valY = 8-yFrac
+
+    LDR     mb, [sp, #0xc8]         ;// predPartChroma
+
+
+    ;// pack values to count register
+    ;// [31:28] loop_x (chromaPartWidth-1)
+    ;// [27:24] loop_y (chromaPartHeight-1)
+    ;// [23:20] chromaPartWidth-1
+    ;// [19:16] chromaPartHeight-1
+    ;// [15:00] nothing
+
+    SUB     tmp2, chrPH, #1             ;// chromaPartHeight-1
+    SUB     tmp1, chrPW, #1             ;// chromaPartWidth-1
+    ADD     count, count, tmp2, LSL #16 ;// chromaPartHeight-1
+    ADD     count, count, tmp2, LSL #24 ;// loop_y
+    ADD     count, count, tmp1, LSL #20 ;// chromaPartWidth-1
+    AND     tmp2, count, #0x00F00000    ;// loop_x
+    PKHBT   valY, valY, yFrac, LSL #16  ;// |yFrac|valY |
+    MOV     valY, valY, LSL #3          ;// multiply by 8 in advance
+    MOV     c32, #32
+
+
+    ;///////////////////////////////////////////////////////////////////////////
+    ;// Cb
+    ;///////////////////////////////////////////////////////////////////////////
+
+    ;// 2x2 pels per iteration
+    ;// bilinear vertical interpolation
+
+loop1_y
+    ADD     count, count, tmp2, LSL #8
+loop1_x
+    ;// Process 2x2 block
+    LDRB    tmp2, [ptrA,width]          ;// 2 row, 1 col
+    LDRB    tmp3, [ptrA,width, LSL #1]  ;// 3 row, 1 col
+    LDRB    tmp1, [ptrA],#1             ;// 1 row, 1 col
+
+    LDRB    tmp5, [ptrA,width]          ;// 2 row, 2 col
+    LDRB    tmp6, [ptrA,width, LSL #1]  ;// 3 row, 2 col
+    LDRB    tmp4, [ptrA],#1             ;// 1 row, 2 col
+
+    PKHBT   tmp1, tmp1, tmp2, LSL #16   ;// |B|A|
+    PKHBT   tmp2, tmp2, tmp3, LSL #16   ;// |C|B|
+    PKHBT   tmp4, tmp4, tmp5, LSL #16   ;// |B|A|
+
+    SMLAD   tmp7, tmp2, valY, c32       ;// multiply
+    PKHBT   tmp5, tmp5, tmp6, LSL #16   ;// |C|B|
+    SMLAD   tmp2, tmp1, valY, c32       ;// multiply
+    SMLAD   tmp8, tmp5, valY, c32       ;// multiply
+    SMLAD   tmp5, tmp4, valY, c32       ;// multiply
+
+    MOV     tmp7, tmp7, LSR #6          ;// scale down
+    STRB    tmp7, [mb,#8]               ;// store row 2 col 1
+    MOV     tmp2, tmp2, LSR #6          ;// scale down
+    STRB    tmp2, [mb],#1               ;// store row 1 col 1
+
+    MOV     tmp8, tmp8, LSR #6          ;// scale down
+    STRB    tmp8, [mb,#8]               ;// store row 2 col 2
+    MOV     tmp5, tmp5, LSR #6          ;// scale down
+    STRB    tmp5, [mb],#1               ;// store row 1 col 2
+
+
+    SUBS    count, count, #2<<28
+    BCS     loop1_x
+
+    AND     tmp2, count, #0x00F00000
+
+    ADDS    mb, mb, #16
+    SBC     mb, mb, tmp2, LSR #20
+    ADD     ptrA, ptrA, width, LSL #1
+    SBC     ptrA, ptrA, tmp2, LSR #20
+
+    ADDS    count, count, #0xE << 24
+    BGE     loop1_y 
+
+    ;///////////////////////////////////////////////////////////////////////////
+    ;// Cr
+    ;///////////////////////////////////////////////////////////////////////////
+    LDR     height, [sp,#0xfc]          ;// height
+    LDR     ref, [sp, #0xc4]            ;// ref
+    LDR     tmp1, [sp, #0xd0]           ;// y0
+    LDR     tmp2, [sp, #0xcc]           ;// x0
+    LDR     mb, [sp, #0xc8]             ;// predPartChroma
+
+    ADD     tmp1, height, tmp1
+    MLA     tmp3, tmp1, width, tmp2
+    ADD     ptrA, ref, tmp3
+    ADD     mb, mb, #64
+
+    AND     count, count, #0x00FFFFFF
+    AND     tmp1, count, #0x000F0000
+    ADD     count, count, tmp1, LSL #8
+    AND     tmp2, count, #0x00F00000
+
+    ;// 2x2 pels per iteration
+    ;// bilinear vertical interpolation
+loop2_y
+    ADD     count, count, tmp2, LSL #8
+loop2_x
+    ;// Process 2x2 block
+    LDRB    tmp2, [ptrA,width]          ;// 2 row, 1 col
+    LDRB    tmp3, [ptrA,width, LSL #1]  ;// 3 row, 1 col
+    LDRB    tmp1, [ptrA],#1             ;// 1 row, 1 col
+
+    LDRB    tmp5, [ptrA,width]          ;// 2 row, 2 col
+    LDRB    tmp6, [ptrA,width, LSL #1]  ;// 3 row, 2 col
+    LDRB    tmp4, [ptrA],#1             ;// 1 row, 2 col
+
+    PKHBT   tmp1, tmp1, tmp2, LSL #16   ;// |B|A|
+    PKHBT   tmp2, tmp2, tmp3, LSL #16   ;// |C|B|
+    PKHBT   tmp4, tmp4, tmp5, LSL #16   ;// |B|A|
+
+    SMLAD   tmp7, tmp2, valY, c32       ;// multiply
+    PKHBT   tmp5, tmp5, tmp6, LSL #16   ;// |C|B|
+    SMLAD   tmp2, tmp1, valY, c32       ;// multiply
+    SMLAD   tmp8, tmp5, valY, c32       ;// multiply
+    SMLAD   tmp5, tmp4, valY, c32       ;// multiply
+
+    MOV     tmp7, tmp7, LSR #6          ;// scale down
+    STRB    tmp7, [mb,#8]               ;// store row 2 col 1
+    MOV     tmp2, tmp2, LSR #6          ;// scale down
+    STRB    tmp2, [mb],#1               ;// store row 1 col 1
+
+    MOV     tmp8, tmp8, LSR #6          ;// scale down
+    STRB    tmp8, [mb,#8]               ;// store row 2 col 2
+    MOV     tmp5, tmp5, LSR #6          ;// scale down
+    STRB    tmp5, [mb],#1               ;// store row 1 col 2
+
+
+    SUBS    count, count, #2<<28
+    BCS     loop2_x
+
+    AND     tmp2, count, #0x00F00000
+
+    ADDS    mb, mb, #16
+    SBC     mb, mb, tmp2, LSR #20
+    ADD     ptrA, ptrA, width, LSL #1
+    SBC     ptrA, ptrA, tmp2, LSR #20
+
+    ADDS    count, count, #0xE << 24
+    BGE     loop2_y
+
+    ADD     sp,sp,#0xd4
+    LDMFD   sp!, {r4-r11,pc}
+
+    END
diff --git a/media/libstagefright/codecs/on2/h264dec/source/arm11_asm/h264bsd_interpolate_hor_half.s b/media/libstagefright/codecs/on2/h264dec/source/arm11_asm/h264bsd_interpolate_hor_half.s
new file mode 100755
index 0000000..93968b6
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/arm11_asm/h264bsd_interpolate_hor_half.s
@@ -0,0 +1,251 @@
+; 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.
+
+;-------------------------------------------------------------------------------
+;--
+;-- Abstract : ARMv6 optimized version of h264bsdInterpolateHorHalf function
+;--
+;-------------------------------------------------------------------------------
+
+
+    IF :DEF: H264DEC_WINASM
+        ;// We dont use REQUIRE8 and PRESERVE8 for winasm
+    ELSE
+        REQUIRE8
+        PRESERVE8
+    ENDIF
+
+    AREA    |.text|, CODE
+
+;// h264bsdInterpolateHorHalf register allocation
+
+ref     RN 0
+
+mb      RN 1
+buff    RN 1
+
+count   RN 2
+x0      RN 2
+
+y0      RN 3
+x_2_0   RN 3
+
+width   RN 4
+x_3_1   RN 4
+
+height  RN 5
+x_6_4   RN 5
+
+partW   RN 6
+x_7_5   RN 6
+
+partH   RN 7
+tmp1    RN 7
+
+tmp2    RN 8
+
+tmp3    RN 9
+
+tmp4    RN 10
+
+mult_20_01  RN 11
+mult_20_m5  RN 12
+
+plus16  RN 14
+
+
+;// function exports and imports
+
+    IMPORT  h264bsdFillBlock
+
+    EXPORT  h264bsdInterpolateHorHalf
+
+;// Horizontal filter approach
+;//
+;// Basic idea in horizontal filtering is to adjust coefficients
+;// like below. Calculation is done with 16-bit maths.
+;//
+;// Reg     x_2_0     x_3_1     x_6_4     x_7_5     x_2_0
+;//       [  2  0 ] [  3  1 ] [  6  4 ] [  7  5 ] [ 10  8 ] ...
+;// y_0 =   20  1     20 -5        -5         1
+;// y_1 =   -5        20  1      1 20        -5
+;// y_2 =    1        -5        -5 20      1 20
+;// y_3 =              1        20 -5     -5 20         1
+
+
+h264bsdInterpolateHorHalf
+    STMFD   sp!, {r0-r11, lr}
+    SUB     sp, sp, #0x1e4
+
+    CMP     x0, #0
+    BLT     do_fill                 ;// (x0 < 0)
+    LDR     partW, [sp,#0x220]      ;// partWidth
+    ADD     tmp4, x0, partW         ;// (x0+partWidth)
+    ADD     tmp4, tmp4, #5          ;// (y0+partW+5)
+    LDR     width, [sp,#0x218]      ;// width
+    CMP     tmp4, width
+    BHI     do_fill                 ;// (x0+partW)>width
+
+    CMP     y0, #0
+    BLT     do_fill                 ;// (y0 < 0)
+    LDR     partH, [sp,#0x224]      ;// partHeight
+    ADD     tmp2, y0, partH         ;// (y0+partHeight)
+    LDR     height, [sp,#0x21c]     ;// height
+    CMP     tmp2, height
+    BLS     skip_fill               ;// no overfill needed
+
+
+do_fill
+    LDR     partH, [sp,#0x224]      ;// partHeight
+    LDR     height, [sp,#0x21c]     ;// height
+    LDR     partW, [sp,#0x220]      ;// partWidth
+    ADD     tmp4, partW, #5         ;// tmp4 = partW + 5;
+    STMIB   sp, {height, tmp4}      ;// sp+4 = height, sp+8 = partWidth+5
+    STR     partH, [sp,#0xc]        ;// sp+c = partHeight
+    STR     tmp4, [sp,#0x10]        ;// sp+10 = partWidth+5
+    LDR     width, [sp,#0x218]      ;// width
+    STR     width, [sp,#0]          ;// sp+0 = width
+    ADD     buff, sp, #0x28         ;// buff = p1[21*21/4+1]
+    BL      h264bsdFillBlock
+
+    MOV     x0, #0
+    STR     x0,[sp,#0x1ec]          ;// x0 = 0
+    STR     x0,[sp,#0x1f0]          ;// y0 = 0
+    ADD     ref,sp,#0x28            ;// ref = p1
+    STR     tmp4, [sp,#0x218]       ;// width = partWidth+5
+
+
+skip_fill
+    LDR     x0 ,[sp,#0x1ec]         ;// x0
+    LDR     y0 ,[sp,#0x1f0]         ;// y0
+    LDR     width, [sp,#0x218]      ;// width
+    MLA     tmp2, width, y0, x0     ;// y0*width+x0
+    ADD     ref, ref, tmp2          ;// ref += y0*width+x0
+    ADD     ref, ref, #8            ;// ref = ref+8
+    LDR     mb, [sp, #0x1e8]        ;// mb
+
+    ;// pack values to count register
+    ;// [31:28] loop_x (partWidth-1)
+    ;// [27:24] loop_y (partHeight-1)
+    ;// [23:20] partWidth-1
+    ;// [19:16] partHeight-1
+    ;// [15:00] width
+    MOV     count, width
+    SUB     partW, partW, #1;
+    SUB     partH, partH, #1;
+    ADD     tmp2, partH, partW, LSL #4
+    ADD     count, count, tmp2, LSL #16
+
+
+    LDR     mult_20_01, = 0x00140001
+    LDR     mult_20_m5, = 0x0014FFFB
+    MOV     plus16, #16
+    AND     tmp1, count, #0x000F0000    ;// partHeight-1
+    AND     tmp3, count, #0x00F00000    ;// partWidth-1
+    ADD     count, count, tmp1, LSL #8
+loop_y
+    LDR     x_3_1, [ref, #-8]
+    ADD     count, count, tmp3, LSL #8
+    LDR     x_7_5, [ref, #-4]
+    UXTB16  x_2_0, x_3_1
+    UXTB16  x_3_1, x_3_1, ROR #8
+    UXTB16  x_6_4, x_7_5
+
+loop_x
+    UXTB16  x_7_5, x_7_5, ROR #8
+
+    SMLAD   tmp1, x_2_0, mult_20_01, plus16
+    SMLATB  tmp3, x_2_0, mult_20_01, plus16
+    SMLATB  tmp2, x_2_0, mult_20_m5, plus16
+    SMLATB  tmp4, x_3_1, mult_20_01, plus16
+
+    SMLAD   tmp1, x_3_1, mult_20_m5, tmp1
+    SMLATB  tmp3, x_3_1, mult_20_m5, tmp3
+    SMLAD   tmp2, x_3_1, mult_20_01, tmp2
+    LDR     x_3_1, [ref], #4
+    SMLAD   tmp4, x_6_4, mult_20_m5, tmp4
+
+    SMLABB  tmp1, x_6_4, mult_20_m5, tmp1
+    SMLADX  tmp3, x_6_4, mult_20_m5, tmp3
+    SMLADX  tmp2, x_6_4, mult_20_01, tmp2
+    SMLADX  tmp4, x_7_5, mult_20_m5, tmp4
+
+    SMLABB  tmp1, x_7_5, mult_20_01, tmp1
+    UXTB16  x_2_0, x_3_1
+    SMLABB  tmp2, x_7_5, mult_20_m5, tmp2
+    SMLADX  tmp3, x_7_5, mult_20_01, tmp3
+    SMLABB  tmp4, x_2_0, mult_20_01, tmp4
+
+    MOV     tmp2, tmp2, ASR #5
+    MOV     tmp1, tmp1, ASR #5
+    PKHBT   tmp2, tmp2, tmp4, LSL #(16-5)
+    PKHBT   tmp1, tmp1, tmp3, LSL #(16-5)
+    USAT16  tmp2, #8, tmp2
+    USAT16  tmp1, #8, tmp1
+
+    SUBS    count, count, #4<<28
+    ORR     tmp1, tmp1, tmp2, LSL #8
+    STR     tmp1, [mb], #4
+    BCC     next_y
+
+    UXTB16  x_3_1, x_3_1, ROR #8
+
+    SMLAD   tmp1, x_6_4, mult_20_01, plus16
+    SMLATB  tmp3, x_6_4, mult_20_01, plus16
+    SMLATB  tmp2, x_6_4, mult_20_m5, plus16
+    SMLATB  tmp4, x_7_5, mult_20_01, plus16
+
+    SMLAD   tmp1, x_7_5, mult_20_m5, tmp1
+    SMLATB  tmp3, x_7_5, mult_20_m5, tmp3
+    SMLAD   tmp2, x_7_5, mult_20_01, tmp2
+    LDR     x_7_5, [ref], #4
+    SMLAD   tmp4, x_2_0, mult_20_m5, tmp4
+
+    SMLABB  tmp1, x_2_0, mult_20_m5, tmp1
+    SMLADX  tmp3, x_2_0, mult_20_m5, tmp3
+    SMLADX  tmp2, x_2_0, mult_20_01, tmp2
+    SMLADX  tmp4, x_3_1, mult_20_m5, tmp4
+
+    SMLABB  tmp1, x_3_1, mult_20_01, tmp1
+    UXTB16  x_6_4, x_7_5
+    SMLABB  tmp2, x_3_1, mult_20_m5, tmp2
+    SMLADX  tmp3, x_3_1, mult_20_01, tmp3
+    SMLABB  tmp4, x_6_4, mult_20_01, tmp4
+
+    MOV     tmp2, tmp2, ASR #5
+    MOV     tmp1, tmp1, ASR #5
+    PKHBT   tmp2, tmp2, tmp4, LSL #(16-5)
+    PKHBT   tmp1, tmp1, tmp3, LSL #(16-5)
+    USAT16  tmp2, #8, tmp2
+    USAT16  tmp1, #8, tmp1
+
+    SUBS    count, count, #4<<28
+    ORR     tmp1, tmp1, tmp2, LSL #8
+    STR     tmp1, [mb], #4
+    BCS     loop_x
+
+next_y
+    AND     tmp3, count, #0x00F00000    ;// partWidth-1
+    SMLABB  ref, count, mult_20_01, ref ;// +width
+    ADDS    mb, mb, #16                 ;// +16, Carry=0
+    SBC     mb, mb, tmp3, LSR #20       ;// -(partWidth-1)-1
+    SBC     ref, ref, tmp3, LSR #20     ;// -(partWidth-1)-1
+    ADDS    count, count, #(1<<28)-(1<<24)
+    BGE     loop_y
+
+    ADD     sp,sp,#0x1f4
+    LDMFD   sp!, {r4-r11, pc}
+
+    END
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/arm11_asm/h264bsd_interpolate_hor_quarter.s b/media/libstagefright/codecs/on2/h264dec/source/arm11_asm/h264bsd_interpolate_hor_quarter.s
new file mode 100755
index 0000000..de243d4
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/arm11_asm/h264bsd_interpolate_hor_quarter.s
@@ -0,0 +1,273 @@
+; 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.
+
+;-------------------------------------------------------------------------------
+;--
+;-- Abstract : ARMv6 optimized version of h264bsdInterpolateHorQuarter function
+;--
+;-------------------------------------------------------------------------------
+
+
+    IF :DEF: H264DEC_WINASM
+        ;// We dont use REQUIRE8 and PRESERVE8 for winasm
+    ELSE
+        REQUIRE8
+        PRESERVE8
+    ENDIF
+
+    AREA    |.text|, CODE
+
+;// h264bsdInterpolateHorQuarter register allocation
+
+ref     RN 0
+
+mb      RN 1
+buff    RN 1
+
+count   RN 2
+x0      RN 2
+
+y0      RN 3
+x_2_0   RN 3
+
+width   RN 4
+x_3_1   RN 4
+
+height  RN 5
+x_6_4   RN 5
+
+partW   RN 6
+x_7_5   RN 6
+
+partH   RN 7
+tmp1    RN 7
+
+tmp2    RN 8
+
+tmp3    RN 9
+
+tmp4    RN 10
+
+mult_20_01  RN 11
+
+mult_20_m5  RN 12
+
+plus16  RN 14
+
+
+;// function exports and imports
+
+    IMPORT  h264bsdFillBlock
+
+    EXPORT  h264bsdInterpolateHorQuarter
+
+
+;// Horizontal filter approach
+;//
+;// Basic idea in horizontal filtering is to adjust coefficients
+;// like below. Calculation is done with 16-bit maths.
+;//
+;// Reg     x_2_0     x_3_1     x_6_4     x_7_5     x_2_0
+;//       [  2  0 ] [  3  1 ] [  6  4 ] [  7  5 ] [ 10  8 ] ...
+;// y_0 =   20  1     20 -5        -5         1
+;// y_1 =   -5        20  1      1 20        -5
+;// y_2 =    1        -5        -5 20      1 20
+;// y_3 =              1        20 -5     -5 20         1
+
+
+h264bsdInterpolateHorQuarter
+    STMFD   sp!, {r0-r11, lr}
+    SUB     sp, sp, #0x1e4
+
+    CMP     x0, #0
+    BLT     do_fill                 ;// (x0 < 0)
+    LDR     partW, [sp,#0x220]      ;// partWidth
+    ADD     tmp4, x0, partW         ;// (x0+partWidth)
+    ADD     tmp4, tmp4, #5          ;// (y0+partW+5)
+    LDR     width, [sp,#0x218]      ;// width
+    CMP     tmp4, width
+    BHI     do_fill                 ;// (x0+partW)>width
+
+    CMP     y0, #0
+    BLT     do_fill                 ;// (y0 < 0)
+    LDR     partH, [sp,#0x224]      ;// partHeight
+    ADD     tmp2, y0, partH         ;// (y0+partHeight)
+    LDR     height, [sp,#0x21c]     ;// height
+    CMP     tmp2, height
+    BLS     skip_fill               ;// no overfill needed
+
+
+do_fill
+    LDR     partH, [sp,#0x224]      ;// partHeight
+    LDR     height, [sp,#0x21c]     ;// height
+    LDR     partW, [sp,#0x220]      ;// partWidth
+    ADD     tmp4, partW, #5         ;// tmp4 = partW + 5;
+    STMIB   sp, {height, tmp4}      ;// sp+4 = height, sp+8 = partWidth+5
+    STR     partH, [sp,#0xc]        ;// sp+c = partHeight
+    STR     tmp4, [sp,#0x10]        ;// sp+10 = partWidth+5
+    LDR     width, [sp,#0x218]      ;// width
+    STR     width, [sp,#0]          ;// sp+0 = width
+    ADD     buff, sp, #0x28         ;// buff = p1[21*21/4+1]
+    BL      h264bsdFillBlock
+
+    MOV     x0, #0
+    STR     x0,[sp,#0x1ec]          ;// x0 = 0
+    STR     x0,[sp,#0x1f0]          ;// y0 = 0
+    ADD     ref,sp,#0x28            ;// ref = p1
+    STR     tmp4, [sp,#0x218]       ;// width = partWidth+5
+
+
+skip_fill
+    LDR     x0 ,[sp,#0x1ec]         ;// x0
+    LDR     y0 ,[sp,#0x1f0]         ;// y0
+    LDR     width, [sp,#0x218]      ;// width
+    MLA     tmp2, width, y0, x0     ;// y0*width+x0
+    ADD     ref, ref, tmp2          ;// ref += y0*width+x0
+    ADD     ref, ref, #8            ;// ref = ref+8
+    LDR     mb, [sp, #0x1e8]        ;// mb
+
+    ;// pack values to count register
+    ;// [31:28] loop_x (partWidth-1)
+    ;// [27:24] loop_y (partHeight-1)
+    ;// [23:20] partWidth-1
+    ;// [19:16] partHeight-1
+    ;// [15:00] width
+    MOV     count, width
+    SUB     partW, partW, #1;
+    SUB     partH, partH, #1;
+    ADD     tmp2, partH, partW, LSL #4
+    ADD     count, count, tmp2, LSL #16
+
+
+    LDR     mult_20_01, = 0x00140001
+    LDR     mult_20_m5, = 0x0014FFFB
+    MOV     plus16, #16
+    AND     tmp1, count, #0x000F0000    ;// partHeight-1
+    AND     tmp3, count, #0x00F00000    ;// partWidth-1
+    ADD     count, count, tmp1, LSL #8
+loop_y
+    LDR     x_3_1, [ref, #-8]
+    ADD     count, count, tmp3, LSL #8
+    LDR     x_7_5, [ref, #-4]
+    UXTB16  x_2_0, x_3_1
+    UXTB16  x_3_1, x_3_1, ROR #8
+    UXTB16  x_6_4, x_7_5
+
+loop_x
+    UXTB16  x_7_5, x_7_5, ROR #8
+
+    SMLAD   tmp1, x_2_0, mult_20_01, plus16
+    SMLATB  tmp3, x_2_0, mult_20_01, plus16
+    SMLATB  tmp2, x_2_0, mult_20_m5, plus16
+    SMLATB  tmp4, x_3_1, mult_20_01, plus16
+
+    SMLAD   tmp1, x_3_1, mult_20_m5, tmp1
+    SMLATB  tmp3, x_3_1, mult_20_m5, tmp3
+    SMLAD   tmp2, x_3_1, mult_20_01, tmp2
+    LDR     x_3_1, [ref], #4
+    SMLAD   tmp4, x_6_4, mult_20_m5, tmp4
+
+    SMLABB  tmp1, x_6_4, mult_20_m5, tmp1
+    SMLADX  tmp3, x_6_4, mult_20_m5, tmp3
+    SMLADX  tmp2, x_6_4, mult_20_01, tmp2
+    SMLADX  tmp4, x_7_5, mult_20_m5, tmp4
+
+    SMLABB  tmp1, x_7_5, mult_20_01, tmp1
+    UXTB16  x_2_0, x_3_1
+    SMLABB  tmp2, x_7_5, mult_20_m5, tmp2
+    SMLADX  tmp3, x_7_5, mult_20_01, tmp3
+    SMLABB  tmp4, x_2_0, mult_20_01, tmp4
+
+    MOV     tmp2, tmp2, ASR #5
+    MOV     tmp1, tmp1, ASR #5
+    PKHBT   tmp2, tmp2, tmp4, LSL #(16-5)
+    PKHBT   tmp1, tmp1, tmp3, LSL #(16-5)
+    LDR     tmp4, [sp, #0x228]
+    USAT16  tmp2, #8, tmp2
+    USAT16  tmp1, #8, tmp1
+    SUB     tmp4, tmp4, #10
+
+    SUBS    count, count, #4<<28
+    LDR     tmp3, [ref, tmp4]
+    ORR     tmp1, tmp1, tmp2, LSL #8
+
+;// quarter pel position
+    LDR     tmp2, = 0x80808080
+    MVN     tmp3, tmp3
+    UHSUB8  tmp1, tmp1, tmp3
+    EOR     tmp1, tmp1, tmp2
+    STR     tmp1, [mb], #4
+
+    BCC     next_y
+
+    UXTB16  x_3_1, x_3_1, ROR #8
+
+    SMLAD   tmp1, x_6_4, mult_20_01, plus16
+    SMLATB  tmp3, x_6_4, mult_20_01, plus16
+    SMLATB  tmp2, x_6_4, mult_20_m5, plus16
+    SMLATB  tmp4, x_7_5, mult_20_01, plus16
+
+    SMLAD   tmp1, x_7_5, mult_20_m5, tmp1
+    SMLATB  tmp3, x_7_5, mult_20_m5, tmp3
+    SMLAD   tmp2, x_7_5, mult_20_01, tmp2
+    LDR     x_7_5, [ref], #4
+    SMLAD   tmp4, x_2_0, mult_20_m5, tmp4
+
+    SMLABB  tmp1, x_2_0, mult_20_m5, tmp1
+    SMLADX  tmp3, x_2_0, mult_20_m5, tmp3
+    SMLADX  tmp2, x_2_0, mult_20_01, tmp2
+    SMLADX  tmp4, x_3_1, mult_20_m5, tmp4
+
+    SMLABB  tmp1, x_3_1, mult_20_01, tmp1
+    UXTB16  x_6_4, x_7_5
+    SMLABB  tmp2, x_3_1, mult_20_m5, tmp2
+    SMLADX  tmp3, x_3_1, mult_20_01, tmp3
+    SMLABB  tmp4, x_6_4, mult_20_01, tmp4
+
+    MOV     tmp2, tmp2, ASR #5
+    MOV     tmp1, tmp1, ASR #5
+    PKHBT   tmp2, tmp2, tmp4, LSL #(16-5)
+    PKHBT   tmp1, tmp1, tmp3, LSL #(16-5)
+    LDR     tmp4, [sp, #0x228]
+    USAT16  tmp2, #8, tmp2
+    USAT16  tmp1, #8, tmp1
+    SUB     tmp4, tmp4, #10
+
+    SUBS    count, count, #4<<28
+    LDR     tmp3, [ref, tmp4]
+    ORR     tmp1, tmp1, tmp2, LSL #8
+
+;// quarter pel
+    LDR     tmp2, = 0x80808080
+    MVN     tmp3, tmp3
+    UHSUB8  tmp1, tmp1, tmp3
+    EOR     tmp1, tmp1, tmp2
+
+    STR     tmp1, [mb], #4
+    BCS     loop_x
+
+next_y
+    AND     tmp3, count, #0x00F00000    ;// partWidth-1
+    SMLABB  ref, count, mult_20_01, ref ;// +width
+    ADDS    mb, mb, #16                 ;// +16, Carry=0
+    SBC     mb, mb, tmp3, LSR #20       ;// -(partWidth-1)-1
+    SBC     ref, ref, tmp3, LSR #20     ;// -(partWidth-1)-1
+    ADDS    count, count, #(1<<28)-(1<<24)
+    BGE     loop_y
+
+    ADD     sp,sp,#0x1f4
+    LDMFD   sp!, {r4-r11, pc}
+
+    END
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/arm11_asm/h264bsd_interpolate_hor_ver_quarter.s b/media/libstagefright/codecs/on2/h264dec/source/arm11_asm/h264bsd_interpolate_hor_ver_quarter.s
new file mode 100755
index 0000000..1c79b39
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/arm11_asm/h264bsd_interpolate_hor_ver_quarter.s
@@ -0,0 +1,536 @@
+; 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.
+
+;-------------------------------------------------------------------------------
+;--
+;-- Abstract : ARMv6 optimized version of h264bsdInterpolateHorVerQuarter 
+;--            function
+;--
+;-------------------------------------------------------------------------------
+
+
+    IF :DEF: H264DEC_WINASM
+        ;// We dont use REQUIRE8 and PRESERVE8 for winasm
+    ELSE
+        REQUIRE8
+        PRESERVE8
+    ENDIF
+
+    AREA    |.text|, CODE
+
+;// h264bsdInterpolateHorVerQuarter register allocation
+
+ref     RN 0
+
+mb      RN 1
+buff    RN 1
+
+count   RN 2
+x0      RN 2
+
+y0      RN 3
+x_2_0   RN 3
+res     RN 3
+
+x_3_1   RN 4
+tmp1    RN 4
+
+height  RN 5
+x_6_4   RN 5
+tmp2    RN 5
+
+partW   RN 6
+x_7_5   RN 6
+tmp3    RN 6
+
+partH   RN 7
+tmp4    RN 7
+
+tmp5    RN 8
+
+tmp6    RN 9
+
+tmpa    RN 10
+
+mult_20_01  RN 11
+tmpb        RN 11
+
+mult_20_m5  RN 12
+width       RN 12
+
+plus16  RN 14
+
+
+;// function exports and imports
+
+    IMPORT  h264bsdFillBlock
+
+    EXPORT  h264bsdInterpolateHorVerQuarter
+
+;// Horizontal filter approach
+;//
+;// Basic idea in horizontal filtering is to adjust coefficients
+;// like below. Calculation is done with 16-bit maths.
+;//
+;// Reg     x_2_0     x_3_1     x_6_4     x_7_5     x_2_0
+;//       [  2  0 ] [  3  1 ] [  6  4 ] [  7  5 ] [ 10  8 ] ...
+;// y_0 =   20  1     20 -5        -5         1
+;// y_1 =   -5        20  1      1 20        -5
+;// y_2 =    1        -5        -5 20      1 20
+;// y_3 =              1        20 -5     -5 20         1
+
+
+h264bsdInterpolateHorVerQuarter
+    STMFD   sp!, {r0-r11, lr}
+    SUB     sp, sp, #0x1e4
+
+    CMP     x0, #0
+    BLT     do_fill                 ;// (x0 < 0)
+    LDR     partW, [sp,#0x220]      ;// partWidth
+    LDR     width, [sp,#0x218]      ;// width
+    ADD     tmpa, x0, partW         ;// (x0+partWidth)
+    ADD     tmpa, tmpa, #5          ;// (x0+partW+5)
+    CMP     tmpa, width
+    BHI     do_fill                 ;// (x0+partW)>width
+
+    CMP     y0, #0
+    BLT     do_fill                 ;// (y0 < 0)
+    LDR     partH, [sp,#0x224]      ;// partHeight
+    LDR     height, [sp,#0x21c]     ;// height
+    ADD     tmp5, y0, partH         ;// (y0+partHeight)
+    ADD     tmp5, tmp5, #5          ;// (y0+partH+5)
+    CMP     tmp5, height
+    BLS     skip_fill               ;// no overfill needed
+
+
+do_fill
+    LDR     partH, [sp,#0x224]      ;// partHeight
+    LDR     partW, [sp,#0x220]      ;// partWidth
+    LDR     height, [sp,#0x21c]     ;// height
+    ADD     tmp5, partH, #5         ;// tmp5 = partH + 5
+    ADD     tmpa, partW, #5         ;// tmpa = partW + 5
+    STMIB   sp, {height, tmpa}      ;// sp+4 = height, sp+8 = partWidth+5
+    LDR     width, [sp,#0x218]      ;// width
+    STR     tmp5, [sp,#0xc]         ;// sp+c = partHeight+5
+    STR     tmpa, [sp,#0x10]        ;// sp+10 = partWidth+5
+    STR     width, [sp,#0]          ;// sp+0 = width
+    ADD     buff, sp, #0x28         ;// buff = p1[21*21/4+1]
+    BL      h264bsdFillBlock
+
+    MOV     x0, #0
+    STR     x0,[sp,#0x1ec]          ;// x0 = 0
+    STR     x0,[sp,#0x1f0]          ;// y0 = 0
+    ADD     ref,sp,#0x28            ;// ref = p1
+    STR     tmpa, [sp,#0x218]       ;// width = partWidth+5
+
+
+skip_fill
+    LDR     x0 ,[sp,#0x1ec]         ;// x0
+    LDR     y0 ,[sp,#0x1f0]         ;// y0
+    LDR     width, [sp,#0x218]      ;// width
+    LDR     tmp6, [sp,#0x228]       ;// horVerOffset
+    LDR     mb, [sp, #0x1e8]        ;// mb
+    MLA     tmp5, width, y0, x0     ;// y0*width+x0
+    ADD     ref, ref, tmp5          ;// ref += y0*width+x0
+    STR     ref, [sp, #0x1e4]       ;// store "ref" for vertical filtering
+    AND     tmp6, tmp6, #2          ;// calculate ref for horizontal filter
+    MOV     tmpa, #2
+    ADD     tmp6, tmpa, tmp6, LSR #1
+    MLA     ref, tmp6, width, ref
+    ADD     ref, ref, #8            ;// ref = ref+8
+
+    ;// pack values to count register
+    ;// [31:28] loop_x (partWidth-1)
+    ;// [27:24] loop_y (partHeight-1)
+    ;// [23:20] partWidth-1
+    ;// [19:16] partHeight-1
+    ;// [15:00] width
+    MOV     count, width
+    SUB     partW, partW, #1;
+    SUB     partH, partH, #1;
+    ADD     tmp5, partH, partW, LSL #4
+    ADD     count, count, tmp5, LSL #16
+
+
+    LDR     mult_20_01, = 0x00140001    ;// constant multipliers
+    LDR     mult_20_m5, = 0x0014FFFB    ;// constant multipliers
+    MOV     plus16, #16                 ;// constant for add
+    AND     tmp4, count, #0x000F0000    ;// partHeight-1
+    AND     tmp6, count, #0x00F00000    ;// partWidth-1
+    ADD     count, count, tmp4, LSL #8  ;// partH-1 to lower part of top byte
+
+;// HORIZONTAL PART
+
+loop_y_hor
+    LDR     x_3_1, [ref, #-8]
+    ADD     count, count, tmp6, LSL #8   ;// partW-1 to upper part of top byte
+    LDR     x_7_5, [ref, #-4]
+    UXTB16  x_2_0, x_3_1
+    UXTB16  x_3_1, x_3_1, ROR #8
+    UXTB16  x_6_4, x_7_5
+
+loop_x_hor
+    UXTB16  x_7_5, x_7_5, ROR #8
+
+    SMLAD   tmp4, x_2_0, mult_20_01, plus16
+    SMLATB  tmp6, x_2_0, mult_20_01, plus16
+    SMLATB  tmp5, x_2_0, mult_20_m5, plus16
+    SMLATB  tmpa, x_3_1, mult_20_01, plus16
+
+    SMLAD   tmp4, x_3_1, mult_20_m5, tmp4
+    SMLATB  tmp6, x_3_1, mult_20_m5, tmp6
+    SMLAD   tmp5, x_3_1, mult_20_01, tmp5
+    LDR     x_3_1, [ref], #4
+    SMLAD   tmpa, x_6_4, mult_20_m5, tmpa
+
+    SMLABB  tmp4, x_6_4, mult_20_m5, tmp4
+    SMLADX  tmp6, x_6_4, mult_20_m5, tmp6
+    SMLADX  tmp5, x_6_4, mult_20_01, tmp5
+    SMLADX  tmpa, x_7_5, mult_20_m5, tmpa
+
+    SMLABB  tmp4, x_7_5, mult_20_01, tmp4
+    UXTB16  x_2_0, x_3_1
+    SMLABB  tmp5, x_7_5, mult_20_m5, tmp5
+    SMLADX  tmp6, x_7_5, mult_20_01, tmp6
+    SMLABB  tmpa, x_2_0, mult_20_01, tmpa
+
+    MOV     tmp5, tmp5, ASR #5
+    MOV     tmp4, tmp4, ASR #5
+    PKHBT   tmp5, tmp5, tmpa, LSL #(16-5)
+    PKHBT   tmp4, tmp4, tmp6, LSL #(16-5)
+    USAT16  tmp5, #8, tmp5
+    USAT16  tmp4, #8, tmp4
+
+    SUBS    count, count, #4<<28
+    ORR     tmp4, tmp4, tmp5, LSL #8
+    STR     tmp4, [mb], #4
+    BCC     next_y_hor
+
+    UXTB16  x_3_1, x_3_1, ROR #8
+
+    SMLAD   tmp4, x_6_4, mult_20_01, plus16
+    SMLATB  tmp6, x_6_4, mult_20_01, plus16
+    SMLATB  tmp5, x_6_4, mult_20_m5, plus16
+    SMLATB  tmpa, x_7_5, mult_20_01, plus16
+
+    SMLAD   tmp4, x_7_5, mult_20_m5, tmp4
+    SMLATB  tmp6, x_7_5, mult_20_m5, tmp6
+    SMLAD   tmp5, x_7_5, mult_20_01, tmp5
+    LDR     x_7_5, [ref], #4
+    SMLAD   tmpa, x_2_0, mult_20_m5, tmpa
+
+    SMLABB  tmp4, x_2_0, mult_20_m5, tmp4
+    SMLADX  tmp6, x_2_0, mult_20_m5, tmp6
+    SMLADX  tmp5, x_2_0, mult_20_01, tmp5
+    SMLADX  tmpa, x_3_1, mult_20_m5, tmpa
+
+    SMLABB  tmp4, x_3_1, mult_20_01, tmp4
+    UXTB16  x_6_4, x_7_5
+    SMLABB  tmp5, x_3_1, mult_20_m5, tmp5
+    SMLADX  tmp6, x_3_1, mult_20_01, tmp6
+    SMLABB  tmpa, x_6_4, mult_20_01, tmpa
+
+    MOV     tmp5, tmp5, ASR #5
+    MOV     tmp4, tmp4, ASR #5
+    PKHBT   tmp5, tmp5, tmpa, LSL #(16-5)
+    PKHBT   tmp4, tmp4, tmp6, LSL #(16-5)
+    USAT16  tmp5, #8, tmp5
+    USAT16  tmp4, #8, tmp4
+
+    SUBS    count, count, #4<<28
+    ORR     tmp4, tmp4, tmp5, LSL #8
+    STR     tmp4, [mb], #4
+    BCS     loop_x_hor
+
+next_y_hor
+    AND     tmp6, count, #0x00F00000        ;// partWidth-1
+    SMLABB  ref, count, mult_20_01, ref     ;// +width
+    ADDS    mb, mb, #16                     ;// +16, Carry=0
+    SBC     mb, mb, tmp6, LSR #20           ;// -(partWidth-1)-1
+    SBC     ref, ref, tmp6, LSR #20         ;// -(partWidth-1)-1
+    ADDS    count, count, #(1<<28)-(1<<24)  ;// decrement counter (partW)
+    BGE     loop_y_hor
+
+
+
+;// VERTICAL PART
+;//
+;// Approach to vertical interpolation
+;//
+;// Interpolation is done by using 32-bit loads and stores
+;// and by using 16 bit arithmetic. 4x4 block is processed
+;// in each round.
+;//
+;// |a_11|a_11|a_11|a_11|...|a_1n|a_1n|a_1n|a_1n|
+;// |b_11|b_11|b_11|b_11|...|b_1n|b_1n|b_1n|b_1n|
+;// |c_11|c_11|c_11|c_11|...|c_1n|c_1n|c_1n|c_1n|
+;// |d_11|d_11|d_11|d_11|...|d_1n|d_1n|d_1n|d_1n|
+;//           ..
+;//           ..
+;// |a_m1|a_m1|a_m1|a_m1|...
+;// |b_m1|b_m1|b_m1|b_m1|...
+;// |c_m1|c_m1|c_m1|c_m1|...
+;// |d_m1|d_m1|d_m1|d_m1|...
+
+;// Approach to bilinear interpolation to quarter pel position.
+;// 4 bytes are processed parallel
+;//
+;// algorithm (a+b+1)/2. Rouding upwards +1 can be achieved by 
+;// negating second operand to get one's complement (instead of 2's)
+;// and using subtraction, EOR is used to correct sign.
+;//
+;// MVN     b, b
+;// UHSUB8  a, a, b
+;// EOR     a, a, 0x80808080
+
+
+    LDR     ref, [sp, #0x1e4]           ;// ref
+    LDR     tmpa, [sp, #0x228]          ;// horVerOffset
+    LDR     mb, [sp, #0x1e8]            ;// mb
+    LDR     width, [sp, #0x218]         ;// width
+    ADD     ref, ref, #2                ;// calculate correct position
+    AND     tmpa, tmpa, #1
+    ADD     ref, ref, tmpa
+    LDR     plus16, = 0x00100010        ;// +16 to lower and upperf halfwords
+    AND     count, count, #0x00FFFFFF   ;// partWidth-1
+
+    AND     tmpa, count, #0x000F0000    ;// partHeight-1
+    ADD     count, count, tmpa, LSL #8
+
+loop_y
+    ADD     count, count, tmp6, LSL #8  ;// partWidth-1
+
+loop_x
+    LDR     tmp1, [ref], width     ;// |a4|a3|a2|a1|
+    LDR     tmp2, [ref], width     ;// |c4|c3|c2|c1|
+    LDR     tmp3, [ref], width     ;// |g4|g3|g2|g1|
+    LDR     tmp4, [ref], width     ;// |m4|m3|m2|m1|
+    LDR     tmp5, [ref], width     ;// |r4|r3|r2|r1|
+    LDR     tmp6, [ref], width     ;// |t4|t3|t2|t1|
+
+    ;// first four pixels 
+    UXTB16  tmpa, tmp3                  ;// |g3|g1|
+    UXTAB16 tmpa, tmpa, tmp4            ;// |g3+m3|g1+m1|
+    UXTB16  tmpb, tmp2                  ;// |c3|c1|
+    ADD     tmpa, tmpa, tmpa, LSL #2    ;// 5(G+M)
+
+    UXTAB16 tmpb, tmpb, tmp5            ;// |c3+r3|c1+r1|
+    ADD     tmpa, plus16, tmpa, LSL #2  ;// 16+20(G+M)
+    UXTAB16 tmpa, tmpa, tmp1            ;// 16+20(G+M)+A
+    UXTAB16 tmpa, tmpa, tmp6            ;// 16+20(G+M)+A+T
+
+    ADD     tmpb, tmpb, tmpb, LSL #2    ;// 5(C+R)
+    SSUB16  tmpa, tmpa, tmpb            ;// 16+20(G+M)+(A+T)-5(C+R)
+
+    USAT16  tmpb, #13, tmpa             ;// saturate
+    LDR     res, = 0x00FF00FF
+    UXTB16  tmpa, tmp3, ROR #8          ;// |g4|g2|
+    UXTAB16 tmpa, tmpa, tmp4, ROR #8    ;// |g4+m4|g2+m2|
+    AND     res, res, tmpb, LSR #5      ;// mask and divide by 32
+
+    ADD     tmpa, tmpa, tmpa, LSL #2    ;// 5(G+M)
+    UXTB16  tmpb, tmp2, ROR #8          ;// |c4|c2|
+    ADD     tmpa, plus16, tmpa, LSL #2  ;// 16+20(G+M)
+    UXTAB16 tmpb, tmpb, tmp5, ROR #8    ;// |c4+r4|c2+r2|
+    UXTAB16 tmpa, tmpa, tmp1, ROR #8    ;// 16+20(G+M)+A
+    UXTAB16 tmpa, tmpa, tmp6, ROR #8    ;// 16+20(G+M)+A+T
+
+    ADD     tmpb, tmpb, tmpb, LSL #2    ;// 5(C+R)
+    SSUB16  tmpa, tmpa, tmpb            ;// 16+20(G+M)+(A+T)-5(C+R)
+
+    USAT16  tmpb, #13, tmpa             ;// saturate
+    LDR     tmp1, [mb]
+    LDR     tmpa, = 0xFF00FF00
+    MVN     tmp1, tmp1
+    AND     tmpa, tmpa, tmpb, LSL #3    ;// mask and divede by 32
+    ORR     res, res, tmpa
+
+    LDR     tmpa, = 0x80808080
+    UHSUB8  res, res, tmp1              ;// bilinear interpolation
+    LDR     tmp1, [ref], width          ;// load next row
+    EOR     res, res, tmpa              ;// correct sign
+
+    STR     res, [mb], #16              ;// next row (mb)
+
+
+    ;// tmp2 = |a4|a3|a2|a1|
+    ;// tmp3 = |c4|c3|c2|c1|
+    ;// tmp4 = |g4|g3|g2|g1|
+    ;// tmp5 = |m4|m3|m2|m1|
+    ;// tmp6 = |r4|r3|r2|r1|
+    ;// tmp1 = |t4|t3|t2|t1|
+
+    ;// second four pixels
+    UXTB16  tmpa, tmp4                  ;// |g3|g1|
+    UXTAB16 tmpa, tmpa, tmp5            ;// |g3+m3|g1+m1|
+    UXTB16  tmpb, tmp3                  ;// |c3|c1|
+    ADD     tmpa, tmpa, tmpa, LSL #2    ;// 5(G+M)
+    UXTAB16 tmpb, tmpb, tmp6            ;// |c3+r3|c1+r1|
+    ADD     tmpa, plus16, tmpa, LSL #2  ;// 16+20(G+M)
+    UXTAB16 tmpa, tmpa, tmp2            ;// 16+20(G+M)+A
+    UXTAB16 tmpa, tmpa, tmp1            ;// 16+20(G+M)+A+T
+
+    ADD     tmpb, tmpb, tmpb, LSL #2    ;// 5(C+R)
+    SSUB16  tmpa, tmpa, tmpb            ;// 16+20(G+M)+(A+T)-5(C+R)
+
+    USAT16  tmpb, #13, tmpa             ;// saturate
+    LDR     res, = 0x00FF00FF
+    UXTB16  tmpa, tmp4, ROR #8          ;// |g4|g2|
+    UXTAB16 tmpa, tmpa, tmp5, ROR #8    ;// |g4+m4|g2+m2|
+    AND     res, res, tmpb, LSR #5      ;// mask and divide by 32
+
+    ADD     tmpa, tmpa, tmpa, LSL #2    ;// 5(G+M)
+    UXTB16  tmpb, tmp3, ROR #8          ;// |c4|c2|
+    ADD     tmpa, plus16, tmpa, LSL #2  ;// 16+20(G+M)
+    UXTAB16 tmpb, tmpb, tmp6, ROR #8    ;// |c4+r4|c2+r2|
+    UXTAB16 tmpa, tmpa, tmp2, ROR #8    ;// 16+20(G+M)+A
+    UXTAB16 tmpa, tmpa, tmp1, ROR #8    ;// 16+20(G+M)+A+T
+
+    ADD     tmpb, tmpb, tmpb, LSL #2    ;// 5(C+R)
+    SSUB16  tmpa, tmpa, tmpb            ;// 16+20(G+M)+(A+T)-5(C+R)
+
+    USAT16  tmpb, #13, tmpa             ;// saturate
+    LDR     tmp2, [mb]
+    LDR     tmpa, = 0xFF00FF00
+    MVN     tmp2, tmp2
+
+    AND     tmpa, tmpa, tmpb, LSL #3    ;// mask and divide by 32
+    ORR     res, res, tmpa
+    LDR     tmpa, = 0x80808080
+    UHSUB8  res, res, tmp2              ;// bilinear interpolation
+    LDR     tmp2, [ref], width          ;// load next row
+    EOR     res, res, tmpa              ;// correct sign
+    STR     res, [mb], #16              ;// next row
+
+    ;// tmp3 = |a4|a3|a2|a1|
+    ;// tmp4 = |c4|c3|c2|c1|
+    ;// tmp5 = |g4|g3|g2|g1|
+    ;// tmp6 = |m4|m3|m2|m1|
+    ;// tmp1 = |r4|r3|r2|r1|
+    ;// tmp2 = |t4|t3|t2|t1|
+
+    ;// third four pixels
+    UXTB16  tmpa, tmp5                  ;// |g3|g1|
+    UXTAB16 tmpa, tmpa, tmp6            ;// |g3+m3|g1+m1|
+    UXTB16  tmpb, tmp4                  ;// |c3|c1|
+    ADD     tmpa, tmpa, tmpa, LSL #2    ;// 5(G+M)
+    UXTAB16 tmpb, tmpb, tmp1            ;// |c3+r3|c1+r1|
+    ADD     tmpa, plus16, tmpa, LSL #2  ;// 16+20(G+M)
+    UXTAB16 tmpa, tmpa, tmp3            ;// 16+20(G+M)+A
+    UXTAB16 tmpa, tmpa, tmp2            ;// 16+20(G+M)+A+T
+
+    ADD     tmpb, tmpb, tmpb, LSL #2    ;// 5(C+R)
+    SSUB16  tmpa, tmpa, tmpb            ;// 16+20(G+M)+(A+T)-5(C+R)
+
+    USAT16  tmpb, #13, tmpa             ;// saturate
+    LDR     res, = 0x00FF00FF
+    UXTB16  tmpa, tmp5, ROR #8          ;// |g4|g2|
+    UXTAB16 tmpa, tmpa, tmp6, ROR #8    ;// |g4+m4|g2+m2|
+    AND     res, res, tmpb, LSR #5      ;// mask and divide by 32
+
+    ADD     tmpa, tmpa, tmpa, LSL #2    ;// 5(G+M)
+    UXTB16  tmpb, tmp4, ROR #8          ;// |c4|c2|
+    ADD     tmpa, plus16, tmpa, LSL #2  ;// 16+20(G+M)
+    UXTAB16 tmpb, tmpb, tmp1, ROR #8    ;// |c4+r4|c2+r2|
+    UXTAB16 tmpa, tmpa, tmp3, ROR #8    ;// 16+20(G+M)+A
+    UXTAB16 tmpa, tmpa, tmp2, ROR #8    ;// 16+20(G+M)+A+T
+
+
+    ADD     tmpb, tmpb, tmpb, LSL #2    ;// 5(C+R)
+    SSUB16  tmpa, tmpa, tmpb            ;// 16+20(G+M)+(A+T)-5(C+R)
+
+    USAT16  tmpb, #13, tmpa             ;// saturate
+    LDR     tmp3, [mb]
+    LDR     tmpa, = 0xFF00FF00
+    MVN     tmp3, tmp3
+
+    AND     tmpa, tmpa, tmpb, LSL #3    ;// mask and divide by 32
+    ORR     res, res, tmpa
+    LDR     tmpa, = 0x80808080
+    UHSUB8  res, res, tmp3              ;// bilinear interpolation
+    LDR     tmp3, [ref]                 ;// load next row
+    EOR     res, res, tmpa              ;// correct sign
+    STR     res, [mb], #16              ;// next row
+
+    ;// tmp4 = |a4|a3|a2|a1|
+    ;// tmp5 = |c4|c3|c2|c1|
+    ;// tmp6 = |g4|g3|g2|g1|
+    ;// tmp1 = |m4|m3|m2|m1|
+    ;// tmp2 = |r4|r3|r2|r1|
+    ;// tmp3 = |t4|t3|t2|t1|
+
+    ;// fourth four pixels
+    UXTB16  tmpa, tmp6                  ;// |g3|g1|
+    UXTAB16 tmpa, tmpa, tmp1            ;// |g3+m3|g1+m1|
+    UXTB16  tmpb, tmp5                  ;// |c3|c1|
+    ADD     tmpa, tmpa, tmpa, LSL #2    ;// 5(G+M)
+    UXTAB16 tmpb, tmpb, tmp2            ;// |c3+r3|c1+r1|
+    ADD     tmpa, plus16, tmpa, LSL #2  ;// 16+20(G+M)
+    UXTAB16 tmpa, tmpa, tmp4            ;// 16+20(G+M)+A
+    UXTAB16 tmpa, tmpa, tmp3            ;// 16+20(G+M)+A+T
+
+    ADD     tmpb, tmpb, tmpb, LSL #2    ;// 5(C+R)
+    SSUB16  tmpa, tmpa, tmpb            ;// 16+20(G+M)+(A+T)-5(C+R)
+
+    USAT16  tmpb, #13, tmpa             ;// saturate
+    LDR     res, = 0x00FF00FF
+    UXTB16  tmpa, tmp6, ROR #8          ;// |g4|g2|
+    UXTAB16 tmpa, tmpa, tmp1, ROR #8    ;// |g4+m4|g2+m2|
+    AND     res, res, tmpb, LSR #5      ;// mask and divide by 32
+
+    ADD     tmpa, tmpa, tmpa, LSL #2    ;// 5(G+M)
+    UXTB16  tmpb, tmp5, ROR #8          ;// |c4|c2|
+    ADD     tmpa, plus16, tmpa, LSL #2  ;// 16+20(G+M)
+    UXTAB16 tmpb, tmpb, tmp2, ROR #8    ;// |c4+r4|c2+r2|
+    UXTAB16 tmpa, tmpa, tmp4, ROR #8    ;// 16+20(G+M)+A
+    UXTAB16 tmpa, tmpa, tmp3, ROR #8    ;// 16+20(G+M)+A+T
+
+    ADD     tmpb, tmpb, tmpb, LSL #2    ;// 5(C+R)
+    SSUB16  tmpa, tmpa, tmpb            ;// 16+20(G+M)+(A+T)-5(C+R)
+
+    USAT16  tmpb, #13, tmpa             ;// saturate
+    LDR     tmp5, [mb]
+    LDR     tmp4, = 0xFF00FF00
+    MVN     tmp5, tmp5
+
+    AND     tmpa, tmp4, tmpb, LSL #3    ;// mask and divide by 32
+    ORR     res, res, tmpa
+    LDR     tmpa, = 0x80808080
+    UHSUB8  res, res, tmp5              ;// bilinear interpolation
+
+    ;// decrement loop_x counter
+    SUBS    count, count, #4<<28        ;// decrement x loop counter
+
+    ;// calculate "ref" address for next round
+    SUB     ref, ref, width, LSL #3     ;// ref -= 8*width;
+    ADD     ref, ref, #4                ;// next column (4 pixels)
+
+    EOR     res, res, tmpa              ;// correct sign
+    STR     res, [mb], #-44
+
+    BCS     loop_x
+
+    ADDS    mb, mb, #64                 ;// set Carry=0
+    ADD     ref, ref, width, LSL #2     ;// ref += 4*width
+    AND     tmp6, count, #0x00F00000    ;// partWidth-1
+    SBC     ref, ref, tmp6, LSR #20     ;// -(partWidth-1)-1
+    SBC     mb, mb, tmp6, LSR #20       ;// -(partWidth-1)-1
+
+    ADDS    count, count, #0xC << 24    ;// decrement y loop counter
+    BGE     loop_y
+
+    ADD     sp, sp, #0x1f4
+    LDMFD   sp!, {r4-r11, pc}
+
+    END
diff --git a/media/libstagefright/codecs/on2/h264dec/source/arm11_asm/h264bsd_interpolate_mid_hor.s b/media/libstagefright/codecs/on2/h264dec/source/arm11_asm/h264bsd_interpolate_mid_hor.s
new file mode 100755
index 0000000..a81aed7
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/arm11_asm/h264bsd_interpolate_mid_hor.s
@@ -0,0 +1,163 @@
+; 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.

+

+;-------------------------------------------------------------------------------

+;--

+;-- Abstract : ARMv6 optimized version horizontal part of 

+;--            h264bsdInterpolateMid functions

+;--

+;-------------------------------------------------------------------------------

+

+

+    IF :DEF: H264DEC_WINASM

+        ;// We dont use REQUIRE8 and PRESERVE8 for winasm

+    ELSE

+        REQUIRE8

+        PRESERVE8

+    ENDIF

+

+    AREA    |.text|, CODE

+

+

+;// Register allocation

+

+ref     RN 0    ;// pointer to current position in reference image

+mb      RN 1    ;// pointer to current position in interpolated mb

+count   RN 2    ;// bit-packed width and count values

+

+x_2_0   RN 4

+x_3_1   RN 5

+x_6_4   RN 6

+x_7_5   RN 7

+

+tmp1    RN 8

+tmp2    RN 9

+tmp3    RN 10

+tmp4    RN 11

+

+mult_20_01  RN 12   ;// [20,  1]

+mult_20_m5  RN 14   ;// [20, -5]

+

+

+        EXPORT  h264bsdInterpolateMidHorPart

+

+;// Horizontal filter approach

+;//

+;// Basic idea in horizontal filtering is to adjust coefficients

+;// like below. Calculation is done with 16-bit maths.

+;//

+;// Reg     x_2_0     x_3_1     x_6_4     x_7_5     x_2_0

+;//       [  2  0 ] [  3  1 ] [  6  4 ] [  7  5 ] [ 10  8 ] ...

+;// y_0 =   20  1     20 -5        -5         1

+;// y_1 =   -5        20  1      1 20        -5

+;// y_2 =    1        -5        -5 20      1 20

+;// y_3 =              1        20 -5     -5 20         1

+

+

+h264bsdInterpolateMidHorPart

+    STMFD   sp!, {r4-r11, lr}

+

+    ;// pack values to count register

+    ;// [31:28] loop_x (partWidth-1)

+    ;// [27:24] loop_y (partHeight-1)

+    ;// [23:20] partWidth-1

+    ;// [19:16] partHeight-1

+    ;// [15:00] width

+

+

+    LDR     mult_20_01, = 0x00140001

+    LDR     mult_20_m5, = 0x0014FFFB

+    AND     tmp3, count, #0x000F0000    ;// partWidth-1

+loop_y

+    LDR     x_3_1, [ref, #-8]

+    ADD     count, count, tmp3, LSL #12

+    LDR     x_7_5, [ref, #-4]

+    UXTB16  x_2_0, x_3_1

+    UXTB16  x_3_1, x_3_1, ROR #8

+    UXTB16  x_6_4, x_7_5

+

+loop_x

+    UXTB16  x_7_5, x_7_5, ROR #8

+

+    SMUAD   tmp1, x_2_0, mult_20_01

+    SMULTB  tmp2, x_2_0, mult_20_m5

+    SMULTB  tmp3, x_2_0, mult_20_01

+    SMULTB  tmp4, x_3_1, mult_20_01

+

+    SMLAD   tmp1, x_3_1, mult_20_m5, tmp1

+    SMLAD   tmp2, x_3_1, mult_20_01, tmp2

+    SMLATB  tmp3, x_3_1, mult_20_m5, tmp3

+    LDR     x_3_1, [ref], #4

+    SMLAD   tmp4, x_6_4, mult_20_m5, tmp4

+

+    SMLABB  tmp1, x_6_4, mult_20_m5, tmp1

+    SMLADX  tmp2, x_6_4, mult_20_01, tmp2

+    SMLADX  tmp3, x_6_4, mult_20_m5, tmp3

+    SMLADX  tmp4, x_7_5, mult_20_m5, tmp4

+

+    SMLABB  tmp1, x_7_5, mult_20_01, tmp1

+    SMLABB  tmp2, x_7_5, mult_20_m5, tmp2

+    UXTB16  x_2_0, x_3_1

+    SMLADX  tmp3, x_7_5, mult_20_01, tmp3

+    SMLABB  tmp4, x_2_0, mult_20_01, tmp4

+

+    SUBS    count, count, #4<<28

+    STR     tmp1, [mb], #4

+    STR     tmp2, [mb], #4

+    STR     tmp3, [mb], #4

+    STR     tmp4, [mb], #4

+    BCC     next_y

+

+    UXTB16  x_3_1, x_3_1, ROR #8

+

+    SMUAD   tmp1, x_6_4, mult_20_01

+    SMULTB  tmp2, x_6_4, mult_20_m5

+    SMULTB  tmp3, x_6_4, mult_20_01

+    SMULTB  tmp4, x_7_5, mult_20_01

+

+    SMLAD   tmp1, x_7_5, mult_20_m5, tmp1

+    SMLAD   tmp2, x_7_5, mult_20_01, tmp2

+    SMLATB  tmp3, x_7_5, mult_20_m5, tmp3

+    LDR     x_7_5, [ref], #4

+    SMLAD   tmp4, x_2_0, mult_20_m5, tmp4

+

+    SMLABB  tmp1, x_2_0, mult_20_m5, tmp1

+    SMLADX  tmp2, x_2_0, mult_20_01, tmp2

+    SMLADX  tmp3, x_2_0, mult_20_m5, tmp3

+    SMLADX  tmp4, x_3_1, mult_20_m5, tmp4

+

+    SMLABB  tmp1, x_3_1, mult_20_01, tmp1

+    SMLABB  tmp2, x_3_1, mult_20_m5, tmp2

+    UXTB16  x_6_4, x_7_5

+    SMLADX  tmp3, x_3_1, mult_20_01, tmp3

+    SMLABB  tmp4, x_6_4, mult_20_01, tmp4

+

+    SUBS    count, count, #4<<28

+    STR     tmp1, [mb], #4

+    STR     tmp2, [mb], #4

+    STR     tmp3, [mb], #4

+    STR     tmp4, [mb], #4

+    BCS     loop_x

+

+next_y

+    AND     tmp3, count, #0x000F0000    ;// partWidth-1

+    SMLABB  ref, count, mult_20_01, ref   ;// +width

+    SBC     ref, ref, tmp3, LSR #16   ;// -(partWidth-1)-1

+    ADDS    count, count, #(1<<28)-(1<<20)

+    BGE     loop_y

+

+    LDMFD   sp!, {r4-r11, pc}

+

+    END

+

diff --git a/media/libstagefright/codecs/on2/h264dec/source/arm11_asm/h264bsd_interpolate_ver_half.s b/media/libstagefright/codecs/on2/h264dec/source/arm11_asm/h264bsd_interpolate_ver_half.s
new file mode 100755
index 0000000..244fc6f
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/arm11_asm/h264bsd_interpolate_ver_half.s
@@ -0,0 +1,347 @@
+; 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.
+
+;-------------------------------------------------------------------------------
+;--
+;-- Abstract : ARMv6 optimized version of h264bsdInterpolateVerHalf function
+;--
+;-------------------------------------------------------------------------------
+
+
+    IF :DEF: H264DEC_WINASM
+        ;// We dont use REQUIRE8 and PRESERVE8 for winasm
+    ELSE
+        REQUIRE8
+        PRESERVE8
+    ENDIF
+
+    AREA    |.text|, CODE
+
+;// h264bsdInterpolateVerHalf register allocation
+
+ref     RN 0
+
+mb      RN 1
+buff    RN 1
+
+count   RN 2
+x0      RN 2
+
+res     RN 3
+y0      RN 3
+
+tmp1    RN 4
+
+tmp2    RN 5
+height  RN 5
+
+tmp3    RN 6
+partW   RN 6
+
+tmp4    RN 7
+partH   RN 7
+
+tmp5    RN 8
+tmp6    RN 9
+
+tmpa    RN 10
+tmpb    RN 11
+width   RN 12
+
+plus16  RN 14
+
+
+;// function exports and imports
+
+    IMPORT  h264bsdFillBlock
+
+    EXPORT  h264bsdInterpolateVerHalf
+
+;// Approach to vertical interpolation
+;//
+;// Interpolation is done by using 32-bit loads and stores
+;// and by using 16 bit arithmetic. 4x4 block is processed
+;// in each round.
+;//
+;// |a_11|a_11|a_11|a_11|...|a_1n|a_1n|a_1n|a_1n|
+;// |b_11|b_11|b_11|b_11|...|b_1n|b_1n|b_1n|b_1n|
+;// |c_11|c_11|c_11|c_11|...|c_1n|c_1n|c_1n|c_1n|
+;// |d_11|d_11|d_11|d_11|...|d_1n|d_1n|d_1n|d_1n|
+;//           ..
+;//           ..
+;// |a_m1|a_m1|a_m1|a_m1|...
+;// |b_m1|b_m1|b_m1|b_m1|...
+;// |c_m1|c_m1|c_m1|c_m1|...
+;// |d_m1|d_m1|d_m1|d_m1|...
+
+h264bsdInterpolateVerHalf
+    STMFD   sp!, {r0-r11, lr}
+    SUB     sp, sp, #0x1e4
+
+    CMP     x0, #0
+    BLT     do_fill                 ;// (x0 < 0)
+    LDR     partW, [sp,#0x220]      ;// partWidth
+    ADD     tmp5, x0, partW         ;// (x0+partWidth)
+    LDR     width, [sp,#0x218]      ;// width
+    CMP     tmp5, width
+    BHI     do_fill                 ;// (x0+partW)>width
+
+    CMP     y0, #0
+    BLT     do_fill                 ;// (y0 < 0)
+    LDR     partH, [sp,#0x224]      ;// partHeight
+    ADD     tmp6, y0, partH         ;// (y0+partHeight)
+    ADD     tmp6, tmp6, #5          ;// (y0+partH+5)
+    LDR     height, [sp,#0x21c]     ;// height
+    CMP     tmp6, height
+    BLS     skip_fill               ;// no overfill needed
+
+
+do_fill
+    LDR     partH, [sp,#0x224]      ;// partHeight
+    ADD     tmp5, partH, #5         ;// r2 = partH + 5;
+    LDR     height, [sp,#0x21c]     ;// height
+    LDR     partW, [sp,#0x220]      ;// partWidth
+    STMIB   sp, {height, partW}     ;// sp+4 = height, sp+8 = partWidth
+    STR     tmp5, [sp,#0xc]         ;// sp+c partHeight+5
+    STR     partW, [sp,#0x10]       ;// sp+10 = partWidth
+    LDR     width, [sp,#0x218]      ;// width
+    STR     width, [sp,#0]          ;// sp+0 = width
+    ADD     buff, sp, #0x28         ;// buff = p1[21*21/4+1]
+    BL      h264bsdFillBlock
+
+    MOV     x0, #0
+    STR     x0,[sp,#0x1ec]          ;// x0 = 0
+    STR     x0,[sp,#0x1f0]          ;// y0 = 0
+    ADD     ref,sp,#0x28            ;// ref = p1
+    STR     partW, [sp,#0x218]
+
+
+skip_fill
+    LDR     x0 ,[sp,#0x1ec]         ;// x0
+    LDR     y0 ,[sp,#0x1f0]         ;// y0
+    LDR     width, [sp,#0x218]      ;// width
+    MLA     tmp6, width, y0, x0     ;// y0*width+x0
+    ADD     ref, ref, tmp6          ;// ref += y0*width+x0
+    LDR     mb, [sp, #0x1e8]        ;// mb
+
+    ADD     count, partW, partH, LSL #16    ;// |partH|partW|
+    LDR     tmp5, = 0x00010001
+    SSUB16  count, count, tmp5;     ;// |partH-1|partW-1|
+    LDR     plus16, = 0x00100010
+
+    AND     tmp1, count, #0x000000FF ;// partWidth
+
+
+loop_y
+    ADD     count, count, tmp1, LSL #24  ;// partWidth-1 to top byte
+
+loop_x
+    LDR     tmp1, [ref], width     ;// |a4|a3|a2|a1|
+    LDR     tmp2, [ref], width     ;// |c4|c3|c2|c1|
+    LDR     tmp3, [ref], width     ;// |g4|g3|g2|g1|
+    LDR     tmp4, [ref], width     ;// |m4|m3|m2|m1|
+    LDR     tmp5, [ref], width     ;// |r4|r3|r2|r1|
+    LDR     tmp6, [ref], width     ;// |t4|t3|t2|t1|
+
+    ;// first four pixels
+    UXTB16  tmpa, tmp3                  ;// |g3|g1|
+    UXTAB16 tmpa, tmpa, tmp4            ;// |g3+m3|g1+m1|
+    UXTB16  tmpb, tmp2                  ;// |c3|c1|
+    ADD     tmpa, tmpa, tmpa, LSL #2    ;// 5(G+M)
+
+    UXTAB16 tmpb, tmpb, tmp5            ;// |c3+r3|c1+r1|
+    ADD     tmpa, plus16, tmpa, LSL #2  ;// 16+20(G+M)
+    UXTAB16 tmpa, tmpa, tmp1            ;// 16+20(G+M)+A
+    UXTAB16 tmpa, tmpa, tmp6            ;// 16+20(G+M)+A+T
+
+    ADD     tmpb, tmpb, tmpb, LSL #2    ;// 5(C+R)
+    SSUB16  tmpa, tmpa, tmpb            ;// 16+20(G+M)+(A+T)-5(C+R)
+
+    USAT16  tmpb, #13, tmpa             ;// saturate
+    LDR     res, = 0x00FF00FF
+    UXTB16  tmpa, tmp3, ROR #8          ;// |g4|g2|
+    UXTAB16 tmpa, tmpa, tmp4, ROR #8    ;// |g4+m4|g2+m2|
+    AND     res, res, tmpb, LSR #5      ;// mask and divide by 32
+
+    ADD     tmpa, tmpa, tmpa, LSL #2    ;// 5(G+M)
+    UXTB16  tmpb, tmp2, ROR #8          ;// |c4|c2|
+    ADD     tmpa, plus16, tmpa, LSL #2  ;// 16+20(G+M)
+    UXTAB16 tmpb, tmpb, tmp5, ROR #8    ;// |c4+r4|c2+r2|
+    UXTAB16 tmpa, tmpa, tmp1, ROR #8    ;// 16+20(G+M)+A
+    UXTAB16 tmpa, tmpa, tmp6, ROR #8    ;// 16+20(G+M)+A+T
+
+    ADD     tmpb, tmpb, tmpb, LSL #2    ;// 5(C+R)
+    SSUB16  tmpa, tmpa, tmpb            ;// 16+20(G+M)+(A+T)-5(C+R)
+
+    USAT16  tmpb, #13, tmpa             ;// saturate
+    LDR     tmp1, [ref], width
+    LDR     tmpa, = 0xFF00FF00
+
+    AND     tmpa, tmpa, tmpb, LSL #3    ;// mask and divede by 32
+    ORR     res, res, tmpa
+    STR     res, [mb], #16              ;// next row (mb)
+
+    ;// tmp2 = |a4|a3|a2|a1|
+    ;// tmp3 = |c4|c3|c2|c1|
+    ;// tmp4 = |g4|g3|g2|g1|
+    ;// tmp5 = |m4|m3|m2|m1|
+    ;// tmp6 = |r4|r3|r2|r1|
+    ;// tmp1 = |t4|t3|t2|t1|
+
+    ;// second four pixels
+    UXTB16  tmpa, tmp4                  ;// |g3|g1|
+    UXTAB16 tmpa, tmpa, tmp5            ;// |g3+m3|g1+m1|
+    UXTB16  tmpb, tmp3                  ;// |c3|c1|
+    ADD     tmpa, tmpa, tmpa, LSL #2    ;// 5(G+M)
+    UXTAB16 tmpb, tmpb, tmp6            ;// |c3+r3|c1+r1|
+    ADD     tmpa, plus16, tmpa, LSL #2  ;// 16+20(G+M)
+    UXTAB16 tmpa, tmpa, tmp2            ;// 16+20(G+M)+A
+    UXTAB16 tmpa, tmpa, tmp1            ;// 16+20(G+M)+A+T
+
+    ADD     tmpb, tmpb, tmpb, LSL #2    ;// 5(C+R)
+    SSUB16  tmpa, tmpa, tmpb            ;// 16+20(G+M)+(A+T)-5(C+R)
+
+    USAT16  tmpb, #13, tmpa             ;// saturate
+    LDR     res, = 0x00FF00FF
+    UXTB16  tmpa, tmp4, ROR #8          ;// |g4|g2|
+    UXTAB16 tmpa, tmpa, tmp5, ROR #8    ;// |g4+m4|g2+m2|
+    AND     res, res, tmpb, LSR #5      ;// mask and divide by 32
+
+    ADD     tmpa, tmpa, tmpa, LSL #2    ;// 5(G+M)
+    UXTB16  tmpb, tmp3, ROR #8          ;// |c4|c2|
+    ADD     tmpa, plus16, tmpa, LSL #2  ;// 16+20(G+M)
+    UXTAB16 tmpb, tmpb, tmp6, ROR #8    ;// |c4+r4|c2+r2|
+    UXTAB16 tmpa, tmpa, tmp2, ROR #8    ;// 16+20(G+M)+A
+    UXTAB16 tmpa, tmpa, tmp1, ROR #8    ;// 16+20(G+M)+A+T
+
+    ADD     tmpb, tmpb, tmpb, LSL #2    ;// 5(C+R)
+    SSUB16  tmpa, tmpa, tmpb            ;// 16+20(G+M)+(A+T)-5(C+R)
+
+    USAT16  tmpb, #13, tmpa             ;// saturate
+    LDR     tmp2, [ref], width
+    LDR     tmpa, = 0xFF00FF00
+
+    AND     tmpa, tmpa, tmpb, LSL #3    ;// mask and divide by 32
+    ORR     res, res, tmpa
+    STR     res, [mb], #16              ;// next row
+
+    ;// tmp3 = |a4|a3|a2|a1|
+    ;// tmp4 = |c4|c3|c2|c1|
+    ;// tmp5 = |g4|g3|g2|g1|
+    ;// tmp6 = |m4|m3|m2|m1|
+    ;// tmp1 = |r4|r3|r2|r1|
+    ;// tmp2 = |t4|t3|t2|t1|
+
+    ;// third four pixels
+    UXTB16  tmpa, tmp5                  ;// |g3|g1|
+    UXTAB16 tmpa, tmpa, tmp6            ;// |g3+m3|g1+m1|
+    UXTB16  tmpb, tmp4                  ;// |c3|c1|
+    ADD     tmpa, tmpa, tmpa, LSL #2    ;// 5(G+M)
+    UXTAB16 tmpb, tmpb, tmp1            ;// |c3+r3|c1+r1|
+    ADD     tmpa, plus16, tmpa, LSL #2  ;// 16+20(G+M)
+    UXTAB16 tmpa, tmpa, tmp3            ;// 16+20(G+M)+A
+    UXTAB16 tmpa, tmpa, tmp2            ;// 16+20(G+M)+A+T
+
+    ADD     tmpb, tmpb, tmpb, LSL #2    ;// 5(C+R)
+    SSUB16  tmpa, tmpa, tmpb            ;// 16+20(G+M)+(A+T)-5(C+R)
+
+    USAT16  tmpb, #13, tmpa             ;// saturate
+    LDR     res, = 0x00FF00FF
+    UXTB16  tmpa, tmp5, ROR #8          ;// |g4|g2|
+    UXTAB16 tmpa, tmpa, tmp6, ROR #8    ;// |g4+m4|g2+m2|
+    AND     res, res, tmpb, LSR #5      ;// mask and divide by 32
+
+    ADD     tmpa, tmpa, tmpa, LSL #2    ;// 5(G+M)
+    UXTB16  tmpb, tmp4, ROR #8          ;// |c4|c2|
+    ADD     tmpa, plus16, tmpa, LSL #2  ;// 16+20(G+M)
+    UXTAB16 tmpb, tmpb, tmp1, ROR #8    ;// |c4+r4|c2+r2|
+    UXTAB16 tmpa, tmpa, tmp3, ROR #8    ;// 16+20(G+M)+A
+    UXTAB16 tmpa, tmpa, tmp2, ROR #8    ;// 16+20(G+M)+A+T
+
+
+    ADD     tmpb, tmpb, tmpb, LSL #2    ;// 5(C+R)
+    SSUB16  tmpa, tmpa, tmpb            ;// 16+20(G+M)+(A+T)-5(C+R)
+
+    USAT16  tmpb, #13, tmpa             ;// saturate
+    LDR     tmp3, [ref]
+    LDR     tmpa, = 0xFF00FF00
+
+    ;// decrement loop_x counter
+    SUBS    count, count, #4<<24        ;// (partWidth-1) -= 4;
+
+    AND     tmpa, tmpa, tmpb, LSL #3    ;// mask and divide by 32
+    ORR     res, res, tmpa
+    STR     res, [mb], #16              ;// next row
+
+    ;// tmp4 = |a4|a3|a2|a1|
+    ;// tmp5 = |c4|c3|c2|c1|
+    ;// tmp6 = |g4|g3|g2|g1|
+    ;// tmp1 = |m4|m3|m2|m1|
+    ;// tmp2 = |r4|r3|r2|r1|
+    ;// tmp3 = |t4|t3|t2|t1|
+
+    ;// fourth four pixels
+    UXTB16  tmpa, tmp6                  ;// |g3|g1|
+    UXTAB16 tmpa, tmpa, tmp1            ;// |g3+m3|g1+m1|
+    UXTB16  tmpb, tmp5                  ;// |c3|c1|
+    ADD     tmpa, tmpa, tmpa, LSL #2    ;// 5(G+M)
+    UXTAB16 tmpb, tmpb, tmp2            ;// |c3+r3|c1+r1|
+    ADD     tmpa, plus16, tmpa, LSL #2  ;// 16+20(G+M)
+    UXTAB16 tmpa, tmpa, tmp4            ;// 16+20(G+M)+A
+    UXTAB16 tmpa, tmpa, tmp3            ;// 16+20(G+M)+A+T
+
+    ADD     tmpb, tmpb, tmpb, LSL #2    ;// 5(C+R)
+    SSUB16  tmpa, tmpa, tmpb            ;// 16+20(G+M)+(A+T)-5(C+R)
+
+    USAT16  tmpb, #13, tmpa             ;// saturate
+    LDR     res, = 0x00FF00FF
+    UXTB16  tmpa, tmp6, ROR #8          ;// |g4|g2|
+    UXTAB16 tmpa, tmpa, tmp1, ROR #8    ;// |g4+m4|g2+m2|
+    AND     res, res, tmpb, LSR #5      ;// mask and divide by 32
+
+    ADD     tmpa, tmpa, tmpa, LSL #2    ;// 5(G+M)
+    UXTB16  tmpb, tmp5, ROR #8          ;// |c4|c2|
+    ADD     tmpa, plus16, tmpa, LSL #2  ;// 16+20(G+M)
+    UXTAB16 tmpb, tmpb, tmp2, ROR #8    ;// |c4+r4|c2+r2|
+    UXTAB16 tmpa, tmpa, tmp4, ROR #8    ;// 16+20(G+M)+A
+    UXTAB16 tmpa, tmpa, tmp3, ROR #8    ;// 16+20(G+M)+A+T
+
+    ADD     tmpb, tmpb, tmpb, LSL #2    ;// 5(C+R)
+    SSUB16  tmpa, tmpa, tmpb            ;// 16+20(G+M)+(A+T)-5(C+R)
+
+    USAT16  tmpb, #13, tmpa             ;// saturate
+    LDR     tmp4, = 0xFF00FF00
+
+    ;// calculate "ref" address for next round
+    SUB     ref, ref, width, LSL #3     ;// ref -= 8*width;
+    ADD     ref, ref, #4;               ;// next column (4 pixels)
+    AND     tmpa, tmp4, tmpb, LSL #3    ;// mask and divide by 32
+    ORR     res, res, tmpa
+    STR     res, [mb], #-44
+
+    BCS     loop_x
+
+    ADDS    count, count, #252<<16      ;// (partHeight-1) -= 4;
+    ADD     ref, ref, width, LSL #2     ;// ref += 4*width
+    AND     tmp1, count, #0x000000FF    ;// partWidth-1
+    ADD     tmp2, tmp1, #1              ;// partWidth
+    SUB     ref, ref, tmp2              ;// ref -= partWidth
+    ADD     mb, mb, #64;
+    SUB     mb, mb, tmp2;               ;// mb -= partWidth
+    BGE     loop_y
+
+    ADD     sp,sp,#0x1f4
+    LDMFD   sp!, {r4-r11, pc}
+
+    END
diff --git a/media/libstagefright/codecs/on2/h264dec/source/arm11_asm/h264bsd_interpolate_ver_quarter.s b/media/libstagefright/codecs/on2/h264dec/source/arm11_asm/h264bsd_interpolate_ver_quarter.s
new file mode 100755
index 0000000..5266c85
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/arm11_asm/h264bsd_interpolate_ver_quarter.s
@@ -0,0 +1,374 @@
+; 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.
+
+;-------------------------------------------------------------------------------
+;--
+;-- Abstract : ARMv6 optimized version of h264bsdInterpolateVerQuarter function
+;--
+;-------------------------------------------------------------------------------
+
+    IF :DEF: H264DEC_WINASM
+        ;// We dont use REQUIRE8 and PRESERVE8 for winasm
+    ELSE
+        REQUIRE8
+        PRESERVE8
+    ENDIF
+
+    AREA    |.text|, CODE
+
+;// h264bsdInterpolateVerQuarter register allocation
+
+ref     RN 0
+
+mb      RN 1
+buff    RN 1
+
+count   RN 2
+x0      RN 2
+
+res     RN 3
+y0      RN 3
+
+tmp1    RN 4
+
+tmp2    RN 5
+height  RN 5
+
+tmp3    RN 6
+partW   RN 6
+
+tmp4    RN 7
+partH   RN 7
+
+tmp5    RN 8
+tmp6    RN 9
+
+tmpa    RN 10
+tmpb    RN 11
+width   RN 12
+
+plus16  RN 14
+
+
+;// function exports and imports
+
+    IMPORT  h264bsdFillBlock
+
+    EXPORT  h264bsdInterpolateVerQuarter
+
+;// Approach to vertical interpolation
+;//
+;// Interpolation is done by using 32-bit loads and stores
+;// and by using 16 bit arithmetic. 4x4 block is processed
+;// in each round.
+;//
+;// |a_11|a_11|a_11|a_11|...|a_1n|a_1n|a_1n|a_1n|
+;// |b_11|b_11|b_11|b_11|...|b_1n|b_1n|b_1n|b_1n|
+;// |c_11|c_11|c_11|c_11|...|c_1n|c_1n|c_1n|c_1n|
+;// |d_11|d_11|d_11|d_11|...|d_1n|d_1n|d_1n|d_1n|
+;//           ..
+;//           ..
+;// |a_m1|a_m1|a_m1|a_m1|...
+;// |b_m1|b_m1|b_m1|b_m1|...
+;// |c_m1|c_m1|c_m1|c_m1|...
+;// |d_m1|d_m1|d_m1|d_m1|...
+
+h264bsdInterpolateVerQuarter
+    STMFD   sp!, {r0-r11, lr}
+    SUB     sp, sp, #0x1e4
+
+    CMP     x0, #0
+    BLT     do_fill                 ;// (x0 < 0)
+    LDR     partW, [sp,#0x220]      ;// partWidth
+    ADD     tmp5, x0, partW         ;// (x0+partWidth)
+    LDR     width, [sp,#0x218]      ;// width
+    CMP     tmp5, width
+    BHI     do_fill                 ;// (x0+partW)>width
+
+    CMP     y0, #0
+    BLT     do_fill                 ;// (y0 < 0)
+    LDR     partH, [sp,#0x224]      ;// partHeight
+    ADD     tmp6, y0, partH         ;// (y0+partHeight)
+    ADD     tmp6, tmp6, #5          ;// (y0+partH+5)
+    LDR     height, [sp,#0x21c]     ;// height
+    CMP     tmp6, height
+    BLS     skip_fill               ;// no overfill needed
+
+
+do_fill
+    LDR     partH, [sp,#0x224]      ;// partHeight
+    ADD     tmp5, partH, #5         ;// r2 = partH + 5;
+    LDR     height, [sp,#0x21c]     ;// height
+    LDR     partW, [sp,#0x220]      ;// partWidth
+    STMIB   sp, {height, partW}     ;// sp+4 = height, sp+8 = partWidth
+    STR     tmp5, [sp,#0xc]         ;// sp+c partHeight+5
+    STR     partW, [sp,#0x10]       ;// sp+10 = partWidth
+    LDR     width, [sp,#0x218]      ;// width
+    STR     width, [sp,#0]          ;// sp+0 = width
+    ADD     buff, sp, #0x28         ;// buff = p1[21*21/4+1]
+    BL      h264bsdFillBlock
+
+    MOV     x0, #0
+    STR     x0,[sp,#0x1ec]          ;// x0 = 0
+    STR     x0,[sp,#0x1f0]          ;// y0 = 0
+    ADD     ref,sp,#0x28            ;// ref = p1
+    STR     partW, [sp,#0x218]
+
+
+skip_fill
+    LDR     x0 ,[sp,#0x1ec]         ;// x0
+    LDR     y0 ,[sp,#0x1f0]         ;// y0
+    LDR     width, [sp,#0x218]      ;// width
+    MLA     tmp6, width, y0, x0     ;// y0*width+x0
+    ADD     ref, ref, tmp6          ;// ref += y0*width+x0
+    LDR     mb, [sp, #0x1e8]        ;// mb
+
+    ADD     count, partW, partH, LSL #8    ;// |xx|xx|partH|partW|
+    LDR     tmp5, = 0x00010100
+    RSB     count, tmp5, count, LSL #8      ;// |xx|partH-1|partW-1|xx|
+    LDR     tmp2, [sp, #0x228]      ;// verOffset
+    ADD     count, count, tmp2      ;// |xx|partH-1|partW-1|verOffset|
+    LDR     plus16, = 0x00100010
+
+    AND     tmp1, count, #0x0000FF00 ;// partWidth
+
+
+loop_y
+    ADD     count, count, tmp1, LSL #16  ;// partWidth-1 to top byte
+
+loop_x
+    LDR     tmp1, [ref], width     ;// |a4|a3|a2|a1|
+    LDR     tmp2, [ref], width     ;// |c4|c3|c2|c1|
+    LDR     tmp3, [ref], width     ;// |g4|g3|g2|g1|
+    LDR     tmp4, [ref], width     ;// |m4|m3|m2|m1|
+    LDR     tmp5, [ref], width     ;// |r4|r3|r2|r1|
+    LDR     tmp6, [ref], width     ;// |t4|t3|t2|t1|
+
+    ;// first four pixels 
+    UXTB16  tmpa, tmp3                  ;// |g3|g1|
+    UXTAB16 tmpa, tmpa, tmp4            ;// |g3+m3|g1+m1|
+    UXTB16  tmpb, tmp2                  ;// |c3|c1|
+    ADD     tmpa, tmpa, tmpa, LSL #2    ;// 5(G+M)
+
+    UXTAB16 tmpb, tmpb, tmp5            ;// |c3+r3|c1+r1|
+    ADD     tmpa, plus16, tmpa, LSL #2  ;// 16+20(G+M)
+    UXTAB16 tmpa, tmpa, tmp1            ;// 16+20(G+M)+A
+    UXTAB16 tmpa, tmpa, tmp6            ;// 16+20(G+M)+A+T
+
+    ADD     tmpb, tmpb, tmpb, LSL #2    ;// 5(C+R)
+    SSUB16  tmpa, tmpa, tmpb            ;// 16+20(G+M)+(A+T)-5(C+R)
+
+    USAT16  tmpb, #13, tmpa             ;// saturate
+    LDR     res, = 0x00FF00FF
+    UXTB16  tmpa, tmp3, ROR #8          ;// |g4|g2|
+    UXTAB16 tmpa, tmpa, tmp4, ROR #8    ;// |g4+m4|g2+m2|
+    AND     res, res, tmpb, LSR #5      ;// mask and divide by 32
+
+    ADD     tmpa, tmpa, tmpa, LSL #2    ;// 5(G+M)
+    UXTB16  tmpb, tmp2, ROR #8          ;// |c4|c2|
+    ADD     tmpa, plus16, tmpa, LSL #2  ;// 16+20(G+M)
+    UXTAB16 tmpb, tmpb, tmp5, ROR #8    ;// |c4+r4|c2+r2|
+    UXTAB16 tmpa, tmpa, tmp1, ROR #8    ;// 16+20(G+M)+A
+    UXTAB16 tmpa, tmpa, tmp6, ROR #8    ;// 16+20(G+M)+A+T
+
+    ADD     tmpb, tmpb, tmpb, LSL #2    ;// 5(C+R)
+    SSUB16  tmpa, tmpa, tmpb            ;// 16+20(G+M)+(A+T)-5(C+R)
+
+    USAT16  tmpb, #13, tmpa             ;// saturate
+    MOVS    tmp1, count, LSL #31        ;// update flags (verOffset)
+    LDR     tmpa, = 0xFF00FF00
+    MVNEQ   tmp1, tmp3                  ;// select verOffset=0
+    MVNNE   tmp1, tmp4                  ;// select verOffset=1
+    AND     tmpa, tmpa, tmpb, LSL #3    ;// mask and divede by 32
+    ORR     res, res, tmpa
+
+    LDR     tmpa, = 0x80808080
+    UHSUB8  res, res, tmp1              ;// bilinear interpolation
+    LDR     tmp1, [ref], width          ;// load next row
+    EOR     res, res, tmpa              ;// correct sign
+
+    STR     res, [mb], #16              ;// next row (mb)
+
+
+    ;// tmp2 = |a4|a3|a2|a1|
+    ;// tmp3 = |c4|c3|c2|c1|
+    ;// tmp4 = |g4|g3|g2|g1|
+    ;// tmp5 = |m4|m3|m2|m1|
+    ;// tmp6 = |r4|r3|r2|r1|
+    ;// tmp1 = |t4|t3|t2|t1|
+
+    ;// second four pixels
+    UXTB16  tmpa, tmp4                  ;// |g3|g1|
+    UXTAB16 tmpa, tmpa, tmp5            ;// |g3+m3|g1+m1|
+    UXTB16  tmpb, tmp3                  ;// |c3|c1|
+    ADD     tmpa, tmpa, tmpa, LSL #2    ;// 5(G+M)
+    UXTAB16 tmpb, tmpb, tmp6            ;// |c3+r3|c1+r1|
+    ADD     tmpa, plus16, tmpa, LSL #2  ;// 16+20(G+M)
+    UXTAB16 tmpa, tmpa, tmp2            ;// 16+20(G+M)+A
+    UXTAB16 tmpa, tmpa, tmp1            ;// 16+20(G+M)+A+T
+
+    ADD     tmpb, tmpb, tmpb, LSL #2    ;// 5(C+R)
+    SSUB16  tmpa, tmpa, tmpb            ;// 16+20(G+M)+(A+T)-5(C+R)
+
+    USAT16  tmpb, #13, tmpa             ;// saturate
+    LDR     res, = 0x00FF00FF
+    UXTB16  tmpa, tmp4, ROR #8          ;// |g4|g2|
+    UXTAB16 tmpa, tmpa, tmp5, ROR #8    ;// |g4+m4|g2+m2|
+    AND     res, res, tmpb, LSR #5      ;// mask and divide by 32
+
+    ADD     tmpa, tmpa, tmpa, LSL #2    ;// 5(G+M)
+    UXTB16  tmpb, tmp3, ROR #8          ;// |c4|c2|
+    ADD     tmpa, plus16, tmpa, LSL #2  ;// 16+20(G+M)
+    UXTAB16 tmpb, tmpb, tmp6, ROR #8    ;// |c4+r4|c2+r2|
+    UXTAB16 tmpa, tmpa, tmp2, ROR #8    ;// 16+20(G+M)+A
+    UXTAB16 tmpa, tmpa, tmp1, ROR #8    ;// 16+20(G+M)+A+T
+
+    ADD     tmpb, tmpb, tmpb, LSL #2    ;// 5(C+R)
+    SSUB16  tmpa, tmpa, tmpb            ;// 16+20(G+M)+(A+T)-5(C+R)
+
+    USAT16  tmpb, #13, tmpa             ;// saturate
+    LDR     tmpa, = 0xFF00FF00
+    MVNEQ   tmp2, tmp4                  ;// select verOffset=0
+    MVNNE   tmp2, tmp5                  ;// select verOffset=1
+
+    AND     tmpa, tmpa, tmpb, LSL #3    ;// mask and divide by 32
+    ORR     res, res, tmpa
+    LDR     tmpa, = 0x80808080
+    UHSUB8  res, res, tmp2              ;// bilinear interpolation
+    LDR     tmp2, [ref], width          ;// load next row
+    EOR     res, res, tmpa              ;// correct sign
+    STR     res, [mb], #16              ;// next row
+
+    ;// tmp3 = |a4|a3|a2|a1|
+    ;// tmp4 = |c4|c3|c2|c1|
+    ;// tmp5 = |g4|g3|g2|g1|
+    ;// tmp6 = |m4|m3|m2|m1|
+    ;// tmp1 = |r4|r3|r2|r1|
+    ;// tmp2 = |t4|t3|t2|t1|
+
+    ;// third four pixels
+    UXTB16  tmpa, tmp5                  ;// |g3|g1|
+    UXTAB16 tmpa, tmpa, tmp6            ;// |g3+m3|g1+m1|
+    UXTB16  tmpb, tmp4                  ;// |c3|c1|
+    ADD     tmpa, tmpa, tmpa, LSL #2    ;// 5(G+M)
+    UXTAB16 tmpb, tmpb, tmp1            ;// |c3+r3|c1+r1|
+    ADD     tmpa, plus16, tmpa, LSL #2  ;// 16+20(G+M)
+    UXTAB16 tmpa, tmpa, tmp3            ;// 16+20(G+M)+A
+    UXTAB16 tmpa, tmpa, tmp2            ;// 16+20(G+M)+A+T
+
+    ADD     tmpb, tmpb, tmpb, LSL #2    ;// 5(C+R)
+    SSUB16  tmpa, tmpa, tmpb            ;// 16+20(G+M)+(A+T)-5(C+R)
+
+    USAT16  tmpb, #13, tmpa             ;// saturate
+    LDR     res, = 0x00FF00FF
+    UXTB16  tmpa, tmp5, ROR #8          ;// |g4|g2|
+    UXTAB16 tmpa, tmpa, tmp6, ROR #8    ;// |g4+m4|g2+m2|
+    AND     res, res, tmpb, LSR #5      ;// mask and divide by 32
+
+    ADD     tmpa, tmpa, tmpa, LSL #2    ;// 5(G+M)
+    UXTB16  tmpb, tmp4, ROR #8          ;// |c4|c2|
+    ADD     tmpa, plus16, tmpa, LSL #2  ;// 16+20(G+M)
+    UXTAB16 tmpb, tmpb, tmp1, ROR #8    ;// |c4+r4|c2+r2|
+    UXTAB16 tmpa, tmpa, tmp3, ROR #8    ;// 16+20(G+M)+A
+    UXTAB16 tmpa, tmpa, tmp2, ROR #8    ;// 16+20(G+M)+A+T
+
+
+    ADD     tmpb, tmpb, tmpb, LSL #2    ;// 5(C+R)
+    SSUB16  tmpa, tmpa, tmpb            ;// 16+20(G+M)+(A+T)-5(C+R)
+
+    USAT16  tmpb, #13, tmpa             ;// saturate
+    LDR     tmpa, = 0xFF00FF00
+    MVNEQ   tmp3, tmp5                  ;// select verOffset=0
+    MVNNE   tmp3, tmp6                  ;// select verOffset=1
+
+    AND     tmpa, tmpa, tmpb, LSL #3    ;// mask and divide by 32
+    ORR     res, res, tmpa
+    LDR     tmpa, = 0x80808080
+    UHSUB8  res, res, tmp3              ;// bilinear interpolation
+    LDR     tmp3, [ref]                 ;// load next row
+    EOR     res, res, tmpa              ;// correct sign
+    STR     res, [mb], #16              ;// next row
+
+    ;// tmp4 = |a4|a3|a2|a1|
+    ;// tmp5 = |c4|c3|c2|c1|
+    ;// tmp6 = |g4|g3|g2|g1|
+    ;// tmp1 = |m4|m3|m2|m1|
+    ;// tmp2 = |r4|r3|r2|r1|
+    ;// tmp3 = |t4|t3|t2|t1|
+
+    ;// fourth four pixels
+    UXTB16  tmpa, tmp6                  ;// |g3|g1|
+    UXTAB16 tmpa, tmpa, tmp1            ;// |g3+m3|g1+m1|
+    UXTB16  tmpb, tmp5                  ;// |c3|c1|
+    ADD     tmpa, tmpa, tmpa, LSL #2    ;// 5(G+M)
+    UXTAB16 tmpb, tmpb, tmp2            ;// |c3+r3|c1+r1|
+    ADD     tmpa, plus16, tmpa, LSL #2  ;// 16+20(G+M)
+    UXTAB16 tmpa, tmpa, tmp4            ;// 16+20(G+M)+A
+    UXTAB16 tmpa, tmpa, tmp3            ;// 16+20(G+M)+A+T
+
+    ADD     tmpb, tmpb, tmpb, LSL #2    ;// 5(C+R)
+    SSUB16  tmpa, tmpa, tmpb            ;// 16+20(G+M)+(A+T)-5(C+R)
+
+    USAT16  tmpb, #13, tmpa             ;// saturate
+    LDR     res, = 0x00FF00FF
+    UXTB16  tmpa, tmp6, ROR #8          ;// |g4|g2|
+    UXTAB16 tmpa, tmpa, tmp1, ROR #8    ;// |g4+m4|g2+m2|
+    AND     res, res, tmpb, LSR #5      ;// mask and divide by 32
+
+    ADD     tmpa, tmpa, tmpa, LSL #2    ;// 5(G+M)
+    UXTB16  tmpb, tmp5, ROR #8          ;// |c4|c2|
+    ADD     tmpa, plus16, tmpa, LSL #2  ;// 16+20(G+M)
+    UXTAB16 tmpb, tmpb, tmp2, ROR #8    ;// |c4+r4|c2+r2|
+    UXTAB16 tmpa, tmpa, tmp4, ROR #8    ;// 16+20(G+M)+A
+    UXTAB16 tmpa, tmpa, tmp3, ROR #8    ;// 16+20(G+M)+A+T
+
+    ADD     tmpb, tmpb, tmpb, LSL #2    ;// 5(C+R)
+    SSUB16  tmpa, tmpa, tmpb            ;// 16+20(G+M)+(A+T)-5(C+R)
+
+    USAT16  tmpb, #13, tmpa             ;// saturate
+    LDR     tmp4, = 0xFF00FF00
+    MVNEQ   tmp5, tmp6                  ;// select verOffset=0
+    MVNNE   tmp5, tmp1                  ;// select verOffset=1
+
+    AND     tmpa, tmp4, tmpb, LSL #3    ;// mask and divide by 32
+    ORR     res, res, tmpa
+    LDR     tmpa, = 0x80808080
+    UHSUB8  res, res, tmp5              ;// bilinear interpolation
+
+    ;// decrement loop_x counter
+    SUBS    count, count, #4<<24        ;// (partWidth-1) -= 4;
+
+    ;// calculate "ref" address for next round
+    SUB     ref, ref, width, LSL #3     ;// ref -= 8*width;
+    ADD     ref, ref, #4;               ;// next column (4 pixels)
+
+    EOR     res, res, tmpa              ;// correct sign
+    STR     res, [mb], #-44
+ 
+    BCS     loop_x
+
+    ADDS    count, count, #252<<16      ;// (partHeight-1) -= 4;
+    ADD     ref, ref, width, LSL #2     ;// ref += 4*width
+    AND     tmp1, count, #0x0000FF00    ;// partWidth-1
+    MOV     tmp2, #1
+    ADD     tmp2, tmp2, tmp1, LSR #8    ;// partWidth
+    SUB     ref, ref, tmp2              ;// ref -= partWidth
+    ADD     mb, mb, #64;
+    SUB     mb, mb, tmp2;               ;// mb -= partWidth
+    BGE     loop_y
+
+    ADD     sp,sp,#0x1f4
+    LDMFD   sp!, {r4-r11, pc}
+
+    END
diff --git a/media/libstagefright/codecs/on2/h264dec/source/arm11_asm/win_asm.bat b/media/libstagefright/codecs/on2/h264dec/source/arm11_asm/win_asm.bat
new file mode 100644
index 0000000..1b8d88c
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/arm11_asm/win_asm.bat
@@ -0,0 +1,15 @@
+echo off
+set ASMFLAGS= -checkreglist -CPU ARM1136 -PreDefine "H264DEC_WINASM SETL {TRUE}"
+set ASM="D:\Program Files\Microsoft Visual Studio 8\VC\ce\bin\x86_arm\armasm"
+echo on
+
+%ASM% %ASMFLAGS% h264bsd_interpolate_chroma_ver.s
+%ASM% %ASMFLAGS% h264bsd_interpolate_chroma_hor.s
+%ASM% %ASMFLAGS% h264bsd_interpolate_hor_half.s
+%ASM% %ASMFLAGS% h264bsd_interpolate_hor_quarter.s
+%ASM% %ASMFLAGS% h264bsd_interpolate_hor_ver_quarter.s
+%ASM% %ASMFLAGS% h264bsd_interpolate_ver_half.s
+%ASM% %ASMFLAGS% h264bsd_interpolate_ver_quarter.s
+
+rem %ASM% %ASMFLAGS% h264bsd_interpolate_chroma_hor_ver.s
+rem %ASM% %ASMFLAGS% h264bsd_interpolate_mid_hor.s
diff --git a/media/libstagefright/codecs/on2/h264dec/source/arm_neon_asm/h264bsdClearMbLayer.s b/media/libstagefright/codecs/on2/h264dec/source/arm_neon_asm/h264bsdClearMbLayer.s
new file mode 100644
index 0000000..db11654
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/arm_neon_asm/h264bsdClearMbLayer.s
@@ -0,0 +1,66 @@
+;
+; 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.
+;
+
+    REQUIRE8
+    PRESERVE8
+
+    AREA    |.text|, CODE
+
+    EXPORT h264bsdClearMbLayer
+
+; Input / output registers
+pMbLayer    RN  0
+size        RN  1
+pTmp        RN  2
+step        RN  3
+
+; -- NEON registers --
+
+qZero   QN  Q0.U8
+
+;/*------------------------------------------------------------------------------
+;
+;    Function: h264bsdClearMbLayer
+;
+;        Functional description:
+;
+;        Inputs:
+;
+;        Outputs:
+;
+;        Returns:
+;
+;------------------------------------------------------------------------------*/
+
+h264bsdClearMbLayer
+
+    VMOV    qZero, #0
+    ADD     pTmp, pMbLayer, #16
+    MOV     step, #32
+    SUBS    size, size, #64
+
+loop
+    VST1    qZero, [pMbLayer], step
+    SUBS    size, size, #64
+    VST1    qZero, [pTmp], step
+    VST1    qZero, [pMbLayer], step
+    VST1    qZero, [pTmp], step
+    BCS     loop
+
+    BX      lr
+    END
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/arm_neon_asm/h264bsdCountLeadingZeros.s b/media/libstagefright/codecs/on2/h264dec/source/arm_neon_asm/h264bsdCountLeadingZeros.s
new file mode 100644
index 0000000..c7bd73e
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/arm_neon_asm/h264bsdCountLeadingZeros.s
@@ -0,0 +1,49 @@
+;
+; 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.
+;
+
+    REQUIRE8
+    PRESERVE8
+
+    AREA    |.text|, CODE
+
+    EXPORT h264bsdCountLeadingZeros
+
+; Input / output registers
+value    RN  0
+
+; -- NEON registers --
+
+;/*------------------------------------------------------------------------------
+;
+;    Function: h264bsdCountLeadingZeros
+;
+;        Functional description:
+;
+;        Inputs:
+;
+;        Outputs:
+;
+;        Returns:
+;
+;------------------------------------------------------------------------------*/
+
+h264bsdCountLeadingZeros
+
+    CLZ     value, value
+    BX      lr
+    END
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/arm_neon_asm/h264bsdFillRow7.s b/media/libstagefright/codecs/on2/h264dec/source/arm_neon_asm/h264bsdFillRow7.s
new file mode 100644
index 0000000..5bfac92
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/arm_neon_asm/h264bsdFillRow7.s
@@ -0,0 +1,180 @@
+;
+; 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.
+;
+
+    REQUIRE8
+    PRESERVE8
+
+    AREA    |.text|, CODE
+
+    EXPORT h264bsdFillRow7
+
+; Input / output registers
+
+ref     RN 0
+fill    RN 1
+left    RN 2
+tmp2    RN 2
+center  RN 3
+right   RN 4
+tmp1    RN 5
+
+; -- NEON registers --
+
+qTmp0   QN  Q0.U8
+qTmp1   QN  Q1.U8
+dTmp0   DN  D0.U8
+dTmp1   DN  D1.U8
+dTmp2   DN  D2.U8
+dTmp3   DN  D3.U8
+
+
+;/*------------------------------------------------------------------------------
+;
+;    Function: h264bsdFillRow7
+;
+;        Functional description:
+;
+;        Inputs:
+;
+;        Outputs:
+;
+;        Returns:
+;
+;------------------------------------------------------------------------------*/
+
+h264bsdFillRow7
+        PUSH     {r4-r6,lr}
+        CMP      left, #0
+        LDR      right, [sp,#0x10]
+        BEQ      switch_center
+        LDRB     tmp1, [ref,#0]
+
+loop_left
+        SUBS     left, left, #1
+        STRB     tmp1, [fill], #1
+        BNE      loop_left
+
+switch_center
+        ASR      tmp2,center,#2
+        CMP      tmp2,#9
+        ADDCC    pc,pc,tmp2,LSL #2
+        B        loop_center
+        B        loop_center
+        B        case_1
+        B        case_2
+        B        case_3
+        B        case_4
+        B        case_5
+        B        case_6
+        B        case_7
+        B        case_8
+;case_8
+;        LDR      tmp2, [ref], #4
+;        SUB      center, center, #4
+;        STR      tmp2, [fill], #4
+;case_7
+;        LDR      tmp2, [ref], #4
+;        SUB      center, center, #4
+;        STR      tmp2, [fill], #4
+;case_6
+;        LDR      tmp2, [ref], #4
+;        SUB      center, center, #4
+;        STR      tmp2, [fill],#4
+;case_5
+;        LDR      tmp2, [ref], #4
+;        SUB      center, center, #4
+;        STR      tmp2, [fill],#4
+;case_4
+;        LDR      tmp2, [ref],#4
+;        SUB      center, center, #4
+;        STR      tmp2, [fill], #4
+;case_3
+;        LDR      tmp2, [ref],#4
+;        SUB      center, center, #4
+;        STR      tmp2, [fill], #4
+;case_2
+;        LDR      tmp2, [ref],#4
+;        SUB      center, center, #4
+;        STR      tmp2, [fill], #4
+;case_1
+;        LDR      tmp2, [ref],#4
+;        SUB      center, center, #4
+;        STR      tmp2, [fill], #4
+
+case_8
+        VLD1    {qTmp0, qTmp1}, [ref]!
+        SUB     center, center, #32
+        VST1    qTmp0, [fill]!
+        VST1    qTmp1, [fill]!
+        B       loop_center
+case_7
+        VLD1    {dTmp0,dTmp1,dTmp2}, [ref]!
+        SUB     center, center, #28
+        LDR     tmp2, [ref], #4
+        VST1    {dTmp0,dTmp1,dTmp2}, [fill]!
+        STR     tmp2, [fill],#4
+        B       loop_center
+case_6
+        VLD1    {dTmp0,dTmp1,dTmp2}, [ref]!
+        SUB     center, center, #24
+        VST1    {dTmp0,dTmp1,dTmp2}, [fill]!
+        B       loop_center
+case_5
+        VLD1    qTmp0, [ref]!
+        SUB     center, center, #20
+        LDR     tmp2, [ref], #4
+        VST1    qTmp0, [fill]!
+        STR     tmp2, [fill],#4
+        B       loop_center
+case_4
+        VLD1    qTmp0, [ref]!
+        SUB     center, center, #16
+        VST1    qTmp0, [fill]!
+        B       loop_center
+case_3
+        VLD1    dTmp0, [ref]!
+        SUB     center, center, #12
+        LDR     tmp2, [ref], #4
+        VST1    dTmp0, [fill]!
+        STR     tmp2, [fill],#4
+        B       loop_center
+case_2
+        LDR      tmp2, [ref],#4
+        SUB      center, center, #4
+        STR      tmp2, [fill], #4
+case_1
+        LDR      tmp2, [ref],#4
+        SUB      center, center, #4
+        STR      tmp2, [fill], #4
+
+loop_center
+        CMP      center, #0
+        LDRBNE   tmp2, [ref], #1
+        SUBNE    center, center, #1
+        STRBNE   tmp2, [fill], #1
+        BNE      loop_center
+        CMP      right,#0
+        POPEQ    {r4-r6,pc}
+        LDRB     tmp2, [ref,#-1]
+
+loop_right
+        STRB     tmp2, [fill], #1
+        SUBS     right, right, #1
+        BNE      loop_right
+
+        POP      {r4-r6,pc}
+        END
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/arm_neon_asm/h264bsdFlushBits.s b/media/libstagefright/codecs/on2/h264dec/source/arm_neon_asm/h264bsdFlushBits.s
new file mode 100644
index 0000000..21335b8
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/arm_neon_asm/h264bsdFlushBits.s
@@ -0,0 +1,82 @@
+;
+; 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.
+;
+
+    REQUIRE8
+    PRESERVE8
+
+    AREA    |.text|, CODE
+
+    EXPORT h264bsdFlushBits
+
+; Input / output registers
+pStrmData       RN  0
+numBits         RN  1
+readBits        RN  2
+strmBuffSize    RN  3
+pStrmBuffStart  RN  1
+pStrmCurrPos    RN  2
+bitPosInWord    RN  1
+
+; -- NEON registers --
+
+
+
+;/*------------------------------------------------------------------------------
+;
+;    Function: h264bsdFlushBits
+;
+;        Functional description:
+;
+;        Inputs:
+;
+;        Outputs:
+;
+;        Returns:
+;
+;------------------------------------------------------------------------------*/
+
+h264bsdFlushBits
+;//    PUSH     {r4-r6,lr}
+
+    LDR readBits, [pStrmData, #0x10]
+    LDR strmBuffSize, [pStrmData, #0xC]
+
+    ADD readBits, readBits, numBits
+    AND bitPosInWord, readBits, #7
+
+    STR readBits, [pStrmData, #0x10]
+    STR bitPosInWord, [pStrmData, #0x8]
+
+    LDR pStrmBuffStart, [pStrmData, #0x0]
+
+    CMP readBits, strmBuffSize, LSL #3
+
+    BHI end_of_stream
+
+    ADD pStrmCurrPos, pStrmBuffStart, readBits, LSR #3
+    STR pStrmCurrPos, [pStrmData, #0x4]
+    MOV r0, #0
+    BX  lr
+;//    POP      {r4-r6,pc}
+
+end_of_stream
+    MVN r0, #0
+    BX  lr
+;//    POP      {r4-r6,pc}
+
+    END
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/arm_neon_asm/h264bsdWriteMacroblock.s b/media/libstagefright/codecs/on2/h264dec/source/arm_neon_asm/h264bsdWriteMacroblock.s
new file mode 100644
index 0000000..38a0781
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/arm_neon_asm/h264bsdWriteMacroblock.s
@@ -0,0 +1,152 @@
+;
+; 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.
+;
+
+    REQUIRE8
+    PRESERVE8
+
+    AREA    |.text|, CODE
+
+    EXPORT h264bsdWriteMacroblock
+
+; Input / output registers
+image   RN  0
+data    RN  1
+width   RN  2
+luma    RN  3
+cb      RN  4
+cr      RN  5
+cwidth  RN  6
+
+; -- NEON registers --
+
+qRow0   QN  Q0.U8
+qRow1   QN  Q1.U8
+qRow2   QN  Q2.U8
+qRow3   QN  Q3.U8
+qRow4   QN  Q4.U8
+qRow5   QN  Q5.U8
+qRow6   QN  Q6.U8
+qRow7   QN  Q7.U8
+qRow8   QN  Q8.U8
+qRow9   QN  Q9.U8
+qRow10  QN  Q10.U8
+qRow11  QN  Q11.U8
+qRow12  QN  Q12.U8
+qRow13  QN  Q13.U8
+qRow14  QN  Q14.U8
+qRow15  QN  Q15.U8
+
+dRow0   DN  D0.U8
+dRow1   DN  D1.U8
+dRow2   DN  D2.U8
+dRow3   DN  D3.U8
+dRow4   DN  D4.U8
+dRow5   DN  D5.U8
+dRow6   DN  D6.U8
+dRow7   DN  D7.U8
+dRow8   DN  D8.U8
+dRow9   DN  D9.U8
+dRow10  DN  D10.U8
+dRow11  DN  D11.U8
+dRow12  DN  D12.U8
+dRow13  DN  D13.U8
+dRow14  DN  D14.U8
+dRow15  DN  D15.U8
+
+;/*------------------------------------------------------------------------------
+;
+;    Function: h264bsdWriteMacroblock
+;
+;        Functional description:
+;            Write one macroblock into the image. Both luma and chroma
+;            components will be written at the same time.
+;
+;        Inputs:
+;            data    pointer to macroblock data to be written, 256 values for
+;                    luma followed by 64 values for both chroma components
+;
+;        Outputs:
+;            image   pointer to the image where the macroblock will be written
+;
+;        Returns:
+;            none
+;
+;------------------------------------------------------------------------------*/
+
+h264bsdWriteMacroblock
+    PUSH    {r4-r6,lr}
+    VPUSH   {q4-q7}
+
+    LDR     width, [image, #4]
+    LDR     luma, [image, #0xC]
+    LDR     cb, [image, #0x10]
+    LDR     cr, [image, #0x14]
+
+
+;   Write luma
+    VLD1    {qRow0, qRow1}, [data]!
+    LSL     width, width, #4
+    VLD1    {qRow2, qRow3}, [data]!
+    LSR     cwidth, width, #1
+    VST1    {qRow0}, [luma@128], width
+    VLD1    {qRow4, qRow5}, [data]!
+    VST1    {qRow1}, [luma@128], width
+    VLD1    {qRow6, qRow7}, [data]!
+    VST1    {qRow2}, [luma@128], width
+    VLD1    {qRow8, qRow9}, [data]!
+    VST1    {qRow3}, [luma@128], width
+    VLD1    {qRow10, qRow11}, [data]!
+    VST1    {qRow4}, [luma@128], width
+    VLD1    {qRow12, qRow13}, [data]!
+    VST1    {qRow5}, [luma@128], width
+    VLD1    {qRow14, qRow15}, [data]!
+    VST1    {qRow6}, [luma@128], width
+
+    VLD1    {qRow0, qRow1}, [data]! ;cb rows 0,1,2,3
+    VST1    {qRow7}, [luma@128], width
+    VLD1    {qRow2, qRow3}, [data]! ;cb rows 4,5,6,7
+    VST1    {qRow8}, [luma@128], width
+    VLD1    {qRow4, qRow5}, [data]! ;cr rows 0,1,2,3
+    VST1    {qRow9}, [luma@128], width
+    VLD1    {qRow6, qRow7}, [data]! ;cr rows 4,5,6,7
+    VST1    {qRow10}, [luma@128], width
+    VST1    {dRow0}, [cb@64], cwidth
+    VST1    {dRow8}, [cr@64], cwidth
+    VST1    {qRow11}, [luma@128], width
+    VST1    {dRow1}, [cb@64], cwidth
+    VST1    {dRow9}, [cr@64], cwidth
+    VST1    {qRow12}, [luma@128], width
+    VST1    {dRow2}, [cb@64], cwidth
+    VST1    {dRow10}, [cr@64], cwidth
+    VST1    {qRow13}, [luma@128], width
+    VST1    {dRow3}, [cb@64], cwidth
+    VST1    {dRow11}, [cr@64], cwidth
+    VST1    {qRow14}, [luma@128], width
+    VST1    {dRow4}, [cb@64], cwidth
+    VST1    {dRow12}, [cr@64], cwidth
+    VST1    {qRow15}, [luma]
+    VST1    {dRow5}, [cb@64], cwidth
+    VST1    {dRow13}, [cr@64], cwidth
+    VST1    {dRow6}, [cb@64], cwidth
+    VST1    {dRow14}, [cr@64], cwidth
+    VST1    {dRow7}, [cb@64]
+    VST1    {dRow15}, [cr@64]
+
+    VPOP    {q4-q7}
+    POP     {r4-r6,pc}
+    END
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/arm_neon_asm_gcc/asm_common.S b/media/libstagefright/codecs/on2/h264dec/source/arm_neon_asm_gcc/asm_common.S
new file mode 100644
index 0000000..f39f5c4
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/arm_neon_asm_gcc/asm_common.S
@@ -0,0 +1,41 @@
+@
+@ 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.
+@
+
+
+
+
+    .macro REQUIRE8
+    .eabi_attribute 24, 1
+    .endm
+
+    .macro PRESERVE8
+    .eabi_attribute 25, 1
+    .endm
+
+
+    .macro function name, export=0
+.if \export
+    .global \name
+.endif
+    .type   \name, %function
+    .func   \name
+\name:
+    .endm
+
+    .macro endfunction
+    .endfunc
+    .endm
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/arm_neon_asm_gcc/h264bsdClearMbLayer.S b/media/libstagefright/codecs/on2/h264dec/source/arm_neon_asm_gcc/h264bsdClearMbLayer.S
new file mode 100644
index 0000000..c8a940e
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/arm_neon_asm_gcc/h264bsdClearMbLayer.S
@@ -0,0 +1,68 @@
+@
+@ 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.
+@
+
+#include "asm_common.S"
+
+    preserve8
+
+    .fpu neon
+    .text
+
+/* Input / output registers */
+#define pMbLayer    r0
+#define size        r1
+#define pTmp        r2
+#define step        r3
+
+/* -- NEON registers -- */
+
+#define qZero   Q0.U8
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdClearMbLayer
+
+        Functional description:
+
+        Inputs:
+
+        Outputs:
+
+        Returns:
+
+------------------------------------------------------------------------------*/
+
+function h264bsdClearMbLayer, export=1
+
+    VMOV    qZero, #0
+    ADD     pTmp, pMbLayer, #16
+    MOV     step, #32
+    SUBS    size, size, #64
+
+loop:
+    VST1    {qZero}, [pMbLayer], step
+    SUBS    size, size, #64
+    VST1    {qZero}, [pTmp], step
+    VST1    {qZero}, [pMbLayer], step
+    VST1    {qZero}, [pTmp], step
+    BCS     loop
+
+    BX      lr
+
+endfunction
+
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/arm_neon_asm_gcc/h264bsdCountLeadingZeros.S b/media/libstagefright/codecs/on2/h264dec/source/arm_neon_asm_gcc/h264bsdCountLeadingZeros.S
new file mode 100644
index 0000000..05253d0
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/arm_neon_asm_gcc/h264bsdCountLeadingZeros.S
@@ -0,0 +1,48 @@
+@
+@ 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.
+@
+#include "asm_common.S"
+
+    preserve8
+    .arm
+    .text
+
+
+/* Input / output registers */
+#define value    r0
+
+/* -- NEON registers -- */
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdCountLeadingZeros
+
+        Functional description:
+
+        Inputs:
+
+        Outputs:
+
+        Returns:
+
+------------------------------------------------------------------------------*/
+
+function h264bsdCountLeadingZeros, export=1
+
+    CLZ     value, value
+    BX      lr
+
+endfunction
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/arm_neon_asm_gcc/h264bsdFillRow7.S b/media/libstagefright/codecs/on2/h264dec/source/arm_neon_asm_gcc/h264bsdFillRow7.S
new file mode 100644
index 0000000..6955b9a
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/arm_neon_asm_gcc/h264bsdFillRow7.S
@@ -0,0 +1,143 @@
+@
+@ 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.
+@
+
+#include "asm_common.S"
+
+    preserve8
+
+    .fpu neon
+    .text
+
+/* Input / output registers */
+
+#define ref     r0
+#define fill    r1
+#define left    r2
+#define tmp2    r2
+#define center  r3
+#define right   r4
+#define tmp1    r5
+
+/* -- NEON registers -- */
+
+#define qTmp0     Q0.U8
+#define qTmp1     Q1.U8
+#define dTmp0     D0.U8
+#define dTmp1     D1.U8
+#define dTmp2     D2.U8
+#define dTmp3     D3.U8
+
+/*
+void h264bsdFillRow7(const u8 * ref, u8 * fill, i32 left, i32 center,
+                     i32 right);
+*/
+
+function h264bsdFillRow7, export=1
+
+        PUSH     {r4-r6,lr}
+        CMP      left, #0
+        LDR      right, [sp,#0x10]
+        BEQ      switch_center
+        LDRB     tmp1, [ref,#0]
+
+loop_left:
+        SUBS     left, left, #1
+        STRB     tmp1, [fill], #1
+        BNE      loop_left
+
+switch_center:
+        ASR      tmp2,center,#2
+        CMP      tmp2,#9
+        ADDCC    pc,pc,tmp2,LSL #2
+        B        loop_center
+        B        loop_center
+        B        case_1
+        B        case_2
+        B        case_3
+        B        case_4
+        B        case_5
+        B        case_6
+        B        case_7
+        B        case_8
+
+case_8:
+        VLD1    {qTmp0, qTmp1}, [ref]!
+        SUB     center, center, #32
+        VST1    {qTmp0}, [fill]!
+        VST1    {qTmp1}, [fill]!
+        B       loop_center
+case_7:
+        VLD1    {dTmp0,dTmp1,dTmp2}, [ref]!
+        SUB     center, center, #28
+        LDR     tmp2, [ref], #4
+        VST1    {dTmp0,dTmp1,dTmp2}, [fill]!
+        STR     tmp2, [fill],#4
+        B       loop_center
+case_6:
+        VLD1    {dTmp0,dTmp1,dTmp2}, [ref]!
+        SUB     center, center, #24
+        VST1    {dTmp0,dTmp1,dTmp2}, [fill]!
+        B       loop_center
+case_5:
+        VLD1    {qTmp0}, [ref]!
+        SUB     center, center, #20
+        LDR     tmp2, [ref], #4
+        VST1    {qTmp0}, [fill]!
+        STR     tmp2, [fill],#4
+        B       loop_center
+case_4:
+        VLD1    {qTmp0}, [ref]!
+        SUB     center, center, #16
+        VST1    {qTmp0}, [fill]!
+        B       loop_center
+case_3:
+        VLD1    {dTmp0}, [ref]!
+        SUB     center, center, #12
+        LDR     tmp2, [ref], #4
+        VST1    dTmp0, [fill]!
+        STR     tmp2, [fill],#4
+        B       loop_center
+case_2:
+        LDR      tmp2, [ref],#4
+        SUB      center, center, #4
+        STR      tmp2, [fill], #4
+case_1:
+        LDR      tmp2, [ref],#4
+        SUB      center, center, #4
+        STR      tmp2, [fill], #4
+
+loop_center:
+        CMP      center, #0
+        BEQ      jump
+        LDRB     tmp2, [ref], #1
+        SUB      center, center, #1
+        STRB     tmp2, [fill], #1
+        BNE      loop_center
+jump:
+        CMP      right,#0
+        POPEQ    {r4-r6,pc}
+        LDRB     tmp2, [ref,#-1]
+
+loop_right:
+        STRB     tmp2, [fill], #1
+        SUBS     right, right, #1
+        BNE      loop_right
+
+        POP      {r4-r6,pc}
+
+endfunction
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/arm_neon_asm_gcc/h264bsdFlushBits.S b/media/libstagefright/codecs/on2/h264dec/source/arm_neon_asm_gcc/h264bsdFlushBits.S
new file mode 100644
index 0000000..b3f3191
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/arm_neon_asm_gcc/h264bsdFlushBits.S
@@ -0,0 +1,78 @@
+@
+@ 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.
+@
+
+#include "asm_common.S"
+
+    preserve8
+
+    .arm
+    .text
+
+/* Input / output registers */
+#define pStrmData       r0
+#define numBits         r1
+#define readBits        r2
+#define strmBuffSize    r3
+#define pStrmBuffStart  r1
+#define pStrmCurrPos    r2
+#define bitPosInWord    r1
+
+/* Input / output registers */
+
+
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdFlushBits
+
+        Functional description:
+
+        Inputs:
+
+        Outputs:
+
+        Returns:
+
+------------------------------------------------------------------------------*/
+function h264bsdFlushBits, export=1
+
+    LDR readBits, [pStrmData, #0x10]
+    LDR strmBuffSize, [pStrmData, #0xC]
+
+    ADD readBits, readBits, numBits
+    AND bitPosInWord, readBits, #7
+
+    STR readBits, [pStrmData, #0x10]
+    STR bitPosInWord, [pStrmData, #0x8]
+
+    LDR pStrmBuffStart, [pStrmData, #0x0]
+
+    CMP readBits, strmBuffSize, LSL #3
+
+    BHI end_of_stream
+
+    ADD pStrmCurrPos, pStrmBuffStart, readBits, LSR #3
+    STR pStrmCurrPos, [pStrmData, #0x4]
+    MOV r0, #0
+    BX  lr
+
+end_of_stream:
+    MVN r0, #0
+    BX  lr
+
+endfunction
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/arm_neon_asm_gcc/h264bsdWriteMacroblock.S b/media/libstagefright/codecs/on2/h264dec/source/arm_neon_asm_gcc/h264bsdWriteMacroblock.S
new file mode 100644
index 0000000..495d560
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/arm_neon_asm_gcc/h264bsdWriteMacroblock.S
@@ -0,0 +1,157 @@
+@
+@ 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.
+@
+
+#include "asm_common.S"
+
+    require8
+    preserve8
+
+    .arm
+    .fpu neon
+    .text
+
+/* Input / output registers */
+#define image   r0
+#define data    r1
+#define width   r2
+#define luma    r3
+#define cb      r4
+#define cr      r5
+#define cwidth  r6
+
+/* -- NEON registers -- */
+
+#define qRow0     Q0.U8
+#define qRow1     Q1.U8
+#define qRow2     Q2.U8
+#define qRow3     Q3.U8
+#define qRow4     Q4.U8
+#define qRow5     Q5.U8
+#define qRow6     Q6.U8
+#define qRow7     Q7.U8
+#define qRow8     Q8.U8
+#define qRow9     Q9.U8
+#define qRow10    Q10.U8
+#define qRow11    Q11.U8
+#define qRow12    Q12.U8
+#define qRow13    Q13.U8
+#define qRow14    Q14.U8
+#define qRow15    Q15.U8
+
+#define dRow0     D0.U8
+#define dRow1     D1.U8
+#define dRow2     D2.U8
+#define dRow3     D3.U8
+#define dRow4     D4.U8
+#define dRow5     D5.U8
+#define dRow6     D6.U8
+#define dRow7     D7.U8
+#define dRow8     D8.U8
+#define dRow9     D9.U8
+#define dRow10    D10.U8
+#define dRow11    D11.U8
+#define dRow12    D12.U8
+#define dRow13    D13.U8
+#define dRow14    D14.U8
+#define dRow15    D15.U8
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdWriteMacroblock
+
+        Functional description:
+            Write one macroblock into the image. Both luma and chroma
+            components will be written at the same time.
+
+        Inputs:
+            data    pointer to macroblock data to be written, 256 values for
+                    luma followed by 64 values for both chroma components
+
+        Outputs:
+            image   pointer to the image where the macroblock will be written
+
+        Returns:
+            none
+
+------------------------------------------------------------------------------*/
+
+function h264bsdWriteMacroblock, export=1
+    PUSH    {r4-r6,lr}
+    VPUSH   {q4-q7}
+
+    LDR     width, [image, #4]
+    LDR     luma, [image, #0xC]
+    LDR     cb, [image, #0x10]
+    LDR     cr, [image, #0x14]
+
+
+@   Write luma
+    VLD1    {qRow0, qRow1}, [data]!
+    LSL     width, width, #4
+    VLD1    {qRow2, qRow3}, [data]!
+    LSR     cwidth, width, #1
+    VST1    {qRow0}, [luma,:128], width
+    VLD1    {qRow4, qRow5}, [data]!
+    VST1    {qRow1}, [luma,:128], width
+    VLD1    {qRow6, qRow7}, [data]!
+    VST1    {qRow2}, [luma,:128], width
+    VLD1    {qRow8, qRow9}, [data]!
+    VST1    {qRow3}, [luma,:128], width
+    VLD1    {qRow10, qRow11}, [data]!
+    VST1    {qRow4}, [luma,:128], width
+    VLD1    {qRow12, qRow13}, [data]!
+    VST1    {qRow5}, [luma,:128], width
+    VLD1    {qRow14, qRow15}, [data]!
+    VST1    {qRow6}, [luma,:128], width
+
+    VLD1    {qRow0, qRow1}, [data]! ;//cb rows 0,1,2,3
+    VST1    {qRow7}, [luma,:128], width
+    VLD1    {qRow2, qRow3}, [data]! ;//cb rows 4,5,6,7
+    VST1    {qRow8}, [luma,:128], width
+    VLD1    {qRow4, qRow5}, [data]! ;//cr rows 0,1,2,3
+    VST1    {qRow9}, [luma,:128], width
+    VLD1    {qRow6, qRow7}, [data]! ;//cr rows 4,5,6,7
+    VST1    {qRow10}, [luma,:128], width
+    VST1    {dRow0}, [cb,:64], cwidth
+    VST1    {dRow8}, [cr,:64], cwidth
+    VST1    {qRow11}, [luma,:128], width
+    VST1    {dRow1}, [cb,:64], cwidth
+    VST1    {dRow9}, [cr,:64], cwidth
+    VST1    {qRow12}, [luma,:128], width
+    VST1    {dRow2}, [cb,:64], cwidth
+    VST1    {dRow10}, [cr,:64], cwidth
+    VST1    {qRow13}, [luma,:128], width
+    VST1    {dRow3}, [cb,:64], cwidth
+    VST1    {dRow11}, [cr,:64], cwidth
+    VST1    {qRow14}, [luma,:128], width
+    VST1    {dRow4}, [cb,:64], cwidth
+    VST1    {dRow12}, [cr,:64], cwidth
+    VST1    {qRow15}, [luma]
+    VST1    {dRow5}, [cb,:64], cwidth
+    VST1    {dRow13}, [cr,:64], cwidth
+    VST1    {dRow6}, [cb,:64], cwidth
+    VST1    {dRow14}, [cr,:64], cwidth
+    VST1    {dRow7}, [cb,:64]
+    VST1    {dRow15}, [cr,:64]
+
+    VPOP    {q4-q7}
+    POP     {r4-r6,pc}
+@    BX      lr
+
+    .endfunc
+
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_byte_stream.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_byte_stream.c
new file mode 100755
index 0000000..db77f8c
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_byte_stream.c
@@ -0,0 +1,237 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+     1. Include headers
+     2. External compiler flags
+     3. Module defines
+     4. Local function prototypes
+     5. Functions
+          ExtractNalUnit
+
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "h264bsd_byte_stream.h"
+#include "h264bsd_util.h"
+
+/*------------------------------------------------------------------------------
+    2. External compiler flags
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+    3. Module defines
+------------------------------------------------------------------------------*/
+
+#define BYTE_STREAM_ERROR  0xFFFFFFFF
+
+/*------------------------------------------------------------------------------
+    4. Local function prototypes
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+
+    Function name: ExtractNalUnit
+
+        Functional description:
+            Extracts one NAL unit from the byte stream buffer. Removes
+            emulation prevention bytes if present. The original stream buffer
+            is used directly and is therefore modified if emulation prevention
+            bytes are present in the stream.
+
+            Stream buffer is assumed to contain either exactly one NAL unit
+            and nothing else, or one or more NAL units embedded in byte
+            stream format described in the Annex B of the standard. Function
+            detects which one is used based on the first bytes in the buffer.
+
+        Inputs:
+            pByteStream     pointer to byte stream buffer
+            len             length of the stream buffer (in bytes)
+
+        Outputs:
+            pStrmData       stream information is stored here
+            readBytes       number of bytes "consumed" from the stream buffer
+
+        Returns:
+            HANTRO_OK       success
+            HANTRO_NOK      error in byte stream
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdExtractNalUnit(u8 *pByteStream, u32 len, strmData_t *pStrmData,
+    u32 *readBytes)
+{
+
+/* Variables */
+
+    u32 i, tmp;
+    u32 byteCount,initByteCount;
+    u32 zeroCount;
+    u8  byte;
+    u32 hasEmulation = HANTRO_FALSE;
+    u32 invalidStream = HANTRO_FALSE;
+    u8 *readPtr, *writePtr;
+
+/* Code */
+
+    ASSERT(pByteStream);
+    ASSERT(len);
+    ASSERT(len < BYTE_STREAM_ERROR);
+    ASSERT(pStrmData);
+
+    /* byte stream format if starts with 0x000001 or 0x000000 */
+    if (len > 3 && pByteStream[0] == 0x00 && pByteStream[1] == 0x00 &&
+        (pByteStream[2]&0xFE) == 0x00)
+    {
+        /* search for NAL unit start point, i.e. point after first start code
+         * prefix in the stream */
+        zeroCount = byteCount = 2;
+        readPtr = pByteStream + 2;
+        /*lint -e(716) while(1) used consciously */
+        while (1)
+        {
+            byte = *readPtr++;
+            byteCount++;
+
+            if (byteCount == len)
+            {
+                /* no start code prefix found -> error */
+                *readBytes = len;
+                return(HANTRO_NOK);
+            }
+
+            if (!byte)
+                zeroCount++;
+            else if ((byte == 0x01) && (zeroCount >= 2))
+                break;
+            else
+                zeroCount = 0;
+        }
+
+        initByteCount = byteCount;
+
+        /* determine size of the NAL unit. Search for next start code prefix
+         * or end of stream and ignore possible trailing zero bytes */
+        zeroCount = 0;
+        /*lint -e(716) while(1) used consciously */
+        while (1)
+        {
+            byte = *readPtr++;
+            byteCount++;
+            if (!byte)
+                zeroCount++;
+
+            if ( (byte == 0x03) && (zeroCount == 2) )
+            {
+                hasEmulation = HANTRO_TRUE;
+            }
+
+            if ( (byte == 0x01) && (zeroCount >= 2 ) )
+            {
+                pStrmData->strmBuffSize =
+                    byteCount - initByteCount - zeroCount - 1;
+                zeroCount -= MIN(zeroCount, 3);
+                break;
+            }
+            else if (byte)
+            {
+                if (zeroCount >= 3)
+                    invalidStream = HANTRO_TRUE;
+                zeroCount = 0;
+            }
+
+            if (byteCount == len)
+            {
+                pStrmData->strmBuffSize = byteCount - initByteCount - zeroCount;
+                break;
+            }
+
+        }
+    }
+    /* separate NAL units as input -> just set stream params */
+    else
+    {
+        initByteCount = 0;
+        zeroCount = 0;
+        pStrmData->strmBuffSize = len;
+        hasEmulation = HANTRO_TRUE;
+    }
+
+    pStrmData->pStrmBuffStart    = pByteStream + initByteCount;
+    pStrmData->pStrmCurrPos      = pStrmData->pStrmBuffStart;
+    pStrmData->bitPosInWord      = 0;
+    pStrmData->strmBuffReadBits  = 0;
+
+    /* return number of bytes "consumed" */
+    *readBytes = pStrmData->strmBuffSize + initByteCount + zeroCount;
+
+    if (invalidStream)
+    {
+        return(HANTRO_NOK);
+    }
+
+    /* remove emulation prevention bytes before rbsp processing */
+    if (hasEmulation)
+    {
+        tmp = pStrmData->strmBuffSize;
+        readPtr = writePtr = pStrmData->pStrmBuffStart;
+        zeroCount = 0;
+        for (i = tmp; i--;)
+        {
+            if ((zeroCount == 2) && (*readPtr == 0x03))
+            {
+                /* emulation prevention byte shall be followed by one of the
+                 * following bytes: 0x00, 0x01, 0x02, 0x03. This implies that
+                 * emulation prevention 0x03 byte shall not be the last byte
+                 * of the stream. */
+                if ( (i == 0) || (*(readPtr+1) > 0x03) )
+                    return(HANTRO_NOK);
+
+                /* do not write emulation prevention byte */
+                readPtr++;
+                zeroCount = 0;
+            }
+            else
+            {
+                /* NAL unit shall not contain byte sequences 0x000000,
+                 * 0x000001 or 0x000002 */
+                if ( (zeroCount == 2) && (*readPtr <= 0x02) )
+                    return(HANTRO_NOK);
+
+                if (*readPtr == 0)
+                    zeroCount++;
+                else
+                    zeroCount = 0;
+
+                *writePtr++ = *readPtr++;
+            }
+        }
+
+        /* (readPtr - writePtr) indicates number of "removed" emulation
+         * prevention bytes -> subtract from stream buffer size */
+        pStrmData->strmBuffSize -= (u32)(readPtr - writePtr);
+    }
+
+    return(HANTRO_OK);
+
+}
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_byte_stream.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_byte_stream.h
new file mode 100755
index 0000000..36aec76
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_byte_stream.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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+    1. Include headers
+    2. Module defines
+    3. Data types
+    4. Function prototypes
+
+------------------------------------------------------------------------------*/
+
+#ifndef H264SWDEC_BYTE_STREAM_H
+#define H264SWDEC_BYTE_STREAM_H
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "basetype.h"
+#include "h264bsd_stream.h"
+
+/*------------------------------------------------------------------------------
+    2. Module defines
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    3. Data types
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    4. Function prototypes
+------------------------------------------------------------------------------*/
+
+u32 h264bsdExtractNalUnit(u8 *pByteStream, u32 len, strmData_t *pStrmData,
+    u32 *readBytes);
+
+#endif /* #ifdef H264SWDEC_BYTE_STREAM_H */
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_cavlc.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_cavlc.c
new file mode 100755
index 0000000..91d78bd
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_cavlc.c
@@ -0,0 +1,916 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+     1. Include headers
+     2. External compiler flags
+     3. Module defines
+     4. Local function prototypes
+     5. Functions
+          DecodeCoeffToken
+          DecodeLevelPrefix
+          DecodeTotalZeros
+          DecodeRunBefore
+          DecodeResidualBlockCavlc
+
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "h264bsd_cavlc.h"
+#include "h264bsd_util.h"
+
+/*------------------------------------------------------------------------------
+    2. External compiler flags
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+    3. Module defines
+------------------------------------------------------------------------------*/
+
+/* Following descriptions use term "information field" to represent combination
+ * of certain decoded symbol value and the length of the corresponding variable
+ * length code word. For example, total_zeros information field consists of
+ * 4 bits symbol value (bits [4,7]) along with four bits to represent length
+ * of the VLC code word (bits [0,3]) */
+
+/* macro to obtain length of the coeff token information field, bits [0,4]  */
+#define LENGTH_TC(vlc) ((vlc) & 0x1F)
+/* macro to obtain length of the other information fields, bits [0,3] */
+#define LENGTH(vlc) ((vlc) & 0xF)
+/* macro to obtain code word from the information fields, bits [4,7] */
+#define INFO(vlc) (((vlc) >> 4) & 0xF)  /* 4 MSB bits contain information */
+/* macro to obtain trailing ones from the coeff token information word,
+ * bits [5,10] */
+#define TRAILING_ONES(coeffToken) ((coeffToken>>5) & 0x3F)
+/* macro to obtain total coeff from the coeff token information word,
+ * bits [11,15] */
+#define TOTAL_COEFF(coeffToken) (((coeffToken) >> 11) & 0x1F)
+
+#define VLC_NOT_FOUND 0xFFFFFFFEU
+
+/* VLC tables for coeff_token. Because of long codes (max. 16 bits) some of the
+ * tables have been splitted into multiple separate tables. Each array/table
+ * element has the following structure:
+ * [5 bits for tot.coeff.] [6 bits for tr.ones] [5 bits for VLC length]
+ * If there is a 0x0000 value, it means that there is not corresponding VLC
+ * codeword for that index. */
+
+/* VLC lengths up to 6 bits, 0 <= nC < 2 */
+static const u16 coeffToken0_0[32] = {
+    0x0000,0x0000,0x0000,0x2066,0x1026,0x0806,0x1865,0x1865,
+    0x1043,0x1043,0x1043,0x1043,0x1043,0x1043,0x1043,0x1043,
+    0x0822,0x0822,0x0822,0x0822,0x0822,0x0822,0x0822,0x0822,
+    0x0822,0x0822,0x0822,0x0822,0x0822,0x0822,0x0822,0x0822};
+
+/* VLC lengths up to 10 bits, 0 <= nC < 2 */
+static const u16 coeffToken0_1[48] = {
+    0x0000,0x0000,0x0000,0x0000,0x406a,0x304a,0x282a,0x200a,
+    0x3869,0x3869,0x2849,0x2849,0x2029,0x2029,0x1809,0x1809,
+    0x3068,0x3068,0x3068,0x3068,0x2048,0x2048,0x2048,0x2048,
+    0x1828,0x1828,0x1828,0x1828,0x1008,0x1008,0x1008,0x1008,
+    0x2867,0x2867,0x2867,0x2867,0x2867,0x2867,0x2867,0x2867,
+    0x1847,0x1847,0x1847,0x1847,0x1847,0x1847,0x1847,0x1847};
+
+/* VLC lengths up to 14 bits, 0 <= nC < 2 */
+static const u16 coeffToken0_2[56] = {
+    0x606e,0x584e,0x502e,0x500e,0x586e,0x504e,0x482e,0x480e,
+    0x400d,0x400d,0x484d,0x484d,0x402d,0x402d,0x380d,0x380d,
+    0x506d,0x506d,0x404d,0x404d,0x382d,0x382d,0x300d,0x300d,
+    0x486b,0x486b,0x486b,0x486b,0x486b,0x486b,0x486b,0x486b,
+    0x384b,0x384b,0x384b,0x384b,0x384b,0x384b,0x384b,0x384b,
+    0x302b,0x302b,0x302b,0x302b,0x302b,0x302b,0x302b,0x302b,
+    0x280b,0x280b,0x280b,0x280b,0x280b,0x280b,0x280b,0x280b};
+
+/* VLC lengths up to 16 bits, 0 <= nC < 2 */
+static const u16 coeffToken0_3[32] = {
+    0x0000,0x0000,0x682f,0x682f,0x8010,0x8050,0x8030,0x7810,
+    0x8070,0x7850,0x7830,0x7010,0x7870,0x7050,0x7030,0x6810,
+    0x706f,0x706f,0x684f,0x684f,0x602f,0x602f,0x600f,0x600f,
+    0x686f,0x686f,0x604f,0x604f,0x582f,0x582f,0x580f,0x580f};
+
+/* VLC lengths up to 6 bits, 2 <= nC < 4 */
+static const u16 coeffToken2_0[32] = {
+    0x0000,0x0000,0x0000,0x0000,0x3866,0x2046,0x2026,0x1006,
+    0x3066,0x1846,0x1826,0x0806,0x2865,0x2865,0x1025,0x1025,
+    0x2064,0x2064,0x2064,0x2064,0x1864,0x1864,0x1864,0x1864,
+    0x1043,0x1043,0x1043,0x1043,0x1043,0x1043,0x1043,0x1043};
+
+/* VLC lengths up to 9 bits, 2 <= nC < 4 */
+static const u16 coeffToken2_1[32] = {
+    0x0000,0x0000,0x0000,0x0000,0x4869,0x3849,0x3829,0x3009,
+    0x2808,0x2808,0x3048,0x3048,0x3028,0x3028,0x2008,0x2008,
+    0x4067,0x4067,0x4067,0x4067,0x2847,0x2847,0x2847,0x2847,
+    0x2827,0x2827,0x2827,0x2827,0x1807,0x1807,0x1807,0x1807};
+
+/* VLC lengths up to 14 bits, 2 <= nC < 4 */
+static const u16 coeffToken2_2[128] = {
+    0x0000,0x0000,0x786d,0x786d,0x806e,0x804e,0x802e,0x800e,
+    0x782e,0x780e,0x784e,0x702e,0x704d,0x704d,0x700d,0x700d,
+    0x706d,0x706d,0x684d,0x684d,0x682d,0x682d,0x680d,0x680d,
+    0x686d,0x686d,0x604d,0x604d,0x602d,0x602d,0x600d,0x600d,
+    0x580c,0x580c,0x580c,0x580c,0x584c,0x584c,0x584c,0x584c,
+    0x582c,0x582c,0x582c,0x582c,0x500c,0x500c,0x500c,0x500c,
+    0x606c,0x606c,0x606c,0x606c,0x504c,0x504c,0x504c,0x504c,
+    0x502c,0x502c,0x502c,0x502c,0x480c,0x480c,0x480c,0x480c,
+    0x586b,0x586b,0x586b,0x586b,0x586b,0x586b,0x586b,0x586b,
+    0x484b,0x484b,0x484b,0x484b,0x484b,0x484b,0x484b,0x484b,
+    0x482b,0x482b,0x482b,0x482b,0x482b,0x482b,0x482b,0x482b,
+    0x400b,0x400b,0x400b,0x400b,0x400b,0x400b,0x400b,0x400b,
+    0x506b,0x506b,0x506b,0x506b,0x506b,0x506b,0x506b,0x506b,
+    0x404b,0x404b,0x404b,0x404b,0x404b,0x404b,0x404b,0x404b,
+    0x402b,0x402b,0x402b,0x402b,0x402b,0x402b,0x402b,0x402b,
+    0x380b,0x380b,0x380b,0x380b,0x380b,0x380b,0x380b,0x380b};
+
+/* VLC lengths up to 6 bits, 4 <= nC < 8 */
+static const u16 coeffToken4_0[64] = {
+    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
+    0x1806,0x3846,0x3826,0x1006,0x4866,0x3046,0x3026,0x0806,
+    0x2825,0x2825,0x2845,0x2845,0x2025,0x2025,0x2045,0x2045,
+    0x1825,0x1825,0x4065,0x4065,0x1845,0x1845,0x1025,0x1025,
+    0x3864,0x3864,0x3864,0x3864,0x3064,0x3064,0x3064,0x3064,
+    0x2864,0x2864,0x2864,0x2864,0x2064,0x2064,0x2064,0x2064,
+    0x1864,0x1864,0x1864,0x1864,0x1044,0x1044,0x1044,0x1044,
+    0x0824,0x0824,0x0824,0x0824,0x0004,0x0004,0x0004,0x0004};
+
+/* VLC lengths up to 10 bits, 4 <= nC < 8 */
+static const u16 coeffToken4_1[128] = {
+    0x0000,0x800a,0x806a,0x804a,0x802a,0x780a,0x786a,0x784a,
+    0x782a,0x700a,0x706a,0x704a,0x702a,0x680a,0x6829,0x6829,
+    0x6009,0x6009,0x6849,0x6849,0x6029,0x6029,0x5809,0x5809,
+    0x6869,0x6869,0x6049,0x6049,0x5829,0x5829,0x5009,0x5009,
+    0x6068,0x6068,0x6068,0x6068,0x5848,0x5848,0x5848,0x5848,
+    0x5028,0x5028,0x5028,0x5028,0x4808,0x4808,0x4808,0x4808,
+    0x5868,0x5868,0x5868,0x5868,0x5048,0x5048,0x5048,0x5048,
+    0x4828,0x4828,0x4828,0x4828,0x4008,0x4008,0x4008,0x4008,
+    0x3807,0x3807,0x3807,0x3807,0x3807,0x3807,0x3807,0x3807,
+    0x3007,0x3007,0x3007,0x3007,0x3007,0x3007,0x3007,0x3007,
+    0x4847,0x4847,0x4847,0x4847,0x4847,0x4847,0x4847,0x4847,
+    0x2807,0x2807,0x2807,0x2807,0x2807,0x2807,0x2807,0x2807,
+    0x5067,0x5067,0x5067,0x5067,0x5067,0x5067,0x5067,0x5067,
+    0x4047,0x4047,0x4047,0x4047,0x4047,0x4047,0x4047,0x4047,
+    0x4027,0x4027,0x4027,0x4027,0x4027,0x4027,0x4027,0x4027,
+    0x2007,0x2007,0x2007,0x2007,0x2007,0x2007,0x2007,0x2007};
+
+/* fixed 6 bit length VLC, nC <= 8 */
+static const u16 coeffToken8[64] = {
+    0x0806,0x0826,0x0000,0x0006,0x1006,0x1026,0x1046,0x0000,
+    0x1806,0x1826,0x1846,0x1866,0x2006,0x2026,0x2046,0x2066,
+    0x2806,0x2826,0x2846,0x2866,0x3006,0x3026,0x3046,0x3066,
+    0x3806,0x3826,0x3846,0x3866,0x4006,0x4026,0x4046,0x4066,
+    0x4806,0x4826,0x4846,0x4866,0x5006,0x5026,0x5046,0x5066,
+    0x5806,0x5826,0x5846,0x5866,0x6006,0x6026,0x6046,0x6066,
+    0x6806,0x6826,0x6846,0x6866,0x7006,0x7026,0x7046,0x7066,
+    0x7806,0x7826,0x7846,0x7866,0x8006,0x8026,0x8046,0x8066};
+
+/* VLC lengths up to 3 bits, nC == -1 */
+static const u16 coeffTokenMinus1_0[8] = {
+    0x0000,0x1043,0x0002,0x0002,0x0821,0x0821,0x0821,0x0821};
+
+/* VLC lengths up to 8 bits, nC == -1 */
+static const u16 coeffTokenMinus1_1[32] = {
+    0x2067,0x2067,0x2048,0x2028,0x1847,0x1847,0x1827,0x1827,
+    0x2006,0x2006,0x2006,0x2006,0x1806,0x1806,0x1806,0x1806,
+    0x1006,0x1006,0x1006,0x1006,0x1866,0x1866,0x1866,0x1866,
+    0x1026,0x1026,0x1026,0x1026,0x0806,0x0806,0x0806,0x0806};
+
+/* VLC tables for total_zeros. One table containing longer code, totalZeros_1,
+ * has been broken into two separate tables. Table elements have the
+ * following structure:
+ * [4 bits for info] [4 bits for VLC length] */
+
+/* VLC lengths up to 5 bits */
+static const u8 totalZeros_1_0[32] = {
+    0x00,0x00,0x65,0x55,0x44,0x44,0x34,0x34,
+    0x23,0x23,0x23,0x23,0x13,0x13,0x13,0x13,
+    0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
+    0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01};
+
+/* VLC lengths up to 9 bits */
+static const u8 totalZeros_1_1[32] = {
+    0x00,0xf9,0xe9,0xd9,0xc8,0xc8,0xb8,0xb8,
+    0xa7,0xa7,0xa7,0xa7,0x97,0x97,0x97,0x97,
+    0x86,0x86,0x86,0x86,0x86,0x86,0x86,0x86,
+    0x76,0x76,0x76,0x76,0x76,0x76,0x76,0x76};
+
+static const u8 totalZeros_2[64] = {
+    0xe6,0xd6,0xc6,0xb6,0xa5,0xa5,0x95,0x95,
+    0x84,0x84,0x84,0x84,0x74,0x74,0x74,0x74,
+    0x64,0x64,0x64,0x64,0x54,0x54,0x54,0x54,
+    0x43,0x43,0x43,0x43,0x43,0x43,0x43,0x43,
+    0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,
+    0x23,0x23,0x23,0x23,0x23,0x23,0x23,0x23,
+    0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,
+    0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03};
+
+static const u8 totalZeros_3[64] = {
+    0xd6,0xb6,0xc5,0xc5,0xa5,0xa5,0x95,0x95,
+    0x84,0x84,0x84,0x84,0x54,0x54,0x54,0x54,
+    0x44,0x44,0x44,0x44,0x04,0x04,0x04,0x04,
+    0x73,0x73,0x73,0x73,0x73,0x73,0x73,0x73,
+    0x63,0x63,0x63,0x63,0x63,0x63,0x63,0x63,
+    0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,
+    0x23,0x23,0x23,0x23,0x23,0x23,0x23,0x23,
+    0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13};
+
+static const u8 totalZeros_4[32] = {
+    0xc5,0xb5,0xa5,0x05,0x94,0x94,0x74,0x74,
+    0x34,0x34,0x24,0x24,0x83,0x83,0x83,0x83,
+    0x63,0x63,0x63,0x63,0x53,0x53,0x53,0x53,
+    0x43,0x43,0x43,0x43,0x13,0x13,0x13,0x13};
+
+static const u8 totalZeros_5[32] = {
+    0xb5,0x95,0xa4,0xa4,0x84,0x84,0x24,0x24,
+    0x14,0x14,0x04,0x04,0x73,0x73,0x73,0x73,
+    0x63,0x63,0x63,0x63,0x53,0x53,0x53,0x53,
+    0x43,0x43,0x43,0x43,0x33,0x33,0x33,0x33};
+
+static const u8 totalZeros_6[64] = {
+    0xa6,0x06,0x15,0x15,0x84,0x84,0x84,0x84,
+    0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,
+    0x73,0x73,0x73,0x73,0x73,0x73,0x73,0x73,
+    0x63,0x63,0x63,0x63,0x63,0x63,0x63,0x63,
+    0x53,0x53,0x53,0x53,0x53,0x53,0x53,0x53,
+    0x43,0x43,0x43,0x43,0x43,0x43,0x43,0x43,
+    0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,
+    0x23,0x23,0x23,0x23,0x23,0x23,0x23,0x23};
+
+static const u8 totalZeros_7[64] = {
+    0x96,0x06,0x15,0x15,0x74,0x74,0x74,0x74,
+    0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,
+    0x63,0x63,0x63,0x63,0x63,0x63,0x63,0x63,
+    0x43,0x43,0x43,0x43,0x43,0x43,0x43,0x43,
+    0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,
+    0x23,0x23,0x23,0x23,0x23,0x23,0x23,0x23,
+    0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,
+    0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52};
+
+static const u8 totalZeros_8[64] = {
+    0x86,0x06,0x25,0x25,0x14,0x14,0x14,0x14,
+    0x73,0x73,0x73,0x73,0x73,0x73,0x73,0x73,
+    0x63,0x63,0x63,0x63,0x63,0x63,0x63,0x63,
+    0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,
+    0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,
+    0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,
+    0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,
+    0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42};
+
+static const u8 totalZeros_9[64] = {
+    0x16,0x06,0x75,0x75,0x24,0x24,0x24,0x24,
+    0x53,0x53,0x53,0x53,0x53,0x53,0x53,0x53,
+    0x62,0x62,0x62,0x62,0x62,0x62,0x62,0x62,
+    0x62,0x62,0x62,0x62,0x62,0x62,0x62,0x62,
+    0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,
+    0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,
+    0x32,0x32,0x32,0x32,0x32,0x32,0x32,0x32,
+    0x32,0x32,0x32,0x32,0x32,0x32,0x32,0x32};
+
+static const u8 totalZeros_10[32] = {
+    0x15,0x05,0x64,0x64,0x23,0x23,0x23,0x23,
+    0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,
+    0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,
+    0x32,0x32,0x32,0x32,0x32,0x32,0x32,0x32};
+
+static const u8 totalZeros_11[16] = {
+    0x04,0x14,0x23,0x23,0x33,0x33,0x53,0x53,
+    0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41};
+
+static const u8 totalZeros_12[16] = {
+    0x04,0x14,0x43,0x43,0x22,0x22,0x22,0x22,
+    0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31};
+
+static const u8 totalZeros_13[8] = {0x03,0x13,0x32,0x32,0x21,0x21,0x21,0x21};
+
+static const u8 totalZeros_14[4] = {0x02,0x12,0x21,0x21};
+
+/* VLC tables for run_before. Table elements have the following structure:
+ * [4 bits for info] [4bits for VLC length]
+ */
+
+static const u8 runBefore_6[8] = {0x13,0x23,0x43,0x33,0x63,0x53,0x02,0x02};
+
+static const u8 runBefore_5[8] = {0x53,0x43,0x33,0x23,0x12,0x12,0x02,0x02};
+
+static const u8 runBefore_4[8] = {0x43,0x33,0x22,0x22,0x12,0x12,0x02,0x02};
+
+static const u8 runBefore_3[4] = {0x32,0x22,0x12,0x02};
+
+static const u8 runBefore_2[4] = {0x22,0x12,0x01,0x01};
+
+static const u8 runBefore_1[2] = {0x11,0x01};
+
+/* following four macros are used to handle stream buffer "cache" in the CAVLC
+ * decoding function */
+
+/* macro to initialize stream buffer cache, fills the buffer (32 bits) */
+#define BUFFER_INIT(value, bits) \
+{ \
+    bits = 32; \
+    value = h264bsdShowBits32(pStrmData); \
+}
+
+/* macro to read numBits bits from the buffer, bits will be written to
+ * outVal. Refills the buffer if not enough bits left */
+#define BUFFER_SHOW(value, bits, outVal, numBits) \
+{ \
+    if (bits < (numBits)) \
+    { \
+        if(h264bsdFlushBits(pStrmData,32-bits) == END_OF_STREAM) \
+            return(HANTRO_NOK); \
+        value = h264bsdShowBits32(pStrmData); \
+        bits = 32; \
+    } \
+    (outVal) = value >> (32 - (numBits)); \
+}
+
+/* macro to flush numBits bits from the buffer */
+#define BUFFER_FLUSH(value, bits, numBits) \
+{ \
+    value <<= (numBits); \
+    bits -= (numBits); \
+}
+
+/* macro to read and flush  numBits bits from the buffer, bits will be written
+ * to outVal. Refills the buffer if not enough bits left */
+#define BUFFER_GET(value, bits, outVal, numBits) \
+{ \
+    if (bits < (numBits)) \
+    { \
+        if(h264bsdFlushBits(pStrmData,32-bits) == END_OF_STREAM) \
+            return(HANTRO_NOK); \
+        value = h264bsdShowBits32(pStrmData); \
+        bits = 32; \
+    } \
+    (outVal) = value >> (32 - (numBits)); \
+    value <<= (numBits); \
+    bits -= (numBits); \
+}
+
+/*------------------------------------------------------------------------------
+    4. Local function prototypes
+------------------------------------------------------------------------------*/
+
+static u32 DecodeCoeffToken(u32 bits, u32 nc);
+
+static u32 DecodeLevelPrefix(u32 bits);
+
+static u32 DecodeTotalZeros(u32 bits, u32 totalCoeff, u32 isChromaDC);
+
+static u32 DecodeRunBefore(u32 bits,u32 zerosLeft);
+
+/*------------------------------------------------------------------------------
+
+    Function: DecodeCoeffToken
+
+        Functional description:
+          Function to decode coeff_token information field from the stream.
+
+        Inputs:
+          u32 bits                  next 16 stream bits
+          u32 nc                    nC, see standard for details
+
+        Outputs:
+          u32  information field (11 bits for value, 5 bits for length)
+
+------------------------------------------------------------------------------*/
+
+u32 DecodeCoeffToken(u32 bits, u32 nc)
+{
+
+/* Variables */
+
+    u32 value;
+
+/* Code */
+
+    /* standard defines that nc for decoding of chroma dc coefficients is -1,
+     * represented by u32 here -> -1 maps to 2^32 - 1 */
+    ASSERT(nc <= 16 || nc == (u32)(-1));
+
+    if (nc < 2)
+    {
+        if (bits >= 0x8000)
+        {
+            value = 0x0001;
+        }
+        else if (bits >= 0x0C00)
+            value = coeffToken0_0[bits >> 10];
+        else if (bits >= 0x0100)
+            value = coeffToken0_1[bits >> 6];
+        else if (bits >= 0x0020)
+            value = coeffToken0_2[(bits>>2)-8];
+        else
+            value = coeffToken0_3[bits];
+    }
+    else if (nc < 4)
+    {
+        if (bits >= 0x8000)
+        {
+            value = bits & 0x4000 ? 0x0002 : 0x0822;
+        }
+        else if (bits >= 0x1000)
+            value = coeffToken2_0[bits >> 10];
+        else if (bits >= 0x0200)
+            value = coeffToken2_1[bits >> 7];
+        else
+            value = coeffToken2_2[bits>>2];
+    }
+    else if (nc < 8)
+    {
+        value = coeffToken4_0[bits >> 10];
+        if (!value)
+            value = coeffToken4_1[bits>>6];
+    }
+    else if (nc <= 16)
+    {
+        value = coeffToken8[bits>>10];
+    }
+    else
+    {
+        value = coeffTokenMinus1_0[bits >> 13];
+        if (!value)
+            value = coeffTokenMinus1_1[bits>>8];
+    }
+
+    return(value);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: DecodeLevelPrefix
+
+        Functional description:
+          Function to decode level_prefix information field from the stream
+
+        Inputs:
+          u32 bits      next 16 stream bits
+
+        Outputs:
+          u32  level_prefix information field or VLC_NOT_FOUND
+
+------------------------------------------------------------------------------*/
+
+u32 DecodeLevelPrefix(u32 bits)
+{
+
+/* Variables */
+
+    u32 numZeros;
+
+/* Code */
+
+    if (bits >= 0x8000)
+        numZeros = 0;
+    else if (bits >= 0x4000)
+        numZeros = 1;
+    else if (bits >= 0x2000)
+        numZeros = 2;
+    else if (bits >= 0x1000)
+        numZeros = 3;
+    else if (bits >= 0x0800)
+        numZeros = 4;
+    else if (bits >= 0x0400)
+        numZeros = 5;
+    else if (bits >= 0x0200)
+        numZeros = 6;
+    else if (bits >= 0x0100)
+        numZeros = 7;
+    else if (bits >= 0x0080)
+        numZeros = 8;
+    else if (bits >= 0x0040)
+        numZeros = 9;
+    else if (bits >= 0x0020)
+        numZeros = 10;
+    else if (bits >= 0x0010)
+        numZeros = 11;
+    else if (bits >= 0x0008)
+        numZeros = 12;
+    else if (bits >= 0x0004)
+        numZeros = 13;
+    else if (bits >= 0x0002)
+        numZeros = 14;
+    else if (bits >= 0x0001)
+        numZeros = 15;
+    else /* more than 15 zeros encountered which is an error */
+        return(VLC_NOT_FOUND);
+
+    return(numZeros);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: DecodeTotalZeros
+
+        Functional description:
+          Function to decode total_zeros information field from the stream
+
+        Inputs:
+          u32 bits                  next 9 stream bits
+          u32 totalCoeff            total number of coefficients for the block
+                                    being decoded
+          u32 isChromaDC           flag to indicate chroma DC block
+
+        Outputs:
+          u32  information field (4 bits value, 4 bits length)
+
+------------------------------------------------------------------------------*/
+
+u32 DecodeTotalZeros(u32 bits, u32 totalCoeff, u32 isChromaDC)
+{
+
+/* Variables */
+
+    u32 value = 0x0;
+
+/* Code */
+
+    ASSERT(totalCoeff);
+
+    if (!isChromaDC)
+    {
+        ASSERT(totalCoeff < 16);
+        switch (totalCoeff)
+        {
+            case 1:
+                value = totalZeros_1_0[bits >> 4];
+                if (!value)
+                    value = totalZeros_1_1[bits];
+                break;
+
+            case 2:
+                value = totalZeros_2[bits >> 3];
+                break;
+
+            case 3:
+                value = totalZeros_3[bits >> 3];
+                break;
+
+            case 4:
+                value = totalZeros_4[bits >> 4];
+                break;
+
+            case 5:
+                value = totalZeros_5[bits >> 4];
+                break;
+
+            case 6:
+                value = totalZeros_6[bits >> 3];
+                break;
+
+            case 7:
+                value = totalZeros_7[bits >> 3];
+                break;
+
+            case 8:
+                value = totalZeros_8[bits >> 3];
+                break;
+
+            case 9:
+                value = totalZeros_9[bits >> 3];
+                break;
+
+            case 10:
+                value = totalZeros_10[bits >> 4];
+                break;
+
+            case 11:
+                value = totalZeros_11[bits >> 5];
+                break;
+
+            case 12:
+                value = totalZeros_12[bits >> 5];
+                break;
+
+            case 13:
+                value = totalZeros_13[bits >> 6];
+                break;
+
+            case 14:
+                value = totalZeros_14[bits >> 7];
+                break;
+
+            default: /* case 15 */
+                value = (bits >> 8) ? 0x11 : 0x01;
+                break;
+        }
+    }
+    else
+    {
+        ASSERT(totalCoeff < 4);
+        bits >>= 6;
+        if (bits > 3)
+            value = 0x01;
+        else
+        {
+            if (totalCoeff == 3)
+                value = 0x11;
+            else if (bits > 1)
+            {
+                value = 0x12;
+            }
+            else if (totalCoeff == 2)
+                value = 0x22;
+            else if (bits)
+                value = 0x23;
+            else
+                value = 0x33;
+        }
+    }
+
+    return(value);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: DecodeRunBefore
+
+        Functional description:
+          Function to decode run_before information field from the stream
+
+        Inputs:
+          u32 bits                  next 11 stream bits
+          u32 zerosLeft             number of zeros left for the current block
+
+        Outputs:
+          u32  information field (4 bits value, 4 bits length)
+
+------------------------------------------------------------------------------*/
+
+u32 DecodeRunBefore(u32 bits, u32 zerosLeft)
+{
+
+/* Variables */
+
+    u32 value = 0x0;
+
+/* Code */
+
+    switch (zerosLeft)
+    {
+        case 1:
+            value = runBefore_1[bits>>10];
+            break;
+
+        case 2:
+            value = runBefore_2[bits>>9];
+            break;
+
+        case 3:
+            value = runBefore_3[bits>>9];
+            break;
+
+        case 4:
+            value = runBefore_4[bits>>8];
+            break;
+
+        case 5:
+            value = runBefore_5[bits>>8];
+            break;
+
+        case 6:
+            value = runBefore_6[bits>>8];
+            break;
+
+        default:
+            if (bits >= 0x100)
+                value = ((7-(bits>>8))<<4)+0x3;
+            else if (bits >= 0x80)
+                value = 0x74;
+            else if (bits >= 0x40)
+                value = 0x85;
+            else if (bits >= 0x20)
+                value = 0x96;
+            else if (bits >= 0x10)
+                value = 0xa7;
+            else if (bits >= 0x8)
+                value = 0xb8;
+            else if (bits >= 0x4)
+                value = 0xc9;
+            else if (bits >= 0x2)
+                value = 0xdA;
+            else if (bits)
+                value = 0xeB;
+            if (INFO(value) > zerosLeft)
+                value = 0;
+            break;
+    }
+
+    return(value);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: DecodeResidualBlockCavlc
+
+        Functional description:
+          Function to decode one CAVLC coded block. This corresponds to
+          syntax elements residual_block_cavlc() in the standard.
+
+        Inputs:
+          pStrmData             pointer to stream data structure
+          nc                    nC value
+          maxNumCoeff           maximum number of residual coefficients
+
+        Outputs:
+          coeffLevel            stores decoded coefficient levels
+
+        Returns:
+          numCoeffs             on bits [4,11] if successful
+          coeffMap              on bits [16,31] if successful, this is bit map
+                                where each bit indicates if the corresponding
+                                coefficient was zero (0) or non-zero (1)
+          HANTRO_NOK            end of stream or error in stream
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdDecodeResidualBlockCavlc(
+  strmData_t *pStrmData,
+  i32 *coeffLevel,
+  i32 nc,
+  u32 maxNumCoeff)
+{
+
+/* Variables */
+
+    u32 i, tmp, totalCoeff, trailingOnes, suffixLength, levelPrefix;
+    u32 levelSuffix, zerosLeft, bit;
+    i32 level[16];
+    u32 run[16];
+    /* stream "cache" */
+    u32 bufferValue;
+    u32 bufferBits;
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(coeffLevel);
+    ASSERT(nc > -2);
+    ASSERT(maxNumCoeff == 4 || maxNumCoeff == 15 || maxNumCoeff == 16);
+    ASSERT(VLC_NOT_FOUND != END_OF_STREAM);
+
+    /* assume that coeffLevel array has been "cleaned" by caller */
+
+    BUFFER_INIT(bufferValue, bufferBits);
+
+    /*lint -e774 disable lint warning on always false comparison */
+    BUFFER_SHOW(bufferValue, bufferBits, bit, 16);
+    /*lint +e774 */
+    tmp = DecodeCoeffToken(bit, (u32)nc);
+    if (!tmp)
+        return(HANTRO_NOK);
+    BUFFER_FLUSH(bufferValue, bufferBits, LENGTH_TC(tmp));
+
+    totalCoeff = TOTAL_COEFF(tmp);
+    if (totalCoeff > maxNumCoeff)
+        return(HANTRO_NOK);
+    trailingOnes = TRAILING_ONES(tmp);
+
+    if (totalCoeff != 0)
+    {
+        i = 0;
+        /* nonzero coefficients: +/- 1 */
+        if (trailingOnes)
+        {
+            BUFFER_GET(bufferValue, bufferBits, bit, trailingOnes);
+            tmp = 1 << (trailingOnes - 1);
+            for (; tmp; i++)
+            {
+                level[i] = bit & tmp ? -1 : 1;
+                tmp >>= 1;
+            }
+        }
+
+        /* other levels */
+        if (totalCoeff > 10 && trailingOnes < 3)
+            suffixLength = 1;
+        else
+            suffixLength = 0;
+
+        for (; i < totalCoeff; i++)
+        {
+            BUFFER_SHOW(bufferValue, bufferBits, bit, 16);
+            levelPrefix = DecodeLevelPrefix(bit);
+            if (levelPrefix == VLC_NOT_FOUND)
+                return(HANTRO_NOK);
+            BUFFER_FLUSH(bufferValue, bufferBits, levelPrefix+1);
+
+            if (levelPrefix < 14)
+                tmp = suffixLength;
+            else if (levelPrefix == 14)
+            {
+                tmp = suffixLength ? suffixLength : 4;
+            }
+            else
+            {
+                /* setting suffixLength to 1 here corresponds to adding 15
+                 * to levelCode value if levelPrefix == 15 and
+                 * suffixLength == 0 */
+                if (!suffixLength)
+                    suffixLength = 1;
+                tmp = 12;
+            }
+
+            if (suffixLength)
+                levelPrefix <<= suffixLength;
+
+            if (tmp)
+            {
+                BUFFER_GET(bufferValue, bufferBits, levelSuffix, tmp);
+                levelPrefix += levelSuffix;
+            }
+
+            tmp = levelPrefix;
+
+            if (i == trailingOnes && trailingOnes < 3)
+                tmp += 2;
+
+            level[i] = (tmp+2)>>1;
+
+            if (suffixLength == 0)
+                suffixLength = 1;
+
+            if ((level[i] > (3 << (suffixLength - 1))) && suffixLength < 6)
+                suffixLength++;
+
+            if (tmp & 0x1)
+                level[i] = -level[i];
+        }
+
+        /* zero runs */
+        if (totalCoeff < maxNumCoeff)
+        {
+            BUFFER_SHOW(bufferValue, bufferBits, bit,9);
+            zerosLeft = DecodeTotalZeros(bit, totalCoeff,
+                                        (u32)(maxNumCoeff == 4));
+            if (!zerosLeft)
+                return(HANTRO_NOK);
+            BUFFER_FLUSH(bufferValue, bufferBits, LENGTH(zerosLeft));
+            zerosLeft = INFO(zerosLeft);
+        }
+        else
+            zerosLeft = 0;
+
+        for (i = 0; i < totalCoeff - 1; i++)
+        {
+            if (zerosLeft > 0)
+            {
+                BUFFER_SHOW(bufferValue, bufferBits, bit,11);
+                tmp = DecodeRunBefore(bit, zerosLeft);
+                if (!tmp)
+                    return(HANTRO_NOK);
+                BUFFER_FLUSH(bufferValue, bufferBits, LENGTH(tmp));
+                run[i] = INFO(tmp);
+                zerosLeft -= run[i]++;
+            }
+            else
+            {
+                run[i] = 1;
+            }
+        }
+
+        /* combining level and run, levelSuffix variable used to hold coeffMap,
+         * i.e. bit map indicating which coefficients had non-zero value. */
+
+        /*lint -esym(771,level,run) level and run are always initialized */
+        tmp = zerosLeft;
+        coeffLevel[tmp] = level[totalCoeff-1];
+        levelSuffix = 1 << tmp;
+        for (i = totalCoeff-1; i--;)
+        {
+            tmp += run[i];
+            levelSuffix |= 1 << tmp;
+            coeffLevel[tmp] = level[i];
+        }
+
+    }
+    else
+        levelSuffix = 0;
+
+    if (h264bsdFlushBits(pStrmData, 32-bufferBits) != HANTRO_OK)
+        return(HANTRO_NOK);
+
+    return((totalCoeff << 4) | (levelSuffix << 16));
+}
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_cavlc.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_cavlc.h
new file mode 100755
index 0000000..80353d3
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_cavlc.h
@@ -0,0 +1,58 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+    1. Include headers
+    2. Module defines
+    3. Data types
+    4. Function prototypes
+
+------------------------------------------------------------------------------*/
+
+#ifndef H264SWDEC_CAVLC_H
+#define H264SWDEC_CAVLC_H
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "basetype.h"
+#include "h264bsd_stream.h"
+
+/*------------------------------------------------------------------------------
+    2. Module defines
+------------------------------------------------------------------------------*/
+
+
+/*------------------------------------------------------------------------------
+    3. Data types
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    4. Function prototypes
+------------------------------------------------------------------------------*/
+
+u32 h264bsdDecodeResidualBlockCavlc(
+  strmData_t *pStrmData,
+  i32 *coeffLevel,
+  i32 nc,
+  u32 maxNumCoeff);
+
+#endif /* #ifdef H264SWDEC_CAVLC_H */
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_cfg.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_cfg.h
new file mode 100755
index 0000000..2baba5a
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_cfg.h
@@ -0,0 +1,56 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+    1. Include headers
+    2. Module defines
+    3. Data types
+    4. Function prototypes
+
+------------------------------------------------------------------------------*/
+
+#ifndef H264SWDEC_CFG_H
+#define H264SWDEC_CFG_H
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "basetype.h"
+
+/*------------------------------------------------------------------------------
+    2. Module defines
+------------------------------------------------------------------------------*/
+
+#define MAX_NUM_REF_PICS 16
+#define MAX_NUM_SLICE_GROUPS 8
+#define MAX_NUM_SEQ_PARAM_SETS 32
+#define MAX_NUM_PIC_PARAM_SETS 256
+
+/*------------------------------------------------------------------------------
+    3. Data types
+------------------------------------------------------------------------------*/
+
+
+/*------------------------------------------------------------------------------
+    4. Function prototypes
+------------------------------------------------------------------------------*/
+
+#endif /* #ifdef H264SWDEC_CFG_H */
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_conceal.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_conceal.c
new file mode 100755
index 0000000..493fb9e
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_conceal.c
@@ -0,0 +1,626 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+     1. Include headers
+     2. External compiler flags
+     3. Module defines
+     4. Local function prototypes
+     5. Functions
+          h264bsdConceal
+          ConcealMb
+          Transform
+
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "h264bsd_conceal.h"
+#include "h264bsd_util.h"
+#include "h264bsd_reconstruct.h"
+#include "h264bsd_dpb.h"
+
+/*------------------------------------------------------------------------------
+    2. External compiler flags
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+    3. Module defines
+------------------------------------------------------------------------------*/
+
+/*lint -e702 disable lint warning on right shift of signed quantity */
+
+/*------------------------------------------------------------------------------
+    4. Local function prototypes
+------------------------------------------------------------------------------*/
+
+static u32 ConcealMb(mbStorage_t *pMb, image_t *currImage, u32 row, u32 col,
+    u32 sliceType, u8 *data);
+
+static void Transform(i32 *data);
+
+/*------------------------------------------------------------------------------
+
+    Function name: h264bsdConceal
+
+        Functional description:
+            Perform error concealment for a picture. Two types of concealment
+            is performed based on sliceType:
+                1) copy from previous picture for P-slices.
+                2) concealment from neighbour pixels for I-slices
+
+            I-type concealment is based on ideas presented by Jarno Tulkki.
+            The concealment algorithm determines frequency domain coefficients
+            from the neighbour pixels, applies integer transform (the same
+            transform used in the residual processing) and uses the results as
+            pixel values for concealed macroblocks. Transform produces 4x4
+            array and one pixel value has to be used for 4x4 luma blocks and
+            2x2 chroma blocks.
+
+            Similar concealment is performed for whole picture (the choise
+            of the type is based on last successfully decoded slice header of
+            the picture but it is handled by the calling function). It is
+            acknowledged that this may result in wrong type of concealment
+            when a picture contains both types of slices. However,
+            determination of slice type macroblock-by-macroblock cannot
+            be done due to the fact that it is impossible to know to which
+            slice each corrupted (not successfully decoded) macroblock
+            belongs.
+
+            The error concealment is started by searching the first propoerly
+            decoded macroblock and concealing the row containing the macroblock
+            in question. After that all macroblocks above the row in question
+            are concealed. Finally concealment of rows below is performed.
+            The order of concealment for 4x4 picture where macroblock 9 is the
+            first properly decoded one is as follows (properly decoded
+            macroblocks marked with 'x', numbers indicating the order of
+            concealment):
+
+               4  6  8 10
+               3  5  7  9
+               1  x  x  2
+              11 12 13 14
+
+            If all macroblocks of the picture are lost, the concealment is
+            copy of previous picture for P-type and setting the image to
+            constant gray (pixel value 128) for I-type.
+
+            Concealment sets quantization parameter of the concealed
+            macroblocks to value 40 and macroblock type to intra to enable
+            deblocking filter to smooth the edges of the concealed areas.
+
+        Inputs:
+            pStorage        pointer to storage structure
+            currImage       pointer to current image structure
+            sliceType       type of the slice
+
+        Outputs:
+            currImage       concealed macroblocks will be written here
+
+        Returns:
+            HANTRO_OK
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdConceal(storage_t *pStorage, image_t *currImage, u32 sliceType)
+{
+
+/* Variables */
+
+    u32 i, j;
+    u32 row, col;
+    u32 width, height;
+    u8 *refData;
+    mbStorage_t *mb;
+
+/* Code */
+
+    ASSERT(pStorage);
+    ASSERT(currImage);
+
+    DEBUG(("Concealing %s slice\n", IS_I_SLICE(sliceType) ?
+            "intra" : "inter"));
+
+    width = currImage->width;
+    height = currImage->height;
+    refData = NULL;
+    /* use reference picture with smallest available index */
+    if (IS_P_SLICE(sliceType) || (pStorage->intraConcealmentFlag != 0))
+    {
+        i = 0;
+        do
+        {
+            refData = h264bsdGetRefPicData(pStorage->dpb, i);
+            i++;
+            if (i >= 16)
+                break;
+        } while (refData == NULL);
+    }
+
+    i = row = col = 0;
+    /* find first properly decoded macroblock -> start point for concealment */
+    while (i < pStorage->picSizeInMbs && !pStorage->mb[i].decoded)
+    {
+        i++;
+        col++;
+        if (col == width)
+        {
+            row++;
+            col = 0;
+        }
+    }
+
+    /* whole picture lost -> copy previous or set grey */
+    if (i == pStorage->picSizeInMbs)
+    {
+        if ( (IS_I_SLICE(sliceType) && (pStorage->intraConcealmentFlag == 0)) ||
+             refData == NULL)
+            H264SwDecMemset(currImage->data, 128, width*height*384);
+        else
+            H264SwDecMemcpy(currImage->data, refData, width*height*384);
+
+        pStorage->numConcealedMbs = pStorage->picSizeInMbs;
+
+        /* no filtering if whole picture concealed */
+        for (i = 0; i < pStorage->picSizeInMbs; i++)
+            pStorage->mb[i].disableDeblockingFilterIdc = 1;
+
+        return(HANTRO_OK);
+    }
+
+    /* start from the row containing the first correct macroblock, conceal the
+     * row in question, all rows above that row and then continue downwards */
+    mb = pStorage->mb + row * width;
+    for (j = col; j--;)
+    {
+        ConcealMb(mb+j, currImage, row, j, sliceType, refData);
+        mb[j].decoded = 1;
+        pStorage->numConcealedMbs++;
+    }
+    for (j = col + 1; j < width; j++)
+    {
+        if (!mb[j].decoded)
+        {
+            ConcealMb(mb+j, currImage, row, j, sliceType, refData);
+            mb[j].decoded = 1;
+            pStorage->numConcealedMbs++;
+        }
+    }
+    /* if previous row(s) could not be concealed -> conceal them now */
+    if (row)
+    {
+        for (j = 0; j < width; j++)
+        {
+            i = row - 1;
+            mb = pStorage->mb + i*width + j;
+            do
+            {
+                ConcealMb(mb, currImage, i, j, sliceType, refData);
+                mb->decoded = 1;
+                pStorage->numConcealedMbs++;
+                mb -= width;
+            } while(i--);
+        }
+    }
+
+    /* process rows below the one containing the first correct macroblock */
+    for (i = row + 1; i < height; i++)
+    {
+        mb = pStorage->mb + i * width;
+
+        for (j = 0; j < width; j++)
+        {
+            if (!mb[j].decoded)
+            {
+                ConcealMb(mb+j, currImage, i, j, sliceType, refData);
+                mb[j].decoded = 1;
+                pStorage->numConcealedMbs++;
+            }
+        }
+    }
+
+    return(HANTRO_OK);
+}
+
+/*------------------------------------------------------------------------------
+
+    Function name: ConcealMb
+
+        Functional description:
+            Perform error concealment for one macroblock, location of the
+            macroblock in the picture indicated by row and col
+
+------------------------------------------------------------------------------*/
+
+u32 ConcealMb(mbStorage_t *pMb, image_t *currImage, u32 row, u32 col,
+    u32 sliceType, u8 *refData)
+{
+
+/* Variables */
+
+    u32 i, j, comp;
+    u32 hor, ver;
+    u32 mbNum;
+    u32 width, height;
+    u8 *mbPos;
+    u8 data[384];
+    u8 *pData;
+    i32 tmp;
+    i32 firstPhase[16];
+    i32 *pTmp;
+    /* neighbours above, below, left and right */
+    i32 a[4], b[4], l[4], r[4];
+    u32 A, B, L, R;
+#ifdef H264DEC_OMXDL
+    u8 fillBuff[32*21 + 15 + 32];
+    u8 *pFill;
+#endif
+/* Code */
+
+    ASSERT(pMb);
+    ASSERT(!pMb->decoded);
+    ASSERT(currImage);
+    ASSERT(col < currImage->width);
+    ASSERT(row < currImage->height);
+
+#ifdef H264DEC_OMXDL
+    pFill = ALIGN(fillBuff, 16);
+#endif
+    width = currImage->width;
+    height = currImage->height;
+    mbNum = row * width + col;
+
+    h264bsdSetCurrImageMbPointers(currImage, mbNum);
+
+    mbPos = currImage->data + row * 16 * width * 16 + col * 16;
+    A = B = L = R = HANTRO_FALSE;
+
+    /* set qpY to 40 to enable some filtering in deblocking (stetson value) */
+    pMb->qpY = 40;
+    pMb->disableDeblockingFilterIdc = 0;
+    /* mbType set to intra to perform filtering despite the values of other
+     * boundary strength determination fields */
+    pMb->mbType = I_4x4;
+    pMb->filterOffsetA = 0;
+    pMb->filterOffsetB = 0;
+    pMb->chromaQpIndexOffset = 0;
+
+    if (IS_I_SLICE(sliceType))
+        H264SwDecMemset(data, 0, sizeof(data));
+    else
+    {
+        mv_t mv = {0,0};
+        image_t refImage;
+        refImage.width = width;
+        refImage.height = height;
+        refImage.data = refData;
+        if (refImage.data)
+        {
+#ifndef H264DEC_OMXDL
+            h264bsdPredictSamples(data, &mv, &refImage, col*16, row*16,
+                0, 0, 16, 16);
+#else
+            h264bsdPredictSamples(data, &mv, &refImage,
+                    ((row*16) + ((col*16)<<16)),
+                    0x00001010, pFill);
+#endif
+            h264bsdWriteMacroblock(currImage, data);
+
+            return(HANTRO_OK);
+        }
+        else
+            H264SwDecMemset(data, 0, sizeof(data));
+    }
+
+    H264SwDecMemset(firstPhase, 0, sizeof(firstPhase));
+
+    /* counter for number of neighbours used */
+    j = 0;
+    hor = ver = 0;
+    if (row && (pMb-width)->decoded)
+    {
+        A = HANTRO_TRUE;
+        pData = mbPos - width*16;
+        a[0] = *pData++; a[0] += *pData++; a[0] += *pData++; a[0] += *pData++;
+        a[1] = *pData++; a[1] += *pData++; a[1] += *pData++; a[1] += *pData++;
+        a[2] = *pData++; a[2] += *pData++; a[2] += *pData++; a[2] += *pData++;
+        a[3] = *pData++; a[3] += *pData++; a[3] += *pData++; a[3] += *pData++;
+        j++;
+        hor++;
+        firstPhase[0] += a[0] + a[1] + a[2] + a[3];
+        firstPhase[1] += a[0] + a[1] - a[2] - a[3];
+    }
+    if ((row != height - 1) && (pMb+width)->decoded)
+    {
+        B = HANTRO_TRUE;
+        pData = mbPos + 16*width*16;
+        b[0] = *pData++; b[0] += *pData++; b[0] += *pData++; b[0] += *pData++;
+        b[1] = *pData++; b[1] += *pData++; b[1] += *pData++; b[1] += *pData++;
+        b[2] = *pData++; b[2] += *pData++; b[2] += *pData++; b[2] += *pData++;
+        b[3] = *pData++; b[3] += *pData++; b[3] += *pData++; b[3] += *pData++;
+        j++;
+        hor++;
+        firstPhase[0] += b[0] + b[1] + b[2] + b[3];
+        firstPhase[1] += b[0] + b[1] - b[2] - b[3];
+    }
+    if (col && (pMb-1)->decoded)
+    {
+        L = HANTRO_TRUE;
+        pData = mbPos - 1;
+        l[0] = pData[0]; l[0] += pData[16*width];
+        l[0] += pData[32*width]; l[0] += pData[48*width];
+        pData += 64*width;
+        l[1] = pData[0]; l[1] += pData[16*width];
+        l[1] += pData[32*width]; l[1] += pData[48*width];
+        pData += 64*width;
+        l[2] = pData[0]; l[2] += pData[16*width];
+        l[2] += pData[32*width]; l[2] += pData[48*width];
+        pData += 64*width;
+        l[3] = pData[0]; l[3] += pData[16*width];
+        l[3] += pData[32*width]; l[3] += pData[48*width];
+        j++;
+        ver++;
+        firstPhase[0] += l[0] + l[1] + l[2] + l[3];
+        firstPhase[4] += l[0] + l[1] - l[2] - l[3];
+    }
+    if ((col != width - 1) && (pMb+1)->decoded)
+    {
+        R = HANTRO_TRUE;
+        pData = mbPos + 16;
+        r[0] = pData[0]; r[0] += pData[16*width];
+        r[0] += pData[32*width]; r[0] += pData[48*width];
+        pData += 64*width;
+        r[1] = pData[0]; r[1] += pData[16*width];
+        r[1] += pData[32*width]; r[1] += pData[48*width];
+        pData += 64*width;
+        r[2] = pData[0]; r[2] += pData[16*width];
+        r[2] += pData[32*width]; r[2] += pData[48*width];
+        pData += 64*width;
+        r[3] = pData[0]; r[3] += pData[16*width];
+        r[3] += pData[32*width]; r[3] += pData[48*width];
+        j++;
+        ver++;
+        firstPhase[0] += r[0] + r[1] + r[2] + r[3];
+        firstPhase[4] += r[0] + r[1] - r[2] - r[3];
+    }
+
+    /* at least one properly decoded neighbour available */
+    ASSERT(j);
+
+    /*lint -esym(644,l,r,a,b) variable initialized above */
+    if (!hor && L && R)
+        firstPhase[1] = (l[0]+l[1]+l[2]+l[3]-r[0]-r[1]-r[2]-r[3]) >> 5;
+    else if (hor)
+        firstPhase[1] >>= (3+hor);
+
+    if (!ver && A && B)
+        firstPhase[4] = (a[0]+a[1]+a[2]+a[3]-b[0]-b[1]-b[2]-b[3]) >> 5;
+    else if (ver)
+        firstPhase[4] >>= (3+ver);
+
+    switch (j)
+    {
+        case 1:
+            firstPhase[0] >>= 4;
+            break;
+
+        case 2:
+            firstPhase[0] >>= 5;
+            break;
+
+        case 3:
+            /* approximate (firstPhase[0]*4/3)>>6 */
+            firstPhase[0] = (21 * firstPhase[0]) >> 10;
+            break;
+
+        default: /* 4 */
+            firstPhase[0] >>= 6;
+            break;
+
+    }
+
+
+    Transform(firstPhase);
+
+    for (i = 0, pData = data, pTmp = firstPhase; i < 256;)
+    {
+        tmp = pTmp[(i & 0xF)>>2];
+        /*lint -e734 CLIP1 macro results in value that fits into 8 bits */
+        *pData++ = CLIP1(tmp);
+        /*lint +e734 */
+
+        i++;
+        if (!(i & 0x3F))
+            pTmp += 4;
+    }
+
+    /* chroma components */
+    mbPos = currImage->data + width * height * 256 +
+       row * 8 * width * 8 + col * 8;
+    for (comp = 0; comp < 2; comp++)
+    {
+
+        H264SwDecMemset(firstPhase, 0, sizeof(firstPhase));
+
+        /* counter for number of neighbours used */
+        j = 0;
+        hor = ver = 0;
+        if (A)
+        {
+            pData = mbPos - width*8;
+            a[0] = *pData++; a[0] += *pData++;
+            a[1] = *pData++; a[1] += *pData++;
+            a[2] = *pData++; a[2] += *pData++;
+            a[3] = *pData++; a[3] += *pData++;
+            j++;
+            hor++;
+            firstPhase[0] += a[0] + a[1] + a[2] + a[3];
+            firstPhase[1] += a[0] + a[1] - a[2] - a[3];
+        }
+        if (B)
+        {
+            pData = mbPos + 8*width*8;
+            b[0] = *pData++; b[0] += *pData++;
+            b[1] = *pData++; b[1] += *pData++;
+            b[2] = *pData++; b[2] += *pData++;
+            b[3] = *pData++; b[3] += *pData++;
+            j++;
+            hor++;
+            firstPhase[0] += b[0] + b[1] + b[2] + b[3];
+            firstPhase[1] += b[0] + b[1] - b[2] - b[3];
+        }
+        if (L)
+        {
+            pData = mbPos - 1;
+            l[0] = pData[0]; l[0] += pData[8*width];
+            pData += 16*width;
+            l[1] = pData[0]; l[1] += pData[8*width];
+            pData += 16*width;
+            l[2] = pData[0]; l[2] += pData[8*width];
+            pData += 16*width;
+            l[3] = pData[0]; l[3] += pData[8*width];
+            j++;
+            ver++;
+            firstPhase[0] += l[0] + l[1] + l[2] + l[3];
+            firstPhase[4] += l[0] + l[1] - l[2] - l[3];
+        }
+        if (R)
+        {
+            pData = mbPos + 8;
+            r[0] = pData[0]; r[0] += pData[8*width];
+            pData += 16*width;
+            r[1] = pData[0]; r[1] += pData[8*width];
+            pData += 16*width;
+            r[2] = pData[0]; r[2] += pData[8*width];
+            pData += 16*width;
+            r[3] = pData[0]; r[3] += pData[8*width];
+            j++;
+            ver++;
+            firstPhase[0] += r[0] + r[1] + r[2] + r[3];
+            firstPhase[4] += r[0] + r[1] - r[2] - r[3];
+        }
+        if (!hor && L && R)
+            firstPhase[1] = (l[0]+l[1]+l[2]+l[3]-r[0]-r[1]-r[2]-r[3]) >> 4;
+        else if (hor)
+            firstPhase[1] >>= (2+hor);
+
+        if (!ver && A && B)
+            firstPhase[4] = (a[0]+a[1]+a[2]+a[3]-b[0]-b[1]-b[2]-b[3]) >> 4;
+        else if (ver)
+            firstPhase[4] >>= (2+ver);
+
+        switch (j)
+        {
+            case 1:
+                firstPhase[0] >>= 3;
+                break;
+
+            case 2:
+                firstPhase[0] >>= 4;
+                break;
+
+            case 3:
+                /* approximate (firstPhase[0]*4/3)>>5 */
+                firstPhase[0] = (21 * firstPhase[0]) >> 9;
+                break;
+
+            default: /* 4 */
+                firstPhase[0] >>= 5;
+                break;
+
+        }
+
+        Transform(firstPhase);
+
+        pData = data + 256 + comp*64;
+        for (i = 0, pTmp = firstPhase; i < 64;)
+        {
+            tmp = pTmp[(i & 0x7)>>1];
+            /*lint -e734 CLIP1 macro results in value that fits into 8 bits */
+            *pData++ = CLIP1(tmp);
+            /*lint +e734 */
+
+            i++;
+            if (!(i & 0xF))
+                pTmp += 4;
+        }
+
+        /* increment pointers for cr */
+        mbPos += width * height * 64;
+    }
+
+    h264bsdWriteMacroblock(currImage, data);
+
+    return(HANTRO_OK);
+
+}
+
+
+/*------------------------------------------------------------------------------
+
+    Function name: Transform
+
+        Functional description:
+            Simplified transform, assuming that only dc component and lowest
+            horizontal and lowest vertical component may be non-zero
+
+------------------------------------------------------------------------------*/
+
+void Transform(i32 *data)
+{
+
+    u32 col;
+    i32 tmp0, tmp1;
+
+    if (!data[1] && !data[4])
+    {
+        data[1]  = data[2]  = data[3]  = data[4]  = data[5]  =
+        data[6]  = data[7]  = data[8]  = data[9]  = data[10] =
+        data[11] = data[12] = data[13] = data[14] = data[15] = data[0];
+        return;
+    }
+    /* first horizontal transform for rows 0 and 1 */
+    tmp0 = data[0];
+    tmp1 = data[1];
+    data[0] = tmp0 + tmp1;
+    data[1] = tmp0 + (tmp1>>1);
+    data[2] = tmp0 - (tmp1>>1);
+    data[3] = tmp0 - tmp1;
+
+    tmp0 = data[4];
+    data[5] = tmp0;
+    data[6] = tmp0;
+    data[7] = tmp0;
+
+    /* then vertical transform */
+    for (col = 4; col--; data++)
+    {
+        tmp0 = data[0];
+        tmp1 = data[4];
+        data[0] = tmp0 + tmp1;
+        data[4] = tmp0 + (tmp1>>1);
+        data[8] = tmp0 - (tmp1>>1);
+        data[12] = tmp0 - tmp1;
+    }
+
+}
+/*lint +e702 */
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_conceal.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_conceal.h
new file mode 100755
index 0000000..3134670
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_conceal.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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+    1. Include headers
+    2. Module defines
+    3. Data types
+    4. Function prototypes
+
+------------------------------------------------------------------------------*/
+
+#ifndef H264SWDEC_CONCEAL_H
+#define H264SWDEC_CONCEAL_H
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "basetype.h"
+#include "h264bsd_slice_header.h"
+#include "h264bsd_storage.h"
+
+/*------------------------------------------------------------------------------
+    2. Module defines
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    3. Data types
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    4. Function prototypes
+------------------------------------------------------------------------------*/
+
+u32 h264bsdConceal(storage_t *pStorage, image_t *currImage, u32 sliceType);
+
+#endif /* #ifdef H264SWDEC_CONCEAL_H */
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_container.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_container.h
new file mode 100755
index 0000000..99b74a0
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_container.h
@@ -0,0 +1,69 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+    1. Include headers
+    2. Module defines
+    3. Data types
+    4. Function prototypes
+
+------------------------------------------------------------------------------*/
+
+#ifndef H264SWDEC_CONTAINER_H
+#define H264SWDEC_CONTAINER_H
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "basetype.h"
+#include "h264bsd_storage.h"
+
+/*------------------------------------------------------------------------------
+    2. Module defines
+------------------------------------------------------------------------------*/
+
+/* String length for tracing */
+#define H264DEC_TRACE_STR_LEN 100
+
+/*------------------------------------------------------------------------------
+    3. Data types
+------------------------------------------------------------------------------*/
+
+typedef struct
+{
+    enum {
+        UNINITIALIZED,
+        INITIALIZED,
+        NEW_HEADERS
+    } decStat;
+
+    u32 picNumber;
+    storage_t storage;
+#ifdef H264DEC_TRACE
+    char str[H264DEC_TRACE_STR_LEN];
+#endif
+} decContainer_t;
+
+/*------------------------------------------------------------------------------
+    4. Function prototypes
+------------------------------------------------------------------------------*/
+
+#endif /* #ifdef H264SWDEC_DECCONTAINER_H */
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_deblocking.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_deblocking.c
new file mode 100755
index 0000000..f8c1f76
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_deblocking.c
@@ -0,0 +1,2417 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+     1. Include headers
+     2. External compiler flags
+     3. Module defines
+     4. Local function prototypes
+     5. Functions
+          h264bsdFilterPicture
+          FilterVerLumaEdge
+          FilterHorLumaEdge
+          FilterHorLuma
+          FilterVerChromaEdge
+          FilterHorChromaEdge
+          FilterHorChroma
+          InnerBoundaryStrength
+          EdgeBoundaryStrength
+          GetBoundaryStrengths
+          IsSliceBoundaryOnLeft
+          IsSliceBoundaryOnTop
+          GetMbFilteringFlags
+          GetLumaEdgeThresholds
+          GetChromaEdgeThresholds
+          FilterLuma
+          FilterChroma
+
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "basetype.h"
+#include "h264bsd_util.h"
+#include "h264bsd_macroblock_layer.h"
+#include "h264bsd_deblocking.h"
+#include "h264bsd_dpb.h"
+
+#ifdef H264DEC_OMXDL
+#include "omxtypes.h"
+#include "omxVC.h"
+#include "armVC.h"
+#endif /* H264DEC_OMXDL */
+
+/*------------------------------------------------------------------------------
+    2. External compiler flags
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+    3. Module defines
+------------------------------------------------------------------------------*/
+
+/* Switch off the following Lint messages for this file:
+ * Info 701: Shift left of signed quantity (int)
+ * Info 702: Shift right of signed quantity (int)
+ */
+/*lint -e701 -e702 */
+
+/* array of alpha values, from the standard */
+static const u8 alphas[52] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,4,5,6,7,8,9,10,
+    12,13,15,17,20,22,25,28,32,36,40,45,50,56,63,71,80,90,101,113,127,144,162,
+    182,203,226,255,255};
+
+/* array of beta values, from the standard */
+static const u8 betas[52] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,3,3,3,3,4,4,
+    4,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18};
+
+
+
+#ifndef H264DEC_OMXDL
+/* array of tc0 values, from the standard, each triplet corresponds to a
+ * column in the table. Indexing goes as tc0[indexA][bS-1] */
+static const u8 tc0[52][3] = {
+    {0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},
+    {0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},
+    {0,0,0},{0,0,1},{0,0,1},{0,0,1},{0,0,1},{0,1,1},{0,1,1},{1,1,1},
+    {1,1,1},{1,1,1},{1,1,1},{1,1,2},{1,1,2},{1,1,2},{1,1,2},{1,2,3},
+    {1,2,3},{2,2,3},{2,2,4},{2,3,4},{2,3,4},{3,3,5},{3,4,6},{3,4,6},
+    {4,5,7},{4,5,8},{4,6,9},{5,7,10},{6,8,11},{6,8,13},{7,10,14},{8,11,16},
+    {9,12,18},{10,13,20},{11,15,23},{13,17,25}
+};
+#else
+/* array of tc0 values, from the standard, each triplet corresponds to a
+ * column in the table. Indexing goes as tc0[indexA][bS] */
+static const u8 tc0[52][5] = {
+    {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0},
+    {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0},
+    {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0},
+    {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0},
+    {0, 0, 0, 0, 0}, {0, 0, 0, 1, 0}, {0, 0, 0, 1, 0}, {0, 0, 0, 1, 0},
+    {0, 0, 0, 1, 0}, {0, 0, 1, 1, 0}, {0, 0, 1, 1, 0}, {0, 1, 1, 1, 0},
+    {0, 1, 1, 1, 0}, {0, 1, 1, 1, 0}, {0, 1, 1, 1, 0}, {0, 1, 1, 2, 0},
+    {0, 1, 1, 2, 0}, {0, 1, 1, 2, 0}, {0, 1, 1, 2, 0}, {0, 1, 2, 3, 0},
+    {0, 1, 2, 3, 0}, {0, 2, 2, 3, 0}, {0, 2, 2, 4, 0}, {0, 2, 3, 4, 0},
+    {0, 2, 3, 4, 0}, {0, 3, 3, 5, 0}, {0, 3, 4, 6, 0}, {0, 3, 4, 6, 0},
+    {0, 4, 5, 7, 0}, {0, 4, 5, 8, 0}, {0, 4, 6, 9, 0}, {0, 5, 7, 10, 0},
+    {0, 6, 8, 11, 0}, {0, 6, 8, 13, 0}, {0, 7, 10, 14, 0},
+    {0, 8, 11, 16, 0}, {0, 9, 12, 18, 0}, {0, 10, 13, 20, 0},
+    {0, 11, 15, 23, 0}, {0, 13, 17, 25, 0}
+};
+#endif
+
+
+#ifndef H264DEC_OMXDL
+/* mapping of raster scan block index to 4x4 block index */
+static const u32 mb4x4Index[16] =
+    {0, 1, 4, 5, 2, 3, 6, 7, 8, 9, 12, 13, 10, 11, 14, 15};
+
+typedef struct {
+    const u8 *tc0;
+    u32 alpha;
+    u32 beta;
+} edgeThreshold_t;
+
+typedef struct {
+    u32 top;
+    u32 left;
+} bS_t;
+
+enum { TOP = 0, LEFT = 1, INNER = 2 };
+#endif /* H264DEC_OMXDL */
+
+#define FILTER_LEFT_EDGE    0x04
+#define FILTER_TOP_EDGE     0x02
+#define FILTER_INNER_EDGE   0x01
+
+
+/* clipping table defined in intra_prediction.c */
+extern const u8 h264bsdClip[];
+
+/*------------------------------------------------------------------------------
+    4. Local function prototypes
+------------------------------------------------------------------------------*/
+
+static u32 InnerBoundaryStrength(mbStorage_t *mb1, u32 i1, u32 i2);
+
+#ifndef H264DEC_OMXDL
+static u32 EdgeBoundaryStrength(mbStorage_t *mb1, mbStorage_t *mb2,
+    u32 i1, u32 i2);
+#else
+static u32 InnerBoundaryStrength2(mbStorage_t *mb1, u32 i1, u32 i2);
+static u32 EdgeBoundaryStrengthLeft(mbStorage_t *mb1, mbStorage_t *mb2);
+static u32 EdgeBoundaryStrengthTop(mbStorage_t *mb1, mbStorage_t *mb2);
+#endif
+
+static u32 IsSliceBoundaryOnLeft(mbStorage_t *mb);
+
+static u32 IsSliceBoundaryOnTop(mbStorage_t *mb);
+
+static u32 GetMbFilteringFlags(mbStorage_t *mb);
+
+#ifndef H264DEC_OMXDL
+
+static u32 GetBoundaryStrengths(mbStorage_t *mb, bS_t *bs, u32 flags);
+
+static void FilterLuma(u8 *data, bS_t *bS, edgeThreshold_t *thresholds,
+        u32 imageWidth);
+
+static void FilterChroma(u8 *cb, u8 *cr, bS_t *bS, edgeThreshold_t *thresholds,
+        u32 imageWidth);
+
+static void FilterVerLumaEdge( u8 *data, u32 bS, edgeThreshold_t *thresholds,
+        u32 imageWidth);
+static void FilterHorLumaEdge( u8 *data, u32 bS, edgeThreshold_t *thresholds,
+        i32 imageWidth);
+static void FilterHorLuma( u8 *data, u32 bS, edgeThreshold_t *thresholds,
+        i32 imageWidth);
+
+static void FilterVerChromaEdge( u8 *data, u32 bS, edgeThreshold_t *thresholds,
+  u32 imageWidth);
+static void FilterHorChromaEdge( u8 *data, u32 bS, edgeThreshold_t *thresholds,
+  i32 imageWidth);
+static void FilterHorChroma( u8 *data, u32 bS, edgeThreshold_t *thresholds,
+  i32 imageWidth);
+
+static void GetLumaEdgeThresholds(
+  edgeThreshold_t *thresholds,
+  mbStorage_t *mb,
+  u32 filteringFlags);
+
+static void GetChromaEdgeThresholds(
+  edgeThreshold_t *thresholds,
+  mbStorage_t *mb,
+  u32 filteringFlags,
+  i32 chromaQpIndexOffset);
+
+#else /* H264DEC_OMXDL */
+
+static u32 GetBoundaryStrengths(mbStorage_t *mb, u8 (*bs)[16], u32 flags);
+
+static void GetLumaEdgeThresholds(
+    mbStorage_t *mb,
+    u8 (*alpha)[2],
+    u8 (*beta)[2],
+    u8 (*threshold)[16],
+    u8 (*bs)[16],
+    u32 filteringFlags );
+
+static void GetChromaEdgeThresholds(
+    mbStorage_t *mb,
+    u8 (*alpha)[2],
+    u8 (*beta)[2],
+    u8 (*threshold)[8],
+    u8 (*bs)[16],
+    u32 filteringFlags,
+    i32 chromaQpIndexOffset);
+
+#endif /* H264DEC_OMXDL */
+
+/*------------------------------------------------------------------------------
+
+    Function: IsSliceBoundaryOnLeft
+
+        Functional description:
+            Function to determine if there is a slice boundary on the left side
+            of a macroblock.
+
+------------------------------------------------------------------------------*/
+u32 IsSliceBoundaryOnLeft(mbStorage_t *mb)
+{
+
+/* Variables */
+
+/* Code */
+
+    ASSERT(mb && mb->mbA);
+
+    if (mb->sliceId != mb->mbA->sliceId)
+        return(HANTRO_TRUE);
+    else
+        return(HANTRO_FALSE);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: IsSliceBoundaryOnTop
+
+        Functional description:
+            Function to determine if there is a slice boundary above the
+            current macroblock.
+
+------------------------------------------------------------------------------*/
+u32 IsSliceBoundaryOnTop(mbStorage_t *mb)
+{
+
+/* Variables */
+
+/* Code */
+
+    ASSERT(mb && mb->mbB);
+
+    if (mb->sliceId != mb->mbB->sliceId)
+        return(HANTRO_TRUE);
+    else
+        return(HANTRO_FALSE);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: GetMbFilteringFlags
+
+        Functional description:
+          Function to determine which edges of a macroblock has to be
+          filtered. Output is a bit-wise OR of FILTER_LEFT_EDGE,
+          FILTER_TOP_EDGE and FILTER_INNER_EDGE, depending on which edges
+          shall be filtered.
+
+------------------------------------------------------------------------------*/
+u32 GetMbFilteringFlags(mbStorage_t *mb)
+{
+
+/* Variables */
+
+    u32 flags = 0;
+
+/* Code */
+
+    ASSERT(mb);
+
+    /* nothing will be filtered if disableDeblockingFilterIdc == 1 */
+    if (mb->disableDeblockingFilterIdc != 1)
+    {
+        flags |= FILTER_INNER_EDGE;
+
+        /* filterLeftMbEdgeFlag, left mb is MB_A */
+        if (mb->mbA &&
+            ((mb->disableDeblockingFilterIdc != 2) ||
+             !IsSliceBoundaryOnLeft(mb)))
+            flags |= FILTER_LEFT_EDGE;
+
+        /* filterTopMbEdgeFlag */
+        if (mb->mbB &&
+            ((mb->disableDeblockingFilterIdc != 2) ||
+             !IsSliceBoundaryOnTop(mb)))
+            flags |= FILTER_TOP_EDGE;
+    }
+
+    return(flags);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: InnerBoundaryStrength
+
+        Functional description:
+            Function to calculate boundary strength value bs for an inner
+            edge of a macroblock. Macroblock type is checked before this is
+            called -> no intra mb condition here.
+
+------------------------------------------------------------------------------*/
+u32 InnerBoundaryStrength(mbStorage_t *mb1, u32 ind1, u32 ind2)
+{
+    i32 tmp1, tmp2;
+    i32 mv1, mv2, mv3, mv4;
+
+    tmp1 = mb1->totalCoeff[ind1];
+    tmp2 = mb1->totalCoeff[ind2];
+    mv1 = mb1->mv[ind1].hor;
+    mv2 = mb1->mv[ind2].hor;
+    mv3 = mb1->mv[ind1].ver;
+    mv4 = mb1->mv[ind2].ver;
+
+    if (tmp1 || tmp2)
+    {
+        return 2;
+    }
+    else if ( (ABS(mv1 - mv2) >= 4) || (ABS(mv3 - mv4) >= 4) ||
+              (mb1->refAddr[ind1 >> 2] != mb1->refAddr[ind2 >> 2]) )
+    {
+        return 1;
+    }
+    else
+        return 0;
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: InnerBoundaryStrength2
+
+        Functional description:
+            Function to calculate boundary strength value bs for an inner
+            edge of a macroblock. The function is the same as
+            InnerBoundaryStrength but without checking totalCoeff.
+
+------------------------------------------------------------------------------*/
+u32 InnerBoundaryStrength2(mbStorage_t *mb1, u32 ind1, u32 ind2)
+{
+    i32 tmp1, tmp2, tmp3, tmp4;
+
+    tmp1 = mb1->mv[ind1].hor;
+    tmp2 = mb1->mv[ind2].hor;
+    tmp3 = mb1->mv[ind1].ver;
+    tmp4 = mb1->mv[ind2].ver;
+
+    if ( (ABS(tmp1 - tmp2) >= 4) || (ABS(tmp3 - tmp4) >= 4) ||
+         (mb1->refAddr[ind1 >> 2] != mb1->refAddr[ind2 >> 2]))
+    {
+        return 1;
+    }
+    else
+        return 0;
+}
+#ifndef H264DEC_OMXDL
+/*------------------------------------------------------------------------------
+
+    Function: EdgeBoundaryStrength
+
+        Functional description:
+            Function to calculate boundary strength value bs for left- or
+            top-most edge of a macroblock. Macroblock types are checked
+            before this is called -> no intra mb conditions here.
+
+------------------------------------------------------------------------------*/
+u32 EdgeBoundaryStrength(mbStorage_t *mb1, mbStorage_t *mb2,
+    u32 ind1, u32 ind2)
+{
+
+    if (mb1->totalCoeff[ind1] || mb2->totalCoeff[ind2])
+    {
+        return 2;
+    }
+    else if ((mb1->refAddr[ind1 >> 2] != mb2->refAddr[ind2 >> 2]) ||
+             (ABS(mb1->mv[ind1].hor - mb2->mv[ind2].hor) >= 4) ||
+             (ABS(mb1->mv[ind1].ver - mb2->mv[ind2].ver) >= 4))
+    {
+        return 1;
+    }
+    else
+        return 0;
+}
+
+#else /* H264DEC_OMXDL */
+
+/*------------------------------------------------------------------------------
+
+    Function: EdgeBoundaryStrengthTop
+
+        Functional description:
+            Function to calculate boundary strength value bs for
+            top-most edge of a macroblock. Macroblock types are checked
+            before this is called -> no intra mb conditions here.
+
+------------------------------------------------------------------------------*/
+u32 EdgeBoundaryStrengthTop(mbStorage_t *mb1, mbStorage_t *mb2)
+{
+    u32 topBs = 0;
+    u32 tmp1, tmp2, tmp3, tmp4;
+
+    tmp1 = mb1->totalCoeff[0];
+    tmp2 = mb2->totalCoeff[10];
+    tmp3 = mb1->totalCoeff[1];
+    tmp4 = mb2->totalCoeff[11];
+    if (tmp1 || tmp2)
+    {
+        topBs = 2<<0;
+    }
+    else if ((ABS(mb1->mv[0].hor - mb2->mv[10].hor) >= 4) ||
+             (ABS(mb1->mv[0].ver - mb2->mv[10].ver) >= 4) ||
+             (mb1->refAddr[0] != mb2->refAddr[10 >> 2]))
+    {
+        topBs = 1<<0;
+    }
+    tmp1 = mb1->totalCoeff[4];
+    tmp2 = mb2->totalCoeff[14];
+    if (tmp3 || tmp4)
+    {
+        topBs += 2<<8;
+    }
+    else if ((ABS(mb1->mv[1].hor - mb2->mv[11].hor) >= 4) ||
+             (ABS(mb1->mv[1].ver - mb2->mv[11].ver) >= 4) ||
+             (mb1->refAddr[0] != mb2->refAddr[11 >> 2]))
+    {
+        topBs += 1<<8;
+    }
+    tmp3 = mb1->totalCoeff[5];
+    tmp4 = mb2->totalCoeff[15];
+    if (tmp1 || tmp2)
+    {
+        topBs += 2<<16;
+    }
+    else if ((ABS(mb1->mv[4].hor - mb2->mv[14].hor) >= 4) ||
+             (ABS(mb1->mv[4].ver - mb2->mv[14].ver) >= 4) ||
+             (mb1->refAddr[4 >> 2] != mb2->refAddr[14 >> 2]))
+    {
+        topBs += 1<<16;
+    }
+    if (tmp3 || tmp4)
+    {
+        topBs += 2<<24;
+    }
+    else if ((ABS(mb1->mv[5].hor - mb2->mv[15].hor) >= 4) ||
+             (ABS(mb1->mv[5].ver - mb2->mv[15].ver) >= 4) ||
+             (mb1->refAddr[5 >> 2] != mb2->refAddr[15 >> 2]))
+    {
+        topBs += 1<<24;
+    }
+
+    return topBs;
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: EdgeBoundaryStrengthLeft
+
+        Functional description:
+            Function to calculate boundary strength value bs for left-
+            edge of a macroblock. Macroblock types are checked
+            before this is called -> no intra mb conditions here.
+
+------------------------------------------------------------------------------*/
+u32 EdgeBoundaryStrengthLeft(mbStorage_t *mb1, mbStorage_t *mb2)
+{
+    u32 leftBs = 0;
+    u32 tmp1, tmp2, tmp3, tmp4;
+
+    tmp1 = mb1->totalCoeff[0];
+    tmp2 = mb2->totalCoeff[5];
+    tmp3 = mb1->totalCoeff[2];
+    tmp4 = mb2->totalCoeff[7];
+
+    if (tmp1 || tmp2)
+    {
+        leftBs = 2<<0;
+    }
+    else if ((ABS(mb1->mv[0].hor - mb2->mv[5].hor) >= 4) ||
+             (ABS(mb1->mv[0].ver - mb2->mv[5].ver) >= 4) ||
+             (mb1->refAddr[0] != mb2->refAddr[5 >> 2]))
+    {
+        leftBs = 1<<0;
+    }
+    tmp1 = mb1->totalCoeff[8];
+    tmp2 = mb2->totalCoeff[13];
+    if (tmp3 || tmp4)
+    {
+        leftBs += 2<<8;
+    }
+    else if ((ABS(mb1->mv[2].hor - mb2->mv[7].hor) >= 4) ||
+             (ABS(mb1->mv[2].ver - mb2->mv[7].ver) >= 4) ||
+             (mb1->refAddr[0] != mb2->refAddr[7 >> 2]))
+    {
+        leftBs += 1<<8;
+    }
+    tmp3 = mb1->totalCoeff[10];
+    tmp4 = mb2->totalCoeff[15];
+    if (tmp1 || tmp2)
+    {
+        leftBs += 2<<16;
+    }
+    else if ((ABS(mb1->mv[8].hor - mb2->mv[13].hor) >= 4) ||
+             (ABS(mb1->mv[8].ver - mb2->mv[13].ver) >= 4) ||
+             (mb1->refAddr[8 >> 2] != mb2->refAddr[13 >> 2]))
+    {
+        leftBs += 1<<16;
+    }
+    if (tmp3 || tmp4)
+    {
+        leftBs += 2<<24;
+    }
+    else if ((ABS(mb1->mv[10].hor - mb2->mv[15].hor) >= 4) ||
+             (ABS(mb1->mv[10].ver - mb2->mv[15].ver) >= 4) ||
+             (mb1->refAddr[10 >> 2] != mb2->refAddr[15 >> 2]))
+    {
+        leftBs += 1<<24;
+    }
+
+    return leftBs;
+}
+#endif /* H264DEC_OMXDL */
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdFilterPicture
+
+        Functional description:
+          Perform deblocking filtering for a picture. Filter does not copy
+          the original picture anywhere but filtering is performed directly
+          on the original image. Parameters controlling the filtering process
+          are computed based on information in macroblock structures of the
+          filtered macroblock, macroblock above and macroblock on the left of
+          the filtered one.
+
+        Inputs:
+          image         pointer to image to be filtered
+          mb            pointer to macroblock data structure of the top-left
+                        macroblock of the picture
+
+        Outputs:
+          image         filtered image stored here
+
+        Returns:
+          none
+
+------------------------------------------------------------------------------*/
+#ifndef H264DEC_OMXDL
+void h264bsdFilterPicture(
+  image_t *image,
+  mbStorage_t *mb)
+{
+
+/* Variables */
+
+    u32 flags;
+    u32 picSizeInMbs, mbRow, mbCol;
+    u32 picWidthInMbs;
+    u8 *data;
+    mbStorage_t *pMb;
+    bS_t bS[16];
+    edgeThreshold_t thresholds[3];
+
+/* Code */
+
+    ASSERT(image);
+    ASSERT(mb);
+    ASSERT(image->data);
+    ASSERT(image->width);
+    ASSERT(image->height);
+
+    picWidthInMbs = image->width;
+    data = image->data;
+    picSizeInMbs = picWidthInMbs * image->height;
+
+    pMb = mb;
+
+    for (mbRow = 0, mbCol = 0; mbRow < image->height; pMb++)
+    {
+        flags = GetMbFilteringFlags(pMb);
+
+        if (flags)
+        {
+            /* GetBoundaryStrengths function returns non-zero value if any of
+             * the bS values for the macroblock being processed was non-zero */
+            if (GetBoundaryStrengths(pMb, bS, flags))
+            {
+                /* luma */
+                GetLumaEdgeThresholds(thresholds, pMb, flags);
+                data = image->data + mbRow * picWidthInMbs * 256 + mbCol * 16;
+
+                FilterLuma((u8*)data, bS, thresholds, picWidthInMbs*16);
+
+                /* chroma */
+                GetChromaEdgeThresholds(thresholds, pMb, flags,
+                    pMb->chromaQpIndexOffset);
+                data = image->data + picSizeInMbs * 256 +
+                    mbRow * picWidthInMbs * 64 + mbCol * 8;
+
+                FilterChroma((u8*)data, data + 64*picSizeInMbs, bS,
+                        thresholds, picWidthInMbs*8);
+
+            }
+        }
+
+        mbCol++;
+        if (mbCol == picWidthInMbs)
+        {
+            mbCol = 0;
+            mbRow++;
+        }
+    }
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: FilterVerLumaEdge
+
+        Functional description:
+            Filter one vertical 4-pixel luma edge.
+
+------------------------------------------------------------------------------*/
+void FilterVerLumaEdge(
+  u8 *data,
+  u32 bS,
+  edgeThreshold_t *thresholds,
+  u32 imageWidth)
+{
+
+/* Variables */
+
+    i32 delta, tc, tmp;
+    u32 i;
+    u8 p0, q0, p1, q1, p2, q2;
+    u32 tmpFlag;
+    const u8 *clp = h264bsdClip + 512;
+
+/* Code */
+
+    ASSERT(data);
+    ASSERT(bS && bS <= 4);
+    ASSERT(thresholds);
+
+    if (bS < 4)
+    {
+        tc = thresholds->tc0[bS-1];
+        tmp = tc;
+        for (i = 4; i; i--, data += imageWidth)
+        {
+            p1 = data[-2]; p0 = data[-1];
+            q0 = data[0]; q1 = data[1];
+            if ( ((unsigned)ABS(p0-q0) < thresholds->alpha) &&
+                 ((unsigned)ABS(p1-p0) < thresholds->beta)  &&
+                 ((unsigned)ABS(q1-q0) < thresholds->beta) )
+            {
+                p2 = data[-3];
+                q2 = data[2];
+
+                if ((unsigned)ABS(p2-p0) < thresholds->beta)
+                {
+                    data[-2] = (u8)(p1 + CLIP3(-tc,tc,
+                        (p2 + ((p0 + q0 + 1) >> 1) - (p1 << 1)) >> 1));
+                    tmp++;
+                }
+
+                if ((unsigned)ABS(q2-q0) < thresholds->beta)
+                {
+                    data[1] = (u8)(q1 + CLIP3(-tc,tc,
+                        (q2 + ((p0 + q0 + 1) >> 1) - (q1 << 1)) >> 1));
+                    tmp++;
+                }
+
+                delta = CLIP3(-tmp, tmp, ((((q0 - p0) << 2) +
+                          (p1 - q1) + 4) >> 3));
+
+                p0 = clp[p0 + delta];
+                q0 = clp[q0 - delta];
+                tmp = tc;
+                data[-1] = p0;
+                data[ 0] = q0;
+            }
+        }
+    }
+    else
+    {
+        for (i = 4; i; i--, data += imageWidth)
+        {
+            p1 = data[-2]; p0 = data[-1];
+            q0 = data[0]; q1 = data[1];
+            if ( ((unsigned)ABS(p0-q0) < thresholds->alpha) &&
+                 ((unsigned)ABS(p1-p0) < thresholds->beta)  &&
+                 ((unsigned)ABS(q1-q0) < thresholds->beta) )
+            {
+                tmpFlag =
+                    ((unsigned)ABS(p0-q0) < ((thresholds->alpha >> 2) +2)) ?
+                        HANTRO_TRUE : HANTRO_FALSE;
+
+                p2 = data[-3];
+                q2 = data[2];
+
+                if (tmpFlag && (unsigned)ABS(p2-p0) < thresholds->beta)
+                {
+                    tmp = p1 + p0 + q0;
+                    data[-1] = (u8)((p2 + 2 * tmp + q1 + 4) >> 3);
+                    data[-2] = (u8)((p2 + tmp + 2) >> 2);
+                    data[-3] = (u8)((2 * data[-4] + 3 * p2 + tmp + 4) >> 3);
+                }
+                else
+                    data[-1] = (2 * p1 + p0 + q1 + 2) >> 2;
+
+                if (tmpFlag && (unsigned)ABS(q2-q0) < thresholds->beta)
+                {
+                    tmp = p0 + q0 + q1;
+                    data[0] = (u8)((p1 + 2 * tmp + q2 + 4) >> 3);
+                    data[1] = (u8)((tmp + q2 + 2) >> 2);
+                    data[2] = (u8)((2 * data[3] + 3 * q2 + tmp + 4) >> 3);
+                }
+                else
+                    data[0] = (u8)((2 * q1 + q0 + p1 + 2) >> 2);
+            }
+        }
+    }
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: FilterHorLumaEdge
+
+        Functional description:
+            Filter one horizontal 4-pixel luma edge
+
+------------------------------------------------------------------------------*/
+void FilterHorLumaEdge(
+  u8 *data,
+  u32 bS,
+  edgeThreshold_t *thresholds,
+  i32 imageWidth)
+{
+
+/* Variables */
+
+    i32 delta, tc, tmp;
+    u32 i;
+    u8 p0, q0, p1, q1, p2, q2;
+    const u8 *clp = h264bsdClip + 512;
+
+/* Code */
+
+    ASSERT(data);
+    ASSERT(bS < 4);
+    ASSERT(thresholds);
+
+    tc = thresholds->tc0[bS-1];
+    tmp = tc;
+    for (i = 4; i; i--, data++)
+    {
+        p1 = data[-imageWidth*2]; p0 = data[-imageWidth];
+        q0 = data[0]; q1 = data[imageWidth];
+        if ( ((unsigned)ABS(p0-q0) < thresholds->alpha) &&
+             ((unsigned)ABS(p1-p0) < thresholds->beta)  &&
+             ((unsigned)ABS(q1-q0) < thresholds->beta) )
+        {
+            p2 = data[-imageWidth*3];
+
+            if ((unsigned)ABS(p2-p0) < thresholds->beta)
+            {
+                data[-imageWidth*2] = (u8)(p1 + CLIP3(-tc,tc,
+                    (p2 + ((p0 + q0 + 1) >> 1) - (p1 << 1)) >> 1));
+                tmp++;
+            }
+
+            q2 = data[imageWidth*2];
+
+            if ((unsigned)ABS(q2-q0) < thresholds->beta)
+            {
+                data[imageWidth] = (u8)(q1 + CLIP3(-tc,tc,
+                    (q2 + ((p0 + q0 + 1) >> 1) - (q1 << 1)) >> 1));
+                tmp++;
+            }
+
+            delta = CLIP3(-tmp, tmp, ((((q0 - p0) << 2) +
+                      (p1 - q1) + 4) >> 3));
+
+            p0 = clp[p0 + delta];
+            q0 = clp[q0 - delta];
+            tmp = tc;
+            data[-imageWidth] = p0;
+            data[  0] = q0;
+        }
+    }
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: FilterHorLuma
+
+        Functional description:
+            Filter all four successive horizontal 4-pixel luma edges. This can
+            be done when bS is equal to all four edges.
+
+------------------------------------------------------------------------------*/
+void FilterHorLuma(
+  u8 *data,
+  u32 bS,
+  edgeThreshold_t *thresholds,
+  i32 imageWidth)
+{
+
+/* Variables */
+
+    i32 delta, tc, tmp;
+    u32 i;
+    u8 p0, q0, p1, q1, p2, q2;
+    u32 tmpFlag;
+    const u8 *clp = h264bsdClip + 512;
+
+/* Code */
+
+    ASSERT(data);
+    ASSERT(bS <= 4);
+    ASSERT(thresholds);
+
+    if (bS < 4)
+    {
+        tc = thresholds->tc0[bS-1];
+        tmp = tc;
+        for (i = 16; i; i--, data++)
+        {
+            p1 = data[-imageWidth*2]; p0 = data[-imageWidth];
+            q0 = data[0]; q1 = data[imageWidth];
+            if ( ((unsigned)ABS(p0-q0) < thresholds->alpha) &&
+                 ((unsigned)ABS(p1-p0) < thresholds->beta)  &&
+                 ((unsigned)ABS(q1-q0) < thresholds->beta) )
+            {
+                p2 = data[-imageWidth*3];
+
+                if ((unsigned)ABS(p2-p0) < thresholds->beta)
+                {
+                    data[-imageWidth*2] = (u8)(p1 + CLIP3(-tc,tc,
+                        (p2 + ((p0 + q0 + 1) >> 1) - (p1 << 1)) >> 1));
+                    tmp++;
+                }
+
+                q2 = data[imageWidth*2];
+
+                if ((unsigned)ABS(q2-q0) < thresholds->beta)
+                {
+                    data[imageWidth] = (u8)(q1 + CLIP3(-tc,tc,
+                        (q2 + ((p0 + q0 + 1) >> 1) - (q1 << 1)) >> 1));
+                    tmp++;
+                }
+
+                delta = CLIP3(-tmp, tmp, ((((q0 - p0) << 2) +
+                          (p1 - q1) + 4) >> 3));
+
+                p0 = clp[p0 + delta];
+                q0 = clp[q0 - delta];
+                tmp = tc;
+                data[-imageWidth] = p0;
+                data[  0] = q0;
+            }
+        }
+    }
+    else
+    {
+        for (i = 16; i; i--, data++)
+        {
+            p1 = data[-imageWidth*2]; p0 = data[-imageWidth];
+            q0 = data[0]; q1 = data[imageWidth];
+            if ( ((unsigned)ABS(p0-q0) < thresholds->alpha) &&
+                 ((unsigned)ABS(p1-p0) < thresholds->beta)  &&
+                 ((unsigned)ABS(q1-q0) < thresholds->beta) )
+            {
+                tmpFlag = ((unsigned)ABS(p0-q0) < ((thresholds->alpha >> 2) +2))
+                            ? HANTRO_TRUE : HANTRO_FALSE;
+
+                p2 = data[-imageWidth*3];
+                q2 = data[imageWidth*2];
+
+                if (tmpFlag && (unsigned)ABS(p2-p0) < thresholds->beta)
+                {
+                    tmp = p1 + p0 + q0;
+                    data[-imageWidth] = (u8)((p2 + 2 * tmp + q1 + 4) >> 3);
+                    data[-imageWidth*2] = (u8)((p2 + tmp + 2) >> 2);
+                    data[-imageWidth*3] = (u8)((2 * data[-imageWidth*4] +
+                                           3 * p2 + tmp + 4) >> 3);
+                }
+                else
+                    data[-imageWidth] = (u8)((2 * p1 + p0 + q1 + 2) >> 2);
+
+                if (tmpFlag && (unsigned)ABS(q2-q0) < thresholds->beta)
+                {
+                    tmp = p0 + q0 + q1;
+                    data[ 0] = (u8)((p1 + 2 * tmp + q2 + 4) >> 3);
+                    data[imageWidth] = (u8)((tmp + q2 + 2) >> 2);
+                    data[imageWidth*2] = (u8)((2 * data[imageWidth*3] +
+                                          3 * q2 + tmp + 4) >> 3);
+                }
+                else
+                    data[0] = (2 * q1 + q0 + p1 + 2) >> 2;
+            }
+        }
+    }
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: FilterVerChromaEdge
+
+        Functional description:
+            Filter one vertical 2-pixel chroma edge
+
+------------------------------------------------------------------------------*/
+void FilterVerChromaEdge(
+  u8 *data,
+  u32 bS,
+  edgeThreshold_t *thresholds,
+  u32 width)
+{
+
+/* Variables */
+
+    i32 delta, tc;
+    u8 p0, q0, p1, q1;
+    const u8 *clp = h264bsdClip + 512;
+
+/* Code */
+
+    ASSERT(data);
+    ASSERT(bS <= 4);
+    ASSERT(thresholds);
+
+    p1 = data[-2]; p0 = data[-1];
+    q0 = data[0]; q1 = data[1];
+    if ( ((unsigned)ABS(p0-q0) < thresholds->alpha) &&
+         ((unsigned)ABS(p1-p0) < thresholds->beta)  &&
+         ((unsigned)ABS(q1-q0) < thresholds->beta) )
+    {
+        if (bS < 4)
+        {
+            tc = thresholds->tc0[bS-1] + 1;
+            delta = CLIP3(-tc, tc, ((((q0 - p0) << 2) +
+                      (p1 - q1) + 4) >> 3));
+            p0 = clp[p0 + delta];
+            q0 = clp[q0 - delta];
+            data[-1] = p0;
+            data[ 0] = q0;
+        }
+        else
+        {
+            data[-1] = (2 * p1 + p0 + q1 + 2) >> 2;
+            data[ 0] = (2 * q1 + q0 + p1 + 2) >> 2;
+        }
+    }
+    data += width;
+    p1 = data[-2]; p0 = data[-1];
+    q0 = data[0]; q1 = data[1];
+    if ( ((unsigned)ABS(p0-q0) < thresholds->alpha) &&
+         ((unsigned)ABS(p1-p0) < thresholds->beta)  &&
+         ((unsigned)ABS(q1-q0) < thresholds->beta) )
+    {
+        if (bS < 4)
+        {
+            tc = thresholds->tc0[bS-1] + 1;
+            delta = CLIP3(-tc, tc, ((((q0 - p0) << 2) +
+                      (p1 - q1) + 4) >> 3));
+            p0 = clp[p0 + delta];
+            q0 = clp[q0 - delta];
+            data[-1] = p0;
+            data[ 0] = q0;
+        }
+        else
+        {
+            data[-1] = (2 * p1 + p0 + q1 + 2) >> 2;
+            data[ 0] = (2 * q1 + q0 + p1 + 2) >> 2;
+        }
+    }
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: FilterHorChromaEdge
+
+        Functional description:
+            Filter one horizontal 2-pixel chroma edge
+
+------------------------------------------------------------------------------*/
+void FilterHorChromaEdge(
+  u8 *data,
+  u32 bS,
+  edgeThreshold_t *thresholds,
+  i32 width)
+{
+
+/* Variables */
+
+    i32 delta, tc;
+    u32 i;
+    u8 p0, q0, p1, q1;
+    const u8 *clp = h264bsdClip + 512;
+
+/* Code */
+
+    ASSERT(data);
+    ASSERT(bS < 4);
+    ASSERT(thresholds);
+
+    tc = thresholds->tc0[bS-1] + 1;
+    for (i = 2; i; i--, data++)
+    {
+        p1 = data[-width*2]; p0 = data[-width];
+        q0 = data[0]; q1 = data[width];
+        if ( ((unsigned)ABS(p0-q0) < thresholds->alpha) &&
+             ((unsigned)ABS(p1-p0) < thresholds->beta)  &&
+             ((unsigned)ABS(q1-q0) < thresholds->beta) )
+        {
+            delta = CLIP3(-tc, tc, ((((q0 - p0) << 2) +
+                      (p1 - q1) + 4) >> 3));
+            p0 = clp[p0 + delta];
+            q0 = clp[q0 - delta];
+            data[-width] = p0;
+            data[  0] = q0;
+        }
+    }
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: FilterHorChroma
+
+        Functional description:
+            Filter all four successive horizontal 2-pixel chroma edges. This
+            can be done if bS is equal for all four edges.
+
+------------------------------------------------------------------------------*/
+void FilterHorChroma(
+  u8 *data,
+  u32 bS,
+  edgeThreshold_t *thresholds,
+  i32 width)
+{
+
+/* Variables */
+
+    i32 delta, tc;
+    u32 i;
+    u8 p0, q0, p1, q1;
+    const u8 *clp = h264bsdClip + 512;
+
+/* Code */
+
+    ASSERT(data);
+    ASSERT(bS <= 4);
+    ASSERT(thresholds);
+
+    if (bS < 4)
+    {
+        tc = thresholds->tc0[bS-1] + 1;
+        for (i = 8; i; i--, data++)
+        {
+            p1 = data[-width*2]; p0 = data[-width];
+            q0 = data[0]; q1 = data[width];
+            if ( ((unsigned)ABS(p0-q0) < thresholds->alpha) &&
+                 ((unsigned)ABS(p1-p0) < thresholds->beta)  &&
+                 ((unsigned)ABS(q1-q0) < thresholds->beta) )
+            {
+                delta = CLIP3(-tc, tc, ((((q0 - p0) << 2) +
+                          (p1 - q1) + 4) >> 3));
+                p0 = clp[p0 + delta];
+                q0 = clp[q0 - delta];
+                data[-width] = p0;
+                data[  0] = q0;
+            }
+        }
+    }
+    else
+    {
+        for (i = 8; i; i--, data++)
+        {
+            p1 = data[-width*2]; p0 = data[-width];
+            q0 = data[0]; q1 = data[width];
+            if ( ((unsigned)ABS(p0-q0) < thresholds->alpha) &&
+                 ((unsigned)ABS(p1-p0) < thresholds->beta)  &&
+                 ((unsigned)ABS(q1-q0) < thresholds->beta) )
+            {
+                    data[-width] = (2 * p1 + p0 + q1 + 2) >> 2;
+                    data[  0] = (2 * q1 + q0 + p1 + 2) >> 2;
+            }
+        }
+    }
+
+}
+
+
+/*------------------------------------------------------------------------------
+
+    Function: GetBoundaryStrengths
+
+        Functional description:
+            Function to calculate boundary strengths for all edges of a
+            macroblock. Function returns HANTRO_TRUE if any of the bS values for
+            the macroblock had non-zero value, HANTRO_FALSE otherwise.
+
+------------------------------------------------------------------------------*/
+u32 GetBoundaryStrengths(mbStorage_t *mb, bS_t *bS, u32 flags)
+{
+
+/* Variables */
+
+    /* this flag is set HANTRO_TRUE as soon as any boundary strength value is
+     * non-zero */
+    u32 nonZeroBs = HANTRO_FALSE;
+
+/* Code */
+
+    ASSERT(mb);
+    ASSERT(bS);
+    ASSERT(flags);
+
+    /* top edges */
+    if (flags & FILTER_TOP_EDGE)
+    {
+        if (IS_INTRA_MB(*mb) || IS_INTRA_MB(*mb->mbB))
+        {
+            bS[0].top = bS[1].top = bS[2].top = bS[3].top = 4;
+            nonZeroBs = HANTRO_TRUE;
+        }
+        else
+        {
+            bS[0].top = EdgeBoundaryStrength(mb, mb->mbB, 0, 10);
+            bS[1].top = EdgeBoundaryStrength(mb, mb->mbB, 1, 11);
+            bS[2].top = EdgeBoundaryStrength(mb, mb->mbB, 4, 14);
+            bS[3].top = EdgeBoundaryStrength(mb, mb->mbB, 5, 15);
+            if (bS[0].top || bS[1].top || bS[2].top || bS[3].top)
+                nonZeroBs = HANTRO_TRUE;
+        }
+    }
+    else
+    {
+        bS[0].top = bS[1].top = bS[2].top = bS[3].top = 0;
+    }
+
+    /* left edges */
+    if (flags & FILTER_LEFT_EDGE)
+    {
+        if (IS_INTRA_MB(*mb) || IS_INTRA_MB(*mb->mbA))
+        {
+            bS[0].left = bS[4].left = bS[8].left = bS[12].left = 4;
+            nonZeroBs = HANTRO_TRUE;
+        }
+        else
+        {
+            bS[0].left = EdgeBoundaryStrength(mb, mb->mbA, 0, 5);
+            bS[4].left = EdgeBoundaryStrength(mb, mb->mbA, 2, 7);
+            bS[8].left = EdgeBoundaryStrength(mb, mb->mbA, 8, 13);
+            bS[12].left = EdgeBoundaryStrength(mb, mb->mbA, 10, 15);
+            if (!nonZeroBs &&
+                (bS[0].left || bS[4].left || bS[8].left || bS[12].left))
+                nonZeroBs = HANTRO_TRUE;
+        }
+    }
+    else
+    {
+        bS[0].left = bS[4].left = bS[8].left = bS[12].left = 0;
+    }
+
+    /* inner edges */
+    if (IS_INTRA_MB(*mb))
+    {
+        bS[4].top  = bS[5].top  = bS[6].top  = bS[7].top  =
+        bS[8].top  = bS[9].top  = bS[10].top = bS[11].top =
+        bS[12].top = bS[13].top = bS[14].top = bS[15].top = 3;
+
+        bS[1].left  = bS[2].left  = bS[3].left  =
+        bS[5].left  = bS[6].left  = bS[7].left  =
+        bS[9].left  = bS[10].left = bS[11].left =
+        bS[13].left = bS[14].left = bS[15].left = 3;
+        nonZeroBs = HANTRO_TRUE;
+    }
+    else
+    {
+        /* 16x16 inter mb -> ref addresses or motion vectors cannot differ,
+         * only check if either of the blocks contain coefficients */
+        if (h264bsdNumMbPart(mb->mbType) == 1)
+        {
+            bS[4].top = mb->totalCoeff[2] || mb->totalCoeff[0] ? 2 : 0;
+            bS[5].top = mb->totalCoeff[3] || mb->totalCoeff[1] ? 2 : 0;
+            bS[6].top = mb->totalCoeff[6] || mb->totalCoeff[4] ? 2 : 0;
+            bS[7].top = mb->totalCoeff[7] || mb->totalCoeff[5] ? 2 : 0;
+            bS[8].top = mb->totalCoeff[8] || mb->totalCoeff[2] ? 2 : 0;
+            bS[9].top = mb->totalCoeff[9] || mb->totalCoeff[3] ? 2 : 0;
+            bS[10].top = mb->totalCoeff[12] || mb->totalCoeff[6] ? 2 : 0;
+            bS[11].top = mb->totalCoeff[13] || mb->totalCoeff[7] ? 2 : 0;
+            bS[12].top = mb->totalCoeff[10] || mb->totalCoeff[8] ? 2 : 0;
+            bS[13].top = mb->totalCoeff[11] || mb->totalCoeff[9] ? 2 : 0;
+            bS[14].top = mb->totalCoeff[14] || mb->totalCoeff[12] ? 2 : 0;
+            bS[15].top = mb->totalCoeff[15] || mb->totalCoeff[13] ? 2 : 0;
+
+            bS[1].left = mb->totalCoeff[1] || mb->totalCoeff[0] ? 2 : 0;
+            bS[2].left = mb->totalCoeff[4] || mb->totalCoeff[1] ? 2 : 0;
+            bS[3].left = mb->totalCoeff[5] || mb->totalCoeff[4] ? 2 : 0;
+            bS[5].left = mb->totalCoeff[3] || mb->totalCoeff[2] ? 2 : 0;
+            bS[6].left = mb->totalCoeff[6] || mb->totalCoeff[3] ? 2 : 0;
+            bS[7].left = mb->totalCoeff[7] || mb->totalCoeff[6] ? 2 : 0;
+            bS[9].left = mb->totalCoeff[9] || mb->totalCoeff[8] ? 2 : 0;
+            bS[10].left = mb->totalCoeff[12] || mb->totalCoeff[9] ? 2 : 0;
+            bS[11].left = mb->totalCoeff[13] || mb->totalCoeff[12] ? 2 : 0;
+            bS[13].left = mb->totalCoeff[11] || mb->totalCoeff[10] ? 2 : 0;
+            bS[14].left = mb->totalCoeff[14] || mb->totalCoeff[11] ? 2 : 0;
+            bS[15].left = mb->totalCoeff[15] || mb->totalCoeff[14] ? 2 : 0;
+        }
+        /* 16x8 inter mb -> ref addresses and motion vectors can be different
+         * only for the middle horizontal edge, for the other top edges it is
+         * enough to check whether the blocks contain coefficients or not. The
+         * same applies to all internal left edges. */
+        else if (mb->mbType == P_L0_L0_16x8)
+        {
+            bS[4].top = mb->totalCoeff[2] || mb->totalCoeff[0] ? 2 : 0;
+            bS[5].top = mb->totalCoeff[3] || mb->totalCoeff[1] ? 2 : 0;
+            bS[6].top = mb->totalCoeff[6] || mb->totalCoeff[4] ? 2 : 0;
+            bS[7].top = mb->totalCoeff[7] || mb->totalCoeff[5] ? 2 : 0;
+            bS[12].top = mb->totalCoeff[10] || mb->totalCoeff[8] ? 2 : 0;
+            bS[13].top = mb->totalCoeff[11] || mb->totalCoeff[9] ? 2 : 0;
+            bS[14].top = mb->totalCoeff[14] || mb->totalCoeff[12] ? 2 : 0;
+            bS[15].top = mb->totalCoeff[15] || mb->totalCoeff[13] ? 2 : 0;
+            bS[8].top = InnerBoundaryStrength(mb, 8, 2);
+            bS[9].top = InnerBoundaryStrength(mb, 9, 3);
+            bS[10].top = InnerBoundaryStrength(mb, 12, 6);
+            bS[11].top = InnerBoundaryStrength(mb, 13, 7);
+
+            bS[1].left = mb->totalCoeff[1] || mb->totalCoeff[0] ? 2 : 0;
+            bS[2].left = mb->totalCoeff[4] || mb->totalCoeff[1] ? 2 : 0;
+            bS[3].left = mb->totalCoeff[5] || mb->totalCoeff[4] ? 2 : 0;
+            bS[5].left = mb->totalCoeff[3] || mb->totalCoeff[2] ? 2 : 0;
+            bS[6].left = mb->totalCoeff[6] || mb->totalCoeff[3] ? 2 : 0;
+            bS[7].left = mb->totalCoeff[7] || mb->totalCoeff[6] ? 2 : 0;
+            bS[9].left = mb->totalCoeff[9] || mb->totalCoeff[8] ? 2 : 0;
+            bS[10].left = mb->totalCoeff[12] || mb->totalCoeff[9] ? 2 : 0;
+            bS[11].left = mb->totalCoeff[13] || mb->totalCoeff[12] ? 2 : 0;
+            bS[13].left = mb->totalCoeff[11] || mb->totalCoeff[10] ? 2 : 0;
+            bS[14].left = mb->totalCoeff[14] || mb->totalCoeff[11] ? 2 : 0;
+            bS[15].left = mb->totalCoeff[15] || mb->totalCoeff[14] ? 2 : 0;
+        }
+        /* 8x16 inter mb -> ref addresses and motion vectors can be different
+         * only for the middle vertical edge, for the other left edges it is
+         * enough to check whether the blocks contain coefficients or not. The
+         * same applies to all internal top edges. */
+        else if (mb->mbType == P_L0_L0_8x16)
+        {
+            bS[4].top = mb->totalCoeff[2] || mb->totalCoeff[0] ? 2 : 0;
+            bS[5].top = mb->totalCoeff[3] || mb->totalCoeff[1] ? 2 : 0;
+            bS[6].top = mb->totalCoeff[6] || mb->totalCoeff[4] ? 2 : 0;
+            bS[7].top = mb->totalCoeff[7] || mb->totalCoeff[5] ? 2 : 0;
+            bS[8].top = mb->totalCoeff[8] || mb->totalCoeff[2] ? 2 : 0;
+            bS[9].top = mb->totalCoeff[9] || mb->totalCoeff[3] ? 2 : 0;
+            bS[10].top = mb->totalCoeff[12] || mb->totalCoeff[6] ? 2 : 0;
+            bS[11].top = mb->totalCoeff[13] || mb->totalCoeff[7] ? 2 : 0;
+            bS[12].top = mb->totalCoeff[10] || mb->totalCoeff[8] ? 2 : 0;
+            bS[13].top = mb->totalCoeff[11] || mb->totalCoeff[9] ? 2 : 0;
+            bS[14].top = mb->totalCoeff[14] || mb->totalCoeff[12] ? 2 : 0;
+            bS[15].top = mb->totalCoeff[15] || mb->totalCoeff[13] ? 2 : 0;
+
+            bS[1].left = mb->totalCoeff[1] || mb->totalCoeff[0] ? 2 : 0;
+            bS[3].left = mb->totalCoeff[5] || mb->totalCoeff[4] ? 2 : 0;
+            bS[5].left = mb->totalCoeff[3] || mb->totalCoeff[2] ? 2 : 0;
+            bS[7].left = mb->totalCoeff[7] || mb->totalCoeff[6] ? 2 : 0;
+            bS[9].left = mb->totalCoeff[9] || mb->totalCoeff[8] ? 2 : 0;
+            bS[11].left = mb->totalCoeff[13] || mb->totalCoeff[12] ? 2 : 0;
+            bS[13].left = mb->totalCoeff[11] || mb->totalCoeff[10] ? 2 : 0;
+            bS[15].left = mb->totalCoeff[15] || mb->totalCoeff[14] ? 2 : 0;
+            bS[2].left = InnerBoundaryStrength(mb, 4, 1);
+            bS[6].left = InnerBoundaryStrength(mb, 6, 3);
+            bS[10].left = InnerBoundaryStrength(mb, 12, 9);
+            bS[14].left = InnerBoundaryStrength(mb, 14, 11);
+        }
+        else
+        {
+            bS[4].top =
+                InnerBoundaryStrength(mb, mb4x4Index[4], mb4x4Index[0]);
+            bS[5].top =
+                InnerBoundaryStrength(mb, mb4x4Index[5], mb4x4Index[1]);
+            bS[6].top =
+                InnerBoundaryStrength(mb, mb4x4Index[6], mb4x4Index[2]);
+            bS[7].top =
+                InnerBoundaryStrength(mb, mb4x4Index[7], mb4x4Index[3]);
+            bS[8].top =
+                InnerBoundaryStrength(mb, mb4x4Index[8], mb4x4Index[4]);
+            bS[9].top =
+                InnerBoundaryStrength(mb, mb4x4Index[9], mb4x4Index[5]);
+            bS[10].top =
+                InnerBoundaryStrength(mb, mb4x4Index[10], mb4x4Index[6]);
+            bS[11].top =
+                InnerBoundaryStrength(mb, mb4x4Index[11], mb4x4Index[7]);
+            bS[12].top =
+                InnerBoundaryStrength(mb, mb4x4Index[12], mb4x4Index[8]);
+            bS[13].top =
+                InnerBoundaryStrength(mb, mb4x4Index[13], mb4x4Index[9]);
+            bS[14].top =
+                InnerBoundaryStrength(mb, mb4x4Index[14], mb4x4Index[10]);
+            bS[15].top =
+                InnerBoundaryStrength(mb, mb4x4Index[15], mb4x4Index[11]);
+
+            bS[1].left =
+                InnerBoundaryStrength(mb, mb4x4Index[1], mb4x4Index[0]);
+            bS[2].left =
+                InnerBoundaryStrength(mb, mb4x4Index[2], mb4x4Index[1]);
+            bS[3].left =
+                InnerBoundaryStrength(mb, mb4x4Index[3], mb4x4Index[2]);
+            bS[5].left =
+                InnerBoundaryStrength(mb, mb4x4Index[5], mb4x4Index[4]);
+            bS[6].left =
+                InnerBoundaryStrength(mb, mb4x4Index[6], mb4x4Index[5]);
+            bS[7].left =
+                InnerBoundaryStrength(mb, mb4x4Index[7], mb4x4Index[6]);
+            bS[9].left =
+                InnerBoundaryStrength(mb, mb4x4Index[9], mb4x4Index[8]);
+            bS[10].left =
+                InnerBoundaryStrength(mb, mb4x4Index[10], mb4x4Index[9]);
+            bS[11].left =
+                InnerBoundaryStrength(mb, mb4x4Index[11], mb4x4Index[10]);
+            bS[13].left =
+                InnerBoundaryStrength(mb, mb4x4Index[13], mb4x4Index[12]);
+            bS[14].left =
+                InnerBoundaryStrength(mb, mb4x4Index[14], mb4x4Index[13]);
+            bS[15].left =
+                InnerBoundaryStrength(mb, mb4x4Index[15], mb4x4Index[14]);
+        }
+        if (!nonZeroBs &&
+            (bS[4].top || bS[5].top || bS[6].top || bS[7].top ||
+             bS[8].top || bS[9].top || bS[10].top || bS[11].top ||
+             bS[12].top || bS[13].top || bS[14].top || bS[15].top ||
+             bS[1].left || bS[2].left || bS[3].left ||
+             bS[5].left || bS[6].left || bS[7].left ||
+             bS[9].left || bS[10].left || bS[11].left ||
+             bS[13].left || bS[14].left || bS[15].left))
+            nonZeroBs = HANTRO_TRUE;
+    }
+
+    return(nonZeroBs);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: GetLumaEdgeThresholds
+
+        Functional description:
+            Compute alpha, beta and tc0 thresholds for inner, left and top
+            luma edges of a macroblock.
+
+------------------------------------------------------------------------------*/
+void GetLumaEdgeThresholds(
+  edgeThreshold_t *thresholds,
+  mbStorage_t *mb,
+  u32 filteringFlags)
+{
+
+/* Variables */
+
+    u32 indexA, indexB;
+    u32 qpAv, qp, qpTmp;
+
+/* Code */
+
+    ASSERT(thresholds);
+    ASSERT(mb);
+
+    qp = mb->qpY;
+
+    indexA = (u32)CLIP3(0, 51, (i32)qp + mb->filterOffsetA);
+    indexB = (u32)CLIP3(0, 51, (i32)qp + mb->filterOffsetB);
+
+    thresholds[INNER].alpha = alphas[indexA];
+    thresholds[INNER].beta = betas[indexB];
+    thresholds[INNER].tc0 = tc0[indexA];
+
+    if (filteringFlags & FILTER_TOP_EDGE)
+    {
+        qpTmp = mb->mbB->qpY;
+        if (qpTmp != qp)
+        {
+            qpAv = (qp + qpTmp + 1) >> 1;
+
+            indexA = (u32)CLIP3(0, 51, (i32)qpAv + mb->filterOffsetA);
+            indexB = (u32)CLIP3(0, 51, (i32)qpAv + mb->filterOffsetB);
+
+            thresholds[TOP].alpha = alphas[indexA];
+            thresholds[TOP].beta = betas[indexB];
+            thresholds[TOP].tc0 = tc0[indexA];
+        }
+        else
+        {
+            thresholds[TOP].alpha = thresholds[INNER].alpha;
+            thresholds[TOP].beta = thresholds[INNER].beta;
+            thresholds[TOP].tc0 = thresholds[INNER].tc0;
+        }
+    }
+    if (filteringFlags & FILTER_LEFT_EDGE)
+    {
+        qpTmp = mb->mbA->qpY;
+        if (qpTmp != qp)
+        {
+            qpAv = (qp + qpTmp + 1) >> 1;
+
+            indexA = (u32)CLIP3(0, 51, (i32)qpAv + mb->filterOffsetA);
+            indexB = (u32)CLIP3(0, 51, (i32)qpAv + mb->filterOffsetB);
+
+            thresholds[LEFT].alpha = alphas[indexA];
+            thresholds[LEFT].beta = betas[indexB];
+            thresholds[LEFT].tc0 = tc0[indexA];
+        }
+        else
+        {
+            thresholds[LEFT].alpha = thresholds[INNER].alpha;
+            thresholds[LEFT].beta = thresholds[INNER].beta;
+            thresholds[LEFT].tc0 = thresholds[INNER].tc0;
+        }
+    }
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: GetChromaEdgeThresholds
+
+        Functional description:
+            Compute alpha, beta and tc0 thresholds for inner, left and top
+            chroma edges of a macroblock.
+
+------------------------------------------------------------------------------*/
+void GetChromaEdgeThresholds(
+  edgeThreshold_t *thresholds,
+  mbStorage_t *mb,
+  u32 filteringFlags,
+  i32 chromaQpIndexOffset)
+{
+
+/* Variables */
+
+    u32 indexA, indexB;
+    u32 qpAv, qp, qpTmp;
+
+/* Code */
+
+    ASSERT(thresholds);
+    ASSERT(mb);
+
+    qp = mb->qpY;
+    qp = h264bsdQpC[CLIP3(0, 51, (i32)qp + chromaQpIndexOffset)];
+
+    indexA = (u32)CLIP3(0, 51, (i32)qp + mb->filterOffsetA);
+    indexB = (u32)CLIP3(0, 51, (i32)qp + mb->filterOffsetB);
+
+    thresholds[INNER].alpha = alphas[indexA];
+    thresholds[INNER].beta = betas[indexB];
+    thresholds[INNER].tc0 = tc0[indexA];
+
+    if (filteringFlags & FILTER_TOP_EDGE)
+    {
+        qpTmp = mb->mbB->qpY;
+        if (qpTmp != mb->qpY)
+        {
+            qpTmp = h264bsdQpC[CLIP3(0, 51, (i32)qpTmp + chromaQpIndexOffset)];
+            qpAv = (qp + qpTmp + 1) >> 1;
+
+            indexA = (u32)CLIP3(0, 51, (i32)qpAv + mb->filterOffsetA);
+            indexB = (u32)CLIP3(0, 51, (i32)qpAv + mb->filterOffsetB);
+
+            thresholds[TOP].alpha = alphas[indexA];
+            thresholds[TOP].beta = betas[indexB];
+            thresholds[TOP].tc0 = tc0[indexA];
+        }
+        else
+        {
+            thresholds[TOP].alpha = thresholds[INNER].alpha;
+            thresholds[TOP].beta = thresholds[INNER].beta;
+            thresholds[TOP].tc0 = thresholds[INNER].tc0;
+        }
+    }
+    if (filteringFlags & FILTER_LEFT_EDGE)
+    {
+        qpTmp = mb->mbA->qpY;
+        if (qpTmp != mb->qpY)
+        {
+            qpTmp = h264bsdQpC[CLIP3(0, 51, (i32)qpTmp + chromaQpIndexOffset)];
+            qpAv = (qp + qpTmp + 1) >> 1;
+
+            indexA = (u32)CLIP3(0, 51, (i32)qpAv + mb->filterOffsetA);
+            indexB = (u32)CLIP3(0, 51, (i32)qpAv + mb->filterOffsetB);
+
+            thresholds[LEFT].alpha = alphas[indexA];
+            thresholds[LEFT].beta = betas[indexB];
+            thresholds[LEFT].tc0 = tc0[indexA];
+        }
+        else
+        {
+            thresholds[LEFT].alpha = thresholds[INNER].alpha;
+            thresholds[LEFT].beta = thresholds[INNER].beta;
+            thresholds[LEFT].tc0 = thresholds[INNER].tc0;
+        }
+    }
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: FilterLuma
+
+        Functional description:
+            Function to filter all luma edges of a macroblock
+
+------------------------------------------------------------------------------*/
+void FilterLuma(
+  u8 *data,
+  bS_t *bS,
+  edgeThreshold_t *thresholds,
+  u32 width)
+{
+
+/* Variables */
+
+    u32 vblock;
+    bS_t *tmp;
+    u8 *ptr;
+    u32 offset;
+
+/* Code */
+
+    ASSERT(data);
+    ASSERT(bS);
+    ASSERT(thresholds);
+
+    ptr = data;
+    tmp = bS;
+
+    offset  = TOP;
+
+    /* loop block rows, perform filtering for all vertical edges of the block
+     * row first, then filter each horizontal edge of the row */
+    for (vblock = 4; vblock--;)
+    {
+        /* only perform filtering if bS is non-zero, first of the four
+         * FilterVerLumaEdge handles the left edge of the macroblock, others
+         * filter inner edges */
+        if (tmp[0].left)
+            FilterVerLumaEdge(ptr, tmp[0].left, thresholds + LEFT, width);
+        if (tmp[1].left)
+            FilterVerLumaEdge(ptr+4, tmp[1].left, thresholds + INNER, width);
+        if (tmp[2].left)
+            FilterVerLumaEdge(ptr+8, tmp[2].left, thresholds + INNER, width);
+        if (tmp[3].left)
+            FilterVerLumaEdge(ptr+12, tmp[3].left, thresholds + INNER, width);
+
+        /* if bS is equal for all horizontal edges of the row -> perform
+         * filtering with FilterHorLuma, otherwise use FilterHorLumaEdge for
+         * each edge separately. offset variable indicates top macroblock edge
+         * on the first loop round, inner edge for the other rounds */
+        if (tmp[0].top == tmp[1].top && tmp[1].top == tmp[2].top &&
+            tmp[2].top == tmp[3].top)
+        {
+            if(tmp[0].top)
+                FilterHorLuma(ptr, tmp[0].top, thresholds + offset, (i32)width);
+        }
+        else
+        {
+            if(tmp[0].top)
+                FilterHorLumaEdge(ptr, tmp[0].top, thresholds+offset,
+                    (i32)width);
+            if(tmp[1].top)
+                FilterHorLumaEdge(ptr+4, tmp[1].top, thresholds+offset,
+                    (i32)width);
+            if(tmp[2].top)
+                FilterHorLumaEdge(ptr+8, tmp[2].top, thresholds+offset,
+                    (i32)width);
+            if(tmp[3].top)
+                FilterHorLumaEdge(ptr+12, tmp[3].top, thresholds+offset,
+                    (i32)width);
+        }
+
+        /* four pixel rows ahead, i.e. next row of 4x4-blocks */
+        ptr += width*4;
+        tmp += 4;
+        offset = INNER;
+    }
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: FilterChroma
+
+        Functional description:
+            Function to filter all chroma edges of a macroblock
+
+------------------------------------------------------------------------------*/
+void FilterChroma(
+  u8 *dataCb,
+  u8 *dataCr,
+  bS_t *bS,
+  edgeThreshold_t *thresholds,
+  u32 width)
+{
+
+/* Variables */
+
+    u32 vblock;
+    bS_t *tmp;
+    u32 offset;
+
+/* Code */
+
+    ASSERT(dataCb);
+    ASSERT(dataCr);
+    ASSERT(bS);
+    ASSERT(thresholds);
+
+    tmp = bS;
+    offset = TOP;
+
+    /* loop block rows, perform filtering for all vertical edges of the block
+     * row first, then filter each horizontal edge of the row */
+    for (vblock = 0; vblock < 2; vblock++)
+    {
+        /* only perform filtering if bS is non-zero, first two of the four
+         * FilterVerChromaEdge calls handle the left edge of the macroblock,
+         * others filter the inner edge. Note that as chroma uses bS values
+         * determined for luma edges, each bS is used only for 2 pixels of
+         * a 4-pixel edge */
+        if (tmp[0].left)
+        {
+            FilterVerChromaEdge(dataCb, tmp[0].left, thresholds + LEFT, width);
+            FilterVerChromaEdge(dataCr, tmp[0].left, thresholds + LEFT, width);
+        }
+        if (tmp[4].left)
+        {
+            FilterVerChromaEdge(dataCb+2*width, tmp[4].left, thresholds + LEFT,
+                width);
+            FilterVerChromaEdge(dataCr+2*width, tmp[4].left, thresholds + LEFT,
+                width);
+        }
+        if (tmp[2].left)
+        {
+            FilterVerChromaEdge(dataCb+4, tmp[2].left, thresholds + INNER,
+                width);
+            FilterVerChromaEdge(dataCr+4, tmp[2].left, thresholds + INNER,
+                width);
+        }
+        if (tmp[6].left)
+        {
+            FilterVerChromaEdge(dataCb+2*width+4, tmp[6].left,
+                thresholds + INNER, width);
+            FilterVerChromaEdge(dataCr+2*width+4, tmp[6].left,
+                thresholds + INNER, width);
+        }
+
+        /* if bS is equal for all horizontal edges of the row -> perform
+         * filtering with FilterHorChroma, otherwise use FilterHorChromaEdge
+         * for each edge separately. offset variable indicates top macroblock
+         * edge on the first loop round, inner edge for the second */
+        if (tmp[0].top == tmp[1].top && tmp[1].top == tmp[2].top &&
+            tmp[2].top == tmp[3].top)
+        {
+            if(tmp[0].top)
+            {
+                FilterHorChroma(dataCb, tmp[0].top, thresholds+offset,
+                    (i32)width);
+                FilterHorChroma(dataCr, tmp[0].top, thresholds+offset,
+                    (i32)width);
+            }
+        }
+        else
+        {
+            if (tmp[0].top)
+            {
+                FilterHorChromaEdge(dataCb, tmp[0].top, thresholds+offset,
+                    (i32)width);
+                FilterHorChromaEdge(dataCr, tmp[0].top, thresholds+offset,
+                    (i32)width);
+            }
+            if (tmp[1].top)
+            {
+                FilterHorChromaEdge(dataCb+2, tmp[1].top, thresholds+offset,
+                    (i32)width);
+                FilterHorChromaEdge(dataCr+2, tmp[1].top, thresholds+offset,
+                    (i32)width);
+            }
+            if (tmp[2].top)
+            {
+                FilterHorChromaEdge(dataCb+4, tmp[2].top, thresholds+offset,
+                    (i32)width);
+                FilterHorChromaEdge(dataCr+4, tmp[2].top, thresholds+offset,
+                    (i32)width);
+            }
+            if (tmp[3].top)
+            {
+                FilterHorChromaEdge(dataCb+6, tmp[3].top, thresholds+offset,
+                    (i32)width);
+                FilterHorChromaEdge(dataCr+6, tmp[3].top, thresholds+offset,
+                    (i32)width);
+            }
+        }
+
+        tmp += 8;
+        dataCb += width*4;
+        dataCr += width*4;
+        offset = INNER;
+    }
+}
+
+#else /* H264DEC_OMXDL */
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdFilterPicture
+
+        Functional description:
+          Perform deblocking filtering for a picture. Filter does not copy
+          the original picture anywhere but filtering is performed directly
+          on the original image. Parameters controlling the filtering process
+          are computed based on information in macroblock structures of the
+          filtered macroblock, macroblock above and macroblock on the left of
+          the filtered one.
+
+        Inputs:
+          image         pointer to image to be filtered
+          mb            pointer to macroblock data structure of the top-left
+                        macroblock of the picture
+
+        Outputs:
+          image         filtered image stored here
+
+        Returns:
+          none
+
+------------------------------------------------------------------------------*/
+
+/*lint --e{550} Symbol not accessed */
+void h264bsdFilterPicture(
+  image_t *image,
+  mbStorage_t *mb)
+{
+
+/* Variables */
+
+    u32 flags;
+    u32 picSizeInMbs, mbRow, mbCol;
+    u32 picWidthInMbs;
+    u8 *data;
+    mbStorage_t *pMb;
+    u8 bS[2][16];
+    u8 thresholdLuma[2][16];
+    u8 thresholdChroma[2][8];
+    u8 alpha[2][2];
+    u8 beta[2][2];
+    OMXResult res;
+
+/* Code */
+
+    ASSERT(image);
+    ASSERT(mb);
+    ASSERT(image->data);
+    ASSERT(image->width);
+    ASSERT(image->height);
+
+    picWidthInMbs = image->width;
+    data = image->data;
+    picSizeInMbs = picWidthInMbs * image->height;
+
+    pMb = mb;
+
+    for (mbRow = 0, mbCol = 0; mbRow < image->height; pMb++)
+    {
+        flags = GetMbFilteringFlags(pMb);
+
+        if (flags)
+        {
+            /* GetBoundaryStrengths function returns non-zero value if any of
+             * the bS values for the macroblock being processed was non-zero */
+            if (GetBoundaryStrengths(pMb, bS, flags))
+            {
+
+                /* Luma */
+                GetLumaEdgeThresholds(pMb,alpha,beta,thresholdLuma,bS,flags);
+                data = image->data + mbRow * picWidthInMbs * 256 + mbCol * 16;
+
+                res = omxVCM4P10_FilterDeblockingLuma_VerEdge_I( data,
+                                                (OMX_S32)(picWidthInMbs*16),
+                                                (const OMX_U8*)alpha,
+                                                (const OMX_U8*)beta,
+                                                (const OMX_U8*)thresholdLuma,
+                                                (const OMX_U8*)bS );
+
+                res = omxVCM4P10_FilterDeblockingLuma_HorEdge_I( data,
+                                                (OMX_S32)(picWidthInMbs*16),
+                                                (const OMX_U8*)alpha+2,
+                                                (const OMX_U8*)beta+2,
+                                                (const OMX_U8*)thresholdLuma+16,
+                                                (const OMX_U8*)bS+16 );
+                /* Cb */
+                GetChromaEdgeThresholds(pMb, alpha, beta, thresholdChroma,
+                                        bS, flags, pMb->chromaQpIndexOffset);
+                data = image->data + picSizeInMbs * 256 +
+                    mbRow * picWidthInMbs * 64 + mbCol * 8;
+
+                res = omxVCM4P10_FilterDeblockingChroma_VerEdge_I( data,
+                                              (OMX_S32)(picWidthInMbs*8),
+                                              (const OMX_U8*)alpha,
+                                              (const OMX_U8*)beta,
+                                              (const OMX_U8*)thresholdChroma,
+                                              (const OMX_U8*)bS );
+                res = omxVCM4P10_FilterDeblockingChroma_HorEdge_I( data,
+                                              (OMX_S32)(picWidthInMbs*8),
+                                              (const OMX_U8*)alpha+2,
+                                              (const OMX_U8*)beta+2,
+                                              (const OMX_U8*)thresholdChroma+8,
+                                              (const OMX_U8*)bS+16 );
+                /* Cr */
+                data += (picSizeInMbs * 64);
+                res = omxVCM4P10_FilterDeblockingChroma_VerEdge_I( data,
+                                              (OMX_S32)(picWidthInMbs*8),
+                                              (const OMX_U8*)alpha,
+                                              (const OMX_U8*)beta,
+                                              (const OMX_U8*)thresholdChroma,
+                                              (const OMX_U8*)bS );
+                res = omxVCM4P10_FilterDeblockingChroma_HorEdge_I( data,
+                                              (OMX_S32)(picWidthInMbs*8),
+                                              (const OMX_U8*)alpha+2,
+                                              (const OMX_U8*)beta+2,
+                                              (const OMX_U8*)thresholdChroma+8,
+                                              (const OMX_U8*)bS+16 );
+            }
+        }
+
+        mbCol++;
+        if (mbCol == picWidthInMbs)
+        {
+            mbCol = 0;
+            mbRow++;
+        }
+    }
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: GetBoundaryStrengths
+
+        Functional description:
+            Function to calculate boundary strengths for all edges of a
+            macroblock. Function returns HANTRO_TRUE if any of the bS values for
+            the macroblock had non-zero value, HANTRO_FALSE otherwise.
+
+------------------------------------------------------------------------------*/
+u32 GetBoundaryStrengths(mbStorage_t *mb, u8 (*bS)[16], u32 flags)
+{
+
+/* Variables */
+
+    /* this flag is set HANTRO_TRUE as soon as any boundary strength value is
+     * non-zero */
+    u32 nonZeroBs = HANTRO_FALSE;
+    u32 *pTmp;
+    u32 tmp1, tmp2, isIntraMb;
+
+/* Code */
+
+    ASSERT(mb);
+    ASSERT(bS);
+    ASSERT(flags);
+
+    isIntraMb = IS_INTRA_MB(*mb);
+
+    /* top edges */
+    pTmp = (u32*)&bS[1][0];
+    if (flags & FILTER_TOP_EDGE)
+    {
+        if (isIntraMb || IS_INTRA_MB(*mb->mbB))
+        {
+            *pTmp = 0x04040404;
+            nonZeroBs = HANTRO_TRUE;
+        }
+        else
+        {
+            *pTmp = EdgeBoundaryStrengthTop(mb, mb->mbB);
+            if (*pTmp)
+                nonZeroBs = HANTRO_TRUE;
+        }
+    }
+    else
+    {
+        *pTmp = 0;
+    }
+
+    /* left edges */
+    pTmp = (u32*)&bS[0][0];
+    if (flags & FILTER_LEFT_EDGE)
+    {
+        if (isIntraMb || IS_INTRA_MB(*mb->mbA))
+        {
+            /*bS[0][0] = bS[0][1] = bS[0][2] = bS[0][3] = 4;*/
+            *pTmp = 0x04040404;
+            nonZeroBs = HANTRO_TRUE;
+        }
+        else
+        {
+            *pTmp = EdgeBoundaryStrengthLeft(mb, mb->mbA);
+            if (!nonZeroBs && *pTmp)
+                nonZeroBs = HANTRO_TRUE;
+        }
+    }
+    else
+    {
+        *pTmp = 0;
+    }
+
+    /* inner edges */
+    if (isIntraMb)
+    {
+        pTmp++;
+        *pTmp++ = 0x03030303;
+        *pTmp++ = 0x03030303;
+        *pTmp++ = 0x03030303;
+        pTmp++;
+        *pTmp++ = 0x03030303;
+        *pTmp++ = 0x03030303;
+        *pTmp = 0x03030303;
+
+        nonZeroBs = HANTRO_TRUE;
+    }
+    else
+    {
+        pTmp = (u32*)mb->totalCoeff;
+
+        /* 16x16 inter mb -> ref addresses or motion vectors cannot differ,
+         * only check if either of the blocks contain coefficients */
+        if (h264bsdNumMbPart(mb->mbType) == 1)
+        {
+            tmp1 = *pTmp++;
+            tmp2 = *pTmp++;
+            bS[1][4]  = (tmp1 & 0x00FF00FF) ? 2 : 0; /* [2]  || [0] */
+            bS[1][5]  = (tmp1 & 0xFF00FF00) ? 2 : 0; /* [3]  || [1] */
+            bS[0][4]  = (tmp1 & 0x0000FFFF) ? 2 : 0; /* [1]  || [0] */
+            bS[0][5]  = (tmp1 & 0xFFFF0000) ? 2 : 0; /* [3]  || [2] */
+
+            tmp1 = *pTmp++;
+            bS[1][6]  = (tmp2 & 0x00FF00FF) ? 2 : 0; /* [6]  || [4] */
+            bS[1][7]  = (tmp2 & 0xFF00FF00) ? 2 : 0; /* [7]  || [5] */
+            bS[0][12] = (tmp2 & 0x0000FFFF) ? 2 : 0; /* [5]  || [4] */
+            bS[0][13] = (tmp2 & 0xFFFF0000) ? 2 : 0; /* [7]  || [6] */
+            tmp2 = *pTmp;
+            bS[1][12] = (tmp1 & 0x00FF00FF) ? 2 : 0; /* [10] || [8] */
+            bS[1][13] = (tmp1 & 0xFF00FF00) ? 2 : 0; /* [11] || [9] */
+            bS[0][6]  = (tmp1 & 0x0000FFFF) ? 2 : 0; /* [9]  || [8] */
+            bS[0][7]  = (tmp1 & 0xFFFF0000) ? 2 : 0; /* [11] || [10] */
+
+            bS[1][14] = (tmp2 & 0x00FF00FF) ? 2 : 0; /* [14] || [12] */
+            bS[1][15] = (tmp2 & 0xFF00FF00) ? 2 : 0; /* [15] || [13] */
+            bS[0][14] = (tmp2 & 0x0000FFFF) ? 2 : 0; /* [13] || [12] */
+            bS[0][15] = (tmp2 & 0xFFFF0000) ? 2 : 0; /* [15] || [14] */
+
+            {
+            u32 tmp3, tmp4;
+
+            tmp1 = mb->totalCoeff[8];
+            tmp2 = mb->totalCoeff[2];
+            tmp3 = mb->totalCoeff[9];
+            tmp4 = mb->totalCoeff[3];
+
+            bS[1][8] = tmp1 || tmp2 ? 2 : 0;
+            tmp1 = mb->totalCoeff[12];
+            tmp2 = mb->totalCoeff[6];
+            bS[1][9] = tmp3 || tmp4 ? 2 : 0;
+            tmp3 = mb->totalCoeff[13];
+            tmp4 = mb->totalCoeff[7];
+            bS[1][10] = tmp1 || tmp2 ? 2 : 0;
+            tmp1 = mb->totalCoeff[4];
+            tmp2 = mb->totalCoeff[1];
+            bS[1][11] = tmp3 || tmp4 ? 2 : 0;
+            tmp3 = mb->totalCoeff[6];
+            tmp4 = mb->totalCoeff[3];
+            bS[0][8] = tmp1 || tmp2 ? 2 : 0;
+            tmp1 = mb->totalCoeff[12];
+            tmp2 = mb->totalCoeff[9];
+            bS[0][9] = tmp3 || tmp4 ? 2 : 0;
+            tmp3 = mb->totalCoeff[14];
+            tmp4 = mb->totalCoeff[11];
+            bS[0][10] = tmp1 || tmp2 ? 2 : 0;
+            bS[0][11] = tmp3 || tmp4 ? 2 : 0;
+            }
+        }
+
+        /* 16x8 inter mb -> ref addresses and motion vectors can be different
+         * only for the middle horizontal edge, for the other top edges it is
+         * enough to check whether the blocks contain coefficients or not. The
+         * same applies to all internal left edges. */
+        else if (mb->mbType == P_L0_L0_16x8)
+        {
+            tmp1 = *pTmp++;
+            tmp2 = *pTmp++;
+            bS[1][4]  = (tmp1 & 0x00FF00FF) ? 2 : 0; /* [2]  || [0] */
+            bS[1][5]  = (tmp1 & 0xFF00FF00) ? 2 : 0; /* [3]  || [1] */
+            bS[0][4]  = (tmp1 & 0x0000FFFF) ? 2 : 0; /* [1]  || [0] */
+            bS[0][5]  = (tmp1 & 0xFFFF0000) ? 2 : 0; /* [3]  || [2] */
+            tmp1 = *pTmp++;
+            bS[1][6]  = (tmp2 & 0x00FF00FF) ? 2 : 0; /* [6]  || [4] */
+            bS[1][7]  = (tmp2 & 0xFF00FF00) ? 2 : 0; /* [7]  || [5] */
+            bS[0][12] = (tmp2 & 0x0000FFFF) ? 2 : 0; /* [5]  || [4] */
+            bS[0][13] = (tmp2 & 0xFFFF0000) ? 2 : 0; /* [7]  || [6] */
+            tmp2 = *pTmp;
+            bS[1][12] = (tmp1 & 0x00FF00FF) ? 2 : 0; /* [10] || [8] */
+            bS[1][13] = (tmp1 & 0xFF00FF00) ? 2 : 0; /* [11] || [9] */
+            bS[0][6]  = (tmp1 & 0x0000FFFF) ? 2 : 0; /* [9]  || [8] */
+            bS[0][7]  = (tmp1 & 0xFFFF0000) ? 2 : 0; /* [11] || [10] */
+
+            bS[1][14] = (tmp2 & 0x00FF00FF) ? 2 : 0; /* [14] || [12] */
+            bS[1][15] = (tmp2 & 0xFF00FF00) ? 2 : 0; /* [15] || [13] */
+            bS[0][14] = (tmp2 & 0x0000FFFF) ? 2 : 0; /* [13] || [12] */
+            bS[0][15] = (tmp2 & 0xFFFF0000) ? 2 : 0; /* [15] || [14] */
+
+            bS[1][8] = (u8)InnerBoundaryStrength(mb, 8, 2);
+            bS[1][9] = (u8)InnerBoundaryStrength(mb, 9, 3);
+            bS[1][10] = (u8)InnerBoundaryStrength(mb, 12, 6);
+            bS[1][11] = (u8)InnerBoundaryStrength(mb, 13, 7);
+
+            {
+            u32 tmp3, tmp4;
+
+            tmp1 = mb->totalCoeff[4];
+            tmp2 = mb->totalCoeff[1];
+            tmp3 = mb->totalCoeff[6];
+            tmp4 = mb->totalCoeff[3];
+            bS[0][8] = tmp1 || tmp2 ? 2 : 0;
+            tmp1 = mb->totalCoeff[12];
+            tmp2 = mb->totalCoeff[9];
+            bS[0][9] = tmp3 || tmp4 ? 2 : 0;
+            tmp3 = mb->totalCoeff[14];
+            tmp4 = mb->totalCoeff[11];
+            bS[0][10] = tmp1 || tmp2 ? 2 : 0;
+            bS[0][11] = tmp3 || tmp4 ? 2 : 0;
+            }
+        }
+        /* 8x16 inter mb -> ref addresses and motion vectors can be different
+         * only for the middle vertical edge, for the other left edges it is
+         * enough to check whether the blocks contain coefficients or not. The
+         * same applies to all internal top edges. */
+        else if (mb->mbType == P_L0_L0_8x16)
+        {
+            tmp1 = *pTmp++;
+            tmp2 = *pTmp++;
+            bS[1][4]  = (tmp1 & 0x00FF00FF) ? 2 : 0; /* [2]  || [0] */
+            bS[1][5]  = (tmp1 & 0xFF00FF00) ? 2 : 0; /* [3]  || [1] */
+            bS[0][4]  = (tmp1 & 0x0000FFFF) ? 2 : 0; /* [1]  || [0] */
+            bS[0][5]  = (tmp1 & 0xFFFF0000) ? 2 : 0; /* [3]  || [2] */
+            tmp1 = *pTmp++;
+            bS[1][6]  = (tmp2 & 0x00FF00FF) ? 2 : 0; /* [6]  || [4] */
+            bS[1][7]  = (tmp2 & 0xFF00FF00) ? 2 : 0; /* [7]  || [5] */
+            bS[0][12] = (tmp2 & 0x0000FFFF) ? 2 : 0; /* [5]  || [4] */
+            bS[0][13] = (tmp2 & 0xFFFF0000) ? 2 : 0; /* [7]  || [6] */
+            tmp2 = *pTmp;
+            bS[1][12] = (tmp1 & 0x00FF00FF) ? 2 : 0; /* [10] || [8] */
+            bS[1][13] = (tmp1 & 0xFF00FF00) ? 2 : 0; /* [11] || [9] */
+            bS[0][6]  = (tmp1 & 0x0000FFFF) ? 2 : 0; /* [9]  || [8] */
+            bS[0][7]  = (tmp1 & 0xFFFF0000) ? 2 : 0; /* [11] || [10] */
+
+            bS[1][14] = (tmp2 & 0x00FF00FF) ? 2 : 0; /* [14] || [12] */
+            bS[1][15] = (tmp2 & 0xFF00FF00) ? 2 : 0; /* [15] || [13] */
+            bS[0][14] = (tmp2 & 0x0000FFFF) ? 2 : 0; /* [13] || [12] */
+            bS[0][15] = (tmp2 & 0xFFFF0000) ? 2 : 0; /* [15] || [14] */
+
+            bS[0][8] = (u8)InnerBoundaryStrength(mb, 4, 1);
+            bS[0][9] = (u8)InnerBoundaryStrength(mb, 6, 3);
+            bS[0][10] = (u8)InnerBoundaryStrength(mb, 12, 9);
+            bS[0][11] = (u8)InnerBoundaryStrength(mb, 14, 11);
+
+            {
+            u32 tmp3, tmp4;
+
+            tmp1 = mb->totalCoeff[8];
+            tmp2 = mb->totalCoeff[2];
+            tmp3 = mb->totalCoeff[9];
+            tmp4 = mb->totalCoeff[3];
+            bS[1][8] = tmp1 || tmp2 ? 2 : 0;
+            tmp1 = mb->totalCoeff[12];
+            tmp2 = mb->totalCoeff[6];
+            bS[1][9] = tmp3 || tmp4 ? 2 : 0;
+            tmp3 = mb->totalCoeff[13];
+            tmp4 = mb->totalCoeff[7];
+            bS[1][10] = tmp1 || tmp2 ? 2 : 0;
+            bS[1][11] = tmp3 || tmp4 ? 2 : 0;
+            }
+        }
+        else
+        {
+            tmp1 = *pTmp++;
+            bS[1][4] = (tmp1 & 0x00FF00FF) ? 2 : (u8)InnerBoundaryStrength2(mb, 2, 0);
+            bS[1][5] = (tmp1 & 0xFF00FF00) ? 2 : (u8)InnerBoundaryStrength2(mb, 3, 1);
+            bS[0][4] = (tmp1 & 0x0000FFFF) ? 2 : (u8)InnerBoundaryStrength2(mb, 1, 0);
+            bS[0][5] = (tmp1 & 0xFFFF0000) ? 2 : (u8)InnerBoundaryStrength2(mb, 3, 2);
+            tmp1 = *pTmp++;
+            bS[1][6]  = (tmp1 & 0x00FF00FF) ? 2 : (u8)InnerBoundaryStrength2(mb, 6, 4);
+            bS[1][7]  = (tmp1 & 0xFF00FF00) ? 2 : (u8)InnerBoundaryStrength2(mb, 7, 5);
+            bS[0][12] = (tmp1 & 0x0000FFFF) ? 2 : (u8)InnerBoundaryStrength2(mb, 5, 4);
+            bS[0][13] = (tmp1 & 0xFFFF0000) ? 2 : (u8)InnerBoundaryStrength2(mb, 7, 6);
+            tmp1 = *pTmp++;
+            bS[1][12] = (tmp1 & 0x00FF00FF) ? 2 : (u8)InnerBoundaryStrength2(mb, 10, 8);
+            bS[1][13] = (tmp1 & 0xFF00FF00) ? 2 : (u8)InnerBoundaryStrength2(mb, 11, 9);
+            bS[0][6]  = (tmp1 & 0x0000FFFF) ? 2 : (u8)InnerBoundaryStrength2(mb, 9, 8);
+            bS[0][7]  = (tmp1 & 0xFFFF0000) ? 2 : (u8)InnerBoundaryStrength2(mb, 11, 10);
+            tmp1 = *pTmp;
+            bS[1][14] = (tmp1 & 0x00FF00FF) ? 2 : (u8)InnerBoundaryStrength2(mb, 14, 12);
+            bS[1][15] = (tmp1 & 0xFF00FF00) ? 2 : (u8)InnerBoundaryStrength2(mb, 15, 13);
+            bS[0][14] = (tmp1 & 0x0000FFFF) ? 2 : (u8)InnerBoundaryStrength2(mb, 13, 12);
+            bS[0][15] = (tmp1 & 0xFFFF0000) ? 2 : (u8)InnerBoundaryStrength2(mb, 15, 14);
+
+            bS[1][8] = (u8)InnerBoundaryStrength(mb, 8, 2);
+            bS[1][9] = (u8)InnerBoundaryStrength(mb, 9, 3);
+            bS[1][10] = (u8)InnerBoundaryStrength(mb, 12, 6);
+            bS[1][11] = (u8)InnerBoundaryStrength(mb, 13, 7);
+
+            bS[0][8] = (u8)InnerBoundaryStrength(mb, 4, 1);
+            bS[0][9] = (u8)InnerBoundaryStrength(mb, 6, 3);
+            bS[0][10] = (u8)InnerBoundaryStrength(mb, 12, 9);
+            bS[0][11] = (u8)InnerBoundaryStrength(mb, 14, 11);
+        }
+        pTmp = (u32*)&bS[0][0];
+        if (!nonZeroBs && (pTmp[1] || pTmp[2] || pTmp[3] ||
+                           pTmp[5] || pTmp[6] || pTmp[7]) )
+        {
+            nonZeroBs = HANTRO_TRUE;
+        }
+    }
+
+    return(nonZeroBs);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: GetLumaEdgeThresholds
+
+        Functional description:
+            Compute alpha, beta and tc0 thresholds for inner, left and top
+            luma edges of a macroblock.
+
+------------------------------------------------------------------------------*/
+void GetLumaEdgeThresholds(
+    mbStorage_t *mb,
+    u8 (*alpha)[2],
+    u8 (*beta)[2],
+    u8 (*threshold)[16],
+    u8 (*bs)[16],
+    u32 filteringFlags )
+{
+
+/* Variables */
+
+    u32 indexA, indexB;
+    u32 qpAv, qp, qpTmp;
+    u32 i;
+
+/* Code */
+
+    ASSERT(threshold);
+    ASSERT(bs);
+    ASSERT(beta);
+    ASSERT(alpha);
+    ASSERT(mb);
+
+    qp = mb->qpY;
+
+    indexA = (u32)CLIP3(0, 51, (i32)qp + mb->filterOffsetA);
+    indexB = (u32)CLIP3(0, 51, (i32)qp + mb->filterOffsetB);
+
+    /* Internal edge values */
+    alpha[0][1] = alphas[indexA];
+    alpha[1][1] = alphas[indexA];
+    alpha[1][0] = alphas[indexA];
+    alpha[0][0] = alphas[indexA];
+    beta[0][1] = betas[indexB];
+    beta[1][1] = betas[indexB];
+    beta[1][0] = betas[indexB];
+    beta[0][0] = betas[indexB];
+
+    /* vertical scan order */
+    for (i = 0; i < 2; i++)
+    {
+        u32 t1, t2;
+
+        t1 = bs[i][0];
+        t2 = bs[i][1];
+        threshold[i][0]  = (t1) ? tc0[indexA][t1] : 0;
+        t1 = bs[i][2];
+        threshold[i][1]  = (t2) ? tc0[indexA][t2] : 0;
+        t2 = bs[i][3];
+        threshold[i][2]  = (t1) ? tc0[indexA][t1] : 0;
+        t1 = bs[i][4];
+        threshold[i][3]  = (t2) ? tc0[indexA][t2] : 0;
+        t2 = bs[i][5];
+        threshold[i][4]  = (t1) ? tc0[indexA][t1] : 0;
+        t1 = bs[i][6];
+        threshold[i][5]  = (t2) ? tc0[indexA][t2] : 0;
+        t2 = bs[i][7];
+        threshold[i][6]  = (t1) ? tc0[indexA][t1] : 0;
+        t1 = bs[i][8];
+        threshold[i][7]  = (t2) ? tc0[indexA][t2] : 0;
+        t2 = bs[i][9];
+        threshold[i][8]  = (t1) ? tc0[indexA][t1] : 0;
+        t1 = bs[i][10];
+        threshold[i][9]  = (t2) ? tc0[indexA][t2] : 0;
+        t2 = bs[i][11];
+        threshold[i][10] = (t1) ? tc0[indexA][t1] : 0;
+        t1 = bs[i][12];
+        threshold[i][11] = (t2) ? tc0[indexA][t2] : 0;
+        t2 = bs[i][13];
+        threshold[i][12] = (t1) ? tc0[indexA][t1] : 0;
+        t1 = bs[i][14];
+        threshold[i][13] = (t2) ? tc0[indexA][t2] : 0;
+        t2 = bs[i][15];
+        threshold[i][14] = (t1) ? tc0[indexA][t1] : 0;
+        threshold[i][15] = (t2) ? tc0[indexA][t2] : 0;
+    }
+
+    if (filteringFlags & FILTER_TOP_EDGE)
+    {
+        qpTmp = mb->mbB->qpY;
+        if (qpTmp != qp)
+        {
+            u32 t1, t2, t3, t4;
+            qpAv = (qp + qpTmp + 1) >> 1;
+
+            indexA = (u32)CLIP3(0, 51, (i32)qpAv + mb->filterOffsetA);
+            indexB = (u32)CLIP3(0, 51, (i32)qpAv + mb->filterOffsetB);
+
+            alpha[1][0] = alphas[indexA];
+            beta[1][0] = betas[indexB];
+            t1 = bs[1][0];
+            t2 = bs[1][1];
+            t3 = bs[1][2];
+            t4 = bs[1][3];
+            threshold[1][0] = (t1 && (t1 < 4)) ? tc0[indexA][t1] : 0;
+            threshold[1][1] = (t2 && (t2 < 4)) ? tc0[indexA][t2] : 0;
+            threshold[1][2] = (t3 && (t3 < 4)) ? tc0[indexA][t3] : 0;
+            threshold[1][3] = (t4 && (t4 < 4)) ? tc0[indexA][t4] : 0;
+        }
+    }
+    if (filteringFlags & FILTER_LEFT_EDGE)
+    {
+        qpTmp = mb->mbA->qpY;
+        if (qpTmp != qp)
+        {
+            qpAv = (qp + qpTmp + 1) >> 1;
+
+            indexA = (u32)CLIP3(0, 51, (i32)qpAv + mb->filterOffsetA);
+            indexB = (u32)CLIP3(0, 51, (i32)qpAv + mb->filterOffsetB);
+
+            alpha[0][0] = alphas[indexA];
+            beta[0][0] = betas[indexB];
+            threshold[0][0] = (bs[0][0] && (bs[0][0] < 4)) ? tc0[indexA][bs[0][0]] : 0;
+            threshold[0][1] = (bs[0][1] && (bs[0][1] < 4)) ? tc0[indexA][bs[0][1]] : 0;
+            threshold[0][2] = (bs[0][2] && (bs[0][2] < 4)) ? tc0[indexA][bs[0][2]] : 0;
+            threshold[0][3] = (bs[0][3] && (bs[0][3] < 4)) ? tc0[indexA][bs[0][3]] : 0;
+        }
+    }
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: GetChromaEdgeThresholds
+
+        Functional description:
+            Compute alpha, beta and tc0 thresholds for inner, left and top
+            chroma edges of a macroblock.
+
+------------------------------------------------------------------------------*/
+void GetChromaEdgeThresholds(
+    mbStorage_t *mb,
+    u8 (*alpha)[2],
+    u8 (*beta)[2],
+    u8 (*threshold)[8],
+    u8 (*bs)[16],
+    u32 filteringFlags,
+    i32 chromaQpIndexOffset)
+{
+
+/* Variables */
+
+    u32 indexA, indexB;
+    u32 qpAv, qp, qpTmp;
+    u32 i;
+
+/* Code */
+
+    ASSERT(threshold);
+    ASSERT(bs);
+    ASSERT(beta);
+    ASSERT(alpha);
+    ASSERT(mb);
+    ASSERT(mb);
+
+    qp = mb->qpY;
+    qp = h264bsdQpC[CLIP3(0, 51, (i32)qp + chromaQpIndexOffset)];
+
+    indexA = (u32)CLIP3(0, 51, (i32)qp + mb->filterOffsetA);
+    indexB = (u32)CLIP3(0, 51, (i32)qp + mb->filterOffsetB);
+
+    alpha[0][1] = alphas[indexA];
+    alpha[1][1] = alphas[indexA];
+    alpha[1][0] = alphas[indexA];
+    alpha[0][0] = alphas[indexA];
+    beta[0][1] = betas[indexB];
+    beta[1][1] = betas[indexB];
+    beta[1][0] = betas[indexB];
+    beta[0][0] = betas[indexB];
+
+    for (i = 0; i < 2; i++)
+    {
+        u32 t1, t2;
+
+        t1 = bs[i][0];
+        t2 = bs[i][1];
+        threshold[i][0]  = (t1) ? tc0[indexA][t1] : 0;
+        t1 = bs[i][2];
+        threshold[i][1]  = (t2) ? tc0[indexA][t2] : 0;
+        t2 = bs[i][3];
+        threshold[i][2]  = (t1) ? tc0[indexA][t1] : 0;
+        t1 = bs[i][8];
+        threshold[i][3]  = (t2) ? tc0[indexA][t2] : 0;
+        t2 = bs[i][9];
+        threshold[i][4]  = (t1) ? tc0[indexA][t1] : 0;
+        t1 = bs[i][10];
+        threshold[i][5]  = (t2) ? tc0[indexA][t2] : 0;
+        t2 = bs[i][11];
+        threshold[i][6]  = (t1) ? tc0[indexA][t1] : 0;
+        threshold[i][7]  = (t2) ? tc0[indexA][t2] : 0;
+    }
+
+    if (filteringFlags & FILTER_TOP_EDGE)
+    {
+        qpTmp = mb->mbB->qpY;
+        if (qpTmp != mb->qpY)
+        {
+            u32 t1, t2, t3, t4;
+            qpTmp = h264bsdQpC[CLIP3(0, 51, (i32)qpTmp + chromaQpIndexOffset)];
+            qpAv = (qp + qpTmp + 1) >> 1;
+
+            indexA = (u32)CLIP3(0, 51, (i32)qpAv + mb->filterOffsetA);
+            indexB = (u32)CLIP3(0, 51, (i32)qpAv + mb->filterOffsetB);
+
+            alpha[1][0] = alphas[indexA];
+            beta[1][0] = betas[indexB];
+
+            t1 = bs[1][0];
+            t2 = bs[1][1];
+            t3 = bs[1][2];
+            t4 = bs[1][3];
+            threshold[1][0] = (t1) ? tc0[indexA][t1] : 0;
+            threshold[1][1] = (t2) ? tc0[indexA][t2] : 0;
+            threshold[1][2] = (t3) ? tc0[indexA][t3] : 0;
+            threshold[1][3] = (t4) ? tc0[indexA][t4] : 0;
+        }
+    }
+    if (filteringFlags & FILTER_LEFT_EDGE)
+    {
+        qpTmp = mb->mbA->qpY;
+        if (qpTmp != mb->qpY)
+        {
+
+            qpTmp = h264bsdQpC[CLIP3(0, 51, (i32)qpTmp + chromaQpIndexOffset)];
+            qpAv = (qp + qpTmp + 1) >> 1;
+
+            indexA = (u32)CLIP3(0, 51, (i32)qpAv + mb->filterOffsetA);
+            indexB = (u32)CLIP3(0, 51, (i32)qpAv + mb->filterOffsetB);
+
+            alpha[0][0] = alphas[indexA];
+            beta[0][0] = betas[indexB];
+            threshold[0][0] = (bs[0][0]) ? tc0[indexA][bs[0][0]] : 0;
+            threshold[0][1] = (bs[0][1]) ? tc0[indexA][bs[0][1]] : 0;
+            threshold[0][2] = (bs[0][2]) ? tc0[indexA][bs[0][2]] : 0;
+            threshold[0][3] = (bs[0][3]) ? tc0[indexA][bs[0][3]] : 0;
+        }
+    }
+
+}
+
+#endif /* H264DEC_OMXDL */
+
+/*lint +e701 +e702 */
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_deblocking.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_deblocking.h
new file mode 100755
index 0000000..2571dda
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_deblocking.h
@@ -0,0 +1,56 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+    1. Include headers
+    2. Module defines
+    3. Data types
+    4. Function prototypes
+
+------------------------------------------------------------------------------*/
+
+#ifndef H264SWDEC_DEBLOCKING_H
+#define H264SWDEC_DEBLOCKING_H
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "basetype.h"
+#include "h264bsd_image.h"
+#include "h264bsd_macroblock_layer.h"
+
+/*------------------------------------------------------------------------------
+    2. Module defines
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    3. Data types
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    4. Function prototypes
+------------------------------------------------------------------------------*/
+
+void h264bsdFilterPicture(
+  image_t *image,
+  mbStorage_t *mb);
+
+#endif /* #ifdef H264SWDEC_DEBLOCKING_H */
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_decoder.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_decoder.c
new file mode 100644
index 0000000..a816871
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_decoder.c
@@ -0,0 +1,961 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+     1. Include headers
+     2. External compiler flags
+     3. Module defines
+     4. Local function prototypes
+     5. Functions
+          h264bsdInit
+          h264bsdDecode
+          h264bsdShutdown
+          h264bsdCurrentImage
+          h264bsdNextOutputPicture
+          h264bsdPicWidth
+          h264bsdPicHeight
+          h264bsdFlushBuffer
+          h264bsdCheckValidParamSets
+          h264bsdVideoRange
+          h264bsdMatrixCoefficients
+          h264bsdCroppingParams
+
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "h264bsd_decoder.h"
+#include "h264bsd_nal_unit.h"
+#include "h264bsd_byte_stream.h"
+#include "h264bsd_seq_param_set.h"
+#include "h264bsd_pic_param_set.h"
+#include "h264bsd_slice_header.h"
+#include "h264bsd_slice_data.h"
+#include "h264bsd_neighbour.h"
+#include "h264bsd_util.h"
+#include "h264bsd_dpb.h"
+#include "h264bsd_deblocking.h"
+#include "h264bsd_conceal.h"
+
+/*------------------------------------------------------------------------------
+    2. External compiler flags
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+    3. Module defines
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    4. Local function prototypes
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+
+    Function name: h264bsdInit
+
+        Functional description:
+            Initialize the decoder.
+
+        Inputs:
+            noOutputReordering  flag to indicate the decoder that it does not
+                                have to perform reordering of display images.
+
+        Outputs:
+            pStorage            pointer to initialized storage structure
+
+        Returns:
+            none
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdInit(storage_t *pStorage, u32 noOutputReordering)
+{
+
+/* Variables */
+    u32 size;
+/* Code */
+
+    ASSERT(pStorage);
+
+    h264bsdInitStorage(pStorage);
+
+    /* allocate mbLayer to be next multiple of 64 to enable use of
+     * specific NEON optimized "memset" for clearing the structure */
+    size = (sizeof(macroblockLayer_t) + 63) & ~0x3F;
+
+    pStorage->mbLayer = (macroblockLayer_t*)H264SwDecMalloc(size);
+    if (!pStorage->mbLayer)
+        return HANTRO_NOK;
+
+    if (noOutputReordering)
+        pStorage->noReordering = HANTRO_TRUE;
+
+    return HANTRO_OK;
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdDecode
+
+        Functional description:
+            Decode a NAL unit. This function calls other modules to perform
+            tasks like
+                * extract and decode NAL unit from the byte stream
+                * decode parameter sets
+                * decode slice header and slice data
+                * conceal errors in the picture
+                * perform deblocking filtering
+
+            This function contains top level control logic of the decoder.
+
+        Inputs:
+            pStorage        pointer to storage data structure
+            byteStrm        pointer to stream buffer given by application
+            len             length of the buffer in bytes
+            picId           identifier for a picture, assigned by the
+                            application
+
+        Outputs:
+            readBytes       number of bytes read from the stream is stored
+                            here
+
+        Returns:
+            H264BSD_RDY             decoding finished, nothing special
+            H264BSD_PIC_RDY         decoding of a picture finished
+            H264BSD_HDRS_RDY        param sets activated, information like
+                                    picture dimensions etc can be read
+            H264BSD_ERROR           error in decoding
+            H264BSD_PARAM_SET_ERROR serius error in decoding, failed to
+                                    activate param sets
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdDecode(storage_t *pStorage, u8 *byteStrm, u32 len, u32 picId,
+    u32 *readBytes)
+{
+
+/* Variables */
+
+    u32 tmp, ppsId, spsId;
+    i32 picOrderCnt;
+    nalUnit_t nalUnit;
+    seqParamSet_t seqParamSet;
+    picParamSet_t picParamSet;
+    strmData_t strm;
+    u32 accessUnitBoundaryFlag = HANTRO_FALSE;
+    u32 picReady = HANTRO_FALSE;
+
+/* Code */
+
+    ASSERT(pStorage);
+    ASSERT(byteStrm);
+    ASSERT(len);
+    ASSERT(readBytes);
+
+    /* if previous buffer was not finished and same pointer given -> skip NAL
+     * unit extraction */
+    if (pStorage->prevBufNotFinished && byteStrm == pStorage->prevBufPointer)
+    {
+        strm = pStorage->strm[0];
+        strm.pStrmCurrPos = strm.pStrmBuffStart;
+        strm.strmBuffReadBits = strm.bitPosInWord = 0;
+        *readBytes = pStorage->prevBytesConsumed;
+    }
+    else
+    {
+        tmp = h264bsdExtractNalUnit(byteStrm, len, &strm, readBytes);
+        if (tmp != HANTRO_OK)
+        {
+            EPRINT("BYTE_STREAM");
+            return(H264BSD_ERROR);
+        }
+        /* store stream */
+        pStorage->strm[0] = strm;
+        pStorage->prevBytesConsumed = *readBytes;
+        pStorage->prevBufPointer = byteStrm;
+    }
+    pStorage->prevBufNotFinished = HANTRO_FALSE;
+
+    tmp = h264bsdDecodeNalUnit(&strm, &nalUnit);
+    if (tmp != HANTRO_OK)
+    {
+        EPRINT("NAL_UNIT");
+        return(H264BSD_ERROR);
+    }
+
+    /* Discard unspecified, reserved, SPS extension and auxiliary picture slices */
+    if(nalUnit.nalUnitType == 0 || nalUnit.nalUnitType >= 13)
+    {
+        DEBUG(("DISCARDED NAL (UNSPECIFIED, REGISTERED, SPS ext or AUX slice)\n"));
+        return(H264BSD_RDY);
+    }
+
+    tmp = h264bsdCheckAccessUnitBoundary(
+      &strm,
+      &nalUnit,
+      pStorage,
+      &accessUnitBoundaryFlag);
+    if (tmp != HANTRO_OK)
+    {
+        EPRINT("ACCESS UNIT BOUNDARY CHECK");
+        if (tmp == PARAM_SET_ERROR)
+            return(H264BSD_PARAM_SET_ERROR);
+        else
+            return(H264BSD_ERROR);
+    }
+
+    if ( accessUnitBoundaryFlag )
+    {
+        DEBUG(("Access unit boundary\n"));
+        /* conceal if picture started and param sets activated */
+        if (pStorage->picStarted && pStorage->activeSps != NULL)
+        {
+            DEBUG(("CONCEALING..."));
+
+            /* return error if second phase of
+             * initialization is not completed */
+            if (pStorage->pendingActivation)
+            {
+                EPRINT("Pending activation not completed");
+                return (H264BSD_ERROR);
+            }
+
+            if (!pStorage->validSliceInAccessUnit)
+            {
+                pStorage->currImage->data =
+                    h264bsdAllocateDpbImage(pStorage->dpb);
+                h264bsdInitRefPicList(pStorage->dpb);
+                tmp = h264bsdConceal(pStorage, pStorage->currImage, P_SLICE);
+            }
+            else
+                tmp = h264bsdConceal(pStorage, pStorage->currImage,
+                    pStorage->sliceHeader->sliceType);
+
+            picReady = HANTRO_TRUE;
+
+            /* current NAL unit should be decoded on next activation -> set
+             * readBytes to 0 */
+            *readBytes = 0;
+            pStorage->prevBufNotFinished = HANTRO_TRUE;
+            DEBUG(("...DONE\n"));
+        }
+        else
+        {
+            pStorage->validSliceInAccessUnit = HANTRO_FALSE;
+        }
+        pStorage->skipRedundantSlices = HANTRO_FALSE;
+    }
+
+    if (!picReady)
+    {
+        switch (nalUnit.nalUnitType)
+        {
+            case NAL_SEQ_PARAM_SET:
+                DEBUG(("SEQ PARAM SET\n"));
+                tmp = h264bsdDecodeSeqParamSet(&strm, &seqParamSet);
+                if (tmp != HANTRO_OK)
+                {
+                    EPRINT("SEQ_PARAM_SET");
+                    FREE(seqParamSet.offsetForRefFrame);
+                    FREE(seqParamSet.vuiParameters);
+                    return(H264BSD_ERROR);
+                }
+                tmp = h264bsdStoreSeqParamSet(pStorage, &seqParamSet);
+                break;
+
+            case NAL_PIC_PARAM_SET:
+                DEBUG(("PIC PARAM SET\n"));
+                tmp = h264bsdDecodePicParamSet(&strm, &picParamSet);
+                if (tmp != HANTRO_OK)
+                {
+                    EPRINT("PIC_PARAM_SET");
+                    FREE(picParamSet.runLength);
+                    FREE(picParamSet.topLeft);
+                    FREE(picParamSet.bottomRight);
+                    FREE(picParamSet.sliceGroupId);
+                    return(H264BSD_ERROR);
+                }
+                tmp = h264bsdStorePicParamSet(pStorage, &picParamSet);
+                break;
+
+            case NAL_CODED_SLICE_IDR:
+                DEBUG(("IDR "));
+                /* fall through */
+            case NAL_CODED_SLICE:
+                DEBUG(("SLICE HEADER\n"));
+
+                /* picture successfully finished and still decoding same old
+                 * access unit -> no need to decode redundant slices */
+                if (pStorage->skipRedundantSlices)
+                    return(H264BSD_RDY);
+
+                pStorage->picStarted = HANTRO_TRUE;
+
+                if (h264bsdIsStartOfPicture(pStorage))
+                {
+                    pStorage->numConcealedMbs = 0;
+                    pStorage->currentPicId    = picId;
+
+                    tmp = h264bsdCheckPpsId(&strm, &ppsId);
+                    ASSERT(tmp == HANTRO_OK);
+                    /* store old activeSpsId and return headers ready
+                     * indication if activeSps changes */
+                    spsId = pStorage->activeSpsId;
+                    tmp = h264bsdActivateParamSets(pStorage, ppsId,
+                            IS_IDR_NAL_UNIT(&nalUnit) ?
+                            HANTRO_TRUE : HANTRO_FALSE);
+                    if (tmp != HANTRO_OK)
+                    {
+                        EPRINT("Param set activation");
+                        pStorage->activePpsId = MAX_NUM_PIC_PARAM_SETS;
+                        pStorage->activePps = NULL;
+                        pStorage->activeSpsId = MAX_NUM_SEQ_PARAM_SETS;
+                        pStorage->activeSps = NULL;
+                        pStorage->pendingActivation = HANTRO_FALSE;
+
+                        if(tmp == MEMORY_ALLOCATION_ERROR)
+                        {
+                            return H264BSD_MEMALLOC_ERROR;
+                        }
+                        else
+                            return(H264BSD_PARAM_SET_ERROR);
+                    }
+
+                    if (spsId != pStorage->activeSpsId)
+                    {
+                        seqParamSet_t *oldSPS = NULL;
+                        seqParamSet_t *newSPS = pStorage->activeSps;
+                        u32 noOutputOfPriorPicsFlag = 1;
+
+                        if(pStorage->oldSpsId < MAX_NUM_SEQ_PARAM_SETS)
+                        {
+                            oldSPS = pStorage->sps[pStorage->oldSpsId];
+                        }
+
+                        *readBytes = 0;
+                        pStorage->prevBufNotFinished = HANTRO_TRUE;
+
+
+                        if(nalUnit.nalUnitType == NAL_CODED_SLICE_IDR)
+                        {
+                            tmp =
+                            h264bsdCheckPriorPicsFlag(&noOutputOfPriorPicsFlag,
+                                                          &strm, newSPS,
+                                                          pStorage->activePps,
+                                                          nalUnit.nalUnitType);
+                        }
+                        else
+                        {
+                            tmp = HANTRO_NOK;
+                        }
+
+                        if((tmp != HANTRO_OK) ||
+                           (noOutputOfPriorPicsFlag != 0) ||
+                           (pStorage->dpb->noReordering) ||
+                           (oldSPS == NULL) ||
+                           (oldSPS->picWidthInMbs != newSPS->picWidthInMbs) ||
+                           (oldSPS->picHeightInMbs != newSPS->picHeightInMbs) ||
+                           (oldSPS->maxDpbSize != newSPS->maxDpbSize))
+                        {
+                            pStorage->dpb->flushed = 0;
+                        }
+                        else
+                        {
+                            h264bsdFlushDpb(pStorage->dpb);
+                        }
+
+                        pStorage->oldSpsId = pStorage->activeSpsId;
+
+                        return(H264BSD_HDRS_RDY);
+                    }
+                }
+
+                /* return error if second phase of
+                 * initialization is not completed */
+                if (pStorage->pendingActivation)
+                {
+                    EPRINT("Pending activation not completed");
+                    return (H264BSD_ERROR);
+                }
+                tmp = h264bsdDecodeSliceHeader(&strm, pStorage->sliceHeader + 1,
+                    pStorage->activeSps, pStorage->activePps, &nalUnit);
+                if (tmp != HANTRO_OK)
+                {
+                    EPRINT("SLICE_HEADER");
+                    return(H264BSD_ERROR);
+                }
+                if (h264bsdIsStartOfPicture(pStorage))
+                {
+                    if (!IS_IDR_NAL_UNIT(&nalUnit))
+                    {
+                        tmp = h264bsdCheckGapsInFrameNum(pStorage->dpb,
+                            pStorage->sliceHeader[1].frameNum,
+                            nalUnit.nalRefIdc != 0 ?
+                            HANTRO_TRUE : HANTRO_FALSE,
+                            pStorage->activeSps->
+                            gapsInFrameNumValueAllowedFlag);
+                        if (tmp != HANTRO_OK)
+                        {
+                            EPRINT("Gaps in frame num");
+                            return(H264BSD_ERROR);
+                        }
+                    }
+                    pStorage->currImage->data =
+                        h264bsdAllocateDpbImage(pStorage->dpb);
+                }
+
+                /* store slice header to storage if successfully decoded */
+                pStorage->sliceHeader[0] = pStorage->sliceHeader[1];
+                pStorage->validSliceInAccessUnit = HANTRO_TRUE;
+                pStorage->prevNalUnit[0] = nalUnit;
+
+                h264bsdComputeSliceGroupMap(pStorage,
+                    pStorage->sliceHeader->sliceGroupChangeCycle);
+
+                h264bsdInitRefPicList(pStorage->dpb);
+                tmp = h264bsdReorderRefPicList(pStorage->dpb,
+                    &pStorage->sliceHeader->refPicListReordering,
+                    pStorage->sliceHeader->frameNum,
+                    pStorage->sliceHeader->numRefIdxL0Active);
+                if (tmp != HANTRO_OK)
+                {
+                    EPRINT("Reordering");
+                    return(H264BSD_ERROR);
+                }
+
+                DEBUG(("SLICE DATA, FIRST %d\n",
+                        pStorage->sliceHeader->firstMbInSlice));
+                tmp = h264bsdDecodeSliceData(&strm, pStorage,
+                    pStorage->currImage, pStorage->sliceHeader);
+                if (tmp != HANTRO_OK)
+                {
+                    EPRINT("SLICE_DATA");
+                    h264bsdMarkSliceCorrupted(pStorage,
+                        pStorage->sliceHeader->firstMbInSlice);
+                    return(H264BSD_ERROR);
+                }
+
+                if (h264bsdIsEndOfPicture(pStorage))
+                {
+                    picReady = HANTRO_TRUE;
+                    pStorage->skipRedundantSlices = HANTRO_TRUE;
+                }
+                break;
+
+            case NAL_SEI:
+                DEBUG(("SEI MESSAGE, NOT DECODED"));
+                break;
+
+            default:
+                DEBUG(("NOT IMPLEMENTED YET %d\n",nalUnit.nalUnitType));
+        }
+    }
+
+    if (picReady)
+    {
+        h264bsdFilterPicture(pStorage->currImage, pStorage->mb);
+
+        h264bsdResetStorage(pStorage);
+
+        picOrderCnt = h264bsdDecodePicOrderCnt(pStorage->poc,
+            pStorage->activeSps, pStorage->sliceHeader, pStorage->prevNalUnit);
+
+        if (pStorage->validSliceInAccessUnit)
+        {
+            if (pStorage->prevNalUnit->nalRefIdc)
+            {
+                tmp = h264bsdMarkDecRefPic(pStorage->dpb,
+                    &pStorage->sliceHeader->decRefPicMarking,
+                    pStorage->currImage, pStorage->sliceHeader->frameNum,
+                    picOrderCnt,
+                    IS_IDR_NAL_UNIT(pStorage->prevNalUnit) ?
+                    HANTRO_TRUE : HANTRO_FALSE,
+                    pStorage->currentPicId, pStorage->numConcealedMbs);
+            }
+            /* non-reference picture, just store for possible display
+             * reordering */
+            else
+            {
+                tmp = h264bsdMarkDecRefPic(pStorage->dpb, NULL,
+                    pStorage->currImage, pStorage->sliceHeader->frameNum,
+                    picOrderCnt,
+                    IS_IDR_NAL_UNIT(pStorage->prevNalUnit) ?
+                    HANTRO_TRUE : HANTRO_FALSE,
+                    pStorage->currentPicId, pStorage->numConcealedMbs);
+            }
+        }
+
+        pStorage->picStarted = HANTRO_FALSE;
+        pStorage->validSliceInAccessUnit = HANTRO_FALSE;
+
+        return(H264BSD_PIC_RDY);
+    }
+    else
+        return(H264BSD_RDY);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdShutdown
+
+        Functional description:
+            Shutdown a decoder instance. Function frees all the memories
+            allocated for the decoder instance.
+
+        Inputs:
+            pStorage    pointer to storage data structure
+
+        Returns:
+            none
+
+
+------------------------------------------------------------------------------*/
+
+void h264bsdShutdown(storage_t *pStorage)
+{
+
+/* Variables */
+
+    u32 i;
+
+/* Code */
+
+    ASSERT(pStorage);
+
+    for (i = 0; i < MAX_NUM_SEQ_PARAM_SETS; i++)
+    {
+        if (pStorage->sps[i])
+        {
+            FREE(pStorage->sps[i]->offsetForRefFrame);
+            FREE(pStorage->sps[i]->vuiParameters);
+            FREE(pStorage->sps[i]);
+        }
+    }
+
+    for (i = 0; i < MAX_NUM_PIC_PARAM_SETS; i++)
+    {
+        if (pStorage->pps[i])
+        {
+            FREE(pStorage->pps[i]->runLength);
+            FREE(pStorage->pps[i]->topLeft);
+            FREE(pStorage->pps[i]->bottomRight);
+            FREE(pStorage->pps[i]->sliceGroupId);
+            FREE(pStorage->pps[i]);
+        }
+    }
+
+    FREE(pStorage->mbLayer);
+    FREE(pStorage->mb);
+    FREE(pStorage->sliceGroupMap);
+
+    h264bsdFreeDpb(pStorage->dpb);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdNextOutputPicture
+
+        Functional description:
+            Get next output picture in display order.
+
+        Inputs:
+            pStorage    pointer to storage data structure
+
+        Outputs:
+            picId       identifier of the picture will be stored here
+            isIdrPic    IDR flag of the picture will be stored here
+            numErrMbs   number of concealed macroblocks in the picture
+                        will be stored here
+
+        Returns:
+            pointer to the picture data
+            NULL if no pictures available for display
+
+------------------------------------------------------------------------------*/
+
+u8* h264bsdNextOutputPicture(storage_t *pStorage, u32 *picId, u32 *isIdrPic,
+    u32 *numErrMbs)
+{
+
+/* Variables */
+
+    dpbOutPicture_t *pOut;
+
+/* Code */
+
+    ASSERT(pStorage);
+
+    pOut = h264bsdDpbOutputPicture(pStorage->dpb);
+
+    if (pOut != NULL)
+    {
+        *picId = pOut->picId;
+        *isIdrPic = pOut->isIdr;
+        *numErrMbs = pOut->numErrMbs;
+        return (pOut->data);
+    }
+    else
+        return(NULL);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdPicWidth
+
+        Functional description:
+            Get width of the picture in macroblocks
+
+        Inputs:
+            pStorage    pointer to storage data structure
+
+        Outputs:
+            none
+
+        Returns:
+            picture width
+            0 if parameters sets not yet activated
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdPicWidth(storage_t *pStorage)
+{
+
+/* Variables */
+
+/* Code */
+
+    ASSERT(pStorage);
+
+    if (pStorage->activeSps)
+        return(pStorage->activeSps->picWidthInMbs);
+    else
+        return(0);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdPicHeight
+
+        Functional description:
+            Get height of the picture in macroblocks
+
+        Inputs:
+            pStorage    pointer to storage data structure
+
+        Outputs:
+            none
+
+        Returns:
+            picture width
+            0 if parameters sets not yet activated
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdPicHeight(storage_t *pStorage)
+{
+
+/* Variables */
+
+/* Code */
+
+    ASSERT(pStorage);
+
+    if (pStorage->activeSps)
+        return(pStorage->activeSps->picHeightInMbs);
+    else
+        return(0);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdFlushBuffer
+
+        Functional description:
+            Flush the decoded picture buffer, see dpb.c for details
+
+        Inputs:
+            pStorage    pointer to storage data structure
+
+------------------------------------------------------------------------------*/
+
+void h264bsdFlushBuffer(storage_t *pStorage)
+{
+
+/* Variables */
+
+/* Code */
+
+    ASSERT(pStorage);
+
+    h264bsdFlushDpb(pStorage->dpb);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdCheckValidParamSets
+
+        Functional description:
+            Check if any valid parameter set combinations (SPS/PPS) exists.
+
+        Inputs:
+            pStorage    pointer to storage structure
+
+        Returns:
+            1       at least one valid SPS/PPS combination found
+            0       no valid param set combinations found
+
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdCheckValidParamSets(storage_t *pStorage)
+{
+
+/* Variables */
+
+/* Code */
+
+    ASSERT(pStorage);
+
+    return(h264bsdValidParamSets(pStorage) == HANTRO_OK ? 1 : 0);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdVideoRange
+
+        Functional description:
+            Get value of video_full_range_flag received in the VUI data.
+
+        Inputs:
+            pStorage    pointer to storage structure
+
+        Returns:
+            1   video_full_range_flag received and value is 1
+            0   otherwise
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdVideoRange(storage_t *pStorage)
+{
+
+/* Variables */
+
+/* Code */
+
+    ASSERT(pStorage);
+
+    if (pStorage->activeSps && pStorage->activeSps->vuiParametersPresentFlag &&
+        pStorage->activeSps->vuiParameters &&
+        pStorage->activeSps->vuiParameters->videoSignalTypePresentFlag &&
+        pStorage->activeSps->vuiParameters->videoFullRangeFlag)
+        return(1);
+    else /* default value of video_full_range_flag is 0 */
+        return(0);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdMatrixCoefficients
+
+        Functional description:
+            Get value of matrix_coefficients received in the VUI data
+
+        Inputs:
+            pStorage    pointer to storage structure
+
+        Outputs:
+            value of matrix_coefficients if received
+            2   otherwise (this is the default value)
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdMatrixCoefficients(storage_t *pStorage)
+{
+
+/* Variables */
+
+/* Code */
+
+    ASSERT(pStorage);
+
+    if (pStorage->activeSps && pStorage->activeSps->vuiParametersPresentFlag &&
+        pStorage->activeSps->vuiParameters &&
+        pStorage->activeSps->vuiParameters->videoSignalTypePresentFlag &&
+        pStorage->activeSps->vuiParameters->colourDescriptionPresentFlag)
+        return(pStorage->activeSps->vuiParameters->matrixCoefficients);
+    else /* default unspecified */
+        return(2);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: hh264bsdCroppingParams
+
+        Functional description:
+            Get cropping parameters of the active SPS
+
+        Inputs:
+            pStorage    pointer to storage structure
+
+        Outputs:
+            croppingFlag    flag indicating if cropping params present is
+                            stored here
+            leftOffset      cropping left offset in pixels is stored here
+            width           width of the image after cropping is stored here
+            topOffset       cropping top offset in pixels is stored here
+            height          height of the image after cropping is stored here
+
+        Returns:
+            none
+
+------------------------------------------------------------------------------*/
+
+void h264bsdCroppingParams(storage_t *pStorage, u32 *croppingFlag,
+    u32 *leftOffset, u32 *width, u32 *topOffset, u32 *height)
+{
+
+/* Variables */
+
+/* Code */
+
+    ASSERT(pStorage);
+
+    if (pStorage->activeSps && pStorage->activeSps->frameCroppingFlag)
+    {
+        *croppingFlag = 1;
+        *leftOffset = 2 * pStorage->activeSps->frameCropLeftOffset;
+        *width = 16 * pStorage->activeSps->picWidthInMbs -
+                 2 * (pStorage->activeSps->frameCropLeftOffset +
+                      pStorage->activeSps->frameCropRightOffset);
+        *topOffset = 2 * pStorage->activeSps->frameCropTopOffset;
+        *height = 16 * pStorage->activeSps->picHeightInMbs -
+                  2 * (pStorage->activeSps->frameCropTopOffset +
+                       pStorage->activeSps->frameCropBottomOffset);
+    }
+    else
+    {
+        *croppingFlag = 0;
+        *leftOffset = 0;
+        *width = 0;
+        *topOffset = 0;
+        *height = 0;
+    }
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdSampleAspectRatio
+
+        Functional description:
+            Get aspect ratio received in the VUI data
+
+        Inputs:
+            pStorage    pointer to storage structure
+
+        Outputs:
+            sarWidth    sample aspect ratio height
+            sarHeight   sample aspect ratio width
+
+------------------------------------------------------------------------------*/
+
+void h264bsdSampleAspectRatio(storage_t *pStorage, u32 *sarWidth, u32 *sarHeight)
+{
+
+/* Variables */
+    u32 w = 1;
+    u32 h = 1;
+/* Code */
+
+    ASSERT(pStorage);
+
+
+    if (pStorage->activeSps &&
+        pStorage->activeSps->vuiParametersPresentFlag &&
+        pStorage->activeSps->vuiParameters &&
+        pStorage->activeSps->vuiParameters->aspectRatioPresentFlag )
+    {
+        switch (pStorage->activeSps->vuiParameters->aspectRatioIdc)
+        {
+            case ASPECT_RATIO_UNSPECIFIED:  w =   0; h =  0; break;
+            case ASPECT_RATIO_1_1:          w =   1; h =  1; break;
+            case ASPECT_RATIO_12_11:        w =  12; h = 11; break;
+            case ASPECT_RATIO_10_11:        w =  10; h = 11; break;
+            case ASPECT_RATIO_16_11:        w =  16; h = 11; break;
+            case ASPECT_RATIO_40_33:        w =  40; h = 33; break;
+            case ASPECT_RATIO_24_11:        w =  24; h = 11; break;
+            case ASPECT_RATIO_20_11:        w =  20; h = 11; break;
+            case ASPECT_RATIO_32_11:        w =  32; h = 11; break;
+            case ASPECT_RATIO_80_33:        w =  80; h = 33; break;
+            case ASPECT_RATIO_18_11:        w =  18; h = 11; break;
+            case ASPECT_RATIO_15_11:        w =  15; h = 11; break;
+            case ASPECT_RATIO_64_33:        w =  64; h = 33; break;
+            case ASPECT_RATIO_160_99:       w = 160; h = 99; break;
+            case ASPECT_RATIO_EXTENDED_SAR:
+                w = pStorage->activeSps->vuiParameters->sarWidth;
+                h = pStorage->activeSps->vuiParameters->sarHeight;
+                if ((w == 0) || (h == 0))
+                    w = h = 0;
+                break;
+            default:
+                w = 0;
+                h = 0;
+                break;
+        }
+    }
+
+    /* set aspect ratio*/
+    *sarWidth = w;
+    *sarHeight = h;
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdProfile
+
+        Functional description:
+            Get profile information from active SPS
+
+        Inputs:
+            pStorage    pointer to storage structure
+
+        Outputs:
+            profile   current profile
+
+------------------------------------------------------------------------------*/
+u32 h264bsdProfile(storage_t *pStorage)
+{
+    if (pStorage->activeSps)
+        return pStorage->activeSps->profileIdc;
+    else
+        return 0;
+}
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_decoder.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_decoder.h
new file mode 100644
index 0000000..8336523
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_decoder.h
@@ -0,0 +1,83 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+    1. Include headers
+    2. Module defines
+    3. Data types
+    4. Function prototypes
+
+------------------------------------------------------------------------------*/
+
+#ifndef H264SWDEC_DECODER_H
+#define H264SWDEC_DECODER_H
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "basetype.h"
+#include "h264bsd_storage.h"
+
+/*------------------------------------------------------------------------------
+    2. Module defines
+------------------------------------------------------------------------------*/
+
+/* enumerated return values of the functions */
+enum {
+    H264BSD_RDY,
+    H264BSD_PIC_RDY,
+    H264BSD_HDRS_RDY,
+    H264BSD_ERROR,
+    H264BSD_PARAM_SET_ERROR,
+    H264BSD_MEMALLOC_ERROR
+};
+
+/*------------------------------------------------------------------------------
+    3. Data types
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    4. Function prototypes
+------------------------------------------------------------------------------*/
+
+u32 h264bsdInit(storage_t *pStorage, u32 noOutputReordering);
+u32 h264bsdDecode(storage_t *pStorage, u8 *byteStrm, u32 len, u32 picId,
+    u32 *readBytes);
+void h264bsdShutdown(storage_t *pStorage);
+
+u8* h264bsdNextOutputPicture(storage_t *pStorage, u32 *picId, u32 *isIdrPic,
+    u32 *numErrMbs);
+
+u32 h264bsdPicWidth(storage_t *pStorage);
+u32 h264bsdPicHeight(storage_t *pStorage);
+u32 h264bsdVideoRange(storage_t *pStorage);
+u32 h264bsdMatrixCoefficients(storage_t *pStorage);
+void h264bsdCroppingParams(storage_t *pStorage, u32 *croppingFlag,
+    u32 *left, u32 *width, u32 *top, u32 *height);
+void h264bsdSampleAspectRatio(storage_t *pStorage,
+                              u32 *sarWidth, u32 *sarHeight);
+u32 h264bsdCheckValidParamSets(storage_t *pStorage);
+
+void h264bsdFlushBuffer(storage_t *pStorage);
+
+u32 h264bsdProfile(storage_t *pStorage);
+
+#endif /* #ifdef H264SWDEC_DECODER_H */
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_dpb.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_dpb.c
new file mode 100755
index 0000000..9517d0a
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_dpb.c
@@ -0,0 +1,1584 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+     1. Include headers
+     2. External compiler flags
+     3. Module defines
+     4. Local function prototypes
+     5. Functions
+          ComparePictures
+          h264bsdReorderRefPicList
+          Mmcop1
+          Mmcop2
+          Mmcop3
+          Mmcop4
+          Mmcop5
+          Mmcop6
+          h264bsdMarkDecRefPic
+          h264bsdGetRefPicData
+          h264bsdAllocateDpbImage
+          SlidingWindowRefPicMarking
+          h264bsdInitDpb
+          h264bsdResetDpb
+          h264bsdInitRefPicList
+          FindDpbPic
+          SetPicNums
+          h264bsdCheckGapsInFrameNum
+          FindSmallestPicOrderCnt
+          OutputPicture
+          h264bsdDpbOutputPicture
+          h264bsdFlushDpb
+          h264bsdFreeDpb
+
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "h264bsd_cfg.h"
+#include "h264bsd_dpb.h"
+#include "h264bsd_slice_header.h"
+#include "h264bsd_image.h"
+#include "h264bsd_util.h"
+#include "basetype.h"
+
+/*------------------------------------------------------------------------------
+    2. External compiler flags
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+    3. Module defines
+------------------------------------------------------------------------------*/
+
+/* macros to determine picture status. Note that IS_SHORT_TERM macro returns
+ * true also for non-existing pictures because non-existing pictures are
+ * regarded short term pictures according to H.264 standard */
+#define IS_REFERENCE(a) ((a).status)
+#define IS_EXISTING(a) ((a).status > NON_EXISTING)
+#define IS_SHORT_TERM(a) \
+    ((a).status == NON_EXISTING || (a).status == SHORT_TERM)
+#define IS_LONG_TERM(a) ((a).status == LONG_TERM)
+
+/* macro to set a picture unused for reference */
+#define SET_UNUSED(a) (a).status = UNUSED;
+
+#define MAX_NUM_REF_IDX_L0_ACTIVE 16
+
+/*------------------------------------------------------------------------------
+    4. Local function prototypes
+------------------------------------------------------------------------------*/
+
+static i32 ComparePictures(const void *ptr1, const void *ptr2);
+
+static u32 Mmcop1(dpbStorage_t *dpb, u32 currPicNum, u32 differenceOfPicNums);
+
+static u32 Mmcop2(dpbStorage_t *dpb, u32 longTermPicNum);
+
+static u32 Mmcop3(dpbStorage_t *dpb, u32 currPicNum, u32 differenceOfPicNums,
+    u32 longTermFrameIdx);
+
+static u32 Mmcop4(dpbStorage_t *dpb, u32 maxLongTermFrameIdx);
+
+static u32 Mmcop5(dpbStorage_t *dpb);
+
+static u32 Mmcop6(dpbStorage_t *dpb, u32 frameNum, i32 picOrderCnt,
+    u32 longTermFrameIdx);
+
+static u32 SlidingWindowRefPicMarking(dpbStorage_t *dpb);
+
+static i32 FindDpbPic(dpbStorage_t *dpb, i32 picNum, u32 isShortTerm);
+
+static void SetPicNums(dpbStorage_t *dpb, u32 currFrameNum);
+
+static dpbPicture_t* FindSmallestPicOrderCnt(dpbStorage_t *dpb);
+
+static u32 OutputPicture(dpbStorage_t *dpb);
+
+static void ShellSort(dpbPicture_t *pPic, u32 num);
+
+/*------------------------------------------------------------------------------
+
+    Function: ComparePictures
+
+        Functional description:
+            Function to compare dpb pictures, used by the ShellSort() function.
+            Order of the pictures after sorting shall be as follows:
+                1) short term reference pictures starting with the largest
+                   picNum
+                2) long term reference pictures starting with the smallest
+                   longTermPicNum
+                3) pictures unused for reference but needed for display
+                4) other pictures
+
+        Returns:
+            -1      pic 1 is greater than pic 2
+             0      equal from comparison point of view
+             1      pic 2 is greater then pic 1
+
+------------------------------------------------------------------------------*/
+
+static i32 ComparePictures(const void *ptr1, const void *ptr2)
+{
+
+/* Variables */
+
+    dpbPicture_t *pic1, *pic2;
+
+/* Code */
+
+    ASSERT(ptr1);
+    ASSERT(ptr2);
+
+    pic1 = (dpbPicture_t*)ptr1;
+    pic2 = (dpbPicture_t*)ptr2;
+
+    /* both are non-reference pictures, check if needed for display */
+    if (!IS_REFERENCE(*pic1) && !IS_REFERENCE(*pic2))
+    {
+        if (pic1->toBeDisplayed && !pic2->toBeDisplayed)
+            return(-1);
+        else if (!pic1->toBeDisplayed && pic2->toBeDisplayed)
+            return(1);
+        else
+            return(0);
+    }
+    /* only pic 1 needed for reference -> greater */
+    else if (!IS_REFERENCE(*pic2))
+        return(-1);
+    /* only pic 2 needed for reference -> greater */
+    else if (!IS_REFERENCE(*pic1))
+        return(1);
+    /* both are short term reference pictures -> check picNum */
+    else if (IS_SHORT_TERM(*pic1) && IS_SHORT_TERM(*pic2))
+    {
+        if (pic1->picNum > pic2->picNum)
+            return(-1);
+        else if (pic1->picNum < pic2->picNum)
+            return(1);
+        else
+            return(0);
+    }
+    /* only pic 1 is short term -> greater */
+    else if (IS_SHORT_TERM(*pic1))
+        return(-1);
+    /* only pic 2 is short term -> greater */
+    else if (IS_SHORT_TERM(*pic2))
+        return(1);
+    /* both are long term reference pictures -> check picNum (contains the
+     * longTermPicNum */
+    else
+    {
+        if (pic1->picNum > pic2->picNum)
+            return(1);
+        else if (pic1->picNum < pic2->picNum)
+            return(-1);
+        else
+            return(0);
+    }
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdReorderRefPicList
+
+        Functional description:
+            Function to perform reference picture list reordering based on
+            reordering commands received in the slice header. See details
+            of the process in the H.264 standard.
+
+        Inputs:
+            dpb             pointer to dpb storage structure
+            order           pointer to reordering commands
+            currFrameNum    current frame number
+            numRefIdxActive number of active reference indices for current
+                            picture
+
+        Outputs:
+            dpb             'list' field of the structure reordered
+
+        Returns:
+            HANTRO_OK      success
+            HANTRO_NOK     if non-existing pictures referred to in the
+                           reordering commands
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdReorderRefPicList(
+  dpbStorage_t *dpb,
+  refPicListReordering_t *order,
+  u32 currFrameNum,
+  u32 numRefIdxActive)
+{
+
+/* Variables */
+
+    u32 i, j, k, picNumPred, refIdx;
+    i32 picNum, picNumNoWrap, index;
+    u32 isShortTerm;
+
+/* Code */
+
+    ASSERT(order);
+    ASSERT(currFrameNum <= dpb->maxFrameNum);
+    ASSERT(numRefIdxActive <= MAX_NUM_REF_IDX_L0_ACTIVE);
+
+    /* set dpb picture numbers for sorting */
+    SetPicNums(dpb, currFrameNum);
+
+    if (!order->refPicListReorderingFlagL0)
+        return(HANTRO_OK);
+
+    refIdx     = 0;
+    picNumPred = currFrameNum;
+
+    i = 0;
+    while (order->command[i].reorderingOfPicNumsIdc < 3)
+    {
+        /* short term */
+        if (order->command[i].reorderingOfPicNumsIdc < 2)
+        {
+            if (order->command[i].reorderingOfPicNumsIdc == 0)
+            {
+                picNumNoWrap =
+                    (i32)picNumPred - (i32)order->command[i].absDiffPicNum;
+                if (picNumNoWrap < 0)
+                    picNumNoWrap += (i32)dpb->maxFrameNum;
+            }
+            else
+            {
+                picNumNoWrap =
+                    (i32)(picNumPred + order->command[i].absDiffPicNum);
+                if (picNumNoWrap >= (i32)dpb->maxFrameNum)
+                    picNumNoWrap -= (i32)dpb->maxFrameNum;
+            }
+            picNumPred = (u32)picNumNoWrap;
+            picNum = picNumNoWrap;
+            if ((u32)picNumNoWrap > currFrameNum)
+                picNum -= (i32)dpb->maxFrameNum;
+            isShortTerm = HANTRO_TRUE;
+        }
+        /* long term */
+        else
+        {
+            picNum = (i32)order->command[i].longTermPicNum;
+            isShortTerm = HANTRO_FALSE;
+
+        }
+        /* find corresponding picture from dpb */
+        index = FindDpbPic(dpb, picNum, isShortTerm);
+        if (index < 0 || !IS_EXISTING(dpb->buffer[index]))
+            return(HANTRO_NOK);
+
+        /* shift pictures */
+        for (j = numRefIdxActive; j > refIdx; j--)
+            dpb->list[j] = dpb->list[j-1];
+        /* put picture into the list */
+        dpb->list[refIdx++] = &dpb->buffer[index];
+        /* remove later references to the same picture */
+        for (j = k = refIdx; j <= numRefIdxActive; j++)
+            if(dpb->list[j] != &dpb->buffer[index])
+                dpb->list[k++] = dpb->list[j];
+
+        i++;
+    }
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: Mmcop1
+
+        Functional description:
+            Function to mark a short-term reference picture unused for
+            reference, memory_management_control_operation equal to 1
+
+        Returns:
+            HANTRO_OK      success
+            HANTRO_NOK     failure, picture does not exist in the buffer
+
+------------------------------------------------------------------------------*/
+
+static u32 Mmcop1(dpbStorage_t *dpb, u32 currPicNum, u32 differenceOfPicNums)
+{
+
+/* Variables */
+
+    i32 index, picNum;
+
+/* Code */
+
+    ASSERT(currPicNum < dpb->maxFrameNum);
+
+    picNum = (i32)currPicNum - (i32)differenceOfPicNums;
+
+    index = FindDpbPic(dpb, picNum, HANTRO_TRUE);
+    if (index < 0)
+        return(HANTRO_NOK);
+
+    SET_UNUSED(dpb->buffer[index]);
+    dpb->numRefFrames--;
+    if (!dpb->buffer[index].toBeDisplayed)
+        dpb->fullness--;
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: Mmcop2
+
+        Functional description:
+            Function to mark a long-term reference picture unused for
+            reference, memory_management_control_operation equal to 2
+
+        Returns:
+            HANTRO_OK      success
+            HANTRO_NOK     failure, picture does not exist in the buffer
+
+------------------------------------------------------------------------------*/
+
+static u32 Mmcop2(dpbStorage_t *dpb, u32 longTermPicNum)
+{
+
+/* Variables */
+
+    i32 index;
+
+/* Code */
+
+    index = FindDpbPic(dpb, (i32)longTermPicNum, HANTRO_FALSE);
+    if (index < 0)
+        return(HANTRO_NOK);
+
+    SET_UNUSED(dpb->buffer[index]);
+    dpb->numRefFrames--;
+    if (!dpb->buffer[index].toBeDisplayed)
+        dpb->fullness--;
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: Mmcop3
+
+        Functional description:
+            Function to assing a longTermFrameIdx to a short-term reference
+            frame (i.e. to change it to a long-term reference picture),
+            memory_management_control_operation equal to 3
+
+        Returns:
+            HANTRO_OK      success
+            HANTRO_NOK     failure, short-term picture does not exist in the
+                           buffer or is a non-existing picture, or invalid
+                           longTermFrameIdx given
+
+------------------------------------------------------------------------------*/
+
+static u32 Mmcop3(dpbStorage_t *dpb, u32 currPicNum, u32 differenceOfPicNums,
+    u32 longTermFrameIdx)
+{
+
+/* Variables */
+
+    i32 index, picNum;
+    u32 i;
+
+/* Code */
+
+    ASSERT(dpb);
+    ASSERT(currPicNum < dpb->maxFrameNum);
+
+    if ( (dpb->maxLongTermFrameIdx == NO_LONG_TERM_FRAME_INDICES) ||
+         (longTermFrameIdx > dpb->maxLongTermFrameIdx) )
+        return(HANTRO_NOK);
+
+    /* check if a long term picture with the same longTermFrameIdx already
+     * exist and remove it if necessary */
+    for (i = 0; i < dpb->maxRefFrames; i++)
+        if (IS_LONG_TERM(dpb->buffer[i]) &&
+          (u32)dpb->buffer[i].picNum == longTermFrameIdx)
+        {
+            SET_UNUSED(dpb->buffer[i]);
+            dpb->numRefFrames--;
+            if (!dpb->buffer[i].toBeDisplayed)
+                dpb->fullness--;
+            break;
+        }
+
+    picNum = (i32)currPicNum - (i32)differenceOfPicNums;
+
+    index = FindDpbPic(dpb, picNum, HANTRO_TRUE);
+    if (index < 0)
+        return(HANTRO_NOK);
+    if (!IS_EXISTING(dpb->buffer[index]))
+        return(HANTRO_NOK);
+
+    dpb->buffer[index].status = LONG_TERM;
+    dpb->buffer[index].picNum = (i32)longTermFrameIdx;
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: Mmcop4
+
+        Functional description:
+            Function to set maxLongTermFrameIdx,
+            memory_management_control_operation equal to 4
+
+        Returns:
+            HANTRO_OK      success
+
+------------------------------------------------------------------------------*/
+
+static u32 Mmcop4(dpbStorage_t *dpb, u32 maxLongTermFrameIdx)
+{
+
+/* Variables */
+
+    u32 i;
+
+/* Code */
+
+    dpb->maxLongTermFrameIdx = maxLongTermFrameIdx;
+
+    for (i = 0; i < dpb->maxRefFrames; i++)
+        if (IS_LONG_TERM(dpb->buffer[i]) &&
+          ( ((u32)dpb->buffer[i].picNum > maxLongTermFrameIdx) ||
+            (dpb->maxLongTermFrameIdx == NO_LONG_TERM_FRAME_INDICES) ) )
+        {
+            SET_UNUSED(dpb->buffer[i]);
+            dpb->numRefFrames--;
+            if (!dpb->buffer[i].toBeDisplayed)
+                dpb->fullness--;
+        }
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: Mmcop5
+
+        Functional description:
+            Function to mark all reference pictures unused for reference and
+            set maxLongTermFrameIdx to NO_LONG_TERM_FRAME_INDICES,
+            memory_management_control_operation equal to 5. Function flushes
+            the buffer and places all pictures that are needed for display into
+            the output buffer.
+
+        Returns:
+            HANTRO_OK      success
+
+------------------------------------------------------------------------------*/
+
+static u32 Mmcop5(dpbStorage_t *dpb)
+{
+
+/* Variables */
+
+    u32 i;
+
+/* Code */
+
+    for (i = 0; i < 16; i++)
+    {
+        if (IS_REFERENCE(dpb->buffer[i]))
+        {
+            SET_UNUSED(dpb->buffer[i]);
+            if (!dpb->buffer[i].toBeDisplayed)
+                dpb->fullness--;
+        }
+    }
+
+    /* output all pictures */
+    while (OutputPicture(dpb) == HANTRO_OK)
+        ;
+    dpb->numRefFrames = 0;
+    dpb->maxLongTermFrameIdx = NO_LONG_TERM_FRAME_INDICES;
+    dpb->prevRefFrameNum = 0;
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: Mmcop6
+
+        Functional description:
+            Function to assign longTermFrameIdx to the current picture,
+            memory_management_control_operation equal to 6
+
+        Returns:
+            HANTRO_OK      success
+            HANTRO_NOK     invalid longTermFrameIdx or no room for current
+                           picture in the buffer
+
+------------------------------------------------------------------------------*/
+
+static u32 Mmcop6(dpbStorage_t *dpb, u32 frameNum, i32 picOrderCnt,
+    u32 longTermFrameIdx)
+{
+
+/* Variables */
+
+    u32 i;
+
+/* Code */
+
+    ASSERT(frameNum < dpb->maxFrameNum);
+
+    if ( (dpb->maxLongTermFrameIdx == NO_LONG_TERM_FRAME_INDICES) ||
+         (longTermFrameIdx > dpb->maxLongTermFrameIdx) )
+        return(HANTRO_NOK);
+
+    /* check if a long term picture with the same longTermFrameIdx already
+     * exist and remove it if necessary */
+    for (i = 0; i < dpb->maxRefFrames; i++)
+        if (IS_LONG_TERM(dpb->buffer[i]) &&
+          (u32)dpb->buffer[i].picNum == longTermFrameIdx)
+        {
+            SET_UNUSED(dpb->buffer[i]);
+            dpb->numRefFrames--;
+            if (!dpb->buffer[i].toBeDisplayed)
+                dpb->fullness--;
+            break;
+        }
+
+    if (dpb->numRefFrames < dpb->maxRefFrames)
+    {
+        dpb->currentOut->frameNum = frameNum;
+        dpb->currentOut->picNum   = (i32)longTermFrameIdx;
+        dpb->currentOut->picOrderCnt = picOrderCnt;
+        dpb->currentOut->status   = LONG_TERM;
+        if (dpb->noReordering)
+            dpb->currentOut->toBeDisplayed = HANTRO_FALSE;
+        else
+            dpb->currentOut->toBeDisplayed = HANTRO_TRUE;
+        dpb->numRefFrames++;
+        dpb->fullness++;
+        return(HANTRO_OK);
+    }
+    /* if there is no room, return an error */
+    else
+        return(HANTRO_NOK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdMarkDecRefPic
+
+        Functional description:
+            Function to perform reference picture marking process. This
+            function should be called both for reference and non-reference
+            pictures.  Non-reference pictures shall have mark pointer set to
+            NULL.
+
+        Inputs:
+            dpb         pointer to the DPB data structure
+            mark        pointer to reference picture marking commands
+            image       pointer to current picture to be placed in the buffer
+            frameNum    frame number of the current picture
+            picOrderCnt picture order count for the current picture
+            isIdr       flag to indicate if the current picture is an
+                        IDR picture
+            currentPicId    identifier for the current picture, from the
+                            application, stored along with the picture
+            numErrMbs       number of concealed macroblocks in the current
+                            picture, stored along with the picture
+
+        Outputs:
+            dpb         'buffer' modified, possible output frames placed into
+                        'outBuf'
+
+        Returns:
+            HANTRO_OK   success
+            HANTRO_NOK  failure
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdMarkDecRefPic(
+  dpbStorage_t *dpb,
+  decRefPicMarking_t *mark,
+  image_t *image,
+  u32 frameNum,
+  i32 picOrderCnt,
+  u32 isIdr,
+  u32 currentPicId,
+  u32 numErrMbs)
+{
+
+/* Variables */
+
+    u32 i, status;
+    u32 markedAsLongTerm;
+    u32 toBeDisplayed;
+
+/* Code */
+
+    ASSERT(dpb);
+    ASSERT(mark || !isIdr);
+    ASSERT(!isIdr || (frameNum == 0 && picOrderCnt == 0));
+    ASSERT(frameNum < dpb->maxFrameNum);
+
+    if (image->data != dpb->currentOut->data)
+    {
+        EPRINT("TRYING TO MARK NON-ALLOCATED IMAGE");
+        return(HANTRO_NOK);
+    }
+
+    dpb->lastContainsMmco5 = HANTRO_FALSE;
+    status = HANTRO_OK;
+
+    toBeDisplayed = dpb->noReordering ? HANTRO_FALSE : HANTRO_TRUE;
+
+    /* non-reference picture, stored for display reordering purposes */
+    if (mark == NULL)
+    {
+        dpb->currentOut->status = UNUSED;
+        dpb->currentOut->frameNum = frameNum;
+        dpb->currentOut->picNum = (i32)frameNum;
+        dpb->currentOut->picOrderCnt = picOrderCnt;
+        dpb->currentOut->toBeDisplayed = toBeDisplayed;
+        if (!dpb->noReordering)
+            dpb->fullness++;
+    }
+    /* IDR picture */
+    else if (isIdr)
+    {
+
+        /* h264bsdCheckGapsInFrameNum not called for IDR pictures -> have to
+         * reset numOut and outIndex here */
+        dpb->numOut = dpb->outIndex = 0;
+
+        /* flush the buffer */
+        Mmcop5(dpb);
+        /* if noOutputOfPriorPicsFlag was set -> the pictures preceding the
+         * IDR picture shall not be output -> set output buffer empty */
+        if (mark->noOutputOfPriorPicsFlag || dpb->noReordering)
+        {
+            dpb->numOut = 0;
+            dpb->outIndex = 0;
+        }
+
+        if (mark->longTermReferenceFlag)
+        {
+            dpb->currentOut->status = LONG_TERM;
+            dpb->maxLongTermFrameIdx = 0;
+        }
+        else
+        {
+            dpb->currentOut->status = SHORT_TERM;
+            dpb->maxLongTermFrameIdx = NO_LONG_TERM_FRAME_INDICES;
+        }
+        dpb->currentOut->frameNum  = 0;
+        dpb->currentOut->picNum    = 0;
+        dpb->currentOut->picOrderCnt = 0;
+        dpb->currentOut->toBeDisplayed = toBeDisplayed;
+        dpb->fullness = 1;
+        dpb->numRefFrames = 1;
+    }
+    /* reference picture */
+    else
+    {
+        markedAsLongTerm = HANTRO_FALSE;
+        if (mark->adaptiveRefPicMarkingModeFlag)
+        {
+            i = 0;
+            while (mark->operation[i].memoryManagementControlOperation)
+            {
+                switch (mark->operation[i].memoryManagementControlOperation)
+                {
+                    case 1:
+                        status = Mmcop1(
+                          dpb,
+                          frameNum,
+                          mark->operation[i].differenceOfPicNums);
+                        break;
+
+                    case 2:
+                        status = Mmcop2(dpb, mark->operation[i].longTermPicNum);
+                        break;
+
+                    case 3:
+                        status =  Mmcop3(
+                          dpb,
+                          frameNum,
+                          mark->operation[i].differenceOfPicNums,
+                          mark->operation[i].longTermFrameIdx);
+                        break;
+
+                    case 4:
+                        status = Mmcop4(
+                          dpb,
+                          mark->operation[i].maxLongTermFrameIdx);
+                        break;
+
+                    case 5:
+                        status = Mmcop5(dpb);
+                        dpb->lastContainsMmco5 = HANTRO_TRUE;
+                        frameNum = 0;
+                        break;
+
+                    case 6:
+                        status = Mmcop6(
+                          dpb,
+                          frameNum,
+                          picOrderCnt,
+                          mark->operation[i].longTermFrameIdx);
+                        if (status == HANTRO_OK)
+                            markedAsLongTerm = HANTRO_TRUE;
+                        break;
+
+                    default: /* invalid memory management control operation */
+                        status = HANTRO_NOK;
+                        break;
+                }
+                if (status != HANTRO_OK)
+                {
+                    break;
+                }
+                i++;
+            }
+        }
+        else
+        {
+            status = SlidingWindowRefPicMarking(dpb);
+        }
+        /* if current picture was not marked as long-term reference by
+         * memory management control operation 6 -> mark current as short
+         * term and insert it into dpb (if there is room) */
+        if (!markedAsLongTerm)
+        {
+            if (dpb->numRefFrames < dpb->maxRefFrames)
+            {
+                dpb->currentOut->frameNum = frameNum;
+                dpb->currentOut->picNum   = (i32)frameNum;
+                dpb->currentOut->picOrderCnt = picOrderCnt;
+                dpb->currentOut->status   = SHORT_TERM;
+                dpb->currentOut->toBeDisplayed = toBeDisplayed;
+                dpb->fullness++;
+                dpb->numRefFrames++;
+            }
+            /* no room */
+            else
+            {
+                status = HANTRO_NOK;
+            }
+        }
+    }
+
+    dpb->currentOut->isIdr = isIdr;
+    dpb->currentOut->picId = currentPicId;
+    dpb->currentOut->numErrMbs = numErrMbs;
+
+    /* dpb was initialized to not to reorder the pictures -> output current
+     * picture immediately */
+    if (dpb->noReordering)
+    {
+        ASSERT(dpb->numOut == 0);
+        ASSERT(dpb->outIndex == 0);
+        dpb->outBuf[dpb->numOut].data  = dpb->currentOut->data;
+        dpb->outBuf[dpb->numOut].isIdr = dpb->currentOut->isIdr;
+        dpb->outBuf[dpb->numOut].picId = dpb->currentOut->picId;
+        dpb->outBuf[dpb->numOut].numErrMbs = dpb->currentOut->numErrMbs;
+        dpb->numOut++;
+    }
+    else
+    {
+        /* output pictures if buffer full */
+        while (dpb->fullness > dpb->dpbSize)
+        {
+            i = OutputPicture(dpb);
+            ASSERT(i == HANTRO_OK);
+        }
+    }
+
+    /* sort dpb */
+    ShellSort(dpb->buffer, dpb->dpbSize+1);
+
+    return(status);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdGetRefPicData
+
+        Functional description:
+            Function to get reference picture data from the reference picture
+            list
+
+        Returns:
+            pointer to desired reference picture data
+            NULL if invalid index or non-existing picture referred
+
+------------------------------------------------------------------------------*/
+
+u8* h264bsdGetRefPicData(dpbStorage_t *dpb, u32 index)
+{
+
+/* Variables */
+
+/* Code */
+
+    if(index > 16 || dpb->list[index] == NULL)
+        return(NULL);
+    else if(!IS_EXISTING(*dpb->list[index]))
+        return(NULL);
+    else
+        return(dpb->list[index]->data);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdAllocateDpbImage
+
+        Functional description:
+            function to allocate memory for a image. This function does not
+            really allocate any memory but reserves one of the buffer
+            positions for decoding of current picture
+
+        Returns:
+            pointer to memory area for the image
+
+
+------------------------------------------------------------------------------*/
+
+u8* h264bsdAllocateDpbImage(dpbStorage_t *dpb)
+{
+
+/* Variables */
+
+/* Code */
+
+    ASSERT( !dpb->buffer[dpb->dpbSize].toBeDisplayed &&
+            !IS_REFERENCE(dpb->buffer[dpb->dpbSize]) );
+    ASSERT(dpb->fullness <=  dpb->dpbSize);
+
+    dpb->currentOut = dpb->buffer + dpb->dpbSize;
+
+    return(dpb->currentOut->data);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: SlidingWindowRefPicMarking
+
+        Functional description:
+            Function to perform sliding window refence picture marking process.
+
+        Outputs:
+            HANTRO_OK      success
+            HANTRO_NOK     failure, no short-term reference frame found that
+                           could be marked unused
+
+
+------------------------------------------------------------------------------*/
+
+static u32 SlidingWindowRefPicMarking(dpbStorage_t *dpb)
+{
+
+/* Variables */
+
+    i32 index, picNum;
+    u32 i;
+
+/* Code */
+
+    if (dpb->numRefFrames < dpb->maxRefFrames)
+    {
+        return(HANTRO_OK);
+    }
+    else
+    {
+        index = -1;
+        picNum = 0;
+        /* find the oldest short term picture */
+        for (i = 0; i < dpb->numRefFrames; i++)
+            if (IS_SHORT_TERM(dpb->buffer[i]))
+                if (dpb->buffer[i].picNum < picNum || index == -1)
+                {
+                    index = (i32)i;
+                    picNum = dpb->buffer[i].picNum;
+                }
+        if (index >= 0)
+        {
+            SET_UNUSED(dpb->buffer[index]);
+            dpb->numRefFrames--;
+            if (!dpb->buffer[index].toBeDisplayed)
+                dpb->fullness--;
+
+            return(HANTRO_OK);
+        }
+    }
+
+    return(HANTRO_NOK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdInitDpb
+
+        Functional description:
+            Function to initialize DPB. Reserves memories for the buffer,
+            reference picture list and output buffer. dpbSize indicates
+            the maximum DPB size indicated by the levelIdc in the stream.
+            If noReordering flag is FALSE the DPB stores dpbSize pictures
+            for display reordering purposes. On the other hand, if the
+            flag is TRUE the DPB only stores maxRefFrames reference pictures
+            and outputs all the pictures immediately.
+
+        Inputs:
+            picSizeInMbs    picture size in macroblocks
+            dpbSize         size of the DPB (number of pictures)
+            maxRefFrames    max number of reference frames
+            maxFrameNum     max frame number
+            noReordering    flag to indicate that DPB does not have to
+                            prepare to reorder frames for display
+
+        Outputs:
+            dpb             pointer to dpb data storage
+
+        Returns:
+            HANTRO_OK       success
+            MEMORY_ALLOCATION_ERROR if memory allocation failed
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdInitDpb(
+  dpbStorage_t *dpb,
+  u32 picSizeInMbs,
+  u32 dpbSize,
+  u32 maxRefFrames,
+  u32 maxFrameNum,
+  u32 noReordering)
+{
+
+/* Variables */
+
+    u32 i;
+
+/* Code */
+
+    ASSERT(picSizeInMbs);
+    ASSERT(maxRefFrames <= MAX_NUM_REF_PICS);
+    ASSERT(maxRefFrames <= dpbSize);
+    ASSERT(maxFrameNum);
+    ASSERT(dpbSize);
+
+    dpb->maxLongTermFrameIdx = NO_LONG_TERM_FRAME_INDICES;
+    dpb->maxRefFrames        = MAX(maxRefFrames, 1);
+    if (noReordering)
+        dpb->dpbSize         = dpb->maxRefFrames;
+    else
+        dpb->dpbSize         = dpbSize;
+    dpb->maxFrameNum         = maxFrameNum;
+    dpb->noReordering        = noReordering;
+    dpb->fullness            = 0;
+    dpb->numRefFrames        = 0;
+    dpb->prevRefFrameNum     = 0;
+
+    ALLOCATE(dpb->buffer, MAX_NUM_REF_IDX_L0_ACTIVE + 1, dpbPicture_t);
+    if (dpb->buffer == NULL)
+        return(MEMORY_ALLOCATION_ERROR);
+    H264SwDecMemset(dpb->buffer, 0,
+            (MAX_NUM_REF_IDX_L0_ACTIVE + 1)*sizeof(dpbPicture_t));
+    for (i = 0; i < dpb->dpbSize + 1; i++)
+    {
+        /* Allocate needed amount of memory, which is:
+         * image size + 32 + 15, where 32 cames from the fact that in ARM OpenMax
+         * DL implementation Functions may read beyond the end of an array,
+         * by a maximum of 32 bytes. And +15 cames for the need to align memory
+         * to 16-byte boundary */
+        ALLOCATE(dpb->buffer[i].pAllocatedData, (picSizeInMbs*384 + 32+15), u8);
+        if (dpb->buffer[i].pAllocatedData == NULL)
+            return(MEMORY_ALLOCATION_ERROR);
+
+        dpb->buffer[i].data = ALIGN(dpb->buffer[i].pAllocatedData, 16);
+    }
+
+    ALLOCATE(dpb->list, MAX_NUM_REF_IDX_L0_ACTIVE + 1, dpbPicture_t*);
+    ALLOCATE(dpb->outBuf, dpb->dpbSize+1, dpbOutPicture_t);
+
+    if (dpb->list == NULL || dpb->outBuf == NULL)
+        return(MEMORY_ALLOCATION_ERROR);
+
+    H264SwDecMemset(dpb->list, 0,
+            ((MAX_NUM_REF_IDX_L0_ACTIVE + 1) * sizeof(dpbPicture_t*)) );
+
+    dpb->numOut = dpb->outIndex = 0;
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdResetDpb
+
+        Functional description:
+            Function to reset DPB. This function should be called when an IDR
+            slice (other than the first) activates new sequence parameter set.
+            Function calls h264bsdFreeDpb to free old allocated memories and
+            h264bsdInitDpb to re-initialize the DPB. Same inputs, outputs and
+            returns as for h264bsdInitDpb.
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdResetDpb(
+  dpbStorage_t *dpb,
+  u32 picSizeInMbs,
+  u32 dpbSize,
+  u32 maxRefFrames,
+  u32 maxFrameNum,
+  u32 noReordering)
+{
+
+/* Code */
+
+    ASSERT(picSizeInMbs);
+    ASSERT(maxRefFrames <= MAX_NUM_REF_PICS);
+    ASSERT(maxRefFrames <= dpbSize);
+    ASSERT(maxFrameNum);
+    ASSERT(dpbSize);
+
+    h264bsdFreeDpb(dpb);
+
+    return h264bsdInitDpb(dpb, picSizeInMbs, dpbSize, maxRefFrames,
+                          maxFrameNum, noReordering);
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdInitRefPicList
+
+        Functional description:
+            Function to initialize reference picture list. Function just
+            sets pointers in the list according to pictures in the buffer.
+            The buffer is assumed to contain pictures sorted according to
+            what the H.264 standard says about initial reference picture list.
+
+        Inputs:
+            dpb     pointer to dpb data structure
+
+        Outputs:
+            dpb     'list' field initialized
+
+        Returns:
+            none
+
+------------------------------------------------------------------------------*/
+
+void h264bsdInitRefPicList(dpbStorage_t *dpb)
+{
+
+/* Variables */
+
+    u32 i;
+
+/* Code */
+
+    for (i = 0; i < dpb->numRefFrames; i++)
+        dpb->list[i] = &dpb->buffer[i];
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: FindDpbPic
+
+        Functional description:
+            Function to find a reference picture from the buffer. The picture
+            to be found is identified by picNum and isShortTerm flag.
+
+        Returns:
+            index of the picture in the buffer
+            -1 if the specified picture was not found in the buffer
+
+------------------------------------------------------------------------------*/
+
+static i32 FindDpbPic(dpbStorage_t *dpb, i32 picNum, u32 isShortTerm)
+{
+
+/* Variables */
+
+    u32 i = 0;
+    u32 found = HANTRO_FALSE;
+
+/* Code */
+
+    if (isShortTerm)
+    {
+        while (i < dpb->maxRefFrames && !found)
+        {
+            if (IS_SHORT_TERM(dpb->buffer[i]) &&
+              dpb->buffer[i].picNum == picNum)
+                found = HANTRO_TRUE;
+            else
+                i++;
+        }
+    }
+    else
+    {
+        ASSERT(picNum >= 0);
+        while (i < dpb->maxRefFrames && !found)
+        {
+            if (IS_LONG_TERM(dpb->buffer[i]) &&
+              dpb->buffer[i].picNum == picNum)
+                found = HANTRO_TRUE;
+            else
+                i++;
+        }
+    }
+
+    if (found)
+        return((i32)i);
+    else
+        return(-1);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: SetPicNums
+
+        Functional description:
+            Function to set picNum values for short-term pictures in the
+            buffer. Numbering of pictures is based on frame numbers and as
+            frame numbers are modulo maxFrameNum -> frame numbers of older
+            pictures in the buffer may be bigger than the currFrameNum.
+            picNums will be set so that current frame has the largest picNum
+            and all the short-term frames in the buffer will get smaller picNum
+            representing their "distance" from the current frame. This
+            function kind of maps the modulo arithmetic back to normal.
+
+------------------------------------------------------------------------------*/
+
+static void SetPicNums(dpbStorage_t *dpb, u32 currFrameNum)
+{
+
+/* Variables */
+
+    u32 i;
+    i32 frameNumWrap;
+
+/* Code */
+
+    ASSERT(dpb);
+    ASSERT(currFrameNum < dpb->maxFrameNum);
+
+    for (i = 0; i < dpb->numRefFrames; i++)
+        if (IS_SHORT_TERM(dpb->buffer[i]))
+        {
+            if (dpb->buffer[i].frameNum > currFrameNum)
+                frameNumWrap =
+                    (i32)dpb->buffer[i].frameNum - (i32)dpb->maxFrameNum;
+            else
+                frameNumWrap = (i32)dpb->buffer[i].frameNum;
+            dpb->buffer[i].picNum = frameNumWrap;
+        }
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdCheckGapsInFrameNum
+
+        Functional description:
+            Function to check gaps in frame_num and generate non-existing
+            (short term) reference pictures if necessary. This function should
+            be called only for non-IDR pictures.
+
+        Inputs:
+            dpb         pointer to dpb data structure
+            frameNum    frame number of the current picture
+            isRefPic    flag to indicate if current picture is a reference or
+                        non-reference picture
+            gapsAllowed Flag which indicates active SPS stance on whether
+                        to allow gaps
+
+        Outputs:
+            dpb         'buffer' possibly modified by inserting non-existing
+                        pictures with sliding window marking process
+
+        Returns:
+            HANTRO_OK   success
+            HANTRO_NOK  error in sliding window reference picture marking or
+                        frameNum equal to previous reference frame used for
+                        a reference picture
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdCheckGapsInFrameNum(dpbStorage_t *dpb, u32 frameNum, u32 isRefPic,
+                               u32 gapsAllowed)
+{
+
+/* Variables */
+
+    u32 unUsedShortTermFrameNum;
+    u8 *tmp;
+
+/* Code */
+
+    ASSERT(dpb);
+    ASSERT(dpb->fullness <= dpb->dpbSize);
+    ASSERT(frameNum < dpb->maxFrameNum);
+
+    dpb->numOut = 0;
+    dpb->outIndex = 0;
+
+    if(!gapsAllowed)
+        return(HANTRO_OK);
+
+    if ( (frameNum != dpb->prevRefFrameNum) &&
+         (frameNum != ((dpb->prevRefFrameNum + 1) % dpb->maxFrameNum)))
+    {
+
+        unUsedShortTermFrameNum = (dpb->prevRefFrameNum + 1) % dpb->maxFrameNum;
+
+        /* store data pointer of last buffer position to be used as next
+         * "allocated" data pointer if last buffer position after this process
+         * contains data pointer located in outBuf (buffer placed in the output
+         * shall not be overwritten by the current picture) */
+        tmp = dpb->buffer[dpb->dpbSize].data;
+        do
+        {
+            SetPicNums(dpb, unUsedShortTermFrameNum);
+
+            if (SlidingWindowRefPicMarking(dpb) != HANTRO_OK)
+            {
+                return(HANTRO_NOK);
+            }
+
+            /* output pictures if buffer full */
+            while (dpb->fullness >= dpb->dpbSize)
+            {
+#ifdef _ASSERT_USED
+                ASSERT(!dpb->noReordering);
+                ASSERT(OutputPicture(dpb) == HANTRO_OK);
+#else
+                OutputPicture(dpb);
+#endif
+            }
+
+            /* add to end of list */
+            ASSERT( !dpb->buffer[dpb->dpbSize].toBeDisplayed &&
+                    !IS_REFERENCE(dpb->buffer[dpb->dpbSize]) );
+            dpb->buffer[dpb->dpbSize].status = NON_EXISTING;
+            dpb->buffer[dpb->dpbSize].frameNum = unUsedShortTermFrameNum;
+            dpb->buffer[dpb->dpbSize].picNum   = (i32)unUsedShortTermFrameNum;
+            dpb->buffer[dpb->dpbSize].picOrderCnt = 0;
+            dpb->buffer[dpb->dpbSize].toBeDisplayed = HANTRO_FALSE;
+            dpb->fullness++;
+            dpb->numRefFrames++;
+
+            /* sort the buffer */
+            ShellSort(dpb->buffer, dpb->dpbSize+1);
+
+            unUsedShortTermFrameNum = (unUsedShortTermFrameNum + 1) %
+                dpb->maxFrameNum;
+
+        } while (unUsedShortTermFrameNum != frameNum);
+
+        /* pictures placed in output buffer -> check that 'data' in
+         * buffer position dpbSize is not in the output buffer (this will be
+         * "allocated" by h264bsdAllocateDpbImage). If it is -> exchange data
+         * pointer with the one stored in the beginning */
+        if (dpb->numOut)
+        {
+            u32 i;
+
+            for (i = 0; i < dpb->numOut; i++)
+            {
+                if (dpb->outBuf[i].data == dpb->buffer[dpb->dpbSize].data)
+                {
+                    /* find buffer position containing data pointer stored in
+                     * tmp */
+                    for (i = 0; i < dpb->dpbSize; i++)
+                    {
+                        if (dpb->buffer[i].data == tmp)
+                        {
+                            dpb->buffer[i].data =
+                                dpb->buffer[dpb->dpbSize].data;
+                            dpb->buffer[dpb->dpbSize].data = tmp;
+                            break;
+                        }
+                    }
+                    ASSERT(i < dpb->dpbSize);
+                    break;
+                }
+            }
+        }
+    }
+    /* frameNum for reference pictures shall not be the same as for previous
+     * reference picture, otherwise accesses to pictures in the buffer cannot
+     * be solved unambiguously */
+    else if (isRefPic && frameNum == dpb->prevRefFrameNum)
+    {
+        return(HANTRO_NOK);
+    }
+
+    /* save current frame_num in prevRefFrameNum. For non-reference frame
+     * prevFrameNum is set to frame number of last non-existing frame above */
+    if (isRefPic)
+        dpb->prevRefFrameNum = frameNum;
+    else if (frameNum != dpb->prevRefFrameNum)
+    {
+        dpb->prevRefFrameNum =
+            (frameNum + dpb->maxFrameNum - 1) % dpb->maxFrameNum;
+    }
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: FindSmallestPicOrderCnt
+
+        Functional description:
+            Function to find picture with smallest picture order count. This
+            will be the next picture in display order.
+
+        Returns:
+            pointer to the picture, NULL if no pictures to be displayed
+
+------------------------------------------------------------------------------*/
+
+dpbPicture_t* FindSmallestPicOrderCnt(dpbStorage_t *dpb)
+{
+
+/* Variables */
+
+    u32 i;
+    i32 picOrderCnt;
+    dpbPicture_t *tmp;
+
+/* Code */
+
+    ASSERT(dpb);
+
+    picOrderCnt = 0x7FFFFFFF;
+    tmp = NULL;
+
+    for (i = 0; i <= dpb->dpbSize; i++)
+    {
+        if (dpb->buffer[i].toBeDisplayed &&
+            (dpb->buffer[i].picOrderCnt < picOrderCnt))
+        {
+            tmp = dpb->buffer + i;
+            picOrderCnt = dpb->buffer[i].picOrderCnt;
+        }
+    }
+
+    return(tmp);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: OutputPicture
+
+        Functional description:
+            Function to put next display order picture into the output buffer.
+
+        Returns:
+            HANTRO_OK      success
+            HANTRO_NOK     no pictures to display
+
+------------------------------------------------------------------------------*/
+
+u32 OutputPicture(dpbStorage_t *dpb)
+{
+
+/* Variables */
+
+    dpbPicture_t *tmp;
+
+/* Code */
+
+    ASSERT(dpb);
+
+    if (dpb->noReordering)
+        return(HANTRO_NOK);
+
+    tmp = FindSmallestPicOrderCnt(dpb);
+
+    /* no pictures to be displayed */
+    if (tmp == NULL)
+        return(HANTRO_NOK);
+
+    dpb->outBuf[dpb->numOut].data  = tmp->data;
+    dpb->outBuf[dpb->numOut].isIdr = tmp->isIdr;
+    dpb->outBuf[dpb->numOut].picId = tmp->picId;
+    dpb->outBuf[dpb->numOut].numErrMbs = tmp->numErrMbs;
+    dpb->numOut++;
+
+    tmp->toBeDisplayed = HANTRO_FALSE;
+    if (!IS_REFERENCE(*tmp))
+    {
+        dpb->fullness--;
+    }
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdDpbOutputPicture
+
+        Functional description:
+            Function to get next display order picture from the output buffer.
+
+        Return:
+            pointer to output picture structure, NULL if no pictures to
+            display
+
+------------------------------------------------------------------------------*/
+
+dpbOutPicture_t* h264bsdDpbOutputPicture(dpbStorage_t *dpb)
+{
+
+/* Variables */
+
+/* Code */
+
+    ASSERT(dpb);
+
+    if (dpb->outIndex < dpb->numOut)
+        return(dpb->outBuf + dpb->outIndex++);
+    else
+        return(NULL);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdFlushDpb
+
+        Functional description:
+            Function to flush the DPB. Function puts all pictures needed for
+            display into the output buffer. This function shall be called in
+            the end of the stream to obtain pictures buffered for display
+            re-ordering purposes.
+
+------------------------------------------------------------------------------*/
+
+void h264bsdFlushDpb(dpbStorage_t *dpb)
+{
+
+    /* don't do anything if buffer not reserved */
+    if (dpb->buffer)
+    {
+        dpb->flushed = 1;
+        /* output all pictures */
+        while (OutputPicture(dpb) == HANTRO_OK)
+            ;
+    }
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdFreeDpb
+
+        Functional description:
+            Function to free memories reserved for the DPB.
+
+------------------------------------------------------------------------------*/
+
+void h264bsdFreeDpb(dpbStorage_t *dpb)
+{
+
+/* Variables */
+
+    u32 i;
+
+/* Code */
+
+    ASSERT(dpb);
+
+    if (dpb->buffer)
+    {
+        for (i = 0; i < dpb->dpbSize+1; i++)
+        {
+            FREE(dpb->buffer[i].pAllocatedData);
+        }
+    }
+    FREE(dpb->buffer);
+    FREE(dpb->list);
+    FREE(dpb->outBuf);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: ShellSort
+
+        Functional description:
+            Sort pictures in the buffer. Function implements Shell's method,
+            i.e. diminishing increment sort. See e.g. "Numerical Recipes in C"
+            for more information.
+
+------------------------------------------------------------------------------*/
+
+static void ShellSort(dpbPicture_t *pPic, u32 num)
+{
+
+    u32 i, j;
+    u32 step;
+    dpbPicture_t tmpPic;
+
+    step = 7;
+
+    while (step)
+    {
+        for (i = step; i < num; i++)
+        {
+            tmpPic = pPic[i];
+            j = i;
+            while (j >= step && ComparePictures(pPic + j - step, &tmpPic) > 0)
+            {
+                pPic[j] = pPic[j-step];
+                j -= step;
+            }
+            pPic[j] = tmpPic;
+        }
+        step >>= 1;
+    }
+
+}
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_dpb.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_dpb.h
new file mode 100755
index 0000000..0e25084
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_dpb.h
@@ -0,0 +1,149 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+    1. Include headers
+    2. Module defines
+    3. Data types
+    4. Function prototypes
+
+------------------------------------------------------------------------------*/
+
+#ifndef H264SWDEC_DPB_H
+#define H264SWDEC_DPB_H
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "basetype.h"
+#include "h264bsd_slice_header.h"
+#include "h264bsd_image.h"
+
+/*------------------------------------------------------------------------------
+    2. Module defines
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    3. Data types
+------------------------------------------------------------------------------*/
+
+/* enumeration to represent status of buffered image */
+typedef enum {
+    UNUSED = 0,
+    NON_EXISTING,
+    SHORT_TERM,
+    LONG_TERM
+} dpbPictureStatus_e;
+
+/* structure to represent a buffered picture */
+typedef struct {
+    u8 *data;           /* 16-byte aligned pointer of pAllocatedData */
+    u8 *pAllocatedData; /* allocated picture pointer; (size + 15) bytes */
+    i32 picNum;
+    u32 frameNum;
+    i32 picOrderCnt;
+    dpbPictureStatus_e status;
+    u32 toBeDisplayed;
+    u32 picId;
+    u32 numErrMbs;
+    u32 isIdr;
+} dpbPicture_t;
+
+/* structure to represent display image output from the buffer */
+typedef struct {
+    u8 *data;
+    u32 picId;
+    u32 numErrMbs;
+    u32 isIdr;
+} dpbOutPicture_t;
+
+/* structure to represent DPB */
+typedef struct {
+    dpbPicture_t *buffer;
+    dpbPicture_t **list;
+    dpbPicture_t *currentOut;
+    dpbOutPicture_t *outBuf;
+    u32 numOut;
+    u32 outIndex;
+    u32 maxRefFrames;
+    u32 dpbSize;
+    u32 maxFrameNum;
+    u32 maxLongTermFrameIdx;
+    u32 numRefFrames;
+    u32 fullness;
+    u32 prevRefFrameNum;
+    u32 lastContainsMmco5;
+    u32 noReordering;
+    u32 flushed;
+} dpbStorage_t;
+
+/*------------------------------------------------------------------------------
+    4. Function prototypes
+------------------------------------------------------------------------------*/
+
+u32 h264bsdInitDpb(
+  dpbStorage_t *dpb,
+  u32 picSizeInMbs,
+  u32 dpbSize,
+  u32 numRefFrames,
+  u32 maxFrameNum,
+  u32 noReordering);
+
+u32 h264bsdResetDpb(
+  dpbStorage_t *dpb,
+  u32 picSizeInMbs,
+  u32 dpbSize,
+  u32 numRefFrames,
+  u32 maxFrameNum,
+  u32 noReordering);
+
+void h264bsdInitRefPicList(dpbStorage_t *dpb);
+
+u8* h264bsdAllocateDpbImage(dpbStorage_t *dpb);
+
+u8* h264bsdGetRefPicData(dpbStorage_t *dpb, u32 index);
+
+u32 h264bsdReorderRefPicList(
+  dpbStorage_t *dpb,
+  refPicListReordering_t *order,
+  u32 currFrameNum,
+  u32 numRefIdxActive);
+
+u32 h264bsdMarkDecRefPic(
+  dpbStorage_t *dpb,
+  decRefPicMarking_t *mark,
+  image_t *image,
+  u32 frameNum,
+  i32 picOrderCnt,
+  u32 isIdr,
+  u32 picId,
+  u32 numErrMbs);
+
+u32 h264bsdCheckGapsInFrameNum(dpbStorage_t *dpb, u32 frameNum, u32 isRefPic,
+                               u32 gapsAllowed);
+
+dpbOutPicture_t* h264bsdDpbOutputPicture(dpbStorage_t *dpb);
+
+void h264bsdFlushDpb(dpbStorage_t *dpb);
+
+void h264bsdFreeDpb(dpbStorage_t *dpb);
+
+#endif /* #ifdef H264SWDEC_DPB_H */
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_image.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_image.c
new file mode 100755
index 0000000..7b92870
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_image.c
@@ -0,0 +1,345 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+     1. Include headers
+     2. External compiler flags
+     3. Module defines
+     4. Local function prototypes
+     5. Functions
+          h264bsdWriteMacroblock
+          h264bsdWriteOutputBlocks
+
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "h264bsd_image.h"
+#include "h264bsd_util.h"
+#include "h264bsd_neighbour.h"
+
+/*------------------------------------------------------------------------------
+    2. External compiler flags
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+    3. Module defines
+------------------------------------------------------------------------------*/
+
+/* x- and y-coordinates for each block, defined in h264bsd_intra_prediction.c */
+extern const u32 h264bsdBlockX[];
+extern const u32 h264bsdBlockY[];
+
+/* clipping table, defined in h264bsd_intra_prediction.c */
+extern const u8 h264bsdClip[];
+
+/*------------------------------------------------------------------------------
+    4. Local function prototypes
+------------------------------------------------------------------------------*/
+
+
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdWriteMacroblock
+
+        Functional description:
+            Write one macroblock into the image. Both luma and chroma
+            components will be written at the same time.
+
+        Inputs:
+            data    pointer to macroblock data to be written, 256 values for
+                    luma followed by 64 values for both chroma components
+
+        Outputs:
+            image   pointer to the image where the macroblock will be written
+
+        Returns:
+            none
+
+------------------------------------------------------------------------------*/
+#ifndef H264DEC_NEON
+void h264bsdWriteMacroblock(image_t *image, u8 *data)
+{
+
+/* Variables */
+
+    u32 i;
+    u32 width;
+    u32 *lum, *cb, *cr;
+    u32 *ptr;
+    u32 tmp1, tmp2;
+
+/* Code */
+
+    ASSERT(image);
+    ASSERT(data);
+    ASSERT(!((u32)data&0x3));
+
+    width = image->width;
+
+    /*lint -save -e826 lum, cb and cr used to copy 4 bytes at the time, disable
+     * "area too small" info message */
+    lum = (u32*)image->luma;
+    cb = (u32*)image->cb;
+    cr = (u32*)image->cr;
+    ASSERT(!((u32)lum&0x3));
+    ASSERT(!((u32)cb&0x3));
+    ASSERT(!((u32)cr&0x3));
+
+    ptr = (u32*)data;
+
+    width *= 4;
+    for (i = 16; i ; i--)
+    {
+        tmp1 = *ptr++;
+        tmp2 = *ptr++;
+        *lum++ = tmp1;
+        *lum++ = tmp2;
+        tmp1 = *ptr++;
+        tmp2 = *ptr++;
+        *lum++ = tmp1;
+        *lum++ = tmp2;
+        lum += width-4;
+    }
+
+    width >>= 1;
+    for (i = 8; i ; i--)
+    {
+        tmp1 = *ptr++;
+        tmp2 = *ptr++;
+        *cb++ = tmp1;
+        *cb++ = tmp2;
+        cb += width-2;
+    }
+
+    for (i = 8; i ; i--)
+    {
+        tmp1 = *ptr++;
+        tmp2 = *ptr++;
+        *cr++ = tmp1;
+        *cr++ = tmp2;
+        cr += width-2;
+    }
+
+}
+#endif
+#ifndef H264DEC_OMXDL
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdWriteOutputBlocks
+
+        Functional description:
+            Write one macroblock into the image. Prediction for the macroblock
+            and the residual are given separately and will be combined while
+            writing the data to the image
+
+        Inputs:
+            data        pointer to macroblock prediction data, 256 values for
+                        luma followed by 64 values for both chroma components
+            mbNum       number of the macroblock
+            residual    pointer to residual data, 16 16-element arrays for luma
+                        followed by 4 16-element arrays for both chroma
+                        components
+
+        Outputs:
+            image       pointer to the image where the data will be written
+
+        Returns:
+            none
+
+------------------------------------------------------------------------------*/
+
+void h264bsdWriteOutputBlocks(image_t *image, u32 mbNum, u8 *data,
+        i32 residual[][16])
+{
+
+/* Variables */
+
+    u32 i;
+    u32 picWidth, picSize;
+    u8 *lum, *cb, *cr;
+    u8 *imageBlock;
+    u8 *tmp;
+    u32 row, col;
+    u32 block;
+    u32 x, y;
+    i32 *pRes;
+    i32 tmp1, tmp2, tmp3, tmp4;
+    const u8 *clp = h264bsdClip + 512;
+
+/* Code */
+
+    ASSERT(image);
+    ASSERT(data);
+    ASSERT(mbNum < image->width * image->height);
+    ASSERT(!((u32)data&0x3));
+
+    /* Image size in macroblocks */
+    picWidth = image->width;
+    picSize = picWidth * image->height;
+    row = mbNum / picWidth;
+    col = mbNum % picWidth;
+
+    /* Output macroblock position in output picture */
+    lum = (image->data + row * picWidth * 256 + col * 16);
+    cb = (image->data + picSize * 256 + row * picWidth * 64 + col * 8);
+    cr = (cb + picSize * 64);
+
+    picWidth *= 16;
+
+    for (block = 0; block < 16; block++)
+    {
+        x = h264bsdBlockX[block];
+        y = h264bsdBlockY[block];
+
+        pRes = residual[block];
+
+        ASSERT(pRes);
+
+        tmp = data + y*16 + x;
+        imageBlock = lum + y*picWidth + x;
+
+        ASSERT(!((u32)tmp&0x3));
+        ASSERT(!((u32)imageBlock&0x3));
+
+        if (IS_RESIDUAL_EMPTY(pRes))
+        {
+            /*lint -e826 */
+            i32 *in32 = (i32*)tmp;
+            i32 *out32 = (i32*)imageBlock;
+
+            /* Residual is zero => copy prediction block to output */
+            tmp1 = *in32;  in32 += 4;
+            tmp2 = *in32;  in32 += 4;
+            *out32 = tmp1; out32 += picWidth/4;
+            *out32 = tmp2; out32 += picWidth/4;
+            tmp1 = *in32;  in32 += 4;
+            tmp2 = *in32;
+            *out32 = tmp1; out32 += picWidth/4;
+            *out32 = tmp2;
+        }
+        else
+        {
+
+            RANGE_CHECK_ARRAY(pRes, -512, 511, 16);
+
+            /* Calculate image = prediction + residual
+             * Process four pixels in a loop */
+            for (i = 4; i; i--)
+            {
+                tmp1 = tmp[0];
+                tmp2 = *pRes++;
+                tmp3 = tmp[1];
+                tmp1 = clp[tmp1 + tmp2];
+                tmp4 = *pRes++;
+                imageBlock[0] = (u8)tmp1;
+                tmp3 = clp[tmp3 + tmp4];
+                tmp1 = tmp[2];
+                tmp2 = *pRes++;
+                imageBlock[1] = (u8)tmp3;
+                tmp1 = clp[tmp1 + tmp2];
+                tmp3 = tmp[3];
+                tmp4 = *pRes++;
+                imageBlock[2] = (u8)tmp1;
+                tmp3 = clp[tmp3 + tmp4];
+                tmp += 16;
+                imageBlock[3] = (u8)tmp3;
+                imageBlock += picWidth;
+            }
+        }
+
+    }
+
+    picWidth /= 2;
+
+    for (block = 16; block <= 23; block++)
+    {
+        x = h264bsdBlockX[block & 0x3];
+        y = h264bsdBlockY[block & 0x3];
+
+        pRes = residual[block];
+
+        ASSERT(pRes);
+
+        tmp = data + 256;
+        imageBlock = cb;
+
+        if (block >= 20)
+        {
+            imageBlock = cr;
+            tmp += 64;
+        }
+
+        tmp += y*8 + x;
+        imageBlock += y*picWidth + x;
+
+        ASSERT(!((u32)tmp&0x3));
+        ASSERT(!((u32)imageBlock&0x3));
+
+        if (IS_RESIDUAL_EMPTY(pRes))
+        {
+            /*lint -e826 */
+            i32 *in32 = (i32*)tmp;
+            i32 *out32 = (i32*)imageBlock;
+
+            /* Residual is zero => copy prediction block to output */
+            tmp1 = *in32;  in32 += 2;
+            tmp2 = *in32;  in32 += 2;
+            *out32 = tmp1; out32 += picWidth/4;
+            *out32 = tmp2; out32 += picWidth/4;
+            tmp1 = *in32;  in32 += 2;
+            tmp2 = *in32;
+            *out32 = tmp1; out32 += picWidth/4;
+            *out32 = tmp2;
+        }
+        else
+        {
+
+            RANGE_CHECK_ARRAY(pRes, -512, 511, 16);
+
+            for (i = 4; i; i--)
+            {
+                tmp1 = tmp[0];
+                tmp2 = *pRes++;
+                tmp3 = tmp[1];
+                tmp1 = clp[tmp1 + tmp2];
+                tmp4 = *pRes++;
+                imageBlock[0] = (u8)tmp1;
+                tmp3 = clp[tmp3 + tmp4];
+                tmp1 = tmp[2];
+                tmp2 = *pRes++;
+                imageBlock[1] = (u8)tmp3;
+                tmp1 = clp[tmp1 + tmp2];
+                tmp3 = tmp[3];
+                tmp4 = *pRes++;
+                imageBlock[2] = (u8)tmp1;
+                tmp3 = clp[tmp3 + tmp4];
+                tmp += 8;
+                imageBlock[3] = (u8)tmp3;
+                imageBlock += picWidth;
+            }
+        }
+    }
+
+}
+#endif /* H264DEC_OMXDL */
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_image.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_image.h
new file mode 100755
index 0000000..ed7c18c
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_image.h
@@ -0,0 +1,68 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+    1. Include headers
+    2. Module defines
+    3. Data types
+    4. Function prototypes
+
+------------------------------------------------------------------------------*/
+
+#ifndef H264SWDEC_IMAGE_H
+#define H264SWDEC_IMAGE_H
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "basetype.h"
+
+/*------------------------------------------------------------------------------
+    2. Module defines
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    3. Data types
+------------------------------------------------------------------------------*/
+
+typedef struct
+{
+    u8 *data;
+    u32 width;
+    u32 height;
+    /* current MB's components */
+    u8 *luma;
+    u8 *cb;
+    u8 *cr;
+} image_t;
+
+/*------------------------------------------------------------------------------
+    4. Function prototypes
+------------------------------------------------------------------------------*/
+
+void h264bsdWriteMacroblock(image_t *image, u8 *data);
+
+#ifndef H264DEC_OMXDL
+void h264bsdWriteOutputBlocks(image_t *image, u32 mbNum, u8 *data,
+    i32 residual[][16]);
+#endif
+
+#endif /* #ifdef H264SWDEC_IMAGE_H */
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_inter_prediction.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_inter_prediction.c
new file mode 100755
index 0000000..2a81c4a
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_inter_prediction.c
@@ -0,0 +1,1027 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+     1. Include headers
+     2. External compiler flags
+     3. Module defines
+     4. Local function prototypes
+     5. Functions
+          h264bsdInterPrediction
+          MvPrediction16x16
+          MvPrediction16x8
+          MvPrediction8x16
+          MvPrediction8x8
+          MvPrediction
+          MedianFilter
+          GetInterNeighbour
+          GetPredictionMv
+
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "h264bsd_inter_prediction.h"
+#include "h264bsd_neighbour.h"
+#include "h264bsd_util.h"
+#include "h264bsd_reconstruct.h"
+#include "h264bsd_dpb.h"
+
+/*------------------------------------------------------------------------------
+    2. External compiler flags
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+    3. Module defines
+------------------------------------------------------------------------------*/
+
+typedef struct
+{
+    u32 available;
+    u32 refIndex;
+    mv_t mv;
+} interNeighbour_t;
+
+/*------------------------------------------------------------------------------
+    4. Local function prototypes
+------------------------------------------------------------------------------*/
+
+static u32 MvPrediction16x16(mbStorage_t *pMb, mbPred_t *mbPred,
+    dpbStorage_t *dpb);
+static u32 MvPrediction16x8(mbStorage_t *pMb, mbPred_t *mbPred,
+    dpbStorage_t *dpb);
+static u32 MvPrediction8x16(mbStorage_t *pMb, mbPred_t *mbPred,
+    dpbStorage_t *dpb);
+static u32 MvPrediction8x8(mbStorage_t *pMb, subMbPred_t *subMbPred,
+    dpbStorage_t *dpb);
+static u32 MvPrediction(mbStorage_t *pMb, subMbPred_t *subMbPred,
+    u32 mbPartIdx, u32 subMbPartIdx);
+static i32 MedianFilter(i32 a, i32 b, i32 c);
+
+static void GetInterNeighbour(u32 sliceId, mbStorage_t *nMb,
+    interNeighbour_t *n, u32 index);
+static void GetPredictionMv(mv_t *mv, interNeighbour_t *a, u32 refIndex);
+
+static const neighbour_t N_A_SUB_PART[4][4][4] = {
+    { { {MB_A,5}, {MB_NA,0}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_A,5}, {MB_A,7}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_A,5}, {MB_CURR,0}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_A,5}, {MB_CURR,0}, {MB_A,7}, {MB_CURR,2} } },
+
+    { { {MB_CURR,1}, {MB_NA,0}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_CURR,1}, {MB_CURR,3}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_CURR,1}, {MB_CURR,4}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_CURR,1}, {MB_CURR,4}, {MB_CURR,3}, {MB_CURR,6} } },
+
+    { { {MB_A,13}, {MB_NA,0}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_A,13}, {MB_A,15}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_A,13}, {MB_CURR,8}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_A,13}, {MB_CURR,8}, {MB_A,15}, {MB_CURR,10} } },
+
+    { { {MB_CURR,9}, {MB_NA,0}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_CURR,9}, {MB_CURR,11}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_CURR,9}, {MB_CURR,12}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_CURR,9}, {MB_CURR,12}, {MB_CURR,11}, {MB_CURR,14} } } };
+
+static const neighbour_t N_B_SUB_PART[4][4][4] = {
+    { { {MB_B,10}, {MB_NA,0}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_B,10}, {MB_CURR,0}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_B,10}, {MB_B,11}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_B,10}, {MB_B,11}, {MB_CURR,0}, {MB_CURR,1} } },
+
+    { { {MB_B,14}, {MB_NA,0}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_B,14}, {MB_CURR,4}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_B,14}, {MB_B,15}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_B,14}, {MB_B,15}, {MB_CURR,4}, {MB_CURR,5} } },
+
+    { { {MB_CURR,2}, {MB_NA,0}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_CURR,2}, {MB_CURR,8}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_CURR,2}, {MB_CURR,3}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_CURR,2}, {MB_CURR,3}, {MB_CURR,8}, {MB_CURR,9} } },
+
+    { { {MB_CURR,6}, {MB_NA,0}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_CURR,6}, {MB_CURR,12}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_CURR,6}, {MB_CURR,7}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_CURR,6}, {MB_CURR,7}, {MB_CURR,12}, {MB_CURR,13} } } };
+
+static const neighbour_t N_C_SUB_PART[4][4][4] = {
+    { { {MB_B,14}, {MB_NA,0}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_B,14}, {MB_NA,4}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_B,11}, {MB_B,14}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_B,11}, {MB_B,14}, {MB_CURR,1}, {MB_NA,4} } },
+
+    { { {MB_C,10}, {MB_NA,0}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_C,10}, {MB_NA,0}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_B,15}, {MB_C,10}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_B,15}, {MB_C,10}, {MB_CURR,5}, {MB_NA,0} } },
+
+    { { {MB_CURR,6}, {MB_NA,0}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_CURR,6}, {MB_NA,12}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_CURR,3}, {MB_CURR,6}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_CURR,3}, {MB_CURR,6}, {MB_CURR,9}, {MB_NA,12} } },
+
+    { { {MB_NA,2}, {MB_NA,0}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_NA,2}, {MB_NA,8}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_CURR,7}, {MB_NA,2}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_CURR,7}, {MB_NA,2}, {MB_CURR,13}, {MB_NA,8} } } };
+
+static const neighbour_t N_D_SUB_PART[4][4][4] = {
+    { { {MB_D,15}, {MB_NA,0}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_D,15}, {MB_A,5}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_D,15}, {MB_B,10}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_D,15}, {MB_B,10}, {MB_A,5}, {MB_CURR,0} } },
+
+    { { {MB_B,11}, {MB_NA,0}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_B,11}, {MB_CURR,1}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_B,11}, {MB_B,14}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_B,11}, {MB_B,14}, {MB_CURR,1}, {MB_CURR,4} } },
+
+    { { {MB_A,7}, {MB_NA,0}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_A,7}, {MB_A,13}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_A,7}, {MB_CURR,2}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_A,7}, {MB_CURR,2}, {MB_A,13}, {MB_CURR,8} } },
+
+    { { {MB_CURR,3}, {MB_NA,0}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_CURR,3}, {MB_CURR,9}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_CURR,3}, {MB_CURR,6}, {MB_NA,0}, {MB_NA,0} },
+      { {MB_CURR,3}, {MB_CURR,6}, {MB_CURR,9}, {MB_CURR,12} } } };
+
+
+#ifdef H264DEC_OMXDL
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdInterPrediction
+
+        Functional description:
+          Processes one inter macroblock. Performs motion vector prediction
+          and reconstructs prediction macroblock. Writes the final macroblock
+          (prediction + residual) into the output image (currImage)
+
+        Inputs:
+          pMb           pointer to macroblock specific information
+          pMbLayer      pointer to current macroblock data from stream
+          dpb           pointer to decoded picture buffer
+          mbNum         current macroblock number
+          currImage     pointer to output image
+          data          pointer where predicted macroblock will be stored
+
+        Outputs:
+          pMb           structure is updated with current macroblock
+          currImage     current macroblock is written into image
+          data          prediction is stored here
+
+        Returns:
+          HANTRO_OK     success
+          HANTRO_NOK    error in motion vector prediction
+
+------------------------------------------------------------------------------*/
+u32 h264bsdInterPrediction(mbStorage_t *pMb, macroblockLayer_t *pMbLayer,
+    dpbStorage_t *dpb, u32 mbNum, image_t *currImage, u8 *data)
+{
+
+/* Variables */
+
+    u32 i;
+    u32 x, y;
+    u32 colAndRow;
+    subMbPartMode_e subPartMode;
+    image_t refImage;
+    u8 fillBuff[32*21 + 15 + 32];
+    u8 *pFill;
+    u32 tmp;
+/* Code */
+
+    ASSERT(pMb);
+    ASSERT(h264bsdMbPartPredMode(pMb->mbType) == PRED_MODE_INTER);
+    ASSERT(pMbLayer);
+
+    /* 16-byte alignment */
+    pFill = ALIGN(fillBuff, 16);
+
+    /* set row bits 15:0 */
+    colAndRow = mbNum / currImage->width;
+    /*set col to bits 31:16 */
+    colAndRow += (mbNum - colAndRow * currImage->width) << 16;
+    colAndRow <<= 4;
+
+    refImage.width = currImage->width;
+    refImage.height = currImage->height;
+
+    switch (pMb->mbType)
+    {
+        case P_Skip:
+        case P_L0_16x16:
+            if (MvPrediction16x16(pMb, &pMbLayer->mbPred, dpb) != HANTRO_OK)
+                return(HANTRO_NOK);
+            refImage.data = pMb->refAddr[0];
+            tmp = (0<<24) + (0<<16) + (16<<8) + 16;
+            h264bsdPredictSamples(data, pMb->mv, &refImage,
+                                    colAndRow, tmp, pFill);
+            break;
+
+        case P_L0_L0_16x8:
+            if ( MvPrediction16x8(pMb, &pMbLayer->mbPred, dpb) != HANTRO_OK)
+                return(HANTRO_NOK);
+            refImage.data = pMb->refAddr[0];
+            tmp = (0<<24) + (0<<16) + (16<<8) + 8;
+            h264bsdPredictSamples(data, pMb->mv, &refImage,
+                                    colAndRow, tmp, pFill);
+
+            refImage.data = pMb->refAddr[2];
+            tmp = (0<<24) + (8<<16) + (16<<8) + 8;
+            h264bsdPredictSamples(data, pMb->mv+8, &refImage,
+                                    colAndRow, tmp, pFill);
+            break;
+
+        case P_L0_L0_8x16:
+            if ( MvPrediction8x16(pMb, &pMbLayer->mbPred, dpb) != HANTRO_OK)
+                return(HANTRO_NOK);
+            refImage.data = pMb->refAddr[0];
+            tmp = (0<<24) + (0<<16) + (8<<8) + 16;
+            h264bsdPredictSamples(data, pMb->mv, &refImage,
+                                    colAndRow, tmp, pFill);
+            refImage.data = pMb->refAddr[1];
+            tmp = (8<<24) + (0<<16) + (8<<8) + 16;
+            h264bsdPredictSamples(data, pMb->mv+4, &refImage,
+                                    colAndRow, tmp, pFill);
+            break;
+
+        default: /* P_8x8 and P_8x8ref0 */
+            if ( MvPrediction8x8(pMb, &pMbLayer->subMbPred, dpb) != HANTRO_OK)
+                return(HANTRO_NOK);
+            for (i = 0; i < 4; i++)
+            {
+                refImage.data = pMb->refAddr[i];
+                subPartMode =
+                    h264bsdSubMbPartMode(pMbLayer->subMbPred.subMbType[i]);
+                x = i & 0x1 ? 8 : 0;
+                y = i < 2 ? 0 : 8;
+                switch (subPartMode)
+                {
+                    case MB_SP_8x8:
+                        tmp = (x<<24) + (y<<16) + (8<<8) + 8;
+                        h264bsdPredictSamples(data, pMb->mv+4*i, &refImage,
+                                                    colAndRow, tmp, pFill);
+                        break;
+
+                    case MB_SP_8x4:
+                        tmp = (x<<24) + (y<<16) + (8<<8) + 4;
+                        h264bsdPredictSamples(data, pMb->mv+4*i, &refImage,
+                                                    colAndRow, tmp, pFill);
+                        tmp = (x<<24) + ((y+4)<<16) + (8<<8) + 4;
+                        h264bsdPredictSamples(data, pMb->mv+4*i+2, &refImage,
+                                                    colAndRow, tmp, pFill);
+                        break;
+
+                    case MB_SP_4x8:
+                        tmp = (x<<24) + (y<<16) + (4<<8) + 8;
+                        h264bsdPredictSamples(data, pMb->mv+4*i, &refImage,
+                                                    colAndRow, tmp, pFill);
+                        tmp = ((x+4)<<24) + (y<<16) + (4<<8) + 8;
+                        h264bsdPredictSamples(data, pMb->mv+4*i+1, &refImage,
+                                                    colAndRow, tmp, pFill);
+                        break;
+
+                    default:
+                        tmp = (x<<24) + (y<<16) + (4<<8) + 4;
+                        h264bsdPredictSamples(data, pMb->mv+4*i, &refImage,
+                                                    colAndRow, tmp, pFill);
+                        tmp = ((x+4)<<24) + (y<<16) + (4<<8) + 4;
+                        h264bsdPredictSamples(data, pMb->mv+4*i+1, &refImage,
+                                                    colAndRow, tmp, pFill);
+                        tmp = (x<<24) + ((y+4)<<16) + (4<<8) + 4;
+                        h264bsdPredictSamples(data, pMb->mv+4*i+2, &refImage,
+                                                    colAndRow, tmp, pFill);
+                        tmp = ((x+4)<<24) + ((y+4)<<16) + (4<<8) + 4;
+                        h264bsdPredictSamples(data, pMb->mv+4*i+3, &refImage,
+                                                    colAndRow, tmp, pFill);
+                        break;
+                }
+            }
+            break;
+    }
+
+    /* if decoded flag > 1 -> mb has already been successfully decoded and
+     * written to output -> do not write again */
+    if (pMb->decoded > 1)
+        return HANTRO_OK;
+
+    return(HANTRO_OK);
+}
+
+#else /* H264DEC_OMXDL */
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdInterPrediction
+
+        Functional description:
+          Processes one inter macroblock. Performs motion vector prediction
+          and reconstructs prediction macroblock. Writes the final macroblock
+          (prediction + residual) into the output image (currImage)
+
+        Inputs:
+          pMb           pointer to macroblock specific information
+          pMbLayer      pointer to current macroblock data from stream
+          dpb           pointer to decoded picture buffer
+          mbNum         current macroblock number
+          currImage     pointer to output image
+          data          pointer where predicted macroblock will be stored
+
+        Outputs:
+          pMb           structure is updated with current macroblock
+          currImage     current macroblock is written into image
+          data          prediction is stored here
+
+        Returns:
+          HANTRO_OK     success
+          HANTRO_NOK    error in motion vector prediction
+
+------------------------------------------------------------------------------*/
+u32 h264bsdInterPrediction(mbStorage_t *pMb, macroblockLayer_t *pMbLayer,
+    dpbStorage_t *dpb, u32 mbNum, image_t *currImage, u8 *data)
+{
+
+/* Variables */
+
+    u32 i;
+    u32 x, y;
+    u32 row, col;
+    subMbPartMode_e subPartMode;
+    image_t refImage;
+
+/* Code */
+
+    ASSERT(pMb);
+    ASSERT(h264bsdMbPartPredMode(pMb->mbType) == PRED_MODE_INTER);
+    ASSERT(pMbLayer);
+
+    row = mbNum / currImage->width;
+    col = mbNum - row * currImage->width;
+    row *= 16;
+    col *= 16;
+
+    refImage.width = currImage->width;
+    refImage.height = currImage->height;
+
+    switch (pMb->mbType)
+    {
+        case P_Skip:
+        case P_L0_16x16:
+            if (MvPrediction16x16(pMb, &pMbLayer->mbPred, dpb) != HANTRO_OK)
+                return(HANTRO_NOK);
+            refImage.data = pMb->refAddr[0];
+            h264bsdPredictSamples(data, pMb->mv, &refImage, col, row, 0, 0,
+                16, 16);
+            break;
+
+        case P_L0_L0_16x8:
+            if ( MvPrediction16x8(pMb, &pMbLayer->mbPred, dpb) != HANTRO_OK)
+                return(HANTRO_NOK);
+            refImage.data = pMb->refAddr[0];
+            h264bsdPredictSamples(data, pMb->mv, &refImage, col, row, 0, 0,
+                16, 8);
+            refImage.data = pMb->refAddr[2];
+            h264bsdPredictSamples(data, pMb->mv+8, &refImage, col, row, 0, 8,
+                16, 8);
+            break;
+
+        case P_L0_L0_8x16:
+            if ( MvPrediction8x16(pMb, &pMbLayer->mbPred, dpb) != HANTRO_OK)
+                return(HANTRO_NOK);
+            refImage.data = pMb->refAddr[0];
+            h264bsdPredictSamples(data, pMb->mv, &refImage, col, row, 0, 0,
+                8, 16);
+            refImage.data = pMb->refAddr[1];
+            h264bsdPredictSamples(data, pMb->mv+4, &refImage, col, row, 8, 0,
+                8, 16);
+            break;
+
+        default: /* P_8x8 and P_8x8ref0 */
+            if ( MvPrediction8x8(pMb, &pMbLayer->subMbPred, dpb) != HANTRO_OK)
+                return(HANTRO_NOK);
+            for (i = 0; i < 4; i++)
+            {
+                refImage.data = pMb->refAddr[i];
+                subPartMode =
+                    h264bsdSubMbPartMode(pMbLayer->subMbPred.subMbType[i]);
+                x = i & 0x1 ? 8 : 0;
+                y = i < 2 ? 0 : 8;
+                switch (subPartMode)
+                {
+                    case MB_SP_8x8:
+                        h264bsdPredictSamples(data, pMb->mv+4*i, &refImage,
+                            col, row, x, y, 8, 8);
+                        break;
+
+                    case MB_SP_8x4:
+                        h264bsdPredictSamples(data, pMb->mv+4*i, &refImage,
+                            col, row, x, y, 8, 4);
+                        h264bsdPredictSamples(data, pMb->mv+4*i+2, &refImage,
+                            col, row, x, y+4, 8, 4);
+                        break;
+
+                    case MB_SP_4x8:
+                        h264bsdPredictSamples(data, pMb->mv+4*i, &refImage,
+                            col, row, x, y, 4, 8);
+                        h264bsdPredictSamples(data, pMb->mv+4*i+1, &refImage,
+                            col, row, x+4, y, 4, 8);
+                        break;
+
+                    default:
+                        h264bsdPredictSamples(data, pMb->mv+4*i, &refImage,
+                            col, row, x, y, 4, 4);
+                        h264bsdPredictSamples(data, pMb->mv+4*i+1, &refImage,
+                            col, row, x+4, y, 4, 4);
+                        h264bsdPredictSamples(data, pMb->mv+4*i+2, &refImage,
+                            col, row, x, y+4, 4, 4);
+                        h264bsdPredictSamples(data, pMb->mv+4*i+3, &refImage,
+                            col, row, x+4, y+4, 4, 4);
+                        break;
+                }
+            }
+            break;
+    }
+
+    /* if decoded flag > 1 -> mb has already been successfully decoded and
+     * written to output -> do not write again */
+    if (pMb->decoded > 1)
+        return HANTRO_OK;
+
+    if (pMb->mbType != P_Skip)
+    {
+        h264bsdWriteOutputBlocks(currImage, mbNum, data,
+            pMbLayer->residual.level);
+    }
+    else
+    {
+        h264bsdWriteMacroblock(currImage, data);
+    }
+
+    return(HANTRO_OK);
+}
+#endif /* H264DEC_OMXDL */
+
+/*------------------------------------------------------------------------------
+
+    Function: MvPrediction16x16
+
+        Functional description:
+            Motion vector prediction for 16x16 partition mode
+
+------------------------------------------------------------------------------*/
+
+u32 MvPrediction16x16(mbStorage_t *pMb, mbPred_t *mbPred, dpbStorage_t *dpb)
+{
+
+/* Variables */
+
+    mv_t mv;
+    mv_t mvPred;
+    interNeighbour_t a[3]; /* A, B, C */
+    u32 refIndex;
+    u8 *tmp;
+    u32 *tmpMv1, *tmpMv2;
+
+/* Code */
+
+    refIndex = mbPred->refIdxL0[0];
+
+    GetInterNeighbour(pMb->sliceId, pMb->mbA, a, 5);
+    GetInterNeighbour(pMb->sliceId, pMb->mbB, a+1, 10);
+    /*lint --e(740)  Unusual pointer cast (incompatible indirect types) */
+    tmpMv1 = (u32*)(&a[0].mv); /* we test just that both MVs are zero */
+    /*lint --e(740) */
+    tmpMv2 = (u32*)(&a[1].mv); /* i.e. a[0].mv.hor == 0 && a[0].mv.ver == 0 */
+    if (pMb->mbType == P_Skip &&
+        (!a[0].available || !a[1].available ||
+         ( a[0].refIndex == 0 && ((u32)(*tmpMv1) == 0) ) ||
+         ( a[1].refIndex == 0 && ((u32)(*tmpMv2) == 0) )))
+    {
+            mv.hor = mv.ver = 0;
+    }
+    else
+    {
+        mv = mbPred->mvdL0[0];
+        GetInterNeighbour(pMb->sliceId, pMb->mbC, a+2, 10);
+        if (!a[2].available)
+        {
+            GetInterNeighbour(pMb->sliceId, pMb->mbD, a+2, 15);
+        }
+
+        GetPredictionMv(&mvPred, a, refIndex);
+
+        mv.hor += mvPred.hor;
+        mv.ver += mvPred.ver;
+
+        /* horizontal motion vector range [-2048, 2047.75] */
+        if ((u32)(i32)(mv.hor+8192) >= (16384))
+            return(HANTRO_NOK);
+
+        /* vertical motion vector range [-512, 511.75]
+         * (smaller for low levels) */
+        if ((u32)(i32)(mv.ver+2048) >= (4096))
+            return(HANTRO_NOK);
+    }
+
+    tmp = h264bsdGetRefPicData(dpb, refIndex);
+    if (tmp == NULL)
+        return(HANTRO_NOK);
+
+    pMb->mv[0] = pMb->mv[1] = pMb->mv[2] = pMb->mv[3] =
+    pMb->mv[4] = pMb->mv[5] = pMb->mv[6] = pMb->mv[7] =
+    pMb->mv[8] = pMb->mv[9] = pMb->mv[10] = pMb->mv[11] =
+    pMb->mv[12] = pMb->mv[13] = pMb->mv[14] = pMb->mv[15] = mv;
+
+    pMb->refPic[0] = refIndex;
+    pMb->refPic[1] = refIndex;
+    pMb->refPic[2] = refIndex;
+    pMb->refPic[3] = refIndex;
+    pMb->refAddr[0] = tmp;
+    pMb->refAddr[1] = tmp;
+    pMb->refAddr[2] = tmp;
+    pMb->refAddr[3] = tmp;
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: MvPrediction16x8
+
+        Functional description:
+            Motion vector prediction for 16x8 partition mode
+
+------------------------------------------------------------------------------*/
+
+u32 MvPrediction16x8(mbStorage_t *pMb, mbPred_t *mbPred, dpbStorage_t *dpb)
+{
+
+/* Variables */
+
+    mv_t mv;
+    mv_t mvPred;
+    interNeighbour_t a[3]; /* A, B, C */
+    u32 refIndex;
+    u8 *tmp;
+
+/* Code */
+
+    mv = mbPred->mvdL0[0];
+    refIndex = mbPred->refIdxL0[0];
+
+    GetInterNeighbour(pMb->sliceId, pMb->mbB, a+1, 10);
+
+    if (a[1].refIndex == refIndex)
+        mvPred = a[1].mv;
+    else
+    {
+        GetInterNeighbour(pMb->sliceId, pMb->mbA, a, 5);
+        GetInterNeighbour(pMb->sliceId, pMb->mbC, a+2, 10);
+        if (!a[2].available)
+        {
+            GetInterNeighbour(pMb->sliceId, pMb->mbD, a+2, 15);
+        }
+
+        GetPredictionMv(&mvPred, a, refIndex);
+
+    }
+    mv.hor += mvPred.hor;
+    mv.ver += mvPred.ver;
+
+    /* horizontal motion vector range [-2048, 2047.75] */
+    if ((u32)(i32)(mv.hor+8192) >= (16384))
+        return(HANTRO_NOK);
+
+    /* vertical motion vector range [-512, 511.75] (smaller for low levels) */
+    if ((u32)(i32)(mv.ver+2048) >= (4096))
+        return(HANTRO_NOK);
+
+    tmp = h264bsdGetRefPicData(dpb, refIndex);
+    if (tmp == NULL)
+        return(HANTRO_NOK);
+
+    pMb->mv[0] = pMb->mv[1] = pMb->mv[2] = pMb->mv[3] =
+    pMb->mv[4] = pMb->mv[5] = pMb->mv[6] = pMb->mv[7] = mv;
+    pMb->refPic[0] = refIndex;
+    pMb->refPic[1] = refIndex;
+    pMb->refAddr[0] = tmp;
+    pMb->refAddr[1] = tmp;
+
+    mv = mbPred->mvdL0[1];
+    refIndex = mbPred->refIdxL0[1];
+
+    GetInterNeighbour(pMb->sliceId, pMb->mbA, a, 13);
+    if (a[0].refIndex == refIndex)
+        mvPred = a[0].mv;
+    else
+    {
+        a[1].available = HANTRO_TRUE;
+        a[1].refIndex = pMb->refPic[0];
+        a[1].mv = pMb->mv[0];
+
+        /* c is not available */
+        GetInterNeighbour(pMb->sliceId, pMb->mbA, a+2, 7);
+
+        GetPredictionMv(&mvPred, a, refIndex);
+
+    }
+    mv.hor += mvPred.hor;
+    mv.ver += mvPred.ver;
+
+    /* horizontal motion vector range [-2048, 2047.75] */
+    if ((u32)(i32)(mv.hor+8192) >= (16384))
+        return(HANTRO_NOK);
+
+    /* vertical motion vector range [-512, 511.75] (smaller for low levels) */
+    if ((u32)(i32)(mv.ver+2048) >= (4096))
+        return(HANTRO_NOK);
+
+    tmp = h264bsdGetRefPicData(dpb, refIndex);
+    if (tmp == NULL)
+        return(HANTRO_NOK);
+
+    pMb->mv[8] = pMb->mv[9] = pMb->mv[10] = pMb->mv[11] =
+    pMb->mv[12] = pMb->mv[13] = pMb->mv[14] = pMb->mv[15] = mv;
+    pMb->refPic[2] = refIndex;
+    pMb->refPic[3] = refIndex;
+    pMb->refAddr[2] = tmp;
+    pMb->refAddr[3] = tmp;
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: MvPrediction8x16
+
+        Functional description:
+            Motion vector prediction for 8x16 partition mode
+
+------------------------------------------------------------------------------*/
+
+u32 MvPrediction8x16(mbStorage_t *pMb, mbPred_t *mbPred, dpbStorage_t *dpb)
+{
+
+/* Variables */
+
+    mv_t mv;
+    mv_t mvPred;
+    interNeighbour_t a[3]; /* A, B, C */
+    u32 refIndex;
+    u8 *tmp;
+
+/* Code */
+
+    mv = mbPred->mvdL0[0];
+    refIndex = mbPred->refIdxL0[0];
+
+    GetInterNeighbour(pMb->sliceId, pMb->mbA, a, 5);
+
+    if (a[0].refIndex == refIndex)
+        mvPred = a[0].mv;
+    else
+    {
+        GetInterNeighbour(pMb->sliceId, pMb->mbB, a+1, 10);
+        GetInterNeighbour(pMb->sliceId, pMb->mbB, a+2, 14);
+        if (!a[2].available)
+        {
+            GetInterNeighbour(pMb->sliceId, pMb->mbD, a+2, 15);
+        }
+
+        GetPredictionMv(&mvPred, a, refIndex);
+
+    }
+    mv.hor += mvPred.hor;
+    mv.ver += mvPred.ver;
+
+    /* horizontal motion vector range [-2048, 2047.75] */
+    if ((u32)(i32)(mv.hor+8192) >= (16384))
+        return(HANTRO_NOK);
+
+    /* vertical motion vector range [-512, 511.75] (smaller for low levels) */
+    if ((u32)(i32)(mv.ver+2048) >= (4096))
+        return(HANTRO_NOK);
+
+    tmp = h264bsdGetRefPicData(dpb, refIndex);
+    if (tmp == NULL)
+        return(HANTRO_NOK);
+
+    pMb->mv[0] = pMb->mv[1] = pMb->mv[2] = pMb->mv[3] =
+    pMb->mv[8] = pMb->mv[9] = pMb->mv[10] = pMb->mv[11] = mv;
+    pMb->refPic[0] = refIndex;
+    pMb->refPic[2] = refIndex;
+    pMb->refAddr[0] = tmp;
+    pMb->refAddr[2] = tmp;
+
+    mv = mbPred->mvdL0[1];
+    refIndex = mbPred->refIdxL0[1];
+
+    GetInterNeighbour(pMb->sliceId, pMb->mbC, a+2, 10);
+    if (!a[2].available)
+    {
+        GetInterNeighbour(pMb->sliceId, pMb->mbB, a+2, 11);
+    }
+    if (a[2].refIndex == refIndex)
+        mvPred = a[2].mv;
+    else
+    {
+        a[0].available = HANTRO_TRUE;
+        a[0].refIndex = pMb->refPic[0];
+        a[0].mv = pMb->mv[0];
+
+        GetInterNeighbour(pMb->sliceId, pMb->mbB, a+1, 14);
+
+        GetPredictionMv(&mvPred, a, refIndex);
+
+    }
+    mv.hor += mvPred.hor;
+    mv.ver += mvPred.ver;
+
+    /* horizontal motion vector range [-2048, 2047.75] */
+    if ((u32)(i32)(mv.hor+8192) >= (16384))
+        return(HANTRO_NOK);
+
+    /* vertical motion vector range [-512, 511.75] (smaller for low levels) */
+    if ((u32)(i32)(mv.ver+2048) >= (4096))
+        return(HANTRO_NOK);
+
+    tmp = h264bsdGetRefPicData(dpb, refIndex);
+    if (tmp == NULL)
+        return(HANTRO_NOK);
+
+    pMb->mv[4] = pMb->mv[5] = pMb->mv[6] = pMb->mv[7] =
+    pMb->mv[12] = pMb->mv[13] = pMb->mv[14] = pMb->mv[15] = mv;
+    pMb->refPic[1] = refIndex;
+    pMb->refPic[3] = refIndex;
+    pMb->refAddr[1] = tmp;
+    pMb->refAddr[3] = tmp;
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: MvPrediction8x8
+
+        Functional description:
+            Motion vector prediction for 8x8 partition mode
+
+------------------------------------------------------------------------------*/
+
+u32 MvPrediction8x8(mbStorage_t *pMb, subMbPred_t *subMbPred, dpbStorage_t *dpb)
+{
+
+/* Variables */
+
+    u32 i, j;
+    u32 numSubMbPart;
+
+/* Code */
+
+    for (i = 0; i < 4; i++)
+    {
+        numSubMbPart = h264bsdNumSubMbPart(subMbPred->subMbType[i]);
+        pMb->refPic[i] = subMbPred->refIdxL0[i];
+        pMb->refAddr[i] = h264bsdGetRefPicData(dpb, subMbPred->refIdxL0[i]);
+        if (pMb->refAddr[i] == NULL)
+            return(HANTRO_NOK);
+        for (j = 0; j < numSubMbPart; j++)
+        {
+            if (MvPrediction(pMb, subMbPred, i, j) != HANTRO_OK)
+                return(HANTRO_NOK);
+        }
+    }
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: MvPrediction
+
+        Functional description:
+            Perform motion vector prediction for sub-partition
+
+------------------------------------------------------------------------------*/
+
+u32 MvPrediction(mbStorage_t *pMb, subMbPred_t *subMbPred, u32 mbPartIdx,
+    u32 subMbPartIdx)
+{
+
+/* Variables */
+
+    mv_t mv, mvPred;
+    u32 refIndex;
+    subMbPartMode_e subMbPartMode;
+    const neighbour_t *n;
+    mbStorage_t *nMb;
+    interNeighbour_t a[3]; /* A, B, C */
+
+/* Code */
+
+    mv = subMbPred->mvdL0[mbPartIdx][subMbPartIdx];
+    subMbPartMode = h264bsdSubMbPartMode(subMbPred->subMbType[mbPartIdx]);
+    refIndex = subMbPred->refIdxL0[mbPartIdx];
+
+    n = N_A_SUB_PART[mbPartIdx][subMbPartMode]+subMbPartIdx;
+    nMb = h264bsdGetNeighbourMb(pMb, n->mb);
+    GetInterNeighbour(pMb->sliceId, nMb, a, n->index);
+
+    n = N_B_SUB_PART[mbPartIdx][subMbPartMode]+subMbPartIdx;
+    nMb = h264bsdGetNeighbourMb(pMb, n->mb);
+    GetInterNeighbour(pMb->sliceId, nMb, a+1, n->index);
+
+    n = N_C_SUB_PART[mbPartIdx][subMbPartMode]+subMbPartIdx;
+    nMb = h264bsdGetNeighbourMb(pMb, n->mb);
+    GetInterNeighbour(pMb->sliceId, nMb, a+2, n->index);
+
+    if (!a[2].available)
+    {
+        n = N_D_SUB_PART[mbPartIdx][subMbPartMode]+subMbPartIdx;
+        nMb = h264bsdGetNeighbourMb(pMb, n->mb);
+        GetInterNeighbour(pMb->sliceId, nMb, a+2, n->index);
+    }
+
+    GetPredictionMv(&mvPred, a, refIndex);
+
+    mv.hor += mvPred.hor;
+    mv.ver += mvPred.ver;
+
+    /* horizontal motion vector range [-2048, 2047.75] */
+    if (((u32)(i32)(mv.hor+8192) >= (16384)))
+        return(HANTRO_NOK);
+
+    /* vertical motion vector range [-512, 511.75] (smaller for low levels) */
+    if (((u32)(i32)(mv.ver+2048) >= (4096)))
+        return(HANTRO_NOK);
+
+    switch (subMbPartMode)
+    {
+        case MB_SP_8x8:
+            pMb->mv[4*mbPartIdx] = mv;
+            pMb->mv[4*mbPartIdx + 1] = mv;
+            pMb->mv[4*mbPartIdx + 2] = mv;
+            pMb->mv[4*mbPartIdx + 3] = mv;
+            break;
+
+        case MB_SP_8x4:
+            pMb->mv[4*mbPartIdx + 2*subMbPartIdx] = mv;
+            pMb->mv[4*mbPartIdx + 2*subMbPartIdx + 1] = mv;
+            break;
+
+        case MB_SP_4x8:
+            pMb->mv[4*mbPartIdx + subMbPartIdx] = mv;
+            pMb->mv[4*mbPartIdx + subMbPartIdx + 2] = mv;
+            break;
+
+        case MB_SP_4x4:
+            pMb->mv[4*mbPartIdx + subMbPartIdx] = mv;
+            break;
+    }
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: MedianFilter
+
+        Functional description:
+            Median filtering for motion vector prediction
+
+------------------------------------------------------------------------------*/
+
+i32 MedianFilter(i32 a, i32 b, i32 c)
+{
+
+/* Variables */
+
+    i32 max,min,med;
+
+/* Code */
+
+    max = min = med = a;
+    if (b > max)
+    {
+        max = b;
+    }
+    else if (b < min)
+    {
+        min = b;
+    }
+    if (c > max)
+    {
+        med = max;
+    }
+    else if (c < min)
+    {
+        med = min;
+    }
+    else
+    {
+        med = c;
+    }
+
+    return(med);
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: GetInterNeighbour
+
+        Functional description:
+            Get availability, reference index and motion vector of a neighbour
+
+------------------------------------------------------------------------------*/
+
+void GetInterNeighbour(u32 sliceId, mbStorage_t *nMb,
+    interNeighbour_t *n, u32 index)
+{
+
+    n->available = HANTRO_FALSE;
+    n->refIndex = 0xFFFFFFFF;
+    n->mv.hor = n->mv.ver = 0;
+
+    if (nMb && (sliceId == nMb->sliceId))
+    {
+        u32 tmp;
+        mv_t tmpMv;
+
+        tmp = nMb->mbType;
+        n->available = HANTRO_TRUE;
+        /* MbPartPredMode "inlined" */
+        if (tmp <= P_8x8ref0)
+        {
+            tmpMv = nMb->mv[index];
+            tmp = nMb->refPic[index>>2];
+            n->refIndex = tmp;
+            n->mv = tmpMv;
+        }
+    }
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: GetPredictionMv
+
+        Functional description:
+            Compute motion vector predictor based on neighbours A, B and C
+
+------------------------------------------------------------------------------*/
+
+void GetPredictionMv(mv_t *mv, interNeighbour_t *a, u32 refIndex)
+{
+
+    if ( a[1].available || a[2].available || !a[0].available)
+    {
+        u32 isA, isB, isC;
+        isA = (a[0].refIndex == refIndex) ? HANTRO_TRUE : HANTRO_FALSE;
+        isB = (a[1].refIndex == refIndex) ? HANTRO_TRUE : HANTRO_FALSE;
+        isC = (a[2].refIndex == refIndex) ? HANTRO_TRUE : HANTRO_FALSE;
+
+        if (((u32)isA+(u32)isB+(u32)isC) != 1)
+        {
+            mv->hor = (i16)MedianFilter(a[0].mv.hor, a[1].mv.hor, a[2].mv.hor);
+            mv->ver = (i16)MedianFilter(a[0].mv.ver, a[1].mv.ver, a[2].mv.ver);
+        }
+        else if (isA)
+            *mv = a[0].mv;
+        else if (isB)
+            *mv = a[1].mv;
+        else
+            *mv = a[2].mv;
+    }
+    else
+    {
+        *mv = a[0].mv;
+    }
+
+}
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_inter_prediction.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_inter_prediction.h
new file mode 100755
index 0000000..94dee25
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_inter_prediction.h
@@ -0,0 +1,56 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+    1. Include headers
+    2. Module defines
+    3. Data types
+    4. Function prototypes
+
+------------------------------------------------------------------------------*/
+
+#ifndef H264SWDEC_INTER_PREDICTION_H
+#define H264SWDEC_INTER_PREDICTION_H
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "basetype.h"
+#include "h264bsd_image.h"
+#include "h264bsd_macroblock_layer.h"
+#include "h264bsd_dpb.h"
+
+/*------------------------------------------------------------------------------
+    2. Module defines
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    3. Data types
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    4. Function prototypes
+------------------------------------------------------------------------------*/
+
+u32 h264bsdInterPrediction(mbStorage_t *pMb, macroblockLayer_t *pMbLayer,
+    dpbStorage_t *dpb, u32 mbNum, image_t *image, u8 *data);
+
+#endif /* #ifdef H264SWDEC_INTER_PREDICTION_H */
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_intra_prediction.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_intra_prediction.c
new file mode 100755
index 0000000..15eabfb
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_intra_prediction.c
@@ -0,0 +1,1937 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+     1. Include headers
+     2. External compiler flags
+     3. Module defines
+     4. Local function prototypes
+     5. Functions
+          h264bsdIntraPrediction
+          h264bsdGetNeighbourPels
+          h264bsdIntra16x16Prediction
+          h264bsdIntra4x4Prediction
+          h264bsdIntraChromaPrediction
+          h264bsdAddResidual
+          Intra16x16VerticalPrediction
+          Intra16x16HorizontalPrediction
+          Intra16x16DcPrediction
+          Intra16x16PlanePrediction
+          IntraChromaDcPrediction
+          IntraChromaHorizontalPrediction
+          IntraChromaVerticalPrediction
+          IntraChromaPlanePrediction
+          Get4x4NeighbourPels
+          Write4x4To16x16
+          Intra4x4VerticalPrediction
+          Intra4x4HorizontalPrediction
+          Intra4x4DcPrediction
+          Intra4x4DiagonalDownLeftPrediction
+          Intra4x4DiagonalDownRightPrediction
+          Intra4x4VerticalRightPrediction
+          Intra4x4HorizontalDownPrediction
+          Intra4x4VerticalLeftPrediction
+          Intra4x4HorizontalUpPrediction
+          DetermineIntra4x4PredMode
+
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "h264bsd_intra_prediction.h"
+#include "h264bsd_util.h"
+#include "h264bsd_macroblock_layer.h"
+#include "h264bsd_neighbour.h"
+#include "h264bsd_image.h"
+
+#ifdef H264DEC_OMXDL
+#include "omxtypes.h"
+#include "omxVC.h"
+#endif /* H264DEC_OMXDL */
+
+/*------------------------------------------------------------------------------
+    2. External compiler flags
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+    3. Module defines
+------------------------------------------------------------------------------*/
+
+/* Switch off the following Lint messages for this file:
+ * Info 702: Shift right of signed quantity (int)
+ */
+/*lint -e702 */
+
+
+/* x- and y-coordinates for each block */
+const u32 h264bsdBlockX[16] =
+    { 0, 4, 0, 4, 8, 12, 8, 12, 0, 4, 0, 4, 8, 12, 8, 12 };
+const u32 h264bsdBlockY[16] =
+    { 0, 0, 4, 4, 0, 0, 4, 4, 8, 8, 12, 12, 8, 8, 12, 12 };
+
+const u8 h264bsdClip[1280] =
+{
+    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+    0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
+    16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
+    32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,
+    48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
+    64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,
+    80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,
+    96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,
+    112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
+    128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
+    144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
+    160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
+    176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
+    192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
+    208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
+    224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
+    240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,
+    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
+};
+
+#ifndef H264DEC_OMXDL
+/*------------------------------------------------------------------------------
+    4. Local function prototypes
+------------------------------------------------------------------------------*/
+static void Get4x4NeighbourPels(u8 *a, u8 *l, u8 *data, u8 *above, u8 *left,
+    u32 blockNum);
+static void Intra16x16VerticalPrediction(u8 *data, u8 *above);
+static void Intra16x16HorizontalPrediction(u8 *data, u8 *left);
+static void Intra16x16DcPrediction(u8 *data, u8 *above, u8 *left,
+    u32 A, u32 B);
+static void Intra16x16PlanePrediction(u8 *data, u8 *above, u8 *left);
+static void IntraChromaDcPrediction(u8 *data, u8 *above, u8 *left,
+    u32 A, u32 B);
+static void IntraChromaHorizontalPrediction(u8 *data, u8 *left);
+static void IntraChromaVerticalPrediction(u8 *data, u8 *above);
+static void IntraChromaPlanePrediction(u8 *data, u8 *above, u8 *left);
+
+static void Intra4x4VerticalPrediction(u8 *data, u8 *above);
+static void Intra4x4HorizontalPrediction(u8 *data, u8 *left);
+static void Intra4x4DcPrediction(u8 *data, u8 *above, u8 *left, u32 A, u32 B);
+static void Intra4x4DiagonalDownLeftPrediction(u8 *data, u8 *above);
+static void Intra4x4DiagonalDownRightPrediction(u8 *data, u8 *above, u8 *left);
+static void Intra4x4VerticalRightPrediction(u8 *data, u8 *above, u8 *left);
+static void Intra4x4HorizontalDownPrediction(u8 *data, u8 *above, u8 *left);
+static void Intra4x4VerticalLeftPrediction(u8 *data, u8 *above);
+static void Intra4x4HorizontalUpPrediction(u8 *data, u8 *left);
+void h264bsdAddResidual(u8 *data, i32 *residual, u32 blockNum);
+
+static void Write4x4To16x16(u8 *data, u8 *data4x4, u32 blockNum);
+#endif /* H264DEC_OMXDL */
+
+static u32 DetermineIntra4x4PredMode(macroblockLayer_t *pMbLayer,
+    u32 available, neighbour_t *nA, neighbour_t *nB, u32 index,
+    mbStorage_t *nMbA, mbStorage_t *nMbB);
+
+
+#ifdef H264DEC_OMXDL
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdIntra16x16Prediction
+
+        Functional description:
+          Perform intra 16x16 prediction mode for luma pixels and add
+          residual into prediction. The resulting luma pixels are
+          stored in macroblock array 'data'.
+
+------------------------------------------------------------------------------*/
+u32 h264bsdIntra16x16Prediction(mbStorage_t *pMb, u8 *data, u8 *ptr,
+                                u32 width, u32 constrainedIntraPred)
+{
+
+/* Variables */
+
+    u32 availableA, availableB, availableD;
+    OMXResult omxRes;
+
+/* Code */
+    ASSERT(pMb);
+    ASSERT(data);
+    ASSERT(ptr);
+    ASSERT(h264bsdPredModeIntra16x16(pMb->mbType) < 4);
+
+    availableA = h264bsdIsNeighbourAvailable(pMb, pMb->mbA);
+    if (availableA && constrainedIntraPred &&
+       (h264bsdMbPartPredMode(pMb->mbA->mbType) == PRED_MODE_INTER))
+        availableA = HANTRO_FALSE;
+    availableB = h264bsdIsNeighbourAvailable(pMb, pMb->mbB);
+    if (availableB && constrainedIntraPred &&
+       (h264bsdMbPartPredMode(pMb->mbB->mbType) == PRED_MODE_INTER))
+        availableB = HANTRO_FALSE;
+    availableD = h264bsdIsNeighbourAvailable(pMb, pMb->mbD);
+    if (availableD && constrainedIntraPred &&
+       (h264bsdMbPartPredMode(pMb->mbD->mbType) == PRED_MODE_INTER))
+        availableD = HANTRO_FALSE;
+
+    omxRes = omxVCM4P10_PredictIntra_16x16( (ptr-1),
+                                    (ptr - width),
+                                    (ptr - width-1),
+                                    data,
+                                    (i32)width,
+                                    16,
+                                    (OMXVCM4P10Intra16x16PredMode)
+                                    h264bsdPredModeIntra16x16(pMb->mbType),
+                                    (i32)(availableB + (availableA<<1) +
+                                     (availableD<<5)) );
+    if (omxRes != OMX_Sts_NoErr)
+        return HANTRO_NOK;
+    else
+        return(HANTRO_OK);
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdIntra4x4Prediction
+
+        Functional description:
+          Perform intra 4x4 prediction for luma pixels and add residual
+          into prediction. The resulting luma pixels are stored in
+          macroblock array 'data'. The intra 4x4 prediction mode for each
+          block is stored in 'pMb' structure.
+
+------------------------------------------------------------------------------*/
+u32 h264bsdIntra4x4Prediction(mbStorage_t *pMb, u8 *data,
+                              macroblockLayer_t *mbLayer,
+                              u8 *ptr, u32 width,
+                              u32 constrainedIntraPred, u32 block)
+{
+
+/* Variables */
+    u32 mode;
+    neighbour_t neighbour, neighbourB;
+    mbStorage_t *nMb, *nMb2;
+    u32 availableA, availableB, availableC, availableD;
+
+    OMXResult omxRes;
+    u32 x, y;
+    u8 *l, *a, *al;
+/* Code */
+    ASSERT(pMb);
+    ASSERT(data);
+    ASSERT(mbLayer);
+    ASSERT(ptr);
+    ASSERT(pMb->intra4x4PredMode[block] < 9);
+
+    neighbour = *h264bsdNeighbour4x4BlockA(block);
+    nMb = h264bsdGetNeighbourMb(pMb, neighbour.mb);
+    availableA = h264bsdIsNeighbourAvailable(pMb, nMb);
+    if (availableA && constrainedIntraPred &&
+       ( h264bsdMbPartPredMode(nMb->mbType) == PRED_MODE_INTER) )
+    {
+        availableA = HANTRO_FALSE;
+    }
+
+    neighbourB = *h264bsdNeighbour4x4BlockB(block);
+    nMb2 = h264bsdGetNeighbourMb(pMb, neighbourB.mb);
+    availableB = h264bsdIsNeighbourAvailable(pMb, nMb2);
+    if (availableB && constrainedIntraPred &&
+       ( h264bsdMbPartPredMode(nMb2->mbType) == PRED_MODE_INTER) )
+    {
+        availableB = HANTRO_FALSE;
+    }
+
+    mode = DetermineIntra4x4PredMode(mbLayer,
+        (u32)(availableA && availableB),
+        &neighbour, &neighbourB, block, nMb, nMb2);
+    pMb->intra4x4PredMode[block] = (u8)mode;
+
+    neighbour = *h264bsdNeighbour4x4BlockC(block);
+    nMb = h264bsdGetNeighbourMb(pMb, neighbour.mb);
+    availableC = h264bsdIsNeighbourAvailable(pMb, nMb);
+    if (availableC && constrainedIntraPred &&
+       ( h264bsdMbPartPredMode(nMb->mbType) == PRED_MODE_INTER) )
+    {
+        availableC = HANTRO_FALSE;
+    }
+
+    neighbour = *h264bsdNeighbour4x4BlockD(block);
+    nMb = h264bsdGetNeighbourMb(pMb, neighbour.mb);
+    availableD = h264bsdIsNeighbourAvailable(pMb, nMb);
+    if (availableD && constrainedIntraPred &&
+       ( h264bsdMbPartPredMode(nMb->mbType) == PRED_MODE_INTER) )
+    {
+        availableD = HANTRO_FALSE;
+    }
+
+    x = h264bsdBlockX[block];
+    y = h264bsdBlockY[block];
+
+    if (y == 0)
+        a = ptr - width + x;
+    else
+        a = data-16;
+
+    if (x == 0)
+        l = ptr + y * width -1;
+    else
+    {
+        l = data-1;
+        width = 16;
+    }
+
+    if (x == 0)
+        al = l-width;
+    else
+        al = a-1;
+
+    omxRes = omxVCM4P10_PredictIntra_4x4( l,
+                                          a,
+                                          al,
+                                          data,
+                                          (i32)width,
+                                          16,
+                                          (OMXVCM4P10Intra4x4PredMode)mode,
+                                          (i32)(availableB +
+                                          (availableA<<1) +
+                                          (availableD<<5) +
+                                          (availableC<<6)) );
+    if (omxRes != OMX_Sts_NoErr)
+        return HANTRO_NOK;
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdIntraChromaPrediction
+
+        Functional description:
+          Perform intra prediction for chroma pixels and add residual
+          into prediction. The resulting chroma pixels are stored in 'data'.
+
+------------------------------------------------------------------------------*/
+u32 h264bsdIntraChromaPrediction(mbStorage_t *pMb, u8 *data, image_t *image,
+                                        u32 predMode, u32 constrainedIntraPred)
+{
+
+/* Variables */
+
+    u32 availableA, availableB, availableD;
+    OMXResult omxRes;
+    u8 *ptr;
+    u32 width;
+
+/* Code */
+    ASSERT(pMb);
+    ASSERT(data);
+    ASSERT(image);
+    ASSERT(predMode < 4);
+
+    availableA = h264bsdIsNeighbourAvailable(pMb, pMb->mbA);
+    if (availableA && constrainedIntraPred &&
+       (h264bsdMbPartPredMode(pMb->mbA->mbType) == PRED_MODE_INTER))
+        availableA = HANTRO_FALSE;
+    availableB = h264bsdIsNeighbourAvailable(pMb, pMb->mbB);
+    if (availableB && constrainedIntraPred &&
+       (h264bsdMbPartPredMode(pMb->mbB->mbType) == PRED_MODE_INTER))
+        availableB = HANTRO_FALSE;
+    availableD = h264bsdIsNeighbourAvailable(pMb, pMb->mbD);
+    if (availableD && constrainedIntraPred &&
+       (h264bsdMbPartPredMode(pMb->mbD->mbType) == PRED_MODE_INTER))
+        availableD = HANTRO_FALSE;
+
+    ptr = image->cb;
+    width = image->width*8;
+
+    omxRes = omxVCM4P10_PredictIntraChroma_8x8( (ptr-1),
+                                                (ptr - width),
+                                                (ptr - width -1),
+                                                data,
+                                                (i32)width,
+                                                8,
+                                                (OMXVCM4P10IntraChromaPredMode)
+                                                predMode,
+                                                (i32)(availableB +
+                                                 (availableA<<1) +
+                                                 (availableD<<5)) );
+    if (omxRes != OMX_Sts_NoErr)
+        return HANTRO_NOK;
+
+    /* advance pointers */
+    data += 64;
+    ptr = image->cr;
+
+    omxRes = omxVCM4P10_PredictIntraChroma_8x8( (ptr-1),
+                                                (ptr - width),
+                                                (ptr - width -1),
+                                                data,
+                                                (i32)width,
+                                                8,
+                                                (OMXVCM4P10IntraChromaPredMode)
+                                                predMode,
+                                                (i32)(availableB +
+                                                 (availableA<<1) +
+                                                 (availableD<<5)) );
+    if (omxRes != OMX_Sts_NoErr)
+        return HANTRO_NOK;
+
+    return(HANTRO_OK);
+
+}
+
+
+#else /* H264DEC_OMXDL */
+
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdIntraPrediction
+
+        Functional description:
+          Processes one intra macroblock. Performs intra prediction using
+          specified prediction mode. Writes the final macroblock
+          (prediction + residual) into the output image (image)
+
+        Inputs:
+          pMb           pointer to macroblock specific information
+          mbLayer       pointer to current macroblock data from stream
+          image         pointer to output image
+          mbNum         current macroblock number
+          constrainedIntraPred  flag specifying if neighbouring inter
+                                macroblocks are used in intra prediction
+          data          pointer where output macroblock will be stored
+
+        Outputs:
+          pMb           structure is updated with current macroblock
+          image         current macroblock is written into image
+          data          current macroblock is stored here
+
+        Returns:
+          HANTRO_OK     success
+          HANTRO_NOK    error in intra prediction
+
+------------------------------------------------------------------------------*/
+u32 h264bsdIntraPrediction(mbStorage_t *pMb, macroblockLayer_t *mbLayer,
+    image_t *image, u32 mbNum, u32 constrainedIntraPred, u8 *data)
+{
+
+/* Variables */
+
+    /* pelAbove and pelLeft contain samples above and left to the current
+     * macroblock. Above array contains also sample above-left to the current
+     * mb as well as 4 samples above-right to the current mb (latter only for
+     * luma) */
+    /* lumD + lumB + lumC + cbD + cbB + crD + crB */
+    u8 pelAbove[1 + 16 + 4 + 1 + 8 + 1 + 8];
+    /* lumA + cbA + crA */
+    u8 pelLeft[16 + 8 + 8];
+    u32 tmp;
+
+/* Code */
+
+    ASSERT(pMb);
+    ASSERT(image);
+    ASSERT(mbNum < image->width * image->height);
+    ASSERT(h264bsdMbPartPredMode(pMb->mbType) != PRED_MODE_INTER);
+
+    h264bsdGetNeighbourPels(image, pelAbove, pelLeft, mbNum);
+
+    if (h264bsdMbPartPredMode(pMb->mbType) == PRED_MODE_INTRA16x16)
+    {
+        tmp = h264bsdIntra16x16Prediction(pMb, data, mbLayer->residual.level,
+            pelAbove, pelLeft, constrainedIntraPred);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+    }
+    else
+    {
+        tmp = h264bsdIntra4x4Prediction(pMb, data, mbLayer,
+            pelAbove, pelLeft, constrainedIntraPred);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+    }
+
+    tmp = h264bsdIntraChromaPrediction(pMb, data + 256,
+            mbLayer->residual.level+16, pelAbove + 21, pelLeft + 16,
+            mbLayer->mbPred.intraChromaPredMode, constrainedIntraPred);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+
+    /* if decoded flag > 1 -> mb has already been successfully decoded and
+     * written to output -> do not write again */
+    if (pMb->decoded > 1)
+        return HANTRO_OK;
+
+    h264bsdWriteMacroblock(image, data);
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdGetNeighbourPels
+
+        Functional description:
+          Get pixel values from neighbouring macroblocks into 'above'
+          and 'left' arrays.
+
+------------------------------------------------------------------------------*/
+
+void h264bsdGetNeighbourPels(image_t *image, u8 *above, u8 *left, u32 mbNum)
+{
+
+/* Variables */
+
+    u32 i;
+    u32 width, picSize;
+    u8 *ptr, *tmp;
+    u32 row, col;
+
+/* Code */
+
+    ASSERT(image);
+    ASSERT(above);
+    ASSERT(left);
+    ASSERT(mbNum < image->width * image->height);
+
+    if (!mbNum)
+        return;
+
+    width = image->width;
+    picSize = width * image->height;
+    row = mbNum / width;
+    col = mbNum - row * width;
+
+    width *= 16;
+    ptr = image->data + row * 16 * width  + col * 16;
+
+    /* note that luma samples above-right to current macroblock do not make
+     * sense when current mb is the right-most mb in a row. Same applies to
+     * sample above-left if col is zero. However, usage of pels in prediction
+     * is controlled by neighbour availability information in actual prediction
+     * process */
+    if (row)
+    {
+        tmp = ptr - (width + 1);
+        for (i = 21; i--;)
+            *above++ = *tmp++;
+    }
+
+    if (col)
+    {
+        ptr--;
+        for (i = 16; i--; ptr+=width)
+            *left++ = *ptr;
+    }
+
+    width >>= 1;
+    ptr = image->data + picSize * 256 + row * 8 * width  + col * 8;
+
+    if (row)
+    {
+        tmp = ptr - (width + 1);
+        for (i = 9; i--;)
+            *above++ = *tmp++;
+        tmp += (picSize * 64) - 9;
+        for (i = 9; i--;)
+            *above++ = *tmp++;
+    }
+
+    if (col)
+    {
+        ptr--;
+        for (i = 8; i--; ptr+=width)
+            *left++ = *ptr;
+        ptr += (picSize * 64) - 8 * width;
+        for (i = 8; i--; ptr+=width)
+            *left++ = *ptr;
+    }
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: Intra16x16Prediction
+
+        Functional description:
+          Perform intra 16x16 prediction mode for luma pixels and add
+          residual into prediction. The resulting luma pixels are
+          stored in macroblock array 'data'.
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdIntra16x16Prediction(mbStorage_t *pMb, u8 *data, i32 residual[][16],
+                                u8 *above, u8 *left, u32 constrainedIntraPred)
+{
+
+/* Variables */
+
+    u32 i;
+    u32 availableA, availableB, availableD;
+
+/* Code */
+
+    ASSERT(data);
+    ASSERT(residual);
+    ASSERT(above);
+    ASSERT(left);
+    ASSERT(h264bsdPredModeIntra16x16(pMb->mbType) < 4);
+
+    availableA = h264bsdIsNeighbourAvailable(pMb, pMb->mbA);
+    if (availableA && constrainedIntraPred &&
+       (h264bsdMbPartPredMode(pMb->mbA->mbType) == PRED_MODE_INTER))
+        availableA = HANTRO_FALSE;
+    availableB = h264bsdIsNeighbourAvailable(pMb, pMb->mbB);
+    if (availableB && constrainedIntraPred &&
+       (h264bsdMbPartPredMode(pMb->mbB->mbType) == PRED_MODE_INTER))
+        availableB = HANTRO_FALSE;
+    availableD = h264bsdIsNeighbourAvailable(pMb, pMb->mbD);
+    if (availableD && constrainedIntraPred &&
+       (h264bsdMbPartPredMode(pMb->mbD->mbType) == PRED_MODE_INTER))
+        availableD = HANTRO_FALSE;
+
+    switch(h264bsdPredModeIntra16x16(pMb->mbType))
+    {
+        case 0: /* Intra_16x16_Vertical */
+            if (!availableB)
+                return(HANTRO_NOK);
+            Intra16x16VerticalPrediction(data, above+1);
+            break;
+
+        case 1: /* Intra_16x16_Horizontal */
+            if (!availableA)
+                return(HANTRO_NOK);
+            Intra16x16HorizontalPrediction(data, left);
+            break;
+
+        case 2: /* Intra_16x16_DC */
+            Intra16x16DcPrediction(data, above+1, left, availableA, availableB);
+            break;
+
+        default: /* case 3: Intra_16x16_Plane */
+            if (!availableA || !availableB || !availableD)
+                return(HANTRO_NOK);
+            Intra16x16PlanePrediction(data, above+1, left);
+            break;
+    }
+    /* add residual */
+    for (i = 0; i < 16; i++)
+        h264bsdAddResidual(data, residual[i], i);
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: Intra4x4Prediction
+
+        Functional description:
+          Perform intra 4x4 prediction for luma pixels and add residual
+          into prediction. The resulting luma pixels are stored in
+          macroblock array 'data'. The intra 4x4 prediction mode for each
+          block is stored in 'pMb' structure.
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdIntra4x4Prediction(mbStorage_t *pMb, u8 *data,
+                              macroblockLayer_t *mbLayer, u8 *above,
+                              u8 *left, u32 constrainedIntraPred)
+{
+
+/* Variables */
+
+    u32 block;
+    u32 mode;
+    neighbour_t neighbour, neighbourB;
+    mbStorage_t *nMb, *nMb2;
+    u8 a[1 + 4 + 4], l[1 + 4];
+    u32 data4x4[4];
+    u32 availableA, availableB, availableC, availableD;
+
+/* Code */
+
+    ASSERT(data);
+    ASSERT(mbLayer);
+    ASSERT(above);
+    ASSERT(left);
+
+    for (block = 0; block < 16; block++)
+    {
+
+        ASSERT(pMb->intra4x4PredMode[block] < 9);
+
+        neighbour = *h264bsdNeighbour4x4BlockA(block);
+        nMb = h264bsdGetNeighbourMb(pMb, neighbour.mb);
+        availableA = h264bsdIsNeighbourAvailable(pMb, nMb);
+        if (availableA && constrainedIntraPred &&
+           ( h264bsdMbPartPredMode(nMb->mbType) == PRED_MODE_INTER) )
+        {
+            availableA = HANTRO_FALSE;
+        }
+
+        neighbourB = *h264bsdNeighbour4x4BlockB(block);
+        nMb2 = h264bsdGetNeighbourMb(pMb, neighbourB.mb);
+        availableB = h264bsdIsNeighbourAvailable(pMb, nMb2);
+        if (availableB && constrainedIntraPred &&
+           ( h264bsdMbPartPredMode(nMb2->mbType) == PRED_MODE_INTER) )
+        {
+            availableB = HANTRO_FALSE;
+        }
+
+        mode = DetermineIntra4x4PredMode(mbLayer,
+            (u32)(availableA && availableB),
+            &neighbour, &neighbourB, block, nMb, nMb2);
+        pMb->intra4x4PredMode[block] = (u8)mode;
+
+        neighbour = *h264bsdNeighbour4x4BlockC(block);
+        nMb = h264bsdGetNeighbourMb(pMb, neighbour.mb);
+        availableC = h264bsdIsNeighbourAvailable(pMb, nMb);
+        if (availableC && constrainedIntraPred &&
+           ( h264bsdMbPartPredMode(nMb->mbType) == PRED_MODE_INTER) )
+        {
+            availableC = HANTRO_FALSE;
+        }
+
+        neighbour = *h264bsdNeighbour4x4BlockD(block);
+        nMb = h264bsdGetNeighbourMb(pMb, neighbour.mb);
+        availableD = h264bsdIsNeighbourAvailable(pMb, nMb);
+        if (availableD && constrainedIntraPred &&
+           ( h264bsdMbPartPredMode(nMb->mbType) == PRED_MODE_INTER) )
+        {
+            availableD = HANTRO_FALSE;
+        }
+
+        Get4x4NeighbourPels(a, l, data, above, left, block);
+
+        switch(mode)
+        {
+            case 0: /* Intra_4x4_Vertical */
+                if (!availableB)
+                    return(HANTRO_NOK);
+                Intra4x4VerticalPrediction((u8*)data4x4, a + 1);
+                break;
+            case 1: /* Intra_4x4_Horizontal */
+                if (!availableA)
+                    return(HANTRO_NOK);
+                Intra4x4HorizontalPrediction((u8*)data4x4, l + 1);
+                break;
+            case 2: /* Intra_4x4_DC */
+                Intra4x4DcPrediction((u8*)data4x4, a + 1, l + 1,
+                    availableA, availableB);
+                break;
+            case 3: /* Intra_4x4_Diagonal_Down_Left */
+                if (!availableB)
+                    return(HANTRO_NOK);
+                if (!availableC)
+                {
+                    a[5] = a[6] = a[7] = a[8] = a[4];
+                }
+                Intra4x4DiagonalDownLeftPrediction((u8*)data4x4, a + 1);
+                break;
+            case 4: /* Intra_4x4_Diagonal_Down_Right */
+                if (!availableA || !availableB || !availableD)
+                    return(HANTRO_NOK);
+                Intra4x4DiagonalDownRightPrediction((u8*)data4x4, a + 1, l + 1);
+                break;
+            case 5: /* Intra_4x4_Vertical_Right */
+                if (!availableA || !availableB || !availableD)
+                    return(HANTRO_NOK);
+                Intra4x4VerticalRightPrediction((u8*)data4x4, a + 1, l + 1);
+                break;
+            case 6: /* Intra_4x4_Horizontal_Down */
+                if (!availableA || !availableB || !availableD)
+                    return(HANTRO_NOK);
+                Intra4x4HorizontalDownPrediction((u8*)data4x4, a + 1, l + 1);
+                break;
+            case 7: /* Intra_4x4_Vertical_Left */
+                if (!availableB)
+                    return(HANTRO_NOK);
+                if (!availableC)
+                {
+                    a[5] = a[6] = a[7] = a[8] = a[4];
+                }
+                Intra4x4VerticalLeftPrediction((u8*)data4x4, a + 1);
+                break;
+            default: /* case 8 Intra_4x4_Horizontal_Up */
+                if (!availableA)
+                    return(HANTRO_NOK);
+                Intra4x4HorizontalUpPrediction((u8*)data4x4, l + 1);
+                break;
+        }
+
+        Write4x4To16x16(data, (u8*)data4x4, block);
+        h264bsdAddResidual(data, mbLayer->residual.level[block], block);
+    }
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: IntraChromaPrediction
+
+        Functional description:
+          Perform intra prediction for chroma pixels and add residual
+          into prediction. The resulting chroma pixels are stored in 'data'.
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdIntraChromaPrediction(mbStorage_t *pMb, u8 *data, i32 residual[][16],
+                    u8 *above, u8 *left, u32 predMode, u32 constrainedIntraPred)
+{
+
+/* Variables */
+
+    u32 i, comp, block;
+    u32 availableA, availableB, availableD;
+
+/* Code */
+
+    ASSERT(data);
+    ASSERT(residual);
+    ASSERT(above);
+    ASSERT(left);
+    ASSERT(predMode < 4);
+
+    availableA = h264bsdIsNeighbourAvailable(pMb, pMb->mbA);
+    if (availableA && constrainedIntraPred &&
+       (h264bsdMbPartPredMode(pMb->mbA->mbType) == PRED_MODE_INTER))
+        availableA = HANTRO_FALSE;
+    availableB = h264bsdIsNeighbourAvailable(pMb, pMb->mbB);
+    if (availableB && constrainedIntraPred &&
+       (h264bsdMbPartPredMode(pMb->mbB->mbType) == PRED_MODE_INTER))
+        availableB = HANTRO_FALSE;
+    availableD = h264bsdIsNeighbourAvailable(pMb, pMb->mbD);
+    if (availableD && constrainedIntraPred &&
+       (h264bsdMbPartPredMode(pMb->mbD->mbType) == PRED_MODE_INTER))
+        availableD = HANTRO_FALSE;
+
+    for (comp = 0, block = 16; comp < 2; comp++)
+    {
+        switch(predMode)
+        {
+            case 0: /* Intra_Chroma_DC */
+                IntraChromaDcPrediction(data, above+1, left, availableA,
+                    availableB);
+                break;
+
+            case 1: /* Intra_Chroma_Horizontal */
+                if (!availableA)
+                    return(HANTRO_NOK);
+                IntraChromaHorizontalPrediction(data, left);
+                break;
+
+            case 2: /* Intra_Chroma_Vertical */
+                if (!availableB)
+                    return(HANTRO_NOK);
+                IntraChromaVerticalPrediction(data, above+1);
+
+                break;
+
+            default: /* case 3: Intra_Chroma_Plane */
+                if (!availableA || !availableB || !availableD)
+                    return(HANTRO_NOK);
+                IntraChromaPlanePrediction(data, above+1, left);
+                break;
+        }
+        for (i = 0; i < 4; i++, block++)
+            h264bsdAddResidual(data, residual[i], block);
+
+        /* advance pointers */
+        data += 64;
+        above += 9;
+        left += 8;
+        residual += 4;
+    }
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdAddResidual
+
+        Functional description:
+          Add residual of a block into prediction in macroblock array 'data'.
+          The result (residual + prediction) is stored in 'data'.
+
+------------------------------------------------------------------------------*/
+#ifndef H264DEC_OMXDL
+void h264bsdAddResidual(u8 *data, i32 *residual, u32 blockNum)
+{
+
+/* Variables */
+
+    u32 i;
+    u32 x, y;
+    u32 width;
+    i32 tmp1, tmp2, tmp3, tmp4;
+    u8 *tmp;
+    const u8 *clp = h264bsdClip + 512;
+
+/* Code */
+
+    ASSERT(data);
+    ASSERT(residual);
+    ASSERT(blockNum < 16 + 4 + 4);
+
+    if (IS_RESIDUAL_EMPTY(residual))
+        return;
+
+    RANGE_CHECK_ARRAY(residual, -512, 511, 16);
+
+    if (blockNum < 16)
+    {
+        width = 16;
+        x = h264bsdBlockX[blockNum];
+        y = h264bsdBlockY[blockNum];
+    }
+    else
+    {
+        width = 8;
+        x = h264bsdBlockX[blockNum & 0x3];
+        y = h264bsdBlockY[blockNum & 0x3];
+    }
+
+    tmp = data + y*width + x;
+    for (i = 4; i; i--)
+    {
+        tmp1 = *residual++;
+        tmp2 = tmp[0];
+        tmp3 = *residual++;
+        tmp4 = tmp[1];
+
+        tmp[0] = clp[tmp1 + tmp2];
+
+        tmp1 = *residual++;
+        tmp2 = tmp[2];
+
+        tmp[1] = clp[tmp3 + tmp4];
+
+        tmp3 = *residual++;
+        tmp4 = tmp[3];
+
+        tmp1 = clp[tmp1 + tmp2];
+        tmp3 = clp[tmp3 + tmp4];
+        tmp[2] = (u8)tmp1;
+        tmp[3] = (u8)tmp3;
+
+        tmp += width;
+    }
+
+}
+#endif
+/*------------------------------------------------------------------------------
+
+    Function: Intra16x16VerticalPrediction
+
+        Functional description:
+          Perform intra 16x16 vertical prediction mode.
+
+------------------------------------------------------------------------------*/
+
+void Intra16x16VerticalPrediction(u8 *data, u8 *above)
+{
+
+/* Variables */
+
+    u32 i, j;
+
+/* Code */
+
+    ASSERT(data);
+    ASSERT(above);
+
+    for (i = 0; i < 16; i++)
+    {
+        for (j = 0; j < 16; j++)
+        {
+            *data++ = above[j];
+        }
+    }
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: Intra16x16HorizontalPrediction
+
+        Functional description:
+          Perform intra 16x16 horizontal prediction mode.
+
+------------------------------------------------------------------------------*/
+
+void Intra16x16HorizontalPrediction(u8 *data, u8 *left)
+{
+
+/* Variables */
+
+    u32 i, j;
+
+/* Code */
+
+    ASSERT(data);
+    ASSERT(left);
+
+    for (i = 0; i < 16; i++)
+    {
+        for (j = 0; j < 16; j++)
+        {
+            *data++ = left[i];
+        }
+    }
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: Intra16x16DcPrediction
+
+        Functional description:
+          Perform intra 16x16 DC prediction mode.
+
+------------------------------------------------------------------------------*/
+
+void Intra16x16DcPrediction(u8 *data, u8 *above, u8 *left, u32 availableA,
+    u32 availableB)
+{
+
+/* Variables */
+
+    u32 i, tmp;
+
+/* Code */
+
+    ASSERT(data);
+    ASSERT(above);
+    ASSERT(left);
+
+    if (availableA && availableB)
+    {
+        for (i = 0, tmp = 0; i < 16; i++)
+            tmp += above[i] + left[i];
+        tmp = (tmp + 16) >> 5;
+    }
+    else if (availableA)
+    {
+        for (i = 0, tmp = 0; i < 16; i++)
+            tmp += left[i];
+        tmp = (tmp + 8) >> 4;
+    }
+    else if (availableB)
+    {
+        for (i = 0, tmp = 0; i < 16; i++)
+            tmp += above[i];
+        tmp = (tmp + 8) >> 4;
+    }
+    /* neither A nor B available */
+    else
+    {
+        tmp = 128;
+    }
+    for (i = 0; i < 256; i++)
+        data[i] = (u8)tmp;
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: Intra16x16PlanePrediction
+
+        Functional description:
+          Perform intra 16x16 plane prediction mode.
+
+------------------------------------------------------------------------------*/
+
+void Intra16x16PlanePrediction(u8 *data, u8 *above, u8 *left)
+{
+
+/* Variables */
+
+    u32 i, j;
+    i32 a, b, c;
+    i32 tmp;
+
+/* Code */
+
+    ASSERT(data);
+    ASSERT(above);
+    ASSERT(left);
+
+    a = 16 * (above[15] + left[15]);
+
+    for (i = 0, b = 0; i < 8; i++)
+        b += ((i32)i + 1) * (above[8+i] - above[6-i]);
+    b = (5 * b + 32) >> 6;
+
+    for (i = 0, c = 0; i < 7; i++)
+        c += ((i32)i + 1) * (left[8+i] - left[6-i]);
+    /* p[-1,-1] has to be accessed through above pointer */
+    c += ((i32)i + 1) * (left[8+i] - above[-1]);
+    c = (5 * c + 32) >> 6;
+
+    for (i = 0; i < 16; i++)
+    {
+        for (j = 0; j < 16; j++)
+        {
+            tmp = (a + b * ((i32)j - 7) + c * ((i32)i - 7) + 16) >> 5;
+            data[i*16+j] = (u8)CLIP1(tmp);
+        }
+    }
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: IntraChromaDcPrediction
+
+        Functional description:
+          Perform intra chroma DC prediction mode.
+
+------------------------------------------------------------------------------*/
+
+void IntraChromaDcPrediction(u8 *data, u8 *above, u8 *left, u32 availableA,
+    u32 availableB)
+{
+
+/* Variables */
+
+    u32 i;
+    u32 tmp1, tmp2;
+
+/* Code */
+
+    ASSERT(data);
+    ASSERT(above);
+    ASSERT(left);
+
+    /* y = 0..3 */
+    if (availableA && availableB)
+    {
+        tmp1 = above[0] + above[1] + above[2] + above[3] +
+              left[0] + left[1] + left[2] + left[3];
+        tmp1 = (tmp1 + 4) >> 3;
+        tmp2 = (above[4] + above[5] + above[6] + above[7] + 2) >> 2;
+    }
+    else if (availableB)
+    {
+        tmp1 = (above[0] + above[1] + above[2] + above[3] + 2) >> 2;
+        tmp2 = (above[4] + above[5] + above[6] + above[7] + 2) >> 2;
+    }
+    else if (availableA)
+    {
+        tmp1 = (left[0] + left[1] + left[2] + left[3] + 2) >> 2;
+        tmp2 = tmp1;
+    }
+    /* neither A nor B available */
+    else
+    {
+        tmp1 = tmp2 = 128;
+    }
+
+    ASSERT(tmp1 < 256 && tmp2 < 256);
+    for (i = 4; i--;)
+    {
+        *data++ = (u8)tmp1;
+        *data++ = (u8)tmp1;
+        *data++ = (u8)tmp1;
+        *data++ = (u8)tmp1;
+        *data++ = (u8)tmp2;
+        *data++ = (u8)tmp2;
+        *data++ = (u8)tmp2;
+        *data++ = (u8)tmp2;
+    }
+
+    /* y = 4...7 */
+    if (availableA)
+    {
+        tmp1 = (left[4] + left[5] + left[6] + left[7] + 2) >> 2;
+        if (availableB)
+        {
+            tmp2 = above[4] + above[5] + above[6] + above[7] +
+                   left[4] + left[5] + left[6] + left[7];
+            tmp2 = (tmp2 + 4) >> 3;
+        }
+        else
+            tmp2 = tmp1;
+    }
+    else if (availableB)
+    {
+        tmp1 = (above[0] + above[1] + above[2] + above[3] + 2) >> 2;
+        tmp2 = (above[4] + above[5] + above[6] + above[7] + 2) >> 2;
+    }
+    else
+    {
+        tmp1 = tmp2 = 128;
+    }
+
+    ASSERT(tmp1 < 256 && tmp2 < 256);
+    for (i = 4; i--;)
+    {
+        *data++ = (u8)tmp1;
+        *data++ = (u8)tmp1;
+        *data++ = (u8)tmp1;
+        *data++ = (u8)tmp1;
+        *data++ = (u8)tmp2;
+        *data++ = (u8)tmp2;
+        *data++ = (u8)tmp2;
+        *data++ = (u8)tmp2;
+    }
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: IntraChromaHorizontalPrediction
+
+        Functional description:
+          Perform intra chroma horizontal prediction mode.
+
+------------------------------------------------------------------------------*/
+
+void IntraChromaHorizontalPrediction(u8 *data, u8 *left)
+{
+
+/* Variables */
+
+    u32 i;
+
+/* Code */
+
+    ASSERT(data);
+    ASSERT(left);
+
+    for (i = 8; i--;)
+    {
+        *data++ = *left;
+        *data++ = *left;
+        *data++ = *left;
+        *data++ = *left;
+        *data++ = *left;
+        *data++ = *left;
+        *data++ = *left;
+        *data++ = *left++;
+    }
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: IntraChromaVerticalPrediction
+
+        Functional description:
+          Perform intra chroma vertical prediction mode.
+
+------------------------------------------------------------------------------*/
+
+void IntraChromaVerticalPrediction(u8 *data, u8 *above)
+{
+
+/* Variables */
+
+    u32 i;
+
+/* Code */
+
+    ASSERT(data);
+    ASSERT(above);
+
+    for (i = 8; i--;data++/*above-=8*/)
+    {
+        data[0] = *above;
+        data[8] = *above;
+        data[16] = *above;
+        data[24] = *above;
+        data[32] = *above;
+        data[40] = *above;
+        data[48] = *above;
+        data[56] = *above++;
+    }
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: IntraChromaPlanePrediction
+
+        Functional description:
+          Perform intra chroma plane prediction mode.
+
+------------------------------------------------------------------------------*/
+
+void IntraChromaPlanePrediction(u8 *data, u8 *above, u8 *left)
+{
+
+/* Variables */
+
+    u32 i;
+    i32 a, b, c;
+    i32 tmp;
+    const u8 *clp = h264bsdClip + 512;
+
+/* Code */
+
+    ASSERT(data);
+    ASSERT(above);
+    ASSERT(left);
+
+    a = 16 * (above[7] + left[7]);
+
+    b = (above[4] - above[2]) + 2 * (above[5] - above[1])
+        + 3 * (above[6] - above[0]) + 4 * (above[7] - above[-1]);
+    b = (17 * b + 16) >> 5;
+
+    /* p[-1,-1] has to be accessed through above pointer */
+    c = (left[4] - left[2]) + 2 * (left[5] - left[1])
+        + 3 * (left[6] - left[0]) + 4 * (left[7] - above[-1]);
+    c = (17 * c + 16) >> 5;
+
+    /*a += 16;*/
+    a = a - 3 * c + 16;
+    for (i = 8; i--; a += c)
+    {
+        tmp = (a - 3 * b);
+        *data++ = clp[tmp>>5];
+        tmp += b;
+        *data++ = clp[tmp>>5];
+        tmp += b;
+        *data++ = clp[tmp>>5];
+        tmp += b;
+        *data++ = clp[tmp>>5];
+        tmp += b;
+        *data++ = clp[tmp>>5];
+        tmp += b;
+        *data++ = clp[tmp>>5];
+        tmp += b;
+        *data++ = clp[tmp>>5];
+        tmp += b;
+        *data++ = clp[tmp>>5];
+    }
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: Get4x4NeighbourPels
+
+        Functional description:
+          Get neighbouring pixels of a 4x4 block into 'a' and 'l'.
+
+------------------------------------------------------------------------------*/
+
+void Get4x4NeighbourPels(u8 *a, u8 *l, u8 *data, u8 *above, u8 *left,
+    u32 blockNum)
+{
+
+/* Variables */
+
+    u32 x, y;
+    u8 t1, t2;
+
+/* Code */
+
+    ASSERT(a);
+    ASSERT(l);
+    ASSERT(data);
+    ASSERT(above);
+    ASSERT(left);
+    ASSERT(blockNum < 16);
+
+    x = h264bsdBlockX[blockNum];
+    y = h264bsdBlockY[blockNum];
+
+    /* A and D */
+    if (x == 0)
+    {
+        t1 = left[y    ];
+        t2 = left[y + 1];
+        l[1] = t1;
+        l[2] = t2;
+        t1 = left[y + 2];
+        t2 = left[y + 3];
+        l[3] = t1;
+        l[4] = t2;
+    }
+    else
+    {
+        t1 = data[y * 16 + x - 1     ];
+        t2 = data[y * 16 + x - 1 + 16];
+        l[1] = t1;
+        l[2] = t2;
+        t1 = data[y * 16 + x - 1 + 32];
+        t2 = data[y * 16 + x - 1 + 48];
+        l[3] = t1;
+        l[4] = t2;
+    }
+
+    /* B, C and D */
+    if (y == 0)
+    {
+        t1 = above[x    ];
+        t2 = above[x    ];
+        l[0] = t1;
+        a[0] = t2;
+        t1 = above[x + 1];
+        t2 = above[x + 2];
+        a[1] = t1;
+        a[2] = t2;
+        t1 = above[x + 3];
+        t2 = above[x + 4];
+        a[3] = t1;
+        a[4] = t2;
+        t1 = above[x + 5];
+        t2 = above[x + 6];
+        a[5] = t1;
+        a[6] = t2;
+        t1 = above[x + 7];
+        t2 = above[x + 8];
+        a[7] = t1;
+        a[8] = t2;
+    }
+    else
+    {
+        t1 = data[(y - 1) * 16 + x    ];
+        t2 = data[(y - 1) * 16 + x + 1];
+        a[1] = t1;
+        a[2] = t2;
+        t1 = data[(y - 1) * 16 + x + 2];
+        t2 = data[(y - 1) * 16 + x + 3];
+        a[3] = t1;
+        a[4] = t2;
+        t1 = data[(y - 1) * 16 + x + 4];
+        t2 = data[(y - 1) * 16 + x + 5];
+        a[5] = t1;
+        a[6] = t2;
+        t1 = data[(y - 1) * 16 + x + 6];
+        t2 = data[(y - 1) * 16 + x + 7];
+        a[7] = t1;
+        a[8] = t2;
+
+        if (x == 0)
+            l[0] = a[0] = left[y-1];
+        else
+            l[0] = a[0] = data[(y - 1) * 16 + x - 1];
+    }
+}
+
+
+/*------------------------------------------------------------------------------
+
+    Function: Intra4x4VerticalPrediction
+
+        Functional description:
+          Perform intra 4x4 vertical prediction mode.
+
+------------------------------------------------------------------------------*/
+
+void Intra4x4VerticalPrediction(u8 *data, u8 *above)
+{
+
+/* Variables */
+
+    u8 t1, t2;
+
+/* Code */
+
+    ASSERT(data);
+    ASSERT(above);
+
+    t1 = above[0];
+    t2 = above[1];
+    data[0] = data[4] = data[8] = data[12] = t1;
+    data[1] = data[5] = data[9] = data[13] = t2;
+    t1 = above[2];
+    t2 = above[3];
+    data[2] = data[6] = data[10] = data[14] = t1;
+    data[3] = data[7] = data[11] = data[15] = t2;
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: Intra4x4HorizontalPrediction
+
+        Functional description:
+          Perform intra 4x4 horizontal prediction mode.
+
+------------------------------------------------------------------------------*/
+
+void Intra4x4HorizontalPrediction(u8 *data, u8 *left)
+{
+
+/* Variables */
+
+    u8 t1, t2;
+
+/* Code */
+
+    ASSERT(data);
+    ASSERT(left);
+
+    t1 = left[0];
+    t2 = left[1];
+    data[0] = data[1] = data[2] = data[3] = t1;
+    data[4] = data[5] = data[6] = data[7] = t2;
+    t1 = left[2];
+    t2 = left[3];
+    data[8] = data[9] = data[10] = data[11] = t1;
+    data[12] = data[13] = data[14] = data[15] = t2;
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: Intra4x4DcPrediction
+
+        Functional description:
+          Perform intra 4x4 DC prediction mode.
+
+------------------------------------------------------------------------------*/
+
+void Intra4x4DcPrediction(u8 *data, u8 *above, u8 *left, u32 availableA,
+    u32 availableB)
+{
+
+/* Variables */
+
+    u32 tmp;
+    u8 t1, t2, t3, t4;
+
+/* Code */
+
+    ASSERT(data);
+    ASSERT(above);
+    ASSERT(left);
+
+    if (availableA && availableB)
+    {
+        t1 = above[0]; t2 = above[1]; t3 = above[2]; t4 = above[3];
+        tmp = t1 + t2 + t3 + t4;
+        t1 = left[0]; t2 = left[1]; t3 = left[2]; t4 = left[3];
+        tmp += t1 + t2 + t3 + t4;
+        tmp = (tmp + 4) >> 3;
+    }
+    else if (availableA)
+    {
+        t1 = left[0]; t2 = left[1]; t3 = left[2]; t4 = left[3];
+        tmp = (t1 + t2 + t3 + t4 + 2) >> 2;
+    }
+    else if (availableB)
+    {
+        t1 = above[0]; t2 = above[1]; t3 = above[2]; t4 = above[3];
+        tmp = (t1 + t2 + t3 + t4 + 2) >> 2;
+    }
+    else
+    {
+        tmp = 128;
+    }
+
+    ASSERT(tmp < 256);
+    data[0] = data[1] = data[2] = data[3] =
+    data[4] = data[5] = data[6] = data[7] =
+    data[8] = data[9] = data[10] = data[11] =
+    data[12] = data[13] = data[14] = data[15] = (u8)tmp;
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: Intra4x4DiagonalDownLeftPrediction
+
+        Functional description:
+          Perform intra 4x4 diagonal down-left prediction mode.
+
+------------------------------------------------------------------------------*/
+
+void Intra4x4DiagonalDownLeftPrediction(u8 *data, u8 *above)
+{
+
+/* Variables */
+
+/* Code */
+
+    ASSERT(data);
+    ASSERT(above);
+
+    data[ 0] = (above[0] + 2 * above[1] + above[2] + 2) >> 2;
+    data[ 1] = (above[1] + 2 * above[2] + above[3] + 2) >> 2;
+    data[ 4] = (above[1] + 2 * above[2] + above[3] + 2) >> 2;
+    data[ 2] = (above[2] + 2 * above[3] + above[4] + 2) >> 2;
+    data[ 5] = (above[2] + 2 * above[3] + above[4] + 2) >> 2;
+    data[ 8] = (above[2] + 2 * above[3] + above[4] + 2) >> 2;
+    data[ 3] = (above[3] + 2 * above[4] + above[5] + 2) >> 2;
+    data[ 6] = (above[3] + 2 * above[4] + above[5] + 2) >> 2;
+    data[ 9] = (above[3] + 2 * above[4] + above[5] + 2) >> 2;
+    data[12] = (above[3] + 2 * above[4] + above[5] + 2) >> 2;
+    data[ 7] = (above[4] + 2 * above[5] + above[6] + 2) >> 2;
+    data[10] = (above[4] + 2 * above[5] + above[6] + 2) >> 2;
+    data[13] = (above[4] + 2 * above[5] + above[6] + 2) >> 2;
+    data[11] = (above[5] + 2 * above[6] + above[7] + 2) >> 2;
+    data[14] = (above[5] + 2 * above[6] + above[7] + 2) >> 2;
+    data[15] = (above[6] + 3 * above[7] + 2) >> 2;
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: Intra4x4DiagonalDownRightPrediction
+
+        Functional description:
+          Perform intra 4x4 diagonal down-right prediction mode.
+
+------------------------------------------------------------------------------*/
+
+void Intra4x4DiagonalDownRightPrediction(u8 *data, u8 *above, u8 *left)
+{
+
+/* Variables */
+
+/* Code */
+
+    ASSERT(data);
+    ASSERT(above);
+    ASSERT(left);
+
+    data[ 0] = (above[0] + 2 * above[-1] + left[0] + 2) >> 2;
+    data[ 5] = (above[0] + 2 * above[-1] + left[0] + 2) >> 2;
+    data[10] = (above[0] + 2 * above[-1] + left[0] + 2) >> 2;
+    data[15] = (above[0] + 2 * above[-1] + left[0] + 2) >> 2;
+    data[ 1] = (above[-1] + 2 * above[0] + above[1] + 2) >> 2;
+    data[ 6] = (above[-1] + 2 * above[0] + above[1] + 2) >> 2;
+    data[11] = (above[-1] + 2 * above[0] + above[1] + 2) >> 2;
+    data[ 2] = (above[0] + 2 * above[1] + above[2] + 2) >> 2;
+    data[ 7] = (above[0] + 2 * above[1] + above[2] + 2) >> 2;
+    data[ 3] = (above[1] + 2 * above[2] + above[3] + 2) >> 2;
+    data[ 4] = (left[-1] + 2 * left[0] + left[1] + 2) >> 2;
+    data[ 9] = (left[-1] + 2 * left[0] + left[1] + 2) >> 2;
+    data[14] = (left[-1] + 2 * left[0] + left[1] + 2) >> 2;
+    data[ 8] = (left[0] + 2 * left[1] + left[2] + 2) >> 2;
+    data[13] = (left[0] + 2 * left[1] + left[2] + 2) >> 2;
+    data[12] = (left[1] + 2 * left[2] + left[3] + 2) >> 2;
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: Intra4x4VerticalRightPrediction
+
+        Functional description:
+          Perform intra 4x4 vertical right prediction mode.
+
+------------------------------------------------------------------------------*/
+
+void Intra4x4VerticalRightPrediction(u8 *data, u8 *above, u8 *left)
+{
+
+/* Variables */
+
+/* Code */
+
+    ASSERT(data);
+    ASSERT(above);
+    ASSERT(left);
+
+    data[ 0] = (above[-1] + above[0] + 1) >> 1;
+    data[ 9] = (above[-1] + above[0] + 1) >> 1;
+    data[ 5] = (above[-1] + 2 * above[0] + above[1] + 2) >> 2;
+    data[14] = (above[-1] + 2 * above[0] + above[1] + 2) >> 2;
+    data[ 4] = (above[0] + 2 * above[-1] + left[0] + 2) >> 2;
+    data[13] = (above[0] + 2 * above[-1] + left[0] + 2) >> 2;
+    data[ 1] = (above[0] + above[1] + 1) >> 1;
+    data[10] = (above[0] + above[1] + 1) >> 1;
+    data[ 6] = (above[0] + 2 * above[1] + above[2] + 2) >> 2;
+    data[15] = (above[0] + 2 * above[1] + above[2] + 2) >> 2;
+    data[ 2] = (above[1] + above[2] + 1) >> 1;
+    data[11] = (above[1] + above[2] + 1) >> 1;
+    data[ 7] = (above[1] + 2 * above[2] + above[3] + 2) >> 2;
+    data[ 3] = (above[2] + above[3] + 1) >> 1;
+    data[ 8] = (left[1] + 2 * left[0] + left[-1] + 2) >> 2;
+    data[12] = (left[2] + 2 * left[1] + left[0] + 2) >> 2;
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: Intra4x4HorizontalDownPrediction
+
+        Functional description:
+          Perform intra 4x4 horizontal down prediction mode.
+
+------------------------------------------------------------------------------*/
+
+void Intra4x4HorizontalDownPrediction(u8 *data, u8 *above, u8 *left)
+{
+
+/* Variables */
+
+/* Code */
+
+    ASSERT(data);
+    ASSERT(above);
+    ASSERT(left);
+
+    data[ 0] = (left[-1] + left[0] + 1) >> 1;
+    data[ 6] = (left[-1] + left[0] + 1) >> 1;
+    data[ 5] = (left[-1] + 2 * left[0] + left[1] + 2) >> 2;
+    data[11] = (left[-1] + 2 * left[0] + left[1] + 2) >> 2;
+    data[ 4] = (left[0] + left[1] + 1) >> 1;
+    data[10] = (left[0] + left[1] + 1) >> 1;
+    data[ 9] = (left[0] + 2 * left[1] + left[2] + 2) >> 2;
+    data[15] = (left[0] + 2 * left[1] + left[2] + 2) >> 2;
+    data[ 8] = (left[1] + left[2] + 1) >> 1;
+    data[14] = (left[1] + left[2] + 1) >> 1;
+    data[13] = (left[1] + 2 * left[2] + left[3] + 2) >> 2;
+    data[12] = (left[2] + left[3] + 1) >> 1;
+    data[ 1] = (above[0] + 2 * above[-1] + left[0] + 2) >> 2;
+    data[ 7] = (above[0] + 2 * above[-1] + left[0] + 2) >> 2;
+    data[ 2] = (above[1] + 2 * above[0] + above[-1] + 2) >> 2;
+    data[ 3] = (above[2] + 2 * above[1] + above[0] + 2) >> 2;
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: Intra4x4VerticalLeftPrediction
+
+        Functional description:
+          Perform intra 4x4 vertical left prediction mode.
+
+------------------------------------------------------------------------------*/
+
+void Intra4x4VerticalLeftPrediction(u8 *data, u8 *above)
+{
+
+/* Variables */
+
+/* Code */
+
+    ASSERT(data);
+    ASSERT(above);
+
+    data[ 0] = (above[0] + above[1] + 1) >> 1;
+    data[ 1] = (above[1] + above[2] + 1) >> 1;
+    data[ 2] = (above[2] + above[3] + 1) >> 1;
+    data[ 3] = (above[3] + above[4] + 1) >> 1;
+    data[ 4] = (above[0] + 2 * above[1] + above[2] + 2) >> 2;
+    data[ 5] = (above[1] + 2 * above[2] + above[3] + 2) >> 2;
+    data[ 6] = (above[2] + 2 * above[3] + above[4] + 2) >> 2;
+    data[ 7] = (above[3] + 2 * above[4] + above[5] + 2) >> 2;
+    data[ 8] = (above[1] + above[2] + 1) >> 1;
+    data[ 9] = (above[2] + above[3] + 1) >> 1;
+    data[10] = (above[3] + above[4] + 1) >> 1;
+    data[11] = (above[4] + above[5] + 1) >> 1;
+    data[12] = (above[1] + 2 * above[2] + above[3] + 2) >> 2;
+    data[13] = (above[2] + 2 * above[3] + above[4] + 2) >> 2;
+    data[14] = (above[3] + 2 * above[4] + above[5] + 2) >> 2;
+    data[15] = (above[4] + 2 * above[5] + above[6] + 2) >> 2;
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: Intra4x4HorizontalUpPrediction
+
+        Functional description:
+          Perform intra 4x4 horizontal up prediction mode.
+
+------------------------------------------------------------------------------*/
+
+void Intra4x4HorizontalUpPrediction(u8 *data, u8 *left)
+{
+
+/* Variables */
+
+/* Code */
+
+    ASSERT(data);
+    ASSERT(left);
+
+    data[ 0] = (left[0] + left[1] + 1) >> 1;
+    data[ 1] = (left[0] + 2 * left[1] + left[2] + 2) >> 2;
+    data[ 2] = (left[1] + left[2] + 1) >> 1;
+    data[ 3] = (left[1] + 2 * left[2] + left[3] + 2) >> 2;
+    data[ 4] = (left[1] + left[2] + 1) >> 1;
+    data[ 5] = (left[1] + 2 * left[2] + left[3] + 2) >> 2;
+    data[ 6] = (left[2] + left[3] + 1) >> 1;
+    data[ 7] = (left[2] + 3 * left[3] + 2) >> 2;
+    data[ 8] = (left[2] + left[3] + 1) >> 1;
+    data[ 9] = (left[2] + 3 * left[3] + 2) >> 2;
+    data[10] = left[3];
+    data[11] = left[3];
+    data[12] = left[3];
+    data[13] = left[3];
+    data[14] = left[3];
+    data[15] = left[3];
+
+}
+
+#endif /* H264DEC_OMXDL */
+
+/*------------------------------------------------------------------------------
+
+    Function: Write4x4To16x16
+
+        Functional description:
+          Write a 4x4 block (data4x4) into correct position
+          in 16x16 macroblock (data).
+
+------------------------------------------------------------------------------*/
+
+void Write4x4To16x16(u8 *data, u8 *data4x4, u32 blockNum)
+{
+
+/* Variables */
+
+    u32 x, y;
+    u32 *in32, *out32;
+
+/* Code */
+
+    ASSERT(data);
+    ASSERT(data4x4);
+    ASSERT(blockNum < 16);
+
+    x = h264bsdBlockX[blockNum];
+    y = h264bsdBlockY[blockNum];
+
+    data += y*16+x;
+
+    ASSERT(((u32)data&0x3) == 0);
+
+    /*lint --e(826) */
+    out32 = (u32 *)data;
+    /*lint --e(826) */
+    in32 = (u32 *)data4x4;
+
+    out32[0] = *in32++;
+    out32[4] = *in32++;
+    out32[8] = *in32++;
+    out32[12] = *in32++;
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: DetermineIntra4x4PredMode
+
+        Functional description:
+          Returns the intra 4x4 prediction mode of a block based on the
+          neighbouring macroblocks and information parsed from stream.
+
+------------------------------------------------------------------------------*/
+
+u32 DetermineIntra4x4PredMode(macroblockLayer_t *pMbLayer,
+    u32 available, neighbour_t *nA, neighbour_t *nB, u32 index,
+    mbStorage_t *nMbA, mbStorage_t *nMbB)
+{
+
+/* Variables */
+
+    u32 mode1, mode2;
+    mbStorage_t *pMb;
+
+/* Code */
+
+    ASSERT(pMbLayer);
+
+    /* dc only prediction? */
+    if (!available)
+        mode1 = 2;
+    else
+    {
+        pMb = nMbA;
+        if (h264bsdMbPartPredMode(pMb->mbType) == PRED_MODE_INTRA4x4)
+        {
+            mode1 = pMb->intra4x4PredMode[nA->index];
+        }
+        else
+            mode1 = 2;
+
+        pMb = nMbB;
+        if (h264bsdMbPartPredMode(pMb->mbType) == PRED_MODE_INTRA4x4)
+        {
+            mode2 = pMb->intra4x4PredMode[nB->index];
+        }
+        else
+            mode2 = 2;
+
+        mode1 = MIN(mode1, mode2);
+    }
+
+    if (!pMbLayer->mbPred.prevIntra4x4PredModeFlag[index])
+    {
+        if (pMbLayer->mbPred.remIntra4x4PredMode[index] < mode1)
+        {
+            mode1 = pMbLayer->mbPred.remIntra4x4PredMode[index];
+        }
+        else
+        {
+            mode1 = pMbLayer->mbPred.remIntra4x4PredMode[index] + 1;
+        }
+    }
+
+    return(mode1);
+}
+
+
+/*lint +e702 */
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_intra_prediction.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_intra_prediction.h
new file mode 100755
index 0000000..4652bd5
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_intra_prediction.h
@@ -0,0 +1,81 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+    1. Include headers
+    2. Module defines
+    3. Data types
+    4. Function prototypes
+
+------------------------------------------------------------------------------*/
+
+#ifndef H264SWDEC_INTRA_PREDICTION_H
+#define H264SWDEC_INTRA_PREDICTION_H
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "basetype.h"
+#include "h264bsd_image.h"
+#include "h264bsd_macroblock_layer.h"
+
+/*------------------------------------------------------------------------------
+    2. Module defines
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    3. Data types
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    4. Function prototypes
+------------------------------------------------------------------------------*/
+#ifndef H264DEC_OMXDL
+u32 h264bsdIntraPrediction(mbStorage_t *pMb, macroblockLayer_t *mbLayer,
+    image_t *image, u32 mbNum, u32 constrainedIntraPred, u8 *data);
+
+u32 h264bsdIntra4x4Prediction(mbStorage_t *pMb, u8 *data,
+                              macroblockLayer_t *mbLayer,
+                              u8 *above, u8 *left, u32 constrainedIntraPred);
+u32 h264bsdIntra16x16Prediction(mbStorage_t *pMb, u8 *data, i32 residual[][16],
+    u8 *above, u8 *left, u32 constrainedIntraPred);
+
+u32 h264bsdIntraChromaPrediction(mbStorage_t *pMb, u8 *data, i32 residual[][16],
+    u8 *above, u8 *left, u32 predMode, u32 constrainedIntraPred);
+
+void h264bsdGetNeighbourPels(image_t *image, u8 *above, u8 *left, u32 mbNum);
+
+#else
+
+u32 h264bsdIntra4x4Prediction(mbStorage_t *pMb, u8 *data,
+                              macroblockLayer_t *mbLayer,
+                              u8 *pImage, u32 width,
+                              u32 constrainedIntraPred, u32 block);
+
+u32 h264bsdIntra16x16Prediction(mbStorage_t *pMb, u8 *data, u8 *pImage,
+                            u32 width, u32 constrainedIntraPred);
+
+u32 h264bsdIntraChromaPrediction(mbStorage_t *pMb, u8 *data, image_t *image,
+                                        u32 predMode, u32 constrainedIntraPred);
+
+#endif
+
+#endif /* #ifdef H264SWDEC_INTRA_PREDICTION_H */
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_macroblock_layer.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_macroblock_layer.c
new file mode 100755
index 0000000..2b3e7f0
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_macroblock_layer.c
@@ -0,0 +1,1446 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+     1. Include headers
+     2. External compiler flags
+     3. Module defines
+     4. Local function prototypes
+     5. Functions
+          h264bsdDecodeMacroblockLayer
+          h264bsdMbPartPredMode
+          h264bsdNumMbPart
+          h264bsdNumSubMbPart
+          DecodeMbPred
+          DecodeSubMbPred
+          DecodeResidual
+          DetermineNc
+          CbpIntra16x16
+          h264bsdPredModeIntra16x16
+          h264bsdDecodeMacroblock
+          ProcessResidual
+          h264bsdSubMbPartMode
+
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "h264bsd_macroblock_layer.h"
+#include "h264bsd_slice_header.h"
+#include "h264bsd_util.h"
+#include "h264bsd_vlc.h"
+#include "h264bsd_cavlc.h"
+#include "h264bsd_nal_unit.h"
+#include "h264bsd_neighbour.h"
+#include "h264bsd_transform.h"
+#include "h264bsd_intra_prediction.h"
+#include "h264bsd_inter_prediction.h"
+
+#ifdef H264DEC_OMXDL
+#include "omxtypes.h"
+#include "omxVC.h"
+#include "armVC.h"
+#endif /* H264DEC_OMXDL */
+
+/*------------------------------------------------------------------------------
+    2. External compiler flags
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+    3. Module defines
+------------------------------------------------------------------------------*/
+#ifdef H264DEC_OMXDL
+static const u32 chromaIndex[8] = { 256, 260, 288, 292, 320, 324, 352, 356 };
+static const u32 lumaIndex[16] = {   0,   4,  64,  68,
+                                     8,  12,  72,  76,
+                                   128, 132, 192, 196,
+                                   136, 140, 200, 204 };
+#endif
+/* mapping of dc coefficients array to luma blocks */
+static const u32 dcCoeffIndex[16] =
+    {0, 1, 4, 5, 2, 3, 6, 7, 8, 9, 12, 13, 10, 11, 14, 15};
+
+/*------------------------------------------------------------------------------
+    4. Local function prototypes
+------------------------------------------------------------------------------*/
+
+static u32 DecodeMbPred(strmData_t *pStrmData, mbPred_t *pMbPred,
+    mbType_e mbType, u32 numRefIdxActive);
+static u32 DecodeSubMbPred(strmData_t *pStrmData, subMbPred_t *pSubMbPred,
+    mbType_e mbType, u32 numRefIdxActive);
+static u32 DecodeResidual(strmData_t *pStrmData, residual_t *pResidual,
+    mbStorage_t *pMb, mbType_e mbType, u32 codedBlockPattern);
+
+#ifdef H264DEC_OMXDL
+static u32 DetermineNc(mbStorage_t *pMb, u32 blockIndex, u8 *pTotalCoeff);
+#else
+static u32 DetermineNc(mbStorage_t *pMb, u32 blockIndex, i16 *pTotalCoeff);
+#endif
+
+static u32 CbpIntra16x16(mbType_e mbType);
+#ifdef H264DEC_OMXDL
+static u32 ProcessIntra4x4Residual(mbStorage_t *pMb, u8 *data, u32 constrainedIntraPred,
+                    macroblockLayer_t *mbLayer, const u8 **pSrc, image_t *image);
+static u32 ProcessChromaResidual(mbStorage_t *pMb, u8 *data, const u8 **pSrc );
+static u32 ProcessIntra16x16Residual(mbStorage_t *pMb, u8 *data, u32 constrainedIntraPred,
+                    u32 intraChromaPredMode, const u8 **pSrc, image_t *image);
+
+
+#else
+static u32 ProcessResidual(mbStorage_t *pMb, i32 residualLevel[][16], u32 *);
+#endif
+
+/*------------------------------------------------------------------------------
+
+    Function name: h264bsdDecodeMacroblockLayer
+
+        Functional description:
+          Parse macroblock specific information from bit stream.
+
+        Inputs:
+          pStrmData         pointer to stream data structure
+          pMb               pointer to macroblock storage structure
+          sliceType         type of the current slice
+          numRefIdxActive   maximum reference index
+
+        Outputs:
+          pMbLayer          stores the macroblock data parsed from stream
+
+        Returns:
+          HANTRO_OK         success
+          HANTRO_NOK        end of stream or error in stream
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdDecodeMacroblockLayer(strmData_t *pStrmData,
+    macroblockLayer_t *pMbLayer, mbStorage_t *pMb, u32 sliceType,
+    u32 numRefIdxActive)
+{
+
+/* Variables */
+
+    u32 tmp, i, value;
+    i32 itmp;
+    mbPartPredMode_e partMode;
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(pMbLayer);
+
+#ifdef H264DEC_NEON
+    h264bsdClearMbLayer(pMbLayer, ((sizeof(macroblockLayer_t) + 63) & ~0x3F));
+#else
+    H264SwDecMemset(pMbLayer, 0, sizeof(macroblockLayer_t));
+#endif
+
+    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);
+
+    if (IS_I_SLICE(sliceType))
+    {
+        if ((value + 6) > 31 || tmp != HANTRO_OK)
+            return(HANTRO_NOK);
+        pMbLayer->mbType = (mbType_e)(value + 6);
+    }
+    else
+    {
+        if ((value + 1) > 31 || tmp != HANTRO_OK)
+            return(HANTRO_NOK);
+        pMbLayer->mbType = (mbType_e)(value + 1);
+    }
+
+    if (pMbLayer->mbType == I_PCM)
+    {
+        i32 *level;
+        while( !h264bsdIsByteAligned(pStrmData) )
+        {
+            /* pcm_alignment_zero_bit */
+            tmp = h264bsdGetBits(pStrmData, 1);
+            if (tmp)
+                return(HANTRO_NOK);
+        }
+
+        level = pMbLayer->residual.level[0];
+        for (i = 0; i < 384; i++)
+        {
+            value = h264bsdGetBits(pStrmData, 8);
+            if (value == END_OF_STREAM)
+                return(HANTRO_NOK);
+            *level++ = (i32)value;
+        }
+    }
+    else
+    {
+        partMode = h264bsdMbPartPredMode(pMbLayer->mbType);
+        if ( (partMode == PRED_MODE_INTER) &&
+             (h264bsdNumMbPart(pMbLayer->mbType) == 4) )
+        {
+            tmp = DecodeSubMbPred(pStrmData, &pMbLayer->subMbPred,
+                pMbLayer->mbType, numRefIdxActive);
+        }
+        else
+        {
+            tmp = DecodeMbPred(pStrmData, &pMbLayer->mbPred,
+                pMbLayer->mbType, numRefIdxActive);
+        }
+        if (tmp != HANTRO_OK)
+            return(tmp);
+
+        if (partMode != PRED_MODE_INTRA16x16)
+        {
+            tmp = h264bsdDecodeExpGolombMapped(pStrmData, &value,
+                (u32)(partMode == PRED_MODE_INTRA4x4));
+            if (tmp != HANTRO_OK)
+                return(tmp);
+            pMbLayer->codedBlockPattern = value;
+        }
+        else
+        {
+            pMbLayer->codedBlockPattern = CbpIntra16x16(pMbLayer->mbType);
+        }
+
+        if ( pMbLayer->codedBlockPattern ||
+             (partMode == PRED_MODE_INTRA16x16) )
+        {
+            tmp = h264bsdDecodeExpGolombSigned(pStrmData, &itmp);
+            if (tmp != HANTRO_OK || (itmp < -26) || (itmp > 25) )
+                return(HANTRO_NOK);
+            pMbLayer->mbQpDelta = itmp;
+
+            tmp = DecodeResidual(pStrmData, &pMbLayer->residual, pMb,
+                pMbLayer->mbType, pMbLayer->codedBlockPattern);
+
+            pStrmData->strmBuffReadBits =
+                (u32)(pStrmData->pStrmCurrPos - pStrmData->pStrmBuffStart) * 8 +
+                pStrmData->bitPosInWord;
+
+            if (tmp != HANTRO_OK)
+                return(tmp);
+        }
+    }
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdMbPartPredMode
+
+        Functional description:
+          Returns the prediction mode of a macroblock type
+
+------------------------------------------------------------------------------*/
+
+mbPartPredMode_e h264bsdMbPartPredMode(mbType_e mbType)
+{
+
+/* Variables */
+
+
+/* Code */
+
+    ASSERT(mbType <= 31);
+
+    if ((mbType <= P_8x8ref0))
+        return(PRED_MODE_INTER);
+    else if (mbType == I_4x4)
+        return(PRED_MODE_INTRA4x4);
+    else
+        return(PRED_MODE_INTRA16x16);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdNumMbPart
+
+        Functional description:
+          Returns the amount of macroblock partitions in a macroblock type
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdNumMbPart(mbType_e mbType)
+{
+
+/* Variables */
+
+
+/* Code */
+
+    ASSERT(h264bsdMbPartPredMode(mbType) == PRED_MODE_INTER);
+
+    switch (mbType)
+    {
+        case P_L0_16x16:
+        case P_Skip:
+            return(1);
+
+        case P_L0_L0_16x8:
+        case P_L0_L0_8x16:
+            return(2);
+
+        /* P_8x8 or P_8x8ref0 */
+        default:
+            return(4);
+    }
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdNumSubMbPart
+
+        Functional description:
+          Returns the amount of sub-partitions in a sub-macroblock type
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdNumSubMbPart(subMbType_e subMbType)
+{
+
+/* Variables */
+
+
+/* Code */
+
+    ASSERT(subMbType <= P_L0_4x4);
+
+    switch (subMbType)
+    {
+        case P_L0_8x8:
+            return(1);
+
+        case P_L0_8x4:
+        case P_L0_4x8:
+            return(2);
+
+        /* P_L0_4x4 */
+        default:
+            return(4);
+    }
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: DecodeMbPred
+
+        Functional description:
+          Parse macroblock prediction information from bit stream and store
+          in 'pMbPred'.
+
+------------------------------------------------------------------------------*/
+
+u32 DecodeMbPred(strmData_t *pStrmData, mbPred_t *pMbPred, mbType_e mbType,
+    u32 numRefIdxActive)
+{
+
+/* Variables */
+
+    u32 tmp, i, j, value;
+    i32 itmp;
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(pMbPred);
+
+    switch (h264bsdMbPartPredMode(mbType))
+    {
+        case PRED_MODE_INTER: /* PRED_MODE_INTER */
+            if (numRefIdxActive > 1)
+            {
+                for (i = h264bsdNumMbPart(mbType), j = 0; i--;  j++)
+                {
+                    tmp = h264bsdDecodeExpGolombTruncated(pStrmData, &value,
+                        (u32)(numRefIdxActive > 2));
+                    if (tmp != HANTRO_OK || value >= numRefIdxActive)
+                        return(HANTRO_NOK);
+
+                    pMbPred->refIdxL0[j] = value;
+                }
+            }
+
+            for (i = h264bsdNumMbPart(mbType), j = 0; i--;  j++)
+            {
+                tmp = h264bsdDecodeExpGolombSigned(pStrmData, &itmp);
+                if (tmp != HANTRO_OK)
+                    return(tmp);
+                pMbPred->mvdL0[j].hor = (i16)itmp;
+
+                tmp = h264bsdDecodeExpGolombSigned(pStrmData, &itmp);
+                if (tmp != HANTRO_OK)
+                    return(tmp);
+                pMbPred->mvdL0[j].ver = (i16)itmp;
+            }
+            break;
+
+        case PRED_MODE_INTRA4x4:
+            for (itmp = 0, i = 0; itmp < 2; itmp++)
+            {
+                value = h264bsdShowBits32(pStrmData);
+                tmp = 0;
+                for (j = 8; j--; i++)
+                {
+                    pMbPred->prevIntra4x4PredModeFlag[i] =
+                        value & 0x80000000 ? HANTRO_TRUE : HANTRO_FALSE;
+                    value <<= 1;
+                    if (!pMbPred->prevIntra4x4PredModeFlag[i])
+                    {
+                        pMbPred->remIntra4x4PredMode[i] = value>>29;
+                        value <<= 3;
+                        tmp++;
+                    }
+                }
+                if (h264bsdFlushBits(pStrmData, 8 + 3*tmp) == END_OF_STREAM)
+                    return(HANTRO_NOK);
+            }
+            /* fall-through */
+
+        case PRED_MODE_INTRA16x16:
+            tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);
+            if (tmp != HANTRO_OK || value > 3)
+                return(HANTRO_NOK);
+            pMbPred->intraChromaPredMode = value;
+            break;
+    }
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: DecodeSubMbPred
+
+        Functional description:
+          Parse sub-macroblock prediction information from bit stream and
+          store in 'pMbPred'.
+
+------------------------------------------------------------------------------*/
+
+u32 DecodeSubMbPred(strmData_t *pStrmData, subMbPred_t *pSubMbPred,
+    mbType_e mbType, u32 numRefIdxActive)
+{
+
+/* Variables */
+
+    u32 tmp, i, j, value;
+    i32 itmp;
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(pSubMbPred);
+    ASSERT(h264bsdMbPartPredMode(mbType) == PRED_MODE_INTER);
+
+    for (i = 0; i < 4; i++)
+    {
+        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);
+        if (tmp != HANTRO_OK || value > 3)
+            return(HANTRO_NOK);
+        pSubMbPred->subMbType[i] = (subMbType_e)value;
+    }
+
+    if ( (numRefIdxActive > 1) && (mbType != P_8x8ref0) )
+    {
+        for (i = 0; i < 4; i++)
+        {
+            tmp = h264bsdDecodeExpGolombTruncated(pStrmData, &value,
+                (u32)(numRefIdxActive > 2));
+            if (tmp != HANTRO_OK || value >= numRefIdxActive)
+                return(HANTRO_NOK);
+            pSubMbPred->refIdxL0[i] = value;
+        }
+    }
+
+    for (i = 0; i < 4; i++)
+    {
+        j = 0;
+        for (value = h264bsdNumSubMbPart(pSubMbPred->subMbType[i]);
+             value--; j++)
+        {
+            tmp = h264bsdDecodeExpGolombSigned(pStrmData, &itmp);
+            if (tmp != HANTRO_OK)
+                return(tmp);
+            pSubMbPred->mvdL0[i][j].hor = (i16)itmp;
+
+            tmp = h264bsdDecodeExpGolombSigned(pStrmData, &itmp);
+            if (tmp != HANTRO_OK)
+                return(tmp);
+            pSubMbPred->mvdL0[i][j].ver = (i16)itmp;
+        }
+    }
+
+    return(HANTRO_OK);
+
+}
+
+#ifdef H264DEC_OMXDL
+/*------------------------------------------------------------------------------
+
+    Function: DecodeResidual
+
+        Functional description:
+          Parse residual information from bit stream and store in 'pResidual'.
+
+------------------------------------------------------------------------------*/
+
+u32 DecodeResidual(strmData_t *pStrmData, residual_t *pResidual,
+    mbStorage_t *pMb, mbType_e mbType, u32 codedBlockPattern)
+{
+
+/* Variables */
+
+    u32 i, j;
+    u32 blockCoded;
+    u32 blockIndex;
+    u32 is16x16;
+    OMX_INT nc;
+    OMXResult omxRes;
+    OMX_U8 *pPosCoefBuf;
+
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(pResidual);
+
+    pPosCoefBuf = pResidual->posCoefBuf;
+
+    /* luma DC is at index 24 */
+    if (h264bsdMbPartPredMode(mbType) == PRED_MODE_INTRA16x16)
+    {
+        nc = (OMX_INT)DetermineNc(pMb, 0, pResidual->totalCoeff);
+#ifndef H264DEC_NEON
+        omxRes =  omxVCM4P10_DecodeCoeffsToPairCAVLC(
+                (const OMX_U8 **) (&pStrmData->pStrmCurrPos),
+                (OMX_S32*) (&pStrmData->bitPosInWord),
+                &pResidual->totalCoeff[24],
+                &pPosCoefBuf,
+                nc,
+                16);
+#else
+        omxRes = armVCM4P10_DecodeCoeffsToPair(
+                (const OMX_U8 **) (&pStrmData->pStrmCurrPos),
+                (OMX_S32*) (&pStrmData->bitPosInWord),
+                &pResidual->totalCoeff[24],
+                &pPosCoefBuf,
+                nc,
+                16);
+#endif
+        if (omxRes != OMX_Sts_NoErr)
+            return(HANTRO_NOK);
+        is16x16 = HANTRO_TRUE;
+    }
+    else
+        is16x16 = HANTRO_FALSE;
+
+    for (i = 4, blockIndex = 0; i--;)
+    {
+        /* luma cbp in bits 0-3 */
+        blockCoded = codedBlockPattern & 0x1;
+        codedBlockPattern >>= 1;
+        if (blockCoded)
+        {
+            for (j = 4; j--; blockIndex++)
+            {
+                nc = (OMX_INT)DetermineNc(pMb,blockIndex,pResidual->totalCoeff);
+                if (is16x16)
+                {
+#ifndef H264DEC_NEON
+                    omxRes =  omxVCM4P10_DecodeCoeffsToPairCAVLC(
+                            (const OMX_U8 **) (&pStrmData->pStrmCurrPos),
+                            (OMX_S32*) (&pStrmData->bitPosInWord),
+                            &pResidual->totalCoeff[blockIndex],
+                            &pPosCoefBuf,
+                            nc,
+                            15);
+#else
+                    omxRes =  armVCM4P10_DecodeCoeffsToPair(
+                            (const OMX_U8 **) (&pStrmData->pStrmCurrPos),
+                            (OMX_S32*) (&pStrmData->bitPosInWord),
+                            &pResidual->totalCoeff[blockIndex],
+                            &pPosCoefBuf,
+                            nc,
+                            15);
+#endif
+                }
+                else
+                {
+#ifndef H264DEC_NEON
+                    omxRes =  omxVCM4P10_DecodeCoeffsToPairCAVLC(
+                            (const OMX_U8 **) (&pStrmData->pStrmCurrPos),
+                            (OMX_S32*) (&pStrmData->bitPosInWord),
+                            &pResidual->totalCoeff[blockIndex],
+                            &pPosCoefBuf,
+                            nc,
+                            16);
+#else
+                    omxRes = armVCM4P10_DecodeCoeffsToPair(
+                            (const OMX_U8 **) (&pStrmData->pStrmCurrPos),
+                            (OMX_S32*) (&pStrmData->bitPosInWord),
+                            &pResidual->totalCoeff[blockIndex],
+                            &pPosCoefBuf,
+                            nc,
+                            16);
+#endif
+                }
+                if (omxRes != OMX_Sts_NoErr)
+                    return(HANTRO_NOK);
+            }
+        }
+        else
+            blockIndex += 4;
+    }
+
+    /* chroma DC block are at indices 25 and 26 */
+    blockCoded = codedBlockPattern & 0x3;
+    if (blockCoded)
+    {
+#ifndef H264DEC_NEON
+        omxRes =  omxVCM4P10_DecodeChromaDcCoeffsToPairCAVLC(
+                (const OMX_U8**) (&pStrmData->pStrmCurrPos),
+                (OMX_S32*) (&pStrmData->bitPosInWord),
+                &pResidual->totalCoeff[25],
+                &pPosCoefBuf);
+#else
+        omxRes = armVCM4P10_DecodeCoeffsToPair(
+                (const OMX_U8**) (&pStrmData->pStrmCurrPos),
+                (OMX_S32*) (&pStrmData->bitPosInWord),
+                &pResidual->totalCoeff[25],
+                &pPosCoefBuf,
+                17,
+                4);
+#endif
+        if (omxRes != OMX_Sts_NoErr)
+            return(HANTRO_NOK);
+#ifndef H264DEC_NEON
+        omxRes =  omxVCM4P10_DecodeChromaDcCoeffsToPairCAVLC(
+                (const OMX_U8**) (&pStrmData->pStrmCurrPos),
+                (OMX_S32*) (&pStrmData->bitPosInWord),
+                &pResidual->totalCoeff[26],
+                &pPosCoefBuf);
+#else
+        omxRes = armVCM4P10_DecodeCoeffsToPair(
+                (const OMX_U8**) (&pStrmData->pStrmCurrPos),
+                (OMX_S32*) (&pStrmData->bitPosInWord),
+                &pResidual->totalCoeff[26],
+                &pPosCoefBuf,
+                17,
+                4);
+#endif
+        if (omxRes != OMX_Sts_NoErr)
+            return(HANTRO_NOK);
+    }
+
+    /* chroma AC */
+    blockCoded = codedBlockPattern & 0x2;
+    if (blockCoded)
+    {
+        for (i = 8; i--;blockIndex++)
+        {
+            nc = (OMX_INT)DetermineNc(pMb, blockIndex, pResidual->totalCoeff);
+#ifndef H264DEC_NEON
+            omxRes =  omxVCM4P10_DecodeCoeffsToPairCAVLC(
+                    (const OMX_U8 **) (&pStrmData->pStrmCurrPos),
+                    (OMX_S32*) (&pStrmData->bitPosInWord),
+                    &pResidual->totalCoeff[blockIndex],
+                    &pPosCoefBuf,
+                    nc,
+                    15);
+#else
+            omxRes =  armVCM4P10_DecodeCoeffsToPair(
+                    (const OMX_U8 **) (&pStrmData->pStrmCurrPos),
+                    (OMX_S32*) (&pStrmData->bitPosInWord),
+                    &pResidual->totalCoeff[blockIndex],
+                    &pPosCoefBuf,
+                    nc,
+                    15);
+#endif
+            if (omxRes != OMX_Sts_NoErr)
+                return(HANTRO_NOK);
+        }
+    }
+
+    return(HANTRO_OK);
+
+}
+
+#else
+/*------------------------------------------------------------------------------
+
+    Function: DecodeResidual
+
+        Functional description:
+          Parse residual information from bit stream and store in 'pResidual'.
+
+------------------------------------------------------------------------------*/
+
+u32 DecodeResidual(strmData_t *pStrmData, residual_t *pResidual,
+    mbStorage_t *pMb, mbType_e mbType, u32 codedBlockPattern)
+{
+
+/* Variables */
+
+    u32 i, j, tmp;
+    i32 nc;
+    u32 blockCoded;
+    u32 blockIndex;
+    u32 is16x16;
+    i32 (*level)[16];
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(pResidual);
+
+    level = pResidual->level;
+
+    /* luma DC is at index 24 */
+    if (h264bsdMbPartPredMode(mbType) == PRED_MODE_INTRA16x16)
+    {
+        nc = (i32)DetermineNc(pMb, 0, pResidual->totalCoeff);
+        tmp = h264bsdDecodeResidualBlockCavlc(pStrmData, level[24], nc, 16);
+        if ((tmp & 0xF) != HANTRO_OK)
+            return(tmp);
+        pResidual->totalCoeff[24] = (tmp >> 4) & 0xFF;
+        is16x16 = HANTRO_TRUE;
+    }
+    else
+        is16x16 = HANTRO_FALSE;
+
+    for (i = 4, blockIndex = 0; i--;)
+    {
+        /* luma cbp in bits 0-3 */
+        blockCoded = codedBlockPattern & 0x1;
+        codedBlockPattern >>= 1;
+        if (blockCoded)
+        {
+            for (j = 4; j--; blockIndex++)
+            {
+                nc = (i32)DetermineNc(pMb, blockIndex, pResidual->totalCoeff);
+                if (is16x16)
+                {
+                    tmp = h264bsdDecodeResidualBlockCavlc(pStrmData,
+                        level[blockIndex] + 1, nc, 15);
+                    pResidual->coeffMap[blockIndex] = tmp >> 15;
+                }
+                else
+                {
+                    tmp = h264bsdDecodeResidualBlockCavlc(pStrmData,
+                        level[blockIndex], nc, 16);
+                    pResidual->coeffMap[blockIndex] = tmp >> 16;
+                }
+                if ((tmp & 0xF) != HANTRO_OK)
+                    return(tmp);
+                pResidual->totalCoeff[blockIndex] = (tmp >> 4) & 0xFF;
+            }
+        }
+        else
+            blockIndex += 4;
+    }
+
+    /* chroma DC block are at indices 25 and 26 */
+    blockCoded = codedBlockPattern & 0x3;
+    if (blockCoded)
+    {
+        tmp = h264bsdDecodeResidualBlockCavlc(pStrmData, level[25], -1, 4);
+        if ((tmp & 0xF) != HANTRO_OK)
+            return(tmp);
+        pResidual->totalCoeff[25] = (tmp >> 4) & 0xFF;
+        tmp = h264bsdDecodeResidualBlockCavlc(pStrmData, level[25]+4, -1, 4);
+        if ((tmp & 0xF) != HANTRO_OK)
+            return(tmp);
+        pResidual->totalCoeff[26] = (tmp >> 4) & 0xFF;
+    }
+
+    /* chroma AC */
+    blockCoded = codedBlockPattern & 0x2;
+    if (blockCoded)
+    {
+        for (i = 8; i--;blockIndex++)
+        {
+            nc = (i32)DetermineNc(pMb, blockIndex, pResidual->totalCoeff);
+            tmp = h264bsdDecodeResidualBlockCavlc(pStrmData,
+                level[blockIndex] + 1, nc, 15);
+            if ((tmp & 0xF) != HANTRO_OK)
+                return(tmp);
+            pResidual->totalCoeff[blockIndex] = (tmp >> 4) & 0xFF;
+            pResidual->coeffMap[blockIndex] = (tmp >> 15);
+        }
+    }
+
+    return(HANTRO_OK);
+
+}
+#endif
+
+/*------------------------------------------------------------------------------
+
+    Function: DetermineNc
+
+        Functional description:
+          Returns the nC of a block.
+
+------------------------------------------------------------------------------*/
+#ifdef H264DEC_OMXDL
+u32 DetermineNc(mbStorage_t *pMb, u32 blockIndex, u8 *pTotalCoeff)
+#else
+u32 DetermineNc(mbStorage_t *pMb, u32 blockIndex, i16 *pTotalCoeff)
+#endif
+{
+/*lint -e702 */
+/* Variables */
+
+    u32 tmp;
+    i32 n;
+    const neighbour_t *neighbourA, *neighbourB;
+    u8 neighbourAindex, neighbourBindex;
+
+/* Code */
+
+    ASSERT(blockIndex < 24);
+
+    /* if neighbour block belongs to current macroblock totalCoeff array
+     * mbStorage has not been set/updated yet -> use pTotalCoeff */
+    neighbourA = h264bsdNeighbour4x4BlockA(blockIndex);
+    neighbourB = h264bsdNeighbour4x4BlockB(blockIndex);
+    neighbourAindex = neighbourA->index;
+    neighbourBindex = neighbourB->index;
+    if (neighbourA->mb == MB_CURR && neighbourB->mb == MB_CURR)
+    {
+        n = (pTotalCoeff[neighbourAindex] +
+             pTotalCoeff[neighbourBindex] + 1)>>1;
+    }
+    else if (neighbourA->mb == MB_CURR)
+    {
+        n = pTotalCoeff[neighbourAindex];
+        if (h264bsdIsNeighbourAvailable(pMb, pMb->mbB))
+        {
+            n = (n + pMb->mbB->totalCoeff[neighbourBindex] + 1) >> 1;
+        }
+    }
+    else if (neighbourB->mb == MB_CURR)
+    {
+        n = pTotalCoeff[neighbourBindex];
+        if (h264bsdIsNeighbourAvailable(pMb, pMb->mbA))
+        {
+            n = (n + pMb->mbA->totalCoeff[neighbourAindex] + 1) >> 1;
+        }
+    }
+    else
+    {
+        n = tmp = 0;
+        if (h264bsdIsNeighbourAvailable(pMb, pMb->mbA))
+        {
+            n = pMb->mbA->totalCoeff[neighbourAindex];
+            tmp = 1;
+        }
+        if (h264bsdIsNeighbourAvailable(pMb, pMb->mbB))
+        {
+            if (tmp)
+                n = (n + pMb->mbB->totalCoeff[neighbourBindex] + 1) >> 1;
+            else
+                n = pMb->mbB->totalCoeff[neighbourBindex];
+        }
+    }
+    return((u32)n);
+/*lint +e702 */
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: CbpIntra16x16
+
+        Functional description:
+          Returns the coded block pattern for intra 16x16 macroblock.
+
+------------------------------------------------------------------------------*/
+
+u32 CbpIntra16x16(mbType_e mbType)
+{
+
+/* Variables */
+
+    u32 cbp;
+    u32 tmp;
+
+/* Code */
+
+    ASSERT(mbType >= I_16x16_0_0_0 && mbType <= I_16x16_3_2_1);
+
+    if (mbType >= I_16x16_0_0_1)
+        cbp = 15;
+    else
+        cbp = 0;
+
+    /* tmp is 0 for I_16x16_0_0_0 mb type */
+    /* ignore lint warning on arithmetic on enum's */
+    tmp = /*lint -e(656)*/(mbType - I_16x16_0_0_0) >> 2;
+    if (tmp > 2)
+        tmp -= 3;
+
+    cbp += tmp << 4;
+
+    return(cbp);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdPredModeIntra16x16
+
+        Functional description:
+          Returns the prediction mode for intra 16x16 macroblock.
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdPredModeIntra16x16(mbType_e mbType)
+{
+
+/* Variables */
+
+    u32 tmp;
+
+/* Code */
+
+    ASSERT(mbType >= I_16x16_0_0_0 && mbType <= I_16x16_3_2_1);
+
+    /* tmp is 0 for I_16x16_0_0_0 mb type */
+    /* ignore lint warning on arithmetic on enum's */
+    tmp = /*lint -e(656)*/(mbType - I_16x16_0_0_0);
+
+    return(tmp & 0x3);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdDecodeMacroblock
+
+        Functional description:
+          Decode one macroblock and write into output image.
+
+        Inputs:
+          pMb           pointer to macroblock specific information
+          mbLayer       pointer to current macroblock data from stream
+          currImage     pointer to output image
+          dpb           pointer to decoded picture buffer
+          qpY           pointer to slice QP
+          mbNum         current macroblock number
+          constrainedIntraPred  flag specifying if neighbouring inter
+                                macroblocks are used in intra prediction
+
+        Outputs:
+          pMb           structure is updated with current macroblock
+          currImage     decoded macroblock is written into output image
+
+        Returns:
+          HANTRO_OK     success
+          HANTRO_NOK    error in macroblock decoding
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdDecodeMacroblock(mbStorage_t *pMb, macroblockLayer_t *pMbLayer,
+    image_t *currImage, dpbStorage_t *dpb, i32 *qpY, u32 mbNum,
+    u32 constrainedIntraPredFlag, u8* data)
+{
+
+/* Variables */
+
+    u32 i, tmp;
+    mbType_e mbType;
+#ifdef H264DEC_OMXDL
+    const u8 *pSrc;
+#endif
+/* Code */
+
+    ASSERT(pMb);
+    ASSERT(pMbLayer);
+    ASSERT(currImage);
+    ASSERT(qpY && *qpY < 52);
+    ASSERT(mbNum < currImage->width*currImage->height);
+
+    mbType = pMbLayer->mbType;
+    pMb->mbType = mbType;
+
+    pMb->decoded++;
+
+    h264bsdSetCurrImageMbPointers(currImage, mbNum);
+
+    if (mbType == I_PCM)
+    {
+        u8 *pData = (u8*)data;
+#ifdef H264DEC_OMXDL
+        u8 *tot = pMb->totalCoeff;
+#else
+        i16 *tot = pMb->totalCoeff;
+#endif
+        i32 *lev = pMbLayer->residual.level[0];
+
+        pMb->qpY = 0;
+
+        /* if decoded flag > 1 -> mb has already been successfully decoded and
+         * written to output -> do not write again */
+        if (pMb->decoded > 1)
+        {
+            for (i = 24; i--;)
+                *tot++ = 16;
+            return HANTRO_OK;
+        }
+
+        for (i = 24; i--;)
+        {
+            *tot++ = 16;
+            for (tmp = 16; tmp--;)
+                *pData++ = (u8)(*lev++);
+        }
+        h264bsdWriteMacroblock(currImage, (u8*)data);
+
+        return(HANTRO_OK);
+    }
+    else
+    {
+#ifdef H264DEC_OMXDL
+        if (h264bsdMbPartPredMode(mbType) == PRED_MODE_INTER)
+        {
+            tmp = h264bsdInterPrediction(pMb, pMbLayer, dpb, mbNum,
+                currImage, (u8*)data);
+            if (tmp != HANTRO_OK) return (tmp);
+        }
+#endif
+        if (mbType != P_Skip)
+        {
+            H264SwDecMemcpy(pMb->totalCoeff,
+                            pMbLayer->residual.totalCoeff,
+                            27*sizeof(*pMb->totalCoeff));
+
+            /* update qpY */
+            if (pMbLayer->mbQpDelta)
+            {
+                *qpY = *qpY + pMbLayer->mbQpDelta;
+                if (*qpY < 0) *qpY += 52;
+                else if (*qpY >= 52) *qpY -= 52;
+            }
+            pMb->qpY = (u32)*qpY;
+
+#ifdef H264DEC_OMXDL
+            pSrc = pMbLayer->residual.posCoefBuf;
+
+            if (h264bsdMbPartPredMode(mbType) == PRED_MODE_INTER)
+            {
+                OMXResult res;
+                u8 *p;
+                u8 *totalCoeff = pMb->totalCoeff;
+
+                for (i = 0; i < 16; i++, totalCoeff++)
+                {
+                    p = data + lumaIndex[i];
+                    if (*totalCoeff)
+                    {
+                        res = omxVCM4P10_DequantTransformResidualFromPairAndAdd(
+                                &pSrc, p, 0, p, 16, 16, *qpY, *totalCoeff);
+                        if (res != OMX_Sts_NoErr)
+                            return (HANTRO_NOK);
+                    }
+                }
+
+            }
+            else if (h264bsdMbPartPredMode(mbType) == PRED_MODE_INTRA4x4)
+            {
+                tmp = ProcessIntra4x4Residual(pMb,
+                                              data,
+                                              constrainedIntraPredFlag,
+                                              pMbLayer,
+                                              &pSrc,
+                                              currImage);
+                if (tmp != HANTRO_OK)
+                    return (tmp);
+            }
+            else if (h264bsdMbPartPredMode(mbType) == PRED_MODE_INTRA16x16)
+            {
+                tmp = ProcessIntra16x16Residual(pMb,
+                                        data,
+                                        constrainedIntraPredFlag,
+                                        pMbLayer->mbPred.intraChromaPredMode,
+                                        &pSrc,
+                                        currImage);
+                if (tmp != HANTRO_OK)
+                    return (tmp);
+            }
+
+            tmp = ProcessChromaResidual(pMb, data, &pSrc);
+
+#else
+            tmp = ProcessResidual(pMb, pMbLayer->residual.level,
+                pMbLayer->residual.coeffMap);
+#endif
+            if (tmp != HANTRO_OK)
+                return (tmp);
+        }
+        else
+        {
+            H264SwDecMemset(pMb->totalCoeff, 0, 27*sizeof(*pMb->totalCoeff));
+            pMb->qpY = (u32)*qpY;
+        }
+#ifdef H264DEC_OMXDL
+        /* if decoded flag > 1 -> mb has already been successfully decoded and
+         * written to output -> do not write again */
+        if (pMb->decoded > 1)
+            return HANTRO_OK;
+
+        h264bsdWriteMacroblock(currImage, data);
+#else
+        if (h264bsdMbPartPredMode(mbType) != PRED_MODE_INTER)
+        {
+            tmp = h264bsdIntraPrediction(pMb, pMbLayer, currImage, mbNum,
+                constrainedIntraPredFlag, (u8*)data);
+            if (tmp != HANTRO_OK) return (tmp);
+        }
+        else
+        {
+            tmp = h264bsdInterPrediction(pMb, pMbLayer, dpb, mbNum,
+                currImage, (u8*)data);
+            if (tmp != HANTRO_OK) return (tmp);
+        }
+#endif
+    }
+
+    return HANTRO_OK;
+}
+
+
+#ifdef H264DEC_OMXDL
+
+/*------------------------------------------------------------------------------
+
+    Function: ProcessChromaResidual
+
+        Functional description:
+          Process the residual data of chroma with
+          inverse quantization and inverse transform.
+
+------------------------------------------------------------------------------*/
+u32 ProcessChromaResidual(mbStorage_t *pMb, u8 *data, const u8 **pSrc )
+{
+    u32 i;
+    u32 chromaQp;
+    i16 *pDc;
+    i16 dc[4 + 4] = {0,0,0,0,0,0,0,0};
+    u8 *totalCoeff;
+    OMXResult result;
+    u8 *p;
+
+    /* chroma DC processing. First chroma dc block is block with index 25 */
+    chromaQp =
+        h264bsdQpC[CLIP3(0, 51, (i32)pMb->qpY + pMb->chromaQpIndexOffset)];
+
+    if (pMb->totalCoeff[25])
+    {
+        pDc = dc;
+        result = omxVCM4P10_TransformDequantChromaDCFromPair(
+                pSrc,
+                pDc,
+                (i32)chromaQp);
+        if (result != OMX_Sts_NoErr)
+            return (HANTRO_NOK);
+    }
+    if (pMb->totalCoeff[26])
+    {
+        pDc = dc+4;
+        result = omxVCM4P10_TransformDequantChromaDCFromPair(
+                pSrc,
+                pDc,
+                (i32)chromaQp);
+        if (result != OMX_Sts_NoErr)
+            return (HANTRO_NOK);
+    }
+
+    pDc = dc;
+    totalCoeff = pMb->totalCoeff + 16;
+    for (i = 0; i < 8; i++, pDc++, totalCoeff++)
+    {
+        /* chroma prediction */
+        if (*totalCoeff || *pDc)
+        {
+            p = data + chromaIndex[i];
+            result = omxVCM4P10_DequantTransformResidualFromPairAndAdd(
+                    pSrc,
+                    p,
+                    pDc,
+                    p,
+                    8,
+                    8,
+                    (i32)chromaQp,
+                    *totalCoeff);
+            if (result != OMX_Sts_NoErr)
+                return (HANTRO_NOK);
+        }
+    }
+
+    return(HANTRO_OK);
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: ProcessIntra16x16Residual
+
+        Functional description:
+          Process the residual data of luma with
+          inverse quantization and inverse transform.
+
+------------------------------------------------------------------------------*/
+u32 ProcessIntra16x16Residual(mbStorage_t *pMb,
+                              u8 *data,
+                              u32 constrainedIntraPred,
+                              u32 intraChromaPredMode,
+                              const u8** pSrc,
+                              image_t *image)
+{
+    u32 i;
+    i16 *pDc;
+    i16 dc[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+    u8 *totalCoeff;
+    OMXResult result;
+    u8 *p;
+
+    totalCoeff = pMb->totalCoeff;
+
+    if (totalCoeff[24])
+    {
+        pDc = dc;
+        result = omxVCM4P10_TransformDequantLumaDCFromPair(
+                    pSrc,
+                    pDc,
+                    (i32)pMb->qpY);
+        if (result != OMX_Sts_NoErr)
+            return (HANTRO_NOK);
+    }
+    /* Intra 16x16 pred */
+    if (h264bsdIntra16x16Prediction(pMb, data, image->luma,
+                            image->width*16, constrainedIntraPred) != HANTRO_OK)
+        return(HANTRO_NOK);
+    for (i = 0; i < 16; i++, totalCoeff++)
+    {
+        p = data + lumaIndex[i];
+        pDc = &dc[dcCoeffIndex[i]];
+        if (*totalCoeff || *pDc)
+        {
+            result = omxVCM4P10_DequantTransformResidualFromPairAndAdd(
+                    pSrc,
+                    p,
+                    pDc,
+                    p,
+                    16,
+                    16,
+                    (i32)pMb->qpY,
+                    *totalCoeff);
+            if (result != OMX_Sts_NoErr)
+                return (HANTRO_NOK);
+        }
+    }
+
+    if (h264bsdIntraChromaPrediction(pMb, data + 256,
+                image,
+                intraChromaPredMode,
+                constrainedIntraPred) != HANTRO_OK)
+        return(HANTRO_NOK);
+
+    return HANTRO_OK;
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: ProcessIntra4x4Residual
+
+        Functional description:
+          Process the residual data of luma with
+          inverse quantization and inverse transform.
+
+------------------------------------------------------------------------------*/
+u32 ProcessIntra4x4Residual(mbStorage_t *pMb,
+                            u8 *data,
+                            u32 constrainedIntraPred,
+                            macroblockLayer_t *mbLayer,
+                            const u8 **pSrc,
+                            image_t *image)
+{
+    u32 i;
+    u8 *totalCoeff;
+    OMXResult result;
+    u8 *p;
+
+    totalCoeff = pMb->totalCoeff;
+
+    for (i = 0; i < 16; i++, totalCoeff++)
+    {
+        p = data + lumaIndex[i];
+        if (h264bsdIntra4x4Prediction(pMb, p, mbLayer, image->luma,
+                    image->width*16, constrainedIntraPred, i) != HANTRO_OK)
+            return(HANTRO_NOK);
+
+        if (*totalCoeff)
+        {
+            result = omxVCM4P10_DequantTransformResidualFromPairAndAdd(
+                    pSrc,
+                    p,
+                    NULL,
+                    p,
+                    16,
+                    16,
+                    (i32)pMb->qpY,
+                    *totalCoeff);
+            if (result != OMX_Sts_NoErr)
+                return (HANTRO_NOK);
+        }
+    }
+
+    if (h264bsdIntraChromaPrediction(pMb, data + 256,
+                image,
+                mbLayer->mbPred.intraChromaPredMode,
+                constrainedIntraPred) != HANTRO_OK)
+        return(HANTRO_NOK);
+
+    return HANTRO_OK;
+}
+
+#else /* H264DEC_OMXDL */
+
+/*------------------------------------------------------------------------------
+
+    Function: ProcessResidual
+
+        Functional description:
+          Process the residual data of one macroblock with
+          inverse quantization and inverse transform.
+
+------------------------------------------------------------------------------*/
+
+u32 ProcessResidual(mbStorage_t *pMb, i32 residualLevel[][16], u32 *coeffMap)
+{
+
+/* Variables */
+
+    u32 i;
+    u32 chromaQp;
+    i32 (*blockData)[16];
+    i32 (*blockDc)[16];
+    i16 *totalCoeff;
+    i32 *chromaDc;
+    const u32 *dcCoeffIdx;
+
+/* Code */
+
+    ASSERT(pMb);
+    ASSERT(residualLevel);
+
+    /* set pointers to DC coefficient blocks */
+    blockDc = residualLevel + 24;
+
+    blockData = residualLevel;
+    totalCoeff = pMb->totalCoeff;
+    if (h264bsdMbPartPredMode(pMb->mbType) == PRED_MODE_INTRA16x16)
+    {
+        if (totalCoeff[24])
+        {
+            h264bsdProcessLumaDc(*blockDc, pMb->qpY);
+        }
+        dcCoeffIdx = dcCoeffIndex;
+
+        for (i = 16; i--; blockData++, totalCoeff++, coeffMap++)
+        {
+            /* set dc coefficient of luma block */
+            (*blockData)[0] = (*blockDc)[*dcCoeffIdx++];
+            if ((*blockData)[0] || *totalCoeff)
+            {
+                if (h264bsdProcessBlock(*blockData, pMb->qpY, 1, *coeffMap) !=
+                    HANTRO_OK)
+                    return(HANTRO_NOK);
+            }
+            else
+                MARK_RESIDUAL_EMPTY(*blockData);
+        }
+    }
+    else
+    {
+        for (i = 16; i--; blockData++, totalCoeff++, coeffMap++)
+        {
+            if (*totalCoeff)
+            {
+                if (h264bsdProcessBlock(*blockData, pMb->qpY, 0, *coeffMap) !=
+                    HANTRO_OK)
+                    return(HANTRO_NOK);
+            }
+            else
+                MARK_RESIDUAL_EMPTY(*blockData);
+        }
+    }
+
+    /* chroma DC processing. First chroma dc block is block with index 25 */
+    chromaQp =
+        h264bsdQpC[CLIP3(0, 51, (i32)pMb->qpY + pMb->chromaQpIndexOffset)];
+    if (pMb->totalCoeff[25] || pMb->totalCoeff[26])
+        h264bsdProcessChromaDc(residualLevel[25], chromaQp);
+    chromaDc = residualLevel[25];
+    for (i = 8; i--; blockData++, totalCoeff++, coeffMap++)
+    {
+        /* set dc coefficient of chroma block */
+        (*blockData)[0] = *chromaDc++;
+        if ((*blockData)[0] || *totalCoeff)
+        {
+            if (h264bsdProcessBlock(*blockData, chromaQp, 1,*coeffMap) !=
+                HANTRO_OK)
+                return(HANTRO_NOK);
+        }
+        else
+            MARK_RESIDUAL_EMPTY(*blockData);
+    }
+
+    return(HANTRO_OK);
+}
+#endif /* H264DEC_OMXDL */
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdSubMbPartMode
+
+        Functional description:
+          Returns the macroblock's sub-partition mode.
+
+------------------------------------------------------------------------------*/
+
+subMbPartMode_e h264bsdSubMbPartMode(subMbType_e subMbType)
+{
+
+/* Variables */
+
+
+/* Code */
+
+    ASSERT(subMbType < 4);
+
+    return((subMbPartMode_e)subMbType);
+
+}
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_macroblock_layer.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_macroblock_layer.h
new file mode 100755
index 0000000..32bc340
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_macroblock_layer.h
@@ -0,0 +1,212 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+    1. Include headers
+    2. Module defines
+    3. Data types
+    4. Function prototypes
+
+------------------------------------------------------------------------------*/
+
+#ifndef H264SWDEC_MACROBLOCK_LAYER_H
+#define H264SWDEC_MACROBLOCK_LAYER_H
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "basetype.h"
+#include "h264bsd_stream.h"
+#include "h264bsd_image.h"
+#include "h264bsd_dpb.h"
+
+/*------------------------------------------------------------------------------
+    2. Module defines
+------------------------------------------------------------------------------*/
+
+/* Macro to determine if a mb is an intra mb */
+#define IS_INTRA_MB(a) ((a).mbType > 5)
+
+/* Macro to determine if a mb is an I_PCM mb */
+#define IS_I_PCM_MB(a) ((a).mbType == 31)
+
+typedef enum {
+    P_Skip          = 0,
+    P_L0_16x16      = 1,
+    P_L0_L0_16x8    = 2,
+    P_L0_L0_8x16    = 3,
+    P_8x8           = 4,
+    P_8x8ref0       = 5,
+    I_4x4           = 6,
+    I_16x16_0_0_0   = 7,
+    I_16x16_1_0_0   = 8,
+    I_16x16_2_0_0   = 9,
+    I_16x16_3_0_0   = 10,
+    I_16x16_0_1_0   = 11,
+    I_16x16_1_1_0   = 12,
+    I_16x16_2_1_0   = 13,
+    I_16x16_3_1_0   = 14,
+    I_16x16_0_2_0   = 15,
+    I_16x16_1_2_0   = 16,
+    I_16x16_2_2_0   = 17,
+    I_16x16_3_2_0   = 18,
+    I_16x16_0_0_1   = 19,
+    I_16x16_1_0_1   = 20,
+    I_16x16_2_0_1   = 21,
+    I_16x16_3_0_1   = 22,
+    I_16x16_0_1_1   = 23,
+    I_16x16_1_1_1   = 24,
+    I_16x16_2_1_1   = 25,
+    I_16x16_3_1_1   = 26,
+    I_16x16_0_2_1   = 27,
+    I_16x16_1_2_1   = 28,
+    I_16x16_2_2_1   = 29,
+    I_16x16_3_2_1   = 30,
+    I_PCM           = 31
+} mbType_e;
+
+typedef enum {
+    P_L0_8x8 = 0,
+    P_L0_8x4 = 1,
+    P_L0_4x8 = 2,
+    P_L0_4x4 = 3
+} subMbType_e;
+
+typedef enum {
+    MB_P_16x16 = 0,
+    MB_P_16x8,
+    MB_P_8x16,
+    MB_P_8x8
+} mbPartMode_e;
+
+typedef enum {
+    MB_SP_8x8 = 0,
+    MB_SP_8x4,
+    MB_SP_4x8,
+    MB_SP_4x4
+} subMbPartMode_e;
+
+typedef enum {
+    PRED_MODE_INTRA4x4 = 0,
+    PRED_MODE_INTRA16x16  ,
+    PRED_MODE_INTER
+} mbPartPredMode_e;
+
+/*------------------------------------------------------------------------------
+    3. Data types
+------------------------------------------------------------------------------*/
+
+typedef struct
+{
+    /* MvPrediction16x16 assumes that MVs are 16bits */
+    i16 hor;
+    i16 ver;
+} mv_t;
+
+typedef struct
+{
+    u32 prevIntra4x4PredModeFlag[16];
+    u32 remIntra4x4PredMode[16];
+    u32 intraChromaPredMode;
+    u32 refIdxL0[4];
+    mv_t mvdL0[4];
+} mbPred_t;
+
+typedef struct
+{
+    subMbType_e subMbType[4];
+    u32 refIdxL0[4];
+    mv_t mvdL0[4][4];
+} subMbPred_t;
+
+typedef struct
+{
+#ifdef H264DEC_OMXDL
+    u8 posCoefBuf[27*16*3];
+    u8 totalCoeff[27];
+#else
+    i16 totalCoeff[27];
+#endif
+    i32 level[26][16];
+    u32 coeffMap[24];
+} residual_t;
+
+typedef struct
+{
+    mbType_e mbType;
+    u32 codedBlockPattern;
+    i32 mbQpDelta;
+    mbPred_t mbPred;
+    subMbPred_t subMbPred;
+    residual_t residual;
+} macroblockLayer_t;
+
+typedef struct mbStorage
+{
+    mbType_e mbType;
+    u32 sliceId;
+    u32 disableDeblockingFilterIdc;
+    i32 filterOffsetA;
+    i32 filterOffsetB;
+    u32 qpY;
+    i32 chromaQpIndexOffset;
+#ifdef H264DEC_OMXDL
+    u8 totalCoeff[27];
+#else
+    i16 totalCoeff[27];
+#endif
+    u8 intra4x4PredMode[16];
+    u32 refPic[4];
+    u8* refAddr[4];
+    mv_t mv[16];
+    u32 decoded;
+    struct mbStorage *mbA;
+    struct mbStorage *mbB;
+    struct mbStorage *mbC;
+    struct mbStorage *mbD;
+} mbStorage_t;
+
+/*------------------------------------------------------------------------------
+    4. Function prototypes
+------------------------------------------------------------------------------*/
+
+u32 h264bsdDecodeMacroblockLayer(strmData_t *pStrmData,
+    macroblockLayer_t *pMbLayer, mbStorage_t *pMb, u32 sliceType,
+    u32 numRefIdxActive);
+
+u32 h264bsdNumMbPart(mbType_e mbType);
+u32 h264bsdNumSubMbPart(subMbType_e subMbType);
+
+subMbPartMode_e h264bsdSubMbPartMode(subMbType_e subMbType);
+
+u32 h264bsdDecodeMacroblock(mbStorage_t *pMb, macroblockLayer_t *pMbLayer,
+    image_t *currImage, dpbStorage_t *dpb, i32 *qpY, u32 mbNum,
+    u32 constrainedIntraPredFlag, u8* data);
+
+u32 h264bsdPredModeIntra16x16(mbType_e mbType);
+
+mbPartPredMode_e h264bsdMbPartPredMode(mbType_e mbType);
+#ifdef H264DEC_NEON
+u32 h264bsdClearMbLayer(macroblockLayer_t *pMbLayer, u32 size);
+#endif
+
+#endif /* #ifdef H264SWDEC_MACROBLOCK_LAYER_H */
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_nal_unit.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_nal_unit.c
new file mode 100755
index 0000000..e44c43a
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_nal_unit.c
@@ -0,0 +1,117 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+     1. Include headers
+     2. External compiler flags
+     3. Module defines
+     4. Local function prototypes
+     5. Functions
+          h264bsdDecodeNalUnit
+
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "h264bsd_nal_unit.h"
+#include "h264bsd_util.h"
+
+/*------------------------------------------------------------------------------
+    2. External compiler flags
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+    3. Module defines
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    4. Local function prototypes
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+
+    Function name: h264bsdDecodeNalUnit
+
+        Functional description:
+            Decode NAL unit header information
+
+        Inputs:
+            pStrmData       pointer to stream data structure
+
+        Outputs:
+            pNalUnit        NAL unit header information is stored here
+
+        Returns:
+            HANTRO_OK       success
+            HANTRO_NOK      invalid NAL unit header information
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdDecodeNalUnit(strmData_t *pStrmData, nalUnit_t *pNalUnit)
+{
+
+/* Variables */
+
+    u32 tmp;
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(pNalUnit);
+    ASSERT(pStrmData->bitPosInWord == 0);
+
+    /* forbidden_zero_bit (not checked to be zero, errors ignored) */
+    tmp = h264bsdGetBits(pStrmData, 1);
+    /* Assuming that NAL unit starts from byte boundary ­> don't have to check
+     * following 7 bits for END_OF_STREAM */
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+
+    tmp = h264bsdGetBits(pStrmData, 2);
+    pNalUnit->nalRefIdc = tmp;
+
+    tmp = h264bsdGetBits(pStrmData, 5);
+    pNalUnit->nalUnitType = (nalUnitType_e)tmp;
+
+    /* data partitioning NAL units not supported */
+    if ( (tmp == 2) || (tmp == 3) || (tmp == 4) )
+    {
+        return(HANTRO_NOK);
+    }
+
+    /* nal_ref_idc shall not be zero for these nal_unit_types */
+    if ( ( (tmp == NAL_SEQ_PARAM_SET) || (tmp == NAL_PIC_PARAM_SET) ||
+           (tmp == NAL_CODED_SLICE_IDR) ) && (pNalUnit->nalRefIdc == 0) )
+    {
+        return(HANTRO_NOK);
+    }
+    /* nal_ref_idc shall be zero for these nal_unit_types */
+    else if ( ( (tmp == NAL_SEI) || (tmp == NAL_ACCESS_UNIT_DELIMITER) ||
+                (tmp == NAL_END_OF_SEQUENCE) || (tmp == NAL_END_OF_STREAM) ||
+                (tmp == NAL_FILLER_DATA) ) && (pNalUnit->nalRefIdc != 0) )
+    {
+        return(HANTRO_NOK);
+    }
+
+    return(HANTRO_OK);
+
+}
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_nal_unit.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_nal_unit.h
new file mode 100755
index 0000000..38957bf
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_nal_unit.h
@@ -0,0 +1,76 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+    1. Include headers
+    2. Module defines
+    3. Data types
+    4. Function prototypes
+
+------------------------------------------------------------------------------*/
+
+#ifndef H264SWDEC_NAL_UNIT_H
+#define H264SWDEC_NAL_UNIT_H
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "basetype.h"
+#include "h264bsd_stream.h"
+
+/*------------------------------------------------------------------------------
+    2. Module defines
+------------------------------------------------------------------------------*/
+
+/* macro to determine if NAL unit pointed by pNalUnit contains an IDR slice */
+#define IS_IDR_NAL_UNIT(pNalUnit) \
+    ((pNalUnit)->nalUnitType == NAL_CODED_SLICE_IDR)
+
+/*------------------------------------------------------------------------------
+    3. Data types
+------------------------------------------------------------------------------*/
+
+typedef enum {
+    NAL_CODED_SLICE = 1,
+    NAL_CODED_SLICE_IDR = 5,
+    NAL_SEI = 6,
+    NAL_SEQ_PARAM_SET = 7,
+    NAL_PIC_PARAM_SET = 8,
+    NAL_ACCESS_UNIT_DELIMITER = 9,
+    NAL_END_OF_SEQUENCE = 10,
+    NAL_END_OF_STREAM = 11,
+    NAL_FILLER_DATA = 12,
+    NAL_MAX_TYPE_VALUE = 31
+} nalUnitType_e;
+
+typedef struct
+{
+    nalUnitType_e nalUnitType;
+    u32 nalRefIdc;
+} nalUnit_t;
+
+/*------------------------------------------------------------------------------
+    4. Function prototypes
+------------------------------------------------------------------------------*/
+
+u32 h264bsdDecodeNalUnit(strmData_t *pStrmData, nalUnit_t *pNalUnit);
+
+#endif /* #ifdef H264SWDEC_NAL_UNIT_H */
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_neighbour.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_neighbour.c
new file mode 100755
index 0000000..ce5eeff
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_neighbour.c
@@ -0,0 +1,382 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+     1. Include headers
+     2. External compiler flags
+     3. Module defines
+     4. Local function prototypes
+     5. Functions
+          h264bsdInitMbNeighbours
+          h264bsdGetNeighbourMb
+          h264bsdNeighbour4x4BlockA
+          h264bsdNeighbour4x4BlockB
+          h264bsdNeighbour4x4BlockC
+          h264bsdNeighbour4x4BlockD
+
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "h264bsd_neighbour.h"
+#include "h264bsd_util.h"
+
+/*------------------------------------------------------------------------------
+    2. External compiler flags
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+    3. Module defines
+------------------------------------------------------------------------------*/
+
+/* Following four tables indicate neighbours of each block of a macroblock.
+ * First 16 values are for luma blocks, next 4 values for Cb and last 4
+ * values for Cr. Elements of the table indicate to which macroblock the
+ * neighbour block belongs and the index of the neighbour block in question.
+ * Indexing of the blocks goes as follows
+ *
+ *          Y             Cb       Cr
+ *      0  1  4  5      16 17    20 21
+ *      2  3  6  7      18 19    22 23
+ *      8  9 12 13
+ *     10 11 14 15
+ */
+
+/* left neighbour for each block */
+static const neighbour_t N_A_4x4B[24] = {
+    {MB_A,5},    {MB_CURR,0}, {MB_A,7},    {MB_CURR,2},
+    {MB_CURR,1}, {MB_CURR,4}, {MB_CURR,3}, {MB_CURR,6},
+    {MB_A,13},   {MB_CURR,8}, {MB_A,15},   {MB_CURR,10},
+    {MB_CURR,9}, {MB_CURR,12},{MB_CURR,11},{MB_CURR,14},
+    {MB_A,17},   {MB_CURR,16},{MB_A,19},   {MB_CURR,18},
+    {MB_A,21},   {MB_CURR,20},{MB_A,23},   {MB_CURR,22} };
+
+/* above neighbour for each block */
+static const neighbour_t N_B_4x4B[24] = {
+    {MB_B,10},   {MB_B,11},   {MB_CURR,0}, {MB_CURR,1},
+    {MB_B,14},   {MB_B,15},   {MB_CURR,4}, {MB_CURR,5},
+    {MB_CURR,2}, {MB_CURR,3}, {MB_CURR,8}, {MB_CURR,9},
+    {MB_CURR,6}, {MB_CURR,7}, {MB_CURR,12},{MB_CURR,13},
+    {MB_B,18},   {MB_B,19},   {MB_CURR,16},{MB_CURR,17},
+    {MB_B,22},   {MB_B,23},   {MB_CURR,20},{MB_CURR,21} };
+
+/* above-right neighbour for each block */
+static const neighbour_t N_C_4x4B[24] = {
+    {MB_B,11},   {MB_B,14},   {MB_CURR,1}, {MB_NA,4},
+    {MB_B,15},   {MB_C,10},   {MB_CURR,5}, {MB_NA,0},
+    {MB_CURR,3}, {MB_CURR,6}, {MB_CURR,9}, {MB_NA,12},
+    {MB_CURR,7}, {MB_NA,2},   {MB_CURR,13},{MB_NA,8},
+    {MB_B,19},   {MB_C,18},   {MB_CURR,17},{MB_NA,16},
+    {MB_B,23},   {MB_C,22},   {MB_CURR,21},{MB_NA,20} };
+
+/* above-left neighbour for each block */
+static const neighbour_t N_D_4x4B[24] = {
+    {MB_D,15},   {MB_B,10},   {MB_A,5},    {MB_CURR,0},
+    {MB_B,11},   {MB_B,14},   {MB_CURR,1}, {MB_CURR,4},
+    {MB_A,7},    {MB_CURR,2}, {MB_A,13},   {MB_CURR,8},
+    {MB_CURR,3}, {MB_CURR,6}, {MB_CURR,9}, {MB_CURR,12},
+    {MB_D,19},   {MB_B,18},   {MB_A,17},   {MB_CURR,16},
+    {MB_D,23},   {MB_B,22},   {MB_A,21},   {MB_CURR,20} };
+
+/*------------------------------------------------------------------------------
+    4. Local function prototypes
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdInitMbNeighbours
+
+        Functional description:
+            Initialize macroblock neighbours. Function sets neighbour
+            macroblock pointers in macroblock structures to point to
+            macroblocks on the left, above, above-right and above-left.
+            Pointers are set NULL if the neighbour does not fit into the
+            picture.
+
+        Inputs:
+            picWidth        width of the picture in macroblocks
+            picSizeInMbs    no need to clarify
+
+        Outputs:
+            pMbStorage      neighbour pointers of each mbStorage structure
+                            stored here
+
+        Returns:
+            none
+
+------------------------------------------------------------------------------*/
+
+void h264bsdInitMbNeighbours(mbStorage_t *pMbStorage, u32 picWidth,
+    u32 picSizeInMbs)
+{
+
+/* Variables */
+
+    u32 i, row, col;
+
+/* Code */
+
+    ASSERT(pMbStorage);
+    ASSERT(picWidth);
+    ASSERT(picWidth <= picSizeInMbs);
+    ASSERT(((picSizeInMbs / picWidth) * picWidth) == picSizeInMbs);
+
+    row = col = 0;
+
+    for (i = 0; i < picSizeInMbs; i++)
+    {
+
+        if (col)
+            pMbStorage[i].mbA = pMbStorage + i - 1;
+        else
+            pMbStorage[i].mbA = NULL;
+
+        if (row)
+            pMbStorage[i].mbB = pMbStorage + i - picWidth;
+        else
+            pMbStorage[i].mbB = NULL;
+
+        if (row && (col < picWidth - 1))
+            pMbStorage[i].mbC = pMbStorage + i - (picWidth - 1);
+        else
+            pMbStorage[i].mbC = NULL;
+
+        if (row && col)
+            pMbStorage[i].mbD = pMbStorage + i - (picWidth + 1);
+        else
+            pMbStorage[i].mbD = NULL;
+
+        col++;
+        if (col == picWidth)
+        {
+            col = 0;
+            row++;
+        }
+    }
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdGetNeighbourMb
+
+        Functional description:
+            Get pointer to neighbour macroblock.
+
+        Inputs:
+            pMb         pointer to macroblock structure of the macroblock
+                        whose neighbour is wanted
+            neighbour   indicates which neighbour is wanted
+
+        Outputs:
+            none
+
+        Returns:
+            pointer to neighbour macroblock
+            NULL if not available
+
+------------------------------------------------------------------------------*/
+
+mbStorage_t* h264bsdGetNeighbourMb(mbStorage_t *pMb, neighbourMb_e neighbour)
+{
+
+/* Variables */
+
+
+/* Code */
+
+    ASSERT((neighbour <= MB_CURR) || (neighbour == MB_NA));
+
+    if (neighbour == MB_A)
+        return(pMb->mbA);
+    else if (neighbour == MB_B)
+        return(pMb->mbB);
+    else if (neighbour == MB_C)
+        return(pMb->mbC);
+    else if (neighbour == MB_D)
+        return(pMb->mbD);
+    else if (neighbour == MB_CURR)
+        return(pMb);
+    else
+        return(NULL);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdNeighbour4x4BlockA
+
+        Functional description:
+            Get left neighbour of the block. Function returns pointer to
+            the table defined in the beginning of the file.
+
+        Inputs:
+            blockIndex  indicates the block whose neighbours are wanted
+
+        Outputs:
+
+        Returns:
+            pointer to neighbour structure
+
+------------------------------------------------------------------------------*/
+
+const neighbour_t* h264bsdNeighbour4x4BlockA(u32 blockIndex)
+{
+
+/* Variables */
+
+/* Code */
+
+    ASSERT(blockIndex < 24);
+
+    return(N_A_4x4B+blockIndex);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdNeighbour4x4BlockB
+
+        Functional description:
+            Get above neighbour of the block. Function returns pointer to
+            the table defined in the beginning of the file.
+
+        Inputs:
+            blockIndex  indicates the block whose neighbours are wanted
+
+        Outputs:
+
+        Returns:
+            pointer to neighbour structure
+
+------------------------------------------------------------------------------*/
+
+const neighbour_t* h264bsdNeighbour4x4BlockB(u32 blockIndex)
+{
+
+/* Variables */
+
+/* Code */
+
+    ASSERT(blockIndex < 24);
+
+    return(N_B_4x4B+blockIndex);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdNeighbour4x4BlockC
+
+        Functional description:
+            Get above-right  neighbour of the block. Function returns pointer
+            to the table defined in the beginning of the file.
+
+        Inputs:
+            blockIndex  indicates the block whose neighbours are wanted
+
+        Outputs:
+
+        Returns:
+            pointer to neighbour structure
+
+------------------------------------------------------------------------------*/
+
+const neighbour_t* h264bsdNeighbour4x4BlockC(u32 blockIndex)
+{
+
+/* Variables */
+
+/* Code */
+
+    ASSERT(blockIndex < 24);
+
+    return(N_C_4x4B+blockIndex);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdNeighbour4x4BlockD
+
+        Functional description:
+            Get above-left neighbour of the block. Function returns pointer to
+            the table defined in the beginning of the file.
+
+        Inputs:
+            blockIndex  indicates the block whose neighbours are wanted
+
+        Outputs:
+
+        Returns:
+            pointer to neighbour structure
+
+------------------------------------------------------------------------------*/
+
+const neighbour_t* h264bsdNeighbour4x4BlockD(u32 blockIndex)
+{
+
+/* Variables */
+
+/* Code */
+
+    ASSERT(blockIndex < 24);
+
+    return(N_D_4x4B+blockIndex);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdIsNeighbourAvailable
+
+        Functional description:
+            Check if neighbour macroblock is available. Neighbour macroblock
+            is considered available if it is within the picture and belongs
+            to the same slice as the current macroblock.
+
+        Inputs:
+            pMb         pointer to the current macroblock
+            pNeighbour  pointer to the neighbour macroblock
+
+        Outputs:
+            none
+
+        Returns:
+            TRUE    neighbour is available
+            FALSE   neighbour is not available
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdIsNeighbourAvailable(mbStorage_t *pMb, mbStorage_t *pNeighbour)
+{
+
+/* Variables */
+
+/* Code */
+
+    if ( (pNeighbour == NULL) || (pMb->sliceId != pNeighbour->sliceId) )
+        return(HANTRO_FALSE);
+    else
+        return(HANTRO_TRUE);
+
+}
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_neighbour.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_neighbour.h
new file mode 100755
index 0000000..fce0ad1
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_neighbour.h
@@ -0,0 +1,78 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+    1. Include headers
+    2. Module defines
+    3. Data types
+    4. Function prototypes
+
+------------------------------------------------------------------------------*/
+
+#ifndef H264SWDEC_NEIGHBOUR_H
+#define H264SWDEC_NEIGHBOUR_H
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "basetype.h"
+#include "h264bsd_macroblock_layer.h"
+
+/*------------------------------------------------------------------------------
+    2. Module defines
+------------------------------------------------------------------------------*/
+
+typedef enum {
+    MB_A = 0,
+    MB_B,
+    MB_C,
+    MB_D,
+    MB_CURR,
+    MB_NA = 0xFF
+} neighbourMb_e;
+
+/*------------------------------------------------------------------------------
+    3. Data types
+------------------------------------------------------------------------------*/
+
+typedef struct
+{
+    neighbourMb_e   mb;
+    u8             index;
+} neighbour_t;
+
+/*------------------------------------------------------------------------------
+    4. Function prototypes
+------------------------------------------------------------------------------*/
+
+void h264bsdInitMbNeighbours(mbStorage_t *pMbStorage, u32 picWidth,
+    u32 picSizeInMbs);
+
+mbStorage_t* h264bsdGetNeighbourMb(mbStorage_t *pMb, neighbourMb_e neighbour);
+
+u32 h264bsdIsNeighbourAvailable(mbStorage_t *pMb, mbStorage_t *pNeighbour);
+
+const neighbour_t* h264bsdNeighbour4x4BlockA(u32 blockIndex);
+const neighbour_t* h264bsdNeighbour4x4BlockB(u32 blockIndex);
+const neighbour_t* h264bsdNeighbour4x4BlockC(u32 blockIndex);
+const neighbour_t* h264bsdNeighbour4x4BlockD(u32 blockIndex);
+
+#endif /* #ifdef H264SWDEC_NEIGHBOUR_H */
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_pic_order_cnt.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_pic_order_cnt.c
new file mode 100755
index 0000000..fb23352
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_pic_order_cnt.c
@@ -0,0 +1,347 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+     1. Include headers
+     2. External compiler flags
+     3. Module defines
+     4. Local function prototypes
+     5. Functions
+          h264bsdDecodePicOrderCnt
+
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "h264bsd_util.h"
+#include "h264bsd_pic_order_cnt.h"
+
+/*------------------------------------------------------------------------------
+    2. External compiler flags
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+    3. Module defines
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    4. Local function prototypes
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdDecodePicOrderCnt
+
+        Functional description:
+            Compute picture order count for a picture. Function implements
+            computation of all POC types (0, 1 and 2), type is obtained from
+            sps. See standard for description of the POC types and how POC is
+            computed for each type.
+
+            Function returns the minimum of top field and bottom field pic
+            order counts.
+
+        Inputs:
+            poc         pointer to previous results
+            sps         pointer to sequence parameter set
+            slicHeader  pointer to current slice header, frame number and
+                        other params needed for POC computation
+            pNalUnit    pointer to current NAL unit structrue, function needs
+                        to know if this is an IDR picture and also if this is
+                        a reference picture
+
+        Outputs:
+            poc         results stored here for computation of next POC
+
+        Returns:
+            picture order count
+
+------------------------------------------------------------------------------*/
+
+i32 h264bsdDecodePicOrderCnt(pocStorage_t *poc, seqParamSet_t *sps,
+    sliceHeader_t *pSliceHeader, nalUnit_t *pNalUnit)
+{
+
+/* Variables */
+
+    u32 i;
+    i32 picOrderCnt;
+    u32 frameNumOffset, absFrameNum, picOrderCntCycleCnt;
+    u32 frameNumInPicOrderCntCycle;
+    i32 expectedDeltaPicOrderCntCycle;
+    u32 containsMmco5;
+
+/* Code */
+
+    ASSERT(poc);
+    ASSERT(sps);
+    ASSERT(pSliceHeader);
+    ASSERT(pNalUnit);
+    ASSERT(sps->picOrderCntType <= 2);
+
+#if 0
+    /* JanSa: I don't think this is necessary, don't see any reason to
+     * increment prevFrameNum one by one instead of one big increment.
+     * However, standard specifies that this should be done -> if someone
+     * figures out any case when the outcome would be different for step by
+     * step increment, this part of the code should be enabled */
+
+    /* if there was a gap in frame numbering and picOrderCntType is 1 or 2 ->
+     * "compute" pic order counts for non-existing frames. These are not
+     * actually computed, but process needs to be done to update the
+     * prevFrameNum and prevFrameNumOffset */
+    if ( sps->picOrderCntType > 0 &&
+         pSliceHeader->frameNum != poc->prevFrameNum &&
+         pSliceHeader->frameNum != ((poc->prevFrameNum + 1) % sps->maxFrameNum))
+    {
+
+        /* use variable i for unUsedShortTermFrameNum */
+        i = (poc->prevFrameNum + 1) % sps->maxFrameNum;
+
+        do
+        {
+            if (poc->prevFrameNum > i)
+                frameNumOffset = poc->prevFrameNumOffset + sps->maxFrameNum;
+            else
+                frameNumOffset = poc->prevFrameNumOffset;
+
+            poc->prevFrameNumOffset = frameNumOffset;
+            poc->prevFrameNum = i;
+
+            i = (i + 1) % sps->maxFrameNum;
+
+        } while (i != pSliceHeader->frameNum);
+    }
+#endif
+
+    /* check if current slice includes mmco equal to 5 */
+    containsMmco5 = HANTRO_FALSE;
+    if (pSliceHeader->decRefPicMarking.adaptiveRefPicMarkingModeFlag)
+    {
+        i = 0;
+        while (pSliceHeader->decRefPicMarking.operation[i].
+            memoryManagementControlOperation)
+        {
+            if (pSliceHeader->decRefPicMarking.operation[i].
+                memoryManagementControlOperation == 5)
+            {
+                containsMmco5 = HANTRO_TRUE;
+                break;
+            }
+            i++;
+        }
+    }
+    switch (sps->picOrderCntType)
+    {
+
+        case 0:
+            /* set prevPicOrderCnt values for IDR frame */
+            if (IS_IDR_NAL_UNIT(pNalUnit))
+            {
+                poc->prevPicOrderCntMsb = 0;
+                poc->prevPicOrderCntLsb = 0;
+            }
+
+            /* compute picOrderCntMsb (stored in picOrderCnt variable) */
+            if ( (pSliceHeader->picOrderCntLsb < poc->prevPicOrderCntLsb) &&
+                ((poc->prevPicOrderCntLsb - pSliceHeader->picOrderCntLsb) >=
+                 sps->maxPicOrderCntLsb/2) )
+            {
+                picOrderCnt = poc->prevPicOrderCntMsb +
+                    (i32)sps->maxPicOrderCntLsb;
+            }
+            else if ((pSliceHeader->picOrderCntLsb > poc->prevPicOrderCntLsb) &&
+                ((pSliceHeader->picOrderCntLsb - poc->prevPicOrderCntLsb) >
+                 sps->maxPicOrderCntLsb/2) )
+            {
+                picOrderCnt = poc->prevPicOrderCntMsb -
+                    (i32)sps->maxPicOrderCntLsb;
+            }
+            else
+                picOrderCnt = poc->prevPicOrderCntMsb;
+
+            /* standard specifies that prevPicOrderCntMsb is from previous
+             * rererence frame -> replace old value only if current frame is
+             * rererence frame */
+            if (pNalUnit->nalRefIdc)
+                poc->prevPicOrderCntMsb = picOrderCnt;
+
+            /* compute top field order cnt (stored in picOrderCnt) */
+            picOrderCnt += (i32)pSliceHeader->picOrderCntLsb;
+
+            /* if delta for bottom field is negative -> bottom will be the
+             * minimum pic order count */
+            if (pSliceHeader->deltaPicOrderCntBottom < 0)
+                picOrderCnt += pSliceHeader->deltaPicOrderCntBottom;
+
+            /* standard specifies that prevPicOrderCntLsb is from previous
+             * rererence frame -> replace old value only if current frame is
+             * rererence frame */
+            if (pNalUnit->nalRefIdc)
+            {
+                /* if current frame contains mmco5 -> modify values to be
+                 * stored */
+                if (containsMmco5)
+                {
+                    poc->prevPicOrderCntMsb = 0;
+                    /* prevPicOrderCntLsb should be the top field picOrderCnt
+                     * if previous frame included mmco5. Top field picOrderCnt
+                     * for frames containing mmco5 is obtained by subtracting
+                     * the picOrderCnt from original top field order count ->
+                     * value is zero if top field was the minimum, i.e. delta
+                     * for bottom was positive, otherwise value is
+                     * -deltaPicOrderCntBottom */
+                    if (pSliceHeader->deltaPicOrderCntBottom < 0)
+                        poc->prevPicOrderCntLsb =
+                            (u32)(-pSliceHeader->deltaPicOrderCntBottom);
+                    else
+                        poc->prevPicOrderCntLsb = 0;
+                    picOrderCnt = 0;
+                }
+                else
+                {
+                    poc->prevPicOrderCntLsb = pSliceHeader->picOrderCntLsb;
+                }
+            }
+
+            break;
+
+        case 1:
+
+            /* step 1 (in the description in the standard) */
+            if (IS_IDR_NAL_UNIT(pNalUnit))
+                frameNumOffset = 0;
+            else if (poc->prevFrameNum > pSliceHeader->frameNum)
+                frameNumOffset = poc->prevFrameNumOffset + sps->maxFrameNum;
+            else
+                frameNumOffset = poc->prevFrameNumOffset;
+
+            /* step 2 */
+            if (sps->numRefFramesInPicOrderCntCycle)
+                absFrameNum = frameNumOffset + pSliceHeader->frameNum;
+            else
+                absFrameNum = 0;
+
+            if (pNalUnit->nalRefIdc == 0 && absFrameNum > 0)
+                absFrameNum -= 1;
+
+            /* step 3 */
+            if (absFrameNum > 0)
+            {
+                picOrderCntCycleCnt =
+                    (absFrameNum - 1)/sps->numRefFramesInPicOrderCntCycle;
+                frameNumInPicOrderCntCycle =
+                    (absFrameNum - 1)%sps->numRefFramesInPicOrderCntCycle;
+            }
+
+            /* step 4 */
+            expectedDeltaPicOrderCntCycle = 0;
+            for (i = 0; i < sps->numRefFramesInPicOrderCntCycle; i++)
+                expectedDeltaPicOrderCntCycle += sps->offsetForRefFrame[i];
+
+            /* step 5 (picOrderCnt used to store expectedPicOrderCnt) */
+            /*lint -esym(644,picOrderCntCycleCnt) always initialized */
+            /*lint -esym(644,frameNumInPicOrderCntCycle) always initialized */
+            if (absFrameNum > 0)
+            {
+                picOrderCnt =
+                    (i32)picOrderCntCycleCnt * expectedDeltaPicOrderCntCycle;
+                for (i = 0; i <= frameNumInPicOrderCntCycle; i++)
+                    picOrderCnt += sps->offsetForRefFrame[i];
+            }
+            else
+                picOrderCnt = 0;
+
+            if (pNalUnit->nalRefIdc == 0)
+                picOrderCnt += sps->offsetForNonRefPic;
+
+            /* step 6 (picOrderCnt is top field order cnt if delta for bottom
+             * is positive, otherwise it is bottom field order cnt) */
+            picOrderCnt += pSliceHeader->deltaPicOrderCnt[0];
+
+            if ( (sps->offsetForTopToBottomField +
+                    pSliceHeader->deltaPicOrderCnt[1]) < 0 )
+            {
+                picOrderCnt += sps->offsetForTopToBottomField +
+                    pSliceHeader->deltaPicOrderCnt[1];
+            }
+
+            /* if current picture contains mmco5 -> set prevFrameNumOffset and
+             * prevFrameNum to 0 for computation of picOrderCnt of next
+             * frame, otherwise store frameNum and frameNumOffset to poc
+             * structure */
+            if (!containsMmco5)
+            {
+                poc->prevFrameNumOffset = frameNumOffset;
+                poc->prevFrameNum = pSliceHeader->frameNum;
+            }
+            else
+            {
+                poc->prevFrameNumOffset = 0;
+                poc->prevFrameNum = 0;
+                picOrderCnt = 0;
+            }
+            break;
+
+        default: /* case 2 */
+            /* derive frameNumOffset */
+            if (IS_IDR_NAL_UNIT(pNalUnit))
+                frameNumOffset = 0;
+            else if (poc->prevFrameNum > pSliceHeader->frameNum)
+                frameNumOffset = poc->prevFrameNumOffset + sps->maxFrameNum;
+            else
+                frameNumOffset = poc->prevFrameNumOffset;
+
+            /* derive picOrderCnt (type 2 has same value for top and bottom
+             * field order cnts) */
+            if (IS_IDR_NAL_UNIT(pNalUnit))
+                picOrderCnt = 0;
+            else if (pNalUnit->nalRefIdc == 0)
+                picOrderCnt =
+                    2 * (i32)(frameNumOffset + pSliceHeader->frameNum) - 1;
+            else
+                picOrderCnt =
+                    2 * (i32)(frameNumOffset + pSliceHeader->frameNum);
+
+            /* if current picture contains mmco5 -> set prevFrameNumOffset and
+             * prevFrameNum to 0 for computation of picOrderCnt of next
+             * frame, otherwise store frameNum and frameNumOffset to poc
+             * structure */
+            if (!containsMmco5)
+            {
+                poc->prevFrameNumOffset = frameNumOffset;
+                poc->prevFrameNum = pSliceHeader->frameNum;
+            }
+            else
+            {
+                poc->prevFrameNumOffset = 0;
+                poc->prevFrameNum = 0;
+                picOrderCnt = 0;
+            }
+            break;
+
+    }
+
+    /*lint -esym(644,picOrderCnt) always initialized */
+    return(picOrderCnt);
+
+}
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_pic_order_cnt.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_pic_order_cnt.h
new file mode 100755
index 0000000..19741eb
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_pic_order_cnt.h
@@ -0,0 +1,68 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+    1. Include headers
+    2. Module defines
+    3. Data types
+    4. Function prototypes
+
+------------------------------------------------------------------------------*/
+
+#ifndef H264SWDEC_PIC_ORDER_CNT_H
+#define H264SWDEC_PIC_ORDER_CNT_H
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "basetype.h"
+#include "h264bsd_seq_param_set.h"
+#include "h264bsd_slice_header.h"
+#include "h264bsd_nal_unit.h"
+
+/*------------------------------------------------------------------------------
+    2. Module defines
+------------------------------------------------------------------------------*/
+
+
+/*------------------------------------------------------------------------------
+    3. Data types
+------------------------------------------------------------------------------*/
+
+/* structure to store information computed for previous picture, needed for
+ * POC computation of a picture. Two first fields for POC type 0, last two
+ * for types 1 and 2 */
+typedef struct
+{
+    u32 prevPicOrderCntLsb;
+    i32 prevPicOrderCntMsb;
+    u32 prevFrameNum;
+    u32 prevFrameNumOffset;
+} pocStorage_t;
+
+/*------------------------------------------------------------------------------
+    4. Function prototypes
+------------------------------------------------------------------------------*/
+
+i32 h264bsdDecodePicOrderCnt(pocStorage_t *poc, seqParamSet_t *sps,
+    sliceHeader_t *sliceHeader, nalUnit_t *pNalUnit);
+
+#endif /* #ifdef H264SWDEC_PIC_ORDER_CNT_H */
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_pic_param_set.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_pic_param_set.c
new file mode 100755
index 0000000..e04dea4b
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_pic_param_set.c
@@ -0,0 +1,335 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+     1. Include headers
+     2. External compiler flags
+     3. Module defines
+     4. Local function prototypes
+     5. Functions
+          h264bsdDecodePicParamSet
+
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "h264bsd_pic_param_set.h"
+#include "h264bsd_util.h"
+#include "h264bsd_vlc.h"
+#include "h264bsd_cfg.h"
+
+/*------------------------------------------------------------------------------
+    2. External compiler flags
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+    3. Module defines
+------------------------------------------------------------------------------*/
+
+/* lookup table for ceil(log2(numSliceGroups)), i.e. number of bits needed to
+ * represent range [0, numSliceGroups)
+ *
+ * NOTE: if MAX_NUM_SLICE_GROUPS is higher than 8 this table has to be resized
+ * accordingly */
+static const u32 CeilLog2NumSliceGroups[8] = {1, 1, 2, 2, 3, 3, 3, 3};
+
+/*------------------------------------------------------------------------------
+    4. Local function prototypes
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+
+    Function name: h264bsdDecodePicParamSet
+
+        Functional description:
+            Decode picture parameter set information from the stream.
+
+            Function allocates memory for
+                - run lengths if slice group map type is 0
+                - top-left and bottom-right arrays if map type is 2
+                - for slice group ids if map type is 6
+
+            Validity of some of the slice group mapping information depends
+            on the image dimensions which are not known here. Therefore the
+            validity has to be checked afterwards, currently in the parameter
+            set activation phase.
+
+        Inputs:
+            pStrmData       pointer to stream data structure
+
+        Outputs:
+            pPicParamSet    decoded information is stored here
+
+        Returns:
+            HANTRO_OK       success
+            HANTRO_NOK      failure, invalid information or end of stream
+            MEMORY_ALLOCATION_ERROR for memory allocation failure
+
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdDecodePicParamSet(strmData_t *pStrmData, picParamSet_t *pPicParamSet)
+{
+
+/* Variables */
+
+    u32 tmp, i, value;
+    i32 itmp;
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(pPicParamSet);
+
+
+    H264SwDecMemset(pPicParamSet, 0, sizeof(picParamSet_t));
+
+    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+        &pPicParamSet->picParameterSetId);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+    if (pPicParamSet->picParameterSetId >= MAX_NUM_PIC_PARAM_SETS)
+    {
+        EPRINT("pic_parameter_set_id");
+        return(HANTRO_NOK);
+    }
+
+    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+        &pPicParamSet->seqParameterSetId);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+    if (pPicParamSet->seqParameterSetId >= MAX_NUM_SEQ_PARAM_SETS)
+    {
+        EPRINT("seq_param_set_id");
+        return(HANTRO_NOK);
+    }
+
+    /* entropy_coding_mode_flag, shall be 0 for baseline profile */
+    tmp = h264bsdGetBits(pStrmData, 1);
+    if (tmp)
+    {
+        EPRINT("entropy_coding_mode_flag");
+        return(HANTRO_NOK);
+    }
+
+    tmp = h264bsdGetBits(pStrmData, 1);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    pPicParamSet->picOrderPresentFlag = (tmp == 1) ? HANTRO_TRUE : HANTRO_FALSE;
+
+    /* num_slice_groups_minus1 */
+    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+    pPicParamSet->numSliceGroups = value + 1;
+    if (pPicParamSet->numSliceGroups > MAX_NUM_SLICE_GROUPS)
+    {
+        EPRINT("num_slice_groups_minus1");
+        return(HANTRO_NOK);
+    }
+
+    /* decode slice group mapping information if more than one slice groups */
+    if (pPicParamSet->numSliceGroups > 1)
+    {
+        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+            &pPicParamSet->sliceGroupMapType);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+        if (pPicParamSet->sliceGroupMapType > 6)
+        {
+            EPRINT("slice_group_map_type");
+            return(HANTRO_NOK);
+        }
+
+        if (pPicParamSet->sliceGroupMapType == 0)
+        {
+            ALLOCATE(pPicParamSet->runLength,
+                pPicParamSet->numSliceGroups, u32);
+            if (pPicParamSet->runLength == NULL)
+                return(MEMORY_ALLOCATION_ERROR);
+            for (i = 0; i < pPicParamSet->numSliceGroups; i++)
+            {
+                tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);
+                if (tmp != HANTRO_OK)
+                    return(tmp);
+                pPicParamSet->runLength[i] = value+1;
+                /* param values checked in CheckPps() */
+            }
+        }
+        else if (pPicParamSet->sliceGroupMapType == 2)
+        {
+            ALLOCATE(pPicParamSet->topLeft,
+                pPicParamSet->numSliceGroups - 1, u32);
+            ALLOCATE(pPicParamSet->bottomRight,
+                pPicParamSet->numSliceGroups - 1, u32);
+            if (pPicParamSet->topLeft == NULL ||
+                pPicParamSet->bottomRight == NULL)
+                return(MEMORY_ALLOCATION_ERROR);
+            for (i = 0; i < pPicParamSet->numSliceGroups - 1; i++)
+            {
+                tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);
+                if (tmp != HANTRO_OK)
+                    return(tmp);
+                pPicParamSet->topLeft[i] = value;
+                tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);
+                if (tmp != HANTRO_OK)
+                    return(tmp);
+                pPicParamSet->bottomRight[i] = value;
+                /* param values checked in CheckPps() */
+            }
+        }
+        else if ( (pPicParamSet->sliceGroupMapType == 3) ||
+                  (pPicParamSet->sliceGroupMapType == 4) ||
+                  (pPicParamSet->sliceGroupMapType == 5) )
+        {
+            tmp = h264bsdGetBits(pStrmData, 1);
+            if (tmp == END_OF_STREAM)
+                return(HANTRO_NOK);
+            pPicParamSet->sliceGroupChangeDirectionFlag =
+                (tmp == 1) ? HANTRO_TRUE : HANTRO_FALSE;
+            tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);
+            if (tmp != HANTRO_OK)
+                return(tmp);
+            pPicParamSet->sliceGroupChangeRate = value + 1;
+            /* param value checked in CheckPps() */
+        }
+        else if (pPicParamSet->sliceGroupMapType == 6)
+        {
+            tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);
+            if (tmp != HANTRO_OK)
+                return(tmp);
+            pPicParamSet->picSizeInMapUnits = value + 1;
+
+            ALLOCATE(pPicParamSet->sliceGroupId,
+                pPicParamSet->picSizeInMapUnits, u32);
+            if (pPicParamSet->sliceGroupId == NULL)
+                return(MEMORY_ALLOCATION_ERROR);
+
+            /* determine number of bits needed to represent range
+             * [0, numSliceGroups) */
+            tmp = CeilLog2NumSliceGroups[pPicParamSet->numSliceGroups-1];
+
+            for (i = 0; i < pPicParamSet->picSizeInMapUnits; i++)
+            {
+                pPicParamSet->sliceGroupId[i] = h264bsdGetBits(pStrmData, tmp);
+                if ( pPicParamSet->sliceGroupId[i] >=
+                     pPicParamSet->numSliceGroups )
+                {
+                    EPRINT("slice_group_id");
+                    return(HANTRO_NOK);
+                }
+            }
+        }
+    }
+
+    /* num_ref_idx_l0_active_minus1 */
+    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+    if (value > 31)
+    {
+        EPRINT("num_ref_idx_l0_active_minus1");
+        return(HANTRO_NOK);
+    }
+    pPicParamSet->numRefIdxL0Active = value + 1;
+
+    /* num_ref_idx_l1_active_minus1 */
+    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+    if (value > 31)
+    {
+        EPRINT("num_ref_idx_l1_active_minus1");
+        return(HANTRO_NOK);
+    }
+
+    /* weighted_pred_flag, this shall be 0 for baseline profile */
+    tmp = h264bsdGetBits(pStrmData, 1);
+    if (tmp)
+    {
+        EPRINT("weighted_pred_flag");
+        return(HANTRO_NOK);
+    }
+
+    /* weighted_bipred_idc */
+    tmp = h264bsdGetBits(pStrmData, 2);
+    if (tmp > 2)
+    {
+        EPRINT("weighted_bipred_idc");
+        return(HANTRO_NOK);
+    }
+
+    /* pic_init_qp_minus26 */
+    tmp = h264bsdDecodeExpGolombSigned(pStrmData, &itmp);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+    if ((itmp < -26) || (itmp > 25))
+    {
+        EPRINT("pic_init_qp_minus26");
+        return(HANTRO_NOK);
+    }
+    pPicParamSet->picInitQp = (u32)(itmp + 26);
+
+    /* pic_init_qs_minus26 */
+    tmp = h264bsdDecodeExpGolombSigned(pStrmData, &itmp);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+    if ((itmp < -26) || (itmp > 25))
+    {
+        EPRINT("pic_init_qs_minus26");
+        return(HANTRO_NOK);
+    }
+
+    tmp = h264bsdDecodeExpGolombSigned(pStrmData, &itmp);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+    if ((itmp < -12) || (itmp > 12))
+    {
+        EPRINT("chroma_qp_index_offset");
+        return(HANTRO_NOK);
+    }
+    pPicParamSet->chromaQpIndexOffset = itmp;
+
+    tmp = h264bsdGetBits(pStrmData, 1);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    pPicParamSet->deblockingFilterControlPresentFlag =
+        (tmp == 1) ? HANTRO_TRUE : HANTRO_FALSE;
+
+    tmp = h264bsdGetBits(pStrmData, 1);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    pPicParamSet->constrainedIntraPredFlag = (tmp == 1) ?
+                                    HANTRO_TRUE : HANTRO_FALSE;
+
+    tmp = h264bsdGetBits(pStrmData, 1);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    pPicParamSet->redundantPicCntPresentFlag = (tmp == 1) ?
+                                    HANTRO_TRUE : HANTRO_FALSE;
+
+    tmp = h264bsdRbspTrailingBits(pStrmData);
+
+    /* ignore possible errors in trailing bits of parameters sets */
+    return(HANTRO_OK);
+
+}
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_pic_param_set.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_pic_param_set.h
new file mode 100755
index 0000000..6328638
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_pic_param_set.h
@@ -0,0 +1,77 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+    1. Include headers
+    2. Module defines
+    3. Data types
+    4. Function prototypes
+
+------------------------------------------------------------------------------*/
+
+#ifndef H264SWDEC_PIC_PARAM_SET_H
+#define H264SWDEC_PIC_PARAM_SET_H
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "basetype.h"
+#include "h264bsd_stream.h"
+
+/*------------------------------------------------------------------------------
+    2. Module defines
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    3. Data types
+------------------------------------------------------------------------------*/
+
+/* data structure to store PPS information decoded from the stream */
+typedef struct
+{
+    u32 picParameterSetId;
+    u32 seqParameterSetId;
+    u32 picOrderPresentFlag;
+    u32 numSliceGroups;
+    u32 sliceGroupMapType;
+    u32 *runLength;
+    u32 *topLeft;
+    u32 *bottomRight;
+    u32 sliceGroupChangeDirectionFlag;
+    u32 sliceGroupChangeRate;
+    u32 picSizeInMapUnits;
+    u32 *sliceGroupId;
+    u32 numRefIdxL0Active;
+    u32 picInitQp;
+    i32 chromaQpIndexOffset;
+    u32 deblockingFilterControlPresentFlag;
+    u32 constrainedIntraPredFlag;
+    u32 redundantPicCntPresentFlag;
+} picParamSet_t;
+
+/*------------------------------------------------------------------------------
+    4. Function prototypes
+------------------------------------------------------------------------------*/
+
+u32 h264bsdDecodePicParamSet(strmData_t *pStrmData,
+    picParamSet_t *pPicParamSet);
+
+#endif /* #ifdef H264SWDEC_PIC_PARAM_SET_H */
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_reconstruct.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_reconstruct.c
new file mode 100755
index 0000000..c948776
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_reconstruct.c
@@ -0,0 +1,2315 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+     1. Include headers
+     2. External compiler flags
+     3. Module defines
+     4. Local function prototypes
+     5. Functions
+
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "basetype.h"
+#include "h264bsd_reconstruct.h"
+#include "h264bsd_macroblock_layer.h"
+#include "h264bsd_image.h"
+#include "h264bsd_util.h"
+
+#ifdef H264DEC_OMXDL
+#include "omxtypes.h"
+#include "omxVC.h"
+#include "armVC.h"
+#endif /* H264DEC_OMXDL */
+
+/*------------------------------------------------------------------------------
+    2. External compiler flags
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+    3. Module defines
+------------------------------------------------------------------------------*/
+
+/* Switch off the following Lint messages for this file:
+ * Info 701: Shift left of signed quantity (int)
+ * Info 702: Shift right of signed quantity (int)
+ */
+/*lint -e701 -e702 */
+
+/* Luma fractional-sample positions
+ *
+ *  G a b c H
+ *  d e f g
+ *  h i j k m
+ *  n p q r
+ *  M   s   N
+ *
+ *  G, H, M and N are integer sample positions
+ *  a-s are fractional samples that need to be interpolated.
+ */
+#ifndef H264DEC_OMXDL
+static const u32 lumaFracPos[4][4] = {
+  /* G  d  h  n    a  e  i  p    b  f  j   q     c   g   k   r */
+    {0, 1, 2, 3}, {4, 5, 6, 7}, {8, 9, 10, 11}, {12, 13, 14, 15}};
+#endif /* H264DEC_OMXDL */
+
+/* clipping table, defined in h264bsd_intra_prediction.c */
+extern const u8 h264bsdClip[];
+
+/*------------------------------------------------------------------------------
+    4. Local function prototypes
+------------------------------------------------------------------------------*/
+
+#ifndef H264DEC_OMXDL
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdInterpolateChromaHor
+
+        Functional description:
+          This function performs chroma interpolation in horizontal direction.
+          Overfilling is done only if needed. Reference image (pRef) is
+          read at correct position and the predicted part is written to
+          macroblock's chrominance (predPartChroma)
+        Inputs:
+          pRef              pointer to reference frame Cb top-left corner
+          x0                integer x-coordinate for prediction
+          y0                integer y-coordinate for prediction
+          width             width of the reference frame chrominance in pixels
+          height            height of the reference frame chrominance in pixels
+          xFrac             horizontal fraction for prediction in 1/8 pixels
+          chromaPartWidth   width of the predicted part in pixels
+          chromaPartHeight  height of the predicted part in pixels
+        Outputs:
+          predPartChroma    pointer where predicted part is written
+
+------------------------------------------------------------------------------*/
+#ifndef H264DEC_ARM11
+void h264bsdInterpolateChromaHor(
+  u8 *pRef,
+  u8 *predPartChroma,
+  i32 x0,
+  i32 y0,
+  u32 width,
+  u32 height,
+  u32 xFrac,
+  u32 chromaPartWidth,
+  u32 chromaPartHeight)
+{
+
+/* Variables */
+
+    u32 x, y, tmp1, tmp2, tmp3, tmp4, c, val;
+    u8 *ptrA, *cbr;
+    u32 comp;
+    u8 block[9*8*2];
+
+/* Code */
+
+    ASSERT(predPartChroma);
+    ASSERT(chromaPartWidth);
+    ASSERT(chromaPartHeight);
+    ASSERT(xFrac < 8);
+    ASSERT(pRef);
+
+    if ((x0 < 0) || ((u32)x0+chromaPartWidth+1 > width) ||
+        (y0 < 0) || ((u32)y0+chromaPartHeight > height))
+    {
+        h264bsdFillBlock(pRef, block, x0, y0, width, height,
+            chromaPartWidth + 1, chromaPartHeight, chromaPartWidth + 1);
+        pRef += width * height;
+        h264bsdFillBlock(pRef, block + (chromaPartWidth+1)*chromaPartHeight,
+            x0, y0, width, height, chromaPartWidth + 1,
+            chromaPartHeight, chromaPartWidth + 1);
+
+        pRef = block;
+        x0 = 0;
+        y0 = 0;
+        width = chromaPartWidth+1;
+        height = chromaPartHeight;
+    }
+
+    val = 8 - xFrac;
+
+    for (comp = 0; comp <= 1; comp++)
+    {
+
+        ptrA = pRef + (comp * height + (u32)y0) * width + x0;
+        cbr = predPartChroma + comp * 8 * 8;
+
+        /* 2x2 pels per iteration
+         * bilinear horizontal interpolation */
+        for (y = (chromaPartHeight >> 1); y; y--)
+        {
+            for (x = (chromaPartWidth >> 1); x; x--)
+            {
+                tmp1 = ptrA[width];
+                tmp2 = *ptrA++;
+                tmp3 = ptrA[width];
+                tmp4 = *ptrA++;
+                c = ((val * tmp1 + xFrac * tmp3) << 3) + 32;
+                c >>= 6;
+                cbr[8] = (u8)c;
+                c = ((val * tmp2 + xFrac * tmp4) << 3) + 32;
+                c >>= 6;
+                *cbr++ = (u8)c;
+                tmp1 = ptrA[width];
+                tmp2 = *ptrA;
+                c = ((val * tmp3 + xFrac * tmp1) << 3) + 32;
+                c >>= 6;
+                cbr[8] = (u8)c;
+                c = ((val * tmp4 + xFrac * tmp2) << 3) + 32;
+                c >>= 6;
+                *cbr++ = (u8)c;
+            }
+            cbr += 2*8 - chromaPartWidth;
+            ptrA += 2*width - chromaPartWidth;
+        }
+    }
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdInterpolateChromaVer
+
+        Functional description:
+          This function performs chroma interpolation in vertical direction.
+          Overfilling is done only if needed. Reference image (pRef) is
+          read at correct position and the predicted part is written to
+          macroblock's chrominance (predPartChroma)
+
+------------------------------------------------------------------------------*/
+
+void h264bsdInterpolateChromaVer(
+  u8 *pRef,
+  u8 *predPartChroma,
+  i32 x0,
+  i32 y0,
+  u32 width,
+  u32 height,
+  u32 yFrac,
+  u32 chromaPartWidth,
+  u32 chromaPartHeight)
+{
+
+/* Variables */
+
+    u32 x, y, tmp1, tmp2, tmp3, c, val;
+    u8 *ptrA, *cbr;
+    u32 comp;
+    u8 block[9*8*2];
+
+/* Code */
+
+    ASSERT(predPartChroma);
+    ASSERT(chromaPartWidth);
+    ASSERT(chromaPartHeight);
+    ASSERT(yFrac < 8);
+    ASSERT(pRef);
+
+    if ((x0 < 0) || ((u32)x0+chromaPartWidth > width) ||
+        (y0 < 0) || ((u32)y0+chromaPartHeight+1 > height))
+    {
+        h264bsdFillBlock(pRef, block, x0, y0, width, height, chromaPartWidth,
+            chromaPartHeight + 1, chromaPartWidth);
+        pRef += width * height;
+        h264bsdFillBlock(pRef, block + chromaPartWidth*(chromaPartHeight+1),
+            x0, y0, width, height, chromaPartWidth,
+            chromaPartHeight + 1, chromaPartWidth);
+
+        pRef = block;
+        x0 = 0;
+        y0 = 0;
+        width = chromaPartWidth;
+        height = chromaPartHeight+1;
+    }
+
+    val = 8 - yFrac;
+
+    for (comp = 0; comp <= 1; comp++)
+    {
+
+        ptrA = pRef + (comp * height + (u32)y0) * width + x0;
+        cbr = predPartChroma + comp * 8 * 8;
+
+        /* 2x2 pels per iteration
+         * bilinear vertical interpolation */
+        for (y = (chromaPartHeight >> 1); y; y--)
+        {
+            for (x = (chromaPartWidth >> 1); x; x--)
+            {
+                tmp3 = ptrA[width*2];
+                tmp2 = ptrA[width];
+                tmp1 = *ptrA++;
+                c = ((val * tmp2 + yFrac * tmp3) << 3) + 32;
+                c >>= 6;
+                cbr[8] = (u8)c;
+                c = ((val * tmp1 + yFrac * tmp2) << 3) + 32;
+                c >>= 6;
+                *cbr++ = (u8)c;
+                tmp3 = ptrA[width*2];
+                tmp2 = ptrA[width];
+                tmp1 = *ptrA++;
+                c = ((val * tmp2 + yFrac * tmp3) << 3) + 32;
+                c >>= 6;
+                cbr[8] = (u8)c;
+                c = ((val * tmp1 + yFrac * tmp2) << 3) + 32;
+                c >>= 6;
+                *cbr++ = (u8)c;
+            }
+            cbr += 2*8 - chromaPartWidth;
+            ptrA += 2*width - chromaPartWidth;
+        }
+    }
+
+}
+#endif
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdInterpolateChromaHorVer
+
+        Functional description:
+          This function performs chroma interpolation in horizontal and
+          vertical direction. Overfilling is done only if needed. Reference
+          image (ref) is read at correct position and the predicted part
+          is written to macroblock's chrominance (predPartChroma)
+
+------------------------------------------------------------------------------*/
+
+void h264bsdInterpolateChromaHorVer(
+  u8 *ref,
+  u8 *predPartChroma,
+  i32 x0,
+  i32 y0,
+  u32 width,
+  u32 height,
+  u32 xFrac,
+  u32 yFrac,
+  u32 chromaPartWidth,
+  u32 chromaPartHeight)
+{
+    u8 block[9*9*2];
+    u32 x, y, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, valX, valY, plus32 = 32;
+    u32 comp;
+    u8 *ptrA, *cbr;
+
+/* Code */
+
+    ASSERT(predPartChroma);
+    ASSERT(chromaPartWidth);
+    ASSERT(chromaPartHeight);
+    ASSERT(xFrac < 8);
+    ASSERT(yFrac < 8);
+    ASSERT(ref);
+
+    if ((x0 < 0) || ((u32)x0+chromaPartWidth+1 > width) ||
+        (y0 < 0) || ((u32)y0+chromaPartHeight+1 > height))
+    {
+        h264bsdFillBlock(ref, block, x0, y0, width, height,
+            chromaPartWidth + 1, chromaPartHeight + 1, chromaPartWidth + 1);
+        ref += width * height;
+        h264bsdFillBlock(ref, block + (chromaPartWidth+1)*(chromaPartHeight+1),
+            x0, y0, width, height, chromaPartWidth + 1,
+            chromaPartHeight + 1, chromaPartWidth + 1);
+
+        ref = block;
+        x0 = 0;
+        y0 = 0;
+        width = chromaPartWidth+1;
+        height = chromaPartHeight+1;
+    }
+
+    valX = 8 - xFrac;
+    valY = 8 - yFrac;
+
+    for (comp = 0; comp <= 1; comp++)
+    {
+
+        ptrA = ref + (comp * height + (u32)y0) * width + x0;
+        cbr = predPartChroma + comp * 8 * 8;
+
+        /* 2x2 pels per iteration
+         * bilinear vertical and horizontal interpolation */
+        for (y = (chromaPartHeight >> 1); y; y--)
+        {
+            tmp1 = *ptrA;
+            tmp3 = ptrA[width];
+            tmp5 = ptrA[width*2];
+            tmp1 *= valY;
+            tmp1 += tmp3 * yFrac;
+            tmp3 *= valY;
+            tmp3 += tmp5 * yFrac;
+            for (x = (chromaPartWidth >> 1); x; x--)
+            {
+                tmp2 = *++ptrA;
+                tmp4 = ptrA[width];
+                tmp6 = ptrA[width*2];
+                tmp2 *= valY;
+                tmp2 += tmp4 * yFrac;
+                tmp4 *= valY;
+                tmp4 += tmp6 * yFrac;
+                tmp1 = tmp1 * valX + plus32;
+                tmp3 = tmp3 * valX + plus32;
+                tmp1 += tmp2 * xFrac;
+                tmp1 >>= 6;
+                tmp3 += tmp4 * xFrac;
+                tmp3 >>= 6;
+                cbr[8] = (u8)tmp3;
+                *cbr++ = (u8)tmp1;
+
+                tmp1 = *++ptrA;
+                tmp3 = ptrA[width];
+                tmp5 = ptrA[width*2];
+                tmp1 *= valY;
+                tmp1 += tmp3 * yFrac;
+                tmp3 *= valY;
+                tmp3 += tmp5 * yFrac;
+                tmp2 = tmp2 * valX + plus32;
+                tmp4 = tmp4 * valX + plus32;
+                tmp2 += tmp1 * xFrac;
+                tmp2 >>= 6;
+                tmp4 += tmp3 * xFrac;
+                tmp4 >>= 6;
+                cbr[8] = (u8)tmp4;
+                *cbr++ = (u8)tmp2;
+            }
+            cbr += 2*8 - chromaPartWidth;
+            ptrA += 2*width - chromaPartWidth;
+        }
+    }
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: PredictChroma
+
+        Functional description:
+          Top level chroma prediction function that calls the appropriate
+          interpolation function. The output is written to macroblock array.
+
+------------------------------------------------------------------------------*/
+
+static void PredictChroma(
+  u8 *mbPartChroma,
+  u32 xAL,
+  u32 yAL,
+  u32 partWidth,
+  u32 partHeight,
+  mv_t *mv,
+  image_t *refPic)
+{
+
+/* Variables */
+
+    u32 xFrac, yFrac, width, height, chromaPartWidth, chromaPartHeight;
+    i32 xInt, yInt;
+    u8 *ref;
+
+/* Code */
+
+    ASSERT(mv);
+    ASSERT(refPic);
+    ASSERT(refPic->data);
+    ASSERT(refPic->width);
+    ASSERT(refPic->height);
+
+    width  = 8 * refPic->width;
+    height = 8 * refPic->height;
+
+    xInt = (xAL >> 1) + (mv->hor >> 3);
+    yInt = (yAL >> 1) + (mv->ver >> 3);
+    xFrac = mv->hor & 0x7;
+    yFrac = mv->ver & 0x7;
+
+    chromaPartWidth  = partWidth >> 1;
+    chromaPartHeight = partHeight >> 1;
+    ref = refPic->data + 256 * refPic->width * refPic->height;
+
+    if (xFrac && yFrac)
+    {
+        h264bsdInterpolateChromaHorVer(ref, mbPartChroma, xInt, yInt, width,
+                height, xFrac, yFrac, chromaPartWidth, chromaPartHeight);
+    }
+    else if (xFrac)
+    {
+        h264bsdInterpolateChromaHor(ref, mbPartChroma, xInt, yInt, width,
+                height, xFrac, chromaPartWidth, chromaPartHeight);
+    }
+    else if (yFrac)
+    {
+        h264bsdInterpolateChromaVer(ref, mbPartChroma, xInt, yInt, width,
+                height, yFrac, chromaPartWidth, chromaPartHeight);
+    }
+    else
+    {
+        h264bsdFillBlock(ref, mbPartChroma, xInt, yInt, width, height,
+            chromaPartWidth, chromaPartHeight, 8);
+        ref += width * height;
+        h264bsdFillBlock(ref, mbPartChroma + 8*8, xInt, yInt, width, height,
+            chromaPartWidth, chromaPartHeight, 8);
+    }
+
+}
+
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdInterpolateVerHalf
+
+        Functional description:
+          Function to perform vertical interpolation of pixel position 'h'
+          for a block. Overfilling is done only if needed. Reference
+          image (ref) is read at correct position and the predicted part
+          is written to macroblock array (mb)
+
+------------------------------------------------------------------------------*/
+#ifndef H264DEC_ARM11
+void h264bsdInterpolateVerHalf(
+  u8 *ref,
+  u8 *mb,
+  i32 x0,
+  i32 y0,
+  u32 width,
+  u32 height,
+  u32 partWidth,
+  u32 partHeight)
+{
+    u32 p1[21*21/4+1];
+    u32 i, j;
+    i32 tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
+    u8 *ptrC, *ptrV;
+    const u8 *clp = h264bsdClip + 512;
+
+    /* Code */
+
+    ASSERT(ref);
+    ASSERT(mb);
+
+    if ((x0 < 0) || ((u32)x0+partWidth > width) ||
+        (y0 < 0) || ((u32)y0+partHeight+5 > height))
+    {
+        h264bsdFillBlock(ref, (u8*)p1, x0, y0, width, height,
+                partWidth, partHeight+5, partWidth);
+
+        x0 = 0;
+        y0 = 0;
+        ref = (u8*)p1;
+        width = partWidth;
+    }
+
+    ref += (u32)y0 * width + (u32)x0;
+
+    ptrC = ref + width;
+    ptrV = ptrC + 5*width;
+
+    /* 4 pixels per iteration, interpolate using 5 vertical samples */
+    for (i = (partHeight >> 2); i; i--)
+    {
+        /* h1 = (16 + A + 16(G+M) + 4(G+M) - 4(C+R) - (C+R) + T) >> 5 */
+        for (j = partWidth; j; j--)
+        {
+            tmp4 = ptrV[-(i32)width*2];
+            tmp5 = ptrV[-(i32)width];
+            tmp1 = ptrV[width];
+            tmp2 = ptrV[width*2];
+            tmp6 = *ptrV++;
+
+            tmp7 = tmp4 + tmp1;
+            tmp2 -= (tmp7 << 2);
+            tmp2 -= tmp7;
+            tmp2 += 16;
+            tmp7 = tmp5 + tmp6;
+            tmp3 = ptrC[width*2];
+            tmp2 += (tmp7 << 4);
+            tmp2 += (tmp7 << 2);
+            tmp2 += tmp3;
+            tmp2 = clp[tmp2>>5];
+            tmp1 += 16;
+            mb[48] = (u8)tmp2;
+
+            tmp7 = tmp3 + tmp6;
+            tmp1 -= (tmp7 << 2);
+            tmp1 -= tmp7;
+            tmp7 = tmp4 + tmp5;
+            tmp2 = ptrC[width];
+            tmp1 += (tmp7 << 4);
+            tmp1 += (tmp7 << 2);
+            tmp1 += tmp2;
+            tmp1 = clp[tmp1>>5];
+            tmp6 += 16;
+            mb[32] = (u8)tmp1;
+
+            tmp7 = tmp2 + tmp5;
+            tmp6 -= (tmp7 << 2);
+            tmp6 -= tmp7;
+            tmp7 = tmp4 + tmp3;
+            tmp1 = *ptrC;
+            tmp6 += (tmp7 << 4);
+            tmp6 += (tmp7 << 2);
+            tmp6 += tmp1;
+            tmp6 = clp[tmp6>>5];
+            tmp5 += 16;
+            mb[16] = (u8)tmp6;
+
+            tmp1 += tmp4;
+            tmp5 -= (tmp1 << 2);
+            tmp5 -= tmp1;
+            tmp3 += tmp2;
+            tmp6 = ptrC[-(i32)width];
+            tmp5 += (tmp3 << 4);
+            tmp5 += (tmp3 << 2);
+            tmp5 += tmp6;
+            tmp5 = clp[tmp5>>5];
+            *mb++ = (u8)tmp5;
+            ptrC++;
+        }
+        ptrC += 4*width - partWidth;
+        ptrV += 4*width - partWidth;
+        mb += 4*16 - partWidth;
+    }
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdInterpolateVerQuarter
+
+        Functional description:
+          Function to perform vertical interpolation of pixel position 'd'
+          or 'n' for a block. Overfilling is done only if needed. Reference
+          image (ref) is read at correct position and the predicted part
+          is written to macroblock array (mb)
+
+------------------------------------------------------------------------------*/
+
+void h264bsdInterpolateVerQuarter(
+  u8 *ref,
+  u8 *mb,
+  i32 x0,
+  i32 y0,
+  u32 width,
+  u32 height,
+  u32 partWidth,
+  u32 partHeight,
+  u32 verOffset)    /* 0 for pixel d, 1 for pixel n */
+{
+    u32 p1[21*21/4+1];
+    u32 i, j;
+    i32 tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
+    u8 *ptrC, *ptrV, *ptrInt;
+    const u8 *clp = h264bsdClip + 512;
+
+    /* Code */
+
+    ASSERT(ref);
+    ASSERT(mb);
+
+    if ((x0 < 0) || ((u32)x0+partWidth > width) ||
+        (y0 < 0) || ((u32)y0+partHeight+5 > height))
+    {
+        h264bsdFillBlock(ref, (u8*)p1, x0, y0, width, height,
+                partWidth, partHeight+5, partWidth);
+
+        x0 = 0;
+        y0 = 0;
+        ref = (u8*)p1;
+        width = partWidth;
+    }
+
+    ref += (u32)y0 * width + (u32)x0;
+
+    ptrC = ref + width;
+    ptrV = ptrC + 5*width;
+
+    /* Pointer to integer sample position, either M or R */
+    ptrInt = ptrC + (2+verOffset)*width;
+
+    /* 4 pixels per iteration
+     * interpolate using 5 vertical samples and average between
+     * interpolated value and integer sample value */
+    for (i = (partHeight >> 2); i; i--)
+    {
+        /* h1 = (16 + A + 16(G+M) + 4(G+M) - 4(C+R) - (C+R) + T) >> 5 */
+        for (j = partWidth; j; j--)
+        {
+            tmp4 = ptrV[-(i32)width*2];
+            tmp5 = ptrV[-(i32)width];
+            tmp1 = ptrV[width];
+            tmp2 = ptrV[width*2];
+            tmp6 = *ptrV++;
+
+            tmp7 = tmp4 + tmp1;
+            tmp2 -= (tmp7 << 2);
+            tmp2 -= tmp7;
+            tmp2 += 16;
+            tmp7 = tmp5 + tmp6;
+            tmp3 = ptrC[width*2];
+            tmp2 += (tmp7 << 4);
+            tmp2 += (tmp7 << 2);
+            tmp2 += tmp3;
+            tmp2 = clp[tmp2>>5];
+            tmp7 = ptrInt[width*2];
+            tmp1 += 16;
+            tmp2++;
+            mb[48] = (u8)((tmp2 + tmp7) >> 1);
+
+            tmp7 = tmp3 + tmp6;
+            tmp1 -= (tmp7 << 2);
+            tmp1 -= tmp7;
+            tmp7 = tmp4 + tmp5;
+            tmp2 = ptrC[width];
+            tmp1 += (tmp7 << 4);
+            tmp1 += (tmp7 << 2);
+            tmp1 += tmp2;
+            tmp1 = clp[tmp1>>5];
+            tmp7 = ptrInt[width];
+            tmp6 += 16;
+            tmp1++;
+            mb[32] = (u8)((tmp1 + tmp7) >> 1);
+
+            tmp7 = tmp2 + tmp5;
+            tmp6 -= (tmp7 << 2);
+            tmp6 -= tmp7;
+            tmp7 = tmp4 + tmp3;
+            tmp1 = *ptrC;
+            tmp6 += (tmp7 << 4);
+            tmp6 += (tmp7 << 2);
+            tmp6 += tmp1;
+            tmp6 = clp[tmp6>>5];
+            tmp7 = *ptrInt;
+            tmp5 += 16;
+            tmp6++;
+            mb[16] = (u8)((tmp6 + tmp7) >> 1);
+
+            tmp1 += tmp4;
+            tmp5 -= (tmp1 << 2);
+            tmp5 -= tmp1;
+            tmp3 += tmp2;
+            tmp6 = ptrC[-(i32)width];
+            tmp5 += (tmp3 << 4);
+            tmp5 += (tmp3 << 2);
+            tmp5 += tmp6;
+            tmp5 = clp[tmp5>>5];
+            tmp7 = ptrInt[-(i32)width];
+            tmp5++;
+            *mb++ = (u8)((tmp5 + tmp7) >> 1);
+            ptrC++;
+            ptrInt++;
+        }
+        ptrC += 4*width - partWidth;
+        ptrV += 4*width - partWidth;
+        ptrInt += 4*width - partWidth;
+        mb += 4*16 - partWidth;
+    }
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdInterpolateHorHalf
+
+        Functional description:
+          Function to perform horizontal interpolation of pixel position 'b'
+          for a block. Overfilling is done only if needed. Reference
+          image (ref) is read at correct position and the predicted part
+          is written to macroblock array (mb)
+
+------------------------------------------------------------------------------*/
+
+void h264bsdInterpolateHorHalf(
+  u8 *ref,
+  u8 *mb,
+  i32 x0,
+  i32 y0,
+  u32 width,
+  u32 height,
+  u32 partWidth,
+  u32 partHeight)
+{
+    u32 p1[21*21/4+1];
+    u8 *ptrJ;
+    u32 x, y;
+    i32 tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
+    const u8 *clp = h264bsdClip + 512;
+
+    /* Code */
+
+    ASSERT(ref);
+    ASSERT(mb);
+    ASSERT((partWidth&0x3) == 0);
+    ASSERT((partHeight&0x3) == 0);
+
+    if ((x0 < 0) || ((u32)x0+partWidth+5 > width) ||
+        (y0 < 0) || ((u32)y0+partHeight > height))
+    {
+        h264bsdFillBlock(ref, (u8*)p1, x0, y0, width, height,
+                partWidth+5, partHeight, partWidth+5);
+
+        x0 = 0;
+        y0 = 0;
+        ref = (u8*)p1;
+        width = partWidth + 5;
+    }
+
+    ref += (u32)y0 * width + (u32)x0;
+
+    ptrJ = ref + 5;
+
+    for (y = partHeight; y; y--)
+    {
+        tmp6 = *(ptrJ - 5);
+        tmp5 = *(ptrJ - 4);
+        tmp4 = *(ptrJ - 3);
+        tmp3 = *(ptrJ - 2);
+        tmp2 = *(ptrJ - 1);
+
+        /* calculate 4 pels per iteration */
+        for (x = (partWidth >> 2); x; x--)
+        {
+            /* First pixel */
+            tmp6 += 16;
+            tmp7 = tmp3 + tmp4;
+            tmp6 += (tmp7 << 4);
+            tmp6 += (tmp7 << 2);
+            tmp7 = tmp2 + tmp5;
+            tmp1 = *ptrJ++;
+            tmp6 -= (tmp7 << 2);
+            tmp6 -= tmp7;
+            tmp6 += tmp1;
+            tmp6 = clp[tmp6>>5];
+            /* Second pixel */
+            tmp5 += 16;
+            tmp7 = tmp2 + tmp3;
+            *mb++ = (u8)tmp6;
+            tmp5 += (tmp7 << 4);
+            tmp5 += (tmp7 << 2);
+            tmp7 = tmp1 + tmp4;
+            tmp6 = *ptrJ++;
+            tmp5 -= (tmp7 << 2);
+            tmp5 -= tmp7;
+            tmp5 += tmp6;
+            tmp5 = clp[tmp5>>5];
+            /* Third pixel */
+            tmp4 += 16;
+            tmp7 = tmp1 + tmp2;
+            *mb++ = (u8)tmp5;
+            tmp4 += (tmp7 << 4);
+            tmp4 += (tmp7 << 2);
+            tmp7 = tmp6 + tmp3;
+            tmp5 = *ptrJ++;
+            tmp4 -= (tmp7 << 2);
+            tmp4 -= tmp7;
+            tmp4 += tmp5;
+            tmp4 = clp[tmp4>>5];
+            /* Fourth pixel */
+            tmp3 += 16;
+            tmp7 = tmp6 + tmp1;
+            *mb++ = (u8)tmp4;
+            tmp3 += (tmp7 << 4);
+            tmp3 += (tmp7 << 2);
+            tmp7 = tmp5 + tmp2;
+            tmp4 = *ptrJ++;
+            tmp3 -= (tmp7 << 2);
+            tmp3 -= tmp7;
+            tmp3 += tmp4;
+            tmp3 = clp[tmp3>>5];
+            tmp7 = tmp4;
+            tmp4 = tmp6;
+            tmp6 = tmp2;
+            tmp2 = tmp7;
+            *mb++ = (u8)tmp3;
+            tmp3 = tmp5;
+            tmp5 = tmp1;
+        }
+        ptrJ += width - partWidth;
+        mb += 16 - partWidth;
+    }
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdInterpolateHorQuarter
+
+        Functional description:
+          Function to perform horizontal interpolation of pixel position 'a'
+          or 'c' for a block. Overfilling is done only if needed. Reference
+          image (ref) is read at correct position and the predicted part
+          is written to macroblock array (mb)
+
+------------------------------------------------------------------------------*/
+
+void h264bsdInterpolateHorQuarter(
+  u8 *ref,
+  u8 *mb,
+  i32 x0,
+  i32 y0,
+  u32 width,
+  u32 height,
+  u32 partWidth,
+  u32 partHeight,
+  u32 horOffset) /* 0 for pixel a, 1 for pixel c */
+{
+    u32 p1[21*21/4+1];
+    u8 *ptrJ;
+    u32 x, y;
+    i32 tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
+    const u8 *clp = h264bsdClip + 512;
+
+    /* Code */
+
+    ASSERT(ref);
+    ASSERT(mb);
+
+    if ((x0 < 0) || ((u32)x0+partWidth+5 > width) ||
+        (y0 < 0) || ((u32)y0+partHeight > height))
+    {
+        h264bsdFillBlock(ref, (u8*)p1, x0, y0, width, height,
+                partWidth+5, partHeight, partWidth+5);
+
+        x0 = 0;
+        y0 = 0;
+        ref = (u8*)p1;
+        width = partWidth + 5;
+    }
+
+    ref += (u32)y0 * width + (u32)x0;
+
+    ptrJ = ref + 5;
+
+    for (y = partHeight; y; y--)
+    {
+        tmp6 = *(ptrJ - 5);
+        tmp5 = *(ptrJ - 4);
+        tmp4 = *(ptrJ - 3);
+        tmp3 = *(ptrJ - 2);
+        tmp2 = *(ptrJ - 1);
+
+        /* calculate 4 pels per iteration */
+        for (x = (partWidth >> 2); x; x--)
+        {
+            /* First pixel */
+            tmp6 += 16;
+            tmp7 = tmp3 + tmp4;
+            tmp6 += (tmp7 << 4);
+            tmp6 += (tmp7 << 2);
+            tmp7 = tmp2 + tmp5;
+            tmp1 = *ptrJ++;
+            tmp6 -= (tmp7 << 2);
+            tmp6 -= tmp7;
+            tmp6 += tmp1;
+            tmp6 = clp[tmp6>>5];
+            tmp5 += 16;
+            if (!horOffset)
+                tmp6 += tmp4;
+            else
+                tmp6 += tmp3;
+            *mb++ = (u8)((tmp6 + 1) >> 1);
+            /* Second pixel */
+            tmp7 = tmp2 + tmp3;
+            tmp5 += (tmp7 << 4);
+            tmp5 += (tmp7 << 2);
+            tmp7 = tmp1 + tmp4;
+            tmp6 = *ptrJ++;
+            tmp5 -= (tmp7 << 2);
+            tmp5 -= tmp7;
+            tmp5 += tmp6;
+            tmp5 = clp[tmp5>>5];
+            tmp4 += 16;
+            if (!horOffset)
+                tmp5 += tmp3;
+            else
+                tmp5 += tmp2;
+            *mb++ = (u8)((tmp5 + 1) >> 1);
+            /* Third pixel */
+            tmp7 = tmp1 + tmp2;
+            tmp4 += (tmp7 << 4);
+            tmp4 += (tmp7 << 2);
+            tmp7 = tmp6 + tmp3;
+            tmp5 = *ptrJ++;
+            tmp4 -= (tmp7 << 2);
+            tmp4 -= tmp7;
+            tmp4 += tmp5;
+            tmp4 = clp[tmp4>>5];
+            tmp3 += 16;
+            if (!horOffset)
+                tmp4 += tmp2;
+            else
+                tmp4 += tmp1;
+            *mb++ = (u8)((tmp4 + 1) >> 1);
+            /* Fourth pixel */
+            tmp7 = tmp6 + tmp1;
+            tmp3 += (tmp7 << 4);
+            tmp3 += (tmp7 << 2);
+            tmp7 = tmp5 + tmp2;
+            tmp4 = *ptrJ++;
+            tmp3 -= (tmp7 << 2);
+            tmp3 -= tmp7;
+            tmp3 += tmp4;
+            tmp3 = clp[tmp3>>5];
+            if (!horOffset)
+                tmp3 += tmp1;
+            else
+                tmp3 += tmp6;
+            *mb++ = (u8)((tmp3 + 1) >> 1);
+            tmp3 = tmp5;
+            tmp5 = tmp1;
+            tmp7 = tmp4;
+            tmp4 = tmp6;
+            tmp6 = tmp2;
+            tmp2 = tmp7;
+        }
+        ptrJ += width - partWidth;
+        mb += 16 - partWidth;
+    }
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdInterpolateHorVerQuarter
+
+        Functional description:
+          Function to perform horizontal and vertical interpolation of pixel
+          position 'e', 'g', 'p' or 'r' for a block. Overfilling is done only
+          if needed. Reference image (ref) is read at correct position and
+          the predicted part is written to macroblock array (mb)
+
+------------------------------------------------------------------------------*/
+
+void h264bsdInterpolateHorVerQuarter(
+  u8 *ref,
+  u8 *mb,
+  i32 x0,
+  i32 y0,
+  u32 width,
+  u32 height,
+  u32 partWidth,
+  u32 partHeight,
+  u32 horVerOffset) /* 0 for pixel e, 1 for pixel g,
+                       2 for pixel p, 3 for pixel r */
+{
+    u32 p1[21*21/4+1];
+    u8 *ptrC, *ptrJ, *ptrV;
+    u32 x, y;
+    i32 tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
+    const u8 *clp = h264bsdClip + 512;
+
+    /* Code */
+
+    ASSERT(ref);
+    ASSERT(mb);
+
+    if ((x0 < 0) || ((u32)x0+partWidth+5 > width) ||
+        (y0 < 0) || ((u32)y0+partHeight+5 > height))
+    {
+        h264bsdFillBlock(ref, (u8*)p1, x0, y0, width, height,
+                partWidth+5, partHeight+5, partWidth+5);
+
+        x0 = 0;
+        y0 = 0;
+        ref = (u8*)p1;
+        width = partWidth+5;
+    }
+
+    /* Ref points to G + (-2, -2) */
+    ref += (u32)y0 * width + (u32)x0;
+
+    /* ptrJ points to either J or Q, depending on vertical offset */
+    ptrJ = ref + (((horVerOffset & 0x2) >> 1) + 2) * width + 5;
+
+    /* ptrC points to either C or D, depending on horizontal offset */
+    ptrC = ref + width + 2 + (horVerOffset & 0x1);
+
+    for (y = partHeight; y; y--)
+    {
+        tmp6 = *(ptrJ - 5);
+        tmp5 = *(ptrJ - 4);
+        tmp4 = *(ptrJ - 3);
+        tmp3 = *(ptrJ - 2);
+        tmp2 = *(ptrJ - 1);
+
+        /* Horizontal interpolation, calculate 4 pels per iteration */
+        for (x = (partWidth >> 2); x; x--)
+        {
+            /* First pixel */
+            tmp6 += 16;
+            tmp7 = tmp3 + tmp4;
+            tmp6 += (tmp7 << 4);
+            tmp6 += (tmp7 << 2);
+            tmp7 = tmp2 + tmp5;
+            tmp1 = *ptrJ++;
+            tmp6 -= (tmp7 << 2);
+            tmp6 -= tmp7;
+            tmp6 += tmp1;
+            tmp6 = clp[tmp6>>5];
+            /* Second pixel */
+            tmp5 += 16;
+            tmp7 = tmp2 + tmp3;
+            *mb++ = (u8)tmp6;
+            tmp5 += (tmp7 << 4);
+            tmp5 += (tmp7 << 2);
+            tmp7 = tmp1 + tmp4;
+            tmp6 = *ptrJ++;
+            tmp5 -= (tmp7 << 2);
+            tmp5 -= tmp7;
+            tmp5 += tmp6;
+            tmp5 = clp[tmp5>>5];
+            /* Third pixel */
+            tmp4 += 16;
+            tmp7 = tmp1 + tmp2;
+            *mb++ = (u8)tmp5;
+            tmp4 += (tmp7 << 4);
+            tmp4 += (tmp7 << 2);
+            tmp7 = tmp6 + tmp3;
+            tmp5 = *ptrJ++;
+            tmp4 -= (tmp7 << 2);
+            tmp4 -= tmp7;
+            tmp4 += tmp5;
+            tmp4 = clp[tmp4>>5];
+            /* Fourth pixel */
+            tmp3 += 16;
+            tmp7 = tmp6 + tmp1;
+            *mb++ = (u8)tmp4;
+            tmp3 += (tmp7 << 4);
+            tmp3 += (tmp7 << 2);
+            tmp7 = tmp5 + tmp2;
+            tmp4 = *ptrJ++;
+            tmp3 -= (tmp7 << 2);
+            tmp3 -= tmp7;
+            tmp3 += tmp4;
+            tmp3 = clp[tmp3>>5];
+            tmp7 = tmp4;
+            tmp4 = tmp6;
+            tmp6 = tmp2;
+            tmp2 = tmp7;
+            *mb++ = (u8)tmp3;
+            tmp3 = tmp5;
+            tmp5 = tmp1;
+        }
+        ptrJ += width - partWidth;
+        mb += 16 - partWidth;
+    }
+
+    mb -= 16*partHeight;
+    ptrV = ptrC + 5*width;
+
+    for (y = (partHeight >> 2); y; y--)
+    {
+        /* Vertical interpolation and averaging, 4 pels per iteration */
+        for (x = partWidth; x; x--)
+        {
+            tmp4 = ptrV[-(i32)width*2];
+            tmp5 = ptrV[-(i32)width];
+            tmp1 = ptrV[width];
+            tmp2 = ptrV[width*2];
+            tmp6 = *ptrV++;
+
+            tmp7 = tmp4 + tmp1;
+            tmp2 -= (tmp7 << 2);
+            tmp2 -= tmp7;
+            tmp2 += 16;
+            tmp7 = tmp5 + tmp6;
+            tmp3 = ptrC[width*2];
+            tmp2 += (tmp7 << 4);
+            tmp2 += (tmp7 << 2);
+            tmp2 += tmp3;
+            tmp7 = clp[tmp2>>5];
+            tmp2 = mb[48];
+            tmp1 += 16;
+            tmp7++;
+            mb[48] = (u8)((tmp2 + tmp7) >> 1);
+
+            tmp7 = tmp3 + tmp6;
+            tmp1 -= (tmp7 << 2);
+            tmp1 -= tmp7;
+            tmp7 = tmp4 + tmp5;
+            tmp2 = ptrC[width];
+            tmp1 += (tmp7 << 4);
+            tmp1 += (tmp7 << 2);
+            tmp1 += tmp2;
+            tmp7 = clp[tmp1>>5];
+            tmp1 = mb[32];
+            tmp6 += 16;
+            tmp7++;
+            mb[32] = (u8)((tmp1 + tmp7) >> 1);
+
+            tmp1 = *ptrC;
+            tmp7 = tmp2 + tmp5;
+            tmp6 -= (tmp7 << 2);
+            tmp6 -= tmp7;
+            tmp7 = tmp4 + tmp3;
+            tmp6 += (tmp7 << 4);
+            tmp6 += (tmp7 << 2);
+            tmp6 += tmp1;
+            tmp7 = clp[tmp6>>5];
+            tmp6 = mb[16];
+            tmp5 += 16;
+            tmp7++;
+            mb[16] = (u8)((tmp6 + tmp7) >> 1);
+
+            tmp6 = ptrC[-(i32)width];
+            tmp1 += tmp4;
+            tmp5 -= (tmp1 << 2);
+            tmp5 -= tmp1;
+            tmp3 += tmp2;
+            tmp5 += (tmp3 << 4);
+            tmp5 += (tmp3 << 2);
+            tmp5 += tmp6;
+            tmp7 = clp[tmp5>>5];
+            tmp5 = *mb;
+            tmp7++;
+            *mb++ = (u8)((tmp5 + tmp7) >> 1);
+            ptrC++;
+
+        }
+        ptrC += 4*width - partWidth;
+        ptrV += 4*width - partWidth;
+        mb += 4*16 - partWidth;
+    }
+
+}
+#endif
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdInterpolateMidHalf
+
+        Functional description:
+          Function to perform horizontal and vertical interpolation of pixel
+          position 'j' for a block. Overfilling is done only if needed.
+          Reference image (ref) is read at correct position and the predicted
+          part is written to macroblock array (mb)
+
+------------------------------------------------------------------------------*/
+
+void h264bsdInterpolateMidHalf(
+  u8 *ref,
+  u8 *mb,
+  i32 x0,
+  i32 y0,
+  u32 width,
+  u32 height,
+  u32 partWidth,
+  u32 partHeight)
+{
+    u32 p1[21*21/4+1];
+    u32 x, y;
+    i32 tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
+    i32 *ptrC, *ptrV, *b1;
+    u8  *ptrJ;
+    i32 table[21*16];
+    const u8 *clp = h264bsdClip + 512;
+
+    /* Code */
+
+    ASSERT(ref);
+    ASSERT(mb);
+
+    if ((x0 < 0) || ((u32)x0+partWidth+5 > width) ||
+        (y0 < 0) || ((u32)y0+partHeight+5 > height))
+    {
+        h264bsdFillBlock(ref, (u8*)p1, x0, y0, width, height,
+                partWidth+5, partHeight+5, partWidth+5);
+
+        x0 = 0;
+        y0 = 0;
+        ref = (u8*)p1;
+        width = partWidth+5;
+    }
+
+    ref += (u32)y0 * width + (u32)x0;
+
+    b1 = table;
+    ptrJ = ref + 5;
+
+    /* First step: calculate intermediate values for
+     * horizontal interpolation */
+    for (y = partHeight + 5; y; y--)
+    {
+        tmp6 = *(ptrJ - 5);
+        tmp5 = *(ptrJ - 4);
+        tmp4 = *(ptrJ - 3);
+        tmp3 = *(ptrJ - 2);
+        tmp2 = *(ptrJ - 1);
+
+        /* 4 pels per iteration */
+        for (x = (partWidth >> 2); x; x--)
+        {
+            /* First pixel */
+            tmp7 = tmp3 + tmp4;
+            tmp6 += (tmp7 << 4);
+            tmp6 += (tmp7 << 2);
+            tmp7 = tmp2 + tmp5;
+            tmp1 = *ptrJ++;
+            tmp6 -= (tmp7 << 2);
+            tmp6 -= tmp7;
+            tmp6 += tmp1;
+            *b1++ = tmp6;
+            /* Second pixel */
+            tmp7 = tmp2 + tmp3;
+            tmp5 += (tmp7 << 4);
+            tmp5 += (tmp7 << 2);
+            tmp7 = tmp1 + tmp4;
+            tmp6 = *ptrJ++;
+            tmp5 -= (tmp7 << 2);
+            tmp5 -= tmp7;
+            tmp5 += tmp6;
+            *b1++ = tmp5;
+            /* Third pixel */
+            tmp7 = tmp1 + tmp2;
+            tmp4 += (tmp7 << 4);
+            tmp4 += (tmp7 << 2);
+            tmp7 = tmp6 + tmp3;
+            tmp5 = *ptrJ++;
+            tmp4 -= (tmp7 << 2);
+            tmp4 -= tmp7;
+            tmp4 += tmp5;
+            *b1++ = tmp4;
+            /* Fourth pixel */
+            tmp7 = tmp6 + tmp1;
+            tmp3 += (tmp7 << 4);
+            tmp3 += (tmp7 << 2);
+            tmp7 = tmp5 + tmp2;
+            tmp4 = *ptrJ++;
+            tmp3 -= (tmp7 << 2);
+            tmp3 -= tmp7;
+            tmp3 += tmp4;
+            *b1++ = tmp3;
+            tmp7 = tmp4;
+            tmp4 = tmp6;
+            tmp6 = tmp2;
+            tmp2 = tmp7;
+            tmp3 = tmp5;
+            tmp5 = tmp1;
+        }
+        ptrJ += width - partWidth;
+    }
+
+    /* Second step: calculate vertical interpolation */
+    ptrC = table + partWidth;
+    ptrV = ptrC + 5*partWidth;
+    for (y = (partHeight >> 2); y; y--)
+    {
+        /* 4 pels per iteration */
+        for (x = partWidth; x; x--)
+        {
+            tmp4 = ptrV[-(i32)partWidth*2];
+            tmp5 = ptrV[-(i32)partWidth];
+            tmp1 = ptrV[partWidth];
+            tmp2 = ptrV[partWidth*2];
+            tmp6 = *ptrV++;
+
+            tmp7 = tmp4 + tmp1;
+            tmp2 -= (tmp7 << 2);
+            tmp2 -= tmp7;
+            tmp2 += 512;
+            tmp7 = tmp5 + tmp6;
+            tmp3 = ptrC[partWidth*2];
+            tmp2 += (tmp7 << 4);
+            tmp2 += (tmp7 << 2);
+            tmp2 += tmp3;
+            tmp7 = clp[tmp2>>10];
+            tmp1 += 512;
+            mb[48] = (u8)tmp7;
+
+            tmp7 = tmp3 + tmp6;
+            tmp1 -= (tmp7 << 2);
+            tmp1 -= tmp7;
+            tmp7 = tmp4 + tmp5;
+            tmp2 = ptrC[partWidth];
+            tmp1 += (tmp7 << 4);
+            tmp1 += (tmp7 << 2);
+            tmp1 += tmp2;
+            tmp7 = clp[tmp1>>10];
+            tmp6 += 512;
+            mb[32] = (u8)tmp7;
+
+            tmp1 = *ptrC;
+            tmp7 = tmp2 + tmp5;
+            tmp6 -= (tmp7 << 2);
+            tmp6 -= tmp7;
+            tmp7 = tmp4 + tmp3;
+            tmp6 += (tmp7 << 4);
+            tmp6 += (tmp7 << 2);
+            tmp6 += tmp1;
+            tmp7 = clp[tmp6>>10];
+            tmp5 += 512;
+            mb[16] = (u8)tmp7;
+
+            tmp6 = ptrC[-(i32)partWidth];
+            tmp1 += tmp4;
+            tmp5 -= (tmp1 << 2);
+            tmp5 -= tmp1;
+            tmp3 += tmp2;
+            tmp5 += (tmp3 << 4);
+            tmp5 += (tmp3 << 2);
+            tmp5 += tmp6;
+            tmp7 = clp[tmp5>>10];
+            *mb++ = (u8)tmp7;
+            ptrC++;
+        }
+        mb += 4*16 - partWidth;
+        ptrC += 3*partWidth;
+        ptrV += 3*partWidth;
+    }
+
+}
+
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdInterpolateMidVerQuarter
+
+        Functional description:
+          Function to perform horizontal and vertical interpolation of pixel
+          position 'f' or 'q' for a block. Overfilling is done only if needed.
+          Reference image (ref) is read at correct position and the predicted
+          part is written to macroblock array (mb)
+
+------------------------------------------------------------------------------*/
+
+void h264bsdInterpolateMidVerQuarter(
+  u8 *ref,
+  u8 *mb,
+  i32 x0,
+  i32 y0,
+  u32 width,
+  u32 height,
+  u32 partWidth,
+  u32 partHeight,
+  u32 verOffset)    /* 0 for pixel f, 1 for pixel q */
+{
+    u32 p1[21*21/4+1];
+    u32 x, y;
+    i32 tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
+    i32 *ptrC, *ptrV, *ptrInt, *b1;
+    u8  *ptrJ;
+    i32 table[21*16];
+    const u8 *clp = h264bsdClip + 512;
+
+    /* Code */
+
+    ASSERT(ref);
+    ASSERT(mb);
+
+    if ((x0 < 0) || ((u32)x0+partWidth+5 > width) ||
+        (y0 < 0) || ((u32)y0+partHeight+5 > height))
+    {
+        h264bsdFillBlock(ref, (u8*)p1, x0, y0, width, height,
+                partWidth+5, partHeight+5, partWidth+5);
+
+        x0 = 0;
+        y0 = 0;
+        ref = (u8*)p1;
+        width = partWidth+5;
+    }
+
+    ref += (u32)y0 * width + (u32)x0;
+
+    b1 = table;
+    ptrJ = ref + 5;
+
+    /* First step: calculate intermediate values for
+     * horizontal interpolation */
+    for (y = partHeight + 5; y; y--)
+    {
+        tmp6 = *(ptrJ - 5);
+        tmp5 = *(ptrJ - 4);
+        tmp4 = *(ptrJ - 3);
+        tmp3 = *(ptrJ - 2);
+        tmp2 = *(ptrJ - 1);
+        for (x = (partWidth >> 2); x; x--)
+        {
+            /* First pixel */
+            tmp7 = tmp3 + tmp4;
+            tmp6 += (tmp7 << 4);
+            tmp6 += (tmp7 << 2);
+            tmp7 = tmp2 + tmp5;
+            tmp1 = *ptrJ++;
+            tmp6 -= (tmp7 << 2);
+            tmp6 -= tmp7;
+            tmp6 += tmp1;
+            *b1++ = tmp6;
+            /* Second pixel */
+            tmp7 = tmp2 + tmp3;
+            tmp5 += (tmp7 << 4);
+            tmp5 += (tmp7 << 2);
+            tmp7 = tmp1 + tmp4;
+            tmp6 = *ptrJ++;
+            tmp5 -= (tmp7 << 2);
+            tmp5 -= tmp7;
+            tmp5 += tmp6;
+            *b1++ = tmp5;
+            /* Third pixel */
+            tmp7 = tmp1 + tmp2;
+            tmp4 += (tmp7 << 4);
+            tmp4 += (tmp7 << 2);
+            tmp7 = tmp6 + tmp3;
+            tmp5 = *ptrJ++;
+            tmp4 -= (tmp7 << 2);
+            tmp4 -= tmp7;
+            tmp4 += tmp5;
+            *b1++ = tmp4;
+            /* Fourth pixel */
+            tmp7 = tmp6 + tmp1;
+            tmp3 += (tmp7 << 4);
+            tmp3 += (tmp7 << 2);
+            tmp7 = tmp5 + tmp2;
+            tmp4 = *ptrJ++;
+            tmp3 -= (tmp7 << 2);
+            tmp3 -= tmp7;
+            tmp3 += tmp4;
+            *b1++ = tmp3;
+            tmp7 = tmp4;
+            tmp4 = tmp6;
+            tmp6 = tmp2;
+            tmp2 = tmp7;
+            tmp3 = tmp5;
+            tmp5 = tmp1;
+        }
+        ptrJ += width - partWidth;
+    }
+
+    /* Second step: calculate vertical interpolation and average */
+    ptrC = table + partWidth;
+    ptrV = ptrC + 5*partWidth;
+    /* Pointer to integer sample position, either M or R */
+    ptrInt = ptrC + (2+verOffset)*partWidth;
+    for (y = (partHeight >> 2); y; y--)
+    {
+        for (x = partWidth; x; x--)
+        {
+            tmp4 = ptrV[-(i32)partWidth*2];
+            tmp5 = ptrV[-(i32)partWidth];
+            tmp1 = ptrV[partWidth];
+            tmp2 = ptrV[partWidth*2];
+            tmp6 = *ptrV++;
+
+            tmp7 = tmp4 + tmp1;
+            tmp2 -= (tmp7 << 2);
+            tmp2 -= tmp7;
+            tmp2 += 512;
+            tmp7 = tmp5 + tmp6;
+            tmp3 = ptrC[partWidth*2];
+            tmp2 += (tmp7 << 4);
+            tmp2 += (tmp7 << 2);
+            tmp7 = ptrInt[partWidth*2];
+            tmp2 += tmp3;
+            tmp2 = clp[tmp2>>10];
+            tmp7 += 16;
+            tmp7 = clp[tmp7>>5];
+            tmp1 += 512;
+            tmp2++;
+            mb[48] = (u8)((tmp7 + tmp2) >> 1);
+
+            tmp7 = tmp3 + tmp6;
+            tmp1 -= (tmp7 << 2);
+            tmp1 -= tmp7;
+            tmp7 = tmp4 + tmp5;
+            tmp2 = ptrC[partWidth];
+            tmp1 += (tmp7 << 4);
+            tmp1 += (tmp7 << 2);
+            tmp7 = ptrInt[partWidth];
+            tmp1 += tmp2;
+            tmp1 = clp[tmp1>>10];
+            tmp7 += 16;
+            tmp7 = clp[tmp7>>5];
+            tmp6 += 512;
+            tmp1++;
+            mb[32] = (u8)((tmp7 + tmp1) >> 1);
+
+            tmp1 = *ptrC;
+            tmp7 = tmp2 + tmp5;
+            tmp6 -= (tmp7 << 2);
+            tmp6 -= tmp7;
+            tmp7 = tmp4 + tmp3;
+            tmp6 += (tmp7 << 4);
+            tmp6 += (tmp7 << 2);
+            tmp7 = *ptrInt;
+            tmp6 += tmp1;
+            tmp6 = clp[tmp6>>10];
+            tmp7 += 16;
+            tmp7 = clp[tmp7>>5];
+            tmp5 += 512;
+            tmp6++;
+            mb[16] = (u8)((tmp7 + tmp6) >> 1);
+
+            tmp6 = ptrC[-(i32)partWidth];
+            tmp1 += tmp4;
+            tmp5 -= (tmp1 << 2);
+            tmp5 -= tmp1;
+            tmp3 += tmp2;
+            tmp5 += (tmp3 << 4);
+            tmp5 += (tmp3 << 2);
+            tmp7 = ptrInt[-(i32)partWidth];
+            tmp5 += tmp6;
+            tmp5 = clp[tmp5>>10];
+            tmp7 += 16;
+            tmp7 = clp[tmp7>>5];
+            tmp5++;
+            *mb++ = (u8)((tmp7 + tmp5) >> 1);
+            ptrC++;
+            ptrInt++;
+        }
+        mb += 4*16 - partWidth;
+        ptrC += 3*partWidth;
+        ptrV += 3*partWidth;
+        ptrInt += 3*partWidth;
+    }
+
+}
+
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdInterpolateMidHorQuarter
+
+        Functional description:
+          Function to perform horizontal and vertical interpolation of pixel
+          position 'i' or 'k' for a block. Overfilling is done only if needed.
+          Reference image (ref) is read at correct position and the predicted
+          part is written to macroblock array (mb)
+
+------------------------------------------------------------------------------*/
+
+void h264bsdInterpolateMidHorQuarter(
+  u8 *ref,
+  u8 *mb,
+  i32 x0,
+  i32 y0,
+  u32 width,
+  u32 height,
+  u32 partWidth,
+  u32 partHeight,
+  u32 horOffset)    /* 0 for pixel i, 1 for pixel k */
+{
+    u32 p1[21*21/4+1];
+    u32 x, y;
+    i32 tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
+    i32 *ptrJ, *ptrInt, *h1;
+    u8  *ptrC, *ptrV;
+    i32 table[21*16];
+    i32 tableWidth = (i32)partWidth+5;
+    const u8 *clp = h264bsdClip + 512;
+
+    /* Code */
+
+    ASSERT(ref);
+    ASSERT(mb);
+
+    if ((x0 < 0) || ((u32)x0+partWidth+5 > width) ||
+        (y0 < 0) || ((u32)y0+partHeight+5 > height))
+    {
+        h264bsdFillBlock(ref, (u8*)p1, x0, y0, width, height,
+                partWidth+5, partHeight+5, partWidth+5);
+
+        x0 = 0;
+        y0 = 0;
+        ref = (u8*)p1;
+        width = partWidth+5;
+    }
+
+    ref += (u32)y0 * width + (u32)x0;
+
+    h1 = table + tableWidth;
+    ptrC = ref + width;
+    ptrV = ptrC + 5*width;
+
+    /* First step: calculate intermediate values for
+     * vertical interpolation */
+    for (y = (partHeight >> 2); y; y--)
+    {
+        for (x = (u32)tableWidth; x; x--)
+        {
+            tmp4 = ptrV[-(i32)width*2];
+            tmp5 = ptrV[-(i32)width];
+            tmp1 = ptrV[width];
+            tmp2 = ptrV[width*2];
+            tmp6 = *ptrV++;
+
+            tmp7 = tmp4 + tmp1;
+            tmp2 -= (tmp7 << 2);
+            tmp2 -= tmp7;
+            tmp7 = tmp5 + tmp6;
+            tmp3 = ptrC[width*2];
+            tmp2 += (tmp7 << 4);
+            tmp2 += (tmp7 << 2);
+            tmp2 += tmp3;
+            h1[tableWidth*2] = tmp2;
+
+            tmp7 = tmp3 + tmp6;
+            tmp1 -= (tmp7 << 2);
+            tmp1 -= tmp7;
+            tmp7 = tmp4 + tmp5;
+            tmp2 = ptrC[width];
+            tmp1 += (tmp7 << 4);
+            tmp1 += (tmp7 << 2);
+            tmp1 += tmp2;
+            h1[tableWidth] = tmp1;
+
+            tmp1 = *ptrC;
+            tmp7 = tmp2 + tmp5;
+            tmp6 -= (tmp7 << 2);
+            tmp6 -= tmp7;
+            tmp7 = tmp4 + tmp3;
+            tmp6 += (tmp7 << 4);
+            tmp6 += (tmp7 << 2);
+            tmp6 += tmp1;
+            *h1 = tmp6;
+
+            tmp6 = ptrC[-(i32)width];
+            tmp1 += tmp4;
+            tmp5 -= (tmp1 << 2);
+            tmp5 -= tmp1;
+            tmp3 += tmp2;
+            tmp5 += (tmp3 << 4);
+            tmp5 += (tmp3 << 2);
+            tmp5 += tmp6;
+            h1[-tableWidth] = tmp5;
+            h1++;
+            ptrC++;
+        }
+        ptrC += 4*width - partWidth - 5;
+        ptrV += 4*width - partWidth - 5;
+        h1 += 3*tableWidth;
+    }
+
+    /* Second step: calculate horizontal interpolation and average */
+    ptrJ = table + 5;
+    /* Pointer to integer sample position, either G or H */
+    ptrInt = table + 2 + horOffset;
+    for (y = partHeight; y; y--)
+    {
+        tmp6 = *(ptrJ - 5);
+        tmp5 = *(ptrJ - 4);
+        tmp4 = *(ptrJ - 3);
+        tmp3 = *(ptrJ - 2);
+        tmp2 = *(ptrJ - 1);
+        for (x = (partWidth>>2); x; x--)
+        {
+            /* First pixel */
+            tmp6 += 512;
+            tmp7 = tmp3 + tmp4;
+            tmp6 += (tmp7 << 4);
+            tmp6 += (tmp7 << 2);
+            tmp7 = tmp2 + tmp5;
+            tmp1 = *ptrJ++;
+            tmp6 -= (tmp7 << 2);
+            tmp6 -= tmp7;
+            tmp7 = *ptrInt++;
+            tmp6 += tmp1;
+            tmp6 = clp[tmp6 >> 10];
+            tmp7 += 16;
+            tmp7 = clp[tmp7 >> 5];
+            tmp5 += 512;
+            tmp6++;
+            *mb++ = (u8)((tmp6 + tmp7) >> 1);
+            /* Second pixel */
+            tmp7 = tmp2 + tmp3;
+            tmp5 += (tmp7 << 4);
+            tmp5 += (tmp7 << 2);
+            tmp7 = tmp1 + tmp4;
+            tmp6 = *ptrJ++;
+            tmp5 -= (tmp7 << 2);
+            tmp5 -= tmp7;
+            tmp7 = *ptrInt++;
+            tmp5 += tmp6;
+            tmp5 = clp[tmp5 >> 10];
+            tmp7 += 16;
+            tmp7 = clp[tmp7 >> 5];
+            tmp4 += 512;
+            tmp5++;
+            *mb++ = (u8)((tmp5 + tmp7) >> 1);
+            /* Third pixel */
+            tmp7 = tmp1 + tmp2;
+            tmp4 += (tmp7 << 4);
+            tmp4 += (tmp7 << 2);
+            tmp7 = tmp6 + tmp3;
+            tmp5 = *ptrJ++;
+            tmp4 -= (tmp7 << 2);
+            tmp4 -= tmp7;
+            tmp7 = *ptrInt++;
+            tmp4 += tmp5;
+            tmp4 = clp[tmp4 >> 10];
+            tmp7 += 16;
+            tmp7 = clp[tmp7 >> 5];
+            tmp3 += 512;
+            tmp4++;
+            *mb++ = (u8)((tmp4 + tmp7) >> 1);
+            /* Fourth pixel */
+            tmp7 = tmp6 + tmp1;
+            tmp3 += (tmp7 << 4);
+            tmp3 += (tmp7 << 2);
+            tmp7 = tmp5 + tmp2;
+            tmp4 = *ptrJ++;
+            tmp3 -= (tmp7 << 2);
+            tmp3 -= tmp7;
+            tmp7 = *ptrInt++;
+            tmp3 += tmp4;
+            tmp3 = clp[tmp3 >> 10];
+            tmp7 += 16;
+            tmp7 = clp[tmp7 >> 5];
+            tmp3++;
+            *mb++ = (u8)((tmp3 + tmp7) >> 1);
+            tmp3 = tmp5;
+            tmp5 = tmp1;
+            tmp7 = tmp4;
+            tmp4 = tmp6;
+            tmp6 = tmp2;
+            tmp2 = tmp7;
+        }
+        ptrJ += 5;
+        ptrInt += 5;
+        mb += 16 - partWidth;
+    }
+
+}
+
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdPredictSamples
+
+        Functional description:
+          This function reconstructs a prediction for a macroblock partition.
+          The prediction is either copied or interpolated using the reference
+          frame and the motion vector. Both luminance and chrominance parts are
+          predicted. The prediction is stored in given macroblock array (data).
+        Inputs:
+          data          pointer to macroblock array (384 bytes) for output
+          mv            pointer to motion vector used for prediction
+          refPic        pointer to reference picture structure
+          xA            x-coordinate for current macroblock
+          yA            y-coordinate for current macroblock
+          partX         x-offset for partition in macroblock
+          partY         y-offset for partition in macroblock
+          partWidth     width of partition
+          partHeight    height of partition
+        Outputs:
+          data          macroblock array (16x16+8x8+8x8) where predicted
+                        partition is stored at correct position
+
+------------------------------------------------------------------------------*/
+
+void h264bsdPredictSamples(
+  u8 *data,
+  mv_t *mv,
+  image_t *refPic,
+  u32 xA,
+  u32 yA,
+  u32 partX,
+  u32 partY,
+  u32 partWidth,
+  u32 partHeight)
+
+{
+
+/* Variables */
+
+    u32 xFrac, yFrac, width, height;
+    i32 xInt, yInt;
+    u8 *lumaPartData;
+
+/* Code */
+
+    ASSERT(data);
+    ASSERT(mv);
+    ASSERT(partWidth);
+    ASSERT(partHeight);
+    ASSERT(refPic);
+    ASSERT(refPic->data);
+    ASSERT(refPic->width);
+    ASSERT(refPic->height);
+
+    /* luma */
+    lumaPartData = data + 16*partY + partX;
+
+    xFrac = mv->hor & 0x3;
+    yFrac = mv->ver & 0x3;
+
+    width = 16 * refPic->width;
+    height = 16 * refPic->height;
+
+    xInt = (i32)xA + (i32)partX + (mv->hor >> 2);
+    yInt = (i32)yA + (i32)partY + (mv->ver >> 2);
+
+    ASSERT(lumaFracPos[xFrac][yFrac] < 16);
+
+    switch (lumaFracPos[xFrac][yFrac])
+    {
+        case 0: /* G */
+            h264bsdFillBlock(refPic->data, lumaPartData,
+                    xInt,yInt,width,height,partWidth,partHeight,16);
+            break;
+        case 1: /* d */
+            h264bsdInterpolateVerQuarter(refPic->data, lumaPartData,
+                    xInt, yInt-2, width, height, partWidth, partHeight, 0);
+            break;
+        case 2: /* h */
+            h264bsdInterpolateVerHalf(refPic->data, lumaPartData,
+                    xInt, yInt-2, width, height, partWidth, partHeight);
+            break;
+        case 3: /* n */
+            h264bsdInterpolateVerQuarter(refPic->data, lumaPartData,
+                    xInt, yInt-2, width, height, partWidth, partHeight, 1);
+            break;
+        case 4: /* a */
+            h264bsdInterpolateHorQuarter(refPic->data, lumaPartData,
+                    xInt-2, yInt, width, height, partWidth, partHeight, 0);
+            break;
+        case 5: /* e */
+            h264bsdInterpolateHorVerQuarter(refPic->data, lumaPartData,
+                    xInt-2, yInt-2, width, height, partWidth, partHeight, 0);
+            break;
+        case 6: /* i */
+            h264bsdInterpolateMidHorQuarter(refPic->data, lumaPartData,
+                    xInt-2, yInt-2, width, height, partWidth, partHeight, 0);
+            break;
+        case 7: /* p */
+            h264bsdInterpolateHorVerQuarter(refPic->data, lumaPartData,
+                    xInt-2, yInt-2, width, height, partWidth, partHeight, 2);
+            break;
+        case 8: /* b */
+            h264bsdInterpolateHorHalf(refPic->data, lumaPartData,
+                    xInt-2, yInt, width, height, partWidth, partHeight);
+            break;
+        case 9: /* f */
+            h264bsdInterpolateMidVerQuarter(refPic->data, lumaPartData,
+                    xInt-2, yInt-2, width, height, partWidth, partHeight, 0);
+            break;
+        case 10: /* j */
+            h264bsdInterpolateMidHalf(refPic->data, lumaPartData,
+                    xInt-2, yInt-2, width, height, partWidth, partHeight);
+            break;
+        case 11: /* q */
+            h264bsdInterpolateMidVerQuarter(refPic->data, lumaPartData,
+                    xInt-2, yInt-2, width, height, partWidth, partHeight, 1);
+            break;
+        case 12: /* c */
+            h264bsdInterpolateHorQuarter(refPic->data, lumaPartData,
+                    xInt-2, yInt, width, height, partWidth, partHeight, 1);
+            break;
+        case 13: /* g */
+            h264bsdInterpolateHorVerQuarter(refPic->data, lumaPartData,
+                    xInt-2, yInt-2, width, height, partWidth, partHeight, 1);
+            break;
+        case 14: /* k */
+            h264bsdInterpolateMidHorQuarter(refPic->data, lumaPartData,
+                    xInt-2, yInt-2, width, height, partWidth, partHeight, 1);
+            break;
+        default: /* case 15, r */
+            h264bsdInterpolateHorVerQuarter(refPic->data, lumaPartData,
+                    xInt-2, yInt-2, width, height, partWidth, partHeight, 3);
+            break;
+    }
+
+    /* chroma */
+    PredictChroma(
+      data + 16*16 + (partY>>1)*8 + (partX>>1),
+      xA + partX,
+      yA + partY,
+      partWidth,
+      partHeight,
+      mv,
+      refPic);
+
+}
+
+#else /* H264DEC_OMXDL */
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdPredictSamples
+
+        Functional description:
+          This function reconstructs a prediction for a macroblock partition.
+          The prediction is either copied or interpolated using the reference
+          frame and the motion vector. Both luminance and chrominance parts are
+          predicted. The prediction is stored in given macroblock array (data).
+        Inputs:
+          data          pointer to macroblock array (384 bytes) for output
+          mv            pointer to motion vector used for prediction
+          refPic        pointer to reference picture structure
+          xA            x-coordinate for current macroblock
+          yA            y-coordinate for current macroblock
+          partX         x-offset for partition in macroblock
+          partY         y-offset for partition in macroblock
+          partWidth     width of partition
+          partHeight    height of partition
+        Outputs:
+          data          macroblock array (16x16+8x8+8x8) where predicted
+                        partition is stored at correct position
+
+------------------------------------------------------------------------------*/
+
+/*lint -e{550} Symbol 'res' not accessed */
+void h264bsdPredictSamples(
+  u8 *data,
+  mv_t *mv,
+  image_t *refPic,
+  u32 colAndRow,
+  u32 part,
+  u8 *pFill)
+
+{
+
+/* Variables */
+
+    u32 xFrac, yFrac;
+    u32 width, height;
+    i32 xInt, yInt, x0, y0;
+    u8 *partData, *ref;
+    OMXSize roi;
+    u32 fillWidth;
+    u32 fillHeight;
+    OMXResult res;
+    u32 xA, yA;
+    u32 partX, partY;
+    u32 partWidth, partHeight;
+
+/* Code */
+
+    ASSERT(data);
+    ASSERT(mv);
+    ASSERT(refPic);
+    ASSERT(refPic->data);
+    ASSERT(refPic->width);
+    ASSERT(refPic->height);
+
+    xA = (colAndRow & 0xFFFF0000) >> 16;
+    yA = (colAndRow & 0x0000FFFF);
+
+    partX = (part & 0xFF000000) >> 24;
+    partY = (part & 0x00FF0000) >> 16;
+    partWidth = (part & 0x0000FF00) >> 8;
+    partHeight = (part & 0x000000FF);
+
+    ASSERT(partWidth);
+    ASSERT(partHeight);
+
+    /* luma */
+    partData = data + 16*partY + partX;
+
+    xFrac = mv->hor & 0x3;
+    yFrac = mv->ver & 0x3;
+
+    width = 16 * refPic->width;
+    height = 16 * refPic->height;
+
+    xInt = (i32)xA + (i32)partX + (mv->hor >> 2);
+    yInt = (i32)yA + (i32)partY + (mv->ver >> 2);
+
+    x0 = (xFrac) ? xInt-2 : xInt;
+    y0 = (yFrac) ? yInt-2 : yInt;
+
+    if (xFrac)
+    {
+        if (partWidth == 16)
+            fillWidth = 32;
+        else
+            fillWidth = 16;
+    }
+    else
+        fillWidth = (partWidth*2);
+    if (yFrac)
+        fillHeight = partHeight+5;
+    else
+        fillHeight = partHeight;
+
+
+    if ((x0 < 0) || ((u32)x0+fillWidth > width) ||
+        (y0 < 0) || ((u32)y0+fillHeight > height))
+    {
+        h264bsdFillBlock(refPic->data, (u8*)pFill, x0, y0, width, height,
+                fillWidth, fillHeight, fillWidth);
+
+        x0 = 0;
+        y0 = 0;
+        ref = pFill;
+        width = fillWidth;
+        if (yFrac)
+            ref += 2*width;
+        if (xFrac)
+            ref += 2;
+    }
+    else
+    {
+        /*lint --e(737) Loss of sign */
+        ref = refPic->data + yInt*width + xInt;
+    }
+    /* Luma interpolation */
+    roi.width = (i32)partWidth;
+    roi.height = (i32)partHeight;
+
+    res = omxVCM4P10_InterpolateLuma(ref, (i32)width, partData, 16,
+                                        (i32)xFrac, (i32)yFrac, roi);
+    ASSERT(res == 0);
+
+    /* Chroma */
+    width  = 8 * refPic->width;
+    height = 8 * refPic->height;
+
+    x0 = ((xA + partX) >> 1) + (mv->hor >> 3);
+    y0 = ((yA + partY) >> 1) + (mv->ver >> 3);
+    xFrac = mv->hor & 0x7;
+    yFrac = mv->ver & 0x7;
+
+    ref = refPic->data + 256 * refPic->width * refPic->height;
+
+    roi.width = (i32)(partWidth >> 1);
+    fillWidth = ((partWidth >> 1) + 8) & ~0x7;
+    roi.height = (i32)(partHeight >> 1);
+    fillHeight = (partHeight >> 1) + 1;
+
+    if ((x0 < 0) || ((u32)x0+fillWidth > width) ||
+        (y0 < 0) || ((u32)y0+fillHeight > height))
+    {
+        h264bsdFillBlock(ref, pFill, x0, y0, width, height,
+            fillWidth, fillHeight, fillWidth);
+        ref += width * height;
+        h264bsdFillBlock(ref, pFill + fillWidth*fillHeight,
+            x0, y0, width, height, fillWidth,
+            fillHeight, fillWidth);
+
+        ref = pFill;
+        x0 = 0;
+        y0 = 0;
+        width = fillWidth;
+        height = fillHeight;
+    }
+
+    partData = data + 16*16 + (partY>>1)*8 + (partX>>1);
+
+    /* Chroma interpolation */
+    /*lint --e(737) Loss of sign */
+    ref += y0 * width + x0;
+    res = armVCM4P10_Interpolate_Chroma(ref, width, partData, 8,
+                            (u32)roi.width, (u32)roi.height, xFrac, yFrac);
+    ASSERT(res == 0);
+    partData += 8 * 8;
+    ref += height * width;
+    res = armVCM4P10_Interpolate_Chroma(ref, width, partData, 8,
+                            (u32)roi.width, (u32)roi.height, xFrac, yFrac);
+    ASSERT(res == 0);
+
+}
+
+#endif /* H264DEC_OMXDL */
+
+
+/*------------------------------------------------------------------------------
+
+    Function: FillRow1
+
+        Functional description:
+          This function gets a row of reference pels in a 'normal' case when no
+          overfilling is necessary.
+
+------------------------------------------------------------------------------*/
+
+static void FillRow1(
+  u8 *ref,
+  u8 *fill,
+  i32 left,
+  i32 center,
+  i32 right)
+{
+
+    ASSERT(ref);
+    ASSERT(fill);
+
+    H264SwDecMemcpy(fill, ref, (u32)center);
+
+    /*lint -e(715) */
+}
+
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdFillRow7
+
+        Functional description:
+          This function gets a row of reference pels when horizontal coordinate
+          is partly negative or partly greater than reference picture width
+          (overfilling some pels on left and/or right edge).
+        Inputs:
+          ref       pointer to reference samples
+          left      amount of pixels to overfill on left-edge
+          center    amount of pixels to copy
+          right     amount of pixels to overfill on right-edge
+        Outputs:
+          fill      pointer where samples are stored
+
+------------------------------------------------------------------------------*/
+#ifndef H264DEC_NEON
+void h264bsdFillRow7(
+  u8 *ref,
+  u8 *fill,
+  i32 left,
+  i32 center,
+  i32 right)
+{
+    u8 tmp;
+
+    ASSERT(ref);
+    ASSERT(fill);
+
+    if (left)
+        tmp = *ref;
+
+    for ( ; left; left--)
+        /*lint -esym(644,tmp)  tmp is initialized if used */
+        *fill++ = tmp;
+
+    for ( ; center; center--)
+        *fill++ = *ref++;
+
+    if (right)
+        tmp = ref[-1];
+
+    for ( ; right; right--)
+        /*lint -esym(644,tmp)  tmp is initialized if used */
+        *fill++ = tmp;
+}
+#endif
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdFillBlock
+
+        Functional description:
+          This function gets a block of reference pels. It determines whether
+          overfilling is needed or not and repeatedly calls an appropriate
+          function (by using a function pointer) that fills one row the block.
+        Inputs:
+          ref               pointer to reference frame
+          x0                x-coordinate for block
+          y0                y-coordinate for block
+          width             width of reference frame
+          height            height of reference frame
+          blockWidth        width of block
+          blockHeight       height of block
+          fillScanLength    length of a line in output array (pixels)
+        Outputs:
+          fill              pointer to array where output block is written
+
+------------------------------------------------------------------------------*/
+
+void h264bsdFillBlock(
+  u8 *ref,
+  u8 *fill,
+  i32 x0,
+  i32 y0,
+  u32 width,
+  u32 height,
+  u32 blockWidth,
+  u32 blockHeight,
+  u32 fillScanLength)
+
+{
+
+/* Variables */
+
+    i32 xstop, ystop;
+    void (*fp)(u8*, u8*, i32, i32, i32);
+    i32 left, x, right;
+    i32 top, y, bottom;
+
+/* Code */
+
+    ASSERT(ref);
+    ASSERT(fill);
+    ASSERT(width);
+    ASSERT(height);
+    ASSERT(fill);
+    ASSERT(blockWidth);
+    ASSERT(blockHeight);
+
+    xstop = x0 + (i32)blockWidth;
+    ystop = y0 + (i32)blockHeight;
+
+    /* Choose correct function whether overfilling on left-edge or right-edge
+     * is needed or not */
+    if (x0 >= 0 && xstop <= (i32)width)
+        fp = FillRow1;
+    else
+        fp = h264bsdFillRow7;
+
+    if (ystop < 0)
+        y0 = -(i32)blockHeight;
+
+    if (xstop < 0)
+        x0 = -(i32)blockWidth;
+
+    if (y0 > (i32)height)
+        y0 = (i32)height;
+
+    if (x0 > (i32)width)
+        x0 = (i32)width;
+
+    xstop = x0 + (i32)blockWidth;
+    ystop = y0 + (i32)blockHeight;
+
+    if (x0 > 0)
+        ref += x0;
+
+    if (y0 > 0)
+        ref += y0 * (i32)width;
+
+    left = x0 < 0 ? -x0 : 0;
+    right = xstop > (i32)width ? xstop - (i32)width : 0;
+    x = (i32)blockWidth - left - right;
+
+    top = y0 < 0 ? -y0 : 0;
+    bottom = ystop > (i32)height ? ystop - (i32)height : 0;
+    y = (i32)blockHeight - top - bottom;
+
+    /* Top-overfilling */
+    for ( ; top; top-- )
+    {
+        (*fp)(ref, fill, left, x, right);
+        fill += fillScanLength;
+    }
+
+    /* Lines inside reference image */
+    for ( ; y; y-- )
+    {
+        (*fp)(ref, fill, left, x, right);
+        ref += width;
+        fill += fillScanLength;
+    }
+
+    ref -= width;
+
+    /* Bottom-overfilling */
+    for ( ; bottom; bottom-- )
+    {
+        (*fp)(ref, fill, left, x, right);
+        fill += fillScanLength;
+    }
+}
+
+/*lint +e701 +e702 */
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_reconstruct.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_reconstruct.h
new file mode 100755
index 0000000..5a1a140
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_reconstruct.h
@@ -0,0 +1,210 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+    1. Include headers
+    2. Module defines
+    3. Data types
+    4. Function prototypes
+
+------------------------------------------------------------------------------*/
+
+#ifndef H264SWDEC_RECONSTRUCT_H
+#define H264SWDEC_RECONSTRUCT_H
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "basetype.h"
+#include "h264bsd_macroblock_layer.h"
+#include "h264bsd_image.h"
+
+/*------------------------------------------------------------------------------
+    2. Module defines
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    3. Data types
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    4. Function prototypes
+------------------------------------------------------------------------------*/
+#ifndef H264DEC_OMXDL
+void h264bsdPredictSamples(
+  u8 *data,
+  mv_t *mv,
+  image_t *refPic,
+  u32 xA,
+  u32 yA,
+  u32 partX,
+  u32 partY,
+  u32 partWidth,
+  u32 partHeight);
+#else
+void h264bsdPredictSamples(
+  u8 *data,
+  mv_t *mv,
+  image_t *refPic,
+  u32 colAndRow,/* packaged data | column    | row                |*/
+  u32 part,     /* packaged data |partX|partY|partWidth|partHeight|*/
+  u8 *pFill);
+#endif
+
+void h264bsdFillBlock(
+  u8 * ref,
+  u8 * fill,
+  i32 x0,
+  i32 y0,
+  u32 width,
+  u32 height,
+  u32 blockWidth,
+  u32 blockHeight,
+  u32 fillScanLength);
+
+void h264bsdInterpolateChromaHor(
+  u8 *pRef,
+  u8 *predPartChroma,
+  i32 x0,
+  i32 y0,
+  u32 width,
+  u32 height,
+  u32 xFrac,
+  u32 chromaPartWidth,
+  u32 chromaPartHeight);
+
+void h264bsdInterpolateChromaVer(
+  u8 *pRef,
+  u8 *predPartChroma,
+  i32 x0,
+  i32 y0,
+  u32 width,
+  u32 height,
+  u32 yFrac,
+  u32 chromaPartWidth,
+  u32 chromaPartHeight);
+
+void h264bsdInterpolateChromaHorVer(
+  u8 *ref,
+  u8 *predPartChroma,
+  i32 x0,
+  i32 y0,
+  u32 width,
+  u32 height,
+  u32 xFrac,
+  u32 yFrac,
+  u32 chromaPartWidth,
+  u32 chromaPartHeight);
+
+void h264bsdInterpolateVerHalf(
+  u8 *ref,
+  u8 *mb,
+  i32 x0,
+  i32 y0,
+  u32 width,
+  u32 height,
+  u32 partWidth,
+  u32 partHeight);
+
+void h264bsdInterpolateVerQuarter(
+  u8 *ref,
+  u8 *mb,
+  i32 x0,
+  i32 y0,
+  u32 width,
+  u32 height,
+  u32 partWidth,
+  u32 partHeight,
+  u32 verOffset);
+
+void h264bsdInterpolateHorHalf(
+  u8 *ref,
+  u8 *mb,
+  i32 x0,
+  i32 y0,
+  u32 width,
+  u32 height,
+  u32 partWidth,
+  u32 partHeight);
+
+void h264bsdInterpolateHorQuarter(
+  u8 *ref,
+  u8 *mb,
+  i32 x0,
+  i32 y0,
+  u32 width,
+  u32 height,
+  u32 partWidth,
+  u32 partHeight,
+  u32 horOffset);
+
+void h264bsdInterpolateHorVerQuarter(
+  u8 *ref,
+  u8 *mb,
+  i32 x0,
+  i32 y0,
+  u32 width,
+  u32 height,
+  u32 partWidth,
+  u32 partHeight,
+  u32 horVerOffset);
+
+void h264bsdInterpolateMidHalf(
+  u8 *ref,
+  u8 *mb,
+  i32 x0,
+  i32 y0,
+  u32 width,
+  u32 height,
+  u32 partWidth,
+  u32 partHeight);
+
+void h264bsdInterpolateMidVerQuarter(
+  u8 *ref,
+  u8 *mb,
+  i32 x0,
+  i32 y0,
+  u32 width,
+  u32 height,
+  u32 partWidth,
+  u32 partHeight,
+  u32 verOffset);
+
+void h264bsdInterpolateMidHorQuarter(
+  u8 *ref,
+  u8 *mb,
+  i32 x0,
+  i32 y0,
+  u32 width,
+  u32 height,
+  u32 partWidth,
+  u32 partHeight,
+  u32 horOffset);
+
+
+void h264bsdFillRow7(
+  u8 *ref,
+  u8 *fill,
+  i32 left,
+  i32 center,
+  i32 right);
+
+#endif /* #ifdef H264SWDEC_RECONSTRUCT_H */
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_sei.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_sei.c
new file mode 100755
index 0000000..0756c47
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_sei.c
@@ -0,0 +1,1692 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+     1. Include headers
+     2. External compiler flags
+     3. Module defines
+     4. Local function prototypes
+     5. Functions
+          h264bsdDecodeSeiMessage
+          DecodeBufferingPeriod
+          DecodePictureTiming
+          DecodePanScanRectangle
+          DecodeFillerPayload
+          DecodeUserDataRegisteredITuTT35
+          DecodeUserDataUnregistered
+          DecodeRecoveryPoint
+          DecodeDecRefPicMarkingRepetition
+          DecodeSparePic
+          DecodeSceneInfo
+          DecodeSubSeqInfo
+          DecodeSubSeqLayerCharacteristics
+          DecodeSubSeqCharacteristics
+          DecodeFullFrameFreeze
+          DecodeFullFrameSnapshot
+          DecodeProgressiveRefinementSegmentStart
+          DecodeProgressiveRefinementSegmentEnd
+          DecodeMotionConstrainedSliceGroupSet
+          DecodeReservedSeiMessage
+
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "h264bsd_sei.h"
+#include "basetype.h"
+#include "h264bsd_util.h"
+#include "h264bsd_stream.h"
+#include "h264bsd_vlc.h"
+#include "h264bsd_seq_param_set.h"
+#include "h264bsd_slice_header.h"
+
+/*------------------------------------------------------------------------------
+    2. External compiler flags
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+    3. Module defines
+------------------------------------------------------------------------------*/
+
+static const u32 numClockTS[9] = {1,1,1,2,2,3,3,2,3};
+static const u32 ceilLog2NumSliceGroups[9] = {0,1,1,2,2,3,3,3,3};
+
+/*------------------------------------------------------------------------------
+    4. Local function prototypes
+------------------------------------------------------------------------------*/
+
+static u32 DecodeBufferingPeriod(
+  strmData_t *pStrmData,
+  seiBufferingPeriod_t *pBufferingPeriod,
+  u32 cpbCnt,
+  u32 initialCpbRemovalDelayLength,
+  u32 nalHrdBpPresentFlag,
+  u32 vclHrdBpPresentFlag);
+
+static u32 DecodePictureTiming(
+  strmData_t *pStrmData,
+  seiPicTiming_t *pPicTiming,
+  u32 cpbRemovalDelayLength,
+  u32 dpbOutputDelayLength,
+  u32 timeOffsetLength,
+  u32 cpbDpbDelaysPresentFlag,
+  u32 picStructPresentFlag);
+
+static u32 DecodePanScanRectangle(
+  strmData_t *pStrmData,
+  seiPanScanRect_t *pPanScanRectangle);
+
+static u32 DecodeFillerPayload(strmData_t *pStrmData, u32 payloadSize);
+
+static u32 DecodeUserDataRegisteredITuTT35(
+  strmData_t *pStrmData,
+  seiUserDataRegisteredItuTT35_t *pUserDataRegisteredItuTT35,
+  u32 payloadSize);
+
+static u32 DecodeUserDataUnregistered(
+  strmData_t *pStrmData,
+  seiUserDataUnregistered_t *pUserDataUnregistered,
+  u32 payloadSize);
+
+static u32 DecodeRecoveryPoint(
+  strmData_t *pStrmData,
+  seiRecoveryPoint_t *pRecoveryPoint);
+
+static u32 DecodeDecRefPicMarkingRepetition(
+  strmData_t *pStrmData,
+  seiDecRefPicMarkingRepetition_t *pDecRefPicMarkingRepetition,
+  u32 numRefFrames);
+
+static u32 DecodeSparePic(
+  strmData_t *pStrmData,
+  seiSparePic_t *pSparePic,
+  u32 picSizeInMapUnits);
+
+static u32 DecodeSceneInfo(
+  strmData_t *pStrmData,
+  seiSceneInfo_t *pSceneInfo);
+
+static u32 DecodeSubSeqInfo(
+  strmData_t *pStrmData,
+  seiSubSeqInfo_t *pSubSeqInfo);
+
+static u32 DecodeSubSeqLayerCharacteristics(
+  strmData_t *pStrmData,
+  seiSubSeqLayerCharacteristics_t *pSubSeqLayerCharacteristics);
+
+static u32 DecodeSubSeqCharacteristics(
+  strmData_t *pStrmData,
+  seiSubSeqCharacteristics_t *pSubSeqCharacteristics);
+
+static u32 DecodeFullFrameFreeze(
+  strmData_t *pStrmData,
+  seiFullFrameFreeze_t *pFullFrameFreeze);
+
+static u32 DecodeFullFrameSnapshot(
+  strmData_t *pStrmData,
+  seiFullFrameSnapshot_t *pFullFrameSnapshot);
+
+static u32 DecodeProgressiveRefinementSegmentStart(
+  strmData_t *pStrmData,
+  seiProgressiveRefinementSegmentStart_t *pProgressiveRefinementSegmentStart);
+
+static u32 DecodeProgressiveRefinementSegmentEnd(
+  strmData_t *pStrmData,
+  seiProgressiveRefinementSegmentEnd_t *pProgressiveRefinementSegmentEnd);
+
+static u32 DecodeMotionConstrainedSliceGroupSet(
+  strmData_t *pStrmData,
+  seiMotionConstrainedSliceGroupSet_t *pMotionConstrainedSliceGroupSet,
+  u32 numSliceGroups);
+
+static u32 DecodeReservedSeiMessage(
+  strmData_t *pStrmData,
+  seiReservedSeiMessage_t *pReservedSeiMessage,
+  u32 payloadSize);
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdDecodeSeiMessage
+
+        Functional description:
+          <++>
+        Inputs:
+          <++>
+        Outputs:
+          <++>
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdDecodeSeiMessage(
+  strmData_t *pStrmData,
+  seqParamSet_t *pSeqParamSet,
+  seiMessage_t *pSeiMessage,
+  u32 numSliceGroups)
+{
+
+/* Variables */
+
+    u32 tmp, payloadType, payloadSize, status;
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(pSeiMessage);
+
+
+    H264SwDecMemset(pSeiMessage, 0, sizeof(seiMessage_t));
+
+    do
+    {
+        payloadType = 0;
+        while((tmp = h264bsdGetBits(pStrmData, 8)) == 0xFF)
+        {
+            payloadType += 255;
+                    }
+        if (tmp == END_OF_STREAM)
+            return(HANTRO_NOK);
+        payloadType += tmp;
+
+        payloadSize = 0;
+        while((tmp = h264bsdGetBits(pStrmData, 8)) == 0xFF)
+        {
+            payloadSize += 255;
+        }
+        if (tmp == END_OF_STREAM)
+            return(HANTRO_NOK);
+        payloadSize += tmp;
+
+        pSeiMessage->payloadType = payloadType;
+
+        switch (payloadType)
+        {
+            case 0:
+                ASSERT(pSeqParamSet);
+                status = DecodeBufferingPeriod(
+                  pStrmData,
+                  &pSeiMessage->bufferingPeriod,
+                  pSeqParamSet->vuiParameters->vclHrdParameters.cpbCnt,
+                  pSeqParamSet->vuiParameters->vclHrdParameters.
+                  initialCpbRemovalDelayLength,
+                  pSeqParamSet->vuiParameters->nalHrdParametersPresentFlag,
+                  pSeqParamSet->vuiParameters->vclHrdParametersPresentFlag);
+                break;
+
+            case 1:
+                ASSERT(pSeqParamSet->vuiParametersPresentFlag);
+                status = DecodePictureTiming(
+                  pStrmData,
+                  &pSeiMessage->picTiming,
+                  pSeqParamSet->vuiParameters->vclHrdParameters.
+                      cpbRemovalDelayLength,
+                  pSeqParamSet->vuiParameters->vclHrdParameters.
+                      dpbOutputDelayLength,
+                  pSeqParamSet->vuiParameters->vclHrdParameters.
+                    timeOffsetLength,
+                  pSeqParamSet->vuiParameters->nalHrdParametersPresentFlag ||
+                  pSeqParamSet->vuiParameters->vclHrdParametersPresentFlag ?
+                  HANTRO_TRUE : HANTRO_FALSE,
+                  pSeqParamSet->vuiParameters->picStructPresentFlag);
+                break;
+
+            case 2:
+                status = DecodePanScanRectangle(
+                  pStrmData,
+                  &pSeiMessage->panScanRect);
+                break;
+
+            case 3:
+                status = DecodeFillerPayload(pStrmData, payloadSize);
+                break;
+
+            case 4:
+                status = DecodeUserDataRegisteredITuTT35(
+                  pStrmData,
+                  &pSeiMessage->userDataRegisteredItuTT35,
+                  payloadSize);
+                break;
+
+            case 5:
+                status = DecodeUserDataUnregistered(
+                  pStrmData,
+                  &pSeiMessage->userDataUnregistered,
+                  payloadSize);
+                break;
+
+            case 6:
+                status = DecodeRecoveryPoint(
+                  pStrmData,
+                  &pSeiMessage->recoveryPoint);
+                break;
+
+            case 7:
+                status = DecodeDecRefPicMarkingRepetition(
+                  pStrmData,
+                  &pSeiMessage->decRefPicMarkingRepetition,
+                  pSeqParamSet->numRefFrames);
+                break;
+
+            case 8:
+                ASSERT(pSeqParamSet);
+                status = DecodeSparePic(
+                  pStrmData,
+                  &pSeiMessage->sparePic,
+                  pSeqParamSet->picWidthInMbs * pSeqParamSet->picHeightInMbs);
+                break;
+
+            case 9:
+                status = DecodeSceneInfo(
+                  pStrmData,
+                  &pSeiMessage->sceneInfo);
+                break;
+
+            case 10:
+                status = DecodeSubSeqInfo(
+                  pStrmData,
+                  &pSeiMessage->subSeqInfo);
+                break;
+
+            case 11:
+                status = DecodeSubSeqLayerCharacteristics(
+                  pStrmData,
+                  &pSeiMessage->subSeqLayerCharacteristics);
+                break;
+
+            case 12:
+                status = DecodeSubSeqCharacteristics(
+                  pStrmData,
+                  &pSeiMessage->subSeqCharacteristics);
+                break;
+
+            case 13:
+                status = DecodeFullFrameFreeze(
+                  pStrmData,
+                  &pSeiMessage->fullFrameFreeze);
+                break;
+
+            case 14: /* This SEI does not contain data, what to do ??? */
+                status = HANTRO_OK;
+                break;
+
+            case 15:
+                status = DecodeFullFrameSnapshot(
+                  pStrmData,
+                  &pSeiMessage->fullFrameSnapshot);
+                break;
+
+            case 16:
+                status = DecodeProgressiveRefinementSegmentStart(
+                  pStrmData,
+                  &pSeiMessage->progressiveRefinementSegmentStart);
+                break;
+
+            case 17:
+                status = DecodeProgressiveRefinementSegmentEnd(
+                  pStrmData,
+                  &pSeiMessage->progressiveRefinementSegmentEnd);
+                break;
+
+            case 18:
+                ASSERT(numSliceGroups);
+                status = DecodeMotionConstrainedSliceGroupSet(
+                  pStrmData,
+                  &pSeiMessage->motionConstrainedSliceGroupSet,
+                  numSliceGroups);
+                break;
+
+            default:
+                status = DecodeReservedSeiMessage(
+                  pStrmData,
+                  &pSeiMessage->reservedSeiMessage,
+                  payloadSize);
+                break;
+        }
+
+        if (status != HANTRO_OK)
+            return(status);
+
+        while (!h264bsdIsByteAligned(pStrmData))
+        {
+            if (h264bsdGetBits(pStrmData, 1) != 1)
+                return(HANTRO_NOK);
+            while (!h264bsdIsByteAligned(pStrmData))
+            {
+                if (h264bsdGetBits(pStrmData, 1) != 0)
+                    return(HANTRO_NOK);
+            }
+        }
+    } while (h264bsdMoreRbspData(pStrmData));
+
+    return(h264bsdRbspTrailingBits(pStrmData));
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: DecodeBufferingPeriod
+
+        Functional description:
+          <++>
+        Inputs:
+          <++>
+        Outputs:
+          <++>
+
+------------------------------------------------------------------------------*/
+
+static u32 DecodeBufferingPeriod(
+  strmData_t *pStrmData,
+  seiBufferingPeriod_t *pBufferingPeriod,
+  u32 cpbCnt,
+  u32 initialCpbRemovalDelayLength,
+  u32 nalHrdBpPresentFlag,
+  u32 vclHrdBpPresentFlag)
+{
+
+/* Variables */
+
+    u32 tmp, i;
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(pBufferingPeriod);
+    ASSERT(cpbCnt);
+    ASSERT(initialCpbRemovalDelayLength);
+
+
+    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+      &pBufferingPeriod->seqParameterSetId);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+    if (pBufferingPeriod->seqParameterSetId > 31)
+        return(HANTRO_NOK);
+
+    if (nalHrdBpPresentFlag)
+    {
+        for (i = 0; i < cpbCnt; i++)
+        {
+            tmp = h264bsdGetBits(pStrmData, initialCpbRemovalDelayLength);
+            if (tmp == END_OF_STREAM)
+                return(HANTRO_NOK);
+            if (tmp == 0)
+                return(HANTRO_NOK);
+            pBufferingPeriod->initialCpbRemovalDelay[i] = tmp;
+
+            tmp = h264bsdGetBits(pStrmData, initialCpbRemovalDelayLength);
+            if (tmp == END_OF_STREAM)
+                return(HANTRO_NOK);
+            pBufferingPeriod->initialCpbRemovalDelayOffset[i] = tmp;
+        }
+    }
+
+    if (vclHrdBpPresentFlag)
+    {
+        for (i = 0; i < cpbCnt; i++)
+        {
+            tmp = h264bsdGetBits(pStrmData, initialCpbRemovalDelayLength);
+            if (tmp == END_OF_STREAM)
+                return(HANTRO_NOK);
+            pBufferingPeriod->initialCpbRemovalDelay[i] = tmp;
+
+            tmp = h264bsdGetBits(pStrmData, initialCpbRemovalDelayLength);
+            if (tmp == END_OF_STREAM)
+                return(HANTRO_NOK);
+            pBufferingPeriod->initialCpbRemovalDelayOffset[i] = tmp;
+        }
+    }
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: DecodePictureTiming
+
+        Functional description:
+          <++>
+        Inputs:
+          <++>
+        Outputs:
+          <++>
+
+------------------------------------------------------------------------------*/
+
+static u32 DecodePictureTiming(
+  strmData_t *pStrmData,
+  seiPicTiming_t *pPicTiming,
+  u32 cpbRemovalDelayLength,
+  u32 dpbOutputDelayLength,
+  u32 timeOffsetLength,
+  u32 cpbDpbDelaysPresentFlag,
+  u32 picStructPresentFlag)
+{
+
+/* Variables */
+
+    u32 tmp, i;
+    i32 itmp;
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(pPicTiming);
+
+
+    if (cpbDpbDelaysPresentFlag)
+    {
+        tmp = h264bsdGetBits(pStrmData, cpbRemovalDelayLength);
+        if (tmp == END_OF_STREAM)
+            return(HANTRO_NOK);
+        pPicTiming->cpbRemovalDelay = tmp;
+
+        tmp = h264bsdGetBits(pStrmData, dpbOutputDelayLength);
+        if (tmp == END_OF_STREAM)
+            return(HANTRO_NOK);
+        pPicTiming->dpbOutputDelay = tmp;
+    }
+
+    if (picStructPresentFlag)
+    {
+        tmp = h264bsdGetBits(pStrmData, 4);
+        if (tmp == END_OF_STREAM)
+            return(HANTRO_NOK);
+        if (tmp > 8)
+            return(HANTRO_NOK);
+        pPicTiming->picStruct = tmp;
+
+        for (i = 0; i < numClockTS[pPicTiming->picStruct]; i++)
+        {
+            tmp = h264bsdGetBits(pStrmData, 1);
+            if (tmp == END_OF_STREAM)
+                return(HANTRO_NOK);
+            pPicTiming->clockTimeStampFlag[i] = tmp == 1 ?
+                                    HANTRO_TRUE : HANTRO_FALSE;
+
+            if (pPicTiming->clockTimeStampFlag[i])
+            {
+                tmp = h264bsdGetBits(pStrmData, 2);
+                if (tmp == END_OF_STREAM)
+                    return(HANTRO_NOK);
+                pPicTiming->ctType[i] = tmp;
+
+                tmp = h264bsdGetBits(pStrmData, 1);
+                if (tmp == END_OF_STREAM)
+                    return(HANTRO_NOK);
+                pPicTiming->nuitFieldBasedFlag[i] = tmp == 1 ?
+                                    HANTRO_TRUE : HANTRO_FALSE;
+
+                tmp = h264bsdGetBits(pStrmData, 5);
+                if (tmp == END_OF_STREAM)
+                    return(HANTRO_NOK);
+                if (tmp > 6)
+                    return(HANTRO_NOK);
+                pPicTiming->countingType[i] = tmp;
+
+                tmp = h264bsdGetBits(pStrmData, 1);
+                if (tmp == END_OF_STREAM)
+                    return(HANTRO_NOK);
+                pPicTiming->fullTimeStampFlag[i] = tmp == 1 ?
+                                    HANTRO_TRUE : HANTRO_FALSE;
+
+                tmp = h264bsdGetBits(pStrmData, 1);
+                if (tmp == END_OF_STREAM)
+                    return(HANTRO_NOK);
+                pPicTiming->discontinuityFlag[i] = tmp == 1 ?
+                                    HANTRO_TRUE : HANTRO_FALSE;
+
+                tmp = h264bsdGetBits(pStrmData, 1);
+                if (tmp == END_OF_STREAM)
+                    return(HANTRO_NOK);
+                pPicTiming->cntDroppedFlag[i] = tmp == 1 ?
+                                    HANTRO_TRUE : HANTRO_FALSE;
+
+                tmp = h264bsdGetBits(pStrmData, 8);
+                if (tmp == END_OF_STREAM)
+                    return(HANTRO_NOK);
+                pPicTiming->nFrames[i] = tmp;
+
+                if (pPicTiming->fullTimeStampFlag[i])
+                {
+                    tmp = h264bsdGetBits(pStrmData, 6);
+                    if (tmp == END_OF_STREAM)
+                        return(HANTRO_NOK);
+                    if (tmp > 59)
+                        return(HANTRO_NOK);
+                    pPicTiming->secondsValue[i] = tmp;
+
+                    tmp = h264bsdGetBits(pStrmData, 6);
+                    if (tmp == END_OF_STREAM)
+                        return(HANTRO_NOK);
+                    if (tmp > 59)
+                        return(HANTRO_NOK);
+                    pPicTiming->minutesValue[i] = tmp;
+
+                    tmp = h264bsdGetBits(pStrmData, 5);
+                    if (tmp == END_OF_STREAM)
+                        return(HANTRO_NOK);
+                    if (tmp > 23)
+                        return(HANTRO_NOK);
+                    pPicTiming->hoursValue[i] = tmp;
+                }
+                else
+                {
+                    tmp = h264bsdGetBits(pStrmData, 1);
+                    if (tmp == END_OF_STREAM)
+                        return(HANTRO_NOK);
+                    pPicTiming->secondsFlag[i] = tmp == 1 ?
+                                    HANTRO_TRUE : HANTRO_FALSE;
+
+                    if (pPicTiming->secondsFlag[i])
+                    {
+                        tmp = h264bsdGetBits(pStrmData, 6);
+                        if (tmp == END_OF_STREAM)
+                            return(HANTRO_NOK);
+                        if (tmp > 59)
+                            return(HANTRO_NOK);
+                        pPicTiming->secondsValue[i] = tmp;
+
+                        tmp = h264bsdGetBits(pStrmData, 1);
+                        if (tmp == END_OF_STREAM)
+                            return(HANTRO_NOK);
+                        pPicTiming->minutesFlag[i] = tmp == 1 ?
+                                    HANTRO_TRUE : HANTRO_FALSE;
+
+                        if (pPicTiming->minutesFlag[i])
+                        {
+                            tmp = h264bsdGetBits(pStrmData, 6);
+                            if (tmp == END_OF_STREAM)
+                                return(HANTRO_NOK);
+                            if (tmp > 59)
+                                return(HANTRO_NOK);
+                            pPicTiming->minutesValue[i] = tmp;
+
+                            tmp = h264bsdGetBits(pStrmData, 1);
+                            if (tmp == END_OF_STREAM)
+                                return(HANTRO_NOK);
+                            pPicTiming->hoursFlag[i] = tmp == 1 ?
+                                    HANTRO_TRUE : HANTRO_FALSE;
+
+                            if (pPicTiming->hoursFlag[i])
+                            {
+                                tmp = h264bsdGetBits(pStrmData, 5);
+                                if (tmp == END_OF_STREAM)
+                                    return(HANTRO_NOK);
+                                if (tmp > 23)
+                                    return(HANTRO_NOK);
+                                pPicTiming->hoursValue[i] = tmp;
+                            }
+                        }
+                    }
+                }
+                if (timeOffsetLength)
+                {
+                    tmp = h264bsdGetBits(pStrmData, timeOffsetLength);
+                    if (tmp == END_OF_STREAM)
+                        return(HANTRO_NOK);
+                    itmp = (i32)tmp;
+                    /* following "converts" timeOffsetLength-bit signed
+                     * integer into i32 */
+                    /*lint -save -e701 -e702 */
+                    itmp <<= (32 - timeOffsetLength);
+                    itmp >>= (32 - timeOffsetLength);
+                    /*lint -restore */
+                    pPicTiming->timeOffset[i] = itmp;
+                                    }
+                else
+                    pPicTiming->timeOffset[i] = 0;
+            }
+        }
+    }
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: DecodePanScanRectangle
+
+        Functional description:
+          <++>
+        Inputs:
+          <++>
+        Outputs:
+          <++>
+
+------------------------------------------------------------------------------*/
+
+static u32 DecodePanScanRectangle(
+  strmData_t *pStrmData,
+  seiPanScanRect_t *pPanScanRectangle)
+{
+
+/* Variables */
+
+    u32 tmp, i;
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(pPanScanRectangle);
+
+
+    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+      &pPanScanRectangle->panScanRectId);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+
+    tmp = h264bsdGetBits(pStrmData, 1);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    pPanScanRectangle->panScanRectCancelFlag = tmp == 1 ?
+                                HANTRO_TRUE : HANTRO_FALSE;
+
+    if (!pPanScanRectangle->panScanRectCancelFlag)
+    {
+        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+          &pPanScanRectangle->panScanCnt);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+        if (pPanScanRectangle->panScanCnt > 2)
+            return(HANTRO_NOK);
+        pPanScanRectangle->panScanCnt++;
+
+        for (i = 0; i < pPanScanRectangle->panScanCnt; i++)
+        {
+            tmp = h264bsdDecodeExpGolombSigned(pStrmData,
+              &pPanScanRectangle->panScanRectLeftOffset[i]);
+            if (tmp != HANTRO_OK)
+                return(tmp);
+
+            tmp = h264bsdDecodeExpGolombSigned(pStrmData,
+              &pPanScanRectangle->panScanRectRightOffset[i]);
+            if (tmp != HANTRO_OK)
+                return(tmp);
+
+            tmp = h264bsdDecodeExpGolombSigned(pStrmData,
+              &pPanScanRectangle->panScanRectTopOffset[i]);
+            if (tmp != HANTRO_OK)
+                return(tmp);
+
+            tmp = h264bsdDecodeExpGolombSigned(pStrmData,
+              &pPanScanRectangle->panScanRectBottomOffset[i]);
+            if (tmp != HANTRO_OK)
+                return(tmp);
+        }
+        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+          &pPanScanRectangle->panScanRectRepetitionPeriod);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+        if (pPanScanRectangle->panScanRectRepetitionPeriod > 16384)
+            return(HANTRO_NOK);
+        if (pPanScanRectangle->panScanCnt > 1 &&
+          pPanScanRectangle->panScanRectRepetitionPeriod > 1)
+            return(HANTRO_NOK);
+    }
+
+    return(HANTRO_OK);
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: DecodeFillerPayload
+
+        Functional description:
+          <++>
+        Inputs:
+          <++>
+        Outputs:
+          <++>
+
+------------------------------------------------------------------------------*/
+
+static u32 DecodeFillerPayload(strmData_t *pStrmData, u32 payloadSize)
+{
+
+/* Variables */
+
+/* Code */
+
+    ASSERT(pStrmData);
+
+
+    if (payloadSize)
+        if (h264bsdFlushBits(pStrmData, 8 * payloadSize) == END_OF_STREAM)
+            return(HANTRO_NOK);
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: DecodeUserDataRegisteredITuTT35
+
+        Functional description:
+          <++>
+        Inputs:
+          <++>
+        Outputs:
+          <++>
+
+------------------------------------------------------------------------------*/
+
+static u32 DecodeUserDataRegisteredITuTT35(
+  strmData_t *pStrmData,
+  seiUserDataRegisteredItuTT35_t *pUserDataRegisteredItuTT35,
+  u32 payloadSize)
+{
+
+/* Variables */
+
+    u32 tmp, i, j;
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(pUserDataRegisteredItuTT35);
+    ASSERT(payloadSize);
+
+        tmp = h264bsdGetBits(pStrmData, 8);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    pUserDataRegisteredItuTT35->ituTT35CountryCode = tmp;
+
+    if (pUserDataRegisteredItuTT35->ituTT35CountryCode != 0xFF)
+        i = 1;
+    else
+    {
+        tmp = h264bsdGetBits(pStrmData, 8);
+        if (tmp == END_OF_STREAM)
+            return(HANTRO_NOK);
+        pUserDataRegisteredItuTT35->ituTT35CountryCodeExtensionByte = tmp;
+        i = 2;
+    }
+
+    /* where corresponding FREE() ??? */
+    ALLOCATE(pUserDataRegisteredItuTT35->ituTT35PayloadByte,payloadSize-i,u8);
+    pUserDataRegisteredItuTT35->numPayloadBytes = payloadSize - i;
+    if (pUserDataRegisteredItuTT35->ituTT35PayloadByte == NULL)
+        return(MEMORY_ALLOCATION_ERROR);
+
+    j = 0;
+    do
+    {
+        tmp = h264bsdGetBits(pStrmData, 8);
+        if (tmp == END_OF_STREAM)
+            return(HANTRO_NOK);
+        pUserDataRegisteredItuTT35->ituTT35PayloadByte[j] = (u8)tmp;
+        i++;
+        j++;
+    } while (i < payloadSize);
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: DecodeUserDataUnregistered
+
+        Functional description:
+          <++>
+        Inputs:
+          <++>
+        Outputs:
+          <++>
+
+------------------------------------------------------------------------------*/
+
+static u32 DecodeUserDataUnregistered(
+  strmData_t *pStrmData,
+  seiUserDataUnregistered_t *pUserDataUnregistered,
+  u32 payloadSize)
+{
+
+/* Variables */
+
+    u32 i, tmp;
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(pUserDataUnregistered);
+
+
+    for (i = 0; i < 4; i++)
+    {
+        pUserDataUnregistered->uuidIsoIec11578[i] = h264bsdShowBits32(pStrmData);
+        if (h264bsdFlushBits(pStrmData,32) == END_OF_STREAM)
+            return(HANTRO_NOK);
+    }
+
+    /* where corresponding FREE() ??? */
+    ALLOCATE(pUserDataUnregistered->userDataPayloadByte, payloadSize - 16, u8);
+    if (pUserDataUnregistered->userDataPayloadByte == NULL)
+        return(MEMORY_ALLOCATION_ERROR);
+
+    pUserDataUnregistered->numPayloadBytes = payloadSize - 16;
+
+    for (i = 0; i < payloadSize - 16; i++)
+    {
+        tmp = h264bsdGetBits(pStrmData, 8);
+        if (tmp == END_OF_STREAM)
+            return(HANTRO_NOK);
+        pUserDataUnregistered->userDataPayloadByte[i] = (u8)tmp;
+    }
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: DecodeRecoveryPoint
+
+        Functional description:
+          <++>
+        Inputs:
+          <++>
+        Outputs:
+          <++>
+
+------------------------------------------------------------------------------*/
+
+static u32 DecodeRecoveryPoint(
+  strmData_t *pStrmData,
+  seiRecoveryPoint_t *pRecoveryPoint)
+{
+
+/* Variables */
+
+    u32 tmp;
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(pRecoveryPoint);
+
+
+    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+        &pRecoveryPoint->recoveryFrameCnt);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+
+    tmp = h264bsdGetBits(pStrmData, 1);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    pRecoveryPoint->exactMatchFlag = tmp == 1 ? HANTRO_TRUE : HANTRO_FALSE;
+
+    tmp = h264bsdGetBits(pStrmData, 1);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    pRecoveryPoint->brokenLinkFlag = tmp == 1 ? HANTRO_TRUE : HANTRO_FALSE;
+
+    tmp = h264bsdGetBits(pStrmData, 2);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    if (tmp > 2)
+        return(HANTRO_NOK);
+    pRecoveryPoint->changingSliceGroupIdc = tmp;
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: DecodeDecRefPicMarkingRepetition
+
+        Functional description:
+          <++>
+        Inputs:
+          <++>
+        Outputs:
+          <++>
+
+------------------------------------------------------------------------------*/
+
+static u32 DecodeDecRefPicMarkingRepetition(
+  strmData_t *pStrmData,
+  seiDecRefPicMarkingRepetition_t *pDecRefPicMarkingRepetition,
+  u32 numRefFrames)
+{
+
+/* Variables */
+
+    u32 tmp;
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(pDecRefPicMarkingRepetition);
+
+
+    tmp = h264bsdGetBits(pStrmData, 1);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    pDecRefPicMarkingRepetition->originalIdrFlag = tmp == 1 ? HANTRO_TRUE : HANTRO_FALSE;
+
+    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+      &pDecRefPicMarkingRepetition->originalFrameNum);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+
+    /* frame_mbs_only_flag assumed always true so some field related syntax
+     * elements are skipped, see H.264 standard */
+    tmp = h264bsdDecRefPicMarking(pStrmData,
+      &pDecRefPicMarkingRepetition->decRefPicMarking, NAL_SEI, numRefFrames);
+
+    return(tmp);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: DecodeSparePic
+
+        Functional description:
+          <++>
+        Inputs:
+          <++>
+        Outputs:
+          <++>
+
+------------------------------------------------------------------------------*/
+
+static u32 DecodeSparePic(
+  strmData_t *pStrmData,
+  seiSparePic_t *pSparePic,
+  u32 picSizeInMapUnits)
+{
+
+/* Variables */
+
+    u32 tmp, i, j, mapUnitCnt;
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(pSparePic);
+
+
+    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+        &pSparePic->targetFrameNum);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+
+    tmp = h264bsdGetBits(pStrmData, 1);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    pSparePic->spareFieldFlag = tmp == 1 ? HANTRO_TRUE : HANTRO_FALSE;
+    /* do not accept fields */
+    if (pSparePic->spareFieldFlag)
+        return(HANTRO_NOK);
+
+    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &pSparePic->numSparePics);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+    pSparePic->numSparePics++;
+    if (pSparePic->numSparePics > MAX_NUM_SPARE_PICS)
+        return(HANTRO_NOK);
+
+    for (i = 0; i < pSparePic->numSparePics; i++)
+    {
+        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+          &pSparePic->deltaSpareFrameNum[i]);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+
+        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+            &pSparePic->spareAreaIdc[i]);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+        if (pSparePic->spareAreaIdc[i] > 2)
+            return(HANTRO_NOK);
+
+        if (pSparePic->spareAreaIdc[i] == 1)
+        {
+            /* where corresponding FREE() ??? */
+            ALLOCATE(pSparePic->spareUnitFlag[i], picSizeInMapUnits, u32);
+            if (pSparePic->spareUnitFlag[i] == NULL)
+                return(MEMORY_ALLOCATION_ERROR);
+            pSparePic->zeroRunLength[i] = NULL;
+
+            for (j = 0; j < picSizeInMapUnits; j++)
+            {
+                tmp = h264bsdGetBits(pStrmData, 1);
+                if (tmp == END_OF_STREAM)
+                    return(HANTRO_NOK);
+                pSparePic->spareUnitFlag[i][j] = tmp == 1 ?
+                                    HANTRO_TRUE : HANTRO_FALSE;
+            }
+        }
+        else if (pSparePic->spareAreaIdc[i] == 2)
+        {
+            /* where corresponding FREE() ??? */
+            ALLOCATE(pSparePic->zeroRunLength[i], picSizeInMapUnits, u32);
+            if (pSparePic->zeroRunLength[i] == NULL)
+                return(MEMORY_ALLOCATION_ERROR);
+            pSparePic->spareUnitFlag[i] = NULL;
+
+            for (j = 0, mapUnitCnt = 0; mapUnitCnt < picSizeInMapUnits; j++)
+            {
+                tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+                  &pSparePic->zeroRunLength[i][j]);
+                if (tmp != HANTRO_OK)
+                    return(tmp);
+                mapUnitCnt += pSparePic->zeroRunLength[i][j] + 1;
+            }
+        }
+    }
+
+    /* set rest to null */
+    for (i = pSparePic->numSparePics; i < MAX_NUM_SPARE_PICS; i++)
+    {
+        pSparePic->spareUnitFlag[i] = NULL;
+        pSparePic->zeroRunLength[i] = NULL;
+    }
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: DecodeSceneInfo
+
+        Functional description:
+          <++>
+        Inputs:
+          <++>
+        Outputs:
+          <++>
+
+------------------------------------------------------------------------------*/
+
+static u32 DecodeSceneInfo(
+  strmData_t *pStrmData,
+  seiSceneInfo_t *pSceneInfo)
+{
+
+/* Variables */
+
+    u32 tmp;
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(pSceneInfo);
+
+
+    tmp = h264bsdGetBits(pStrmData, 1);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    pSceneInfo->sceneInfoPresentFlag = tmp == 1 ? HANTRO_TRUE : HANTRO_FALSE;
+
+    if (pSceneInfo->sceneInfoPresentFlag)
+    {
+        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &pSceneInfo->sceneId);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+
+        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+          &pSceneInfo->sceneTransitionType);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+        if (pSceneInfo->sceneTransitionType > 6)
+            return(HANTRO_NOK);
+
+        if (pSceneInfo->sceneTransitionType)
+        {
+            tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+              &pSceneInfo->secondSceneId);
+            if (tmp != HANTRO_OK)
+                return(tmp);
+        }
+
+    }
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: DecodeSubSeqInfo
+
+        Functional description:
+          <++>
+        Inputs:
+          <++>
+        Outputs:
+          <++>
+
+-----------------------------------------------------------------------------*/
+
+static u32 DecodeSubSeqInfo(
+  strmData_t *pStrmData,
+  seiSubSeqInfo_t *pSubSeqInfo)
+{
+
+/* Variables */
+
+    u32 tmp;
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(pSubSeqInfo);
+
+
+    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+        &pSubSeqInfo->subSeqLayerNum);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+    if (pSubSeqInfo->subSeqLayerNum > 255)
+        return(HANTRO_NOK);
+
+    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &pSubSeqInfo->subSeqId);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+    if (pSubSeqInfo->subSeqId > 65535)
+        return(HANTRO_NOK);
+
+    tmp = h264bsdGetBits(pStrmData, 1);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    pSubSeqInfo->firstRefPicFlag = tmp == 1 ? HANTRO_TRUE : HANTRO_FALSE;
+
+    tmp = h264bsdGetBits(pStrmData, 1);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    pSubSeqInfo->leadingNonRefPicFlag = tmp == 1 ? HANTRO_TRUE : HANTRO_FALSE;
+
+    tmp = h264bsdGetBits(pStrmData, 1);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    pSubSeqInfo->lastPicFlag = tmp == 1 ? HANTRO_TRUE : HANTRO_FALSE;
+
+    tmp = h264bsdGetBits(pStrmData, 1);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    pSubSeqInfo->subSeqFrameNumFlag = tmp == 1 ? HANTRO_TRUE : HANTRO_FALSE;
+
+    if (pSubSeqInfo->subSeqFrameNumFlag)
+    {
+        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+            &pSubSeqInfo->subSeqFrameNum);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+    }
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: DecodeSubSeqLayerCharacteristics
+
+        Functional description:
+          <++>
+        Inputs:
+          <++>
+        Outputs:
+          <++>
+
+------------------------------------------------------------------------------*/
+
+static u32 DecodeSubSeqLayerCharacteristics(
+  strmData_t *pStrmData,
+  seiSubSeqLayerCharacteristics_t *pSubSeqLayerCharacteristics)
+{
+
+/* Variables */
+
+    u32 tmp, i;
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(pSubSeqLayerCharacteristics);
+
+
+    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+      &pSubSeqLayerCharacteristics->numSubSeqLayers);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+    pSubSeqLayerCharacteristics->numSubSeqLayers++;
+    if (pSubSeqLayerCharacteristics->numSubSeqLayers > MAX_NUM_SUB_SEQ_LAYERS)
+        return(HANTRO_NOK);
+
+    for (i = 0; i < pSubSeqLayerCharacteristics->numSubSeqLayers; i++)
+    {
+        tmp = h264bsdGetBits(pStrmData, 1);
+        if (tmp == END_OF_STREAM)
+            return(HANTRO_NOK);
+        pSubSeqLayerCharacteristics->accurateStatisticsFlag[i] =
+            tmp == 1 ? HANTRO_TRUE : HANTRO_FALSE;
+
+        tmp = h264bsdGetBits(pStrmData, 16);
+        if (tmp == END_OF_STREAM)
+            return(HANTRO_NOK);
+        pSubSeqLayerCharacteristics->averageBitRate[i] = tmp;
+
+        tmp = h264bsdGetBits(pStrmData, 16);
+        if (tmp == END_OF_STREAM)
+            return(HANTRO_NOK);
+        pSubSeqLayerCharacteristics->averageFrameRate[i] = tmp;
+    }
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: DecodeSubSeqCharacteristics
+
+        Functional description:
+          <++>
+        Inputs:
+          <++>
+        Outputs:
+          <++>
+
+------------------------------------------------------------------------------*/
+
+static u32 DecodeSubSeqCharacteristics(
+  strmData_t *pStrmData,
+  seiSubSeqCharacteristics_t *pSubSeqCharacteristics)
+{
+
+/* Variables */
+
+    u32 tmp, i;
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(pSubSeqCharacteristics);
+
+
+    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+      &pSubSeqCharacteristics->subSeqLayerNum);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+    if (pSubSeqCharacteristics->subSeqLayerNum > MAX_NUM_SUB_SEQ_LAYERS-1)
+        return(HANTRO_NOK);
+
+    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+        &pSubSeqCharacteristics->subSeqId);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+    if (pSubSeqCharacteristics->subSeqId > 65535)
+        return(HANTRO_NOK);
+
+    tmp = h264bsdGetBits(pStrmData, 1);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    pSubSeqCharacteristics->durationFlag = tmp == 1 ?
+                            HANTRO_TRUE : HANTRO_FALSE;
+
+    if (pSubSeqCharacteristics->durationFlag)
+    {
+        pSubSeqCharacteristics->subSeqDuration = h264bsdShowBits32(pStrmData);
+        if (h264bsdFlushBits(pStrmData,32) == END_OF_STREAM)
+            return(HANTRO_NOK);
+    }
+
+    tmp = h264bsdGetBits(pStrmData, 1);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    pSubSeqCharacteristics->averageRateFlag = tmp == 1 ?
+                            HANTRO_TRUE : HANTRO_FALSE;
+
+    if (pSubSeqCharacteristics->averageRateFlag)
+    {
+        tmp = h264bsdGetBits(pStrmData, 1);
+        if (tmp == END_OF_STREAM)
+            return(HANTRO_NOK);
+        pSubSeqCharacteristics->accurateStatisticsFlag =
+            tmp == 1 ? HANTRO_TRUE : HANTRO_FALSE;
+
+        tmp = h264bsdGetBits(pStrmData, 16);
+        if (tmp == END_OF_STREAM)
+            return(HANTRO_NOK);
+        pSubSeqCharacteristics->averageBitRate = tmp;
+
+        tmp = h264bsdGetBits(pStrmData, 16);
+        if (tmp == END_OF_STREAM)
+            return(HANTRO_NOK);
+        pSubSeqCharacteristics->averageFrameRate = tmp;
+    }
+
+    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+      &pSubSeqCharacteristics->numReferencedSubseqs);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+    if (pSubSeqCharacteristics->numReferencedSubseqs > MAX_NUM_SUB_SEQ_LAYERS-1)
+        return(HANTRO_NOK);
+
+    for (i = 0; i < pSubSeqCharacteristics->numReferencedSubseqs; i++)
+    {
+        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+          &pSubSeqCharacteristics->refSubSeqLayerNum[i]);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+
+        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+          &pSubSeqCharacteristics->refSubSeqId[i]);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+
+        tmp = h264bsdGetBits(pStrmData, 1);
+        if (tmp == END_OF_STREAM)
+            return(HANTRO_NOK);
+        pSubSeqCharacteristics->refSubSeqDirection[i] = tmp;
+    }
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: DecodeFullFrameFreeze
+
+        Functional description:
+          <++>
+        Inputs:
+          <++>
+        Outputs:
+          <++>
+
+------------------------------------------------------------------------------*/
+
+static u32 DecodeFullFrameFreeze(
+  strmData_t *pStrmData,
+  seiFullFrameFreeze_t *pFullFrameFreeze)
+{
+
+/* Variables */
+
+    u32 tmp;
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(pFullFrameFreeze);
+
+
+    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+      &pFullFrameFreeze->fullFrameFreezeRepetitionPeriod);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+    if (pFullFrameFreeze->fullFrameFreezeRepetitionPeriod > 16384)
+        return(HANTRO_NOK);
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: DecodeFullFrameSnapshot
+
+        Functional description:
+          <++>
+        Inputs:
+          <++>
+        Outputs:
+          <++>
+
+------------------------------------------------------------------------------*/
+
+static u32 DecodeFullFrameSnapshot(
+  strmData_t *pStrmData,
+  seiFullFrameSnapshot_t *pFullFrameSnapshot)
+{
+
+/* Variables */
+
+    u32 tmp;
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(pFullFrameSnapshot);
+
+
+    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+        &pFullFrameSnapshot->snapShotId);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: DecodeProgressiveRefinementSegmentStart
+
+        Functional description:
+          <++>
+        Inputs:
+          <++>
+        Outputs:
+          <++>
+
+------------------------------------------------------------------------------*/
+
+static u32 DecodeProgressiveRefinementSegmentStart(
+  strmData_t *pStrmData,
+  seiProgressiveRefinementSegmentStart_t *pProgressiveRefinementSegmentStart)
+{
+
+/* Variables */
+
+    u32 tmp;
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(pProgressiveRefinementSegmentStart);
+
+
+    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+      &pProgressiveRefinementSegmentStart->progressiveRefinementId);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+
+    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+      &pProgressiveRefinementSegmentStart->numRefinementSteps);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+    pProgressiveRefinementSegmentStart->numRefinementSteps++;
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: DecodeProgressiveRefinementSegmentEnd
+
+        Functional description:
+          <++>
+        Inputs:
+          <++>
+        Outputs:
+          <++>
+
+------------------------------------------------------------------------------*/
+
+static u32 DecodeProgressiveRefinementSegmentEnd(
+  strmData_t *pStrmData,
+  seiProgressiveRefinementSegmentEnd_t *pProgressiveRefinementSegmentEnd)
+{
+
+/* Variables */
+
+    u32 tmp;
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(pProgressiveRefinementSegmentEnd);
+
+
+    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+      &pProgressiveRefinementSegmentEnd->progressiveRefinementId);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: DecodeMotionConstrainedSliceGroupSet
+
+        Functional description:
+          <++>
+        Inputs:
+          <++>
+        Outputs:
+          <++>
+
+------------------------------------------------------------------------------*/
+
+static u32 DecodeMotionConstrainedSliceGroupSet(
+  strmData_t *pStrmData,
+  seiMotionConstrainedSliceGroupSet_t *pMotionConstrainedSliceGroupSet,
+  u32 numSliceGroups)
+{
+
+/* Variables */
+
+    u32 tmp,i;
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(pMotionConstrainedSliceGroupSet);
+    ASSERT(numSliceGroups < MAX_NUM_SLICE_GROUPS);
+
+
+    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+      &pMotionConstrainedSliceGroupSet->numSliceGroupsInSet);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+    pMotionConstrainedSliceGroupSet->numSliceGroupsInSet++;
+    if (pMotionConstrainedSliceGroupSet->numSliceGroupsInSet > numSliceGroups)
+        return(HANTRO_NOK);
+
+    for (i = 0; i < pMotionConstrainedSliceGroupSet->numSliceGroupsInSet; i++)
+    {
+        tmp = h264bsdGetBits(pStrmData,
+            ceilLog2NumSliceGroups[numSliceGroups]);
+        if (tmp == END_OF_STREAM)
+            return(HANTRO_NOK);
+        pMotionConstrainedSliceGroupSet->sliceGroupId[i] = tmp;
+        if (pMotionConstrainedSliceGroupSet->sliceGroupId[i] >
+          pMotionConstrainedSliceGroupSet->numSliceGroupsInSet-1)
+            return(HANTRO_NOK);
+    }
+
+    tmp = h264bsdGetBits(pStrmData, 1);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    pMotionConstrainedSliceGroupSet->exactSampleValueMatchFlag =
+        tmp == 1 ? HANTRO_TRUE : HANTRO_FALSE;
+
+    tmp = h264bsdGetBits(pStrmData, 1);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    pMotionConstrainedSliceGroupSet->panScanRectFlag = tmp == 1 ?
+                                        HANTRO_TRUE : HANTRO_FALSE;
+
+    if (pMotionConstrainedSliceGroupSet->panScanRectFlag)
+    {
+        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+          &pMotionConstrainedSliceGroupSet->panScanRectId);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+    }
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: DecodeReservedSeiMessage
+
+        Functional description:
+          <++>
+        Inputs:
+          <++>
+        Outputs:
+          <++>
+
+------------------------------------------------------------------------------*/
+
+static u32 DecodeReservedSeiMessage(
+  strmData_t *pStrmData,
+  seiReservedSeiMessage_t *pReservedSeiMessage,
+  u32 payloadSize)
+{
+
+/* Variables */
+
+    u32 i, tmp;
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(pReservedSeiMessage);
+
+
+    /* where corresponding FREE() ??? */
+    ALLOCATE(pReservedSeiMessage->reservedSeiMessagePayloadByte,payloadSize,u8);
+    if (pReservedSeiMessage->reservedSeiMessagePayloadByte == NULL)
+        return(MEMORY_ALLOCATION_ERROR);
+
+    pReservedSeiMessage->numPayloadBytes = payloadSize;
+
+    for (i = 0; i < payloadSize; i++)
+    {
+        tmp = h264bsdGetBits(pStrmData,8);
+        if (tmp == END_OF_STREAM)
+            return(HANTRO_NOK);
+        pReservedSeiMessage->reservedSeiMessagePayloadByte[i] = (u8)tmp;
+    }
+
+    return(HANTRO_OK);
+
+}
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_sei.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_sei.h
new file mode 100755
index 0000000..efe543a
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_sei.h
@@ -0,0 +1,252 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+    1. Include headers
+    2. Module defines
+    3. Data types
+    4. Function prototypes
+
+------------------------------------------------------------------------------*/
+
+#ifndef H264SWDEC_SEI_H
+#define H264SWDEC_SEI_H
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "basetype.h"
+#include "h264bsd_stream.h"
+#include "h264bsd_slice_header.h"
+#include "h264bsd_seq_param_set.h"
+#include "h264bsd_vui.h"
+
+/*------------------------------------------------------------------------------
+    2. Module defines
+------------------------------------------------------------------------------*/
+
+#define MAX_PAN_SCAN_CNT 32
+#define MAX_NUM_SPARE_PICS 16
+#define MAX_NUM_CLOCK_TS 3
+#define MAX_NUM_SUB_SEQ_LAYERS 256
+
+/*------------------------------------------------------------------------------
+    3. Data types
+------------------------------------------------------------------------------*/
+
+typedef struct
+{
+    u32 seqParameterSetId;
+    u32 initialCpbRemovalDelay[MAX_CPB_CNT];
+    u32 initialCpbRemovalDelayOffset[MAX_CPB_CNT];
+} seiBufferingPeriod_t;
+
+typedef struct
+{
+    u32 cpbRemovalDelay;
+    u32 dpbOutputDelay;
+    u32 picStruct;
+    u32 clockTimeStampFlag[MAX_NUM_CLOCK_TS];
+    u32 clockTimeStamp[MAX_NUM_CLOCK_TS];
+    u32 ctType[MAX_NUM_CLOCK_TS];
+    u32 nuitFieldBasedFlag[MAX_NUM_CLOCK_TS];
+    u32 countingType[MAX_NUM_CLOCK_TS];
+    u32 fullTimeStampFlag[MAX_NUM_CLOCK_TS];
+    u32 discontinuityFlag[MAX_NUM_CLOCK_TS];
+    u32 cntDroppedFlag[MAX_NUM_CLOCK_TS];
+    u32 nFrames[MAX_NUM_CLOCK_TS];
+    u32 secondsFlag[MAX_NUM_CLOCK_TS];
+    u32 secondsValue[MAX_NUM_CLOCK_TS];
+    u32 minutesFlag[MAX_NUM_CLOCK_TS];
+    u32 minutesValue[MAX_NUM_CLOCK_TS];
+    u32 hoursFlag[MAX_NUM_CLOCK_TS];
+    u32 hoursValue[MAX_NUM_CLOCK_TS];
+    i32 timeOffset[MAX_NUM_CLOCK_TS];
+} seiPicTiming_t;
+
+typedef struct
+{
+    u32 panScanRectId;
+    u32 panScanRectCancelFlag;
+    u32 panScanCnt;
+    i32 panScanRectLeftOffset[MAX_PAN_SCAN_CNT];
+    i32 panScanRectRightOffset[MAX_PAN_SCAN_CNT];
+    i32 panScanRectTopOffset[MAX_PAN_SCAN_CNT];
+    i32 panScanRectBottomOffset[MAX_PAN_SCAN_CNT];
+    u32 panScanRectRepetitionPeriod;
+} seiPanScanRect_t;
+
+typedef struct
+{
+    u32 ituTT35CountryCode;
+    u32 ituTT35CountryCodeExtensionByte;
+    u8 *ituTT35PayloadByte;
+    u32 numPayloadBytes;
+} seiUserDataRegisteredItuTT35_t;
+
+typedef struct
+{
+    u32 uuidIsoIec11578[4];
+    u8 *userDataPayloadByte;
+    u32 numPayloadBytes;
+} seiUserDataUnregistered_t;
+
+typedef struct
+{
+    u32 recoveryFrameCnt;
+    u32 exactMatchFlag;
+    u32 brokenLinkFlag;
+    u32 changingSliceGroupIdc;
+} seiRecoveryPoint_t;
+
+typedef struct
+{
+    u32 originalIdrFlag;
+    u32 originalFrameNum;
+    decRefPicMarking_t decRefPicMarking;
+} seiDecRefPicMarkingRepetition_t;
+
+typedef struct
+{
+    u32 targetFrameNum;
+    u32 spareFieldFlag;
+    u32 targetBottomFieldFlag;
+    u32 numSparePics;
+    u32 deltaSpareFrameNum[MAX_NUM_SPARE_PICS];
+    u32 spareBottomFieldFlag[MAX_NUM_SPARE_PICS];
+    u32 spareAreaIdc[MAX_NUM_SPARE_PICS];
+    u32 *spareUnitFlag[MAX_NUM_SPARE_PICS];
+    u32 *zeroRunLength[MAX_NUM_SPARE_PICS];
+} seiSparePic_t;
+
+typedef struct
+{
+    u32 sceneInfoPresentFlag;
+    u32 sceneId;
+    u32 sceneTransitionType;
+    u32 secondSceneId;
+} seiSceneInfo_t;
+
+typedef struct
+{
+    u32 subSeqLayerNum;
+    u32 subSeqId;
+    u32 firstRefPicFlag;
+    u32 leadingNonRefPicFlag;
+    u32 lastPicFlag;
+    u32 subSeqFrameNumFlag;
+    u32 subSeqFrameNum;
+} seiSubSeqInfo_t;
+
+typedef struct
+{
+    u32 numSubSeqLayers;
+    u32 accurateStatisticsFlag[MAX_NUM_SUB_SEQ_LAYERS];
+    u32 averageBitRate[MAX_NUM_SUB_SEQ_LAYERS];
+    u32 averageFrameRate[MAX_NUM_SUB_SEQ_LAYERS];
+} seiSubSeqLayerCharacteristics_t;
+
+typedef struct
+{
+    u32 subSeqLayerNum;
+    u32 subSeqId;
+    u32 durationFlag;
+    u32 subSeqDuration;
+    u32 averageRateFlag;
+    u32 accurateStatisticsFlag;
+    u32 averageBitRate;
+    u32 averageFrameRate;
+    u32 numReferencedSubseqs;
+    u32 refSubSeqLayerNum[MAX_NUM_SUB_SEQ_LAYERS];
+    u32 refSubSeqId[MAX_NUM_SUB_SEQ_LAYERS];
+    u32 refSubSeqDirection[MAX_NUM_SUB_SEQ_LAYERS];
+} seiSubSeqCharacteristics_t;
+
+typedef struct
+{
+    u32 fullFrameFreezeRepetitionPeriod;
+} seiFullFrameFreeze_t;
+
+typedef struct
+{
+    u32 snapShotId;
+} seiFullFrameSnapshot_t;
+
+typedef struct
+{
+    u32 progressiveRefinementId;
+    u32 numRefinementSteps;
+} seiProgressiveRefinementSegmentStart_t;
+
+typedef struct
+{
+    u32 progressiveRefinementId;
+} seiProgressiveRefinementSegmentEnd_t;
+
+typedef struct
+{
+    u32 numSliceGroupsInSet;
+    u32 sliceGroupId[MAX_NUM_SLICE_GROUPS];
+    u32 exactSampleValueMatchFlag;
+    u32 panScanRectFlag;
+    u32 panScanRectId;
+} seiMotionConstrainedSliceGroupSet_t;
+
+typedef struct
+{
+    u8 *reservedSeiMessagePayloadByte;
+    u32 numPayloadBytes;
+} seiReservedSeiMessage_t;
+
+typedef struct
+{
+    u32 payloadType;
+    seiBufferingPeriod_t bufferingPeriod;
+    seiPicTiming_t picTiming;
+    seiPanScanRect_t panScanRect;
+    seiUserDataRegisteredItuTT35_t userDataRegisteredItuTT35;
+    seiUserDataUnregistered_t userDataUnregistered;
+    seiRecoveryPoint_t recoveryPoint;
+    seiDecRefPicMarkingRepetition_t decRefPicMarkingRepetition;
+    seiSparePic_t sparePic;
+    seiSceneInfo_t sceneInfo;
+    seiSubSeqInfo_t subSeqInfo;
+    seiSubSeqLayerCharacteristics_t subSeqLayerCharacteristics;
+    seiSubSeqCharacteristics_t subSeqCharacteristics;
+    seiFullFrameFreeze_t fullFrameFreeze;
+    seiFullFrameSnapshot_t fullFrameSnapshot;
+    seiProgressiveRefinementSegmentStart_t progressiveRefinementSegmentStart;
+    seiProgressiveRefinementSegmentEnd_t progressiveRefinementSegmentEnd;
+    seiMotionConstrainedSliceGroupSet_t motionConstrainedSliceGroupSet;
+    seiReservedSeiMessage_t reservedSeiMessage;
+} seiMessage_t;
+
+/*------------------------------------------------------------------------------
+    4. Function prototypes
+------------------------------------------------------------------------------*/
+
+u32 h264bsdDecodeSeiMessage(
+  strmData_t *pStrmData,
+  seqParamSet_t *pSeqParamSet,
+  seiMessage_t *pSeiMessage,
+  u32 numSliceGroups);
+
+#endif /* #ifdef H264SWDEC_SEI_H */
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_seq_param_set.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_seq_param_set.c
new file mode 100644
index 0000000..751051a
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_seq_param_set.c
@@ -0,0 +1,577 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+     1. Include headers
+     2. External compiler flags
+     3. Module defines
+     4. Local function prototypes
+     5. Functions
+          h264bsdDecodeSeqParamSet
+          GetDpbSize
+          h264bsdCompareSeqParamSets
+
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "h264bsd_seq_param_set.h"
+#include "h264bsd_util.h"
+#include "h264bsd_vlc.h"
+#include "h264bsd_vui.h"
+#include "h264bsd_cfg.h"
+
+/*------------------------------------------------------------------------------
+    2. External compiler flags
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+    3. Module defines
+------------------------------------------------------------------------------*/
+
+/* enumeration to indicate invalid return value from the GetDpbSize function */
+enum {INVALID_DPB_SIZE = 0x7FFFFFFF};
+
+/*------------------------------------------------------------------------------
+    4. Local function prototypes
+------------------------------------------------------------------------------*/
+
+static u32 GetDpbSize(u32 picSizeInMbs, u32 levelIdc);
+
+/*------------------------------------------------------------------------------
+
+    Function name: h264bsdDecodeSeqParamSet
+
+        Functional description:
+            Decode sequence parameter set information from the stream.
+
+            Function allocates memory for offsetForRefFrame array if
+            picture order count type is 1 and numRefFramesInPicOrderCntCycle
+            is greater than zero.
+
+        Inputs:
+            pStrmData       pointer to stream data structure
+
+        Outputs:
+            pSeqParamSet    decoded information is stored here
+
+        Returns:
+            HANTRO_OK       success
+            HANTRO_NOK      failure, invalid information or end of stream
+            MEMORY_ALLOCATION_ERROR for memory allocation failure
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdDecodeSeqParamSet(strmData_t *pStrmData, seqParamSet_t *pSeqParamSet)
+{
+
+/* Variables */
+
+    u32 tmp, i, value;
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(pSeqParamSet);
+
+    H264SwDecMemset(pSeqParamSet, 0, sizeof(seqParamSet_t));
+
+    /* profile_idc */
+    tmp = h264bsdGetBits(pStrmData, 8);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    if (tmp != 66)
+    {
+        DEBUG(("NOT BASELINE PROFILE %d\n", tmp));
+    }
+    pSeqParamSet->profileIdc = tmp;
+
+    /* constrained_set0_flag */
+    tmp = h264bsdGetBits(pStrmData, 1);
+    /* constrained_set1_flag */
+    tmp = h264bsdGetBits(pStrmData, 1);
+    /* constrained_set2_flag */
+    tmp = h264bsdGetBits(pStrmData, 1);
+
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+
+    /* reserved_zero_5bits, values of these bits shall be ignored */
+    tmp = h264bsdGetBits(pStrmData, 5);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+
+    tmp = h264bsdGetBits(pStrmData, 8);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    pSeqParamSet->levelIdc = tmp;
+
+    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+        &pSeqParamSet->seqParameterSetId);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+    if (pSeqParamSet->seqParameterSetId >= MAX_NUM_SEQ_PARAM_SETS)
+    {
+        EPRINT("seq_param_set_id");
+        return(HANTRO_NOK);
+    }
+
+    /* log2_max_frame_num_minus4 */
+    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+    if (value > 12)
+    {
+        EPRINT("log2_max_frame_num_minus4");
+        return(HANTRO_NOK);
+    }
+    /* maxFrameNum = 2^(log2_max_frame_num_minus4 + 4) */
+    pSeqParamSet->maxFrameNum = 1 << (value+4);
+
+    /* valid POC types are 0, 1 and 2 */
+    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+    if (value > 2)
+    {
+        EPRINT("pic_order_cnt_type");
+        return(HANTRO_NOK);
+    }
+    pSeqParamSet->picOrderCntType = value;
+
+    if (pSeqParamSet->picOrderCntType == 0)
+    {
+        /* log2_max_pic_order_cnt_lsb_minus4 */
+        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+        if (value > 12)
+        {
+            EPRINT("log2_max_pic_order_cnt_lsb_minus4");
+            return(HANTRO_NOK);
+        }
+        /* maxPicOrderCntLsb = 2^(log2_max_pic_order_cnt_lsb_minus4 + 4) */
+        pSeqParamSet->maxPicOrderCntLsb = 1 << (value+4);
+    }
+    else if (pSeqParamSet->picOrderCntType == 1)
+    {
+        tmp = h264bsdGetBits(pStrmData, 1);
+        if (tmp == END_OF_STREAM)
+            return(HANTRO_NOK);
+        pSeqParamSet->deltaPicOrderAlwaysZeroFlag = (tmp == 1) ?
+                                        HANTRO_TRUE : HANTRO_FALSE;
+
+        tmp = h264bsdDecodeExpGolombSigned(pStrmData,
+            &pSeqParamSet->offsetForNonRefPic);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+
+        tmp = h264bsdDecodeExpGolombSigned(pStrmData,
+            &pSeqParamSet->offsetForTopToBottomField);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+
+        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+            &pSeqParamSet->numRefFramesInPicOrderCntCycle);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+        if (pSeqParamSet->numRefFramesInPicOrderCntCycle > 255)
+        {
+            EPRINT("num_ref_frames_in_pic_order_cnt_cycle");
+            return(HANTRO_NOK);
+        }
+
+        if (pSeqParamSet->numRefFramesInPicOrderCntCycle)
+        {
+            /* NOTE: This has to be freed somewhere! */
+            ALLOCATE(pSeqParamSet->offsetForRefFrame,
+                     pSeqParamSet->numRefFramesInPicOrderCntCycle, i32);
+            if (pSeqParamSet->offsetForRefFrame == NULL)
+                return(MEMORY_ALLOCATION_ERROR);
+
+            for (i = 0; i < pSeqParamSet->numRefFramesInPicOrderCntCycle; i++)
+            {
+                tmp =  h264bsdDecodeExpGolombSigned(pStrmData,
+                    pSeqParamSet->offsetForRefFrame + i);
+                if (tmp != HANTRO_OK)
+                    return(tmp);
+            }
+        }
+        else
+        {
+            pSeqParamSet->offsetForRefFrame = NULL;
+        }
+    }
+
+    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+        &pSeqParamSet->numRefFrames);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+    if (pSeqParamSet->numRefFrames > MAX_NUM_REF_PICS)
+    {
+        EPRINT("num_ref_frames");
+        return(HANTRO_NOK);
+    }
+
+    tmp = h264bsdGetBits(pStrmData, 1);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    pSeqParamSet->gapsInFrameNumValueAllowedFlag = (tmp == 1) ?
+                                        HANTRO_TRUE : HANTRO_FALSE;
+
+    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+    pSeqParamSet->picWidthInMbs = value + 1;
+
+    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+    pSeqParamSet->picHeightInMbs = value + 1;
+
+    /* frame_mbs_only_flag, shall be 1 for baseline profile */
+    tmp = h264bsdGetBits(pStrmData, 1);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    if (!tmp)
+    {
+        EPRINT("frame_mbs_only_flag");
+        return(HANTRO_NOK);
+    }
+
+    /* direct_8x8_inference_flag */
+    tmp = h264bsdGetBits(pStrmData, 1);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+
+    tmp = h264bsdGetBits(pStrmData, 1);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    pSeqParamSet->frameCroppingFlag = (tmp == 1) ? HANTRO_TRUE : HANTRO_FALSE;
+
+    if (pSeqParamSet->frameCroppingFlag)
+    {
+        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+            &pSeqParamSet->frameCropLeftOffset);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+            &pSeqParamSet->frameCropRightOffset);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+            &pSeqParamSet->frameCropTopOffset);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+            &pSeqParamSet->frameCropBottomOffset);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+
+        /* check that frame cropping params are valid, parameters shall
+         * specify non-negative area within the original picture */
+        if ( ( (i32)pSeqParamSet->frameCropLeftOffset >
+               ( 8 * (i32)pSeqParamSet->picWidthInMbs -
+                 ((i32)pSeqParamSet->frameCropRightOffset + 1) ) ) ||
+             ( (i32)pSeqParamSet->frameCropTopOffset >
+               ( 8 * (i32)pSeqParamSet->picHeightInMbs -
+                 ((i32)pSeqParamSet->frameCropBottomOffset + 1) ) ) )
+        {
+            EPRINT("frame_cropping");
+            return(HANTRO_NOK);
+        }
+    }
+
+    /* check that image dimensions and levelIdc match */
+    tmp = pSeqParamSet->picWidthInMbs * pSeqParamSet->picHeightInMbs;
+    value = GetDpbSize(tmp, pSeqParamSet->levelIdc);
+    if (value == INVALID_DPB_SIZE || pSeqParamSet->numRefFrames > value)
+    {
+        DEBUG(("WARNING! Invalid DPB size based on SPS Level!\n"));
+        DEBUG(("WARNING! Using num_ref_frames =%d for DPB size!\n",
+                        pSeqParamSet->numRefFrames));
+        value = pSeqParamSet->numRefFrames;
+    }
+    pSeqParamSet->maxDpbSize = value;
+
+    tmp = h264bsdGetBits(pStrmData, 1);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    pSeqParamSet->vuiParametersPresentFlag = (tmp == 1) ?
+                                HANTRO_TRUE : HANTRO_FALSE;
+
+    /* VUI */
+    if (pSeqParamSet->vuiParametersPresentFlag)
+    {
+        ALLOCATE(pSeqParamSet->vuiParameters, 1, vuiParameters_t);
+        if (pSeqParamSet->vuiParameters == NULL)
+            return(MEMORY_ALLOCATION_ERROR);
+        tmp = h264bsdDecodeVuiParameters(pStrmData,
+            pSeqParamSet->vuiParameters);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+        /* check numReorderFrames and maxDecFrameBuffering */
+        if (pSeqParamSet->vuiParameters->bitstreamRestrictionFlag)
+        {
+            if (pSeqParamSet->vuiParameters->numReorderFrames >
+                    pSeqParamSet->vuiParameters->maxDecFrameBuffering ||
+                pSeqParamSet->vuiParameters->maxDecFrameBuffering <
+                    pSeqParamSet->numRefFrames ||
+                pSeqParamSet->vuiParameters->maxDecFrameBuffering >
+                    pSeqParamSet->maxDpbSize)
+            {
+                return(HANTRO_NOK);
+            }
+
+            /* standard says that "the sequence shall not require a DPB with
+             * size of more than max(1, maxDecFrameBuffering) */
+            pSeqParamSet->maxDpbSize =
+                MAX(1, pSeqParamSet->vuiParameters->maxDecFrameBuffering);
+        }
+    }
+
+    tmp = h264bsdRbspTrailingBits(pStrmData);
+
+    /* ignore possible errors in trailing bits of parameters sets */
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: GetDpbSize
+
+        Functional description:
+            Get size of the DPB in frames. Size is determined based on the
+            picture size and MaxDPB for the specified level. These determine
+            how many pictures may fit into to the buffer. However, the size
+            is also limited to a maximum of 16 frames and therefore function
+            returns the minimum of the determined size and 16.
+
+        Inputs:
+            picSizeInMbs    number of macroblocks in the picture
+            levelIdc        indicates the level
+
+        Outputs:
+            none
+
+        Returns:
+            size of the DPB in frames
+            INVALID_DPB_SIZE when invalid levelIdc specified or picSizeInMbs
+            is higher than supported by the level in question
+
+------------------------------------------------------------------------------*/
+
+u32 GetDpbSize(u32 picSizeInMbs, u32 levelIdc)
+{
+
+/* Variables */
+
+    u32 tmp;
+    u32 maxPicSizeInMbs;
+
+/* Code */
+
+    ASSERT(picSizeInMbs);
+
+    /* use tmp as the size of the DPB in bytes, computes as 1024 * MaxDPB
+     * (from table A-1 in Annex A) */
+    switch (levelIdc)
+    {
+        case 10:
+            tmp = 152064;
+            maxPicSizeInMbs = 99;
+            break;
+
+        case 11:
+            tmp = 345600;
+            maxPicSizeInMbs = 396;
+            break;
+
+        case 12:
+            tmp = 912384;
+            maxPicSizeInMbs = 396;
+            break;
+
+        case 13:
+            tmp = 912384;
+            maxPicSizeInMbs = 396;
+            break;
+
+        case 20:
+            tmp = 912384;
+            maxPicSizeInMbs = 396;
+            break;
+
+        case 21:
+            tmp = 1824768;
+            maxPicSizeInMbs = 792;
+            break;
+
+        case 22:
+            tmp = 3110400;
+            maxPicSizeInMbs = 1620;
+            break;
+
+        case 30:
+            tmp = 3110400;
+            maxPicSizeInMbs = 1620;
+            break;
+
+        case 31:
+            tmp = 6912000;
+            maxPicSizeInMbs = 3600;
+            break;
+
+        case 32:
+            tmp = 7864320;
+            maxPicSizeInMbs = 5120;
+            break;
+
+        case 40:
+            tmp = 12582912;
+            maxPicSizeInMbs = 8192;
+            break;
+
+        case 41:
+            tmp = 12582912;
+            maxPicSizeInMbs = 8192;
+            break;
+
+        case 42:
+            tmp = 34816*384;
+            maxPicSizeInMbs = 8704;
+            break;
+
+        case 50:
+            /* standard says 42301440 here, but corrigendum "corrects" this to
+             * 42393600 */
+            tmp = 42393600;
+            maxPicSizeInMbs = 22080;
+            break;
+
+        case 51:
+            tmp = 70778880;
+            maxPicSizeInMbs = 36864;
+            break;
+
+        default:
+            return(INVALID_DPB_SIZE);
+    }
+
+    /* this is not "correct" return value! However, it results in error in
+     * decoding and this was easiest place to check picture size */
+    if (picSizeInMbs > maxPicSizeInMbs)
+        return(INVALID_DPB_SIZE);
+
+    tmp /= (picSizeInMbs*384);
+
+    return(MIN(tmp, 16));
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function name: h264bsdCompareSeqParamSets
+
+        Functional description:
+            Compare two sequence parameter sets.
+
+        Inputs:
+            pSps1   pointer to a sequence parameter set
+            pSps2   pointer to another sequence parameter set
+
+        Outputs:
+            0       sequence parameter sets are equal
+            1       otherwise
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdCompareSeqParamSets(seqParamSet_t *pSps1, seqParamSet_t *pSps2)
+{
+
+/* Variables */
+
+    u32 i;
+
+/* Code */
+
+    ASSERT(pSps1);
+    ASSERT(pSps2);
+
+    /* first compare parameters whose existence does not depend on other
+     * parameters and only compare the rest of the params if these are equal */
+    if (pSps1->profileIdc        == pSps2->profileIdc &&
+        pSps1->levelIdc          == pSps2->levelIdc &&
+        pSps1->maxFrameNum       == pSps2->maxFrameNum &&
+        pSps1->picOrderCntType   == pSps2->picOrderCntType &&
+        pSps1->numRefFrames      == pSps2->numRefFrames &&
+        pSps1->gapsInFrameNumValueAllowedFlag ==
+            pSps2->gapsInFrameNumValueAllowedFlag &&
+        pSps1->picWidthInMbs     == pSps2->picWidthInMbs &&
+        pSps1->picHeightInMbs    == pSps2->picHeightInMbs &&
+        pSps1->frameCroppingFlag == pSps2->frameCroppingFlag &&
+        pSps1->vuiParametersPresentFlag == pSps2->vuiParametersPresentFlag)
+    {
+        if (pSps1->picOrderCntType == 0)
+        {
+            if (pSps1->maxPicOrderCntLsb != pSps2->maxPicOrderCntLsb)
+                return 1;
+        }
+        else if (pSps1->picOrderCntType == 1)
+        {
+            if (pSps1->deltaPicOrderAlwaysZeroFlag !=
+                    pSps2->deltaPicOrderAlwaysZeroFlag ||
+                pSps1->offsetForNonRefPic != pSps2->offsetForNonRefPic ||
+                pSps1->offsetForTopToBottomField !=
+                    pSps2->offsetForTopToBottomField ||
+                pSps1->numRefFramesInPicOrderCntCycle !=
+                    pSps2->numRefFramesInPicOrderCntCycle)
+            {
+                return 1;
+            }
+            else
+            {
+                for (i = 0; i < pSps1->numRefFramesInPicOrderCntCycle; i++)
+                    if (pSps1->offsetForRefFrame[i] !=
+                        pSps2->offsetForRefFrame[i])
+                    {
+                        return 1;
+                    }
+            }
+        }
+        if (pSps1->frameCroppingFlag)
+        {
+            if (pSps1->frameCropLeftOffset   != pSps2->frameCropLeftOffset ||
+                pSps1->frameCropRightOffset  != pSps2->frameCropRightOffset ||
+                pSps1->frameCropTopOffset    != pSps2->frameCropTopOffset ||
+                pSps1->frameCropBottomOffset != pSps2->frameCropBottomOffset)
+            {
+                return 1;
+            }
+        }
+
+        return 0;
+    }
+
+    return 1;
+}
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_seq_param_set.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_seq_param_set.h
new file mode 100755
index 0000000..e18df94
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_seq_param_set.h
@@ -0,0 +1,86 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+    1. Include headers
+    2. Module defines
+    3. Data types
+    4. Function prototypes
+
+------------------------------------------------------------------------------*/
+
+#ifndef H264SWDEC_SEQ_PARAM_SET_H
+#define H264SWDEC_SEQ_PARAM_SET_H
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "basetype.h"
+#include "h264bsd_stream.h"
+#include "h264bsd_vui.h"
+
+/*------------------------------------------------------------------------------
+    2. Module defines
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    3. Data types
+------------------------------------------------------------------------------*/
+
+/* structure to store sequence parameter set information decoded from the
+ * stream */
+typedef struct
+{
+    u32 profileIdc;
+    u32 levelIdc;
+    u32 seqParameterSetId;
+    u32 maxFrameNum;
+    u32 picOrderCntType;
+    u32 maxPicOrderCntLsb;
+    u32 deltaPicOrderAlwaysZeroFlag;
+    i32 offsetForNonRefPic;
+    i32 offsetForTopToBottomField;
+    u32 numRefFramesInPicOrderCntCycle;
+    i32 *offsetForRefFrame;
+    u32 numRefFrames;
+    u32 gapsInFrameNumValueAllowedFlag;
+    u32 picWidthInMbs;
+    u32 picHeightInMbs;
+    u32 frameCroppingFlag;
+    u32 frameCropLeftOffset;
+    u32 frameCropRightOffset;
+    u32 frameCropTopOffset;
+    u32 frameCropBottomOffset;
+    u32 vuiParametersPresentFlag;
+    vuiParameters_t *vuiParameters;
+    u32 maxDpbSize;
+} seqParamSet_t;
+
+/*------------------------------------------------------------------------------
+    4. Function prototypes
+------------------------------------------------------------------------------*/
+
+u32 h264bsdDecodeSeqParamSet(strmData_t *pStrmData,
+    seqParamSet_t *pSeqParamSet);
+
+u32 h264bsdCompareSeqParamSets(seqParamSet_t *pSps1, seqParamSet_t *pSps2);
+
+#endif /* #ifdef H264SWDEC_SEQ_PARAM_SET_H */
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_slice_data.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_slice_data.c
new file mode 100755
index 0000000..c288d4b
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_slice_data.c
@@ -0,0 +1,354 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+     1. Include headers
+     2. External compiler flags
+     3. Module defines
+     4. Local function prototypes
+     5. Functions
+          h264bsdDecodeSliceData
+          SetMbParams
+          h264bsdMarkSliceCorrupted
+
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "h264bsd_slice_data.h"
+#include "h264bsd_util.h"
+#include "h264bsd_vlc.h"
+
+/*------------------------------------------------------------------------------
+    2. External compiler flags
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+    3. Module defines
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    4. Local function prototypes
+------------------------------------------------------------------------------*/
+
+static void SetMbParams(mbStorage_t *pMb, sliceHeader_t *pSlice, u32 sliceId,
+    i32 chromaQpIndexOffset);
+
+/*------------------------------------------------------------------------------
+
+   5.1  Function name: h264bsdDecodeSliceData
+
+        Functional description:
+            Decode one slice. Function decodes stream data, i.e. macroblocks
+            and possible skip_run fields. h264bsdDecodeMacroblock function is
+            called to handle all other macroblock related processing.
+            Macroblock to slice group mapping is considered when next
+            macroblock to process is determined (h264bsdNextMbAddress function)
+            map
+
+        Inputs:
+            pStrmData       pointer to stream data structure
+            pStorage        pointer to storage structure
+            currImage       pointer to current processed picture, needed for
+                            intra prediction of the macroblocks
+            pSliceHeader    pointer to slice header of the current slice
+
+        Outputs:
+            currImage       processed macroblocks are written to current image
+            pStorage        mbStorage structure of each processed macroblock
+                            is updated here
+
+        Returns:
+            HANTRO_OK       success
+            HANTRO_NOK      invalid stream data
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdDecodeSliceData(strmData_t *pStrmData, storage_t *pStorage,
+    image_t *currImage, sliceHeader_t *pSliceHeader)
+{
+
+/* Variables */
+
+    u8 mbData[384 + 15 + 32];
+    u8 *data;
+    u32 tmp;
+    u32 skipRun;
+    u32 prevSkipped;
+    u32 currMbAddr;
+    u32 moreMbs;
+    u32 mbCount;
+    i32 qpY;
+    macroblockLayer_t *mbLayer;
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(pSliceHeader);
+    ASSERT(pStorage);
+    ASSERT(pSliceHeader->firstMbInSlice < pStorage->picSizeInMbs);
+
+    /* ensure 16-byte alignment */
+    data = (u8*)ALIGN(mbData, 16);
+
+    mbLayer = pStorage->mbLayer;
+
+    currMbAddr = pSliceHeader->firstMbInSlice;
+    skipRun = 0;
+    prevSkipped = HANTRO_FALSE;
+
+    /* increment slice index, will be one for decoding of the first slice of
+     * the picture */
+    pStorage->slice->sliceId++;
+
+    /* lastMbAddr stores address of the macroblock that was last successfully
+     * decoded, needed for error handling */
+    pStorage->slice->lastMbAddr = 0;
+
+    mbCount = 0;
+    /* initial quantization parameter for the slice is obtained as the sum of
+     * initial QP for the picture and sliceQpDelta for the current slice */
+    qpY = (i32)pStorage->activePps->picInitQp + pSliceHeader->sliceQpDelta;
+    do
+    {
+        /* primary picture and already decoded macroblock -> error */
+        if (!pSliceHeader->redundantPicCnt && pStorage->mb[currMbAddr].decoded)
+        {
+            EPRINT("Primary and already decoded");
+            return(HANTRO_NOK);
+        }
+
+        SetMbParams(pStorage->mb + currMbAddr, pSliceHeader,
+            pStorage->slice->sliceId, pStorage->activePps->chromaQpIndexOffset);
+
+        if (!IS_I_SLICE(pSliceHeader->sliceType))
+        {
+            if (!prevSkipped)
+            {
+                tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &skipRun);
+                if (tmp != HANTRO_OK)
+                    return(tmp);
+                /* skip_run shall be less than or equal to number of
+                 * macroblocks left */
+                if (skipRun > (pStorage->picSizeInMbs - currMbAddr))
+                {
+                    EPRINT("skip_run");
+                    return(HANTRO_NOK);
+                }
+                if (skipRun)
+                {
+                    prevSkipped = HANTRO_TRUE;
+                    H264SwDecMemset(&mbLayer->mbPred, 0, sizeof(mbPred_t));
+                    /* mark current macroblock skipped */
+                    mbLayer->mbType = P_Skip;
+                }
+            }
+        }
+
+        if (skipRun)
+        {
+            DEBUG(("Skipping macroblock %d\n", currMbAddr));
+            skipRun--;
+        }
+        else
+        {
+            prevSkipped = HANTRO_FALSE;
+            tmp = h264bsdDecodeMacroblockLayer(pStrmData, mbLayer,
+                pStorage->mb + currMbAddr, pSliceHeader->sliceType,
+                pSliceHeader->numRefIdxL0Active);
+            if (tmp != HANTRO_OK)
+            {
+                EPRINT("macroblock_layer");
+                return(tmp);
+            }
+        }
+
+        tmp = h264bsdDecodeMacroblock(pStorage->mb + currMbAddr, mbLayer,
+            currImage, pStorage->dpb, &qpY, currMbAddr,
+            pStorage->activePps->constrainedIntraPredFlag, data);
+        if (tmp != HANTRO_OK)
+        {
+            EPRINT("MACRO_BLOCK");
+            return(tmp);
+        }
+
+        /* increment macroblock count only for macroblocks that were decoded
+         * for the first time (redundant slices) */
+        if (pStorage->mb[currMbAddr].decoded == 1)
+            mbCount++;
+
+        /* keep on processing as long as there is stream data left or
+         * processing of macroblocks to be skipped based on the last skipRun is
+         * not finished */
+        moreMbs = (h264bsdMoreRbspData(pStrmData) || skipRun) ?
+                                        HANTRO_TRUE : HANTRO_FALSE;
+
+        /* lastMbAddr is only updated for intra slices (all macroblocks of
+         * inter slices will be lost in case of an error) */
+        if (IS_I_SLICE(pSliceHeader->sliceType))
+            pStorage->slice->lastMbAddr = currMbAddr;
+
+        currMbAddr = h264bsdNextMbAddress(pStorage->sliceGroupMap,
+            pStorage->picSizeInMbs, currMbAddr);
+        /* data left in the buffer but no more macroblocks for current slice
+         * group -> error */
+        if (moreMbs && !currMbAddr)
+        {
+            EPRINT("Next mb address");
+            return(HANTRO_NOK);
+        }
+
+    } while (moreMbs);
+
+    if ((pStorage->slice->numDecodedMbs + mbCount) > pStorage->picSizeInMbs)
+    {
+        EPRINT("Num decoded mbs");
+        return(HANTRO_NOK);
+    }
+
+    pStorage->slice->numDecodedMbs += mbCount;
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+   5.2  Function: SetMbParams
+
+        Functional description:
+            Set macroblock parameters that remain constant for this slice
+
+        Inputs:
+            pSlice      pointer to current slice header
+            sliceId     id of the current slice
+            chromaQpIndexOffset
+
+        Outputs:
+            pMb         pointer to macroblock structure which is updated
+
+        Returns:
+            none
+
+------------------------------------------------------------------------------*/
+
+void SetMbParams(mbStorage_t *pMb, sliceHeader_t *pSlice, u32 sliceId,
+    i32 chromaQpIndexOffset)
+{
+
+/* Variables */
+    u32 tmp1;
+    i32 tmp2, tmp3;
+
+/* Code */
+
+    tmp1 = pSlice->disableDeblockingFilterIdc;
+    tmp2 = pSlice->sliceAlphaC0Offset;
+    tmp3 = pSlice->sliceBetaOffset;
+    pMb->sliceId = sliceId;
+    pMb->disableDeblockingFilterIdc = tmp1;
+    pMb->filterOffsetA = tmp2;
+    pMb->filterOffsetB = tmp3;
+    pMb->chromaQpIndexOffset = chromaQpIndexOffset;
+
+}
+
+/*------------------------------------------------------------------------------
+
+   5.3  Function name: h264bsdMarkSliceCorrupted
+
+        Functional description:
+            Mark macroblocks of the slice corrupted. If lastMbAddr in the slice
+            storage is set -> picWidhtInMbs (or at least 10) macroblocks back
+            from  the lastMbAddr are marked corrupted. However, if lastMbAddr
+            is not set -> all macroblocks of the slice are marked.
+
+        Inputs:
+            pStorage        pointer to storage structure
+            firstMbInSlice  address of the first macroblock in the slice, this
+                            identifies the slice to be marked corrupted
+
+        Outputs:
+            pStorage        mbStorage for the corrupted macroblocks updated
+
+        Returns:
+            none
+
+------------------------------------------------------------------------------*/
+
+void h264bsdMarkSliceCorrupted(storage_t *pStorage, u32 firstMbInSlice)
+{
+
+/* Variables */
+
+    u32 tmp, i;
+    u32 sliceId;
+    u32 currMbAddr;
+
+/* Code */
+
+    ASSERT(pStorage);
+    ASSERT(firstMbInSlice < pStorage->picSizeInMbs);
+
+    currMbAddr = firstMbInSlice;
+
+    sliceId = pStorage->slice->sliceId;
+
+    /* DecodeSliceData sets lastMbAddr for I slices -> if it was set, go back
+     * MAX(picWidthInMbs, 10) macroblocks and start marking from there */
+    if (pStorage->slice->lastMbAddr)
+    {
+        ASSERT(pStorage->mb[pStorage->slice->lastMbAddr].sliceId == sliceId);
+        i = pStorage->slice->lastMbAddr - 1;
+        tmp = 0;
+        while (i > currMbAddr)
+        {
+            if (pStorage->mb[i].sliceId == sliceId)
+            {
+                tmp++;
+                if (tmp >= MAX(pStorage->activeSps->picWidthInMbs, 10))
+                    break;
+            }
+            i--;
+        }
+        currMbAddr = i;
+    }
+
+    do
+    {
+
+        if ( (pStorage->mb[currMbAddr].sliceId == sliceId) &&
+             (pStorage->mb[currMbAddr].decoded) )
+        {
+            pStorage->mb[currMbAddr].decoded--;
+        }
+        else
+        {
+            break;
+        }
+
+        currMbAddr = h264bsdNextMbAddress(pStorage->sliceGroupMap,
+            pStorage->picSizeInMbs, currMbAddr);
+
+    } while (currMbAddr);
+
+}
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_slice_data.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_slice_data.h
new file mode 100755
index 0000000..f23d49e
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_slice_data.h
@@ -0,0 +1,59 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+    1. Include headers
+    2. Module defines
+    3. Data types
+    4. Function prototypes
+
+------------------------------------------------------------------------------*/
+
+#ifndef H264SWDEC_SLICE_DATA_H
+#define H264SWDEC_SLICE_DATA_H
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "basetype.h"
+#include "h264bsd_stream.h"
+#include "h264bsd_cfg.h"
+#include "h264bsd_slice_header.h"
+#include "h264bsd_storage.h"
+
+/*------------------------------------------------------------------------------
+    2. Module defines
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    3. Data types
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    4. Function prototypes
+------------------------------------------------------------------------------*/
+
+u32 h264bsdDecodeSliceData(strmData_t *pStrmData, storage_t *pStorage,
+    image_t *currImage, sliceHeader_t *pSliceHeader);
+
+void h264bsdMarkSliceCorrupted(storage_t *pStorage, u32 firstMbInSlice);
+
+#endif /* #ifdef H264SWDEC_SLICE_DATA_H */
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_slice_group_map.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_slice_group_map.c
new file mode 100755
index 0000000..7cbb534
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_slice_group_map.c
@@ -0,0 +1,589 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+     1. Include headers
+     2. External compiler flags
+     3. Module defines
+     4. Local function prototypes
+     5. Functions
+          DecodeInterleavedMap
+          DecodeDispersedMap
+          DecodeForegroundLeftOverMap
+          DecodeBoxOutMap
+          DecodeRasterScanMap
+          DecodeWipeMap
+          h264bsdDecodeSliceGroupMap
+
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "basetype.h"
+#include "h264bsd_slice_group_map.h"
+#include "h264bsd_cfg.h"
+#include "h264bsd_pic_param_set.h"
+#include "h264bsd_util.h"
+
+/*------------------------------------------------------------------------------
+    2. External compiler flags
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+    3. Module defines
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    4. Local function prototypes
+------------------------------------------------------------------------------*/
+
+static void DecodeInterleavedMap(
+  u32 *map,
+  u32 numSliceGroups,
+  u32 *runLength,
+  u32 picSize);
+
+static void DecodeDispersedMap(
+  u32 *map,
+  u32 numSliceGroups,
+  u32 picWidth,
+  u32 picHeight);
+
+static void DecodeForegroundLeftOverMap(
+  u32 *map,
+  u32 numSliceGroups,
+  u32 *topLeft,
+  u32 *bottomRight,
+  u32 picWidth,
+  u32 picHeight);
+
+static void DecodeBoxOutMap(
+  u32 *map,
+  u32 sliceGroupChangeDirectionFlag,
+  u32 unitsInSliceGroup0,
+  u32 picWidth,
+  u32 picHeight);
+
+static void DecodeRasterScanMap(
+  u32 *map,
+  u32 sliceGroupChangeDirectionFlag,
+  u32 sizeOfUpperLeftGroup,
+  u32 picSize);
+
+static void DecodeWipeMap(
+  u32 *map,
+  u32 sliceGroupChangeDirectionFlag,
+  u32 sizeOfUpperLeftGroup,
+  u32 picWidth,
+  u32 picHeight);
+
+/*------------------------------------------------------------------------------
+
+    Function: DecodeInterleavedMap
+
+        Functional description:
+            Function to decode interleaved slice group map type, i.e. slice
+            group map type 0.
+
+        Inputs:
+            map             pointer to the map
+            numSliceGroups  number of slice groups
+            runLength       run_length[] values for each slice group
+            picSize         picture size in macroblocks
+
+        Outputs:
+            map             slice group map is stored here
+
+        Returns:
+            none
+
+------------------------------------------------------------------------------*/
+
+void DecodeInterleavedMap(
+  u32 *map,
+  u32 numSliceGroups,
+  u32 *runLength,
+  u32 picSize)
+{
+
+/* Variables */
+
+    u32 i,j, group;
+
+/* Code */
+
+    ASSERT(map);
+    ASSERT(numSliceGroups >= 1 && numSliceGroups <= MAX_NUM_SLICE_GROUPS);
+    ASSERT(runLength);
+
+    i = 0;
+
+    do {
+        for (group = 0; group < numSliceGroups && i < picSize;
+          i += runLength[group++])
+        {
+            ASSERT(runLength[group] <= picSize);
+            for (j = 0; j < runLength[group] && i + j < picSize; j++)
+                map[i+j] = group;
+        }
+    } while (i < picSize);
+
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: DecodeDispersedMap
+
+        Functional description:
+            Function to decode dispersed slice group map type, i.e. slice
+            group map type 1.
+
+        Inputs:
+            map               pointer to the map
+            numSliceGroups    number of slice groups
+            picWidth          picture width in macroblocks
+            picHeight         picture height in macroblocks
+
+        Outputs:
+            map               slice group map is stored here
+
+        Returns:
+            none
+
+------------------------------------------------------------------------------*/
+
+void DecodeDispersedMap(
+  u32 *map,
+  u32 numSliceGroups,
+  u32 picWidth,
+  u32 picHeight)
+{
+
+/* Variables */
+
+    u32 i, picSize;
+
+/* Code */
+
+    ASSERT(map);
+    ASSERT(numSliceGroups >= 1 && numSliceGroups <= MAX_NUM_SLICE_GROUPS);
+    ASSERT(picWidth);
+    ASSERT(picHeight);
+
+    picSize = picWidth * picHeight;
+
+    for (i = 0; i < picSize; i++)
+        map[i] = ((i % picWidth) + (((i / picWidth) * numSliceGroups) >> 1)) %
+            numSliceGroups;
+
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: DecodeForegroundLeftOverMap
+
+        Functional description:
+            Function to decode foreground with left-over slice group map type,
+            i.e. slice group map type 2.
+
+        Inputs:
+            map               pointer to the map
+            numSliceGroups    number of slice groups
+            topLeft           top_left[] values
+            bottomRight       bottom_right[] values
+            picWidth          picture width in macroblocks
+            picHeight         picture height in macroblocks
+
+        Outputs:
+            map               slice group map is stored here
+
+        Returns:
+            none
+
+------------------------------------------------------------------------------*/
+
+void DecodeForegroundLeftOverMap(
+  u32 *map,
+  u32 numSliceGroups,
+  u32 *topLeft,
+  u32 *bottomRight,
+  u32 picWidth,
+  u32 picHeight)
+{
+
+/* Variables */
+
+    u32 i,y,x,yTopLeft,yBottomRight,xTopLeft,xBottomRight, picSize;
+    u32 group;
+
+/* Code */
+
+    ASSERT(map);
+    ASSERT(numSliceGroups >= 1 && numSliceGroups <= MAX_NUM_SLICE_GROUPS);
+    ASSERT(topLeft);
+    ASSERT(bottomRight);
+    ASSERT(picWidth);
+    ASSERT(picHeight);
+
+    picSize = picWidth * picHeight;
+
+    for (i = 0; i < picSize; i++)
+        map[i] = numSliceGroups - 1;
+
+    for (group = numSliceGroups - 1; group--; )
+    {
+        ASSERT( topLeft[group] <= bottomRight[group] &&
+                bottomRight[group] < picSize );
+        yTopLeft = topLeft[group] / picWidth;
+        xTopLeft = topLeft[group] % picWidth;
+        yBottomRight = bottomRight[group] / picWidth;
+        xBottomRight = bottomRight[group] % picWidth;
+        ASSERT(xTopLeft <= xBottomRight);
+
+        for (y = yTopLeft; y <= yBottomRight; y++)
+            for (x = xTopLeft; x <= xBottomRight; x++)
+                map[ y * picWidth + x ] = group;
+    }
+
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: DecodeBoxOutMap
+
+        Functional description:
+            Function to decode box-out slice group map type, i.e. slice group
+            map type 3.
+
+        Inputs:
+            map                               pointer to the map
+            sliceGroupChangeDirectionFlag     slice_group_change_direction_flag
+            unitsInSliceGroup0                mbs on slice group 0
+            picWidth                          picture width in macroblocks
+            picHeight                         picture height in macroblocks
+
+        Outputs:
+            map                               slice group map is stored here
+
+        Returns:
+            none
+
+------------------------------------------------------------------------------*/
+
+void DecodeBoxOutMap(
+  u32 *map,
+  u32 sliceGroupChangeDirectionFlag,
+  u32 unitsInSliceGroup0,
+  u32 picWidth,
+  u32 picHeight)
+{
+
+/* Variables */
+
+    u32 i, k, picSize;
+    i32 x, y, xDir, yDir, leftBound, topBound, rightBound, bottomBound;
+    u32 mapUnitVacant;
+
+/* Code */
+
+    ASSERT(map);
+    ASSERT(picWidth);
+    ASSERT(picHeight);
+
+    picSize = picWidth * picHeight;
+    ASSERT(unitsInSliceGroup0 <= picSize);
+
+    for (i = 0; i < picSize; i++)
+        map[i] = 1;
+
+    x = (picWidth - (u32)sliceGroupChangeDirectionFlag) >> 1;
+    y = (picHeight - (u32)sliceGroupChangeDirectionFlag) >> 1;
+
+    leftBound = x;
+    topBound = y;
+
+    rightBound = x;
+    bottomBound = y;
+
+    xDir = (i32)sliceGroupChangeDirectionFlag - 1;
+    yDir = (i32)sliceGroupChangeDirectionFlag;
+
+    for (k = 0; k < unitsInSliceGroup0; k += mapUnitVacant ? 1 : 0)
+    {
+        mapUnitVacant = (map[ (u32)y * picWidth + (u32)x ] == 1) ?
+                                        HANTRO_TRUE : HANTRO_FALSE;
+
+        if (mapUnitVacant)
+            map[ (u32)y * picWidth + (u32)x ] = 0;
+
+        if (xDir == -1 && x == leftBound)
+        {
+            leftBound = MAX(leftBound - 1, 0);
+            x = leftBound;
+            xDir = 0;
+            yDir = 2 * (i32)sliceGroupChangeDirectionFlag - 1;
+        }
+        else if (xDir == 1 && x == rightBound)
+        {
+            rightBound = MIN(rightBound + 1, (i32)picWidth - 1);
+            x = rightBound;
+            xDir = 0;
+            yDir = 1 - 2 * (i32)sliceGroupChangeDirectionFlag;
+        }
+        else if (yDir == -1 && y == topBound)
+        {
+            topBound = MAX(topBound - 1, 0);
+            y = topBound;
+            xDir = 1 - 2 * (i32)sliceGroupChangeDirectionFlag;
+            yDir = 0;
+        }
+        else if (yDir == 1 && y == bottomBound)
+        {
+            bottomBound = MIN(bottomBound + 1, (i32)picHeight - 1);
+            y = bottomBound;
+            xDir = 2 * (i32)sliceGroupChangeDirectionFlag - 1;
+            yDir = 0;
+        }
+        else
+        {
+            x += xDir;
+            y += yDir;
+        }
+    }
+
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: DecodeRasterScanMap
+
+        Functional description:
+            Function to decode raster scan slice group map type, i.e. slice
+            group map type 4.
+
+        Inputs:
+            map                               pointer to the map
+            sliceGroupChangeDirectionFlag     slice_group_change_direction_flag
+            sizeOfUpperLeftGroup              mbs in upperLeftGroup
+            picSize                           picture size in macroblocks
+
+        Outputs:
+            map                               slice group map is stored here
+
+        Returns:
+            none
+
+------------------------------------------------------------------------------*/
+
+void DecodeRasterScanMap(
+  u32 *map,
+  u32 sliceGroupChangeDirectionFlag,
+  u32 sizeOfUpperLeftGroup,
+  u32 picSize)
+{
+
+/* Variables */
+
+    u32 i;
+
+/* Code */
+
+    ASSERT(map);
+    ASSERT(picSize);
+    ASSERT(sizeOfUpperLeftGroup <= picSize);
+
+    for (i = 0; i < picSize; i++)
+        if (i < sizeOfUpperLeftGroup)
+            map[i] = (u32)sliceGroupChangeDirectionFlag;
+        else
+            map[i] = 1 - (u32)sliceGroupChangeDirectionFlag;
+
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: DecodeWipeMap
+
+        Functional description:
+            Function to decode wipe slice group map type, i.e. slice group map
+            type 5.
+
+        Inputs:
+            sliceGroupChangeDirectionFlag     slice_group_change_direction_flag
+            sizeOfUpperLeftGroup              mbs in upperLeftGroup
+            picWidth                          picture width in macroblocks
+            picHeight                         picture height in macroblocks
+
+        Outputs:
+            map                               slice group map is stored here
+
+        Returns:
+            none
+
+------------------------------------------------------------------------------*/
+
+void DecodeWipeMap(
+  u32 *map,
+  u32 sliceGroupChangeDirectionFlag,
+  u32 sizeOfUpperLeftGroup,
+  u32 picWidth,
+  u32 picHeight)
+{
+
+/* Variables */
+
+    u32 i,j,k;
+
+/* Code */
+
+    ASSERT(map);
+    ASSERT(picWidth);
+    ASSERT(picHeight);
+    ASSERT(sizeOfUpperLeftGroup <= picWidth * picHeight);
+
+    k = 0;
+    for (j = 0; j < picWidth; j++)
+        for (i = 0; i < picHeight; i++)
+            if (k++ < sizeOfUpperLeftGroup)
+                map[ i * picWidth + j ] = (u32)sliceGroupChangeDirectionFlag;
+            else
+                map[ i * picWidth + j ] = 1 -
+                    (u32)sliceGroupChangeDirectionFlag;
+
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdDecodeSliceGroupMap
+
+        Functional description:
+            Function to decode macroblock to slice group map. Construction
+            of different slice group map types is handled by separate
+            functions defined above. See standard for details how slice group
+            maps are computed.
+
+        Inputs:
+            pps                     active picture parameter set
+            sliceGroupChangeCycle   slice_group_change_cycle
+            picWidth                picture width in macroblocks
+            picHeight               picture height in macroblocks
+
+        Outputs:
+            map                     slice group map is stored here
+
+        Returns:
+            none
+
+------------------------------------------------------------------------------*/
+
+void h264bsdDecodeSliceGroupMap(
+  u32 *map,
+  picParamSet_t *pps,
+  u32 sliceGroupChangeCycle,
+  u32 picWidth,
+  u32 picHeight)
+{
+
+/* Variables */
+
+    u32 i, picSize, unitsInSliceGroup0 = 0, sizeOfUpperLeftGroup = 0;
+
+/* Code */
+
+    ASSERT(map);
+    ASSERT(pps);
+    ASSERT(picWidth);
+    ASSERT(picHeight);
+    ASSERT(pps->sliceGroupMapType < 7);
+
+    picSize = picWidth * picHeight;
+
+    /* just one slice group -> all macroblocks belong to group 0 */
+    if (pps->numSliceGroups == 1)
+    {
+        H264SwDecMemset(map, 0, picSize * sizeof(u32));
+        return;
+    }
+
+    if (pps->sliceGroupMapType > 2 && pps->sliceGroupMapType < 6)
+    {
+        ASSERT(pps->sliceGroupChangeRate &&
+               pps->sliceGroupChangeRate <= picSize);
+
+        unitsInSliceGroup0 =
+            MIN(sliceGroupChangeCycle * pps->sliceGroupChangeRate, picSize);
+
+        if (pps->sliceGroupMapType == 4 || pps->sliceGroupMapType == 5)
+            sizeOfUpperLeftGroup = pps->sliceGroupChangeDirectionFlag ?
+                (picSize - unitsInSliceGroup0) : unitsInSliceGroup0;
+    }
+
+    switch (pps->sliceGroupMapType)
+    {
+        case 0:
+            DecodeInterleavedMap(map, pps->numSliceGroups,
+              pps->runLength, picSize);
+            break;
+
+        case 1:
+            DecodeDispersedMap(map, pps->numSliceGroups, picWidth,
+              picHeight);
+            break;
+
+        case 2:
+            DecodeForegroundLeftOverMap(map, pps->numSliceGroups,
+              pps->topLeft, pps->bottomRight, picWidth, picHeight);
+            break;
+
+        case 3:
+            DecodeBoxOutMap(map, pps->sliceGroupChangeDirectionFlag,
+              unitsInSliceGroup0, picWidth, picHeight);
+            break;
+
+        case 4:
+            DecodeRasterScanMap(map,
+              pps->sliceGroupChangeDirectionFlag, sizeOfUpperLeftGroup,
+              picSize);
+            break;
+
+        case 5:
+            DecodeWipeMap(map, pps->sliceGroupChangeDirectionFlag,
+              sizeOfUpperLeftGroup, picWidth, picHeight);
+            break;
+
+        default:
+            ASSERT(pps->sliceGroupId);
+            for (i = 0; i < picSize; i++)
+            {
+                ASSERT(pps->sliceGroupId[i] < pps->numSliceGroups);
+                map[i] = pps->sliceGroupId[i];
+            }
+            break;
+    }
+
+}
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_slice_group_map.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_slice_group_map.h
new file mode 100755
index 0000000..4bcb6f2
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_slice_group_map.h
@@ -0,0 +1,60 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+    1. Include headers
+    2. Module defines
+    3. Data types
+    4. Function prototypes
+
+------------------------------------------------------------------------------*/
+
+#ifndef H264SWDEC_SLICE_GROUP_MAP_H
+#define H264SWDEC_SLICE_GROUP_MAP_H
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "basetype.h"
+#include "h264bsd_pic_param_set.h"
+
+/*------------------------------------------------------------------------------
+    2. Module defines
+------------------------------------------------------------------------------*/
+
+
+/*------------------------------------------------------------------------------
+    3. Data types
+------------------------------------------------------------------------------*/
+
+
+/*------------------------------------------------------------------------------
+    4. Function prototypes
+------------------------------------------------------------------------------*/
+
+void h264bsdDecodeSliceGroupMap(
+  u32 *map,
+  picParamSet_t *pps,
+  u32 sliceGroupChangeCycle,
+  u32 picWidth,
+  u32 picHeight);
+
+#endif /* #ifdef H264SWDEC_SLICE_GROUP_MAP_H */
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_slice_header.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_slice_header.c
new file mode 100755
index 0000000..a7c6f64
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_slice_header.c
@@ -0,0 +1,1511 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+     1. Include headers
+     2. External compiler flags
+     3. Module defines
+     4. Local function prototypes
+     5. Functions
+          h264bsdDecodeSliceHeader
+          NumSliceGroupChangeCycleBits
+          RefPicListReordering
+          DecRefPicMarking
+          CheckPpsId
+          CheckFrameNum
+          CheckIdrPicId
+          CheckPicOrderCntLsb
+          CheckDeltaPicOrderCntBottom
+          CheckDeltaPicOrderCnt
+          CheckRedundantPicCnt
+
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "h264bsd_slice_header.h"
+#include "h264bsd_util.h"
+#include "h264bsd_vlc.h"
+#include "h264bsd_nal_unit.h"
+#include "h264bsd_dpb.h"
+
+/*------------------------------------------------------------------------------
+    2. External compiler flags
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+    3. Module defines
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    4. Local function prototypes
+------------------------------------------------------------------------------*/
+
+static u32 RefPicListReordering(strmData_t *, refPicListReordering_t *,
+    u32, u32);
+
+static u32 NumSliceGroupChangeCycleBits(u32 picSizeInMbs,
+    u32 sliceGroupChangeRate);
+
+static u32 DecRefPicMarking(strmData_t *pStrmData,
+    decRefPicMarking_t *pDecRefPicMarking, nalUnitType_e nalUnitType,
+    u32 numRefFrames);
+
+
+/*------------------------------------------------------------------------------
+
+    Function name: h264bsdDecodeSliceHeader
+
+        Functional description:
+            Decode slice header data from the stream.
+
+        Inputs:
+            pStrmData       pointer to stream data structure
+            pSeqParamSet    pointer to active sequence parameter set
+            pPicParamSet    pointer to active picture parameter set
+            pNalUnit        pointer to current NAL unit structure
+
+        Outputs:
+            pSliceHeader    decoded data is stored here
+
+        Returns:
+            HANTRO_OK       success
+            HANTRO_NOK      invalid stream data or end of stream
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdDecodeSliceHeader(strmData_t *pStrmData, sliceHeader_t *pSliceHeader,
+    seqParamSet_t *pSeqParamSet, picParamSet_t *pPicParamSet,
+    nalUnit_t *pNalUnit)
+{
+
+/* Variables */
+
+    u32 tmp, i, value;
+    i32 itmp;
+    u32 picSizeInMbs;
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(pSliceHeader);
+    ASSERT(pSeqParamSet);
+    ASSERT(pPicParamSet);
+    ASSERT( pNalUnit->nalUnitType == NAL_CODED_SLICE ||
+            pNalUnit->nalUnitType == NAL_CODED_SLICE_IDR );
+
+
+    H264SwDecMemset(pSliceHeader, 0, sizeof(sliceHeader_t));
+
+    picSizeInMbs = pSeqParamSet->picWidthInMbs * pSeqParamSet->picHeightInMbs;
+    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+    pSliceHeader->firstMbInSlice = value;
+    if (value >= picSizeInMbs)
+    {
+        EPRINT("first_mb_in_slice");
+        return(HANTRO_NOK);
+    }
+
+    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+    pSliceHeader->sliceType = value;
+    /* slice type has to be either I or P slice. P slice is not allowed when
+     * current NAL unit is an IDR NAL unit or num_ref_frames is 0 */
+    if ( !IS_I_SLICE(pSliceHeader->sliceType) &&
+         ( !IS_P_SLICE(pSliceHeader->sliceType) ||
+           IS_IDR_NAL_UNIT(pNalUnit) ||
+           !pSeqParamSet->numRefFrames ) )
+    {
+        EPRINT("slice_type");
+        return(HANTRO_NOK);
+    }
+
+    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+    pSliceHeader->picParameterSetId = value;
+    if (pSliceHeader->picParameterSetId != pPicParamSet->picParameterSetId)
+    {
+        EPRINT("pic_parameter_set_id");
+        return(HANTRO_NOK);
+    }
+
+    /* log2(maxFrameNum) -> num bits to represent frame_num */
+    i = 0;
+    while (pSeqParamSet->maxFrameNum >> i)
+        i++;
+    i--;
+
+    tmp = h264bsdGetBits(pStrmData, i);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    if (IS_IDR_NAL_UNIT(pNalUnit) && tmp != 0)
+    {
+        EPRINT("frame_num");
+        return(HANTRO_NOK);
+    }
+    pSliceHeader->frameNum = tmp;
+
+    if (IS_IDR_NAL_UNIT(pNalUnit))
+    {
+        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+        pSliceHeader->idrPicId = value;
+        if (value > 65535)
+        {
+            EPRINT("idr_pic_id");
+            return(HANTRO_NOK);
+        }
+    }
+
+    if (pSeqParamSet->picOrderCntType == 0)
+    {
+        /* log2(maxPicOrderCntLsb) -> num bits to represent pic_order_cnt_lsb */
+        i = 0;
+        while (pSeqParamSet->maxPicOrderCntLsb >> i)
+            i++;
+        i--;
+
+        tmp = h264bsdGetBits(pStrmData, i);
+        if (tmp == END_OF_STREAM)
+            return(HANTRO_NOK);
+        pSliceHeader->picOrderCntLsb = tmp;
+
+        if (pPicParamSet->picOrderPresentFlag)
+        {
+            tmp = h264bsdDecodeExpGolombSigned(pStrmData, &itmp);
+            if (tmp != HANTRO_OK)
+                return(tmp);
+            pSliceHeader->deltaPicOrderCntBottom = itmp;
+        }
+
+        /* check that picOrderCnt for IDR picture will be zero. See
+         * DecodePicOrderCnt function to understand the logic here */
+        if ( IS_IDR_NAL_UNIT(pNalUnit) &&
+             ( (pSliceHeader->picOrderCntLsb >
+                pSeqParamSet->maxPicOrderCntLsb/2) ||
+                MIN((i32)pSliceHeader->picOrderCntLsb,
+                    (i32)pSliceHeader->picOrderCntLsb +
+                    pSliceHeader->deltaPicOrderCntBottom) != 0 ) )
+        {
+            return(HANTRO_NOK);
+        }
+    }
+
+    if ( (pSeqParamSet->picOrderCntType == 1) &&
+         !pSeqParamSet->deltaPicOrderAlwaysZeroFlag )
+    {
+        tmp = h264bsdDecodeExpGolombSigned(pStrmData, &itmp);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+        pSliceHeader->deltaPicOrderCnt[0] = itmp;
+
+        if (pPicParamSet->picOrderPresentFlag)
+        {
+            tmp = h264bsdDecodeExpGolombSigned(pStrmData, &itmp);
+            if (tmp != HANTRO_OK)
+                return(tmp);
+            pSliceHeader->deltaPicOrderCnt[1] = itmp;
+        }
+
+        /* check that picOrderCnt for IDR picture will be zero. See
+         * DecodePicOrderCnt function to understand the logic here */
+        if ( IS_IDR_NAL_UNIT(pNalUnit) &&
+             MIN(pSliceHeader->deltaPicOrderCnt[0],
+                 pSliceHeader->deltaPicOrderCnt[0] +
+                 pSeqParamSet->offsetForTopToBottomField +
+                 pSliceHeader->deltaPicOrderCnt[1]) != 0)
+        {
+            return(HANTRO_NOK);
+        }
+    }
+
+    if (pPicParamSet->redundantPicCntPresentFlag)
+    {
+        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+        pSliceHeader->redundantPicCnt = value;
+        if (value > 127)
+        {
+            EPRINT("redundant_pic_cnt");
+            return(HANTRO_NOK);
+        }
+    }
+
+    if (IS_P_SLICE(pSliceHeader->sliceType))
+    {
+        tmp = h264bsdGetBits(pStrmData, 1);
+        if (tmp == END_OF_STREAM)
+            return(HANTRO_NOK);
+        pSliceHeader->numRefIdxActiveOverrideFlag = tmp;
+
+        if (pSliceHeader->numRefIdxActiveOverrideFlag)
+        {
+            tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);
+            if (tmp != HANTRO_OK)
+                return(tmp);
+            if (value > 15)
+            {
+                EPRINT("num_ref_idx_l0_active_minus1");
+                return(HANTRO_NOK);
+            }
+            pSliceHeader->numRefIdxL0Active = value + 1;
+        }
+        /* set numRefIdxL0Active from pic param set */
+        else
+        {
+            /* if value (minus1) in picture parameter set exceeds 15 it should
+             * have been overridden here */
+            if (pPicParamSet->numRefIdxL0Active > 16)
+            {
+                EPRINT("num_ref_idx_active_override_flag");
+                return(HANTRO_NOK);
+            }
+            pSliceHeader->numRefIdxL0Active = pPicParamSet->numRefIdxL0Active;
+        }
+    }
+
+    if (IS_P_SLICE(pSliceHeader->sliceType))
+    {
+        tmp = RefPicListReordering(pStrmData,
+            &pSliceHeader->refPicListReordering,
+            pSliceHeader->numRefIdxL0Active,
+            pSeqParamSet->maxFrameNum);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+    }
+
+    if (pNalUnit->nalRefIdc != 0)
+    {
+        tmp = DecRefPicMarking(pStrmData, &pSliceHeader->decRefPicMarking,
+            pNalUnit->nalUnitType, pSeqParamSet->numRefFrames);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+    }
+
+    /* decode sliceQpDelta and check that initial QP for the slice will be on
+     * the range [0, 51] */
+    tmp = h264bsdDecodeExpGolombSigned(pStrmData, &itmp);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+    pSliceHeader->sliceQpDelta = itmp;
+    itmp += (i32)pPicParamSet->picInitQp;
+    if ( (itmp < 0) || (itmp > 51) )
+    {
+        EPRINT("slice_qp_delta");
+        return(HANTRO_NOK);
+    }
+
+    if (pPicParamSet->deblockingFilterControlPresentFlag)
+    {
+        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+        pSliceHeader->disableDeblockingFilterIdc = value;
+        if (pSliceHeader->disableDeblockingFilterIdc > 2)
+        {
+            EPRINT("disable_deblocking_filter_idc");
+            return(HANTRO_NOK);
+        }
+
+        if (pSliceHeader->disableDeblockingFilterIdc != 1)
+        {
+            tmp = h264bsdDecodeExpGolombSigned(pStrmData, &itmp);
+            if (tmp != HANTRO_OK)
+                return(tmp);
+            if ( (itmp < -6) || (itmp > 6) )
+            {
+               EPRINT("slice_alpha_c0_offset_div2");
+               return(HANTRO_NOK);
+            }
+            pSliceHeader->sliceAlphaC0Offset = itmp * 2;
+
+            tmp = h264bsdDecodeExpGolombSigned(pStrmData, &itmp);
+            if (tmp != HANTRO_OK)
+                return(tmp);
+            if ( (itmp < -6) || (itmp > 6) )
+            {
+               EPRINT("slice_beta_offset_div2");
+               return(HANTRO_NOK);
+            }
+            pSliceHeader->sliceBetaOffset = itmp * 2;
+        }
+    }
+
+    if ( (pPicParamSet->numSliceGroups > 1) &&
+         (pPicParamSet->sliceGroupMapType >= 3) &&
+         (pPicParamSet->sliceGroupMapType <= 5) )
+    {
+        /* set tmp to number of bits used to represent slice_group_change_cycle
+         * in the stream */
+        tmp = NumSliceGroupChangeCycleBits(picSizeInMbs,
+            pPicParamSet->sliceGroupChangeRate);
+        value = h264bsdGetBits(pStrmData, tmp);
+        if (value == END_OF_STREAM)
+            return(HANTRO_NOK);
+        pSliceHeader->sliceGroupChangeCycle = value;
+
+        /* corresponds to tmp = Ceil(picSizeInMbs / sliceGroupChangeRate) */
+        tmp = (picSizeInMbs + pPicParamSet->sliceGroupChangeRate - 1) /
+              pPicParamSet->sliceGroupChangeRate;
+        if (pSliceHeader->sliceGroupChangeCycle > tmp)
+        {
+            EPRINT("slice_group_change_cycle");
+            return(HANTRO_NOK);
+        }
+    }
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: NumSliceGroupChangeCycleBits
+
+        Functional description:
+            Determine number of bits needed to represent
+            slice_group_change_cycle in the stream. The standard states that
+            slice_group_change_cycle is represented by
+                Ceil( Log2( (picSizeInMbs / sliceGroupChangeRate) + 1) )
+
+            bits. Division "/" in the equation is non-truncating division.
+
+        Inputs:
+            picSizeInMbs            picture size in macroblocks
+            sliceGroupChangeRate
+
+        Outputs:
+            none
+
+        Returns:
+            number of bits needed
+
+------------------------------------------------------------------------------*/
+
+u32 NumSliceGroupChangeCycleBits(u32 picSizeInMbs, u32 sliceGroupChangeRate)
+{
+
+/* Variables */
+
+    u32 tmp,numBits,mask;
+
+/* Code */
+
+    ASSERT(picSizeInMbs);
+    ASSERT(sliceGroupChangeRate);
+    ASSERT(sliceGroupChangeRate <= picSizeInMbs);
+
+    /* compute (picSizeInMbs / sliceGroupChangeRate + 1), rounded up */
+    if (picSizeInMbs % sliceGroupChangeRate)
+        tmp = 2 + picSizeInMbs/sliceGroupChangeRate;
+    else
+        tmp = 1 + picSizeInMbs/sliceGroupChangeRate;
+
+    numBits = 0;
+    mask = ~0U;
+
+    /* set numBits to position of right-most non-zero bit */
+    while (tmp & (mask<<++numBits))
+        ;
+    numBits--;
+
+    /* add one more bit if value greater than 2^numBits */
+    if (tmp & ((1<<numBits)-1))
+        numBits++;
+
+    return(numBits);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: RefPicListReordering
+
+        Functional description:
+            Decode reference picture list reordering syntax elements from
+            the stream. Max number of reordering commands is numRefIdxActive.
+
+        Inputs:
+            pStrmData       pointer to stream data structure
+            numRefIdxActive number of active reference indices to be used for
+                            current slice
+            maxPicNum       maxFrameNum from the active SPS
+
+        Outputs:
+            pRefPicListReordering   decoded data is stored here
+
+        Returns:
+            HANTRO_OK       success
+            HANTRO_NOK      invalid stream data
+
+------------------------------------------------------------------------------*/
+
+u32 RefPicListReordering(strmData_t *pStrmData,
+    refPicListReordering_t *pRefPicListReordering, u32 numRefIdxActive,
+    u32 maxPicNum)
+{
+
+/* Variables */
+
+    u32 tmp, value, i;
+    u32 command;
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(pRefPicListReordering);
+    ASSERT(numRefIdxActive);
+    ASSERT(maxPicNum);
+
+
+    tmp = h264bsdGetBits(pStrmData, 1);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+
+    pRefPicListReordering->refPicListReorderingFlagL0 = tmp;
+
+    if (pRefPicListReordering->refPicListReorderingFlagL0)
+    {
+        i = 0;
+
+        do
+        {
+            if (i > numRefIdxActive)
+            {
+                EPRINT("Too many reordering commands");
+                return(HANTRO_NOK);
+            }
+
+            tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &command);
+            if (tmp != HANTRO_OK)
+                return(tmp);
+            if (command > 3)
+            {
+                EPRINT("reordering_of_pic_nums_idc");
+                return(HANTRO_NOK);
+            }
+
+            pRefPicListReordering->command[i].reorderingOfPicNumsIdc = command;
+
+            if ((command == 0) || (command == 1))
+            {
+                tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);
+                if (tmp != HANTRO_OK)
+                    return(tmp);
+                if (value >= maxPicNum)
+                {
+                    EPRINT("abs_diff_pic_num_minus1");
+                    return(HANTRO_NOK);
+                }
+                pRefPicListReordering->command[i].absDiffPicNum = value + 1;
+                            }
+            else if (command == 2)
+            {
+                tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);
+                if (tmp != HANTRO_OK)
+                    return(tmp);
+                pRefPicListReordering->command[i].longTermPicNum = value;
+                            }
+            i++;
+        } while (command != 3);
+
+        /* there shall be at least one reordering command if
+         * refPicListReorderingFlagL0 was set */
+        if (i == 1)
+        {
+            EPRINT("ref_pic_list_reordering");
+            return(HANTRO_NOK);
+        }
+    }
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: DecRefPicMarking
+
+        Functional description:
+            Decode decoded reference picture marking syntax elements from
+            the stream.
+
+        Inputs:
+            pStrmData       pointer to stream data structure
+            nalUnitType     type of the current NAL unit
+            numRefFrames    max number of reference frames from the active SPS
+
+        Outputs:
+            pDecRefPicMarking   decoded data is stored here
+
+        Returns:
+            HANTRO_OK       success
+            HANTRO_NOK      invalid stream data
+
+------------------------------------------------------------------------------*/
+
+u32 DecRefPicMarking(strmData_t *pStrmData,
+    decRefPicMarking_t *pDecRefPicMarking, nalUnitType_e nalUnitType,
+    u32 numRefFrames)
+{
+
+/* Variables */
+
+    u32 tmp, value;
+    u32 i;
+    u32 operation;
+    /* variables for error checking purposes, store number of memory
+     * management operations of certain type */
+    u32 num4 = 0, num5 = 0, num6 = 0, num1to3 = 0;
+
+/* Code */
+
+    ASSERT( nalUnitType == NAL_CODED_SLICE_IDR ||
+            nalUnitType == NAL_CODED_SLICE ||
+            nalUnitType == NAL_SEI );
+
+
+    if (nalUnitType == NAL_CODED_SLICE_IDR)
+    {
+        tmp = h264bsdGetBits(pStrmData, 1);
+        if (tmp == END_OF_STREAM)
+            return(HANTRO_NOK);
+        pDecRefPicMarking->noOutputOfPriorPicsFlag = tmp;
+
+        tmp = h264bsdGetBits(pStrmData, 1);
+        if (tmp == END_OF_STREAM)
+            return(HANTRO_NOK);
+        pDecRefPicMarking->longTermReferenceFlag = tmp;
+        if (!numRefFrames && pDecRefPicMarking->longTermReferenceFlag)
+        {
+            EPRINT("long_term_reference_flag");
+            return(HANTRO_NOK);
+        }
+    }
+    else
+    {
+        tmp = h264bsdGetBits(pStrmData, 1);
+        if (tmp == END_OF_STREAM)
+            return(HANTRO_NOK);
+        pDecRefPicMarking->adaptiveRefPicMarkingModeFlag = tmp;
+        if (pDecRefPicMarking->adaptiveRefPicMarkingModeFlag)
+        {
+            i = 0;
+            do
+            {
+                /* see explanation of the MAX_NUM_MMC_OPERATIONS in
+                 * slice_header.h */
+                if (i > (2 * numRefFrames + 2))
+                {
+                    EPRINT("Too many management operations");
+                    return(HANTRO_NOK);
+                }
+
+                tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &operation);
+                if (tmp != HANTRO_OK)
+                    return(tmp);
+                if (operation > 6)
+                {
+                    EPRINT("memory_management_control_operation");
+                    return(HANTRO_NOK);
+                }
+
+                pDecRefPicMarking->operation[i].
+                    memoryManagementControlOperation = operation;
+                if ((operation == 1) || (operation == 3))
+                {
+                    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);
+                    if (tmp != HANTRO_OK)
+                        return(tmp);
+                    pDecRefPicMarking->operation[i].differenceOfPicNums =
+                        value + 1;
+                }
+                if (operation == 2)
+                {
+                    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);
+                    if (tmp != HANTRO_OK)
+                        return(tmp);
+                    pDecRefPicMarking->operation[i].longTermPicNum = value;
+                }
+                if ((operation == 3) || (operation == 6))
+                {
+                    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);
+                    if (tmp != HANTRO_OK)
+                        return(tmp);
+                    pDecRefPicMarking->operation[i].longTermFrameIdx =
+                        value;
+                }
+                if (operation == 4)
+                {
+                    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);
+                    if (tmp != HANTRO_OK)
+                        return(tmp);
+                    /* value shall be in range [0, numRefFrames] */
+                    if (value > numRefFrames)
+                    {
+                        EPRINT("max_long_term_frame_idx_plus1");
+                        return(HANTRO_NOK);
+                    }
+                    if (value == 0)
+                    {
+                        pDecRefPicMarking->operation[i].
+                            maxLongTermFrameIdx =
+                            NO_LONG_TERM_FRAME_INDICES;
+                    }
+                    else
+                    {
+                        pDecRefPicMarking->operation[i].
+                            maxLongTermFrameIdx = value - 1;
+                    }
+                    num4++;
+                }
+                if (operation == 5)
+                {
+                    num5++;
+                }
+                if (operation && operation <= 3)
+                    num1to3++;
+                if (operation == 6)
+                    num6++;
+
+                i++;
+            } while (operation != 0);
+
+            /* error checking */
+            if (num4 > 1 || num5 > 1 || num6 > 1 || (num1to3 && num5))
+                return(HANTRO_NOK);
+
+        }
+    }
+
+    return(HANTRO_OK);
+}
+
+/*------------------------------------------------------------------------------
+
+    Function name: h264bsdCheckPpsId
+
+        Functional description:
+            Peek value of pic_parameter_set_id from the slice header. Function
+            does not modify current stream positions but copies the stream
+            data structure to tmp structure which is used while accessing
+            stream data.
+
+        Inputs:
+            pStrmData       pointer to stream data structure
+
+        Outputs:
+            picParamSetId   value is stored here
+
+        Returns:
+            HANTRO_OK       success
+            HANTRO_NOK      invalid stream data
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdCheckPpsId(strmData_t *pStrmData, u32 *picParamSetId)
+{
+
+/* Variables */
+
+    u32 tmp, value;
+    strmData_t tmpStrmData[1];
+
+/* Code */
+
+    ASSERT(pStrmData);
+
+    /* don't touch original stream position params */
+    *tmpStrmData = *pStrmData;
+
+    /* first_mb_in_slice */
+    tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+
+    /* slice_type */
+    tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+
+    tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+    if (value >= MAX_NUM_PIC_PARAM_SETS)
+        return(HANTRO_NOK);
+
+    *picParamSetId = value;
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdCheckFrameNum
+
+        Functional description:
+            Peek value of frame_num from the slice header. Function does not
+            modify current stream positions but copies the stream data
+            structure to tmp structure which is used while accessing stream
+            data.
+
+        Inputs:
+            pStrmData       pointer to stream data structure
+            maxFrameNum
+
+        Outputs:
+            frameNum        value is stored here
+
+        Returns:
+            HANTRO_OK       success
+            HANTRO_NOK      invalid stream data
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdCheckFrameNum(
+  strmData_t *pStrmData,
+  u32 maxFrameNum,
+  u32 *frameNum)
+{
+
+/* Variables */
+
+    u32 tmp, value, i;
+    strmData_t tmpStrmData[1];
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(maxFrameNum);
+    ASSERT(frameNum);
+
+    /* don't touch original stream position params */
+    *tmpStrmData = *pStrmData;
+
+    /* skip first_mb_in_slice */
+    tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+
+    /* skip slice_type */
+    tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+
+    /* skip pic_parameter_set_id */
+    tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+
+    /* log2(maxFrameNum) -> num bits to represent frame_num */
+    i = 0;
+    while (maxFrameNum >> i)
+        i++;
+    i--;
+
+    /* frame_num */
+    tmp = h264bsdGetBits(tmpStrmData, i);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    *frameNum = tmp;
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdCheckIdrPicId
+
+        Functional description:
+            Peek value of idr_pic_id from the slice header. Function does not
+            modify current stream positions but copies the stream data
+            structure to tmp structure which is used while accessing stream
+            data.
+
+        Inputs:
+            pStrmData       pointer to stream data structure
+            maxFrameNum     max frame number from active SPS
+            nalUnitType     type of the current NAL unit
+
+        Outputs:
+            idrPicId        value is stored here
+
+        Returns:
+            HANTRO_OK       success
+            HANTRO_NOK      invalid stream data
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdCheckIdrPicId(
+  strmData_t *pStrmData,
+  u32 maxFrameNum,
+  nalUnitType_e nalUnitType,
+  u32 *idrPicId)
+{
+
+/* Variables */
+
+    u32 tmp, value, i;
+    strmData_t tmpStrmData[1];
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(maxFrameNum);
+    ASSERT(idrPicId);
+
+    /* nalUnitType must be equal to 5 because otherwise idrPicId is not
+     * present */
+    if (nalUnitType != NAL_CODED_SLICE_IDR)
+        return(HANTRO_NOK);
+
+    /* don't touch original stream position params */
+    *tmpStrmData = *pStrmData;
+
+    /* skip first_mb_in_slice */
+    tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+
+    /* skip slice_type */
+    tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+
+    /* skip pic_parameter_set_id */
+    tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+
+    /* log2(maxFrameNum) -> num bits to represent frame_num */
+    i = 0;
+    while (maxFrameNum >> i)
+        i++;
+    i--;
+
+    /* skip frame_num */
+    tmp = h264bsdGetBits(tmpStrmData, i);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+
+    /* idr_pic_id */
+    tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, idrPicId);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdCheckPicOrderCntLsb
+
+        Functional description:
+            Peek value of pic_order_cnt_lsb from the slice header. Function
+            does not modify current stream positions but copies the stream
+            data structure to tmp structure which is used while accessing
+            stream data.
+
+        Inputs:
+            pStrmData       pointer to stream data structure
+            pSeqParamSet    pointer to active SPS
+            nalUnitType     type of the current NAL unit
+
+        Outputs:
+            picOrderCntLsb  value is stored here
+
+        Returns:
+            HANTRO_OK       success
+            HANTRO_NOK      invalid stream data
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdCheckPicOrderCntLsb(
+  strmData_t *pStrmData,
+  seqParamSet_t *pSeqParamSet,
+  nalUnitType_e nalUnitType,
+  u32 *picOrderCntLsb)
+{
+
+/* Variables */
+
+    u32 tmp, value, i;
+    strmData_t tmpStrmData[1];
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(pSeqParamSet);
+    ASSERT(picOrderCntLsb);
+
+    /* picOrderCntType must be equal to 0 */
+    ASSERT(pSeqParamSet->picOrderCntType == 0);
+    ASSERT(pSeqParamSet->maxFrameNum);
+    ASSERT(pSeqParamSet->maxPicOrderCntLsb);
+
+    /* don't touch original stream position params */
+    *tmpStrmData = *pStrmData;
+
+    /* skip first_mb_in_slice */
+    tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+
+    /* skip slice_type */
+    tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+
+    /* skip pic_parameter_set_id */
+    tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+
+    /* log2(maxFrameNum) -> num bits to represent frame_num */
+    i = 0;
+    while (pSeqParamSet->maxFrameNum >> i)
+        i++;
+    i--;
+
+    /* skip frame_num */
+    tmp = h264bsdGetBits(tmpStrmData, i);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+
+    /* skip idr_pic_id when necessary */
+    if (nalUnitType == NAL_CODED_SLICE_IDR)
+    {
+        tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+    }
+
+    /* log2(maxPicOrderCntLsb) -> num bits to represent pic_order_cnt_lsb */
+    i = 0;
+    while (pSeqParamSet->maxPicOrderCntLsb >> i)
+        i++;
+    i--;
+
+    /* pic_order_cnt_lsb */
+    tmp = h264bsdGetBits(tmpStrmData, i);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    *picOrderCntLsb = tmp;
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdCheckDeltaPicOrderCntBottom
+
+        Functional description:
+            Peek value of delta_pic_order_cnt_bottom from the slice header.
+            Function does not modify current stream positions but copies the
+            stream data structure to tmp structure which is used while
+            accessing stream data.
+
+        Inputs:
+            pStrmData       pointer to stream data structure
+            pSeqParamSet    pointer to active SPS
+            nalUnitType     type of the current NAL unit
+
+        Outputs:
+            deltaPicOrderCntBottom  value is stored here
+
+        Returns:
+            HANTRO_OK       success
+            HANTRO_NOK      invalid stream data
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdCheckDeltaPicOrderCntBottom(
+  strmData_t *pStrmData,
+  seqParamSet_t *pSeqParamSet,
+  nalUnitType_e nalUnitType,
+  i32 *deltaPicOrderCntBottom)
+{
+
+/* Variables */
+
+    u32 tmp, value, i;
+    strmData_t tmpStrmData[1];
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(pSeqParamSet);
+    ASSERT(deltaPicOrderCntBottom);
+
+    /* picOrderCntType must be equal to 0 and picOrderPresentFlag must be TRUE
+     * */
+    ASSERT(pSeqParamSet->picOrderCntType == 0);
+    ASSERT(pSeqParamSet->maxFrameNum);
+    ASSERT(pSeqParamSet->maxPicOrderCntLsb);
+
+    /* don't touch original stream position params */
+    *tmpStrmData = *pStrmData;
+
+    /* skip first_mb_in_slice */
+    tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+
+    /* skip slice_type */
+    tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+
+    /* skip pic_parameter_set_id */
+    tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+
+    /* log2(maxFrameNum) -> num bits to represent frame_num */
+    i = 0;
+    while (pSeqParamSet->maxFrameNum >> i)
+        i++;
+    i--;
+
+    /* skip frame_num */
+    tmp = h264bsdGetBits(tmpStrmData, i);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+
+    /* skip idr_pic_id when necessary */
+    if (nalUnitType == NAL_CODED_SLICE_IDR)
+    {
+        tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+    }
+
+    /* log2(maxPicOrderCntLsb) -> num bits to represent pic_order_cnt_lsb */
+    i = 0;
+    while (pSeqParamSet->maxPicOrderCntLsb >> i)
+        i++;
+    i--;
+
+    /* skip pic_order_cnt_lsb */
+    tmp = h264bsdGetBits(tmpStrmData, i);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+
+    /* delta_pic_order_cnt_bottom */
+    tmp = h264bsdDecodeExpGolombSigned(tmpStrmData, deltaPicOrderCntBottom);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdCheckDeltaPicOrderCnt
+
+        Functional description:
+            Peek values delta_pic_order_cnt[0] and delta_pic_order_cnt[1]
+            from the slice header. Function does not modify current stream
+            positions but copies the stream data structure to tmp structure
+            which is used while accessing stream data.
+
+        Inputs:
+            pStrmData               pointer to stream data structure
+            pSeqParamSet            pointer to active SPS
+            nalUnitType             type of the current NAL unit
+            picOrderPresentFlag     flag indicating if delta_pic_order_cnt[1]
+                                    is present in the stream
+
+        Outputs:
+            deltaPicOrderCnt        values are stored here
+
+        Returns:
+            HANTRO_OK               success
+            HANTRO_NOK              invalid stream data
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdCheckDeltaPicOrderCnt(
+  strmData_t *pStrmData,
+  seqParamSet_t *pSeqParamSet,
+  nalUnitType_e nalUnitType,
+  u32 picOrderPresentFlag,
+  i32 *deltaPicOrderCnt)
+{
+
+/* Variables */
+
+    u32 tmp, value, i;
+    strmData_t tmpStrmData[1];
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(pSeqParamSet);
+    ASSERT(deltaPicOrderCnt);
+
+    /* picOrderCntType must be equal to 1 and deltaPicOrderAlwaysZeroFlag must
+     * be FALSE */
+    ASSERT(pSeqParamSet->picOrderCntType == 1);
+    ASSERT(!pSeqParamSet->deltaPicOrderAlwaysZeroFlag);
+    ASSERT(pSeqParamSet->maxFrameNum);
+
+    /* don't touch original stream position params */
+    *tmpStrmData = *pStrmData;
+
+    /* skip first_mb_in_slice */
+    tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+
+    /* skip slice_type */
+    tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+
+    /* skip pic_parameter_set_id */
+    tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+
+    /* log2(maxFrameNum) -> num bits to represent frame_num */
+    i = 0;
+    while (pSeqParamSet->maxFrameNum >> i)
+        i++;
+    i--;
+
+    /* skip frame_num */
+    tmp = h264bsdGetBits(tmpStrmData, i);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+
+    /* skip idr_pic_id when necessary */
+    if (nalUnitType == NAL_CODED_SLICE_IDR)
+    {
+        tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+    }
+
+    /* delta_pic_order_cnt[0] */
+    tmp = h264bsdDecodeExpGolombSigned(tmpStrmData, &deltaPicOrderCnt[0]);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+
+    /* delta_pic_order_cnt[1] if present */
+    if (picOrderPresentFlag)
+    {
+        tmp = h264bsdDecodeExpGolombSigned(tmpStrmData, &deltaPicOrderCnt[1]);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+    }
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdCheckRedundantPicCnt
+
+        Functional description:
+            Peek value of redundant_pic_cnt from the slice header. Function
+            does not modify current stream positions but copies the stream
+            data structure to tmp structure which is used while accessing
+            stream data.
+
+        Inputs:
+            pStrmData       pointer to stream data structure
+            pSeqParamSet    pointer to active SPS
+            pPicParamSet    pointer to active PPS
+            nalUnitType     type of the current NAL unit
+
+        Outputs:
+            redundantPicCnt value is stored here
+
+        Returns:
+            HANTRO_OK       success
+            HANTRO_NOK      invalid stream data
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdCheckRedundantPicCnt(
+  strmData_t *pStrmData,
+  seqParamSet_t *pSeqParamSet,
+  picParamSet_t *pPicParamSet,
+  nalUnitType_e nalUnitType,
+  u32 *redundantPicCnt)
+{
+
+/* Variables */
+
+    u32 tmp, value, i;
+    i32 ivalue;
+    strmData_t tmpStrmData[1];
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(pSeqParamSet);
+    ASSERT(pPicParamSet);
+    ASSERT(redundantPicCnt);
+
+    /* redundant_pic_cnt_flag must be TRUE */
+    ASSERT(pPicParamSet->redundantPicCntPresentFlag);
+    ASSERT(pSeqParamSet->maxFrameNum);
+    ASSERT(pSeqParamSet->picOrderCntType > 0 ||
+           pSeqParamSet->maxPicOrderCntLsb);
+
+    /* don't touch original stream position params */
+    *tmpStrmData = *pStrmData;
+
+    /* skip first_mb_in_slice */
+    tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+
+    /* skip slice_type */
+    tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+
+    /* skip pic_parameter_set_id */
+    tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+
+    /* log2(maxFrameNum) -> num bits to represent frame_num */
+    i = 0;
+    while (pSeqParamSet->maxFrameNum >> i)
+        i++;
+    i--;
+
+    /* skip frame_num */
+    tmp = h264bsdGetBits(tmpStrmData, i);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+
+    /* skip idr_pic_id when necessary */
+    if (nalUnitType == NAL_CODED_SLICE_IDR)
+    {
+        tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+    }
+
+    if (pSeqParamSet->picOrderCntType == 0)
+    {
+        /* log2(maxPicOrderCntLsb) -> num bits to represent pic_order_cnt_lsb */
+        i = 0;
+        while (pSeqParamSet->maxPicOrderCntLsb >> i)
+            i++;
+        i--;
+
+        /* pic_order_cnt_lsb */
+        tmp = h264bsdGetBits(tmpStrmData, i);
+        if (tmp == END_OF_STREAM)
+            return(HANTRO_NOK);
+
+        if (pPicParamSet->picOrderPresentFlag)
+        {
+            /* skip delta_pic_order_cnt_bottom */
+            tmp = h264bsdDecodeExpGolombSigned(tmpStrmData, &ivalue);
+            if (tmp != HANTRO_OK)
+                return(tmp);
+        }
+    }
+
+    if (pSeqParamSet->picOrderCntType == 1 &&
+      !pSeqParamSet->deltaPicOrderAlwaysZeroFlag)
+    {
+        /* delta_pic_order_cnt[0] */
+        tmp = h264bsdDecodeExpGolombSigned(tmpStrmData, &ivalue);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+
+        /* delta_pic_order_cnt[1] if present */
+        if (pPicParamSet->picOrderPresentFlag)
+        {
+            tmp = h264bsdDecodeExpGolombSigned(tmpStrmData, &ivalue);
+            if (tmp != HANTRO_OK)
+                return(tmp);
+        }
+    }
+
+    /* redundant_pic_cnt */
+    tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, redundantPicCnt);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+
+    return(HANTRO_OK);
+
+}
+
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdCheckPriorPicsFlag
+
+        Functional description:
+            Peek value of no_output_of_prior_pics_flag from the slice header.
+            Function does not modify current stream positions but copies
+            the stream data structure to tmp structure which is used while
+            accessing stream data.
+
+        Inputs:
+            pStrmData       pointer to stream data structure
+            pSeqParamSet    pointer to active SPS
+            pPicParamSet    pointer to active PPS
+            nalUnitType     type of the current NAL unit
+
+        Outputs:
+            noOutputOfPriorPicsFlag value is stored here
+
+        Returns:
+            HANTRO_OK       success
+            HANTRO_NOK      invalid stream data
+
+------------------------------------------------------------------------------*/
+/*lint -e715 disable lint info nalUnitType not referenced */
+u32 h264bsdCheckPriorPicsFlag(u32 * noOutputOfPriorPicsFlag,
+                              const strmData_t * pStrmData,
+                              const seqParamSet_t * pSeqParamSet,
+                              const picParamSet_t * pPicParamSet,
+                              nalUnitType_e nalUnitType)
+{
+/* Variables */
+
+    u32 tmp, value, i;
+    i32 ivalue;
+    strmData_t tmpStrmData[1];
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(pSeqParamSet);
+    ASSERT(pPicParamSet);
+    ASSERT(noOutputOfPriorPicsFlag);
+
+    /* must be IDR lsice */
+    ASSERT(nalUnitType == NAL_CODED_SLICE_IDR);
+
+    /* don't touch original stream position params */
+    *tmpStrmData = *pStrmData;
+
+    /* skip first_mb_in_slice */
+    tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
+    if(tmp != HANTRO_OK)
+        return (tmp);
+
+    /* slice_type */
+    tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
+    if(tmp != HANTRO_OK)
+        return (tmp);
+
+    /* skip pic_parameter_set_id */
+    tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
+    if(tmp != HANTRO_OK)
+        return (tmp);
+
+    /* log2(maxFrameNum) -> num bits to represent frame_num */
+    i = 0;
+    while(pSeqParamSet->maxFrameNum >> i)
+        i++;
+    i--;
+
+    /* skip frame_num */
+    tmp = h264bsdGetBits(tmpStrmData, i);
+    if(tmp == END_OF_STREAM)
+        return (HANTRO_NOK);
+
+    /* skip idr_pic_id */
+    tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
+    if(tmp != HANTRO_OK)
+        return (tmp);
+
+    if(pSeqParamSet->picOrderCntType == 0)
+    {
+        /* log2(maxPicOrderCntLsb) -> num bits to represent pic_order_cnt_lsb */
+        i = 0;
+        while(pSeqParamSet->maxPicOrderCntLsb >> i)
+            i++;
+        i--;
+
+        /* skip pic_order_cnt_lsb */
+        tmp = h264bsdGetBits(tmpStrmData, i);
+        if(tmp == END_OF_STREAM)
+            return (HANTRO_NOK);
+
+        if(pPicParamSet->picOrderPresentFlag)
+        {
+            /* skip delta_pic_order_cnt_bottom */
+            tmp = h264bsdDecodeExpGolombSigned(tmpStrmData, &ivalue);
+            if(tmp != HANTRO_OK)
+                return (tmp);
+        }
+    }
+
+    if(pSeqParamSet->picOrderCntType == 1 &&
+       !pSeqParamSet->deltaPicOrderAlwaysZeroFlag)
+    {
+        /* skip delta_pic_order_cnt[0] */
+        tmp = h264bsdDecodeExpGolombSigned(tmpStrmData, &ivalue);
+        if(tmp != HANTRO_OK)
+            return (tmp);
+
+        /* skip delta_pic_order_cnt[1] if present */
+        if(pPicParamSet->picOrderPresentFlag)
+        {
+            tmp = h264bsdDecodeExpGolombSigned(tmpStrmData, &ivalue);
+            if(tmp != HANTRO_OK)
+                return (tmp);
+        }
+    }
+
+    /* skip redundant_pic_cnt */
+    if(pPicParamSet->redundantPicCntPresentFlag)
+    {
+        tmp = h264bsdDecodeExpGolombUnsigned(tmpStrmData, &value);
+        if(tmp != HANTRO_OK)
+            return (tmp);
+    }
+
+    *noOutputOfPriorPicsFlag = h264bsdGetBits(tmpStrmData, 1);
+    if(*noOutputOfPriorPicsFlag == END_OF_STREAM)
+        return (HANTRO_NOK);
+
+    return (HANTRO_OK);
+
+}
+/*lint +e715 */
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_slice_header.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_slice_header.h
new file mode 100755
index 0000000..198898a
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_slice_header.h
@@ -0,0 +1,186 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+    1. Include headers
+    2. Module defines
+    3. Data types
+    4. Function prototypes
+
+------------------------------------------------------------------------------*/
+
+#ifndef H264SWDEC_SLICE_HEADER_H
+#define H264SWDEC_SLICE_HEADER_H
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "basetype.h"
+#include "h264bsd_stream.h"
+#include "h264bsd_cfg.h"
+#include "h264bsd_seq_param_set.h"
+#include "h264bsd_pic_param_set.h"
+#include "h264bsd_nal_unit.h"
+
+/*------------------------------------------------------------------------------
+    2. Module defines
+------------------------------------------------------------------------------*/
+
+enum {
+    P_SLICE = 0,
+    I_SLICE = 2
+};
+
+enum {NO_LONG_TERM_FRAME_INDICES = 0xFFFF};
+
+/* macro to determine if slice is an inter slice, sliceTypes 0 and 5 */
+#define IS_P_SLICE(sliceType) (((sliceType) == P_SLICE) || \
+    ((sliceType) == P_SLICE + 5))
+
+/* macro to determine if slice is an intra slice, sliceTypes 2 and 7 */
+#define IS_I_SLICE(sliceType) (((sliceType) == I_SLICE) || \
+    ((sliceType) == I_SLICE + 5))
+
+/*------------------------------------------------------------------------------
+    3. Data types
+------------------------------------------------------------------------------*/
+
+/* structure to store data of one reference picture list reordering operation */
+typedef struct
+{
+    u32 reorderingOfPicNumsIdc;
+    u32 absDiffPicNum;
+    u32 longTermPicNum;
+} refPicListReorderingOperation_t;
+
+/* structure to store reference picture list reordering operations */
+typedef struct
+{
+    u32 refPicListReorderingFlagL0;
+    refPicListReorderingOperation_t command[MAX_NUM_REF_PICS+1];
+} refPicListReordering_t;
+
+/* structure to store data of one DPB memory management control operation */
+typedef struct
+{
+    u32 memoryManagementControlOperation;
+    u32 differenceOfPicNums;
+    u32 longTermPicNum;
+    u32 longTermFrameIdx;
+    u32 maxLongTermFrameIdx;
+} memoryManagementOperation_t;
+
+/* worst case scenario: all MAX_NUM_REF_PICS pictures in the buffer are
+ * short term pictures, each one of them is first marked as long term
+ * reference picture which is then marked as unused for reference.
+ * Additionally, max long-term frame index is set and current picture is
+ * marked as long term reference picture. Last position reserved for
+ * end memory_management_control_operation command */
+#define MAX_NUM_MMC_OPERATIONS (2*MAX_NUM_REF_PICS+2+1)
+
+/* structure to store decoded reference picture marking data */
+typedef struct
+{
+    u32 noOutputOfPriorPicsFlag;
+    u32 longTermReferenceFlag;
+    u32 adaptiveRefPicMarkingModeFlag;
+    memoryManagementOperation_t operation[MAX_NUM_MMC_OPERATIONS];
+} decRefPicMarking_t;
+
+/* structure to store slice header data decoded from the stream */
+typedef struct
+{
+    u32 firstMbInSlice;
+    u32 sliceType;
+    u32 picParameterSetId;
+    u32 frameNum;
+    u32 idrPicId;
+    u32 picOrderCntLsb;
+    i32 deltaPicOrderCntBottom;
+    i32 deltaPicOrderCnt[2];
+    u32 redundantPicCnt;
+    u32 numRefIdxActiveOverrideFlag;
+    u32 numRefIdxL0Active;
+    i32 sliceQpDelta;
+    u32 disableDeblockingFilterIdc;
+    i32 sliceAlphaC0Offset;
+    i32 sliceBetaOffset;
+    u32 sliceGroupChangeCycle;
+    refPicListReordering_t refPicListReordering;
+    decRefPicMarking_t decRefPicMarking;
+} sliceHeader_t;
+
+/*------------------------------------------------------------------------------
+    4. Function prototypes
+------------------------------------------------------------------------------*/
+
+u32 h264bsdDecodeSliceHeader(strmData_t *pStrmData,
+  sliceHeader_t *pSliceHeader,
+  seqParamSet_t *pSeqParamSet,
+  picParamSet_t *pPicParamSet,
+  nalUnit_t *pNalUnit);
+
+u32 h264bsdCheckPpsId(strmData_t *pStrmData, u32 *ppsId);
+
+u32 h264bsdCheckFrameNum(
+  strmData_t *pStrmData,
+  u32 maxFrameNum,
+  u32 *frameNum);
+
+u32 h264bsdCheckIdrPicId(
+  strmData_t *pStrmData,
+  u32 maxFrameNum,
+  nalUnitType_e nalUnitType,
+  u32 *idrPicId);
+
+u32 h264bsdCheckPicOrderCntLsb(
+  strmData_t *pStrmData,
+  seqParamSet_t *pSeqParamSet,
+  nalUnitType_e nalUnitType,
+  u32 *picOrderCntLsb);
+
+u32 h264bsdCheckDeltaPicOrderCntBottom(
+  strmData_t *pStrmData,
+  seqParamSet_t *pSeqParamSet,
+  nalUnitType_e nalUnitType,
+  i32 *deltaPicOrderCntBottom);
+
+u32 h264bsdCheckDeltaPicOrderCnt(
+  strmData_t *pStrmData,
+  seqParamSet_t *pSeqParamSet,
+  nalUnitType_e nalUnitType,
+  u32 picOrderPresentFlag,
+  i32 *deltaPicOrderCnt);
+
+u32 h264bsdCheckRedundantPicCnt(
+  strmData_t *pStrmData,
+  seqParamSet_t *pSeqParamSet,
+  picParamSet_t *pPicParamSet,
+  nalUnitType_e nalUnitType,
+  u32 *redundantPicCnt);
+
+u32 h264bsdCheckPriorPicsFlag(u32 * noOutputOfPriorPicsFlag,
+                              const strmData_t * pStrmData,
+                              const seqParamSet_t * pSeqParamSet,
+                              const picParamSet_t * pPicParamSet,
+                              nalUnitType_e nalUnitType);
+
+#endif /* #ifdef H264SWDEC_SLICE_HEADER_H */
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_storage.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_storage.c
new file mode 100755
index 0000000..3234754
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_storage.c
@@ -0,0 +1,888 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+     1. Include headers
+     2. External compiler flags
+     3. Module defines
+     4. Local function prototypes
+     5. Functions
+          h264bsdInitStorage
+          h264bsdStoreSeqParamSet
+          h264bsdStorePicParamSet
+          h264bsdActivateParamSets
+          h264bsdResetStorage
+          h264bsdIsStartOfPicture
+          h264bsdIsEndOfPicture
+          h264bsdComputeSliceGroupMap
+          h264bsdCheckAccessUnitBoundary
+          CheckPps
+          h264bsdValidParamSets
+
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "h264bsd_storage.h"
+#include "h264bsd_util.h"
+#include "h264bsd_neighbour.h"
+#include "h264bsd_slice_group_map.h"
+#include "h264bsd_dpb.h"
+#include "h264bsd_nal_unit.h"
+#include "h264bsd_slice_header.h"
+#include "h264bsd_seq_param_set.h"
+
+/*------------------------------------------------------------------------------
+    2. External compiler flags
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+    3. Module defines
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    4. Local function prototypes
+------------------------------------------------------------------------------*/
+
+static u32 CheckPps(picParamSet_t *pps, seqParamSet_t *sps);
+
+/*------------------------------------------------------------------------------
+
+    Function name: h264bsdInitStorage
+
+        Functional description:
+            Initialize storage structure. Sets contents of the storage to '0'
+            except for the active parameter set ids, which are initialized
+            to invalid values.
+
+        Inputs:
+
+        Outputs:
+            pStorage    initialized data stored here
+
+        Returns:
+            none
+
+------------------------------------------------------------------------------*/
+
+void h264bsdInitStorage(storage_t *pStorage)
+{
+
+/* Variables */
+
+/* Code */
+
+    ASSERT(pStorage);
+
+    H264SwDecMemset(pStorage, 0, sizeof(storage_t));
+
+    pStorage->activeSpsId = MAX_NUM_SEQ_PARAM_SETS;
+    pStorage->activePpsId = MAX_NUM_PIC_PARAM_SETS;
+
+    pStorage->aub->firstCallFlag = HANTRO_TRUE;
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdStoreSeqParamSet
+
+        Functional description:
+            Store sequence parameter set into the storage. If active SPS is
+            overwritten -> check if contents changes and if it does, set
+            parameters to force reactivation of parameter sets
+
+        Inputs:
+            pStorage        pointer to storage structure
+            pSeqParamSet    pointer to param set to be stored
+
+        Outputs:
+            none
+
+        Returns:
+            HANTRO_OK                success
+            MEMORY_ALLOCATION_ERROR  failure in memory allocation
+
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdStoreSeqParamSet(storage_t *pStorage, seqParamSet_t *pSeqParamSet)
+{
+
+/* Variables */
+
+    u32 id;
+
+/* Code */
+
+    ASSERT(pStorage);
+    ASSERT(pSeqParamSet);
+    ASSERT(pSeqParamSet->seqParameterSetId < MAX_NUM_SEQ_PARAM_SETS);
+
+    id = pSeqParamSet->seqParameterSetId;
+
+    /* seq parameter set with id not used before -> allocate memory */
+    if (pStorage->sps[id] == NULL)
+    {
+        ALLOCATE(pStorage->sps[id], 1, seqParamSet_t);
+        if (pStorage->sps[id] == NULL)
+            return(MEMORY_ALLOCATION_ERROR);
+    }
+    /* sequence parameter set with id equal to id of active sps */
+    else if (id == pStorage->activeSpsId)
+    {
+        /* if seq parameter set contents changes
+         *    -> overwrite and re-activate when next IDR picture decoded
+         *    ids of active param sets set to invalid values to force
+         *    re-activation. Memories allocated for old sps freed
+         * otherwise free memeries allocated for just decoded sps and
+         * continue */
+        if (h264bsdCompareSeqParamSets(pSeqParamSet, pStorage->activeSps) != 0)
+        {
+            FREE(pStorage->sps[id]->offsetForRefFrame);
+            FREE(pStorage->sps[id]->vuiParameters);
+            pStorage->activeSpsId = MAX_NUM_SEQ_PARAM_SETS + 1;
+            pStorage->activePpsId = MAX_NUM_PIC_PARAM_SETS + 1;
+            pStorage->activeSps = NULL;
+            pStorage->activePps = NULL;
+        }
+        else
+        {
+            FREE(pSeqParamSet->offsetForRefFrame);
+            FREE(pSeqParamSet->vuiParameters);
+            return(HANTRO_OK);
+        }
+    }
+    /* overwrite seq param set other than active one -> free memories
+     * allocated for old param set */
+    else
+    {
+        FREE(pStorage->sps[id]->offsetForRefFrame);
+        FREE(pStorage->sps[id]->vuiParameters);
+    }
+
+    *pStorage->sps[id] = *pSeqParamSet;
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdStorePicParamSet
+
+        Functional description:
+            Store picture parameter set into the storage. If active PPS is
+            overwritten -> check if active SPS changes and if it does -> set
+            parameters to force reactivation of parameter sets
+
+        Inputs:
+            pStorage        pointer to storage structure
+            pPicParamSet    pointer to param set to be stored
+
+        Outputs:
+            none
+
+        Returns:
+            HANTRO_OK                success
+            MEMORY_ALLOCATION_ERROR  failure in memory allocation
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdStorePicParamSet(storage_t *pStorage, picParamSet_t *pPicParamSet)
+{
+
+/* Variables */
+
+    u32 id;
+
+/* Code */
+
+    ASSERT(pStorage);
+    ASSERT(pPicParamSet);
+    ASSERT(pPicParamSet->picParameterSetId < MAX_NUM_PIC_PARAM_SETS);
+    ASSERT(pPicParamSet->seqParameterSetId < MAX_NUM_SEQ_PARAM_SETS);
+
+    id = pPicParamSet->picParameterSetId;
+
+    /* pic parameter set with id not used before -> allocate memory */
+    if (pStorage->pps[id] == NULL)
+    {
+        ALLOCATE(pStorage->pps[id], 1, picParamSet_t);
+        if (pStorage->pps[id] == NULL)
+            return(MEMORY_ALLOCATION_ERROR);
+    }
+    /* picture parameter set with id equal to id of active pps */
+    else if (id == pStorage->activePpsId)
+    {
+        /* check whether seq param set changes, force re-activation of
+         * param set if it does. Set activeSpsId to invalid value to
+         * accomplish this */
+        if (pPicParamSet->seqParameterSetId != pStorage->activeSpsId)
+        {
+            pStorage->activePpsId = MAX_NUM_PIC_PARAM_SETS + 1;
+        }
+        /* free memories allocated for old param set */
+        FREE(pStorage->pps[id]->runLength);
+        FREE(pStorage->pps[id]->topLeft);
+        FREE(pStorage->pps[id]->bottomRight);
+        FREE(pStorage->pps[id]->sliceGroupId);
+    }
+    /* overwrite pic param set other than active one -> free memories
+     * allocated for old param set */
+    else
+    {
+        FREE(pStorage->pps[id]->runLength);
+        FREE(pStorage->pps[id]->topLeft);
+        FREE(pStorage->pps[id]->bottomRight);
+        FREE(pStorage->pps[id]->sliceGroupId);
+    }
+
+    *pStorage->pps[id] = *pPicParamSet;
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdActivateParamSets
+
+        Functional description:
+            Activate certain SPS/PPS combination. This function shall be
+            called in the beginning of each picture. Picture parameter set
+            can be changed as wanted, but sequence parameter set may only be
+            changed when the starting picture is an IDR picture.
+
+            When new SPS is activated the function allocates memory for
+            macroblock storages and slice group map and (re-)initializes the
+            decoded picture buffer. If this is not the first activation the old
+            allocations are freed and FreeDpb called before new allocations.
+
+        Inputs:
+            pStorage        pointer to storage data structure
+            ppsId           identifies the PPS to be activated, SPS id obtained
+                            from the PPS
+            isIdr           flag to indicate if the picture is an IDR picture
+
+        Outputs:
+            none
+
+        Returns:
+            HANTRO_OK       success
+            HANTRO_NOK      non-existing or invalid param set combination,
+                            trying to change SPS with non-IDR picture
+            MEMORY_ALLOCATION_ERROR     failure in memory allocation
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdActivateParamSets(storage_t *pStorage, u32 ppsId, u32 isIdr)
+{
+
+/* Variables */
+
+    u32 tmp;
+    u32 flag;
+
+/* Code */
+
+    ASSERT(pStorage);
+    ASSERT(ppsId < MAX_NUM_PIC_PARAM_SETS);
+
+    /* check that pps and corresponding sps exist */
+    if ( (pStorage->pps[ppsId] == NULL) ||
+         (pStorage->sps[pStorage->pps[ppsId]->seqParameterSetId] == NULL) )
+    {
+        return(HANTRO_NOK);
+    }
+
+    /* check that pps parameters do not violate picture size constraints */
+    tmp = CheckPps(pStorage->pps[ppsId],
+                   pStorage->sps[pStorage->pps[ppsId]->seqParameterSetId]);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+
+    /* first activation part1 */
+    if (pStorage->activePpsId == MAX_NUM_PIC_PARAM_SETS)
+    {
+        pStorage->activePpsId = ppsId;
+        pStorage->activePps = pStorage->pps[ppsId];
+        pStorage->activeSpsId = pStorage->activePps->seqParameterSetId;
+        pStorage->activeSps = pStorage->sps[pStorage->activeSpsId];
+        pStorage->picSizeInMbs =
+            pStorage->activeSps->picWidthInMbs *
+            pStorage->activeSps->picHeightInMbs;
+
+        pStorage->currImage->width = pStorage->activeSps->picWidthInMbs;
+        pStorage->currImage->height = pStorage->activeSps->picHeightInMbs;
+
+        pStorage->pendingActivation = HANTRO_TRUE;
+    }
+    /* first activation part2 */
+    else if (pStorage->pendingActivation)
+    {
+        pStorage->pendingActivation = HANTRO_FALSE;
+
+        FREE(pStorage->mb);
+        FREE(pStorage->sliceGroupMap);
+
+        ALLOCATE(pStorage->mb, pStorage->picSizeInMbs, mbStorage_t);
+        ALLOCATE(pStorage->sliceGroupMap, pStorage->picSizeInMbs, u32);
+        if (pStorage->mb == NULL || pStorage->sliceGroupMap == NULL)
+            return(MEMORY_ALLOCATION_ERROR);
+
+        H264SwDecMemset(pStorage->mb, 0,
+            pStorage->picSizeInMbs * sizeof(mbStorage_t));
+
+        h264bsdInitMbNeighbours(pStorage->mb,
+            pStorage->activeSps->picWidthInMbs,
+            pStorage->picSizeInMbs);
+
+        /* dpb output reordering disabled if
+         * 1) application set noReordering flag
+         * 2) POC type equal to 2
+         * 3) num_reorder_frames in vui equal to 0 */
+        if ( pStorage->noReordering ||
+             pStorage->activeSps->picOrderCntType == 2 ||
+             (pStorage->activeSps->vuiParametersPresentFlag &&
+              pStorage->activeSps->vuiParameters->bitstreamRestrictionFlag &&
+              !pStorage->activeSps->vuiParameters->numReorderFrames) )
+            flag = HANTRO_TRUE;
+        else
+            flag = HANTRO_FALSE;
+
+        tmp = h264bsdResetDpb(pStorage->dpb,
+            pStorage->activeSps->picWidthInMbs *
+            pStorage->activeSps->picHeightInMbs,
+            pStorage->activeSps->maxDpbSize,
+            pStorage->activeSps->numRefFrames,
+            pStorage->activeSps->maxFrameNum,
+            flag);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+    }
+    else if (ppsId != pStorage->activePpsId)
+    {
+        /* sequence parameter set shall not change but before an IDR picture */
+        if (pStorage->pps[ppsId]->seqParameterSetId != pStorage->activeSpsId)
+        {
+            DEBUG(("SEQ PARAM SET CHANGING...\n"));
+            if (isIdr)
+            {
+                pStorage->activePpsId = ppsId;
+                pStorage->activePps = pStorage->pps[ppsId];
+                pStorage->activeSpsId = pStorage->activePps->seqParameterSetId;
+                pStorage->activeSps = pStorage->sps[pStorage->activeSpsId];
+                pStorage->picSizeInMbs =
+                    pStorage->activeSps->picWidthInMbs *
+                    pStorage->activeSps->picHeightInMbs;
+
+                pStorage->currImage->width = pStorage->activeSps->picWidthInMbs;
+                pStorage->currImage->height =
+                    pStorage->activeSps->picHeightInMbs;
+
+                pStorage->pendingActivation = HANTRO_TRUE;
+            }
+            else
+            {
+                DEBUG(("TRYING TO CHANGE SPS IN NON-IDR SLICE\n"));
+                return(HANTRO_NOK);
+            }
+        }
+        else
+        {
+            pStorage->activePpsId = ppsId;
+            pStorage->activePps = pStorage->pps[ppsId];
+        }
+    }
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdResetStorage
+
+        Functional description:
+            Reset contents of the storage. This should be called before
+            processing of new image is started.
+
+        Inputs:
+            pStorage    pointer to storage structure
+
+        Outputs:
+            none
+
+        Returns:
+            none
+
+
+------------------------------------------------------------------------------*/
+
+void h264bsdResetStorage(storage_t *pStorage)
+{
+
+/* Variables */
+
+    u32 i;
+
+/* Code */
+
+    ASSERT(pStorage);
+
+    pStorage->slice->numDecodedMbs = 0;
+    pStorage->slice->sliceId = 0;
+
+    for (i = 0; i < pStorage->picSizeInMbs; i++)
+    {
+        pStorage->mb[i].sliceId = 0;
+        pStorage->mb[i].decoded = 0;
+    }
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdIsStartOfPicture
+
+        Functional description:
+            Determine if the decoder is in the start of a picture. This
+            information is needed to decide if h264bsdActivateParamSets and
+            h264bsdCheckGapsInFrameNum functions should be called. Function
+            considers that new picture is starting if no slice headers
+            have been successfully decoded for the current access unit.
+
+        Inputs:
+            pStorage    pointer to storage structure
+
+        Outputs:
+            none
+
+        Returns:
+            HANTRO_TRUE        new picture is starting
+            HANTRO_FALSE       not starting
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdIsStartOfPicture(storage_t *pStorage)
+{
+
+/* Variables */
+
+
+/* Code */
+
+    if (pStorage->validSliceInAccessUnit == HANTRO_FALSE)
+        return(HANTRO_TRUE);
+    else
+        return(HANTRO_FALSE);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdIsEndOfPicture
+
+        Functional description:
+            Determine if the decoder is in the end of a picture. This
+            information is needed to determine when deblocking filtering
+            and reference picture marking processes should be performed.
+
+            If the decoder is processing primary slices the return value
+            is determined by checking the value of numDecodedMbs in the
+            storage. On the other hand, if the decoder is processing
+            redundant slices the numDecodedMbs may not contain valid
+            informationa and each macroblock has to be checked separately.
+
+        Inputs:
+            pStorage    pointer to storage structure
+
+        Outputs:
+            none
+
+        Returns:
+            HANTRO_TRUE        end of picture
+            HANTRO_FALSE       noup
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdIsEndOfPicture(storage_t *pStorage)
+{
+
+/* Variables */
+
+    u32 i, tmp;
+
+/* Code */
+
+    /* primary picture */
+    if (!pStorage->sliceHeader[0].redundantPicCnt)
+    {
+        if (pStorage->slice->numDecodedMbs == pStorage->picSizeInMbs)
+            return(HANTRO_TRUE);
+    }
+    else
+    {
+        for (i = 0, tmp = 0; i < pStorage->picSizeInMbs; i++)
+            tmp += pStorage->mb[i].decoded ? 1 : 0;
+
+        if (tmp == pStorage->picSizeInMbs)
+            return(HANTRO_TRUE);
+    }
+
+    return(HANTRO_FALSE);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdComputeSliceGroupMap
+
+        Functional description:
+            Compute slice group map. Just call h264bsdDecodeSliceGroupMap with
+            appropriate parameters.
+
+        Inputs:
+            pStorage                pointer to storage structure
+            sliceGroupChangeCycle
+
+        Outputs:
+            none
+
+        Returns:
+            none
+
+------------------------------------------------------------------------------*/
+
+void h264bsdComputeSliceGroupMap(storage_t *pStorage, u32 sliceGroupChangeCycle)
+{
+
+/* Variables */
+
+
+/* Code */
+
+    h264bsdDecodeSliceGroupMap(pStorage->sliceGroupMap,
+                        pStorage->activePps, sliceGroupChangeCycle,
+                        pStorage->activeSps->picWidthInMbs,
+                        pStorage->activeSps->picHeightInMbs);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdCheckAccessUnitBoundary
+
+        Functional description:
+            Check if next NAL unit starts a new access unit. Following
+            conditions specify start of a new access unit:
+
+                -NAL unit types 6-11, 13-18 (e.g. SPS, PPS)
+
+           following conditions checked only for slice NAL units, values
+           compared to ones obtained from previous slice:
+
+                -NAL unit type differs (slice / IDR slice)
+                -frame_num differs
+                -nal_ref_idc differs and one of the values is 0
+                -POC information differs
+                -both are IDR slices and idr_pic_id differs
+
+        Inputs:
+            strm        pointer to stream data structure
+            nuNext      pointer to NAL unit structure
+            storage     pointer to storage structure
+
+        Outputs:
+            accessUnitBoundaryFlag  the result is stored here, TRUE for
+                                    access unit boundary, FALSE otherwise
+
+        Returns:
+            HANTRO_OK           success
+            HANTRO_NOK          failure, invalid stream data
+            PARAM_SET_ERROR     invalid param set usage
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdCheckAccessUnitBoundary(
+  strmData_t *strm,
+  nalUnit_t *nuNext,
+  storage_t *storage,
+  u32 *accessUnitBoundaryFlag)
+{
+
+/* Variables */
+
+    u32 tmp, ppsId, frameNum, idrPicId, picOrderCntLsb;
+    i32 deltaPicOrderCntBottom, deltaPicOrderCnt[2];
+    seqParamSet_t *sps;
+    picParamSet_t *pps;
+
+/* Code */
+
+    ASSERT(strm);
+    ASSERT(nuNext);
+    ASSERT(storage);
+    ASSERT(storage->sps);
+    ASSERT(storage->pps);
+
+    /* initialize default output to FALSE */
+    *accessUnitBoundaryFlag = HANTRO_FALSE;
+
+    if ( ( (nuNext->nalUnitType > 5) && (nuNext->nalUnitType < 12) ) ||
+         ( (nuNext->nalUnitType > 12) && (nuNext->nalUnitType <= 18) ) )
+    {
+        *accessUnitBoundaryFlag = HANTRO_TRUE;
+        return(HANTRO_OK);
+    }
+    else if ( nuNext->nalUnitType != NAL_CODED_SLICE &&
+              nuNext->nalUnitType != NAL_CODED_SLICE_IDR )
+    {
+        return(HANTRO_OK);
+    }
+
+    /* check if this is the very first call to this function */
+    if (storage->aub->firstCallFlag)
+    {
+        *accessUnitBoundaryFlag = HANTRO_TRUE;
+        storage->aub->firstCallFlag = HANTRO_FALSE;
+    }
+
+    /* get picture parameter set id */
+    tmp = h264bsdCheckPpsId(strm, &ppsId);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+
+    /* store sps and pps in separate pointers just to make names shorter */
+    pps = storage->pps[ppsId];
+    if ( pps == NULL || storage->sps[pps->seqParameterSetId] == NULL  ||
+         (storage->activeSpsId != MAX_NUM_SEQ_PARAM_SETS &&
+          pps->seqParameterSetId != storage->activeSpsId &&
+          nuNext->nalUnitType != NAL_CODED_SLICE_IDR) )
+        return(PARAM_SET_ERROR);
+    sps = storage->sps[pps->seqParameterSetId];
+
+    if (storage->aub->nuPrev->nalRefIdc != nuNext->nalRefIdc &&
+      (storage->aub->nuPrev->nalRefIdc == 0 || nuNext->nalRefIdc == 0))
+        *accessUnitBoundaryFlag = HANTRO_TRUE;
+
+    if ((storage->aub->nuPrev->nalUnitType == NAL_CODED_SLICE_IDR &&
+          nuNext->nalUnitType != NAL_CODED_SLICE_IDR) ||
+      (storage->aub->nuPrev->nalUnitType != NAL_CODED_SLICE_IDR &&
+       nuNext->nalUnitType == NAL_CODED_SLICE_IDR))
+        *accessUnitBoundaryFlag = HANTRO_TRUE;
+
+    tmp = h264bsdCheckFrameNum(strm, sps->maxFrameNum, &frameNum);
+    if (tmp != HANTRO_OK)
+        return(HANTRO_NOK);
+
+    if (storage->aub->prevFrameNum != frameNum)
+    {
+        storage->aub->prevFrameNum = frameNum;
+        *accessUnitBoundaryFlag = HANTRO_TRUE;
+    }
+
+    if (nuNext->nalUnitType == NAL_CODED_SLICE_IDR)
+    {
+        tmp = h264bsdCheckIdrPicId(strm, sps->maxFrameNum, nuNext->nalUnitType,
+          &idrPicId);
+        if (tmp != HANTRO_OK)
+            return(HANTRO_NOK);
+
+        if (storage->aub->nuPrev->nalUnitType == NAL_CODED_SLICE_IDR &&
+          storage->aub->prevIdrPicId != idrPicId)
+            *accessUnitBoundaryFlag = HANTRO_TRUE;
+
+        storage->aub->prevIdrPicId = idrPicId;
+    }
+
+    if (sps->picOrderCntType == 0)
+    {
+        tmp = h264bsdCheckPicOrderCntLsb(strm, sps, nuNext->nalUnitType,
+          &picOrderCntLsb);
+        if (tmp != HANTRO_OK)
+            return(HANTRO_NOK);
+
+        if (storage->aub->prevPicOrderCntLsb != picOrderCntLsb)
+        {
+            storage->aub->prevPicOrderCntLsb = picOrderCntLsb;
+            *accessUnitBoundaryFlag = HANTRO_TRUE;
+        }
+
+        if (pps->picOrderPresentFlag)
+        {
+            tmp = h264bsdCheckDeltaPicOrderCntBottom(strm, sps,
+                nuNext->nalUnitType, &deltaPicOrderCntBottom);
+            if (tmp != HANTRO_OK)
+                return(tmp);
+
+            if (storage->aub->prevDeltaPicOrderCntBottom !=
+                deltaPicOrderCntBottom)
+            {
+                storage->aub->prevDeltaPicOrderCntBottom =
+                    deltaPicOrderCntBottom;
+                *accessUnitBoundaryFlag = HANTRO_TRUE;
+            }
+        }
+    }
+    else if (sps->picOrderCntType == 1 && !sps->deltaPicOrderAlwaysZeroFlag)
+    {
+        tmp = h264bsdCheckDeltaPicOrderCnt(strm, sps, nuNext->nalUnitType,
+          pps->picOrderPresentFlag, deltaPicOrderCnt);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+
+        if (storage->aub->prevDeltaPicOrderCnt[0] != deltaPicOrderCnt[0])
+        {
+            storage->aub->prevDeltaPicOrderCnt[0] = deltaPicOrderCnt[0];
+            *accessUnitBoundaryFlag = HANTRO_TRUE;
+        }
+
+        if (pps->picOrderPresentFlag)
+            if (storage->aub->prevDeltaPicOrderCnt[1] != deltaPicOrderCnt[1])
+            {
+                storage->aub->prevDeltaPicOrderCnt[1] = deltaPicOrderCnt[1];
+                *accessUnitBoundaryFlag = HANTRO_TRUE;
+            }
+    }
+
+    *storage->aub->nuPrev = *nuNext;
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: CheckPps
+
+        Functional description:
+            Check picture parameter set. Contents of the picture parameter
+            set information that depends on the image dimensions is checked
+            against the dimensions in the sps.
+
+        Inputs:
+            pps     pointer to picture paramter set
+            sps     pointer to sequence parameter set
+
+        Outputs:
+            none
+
+        Returns:
+            HANTRO_OK      everything ok
+            HANTRO_NOK     invalid data in picture parameter set
+
+------------------------------------------------------------------------------*/
+u32 CheckPps(picParamSet_t *pps, seqParamSet_t *sps)
+{
+
+    u32 i;
+    u32 picSize;
+
+    picSize = sps->picWidthInMbs * sps->picHeightInMbs;
+
+    /* check slice group params */
+    if (pps->numSliceGroups > 1)
+    {
+        if (pps->sliceGroupMapType == 0)
+        {
+            ASSERT(pps->runLength);
+            for (i = 0; i < pps->numSliceGroups; i++)
+            {
+                if (pps->runLength[i] > picSize)
+                    return(HANTRO_NOK);
+            }
+        }
+        else if (pps->sliceGroupMapType == 2)
+        {
+            ASSERT(pps->topLeft);
+            ASSERT(pps->bottomRight);
+            for (i = 0; i < pps->numSliceGroups-1; i++)
+            {
+                if (pps->topLeft[i] > pps->bottomRight[i] ||
+                    pps->bottomRight[i] >= picSize)
+                    return(HANTRO_NOK);
+
+                if ( (pps->topLeft[i] % sps->picWidthInMbs) >
+                     (pps->bottomRight[i] % sps->picWidthInMbs) )
+                    return(HANTRO_NOK);
+            }
+        }
+        else if (pps->sliceGroupMapType > 2 && pps->sliceGroupMapType < 6)
+        {
+            if (pps->sliceGroupChangeRate > picSize)
+                return(HANTRO_NOK);
+        }
+        else if (pps->sliceGroupMapType == 6 &&
+                 pps->picSizeInMapUnits < picSize)
+            return(HANTRO_NOK);
+    }
+
+    return(HANTRO_OK);
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdValidParamSets
+
+        Functional description:
+            Check if any valid SPS/PPS combination exists in the storage.
+            Function tries each PPS in the buffer and checks if corresponding
+            SPS exists and calls CheckPps to determine if the PPS conforms
+            to image dimensions of the SPS.
+
+        Inputs:
+            pStorage    pointer to storage structure
+
+        Outputs:
+            HANTRO_OK   there is at least one valid combination
+            HANTRO_NOK  no valid combinations found
+
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdValidParamSets(storage_t *pStorage)
+{
+
+/* Variables */
+
+    u32 i;
+
+/* Code */
+
+    ASSERT(pStorage);
+
+    for (i = 0; i < MAX_NUM_PIC_PARAM_SETS; i++)
+    {
+        if ( pStorage->pps[i] &&
+             pStorage->sps[pStorage->pps[i]->seqParameterSetId] &&
+             CheckPps(pStorage->pps[i],
+                      pStorage->sps[pStorage->pps[i]->seqParameterSetId]) ==
+                 HANTRO_OK)
+        {
+            return(HANTRO_OK);
+        }
+    }
+
+    return(HANTRO_NOK);
+
+}
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_storage.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_storage.h
new file mode 100755
index 0000000..ba3b2da
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_storage.h
@@ -0,0 +1,174 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+    1. Include headers
+    2. Module defines
+    3. Data types
+    4. Function prototypes
+
+------------------------------------------------------------------------------*/
+
+#ifndef H264SWDEC_STORAGE_H
+#define H264SWDEC_STORAGE_H
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "basetype.h"
+#include "h264bsd_cfg.h"
+#include "h264bsd_seq_param_set.h"
+#include "h264bsd_pic_param_set.h"
+#include "h264bsd_macroblock_layer.h"
+#include "h264bsd_nal_unit.h"
+#include "h264bsd_slice_header.h"
+#include "h264bsd_seq_param_set.h"
+#include "h264bsd_dpb.h"
+#include "h264bsd_pic_order_cnt.h"
+
+/*------------------------------------------------------------------------------
+    2. Module defines
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    3. Data types
+------------------------------------------------------------------------------*/
+
+typedef struct
+{
+    u32 sliceId;
+    u32 numDecodedMbs;
+    u32 lastMbAddr;
+} sliceStorage_t;
+
+/* structure to store parameters needed for access unit boundary checking */
+typedef struct
+{
+    nalUnit_t nuPrev[1];
+    u32 prevFrameNum;
+    u32 prevIdrPicId;
+    u32 prevPicOrderCntLsb;
+    i32 prevDeltaPicOrderCntBottom;
+    i32 prevDeltaPicOrderCnt[2];
+    u32 firstCallFlag;
+} aubCheck_t;
+
+/* storage data structure, holds all data of a decoder instance */
+typedef struct
+{
+    /* active paramet set ids and pointers */
+    u32 oldSpsId;
+    u32 activePpsId;
+    u32 activeSpsId;
+    picParamSet_t *activePps;
+    seqParamSet_t *activeSps;
+    seqParamSet_t *sps[MAX_NUM_SEQ_PARAM_SETS];
+    picParamSet_t *pps[MAX_NUM_PIC_PARAM_SETS];
+
+    /* current slice group map, recomputed for each slice */
+    u32 *sliceGroupMap;
+
+    u32 picSizeInMbs;
+
+    /* this flag is set after all macroblocks of a picture successfully
+     * decoded -> redundant slices not decoded */
+    u32 skipRedundantSlices;
+    u32 picStarted;
+
+    /* flag to indicate if current access unit contains any valid slices */
+    u32 validSliceInAccessUnit;
+
+    /* store information needed for handling of slice decoding */
+    sliceStorage_t slice[1];
+
+    /* number of concealed macroblocks in the current image */
+    u32 numConcealedMbs;
+
+    /* picId given by application */
+    u32 currentPicId;
+
+    /* macroblock specific storages, size determined by image dimensions */
+    mbStorage_t *mb;
+
+    /* flag to store noOutputReordering flag set by the application */
+    u32 noReordering;
+
+    /* DPB */
+    dpbStorage_t dpb[1];
+
+    /* structure to store picture order count related information */
+    pocStorage_t poc[1];
+
+    /* access unit boundary checking related data */
+    aubCheck_t aub[1];
+
+    /* current processed image */
+    image_t currImage[1];
+
+    /* last valid NAL unit header is stored here */
+    nalUnit_t prevNalUnit[1];
+
+    /* slice header, second structure used as a temporary storage while
+     * decoding slice header, first one stores last successfully decoded
+     * slice header */
+    sliceHeader_t sliceHeader[2];
+
+    /* fields to store old stream buffer pointers, needed when only part of
+     * a stream buffer is processed by h264bsdDecode function */
+    u32 prevBufNotFinished;
+    u8 *prevBufPointer;
+    u32 prevBytesConsumed;
+    strmData_t strm[1];
+
+    /* macroblock layer structure, there is no need to store this but it
+     * would have increased the stack size excessively and needed to be
+     * allocated from head -> easiest to put it here */
+    macroblockLayer_t *mbLayer;
+
+    u32 pendingActivation; /* Activate parameter sets after returning
+                              HEADERS_RDY to the user */
+    u32 intraConcealmentFlag; /* 0 gray picture for corrupted intra
+                                 1 previous frame used if available */
+} storage_t;
+
+/*------------------------------------------------------------------------------
+    4. Function prototypes
+------------------------------------------------------------------------------*/
+
+void h264bsdInitStorage(storage_t *pStorage);
+void h264bsdResetStorage(storage_t *pStorage);
+u32 h264bsdIsStartOfPicture(storage_t *pStorage);
+u32 h264bsdIsEndOfPicture(storage_t *pStorage);
+u32 h264bsdStoreSeqParamSet(storage_t *pStorage, seqParamSet_t *pSeqParamSet);
+u32 h264bsdStorePicParamSet(storage_t *pStorage, picParamSet_t *pPicParamSet);
+u32 h264bsdActivateParamSets(storage_t *pStorage, u32 ppsId, u32 isIdr);
+void h264bsdComputeSliceGroupMap(storage_t *pStorage,
+    u32 sliceGroupChangeCycle);
+
+u32 h264bsdCheckAccessUnitBoundary(
+  strmData_t *strm,
+  nalUnit_t *nuNext,
+  storage_t *storage,
+  u32 *accessUnitBoundaryFlag);
+
+u32 h264bsdValidParamSets(storage_t *pStorage);
+
+#endif /* #ifdef H264SWDEC_STORAGE_H */
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_stream.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_stream.c
new file mode 100755
index 0000000..20d1083
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_stream.c
@@ -0,0 +1,242 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+     1. Include headers
+     2. External compiler flags
+     3. Module defines
+     4. Local function prototypes
+     5. Functions
+          h264bsdGetBits
+          h264bsdShowBits32
+          h264bsdFlushBits
+          h264bsdIsByteAligned
+
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "h264bsd_util.h"
+#include "h264bsd_stream.h"
+
+/*------------------------------------------------------------------------------
+    2. External compiler flags
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+    3. Module defines
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    4. Local function prototypes
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdGetBits
+
+        Functional description:
+            Read and remove bits from the stream buffer.
+
+        Input:
+            pStrmData   pointer to stream data structure
+            numBits     number of bits to read
+
+        Output:
+            none
+
+        Returns:
+            bits read from stream
+            END_OF_STREAM if not enough bits left
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdGetBits(strmData_t *pStrmData, u32 numBits)
+{
+
+    u32 out;
+
+    ASSERT(pStrmData);
+    ASSERT(numBits < 32);
+
+    out = h264bsdShowBits32(pStrmData) >> (32 - numBits);
+
+    if (h264bsdFlushBits(pStrmData, numBits) == HANTRO_OK)
+    {
+        return(out);
+    }
+    else
+    {
+        return(END_OF_STREAM);
+    }
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdShowBits32
+
+        Functional description:
+            Read 32 bits from the stream buffer. Buffer is left as it is, i.e.
+            no bits are removed. First bit read from the stream is the MSB of
+            the return value. If there is not enough bits in the buffer ->
+            bits beyong the end of the stream are set to '0' in the return
+            value.
+
+        Input:
+            pStrmData   pointer to stream data structure
+
+        Output:
+            none
+
+        Returns:
+            bits read from stream
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdShowBits32(strmData_t *pStrmData)
+{
+
+    i32 bits, shift;
+    u32 out;
+    u8 *pStrm;
+
+    ASSERT(pStrmData);
+    ASSERT(pStrmData->pStrmCurrPos);
+    ASSERT(pStrmData->bitPosInWord < 8);
+    ASSERT(pStrmData->bitPosInWord ==
+           (pStrmData->strmBuffReadBits & 0x7));
+
+    pStrm = pStrmData->pStrmCurrPos;
+
+    /* number of bits left in the buffer */
+    bits = (i32)pStrmData->strmBuffSize*8 - (i32)pStrmData->strmBuffReadBits;
+
+    /* at least 32-bits in the buffer */
+    if (bits >= 32)
+    {
+        u32 bitPosInWord = pStrmData->bitPosInWord;
+        out = ((u32)pStrm[0] << 24) | ((u32)pStrm[1] << 16) |
+              ((u32)pStrm[2] <<  8) | ((u32)pStrm[3]);
+
+        if (bitPosInWord)
+        {
+            u32 byte = (u32)pStrm[4];
+            u32 tmp = (8-bitPosInWord);
+            out <<= bitPosInWord;
+            out |= byte>>tmp;
+        }
+        return (out);
+    }
+    /* at least one bit in the buffer */
+    else if (bits > 0)
+    {
+        shift = (i32)(24 + pStrmData->bitPosInWord);
+        out = (u32)(*pStrm++) << shift;
+        bits -= (i32)(8 - pStrmData->bitPosInWord);
+        while (bits > 0)
+        {
+            shift -= 8;
+            out |= (u32)(*pStrm++) << shift;
+            bits -= 8;
+        }
+        return (out);
+    }
+    else
+        return (0);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdFlushBits
+
+        Functional description:
+            Remove bits from the stream buffer
+
+        Input:
+            pStrmData       pointer to stream data structure
+            numBits         number of bits to remove
+
+        Output:
+            none
+
+        Returns:
+            HANTRO_OK       success
+            END_OF_STREAM   not enough bits left
+
+------------------------------------------------------------------------------*/
+#ifndef H264DEC_NEON
+u32 h264bsdFlushBits(strmData_t *pStrmData, u32 numBits)
+{
+
+    ASSERT(pStrmData);
+    ASSERT(pStrmData->pStrmBuffStart);
+    ASSERT(pStrmData->pStrmCurrPos);
+    ASSERT(pStrmData->bitPosInWord < 8);
+    ASSERT(pStrmData->bitPosInWord == (pStrmData->strmBuffReadBits & 0x7));
+
+    pStrmData->strmBuffReadBits += numBits;
+    pStrmData->bitPosInWord = pStrmData->strmBuffReadBits & 0x7;
+    if ( (pStrmData->strmBuffReadBits ) <= (8*pStrmData->strmBuffSize) )
+    {
+        pStrmData->pStrmCurrPos = pStrmData->pStrmBuffStart +
+            (pStrmData->strmBuffReadBits >> 3);
+        return(HANTRO_OK);
+    }
+    else
+        return(END_OF_STREAM);
+
+}
+#endif
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdIsByteAligned
+
+        Functional description:
+            Check if current stream position is byte aligned.
+
+        Inputs:
+            pStrmData   pointer to stream data structure
+
+        Outputs:
+            none
+
+        Returns:
+            TRUE        stream is byte aligned
+            FALSE       stream is not byte aligned
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdIsByteAligned(strmData_t *pStrmData)
+{
+
+/* Variables */
+
+/* Code */
+
+    if (!pStrmData->bitPosInWord)
+        return(HANTRO_TRUE);
+    else
+        return(HANTRO_FALSE);
+
+}
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_stream.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_stream.h
new file mode 100755
index 0000000..4404b66
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_stream.h
@@ -0,0 +1,67 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+    1. Include headers
+    2. Module defines
+    3. Data types
+    4. Function prototypes
+
+------------------------------------------------------------------------------*/
+
+#ifndef H264SWDEC_STREAM_H
+#define H264SWDEC_STREAM_H
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "basetype.h"
+
+/*------------------------------------------------------------------------------
+    2. Module defines
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    3. Data types
+------------------------------------------------------------------------------*/
+
+typedef struct
+{
+    u8  *pStrmBuffStart;    /* pointer to start of stream buffer */
+    u8  *pStrmCurrPos;      /* current read address in stream buffer */
+    u32  bitPosInWord;      /* bit position in stream buffer byte */
+    u32  strmBuffSize;      /* size of stream buffer (bytes) */
+    u32  strmBuffReadBits;  /* number of bits read from stream buffer */
+} strmData_t;
+
+/*------------------------------------------------------------------------------
+    4. Function prototypes
+------------------------------------------------------------------------------*/
+
+u32 h264bsdGetBits(strmData_t *pStrmData, u32 numBits);
+
+u32 h264bsdShowBits32(strmData_t *pStrmData);
+
+u32 h264bsdFlushBits(strmData_t *pStrmData, u32 numBits);
+
+u32 h264bsdIsByteAligned(strmData_t *);
+
+#endif /* #ifdef H264SWDEC_STREAM_H */
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_transform.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_transform.c
new file mode 100755
index 0000000..4eb6dd0
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_transform.c
@@ -0,0 +1,402 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+     1. Include headers
+     2. External compiler flags
+     3. Module defines
+     4. Local function prototypes
+     5. Functions
+          h264bsdProcessBlock
+          h264bsdProcessLumaDc
+          h264bsdProcessChromaDc
+
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "basetype.h"
+#include "h264bsd_transform.h"
+#include "h264bsd_util.h"
+
+/*------------------------------------------------------------------------------
+    2. External compiler flags
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+    3. Module defines
+------------------------------------------------------------------------------*/
+
+/* Switch off the following Lint messages for this file:
+ * Info 701: Shift left of signed quantity (int)
+ * Info 702: Shift right of signed quantity (int)
+ */
+/*lint -e701 -e702 */
+
+/* LevelScale function */
+static const i32 levelScale[6][3] = {
+    {10,13,16}, {11,14,18}, {13,16,20}, {14,18,23}, {16,20,25}, {18,23,29}};
+
+/* qp % 6 as a function of qp */
+static const u8 qpMod6[52] = {0,1,2,3,4,5,0,1,2,3,4,5,0,1,2,3,4,5,0,1,2,3,4,5,
+    0,1,2,3,4,5,0,1,2,3,4,5,0,1,2,3,4,5,0,1,2,3,4,5,0,1,2,3};
+
+/* qp / 6 as a function of qp */
+static const u8 qpDiv6[52] = {0,0,0,0,0,0,1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,3,3,3,
+    4,4,4,4,4,4,5,5,5,5,5,5,6,6,6,6,6,6,7,7,7,7,7,7,8,8,8,8};
+
+/*------------------------------------------------------------------------------
+    4. Local function prototypes
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdProcessBlock
+
+        Functional description:
+            Function performs inverse zig-zag scan, inverse scaling and
+            inverse transform for a luma or a chroma residual block
+
+        Inputs:
+            data            pointer to data to be processed
+            qp              quantization parameter
+            skip            skip processing of data[0], set to non-zero value
+                            if dc coeff hanled separately
+            coeffMap        16 lsb's indicate which coeffs are non-zero,
+                            bit 0 (lsb) for coeff 0, bit 1 for coeff 1 etc.
+
+        Outputs:
+            data            processed data
+
+        Returns:
+            HANTRO_OK       success
+            HANTRO_NOK      processed data not in valid range [-512, 511]
+
+------------------------------------------------------------------------------*/
+u32 h264bsdProcessBlock(i32 *data, u32 qp, u32 skip, u32 coeffMap)
+{
+
+/* Variables */
+
+    i32 tmp0, tmp1, tmp2, tmp3;
+    i32 d1, d2, d3;
+    u32 row,col;
+    u32 qpDiv;
+    i32 *ptr;
+
+/* Code */
+
+    qpDiv = qpDiv6[qp];
+    tmp1 = levelScale[qpMod6[qp]][0] << qpDiv;
+    tmp2 = levelScale[qpMod6[qp]][1] << qpDiv;
+    tmp3 = levelScale[qpMod6[qp]][2] << qpDiv;
+
+    if (!skip)
+        data[0] = (data[0] * tmp1);
+
+    /* at least one of the rows 1, 2 or 3 contain non-zero coeffs, mask takes
+     * the scanning order into account */
+    if (coeffMap & 0xFF9C)
+    {
+        /* do the zig-zag scan and inverse quantization */
+        d1 = data[1];
+        d2 = data[14];
+        d3 = data[15];
+        data[1] = (d1 * tmp2);
+        data[14] = (d2 * tmp2);
+        data[15] = (d3 * tmp3);
+
+        d1 = data[2];
+        d2 = data[5];
+        d3 = data[4];
+        data[4] = (d1 * tmp2);
+        data[2]  = (d2 * tmp1);
+        data[5] = (d3 * tmp3);
+
+        d1 = data[8];
+        d2 = data[3];
+        d3 = data[6];
+        tmp0 = (d1 * tmp2);
+        data[8] = (d2 * tmp1);
+        data[3]  = (d3 * tmp2);
+        d1 = data[7];
+        d2 = data[12];
+        d3 = data[9];
+        data[6]  = (d1 * tmp2);
+        data[7]  = (d2 * tmp3);
+        data[12] = (d3 * tmp2);
+        data[9]  = tmp0;
+
+        d1 = data[10];
+        d2 = data[11];
+        d3 = data[13];
+        data[13] = (d1 * tmp3);
+        data[10] = (d2 * tmp1);
+        data[11] = (d3 * tmp2);
+
+        /* horizontal transform */
+        for (row = 4, ptr = data; row--; ptr += 4)
+        {
+            tmp0 = ptr[0] + ptr[2];
+            tmp1 = ptr[0] - ptr[2];
+            tmp2 = (ptr[1] >> 1) - ptr[3];
+            tmp3 = ptr[1] + (ptr[3] >> 1);
+            ptr[0] = tmp0 + tmp3;
+            ptr[1] = tmp1 + tmp2;
+            ptr[2] = tmp1 - tmp2;
+            ptr[3] = tmp0 - tmp3;
+        }
+
+        /*lint +e661 +e662*/
+        /* then vertical transform */
+        for (col = 4; col--; data++)
+        {
+            tmp0 = data[0] + data[8];
+            tmp1 = data[0] - data[8];
+            tmp2 = (data[4] >> 1) - data[12];
+            tmp3 = data[4] + (data[12] >> 1);
+            data[0 ] = (tmp0 + tmp3 + 32)>>6;
+            data[4 ] = (tmp1 + tmp2 + 32)>>6;
+            data[8 ] = (tmp1 - tmp2 + 32)>>6;
+            data[12] = (tmp0 - tmp3 + 32)>>6;
+            /* check that each value is in the range [-512,511] */
+            if (((u32)(data[0] + 512) > 1023) ||
+                ((u32)(data[4] + 512) > 1023) ||
+                ((u32)(data[8] + 512) > 1023) ||
+                ((u32)(data[12] + 512) > 1023) )
+                return(HANTRO_NOK);
+        }
+    }
+    else /* rows 1, 2 and 3 are zero */
+    {
+        /* only dc-coeff is non-zero, i.e. coeffs at original positions
+         * 1, 5 and 6 are zero */
+        if ((coeffMap & 0x62) == 0)
+        {
+            tmp0 = (data[0] + 32) >> 6;
+            /* check that value is in the range [-512,511] */
+            if ((u32)(tmp0 + 512) > 1023)
+                return(HANTRO_NOK);
+            data[0] = data[1]  = data[2]  = data[3]  = data[4]  = data[5]  =
+                      data[6]  = data[7]  = data[8]  = data[9]  = data[10] =
+                      data[11] = data[12] = data[13] = data[14] = data[15] =
+                      tmp0;
+        }
+        else /* at least one of the coeffs 1, 5 or 6 is non-zero */
+        {
+            data[1] = (data[1] * tmp2);
+            data[2] = (data[5] * tmp1);
+            data[3] = (data[6] * tmp2);
+            tmp0 = data[0] + data[2];
+            tmp1 = data[0] - data[2];
+            tmp2 = (data[1] >> 1) - data[3];
+            tmp3 = data[1] + (data[3] >> 1);
+            data[0] = (tmp0 + tmp3 + 32)>>6;
+            data[1] = (tmp1 + tmp2 + 32)>>6;
+            data[2] = (tmp1 - tmp2 + 32)>>6;
+            data[3] = (tmp0 - tmp3 + 32)>>6;
+            data[4] = data[8] = data[12] = data[0];
+            data[5] = data[9] = data[13] = data[1];
+            data[6] = data[10] = data[14] = data[2];
+            data[7] = data[11] = data[15] = data[3];
+            /* check that each value is in the range [-512,511] */
+            if (((u32)(data[0] + 512) > 1023) ||
+                ((u32)(data[1] + 512) > 1023) ||
+                ((u32)(data[2] + 512) > 1023) ||
+                ((u32)(data[3] + 512) > 1023) )
+                return(HANTRO_NOK);
+        }
+    }
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdProcessLumaDc
+
+        Functional description:
+            Function performs inverse zig-zag scan, inverse transform and
+            inverse scaling for a luma DC coefficients block
+
+        Inputs:
+            data            pointer to data to be processed
+            qp              quantization parameter
+
+        Outputs:
+            data            processed data
+
+        Returns:
+            none
+
+------------------------------------------------------------------------------*/
+void h264bsdProcessLumaDc(i32 *data, u32 qp)
+{
+
+/* Variables */
+
+    i32 tmp0, tmp1, tmp2, tmp3;
+    u32 row,col;
+    u32 qpMod, qpDiv;
+    i32 levScale;
+    i32 *ptr;
+
+/* Code */
+
+    qpMod = qpMod6[qp];
+    qpDiv = qpDiv6[qp];
+
+    /* zig-zag scan */
+    tmp0 = data[2];
+    data[2]  = data[5];
+    data[5] = data[4];
+    data[4] = tmp0;
+
+    tmp0 = data[8];
+    data[8] = data[3];
+    data[3]  = data[6];
+    data[6]  = data[7];
+    data[7]  = data[12];
+    data[12] = data[9];
+    data[9]  = tmp0;
+
+    tmp0 = data[10];
+    data[10] = data[11];
+    data[11] = data[13];
+    data[13] = tmp0;
+
+    /* horizontal transform */
+    for (row = 4, ptr = data; row--; ptr += 4)
+    {
+        tmp0 = ptr[0] + ptr[2];
+        tmp1 = ptr[0] - ptr[2];
+        tmp2 = ptr[1] - ptr[3];
+        tmp3 = ptr[1] + ptr[3];
+        ptr[0] = tmp0 + tmp3;
+        ptr[1] = tmp1 + tmp2;
+        ptr[2] = tmp1 - tmp2;
+        ptr[3] = tmp0 - tmp3;
+    }
+
+    /*lint +e661 +e662*/
+    /* then vertical transform and inverse scaling */
+    levScale = levelScale[ qpMod ][0];
+    if (qp >= 12)
+    {
+        levScale <<= (qpDiv-2);
+        for (col = 4; col--; data++)
+        {
+            tmp0 = data[0] + data[8 ];
+            tmp1 = data[0] - data[8 ];
+            tmp2 = data[4] - data[12];
+            tmp3 = data[4] + data[12];
+            data[0 ] = ((tmp0 + tmp3)*levScale);
+            data[4 ] = ((tmp1 + tmp2)*levScale);
+            data[8 ] = ((tmp1 - tmp2)*levScale);
+            data[12] = ((tmp0 - tmp3)*levScale);
+        }
+    }
+    else
+    {
+        i32 tmp;
+        tmp = ((1 - qpDiv) == 0) ? 1 : 2;
+        for (col = 4; col--; data++)
+        {
+            tmp0 = data[0] + data[8 ];
+            tmp1 = data[0] - data[8 ];
+            tmp2 = data[4] - data[12];
+            tmp3 = data[4] + data[12];
+            data[0 ] = ((tmp0 + tmp3)*levScale+tmp) >> (2-qpDiv);
+            data[4 ] = ((tmp1 + tmp2)*levScale+tmp) >> (2-qpDiv);
+            data[8 ] = ((tmp1 - tmp2)*levScale+tmp) >> (2-qpDiv);
+            data[12] = ((tmp0 - tmp3)*levScale+tmp) >> (2-qpDiv);
+        }
+    }
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdProcessChromaDc
+
+        Functional description:
+            Function performs inverse transform and inverse scaling for a
+            chroma DC coefficients block
+
+        Inputs:
+            data            pointer to data to be processed
+            qp              quantization parameter
+
+        Outputs:
+            data            processed data
+
+        Returns:
+            none
+
+------------------------------------------------------------------------------*/
+void h264bsdProcessChromaDc(i32 *data, u32 qp)
+{
+
+/* Variables */
+
+    i32 tmp0, tmp1, tmp2, tmp3;
+    u32 qpDiv;
+    i32 levScale;
+    u32 levShift;
+
+/* Code */
+
+    qpDiv = qpDiv6[qp];
+    levScale = levelScale[ qpMod6[qp] ][0];
+
+    if (qp >= 6)
+    {
+        levScale <<= (qpDiv-1);
+        levShift = 0;
+    }
+    else
+    {
+        levShift = 1;
+    }
+
+    tmp0 = data[0] + data[2];
+    tmp1 = data[0] - data[2];
+    tmp2 = data[1] - data[3];
+    tmp3 = data[1] + data[3];
+    data[0] = ((tmp0 + tmp3) * levScale) >> levShift;
+    data[1] = ((tmp0 - tmp3) * levScale) >> levShift;
+    data[2] = ((tmp1 + tmp2) * levScale) >> levShift;
+    data[3] = ((tmp1 - tmp2) * levScale) >> levShift;
+    tmp0 = data[4] + data[6];
+    tmp1 = data[4] - data[6];
+    tmp2 = data[5] - data[7];
+    tmp3 = data[5] + data[7];
+    data[4] = ((tmp0 + tmp3) * levScale) >> levShift;
+    data[5] = ((tmp0 - tmp3) * levScale) >> levShift;
+    data[6] = ((tmp1 + tmp2) * levScale) >> levShift;
+    data[7] = ((tmp1 - tmp2) * levScale) >> levShift;
+
+}
+
+/*lint +e701 +e702 */
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_transform.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_transform.h
new file mode 100755
index 0000000..4f41a23
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_transform.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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+    1. Include headers
+    2. Module defines
+    3. Data types
+    4. Function prototypes
+
+------------------------------------------------------------------------------*/
+
+#ifndef H264SWDEC_TRANSFORM_H
+#define H264SWDEC_TRANSFORM_H
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "basetype.h"
+
+/*------------------------------------------------------------------------------
+    2. Module defines
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    3. Data types
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    4. Function prototypes
+------------------------------------------------------------------------------*/
+
+u32 h264bsdProcessBlock(i32 *data, u32 qp, u32 skip, u32 coeffMap);
+void h264bsdProcessLumaDc(i32 *data, u32 qp);
+void h264bsdProcessChromaDc(i32 *data, u32 qp);
+
+#endif /* #ifdef H264SWDEC_TRANSFORM_H */
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_util.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_util.c
new file mode 100755
index 0000000..53b2fd8
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_util.c
@@ -0,0 +1,286 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+     1. Include headers
+     2. External compiler flags
+     3. Module defines
+     4. Local function prototypes
+     5. Functions
+          h264bsdCountLeadingZeros
+          h264bsdRbspTrailingBits
+          h264bsdMoreRbspData
+          h264bsdNextMbAddress
+          h264bsdSetCurrImageMbPointers
+
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "h264bsd_util.h"
+
+/*------------------------------------------------------------------------------
+    2. External compiler flags
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+    3. Module defines
+------------------------------------------------------------------------------*/
+
+/* look-up table for expected values of stuffing bits */
+static const u32 stuffingTable[8] = {0x1,0x2,0x4,0x8,0x10,0x20,0x40,0x80};
+
+/* look-up table for chroma quantization parameter as a function of luma QP */
+const u32 h264bsdQpC[52] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,
+    20,21,22,23,24,25,26,27,28,29,29,30,31,32,32,33,34,34,35,35,36,36,37,37,37,
+    38,38,38,39,39,39,39};
+
+/*------------------------------------------------------------------------------
+    4. Local function prototypes
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+
+   5.1  Function: h264bsdCountLeadingZeros
+
+        Functional description:
+            Count leading zeros in a code word. Code word is assumed to be
+            right-aligned, last bit of the code word in the lsb of the value.
+
+        Inputs:
+            value   code word
+            length  number of bits in the code word
+
+        Outputs:
+            none
+
+        Returns:
+            number of leading zeros in the code word
+
+------------------------------------------------------------------------------*/
+#ifndef H264DEC_NEON
+u32 h264bsdCountLeadingZeros(u32 value, u32 length)
+{
+
+/* Variables */
+
+    u32 zeros = 0;
+    u32 mask = 1 << (length - 1);
+
+/* Code */
+
+    ASSERT(length <= 32);
+
+    while (mask && !(value & mask))
+    {
+        zeros++;
+        mask >>= 1;
+    }
+    return(zeros);
+
+}
+#endif
+/*------------------------------------------------------------------------------
+
+   5.2  Function: h264bsdRbspTrailingBits
+
+        Functional description:
+            Check Raw Byte Stream Payload (RBSP) trailing bits, i.e. stuffing.
+            Rest of the current byte (whole byte if allready byte aligned)
+            in the stream buffer shall contain a '1' bit followed by zero or
+            more '0' bits.
+
+        Inputs:
+            pStrmData   pointer to stream data structure
+
+        Outputs:
+            none
+
+        Returns:
+            HANTRO_OK      RBSP trailing bits found
+            HANTRO_NOK     otherwise
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdRbspTrailingBits(strmData_t *pStrmData)
+{
+
+/* Variables */
+
+    u32 stuffing;
+    u32 stuffingLength;
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(pStrmData->bitPosInWord < 8);
+
+    stuffingLength = 8 - pStrmData->bitPosInWord;
+
+    stuffing = h264bsdGetBits(pStrmData, stuffingLength);
+    if (stuffing == END_OF_STREAM)
+        return(HANTRO_NOK);
+
+    if (stuffing != stuffingTable[stuffingLength - 1])
+        return(HANTRO_NOK);
+    else
+        return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+   5.3  Function: h264bsdMoreRbspData
+
+        Functional description:
+            Check if there is more data in the current RBSP. The standard
+            defines this function so that there is more data if
+                -more than 8 bits left or
+                -last bits are not RBSP trailing bits
+
+        Inputs:
+            pStrmData   pointer to stream data structure
+
+        Outputs:
+            none
+
+        Returns:
+            HANTRO_TRUE    there is more data
+            HANTRO_FALSE   no more data
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdMoreRbspData(strmData_t *pStrmData)
+{
+
+/* Variables */
+
+    u32 bits;
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(pStrmData->strmBuffReadBits <= 8 * pStrmData->strmBuffSize);
+
+    bits = pStrmData->strmBuffSize * 8 - pStrmData->strmBuffReadBits;
+
+    if (bits == 0)
+        return(HANTRO_FALSE);
+
+    if ( (bits > 8) ||
+         ((h264bsdShowBits32(pStrmData)>>(32-bits)) != (1 << (bits-1))) )
+        return(HANTRO_TRUE);
+    else
+        return(HANTRO_FALSE);
+
+}
+
+/*------------------------------------------------------------------------------
+
+   5.4  Function: h264bsdNextMbAddress
+
+        Functional description:
+            Get address of the next macroblock in the current slice group.
+
+        Inputs:
+            pSliceGroupMap      slice group for each macroblock
+            picSizeInMbs        size of the picture
+            currMbAddr          where to start
+
+        Outputs:
+            none
+
+        Returns:
+            address of the next macroblock
+            0   if none of the following macroblocks belong to same slice
+                group as currMbAddr
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdNextMbAddress(u32 *pSliceGroupMap, u32 picSizeInMbs, u32 currMbAddr)
+{
+
+/* Variables */
+
+    u32 i, sliceGroup, tmp;
+
+/* Code */
+
+    ASSERT(pSliceGroupMap);
+    ASSERT(picSizeInMbs);
+    ASSERT(currMbAddr < picSizeInMbs);
+
+    sliceGroup = pSliceGroupMap[currMbAddr];
+
+    i = currMbAddr + 1;
+    tmp = pSliceGroupMap[i];
+    while ((i < picSizeInMbs) && (tmp != sliceGroup))
+    {
+        i++;
+        tmp = pSliceGroupMap[i];
+    }
+
+    if (i == picSizeInMbs)
+        i = 0;
+
+    return(i);
+
+}
+
+
+/*------------------------------------------------------------------------------
+
+   5.5  Function: h264bsdSetCurrImageMbPointers
+
+        Functional description:
+            Set luma and chroma pointers in image_t for current MB
+
+        Inputs:
+            image       Current image
+            mbNum       number of current MB
+
+        Outputs:
+            none
+
+        Returns:
+            none
+------------------------------------------------------------------------------*/
+void h264bsdSetCurrImageMbPointers(image_t *image, u32 mbNum)
+{
+    u32 width, height;
+    u32 picSize;
+    u32 row, col;
+    u32 tmp;
+
+    width = image->width;
+    height = image->height;
+    row = mbNum / width;
+    col = mbNum % width;
+
+    tmp = row * width;
+    picSize = width * height;
+
+    image->luma = (u8*)(image->data + col * 16 + tmp * 256);
+    image->cb = (u8*)(image->data + picSize * 256 + tmp * 64 + col * 8);
+    image->cr = (u8*)(image->cb + picSize * 64);
+}
+
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_util.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_util.h
new file mode 100755
index 0000000..cb3adda
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_util.h
@@ -0,0 +1,178 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+    1. Include headers
+    2. Module defines
+    3. Data types
+    4. Function prototypes
+
+------------------------------------------------------------------------------*/
+
+#ifndef H264SWDEC_UTIL_H
+#define H264SWDEC_UTIL_H
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#ifdef _ASSERT_USED
+#include <assert.h>
+#endif
+
+#include "H264SwDecApi.h"
+
+#if defined(_RANGE_CHECK) || defined(_DEBUG_PRINT) || defined(_ERROR_PRINT)
+#include <stdio.h>
+#endif
+
+#include "basetype.h"
+#include "h264bsd_stream.h"
+#include "h264bsd_image.h"
+
+/*------------------------------------------------------------------------------
+    2. Module defines
+------------------------------------------------------------------------------*/
+
+#define HANTRO_OK   0
+#define HANTRO_NOK  1
+
+#define HANTRO_TRUE     (1)
+#define HANTRO_FALSE    (0)
+
+#ifndef NULL
+#define NULL 0
+#endif
+
+#define MEMORY_ALLOCATION_ERROR 0xFFFF
+#define PARAM_SET_ERROR 0xFFF0
+
+/* value to be returned by GetBits if stream buffer is empty */
+#define END_OF_STREAM 0xFFFFFFFFU
+
+#define EMPTY_RESIDUAL_INDICATOR 0xFFFFFF
+
+/* macro to mark a residual block empty, i.e. contain zero coefficients */
+#define MARK_RESIDUAL_EMPTY(residual) ((residual)[0] = EMPTY_RESIDUAL_INDICATOR)
+/* macro to check if residual block is empty */
+#define IS_RESIDUAL_EMPTY(residual) ((residual)[0] == EMPTY_RESIDUAL_INDICATOR)
+
+/* macro for assertion, used only if compiler flag _ASSERT_USED is defined */
+#ifdef _ASSERT_USED
+#define ASSERT(expr) assert(expr)
+#else
+#define ASSERT(expr)
+#endif
+
+/* macro for range checking an value, used only if compiler flag _RANGE_CHECK
+ * is defined */
+#ifdef _RANGE_CHECK
+#define RANGE_CHECK(value, minBound, maxBound) \
+{ \
+    if ((value) < (minBound) || (value) > (maxBound)) \
+        fprintf(stderr, "Warning: Value exceeds given limit(s)!\n"); \
+}
+#else
+#define RANGE_CHECK(value, minBound, maxBound)
+#endif
+
+/* macro for range checking an array, used only if compiler flag _RANGE_CHECK
+ * is defined */
+#ifdef _RANGE_CHECK
+#define RANGE_CHECK_ARRAY(array, minBound, maxBound, length) \
+{ \
+    i32 i; \
+    for (i = 0; i < (length); i++) \
+        if ((array)[i] < (minBound) || (array)[i] > (maxBound)) \
+            fprintf(stderr,"Warning: Value [%d] exceeds given limit(s)!\n",i); \
+}
+#else
+#define RANGE_CHECK_ARRAY(array, minBound, maxBound, length)
+#endif
+
+/* macro for debug printing, used only if compiler flag _DEBUG_PRINT is
+ * defined */
+#ifdef _DEBUG_PRINT
+#define DEBUG(args) printf args
+#else
+#define DEBUG(args)
+#endif
+
+/* macro for error printing, used only if compiler flag _ERROR_PRINT is
+ * defined */
+#ifdef _ERROR_PRINT
+#define EPRINT(msg) fprintf(stderr,"ERROR: %s\n",msg)
+#else
+#define EPRINT(msg)
+#endif
+
+/* macro to get smaller of two values */
+#define MIN(a, b) (((a) < (b)) ? (a) : (b))
+
+/* macro to get greater of two values */
+#define MAX(a, b) (((a) > (b)) ? (a) : (b))
+
+/* macro to get absolute value */
+#define ABS(a) (((a) < 0) ? -(a) : (a))
+
+/* macro to clip a value z, so that x <= z =< y */
+#define CLIP3(x,y,z) (((z) < (x)) ? (x) : (((z) > (y)) ? (y) : (z)))
+
+/* macro to clip a value z, so that 0 <= z =< 255 */
+#define CLIP1(z) (((z) < 0) ? 0 : (((z) > 255) ? 255 : (z)))
+
+/* macro to allocate memory */
+#define ALLOCATE(ptr, count, type) \
+{ \
+    (ptr) = H264SwDecMalloc((count) * sizeof(type)); \
+}
+
+/* macro to free allocated memory */
+#define FREE(ptr) \
+{ \
+    H264SwDecFree((ptr)); (ptr) = NULL; \
+}
+
+#define ALIGN(ptr, bytePos) \
+        (ptr + ( ((bytePos - (int)ptr) & (bytePos - 1)) / sizeof(*ptr) ))
+
+extern const u32 h264bsdQpC[52];
+
+/*------------------------------------------------------------------------------
+    3. Data types
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    4. Function prototypes
+------------------------------------------------------------------------------*/
+#ifndef H264DEC_NEON
+u32 h264bsdCountLeadingZeros(u32 value, u32 length);
+#else
+u32 h264bsdCountLeadingZeros(u32 value);
+#endif
+u32 h264bsdRbspTrailingBits(strmData_t *strmData);
+
+u32 h264bsdMoreRbspData(strmData_t *strmData);
+
+u32 h264bsdNextMbAddress(u32 *pSliceGroupMap, u32 picSizeInMbs, u32 currMbAddr);
+
+void h264bsdSetCurrImageMbPointers(image_t *image, u32 mbNum);
+
+#endif /* #ifdef H264SWDEC_UTIL_H */
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_vlc.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_vlc.c
new file mode 100755
index 0000000..060f35e
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_vlc.c
@@ -0,0 +1,391 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+     1. Include headers
+     2. External compiler flags
+     3. Module defines
+     4. Local function prototypes
+     5. Functions
+          h264bsdDecodeExpGolombUnsigned
+          h264bsdDecodeExpGolombSigned
+          h264bsdDecodeExpGolombMapped
+          h264bsdDecodeExpGolombTruncated
+
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "h264bsd_vlc.h"
+#include "basetype.h"
+#include "h264bsd_stream.h"
+#include "h264bsd_util.h"
+
+/*------------------------------------------------------------------------------
+    2. External compiler flags
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+    3. Module defines
+------------------------------------------------------------------------------*/
+
+/* definition of special code num, this along with the return value is used
+ * to handle code num in the range [0, 2^32] in the DecodeExpGolombUnsigned
+ * function */
+#define BIG_CODE_NUM 0xFFFFFFFFU
+
+/* Mapping tables for coded_block_pattern, used for decoding of mapped
+ * Exp-Golomb codes */
+static const u8 codedBlockPatternIntra4x4[48] = {
+    47,31,15,0,23,27,29,30,7,11,13,14,39,43,45,46,16,3,5,10,12,19,21,26,28,35,
+    37,42,44,1,2,4,8,17,18,20,24,6,9,22,25,32,33,34,36,40,38,41};
+
+static const u8 codedBlockPatternInter[48] = {
+    0,16,1,2,4,8,32,3,5,10,12,15,47,7,11,13,14,6,9,31,35,37,42,44,33,34,36,40,
+    39,43,45,46,17,18,20,24,19,21,26,28,23,27,29,30,22,25,38,41};
+
+/*------------------------------------------------------------------------------
+    4. Local function prototypes
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+
+   5.1  Function: h264bsdDecodeExpGolombUnsigned
+
+        Functional description:
+            Decode unsigned Exp-Golomb code. This is the same as codeNum used
+            in other Exp-Golomb code mappings. Code num (i.e. the decoded
+            symbol) is determined as
+
+                codeNum = 2^leadingZeros - 1 + GetBits(leadingZeros)
+
+            Normal decoded symbols are in the range [0, 2^32 - 2]. Symbol
+            2^32-1 is indicated by BIG_CODE_NUM with return value HANTRO_OK
+            while symbol 2^32  is indicated by BIG_CODE_NUM with return value
+            HANTRO_NOK.  These two symbols are special cases with code length
+            of 65, i.e.  32 '0' bits, a '1' bit, and either 0 or 1 represented
+            by 32 bits.
+
+            Symbol 2^32 is out of unsigned 32-bit range but is needed for
+            DecodeExpGolombSigned to express value -2^31.
+
+        Inputs:
+            pStrmData       pointer to stream data structure
+
+        Outputs:
+            codeNum         decoded code word is stored here
+
+        Returns:
+            HANTRO_OK       success
+            HANTRO_NOK      failure, no valid code word found, note exception
+                            with BIG_CODE_NUM
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdDecodeExpGolombUnsigned(strmData_t *pStrmData, u32 *codeNum)
+{
+
+/* Variables */
+
+    u32 bits, numZeros;
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(codeNum);
+
+    bits = h264bsdShowBits32(pStrmData);
+
+    /* first bit is 1 -> code length 1 */
+    if (bits >= 0x80000000)
+    {
+        h264bsdFlushBits(pStrmData, 1);
+        *codeNum = 0;
+        return(HANTRO_OK);
+    }
+    /* second bit is 1 -> code length 3 */
+    else if (bits >= 0x40000000)
+    {
+        if (h264bsdFlushBits(pStrmData, 3) == END_OF_STREAM)
+            return(HANTRO_NOK);
+        *codeNum = 1 + ((bits >> 29) & 0x1);
+        return(HANTRO_OK);
+    }
+    /* third bit is 1 -> code length 5 */
+    else if (bits >= 0x20000000)
+    {
+        if (h264bsdFlushBits(pStrmData, 5) == END_OF_STREAM)
+            return(HANTRO_NOK);
+        *codeNum = 3 + ((bits >> 27) & 0x3);
+        return(HANTRO_OK);
+    }
+    /* fourth bit is 1 -> code length 7 */
+    else if (bits >= 0x10000000)
+    {
+        if (h264bsdFlushBits(pStrmData, 7) == END_OF_STREAM)
+            return(HANTRO_NOK);
+        *codeNum = 7 + ((bits >> 25) & 0x7);
+        return(HANTRO_OK);
+    }
+    /* other code lengths */
+    else
+    {
+#ifndef H264DEC_NEON
+        numZeros = 4 + h264bsdCountLeadingZeros(bits, 28);
+#else
+        numZeros = h264bsdCountLeadingZeros(bits);
+#endif
+        /* all 32 bits are zero */
+        if (numZeros == 32)
+        {
+            *codeNum = 0;
+            h264bsdFlushBits(pStrmData,32);
+            bits = h264bsdGetBits(pStrmData, 1);
+            /* check 33rd bit, must be 1 */
+            if (bits == 1)
+            {
+                /* cannot use h264bsdGetBits, limited to 31 bits */
+                bits = h264bsdShowBits32(pStrmData);
+                if (h264bsdFlushBits(pStrmData, 32) == END_OF_STREAM)
+                    return(HANTRO_NOK);
+                /* code num 2^32 - 1, needed for unsigned mapping */
+                if (bits == 0)
+                {
+                    *codeNum = BIG_CODE_NUM;
+                    return(HANTRO_OK);
+                }
+                /* code num 2^32, needed for unsigned mapping
+                 * (results in -2^31) */
+                else if (bits == 1)
+                {
+                    *codeNum = BIG_CODE_NUM;
+                    return(HANTRO_NOK);
+                }
+            }
+            /* if more zeros than 32, it is an error */
+            return(HANTRO_NOK);
+        }
+        else
+            h264bsdFlushBits(pStrmData,numZeros+1);
+
+        bits = h264bsdGetBits(pStrmData, numZeros);
+        if (bits == END_OF_STREAM)
+            return(HANTRO_NOK);
+
+        *codeNum = (1 << numZeros) - 1 + bits;
+
+    }
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+   5.2  Function: h264bsdDecodeExpGolombSigned
+
+        Functional description:
+            Decode signed Exp-Golomb code. Code num is determined by
+            h264bsdDecodeExpGolombUnsigned and then mapped to signed
+            representation as
+
+                symbol = (-1)^(codeNum+1) * (codeNum+1)/2
+
+            Signed symbols shall be in the range [-2^31, 2^31 - 1]. Symbol
+            -2^31 is obtained when codeNum is 2^32, which cannot be expressed
+            by unsigned 32-bit value. This is signaled as a special case from
+            the h264bsdDecodeExpGolombUnsigned by setting codeNum to
+            BIG_CODE_NUM and returning HANTRO_NOK status.
+
+        Inputs:
+            pStrmData       pointer to stream data structure
+
+        Outputs:
+            value           decoded code word is stored here
+
+        Returns:
+            HANTRO_OK       success
+            HANTRO_NOK      failure, no valid code word found
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdDecodeExpGolombSigned(strmData_t *pStrmData, i32 *value)
+{
+
+/* Variables */
+
+    u32 status, codeNum = 0;
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(value);
+
+    status = h264bsdDecodeExpGolombUnsigned(pStrmData, &codeNum);
+
+    if (codeNum == BIG_CODE_NUM)
+    {
+        /* BIG_CODE_NUM and HANTRO_OK status means codeNum 2^32-1 which would
+         * result in signed integer valued 2^31 (i.e. out of 32-bit signed
+         * integer range) */
+        if (status == HANTRO_OK)
+            return(HANTRO_NOK);
+        /* BIG_CODE_NUM and HANTRO_NOK status means codeNum 2^32 which results
+         * in signed integer valued -2^31 */
+        else
+        {
+            *value = (i32)(2147483648U);
+            return (HANTRO_OK);
+        }
+    }
+    else if (status == HANTRO_OK)
+    {
+        /* (-1)^(codeNum+1) results in positive sign if codeNum is odd,
+         * negative when it is even. (codeNum+1)/2 is obtained as
+         * (codeNum+1)>>1 when value is positive and as (-codeNum)>>1 for
+         * negative value */
+        /*lint -e702 */
+        *value = (codeNum & 0x1) ? (i32)((codeNum + 1) >> 1) :
+                                  -(i32)((codeNum + 1) >> 1);
+        /*lint +e702 */
+        return(HANTRO_OK);
+    }
+
+    return(HANTRO_NOK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+   5.3  Function: h264bsdDecodeExpGolombMapped
+
+        Functional description:
+            Decode mapped Exp-Golomb code. Code num is determined by
+            h264bsdDecodeExpGolombUnsigned and then mapped to codedBlockPattern
+            either for intra or inter macroblock. The mapping is implemented by
+            look-up tables defined in the beginning of the file.
+
+        Inputs:
+            pStrmData       pointer to stream data structure
+            isIntra         flag to indicate if intra or inter mapping is to
+                            be used
+
+        Outputs:
+            value           decoded code word is stored here
+
+        Returns:
+            HANTRO_OK       success
+            HANTRO_NOK      failure, no valid code word found
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdDecodeExpGolombMapped(strmData_t *pStrmData, u32 *value,
+    u32 isIntra)
+{
+
+/* Variables */
+
+    u32 status, codeNum;
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(value);
+
+    status = h264bsdDecodeExpGolombUnsigned(pStrmData, &codeNum);
+
+    if (status != HANTRO_OK)
+        return (HANTRO_NOK);
+    else
+    {
+        /* range of valid codeNums [0,47] */
+        if (codeNum > 47)
+            return (HANTRO_NOK);
+        if (isIntra)
+            *value = codedBlockPatternIntra4x4[codeNum];
+        else
+            *value = codedBlockPatternInter[codeNum];
+        return(HANTRO_OK);
+    }
+
+}
+
+/*------------------------------------------------------------------------------
+
+   5.4  Function: h264bsdDecodeExpGolombTruncated
+
+        Functional description:
+            Decode truncated Exp-Golomb code. greaterThanOne flag indicates
+            the range of the symbol to be decoded as follows:
+                FALSE   ->  [0,1]
+                TRUE    ->  [0,2^32-1]
+
+            If flag is false the decoding is performed by reading one bit
+            from the stream with h264bsdGetBits and mapping this to decoded
+            symbol as
+                symbol = bit ? 0 : 1
+
+            Otherwise, i.e. when flag is TRUE, code num is determined by
+            h264bsdDecodeExpGolombUnsigned and this is used as the decoded
+            symbol.
+
+        Inputs:
+            pStrmData       pointer to stream data structure
+            greaterThanOne  flag to indicate if range is wider than [0,1]
+
+        Outputs:
+            value           decoded code word is stored here
+
+        Returns:
+            HANTRO_OK       success
+            HANTRO_NOK      failure, no valid code word found
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdDecodeExpGolombTruncated(
+  strmData_t *pStrmData,
+  u32 *value,
+  u32 greaterThanOne)
+{
+
+/* Variables */
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(value);
+
+    if (greaterThanOne)
+    {
+        return(h264bsdDecodeExpGolombUnsigned(pStrmData, value));
+    }
+    else
+    {
+        *value = h264bsdGetBits(pStrmData,1);
+        if (*value == END_OF_STREAM)
+            return (HANTRO_NOK);
+        *value ^= 0x1;
+    }
+
+    return (HANTRO_OK);
+
+}
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_vlc.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_vlc.h
new file mode 100755
index 0000000..4c16773
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_vlc.h
@@ -0,0 +1,63 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+    1. Include headers
+    2. Module defines
+    3. Data types
+    4. Function prototypes
+
+------------------------------------------------------------------------------*/
+
+#ifndef H264SWDEC_VLC_H
+#define H264SWDEC_VLC_H
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "basetype.h"
+#include "h264bsd_stream.h"
+#include "h264bsd_transform.h"
+
+/*------------------------------------------------------------------------------
+    2. Module defines
+------------------------------------------------------------------------------*/
+
+
+/*------------------------------------------------------------------------------
+    3. Data types
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    4. Function prototypes
+------------------------------------------------------------------------------*/
+
+u32 h264bsdDecodeExpGolombUnsigned(strmData_t *pStrmData, u32 *value);
+
+u32 h264bsdDecodeExpGolombSigned(strmData_t *pStrmData, i32 *value);
+
+u32 h264bsdDecodeExpGolombMapped(strmData_t *pStrmData, u32 *value,
+    u32 isIntra);
+
+u32 h264bsdDecodeExpGolombTruncated(strmData_t *pStrmData, u32 *value,
+    u32 greaterThanOne);
+
+#endif /* #ifdef H264SWDEC_VLC_H */
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_vui.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_vui.c
new file mode 100755
index 0000000..4a9335a
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_vui.c
@@ -0,0 +1,490 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+     1. Include headers
+     2. External compiler flags
+     3. Module defines
+     4. Local function prototypes
+     5. Functions
+          h264bsdDecodeVuiParameters
+          DecodeHrdParameters
+
+------------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "h264bsd_vui.h"
+#include "basetype.h"
+#include "h264bsd_vlc.h"
+#include "h264bsd_stream.h"
+#include "h264bsd_util.h"
+
+/*------------------------------------------------------------------------------
+    2. External compiler flags
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+    3. Module defines
+------------------------------------------------------------------------------*/
+
+#define MAX_DPB_SIZE 16
+#define MAX_BR       240000 /* for level 5.1 */
+#define MAX_CPB      240000 /* for level 5.1 */
+
+/*------------------------------------------------------------------------------
+    4. Local function prototypes
+------------------------------------------------------------------------------*/
+
+static u32 DecodeHrdParameters(
+  strmData_t *pStrmData,
+  hrdParameters_t *pHrdParameters);
+
+/*------------------------------------------------------------------------------
+
+    Function: h264bsdDecodeVuiParameters
+
+        Functional description:
+            Decode VUI parameters from the stream. See standard for details.
+
+        Inputs:
+            pStrmData       pointer to stream data structure
+
+        Outputs:
+            pVuiParameters  decoded information is stored here
+
+        Returns:
+            HANTRO_OK       success
+            HANTRO_NOK      invalid stream data or end of stream
+
+------------------------------------------------------------------------------*/
+
+u32 h264bsdDecodeVuiParameters(strmData_t *pStrmData,
+    vuiParameters_t *pVuiParameters)
+{
+
+/* Variables */
+
+    u32 tmp;
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(pVuiParameters);
+
+    H264SwDecMemset(pVuiParameters, 0, sizeof(vuiParameters_t));
+
+    tmp = h264bsdGetBits(pStrmData, 1);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    pVuiParameters->aspectRatioPresentFlag = (tmp == 1) ?
+                                HANTRO_TRUE : HANTRO_FALSE;
+
+    if (pVuiParameters->aspectRatioPresentFlag)
+    {
+        tmp = h264bsdGetBits(pStrmData, 8);
+        if (tmp == END_OF_STREAM)
+            return(HANTRO_NOK);
+        pVuiParameters->aspectRatioIdc = tmp;
+
+        if (pVuiParameters->aspectRatioIdc == ASPECT_RATIO_EXTENDED_SAR)
+        {
+            tmp = h264bsdGetBits(pStrmData, 16);
+            if (tmp == END_OF_STREAM)
+                return(HANTRO_NOK);
+            pVuiParameters->sarWidth = tmp;
+
+            tmp = h264bsdGetBits(pStrmData, 16);
+            if (tmp == END_OF_STREAM)
+                return(HANTRO_NOK);
+            pVuiParameters->sarHeight = tmp;
+        }
+    }
+
+    tmp = h264bsdGetBits(pStrmData, 1);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    pVuiParameters->overscanInfoPresentFlag = (tmp == 1) ?
+                                HANTRO_TRUE : HANTRO_FALSE;
+
+    if (pVuiParameters->overscanInfoPresentFlag)
+    {
+        tmp = h264bsdGetBits(pStrmData, 1);
+        if (tmp == END_OF_STREAM)
+            return(HANTRO_NOK);
+        pVuiParameters->overscanAppropriateFlag = (tmp == 1) ?
+                                HANTRO_TRUE : HANTRO_FALSE;
+    }
+
+    tmp = h264bsdGetBits(pStrmData, 1);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    pVuiParameters->videoSignalTypePresentFlag = (tmp == 1) ?
+                                HANTRO_TRUE : HANTRO_FALSE;
+
+    if (pVuiParameters->videoSignalTypePresentFlag)
+    {
+        tmp = h264bsdGetBits(pStrmData, 3);
+        if (tmp == END_OF_STREAM)
+            return(HANTRO_NOK);
+        pVuiParameters->videoFormat = tmp;
+
+        tmp = h264bsdGetBits(pStrmData, 1);
+        if (tmp == END_OF_STREAM)
+            return(HANTRO_NOK);
+        pVuiParameters->videoFullRangeFlag = (tmp == 1) ?
+                                HANTRO_TRUE : HANTRO_FALSE;
+
+        tmp = h264bsdGetBits(pStrmData, 1);
+        if (tmp == END_OF_STREAM)
+            return(HANTRO_NOK);
+        pVuiParameters->colourDescriptionPresentFlag =
+            (tmp == 1) ? HANTRO_TRUE : HANTRO_FALSE;
+
+        if (pVuiParameters->colourDescriptionPresentFlag)
+        {
+            tmp = h264bsdGetBits(pStrmData, 8);
+            if (tmp == END_OF_STREAM)
+                return(HANTRO_NOK);
+            pVuiParameters->colourPrimaries = tmp;
+
+            tmp = h264bsdGetBits(pStrmData, 8);
+            if (tmp == END_OF_STREAM)
+                return(HANTRO_NOK);
+            pVuiParameters->transferCharacteristics = tmp;
+
+            tmp = h264bsdGetBits(pStrmData, 8);
+            if (tmp == END_OF_STREAM)
+                return(HANTRO_NOK);
+            pVuiParameters->matrixCoefficients = tmp;
+        }
+        else
+        {
+            pVuiParameters->colourPrimaries         = 2;
+            pVuiParameters->transferCharacteristics = 2;
+            pVuiParameters->matrixCoefficients      = 2;
+        }
+    }
+    else
+    {
+        pVuiParameters->videoFormat             = 5;
+        pVuiParameters->colourPrimaries         = 2;
+        pVuiParameters->transferCharacteristics = 2;
+        pVuiParameters->matrixCoefficients      = 2;
+    }
+
+    tmp = h264bsdGetBits(pStrmData, 1);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    pVuiParameters->chromaLocInfoPresentFlag =
+        (tmp == 1) ? HANTRO_TRUE : HANTRO_FALSE;
+
+    if (pVuiParameters->chromaLocInfoPresentFlag)
+    {
+        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+          &pVuiParameters->chromaSampleLocTypeTopField);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+        if (pVuiParameters->chromaSampleLocTypeTopField > 5)
+            return(HANTRO_NOK);
+
+        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+          &pVuiParameters->chromaSampleLocTypeBottomField);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+        if (pVuiParameters->chromaSampleLocTypeBottomField > 5)
+            return(HANTRO_NOK);
+    }
+
+    tmp = h264bsdGetBits(pStrmData, 1);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    pVuiParameters->timingInfoPresentFlag =
+        (tmp == 1) ? HANTRO_TRUE : HANTRO_FALSE;
+
+    if (pVuiParameters->timingInfoPresentFlag)
+    {
+        tmp = h264bsdShowBits32(pStrmData);
+        if (h264bsdFlushBits(pStrmData, 32) == END_OF_STREAM)
+            return(HANTRO_NOK);
+        if (tmp == 0)
+            return(HANTRO_NOK);
+        pVuiParameters->numUnitsInTick = tmp;
+
+        tmp = h264bsdShowBits32(pStrmData);
+        if (h264bsdFlushBits(pStrmData, 32) == END_OF_STREAM)
+            return(HANTRO_NOK);
+        if (tmp == 0)
+            return(HANTRO_NOK);
+        pVuiParameters->timeScale = tmp;
+
+        tmp = h264bsdGetBits(pStrmData, 1);
+        if (tmp == END_OF_STREAM)
+            return(HANTRO_NOK);
+        pVuiParameters->fixedFrameRateFlag =
+            (tmp == 1) ? HANTRO_TRUE : HANTRO_FALSE;
+    }
+
+    tmp = h264bsdGetBits(pStrmData, 1);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    pVuiParameters->nalHrdParametersPresentFlag =
+        (tmp == 1) ? HANTRO_TRUE : HANTRO_FALSE;
+
+    if (pVuiParameters->nalHrdParametersPresentFlag)
+    {
+        tmp = DecodeHrdParameters(pStrmData, &pVuiParameters->nalHrdParameters);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+    }
+    else
+    {
+        pVuiParameters->nalHrdParameters.cpbCnt          = 1;
+        /* MaxBR and MaxCPB should be the values correspondig to the levelIdc
+         * in the SPS containing these VUI parameters. However, these values
+         * are not used anywhere and maximum for any level will be used here */
+        pVuiParameters->nalHrdParameters.bitRateValue[0] = 1200 * MAX_BR + 1;
+        pVuiParameters->nalHrdParameters.cpbSizeValue[0] = 1200 * MAX_CPB + 1;
+        pVuiParameters->nalHrdParameters.initialCpbRemovalDelayLength = 24;
+        pVuiParameters->nalHrdParameters.cpbRemovalDelayLength        = 24;
+        pVuiParameters->nalHrdParameters.dpbOutputDelayLength         = 24;
+        pVuiParameters->nalHrdParameters.timeOffsetLength             = 24;
+    }
+
+    tmp = h264bsdGetBits(pStrmData, 1);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    pVuiParameters->vclHrdParametersPresentFlag =
+        (tmp == 1) ? HANTRO_TRUE : HANTRO_FALSE;
+
+    if (pVuiParameters->vclHrdParametersPresentFlag)
+    {
+        tmp = DecodeHrdParameters(pStrmData, &pVuiParameters->vclHrdParameters);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+    }
+    else
+    {
+        pVuiParameters->vclHrdParameters.cpbCnt          = 1;
+        /* MaxBR and MaxCPB should be the values correspondig to the levelIdc
+         * in the SPS containing these VUI parameters. However, these values
+         * are not used anywhere and maximum for any level will be used here */
+        pVuiParameters->vclHrdParameters.bitRateValue[0] = 1000 * MAX_BR + 1;
+        pVuiParameters->vclHrdParameters.cpbSizeValue[0] = 1000 * MAX_CPB + 1;
+        pVuiParameters->vclHrdParameters.initialCpbRemovalDelayLength = 24;
+        pVuiParameters->vclHrdParameters.cpbRemovalDelayLength        = 24;
+        pVuiParameters->vclHrdParameters.dpbOutputDelayLength         = 24;
+        pVuiParameters->vclHrdParameters.timeOffsetLength             = 24;
+    }
+
+    if (pVuiParameters->nalHrdParametersPresentFlag ||
+      pVuiParameters->vclHrdParametersPresentFlag)
+    {
+        tmp = h264bsdGetBits(pStrmData, 1);
+        if (tmp == END_OF_STREAM)
+            return(HANTRO_NOK);
+        pVuiParameters->lowDelayHrdFlag =
+            (tmp == 1) ? HANTRO_TRUE : HANTRO_FALSE;
+    }
+
+    tmp = h264bsdGetBits(pStrmData, 1);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    pVuiParameters->picStructPresentFlag =
+        (tmp == 1) ? HANTRO_TRUE : HANTRO_FALSE;
+
+    tmp = h264bsdGetBits(pStrmData, 1);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    pVuiParameters->bitstreamRestrictionFlag =
+        (tmp == 1) ? HANTRO_TRUE : HANTRO_FALSE;
+
+    if (pVuiParameters->bitstreamRestrictionFlag)
+    {
+        tmp = h264bsdGetBits(pStrmData, 1);
+        if (tmp == END_OF_STREAM)
+            return(HANTRO_NOK);
+        pVuiParameters->motionVectorsOverPicBoundariesFlag =
+            (tmp == 1) ? HANTRO_TRUE : HANTRO_FALSE;
+
+        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+          &pVuiParameters->maxBytesPerPicDenom);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+        if (pVuiParameters->maxBytesPerPicDenom > 16)
+            return(HANTRO_NOK);
+
+        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+          &pVuiParameters->maxBitsPerMbDenom);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+        if (pVuiParameters->maxBitsPerMbDenom > 16)
+            return(HANTRO_NOK);
+
+        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+          &pVuiParameters->log2MaxMvLengthHorizontal);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+        if (pVuiParameters->log2MaxMvLengthHorizontal > 16)
+            return(HANTRO_NOK);
+
+        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+          &pVuiParameters->log2MaxMvLengthVertical);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+        if (pVuiParameters->log2MaxMvLengthVertical > 16)
+            return(HANTRO_NOK);
+
+        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+          &pVuiParameters->numReorderFrames);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+
+        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+          &pVuiParameters->maxDecFrameBuffering);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+    }
+    else
+    {
+        pVuiParameters->motionVectorsOverPicBoundariesFlag = HANTRO_TRUE;
+        pVuiParameters->maxBytesPerPicDenom       = 2;
+        pVuiParameters->maxBitsPerMbDenom         = 1;
+        pVuiParameters->log2MaxMvLengthHorizontal = 16;
+        pVuiParameters->log2MaxMvLengthVertical   = 16;
+        pVuiParameters->numReorderFrames          = MAX_DPB_SIZE;
+        pVuiParameters->maxDecFrameBuffering      = MAX_DPB_SIZE;
+    }
+
+    return(HANTRO_OK);
+
+}
+
+/*------------------------------------------------------------------------------
+
+    Function: DecodeHrdParameters
+
+        Functional description:
+            Decode HRD parameters from the stream. See standard for details.
+
+        Inputs:
+            pStrmData       pointer to stream data structure
+
+        Outputs:
+            pHrdParameters  decoded information is stored here
+
+        Returns:
+            HANTRO_OK       success
+            HANTRO_NOK      invalid stream data
+
+------------------------------------------------------------------------------*/
+
+static u32 DecodeHrdParameters(
+  strmData_t *pStrmData,
+  hrdParameters_t *pHrdParameters)
+{
+
+/* Variables */
+
+    u32 tmp, i;
+
+/* Code */
+
+    ASSERT(pStrmData);
+    ASSERT(pHrdParameters);
+
+
+    tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &pHrdParameters->cpbCnt);
+    if (tmp != HANTRO_OK)
+        return(tmp);
+    /* cpbCount = cpb_cnt_minus1 + 1 */
+    pHrdParameters->cpbCnt++;
+    if (pHrdParameters->cpbCnt > MAX_CPB_CNT)
+        return(HANTRO_NOK);
+
+    tmp = h264bsdGetBits(pStrmData, 4);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    pHrdParameters->bitRateScale = tmp;
+
+    tmp = h264bsdGetBits(pStrmData, 4);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    pHrdParameters->cpbSizeScale = tmp;
+
+    for (i = 0; i < pHrdParameters->cpbCnt; i++)
+    {
+        /* bit_rate_value_minus1 in the range [0, 2^32 - 2] */
+        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+          &pHrdParameters->bitRateValue[i]);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+        if (pHrdParameters->bitRateValue[i] > 4294967294U)
+            return(HANTRO_NOK);
+        pHrdParameters->bitRateValue[i]++;
+        /* this may result in overflow, but this value is not used for
+         * anything */
+        pHrdParameters->bitRateValue[i] *=
+            1 << (6 + pHrdParameters->bitRateScale);
+
+        /* cpb_size_value_minus1 in the range [0, 2^32 - 2] */
+        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData,
+          &pHrdParameters->cpbSizeValue[i]);
+        if (tmp != HANTRO_OK)
+            return(tmp);
+        if (pHrdParameters->cpbSizeValue[i] > 4294967294U)
+            return(HANTRO_NOK);
+        pHrdParameters->cpbSizeValue[i]++;
+        /* this may result in overflow, but this value is not used for
+         * anything */
+        pHrdParameters->cpbSizeValue[i] *=
+            1 << (4 + pHrdParameters->cpbSizeScale);
+
+        tmp = h264bsdGetBits(pStrmData, 1);
+        if (tmp == END_OF_STREAM)
+            return(HANTRO_NOK);
+        pHrdParameters->cbrFlag[i] = (tmp == 1) ? HANTRO_TRUE : HANTRO_FALSE;
+    }
+
+    tmp = h264bsdGetBits(pStrmData, 5);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    pHrdParameters->initialCpbRemovalDelayLength = tmp + 1;
+
+    tmp = h264bsdGetBits(pStrmData, 5);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    pHrdParameters->cpbRemovalDelayLength = tmp + 1;
+
+    tmp = h264bsdGetBits(pStrmData, 5);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    pHrdParameters->dpbOutputDelayLength = tmp + 1;
+
+    tmp = h264bsdGetBits(pStrmData, 5);
+    if (tmp == END_OF_STREAM)
+        return(HANTRO_NOK);
+    pHrdParameters->timeOffsetLength = tmp;
+
+    return(HANTRO_OK);
+
+}
+
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_vui.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_vui.h
new file mode 100755
index 0000000..05d52a4
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_vui.h
@@ -0,0 +1,130 @@
+/*
+ * 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.
+ */
+
+/*------------------------------------------------------------------------------
+
+    Table of contents
+
+    1. Include headers
+    2. Module defines
+    3. Data types
+    4. Function prototypes
+
+------------------------------------------------------------------------------*/
+
+#ifndef H264SWDEC_VUI_H
+#define H264SWDEC_VUI_H
+
+/*------------------------------------------------------------------------------
+    1. Include headers
+------------------------------------------------------------------------------*/
+
+#include "basetype.h"
+#include "h264bsd_stream.h"
+
+/*------------------------------------------------------------------------------
+    2. Module defines
+------------------------------------------------------------------------------*/
+
+#define MAX_CPB_CNT 32
+
+/*------------------------------------------------------------------------------
+    3. Data types
+------------------------------------------------------------------------------*/
+
+/* enumerated sample aspect ratios, ASPECT_RATIO_M_N means M:N */
+enum
+{
+    ASPECT_RATIO_UNSPECIFIED = 0,
+    ASPECT_RATIO_1_1,
+    ASPECT_RATIO_12_11,
+    ASPECT_RATIO_10_11,
+    ASPECT_RATIO_16_11,
+    ASPECT_RATIO_40_33,
+    ASPECT_RATIO_24_11,
+    ASPECT_RATIO_20_11,
+    ASPECT_RATIO_32_11,
+    ASPECT_RATIO_80_33,
+    ASPECT_RATIO_18_11,
+    ASPECT_RATIO_15_11,
+    ASPECT_RATIO_64_33,
+    ASPECT_RATIO_160_99,
+    ASPECT_RATIO_EXTENDED_SAR = 255
+};
+
+/* structure to store Hypothetical Reference Decoder (HRD) parameters */
+typedef struct
+{
+    u32 cpbCnt;
+    u32 bitRateScale;
+    u32 cpbSizeScale;
+    u32 bitRateValue[MAX_CPB_CNT];
+    u32 cpbSizeValue[MAX_CPB_CNT];
+    u32 cbrFlag[MAX_CPB_CNT];
+    u32 initialCpbRemovalDelayLength;
+    u32 cpbRemovalDelayLength;
+    u32 dpbOutputDelayLength;
+    u32 timeOffsetLength;
+} hrdParameters_t;
+
+/* storage for VUI parameters */
+typedef struct
+{
+    u32 aspectRatioPresentFlag;
+    u32 aspectRatioIdc;
+    u32 sarWidth;
+    u32 sarHeight;
+    u32 overscanInfoPresentFlag;
+    u32 overscanAppropriateFlag;
+    u32 videoSignalTypePresentFlag;
+    u32 videoFormat;
+    u32 videoFullRangeFlag;
+    u32 colourDescriptionPresentFlag;
+    u32 colourPrimaries;
+    u32 transferCharacteristics;
+    u32 matrixCoefficients;
+    u32 chromaLocInfoPresentFlag;
+    u32 chromaSampleLocTypeTopField;
+    u32 chromaSampleLocTypeBottomField;
+    u32 timingInfoPresentFlag;
+    u32 numUnitsInTick;
+    u32 timeScale;
+    u32 fixedFrameRateFlag;
+    u32 nalHrdParametersPresentFlag;
+    hrdParameters_t nalHrdParameters;
+    u32 vclHrdParametersPresentFlag;
+    hrdParameters_t vclHrdParameters;
+    u32 lowDelayHrdFlag;
+    u32 picStructPresentFlag;
+    u32 bitstreamRestrictionFlag;
+    u32 motionVectorsOverPicBoundariesFlag;
+    u32 maxBytesPerPicDenom;
+    u32 maxBitsPerMbDenom;
+    u32 log2MaxMvLengthHorizontal;
+    u32 log2MaxMvLengthVertical;
+    u32 numReorderFrames;
+    u32 maxDecFrameBuffering;
+} vuiParameters_t;
+
+/*------------------------------------------------------------------------------
+    4. Function prototypes
+------------------------------------------------------------------------------*/
+
+u32 h264bsdDecodeVuiParameters(strmData_t *pStrmData,
+    vuiParameters_t *pVuiParameters);
+
+#endif /* #ifdef H264SWDEC_VUI_H */
+
diff --git a/media/libstagefright/colorconversion/Android.mk b/media/libstagefright/colorconversion/Android.mk
index 702a7b4..62ba40f 100644
--- a/media/libstagefright/colorconversion/Android.mk
+++ b/media/libstagefright/colorconversion/Android.mk
@@ -9,10 +9,6 @@
         $(TOP)/frameworks/base/include/media/stagefright/openmax \
         $(TOP)/hardware/msm7k
 
-ifneq ($(filter crespo crespo4g,$(TARGET_DEVICE)),)
-LOCAL_CFLAGS += -DTHIS_IS_CRESPO=1
-endif
-
 LOCAL_MODULE:= libstagefright_color_conversion
 
 include $(BUILD_STATIC_LIBRARY)
diff --git a/media/libstagefright/colorconversion/ColorConverter.cpp b/media/libstagefright/colorconversion/ColorConverter.cpp
index 4b72a53..b28d947 100644
--- a/media/libstagefright/colorconversion/ColorConverter.cpp
+++ b/media/libstagefright/colorconversion/ColorConverter.cpp
@@ -20,8 +20,6 @@
 
 namespace android {
 
-static const int OMX_QCOM_COLOR_FormatYVU420SemiPlanar = 0x7FA30C00;
-
 ColorConverter::ColorConverter(
         OMX_COLOR_FORMATTYPE from, OMX_COLOR_FORMATTYPE to)
     : mSrcFormat(from),
diff --git a/media/libstagefright/colorconversion/SoftwareRenderer.cpp b/media/libstagefright/colorconversion/SoftwareRenderer.cpp
index 1828ac8..a4e8ee4 100644
--- a/media/libstagefright/colorconversion/SoftwareRenderer.cpp
+++ b/media/libstagefright/colorconversion/SoftwareRenderer.cpp
@@ -59,7 +59,6 @@
     size_t bufWidth, bufHeight;
 
     switch (mColorFormat) {
-#ifndef THIS_IS_CRESPO
         case OMX_COLOR_FormatYUV420Planar:
         {
             halFormat = HAL_PIXEL_FORMAT_YV12;
@@ -67,7 +66,6 @@
             bufHeight = (mHeight + 1) & ~1;
             break;
         }
-#endif
 
         default:
             halFormat = HAL_PIXEL_FORMAT_RGB_565;
@@ -89,11 +87,7 @@
             native_window_set_usage(
             mNativeWindow.get(),
             GRALLOC_USAGE_SW_READ_NEVER | GRALLOC_USAGE_SW_WRITE_OFTEN
-            | GRALLOC_USAGE_HW_TEXTURE
-#ifndef THIS_IS_CRESPO
-            | GRALLOC_USAGE_EXTERNAL_DISP
-#endif
-            ));
+            | GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_EXTERNAL_DISP));
 
     // Width must be multiple of 32???
     CHECK_EQ(0, native_window_set_buffers_geometry(
diff --git a/media/libstagefright/include/AwesomePlayer.h b/media/libstagefright/include/AwesomePlayer.h
index a9e8e95..f6df380 100644
--- a/media/libstagefright/include/AwesomePlayer.h
+++ b/media/libstagefright/include/AwesomePlayer.h
@@ -93,6 +93,7 @@
 
     status_t setParameter(int key, const Parcel &request);
     status_t getParameter(int key, Parcel *reply);
+    status_t setCacheStatCollectFreq(const Parcel &request);
 
     status_t seekTo(int64_t timeUs);
 
@@ -104,6 +105,8 @@
 
     status_t setTimedTextTrackIndex(int32_t index);
 
+    status_t dump(int fd, const Vector<String16> &args) const;
+
 private:
     friend struct AwesomeEvent;
     friend struct PreviewPlayer;
@@ -141,6 +144,7 @@
 
     mutable Mutex mLock;
     Mutex mMiscStateLock;
+    mutable Mutex mStatsLock;
 
     OMXClient mClient;
     TimedEventQueue mQueue;
@@ -291,6 +295,34 @@
     void setNativeWindow_l(const sp<ANativeWindow> &native);
 
     bool isStreamingHTTP() const;
+    void sendCacheStats();
+
+    enum FlagMode {
+        SET,
+        CLEAR,
+        ASSIGN
+    };
+    void modifyFlags(unsigned value, FlagMode mode);
+
+    struct TrackStat {
+        String8 mMIME;
+        String8 mDecoderName;
+    };
+
+    // protected by mStatsLock
+    struct Stats {
+        int mFd;
+        String8 mURI;
+        int64_t mBitrate;
+        ssize_t mAudioTrackIndex;
+        ssize_t mVideoTrackIndex;
+        int64_t mNumVideoFramesDecoded;
+        int64_t mNumVideoFramesDropped;
+        int32_t mVideoWidth;
+        int32_t mVideoHeight;
+        uint32_t mFlags;
+        Vector<TrackStat> mTracks;
+    } mStats;
 
     AwesomePlayer(const AwesomePlayer &);
     AwesomePlayer &operator=(const AwesomePlayer &);
diff --git a/media/libstagefright/include/ChromiumHTTPDataSource.h b/media/libstagefright/include/ChromiumHTTPDataSource.h
index 0e2927d..d833e2e 100644
--- a/media/libstagefright/include/ChromiumHTTPDataSource.h
+++ b/media/libstagefright/include/ChromiumHTTPDataSource.h
@@ -43,8 +43,6 @@
     virtual status_t getSize(off64_t *size);
     virtual uint32_t flags();
 
-    virtual bool estimateBandwidth(int32_t *bandwidth_bps);
-
     virtual sp<DecryptHandle> DrmInitialization();
 
     virtual void getDrmInfo(sp<DecryptHandle> &handle, DrmManagerClient **client);
@@ -67,11 +65,6 @@
         DISCONNECTING
     };
 
-    struct BandwidthEntry {
-        int64_t mDelayUs;
-        size_t mNumBytes;
-    };
-
     const uint32_t mFlags;
 
     mutable Mutex mLock;
@@ -94,11 +87,6 @@
 
     String8 mContentType;
 
-    List<BandwidthEntry> mBandwidthHistory;
-    size_t mNumBandwidthHistoryItems;
-    int64_t mTotalTransferTimeUs;
-    size_t mTotalTransferBytes;
-
     sp<DecryptHandle> mDecryptHandle;
     DrmManagerClient *mDrmManagerClient;
 
@@ -121,8 +109,6 @@
     void onReadCompleted(ssize_t size);
     void onDisconnectComplete();
 
-    void addBandwidthMeasurement_l(size_t numBytes, int64_t delayUs);
-
     void clearDRMState_l();
 
     DISALLOW_EVIL_CONSTRUCTORS(ChromiumHTTPDataSource);
diff --git a/media/libstagefright/include/HTTPBase.h b/media/libstagefright/include/HTTPBase.h
index 6cec390..3a7fbb6 100644
--- a/media/libstagefright/include/HTTPBase.h
+++ b/media/libstagefright/include/HTTPBase.h
@@ -20,6 +20,8 @@
 
 #include <media/stagefright/foundation/ABase.h>
 #include <media/stagefright/DataSource.h>
+#include <media/stagefright/MediaErrors.h>
+#include <utils/threads.h>
 
 namespace android {
 
@@ -40,11 +42,41 @@
 
     // Returns true if bandwidth could successfully be estimated,
     // false otherwise.
-    virtual bool estimateBandwidth(int32_t *bandwidth_bps) = 0;
+    virtual bool estimateBandwidth(int32_t *bandwidth_bps);
+
+    virtual status_t getEstimatedBandwidthKbps(int32_t *kbps);
+
+    virtual status_t setBandwidthStatCollectFreq(int32_t freqMs);
 
     static sp<HTTPBase> Create(uint32_t flags = 0);
 
+protected:
+    void addBandwidthMeasurement(size_t numBytes, int64_t delayUs);
+
 private:
+
+    struct BandwidthEntry {
+        int64_t mDelayUs;
+        size_t mNumBytes;
+    };
+
+    Mutex mLock;
+
+    List<BandwidthEntry> mBandwidthHistory;
+    size_t mNumBandwidthHistoryItems;
+    int64_t mTotalTransferTimeUs;
+    size_t mTotalTransferBytes;
+
+    enum {
+        kMinBandwidthCollectFreqMs = 1000,   // 1 second
+        kMaxBandwidthCollectFreqMs = 60000,  // one minute
+    };
+
+    int64_t mPrevBandwidthMeasureTimeUs;
+    int32_t mPrevEstimatedBandWidthKbps;
+    int32_t mBandWidthCollectFreqMs;
+
+
     DISALLOW_EVIL_CONSTRUCTORS(HTTPBase);
 };
 
diff --git a/media/libstagefright/include/NuCachedSource2.h b/media/libstagefright/include/NuCachedSource2.h
index ed3e265c..2d6cb84 100644
--- a/media/libstagefright/include/NuCachedSource2.h
+++ b/media/libstagefright/include/NuCachedSource2.h
@@ -50,6 +50,12 @@
 
     void resumeFetchingIfNecessary();
 
+    // The following methods are supported only if the
+    // data source is HTTP-based; otherwise, ERROR_UNSUPPORTED
+    // is returned.
+    status_t getEstimatedBandwidthKbps(int32_t *kbps);
+    status_t setCacheStatCollectFreq(int32_t freqMs);
+
 protected:
     virtual ~NuCachedSource2();
 
diff --git a/media/libstagefright/include/NuHTTPDataSource.h b/media/libstagefright/include/NuHTTPDataSource.h
index 2ab1f19..c265b3a 100644
--- a/media/libstagefright/include/NuHTTPDataSource.h
+++ b/media/libstagefright/include/NuHTTPDataSource.h
@@ -43,10 +43,6 @@
     virtual status_t getSize(off64_t *size);
     virtual uint32_t flags();
 
-    // Returns true if bandwidth could successfully be estimated,
-    // false otherwise.
-    virtual bool estimateBandwidth(int32_t *bandwidth_bps);
-
     virtual sp<DecryptHandle> DrmInitialization();
     virtual void getDrmInfo(sp<DecryptHandle> &handle, DrmManagerClient **client);
     virtual String8 getUri();
@@ -63,11 +59,6 @@
         CONNECTED
     };
 
-    struct BandwidthEntry {
-        int64_t mDelayUs;
-        size_t mNumBytes;
-    };
-
     Mutex mLock;
 
     uint32_t mFlags;
@@ -93,11 +84,6 @@
     // chunk header (or -1 if no more chunks).
     ssize_t mChunkDataBytesLeft;
 
-    List<BandwidthEntry> mBandwidthHistory;
-    size_t mNumBandwidthHistoryItems;
-    int64_t mTotalTransferTimeUs;
-    size_t mTotalTransferBytes;
-
     sp<DecryptHandle> mDecryptHandle;
     DrmManagerClient *mDrmManagerClient;
 
@@ -114,7 +100,6 @@
     ssize_t internalRead(void *data, size_t size);
 
     void applyTimeoutResponse();
-    void addBandwidthMeasurement_l(size_t numBytes, int64_t delayUs);
 
     static void MakeFullHeaders(
             const KeyedVector<String8, String8> *overrides,
diff --git a/media/libstagefright/omx/OMX.cpp b/media/libstagefright/omx/OMX.cpp
index 4b1c3a7..d23aa3a 100644
--- a/media/libstagefright/omx/OMX.cpp
+++ b/media/libstagefright/omx/OMX.cpp
@@ -21,7 +21,6 @@
 #include <dlfcn.h>
 
 #include <sys/prctl.h>
-#include <sys/resource.h>
 
 #include "../include/OMX.h"
 
@@ -116,7 +115,7 @@
 }
 
 void OMX::CallbackDispatcher::threadEntry() {
-    setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_AUDIO);
+    androidSetThreadPriority(0, ANDROID_PRIORITY_AUDIO);
     prctl(PR_SET_NAME, (unsigned long)"OMXCallbackDisp", 0, 0, 0);
 
     for (;;) {
diff --git a/media/libstagefright/omx/SoftOMXPlugin.cpp b/media/libstagefright/omx/SoftOMXPlugin.cpp
index 04ca39e..02b1c8e 100644
--- a/media/libstagefright/omx/SoftOMXPlugin.cpp
+++ b/media/libstagefright/omx/SoftOMXPlugin.cpp
@@ -37,6 +37,7 @@
     { "OMX.google.aac.decoder", "aacdec", "audio_decoder.aac" },
     { "OMX.google.amrnb.decoder", "amrdec", "audio_decoder.amrnb" },
     { "OMX.google.amrwb.decoder", "amrdec", "audio_decoder.amrwb" },
+    { "OMX.google.h264.decoder", "h264dec", "video_decoder.avc" },
     { "OMX.google.avc.decoder", "avcdec", "video_decoder.avc" },
     { "OMX.google.g711.alaw.decoder", "g711dec", "audio_decoder.g711alaw" },
     { "OMX.google.g711.mlaw.decoder", "g711dec", "audio_decoder.g711mlaw" },
diff --git a/media/mtp/MtpServer.cpp b/media/mtp/MtpServer.cpp
index 4a8fd3e..9ec73c4 100644
--- a/media/mtp/MtpServer.cpp
+++ b/media/mtp/MtpServer.cpp
@@ -533,12 +533,10 @@
     MtpStorageID storageID = mRequest.getParameter(1);      // 0xFFFFFFFF for all storage
     MtpObjectFormat format = mRequest.getParameter(2);      // 0 for all formats
     MtpObjectHandle parent = mRequest.getParameter(3);      // 0xFFFFFFFF for objects with no parent
-                                                            // 0x00000000 for all objects?
+                                                            // 0x00000000 for all objects
 
     if (!hasStorage(storageID))
         return MTP_RESPONSE_INVALID_STORAGE_ID;
-    if (parent == 0xFFFFFFFF)
-        parent = 0;
 
     MtpObjectHandleList* handles = mDatabase->getObjectList(storageID, format, parent);
     mData.putAUInt32(handles);
@@ -552,11 +550,9 @@
     MtpStorageID storageID = mRequest.getParameter(1);      // 0xFFFFFFFF for all storage
     MtpObjectFormat format = mRequest.getParameter(2);      // 0 for all formats
     MtpObjectHandle parent = mRequest.getParameter(3);      // 0xFFFFFFFF for objects with no parent
-                                                            // 0x00000000 for all objects?
+                                                            // 0x00000000 for all objects
     if (!hasStorage(storageID))
         return MTP_RESPONSE_INVALID_STORAGE_ID;
-    if (parent == 0xFFFFFFFF)
-        parent = 0;
 
     int count = mDatabase->getNumObjects(storageID, format, parent);
     if (count >= 0) {
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkTest.java
index 79fd2cb..e7f98de 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkTest.java
@@ -123,63 +123,6 @@
       intent.setDataAndType(path, mimetype);
       startActivity(intent);
     }
-    
-    @Override public boolean onKeyDown(int keyCode, KeyEvent event) {
-      switch (keyCode) {
-          case KeyEvent.KEYCODE_0:
-            MediaPlayer mp = new MediaPlayer();
-            try{
-              mp.setDataSource(MediaNames.VIDEO_RTSP3GP);
-              Log.v("emily","awb  " + testfilepath);
-              mp.setDisplay(mSurfaceView.getHolder());
-              mp.prepare();
-              mp.start();
-            }catch (Exception e){}
-              break;
-          
-          //start the music player intent with the test URL from PV    
-          case KeyEvent.KEYCODE_1:
-            startPlayback(MediaNames.STREAM_MP3_1);
-            break;
-          
-          case KeyEvent.KEYCODE_2:
-            startPlayback(MediaNames.STREAM_MP3_2);
-            break;
-          
-          case KeyEvent.KEYCODE_3:
-            startPlayback(MediaNames.STREAM_MP3_3);
-            break;
-          
-          case KeyEvent.KEYCODE_4:
-            startPlayback(MediaNames.STREAM_MP3_4);
-            break;
-          
-          case KeyEvent.KEYCODE_5:
-            startPlayback(MediaNames.STREAM_MP3_5);
-            break;
-          
-          case KeyEvent.KEYCODE_6:
-            startPlayback(MediaNames.STREAM_MP3_6);
-            break;
-          
-          case KeyEvent.KEYCODE_7:
-            startPlayback(MediaNames.STREAM_MP3_7);
-            break;
-          
-          case KeyEvent.KEYCODE_8:
-            startPlayback(MediaNames.STREAM_MP3_8);
-            break;
-          
-          case KeyEvent.KEYCODE_9:
-            startPlayback(MediaNames.STREAM_MP3_9);
-            break;
-          
-              
-              
-      }
-      return super.onKeyDown(keyCode, event);
-     
-  }  
 
   public static boolean checkStreamingServer() throws Exception {
       InetAddress address = InetAddress.getByAddress(MediaNames.STREAM_SERVER);
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaNames.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaNames.java
index ca6e999..f3a91c5 100755
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaNames.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaNames.java
@@ -1,510 +1,160 @@
 /*
  * 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
+ * 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
+ * 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.
+ * 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.mediaframeworktest;
 
 /**
- * 
- * This class has the names of the all the activity name and variables 
- * in the instrumentation test.
+ *
+ * This class has the names of the all the activity name and variables in the
+ * instrumentation test.
  *
  */
 public class MediaNames {
-    //A directory to hold all kinds of media files
+    // A directory to hold all kinds of media files
     public static final String MEDIA_SAMPLE_POOL = "/sdcard/media_api/samples/";
-    //Audio files
-    public static final String MP3CBR = "/sdcard/media_api/music/MP3_256kbps_2ch.mp3";
-    public static final String MP3VBR = "/sdcard/media_api/music/MP3_256kbps_2ch_VBR.mp3";
+    // Audio files
+    public static final String MP3CBR = "/sdcard/media_api/music/MP3_48KHz_128kbps_s_1_17_CBR.mp3";
+    public static final String MP3VBR = "/sdcard/media_api/music/MP3_48KHz_128kbps_s_1_17_VBR.mp3";
+    public static final String MP3ABR = "/sdcard/media_api/music/MP3_48KHz_128kbps_s_1_17_ABR.mp3";
     public static final String SHORTMP3 = "/sdcard/media_api/music/SHORTMP3.mp3";
     public static final String MIDI = "/sdcard/media_api/music/ants.mid";
-    public static final String WMA9 = "/sdcard/media_api/music/WMA9.wma";
-    public static final String WMA10 = "/sdcard/media_api/music/WMA10.wma";
     public static final String WAV = "/sdcard/media_api/music/rings_2ch.wav";
     public static final String AMR = "/sdcard/media_api/music/test_amr_ietf.amr";
-    public static final String OGG = "/sdcard/media_api/music/Revelation.ogg";
     public static final String SINE_200_1000 = "/sdcard/media_api/music/sine_200+1000Hz_44K_mo.wav";
-  
+    // public static final String OGG =
+    // "/sdcard/media_api/music/Revelation.ogg";
+
     public static final int MP3CBR_LENGTH = 71000;
     public static final int MP3VBR_LENGTH = 71000;
     public static final int SHORTMP3_LENGTH = 286;
     public static final int MIDI_LENGTH = 17000;
-    public static final int WMA9_LENGTH = 126559;
-    public static final int WMA10_LENGTH = 126559;
     public static final int AMR_LENGTH = 37000;
-    public static final int OGG_LENGTH = 4000;
     public static final int SEEK_TIME = 10000;
-  
+
     public static final long PAUSE_WAIT_TIME = 3000;
     public static final long WAIT_TIME = 2000;
     public static final long WAIT_SNAPSHOT_TIME = 5000;
-  
-    //Streaming Video
-    public static final String VIDEO_HTTP3GP = "http://pvs.pv.com/jj/lipsync0.3gp";  
-    public static final String VIDEO_RTSP3GP = "rtsp://63.241.31.203/public/jj/md.3gp";
-    public static final String VIDEO_RTSP3GP2 = "rtsp://pvs.pv.com/public/live_dvd1.3gp";
-    public static final String VIDEO_RTSP3GP3 = 
-      "rtsp://ehug.rtsp-youtube.l.google.com/" +
-      "Ci4LENy73wIaJQmeRVCJq4HuQBMYDSANFEIJbXYtZ29vZ2xlSARSB2RldGFpbHMM/0/0/0/video.3gp";
-    //public static final String VIDEO_RTSP3GP = "rtsp://193.159.241.21/sp/alizee05.3gp";
-  
-    //local video
+
+    // local video
     public static final String VIDEO_MP4 = "/sdcard/media_api/video/MPEG4_320_AAC_64.mp4";
-    public static final String VIDEO_LONG_3GP = "/sdcard/media_api/video/radiohead.3gp";
     public static final String VIDEO_SHORT_3GP = "/sdcard/media_api/video/short.3gp";
     public static final String VIDEO_LARGE_SIZE_3GP = "/sdcard/media_api/video/border_large.3gp";
     public static final String VIDEO_H263_AAC = "/sdcard/media_api/video/H263_56_AAC_24.3gp";
     public static final String VIDEO_H263_AMR = "/sdcard/media_api/video/H263_56_AMRNB_6.3gp";
     public static final String VIDEO_H264_AAC = "/sdcard/media_api/video/H264_320_AAC_64.3gp";
     public static final String VIDEO_H264_AMR = "/sdcard/media_api/video/H264_320_AMRNB_6.3gp";
-    public static final String VIDEO_WMV = "/sdcard/media_api/video/bugs.wmv";
     public static final String VIDEO_HIGHRES_H263 = "/sdcard/media_api/video/H263_500_AMRNB_12.3gp";
     public static final String VIDEO_HIGHRES_MP4 = "/sdcard/media_api/video/H264_500_AAC_128.3gp";
-    
-    //ringtone
-    public static final String ringtone = "/sdcard/media_api/ringtones/F1_NewVoicemail.mp3";
+    public static final String VIDEO_WEBM = "/sdcard/media_api/video/big-buck-bunny_trailer.webm";
 
-    //streaming mp3
-    public static final String STREAM_MP3_1 = 
-      "http://wms.pv.com:7070/MediaDownloadContent/mp3/chadthi_jawani_128kbps.mp3";
-    public static final String STREAM_MP3_2 = 
-      "http://wms.pv.com:7070/MediaDownloadContent/mp3/dualStereo.mp3";
-    public static final String STREAM_MP3_3 = 
-      "http://wms.pv.com:7070/mediadownloadcontent/UserUploads/15%20Keep%20Holding%20On.mp3";
-    public static final String STREAM_MP3_4 = 
-      "http://wms.pv.com:7070/mediadownloadcontent/UserUploads/1%20-%20Apologize.mp3";
-    public static final String STREAM_MP3_5 = 
-      "http://wms.pv.com:7070/mediadownloadcontent/UserUploads/" +
-      "03%20You're%20Gonna%20Miss%20This.mp3";
-    public static final String STREAM_MP3_6 = 
-      "http://wms.pv.com:7070/mediadownloadcontent/UserUploads" +
-      "/02%20Looney%20Tunes%20%C3%82%C2%B7%20Light%20Cavalry%20Overture%20(LP%20Version).mp3";
-    public static final String STREAM_MP3_7 = 
-      "http://wms.pv.com:7070/mediadownloadcontent/UserUploads" +
-      "/01%20Love%20Song%20(Album%20Version).mp3";
-    public static final String STREAM_MP3_8 = 
-      "http://wms.pv.com:7070/MediaDownloadContent/UserUploads/1%20-%20Apologize.mp3";
-    public static final String STREAM_MP3_9 = 
-      "http://wms.pv.com:7070/MediaDownloadContent/UserUploads" +
-      "/1%20-%20Smile%20(Explicit%20Version).mp3";
-    public static final String STREAM_MP3_10 = 
-      "http://wms.pv.com:7070/MediaDownloadContent/UserUploads/beefcake.mp3";
-
-    //Sonivox
-    public static String MIDIFILES[] = { 
-        "/sdcard/media_api/music/Leadsol.mxmf",
-        "/sdcard/media_api/music/abba.imy", "/sdcard/media_api/music/ants.mid",
-        "/sdcard/media_api/music/greensleeves.rtttl", "/sdcard/media_api/music/test.ota"};
-  
-    //Performance measurement
-    public static String[] WAVFILES = { 
-        "/sdcard/media_api/music_perf/WAV/M1F1-AlawWE-AFsp.wav",
-        "/sdcard/media_api/music_perf/WAV/M1F1-float64-AFsp.wav",
-        "/sdcard/media_api/music_perf/WAV/song.wav",
-        "/sdcard/media_api/music_perf/WAV/WAVEtest.wav",
-        "/sdcard/media_api/music_perf/WAV/WAVEtest_out.wav",
-        "/sdcard/media_api/music_perf/WAV/test_out.wav"};
-        
-    public static String[] AMRNBFILES = { 
-        "/sdcard/media_api/music_perf/AMR/AI_AMR-NB_5.9kbps_6.24kbps_8khz_mono_NMC.amr",
-        "/sdcard/media_api/music_perf/AMR/AI_AMR-NB_5.15kbps_5.46kbps_8khz_mono_NMC.amr",
-        "/sdcard/media_api/music_perf/AMR/AI_AMR-NB_7.4kbps_7.80kbps_8khz_mono_NMC.amr",
-        "/sdcard/media_api/music_perf/AMR/AI_AMR-NB_7.95kbps_9.6kbps_8khz_mono_NMC.amr",
-        "/sdcard/media_api/music_perf/AMR/AI_AMR-NB_10.2kbps_10.48kbps_8khz_mono_NMC.amr"};
-  
-    public static String[] AMRWBFILES = { 
-        "/sdcard/media_api/music_perf/AMRWB/NIN_AMR-WB_15.85kbps_16kbps.amr",
-        "/sdcard/media_api/music_perf/AMRWB/NIN_AMR-WB_18.25kbps_18kbps.amr",
-        "/sdcard/media_api/music_perf/AMRWB/NIN_AMR-WB_19.85kbps_20kbps.amr",
-        "/sdcard/media_api/music_perf/AMRWB/NIN_AMR-WB_23.05kbps_23kbps.amr",
-        "/sdcard/media_api/music_perf/AMRWB/NIN_AMR-WB_23.85kbps_24kbps.amr",
-        "/sdcard/media_api/music_perf/AMRWB/PD_AMR-WB_19.85kbps_20kbps.amr",
-        "/sdcard/media_api/music_perf/AMRWB/PD_AMR-WB_23.05kbps_23kbps.amr",
-        "/sdcard/media_api/music_perf/AMRWB/PD_AMR-WB_23.85kbps_24kbps.amr",
-        "/sdcard/media_api/music_perf/AMRWB/WC_AMR-WB_23.05kbps_23kbps.amr",
-        "/sdcard/media_api/music_perf/AMRWB/WC_AMR-WB_23.85kbps_24kbps.amr", };
- 
-    public static String[] MP3FILES = { 
-        "/sdcard/media_api/music_perf/MP3/NIN_56kbps_32khz_stereo_VBR_MCA.MP3",
-        "/sdcard/media_api/music_perf/MP3/NIN_80kbps_32khz_stereo_VBR_MCA.mp3",
-        "/sdcard/media_api/music_perf/MP3/NIN_80kbps_44.1khz_stereo_VBR_MCA.mp3", 
-        "/sdcard/media_api/music_perf/MP3/NIN_80kbps_48khz_stereo_VBR_MCA.mp3",
-        "/sdcard/media_api/music_perf/MP3/NIN_112kbps_32khz_stereo_VBR_MCA.mp3",
-        "/sdcard/media_api/music_perf/MP3/NIN_112kbps_44.1khz_stereo_VBR_MCA.mp3",
-        "/sdcard/media_api/music_perf/MP3/NIN_112kbps_48khz_stereo_VBR_MCA.mp3",
-        "/sdcard/media_api/music_perf/MP3/NIN_192kbps_32khz_mono_CBR_MCA.mp3",
-        "/sdcard/media_api/music_perf/MP3/NIN_192kbps_44.1khz_mono_CBR_MCA.mp3",
-        "/sdcard/media_api/music_perf/MP3/NIN_192kbps_48khz_mono_CBR_MCA.mp3",
-        "/sdcard/media_api/music_perf/MP3/NIN_256kbps_44.1khz_mono_CBR_MCA.mp3",
-        "/sdcard/media_api/music_perf/MP3/NIN_256kbps_48khz_mono_CBR_MCA.mp3",
-        "/sdcard/media_api/music_perf/MP3/PD_112kbps_32khz_stereo_VBR_MCA.mp3",
-        "/sdcard/media_api/music_perf/MP3/PD_112kbps_44.1khz_stereo_VBR_MCA.mp3",
-        "/sdcard/media_api/music_perf/MP3/PD_112kbps_48khz_stereo_VBR_MCA.mp3",
-        "/sdcard/media_api/music_perf/MP3/PD_192kbps_32khz_mono_CBR_DPA.mp3",
-        "/sdcard/media_api/music_perf/MP3/PD_256kbps_44.1khz_mono_CBR_DPA.mp3",
-        "/sdcard/media_api/music_perf/MP3/PD_256kbps_48khz_mono_CBR_MCA.mp3",
-        "/sdcard/media_api/music_perf/MP3/WC_256kbps_44.1khz_mono_CBR_DPA.mp3",
-        "/sdcard/media_api/music_perf/MP3/WC_256kbps_48khz_mono_CBR_DPA.mp3",
-        "/sdcard/media_api/music_perf/regular_album_photo/Apologize.mp3",
-        "/sdcard/media_api/music_perf/regular_album_photo/Because_Of_You.mp3",
-        "/sdcard/media_api/music_perf/regular_album_photo/Complicated.mp3",
-        "/sdcard/media_api/music_perf/regular_album_photo/Glamorous.mp3",
-        "/sdcard/media_api/music_perf/regular_album_photo/Im_With_You.mp3",
-        "/sdcard/media_api/music_perf/regular_album_photo/Smile.mp3",
-        "/sdcard/media_api/music_perf/regular_album_photo/Suddenly_I_See.mp3",
-        "/sdcard/media_api/music_perf/regular_album_photo/When You Say Nothing At All.mp3",
-        "/sdcard/media_api/music_perf/regular_album_photo/my_happy_ending.mp3"};
-  
-    public static String[] AACFILES = { 
-        "/sdcard/media_api/music_perf/AAC/AI_AAC_24kbps_12khz_Mono_1pCBR_SSE.mp4",
-        "/sdcard/media_api/music_perf/AAC/AI_AAC_56kbps_22.05khz_Stereo_1pCBR_SSE.mp4",
-        "/sdcard/media_api/music_perf/AAC/AI_AAC_56kbps_32khz_Stereo_CBR_SSE.mp4",
-        "/sdcard/media_api/music_perf/AAC/AI_AAC_56kbps_44.1khz_Stereo_1pCBR_SSE.mp4",
-        "/sdcard/media_api/music_perf/AAC/AI_AAC_80kbps_32khz_Stereo_1pCBR_SSE.mp4",
-        "/sdcard/media_api/music_perf/AAC/AI_AAC_80kbps_32khz_Stereo_CBR_SSE.mp4",
-        "/sdcard/media_api/music_perf/AAC/NIN_AAC_56kbps_22.05khz_Stereo_1pCBR_SSE.mp4",
-        "/sdcard/media_api/music_perf/AAC/NIN_AAC_56kbps_32khz_Stereo_CBR_SSE.mp4",
-        "/sdcard/media_api/music_perf/AAC/NIN_AAC_56kbps_44.1khz_Stereo_1pCBR_SSE.mp4",
-        "/sdcard/media_api/music_perf/AAC/NIN_AAC_80kbps_32khz_Stereo_1pCBR_SSE.mp4",
-        "/sdcard/media_api/music_perf/AAC/NIN_AAC_80kbps_32khz_Stereo_CBR_SSE.mp4",
-        "/sdcard/media_api/music_perf/AAC/PD_AAC_56kbps_22.05khz_Stereo_1pCBR_SSE.mp4",
-        "/sdcard/media_api/music_perf/AAC/PD_AAC_56kbps_32khz_Stereo_CBR_SSE.mp4",
-        "/sdcard/media_api/music_perf/AAC/PD_AAC_56kbps_44.1khz_Stereo_1pCBR_SSE.mp4",
-        "/sdcard/media_api/music_perf/AAC/PD_AAC_80kbps_32khz_Stereo_1pCBR_SSE.mp4",
-        "/sdcard/media_api/music_perf/AAC/PD_AAC_80kbps_32khz_Stereo_CBR_SSE.mp4",
-        "/sdcard/media_api/music_perf/AAC/PV_AAC_56kbps_22.05khz_Stereo_1pCBR_SSE.mp4",
-        "/sdcard/media_api/music_perf/AAC/PV_AAC_56kbps_32khz_Stereo_CBR_SSE.mp4",
-        "/sdcard/media_api/music_perf/AAC/PV_AAC_56kbps_44.1khz_Stereo_1pCBR_SSE.mp4",
-        "/sdcard/media_api/music_perf/AAC/PV_AAC_80kbps_32khz_Stereo_1pCBR_SSE.mp4",
-        "/sdcard/media_api/music_perf/AAC/PV_AAC_80kbps_32khz_Stereo_CBR_SSE.mp4",
-        "/sdcard/media_api/music_perf/AAC/WC_AAC_56kbps_22.05khz_Stereo_1pCBR_SSE.mp4",
-        "/sdcard/media_api/music_perf/AAC/WC_AAC_56kbps_32khz_Stereo_CBR_SSE.mp4",
-        "/sdcard/media_api/music_perf/AAC/WC_AAC_56kbps_44.1khz_Stereo_1pCBR_SSE.mp4",
-        "/sdcard/media_api/music_perf/AAC/WC_AAC_80kbps_32khz_Stereo_1pCBR_SSE.mp4",
-        "/sdcard/media_api/music_perf/AAC/WC_AAC_80kbps_32khz_Stereo_CBR_SSE.mp4",      
-    };
-    
-    public static String[] VIDEOFILES = { "/sdcard/media_api/video_perf/AI_CTO_Mpeg4_32kbps_10fps_SQCIF_128x96+AAC_8kbps_8khz_mono_QTE.mp4",
-      "/sdcard/media_api/video_perf/AI_CTO_Mpeg4_32kbps_12fps_SQCIF_128x96+AAC_8kbps_8khz_mono_QTE.mp4",
-      "/sdcard/media_api/video_perf/AI_CTO_Mpeg4_32kbps_15fps_SQCIF_128x96+AAC_8kbps_8khz_mono_QTE.mp4",
-      "/sdcard/media_api/video_perf/AI_CTO_Mpeg4_32kbps_5fps_SQCIF_128x96+AAC_8kbps_8khz_mono_QTE.mp4",
-      "/sdcard/media_api/video_perf/AI_CTO_Mpeg4_32kbps_5fps_SQCIF_128x96+AAC_8kbps_8khz_mono_SSE.mp4",
-      "/sdcard/media_api/video_perf/AI_CTO_Mpeg4_32kbps_7.5fps_SQCIF_128x96+AAC_8kbps_8khz_mono_QTE.mp4",
-      "/sdcard/media_api/video_perf/AI_WMV_1024kbps_20fps_QCIF_176x144_noaudio_SSE.wmv",
-      "/sdcard/media_api/video_perf/AI_WMV_1024kbps_25fps_QCIF_176x144_noaudio_SSE.wmv",
-      "/sdcard/media_api/video_perf/Chicken.wmv",
-      "/sdcard/media_api/video_perf/MP_qcif_15fps_100kbps_48kHz_192kbps_30secs.wmv",
-      "/sdcard/media_api/video_perf/NIN_CTO_H264_123kbps_5fps_QCIF_176x144+AMR_12.2kbps_8khz_mono_QTE.3gp",
-      "/sdcard/media_api/video_perf/NIN_CTO_H264_96kbps_10.2fps_QCIF_176x144+AMR_12.2kbps_8khz_mono_QTE.3gp",
-      "/sdcard/media_api/video_perf/NIN_CTO_H264_96kbps_12fps_QCIF_176x144+AMR_12.2kbps_8khz_mono_QTE.3gp",
-      "/sdcard/media_api/video_perf/NIN_CTO_H264_96kbps_15fps_QCIF_176x144+AMR_12.2kbps_8khz_mono_QTE.3gp",
-      "/sdcard/media_api/video_perf/NIN_CTO_Mpeg4_123kbps_15fps_QCIF_176x144+AAC_32kbps_22khz_mono_SSE.3gp",
-      "/sdcard/media_api/video_perf/NIN_CTO_Mpeg4_123kbps_7.5fps_QCIF_176x144+AAC_32kbps_22khz_stereo_SSE.3gp",
-      "/sdcard/media_api/video_perf/NIN_CTO_Mpeg4_128kbps_10fps_QCIF_176x144+AAC+_32kbps_48khz_stereo_SSE.3gp",
-      "/sdcard/media_api/video_perf/NIN_CTO_Mpeg4_128kbps_12fps_QCIF_176x144+AAC+_32kbps_48khz_stereo_SSE.3gp",
-      "/sdcard/media_api/video_perf/NIN_CTO_Mpeg4_128kbps_15fps_QCIF_176x144+AAC+_32kbps_48khz_stereo_SSE.3gp",
-      "/sdcard/media_api/video_perf/NIN_CTO_Mpeg4_128kbps_5fps_QCIF_176x144+AAC+_32kbps_48khz_stereo_SSE.3gp",
-      "/sdcard/media_api/video_perf/NIN_CTO_Mpeg4_128kbps_7.5fps_QCIF_176x144+AAC+_32kbps_48khz_stereo_SSE.3gp",
-      "/sdcard/media_api/video_perf/NIN_H263_128kbps_10fps_QCIF_174x144_noaudio_SSE.mp4",
-      "/sdcard/media_api/video_perf/NIN_H263_128kbps_15fps_QCIF_174x144_noaudio_SSE.mp4",
-      "/sdcard/media_api/video_perf/NIN_H263_48kbps_10fps_QCIF_174x144_noaudio_SSE.3gp",
-      "/sdcard/media_api/video_perf/NIN_H263_48kbps_12fps_QCIF_174x144_noaudio_SSE.3gp",
-      "/sdcard/media_api/video_perf/NIN_H264_123kbps_15fps_QCIF_176x144+AAC_32kbps_22khz_stereo_SSE.3gp",
-      "/sdcard/media_api/video_perf/NIN_H264_123kbps_7.5fps_QCIF_176x144+AAC_32kbps_22khz_stereo_SSE.3gp",
-      "/sdcard/media_api/video_perf/PV_H264_2000kbps_20fps_CIF_352x288+AAC_96kbps_48khz_stereo_SSE.mp4",
-      "/sdcard/media_api/video_perf/PV_H264_2000kbps_25fps_CIF_352x288+AAC_96kbps_48khz_stereo_SSE.mp4",
-      "/sdcard/media_api/video_perf/PV_H264_2000kbps_30fps_CIF_352x288+AAC_128kbps_48khz_stereo_SSE.mp4",
-      "/sdcard/media_api/video_perf/Stevie-1.wmv",
-      "/sdcard/media_api/video_perf/WC_H264_1600kbps_20fps_QCIF_176x144+AAC_96kbps_48khz_mono_SSE.mp4",
-      "/sdcard/media_api/video_perf/WC_H264_1600kbps_25fps_QCIF_176x144+AAC_96kbps_48khz_mono_SSE.mp4",
-      "/sdcard/media_api/video_perf/WC_H264_1600kbps_30fps_QCIF_176x144+AAC_96kbps_48khz_mono_SSE.mp4",
-      "/sdcard/media_api/video_perf/bugs.wmv",
-      "/sdcard/media_api/video_perf/niceday.wmv",
-      "/sdcard/media_api/video_perf/eaglesatopnflpe.wmv",
-     
-    };
-    
-    //wma - only support up to wma 9
-    public static String[] WMASUPPORTED = {
-      "/sdcard/media_api/music_perf/WMASUPPORTED/AI_WMA9.2_32kbps_44.1khz_mono_CBR_DPA.wma",
-      "/sdcard/media_api/music_perf/WMASUPPORTED/AI_WMA9.2_48kbps_44.1khz_mono_CBR_DPA.wma",
-      "/sdcard/media_api/music_perf/WMASUPPORTED/NIN_WMA9.2_32kbps_44.1khz_mono_CBR_DPA.wma",
-      "/sdcard/media_api/music_perf/WMASUPPORTED/NIN_WMA9.2_48kbps_44.1khz_mono_CBR_DPA.wma",
-      "/sdcard/media_api/music_perf/WMASUPPORTED/PD_WMA9.2_32kbps_44.1khz_mono_CBR_DPA.wma",
-      "/sdcard/media_api/music_perf/WMASUPPORTED/PD_WMA9.2_48kbps_44.1khz_mono_CBR_DPA.wma",
-      "/sdcard/media_api/music_perf/WMASUPPORTED/PV_WMA9.2_32kbps_44.1khz_mono_CBR_DPA.wma",
-      "/sdcard/media_api/music_perf/WMASUPPORTED/PV_WMA9.2_48kbps_44.1khz_mono_CBR_DPA.wma",
-      "/sdcard/media_api/music_perf/WMASUPPORTED/WC_WMA9.2_32kbps_44.1khz_mono_CBR_DPA.wma",
-      "/sdcard/media_api/music_perf/WMASUPPORTED/WC_WMA9.2_48kbps_44.1khz_mono_CBR_DPA.wma"
-      
-    };
-    
-    public static String[] WMAUNSUPPORTED = { 
-      "/sdcard/media_api/music_perf/WMAUNSUPPORTED/AI_WMA10_127kbps_48khz_stereo_CBR_DPA.wma",
-      "/sdcard/media_api/music_perf/WMAUNSUPPORTED/AI_WMA10_128kbps_44.1khz_stereo_2pVBR_DPA.wma",
-      "/sdcard/media_api/music_perf/WMAUNSUPPORTED/AI_WMA10_128kbps_48khz_stereo_2pVBR_DPA.wma",
-      "/sdcard/media_api/music_perf/WMAUNSUPPORTED/AI_WMA10_128kbps_88khz_stereo_CBR_DPA.wma",
-      "/sdcard/media_api/music_perf/WMAUNSUPPORTED/AI_WMA10_128kbps_96khz_stereo_CBR_DPA.wma",
-      "/sdcard/media_api/music_perf/WMAUNSUPPORTED/AI_WMA10_192kbps_44.1khz_stereo_2pVBR_DPA.wma",
-      "/sdcard/media_api/music_perf/WMAUNSUPPORTED/AI_WMA10_192kbps_88khz_stereo_CBR_DPA.wma",
-      "/sdcard/media_api/music_perf/WMAUNSUPPORTED/AI_WMA10_192kbps_96khz_stereo_CBR_DPA.wma",
-      "/sdcard/media_api/music_perf/WMAUNSUPPORTED/AI_WMA10_256kbps_44khz_stereo_CBR_DPA.wma",
-      "/sdcard/media_api/music_perf/WMAUNSUPPORTED/AI_WMA10_256kbps_48khz_stereo_CBR_DPA.wma",
-      "/sdcard/media_api/music_perf/WMAUNSUPPORTED/AI_WMA10_256kbps_88khz_stereo_CBR_DPA.wma",
-      "/sdcard/media_api/music_perf/WMAUNSUPPORTED/AI_WMA10_256kbps_96khz_stereo_CBR_DPA.wma",
-      "/sdcard/media_api/music_perf/WMAUNSUPPORTED/AI_WMA10_384kbps_44khz_stereo_CBR_DPA.wma",
-      "/sdcard/media_api/music_perf/WMAUNSUPPORTED/AI_WMA10_384kbps_48khz_stereo_CBR_DPA.wma",
-      "/sdcard/media_api/music_perf/WMAUNSUPPORTED/AI_WMA10_384kbps_88khz_stereo_CBR_DPA.wma"
-    };
-    
-    //Media Recorder
+    // Media Recorder
     public static final String RECORDER_OUTPUT = "/sdcard/media_api/recorderOutput.amr";
-    
-    //video thumbnail
+
+    // video thumbnail
     public static final String THUMBNAIL_OUTPUT = "/sdcard/media_api/videoThumbnail.png";
     public static final String GOLDEN_THUMBNAIL_OUTPUT = "/sdcard/media_api/goldenThumbnail.png";
-    public static final String GOLDEN_THUMBNAIL_OUTPUT_2 = "/sdcard/media_api/goldenThumbnail2.png";
-    
-    //Metadata Utility
-    public static final String[] THUMBNAIL_CAPTURE_TEST_FILES = {
-      "/sdcard/media_api/metadata/test.mp4",
-      "/sdcard/media_api/metadata/test1.3gp",
-      "/sdcard/media_api/metadata/test2.3gp",
-      "/sdcard/media_api/metadata/test3.3gp",
-      "/sdcard/media_api/metadata/test4.3gp",
-      "/sdcard/media_api/metadata/test5.3gp",
-      "/sdcard/media_api/metadata/test6.3gp",
-      "/sdcard/media_api/metadata/test7.3gp",
-      "/sdcard/media_api/metadata/test8.3gp",
-      "/sdcard/media_api/metadata/test9.3gp",
-      "/sdcard/media_api/metadata/test10.3gp",
-      "/sdcard/media_api/metadata/test11.3gp",
-      "/sdcard/media_api/metadata/test12.3gp",
-      "/sdcard/media_api/metadata/test13.3gp",
-      "/sdcard/media_api/metadata/test14.3gp",
-      "/sdcard/media_api/metadata/test15.3gp",
-      "/sdcard/media_api/metadata/test16.3gp",
-      "/sdcard/media_api/metadata/test17.3gp",
-      "/sdcard/media_api/metadata/test18.3gp",
-      "/sdcard/media_api/metadata/test19.3gp",
-      "/sdcard/media_api/metadata/test20.3gp",
-      "/sdcard/media_api/metadata/test21.3gp",
-      "/sdcard/media_api/metadata/test22.3gp",
-      "/sdcard/media_api/metadata/test23.3gp",
-      "/sdcard/media_api/metadata/test24.3gp",
-      "/sdcard/media_api/metadata/test25.3gp",
-      "/sdcard/media_api/metadata/test26.3gp",
-      "/sdcard/media_api/metadata/test27.3gp",
-      "/sdcard/media_api/metadata/test28.3gp",
-      "/sdcard/media_api/metadata/test29.3gp",
-      "/sdcard/media_api/metadata/test30.3gp",
-      "/sdcard/media_api/metadata/test31.3gp",
-      "/sdcard/media_api/metadata/test32.3gp",
-      "/sdcard/media_api/metadata/test33.3gp",
-      "/sdcard/media_api/metadata/test35.mp4",
-      "/sdcard/media_api/metadata/test36.m4v",
-      "/sdcard/media_api/metadata/test34.wmv",
-      "/sdcard/media_api/metadata/test_metadata.mp4",
-  };
-  
-  public static final String[] METADATA_RETRIEVAL_TEST_FILES = {
-      // Raw AAC is not supported
-      // "/sdcard/media_api/test_raw.aac",
-      // "/sdcard/media_api/test_adts.aac",
-      // "/sdcard/media_api/test_adif.aac",
-      "/sdcard/media_api/metadata/test_metadata.mp4",
-      "/sdcard/media_api/metadata/WMA10.wma",
-      "/sdcard/media_api/metadata/Leadsol_out.wav",
-      "/sdcard/media_api/metadata/test_aac.mp4",
-      "/sdcard/media_api/metadata/test_amr.mp4",
-      "/sdcard/media_api/metadata/test_avc_amr.mp4",
-      "/sdcard/media_api/metadata/test_metadata.mp4",
-      "/sdcard/media_api/metadata/test_vbr.mp3",
-      "/sdcard/media_api/metadata/test_cbr.mp3",
-      "/sdcard/media_api/metadata/metadata_test1.mp3",
-      "/sdcard/media_api/metadata/test33.3gp",
-      "/sdcard/media_api/metadata/test35.mp4",
-      "/sdcard/media_api/metadata/test36.m4v",
-      "/sdcard/media_api/metadata/test_m4v_amr.mp4",
-      "/sdcard/media_api/metadata/test_h263_amr.mp4",
-      "/sdcard/media_api/metadata/test34.wmv",
-  };
-  
-  public static final String[] ALBUMART_TEST_FILES = {
-      "/sdcard/media_api/album_photo/test_22_16_mp3.mp3",
-      "/sdcard/media_api/album_photo/PD_256kbps_48khz_mono_CBR_MCA.mp3",
-      "/sdcard/media_api/album_photo/PD_256kbps_44.1khz_mono_CBR_DPA.mp3",
-      "/sdcard/media_api/album_photo/PD_192kbps_32khz_mono_CBR_DPA.mp3",
-      "/sdcard/media_api/album_photo/NIN_256kbps_48khz_mono_CBR_MCA.mp3",
-      "/sdcard/media_api/album_photo/NIN_256kbps_44.1khz_mono_CBR_MCA.mp3",
-      "/sdcard/media_api/album_photo/NIN_112kbps(96kbps)_48khz_stereo_VBR_MCA.mp3",
-      "/sdcard/media_api/album_photo/NIN_112kbps(96kbps)_44.1khz_stereo_VBR_MCA.mp3",
-      "/sdcard/media_api/album_photo/lightGreen1.mp3",
-      "/sdcard/media_api/album_photo/babyBlue2 1.mp3",
-      "/sdcard/media_api/album_photo/2-01 01 NIN_56kbps(64kbps)_32khz_stereo_VBR_MCA.mp3",
-      "/sdcard/media_api/album_photo/02_NIN_112kbps(80kbps)_32khz_stereo_VBR_MCA.mp3",
-      "/sdcard/media_api/album_photo/No_Woman_No_Cry_128K.wma",
-      "/sdcard/media_api/album_photo/Beethoven_2.wma",
-  };
 
-  //TEST_PATH_1: is a video and contains metadata for key "num-tracks"
-  // TEST_PATH_2: any valid media file.
-  // TEST_PATH_3: invalid media file
-  public static final String TEST_PATH_1 = "/sdcard/media_api/metadata/test.mp4";
-  public static final String TEST_PATH_3 = "/sdcard/media_api/data.txt";
-  public static final String TEST_PATH_4 = "somenonexistingpathname";
-  public static final String TEST_PATH_5 = "mem://012345";
-  
-  //Meta data expected result
-  //The expected tag result in the following order
-  //cd_track_number, album, artist, author, composer, date, genre
-  //title, years, duration
-  public static final String META_DATA_MP3 [][] = {
-      {"/sdcard/media_api/metaDataTestMedias/MP3/ID3V1_ID3V2.mp3", "1/10", "ID3V2.3 Album", "ID3V2.3 Artist",
-          "ID3V2.3 Lyricist", "ID3V2.3 Composer", null, "Blues",
-          "ID3V2.3 Title", "1234", "295", "1", null},
-      {"/sdcard/media_api/metaDataTestMedias/MP3/ID3V2.mp3", "1/10", "ID3V2.3 Album", "ID3V2.3 Artist",
-          "ID3V2.3 Lyricist", "ID3V2.3 Composer", null, "Blues", 
-          "ID3V2.3 Title", "1234", "287", "1", null},
-      {"/sdcard/media_api/metaDataTestMedias/MP3/ID3V1.mp3", "1", "test ID3V1 Album", "test ID3V1 Artist",
-          null, null, null, "255", "test ID3V1 Title", "1234", "231332", "1", null},
-      {"/sdcard/media_api/metaDataTestMedias/MP3/Corrupted_ID3V1.mp3" , null, null, null,
-              null, null, null, null, null, null, "231330", "1", null},
-      //The corrupted TALB field in id3v2 would not switch to id3v1 tag automatically
-      {"/sdcard/media_api/metaDataTestMedias/MP3/Corrupted_ID3V2_TALB.mp3", "01", null, "ID3V2.3 Artist",
-          "ID3V2.3 Lyricist", "ID3V2.3 Composer", null, 
-          "Blues", "ID3V2.3 Title", "1234", "295", "1", null},
-      {"/sdcard/media_api/metaDataTestMedias/MP3/Corrupted_ID3V2_TCOM.mp3", "01", "ID3V2.3 Album", 
-           "ID3V2.3 Artist", "ID3V2.3 Lyricist", null, null, 
-           "Blues", "ID3V2.3 Title", "1234", "295", "1", null},
-      {"/sdcard/media_api/metaDataTestMedias/MP3/Corrupted_ID3V2_TCOM_2.mp3", "01", "ID3V2.3 Album", 
-           "ID3V2.3 Artist", null, null, null, "Blues", "ID3V2.3 Title", "1234", "295", "1", null},
-      {"/sdcard/media_api/metaDataTestMedias/MP3/Corrupted_ID3V2_TRCK.mp3", "dd", "ID3V2.3 Album", 
-           "ID3V2.3 Artist", "ID3V2.3 Lyricist", "ID3V2.3 Composer", null,
-           "Blues", "ID3V2.3 Title", "1234", "295", "1", null},
-      {"/sdcard/media_api/metaDataTestMedias/MP3/Corrupted_ID3V2_TRCK_2.mp3", "01", "ID3V2.3 Album", 
-           "ID3V2.3 Artist", null, null, null, null, "ID3V2.3 Title", null, "295", "1", null},
-      {"/sdcard/media_api/metaDataTestMedias/MP3/Corrupted_ID3V2_TYER.mp3", "01", "ID3V2.3 Album",
-           "ID3V2.3 Artist", null, null, null, null, "ID3V2.3 Title", "9999", "295", "1", null},
-      {"/sdcard/media_api/metaDataTestMedias/MP3/Corrupted_ID3V2_TYER_2.mp3", "01", "ID3V2.3 Album",
-           "ID3V2.3 Artist", "ID3V2.3 Lyricist", "ID3V2.3 Composer", null, 
-           "Blues", "ID3V2.3 Title", null, "295", "1", null},
-      {"/sdcard/media_api/metaDataTestMedias/MP3/Corrupted_ID3V2_TIT.mp3", null, null, null,
-          null, null, null, null, null, null, "295", "1", null}
-  };
+    /*
+     * Metadata Utility Test media files which contain meta data.
+     */
+    public static final String[] THUMBNAIL_METADATA_TEST_FILES = {
+        "/sdcard/media_api/video/H263_500_AMRNB_12.3gp",
+        "/sdcard/media_api/video/H263_56_AAC_24.3gp",
+        "/sdcard/media_api/video/H263_56_AMRNB_6.3gp",
+        "/sdcard/media_api/video/H264_320_AAC_64.3gp",
+        "/sdcard/media_api/video/H264_320_AMRNB_6.3gp",
+        "/sdcard/media_api/video/H264_500_AAC_128.3gp",
+        "/sdcard/media_api/video/H264_HVGA_500_NO_AUDIO.3gp",
+        "/sdcard/media_api/video/H264_QVGA_500_NO_AUDIO.3gp",
+        "/sdcard/media_api/video/MPEG4_320_AAC_64.mp4",
+        "/sdcard/media_api/video/border_large.3gp",
+        "/sdcard/media_api/videoeditor/H264_BP_800x480_15fps_512kbps_AACLC_24KHz_38Kbps_s_1_17.mp4",
+        "/sdcard/media_api/videoeditor/H264_MP_960x720_25fps_800kbps_AACLC_48Khz_192Kbps_s_1_17.mp4",
+        "/sdcard/media_api/videoeditor/MPEG4_SP_640x480_15fps_512kbps_AACLC_48khz_132kbps_s_0_26.mp4",
+        "/sdcard/media_api/videoeditor/MPEG4_SP_176x144_12fps_92kbps_AMRNB_8KHz_12.2kbps_m_0_27.3gp",
+        "/sdcard/media_api/videoeditor/MPEG4_SP_720x480_30fps_280kbps_AACLC_48kHz_161kbps_s_0_26.mp4"
+    };
 
-  public static final String META_DATA_OTHERS [][] = {
-      {"/sdcard/media_api/metaDataTestMedias/3GP/cat.3gp", null, null, null,
-          null, null, "20080309T002415.000Z", null,
-          null, null, "63916", "2", null},
-      {"/sdcard/media_api/metaDataTestMedias/AMR/AMR_NB.amr", null, null, null,
-          null, null, null, null,
-          null, null, "126540", "1", null},
-      {"/sdcard/media_api/metaDataTestMedias/AMRWB/AMR_WB.amr", null, null, null,
-          null, null, null, null,
-          null, null, "231180", "1", null},
-      {"/sdcard/media_api/metaDataTestMedias/M4A/Jaws Of Life_ver1.m4a", "1/8", "Suspended Animation",
-          "John Petrucci", null, null, "20070510T125223.000Z", 
-          "12", "Jaws Of Life", "2005", "449329", "1", "m4a composer"},
-      {"/sdcard/media_api/metaDataTestMedias/M4V/sample_iPod.m4v", null, null, 
-          null, null, null, "20051220T202015.000Z", 
-          null, null, null, "85500", "2", null},
-      {"/sdcard/media_api/metaDataTestMedias/MIDI/MIDI.mid", null, "Suspended Animation", 
-          "John Petrucci", null, null, "20070510T125223.000Z", 
-          null, null, "2005", "231180", "1", null},
-      {"/sdcard/media_api/metaDataTestMedias/MP4/kung_fu_panda_h264.mp4", "2/0", "mp4 album Kung Fu Panda",
-          "mp4 artist Kung Fu Panda", null, null, "20080517T091451.000Z", 
-          "40", "Kung Fu Panda", "2008", "128521", "2", "mp4 composer"},
-      {"/sdcard/media_api/metaDataTestMedias/OGG/Ring_Classic_02.ogg", null, "Suspended Animation", 
-          "John Petrucci", null, null, "20070510T125223.000Z", 
-          null, null, "2005", "231180", "1", null},
-      {"/sdcard/media_api/metaDataTestMedias/OGG/When You Say Nothing At All.ogg", 
-          null, "Suspended Animation", "John Petrucci", 
-          null, null, "20070510T125223.000Z", null, null, "2005", "231180", "1", null},
-      {"/sdcard/media_api/metaDataTestMedias/WAV/Im With You.wav", null, null, 
-          null, null, null, null, 
-          null, null, null, "224000", "1", null},
-      {"/sdcard/media_api/metaDataTestMedias/WMA/WMA9.wma", "6", "Ten Songs in the Key of Betrayal", 
-          "Alien Crime Syndicate", "Alien Crime Syndicate", 
-          "wma 9 Composer", "20040521T175729.483Z", 
-          "Rock", "Run for the Money", "2004", "134479", "1", null},
-      {"/sdcard/media_api/metaDataTestMedias/WMA/WMA10.wma", "09", "wma 10 Album", 
-          "wma 10 Album Artist", "wma 10 Artist", "wma 10 Composer", "20070705T063625.097Z", 
-          "Acid Jazz", "wma 10 Title", "2010", "126574", "1", null},
-      {"/sdcard/media_api/metaDataTestMedias/WMV/bugs.wmv", "8", "wmv 9 Album", 
-          null, "wmv 9 Artist ", null, "20051122T155247.540Z", 
-          null, "Looney Tunes - Hare-Breadth Hurry", "2005", "193482", "2", null},
-      {"/sdcard/media_api/metaDataTestMedias/WMV/clips_ver7.wmv", "50", "wmv 7 Album", 
-          null, "Hallau Shoots & Company", null, "20020226T170045.891Z", 
-          null, "CODEC Shootout", "1986", "43709", "2", null}
-  };
-  
-  //output recorded video
-  
-  public static final String RECORDED_HVGA_H263 = "/sdcard/HVGA_H263.3gp";
-  public static final String RECORDED_QVGA_H263 = "/sdcard/QVGA_H263.3gp";
-  public static final String RECORDED_SQVGA_H263 = "/sdcard/SQVGA_H263.3gp";
-  public static final String RECORDED_CIF_H263 = "/sdcard/CIF_H263.3gp";
-  public static final String RECORDED_QCIF_H263 = "/sdcard/QCIF_H263.3gp";
-  public static final String RECORDED_PORTRAIT_H263 = "/sdcard/QCIF_mp4.3gp";
-  
-  public static final String RECORDED_HVGA_MP4 = "/sdcard/HVGA_mp4.mp4";
-  public static final String RECORDED_QVGA_MP4 = "/sdcard/QVGA_mp4.mp4";
-  public static final String RECORDED_SQVGA_MP4 = "/sdcard/SQVGA_mp4.mp4";
-  public static final String RECORDED_CIF_MP4 = "/sdcard/CIF_mp4.mp4";
-  public static final String RECORDED_QCIF_MP4 = "/sdcard/QCIF_mp4.mp4";
-  
-  public static final String RECORDED_VIDEO_3GP = "/sdcard/temp.3gp";
-  
-  public static final String INVALD_VIDEO_PATH = "/sdcard/media_api/filepathdoesnotexist" +
-      "/filepathdoesnotexist/temp.3gp";
-  
- 
-  public static final long RECORDED_TIME = 5000;
-  public static final long VALID_VIDEO_DURATION = 2000;
-  
-  //Videos for the mediaplayer stress test
-  public static String[] H263_STRESS = { 
-      "/sdcard/media_api/video_stress/h263/H263_CIF.3gp",
-      "/sdcard/media_api/video_stress/h263/H263_QCIF.3gp",
-      "/sdcard/media_api/video_stress/h263/H263_QVGA.3gp",
-      "/sdcard/media_api/video_stress/h263/H263_SQVGA.3gp"
-  };
-  
-  public static String[] MPEG4_STRESS = { 
-    "/sdcard/media_api/video_stress/h263/mpeg4_CIF.mp4",
-    "/sdcard/media_api/video_stress/h263/mpeg4_QCIF.3gp",
-    "/sdcard/media_api/video_stress/h263/mpeg4_QVGA.3gp",
-    "/sdcard/media_api/video_stress/h263/mpeg4_SQVGA.mp4"
-  };
-  
-  //Streaming test files
-  public static final byte [] STREAM_SERVER = new byte[] {(byte)75,(byte)17,(byte)48,(byte)204};
-  public static final String STREAM_H264_480_360_1411k = 
-      "http://75.17.48.204:10088/yslau/stress_media/h264_regular.mp4";
-  public static final String STREAM_WMV = 
-      "http://75.17.48.204:10088/yslau/stress_media/bugs.wmv";
-  public static final String STREAM_H263_176x144_325k = 
-      "http://75.17.48.204:10088/yslau/stress_media/h263_regular.3gp";
-  public static final String STREAM_H264_352x288_1536k = 
-      "http://75.17.48.204:10088/yslau/stress_media/h264_highBitRate.mp4";
-  public static final String STREAM_MP3= 
-      "http://75.17.48.204:10088/yslau/stress_media/mp3_regular.mp3";
-  public static final String STREAM_MPEG4_QVGA_128k = 
-      "http://75.17.48.204:10088/yslau/stress_media/mpeg4_qvga_24fps.3gp";
-  public static final int STREAM_H264_480_360_1411k_DURATION = 46000;
-  public static final int VIDEO_H263_AAC_DURATION = 501000;
-  public static final int VIDEO_H263_AMR_DURATION = 502000;
+    public static final String[] ALBUMART_TEST_FILES = {
+        "/sdcard/media_api/music/MP3_48KHz_128kbps_s_1_17_ID3V1_ID3V2.mp3",
+        "/sdcard/media_api/music/MP3_48KHz_128kbps_s_1_17_ID3V2.mp3",
+        "/sdcard/media_api/music/MP3_48KHz_128kbps_s_1_17_ID3V1.mp3",
+    };
+
+    // TEST_PATH_1: is a video and contains metadata for key "num-tracks"
+    // TEST_PATH_2: any valid media file.
+    // TEST_PATH_3: invalid media file
+    public static final String TEST_PATH_1 = "/sdcard/media_api/video/MPEG4_320_AAC_64.mp4";
+    public static final String TEST_PATH_3 = "/sdcard/media_api/data.txt";
+    public static final String TEST_PATH_4 = "somenonexistingpathname";
+    public static final String TEST_PATH_5 = "mem://012345";
+
+    // Meta data expected result
+    // The expected tag result in the following order
+    // cd_track_number, album, artist, author, composer, date, genre
+    // title, years, duration
+    public static final String META_DATA_MP3[][] = {
+        {"/sdcard/media_api/music/MP3_48KHz_128kbps_s_1_17_ID3V1_ID3V2.mp3", "2/34",
+         "Test ID3V2 Album", "Test ID3V2 Artist", null, "Test ID3V2 Composer",
+         null, "(1)Classic Rock", "Test ID3V2 Title ", null, "77640", "1", null},
+        {"/sdcard/media_api/music/MP3_48KHz_128kbps_s_1_17_ID3V2.mp3", "1/10",
+         "Test ID3V2 Album", "Test ID3V2 Artist", null, "Test ID3V2 Composer",
+         null, "(74)Acid Jazz", "Test ID3V2 Tag", null, "77640", "1", null},
+        {"/sdcard/media_api/music/MP3_48KHz_128kbps_s_1_17_ID3V1.mp3", "2",
+         "Test ID3V1 Album", "Test ID3V1 Artist", null, null, null, "(15)",
+         "Test ID3V1 Title", "2011", "77640", "1", null}
+    };
+
+    // output recorded video
+    public static final String RECORDED_HVGA_H263 = "/sdcard/HVGA_H263.3gp";
+    public static final String RECORDED_QVGA_H263 = "/sdcard/QVGA_H263.3gp";
+    public static final String RECORDED_SQVGA_H263 = "/sdcard/SQVGA_H263.3gp";
+    public static final String RECORDED_CIF_H263 = "/sdcard/CIF_H263.3gp";
+    public static final String RECORDED_QCIF_H263 = "/sdcard/QCIF_H263.3gp";
+    public static final String RECORDED_PORTRAIT_H263 = "/sdcard/QCIF_mp4.3gp";
+
+    public static final String RECORDED_HVGA_MP4 = "/sdcard/HVGA_mp4.mp4";
+    public static final String RECORDED_QVGA_MP4 = "/sdcard/QVGA_mp4.mp4";
+    public static final String RECORDED_SQVGA_MP4 = "/sdcard/SQVGA_mp4.mp4";
+    public static final String RECORDED_CIF_MP4 = "/sdcard/CIF_mp4.mp4";
+    public static final String RECORDED_QCIF_MP4 = "/sdcard/QCIF_mp4.mp4";
+
+    public static final String RECORDED_VIDEO_3GP = "/sdcard/temp.3gp";
+
+    public static final String INVALD_VIDEO_PATH =
+            "/sdcard/media_api/filepathdoesnotexist" + "/filepathdoesnotexist/temp.3gp";
+
+    public static final long RECORDED_TIME = 5000;
+    public static final long VALID_VIDEO_DURATION = 2000;
+
+    // Streaming test files
+    public static final byte[] STREAM_SERVER =
+            new byte[] {(byte) 75, (byte) 17, (byte) 48, (byte) 204};
+    public static final String STREAM_H264_480_360_1411k =
+            "http://75.17.48.204:10088/yslau/stress_media/h264_regular.mp4";
+    public static final String STREAM_WMV = "http://75.17.48.204:10088/yslau/stress_media/bugs.wmv";
+    public static final String STREAM_H263_176x144_325k =
+            "http://75.17.48.204:10088/yslau/stress_media/h263_regular.3gp";
+    public static final String STREAM_H264_352x288_1536k =
+            "http://75.17.48.204:10088/yslau/stress_media/h264_highBitRate.mp4";
+    public static final String STREAM_MP3 =
+            "http://75.17.48.204:10088/yslau/stress_media/mp3_regular.mp3";
+    public static final String STREAM_MPEG4_QVGA_128k =
+            "http://75.17.48.204:10088/yslau/stress_media/mpeg4_qvga_24fps.3gp";
+    public static final int STREAM_H264_480_360_1411k_DURATION = 46000;
+    public static final int VIDEO_H263_AAC_DURATION = 501000;
+    public static final int VIDEO_H263_AMR_DURATION = 502000;
 }
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaMetadataTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaMetadataTest.java
index 6ded74d..380de9c 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaMetadataTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaMetadataTest.java
@@ -41,20 +41,11 @@
     }
     
     public static enum MP3_TEST_FILE{
-        ID3V1V2, ID3V2, ID3V1,
-        CORRUPTED_ID3V1, CORRUPTED_ID3V2_TALB, CORRUPTED_ID3V2_TCOM,
-        CORRUPTED_ID3V2_TCOM_2, CORRUPTED_ID3V2_TRCK, CORRUPTED_D3V2_TRCK_2,
-        CORRUPTED_ID3V2_TYER, CORRUPTED_ID3V2_TYER_2, CORRUPTED_ID3V2_TIT
-    }
-    
-    public static enum NON_MP3_TEST_FILE{
-         THREE3GP, AMRNB, AMRWB, M4A1, M4V, MIDI,
-         H264, OGG1, OGG2, WAV, WMA9, WMA10, WMV9, WMV7
+        ID3V1V2, ID3V2, ID3V1
     }
     
     public static METADATA_EXPECTEDRESULT meta;
     public static MP3_TEST_FILE mp3_test_file;
-    public static NON_MP3_TEST_FILE non_mp3_test_file;
    
     @MediumTest
     public static void testID3V1V2Metadata() throws Exception {
@@ -70,134 +61,11 @@
     public static void testID3V1Metadata() throws Exception {
         validateMetatData(mp3_test_file.ID3V1.ordinal(), MediaNames.META_DATA_MP3);
     }
-    
-    @MediumTest
-    public static void testCorruptedID3V1Metadata() throws Exception {
-        validateMetatData(mp3_test_file.CORRUPTED_ID3V1.ordinal(), MediaNames.META_DATA_MP3);
-    }
 
-    @MediumTest
-    public static void testCorrupted_ID3V2_TALBMetadata() throws Exception {
-        validateMetatData(mp3_test_file.CORRUPTED_ID3V2_TALB.ordinal(), MediaNames.META_DATA_MP3);
-    }
-    
-    @MediumTest
-    public static void testCorrupted_ID3V2_TCOMMetadata() throws Exception {
-        validateMetatData(mp3_test_file.CORRUPTED_ID3V2_TCOM.ordinal(), MediaNames.META_DATA_MP3);
-    }
-    
-    @MediumTest
-    public static void testCorrupted_ID3V2_TCOMM2etadata() throws Exception {
-        validateMetatData(mp3_test_file.CORRUPTED_ID3V2_TCOM_2.ordinal(), MediaNames.META_DATA_MP3);
-    }
-    
-    @MediumTest
-    public static void testCorrupted_ID3V2_TRCKMetadata() throws Exception {
-        validateMetatData(mp3_test_file.CORRUPTED_ID3V2_TRCK.ordinal(), MediaNames.META_DATA_MP3);
-    }
-    
-    @MediumTest
-    public static void testCorrupted_ID3V2_TRCK2Metadata() throws Exception {
-        validateMetatData(mp3_test_file.CORRUPTED_D3V2_TRCK_2.ordinal(), MediaNames.META_DATA_MP3);
-    }
-   
-    @MediumTest
-    public static void testCorrupted_ID3V2_TYERMetadata() throws Exception {
-        validateMetatData(mp3_test_file.CORRUPTED_ID3V2_TYER.ordinal(), MediaNames.META_DATA_MP3);
-    }
-    
-    @MediumTest
-    public static void testCorrupted_ID3V2_TYER2Metadata() throws Exception {
-        validateMetatData(mp3_test_file.CORRUPTED_ID3V2_TYER_2.ordinal(), MediaNames.META_DATA_MP3);
-    }
-    
-    @MediumTest
-    public static void testCorrupted_ID3V2_TITMetadata() throws Exception {
-        validateMetatData(mp3_test_file.CORRUPTED_ID3V2_TIT.ordinal(), MediaNames.META_DATA_MP3);
-    }
-   
-    @MediumTest
-    public static void test3gp_Metadata() throws Exception {
-        validateMetatData(non_mp3_test_file.THREE3GP.ordinal(), MediaNames.META_DATA_OTHERS);
-    }
-    
-    @MediumTest
-    public static void testAmr_Metadata() throws Exception {
-        validateMetatData(non_mp3_test_file.AMRNB.ordinal(), MediaNames.META_DATA_OTHERS);
-    }
-    
-    @MediumTest
-    public static void testAmrWb_Metadata() throws Exception {
-        validateMetatData(non_mp3_test_file.AMRWB.ordinal(), MediaNames.META_DATA_OTHERS);
-    }
-    
-    @MediumTest
-    public static void testM4A1_Metadata() throws Exception {
-        validateMetatData(non_mp3_test_file.M4A1.ordinal(), MediaNames.META_DATA_OTHERS);
-    }
-    
-    @MediumTest
-    public static void testM4v_Metadata() throws Exception {
-        validateMetatData(non_mp3_test_file.M4V.ordinal(), MediaNames.META_DATA_OTHERS);
-    }
-    
-    @MediumTest
-    public static void testH264_Metadata() throws Exception {
-        validateMetatData(non_mp3_test_file.H264.ordinal(), MediaNames.META_DATA_OTHERS);
-    }
-    //bug# 1440489
-    @Suppress
-    @MediumTest
-    public static void testOgg1_Metadata() throws Exception {
-        validateMetatData(non_mp3_test_file.OGG1.ordinal(), MediaNames.META_DATA_OTHERS);
-    }
-    
-    @Suppress
-    @MediumTest
-    public static void testOgg2_Metadata() throws Exception {
-        validateMetatData(non_mp3_test_file.OGG2.ordinal(), MediaNames.META_DATA_OTHERS);
-    }
-    
-    @Suppress
-    @MediumTest
-    public static void testMidi_Metadata() throws Exception {
-        validateMetatData(non_mp3_test_file.MIDI.ordinal(), MediaNames.META_DATA_OTHERS);
-    }
-    
-    @MediumTest
-    public static void testWav_Metadata() throws Exception {
-        validateMetatData(non_mp3_test_file.WAV.ordinal(), MediaNames.META_DATA_OTHERS);
-    }
-    
-    @Suppress
-    @MediumTest
-    public static void testWma9_Metadata() throws Exception {
-        validateMetatData(non_mp3_test_file.WMA9.ordinal(), MediaNames.META_DATA_OTHERS);
-    }
-    
-    @Suppress
-    @MediumTest
-    public static void testWma10_Metadata() throws Exception {
-        validateMetatData(non_mp3_test_file.WMA10.ordinal(), MediaNames.META_DATA_OTHERS);
-    }
-    
-    @Suppress
-    @MediumTest
-    public static void testWmv9_Metadata() throws Exception {
-        validateMetatData(non_mp3_test_file.WMV9.ordinal(), MediaNames.META_DATA_OTHERS);
-    }
-    
-    @Suppress
-    @MediumTest
-    public static void testWmv10_Metadata() throws Exception {
-        validateMetatData(non_mp3_test_file.WMV7.ordinal(), MediaNames.META_DATA_OTHERS);
-    }
-     
     private static void validateMetatData(int fileIndex, String meta_data_file[][]) {
         Log.v(TAG, "filePath = "+ meta_data_file[fileIndex][0]);
         if ((meta_data_file[fileIndex][0].endsWith("wma") && !MediaProfileReader.getWMAEnable()) ||
             (meta_data_file[fileIndex][0].endsWith("wmv") && !MediaProfileReader.getWMVEnable())) {
-            Log.v(TAG, "Skip test since windows media is not supported");
             return;
         }
         String value = null;
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaPlayerApiTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaPlayerApiTest.java
index d22025c..57d5368 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaPlayerApiTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaPlayerApiTest.java
@@ -84,15 +84,6 @@
       duratoinWithinTolerence = verifyDuration(duration, MediaNames.MIDI_LENGTH);
       assertTrue("MIDI getDuration", duratoinWithinTolerence);  
     }
-    
-    @MediumTest
-    public void testWMA9GetDuration() throws Exception {
-      if (isWMAEnable) {
-            int duration = CodecTest.getDuration(MediaNames.WMA9);
-            duratoinWithinTolerence = verifyDuration(duration, MediaNames.WMA9_LENGTH);
-            assertTrue("WMA9 getDuration", duratoinWithinTolerence);
-        }
-    }
 
     @MediumTest
     public void testAMRGetDuration() throws Exception {
@@ -127,15 +118,7 @@
       boolean currentPosition = CodecTest.getCurrentPosition(MediaNames.MIDI);  
       assertTrue("MIDI GetCurrentPosition", currentPosition);  
     }
-    
-    @LargeTest
-    public void testWMA9GetCurrentPosition() throws Exception {
-        if (isWMAEnable) {
-            boolean currentPosition = CodecTest.getCurrentPosition(MediaNames.WMA9);
-            assertTrue("WMA9 GetCurrentPosition", currentPosition);
-        }
-    }
-    
+
     @LargeTest
     public void testAMRGetCurrentPosition() throws Exception {
       boolean currentPosition = CodecTest.getCurrentPosition(MediaNames.AMR);  
@@ -166,15 +149,7 @@
       boolean isPaused = CodecTest.pause(MediaNames.MIDI);  
       assertTrue("MIDI Pause", isPaused);  
     }
-   
-    @LargeTest
-    public void testWMA9Pause() throws Exception {
-        if (isWMAEnable) {
-            boolean isPaused = CodecTest.pause(MediaNames.WMA9);
-            assertTrue("WMA9 Pause", isPaused);
-        }
-    }
-  
+
     @LargeTest
     public void testAMRPause() throws Exception {
       boolean isPaused = CodecTest.pause(MediaNames.AMR);  
@@ -239,15 +214,7 @@
       boolean isLoop = CodecTest.setLooping(MediaNames.MIDI);  
       assertTrue("MIDI setLooping", isLoop);  
     }
-    
-    @LargeTest
-    public void testWMA9SetLooping() throws Exception {
-      if (isWMAEnable) {
-        boolean isLoop = CodecTest.setLooping(MediaNames.WMA9);
-        assertTrue("WMA9 setLooping", isLoop);
-      }
-    }
-    
+
     @LargeTest
     public void testAMRSetLooping() throws Exception {
       boolean isLoop = CodecTest.setLooping(MediaNames.AMR);  
@@ -279,15 +246,7 @@
       boolean isLoop = CodecTest.seekTo(MediaNames.MIDI);  
       assertTrue("MIDI seekTo", isLoop);  
     }
-    
-    @LargeTest
-    public void testWMA9SeekTo() throws Exception {
-        if (isWMAEnable) {
-            boolean isLoop = CodecTest.seekTo(MediaNames.WMA9);
-            assertTrue("WMA9 seekTo", isLoop);
-        }
-    }
-    
+
     @LargeTest
     public void testAMRSeekTo() throws Exception {
       boolean isLoop = CodecTest.seekTo(MediaNames.AMR);  
@@ -320,15 +279,6 @@
       boolean isEnd = CodecTest.seekToEnd(MediaNames.MIDI);  
       assertTrue("MIDI seekToEnd", isEnd);  
     }
-
-    @Suppress
-    @LargeTest
-    public void testWMA9SeekToEnd() throws Exception {
-        if (isWMAEnable) {
-            boolean isEnd = CodecTest.seekToEnd(MediaNames.WMA9);
-            assertTrue("WMA9 seekToEnd", isEnd);
-        }
-    }
     
     @LargeTest
     public void testAMRSeekToEnd() throws Exception {
@@ -369,13 +319,7 @@
       boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_MP4);
       assertTrue("Local MP4 SeekTo", isSeek);          
     }
-    
-    @LargeTest
-    public void testVideoLong3gpSeekTo() throws Exception {
-      boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_LONG_3GP);
-      assertTrue("Local 3gp SeekTo", isSeek);         
-    }
-   
+
     @LargeTest
     public void testVideoH263AACSeekTo() throws Exception {
       boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_H263_AAC);
@@ -399,17 +343,13 @@
       boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_H264_AMR);
       assertTrue("H264AMR SeekTo", isSeek);         
     }
-   
+
     @LargeTest
-    public void testVideoWMVSeekTo() throws Exception {
-        Log.v(TAG, "wmv not enable");
-        if (isWMVEnable) {
-            Log.v(TAG, "wmv enable");
-            boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_WMV);
-            assertTrue("WMV SeekTo", isSeek);
-        }
+    public void testVideoWebmSeekTo() throws Exception {
+      boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_WEBM);
+      assertTrue("WEBM SeekTo", isSeek);
     }
-    
+
     @LargeTest
     public void testSoundRecord() throws Exception {
       boolean isRecordered = CodecTest.mediaRecorderRecord(MediaNames.RECORDER_OUTPUT);
@@ -418,7 +358,7 @@
   
     @LargeTest
     public void testGetThumbnail() throws Exception {
-      boolean getThumbnail = CodecTest.getThumbnail(MediaNames.VIDEO_H264_AAC, MediaNames.GOLDEN_THUMBNAIL_OUTPUT_2);
+      boolean getThumbnail = CodecTest.getThumbnail(MediaNames.VIDEO_H264_AAC, MediaNames.GOLDEN_THUMBNAIL_OUTPUT);
       assertTrue("Get Thumbnail", getThumbnail);         
     }
     
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/performance/MediaPlayerPerformance.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/performance/MediaPlayerPerformance.java
index 34affa7..b396223 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/performance/MediaPlayerPerformance.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/performance/MediaPlayerPerformance.java
@@ -100,109 +100,6 @@
             MediaTestUtil.getNativeHeapDump(this.getName() + "_after");
     }
 
-    public void createDB() {
-        mDB = SQLiteDatabase.openOrCreateDatabase("/sdcard/perf.db", null);
-        mDB.execSQL("CREATE TABLE IF NOT EXISTS perfdata (_id INTEGER PRIMARY KEY," + 
-                "file TEXT," + "setdatatime LONG," + "preparetime LONG," +
-                "playtime LONG" + ");");
-        //clean the table before adding new data
-        mDB.execSQL("DELETE FROM perfdata");
-    }
-
-    public void audioPlaybackStartupTime(String[] testFile) {
-        long t1 = 0;
-        long t2 = 0;
-        long t3 = 0;
-        long t4 = 0;
-        long setDataSourceDuration = 0;
-        long prepareDuration = 0;
-        long startDuration = 0;
-        long totalSetDataTime = 0;
-        long totalPrepareTime = 0;
-        long totalStartDuration = 0;
-
-        int numberOfFiles = testFile.length;
-        Log.v(TAG, "File length " + numberOfFiles);
-        for (int k = 0; k < numberOfFiles; k++) {
-            MediaPlayer mp = new MediaPlayer();
-            try {
-                t1 = SystemClock.uptimeMillis();
-                FileInputStream fis = new FileInputStream(testFile[k]);
-                FileDescriptor fd = fis.getFD();
-                mp.setDataSource(fd);
-                fis.close();
-                t2 = SystemClock.uptimeMillis();
-                mp.prepare();
-                t3 = SystemClock.uptimeMillis();
-                mp.start();
-                t4 = SystemClock.uptimeMillis();
-            } catch (Exception e) {
-                Log.v(TAG, e.toString());
-            }
-            setDataSourceDuration = t2 - t1;
-            prepareDuration = t3 - t2;
-            startDuration = t4 - t3;
-            totalSetDataTime = totalSetDataTime + setDataSourceDuration;
-            totalPrepareTime = totalPrepareTime + prepareDuration;
-            totalStartDuration = totalStartDuration + startDuration;
-            mDB.execSQL("INSERT INTO perfdata (file, setdatatime, preparetime," +
-                    " playtime) VALUES (" + '"' + testFile[k] + '"' + ',' +
-                    setDataSourceDuration + ',' + prepareDuration +
-            		',' + startDuration + ");");
-            Log.v(TAG, "File name " + testFile[k]);
-            mp.stop();
-            mp.release();
-        }
-        Log.v(TAG, "setDataSource average " + totalSetDataTime / numberOfFiles);
-        Log.v(TAG, "prepare average " + totalPrepareTime / numberOfFiles);
-        Log.v(TAG, "start average " + totalStartDuration / numberOfFiles);
-
-    }
-
-    @Suppress
-    public void testStartUpTime() throws Exception {
-        createDB();
-        audioPlaybackStartupTime(MediaNames.MP3FILES);
-        audioPlaybackStartupTime(MediaNames.AACFILES);
-
-        //close the database after all transactions
-        if (mDB.isOpen()) {
-            mDB.close();
-        }
-    }
-
-    public void wmametadatautility(String[] testFile) {
-        long t1 = 0;
-        long t2 = 0;
-        long sum = 0;
-        long duration = 0;
-        MediaMetadataRetriever retriever = new MediaMetadataRetriever();
-        String value;
-        for (int i = 0, n = testFile.length; i < n; ++i) {
-            try {
-                t1 = SystemClock.uptimeMillis();
-                retriever.setDataSource(testFile[i]);
-                value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM);
-                value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
-                value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_COMPOSER);
-                value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE);
-                value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
-                value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_YEAR);
-                value =
-                    retriever
-                    .extractMetadata(MediaMetadataRetriever.METADATA_KEY_CD_TRACK_NUMBER);
-                t2 = SystemClock.uptimeMillis();
-                duration = t2 - t1;
-                Log.v(TAG, "Time taken = " + duration);
-                sum = sum + duration;
-            } catch (Exception e) {
-                Log.v(TAG, e.getMessage());
-            }
-
-        }
-        Log.v(TAG, "Average duration = " + sum / testFile.length);
-    }
-
     private void initializeMessageLooper() {
         final ConditionVariable startDone = new ConditionVariable();
         new Thread() {
@@ -421,13 +318,6 @@
         return true;
     }
 
-    @Suppress
-    public void testWmaParseTime() throws Exception {
-        // createDB();
-        wmametadatautility(MediaNames.WMASUPPORTED);
-    }
-
-
     // Test case 1: Capture the memory usage after every 20 h263 playback
     @LargeTest
     public void testH263VideoPlaybackMemoryUsage() throws Exception {
@@ -466,26 +356,6 @@
         assertTrue("H264 playback memory test", memoryResult);
     }
 
-    // Test case 3: Capture the memory usage after each 20 WMV playback
-    @LargeTest
-    public void testWMVVideoPlaybackMemoryUsage() throws Exception {
-        boolean memoryResult = false;
-        if (MediaProfileReader.getWMVEnable()){
-            mStartPid = getMediaserverPid();
-            File wmvMemoryOut = new File(MEDIA_MEMORY_OUTPUT);
-            Writer output = new BufferedWriter(new FileWriter(wmvMemoryOut, true));
-            output.write("WMV video playback only\n");
-            for (int i = 0; i < NUM_STRESS_LOOP; i++) {
-                mediaStressPlayback(MediaNames.VIDEO_WMV);
-                getMemoryWriteToLog(output, i);
-            }
-            output.write("\n");
-            memoryResult = validateMemoryResult(mStartPid, mStartMemory, output, DECODER_LIMIT);
-            output.close();
-            assertTrue("wmv playback memory test", memoryResult);
-        }
-    }
-
     // Test case 4: Capture the memory usage after every 20 video only recorded
     @LargeTest
     public void testH263RecordVideoOnlyMemoryUsage() throws Exception {
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/performance/VideoEditorPerformance.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/performance/VideoEditorPerformance.java
index 4c66a2d..7eb6d22 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/performance/VideoEditorPerformance.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/performance/VideoEditorPerformance.java
@@ -112,12 +112,11 @@
 
     private final int NUM_OF_ITERATIONS=20;
 
-    private float calculateTimeTaken(long beginTime, int numIterations)
+    private int calculateTimeTaken(long beginTime, int numIterations)
         throws Exception {
         final long duration2 = SystemClock.uptimeMillis();
         final long durationToCreateMediaItem = (duration2 - beginTime);
-        final float timeTaken1 = (float)durationToCreateMediaItem *
-            1.0f/(float)numIterations;
+        final int timeTaken1 = (int)(durationToCreateMediaItem / numIterations);
         return (timeTaken1);
     }
 
@@ -208,7 +207,7 @@
         final String[] loggingInfo = new String[3];
         final MediaVideoItem[] mediaVideoItem =
             new MediaVideoItem[NUM_OF_ITERATIONS];
-        float timeTaken = 0.0f;
+        int timeTaken = 0;
         long startTime = 0;
 
         /** Time Take for creation of Media Video Item */
@@ -251,7 +250,7 @@
         final String[] loggingInfo = new String[3];
         final MediaImageItem[] mediaImageItem =
             new MediaImageItem[NUM_OF_ITERATIONS];
-        float timeTaken = 0.0f;
+        int timeTaken = 0;
 
         long beginTime = SystemClock.uptimeMillis();
         createImageItems(mediaImageItem, imageItemFileName, renderingMode,
@@ -296,7 +295,7 @@
         final int transitionDuration = 5000;
         final int transitionBehavior = Transition.BEHAVIOR_MIDDLE_FAST;
         final String[] loggingInfo = new String[3];
-        float timeTaken = 0.0f;
+        int timeTaken = 0;
 
         final MediaVideoItem[] mediaVideoItem =
             new MediaVideoItem[(NUM_OF_ITERATIONS *10) + 1];
@@ -514,7 +513,7 @@
         /** 18.Enable Looping for Audio Track.
          * */
         audioTrack.enableLoop();
-        float timeTaken = 0.0f;
+        int timeTaken = 0;
         final long beginTime = SystemClock.uptimeMillis();
             try {
                 mVideoEditor.export(outFilename, outHeight, outBitrate,
@@ -557,7 +556,7 @@
         mediaVideoItem.setExtractBoundaries(videoItemStartTime,
             videoItemEndTime);
 
-        float timeTaken = 0.0f;
+        int timeTaken = 0;
         long beginTime = SystemClock.uptimeMillis();
         for (int i = 0; i < NUM_OF_ITERATIONS; i++) {
             mediaVideoItem.getThumbnail(mediaVideoItem.getWidth() / 2,
@@ -603,7 +602,7 @@
         final OverlayFrame overlayFrame[] = new OverlayFrame[NUM_OF_ITERATIONS];
         final Bitmap mBitmap =  mVideoEditorHelper.getBitmap(overlayFilename,
             640, 480);
-        float timeTaken = 0.0f;
+        int timeTaken = 0;
         long beginTime = SystemClock.uptimeMillis();
         for (int i = 0; i < NUM_OF_ITERATIONS; i++) {
             overlayFrame[i] = new OverlayFrame(mediaVideoItem, "overlay" + i,
@@ -647,7 +646,7 @@
         final int videoProfile = MediaProperties.H264_PROFILE_0_LEVEL_1_3;
         final int width = 1080;
         final int height = MediaProperties.HEIGHT_720;
-        float timeTaken = 0.0f;
+        int timeTaken = 0;
         final String[] loggingInfo = new String[1];
         final MediaVideoItem mediaVideoItem = new MediaVideoItem(mVideoEditor,
             "m0", videoItemFileName1, renderingMode);
@@ -1006,7 +1005,7 @@
         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
         final int audioVolume = 50;
         final String[] loggingInfo = new String[2];
-        float timeTaken = 0.0f;
+        int timeTaken = 0;
 
         final MediaVideoItem mediaVideoItem = new MediaVideoItem(mVideoEditor,
             "mediaItem1", videoItemFileName1, renderingMode);
@@ -1057,7 +1056,7 @@
         final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
         final String[] loggingInfo = new String[3];
 
-        float timeTaken = 0.0f;
+        int timeTaken = 0;
 
         final MediaImageItem[] mediaImageItem =
             new MediaImageItem[NUM_OF_ITERATIONS];
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaMetadataRetrieverTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaMetadataRetrieverTest.java
index a66db05..8eb75f3 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaMetadataRetrieverTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaMetadataRetrieverTest.java
@@ -76,29 +76,29 @@
         boolean hasFailed = false;
         Log.v(TAG, "Thumbnail processing starts");
         long startedAt = System.currentTimeMillis();
-        for(int i = 0, n = MediaNames.THUMBNAIL_CAPTURE_TEST_FILES.length; i < n; ++i) {
+        for(int i = 0, n = MediaNames.THUMBNAIL_METADATA_TEST_FILES.length; i < n; ++i) {
             try {
-                Log.v(TAG, "File " + i + ": " + MediaNames.THUMBNAIL_CAPTURE_TEST_FILES[i]);
-                if ((MediaNames.THUMBNAIL_CAPTURE_TEST_FILES[i].endsWith(".wma") && !supportWMA) ||
-                    (MediaNames.THUMBNAIL_CAPTURE_TEST_FILES[i].endsWith(".wmv") && !supportWMV)
+                Log.v(TAG, "File " + i + ": " + MediaNames.THUMBNAIL_METADATA_TEST_FILES[i]);
+                if ((MediaNames.THUMBNAIL_METADATA_TEST_FILES[i].endsWith(".wma") && !supportWMA) ||
+                    (MediaNames.THUMBNAIL_METADATA_TEST_FILES[i].endsWith(".wmv") && !supportWMV)
                    ) {
                     Log.v(TAG, "windows media is not supported and thus we will skip the test for this file");
                     continue;
                 }
-                retriever.setDataSource(MediaNames.THUMBNAIL_CAPTURE_TEST_FILES[i]);
+                retriever.setDataSource(MediaNames.THUMBNAIL_METADATA_TEST_FILES[i]);
                 Bitmap bitmap = retriever.getFrameAtTime(-1);
                 assertTrue(bitmap != null);
                 try {
-                    java.io.OutputStream stream = new FileOutputStream(MediaNames.THUMBNAIL_CAPTURE_TEST_FILES[i] + ".jpg");
+                    java.io.OutputStream stream = new FileOutputStream(MediaNames.THUMBNAIL_METADATA_TEST_FILES[i] + ".jpg");
                     bitmap.compress(Bitmap.CompressFormat.JPEG, 75, stream);
                     stream.close();
                 } catch (Exception e) {
-                    Log.e(TAG, "Fails to convert the bitmap to a JPEG file for " + MediaNames.THUMBNAIL_CAPTURE_TEST_FILES[i]);
+                    Log.e(TAG, "Fails to convert the bitmap to a JPEG file for " + MediaNames.THUMBNAIL_METADATA_TEST_FILES[i]);
                     hasFailed = true;
                     Log.e(TAG, e.toString());
                 }
             } catch(Exception e) {
-                Log.e(TAG, "Fails to setDataSource for file " + MediaNames.THUMBNAIL_CAPTURE_TEST_FILES[i]);
+                Log.e(TAG, "Fails to setDataSource for file " + MediaNames.THUMBNAIL_METADATA_TEST_FILES[i]);
                 hasFailed = true;
             }
             Thread.yield();  // Don't be evil
@@ -106,7 +106,7 @@
         long endedAt = System.currentTimeMillis();
         retriever.release();
         assertTrue(!hasFailed);
-        Log.v(TAG, "Average processing time per thumbnail: " + (endedAt - startedAt)/MediaNames.THUMBNAIL_CAPTURE_TEST_FILES.length + " ms");
+        Log.v(TAG, "Average processing time per thumbnail: " + (endedAt - startedAt)/MediaNames.THUMBNAIL_METADATA_TEST_FILES.length + " ms");
     }
     
     @LargeTest
@@ -115,19 +115,19 @@
         boolean supportWMV = MediaProfileReader.getWMVEnable();
         boolean hasFailed = false;
         MediaMetadataRetriever retriever = new MediaMetadataRetriever();
-        for(int i = 0, n = MediaNames.METADATA_RETRIEVAL_TEST_FILES.length; i < n; ++i) {
+        for(int i = 0, n = MediaNames.THUMBNAIL_METADATA_TEST_FILES.length; i < n; ++i) {
             try {
-                Log.v(TAG, "File " + i + ": " + MediaNames.METADATA_RETRIEVAL_TEST_FILES[i]);
-                if ((MediaNames.METADATA_RETRIEVAL_TEST_FILES[i].endsWith(".wma") && !supportWMA) ||
-                    (MediaNames.METADATA_RETRIEVAL_TEST_FILES[i].endsWith(".wmv") && !supportWMV)
+                Log.v(TAG, "File " + i + ": " + MediaNames.THUMBNAIL_METADATA_TEST_FILES[i]);
+                if ((MediaNames.THUMBNAIL_METADATA_TEST_FILES[i].endsWith(".wma") && !supportWMA) ||
+                    (MediaNames.THUMBNAIL_METADATA_TEST_FILES[i].endsWith(".wmv") && !supportWMV)
                    ) {
                     Log.v(TAG, "windows media is not supported and thus we will skip the test for this file");
                     continue;
                 }
-                retriever.setDataSource(MediaNames.METADATA_RETRIEVAL_TEST_FILES[i]);
+                retriever.setDataSource(MediaNames.THUMBNAIL_METADATA_TEST_FILES[i]);
                 extractAllSupportedMetadataValues(retriever);
             } catch(Exception e) {
-                Log.e(TAG, "Fails to setDataSource for file " + MediaNames.METADATA_RETRIEVAL_TEST_FILES[i]);
+                Log.e(TAG, "Fails to setDataSource for file " + MediaNames.THUMBNAIL_METADATA_TEST_FILES[i]);
                 hasFailed = true;
             }
             Thread.yield();  // Don't be evil
@@ -239,45 +239,6 @@
         assertTrue(!hasFailed);
     }
 
-    @MediumTest
-    public static void testIntendedUsage() {
-        // By default, capture frame and retrieve metadata
-        MediaMetadataRetriever retriever = new MediaMetadataRetriever();
-        boolean hasFailed = false;
-        retriever.setDataSource(MediaNames.TEST_PATH_1);
-        assertTrue(retriever.getFrameAtTime(-1) != null);
-        assertTrue(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_NUM_TRACKS) != null);
-
-        // Do not capture frame or retrieve metadata
-        retriever.setDataSource(MediaNames.TEST_PATH_1);
-        if (retriever.getFrameAtTime(-1) != null) {
-            Log.e(TAG, "No frame expected, but is available");
-            hasFailed = true;
-        }
-        if (retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_NUM_TRACKS) != null) {
-            Log.e(TAG, "No num track metadata expected, but is available");
-            hasFailed = true;
-        }
-
-        // Capture frame only
-        retriever.setDataSource(MediaNames.TEST_PATH_1);
-        assertTrue(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_NUM_TRACKS) == null);
-
-        // Retriever metadata only
-        retriever.setDataSource(MediaNames.TEST_PATH_1);
-        if (retriever.getFrameAtTime(-1) != null) {
-            Log.e(TAG, "No frame expected, but is available");
-            hasFailed = true;
-        }
-
-        // Capture frame and retrieve metadata
-        retriever.setDataSource(MediaNames.TEST_PATH_1);
-        assertTrue(retriever.getFrameAtTime(-1) != null);
-        assertTrue(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_NUM_TRACKS) != null);
-        retriever.release();
-        assertTrue(!hasFailed);
-    }
-
     // TODO:
     // Encode and test for the correct mix of metadata elements on a per-file basis?
     // We should be able to compare the actual returned metadata with the expected metadata
diff --git a/media/tests/contents/media_api/goldenThumbnail.png b/media/tests/contents/media_api/goldenThumbnail.png
new file mode 100755
index 0000000..3bb6ed2
--- /dev/null
+++ b/media/tests/contents/media_api/goldenThumbnail.png
Binary files differ
diff --git a/media/tests/contents/media_api/music/MP3_48KHz_128kbps_s_1_17.mp3 b/media/tests/contents/media_api/music/MP3_48KHz_128kbps_s_1_17.mp3
new file mode 100755
index 0000000..e0d6a17
--- /dev/null
+++ b/media/tests/contents/media_api/music/MP3_48KHz_128kbps_s_1_17.mp3
Binary files differ
diff --git a/media/tests/contents/media_api/music/MP3_48KHz_128kbps_s_1_17_ABR.mp3 b/media/tests/contents/media_api/music/MP3_48KHz_128kbps_s_1_17_ABR.mp3
new file mode 100644
index 0000000..12f7193
--- /dev/null
+++ b/media/tests/contents/media_api/music/MP3_48KHz_128kbps_s_1_17_ABR.mp3
Binary files differ
diff --git a/media/tests/contents/media_api/music/MP3_48KHz_128kbps_s_1_17_CBR.mp3 b/media/tests/contents/media_api/music/MP3_48KHz_128kbps_s_1_17_CBR.mp3
new file mode 100644
index 0000000..12f7193
--- /dev/null
+++ b/media/tests/contents/media_api/music/MP3_48KHz_128kbps_s_1_17_CBR.mp3
Binary files differ
diff --git a/media/tests/contents/media_api/music/MP3_48KHz_128kbps_s_1_17_ID3V1.mp3 b/media/tests/contents/media_api/music/MP3_48KHz_128kbps_s_1_17_ID3V1.mp3
new file mode 100644
index 0000000..29d332b
--- /dev/null
+++ b/media/tests/contents/media_api/music/MP3_48KHz_128kbps_s_1_17_ID3V1.mp3
Binary files differ
diff --git a/media/tests/contents/media_api/music/MP3_48KHz_128kbps_s_1_17_ID3V1_ID3V2.mp3 b/media/tests/contents/media_api/music/MP3_48KHz_128kbps_s_1_17_ID3V1_ID3V2.mp3
new file mode 100644
index 0000000..ea52638
--- /dev/null
+++ b/media/tests/contents/media_api/music/MP3_48KHz_128kbps_s_1_17_ID3V1_ID3V2.mp3
Binary files differ
diff --git a/media/tests/contents/media_api/music/MP3_48KHz_128kbps_s_1_17_ID3V2.mp3 b/media/tests/contents/media_api/music/MP3_48KHz_128kbps_s_1_17_ID3V2.mp3
new file mode 100644
index 0000000..024039c
--- /dev/null
+++ b/media/tests/contents/media_api/music/MP3_48KHz_128kbps_s_1_17_ID3V2.mp3
Binary files differ
diff --git a/media/tests/contents/media_api/music/MP3_48KHz_128kbps_s_1_17_VBR.mp3 b/media/tests/contents/media_api/music/MP3_48KHz_128kbps_s_1_17_VBR.mp3
new file mode 100644
index 0000000..12f7193
--- /dev/null
+++ b/media/tests/contents/media_api/music/MP3_48KHz_128kbps_s_1_17_VBR.mp3
Binary files differ
diff --git a/media/tests/contents/media_api/music/SHORTMP3.mp3 b/media/tests/contents/media_api/music/SHORTMP3.mp3
new file mode 100755
index 0000000..8b51b5d
--- /dev/null
+++ b/media/tests/contents/media_api/music/SHORTMP3.mp3
Binary files differ
diff --git a/media/tests/contents/media_api/music/ants.mid b/media/tests/contents/media_api/music/ants.mid
new file mode 100755
index 0000000..d4ead53
--- /dev/null
+++ b/media/tests/contents/media_api/music/ants.mid
Binary files differ
diff --git a/media/tests/contents/media_api/music/bzk_chic.wav b/media/tests/contents/media_api/music/bzk_chic.wav
new file mode 100755
index 0000000..bab1a6b
--- /dev/null
+++ b/media/tests/contents/media_api/music/bzk_chic.wav
Binary files differ
diff --git a/media/tests/contents/media_api/music/sine_200+1000Hz_44K_mo.wav b/media/tests/contents/media_api/music/sine_200+1000Hz_44K_mo.wav
new file mode 100755
index 0000000..312b6fb
--- /dev/null
+++ b/media/tests/contents/media_api/music/sine_200+1000Hz_44K_mo.wav
Binary files differ
diff --git a/media/tests/contents/media_api/music/test_amr_ietf.amr b/media/tests/contents/media_api/music/test_amr_ietf.amr
new file mode 100755
index 0000000..540794c
--- /dev/null
+++ b/media/tests/contents/media_api/music/test_amr_ietf.amr
Binary files differ
diff --git a/media/tests/contents/media_api/video/big-buck-bunny_trailer.webm b/media/tests/contents/media_api/video/big-buck-bunny_trailer.webm
new file mode 100755
index 0000000..6a17395
--- /dev/null
+++ b/media/tests/contents/media_api/video/big-buck-bunny_trailer.webm
Binary files differ
diff --git a/native/android/native_window.cpp b/native/android/native_window.cpp
index 8d42edb..2c0e88e 100644
--- a/native/android/native_window.cpp
+++ b/native/android/native_window.cpp
@@ -20,12 +20,20 @@
 #include <android/native_window_jni.h>
 #include <surfaceflinger/Surface.h>
 #include <android_runtime/android_view_Surface.h>
+#include <android_runtime/android_graphics_ParcelSurfaceTexture.h>
 #include <android_runtime/android_graphics_SurfaceTexture.h>
 
 using namespace android;
 
 ANativeWindow* ANativeWindow_fromSurface(JNIEnv* env, jobject surface) {
-    sp<ANativeWindow> win = android_Surface_getNativeWindow(env, surface);
+    sp<ANativeWindow> win;
+    if (android_Surface_isInstanceOf(env, surface)) {
+        win = android_Surface_getNativeWindow(env, surface);
+    } else if (android_SurfaceTexture_isInstanceOf(env, surface)) {
+        win = android_SurfaceTexture_getNativeWindow(env, surface);
+    } else if (android_ParcelSurfaceTexture_isInstanceOf(env, surface)) {
+        win = android_ParcelSurfaceTexture_getNativeWindow(env, surface);
+    }
     if (win != NULL) {
         win->incStrong((void*)ANativeWindow_acquire);
     }
diff --git a/native/include/android/configuration.h b/native/include/android/configuration.h
index 39fef21..2444c4b 100644
--- a/native/include/android/configuration.h
+++ b/native/include/android/configuration.h
@@ -40,6 +40,7 @@
     ACONFIGURATION_DENSITY_DEFAULT = 0,
     ACONFIGURATION_DENSITY_LOW = 120,
     ACONFIGURATION_DENSITY_MEDIUM = 160,
+    ACONFIGURATION_DENSITY_TV = 213,
     ACONFIGURATION_DENSITY_HIGH = 240,
     ACONFIGURATION_DENSITY_NONE = 0xffff,
 
diff --git a/nfc-extras/java/com/android/nfc_extras/NfcAdapterExtras.java b/nfc-extras/java/com/android/nfc_extras/NfcAdapterExtras.java
index 6001be9..7775dbf 100644
--- a/nfc-extras/java/com/android/nfc_extras/NfcAdapterExtras.java
+++ b/nfc-extras/java/com/android/nfc_extras/NfcAdapterExtras.java
@@ -207,20 +207,4 @@
     public NfcExecutionEnvironment getEmbeddedExecutionEnvironment() {
         return sEmbeddedEe;
     }
-
-    public void registerTearDownApdus(String packageName, ApduList apdus) {
-        try {
-            sService.registerTearDownApdus(packageName, apdus);
-        } catch (RemoteException e) {
-            attemptDeadServiceRecovery(e);
-        }
-    }
-
-    public void unregisterTearDownApdus(String packageName) {
-        try {
-            sService.unregisterTearDownApdus(packageName);
-        } catch (RemoteException e) {
-            attemptDeadServiceRecovery(e);
-        }
-    }
 }
diff --git a/opengl/java/com/google/android/gles_jni/EGLImpl.java b/opengl/java/com/google/android/gles_jni/EGLImpl.java
index f162d40..51d6ca8 100644
--- a/opengl/java/com/google/android/gles_jni/EGLImpl.java
+++ b/opengl/java/com/google/android/gles_jni/EGLImpl.java
@@ -85,7 +85,7 @@
             eglSurfaceId = _eglCreateWindowSurface(display, config, sur, attrib_list);
         } else if (native_window instanceof SurfaceTexture) {
             eglSurfaceId = _eglCreateWindowSurfaceTexture(display, config,
-                    ((SurfaceTexture) native_window).mSurfaceTexture, attrib_list);
+                    (SurfaceTexture) native_window, attrib_list);
         } else {
             throw new java.lang.UnsupportedOperationException(
                 "eglCreateWindowSurface() can only be called with an instance of " +
@@ -143,7 +143,7 @@
     private native int _eglCreatePbufferSurface(EGLDisplay display, EGLConfig config, int[] attrib_list);
     private native void _eglCreatePixmapSurface(EGLSurface sur, EGLDisplay display, EGLConfig config, Object native_pixmap, int[] attrib_list);
     private native int _eglCreateWindowSurface(EGLDisplay display, EGLConfig config, Object native_window, int[] attrib_list);
-    private native int _eglCreateWindowSurfaceTexture(EGLDisplay display, EGLConfig config, int native_window, int[] attrib_list);
+    private native int _eglCreateWindowSurfaceTexture(EGLDisplay display, EGLConfig config, Object native_window, int[] attrib_list);
     private native int _eglGetDisplay(Object native_display);
     private native int _eglGetCurrentContext();
     private native int _eglGetCurrentDisplay();
diff --git a/packages/BackupRestoreConfirmation/AndroidManifest.xml b/packages/BackupRestoreConfirmation/AndroidManifest.xml
index ed9a519..19848f6 100644
--- a/packages/BackupRestoreConfirmation/AndroidManifest.xml
+++ b/packages/BackupRestoreConfirmation/AndroidManifest.xml
@@ -21,7 +21,7 @@
     <uses-permission android:name="android.permission.BACKUP" />
 
     <application android:allowClearUserData="false"
-                 android:killAfterRestore="false"
+                 android:allowBackup="false"
                  android:permission="android.permission.CONFIRM_FULL_BACKUP" >
 
         <activity android:name=".BackupRestoreConfirmation" 
diff --git a/packages/BackupRestoreConfirmation/res/layout/confirm_backup.xml b/packages/BackupRestoreConfirmation/res/layout/confirm_backup.xml
index 109cfff..a4564e6 100644
--- a/packages/BackupRestoreConfirmation/res/layout/confirm_backup.xml
+++ b/packages/BackupRestoreConfirmation/res/layout/confirm_backup.xml
@@ -37,6 +37,7 @@
               android:layout_marginBottom="30dp" />
 
     <Button android:id="@+id/button_allow"
+            android:filterTouchesWhenObscured="true"
             android:text="@string/allow_backup_button_label"
             android:layout_below="@id/package_name"
             android:layout_height="wrap_content"
diff --git a/packages/BackupRestoreConfirmation/res/layout/confirm_restore.xml b/packages/BackupRestoreConfirmation/res/layout/confirm_restore.xml
index a1f9a4a..ca99ae1 100644
--- a/packages/BackupRestoreConfirmation/res/layout/confirm_restore.xml
+++ b/packages/BackupRestoreConfirmation/res/layout/confirm_restore.xml
@@ -37,6 +37,7 @@
               android:layout_marginBottom="30dp" />
 
     <Button android:id="@+id/button_allow"
+            android:filterTouchesWhenObscured="true"
             android:text="@string/allow_restore_button_label"
             android:layout_below="@id/package_name"
             android:layout_height="wrap_content"
diff --git a/packages/BackupRestoreConfirmation/src/com/android/backupconfirm/BackupRestoreConfirmation.java b/packages/BackupRestoreConfirmation/src/com/android/backupconfirm/BackupRestoreConfirmation.java
index 4b42067..ed413e6 100644
--- a/packages/BackupRestoreConfirmation/src/com/android/backupconfirm/BackupRestoreConfirmation.java
+++ b/packages/BackupRestoreConfirmation/src/com/android/backupconfirm/BackupRestoreConfirmation.java
@@ -60,6 +60,7 @@
     IBackupManager mBackupManager;
     FullObserver mObserver;
     int mToken;
+    boolean mDidAcknowledge;
 
     TextView mStatusView;
     Button mAllowButton;
@@ -70,6 +71,7 @@
         Context mContext;
         ObserverHandler(Context context) {
             mContext = context;
+            mDidAcknowledge = false;
         }
 
         @Override
@@ -98,6 +100,8 @@
                 break;
 
                 case MSG_RESTORE_PACKAGE: {
+                    String name = (String) msg.obj;
+                    mStatusView.setText(name);
                 }
                 break;
 
@@ -155,11 +159,7 @@
         mAllowButton.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
-                try {
-                    mBackupManager.acknowledgeFullBackupOrRestore(mToken, true, mObserver);
-                } catch (RemoteException e) {
-                    // TODO: bail gracefully if we can't contact the backup manager
-                }
+                sendAcknowledgement(mToken, true, mObserver);
                 mAllowButton.setEnabled(false);
                 mDenyButton.setEnabled(false);
             }
@@ -168,11 +168,7 @@
         mDenyButton.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
-                try {
-                    mBackupManager.acknowledgeFullBackupOrRestore(mToken, false, mObserver);
-                } catch (RemoteException e) {
-                    // TODO: bail gracefully if we can't contact the backup manager
-                }
+                sendAcknowledgement(mToken, false, mObserver);
                 mAllowButton.setEnabled(false);
                 mDenyButton.setEnabled(false);
             }
@@ -185,14 +181,21 @@
 
         // We explicitly equate departure from the UI with refusal.  This includes the
         // implicit configuration-changed stop/restart cycle.
-        try {
-            mBackupManager.acknowledgeFullBackupOrRestore(mToken, false, null);
-        } catch (RemoteException e) {
-            // if this fails we'll still time out with no acknowledgment
-        }
+        sendAcknowledgement(mToken, false, null);
         finish();
     }
 
+    void sendAcknowledgement(int token, boolean allow, IFullBackupRestoreObserver observer) {
+        if (!mDidAcknowledge) {
+            mDidAcknowledge = true;
+            try {
+                mBackupManager.acknowledgeFullBackupOrRestore(mToken, true, mObserver);
+            } catch (RemoteException e) {
+                // TODO: bail gracefully if we can't contact the backup manager
+            }
+        }
+    }
+
     /**
      * The observer binder for showing backup/restore progress.  This binder just bounces
      * the notifications onto the main thread.
diff --git a/packages/SettingsProvider/res/values/defaults.xml b/packages/SettingsProvider/res/values/defaults.xml
index bf06f947..b349030 100644
--- a/packages/SettingsProvider/res/values/defaults.xml
+++ b/packages/SettingsProvider/res/values/defaults.xml
@@ -77,8 +77,6 @@
     <!-- Default for Settings.System.VIBRATE_IN_SILENT -->
     <bool name="def_vibrate_in_silent">true</bool>
 
-    <bool name="def_use_ptp_interface">false</bool>
-
     <!-- Default for Settings.Secure.ACCESSIBILITY_SCRIPT_INJECTION -->
     <bool name="def_accessibility_script_injection">false</bool>
 
@@ -125,4 +123,7 @@
     <!-- Default for Settings.Secure.LONG_PRESS_TIMEOUT_MILLIS -->
     <integer name="def_long_press_timeout_millis">500</integer>
 
+    <!-- Default for Settings.System.POINTER_SPEED -->
+    <integer name="def_pointer_speed">0</integer>
+
 </resources>
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java b/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
index b99c8b0..47ab150 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
@@ -17,6 +17,8 @@
 package com.android.providers.settings;
 
 import com.android.internal.content.PackageHelper;
+import com.android.internal.telephony.BaseCommands;
+import com.android.internal.telephony.Phone;
 import com.android.internal.telephony.RILConstants;
 import com.android.internal.util.XmlUtils;
 import com.android.internal.widget.LockPatternUtils;
@@ -1207,13 +1209,13 @@
             loadBooleanSetting(stmt, Settings.System.VIBRATE_IN_SILENT,
                     R.bool.def_vibrate_in_silent);
 
-            loadBooleanSetting(stmt, Settings.System.USE_PTP_INTERFACE,
-                    R.bool.def_use_ptp_interface);
-
             // Set notification volume to follow ringer volume by default
             loadBooleanSetting(stmt, Settings.System.NOTIFICATIONS_USE_RING_VOLUME,
                     R.bool.def_notifications_use_ring_volume);
 
+            loadIntegerSetting(stmt, Settings.System.POINTER_SPEED,
+                    R.integer.def_pointer_speed);
+
         } finally {
             if (stmt != null) stmt.close();
         }
@@ -1297,8 +1299,13 @@
             }
     
             // Set the preferred network mode to 0 = Global, CDMA default
-            int type = SystemProperties.getInt("ro.telephony.default_network",
-                    RILConstants.PREFERRED_NETWORK_MODE);
+            int type;
+            if (BaseCommands.getLteOnCdmaModeStatic() == Phone.LTE_ON_CDMA_TRUE) {
+                type = Phone.NT_MODE_GLOBAL;
+            } else {
+                type = SystemProperties.getInt("ro.telephony.default_network",
+                        RILConstants.PREFERRED_NETWORK_MODE);
+            }
             loadSetting(stmt, Settings.Secure.PREFERRED_NETWORK_MODE, type);
     
             // Enable or disable Cell Broadcast SMS
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java
index 45bb2b6..0c4ef7d 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java
@@ -55,6 +55,7 @@
  */
 public class SettingsBackupAgent extends BackupAgentHelper {
     private static final boolean DEBUG = false;
+    private static final boolean DEBUG_BACKUP = DEBUG || true;
 
     private static final String KEY_SYSTEM = "system";
     private static final String KEY_SECURE = "secure";
@@ -75,6 +76,9 @@
     private static final int STATE_WIFI_CONFIG     = 4;
     private static final int STATE_SIZE            = 5; // The number of state items
 
+    // Versioning of the 'full backup' format
+    private static final int FULL_BACKUP_VERSION = 1;
+
     private static String[] sortedSystemKeys = null;
     private static String[] sortedSecureKeys = null;
 
@@ -109,6 +113,8 @@
     private static String mWifiConfigFile;
 
     public void onCreate() {
+        if (DEBUG_BACKUP) Log.d(TAG, "onCreate() invoked");
+
         mSettingsHelper = new SettingsHelper(this);
         super.onCreate();
 
@@ -151,26 +157,32 @@
             // representation of the backed-up settings.
             String root = getFilesDir().getAbsolutePath();
             File stage = new File(root, STAGE_FILE);
-            FileOutputStream filestream = new FileOutputStream(stage);
-            BufferedOutputStream bufstream = new BufferedOutputStream(filestream);
-            DataOutputStream out = new DataOutputStream(bufstream);
+            try {
+                FileOutputStream filestream = new FileOutputStream(stage);
+                BufferedOutputStream bufstream = new BufferedOutputStream(filestream);
+                DataOutputStream out = new DataOutputStream(bufstream);
 
-            out.writeInt(systemSettingsData.length);
-            out.write(systemSettingsData);
-            out.writeInt(secureSettingsData.length);
-            out.write(secureSettingsData);
-            out.writeInt(locale.length);
-            out.write(locale);
-            out.writeInt(wifiSupplicantData.length);
-            out.write(wifiSupplicantData);
-            out.writeInt(wifiConfigData.length);
-            out.write(wifiConfigData);
+                out.writeInt(FULL_BACKUP_VERSION);
 
-            out.flush();    // also flushes downstream
+                out.writeInt(systemSettingsData.length);
+                out.write(systemSettingsData);
+                out.writeInt(secureSettingsData.length);
+                out.write(secureSettingsData);
+                out.writeInt(locale.length);
+                out.write(locale);
+                out.writeInt(wifiSupplicantData.length);
+                out.write(wifiSupplicantData);
+                out.writeInt(wifiConfigData.length);
+                out.write(wifiConfigData);
 
-            // now we're set to emit the tar stream
-            FullBackup.backupToTar(getPackageName(), FullBackup.DATA_TREE_TOKEN, null,
-                    root, stage.getAbsolutePath(), data);
+                out.flush();    // also flushes downstream
+
+                // now we're set to emit the tar stream
+                FullBackup.backupToTar(getPackageName(), FullBackup.DATA_TREE_TOKEN, null,
+                        root, stage.getAbsolutePath(), data);
+            } finally {
+                stage.delete();
+            }
         }
     }
 
@@ -199,7 +211,7 @@
             } else if (KEY_LOCALE.equals(key)) {
                 byte[] localeData = new byte[size];
                 data.readEntityData(localeData, 0, size);
-                mSettingsHelper.setLocaleData(localeData);
+                mSettingsHelper.setLocaleData(localeData, size);
             } else if (KEY_WIFI_CONFIG.equals(key)) {
                 restoreFileData(mWifiConfigFile, data);
              } else {
@@ -208,6 +220,70 @@
         }
     }
 
+    @Override
+    public void onRestoreFile(ParcelFileDescriptor data, long size,
+            int type, String domain, String relpath, long mode, long mtime)
+            throws IOException {
+        if (DEBUG_BACKUP) Log.d(TAG, "onRestoreFile() invoked");
+        // Our data is actually a blob of flattened settings data identical to that
+        // produced during incremental backups.  Just unpack and apply it all in
+        // turn.
+        FileInputStream instream = new FileInputStream(data.getFileDescriptor());
+        DataInputStream in = new DataInputStream(instream);
+
+        int version = in.readInt();
+        if (DEBUG_BACKUP) Log.d(TAG, "Flattened data version " + version);
+        if (version == FULL_BACKUP_VERSION) {
+            // system settings data first
+            int nBytes = in.readInt();
+            if (DEBUG_BACKUP) Log.d(TAG, nBytes + " bytes of settings data");
+            byte[] buffer = new byte[nBytes];
+            in.read(buffer, 0, nBytes);
+            restoreSettings(buffer, nBytes, Settings.System.CONTENT_URI);
+
+            // secure settings
+            nBytes = in.readInt();
+            if (DEBUG_BACKUP) Log.d(TAG, nBytes + " bytes of secure settings data");
+            if (nBytes > buffer.length) buffer = new byte[nBytes];
+            in.read(buffer, 0, nBytes);
+            restoreSettings(buffer, nBytes, Settings.Secure.CONTENT_URI);
+
+            // locale
+            nBytes = in.readInt();
+            if (DEBUG_BACKUP) Log.d(TAG, nBytes + " bytes of locale data");
+            if (nBytes > buffer.length) buffer = new byte[nBytes];
+            in.read(buffer, 0, nBytes);
+            mSettingsHelper.setLocaleData(buffer, nBytes);
+
+            // wifi supplicant
+            nBytes = in.readInt();
+            if (DEBUG_BACKUP) Log.d(TAG, nBytes + " bytes of wifi supplicant data");
+            if (nBytes > buffer.length) buffer = new byte[nBytes];
+            in.read(buffer, 0, nBytes);
+            int retainedWifiState = enableWifi(false);
+            restoreWifiSupplicant(FILE_WIFI_SUPPLICANT, buffer, nBytes);
+            FileUtils.setPermissions(FILE_WIFI_SUPPLICANT,
+                    FileUtils.S_IRUSR | FileUtils.S_IWUSR |
+                    FileUtils.S_IRGRP | FileUtils.S_IWGRP,
+                    Process.myUid(), Process.WIFI_UID);
+            // retain the previous WIFI state.
+            enableWifi(retainedWifiState == WifiManager.WIFI_STATE_ENABLED ||
+                    retainedWifiState == WifiManager.WIFI_STATE_ENABLING);
+
+            // wifi config
+            nBytes = in.readInt();
+            if (DEBUG_BACKUP) Log.d(TAG, nBytes + " bytes of wifi config data");
+            if (nBytes > buffer.length) buffer = new byte[nBytes];
+            in.read(buffer, 0, nBytes);
+            restoreFileData(mWifiConfigFile, buffer, nBytes);
+
+            if (DEBUG_BACKUP) Log.d(TAG, "Full restore complete.");
+        } else {
+            data.close();
+            throw new IOException("Invalid file schema");
+        }
+    }
+
     private long[] readOldChecksums(ParcelFileDescriptor oldState) throws IOException {
         long[] stateChecksums = new long[STATE_SIZE];
 
@@ -287,6 +363,17 @@
     }
 
     private void restoreSettings(BackupDataInput data, Uri contentUri) {
+        byte[] settings = new byte[data.getDataSize()];
+        try {
+            data.readEntityData(settings, 0, settings.length);
+        } catch (IOException ioe) {
+            Log.e(TAG, "Couldn't read entity data");
+            return;
+        }
+        restoreSettings(settings, settings.length, contentUri);
+    }
+
+    private void restoreSettings(byte[] settings, int bytes, Uri contentUri) {
         if (DEBUG) Log.i(TAG, "restoreSettings: " + contentUri);
         String[] whitelist = null;
         if (contentUri.equals(Settings.Secure.CONTENT_URI)) {
@@ -296,15 +383,8 @@
         }
 
         ContentValues cv = new ContentValues(2);
-        byte[] settings = new byte[data.getDataSize()];
-        try {
-            data.readEntityData(settings, 0, settings.length);
-        } catch (IOException ioe) {
-            Log.e(TAG, "Couldn't read entity data");
-            return;
-        }
         int pos = 0;
-        while (pos < settings.length) {
+        while (pos < bytes) {
             int length = readInt(settings, pos);
             pos += 4;
             String settingName = length > 0? new String(settings, pos, length) : null;
@@ -451,13 +531,16 @@
     private void restoreFileData(String filename, BackupDataInput data) {
         byte[] bytes = new byte[data.getDataSize()];
         if (bytes.length <= 0) return;
+        restoreFileData(filename, bytes, bytes.length);
+    }
+
+    private void restoreFileData(String filename, byte[] bytes, int size) {
         try {
-            data.readEntityData(bytes, 0, bytes.length);
             File file = new File(filename);
             if (file.exists()) file.delete();
 
             OutputStream os = new BufferedOutputStream(new FileOutputStream(filename, true));
-            os.write(bytes);
+            os.write(bytes, 0, size);
             os.close();
         } catch (IOException ioe) {
             Log.w(TAG, "Couldn't restore " + filename);
@@ -506,15 +589,18 @@
     private void restoreWifiSupplicant(String filename, BackupDataInput data) {
         byte[] bytes = new byte[data.getDataSize()];
         if (bytes.length <= 0) return;
+        restoreWifiSupplicant(filename, bytes, bytes.length);
+    }
+
+    private void restoreWifiSupplicant(String filename, byte[] bytes, int size) {
         try {
-            data.readEntityData(bytes, 0, bytes.length);
             File supplicantFile = new File(FILE_WIFI_SUPPLICANT);
             if (supplicantFile.exists()) supplicantFile.delete();
             copyWifiSupplicantTemplate();
 
             OutputStream os = new BufferedOutputStream(new FileOutputStream(filename, true));
             os.write("\n".getBytes());
-            os.write(bytes);
+            os.write(bytes, 0, size);
             os.close();
         } catch (IOException ioe) {
             Log.w(TAG, "Couldn't restore " + filename);
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java
index 0e75fbc..3e7d86a 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java
@@ -147,7 +147,7 @@
      * "ll" is the language code and "cc" is the country code.
      * @param data the locale string in bytes.
      */
-    void setLocaleData(byte[] data) {
+    void setLocaleData(byte[] data, int size) {
         // Check if locale was set by the user:
         Configuration conf = mContext.getResources().getConfiguration();
         Locale loc = conf.locale;
@@ -157,9 +157,9 @@
         if (conf.userSetLocale) return; // Don't change if user set it in the SetupWizard
 
         final String[] availableLocales = mContext.getAssets().getLocales();
-        String localeCode = new String(data);
+        String localeCode = new String(data, 0, size);
         String language = new String(data, 0, 2);
-        String country = data.length > 4 ? new String(data, 3, 2) : "";
+        String country = size > 4 ? new String(data, 3, 2) : "";
         loc = null;
         for (int i = 0; i < availableLocales.length; i++) {
             if (availableLocales[i].equals(localeCode)) {
diff --git a/packages/SharedStorageBackup/Android.mk b/packages/SharedStorageBackup/Android.mk
new file mode 100644
index 0000000..1d4f4da7
--- /dev/null
+++ b/packages/SharedStorageBackup/Android.mk
@@ -0,0 +1,33 @@
+#
+# Copyright (C) 2011 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_PROGUARD_FLAG_FILES := proguard.flags
+
+LOCAL_PACKAGE_NAME := SharedStorageBackup
+LOCAL_CERTIFICATE := platform
+
+include $(BUILD_PACKAGE)
+
+########################
+include $(call all-makefiles-under,$(LOCAL_PATH))
+
diff --git a/packages/SharedStorageBackup/AndroidManifest.xml b/packages/SharedStorageBackup/AndroidManifest.xml
new file mode 100644
index 0000000..258059c
--- /dev/null
+++ b/packages/SharedStorageBackup/AndroidManifest.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+** Copyright 2011, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+**     http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.android.sharedstoragebackup" >
+
+    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+    <uses-permission android:name="android.permission.WRITE_MEDIA_STORAGE" />
+
+    <application android:allowClearUserData="false"
+                 android:permission="android.permission.CONFIRM_FULL_BACKUP"
+                 android:fullBackupAgent=".SharedStorageAgent"
+                 android:allowBackup="false" >
+    </application>
+</manifest>
diff --git a/packages/SharedStorageBackup/proguard.flags b/packages/SharedStorageBackup/proguard.flags
new file mode 100644
index 0000000..f43cb81
--- /dev/null
+++ b/packages/SharedStorageBackup/proguard.flags
@@ -0,0 +1 @@
+-keep class com.android.sharedstoragebackup.SharedStorageAgent
diff --git a/packages/SharedStorageBackup/src/com/android/sharedstoragebackup/SharedStorageAgent.java b/packages/SharedStorageBackup/src/com/android/sharedstoragebackup/SharedStorageAgent.java
new file mode 100644
index 0000000..b02ca2e
--- /dev/null
+++ b/packages/SharedStorageBackup/src/com/android/sharedstoragebackup/SharedStorageAgent.java
@@ -0,0 +1,93 @@
+package com.android.sharedstoragebackup;
+
+import android.app.backup.FullBackup;
+import android.app.backup.FullBackupAgent;
+import android.app.backup.BackupDataInput;
+import android.app.backup.BackupDataOutput;
+import android.content.Context;
+import android.os.Environment;
+import android.os.ParcelFileDescriptor;
+import android.os.storage.StorageManager;
+import android.os.storage.StorageVolume;
+import android.util.Slog;
+
+import java.io.File;
+import java.io.IOException;
+
+public class SharedStorageAgent extends FullBackupAgent {
+    static final String TAG = "SharedStorageAgent";
+    static final boolean DEBUG = true;
+
+    StorageVolume[] mVolumes;
+
+    @Override
+    public void onCreate() {
+        StorageManager mgr = (StorageManager) getSystemService(Context.STORAGE_SERVICE);
+        if (mgr != null) {
+            mVolumes = mgr.getVolumeList();
+        } else {
+            Slog.e(TAG, "Unable to access Storage Manager");
+        }
+    }
+
+    @Override
+    public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
+            ParcelFileDescriptor newState) throws IOException {
+        // If there are shared-storage volumes available, run the inherited directory-
+        // hierarchy backup process on them.  By convention in the Storage Manager, the
+        // "primary" shared storage volume is first in the list.
+        if (mVolumes != null) {
+            for (int i = 0; i < mVolumes.length; i++) {
+                StorageVolume v = mVolumes[i];
+                // Express the contents of volume N this way in the tar stream:
+                //     shared/N/path/to/file
+                // The restore will then extract to the given volume
+                String domain = FullBackup.SHARED_PREFIX + i;
+                processTree(null, domain, v.getPath(), null, data);
+            }
+        }
+    }
+
+    /**
+     * Incremental onRestore() implementation is not used.
+     */
+    @Override
+    public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState)
+            throws IOException {
+    }
+
+    /**
+     * Full restore of one file to shared storage
+     */
+    @Override
+    public void onRestoreFile(ParcelFileDescriptor data, long size,
+            int type, String domain, String relpath, long mode, long mtime)
+            throws IOException {
+        Slog.d(TAG, "Shared restore: [ " + domain + " : " + relpath + "]");
+
+        File outFile = null;
+
+        // The file path must be in the semantic form [number]/path/to/file...
+        int slash = relpath.indexOf('/');
+        if (slash > 0) {
+            try {
+                int i = Integer.parseInt(relpath.substring(0, slash));
+                if (i <= mVolumes.length) {
+                    outFile = new File(mVolumes[i].getPath(), relpath.substring(slash + 1));
+                    if (DEBUG) Slog.i(TAG, " => " + outFile.getAbsolutePath());
+                } else {
+                    Slog.w(TAG, "Cannot restore data for unavailable volume " + i);
+                }
+            } catch (NumberFormatException e) {
+                if (DEBUG) Slog.w(TAG, "Bad volume number token: " + relpath.substring(0, slash));
+            }
+        } else {
+            if (DEBUG) Slog.i(TAG, "Can't find volume-number token");
+        }
+        if (outFile == null) {
+            Slog.e(TAG, "Skipping data with malformed path " + relpath);
+        }
+
+        FullBackup.restoreToFile(data, size, type, mode, mtime, outFile, false);
+    }
+}
diff --git a/packages/SystemUI/AndroidManifest.xml b/packages/SystemUI/AndroidManifest.xml
index bbe146d6..6d8eab6 100644
--- a/packages/SystemUI/AndroidManifest.xml
+++ b/packages/SystemUI/AndroidManifest.xml
@@ -25,6 +25,10 @@
             android:exported="true"
             />
 
+        <activity android:name=".usb.UsbPreferenceActivity"
+             android:theme="@*android:style/Theme.Holo.Dialog.Alert"
+             android:excludeFromRecents="true">
+        </activity>
         <activity android:name=".usb.UsbStorageActivity"
                 android:excludeFromRecents="true">
         </activity>
@@ -33,13 +37,6 @@
                 android:excludeFromRecents="true">
         </activity>
 
-        <activity android:name=".recent.RecentApplicationsActivity"
-            android:theme="@android:style/Theme.NoTitleBar"
-            android:excludeFromRecents="true"
-            android:launchMode="singleInstance"
-            android:exported="true">
-        </activity>
-
         <!-- started from UsbDeviceSettingsManager -->
         <activity android:name=".usb.UsbConfirmActivity"
             android:exported="true"
diff --git a/packages/SystemUI/res/drawable-hdpi/compat_mode_help_diagram.png b/packages/SystemUI/res/drawable-hdpi/compat_mode_help_diagram.png
new file mode 100644
index 0000000..944b1f0
--- /dev/null
+++ b/packages/SystemUI/res/drawable-hdpi/compat_mode_help_diagram.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-hdpi/compat_mode_help_divider_bottom.9.png b/packages/SystemUI/res/drawable-hdpi/compat_mode_help_divider_bottom.9.png
new file mode 100644
index 0000000..2e11928
--- /dev/null
+++ b/packages/SystemUI/res/drawable-hdpi/compat_mode_help_divider_bottom.9.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-hdpi/compat_mode_help_divider_top.9.png b/packages/SystemUI/res/drawable-hdpi/compat_mode_help_divider_top.9.png
new file mode 100644
index 0000000..58a78b7
--- /dev/null
+++ b/packages/SystemUI/res/drawable-hdpi/compat_mode_help_divider_top.9.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-hdpi/compat_mode_help_icon.png b/packages/SystemUI/res/drawable-hdpi/compat_mode_help_icon.png
new file mode 100644
index 0000000..46bb891
--- /dev/null
+++ b/packages/SystemUI/res/drawable-hdpi/compat_mode_help_icon.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-hdpi/compat_mode_help_top_divider.9.png b/packages/SystemUI/res/drawable-hdpi/compat_mode_help_top_divider.9.png
new file mode 100644
index 0000000..03a5639
--- /dev/null
+++ b/packages/SystemUI/res/drawable-hdpi/compat_mode_help_top_divider.9.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-hdpi/ic_sysbar_ime_default.png b/packages/SystemUI/res/drawable-hdpi/ic_sysbar_ime_default.png
deleted file mode 100644
index eb6eb0c..0000000
--- a/packages/SystemUI/res/drawable-hdpi/ic_sysbar_ime_default.png
+++ /dev/null
Binary files differ
diff --git a/packages/SystemUI/res/drawable-hdpi/ic_sysbar_ime_pressed.png b/packages/SystemUI/res/drawable-hdpi/ic_sysbar_ime_pressed.png
deleted file mode 100644
index 11f66f5..0000000
--- a/packages/SystemUI/res/drawable-hdpi/ic_sysbar_ime_pressed.png
+++ /dev/null
Binary files differ
diff --git a/packages/SystemUI/res/drawable-hdpi/recents_thumbnail_bg.png b/packages/SystemUI/res/drawable-hdpi/recents_thumbnail_bg.png
index 87a67c9..23aabce 100644
--- a/packages/SystemUI/res/drawable-hdpi/recents_thumbnail_bg.png
+++ b/packages/SystemUI/res/drawable-hdpi/recents_thumbnail_bg.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-hdpi/recents_thumbnail_bg_press.png b/packages/SystemUI/res/drawable-hdpi/recents_thumbnail_bg_press.png
new file mode 100644
index 0000000..0b0765b
--- /dev/null
+++ b/packages/SystemUI/res/drawable-hdpi/recents_thumbnail_bg_press.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-large-hdpi/app_icon.png b/packages/SystemUI/res/drawable-large-hdpi/app_icon.png
deleted file mode 100644
index aedf7e7..0000000
--- a/packages/SystemUI/res/drawable-large-hdpi/app_icon.png
+++ /dev/null
Binary files differ
diff --git a/packages/SystemUI/res/drawable-large-mdpi/app_icon.png b/packages/SystemUI/res/drawable-large-mdpi/app_icon.png
deleted file mode 100644
index 50a8ac8..0000000
--- a/packages/SystemUI/res/drawable-large-mdpi/app_icon.png
+++ /dev/null
Binary files differ
diff --git a/packages/SystemUI/res/drawable-mdpi/compat_mode_help_diagram.png b/packages/SystemUI/res/drawable-mdpi/compat_mode_help_diagram.png
new file mode 100644
index 0000000..518a5c1
--- /dev/null
+++ b/packages/SystemUI/res/drawable-mdpi/compat_mode_help_diagram.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-mdpi/compat_mode_help_divider_bottom.9.png b/packages/SystemUI/res/drawable-mdpi/compat_mode_help_divider_bottom.9.png
new file mode 100644
index 0000000..3712abf
--- /dev/null
+++ b/packages/SystemUI/res/drawable-mdpi/compat_mode_help_divider_bottom.9.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-mdpi/compat_mode_help_divider_top.9.png b/packages/SystemUI/res/drawable-mdpi/compat_mode_help_divider_top.9.png
new file mode 100644
index 0000000..a4d08c8
--- /dev/null
+++ b/packages/SystemUI/res/drawable-mdpi/compat_mode_help_divider_top.9.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-mdpi/compat_mode_help_icon.png b/packages/SystemUI/res/drawable-mdpi/compat_mode_help_icon.png
new file mode 100644
index 0000000..233c4df
--- /dev/null
+++ b/packages/SystemUI/res/drawable-mdpi/compat_mode_help_icon.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-mdpi/ic_sysbar_ime_default.png b/packages/SystemUI/res/drawable-mdpi/ic_sysbar_ime_default.png
deleted file mode 100644
index f907de7..0000000
--- a/packages/SystemUI/res/drawable-mdpi/ic_sysbar_ime_default.png
+++ /dev/null
Binary files differ
diff --git a/packages/SystemUI/res/drawable-mdpi/ic_sysbar_ime_pressed.png b/packages/SystemUI/res/drawable-mdpi/ic_sysbar_ime_pressed.png
deleted file mode 100644
index 36f8853..0000000
--- a/packages/SystemUI/res/drawable-mdpi/ic_sysbar_ime_pressed.png
+++ /dev/null
Binary files differ
diff --git a/packages/SystemUI/res/drawable-mdpi/recents_thumbnail_bg.png b/packages/SystemUI/res/drawable-mdpi/recents_thumbnail_bg.png
index 87a67c9..23aabce 100644
--- a/packages/SystemUI/res/drawable-mdpi/recents_thumbnail_bg.png
+++ b/packages/SystemUI/res/drawable-mdpi/recents_thumbnail_bg.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-mdpi/recents_thumbnail_bg_press.png b/packages/SystemUI/res/drawable-mdpi/recents_thumbnail_bg_press.png
index a1c39e6..0b0765b 100644
--- a/packages/SystemUI/res/drawable-mdpi/recents_thumbnail_bg_press.png
+++ b/packages/SystemUI/res/drawable-mdpi/recents_thumbnail_bg_press.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-nodpi/compat_mode_help_bg.png b/packages/SystemUI/res/drawable-nodpi/compat_mode_help_bg.png
new file mode 100644
index 0000000..59a70ff
--- /dev/null
+++ b/packages/SystemUI/res/drawable-nodpi/compat_mode_help_bg.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-sw600dp-hdpi/ic_sysbar_ime_default.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/ic_sysbar_ime_default.png
new file mode 100644
index 0000000..1a9d88c
--- /dev/null
+++ b/packages/SystemUI/res/drawable-sw600dp-hdpi/ic_sysbar_ime_default.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-sw600dp-hdpi/ic_sysbar_ime_pressed.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/ic_sysbar_ime_pressed.png
new file mode 100644
index 0000000..a6d7507
--- /dev/null
+++ b/packages/SystemUI/res/drawable-sw600dp-hdpi/ic_sysbar_ime_pressed.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-sw600dp-hdpi/ic_sysbar_zoom_default.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/ic_sysbar_zoom_default.png
new file mode 100644
index 0000000..1e1324a
--- /dev/null
+++ b/packages/SystemUI/res/drawable-sw600dp-hdpi/ic_sysbar_zoom_default.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-sw600dp-hdpi/ic_sysbar_zoom_pressed.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/ic_sysbar_zoom_pressed.png
new file mode 100644
index 0000000..e4e13c5
--- /dev/null
+++ b/packages/SystemUI/res/drawable-sw600dp-hdpi/ic_sysbar_zoom_pressed.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-large-hdpi/recents_bg_protect_tile.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/recents_bg_protect_tile.png
similarity index 100%
rename from packages/SystemUI/res/drawable-large-hdpi/recents_bg_protect_tile.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/recents_bg_protect_tile.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_1x.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_1x.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_1x.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_1x.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_3g.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_3g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_3g.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_3g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_4g.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_4g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_4g.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_4g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_e.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_e.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_e.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_e.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_g.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_g.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_h.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_h.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_h.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_h.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_in_1x.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_in_1x.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_in_1x.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_in_1x.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_in_3g.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_in_3g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_in_3g.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_in_3g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_in_4g.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_in_4g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_in_4g.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_in_4g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_in_e.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_in_e.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_in_e.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_in_e.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_in_g.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_in_g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_in_g.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_in_g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_in_h.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_in_h.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_in_h.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_in_h.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_inandout_1x.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_inandout_1x.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_inandout_1x.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_inandout_1x.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_inandout_3g.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_inandout_3g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_inandout_3g.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_inandout_3g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_inandout_4g.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_inandout_4g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_inandout_4g.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_inandout_4g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_inandout_e.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_inandout_e.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_inandout_e.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_inandout_e.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_inandout_g.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_inandout_g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_inandout_g.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_inandout_g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_inandout_h.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_inandout_h.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_inandout_h.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_inandout_h.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_out_1x.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_out_1x.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_out_1x.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_out_1x.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_out_3g.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_out_3g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_out_3g.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_out_3g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_out_4g.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_out_4g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_out_4g.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_out_4g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_out_e.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_out_e.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_out_e.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_out_e.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_out_g.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_out_g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_out_g.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_out_g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_out_h.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_out_h.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_out_h.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_out_h.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_roam.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_roam.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_connected_roam.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_connected_roam.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_connected_1x.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_connected_1x.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_connected_1x.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_connected_1x.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_connected_3g.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_connected_3g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_connected_3g.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_connected_3g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_connected_4g.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_connected_4g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_connected_4g.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_connected_4g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_connected_e.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_connected_e.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_connected_e.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_connected_e.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_connected_g.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_connected_g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_connected_g.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_connected_g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_connected_h.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_connected_h.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_connected_h.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_connected_h.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_in_1x.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_in_1x.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_in_1x.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_in_1x.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_in_3g.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_in_3g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_in_3g.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_in_3g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_in_4g.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_in_4g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_in_4g.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_in_4g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_in_e.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_in_e.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_in_e.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_in_e.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_in_g.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_in_g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_in_g.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_in_g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_in_h.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_in_h.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_in_h.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_in_h.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_inandout_1x.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_inandout_1x.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_inandout_1x.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_inandout_1x.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_inandout_3g.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_inandout_3g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_inandout_3g.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_inandout_3g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_inandout_4g.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_inandout_4g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_inandout_4g.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_inandout_4g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_inandout_e.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_inandout_e.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_inandout_e.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_inandout_e.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_inandout_g.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_inandout_g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_inandout_g.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_inandout_g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_inandout_h.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_inandout_h.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_inandout_h.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_inandout_h.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_out_1x.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_out_1x.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_out_1x.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_out_1x.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_out_3g.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_out_3g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_out_3g.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_out_3g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_out_4g.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_out_4g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_out_4g.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_out_4g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_out_e.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_out_e.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_out_e.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_out_e.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_out_g.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_out_g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_out_g.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_out_g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_out_h.png b/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_out_h.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-hdpi/stat_sys_data_fully_out_h.png
rename to packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_data_fully_out_h.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-sw600dp-mdpi/ic_sysbar_ime_default.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/ic_sysbar_ime_default.png
new file mode 100644
index 0000000..33edce0
--- /dev/null
+++ b/packages/SystemUI/res/drawable-sw600dp-mdpi/ic_sysbar_ime_default.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-sw600dp-mdpi/ic_sysbar_ime_pressed.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/ic_sysbar_ime_pressed.png
new file mode 100644
index 0000000..8bab6cf
--- /dev/null
+++ b/packages/SystemUI/res/drawable-sw600dp-mdpi/ic_sysbar_ime_pressed.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-sw600dp-mdpi/ic_sysbar_zoom_default.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/ic_sysbar_zoom_default.png
new file mode 100644
index 0000000..89d486f
--- /dev/null
+++ b/packages/SystemUI/res/drawable-sw600dp-mdpi/ic_sysbar_zoom_default.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-sw600dp-mdpi/ic_sysbar_zoom_pressed.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/ic_sysbar_zoom_pressed.png
new file mode 100644
index 0000000..b134436
--- /dev/null
+++ b/packages/SystemUI/res/drawable-sw600dp-mdpi/ic_sysbar_zoom_pressed.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-large-mdpi/recents_bg_protect_tile.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/recents_bg_protect_tile.png
similarity index 100%
rename from packages/SystemUI/res/drawable-large-mdpi/recents_bg_protect_tile.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/recents_bg_protect_tile.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-large-mdpi/recents_blue_glow.9.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/recents_blue_glow.9.png
similarity index 100%
rename from packages/SystemUI/res/drawable-large-mdpi/recents_blue_glow.9.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/recents_blue_glow.9.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-large-mdpi/recents_callout_line.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/recents_callout_line.png
similarity index 100%
rename from packages/SystemUI/res/drawable-large-mdpi/recents_callout_line.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/recents_callout_line.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-large-mdpi/recents_thumbnail_bg.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/recents_thumbnail_bg.png
similarity index 100%
rename from packages/SystemUI/res/drawable-large-mdpi/recents_thumbnail_bg.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/recents_thumbnail_bg.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-large-mdpi/recents_thumbnail_bg_press.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/recents_thumbnail_bg_press.png
similarity index 100%
rename from packages/SystemUI/res/drawable-large-mdpi/recents_thumbnail_bg_press.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/recents_thumbnail_bg_press.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_1x.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_1x.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_1x.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_1x.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_3g.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_3g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_3g.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_3g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_4g.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_4g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_4g.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_4g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_e.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_e.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_e.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_e.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_g.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_g.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_h.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_h.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_h.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_h.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_in_1x.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_in_1x.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_in_1x.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_in_1x.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_in_3g.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_in_3g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_in_3g.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_in_3g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_in_4g.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_in_4g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_in_4g.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_in_4g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_in_e.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_in_e.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_in_e.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_in_e.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_in_g.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_in_g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_in_g.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_in_g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_in_h.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_in_h.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_in_h.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_in_h.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_inandout_1x.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_inandout_1x.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_inandout_1x.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_inandout_1x.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_inandout_3g.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_inandout_3g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_inandout_3g.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_inandout_3g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_inandout_4g.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_inandout_4g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_inandout_4g.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_inandout_4g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_inandout_e.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_inandout_e.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_inandout_e.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_inandout_e.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_inandout_g.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_inandout_g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_inandout_g.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_inandout_g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_inandout_h.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_inandout_h.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_inandout_h.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_inandout_h.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_out_1x.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_out_1x.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_out_1x.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_out_1x.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_out_3g.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_out_3g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_out_3g.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_out_3g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_out_4g.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_out_4g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_out_4g.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_out_4g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_out_e.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_out_e.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_out_e.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_out_e.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_out_g.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_out_g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_out_g.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_out_g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_out_h.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_out_h.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_out_h.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_out_h.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_roam.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_roam.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_connected_roam.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_connected_roam.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_connected_1x.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_connected_1x.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_connected_1x.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_connected_1x.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_connected_3g.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_connected_3g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_connected_3g.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_connected_3g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_connected_4g.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_connected_4g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_connected_4g.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_connected_4g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_connected_e.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_connected_e.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_connected_e.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_connected_e.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_connected_g.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_connected_g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_connected_g.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_connected_g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_connected_h.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_connected_h.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_connected_h.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_connected_h.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_in_1x.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_in_1x.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_in_1x.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_in_1x.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_in_3g.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_in_3g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_in_3g.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_in_3g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_in_4g.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_in_4g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_in_4g.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_in_4g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_in_e.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_in_e.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_in_e.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_in_e.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_in_g.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_in_g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_in_g.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_in_g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_in_h.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_in_h.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_in_h.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_in_h.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_inandout_1x.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_inandout_1x.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_inandout_1x.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_inandout_1x.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_inandout_3g.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_inandout_3g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_inandout_3g.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_inandout_3g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_inandout_4g.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_inandout_4g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_inandout_4g.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_inandout_4g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_inandout_e.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_inandout_e.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_inandout_e.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_inandout_e.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_inandout_g.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_inandout_g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_inandout_g.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_inandout_g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_inandout_h.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_inandout_h.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_inandout_h.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_inandout_h.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_out_1x.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_out_1x.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_out_1x.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_out_1x.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_out_3g.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_out_3g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_out_3g.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_out_3g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_out_4g.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_out_4g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_out_4g.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_out_4g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_out_e.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_out_e.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_out_e.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_out_e.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_out_g.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_out_g.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_out_g.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_out_g.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_out_h.png b/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_out_h.png
similarity index 100%
rename from packages/SystemUI/res/drawable-xlarge-mdpi/stat_sys_data_fully_out_h.png
rename to packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_data_fully_out_h.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/app_icon.png b/packages/SystemUI/res/drawable-xlarge-hdpi/app_icon.png
deleted file mode 100644
index aedf7e7..0000000
--- a/packages/SystemUI/res/drawable-xlarge-hdpi/app_icon.png
+++ /dev/null
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-hdpi/recents_bg_protect_tile.png b/packages/SystemUI/res/drawable-xlarge-hdpi/recents_bg_protect_tile.png
deleted file mode 100644
index a57c27a..0000000
--- a/packages/SystemUI/res/drawable-xlarge-hdpi/recents_bg_protect_tile.png
+++ /dev/null
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/app_icon.png b/packages/SystemUI/res/drawable-xlarge-mdpi/app_icon.png
deleted file mode 100644
index 50a8ac8..0000000
--- a/packages/SystemUI/res/drawable-xlarge-mdpi/app_icon.png
+++ /dev/null
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/recents_bg_protect_tile.png b/packages/SystemUI/res/drawable-xlarge-mdpi/recents_bg_protect_tile.png
deleted file mode 100644
index 87c7be6..0000000
--- a/packages/SystemUI/res/drawable-xlarge-mdpi/recents_bg_protect_tile.png
+++ /dev/null
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/recents_blue_glow.9.png b/packages/SystemUI/res/drawable-xlarge-mdpi/recents_blue_glow.9.png
deleted file mode 100644
index 4f4ae78..0000000
--- a/packages/SystemUI/res/drawable-xlarge-mdpi/recents_blue_glow.9.png
+++ /dev/null
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/recents_callout_line.png b/packages/SystemUI/res/drawable-xlarge-mdpi/recents_callout_line.png
deleted file mode 100644
index 5f4c035..0000000
--- a/packages/SystemUI/res/drawable-xlarge-mdpi/recents_callout_line.png
+++ /dev/null
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/recents_thumbnail_bg.png b/packages/SystemUI/res/drawable-xlarge-mdpi/recents_thumbnail_bg.png
deleted file mode 100644
index 87a67c9..0000000
--- a/packages/SystemUI/res/drawable-xlarge-mdpi/recents_thumbnail_bg.png
+++ /dev/null
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xlarge-mdpi/recents_thumbnail_bg_press.png b/packages/SystemUI/res/drawable-xlarge-mdpi/recents_thumbnail_bg_press.png
deleted file mode 100644
index a1c39e6..0000000
--- a/packages/SystemUI/res/drawable-xlarge-mdpi/recents_thumbnail_bg_press.png
+++ /dev/null
Binary files differ
diff --git a/packages/SystemUI/res/drawable/compat_mode_help_bg.png b/packages/SystemUI/res/drawable/compat_mode_help_bg.png
new file mode 100644
index 0000000..87d8c41
--- /dev/null
+++ b/packages/SystemUI/res/drawable/compat_mode_help_bg.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable/ic_sysbar_zoom.xml b/packages/SystemUI/res/drawable/ic_sysbar_zoom.xml
new file mode 100644
index 0000000..97d0348
--- /dev/null
+++ b/packages/SystemUI/res/drawable/ic_sysbar_zoom.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+    <item android:state_pressed="true" android:drawable="@drawable/ic_sysbar_zoom_pressed" />
+    <item android:state_selected="true" android:drawable="@drawable/ic_sysbar_zoom_pressed" />
+    <item android:drawable="@drawable/ic_sysbar_zoom_default" />
+</selector>
+
diff --git a/packages/SystemUI/res/layout-land/status_bar_recent_item.xml b/packages/SystemUI/res/layout-land/status_bar_recent_item.xml
index ce72f04..be4f1d7 100644
--- a/packages/SystemUI/res/layout-land/status_bar_recent_item.xml
+++ b/packages/SystemUI/res/layout-land/status_bar_recent_item.xml
@@ -39,8 +39,8 @@
         android:layout_height="wrap_content"
         android:layout_alignLeft="@id/app_thumbnail"
         android:layout_alignTop="@id/app_thumbnail"
-        android:layout_marginLeft="@dimen/status_bar_recents_thumbnail_border_width"
-        android:layout_marginTop="@dimen/status_bar_recents_thumbnail_border_height"
+        android:layout_marginTop="@dimen/status_bar_recents_app_icon_top_margin"
+        android:layout_marginLeft="@dimen/status_bar_recents_app_icon_left_margin"
         android:maxWidth="@dimen/status_bar_recents_thumbnail_max_width"
         android:maxHeight="@dimen/status_bar_recents_thumbnail_max_height"
         android:adjustViewBounds="true"
@@ -56,7 +56,7 @@
         android:layout_alignLeft="@id/app_thumbnail"
         android:layout_below="@id/app_thumbnail"
         android:layout_marginTop="@dimen/status_bar_recents_text_description_padding"
-        android:layout_marginLeft="@dimen/status_bar_recents_thumbnail_border_width"
+        android:layout_marginLeft="@dimen/recents_thumbnail_bg_padding_left"
         android:singleLine="true"
         android:ellipsize="marquee"
     />
@@ -71,7 +71,7 @@
         android:layout_alignLeft="@id/app_thumbnail"
         android:layout_below="@id/app_label"
         android:layout_marginTop="@dimen/status_bar_recents_text_description_padding"
-        android:layout_marginLeft="@dimen/status_bar_recents_thumbnail_border_width"
+        android:layout_marginLeft="@dimen/recents_thumbnail_bg_padding_left"
         android:singleLine="true"
         android:ellipsize="marquee"
     />
diff --git a/packages/SystemUI/res/layout-land/status_bar_recent_panel.xml b/packages/SystemUI/res/layout-land/status_bar_recent_panel.xml
index 75f5ee4..4a80489 100644
--- a/packages/SystemUI/res/layout-land/status_bar_recent_panel.xml
+++ b/packages/SystemUI/res/layout-land/status_bar_recent_panel.xml
@@ -27,10 +27,9 @@
     <FrameLayout
         android:id="@+id/recents_bg_protect"
         android:background="@drawable/recents_bg_protect_tile"
-        android:layout_width="wrap_content"
+        android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:layout_alignParentBottom="true"
-        android:layout_alignParentRight="true"
         android:paddingBottom="@*android:dimen/status_bar_height"
         android:clipToPadding="false"
         android:clipChildren="false">
diff --git a/packages/SystemUI/res/layout-port/status_bar_recent_item.xml b/packages/SystemUI/res/layout-port/status_bar_recent_item.xml
new file mode 100644
index 0000000..76965c9
--- /dev/null
+++ b/packages/SystemUI/res/layout-port/status_bar_recent_item.xml
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/* apps/common/assets/default/default/skins/StatusBar.xml
+**
+** Copyright 2006, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+**     http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+-->
+
+<!--    android:background="@drawable/status_bar_closed_default_background" -->
+<RelativeLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_height="wrap_content"
+    android:layout_width="@dimen/status_bar_recents_thumbnail_view_width">
+
+    <ImageView android:id="@+id/app_thumbnail"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentLeft="true"
+        android:layout_alignParentTop="true"
+        android:layout_marginLeft="@dimen/status_bar_recents_thumbnail_left_margin"
+        android:scaleType="center"
+    />
+
+    <ImageView android:id="@+id/app_icon"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignLeft="@id/app_thumbnail"
+        android:layout_alignTop="@id/app_thumbnail"
+        android:layout_marginLeft="@dimen/status_bar_recents_app_icon_left_margin"
+        android:layout_marginTop="@dimen/status_bar_recents_app_icon_top_margin"
+        android:maxWidth="@dimen/status_bar_recents_thumbnail_max_width"
+        android:maxHeight="@dimen/status_bar_recents_thumbnail_max_height"
+        android:adjustViewBounds="true"
+    />
+
+    <TextView android:id="@+id/app_label"
+        android:layout_width="@dimen/status_bar_recents_app_label_width"
+        android:layout_height="wrap_content"
+        android:textSize="@dimen/status_bar_recents_app_label_text_size"
+        android:fadingEdge="horizontal"
+        android:fadingEdgeLength="@dimen/status_bar_recents_fading_edge_length"
+        android:scrollHorizontally="true"
+        android:layout_alignParentLeft="true"
+        android:layout_alignTop="@id/app_icon"
+        android:layout_marginLeft="@dimen/status_bar_recents_app_label_left_margin"
+        android:singleLine="true"
+        android:ellipsize="marquee"
+    />
+
+    <View android:id="@+id/recents_callout_line"
+        android:layout_width="@dimen/status_bar_recents_app_label_width"
+        android:layout_height="1dip"
+        android:layout_alignParentLeft="true"
+        android:layout_marginLeft="@dimen/status_bar_recents_app_label_left_margin"
+        android:layout_toLeftOf="@id/app_thumbnail"
+        android:layout_below="@id/app_label"
+        android:layout_marginRight="3dip"
+        android:layout_marginTop="3dip"
+        android:background="@drawable/recents_callout_line"
+    />
+
+    <TextView android:id="@+id/app_description"
+        android:layout_width="@dimen/status_bar_recents_app_label_width"
+        android:layout_height="wrap_content"
+        android:textSize="@dimen/status_bar_recents_app_description_text_size"
+        android:fadingEdge="horizontal"
+        android:fadingEdgeLength="@dimen/status_bar_recents_fading_edge_length"
+        android:scrollHorizontally="true"
+        android:layout_alignParentLeft="true"
+        android:layout_marginLeft="@dimen/status_bar_recents_app_label_left_margin"
+        android:layout_below="@id/recents_callout_line"
+        android:layout_marginTop="3dip"
+        android:singleLine="true"
+        android:ellipsize="marquee"
+    />
+
+</RelativeLayout>
diff --git a/packages/SystemUI/res/layout-port/status_bar_recent_panel.xml b/packages/SystemUI/res/layout-port/status_bar_recent_panel.xml
new file mode 100644
index 0000000..9391f9d
--- /dev/null
+++ b/packages/SystemUI/res/layout-port/status_bar_recent_panel.xml
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/* apps/common/assets/default/default/skins/StatusBar.xml
+**
+** Copyright 2010, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+**     http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+-->
+
+<com.android.systemui.recent.RecentsPanelView
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/recents_root"
+    android:layout_height="match_parent"
+    android:layout_width="match_parent">
+
+    <FrameLayout
+        android:id="@+id/recents_bg_protect"
+        android:background="@drawable/recents_bg_protect_tile"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:layout_alignParentBottom="true"
+        android:paddingBottom="@*android:dimen/status_bar_height"
+        android:clipToPadding="false"
+        android:clipChildren="false">
+
+        <LinearLayout android:id="@+id/recents_glow"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginBottom="0dp"
+            android:layout_gravity="bottom"
+            android:background="@drawable/recents_blue_glow"
+            android:orientation="horizontal"
+            android:clipToPadding="false"
+            android:clipChildren="false"
+            >
+            <com.android.systemui.recent.RecentsVerticalScrollView android:id="@+id/recents_container"
+                android:layout_width="@dimen/status_bar_recents_width"
+                android:layout_height="wrap_content"
+                android:layout_marginRight="0dp"
+                android:divider="@null"
+                android:stackFromBottom="true"
+                android:fadingEdge="vertical"
+                android:scrollbars="none"
+                android:fadingEdgeLength="20dip"
+                android:listSelector="@drawable/recents_thumbnail_bg_selector"
+                android:layout_gravity="bottom|left"
+                android:clipToPadding="false"
+                android:clipChildren="false">
+
+                <LinearLayout android:id="@+id/recents_linear_layout"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:orientation="vertical"
+                    android:clipToPadding="false"
+                    android:clipChildren="false">
+                </LinearLayout>
+
+            </com.android.systemui.recent.RecentsVerticalScrollView>
+
+
+        </LinearLayout>
+
+    </FrameLayout>
+
+    <View android:id="@+id/recents_dismiss_button"
+        android:layout_width="80px"
+        android:layout_height="@*android:dimen/status_bar_height"
+        android:layout_alignParentBottom="true"
+        android:layout_alignParentLeft="true"
+        android:background="@drawable/ic_sysbar_back_ime"
+    />
+
+</com.android.systemui.recent.RecentsPanelView>
diff --git a/packages/SystemUI/res/layout-sw600dp/compat_mode_help.xml b/packages/SystemUI/res/layout-sw600dp/compat_mode_help.xml
new file mode 100644
index 0000000..d29e495
--- /dev/null
+++ b/packages/SystemUI/res/layout-sw600dp/compat_mode_help.xml
@@ -0,0 +1,90 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+** Copyright 2011, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License"); 
+** you may not use this file except in compliance with the License. 
+** You may obtain a copy of the License at 
+**
+**     http://www.apache.org/licenses/LICENSE-2.0 
+**
+** Unless required by applicable law or agreed to in writing, software 
+** distributed under the License is distributed on an "AS IS" BASIS, 
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+** See the License for the specific language governing permissions and 
+** limitations under the License.
+*/
+-->
+
+<RelativeLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_height="match_parent"
+    android:layout_width="match_parent"
+    android:background="@drawable/compat_mode_help_bg"
+    >
+    <TextView
+        android:id="@+id/header"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_marginLeft="80dp"
+        android:layout_marginTop="80dp"
+        android:layout_marginRight="80dp"
+        android:textSize="60sp"
+        android:maxLines="1"
+        android:shadowRadius="8"
+        android:shadowColor="#FF000000"
+        android:text="@string/compat_mode_help_header"
+        android:background="@drawable/compat_mode_help_divider_top"
+        />
+    <ImageView
+        android:id="@+id/diagram"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_centerInParent="true"
+        android:src="@drawable/compat_mode_help_diagram"
+        />
+    <RelativeLayout
+        android:orientation="horizontal"
+        android:layout_width="match_parent"
+        android:layout_height="190dp"
+        android:background="@drawable/compat_mode_help_divider_bottom"
+        android:layout_marginBottom="55dp"
+        android:layout_marginRight="80dp"
+        android:layout_alignLeft="@id/header"
+        android:layout_alignParentBottom="true"
+        >
+        <ImageView
+            android:id="@+id/icon"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_alignParentRight="true"
+            android:layout_centerVertical="true"
+            android:src="@drawable/compat_mode_help_icon"
+            />
+        <TextView
+            android:id="@+id/explanation"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_centerVertical="true"
+            android:layout_alignParentLeft="true"
+            android:layout_toLeftOf="@id/icon"
+            android:layout_marginRight="10dp"
+            android:shadowRadius="4"
+            android:shadowColor="#FF000000"
+            android:textSize="28sp"
+            android:text="@string/compat_mode_help_body"
+            />
+    </RelativeLayout>
+    <Button
+        android:id="@+id/button"
+        android:layout_width="208dp"
+        android:layout_height="48dp"
+        android:layout_alignLeft="@id/header"
+        android:layout_alignParentBottom="true"
+        android:layout_marginBottom="20dp"
+        android:textSize="28sp"
+        android:text="@android:string/ok"
+        />
+</RelativeLayout>
+
diff --git a/packages/SystemUI/res/layout-sw600dp/status_bar_compat_mode_panel.xml b/packages/SystemUI/res/layout-sw600dp/status_bar_compat_mode_panel.xml
new file mode 100644
index 0000000..a33741e
--- /dev/null
+++ b/packages/SystemUI/res/layout-sw600dp/status_bar_compat_mode_panel.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+**
+** Copyright 2011, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+**     http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+-->
+
+<com.android.systemui.statusbar.tablet.CompatModePanel
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_height="wrap_content"
+    android:layout_width="match_parent"
+    android:paddingBottom="@dimen/panel_float"
+    android:paddingRight="20dp"
+    >
+    <RadioGroup android:id="@+id/compat_mode_radio_group"
+        android:background="@*android:drawable/dialog_full_holo_dark"
+        android:layout_height="wrap_content"
+        android:layout_width="match_parent"
+        android:orientation="vertical"
+        android:padding="10dp"
+        >
+        <RadioButton android:id="@+id/compat_mode_off_radio"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="@string/compat_mode_off" />
+        <RadioButton android:id="@+id/compat_mode_on_radio"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="@string/compat_mode_on" />
+    </RadioGroup>
+</com.android.systemui.statusbar.tablet.CompatModePanel>
diff --git a/packages/SystemUI/res/layout-sw600dp/status_bar_notification_area.xml b/packages/SystemUI/res/layout-sw600dp/status_bar_notification_area.xml
index f53b29e..fecfe7f 100644
--- a/packages/SystemUI/res/layout-sw600dp/status_bar_notification_area.xml
+++ b/packages/SystemUI/res/layout-sw600dp/status_bar_notification_area.xml
@@ -27,7 +27,7 @@
     >
 
     <LinearLayout
-        android:id="@+id/notificationAndImeArea"
+        android:id="@+id/feedbackIconArea"
         android:layout_width="wrap_content"
         android:layout_height="match_parent"
         android:orientation="horizontal"
@@ -41,7 +41,16 @@
             android:src="@drawable/ic_sysbar_ime_default"
             android:visibility="gone"
             />
-        
+
+        <com.android.systemui.statusbar.policy.CompatModeButton
+            android:id="@+id/compatModeButton"
+            android:layout_width="wrap_content"
+            android:layout_height="match_parent"
+            android:layout_marginLeft="8dip"
+            android:src="@drawable/ic_sysbar_zoom"
+            android:visibility="gone"
+            />
+
         <com.android.systemui.statusbar.tablet.NotificationIconArea
             android:id="@+id/notificationIcons"
             android:layout_width="wrap_content"
@@ -144,4 +153,3 @@
         </LinearLayout>
     </LinearLayout>
 </LinearLayout>
-
diff --git a/packages/SystemUI/res/layout-sw600dp/status_bar_notification_panel.xml b/packages/SystemUI/res/layout-sw600dp/status_bar_notification_panel.xml
index ef57228..72519fb 100644
--- a/packages/SystemUI/res/layout-sw600dp/status_bar_notification_panel.xml
+++ b/packages/SystemUI/res/layout-sw600dp/status_bar_notification_panel.xml
@@ -57,15 +57,15 @@
                 android:layout_width="match_parent"
                 android:layout_weight="1"
                 >
-                <LinearLayout
+                <com.android.systemui.statusbar.policy.NotificationRowLayout
                     android:id="@+id/content"
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
                     android:gravity="center_horizontal|bottom"
-                    android:orientation="vertical"
                     android:clickable="true"
                     android:focusable="true"
                     android:descendantFocusability="afterDescendants"
+                    systemui:rowHeight="@dimen/notification_height"
                     />
             </ScrollView>
         </LinearLayout>
diff --git a/packages/SystemUI/res/layout-sw600dp/status_bar_notification_row.xml b/packages/SystemUI/res/layout-sw600dp/status_bar_notification_row.xml
deleted file mode 100644
index 8e456b2..0000000
--- a/packages/SystemUI/res/layout-sw600dp/status_bar_notification_row.xml
+++ /dev/null
@@ -1,45 +0,0 @@
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="match_parent"
-    android:layout_height="65dp"
-    >
-
-    <ImageButton
-        android:id="@+id/veto"
-        android:layout_width="48dp"
-        android:layout_height="match_parent"
-        android:layout_centerVertical="true"
-        android:layout_alignParentRight="true"
-        android:src="@drawable/status_bar_veto"
-        android:scaleType="center"
-        android:background="@null"
-        android:paddingRight="8dp"
-        android:paddingLeft="8dp"
-        />
-
-    <ImageView
-        android:id="@+id/large_icon"
-        android:layout_width="@android:dimen/notification_large_icon_width"
-        android:layout_height="@android:dimen/notification_large_icon_height"
-        android:layout_alignParentTop="true"
-        android:layout_alignParentLeft="true"
-        android:scaleType="center"
-        />
-
-    <com.android.systemui.statusbar.LatestItemView android:id="@+id/content"
-        android:layout_width="match_parent"
-        android:layout_height="64dp"
-        android:layout_alignParentTop="true"
-        android:layout_toRightOf="@id/large_icon"
-        android:layout_toLeftOf="@id/veto"
-        android:focusable="true"
-        android:clickable="true"
-        />
-
-    <View
-        android:layout_width="match_parent"
-        android:layout_height="1dp"
-        android:layout_alignParentBottom="true"
-        android:background="@android:drawable/divider_horizontal_dark"
-        />
-
-</RelativeLayout>
diff --git a/packages/SystemUI/res/layout-sw600dp/status_bar_recent_item.xml b/packages/SystemUI/res/layout-sw600dp/status_bar_recent_item.xml
index cd42d7e..9687866 100644
--- a/packages/SystemUI/res/layout-sw600dp/status_bar_recent_item.xml
+++ b/packages/SystemUI/res/layout-sw600dp/status_bar_recent_item.xml
@@ -36,53 +36,53 @@
     <ImageView android:id="@+id/app_icon"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_alignParentLeft="true"
-        android:layout_alignParentTop="true"
-        android:layout_marginLeft="131dip"
-        android:layout_marginTop="13dip"
+        android:layout_alignLeft="@id/app_thumbnail"
+        android:layout_alignTop="@id/app_thumbnail"
+        android:layout_marginLeft="@dimen/status_bar_recents_app_icon_left_margin"
+        android:layout_marginTop="@dimen/status_bar_recents_app_icon_top_margin"
         android:maxWidth="@dimen/status_bar_recents_thumbnail_max_width"
         android:maxHeight="@dimen/status_bar_recents_thumbnail_max_height"
         android:adjustViewBounds="true"
     />
 
-    <View android:id="@+id/recents_callout_line"
-        android:layout_width="97dip"
-        android:layout_height="1dip"
-        android:layout_alignParentTop="true"
-        android:layout_marginTop="61dip"
-        android:layout_alignParentLeft="true"
-        android:layout_marginLeft="16dip"
-        android:layout_toLeftOf="@id/app_thumbnail"
-        android:layout_marginRight="3dip"
-        android:background="@drawable/recents_callout_line"
-    />
-
     <TextView android:id="@+id/app_label"
-        android:layout_width="97dip"
+        android:layout_width="@dimen/status_bar_recents_app_label_width"
         android:layout_height="wrap_content"
-        android:textSize="@dimen/status_bar_recents_app_description_text_size"
+        android:textSize="@dimen/status_bar_recents_app_label_text_size"
         android:fadingEdge="horizontal"
         android:fadingEdgeLength="@dimen/status_bar_recents_fading_edge_length"
         android:scrollHorizontally="true"
         android:layout_alignParentLeft="true"
         android:layout_alignParentTop="true"
-        android:layout_marginLeft="16dip"
+        android:layout_marginLeft="@dimen/status_bar_recents_app_label_left_margin"
         android:layout_marginTop="32dip"
         android:singleLine="true"
         android:ellipsize="marquee"
     />
 
+    <View android:id="@+id/recents_callout_line"
+        android:layout_width="@dimen/status_bar_recents_app_label_width"
+        android:layout_height="1dip"
+        android:layout_below="@id/app_label"
+        android:layout_marginTop="3dip"
+        android:layout_alignParentLeft="true"
+        android:layout_marginLeft="@dimen/status_bar_recents_app_label_left_margin"
+        android:layout_toLeftOf="@id/app_thumbnail"
+        android:layout_marginRight="3dip"
+        android:background="@drawable/recents_callout_line"
+    />
+
     <TextView android:id="@+id/app_description"
-        android:layout_width="97dip"
+        android:layout_width="@dimen/status_bar_recents_app_label_width"
         android:layout_height="wrap_content"
         android:textSize="@dimen/status_bar_recents_app_description_text_size"
         android:fadingEdge="horizontal"
         android:fadingEdgeLength="@dimen/status_bar_recents_fading_edge_length"
         android:scrollHorizontally="true"
         android:layout_alignParentLeft="true"
-        android:layout_alignParentTop="true"
-        android:layout_marginLeft="16dip"
-        android:layout_marginTop="61dip"
+        android:layout_below="@id/recents_callout_line"
+        android:layout_marginLeft="@dimen/status_bar_recents_app_label_left_margin"
+        android:layout_marginTop="3dip"
         android:singleLine="true"
         android:ellipsize="marquee"
     />
diff --git a/packages/SystemUI/res/layout/recent_apps_activity.xml b/packages/SystemUI/res/layout/recent_apps_activity.xml
deleted file mode 100644
index ec661e8..0000000
--- a/packages/SystemUI/res/layout/recent_apps_activity.xml
+++ /dev/null
@@ -1,55 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-** Copyright 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.
-*/
--->
-
-<LinearLayout
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent"
-    android:orientation="vertical">
-
-    <!-- Title -->
-    <TextView
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:gravity="center"
-        android:textAppearance="?android:attr/textAppearanceSmall"
-        android:textColor="#80FFFFFF"
-        android:textStyle="bold"
-        android:singleLine="true"
-        android:text="@string/recent_tasks_title"
-        android:visibility="gone"/>
-
-    <!-- This is only intended to be visible when carousel is invisible -->
-    <TextView
-        android:id="@+id/no_applications_message"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_gravity="center"
-        android:textAppearance="?android:attr/textAppearanceSmall"
-        android:text="@string/recent_tasks_empty"
-        android:visibility="gone"/>
-
-    <com.android.systemui.recent.RecentApplicationsCarouselView
-        android:id="@+id/carousel"
-        android:layout_width="match_parent"
-        android:layout_height="0dip"
-        android:layout_weight="1">
-    </com.android.systemui.recent.RecentApplicationsCarouselView>
-
-</LinearLayout>
diff --git a/packages/SystemUI/res/layout/recents_detail_view.xml b/packages/SystemUI/res/layout/recents_detail_view.xml
deleted file mode 100644
index 879d0f2..0000000
--- a/packages/SystemUI/res/layout/recents_detail_view.xml
+++ /dev/null
@@ -1,40 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-** Copyright 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.
-*/
--->
-
-<LinearLayout
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent"
-    android:orientation="vertical">
-
-    <!-- Application Title -->
-    <TextView android:id="@+id/app_title"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:textAppearance="?android:attr/textAppearanceMedium"
-        android:singleLine="true"/>
-
-    <!-- Application Details -->
-    <TextView
-        android:id="@+id/app_description"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:textAppearance="?android:attr/textAppearanceSmall"/>
-
-</LinearLayout>
diff --git a/packages/SystemUI/res/layout/status_bar_expanded.xml b/packages/SystemUI/res/layout/status_bar_expanded.xml
index 18e8273..6670eff 100644
--- a/packages/SystemUI/res/layout/status_bar_expanded.xml
+++ b/packages/SystemUI/res/layout/status_bar_expanded.xml
@@ -18,7 +18,9 @@
 */
 -->
 
-<com.android.systemui.statusbar.phone.ExpandedView xmlns:android="http://schemas.android.com/apk/res/android"
+<com.android.systemui.statusbar.phone.ExpandedView 
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:systemui="http://schemas.android.com/apk/res/com.android.systemui"
     android:orientation="vertical"
     android:focusable="true"
     android:descendantFocusability="afterDescendants"
@@ -97,10 +99,11 @@
                     android:textAppearance="@style/TextAppearance.StatusBar.Title"
                     android:text="@string/status_bar_ongoing_events_title"
                     />
-                <LinearLayout android:id="@+id/ongoingItems"
+                <com.android.systemui.statusbar.policy.NotificationRowLayout
+                    android:id="@+id/ongoingItems"
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
-                    android:orientation="vertical"
+                    systemui:rowHeight="@dimen/notification_height"
                     />
 
                 <TextView android:id="@+id/latestTitle"
@@ -111,10 +114,11 @@
                     android:textAppearance="@style/TextAppearance.StatusBar.Title"
                     android:text="@string/status_bar_latest_events_title"
                     />
-                <LinearLayout android:id="@+id/latestItems"
+                <com.android.systemui.statusbar.policy.NotificationRowLayout
+                    android:id="@+id/latestItems"
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
-                    android:orientation="vertical"
+                    systemui:rowHeight="@dimen/notification_height"
                     />
             </LinearLayout>
         </ScrollView>
diff --git a/packages/SystemUI/res/layout/status_bar_notification_row.xml b/packages/SystemUI/res/layout/status_bar_notification_row.xml
index 8e456b2..aff6a6e 100644
--- a/packages/SystemUI/res/layout/status_bar_notification_row.xml
+++ b/packages/SystemUI/res/layout/status_bar_notification_row.xml
@@ -1,6 +1,6 @@
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
-    android:layout_height="65dp"
+    android:layout_height="@dimen/notification_height"
     >
 
     <ImageButton
@@ -9,6 +9,7 @@
         android:layout_height="match_parent"
         android:layout_centerVertical="true"
         android:layout_alignParentRight="true"
+        android:layout_marginRight="-80dp"
         android:src="@drawable/status_bar_veto"
         android:scaleType="center"
         android:background="@null"
@@ -30,7 +31,7 @@
         android:layout_height="64dp"
         android:layout_alignParentTop="true"
         android:layout_toRightOf="@id/large_icon"
-        android:layout_toLeftOf="@id/veto"
+        android:layout_alignParentRight="true"
         android:focusable="true"
         android:clickable="true"
         />
diff --git a/packages/SystemUI/res/layout/status_bar_recent_item.xml b/packages/SystemUI/res/layout/status_bar_recent_item.xml
deleted file mode 100644
index cd42d7e..0000000
--- a/packages/SystemUI/res/layout/status_bar_recent_item.xml
+++ /dev/null
@@ -1,90 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/* apps/common/assets/default/default/skins/StatusBar.xml
-**
-** Copyright 2006, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-**     http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
--->
-
-<!--    android:background="@drawable/status_bar_closed_default_background" -->
-<RelativeLayout
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_height="wrap_content"
-    android:layout_width="@dimen/status_bar_recents_thumbnail_view_width">
-
-    <ImageView android:id="@+id/app_thumbnail"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_alignParentLeft="true"
-        android:layout_alignParentTop="true"
-        android:layout_marginLeft="@dimen/status_bar_recents_thumbnail_left_margin"
-        android:scaleType="center"
-    />
-
-    <ImageView android:id="@+id/app_icon"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_alignParentLeft="true"
-        android:layout_alignParentTop="true"
-        android:layout_marginLeft="131dip"
-        android:layout_marginTop="13dip"
-        android:maxWidth="@dimen/status_bar_recents_thumbnail_max_width"
-        android:maxHeight="@dimen/status_bar_recents_thumbnail_max_height"
-        android:adjustViewBounds="true"
-    />
-
-    <View android:id="@+id/recents_callout_line"
-        android:layout_width="97dip"
-        android:layout_height="1dip"
-        android:layout_alignParentTop="true"
-        android:layout_marginTop="61dip"
-        android:layout_alignParentLeft="true"
-        android:layout_marginLeft="16dip"
-        android:layout_toLeftOf="@id/app_thumbnail"
-        android:layout_marginRight="3dip"
-        android:background="@drawable/recents_callout_line"
-    />
-
-    <TextView android:id="@+id/app_label"
-        android:layout_width="97dip"
-        android:layout_height="wrap_content"
-        android:textSize="@dimen/status_bar_recents_app_description_text_size"
-        android:fadingEdge="horizontal"
-        android:fadingEdgeLength="@dimen/status_bar_recents_fading_edge_length"
-        android:scrollHorizontally="true"
-        android:layout_alignParentLeft="true"
-        android:layout_alignParentTop="true"
-        android:layout_marginLeft="16dip"
-        android:layout_marginTop="32dip"
-        android:singleLine="true"
-        android:ellipsize="marquee"
-    />
-
-    <TextView android:id="@+id/app_description"
-        android:layout_width="97dip"
-        android:layout_height="wrap_content"
-        android:textSize="@dimen/status_bar_recents_app_description_text_size"
-        android:fadingEdge="horizontal"
-        android:fadingEdgeLength="@dimen/status_bar_recents_fading_edge_length"
-        android:scrollHorizontally="true"
-        android:layout_alignParentLeft="true"
-        android:layout_alignParentTop="true"
-        android:layout_marginLeft="16dip"
-        android:layout_marginTop="61dip"
-        android:singleLine="true"
-        android:ellipsize="marquee"
-    />
-
-</RelativeLayout>
diff --git a/packages/SystemUI/res/layout/status_bar_recent_panel.xml b/packages/SystemUI/res/layout/status_bar_recent_panel.xml
deleted file mode 100644
index 703cbc1..0000000
--- a/packages/SystemUI/res/layout/status_bar_recent_panel.xml
+++ /dev/null
@@ -1,84 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/* apps/common/assets/default/default/skins/StatusBar.xml
-**
-** Copyright 2010, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-**     http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
--->
-
-<com.android.systemui.recent.RecentsPanelView
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    android:id="@+id/recents_root"
-    android:layout_height="match_parent"
-    android:layout_width="wrap_content">
-
-    <FrameLayout
-        android:id="@+id/recents_bg_protect"
-        android:background="@drawable/recents_bg_protect_tile"
-        android:layout_width="wrap_content"
-        android:layout_height="match_parent"
-        android:layout_alignParentBottom="true"
-        android:paddingBottom="@*android:dimen/status_bar_height"
-        android:clipToPadding="false"
-        android:clipChildren="false">
-
-        <LinearLayout android:id="@+id/recents_glow"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_marginBottom="-49dip"
-            android:layout_gravity="bottom"
-            android:background="@drawable/recents_blue_glow"
-            android:orientation="horizontal"
-            android:clipToPadding="false"
-            android:clipChildren="false"
-            >
-            <com.android.systemui.recent.RecentsVerticalScrollView android:id="@+id/recents_container"
-                android:layout_width="@dimen/status_bar_recents_width"
-                android:layout_height="wrap_content"
-                android:layout_marginRight="@dimen/status_bar_recents_right_glow_margin"
-                android:divider="@null"
-                android:stackFromBottom="true"
-                android:fadingEdge="vertical"
-                android:scrollbars="none"
-                android:fadingEdgeLength="20dip"
-                android:listSelector="@drawable/recents_thumbnail_bg_selector"
-                android:layout_gravity="bottom|left"
-                android:clipToPadding="false"
-                android:clipChildren="false">
-
-                <LinearLayout android:id="@+id/recents_linear_layout"
-                    android:layout_width="wrap_content"
-                    android:layout_height="wrap_content"
-                    android:orientation="vertical"
-                    android:clipToPadding="false"
-                    android:clipChildren="false">
-                </LinearLayout>
-
-            </com.android.systemui.recent.RecentsVerticalScrollView>
-
-
-        </LinearLayout>
-
-    </FrameLayout>
-
-    <View android:id="@+id/recents_dismiss_button"
-        android:layout_width="80px"
-        android:layout_height="@*android:dimen/status_bar_height"
-        android:layout_alignParentBottom="true"
-        android:layout_alignParentLeft="true"
-        android:background="@drawable/ic_sysbar_back_ime"
-    />
-
-</com.android.systemui.recent.RecentsPanelView>
diff --git a/packages/SystemUI/res/layout/usb_preference_buttons.xml b/packages/SystemUI/res/layout/usb_preference_buttons.xml
new file mode 100644
index 0000000..babe07e
--- /dev/null
+++ b/packages/SystemUI/res/layout/usb_preference_buttons.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<!-- Check box that is displayed in the activity resolver UI for the user
+     to make their selection the preferred activity. -->
+<LinearLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:paddingLeft="14dip"
+    android:paddingRight="15dip"
+    android:orientation="vertical">
+
+    <Button
+        android:id="@+id/mtp_ptp_button"
+        android:text="@string/use_ptp_button_title"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:focusable="true"
+        android:clickable="true" />
+
+    <Button
+        android:id="@+id/installer_cd_button"
+        android:text="@string/installer_cd_button_title"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:focusable="true"
+        android:clickable="true" />
+
+</LinearLayout>
diff --git a/packages/SystemUI/res/values-fr-large/strings.xml b/packages/SystemUI/res/values-fr-large/strings.xml
index 447b174..f8dd55e 100644
--- a/packages/SystemUI/res/values-fr-large/strings.xml
+++ b/packages/SystemUI/res/values-fr-large/strings.xml
@@ -21,7 +21,7 @@
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
     <string name="status_bar_clear_all_button" msgid="4661583896803349732">"Tout effacer"</string>
     <string name="status_bar_settings_signal_meter_disconnected" msgid="383145178755329067">"Aucune connexion"</string>
-    <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="2535465294437586528">"Connecté au Wi-Fi."</string>
+    <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="2535465294437586528">"Connecté au Wi-Fi"</string>
     <string name="gps_notification_searching_text" msgid="4467935186864208249">"Recherche de GPS en cours"</string>
     <string name="gps_notification_found_text" msgid="6270628388918822956">"Position définie par GPS"</string>
     <string name="notifications_off_title" msgid="1860117696034775851">"Notifications désactivées"</string>
diff --git a/packages/SystemUI/res/values-hdpi/dimens.xml b/packages/SystemUI/res/values-hdpi/dimens.xml
new file mode 100644
index 0000000..741b75a
--- /dev/null
+++ b/packages/SystemUI/res/values-hdpi/dimens.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ * Copyright (c) 2011, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+-->
+<resources>
+    <!-- Offsets for rendering thumbnails over drawable recents_thumbnail_bg -->
+    <dimen name="recents_thumbnail_bg_padding_left">6px</dimen>
+    <dimen name="recents_thumbnail_bg_padding_top">7px</dimen>
+    <dimen name="recents_thumbnail_bg_padding_right">6px</dimen>
+    <dimen name="recents_thumbnail_bg_padding_bottom">6px</dimen>
+</resources>
diff --git a/packages/SystemUI/res/values-it-large/strings.xml b/packages/SystemUI/res/values-it-large/strings.xml
index 3cde529..18ccd07 100644
--- a/packages/SystemUI/res/values-it-large/strings.xml
+++ b/packages/SystemUI/res/values-it-large/strings.xml
@@ -19,8 +19,8 @@
 
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="status_bar_clear_all_button" msgid="4661583896803349732">"Cancella tutto"</string>
-    <string name="status_bar_settings_signal_meter_disconnected" msgid="383145178755329067">"Nessuna conness. Internet"</string>
+    <string name="status_bar_clear_all_button" msgid="4661583896803349732">"Cancella"</string>
+    <string name="status_bar_settings_signal_meter_disconnected" msgid="383145178755329067">"Nessuna connessione"</string>
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="2535465294437586528">"Wi-Fi connesso"</string>
     <string name="gps_notification_searching_text" msgid="4467935186864208249">"Ricerca del GPS"</string>
     <string name="gps_notification_found_text" msgid="6270628388918822956">"Posizione stabilita dal GPS"</string>
diff --git a/packages/SystemUI/res/values-land/dimens.xml b/packages/SystemUI/res/values-land/dimens.xml
index 6f1453e..0219a77 100644
--- a/packages/SystemUI/res/values-land/dimens.xml
+++ b/packages/SystemUI/res/values-land/dimens.xml
@@ -23,15 +23,17 @@
     <!-- Width of a recent app view, including all content -->
     <dimen name="status_bar_recents_thumbnail_view_width">156dp</dimen>
     <!-- How far the thumbnail for a recent app appears from left edge -->
-    <dimen name="status_bar_recents_thumbnail_left_margin">0dp</dimen>
+    <dimen name="status_bar_recents_thumbnail_left_margin">8dp</dimen>
+    <!-- How far the thumbnail for a recent app appears from top edge -->
+    <dimen name="status_bar_recents_thumbnail_top_margin">12dp</dimen>
     <!-- Width of scrollable area in recents -->
     <dimen name="status_bar_recents_width">128dp</dimen>
-    <!-- Thumbnail border width -->
-    <dimen name="status_bar_recents_thumbnail_border_width">8dp</dimen>
-    <!-- Thumbnail border height -->
-    <dimen name="status_bar_recents_thumbnail_border_height">12dp</dimen>
     <!-- Padding for text descriptions -->
     <dimen name="status_bar_recents_text_description_padding">8dp</dimen>
+    <!-- Width of application label text -->
+    <dimen name="status_bar_recents_app_label_width">97dip</dimen>
+    <!-- Left margin of application label text -->
+    <dimen name="status_bar_recents_app_label_left_margin">16dip</dimen>
     <!-- Margin between recents container and glow on the right -->
     <dimen name="status_bar_recents_right_glow_margin">0dip</dimen>
 </resources>
diff --git a/packages/SystemUI/res/values-large/config.xml b/packages/SystemUI/res/values-large/config.xml
index 299ab97..4014f8d 100644
--- a/packages/SystemUI/res/values-large/config.xml
+++ b/packages/SystemUI/res/values-large/config.xml
@@ -20,14 +20,7 @@
 <!-- These resources are around just to allow their values to be customized
      for different hardware and product builds. -->
 <resources>
-    <integer name="config_status_bar_position">1</integer>
-
-    <!-- Component to be used as the status bar service.  Must implement the IStatusBar
-     interface.  This name is in the ComponentName flattened format (package/class)  -->
-    <string name="config_statusBarComponent" translatable="false">com.android.systemui.statusbar.tablet.TabletStatusBar</string>
-
     <!-- Whether or not we show the number in the bar. -->
     <bool name="config_statusBarShowNumber">false</bool>
-
 </resources>
 
diff --git a/packages/SystemUI/res/values-large/dimens.xml b/packages/SystemUI/res/values-large/dimens.xml
index f8a4a1c..9d89e21 100644
--- a/packages/SystemUI/res/values-large/dimens.xml
+++ b/packages/SystemUI/res/values-large/dimens.xml
@@ -22,32 +22,6 @@
     <dimen name="status_bar_panel_bottom_offset">36dp</dimen>
     <!-- gap on either side of status bar notification icons -->
     <dimen name="status_bar_icon_padding">8dp</dimen>
-
-    <!-- Recent Applications parameters -->
-    <!-- Width of a recent app view, including all content -->
-    <dimen name="status_bar_recents_thumbnail_view_width">156dp</dimen>
-    <!-- How far the thumbnail for a recent app appears from left edge -->
-    <dimen name="status_bar_recents_thumbnail_left_margin">110dp</dimen>
-    <!-- Upper width limit for application icon -->
-    <dimen name="status_bar_recents_thumbnail_max_width">64dp</dimen>
-    <!-- Upper height limit for application icon -->
-    <dimen name="status_bar_recents_thumbnail_max_height">64dp</dimen>
-    <!-- Width of scrollable area in recents -->
-    <dimen name="status_bar_recents_width">356dp</dimen>
-    <!-- Thumbnail border width -->
-    <dimen name="status_bar_recents_thumbnail_border_width">12dp</dimen>
-    <!-- Thumbnail border height -->
-    <dimen name="status_bar_recents_thumbnail_border_height">12dp</dimen>
-    <!-- Padding for text descriptions -->
-    <dimen name="status_bar_recents_text_description_padding">8dp</dimen>
-    <!-- Size of application label text -->
-    <dimen name="status_bar_recents_app_label_text_size">18dip</dimen>
-    <!-- Size of application description text -->
-    <dimen name="status_bar_recents_app_description_text_size">18dip</dimen>
-    <!-- Size of fading edge for scroll effect -->
-    <dimen name="status_bar_recents_fading_edge_length">20dip</dimen>
-    <!-- Margin between recents container and glow on the right -->
-    <dimen name="status_bar_recents_right_glow_margin">100dip</dimen>
 </resources>
 
 
diff --git a/packages/SystemUI/res/values-mdpi/dimens.xml b/packages/SystemUI/res/values-mdpi/dimens.xml
new file mode 100644
index 0000000..741b75a
--- /dev/null
+++ b/packages/SystemUI/res/values-mdpi/dimens.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ * Copyright (c) 2011, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+-->
+<resources>
+    <!-- Offsets for rendering thumbnails over drawable recents_thumbnail_bg -->
+    <dimen name="recents_thumbnail_bg_padding_left">6px</dimen>
+    <dimen name="recents_thumbnail_bg_padding_top">7px</dimen>
+    <dimen name="recents_thumbnail_bg_padding_right">6px</dimen>
+    <dimen name="recents_thumbnail_bg_padding_bottom">6px</dimen>
+</resources>
diff --git a/packages/SystemUI/res/values-port/dimens.xml b/packages/SystemUI/res/values-port/dimens.xml
new file mode 100644
index 0000000..54c25fa
--- /dev/null
+++ b/packages/SystemUI/res/values-port/dimens.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ * Copyright (c) 2006, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+-->
+<resources>
+    <!-- Recent Applications parameters -->
+    <!-- Width of a recent app view, including all content -->
+    <dimen name="status_bar_recents_thumbnail_view_width">156dp</dimen>
+    <!-- How far the thumbnail for a recent app appears from left edge -->
+    <dimen name="status_bar_recents_thumbnail_left_margin">110dp</dimen>
+    <!-- Width of scrollable area in recents -->
+    <dimen name="status_bar_recents_width">356dp</dimen>
+    <!-- Padding for text descriptions -->
+    <dimen name="status_bar_recents_text_description_padding">8dp</dimen>
+    <!-- Width of application label text -->
+    <dimen name="status_bar_recents_app_label_width">97dip</dimen>
+    <!-- Left margin of application label text -->
+    <dimen name="status_bar_recents_app_label_left_margin">16dip</dimen>
+    <!-- Margin between recents container and glow on the right -->
+    <dimen name="status_bar_recents_right_glow_margin">100dip</dimen>
+</resources>
diff --git a/packages/SystemUI/res/values-ru-large/strings.xml b/packages/SystemUI/res/values-ru-large/strings.xml
index c48321e..bafb97f 100644
--- a/packages/SystemUI/res/values-ru-large/strings.xml
+++ b/packages/SystemUI/res/values-ru-large/strings.xml
@@ -19,11 +19,11 @@
 
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="status_bar_clear_all_button" msgid="4661583896803349732">"Очистить"</string>
+    <string name="status_bar_clear_all_button" msgid="4661583896803349732">"Очистить все"</string>
     <string name="status_bar_settings_signal_meter_disconnected" msgid="383145178755329067">"Нет подключения к Интернету"</string>
-    <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="2535465294437586528">"Wi-Fi: подключено"</string>
-    <string name="gps_notification_searching_text" msgid="4467935186864208249">"Выполняется поиск при помощи GPS"</string>
+    <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="2535465294437586528">"Wi-Fi подключено"</string>
+    <string name="gps_notification_searching_text" msgid="4467935186864208249">"Поиск GPS"</string>
     <string name="gps_notification_found_text" msgid="6270628388918822956">"Местоположение установлено с помощью GPS"</string>
-    <string name="notifications_off_title" msgid="1860117696034775851">"Показ уведомлений отключен"</string>
-    <string name="notifications_off_text" msgid="1439152806320786912">"Нажмите здесь, чтобы снова разрешить показ уведомлений."</string>
+    <string name="notifications_off_title" msgid="1860117696034775851">"Уведомления отключены"</string>
+    <string name="notifications_off_text" msgid="1439152806320786912">"Нажмите здесь, чтобы снова включить уведомления."</string>
 </resources>
diff --git a/packages/SystemUI/res/values-sw600dp-port/config.xml b/packages/SystemUI/res/values-sw600dp-port/config.xml
new file mode 100644
index 0000000..ab7661a
--- /dev/null
+++ b/packages/SystemUI/res/values-sw600dp-port/config.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+** Copyright 2011, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+**     http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+-->
+
+<!-- These resources are around just to allow their values to be customized
+     for different hardware and product builds. -->
+<resources>
+    <integer name="config_maxNotificationIcons">3</integer>
+</resources>
+
diff --git a/packages/SystemUI/res/values-sw600dp-port/dimens.xml b/packages/SystemUI/res/values-sw600dp-port/dimens.xml
new file mode 100644
index 0000000..b8a6cfe
--- /dev/null
+++ b/packages/SystemUI/res/values-sw600dp-port/dimens.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ * Copyright (c) 2011, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); 
+ * you may not use this file except in compliance with the License. 
+ * You may obtain a copy of the License at 
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0 
+ *
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+*/
+-->
+<resources>
+    <!-- gap on either side of status bar notification icons -->
+    <dimen name="status_bar_icon_padding">0dp</dimen>
+</resources>
+
diff --git a/packages/SystemUI/res/values-xlarge/colors.xml b/packages/SystemUI/res/values-sw600dp/colors.xml
similarity index 100%
rename from packages/SystemUI/res/values-xlarge/colors.xml
rename to packages/SystemUI/res/values-sw600dp/colors.xml
diff --git a/packages/SystemUI/res/values-sw600dp/dimens.xml b/packages/SystemUI/res/values-sw600dp/dimens.xml
new file mode 100644
index 0000000..b4fd8ab
--- /dev/null
+++ b/packages/SystemUI/res/values-sw600dp/dimens.xml
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ * Copyright (c) 2010, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); 
+ * you may not use this file except in compliance with the License. 
+ * You may obtain a copy of the License at 
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0 
+ *
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+*/
+-->
+<resources>
+    <!-- The width of the ticker, including the icon -->
+    <dimen name="notification_ticker_width">360dp</dimen>
+    <!-- Status bar panel bottom offset (height of status bar - overlap) -->
+    <dimen name="status_bar_panel_bottom_offset">36dp</dimen>
+    <!-- gap on either side of status bar notification icons -->
+    <dimen name="status_bar_icon_padding">8dp</dimen>
+    <!-- The width of the notification panel window -->
+    <dimen name="notification_panel_width">512dp</dimen>
+    <!-- The minimum height of the notification panel window -->
+    <dimen name="notification_panel_min_height">770dp</dimen>
+    <!-- Bottom margin (from display edge) for status bar panels -->
+    <dimen name="panel_float">56dp</dimen>
+
+    <!-- Recent Applications parameters -->
+    <!-- Width of a recent app view, including all content -->
+    <dimen name="status_bar_recents_thumbnail_view_width">156dp</dimen>
+    <!-- How far the thumbnail for a recent app appears from left edge -->
+    <dimen name="status_bar_recents_thumbnail_left_margin">110dp</dimen>
+    <!-- Upper width limit for application icon -->
+    <dimen name="status_bar_recents_thumbnail_max_width">64dp</dimen>
+    <!-- Upper height limit for application icon -->
+    <dimen name="status_bar_recents_thumbnail_max_height">64dp</dimen>
+    <!-- Width of scrollable area in recents -->
+    <dimen name="status_bar_recents_width">356dp</dimen>
+    <!-- Padding for text descriptions -->
+    <dimen name="status_bar_recents_text_description_padding">8dp</dimen>
+    <!-- Size of application label text -->
+    <dimen name="status_bar_recents_app_label_text_size">18dip</dimen>
+    <!-- Size of application description text -->
+    <dimen name="status_bar_recents_app_description_text_size">18dip</dimen>
+    <!-- Width of application label text -->
+    <dimen name="status_bar_recents_app_label_width">97dip</dimen>
+    <!-- Left margin for application label -->
+    <dimen name="status_bar_recents_app_label_left_margin">16dip</dimen>
+    <!-- Size of fading edge for scroll effect -->
+    <dimen name="status_bar_recents_fading_edge_length">20dip</dimen>
+    <!-- Margin between recents container and glow on the right -->
+    <dimen name="status_bar_recents_right_glow_margin">100dip</dimen>
+
+    <!-- Offsets for rendering thumbnails over drawable recents_thumbnail_bg -->
+    <dimen name="recents_thumbnail_bg_padding_left">15px</dimen>
+    <dimen name="recents_thumbnail_bg_padding_top">8px</dimen>
+    <dimen name="recents_thumbnail_bg_padding_right">12px</dimen>
+    <dimen name="recents_thumbnail_bg_padding_bottom">8px</dimen>
+
+    <!-- Where to place the app icon over the thumbnail -->
+    <dimen name="status_bar_recents_app_icon_left_margin">13dp</dimen>
+    <dimen name="status_bar_recents_app_icon_top_margin">13dp</dimen>
+</resources>
diff --git a/packages/SystemUI/res/values-sw720dp-port/dimens.xml b/packages/SystemUI/res/values-sw720dp-port/dimens.xml
new file mode 100644
index 0000000..74b266d
--- /dev/null
+++ b/packages/SystemUI/res/values-sw720dp-port/dimens.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ * Copyright (c) 2011, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+-->
+<resources>
+    <!-- gap on either side of status bar notification icons -->
+    <dimen name="status_bar_icon_padding">2dp</dimen>
+</resources>
+
diff --git a/packages/SystemUI/res/values-sw720dp/config.xml b/packages/SystemUI/res/values-sw720dp/config.xml
new file mode 100644
index 0000000..56b8e54
--- /dev/null
+++ b/packages/SystemUI/res/values-sw720dp/config.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+** Copyright 2011, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+**     http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+-->
+
+<!-- These resources are around just to allow their values to be customized
+     for different hardware and product builds. -->
+<resources>
+    <integer name="config_maxNotificationIcons">5</integer>
+</resources>
+
diff --git a/packages/SystemUI/res/values-xlarge-port/dimens.xml b/packages/SystemUI/res/values-xlarge-port/dimens.xml
deleted file mode 100644
index 56effa3..0000000
--- a/packages/SystemUI/res/values-xlarge-port/dimens.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- * Copyright (c) 2010, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); 
- * you may not use this file except in compliance with the License. 
- * You may obtain a copy of the License at 
- *
- *     http://www.apache.org/licenses/LICENSE-2.0 
- *
- * Unless required by applicable law or agreed to in writing, software 
- * distributed under the License is distributed on an "AS IS" BASIS, 
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
- * See the License for the specific language governing permissions and 
- * limitations under the License.
-*/
--->
-<resources>
-    <!-- gap on either side of status bar notification icons -->
-    <dimen name="status_bar_icon_padding">2dp</dimen>
-</resources>
-
-
-
diff --git a/packages/SystemUI/res/values-xlarge/dimens.xml b/packages/SystemUI/res/values-xlarge/dimens.xml
deleted file mode 100644
index 9d89e21..0000000
--- a/packages/SystemUI/res/values-xlarge/dimens.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- * Copyright (c) 2010, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); 
- * you may not use this file except in compliance with the License. 
- * You may obtain a copy of the License at 
- *
- *     http://www.apache.org/licenses/LICENSE-2.0 
- *
- * Unless required by applicable law or agreed to in writing, software 
- * distributed under the License is distributed on an "AS IS" BASIS, 
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
- * See the License for the specific language governing permissions and 
- * limitations under the License.
-*/
--->
-<resources>
-    <!-- The width of the ticker, including the icon -->
-    <dimen name="notification_ticker_width">360dp</dimen>
-    <!-- Status bar panel bottom offset (height of status bar - overlap) -->
-    <dimen name="status_bar_panel_bottom_offset">36dp</dimen>
-    <!-- gap on either side of status bar notification icons -->
-    <dimen name="status_bar_icon_padding">8dp</dimen>
-</resources>
-
-
diff --git a/packages/SystemUI/res/values/attrs.xml b/packages/SystemUI/res/values/attrs.xml
index fb2f7d63..5291629 100644
--- a/packages/SystemUI/res/values/attrs.xml
+++ b/packages/SystemUI/res/values/attrs.xml
@@ -24,5 +24,8 @@
     <declare-styleable name="NotificationLinearLayout">
         <attr name="insetLeft" format="dimension" />
     </declare-styleable>
+    <declare-styleable name="NotificationRowLayout">
+        <attr name="rowHeight" format="dimension" />
+    </declare-styleable>
 </resources>
 
diff --git a/packages/SystemUI/res/values/config.xml b/packages/SystemUI/res/values/config.xml
index 954a871..7a4ac5d 100644
--- a/packages/SystemUI/res/values/config.xml
+++ b/packages/SystemUI/res/values/config.xml
@@ -25,16 +25,14 @@
     data icon on devices -->
     <bool name="config_hspa_data_distinguishable">false</bool>
 
-    <!-- The location of the status bar.
-        0 - top
-        1 - bottom
-    -->
-    <integer name="config_status_bar_position">0</integer>
-
     <!-- Component to be used as the status bar service.  Must implement the IStatusBar
      interface.  This name is in the ComponentName flattened format (package/class)  -->
     <string name="config_statusBarComponent" translatable="false">com.android.systemui.statusbar.phone.PhoneStatusBar</string>
 
+    <!-- Component to be used as the system bar service.  Must implement the IStatusBar
+     interface.  This name is in the ComponentName flattened format (package/class)  -->
+    <string name="config_systemBarComponent" translatable="false">com.android.systemui.statusbar.tablet.TabletStatusBar</string>
+
     <!-- Whether or not we show the number in the bar. -->
     <bool name="config_statusBarShowNumber">true</bool>
 
@@ -42,5 +40,8 @@
          autodetected from the Configuration. -->
     <bool name="config_showNavigationBar">false</bool>
 
+    <!-- How many icons may be shown at once in the system bar. Includes any
+         slots that may be reused for things like IME control. -->
+    <integer name="config_maxNotificationIcons">5</integer>
 </resources>
 
diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml
index 657dc46..fc35a48 100644
--- a/packages/SystemUI/res/values/dimens.xml
+++ b/packages/SystemUI/res/values/dimens.xml
@@ -20,22 +20,14 @@
     <dimen name="status_bar_edge_ignore">5dp</dimen>
 
     <!-- Recent Applications parameters -->
-    <!-- Width of a recent app view, including all content -->
-    <dimen name="status_bar_recents_thumbnail_view_width">156dp</dimen>
-    <!-- How far the thumbnail for a recent app appears from left edge -->
-    <dimen name="status_bar_recents_thumbnail_left_margin">110dp</dimen>
     <!-- Upper width limit for application icon -->
     <dimen name="status_bar_recents_thumbnail_max_width">64dp</dimen>
     <!-- Upper height limit for application icon -->
     <dimen name="status_bar_recents_thumbnail_max_height">64dp</dimen>
-    <!-- Width of scrollable area in recents -->
-    <dimen name="status_bar_recents_width">356dp</dimen>
-    <!-- Thumbnail border width -->
-    <dimen name="status_bar_recents_thumbnail_border_width">12dp</dimen>
-    <!-- Thumbnail border height -->
-    <dimen name="status_bar_recents_thumbnail_border_height">12dp</dimen>
-    <!-- Padding for text descriptions -->
-    <dimen name="status_bar_recents_text_description_padding">8dp</dimen>
+    <!-- Where to place the app icon over the thumbnail -->
+    <dimen name="status_bar_recents_app_icon_left_margin">13dp</dimen>
+    <dimen name="status_bar_recents_app_icon_top_margin">13dp</dimen>
+
     <!-- Size of application label text -->
     <dimen name="status_bar_recents_app_label_text_size">18dip</dimen>
     <!-- Size of application description text -->
@@ -44,8 +36,13 @@
     <dimen name="status_bar_recents_fading_edge_length">20dip</dimen>
     <!-- Margin between recents container and glow on the right -->
     <dimen name="status_bar_recents_right_glow_margin">100dip</dimen>
+    <!-- Amount to offset bottom of notification peek window from top of status bar. -->
+    <dimen name="peek_window_y_offset">-12dp</dimen>
 
     <!-- thickness (height) of the navigation bar on phones that require it -->
     <dimen name="navigation_bar_size">42dp</dimen>
+
+    <!-- thickness (height) of each notification row, including any separators or padding -->
+    <dimen name="notification_height">65dp</dimen>
 </resources>
 
diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml
index 446827b..86e0cd0 100644
--- a/packages/SystemUI/res/values/strings.xml
+++ b/packages/SystemUI/res/values/strings.xml
@@ -143,4 +143,26 @@
     <!-- Checkbox label for USB accessory dialogs.  [CHAR LIMIT=50] -->
     <string name="always_use_accessory">Use by default for this USB accessory</string>
 
+    <!-- Checkbox label for application compatibility mode ON (zooming app to look like it's running
+         on a phone).  [CHAR LIMIT=25] -->
+    <string name="compat_mode_on">Zoom to fill screen</string>
+
+    <!-- Checkbox label for application compatibility mode OFF (normal mode on tablets).
+         [CHAR LIMIT=25] -->
+    <string name="compat_mode_off">Stretch to fill screen</string>
+    
+    <!-- Compatibility mode help screen: header text. [CHAR LIMIT=50] -->
+    <string name="compat_mode_help_header">Compatibility Zoom</string>
+
+    <!-- Compatibility mode help screen: body text. [CHAR LIMIT=150] -->
+    <string name="compat_mode_help_body">When an app was designed for a smaller screen, a zoom control will appear by the clock.</string>
+
+    <!-- Title for the USB function chooser in UsbPreferenceActivity. [CHAR LIMIT=30] -->
+    <string name="usb_preference_title">USB file transfer options</string>
+    <!-- Label for the MTP USB function in UsbPreferenceActivity. [CHAR LIMIT=50] -->
+    <string name="use_mtp_button_title">Mount as a media player (MTP)</string>
+    <!-- Label for the PTP USB function in UsbPreferenceActivity. [CHAR LIMIT=50] -->
+    <string name="use_ptp_button_title">Mount as a camera (PTP)</string>
+    <!-- Label for the installer CD image option in UsbPreferenceActivity. [CHAR LIMIT=50] -->
+    <string name="installer_cd_button_title">Install Android File Transfer application for Mac</string>
 </resources>
diff --git a/packages/SystemUI/res/values/styles.xml b/packages/SystemUI/res/values/styles.xml
index 86ffb4d..91a8855 100644
--- a/packages/SystemUI/res/values/styles.xml
+++ b/packages/SystemUI/res/values/styles.xml
@@ -16,25 +16,25 @@
 
 <resources xmlns:android="http://schemas.android.com/apk/res/android">
 
-    <style name="TextAppearance.StatusBar.Title" parent="@android:style/TextAppearance.StatusBar">
+    <style name="TextAppearance.StatusBar.Title" parent="@*android:style/TextAppearance.StatusBar">
         <item name="android:textAppearance">?android:attr/textAppearanceSmall</item>
         <item name="android:textStyle">bold</item>
         <item name="android:textColor">?android:attr/textColorPrimary</item>
     </style>
 
     <style name="TextAppearance.StatusBar.IntruderAlert"
-        parent="@android:style/TextAppearance.StatusBar">
+        parent="@*android:style/TextAppearance.StatusBar">
     </style>
 
     <style name="TextAppearance.StatusBar.SystemPanel"
-        parent="@android:style/TextAppearance.StatusBar">
+        parent="@*android:style/TextAppearance.StatusBar">
         <item name="android:textAppearance">?android:attr/textAppearance</item>
         <item name="android:textStyle">normal</item>
         <item name="android:textColor">#FF808080</item>
     </style>
 
     <style name="TextAppearance.StatusBar.TextButton"
-        parent="@android:style/TextAppearance.StatusBar">
+        parent="@*android:style/TextAppearance.StatusBar">
         <item name="android:textAppearance">?android:attr/textAppearance</item>
         <item name="android:textStyle">normal</item>
         <item name="android:textColor">#FFFFFFFF</item>
diff --git a/packages/SystemUI/src/com/android/systemui/SystemUIService.java b/packages/SystemUI/src/com/android/systemui/SystemUIService.java
index 870acd3..d7a5056 100644
--- a/packages/SystemUI/src/com/android/systemui/SystemUIService.java
+++ b/packages/SystemUI/src/com/android/systemui/SystemUIService.java
@@ -27,7 +27,10 @@
 import android.content.res.Configuration;
 import android.os.Binder;
 import android.os.IBinder;
+import android.os.RemoteException;
+import android.os.ServiceManager;
 import android.util.Slog;
+import android.view.IWindowManager;
 
 public class SystemUIService extends Service {
     static final String TAG = "SystemUIService";
@@ -36,7 +39,7 @@
      * The class names of the stuff to start.
      */
     final Object[] SERVICES = new Object[] {
-            R.string.config_statusBarComponent,
+            0, // system bar or status bar, filled in below.
             com.android.systemui.power.PowerUI.class,
         };
 
@@ -62,6 +65,17 @@
 
     @Override
     public void onCreate() {
+        // Pick status bar or system bar.
+        IWindowManager wm = IWindowManager.Stub.asInterface(
+                ServiceManager.getService(Context.WINDOW_SERVICE));
+        try {
+            SERVICES[0] = wm.canStatusBarHide()
+                    ? R.string.config_statusBarComponent
+                    : R.string.config_systemBarComponent;
+        } catch (RemoteException e) {
+            Slog.w(TAG, "Failing checking whether status bar can hide", e);
+        }
+
         final int N = SERVICES.length;
         mServices = new SystemUI[N];
         for (int i=0; i<N; i++) {
diff --git a/packages/SystemUI/src/com/android/systemui/recent/Choreographer.java b/packages/SystemUI/src/com/android/systemui/recent/Choreographer.java
index b876075..49a65d8 100644
--- a/packages/SystemUI/src/com/android/systemui/recent/Choreographer.java
+++ b/packages/SystemUI/src/com/android/systemui/recent/Choreographer.java
@@ -36,14 +36,16 @@
     View mScrimView;
     View mContentView;
     AnimatorSet mContentAnim;
+    Animator.AnimatorListener mListener;
 
     // the panel will start to appear this many px from the end
     final int HYPERSPACE_OFFRAMP = 200;
 
-    public Choreographer(View root, View scrim, View content) {
+    public Choreographer(View root, View scrim, View content, Animator.AnimatorListener listener) {
         mRootView = root;
         mScrimView = scrim;
         mContentView = content;
+        mListener = listener;
     }
 
     void createAnimation(boolean appearing) {
@@ -86,6 +88,9 @@
                 .with(posAnim);
         mContentAnim.setDuration(appearing ? OPEN_DURATION : CLOSE_DURATION);
         mContentAnim.addListener(this);
+        if (mListener != null) {
+            mContentAnim.addListener(mListener);
+        }
     }
 
     void startAnimation(boolean appearing) {
diff --git a/packages/SystemUI/src/com/android/systemui/recent/RecentsHorizontalScrollView.java b/packages/SystemUI/src/com/android/systemui/recent/RecentsHorizontalScrollView.java
index 194c9d1..3dbcc59 100644
--- a/packages/SystemUI/src/com/android/systemui/recent/RecentsHorizontalScrollView.java
+++ b/packages/SystemUI/src/com/android/systemui/recent/RecentsHorizontalScrollView.java
@@ -16,7 +16,7 @@
 
 package com.android.systemui.recent;
 
-import com.android.systemui.recent.RecentsPanelView.ActvityDescriptionAdapter;
+import com.android.systemui.recent.RecentsPanelView.ActivityDescriptionAdapter;
 
 import android.animation.Animator;
 import android.animation.Animator.AnimatorListener;
@@ -49,7 +49,7 @@
     private static final float THRESHHOLD = 50;
     private static final boolean DEBUG_INVALIDATE = false;
     private LinearLayout mLinearLayout;
-    private ActvityDescriptionAdapter mAdapter;
+    private ActivityDescriptionAdapter mAdapter;
     private RecentsCallback mCallback;
     protected int mLastScrollPosition;
     private View mCurrentView;
@@ -273,7 +273,7 @@
         }
     }
 
-    public void setAdapter(ActvityDescriptionAdapter adapter) {
+    public void setAdapter(ActivityDescriptionAdapter adapter) {
         mAdapter = adapter;
         mAdapter.registerDataSetObserver(new DataSetObserver() {
             public void onChanged() {
diff --git a/packages/SystemUI/src/com/android/systemui/recent/RecentsPanelView.java b/packages/SystemUI/src/com/android/systemui/recent/RecentsPanelView.java
index e2b3446..b8dc63d 100644
--- a/packages/SystemUI/src/com/android/systemui/recent/RecentsPanelView.java
+++ b/packages/SystemUI/src/com/android/systemui/recent/RecentsPanelView.java
@@ -19,6 +19,7 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import android.animation.Animator;
 import android.animation.LayoutTransition;
 import android.app.ActivityManager;
 import android.content.Context;
@@ -52,27 +53,33 @@
 import android.widget.TextView;
 
 import com.android.systemui.R;
+import com.android.systemui.statusbar.StatusBar;
+import com.android.systemui.statusbar.phone.PhoneStatusBar;
 import com.android.systemui.statusbar.tablet.StatusBarPanel;
 import com.android.systemui.statusbar.tablet.TabletStatusBar;
 
 public class RecentsPanelView extends RelativeLayout
-        implements OnItemClickListener, RecentsCallback, StatusBarPanel {
-    private static final int GLOW_PADDING = 15;
+        implements OnItemClickListener, RecentsCallback, StatusBarPanel, Animator.AnimatorListener {
     static final String TAG = "RecentsListView";
-    static final boolean DEBUG = TabletStatusBar.DEBUG;
+    static final boolean DEBUG = TabletStatusBar.DEBUG || PhoneStatusBar.DEBUG;
     private static final int DISPLAY_TASKS = 20;
     private static final int MAX_TASKS = DISPLAY_TASKS + 1; // allow extra for non-apps
-    private TabletStatusBar mBar;
+    private StatusBar mBar;
     private ArrayList<ActivityDescription> mActivityDescriptions;
     private int mIconDpi;
     private View mRecentsScrim;
     private View mRecentsGlowView;
     private View mRecentsContainer;
     private Bitmap mGlowBitmap;
+    // TODO: add these widgets attributes to the layout file
+    private int mGlowBitmapPaddingLeftPx;
+    private int mGlowBitmapPaddingTopPx;
+    private int mGlowBitmapPaddingRightPx;
+    private int mGlowBitmapPaddingBottomPx;
     private boolean mShowing;
     private Choreographer mChoreo;
     private View mRecentsDismissButton;
-    private ActvityDescriptionAdapter mListAdapter;
+    private ActivityDescriptionAdapter mListAdapter;
 
     /* package */ final static class ActivityDescription {
         int taskId; // application task id for curating apps
@@ -108,10 +115,10 @@
         ActivityDescription activityDescription;
     }
 
-    /* package */ final class ActvityDescriptionAdapter extends BaseAdapter {
+    /* package */ final class ActivityDescriptionAdapter extends BaseAdapter {
         private LayoutInflater mInflater;
 
-        public ActvityDescriptionAdapter(Context context) {
+        public ActivityDescriptionAdapter(Context context) {
             mInflater = LayoutInflater.from(context);
         }
 
@@ -183,6 +190,26 @@
         }
     }
 
+    public void onAnimationCancel(Animator animation) {
+    }
+
+    public void onAnimationEnd(Animator animation) {
+        if (mShowing) {
+            final LayoutTransition transitioner = new LayoutTransition();
+            ((ViewGroup)mRecentsContainer).setLayoutTransition(transitioner);
+            createCustomAnimations(transitioner);
+        } else {
+            ((ViewGroup)mRecentsContainer).setLayoutTransition(null);
+        }
+    }
+
+    public void onAnimationRepeat(Animator animation) {
+    }
+
+    public void onAnimationStart(Animator animation) {
+    }
+
+
     /**
      * We need to be aligned at the bottom.  LinearLayout can't do this, so instead,
      * let LinearLayout do all the hard work, and then shift everything down to the bottom.
@@ -201,7 +228,7 @@
         return mShowing;
     }
 
-    public void setBar(TabletStatusBar bar) {
+    public void setBar(StatusBar bar) {
         mBar = bar;
     }
 
@@ -217,7 +244,16 @@
                 & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE;
 
         mIconDpi = xlarge ? DisplayMetrics.DENSITY_HIGH : res.getDisplayMetrics().densityDpi;
+
         mGlowBitmap = BitmapFactory.decodeResource(res, R.drawable.recents_thumbnail_bg);
+        mGlowBitmapPaddingLeftPx =
+                res.getDimensionPixelSize(R.dimen.recents_thumbnail_bg_padding_left);
+        mGlowBitmapPaddingTopPx =
+                res.getDimensionPixelSize(R.dimen.recents_thumbnail_bg_padding_top);
+        mGlowBitmapPaddingRightPx =
+                res.getDimensionPixelSize(R.dimen.recents_thumbnail_bg_padding_right);
+        mGlowBitmapPaddingBottomPx =
+                res.getDimensionPixelSize(R.dimen.recents_thumbnail_bg_padding_bottom);
     }
 
     @Override
@@ -225,7 +261,7 @@
         super.onFinishInflate();
         mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
         mRecentsContainer = findViewById(R.id.recents_container);
-        mListAdapter = new ActvityDescriptionAdapter(mContext);
+        mListAdapter = new ActivityDescriptionAdapter(mContext);
         if (mRecentsContainer instanceof RecentsListView) {
             RecentsListView listView = (RecentsListView) mRecentsContainer;
             listView.setAdapter(mListAdapter);
@@ -246,13 +282,10 @@
             throw new IllegalArgumentException("missing RecentsListView/RecentsScrollView");
         }
 
-        final LayoutTransition transitioner = new LayoutTransition();
-        ((ViewGroup)mRecentsContainer).setLayoutTransition(transitioner);
-        createCustomAnimations(transitioner);
 
         mRecentsGlowView = findViewById(R.id.recents_glow);
         mRecentsScrim = (View) findViewById(R.id.recents_bg_protect);
-        mChoreo = new Choreographer(this, mRecentsScrim, mRecentsGlowView);
+        mChoreo = new Choreographer(this, mRecentsScrim, mRecentsGlowView, this);
         mRecentsDismissButton = findViewById(R.id.recents_dismiss_button);
         mRecentsDismissButton.setOnClickListener(new OnClickListener() {
             public void onClick(View v) {
@@ -402,10 +435,9 @@
             Log.v(TAG, "Source thumb: " + srcWidth + "x" + srcHeight);
             canvas.drawBitmap(thumbnail,
                     new Rect(0, 0, srcWidth-1, srcHeight-1),
-                    new RectF(GLOW_PADDING,
-                            GLOW_PADDING - 7.0f,
-                            outBitmap.getWidth() - GLOW_PADDING + 3.0f,
-                            outBitmap.getHeight() - GLOW_PADDING + 7.0f), paint);
+                    new RectF(mGlowBitmapPaddingLeftPx, mGlowBitmapPaddingTopPx,
+                            outBitmap.getWidth() - mGlowBitmapPaddingRightPx,
+                            outBitmap.getHeight() - mGlowBitmapPaddingBottomPx), paint);
         }
         return outBitmap;
     }
diff --git a/packages/SystemUI/src/com/android/systemui/recent/RecentsVerticalScrollView.java b/packages/SystemUI/src/com/android/systemui/recent/RecentsVerticalScrollView.java
index 54ec6b5..6a962cb 100644
--- a/packages/SystemUI/src/com/android/systemui/recent/RecentsVerticalScrollView.java
+++ b/packages/SystemUI/src/com/android/systemui/recent/RecentsVerticalScrollView.java
@@ -16,7 +16,7 @@
 
 package com.android.systemui.recent;
 
-import com.android.systemui.recent.RecentsPanelView.ActvityDescriptionAdapter;
+import com.android.systemui.recent.RecentsPanelView.ActivityDescriptionAdapter;
 
 import android.animation.Animator;
 import android.animation.Animator.AnimatorListener;
@@ -49,7 +49,7 @@
     private static final float THRESHHOLD = 50;
     private static final boolean DEBUG_INVALIDATE = false;
     private LinearLayout mLinearLayout;
-    private ActvityDescriptionAdapter mAdapter;
+    private ActivityDescriptionAdapter mAdapter;
     private RecentsCallback mCallback;
     protected int mLastScrollPosition;
     private View mCurrentView;
@@ -275,7 +275,7 @@
         }
     }
 
-    public void setAdapter(ActvityDescriptionAdapter adapter) {
+    public void setAdapter(ActivityDescriptionAdapter adapter) {
         mAdapter = adapter;
         mAdapter.registerDataSetObserver(new DataSetObserver() {
             public void onChanged() {
diff --git a/packages/SystemUI/src/com/android/systemui/recent/carousel/RecentApplicationsActivity.java b/packages/SystemUI/src/com/android/systemui/recent/carousel/RecentApplicationsActivity.java
deleted file mode 100644
index 45e230f..0000000
--- a/packages/SystemUI/src/com/android/systemui/recent/carousel/RecentApplicationsActivity.java
+++ /dev/null
@@ -1,532 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-package com.android.systemui.recent.carousel;
-
-import com.android.systemui.R;
-
-import com.android.ex.carousel.CarouselView;
-import com.android.ex.carousel.CarouselViewHelper;
-import com.android.ex.carousel.CarouselRS.CarouselCallback;
-import com.android.ex.carousel.CarouselViewHelper.DetailTextureParameters;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import android.app.Activity;
-import android.app.ActivityManager;
-import android.app.ActivityManagerNative;
-import android.app.IActivityManager;
-import android.app.IThumbnailReceiver;
-import android.app.ActivityManager.RunningTaskInfo;
-import android.content.ActivityNotFoundException;
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.ActivityInfo;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.content.res.Configuration;
-import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.Canvas;
-import android.graphics.Matrix;
-import android.graphics.Paint;
-import android.graphics.PaintFlagsDrawFilter;
-import android.graphics.PorterDuffXfermode;
-import android.graphics.PorterDuff;
-import android.graphics.Bitmap.Config;
-import android.graphics.drawable.Drawable;
-import android.graphics.PixelFormat;
-import android.os.Bundle;
-import android.os.RemoteException;
-import android.util.Log;
-import android.view.View;
-import android.view.View.MeasureSpec;
-import android.widget.TextView;
-
-public class RecentApplicationsActivity extends Activity {
-    private static final String TAG = "RecentApplicationsActivity";
-    private static boolean DBG = false;
-    private static final int CARD_SLOTS = 56;
-    private static final int VISIBLE_SLOTS = 7;
-    private static final int MAX_TASKS = VISIBLE_SLOTS * 2;
-
-    // TODO: these should be configurable
-    private static final int DETAIL_TEXTURE_MAX_WIDTH = 200;
-    private static final int DETAIL_TEXTURE_MAX_HEIGHT = 80;
-    private static final int TEXTURE_WIDTH = 256;
-    private static final int TEXTURE_HEIGHT = 256;
-
-    private ActivityManager mActivityManager;
-    private List<RunningTaskInfo> mRunningTaskList;
-    private boolean mPortraitMode = true;
-    private ArrayList<ActivityDescription> mActivityDescriptions
-            = new ArrayList<ActivityDescription>();
-    private CarouselView mCarouselView;
-    private LocalCarouselViewHelper mHelper;
-    private View mNoRecentsView;
-    private Bitmap mLoadingBitmap;
-    private Bitmap mRecentOverlay;
-    private boolean mHidden = false;
-    private boolean mHiding = false;
-    private DetailInfo mDetailInfo;
-
-    /**
-     * This class is a container for all items associated with the DetailView we'll
-     * be drawing to a bitmap and sending to Carousel.
-     *
-     */
-    static final class DetailInfo {
-        public DetailInfo(View _view, TextView _title, TextView _desc) {
-            view = _view;
-            title = _title;
-            description = _desc;
-        }
-
-        /**
-         * Draws view into the given bitmap, if provided
-         * @param bitmap
-         */
-        public Bitmap draw(Bitmap bitmap) {
-            resizeView(view, DETAIL_TEXTURE_MAX_WIDTH, DETAIL_TEXTURE_MAX_HEIGHT);
-            int desiredWidth = view.getWidth();
-            int desiredHeight = view.getHeight();
-            if (bitmap == null || desiredWidth != bitmap.getWidth()
-                    || desiredHeight != bitmap.getHeight()) {
-                bitmap = Bitmap.createBitmap(desiredWidth, desiredHeight, Config.ARGB_8888);
-            }
-            Canvas canvas = new Canvas(bitmap);
-            view.draw(canvas);
-            return bitmap;
-        }
-
-        /**
-         * Force a layout pass on the given view.
-         */
-        private void resizeView(View view, int maxWidth, int maxHeight) {
-            int widthSpec = MeasureSpec.getMode(MeasureSpec.AT_MOST)
-                    | MeasureSpec.getSize(maxWidth);
-            int heightSpec = MeasureSpec.getMode(MeasureSpec.AT_MOST)
-                    | MeasureSpec.getSize(maxHeight);
-            view.measure(widthSpec, heightSpec);
-            view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
-            Log.v(TAG, "RESIZED VIEW: " + view.getWidth() + ", " + view.getHeight());
-        }
-
-        public View view;
-        public TextView title;
-        public TextView description;
-    }
-
-    static class ActivityDescription {
-        int id;
-        Bitmap thumbnail; // generated by Activity.onCreateThumbnail()
-        Drawable icon; // application package icon
-        String label; // application package label
-        CharSequence description; // generated by Activity.onCreateDescription()
-        Intent intent; // launch intent for application
-        Matrix matrix; // arbitrary rotation matrix to correct orientation
-        int position; // position in list
-
-        public ActivityDescription(Bitmap _thumbnail,
-                Drawable _icon, String _label, String _desc, int _id, int _pos)
-        {
-            thumbnail = _thumbnail;
-            icon = _icon;
-            label = _label;
-            description = _desc;
-            id = _id;
-            position = _pos;
-        }
-
-        public void clear() {
-            icon = null;
-            thumbnail = null;
-            label = null;
-            description = null;
-            intent = null;
-            matrix = null;
-            id = -1;
-            position = -1;
-        }
-    };
-
-    private ActivityDescription findActivityDescription(int id) {
-        for (int i = 0; i < mActivityDescriptions.size(); i++) {
-            ActivityDescription item = mActivityDescriptions.get(i);
-            if (item != null && item.id == id) {
-                return item;
-            }
-        }
-        return null;
-    }
-
-    private class LocalCarouselViewHelper extends CarouselViewHelper {
-        private DetailTextureParameters mDetailParams = new DetailTextureParameters(10.0f, 20.0f);
-
-        public LocalCarouselViewHelper(Context context) {
-            super(context);
-        }
-
-        @Override
-        public DetailTextureParameters getDetailTextureParameters(int id) {
-            return mDetailParams;
-        }
-
-        public void onCardSelected(int n) {
-            if (n < mActivityDescriptions.size()) {
-                ActivityDescription item = mActivityDescriptions.get(n);
-                if (item.id >= 0) {
-                    // This is an active task; it should just go to the foreground.
-                    final ActivityManager am = (ActivityManager)
-                            getSystemService(Context.ACTIVITY_SERVICE);
-                    am.moveTaskToFront(item.id, ActivityManager.MOVE_TASK_WITH_HOME);
-                } else if (item.intent != null) {
-                    // prepare a launch intent and send it
-                    item.intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY
-                            | Intent.FLAG_ACTIVITY_TASK_ON_HOME);
-                    try {
-                        if (DBG) Log.v(TAG, "Starting intent " + item.intent);
-                        startActivity(item.intent);
-                        overridePendingTransition(R.anim.recent_app_enter, R.anim.recent_app_leave);
-                    } catch (ActivityNotFoundException e) {
-                        if (DBG) Log.w("Recent", "Unable to launch recent task", e);
-                    }
-                    finish();
-                }
-            }
-        }
-
-        @Override
-        public Bitmap getTexture(final int id) {
-            if (DBG) Log.v(TAG, "onRequestTexture(" + id + ")");
-            ActivityDescription info;
-            synchronized(mActivityDescriptions) {
-                info = mActivityDescriptions.get(id);
-            }
-            Bitmap bitmap = null;
-            if (info != null) {
-                bitmap = compositeBitmap(info);
-            }
-            return bitmap;
-        }
-
-        @Override
-        public Bitmap getDetailTexture(int n) {
-            Bitmap bitmap = null;
-            if (n < mActivityDescriptions.size()) {
-                ActivityDescription item = mActivityDescriptions.get(n);
-                mDetailInfo.title.setText(item.label);
-                mDetailInfo.description.setText(item.description);
-                bitmap = mDetailInfo.draw(null);
-            }
-            return bitmap;
-        }
-    };
-
-    private Bitmap compositeBitmap(ActivityDescription info) {
-        final int targetWidth = TEXTURE_WIDTH;
-        final int targetHeight = TEXTURE_HEIGHT;
-        final int border = 3; // inset along the edge for thumnnail content
-        final int overlap = 1; // how many pixels of overlap between border and thumbnail
-        final Resources res = getResources();
-        if (mRecentOverlay == null) {
-            mRecentOverlay = BitmapFactory.decodeResource(res, R.drawable.recent_overlay);
-        }
-
-        // Create a bitmap of the proper size/format and set the canvas to draw to it
-        final Bitmap result = Bitmap.createBitmap(targetWidth, targetHeight, Bitmap.Config.ARGB_8888);
-        final Canvas canvas = new Canvas(result);
-        canvas.setDrawFilter(new PaintFlagsDrawFilter(Paint.DITHER_FLAG, Paint.FILTER_BITMAP_FLAG));
-        Paint paint = new Paint();
-        paint.setFilterBitmap(false);
-
-        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
-        canvas.save();
-        if (info.thumbnail != null) {
-            // Draw the thumbnail
-            int sourceWidth = targetWidth - 2 * (border - overlap);
-            int sourceHeight = targetHeight - 2 * (border - overlap);
-            final float scaleX = (float) sourceWidth / info.thumbnail.getWidth();
-            final float scaleY = (float) sourceHeight / info.thumbnail.getHeight();
-            canvas.translate(border * 0.5f, border * 0.5f);
-            canvas.scale(scaleX, scaleY);
-            canvas.drawBitmap(info.thumbnail, 0, 0, paint);
-        } else {
-            // Draw the Loading bitmap placeholder, TODO: Remove when RS handles blending
-            final float scaleX = (float) targetWidth / mLoadingBitmap.getWidth();
-            final float scaleY = (float) targetHeight / mLoadingBitmap.getHeight();
-            canvas.scale(scaleX, scaleY);
-            canvas.drawBitmap(mLoadingBitmap, 0, 0, paint);
-        }
-        canvas.restore();
-
-        // Draw overlay
-        canvas.save();
-        final float scaleOverlayX = (float) targetWidth / mRecentOverlay.getWidth();
-        final float scaleOverlayY = (float) targetHeight / mRecentOverlay.getHeight();
-        canvas.scale(scaleOverlayX, scaleOverlayY);
-        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.ADD));
-        canvas.drawBitmap(mRecentOverlay, 0, 0, paint);
-        canvas.restore();
-
-        // Draw icon
-        if (info.icon != null) {
-            canvas.save();
-            info.icon.draw(canvas);
-            canvas.restore();
-        }
-
-        return result;
-    }
-
-    private final IThumbnailReceiver mThumbnailReceiver = new IThumbnailReceiver.Stub() {
-
-        public void finished() throws RemoteException {
-
-        }
-
-        public void newThumbnail(final int id, final Bitmap bitmap, CharSequence description)
-                throws RemoteException {
-            int w = bitmap.getWidth();
-            int h = bitmap.getHeight();
-            if (DBG) Log.v(TAG, "New thumbnail for id=" + id + ", dimensions=" + w + "x" + h
-                    + " description '" + description + "'");
-            ActivityDescription info = findActivityDescription(id);
-            if (info != null) {
-                info.thumbnail = bitmap;
-                info.description = description;
-                final int thumbWidth = bitmap.getWidth();
-                final int thumbHeight = bitmap.getHeight();
-                if ((mPortraitMode && thumbWidth > thumbHeight)
-                        || (!mPortraitMode && thumbWidth < thumbHeight)) {
-                    Matrix matrix = new Matrix();
-                    matrix.setRotate(90.0f, (float) thumbWidth / 2, (float) thumbHeight / 2);
-                    info.matrix = matrix;
-                } else {
-                    info.matrix = null;
-                }
-                // Force Carousel to request new textures for this item.
-                mCarouselView.setTextureForItem(info.position, null);
-                mCarouselView.setDetailTextureForItem(info.position, 0, 0, 0, 0, null);
-            } else {
-                if (DBG) Log.v(TAG, "Can't find view for id " + id);
-            }
-        }
-    };
-
-    /**
-     * We never really finish() RecentApplicationsActivity, since we don't want to
-     * get destroyed and pay the start-up cost to restart it.
-     */
-    @Override
-    public void finish() {
-        moveTaskToBack(true);
-    }
-
-    @Override
-    protected void onNewIntent(Intent intent) {
-        mHidden = !mHidden;
-        if (mHidden) {
-            mHiding = true;
-            moveTaskToBack(true);
-        } else {
-            mHiding = false;
-        }
-        super.onNewIntent(intent);
-    }
-
-    @Override
-    protected void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-
-        final Resources res = getResources();
-        final View decorView = getWindow().getDecorView();
-
-        getWindow().getDecorView().setBackgroundColor(0x80000000);
-
-        if (mCarouselView == null) {
-            long t = System.currentTimeMillis();
-            setContentView(R.layout.recent_apps_activity);
-            long elapsed = System.currentTimeMillis() - t;
-            Log.v(TAG, "Recents layout took " + elapsed + "ms to load");
-            mLoadingBitmap = BitmapFactory.decodeResource(res, R.drawable.recent_rez_border);
-            mCarouselView = (CarouselView)findViewById(R.id.carousel);
-            mHelper = new LocalCarouselViewHelper(this);
-            mHelper.setCarouselView(mCarouselView);
-
-            mCarouselView.setSlotCount(CARD_SLOTS);
-            mCarouselView.setVisibleSlots(VISIBLE_SLOTS);
-            mCarouselView.createCards(0);
-            mCarouselView.setStartAngle((float) -(2.0f*Math.PI * 5 / CARD_SLOTS));
-            mCarouselView.setDefaultBitmap(mLoadingBitmap);
-            mCarouselView.setLoadingBitmap(mLoadingBitmap);
-            mCarouselView.setRezInCardCount(3.0f);
-            mCarouselView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
-
-            mNoRecentsView = (View) findViewById(R.id.no_applications_message);
-
-            mActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
-            mPortraitMode = decorView.getHeight() > decorView.getWidth();
-
-            // Load detail view which will be used to render text
-            View detail = getLayoutInflater().inflate(R.layout.recents_detail_view, null);
-            TextView title = (TextView) detail.findViewById(R.id.app_title);
-            TextView description = (TextView) detail.findViewById(R.id.app_description);
-            mDetailInfo = new DetailInfo(detail, title, description);
-
-            refresh();
-        }
-    }
-
-    @Override
-    protected void onResume() {
-        super.onResume();
-        refresh();
-    }
-
-    @Override
-    public void onConfigurationChanged(Configuration newConfig) {
-        super.onConfigurationChanged(newConfig);
-        mPortraitMode = newConfig.orientation == Configuration.ORIENTATION_PORTRAIT;
-        if (DBG) Log.v(TAG, "CONFIG CHANGE, mPortraitMode = " + mPortraitMode);
-        refresh();
-    }
-
-    void updateRunningTasks() {
-        mRunningTaskList = mActivityManager.getRunningTasks(MAX_TASKS,
-                0, mThumbnailReceiver);
-        if (DBG) Log.v(TAG, "Portrait: " + mPortraitMode);
-        for (RunningTaskInfo r : mRunningTaskList) {
-            if (r.thumbnail != null) {
-                int thumbWidth = r.thumbnail.getWidth();
-                int thumbHeight = r.thumbnail.getHeight();
-                if (DBG) Log.v(TAG, "Got thumbnail " + thumbWidth + "x" + thumbHeight);
-                ActivityDescription desc = findActivityDescription(r.id);
-                if (desc != null) {
-                    desc.thumbnail = r.thumbnail;
-                    desc.description = r.description;
-                    if ((mPortraitMode && thumbWidth > thumbHeight)
-                            || (!mPortraitMode && thumbWidth < thumbHeight)) {
-                        Matrix matrix = new Matrix();
-                        matrix.setRotate(90.0f, (float) thumbWidth / 2, (float) thumbHeight / 2);
-                        desc.matrix = matrix;
-                    }
-                } else {
-                    if (DBG) Log.v(TAG, "Couldn't find ActivityDesc for id=" + r.id);
-                }
-            } else {
-                if (DBG) Log.v(TAG, "*** RUNNING THUMBNAIL WAS NULL ***");
-            }
-        }
-    }
-
-    private void updateRecentTasks() {
-        final PackageManager pm = getPackageManager();
-        final ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
-
-        final List<ActivityManager.RecentTaskInfo> recentTasks =
-                am.getRecentTasks(MAX_TASKS, ActivityManager.RECENT_IGNORE_UNAVAILABLE);
-
-        ActivityInfo homeInfo = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME)
-                    .resolveActivityInfo(pm, 0);
-
-        // IconUtilities iconUtilities = new IconUtilities(this); // FIXME
-
-        int numTasks = recentTasks.size();
-        mActivityDescriptions.clear();
-        for (int i = 0, index = 0; i < numTasks && (index < MAX_TASKS); ++i) {
-            final ActivityManager.RecentTaskInfo recentInfo = recentTasks.get(i);
-
-            Intent intent = new Intent(recentInfo.baseIntent);
-            if (recentInfo.origActivity != null) {
-                intent.setComponent(recentInfo.origActivity);
-            }
-
-            // Skip the current home activity.
-            if (homeInfo != null
-                    && homeInfo.packageName.equals(intent.getComponent().getPackageName())
-                    && homeInfo.name.equals(intent.getComponent().getClassName())) {
-                continue;
-            }
-
-            intent.setFlags((intent.getFlags()&~Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED)
-                    | Intent.FLAG_ACTIVITY_NEW_TASK);
-            final ResolveInfo resolveInfo = pm.resolveActivity(intent, 0);
-            if (resolveInfo != null) {
-                final ActivityInfo info = resolveInfo.activityInfo;
-                final String title = info.loadLabel(pm).toString();
-                Drawable icon = info.loadIcon(pm);
-
-                int id = recentTasks.get(i).id;
-                if (id != -1 && title != null && title.length() > 0 && icon != null) {
-                    // icon = null; FIXME: iconUtilities.createIconDrawable(icon);
-                    ActivityDescription item = new ActivityDescription(
-                            null, icon, title, null, id, index);
-                    item.intent = intent;
-                    mActivityDescriptions.add(item);
-                    if (DBG) Log.v(TAG, "Added item[" + index
-                            + "], id=" + item.id
-                            + ", title=" + item.label);
-                    ++index;
-                } else {
-                    if (DBG) Log.v(TAG, "SKIPPING item " + id);
-                }
-            }
-        }
-    }
-
-    private final Runnable mRefreshRunnable = new Runnable() {
-        public void run() {
-            updateRecentTasks();
-            updateRunningTasks();
-            showCarousel(mActivityDescriptions.size() > 0);
-        }
-    };
-
-    private void showCarousel(boolean show) {
-        if (show) {
-            mCarouselView.createCards(mActivityDescriptions.size());
-            for (int i = 1; i < mActivityDescriptions.size(); i++) {
-                // Force Carousel to update textures. Note we don't do this for the first item,
-                // since it will be updated when mThumbnailReceiver returns a thumbnail.
-                // TODO: only do this for apps that have changed.
-                mCarouselView.setTextureForItem(i, null);
-                mCarouselView.setDetailTextureForItem(i, 0, 0, 0, 0, null);
-            }
-            // Make carousel visible
-            mNoRecentsView.setVisibility(View.GONE);
-            mCarouselView.setVisibility(View.VISIBLE);
-            mCarouselView.createCards(mActivityDescriptions.size());
-        } else {
-            // show "No Recent Tasks"
-            mNoRecentsView.setVisibility(View.VISIBLE);
-            mCarouselView.setVisibility(View.GONE);
-        }
-    }
-
-    private void refresh() {
-        if (!mHiding && mCarouselView != null) {
-            // Don't update the view now. Instead, post a request so it happens next time
-            // we reach the looper after a delay. This way we can fold multiple refreshes
-            // into just the latest.
-            mCarouselView.removeCallbacks(mRefreshRunnable);
-            mCarouselView.postDelayed(mRefreshRunnable, 50);
-        }
-    }
-}
diff --git a/packages/SystemUI/src/com/android/systemui/recent/carousel/RecentApplicationsCarouselView.java b/packages/SystemUI/src/com/android/systemui/recent/carousel/RecentApplicationsCarouselView.java
deleted file mode 100644
index 1afb086..0000000
--- a/packages/SystemUI/src/com/android/systemui/recent/carousel/RecentApplicationsCarouselView.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.systemui.recent.carousel;
-
-import android.content.Context;
-import android.util.AttributeSet;
-
-import com.android.ex.carousel.CarouselView;
-import com.android.systemui.R;
-
-public class RecentApplicationsCarouselView extends CarouselView {
-
-    public RecentApplicationsCarouselView(Context context) {
-        this(context, null);
-    }
-
-    public RecentApplicationsCarouselView(Context context, AttributeSet attrs) {
-        super(context, attrs);
-    }
-
-    public Info getRenderScriptInfo() {
-        return new Info(R.raw.carousel);
-    }
-
-}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java b/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java
index da1e1c5..62d7500 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java
@@ -56,12 +56,12 @@
 
     private static final int MSG_SET_LIGHTS_ON          = 7 << MSG_SHIFT;
 
-    private static final int MSG_SHOW_MENU              = 8 << MSG_SHIFT;
+    private static final int MSG_TOP_APP_WINDOW_CHANGED = 8 << MSG_SHIFT;
     private static final int MSG_SHOW_IME_BUTTON        = 9 << MSG_SHIFT;
     private static final int MSG_SET_HARD_KEYBOARD_STATUS = 10 << MSG_SHIFT;
     
     private static final int MSG_USER_ACTIVITY          = 11 << MSG_SHIFT;
-
+    private static final int MSG_TOGGLE_RECENT_APPS       = 12 << MSG_SHIFT;
 
     private StatusBarIconList mList;
     private Callbacks mCallbacks;
@@ -87,10 +87,11 @@
         public void animateExpand();
         public void animateCollapse();
         public void setLightsOn(boolean on);
-        public void setMenuKeyVisible(boolean visible);
+        public void topAppWindowChanged(boolean visible);
         public void setImeWindowStatus(IBinder token, int vis, int backDisposition);
         public void setHardKeyboardStatus(boolean available, boolean enabled);
         public void userActivity();
+        public void toggleRecentApps();
     }
 
     public CommandQueue(Callbacks callbacks, StatusBarIconList list) {
@@ -166,10 +167,11 @@
         }
     }
 
-    public void setMenuKeyVisible(boolean visible) {
+    public void topAppWindowChanged(boolean menuVisible) {
         synchronized (mList) {
-            mHandler.removeMessages(MSG_SHOW_MENU);
-            mHandler.obtainMessage(MSG_SHOW_MENU, visible ? 1 : 0, 0, null).sendToTarget();
+            mHandler.removeMessages(MSG_TOP_APP_WINDOW_CHANGED);
+            mHandler.obtainMessage(MSG_TOP_APP_WINDOW_CHANGED, menuVisible ? 1 : 0, 0,
+                    null).sendToTarget();
         }
     }
 
@@ -196,6 +198,13 @@
         }
     }
 
+    public void toggleRecentApps() {
+        synchronized (mList) {
+            mHandler.removeMessages(MSG_TOGGLE_RECENT_APPS);
+            mHandler.obtainMessage(MSG_TOGGLE_RECENT_APPS, 0, 0, null).sendToTarget();
+        }
+    }
+
     private final class H extends Handler {
         public void handleMessage(Message msg) {
             final int what = msg.what & MSG_MASK;
@@ -253,8 +262,8 @@
                 case MSG_SET_LIGHTS_ON:
                     mCallbacks.setLightsOn(msg.arg1 != 0);
                     break;
-                case MSG_SHOW_MENU:
-                    mCallbacks.setMenuKeyVisible(msg.arg1 != 0);
+                case MSG_TOP_APP_WINDOW_CHANGED:
+                    mCallbacks.topAppWindowChanged(msg.arg1 != 0);
                     break;
                 case MSG_SHOW_IME_BUTTON:
                     mCallbacks.setImeWindowStatus((IBinder)msg.obj, msg.arg1, msg.arg2);
@@ -265,6 +274,9 @@
                 case MSG_USER_ACTIVITY:
                     mCallbacks.userActivity();
                     break;
+                case MSG_TOGGLE_RECENT_APPS:
+                    mCallbacks.toggleRecentApps();
+                    break;
             }
         }
     }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/StatusBar.java
index 23ae823..ca75138 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/StatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/StatusBar.java
@@ -53,6 +53,7 @@
     protected abstract View makeStatusBarView();
     protected abstract int getStatusBarGravity();
     public abstract int getStatusBarHeight();
+    public abstract void animateCollapse();
 
     private DoNotDisturb mDoNotDisturb;
 
@@ -78,7 +79,7 @@
 
         disable(switches[0]);
         setLightsOn(switches[1] != 0);
-        setMenuKeyVisible(switches[2] != 0);
+        topAppWindowChanged(switches[2] != 0);
         // StatusBarManagerService has a back up of IME token and it's restored here.
         setImeWindowStatus(binders.get(0), switches[3], switches[4]);
         setHardKeyboardStatus(switches[5] != 0, switches[6] != 0);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarIconView.java b/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarIconView.java
index dbfbe11..d9d9c06 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarIconView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarIconView.java
@@ -29,6 +29,8 @@
 import android.view.ViewDebug;
 import android.widget.FrameLayout;
 
+import java.text.NumberFormat;
+
 import com.android.internal.statusbar.StatusBarIcon;
 
 import com.android.systemui.R;
@@ -180,7 +182,18 @@
     }
 
     void placeNumber() {
-        final String str = mNumberText = Integer.toString(mIcon.number);
+        final String str;
+        final int tooBig = mContext.getResources().getInteger(
+                android.R.integer.status_bar_notification_info_maxnum);
+        if (mIcon.number > tooBig) {
+            str = mContext.getResources().getString(
+                        android.R.string.status_bar_notification_info_overflow);
+        } else {
+            NumberFormat f = NumberFormat.getIntegerInstance();
+            str = f.format(mIcon.number);
+        }
+        mNumberText = str;
+
         final int w = getWidth();
         final int h = getHeight();
         final Rect r = new Rect();
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ExpandedView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ExpandedView.java
index 92b8976..51fc7c2 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ExpandedView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ExpandedView.java
@@ -16,6 +16,7 @@
 
 package com.android.systemui.statusbar.phone;
 
+import android.animation.LayoutTransition;
 import android.content.Context;
 import android.util.AttributeSet;
 import android.view.Display;
@@ -37,6 +38,8 @@
     @Override
     protected void onFinishInflate() {
         super.onFinishInflate();
+
+        setLayerType(LAYER_TYPE_HARDWARE, null);
     }
 
     /** We want to shrink down to 0, and ignore the background. */
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
index 7d6c57b..7dafb892 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
@@ -36,6 +36,8 @@
 import com.android.systemui.R;
 
 public class NavigationBarView extends LinearLayout {
+    final static boolean NAVBAR_ALWAYS_AT_RIGHT = true;
+
     protected IStatusBarService mBarService;
     final Display mDisplay;
     View[] mRotatedViews = new View[4];
@@ -88,7 +90,9 @@
 
         mRotatedViews[Surface.ROTATION_90] = findViewById(R.id.rot90);
         
-        mRotatedViews[Surface.ROTATION_270] = findViewById(R.id.rot270);
+        mRotatedViews[Surface.ROTATION_270] = NAVBAR_ALWAYS_AT_RIGHT
+                                                ? findViewById(R.id.rot90)
+                                                : findViewById(R.id.rot270);
     }
 
     @Override
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
index e66a1a2..0b82123 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
@@ -28,10 +28,12 @@
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.res.Resources;
+import android.content.res.Configuration;
 import android.graphics.PixelFormat;
 import android.graphics.Rect;
 import android.graphics.drawable.Drawable;
 import android.net.Uri;
+import android.os.Bundle;
 import android.os.IBinder;
 import android.os.RemoteException;
 import android.os.Handler;
@@ -74,6 +76,7 @@
 import com.android.internal.statusbar.StatusBarNotification;
 
 import com.android.systemui.R;
+import com.android.systemui.recent.RecentsPanelView;
 import com.android.systemui.statusbar.NotificationData;
 import com.android.systemui.statusbar.StatusBar;
 import com.android.systemui.statusbar.StatusBarIconView;
@@ -83,6 +86,7 @@
 public class PhoneStatusBar extends StatusBar {
     static final String TAG = "PhoneStatusBar";
     static final boolean SPEW = false;
+    public static final boolean DEBUG = false;
 
     public static final String ACTION_STATUSBAR_START
             = "com.android.internal.policy.statusbar.START";
@@ -94,6 +98,8 @@
     private static final int MSG_ANIMATE_REVEAL = 1001;
     private static final int MSG_SHOW_INTRUDER = 1002;
     private static final int MSG_HIDE_INTRUDER = 1003;
+    private static final int MSG_OPEN_RECENTS_PANEL = 1020;
+    private static final int MSG_CLOSE_RECENTS_PANEL = 1021;
 
     // will likely move to a resource or other tunable param at some point
     private static final int INTRUDER_ALERT_DECAY_MS = 10000;
@@ -130,11 +136,11 @@
     // ongoing
     NotificationData mOngoing = new NotificationData();
     TextView mOngoingTitle;
-    LinearLayout mOngoingItems;
+    ViewGroup mOngoingItems;
     // latest
     NotificationData mLatest = new NotificationData();
     TextView mLatestTitle;
-    LinearLayout mLatestItems;
+    ViewGroup mLatestItems;
     // position
     int[] mPositionTmp = new int[2];
     boolean mExpanded;
@@ -160,6 +166,9 @@
     private View mTickerView;
     private boolean mTicking;
 
+    // Recent applications
+    private RecentsPanelView mRecentsPanel;
+
     // Tracking finger for opening/closing.
     int mEdgeBorder; // corresponds to R.dimen.status_bar_edge_ignore
     boolean mTracking;
@@ -268,9 +277,9 @@
         mExpandedView = expanded;
         mExpandedContents = expanded.findViewById(R.id.notificationLinearLayout);
         mOngoingTitle = (TextView)expanded.findViewById(R.id.ongoingTitle);
-        mOngoingItems = (LinearLayout)expanded.findViewById(R.id.ongoingItems);
+        mOngoingItems = (ViewGroup)expanded.findViewById(R.id.ongoingItems);
         mLatestTitle = (TextView)expanded.findViewById(R.id.latestTitle);
-        mLatestItems = (LinearLayout)expanded.findViewById(R.id.latestItems);
+        mLatestItems = (ViewGroup)expanded.findViewById(R.id.latestItems);
         mNoNotificationsTitle = (TextView)expanded.findViewById(R.id.noNotificationsTitle);
         mClearButton = (TextView)expanded.findViewById(R.id.clear_all_button);
         mClearButton.setOnClickListener(mClearButtonListener);
@@ -296,6 +305,9 @@
         setAreThereNotifications();
         mDateView.setVisibility(View.INVISIBLE);
 
+        // Recents Panel
+        initializeRecentsPanel();
+
         // receive broadcasts
         IntentFilter filter = new IntentFilter();
         filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
@@ -306,6 +318,51 @@
         return sb;
     }
 
+    protected WindowManager.LayoutParams getRecentsLayoutParams() {
+        boolean translucent = false;
+        WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
+                ViewGroup.LayoutParams.WRAP_CONTENT,
+                ViewGroup.LayoutParams.WRAP_CONTENT,
+                WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL,
+                WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
+                | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM
+                | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
+                | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
+                (translucent ? PixelFormat.OPAQUE : PixelFormat.TRANSLUCENT));
+        lp.gravity = Gravity.BOTTOM | Gravity.LEFT;
+        lp.setTitle("RecentsPanel");
+        lp.windowAnimations = R.style.Animation_RecentPanel;
+        lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED
+        | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING;
+        return lp;
+    }
+
+    protected void initializeRecentsPanel() {
+        // Recents Panel
+        boolean visible = false;
+        if (mRecentsPanel != null) {
+            visible = mRecentsPanel.getVisibility() == View.VISIBLE;
+            WindowManagerImpl.getDefault().removeView(mRecentsPanel);
+        }
+        mRecentsPanel = (RecentsPanelView) View.inflate(mContext,
+                R.layout.status_bar_recent_panel, null);
+
+        mRecentsPanel.setOnTouchListener(new TouchOutsideListener(MSG_CLOSE_RECENTS_PANEL,
+                mRecentsPanel));
+        mRecentsPanel.setVisibility(View.GONE);
+        WindowManager.LayoutParams lp = getRecentsLayoutParams();
+
+        WindowManagerImpl.getDefault().addView(mRecentsPanel, lp);
+        mRecentsPanel.setBar(this);
+        if (visible) {
+            // need to set visibility to View.GONE earlier since that
+            // triggers refreshing application list
+            mRecentsPanel.setVisibility(View.VISIBLE);
+            mRecentsPanel.show(true, false);
+        }
+
+    }
+
     protected int getStatusBarGravity() {
         return Gravity.TOP | Gravity.FILL_HORIZONTAL;
     }
@@ -349,7 +406,8 @@
                     | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
                     | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING
                     | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
-                    | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH,
+                    | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
+                    | WindowManager.LayoutParams.FLAG_SLIPPERY,
                 PixelFormat.TRANSLUCENT);
 
         lp.setTitle("NavigationBar");
@@ -360,7 +418,9 @@
                 break;
             case Surface.ROTATION_270:
                 // device has been turned 90deg clockwise
-                lp.gravity = Gravity.LEFT | Gravity.FILL_VERTICAL;
+                lp.gravity = (NavigationBarView.NAVBAR_ALWAYS_AT_RIGHT ? Gravity.RIGHT
+                                                                       : Gravity.LEFT) 
+                             | Gravity.FILL_VERTICAL;
                 break;
             default:
                 lp.gravity = Gravity.BOTTOM | Gravity.FILL_HORIZONTAL;
@@ -578,6 +638,12 @@
         }
     }
 
+    @Override
+    protected void onConfigurationChanged(Configuration newConfig) {
+        initializeRecentsPanel();
+    }
+
+
     View[] makeNotificationView(StatusBarNotification notification, ViewGroup parent) {
         Notification n = notification.notification;
         RemoteViews remoteViews = n.contentView;
@@ -786,6 +852,21 @@
                 case MSG_HIDE_INTRUDER:
                     setIntruderAlertVisibility(false);
                     break;
+                case MSG_OPEN_RECENTS_PANEL:
+                    if (DEBUG) Slog.d(TAG, "opening recents panel");
+                    if (mRecentsPanel != null) {
+                        disable(StatusBarManager.DISABLE_BACK);
+                        mRecentsPanel.setVisibility(View.VISIBLE);
+                        mRecentsPanel.show(true, true);
+                    }
+                    break;
+                case MSG_CLOSE_RECENTS_PANEL:
+                    if (DEBUG) Slog.d(TAG, "closing recents panel");
+                    if (mRecentsPanel != null && mRecentsPanel.isShowing()) {
+                        disable(StatusBarManager.DISABLE_NONE);
+                        mRecentsPanel.show(false, true);
+                    }
+                    break;
             }
         }
     }
@@ -832,6 +913,10 @@
     }
 
     public void animateCollapse() {
+        animateCollapse(false);
+    }
+
+    public void animateCollapse(boolean excludeRecents) {
         if (SPEW) {
             Slog.d(TAG, "animateCollapse(): mExpanded=" + mExpanded
                     + " mExpandedVisible=" + mExpandedVisible
@@ -841,6 +926,11 @@
                     + " mAnimVel=" + mAnimVel);
         }
 
+        if (!excludeRecents) {
+            mHandler.removeMessages(MSG_CLOSE_RECENTS_PANEL);
+            mHandler.sendEmptyMessage(MSG_CLOSE_RECENTS_PANEL);
+        }
+
         if (!mExpandedVisible) {
             return;
         }
@@ -1141,7 +1231,7 @@
     }
 
     // Not supported
-    public void setMenuKeyVisible(boolean visible) { }
+    public void topAppWindowChanged(boolean visible) { }
     public void setImeWindowStatus(IBinder token, int vis, int backDisposition) { }
     @Override
     public void setHardKeyboardStatus(boolean available, boolean enabled) { }
@@ -1554,6 +1644,13 @@
         } catch (RemoteException ex) { }
     }
 
+    public void toggleRecentApps() {
+        int msg = (mRecentsPanel.getVisibility() == View.GONE)
+                ? MSG_OPEN_RECENTS_PANEL : MSG_CLOSE_RECENTS_PANEL;
+        mHandler.removeMessages(msg);
+        mHandler.sendEmptyMessage(msg);
+    }
+
     /**
      * The LEDs are turned o)ff when the notification panel is shown, even just a little bit.
      * This was added last-minute and is inconsistent with the way the rest of the notifications
@@ -1622,7 +1719,14 @@
             String action = intent.getAction();
             if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)
                     || Intent.ACTION_SCREEN_OFF.equals(action)) {
-                animateCollapse();
+                boolean excludeRecents = false;
+                if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)) {
+                    String reason = intent.getExtras().getString("reason");
+                    if (reason != null) {
+                        excludeRecents = reason.equals("recentapps");
+                    }
+                }
+                animateCollapse(excludeRecents);
             }
             else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) {
                 repositionNavigationBar();
@@ -1687,5 +1791,27 @@
             vibrate();
         }
     };
+
+    public class TouchOutsideListener implements View.OnTouchListener {
+        private int mMsg;
+        private RecentsPanelView mPanel;
+
+        public TouchOutsideListener(int msg, RecentsPanelView panel) {
+            mMsg = msg;
+            mPanel = panel;
+        }
+
+        public boolean onTouch(View v, MotionEvent ev) {
+            final int action = ev.getAction();
+            if (action == MotionEvent.ACTION_OUTSIDE
+                || (action == MotionEvent.ACTION_DOWN
+                    && !mPanel.isInContentArea((int)ev.getX(), (int)ev.getY()))) {
+                mHandler.removeMessages(mMsg);
+                mHandler.sendEmptyMessage(mMsg);
+                return true;
+            }
+            return false;
+        }
+    }
 }
 
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/CompatModeButton.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/CompatModeButton.java
new file mode 100644
index 0000000..7fbf734
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/CompatModeButton.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.statusbar.policy;
+
+import android.app.ActivityManager;
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.os.RemoteException;
+import android.util.AttributeSet;
+import android.util.Slog;
+import android.view.View;
+import android.widget.ImageView;
+
+import com.android.systemui.R;
+
+public class CompatModeButton extends ImageView {
+    private static final boolean DEBUG = false;
+    private static final String TAG = "StatusBar.CompatModeButton";
+
+    private ActivityManager mAM;
+
+    public CompatModeButton(Context context, AttributeSet attrs) {
+        this(context, attrs, 0);
+    }
+
+    public CompatModeButton(Context context, AttributeSet attrs, int defStyle) {
+        super(context, attrs);
+
+        setClickable(true);
+
+        mAM = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
+
+        refresh();
+    }
+
+    public void refresh() {
+        int mode = mAM.getFrontActivityScreenCompatMode();
+        final boolean vis = (mode != ActivityManager.COMPAT_MODE_NEVER
+                          && mode != ActivityManager.COMPAT_MODE_ALWAYS);
+        if (DEBUG) Slog.d(TAG, "compat mode is " + mode + "; icon will " + (vis ? "show" : "hide"));
+        setVisibility(vis ? View.VISIBLE : View.GONE);
+    }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkController.java
index 70a78df..3175a99 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkController.java
@@ -446,12 +446,14 @@
     }
 
     boolean isCdmaEri() {
-        final int iconIndex = mServiceState.getCdmaEriIconIndex();
-        if (iconIndex != EriInfo.ROAMING_INDICATOR_OFF) {
-            final int iconMode = mServiceState.getCdmaEriIconMode();
-            if (iconMode == EriInfo.ROAMING_ICON_MODE_NORMAL
-                    || iconMode == EriInfo.ROAMING_ICON_MODE_FLASH) {
-                return true;
+        if (mServiceState != null) {
+            final int iconIndex = mServiceState.getCdmaEriIconIndex();
+            if (iconIndex != EriInfo.ROAMING_INDICATOR_OFF) {
+                final int iconMode = mServiceState.getCdmaEriIconMode();
+                if (iconMode == EriInfo.ROAMING_ICON_MODE_NORMAL
+                        || iconMode == EriInfo.ROAMING_ICON_MODE_FLASH) {
+                    return true;
+                }
             }
         }
         return false;
@@ -854,7 +856,7 @@
         pw.print("  mDataActivity=");
         pw.println(mDataActivity);
         pw.print("  mServiceState=");
-        pw.println(mServiceState.toString());
+        pw.println(mServiceState);
         pw.print("  mNetworkName=");
         pw.println(mNetworkName);
         pw.print("  mNetworkNameDefault=");
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/NotificationRowLayout.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/NotificationRowLayout.java
new file mode 100644
index 0000000..981fb24
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/NotificationRowLayout.java
@@ -0,0 +1,407 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.statusbar.policy;
+
+import android.animation.Animator;
+import android.animation.AnimatorListenerAdapter;
+import android.animation.AnimatorSet;
+import android.animation.ObjectAnimator;
+import android.animation.TimeAnimator;
+import android.animation.ValueAnimator;
+import android.content.Context;
+import android.content.res.Resources;
+import android.content.res.TypedArray;
+import android.graphics.Canvas;
+import android.graphics.Rect;
+import android.graphics.drawable.Drawable;
+import android.util.AttributeSet;
+import android.util.Slog;
+import android.view.LayoutInflater;
+import android.view.MotionEvent;
+import android.view.VelocityTracker;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.animation.AccelerateInterpolator;
+import android.widget.FrameLayout;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import java.util.HashSet;
+
+import com.android.systemui.R;
+
+public class NotificationRowLayout extends ViewGroup {
+    private static final String TAG = "NotificationRowLayout";
+    private static final boolean DEBUG = false;
+    private static final boolean SLOW_ANIMATIONS = false; // DEBUG;
+
+    private static final boolean ANIMATE_LAYOUT = true;
+
+    private static final boolean CLEAR_IF_SWIPED_FAR_ENOUGH = true;
+    
+    private static final boolean CONSTRAIN_SWIPE_ON_PERMANENT = true;
+
+    private static final int APPEAR_ANIM_LEN = SLOW_ANIMATIONS ? 5000 : 250;
+    private static final int DISAPPEAR_ANIM_LEN = APPEAR_ANIM_LEN;
+    private static final int SNAP_ANIM_LEN = SLOW_ANIMATIONS ? 1000 : 250;
+
+    private static final float SWIPE_ESCAPE_VELOCITY = 1500f;
+    private static final float SWIPE_ANIM_VELOCITY_MIN = 1000f;
+
+    Rect mTmpRect = new Rect();
+    int mNumRows = 0;
+    int mRowHeight = 0;
+    int mHeight = 0;
+
+    HashSet<View> mAppearingViews = new HashSet<View>();
+    HashSet<View> mDisappearingViews = new HashSet<View>();
+
+    VelocityTracker mVT;
+    float mInitialTouchX, mInitialTouchY;
+    View mSlidingChild = null;
+    float mLiftoffVelocity;
+
+    public NotificationRowLayout(Context context, AttributeSet attrs) {
+        this(context, attrs, 0);
+    }
+
+    public NotificationRowLayout(Context context, AttributeSet attrs, int defStyle) {
+        super(context, attrs, defStyle);
+
+        mVT = VelocityTracker.obtain();
+
+        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.NotificationRowLayout,
+                defStyle, 0);
+        mRowHeight = a.getDimensionPixelSize(R.styleable.NotificationRowLayout_rowHeight, 0);
+        a.recycle();
+
+        setLayoutTransition(null);
+
+        if (DEBUG) {
+            setOnHierarchyChangeListener(new ViewGroup.OnHierarchyChangeListener() {
+                @Override
+                public void onChildViewAdded(View parent, View child) {
+                    Slog.d(TAG, "view added: " + child + "; new count: " + getChildCount());
+                }
+                @Override
+                public void onChildViewRemoved(View parent, View child) {
+                    Slog.d(TAG, "view removed: " + child + "; new count: " + (getChildCount() - 1));
+                }
+            });
+
+            setBackgroundColor(0x80FF8000);
+        }
+
+    }
+
+    // Swipey code
+    @Override
+    public boolean onInterceptTouchEvent(MotionEvent ev) {
+        final int action = ev.getAction();
+//        if (DEBUG) Slog.d(TAG, "intercepting touch event: " + ev);
+        switch (action) {
+            case MotionEvent.ACTION_DOWN:
+                mVT.clear();
+                mVT.addMovement(ev);
+                mInitialTouchX = ev.getX();
+                mInitialTouchY = ev.getY();
+                mSlidingChild = null;
+                break;
+            case MotionEvent.ACTION_MOVE:
+                mVT.addMovement(ev);
+                if (mSlidingChild == null) {
+                    if (Math.abs(ev.getX() - mInitialTouchX) > 4) { // slide slop
+
+                        // find the view under the pointer, accounting for GONE views
+                        final int count = getChildCount();
+                        int y = 0;
+                        int childIdx = 0;
+                        for (; childIdx < count; childIdx++) {
+                            mSlidingChild = getChildAt(childIdx);
+                            if (mSlidingChild.getVisibility() == GONE) {
+                                continue;
+                            }
+                            y += mRowHeight;
+                            if (mInitialTouchY < y) break;
+                        }
+
+                        mInitialTouchX -= mSlidingChild.getTranslationX();
+                        mSlidingChild.animate().cancel();
+
+                        if (DEBUG) {
+                            Slog.d(TAG, String.format(
+                                "now sliding child %d: %s (touchY=%.1f, rowHeight=%d, count=%d)",
+                                childIdx, mSlidingChild, mInitialTouchY, mRowHeight, count));
+                        }
+                    }
+                }
+                break;
+        }
+        return mSlidingChild != null;
+    }
+
+    protected boolean canBeCleared(View v) {
+        final View veto = v.findViewById(R.id.veto);
+        return (veto != null && veto.getVisibility() != View.GONE);
+    }
+
+    protected boolean clear(View v) {
+        final View veto = v.findViewById(R.id.veto);
+        if (veto != null && veto.getVisibility() != View.GONE) {
+            veto.performClick();
+            return true;
+        }
+        return false;
+    }
+
+    @Override
+    public boolean onTouchEvent(MotionEvent ev) {
+        final int action = ev.getAction();
+//        if (DEBUG) Slog.d(TAG, "touch event: " + ev + " sliding: " + mSlidingChild);
+        if (mSlidingChild != null) {
+            switch (action) {
+                case MotionEvent.ACTION_OUTSIDE:
+                case MotionEvent.ACTION_MOVE:
+                    mVT.addMovement(ev);
+
+                    float delta = (ev.getX() - mInitialTouchX);
+                    if (CONSTRAIN_SWIPE_ON_PERMANENT && !canBeCleared(mSlidingChild)) {
+                        delta = Math.copySign(
+                                    Math.min(Math.abs(delta),
+                                    mSlidingChild.getMeasuredWidth() * 0.2f), delta);
+                    }
+                    mSlidingChild.setTranslationX(delta);
+                    break;
+                case MotionEvent.ACTION_UP:
+                case MotionEvent.ACTION_CANCEL:
+                    mVT.addMovement(ev);
+                    mVT.computeCurrentVelocity(1000 /* px/sec */);
+                    if (DEBUG) Slog.d(TAG, "exit velocity: " + mVT.getXVelocity());
+                    boolean restore = true;
+                    mLiftoffVelocity = mVT.getXVelocity();
+                    if (Math.abs(mLiftoffVelocity) > SWIPE_ESCAPE_VELOCITY
+                        || (CLEAR_IF_SWIPED_FAR_ENOUGH && 
+                            (mSlidingChild.getTranslationX() * 2) > mSlidingChild.getMeasuredWidth()))
+                    {
+
+                        // flingadingy
+                        restore = ! clear(mSlidingChild);
+                    }
+                    if (restore) {
+                        // snappity
+                        mSlidingChild.animate().translationX(0)
+                            .setDuration(SNAP_ANIM_LEN)
+                            .start();
+                    }
+                    break;
+            }
+            return true;
+        }
+        return false;
+    }
+
+    //**
+    @Override
+    public void addView(View child, int index, LayoutParams params) {
+        super.addView(child, index, params);
+
+        final View childF = child;
+
+        if (ANIMATE_LAYOUT) {
+            mAppearingViews.add(child);
+
+            child.setPivotY(0);
+            AnimatorSet a = new AnimatorSet();
+            a.playTogether(
+                    ObjectAnimator.ofFloat(child, "alpha", 0f, 1f)
+//                    ,ObjectAnimator.ofFloat(child, "scaleY", 0f, 1f)
+            );
+            a.setDuration(APPEAR_ANIM_LEN);
+            a.addListener(new AnimatorListenerAdapter() {
+                @Override
+                public void onAnimationEnd(Animator animation) {
+                    mAppearingViews.remove(childF);
+                }
+            });
+            a.start();
+            requestLayout(); // start the container animation
+        }
+    }
+
+    @Override
+    public void removeView(View child) {
+        final View childF = child;
+        if (ANIMATE_LAYOUT) {
+            if (mAppearingViews.contains(child)) {
+                mAppearingViews.remove(child);
+            }
+            mDisappearingViews.add(child);
+
+            child.setPivotY(0);
+
+            final float velocity = (mSlidingChild == child) 
+                    ? Math.min(mLiftoffVelocity, SWIPE_ANIM_VELOCITY_MIN)
+                    : SWIPE_ESCAPE_VELOCITY;
+            final TimeAnimator zoom = new TimeAnimator();
+            zoom.setTimeListener(new TimeAnimator.TimeListener() {
+                @Override
+                public void onTimeUpdate(TimeAnimator animation, long totalTime, long deltaTime) {
+                    childF.setTranslationX(childF.getTranslationX() + deltaTime / 1000f * velocity);
+                }
+            });
+
+            final ObjectAnimator alphaFade = ObjectAnimator.ofFloat(child, "alpha", 0f);
+            alphaFade.addListener(new AnimatorListenerAdapter() {
+                @Override
+                public void onAnimationEnd(Animator animation) {
+                    zoom.cancel(); // it won't end on its own
+                    if (DEBUG) Slog.d(TAG, "actually removing child: " + childF);
+                    NotificationRowLayout.super.removeView(childF);
+                    childF.setAlpha(1f);
+                    mDisappearingViews.remove(childF);
+                }
+            });
+
+            AnimatorSet a = new AnimatorSet();
+            a.playTogether(alphaFade, zoom);
+                    
+//                    ,ObjectAnimator.ofFloat(child, "scaleY", 0f)
+//                    ,ObjectAnimator.ofFloat(child, "translationX", child.getTranslationX() + 300f)
+
+            a.setDuration(DISAPPEAR_ANIM_LEN);
+            a.start();
+            requestLayout(); // start the container animation
+        } else {
+            super.removeView(child);
+        }
+    }
+    //**
+
+    @Override
+    public void onFinishInflate() {
+        super.onFinishInflate();
+        setWillNotDraw(false);
+    }
+
+    @Override
+    public void onDraw(android.graphics.Canvas c) {
+        super.onDraw(c);
+        if (DEBUG) {
+            //Slog.d(TAG, "onDraw: canvas height: " + c.getHeight() + "px; measured height: "
+            //        + getMeasuredHeight() + "px");
+            c.save();
+            c.clipRect(6, 6, c.getWidth() - 6, getMeasuredHeight() - 6,
+                    android.graphics.Region.Op.DIFFERENCE);
+            c.drawColor(0xFFFF8000);
+            c.restore();
+        }
+    }
+
+    @Override
+    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+        final int count = getChildCount();
+
+        // pass 1: count the number of non-GONE views
+        int numRows = 0;
+        for (int i = 0; i < count; i++) {
+            final View child = getChildAt(i);
+            if (child.getVisibility() == GONE) {
+                continue;
+            }
+            if (mDisappearingViews.contains(child)) {
+                continue;
+            }
+            numRows++;
+        }
+        if (numRows != mNumRows) {
+            // uh oh, now you made us go and do work
+            
+            final int computedHeight = numRows * mRowHeight;
+            if (DEBUG) {
+                Slog.d(TAG, String.format("rows went from %d to %d, resizing to %dpx",
+                            mNumRows, numRows, computedHeight));
+            }
+
+            mNumRows = numRows;
+
+            if (ANIMATE_LAYOUT && isShown()) {
+                ObjectAnimator.ofInt(this, "forcedHeight", computedHeight)
+                    .setDuration(APPEAR_ANIM_LEN)
+                    .start();
+            } else {
+                setForcedHeight(computedHeight);
+            }
+        }
+
+        // pass 2: you know, do the measuring
+        final int childWidthMS = widthMeasureSpec;
+        final int childHeightMS = MeasureSpec.makeMeasureSpec(
+                mRowHeight, MeasureSpec.EXACTLY);
+
+        for (int i = 0; i < count; i++) {
+            final View child = getChildAt(i);
+            if (child.getVisibility() == GONE) {
+                continue;
+            }
+
+            child.measure(childWidthMS, childHeightMS);
+        }
+
+        setMeasuredDimension(
+                getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec),
+                resolveSize(getForcedHeight(), heightMeasureSpec));
+    }
+
+    @Override
+    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
+        final int width = right - left;
+        final int height = bottom - top;
+
+        //if (DEBUG) Slog.d(TAG, "onLayout: height=" + height);
+
+        final int count = getChildCount();
+        int y = 0;
+        for (int i = 0; i < count; i++) {
+            final View child = getChildAt(i);
+            if (child.getVisibility() == GONE) {
+                continue;
+            }
+//            final int thisRowHeight = (int)(
+//                ((mAppearingViews.contains(child) || mDisappearingViews.contains(child))
+//                        ? child.getScaleY()
+//                        : 1.0f)
+//                * mRowHeight);
+            final int thisRowHeight = (int)(child.getAlpha() * mRowHeight);
+//            child.layout(0, y, width, y + thisRowHeight);
+            child.layout(0, y, width, y + mRowHeight);
+            y += thisRowHeight;
+        }
+    }
+
+    public void setForcedHeight(int h) {
+        //if (DEBUG) Slog.d(TAG, "forcedHeight: " + h);
+        if (h != mHeight) {
+            mHeight = h;
+            requestLayout();
+        }
+    }
+
+    public int getForcedHeight() {
+        return mHeight;
+    }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/Prefs.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/Prefs.java
index 05eafe8..83e8c96 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/Prefs.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/Prefs.java
@@ -26,6 +26,8 @@
     public static final String DO_NOT_DISTURB_PREF = "do_not_disturb";
     public static final boolean DO_NOT_DISTURB_DEFAULT = false;
 
+    public static final String SHOWN_COMPAT_MODE_HELP = "shown_compat_mode_help";
+
     public static SharedPreferences read(Context context) {
         return context.getSharedPreferences(Prefs.SHARED_PREFS_NAME, Context.MODE_PRIVATE);
     }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/CompatModePanel.java b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/CompatModePanel.java
new file mode 100644
index 0000000..c62c4ad
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/CompatModePanel.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.statusbar.tablet;
+
+import android.app.ActivityManager;
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.os.RemoteException;
+import android.util.AttributeSet;
+import android.util.Slog;
+import android.view.View;
+import android.widget.FrameLayout;
+import android.widget.ImageView;
+import android.widget.RadioButton;
+import android.widget.RadioGroup;
+
+import com.android.systemui.R;
+
+public class CompatModePanel extends FrameLayout implements StatusBarPanel,
+        View.OnClickListener {
+    private static final boolean DEBUG = TabletStatusBar.DEBUG;
+    private static final String TAG = "CompatModePanel";
+
+    private ActivityManager mAM;
+
+    private boolean mAttached = false;
+    private Context mContext;
+    private RadioButton mOnButton, mOffButton;
+
+    private View mTrigger;
+//    private InputMethodButton mInputMethodSwitchButton;
+
+    public CompatModePanel(Context context, AttributeSet attrs) {
+        super(context, attrs);
+        mContext = context;
+        mAM = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
+    }
+
+    @Override
+    public void onFinishInflate() {
+        mOnButton  = (RadioButton) findViewById(R.id.compat_mode_on_radio);
+        mOffButton = (RadioButton) findViewById(R.id.compat_mode_off_radio);
+        mOnButton.setOnClickListener(this);
+        mOffButton.setOnClickListener(this);
+
+        refresh();
+    }
+
+    @Override
+    protected void onDetachedFromWindow() {
+        super.onDetachedFromWindow();
+        if (mAttached) {
+            mAttached = false;
+        }
+    }
+
+    @Override
+    protected void onAttachedToWindow() {
+        super.onAttachedToWindow();
+        if (!mAttached) {
+            mAttached = true;
+        }
+    }
+
+    @Override
+    public void onClick(View v) {
+        if (v == mOnButton) {
+            mAM.setFrontActivityScreenCompatMode(ActivityManager.COMPAT_MODE_ENABLED);
+        } else if (v == mOffButton) {
+            mAM.setFrontActivityScreenCompatMode(ActivityManager.COMPAT_MODE_DISABLED);
+        }
+    }
+
+    @Override
+    public boolean isInContentArea(int x, int y) {
+        return false;
+    }
+
+    public void setTrigger(View v) {
+        mTrigger = v;
+    }
+
+    public void openPanel() {
+        setVisibility(View.VISIBLE);
+        if (mTrigger != null) mTrigger.setSelected(true);
+        refresh();
+    }
+
+    public void closePanel() {
+        setVisibility(View.GONE);
+        if (mTrigger != null) mTrigger.setSelected(false);
+    }
+
+    private void refresh() {
+        int mode = mAM.getFrontActivityScreenCompatMode();
+        if (mode == ActivityManager.COMPAT_MODE_ALWAYS
+                || mode == ActivityManager.COMPAT_MODE_NEVER) {
+            // No longer have something to switch.
+            closePanel();
+            return;
+        }
+        final boolean on = (mode == ActivityManager.COMPAT_MODE_ENABLED);
+        mOnButton.setChecked(on);
+        mOffButton.setChecked(!on);
+    }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/HeightReceiver.java b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/HeightReceiver.java
index 9924faa..7f4c918 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/HeightReceiver.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/HeightReceiver.java
@@ -76,7 +76,7 @@
         int height = -1;
         if (plugged) {
             final DisplayMetrics metrics = new DisplayMetrics();
-            mWindowManager.getDefaultDisplay().getMetrics(metrics);
+            mWindowManager.getDefaultDisplay().getRealMetrics(metrics);
             //Slog.i(TAG, "setPlugged: display metrics=" + metrics);
             final int shortSide = Math.min(metrics.widthPixels, metrics.heightPixels);
             height = shortSide - 720;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/InputMethodsPanel.java b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/InputMethodsPanel.java
index e9db998..339e3f3 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/InputMethodsPanel.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/InputMethodsPanel.java
@@ -422,9 +422,8 @@
             Log.d(TAG, "Get text from: " + imi.getPackageName() + subtype.getNameResId()
                     + imi.getServiceInfo().applicationInfo);
         }
-        // TODO: Change the language of subtype name according to subtype's locale.
-        return mPackageManager.getText(
-                imi.getPackageName(), subtype.getNameResId(), imi.getServiceInfo().applicationInfo);
+        return subtype.getDisplayName(
+                mContext, imi.getPackageName(), imi.getServiceInfo().applicationInfo);
     }
 
     private Drawable getSubtypeIcon(InputMethodInfo imi, InputMethodSubtype subtype) {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBar.java
index 91c3cc1..93f7af3 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBar.java
@@ -23,6 +23,7 @@
 import android.animation.LayoutTransition;
 import android.animation.ObjectAnimator;
 import android.app.ActivityManagerNative;
+import android.app.Dialog;
 import android.app.PendingIntent;
 import android.app.Notification;
 import android.app.StatusBarManager;
@@ -35,6 +36,7 @@
 import android.graphics.PixelFormat;
 import android.graphics.Rect;
 import android.graphics.drawable.LayerDrawable;
+import android.provider.Settings;
 import android.os.Handler;
 import android.os.IBinder;
 import android.os.Message;
@@ -43,6 +45,7 @@
 import android.text.TextUtils;
 import android.util.Slog;
 import android.view.accessibility.AccessibilityEvent;
+import android.view.Display;
 import android.view.Gravity;
 import android.view.IWindowManager;
 import android.view.KeyEvent;
@@ -68,21 +71,19 @@
 import com.android.systemui.statusbar.*;
 import com.android.systemui.statusbar.policy.BatteryController;
 import com.android.systemui.statusbar.policy.BluetoothController;
+import com.android.systemui.statusbar.policy.CompatModeButton;
 import com.android.systemui.statusbar.policy.LocationController;
 import com.android.systemui.statusbar.policy.NetworkController;
 import com.android.systemui.statusbar.policy.Prefs;
 import com.android.systemui.recent.RecentsPanelView;
-import com.android.systemui.recent.carousel.RecentApplicationsActivity;
 
 public class TabletStatusBar extends StatusBar implements
         HeightReceiver.OnBarHeightChangedListener,
         InputMethodsPanel.OnHardKeyboardEnabledChangeListener {
     public static final boolean DEBUG = false;
+    public static final boolean DEBUG_COMPAT_HELP = false;
     public static final String TAG = "TabletStatusBar";
 
-    public static final int MAX_NOTIFICATION_ICONS = 5;
-    // IME switcher icon is big and occupy width of two icons
-    public static final int MAX_NOTIFICATION_ICONS_IME_BUTTON_VISIBLE = MAX_NOTIFICATION_ICONS - 1;
 
     public static final int MSG_OPEN_NOTIFICATION_PANEL = 1000;
     public static final int MSG_CLOSE_NOTIFICATION_PANEL = 1001;
@@ -94,6 +95,8 @@
     public static final int MSG_HIDE_CHROME = 1031;
     public static final int MSG_OPEN_INPUT_METHODS_PANEL = 1040;
     public static final int MSG_CLOSE_INPUT_METHODS_PANEL = 1041;
+    public static final int MSG_OPEN_COMPAT_MODE_PANEL = 1050;
+    public static final int MSG_CLOSE_COMPAT_MODE_PANEL = 1051;
     public static final int MSG_STOP_TICKER = 2000;
 
     // Fitts' Law assistance for LatinIME; see policy.EventHole
@@ -104,6 +107,7 @@
     int mNaturalBarHeight = -1;
     int mIconSize = -1;
     int mIconHPadding = -1;
+    private int mMaxNotificationIcons = 5;
 
     H mHandler = new H();
 
@@ -126,10 +130,12 @@
     View mMenuButton;
     View mRecentButton;
 
-    ViewGroup mNotificationAndImeArea;
+    ViewGroup mFeedbackIconArea; // notification icons, IME icon, compat icon
     InputMethodButton mInputMethodSwitchButton;
+    CompatModeButton mCompatModeButton;
 
     NotificationPanel mNotificationPanel;
+    WindowManager.LayoutParams mNotificationPanelParams;
     NotificationPeekPanel mNotificationPeekWindow;
     ViewGroup mNotificationPeekRow;
     int mNotificationPeekIndex;
@@ -160,16 +166,20 @@
     View mFakeSpaceBar;
     KeyEvent mSpaceBarKeyEvent = null;
 
+    View mCompatibilityHelpDialog = null;
+    
     // for disabling the status bar
     int mDisabled = 0;
 
     private RecentsPanelView mRecentsPanel;
     private InputMethodsPanel mInputMethodsPanel;
+    private CompatModePanel mCompatModePanel;
 
     public Context getContext() { return mContext; }
 
     protected void addPanelWindows() {
         final Context context = mContext;
+        final Resources res = mContext.getResources();
 
         // Notification Panel
         mNotificationPanel = (NotificationPanel)View.inflate(context,
@@ -197,11 +207,12 @@
 
         mStatusBarView.setIgnoreChildren(0, mNotificationTrigger, mNotificationPanel);
 
-        WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
-                512, // ViewGroup.LayoutParams.MATCH_PARENT,
-                ViewGroup.LayoutParams.MATCH_PARENT,
+        WindowManager.LayoutParams lp = mNotificationPanelParams = new WindowManager.LayoutParams(
+                res.getDimensionPixelSize(R.dimen.notification_panel_width),
+                getNotificationPanelHeight(),
                 WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL,
                 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
+                    | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
                     | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM
                     | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
                     | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
@@ -243,11 +254,12 @@
                 512, // ViewGroup.LayoutParams.WRAP_CONTENT,
                 ViewGroup.LayoutParams.WRAP_CONTENT,
                 WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL,
-                WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
+                WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
                     | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM
                     | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH,
                 PixelFormat.TRANSLUCENT);
         lp.gravity = Gravity.BOTTOM | Gravity.RIGHT;
+        lp.y = res.getDimensionPixelOffset(R.dimen.peek_window_y_offset);
         lp.setTitle("NotificationPeekWindow");
         lp.windowAnimations = com.android.internal.R.style.Animation_Toast;
 
@@ -301,6 +313,36 @@
         lp.windowAnimations = R.style.Animation_RecentPanel;
 
         WindowManagerImpl.getDefault().addView(mInputMethodsPanel, lp);
+        
+        // Compatibility mode selector panel
+        mCompatModePanel = (CompatModePanel) View.inflate(context,
+                R.layout.status_bar_compat_mode_panel, null);
+        mCompatModePanel.setOnTouchListener(new TouchOutsideListener(
+                MSG_CLOSE_COMPAT_MODE_PANEL, mCompatModePanel));
+        mCompatModePanel.setTrigger(mCompatModeButton);
+        mCompatModePanel.setVisibility(View.GONE);
+        mStatusBarView.setIgnoreChildren(4, mCompatModeButton, mCompatModePanel);
+        lp = new WindowManager.LayoutParams(
+                250,
+                ViewGroup.LayoutParams.WRAP_CONTENT,
+                WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL,
+                WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
+                    | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM
+                    | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
+                    | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
+                PixelFormat.TRANSLUCENT);
+        lp.gravity = Gravity.BOTTOM | Gravity.RIGHT;
+        lp.setTitle("CompatModePanel");
+        lp.windowAnimations = android.R.style.Animation_Dialog;
+
+        WindowManagerImpl.getDefault().addView(mCompatModePanel, lp);
+    }
+
+    private int getNotificationPanelHeight() {
+        final Resources res = mContext.getResources();
+        final Display d = WindowManagerImpl.getDefault().getDefaultDisplay();
+        return Math.max(res.getDimensionPixelSize(R.dimen.notification_panel_min_height),
+                d.getRealHeight());
     }
 
     @Override
@@ -311,16 +353,19 @@
     @Override
     protected void onConfigurationChanged(Configuration newConfig) {
         loadDimens();
+        mNotificationPanelParams.height = getNotificationPanelHeight();
+        WindowManagerImpl.getDefault().updateViewLayout(mNotificationPanel,
+                mNotificationPanelParams);
     }
 
     protected void loadDimens() {
         final Resources res = mContext.getResources();
 
         mNaturalBarHeight = res.getDimensionPixelSize(
-                com.android.internal.R.dimen.status_bar_height);
+                com.android.internal.R.dimen.system_bar_height);
 
         int newIconSize = res.getDimensionPixelSize(
-            com.android.internal.R.dimen.status_bar_icon_size);
+            com.android.internal.R.dimen.system_bar_icon_size);
         int newIconHPadding = res.getDimensionPixelSize(
             R.dimen.status_bar_icon_padding);
 
@@ -330,6 +375,13 @@
             mIconSize = newIconSize;
             reloadAllNotificationIcons(); // reload the tray
         }
+
+        final int numIcons = res.getInteger(R.integer.config_maxNotificationIcons);
+        if (numIcons != mMaxNotificationIcons) {
+            mMaxNotificationIcons = numIcons;
+            if (DEBUG) Slog.d(TAG, "max notification icons: " + mMaxNotificationIcons);
+            reloadAllNotificationIcons();
+        }
     }
 
     protected View makeStatusBarView() {
@@ -410,11 +462,14 @@
         mNavigationArea.setLayoutTransition(mBarContentsLayoutTransition);
 
         // The bar contents buttons
-        mNotificationAndImeArea = (ViewGroup)sb.findViewById(R.id.notificationAndImeArea);
+        mFeedbackIconArea = (ViewGroup)sb.findViewById(R.id.feedbackIconArea);
         mInputMethodSwitchButton = (InputMethodButton) sb.findViewById(R.id.imeSwitchButton);
         // Overwrite the lister
         mInputMethodSwitchButton.setOnClickListener(mOnClickListener);
 
+        mCompatModeButton = (CompatModeButton) sb.findViewById(R.id.compatModeButton);
+        mCompatModeButton.setOnClickListener(mOnClickListener);
+
         // for redirecting errant bar taps to the IME
         mFakeSpaceBar = sb.findViewById(R.id.fake_space_bar);
 
@@ -626,6 +681,14 @@
                     if (DEBUG) Slog.d(TAG, "closing input methods panel");
                     if (mInputMethodsPanel != null) mInputMethodsPanel.closePanel(false);
                     break;
+                case MSG_OPEN_COMPAT_MODE_PANEL:
+                    if (DEBUG) Slog.d(TAG, "opening compat panel");
+                    if (mCompatModePanel != null) mCompatModePanel.openPanel();
+                    break;
+                case MSG_CLOSE_COMPAT_MODE_PANEL:
+                    if (DEBUG) Slog.d(TAG, "closing compat panel");
+                    if (mCompatModePanel != null) mCompatModePanel.closePanel();
+                    break;
                 case MSG_SHOW_CHROME:
                     if (DEBUG) Slog.d(TAG, "hiding shadows (lights on)");
                     mBarContents.setVisibility(View.VISIBLE);
@@ -894,14 +957,14 @@
             if (0 == (mDisabled & (StatusBarManager.DISABLE_NOTIFICATION_ICONS
                             | StatusBarManager.DISABLE_NOTIFICATION_TICKER))) {
                 mTicker.add(key, n);
-                mNotificationAndImeArea.setVisibility(View.GONE);
+                mFeedbackIconArea.setVisibility(View.GONE);
             }
         }
     }
 
     // called by TabletTicker when it's done with all queued ticks
     public void doneTicking() {
-        mNotificationAndImeArea.setVisibility(View.VISIBLE);
+        mFeedbackIconArea.setVisibility(View.VISIBLE);
     }
 
     public void animateExpand() {
@@ -919,6 +982,8 @@
         mHandler.sendEmptyMessage(MSG_CLOSE_RECENTS_PANEL);
         mHandler.removeMessages(MSG_CLOSE_INPUT_METHODS_PANEL);
         mHandler.sendEmptyMessage(MSG_CLOSE_INPUT_METHODS_PANEL);
+        mHandler.removeMessages(MSG_CLOSE_COMPAT_MODE_PANEL);
+        mHandler.sendEmptyMessage(MSG_CLOSE_COMPAT_MODE_PANEL);
         mHandler.removeMessages(MSG_CLOSE_NOTIFICATION_PEEK);
         mHandler.sendEmptyMessage(MSG_CLOSE_NOTIFICATION_PEEK);
     }
@@ -936,16 +1001,68 @@
         mHandler.sendEmptyMessage(on ? MSG_SHOW_CHROME : MSG_HIDE_CHROME);
     }
 
-    public void setMenuKeyVisible(boolean visible) {
+    public void topAppWindowChanged(boolean windowVisible) {
         if (DEBUG) {
-            Slog.d(TAG, (visible?"showing":"hiding") + " the MENU button");
+            Slog.d(TAG, (windowVisible?"showing":"hiding") + " the MENU button");
         }
-        mMenuButton.setVisibility(visible ? View.VISIBLE : View.GONE);
+        mMenuButton.setVisibility(windowVisible ? View.VISIBLE : View.GONE);
 
         // See above re: lights-out policy for legacy apps.
-        if (visible) setLightsOn(true);
+        if (windowVisible) setLightsOn(true);
+
+        mCompatModeButton.refresh();
+        if (mCompatModeButton.getVisibility() == View.VISIBLE) {
+            if (DEBUG_COMPAT_HELP
+                    || ! Prefs.read(mContext).getBoolean(Prefs.SHOWN_COMPAT_MODE_HELP, false)) {
+                showCompatibilityHelp();
+            }
+        } else {
+            hideCompatibilityHelp();
+            mCompatModePanel.closePanel();
+        }
     }
 
+    private void showCompatibilityHelp() {
+        if (mCompatibilityHelpDialog != null) {
+            return;
+        }
+        
+        mCompatibilityHelpDialog = View.inflate(mContext, R.layout.compat_mode_help, null);
+        View button = mCompatibilityHelpDialog.findViewById(R.id.button);
+
+        button.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                hideCompatibilityHelp();
+                SharedPreferences.Editor editor = Prefs.edit(mContext);
+                editor.putBoolean(Prefs.SHOWN_COMPAT_MODE_HELP, true);
+                editor.apply();
+            }
+        });
+
+        WindowManager.LayoutParams lp = mNotificationPanelParams = new WindowManager.LayoutParams(
+                ViewGroup.LayoutParams.MATCH_PARENT,
+                ViewGroup.LayoutParams.MATCH_PARENT,
+                WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG,
+                WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
+                    | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
+                    | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
+                PixelFormat.TRANSLUCENT);
+        lp.setTitle("CompatibilityModeDialog");
+        lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED
+                | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING;
+        lp.windowAnimations = com.android.internal.R.style.Animation_ZoomButtons; // simple fade
+
+        WindowManagerImpl.getDefault().addView(mCompatibilityHelpDialog, lp);
+    }
+
+    private void hideCompatibilityHelp() {
+        if (mCompatibilityHelpDialog != null) {
+            WindowManagerImpl.getDefault().removeView(mCompatibilityHelpDialog);
+            mCompatibilityHelpDialog = null;
+        }
+    }
+    
     public void setImeWindowStatus(IBinder token, int vis, int backDisposition) {
         mInputMethodSwitchButton.setImeWindowStatus(token,
                 (vis & InputMethodService.IME_ACTIVE) != 0);
@@ -1036,6 +1153,8 @@
                 onClickRecentButton();
             } else if (v == mInputMethodSwitchButton) {
                 onClickInputMethodSwitchButton();
+            } else if (v == mCompatModeButton) {
+                onClickCompatModeButton();
             }
         }
     };
@@ -1053,20 +1172,12 @@
 
     public void onClickRecentButton() {
         if (DEBUG) Slog.d(TAG, "clicked recent apps; disabled=" + mDisabled);
-        if (mRecentsPanel == null) {
-            Intent intent = new Intent();
-            intent.setClass(mContext, RecentApplicationsActivity.class);
-            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
-                    | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
-            mContext.startActivity(intent);
-        } else {
-            if ((mDisabled & StatusBarManager.DISABLE_EXPAND) == 0) {
-                int msg = (mRecentsPanel.getVisibility() == View.GONE)
-                    ? MSG_OPEN_RECENTS_PANEL
-                    : MSG_CLOSE_RECENTS_PANEL;
-                mHandler.removeMessages(msg);
-                mHandler.sendEmptyMessage(msg);
-            }
+        if ((mDisabled & StatusBarManager.DISABLE_EXPAND) == 0) {
+            int msg = (mRecentsPanel.getVisibility() == View.GONE)
+                ? MSG_OPEN_RECENTS_PANEL
+                : MSG_CLOSE_RECENTS_PANEL;
+            mHandler.removeMessages(msg);
+            mHandler.sendEmptyMessage(msg);
         }
     }
 
@@ -1078,6 +1189,13 @@
         mHandler.sendEmptyMessage(msg);
     }
 
+    public void onClickCompatModeButton() {
+        int msg = (mCompatModePanel.getVisibility() == View.GONE) ?
+                MSG_OPEN_COMPAT_MODE_PANEL : MSG_CLOSE_COMPAT_MODE_PANEL;
+        mHandler.removeMessages(msg);
+        mHandler.sendEmptyMessage(msg);
+    }
+
     public NotificationClicker makeClicker(PendingIntent intent, String pkg, String tag, int id) {
         return new NotificationClicker(intent, pkg, tag, id);
     }
@@ -1414,11 +1532,13 @@
 
         ArrayList<View> toShow = new ArrayList<View>();
 
-        // When IME button is visible, the number of notification icons should be decremented
-        // to fit the upper limit.
-        final int maxNotificationIconsCount =
-                (mInputMethodSwitchButton.getVisibility() != View.GONE) ?
-                        MAX_NOTIFICATION_ICONS_IME_BUTTON_VISIBLE : MAX_NOTIFICATION_ICONS;
+        // Extra Special Icons
+        // The IME switcher and compatibility mode icons take the place of notifications. You didn't
+        // need to see all those new emails, did you?
+        int maxNotificationIconsCount = mMaxNotificationIcons;
+        if (mInputMethodSwitchButton.getVisibility() != View.GONE) maxNotificationIconsCount --;
+        if (mCompatModeButton.getVisibility()        != View.GONE) maxNotificationIconsCount --;
+
         for (int i=0; i< maxNotificationIconsCount; i++) {
             if (i>=N) break;
             toShow.add(mNotificationData.get(N-i-1).icon);
@@ -1569,6 +1689,13 @@
     public void userActivity() {
     }
 
+    public void toggleRecentApps() {
+        int msg = (mRecentsPanel.getVisibility() == View.GONE)
+                ? MSG_OPEN_RECENTS_PANEL : MSG_CLOSE_RECENTS_PANEL;
+        mHandler.removeMessages(msg);
+        mHandler.sendEmptyMessage(msg);
+    }
+
     public class TouchOutsideListener implements View.OnTouchListener {
         private int mMsg;
         private StatusBarPanel mPanel;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBarView.java b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBarView.java
index 4e2faf7..dff1f6a 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBarView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBarView.java
@@ -27,8 +27,9 @@
 public class TabletStatusBarView extends FrameLayout {
     private Handler mHandler;
 
-    private final View[] mIgnoreChildren = new View[4];
-    private final View[] mPanels = new View[4];
+    private final int MAX_PANELS = 5;
+    private final View[] mIgnoreChildren = new View[MAX_PANELS];
+    private final View[] mPanels = new View[MAX_PANELS];
     private final int[] mPos = new int[2];
 
     public TabletStatusBarView(Context context) {
diff --git a/packages/SystemUI/src/com/android/systemui/usb/UsbPreferenceActivity.java b/packages/SystemUI/src/com/android/systemui/usb/UsbPreferenceActivity.java
new file mode 100644
index 0000000..3ed44e8
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/usb/UsbPreferenceActivity.java
@@ -0,0 +1,91 @@
+/*

+ * Copyright (C) 2011 The Android Open Source Project

+ *

+ * Licensed under the Apache License, Version 2.0 (the "License");

+ * you may not use this file except in compliance with the License.

+ * You may obtain a copy of the License at

+ *

+ *      http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing, software

+ * distributed under the License is distributed on an "AS IS" BASIS,

+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

+ * See the License for the specific language governing permissions and

+ * limitations under the License.

+ */

+

+package com.android.systemui.usb;

+

+import android.app.Activity;

+import android.app.AlertDialog;

+import android.content.Context;

+import android.content.DialogInterface;

+import android.hardware.usb.UsbManager;

+import android.os.Bundle;

+import android.view.LayoutInflater;

+import android.view.View;

+import android.util.Log;

+import android.widget.Button;

+

+import java.io.File;

+

+import com.android.systemui.R;

+

+public class UsbPreferenceActivity extends Activity implements View.OnClickListener  {

+

+    private static final String TAG = "UsbPreferenceActivity";

+

+    private UsbManager mUsbManager;

+    private String mCurrentFunction;

+    private String[] mFunctions;

+    private String mInstallerImagePath;

+    private Button mMtpPtpButton;

+    private Button mInstallerCdButton;

+    private boolean mPtpActive;

+

+    @Override

+    public void onCreate(Bundle icicle) {

+        super.onCreate(icicle);

+

+        mUsbManager = (UsbManager)getSystemService(Context.USB_SERVICE);

+

+        AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);

+        dialogBuilder.setTitle(getString(R.string.usb_preference_title));

+

+        LayoutInflater inflater = (LayoutInflater)getSystemService(

+                Context.LAYOUT_INFLATER_SERVICE);

+        View buttonView = inflater.inflate(R.layout.usb_preference_buttons, null);

+        dialogBuilder.setView(buttonView);

+        mMtpPtpButton = (Button)buttonView.findViewById(R.id.mtp_ptp_button);

+        mInstallerCdButton = (Button)buttonView.findViewById(R.id.installer_cd_button);

+        mMtpPtpButton.setOnClickListener(this);

+        mInstallerCdButton.setOnClickListener(this);

+

+        mPtpActive = mUsbManager.isFunctionEnabled(UsbManager.USB_FUNCTION_PTP);

+        if (mPtpActive) {

+            mMtpPtpButton.setText(R.string.use_mtp_button_title);

+        }

+

+        mInstallerImagePath = getString(com.android.internal.R.string.config_isoImagePath);

+        if (!(new File(mInstallerImagePath)).exists()) {

+            mInstallerCdButton.setVisibility(View.GONE);

+        }

+

+        dialogBuilder.show();

+    }

+

+    public void onClick(View v) {

+        if (v.equals(mMtpPtpButton)) {

+            if (mPtpActive) {

+                mUsbManager.setPrimaryFunction(UsbManager.USB_FUNCTION_MTP);

+            } else {

+                mUsbManager.setPrimaryFunction(UsbManager.USB_FUNCTION_PTP);

+            }

+        } else if (v.equals(mInstallerCdButton)) {

+            mUsbManager.setPrimaryFunction(UsbManager.USB_FUNCTION_MASS_STORAGE);

+            mUsbManager.setMassStorageBackingFile(mInstallerImagePath);

+        }

+

+        finish();

+    }

+}

diff --git a/packages/VpnDialogs/Android.mk b/packages/VpnDialogs/Android.mk
new file mode 100644
index 0000000..89f010a
--- /dev/null
+++ b/packages/VpnDialogs/Android.mk
@@ -0,0 +1,27 @@
+#
+# Copyright (C) 2011 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_PACKAGE_NAME := VpnDialogs
+
+include $(BUILD_PACKAGE)
diff --git a/packages/VpnDialogs/AndroidManifest.xml b/packages/VpnDialogs/AndroidManifest.xml
new file mode 100644
index 0000000..4e6784c
--- /dev/null
+++ b/packages/VpnDialogs/AndroidManifest.xml
@@ -0,0 +1,22 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+        package="com.android.vpndialogs">
+
+    <application android:label="VpnDialogs">
+        <activity android:name=".ConfirmDialog"
+                android:theme="@style/transparent">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN"/>
+                <category android:name="android.intent.category.DEFAULT"/>
+            </intent-filter>
+        </activity>
+
+        <activity android:name=".ManageDialog"
+                android:theme="@style/transparent"
+                android:noHistory="true">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN"/>
+                <category android:name="android.intent.category.DEFAULT"/>
+            </intent-filter>
+        </activity>
+    </application>
+</manifest>
diff --git a/packages/VpnDialogs/res/layout/confirm.xml b/packages/VpnDialogs/res/layout/confirm.xml
new file mode 100644
index 0000000..249b6e6
--- /dev/null
+++ b/packages/VpnDialogs/res/layout/confirm.xml
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+     implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content">
+
+    <ImageView android:id="@+id/icon"
+            android:layout_width="@android:dimen/app_icon_size"
+            android:layout_height="@android:dimen/app_icon_size"
+            android:layout_alignParentTop="true"
+            android:layout_alignParentLeft="true"
+            android:layout_marginRight="1mm"/>
+
+    <TextView android:id="@+id/warning"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:layout_alignParentLeft="true"
+            android:layout_alignParentRight="true"
+            android:layout_below="@id/icon"
+            android:padding="2mm"
+            android:text="@string/warning"
+            android:textSize="18sp"/>
+
+    <TextView android:id="@+id/prompt"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:layout_alignParentTop="true"
+            android:layout_alignParentRight="true"
+            android:layout_toRightOf="@id/icon"
+            android:layout_above="@id/warning"
+            android:gravity="center_vertical"
+            android:textSize="20sp"/>
+
+    <CheckBox android:id="@+id/check"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:layout_alignParentLeft="true"
+            android:layout_alignParentRight="true"
+            android:layout_below="@id/warning"
+            android:text="@string/accept"
+
+
+            android:textSize="18sp"
+            android:checked="false"/>
+
+</RelativeLayout>
diff --git a/packages/VpnDialogs/res/layout/manage.xml b/packages/VpnDialogs/res/layout/manage.xml
new file mode 100644
index 0000000..330b8e3
--- /dev/null
+++ b/packages/VpnDialogs/res/layout/manage.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+     implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:stretchColumns="0,1">
+
+    <TableRow>
+        <TextView android:text="@string/session" style="@style/label"/>
+        <TextView android:id="@+id/session" style="@style/value"/>
+    </TableRow>
+
+    <TableRow>
+        <TextView android:text="@string/duration" style="@style/label"/>
+        <TextView android:id="@+id/duration" style="@style/value"/>
+    </TableRow>
+
+    <TableRow>
+        <TextView android:text="@string/data_transmitted" style="@style/label"/>
+        <TextView android:id="@+id/data_transmitted" style="@style/value"/>
+    </TableRow>
+
+    <TableRow>
+        <TextView android:text="@string/data_received" style="@style/label"/>
+        <TextView android:id="@+id/data_received" style="@style/value"/>
+    </TableRow>
+
+</TableLayout>
diff --git a/packages/VpnDialogs/res/values/strings.xml b/packages/VpnDialogs/res/values/strings.xml
new file mode 100644
index 0000000..8186e26
--- /dev/null
+++ b/packages/VpnDialogs/res/values/strings.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+
+    <string name="prompt"><xliff:g id="app">%s</xliff:g>
+        attempts to create a VPN connection.
+    </string>
+
+    <string name="warning">By proceeding, you are giving the application
+        permission to intercept all network traffic.
+        <b>Do NOT accept unless you trust the application.</b> Otherwise,
+        you run the risk of having your data compromised by a malicious
+        software.
+    </string>
+
+    <string name="accept">I trust this application.</string>
+
+    <string name="configure">Configure</string>
+    <string name="disconnect">Disconnect</string>
+
+    <string name="session">Session:</string>
+    <string name="duration">Duration:</string>
+    <string name="data_transmitted">Data Transmitted:</string>
+    <string name="data_received">Data Received:</string>
+
+    <string name="blank_value">--</string>
+    <string name="data_value_format">
+        <xliff:g id="number">%1$s</xliff:g> bytes /
+        <xliff:g id="number">%2$s</xliff:g> packets
+    </string>
+</resources>
diff --git a/packages/VpnDialogs/res/values/styles.xml b/packages/VpnDialogs/res/values/styles.xml
new file mode 100644
index 0000000..6eae218
--- /dev/null
+++ b/packages/VpnDialogs/res/values/styles.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<resources>
+
+    <style name="transparent">
+        <item name="android:windowBackground">@android:color/transparent</item>
+        <item name="android:windowNoTitle">true</item>
+        <item name="android:windowIsFloating">true</item>
+    </style>
+
+    <style name="label">
+        <item name="android:gravity">center_vertical|right</item>
+        <item name="android:paddingRight">5mm</item>
+        <item name="android:textSize">16sp</item>
+    </style>
+
+    <style name="value">
+        <item name="android:gravity">center_vertical|left</item>
+        <item name="android:textSize">18sp</item>
+        <item name="android:textStyle">bold</item>
+        <item name="android:text">@string/blank_value</item>
+    </style>
+</resources>
diff --git a/packages/VpnDialogs/src/com/android/vpndialogs/ConfirmDialog.java b/packages/VpnDialogs/src/com/android/vpndialogs/ConfirmDialog.java
new file mode 100644
index 0000000..c54e719
--- /dev/null
+++ b/packages/VpnDialogs/src/com/android/vpndialogs/ConfirmDialog.java
@@ -0,0 +1,119 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.vpndialogs;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.net.IConnectivityManager;
+import android.os.ServiceManager;
+import android.util.Log;
+import android.view.View;
+import android.widget.Button;
+import android.widget.CompoundButton;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+public class ConfirmDialog extends Activity implements CompoundButton.OnCheckedChangeListener,
+        DialogInterface.OnClickListener, DialogInterface.OnDismissListener {
+    private static final String TAG = "VpnConfirm";
+
+    private String mPackageName;
+
+    private IConnectivityManager mService;
+
+    private AlertDialog mDialog;
+    private Button mButton;
+
+    @Override
+    protected void onResume() {
+        super.onResume();
+        try {
+            mPackageName = getCallingPackage();
+
+            mService = IConnectivityManager.Stub.asInterface(
+                    ServiceManager.getService(Context.CONNECTIVITY_SERVICE));
+
+            if (mPackageName.equals(mService.prepareVpn(null))) {
+                setResult(RESULT_OK);
+                finish();
+                return;
+            }
+
+            PackageManager pm = getPackageManager();
+            ApplicationInfo app = pm.getApplicationInfo(mPackageName, 0);
+
+            View view = View.inflate(this, R.layout.confirm, null);
+            ((ImageView) view.findViewById(R.id.icon)).setImageDrawable(app.loadIcon(pm));
+            ((TextView) view.findViewById(R.id.prompt)).setText(
+                    getString(R.string.prompt, app.loadLabel(pm)));
+            ((CompoundButton) view.findViewById(R.id.check)).setOnCheckedChangeListener(this);
+
+            mDialog = new AlertDialog.Builder(this)
+                    .setIcon(android.R.drawable.ic_dialog_alert)
+                    .setTitle(android.R.string.dialog_alert_title)
+                    .setView(view)
+                    .setPositiveButton(android.R.string.ok, this)
+                    .setNegativeButton(android.R.string.cancel, this)
+                    .setCancelable(false)
+                    .create();
+            mDialog.setOnDismissListener(this);
+            mDialog.show();
+
+            mButton = mDialog.getButton(DialogInterface.BUTTON_POSITIVE);
+            mButton.setEnabled(false);
+        } catch (Exception e) {
+            Log.e(TAG, "onResume", e);
+            finish();
+        }
+    }
+
+    @Override
+    protected void onPause() {
+        super.onPause();
+        if (mDialog != null) {
+            mDialog.setOnDismissListener(null);
+            mDialog.dismiss();
+        }
+    }
+
+    @Override
+    public void onCheckedChanged(CompoundButton button, boolean checked) {
+        mButton.setEnabled(checked);
+    }
+
+    @Override
+    public void onClick(DialogInterface dialog, int which) {
+        try {
+            if (which == AlertDialog.BUTTON_POSITIVE &&
+                    mPackageName.equals(mService.prepareVpn(mPackageName))) {
+                setResult(RESULT_OK);
+            }
+        } catch (Exception e) {
+            Log.e(TAG, "onClick", e);
+        }
+    }
+
+    @Override
+    public void onDismiss(DialogInterface dialog) {
+        finish();
+    }
+}
diff --git a/packages/VpnDialogs/src/com/android/vpndialogs/ManageDialog.java b/packages/VpnDialogs/src/com/android/vpndialogs/ManageDialog.java
new file mode 100644
index 0000000..ba3f344
--- /dev/null
+++ b/packages/VpnDialogs/src/com/android/vpndialogs/ManageDialog.java
@@ -0,0 +1,187 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.vpndialogs;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.net.IConnectivityManager;
+import android.os.Handler;
+import android.os.Message;
+import android.os.ServiceManager;
+import android.os.SystemClock;
+import android.util.Log;
+import android.view.View;
+import android.widget.Button;
+import android.widget.CompoundButton;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import com.android.internal.net.VpnConfig;
+
+import java.io.DataInputStream;
+import java.io.FileInputStream;
+
+public class ManageDialog extends Activity implements Handler.Callback,
+        DialogInterface.OnClickListener, DialogInterface.OnDismissListener {
+    private static final String TAG = "VpnManage";
+
+    private VpnConfig mConfig;
+
+    private IConnectivityManager mService;
+
+    private AlertDialog mDialog;
+    private TextView mDuration;
+    private TextView mDataTransmitted;
+    private TextView mDataReceived;
+
+    private Handler mHandler;
+
+    @Override
+    protected void onResume() {
+        super.onResume();
+        try {
+            mConfig = getIntent().getParcelableExtra("config");
+
+            mService = IConnectivityManager.Stub.asInterface(
+                    ServiceManager.getService(Context.CONNECTIVITY_SERVICE));
+
+            PackageManager pm = getPackageManager();
+            ApplicationInfo app = pm.getApplicationInfo(mConfig.packageName, 0);
+
+            View view = View.inflate(this, R.layout.manage, null);
+            if (mConfig.sessionName != null) {
+                ((TextView) view.findViewById(R.id.session)).setText(mConfig.sessionName);
+            }
+            mDuration = (TextView) view.findViewById(R.id.duration);
+            mDataTransmitted = (TextView) view.findViewById(R.id.data_transmitted);
+            mDataReceived = (TextView) view.findViewById(R.id.data_received);
+
+            mDialog = new AlertDialog.Builder(this)
+                    .setIcon(app.loadIcon(pm))
+                    .setTitle(app.loadLabel(pm))
+                    .setView(view)
+                    .setNeutralButton(R.string.disconnect, this)
+                    .setNegativeButton(android.R.string.cancel, this)
+                    .create();
+
+            if (mConfig.configureActivity != null) {
+                mDialog.setButton(DialogInterface.BUTTON_POSITIVE,
+                        getText(R.string.configure), this);
+            }
+            mDialog.setOnDismissListener(this);
+            mDialog.show();
+
+            if (mHandler == null) {
+                mHandler = new Handler(this);
+            }
+            mHandler.sendEmptyMessage(0);
+        } catch (Exception e) {
+            Log.e(TAG, "onResume", e);
+            finish();
+        }
+    }
+
+    @Override
+    protected void onPause() {
+        super.onPause();
+        if (mDialog != null) {
+            mDialog.setOnDismissListener(null);
+            mDialog.dismiss();
+        }
+    }
+
+    @Override
+    public void onClick(DialogInterface dialog, int which) {
+        try {
+            if (which == AlertDialog.BUTTON_POSITIVE) {
+                Intent intent = new Intent();
+                intent.setClassName(mConfig.packageName, mConfig.configureActivity);
+                startActivity(intent);
+            } else if (which == AlertDialog.BUTTON_NEUTRAL) {
+                mService.prepareVpn("");
+            }
+        } catch (Exception e) {
+            Log.e(TAG, "onClick", e);
+            finish();
+        }
+    }
+
+    @Override
+    public void onDismiss(DialogInterface dialog) {
+        finish();
+    }
+
+    @Override
+    public boolean handleMessage(Message message) {
+        mHandler.removeMessages(0);
+
+        if (mDialog.isShowing()) {
+            if (mConfig.startTime != 0) {
+                long seconds = (SystemClock.elapsedRealtime() - mConfig.startTime) / 1000;
+                mDuration.setText(String.format("%02d:%02d:%02d",
+                        seconds / 3600, seconds / 60 % 60, seconds % 60));
+            }
+
+            String[] numbers = getStatistics();
+            if (numbers != null) {
+                // [1] and [2] are received data in bytes and packets.
+                mDataReceived.setText(getString(R.string.data_value_format,
+                        numbers[1], numbers[2]));
+
+                // [9] and [10] are transmitted data in bytes and packets.
+                mDataTransmitted.setText(getString(R.string.data_value_format,
+                        numbers[9], numbers[10]));
+            }
+            mHandler.sendEmptyMessageDelayed(0, 1000);
+        }
+        return true;
+    }
+
+    private String[] getStatistics() {
+        DataInputStream in = null;
+        try {
+            // See dev_seq_printf_stats() in net/core/dev.c.
+            in = new DataInputStream(new FileInputStream("/proc/net/dev"));
+            String prefix = mConfig.interfaceName + ':';
+
+            while (true) {
+                String line = in.readLine().trim();
+                if (line.startsWith(prefix)) {
+                    String[] numbers = line.substring(prefix.length()).split(" +");
+                    if (numbers.length == 17) {
+                        return numbers;
+                    }
+                    break;
+                }
+            }
+        } catch (Exception e) {
+            // ignore
+        } finally {
+            try {
+                in.close();
+            } catch (Exception e) {
+                // ignore
+            }
+        }
+        return null;
+    }
+}
diff --git a/policy/src/com/android/internal/policy/impl/KeyguardUpdateMonitor.java b/policy/src/com/android/internal/policy/impl/KeyguardUpdateMonitor.java
index 5ed67a9..f385a23 100644
--- a/policy/src/com/android/internal/policy/impl/KeyguardUpdateMonitor.java
+++ b/policy/src/com/android/internal/policy/impl/KeyguardUpdateMonitor.java
@@ -114,7 +114,15 @@
             }
             String stateExtra = intent.getStringExtra(IccCard.INTENT_KEY_ICC_STATE);
             if (IccCard.INTENT_VALUE_ICC_ABSENT.equals(stateExtra)) {
-                this.simState = IccCard.State.ABSENT;
+                final String absentReason = intent
+                    .getStringExtra(IccCard.INTENT_KEY_LOCKED_REASON);
+
+                if (IccCard.INTENT_VALUE_ABSENT_ON_PERM_DISABLED.equals(
+                        absentReason)) {
+                    this.simState = IccCard.State.PERM_DISABLED;
+                } else {
+                    this.simState = IccCard.State.ABSENT;
+                }
             } else if (IccCard.INTENT_VALUE_ICC_READY.equals(stateExtra)) {
                 this.simState = IccCard.State.READY;
             } else if (IccCard.INTENT_VALUE_ICC_LOCKED.equals(stateExtra)) {
@@ -480,11 +488,11 @@
     }
 
     /**
-     * Report that the user succesfully entered the sim pin so we
+     * Report that the user succesfully entered the sim pin or puk so we
      * have the information earlier than waiting for the intent
      * broadcast from the telephony code.
      */
-    public void reportSimPinUnlocked() {
+    public void reportSimUnlocked() {
         mSimState = IccCard.State.READY;
     }
 
diff --git a/policy/src/com/android/internal/policy/impl/KeyguardViewManager.java b/policy/src/com/android/internal/policy/impl/KeyguardViewManager.java
index ae23df6..7983278 100644
--- a/policy/src/com/android/internal/policy/impl/KeyguardViewManager.java
+++ b/policy/src/com/android/internal/policy/impl/KeyguardViewManager.java
@@ -20,6 +20,7 @@
 
 import android.content.Context;
 import android.content.pm.ActivityInfo;
+import android.content.res.Resources;
 import android.graphics.PixelFormat;
 import android.graphics.Canvas;
 import android.util.Log;
@@ -94,6 +95,8 @@
     public synchronized void show() {
         if (DEBUG) Log.d(TAG, "show(); mKeyguardView==" + mKeyguardView);
 
+        Resources res = mContext.getResources();
+        boolean enableScreenRotation = res.getBoolean(R.bool.config_enableLockScreenRotation);
         if (mKeyguardHost == null) {
             if (DEBUG) Log.d(TAG, "keyguard host is null, creating it...");
 
@@ -116,18 +119,22 @@
             lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN;
             lp.windowAnimations = com.android.internal.R.style.Animation_LockScreen;
 
-            // TODO: Sometimes we get the wrong value for the sensor resource we use to configure
-            // this.  However, the current UI design has LockScreen always respond to orientation so
-            // we don't need this for the time-being.
-            //
-            // For reference, the configuration variable is R.bool.config_enableLockScreenRotation
-            lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR;
             lp.setTitle("Keyguard");
             mWindowLayoutParams = lp;
 
             mViewManager.addView(mKeyguardHost, lp);
         }
 
+        if (enableScreenRotation) {
+            Log.d(TAG, "Rotation sensor for lock screen On!");
+            mWindowLayoutParams.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR;
+        } else {
+            Log.d(TAG, "Rotation sensor for lock screen Off!");
+            mWindowLayoutParams.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
+        }
+
+        mViewManager.updateViewLayout(mKeyguardHost, mWindowLayoutParams);
+
         if (mKeyguardView == null) {
             if (DEBUG) Log.d(TAG, "keyguard view is null, creating it...");
             mKeyguardView = mKeyguardViewProperties.createKeyguardView(mContext, mUpdateMonitor, this);
diff --git a/policy/src/com/android/internal/policy/impl/KeyguardViewMediator.java b/policy/src/com/android/internal/policy/impl/KeyguardViewMediator.java
index 8a60098..8ba235b 100644
--- a/policy/src/com/android/internal/policy/impl/KeyguardViewMediator.java
+++ b/policy/src/com/android/internal/policy/impl/KeyguardViewMediator.java
@@ -580,7 +580,9 @@
             final boolean provisioned = mUpdateMonitor.isDeviceProvisioned();
             final IccCard.State state = mUpdateMonitor.getSimState();
             final boolean lockedOrMissing = state.isPinLocked()
-                    || ((state == IccCard.State.ABSENT) && requireSim);
+                    || ((state == IccCard.State.ABSENT
+                            || state == IccCard.State.PERM_DISABLED)
+                            && requireSim);
 
             if (!lockedOrMissing && !provisioned) {
                 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because device isn't provisioned"
@@ -687,12 +689,15 @@
 
         switch (simState) {
             case ABSENT:
+            case PERM_DISABLED:
                 // only force lock screen in case of missing sim if user hasn't
                 // gone through setup wizard
                 if (!mUpdateMonitor.isDeviceProvisioned()) {
                     if (!isShowing()) {
-                        if (DEBUG) Log.d(TAG, "INTENT_VALUE_ICC_ABSENT and keygaurd isn't showing, we need "
-                             + "to show the keyguard since the device isn't provisioned yet.");
+                        if (DEBUG) Log.d(TAG, "INTENT_VALUE_ICC_ABSENT "
+                                + "or PERM_DISABLED and keygaurd isn't showing,"
+                                + " we need to show the keyguard since the "
+                                + "device isn't provisioned yet.");
                         doKeyguard();
                     } else {
                         resetStateLocked();
diff --git a/policy/src/com/android/internal/policy/impl/LockPatternKeyguardView.java b/policy/src/com/android/internal/policy/impl/LockPatternKeyguardView.java
index 2fda3aa..eea30407 100644
--- a/policy/src/com/android/internal/policy/impl/LockPatternKeyguardView.java
+++ b/policy/src/com/android/internal/policy/impl/LockPatternKeyguardView.java
@@ -116,6 +116,11 @@
         SimPin,
 
         /**
+         * Unlock by entering a sim puk.
+         */
+        SimPuk,
+
+        /**
          * Unlock by entering an account's login and password.
          */
         Account,
@@ -176,7 +181,8 @@
     private boolean stuckOnLockScreenBecauseSimMissing() {
         return mRequiresSim
                 && (!mUpdateMonitor.isDeviceProvisioned())
-                && (mUpdateMonitor.getSimState() == IccCard.State.ABSENT);
+                && (mUpdateMonitor.getSimState() == IccCard.State.ABSENT ||
+                    mUpdateMonitor.getSimState() == IccCard.State.PERM_DISABLED);
     }
 
     /**
@@ -222,8 +228,10 @@
             public void goToUnlockScreen() {
                 final IccCard.State simState = mUpdateMonitor.getSimState();
                 if (stuckOnLockScreenBecauseSimMissing()
-                         || (simState == IccCard.State.PUK_REQUIRED)){
-                    // stuck on lock screen when sim missing or puk'd
+                         || (simState == IccCard.State.PUK_REQUIRED
+                             && !mLockPatternUtils.isPukUnlockScreenEnable())){
+                    // stuck on lock screen when sim missing or
+                    // puk'd but puk unlock screen is disabled
                     return;
                 }
                 if (!isSecure()) {
@@ -522,8 +530,10 @@
                 secure = mLockPatternUtils.isLockPatternEnabled();
                 break;
             case SimPin:
-                secure = mUpdateMonitor.getSimState() == IccCard.State.PIN_REQUIRED
-                            || mUpdateMonitor.getSimState() == IccCard.State.PUK_REQUIRED;
+                secure = mUpdateMonitor.getSimState() == IccCard.State.PIN_REQUIRED;
+                break;
+            case SimPuk:
+                secure = mUpdateMonitor.getSimState() == IccCard.State.PUK_REQUIRED;
                 break;
             case Account:
                 secure = true;
@@ -592,6 +602,10 @@
 
     View createUnlockScreenFor(UnlockMode unlockMode) {
         View unlockView = null;
+
+        if (DEBUG) Log.d(TAG,
+                "createUnlockScreenFor(" + unlockMode + "): mEnableFallback=" + mEnableFallback);
+
         if (unlockMode == UnlockMode.Pattern) {
             PatternUnlockScreen view = new PatternUnlockScreen(
                     mContext,
@@ -600,10 +614,15 @@
                     mUpdateMonitor,
                     mKeyguardScreenCallback,
                     mUpdateMonitor.getFailedAttempts());
-            if (DEBUG) Log.d(TAG,
-                "createUnlockScreenFor(" + unlockMode + "): mEnableFallback=" + mEnableFallback);
             view.setEnableFallback(mEnableFallback);
             unlockView = view;
+        } else if (unlockMode == UnlockMode.SimPuk) {
+            unlockView = new SimPukUnlockScreen(
+                    mContext,
+                    mConfiguration,
+                    mUpdateMonitor,
+                    mKeyguardScreenCallback,
+                    mLockPatternUtils);
         } else if (unlockMode == UnlockMode.SimPin) {
             unlockView = new SimUnlockScreen(
                     mContext,
@@ -654,7 +673,9 @@
      */
     private Mode getInitialMode() {
         final IccCard.State simState = mUpdateMonitor.getSimState();
-        if (stuckOnLockScreenBecauseSimMissing() || (simState == IccCard.State.PUK_REQUIRED)) {
+        if (stuckOnLockScreenBecauseSimMissing() ||
+                (simState == IccCard.State.PUK_REQUIRED &&
+                        !mLockPatternUtils.isPukUnlockScreenEnable())) {
             return Mode.LockScreen;
         } else {
             // Show LockScreen first for any screen other than Pattern unlock.
@@ -676,8 +697,10 @@
     private UnlockMode getUnlockMode() {
         final IccCard.State simState = mUpdateMonitor.getSimState();
         UnlockMode currentMode;
-        if (simState == IccCard.State.PIN_REQUIRED || simState == IccCard.State.PUK_REQUIRED) {
+        if (simState == IccCard.State.PIN_REQUIRED) {
             currentMode = UnlockMode.SimPin;
+        } else if (simState == IccCard.State.PUK_REQUIRED) {
+            currentMode = UnlockMode.SimPuk;
         } else {
             final int mode = mLockPatternUtils.getKeyguardStoredPasswordQuality();
             switch (mode) {
diff --git a/policy/src/com/android/internal/policy/impl/LockPatternKeyguardViewProperties.java b/policy/src/com/android/internal/policy/impl/LockPatternKeyguardViewProperties.java
index ed5a058..19adb3e 100644
--- a/policy/src/com/android/internal/policy/impl/LockPatternKeyguardViewProperties.java
+++ b/policy/src/com/android/internal/policy/impl/LockPatternKeyguardViewProperties.java
@@ -55,8 +55,10 @@
 
     private boolean isSimPinSecure() {
         final IccCard.State simState = mUpdateMonitor.getSimState();
-        return (simState == IccCard.State.PIN_REQUIRED || simState == IccCard.State.PUK_REQUIRED
-            || simState == IccCard.State.ABSENT);
+        return (simState == IccCard.State.PIN_REQUIRED
+                || simState == IccCard.State.PUK_REQUIRED
+                || simState == IccCard.State.ABSENT
+                || simState == IccCard.State.PERM_DISABLED);
     }
 
 }
diff --git a/policy/src/com/android/internal/policy/impl/LockScreen.java b/policy/src/com/android/internal/policy/impl/LockScreen.java
index a9d5ce4..8b7a61e 100644
--- a/policy/src/com/android/internal/policy/impl/LockScreen.java
+++ b/policy/src/com/android/internal/policy/impl/LockScreen.java
@@ -22,6 +22,7 @@
 import com.android.internal.widget.SlidingTab;
 import com.android.internal.widget.WaveView;
 import com.android.internal.widget.WaveView.OnTriggerListener;
+import com.android.internal.widget.multiwaveview.MultiWaveView;
 
 import android.app.ActivityManager;
 import android.content.Context;
@@ -91,6 +92,8 @@
     private WaveView mEnergyWave;
     private SlidingTabMethods mSlidingTabMethods;
     private WaveViewMethods mWaveViewMethods;
+    private MultiWaveView mMultiWaveView;
+    private MultiWaveViewMethods mMultiWaveViewMethods;
 
     /**
      * The status of this lock screen.
@@ -126,7 +129,12 @@
         /**
          * The sim card is locked.
          */
-        SimLocked(true);
+        SimLocked(true),
+
+        /**
+         * The sim card is permanently disabled due to puk unlock failure
+         */
+        SimPermDisabled(false);
 
         private final boolean mShowStatusLines;
 
@@ -166,34 +174,9 @@
             if (whichHandle == SlidingTab.OnTriggerListener.LEFT_HANDLE) {
                 mCallback.goToUnlockScreen();
             } else if (whichHandle == SlidingTab.OnTriggerListener.RIGHT_HANDLE) {
-                // toggle silent mode
-                mSilentMode = !mSilentMode;
-                if (mSilentMode) {
-                    final boolean vibe = (Settings.System.getInt(
-                        getContext().getContentResolver(),
-                        Settings.System.VIBRATE_IN_SILENT, 1) == 1);
-
-                    mAudioManager.setRingerMode(vibe
-                        ? AudioManager.RINGER_MODE_VIBRATE
-                        : AudioManager.RINGER_MODE_SILENT);
-                } else {
-                    mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
-                }
-
+                toggleRingMode();
                 updateRightTabResources();
-
-                String message = mSilentMode ?
-                        getContext().getString(R.string.global_action_silent_mode_on_status) :
-                        getContext().getString(R.string.global_action_silent_mode_off_status);
-
-                final int toastIcon = mSilentMode
-                    ? R.drawable.ic_lock_ringer_off
-                    : R.drawable.ic_lock_ringer_on;
-
-                final int toastColor = mSilentMode
-                    ? getContext().getResources().getColor(R.color.keyguard_text_color_soundoff)
-                    : getContext().getResources().getColor(R.color.keyguard_text_color_soundon);
-                toastMessage(mScreenLocked, message, toastColor, toastIcon);
+                doSilenceRingToast();
                 mCallback.pokeWakelock();
             }
         }
@@ -214,25 +197,20 @@
         }
     }
 
-    class WaveViewMethods implements WaveView.OnTriggerListener {
-        private static final int WAIT_FOR_ANIMATION_TIMEOUT = 0;
-        private static final int STAY_ON_WHILE_GRABBED_TIMEOUT = 30000;
+    private static final int WAIT_FOR_ANIMATION_TIMEOUT = 0;
+    private static final int STAY_ON_WHILE_GRABBED_TIMEOUT = 30000;
 
+    class WaveViewMethods implements WaveView.OnTriggerListener {
         /** {@inheritDoc} */
         public void onTrigger(View v, int whichHandle) {
             if (whichHandle == WaveView.OnTriggerListener.CENTER_HANDLE) {
-                // Delay hiding lock screen long enough for animation to finish
-                postDelayed(new Runnable() {
-                    public void run() {
-                        mCallback.goToUnlockScreen();
-                    }
-                }, WAIT_FOR_ANIMATION_TIMEOUT);
+                requestUnlockScreen();
             }
         }
 
         /** {@inheritDoc} */
         public void onGrabbedStateChange(View v, int grabbedState) {
-            if (DBG) Log.v(TAG, "*** LockScreen accel is " 
+            if (DBG) Log.v(TAG, "*** LockScreen accel is "
                     + (mEnergyWave.isHardwareAccelerated() ? "on":"off"));
             // Don't poke the wake lock when returning to a state where the handle is
             // not grabbed since that can happen when the system (instead of the user)
@@ -243,6 +221,80 @@
         }
     }
 
+    class MultiWaveViewMethods implements MultiWaveView.OnTriggerListener {
+        public void onGrabbed(View v, int handle) {
+
+        }
+        public void onReleased(View v, int handle) {
+
+        }
+        public void onTrigger(View v, int target) {
+            if (target == 0) { // TODO: Use resources to determine which handle was used
+                mCallback.goToUnlockScreen();
+            } else if (target == 2) {
+                toggleRingMode();
+                updateResources();
+                doSilenceRingToast();
+                mCallback.pokeWakelock();
+            }
+
+        }
+
+        private void updateResources() {
+            mMultiWaveView.setTargetResources(mSilentMode ? R.array.lockscreen_targets_when_silent
+                    : R.array.lockscreen_targets_when_soundon);
+        }
+
+        public void onGrabbedStateChange(View v, int handle) {
+            // Don't poke the wake lock when returning to a state where the handle is
+            // not grabbed since that can happen when the system (instead of the user)
+            // cancels the grab.
+            if (handle != MultiWaveView.OnTriggerListener.NO_HANDLE) {
+                mCallback.pokeWakelock();
+            }
+        }
+    }
+
+    private void requestUnlockScreen() {
+        // Delay hiding lock screen long enough for animation to finish
+        postDelayed(new Runnable() {
+            public void run() {
+                mCallback.goToUnlockScreen();
+            }
+        }, WAIT_FOR_ANIMATION_TIMEOUT);
+    }
+
+    private void doSilenceRingToast() {
+        String message = mSilentMode ?
+                getContext().getString(R.string.global_action_silent_mode_on_status) :
+                getContext().getString(R.string.global_action_silent_mode_off_status);
+
+        final int toastIcon = mSilentMode
+            ? R.drawable.ic_lock_ringer_off
+            : R.drawable.ic_lock_ringer_on;
+
+        final int toastColor = mSilentMode
+            ? getContext().getResources().getColor(R.color.keyguard_text_color_soundoff)
+            : getContext().getResources().getColor(R.color.keyguard_text_color_soundon);
+        toastMessage(mScreenLocked, message, toastColor, toastIcon);
+    }
+
+    private void toggleRingMode() {
+        // toggle silent mode
+        mSilentMode = !mSilentMode;
+        if (mSilentMode) {
+            final boolean vibe = (Settings.System.getInt(
+                getContext().getContentResolver(),
+                Settings.System.VIBRATE_IN_SILENT, 1) == 1);
+
+            mAudioManager.setRingerMode(vibe
+                ? AudioManager.RINGER_MODE_VIBRATE
+                : AudioManager.RINGER_MODE_SILENT);
+        } else {
+            mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
+        }
+    }
+
     /**
      * In general, we enable unlocking the insecure key guard with the menu key. However, there are
      * some cases where we wish to disable it, notably when the menu button placement or technology
@@ -319,9 +371,9 @@
         mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
         mSilentMode = isSilentMode();
 
-        mSlidingTab = (SlidingTab) findViewById(R.id.tab_selector);
-        mEnergyWave = (WaveView) findViewById(R.id.wave_view);
-        if (mSlidingTab != null) {
+        View unlockWidget = findViewById(R.id.unlock_widget);
+        if (unlockWidget instanceof SlidingTab) {
+            mSlidingTab = (SlidingTab) unlockWidget;
             mSlidingTab.setHoldAfterTrigger(true, false);
             mSlidingTab.setLeftHintText(R.string.lockscreen_unlock_label);
             mSlidingTab.setLeftTabResources(
@@ -332,11 +384,17 @@
             mSlidingTabMethods = new SlidingTabMethods();
             mSlidingTab.setOnTriggerListener(mSlidingTabMethods);
             mSlidingTabMethods.updateRightTabResources();
-        } else if (mEnergyWave != null) {
+        } else if (unlockWidget instanceof WaveView) {
+            mEnergyWave = (WaveView) unlockWidget;
             mWaveViewMethods = new WaveViewMethods();
             mEnergyWave.setOnTriggerListener(mWaveViewMethods);
+        } else if (unlockWidget instanceof MultiWaveView) {
+            mMultiWaveView = (MultiWaveView) unlockWidget;
+            mMultiWaveViewMethods = new MultiWaveViewMethods();
+            mMultiWaveViewMethods.updateResources(); // update silence/ring resources
+            mMultiWaveView.setOnTriggerListener(mMultiWaveViewMethods);
         } else {
-            throw new IllegalStateException("Must have either SlidingTab or WaveView defined");
+            throw new IllegalStateException("Unrecognized unlock widget: " + unlockWidget);
         }
 
         resetStatusInfo(updateMonitor);
@@ -450,7 +508,9 @@
      */
     private Status getCurrentStatus(IccCard.State simState) {
         boolean missingAndNotProvisioned = (!mUpdateMonitor.isDeviceProvisioned()
-                && simState == IccCard.State.ABSENT);
+                && (simState == IccCard.State.ABSENT
+                        || simState == IccCard.State.PERM_DISABLED));
+
         if (missingAndNotProvisioned) {
             return Status.SimMissingLocked;
         }
@@ -468,6 +528,8 @@
                 return Status.SimPukLocked;
             case READY:
                 return Status.Normal;
+            case PERM_DISABLED:
+                return Status.SimPermDisabled;
             case UNKNOWN:
                 return Status.SimMissing;
         }
@@ -534,11 +596,23 @@
             case SimMissing:
                 // text
                 mStatusView.setCarrierText(R.string.lockscreen_missing_sim_message_short);
-                mScreenLocked.setText(R.string.lockscreen_missing_sim_instructions);
+                mScreenLocked.setText(R.string.lockscreen_missing_sim_instructions_long);
 
                 // layout
                 mScreenLocked.setVisibility(View.VISIBLE);
-                mEmergencyCallText.setVisibility(View.VISIBLE);
+                mLockPatternUtils.updateEmergencyCallText(mEmergencyCallText);
+                enableUnlock(); // do not need to show the e-call button; user may unlock
+                break;
+
+            case SimPermDisabled:
+                // text
+                mStatusView.setCarrierText(R.string.lockscreen_missing_sim_message_short);
+                mScreenLocked.setText(
+                        R.string.lockscreen_permanent_disabled_sim_instructions);
+
+                // layout
+                mScreenLocked.setVisibility(View.VISIBLE);
+                mLockPatternUtils.updateEmergencyCallText(mEmergencyCallText);
                 enableUnlock(); // do not need to show the e-call button; user may unlock
                 break;
 
@@ -552,8 +626,8 @@
 
                 // layout
                 mScreenLocked.setVisibility(View.VISIBLE);
-                mEmergencyCallText.setVisibility(View.VISIBLE);
-                mEmergencyCallButton.setVisibility(View.VISIBLE);
+                mLockPatternUtils.updateEmergencyCallText(mEmergencyCallText);
+                mLockPatternUtils.updateEmergencyCallButtonState(mEmergencyCallButton);
                 disableUnlock();
                 break;
 
@@ -579,10 +653,15 @@
                 mScreenLocked.setText(R.string.lockscreen_sim_puk_locked_instructions);
 
                 // layout
-                mScreenLocked.setVisibility(View.VISIBLE);
-                mEmergencyCallText.setVisibility(View.VISIBLE);
-                mEmergencyCallButton.setVisibility(View.VISIBLE);
-                disableUnlock();
+                mLockPatternUtils.updateEmergencyCallText(mEmergencyCallText);
+                mLockPatternUtils.updateEmergencyCallButtonState(mEmergencyCallButton);
+                if (mLockPatternUtils.isPukUnlockScreenEnable()) {
+                    mScreenLocked.setVisibility(View.INVISIBLE);
+                    enableUnlock();
+                } else {
+                    mScreenLocked.setVisibility(View.VISIBLE);
+                    disableUnlock();
+                }
                 break;
         }
     }
@@ -652,11 +731,17 @@
         if (mEnergyWave != null) {
             mEnergyWave.reset();
         }
+        if (mMultiWaveView != null) {
+            mMultiWaveView.reset(false);
+        }
     }
 
     /** {@inheritDoc} */
     public void onResume() {
         resetStatusInfo(mUpdateMonitor);
+        if (mMultiWaveView != null) {
+            mMultiWaveView.ping();
+        }
     }
 
     /** {@inheritDoc} */
diff --git a/policy/src/com/android/internal/policy/impl/PasswordUnlockScreen.java b/policy/src/com/android/internal/policy/impl/PasswordUnlockScreen.java
index ca56c4f..6734005 100644
--- a/policy/src/com/android/internal/policy/impl/PasswordUnlockScreen.java
+++ b/policy/src/com/android/internal/policy/impl/PasswordUnlockScreen.java
@@ -27,6 +27,7 @@
 
 import android.os.CountDownTimer;
 import android.os.SystemClock;
+import android.security.KeyStore;
 import android.telephony.TelephonyManager;
 import android.text.InputType;
 import android.text.method.DigitsKeyListener;
@@ -124,7 +125,8 @@
             mPasswordEntry.setInputType(InputType.TYPE_CLASS_NUMBER
                     | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
         } else {
-            mPasswordEntry.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
+            mPasswordEntry.setInputType(InputType.TYPE_CLASS_TEXT
+                    | InputType.TYPE_TEXT_VARIATION_PASSWORD);
         }
 
         mEmergencyCallButton = (Button) findViewById(R.id.emergencyCall);
@@ -231,6 +233,7 @@
             mCallback.keyguardDone(true);
             mCallback.reportSuccessfulUnlockAttempt();
             mStatusView.setInstructionText(null);
+            KeyStore.getInstance().password(entry);
         } else if (entry.length() > MINIMUM_PASSWORD_LENGTH_BEFORE_REPORT ) {
             // to avoid accidental lockout, only count attempts that are long enough to be a
             // real password. This may require some tweaking.
diff --git a/policy/src/com/android/internal/policy/impl/PatternUnlockScreen.java b/policy/src/com/android/internal/policy/impl/PatternUnlockScreen.java
index 018fe0c..cd79b60 100644
--- a/policy/src/com/android/internal/policy/impl/PatternUnlockScreen.java
+++ b/policy/src/com/android/internal/policy/impl/PatternUnlockScreen.java
@@ -20,8 +20,10 @@
 import android.content.res.Configuration;
 import android.os.CountDownTimer;
 import android.os.SystemClock;
+import android.security.KeyStore;
 import android.view.LayoutInflater;
 import android.view.View;
+import android.view.View.OnClickListener;
 import android.view.ViewGroup;
 import android.view.MotionEvent;
 import android.widget.Button;
@@ -72,12 +74,8 @@
     private boolean mEnableFallback;
 
     private StatusView mStatusView;
-
     private LockPatternView mLockPatternView;
 
-    private ViewGroup mFooterNormal;
-    private ViewGroup mFooterForgotPattern;
-
     /**
      * Keeps track of the last time we poked the wake lock during dispatching
      * of the touch event, initalized to something gauranteed to make us
@@ -95,9 +93,20 @@
         }
     };
 
+    private final OnClickListener mEmergencyClick = new OnClickListener() {
+        public void onClick(View v) {
+            mCallback.takeEmergencyCallAction();
+        }
+    };
+
+    private final OnClickListener mForgotPatternClick = new OnClickListener() {
+        public void onClick(View v) {
+            mCallback.forgotPattern(true);
+        }
+    };
+
     private Button mForgotPatternButton;
-    private Button mEmergencyAlone;
-    private Button mEmergencyTogether;
+    private Button mEmergencyButton;
     private int mCreationOrientation;
 
     enum FooterMode {
@@ -106,23 +115,27 @@
         VerifyUnlocked
     }
 
+    private void hideForgotPatternButton() {
+        mForgotPatternButton.setVisibility(View.GONE);
+    }
+
+    private void showForgotPatternButton() {
+        mForgotPatternButton.setVisibility(View.VISIBLE);
+    }
+
     private void updateFooter(FooterMode mode) {
         switch (mode) {
             case Normal:
-                Log.d(TAG, "mode normal");
-                mFooterNormal.setVisibility(View.VISIBLE);
-                mFooterForgotPattern.setVisibility(View.GONE);
+                if (DEBUG) Log.d(TAG, "mode normal");
+                hideForgotPatternButton();
                 break;
             case ForgotLockPattern:
-                Log.d(TAG, "mode ForgotLockPattern");
-                mFooterNormal.setVisibility(View.GONE);
-                mFooterForgotPattern.setVisibility(View.VISIBLE);
-                mForgotPatternButton.setVisibility(View.VISIBLE);
+                if (DEBUG) Log.d(TAG, "mode ForgotLockPattern");
+                showForgotPatternButton();
                 break;
             case VerifyUnlocked:
-                Log.d(TAG, "mode VerifyUnlocked");
-                mFooterNormal.setVisibility(View.GONE);
-                mFooterForgotPattern.setVisibility(View.GONE);
+                if (DEBUG) Log.d(TAG, "mode VerifyUnlocked");
+                hideForgotPatternButton();
         }
     }
 
@@ -175,32 +188,16 @@
 
         mLockPatternView = (LockPatternView) findViewById(R.id.lockPattern);
 
-        mFooterNormal = (ViewGroup) findViewById(R.id.footerNormal);
-        mFooterForgotPattern = (ViewGroup) findViewById(R.id.footerForgotPattern);
-
         // emergency call buttons
-        final OnClickListener emergencyClick = new OnClickListener() {
-            public void onClick(View v) {
-                mCallback.takeEmergencyCallAction();
-            }
-        };
+        mEmergencyButton = (Button) findViewById(R.id.emergencyCallButton);
+        mEmergencyButton.setFocusable(false); // touch only!
+        mEmergencyButton.setOnClickListener(mEmergencyClick);
 
-        mEmergencyAlone = (Button) findViewById(R.id.emergencyCallAlone);
-        mEmergencyAlone.setFocusable(false); // touch only!
-        mEmergencyAlone.setOnClickListener(emergencyClick);
-        mEmergencyTogether = (Button) findViewById(R.id.emergencyCallTogether);
-        mEmergencyTogether.setFocusable(false);
-        mEmergencyTogether.setOnClickListener(emergencyClick);
         refreshEmergencyButtonText();
 
-        mForgotPatternButton = (Button) findViewById(R.id.forgotPattern);
+        mForgotPatternButton = (Button) findViewById(R.id.forgotPatternButton);
         mForgotPatternButton.setText(R.string.lockscreen_forgot_pattern_button_text);
-        mForgotPatternButton.setOnClickListener(new OnClickListener() {
-
-            public void onClick(View v) {
-                mCallback.forgotPattern(true);
-            }
-        });
+        mForgotPatternButton.setOnClickListener(mForgotPatternClick);
 
         // make it so unhandled touch events within the unlock screen go to the
         // lock pattern view.
@@ -231,8 +228,7 @@
     }
 
     private void refreshEmergencyButtonText() {
-        mLockPatternUtils.updateEmergencyCallButtonState(mEmergencyAlone);
-        mLockPatternUtils.updateEmergencyCallButtonState(mEmergencyTogether);
+        mLockPatternUtils.updateEmergencyCallButtonState(mEmergencyButton);
     }
 
     public void setEnableFallback(boolean state) {
@@ -337,8 +333,11 @@
         mLockPatternView.clearPattern();
 
         // show "forgot pattern?" button if we have an alternate authentication method
-        mForgotPatternButton.setVisibility(mCallback.doesFallbackUnlockScreenExist()
-                ? View.VISIBLE : View.INVISIBLE);
+        if (mCallback.doesFallbackUnlockScreenExist()) {
+            showForgotPatternButton();
+        } else {
+            hideForgotPatternButton();
+        }
 
         // if the user is currently locked out, enforce it.
         long deadline = mLockPatternUtils.getLockoutAttemptDeadline();
@@ -407,6 +406,7 @@
                 mStatusView.updateStatusLines(true);
                 mCallback.keyguardDone(true);
                 mCallback.reportSuccessfulUnlockAttempt();
+                KeyStore.getInstance().password(LockPatternUtils.patternToString(pattern));
             } else {
                 boolean reportFailedAttempt = false;
                 if (pattern.size() > MIN_PATTERN_BEFORE_POKE_WAKELOCK) {
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindow.java b/policy/src/com/android/internal/policy/impl/PhoneWindow.java
index d997109..75f466a 100644
--- a/policy/src/com/android/internal/policy/impl/PhoneWindow.java
+++ b/policy/src/com/android/internal/policy/impl/PhoneWindow.java
@@ -1446,7 +1446,9 @@
         }
 
         if (mActionBar != null) {
-            outState.putBoolean(ACTION_BAR_TAG, mActionBar.isOverflowMenuShowing());
+            SparseArray<Parcelable> actionBarStates = new SparseArray<Parcelable>();
+            mActionBar.saveHierarchyState(actionBarStates);
+            outState.putSparseParcelableArray(ACTION_BAR_TAG, actionBarStates);
         }
 
         return outState;
@@ -1484,8 +1486,10 @@
             restorePanelState(panelStates);
         }
 
-        if (mActionBar != null && savedInstanceState.getBoolean(ACTION_BAR_TAG)) {
-            mActionBar.postShowOverflowMenu();
+        if (mActionBar != null) {
+            SparseArray<Parcelable> actionBarStates =
+                    savedInstanceState.getSparseParcelableArray(ACTION_BAR_TAG);
+            mActionBar.restoreHierarchyState(actionBarStates);
         }
     }
 
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
index e48dbe9..b52e7e1 100755
--- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
+++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
@@ -30,6 +30,7 @@
 import android.content.IntentFilter;
 import android.content.pm.ActivityInfo;
 import android.content.pm.PackageManager;
+import android.content.res.CompatibilityInfo;
 import android.content.res.Configuration;
 import android.content.res.Resources;
 import android.database.ContentObserver;
@@ -56,6 +57,7 @@
 import com.android.internal.view.BaseInputHandler;
 import com.android.internal.widget.PointerLocationView;
 
+import android.util.DisplayMetrics;
 import android.util.EventLog;
 import android.util.Log;
 import android.util.Slog;
@@ -147,10 +149,12 @@
     static final int LONG_PRESS_POWER_NOTHING = 0;
     static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
     static final int LONG_PRESS_POWER_SHUT_OFF = 2;
-    
+
+    // These need to match the documentation/constant in
+    // core/res/res/values/config.xml
     static final int LONG_PRESS_HOME_NOTHING = 0;
     static final int LONG_PRESS_HOME_RECENT_DIALOG = 1;
-    static final int LONG_PRESS_HOME_RECENT_ACTIVITY = 2;
+    static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 2;
 
     // wallpaper is at the bottom, though the window manager may move it.
     static final int WALLPAPER_LAYER = 2;
@@ -328,6 +332,8 @@
     static final Rect mTmpVisibleFrame = new Rect();
     
     WindowState mTopFullscreenOpaqueWindowState;
+    WindowState mTopAppWindowState;
+    WindowState mLastTopAppWindowState;
     boolean mTopIsFullscreen;
     boolean mForceStatusBar;
     boolean mHideLockScreen;
@@ -338,7 +344,6 @@
     Intent mDeskDockIntent;
     int mShortcutKeyPressed = -1;
     boolean mConsumeShortcutKeyUp;
-    boolean mShowMenuKey = false; // track FLAG_NEEDS_MENU_KEY on frontmost window
 
     // support for activating the lock screen while the screen is on
     boolean mAllowLockscreenWhenOn;
@@ -620,7 +625,7 @@
             mLongPressOnHomeBehavior
                     = mContext.getResources().getInteger(R.integer.config_longPressOnHomeBehavior);
             if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
-                    mLongPressOnHomeBehavior > LONG_PRESS_HOME_RECENT_ACTIVITY) {
+                    mLongPressOnHomeBehavior > LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
                 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
             }
         }
@@ -636,17 +641,11 @@
 
         if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_DIALOG) {
             showOrHideRecentAppsDialog(0, true /*dismissIfShown*/);
-        } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_ACTIVITY) {
+        } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
             try {
-                Intent intent = new Intent();
-                intent.setClassName("com.android.systemui", 
-                        "com.android.systemui.recent.RecentApplicationsActivity");
-                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK 
-                        | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
-                mContext.startActivity(intent);
-                return;
-            } catch (ActivityNotFoundException e) {
-                Log.e(TAG, "Failed to launch RecentAppsIntent", e);
+                mStatusBarService.toggleRecentApps();
+            } catch (RemoteException e) {
+                Slog.e(TAG, "RemoteException when showing recent apps", e);
             }
         }
     }
@@ -745,15 +744,14 @@
         mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
                 com.android.internal.R.array.config_safeModeEnabledVibePattern);
 
-        // Note: the Configuration is not stable here, so we cannot load mStatusBarCanHide from
-        // config_statusBarCanHide because the latter depends on the screen size
-
         // Controls rotation and the like.
         initializeHdmiState();
     }
 
     public void setInitialDisplaySize(int width, int height) {
+        int shortSize;
         if (width > height) {
+            shortSize = height;
             mLandscapeRotation = Surface.ROTATION_0;
             mSeascapeRotation = Surface.ROTATION_180;
             if (mContext.getResources().getBoolean(
@@ -765,6 +763,7 @@
                 mUpsideDownRotation = Surface.ROTATION_90;
             }
         } else {
+            shortSize = width;
             mPortraitRotation = Surface.ROTATION_0;
             mUpsideDownRotation = Surface.ROTATION_180;
             if (mContext.getResources().getBoolean(
@@ -776,6 +775,18 @@
                 mSeascapeRotation = Surface.ROTATION_270;
             }
         }
+
+        // Determine whether the status bar can hide based on the size
+        // of the screen.  We assume sizes > 600dp are tablets where we
+        // will use the system bar.
+        int shortSizeDp = shortSize
+                * DisplayMetrics.DENSITY_DEFAULT
+                / DisplayMetrics.DENSITY_DEVICE;
+        mStatusBarCanHide = shortSizeDp < 600;
+        mStatusBarHeight = mContext.getResources().getDimensionPixelSize(
+                mStatusBarCanHide
+                ? com.android.internal.R.dimen.status_bar_height
+                : com.android.internal.R.dimen.system_bar_height);
     }
 
     public void updateSettings() {
@@ -859,7 +870,7 @@
                 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
             lp.format = PixelFormat.TRANSLUCENT;
             lp.setTitle("PointerLocation");
-            WindowManagerImpl wm = (WindowManagerImpl)
+            WindowManager wm = (WindowManager)
                     mContext.getSystemService(Context.WINDOW_SERVICE);
             wm.addView(addView, lp);
             
@@ -882,7 +893,7 @@
                 mPointerLocationInputChannel = null;
             }
             
-            WindowManagerImpl wm = (WindowManagerImpl)
+            WindowManager wm = (WindowManager)
                     mContext.getSystemService(Context.WINDOW_SERVICE);
             wm.removeView(removeView);
         }
@@ -1083,6 +1094,10 @@
         return STATUS_BAR_LAYER;
     }
 
+    public boolean canStatusBarHide() {
+        return mStatusBarCanHide;
+    }
+
     public int getNonDecorDisplayWidth(int rotation, int fullWidth) {
         return fullWidth;
     }
@@ -1109,9 +1124,9 @@
     }
     
     /** {@inheritDoc} */
-    public View addStartingWindow(IBinder appToken, String packageName,
-                                  int theme, CharSequence nonLocalizedLabel,
-                                  int labelRes, int icon, int windowFlags) {
+    public View addStartingWindow(IBinder appToken, String packageName, int theme,
+            CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
+            int icon, int windowFlags) {
         if (!SHOW_STARTING_ANIMATIONS) {
             return null;
         }
@@ -1157,8 +1172,12 @@
                 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
                 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
     
+            if (!compatInfo.supportsScreen()) {
+                win.addFlags(WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW);
+            }
+
             win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
-                                WindowManager.LayoutParams.MATCH_PARENT);
+                    WindowManager.LayoutParams.MATCH_PARENT);
     
             final WindowManager.LayoutParams params = win.getAttributes();
             params.token = appToken;
@@ -1167,8 +1186,7 @@
                     com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
             params.setTitle("Starting " + packageName);
 
-            WindowManagerImpl wm = (WindowManagerImpl)
-                    context.getSystemService(Context.WINDOW_SERVICE);
+            WindowManager wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
             View view = win.getDecorView();
 
             if (win.isFloating()) {
@@ -1213,7 +1231,7 @@
             TAG, "Removing starting window for " + appToken + ": " + window);
 
         if (window != null) {
-            WindowManagerImpl wm = (WindowManagerImpl) mContext.getSystemService(Context.WINDOW_SERVICE);
+            WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
             wm.removeView(window);
         }
     }
@@ -1244,13 +1262,6 @@
                     return WindowManagerImpl.ADD_MULTIPLE_SINGLETON;
                 }
                 mStatusBar = win;
-
-                // The Configuration will be stable by now, so we can load this
-                mStatusBarCanHide = mContext.getResources().getBoolean(
-                        com.android.internal.R.bool.config_statusBarCanHide);
-                mStatusBarHeight = mContext.getResources().getDimensionPixelSize(
-                        com.android.internal.R.dimen.status_bar_height);
-
                 break;
             case TYPE_NAVIGATION_BAR:
                 mContext.enforceCallingOrSelfPermission(
@@ -1938,28 +1949,40 @@
                     Log.v(TAG, "layoutWindowLw(" + attrs.getTitle() + "): normal window");
                 // Otherwise, a normal window must be placed inside the content
                 // of all screen decorations.
-                pf.left = mContentLeft;
-                pf.top = mContentTop;
-                pf.right = mContentRight;
-                pf.bottom = mContentBottom;
-                if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
-                    df.left = cf.left = mDockLeft;
-                    df.top = cf.top = mDockTop;
-                    df.right = cf.right = mDockRight;
-                    df.bottom = cf.bottom = mDockBottom;
+                if (attrs.type == TYPE_STATUS_BAR_PANEL) {
+                    // Status bar panels are the only windows who can go on top of
+                    // the status bar.  They are protected by the STATUS_BAR_SERVICE
+                    // permission, so they have the same privileges as the status
+                    // bar itself.
+                    pf.left = df.left = cf.left = mRestrictedScreenLeft;
+                    pf.top = df.top = cf.top = mRestrictedScreenTop;
+                    pf.right = df.right = cf.right = mRestrictedScreenLeft+mRestrictedScreenWidth;
+                    pf.bottom = df.bottom = cf.bottom
+                            = mRestrictedScreenTop+mRestrictedScreenHeight;
                 } else {
-                    df.left = cf.left = mContentLeft;
-                    df.top = cf.top = mContentTop;
-                    df.right = cf.right = mContentRight;
-                    df.bottom = cf.bottom = mContentBottom;
-                }
-                if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
-                    vf.left = mCurLeft;
-                    vf.top = mCurTop;
-                    vf.right = mCurRight;
-                    vf.bottom = mCurBottom;
-                } else {
-                    vf.set(cf);
+                    pf.left = mContentLeft;
+                    pf.top = mContentTop;
+                    pf.right = mContentRight;
+                    pf.bottom = mContentBottom;
+                    if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
+                        df.left = cf.left = mDockLeft;
+                        df.top = cf.top = mDockTop;
+                        df.right = cf.right = mDockRight;
+                        df.bottom = cf.bottom = mDockBottom;
+                    } else {
+                        df.left = cf.left = mContentLeft;
+                        df.top = cf.top = mContentTop;
+                        df.right = cf.right = mContentRight;
+                        df.bottom = cf.bottom = mContentBottom;
+                    }
+                    if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
+                        vf.left = mCurLeft;
+                        vf.top = mCurTop;
+                        vf.right = mCurRight;
+                        vf.bottom = mCurBottom;
+                    } else {
+                        vf.set(cf);
+                    }
                 }
             }
         }
@@ -2005,6 +2028,7 @@
     /** {@inheritDoc} */
     public void beginAnimationLw(int displayWidth, int displayHeight) {
         mTopFullscreenOpaqueWindowState = null;
+        mTopAppWindowState = null;
         mForceStatusBar = false;
         
         mHideLockScreen = false;
@@ -2040,6 +2064,12 @@
                 }
             }
         }
+        if (mTopAppWindowState == null && win.isVisibleOrBehindKeyguardLw()) {
+            if (attrs.type >= FIRST_APPLICATION_WINDOW
+                    && attrs.type <= LAST_APPLICATION_WINDOW) {
+                mTopAppWindowState = win;
+            }
+        }
     }
 
     /** {@inheritDoc} */
@@ -2083,22 +2113,13 @@
             }
         }
 
-        boolean topNeedsMenu = mShowMenuKey;
-        if (lp != null) {
-            topNeedsMenu = (lp.flags & WindowManager.LayoutParams.FLAG_NEEDS_MENU_KEY) != 0;
-        }
-
-        if (DEBUG_LAYOUT) Log.v(TAG, "Top window " 
-                + (topNeedsMenu ? "needs" : "does not need")
-                + " the MENU key");
-
         mTopIsFullscreen = topIsFullscreen;
-        final boolean changedMenu = (topNeedsMenu != mShowMenuKey);
 
-        if (changedMenu) {
-            final boolean topNeedsMenuF = topNeedsMenu;
+        if (mTopAppWindowState != null && mTopAppWindowState != mLastTopAppWindowState) {
+            mLastTopAppWindowState = mTopAppWindowState;
 
-            mShowMenuKey = topNeedsMenu;
+            final boolean topNeedsMenu = (mTopAppWindowState.getAttrs().flags
+                    & WindowManager.LayoutParams.FLAG_NEEDS_MENU_KEY) != 0;
 
             mHandler.post(new Runnable() {
                     public void run() {
@@ -2113,9 +2134,7 @@
                         final IStatusBarService sbs = mStatusBarService;
                         if (mStatusBarService != null) {
                             try {
-                                if (changedMenu) {
-                                    sbs.setMenuKeyVisible(topNeedsMenuF);
-                                }
+                                sbs.topAppWindowChanged(topNeedsMenu);
                             } catch (RemoteException e) {
                                 // This should be impossible because we're in the same process.
                                 mStatusBarService = null;
diff --git a/policy/src/com/android/internal/policy/impl/SimPukUnlockScreen.java b/policy/src/com/android/internal/policy/impl/SimPukUnlockScreen.java
new file mode 100644
index 0000000..544bb3d
--- /dev/null
+++ b/policy/src/com/android/internal/policy/impl/SimPukUnlockScreen.java
@@ -0,0 +1,470 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.policy.impl;
+
+import android.app.Dialog;
+import android.app.ProgressDialog;
+import android.content.Context;
+import android.content.res.Configuration;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+
+import com.android.internal.telephony.ITelephony;
+import com.android.internal.telephony.IccCard;
+import com.android.internal.widget.LockPatternUtils;
+
+import android.text.Editable;
+import android.util.Log;
+import android.view.KeyEvent;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.WindowManager;
+import android.widget.Button;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+import com.android.internal.R;
+
+/**
+ * Displays a dialer like interface to unlock the SIM PUK.
+ */
+public class SimPukUnlockScreen extends LinearLayout implements KeyguardScreen,
+    View.OnClickListener, KeyguardUpdateMonitor.InfoCallback {
+
+    private static final int DIGIT_PRESS_WAKE_MILLIS = 5000;
+
+    private final KeyguardUpdateMonitor mUpdateMonitor;
+    private final KeyguardScreenCallback mCallback;
+
+    private TextView mHeaderText;
+    private TextView mPukText;
+    private TextView mPinText;
+
+    private TextView mFocusedEntry;
+
+    private TextView mOkButton;
+    private Button mEmergencyCallButton;
+
+    private View mDelPukButton;
+    private View mDelPinButton;
+
+    private ProgressDialog mSimUnlockProgressDialog = null;
+
+    private LockPatternUtils mLockPatternUtils;
+
+    private int mCreationOrientation;
+
+    private int mKeyboardHidden;
+
+    private static final char[] DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
+
+    public SimPukUnlockScreen(Context context, Configuration configuration,
+            KeyguardUpdateMonitor updateMonitor, KeyguardScreenCallback callback,
+            LockPatternUtils lockpatternutils) {
+        super(context);
+        mUpdateMonitor = updateMonitor;
+        mCallback = callback;;
+
+        mCreationOrientation = configuration.orientation;
+        mKeyboardHidden = configuration.hardKeyboardHidden;
+        mLockPatternUtils = lockpatternutils;
+
+        LayoutInflater inflater = LayoutInflater.from(context);
+        if (mKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) {
+            inflater.inflate(
+                    R.layout.keyguard_screen_sim_puk_landscape, this, true);
+        } else {
+            inflater.inflate(
+                    R.layout.keyguard_screen_sim_puk_portrait, this, true);
+            new TouchInput();
+        }
+
+        mHeaderText = (TextView) findViewById(R.id.headerText);
+        mPukText = (TextView) findViewById(R.id.pukDisplay);
+        mPukText.setOnClickListener(new OnClickListener() {
+           public void onClick(View v) {
+               requestFocus(mPukText);
+               mCallback.pokeWakelock();
+           }
+        });
+        mPinText = (TextView) findViewById(R.id.pinDisplay);
+        mPinText.setOnClickListener(this);
+
+        mDelPukButton = findViewById(R.id.pukDel);
+        mDelPukButton.setOnClickListener(this);
+        mDelPinButton = findViewById(R.id.pinDel);
+        mDelPinButton.setOnClickListener(this);
+
+
+        mEmergencyCallButton = (Button) findViewById(R.id.emergencyCall);
+        mOkButton = (TextView) findViewById(R.id.ok);
+
+        mHeaderText.setText(R.string.keyguard_password_enter_puk_code);
+        mPukText.setFocusable(false);
+        mPinText.setFocusable(false);
+        mOkButton.setOnClickListener(this);
+
+        requestFocus(mPukText);
+
+        if (mLockPatternUtils.isEmergencyCallCapable()) {
+            mLockPatternUtils.updateEmergencyCallButtonState(mEmergencyCallButton);
+            mEmergencyCallButton.setOnClickListener(this);
+        } else {
+            mEmergencyCallButton.setVisibility(View.GONE);
+        }
+
+        setFocusableInTouchMode(true);
+    }
+
+    private void requestFocus(TextView entry) {
+        mFocusedEntry = entry;
+        mFocusedEntry.setText("");
+    }
+
+    /** {@inheritDoc} */
+    public boolean needsInput() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    public void onPause() {
+
+    }
+
+    /** {@inheritDoc} */
+    public void onResume() {
+        // start fresh
+        mHeaderText.setText(R.string.keyguard_password_enter_puk_code);
+        requestFocus(mPukText);
+        mPinText.setText("");
+
+        if (mLockPatternUtils.isEmergencyCallCapable()) {
+            mLockPatternUtils.updateEmergencyCallButtonState(mEmergencyCallButton);
+        }
+    }
+
+    /** {@inheritDoc} */
+    public void cleanUp() {
+        // dismiss the dialog.
+        if (mSimUnlockProgressDialog != null) {
+            mSimUnlockProgressDialog.dismiss();
+            mSimUnlockProgressDialog = null;
+        }
+        mUpdateMonitor.removeCallback(this);
+    }
+
+
+    /**
+     * Since the IPC can block, we want to run the request in a separate thread
+     * with a callback.
+     */
+    private abstract class CheckSimPuk extends Thread {
+
+        private final String mPin, mPuk;
+
+        protected CheckSimPuk(String puk, String pin) {
+            mPuk = puk;
+            mPin = pin;
+        }
+
+        abstract void onSimLockChangedResponse(boolean success);
+
+        @Override
+        public void run() {
+            try {
+                final boolean result = ITelephony.Stub.asInterface(ServiceManager
+                        .checkService("phone")).supplyPuk(mPuk, mPin);
+
+                post(new Runnable() {
+                    public void run() {
+                        onSimLockChangedResponse(result);
+                    }
+                });
+            } catch (RemoteException e) {
+                post(new Runnable() {
+                    public void run() {
+                        onSimLockChangedResponse(false);
+                    }
+                });
+            }
+        }
+    }
+
+    public void onClick(View v) {
+        if (v == mDelPukButton) {
+            final Editable digits = mPukText.getEditableText();
+            final int len = digits.length();
+            if (len > 0) {
+                digits.delete(len-1, len);
+            }
+            mCallback.pokeWakelock();
+        } else if (v == mDelPinButton) {
+            final Editable digits = mPinText.getEditableText();
+            final int len = digits.length();
+            if (len > 0) {
+                digits.delete(len-1, len);
+            }
+            mCallback.pokeWakelock();
+        } else if (v == mPinText) {
+            requestFocus(mPinText);
+            mCallback.pokeWakelock();
+        } else if (v == mEmergencyCallButton) {
+            mCallback.takeEmergencyCallAction();
+        } else if (v == mOkButton) {
+            checkPuk();
+        }
+    }
+
+    private Dialog getSimUnlockProgressDialog() {
+        if (mSimUnlockProgressDialog == null) {
+            mSimUnlockProgressDialog = new ProgressDialog(mContext);
+            mSimUnlockProgressDialog.setMessage(
+                    mContext.getString(R.string.lockscreen_sim_unlock_progress_dialog_message));
+            mSimUnlockProgressDialog.setIndeterminate(true);
+            mSimUnlockProgressDialog.setCancelable(false);
+            mSimUnlockProgressDialog.getWindow().setType(
+                    WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
+            if (!mContext.getResources().getBoolean(
+                    com.android.internal.R.bool.config_sf_slowBlur)) {
+                mSimUnlockProgressDialog.getWindow().setFlags(
+                        WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
+                        WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
+            }
+        }
+        return mSimUnlockProgressDialog;
+    }
+
+    private void checkPuk() {
+        // make sure that the puk is at least 8 digits long.
+        if (mPukText.getText().length() < 8) {
+            // otherwise, display a message to the user, and don't submit.
+            mHeaderText.setText(R.string.invalidPuk);
+            mPukText.setText("");
+            mCallback.pokeWakelock();
+            return;
+        }
+
+        if (mPinText.getText().length() < 4
+                || mPinText.getText().length() > 8) {
+            // otherwise, display a message to the user, and don't submit.
+            mHeaderText.setText(R.string.invalidPin);
+            mPinText.setText("");
+            mCallback.pokeWakelock();
+            return;
+        }
+
+        getSimUnlockProgressDialog().show();
+
+        new CheckSimPuk(mPukText.getText().toString(),
+                mPinText.getText().toString()) {
+            void onSimLockChangedResponse(boolean success) {
+                if (mSimUnlockProgressDialog != null) {
+                    mSimUnlockProgressDialog.hide();
+                }
+                if (success) {
+                    // before closing the keyguard, report back that
+                    // the sim is unlocked so it knows right away
+                    mUpdateMonitor.reportSimUnlocked();
+                    mCallback.goToUnlockScreen();
+                } else {
+                    mHeaderText.setText(R.string.badPuk);
+                    mPukText.setText("");
+                    mPinText.setText("");
+                }
+                mCallback.pokeWakelock();
+            }
+        }.start();
+    }
+
+
+    public boolean onKeyDown(int keyCode, KeyEvent event) {
+        if (keyCode == KeyEvent.KEYCODE_BACK) {
+            mCallback.goToLockScreen();
+            return true;
+        }
+        final char match = event.getMatch(DIGITS);
+        if (match != 0) {
+            reportDigit(match - '0');
+            return true;
+        }
+        if (keyCode == KeyEvent.KEYCODE_DEL) {
+            mFocusedEntry.onKeyDown(keyCode, event);
+            final Editable digits = mFocusedEntry.getEditableText();
+            final int len = digits.length();
+            if (len > 0) {
+                digits.delete(len-1, len);
+            }
+            mCallback.pokeWakelock();
+            return true;
+        }
+
+        if (keyCode == KeyEvent.KEYCODE_ENTER) {
+            checkPuk();
+            return true;
+        }
+
+        return false;
+    }
+
+    private void reportDigit(int digit) {
+        mFocusedEntry.append(Integer.toString(digit));
+    }
+
+    void updateConfiguration() {
+        Configuration newConfig = getResources().getConfiguration();
+        if (newConfig.orientation != mCreationOrientation) {
+            mCallback.recreateMe(newConfig);
+        } else if (newConfig.hardKeyboardHidden != mKeyboardHidden) {
+            mKeyboardHidden = newConfig.hardKeyboardHidden;
+            final boolean isKeyboardOpen =
+                (mKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO);
+            if (mUpdateMonitor.isKeyguardBypassEnabled() && isKeyboardOpen) {
+                mCallback.goToUnlockScreen();
+            }
+        }
+
+    }
+
+    @Override
+    protected void onAttachedToWindow() {
+        super.onAttachedToWindow();
+        updateConfiguration();
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    protected void onConfigurationChanged(Configuration newConfig) {
+        super.onConfigurationChanged(newConfig);
+        updateConfiguration();
+    }
+
+    /**
+     * Helper class to handle input from touch dialer.  Only relevant when
+     * the keyboard is shut.
+     */
+    private class TouchInput implements View.OnClickListener {
+        private TextView mZero;
+        private TextView mOne;
+        private TextView mTwo;
+        private TextView mThree;
+        private TextView mFour;
+        private TextView mFive;
+        private TextView mSix;
+        private TextView mSeven;
+        private TextView mEight;
+        private TextView mNine;
+        private TextView mCancelButton;
+
+        private TouchInput() {
+            mZero = (TextView) findViewById(R.id.zero);
+            mOne = (TextView) findViewById(R.id.one);
+            mTwo = (TextView) findViewById(R.id.two);
+            mThree = (TextView) findViewById(R.id.three);
+            mFour = (TextView) findViewById(R.id.four);
+            mFive = (TextView) findViewById(R.id.five);
+            mSix = (TextView) findViewById(R.id.six);
+            mSeven = (TextView) findViewById(R.id.seven);
+            mEight = (TextView) findViewById(R.id.eight);
+            mNine = (TextView) findViewById(R.id.nine);
+            mCancelButton = (TextView) findViewById(R.id.cancel);
+
+            mZero.setText("0");
+            mOne.setText("1");
+            mTwo.setText("2");
+            mThree.setText("3");
+            mFour.setText("4");
+            mFive.setText("5");
+            mSix.setText("6");
+            mSeven.setText("7");
+            mEight.setText("8");
+            mNine.setText("9");
+
+            mZero.setOnClickListener(this);
+            mOne.setOnClickListener(this);
+            mTwo.setOnClickListener(this);
+            mThree.setOnClickListener(this);
+            mFour.setOnClickListener(this);
+            mFive.setOnClickListener(this);
+            mSix.setOnClickListener(this);
+            mSeven.setOnClickListener(this);
+            mEight.setOnClickListener(this);
+            mNine.setOnClickListener(this);
+            mCancelButton.setOnClickListener(this);
+        }
+
+
+        public void onClick(View v) {
+            if (v == mCancelButton) {
+                mCallback.goToLockScreen();
+                return;
+            }
+
+            final int digit = checkDigit(v);
+            if (digit >= 0) {
+                mCallback.pokeWakelock(DIGIT_PRESS_WAKE_MILLIS);
+                reportDigit(digit);
+            }
+        }
+
+        private int checkDigit(View v) {
+            int digit = -1;
+            if (v == mZero) {
+                digit = 0;
+            } else if (v == mOne) {
+                digit = 1;
+            } else if (v == mTwo) {
+                digit = 2;
+            } else if (v == mThree) {
+                digit = 3;
+            } else if (v == mFour) {
+                digit = 4;
+            } else if (v == mFive) {
+                digit = 5;
+            } else if (v == mSix) {
+                digit = 6;
+            } else if (v == mSeven) {
+                digit = 7;
+            } else if (v == mEight) {
+                digit = 8;
+            } else if (v == mNine) {
+                digit = 9;
+            }
+            return digit;
+        }
+    }
+
+    public void onPhoneStateChanged(String newState) {
+        if (mLockPatternUtils.isEmergencyCallCapable()) {
+            mLockPatternUtils.updateEmergencyCallButtonState(mEmergencyCallButton);
+        }
+    }
+
+    public void onRefreshBatteryInfo(boolean showBatteryInfo, boolean pluggedIn, int batteryLevel) {
+
+    }
+
+    public void onRefreshCarrierInfo(CharSequence plmn, CharSequence spn) {
+
+    }
+
+    public void onRingerModeChanged(int state) {
+
+    }
+
+    public void onTimeChanged() {
+
+    }
+}
diff --git a/policy/src/com/android/internal/policy/impl/SimUnlockScreen.java b/policy/src/com/android/internal/policy/impl/SimUnlockScreen.java
index 486e7aa..7255c27 100644
--- a/policy/src/com/android/internal/policy/impl/SimUnlockScreen.java
+++ b/policy/src/com/android/internal/policy/impl/SimUnlockScreen.java
@@ -92,16 +92,17 @@
         mBackSpaceButton = findViewById(R.id.backspace);
         mBackSpaceButton.setOnClickListener(this);
 
-        mEmergencyCallButton = (Button) findViewById(R.id.emergencyCall);
-        mLockPatternUtils.updateEmergencyCallButtonState(mEmergencyCallButton);
         mOkButton = (TextView) findViewById(R.id.ok);
 
         mHeaderText.setText(R.string.keyguard_password_enter_pin_code);
         mPinText.setFocusable(false);
 
-        mEmergencyCallButton.setOnClickListener(this);
         mOkButton.setOnClickListener(this);
 
+        mEmergencyCallButton = (Button) findViewById(R.id.emergencyCall);
+        mEmergencyCallButton.setOnClickListener(this);
+        mLockPatternUtils.updateEmergencyCallButtonState(mEmergencyCallButton);
+
         setFocusableInTouchMode(true);
     }
 
@@ -229,7 +230,7 @@
                 if (success) {
                     // before closing the keyguard, report back that
                     // the sim is unlocked so it knows right away
-                    mUpdateMonitor.reportSimPinUnlocked();
+                    mUpdateMonitor.reportSimUnlocked();
                     mCallback.goToUnlockScreen();
                 } else {
                     mHeaderText.setText(R.string.keyguard_password_wrong_pin_code);
@@ -291,9 +292,8 @@
                 mCallback.goToUnlockScreen();
             }
         }
-        
     }
-    
+
     @Override
     protected void onAttachedToWindow() {
         super.onAttachedToWindow();
@@ -403,7 +403,7 @@
     }
 
     public void onPhoneStateChanged(String newState) {
-        mLockPatternUtils.updateEmergencyCallButtonState(mEmergencyCallButton);
+            mLockPatternUtils.updateEmergencyCallButtonState(mEmergencyCallButton);
     }
 
     public void onRefreshBatteryInfo(boolean showBatteryInfo, boolean pluggedIn, int batteryLevel) {
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index 053854f..44df5b5 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -44,7 +44,7 @@
 #include <private/media/AudioEffectShared.h>
 
 #include <system/audio.h>
-#include <hardware/audio_hal.h>
+#include <hardware/audio.h>
 
 #include "AudioMixer.h"
 #include "AudioFlinger.h"
@@ -53,13 +53,6 @@
 #include <media/EffectVisualizerApi.h>
 
 // ----------------------------------------------------------------------------
-// the sim build doesn't have gettid
-
-#ifndef HAVE_GETTID
-# define gettid getpid
-#endif
-
-// ----------------------------------------------------------------------------
 
 
 namespace android {
@@ -360,8 +353,8 @@
         pid_t pid,
         int streamType,
         uint32_t sampleRate,
-        int format,
-        int channelCount,
+        uint32_t format,
+        uint32_t channelMask,
         int frameCount,
         uint32_t flags,
         const sp<IMemory>& sharedBuffer,
@@ -429,7 +422,7 @@
         LOGV("createTrack() lSessionId: %d", lSessionId);
 
         track = thread->createTrack_l(client, streamType, sampleRate, format,
-                channelCount, frameCount, sharedBuffer, lSessionId, &lStatus);
+                channelMask, frameCount, sharedBuffer, lSessionId, &lStatus);
 
         // move effect chain to this output thread if an effect on same session was waiting
         // for a track to be created
@@ -477,7 +470,7 @@
     return thread->channelCount();
 }
 
-int AudioFlinger::format(int output) const
+uint32_t AudioFlinger::format(int output) const
 {
     Mutex::Autolock _l(mLock);
     PlaybackThread *thread = checkPlaybackThread_l(output);
@@ -916,7 +909,7 @@
     return (int)mChannelCount;
 }
 
-int AudioFlinger::ThreadBase::format() const
+uint32_t AudioFlinger::ThreadBase::format() const
 {
     return mFormat;
 }
@@ -1002,6 +995,8 @@
     result.append(buffer);
     snprintf(buffer, SIZE, "Channel Count: %d\n", mChannelCount);
     result.append(buffer);
+    snprintf(buffer, SIZE, "Channel Mask: 0x%08x\n", mChannelMask);
+    result.append(buffer);
     snprintf(buffer, SIZE, "Format: %d\n", mFormat);
     result.append(buffer);
     snprintf(buffer, SIZE, "Frame size: %d\n", mFrameSize);
@@ -1075,7 +1070,7 @@
 
     snprintf(buffer, SIZE, "Output thread %p tracks\n", this);
     result.append(buffer);
-    result.append("   Name  Clien Typ Fmt Chn Session Buf  S M F SRate LeftV RighV  Serv       User       Main buf   Aux Buf\n");
+    result.append("   Name  Clien Typ Fmt Chn mask   Session Buf  S M F SRate LeftV RighV  Serv       User       Main buf   Aux Buf\n");
     for (size_t i = 0; i < mTracks.size(); ++i) {
         sp<Track> track = mTracks[i];
         if (track != 0) {
@@ -1086,7 +1081,7 @@
 
     snprintf(buffer, SIZE, "Output thread %p active tracks\n", this);
     result.append(buffer);
-    result.append("   Name  Clien Typ Fmt Chn Session Buf  S M F SRate LeftV RighV  Serv       User       Main buf   Aux Buf\n");
+    result.append("   Name  Clien Typ Fmt Chn mask   Session Buf  S M F SRate LeftV RighV  Serv       User       Main buf   Aux Buf\n");
     for (size_t i = 0; i < mActiveTracks.size(); ++i) {
         wp<Track> wTrack = mActiveTracks[i];
         if (wTrack != 0) {
@@ -1172,8 +1167,8 @@
         const sp<AudioFlinger::Client>& client,
         int streamType,
         uint32_t sampleRate,
-        int format,
-        int channelCount,
+        uint32_t format,
+        uint32_t channelMask,
         int frameCount,
         const sp<IMemory>& sharedBuffer,
         int sessionId,
@@ -1183,11 +1178,14 @@
     status_t lStatus;
 
     if (mType == DIRECT) {
-        if (sampleRate != mSampleRate || format != mFormat || channelCount != (int)mChannelCount) {
-            LOGE("createTrack_l() Bad parameter:  sampleRate %d format %d, channelCount %d for output %p",
-                 sampleRate, format, channelCount, mOutput);
-            lStatus = BAD_VALUE;
-            goto Exit;
+        if ((format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_PCM) {
+            if (sampleRate != mSampleRate || format != mFormat || channelMask != mChannelMask) {
+                LOGE("createTrack_l() Bad parameter: sampleRate %d format %d, channelMask 0x%08x \""
+                        "for output %p with format %d",
+                        sampleRate, format, channelMask, mOutput, mFormat);
+                lStatus = BAD_VALUE;
+                goto Exit;
+            }
         }
     } else {
         // Resampler implementation limits input sampling rate to 2 x output sampling rate.
@@ -1224,7 +1222,7 @@
         }
 
         track = new Track(this, client, streamType, sampleRate, format,
-                channelCount, frameCount, sharedBuffer, sessionId);
+                channelMask, frameCount, sharedBuffer, sessionId);
         if (track->getCblk() == NULL || track->name() < 0) {
             lStatus = NO_MEMORY;
             goto Exit;
@@ -1373,7 +1371,7 @@
     switch (event) {
     case AudioSystem::OUTPUT_OPENED:
     case AudioSystem::OUTPUT_CONFIG_CHANGED:
-        desc.channels = mChannels;
+        desc.channels = mChannelMask;
         desc.samplingRate = mSampleRate;
         desc.format = mFormat;
         desc.frameCount = mFrameCount;
@@ -1393,8 +1391,8 @@
 void AudioFlinger::PlaybackThread::readOutputParameters()
 {
     mSampleRate = mOutput->stream->common.get_sample_rate(&mOutput->stream->common);
-    mChannels = mOutput->stream->common.get_channels(&mOutput->stream->common);
-    mChannelCount = (uint16_t)popcount(mChannels);
+    mChannelMask = mOutput->stream->common.get_channels(&mOutput->stream->common);
+    mChannelCount = (uint16_t)popcount(mChannelMask);
     mFormat = mOutput->stream->common.get_format(&mOutput->stream->common);
     mFrameSize = (uint16_t)audio_stream_frame_size(&mOutput->stream->common);
     mFrameCount = mOutput->stream->common.get_buffer_size(&mOutput->stream->common) / mFrameSize;
@@ -1804,7 +1802,7 @@
                 AudioMixer::FORMAT, (void *)track->format());
             mAudioMixer->setParameter(
                 AudioMixer::TRACK,
-                AudioMixer::CHANNEL_COUNT, (void *)track->channelCount());
+                AudioMixer::CHANNEL_MASK, (void *)track->channelMask());
             mAudioMixer->setParameter(
                 AudioMixer::RESAMPLE,
                 AudioMixer::SAMPLE_RATE,
@@ -2683,7 +2681,7 @@
                                             this,
                                             mSampleRate,
                                             mFormat,
-                                            mChannelCount,
+                                            mChannelMask,
                                             frameCount);
     if (outputTrack->cblk() != NULL) {
         thread->setStreamVolume(AUDIO_STREAM_CNT, 1.0f);
@@ -2751,8 +2749,8 @@
             const wp<ThreadBase>& thread,
             const sp<Client>& client,
             uint32_t sampleRate,
-            int format,
-            int channelCount,
+            uint32_t format,
+            uint32_t channelMask,
             int frameCount,
             uint32_t flags,
             const sp<IMemory>& sharedBuffer,
@@ -2772,6 +2770,7 @@
 
     // LOGD("Creating track with %d buffers @ %d bytes", bufferCount, bufferSize);
    size_t size = sizeof(audio_track_cblk_t);
+   uint8_t channelCount = popcount(channelMask);
    size_t bufferSize = frameCount*channelCount*sizeof(int16_t);
    if (sharedBuffer == 0) {
        size += bufferSize;
@@ -2786,7 +2785,8 @@
                 // clear all buffers
                 mCblk->frameCount = frameCount;
                 mCblk->sampleRate = sampleRate;
-                mCblk->channelCount = (uint8_t)channelCount;
+                mChannelCount = channelCount;
+                mChannelMask = channelMask;
                 if (sharedBuffer == 0) {
                     mBuffer = (char*)mCblk + sizeof(audio_track_cblk_t);
                     memset(mBuffer, 0, frameCount*channelCount*sizeof(int16_t));
@@ -2810,7 +2810,8 @@
            // clear all buffers
            mCblk->frameCount = frameCount;
            mCblk->sampleRate = sampleRate;
-           mCblk->channelCount = (uint8_t)channelCount;
+           mChannelCount = channelCount;
+           mChannelMask = channelMask;
            mBuffer = (char*)mCblk + sizeof(audio_track_cblk_t);
            memset(mBuffer, 0, frameCount*channelCount*sizeof(int16_t));
            // Force underrun condition to avoid false underrun callback until first data is
@@ -2877,7 +2878,11 @@
 }
 
 int AudioFlinger::ThreadBase::TrackBase::channelCount() const {
-    return (int)mCblk->channelCount;
+    return (const int)mChannelCount;
+}
+
+uint32_t AudioFlinger::ThreadBase::TrackBase::channelMask() const {
+    return mChannelMask;
 }
 
 void* AudioFlinger::ThreadBase::TrackBase::getBuffer(uint32_t offset, uint32_t frames) const {
@@ -2889,9 +2894,9 @@
     if (bufferStart < mBuffer || bufferStart > bufferEnd || bufferEnd > mBufferEnd ||
         ((unsigned long)bufferStart & (unsigned long)(cblk->frameSize - 1))) {
         LOGE("TrackBase::getBuffer buffer out of range:\n    start: %p, end %p , mBuffer %p mBufferEnd %p\n    \
-                server %d, serverBase %d, user %d, userBase %d, channelCount %d",
+                server %d, serverBase %d, user %d, userBase %d",
                 bufferStart, bufferEnd, mBuffer, mBufferEnd,
-                cblk->server, cblk->serverBase, cblk->user, cblk->userBase, cblk->channelCount);
+                cblk->server, cblk->serverBase, cblk->user, cblk->userBase);
         return 0;
     }
 
@@ -2906,12 +2911,12 @@
             const sp<Client>& client,
             int streamType,
             uint32_t sampleRate,
-            int format,
-            int channelCount,
+            uint32_t format,
+            uint32_t channelMask,
             int frameCount,
             const sp<IMemory>& sharedBuffer,
             int sessionId)
-    :   TrackBase(thread, client, sampleRate, format, channelCount, frameCount, 0, sharedBuffer, sessionId),
+    :   TrackBase(thread, client, sampleRate, format, channelMask, frameCount, 0, sharedBuffer, sessionId),
     mMute(false), mSharedBuffer(sharedBuffer), mName(-1), mMainBuffer(NULL), mAuxBuffer(NULL),
     mAuxEffectId(0), mHasVolumeController(false)
 {
@@ -2931,7 +2936,7 @@
         mStreamType = streamType;
         // NOTE: audio_track_cblk_t::frameSize for 8 bit PCM data is based on a sample size of
         // 16 bit because data is converted to 16 bit before being stored in buffer by AudioTrack
-        mCblk->frameSize = audio_is_linear_pcm(format) ? channelCount * sizeof(int16_t) : sizeof(int8_t);
+        mCblk->frameSize = audio_is_linear_pcm(format) ? mChannelCount * sizeof(int16_t) : sizeof(int8_t);
     }
 }
 
@@ -2979,12 +2984,12 @@
 
 void AudioFlinger::PlaybackThread::Track::dump(char* buffer, size_t size)
 {
-    snprintf(buffer, size, "   %05d %05d %03u %03u %03u %05u   %04u %1d %1d %1d %05u %05u %05u  0x%08x 0x%08x 0x%08x 0x%08x\n",
+    snprintf(buffer, size, "   %05d %05d %03u %03u 0x%08x %05u   %04u %1d %1d %1d %05u %05u %05u  0x%08x 0x%08x 0x%08x 0x%08x\n",
             mName - AudioMixer::TRACK0,
             (mClient == NULL) ? getpid() : mClient->pid(),
             mStreamType,
             mFormat,
-            mCblk->channelCount,
+            mChannelMask,
             mSessionId,
             mFrameCount,
             mState,
@@ -3219,21 +3224,21 @@
             const wp<ThreadBase>& thread,
             const sp<Client>& client,
             uint32_t sampleRate,
-            int format,
-            int channelCount,
+            uint32_t format,
+            uint32_t channelMask,
             int frameCount,
             uint32_t flags,
             int sessionId)
     :   TrackBase(thread, client, sampleRate, format,
-                  channelCount, frameCount, flags, 0, sessionId),
+                  channelMask, frameCount, flags, 0, sessionId),
         mOverflow(false)
 {
     if (mCblk != NULL) {
        LOGV("RecordTrack constructor, size %d", (int)mBufferEnd - (int)mBuffer);
        if (format == AUDIO_FORMAT_PCM_16_BIT) {
-           mCblk->frameSize = channelCount * sizeof(int16_t);
+           mCblk->frameSize = mChannelCount * sizeof(int16_t);
        } else if (format == AUDIO_FORMAT_PCM_8_BIT) {
-           mCblk->frameSize = channelCount * sizeof(int8_t);
+           mCblk->frameSize = mChannelCount * sizeof(int8_t);
        } else {
            mCblk->frameSize = sizeof(int8_t);
        }
@@ -3313,10 +3318,10 @@
 
 void AudioFlinger::RecordThread::RecordTrack::dump(char* buffer, size_t size)
 {
-    snprintf(buffer, size, "   %05d %03u %03u %05d   %04u %01d %05u  %08x %08x\n",
+    snprintf(buffer, size, "   %05d %03u 0x%08x %05d   %04u %01d %05u  %08x %08x\n",
             (mClient == NULL) ? getpid() : mClient->pid(),
             mFormat,
-            mCblk->channelCount,
+            mChannelMask,
             mSessionId,
             mFrameCount,
             mState,
@@ -3332,10 +3337,10 @@
             const wp<ThreadBase>& thread,
             DuplicatingThread *sourceThread,
             uint32_t sampleRate,
-            int format,
-            int channelCount,
+            uint32_t format,
+            uint32_t channelMask,
             int frameCount)
-    :   Track(thread, NULL, AUDIO_STREAM_CNT, sampleRate, format, channelCount, frameCount, NULL, 0),
+    :   Track(thread, NULL, AUDIO_STREAM_CNT, sampleRate, format, channelMask, frameCount, NULL, 0),
     mActive(false), mSourceThread(sourceThread)
 {
 
@@ -3346,8 +3351,10 @@
         mCblk->volume[0] = mCblk->volume[1] = 0x1000;
         mOutBuffer.frameCount = 0;
         playbackThread->mTracks.add(this);
-        LOGV("OutputTrack constructor mCblk %p, mBuffer %p, mCblk->buffers %p, mCblk->frameCount %d, mCblk->sampleRate %d, mCblk->channelCount %d mBufferEnd %p",
-                mCblk, mBuffer, mCblk->buffers, mCblk->frameCount, mCblk->sampleRate, mCblk->channelCount, mBufferEnd);
+        LOGV("OutputTrack constructor mCblk %p, mBuffer %p, mCblk->buffers %p, " \
+                "mCblk->frameCount %d, mCblk->sampleRate %d, mChannelMask 0x%08x mBufferEnd %p",
+                mCblk, mBuffer, mCblk->buffers,
+                mCblk->frameCount, mCblk->sampleRate, mChannelMask, mBufferEnd);
     } else {
         LOGW("Error creating output track on thread %p", playbackThread);
     }
@@ -3382,7 +3389,7 @@
 {
     Buffer *pInBuffer;
     Buffer inBuffer;
-    uint32_t channelCount = mCblk->channelCount;
+    uint32_t channelCount = mChannelCount;
     bool outputBufferFull = false;
     inBuffer.frameCount = frames;
     inBuffer.i16 = data;
@@ -3667,8 +3674,8 @@
         pid_t pid,
         int input,
         uint32_t sampleRate,
-        int format,
-        int channelCount,
+        uint32_t format,
+        uint32_t channelMask,
         int frameCount,
         uint32_t flags,
         int *sessionId,
@@ -3717,7 +3724,7 @@
         }
         // create new record track. The record track uses one track in mHardwareMixerThread by convention.
         recordTrack = new RecordThread::RecordTrack(thread, client, sampleRate,
-                                                   format, channelCount, frameCount, flags, lSessionId);
+                                                   format, channelMask, frameCount, flags, lSessionId);
     }
     if (recordTrack->getCblk() == NULL) {
         // remove local strong reference to Client before deleting the RecordTrack so that the Client
@@ -4065,7 +4072,7 @@
 
     if (mActiveTrack != 0) {
         result.append("Active Track:\n");
-        result.append("   Clien Fmt Chn Session Buf  S SRate  Serv     User\n");
+        result.append("   Clien Fmt Chn mask   Session Buf  S SRate  Serv     User\n");
         mActiveTrack->dump(buffer, SIZE);
         result.append(buffer);
 
@@ -4219,7 +4226,7 @@
     switch (event) {
     case AudioSystem::INPUT_OPENED:
     case AudioSystem::INPUT_CONFIG_CHANGED:
-        desc.channels = mChannels;
+        desc.channels = mChannelMask;
         desc.samplingRate = mSampleRate;
         desc.format = mFormat;
         desc.frameCount = mFrameCount;
@@ -4242,8 +4249,8 @@
     mResampler = 0;
 
     mSampleRate = mInput->stream->common.get_sample_rate(&mInput->stream->common);
-    mChannels = mInput->stream->common.get_channels(&mInput->stream->common);
-    mChannelCount = (uint16_t)popcount(mChannels);
+    mChannelMask = mInput->stream->common.get_channels(&mInput->stream->common);
+    mChannelCount = (uint16_t)popcount(mChannelMask);
     mFormat = mInput->stream->common.get_format(&mInput->stream->common);
     mFrameSize = (uint16_t)audio_stream_frame_size(&mInput->stream->common);
     mInputBytes = mInput->stream->common.get_buffer_size(&mInput->stream->common);
diff --git a/services/audioflinger/AudioFlinger.h b/services/audioflinger/AudioFlinger.h
index 0698dcb..1fad987 100644
--- a/services/audioflinger/AudioFlinger.h
+++ b/services/audioflinger/AudioFlinger.h
@@ -39,7 +39,7 @@
 #include <binder/MemoryDealer.h>
 
 #include <system/audio.h>
-#include <hardware/audio_hal.h>
+#include <hardware/audio.h>
 
 #include "AudioBufferProvider.h"
 
@@ -76,8 +76,8 @@
                                 pid_t pid,
                                 int streamType,
                                 uint32_t sampleRate,
-                                int format,
-                                int channelCount,
+                                uint32_t format,
+                                uint32_t channelMask,
                                 int frameCount,
                                 uint32_t flags,
                                 const sp<IMemory>& sharedBuffer,
@@ -87,7 +87,7 @@
 
     virtual     uint32_t    sampleRate(int output) const;
     virtual     int         channelCount(int output) const;
-    virtual     int         format(int output) const;
+    virtual     uint32_t    format(int output) const;
     virtual     size_t      frameCount(int output) const;
     virtual     uint32_t    latency(int output) const;
 
@@ -189,8 +189,8 @@
                                 pid_t pid,
                                 int input,
                                 uint32_t sampleRate,
-                                int format,
-                                int channelCount,
+                                uint32_t format,
+                                uint32_t channelMask,
                                 int frameCount,
                                 uint32_t flags,
                                 int *sessionId,
@@ -301,8 +301,8 @@
                                 TrackBase(const wp<ThreadBase>& thread,
                                         const sp<Client>& client,
                                         uint32_t sampleRate,
-                                        int format,
-                                        int channelCount,
+                                        uint32_t format,
+                                        uint32_t channelMask,
                                         int frameCount,
                                         uint32_t flags,
                                         const sp<IMemory>& sharedBuffer,
@@ -329,12 +329,14 @@
             virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer) = 0;
             virtual void releaseBuffer(AudioBufferProvider::Buffer* buffer);
 
-            int format() const {
+            uint32_t format() const {
                 return mFormat;
             }
 
             int channelCount() const ;
 
+            uint32_t channelMask() const;
+
             int sampleRate() const;
 
             void* getBuffer(uint32_t offset, uint32_t frames) const;
@@ -360,9 +362,11 @@
             // we don't really need a lock for these
             int                 mState;
             int                 mClientTid;
-            uint8_t             mFormat;
+            uint32_t            mFormat;
             uint32_t            mFlags;
             int                 mSessionId;
+            uint8_t             mChannelCount;
+            uint32_t            mChannelMask;
         };
 
         class ConfigEvent {
@@ -375,7 +379,7 @@
 
                     uint32_t    sampleRate() const;
                     int         channelCount() const;
-                    int         format() const;
+                    uint32_t    format() const;
                     size_t      frameCount() const;
                     void        wakeUp()    { mWaitWorkCV.broadcast(); }
                     void        exit();
@@ -406,10 +410,10 @@
                     sp<AudioFlinger>        mAudioFlinger;
                     uint32_t                mSampleRate;
                     size_t                  mFrameCount;
-                    uint32_t                mChannels;
+                    uint32_t                mChannelMask;
                     uint16_t                mChannelCount;
                     uint16_t                mFrameSize;
-                    int                     mFormat;
+                    uint32_t                mFormat;
                     Condition               mParamCond;
                     Vector<String8>         mNewParameters;
                     status_t                mParamStatus;
@@ -442,8 +446,8 @@
                                         const sp<Client>& client,
                                         int streamType,
                                         uint32_t sampleRate,
-                                        int format,
-                                        int channelCount,
+                                        uint32_t format,
+                                        uint32_t channelMask,
                                         int frameCount,
                                         const sp<IMemory>& sharedBuffer,
                                         int sessionId);
@@ -530,8 +534,8 @@
                                 OutputTrack(  const wp<ThreadBase>& thread,
                                         DuplicatingThread *sourceThread,
                                         uint32_t sampleRate,
-                                        int format,
-                                        int channelCount,
+                                        uint32_t format,
+                                        uint32_t channelMask,
                                         int frameCount);
                                 ~OutputTrack();
 
@@ -583,8 +587,8 @@
                                     const sp<AudioFlinger::Client>& client,
                                     int streamType,
                                     uint32_t sampleRate,
-                                    int format,
-                                    int channelCount,
+                                    uint32_t format,
+                                    uint32_t channelMask,
                                     int frameCount,
                                     const sp<IMemory>& sharedBuffer,
                                     int sessionId,
@@ -829,8 +833,8 @@
                                 RecordTrack(const wp<ThreadBase>& thread,
                                         const sp<Client>& client,
                                         uint32_t sampleRate,
-                                        int format,
-                                        int channelCount,
+                                        uint32_t format,
+                                        uint32_t channelMask,
                                         int frameCount,
                                         uint32_t flags,
                                         int sessionId);
diff --git a/services/audioflinger/AudioMixer.cpp b/services/audioflinger/AudioMixer.cpp
index 50dcda7..6e9319d 100644
--- a/services/audioflinger/AudioMixer.cpp
+++ b/services/audioflinger/AudioMixer.cpp
@@ -26,6 +26,10 @@
 #include <utils/Errors.h>
 #include <utils/Log.h>
 
+#include <cutils/bitops.h>
+
+#include <system/audio.h>
+
 #include "AudioMixer.h"
 
 namespace android {
@@ -61,6 +65,7 @@
         t->channelCount = 2;
         t->enabled = 0;
         t->format = 16;
+        t->channelMask = AUDIO_CHANNEL_OUT_STEREO;
         t->buffer.raw = 0;
         t->bufferProvider = 0;
         t->hook = 0;
@@ -180,13 +185,18 @@
 
     switch (target) {
     case TRACK:
-        if (name == CHANNEL_COUNT) {
-            if ((uint32_t(valueInt) <= MAX_NUM_CHANNELS) && (valueInt)) {
-                if (mState.tracks[ mActiveTrack ].channelCount != valueInt) {
-                    mState.tracks[ mActiveTrack ].channelCount = valueInt;
-                    LOGV("setParameter(TRACK, CHANNEL_COUNT, %d)", valueInt);
+        if (name == CHANNEL_MASK) {
+            uint32_t mask = (uint32_t)value;
+            if (mState.tracks[ mActiveTrack ].channelMask != mask) {
+                uint8_t channelCount = popcount(mask);
+                if ((channelCount <= MAX_NUM_CHANNELS) && (channelCount)) {
+                    mState.tracks[ mActiveTrack ].channelMask = mask;
+                    mState.tracks[ mActiveTrack ].channelCount = channelCount;
+                    LOGV("setParameter(TRACK, CHANNEL_MASK, %x)", mask);
                     invalidateState(1<<mActiveTrack);
+                    return NO_ERROR;
                 }
+            } else {
                 return NO_ERROR;
             }
         }
diff --git a/services/audioflinger/AudioMixer.h b/services/audioflinger/AudioMixer.h
index 88408a7..75c9170 100644
--- a/services/audioflinger/AudioMixer.h
+++ b/services/audioflinger/AudioMixer.h
@@ -61,7 +61,7 @@
 
         // set Parameter names
         // for target TRACK
-        CHANNEL_COUNT   = 0x4000,
+        CHANNEL_MASK    = 0x4000,
         FORMAT          = 0x4001,
         MAIN_BUFFER     = 0x4002,
         AUX_BUFFER      = 0x4003,
@@ -150,6 +150,7 @@
         uint8_t     enabled      : 1;
         uint8_t     reserved0    : 3;
         uint8_t     format;
+        uint32_t    channelMask;
 
         AudioBufferProvider*                bufferProvider;
         mutable AudioBufferProvider::Buffer buffer;
diff --git a/services/audioflinger/AudioPolicyService.cpp b/services/audioflinger/AudioPolicyService.cpp
index ef8d957..47ca3a0 100644
--- a/services/audioflinger/AudioPolicyService.cpp
+++ b/services/audioflinger/AudioPolicyService.cpp
@@ -36,15 +36,8 @@
 
 #include <hardware/hardware.h>
 #include <system/audio.h>
+#include <system/audio_policy.h>
 #include <hardware/audio_policy.h>
-#include <hardware/audio_policy_hal.h>
-
-// ----------------------------------------------------------------------------
-// the sim build doesn't have gettid
-
-#ifndef HAVE_GETTID
-# define gettid getpid
-#endif
 
 namespace android {
 
diff --git a/services/audioflinger/AudioPolicyService.h b/services/audioflinger/AudioPolicyService.h
index d9b5ada..b830120 100644
--- a/services/audioflinger/AudioPolicyService.h
+++ b/services/audioflinger/AudioPolicyService.h
@@ -23,8 +23,8 @@
 #include <binder/BinderService.h>
 
 #include <system/audio.h>
+#include <system/audio_policy.h>
 #include <hardware/audio_policy.h>
-#include <hardware/audio_policy_hal.h>
 
 namespace android {
 
diff --git a/services/camera/libcameraservice/CameraHardwareInterface.h b/services/camera/libcameraservice/CameraHardwareInterface.h
index f9fa30e..a3749cf 100644
--- a/services/camera/libcameraservice/CameraHardwareInterface.h
+++ b/services/camera/libcameraservice/CameraHardwareInterface.h
@@ -438,18 +438,23 @@
     }
 
     static void __data_cb(int32_t msg_type,
-                          const camera_memory_t *data,
+                          const camera_memory_t *data, unsigned int index,
                           void *user)
     {
         LOGV("%s", __FUNCTION__);
         CameraHardwareInterface *__this =
                 static_cast<CameraHardwareInterface *>(user);
         sp<CameraHeapMemory> mem(static_cast<CameraHeapMemory *>(data->handle));
-        __this->mDataCb(msg_type, mem, __this->mCbUser);
+        if (index >= mem->mNumBufs) {
+            LOGE("%s: invalid buffer index %d, max allowed is %d", __FUNCTION__,
+                 index, mem->mNumBufs);
+            return;
+        }
+        __this->mDataCb(msg_type, mem->mBuffers[index], __this->mCbUser);
     }
 
     static void __data_cb_timestamp(nsecs_t timestamp, int32_t msg_type,
-                             const camera_memory_t *data,
+                             const camera_memory_t *data, unsigned index,
                              void *user)
     {
         LOGV("%s", __FUNCTION__);
@@ -459,38 +464,85 @@
         // drop all references, it will be destroyed (as well as the enclosed
         // MemoryHeapBase.
         sp<CameraHeapMemory> mem(static_cast<CameraHeapMemory *>(data->handle));
-        __this->mDataCbTimestamp(timestamp, msg_type, mem, __this->mCbUser);
+        if (index >= mem->mNumBufs) {
+            LOGE("%s: invalid buffer index %d, max allowed is %d", __FUNCTION__,
+                 index, mem->mNumBufs);
+            return;
+        }
+        __this->mDataCbTimestamp(timestamp, msg_type, mem->mBuffers[index], __this->mCbUser);
     }
 
     // This is a utility class that combines a MemoryHeapBase and a MemoryBase
     // in one.  Since we tend to use them in a one-to-one relationship, this is
     // handy.
 
-    class CameraHeapMemory : public MemoryBase {
+    class CameraHeapMemory : public RefBase {
     public:
-        CameraHeapMemory(size_t size) :
-            MemoryBase(new MemoryHeapBase(size), 0, size)
+        CameraHeapMemory(int fd, size_t buf_size, uint_t num_buffers = 1) :
+                         mBufSize(buf_size),
+                         mNumBufs(num_buffers)
         {
-            handle.data = getHeap()->base();
-            handle.size = size;
-            handle.handle = this;
+            mHeap = new MemoryHeapBase(fd, buf_size * num_buffers);
+            commonInitialization();
         }
 
+        CameraHeapMemory(size_t buf_size, uint_t num_buffers = 1) :
+                         mBufSize(buf_size),
+                         mNumBufs(num_buffers)
+        {
+            mHeap = new MemoryHeapBase(buf_size * num_buffers);
+            commonInitialization();
+        }
+
+        void commonInitialization()
+        {
+            handle.data = mHeap->base();
+            handle.size = mBufSize * mNumBufs;
+            handle.handle = this;
+
+            mBuffers = new sp<MemoryBase>[mNumBufs];
+            for (uint_t i = 0; i < mNumBufs; i++)
+                mBuffers[i] = new MemoryBase(mHeap,
+                                             i * mBufSize,
+                                             mBufSize);
+
+            handle.release = __put_memory;
+        }
+
+        virtual ~CameraHeapMemory()
+        {
+            delete [] mBuffers;
+        }
+
+        size_t mBufSize;
+        uint_t mNumBufs;
+        sp<MemoryHeapBase> mHeap;
+        sp<MemoryBase> *mBuffers;
+
         camera_memory_t handle;
     };
 
-    static camera_memory_t* __get_memory(size_t size,
-                                    void *user __attribute__((unused)))
+    static camera_memory_t* __get_memory(int fd, size_t buf_size, uint_t num_bufs,
+                                         void *user __attribute__((unused)))
     {
-        // We allocate the object here, but we do not assign it to a strong
-        // pointer yet.  The HAL will pass it back to us via the data callback
-        // or the data-timestamp callback, and from there on we will wrap it
-        // within a strong pointer.
-
-        CameraHeapMemory *mem = new CameraHeapMemory(size);
+        CameraHeapMemory *mem;
+        if (fd < 0)
+            mem = new CameraHeapMemory(buf_size, num_bufs);
+        else
+            mem = new CameraHeapMemory(fd, buf_size, num_bufs);
+        mem->incStrong(mem);
         return &mem->handle;
     }
 
+    static void __put_memory(camera_memory_t *data)
+    {
+        if (!data)
+            return;
+
+        CameraHeapMemory *mem = static_cast<CameraHeapMemory *>(data->handle);
+        mem->decStrong(mem);
+    }
+
     static ANativeWindow *__to_anw(void *user)
     {
         CameraHardwareInterface *__this =
@@ -500,7 +552,7 @@
 #define anw(n) __to_anw(((struct camera_preview_window *)n)->user)
 
     static int __dequeue_buffer(struct preview_stream_ops* w,
-                      buffer_handle_t** buffer)
+                                buffer_handle_t** buffer, int *stride)
     {
         int rc;
         ANativeWindow *a = anw(w);
@@ -508,8 +560,10 @@
         rc = a->dequeueBuffer(a, &anb);
         if (!rc) {
             rc = a->lockBuffer(a, anb);
-            if (!rc)
+            if (!rc) {
                 *buffer = &anb->handle;
+                *stride = anb->stride;
+            }
             else
                 a->cancelBuffer(a, anb);
         }
@@ -541,7 +595,7 @@
     static int __set_buffer_count(struct preview_stream_ops* w, int count)
     {
         ANativeWindow *a = anw(w);
-	return native_window_set_buffer_count(a, count);
+        return native_window_set_buffer_count(a, count);
     }
 
     static int __set_buffers_geometry(struct preview_stream_ops* w,
diff --git a/services/camera/libcameraservice/CameraService.cpp b/services/camera/libcameraservice/CameraService.cpp
index 1e8c30b..a011ae2 100644
--- a/services/camera/libcameraservice/CameraService.cpp
+++ b/services/camera/libcameraservice/CameraService.cpp
@@ -147,6 +147,14 @@
         return NULL;
     }
 
+    char value[PROPERTY_VALUE_MAX];
+    property_get("sys.secpolicy.camera.disabled", value, "0");
+    if (strcmp(value, "1") == 0) {
+        // Camera is disabled by DevicePolicyManager.
+        LOGI("Camera is disabled. connect X (pid %d) rejected", callingPid);
+        return NULL;
+    }
+
     Mutex::Autolock lock(mServiceLock);
     if (mClient[cameraId] != 0) {
         client = mClient[cameraId].promote();
diff --git a/services/input/EventHub.cpp b/services/input/EventHub.cpp
index af30887..95b8a57 100644
--- a/services/input/EventHub.cpp
+++ b/services/input/EventHub.cpp
@@ -14,20 +14,9 @@
  * limitations under the License.
  */
 
-//
-// Handle events, like key input and vsync.
-//
-// The goal is to provide an optimized solution for Linux, not an
-// implementation that works well across all platforms.  We expect
-// events to arrive on file descriptors, so that we can use a select()
-// select() call to sleep.
-//
-// We can't select() on anything but network sockets in Windows, so we
-// provide an alternative implementation of waitEvent for that platform.
-//
 #define LOG_TAG "EventHub"
 
-//#define LOG_NDEBUG 0
+// #define LOG_NDEBUG 0
 
 #include "EventHub.h"
 
@@ -54,14 +43,11 @@
 #include <string.h>
 #include <stdint.h>
 #include <dirent.h>
-#ifdef HAVE_INOTIFY
-# include <sys/inotify.h>
-#endif
-#ifdef HAVE_ANDROID_OS
-# include <sys/limits.h>        /* not part of Linux */
-#endif
-#include <sys/poll.h>
+
+#include <sys/inotify.h>
+#include <sys/epoll.h>
 #include <sys/ioctl.h>
+#include <sys/limits.h>
 
 /* this macro is used to tell if "bit" is set in "array"
  * it selects a byte from the array, and does a boolean AND
@@ -73,9 +59,6 @@
 /* this macro computes the number of bytes needed to represent a bit array of the specified size */
 #define sizeof_bit_array(bits)  ((bits + 7) / 8)
 
-// Fd at index 0 is always reserved for inotify
-#define FIRST_ACTUAL_DEVICE_INDEX 1
-
 #define INDENT "  "
 #define INDENT2 "    "
 #define INDENT3 "      "
@@ -101,15 +84,17 @@
         const InputDeviceIdentifier& identifier) :
         next(NULL),
         fd(fd), id(id), path(path), identifier(identifier),
-        classes(0), keyBitmask(NULL), relBitmask(NULL), propBitmask(NULL),
-        configuration(NULL), virtualKeyMap(NULL) {
+        classes(0), configuration(NULL), virtualKeyMap(NULL) {
+    memset(keyBitmask, 0, sizeof(keyBitmask));
+    memset(absBitmask, 0, sizeof(absBitmask));
+    memset(relBitmask, 0, sizeof(relBitmask));
+    memset(swBitmask, 0, sizeof(swBitmask));
+    memset(ledBitmask, 0, sizeof(ledBitmask));
+    memset(propBitmask, 0, sizeof(propBitmask));
 }
 
 EventHub::Device::~Device() {
     close();
-    delete[] keyBitmask;
-    delete[] relBitmask;
-    delete[] propBitmask;
     delete configuration;
     delete virtualKeyMap;
 }
@@ -124,24 +109,72 @@
 
 // --- EventHub ---
 
+const uint32_t EventHub::EPOLL_ID_INOTIFY;
+const uint32_t EventHub::EPOLL_ID_WAKE;
+const int EventHub::EPOLL_SIZE_HINT;
+const int EventHub::EPOLL_MAX_EVENTS;
+
 EventHub::EventHub(void) :
-        mError(NO_INIT), mBuiltInKeyboardId(-1), mNextDeviceId(1),
+        mBuiltInKeyboardId(-1), mNextDeviceId(1),
         mOpeningDevices(0), mClosingDevices(0),
-        mOpened(false), mNeedToSendFinishedDeviceScan(false),
-        mInputFdIndex(1) {
+        mNeedToSendFinishedDeviceScan(false),
+        mNeedToReopenDevices(false), mNeedToScanDevices(true),
+        mPendingEventCount(0), mPendingEventIndex(0), mPendingINotify(false) {
     acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_ID);
 
-    memset(mSwitches, 0, sizeof(mSwitches));
     mNumCpus = sysconf(_SC_NPROCESSORS_ONLN);
+
+    mEpollFd = epoll_create(EPOLL_SIZE_HINT);
+    LOG_ALWAYS_FATAL_IF(mEpollFd < 0, "Could not create epoll instance.  errno=%d", errno);
+
+    mINotifyFd = inotify_init();
+    int result = inotify_add_watch(mINotifyFd, DEVICE_PATH, IN_DELETE | IN_CREATE);
+    LOG_ALWAYS_FATAL_IF(result < 0, "Could not register INotify for %s.  errno=%d",
+            DEVICE_PATH, errno);
+
+    struct epoll_event eventItem;
+    memset(&eventItem, 0, sizeof(eventItem));
+    eventItem.events = EPOLLIN;
+    eventItem.data.u32 = EPOLL_ID_INOTIFY;
+    result = epoll_ctl(mEpollFd, EPOLL_CTL_ADD, mINotifyFd, &eventItem);
+    LOG_ALWAYS_FATAL_IF(result != 0, "Could not add INotify to epoll instance.  errno=%d", errno);
+
+    int wakeFds[2];
+    result = pipe(wakeFds);
+    LOG_ALWAYS_FATAL_IF(result != 0, "Could not create wake pipe.  errno=%d", errno);
+
+    mWakeReadPipeFd = wakeFds[0];
+    mWakeWritePipeFd = wakeFds[1];
+
+    result = fcntl(mWakeReadPipeFd, F_SETFL, O_NONBLOCK);
+    LOG_ALWAYS_FATAL_IF(result != 0, "Could not make wake read pipe non-blocking.  errno=%d",
+            errno);
+
+    result = fcntl(mWakeWritePipeFd, F_SETFL, O_NONBLOCK);
+    LOG_ALWAYS_FATAL_IF(result != 0, "Could not make wake write pipe non-blocking.  errno=%d",
+            errno);
+
+    eventItem.data.u32 = EPOLL_ID_WAKE;
+    result = epoll_ctl(mEpollFd, EPOLL_CTL_ADD, mWakeReadPipeFd, &eventItem);
+    LOG_ALWAYS_FATAL_IF(result != 0, "Could not add wake read pipe to epoll instance.  errno=%d",
+            errno);
 }
 
 EventHub::~EventHub(void) {
-    release_wake_lock(WAKE_LOCK_ID);
-    // we should free stuff here...
-}
+    closeAllDevicesLocked();
 
-status_t EventHub::errorCheck() const {
-    return mError;
+    while (mClosingDevices) {
+        Device* device = mClosingDevices;
+        mClosingDevices = device->next;
+        delete device;
+    }
+
+    ::close(mEpollFd);
+    ::close(mINotifyFd);
+    ::close(mWakeReadPipeFd);
+    ::close(mWakeWritePipeFd);
+
+    release_wake_lock(WAKE_LOCK_ID);
 }
 
 String8 EventHub::getDeviceName(int32_t deviceId) const {
@@ -190,6 +223,7 @@
         outAxisInfo->maxValue = info.maximum;
         outAxisInfo->flat = info.flat;
         outAxisInfo->fuzz = info.fuzz;
+        outAxisInfo->resolution = info.resolution;
     }
     return OK;
 }
@@ -314,7 +348,7 @@
 
 bool EventHub::markSupportedKeyCodesLocked(Device* device, size_t numCodes,
         const int32_t* keyCodes, uint8_t* outFlags) const {
-    if (!device->keyMap.haveKeyLayout() || !device->keyBitmask) {
+    if (!device->keyMap.haveKeyLayout()) {
         return false;
     }
 
@@ -393,24 +427,18 @@
     return NAME_NOT_FOUND;
 }
 
-void EventHub::addExcludedDevice(const char* deviceName)
-{
+void EventHub::setExcludedDevices(const Vector<String8>& devices) {
     AutoMutex _l(mLock);
 
-    String8 name(deviceName);
-    mExcludedDevices.push_back(name);
+    mExcludedDevices = devices;
 }
 
 bool EventHub::hasLed(int32_t deviceId, int32_t led) const {
     AutoMutex _l(mLock);
     Device* device = getDeviceLocked(deviceId);
-    if (device) {
-        uint8_t bitmask[sizeof_bit_array(LED_MAX + 1)];
-        memset(bitmask, 0, sizeof(bitmask));
-        if (ioctl(device->fd, EVIOCGBIT(EV_LED, sizeof(bitmask)), bitmask) >= 0) {
-            if (test_bit(led, bitmask)) {
-                return true;
-            }
+    if (device && led >= 0 && led <= LED_MAX) {
+        if (test_bit(led, device->ledBitmask)) {
+            return true;
         }
     }
     return false;
@@ -419,7 +447,7 @@
 void EventHub::setLedState(int32_t deviceId, int32_t led, bool on) {
     AutoMutex _l(mLock);
     Device* device = getDeviceLocked(deviceId);
-    if (device) {
+    if (device && led >= 0 && led <= LED_MAX) {
         struct input_event ev;
         ev.time.tv_sec = 0;
         ev.time.tv_usec = 0;
@@ -449,11 +477,14 @@
     if (deviceId == 0) {
         deviceId = mBuiltInKeyboardId;
     }
+    ssize_t index = mDevices.indexOfKey(deviceId);
+    return index >= 0 ? mDevices.valueAt(index) : NULL;
+}
 
-    size_t numDevices = mDevices.size();
-    for (size_t i = FIRST_ACTUAL_DEVICE_INDEX; i < numDevices; i++) {
-        Device* device = mDevices[i];
-        if (device->id == deviceId) {
+EventHub::Device* EventHub::getDeviceByPathLocked(const char* devicePath) const {
+    for (size_t i = 0; i < mDevices.size(); i++) {
+        Device* device = mDevices.valueAt(i);
+        if (device->path == devicePath) {
             return device;
         }
     }
@@ -461,23 +492,29 @@
 }
 
 size_t EventHub::getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSize) {
-    // Note that we only allow one caller to getEvents(), so don't need
-    // to do locking here...  only when adding/removing devices.
     LOG_ASSERT(bufferSize >= 1);
 
-    if (!mOpened) {
-        mError = openPlatformInput() ? NO_ERROR : UNKNOWN_ERROR;
-        mOpened = true;
-        mNeedToSendFinishedDeviceScan = true;
-    }
+    AutoMutex _l(mLock);
 
     struct input_event readBuffer[bufferSize];
 
     RawEvent* event = buffer;
     size_t capacity = bufferSize;
+    bool awoken = false;
     for (;;) {
         nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
 
+        // Reopen input devices if needed.
+        if (mNeedToReopenDevices) {
+            mNeedToReopenDevices = false;
+
+            LOGI("Reopening all input devices due to a configuration change.");
+
+            closeAllDevicesLocked();
+            mNeedToScanDevices = true;
+            break; // return to the caller before we actually rescan
+        }
+
         // Report any devices that had last been added/removed.
         while (mClosingDevices) {
             Device* device = mClosingDevices;
@@ -495,6 +532,12 @@
             }
         }
 
+        if (mNeedToScanDevices) {
+            mNeedToScanDevices = false;
+            scanDevicesLocked();
+            mNeedToSendFinishedDeviceScan = true;
+        }
+
         while (mOpeningDevices != NULL) {
             Device* device = mOpeningDevices;
             LOGV("Reporting device opened: id=%d, name=%s\n",
@@ -521,27 +564,56 @@
         }
 
         // Grab the next input event.
-        // mInputFdIndex is initially 1 because index 0 is used for inotify.
-        bool deviceWasRemoved = false;
-        while (mInputFdIndex < mFds.size()) {
-            const struct pollfd& pfd = mFds[mInputFdIndex];
-            if (pfd.revents & POLLIN) {
-                int32_t readSize = read(pfd.fd, readBuffer, sizeof(struct input_event) * capacity);
-                if (readSize < 0) {
-                    if (errno == ENODEV) {
-                        deviceWasRemoved = true;
-                        break;
-                    }
+        bool deviceChanged = false;
+        while (mPendingEventIndex < mPendingEventCount) {
+            const struct epoll_event& eventItem = mPendingEventItems[mPendingEventIndex++];
+            if (eventItem.data.u32 == EPOLL_ID_INOTIFY) {
+                if (eventItem.events & EPOLLIN) {
+                    mPendingINotify = true;
+                } else {
+                    LOGW("Received unexpected epoll event 0x%08x for INotify.", eventItem.events);
+                }
+                continue;
+            }
+
+            if (eventItem.data.u32 == EPOLL_ID_WAKE) {
+                if (eventItem.events & EPOLLIN) {
+                    LOGV("awoken after wake()");
+                    awoken = true;
+                    char buffer[16];
+                    ssize_t nRead;
+                    do {
+                        nRead = read(mWakeReadPipeFd, buffer, sizeof(buffer));
+                    } while ((nRead == -1 && errno == EINTR) || nRead == sizeof(buffer));
+                } else {
+                    LOGW("Received unexpected epoll event 0x%08x for wake read pipe.",
+                            eventItem.events);
+                }
+                continue;
+            }
+
+            ssize_t deviceIndex = mDevices.indexOfKey(eventItem.data.u32);
+            if (deviceIndex < 0) {
+                LOGW("Received unexpected epoll event 0x%08x for unknown device id %d.",
+                        eventItem.events, eventItem.data.u32);
+                continue;
+            }
+
+            Device* device = mDevices.valueAt(deviceIndex);
+            if (eventItem.events & EPOLLIN) {
+                int32_t readSize = read(device->fd, readBuffer,
+                        sizeof(struct input_event) * capacity);
+                if (readSize == 0 || (readSize < 0 && errno == ENODEV)) {
+                    // Device was removed before INotify noticed.
+                    deviceChanged = true;
+                    closeDeviceLocked(device);
+                } else if (readSize < 0) {
                     if (errno != EAGAIN && errno != EINTR) {
                         LOGW("could not get event (errno=%d)", errno);
                     }
                 } else if ((readSize % sizeof(struct input_event)) != 0) {
                     LOGE("could not get event (wrong size: %d)", readSize);
-                } else if (readSize == 0) { // eof
-                    deviceWasRemoved = true;
-                    break;
                 } else {
-                    const Device* device = mDevices[mInputFdIndex];
                     int32_t deviceId = device->id == mBuiltInKeyboardId ? 0 : device->id;
 
                     size_t count = size_t(readSize) / sizeof(struct input_event);
@@ -586,38 +658,39 @@
                     }
                     capacity -= count;
                     if (capacity == 0) {
+                        // The result buffer is full.  Reset the pending event index
+                        // so we will try to read the device again on the next iteration.
+                        mPendingEventIndex -= 1;
                         break;
                     }
                 }
+            } else {
+                LOGW("Received unexpected epoll event 0x%08x for device %s.",
+                        eventItem.events, device->identifier.name.string());
             }
-            mInputFdIndex += 1;
         }
 
-        // Handle the case where a device has been removed but INotify has not yet noticed.
-        if (deviceWasRemoved) {
-            AutoMutex _l(mLock);
-            closeDeviceAtIndexLocked(mInputFdIndex);
-            continue; // report added or removed devices immediately
+        // readNotify() will modify the list of devices so this must be done after
+        // processing all other events to ensure that we read all remaining events
+        // before closing the devices.
+        if (mPendingINotify && mPendingEventIndex >= mPendingEventCount) {
+            mPendingINotify = false;
+            readNotifyLocked();
+            deviceChanged = true;
         }
 
-#if HAVE_INOTIFY
-        // readNotify() will modify mFDs and mFDCount, so this must be done after
-        // processing all other events.
-        if(mFds[0].revents & POLLIN) {
-            readNotify(mFds[0].fd);
-            mFds.editItemAt(0).revents = 0;
-            mInputFdIndex = mFds.size();
-            continue; // report added or removed devices immediately
+        // Report added or removed devices immediately.
+        if (deviceChanged) {
+            continue;
         }
-#endif
 
-        // Return now if we have collected any events, otherwise poll.
-        if (event != buffer) {
+        // Return now if we have collected any events or if we were explicitly awoken.
+        if (event != buffer || awoken) {
             break;
         }
 
         // Poll for events.  Mind the wake lock dance!
-        // We hold a wake lock at all times except during poll().  This works due to some
+        // We hold a wake lock at all times except during epoll_wait().  This works due to some
         // subtle choreography.  When a device driver has pending (unread) events, it acquires
         // a kernel wake lock.  However, once the last pending event has been read, the device
         // driver will release the kernel wake lock.  To prevent the system from going to sleep
@@ -627,16 +700,26 @@
         //
         // The timeout is advisory only.  If the device is asleep, it will not wake just to
         // service the timeout.
+        mPendingEventIndex = 0;
+
+        mLock.unlock(); // release lock before poll, must be before release_wake_lock
         release_wake_lock(WAKE_LOCK_ID);
 
-        int pollResult = poll(mFds.editArray(), mFds.size(), timeoutMillis);
+        int pollResult = epoll_wait(mEpollFd, mPendingEventItems, EPOLL_MAX_EVENTS, timeoutMillis);
 
         acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_ID);
+        mLock.lock(); // reacquire lock after poll, must be after acquire_wake_lock
 
         if (pollResult == 0) {
-            break; // timed out
+            // Timed out.
+            mPendingEventCount = 0;
+            break;
         }
+
         if (pollResult < 0) {
+            // An error occurred.
+            mPendingEventCount = 0;
+
             // Sleep after errors to avoid locking up the system.
             // Hopefully the error is transient.
             if (errno != EINTR) {
@@ -644,6 +727,9 @@
                 usleep(100000);
             }
         } else {
+            // Some events occurred.
+            mPendingEventCount = size_t(pollResult);
+
             // On an SMP system, it is possible for the framework to read input events
             // faster than the kernel input device driver can produce a complete packet.
             // Because poll() wakes up as soon as the first input event becomes available,
@@ -657,52 +743,30 @@
                 usleep(250);
             }
         }
-
-        // Prepare to process all of the FDs we just polled.
-        mInputFdIndex = 1;
     }
 
     // All done, return the number of events we read.
     return event - buffer;
 }
 
-/*
- * Open the platform-specific input device.
- */
-bool EventHub::openPlatformInput(void) {
-    /*
-     * Open platform-specific input device(s).
-     */
-    int res, fd;
+void EventHub::wake() {
+    LOGV("wake() called");
 
-#ifdef HAVE_INOTIFY
-    fd = inotify_init();
-    res = inotify_add_watch(fd, DEVICE_PATH, IN_DELETE | IN_CREATE);
-    if(res < 0) {
-        LOGE("could not add watch for %s, %s\n", DEVICE_PATH, strerror(errno));
+    ssize_t nWrite;
+    do {
+        nWrite = write(mWakeWritePipeFd, "W", 1);
+    } while (nWrite == -1 && errno == EINTR);
+
+    if (nWrite != 1 && errno != EAGAIN) {
+        LOGW("Could not write wake signal, errno=%d", errno);
     }
-#else
-    /*
-     * The code in EventHub::getEvent assumes that mFDs[0] is an inotify fd.
-     * We allocate space for it and set it to something invalid.
-     */
-    fd = -1;
-#endif
+}
 
-    // Reserve fd index 0 for inotify.
-    struct pollfd pollfd;
-    pollfd.fd = fd;
-    pollfd.events = POLLIN;
-    pollfd.revents = 0;
-    mFds.push(pollfd);
-    mDevices.push(NULL);
-
-    res = scanDir(DEVICE_PATH);
+void EventHub::scanDevicesLocked() {
+    status_t res = scanDirLocked(DEVICE_PATH);
     if(res < 0) {
         LOGE("scan dir failed for %s\n", DEVICE_PATH);
     }
-
-    return true;
 }
 
 // ----------------------------------------------------------------------------
@@ -731,13 +795,11 @@
         AKEYCODE_BUTTON_13, AKEYCODE_BUTTON_14, AKEYCODE_BUTTON_15, AKEYCODE_BUTTON_16,
 };
 
-int EventHub::openDevice(const char *devicePath) {
+status_t EventHub::openDeviceLocked(const char *devicePath) {
     char buffer[80];
 
     LOGV("Opening device: %s", devicePath);
 
-    AutoMutex _l(mLock);
-
     int fd = open(devicePath, O_RDWR);
     if(fd < 0) {
         LOGE("could not open %s, %s\n", devicePath, strerror(errno));
@@ -755,12 +817,10 @@
     }
 
     // Check to see if the device is on our excluded list
-    List<String8>::iterator iter = mExcludedDevices.begin();
-    List<String8>::iterator end = mExcludedDevices.end();
-    for ( ; iter != end; iter++) {
-        const char* test = *iter;
-        if (identifier.name == test) {
-            LOGI("ignoring event id %s driver %s\n", devicePath, test);
+    for (size_t i = 0; i < mExcludedDevices.size(); i++) {
+        const String8& item = mExcludedDevices.itemAt(i);
+        if (identifier.name == item) {
+            LOGI("ignoring event id %s driver %s\n", devicePath, item.string());
             close(fd);
             return -1;
         }
@@ -828,77 +888,50 @@
 #endif
 
     // Load the configuration file for the device.
-    loadConfiguration(device);
+    loadConfigurationLocked(device);
 
     // Figure out the kinds of events the device reports.
-    uint8_t key_bitmask[sizeof_bit_array(KEY_MAX + 1)];
-    memset(key_bitmask, 0, sizeof(key_bitmask));
-    ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(key_bitmask)), key_bitmask);
-
-    uint8_t abs_bitmask[sizeof_bit_array(ABS_MAX + 1)];
-    memset(abs_bitmask, 0, sizeof(abs_bitmask));
-    ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(abs_bitmask)), abs_bitmask);
-
-    uint8_t rel_bitmask[sizeof_bit_array(REL_MAX + 1)];
-    memset(rel_bitmask, 0, sizeof(rel_bitmask));
-    ioctl(fd, EVIOCGBIT(EV_REL, sizeof(rel_bitmask)), rel_bitmask);
-
-    uint8_t sw_bitmask[sizeof_bit_array(SW_MAX + 1)];
-    memset(sw_bitmask, 0, sizeof(sw_bitmask));
-    ioctl(fd, EVIOCGBIT(EV_SW, sizeof(sw_bitmask)), sw_bitmask);
-
-    uint8_t prop_bitmask[sizeof_bit_array(INPUT_PROP_MAX + 1)];
-    memset(prop_bitmask, 0, sizeof(prop_bitmask));
-    ioctl(fd, EVIOCGPROP(sizeof(prop_bitmask)), prop_bitmask);
-
-    device->keyBitmask = new uint8_t[sizeof(key_bitmask)];
-    device->relBitmask = new uint8_t[sizeof(rel_bitmask)];
-    device->propBitmask = new uint8_t[sizeof(prop_bitmask)];
-
-    if (!device->keyBitmask || !device->relBitmask || !device->propBitmask) {
-        delete device;
-        LOGE("out of memory allocating bitmasks");
-        return -1;
-    }
-
-    memcpy(device->keyBitmask, key_bitmask, sizeof(key_bitmask));
-    memcpy(device->relBitmask, rel_bitmask, sizeof(rel_bitmask));
-    memcpy(device->propBitmask, prop_bitmask, sizeof(prop_bitmask));
+    ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(device->keyBitmask)), device->keyBitmask);
+    ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(device->absBitmask)), device->absBitmask);
+    ioctl(fd, EVIOCGBIT(EV_REL, sizeof(device->relBitmask)), device->relBitmask);
+    ioctl(fd, EVIOCGBIT(EV_SW, sizeof(device->swBitmask)), device->swBitmask);
+    ioctl(fd, EVIOCGBIT(EV_LED, sizeof(device->ledBitmask)), device->ledBitmask);
+    ioctl(fd, EVIOCGPROP(sizeof(device->propBitmask)), device->propBitmask);
 
     // See if this is a keyboard.  Ignore everything in the button range except for
     // joystick and gamepad buttons which are handled like keyboards for the most part.
-    bool haveKeyboardKeys = containsNonZeroByte(key_bitmask, 0, sizeof_bit_array(BTN_MISC))
-            || containsNonZeroByte(key_bitmask, sizeof_bit_array(KEY_OK),
+    bool haveKeyboardKeys = containsNonZeroByte(device->keyBitmask, 0, sizeof_bit_array(BTN_MISC))
+            || containsNonZeroByte(device->keyBitmask, sizeof_bit_array(KEY_OK),
                     sizeof_bit_array(KEY_MAX + 1));
-    bool haveGamepadButtons = containsNonZeroByte(key_bitmask, sizeof_bit_array(BTN_MISC),
+    bool haveGamepadButtons = containsNonZeroByte(device->keyBitmask, sizeof_bit_array(BTN_MISC),
                     sizeof_bit_array(BTN_MOUSE))
-            || containsNonZeroByte(key_bitmask, sizeof_bit_array(BTN_JOYSTICK),
+            || containsNonZeroByte(device->keyBitmask, sizeof_bit_array(BTN_JOYSTICK),
                     sizeof_bit_array(BTN_DIGI));
     if (haveKeyboardKeys || haveGamepadButtons) {
         device->classes |= INPUT_DEVICE_CLASS_KEYBOARD;
     }
 
     // See if this is a cursor device such as a trackball or mouse.
-    if (test_bit(BTN_MOUSE, key_bitmask)
-            && test_bit(REL_X, rel_bitmask)
-            && test_bit(REL_Y, rel_bitmask)) {
+    if (test_bit(BTN_MOUSE, device->keyBitmask)
+            && test_bit(REL_X, device->relBitmask)
+            && test_bit(REL_Y, device->relBitmask)) {
         device->classes |= INPUT_DEVICE_CLASS_CURSOR;
     }
 
     // See if this is a touch pad.
     // Is this a new modern multi-touch driver?
-    if (test_bit(ABS_MT_POSITION_X, abs_bitmask)
-            && test_bit(ABS_MT_POSITION_Y, abs_bitmask)) {
+    if (test_bit(ABS_MT_POSITION_X, device->absBitmask)
+            && test_bit(ABS_MT_POSITION_Y, device->absBitmask)) {
         // Some joysticks such as the PS3 controller report axes that conflict
         // with the ABS_MT range.  Try to confirm that the device really is
         // a touch screen.
-        if (test_bit(BTN_TOUCH, key_bitmask) || !haveGamepadButtons) {
+        if (test_bit(BTN_TOUCH, device->keyBitmask) || !haveGamepadButtons) {
             device->classes |= INPUT_DEVICE_CLASS_TOUCH | INPUT_DEVICE_CLASS_TOUCH_MT;
         }
     // Is this an old style single-touch driver?
-    } else if (test_bit(BTN_TOUCH, key_bitmask)
-            && test_bit(ABS_X, abs_bitmask)
-            && test_bit(ABS_Y, abs_bitmask)) {
+    } else if (test_bit(BTN_TOUCH, device->keyBitmask)
+            && test_bit(ABS_X, device->absBitmask)
+            && test_bit(ABS_Y, device->absBitmask)) {
         device->classes |= INPUT_DEVICE_CLASS_TOUCH;
     }
 
@@ -908,29 +941,23 @@
     // from other devices such as accelerometers that also have absolute axes.
     if (haveGamepadButtons
             && !(device->classes & INPUT_DEVICE_CLASS_TOUCH)
-            && containsNonZeroByte(abs_bitmask, 0, sizeof_bit_array(ABS_MAX + 1))) {
+            && containsNonZeroByte(device->absBitmask, 0, sizeof_bit_array(ABS_MAX + 1))) {
         device->classes |= INPUT_DEVICE_CLASS_JOYSTICK;
     }
 
-    // figure out the switches this device reports
-    bool haveSwitches = false;
-    for (int i=0; i<EV_SW; i++) {
-        //LOGI("Device %d sw %d: has=%d", device->id, i, test_bit(i, sw_bitmask));
-        if (test_bit(i, sw_bitmask)) {
-            haveSwitches = true;
-            if (mSwitches[i] == 0) {
-                mSwitches[i] = device->id;
-            }
+    // Check whether this device has switches.
+    for (int i = 0; i <= SW_MAX; i++) {
+        if (test_bit(i, device->swBitmask)) {
+            device->classes |= INPUT_DEVICE_CLASS_SWITCH;
+            break;
         }
     }
-    if (haveSwitches) {
-        device->classes |= INPUT_DEVICE_CLASS_SWITCH;
-    }
 
+    // Configure virtual keys.
     if ((device->classes & INPUT_DEVICE_CLASS_TOUCH)) {
         // Load the virtual keys for the touch screen, if any.
         // We do this now so that we can make sure to load the keymap if necessary.
-        status_t status = loadVirtualKeyMap(device);
+        status_t status = loadVirtualKeyMapLocked(device);
         if (!status) {
             device->classes |= INPUT_DEVICE_CLASS_KEYBOARD;
         }
@@ -941,13 +968,13 @@
     status_t keyMapStatus = NAME_NOT_FOUND;
     if (device->classes & (INPUT_DEVICE_CLASS_KEYBOARD | INPUT_DEVICE_CLASS_JOYSTICK)) {
         // Load the keymap for the device.
-        keyMapStatus = loadKeyMap(device);
+        keyMapStatus = loadKeyMapLocked(device);
     }
 
     // Configure the keyboard, gamepad or virtual keyboard.
     if (device->classes & INPUT_DEVICE_CLASS_KEYBOARD) {
         // Set system properties for the keyboard.
-        setKeyboardProperties(device, false);
+        setKeyboardPropertiesLocked(device, false);
 
         // Register the keyboard as a built-in keyboard if it is eligible.
         if (!keyMapStatus
@@ -955,7 +982,7 @@
                 && isEligibleBuiltInKeyboard(device->identifier,
                         device->configuration, &device->keyMap)) {
             mBuiltInKeyboardId = device->id;
-            setKeyboardProperties(device, true);
+            setKeyboardPropertiesLocked(device, true);
         }
 
         // 'Q' key support = cheap test of whether this is an alpha-capable kbd
@@ -990,10 +1017,21 @@
     }
 
     // Determine whether the device is external or internal.
-    if (isExternalDevice(device)) {
+    if (isExternalDeviceLocked(device)) {
         device->classes |= INPUT_DEVICE_CLASS_EXTERNAL;
     }
 
+    // Register with epoll.
+    struct epoll_event eventItem;
+    memset(&eventItem, 0, sizeof(eventItem));
+    eventItem.events = EPOLLIN;
+    eventItem.data.u32 = deviceId;
+    if (epoll_ctl(mEpollFd, EPOLL_CTL_ADD, fd, &eventItem)) {
+        LOGE("Could not add device fd to epoll instance.  errno=%d", errno);
+        delete device;
+        return -1;
+    }
+
     LOGI("New device: id=%d, fd=%d, path='%s', name='%s', classes=0x%x, "
             "configuration='%s', keyLayout='%s', keyCharacterMap='%s', builtinKeyboard=%s",
          deviceId, fd, devicePath, device->identifier.name.string(),
@@ -1003,19 +1041,14 @@
          device->keyMap.keyCharacterMapFile.string(),
          toString(mBuiltInKeyboardId == deviceId));
 
-    struct pollfd pollfd;
-    pollfd.fd = fd;
-    pollfd.events = POLLIN;
-    pollfd.revents = 0;
-    mFds.push(pollfd);
-    mDevices.push(device);
+    mDevices.add(deviceId, device);
 
     device->next = mOpeningDevices;
     mOpeningDevices = device;
     return 0;
 }
 
-void EventHub::loadConfiguration(Device* device) {
+void EventHub::loadConfigurationLocked(Device* device) {
     device->configurationFile = getInputDeviceConfigurationFilePathByDeviceIdentifier(
             device->identifier, INPUT_DEVICE_CONFIGURATION_FILE_TYPE_CONFIGURATION);
     if (device->configurationFile.isEmpty()) {
@@ -1032,7 +1065,7 @@
     }
 }
 
-status_t EventHub::loadVirtualKeyMap(Device* device) {
+status_t EventHub::loadVirtualKeyMapLocked(Device* device) {
     // The virtual key map is supplied by the kernel as a system board property file.
     String8 path;
     path.append("/sys/board_properties/virtualkeys.");
@@ -1043,22 +1076,22 @@
     return VirtualKeyMap::load(path, &device->virtualKeyMap);
 }
 
-status_t EventHub::loadKeyMap(Device* device) {
+status_t EventHub::loadKeyMapLocked(Device* device) {
     return device->keyMap.load(device->identifier, device->configuration);
 }
 
-void EventHub::setKeyboardProperties(Device* device, bool builtInKeyboard) {
+void EventHub::setKeyboardPropertiesLocked(Device* device, bool builtInKeyboard) {
     int32_t id = builtInKeyboard ? 0 : device->id;
     android::setKeyboardProperties(id, device->identifier,
             device->keyMap.keyLayoutFile, device->keyMap.keyCharacterMapFile);
 }
 
-void EventHub::clearKeyboardProperties(Device* device, bool builtInKeyboard) {
+void EventHub::clearKeyboardPropertiesLocked(Device* device, bool builtInKeyboard) {
     int32_t id = builtInKeyboard ? 0 : device->id;
     android::clearKeyboardProperties(id);
 }
 
-bool EventHub::isExternalDevice(Device* device) {
+bool EventHub::isExternalDeviceLocked(Device* device) {
     if (device->configuration) {
         bool value;
         if (device->configuration->tryGetProperty(String8("device.internal"), value)
@@ -1087,41 +1120,40 @@
     return false;
 }
 
-int EventHub::closeDevice(const char *devicePath) {
-    AutoMutex _l(mLock);
-
-    for (size_t i = FIRST_ACTUAL_DEVICE_INDEX; i < mDevices.size(); i++) {
-        Device* device = mDevices[i];
-        if (device->path == devicePath) {
-            return closeDeviceAtIndexLocked(i);
-        }
+status_t EventHub::closeDeviceByPathLocked(const char *devicePath) {
+    Device* device = getDeviceByPathLocked(devicePath);
+    if (device) {
+        closeDeviceLocked(device);
+        return 0;
     }
     LOGV("Remove device: %s not found, device may already have been removed.", devicePath);
     return -1;
 }
 
-int EventHub::closeDeviceAtIndexLocked(int index) {
-    Device* device = mDevices[index];
+void EventHub::closeAllDevicesLocked() {
+    while (mDevices.size() > 0) {
+        closeDeviceLocked(mDevices.valueAt(mDevices.size() - 1));
+    }
+}
+
+void EventHub::closeDeviceLocked(Device* device) {
     LOGI("Removed device: path=%s name=%s id=%d fd=%d classes=0x%x\n",
          device->path.string(), device->identifier.name.string(), device->id,
          device->fd, device->classes);
 
-    for (int j=0; j<EV_SW; j++) {
-        if (mSwitches[j] == device->id) {
-            mSwitches[j] = 0;
-        }
-    }
-
     if (device->id == mBuiltInKeyboardId) {
         LOGW("built-in keyboard device %s (id=%d) is closing! the apps will not like this",
                 device->path.string(), mBuiltInKeyboardId);
         mBuiltInKeyboardId = -1;
-        clearKeyboardProperties(device, true);
+        clearKeyboardPropertiesLocked(device, true);
     }
-    clearKeyboardProperties(device, false);
+    clearKeyboardPropertiesLocked(device, false);
 
-    mFds.removeAt(index);
-    mDevices.removeAt(index);
+    if (epoll_ctl(mEpollFd, EPOLL_CTL_DEL, device->fd, NULL)) {
+        LOGW("Could not remove device fd from epoll instance.  errno=%d", errno);
+    }
+
+    mDevices.removeItem(device->id);
     device->close();
 
     // Unlink for opening devices list if it is present.
@@ -1152,11 +1184,9 @@
         device->next = mClosingDevices;
         mClosingDevices = device;
     }
-    return 0;
 }
 
-int EventHub::readNotify(int nfd) {
-#ifdef HAVE_INOTIFY
+status_t EventHub::readNotifyLocked() {
     int res;
     char devname[PATH_MAX];
     char *filename;
@@ -1165,13 +1195,13 @@
     int event_pos = 0;
     struct inotify_event *event;
 
-    LOGV("EventHub::readNotify nfd: %d\n", nfd);
-    res = read(nfd, event_buf, sizeof(event_buf));
+    LOGV("EventHub::readNotify nfd: %d\n", mINotifyFd);
+    res = read(mINotifyFd, event_buf, sizeof(event_buf));
     if(res < (int)sizeof(*event)) {
         if(errno == EINTR)
             return 0;
         LOGW("could not get event, %s\n", strerror(errno));
-        return 1;
+        return -1;
     }
     //printf("got %d bytes of event information\n", res);
 
@@ -1185,21 +1215,19 @@
         if(event->len) {
             strcpy(filename, event->name);
             if(event->mask & IN_CREATE) {
-                openDevice(devname);
-            }
-            else {
-                closeDevice(devname);
+                openDeviceLocked(devname);
+            } else {
+                closeDeviceByPathLocked(devname);
             }
         }
         event_size = sizeof(*event) + event->len;
         res -= event_size;
         event_pos += event_size;
     }
-#endif
     return 0;
 }
 
-int EventHub::scanDir(const char *dirname)
+status_t EventHub::scanDirLocked(const char *dirname)
 {
     char devname[PATH_MAX];
     char *filename;
@@ -1217,12 +1245,19 @@
             (de->d_name[1] == '.' && de->d_name[2] == '\0')))
             continue;
         strcpy(filename, de->d_name);
-        openDevice(devname);
+        openDeviceLocked(devname);
     }
     closedir(dir);
     return 0;
 }
 
+void EventHub::requestReopenDevices() {
+    LOGV("requestReopenDevices() called");
+
+    AutoMutex _l(mLock);
+    mNeedToReopenDevices = true;
+}
+
 void EventHub::dump(String8& dump) {
     dump.append("Event Hub State:\n");
 
@@ -1233,31 +1268,29 @@
 
         dump.append(INDENT "Devices:\n");
 
-        for (size_t i = FIRST_ACTUAL_DEVICE_INDEX; i < mDevices.size(); i++) {
-            const Device* device = mDevices[i];
-            if (device) {
-                if (mBuiltInKeyboardId == device->id) {
-                    dump.appendFormat(INDENT2 "%d: %s (aka device 0 - built-in keyboard)\n",
-                            device->id, device->identifier.name.string());
-                } else {
-                    dump.appendFormat(INDENT2 "%d: %s\n", device->id,
-                            device->identifier.name.string());
-                }
-                dump.appendFormat(INDENT3 "Classes: 0x%08x\n", device->classes);
-                dump.appendFormat(INDENT3 "Path: %s\n", device->path.string());
-                dump.appendFormat(INDENT3 "Location: %s\n", device->identifier.location.string());
-                dump.appendFormat(INDENT3 "UniqueId: %s\n", device->identifier.uniqueId.string());
-                dump.appendFormat(INDENT3 "Identifier: bus=0x%04x, vendor=0x%04x, "
-                        "product=0x%04x, version=0x%04x\n",
-                        device->identifier.bus, device->identifier.vendor,
-                        device->identifier.product, device->identifier.version);
-                dump.appendFormat(INDENT3 "KeyLayoutFile: %s\n",
-                        device->keyMap.keyLayoutFile.string());
-                dump.appendFormat(INDENT3 "KeyCharacterMapFile: %s\n",
-                        device->keyMap.keyCharacterMapFile.string());
-                dump.appendFormat(INDENT3 "ConfigurationFile: %s\n",
-                        device->configurationFile.string());
+        for (size_t i = 0; i < mDevices.size(); i++) {
+            const Device* device = mDevices.valueAt(i);
+            if (mBuiltInKeyboardId == device->id) {
+                dump.appendFormat(INDENT2 "%d: %s (aka device 0 - built-in keyboard)\n",
+                        device->id, device->identifier.name.string());
+            } else {
+                dump.appendFormat(INDENT2 "%d: %s\n", device->id,
+                        device->identifier.name.string());
             }
+            dump.appendFormat(INDENT3 "Classes: 0x%08x\n", device->classes);
+            dump.appendFormat(INDENT3 "Path: %s\n", device->path.string());
+            dump.appendFormat(INDENT3 "Location: %s\n", device->identifier.location.string());
+            dump.appendFormat(INDENT3 "UniqueId: %s\n", device->identifier.uniqueId.string());
+            dump.appendFormat(INDENT3 "Identifier: bus=0x%04x, vendor=0x%04x, "
+                    "product=0x%04x, version=0x%04x\n",
+                    device->identifier.bus, device->identifier.vendor,
+                    device->identifier.product, device->identifier.version);
+            dump.appendFormat(INDENT3 "KeyLayoutFile: %s\n",
+                    device->keyMap.keyLayoutFile.string());
+            dump.appendFormat(INDENT3 "KeyCharacterMapFile: %s\n",
+                    device->keyMap.keyCharacterMapFile.string());
+            dump.appendFormat(INDENT3 "ConfigurationFile: %s\n",
+                    device->configurationFile.string());
         }
     } // release lock
 }
diff --git a/services/input/EventHub.h b/services/input/EventHub.h
index ca33619..0a34e45 100644
--- a/services/input/EventHub.h
+++ b/services/input/EventHub.h
@@ -31,49 +31,16 @@
 #include <utils/Errors.h>
 #include <utils/PropertyMap.h>
 #include <utils/Vector.h>
+#include <utils/KeyedVector.h>
 
 #include <linux/input.h>
-
-/* These constants are not defined in linux/input.h in the version of the kernel
- * headers currently provided with Bionic. */
-
-#define EVIOCGPROP(len) _IOC(_IOC_READ, 'E', 0x09, len)
-
-#define INPUT_PROP_POINTER 0x00
-#define INPUT_PROP_DIRECT 0x01
-#define INPUT_PROP_BUTTONPAD 0x02
-#define INPUT_PROP_SEMI_MT 0x03
-#define INPUT_PROP_MAX 0x1f
-#define INPUT_PROP_CNT (INPUT_PROP_MAX + 1)
-
-#define ABS_MT_SLOT 0x2f
-#define ABS_MT_TOUCH_MAJOR 0x30
-#define ABS_MT_TOUCH_MINOR 0x31
-#define ABS_MT_WIDTH_MAJOR 0x32
-#define ABS_MT_WIDTH_MINOR 0x33
-#define ABS_MT_ORIENTATION 0x34
-#define ABS_MT_POSITION_X 0x35
-#define ABS_MT_POSITION_Y 0x36
-#define ABS_MT_TOOL_TYPE 0x37
-#define ABS_MT_BLOB_ID 0x38
-#define ABS_MT_TRACKING_ID 0x39
-#define ABS_MT_PRESSURE 0x3a
-#define ABS_MT_DISTANCE 0x3b
-
-#define MT_TOOL_FINGER 0
-#define MT_TOOL_PEN 1
-
-#define SYN_MT_REPORT 2
-#define SYN_DROPPED 3
-
+#include <sys/epoll.h>
 
 /* Convenience constants. */
 
 #define BTN_FIRST 0x100  // first button scancode
 #define BTN_LAST 0x15f   // last button scancode
 
-struct pollfd;
-
 namespace android {
 
 /*
@@ -97,6 +64,7 @@
     int32_t maxValue;  // maximum value
     int32_t flat;      // center flat position, eg. flat == 8 means center is between -8 and 8
     int32_t fuzz;      // error tolerance, eg. fuzz == 4 means value is +/- 4 due to noise
+    int32_t resolution; // resolution in units per mm or radians per mm
 
     inline void clear() {
         valid = false;
@@ -104,6 +72,7 @@
         maxValue = 0;
         flat = 0;
         fuzz = 0;
+        resolution = 0;
     }
 };
 
@@ -193,9 +162,9 @@
     virtual status_t mapAxis(int32_t deviceId, int scancode,
             AxisInfo* outAxisInfo) const = 0;
 
-    // exclude a particular device from opening
-    // this can be used to ignore input devices for sensors
-    virtual void addExcludedDevice(const char* deviceName) = 0;
+    // Sets devices that are excluded from opening.
+    // This can be used to ignore input devices for sensors.
+    virtual void setExcludedDevices(const Vector<String8>& devices) = 0;
 
     /*
      * Wait for events to become available and returns them.
@@ -230,6 +199,12 @@
     virtual void getVirtualKeyDefinitions(int32_t deviceId,
             Vector<VirtualKeyDefinition>& outVirtualKeys) const = 0;
 
+    /* Requests the EventHub to reopen all input devices on the next call to getEvents(). */
+    virtual void requestReopenDevices() = 0;
+
+    /* Wakes up getEvents() if it is blocked on a read. */
+    virtual void wake() = 0;
+
     virtual void dump(String8& dump) = 0;
 };
 
@@ -238,8 +213,6 @@
 public:
     EventHub();
 
-    status_t errorCheck() const;
-
     virtual uint32_t getDeviceClasses(int32_t deviceId) const;
 
     virtual String8 getDeviceName(int32_t deviceId) const;
@@ -259,7 +232,7 @@
     virtual status_t mapAxis(int32_t deviceId, int scancode,
             AxisInfo* outAxisInfo) const;
 
-    virtual void addExcludedDevice(const char* deviceName);
+    virtual void setExcludedDevices(const Vector<String8>& devices);
 
     virtual int32_t getScanCodeState(int32_t deviceId, int32_t scanCode) const;
     virtual int32_t getKeyCodeState(int32_t deviceId, int32_t keyCode) const;
@@ -276,22 +249,16 @@
     virtual void getVirtualKeyDefinitions(int32_t deviceId,
             Vector<VirtualKeyDefinition>& outVirtualKeys) const;
 
+    virtual void requestReopenDevices();
+
+    virtual void wake();
+
     virtual void dump(String8& dump);
 
 protected:
     virtual ~EventHub();
-    
+
 private:
-    bool openPlatformInput(void);
-
-    int openDevice(const char *devicePath);
-    int closeDevice(const char *devicePath);
-    int closeDeviceAtIndexLocked(int index);
-    int scanDir(const char *dirname);
-    int readNotify(int nfd);
-
-    status_t mError;
-
     struct Device {
         Device* next;
 
@@ -301,9 +268,14 @@
         const InputDeviceIdentifier identifier;
 
         uint32_t classes;
-        uint8_t* keyBitmask;
-        uint8_t* relBitmask;
-        uint8_t* propBitmask;
+
+        uint8_t keyBitmask[(KEY_MAX + 1) / 8];
+        uint8_t absBitmask[(ABS_MAX + 1) / 8];
+        uint8_t relBitmask[(REL_MAX + 1) / 8];
+        uint8_t swBitmask[(SW_MAX + 1) / 8];
+        uint8_t ledBitmask[(LED_MAX + 1) / 8];
+        uint8_t propBitmask[(INPUT_PROP_MAX + 1) / 8];
+
         String8 configurationFile;
         PropertyMap* configuration;
         VirtualKeyMap* virtualKeyMap;
@@ -315,7 +287,19 @@
         void close();
     };
 
+    status_t openDeviceLocked(const char *devicePath);
+    status_t closeDeviceByPathLocked(const char *devicePath);
+
+    void closeDeviceLocked(Device* device);
+    void closeAllDevicesLocked();
+
+    status_t scanDirLocked(const char *dirname);
+    void scanDevicesLocked();
+    status_t readNotifyLocked();
+
     Device* getDeviceLocked(int32_t deviceId) const;
+    Device* getDeviceByPathLocked(const char* devicePath) const;
+
     bool hasKeycodeLocked(Device* device, int keycode) const;
 
     int32_t getScanCodeStateLocked(Device* device, int32_t scanCode) const;
@@ -324,13 +308,13 @@
     bool markSupportedKeyCodesLocked(Device* device, size_t numCodes,
             const int32_t* keyCodes, uint8_t* outFlags) const;
 
-    void loadConfiguration(Device* device);
-    status_t loadVirtualKeyMap(Device* device);
-    status_t loadKeyMap(Device* device);
-    void setKeyboardProperties(Device* device, bool builtInKeyboard);
-    void clearKeyboardProperties(Device* device, bool builtInKeyboard);
+    void loadConfigurationLocked(Device* device);
+    status_t loadVirtualKeyMapLocked(Device* device);
+    status_t loadKeyMapLocked(Device* device);
+    void setKeyboardPropertiesLocked(Device* device, bool builtInKeyboard);
+    void clearKeyboardPropertiesLocked(Device* device, bool builtInKeyboard);
 
-    bool isExternalDevice(Device* device);
+    bool isExternalDeviceLocked(Device* device);
 
     // Protect all internal state.
     mutable Mutex mLock;
@@ -341,23 +325,36 @@
 
     int32_t mNextDeviceId;
 
-    // Parallel arrays of fds and devices.
-    // First index is reserved for inotify.
-    Vector<struct pollfd> mFds;
-    Vector<Device*> mDevices;
+    KeyedVector<int32_t, Device*> mDevices;
 
     Device *mOpeningDevices;
     Device *mClosingDevices;
 
-    bool mOpened;
     bool mNeedToSendFinishedDeviceScan;
-    List<String8> mExcludedDevices;
+    bool mNeedToReopenDevices;
+    bool mNeedToScanDevices;
+    Vector<String8> mExcludedDevices;
 
-    // device ids that report particular switches.
-    int32_t mSwitches[SW_MAX + 1];
+    int mEpollFd;
+    int mINotifyFd;
+    int mWakeReadPipeFd;
+    int mWakeWritePipeFd;
 
-    // The index of the next file descriptor that needs to be read.
-    size_t mInputFdIndex;
+    // Ids used for epoll notifications not associated with devices.
+    static const uint32_t EPOLL_ID_INOTIFY = 0x80000001;
+    static const uint32_t EPOLL_ID_WAKE = 0x80000002;
+
+    // Epoll FD list size hint.
+    static const int EPOLL_SIZE_HINT = 8;
+
+    // Maximum number of signalled FDs to handle at a time.
+    static const int EPOLL_MAX_EVENTS = 16;
+
+    // The array of pending epoll events and the index of the next event to be handled.
+    struct epoll_event mPendingEventItems[EPOLL_MAX_EVENTS];
+    size_t mPendingEventCount;
+    size_t mPendingEventIndex;
+    bool mPendingINotify;
 
     // Set to the number of CPUs.
     int32_t mNumCpus;
diff --git a/services/input/InputDispatcher.cpp b/services/input/InputDispatcher.cpp
index 8c535d6..4a50d8a 100644
--- a/services/input/InputDispatcher.cpp
+++ b/services/input/InputDispatcher.cpp
@@ -228,13 +228,14 @@
 
     mKeyRepeatState.lastKeyEntry = NULL;
 
-    int32_t maxEventsPerSecond = policy->getMaxEventsPerSecond();
-    mThrottleState.minTimeBetweenEvents = 1000000000LL / maxEventsPerSecond;
+    policy->getDispatcherConfiguration(&mConfig);
+
+    mThrottleState.minTimeBetweenEvents = 1000000000LL / mConfig.maxEventsPerSecond;
     mThrottleState.lastDeviceId = -1;
 
 #if DEBUG_THROTTLING
     mThrottleState.originalSampleCount = 0;
-    LOGD("Throttling - Max events per second = %d", maxEventsPerSecond);
+    LOGD("Throttling - Max events per second = %d", mConfig.maxEventsPerSecond);
 #endif
 }
 
@@ -253,13 +254,10 @@
 }
 
 void InputDispatcher::dispatchOnce() {
-    nsecs_t keyRepeatTimeout = mPolicy->getKeyRepeatTimeout();
-    nsecs_t keyRepeatDelay = mPolicy->getKeyRepeatDelay();
-
     nsecs_t nextWakeupTime = LONG_LONG_MAX;
     { // acquire lock
         AutoMutex _l(mLock);
-        dispatchOnceInnerLocked(keyRepeatTimeout, keyRepeatDelay, & nextWakeupTime);
+        dispatchOnceInnerLocked(&nextWakeupTime);
 
         if (runCommandsLockedInterruptible()) {
             nextWakeupTime = LONG_LONG_MIN;  // force next poll to wake up immediately
@@ -272,14 +270,13 @@
     mLooper->pollOnce(timeoutMillis);
 }
 
-void InputDispatcher::dispatchOnceInnerLocked(nsecs_t keyRepeatTimeout,
-        nsecs_t keyRepeatDelay, nsecs_t* nextWakeupTime) {
+void InputDispatcher::dispatchOnceInnerLocked(nsecs_t* nextWakeupTime) {
     nsecs_t currentTime = now();
 
     // Reset the key repeat timer whenever we disallow key events, even if the next event
     // is not a key.  This is to ensure that we abort a key repeat if the device is just coming
     // out of sleep.
-    if (keyRepeatTimeout < 0) {
+    if (!mPolicy->isKeyRepeatEnabled()) {
         resetKeyRepeatLocked();
     }
 
@@ -313,7 +310,7 @@
             // Synthesize a key repeat if appropriate.
             if (mKeyRepeatState.lastKeyEntry) {
                 if (currentTime >= mKeyRepeatState.nextRepeatTime) {
-                    mPendingEvent = synthesizeKeyRepeatLocked(currentTime, keyRepeatDelay);
+                    mPendingEvent = synthesizeKeyRepeatLocked(currentTime);
                 } else {
                     if (mKeyRepeatState.nextRepeatTime < *nextWakeupTime) {
                         *nextWakeupTime = mKeyRepeatState.nextRepeatTime;
@@ -432,8 +429,7 @@
         if (dropReason == DROP_REASON_NOT_DROPPED && mNextUnblockedEvent) {
             dropReason = DROP_REASON_BLOCKED;
         }
-        done = dispatchKeyLocked(currentTime, typedEntry, keyRepeatTimeout,
-                &dropReason, nextWakeupTime);
+        done = dispatchKeyLocked(currentTime, typedEntry, &dropReason, nextWakeupTime);
         break;
     }
 
@@ -692,8 +688,7 @@
     }
 }
 
-InputDispatcher::KeyEntry* InputDispatcher::synthesizeKeyRepeatLocked(
-        nsecs_t currentTime, nsecs_t keyRepeatDelay) {
+InputDispatcher::KeyEntry* InputDispatcher::synthesizeKeyRepeatLocked(nsecs_t currentTime) {
     KeyEntry* entry = mKeyRepeatState.lastKeyEntry;
 
     // Reuse the repeated key entry if it is otherwise unreferenced.
@@ -721,7 +716,7 @@
     // mKeyRepeatState.lastKeyEntry in addition to the one we return.
     entry->refCount += 1;
 
-    mKeyRepeatState.nextRepeatTime = currentTime + keyRepeatDelay;
+    mKeyRepeatState.nextRepeatTime = currentTime + mConfig.keyRepeatDelay;
     return entry;
 }
 
@@ -741,8 +736,7 @@
     return true;
 }
 
-bool InputDispatcher::dispatchKeyLocked(
-        nsecs_t currentTime, KeyEntry* entry, nsecs_t keyRepeatTimeout,
+bool InputDispatcher::dispatchKeyLocked(nsecs_t currentTime, KeyEntry* entry,
         DropReason* dropReason, nsecs_t* nextWakeupTime) {
     // Preprocessing.
     if (! entry->dispatchInProgress) {
@@ -762,7 +756,7 @@
             } else {
                 // Not a repeat.  Save key down state in case we do see a repeat later.
                 resetKeyRepeatLocked();
-                mKeyRepeatState.nextRepeatTime = entry->eventTime + keyRepeatTimeout;
+                mKeyRepeatState.nextRepeatTime = entry->eventTime + mConfig.keyRepeatTimeout;
             }
             mKeyRepeatState.lastKeyEntry = entry;
             entry->refCount += 1;
@@ -1418,6 +1412,50 @@
             injectionResult = INPUT_EVENT_INJECTION_FAILED;
             goto Failed;
         }
+
+        // Check whether touches should slip outside of the current foreground window.
+        if (maskedAction == AMOTION_EVENT_ACTION_MOVE
+                && entry->pointerCount == 1
+                && mTempTouchState.isSlippery()) {
+            const MotionSample* sample = &entry->firstSample;
+            int32_t x = int32_t(sample->pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_X));
+            int32_t y = int32_t(sample->pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_Y));
+
+            const InputWindow* oldTouchedWindow = mTempTouchState.getFirstForegroundWindow();
+            const InputWindow* newTouchedWindow = findTouchedWindowAtLocked(x, y);
+            if (oldTouchedWindow != newTouchedWindow && newTouchedWindow) {
+#if DEBUG_FOCUS
+                LOGD("Touch is slipping out of window %s into window %s.",
+                        oldTouchedWindow->name.string(), newTouchedWindow->name.string());
+#endif
+                // Make a slippery exit from the old window.
+                mTempTouchState.addOrUpdateWindow(oldTouchedWindow,
+                        InputTarget::FLAG_DISPATCH_AS_SLIPPERY_EXIT, BitSet32(0));
+
+                // Make a slippery entrance into the new window.
+                if (newTouchedWindow->supportsSplitTouch()) {
+                    isSplit = true;
+                }
+
+                int32_t targetFlags = InputTarget::FLAG_FOREGROUND
+                        | InputTarget::FLAG_DISPATCH_AS_SLIPPERY_ENTER;
+                if (isSplit) {
+                    targetFlags |= InputTarget::FLAG_SPLIT;
+                }
+                if (isWindowObscuredAtPointLocked(newTouchedWindow, x, y)) {
+                    targetFlags |= InputTarget::FLAG_WINDOW_IS_OBSCURED;
+                }
+
+                BitSet32 pointerIds;
+                if (isSplit) {
+                    pointerIds.markBit(entry->pointerProperties[0].id);
+                }
+                mTempTouchState.addOrUpdateWindow(newTouchedWindow, targetFlags, pointerIds);
+
+                // Split the batch here so we send exactly one sample.
+                *outSplitBatchAfterSample = &entry->firstSample;
+            }
+        }
     }
 
     if (newHoverWindow != mLastHoverWindow) {
@@ -1470,6 +1508,23 @@
         injectionPermission = INJECTION_PERMISSION_GRANTED;
     }
 
+    // Check whether windows listening for outside touches are owned by the same UID. If it is
+    // set the policy flag that we will not reveal coordinate information to this window.
+    if (maskedAction == AMOTION_EVENT_ACTION_DOWN) {
+        const InputWindow* foregroundWindow = mTempTouchState.getFirstForegroundWindow();
+        const int32_t foregroundWindowUid = foregroundWindow->ownerUid;
+        for (size_t i = 0; i < mTempTouchState.windows.size(); i++) {
+            const TouchedWindow& touchedWindow = mTempTouchState.windows[i];
+            if (touchedWindow.targetFlags & InputTarget::FLAG_DISPATCH_AS_OUTSIDE) {
+                const InputWindow* inputWindow = touchedWindow.window;
+                if (inputWindow->ownerUid != foregroundWindowUid) {
+                    mTempTouchState.addOrUpdateWindow(inputWindow,
+                            InputTarget::FLAG_ZERO_COORDS, BitSet32(0));
+                }
+            }
+        }
+    }
+
     // Ensure all touched foreground windows are ready for new input.
     for (size_t i = 0; i < mTempTouchState.windows.size(); i++) {
         const TouchedWindow& touchedWindow = mTempTouchState.windows[i];
@@ -1873,6 +1928,10 @@
             resumeWithAppendedMotionSample, InputTarget::FLAG_DISPATCH_AS_HOVER_ENTER);
     enqueueDispatchEntryLocked(connection, eventEntry, inputTarget,
             resumeWithAppendedMotionSample, InputTarget::FLAG_DISPATCH_AS_IS);
+    enqueueDispatchEntryLocked(connection, eventEntry, inputTarget,
+            resumeWithAppendedMotionSample, InputTarget::FLAG_DISPATCH_AS_SLIPPERY_EXIT);
+    enqueueDispatchEntryLocked(connection, eventEntry, inputTarget,
+            resumeWithAppendedMotionSample, InputTarget::FLAG_DISPATCH_AS_SLIPPERY_ENTER);
 
     // If the outbound queue was previously empty, start the dispatch cycle going.
     if (wasEmpty && !connection->outboundQueue.isEmpty()) {
@@ -1974,6 +2033,10 @@
             action = AMOTION_EVENT_ACTION_HOVER_EXIT;
         } else if (dispatchEntry->targetFlags & InputTarget::FLAG_DISPATCH_AS_HOVER_ENTER) {
             action = AMOTION_EVENT_ACTION_HOVER_ENTER;
+        } else if (dispatchEntry->targetFlags & InputTarget::FLAG_DISPATCH_AS_SLIPPERY_EXIT) {
+            action = AMOTION_EVENT_ACTION_CANCEL;
+        } else if (dispatchEntry->targetFlags & InputTarget::FLAG_DISPATCH_AS_SLIPPERY_ENTER) {
+            action = AMOTION_EVENT_ACTION_DOWN;
         }
         if (dispatchEntry->targetFlags & InputTarget::FLAG_WINDOW_IS_OBSCURED) {
             flags |= AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED;
@@ -1993,7 +2056,8 @@
 
         // Set the X and Y offset depending on the input source.
         float xOffset, yOffset, scaleFactor;
-        if (motionEntry->source & AINPUT_SOURCE_CLASS_POINTER) {
+        if (motionEntry->source & AINPUT_SOURCE_CLASS_POINTER
+                && !(dispatchEntry->targetFlags & InputTarget::FLAG_ZERO_COORDS)) {
             scaleFactor = dispatchEntry->scaleFactor;
             xOffset = dispatchEntry->xOffset * scaleFactor;
             yOffset = dispatchEntry->yOffset * scaleFactor;
@@ -2008,6 +2072,14 @@
             xOffset = 0.0f;
             yOffset = 0.0f;
             scaleFactor = 1.0f;
+
+            // We don't want the dispatch target to know.
+            if (dispatchEntry->targetFlags & InputTarget::FLAG_ZERO_COORDS) {
+                for (size_t i = 0; i < motionEntry->pointerCount; i++) {
+                    scaledCoords[i].clear();
+                }
+                usingCoords = scaledCoords;
+            }
         }
 
         // Update the connection's input state.
@@ -2036,9 +2108,11 @@
             MotionSample* nextMotionSample = firstMotionSample->next;
             for (; nextMotionSample != NULL; nextMotionSample = nextMotionSample->next) {
                 if (usingCoords == scaledCoords) {
-                    for (size_t i = 0; i < motionEntry->pointerCount; i++) {
-                        scaledCoords[i] = nextMotionSample->pointerCoords[i];
-                        scaledCoords[i].scale(scaleFactor);
+                    if (!(dispatchEntry->targetFlags & InputTarget::FLAG_ZERO_COORDS)) {
+                        for (size_t i = 0; i < motionEntry->pointerCount; i++) {
+                            scaledCoords[i] = nextMotionSample->pointerCoords[i];
+                            scaledCoords[i].scale(scaleFactor);
+                        }
                     }
                 } else {
                     usingCoords = nextMotionSample->pointerCoords;
@@ -3321,6 +3395,7 @@
                     window.frameRight, window.frameBottom,
                     window.scaleFactor);
             dumpRegion(dump, window.touchableRegion);
+            dump.appendFormat(", inputFeatures=0x%08x", window.inputFeatures);
             dump.appendFormat(", ownerPid=%d, ownerUid=%d, dispatchingTimeout=%0.3fms\n",
                     window.ownerPid, window.ownerUid,
                     window.dispatchingTimeout / 1000000.0);
@@ -3777,6 +3852,11 @@
 void InputDispatcher::dump(String8& dump) {
     dump.append("Input Dispatcher State:\n");
     dumpDispatchStateLocked(dump);
+
+    dump.append(INDENT "Configuration:\n");
+    dump.appendFormat(INDENT2 "MaxEventsPerSecond: %d\n", mConfig.maxEventsPerSecond);
+    dump.appendFormat(INDENT2 "KeyRepeatDelay: %0.1fms\n", mConfig.keyRepeatDelay * 0.000001f);
+    dump.appendFormat(INDENT2 "KeyRepeatTimeout: %0.1fms\n", mConfig.keyRepeatTimeout * 0.000001f);
 }
 
 
@@ -4359,6 +4439,9 @@
         TouchedWindow& touchedWindow = windows.editItemAt(i);
         if (touchedWindow.window == window) {
             touchedWindow.targetFlags |= targetFlags;
+            if (targetFlags & InputTarget::FLAG_DISPATCH_AS_SLIPPERY_EXIT) {
+                touchedWindow.targetFlags &= ~InputTarget::FLAG_DISPATCH_AS_IS;
+            }
             touchedWindow.pointerIds.value |= pointerIds.value;
             return;
         }
@@ -4376,7 +4459,8 @@
 void InputDispatcher::TouchState::filterNonAsIsTouchWindows() {
     for (size_t i = 0 ; i < windows.size(); ) {
         TouchedWindow& window = windows.editItemAt(i);
-        if (window.targetFlags & InputTarget::FLAG_DISPATCH_AS_IS) {
+        if (window.targetFlags & (InputTarget::FLAG_DISPATCH_AS_IS
+                | InputTarget::FLAG_DISPATCH_AS_SLIPPERY_ENTER)) {
             window.targetFlags &= ~InputTarget::FLAG_DISPATCH_MASK;
             window.targetFlags |= InputTarget::FLAG_DISPATCH_AS_IS;
             i += 1;
@@ -4386,15 +4470,32 @@
     }
 }
 
-const InputWindow* InputDispatcher::TouchState::getFirstForegroundWindow() {
+const InputWindow* InputDispatcher::TouchState::getFirstForegroundWindow() const {
     for (size_t i = 0; i < windows.size(); i++) {
-        if (windows[i].targetFlags & InputTarget::FLAG_FOREGROUND) {
-            return windows[i].window;
+        const TouchedWindow& window = windows.itemAt(i);
+        if (window.targetFlags & InputTarget::FLAG_FOREGROUND) {
+            return window.window;
         }
     }
     return NULL;
 }
 
+bool InputDispatcher::TouchState::isSlippery() const {
+    // Must have exactly one foreground window.
+    bool haveSlipperyForegroundWindow = false;
+    for (size_t i = 0; i < windows.size(); i++) {
+        const TouchedWindow& window = windows.itemAt(i);
+        if (window.targetFlags & InputTarget::FLAG_FOREGROUND) {
+            if (haveSlipperyForegroundWindow
+                    || !(window.window->layoutParamsFlags & InputWindow::FLAG_SLIPPERY)) {
+                return false;
+            }
+            haveSlipperyForegroundWindow = true;
+        }
+    }
+    return haveSlipperyForegroundWindow;
+}
+
 
 // --- InputDispatcherThread ---
 
diff --git a/services/input/InputDispatcher.h b/services/input/InputDispatcher.h
index 9ac5b75..676d162 100644
--- a/services/input/InputDispatcher.h
+++ b/services/input/InputDispatcher.h
@@ -96,6 +96,12 @@
         /* This flag indicates that a motion event is being split across multiple windows. */
         FLAG_SPLIT = 1 << 2,
 
+        /* This flag indicates that the pointer coordinates dispatched to the application
+         * will be zeroed out to avoid revealing information to an application. This is
+         * used in conjunction with FLAG_DISPATCH_AS_OUTSIDE to prevent apps not sharing
+         * the same UID from watching all touches. */
+        FLAG_ZERO_COORDS = 1 << 3,
+
         /* This flag indicates that the event should be sent as is.
          * Should always be set unless the event is to be transmuted. */
         FLAG_DISPATCH_AS_IS = 1 << 8,
@@ -115,11 +121,23 @@
          * The event is transmuted into ACTION_HOVER_ENTER. */
         FLAG_DISPATCH_AS_HOVER_EXIT = 1 << 11,
 
+        /* This flag indicates that the event should be canceled.
+         * It is used to transmute ACTION_MOVE into ACTION_CANCEL when a touch slips
+         * outside of a window. */
+        FLAG_DISPATCH_AS_SLIPPERY_EXIT = 1 << 12,
+
+        /* This flag indicates that the event should be dispatched as an initial down.
+         * It is used to transmute ACTION_MOVE into ACTION_DOWN when a touch slips
+         * into a new window. */
+        FLAG_DISPATCH_AS_SLIPPERY_ENTER = 1 << 13,
+
         /* Mask for all dispatch modes. */
         FLAG_DISPATCH_MASK = FLAG_DISPATCH_AS_IS
                 | FLAG_DISPATCH_AS_OUTSIDE
                 | FLAG_DISPATCH_AS_HOVER_ENTER
-                | FLAG_DISPATCH_AS_HOVER_EXIT,
+                | FLAG_DISPATCH_AS_HOVER_EXIT
+                | FLAG_DISPATCH_AS_SLIPPERY_EXIT
+                | FLAG_DISPATCH_AS_SLIPPERY_ENTER,
     };
 
     // The input channel to be targeted.
@@ -143,6 +161,30 @@
 
 
 /*
+ * Input dispatcher configuration.
+ *
+ * Specifies various options that modify the behavior of the input dispatcher.
+ */
+struct InputDispatcherConfiguration {
+    // The key repeat initial timeout.
+    nsecs_t keyRepeatTimeout;
+
+    // The key repeat inter-key delay.
+    nsecs_t keyRepeatDelay;
+
+    // The maximum suggested event delivery rate per second.
+    // This value is used to throttle motion event movement actions on a per-device
+    // basis.  It is not intended to be a hard limit.
+    int32_t maxEventsPerSecond;
+
+    InputDispatcherConfiguration() :
+            keyRepeatTimeout(500 * 1000000LL),
+            keyRepeatDelay(50 * 1000000LL),
+            maxEventsPerSecond(60) { }
+};
+
+
+/*
  * Input dispatcher policy interface.
  *
  * The input reader policy is used by the input reader to interact with the Window Manager
@@ -168,17 +210,11 @@
     /* Notifies the system that an input channel is unrecoverably broken. */
     virtual void notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle) = 0;
 
-    /* Gets the key repeat initial timeout or -1 if automatic key repeating is disabled. */
-    virtual nsecs_t getKeyRepeatTimeout() = 0;
+    /* Gets the input dispatcher configuration. */
+    virtual void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) = 0;
 
-    /* Gets the key repeat inter-key delay. */
-    virtual nsecs_t getKeyRepeatDelay() = 0;
-
-    /* Gets the maximum suggested event delivery rate per second.
-     * This value is used to throttle motion event movement actions on a per-device
-     * basis.  It is not intended to be a hard limit.
-     */
-    virtual int32_t getMaxEventsPerSecond() = 0;
+    /* Returns true if automatic key repeating is enabled. */
+    virtual bool isKeyRepeatEnabled() = 0;
 
     /* Filters an input event.
      * Return true to dispatch the event unmodified, false to consume the event.
@@ -800,6 +836,7 @@
     };
 
     sp<InputDispatcherPolicyInterface> mPolicy;
+    InputDispatcherConfiguration mConfig;
 
     Mutex mLock;
 
@@ -812,8 +849,7 @@
 
     Vector<EventEntry*> mTempCancelationEvents;
 
-    void dispatchOnceInnerLocked(nsecs_t keyRepeatTimeout, nsecs_t keyRepeatDelay,
-            nsecs_t* nextWakeupTime);
+    void dispatchOnceInnerLocked(nsecs_t* nextWakeupTime);
 
     // Batches a new sample onto a motion entry.
     // Assumes that the we have already checked that we can append samples.
@@ -885,7 +921,7 @@
     } mKeyRepeatState;
 
     void resetKeyRepeatLocked();
-    KeyEntry* synthesizeKeyRepeatLocked(nsecs_t currentTime, nsecs_t keyRepeatTimeout);
+    KeyEntry* synthesizeKeyRepeatLocked(nsecs_t currentTime);
 
     // Deferred command processing.
     bool runCommandsLockedInterruptible();
@@ -926,9 +962,10 @@
         ~TouchState();
         void reset();
         void copyFrom(const TouchState& other);
-        void addOrUpdateWindow(const InputWindow* window, int32_t targetFlags, BitSet32 pointerIds);
+        void addOrUpdateWindow(const InputWindow* window,int32_t targetFlags, BitSet32 pointerIds);
         void filterNonAsIsTouchWindows();
-        const InputWindow* getFirstForegroundWindow();
+        const InputWindow* getFirstForegroundWindow() const;
+        bool isSlippery() const;
     };
 
     TouchState mTouchState;
@@ -943,7 +980,7 @@
     bool dispatchConfigurationChangedLocked(
             nsecs_t currentTime, ConfigurationChangedEntry* entry);
     bool dispatchKeyLocked(
-            nsecs_t currentTime, KeyEntry* entry, nsecs_t keyRepeatTimeout,
+            nsecs_t currentTime, KeyEntry* entry,
             DropReason* dropReason, nsecs_t* nextWakeupTime);
     bool dispatchMotionLocked(
             nsecs_t currentTime, MotionEntry* entry,
diff --git a/services/input/InputReader.cpp b/services/input/InputReader.cpp
index 25a2c78..3e4c666 100644
--- a/services/input/InputReader.cpp
+++ b/services/input/InputReader.cpp
@@ -61,65 +61,6 @@
 // Maximum number of slots supported when using the slot-based Multitouch Protocol B.
 static const size_t MAX_SLOTS = 32;
 
-// Quiet time between certain gesture transitions.
-// Time to allow for all fingers or buttons to settle into a stable state before
-// starting a new gesture.
-static const nsecs_t QUIET_INTERVAL = 100 * 1000000; // 100 ms
-
-// The minimum speed that a pointer must travel for us to consider switching the active
-// touch pointer to it during a drag.  This threshold is set to avoid switching due
-// to noise from a finger resting on the touch pad (perhaps just pressing it down).
-static const float DRAG_MIN_SWITCH_SPEED = 50.0f; // pixels per second
-
-// Tap gesture delay time.
-// The time between down and up must be less than this to be considered a tap.
-static const nsecs_t TAP_INTERVAL = 150 * 1000000; // 150 ms
-
-// Tap drag gesture delay time.
-// The time between up and the next up must be greater than this to be considered a
-// drag.  Otherwise, the previous tap is finished and a new tap begins.
-static const nsecs_t TAP_DRAG_INTERVAL = 150 * 1000000; // 150 ms
-
-// The distance in pixels that the pointer is allowed to move from initial down
-// to up and still be called a tap.
-static const float TAP_SLOP = 10.0f; // 10 pixels
-
-// Time after the first touch points go down to settle on an initial centroid.
-// This is intended to be enough time to handle cases where the user puts down two
-// fingers at almost but not quite exactly the same time.
-static const nsecs_t MULTITOUCH_SETTLE_INTERVAL = 100 * 1000000; // 100ms
-
-// The transition from PRESS to SWIPE or FREEFORM gesture mode is made when
-// both of the pointers are moving at least this fast.
-static const float MULTITOUCH_MIN_SPEED = 150.0f; // pixels per second
-
-// The transition from PRESS to SWIPE gesture mode can only occur when the
-// cosine of the angle between the two vectors is greater than or equal to than this value
-// which indicates that the vectors are oriented in the same direction.
-// When the vectors are oriented in the exactly same direction, the cosine is 1.0.
-// (In exactly opposite directions, the cosine is -1.0.)
-static const float SWIPE_TRANSITION_ANGLE_COSINE = 0.5f; // cosine of 45 degrees
-
-// The transition from PRESS to SWIPE gesture mode can only occur when the
-// fingers are no more than this far apart relative to the diagonal size of
-// the touch pad.  For example, a ratio of 0.5 means that the fingers must be
-// no more than half the diagonal size of the touch pad apart.
-static const float SWIPE_MAX_WIDTH_RATIO = 0.333f; // 1/3
-
-// The gesture movement speed factor relative to the size of the display.
-// Movement speed applies when the fingers are moving in the same direction.
-// Without acceleration, a full swipe of the touch pad diagonal in movement mode
-// will cover this portion of the display diagonal.
-static const float GESTURE_MOVEMENT_SPEED_RATIO = 0.8f;
-
-// The gesture zoom speed factor relative to the size of the display.
-// Zoom speed applies when the fingers are mostly moving relative to each other
-// to execute a scale gesture or similar.
-// Without acceleration, a full swipe of the touch pad diagonal in zoom mode
-// will cover this portion of the display diagonal.
-static const float GESTURE_ZOOM_SPEED_RATIO = 0.3f;
-
-
 // --- Static Functions ---
 
 template<typename T>
@@ -258,23 +199,6 @@
     return edgeFlags;
 }
 
-static void clampPositionUsingPointerBounds(
-        const sp<PointerControllerInterface>& pointerController, float* x, float* y) {
-    float minX, minY, maxX, maxY;
-    if (pointerController->getBounds(&minX, &minY, &maxX, &maxY)) {
-        if (*x < minX) {
-            *x = minX;
-        } else if (*x > maxX) {
-            *x = maxX;
-        }
-        if (*y < minY) {
-            *y = minY;
-        } else if (*y > maxY) {
-            *y = maxY;
-        }
-    }
-}
-
 static float calculateCommonVector(float a, float b) {
     if (a > 0 && b > 0) {
         return a < b ? a : b;
@@ -319,8 +243,9 @@
         const sp<InputReaderPolicyInterface>& policy,
         const sp<InputDispatcherInterface>& dispatcher) :
         mEventHub(eventHub), mPolicy(policy), mDispatcher(dispatcher),
-        mGlobalMetaState(0), mDisableVirtualKeysTimeout(LLONG_MIN), mNextTimeout(LLONG_MAX) {
-    configureExcludedDevices();
+        mGlobalMetaState(0), mDisableVirtualKeysTimeout(LLONG_MIN), mNextTimeout(LLONG_MAX),
+        mConfigurationChangesToRefresh(0) {
+    refreshConfiguration(0);
     updateGlobalMetaState();
     updateInputConfiguration();
 }
@@ -332,6 +257,18 @@
 }
 
 void InputReader::loopOnce() {
+    uint32_t changes;
+    { // acquire lock
+        AutoMutex _l(mStateLock);
+
+        changes = mConfigurationChangesToRefresh;
+        mConfigurationChangesToRefresh = 0;
+    } // release lock
+
+    if (changes) {
+        refreshConfiguration(changes);
+    }
+
     int32_t timeoutMillis = -1;
     if (mNextTimeout != LLONG_MAX) {
         nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
@@ -395,7 +332,7 @@
     uint32_t classes = mEventHub->getDeviceClasses(deviceId);
 
     InputDevice* device = createDevice(deviceId, name, classes);
-    device->configure();
+    device->configure(&mConfig, 0);
 
     if (device->isIgnored()) {
         LOGI("Device added: id=%d, name='%s' (ignored non-input device)", deviceId, name.string());
@@ -552,12 +489,25 @@
     mDispatcher->notifyConfigurationChanged(when);
 }
 
-void InputReader::configureExcludedDevices() {
-    Vector<String8> excludedDeviceNames;
-    mPolicy->getExcludedDeviceNames(excludedDeviceNames);
+void InputReader::refreshConfiguration(uint32_t changes) {
+    mPolicy->getReaderConfiguration(&mConfig);
+    mEventHub->setExcludedDevices(mConfig.excludedDeviceNames);
 
-    for (size_t i = 0; i < excludedDeviceNames.size(); i++) {
-        mEventHub->addExcludedDevice(excludedDeviceNames[i]);
+    if (changes) {
+        LOGI("Reconfiguring input devices.  changes=0x%08x", changes);
+
+        if (changes & InputReaderConfiguration::CHANGE_MUST_REOPEN) {
+            mEventHub->requestReopenDevices();
+        } else {
+            { // acquire device registry reader lock
+                RWLock::AutoRLock _rl(mDeviceRegistryLock);
+
+                for (size_t i = 0; i < mDevices.size(); i++) {
+                    InputDevice* device = mDevices.valueAt(i);
+                    device->configure(&mConfig, changes);
+                }
+            } // release device registry reader lock
+        }
     }
 }
 
@@ -778,6 +728,22 @@
     } // release device registy reader lock
 }
 
+void InputReader::requestRefreshConfiguration(uint32_t changes) {
+    if (changes) {
+        bool needWake;
+        { // acquire lock
+            AutoMutex _l(mStateLock);
+
+            needWake = !mConfigurationChangesToRefresh;
+            mConfigurationChangesToRefresh |= changes;
+        } // release lock
+
+        if (needWake) {
+            mEventHub->wake();
+        }
+    }
+}
+
 void InputReader::dump(String8& dump) {
     mEventHub->dump(dump);
     dump.append("\n");
@@ -791,6 +757,62 @@
             mDevices.valueAt(i)->dump(dump);
         }
     } // release device registy reader lock
+
+    dump.append(INDENT "Configuration:\n");
+    dump.append(INDENT2 "ExcludedDeviceNames: [");
+    for (size_t i = 0; i < mConfig.excludedDeviceNames.size(); i++) {
+        if (i != 0) {
+            dump.append(", ");
+        }
+        dump.append(mConfig.excludedDeviceNames.itemAt(i).string());
+    }
+    dump.append("]\n");
+    dump.appendFormat(INDENT2 "FilterTouchEvents: %s\n",
+            toString(mConfig.filterTouchEvents));
+    dump.appendFormat(INDENT2 "FilterJumpyTouchEvents: %s\n",
+            toString(mConfig.filterJumpyTouchEvents));
+    dump.appendFormat(INDENT2 "VirtualKeyQuietTime: %0.1fms\n",
+            mConfig.virtualKeyQuietTime * 0.000001f);
+
+    dump.appendFormat(INDENT2 "PointerVelocityControlParameters: "
+            "scale=%0.3f, lowThreshold=%0.3f, highThreshold=%0.3f, acceleration=%0.3f\n",
+            mConfig.pointerVelocityControlParameters.scale,
+            mConfig.pointerVelocityControlParameters.lowThreshold,
+            mConfig.pointerVelocityControlParameters.highThreshold,
+            mConfig.pointerVelocityControlParameters.acceleration);
+
+    dump.appendFormat(INDENT2 "WheelVelocityControlParameters: "
+            "scale=%0.3f, lowThreshold=%0.3f, highThreshold=%0.3f, acceleration=%0.3f\n",
+            mConfig.wheelVelocityControlParameters.scale,
+            mConfig.wheelVelocityControlParameters.lowThreshold,
+            mConfig.wheelVelocityControlParameters.highThreshold,
+            mConfig.wheelVelocityControlParameters.acceleration);
+
+    dump.appendFormat(INDENT2 "PointerGesture:\n");
+    dump.appendFormat(INDENT3 "Enabled: %s\n",
+            toString(mConfig.pointerGesturesEnabled));
+    dump.appendFormat(INDENT3 "QuietInterval: %0.1fms\n",
+            mConfig.pointerGestureQuietInterval * 0.000001f);
+    dump.appendFormat(INDENT3 "DragMinSwitchSpeed: %0.1fpx/s\n",
+            mConfig.pointerGestureDragMinSwitchSpeed);
+    dump.appendFormat(INDENT3 "TapInterval: %0.1fms\n",
+            mConfig.pointerGestureTapInterval * 0.000001f);
+    dump.appendFormat(INDENT3 "TapDragInterval: %0.1fms\n",
+            mConfig.pointerGestureTapDragInterval * 0.000001f);
+    dump.appendFormat(INDENT3 "TapSlop: %0.1fpx\n",
+            mConfig.pointerGestureTapSlop);
+    dump.appendFormat(INDENT3 "MultitouchSettleInterval: %0.1fms\n",
+            mConfig.pointerGestureMultitouchSettleInterval * 0.000001f);
+    dump.appendFormat(INDENT3 "MultitouchMinDistance: %0.1fpx\n",
+            mConfig.pointerGestureMultitouchMinDistance);
+    dump.appendFormat(INDENT3 "SwipeTransitionAngleCosine: %0.1f\n",
+            mConfig.pointerGestureSwipeTransitionAngleCosine);
+    dump.appendFormat(INDENT3 "SwipeMaxWidthRatio: %0.1f\n",
+            mConfig.pointerGestureSwipeMaxWidthRatio);
+    dump.appendFormat(INDENT3 "MovementSpeedRatio: %0.1f\n",
+            mConfig.pointerGestureMovementSpeedRatio);
+    dump.appendFormat(INDENT3 "ZoomSpeedRatio: %0.1f\n",
+            mConfig.pointerGestureZoomSpeedRatio);
 }
 
 
@@ -864,18 +886,20 @@
     mMappers.add(mapper);
 }
 
-void InputDevice::configure() {
-    if (! isIgnored()) {
-        mContext->getEventHub()->getConfiguration(mId, &mConfiguration);
-    }
-
+void InputDevice::configure(const InputReaderConfiguration* config, uint32_t changes) {
     mSources = 0;
 
-    size_t numMappers = mMappers.size();
-    for (size_t i = 0; i < numMappers; i++) {
-        InputMapper* mapper = mMappers[i];
-        mapper->configure();
-        mSources |= mapper->getSources();
+    if (!isIgnored()) {
+        if (!changes) { // first time only
+            mContext->getEventHub()->getConfiguration(mId, &mConfiguration);
+        }
+
+        size_t numMappers = mMappers.size();
+        for (size_t i = 0; i < numMappers; i++) {
+            InputMapper* mapper = mMappers[i];
+            mapper->configure(config, changes);
+            mSources |= mapper->getSources();
+        }
     }
 }
 
@@ -1019,7 +1043,7 @@
 void InputMapper::dump(String8& dump) {
 }
 
-void InputMapper::configure() {
+void InputMapper::configure(const InputReaderConfiguration* config, uint32_t changes) {
 }
 
 void InputMapper::reset() {
@@ -1055,8 +1079,8 @@
 void InputMapper::dumpRawAbsoluteAxisInfo(String8& dump,
         const RawAbsoluteAxisInfo& axis, const char* name) {
     if (axis.valid) {
-        dump.appendFormat(INDENT4 "%s: min=%d, max=%d, flat=%d, fuzz=%d\n",
-                name, axis.minValue, axis.maxValue, axis.flat, axis.fuzz);
+        dump.appendFormat(INDENT4 "%s: min=%d, max=%d, flat=%d, fuzz=%d, resolution=%d\n",
+                name, axis.minValue, axis.maxValue, axis.flat, axis.fuzz, axis.resolution);
     } else {
         dump.appendFormat(INDENT4 "%s: unknown range\n", name);
     }
@@ -1133,16 +1157,18 @@
 }
 
 
-void KeyboardInputMapper::configure() {
-    InputMapper::configure();
+void KeyboardInputMapper::configure(const InputReaderConfiguration* config, uint32_t changes) {
+    InputMapper::configure(config, changes);
 
-    // Configure basic parameters.
-    configureParameters();
+    if (!changes) { // first time only
+        // Configure basic parameters.
+        configureParameters();
 
-    // Reset LEDs.
-    {
-        AutoMutex _l(mLock);
-        resetLedStateLocked();
+        // Reset LEDs.
+        {
+            AutoMutex _l(mLock);
+            resetLedStateLocked();
+        }
     }
 }
 
@@ -1420,36 +1446,44 @@
     } // release lock
 }
 
-void CursorInputMapper::configure() {
-    InputMapper::configure();
+void CursorInputMapper::configure(const InputReaderConfiguration* config, uint32_t changes) {
+    InputMapper::configure(config, changes);
 
-    // Configure basic parameters.
-    configureParameters();
+    if (!changes) { // first time only
+        // Configure basic parameters.
+        configureParameters();
 
-    // Configure device mode.
-    switch (mParameters.mode) {
-    case Parameters::MODE_POINTER:
-        mSource = AINPUT_SOURCE_MOUSE;
-        mXPrecision = 1.0f;
-        mYPrecision = 1.0f;
-        mXScale = 1.0f;
-        mYScale = 1.0f;
-        mPointerController = getPolicy()->obtainPointerController(getDeviceId());
-        break;
-    case Parameters::MODE_NAVIGATION:
-        mSource = AINPUT_SOURCE_TRACKBALL;
-        mXPrecision = TRACKBALL_MOVEMENT_THRESHOLD;
-        mYPrecision = TRACKBALL_MOVEMENT_THRESHOLD;
-        mXScale = 1.0f / TRACKBALL_MOVEMENT_THRESHOLD;
-        mYScale = 1.0f / TRACKBALL_MOVEMENT_THRESHOLD;
-        break;
+        // Configure device mode.
+        switch (mParameters.mode) {
+        case Parameters::MODE_POINTER:
+            mSource = AINPUT_SOURCE_MOUSE;
+            mXPrecision = 1.0f;
+            mYPrecision = 1.0f;
+            mXScale = 1.0f;
+            mYScale = 1.0f;
+            mPointerController = getPolicy()->obtainPointerController(getDeviceId());
+            break;
+        case Parameters::MODE_NAVIGATION:
+            mSource = AINPUT_SOURCE_TRACKBALL;
+            mXPrecision = TRACKBALL_MOVEMENT_THRESHOLD;
+            mYPrecision = TRACKBALL_MOVEMENT_THRESHOLD;
+            mXScale = 1.0f / TRACKBALL_MOVEMENT_THRESHOLD;
+            mYScale = 1.0f / TRACKBALL_MOVEMENT_THRESHOLD;
+            break;
+        }
+
+        mVWheelScale = 1.0f;
+        mHWheelScale = 1.0f;
+
+        mHaveVWheel = getEventHub()->hasRelativeAxis(getDeviceId(), REL_WHEEL);
+        mHaveHWheel = getEventHub()->hasRelativeAxis(getDeviceId(), REL_HWHEEL);
     }
 
-    mVWheelScale = 1.0f;
-    mHWheelScale = 1.0f;
-
-    mHaveVWheel = getEventHub()->hasRelativeAxis(getDeviceId(), REL_WHEEL);
-    mHaveHWheel = getEventHub()->hasRelativeAxis(getDeviceId(), REL_HWHEEL);
+    if (!changes || (changes & InputReaderConfiguration::CHANGE_POINTER_SPEED)) {
+        mPointerVelocityControl.setParameters(config->pointerVelocityControlParameters);
+        mWheelXVelocityControl.setParameters(config->wheelVelocityControlParameters);
+        mWheelYVelocityControl.setParameters(config->wheelVelocityControlParameters);
+    }
 }
 
 void CursorInputMapper::configureParameters() {
@@ -1511,6 +1545,11 @@
             }
         } // release lock
 
+        // Reset velocity.
+        mPointerVelocityControl.reset();
+        mWheelXVelocityControl.reset();
+        mWheelYVelocityControl.reset();
+
         // Synthesize button up event on reset.
         nsecs_t when = systemTime(SYSTEM_TIME_MONOTONIC);
         mAccumulator.clear();
@@ -1674,11 +1713,16 @@
         } else {
             vscroll = 0;
         }
+        mWheelYVelocityControl.move(when, NULL, &vscroll);
+
         if (mHaveHWheel && (fields & Accumulator::FIELD_REL_HWHEEL)) {
             hscroll = mAccumulator.relHWheel;
         } else {
             hscroll = 0;
         }
+        mWheelXVelocityControl.move(when, &hscroll, NULL);
+
+        mPointerVelocityControl.move(when, &deltaX, &deltaY);
 
         if (mPointerController != NULL) {
             if (deltaX != 0 || deltaY != 0 || vscroll != 0 || hscroll != 0
@@ -1694,7 +1738,7 @@
                     mPointerController->setButtonState(mLocked.buttonState);
                 }
 
-                mPointerController->unfade();
+                mPointerController->unfade(PointerControllerInterface::TRANSITION_IMMEDIATE);
             }
 
             float x, y;
@@ -1772,7 +1816,7 @@
     { // acquire lock
         AutoMutex _l(mLock);
         if (mPointerController != NULL) {
-            mPointerController->fade();
+            mPointerController->fade(PointerControllerInterface::TRANSITION_GRADUAL);
         }
     } // release lock
 }
@@ -1920,54 +1964,81 @@
     mPointerGesture.reset();
 }
 
-void TouchInputMapper::configure() {
-    InputMapper::configure();
+void TouchInputMapper::configure(const InputReaderConfiguration* config, uint32_t changes) {
+    InputMapper::configure(config, changes);
 
-    // Configure basic parameters.
-    configureParameters();
+    mConfig = *config;
 
-    // Configure sources.
-    switch (mParameters.deviceType) {
-    case Parameters::DEVICE_TYPE_TOUCH_SCREEN:
-        mTouchSource = AINPUT_SOURCE_TOUCHSCREEN;
-        mPointerSource = 0;
-        break;
-    case Parameters::DEVICE_TYPE_TOUCH_PAD:
-        mTouchSource = AINPUT_SOURCE_TOUCHPAD;
-        mPointerSource = 0;
-        break;
-    case Parameters::DEVICE_TYPE_POINTER:
-        mTouchSource = AINPUT_SOURCE_TOUCHPAD;
-        mPointerSource = AINPUT_SOURCE_MOUSE;
-        break;
-    default:
-        LOG_ASSERT(false);
+    if (!changes) { // first time only
+        // Configure basic parameters.
+        configureParameters();
+
+        // Configure sources.
+        switch (mParameters.deviceType) {
+        case Parameters::DEVICE_TYPE_TOUCH_SCREEN:
+            mTouchSource = AINPUT_SOURCE_TOUCHSCREEN;
+            mPointerSource = 0;
+            break;
+        case Parameters::DEVICE_TYPE_TOUCH_PAD:
+            mTouchSource = AINPUT_SOURCE_TOUCHPAD;
+            mPointerSource = 0;
+            break;
+        case Parameters::DEVICE_TYPE_POINTER:
+            mTouchSource = AINPUT_SOURCE_TOUCHPAD;
+            mPointerSource = AINPUT_SOURCE_MOUSE;
+            break;
+        default:
+            LOG_ASSERT(false);
+        }
+
+        // Configure absolute axis information.
+        configureRawAxes();
+
+        // Prepare input device calibration.
+        parseCalibration();
+        resolveCalibration();
+
+        { // acquire lock
+            AutoMutex _l(mLock);
+
+             // Configure surface dimensions and orientation.
+            configureSurfaceLocked();
+        } // release lock
     }
 
-    // Configure absolute axis information.
-    configureRawAxes();
+    if (!changes || (changes & InputReaderConfiguration::CHANGE_POINTER_SPEED)) {
+        mPointerGesture.pointerVelocityControl.setParameters(
+                mConfig.pointerVelocityControlParameters);
+    }
 
-    // Prepare input device calibration.
-    parseCalibration();
-    resolveCalibration();
-
-    { // acquire lock
-        AutoMutex _l(mLock);
-
-         // Configure surface dimensions and orientation.
-        configureSurfaceLocked();
-    } // release lock
+    if (!changes || (changes & InputReaderConfiguration::CHANGE_POINTER_GESTURE_ENABLEMENT)) {
+        // Reset the touch screen when pointer gesture enablement changes.
+        reset();
+    }
 }
 
 void TouchInputMapper::configureParameters() {
-    mParameters.useBadTouchFilter = getPolicy()->filterTouchEvents();
-    mParameters.useAveragingTouchFilter = getPolicy()->filterTouchEvents();
-    mParameters.useJumpyTouchFilter = getPolicy()->filterJumpyTouchEvents();
-    mParameters.virtualKeyQuietTime = getPolicy()->getVirtualKeyQuietTime();
+    mParameters.useBadTouchFilter = mConfig.filterTouchEvents;
+    mParameters.useAveragingTouchFilter = mConfig.filterTouchEvents;
+    mParameters.useJumpyTouchFilter = mConfig.filterJumpyTouchEvents;
 
-    // TODO: Make this configurable.
-    //mParameters.gestureMode = Parameters::GESTURE_MODE_POINTER;
-    mParameters.gestureMode = Parameters::GESTURE_MODE_SPOTS;
+    // Use the pointer presentation mode for devices that do not support distinct
+    // multitouch.  The spot-based presentation relies on being able to accurately
+    // locate two or more fingers on the touch pad.
+    mParameters.gestureMode = getEventHub()->hasInputProperty(getDeviceId(), INPUT_PROP_SEMI_MT)
+            ? Parameters::GESTURE_MODE_POINTER : Parameters::GESTURE_MODE_SPOTS;
+
+    String8 gestureModeString;
+    if (getDevice()->getConfiguration().tryGetProperty(String8("touch.gestureMode"),
+            gestureModeString)) {
+        if (gestureModeString == "pointer") {
+            mParameters.gestureMode = Parameters::GESTURE_MODE_POINTER;
+        } else if (gestureModeString == "spots") {
+            mParameters.gestureMode = Parameters::GESTURE_MODE_SPOTS;
+        } else if (gestureModeString != "default") {
+            LOGW("Invalid value for touch.gestureMode: '%s'", gestureModeString.string());
+        }
+    }
 
     if (getEventHub()->hasRelativeAxis(getDeviceId(), REL_X)
             || getEventHub()->hasRelativeAxis(getDeviceId(), REL_Y)) {
@@ -1994,7 +2065,7 @@
             mParameters.deviceType = Parameters::DEVICE_TYPE_TOUCH_PAD;
         } else if (deviceTypeString == "pointer") {
             mParameters.deviceType = Parameters::DEVICE_TYPE_POINTER;
-        } else {
+        } else if (deviceTypeString != "default") {
             LOGW("Invalid value for touch.deviceType: '%s'", deviceTypeString.string());
         }
     }
@@ -2012,6 +2083,17 @@
 void TouchInputMapper::dumpParameters(String8& dump) {
     dump.append(INDENT3 "Parameters:\n");
 
+    switch (mParameters.gestureMode) {
+    case Parameters::GESTURE_MODE_POINTER:
+        dump.append(INDENT4 "GestureMode: pointer\n");
+        break;
+    case Parameters::GESTURE_MODE_SPOTS:
+        dump.append(INDENT4 "GestureMode: spots\n");
+        break;
+    default:
+        assert(false);
+    }
+
     switch (mParameters.deviceType) {
     case Parameters::DEVICE_TYPE_TOUCH_SCREEN:
         dump.append(INDENT4 "DeviceType: touchScreen\n");
@@ -2365,26 +2447,26 @@
                     mLocked.associatedDisplayHeight);
 
             // Scale movements such that one whole swipe of the touch pad covers a
-            // given area relative to the diagonal size of the display.
+            // given area relative to the diagonal size of the display when no acceleration
+            // is applied.
             // Assume that the touch pad has a square aspect ratio such that movements in
             // X and Y of the same number of raw units cover the same physical distance.
-            const float scaleFactor = 0.8f;
-
-            mLocked.pointerGestureXMovementScale = GESTURE_MOVEMENT_SPEED_RATIO
+            mLocked.pointerGestureXMovementScale = mConfig.pointerGestureMovementSpeedRatio
                     * displayDiagonal / rawDiagonal;
             mLocked.pointerGestureYMovementScale = mLocked.pointerGestureXMovementScale;
 
             // Scale zooms to cover a smaller range of the display than movements do.
             // This value determines the area around the pointer that is affected by freeform
             // pointer gestures.
-            mLocked.pointerGestureXZoomScale = GESTURE_ZOOM_SPEED_RATIO
+            mLocked.pointerGestureXZoomScale = mConfig.pointerGestureZoomSpeedRatio
                     * displayDiagonal / rawDiagonal;
             mLocked.pointerGestureYZoomScale = mLocked.pointerGestureXZoomScale;
 
             // Max width between pointers to detect a swipe gesture is more than some fraction
             // of the diagonal axis of the touch pad.  Touches that are wider than this are
             // translated into freeform gestures.
-            mLocked.pointerGestureMaxSwipeWidth = SWIPE_MAX_WIDTH_RATIO * rawDiagonal;
+            mLocked.pointerGestureMaxSwipeWidth =
+                    mConfig.pointerGestureSwipeMaxWidthRatio * rawDiagonal;
 
             // Reset the current pointer gesture.
             mPointerGesture.reset();
@@ -2870,6 +2952,7 @@
 
         if (mPointerController != NULL
                 && mParameters.gestureMode == Parameters::GESTURE_MODE_SPOTS) {
+            mPointerController->fade(PointerControllerInterface::TRANSITION_GRADUAL);
             mPointerController->clearSpots();
         }
     } // release lock
@@ -2950,7 +3033,7 @@
         touchResult = consumeOffScreenTouches(when, policyFlags);
         if (touchResult == DISPATCH_TOUCH) {
             suppressSwipeOntoVirtualKeys(when);
-            if (mPointerController != NULL) {
+            if (mPointerController != NULL && mConfig.pointerGesturesEnabled) {
                 dispatchPointerGestures(when, policyFlags, false /*isTimeout*/);
             }
             dispatchTouches(when, policyFlags);
@@ -3107,8 +3190,8 @@
     //    area and accidentally triggers a virtual key.  This often happens when virtual keys
     //    are layed out below the screen near to where the on screen keyboard's space bar
     //    is displayed.
-    if (mParameters.virtualKeyQuietTime > 0 && mCurrentTouch.pointerCount != 0) {
-        mContext->disableVirtualKeysUntil(when + mParameters.virtualKeyQuietTime);
+    if (mConfig.virtualKeyQuietTime > 0 && mCurrentTouch.pointerCount != 0) {
+        mContext->disableVirtualKeysUntil(when + mConfig.virtualKeyQuietTime);
     }
 }
 
@@ -3451,12 +3534,6 @@
 
 void TouchInputMapper::dispatchPointerGestures(nsecs_t when, uint32_t policyFlags,
         bool isTimeout) {
-    // Switch pointer presentation.
-    mPointerController->setPresentation(
-            mParameters.gestureMode == Parameters::GESTURE_MODE_SPOTS
-                    ? PointerControllerInterface::PRESENTATION_SPOT
-                    : PointerControllerInterface::PRESENTATION_POINTER);
-
     // Update current gesture coordinates.
     bool cancelPreviousGesture, finishPreviousGesture;
     bool sendEvents = preparePointerGestures(when,
@@ -3464,11 +3541,53 @@
     if (!sendEvents) {
         return;
     }
+    if (finishPreviousGesture) {
+        cancelPreviousGesture = false;
+    }
 
-    // Show the pointer if needed.
-    if (mPointerGesture.currentGestureMode != PointerGesture::NEUTRAL
-            && mPointerGesture.currentGestureMode != PointerGesture::QUIET) {
-        mPointerController->unfade();
+    // Update the pointer presentation and spots.
+    if (mParameters.gestureMode == Parameters::GESTURE_MODE_SPOTS) {
+        mPointerController->setPresentation(PointerControllerInterface::PRESENTATION_SPOT);
+        if (finishPreviousGesture || cancelPreviousGesture) {
+            mPointerController->clearSpots();
+        }
+        mPointerController->setSpots(mPointerGesture.currentGestureCoords,
+                mPointerGesture.currentGestureIdToIndex,
+                mPointerGesture.currentGestureIdBits);
+    } else {
+        mPointerController->setPresentation(PointerControllerInterface::PRESENTATION_POINTER);
+    }
+
+    // Show or hide the pointer if needed.
+    switch (mPointerGesture.currentGestureMode) {
+    case PointerGesture::NEUTRAL:
+    case PointerGesture::QUIET:
+        if (mParameters.gestureMode == Parameters::GESTURE_MODE_SPOTS
+                && (mPointerGesture.lastGestureMode == PointerGesture::SWIPE
+                        || mPointerGesture.lastGestureMode == PointerGesture::FREEFORM)) {
+            // Remind the user of where the pointer is after finishing a gesture with spots.
+            mPointerController->unfade(PointerControllerInterface::TRANSITION_GRADUAL);
+        }
+        break;
+    case PointerGesture::TAP:
+    case PointerGesture::TAP_DRAG:
+    case PointerGesture::BUTTON_CLICK_OR_DRAG:
+    case PointerGesture::HOVER:
+    case PointerGesture::PRESS:
+        // Unfade the pointer when the current gesture manipulates the
+        // area directly under the pointer.
+        mPointerController->unfade(PointerControllerInterface::TRANSITION_IMMEDIATE);
+        break;
+    case PointerGesture::SWIPE:
+    case PointerGesture::FREEFORM:
+        // Fade the pointer when the current gesture manipulates a different
+        // area and there are spots to guide the user experience.
+        if (mParameters.gestureMode == Parameters::GESTURE_MODE_SPOTS) {
+            mPointerController->fade(PointerControllerInterface::TRANSITION_GRADUAL);
+        } else {
+            mPointerController->unfade(PointerControllerInterface::TRANSITION_IMMEDIATE);
+        }
+        break;
     }
 
     // Send events!
@@ -3620,9 +3739,10 @@
 #endif
 
         if (mPointerGesture.lastGestureMode == PointerGesture::TAP) {
-            if (when <= mPointerGesture.tapUpTime + TAP_DRAG_INTERVAL) {
+            if (when <= mPointerGesture.tapUpTime + mConfig.pointerGestureTapDragInterval) {
                 // The tap/drag timeout has not yet expired.
-                getContext()->requestTimeoutAtTime(mPointerGesture.tapUpTime + TAP_DRAG_INTERVAL);
+                getContext()->requestTimeoutAtTime(mPointerGesture.tapUpTime
+                        + mConfig.pointerGestureTapDragInterval);
             } else {
                 // The tap is finished.
 #if DEBUG_GESTURES
@@ -3634,11 +3754,7 @@
                 mPointerGesture.currentGestureMode = PointerGesture::NEUTRAL;
                 mPointerGesture.currentGestureIdBits.clear();
 
-                if (mParameters.gestureMode == Parameters::GESTURE_MODE_SPOTS) {
-                    mPointerGesture.spotGesture = PointerControllerInterface::SPOT_GESTURE_NEUTRAL;
-                    mPointerGesture.spotIdBits.clear();
-                    moveSpotsLocked();
-                }
+                mPointerGesture.pointerVelocityControl.reset();
                 return true;
             }
         }
@@ -3691,7 +3807,7 @@
     if (activeTouchId < 0) {
         mPointerGesture.resetQuietTime();
     } else {
-        isQuietTime = when < mPointerGesture.quietTime + QUIET_INTERVAL;
+        isQuietTime = when < mPointerGesture.quietTime + mConfig.pointerGestureQuietInterval;
         if (!isQuietTime) {
             if ((mPointerGesture.lastGestureMode == PointerGesture::PRESS
                     || mPointerGesture.lastGestureMode == PointerGesture::SWIPE
@@ -3719,20 +3835,18 @@
     if (isQuietTime) {
         // Case 1: Quiet time. (QUIET)
 #if DEBUG_GESTURES
-        LOGD("Gestures: QUIET for next %0.3fms",
-                (mPointerGesture.quietTime + QUIET_INTERVAL - when) * 0.000001f);
+        LOGD("Gestures: QUIET for next %0.3fms", (mPointerGesture.quietTime
+                + mConfig.pointerGestureQuietInterval - when) * 0.000001f);
 #endif
-        *outFinishPreviousGesture = true;
+        if (mPointerGesture.lastGestureMode != PointerGesture::QUIET) {
+            *outFinishPreviousGesture = true;
+        }
 
         mPointerGesture.activeGestureId = -1;
         mPointerGesture.currentGestureMode = PointerGesture::QUIET;
         mPointerGesture.currentGestureIdBits.clear();
 
-        if (mParameters.gestureMode == Parameters::GESTURE_MODE_SPOTS) {
-            mPointerGesture.spotGesture = PointerControllerInterface::SPOT_GESTURE_NEUTRAL;
-            mPointerGesture.spotIdBits.clear();
-            moveSpotsLocked();
-        }
+        mPointerGesture.pointerVelocityControl.reset();
     } else if (isPointerDown(mCurrentTouch.buttonState)) {
         // Case 2: Button is pressed. (BUTTON_CLICK_OR_DRAG)
         // The pointer follows the active touch point.
@@ -3759,46 +3873,48 @@
 
         // Switch pointers if needed.
         // Find the fastest pointer and follow it.
-        if (activeTouchId >= 0) {
-            if (mCurrentTouch.pointerCount > 1) {
-                int32_t bestId = -1;
-                float bestSpeed = DRAG_MIN_SWITCH_SPEED;
-                for (uint32_t i = 0; i < mCurrentTouch.pointerCount; i++) {
-                    uint32_t id = mCurrentTouch.pointers[i].id;
-                    float vx, vy;
-                    if (mPointerGesture.velocityTracker.getVelocity(id, &vx, &vy)) {
-                        float speed = hypotf(vx, vy);
-                        if (speed > bestSpeed) {
-                            bestId = id;
-                            bestSpeed = speed;
-                        }
+        if (activeTouchId >= 0 && mCurrentTouch.pointerCount > 1) {
+            int32_t bestId = -1;
+            float bestSpeed = mConfig.pointerGestureDragMinSwitchSpeed;
+            for (uint32_t i = 0; i < mCurrentTouch.pointerCount; i++) {
+                uint32_t id = mCurrentTouch.pointers[i].id;
+                float vx, vy;
+                if (mPointerGesture.velocityTracker.getVelocity(id, &vx, &vy)) {
+                    float speed = hypotf(vx, vy);
+                    if (speed > bestSpeed) {
+                        bestId = id;
+                        bestSpeed = speed;
                     }
                 }
-                if (bestId >= 0 && bestId != activeTouchId) {
-                    mPointerGesture.activeTouchId = activeTouchId = bestId;
-                    activeTouchChanged = true;
+            }
+            if (bestId >= 0 && bestId != activeTouchId) {
+                mPointerGesture.activeTouchId = activeTouchId = bestId;
+                activeTouchChanged = true;
 #if DEBUG_GESTURES
-                    LOGD("Gestures: BUTTON_CLICK_OR_DRAG switched pointers, "
-                            "bestId=%d, bestSpeed=%0.3f", bestId, bestSpeed);
+                LOGD("Gestures: BUTTON_CLICK_OR_DRAG switched pointers, "
+                        "bestId=%d, bestSpeed=%0.3f", bestId, bestSpeed);
 #endif
-                }
             }
+        }
 
-            if (mLastTouch.idBits.hasBit(activeTouchId)) {
-                const PointerData& currentPointer =
-                        mCurrentTouch.pointers[mCurrentTouch.idToIndex[activeTouchId]];
-                const PointerData& lastPointer =
-                        mLastTouch.pointers[mLastTouch.idToIndex[activeTouchId]];
-                float deltaX = (currentPointer.x - lastPointer.x)
-                        * mLocked.pointerGestureXMovementScale;
-                float deltaY = (currentPointer.y - lastPointer.y)
-                        * mLocked.pointerGestureYMovementScale;
+        if (activeTouchId >= 0 && mLastTouch.idBits.hasBit(activeTouchId)) {
+            const PointerData& currentPointer =
+                    mCurrentTouch.pointers[mCurrentTouch.idToIndex[activeTouchId]];
+            const PointerData& lastPointer =
+                    mLastTouch.pointers[mLastTouch.idToIndex[activeTouchId]];
+            float deltaX = (currentPointer.x - lastPointer.x)
+                    * mLocked.pointerGestureXMovementScale;
+            float deltaY = (currentPointer.y - lastPointer.y)
+                    * mLocked.pointerGestureYMovementScale;
 
-                // Move the pointer using a relative motion.
-                // When using spots, the click will occur at the position of the anchor
-                // spot and all other spots will move there.
-                mPointerController->move(deltaX, deltaY);
-            }
+            mPointerGesture.pointerVelocityControl.move(when, &deltaX, &deltaY);
+
+            // Move the pointer using a relative motion.
+            // When using spots, the click will occur at the position of the anchor
+            // spot and all other spots will move there.
+            mPointerController->move(deltaX, deltaY);
+        } else {
+            mPointerGesture.pointerVelocityControl.reset();
         }
 
         float x, y;
@@ -3816,49 +3932,30 @@
         mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, x);
         mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, y);
         mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 1.0f);
-
-        if (mParameters.gestureMode == Parameters::GESTURE_MODE_SPOTS) {
-            if (activeTouchId >= 0) {
-                // Collapse all spots into one point at the pointer location.
-                mPointerGesture.spotGesture = PointerControllerInterface::SPOT_GESTURE_BUTTON_DRAG;
-                mPointerGesture.spotIdBits.clear();
-                for (uint32_t i = 0; i < mCurrentTouch.pointerCount; i++) {
-                    uint32_t id = mCurrentTouch.pointers[i].id;
-                    mPointerGesture.spotIdBits.markBit(id);
-                    mPointerGesture.spotIdToIndex[id] = i;
-                    mPointerGesture.spotCoords[i] = mPointerGesture.currentGestureCoords[0];
-                }
-            } else {
-                // No fingers.  Generate a spot at the pointer location so the
-                // anchor appears to be pressed.
-                mPointerGesture.spotGesture = PointerControllerInterface::SPOT_GESTURE_BUTTON_CLICK;
-                mPointerGesture.spotIdBits.clear();
-                mPointerGesture.spotIdBits.markBit(0);
-                mPointerGesture.spotIdToIndex[0] = 0;
-                mPointerGesture.spotCoords[0] = mPointerGesture.currentGestureCoords[0];
-            }
-            moveSpotsLocked();
-        }
     } else if (mCurrentTouch.pointerCount == 0) {
         // Case 3. No fingers down and button is not pressed. (NEUTRAL)
-        *outFinishPreviousGesture = true;
+        if (mPointerGesture.lastGestureMode != PointerGesture::NEUTRAL) {
+            *outFinishPreviousGesture = true;
+        }
 
         // Watch for taps coming out of HOVER or TAP_DRAG mode.
+        // Checking for taps after TAP_DRAG allows us to detect double-taps.
         bool tapped = false;
         if ((mPointerGesture.lastGestureMode == PointerGesture::HOVER
                 || mPointerGesture.lastGestureMode == PointerGesture::TAP_DRAG)
                 && mLastTouch.pointerCount == 1) {
-            if (when <= mPointerGesture.tapDownTime + TAP_INTERVAL) {
+            if (when <= mPointerGesture.tapDownTime + mConfig.pointerGestureTapInterval) {
                 float x, y;
                 mPointerController->getPosition(&x, &y);
-                if (fabs(x - mPointerGesture.tapX) <= TAP_SLOP
-                        && fabs(y - mPointerGesture.tapY) <= TAP_SLOP) {
+                if (fabs(x - mPointerGesture.tapX) <= mConfig.pointerGestureTapSlop
+                        && fabs(y - mPointerGesture.tapY) <= mConfig.pointerGestureTapSlop) {
 #if DEBUG_GESTURES
                     LOGD("Gestures: TAP");
 #endif
 
                     mPointerGesture.tapUpTime = when;
-                    getContext()->requestTimeoutAtTime(when + TAP_DRAG_INTERVAL);
+                    getContext()->requestTimeoutAtTime(when
+                            + mConfig.pointerGestureTapDragInterval);
 
                     mPointerGesture.activeGestureId = 0;
                     mPointerGesture.currentGestureMode = PointerGesture::TAP;
@@ -3880,15 +3977,6 @@
                     mPointerGesture.currentGestureCoords[0].setAxisValue(
                             AMOTION_EVENT_AXIS_PRESSURE, 1.0f);
 
-                    if (mParameters.gestureMode == Parameters::GESTURE_MODE_SPOTS) {
-                        mPointerGesture.spotGesture = PointerControllerInterface::SPOT_GESTURE_TAP;
-                        mPointerGesture.spotIdBits.clear();
-                        mPointerGesture.spotIdBits.markBit(lastActiveTouchId);
-                        mPointerGesture.spotIdToIndex[lastActiveTouchId] = 0;
-                        mPointerGesture.spotCoords[0] = mPointerGesture.currentGestureCoords[0];
-                        moveSpotsLocked();
-                    }
-
                     tapped = true;
                 } else {
 #if DEBUG_GESTURES
@@ -3905,6 +3993,8 @@
             }
         }
 
+        mPointerGesture.pointerVelocityControl.reset();
+
         if (!tapped) {
 #if DEBUG_GESTURES
             LOGD("Gestures: NEUTRAL");
@@ -3912,12 +4002,6 @@
             mPointerGesture.activeGestureId = -1;
             mPointerGesture.currentGestureMode = PointerGesture::NEUTRAL;
             mPointerGesture.currentGestureIdBits.clear();
-
-            if (mParameters.gestureMode == Parameters::GESTURE_MODE_SPOTS) {
-                mPointerGesture.spotGesture = PointerControllerInterface::SPOT_GESTURE_NEUTRAL;
-                mPointerGesture.spotIdBits.clear();
-                moveSpotsLocked();
-            }
         }
     } else if (mCurrentTouch.pointerCount == 1) {
         // Case 4. Exactly one finger down, button is not pressed. (HOVER or TAP_DRAG)
@@ -3928,11 +4012,11 @@
 
         mPointerGesture.currentGestureMode = PointerGesture::HOVER;
         if (mPointerGesture.lastGestureMode == PointerGesture::TAP) {
-            if (when <= mPointerGesture.tapUpTime + TAP_DRAG_INTERVAL) {
+            if (when <= mPointerGesture.tapUpTime + mConfig.pointerGestureTapDragInterval) {
                 float x, y;
                 mPointerController->getPosition(&x, &y);
-                if (fabs(x - mPointerGesture.tapX) <= TAP_SLOP
-                        && fabs(y - mPointerGesture.tapY) <= TAP_SLOP) {
+                if (fabs(x - mPointerGesture.tapX) <= mConfig.pointerGestureTapSlop
+                        && fabs(y - mPointerGesture.tapY) <= mConfig.pointerGestureTapSlop) {
                     mPointerGesture.currentGestureMode = PointerGesture::TAP_DRAG;
                 } else {
 #if DEBUG_GESTURES
@@ -3961,9 +4045,13 @@
             float deltaY = (currentPointer.y - lastPointer.y)
                     * mLocked.pointerGestureYMovementScale;
 
+            mPointerGesture.pointerVelocityControl.move(when, &deltaX, &deltaY);
+
             // Move the pointer using a relative motion.
             // When using spots, the hover or drag will occur at the position of the anchor spot.
             mPointerController->move(deltaX, deltaY);
+        } else {
+            mPointerGesture.pointerVelocityControl.reset();
         }
 
         bool down;
@@ -3976,7 +4064,9 @@
 #if DEBUG_GESTURES
             LOGD("Gestures: HOVER");
 #endif
-            *outFinishPreviousGesture = true;
+            if (mPointerGesture.lastGestureMode != PointerGesture::HOVER) {
+                *outFinishPreviousGesture = true;
+            }
             mPointerGesture.activeGestureId = 0;
             down = false;
         }
@@ -4003,16 +4093,6 @@
             mPointerGesture.tapX = x;
             mPointerGesture.tapY = y;
         }
-
-        if (mParameters.gestureMode == Parameters::GESTURE_MODE_SPOTS) {
-            mPointerGesture.spotGesture = down ? PointerControllerInterface::SPOT_GESTURE_DRAG
-                    : PointerControllerInterface::SPOT_GESTURE_HOVER;
-            mPointerGesture.spotIdBits.clear();
-            mPointerGesture.spotIdBits.markBit(activeTouchId);
-            mPointerGesture.spotIdToIndex[activeTouchId] = 0;
-            mPointerGesture.spotCoords[0] = mPointerGesture.currentGestureCoords[0];
-            moveSpotsLocked();
-        }
     } else {
         // Case 5. At least two fingers down, button is not pressed. (PRESS, SWIPE or FREEFORM)
         // We need to provide feedback for each finger that goes down so we cannot wait
@@ -4029,128 +4109,165 @@
         // a decision to transition into SWIPE or FREEFORM mode accordingly.
         LOG_ASSERT(activeTouchId >= 0);
 
-        bool needReference = false;
-        bool settled = when >= mPointerGesture.firstTouchTime + MULTITOUCH_SETTLE_INTERVAL;
+        bool settled = when >= mPointerGesture.firstTouchTime
+                + mConfig.pointerGestureMultitouchSettleInterval;
         if (mPointerGesture.lastGestureMode != PointerGesture::PRESS
                 && mPointerGesture.lastGestureMode != PointerGesture::SWIPE
                 && mPointerGesture.lastGestureMode != PointerGesture::FREEFORM) {
             *outFinishPreviousGesture = true;
-            mPointerGesture.currentGestureMode = PointerGesture::PRESS;
-            mPointerGesture.activeGestureId = 0;
-
-            if (settled && mParameters.gestureMode == Parameters::GESTURE_MODE_SPOTS
-                    && mLastTouch.idBits.hasBit(mPointerGesture.activeTouchId)) {
-                // The spot is already visible and has settled, use it as the reference point
-                // for the gesture.  Other spots will be positioned relative to this one.
-#if DEBUG_GESTURES
-                LOGD("Gestures: Using active spot as reference for MULTITOUCH, "
-                        "settle time expired %0.3fms ago",
-                        (when - mPointerGesture.firstTouchTime - MULTITOUCH_SETTLE_INTERVAL)
-                                * 0.000001f);
-#endif
-                const PointerData& d = mLastTouch.pointers[mLastTouch.idToIndex[
-                        mPointerGesture.activeTouchId]];
-                mPointerGesture.referenceTouchX = d.x;
-                mPointerGesture.referenceTouchY = d.y;
-                const PointerCoords& c = mPointerGesture.spotCoords[mPointerGesture.spotIdToIndex[
-                        mPointerGesture.activeTouchId]];
-                mPointerGesture.referenceGestureX = c.getAxisValue(AMOTION_EVENT_AXIS_X);
-                mPointerGesture.referenceGestureY = c.getAxisValue(AMOTION_EVENT_AXIS_Y);
-            } else {
-#if DEBUG_GESTURES
-                LOGD("Gestures: Using centroid as reference for MULTITOUCH, "
-                        "settle time remaining %0.3fms",
-                        (mPointerGesture.firstTouchTime + MULTITOUCH_SETTLE_INTERVAL - when)
-                                * 0.000001f);
-#endif
-                needReference = true;
-            }
         } else if (!settled && mCurrentTouch.pointerCount > mLastTouch.pointerCount) {
             // Additional pointers have gone down but not yet settled.
             // Reset the gesture.
 #if DEBUG_GESTURES
             LOGD("Gestures: Resetting gesture since additional pointers went down for MULTITOUCH, "
-                    "settle time remaining %0.3fms",
-                    (mPointerGesture.firstTouchTime + MULTITOUCH_SETTLE_INTERVAL - when)
+                    "settle time remaining %0.3fms", (mPointerGesture.firstTouchTime
+                            + mConfig.pointerGestureMultitouchSettleInterval - when)
                             * 0.000001f);
 #endif
             *outCancelPreviousGesture = true;
-            mPointerGesture.currentGestureMode = PointerGesture::PRESS;
-            mPointerGesture.activeGestureId = 0;
         } else {
             // Continue previous gesture.
             mPointerGesture.currentGestureMode = mPointerGesture.lastGestureMode;
         }
 
-        if (needReference) {
+        if (*outFinishPreviousGesture || *outCancelPreviousGesture) {
+            mPointerGesture.currentGestureMode = PointerGesture::PRESS;
+            mPointerGesture.activeGestureId = 0;
+            mPointerGesture.referenceIdBits.clear();
+            mPointerGesture.pointerVelocityControl.reset();
+
             // Use the centroid and pointer location as the reference points for the gesture.
+#if DEBUG_GESTURES
+            LOGD("Gestures: Using centroid as reference for MULTITOUCH, "
+                    "settle time remaining %0.3fms", (mPointerGesture.firstTouchTime
+                            + mConfig.pointerGestureMultitouchSettleInterval - when)
+                            * 0.000001f);
+#endif
             mCurrentTouch.getCentroid(&mPointerGesture.referenceTouchX,
                     &mPointerGesture.referenceTouchY);
             mPointerController->getPosition(&mPointerGesture.referenceGestureX,
                     &mPointerGesture.referenceGestureY);
         }
 
-        if (mPointerGesture.currentGestureMode == PointerGesture::PRESS) {
-            float d;
-            if (mCurrentTouch.pointerCount > 2) {
-                // There are more than two pointers, switch to FREEFORM.
-#if DEBUG_GESTURES
-                LOGD("Gestures: PRESS transitioned to FREEFORM, number of pointers %d > 2",
-                        mCurrentTouch.pointerCount);
-#endif
-                *outCancelPreviousGesture = true;
-                mPointerGesture.currentGestureMode = PointerGesture::FREEFORM;
-            } else if (((d = distance(
-                    mCurrentTouch.pointers[0].x, mCurrentTouch.pointers[0].y,
-                    mCurrentTouch.pointers[1].x, mCurrentTouch.pointers[1].y))
-                            > mLocked.pointerGestureMaxSwipeWidth)) {
-                // There are two pointers but they are too far apart, switch to FREEFORM.
-#if DEBUG_GESTURES
-                LOGD("Gestures: PRESS transitioned to FREEFORM, distance %0.3f > %0.3f",
-                        d, mLocked.pointerGestureMaxSwipeWidth);
-#endif
-                *outCancelPreviousGesture = true;
-                mPointerGesture.currentGestureMode = PointerGesture::FREEFORM;
+        // Clear the reference deltas for fingers not yet included in the reference calculation.
+        for (BitSet32 idBits(mCurrentTouch.idBits.value & ~mPointerGesture.referenceIdBits.value);
+                !idBits.isEmpty(); ) {
+            uint32_t id = idBits.firstMarkedBit();
+            idBits.clearBit(id);
+
+            mPointerGesture.referenceDeltas[id].dx = 0;
+            mPointerGesture.referenceDeltas[id].dy = 0;
+        }
+        mPointerGesture.referenceIdBits = mCurrentTouch.idBits;
+
+        // Add delta for all fingers and calculate a common movement delta.
+        float commonDeltaX = 0, commonDeltaY = 0;
+        BitSet32 commonIdBits(mLastTouch.idBits.value & mCurrentTouch.idBits.value);
+        for (BitSet32 idBits(commonIdBits); !idBits.isEmpty(); ) {
+            bool first = (idBits == commonIdBits);
+            uint32_t id = idBits.firstMarkedBit();
+            idBits.clearBit(id);
+
+            const PointerData& cpd = mCurrentTouch.pointers[mCurrentTouch.idToIndex[id]];
+            const PointerData& lpd = mLastTouch.pointers[mLastTouch.idToIndex[id]];
+            PointerGesture::Delta& delta = mPointerGesture.referenceDeltas[id];
+            delta.dx += cpd.x - lpd.x;
+            delta.dy += cpd.y - lpd.y;
+
+            if (first) {
+                commonDeltaX = delta.dx;
+                commonDeltaY = delta.dy;
             } else {
-                // There are two pointers.  Wait for both pointers to start moving
-                // before deciding whether this is a SWIPE or FREEFORM gesture.
-                uint32_t id1 = mCurrentTouch.pointers[0].id;
-                uint32_t id2 = mCurrentTouch.pointers[1].id;
+                commonDeltaX = calculateCommonVector(commonDeltaX, delta.dx);
+                commonDeltaY = calculateCommonVector(commonDeltaY, delta.dy);
+            }
+        }
 
-                float vx1, vy1, vx2, vy2;
-                mPointerGesture.velocityTracker.getVelocity(id1, &vx1, &vy1);
-                mPointerGesture.velocityTracker.getVelocity(id2, &vx2, &vy2);
+        // Consider transitions from PRESS to SWIPE or MULTITOUCH.
+        if (mPointerGesture.currentGestureMode == PointerGesture::PRESS) {
+            float dist[MAX_POINTER_ID + 1];
+            int32_t distOverThreshold = 0;
+            for (BitSet32 idBits(mPointerGesture.referenceIdBits); !idBits.isEmpty(); ) {
+                uint32_t id = idBits.firstMarkedBit();
+                idBits.clearBit(id);
 
-                float speed1 = hypotf(vx1, vy1);
-                float speed2 = hypotf(vx2, vy2);
-                if (speed1 >= MULTITOUCH_MIN_SPEED && speed2 >= MULTITOUCH_MIN_SPEED) {
-                    // Calculate the dot product of the velocity vectors.
-                    // When the vectors are oriented in approximately the same direction,
-                    // the angle betweeen them is near zero and the cosine of the angle
-                    // approches 1.0.  Recall that dot(v1, v2) = cos(angle) * mag(v1) * mag(v2).
-                    float dot = vx1 * vx2 + vy1 * vy2;
-                    float cosine = dot / (speed1 * speed2); // denominator always > 0
-                    if (cosine >= SWIPE_TRANSITION_ANGLE_COSINE) {
-                        // Pointers are moving in the same direction.  Switch to SWIPE.
+                PointerGesture::Delta& delta = mPointerGesture.referenceDeltas[id];
+                dist[id] = hypotf(delta.dx * mLocked.pointerGestureXZoomScale,
+                        delta.dy * mLocked.pointerGestureYZoomScale);
+                if (dist[id] > mConfig.pointerGestureMultitouchMinDistance) {
+                    distOverThreshold += 1;
+                }
+            }
+
+            // Only transition when at least two pointers have moved further than
+            // the minimum distance threshold.
+            if (distOverThreshold >= 2) {
+                float d;
+                if (mCurrentTouch.pointerCount > 2) {
+                    // There are more than two pointers, switch to FREEFORM.
 #if DEBUG_GESTURES
-                        LOGD("Gestures: PRESS transitioned to SWIPE, "
-                                "speed1 %0.3f >= %0.3f, speed2 %0.3f >= %0.3f, "
-                                "cosine %0.3f >= %0.3f",
-                                speed1, MULTITOUCH_MIN_SPEED, speed2, MULTITOUCH_MIN_SPEED,
-                                cosine, SWIPE_TRANSITION_ANGLE_COSINE);
+                    LOGD("Gestures: PRESS transitioned to FREEFORM, number of pointers %d > 2",
+                            mCurrentTouch.pointerCount);
 #endif
-                        mPointerGesture.currentGestureMode = PointerGesture::SWIPE;
-                    } else {
-                        // Pointers are moving in different directions.  Switch to FREEFORM.
+                    *outCancelPreviousGesture = true;
+                    mPointerGesture.currentGestureMode = PointerGesture::FREEFORM;
+                } else if (((d = distance(
+                        mCurrentTouch.pointers[0].x, mCurrentTouch.pointers[0].y,
+                        mCurrentTouch.pointers[1].x, mCurrentTouch.pointers[1].y))
+                                > mLocked.pointerGestureMaxSwipeWidth)) {
+                    // There are two pointers but they are too far apart for a SWIPE,
+                    // switch to FREEFORM.
 #if DEBUG_GESTURES
-                        LOGD("Gestures: PRESS transitioned to FREEFORM, "
-                                "speed1 %0.3f >= %0.3f, speed2 %0.3f >= %0.3f, "
-                                "cosine %0.3f < %0.3f",
-                                speed1, MULTITOUCH_MIN_SPEED, speed2, MULTITOUCH_MIN_SPEED,
-                                cosine, SWIPE_TRANSITION_ANGLE_COSINE);
+                    LOGD("Gestures: PRESS transitioned to FREEFORM, distance %0.3f > %0.3f",
+                            d, mLocked.pointerGestureMaxSwipeWidth);
 #endif
-                        *outCancelPreviousGesture = true;
-                        mPointerGesture.currentGestureMode = PointerGesture::FREEFORM;
+                    *outCancelPreviousGesture = true;
+                    mPointerGesture.currentGestureMode = PointerGesture::FREEFORM;
+                } else {
+                    // There are two pointers.  Wait for both pointers to start moving
+                    // before deciding whether this is a SWIPE or FREEFORM gesture.
+                    uint32_t id1 = mCurrentTouch.pointers[0].id;
+                    uint32_t id2 = mCurrentTouch.pointers[1].id;
+                    float dist1 = dist[id1];
+                    float dist2 = dist[id2];
+                    if (dist1 >= mConfig.pointerGestureMultitouchMinDistance
+                            && dist2 >= mConfig.pointerGestureMultitouchMinDistance) {
+                        // Calculate the dot product of the displacement vectors.
+                        // When the vectors are oriented in approximately the same direction,
+                        // the angle betweeen them is near zero and the cosine of the angle
+                        // approches 1.0.  Recall that dot(v1, v2) = cos(angle) * mag(v1) * mag(v2).
+                        PointerGesture::Delta& delta1 = mPointerGesture.referenceDeltas[id1];
+                        PointerGesture::Delta& delta2 = mPointerGesture.referenceDeltas[id2];
+                        float dx1 = delta1.dx * mLocked.pointerGestureXZoomScale;
+                        float dy1 = delta1.dy * mLocked.pointerGestureYZoomScale;
+                        float dx2 = delta2.dx * mLocked.pointerGestureXZoomScale;
+                        float dy2 = delta2.dy * mLocked.pointerGestureYZoomScale;
+                        float dot = dx1 * dx2 + dy1 * dy2;
+                        float cosine = dot / (dist1 * dist2); // denominator always > 0
+                        if (cosine >= mConfig.pointerGestureSwipeTransitionAngleCosine) {
+                            // Pointers are moving in the same direction.  Switch to SWIPE.
+#if DEBUG_GESTURES
+                            LOGD("Gestures: PRESS transitioned to SWIPE, "
+                                    "dist1 %0.3f >= %0.3f, dist2 %0.3f >= %0.3f, "
+                                    "cosine %0.3f >= %0.3f",
+                                    dist1, mConfig.pointerGestureMultitouchMinDistance,
+                                    dist2, mConfig.pointerGestureMultitouchMinDistance,
+                                    cosine, mConfig.pointerGestureSwipeTransitionAngleCosine);
+#endif
+                            mPointerGesture.currentGestureMode = PointerGesture::SWIPE;
+                        } else {
+                            // Pointers are moving in different directions.  Switch to FREEFORM.
+#if DEBUG_GESTURES
+                            LOGD("Gestures: PRESS transitioned to FREEFORM, "
+                                    "dist1 %0.3f >= %0.3f, dist2 %0.3f >= %0.3f, "
+                                    "cosine %0.3f < %0.3f",
+                                    dist1, mConfig.pointerGestureMultitouchMinDistance,
+                                    dist2, mConfig.pointerGestureMultitouchMinDistance,
+                                    cosine, mConfig.pointerGestureSwipeTransitionAngleCosine);
+#endif
+                            *outCancelPreviousGesture = true;
+                            mPointerGesture.currentGestureMode = PointerGesture::FREEFORM;
+                        }
                     }
                 }
             }
@@ -4167,40 +4284,28 @@
             }
         }
 
-        // Move the reference points based on the overall group motion of the fingers.
-        // The objective is to calculate a vector delta that is common to the movement
-        // of all fingers.
-        BitSet32 commonIdBits(mLastTouch.idBits.value & mCurrentTouch.idBits.value);
-        if (!commonIdBits.isEmpty()) {
-            float commonDeltaX = 0, commonDeltaY = 0;
-            for (BitSet32 idBits(commonIdBits); !idBits.isEmpty(); ) {
-                bool first = (idBits == commonIdBits);
+        // Move the reference points based on the overall group motion of the fingers
+        // except in PRESS mode while waiting for a transition to occur.
+        if (mPointerGesture.currentGestureMode != PointerGesture::PRESS
+                && (commonDeltaX || commonDeltaY)) {
+            for (BitSet32 idBits(mPointerGesture.referenceIdBits); !idBits.isEmpty(); ) {
                 uint32_t id = idBits.firstMarkedBit();
                 idBits.clearBit(id);
 
-                const PointerData& cpd = mCurrentTouch.pointers[mCurrentTouch.idToIndex[id]];
-                const PointerData& lpd = mLastTouch.pointers[mLastTouch.idToIndex[id]];
-                float deltaX = cpd.x - lpd.x;
-                float deltaY = cpd.y - lpd.y;
-
-                if (first) {
-                    commonDeltaX = deltaX;
-                    commonDeltaY = deltaY;
-                } else {
-                    commonDeltaX = calculateCommonVector(commonDeltaX, deltaX);
-                    commonDeltaY = calculateCommonVector(commonDeltaY, deltaY);
-                }
+                PointerGesture::Delta& delta = mPointerGesture.referenceDeltas[id];
+                delta.dx = 0;
+                delta.dy = 0;
             }
 
             mPointerGesture.referenceTouchX += commonDeltaX;
             mPointerGesture.referenceTouchY += commonDeltaY;
-            mPointerGesture.referenceGestureX +=
-                    commonDeltaX * mLocked.pointerGestureXMovementScale;
-            mPointerGesture.referenceGestureY +=
-                    commonDeltaY * mLocked.pointerGestureYMovementScale;
-            clampPositionUsingPointerBounds(mPointerController,
-                    &mPointerGesture.referenceGestureX,
-                    &mPointerGesture.referenceGestureY);
+
+            commonDeltaX *= mLocked.pointerGestureXMovementScale;
+            commonDeltaY *= mLocked.pointerGestureYMovementScale;
+            mPointerGesture.pointerVelocityControl.move(when, &commonDeltaX, &commonDeltaY);
+
+            mPointerGesture.referenceGestureX += commonDeltaX;
+            mPointerGesture.referenceGestureY += commonDeltaY;
         }
 
         // Report gestures.
@@ -4226,10 +4331,6 @@
             mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y,
                     mPointerGesture.referenceGestureY);
             mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 1.0f);
-
-            if (mParameters.gestureMode == Parameters::GESTURE_MODE_SPOTS) {
-                mPointerGesture.spotGesture = PointerControllerInterface::SPOT_GESTURE_PRESS;
-            }
         } else if (mPointerGesture.currentGestureMode == PointerGesture::SWIPE) {
             // SWIPE mode.
 #if DEBUG_GESTURES
@@ -4252,10 +4353,6 @@
             mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y,
                     mPointerGesture.referenceGestureY);
             mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 1.0f);
-
-            if (mParameters.gestureMode == Parameters::GESTURE_MODE_SPOTS) {
-                mPointerGesture.spotGesture = PointerControllerInterface::SPOT_GESTURE_SWIPE;
-            }
         } else if (mPointerGesture.currentGestureMode == PointerGesture::FREEFORM) {
             // FREEFORM mode.
 #if DEBUG_GESTURES
@@ -4357,33 +4454,6 @@
                         "activeGestureId=%d", mPointerGesture.activeGestureId);
 #endif
             }
-
-            if (mParameters.gestureMode == Parameters::GESTURE_MODE_SPOTS) {
-                mPointerGesture.spotGesture = PointerControllerInterface::SPOT_GESTURE_FREEFORM;
-            }
-        }
-
-        // Update spot locations for PRESS, SWIPE and FREEFORM.
-        // We use the same calculation as we do to calculate the gesture pointers
-        // for FREEFORM so that the spots smoothly track gestures.
-        if (mParameters.gestureMode == Parameters::GESTURE_MODE_SPOTS) {
-            mPointerGesture.spotIdBits.clear();
-            for (uint32_t i = 0; i < mCurrentTouch.pointerCount; i++) {
-                uint32_t id = mCurrentTouch.pointers[i].id;
-                mPointerGesture.spotIdBits.markBit(id);
-                mPointerGesture.spotIdToIndex[id] = i;
-
-                float x = (mCurrentTouch.pointers[i].x - mPointerGesture.referenceTouchX)
-                        * mLocked.pointerGestureXZoomScale + mPointerGesture.referenceGestureX;
-                float y = (mCurrentTouch.pointers[i].y - mPointerGesture.referenceTouchY)
-                        * mLocked.pointerGestureYZoomScale + mPointerGesture.referenceGestureY;
-
-                mPointerGesture.spotCoords[i].clear();
-                mPointerGesture.spotCoords[i].setAxisValue(AMOTION_EVENT_AXIS_X, x);
-                mPointerGesture.spotCoords[i].setAxisValue(AMOTION_EVENT_AXIS_Y, y);
-                mPointerGesture.spotCoords[i].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 1.0f);
-            }
-            moveSpotsLocked();
         }
     }
 
@@ -4426,11 +4496,6 @@
     return true;
 }
 
-void TouchInputMapper::moveSpotsLocked() {
-    mPointerController->setSpots(mPointerGesture.spotGesture,
-            mPointerGesture.spotCoords, mPointerGesture.spotIdToIndex, mPointerGesture.spotIdBits);
-}
-
 void TouchInputMapper::dispatchMotion(nsecs_t when, uint32_t policyFlags, uint32_t source,
         int32_t action, int32_t flags, int32_t metaState, int32_t buttonState, int32_t edgeFlags,
         const PointerProperties* properties, const PointerCoords* coords,
@@ -4508,7 +4573,7 @@
     { // acquire lock
         AutoMutex _l(mLock);
         if (mPointerController != NULL) {
-            mPointerController->fade();
+            mPointerController->fade(PointerControllerInterface::TRANSITION_GRADUAL);
         }
     } // release lock
 }
@@ -5303,7 +5368,8 @@
 }
 
 void MultiTouchInputMapper::clearState() {
-    mAccumulator.clear(mSlotCount);
+    mAccumulator.clearSlots(mSlotCount);
+    mAccumulator.clearButtons();
     mButtonState = 0;
 }
 
@@ -5337,13 +5403,13 @@
         }
 
         if (mAccumulator.currentSlot < 0 || size_t(mAccumulator.currentSlot) >= mSlotCount) {
-            if (newSlot) {
 #if DEBUG_POINTERS
+            if (newSlot) {
                 LOGW("MultiTouch device %s emitted invalid slot index %d but it "
                         "should be between 0 and %d; ignoring this slot.",
                         getDeviceName().string(), mAccumulator.currentSlot, mSlotCount);
-#endif
             }
+#endif
             break;
         }
 
@@ -5546,7 +5612,10 @@
 
     syncTouch(when, havePointerIds);
 
-    mAccumulator.clear(mUsingSlotsProtocol ? 0 : mSlotCount);
+    if (!mUsingSlotsProtocol) {
+        mAccumulator.clearSlots(mSlotCount);
+    }
+    mAccumulator.clearButtons();
 }
 
 void MultiTouchInputMapper::configureRawAxes() {
@@ -5640,91 +5709,94 @@
         dump.appendFormat(INDENT4 "  scale=%0.5f, offset=%0.5f, "
                 "highScale=%0.5f, highOffset=%0.5f\n",
                 axis.scale, axis.offset, axis.highScale, axis.highOffset);
-        dump.appendFormat(INDENT4 "  rawAxis=%d, rawMin=%d, rawMax=%d, rawFlat=%d, rawFuzz=%d\n",
+        dump.appendFormat(INDENT4 "  rawAxis=%d, rawMin=%d, rawMax=%d, "
+                "rawFlat=%d, rawFuzz=%d, rawResolution=%d\n",
                 mAxes.keyAt(i), axis.rawAxisInfo.minValue, axis.rawAxisInfo.maxValue,
-                axis.rawAxisInfo.flat, axis.rawAxisInfo.fuzz);
+                axis.rawAxisInfo.flat, axis.rawAxisInfo.fuzz, axis.rawAxisInfo.resolution);
     }
 }
 
-void JoystickInputMapper::configure() {
-    InputMapper::configure();
+void JoystickInputMapper::configure(const InputReaderConfiguration* config, uint32_t changes) {
+    InputMapper::configure(config, changes);
 
-    // Collect all axes.
-    for (int32_t abs = 0; abs <= ABS_MAX; abs++) {
-        RawAbsoluteAxisInfo rawAxisInfo;
-        getEventHub()->getAbsoluteAxisInfo(getDeviceId(), abs, &rawAxisInfo);
-        if (rawAxisInfo.valid) {
-            // Map axis.
-            AxisInfo axisInfo;
-            bool explicitlyMapped = !getEventHub()->mapAxis(getDeviceId(), abs, &axisInfo);
-            if (!explicitlyMapped) {
-                // Axis is not explicitly mapped, will choose a generic axis later.
-                axisInfo.mode = AxisInfo::MODE_NORMAL;
-                axisInfo.axis = -1;
+    if (!changes) { // first time only
+        // Collect all axes.
+        for (int32_t abs = 0; abs <= ABS_MAX; abs++) {
+            RawAbsoluteAxisInfo rawAxisInfo;
+            getEventHub()->getAbsoluteAxisInfo(getDeviceId(), abs, &rawAxisInfo);
+            if (rawAxisInfo.valid) {
+                // Map axis.
+                AxisInfo axisInfo;
+                bool explicitlyMapped = !getEventHub()->mapAxis(getDeviceId(), abs, &axisInfo);
+                if (!explicitlyMapped) {
+                    // Axis is not explicitly mapped, will choose a generic axis later.
+                    axisInfo.mode = AxisInfo::MODE_NORMAL;
+                    axisInfo.axis = -1;
+                }
+
+                // Apply flat override.
+                int32_t rawFlat = axisInfo.flatOverride < 0
+                        ? rawAxisInfo.flat : axisInfo.flatOverride;
+
+                // Calculate scaling factors and limits.
+                Axis axis;
+                if (axisInfo.mode == AxisInfo::MODE_SPLIT) {
+                    float scale = 1.0f / (axisInfo.splitValue - rawAxisInfo.minValue);
+                    float highScale = 1.0f / (rawAxisInfo.maxValue - axisInfo.splitValue);
+                    axis.initialize(rawAxisInfo, axisInfo, explicitlyMapped,
+                            scale, 0.0f, highScale, 0.0f,
+                            0.0f, 1.0f, rawFlat * scale, rawAxisInfo.fuzz * scale);
+                } else if (isCenteredAxis(axisInfo.axis)) {
+                    float scale = 2.0f / (rawAxisInfo.maxValue - rawAxisInfo.minValue);
+                    float offset = avg(rawAxisInfo.minValue, rawAxisInfo.maxValue) * -scale;
+                    axis.initialize(rawAxisInfo, axisInfo, explicitlyMapped,
+                            scale, offset, scale, offset,
+                            -1.0f, 1.0f, rawFlat * scale, rawAxisInfo.fuzz * scale);
+                } else {
+                    float scale = 1.0f / (rawAxisInfo.maxValue - rawAxisInfo.minValue);
+                    axis.initialize(rawAxisInfo, axisInfo, explicitlyMapped,
+                            scale, 0.0f, scale, 0.0f,
+                            0.0f, 1.0f, rawFlat * scale, rawAxisInfo.fuzz * scale);
+                }
+
+                // To eliminate noise while the joystick is at rest, filter out small variations
+                // in axis values up front.
+                axis.filter = axis.flat * 0.25f;
+
+                mAxes.add(abs, axis);
             }
-
-            // Apply flat override.
-            int32_t rawFlat = axisInfo.flatOverride < 0
-                    ? rawAxisInfo.flat : axisInfo.flatOverride;
-
-            // Calculate scaling factors and limits.
-            Axis axis;
-            if (axisInfo.mode == AxisInfo::MODE_SPLIT) {
-                float scale = 1.0f / (axisInfo.splitValue - rawAxisInfo.minValue);
-                float highScale = 1.0f / (rawAxisInfo.maxValue - axisInfo.splitValue);
-                axis.initialize(rawAxisInfo, axisInfo, explicitlyMapped,
-                        scale, 0.0f, highScale, 0.0f,
-                        0.0f, 1.0f, rawFlat * scale, rawAxisInfo.fuzz * scale);
-            } else if (isCenteredAxis(axisInfo.axis)) {
-                float scale = 2.0f / (rawAxisInfo.maxValue - rawAxisInfo.minValue);
-                float offset = avg(rawAxisInfo.minValue, rawAxisInfo.maxValue) * -scale;
-                axis.initialize(rawAxisInfo, axisInfo, explicitlyMapped,
-                        scale, offset, scale, offset,
-                        -1.0f, 1.0f, rawFlat * scale, rawAxisInfo.fuzz * scale);
-            } else {
-                float scale = 1.0f / (rawAxisInfo.maxValue - rawAxisInfo.minValue);
-                axis.initialize(rawAxisInfo, axisInfo, explicitlyMapped,
-                        scale, 0.0f, scale, 0.0f,
-                        0.0f, 1.0f, rawFlat * scale, rawAxisInfo.fuzz * scale);
-            }
-
-            // To eliminate noise while the joystick is at rest, filter out small variations
-            // in axis values up front.
-            axis.filter = axis.flat * 0.25f;
-
-            mAxes.add(abs, axis);
         }
-    }
 
-    // If there are too many axes, start dropping them.
-    // Prefer to keep explicitly mapped axes.
-    if (mAxes.size() > PointerCoords::MAX_AXES) {
-        LOGI("Joystick '%s' has %d axes but the framework only supports a maximum of %d.",
-                getDeviceName().string(), mAxes.size(), PointerCoords::MAX_AXES);
-        pruneAxes(true);
-        pruneAxes(false);
-    }
+        // If there are too many axes, start dropping them.
+        // Prefer to keep explicitly mapped axes.
+        if (mAxes.size() > PointerCoords::MAX_AXES) {
+            LOGI("Joystick '%s' has %d axes but the framework only supports a maximum of %d.",
+                    getDeviceName().string(), mAxes.size(), PointerCoords::MAX_AXES);
+            pruneAxes(true);
+            pruneAxes(false);
+        }
 
-    // Assign generic axis ids to remaining axes.
-    int32_t nextGenericAxisId = AMOTION_EVENT_AXIS_GENERIC_1;
-    size_t numAxes = mAxes.size();
-    for (size_t i = 0; i < numAxes; i++) {
-        Axis& axis = mAxes.editValueAt(i);
-        if (axis.axisInfo.axis < 0) {
-            while (nextGenericAxisId <= AMOTION_EVENT_AXIS_GENERIC_16
-                    && haveAxis(nextGenericAxisId)) {
-                nextGenericAxisId += 1;
-            }
+        // Assign generic axis ids to remaining axes.
+        int32_t nextGenericAxisId = AMOTION_EVENT_AXIS_GENERIC_1;
+        size_t numAxes = mAxes.size();
+        for (size_t i = 0; i < numAxes; i++) {
+            Axis& axis = mAxes.editValueAt(i);
+            if (axis.axisInfo.axis < 0) {
+                while (nextGenericAxisId <= AMOTION_EVENT_AXIS_GENERIC_16
+                        && haveAxis(nextGenericAxisId)) {
+                    nextGenericAxisId += 1;
+                }
 
-            if (nextGenericAxisId <= AMOTION_EVENT_AXIS_GENERIC_16) {
-                axis.axisInfo.axis = nextGenericAxisId;
-                nextGenericAxisId += 1;
-            } else {
-                LOGI("Ignoring joystick '%s' axis %d because all of the generic axis ids "
-                        "have already been assigned to other axes.",
-                        getDeviceName().string(), mAxes.keyAt(i));
-                mAxes.removeItemsAt(i--);
-                numAxes -= 1;
+                if (nextGenericAxisId <= AMOTION_EVENT_AXIS_GENERIC_16) {
+                    axis.axisInfo.axis = nextGenericAxisId;
+                    nextGenericAxisId += 1;
+                } else {
+                    LOGI("Ignoring joystick '%s' axis %d because all of the generic axis ids "
+                            "have already been assigned to other axes.",
+                            getDeviceName().string(), mAxes.keyAt(i));
+                    mAxes.removeItemsAt(i--);
+                    numAxes -= 1;
+                }
             }
         }
     }
diff --git a/services/input/InputReader.h b/services/input/InputReader.h
index 85338b6..288ff4e 100644
--- a/services/input/InputReader.h
+++ b/services/input/InputReader.h
@@ -40,6 +40,133 @@
 
 
 /*
+ * Input reader configuration.
+ *
+ * Specifies various options that modify the behavior of the input reader.
+ */
+struct InputReaderConfiguration {
+    // Describes changes that have occurred.
+    enum {
+        // The pointer speed changed.
+        CHANGE_POINTER_SPEED = 1 << 0,
+
+        // The pointer gesture control changed.
+        CHANGE_POINTER_GESTURE_ENABLEMENT = 1 << 1,
+
+        // All devices must be reopened.
+        CHANGE_MUST_REOPEN = 1 << 31,
+    };
+
+    // Determines whether to turn on some hacks we have to improve the touch interaction with a
+    // certain device whose screen currently is not all that good.
+    bool filterTouchEvents;
+
+    // Determines whether to turn on some hacks to improve touch interaction with another device
+    // where touch coordinate data can get corrupted.
+    bool filterJumpyTouchEvents;
+
+    // Gets the amount of time to disable virtual keys after the screen is touched
+    // in order to filter out accidental virtual key presses due to swiping gestures
+    // or taps near the edge of the display.  May be 0 to disable the feature.
+    nsecs_t virtualKeyQuietTime;
+
+    // The excluded device names for the platform.
+    // Devices with these names will be ignored.
+    Vector<String8> excludedDeviceNames;
+
+    // Velocity control parameters for mouse pointer movements.
+    VelocityControlParameters pointerVelocityControlParameters;
+
+    // Velocity control parameters for mouse wheel movements.
+    VelocityControlParameters wheelVelocityControlParameters;
+
+    // True if pointer gestures are enabled.
+    bool pointerGesturesEnabled;
+
+    // Quiet time between certain pointer gesture transitions.
+    // Time to allow for all fingers or buttons to settle into a stable state before
+    // starting a new gesture.
+    nsecs_t pointerGestureQuietInterval;
+
+    // The minimum speed that a pointer must travel for us to consider switching the active
+    // touch pointer to it during a drag.  This threshold is set to avoid switching due
+    // to noise from a finger resting on the touch pad (perhaps just pressing it down).
+    float pointerGestureDragMinSwitchSpeed; // in pixels per second
+
+    // Tap gesture delay time.
+    // The time between down and up must be less than this to be considered a tap.
+    nsecs_t pointerGestureTapInterval;
+
+    // Tap drag gesture delay time.
+    // The time between the previous tap's up and the next down must be less than
+    // this to be considered a drag.  Otherwise, the previous tap is finished and a
+    // new tap begins.
+    //
+    // Note that the previous tap will be held down for this entire duration so this
+    // interval must be shorter than the long press timeout.
+    nsecs_t pointerGestureTapDragInterval;
+
+    // The distance in pixels that the pointer is allowed to move from initial down
+    // to up and still be called a tap.
+    float pointerGestureTapSlop; // in pixels
+
+    // Time after the first touch points go down to settle on an initial centroid.
+    // This is intended to be enough time to handle cases where the user puts down two
+    // fingers at almost but not quite exactly the same time.
+    nsecs_t pointerGestureMultitouchSettleInterval;
+
+    // The transition from PRESS to SWIPE or FREEFORM gesture mode is made when
+    // at least two pointers have moved at least this far from their starting place.
+    float pointerGestureMultitouchMinDistance; // in pixels
+
+    // The transition from PRESS to SWIPE gesture mode can only occur when the
+    // cosine of the angle between the two vectors is greater than or equal to than this value
+    // which indicates that the vectors are oriented in the same direction.
+    // When the vectors are oriented in the exactly same direction, the cosine is 1.0.
+    // (In exactly opposite directions, the cosine is -1.0.)
+    float pointerGestureSwipeTransitionAngleCosine;
+
+    // The transition from PRESS to SWIPE gesture mode can only occur when the
+    // fingers are no more than this far apart relative to the diagonal size of
+    // the touch pad.  For example, a ratio of 0.5 means that the fingers must be
+    // no more than half the diagonal size of the touch pad apart.
+    float pointerGestureSwipeMaxWidthRatio;
+
+    // The gesture movement speed factor relative to the size of the display.
+    // Movement speed applies when the fingers are moving in the same direction.
+    // Without acceleration, a full swipe of the touch pad diagonal in movement mode
+    // will cover this portion of the display diagonal.
+    float pointerGestureMovementSpeedRatio;
+
+    // The gesture zoom speed factor relative to the size of the display.
+    // Zoom speed applies when the fingers are mostly moving relative to each other
+    // to execute a scale gesture or similar.
+    // Without acceleration, a full swipe of the touch pad diagonal in zoom mode
+    // will cover this portion of the display diagonal.
+    float pointerGestureZoomSpeedRatio;
+
+    InputReaderConfiguration() :
+            filterTouchEvents(false),
+            filterJumpyTouchEvents(false),
+            virtualKeyQuietTime(0),
+            pointerVelocityControlParameters(1.0f, 500.0f, 3000.0f, 3.0f),
+            wheelVelocityControlParameters(1.0f, 15.0f, 50.0f, 4.0f),
+            pointerGesturesEnabled(true),
+            pointerGestureQuietInterval(100 * 1000000LL), // 100 ms
+            pointerGestureDragMinSwitchSpeed(50), // 50 pixels per second
+            pointerGestureTapInterval(150 * 1000000LL), // 150 ms
+            pointerGestureTapDragInterval(150 * 1000000LL), // 150 ms
+            pointerGestureTapSlop(10.0f), // 10 pixels
+            pointerGestureMultitouchSettleInterval(100 * 1000000LL), // 100 ms
+            pointerGestureMultitouchMinDistance(15), // 15 pixels
+            pointerGestureSwipeTransitionAngleCosine(0.2588f), // cosine of 75 degrees
+            pointerGestureSwipeMaxWidthRatio(0.25f),
+            pointerGestureMovementSpeedRatio(0.8f),
+            pointerGestureZoomSpeedRatio(0.3f) { }
+};
+
+
+/*
  * Input reader policy interface.
  *
  * The input reader policy is used by the input reader to interact with the Window Manager
@@ -68,24 +195,8 @@
     virtual bool getDisplayInfo(int32_t displayId,
             int32_t* width, int32_t* height, int32_t* orientation) = 0;
 
-    /* Determines whether to turn on some hacks we have to improve the touch interaction with a
-     * certain device whose screen currently is not all that good.
-     */
-    virtual bool filterTouchEvents() = 0;
-
-    /* Determines whether to turn on some hacks to improve touch interaction with another device
-     * where touch coordinate data can get corrupted.
-     */
-    virtual bool filterJumpyTouchEvents() = 0;
-
-    /* Gets the amount of time to disable virtual keys after the screen is touched
-     * in order to filter out accidental virtual key presses due to swiping gestures
-     * or taps near the edge of the display.  May be 0 to disable the feature.
-     */
-    virtual nsecs_t getVirtualKeyQuietTime() = 0;
-
-    /* Gets the excluded device names for the platform. */
-    virtual void getExcludedDeviceNames(Vector<String8>& outExcludedDeviceNames) = 0;
+    /* Gets the input reader configuration. */
+    virtual void getReaderConfiguration(InputReaderConfiguration* outConfig) = 0;
 
     /* Gets a pointer controller associated with the specified cursor device (ie. a mouse). */
     virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId) = 0;
@@ -139,6 +250,11 @@
     /* Determine whether physical keys exist for the given framework-domain key codes. */
     virtual bool hasKeys(int32_t deviceId, uint32_t sourceMask,
             size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags) = 0;
+
+    /* Requests that a reconfiguration of all input devices.
+     * The changes flag is a bitfield that indicates what has changed and whether
+     * the input devices must all be reopened. */
+    virtual void requestRefreshConfiguration(uint32_t changes) = 0;
 };
 
 
@@ -202,6 +318,8 @@
     virtual bool hasKeys(int32_t deviceId, uint32_t sourceMask,
             size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags);
 
+    virtual void requestRefreshConfiguration(uint32_t changes);
+
 protected:
     // These methods are protected virtual so they can be overridden and instrumented
     // by test cases.
@@ -212,6 +330,8 @@
     sp<InputReaderPolicyInterface> mPolicy;
     sp<InputDispatcherInterface> mDispatcher;
 
+    InputReaderConfiguration mConfig;
+
     virtual InputReaderPolicyInterface* getPolicy() { return mPolicy.get(); }
     virtual InputDispatcherInterface* getDispatcher() { return mDispatcher.get(); }
     virtual EventHubInterface* getEventHub() { return mEventHub.get(); }
@@ -240,18 +360,17 @@
     void timeoutExpired(nsecs_t when);
 
     void handleConfigurationChanged(nsecs_t when);
-    void configureExcludedDevices();
 
     // state management for all devices
     Mutex mStateLock;
 
-    int32_t mGlobalMetaState;
+    int32_t mGlobalMetaState; // guarded by mStateLock
     virtual void updateGlobalMetaState();
     virtual int32_t getGlobalMetaState();
 
     virtual void fadePointer();
 
-    InputConfiguration mInputConfiguration;
+    InputConfiguration mInputConfiguration; // guarded by mStateLock
     void updateInputConfiguration();
 
     nsecs_t mDisableVirtualKeysTimeout; // only accessed by reader thread
@@ -259,9 +378,12 @@
     virtual bool shouldDropVirtualKey(nsecs_t now,
             InputDevice* device, int32_t keyCode, int32_t scanCode);
 
-    nsecs_t mNextTimeout; // only accessed by reader thread
+    nsecs_t mNextTimeout; // only accessed by reader thread, not guarded
     virtual void requestTimeoutAtTime(nsecs_t when);
 
+    uint32_t mConfigurationChangesToRefresh; // guarded by mStateLock
+    void refreshConfiguration(uint32_t changes);
+
     // state queries
     typedef int32_t (InputDevice::*GetStateFunc)(uint32_t sourceMask, int32_t code);
     int32_t getState(int32_t deviceId, uint32_t sourceMask, int32_t code,
@@ -302,7 +424,7 @@
 
     void dump(String8& dump);
     void addMapper(InputMapper* mapper);
-    void configure();
+    void configure(const InputReaderConfiguration* config, uint32_t changes);
     void reset();
     void process(const RawEvent* rawEvents, size_t count);
     void timeoutExpired(nsecs_t when);
@@ -360,7 +482,7 @@
     virtual uint32_t getSources() = 0;
     virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
     virtual void dump(String8& dump);
-    virtual void configure();
+    virtual void configure(const InputReaderConfiguration* config, uint32_t changes);
     virtual void reset();
     virtual void process(const RawEvent* rawEvent) = 0;
     virtual void timeoutExpired(nsecs_t when);
@@ -407,7 +529,7 @@
     virtual uint32_t getSources();
     virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
     virtual void dump(String8& dump);
-    virtual void configure();
+    virtual void configure(const InputReaderConfiguration* config, uint32_t changes);
     virtual void reset();
     virtual void process(const RawEvent* rawEvent);
 
@@ -477,7 +599,7 @@
     virtual uint32_t getSources();
     virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
     virtual void dump(String8& dump);
-    virtual void configure();
+    virtual void configure(const InputReaderConfiguration* config, uint32_t changes);
     virtual void reset();
     virtual void process(const RawEvent* rawEvent);
 
@@ -538,6 +660,12 @@
     float mVWheelScale;
     float mHWheelScale;
 
+    // Velocity controls for mouse pointer and wheel movements.
+    // The controls for X and Y wheel movements are separate to keep them decoupled.
+    VelocityControl mPointerVelocityControl;
+    VelocityControl mWheelXVelocityControl;
+    VelocityControl mWheelYVelocityControl;
+
     sp<PointerControllerInterface> mPointerController;
 
     struct LockedState {
@@ -562,7 +690,7 @@
     virtual uint32_t getSources();
     virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
     virtual void dump(String8& dump);
-    virtual void configure();
+    virtual void configure(const InputReaderConfiguration* config, uint32_t changes);
     virtual void reset();
 
     virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
@@ -669,6 +797,9 @@
     uint32_t mTouchSource; // sources when reporting touch data
     uint32_t mPointerSource; // sources when reporting pointer gestures
 
+    // The reader's configuration.
+    InputReaderConfiguration mConfig;
+
     // Immutable configuration parameters.
     struct Parameters {
         enum DeviceType {
@@ -684,7 +815,6 @@
         bool useBadTouchFilter;
         bool useJumpyTouchFilter;
         bool useAveragingTouchFilter;
-        nsecs_t virtualKeyQuietTime;
 
         enum GestureMode {
             GESTURE_MODE_POINTER,
@@ -964,6 +1094,8 @@
             // Exactly one finger dragging following a tap.
             // Pointer follows the active finger.
             // Emits DOWN, MOVE and UP events at the pointer location.
+            //
+            // Detect double-taps when the finger goes up while in TAP_DRAG mode.
             TAP_DRAG,
 
             // Button is pressed.
@@ -974,6 +1106,8 @@
             // Exactly one finger, button is not pressed.
             // Pointer follows the active finger.
             // Emits HOVER_MOVE events at the pointer location.
+            //
+            // Detect taps when the finger goes up while in HOVER mode.
             HOVER,
 
             // Exactly two fingers but neither have moved enough to clearly indicate
@@ -1021,12 +1155,6 @@
         PointerProperties lastGestureProperties[MAX_POINTERS];
         PointerCoords lastGestureCoords[MAX_POINTERS];
 
-        // Pointer coords and ids for the current spots.
-        PointerControllerInterface::SpotGesture spotGesture;
-        BitSet32 spotIdBits; // same set of ids as touch ids
-        uint32_t spotIdToIndex[MAX_POINTER_ID + 1];
-        PointerCoords spotCoords[MAX_POINTERS];
-
         // Time the pointer gesture last went down.
         nsecs_t downTime;
 
@@ -1048,12 +1176,23 @@
         float referenceGestureX;  // reference gesture X/Y coordinates in pixels
         float referenceGestureY;
 
+        // Distance that each pointer has traveled which has not yet been
+        // subsumed into the reference gesture position.
+        BitSet32 referenceIdBits;
+        struct Delta {
+            float dx, dy;
+        };
+        Delta referenceDeltas[MAX_POINTER_ID + 1];
+
         // Describes how touch ids are mapped to gesture ids for freeform gestures.
         uint32_t freeformTouchToGestureIdMap[MAX_POINTER_ID + 1];
 
         // A velocity tracker for determining whether to switch active pointers during drags.
         VelocityTracker velocityTracker;
 
+        // Velocity control for pointer movements.
+        VelocityControl pointerVelocityControl;
+
         void reset() {
             firstTouchTime = LLONG_MIN;
             activeTouchId = -1;
@@ -1062,12 +1201,11 @@
             currentGestureIdBits.clear();
             lastGestureMode = NEUTRAL;
             lastGestureIdBits.clear();
-            spotGesture = PointerControllerInterface::SPOT_GESTURE_NEUTRAL;
-            spotIdBits.clear();
             downTime = 0;
             velocityTracker.clear();
             resetTap();
             resetQuietTime();
+            pointerVelocityControl.reset();
         }
 
         void resetTap() {
@@ -1088,7 +1226,6 @@
     void dispatchPointerGestures(nsecs_t when, uint32_t policyFlags, bool isTimeout);
     bool preparePointerGestures(nsecs_t when,
             bool* outCancelPreviousGesture, bool* outFinishPreviousGesture, bool isTimeout);
-    void moveSpotsLocked();
 
     // Dispatches a motion event.
     // If the changedId is >= 0 and the action is POINTER_DOWN or POINTER_UP, the
@@ -1235,8 +1372,7 @@
         uint32_t buttonDown;
         uint32_t buttonUp;
 
-        Accumulator() : slots(NULL) {
-            clear(false);
+        Accumulator() : currentSlot(0), slots(NULL), buttonDown(0), buttonUp(0) {
         }
 
         ~Accumulator() {
@@ -1247,11 +1383,14 @@
             slots = new Slot[slotCount];
         }
 
-        void clear(size_t slotCount) {
+        void clearSlots(size_t slotCount) {
             for (size_t i = 0; i < slotCount; i++) {
                 slots[i].clear();
             }
             currentSlot = 0;
+        }
+
+        void clearButtons() {
             buttonDown = 0;
             buttonUp = 0;
         }
@@ -1276,7 +1415,7 @@
     virtual uint32_t getSources();
     virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
     virtual void dump(String8& dump);
-    virtual void configure();
+    virtual void configure(const InputReaderConfiguration* config, uint32_t changes);
     virtual void reset();
     virtual void process(const RawEvent* rawEvent);
 
diff --git a/services/input/InputWindow.h b/services/input/InputWindow.h
index d7d819d..d166ad4 100644
--- a/services/input/InputWindow.h
+++ b/services/input/InputWindow.h
@@ -80,6 +80,10 @@
         FLAG_TURN_SCREEN_ON = 0x00200000,
         FLAG_DISMISS_KEYGUARD = 0x00400000,
         FLAG_SPLIT_TOUCH = 0x00800000,
+        FLAG_HARDWARE_ACCELERATED = 0x01000000,
+        FLAG_HARDWARE_ACCELERATED_SYSTEM = 0x02000000,
+        FLAG_SLIPPERY = 0x04000000,
+        FLAG_NEEDS_MENU_KEY = 0x08000000,
         FLAG_KEEP_SURFACE_WHILE_ANIMATING = 0x10000000,
         FLAG_COMPATIBLE_WINDOW = 0x20000000,
         FLAG_SYSTEM_ERROR = 0x40000000,
@@ -123,6 +127,10 @@
         LAST_SYSTEM_WINDOW      = 2999,
     };
 
+    enum {
+        INPUT_FEATURE_DISABLE_TOUCH_PAD_GESTURES = 0x00000001,
+    };
+
     sp<InputWindowHandle> inputWindowHandle;
     sp<InputChannel> inputChannel;
     String8 name;
@@ -143,6 +151,7 @@
     int32_t layer;
     int32_t ownerPid;
     int32_t ownerUid;
+    int32_t inputFeatures;
 
     bool touchableRegionContainsPoint(int32_t x, int32_t y) const;
     bool frameContainsPoint(int32_t x, int32_t y) const;
diff --git a/services/input/PointerController.cpp b/services/input/PointerController.cpp
index b87c98d..12c7cba 100644
--- a/services/input/PointerController.cpp
+++ b/services/input/PointerController.cpp
@@ -69,10 +69,10 @@
 
     mLocked.inactivityTimeout = INACTIVITY_TIMEOUT_NORMAL;
 
-    mLocked.pointerIsFading = true; // keep the pointer initially faded
+    mLocked.pointerFadeDirection = 0;
     mLocked.pointerX = 0;
     mLocked.pointerY = 0;
-    mLocked.pointerAlpha = 0.0f;
+    mLocked.pointerAlpha = 0.0f; // pointer is initially faded
     mLocked.pointerSprite = mSpriteController->createSprite();
     mLocked.pointerIconChanged = false;
 
@@ -191,23 +191,37 @@
     *outY = mLocked.pointerY;
 }
 
-void PointerController::fade() {
+void PointerController::fade(Transition transition) {
     AutoMutex _l(mLock);
 
-    sendImmediateInactivityTimeoutLocked();
+    // Remove the inactivity timeout, since we are fading now.
+    removeInactivityTimeoutLocked();
+
+    // Start fading.
+    if (transition == TRANSITION_IMMEDIATE) {
+        mLocked.pointerFadeDirection = 0;
+        mLocked.pointerAlpha = 0.0f;
+        updatePointerLocked();
+    } else {
+        mLocked.pointerFadeDirection = -1;
+        startAnimationLocked();
+    }
 }
 
-void PointerController::unfade() {
+void PointerController::unfade(Transition transition) {
     AutoMutex _l(mLock);
 
     // Always reset the inactivity timer.
     resetInactivityTimeoutLocked();
 
-    // Unfade immediately if needed.
-    if (mLocked.pointerIsFading) {
-        mLocked.pointerIsFading = false;
+    // Start unfading.
+    if (transition == TRANSITION_IMMEDIATE) {
+        mLocked.pointerFadeDirection = 0;
         mLocked.pointerAlpha = 1.0f;
         updatePointerLocked();
+    } else {
+        mLocked.pointerFadeDirection = 1;
+        startAnimationLocked();
     }
 }
 
@@ -226,15 +240,15 @@
     }
 }
 
-void PointerController::setSpots(SpotGesture spotGesture,
-        const PointerCoords* spotCoords, const uint32_t* spotIdToIndex, BitSet32 spotIdBits) {
+void PointerController::setSpots(const PointerCoords* spotCoords,
+        const uint32_t* spotIdToIndex, BitSet32 spotIdBits) {
 #if DEBUG_POINTER_UPDATES
-    LOGD("setSpots: spotGesture=%d", spotGesture);
+    LOGD("setSpots: idBits=%08x", spotIdBits.value);
     for (BitSet32 idBits(spotIdBits); !idBits.isEmpty(); ) {
         uint32_t id = idBits.firstMarkedBit();
         idBits.clearBit(id);
         const PointerCoords& c = spotCoords[spotIdToIndex[id]];
-        LOGD("  spot %d: position=(%0.3f, %0.3f), pressure=%0.3f", id,
+        LOGD(" spot %d: position=(%0.3f, %0.3f), pressure=%0.3f", id,
                 c.getAxisValue(AMOTION_EVENT_AXIS_X),
                 c.getAxisValue(AMOTION_EVENT_AXIS_Y),
                 c.getAxisValue(AMOTION_EVENT_AXIS_PRESSURE));
@@ -401,10 +415,20 @@
     nsecs_t frameDelay = systemTime(SYSTEM_TIME_MONOTONIC) - mLocked.animationTime;
 
     // Animate pointer fade.
-    if (mLocked.pointerIsFading) {
+    if (mLocked.pointerFadeDirection < 0) {
         mLocked.pointerAlpha -= float(frameDelay) / POINTER_FADE_DURATION;
-        if (mLocked.pointerAlpha <= 0) {
-            mLocked.pointerAlpha = 0;
+        if (mLocked.pointerAlpha <= 0.0f) {
+            mLocked.pointerAlpha = 0.0f;
+            mLocked.pointerFadeDirection = 0;
+        } else {
+            keepAnimating = true;
+        }
+        updatePointerLocked();
+    } else if (mLocked.pointerFadeDirection > 0) {
+        mLocked.pointerAlpha += float(frameDelay) / POINTER_FADE_DURATION;
+        if (mLocked.pointerAlpha >= 1.0f) {
+            mLocked.pointerAlpha = 1.0f;
+            mLocked.pointerFadeDirection = 0;
         } else {
             keepAnimating = true;
         }
@@ -432,12 +456,7 @@
 }
 
 void PointerController::doInactivityTimeout() {
-    AutoMutex _l(mLock);
-
-    if (!mLocked.pointerIsFading) {
-        mLocked.pointerIsFading = true;
-        startAnimationLocked();
-    }
+    fade(TRANSITION_GRADUAL);
 }
 
 void PointerController::startAnimationLocked() {
@@ -456,9 +475,8 @@
     mLooper->sendMessageDelayed(timeout, mHandler, MSG_INACTIVITY_TIMEOUT);
 }
 
-void PointerController::sendImmediateInactivityTimeoutLocked() {
+void PointerController::removeInactivityTimeoutLocked() {
     mLooper->removeMessages(mHandler, MSG_INACTIVITY_TIMEOUT);
-    mLooper->sendMessage(mHandler, MSG_INACTIVITY_TIMEOUT);
 }
 
 void PointerController::updatePointerLocked() {
diff --git a/services/input/PointerController.h b/services/input/PointerController.h
index c7435ee..700ef72 100644
--- a/services/input/PointerController.h
+++ b/services/input/PointerController.h
@@ -64,14 +64,21 @@
     /* Gets the absolute location of the pointer. */
     virtual void getPosition(float* outX, float* outY) const = 0;
 
+    enum Transition {
+        // Fade/unfade immediately.
+        TRANSITION_IMMEDIATE,
+        // Fade/unfade gradually.
+        TRANSITION_GRADUAL,
+    };
+
     /* Fades the pointer out now. */
-    virtual void fade() = 0;
+    virtual void fade(Transition transition) = 0;
 
     /* Makes the pointer visible if it has faded out.
      * The pointer never unfades itself automatically.  This method must be called
      * by the client whenever the pointer is moved or a button is pressed and it
      * wants to ensure that the pointer becomes visible again. */
-    virtual void unfade() = 0;
+    virtual void unfade(Transition transition) = 0;
 
     enum Presentation {
         // Show the mouse pointer.
@@ -83,38 +90,6 @@
     /* Sets the mode of the pointer controller. */
     virtual void setPresentation(Presentation presentation) = 0;
 
-    // Describes the current gesture.
-    enum SpotGesture {
-        // No gesture.
-        // Do not display any spots.
-        SPOT_GESTURE_NEUTRAL,
-        // Tap at current location.
-        // Briefly display one spot at the tapped location.
-        SPOT_GESTURE_TAP,
-        // Drag at current location.
-        // Display spot at pressed location.
-        SPOT_GESTURE_DRAG,
-        // Button pressed but no finger is down.
-        // Display spot at pressed location.
-        SPOT_GESTURE_BUTTON_CLICK,
-        // Button pressed and a finger is down.
-        // Display spot at pressed location.
-        SPOT_GESTURE_BUTTON_DRAG,
-        // One finger down and hovering.
-        // Display spot at the hovered location.
-        SPOT_GESTURE_HOVER,
-        // Two fingers down but not sure in which direction they are moving so we consider
-        // it a press at the pointer location.
-        // Display two spots near the pointer location.
-        SPOT_GESTURE_PRESS,
-        // Two fingers down and moving in same direction.
-        // Display two spots near the pointer location.
-        SPOT_GESTURE_SWIPE,
-        // Two or more fingers down and moving in arbitrary directions.
-        // Display two or more spots near the pointer location, one for each finger.
-        SPOT_GESTURE_FREEFORM,
-    };
-
     /* Sets the spots for the current gesture.
      * The spots are not subject to the inactivity timeout like the pointer
      * itself it since they are expected to remain visible for so long as
@@ -124,8 +99,7 @@
      * For spotCoords, pressure != 0 indicates that the spot's location is being
      * pressed (not hovering).
      */
-    virtual void setSpots(SpotGesture spotGesture,
-            const PointerCoords* spotCoords, const uint32_t* spotIdToIndex,
+    virtual void setSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex,
             BitSet32 spotIdBits) = 0;
 
     /* Removes all spots. */
@@ -187,12 +161,12 @@
     virtual int32_t getButtonState() const;
     virtual void setPosition(float x, float y);
     virtual void getPosition(float* outX, float* outY) const;
-    virtual void fade();
-    virtual void unfade();
+    virtual void fade(Transition transition);
+    virtual void unfade(Transition transition);
 
     virtual void setPresentation(Presentation presentation);
-    virtual void setSpots(SpotGesture spotGesture,
-            const PointerCoords* spotCoords, const uint32_t* spotIdToIndex, BitSet32 spotIdBits);
+    virtual void setSpots(const PointerCoords* spotCoords,
+            const uint32_t* spotIdToIndex, BitSet32 spotIdBits);
     virtual void clearSpots();
 
     void setDisplaySize(int32_t width, int32_t height);
@@ -250,7 +224,7 @@
         Presentation presentation;
         bool presentationChanged;
 
-        bool pointerIsFading;
+        int32_t pointerFadeDirection;
         float pointerX;
         float pointerY;
         float pointerAlpha;
@@ -274,7 +248,7 @@
     void startAnimationLocked();
 
     void resetInactivityTimeoutLocked();
-    void sendImmediateInactivityTimeoutLocked();
+    void removeInactivityTimeoutLocked();
     void updatePointerLocked();
 
     Spot* getSpotLocked(uint32_t id);
diff --git a/services/input/tests/InputDispatcher_test.cpp b/services/input/tests/InputDispatcher_test.cpp
index 3db3473..8dfb44b 100644
--- a/services/input/tests/InputDispatcher_test.cpp
+++ b/services/input/tests/InputDispatcher_test.cpp
@@ -35,6 +35,8 @@
 // --- FakeInputDispatcherPolicy ---
 
 class FakeInputDispatcherPolicy : public InputDispatcherPolicyInterface {
+    InputDispatcherConfiguration mConfig;
+
 protected:
     virtual ~FakeInputDispatcherPolicy() {
     }
@@ -55,16 +57,12 @@
     virtual void notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle) {
     }
 
-    virtual nsecs_t getKeyRepeatTimeout() {
-        return 500 * 1000000LL;
+    virtual void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) {
+        *outConfig = mConfig;
     }
 
-    virtual nsecs_t getKeyRepeatDelay() {
-        return 50 * 1000000LL;
-    }
-
-    virtual int32_t getMaxEventsPerSecond() {
-        return 60;
+    virtual bool isKeyRepeatEnabled() {
+        return true;
     }
 
     virtual bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) {
diff --git a/services/input/tests/InputReader_test.cpp b/services/input/tests/InputReader_test.cpp
index 1ab2a3e..e349248 100644
--- a/services/input/tests/InputReader_test.cpp
+++ b/services/input/tests/InputReader_test.cpp
@@ -92,17 +92,17 @@
         *outY = 0;
     }
 
-    virtual void fade() {
+    virtual void fade(Transition transition) {
     }
 
-    virtual void unfade() {
+    virtual void unfade(Transition transition) {
     }
 
     virtual void setPresentation(Presentation presentation) {
     }
 
-    virtual void setSpots(SpotGesture spotGesture,
-            const PointerCoords* spotCoords, const uint32_t* spotIdToIndex, BitSet32 spotIdBits) {
+    virtual void setSpots(const PointerCoords* spotCoords,
+            const uint32_t* spotIdToIndex, BitSet32 spotIdBits) {
     }
 
     virtual void clearSpots() {
@@ -120,17 +120,14 @@
     };
 
     KeyedVector<int32_t, DisplayInfo> mDisplayInfos;
-    bool mFilterTouchEvents;
-    bool mFilterJumpyTouchEvents;
-    Vector<String8> mExcludedDeviceNames;
+    InputReaderConfiguration mConfig;
     KeyedVector<int32_t, sp<FakePointerController> > mPointerControllers;
 
 protected:
     virtual ~FakeInputReaderPolicy() { }
 
 public:
-    FakeInputReaderPolicy() :
-            mFilterTouchEvents(false), mFilterJumpyTouchEvents(false) {
+    FakeInputReaderPolicy() {
     }
 
     void removeDisplayInfo(int32_t displayId) {
@@ -148,11 +145,11 @@
     }
 
     void setFilterTouchEvents(bool enabled) {
-        mFilterTouchEvents = enabled;
+        mConfig.filterTouchEvents = enabled;
     }
 
     void setFilterJumpyTouchEvents(bool enabled) {
-        mFilterJumpyTouchEvents = enabled;
+        mConfig.filterJumpyTouchEvents = enabled;
     }
 
     virtual nsecs_t getVirtualKeyQuietTime() {
@@ -160,7 +157,7 @@
     }
 
     void addExcludedDeviceName(const String8& deviceName) {
-        mExcludedDeviceNames.push(deviceName);
+        mConfig.excludedDeviceNames.push(deviceName);
     }
 
     void setPointerController(int32_t deviceId, const sp<FakePointerController>& controller) {
@@ -187,16 +184,8 @@
         return false;
     }
 
-    virtual bool filterTouchEvents() {
-        return mFilterTouchEvents;
-    }
-
-    virtual bool filterJumpyTouchEvents() {
-        return mFilterJumpyTouchEvents;
-    }
-
-    virtual void getExcludedDeviceNames(Vector<String8>& outExcludedDeviceNames) {
-        outExcludedDeviceNames.appendVector(mExcludedDeviceNames);
+    virtual void getReaderConfiguration(InputReaderConfiguration* outConfig) {
+        *outConfig = mConfig;
     }
 
     virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId) {
@@ -492,7 +481,7 @@
     }
 
     void addAbsoluteAxis(int32_t deviceId, int axis,
-            int32_t minValue, int32_t maxValue, int flat, int fuzz) {
+            int32_t minValue, int32_t maxValue, int flat, int fuzz, int resolution = 0) {
         Device* device = getDevice(deviceId);
 
         RawAbsoluteAxisInfo info;
@@ -501,6 +490,7 @@
         info.maxValue = maxValue;
         info.flat = flat;
         info.fuzz = fuzz;
+        info.resolution = resolution;
         device->absoluteAxes.add(axis, info);
     }
 
@@ -640,8 +630,8 @@
         return NAME_NOT_FOUND;
     }
 
-    virtual void addExcludedDevice(const char* deviceName) {
-        mExcludedDevices.add(String8(deviceName));
+    virtual void setExcludedDevices(const Vector<String8>& devices) {
+        mExcludedDevices = devices;
     }
 
     virtual size_t getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSize) {
@@ -739,6 +729,12 @@
 
     virtual void dump(String8& dump) {
     }
+
+    virtual void requestReopenDevices() {
+    }
+
+    virtual void wake() {
+    }
 };
 
 
@@ -892,7 +888,7 @@
         }
     }
 
-    virtual void configure() {
+    virtual void configure(const InputReaderConfiguration* config, uint32_t changes) {
         mConfigureWasCalled = true;
     }
 
@@ -1356,7 +1352,8 @@
 
 TEST_F(InputDeviceTest, WhenNoMappersAreRegistered_DeviceIsIgnored) {
     // Configuration.
-    mDevice->configure();
+    InputReaderConfiguration config;
+    mDevice->configure(&config, 0);
 
     // Metadata.
     ASSERT_TRUE(mDevice->isIgnored());
@@ -1410,7 +1407,8 @@
     mapper2->setMetaState(AMETA_SHIFT_ON);
     mDevice->addMapper(mapper2);
 
-    mDevice->configure();
+    InputReaderConfiguration config;
+    mDevice->configure(&config, 0);
 
     String8 propertyValue;
     ASSERT_TRUE(mDevice->getConfiguration().tryGetProperty(String8("key"), propertyValue))
@@ -1516,8 +1514,10 @@
     }
 
     void addMapperAndConfigure(InputMapper* mapper) {
+        InputReaderConfiguration config;
+
         mDevice->addMapper(mapper);
-        mDevice->configure();
+        mDevice->configure(&config, 0);
     }
 
     static void process(InputMapper* mapper, nsecs_t when, int32_t deviceId, int32_t type,
diff --git a/services/java/com/android/server/AppWidgetService.java b/services/java/com/android/server/AppWidgetService.java
index c03b994..158c778 100644
--- a/services/java/com/android/server/AppWidgetService.java
+++ b/services/java/com/android/server/AppWidgetService.java
@@ -29,6 +29,7 @@
 import java.util.List;
 import java.util.Locale;
 
+import org.apache.commons.logging.impl.SimpleLog;
 import org.xmlpull.v1.XmlPullParser;
 import org.xmlpull.v1.XmlPullParserException;
 import org.xmlpull.v1.XmlSerializer;
@@ -394,41 +395,47 @@
     public void bindAppWidgetId(int appWidgetId, ComponentName provider) {
         mContext.enforceCallingPermission(android.Manifest.permission.BIND_APPWIDGET,
                 "bindGagetId appWidgetId=" + appWidgetId + " provider=" + provider);
-        synchronized (mAppWidgetIds) {
-            AppWidgetId id = lookupAppWidgetIdLocked(appWidgetId);
-            if (id == null) {
-                throw new IllegalArgumentException("bad appWidgetId");
+        
+        final long ident = Binder.clearCallingIdentity();
+        try {
+            synchronized (mAppWidgetIds) {
+                AppWidgetId id = lookupAppWidgetIdLocked(appWidgetId);
+                if (id == null) {
+                    throw new IllegalArgumentException("bad appWidgetId");
+                }
+                if (id.provider != null) {
+                    throw new IllegalArgumentException("appWidgetId " + appWidgetId + " already bound to "
+                            + id.provider.info.provider);
+                }
+                Provider p = lookupProviderLocked(provider);
+                if (p == null) {
+                    throw new IllegalArgumentException("not a appwidget provider: " + provider);
+                }
+                if (p.zombie) {
+                    throw new IllegalArgumentException("can't bind to a 3rd party provider in"
+                            + " safe mode: " + provider);
+                }
+    
+                id.provider = p;
+                p.instances.add(id);
+                int instancesSize = p.instances.size();
+                if (instancesSize == 1) {
+                    // tell the provider that it's ready
+                    sendEnableIntentLocked(p);
+                }
+    
+                // send an update now -- We need this update now, and just for this appWidgetId.
+                // It's less critical when the next one happens, so when we schdule the next one,
+                // we add updatePeriodMillis to its start time.  That time will have some slop,
+                // but that's okay.
+                sendUpdateIntentLocked(p, new int[] { appWidgetId });
+    
+                // schedule the future updates
+                registerForBroadcastsLocked(p, getAppWidgetIds(p));
+                saveStateLocked();
             }
-            if (id.provider != null) {
-                throw new IllegalArgumentException("appWidgetId " + appWidgetId + " already bound to "
-                        + id.provider.info.provider);
-            }
-            Provider p = lookupProviderLocked(provider);
-            if (p == null) {
-                throw new IllegalArgumentException("not a appwidget provider: " + provider);
-            }
-            if (p.zombie) {
-                throw new IllegalArgumentException("can't bind to a 3rd party provider in"
-                        + " safe mode: " + provider);
-            }
-
-            id.provider = p;
-            p.instances.add(id);
-            int instancesSize = p.instances.size();
-            if (instancesSize == 1) {
-                // tell the provider that it's ready
-                sendEnableIntentLocked(p);
-            }
-
-            // send an update now -- We need this update now, and just for this appWidgetId.
-            // It's less critical when the next one happens, so when we schdule the next one,
-            // we add updatePeriodMillis to its start time.  That time will have some slop,
-            // but that's okay.
-            sendUpdateIntentLocked(p, new int[] { appWidgetId });
-
-            // schedule the future updates
-            registerForBroadcastsLocked(p, getAppWidgetIds(p));
-            saveStateLocked();
+        } finally {
+            Binder.restoreCallingIdentity(ident);
         }
     }
 
diff --git a/services/java/com/android/server/BackupManagerService.java b/services/java/com/android/server/BackupManagerService.java
index 455b4c2..3aa1239 100644
--- a/services/java/com/android/server/BackupManagerService.java
+++ b/services/java/com/android/server/BackupManagerService.java
@@ -39,6 +39,8 @@
 import android.content.ServiceConnection;
 import android.content.pm.ApplicationInfo;
 import android.content.pm.IPackageDataObserver;
+import android.content.pm.IPackageDeleteObserver;
+import android.content.pm.IPackageInstallObserver;
 import android.content.pm.IPackageManager;
 import android.content.pm.PackageInfo;
 import android.content.pm.PackageManager;
@@ -46,6 +48,7 @@
 import android.content.pm.PackageManager.NameNotFoundException;
 import android.net.Uri;
 import android.os.Binder;
+import android.os.Build;
 import android.os.Bundle;
 import android.os.Environment;
 import android.os.Handler;
@@ -74,12 +77,16 @@
 import java.io.EOFException;
 import java.io.File;
 import java.io.FileDescriptor;
+import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.PrintWriter;
 import java.io.RandomAccessFile;
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -127,6 +134,7 @@
     // Timeout intervals for agent backup & restore operations
     static final long TIMEOUT_BACKUP_INTERVAL = 30 * 1000;
     static final long TIMEOUT_FULL_BACKUP_INTERVAL = 5 * 60 * 1000;
+    static final long TIMEOUT_SHARED_BACKUP_INTERVAL = 30 * 60 * 1000;
     static final long TIMEOUT_RESTORE_INTERVAL = 60 * 1000;
 
     // User confirmation timeout for a full backup/restore operation
@@ -398,6 +406,13 @@
                 break;
             }
 
+            case MSG_RUN_FULL_RESTORE:
+            {
+                FullRestoreParams params = (FullRestoreParams)msg.obj;
+                (new PerformFullRestoreTask(params.fd, params.observer, params.latch)).run();
+                break;
+            }
+
             case MSG_RUN_CLEAR:
             {
                 ClearParams params = (ClearParams)msg.obj;
@@ -1236,7 +1251,7 @@
                     Slog.d(TAG, "awaiting agent for " + app);
 
                     // success; wait for the agent to arrive
-                    // only wait 10 seconds for the clear data to happen
+                    // only wait 10 seconds for the bind to happen
                     long timeoutMark = System.currentTimeMillis() + TIMEOUT_INTERVAL;
                     while (mConnecting && mConnectedAgent == null
                             && (System.currentTimeMillis() < timeoutMark)) {
@@ -1677,6 +1692,7 @@
         public void run() {
             final List<PackageInfo> packagesToBackup;
 
+            Slog.i(TAG, "--- Performing full-dataset backup ---");
             sendStartBackup();
 
             // doAllApps supersedes the package set if any
@@ -1695,64 +1711,33 @@
                 }
             }
 
-            // Now back up the app data via the agent mechanism
+            // Cull any packages that have indicated that backups are not permitted.
+            for (int i = 0; i < packagesToBackup.size(); ) {
+                PackageInfo info = packagesToBackup.get(i);
+                if ((info.applicationInfo.flags & ApplicationInfo.FLAG_ALLOW_BACKUP) == 0) {
+                    packagesToBackup.remove(i);
+                } else {
+                    i++;
+                }
+            }
+
             PackageInfo pkg = null;
             try {
+                // Now back up the app data via the agent mechanism
                 int N = packagesToBackup.size();
                 for (int i = 0; i < N; i++) {
                     pkg = packagesToBackup.get(i);
+                    backupOnePackage(pkg);
+                }
 
-                    Slog.d(TAG, "Binding to full backup agent : " + pkg.packageName);
-
-                    IBackupAgent agent = bindToAgentSynchronous(pkg.applicationInfo,
-                            IApplicationThread.BACKUP_MODE_FULL);
-                    if (agent != null) {
-                        try {
-                            ApplicationInfo app = pkg.applicationInfo;
-                            boolean sendApk = mIncludeApks
-                                    && ((app.flags & ApplicationInfo.FLAG_FORWARD_LOCK) == 0)
-                                    && ((app.flags & ApplicationInfo.FLAG_SYSTEM) == 0 ||
-                                        (app.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0);
-
-                            sendOnBackupPackage(pkg.packageName);
-
-                            {
-                                BackupDataOutput output = new BackupDataOutput(
-                                        mOutputFile.getFileDescriptor());
-
-                                if (DEBUG) Slog.d(TAG, "Writing manifest for " + pkg.packageName);
-                                writeAppManifest(pkg, mManifestFile, sendApk);
-                                FullBackup.backupToTar(pkg.packageName, null, null,
-                                        mFilesDir.getAbsolutePath(),
-                                        mManifestFile.getAbsolutePath(),
-                                        output);
-                            }
-
-                            if (DEBUG) Slog.d(TAG, "Calling doBackup()");
-                            final int token = generateToken();
-                            prepareOperationTimeout(token, TIMEOUT_FULL_BACKUP_INTERVAL);
-                            agent.doBackup(null, mOutputFile, null, sendApk,
-                                    token, mBackupManagerBinder);
-                            boolean success = waitUntilOperationComplete(token);
-                            if (!success) {
-                                Slog.d(TAG, "Full backup failed on package " + pkg.packageName);
-                            } else {
-                                if (DEBUG) Slog.d(TAG, "Full backup success: " + pkg.packageName);
-                            }
-                        } catch (IOException e) {
-                            Slog.e(TAG, "Error backing up " + pkg.packageName, e);
-                        }
-                    } else {
-                        Slog.w(TAG, "Unable to bind to full agent for " + pkg.packageName);
-                    }
-                    tearDown(pkg);
+                // Finally, shared storage if requested
+                if (mIncludeShared) {
+                    backupSharedStorage();
                 }
             } catch (RemoteException e) {
                 Slog.e(TAG, "App died during full backup");
             } finally {
-                if (pkg != null) {
-                    tearDown(pkg);
-                }
+                tearDown(pkg);
                 try {
                     mOutputFile.close();
                 } catch (IOException e) {
@@ -1771,6 +1756,79 @@
             }
         }
 
+        private void backupOnePackage(PackageInfo pkg) throws RemoteException {
+            Slog.d(TAG, "Binding to full backup agent : " + pkg.packageName);
+
+            IBackupAgent agent = bindToAgentSynchronous(pkg.applicationInfo,
+                    IApplicationThread.BACKUP_MODE_FULL);
+            if (agent != null) {
+                try {
+                    ApplicationInfo app = pkg.applicationInfo;
+                    boolean sendApk = mIncludeApks
+                            && ((app.flags & ApplicationInfo.FLAG_FORWARD_LOCK) == 0)
+                            && ((app.flags & ApplicationInfo.FLAG_SYSTEM) == 0 ||
+                                (app.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0);
+
+                    sendOnBackupPackage(pkg.packageName);
+
+                    {
+                        BackupDataOutput output = new BackupDataOutput(
+                                mOutputFile.getFileDescriptor());
+
+                        if (DEBUG) Slog.d(TAG, "Writing manifest for " + pkg.packageName);
+                        writeAppManifest(pkg, mManifestFile, sendApk);
+                        FullBackup.backupToTar(pkg.packageName, null, null,
+                                mFilesDir.getAbsolutePath(),
+                                mManifestFile.getAbsolutePath(),
+                                output);
+                    }
+
+                    if (DEBUG) Slog.d(TAG, "Calling doBackup()");
+                    final int token = generateToken();
+                    prepareOperationTimeout(token, TIMEOUT_FULL_BACKUP_INTERVAL);
+                    agent.doBackup(null, mOutputFile, null, sendApk,
+                            token, mBackupManagerBinder);
+                    if (!waitUntilOperationComplete(token)) {
+                        Slog.e(TAG, "Full backup failed on package " + pkg.packageName);
+                    } else {
+                        if (DEBUG) Slog.d(TAG, "Full backup success: " + pkg.packageName);
+                    }
+                } catch (IOException e) {
+                    Slog.e(TAG, "Error backing up " + pkg.packageName, e);
+                }
+            } else {
+                Slog.w(TAG, "Unable to bind to full agent for " + pkg.packageName);
+            }
+            tearDown(pkg);
+        }
+
+        private void backupSharedStorage() throws RemoteException {
+            PackageInfo pkg = null;
+            try {
+                pkg = mPackageManager.getPackageInfo("com.android.sharedstoragebackup", 0);
+                IBackupAgent agent = bindToAgentSynchronous(pkg.applicationInfo,
+                        IApplicationThread.BACKUP_MODE_FULL);
+                if (agent != null) {
+                    sendOnBackupPackage("Shared storage");
+
+                    final int token = generateToken();
+                    prepareOperationTimeout(token, TIMEOUT_SHARED_BACKUP_INTERVAL);
+                    agent.doBackup(null, mOutputFile, null, false, token, mBackupManagerBinder);
+                    if (!waitUntilOperationComplete(token)) {
+                        Slog.e(TAG, "Full backup failed on shared storage");
+                    } else {
+                        if (DEBUG) Slog.d(TAG, "Full shared storage backup success");
+                    }
+                } else {
+                    Slog.e(TAG, "Could not bind to shared storage backup agent");
+                }
+            } catch (NameNotFoundException e) {
+                Slog.e(TAG, "Shared storage backup package not found");
+            } finally {
+                tearDown(pkg);
+            }
+        }
+
         private void writeAppManifest(PackageInfo pkg, File manifestFile, boolean withApk)
                 throws IOException {
             // Manifest format. All data are strings ending in LF:
@@ -1779,7 +1837,9 @@
             // Version 1:
             //     package name
             //     package's versionCode
-            //     boolean: "1" if archive includes .apk, "0" otherwise
+            //     platform versionCode
+            //     getInstallerPackageName() for this package (maybe empty)
+            //     boolean: "1" if archive includes .apk; any other string means not
             //     number of signatures == N
             // N*:    signature byte array in ascii format per Signature.toCharsString()
             StringBuilder builder = new StringBuilder(4096);
@@ -1788,6 +1848,11 @@
             printer.println(Integer.toString(BACKUP_MANIFEST_VERSION));
             printer.println(pkg.packageName);
             printer.println(Integer.toString(pkg.versionCode));
+            printer.println(Integer.toString(Build.VERSION.SDK_INT));
+
+            String installerName = mPackageManager.getInstallerPackageName(pkg.packageName);
+            printer.println((installerName != null) ? installerName : "");
+
             printer.println(withApk ? "1" : "0");
             if (pkg.signatures == null) {
                 printer.println("0");
@@ -1804,23 +1869,24 @@
         }
 
         private void tearDown(PackageInfo pkg) {
-            final ApplicationInfo app = pkg.applicationInfo;
-            try {
-                // unbind and tidy up even on timeout or failure, just in case
-                mActivityManager.unbindBackupAgent(app);
+            if (pkg != null) {
+                final ApplicationInfo app = pkg.applicationInfo;
+                if (app != null) {
+                    try {
+                        // unbind and tidy up even on timeout or failure, just in case
+                        mActivityManager.unbindBackupAgent(app);
 
-                // The agent was running with a stub Application object, so shut it down.
-                // !!! We hardcode the confirmation UI's package name here rather than use a
-                //     manifest flag!  TODO something less direct.
-                if (app.uid != Process.SYSTEM_UID
-                        && !pkg.packageName.equals("com.android.backupconfirm")) {
-                    if (DEBUG) Slog.d(TAG, "Backup complete, killing host process");
-                    mActivityManager.killApplicationProcess(app.processName, app.uid);
-                } else {
-                    if (DEBUG) Slog.d(TAG, "Not killing after restore: " + app.processName);
+                        // The agent was running with a stub Application object, so shut it down.
+                        if (app.uid != Process.SYSTEM_UID) {
+                            if (DEBUG) Slog.d(TAG, "Backup complete, killing host process");
+                            mActivityManager.killApplicationProcess(app.processName, app.uid);
+                        } else {
+                            if (DEBUG) Slog.d(TAG, "Not killing after restore: " + app.processName);
+                        }
+                    } catch (RemoteException e) {
+                        Slog.d(TAG, "Lost app trying to shut down");
+                    }
                 }
-            } catch (RemoteException e) {
-                Slog.d(TAG, "Lost app trying to shut down");
             }
         }
 
@@ -1861,6 +1927,1019 @@
     }
 
 
+    // ----- Full restore from a file/socket -----
+
+    // Description of a file in the restore datastream
+    static class FileMetadata {
+        String packageName;             // name of the owning app
+        String installerPackageName;    // name of the market-type app that installed the owner
+        int type;                       // e.g. FullBackup.TYPE_DIRECTORY
+        String domain;                  // e.g. FullBackup.DATABASE_TREE_TOKEN
+        String path;                    // subpath within the semantic domain
+        long mode;                      // e.g. 0666 (actually int)
+        long mtime;                     // last mod time, UTC time_t (actually int)
+        long size;                      // bytes of content
+
+        @Override
+        public String toString() {
+            StringBuilder sb = new StringBuilder(128);
+            sb.append("FileMetadata{");
+            sb.append(packageName); sb.append(',');
+            sb.append(type); sb.append(',');
+            sb.append(domain); sb.append(':'); sb.append(path); sb.append(',');
+            sb.append(size);
+            sb.append('}');
+            return sb.toString();
+        }
+    }
+
+    enum RestorePolicy {
+        IGNORE,
+        ACCEPT,
+        ACCEPT_IF_APK
+    }
+
+    class PerformFullRestoreTask implements Runnable {
+        ParcelFileDescriptor mInputFile;
+        IFullBackupRestoreObserver mObserver;
+        AtomicBoolean mLatchObject;
+        IBackupAgent mAgent;
+        String mAgentPackage;
+        ApplicationInfo mTargetApp;
+        ParcelFileDescriptor[] mPipes = null;
+
+        long mBytes;
+
+        // possible handling states for a given package in the restore dataset
+        final HashMap<String, RestorePolicy> mPackagePolicies
+                = new HashMap<String, RestorePolicy>();
+
+        // installer package names for each encountered app, derived from the manifests
+        final HashMap<String, String> mPackageInstallers = new HashMap<String, String>();
+
+        // Signatures for a given package found in its manifest file
+        final HashMap<String, Signature[]> mManifestSignatures
+                = new HashMap<String, Signature[]>();
+
+        // Packages we've already wiped data on when restoring their first file
+        final HashSet<String> mClearedPackages = new HashSet<String>();
+
+        PerformFullRestoreTask(ParcelFileDescriptor fd, IFullBackupRestoreObserver observer,
+                AtomicBoolean latch) {
+            mInputFile = fd;
+            mObserver = observer;
+            mLatchObject = latch;
+            mAgent = null;
+            mAgentPackage = null;
+            mTargetApp = null;
+
+            // Which packages we've already wiped data on.  We prepopulate this
+            // with a whitelist of packages known to be unclearable.
+            mClearedPackages.add("android");
+            mClearedPackages.add("com.android.providers.settings");
+
+        }
+
+        class RestoreFileRunnable implements Runnable {
+            IBackupAgent mAgent;
+            FileMetadata mInfo;
+            ParcelFileDescriptor mSocket;
+            int mToken;
+
+            RestoreFileRunnable(IBackupAgent agent, FileMetadata info,
+                    ParcelFileDescriptor socket, int token) throws IOException {
+                mAgent = agent;
+                mInfo = info;
+                mToken = token;
+
+                // This class is used strictly for process-local binder invocations.  The
+                // semantics of ParcelFileDescriptor differ in this case; in particular, we
+                // do not automatically get a 'dup'ed descriptor that we can can continue
+                // to use asynchronously from the caller.  So, we make sure to dup it ourselves
+                // before proceeding to do the restore.
+                mSocket = ParcelFileDescriptor.dup(socket.getFileDescriptor());
+            }
+
+            @Override
+            public void run() {
+                try {
+                    mAgent.doRestoreFile(mSocket, mInfo.size, mInfo.type,
+                            mInfo.domain, mInfo.path, mInfo.mode, mInfo.mtime,
+                            mToken, mBackupManagerBinder);
+                } catch (RemoteException e) {
+                    // never happens; this is used strictly for local binder calls
+                }
+            }
+        }
+
+        @Override
+        public void run() {
+            Slog.i(TAG, "--- Performing full-dataset restore ---");
+            sendStartRestore();
+
+            // Are we able to restore shared-storage data?
+            if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
+                mPackagePolicies.put("com.android.sharedstoragebackup", RestorePolicy.ACCEPT);
+            }
+
+            try {
+                mBytes = 0;
+                byte[] buffer = new byte[32 * 1024];
+                FileInputStream instream = new FileInputStream(mInputFile.getFileDescriptor());
+
+                boolean didRestore;
+                do {
+                    didRestore = restoreOneFile(instream, buffer);
+                } while (didRestore);
+
+                if (DEBUG) Slog.v(TAG, "Done consuming input tarfile, total bytes=" + mBytes);
+            } finally {
+                tearDownPipes();
+                tearDownAgent(mTargetApp);
+
+                try {
+                    mInputFile.close();
+                } catch (IOException e) {
+                    Slog.w(TAG, "Close of restore data pipe threw", e);
+                    /* nothing we can do about this */
+                }
+                synchronized (mCurrentOpLock) {
+                    mCurrentOperations.clear();
+                }
+                synchronized (mLatchObject) {
+                    mLatchObject.set(true);
+                    mLatchObject.notifyAll();
+                }
+                sendEndRestore();
+                mWakelock.release();
+                if (DEBUG) Slog.d(TAG, "Full restore pass complete.");
+            }
+        }
+
+        boolean restoreOneFile(InputStream instream, byte[] buffer) {
+            FileMetadata info;
+            try {
+                info = readTarHeaders(instream);
+                if (info != null) {
+                    if (DEBUG) {
+                        dumpFileMetadata(info);
+                    }
+
+                    final String pkg = info.packageName;
+                    if (!pkg.equals(mAgentPackage)) {
+                        // okay, change in package; set up our various
+                        // bookkeeping if we haven't seen it yet
+                        if (!mPackagePolicies.containsKey(pkg)) {
+                            mPackagePolicies.put(pkg, RestorePolicy.IGNORE);
+                        }
+
+                        // Clean up the previous agent relationship if necessary,
+                        // and let the observer know we're considering a new app.
+                        if (mAgent != null) {
+                            if (DEBUG) Slog.d(TAG, "Saw new package; tearing down old one");
+                            tearDownPipes();
+                            tearDownAgent(mTargetApp);
+                            mTargetApp = null;
+                            mAgentPackage = null;
+                        }
+                    }
+
+                    if (info.path.equals(BACKUP_MANIFEST_FILENAME)) {
+                        mPackagePolicies.put(pkg, readAppManifest(info, instream));
+                        mPackageInstallers.put(pkg, info.installerPackageName);
+                        // We've read only the manifest content itself at this point,
+                        // so consume the footer before looping around to the next
+                        // input file
+                        skipTarPadding(info.size, instream);
+                        sendOnRestorePackage(pkg);
+                    } else {
+                        // Non-manifest, so it's actual file data.  Is this a package
+                        // we're ignoring?
+                        boolean okay = true;
+                        RestorePolicy policy = mPackagePolicies.get(pkg);
+                        switch (policy) {
+                            case IGNORE:
+                                okay = false;
+                                break;
+
+                            case ACCEPT_IF_APK:
+                                // If we're in accept-if-apk state, then the first file we
+                                // see MUST be the apk.
+                                if (info.domain.equals(FullBackup.APK_TREE_TOKEN)) {
+                                    if (DEBUG) Slog.d(TAG, "APK file; installing");
+                                    // Try to install the app.
+                                    String installerName = mPackageInstallers.get(pkg);
+                                    okay = installApk(info, installerName, instream);
+                                    // good to go; promote to ACCEPT
+                                    mPackagePolicies.put(pkg, (okay)
+                                            ? RestorePolicy.ACCEPT
+                                            : RestorePolicy.IGNORE);
+                                    // At this point we've consumed this file entry
+                                    // ourselves, so just strip the tar footer and
+                                    // go on to the next file in the input stream
+                                    skipTarPadding(info.size, instream);
+                                    return true;
+                                } else {
+                                    // File data before (or without) the apk.  We can't
+                                    // handle it coherently in this case so ignore it.
+                                    mPackagePolicies.put(pkg, RestorePolicy.IGNORE);
+                                    okay = false;
+                                }
+                                break;
+
+                            case ACCEPT:
+                                if (info.domain.equals(FullBackup.APK_TREE_TOKEN)) {
+                                    if (DEBUG) Slog.d(TAG, "apk present but ACCEPT");
+                                    // we can take the data without the apk, so we
+                                    // *want* to do so.  skip the apk by declaring this
+                                    // one file not-okay without changing the restore
+                                    // policy for the package.
+                                    okay = false;
+                                }
+                                break;
+
+                            default:
+                                // Something has gone dreadfully wrong when determining
+                                // the restore policy from the manifest.  Ignore the
+                                // rest of this package's data.
+                                Slog.e(TAG, "Invalid policy from manifest");
+                                okay = false;
+                                mPackagePolicies.put(pkg, RestorePolicy.IGNORE);
+                                break;
+                        }
+
+                        // If the policy is satisfied, go ahead and set up to pipe the
+                        // data to the agent.
+                        if (DEBUG && okay && mAgent != null) {
+                            Slog.i(TAG, "Reusing existing agent instance");
+                        }
+                        if (okay && mAgent == null) {
+                            if (DEBUG) Slog.d(TAG, "Need to launch agent for " + pkg);
+
+                            try {
+                                mTargetApp = mPackageManager.getApplicationInfo(pkg, 0);
+
+                                // If we haven't sent any data to this app yet, we probably
+                                // need to clear it first.  Check that.
+                                if (!mClearedPackages.contains(pkg)) {
+                                    // apps with their own full backup agents are
+                                    // responsible for coherently managing a full
+                                    // restore.
+                                    if (mTargetApp.fullBackupAgentName == null) {
+                                        if (DEBUG) Slog.d(TAG, "Clearing app data preparatory to full restore");
+                                        clearApplicationDataSynchronous(pkg);
+                                    } else {
+                                        if (DEBUG) Slog.d(TAG, "full backup agent ("
+                                                + mTargetApp.fullBackupAgentName + ") => no clear");
+                                    }
+                                    mClearedPackages.add(pkg);
+                                } else {
+                                    if (DEBUG) Slog.d(TAG, "We've initialized this app already; no clear required");
+                                }
+
+                                // All set; now set up the IPC and launch the agent
+                                setUpPipes();
+                                mAgent = bindToAgentSynchronous(mTargetApp,
+                                        IApplicationThread.BACKUP_MODE_RESTORE_FULL);
+                                mAgentPackage = pkg;
+                            } catch (IOException e) {
+                                // fall through to error handling
+                            } catch (NameNotFoundException e) {
+                                // fall through to error handling
+                            }
+
+                            if (mAgent == null) {
+                                if (DEBUG) Slog.d(TAG, "Unable to create agent for " + pkg);
+                                okay = false;
+                                tearDownPipes();
+                                mPackagePolicies.put(pkg, RestorePolicy.IGNORE);
+                            }
+                        }
+
+                        // Sanity check: make sure we never give data to the wrong app.  This
+                        // should never happen but a little paranoia here won't go amiss.
+                        if (okay && !pkg.equals(mAgentPackage)) {
+                            Slog.e(TAG, "Restoring data for " + pkg
+                                    + " but agent is for " + mAgentPackage);
+                            okay = false;
+                        }
+
+                        // At this point we have an agent ready to handle the full
+                        // restore data as well as a pipe for sending data to
+                        // that agent.  Tell the agent to start reading from the
+                        // pipe.
+                        if (okay) {
+                            boolean agentSuccess = true;
+                            long toCopy = info.size;
+                            final int token = generateToken();
+                            try {
+                                if (DEBUG) Slog.d(TAG, "Invoking agent to restore file "
+                                        + info.path);
+                                prepareOperationTimeout(token,
+                                        TIMEOUT_FULL_BACKUP_INTERVAL);
+                                // fire up the app's agent listening on the socket.  If
+                                // the agent is running in the system process we can't
+                                // just invoke it asynchronously, so we provide a thread
+                                // for it here.
+                                if (mTargetApp.processName.equals("system")) {
+                                    Slog.d(TAG, "system process agent - spinning a thread");
+                                    RestoreFileRunnable runner = new RestoreFileRunnable(
+                                            mAgent, info, mPipes[0], token);
+                                    new Thread(runner).start();
+                                } else {
+                                    mAgent.doRestoreFile(mPipes[0], info.size, info.type,
+                                            info.domain, info.path, info.mode, info.mtime,
+                                            token, mBackupManagerBinder);
+                                }
+                            } catch (IOException e) {
+                                // couldn't dup the socket for a process-local restore
+                                Slog.d(TAG, "Couldn't establish restore");
+                                agentSuccess = false;
+                                okay = false;
+                            } catch (RemoteException e) {
+                                // whoops, remote agent went away.  We'll eat the content
+                                // ourselves, then, and not copy it over.
+                                Slog.e(TAG, "Agent crashed during full restore");
+                                agentSuccess = false;
+                                okay = false;
+                            }
+
+                            // Copy over the data if the agent is still good
+                            if (okay) {
+                                boolean pipeOkay = true;
+                                FileOutputStream pipe = new FileOutputStream(
+                                        mPipes[1].getFileDescriptor());
+                                if (DEBUG) Slog.d(TAG, "Piping data to agent");
+                                while (toCopy > 0) {
+                                    int toRead = (toCopy > buffer.length)
+                                    ? buffer.length : (int)toCopy;
+                                    int nRead = instream.read(buffer, 0, toRead);
+                                    if (nRead >= 0) mBytes += nRead;
+                                    if (nRead <= 0) break;
+                                    toCopy -= nRead;
+
+                                    // send it to the output pipe as long as things
+                                    // are still good
+                                    if (pipeOkay) {
+                                        try {
+                                            pipe.write(buffer, 0, nRead);
+                                        } catch (IOException e) {
+                                            Slog.e(TAG, "Failed to write to restore pipe", e);
+                                            pipeOkay = false;
+                                        }
+                                    }
+                                }
+
+                                // done sending that file!  Now we just need to consume
+                                // the delta from info.size to the end of block.
+                                skipTarPadding(info.size, instream);
+
+                                // and now that we've sent it all, wait for the remote
+                                // side to acknowledge receipt
+                                agentSuccess = waitUntilOperationComplete(token);
+                            }
+
+                            // okay, if the remote end failed at any point, deal with
+                            // it by ignoring the rest of the restore on it
+                            if (!agentSuccess) {
+                                mBackupHandler.removeMessages(MSG_TIMEOUT);
+                                tearDownPipes();
+                                tearDownAgent(mTargetApp);
+                                mAgent = null;
+                                mPackagePolicies.put(pkg, RestorePolicy.IGNORE);
+                            }
+                        }
+
+                        // Problems setting up the agent communication, or an already-
+                        // ignored package: skip to the next tar stream entry by
+                        // reading and discarding this file.
+                        if (!okay) {
+                            if (DEBUG) Slog.d(TAG, "[discarding file content]");
+                            long bytesToConsume = (info.size + 511) & ~511;
+                            while (bytesToConsume > 0) {
+                                int toRead = (bytesToConsume > buffer.length)
+                                ? buffer.length : (int)bytesToConsume;
+                                long nRead = instream.read(buffer, 0, toRead);
+                                if (nRead >= 0) mBytes += nRead;
+                                if (nRead <= 0) break;
+                                bytesToConsume -= nRead;
+                            }
+                        }
+                    }
+                }
+            } catch (IOException e) {
+                Slog.w(TAG, "io exception on restore socket read", e);
+                // treat as EOF
+                info = null;
+            }
+
+            return (info != null);
+        }
+
+        void setUpPipes() throws IOException {
+            mPipes = ParcelFileDescriptor.createPipe();
+        }
+
+        void tearDownPipes() {
+            if (mPipes != null) {
+                try {
+                    mPipes[0].close();
+                    mPipes[0] = null;
+                    mPipes[1].close();
+                    mPipes[1] = null;
+                } catch (IOException e) {
+                    Slog.w(TAG, "Couldn't close agent pipes", e);
+                }
+                mPipes = null;
+            }
+        }
+
+        void tearDownAgent(ApplicationInfo app) {
+            if (mAgent != null) {
+                try {
+                    // unbind and tidy up even on timeout or failure, just in case
+                    mActivityManager.unbindBackupAgent(app);
+
+                    // The agent was running with a stub Application object, so shut it down.
+                    // !!! We hardcode the confirmation UI's package name here rather than use a
+                    //     manifest flag!  TODO something less direct.
+                    if (app.uid != Process.SYSTEM_UID
+                            && !app.packageName.equals("com.android.backupconfirm")) {
+                        if (DEBUG) Slog.d(TAG, "Killing host process");
+                        mActivityManager.killApplicationProcess(app.processName, app.uid);
+                    } else {
+                        if (DEBUG) Slog.d(TAG, "Not killing after full restore");
+                    }
+                } catch (RemoteException e) {
+                    Slog.d(TAG, "Lost app trying to shut down");
+                }
+                mAgent = null;
+            }
+        }
+
+        class RestoreInstallObserver extends IPackageInstallObserver.Stub {
+            final AtomicBoolean mDone = new AtomicBoolean();
+            String mPackageName;
+            int mResult;
+
+            public void reset() {
+                synchronized (mDone) {
+                    mDone.set(false);
+                }
+            }
+
+            public void waitForCompletion() {
+                synchronized (mDone) {
+                    while (mDone.get() == false) {
+                        try {
+                            mDone.wait();
+                        } catch (InterruptedException e) { }
+                    }
+                }
+            }
+
+            int getResult() {
+                return mResult;
+            }
+
+            @Override
+            public void packageInstalled(String packageName, int returnCode)
+                    throws RemoteException {
+                synchronized (mDone) {
+                    mResult = returnCode;
+                    mPackageName = packageName;
+                    mDone.set(true);
+                    mDone.notifyAll();
+                }
+            }
+        }
+
+        class RestoreDeleteObserver extends IPackageDeleteObserver.Stub {
+            final AtomicBoolean mDone = new AtomicBoolean();
+            int mResult;
+
+            public void reset() {
+                synchronized (mDone) {
+                    mDone.set(false);
+                }
+            }
+
+            public void waitForCompletion() {
+                synchronized (mDone) {
+                    while (mDone.get() == false) {
+                        try {
+                            mDone.wait();
+                        } catch (InterruptedException e) { }
+                    }
+                }
+            }
+
+            @Override
+            public void packageDeleted(String packageName, int returnCode) throws RemoteException {
+                synchronized (mDone) {
+                    mResult = returnCode;
+                    mDone.set(true);
+                    mDone.notifyAll();
+                }
+            }
+        }
+
+        final RestoreInstallObserver mInstallObserver = new RestoreInstallObserver();
+        final RestoreDeleteObserver mDeleteObserver = new RestoreDeleteObserver();
+
+        boolean installApk(FileMetadata info, String installerPackage, InputStream instream) {
+            boolean okay = true;
+
+            if (DEBUG) Slog.d(TAG, "Installing from backup: " + info.packageName);
+
+            // The file content is an .apk file.  Copy it out to a staging location and
+            // attempt to install it.
+            File apkFile = new File(mDataDir, info.packageName);
+            try {
+                FileOutputStream apkStream = new FileOutputStream(apkFile);
+                byte[] buffer = new byte[32 * 1024];
+                long size = info.size;
+                while (size > 0) {
+                    long toRead = (buffer.length < size) ? buffer.length : size;
+                    int didRead = instream.read(buffer, 0, (int)toRead);
+                    if (didRead >= 0) mBytes += didRead;
+                    apkStream.write(buffer, 0, didRead);
+                    size -= didRead;
+                }
+                apkStream.close();
+
+                // make sure the installer can read it
+                apkFile.setReadable(true, false);
+
+                // Now install it
+                Uri packageUri = Uri.fromFile(apkFile);
+                mInstallObserver.reset();
+                mPackageManager.installPackage(packageUri, mInstallObserver,
+                        PackageManager.INSTALL_REPLACE_EXISTING, installerPackage);
+                mInstallObserver.waitForCompletion();
+
+                if (mInstallObserver.getResult() != PackageManager.INSTALL_SUCCEEDED) {
+                    // The only time we continue to accept install of data even if the
+                    // apk install failed is if we had already determined that we could
+                    // accept the data regardless.
+                    if (mPackagePolicies.get(info.packageName) != RestorePolicy.ACCEPT) {
+                        okay = false;
+                    }
+                } else {
+                    // Okay, the install succeeded.  Make sure it was the right app.
+                    boolean uninstall = false;
+                    if (!mInstallObserver.mPackageName.equals(info.packageName)) {
+                        Slog.w(TAG, "Restore stream claimed to include apk for "
+                                + info.packageName + " but apk was really "
+                                + mInstallObserver.mPackageName);
+                        // delete the package we just put in place; it might be fraudulent
+                        okay = false;
+                        uninstall = true;
+                    } else {
+                        try {
+                            PackageInfo pkg = mPackageManager.getPackageInfo(info.packageName,
+                                    PackageManager.GET_SIGNATURES);
+                            if ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_ALLOW_BACKUP) == 0) {
+                                Slog.w(TAG, "Restore stream contains apk of package "
+                                        + info.packageName + " but it disallows backup/restore");
+                                okay = false;
+                            } else {
+                                // So far so good -- do the signatures match the manifest?
+                                Signature[] sigs = mManifestSignatures.get(info.packageName);
+                                if (!signaturesMatch(sigs, pkg)) {
+                                    Slog.w(TAG, "Installed app " + info.packageName
+                                            + " signatures do not match restore manifest");
+                                    okay = false;
+                                    uninstall = true;
+                                }
+                            }
+                        } catch (NameNotFoundException e) {
+                            Slog.w(TAG, "Install of package " + info.packageName
+                                    + " succeeded but now not found");
+                            okay = false;
+                        }
+                    }
+
+                    // If we're not okay at this point, we need to delete the package
+                    // that we just installed.
+                    if (uninstall) {
+                        mDeleteObserver.reset();
+                        mPackageManager.deletePackage(mInstallObserver.mPackageName,
+                                mDeleteObserver, 0);
+                        mDeleteObserver.waitForCompletion();
+                    }
+                }
+            } catch (IOException e) {
+                Slog.e(TAG, "Unable to transcribe restored apk for install");
+                okay = false;
+            } finally {
+                apkFile.delete();
+            }
+
+            return okay;
+        }
+
+        // Given an actual file content size, consume the post-content padding mandated
+        // by the tar format.
+        void skipTarPadding(long size, InputStream instream) throws IOException {
+            long partial = (size + 512) % 512;
+            if (partial > 0) {
+                byte[] buffer = new byte[512];
+                int nRead = instream.read(buffer, 0, 512 - (int)partial);
+                if (nRead >= 0) mBytes += nRead;
+            }
+        }
+
+        // Returns a policy constant; takes a buffer arg to reduce memory churn
+        RestorePolicy readAppManifest(FileMetadata info, InputStream instream)
+                throws IOException {
+            // Fail on suspiciously large manifest files
+            if (info.size > 64 * 1024) {
+                throw new IOException("Restore manifest too big; corrupt? size=" + info.size);
+            }
+            byte[] buffer = new byte[(int) info.size];
+            int nRead = 0;
+            while (nRead < info.size) {
+                nRead += instream.read(buffer, nRead, (int)info.size - nRead);
+            }
+            if (nRead >= 0) mBytes += nRead;
+
+            RestorePolicy policy = RestorePolicy.IGNORE;
+            String[] str = new String[1];
+            int offset = 0;
+
+            try {
+                offset = extractLine(buffer, offset, str);
+                int version = Integer.parseInt(str[0]);
+                if (version == BACKUP_MANIFEST_VERSION) {
+                    offset = extractLine(buffer, offset, str);
+                    String manifestPackage = str[0];
+                    // TODO: handle <original-package>
+                    if (manifestPackage.equals(info.packageName)) {
+                        offset = extractLine(buffer, offset, str);
+                        version = Integer.parseInt(str[0]);  // app version
+                        offset = extractLine(buffer, offset, str);
+                        int platformVersion = Integer.parseInt(str[0]);
+                        offset = extractLine(buffer, offset, str);
+                        info.installerPackageName = (str[0].length() > 0) ? str[0] : null;
+                        offset = extractLine(buffer, offset, str);
+                        boolean hasApk = str[0].equals("1");
+                        offset = extractLine(buffer, offset, str);
+                        int numSigs = Integer.parseInt(str[0]);
+                        if (numSigs > 0) {
+                            Signature[] sigs = new Signature[numSigs];
+                            for (int i = 0; i < numSigs; i++) {
+                                offset = extractLine(buffer, offset, str);
+                                sigs[i] = new Signature(str[0]);
+                            }
+                            mManifestSignatures.put(info.packageName, sigs);
+
+                            // Okay, got the manifest info we need...
+                            try {
+                                PackageInfo pkgInfo = mPackageManager.getPackageInfo(
+                                        info.packageName, PackageManager.GET_SIGNATURES);
+                                // Fall through to IGNORE if the app explicitly disallows backup
+                                final int flags = pkgInfo.applicationInfo.flags;
+                                if ((flags & ApplicationInfo.FLAG_ALLOW_BACKUP) != 0) {
+                                    // Verify signatures against any installed version; if they
+                                    // don't match, then we fall though and ignore the data.  The
+                                    // signatureMatch() method explicitly ignores the signature
+                                    // check for packages installed on the system partition, because
+                                    // such packages are signed with the platform cert instead of
+                                    // the app developer's cert, so they're different on every
+                                    // device.
+                                    if (signaturesMatch(sigs, pkgInfo)) {
+                                        if (pkgInfo.versionCode >= version) {
+                                            Slog.i(TAG, "Sig + version match; taking data");
+                                            policy = RestorePolicy.ACCEPT;
+                                        } else {
+                                            // The data is from a newer version of the app than
+                                            // is presently installed.  That means we can only
+                                            // use it if the matching apk is also supplied.
+                                            Slog.d(TAG, "Data version " + version
+                                                    + " is newer than installed version "
+                                                    + pkgInfo.versionCode + " - requiring apk");
+                                            policy = RestorePolicy.ACCEPT_IF_APK;
+                                        }
+                                    } else {
+                                        Slog.w(TAG, "Restore manifest signatures do not match "
+                                                + "installed application for " + info.packageName);
+                                    }
+                                } else {
+                                    if (DEBUG) Slog.i(TAG, "Restore manifest from "
+                                            + info.packageName + " but allowBackup=false");
+                                }
+                            } catch (NameNotFoundException e) {
+                                // Okay, the target app isn't installed.  We can process
+                                // the restore properly only if the dataset provides the
+                                // apk file and we can successfully install it.
+                                if (DEBUG) Slog.i(TAG, "Package " + info.packageName
+                                        + " not installed; requiring apk in dataset");
+                                policy = RestorePolicy.ACCEPT_IF_APK;
+                            }
+
+                            if (policy == RestorePolicy.ACCEPT_IF_APK && !hasApk) {
+                                Slog.i(TAG, "Cannot restore package " + info.packageName
+                                        + " without the matching .apk");
+                            }
+                        } else {
+                            Slog.i(TAG, "Missing signature on backed-up package "
+                                    + info.packageName);
+                        }
+                    } else {
+                        Slog.i(TAG, "Expected package " + info.packageName
+                                + " but restore manifest claims " + manifestPackage);
+                    }
+                } else {
+                    Slog.i(TAG, "Unknown restore manifest version " + version
+                            + " for package " + info.packageName);
+                }
+            } catch (NumberFormatException e) {
+                Slog.w(TAG, "Corrupt restore manifest for package " + info.packageName);
+            }
+
+            return policy;
+        }
+
+        // Builds a line from a byte buffer starting at 'offset', and returns
+        // the index of the next unconsumed data in the buffer.
+        int extractLine(byte[] buffer, int offset, String[] outStr) throws IOException {
+            final int end = buffer.length;
+            if (offset >= end) throw new IOException("Incomplete data");
+
+            int pos;
+            for (pos = offset; pos < end; pos++) {
+                byte c = buffer[pos];
+                // at LF we declare end of line, and return the next char as the
+                // starting point for the next time through
+                if (c == '\n') {
+                    break;
+                }
+            }
+            outStr[0] = new String(buffer, offset, pos - offset);
+            pos++;  // may be pointing an extra byte past the end but that's okay
+            return pos;
+        }
+
+        void dumpFileMetadata(FileMetadata info) {
+            if (DEBUG) {
+                StringBuilder b = new StringBuilder(128);
+
+                // mode string
+                b.append((info.type == FullBackup.TYPE_DIRECTORY) ? 'd' : '-');
+                b.append(((info.mode & 0400) != 0) ? 'r' : '-');
+                b.append(((info.mode & 0200) != 0) ? 'w' : '-');
+                b.append(((info.mode & 0100) != 0) ? 'x' : '-');
+                b.append(((info.mode & 0040) != 0) ? 'r' : '-');
+                b.append(((info.mode & 0020) != 0) ? 'w' : '-');
+                b.append(((info.mode & 0010) != 0) ? 'x' : '-');
+                b.append(((info.mode & 0004) != 0) ? 'r' : '-');
+                b.append(((info.mode & 0002) != 0) ? 'w' : '-');
+                b.append(((info.mode & 0001) != 0) ? 'x' : '-');
+                b.append(String.format(" %9d ", info.size));
+
+                Date stamp = new Date(info.mtime);
+                b.append(new SimpleDateFormat("MMM dd kk:mm:ss ").format(stamp));
+
+                b.append(info.packageName);
+                b.append(" :: ");
+                b.append(info.domain);
+                b.append(" :: ");
+                b.append(info.path);
+
+                Slog.i(TAG, b.toString());
+            }
+        }
+        // Consume a tar file header block [sequence] and accumulate the relevant metadata
+        FileMetadata readTarHeaders(InputStream instream) throws IOException {
+            byte[] block = new byte[512];
+            FileMetadata info = null;
+
+            boolean gotHeader = readTarHeader(instream, block);
+            if (gotHeader) {
+                // okay, presume we're okay, and extract the various metadata
+                info = new FileMetadata();
+                info.size = extractRadix(block, 124, 12, 8);
+                info.mtime = extractRadix(block, 136, 12, 8);
+                info.mode = extractRadix(block, 100, 8, 8);
+
+                info.path = extractString(block, 345, 155); // prefix
+                String path = extractString(block, 0, 100);
+                if (path.length() > 0) {
+                    if (info.path.length() > 0) info.path += '/';
+                    info.path += path;
+                }
+
+                // tar link indicator field: 1 byte at offset 156 in the header.
+                int typeChar = block[156];
+                if (typeChar == 'x') {
+                    // pax extended header, so we need to read that
+                    gotHeader = readPaxExtendedHeader(instream, info);
+                    if (gotHeader) {
+                        // and after a pax extended header comes another real header -- read
+                        // that to find the real file type
+                        gotHeader = readTarHeader(instream, block);
+                    }
+                    if (!gotHeader) throw new IOException("Bad or missing pax header");
+
+                    typeChar = block[156];
+                }
+
+                switch (typeChar) {
+                    case '0': info.type = FullBackup.TYPE_FILE; break;
+                    case '5': {
+                        info.type = FullBackup.TYPE_DIRECTORY;
+                        if (info.size != 0) {
+                            Slog.w(TAG, "Directory entry with nonzero size in header");
+                            info.size = 0;
+                        }
+                        break;
+                    }
+                    case 0: {
+                        // presume EOF
+                        if (DEBUG) Slog.w(TAG, "Saw type=0 in tar header block, info=" + info);
+                        return null;
+                    }
+                    default: {
+                        Slog.e(TAG, "Unknown tar entity type: " + typeChar);
+                        throw new IOException("Unknown entity type " + typeChar);
+                    }
+                }
+
+                // Parse out the path
+                //
+                // first: apps/shared/unrecognized
+                if (FullBackup.SHARED_PREFIX.regionMatches(0,
+                        info.path, 0, FullBackup.SHARED_PREFIX.length())) {
+                    // File in shared storage.  !!! TODO: implement this.
+                    info.path = info.path.substring(FullBackup.SHARED_PREFIX.length());
+                    info.packageName = "com.android.sharedstoragebackup";
+                    info.domain = FullBackup.SHARED_STORAGE_TOKEN;
+                    if (DEBUG) Slog.i(TAG, "File in shared storage: " + info.path);
+                } else if (FullBackup.APPS_PREFIX.regionMatches(0,
+                        info.path, 0, FullBackup.APPS_PREFIX.length())) {
+                    // App content!  Parse out the package name and domain
+
+                    // strip the apps/ prefix
+                    info.path = info.path.substring(FullBackup.APPS_PREFIX.length());
+
+                    // extract the package name
+                    int slash = info.path.indexOf('/');
+                    if (slash < 0) throw new IOException("Illegal semantic path in " + info.path);
+                    info.packageName = info.path.substring(0, slash);
+                    info.path = info.path.substring(slash+1);
+
+                    // if it's a manifest we're done, otherwise parse out the domains
+                    if (!info.path.equals(BACKUP_MANIFEST_FILENAME)) {
+                        slash = info.path.indexOf('/');
+                        if (slash < 0) throw new IOException("Illegal semantic path in non-manifest " + info.path);
+                        info.domain = info.path.substring(0, slash);
+                        // validate that it's one of the domains we understand
+                        if (!info.domain.equals(FullBackup.APK_TREE_TOKEN)
+                                && !info.domain.equals(FullBackup.DATA_TREE_TOKEN)
+                                && !info.domain.equals(FullBackup.DATABASE_TREE_TOKEN)
+                                && !info.domain.equals(FullBackup.ROOT_TREE_TOKEN)
+                                && !info.domain.equals(FullBackup.SHAREDPREFS_TREE_TOKEN)
+                                && !info.domain.equals(FullBackup.OBB_TREE_TOKEN)
+                                && !info.domain.equals(FullBackup.CACHE_TREE_TOKEN)) {
+                            throw new IOException("Unrecognized domain " + info.domain);
+                        }
+
+                        info.path = info.path.substring(slash + 1);
+                    }
+                }
+            }
+            return info;
+        }
+
+        boolean readTarHeader(InputStream instream, byte[] block) throws IOException {
+            int nRead = instream.read(block, 0, 512);
+            if (nRead >= 0) mBytes += nRead;
+            if (nRead > 0 && nRead != 512) {
+                // if we read only a partial block, then things are
+                // clearly screwed up.  terminate the restore.
+                throw new IOException("Partial header block: " + nRead);
+            }
+            return (nRead > 0);
+        }
+
+        // overwrites 'info' fields based on the pax extended header
+        boolean readPaxExtendedHeader(InputStream instream, FileMetadata info)
+                throws IOException {
+            // We should never see a pax extended header larger than this
+            if (info.size > 32*1024) {
+                Slog.w(TAG, "Suspiciously large pax header size " + info.size
+                        + " - aborting");
+                throw new IOException("Sanity failure: pax header size " + info.size);
+            }
+
+            // read whole blocks, not just the content size
+            int numBlocks = (int)((info.size + 511) >> 9);
+            byte[] data = new byte[numBlocks * 512];
+            int nRead = instream.read(data);
+            if (nRead >= 0) mBytes += nRead;
+            if (nRead != data.length) {
+                return false;
+            }
+
+            final int contentSize = (int) info.size;
+            int offset = 0;
+            do {
+                // extract the line at 'offset'
+                int eol = offset+1;
+                while (eol < contentSize && data[eol] != ' ') eol++;
+                if (eol >= contentSize) {
+                    // error: we just hit EOD looking for the end of the size field
+                    throw new IOException("Invalid pax data");
+                }
+                // eol points to the space between the count and the key
+                int linelen = (int) extractRadix(data, offset, eol - offset, 10);
+                int key = eol + 1;  // start of key=value
+                eol = offset + linelen - 1; // trailing LF
+                int value;
+                for (value = key+1; data[value] != '=' && value <= eol; value++);
+                if (value > eol) {
+                    throw new IOException("Invalid pax declaration");
+                }
+
+                // pax requires that key/value strings be in UTF-8
+                String keyStr = new String(data, key, value-key, "UTF-8");
+                // -1 to strip the trailing LF
+                String valStr = new String(data, value+1, eol-value-1, "UTF-8");
+
+                if ("path".equals(keyStr)) {
+                    info.path = valStr;
+                } else if ("size".equals(keyStr)) {
+                    info.size = Long.parseLong(valStr);
+                } else {
+                    if (DEBUG) Slog.i(TAG, "Unhandled pax key: " + key);
+                }
+
+                offset += linelen;
+            } while (offset < contentSize);
+
+            return true;
+        }
+
+        long extractRadix(byte[] data, int offset, int maxChars, int radix)
+                throws IOException {
+            long value = 0;
+            final int end = offset + maxChars;
+            for (int i = offset; i < end; i++) {
+                final byte b = data[i];
+                // Numeric fields in tar can terminate with either NUL or SPC
+                if (b == 0 || b == ' ') break;
+                if (b < '0' || b > ('0' + radix - 1)) {
+                    throw new IOException("Invalid number in header");
+                }
+                value = radix * value + (b - '0');
+            }
+            return value;
+        }
+
+        String extractString(byte[] data, int offset, int maxChars) throws IOException {
+            final int end = offset + maxChars;
+            int eos = offset;
+            // tar string fields terminate early with a NUL
+            while (eos < end && data[eos] != 0) eos++;
+            return new String(data, offset, eos-offset, "US-ASCII");
+        }
+
+        void sendStartRestore() {
+            if (mObserver != null) {
+                try {
+                    mObserver.onStartRestore();
+                } catch (RemoteException e) {
+                    Slog.w(TAG, "full restore observer went away: startRestore");
+                    mObserver = null;
+                }
+            }
+        }
+
+        void sendOnRestorePackage(String name) {
+            if (mObserver != null) {
+                try {
+                    // TODO: use a more user-friendly name string
+                    mObserver.onRestorePackage(name);
+                } catch (RemoteException e) {
+                    Slog.w(TAG, "full restore observer went away: restorePackage");
+                    mObserver = null;
+                }
+            }
+        }
+
+        void sendEndRestore() {
+            if (mObserver != null) {
+                try {
+                    mObserver.onEndRestore();
+                } catch (RemoteException e) {
+                    Slog.w(TAG, "full restore observer went away: endRestore");
+                    mObserver = null;
+                }
+            }
+        }
+    }
+
     // ----- Restore handling -----
 
     private boolean signaturesMatch(Signature[] storedSigs, PackageInfo target) {
@@ -2583,41 +3662,95 @@
                 mFullConfirmations.put(token, params);
             }
 
-            // start up the confirmation UI, making sure the screen lights up
-            if (DEBUG) Slog.d(TAG, "Starting confirmation UI, token=" + token);
-            try {
-                Intent confIntent = new Intent(FullBackup.FULL_BACKUP_INTENT_ACTION);
-                confIntent.setClassName("com.android.backupconfirm",
-                        "com.android.backupconfirm.BackupRestoreConfirmation");
-                confIntent.putExtra(FullBackup.CONF_TOKEN_INTENT_EXTRA, token);
-                confIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-                mContext.startActivity(confIntent);
-            } catch (ActivityNotFoundException e) {
-                Slog.e(TAG, "Unable to launch full backup confirmation", e);
+            // start up the confirmation UI
+            if (DEBUG) Slog.d(TAG, "Starting backup confirmation UI, token=" + token);
+            if (!startConfirmationUi(token, FullBackup.FULL_BACKUP_INTENT_ACTION)) {
+                Slog.e(TAG, "Unable to launch full backup confirmation");
                 mFullConfirmations.delete(token);
                 return;
             }
+
+            // make sure the screen is lit for the user interaction
             mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
 
             // start the confirmation countdown
-            if (DEBUG) Slog.d(TAG, "Posting conf timeout msg after "
-                    + TIMEOUT_FULL_CONFIRMATION + " millis");
-            Message msg = mBackupHandler.obtainMessage(MSG_FULL_CONFIRMATION_TIMEOUT,
-                    token, 0, params);
-            mBackupHandler.sendMessageDelayed(msg, TIMEOUT_FULL_CONFIRMATION);
+            startConfirmationTimeout(token, params);
 
             // wait for the backup to be performed
             if (DEBUG) Slog.d(TAG, "Waiting for full backup completion...");
             waitForCompletion(params);
-            if (DEBUG) Slog.d(TAG, "...Full backup operation complete!");
         } finally {
-            Binder.restoreCallingIdentity(oldId);
             try {
                 fd.close();
             } catch (IOException e) {
                 // just eat it
             }
+            Binder.restoreCallingIdentity(oldId);
         }
+        if (DEBUG) Slog.d(TAG, "Full backup done; returning to caller");
+    }
+
+    public void fullRestore(ParcelFileDescriptor fd) {
+        mContext.enforceCallingPermission(android.Manifest.permission.BACKUP, "fullBackup");
+        Slog.i(TAG, "Beginning full restore...");
+
+        long oldId = Binder.clearCallingIdentity();
+
+        try {
+            FullRestoreParams params = new FullRestoreParams(fd);
+            final int token = generateToken();
+            synchronized (mFullConfirmations) {
+                mFullConfirmations.put(token, params);
+            }
+
+            // start up the confirmation UI
+            if (DEBUG) Slog.d(TAG, "Starting restore confirmation UI, token=" + token);
+            if (!startConfirmationUi(token, FullBackup.FULL_RESTORE_INTENT_ACTION)) {
+                Slog.e(TAG, "Unable to launch full restore confirmation");
+                mFullConfirmations.delete(token);
+                return;
+            }
+
+            // make sure the screen is lit for the user interaction
+            mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
+
+            // start the confirmation countdown
+            startConfirmationTimeout(token, params);
+
+            // wait for the restore to be performed
+            if (DEBUG) Slog.d(TAG, "Waiting for full restore completion...");
+            waitForCompletion(params);
+        } finally {
+            try {
+                fd.close();
+            } catch (IOException e) {
+                Slog.w(TAG, "Error trying to close fd after full restore: " + e);
+            }
+            Binder.restoreCallingIdentity(oldId);
+            Slog.i(TAG, "Full restore completed");
+        }
+    }
+
+    boolean startConfirmationUi(int token, String action) {
+        try {
+            Intent confIntent = new Intent(action);
+            confIntent.setClassName("com.android.backupconfirm",
+                    "com.android.backupconfirm.BackupRestoreConfirmation");
+            confIntent.putExtra(FullBackup.CONF_TOKEN_INTENT_EXTRA, token);
+            confIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+            mContext.startActivity(confIntent);
+        } catch (ActivityNotFoundException e) {
+            return false;
+        }
+        return true;
+    }
+
+    void startConfirmationTimeout(int token, FullParams params) {
+        if (DEBUG) Slog.d(TAG, "Posting conf timeout msg after "
+                + TIMEOUT_FULL_CONFIRMATION + " millis");
+        Message msg = mBackupHandler.obtainMessage(MSG_FULL_CONFIRMATION_TIMEOUT,
+                token, 0, params);
+        mBackupHandler.sendMessageDelayed(msg, TIMEOUT_FULL_CONFIRMATION);
     }
 
     void waitForCompletion(FullParams params) {
@@ -2661,9 +3794,10 @@
                     if (allow) {
                         params.observer = observer;
                         final int verb = params instanceof FullBackupParams
-                        ? MSG_RUN_FULL_BACKUP
+                                ? MSG_RUN_FULL_BACKUP
                                 : MSG_RUN_FULL_RESTORE;
 
+                        if (DEBUG) Slog.d(TAG, "Sending conf message with verb " + verb);
                         mWakelock.acquire();
                         Message msg = mBackupHandler.obtainMessage(verb, params);
                         mBackupHandler.sendMessage(msg);
diff --git a/services/java/com/android/server/ConnectivityService.java b/services/java/com/android/server/ConnectivityService.java
index d2fd04b..aa3dfa6 100644
--- a/services/java/com/android/server/ConnectivityService.java
+++ b/services/java/com/android/server/ConnectivityService.java
@@ -16,6 +16,11 @@
 
 package com.android.server;
 
+import static android.Manifest.permission.MANAGE_NETWORK_POLICY;
+import static android.net.ConnectivityManager.isNetworkTypeValid;
+import static android.net.NetworkPolicyManager.RULE_ALLOW_ALL;
+import static android.net.NetworkPolicyManager.RULE_REJECT_METERED;
+
 import android.bluetooth.BluetoothTetheringDataTracker;
 import android.content.ContentResolver;
 import android.content.Context;
@@ -26,11 +31,14 @@
 import android.net.DummyDataStateTracker;
 import android.net.EthernetDataTracker;
 import android.net.IConnectivityManager;
-import android.net.LinkAddress;
+import android.net.INetworkPolicyListener;
+import android.net.INetworkPolicyManager;
 import android.net.LinkProperties;
 import android.net.MobileDataStateTracker;
 import android.net.NetworkConfig;
 import android.net.NetworkInfo;
+import android.net.NetworkInfo.DetailedState;
+import android.net.NetworkState;
 import android.net.NetworkStateTracker;
 import android.net.NetworkUtils;
 import android.net.Proxy;
@@ -39,12 +47,14 @@
 import android.net.vpn.VpnManager;
 import android.net.wifi.WifiStateTracker;
 import android.os.Binder;
+import android.os.FileUtils;
 import android.os.Handler;
 import android.os.HandlerThread;
 import android.os.IBinder;
 import android.os.INetworkManagementService;
 import android.os.Looper;
 import android.os.Message;
+import android.os.ParcelFileDescriptor;
 import android.os.PowerManager;
 import android.os.RemoteException;
 import android.os.ServiceManager;
@@ -53,22 +63,28 @@
 import android.text.TextUtils;
 import android.util.EventLog;
 import android.util.Slog;
+import android.util.SparseIntArray;
 
+import com.android.internal.net.VpnConfig;
 import com.android.internal.telephony.Phone;
 import com.android.server.connectivity.Tethering;
+import com.android.server.connectivity.Vpn;
+
+import com.google.android.collect.Lists;
+import com.google.android.collect.Sets;
 
 import java.io.FileDescriptor;
-import java.io.FileWriter;
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.net.InetAddress;
-import java.net.Inet4Address;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
-import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.GregorianCalendar;
+import java.util.HashSet;
 import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 /**
  * @hide
@@ -78,6 +94,8 @@
     private static final boolean DBG = true;
     private static final String TAG = "ConnectivityService";
 
+    private static final boolean LOGD_RULES = false;
+
     // how long to wait before switching back to a radio's default network
     private static final int RESTORE_DEFAULT_NETWORK_DELAY = 1 * 60 * 1000;
     // system property that can override the above value
@@ -91,6 +109,15 @@
     private Tethering mTethering;
     private boolean mTetheringConfigValid = false;
 
+    private Vpn mVpn;
+
+    /** Lock around {@link #mUidRules} and {@link #mMeteredIfaces}. */
+    private Object mRulesLock = new Object();
+    /** Currently active network rules by UID. */
+    private SparseIntArray mUidRules = new SparseIntArray();
+    /** Set of ifaces that are costly. */
+    private HashSet<String> mMeteredIfaces = Sets.newHashSet();
+
     /**
      * Sometimes we want to refer to the individual network state
      * trackers separately, and sometimes we just want to treat them
@@ -128,6 +155,7 @@
     private AtomicBoolean mBackgroundDataEnabled = new AtomicBoolean(true);
 
     private INetworkManagementService mNetd;
+    private INetworkPolicyManager mPolicyManager;
 
     private static final int ENABLED  = 1;
     private static final int DISABLED = 0;
@@ -250,14 +278,8 @@
     }
     RadioAttributes[] mRadioAttributes;
 
-    public static synchronized ConnectivityService getInstance(Context context) {
-        if (sServiceInstance == null) {
-            sServiceInstance = new ConnectivityService(context);
-        }
-        return sServiceInstance;
-    }
-
-    private ConnectivityService(Context context) {
+    public ConnectivityService(
+            Context context, INetworkManagementService netd, INetworkPolicyManager policyManager) {
         if (DBG) log("ConnectivityService starting up");
 
         HandlerThread handlerThread = new HandlerThread("ConnectivityServiceThread");
@@ -290,9 +312,19 @@
             loge("Error setting defaultDns using " + dns);
         }
 
-        mContext = context;
+        mContext = checkNotNull(context, "missing Context");
+        mNetd = checkNotNull(netd, "missing INetworkManagementService");
+        mPolicyManager = checkNotNull(policyManager, "missing INetworkPolicyManager");
 
-        PowerManager powerManager = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE);
+        try {
+            mPolicyManager.registerListener(mPolicyListener);
+        } catch (RemoteException e) {
+            // ouch, no rules updates means some processes may never get network
+            Slog.e(TAG, "unable to register INetworkPolicyListener", e);
+        }
+
+        final PowerManager powerManager = (PowerManager) context.getSystemService(
+                Context.POWER_SERVICE);
         mNetTransitionWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
         mNetTransitionWakeLockTimeout = mContext.getResources().getInteger(
                 com.android.internal.R.integer.config_networkTransitionTimeout);
@@ -441,6 +473,15 @@
                                   mTethering.getTetherableBluetoothRegexs().length != 0) &&
                                  mTethering.getUpstreamIfaceRegexs().length != 0);
 
+        mVpn = new Vpn(mContext, new VpnCallback());
+
+        try {
+            nmService.registerObserver(mTethering);
+            nmService.registerObserver(mVpn);
+        } catch (RemoteException e) {
+            loge("Error registering observer :" + e);
+        }
+
         if (DBG) {
             mInetLog = new ArrayList();
         }
@@ -536,34 +577,93 @@
     }
 
     /**
+     * Check if UID should be blocked from using the network represented by the
+     * given {@link NetworkStateTracker}.
+     */
+    private boolean isNetworkBlocked(NetworkStateTracker tracker, int uid) {
+        final String iface = tracker.getLinkProperties().getInterfaceName();
+
+        final boolean networkCostly;
+        final int uidRules;
+        synchronized (mRulesLock) {
+            networkCostly = mMeteredIfaces.contains(iface);
+            uidRules = mUidRules.get(uid, RULE_ALLOW_ALL);
+        }
+
+        if (networkCostly && (uidRules & RULE_REJECT_METERED) != 0) {
+            return true;
+        }
+
+        // no restrictive rules; network is visible
+        return false;
+    }
+
+    /**
+     * Return a filtered {@link NetworkInfo}, potentially marked
+     * {@link DetailedState#BLOCKED} based on
+     * {@link #isNetworkBlocked(NetworkStateTracker, int)}.
+     */
+    private NetworkInfo getFilteredNetworkInfo(NetworkStateTracker tracker, int uid) {
+        NetworkInfo info = tracker.getNetworkInfo();
+        if (isNetworkBlocked(tracker, uid)) {
+            // network is blocked; clone and override state
+            info = new NetworkInfo(info);
+            info.setDetailedState(DetailedState.BLOCKED, null, null);
+        }
+        return info;
+    }
+
+    /**
      * Return NetworkInfo for the active (i.e., connected) network interface.
      * It is assumed that at most one network is active at a time. If more
      * than one is active, it is indeterminate which will be returned.
      * @return the info for the active network, or {@code null} if none is
      * active
      */
+    @Override
     public NetworkInfo getActiveNetworkInfo() {
-        return getNetworkInfo(mActiveDefaultNetwork);
+        enforceAccessPermission();
+        final int uid = Binder.getCallingUid();
+        return getNetworkInfo(mActiveDefaultNetwork, uid);
     }
 
+    @Override
+    public NetworkInfo getActiveNetworkInfoForUid(int uid) {
+        enforceConnectivityInternalPermission();
+        return getNetworkInfo(mActiveDefaultNetwork, uid);
+    }
+
+    @Override
     public NetworkInfo getNetworkInfo(int networkType) {
         enforceAccessPermission();
-        if (ConnectivityManager.isNetworkTypeValid(networkType)) {
-            NetworkStateTracker t = mNetTrackers[networkType];
-            if (t != null)
-                return t.getNetworkInfo();
-        }
-        return null;
+        final int uid = Binder.getCallingUid();
+        return getNetworkInfo(networkType, uid);
     }
 
+    private NetworkInfo getNetworkInfo(int networkType, int uid) {
+        NetworkInfo info = null;
+        if (isNetworkTypeValid(networkType)) {
+            final NetworkStateTracker tracker = mNetTrackers[networkType];
+            if (tracker != null) {
+                info = getFilteredNetworkInfo(tracker, uid);
+            }
+        }
+        return info;
+    }
+
+    @Override
     public NetworkInfo[] getAllNetworkInfo() {
         enforceAccessPermission();
-        NetworkInfo[] result = new NetworkInfo[mNetworksDefined];
-        int i = 0;
-        for (NetworkStateTracker t : mNetTrackers) {
-            if(t != null) result[i++] = t.getNetworkInfo();
+        final int uid = Binder.getCallingUid();
+        final ArrayList<NetworkInfo> result = Lists.newArrayList();
+        synchronized (mRulesLock) {
+            for (NetworkStateTracker tracker : mNetTrackers) {
+                if (tracker != null) {
+                    result.add(getFilteredNetworkInfo(tracker, uid));
+                }
+            }
         }
-        return result;
+        return result.toArray(new NetworkInfo[result.size()]);
     }
 
     /**
@@ -574,19 +674,40 @@
      * @return the ip properties for the active network, or {@code null} if
      * none is active
      */
+    @Override
     public LinkProperties getActiveLinkProperties() {
         return getLinkProperties(mActiveDefaultNetwork);
     }
 
+    @Override
     public LinkProperties getLinkProperties(int networkType) {
         enforceAccessPermission();
-        if (ConnectivityManager.isNetworkTypeValid(networkType)) {
-            NetworkStateTracker t = mNetTrackers[networkType];
-            if (t != null) return t.getLinkProperties();
+        if (isNetworkTypeValid(networkType)) {
+            final NetworkStateTracker tracker = mNetTrackers[networkType];
+            if (tracker != null) {
+                return tracker.getLinkProperties();
+            }
         }
         return null;
     }
 
+    @Override
+    public NetworkState[] getAllNetworkState() {
+        enforceAccessPermission();
+        final int uid = Binder.getCallingUid();
+        final ArrayList<NetworkState> result = Lists.newArrayList();
+        synchronized (mRulesLock) {
+            for (NetworkStateTracker tracker : mNetTrackers) {
+                if (tracker != null) {
+                    final NetworkInfo info = getFilteredNetworkInfo(tracker, uid);
+                    result.add(new NetworkState(
+                            info, tracker.getLinkProperties(), tracker.getLinkCapabilities()));
+                }
+            }
+        }
+        return result.toArray(new NetworkState[result.size()]);
+    }
+
     public boolean setRadios(boolean turnOn) {
         boolean result = true;
         enforceChangePermission();
@@ -1027,6 +1148,47 @@
         }
     }
 
+    private INetworkPolicyListener mPolicyListener = new INetworkPolicyListener.Stub() {
+        @Override
+        public void onUidRulesChanged(int uid, int uidRules) {
+            // only someone like NPMS should only be calling us
+            mContext.enforceCallingOrSelfPermission(MANAGE_NETWORK_POLICY, TAG);
+
+            if (LOGD_RULES) {
+                Slog.d(TAG, "onUidRulesChanged(uid=" + uid + ", uidRules=" + uidRules + ")");
+            }
+
+            synchronized (mRulesLock) {
+                // skip update when we've already applied rules
+                final int oldRules = mUidRules.get(uid, RULE_ALLOW_ALL);
+                if (oldRules == uidRules) return;
+
+                mUidRules.put(uid, uidRules);
+            }
+
+            // TODO: dispatch into NMS to push rules towards kernel module
+            // TODO: notify UID when it has requested targeted updates
+        }
+
+        @Override
+        public void onMeteredIfacesChanged(String[] meteredIfaces) {
+            // only someone like NPMS should only be calling us
+            mContext.enforceCallingOrSelfPermission(MANAGE_NETWORK_POLICY, TAG);
+
+            if (LOGD_RULES) {
+                Slog.d(TAG,
+                        "onMeteredIfacesChanged(ifaces=" + Arrays.toString(meteredIfaces) + ")");
+            }
+
+            synchronized (mRulesLock) {
+                mMeteredIfaces.clear();
+                for (String iface : meteredIfaces) {
+                    mMeteredIfaces.add(iface);
+                }
+            }
+        }
+    };
+
     /**
      * @see ConnectivityManager#setMobileDataEnabled(boolean)
      */
@@ -1132,8 +1294,30 @@
             }
         }
         intent.putExtra(ConnectivityManager.EXTRA_INET_CONDITION, mDefaultInetConditionPublished);
+
+        // Reset interface if no other connections are using the same interface
+        boolean doReset = true;
+        LinkProperties linkProperties = mNetTrackers[prevNetType].getLinkProperties();
+        if (linkProperties != null) {
+            String oldIface = linkProperties.getInterfaceName();
+            if (TextUtils.isEmpty(oldIface) == false) {
+                for (NetworkStateTracker networkStateTracker : mNetTrackers) {
+                    if (networkStateTracker == null) continue;
+                    NetworkInfo networkInfo = networkStateTracker.getNetworkInfo();
+                    if (networkInfo.isConnected() && networkInfo.getType() != prevNetType) {
+                        LinkProperties l = networkStateTracker.getLinkProperties();
+                        if (l == null) continue;
+                        if (oldIface.equals(l.getInterfaceName())) {
+                            doReset = false;
+                            break;
+                        }
+                    }
+                }
+            }
+        }
+
         // do this before we broadcast the change
-        handleConnectivityChange(prevNetType);
+        handleConnectivityChange(prevNetType, doReset);
 
         sendStickyBroadcast(intent);
         /*
@@ -1284,9 +1468,6 @@
     }
 
     void systemReady() {
-        IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE);
-        mNetd = INetworkManagementService.Stub.asInterface(b);
-
         synchronized(this) {
             mSystemReady = true;
             if (mInitialBroadcast != null) {
@@ -1358,7 +1539,7 @@
         }
         thisNet.setTeardownRequested(false);
         updateNetworkSettings(thisNet);
-        handleConnectivityChange(type);
+        handleConnectivityChange(type, false);
         sendConnectedBroadcast(info);
     }
 
@@ -1368,7 +1549,7 @@
      * according to which networks are connected, and ensuring that the
      * right routing table entries exist.
      */
-    private void handleConnectivityChange(int netType) {
+    private void handleConnectivityChange(int netType, boolean doReset) {
         /*
          * If a non-default network is enabled, add the host routes that
          * will allow it's DNS servers to be accessed.
@@ -1408,6 +1589,17 @@
                 removePrivateDnsRoutes(mNetTrackers[netType]);
             }
         }
+
+        if (doReset) {
+            LinkProperties linkProperties = mNetTrackers[netType].getLinkProperties();
+            if (linkProperties != null) {
+                String iface = linkProperties.getInterfaceName();
+                if (TextUtils.isEmpty(iface) == false) {
+                    if (DBG) log("resetConnections(" + iface + ")");
+                    NetworkUtils.resetConnections(iface);
+                }
+            }
+        }
     }
 
     private void addPrivateDnsRoutes(NetworkStateTracker nt) {
@@ -1552,12 +1744,12 @@
 
             if (values.length == 6) {
               final String prefix = "/sys/kernel/ipv4/tcp_";
-                stringToFile(prefix + "rmem_min", values[0]);
-                stringToFile(prefix + "rmem_def", values[1]);
-                stringToFile(prefix + "rmem_max", values[2]);
-                stringToFile(prefix + "wmem_min", values[3]);
-                stringToFile(prefix + "wmem_def", values[4]);
-                stringToFile(prefix + "wmem_max", values[5]);
+                FileUtils.stringToFile(prefix + "rmem_min", values[0]);
+                FileUtils.stringToFile(prefix + "rmem_def", values[1]);
+                FileUtils.stringToFile(prefix + "rmem_max", values[2]);
+                FileUtils.stringToFile(prefix + "wmem_min", values[3]);
+                FileUtils.stringToFile(prefix + "wmem_def", values[4]);
+                FileUtils.stringToFile(prefix + "wmem_max", values[5]);
             } else {
                 loge("Invalid buffersize string: " + bufferSizes);
             }
@@ -1566,23 +1758,6 @@
         }
     }
 
-   /**
-     * Writes string to file. Basically same as "echo -n $string > $filename"
-     *
-     * @param filename
-     * @param string
-     * @throws IOException
-     */
-    private void stringToFile(String filename, String string) throws IOException {
-        FileWriter out = new FileWriter(filename);
-        try {
-            out.write(string);
-        } finally {
-            out.close();
-        }
-    }
-
-
     /**
      * Adjust the per-process dns entries (net.dns<x>.<pid>) based
      * on the highest priority active net which this process requested.
@@ -1850,7 +2025,7 @@
                     break;
                 case NetworkStateTracker.EVENT_CONFIGURATION_CHANGED:
                     info = (NetworkInfo) msg.obj;
-                    handleConnectivityChange(info.getType());
+                    handleConnectivityChange(info.getType(), true);
                     break;
                 case EVENT_CLEAR_NET_TRANSITION_WAKELOCK:
                     String causedBy = null;
@@ -2252,6 +2427,7 @@
     private void loge(String s) {
         Slog.e(TAG, s);
     }
+
     int convertFeatureToNetworkType(String feature){
         int networkType = -1;
         if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_MMS)) {
@@ -2272,4 +2448,82 @@
         }
         return networkType;
     }
+
+    private static <T> T checkNotNull(T value, String message) {
+        if (value == null) {
+            throw new NullPointerException(message);
+        }
+        return value;
+    }
+
+    /**
+     * Protect a socket from VPN routing rules. This method is used by
+     * VpnBuilder and not available in ConnectivityManager. Permission
+     * checks are done in Vpn class.
+     * @hide
+     */
+    @Override
+    public void protectVpn(ParcelFileDescriptor socket) {
+        mVpn.protect(socket, getDefaultInterface());
+    }
+
+    /**
+     * Prepare for a VPN application. This method is used by VpnDialogs
+     * and not available in ConnectivityManager. Permission checks are
+     * done in Vpn class.
+     * @hide
+     */
+    @Override
+    public String prepareVpn(String packageName) {
+        return mVpn.prepare(packageName);
+    }
+
+    /**
+     * Configure a TUN interface and return its file descriptor. Parameters
+     * are encoded and opaque to this class. This method is used by VpnBuilder
+     * and not available in ConnectivityManager. Permission checks are done
+     * in Vpn class.
+     * @hide
+     */
+    @Override
+    public ParcelFileDescriptor establishVpn(VpnConfig config) {
+        return mVpn.establish(config);
+    }
+
+    private String getDefaultInterface() {
+        if (ConnectivityManager.isNetworkTypeValid(mActiveDefaultNetwork)) {
+            NetworkStateTracker tracker = mNetTrackers[mActiveDefaultNetwork];
+            if (tracker != null) {
+                LinkProperties properties = tracker.getLinkProperties();
+                if (properties != null) {
+                    return properties.getInterfaceName();
+                }
+            }
+        }
+        throw new IllegalStateException("No default interface");
+    }
+
+    /**
+     * Callback for VPN subsystem. Currently VPN is not adapted to the service
+     * through NetworkStateTracker since it works differently. For example, it
+     * needs to override DNS servers but never takes the default routes. It
+     * relies on another data network, and it could keep existing connections
+     * alive after reconnecting, switching between networks, or even resuming
+     * from deep sleep. Calls from applications should be done synchronously
+     * to avoid race conditions. As these are all hidden APIs, refactoring can
+     * be done whenever a better abstraction is developed.
+     */
+    public class VpnCallback {
+
+        private VpnCallback() {
+        }
+
+        public synchronized void override(String[] dnsServers) {
+            // TODO: override DNS servers and http proxy.
+        }
+
+        public synchronized void restore() {
+            // TODO: restore VPN changes.
+        }
+    }
 }
diff --git a/services/java/com/android/server/DevicePolicyManagerService.java b/services/java/com/android/server/DevicePolicyManagerService.java
index 92d76be..d549308 100644
--- a/services/java/com/android/server/DevicePolicyManagerService.java
+++ b/services/java/com/android/server/DevicePolicyManagerService.java
@@ -148,7 +148,7 @@
         int minimumPasswordLowerCase = DEF_MINIMUM_PASSWORD_LOWER_CASE;
 
         static final int DEF_MINIMUM_PASSWORD_LETTERS = 1;
-        int minimumPasswordLetters = DEF_MINIMUM_PASSWORD_LOWER_CASE;
+        int minimumPasswordLetters = DEF_MINIMUM_PASSWORD_LETTERS;
 
         static final int DEF_MINIMUM_PASSWORD_NUMERIC = 1;
         int minimumPasswordNumeric = DEF_MINIMUM_PASSWORD_NUMERIC;
@@ -172,6 +172,7 @@
         long passwordExpirationDate = DEF_PASSWORD_EXPIRATION_DATE;
 
         boolean encryptionRequested = false;
+        boolean disableCamera = false;
 
         // TODO: review implementation decisions with frameworks team
         boolean specifiesGlobalProxy = false;
@@ -274,6 +275,11 @@
                 out.attribute(null, "value", Boolean.toString(encryptionRequested));
                 out.endTag(null, "encryption-requested");
             }
+            if (disableCamera) {
+                out.startTag(null, "disable-camera");
+                out.attribute(null, "value", Boolean.toString(disableCamera));
+                out.endTag(null, "disable-camera");
+            }
         }
 
         void readFromXml(XmlPullParser parser)
@@ -339,6 +345,9 @@
                 } else if ("encryption-requested".equals(tag)) {
                     encryptionRequested = Boolean.parseBoolean(
                             parser.getAttributeValue(null, "value"));
+                } else if ("disable-camera".equals(tag)) {
+                    disableCamera = Boolean.parseBoolean(
+                            parser.getAttributeValue(null, "value"));
                 } else {
                     Slog.w(TAG, "Unknown admin tag: " + tag);
                 }
@@ -393,6 +402,8 @@
             }
             pw.print(prefix); pw.print("encryptionRequested=");
                     pw.println(encryptionRequested);
+            pw.print(prefix); pw.print("disableCamera=");
+                    pw.println(disableCamera);
         }
     }
 
@@ -424,6 +435,7 @@
                 }
                 if (removed) {
                     validatePasswordOwnerLocked();
+                    syncDeviceCapabilitiesLocked();
                     saveSettingsLocked();
                 }
             }
@@ -578,6 +590,7 @@
                                 mAdminList.remove(admin);
                                 mAdminMap.remove(adminReceiver);
                                 validatePasswordOwnerLocked();
+                                syncDeviceCapabilitiesLocked();
                                 if (doProxyCleanup) {
                                     resetGlobalProxy();
                                 }
@@ -801,6 +814,7 @@
         }
 
         validatePasswordOwnerLocked();
+        syncDeviceCapabilitiesLocked();
 
         long timeMs = getMaximumTimeToLock(null);
         if (timeMs <= 0) {
@@ -844,6 +858,28 @@
         }
     }
 
+    /**
+     * Pushes down policy information to the system for any policies related to general device
+     * capabilities that need to be enforced by lower level services (e.g. Camera services).
+     */
+    void syncDeviceCapabilitiesLocked() {
+        // Ensure the status of the camera is synced down to the system. Interested native services
+        // should monitor this value and act accordingly.
+        boolean systemState = SystemProperties.getBoolean(SYSTEM_PROP_DISABLE_CAMERA, false);
+        boolean cameraDisabled = getCameraDisabled(null);
+        if (cameraDisabled != systemState) {
+            long token = Binder.clearCallingIdentity();
+            try {
+                String value = cameraDisabled ? "1" : "0";
+                Slog.v(TAG, "Change in camera state ["
+                        + SYSTEM_PROP_DISABLE_CAMERA + "] = " + value);
+                SystemProperties.set(SYSTEM_PROP_DISABLE_CAMERA, value);
+            } finally {
+                Binder.restoreCallingIdentity(token);
+            }
+        }
+    }
+
     public void systemReady() {
         synchronized (this) {
             loadSettingsLocked();
@@ -1925,9 +1961,8 @@
             // Check for permissions if a particular caller is specified
             if (who != null) {
                 // When checking for a single caller, status is based on caller's request
-                ActiveAdmin ap = getActiveAdminForCallerLocked(who,
-                        DeviceAdminInfo.USES_ENCRYPTED_STORAGE);
-                return ap.encryptionRequested;
+                ActiveAdmin ap = getActiveAdminUncheckedLocked(who);
+                return ap != null ? ap.encryptionRequested : false;
             }
 
             // If no particular caller is specified, return the aggregate set of requests.
@@ -1983,6 +2018,53 @@
     private void setEncryptionRequested(boolean encrypt) {
     }
 
+    /**
+     * The system property used to share the state of the camera. The native camera service
+     * is expected to read this property and act accordingly.
+     */
+    public static final String SYSTEM_PROP_DISABLE_CAMERA = "sys.secpolicy.camera.disabled";
+
+    /**
+     * Disables all device cameras according to the specified admin.
+     */
+    public void setCameraDisabled(ComponentName who, boolean disabled) {
+        synchronized (this) {
+            if (who == null) {
+                throw new NullPointerException("ComponentName is null");
+            }
+            ActiveAdmin ap = getActiveAdminForCallerLocked(who,
+                    DeviceAdminInfo.USES_POLICY_DISABLE_CAMERA);
+            if (ap.disableCamera != disabled) {
+                ap.disableCamera = disabled;
+                saveSettingsLocked();
+            }
+            syncDeviceCapabilitiesLocked();
+        }
+    }
+
+    /**
+     * Gets whether or not all device cameras are disabled for a given admin, or disabled for any
+     * active admins.
+     */
+    public boolean getCameraDisabled(ComponentName who) {
+        synchronized (this) {
+            if (who != null) {
+                ActiveAdmin admin = getActiveAdminUncheckedLocked(who);
+                return (admin != null) ? admin.disableCamera : false;
+            }
+
+            // Determine whether or not the device camera is disabled for any active admins.
+            final int N = mAdminList.size();
+            for (int i = 0; i < N; i++) {
+                ActiveAdmin admin = mAdminList.get(i);
+                if (admin.disableCamera) {
+                    return true;
+                }
+            }
+            return false;
+        }
+    }
+
     @Override
     protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
         if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
diff --git a/services/java/com/android/server/InputMethodManagerService.java b/services/java/com/android/server/InputMethodManagerService.java
index c96273b..fbde9d1 100644
--- a/services/java/com/android/server/InputMethodManagerService.java
+++ b/services/java/com/android/server/InputMethodManagerService.java
@@ -17,7 +17,9 @@
 package com.android.server;
 
 import com.android.internal.content.PackageMonitor;
+import com.android.internal.os.AtomicFile;
 import com.android.internal.os.HandlerCaller;
+import com.android.internal.util.FastXmlSerializer;
 import com.android.internal.view.IInputContext;
 import com.android.internal.view.IInputMethod;
 import com.android.internal.view.IInputMethodCallback;
@@ -25,10 +27,11 @@
 import com.android.internal.view.IInputMethodManager;
 import com.android.internal.view.IInputMethodSession;
 import com.android.internal.view.InputBindResult;
-
 import com.android.server.EventLogTags;
 
+import org.xmlpull.v1.XmlPullParser;
 import org.xmlpull.v1.XmlPullParserException;
+import org.xmlpull.v1.XmlSerializer;
 
 import android.app.ActivityManagerNative;
 import android.app.AlertDialog;
@@ -37,9 +40,9 @@
 import android.content.ContentResolver;
 import android.content.Context;
 import android.content.DialogInterface;
-import android.content.IntentFilter;
 import android.content.DialogInterface.OnCancelListener;
 import android.content.Intent;
+import android.content.IntentFilter;
 import android.content.ServiceConnection;
 import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageManager;
@@ -51,6 +54,7 @@
 import android.database.ContentObserver;
 import android.inputmethodservice.InputMethodService;
 import android.os.Binder;
+import android.os.Environment;
 import android.os.Handler;
 import android.os.IBinder;
 import android.os.IInterface;
@@ -68,9 +72,10 @@
 import android.util.EventLog;
 import android.util.LruCache;
 import android.util.Pair;
-import android.util.Slog;
 import android.util.PrintWriterPrinter;
 import android.util.Printer;
+import android.util.Slog;
+import android.util.Xml;
 import android.view.IWindowManager;
 import android.view.WindowManager;
 import android.view.inputmethod.EditorInfo;
@@ -80,15 +85,19 @@
 import android.view.inputmethod.InputMethodManager;
 import android.view.inputmethod.InputMethodSubtype;
 
+import java.io.File;
 import java.io.FileDescriptor;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
-import java.util.Map;
+import java.util.Set;
 import java.util.TreeMap;
 
 /**
@@ -134,6 +143,7 @@
     final StatusBarManagerService mStatusBar;
     final IWindowManager mIWindowManager;
     final HandlerCaller mCaller;
+    private final InputMethodFileManager mFileManager;
 
     final InputBindResult mNoBinding = new InputBindResult(null, null, -1);
 
@@ -407,10 +417,15 @@
                 if (curInputMethodId != null) {
                     for (int i=0; i<N; i++) {
                         InputMethodInfo imi = mMethodList.get(i);
-                        if (imi.getId().equals(curInputMethodId)) {
+                        final String imiId = imi.getId();
+                        if (imiId.equals(curInputMethodId)) {
                             curIm = imi;
                         }
+
                         int change = isPackageDisappearing(imi.getPackageName());
+                        if (isPackageModified(imi.getPackageName())) {
+                            mFileManager.deleteAllInputMethodSubtypes(imiId);
+                        }
                         if (change == PACKAGE_TEMPORARY_CHANGE
                                 || change == PACKAGE_PERMANENT_CHANGE) {
                             Slog.i(TAG, "Input method uninstalled, disabling: "
@@ -471,9 +486,11 @@
             mMethod = method;
         }
 
+        @Override
         public void finishedEvent(int seq, boolean handled) throws RemoteException {
         }
 
+        @Override
         public void sessionCreated(IInputMethodSession session) throws RemoteException {
             onSessionCreated(mMethod, session);
         }
@@ -486,10 +503,14 @@
         mIWindowManager = IWindowManager.Stub.asInterface(
                 ServiceManager.getService(Context.WINDOW_SERVICE));
         mCaller = new HandlerCaller(context, new HandlerCaller.Callback() {
+            @Override
             public void executeMessage(Message msg) {
                 handleMessage(msg);
             }
         });
+        synchronized (mMethodMap) {
+            mFileManager = new InputMethodFileManager(mMethodMap);
+        }
 
         (new MyPackageMonitor()).register(mContext, true);
 
@@ -566,12 +587,14 @@
         }
     }
 
+    @Override
     public List<InputMethodInfo> getInputMethodList() {
         synchronized (mMethodMap) {
             return new ArrayList<InputMethodInfo>(mMethodList);
         }
     }
 
+    @Override
     public List<InputMethodInfo> getEnabledInputMethodList() {
         synchronized (mMethodMap) {
             return mSettings.getEnabledInputMethodListLocked();
@@ -602,6 +625,7 @@
         return InputMethodSubtype.sort(mContext, 0, imi, enabledSubtypes);
     }
 
+    @Override
     public List<InputMethodSubtype> getEnabledInputMethodSubtypeList(InputMethodInfo imi,
             boolean allowsImplicitlySelectedSubtypes) {
         synchronized (mMethodMap) {
@@ -609,6 +633,7 @@
         }
     }
 
+    @Override
     public void addClient(IInputMethodClient client,
             IInputContext inputContext, int uid, int pid) {
         synchronized (mMethodMap) {
@@ -617,6 +642,7 @@
         }
     }
 
+    @Override
     public void removeClient(IInputMethodClient client) {
         synchronized (mMethodMap) {
             mClients.remove(client.asBinder());
@@ -840,6 +866,7 @@
         return null;
     }
 
+    @Override
     public InputBindResult startInput(IInputMethodClient client,
             IInputContext inputContext, EditorInfo attribute,
             boolean initial, boolean needResult) {
@@ -854,9 +881,11 @@
         }
     }
 
+    @Override
     public void finishInput(IInputMethodClient client) {
     }
 
+    @Override
     public void onServiceConnected(ComponentName name, IBinder service) {
         synchronized (mMethodMap) {
             if (mCurIntent != null && name.equals(mCurIntent.getComponent())) {
@@ -947,6 +976,7 @@
         mStatusBar.setIconVisibility("ime", false);
     }
 
+    @Override
     public void onServiceDisconnected(ComponentName name) {
         synchronized (mMethodMap) {
             if (DEBUG) Slog.v(TAG, "Service disconnected: " + name
@@ -1012,6 +1042,7 @@
         }
     }
 
+    @Override
     public void registerSuggestionSpansForNotification(SuggestionSpan[] spans) {
         synchronized (mMethodMap) {
             final InputMethodInfo currentImi = mMethodMap.get(mCurMethodId);
@@ -1025,6 +1056,7 @@
         }
     }
 
+    @Override
     public boolean notifySuggestionPicked(SuggestionSpan span, String originalString, int index) {
         synchronized (mMethodMap) {
             final InputMethodInfo targetImi = mSecureSuggestionSpans.get(span);
@@ -1485,6 +1517,7 @@
         }
     }
 
+    @Override
     public InputMethodSubtype getLastInputMethodSubtype() {
         synchronized (mMethodMap) {
             final Pair<String, String> lastIme = mSettings.getLastInputMethodAndSubtypeLocked();
@@ -1503,6 +1536,22 @@
         }
     }
 
+    @Override
+    public boolean setAdditionalInputMethodSubtypes(IBinder token, InputMethodSubtype[] subtypes) {
+        if (token == null || mCurToken != token) {
+            return false;
+        }
+        if (subtypes == null || subtypes.length == 0) return false;
+        synchronized (mMethodMap) {
+            final InputMethodInfo imi = mMethodMap.get(mCurMethodId);
+            if (imi == null) return false;
+            final int N = subtypes.length;
+            mFileManager.addInputMethodSubtypes(mCurMethodId, subtypes);
+            buildInputMethodListLocked(mMethodList, mMethodMap);
+            return true;
+        }
+    }
+
     private void setInputMethodWithSubtypeId(IBinder token, String id, int subtypeId) {
         synchronized (mMethodMap) {
             if (token == null) {
@@ -1749,6 +1798,8 @@
                 new Intent(InputMethod.SERVICE_INTERFACE),
                 PackageManager.GET_META_DATA);
 
+        final HashMap<String, List<InputMethodSubtype>> additionalSubtypes =
+                mFileManager.getAllAdditionalInputMethodSubtypes();
         for (int i = 0; i < services.size(); ++i) {
             ResolveInfo ri = services.get(i);
             ServiceInfo si = ri.serviceInfo;
@@ -1764,7 +1815,7 @@
             if (DEBUG) Slog.d(TAG, "Checking " + compName);
 
             try {
-                InputMethodInfo p = new InputMethodInfo(mContext, ri);
+                InputMethodInfo p = new InputMethodInfo(mContext, ri, additionalSubtypes);
                 list.add(p);
                 final String id = p.getId();
                 map.put(id, p);
@@ -1885,8 +1936,8 @@
                             int nameResId = subtype.getNameResId();
                             String mode = subtype.getMode();
                             if (nameResId != 0) {
-                                title = TextUtils.concat(pm.getText(imi.getPackageName(),
-                                        nameResId, imi.getServiceInfo().applicationInfo),
+                                title = TextUtils.concat(subtype.getDisplayName(context,
+                                        imi.getPackageName(), imi.getServiceInfo().applicationInfo),
                                         (TextUtils.isEmpty(label) ? "" : " (" + label + ")"));
                             } else {
                                 CharSequence language = subtype.getLocale();
@@ -2399,6 +2450,7 @@
     }
 
     // TODO: We should change the return type from List to List<Parcelable>
+    @Override
     public List getShortcutInputMethodsAndSubtypes() {
         synchronized (mMethodMap) {
             ArrayList<Object> ret = new ArrayList<Object>();
@@ -2821,6 +2873,200 @@
         }
     }
 
+    private static class InputMethodFileManager {
+        private static final String SYSTEM_PATH = "system";
+        private static final String INPUT_METHOD_PATH = "inputmethod";
+        private static final String ADDITIONAL_SUBTYPES_FILE_NAME = "subtypes.xml";
+        private static final String NODE_SUBTYPES = "subtypes";
+        private static final String NODE_SUBTYPE = "subtype";
+        private static final String NODE_IMI = "imi";
+        private static final String ATTR_ID = "id";
+        private static final String ATTR_LABEL = "label";
+        private static final String ATTR_ICON = "icon";
+        private static final String ATTR_IME_SUBTYPE_LOCALE = "imeSubtypeLocale";
+        private static final String ATTR_IME_SUBTYPE_MODE = "imeSubtypeMode";
+        private static final String ATTR_IME_SUBTYPE_EXTRA_VALUE = "imeSubtypeExtraValue";
+        private static final String ATTR_IS_AUXILIARY = "isAuxiliary";
+        private final AtomicFile mAdditionalInputMethodSubtypeFile;
+        private final HashMap<String, InputMethodInfo> mMethodMap;
+        private final HashMap<String, List<InputMethodSubtype>> mSubtypesMap =
+                new HashMap<String, List<InputMethodSubtype>>();
+        public InputMethodFileManager(HashMap<String, InputMethodInfo> methodMap) {
+            if (methodMap == null) {
+                throw new NullPointerException("methodMap is null");
+            }
+            mMethodMap = methodMap;
+            final File systemDir = new File(Environment.getDataDirectory(), SYSTEM_PATH);
+            final File inputMethodDir = new File(systemDir, INPUT_METHOD_PATH);
+            if (!inputMethodDir.mkdirs()) {
+                Slog.w(TAG, "Couldn't create dir.: " + inputMethodDir.getAbsolutePath());
+            }
+            final File subtypeFile = new File(inputMethodDir, ADDITIONAL_SUBTYPES_FILE_NAME);
+            mAdditionalInputMethodSubtypeFile = new AtomicFile(subtypeFile);
+            if (!subtypeFile.exists()) {
+                // If "subtypes.xml" doesn't exist, create a blank file.
+                writeAdditionalInputMethodSubtypes(mSubtypesMap, mAdditionalInputMethodSubtypeFile,
+                        methodMap);
+            } else {
+                readAdditionalInputMethodSubtypes(mSubtypesMap, mAdditionalInputMethodSubtypeFile);
+            }
+        }
+
+        private void deleteAllInputMethodSubtypes(String imiId) {
+            synchronized (mMethodMap) {
+                mSubtypesMap.remove(imiId);
+                writeAdditionalInputMethodSubtypes(mSubtypesMap, mAdditionalInputMethodSubtypeFile,
+                        mMethodMap);
+            }
+        }
+
+        public void addInputMethodSubtypes(
+                String imiId, InputMethodSubtype[] additionalSubtypes) {
+            synchronized (mMethodMap) {
+                final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>();
+                final int N = additionalSubtypes.length;
+                for (int i = 0; i < N; ++i) {
+                    final InputMethodSubtype subtype = additionalSubtypes[i];
+                    if (!subtypes.contains(subtype)) {
+                        subtypes.add(subtype);
+                    }
+                }
+                mSubtypesMap.put(imiId, subtypes);
+                writeAdditionalInputMethodSubtypes(mSubtypesMap, mAdditionalInputMethodSubtypeFile,
+                        mMethodMap);
+            }
+        }
+
+        public HashMap<String, List<InputMethodSubtype>> getAllAdditionalInputMethodSubtypes() {
+            synchronized (mMethodMap) {
+                return mSubtypesMap;
+            }
+        }
+
+        private static void writeAdditionalInputMethodSubtypes(
+                HashMap<String, List<InputMethodSubtype>> allSubtypes, AtomicFile subtypesFile,
+                HashMap<String, InputMethodInfo> methodMap) {
+            // Safety net for the case that this function is called before methodMap is set.
+            final boolean isSetMethodMap = methodMap != null && methodMap.size() > 0;
+            FileOutputStream fos = null;
+            try {
+                fos = subtypesFile.startWrite();
+                final XmlSerializer out = new FastXmlSerializer();
+                out.setOutput(fos, "utf-8");
+                out.startDocument(null, true);
+                out.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
+                out.startTag(null, NODE_SUBTYPES);
+                for (String imiId : allSubtypes.keySet()) {
+                    if (isSetMethodMap && !methodMap.containsKey(imiId)) {
+                        Slog.w(TAG, "IME uninstalled or not valid.: " + imiId);
+                        continue;
+                    }
+                    out.startTag(null, NODE_IMI);
+                    out.attribute(null, ATTR_ID, imiId);
+                    final List<InputMethodSubtype> subtypesList = allSubtypes.get(imiId);
+                    final int N = subtypesList.size();
+                    for (int i = 0; i < N; ++i) {
+                        final InputMethodSubtype subtype = subtypesList.get(i);
+                        out.startTag(null, NODE_SUBTYPE);
+                        out.attribute(null, ATTR_ICON, String.valueOf(subtype.getIconResId()));
+                        out.attribute(null, ATTR_LABEL, String.valueOf(subtype.getNameResId()));
+                        out.attribute(null, ATTR_IME_SUBTYPE_LOCALE, subtype.getLocale());
+                        out.attribute(null, ATTR_IME_SUBTYPE_MODE, subtype.getMode());
+                        out.attribute(null, ATTR_IME_SUBTYPE_EXTRA_VALUE, subtype.getExtraValue());
+                        out.attribute(null, ATTR_IS_AUXILIARY,
+                                String.valueOf(subtype.isAuxiliary() ? 1 : 0));
+                        out.endTag(null, NODE_SUBTYPE);
+                    }
+                    out.endTag(null, NODE_IMI);
+                }
+                out.endTag(null, NODE_SUBTYPES);
+                out.endDocument();
+                subtypesFile.finishWrite(fos);
+            } catch (java.io.IOException e) {
+                Slog.w(TAG, "Error writing subtypes", e);
+                if (fos != null) {
+                    subtypesFile.failWrite(fos);
+                }
+            }
+        }
+
+        private static void readAdditionalInputMethodSubtypes(
+                HashMap<String, List<InputMethodSubtype>> allSubtypes, AtomicFile subtypesFile) {
+            if (allSubtypes == null || subtypesFile == null) return;
+            allSubtypes.clear();
+            FileInputStream fis = null;
+            try {
+                fis = subtypesFile.openRead();
+                final XmlPullParser parser = Xml.newPullParser();
+                parser.setInput(fis, null);
+                int type = parser.getEventType();
+                // Skip parsing until START_TAG
+                while ((type = parser.next()) != XmlPullParser.START_TAG
+                        && type != XmlPullParser.END_DOCUMENT) {}
+                String firstNodeName = parser.getName();
+                if (!NODE_SUBTYPES.equals(firstNodeName)) {
+                    throw new XmlPullParserException("Xml doesn't start with subtypes");
+                }
+                final int depth =parser.getDepth();
+                String currentImiId = null;
+                ArrayList<InputMethodSubtype> tempSubtypesArray = null;
+                while (((type = parser.next()) != XmlPullParser.END_TAG
+                        || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
+                    if (type != XmlPullParser.START_TAG)
+                        continue;
+                    final String nodeName = parser.getName();
+                    if (NODE_IMI.equals(nodeName)) {
+                        currentImiId = parser.getAttributeValue(null, ATTR_ID);
+                        if (TextUtils.isEmpty(currentImiId)) {
+                            Slog.w(TAG, "Invalid imi id found in subtypes.xml");
+                            continue;
+                        }
+                        tempSubtypesArray = new ArrayList<InputMethodSubtype>();
+                        allSubtypes.put(currentImiId, tempSubtypesArray);
+                    } else if (NODE_SUBTYPE.equals(nodeName)) {
+                        if (TextUtils.isEmpty(currentImiId) || tempSubtypesArray == null) {
+                            Slog.w(TAG, "IME uninstalled or not valid.: " + currentImiId);
+                            continue;
+                        }
+                        final int icon = Integer.valueOf(
+                                parser.getAttributeValue(null, ATTR_ICON));
+                        final int label = Integer.valueOf(
+                                parser.getAttributeValue(null, ATTR_LABEL));
+                        final String imeSubtypeLocale =
+                                parser.getAttributeValue(null, ATTR_IME_SUBTYPE_LOCALE);
+                        final String imeSubtypeMode =
+                                parser.getAttributeValue(null, ATTR_IME_SUBTYPE_MODE);
+                        final String imeSubtypeExtraValue =
+                                parser.getAttributeValue(null, ATTR_IME_SUBTYPE_EXTRA_VALUE);
+                        final boolean isAuxiliary =
+                                Boolean.valueOf(parser.getAttributeValue(null, ATTR_IS_AUXILIARY));
+                        final InputMethodSubtype subtype =
+                                new InputMethodSubtype(label, icon, imeSubtypeLocale,
+                                        imeSubtypeMode, imeSubtypeExtraValue, isAuxiliary);
+                        tempSubtypesArray.add(subtype);
+                    }
+                }
+            } catch (XmlPullParserException e) {
+                Slog.w(TAG, "Error reading subtypes: " + e);
+                return;
+            } catch (java.io.IOException e) {
+                Slog.w(TAG, "Error reading subtypes: " + e);
+                return;
+            } catch (NumberFormatException e) {
+                Slog.w(TAG, "Error reading subtypes: " + e);
+                return;
+            } finally {
+                if (fis != null) {
+                    try {
+                        fis.close();
+                    } catch (java.io.IOException e1) {
+                        Slog.w(TAG, "Failed to close.");
+                    }
+                }
+            }
+        }
+    }
+
     // ----------------------------------------------------------------------
 
     @Override
diff --git a/services/java/com/android/server/MountService.java b/services/java/com/android/server/MountService.java
index f78dca9..d3244ec 100644
--- a/services/java/com/android/server/MountService.java
+++ b/services/java/com/android/server/MountService.java
@@ -33,6 +33,7 @@
 import android.content.res.Resources;
 import android.content.res.TypedArray;
 import android.content.res.XmlResourceParser;
+import android.hardware.usb.UsbManager;
 import android.net.Uri;
 import android.os.Binder;
 import android.os.Environment;
@@ -152,7 +153,6 @@
          * 600 series - Unsolicited broadcasts.
          */
         public static final int VolumeStateChange              = 605;
-        public static final int ShareAvailabilityChange        = 620;
         public static final int VolumeDiskInserted             = 630;
         public static final int VolumeDiskRemoved              = 631;
         public static final int VolumeBadRemoval               = 632;
@@ -167,6 +167,7 @@
     private String                                mExternalStoragePath;
     private PackageManagerService                 mPms;
     private boolean                               mUmsEnabling;
+    private boolean                               mUmsAvailable = false;
     // Used as a lock for methods that register/unregister listeners.
     final private ArrayList<MountServiceBinderListener> mListeners =
             new ArrayList<MountServiceBinderListener>();
@@ -525,6 +526,10 @@
                         }
                     }
                 }.start();
+            } else if (action.equals(UsbManager.ACTION_USB_STATE)) {
+                boolean available = (intent.getBooleanExtra(UsbManager.USB_CONNECTED, false) &&
+                        intent.getBooleanExtra(UsbManager.USB_FUNCTION_MASS_STORAGE, false));
+                notifyShareAvailabilityChange(available);
             }
         }
     };
@@ -654,12 +659,6 @@
                     updatePublicVolumeState(mExternalStoragePath, Environment.MEDIA_REMOVED);
                 }
 
-                try {
-                    boolean avail = doGetShareMethodAvailable("ums");
-                    notifyShareAvailabilityChange("ums", avail);
-                } catch (Exception ex) {
-                    Slog.w(TAG, "Failed to get share availability");
-                }
                 /*
                  * Now that we've done our initialization, release
                  * the hounds!
@@ -694,13 +693,6 @@
             notifyVolumeStateChange(
                     cooked[2], cooked[3], Integer.parseInt(cooked[7]),
                             Integer.parseInt(cooked[10]));
-        } else if (code == VoldResponseCode.ShareAvailabilityChange) {
-            // FMT: NNN Share method <method> now <available|unavailable>
-            boolean avail = false;
-            if (cooked[5].equals("available")) {
-                avail = true;
-            }
-            notifyShareAvailabilityChange(cooked[3], avail);
         } else if ((code == VoldResponseCode.VolumeDiskInserted) ||
                    (code == VoldResponseCode.VolumeDiskRemoved) ||
                    (code == VoldResponseCode.VolumeBadRemoval)) {
@@ -835,42 +827,6 @@
         }
     }
 
-    private boolean doGetShareMethodAvailable(String method) {
-        ArrayList<String> rsp;
-        try {
-            rsp = mConnector.doCommand("share status " + method);
-        } catch (NativeDaemonConnectorException ex) {
-            Slog.e(TAG, "Failed to determine whether share method " + method + " is available.");
-            return false;
-        }
-
-        for (String line : rsp) {
-            String[] tok = line.split(" ");
-            if (tok.length < 3) {
-                Slog.e(TAG, "Malformed response to share status " + method);
-                return false;
-            }
-
-            int code;
-            try {
-                code = Integer.parseInt(tok[0]);
-            } catch (NumberFormatException nfe) {
-                Slog.e(TAG, String.format("Error parsing code %s", tok[0]));
-                return false;
-            }
-            if (code == VoldResponseCode.ShareStatusResult) {
-                if (tok[2].equals("available"))
-                    return true;
-                return false;
-            } else {
-                Slog.e(TAG, String.format("Unexpected response code %d", code));
-                return false;
-            }
-        }
-        Slog.e(TAG, "Got an empty response");
-        return false;
-    }
-
     private int doMountVolume(String path) {
         int rc = StorageResultCode.OperationSucceeded;
 
@@ -1018,13 +974,9 @@
         return false;
     }
 
-    private void notifyShareAvailabilityChange(String method, final boolean avail) {
-        if (!method.equals("ums")) {
-           Slog.w(TAG, "Ignoring unsupported share method {" + method + "}");
-           return;
-        }
-
+    private void notifyShareAvailabilityChange(final boolean avail) {
         synchronized (mListeners) {
+            mUmsAvailable = avail;
             for (int i = mListeners.size() -1; i >= 0; i--) {
                 MountServiceBinderListener bl = mListeners.get(i);
                 try {
@@ -1121,16 +1073,20 @@
                             com.android.internal.R.styleable.Storage_emulated, false);
                     int mtpReserve = a.getInt(
                             com.android.internal.R.styleable.Storage_mtpReserve, 0);
+                    boolean allowMassStorage = a.getBoolean(
+                            com.android.internal.R.styleable.Storage_allowMassStorage, false);
 
                     Slog.d(TAG, "got storage path: " + path + " description: " + description +
                             " primary: " + primary + " removable: " + removable +
-                            " emulated: " + emulated +  " mtpReserve: " + mtpReserve);
+                            " emulated: " + emulated +  " mtpReserve: " + mtpReserve +
+                            " allowMassStorage: " + allowMassStorage);
                     if (path == null || description == null) {
                         Slog.e(TAG, "path or description is null in readStorageList");
                     } else {
                         String pathString = path.toString();
                         StorageVolume volume = new StorageVolume(pathString,
-                                description.toString(), removable, emulated, mtpReserve);
+                                description.toString(), removable, emulated,
+                                mtpReserve, allowMassStorage);
                         if (primary) {
                             if (mPrimaryVolume == null) {
                                 mPrimaryVolume = volume;
@@ -1185,8 +1141,13 @@
         // XXX: This will go away soon in favor of IMountServiceObserver
         mPms = (PackageManagerService) ServiceManager.getService("package");
 
-        mContext.registerReceiver(mBroadcastReceiver,
-                new IntentFilter(Intent.ACTION_BOOT_COMPLETED), null, null);
+        IntentFilter filter = new IntentFilter();
+        filter.addAction(Intent.ACTION_BOOT_COMPLETED);
+        // don't bother monitoring USB if mass storage is not supported on our primary volume
+        if (mPrimaryVolume != null && mPrimaryVolume.allowMassStorage()) {
+            filter.addAction(UsbManager.ACTION_USB_STATE);
+        }
+        mContext.registerReceiver(mBroadcastReceiver, filter, null, null);
 
         mHandlerThread = new HandlerThread("MountService");
         mHandlerThread.start();
@@ -1319,7 +1280,9 @@
         if (getUmsEnabling()) {
             return true;
         }
-        return doGetShareMethodAvailable("ums");
+        synchronized (mListeners) {
+            return mUmsAvailable;
+        }
     }
 
     public void setUsbMassStorageEnabled(boolean enable) {
@@ -1415,7 +1378,7 @@
         return doFormatVolume(path);
     }
 
-    public int []getStorageUsers(String path) {
+    public int[] getStorageUsers(String path) {
         validatePermission(android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS);
         waitForReady();
         try {
diff --git a/services/java/com/android/server/NetStatService.java b/services/java/com/android/server/NetStatService.java
deleted file mode 100644
index 7fe6743..0000000
--- a/services/java/com/android/server/NetStatService.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.server;
-
-import android.content.Context;
-import android.net.TrafficStats;
-import android.os.INetStatService;
-import android.os.SystemClock;
-
-import java.io.FileDescriptor;
-import java.io.PrintWriter;
-
-public class NetStatService extends INetStatService.Stub {
-    private final Context mContext;
-
-    public NetStatService(Context context) {
-        mContext = context;
-    }
-
-    public long getMobileTxPackets() {
-        return TrafficStats.getMobileTxPackets();
-    }
-
-    public long getMobileRxPackets() {
-        return TrafficStats.getMobileRxPackets();
-    }
-
-    public long getMobileTxBytes() {
-        return TrafficStats.getMobileTxBytes();
-    }
-
-    public long getMobileRxBytes() {
-        return TrafficStats.getMobileRxBytes();
-    }
-
-    public long getTotalTxPackets() {
-        return TrafficStats.getTotalTxPackets();
-    }
-
-    public long getTotalRxPackets() {
-        return TrafficStats.getTotalRxPackets();
-    }
-
-    public long getTotalTxBytes() {
-        return TrafficStats.getTotalTxBytes();
-    }
-
-    public long getTotalRxBytes() {
-        return TrafficStats.getTotalRxBytes();
-    }
-
-    @Override
-    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
-        // This data is accessible to any app -- no permission check needed.
-
-        pw.print("Elapsed: total=");
-        pw.print(SystemClock.elapsedRealtime());
-        pw.print("ms awake=");
-        pw.print(SystemClock.uptimeMillis());
-        pw.println("ms");
-
-        pw.print("Mobile: Tx=");
-        pw.print(getMobileTxBytes());
-        pw.print("B/");
-        pw.print(getMobileTxPackets());
-        pw.print("Pkts Rx=");
-        pw.print(getMobileRxBytes());
-        pw.print("B/");
-        pw.print(getMobileRxPackets());
-        pw.println("Pkts");
-
-        pw.print("Total: Tx=");
-        pw.print(getTotalTxBytes());
-        pw.print("B/");
-        pw.print(getTotalTxPackets());
-        pw.print("Pkts Rx=");
-        pw.print(getTotalRxBytes());
-        pw.print("B/");
-        pw.print(getTotalRxPackets());
-        pw.println("Pkts");
-    }
-}
diff --git a/services/java/com/android/server/NetworkManagementService.java b/services/java/com/android/server/NetworkManagementService.java
index 8f179f5..d6704f4 100644
--- a/services/java/com/android/server/NetworkManagementService.java
+++ b/services/java/com/android/server/NetworkManagementService.java
@@ -16,6 +16,10 @@
 
 package com.android.server;
 
+import static android.net.NetworkStats.IFACE_ALL;
+import static android.net.NetworkStats.TAG_NONE;
+import static android.net.NetworkStats.UID_ALL;
+
 import android.content.Context;
 import android.content.pm.PackageManager;
 import android.net.INetworkManagementEventObserver;
@@ -37,6 +41,7 @@
 import java.io.DataInputStream;
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.net.Inet4Address;
@@ -59,8 +64,9 @@
     private static final int ADD = 1;
     private static final int REMOVE = 2;
 
-    /** Base path to UID-granularity network statistics. */
-    private static final File PATH_PROC_UID_STAT = new File("/proc/uid_stat");
+    @Deprecated
+    private static final File STATS_UIDSTAT = new File("/proc/uid_stat");
+    private static final File STATS_NETFILTER = new File("/proc/net/xt_qtaguid/stats");
 
     class NetdResponseCode {
         public static final int InterfaceListResult       = 110;
@@ -311,6 +317,18 @@
         }
     }
 
+    /* TODO: This is right now a IPv4 only function. Works for wifi which loses its
+       IPv6 addresses on interface down, but we need to do full clean up here */
+    public void clearInterfaceAddresses(String iface) throws IllegalStateException {
+         String cmd = String.format("interface clearaddrs %s", iface);
+        try {
+            mConnector.doCommand(cmd);
+        } catch (NativeDaemonConnectorException e) {
+            throw new IllegalStateException(
+                    "Unable to communicate with native daemon to interface clearallips - " + e);
+        }
+    }
+
     public void addRoute(String interfaceName, RouteInfo route) {
         modifyRoute(interfaceName, ADD, route);
     }
@@ -882,16 +900,15 @@
                 android.Manifest.permission.ACCESS_NETWORK_STATE, "NetworkManagementService");
 
         final String[] ifaces = listInterfaces();
-        final NetworkStats.Builder stats = new NetworkStats.Builder(
-                SystemClock.elapsedRealtime(), ifaces.length);
+        final NetworkStats stats = new NetworkStats(SystemClock.elapsedRealtime(), ifaces.length);
 
         for (String iface : ifaces) {
             final long rx = getInterfaceCounter(iface, true);
             final long tx = getInterfaceCounter(iface, false);
-            stats.addEntry(iface, NetworkStats.UID_ALL, rx, tx);
+            stats.addEntry(iface, UID_ALL, TAG_NONE, rx, tx);
         }
 
-        return stats.build();
+        return stats;
     }
 
     @Override
@@ -899,16 +916,11 @@
         mContext.enforceCallingOrSelfPermission(
                 android.Manifest.permission.ACCESS_NETWORK_STATE, "NetworkManagementService");
 
-        final String[] knownUids = PATH_PROC_UID_STAT.list();
-        final NetworkStats.Builder stats = new NetworkStats.Builder(
-                SystemClock.elapsedRealtime(), knownUids.length);
-
-        for (String uid : knownUids) {
-            final int uidInt = Integer.parseInt(uid);
-            collectNetworkStatsDetail(stats, uidInt);
+        if (STATS_NETFILTER.exists()) {
+            return getNetworkStatsDetailNetfilter(UID_ALL);
+        } else {
+            return getNetworkStatsDetailUidstat(UID_ALL);
         }
-
-        return stats.build();
     }
 
     @Override
@@ -918,20 +930,84 @@
                     android.Manifest.permission.ACCESS_NETWORK_STATE, "NetworkManagementService");
         }
 
-        final NetworkStats.Builder stats = new NetworkStats.Builder(
-                SystemClock.elapsedRealtime(), 1);
-        collectNetworkStatsDetail(stats, uid);
-        return stats.build();
+        if (STATS_NETFILTER.exists()) {
+            return getNetworkStatsDetailNetfilter(uid);
+        } else {
+            return getNetworkStatsDetailUidstat(uid);
+        }
     }
 
-    private void collectNetworkStatsDetail(NetworkStats.Builder stats, int uid) {
-        // TODO: kernel module will provide interface-level stats in future
-        // TODO: migrate these stats to come across netd in bulk, instead of all
-        // these individual file reads.
-        final File uidPath = new File(PATH_PROC_UID_STAT, Integer.toString(uid));
-        final long rx = readSingleLongFromFile(new File(uidPath, "tcp_rcv"));
-        final long tx = readSingleLongFromFile(new File(uidPath, "tcp_snd"));
-        stats.addEntry(NetworkStats.IFACE_ALL, uid, rx, tx);
+    /**
+     * Build {@link NetworkStats} with detailed UID statistics.
+     */
+    private NetworkStats getNetworkStatsDetailNetfilter(int limitUid) {
+        final NetworkStats stats = new NetworkStats(SystemClock.elapsedRealtime(), 24);
+
+        BufferedReader reader = null;
+        try {
+            reader = new BufferedReader(new FileReader(STATS_NETFILTER));
+
+            // assumes format from kernel:
+            // idx iface acct_tag_hex uid_tag_int rx_bytes tx_bytes
+
+            // skip first line, which is legend
+            String line = reader.readLine();
+            while ((line = reader.readLine()) != null) {
+                final StringTokenizer t = new StringTokenizer(line);
+
+                final String idx = t.nextToken();
+                final String iface = t.nextToken();
+
+                try {
+                    // TODO: kernel currently emits tag in upper half of long;
+                    // eventually switch to directly using int.
+                    final int tag = (int) (Long.parseLong(t.nextToken().substring(2), 16) >> 32);
+                    final int uid = Integer.parseInt(t.nextToken());
+                    final long rx = Long.parseLong(t.nextToken());
+                    final long tx = Long.parseLong(t.nextToken());
+
+                    if (limitUid == UID_ALL || limitUid == uid) {
+                        stats.addEntry(iface, uid, tag, rx, tx);
+                    }
+                } catch (NumberFormatException e) {
+                    Slog.w(TAG, "problem parsing stats for idx " + idx + ": " + e);
+                }
+            }
+        } catch (IOException e) {
+            Slog.w(TAG, "problem parsing stats: " + e);
+        } finally {
+            IoUtils.closeQuietly(reader);
+        }
+
+        return stats;
+    }
+
+    /**
+     * Build {@link NetworkStats} with detailed UID statistics.
+     *
+     * @deprecated since this uses older "uid_stat" data, and doesn't provide
+     *             tag-level granularity or additional variables.
+     */
+    @Deprecated
+    private NetworkStats getNetworkStatsDetailUidstat(int limitUid) {
+        final String[] knownUids;
+        if (limitUid == UID_ALL) {
+            knownUids = STATS_UIDSTAT.list();
+        } else {
+            knownUids = new String[] { String.valueOf(limitUid) };
+        }
+
+        final NetworkStats stats = new NetworkStats(
+                SystemClock.elapsedRealtime(), knownUids.length);
+        for (String uid : knownUids) {
+            final int uidInt = Integer.parseInt(uid);
+            final File uidPath = new File(STATS_UIDSTAT, uid);
+            final long rx = readSingleLongFromFile(new File(uidPath, "tcp_rcv"));
+            final long tx = readSingleLongFromFile(new File(uidPath, "tcp_snd"));
+            stats.addEntry(IFACE_ALL, uidInt, TAG_NONE, rx, tx);
+        }
+
+        return stats;
     }
 
     public void setInterfaceThrottle(String iface, int rxKbps, int txKbps) {
diff --git a/services/java/com/android/server/NotificationManagerService.java b/services/java/com/android/server/NotificationManagerService.java
index e738145..4ecdfed 100755
--- a/services/java/com/android/server/NotificationManagerService.java
+++ b/services/java/com/android/server/NotificationManagerService.java
@@ -27,7 +27,6 @@
 import android.app.PendingIntent;
 import android.app.StatusBarManager;
 import android.content.BroadcastReceiver;
-import android.content.ComponentName;
 import android.content.ContentResolver;
 import android.content.Context;
 import android.content.Intent;
@@ -37,7 +36,6 @@
 import android.content.pm.PackageManager.NameNotFoundException;
 import android.content.res.Resources;
 import android.database.ContentObserver;
-import android.hardware.usb.UsbManager;
 import android.media.AudioManager;
 import android.net.Uri;
 import android.os.Binder;
@@ -47,7 +45,6 @@
 import android.os.Message;
 import android.os.Process;
 import android.os.RemoteException;
-import android.os.SystemProperties;
 import android.os.Vibrator;
 import android.provider.Settings;
 import android.telephony.TelephonyManager;
@@ -112,10 +109,6 @@
     // This is reset to false when the screen is turned on.
     private boolean mPendingPulseNotification;
 
-    // for adb connected notifications
-    private boolean mAdbNotificationShown = false;
-    private Notification mAdbNotification;
-
     private final ArrayList<NotificationRecord> mNotificationList =
             new ArrayList<NotificationRecord>();
 
@@ -330,13 +323,7 @@
 
             boolean queryRestart = false;
             
-            if (action.equals(UsbManager.ACTION_USB_STATE)) {
-                Bundle extras = intent.getExtras();
-                boolean usbConnected = extras.getBoolean(UsbManager.USB_CONNECTED);
-                boolean adbEnabled = (UsbManager.USB_FUNCTION_ENABLED.equals(
-                                    extras.getString(UsbManager.USB_FUNCTION_ADB)));
-                updateAdbNotification(usbConnected && adbEnabled);
-            } else if (action.equals(Intent.ACTION_PACKAGE_REMOVED)
+            if (action.equals(Intent.ACTION_PACKAGE_REMOVED)
                     || action.equals(Intent.ACTION_PACKAGE_RESTARTED)
                     || (queryRestart=action.equals(Intent.ACTION_QUERY_PACKAGE_RESTART))
                     || action.equals(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE)) {
@@ -437,7 +424,6 @@
 
         // register for various Intents
         IntentFilter filter = new IntentFilter();
-        filter.addAction(UsbManager.ACTION_USB_STATE);
         filter.addAction(Intent.ACTION_SCREEN_ON);
         filter.addAction(Intent.ACTION_SCREEN_OFF);
         filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
@@ -1117,67 +1103,6 @@
         return -1;
     }
 
-    // This is here instead of StatusBarPolicy because it is an important
-    // security feature that we don't want people customizing the platform
-    // to accidentally lose.
-    private void updateAdbNotification(boolean adbEnabled) {
-        if (adbEnabled) {
-            if ("0".equals(SystemProperties.get("persist.adb.notify"))) {
-                return;
-            }
-            if (!mAdbNotificationShown) {
-                NotificationManager notificationManager = (NotificationManager) mContext
-                        .getSystemService(Context.NOTIFICATION_SERVICE);
-                if (notificationManager != null) {
-                    Resources r = mContext.getResources();
-                    CharSequence title = r.getText(
-                            com.android.internal.R.string.adb_active_notification_title);
-                    CharSequence message = r.getText(
-                            com.android.internal.R.string.adb_active_notification_message);
-
-                    if (mAdbNotification == null) {
-                        mAdbNotification = new Notification();
-                        mAdbNotification.icon = com.android.internal.R.drawable.stat_sys_adb;
-                        mAdbNotification.when = 0;
-                        mAdbNotification.flags = Notification.FLAG_ONGOING_EVENT;
-                        mAdbNotification.tickerText = title;
-                        mAdbNotification.defaults = 0; // please be quiet
-                        mAdbNotification.sound = null;
-                        mAdbNotification.vibrate = null;
-                    }
-
-                    Intent intent = new Intent(
-                            Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS);
-                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
-                            Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
-                    // Note: we are hard-coding the component because this is
-                    // an important security UI that we don't want anyone
-                    // intercepting.
-                    intent.setComponent(new ComponentName("com.android.settings",
-                            "com.android.settings.DevelopmentSettings"));
-                    PendingIntent pi = PendingIntent.getActivity(mContext, 0,
-                            intent, 0);
-
-                    mAdbNotification.setLatestEventInfo(mContext, title, message, pi);
-
-                    mAdbNotificationShown = true;
-                    notificationManager.notify(
-                            com.android.internal.R.string.adb_active_notification_title,
-                            mAdbNotification);
-                }
-            }
-
-        } else if (mAdbNotificationShown) {
-            NotificationManager notificationManager = (NotificationManager) mContext
-                    .getSystemService(Context.NOTIFICATION_SERVICE);
-            if (notificationManager != null) {
-                mAdbNotificationShown = false;
-                notificationManager.cancel(
-                        com.android.internal.R.string.adb_active_notification_title);
-            }
-        }
-    }
-
     private void updateNotificationPulse() {
         synchronized (mNotificationList) {
             updateLightsLocked();
diff --git a/services/java/com/android/server/StatusBarManagerService.java b/services/java/com/android/server/StatusBarManagerService.java
index 1d2072c..286a937 100644
--- a/services/java/com/android/server/StatusBarManagerService.java
+++ b/services/java/com/android/server/StatusBarManagerService.java
@@ -16,21 +16,16 @@
 
 package com.android.server;
 
-import android.app.PendingIntent;
 import android.app.StatusBarManager;
 import android.content.BroadcastReceiver;
-import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
-import android.content.IntentFilter;
 import android.content.pm.PackageManager;
 import android.content.res.Resources;
-import android.net.Uri;
 import android.os.IBinder;
 import android.os.RemoteException;
 import android.os.Binder;
 import android.os.Handler;
-import android.os.SystemClock;
 import android.util.Slog;
 import android.view.View;
 
@@ -253,25 +248,23 @@
      * Hide or show the on-screen Menu key. Only call this from the window manager, typically in
      * response to a window with FLAG_NEEDS_MENU_KEY set.
      */
-    public void setMenuKeyVisible(final boolean visible) {
+    public void topAppWindowChanged(final boolean menuVisible) {
         enforceStatusBar();
 
-        if (SPEW) Slog.d(TAG, (visible?"showing":"hiding") + " MENU key");
+        if (SPEW) Slog.d(TAG, (menuVisible?"showing":"hiding") + " MENU key");
 
         synchronized(mLock) {
-            if (mMenuVisible != visible) {
-                mMenuVisible = visible;
-                mHandler.post(new Runnable() {
-                        public void run() {
-                            if (mBar != null) {
-                                try {
-                                    mBar.setMenuKeyVisible(visible);
-                                } catch (RemoteException ex) {
-                                }
+            mMenuVisible = menuVisible;
+            mHandler.post(new Runnable() {
+                    public void run() {
+                        if (mBar != null) {
+                            try {
+                                mBar.topAppWindowChanged(menuVisible);
+                            } catch (RemoteException ex) {
                             }
                         }
-                    });
-            }
+                    }
+                });
         }
     }
 
@@ -352,6 +345,15 @@
         });
     }
 
+    @Override
+    public void toggleRecentApps() {
+        if (mBar != null) {
+            try {
+                mBar.toggleRecentApps();
+            } catch (RemoteException ex) {}
+        }
+    }
+
     private void enforceStatusBar() {
         mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR,
                 "StatusBarManagerService");
diff --git a/services/java/com/android/server/SystemBackupAgent.java b/services/java/com/android/server/SystemBackupAgent.java
index 54555bb..08c6699 100644
--- a/services/java/com/android/server/SystemBackupAgent.java
+++ b/services/java/com/android/server/SystemBackupAgent.java
@@ -37,16 +37,25 @@
 public class SystemBackupAgent extends BackupAgentHelper {
     private static final String TAG = "SystemBackupAgent";
 
-    // These paths must match what the WallpaperManagerService uses
+    // These paths must match what the WallpaperManagerService uses.  The leaf *_FILENAME
+    // are also used in the full-backup file format, so must not change unless steps are
+    // taken to support the legacy backed-up datasets.
+    private static final String WALLPAPER_IMAGE_FILENAME = "wallpaper";
+    private static final String WALLPAPER_INFO_FILENAME = "wallpaper_info.xml";
+
     private static final String WALLPAPER_IMAGE_DIR = "/data/data/com.android.settings/files";
-    private static final String WALLPAPER_IMAGE = WALLPAPER_IMAGE_DIR + "/wallpaper";
+    private static final String WALLPAPER_IMAGE = WALLPAPER_IMAGE_DIR + "/" + WALLPAPER_IMAGE_FILENAME;
+
     private static final String WALLPAPER_INFO_DIR = "/data/system";
-    private static final String WALLPAPER_INFO = WALLPAPER_INFO_DIR + "/wallpaper_info.xml";
+    private static final String WALLPAPER_INFO = WALLPAPER_INFO_DIR + "/" +  WALLPAPER_INFO_FILENAME;
+
 
     @Override
     public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
             ParcelFileDescriptor newState) throws IOException {
         if (oldState == null) {
+            // Ah, it's a full backup dataset, being restored piecemeal.  Just
+            // pop over to the full restore handling and we're done.
             runFullBackup(data);
             return;
         }
@@ -66,11 +75,18 @@
     }
 
     private void runFullBackup(BackupDataOutput output) {
-        // Back up the data files directly
-        FullBackup.backupToTar(getPackageName(), null, null,
-                WALLPAPER_IMAGE_DIR, WALLPAPER_IMAGE, output);
-        FullBackup.backupToTar(getPackageName(), null, null,
+        fullWallpaperBackup(output);
+    }
+
+    private void fullWallpaperBackup(BackupDataOutput output) {
+        // Back up the data files directly.  We do them in this specific order --
+        // info file followed by image -- because then we need take no special
+        // steps during restore; the restore will happen properly when the individual
+        // files are restored piecemeal.
+        FullBackup.backupToTar(getPackageName(), FullBackup.ROOT_TREE_TOKEN, null,
                 WALLPAPER_INFO_DIR, WALLPAPER_INFO, output);
+        FullBackup.backupToTar(getPackageName(), FullBackup.ROOT_TREE_TOKEN, null,
+                WALLPAPER_IMAGE_DIR, WALLPAPER_IMAGE, output);
     }
 
     @Override
@@ -96,4 +112,46 @@
             (new File(WALLPAPER_INFO)).delete();
         }
     }
+
+    @Override
+    public void onRestoreFile(ParcelFileDescriptor data, long size,
+            int type, String domain, String path, long mode, long mtime)
+            throws IOException {
+        Slog.i(TAG, "Restoring file domain=" + domain + " path=" + path);
+
+        // Bits to indicate postprocessing we may need to perform
+        boolean restoredWallpaper = false;
+
+        File outFile = null;
+        // Various domain+files we understand a priori
+        if (domain.equals(FullBackup.ROOT_TREE_TOKEN)) {
+            if (path.equals(WALLPAPER_INFO_FILENAME)) {
+                outFile = new File(WALLPAPER_INFO);
+                restoredWallpaper = true;
+            } else if (path.equals(WALLPAPER_IMAGE_FILENAME)) {
+                outFile = new File(WALLPAPER_IMAGE);
+                restoredWallpaper = true;
+            }
+        }
+
+        try {
+            if (outFile == null) {
+                Slog.w(TAG, "Skipping unrecognized system file: [ " + domain + " : " + path + " ]");
+            }
+            FullBackup.restoreToFile(data, size, type, mode, mtime, outFile, true);
+
+            if (restoredWallpaper) {
+                WallpaperManagerService wallpaper =
+                        (WallpaperManagerService)ServiceManager.getService(
+                        Context.WALLPAPER_SERVICE);
+                wallpaper.settingsRestored();
+            }
+        } catch (IOException e) {
+            if (restoredWallpaper) {
+                // Make sure we wind up in a good state
+                (new File(WALLPAPER_IMAGE)).delete();
+                (new File(WALLPAPER_INFO)).delete();
+            }
+        }
+    }
 }
diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java
index 5355d44..a23bacf 100644
--- a/services/java/com/android/server/SystemServer.java
+++ b/services/java/com/android/server/SystemServer.java
@@ -16,19 +16,6 @@
 
 package com.android.server;
 
-import com.android.server.accessibility.AccessibilityManagerService;
-import com.android.server.am.ActivityManagerService;
-import com.android.server.net.NetworkPolicyManagerService;
-import com.android.server.pm.PackageManagerService;
-import com.android.server.usb.UsbService;
-import com.android.server.wm.WindowManagerService;
-import com.android.internal.app.ShutdownThread;
-import com.android.internal.os.BinderInternal;
-import com.android.internal.os.SamplingProfilerIntegration;
-
-import dalvik.system.VMRuntime;
-import dalvik.system.Zygote;
-
 import android.accounts.AccountManagerService;
 import android.app.ActivityManagerNative;
 import android.bluetooth.BluetoothAdapter;
@@ -39,27 +26,36 @@
 import android.content.Intent;
 import android.content.pm.IPackageManager;
 import android.content.res.Configuration;
-import android.database.ContentObserver;
 import android.media.AudioService;
-import android.os.Build;
 import android.os.Looper;
 import android.os.RemoteException;
 import android.os.ServiceManager;
 import android.os.StrictMode;
 import android.os.SystemClock;
 import android.os.SystemProperties;
-import android.provider.Contacts.People;
 import android.provider.Settings;
 import android.server.BluetoothA2dpService;
 import android.server.BluetoothService;
 import android.server.search.SearchManagerService;
 import android.util.DisplayMetrics;
 import android.util.EventLog;
-import android.util.Log;
 import android.util.Slog;
-import android.view.Display;
 import android.view.WindowManager;
 
+import com.android.internal.app.ShutdownThread;
+import com.android.internal.os.BinderInternal;
+import com.android.internal.os.SamplingProfilerIntegration;
+import com.android.server.accessibility.AccessibilityManagerService;
+import com.android.server.am.ActivityManagerService;
+import com.android.server.net.NetworkPolicyManagerService;
+import com.android.server.net.NetworkStatsService;
+import com.android.server.pm.PackageManagerService;
+import com.android.server.usb.UsbService;
+import com.android.server.wm.WindowManagerService;
+
+import dalvik.system.VMRuntime;
+import dalvik.system.Zygote;
+
 import java.io.File;
 import java.util.Timer;
 import java.util.TimerTask;
@@ -69,19 +65,6 @@
 
     ContentResolver mContentResolver;
 
-    private class AdbSettingsObserver extends ContentObserver {
-        public AdbSettingsObserver() {
-            super(null);
-        }
-        @Override
-        public void onChange(boolean selfChange) {
-            boolean enableAdb = (Settings.Secure.getInt(mContentResolver,
-                Settings.Secure.ADB_ENABLED, 0) > 0);
-            // setting this secure property will start or stop adbd
-           SystemProperties.set("persist.service.adb.enable", enableAdb ? "1" : "0");
-        }
-    }
-
     @Override
     public void run() {
         EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_SYSTEM_RUN,
@@ -120,6 +103,9 @@
         LightsService lights = null;
         PowerManagerService power = null;
         BatteryService battery = null;
+        AlarmManagerService alarm = null;
+        NetworkManagementService networkManagement = null;
+        NetworkStatsService networkStats = null;
         NetworkPolicyManagerService networkPolicy = null;
         ConnectivityService connectivity = null;
         IPackageManager pm = null;
@@ -191,7 +177,7 @@
             power.init(context, lights, ActivityManagerService.getDefault(), battery);
 
             Slog.i(TAG, "Alarm Manager");
-            AlarmManagerService alarm = new AlarmManagerService(context);
+            alarm = new AlarmManagerService(context);
             ServiceManager.addService(Context.ALARM_SERVICE, alarm);
 
             Slog.i(TAG, "Init Watchdog");
@@ -277,34 +263,36 @@
             }
 
             try {
-                Slog.i(TAG, "NetStat Service");
-                ServiceManager.addService("netstat", new NetStatService(context));
-            } catch (Throwable e) {
-                Slog.e(TAG, "Failure starting NetStat Service", e);
-            }
-
-            try {
-                Slog.i(TAG, "NetworkPolicy Service");
-                networkPolicy = new NetworkPolicyManagerService(
-                        context, ActivityManagerService.self(), power);
-                ServiceManager.addService(Context.NETWORK_POLICY_SERVICE, networkPolicy);
-            } catch (Throwable e) {
-                Slog.e(TAG, "Failure starting Connectivity Service", e);
-            }
-
-            try {
                 Slog.i(TAG, "NetworkManagement Service");
-                ServiceManager.addService(
-                        Context.NETWORKMANAGEMENT_SERVICE,
-                        NetworkManagementService.create(context));
+                networkManagement = NetworkManagementService.create(context);
+                ServiceManager.addService(Context.NETWORKMANAGEMENT_SERVICE, networkManagement);
             } catch (Throwable e) {
                 Slog.e(TAG, "Failure starting NetworkManagement Service", e);
             }
 
             try {
+                Slog.i(TAG, "NetworkStats Service");
+                networkStats = new NetworkStatsService(context, networkManagement, alarm);
+                ServiceManager.addService(Context.NETWORK_STATS_SERVICE, networkStats);
+            } catch (Throwable e) {
+                Slog.e(TAG, "Failure starting NetworkStats Service", e);
+            }
+
+            try {
+                Slog.i(TAG, "NetworkPolicy Service");
+                networkPolicy = new NetworkPolicyManagerService(
+                        context, ActivityManagerService.self(), power, networkStats);
+                ServiceManager.addService(Context.NETWORK_POLICY_SERVICE, networkPolicy);
+            } catch (Throwable e) {
+                Slog.e(TAG, "Failure starting NetworkPolicy Service", e);
+            }
+
+            try {
                 Slog.i(TAG, "Connectivity Service");
-                connectivity = ConnectivityService.getInstance(context);
+                connectivity = new ConnectivityService(context, networkManagement, networkPolicy);
                 ServiceManager.addService(Context.CONNECTIVITY_SERVICE, connectivity);
+                networkStats.bindConnectivityManager(connectivity);
+                networkPolicy.bindConnectivityManager(connectivity);
             } catch (Throwable e) {
                 Slog.e(TAG, "Failure starting Connectivity Service", e);
             }
@@ -341,6 +329,7 @@
                 Slog.i(TAG, "Notification Manager");
                 notification = new NotificationManagerService(context, statusBar, lights);
                 ServiceManager.addService(Context.NOTIFICATION_SERVICE, notification);
+                networkPolicy.bindNotificationManager(notification);
             } catch (Throwable e) {
                 Slog.e(TAG, "Failure starting Notification Manager", e);
             }
@@ -417,8 +406,8 @@
             }
 
             try {
-                Slog.i(TAG, "USB Observer");
-                // Listen for USB changes
+                Slog.i(TAG, "USB Service");
+                // Manage USB host and device support
                 usb = new UsbService(context);
                 ServiceManager.addService(Context.USB_SERVICE, usb);
             } catch (Throwable e) {
@@ -483,14 +472,6 @@
             }
         }
 
-        // make sure the ADB_ENABLED setting value matches the secure property value
-        Settings.Secure.putInt(mContentResolver, Settings.Secure.ADB_ENABLED,
-                "1".equals(SystemProperties.get("persist.service.adb.enable")) ? 1 : 0);
-
-        // register observer to listen for settings changes
-        mContentResolver.registerContentObserver(Settings.Secure.getUriFor(Settings.Secure.ADB_ENABLED),
-                false, new AdbSettingsObserver());
-
         // Before things start rolling, be sure we have decided whether
         // we are in safe mode.
         final boolean safeMode = wm.detectSafeMode();
@@ -539,6 +520,7 @@
         // These are needed to propagate to the runnable below.
         final Context contextF = context;
         final BatteryService batteryF = battery;
+        final NetworkStatsService networkStatsF = networkStats;
         final NetworkPolicyManagerService networkPolicyF = networkPolicy;
         final ConnectivityService connectivityF = connectivity;
         final DockObserver dockF = dock;
@@ -565,6 +547,7 @@
 
                 startSystemUi(contextF);
                 if (batteryF != null) batteryF.systemReady();
+                if (networkStatsF != null) networkStatsF.systemReady();
                 if (networkPolicyF != null) networkPolicyF.systemReady();
                 if (connectivityF != null) connectivityF.systemReady();
                 if (dockF != null) dockF.systemReady();
diff --git a/services/java/com/android/server/ThrottleService.java b/services/java/com/android/server/ThrottleService.java
index 510ff62..7266d7d 100644
--- a/services/java/com/android/server/ThrottleService.java
+++ b/services/java/com/android/server/ThrottleService.java
@@ -533,7 +533,8 @@
             long incWrite = 0;
             try {
                 final NetworkStats stats = mNMService.getNetworkStatsSummary();
-                final int index = stats.findIndex(mIface, NetworkStats.UID_ALL);
+                final int index = stats.findIndex(
+                        mIface, NetworkStats.UID_ALL, NetworkStats.TAG_NONE);
 
                 if (index != -1) {
                     incRead = stats.rx[index] - mLastRead;
diff --git a/services/java/com/android/server/WifiService.java b/services/java/com/android/server/WifiService.java
index 41ec63a..cb55451 100644
--- a/services/java/com/android/server/WifiService.java
+++ b/services/java/com/android/server/WifiService.java
@@ -84,7 +84,7 @@
 
 public class WifiService extends IWifiManager.Stub {
     private static final String TAG = "WifiService";
-    private static final boolean DBG = true;
+    private static final boolean DBG = false;
 
     private final WifiStateMachine mWifiStateMachine;
 
@@ -321,6 +321,13 @@
                     }
                     break;
                 }
+                case AsyncChannel.CMD_CHANNEL_DISCONNECTED: {
+                    Slog.e(TAG, "WifiStateMachine channel lost, msg.arg1 =" + msg.arg1);
+                    mWifiStateMachineChannel = null;
+                    //Re-establish connection to state machine
+                    mWsmChannel.connect(mContext, this, mWifiStateMachine.getHandler());
+                    break;
+                }
                 default: {
                     Slog.d(TAG, "WifiStateMachineHandler.handleMessage ignoring msg=" + msg);
                     break;
@@ -593,7 +600,12 @@
      */
     public WifiConfiguration getWifiApConfiguration() {
         enforceAccessPermission();
-        return mWifiStateMachine.syncGetWifiApConfiguration(mWifiStateMachineChannel);
+        if (mWifiStateMachineChannel != null) {
+            return mWifiStateMachine.syncGetWifiApConfiguration(mWifiStateMachineChannel);
+        } else {
+            Slog.e(TAG, "mWifiStateMachineChannel is not initialized");
+            return null;
+        }
     }
 
     /**
diff --git a/services/java/com/android/server/WifiWatchdogService.java b/services/java/com/android/server/WifiWatchdogService.java
index 6ef6963..56bfbe0 100644
--- a/services/java/com/android/server/WifiWatchdogService.java
+++ b/services/java/com/android/server/WifiWatchdogService.java
@@ -36,16 +36,21 @@
 import android.text.TextUtils;
 import android.util.Slog;
 
+import java.io.BufferedInputStream;
+import java.io.InputStream;
 import java.io.IOException;
 import java.net.DatagramPacket;
 import java.net.DatagramSocket;
+import java.net.HttpURLConnection;
 import java.net.InetAddress;
 import java.net.SocketException;
 import java.net.SocketTimeoutException;
 import java.net.UnknownHostException;
+import java.net.URL;
 import java.util.Collection;
 import java.util.List;
 import java.util.Random;
+import java.util.Scanner;
 
 /**
  * {@link WifiWatchdogService} monitors the initial connection to a Wi-Fi
@@ -73,9 +78,9 @@
  */
 public class WifiWatchdogService {
     private static final String TAG = "WifiWatchdogService";
-    private static final boolean V = false || false;
-    private static final boolean D = true || false;
-    
+    private static final boolean V = false;
+    private static final boolean D = true;
+
     private Context mContext;
     private ContentResolver mContentResolver;
     private WifiManager mWifiManager;
@@ -103,17 +108,16 @@
     private String mSsid;
     /**
      * The number of access points in the current network ({@link #mSsid}) that
-     * have been checked. Only touched in the main thread!
+     * have been checked. Only touched in the main thread, using getter/setter methods.
      */
-    private int mNumApsChecked;
+    private int mBssidCheckCount;
     /** Whether the current AP check should be canceled. */
     private boolean mShouldCancel;
-    
+
     WifiWatchdogService(Context context) {
         mContext = context;
         mContentResolver = context.getContentResolver();
         mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
-        
         createThread();
         
         // The content observer to listen needs a handler, which createThread creates
@@ -195,6 +199,34 @@
         return Settings.Secure.getInt(mContentResolver,
             Settings.Secure.WIFI_WATCHDOG_PING_DELAY_MS, 250);
     }
+
+    /**
+     * @see android.provider.Settings.Secure#WIFI_WATCHDOG_WALLED_GARDEN_TEST_ENABLED
+     */
+     private Boolean isWalledGardenTestEnabled() {
+        return Settings.Secure.getInt(mContentResolver,
+                 Settings.Secure.WIFI_WATCHDOG_WALLED_GARDEN_TEST_ENABLED, 1) == 1;
+     }
+
+    /**
+     * @see android.provider.Settings.Secure#WIFI_WATCHDOG_WALLED_GARDEN_URL
+     */
+     private String getWalledGardenUrl() {
+        String url = Settings.Secure.getString(mContentResolver,
+                 Settings.Secure.WIFI_WATCHDOG_WALLED_GARDEN_URL);
+        if (TextUtils.isEmpty(url)) return "http://www.google.com/";
+        return url;
+     }
+
+    /**
+     * @see android.provider.Settings.Secure#WIFI_WATCHDOG_WALLED_GARDEN_PATTERN
+     */
+     private String getWalledGardenPattern() {
+        String pattern = Settings.Secure.getString(mContentResolver,
+                 Settings.Secure.WIFI_WATCHDOG_WALLED_GARDEN_PATTERN);
+        if (TextUtils.isEmpty(pattern)) return "<title>.*Google.*</title>";
+        return pattern;
+     }
     
     /**
      * @see android.provider.Settings.Secure#WIFI_WATCHDOG_ACCEPTABLE_PACKET_LOSS_PERCENTAGE
@@ -377,6 +409,9 @@
                  * Successful "ignored" pings are *not* ignored (they count in the total number
                  * of pings), but failures are really ignored.
                  */
+
+                // TODO: This is confusing logic and should be rewitten
+                // Here, successful 'ignored' pings are interpreted as a success in the below loop
                 pingCounter++;
                 successCounter++;
             }
@@ -418,6 +453,7 @@
             }
         }
 
+        //TODO: Integer division might cause problems down the road...
         int packetLossPercentage = 100 * (numPings - successCounter) / numPings;
         if (D) {
             Slog.d(TAG, packetLossPercentage
@@ -437,7 +473,7 @@
             return false;
         }
 
-        if (false && V) {
+        if (V) {
             myLogV("backgroundCheckDnsConnectivity: Background checking " +
                     dns.getHostAddress() + " for connectivity");
         }
@@ -509,7 +545,7 @@
             // This access point does not require a watchdog, so queue idle on the main thread
             mHandler.idle();
         }
-        mHandler.checkWalledGarden(ssid);
+        if (isWalledGardenTestEnabled()) mHandler.checkWalledGarden(ssid);
     }
     
     /**
@@ -698,8 +734,8 @@
          * Checks to make sure we haven't exceeded the max number of checks
          * we're allowed per network
          */
-        mNumApsChecked++;
-        if (mNumApsChecked > getMaxApChecks()) {
+        incrementBssidCheckCount();
+        if (getBssidCheckCount() > getMaxApChecks()) {
             if (V) {
                 Slog.v(TAG, "  Passed the max attempts (" + getMaxApChecks()
                         + "), going to sleep for " + mSsid);
@@ -790,7 +826,7 @@
         // Reset the cancel state since this is the entry point of this action
         mShouldCancel = false;
         
-        if (false && V) {
+        if (V) {
             myLogV("handleBackgroundCheckAp: AccessPoint: " + ap);
         }
         
@@ -929,7 +965,7 @@
         if (forceIdleState || (mState != WatchdogState.SLEEP)) {
             mState = WatchdogState.IDLE;
         }
-        mNumApsChecked = 0;
+        resetBssidCheckCount();
     }
 
     /**
@@ -957,6 +993,18 @@
         SWITCHING_AP
     }
 
+    private int getBssidCheckCount() {
+        return mBssidCheckCount;
+    }
+
+    private void incrementBssidCheckCount() {
+        mBssidCheckCount++;
+    }
+
+    private void resetBssidCheckCount() {
+        this.mBssidCheckCount = 0;
+    }
+
     /**
      * The main thread for the watchdog monitoring. This will be turned into a
      * {@link Looper} thread.
@@ -1087,6 +1135,9 @@
         
         @Override
         public void handleMessage(Message msg) {
+            if (V) {
+                myLogV("handleMessage: " + msg.what);
+            }
             switch (msg.what) {
                 case MESSAGE_NETWORK_CHANGED:
                     handleNetworkChanged((String) msg.obj);
@@ -1118,19 +1169,35 @@
             }
         }
 
+        /**
+         * DNS based detection techniques do not work at all hotspots. The one sure way to check
+         * a walled garden is to see if a URL fetch on a known address fetches the data we
+         * expect
+         */
         private boolean isWalledGardenConnection() {
-            //One way to detect a walled garden is to see if multiple DNS queries
-            //resolve to the same IP address
+            InputStream in = null;
+            HttpURLConnection  urlConnection = null;
             try {
-                String host1 = "www.google.com";
-                String host2 = "www.android.com";
-                String address1 = InetAddress.getByName(host1).getHostAddress();
-                String address2 = InetAddress.getByName(host2).getHostAddress();
-                if (address1.equals(address2)) return true;
-            } catch (UnknownHostException e) {
+                URL url = new URL(getWalledGardenUrl());
+                urlConnection = (HttpURLConnection) url.openConnection();
+                in = new BufferedInputStream(urlConnection.getInputStream());
+                Scanner scanner = new Scanner(in);
+                if (scanner.findInLine(getWalledGardenPattern()) != null) {
+                    return false;
+                } else {
+                    return true;
+                }
+            } catch (IOException e) {
                 return false;
+            } finally {
+                if (in != null) {
+                    try {
+                        in.close();
+                    } catch (IOException e) {
+                    }
+                }
+                if (urlConnection != null) urlConnection.disconnect();
             }
-            return false;
         }
 
         private void handleWalledGardenCheck(String ssid) {
@@ -1214,34 +1281,36 @@
 
     /**
      * Describes an access point by its SSID and BSSID.
+     *
      */
     private static class AccessPoint {
         String ssid;
         String bssid;
         
+        /**
+         * @param ssid cannot be null
+         * @param bssid cannot be null
+         */
         AccessPoint(String ssid, String bssid) {
+            if (ssid == null || bssid == null) {
+                Slog.e(TAG, String.format("(%s) INVALID ACCESSPOINT: (%s, %s)",
+                        Thread.currentThread().getName(),ssid,bssid));
+            }
             this.ssid = ssid;
             this.bssid = bssid;
         }
-
-        private boolean hasNull() {
-            return ssid == null || bssid == null;
-        }
         
         @Override
         public boolean equals(Object o) {
             if (!(o instanceof AccessPoint)) return false;
             AccessPoint otherAp = (AccessPoint) o;
-            boolean iHaveNull = hasNull();
+
             // Either we both have a null, or our SSIDs and BSSIDs are equal
-            return (iHaveNull && otherAp.hasNull()) || 
-                    (otherAp.bssid != null && ssid.equals(otherAp.ssid)
-                    && bssid.equals(otherAp.bssid));
+            return ssid.equals(otherAp.ssid) && bssid.equals(otherAp.bssid);
         }
         
         @Override
         public int hashCode() {
-            if (ssid == null || bssid == null) return 0;
             return ssid.hashCode() + bssid.hashCode();
         }
 
@@ -1316,7 +1385,7 @@
                 return false;
                 
             } catch (Exception e) {
-                if (V || false) {
+                if (V) {
                     Slog.d(TAG, "DnsPinger.isReachable got an unknown exception", e);
                 }
                 return false;
diff --git a/services/java/com/android/server/accessibility/AccessibilityManagerService.java b/services/java/com/android/server/accessibility/AccessibilityManagerService.java
index d96369b..a9dfb22 100644
--- a/services/java/com/android/server/accessibility/AccessibilityManagerService.java
+++ b/services/java/com/android/server/accessibility/AccessibilityManagerService.java
@@ -16,11 +16,7 @@
 
 package com.android.server.accessibility;
 
-import com.android.internal.content.PackageMonitor;
-import com.android.internal.os.HandlerCaller;
-import com.android.internal.os.HandlerCaller.SomeArgs;
-import com.android.server.wm.WindowManagerService;
-
+import android.Manifest;
 import android.accessibilityservice.AccessibilityService;
 import android.accessibilityservice.AccessibilityServiceInfo;
 import android.accessibilityservice.IAccessibilityServiceConnection;
@@ -35,34 +31,46 @@
 import android.content.ServiceConnection;
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
-import android.content.pm.ServiceInfo;
 import android.database.ContentObserver;
 import android.net.Uri;
 import android.os.Binder;
-import android.os.DeadObjectException;
 import android.os.Handler;
 import android.os.IBinder;
 import android.os.Message;
 import android.os.RemoteException;
 import android.os.ServiceManager;
+import android.os.SystemClock;
 import android.provider.Settings;
 import android.text.TextUtils;
 import android.text.TextUtils.SimpleStringSplitter;
 import android.util.Slog;
 import android.util.SparseArray;
+import android.view.IWindow;
+import android.view.View;
 import android.view.accessibility.AccessibilityEvent;
+import android.view.accessibility.AccessibilityNodeInfo;
+import android.view.accessibility.IAccessibilityInteractionConnection;
+import android.view.accessibility.IAccessibilityInteractionConnectionCallback;
 import android.view.accessibility.IAccessibilityManager;
 import android.view.accessibility.IAccessibilityManagerClient;
 
+import com.android.internal.content.PackageMonitor;
+import com.android.internal.os.HandlerCaller;
+import com.android.internal.os.HandlerCaller.SomeArgs;
+import com.android.server.wm.WindowManagerService;
+
+import org.xmlpull.v1.XmlPullParserException;
+
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
 
 /**
  * This class is instantiated by the system as a system level service and can be
@@ -79,12 +87,17 @@
 
     private static final String LOG_TAG = "AccessibilityManagerService";
 
+    private static final String FUNCTION_REGISTER_EVENT_LISTENER =
+        "registerEventListener";
+
     private static int sIdCounter = 0;
 
     private static final int OWN_PROCESS_ID = android.os.Process.myPid();
 
     private static final int DO_SET_SERVICE_INFO = 10;
 
+    private static int sNextWindowId;
+
     final HandlerCaller mCaller;
 
     final Context mContext;
@@ -96,25 +109,35 @@
     final List<IAccessibilityManagerClient> mClients =
         new ArrayList<IAccessibilityManagerClient>();
 
-    final Map<ComponentName, Service> mComponentNameToServiceMap =
-        new HashMap<ComponentName, Service>();
+    final Map<ComponentName, Service> mComponentNameToServiceMap = new HashMap<ComponentName, Service>();
 
-    private final List<ServiceInfo> mInstalledServices = new ArrayList<ServiceInfo>();
+    private final List<AccessibilityServiceInfo> mInstalledServices = new ArrayList<AccessibilityServiceInfo>();
 
     private final Set<ComponentName> mEnabledServices = new HashSet<ComponentName>();
 
-    private final SimpleStringSplitter mStringColonSplitter = new SimpleStringSplitter(':');
+    private final SparseArray<IAccessibilityInteractionConnection> mWindowIdToInteractionConnectionMap =
+        new SparseArray<IAccessibilityInteractionConnection>();
 
-    private final SparseArray<List<ServiceInfo>> mFeedbackTypeToEnabledServicesMap =
-        new SparseArray<List<ServiceInfo>>();
+    private final SparseArray<IBinder> mWindowIdToWindowTokenMap = new SparseArray<IBinder>();
+
+    private final SimpleStringSplitter mStringColonSplitter = new SimpleStringSplitter(':');
 
     private PackageManager mPackageManager;
 
     private int mHandledFeedbackTypes = 0;
 
     private boolean mIsEnabled;
+
     private AccessibilityInputFilter mInputFilter;
 
+    private final List<AccessibilityServiceInfo> mEnabledServicesForFeedbackTempList = new ArrayList<AccessibilityServiceInfo>();
+
+    private boolean mHasInputFilter;
+
+    private final WindowManagerService mWindowManagerService;
+
+    private final SecurityPolicy mSecurityPolicy;
+
     /**
      * Handler for delayed event dispatch.
      */
@@ -127,9 +150,6 @@
 
             synchronized (mLock) {
                 notifyEventListenerLocked(service, eventType);
-                AccessibilityEvent oldEvent = service.mPendingEvents.get(eventType);
-                service.mPendingEvents.remove(eventType);
-                tryRecycleLocked(oldEvent);
             }
         }
     };
@@ -143,6 +163,9 @@
         mContext = context;
         mPackageManager = mContext.getPackageManager();
         mCaller = new HandlerCaller(context, this);
+        mWindowManagerService = (WindowManagerService) ServiceManager.getService(
+                Context.WINDOW_SERVICE);
+        mSecurityPolicy = new SecurityPolicy();
 
         registerPackageChangeAndBootCompletedBroadcastReceiver();
         registerSettingsContentObservers();
@@ -206,7 +229,6 @@
                 if (intent.getAction() == Intent.ACTION_BOOT_COMPLETED) {
                     synchronized (mLock) {
                         populateAccessibilityServiceListLocked();
-
                         // get the accessibility enabled setting on boot
                         mIsEnabled = Settings.Secure.getInt(mContext.getContentResolver(),
                                 Settings.Secure.ACCESSIBILITY_ENABLED, 0) == 1;
@@ -221,7 +243,7 @@
                     
                     return;
                 }
-                
+
                 super.onReceive(context, intent);
             }
         };
@@ -276,42 +298,60 @@
             });
     }
 
-    public boolean addClient(IAccessibilityManagerClient client) {
+    public boolean addClient(IAccessibilityManagerClient client) throws RemoteException {
         synchronized (mLock) {
-            mClients.add(client);
+            final IAccessibilityManagerClient addedClient = client;
+            mClients.add(addedClient);
+            // Clients are registered all the time until their process is
+            // killed, therefore we do not have a corresponding unlinkToDeath.
+            client.asBinder().linkToDeath(new DeathRecipient() {
+                public void binderDied() {
+                    synchronized (mLock) {
+                        mClients.remove(addedClient);
+                    }
+                }
+            }, 0);
             return mIsEnabled;
         }
     }
 
     public boolean sendAccessibilityEvent(AccessibilityEvent event) {
         synchronized (mLock) {
-            notifyAccessibilityServicesDelayedLocked(event, false);
-            notifyAccessibilityServicesDelayedLocked(event, true);
+            if (mSecurityPolicy.canDispatchAccessibilityEvent(event)) {
+                mSecurityPolicy.updateRetrievalAllowingWindowAndEventSourceLocked(event);
+                notifyAccessibilityServicesDelayedLocked(event, false);
+                notifyAccessibilityServicesDelayedLocked(event, true);
+            }
         }
-        // event not scheduled for dispatch => recycle
-        if (mHandledFeedbackTypes == 0) {
-            event.recycle();
-        } else {
-            mHandledFeedbackTypes = 0;
-        }
-
+        event.recycle();
+        mHandledFeedbackTypes = 0;
         return (OWN_PROCESS_ID != Binder.getCallingPid());
     }
 
-    public List<ServiceInfo> getAccessibilityServiceList() {
+    public List<AccessibilityServiceInfo> getInstalledAccessibilityServiceList() {
         synchronized (mLock) {
             return mInstalledServices;
         }
     }
 
-    public List<ServiceInfo> getEnabledAccessibilityServiceList(int feedbackType) {
+    public List<AccessibilityServiceInfo> getEnabledAccessibilityServiceList(int feedbackType) {
+        List<AccessibilityServiceInfo> result = mEnabledServicesForFeedbackTempList;
+        result.clear();
+        List<Service> services = mServices;
         synchronized (mLock) {
-            List<ServiceInfo> enabledServices = mFeedbackTypeToEnabledServicesMap.get(feedbackType);
-            if (enabledServices == null) {
-                return Collections.emptyList();
+            while (feedbackType != 0) {
+                final int feedbackTypeBit = (1 << Integer.numberOfTrailingZeros(feedbackType));
+                feedbackType &= ~feedbackTypeBit;
+                final int serviceCount = services.size();
+                for (int i = 0; i < serviceCount; i++) {
+                    Service service = services.get(i);
+                    if ((service.mFeedbackType & feedbackTypeBit) != 0) {
+                        result.add(service.mAccessibilityServiceInfo);
+                    }
+                }
             }
-            return enabledServices;
         }
+        return result;
     }
 
     public void interrupt() {
@@ -321,16 +361,8 @@
                 try {
                     service.mServiceInterface.onInterrupt();
                 } catch (RemoteException re) {
-                    if (re instanceof DeadObjectException) {
-                        Slog.w(LOG_TAG, "Dead " + service.mService + ". Cleaning up.");
-                        if (removeDeadServiceLocked(service)) {
-                            count--;
-                            i--;
-                        }
-                    } else {
-                        Slog.e(LOG_TAG, "Error during sending interrupt request to "
-                                + service.mService, re);
-                    }
+                    Slog.e(LOG_TAG, "Error during sending interrupt request to "
+                        + service.mService, re);
                 }
             }
         }
@@ -338,30 +370,94 @@
 
     public void executeMessage(Message message) {
         switch (message.what) {
-            case DO_SET_SERVICE_INFO:
+            case DO_SET_SERVICE_INFO: {
                 SomeArgs arguments = ((SomeArgs) message.obj);
 
                 AccessibilityServiceInfo info = (AccessibilityServiceInfo) arguments.arg1;
                 Service service = (Service) arguments.arg2;
 
                 synchronized (mLock) {
-                    service.mEventTypes = info.eventTypes;
-                    service.mFeedbackType = info.feedbackType;
-                    String[] packageNames = info.packageNames;
-                    if (packageNames != null) {
-                        service.mPackageNames.addAll(Arrays.asList(packageNames));
+                    // If the XML manifest had data to configure the service its info
+                    // should be already set. In such a case update only the dynamically
+                    // configurable properties.
+                    AccessibilityServiceInfo oldInfo = service.mAccessibilityServiceInfo;
+                    if (oldInfo != null) {
+                        oldInfo.updateDynamicallyConfigurableProperties(info);
+                        service.setDynamicallyConfigurableProperties(oldInfo);
+                    } else {
+                        service.setDynamicallyConfigurableProperties(info);
                     }
-                    service.mNotificationTimeout = info.notificationTimeout;
-                    service.mIsDefault = (info.flags & AccessibilityServiceInfo.DEFAULT) != 0;
-
-                    updateStateOnEnabledService(service);
                 }
-                return;
+            } return;
             default:
                 Slog.w(LOG_TAG, "Unknown message type: " + message.what);
         }
     }
 
+    public int addAccessibilityInteractionConnection(IWindow windowToken,
+            IAccessibilityInteractionConnection connection) throws RemoteException {
+        synchronized (mLock) {
+            final IWindow addedWindowToken = windowToken;
+            final int windowId = sNextWindowId++;
+            connection.asBinder().linkToDeath(new DeathRecipient() {
+                public void binderDied() {
+                    synchronized (mLock) {
+                        removeAccessibilityInteractionConnection(addedWindowToken);
+                    }
+                }
+            }, 0);
+            mWindowIdToWindowTokenMap.put(windowId, addedWindowToken.asBinder());
+            mWindowIdToInteractionConnectionMap.put(windowId, connection);
+            if (DEBUG) {
+                Slog.i(LOG_TAG, "Adding interaction connection to windowId: " + windowId);
+            }
+            return windowId;
+        }
+    }
+
+    public void removeAccessibilityInteractionConnection(IWindow windowToken) {
+        synchronized (mLock) {
+            final int count = mWindowIdToWindowTokenMap.size();
+            for (int i = 0; i < count; i++) {
+                if (mWindowIdToWindowTokenMap.valueAt(i) == windowToken.asBinder()) {
+                    final int windowId = mWindowIdToWindowTokenMap.keyAt(i);
+                    mWindowIdToWindowTokenMap.remove(windowId);
+                    mWindowIdToInteractionConnectionMap.remove(windowId);
+                    if (DEBUG) {
+                        Slog.i(LOG_TAG, "Removing interaction connection to windowId: " + windowId);
+                    }
+                    return;
+                }
+            }
+        }
+    }
+
+    public IAccessibilityServiceConnection registerEventListener(IEventListener listener) {
+        mSecurityPolicy.enforceCallingPermission(Manifest.permission.RETRIEVE_WINDOW_CONTENT,
+                FUNCTION_REGISTER_EVENT_LISTENER);
+        ComponentName componentName = new ComponentName("foo.bar", "FakeAccessibilityService");
+        synchronized (mLock) {
+            Service oldService = mComponentNameToServiceMap.get(componentName);
+            if (oldService != null) {
+                tryRemoveServiceLocked(oldService);
+            }
+            // This API is intended for testing so enable accessibility to make
+            // sure clients can start poking with the window content.
+            Settings.Secure.putInt(mContext.getContentResolver(),
+                    Settings.Secure.ACCESSIBILITY_ENABLED, 1);
+            // Also disable all accessibility services to avoid interference
+            // with the tests.
+            Settings.Secure.putString(mContext.getContentResolver(),
+                    Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, "");
+        }
+        AccessibilityServiceInfo accessibilityServiceInfo = new AccessibilityServiceInfo();
+        accessibilityServiceInfo.eventTypes = AccessibilityEvent.TYPES_ALL_MASK;
+        accessibilityServiceInfo.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
+        Service service = new Service(componentName, accessibilityServiceInfo, true);
+        service.onServiceConnected(componentName, listener.asBinder());
+        return service;
+    }
+
     /**
      * Populates the cached list of installed {@link AccessibilityService}s.
      */
@@ -369,10 +465,20 @@
         mInstalledServices.clear();
 
         List<ResolveInfo> installedServices = mPackageManager.queryIntentServices(
-                new Intent(AccessibilityService.SERVICE_INTERFACE), PackageManager.GET_SERVICES);
+                new Intent(AccessibilityService.SERVICE_INTERFACE),
+                PackageManager.GET_SERVICES | PackageManager.GET_META_DATA);
 
         for (int i = 0, count = installedServices.size(); i < count; i++) {
-            mInstalledServices.add(installedServices.get(i).serviceInfo);
+            ResolveInfo resolveInfo = installedServices.get(i);
+            AccessibilityServiceInfo accessibilityServiceInfo;
+            try {
+                accessibilityServiceInfo = new AccessibilityServiceInfo(resolveInfo, mContext);
+                mInstalledServices.add(accessibilityServiceInfo);
+            } catch (XmlPullParserException xppe) {
+                Slog.e(LOG_TAG, "Error while initializing AccessibilityServiceInfo", xppe);
+            } catch (IOException ioe) {
+                Slog.e(LOG_TAG, "Error while initializing AccessibilityServiceInfo", ioe);
+            }
         }
     }
 
@@ -414,46 +520,27 @@
     private void notifyAccessibilityServiceDelayedLocked(Service service,
             AccessibilityEvent event) {
         synchronized (mLock) {
-            int eventType = event.getEventType();
+            final int eventType = event.getEventType();
+            // Make a copy since during dispatch it is possible the event to
+            // be modified to remove its source if the receiving service does
+            // not have permission to access the window content.
+            AccessibilityEvent newEvent = AccessibilityEvent.obtain(event);
             AccessibilityEvent oldEvent = service.mPendingEvents.get(eventType);
-            service.mPendingEvents.put(eventType, event);
+            service.mPendingEvents.put(eventType, newEvent);
 
-            int what = eventType | (service.mId << 16);
+            final int what = eventType | (service.mId << 16);
             if (oldEvent != null) {
                 mHandler.removeMessages(what);
-                tryRecycleLocked(oldEvent);
+                oldEvent.recycle();
             }
 
             Message message = mHandler.obtainMessage(what, service);
-            message.arg1 = event.getEventType();
+            message.arg1 = eventType;
             mHandler.sendMessageDelayed(message, service.mNotificationTimeout);
         }
     }
 
     /**
-     * Recycles an event if it can be safely recycled. The condition is that no
-     * not notified service is interested in the event.
-     *
-     * @param event The event.
-     */
-    private void tryRecycleLocked(AccessibilityEvent event) {
-        if (event == null) {
-            return;
-        }
-        int eventType = event.getEventType();
-        List<Service> services = mServices;
-
-        // linear in the number of service which is not large
-        for (int i = 0, count = services.size(); i < count; i++) {
-            Service service = services.get(i);
-            if (service.mPendingEvents.get(eventType) == event) {
-                return;
-            }
-        }
-        event.recycle();
-    }
-
-    /**
      * Notifies a service for a scheduled event given the event type.
      *
      * @param service The service.
@@ -462,35 +549,59 @@
     private void notifyEventListenerLocked(Service service, int eventType) {
         IEventListener listener = service.mServiceInterface;
         AccessibilityEvent event = service.mPendingEvents.get(eventType);
-
+        service.mPendingEvents.remove(eventType);
         try {
+            if (mSecurityPolicy.canRetrieveWindowContent(service)) {
+                event.setConnection(service);
+            } else {
+                event.setSource(null);
+            }
+            event.setSealed(true);
             listener.onAccessibilityEvent(event);
+            event.recycle();
             if (DEBUG) {
                 Slog.i(LOG_TAG, "Event " + event + " sent to " + listener);
             }
         } catch (RemoteException re) {
-            if (re instanceof DeadObjectException) {
-                Slog.w(LOG_TAG, "Dead " + service.mService + ". Cleaning up.");
-                removeDeadServiceLocked(service);
-            } else {
-                Slog.e(LOG_TAG, "Error during sending " + event + " to " + service.mService, re);
-            }
+            Slog.e(LOG_TAG, "Error during sending " + event + " to " + service.mService, re);
         }
     }
 
     /**
-     * Removes a dead service.
+     * Adds a service.
+     *
+     * @param service The service to add.
+     */
+    private void tryAddServiceLocked(Service service) {
+        try {
+            if (mServices.contains(service) || !service.isConfigured()) {
+                return;
+            }
+            service.linkToOwnDeath();
+            mServices.add(service);
+            mComponentNameToServiceMap.put(service.mComponentName, service);
+            updateInputFilterLocked();
+        } catch (RemoteException e) {
+            /* do nothing */
+        }
+    }
+
+    /**
+     * Removes a service.
      *
      * @param service The service.
      * @return True if the service was removed, false otherwise.
      */
-    private boolean removeDeadServiceLocked(Service service) {
-        if (DEBUG) {
-            Slog.i(LOG_TAG, "Dead service " + service.mService + " removed");
+    private boolean tryRemoveServiceLocked(Service service) {
+        final boolean removed = mServices.remove(service);
+        if (!removed) {
+            return false;
         }
+        mComponentNameToServiceMap.remove(service.mComponentName);
         mHandler.removeMessages(service.mId);
-        updateStateOnDisabledService(service);
-        return mServices.remove(service);
+        service.unlinkToOwnDeath();
+        updateInputFilterLocked();
+        return removed;
     }
 
     /**
@@ -513,11 +624,6 @@
             return false;
         }
 
-        if (!service.mService.isBinderAlive()) {
-            removeDeadServiceLocked(service);
-            return false;
-        }
-
         int eventType = event.getEventType();
         if ((service.mEventTypes & eventType) != eventType) {
             return false;
@@ -595,22 +701,22 @@
      * @param installedServices All installed {@link AccessibilityService}s.
      * @param enabledServices The {@link ComponentName}s of the enabled services.
      */
-    private void updateServicesStateLocked(List<ServiceInfo> installedServices,
+    private void updateServicesStateLocked(List<AccessibilityServiceInfo> installedServices,
             Set<ComponentName> enabledServices) {
 
         Map<ComponentName, Service> componentNameToServiceMap = mComponentNameToServiceMap;
         boolean isEnabled = mIsEnabled;
 
         for (int i = 0, count = installedServices.size(); i < count; i++) {
-            ServiceInfo intalledService = installedServices.get(i);
-            ComponentName componentName = new ComponentName(intalledService.packageName,
-                    intalledService.name);
+            AccessibilityServiceInfo installedService = installedServices.get(i);
+            ComponentName componentName = ComponentName.unflattenFromString(
+                    installedService.getId());
             Service service = componentNameToServiceMap.get(componentName);
 
             if (isEnabled) {
                 if (enabledServices.contains(componentName)) {
                     if (service == null) {
-                        service = new Service(componentName, intalledService);
+                        service = new Service(componentName, installedService, false);
                     }
                     service.bind();
                 } else if (!enabledServices.contains(componentName)) {
@@ -642,64 +748,29 @@
     }
 
     /**
-     * Sets the input filter state. If the filter is in enabled it is registered
-     * in the window manager, otherwise the filter is removed from the latter.
-     *
-     * @param enabled Whether the input filter is enabled.
+     * Updates the input filter state. The filter is enabled if accessibility
+     * is enabled and there is at least one accessibility service providing
+     * spoken feedback.
      */
-    private void setInputFilterEnabledLocked(boolean enabled) {
-        WindowManagerService wm = (WindowManagerService)ServiceManager.getService(
-                Context.WINDOW_SERVICE);
-        if (wm != null) {
-            if (enabled) {
+    private void updateInputFilterLocked() {
+        if (mIsEnabled) {
+            final boolean hasSpokenFeedbackServices = !getEnabledAccessibilityServiceList(
+                    AccessibilityServiceInfo.FEEDBACK_SPOKEN).isEmpty();
+            if (hasSpokenFeedbackServices) {
+                if (mHasInputFilter) {
+                    return;
+                }
                 if (mInputFilter == null) {
                     mInputFilter = new AccessibilityInputFilter(mContext);
                 }
-                wm.setInputFilter(mInputFilter);
-            } else {
-                wm.setInputFilter(null);
+                mWindowManagerService.setInputFilter(mInputFilter);
+                mHasInputFilter = true;
+                return;
             }
         }
-    }
-
-    /**
-     * Updates the set of enabled services for a given feedback type and
-     * if more than one of them provides spoken feedback enables touch
-     * exploration.
-     *
-     * @param service An enable service.
-     */
-    private void updateStateOnEnabledService(Service service) {
-        int feedbackType = service.mFeedbackType;
-        List<ServiceInfo> enabledServices = mFeedbackTypeToEnabledServicesMap.get(feedbackType);
-        if (enabledServices == null) {
-            enabledServices = new ArrayList<ServiceInfo>();
-            mFeedbackTypeToEnabledServicesMap.put(feedbackType, enabledServices);
-        }
-        enabledServices.add(service.mServiceInfo);
-
-        // We enable touch exploration if at least one
-        // enabled service provides spoken feedback.
-        if (enabledServices.size() > 0
-                && service.mFeedbackType == AccessibilityServiceInfo.FEEDBACK_SPOKEN) {
-            updateClientsLocked();
-            setInputFilterEnabledLocked(true);
-        }
-    }
-
-    private void updateStateOnDisabledService(Service service) {
-        List<ServiceInfo> enabledServices =
-            mFeedbackTypeToEnabledServicesMap.get(service.mFeedbackType);
-        if (enabledServices == null) {
-            return;
-        }
-        enabledServices.remove(service.mServiceInfo);
-        // We disable touch exploration if no
-        // enabled service provides spoken feedback.
-        if (enabledServices.isEmpty()
-                && service.mFeedbackType == AccessibilityServiceInfo.FEEDBACK_SPOKEN) {
-            updateClientsLocked();
-            setInputFilterEnabledLocked(false);
+        if (mHasInputFilter) {
+            mWindowManagerService.setInputFilter(null);
+            mHasInputFilter = false;
         }
     }
 
@@ -711,10 +782,11 @@
      * passed to the service it represents as soon it is bound. It also serves as the
      * connection for the service.
      */
-    class Service extends IAccessibilityServiceConnection.Stub implements ServiceConnection {
+    class Service extends IAccessibilityServiceConnection.Stub
+            implements ServiceConnection, DeathRecipient {
         int mId = 0;
 
-        ServiceInfo mServiceInfo;
+        AccessibilityServiceInfo mAccessibilityServiceInfo;
 
         IBinder mService;
 
@@ -730,25 +802,54 @@
 
         long mNotificationTimeout;
 
-        boolean mIsActive;
-
         ComponentName mComponentName;
 
         Intent mIntent;
 
+        boolean mCanRetrieveScreenContent;
+
+        boolean mIsFake;
+
+        final Callback mCallback = new Callback();
+
+        final AtomicInteger mInteractionIdCounter = new AtomicInteger();
+
         // the events pending events to be dispatched to this service
         final SparseArray<AccessibilityEvent> mPendingEvents =
             new SparseArray<AccessibilityEvent>();
 
-        Service(ComponentName componentName, ServiceInfo serviceInfo) {
+        public Service(ComponentName componentName,
+                AccessibilityServiceInfo accessibilityServiceInfo, boolean isFake) {
             mId = sIdCounter++;
             mComponentName = componentName;
-            mServiceInfo = serviceInfo;
-            mIntent = new Intent().setComponent(mComponentName);
-            mIntent.putExtra(Intent.EXTRA_CLIENT_LABEL,
-                    com.android.internal.R.string.accessibility_binding_label);
-            mIntent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivity(
-                    mContext, 0, new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS), 0));
+            mAccessibilityServiceInfo = accessibilityServiceInfo;
+            mIsFake = isFake;
+            if (!isFake) {
+                mCanRetrieveScreenContent = accessibilityServiceInfo.getCanRetrieveWindowContent();
+                mIntent = new Intent().setComponent(mComponentName);
+                mIntent.putExtra(Intent.EXTRA_CLIENT_LABEL,
+                        com.android.internal.R.string.accessibility_binding_label);
+                mIntent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivity(
+                        mContext, 0, new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS), 0));
+            } else {
+                mCanRetrieveScreenContent = true;
+            }
+            setDynamicallyConfigurableProperties(accessibilityServiceInfo);
+        }
+
+        public void setDynamicallyConfigurableProperties(AccessibilityServiceInfo info) {
+            mEventTypes = info.eventTypes;
+            mFeedbackType = info.feedbackType;
+            String[] packageNames = info.packageNames;
+            if (packageNames != null) {
+                mPackageNames.addAll(Arrays.asList(packageNames));
+            }
+            mNotificationTimeout = info.notificationTimeout;
+            mIsDefault = (info.flags & AccessibilityServiceInfo.DEFAULT) != 0;
+
+            synchronized (mLock) {
+                tryAddServiceLocked(this);
+            }
         }
 
         /**
@@ -757,7 +858,7 @@
          * @return True if binding is successful.
          */
         public boolean bind() {
-            if (mService == null) {
+            if (!mIsFake && mService == null) {
                 return mContext.bindService(mIntent, this, Context.BIND_AUTO_CREATE);
             }
             return false;
@@ -771,11 +872,13 @@
          */
         public boolean unbind() {
             if (mService != null) {
+                synchronized (mLock) {
+                    tryRemoveServiceLocked(this);
+                }
+                if (!mIsFake) {
+                    mContext.unbindService(this);
+                }
                 mService = null;
-                mContext.unbindService(this);
-                mComponentNameToServiceMap.remove(mComponentName);
-                mServices.remove(this);
-                updateStateOnDisabledService(this);
                 return true;
             }
             return false;
@@ -788,7 +891,7 @@
          * @return True if the service is configured, false otherwise.
          */
         public boolean isConfigured() {
-            return (mEventTypes != 0 && mFeedbackType != 0);
+            return (mEventTypes != 0 && mFeedbackType != 0 && mService != null);
         }
 
         public void setServiceInfo(AccessibilityServiceInfo info) {
@@ -798,24 +901,361 @@
         public void onServiceConnected(ComponentName componentName, IBinder service) {
             mService = service;
             mServiceInterface = IEventListener.Stub.asInterface(service);
-
             try {
                 mServiceInterface.setConnection(this);
                 synchronized (mLock) {
-                    if (!mServices.contains(this)) {
-                        mServices.add(this);
-                        mComponentNameToServiceMap.put(componentName, this);
-                    }
+                    tryAddServiceLocked(this);
                 }
             } catch (RemoteException re) {
                 Slog.w(LOG_TAG, "Error while setting Controller for service: " + service, re);
             }
         }
 
-        public void onServiceDisconnected(ComponentName componentName) {
+        public AccessibilityNodeInfo findAccessibilityNodeInfoByViewIdInActiveWindow(int viewId) {
+            IAccessibilityInteractionConnection connection = null;
             synchronized (mLock) {
-                Service service = mComponentNameToServiceMap.remove(componentName);
-                mServices.remove(service);
+                final boolean permissionGranted = mSecurityPolicy.canRetrieveWindowContent(this);
+                if (permissionGranted) {
+                    connection = getConnectionToRetrievalAllowingWindowLocked();
+                }
+            }
+            if (connection == null) {
+                if (DEBUG) {
+                    Slog.e(LOG_TAG, "No interaction connection to a retrieve allowing window.");
+                }
+                return null;
+            }
+            final long identityToken = Binder.clearCallingIdentity();
+            try {
+                final int interactionId = mInteractionIdCounter.getAndIncrement();
+                connection.findAccessibilityNodeInfoByViewId(viewId, interactionId, mCallback);
+                AccessibilityNodeInfo info = mCallback.getFindAccessibilityNodeInfoResultAndClear(
+                        interactionId);
+                if (info != null) {
+                    info.setConnection(this);
+                }
+                info.setSealed(true);
+                return info;
+            } catch (RemoteException re) {
+                if (DEBUG) {
+                    Slog.e(LOG_TAG, "Error finding node.");
+                }
+            } finally {
+                Binder.restoreCallingIdentity(identityToken);
+            }
+            return null;
+        }
+
+        public List<AccessibilityNodeInfo> findAccessibilityNodeInfosByViewTextInActiveWindow(
+                String text) {
+            return findAccessibilityNodeInfosByViewText(text,
+                    mSecurityPolicy.mRetrievalAlowingWindowId, View.NO_ID);
+        }
+
+        public List<AccessibilityNodeInfo> findAccessibilityNodeInfosByViewText(String text,
+                int accessibilityWindowId, int accessibilityViewId) {
+            IAccessibilityInteractionConnection connection = null;
+            synchronized (mLock) {
+                final boolean permissionGranted =
+                    mSecurityPolicy.canGetAccessibilityNodeInfoLocked(this, accessibilityWindowId);
+                if (permissionGranted) {
+                    connection = getConnectionToRetrievalAllowingWindowLocked();
+                }
+            }
+            if (connection == null) {
+                if (DEBUG) {
+                    Slog.e(LOG_TAG, "No interaction connection to focused window.");
+                }
+                return null;
+            }
+            final long identityToken = Binder.clearCallingIdentity();
+            try {
+                final int interactionId = mInteractionIdCounter.getAndIncrement();
+                connection.findAccessibilityNodeInfosByViewText(text, accessibilityViewId,
+                        interactionId, mCallback);
+                List<AccessibilityNodeInfo> infos =
+                    mCallback.getFindAccessibilityNodeInfosResultAndClear(interactionId);
+                if (infos != null) {
+                    final int infoCount = infos.size();
+                    for (int i = 0; i < infoCount; i++) {
+                        AccessibilityNodeInfo info = infos.get(i);
+                        info.setConnection(this);
+                        info.setSealed(true);
+                    }
+                }
+                return infos;
+            } catch (RemoteException re) {
+                if (DEBUG) {
+                    Slog.e(LOG_TAG, "Error finding node.");
+                }
+            } finally {
+                Binder.restoreCallingIdentity(identityToken);
+            }
+            return null;
+        }
+
+        public AccessibilityNodeInfo findAccessibilityNodeInfoByAccessibilityId(
+                int accessibilityWindowId, int accessibilityViewId) {
+            IAccessibilityInteractionConnection connection = null;
+            synchronized (mLock) {
+                final boolean permissionGranted =
+                    mSecurityPolicy.canGetAccessibilityNodeInfoLocked(this, accessibilityWindowId);
+                if (permissionGranted) {
+                    connection = mWindowIdToInteractionConnectionMap.get(accessibilityWindowId);
+                }
+            }
+            if (connection == null) {
+                if (DEBUG) {
+                    Slog.e(LOG_TAG, "No interaction connection to window: "
+                            + accessibilityWindowId);
+                }
+                return null;
+            }
+            final long identityToken = Binder.clearCallingIdentity();
+            try {
+                final int interactionId = mInteractionIdCounter.getAndIncrement();
+                connection.findAccessibilityNodeInfoByAccessibilityId(accessibilityViewId,
+                        interactionId, mCallback);
+                AccessibilityNodeInfo info =
+                     mCallback.getFindAccessibilityNodeInfoResultAndClear(interactionId);
+                if (info != null) {
+                    info.setConnection(this);
+                    info.setSealed(true);
+                }
+                return info;
+            } catch (RemoteException re) {
+                if (DEBUG) {
+                    Slog.e(LOG_TAG, "Error requesting node with accessibilityViewId: "
+                            + accessibilityViewId);
+                }
+            } finally {
+                Binder.restoreCallingIdentity(identityToken);
+            }
+            return null;
+        }
+
+        public boolean performAccessibilityAction(int accessibilityWindowId,
+                int accessibilityViewId, int action) {
+            IAccessibilityInteractionConnection connection = null;
+            synchronized (mLock) {
+                final boolean permissionGranted = mSecurityPolicy.canPerformActionLocked(this,
+                        accessibilityWindowId, action);
+                if (permissionGranted) {
+                    connection = mWindowIdToInteractionConnectionMap.get(accessibilityWindowId);
+                }
+            }
+            if (connection == null) {
+                if (DEBUG) {
+                    Slog.e(LOG_TAG, "No interaction connection to window: "
+                            + accessibilityWindowId);
+                }
+                return false;
+            }
+            final long identityToken = Binder.clearCallingIdentity();
+            try {
+                final int interactionId = mInteractionIdCounter.getAndIncrement();
+                connection.performAccessibilityAction(accessibilityViewId, action, interactionId,
+                        mCallback);
+                return mCallback.getPerformAccessibilityActionResult(interactionId);
+            } catch (RemoteException re) {
+                if (DEBUG) {
+                    Slog.e(LOG_TAG, "Error requesting node with accessibilityViewId: "
+                            + accessibilityViewId);
+                }
+            } finally {
+                Binder.restoreCallingIdentity(identityToken);
+            }
+            return false;
+        }
+
+        public void onServiceDisconnected(ComponentName componentName) {
+            /* do nothing - #binderDied takes care */
+        }
+
+        public void linkToOwnDeath() throws RemoteException {
+            mService.linkToDeath(this, 0);
+        }
+
+        public void unlinkToOwnDeath() {
+            mService.unlinkToDeath(this, 0);
+        }
+
+        public void binderDied() {
+            synchronized (mLock) {
+                tryRemoveServiceLocked(this);
+            }
+        }
+
+        private IAccessibilityInteractionConnection getConnectionToRetrievalAllowingWindowLocked() {
+            final int windowId = mSecurityPolicy.getRetrievalAllowingWindowLocked();
+            if (DEBUG) {
+                Slog.i(LOG_TAG, "Trying to get interaction connection to windowId: " + windowId);
+            }
+            return mWindowIdToInteractionConnectionMap.get(windowId);
+        }
+    }
+
+    final class SecurityPolicy {
+        private static final int VALID_ACTIONS = AccessibilityNodeInfo.ACTION_FOCUS
+            | AccessibilityNodeInfo.ACTION_CLEAR_FOCUS | AccessibilityNodeInfo.ACTION_SELECT
+            | AccessibilityNodeInfo.ACTION_CLEAR_SELECTION;
+
+        private static final int RETRIEVAL_ALLOWING_EVENT_TYPES =
+            AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_END
+            | AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_START
+            | AccessibilityEvent.TYPE_VIEW_CLICKED | AccessibilityEvent.TYPE_VIEW_FOCUSED
+            | AccessibilityEvent.TYPE_VIEW_HOVER_ENTER | AccessibilityEvent.TYPE_VIEW_HOVER_EXIT
+            | AccessibilityEvent.TYPE_VIEW_LONG_CLICKED | AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED
+            | AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED | AccessibilityEvent.TYPE_VIEW_SELECTED
+            | AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED;
+
+        private int mRetrievalAlowingWindowId;
+
+        private boolean canDispatchAccessibilityEvent(AccessibilityEvent event) {
+            // Send window changed event only for the retrieval allowing window.
+            return (event.getEventType() != AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED
+                    || event.getWindowId() == mRetrievalAlowingWindowId);
+        }
+
+        public void updateRetrievalAllowingWindowAndEventSourceLocked(AccessibilityEvent event) {
+            final int windowId = event.getWindowId();
+            final int eventType = event.getEventType();
+            if ((eventType & RETRIEVAL_ALLOWING_EVENT_TYPES) != 0) {
+                mRetrievalAlowingWindowId = windowId;
+            } else { 
+                event.setSource(null);
+            }
+        }
+
+        public int getRetrievalAllowingWindowLocked() {
+            return mRetrievalAlowingWindowId;
+        }
+
+        public boolean canGetAccessibilityNodeInfoLocked(Service service, int windowId) {
+            return canRetrieveWindowContent(service) && isRetrievalAllowingWindow(windowId);
+        }
+
+        public boolean canPerformActionLocked(Service service, int windowId, int action) {
+            return canRetrieveWindowContent(service)
+                && isRetrievalAllowingWindow(windowId)
+                && isActionPermitted(action);
+        }
+
+        public boolean canRetrieveWindowContent(Service service) {
+            return service.mCanRetrieveScreenContent;
+        }
+
+        private boolean isRetrievalAllowingWindow(int windowId) {
+            return (mRetrievalAlowingWindowId == windowId);
+        }
+
+        private boolean isActionPermitted(int action) {
+             return (VALID_ACTIONS & action) != 0;
+        }
+
+        private void enforceCallingPermission(String permission, String function) {
+            if (OWN_PROCESS_ID == Binder.getCallingPid()) {
+                return;
+            }
+            final int permissionStatus = mContext.checkCallingPermission(permission);
+            if (permissionStatus != PackageManager.PERMISSION_GRANTED) {
+                throw new SecurityException("You do not have " + permission
+                        + " required to call " + function);
+            }
+        }
+    }
+
+    final class Callback extends IAccessibilityInteractionConnectionCallback.Stub {
+        private static final long TIMEOUT_INTERACTION_MILLIS = 5000;
+
+        private int mInteractionId = -1;
+        private AccessibilityNodeInfo mFindAccessibilityNodeInfoResult;
+        private List<AccessibilityNodeInfo> mFindAccessibilityNodeInfosResult;
+        private boolean mPerformAccessibilityActionResult;
+
+        public void setFindAccessibilityNodeInfoResult(AccessibilityNodeInfo info,
+                int interactionId) {
+            synchronized (mLock) {
+                if (interactionId > mInteractionId) {
+                    mFindAccessibilityNodeInfoResult = info;
+                    mInteractionId = interactionId;
+                }
+                mLock.notifyAll();
+            }
+        }
+
+        public AccessibilityNodeInfo getFindAccessibilityNodeInfoResultAndClear(int interactionId) {
+            synchronized (mLock) {
+                waitForResultTimedLocked(TIMEOUT_INTERACTION_MILLIS, interactionId);
+                AccessibilityNodeInfo result = mFindAccessibilityNodeInfoResult;
+                clearLocked();
+                return result;
+            }
+        }
+
+        public void setFindAccessibilityNodeInfosResult(List<AccessibilityNodeInfo> infos,
+                int interactionId) {
+            synchronized (mLock) {
+                if (interactionId > mInteractionId) {
+                    mFindAccessibilityNodeInfosResult = infos;
+                    mInteractionId = interactionId;
+                }
+                mLock.notifyAll();
+            }
+        }
+
+        public List<AccessibilityNodeInfo> getFindAccessibilityNodeInfosResultAndClear(
+                int interactionId) {
+            synchronized (mLock) {
+                waitForResultTimedLocked(TIMEOUT_INTERACTION_MILLIS, interactionId);
+                List<AccessibilityNodeInfo> result = mFindAccessibilityNodeInfosResult;
+                clearLocked();
+                return result;
+            }
+        }
+
+        public void setPerformAccessibilityActionResult(boolean succeeded, int interactionId) {
+            synchronized (mLock) {
+                if (interactionId > mInteractionId) {
+                    mPerformAccessibilityActionResult = succeeded;
+                    mInteractionId = interactionId;
+                }
+                mLock.notifyAll();
+            }
+        }
+
+        public boolean getPerformAccessibilityActionResult(int interactionId) {
+            synchronized (mLock) {
+                waitForResultTimedLocked(TIMEOUT_INTERACTION_MILLIS, interactionId);
+                final boolean result = mPerformAccessibilityActionResult;
+                clearLocked();
+                return result;
+            }
+        }
+
+        public void clearLocked() {
+            mInteractionId = -1;
+            mFindAccessibilityNodeInfoResult = null;
+            mFindAccessibilityNodeInfosResult = null;
+            mPerformAccessibilityActionResult = false;
+        }
+
+        private void waitForResultTimedLocked(long waitTimeMillis, int interactionId) {
+            final long startTimeMillis = SystemClock.uptimeMillis();
+            while (true) {
+                try {
+                    if (mInteractionId == interactionId) {
+                        return;
+                    }
+                    final long elapsedTimeMillis = SystemClock.uptimeMillis() - startTimeMillis;
+                    waitTimeMillis = TIMEOUT_INTERACTION_MILLIS - elapsedTimeMillis;
+                    if (waitTimeMillis <= 0) {
+                        return;
+                    }
+                    mLock.wait(waitTimeMillis);
+                } catch (InterruptedException ie) {
+                    /* ignore */
+                }
             }
         }
     }
diff --git a/services/java/com/android/server/accessibility/TouchExplorer.java b/services/java/com/android/server/accessibility/TouchExplorer.java
index 4c7f595..aab189a6 100644
--- a/services/java/com/android/server/accessibility/TouchExplorer.java
+++ b/services/java/com/android/server/accessibility/TouchExplorer.java
@@ -226,8 +226,9 @@
                 // Send a hover for every finger down so the user gets feedback
                 // where she is currently touching.
                 mSendHoverDelayed.forceSendAndRemove();
-                mSendHoverDelayed.post(event, MotionEvent.ACTION_HOVER_ENTER, 1, policyFlags,
-                        DELAY_SEND_HOVER_MOVE);
+                final int pointerIdBits = (1 << event.getActionIndex());
+                mSendHoverDelayed.post(event, MotionEvent.ACTION_HOVER_ENTER, pointerIdBits,
+                        policyFlags, DELAY_SEND_HOVER_MOVE);
             } break;
             case MotionEvent.ACTION_POINTER_DOWN: {
                 switch (activePointerCount) {
@@ -350,11 +351,12 @@
                         if (isDraggingGesture(event)) {
                             // Two pointers moving in the same direction within
                             // a given distance perform a drag.
-                            mCurrentState = STATE_DRAGGING;      
+                            mCurrentState = STATE_DRAGGING;
                             if (mTouchExploreGestureInProgress) {
                                 sendAccessibilityEvent(TYPE_TOUCH_EXPLORATION_GESTURE_END);
                                 mTouchExploreGestureInProgress = false;
                             }
+                            mLastTouchExploreEvent = null;
                             mDraggingPointerId = pointerId;
                             sendMotionEvent(event, MotionEvent.ACTION_DOWN, pointerIdBits,
                                     policyFlags);
@@ -365,6 +367,7 @@
                                 sendAccessibilityEvent(TYPE_TOUCH_EXPLORATION_GESTURE_END);
                                 mTouchExploreGestureInProgress = false;
                             }
+                            mLastTouchExploreEvent = null;
                             sendDownForAllActiveNotInjectedPointers(event, policyFlags);
                         }
                     } break;
@@ -382,6 +385,7 @@
                             sendAccessibilityEvent(TYPE_TOUCH_EXPLORATION_GESTURE_END);
                             mTouchExploreGestureInProgress = false;
                         }
+                        mLastTouchExploreEvent = null;
                         sendDownForAllActiveNotInjectedPointers(event, policyFlags);
                     }
                 }
@@ -728,7 +732,7 @@
     /**
      * Sends an event.
      *
-     * @param event The event to send.
+     * @param prototype The prototype from which to create the injected events.
      * @param action The action of the event.
      * @param pointerIdBits The bits of the pointers to send.
      * @param policyFlags The policy flags associated with the event.
@@ -979,7 +983,7 @@
                 case MotionEvent.ACTION_DOWN: {
                     // New gesture so restart tracking injected down pointers.
                     mInjectedPointersDown = 0;
-                    handleReceivedPointerDown(0, event);
+                    handleReceivedPointerDown(event.getActionIndex(), event);
                 } break;
                 case MotionEvent.ACTION_POINTER_DOWN: {
                     handleReceivedPointerDown(event.getActionIndex(), event);
@@ -988,7 +992,7 @@
                     handleReceivedPointerMove(event);
                 } break;
                 case MotionEvent.ACTION_UP: {
-                    handleReceivedPointerUp(0, event);
+                    handleReceivedPointerUp(event.getActionIndex(), event);
                 } break;
                 case MotionEvent.ACTION_POINTER_UP: {
                     handleReceivedPointerUp(event.getActionIndex(), event);
@@ -1008,13 +1012,13 @@
             final int action = event.getActionMasked();
             switch (action) {
                 case MotionEvent.ACTION_DOWN: {
-                    handleInjectedPointerDown(0, event);
+                    handleInjectedPointerDown(event.getActionIndex(), event);
                 } break;
                 case MotionEvent.ACTION_POINTER_DOWN: {
                     handleInjectedPointerDown(event.getActionIndex(), event);
                 } break;
                 case MotionEvent.ACTION_UP: {
-                    handleInjectedPointerUp(0, event);
+                    handleInjectedPointerUp(event.getActionIndex(), event);
                 } break;
                 case MotionEvent.ACTION_POINTER_UP: {
                     handleInjectedPointerUp(event.getActionIndex(), event);
diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java
index cf5592c..4ec71c1 100644
--- a/services/java/com/android/server/am/ActivityManagerService.java
+++ b/services/java/com/android/server/am/ActivityManagerService.java
@@ -25,7 +25,6 @@
 import com.android.server.SystemServer;
 import com.android.server.Watchdog;
 import com.android.server.am.ActivityStack.ActivityState;
-import com.android.server.net.NetworkPolicyManagerService;
 import com.android.server.wm.WindowManagerService;
 
 import dalvik.system.Zygote;
@@ -93,7 +92,6 @@
 import android.os.FileUtils;
 import android.os.Handler;
 import android.os.IBinder;
-import android.os.IInterface;
 import android.os.IPermissionController;
 import android.os.Looper;
 import android.os.Message;
@@ -968,10 +966,12 @@
     static final int CHECK_EXCESSIVE_WAKE_LOCKS_MSG = 27;
     static final int CLEAR_DNS_CACHE = 28;
     static final int UPDATE_HTTP_PROXY = 29;
-    static final int DISPATCH_FOREGROUND_ACTIVITIES_CHANGED = 30;
-    static final int DISPATCH_PROCESS_DIED = 31;
+    static final int SHOW_COMPAT_MODE_DIALOG_MSG = 30;
+    static final int DISPATCH_FOREGROUND_ACTIVITIES_CHANGED = 31;
+    static final int DISPATCH_PROCESS_DIED = 32;
 
     AlertDialog mUidAlert;
+    CompatModeDialog mCompatModeDialog;
 
     final Handler mHandler = new Handler() {
         //public Handler() {
@@ -1270,16 +1270,45 @@
                     sendMessageDelayed(nmsg, POWER_CHECK_DELAY);
                 }
             } break;
+            case SHOW_COMPAT_MODE_DIALOG_MSG: {
+                synchronized (ActivityManagerService.this) {
+                    ActivityRecord ar = (ActivityRecord)msg.obj;
+                    if (mCompatModeDialog != null) {
+                        if (mCompatModeDialog.mAppInfo.packageName.equals(
+                                ar.info.applicationInfo.packageName)) {
+                            return;
+                        }
+                        mCompatModeDialog.dismiss();
+                        mCompatModeDialog = null;
+                    }
+                    if (ar != null && false) {
+                        if (mCompatModePackages.getPackageAskCompatModeLocked(
+                                ar.packageName)) {
+                            int mode = mCompatModePackages.computeCompatModeLocked(
+                                    ar.info.applicationInfo);
+                            if (mode == ActivityManager.COMPAT_MODE_DISABLED
+                                    || mode == ActivityManager.COMPAT_MODE_ENABLED) {
+                                mCompatModeDialog = new CompatModeDialog(
+                                        ActivityManagerService.this, mContext,
+                                        ar.info.applicationInfo);
+                                mCompatModeDialog.show();
+                            }
+                        }
+                    }
+                }
+                break;
+            }
             case DISPATCH_FOREGROUND_ACTIVITIES_CHANGED: {
-                final ProcessRecord app = (ProcessRecord) msg.obj;
-                final boolean foregroundActivities = msg.arg1 != 0;
-                dispatchForegroundActivitiesChanged(
-                        app.pid, app.info.uid, foregroundActivities);
+                final int pid = msg.arg1;
+                final int uid = msg.arg2;
+                final boolean foregroundActivities = (Boolean) msg.obj;
+                dispatchForegroundActivitiesChanged(pid, uid, foregroundActivities);
                 break;
             }
             case DISPATCH_PROCESS_DIED: {
-                final ProcessRecord app = (ProcessRecord) msg.obj;
-                dispatchProcessDied(app.pid, app.info.uid);
+                final int pid = msg.arg1;
+                final int uid = msg.arg2;
+                dispatchProcessDied(pid, uid);
                 break;
             }
             }
@@ -1904,6 +1933,9 @@
             int debugFlags = 0;
             if ((app.info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
                 debugFlags |= Zygote.DEBUG_ENABLE_DEBUGGER;
+                // Also turn on CheckJNI for debuggable apps. It's quite
+                // awkward to turn on otherwise.
+                debugFlags |= Zygote.DEBUG_ENABLE_CHECKJNI;
             }
             // Run the app in safe mode if its manifest requests so or the
             // system is booted in safe mode.
@@ -2112,6 +2144,18 @@
         }
     }
 
+    public boolean getPackageAskScreenCompat(String packageName) {
+        synchronized (this) {
+            return mCompatModePackages.getPackageAskCompatModeLocked(packageName);
+        }
+    }
+
+    public void setPackageAskScreenCompat(String packageName, boolean ask) {
+        synchronized (this) {
+            mCompatModePackages.setPackageAskCompatModeLocked(packageName, ask);
+        }
+    }
+
     void reportResumedActivityLocked(ActivityRecord r) {
         //Slog.i(TAG, "**** REPORT RESUME: " + r);
         
@@ -3634,6 +3678,7 @@
             boolean isRestrictedBackupMode = false;
             if (mBackupTarget != null && mBackupAppName.equals(processName)) {
                 isRestrictedBackupMode = (mBackupTarget.backupMode == BackupRecord.RESTORE)
+                        || (mBackupTarget.backupMode == BackupRecord.RESTORE_FULL)
                         || (mBackupTarget.backupMode == BackupRecord.BACKUP_FULL);
             }
             
@@ -3647,12 +3692,12 @@
                     + processName + " with config " + mConfiguration);
             ApplicationInfo appInfo = app.instrumentationInfo != null
                     ? app.instrumentationInfo : app.info;
+            app.compat = compatibilityInfoForPackageLocked(appInfo);
             thread.bindApplication(processName, appInfo, providers,
                     app.instrumentationClass, app.instrumentationProfileFile,
                     app.instrumentationArguments, app.instrumentationWatcher, testMode, 
                     isRestrictedBackupMode || !normalMode,
-                    mConfiguration, compatibilityInfoForPackageLocked(appInfo),
-                    getCommonServicesLocked(),
+                    mConfiguration, app.compat, getCommonServicesLocked(),
                     mCoreSettingsObserver.getCoreSettingsLocked());
             updateLruProcessLocked(app, false, true);
             app.lastRequestedGc = app.lastLowMemory = SystemClock.uptimeMillis();
@@ -7625,7 +7670,8 @@
                 pw.println("  COMP_SPEC may also be a component name (com.foo/.myApp),");
                 pw.println("    a partial substring in a component name, an");
                 pw.println("    ActivityRecord hex object identifier, or");
-                pw.println("    \"all\" for all objects");
+                pw.println("    \"all\" for all objects, or");
+                pw.println("    \"top\" for the top activity.");
                 pw.println("  -a: include all available server state.");
                 pw.println("  -c: include client state.");
                 return;
@@ -7948,8 +7994,14 @@
         if (dumpAll) {
             pw.println("  mConfigWillChange: " + mMainStack.mConfigWillChange);
             if (mCompatModePackages.getPackages().size() > 0) {
-                pw.print("  mScreenCompatPackages=");
-                pw.println(mCompatModePackages.getPackages());
+                pw.println("  mScreenCompatPackages:");
+                for (Map.Entry<String, Integer> entry
+                        : mCompatModePackages.getPackages().entrySet()) {
+                    String pkg = entry.getKey();
+                    int mode = entry.getValue();
+                    pw.print("    "); pw.print(pkg); pw.print(": ");
+                            pw.print(mode); pw.println();
+                }
             }
         }
         pw.println("  mSleeping=" + mSleeping + " mShuttingDown=" + mShuttingDown);
@@ -8173,6 +8225,13 @@
                     activities.add(r1);
                 }
             }
+        } else if ("top".equals(name)) {
+            synchronized (this) {
+                final int N = mMainStack.mHistory.size();
+                if (N > 0) {
+                    activities.add((ActivityRecord)mMainStack.mHistory.get(N-1));
+                }
+            }
         } else {
             ComponentName componentName = ComponentName.unflattenFromString(name);
             int objectId = 0;
@@ -9211,7 +9270,7 @@
             }
         }
 
-        mHandler.obtainMessage(DISPATCH_PROCESS_DIED, app).sendToTarget();
+        mHandler.obtainMessage(DISPATCH_PROCESS_DIED, app.pid, app.info.uid, null).sendToTarget();
 
         // If the caller is restarting this app, then leave it in its
         // current lists and let the caller take care of it.
@@ -11109,13 +11168,11 @@
         // Special case for adding a package: by default turn on compatibility
         // mode.
         } else if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())) {
-            if (!intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
-                Uri data = intent.getData();
-                String ssp;
-                if (data != null && (ssp=data.getSchemeSpecificPart()) != null) {
-                    mCompatModePackages.setPackageScreenCompatModeLocked(ssp,
-                            ActivityManager.COMPAT_MODE_ENABLED);
-                }
+            Uri data = intent.getData();
+            String ssp;
+            if (data != null && (ssp=data.getSchemeSpecificPart()) != null) {
+                mCompatModePackages.handlePackageAddedLocked(ssp,
+                        intent.getBooleanExtra(Intent.EXTRA_REPLACING, false));
             }
         }
 
@@ -12351,6 +12408,15 @@
                     ac.updateConfiguration(mConfiguration);
                 }
 
+                // Make sure all resources in our process are updated
+                // right now, so that anyone who is going to retrieve
+                // resource values after we return will be sure to get
+                // the new ones.  This is especially important during
+                // boot, where the first config change needs to guarantee
+                // all resources have that config before following boot
+                // code is executed.
+                mSystemThread.applyConfigurationToResources(newConfig);
+
                 if (Settings.System.hasInterestingConfigurationChanges(changes)) {
                     Message msg = mHandler.obtainMessage(UPDATE_CONFIGURATION_MSG);
                     msg.obj = new Configuration(mConfiguration);
@@ -12772,8 +12838,8 @@
         app.curSchedGroup = schedGroup;
 
         if (hadForegroundActivities != app.foregroundActivities) {
-            mHandler.obtainMessage(DISPATCH_FOREGROUND_ACTIVITIES_CHANGED,
-                    app.foregroundActivities ? 1 : 0, 0, app).sendToTarget();
+            mHandler.obtainMessage(DISPATCH_FOREGROUND_ACTIVITIES_CHANGED, app.pid, app.info.uid,
+                    app.foregroundActivities).sendToTarget();
         }
 
         return adj;
diff --git a/services/java/com/android/server/am/ActivityRecord.java b/services/java/com/android/server/am/ActivityRecord.java
index cc9e78e..090e26b 100644
--- a/services/java/com/android/server/am/ActivityRecord.java
+++ b/services/java/com/android/server/am/ActivityRecord.java
@@ -24,6 +24,7 @@
 import android.content.Intent;
 import android.content.pm.ActivityInfo;
 import android.content.pm.ApplicationInfo;
+import android.content.res.CompatibilityInfo;
 import android.content.res.Configuration;
 import android.graphics.Bitmap;
 import android.os.Build;
@@ -79,6 +80,7 @@
     long startTime;         // last time this activity was started
     long cpuTimeAtResume;   // the cpu time of host process at the time of resuming activity
     Configuration configuration; // configuration activity was last running in
+    CompatibilityInfo compat;// last used compatibility mode
     ActivityRecord resultTo; // who started this entry, so will get our reply
     final String resultWho; // additional identifier for use by resultTo.
     final int requestCode;  // code given by requester (resultTo)
@@ -137,6 +139,7 @@
                 pw.print(" componentSpecified="); pw.print(componentSpecified);
                 pw.print(" isHomeActivity="); pw.println(isHomeActivity);
         pw.print(prefix); pw.print("config="); pw.println(configuration);
+        pw.print(prefix); pw.print("compat="); pw.println(compat);
         if (resultTo != null || resultWho != null) {
             pw.print(prefix); pw.print("resultTo="); pw.print(resultTo);
                     pw.print(" resultWho="); pw.print(resultWho);
diff --git a/services/java/com/android/server/am/ActivityStack.java b/services/java/com/android/server/am/ActivityStack.java
index d5ac19e..d8772b8 100644
--- a/services/java/com/android/server/am/ActivityStack.java
+++ b/services/java/com/android/server/am/ActivityStack.java
@@ -485,6 +485,13 @@
         return null;
     }
 
+    final void showAskCompatModeDialogLocked(ActivityRecord r) {
+        Message msg = Message.obtain();
+        msg.what = ActivityManagerService.SHOW_COMPAT_MODE_DIALOG_MSG;
+        msg.obj = r.task.askedCompatMode ? null : r;
+        mService.mHandler.sendMessage(msg);
+    }
+
     final boolean realStartActivityLocked(ActivityRecord r,
             ProcessRecord app, boolean andResume, boolean checkConfig)
             throws RemoteException {
@@ -541,10 +548,11 @@
             mService.ensurePackageDexOpt(r.intent.getComponent().getPackageName());
             r.sleeping = false;
             r.forceNewConfig = false;
+            showAskCompatModeDialogLocked(r);
+            r.compat = mService.compatibilityInfoForPackageLocked(r.info.applicationInfo);
             app.thread.scheduleLaunchActivity(new Intent(r.intent), r,
                     System.identityHashCode(r),
-                    r.info, mService.compatibilityInfoForPackageLocked(r.info.applicationInfo),
-                    r.icicle, results, newIntents, !andResume,
+                    r.info, r.compat, r.icicle, results, newIntents, !andResume,
                     mService.isNextTransitionForward());
             
             if ((app.info.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
@@ -1430,6 +1438,7 @@
                         next.task.taskId, next.shortComponentName);
                 
                 next.sleeping = false;
+                showAskCompatModeDialogLocked(next);
                 next.app.thread.scheduleResumeActivity(next,
                         mService.isNextTransitionForward());
                 
@@ -1446,6 +1455,8 @@
                     if (SHOW_APP_STARTING_PREVIEW && mMainStack) {
                         mService.mWindowManager.setAppStartingWindow(
                                 next, next.packageName, next.theme,
+                                mService.compatibilityInfoForPackageLocked(
+                                        next.info.applicationInfo),
                                 next.nonLocalizedLabel,
                                 next.labelRes, next.icon, next.windowFlags,
                                 null, true);
@@ -1482,6 +1493,8 @@
                 if (SHOW_APP_STARTING_PREVIEW) {
                     mService.mWindowManager.setAppStartingWindow(
                             next, next.packageName, next.theme,
+                            mService.compatibilityInfoForPackageLocked(
+                                    next.info.applicationInfo),
                             next.nonLocalizedLabel,
                             next.labelRes, next.icon, next.windowFlags,
                             null, true);
@@ -1606,7 +1619,9 @@
                     else if (prev.nowVisible) prev = null;
                 }
                 mService.mWindowManager.setAppStartingWindow(
-                        r, r.packageName, r.theme, r.nonLocalizedLabel,
+                        r, r.packageName, r.theme,
+                        mService.compatibilityInfoForPackageLocked(
+                                r.info.applicationInfo), r.nonLocalizedLabel,
                         r.labelRes, r.icon, r.windowFlags, prev, showStartingIcon);
             }
         } else {
@@ -3892,10 +3907,10 @@
         if (DEBUG_SWITCH || DEBUG_CONFIGURATION) {
             Slog.v(TAG, "Checking to restart " + r.info.name + ": changed=0x"
                     + Integer.toHexString(changes) + ", handles=0x"
-                    + Integer.toHexString(r.info.configChanges)
+                    + Integer.toHexString(r.info.getRealConfigChanged())
                     + ", newConfig=" + newConfig);
         }
-        if ((changes&(~r.info.configChanges)) != 0 || r.forceNewConfig) {
+        if ((changes&(~r.info.getRealConfigChanged())) != 0 || r.forceNewConfig) {
             // Aha, the activity isn't handling the change, so DIE DIE DIE.
             r.configChangeFlags |= changes;
             r.startFreezingScreenLocked(r.app, globalChanges);
diff --git a/services/java/com/android/server/am/BackupRecord.java b/services/java/com/android/server/am/BackupRecord.java
index 6590b91..7e73106 100644
--- a/services/java/com/android/server/am/BackupRecord.java
+++ b/services/java/com/android/server/am/BackupRecord.java
@@ -26,6 +26,7 @@
     public static final int BACKUP_NORMAL = 0;
     public static final int BACKUP_FULL = 1;
     public static final int RESTORE = 2;
+    public static final int RESTORE_FULL = 3;
     
     final BatteryStatsImpl.Uid.Pkg.Serv stats;
     String stringName;                     // cached toString() output
diff --git a/services/java/com/android/server/am/CompatModeDialog.java b/services/java/com/android/server/am/CompatModeDialog.java
new file mode 100644
index 0000000..0442bda
--- /dev/null
+++ b/services/java/com/android/server/am/CompatModeDialog.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.am;
+
+import android.app.ActivityManager;
+import android.app.Dialog;
+import android.content.Context;
+import android.content.pm.ApplicationInfo;
+import android.view.Gravity;
+import android.view.View;
+import android.view.Window;
+import android.view.WindowManager;
+import android.widget.CheckBox;
+import android.widget.CompoundButton;
+import android.widget.Switch;
+
+public class CompatModeDialog extends Dialog {
+    final ActivityManagerService mService;
+    final ApplicationInfo mAppInfo;
+
+    final Switch mCompatEnabled;
+    final CheckBox mAlwaysShow;
+    final View mHint;
+
+    public CompatModeDialog(ActivityManagerService service, Context context,
+            ApplicationInfo appInfo) {
+        super(context, com.android.internal.R.style.Theme_Holo_Dialog_MinWidth);
+        setCancelable(true);
+        setCanceledOnTouchOutside(true);
+        getWindow().requestFeature(Window.FEATURE_NO_TITLE);
+        getWindow().setType(WindowManager.LayoutParams.TYPE_PHONE);
+        getWindow().setGravity(Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL);
+        mService = service;
+        mAppInfo = appInfo;
+
+        setContentView(com.android.internal.R.layout.am_compat_mode_dialog);
+        mCompatEnabled = (Switch)findViewById(com.android.internal.R.id.compat_checkbox);
+        mCompatEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+            @Override
+            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+                synchronized (mService) {
+                    mService.mCompatModePackages.setPackageScreenCompatModeLocked(
+                            mAppInfo.packageName,
+                            mCompatEnabled.isChecked() ? ActivityManager.COMPAT_MODE_ENABLED
+                                    : ActivityManager.COMPAT_MODE_DISABLED);
+                    updateControls();
+                }
+            }
+        });
+        mAlwaysShow = (CheckBox)findViewById(com.android.internal.R.id.ask_checkbox);
+        mAlwaysShow.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+            @Override
+            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+                synchronized (mService) {
+                    mService.mCompatModePackages.setPackageAskCompatModeLocked(
+                            mAppInfo.packageName, mAlwaysShow.isChecked());
+                    updateControls();
+                }
+            }
+        });
+        mHint = findViewById(com.android.internal.R.id.reask_hint);
+
+        updateControls();
+    }
+
+    void updateControls() {
+        synchronized (mService) {
+            int mode = mService.mCompatModePackages.computeCompatModeLocked(mAppInfo);
+            mCompatEnabled.setChecked(mode == ActivityManager.COMPAT_MODE_ENABLED);
+            boolean ask = mService.mCompatModePackages.getPackageAskCompatModeLocked(
+                    mAppInfo.packageName);
+            mAlwaysShow.setChecked(ask);
+            mHint.setVisibility(ask ? View.INVISIBLE : View.VISIBLE);
+        }
+    }
+}
diff --git a/services/java/com/android/server/am/CompatModePackages.java b/services/java/com/android/server/am/CompatModePackages.java
index 1faf8da..f656486 100644
--- a/services/java/com/android/server/am/CompatModePackages.java
+++ b/services/java/com/android/server/am/CompatModePackages.java
@@ -3,8 +3,10 @@
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.Map;
 
 import org.xmlpull.v1.XmlPullParser;
 import org.xmlpull.v1.XmlPullParserException;
@@ -15,6 +17,7 @@
 
 import android.app.ActivityManager;
 import android.app.AppGlobals;
+import android.content.pm.ActivityInfo;
 import android.content.pm.ApplicationInfo;
 import android.content.pm.IPackageManager;
 import android.content.res.CompatibilityInfo;
@@ -31,7 +34,12 @@
     private final ActivityManagerService mService;
     private final AtomicFile mFile;
 
-    private final HashSet<String> mPackages = new HashSet<String>();
+    // Compatibility state: no longer ask user to select the mode.
+    public static final int COMPAT_FLAG_DONT_ASK = 1<<0;
+    // Compatibility state: compatibility mode is enabled.
+    public static final int COMPAT_FLAG_ENABLED = 1<<1;
+
+    private final HashMap<String, Integer> mPackages = new HashMap<String, Integer>();
 
     private static final int MSG_WRITE = 1;
 
@@ -71,7 +79,15 @@
                             if ("pkg".equals(tagName)) {
                                 String pkg = parser.getAttributeValue(null, "name");
                                 if (pkg != null) {
-                                    mPackages.add(pkg);
+                                    String mode = parser.getAttributeValue(null, "mode");
+                                    int modeInt = 0;
+                                    if (mode != null) {
+                                        try {
+                                            modeInt = Integer.parseInt(mode);
+                                        } catch (NumberFormatException e) {
+                                        }
+                                    }
+                                    mPackages.put(pkg, modeInt);
                                 }
                             }
                         }
@@ -93,19 +109,53 @@
         }
     }
 
-    public HashSet<String> getPackages() {
+    public HashMap<String, Integer> getPackages() {
         return mPackages;
     }
 
-    public CompatibilityInfo compatibilityInfoForPackageLocked(ApplicationInfo ai) {
-        return new CompatibilityInfo(ai, mService.mConfiguration.screenLayout,
-                mPackages.contains(ai.packageName));
+    private int getPackageFlags(String packageName) {
+        Integer flags = mPackages.get(packageName);
+        return flags != null ? flags : 0;
     }
 
-    private int computeCompatModeLocked(ApplicationInfo ai) {
-        boolean enabled = mPackages.contains(ai.packageName);
+    public void handlePackageAddedLocked(String packageName, boolean updated) {
+        ApplicationInfo ai = null;
+        try {
+            ai = AppGlobals.getPackageManager().getApplicationInfo(packageName, 0);
+        } catch (RemoteException e) {
+        }
+        if (ai == null) {
+            return;
+        }
+        CompatibilityInfo ci = compatibilityInfoForPackageLocked(ai);
+        final boolean mayCompat = !ci.alwaysSupportsScreen()
+                && !ci.neverSupportsScreen();
+
+        if (updated) {
+            // Update -- if the app no longer can run in compat mode, clear
+            // any current settings for it.
+            if (!mayCompat && mPackages.containsKey(packageName)) {
+                mPackages.remove(packageName);
+                mHandler.removeMessages(MSG_WRITE);
+                Message msg = mHandler.obtainMessage(MSG_WRITE);
+                mHandler.sendMessageDelayed(msg, 10000);
+            }
+        }
+    }
+
+    public CompatibilityInfo compatibilityInfoForPackageLocked(ApplicationInfo ai) {
+        CompatibilityInfo ci = new CompatibilityInfo(ai, mService.mConfiguration.screenLayout,
+                mService.mConfiguration.smallestScreenWidthDp,
+                (getPackageFlags(ai.packageName)&COMPAT_FLAG_ENABLED) != 0);
+        //Slog.i(TAG, "*********** COMPAT FOR PKG " + ai.packageName + ": " + ci);
+        return ci;
+    }
+
+    public int computeCompatModeLocked(ApplicationInfo ai) {
+        boolean enabled = (getPackageFlags(ai.packageName)&COMPAT_FLAG_ENABLED) != 0;
         CompatibilityInfo info = new CompatibilityInfo(ai,
-                mService.mConfiguration.screenLayout, enabled);
+                mService.mConfiguration.screenLayout,
+                mService.mConfiguration.smallestScreenWidthDp, enabled);
         if (info.alwaysSupportsScreen()) {
             return ActivityManager.COMPAT_MODE_NEVER;
         }
@@ -116,6 +166,40 @@
                 : ActivityManager.COMPAT_MODE_DISABLED;
     }
 
+    public boolean getFrontActivityAskCompatModeLocked() {
+        ActivityRecord r = mService.mMainStack.topRunningActivityLocked(null);
+        if (r == null) {
+            return false;
+        }
+        return getPackageAskCompatModeLocked(r.packageName);
+    }
+
+    public boolean getPackageAskCompatModeLocked(String packageName) {
+        return (getPackageFlags(packageName)&COMPAT_FLAG_DONT_ASK) == 0;
+    }
+
+    public void setFrontActivityAskCompatModeLocked(boolean ask) {
+        ActivityRecord r = mService.mMainStack.topRunningActivityLocked(null);
+        if (r != null) {
+            setPackageAskCompatModeLocked(r.packageName, ask);
+        }
+    }
+
+    public void setPackageAskCompatModeLocked(String packageName, boolean ask) {
+        int curFlags = getPackageFlags(packageName);
+        int newFlags = ask ? (curFlags&~COMPAT_FLAG_DONT_ASK) : (curFlags|COMPAT_FLAG_DONT_ASK);
+        if (curFlags != newFlags) {
+            if (newFlags != 0) {
+                mPackages.put(packageName, newFlags);
+            } else {
+                mPackages.remove(packageName);
+            }
+            mHandler.removeMessages(MSG_WRITE);
+            Message msg = mHandler.obtainMessage(MSG_WRITE);
+            mHandler.sendMessageDelayed(msg, 10000);
+        }
+    }
+
     public int getFrontActivityScreenCompatModeLocked() {
         ActivityRecord r = mService.mMainStack.topRunningActivityLocked(null);
         if (r == null) {
@@ -161,7 +245,8 @@
     private void setPackageScreenCompatModeLocked(ApplicationInfo ai, int mode) {
         final String packageName = ai.packageName;
 
-        boolean changed = false;
+        int curFlags = getPackageFlags(packageName);
+
         boolean enable;
         switch (mode) {
             case ActivityManager.COMPAT_MODE_DISABLED:
@@ -171,40 +256,61 @@
                 enable = true;
                 break;
             case ActivityManager.COMPAT_MODE_TOGGLE:
-                enable = !mPackages.contains(packageName);
+                enable = (curFlags&COMPAT_FLAG_ENABLED) == 0;
                 break;
             default:
                 Slog.w(TAG, "Unknown screen compat mode req #" + mode + "; ignoring");
                 return;
         }
+
+        int newFlags = curFlags;
         if (enable) {
-            if (!mPackages.contains(packageName)) {
-                changed = true;
-                mPackages.add(packageName);
-            }
+            newFlags |= COMPAT_FLAG_ENABLED;
         } else {
-            if (mPackages.contains(packageName)) {
-                changed = true;
+            newFlags &= ~COMPAT_FLAG_ENABLED;
+        }
+
+        CompatibilityInfo ci = compatibilityInfoForPackageLocked(ai);
+        if (ci.alwaysSupportsScreen()) {
+            Slog.w(TAG, "Ignoring compat mode change of " + packageName
+                    + "; compatibility never needed");
+            newFlags = 0;
+        }
+        if (ci.neverSupportsScreen()) {
+            Slog.w(TAG, "Ignoring compat mode change of " + packageName
+                    + "; compatibility always needed");
+            newFlags = 0;
+        }
+
+        if (newFlags != curFlags) {
+            if (newFlags != 0) {
+                mPackages.put(packageName, newFlags);
+            } else {
                 mPackages.remove(packageName);
             }
-        }
-        if (changed) {
-            CompatibilityInfo ci = compatibilityInfoForPackageLocked(ai);
-            if (ci.alwaysSupportsScreen()) {
-                Slog.w(TAG, "Ignoring compat mode change of " + packageName
-                        + "; compatibility never needed");
-                return;
-            }
-            if (ci.neverSupportsScreen()) {
-                Slog.w(TAG, "Ignoring compat mode change of " + packageName
-                        + "; compatibility always needed");
-                return;
-            }
+
+            // Need to get compatibility info in new state.
+            ci = compatibilityInfoForPackageLocked(ai);
 
             mHandler.removeMessages(MSG_WRITE);
             Message msg = mHandler.obtainMessage(MSG_WRITE);
             mHandler.sendMessageDelayed(msg, 10000);
 
+            ActivityRecord starting = mService.mMainStack.topRunningActivityLocked(null);
+
+            // All activities that came from the package must be
+            // restarted as if there was a config change.
+            for (int i=mService.mMainStack.mHistory.size()-1; i>=0; i--) {
+                ActivityRecord a = (ActivityRecord)mService.mMainStack.mHistory.get(i);
+                if (a.info.packageName.equals(packageName)) {
+                    a.forceNewConfig = true;
+                    if (starting != null && a == starting && a.visible) {
+                        a.startFreezingScreenLocked(starting.app,
+                                ActivityInfo.CONFIG_SCREEN_LAYOUT);
+                    }
+                }
+            }
+
             // Tell all processes that loaded this package about the change.
             for (int i=mService.mLruProcesses.size()-1; i>=0; i--) {
                 ProcessRecord app = mService.mLruProcesses.get(i);
@@ -221,16 +327,6 @@
                 }
             }
 
-            // All activities that came from the packge must be
-            // restarted as if there was a config change.
-            for (int i=mService.mMainStack.mHistory.size()-1; i>=0; i--) {
-                ActivityRecord a = (ActivityRecord)mService.mMainStack.mHistory.get(i);
-                if (a.info.packageName.equals(packageName)) {
-                    a.forceNewConfig = true;
-                }
-            }
-
-            ActivityRecord starting = mService.mMainStack.topRunningActivityLocked(null);
             if (starting != null) {
                 mService.mMainStack.ensureActivityConfigurationLocked(starting, 0);
                 // And we need to make sure at this point that all other activities
@@ -241,9 +337,9 @@
     }
 
     void saveCompatModes() {
-        HashSet<String> pkgs;
+        HashMap<String, Integer> pkgs;
         synchronized (mService) {
-            pkgs = new HashSet<String>(mPackages);
+            pkgs = new HashMap<String, Integer>(mPackages);
         }
 
         FileOutputStream fos = null;
@@ -258,9 +354,15 @@
 
             final IPackageManager pm = AppGlobals.getPackageManager();
             final int screenLayout = mService.mConfiguration.screenLayout;
-            final Iterator<String> it = pkgs.iterator();
+            final int smallestScreenWidthDp = mService.mConfiguration.smallestScreenWidthDp;
+            final Iterator<Map.Entry<String, Integer>> it = pkgs.entrySet().iterator();
             while (it.hasNext()) {
-                String pkg = it.next();
+                Map.Entry<String, Integer> entry = it.next();
+                String pkg = entry.getKey();
+                int mode = entry.getValue();
+                if (mode == 0) {
+                    continue;
+                }
                 ApplicationInfo ai = null;
                 try {
                     ai = pm.getApplicationInfo(pkg, 0);
@@ -269,7 +371,8 @@
                 if (ai == null) {
                     continue;
                 }
-                CompatibilityInfo info = new CompatibilityInfo(ai, screenLayout, false);
+                CompatibilityInfo info = new CompatibilityInfo(ai, screenLayout,
+                        smallestScreenWidthDp, false);
                 if (info.alwaysSupportsScreen()) {
                     continue;
                 }
@@ -278,6 +381,7 @@
                 }
                 out.startTag(null, "pkg");
                 out.attribute(null, "name", pkg);
+                out.attribute(null, "mode", Integer.toString(mode));
                 out.endTag(null, "pkg");
             }
 
diff --git a/services/java/com/android/server/am/ProcessRecord.java b/services/java/com/android/server/am/ProcessRecord.java
index beef136..3968f66 100644
--- a/services/java/com/android/server/am/ProcessRecord.java
+++ b/services/java/com/android/server/am/ProcessRecord.java
@@ -71,6 +71,7 @@
     IBinder forcingToForeground;// Token that is forcing this process to be foreground
     int adjSeq;                 // Sequence id for identifying oom_adj assignment cycles
     int lruSeq;                 // Sequence id for identifying LRU update cycles
+    CompatibilityInfo compat;   // last used compatibility mode
     ComponentName instrumentationClass;// class installed to instrument app
     ApplicationInfo instrumentationInfo; // the application being instrumented
     String instrumentationProfileFile; // where to save profiling
@@ -147,6 +148,7 @@
                 pw.print(" publicDir="); pw.print(info.publicSourceDir);
                 pw.print(" data="); pw.println(info.dataDir);
         pw.print(prefix); pw.print("packageList="); pw.println(pkgList);
+        pw.print(prefix); pw.print("compat="); pw.println(compat);
         if (instrumentationClass != null || instrumentationProfileFile != null
                 || instrumentationArguments != null) {
             pw.print(prefix); pw.print("instrumentationClass=");
diff --git a/services/java/com/android/server/am/TaskRecord.java b/services/java/com/android/server/am/TaskRecord.java
index e8c87e1..e61a7f4 100644
--- a/services/java/com/android/server/am/TaskRecord.java
+++ b/services/java/com/android/server/am/TaskRecord.java
@@ -34,6 +34,7 @@
     long lastActiveTime;    // Last time this task was active, including sleep.
     boolean rootWasReset;   // True if the intent at the root of the task had
                             // the FLAG_ACTIVITY_RESET_TASK_IF_NEEDED flag.
+    boolean askedCompatMode;// Have asked the user about compat mode for this task.
 
     String stringName;      // caching of toString() result.
     
@@ -112,6 +113,9 @@
             pw.print(prefix); pw.print("realActivity=");
             pw.println(realActivity.flattenToShortString());
         }
+        if (!askedCompatMode) {
+            pw.print(prefix); pw.print("askedCompatMode="); pw.println(askedCompatMode);
+        }
         pw.print(prefix); pw.print("lastActiveTime="); pw.print(lastActiveTime);
                 pw.print(" (inactive for ");
                 pw.print((getInactiveDuration()/1000)); pw.println("s)");
diff --git a/services/java/com/android/server/connectivity/Tethering.java b/services/java/com/android/server/connectivity/Tethering.java
index e8155b4..5fa26ef 100644
--- a/services/java/com/android/server/connectivity/Tethering.java
+++ b/services/java/com/android/server/connectivity/Tethering.java
@@ -129,13 +129,6 @@
         mNMService = nmService;
         mLooper = looper;
 
-        // register for notifications from NetworkManagement Service
-        try {
-            mNMService.registerObserver(this);
-        } catch (RemoteException e) {
-            Log.e(TAG, "Error registering observer :" + e);
-        }
-
         mIfaces = new HashMap<String, TetherInterfaceSM>();
 
         // make our own thread so we don't anr the system
@@ -1212,8 +1205,8 @@
                     return null;
                 }
 
-                for (String iface : ifaces) {
-                    for (String regex : mUpstreamIfaceRegexs) {
+                for (String regex : mUpstreamIfaceRegexs) {
+                    for (String iface : ifaces) {
                         if (iface.matches(regex)) {
                             // verify it is active
                             InterfaceConfiguration ifcg = null;
diff --git a/services/java/com/android/server/connectivity/Vpn.java b/services/java/com/android/server/connectivity/Vpn.java
new file mode 100644
index 0000000..47813f8
--- /dev/null
+++ b/services/java/com/android/server/connectivity/Vpn.java
@@ -0,0 +1,248 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.connectivity;
+
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.content.res.Resources;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.drawable.Drawable;
+import android.net.INetworkManagementEventObserver;
+import android.os.Binder;
+import android.os.ParcelFileDescriptor;
+import android.os.RemoteException;
+import android.util.Log;
+
+import com.android.internal.R;
+import com.android.internal.net.VpnConfig;
+import com.android.server.ConnectivityService.VpnCallback;
+
+/**
+ * @hide
+ */
+public class Vpn extends INetworkManagementEventObserver.Stub {
+
+    private final static String TAG = "Vpn";
+    private final static String VPN = android.Manifest.permission.VPN;
+
+    private final Context mContext;
+    private final VpnCallback mCallback;
+
+    private String mPackageName;
+    private String mInterfaceName;
+    private String mDnsPropertyPrefix;
+
+    public Vpn(Context context, VpnCallback callback) {
+        mContext = context;
+        mCallback = callback;
+    }
+
+    /**
+     * Prepare for a VPN application.
+     *
+     * @param packageName The package name of the new VPN application.
+     * @return The name of the current prepared package.
+     */
+    public synchronized String prepare(String packageName) {
+        // Return the current prepared package if the new one is null.
+        if (packageName == null) {
+            return mPackageName;
+        }
+
+        // Check the permission of the caller.
+        PackageManager pm = mContext.getPackageManager();
+        VpnConfig.enforceCallingPackage(pm.getNameForUid(Binder.getCallingUid()));
+
+        // Check the permission of the given package.
+        if (packageName.isEmpty()) {
+            packageName = null;
+        } else if (pm.checkPermission(VPN, packageName) != PackageManager.PERMISSION_GRANTED) {
+            throw new SecurityException(packageName + " does not have " + VPN);
+        }
+
+        // Reset the interface and hide the notification.
+        if (mInterfaceName != null) {
+            nativeReset(mInterfaceName);
+            mCallback.restore();
+            hideNotification();
+            mInterfaceName = null;
+        }
+
+        // Notify the package being revoked.
+        if (mPackageName != null) {
+            Intent intent = new Intent(VpnConfig.ACTION_VPN_REVOKED);
+            intent.setPackage(mPackageName);
+            intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
+            mContext.sendBroadcast(intent);
+        }
+
+        Log.i(TAG, "Switched from " + mPackageName + " to " + packageName);
+        mPackageName = packageName;
+        return mPackageName;
+    }
+
+    /**
+     * Protect a socket from routing changes by binding it to the given
+     * interface. The socket IS closed by this method.
+     *
+     * @param socket The socket to be bound.
+     * @param name The name of the interface.
+     */
+    public void protect(ParcelFileDescriptor socket, String name) {
+        try {
+            mContext.enforceCallingPermission(VPN, "protect");
+            nativeProtect(socket.getFd(), name);
+        } finally {
+            try {
+                socket.close();
+            } catch (Exception e) {
+                // ignore
+            }
+        }
+    }
+
+    /**
+     * Configure a TUN interface and return its file descriptor.
+     *
+     * @param configuration The parameters to configure the interface.
+     * @return The file descriptor of the interface.
+     */
+    public synchronized ParcelFileDescriptor establish(VpnConfig config) {
+        // Check the permission of the caller.
+        mContext.enforceCallingPermission(VPN, "establish");
+
+        // Check if the caller is already prepared.
+        PackageManager pm = mContext.getPackageManager();
+        ApplicationInfo app = null;
+        try {
+            app = pm.getApplicationInfo(mPackageName, 0);
+        } catch (Exception e) {
+            return null;
+        }
+        if (Binder.getCallingUid() != app.uid) {
+            return null;
+        }
+
+        // Create and configure the interface.
+        ParcelFileDescriptor descriptor = ParcelFileDescriptor.adoptFd(
+                nativeEstablish(config.mtu, config.addresses, config.routes));
+
+        // Replace the interface and abort if it fails.
+        try {
+            String interfaceName = nativeGetName(descriptor.getFd());
+
+            if (mInterfaceName != null && !mInterfaceName.equals(interfaceName)) {
+                nativeReset(mInterfaceName);
+            }
+            mInterfaceName = interfaceName;
+        } catch (RuntimeException e) {
+            try {
+                descriptor.close();
+            } catch (Exception ex) {
+                // ignore
+            }
+            throw e;
+        }
+
+        String dnsServers = (config.dnsServers == null) ? "" : config.dnsServers.trim();
+        mCallback.override(dnsServers.isEmpty() ? null : dnsServers.split(" "));
+
+        config.packageName = mPackageName;
+        config.interfaceName = mInterfaceName;
+        showNotification(pm, app, config);
+        return descriptor;
+    }
+
+    // INetworkManagementEventObserver.Stub
+    public void interfaceLinkStatusChanged(String name, boolean up) {
+    }
+
+    // INetworkManagementEventObserver.Stub
+    public void interfaceAdded(String name) {
+    }
+
+    // INetworkManagementEventObserver.Stub
+    public synchronized void interfaceRemoved(String name) {
+        if (name.equals(mInterfaceName) && nativeCheck(name) == 0) {
+            hideNotification();
+            mInterfaceName = null;
+            mCallback.restore();
+        }
+    }
+
+    private void showNotification(PackageManager pm, ApplicationInfo app, VpnConfig config) {
+        NotificationManager nm = (NotificationManager)
+                mContext.getSystemService(Context.NOTIFICATION_SERVICE);
+
+        if (nm != null) {
+            // Load the icon and convert it into a bitmap.
+            Drawable icon = app.loadIcon(pm);
+            Bitmap bitmap = null;
+            if (icon.getIntrinsicWidth() > 0 && icon.getIntrinsicHeight() > 0) {
+                int width = mContext.getResources().getDimensionPixelSize(
+                        android.R.dimen.notification_large_icon_width);
+                int height = mContext.getResources().getDimensionPixelSize(
+                        android.R.dimen.notification_large_icon_height);
+                icon.setBounds(0, 0, width, height);
+                bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
+                icon.draw(new Canvas(bitmap));
+            }
+
+            // Load the label.
+            String label = app.loadLabel(pm).toString();
+
+            // Build the notification.
+            String text = (config.sessionName == null) ? mContext.getString(R.string.vpn_text) :
+                    mContext.getString(R.string.vpn_text_long, config.sessionName);
+            long identity = Binder.clearCallingIdentity();
+            Notification notification = new Notification.Builder(mContext)
+                    .setSmallIcon(R.drawable.vpn_connected)
+                    .setLargeIcon(bitmap)
+                    .setTicker(mContext.getString(R.string.vpn_ticker, label))
+                    .setContentTitle(mContext.getString(R.string.vpn_title, label))
+                    .setContentText(text)
+                    .setContentIntent(VpnConfig.getIntentForNotification(mContext, config))
+                    .setDefaults(Notification.DEFAULT_ALL)
+                    .setOngoing(true)
+                    .getNotification();
+            nm.notify(R.drawable.vpn_connected, notification);
+            Binder.restoreCallingIdentity(identity);
+        }
+    }
+
+    private void hideNotification() {
+        NotificationManager nm = (NotificationManager)
+                mContext.getSystemService(Context.NOTIFICATION_SERVICE);
+
+        if (nm != null) {
+            long identity = Binder.clearCallingIdentity();
+            nm.cancel(R.drawable.vpn_connected);
+            Binder.restoreCallingIdentity(identity);
+        }
+    }
+
+    private native int nativeEstablish(int mtu, String addresses, String routes);
+    private native String nativeGetName(int fd);
+    private native void nativeReset(String name);
+    private native int nativeCheck(String name);
+    private native void nativeProtect(int fd, String name);
+}
diff --git a/services/java/com/android/server/net/NetworkIdentitySet.java b/services/java/com/android/server/net/NetworkIdentitySet.java
new file mode 100644
index 0000000..af03fb3
--- /dev/null
+++ b/services/java/com/android/server/net/NetworkIdentitySet.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.net;
+
+import android.net.NetworkIdentity;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.net.ProtocolException;
+import java.util.HashSet;
+
+/**
+ * Identity of a {@code iface}, defined by the set of {@link NetworkIdentity}
+ * active on that interface.
+ *
+ * @hide
+ */
+public class NetworkIdentitySet extends HashSet<NetworkIdentity> {
+    private static final int VERSION_INIT = 1;
+    private static final int VERSION_ADD_ROAMING = 2;
+
+    public NetworkIdentitySet() {
+    }
+
+    public NetworkIdentitySet(DataInputStream in) throws IOException {
+        final int version = in.readInt();
+        switch (version) {
+            case VERSION_INIT: {
+                final int size = in.readInt();
+                for (int i = 0; i < size; i++) {
+                    final int ignoredVersion = in.readInt();
+                    final int type = in.readInt();
+                    final int subType = in.readInt();
+                    final String subscriberId = readOptionalString(in);
+                    add(new NetworkIdentity(type, subType, subscriberId, false));
+                }
+                break;
+            }
+            case VERSION_ADD_ROAMING: {
+                final int size = in.readInt();
+                for (int i = 0; i < size; i++) {
+                    final int type = in.readInt();
+                    final int subType = in.readInt();
+                    final String subscriberId = readOptionalString(in);
+                    final boolean roaming = in.readBoolean();
+                    add(new NetworkIdentity(type, subType, subscriberId, roaming));
+                }
+                break;
+            }
+            default: {
+                throw new ProtocolException("unexpected version: " + version);
+            }
+        }
+    }
+
+    public void writeToStream(DataOutputStream out) throws IOException {
+        out.writeInt(VERSION_ADD_ROAMING);
+        out.writeInt(size());
+        for (NetworkIdentity ident : this) {
+            out.writeInt(ident.getType());
+            out.writeInt(ident.getSubType());
+            writeOptionalString(out, ident.getSubscriberId());
+            out.writeBoolean(ident.getRoaming());
+        }
+    }
+
+    private static void writeOptionalString(DataOutputStream out, String value) throws IOException {
+        if (value != null) {
+            out.writeByte(1);
+            out.writeUTF(value);
+        } else {
+            out.writeByte(0);
+        }
+    }
+
+    private static String readOptionalString(DataInputStream in) throws IOException {
+        if (in.readByte() != 0) {
+            return in.readUTF();
+        } else {
+            return null;
+        }
+    }
+}
diff --git a/services/java/com/android/server/net/NetworkPolicyManagerService.java b/services/java/com/android/server/net/NetworkPolicyManagerService.java
index d083d01..584cd03 100644
--- a/services/java/com/android/server/net/NetworkPolicyManagerService.java
+++ b/services/java/com/android/server/net/NetworkPolicyManagerService.java
@@ -16,63 +16,219 @@
 
 package com.android.server.net;
 
+import static android.Manifest.permission.CONNECTIVITY_INTERNAL;
+import static android.Manifest.permission.DUMP;
 import static android.Manifest.permission.MANAGE_APP_TOKENS;
-import static android.Manifest.permission.UPDATE_DEVICE_STATS;
+import static android.Manifest.permission.MANAGE_NETWORK_POLICY;
+import static android.Manifest.permission.READ_NETWORK_USAGE_HISTORY;
+import static android.Manifest.permission.READ_PHONE_STATE;
+import static android.content.Intent.ACTION_UID_REMOVED;
+import static android.content.Intent.EXTRA_UID;
+import static android.net.ConnectivityManager.CONNECTIVITY_ACTION;
+import static android.net.ConnectivityManager.TYPE_MOBILE;
+import static android.net.NetworkPolicy.LIMIT_DISABLED;
+import static android.net.NetworkPolicy.WARNING_DISABLED;
+import static android.net.NetworkPolicyManager.ACTION_DATA_USAGE_LIMIT;
+import static android.net.NetworkPolicyManager.ACTION_DATA_USAGE_WARNING;
+import static android.net.NetworkPolicyManager.EXTRA_NETWORK_TEMPLATE;
 import static android.net.NetworkPolicyManager.POLICY_NONE;
-import static android.net.NetworkPolicyManager.POLICY_REJECT_BACKGROUND;
-import static android.net.NetworkPolicyManager.POLICY_REJECT_PAID;
+import static android.net.NetworkPolicyManager.POLICY_REJECT_METERED_BACKGROUND;
+import static android.net.NetworkPolicyManager.RULE_ALLOW_ALL;
+import static android.net.NetworkPolicyManager.RULE_REJECT_METERED;
+import static android.net.NetworkPolicyManager.computeLastCycleBoundary;
+import static android.net.NetworkPolicyManager.dumpPolicy;
+import static android.net.NetworkPolicyManager.dumpRules;
+import static android.net.NetworkPolicyManager.isUidValidForPolicy;
+import static android.net.NetworkTemplate.MATCH_MOBILE_3G_LOWER;
+import static android.net.NetworkTemplate.MATCH_MOBILE_4G;
+import static android.net.NetworkTemplate.MATCH_MOBILE_ALL;
+import static android.text.format.DateUtils.DAY_IN_MILLIS;
+import static com.android.internal.util.Preconditions.checkNotNull;
+import static com.android.server.net.NetworkStatsService.ACTION_NETWORK_STATS_UPDATED;
+import static org.xmlpull.v1.XmlPullParser.END_DOCUMENT;
+import static org.xmlpull.v1.XmlPullParser.START_TAG;
 
 import android.app.IActivityManager;
+import android.app.INotificationManager;
 import android.app.IProcessObserver;
+import android.app.Notification;
+import android.app.PendingIntent;
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
+import android.content.res.Resources;
+import android.net.ConnectivityManager;
+import android.net.IConnectivityManager;
+import android.net.INetworkPolicyListener;
 import android.net.INetworkPolicyManager;
+import android.net.INetworkStatsService;
+import android.net.NetworkIdentity;
+import android.net.NetworkPolicy;
+import android.net.NetworkState;
+import android.net.NetworkStats;
+import android.net.NetworkTemplate;
+import android.os.Environment;
+import android.os.Handler;
+import android.os.HandlerThread;
 import android.os.IPowerManager;
+import android.os.RemoteCallbackList;
 import android.os.RemoteException;
-import android.util.Log;
+import android.telephony.TelephonyManager;
+import android.text.format.Formatter;
+import android.text.format.Time;
+import android.util.NtpTrustedTime;
 import android.util.Slog;
 import android.util.SparseArray;
 import android.util.SparseBooleanArray;
 import android.util.SparseIntArray;
+import android.util.TrustedTime;
+import android.util.Xml;
+
+import com.android.internal.R;
+import com.android.internal.os.AtomicFile;
+import com.android.internal.util.FastXmlSerializer;
+import com.google.android.collect.Lists;
+import com.google.android.collect.Maps;
+import com.google.android.collect.Sets;
+
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+import org.xmlpull.v1.XmlSerializer;
+
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.ProtocolException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+
+import libcore.io.IoUtils;
 
 /**
  * Service that maintains low-level network policy rules and collects usage
  * statistics to drive those rules.
+ * <p>
+ * Derives active rules by combining a given policy with other system status,
+ * and delivers to listeners, such as {@link ConnectivityManager}, for
+ * enforcement.
  */
 public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
     private static final String TAG = "NetworkPolicy";
     private static final boolean LOGD = true;
+    private static final boolean LOGV = false;
 
-    private Context mContext;
-    private IActivityManager mActivityManager;
-    private IPowerManager mPowerManager;
+    private static final int VERSION_CURRENT = 1;
 
-    private Object mRulesLock = new Object();
+    private static final long KB_IN_BYTES = 1024;
+    private static final long MB_IN_BYTES = KB_IN_BYTES * 1024;
+    private static final long GB_IN_BYTES = MB_IN_BYTES * 1024;
 
-    private boolean mScreenOn = false;
+    private static final int TYPE_WARNING = 0x1;
+    private static final int TYPE_LIMIT = 0x2;
 
-    /** Current network policy for each UID. */
+    private static final String TAG_POLICY_LIST = "policy-list";
+    private static final String TAG_NETWORK_POLICY = "network-policy";
+    private static final String TAG_UID_POLICY = "uid-policy";
+
+    private static final String ATTR_VERSION = "version";
+    private static final String ATTR_NETWORK_TEMPLATE = "networkTemplate";
+    private static final String ATTR_SUBSCRIBER_ID = "subscriberId";
+    private static final String ATTR_CYCLE_DAY = "cycleDay";
+    private static final String ATTR_WARNING_BYTES = "warningBytes";
+    private static final String ATTR_LIMIT_BYTES = "limitBytes";
+    private static final String ATTR_UID = "uid";
+    private static final String ATTR_POLICY = "policy";
+
+    private static final long TIME_CACHE_MAX_AGE = DAY_IN_MILLIS;
+
+    private final Context mContext;
+    private final IActivityManager mActivityManager;
+    private final IPowerManager mPowerManager;
+    private final INetworkStatsService mNetworkStats;
+    private final TrustedTime mTime;
+
+    private IConnectivityManager mConnManager;
+    private INotificationManager mNotifManager;
+
+    private final Object mRulesLock = new Object();
+
+    private boolean mScreenOn;
+
+    /** Current policy for network templates. */
+    private ArrayList<NetworkPolicy> mNetworkPolicy = Lists.newArrayList();
+
+    /** Current policy for each UID. */
     private SparseIntArray mUidPolicy = new SparseIntArray();
+    /** Current derived network rules for each UID. */
+    private SparseIntArray mUidRules = new SparseIntArray();
+
+    /** Set of ifaces that are metered. */
+    private HashSet<String> mMeteredIfaces = Sets.newHashSet();
 
     /** Foreground at both UID and PID granularity. */
     private SparseBooleanArray mUidForeground = new SparseBooleanArray();
     private SparseArray<SparseBooleanArray> mUidPidForeground = new SparseArray<
             SparseBooleanArray>();
 
-    // TODO: periodically poll network stats and write to disk
-    // TODO: save/restore policy information from disk
+    private final RemoteCallbackList<INetworkPolicyListener> mListeners = new RemoteCallbackList<
+            INetworkPolicyListener>();
 
-    public NetworkPolicyManagerService(
-            Context context, IActivityManager activityManager, IPowerManager powerManager) {
+    private final HandlerThread mHandlerThread;
+    private final Handler mHandler;
+
+    private final AtomicFile mPolicyFile;
+
+    // TODO: keep whitelist of system-critical services that should never have
+    // rules enforced, such as system, phone, and radio UIDs.
+
+    public NetworkPolicyManagerService(Context context, IActivityManager activityManager,
+            IPowerManager powerManager, INetworkStatsService networkStats) {
+        // TODO: move to using cached NtpTrustedTime
+        this(context, activityManager, powerManager, networkStats, new NtpTrustedTime(),
+                getSystemDir());
+    }
+
+    private static File getSystemDir() {
+        return new File(Environment.getDataDirectory(), "system");
+    }
+
+    public NetworkPolicyManagerService(Context context, IActivityManager activityManager,
+            IPowerManager powerManager, INetworkStatsService networkStats, TrustedTime time,
+            File systemDir) {
         mContext = checkNotNull(context, "missing context");
         mActivityManager = checkNotNull(activityManager, "missing activityManager");
         mPowerManager = checkNotNull(powerManager, "missing powerManager");
+        mNetworkStats = checkNotNull(networkStats, "missing networkStats");
+        mTime = checkNotNull(time, "missing TrustedTime");
+
+        mHandlerThread = new HandlerThread(TAG);
+        mHandlerThread.start();
+        mHandler = new Handler(mHandlerThread.getLooper());
+
+        mPolicyFile = new AtomicFile(new File(systemDir, "netpolicy.xml"));
+    }
+
+    public void bindConnectivityManager(IConnectivityManager connManager) {
+        mConnManager = checkNotNull(connManager, "missing IConnectivityManager");
+    }
+
+    public void bindNotificationManager(INotificationManager notifManager) {
+        mNotifManager = checkNotNull(notifManager, "missing INotificationManager");
     }
 
     public void systemReady() {
-        // TODO: read current policy+stats from disk and generate NMS rules
+        synchronized (mRulesLock) {
+            // read policy from disk
+            readPolicyLocked();
+            updateNotificationsLocked();
+        }
 
         updateScreenOn();
 
@@ -92,9 +248,18 @@
         screenFilter.addAction(Intent.ACTION_SCREEN_OFF);
         mContext.registerReceiver(mScreenReceiver, screenFilter);
 
-        final IntentFilter shutdownFilter = new IntentFilter();
-        shutdownFilter.addAction(Intent.ACTION_SHUTDOWN);
-        mContext.registerReceiver(mShutdownReceiver, shutdownFilter);
+        // watch for network interfaces to be claimed
+        final IntentFilter connFilter = new IntentFilter(CONNECTIVITY_ACTION);
+        mContext.registerReceiver(mConnReceiver, connFilter, CONNECTIVITY_INTERNAL, mHandler);
+
+        // listen for uid removal to clean policy
+        final IntentFilter removedFilter = new IntentFilter(ACTION_UID_REMOVED);
+        mContext.registerReceiver(mRemovedReceiver, removedFilter, null, mHandler);
+
+        // listen for warning polling events; currently dispatched by
+        final IntentFilter statsFilter = new IntentFilter(ACTION_NETWORK_STATS_UPDATED);
+        mContext.registerReceiver(
+                mStatsReceiver, statsFilter, READ_NETWORK_USAGE_HISTORY, mHandler);
 
     }
 
@@ -102,8 +267,10 @@
         @Override
         public void onForegroundActivitiesChanged(int pid, int uid, boolean foregroundActivities) {
             // only someone like AMS should only be calling us
-            mContext.enforceCallingOrSelfPermission(
-                    MANAGE_APP_TOKENS, "requires MANAGE_APP_TOKENS permission");
+            mContext.enforceCallingOrSelfPermission(MANAGE_APP_TOKENS, TAG);
+
+            // skip when UID couldn't have any policy
+            if (!isUidValidForPolicy(mContext, uid)) return;
 
             synchronized (mRulesLock) {
                 // because a uid can have multiple pids running inside, we need to
@@ -116,22 +283,24 @@
                     mUidPidForeground.put(uid, pidForeground);
                 }
                 pidForeground.put(pid, foregroundActivities);
-                computeUidForegroundL(uid);
+                computeUidForegroundLocked(uid);
             }
         }
 
         @Override
         public void onProcessDied(int pid, int uid) {
             // only someone like AMS should only be calling us
-            mContext.enforceCallingOrSelfPermission(
-                    MANAGE_APP_TOKENS, "requires MANAGE_APP_TOKENS permission");
+            mContext.enforceCallingOrSelfPermission(MANAGE_APP_TOKENS, TAG);
+
+            // skip when UID couldn't have any policy
+            if (!isUidValidForPolicy(mContext, uid)) return;
 
             synchronized (mRulesLock) {
                 // clear records and recompute, when they exist
                 final SparseBooleanArray pidForeground = mUidPidForeground.get(uid);
                 if (pidForeground != null) {
                     pidForeground.delete(pid);
-                    computeUidForegroundL(uid);
+                    computeUidForegroundLocked(uid);
                 }
             }
         }
@@ -148,36 +317,622 @@
         }
     };
 
-    private BroadcastReceiver mShutdownReceiver = new BroadcastReceiver() {
+    private BroadcastReceiver mRemovedReceiver = new BroadcastReceiver() {
         @Override
         public void onReceive(Context context, Intent intent) {
-            // TODO: persist any pending stats during clean shutdown
-            Log.d(TAG, "persisting stats");
+            // on background handler thread, and UID_REMOVED is protected
+            // broadcast.
+            final int uid = intent.getIntExtra(EXTRA_UID, 0);
+            synchronized (mRulesLock) {
+                // remove any policy and update rules to clean up
+                mUidPolicy.delete(uid);
+                updateRulesForUidLocked(uid);
+                writePolicyLocked();
+            }
         }
     };
 
+    /**
+     * Receiver that watches for {@link INetworkStatsService} updates, which we
+     * use to check against {@link NetworkPolicy#warningBytes}.
+     */
+    private BroadcastReceiver mStatsReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            // on background handler thread, and verified
+            // READ_NETWORK_USAGE_HISTORY permission above.
+
+            synchronized (mRulesLock) {
+                updateNotificationsLocked();
+            }
+        }
+    };
+
+    /**
+     * Check {@link NetworkPolicy} against current {@link INetworkStatsService}
+     * to show visible notifications as needed.
+     */
+    private void updateNotificationsLocked() {
+        if (LOGV) Slog.v(TAG, "updateNotificationsLocked()");
+
+        // try refreshing time source when stale
+        if (mTime.getCacheAge() > TIME_CACHE_MAX_AGE) {
+            mTime.forceRefresh();
+        }
+
+        final long currentTime = mTime.hasCache() ? mTime.currentTimeMillis()
+                : System.currentTimeMillis();
+
+        // TODO: when switching to kernel notifications, compute next future
+        // cycle boundary to recompute notifications.
+
+        // examine stats for each policy defined
+        for (NetworkPolicy policy : mNetworkPolicy) {
+            final long start = computeLastCycleBoundary(currentTime, policy);
+            final long end = currentTime;
+
+            final long total;
+            try {
+                final NetworkStats stats = mNetworkStats.getSummaryForNetwork(
+                        policy.template, start, end);
+                total = stats.rx[0] + stats.tx[0];
+            } catch (RemoteException e) {
+                Slog.w(TAG, "problem reading summary for template " + policy.template);
+                continue;
+            }
+
+            if (policy.limitBytes != LIMIT_DISABLED && total >= policy.limitBytes) {
+                cancelNotification(policy, TYPE_WARNING);
+                enqueueNotification(policy, TYPE_LIMIT);
+            } else {
+                cancelNotification(policy, TYPE_LIMIT);
+
+                if (policy.warningBytes != WARNING_DISABLED && total >= policy.warningBytes) {
+                    enqueueNotification(policy, TYPE_WARNING);
+                } else {
+                    cancelNotification(policy, TYPE_WARNING);
+                }
+            }
+        }
+    }
+
+    /**
+     * Build unique tag that identifies an active {@link NetworkPolicy}
+     * notification of a specific type, like {@link #TYPE_LIMIT}.
+     */
+    private String buildNotificationTag(NetworkPolicy policy, int type) {
+        return TAG + ":" + policy.template.hashCode() + ":" + type;
+    }
+
+    /**
+     * Show notification for combined {@link NetworkPolicy} and specific type,
+     * like {@link #TYPE_LIMIT}. Okay to call multiple times.
+     */
+    private void enqueueNotification(NetworkPolicy policy, int type) {
+        final String tag = buildNotificationTag(policy, type);
+        final Notification.Builder builder = new Notification.Builder(mContext);
+        builder.setOnlyAlertOnce(true);
+        builder.setOngoing(true);
+
+        final Resources res = mContext.getResources();
+        switch (type) {
+            case TYPE_WARNING: {
+                final String title = res.getString(R.string.data_usage_warning_title);
+                final String body = res.getString(R.string.data_usage_warning_body,
+                        Formatter.formatFileSize(mContext, policy.warningBytes));
+
+                builder.setSmallIcon(R.drawable.ic_menu_info_details);
+                builder.setTicker(title);
+                builder.setContentTitle(title);
+                builder.setContentText(body);
+
+                final Intent intent = new Intent(ACTION_DATA_USAGE_WARNING);
+                intent.addCategory(Intent.CATEGORY_DEFAULT);
+                intent.putExtra(EXTRA_NETWORK_TEMPLATE, policy.template.getMatchRule());
+                builder.setContentIntent(PendingIntent.getActivity(
+                        mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT));
+                break;
+            }
+            case TYPE_LIMIT: {
+                final String title;
+                final String body = res.getString(R.string.data_usage_limit_body);
+                switch (policy.template.getMatchRule()) {
+                    case MATCH_MOBILE_3G_LOWER:
+                        title = res.getString(R.string.data_usage_3g_limit_title);
+                        break;
+                    case MATCH_MOBILE_4G:
+                        title = res.getString(R.string.data_usage_4g_limit_title);
+                        break;
+                    default:
+                        title = res.getString(R.string.data_usage_mobile_limit_title);
+                        break;
+                }
+
+                builder.setSmallIcon(com.android.internal.R.drawable.ic_menu_block);
+                builder.setTicker(title);
+                builder.setContentTitle(title);
+                builder.setContentText(body);
+
+                final Intent intent = new Intent(ACTION_DATA_USAGE_LIMIT);
+                intent.addCategory(Intent.CATEGORY_DEFAULT);
+                intent.putExtra(EXTRA_NETWORK_TEMPLATE, policy.template.getMatchRule());
+                builder.setContentIntent(PendingIntent.getActivity(
+                        mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT));
+                break;
+            }
+        }
+
+        // TODO: move to NotificationManager once we can mock it
+        try {
+            final String packageName = mContext.getPackageName();
+            final int[] idReceived = new int[1];
+            mNotifManager.enqueueNotificationWithTag(
+                    packageName, tag, 0x0, builder.getNotification(), idReceived);
+        } catch (RemoteException e) {
+            Slog.w(TAG, "problem during enqueueNotification: " + e);
+        }
+    }
+
+    /**
+     * Cancel any notification for combined {@link NetworkPolicy} and specific
+     * type, like {@link #TYPE_LIMIT}.
+     */
+    private void cancelNotification(NetworkPolicy policy, int type) {
+        final String tag = buildNotificationTag(policy, type);
+
+        // TODO: move to NotificationManager once we can mock it
+        try {
+            final String packageName = mContext.getPackageName();
+            mNotifManager.cancelNotificationWithTag(packageName, tag, 0x0);
+        } catch (RemoteException e) {
+            Slog.w(TAG, "problem during enqueueNotification: " + e);
+        }
+    }
+
+    /**
+     * Receiver that watches for {@link IConnectivityManager} to claim network
+     * interfaces. Used to apply {@link NetworkPolicy} to matching networks.
+     */
+    private BroadcastReceiver mConnReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            // on background handler thread, and verified CONNECTIVITY_INTERNAL
+            // permission above.
+            synchronized (mRulesLock) {
+                ensureActiveMobilePolicyLocked();
+                updateIfacesLocked();
+            }
+        }
+    };
+
+    /**
+     * Examine all connected {@link NetworkState}, looking for
+     * {@link NetworkPolicy} that need to be enforced. When matches found, set
+     * remaining quota based on usage cycle and historical stats.
+     */
+    private void updateIfacesLocked() {
+        if (LOGV) Slog.v(TAG, "updateIfacesLocked()");
+
+        final NetworkState[] states;
+        try {
+            states = mConnManager.getAllNetworkState();
+        } catch (RemoteException e) {
+            Slog.w(TAG, "problem reading network state");
+            return;
+        }
+
+        // first, derive identity for all connected networks, which can be used
+        // to match against templates.
+        final HashMap<NetworkIdentity, String> networks = Maps.newHashMap();
+        for (NetworkState state : states) {
+            // stash identity and iface away for later use
+            if (state.networkInfo.isConnected()) {
+                final String iface = state.linkProperties.getInterfaceName();
+                final NetworkIdentity ident = NetworkIdentity.buildNetworkIdentity(mContext, state);
+                networks.put(ident, iface);
+            }
+        }
+
+        // build list of rules and ifaces to enforce them against
+        final HashMap<NetworkPolicy, String[]> rules = Maps.newHashMap();
+        final ArrayList<String> ifaceList = Lists.newArrayList();
+        for (NetworkPolicy policy : mNetworkPolicy) {
+
+            // collect all active ifaces that match this template
+            ifaceList.clear();
+            for (NetworkIdentity ident : networks.keySet()) {
+                if (policy.template.matches(ident)) {
+                    final String iface = networks.get(ident);
+                    ifaceList.add(iface);
+                }
+            }
+
+            if (ifaceList.size() > 0) {
+                final String[] ifaces = ifaceList.toArray(new String[ifaceList.size()]);
+                rules.put(policy, ifaces);
+            }
+        }
+
+        // try refreshing time source when stale
+        if (mTime.getCacheAge() > TIME_CACHE_MAX_AGE) {
+            mTime.forceRefresh();
+        }
+
+        final long currentTime = mTime.hasCache() ? mTime.currentTimeMillis()
+                : System.currentTimeMillis();
+
+        mMeteredIfaces.clear();
+
+        // apply each policy that we found ifaces for; compute remaining data
+        // based on current cycle and historical stats, and push to kernel.
+        for (NetworkPolicy policy : rules.keySet()) {
+            final String[] ifaces = rules.get(policy);
+
+            final long start = computeLastCycleBoundary(currentTime, policy);
+            final long end = currentTime;
+
+            final NetworkStats stats;
+            final long total;
+            try {
+                stats = mNetworkStats.getSummaryForNetwork(policy.template, start, end);
+                total = stats.rx[0] + stats.tx[0];
+            } catch (RemoteException e) {
+                Slog.w(TAG, "problem reading summary for template " + policy.template);
+                continue;
+            }
+
+            if (LOGD) {
+                Slog.d(TAG, "applying policy " + policy.toString() + " to ifaces "
+                        + Arrays.toString(ifaces));
+            }
+
+            // TODO: register for warning notification trigger through NMS
+
+            if (policy.limitBytes != NetworkPolicy.LIMIT_DISABLED) {
+                // remaining "quota" is based on usage in current cycle
+                final long quota = Math.max(0, policy.limitBytes - total);
+                //kernelSetIfacesQuota(ifaces, quota);
+
+                for (String iface : ifaces) {
+                    mMeteredIfaces.add(iface);
+                }
+            }
+        }
+
+        // dispatch changed rule to existing listeners
+        // TODO: dispatch outside of holding lock
+        final String[] meteredIfaces = mMeteredIfaces.toArray(new String[mMeteredIfaces.size()]);
+        final int length = mListeners.beginBroadcast();
+        for (int i = 0; i < length; i++) {
+            final INetworkPolicyListener listener = mListeners.getBroadcastItem(i);
+            if (listener != null) {
+                try {
+                    listener.onMeteredIfacesChanged(meteredIfaces);
+                } catch (RemoteException e) {
+                }
+            }
+        }
+        mListeners.finishBroadcast();
+    }
+
+    /**
+     * Once any {@link #mNetworkPolicy} are loaded from disk, ensure that we
+     * have at least a default mobile policy defined.
+     */
+    private void ensureActiveMobilePolicyLocked() {
+        if (LOGV) Slog.v(TAG, "ensureActiveMobilePolicyLocked()");
+        final String subscriberId = getActiveSubscriberId();
+        final NetworkIdentity probeIdent = new NetworkIdentity(
+                TYPE_MOBILE, TelephonyManager.NETWORK_TYPE_UNKNOWN, subscriberId, false);
+
+        // examine to see if any policy is defined for active mobile
+        boolean mobileDefined = false;
+        for (NetworkPolicy policy : mNetworkPolicy) {
+            if (policy.template.matches(probeIdent)) {
+                mobileDefined = true;
+            }
+        }
+
+        if (!mobileDefined) {
+            Slog.i(TAG, "no policy for active mobile network; generating default policy");
+
+            // default mobile policy has combined 4GB warning, and assume usage
+            // cycle starts today today.
+
+            // TODO: move this policy definition to overlay or secure setting
+            final Time time = new Time(Time.TIMEZONE_UTC);
+            time.setToNow();
+            final int cycleDay = time.monthDay;
+
+            final NetworkTemplate template = new NetworkTemplate(MATCH_MOBILE_ALL, subscriberId);
+            mNetworkPolicy.add(
+                    new NetworkPolicy(template, cycleDay, 4 * GB_IN_BYTES, LIMIT_DISABLED));
+            writePolicyLocked();
+        }
+    }
+
+    private void readPolicyLocked() {
+        if (LOGV) Slog.v(TAG, "readPolicyLocked()");
+
+        // clear any existing policy and read from disk
+        mNetworkPolicy.clear();
+        mUidPolicy.clear();
+
+        FileInputStream fis = null;
+        try {
+            fis = mPolicyFile.openRead();
+            final XmlPullParser in = Xml.newPullParser();
+            in.setInput(fis, null);
+
+            int type;
+            int version = VERSION_CURRENT;
+            while ((type = in.next()) != END_DOCUMENT) {
+                final String tag = in.getName();
+                if (type == START_TAG) {
+                    if (TAG_POLICY_LIST.equals(tag)) {
+                        version = readIntAttribute(in, ATTR_VERSION);
+
+                    } else if (TAG_NETWORK_POLICY.equals(tag)) {
+                        final int networkTemplate = readIntAttribute(in, ATTR_NETWORK_TEMPLATE);
+                        final String subscriberId = in.getAttributeValue(null, ATTR_SUBSCRIBER_ID);
+                        final int cycleDay = readIntAttribute(in, ATTR_CYCLE_DAY);
+                        final long warningBytes = readLongAttribute(in, ATTR_WARNING_BYTES);
+                        final long limitBytes = readLongAttribute(in, ATTR_LIMIT_BYTES);
+
+                        final NetworkTemplate template = new NetworkTemplate(
+                                networkTemplate, subscriberId);
+                        mNetworkPolicy.add(
+                                new NetworkPolicy(template, cycleDay, warningBytes, limitBytes));
+
+                    } else if (TAG_UID_POLICY.equals(tag)) {
+                        final int uid = readIntAttribute(in, ATTR_UID);
+                        final int policy = readIntAttribute(in, ATTR_POLICY);
+
+                        if (isUidValidForPolicy(mContext, uid)) {
+                            setUidPolicyUnchecked(uid, policy, false);
+                        } else {
+                            Slog.w(TAG, "unable to apply policy to UID " + uid + "; ignoring");
+                        }
+                    }
+                }
+            }
+
+        } catch (FileNotFoundException e) {
+            // missing policy is okay, probably first boot
+        } catch (IOException e) {
+            Slog.e(TAG, "problem reading network stats", e);
+        } catch (XmlPullParserException e) {
+            Slog.e(TAG, "problem reading network stats", e);
+        } finally {
+            IoUtils.closeQuietly(fis);
+        }
+    }
+
+    private void writePolicyLocked() {
+        if (LOGV) Slog.v(TAG, "writePolicyLocked()");
+
+        FileOutputStream fos = null;
+        try {
+            fos = mPolicyFile.startWrite();
+
+            XmlSerializer out = new FastXmlSerializer();
+            out.setOutput(fos, "utf-8");
+            out.startDocument(null, true);
+
+            out.startTag(null, TAG_POLICY_LIST);
+            writeIntAttribute(out, ATTR_VERSION, VERSION_CURRENT);
+
+            // write all known network policies
+            for (NetworkPolicy policy : mNetworkPolicy) {
+                final NetworkTemplate template = policy.template;
+
+                out.startTag(null, TAG_NETWORK_POLICY);
+                writeIntAttribute(out, ATTR_NETWORK_TEMPLATE, template.getMatchRule());
+                final String subscriberId = template.getSubscriberId();
+                if (subscriberId != null) {
+                    out.attribute(null, ATTR_SUBSCRIBER_ID, subscriberId);
+                }
+                writeIntAttribute(out, ATTR_CYCLE_DAY, policy.cycleDay);
+                writeLongAttribute(out, ATTR_WARNING_BYTES, policy.warningBytes);
+                writeLongAttribute(out, ATTR_LIMIT_BYTES, policy.limitBytes);
+                out.endTag(null, TAG_NETWORK_POLICY);
+            }
+
+            // write all known uid policies
+            for (int i = 0; i < mUidPolicy.size(); i++) {
+                final int uid = mUidPolicy.keyAt(i);
+                final int policy = mUidPolicy.valueAt(i);
+
+                // skip writing empty policies
+                if (policy == POLICY_NONE) continue;
+
+                out.startTag(null, TAG_UID_POLICY);
+                writeIntAttribute(out, ATTR_UID, uid);
+                writeIntAttribute(out, ATTR_POLICY, policy);
+                out.endTag(null, TAG_UID_POLICY);
+            }
+
+            out.endTag(null, TAG_POLICY_LIST);
+            out.endDocument();
+
+            mPolicyFile.finishWrite(fos);
+        } catch (IOException e) {
+            if (fos != null) {
+                mPolicyFile.failWrite(fos);
+            }
+        }
+    }
+
     @Override
     public void setUidPolicy(int uid, int policy) {
-        mContext.enforceCallingOrSelfPermission(
-                UPDATE_DEVICE_STATS, "requires UPDATE_DEVICE_STATS permission");
+        mContext.enforceCallingOrSelfPermission(MANAGE_NETWORK_POLICY, TAG);
 
+        if (!isUidValidForPolicy(mContext, uid)) {
+            throw new IllegalArgumentException("cannot apply policy to UID " + uid);
+        }
+
+        setUidPolicyUnchecked(uid, policy, true);
+    }
+
+    private void setUidPolicyUnchecked(int uid, int policy, boolean persist) {
+        final int oldPolicy;
         synchronized (mRulesLock) {
+            oldPolicy = getUidPolicy(uid);
             mUidPolicy.put(uid, policy);
+
+            // uid policy changed, recompute rules and persist policy.
+            updateRulesForUidLocked(uid);
+            if (persist) {
+                writePolicyLocked();
+            }
         }
     }
 
     @Override
     public int getUidPolicy(int uid) {
+        mContext.enforceCallingOrSelfPermission(MANAGE_NETWORK_POLICY, TAG);
+
         synchronized (mRulesLock) {
             return mUidPolicy.get(uid, POLICY_NONE);
         }
     }
 
+    @Override
+    public void registerListener(INetworkPolicyListener listener) {
+        // TODO: create permission for observing network policy
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+
+        mListeners.register(listener);
+
+        synchronized (mRulesLock) {
+            // dispatch any existing rules to new listeners
+            // TODO: dispatch outside of holding lock
+            final int size = mUidRules.size();
+            for (int i = 0; i < size; i++) {
+                final int uid = mUidRules.keyAt(i);
+                final int uidRules = mUidRules.valueAt(i);
+                if (uidRules != RULE_ALLOW_ALL) {
+                    try {
+                        listener.onUidRulesChanged(uid, uidRules);
+                    } catch (RemoteException e) {
+                    }
+                }
+            }
+
+            // dispatch any metered ifaces to new listeners
+            // TODO: dispatch outside of holding lock
+            if (mMeteredIfaces.size() > 0) {
+                final String[] meteredIfaces = mMeteredIfaces.toArray(
+                        new String[mMeteredIfaces.size()]);
+                try {
+                    listener.onMeteredIfacesChanged(meteredIfaces);
+                } catch (RemoteException e) {
+                }
+            }
+        }
+    }
+
+    @Override
+    public void unregisterListener(INetworkPolicyListener listener) {
+        // TODO: create permission for observing network policy
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+
+        mListeners.unregister(listener);
+    }
+
+    @Override
+    public void setNetworkPolicies(NetworkPolicy[] policies) {
+        mContext.enforceCallingOrSelfPermission(MANAGE_NETWORK_POLICY, TAG);
+
+        synchronized (mRulesLock) {
+            mNetworkPolicy.clear();
+            for (NetworkPolicy policy : policies) {
+                mNetworkPolicy.add(policy);
+            }
+
+            updateIfacesLocked();
+            updateNotificationsLocked();
+            writePolicyLocked();
+        }
+    }
+
+    @Override
+    public NetworkPolicy[] getNetworkPolicies() {
+        mContext.enforceCallingOrSelfPermission(MANAGE_NETWORK_POLICY, TAG);
+        mContext.enforceCallingOrSelfPermission(READ_PHONE_STATE, TAG);
+
+        synchronized (mRulesLock) {
+            return mNetworkPolicy.toArray(new NetworkPolicy[mNetworkPolicy.size()]);
+        }
+    }
+
+    @Override
+    protected void dump(FileDescriptor fd, PrintWriter fout, String[] args) {
+        mContext.enforceCallingOrSelfPermission(DUMP, TAG);
+
+        synchronized (mRulesLock) {
+            fout.println("Network policies:");
+            for (NetworkPolicy policy : mNetworkPolicy) {
+                fout.print("  "); fout.println(policy.toString());
+            }
+
+            fout.println("Policy status for known UIDs:");
+
+            final SparseBooleanArray knownUids = new SparseBooleanArray();
+            collectKeys(mUidPolicy, knownUids);
+            collectKeys(mUidForeground, knownUids);
+            collectKeys(mUidRules, knownUids);
+
+            final int size = knownUids.size();
+            for (int i = 0; i < size; i++) {
+                final int uid = knownUids.keyAt(i);
+                fout.print("  UID=");
+                fout.print(uid);
+
+                fout.print(" policy=");
+                final int policyIndex = mUidPolicy.indexOfKey(uid);
+                if (policyIndex < 0) {
+                    fout.print("UNKNOWN");
+                } else {
+                    dumpPolicy(fout, mUidPolicy.valueAt(policyIndex));
+                }
+
+                fout.print(" foreground=");
+                final int foregroundIndex = mUidPidForeground.indexOfKey(uid);
+                if (foregroundIndex < 0) {
+                    fout.print("UNKNOWN");
+                } else {
+                    dumpSparseBooleanArray(fout, mUidPidForeground.valueAt(foregroundIndex));
+                }
+
+                fout.print(" rules=");
+                final int rulesIndex = mUidRules.indexOfKey(uid);
+                if (rulesIndex < 0) {
+                    fout.print("UNKNOWN");
+                } else {
+                    dumpRules(fout, mUidRules.valueAt(rulesIndex));
+                }
+
+                fout.println();
+            }
+        }
+    }
+
+    @Override
+    public boolean isUidForeground(int uid) {
+        mContext.enforceCallingOrSelfPermission(MANAGE_NETWORK_POLICY, TAG);
+
+        synchronized (mRulesLock) {
+            // only really in foreground when screen is also on
+            return mUidForeground.get(uid, false) && mScreenOn;
+        }
+    }
+
     /**
      * Foreground for PID changed; recompute foreground at UID level. If
-     * changed, will trigger {@link #updateRulesForUidL(int)}.
+     * changed, will trigger {@link #updateRulesForUidLocked(int)}.
      */
-    private void computeUidForegroundL(int uid) {
+    private void computeUidForegroundLocked(int uid) {
         final SparseBooleanArray pidForeground = mUidPidForeground.get(uid);
 
         // current pid is dropping foreground; examine other pids
@@ -194,7 +949,7 @@
         if (oldUidForeground != uidForeground) {
             // foreground changed, push updated rules
             mUidForeground.put(uid, uidForeground);
-            updateRulesForUidL(uid);
+            updateRulesForUidLocked(uid);
         }
     }
 
@@ -204,47 +959,116 @@
                 mScreenOn = mPowerManager.isScreenOn();
             } catch (RemoteException e) {
             }
-            updateRulesForScreenL();
+            updateRulesForScreenLocked();
         }
     }
 
     /**
      * Update rules that might be changed by {@link #mScreenOn} value.
      */
-    private void updateRulesForScreenL() {
+    private void updateRulesForScreenLocked() {
         // only update rules for anyone with foreground activities
         final int size = mUidForeground.size();
         for (int i = 0; i < size; i++) {
             if (mUidForeground.valueAt(i)) {
                 final int uid = mUidForeground.keyAt(i);
-                updateRulesForUidL(uid);
+                updateRulesForUidLocked(uid);
             }
         }
     }
 
-    private void updateRulesForUidL(int uid) {
-        // only really in foreground when screen on
-        final boolean uidForeground = mUidForeground.get(uid, false) && mScreenOn;
+    private void updateRulesForUidLocked(int uid) {
+        if (!isUidValidForPolicy(mContext, uid)) return;
+
         final int uidPolicy = getUidPolicy(uid);
+        final boolean uidForeground = isUidForeground(uid);
 
-        if (LOGD) {
-            Log.d(TAG, "updateRulesForUid(uid=" + uid + ") found foreground=" + uidForeground
-                    + " and policy=" + uidPolicy);
+        // derive active rules based on policy and active state
+        int uidRules = RULE_ALLOW_ALL;
+        if (!uidForeground && (uidPolicy & POLICY_REJECT_METERED_BACKGROUND) != 0) {
+            // uid in background, and policy says to block metered data
+            uidRules = RULE_REJECT_METERED;
         }
 
-        if (!uidForeground && (uidPolicy & POLICY_REJECT_BACKGROUND) != 0) {
-            // TODO: build updated rules and push to NMS
-        } else if ((uidPolicy & POLICY_REJECT_PAID) != 0) {
-            // TODO: build updated rules and push to NMS
-        } else {
-            // TODO: build updated rules and push to NMS
+        // TODO: only dispatch when rules actually change
+
+        // record rule locally to dispatch to new listeners
+        mUidRules.put(uid, uidRules);
+
+        final boolean rejectMetered = (uidRules & RULE_REJECT_METERED) != 0;
+        //kernelSetUidRejectPaid(uid, rejectPaid);
+
+        // dispatch changed rule to existing listeners
+        // TODO: dispatch outside of holding lock
+        final int length = mListeners.beginBroadcast();
+        for (int i = 0; i < length; i++) {
+            final INetworkPolicyListener listener = mListeners.getBroadcastItem(i);
+            if (listener != null) {
+                try {
+                    listener.onUidRulesChanged(uid, uidRules);
+                } catch (RemoteException e) {
+                }
+            }
+        }
+        mListeners.finishBroadcast();
+    }
+
+    private String getActiveSubscriberId() {
+        final TelephonyManager telephony = (TelephonyManager) mContext.getSystemService(
+                Context.TELEPHONY_SERVICE);
+        return telephony.getSubscriberId();
+    }
+
+    private static void collectKeys(SparseIntArray source, SparseBooleanArray target) {
+        final int size = source.size();
+        for (int i = 0; i < size; i++) {
+            target.put(source.keyAt(i), true);
         }
     }
 
-    private static <T> T checkNotNull(T value, String message) {
-        if (value == null) {
-            throw new NullPointerException(message);
+    private static void collectKeys(SparseBooleanArray source, SparseBooleanArray target) {
+        final int size = source.size();
+        for (int i = 0; i < size; i++) {
+            target.put(source.keyAt(i), true);
         }
-        return value;
     }
+
+    private static void dumpSparseBooleanArray(PrintWriter fout, SparseBooleanArray value) {
+        fout.print("[");
+        final int size = value.size();
+        for (int i = 0; i < size; i++) {
+            fout.print(value.keyAt(i) + "=" + value.valueAt(i));
+            if (i < size - 1) fout.print(",");
+        }
+        fout.print("]");
+    }
+
+    private static int readIntAttribute(XmlPullParser in, String name) throws IOException {
+        final String value = in.getAttributeValue(null, name);
+        try {
+            return Integer.parseInt(value);
+        } catch (NumberFormatException e) {
+            throw new ProtocolException("problem parsing " + name + "=" + value + " as int");
+        }
+    }
+
+    private static long readLongAttribute(XmlPullParser in, String name) throws IOException {
+        final String value = in.getAttributeValue(null, name);
+        try {
+            return Long.parseLong(value);
+        } catch (NumberFormatException e) {
+            throw new ProtocolException("problem parsing " + name + "=" + value + " as int");
+        }
+    }
+
+    private static void writeIntAttribute(XmlSerializer out, String name, int value)
+            throws IOException {
+        out.attribute(null, name, Integer.toString(value));
+    }
+
+    private static void writeLongAttribute(XmlSerializer out, String name, long value)
+            throws IOException {
+        out.attribute(null, name, Long.toString(value));
+    }
+
 }
diff --git a/services/java/com/android/server/net/NetworkStatsService.java b/services/java/com/android/server/net/NetworkStatsService.java
new file mode 100644
index 0000000..043a581
--- /dev/null
+++ b/services/java/com/android/server/net/NetworkStatsService.java
@@ -0,0 +1,1069 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.net;
+
+import static android.Manifest.permission.CONNECTIVITY_INTERNAL;
+import static android.Manifest.permission.DUMP;
+import static android.Manifest.permission.READ_NETWORK_USAGE_HISTORY;
+import static android.content.Intent.ACTION_SHUTDOWN;
+import static android.content.Intent.ACTION_UID_REMOVED;
+import static android.content.Intent.EXTRA_UID;
+import static android.net.ConnectivityManager.CONNECTIVITY_ACTION;
+import static android.net.NetworkStats.IFACE_ALL;
+import static android.net.NetworkStats.TAG_NONE;
+import static android.net.NetworkStats.UID_ALL;
+import static android.net.TrafficStats.UID_REMOVED;
+import static android.provider.Settings.Secure.NETSTATS_NETWORK_BUCKET_DURATION;
+import static android.provider.Settings.Secure.NETSTATS_NETWORK_MAX_HISTORY;
+import static android.provider.Settings.Secure.NETSTATS_PERSIST_THRESHOLD;
+import static android.provider.Settings.Secure.NETSTATS_POLL_INTERVAL;
+import static android.provider.Settings.Secure.NETSTATS_TAG_MAX_HISTORY;
+import static android.provider.Settings.Secure.NETSTATS_UID_BUCKET_DURATION;
+import static android.provider.Settings.Secure.NETSTATS_UID_MAX_HISTORY;
+import static android.text.format.DateUtils.DAY_IN_MILLIS;
+import static android.text.format.DateUtils.HOUR_IN_MILLIS;
+import static android.text.format.DateUtils.MINUTE_IN_MILLIS;
+import static com.android.internal.util.Preconditions.checkNotNull;
+
+import android.app.AlarmManager;
+import android.app.IAlarmManager;
+import android.app.PendingIntent;
+import android.content.BroadcastReceiver;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.ApplicationInfo;
+import android.net.IConnectivityManager;
+import android.net.INetworkStatsService;
+import android.net.NetworkIdentity;
+import android.net.NetworkInfo;
+import android.net.NetworkState;
+import android.net.NetworkStats;
+import android.net.NetworkStatsHistory;
+import android.net.NetworkTemplate;
+import android.os.Environment;
+import android.os.Handler;
+import android.os.HandlerThread;
+import android.os.INetworkManagementService;
+import android.os.RemoteException;
+import android.os.SystemClock;
+import android.provider.Settings;
+import android.telephony.TelephonyManager;
+import android.util.LongSparseArray;
+import android.util.NtpTrustedTime;
+import android.util.Slog;
+import android.util.TrustedTime;
+
+import com.android.internal.os.AtomicFile;
+import com.google.android.collect.Maps;
+import com.google.android.collect.Sets;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.ProtocolException;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+
+import libcore.io.IoUtils;
+
+/**
+ * Collect and persist detailed network statistics, and provide this data to
+ * other system services.
+ */
+public class NetworkStatsService extends INetworkStatsService.Stub {
+    private static final String TAG = "NetworkStats";
+    private static final boolean LOGD = true;
+    private static final boolean LOGV = false;
+
+    /** File header magic number: "ANET" */
+    private static final int FILE_MAGIC = 0x414E4554;
+    private static final int VERSION_NETWORK_INIT = 1;
+    private static final int VERSION_UID_INIT = 1;
+    private static final int VERSION_UID_WITH_IDENT = 2;
+    private static final int VERSION_UID_WITH_TAG = 3;
+
+    private final Context mContext;
+    private final INetworkManagementService mNetworkManager;
+    private final IAlarmManager mAlarmManager;
+    private final TrustedTime mTime;
+    private final NetworkStatsSettings mSettings;
+
+    private IConnectivityManager mConnManager;
+
+    // @VisibleForTesting
+    public static final String ACTION_NETWORK_STATS_POLL =
+            "com.android.server.action.NETWORK_STATS_POLL";
+    public static final String ACTION_NETWORK_STATS_UPDATED =
+            "com.android.server.action.NETWORK_STATS_UPDATED";
+
+    private PendingIntent mPollIntent;
+
+    // TODO: listen for kernel push events through netd instead of polling
+    // TODO: watch for UID uninstall, and transfer stats into single bucket
+
+    // TODO: trim empty history objects entirely
+
+    private static final long KB_IN_BYTES = 1024;
+    private static final long MB_IN_BYTES = 1024 * KB_IN_BYTES;
+    private static final long GB_IN_BYTES = 1024 * MB_IN_BYTES;
+
+    /**
+     * Settings that can be changed externally.
+     */
+    public interface NetworkStatsSettings {
+        public long getPollInterval();
+        public long getPersistThreshold();
+        public long getNetworkBucketDuration();
+        public long getNetworkMaxHistory();
+        public long getUidBucketDuration();
+        public long getUidMaxHistory();
+        public long getTagMaxHistory();
+        public long getTimeCacheMaxAge();
+    }
+
+    private final Object mStatsLock = new Object();
+
+    /** Set of currently active ifaces. */
+    private HashMap<String, NetworkIdentitySet> mActiveIfaces = Maps.newHashMap();
+    /** Set of historical stats for known networks. */
+    private HashMap<NetworkIdentitySet, NetworkStatsHistory> mNetworkStats = Maps.newHashMap();
+    /** Set of historical stats for known UIDs. */
+    private HashMap<NetworkIdentitySet, LongSparseArray<NetworkStatsHistory>> mUidStats =
+            Maps.newHashMap();
+
+    /** Flag if {@link #mUidStats} have been loaded from disk. */
+    private boolean mUidStatsLoaded = false;
+
+    private NetworkStats mLastNetworkSnapshot;
+    private NetworkStats mLastPersistNetworkSnapshot;
+
+    private NetworkStats mLastUidSnapshot;
+
+    private final HandlerThread mHandlerThread;
+    private final Handler mHandler;
+
+    private final AtomicFile mNetworkFile;
+    private final AtomicFile mUidFile;
+
+    // TODO: collect detailed uid stats, storing tag-granularity data until next
+    // dropbox, and uid summary for a specific bucket count.
+
+    // TODO: periodically compile statistics and send to dropbox.
+
+    public NetworkStatsService(
+            Context context, INetworkManagementService networkManager, IAlarmManager alarmManager) {
+        // TODO: move to using cached NtpTrustedTime
+        this(context, networkManager, alarmManager, new NtpTrustedTime(), getSystemDir(),
+                new DefaultNetworkStatsSettings(context));
+    }
+
+    private static File getSystemDir() {
+        return new File(Environment.getDataDirectory(), "system");
+    }
+
+    public NetworkStatsService(Context context, INetworkManagementService networkManager,
+            IAlarmManager alarmManager, TrustedTime time, File systemDir,
+            NetworkStatsSettings settings) {
+        mContext = checkNotNull(context, "missing Context");
+        mNetworkManager = checkNotNull(networkManager, "missing INetworkManagementService");
+        mAlarmManager = checkNotNull(alarmManager, "missing IAlarmManager");
+        mTime = checkNotNull(time, "missing TrustedTime");
+        mSettings = checkNotNull(settings, "missing NetworkStatsSettings");
+
+        mHandlerThread = new HandlerThread(TAG);
+        mHandlerThread.start();
+        mHandler = new Handler(mHandlerThread.getLooper());
+
+        mNetworkFile = new AtomicFile(new File(systemDir, "netstats.bin"));
+        mUidFile = new AtomicFile(new File(systemDir, "netstats_uid.bin"));
+    }
+
+    public void bindConnectivityManager(IConnectivityManager connManager) {
+        mConnManager = checkNotNull(connManager, "missing IConnectivityManager");
+    }
+
+    public void systemReady() {
+        synchronized (mStatsLock) {
+            // read historical network stats from disk, since policy service
+            // might need them right away. we delay loading detailed UID stats
+            // until actually needed.
+            readNetworkStatsLocked();
+        }
+
+        // watch for network interfaces to be claimed
+        final IntentFilter connFilter = new IntentFilter(CONNECTIVITY_ACTION);
+        mContext.registerReceiver(mConnReceiver, connFilter, CONNECTIVITY_INTERNAL, mHandler);
+
+        // listen for periodic polling events
+        final IntentFilter pollFilter = new IntentFilter(ACTION_NETWORK_STATS_POLL);
+        mContext.registerReceiver(mPollReceiver, pollFilter, READ_NETWORK_USAGE_HISTORY, mHandler);
+
+        // listen for uid removal to clean stats
+        final IntentFilter removedFilter = new IntentFilter(ACTION_UID_REMOVED);
+        mContext.registerReceiver(mRemovedReceiver, removedFilter, null, mHandler);
+
+        // persist stats during clean shutdown
+        final IntentFilter shutdownFilter = new IntentFilter(ACTION_SHUTDOWN);
+        mContext.registerReceiver(mShutdownReceiver, shutdownFilter);
+
+        try {
+            registerPollAlarmLocked();
+        } catch (RemoteException e) {
+            Slog.w(TAG, "unable to register poll alarm");
+        }
+    }
+
+    private void shutdownLocked() {
+        mContext.unregisterReceiver(mConnReceiver);
+        mContext.unregisterReceiver(mPollReceiver);
+        mContext.unregisterReceiver(mRemovedReceiver);
+        mContext.unregisterReceiver(mShutdownReceiver);
+
+        writeNetworkStatsLocked();
+        if (mUidStatsLoaded) {
+            writeUidStatsLocked();
+        }
+        mNetworkStats.clear();
+        mUidStats.clear();
+        mUidStatsLoaded = false;
+    }
+
+    /**
+     * Clear any existing {@link #ACTION_NETWORK_STATS_POLL} alarms, and
+     * reschedule based on current {@link NetworkStatsSettings#getPollInterval()}.
+     */
+    private void registerPollAlarmLocked() throws RemoteException {
+        if (mPollIntent != null) {
+            mAlarmManager.remove(mPollIntent);
+        }
+
+        mPollIntent = PendingIntent.getBroadcast(
+                mContext, 0, new Intent(ACTION_NETWORK_STATS_POLL), 0);
+
+        final long currentRealtime = SystemClock.elapsedRealtime();
+        mAlarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, currentRealtime,
+                mSettings.getPollInterval(), mPollIntent);
+    }
+
+    @Override
+    public NetworkStatsHistory getHistoryForNetwork(NetworkTemplate template) {
+        mContext.enforceCallingOrSelfPermission(READ_NETWORK_USAGE_HISTORY, TAG);
+
+        synchronized (mStatsLock) {
+            // combine all interfaces that match template
+            final NetworkStatsHistory combined = new NetworkStatsHistory(
+                    mSettings.getNetworkBucketDuration(), estimateNetworkBuckets());
+            for (NetworkIdentitySet ident : mNetworkStats.keySet()) {
+                if (templateMatches(template, ident)) {
+                    final NetworkStatsHistory history = mNetworkStats.get(ident);
+                    if (history != null) {
+                        combined.recordEntireHistory(history);
+                    }
+                }
+            }
+            return combined;
+        }
+    }
+
+    @Override
+    public NetworkStatsHistory getHistoryForUid(NetworkTemplate template, int uid, int tag) {
+        mContext.enforceCallingOrSelfPermission(READ_NETWORK_USAGE_HISTORY, TAG);
+
+        synchronized (mStatsLock) {
+            ensureUidStatsLoadedLocked();
+            final long packed = packUidAndTag(uid, tag);
+
+            // combine all interfaces that match template
+            final NetworkStatsHistory combined = new NetworkStatsHistory(
+                    mSettings.getUidBucketDuration(), estimateUidBuckets());
+            for (NetworkIdentitySet ident : mUidStats.keySet()) {
+                if (templateMatches(template, ident)) {
+                    final NetworkStatsHistory history = mUidStats.get(ident).get(packed);
+                    if (history != null) {
+                        combined.recordEntireHistory(history);
+                    }
+                }
+            }
+            return combined;
+        }
+    }
+
+    @Override
+    public NetworkStats getSummaryForNetwork(NetworkTemplate template, long start, long end) {
+        mContext.enforceCallingOrSelfPermission(READ_NETWORK_USAGE_HISTORY, TAG);
+
+        synchronized (mStatsLock) {
+            long rx = 0;
+            long tx = 0;
+            long[] networkTotal = new long[2];
+
+            // combine total from all interfaces that match template
+            for (NetworkIdentitySet ident : mNetworkStats.keySet()) {
+                if (templateMatches(template, ident)) {
+                    final NetworkStatsHistory history = mNetworkStats.get(ident);
+                    networkTotal = history.getTotalData(start, end, networkTotal);
+                    rx += networkTotal[0];
+                    tx += networkTotal[1];
+                }
+            }
+
+            final NetworkStats stats = new NetworkStats(end - start, 1);
+            stats.addEntry(IFACE_ALL, UID_ALL, TAG_NONE, rx, tx);
+            return stats;
+        }
+    }
+
+    @Override
+    public NetworkStats getSummaryForAllUid(
+            NetworkTemplate template, long start, long end, boolean includeTags) {
+        mContext.enforceCallingOrSelfPermission(READ_NETWORK_USAGE_HISTORY, TAG);
+
+        synchronized (mStatsLock) {
+            ensureUidStatsLoadedLocked();
+
+            final NetworkStats stats = new NetworkStats(end - start, 24);
+            long[] total = new long[2];
+
+            for (NetworkIdentitySet ident : mUidStats.keySet()) {
+                if (templateMatches(template, ident)) {
+                    final LongSparseArray<NetworkStatsHistory> uidStats = mUidStats.get(ident);
+                    for (int i = 0; i < uidStats.size(); i++) {
+                        final long packed = uidStats.keyAt(i);
+                        final int uid = unpackUid(packed);
+                        final int tag = unpackTag(packed);
+
+                        // always include summary under TAG_NONE, and include
+                        // other tags when requested.
+                        if (tag == TAG_NONE || includeTags) {
+                            final NetworkStatsHistory history = uidStats.valueAt(i);
+                            total = history.getTotalData(start, end, total);
+                            final long rx = total[0];
+                            final long tx = total[1];
+                            if (rx > 0 || tx > 0) {
+                                stats.combineEntry(IFACE_ALL, uid, tag, rx, tx);
+                            }
+                        }
+                    }
+                }
+            }
+
+            return stats;
+        }
+    }
+
+    /**
+     * Receiver that watches for {@link IConnectivityManager} to claim network
+     * interfaces. Used to associate {@link TelephonyManager#getSubscriberId()}
+     * with mobile interfaces.
+     */
+    private BroadcastReceiver mConnReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            // on background handler thread, and verified CONNECTIVITY_INTERNAL
+            // permission above.
+            synchronized (mStatsLock) {
+                updateIfacesLocked();
+            }
+        }
+    };
+
+    private BroadcastReceiver mPollReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            // on background handler thread, and verified UPDATE_DEVICE_STATS
+            // permission above.
+            synchronized (mStatsLock) {
+                // TODO: acquire wakelock while performing poll
+                performPollLocked(true, false);
+            }
+        }
+    };
+
+    private BroadcastReceiver mRemovedReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            // on background handler thread, and UID_REMOVED is protected
+            // broadcast.
+            final int uid = intent.getIntExtra(EXTRA_UID, 0);
+            synchronized (mStatsLock) {
+                removeUidLocked(uid);
+            }
+        }
+    };
+
+    private BroadcastReceiver mShutdownReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            // SHUTDOWN is protected broadcast.
+            synchronized (mStatsLock) {
+                shutdownLocked();
+            }
+        }
+    };
+
+    /**
+     * Inspect all current {@link NetworkState} to derive mapping from {@code
+     * iface} to {@link NetworkStatsHistory}. When multiple {@link NetworkInfo}
+     * are active on a single {@code iface}, they are combined under a single
+     * {@link NetworkIdentitySet}.
+     */
+    private void updateIfacesLocked() {
+        if (LOGV) Slog.v(TAG, "updateIfacesLocked()");
+
+        // take one last stats snapshot before updating iface mapping. this
+        // isn't perfect, since the kernel may already be counting traffic from
+        // the updated network.
+        performPollLocked(false, false);
+
+        final NetworkState[] states;
+        try {
+            states = mConnManager.getAllNetworkState();
+        } catch (RemoteException e) {
+            Slog.w(TAG, "problem reading network state");
+            return;
+        }
+
+        // rebuild active interfaces based on connected networks
+        mActiveIfaces.clear();
+
+        for (NetworkState state : states) {
+            if (state.networkInfo.isConnected()) {
+                // collect networks under their parent interfaces
+                final String iface = state.linkProperties.getInterfaceName();
+
+                NetworkIdentitySet ident = mActiveIfaces.get(iface);
+                if (ident == null) {
+                    ident = new NetworkIdentitySet();
+                    mActiveIfaces.put(iface, ident);
+                }
+
+                ident.add(NetworkIdentity.buildNetworkIdentity(mContext, state));
+            }
+        }
+    }
+
+    /**
+     * Periodic poll operation, reading current statistics and recording into
+     * {@link NetworkStatsHistory}.
+     *
+     * @param detailedPoll Indicate if detailed UID stats should be collected
+     *            during this poll operation.
+     */
+    private void performPollLocked(boolean detailedPoll, boolean forcePersist) {
+        if (LOGV) Slog.v(TAG, "performPollLocked()");
+
+        // try refreshing time source when stale
+        if (mTime.getCacheAge() > mSettings.getTimeCacheMaxAge()) {
+            mTime.forceRefresh();
+        }
+
+        // TODO: consider marking "untrusted" times in historical stats
+        final long currentTime = mTime.hasCache() ? mTime.currentTimeMillis()
+                : System.currentTimeMillis();
+
+        final NetworkStats networkSnapshot;
+        final NetworkStats uidSnapshot;
+        try {
+            networkSnapshot = mNetworkManager.getNetworkStatsSummary();
+            uidSnapshot = detailedPoll ? mNetworkManager.getNetworkStatsDetail() : null;
+        } catch (RemoteException e) {
+            Slog.w(TAG, "problem reading network stats");
+            return;
+        }
+
+        performNetworkPollLocked(networkSnapshot, currentTime);
+        if (detailedPoll) {
+            performUidPollLocked(uidSnapshot, currentTime);
+        }
+
+        // decide if enough has changed to trigger persist
+        final NetworkStats persistDelta = computeStatsDelta(
+                mLastPersistNetworkSnapshot, networkSnapshot);
+        final long persistThreshold = mSettings.getPersistThreshold();
+        for (String iface : persistDelta.getUniqueIfaces()) {
+            final int index = persistDelta.findIndex(iface, UID_ALL, TAG_NONE);
+            if (forcePersist || persistDelta.rx[index] > persistThreshold
+                    || persistDelta.tx[index] > persistThreshold) {
+                writeNetworkStatsLocked();
+                if (mUidStatsLoaded) {
+                    writeUidStatsLocked();
+                }
+                mLastPersistNetworkSnapshot = networkSnapshot;
+                break;
+            }
+        }
+
+        // finally, dispatch updated event to any listeners
+        final Intent updatedIntent = new Intent(ACTION_NETWORK_STATS_UPDATED);
+        updatedIntent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
+        mContext.sendBroadcast(updatedIntent, READ_NETWORK_USAGE_HISTORY);
+    }
+
+    /**
+     * Update {@link #mNetworkStats} historical usage.
+     */
+    private void performNetworkPollLocked(NetworkStats networkSnapshot, long currentTime) {
+        final HashSet<String> unknownIface = Sets.newHashSet();
+
+        final NetworkStats delta = computeStatsDelta(mLastNetworkSnapshot, networkSnapshot);
+        final long timeStart = currentTime - delta.elapsedRealtime;
+        for (int i = 0; i < delta.size; i++) {
+            final String iface = delta.iface[i];
+            final NetworkIdentitySet ident = mActiveIfaces.get(iface);
+            if (ident == null) {
+                unknownIface.add(iface);
+                continue;
+            }
+
+            final long rx = delta.rx[i];
+            final long tx = delta.tx[i];
+
+            final NetworkStatsHistory history = findOrCreateNetworkStatsLocked(ident);
+            history.recordData(timeStart, currentTime, rx, tx);
+        }
+
+        // trim any history beyond max
+        final long maxHistory = mSettings.getNetworkMaxHistory();
+        for (NetworkStatsHistory history : mNetworkStats.values()) {
+            history.removeBucketsBefore(currentTime - maxHistory);
+        }
+
+        mLastNetworkSnapshot = networkSnapshot;
+
+        if (LOGD && unknownIface.size() > 0) {
+            Slog.w(TAG, "unknown interfaces " + unknownIface.toString() + ", ignoring those stats");
+        }
+    }
+
+    /**
+     * Update {@link #mUidStats} historical usage.
+     */
+    private void performUidPollLocked(NetworkStats uidSnapshot, long currentTime) {
+        ensureUidStatsLoadedLocked();
+
+        final NetworkStats delta = computeStatsDelta(mLastUidSnapshot, uidSnapshot);
+        final long timeStart = currentTime - delta.elapsedRealtime;
+
+        for (int i = 0; i < delta.size; i++) {
+            final String iface = delta.iface[i];
+            final NetworkIdentitySet ident = mActiveIfaces.get(iface);
+            if (ident == null) {
+                continue;
+            }
+
+            final int uid = delta.uid[i];
+            final int tag = delta.tag[i];
+            final long rx = delta.rx[i];
+            final long tx = delta.tx[i];
+
+            final NetworkStatsHistory history = findOrCreateUidStatsLocked(ident, uid, tag);
+            history.recordData(timeStart, currentTime, rx, tx);
+        }
+
+        // trim any history beyond max
+        final long maxUidHistory = mSettings.getUidMaxHistory();
+        final long maxTagHistory = mSettings.getTagMaxHistory();
+        for (LongSparseArray<NetworkStatsHistory> uidStats : mUidStats.values()) {
+            for (int i = 0; i < uidStats.size(); i++) {
+                final long packed = uidStats.keyAt(i);
+                final NetworkStatsHistory history = uidStats.valueAt(i);
+
+                // detailed tags are trimmed sooner than summary in TAG_NONE
+                if (unpackTag(packed) == TAG_NONE) {
+                    history.removeBucketsBefore(currentTime - maxUidHistory);
+                } else {
+                    history.removeBucketsBefore(currentTime - maxTagHistory);
+                }
+            }
+        }
+
+        mLastUidSnapshot = uidSnapshot;
+    }
+
+    /**
+     * Clean up {@link #mUidStats} after UID is removed.
+     */
+    private void removeUidLocked(int uid) {
+        ensureUidStatsLoadedLocked();
+
+        // migrate all UID stats into special "removed" bucket
+        for (NetworkIdentitySet ident : mUidStats.keySet()) {
+            final LongSparseArray<NetworkStatsHistory> uidStats = mUidStats.get(ident);
+            for (int i = 0; i < uidStats.size(); i++) {
+                final long packed = uidStats.keyAt(i);
+                if (unpackUid(packed) == uid) {
+                    // only migrate combined TAG_NONE history
+                    if (unpackTag(packed) == TAG_NONE) {
+                        final NetworkStatsHistory uidHistory = uidStats.valueAt(i);
+                        final NetworkStatsHistory removedHistory = findOrCreateUidStatsLocked(
+                                ident, UID_REMOVED, TAG_NONE);
+                        removedHistory.recordEntireHistory(uidHistory);
+                    }
+                    uidStats.remove(packed);
+                }
+            }
+        }
+
+        // TODO: push kernel event to wipe stats for UID, otherwise we risk
+        // picking them up again during next poll.
+
+        // since this was radical rewrite, push to disk
+        writeUidStatsLocked();
+    }
+
+    private NetworkStatsHistory findOrCreateNetworkStatsLocked(NetworkIdentitySet ident) {
+        final NetworkStatsHistory existing = mNetworkStats.get(ident);
+
+        // update when no existing, or when bucket duration changed
+        final long bucketDuration = mSettings.getNetworkBucketDuration();
+        NetworkStatsHistory updated = null;
+        if (existing == null) {
+            updated = new NetworkStatsHistory(bucketDuration, 10);
+        } else if (existing.bucketDuration != bucketDuration) {
+            updated = new NetworkStatsHistory(
+                    bucketDuration, estimateResizeBuckets(existing, bucketDuration));
+            updated.recordEntireHistory(existing);
+        }
+
+        if (updated != null) {
+            mNetworkStats.put(ident, updated);
+            return updated;
+        } else {
+            return existing;
+        }
+    }
+
+    private NetworkStatsHistory findOrCreateUidStatsLocked(
+            NetworkIdentitySet ident, int uid, int tag) {
+        ensureUidStatsLoadedLocked();
+
+        LongSparseArray<NetworkStatsHistory> uidStats = mUidStats.get(ident);
+        if (uidStats == null) {
+            uidStats = new LongSparseArray<NetworkStatsHistory>();
+            mUidStats.put(ident, uidStats);
+        }
+
+        final long packed = packUidAndTag(uid, tag);
+        final NetworkStatsHistory existing = uidStats.get(packed);
+
+        // update when no existing, or when bucket duration changed
+        final long bucketDuration = mSettings.getUidBucketDuration();
+        NetworkStatsHistory updated = null;
+        if (existing == null) {
+            updated = new NetworkStatsHistory(bucketDuration, 10);
+        } else if (existing.bucketDuration != bucketDuration) {
+            updated = new NetworkStatsHistory(
+                    bucketDuration, estimateResizeBuckets(existing, bucketDuration));
+            updated.recordEntireHistory(existing);
+        }
+
+        if (updated != null) {
+            uidStats.put(packed, updated);
+            return updated;
+        } else {
+            return existing;
+        }
+    }
+
+    private void readNetworkStatsLocked() {
+        if (LOGV) Slog.v(TAG, "readNetworkStatsLocked()");
+
+        // clear any existing stats and read from disk
+        mNetworkStats.clear();
+
+        FileInputStream fis = null;
+        try {
+            fis = mNetworkFile.openRead();
+            final DataInputStream in = new DataInputStream(fis);
+
+            // verify file magic header intact
+            final int magic = in.readInt();
+            if (magic != FILE_MAGIC) {
+                throw new ProtocolException("unexpected magic: " + magic);
+            }
+
+            final int version = in.readInt();
+            switch (version) {
+                case VERSION_NETWORK_INIT: {
+                    // network := size *(NetworkIdentitySet NetworkStatsHistory)
+                    final int size = in.readInt();
+                    for (int i = 0; i < size; i++) {
+                        final NetworkIdentitySet ident = new NetworkIdentitySet(in);
+                        final NetworkStatsHistory history = new NetworkStatsHistory(in);
+                        mNetworkStats.put(ident, history);
+                    }
+                    break;
+                }
+                default: {
+                    throw new ProtocolException("unexpected version: " + version);
+                }
+            }
+        } catch (FileNotFoundException e) {
+            // missing stats is okay, probably first boot
+        } catch (IOException e) {
+            Slog.e(TAG, "problem reading network stats", e);
+        } finally {
+            IoUtils.closeQuietly(fis);
+        }
+    }
+
+    private void ensureUidStatsLoadedLocked() {
+        if (!mUidStatsLoaded) {
+            readUidStatsLocked();
+            mUidStatsLoaded = true;
+        }
+    }
+
+    private void readUidStatsLocked() {
+        if (LOGV) Slog.v(TAG, "readUidStatsLocked()");
+
+        // clear any existing stats and read from disk
+        mUidStats.clear();
+
+        FileInputStream fis = null;
+        try {
+            fis = mUidFile.openRead();
+            final DataInputStream in = new DataInputStream(fis);
+
+            // verify file magic header intact
+            final int magic = in.readInt();
+            if (magic != FILE_MAGIC) {
+                throw new ProtocolException("unexpected magic: " + magic);
+            }
+
+            final int version = in.readInt();
+            switch (version) {
+                case VERSION_UID_INIT: {
+                    // uid := size *(UID NetworkStatsHistory)
+
+                    // drop this data version, since we don't have a good
+                    // mapping into NetworkIdentitySet.
+                    break;
+                }
+                case VERSION_UID_WITH_IDENT: {
+                    // uid := size *(NetworkIdentitySet size *(UID NetworkStatsHistory))
+
+                    // drop this data version, since this version only existed
+                    // for a short time.
+                    break;
+                }
+                case VERSION_UID_WITH_TAG: {
+                    // uid := size *(NetworkIdentitySet size *(UID tag NetworkStatsHistory))
+                    final int ifaceSize = in.readInt();
+                    for (int i = 0; i < ifaceSize; i++) {
+                        final NetworkIdentitySet ident = new NetworkIdentitySet(in);
+
+                        final int childSize = in.readInt();
+                        final LongSparseArray<NetworkStatsHistory> uidStats = new LongSparseArray<
+                                NetworkStatsHistory>(childSize);
+                        for (int j = 0; j < childSize; j++) {
+                            final int uid = in.readInt();
+                            final int tag = in.readInt();
+                            final long packed = packUidAndTag(uid, tag);
+
+                            final NetworkStatsHistory history = new NetworkStatsHistory(in);
+                            uidStats.put(packed, history);
+                        }
+
+                        mUidStats.put(ident, uidStats);
+                    }
+                    break;
+                }
+                default: {
+                    throw new ProtocolException("unexpected version: " + version);
+                }
+            }
+        } catch (FileNotFoundException e) {
+            // missing stats is okay, probably first boot
+        } catch (IOException e) {
+            Slog.e(TAG, "problem reading uid stats", e);
+        } finally {
+            IoUtils.closeQuietly(fis);
+        }
+    }
+
+    private void writeNetworkStatsLocked() {
+        if (LOGV) Slog.v(TAG, "writeNetworkStatsLocked()");
+
+        // TODO: consider duplicating stats and releasing lock while writing
+
+        FileOutputStream fos = null;
+        try {
+            fos = mNetworkFile.startWrite();
+            final DataOutputStream out = new DataOutputStream(fos);
+
+            out.writeInt(FILE_MAGIC);
+            out.writeInt(VERSION_NETWORK_INIT);
+
+            out.writeInt(mNetworkStats.size());
+            for (NetworkIdentitySet ident : mNetworkStats.keySet()) {
+                final NetworkStatsHistory history = mNetworkStats.get(ident);
+                ident.writeToStream(out);
+                history.writeToStream(out);
+            }
+
+            mNetworkFile.finishWrite(fos);
+        } catch (IOException e) {
+            if (fos != null) {
+                mNetworkFile.failWrite(fos);
+            }
+        }
+    }
+
+    private void writeUidStatsLocked() {
+        if (LOGV) Slog.v(TAG, "writeUidStatsLocked()");
+
+        if (!mUidStatsLoaded) {
+            Slog.w(TAG, "asked to write UID stats when not loaded; skipping");
+            return;
+        }
+
+        // TODO: consider duplicating stats and releasing lock while writing
+
+        FileOutputStream fos = null;
+        try {
+            fos = mUidFile.startWrite();
+            final DataOutputStream out = new DataOutputStream(fos);
+
+            out.writeInt(FILE_MAGIC);
+            out.writeInt(VERSION_UID_WITH_TAG);
+
+            final int size = mUidStats.size();
+            out.writeInt(size);
+            for (NetworkIdentitySet ident : mUidStats.keySet()) {
+                final LongSparseArray<NetworkStatsHistory> uidStats = mUidStats.get(ident);
+                ident.writeToStream(out);
+
+                final int childSize = uidStats.size();
+                out.writeInt(childSize);
+                for (int i = 0; i < childSize; i++) {
+                    final long packed = uidStats.keyAt(i);
+                    final int uid = unpackUid(packed);
+                    final int tag = unpackTag(packed);
+                    final NetworkStatsHistory history = uidStats.valueAt(i);
+                    out.writeInt(uid);
+                    out.writeInt(tag);
+                    history.writeToStream(out);
+                }
+            }
+
+            mUidFile.finishWrite(fos);
+        } catch (IOException e) {
+            if (fos != null) {
+                mUidFile.failWrite(fos);
+            }
+        }
+    }
+
+    @Override
+    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+        mContext.enforceCallingOrSelfPermission(DUMP, TAG);
+
+        final HashSet<String> argSet = new HashSet<String>();
+        for (String arg : args) {
+            argSet.add(arg);
+        }
+
+        synchronized (mStatsLock) {
+            // TODO: remove this testing code, since it corrupts stats
+            if (argSet.contains("generate")) {
+                generateRandomLocked();
+                pw.println("Generated stub stats");
+                return;
+            }
+
+            if (argSet.contains("poll")) {
+                performPollLocked(true, true);
+                pw.println("Forced poll");
+                return;
+            }
+
+            pw.println("Active interfaces:");
+            for (String iface : mActiveIfaces.keySet()) {
+                final NetworkIdentitySet ident = mActiveIfaces.get(iface);
+                pw.print("  iface="); pw.print(iface);
+                pw.print(" ident="); pw.println(ident.toString());
+            }
+
+            pw.println("Known historical stats:");
+            for (NetworkIdentitySet ident : mNetworkStats.keySet()) {
+                final NetworkStatsHistory history = mNetworkStats.get(ident);
+                pw.print("  ident="); pw.println(ident.toString());
+                history.dump("  ", pw);
+            }
+
+            if (argSet.contains("detail")) {
+                // since explicitly requested with argument, we're okay to load
+                // from disk if not already in memory.
+                ensureUidStatsLoadedLocked();
+
+                pw.println("Detailed UID stats:");
+                for (NetworkIdentitySet ident : mUidStats.keySet()) {
+                    pw.print("  ident="); pw.println(ident.toString());
+
+                    final LongSparseArray<NetworkStatsHistory> uidStats = mUidStats.get(ident);
+                    for (int i = 0; i < uidStats.size(); i++) {
+                        final long packed = uidStats.keyAt(i);
+                        final int uid = unpackUid(packed);
+                        final int tag = unpackTag(packed);
+                        final NetworkStatsHistory history = uidStats.valueAt(i);
+                        pw.print("    UID="); pw.print(uid);
+                        pw.print(" tag="); pw.println(tag);
+                        history.dump("    ", pw);
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * @deprecated only for temporary testing
+     */
+    @Deprecated
+    private void generateRandomLocked() {
+        long networkEnd = System.currentTimeMillis();
+        long networkStart = networkEnd - mSettings.getNetworkMaxHistory();
+        long networkRx = 3 * GB_IN_BYTES;
+        long networkTx = 2 * GB_IN_BYTES;
+
+        long uidEnd = System.currentTimeMillis();
+        long uidStart = uidEnd - mSettings.getUidMaxHistory();
+        long uidRx = 500 * MB_IN_BYTES;
+        long uidTx = 100 * MB_IN_BYTES;
+
+        final List<ApplicationInfo> installedApps = mContext
+                .getPackageManager().getInstalledApplications(0);
+
+        mNetworkStats.clear();
+        mUidStats.clear();
+        for (NetworkIdentitySet ident : mActiveIfaces.values()) {
+            findOrCreateNetworkStatsLocked(ident).generateRandom(
+                    networkStart, networkEnd, networkRx, networkTx);
+
+            for (ApplicationInfo info : installedApps) {
+                final int uid = info.uid;
+                findOrCreateUidStatsLocked(ident, uid, TAG_NONE).generateRandom(
+                        uidStart, uidEnd, uidRx, uidTx);
+            }
+        }
+    }
+
+    /**
+     * Return the delta between two {@link NetworkStats} snapshots, where {@code
+     * before} can be {@code null}.
+     */
+    private static NetworkStats computeStatsDelta(NetworkStats before, NetworkStats current) {
+        if (before != null) {
+            return current.subtractClamped(before);
+        } else {
+            return current;
+        }
+    }
+
+    private int estimateNetworkBuckets() {
+        return (int) (mSettings.getNetworkMaxHistory() / mSettings.getNetworkBucketDuration());
+    }
+
+    private int estimateUidBuckets() {
+        return (int) (mSettings.getUidMaxHistory() / mSettings.getUidBucketDuration());
+    }
+
+    private static int estimateResizeBuckets(NetworkStatsHistory existing, long newBucketDuration) {
+        return (int) (existing.bucketCount * existing.bucketDuration / newBucketDuration);
+    }
+
+    // @VisibleForTesting
+    public static long packUidAndTag(int uid, int tag) {
+        final long uidLong = uid;
+        final long tagLong = tag;
+        return (uidLong << 32) | (tagLong & 0xFFFFFFFFL);
+    }
+
+    // @VisibleForTesting
+    public static int unpackUid(long packed) {
+        return (int) (packed >> 32);
+    }
+
+    // @VisibleForTesting
+    public static int unpackTag(long packed) {
+        return (int) (packed & 0xFFFFFFFFL);
+    }
+
+    /**
+     * Test if given {@link NetworkTemplate} matches any {@link NetworkIdentity}
+     * in the given {@link NetworkIdentitySet}.
+     */
+    private static boolean templateMatches(NetworkTemplate template, NetworkIdentitySet identSet) {
+        for (NetworkIdentity ident : identSet) {
+            if (template.matches(ident)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Default external settings that read from {@link Settings.Secure}.
+     */
+    private static class DefaultNetworkStatsSettings implements NetworkStatsSettings {
+        private final ContentResolver mResolver;
+
+        public DefaultNetworkStatsSettings(Context context) {
+            mResolver = checkNotNull(context.getContentResolver());
+            // TODO: adjust these timings for production builds
+        }
+
+        private long getSecureLong(String name, long def) {
+            return Settings.Secure.getLong(mResolver, name, def);
+        }
+
+        public long getPollInterval() {
+            return getSecureLong(NETSTATS_POLL_INTERVAL, 15 * MINUTE_IN_MILLIS);
+        }
+        public long getPersistThreshold() {
+            return getSecureLong(NETSTATS_PERSIST_THRESHOLD, 16 * KB_IN_BYTES);
+        }
+        public long getNetworkBucketDuration() {
+            return getSecureLong(NETSTATS_NETWORK_BUCKET_DURATION, HOUR_IN_MILLIS);
+        }
+        public long getNetworkMaxHistory() {
+            return getSecureLong(NETSTATS_NETWORK_MAX_HISTORY, 90 * DAY_IN_MILLIS);
+        }
+        public long getUidBucketDuration() {
+            return getSecureLong(NETSTATS_UID_BUCKET_DURATION, 2 * HOUR_IN_MILLIS);
+        }
+        public long getUidMaxHistory() {
+            return getSecureLong(NETSTATS_UID_MAX_HISTORY, 90 * DAY_IN_MILLIS);
+        }
+        public long getTagMaxHistory() {
+            return getSecureLong(NETSTATS_TAG_MAX_HISTORY, 30 * DAY_IN_MILLIS);
+        }
+        public long getTimeCacheMaxAge() {
+            return DAY_IN_MILLIS;
+        }
+    }
+
+}
diff --git a/services/java/com/android/server/pm/PackageManagerService.java b/services/java/com/android/server/pm/PackageManagerService.java
index e1fbe1c..5a9dae9 100644
--- a/services/java/com/android/server/pm/PackageManagerService.java
+++ b/services/java/com/android/server/pm/PackageManagerService.java
@@ -18,6 +18,7 @@
 
 import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
 import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
+import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER;
 import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
 
 import com.android.internal.app.IMediaContainerService;
@@ -7048,7 +7049,8 @@
             final String packageName, String className, int newState, final int flags) {
         if (!(newState == COMPONENT_ENABLED_STATE_DEFAULT
               || newState == COMPONENT_ENABLED_STATE_ENABLED
-              || newState == COMPONENT_ENABLED_STATE_DISABLED)) {
+              || newState == COMPONENT_ENABLED_STATE_DISABLED
+              || newState == COMPONENT_ENABLED_STATE_DISABLED_USER)) {
             throw new IllegalArgumentException("Invalid new component state: "
                     + newState);
         }
diff --git a/services/java/com/android/server/pm/Settings.java b/services/java/com/android/server/pm/Settings.java
index 2720bf8..5ed7988 100644
--- a/services/java/com/android/server/pm/Settings.java
+++ b/services/java/com/android/server/pm/Settings.java
@@ -18,6 +18,7 @@
 
 import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
 import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
+import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER;
 import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
 
 import com.android.internal.util.FastXmlSerializer;
@@ -1912,6 +1913,7 @@
             return false;
         }
         if (packageSettings.enabled == COMPONENT_ENABLED_STATE_DISABLED
+                || packageSettings.enabled == COMPONENT_ENABLED_STATE_DISABLED_USER
                 || (packageSettings.pkg != null && !packageSettings.pkg.applicationInfo.enabled
                         && packageSettings.enabled == COMPONENT_ENABLED_STATE_DEFAULT)) {
             return false;
diff --git a/services/java/com/android/server/usb/UsbDeviceManager.java b/services/java/com/android/server/usb/UsbDeviceManager.java
new file mode 100644
index 0000000..b7f9d5c
--- /dev/null
+++ b/services/java/com/android/server/usb/UsbDeviceManager.java
@@ -0,0 +1,619 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions an
+ * limitations under the License.
+ */
+
+package com.android.server.usb;
+
+import android.app.PendingIntent;
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.content.ComponentName;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.PackageManager;
+import android.content.res.Resources;
+import android.database.ContentObserver;
+import android.hardware.usb.UsbAccessory;
+import android.hardware.usb.UsbManager;
+import android.net.Uri;
+import android.os.Binder;
+import android.os.Bundle;
+import android.os.FileUtils;
+import android.os.Handler;
+import android.os.HandlerThread;
+import android.os.Looper;
+import android.os.Message;
+import android.os.Parcelable;
+import android.os.ParcelFileDescriptor;
+import android.os.Process;
+import android.os.storage.StorageManager;
+import android.os.storage.StorageVolume;
+import android.os.SystemProperties;
+import android.os.UEventObserver;
+import android.provider.Settings;
+import android.util.Log;
+import android.util.Slog;
+
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * UsbDeviceManager manages USB state in device mode.
+ */
+public class UsbDeviceManager {
+
+    private static final String TAG = UsbDeviceManager.class.getSimpleName();
+    private static final boolean LOG = false;
+
+    private static final String USB_STATE_MATCH =
+            "DEVPATH=/devices/virtual/android_usb/android0";
+    private static final String ACCESSORY_START_MATCH =
+            "DEVPATH=/devices/virtual/misc/usb_accessory";
+    private static final String FUNCTIONS_PATH =
+            "/sys/class/android_usb/android0/functions";
+    private static final String STATE_PATH =
+            "/sys/class/android_usb/android0/state";
+    private static final String MASS_STORAGE_FILE_PATH =
+            "/sys/class/android_usb/f_mass_storage/lun/file";
+
+    private static final int MSG_UPDATE_STATE = 0;
+    private static final int MSG_ENABLE_ADB = 1;
+    private static final int MSG_SET_PRIMARY_FUNCTION = 2;
+    private static final int MSG_SET_DEFAULT_FUNCTION = 3;
+    private static final int MSG_SYSTEM_READY = 4;
+
+    // Delay for debouncing USB disconnects.
+    // We often get rapid connect/disconnect events when enabling USB functions,
+    // which need debouncing.
+    private static final int UPDATE_DELAY = 1000;
+
+    private UsbHandler mHandler;
+    private boolean mSystemReady;
+
+    private final Context mContext;
+    private final ContentResolver mContentResolver;
+    private final UsbSettingsManager mSettingsManager;
+    private NotificationManager mNotificationManager;
+    private final boolean mHasUsbAccessory;
+
+    // for USB connected notification
+    private boolean mUsbNotificationShown;
+    private boolean mUseUsbNotification;
+    private Notification mUsbNotification;
+
+    // for adb connected notification
+    private boolean mAdbNotificationShown;
+    private Notification mAdbNotification;
+    private boolean mAdbEnabled;
+
+
+    private class AdbSettingsObserver extends ContentObserver {
+        public AdbSettingsObserver() {
+            super(null);
+        }
+        @Override
+        public void onChange(boolean selfChange) {
+            boolean enable = (Settings.Secure.getInt(mContentResolver,
+                    Settings.Secure.ADB_ENABLED, 0) > 0);
+            mHandler.sendMessage(MSG_ENABLE_ADB, enable);
+        }
+    }
+
+    private void updateUsbNotification(boolean connected) {
+        if (mNotificationManager == null || !mUseUsbNotification) return;
+        if (connected) {
+            if (!mUsbNotificationShown) {
+                Resources r = mContext.getResources();
+                CharSequence title = r.getText(
+                        com.android.internal.R.string.usb_preferences_notification_title);
+                CharSequence message = r.getText(
+                        com.android.internal.R.string.usb_preferece_notification_message);
+
+                if (mUsbNotification == null) {
+                    mUsbNotification = new Notification();
+                    mUsbNotification.icon = com.android.internal.R.drawable.stat_sys_data_usb;
+                    mUsbNotification.when = 0;
+                    mUsbNotification.flags = Notification.FLAG_ONGOING_EVENT;
+                    mUsbNotification.tickerText = title;
+                    mUsbNotification.defaults = 0; // please be quiet
+                    mUsbNotification.sound = null;
+                    mUsbNotification.vibrate = null;
+                }
+
+                Intent intent = new Intent();
+                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
+                        Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
+                intent.setClassName("com.android.systemui",
+                        "com.android.systemui.usb.UsbPreferenceActivity");
+                PendingIntent pi = PendingIntent.getActivity(mContext, 0,
+                        intent, 0);
+
+                mUsbNotification.setLatestEventInfo(mContext, title, message, pi);
+
+                mUsbNotificationShown = true;
+                mNotificationManager.notify(
+                        com.android.internal.R.string.usb_preferences_notification_title,
+                        mUsbNotification);
+            }
+
+        } else if (mUsbNotificationShown) {
+            mUsbNotificationShown = false;
+            mNotificationManager.cancel(
+                    com.android.internal.R.string.usb_preferences_notification_title);
+        }
+    }
+
+    private void updateAdbNotification(boolean adbEnabled) {
+        if (mNotificationManager == null) return;
+        if (adbEnabled) {
+            if ("0".equals(SystemProperties.get("persist.adb.notify"))) return;
+
+            if (!mAdbNotificationShown) {
+                Resources r = mContext.getResources();
+                CharSequence title = r.getText(
+                        com.android.internal.R.string.adb_active_notification_title);
+                CharSequence message = r.getText(
+                        com.android.internal.R.string.adb_active_notification_message);
+
+                if (mAdbNotification == null) {
+                    mAdbNotification = new Notification();
+                    mAdbNotification.icon = com.android.internal.R.drawable.stat_sys_adb;
+                    mAdbNotification.when = 0;
+                    mAdbNotification.flags = Notification.FLAG_ONGOING_EVENT;
+                    mAdbNotification.tickerText = title;
+                    mAdbNotification.defaults = 0; // please be quiet
+                    mAdbNotification.sound = null;
+                    mAdbNotification.vibrate = null;
+                }
+
+                Intent intent = new Intent(
+                        Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS);
+                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
+                        Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
+                // Note: we are hard-coding the component because this is
+                // an important security UI that we don't want anyone
+                // intercepting.
+                intent.setComponent(new ComponentName("com.android.settings",
+                        "com.android.settings.DevelopmentSettings"));
+                PendingIntent pi = PendingIntent.getActivity(mContext, 0,
+                        intent, 0);
+
+                mAdbNotification.setLatestEventInfo(mContext, title, message, pi);
+
+                mAdbNotificationShown = true;
+                mNotificationManager.notify(
+                        com.android.internal.R.string.adb_active_notification_title,
+                        mAdbNotification);
+            }
+        } else if (mAdbNotificationShown) {
+            mAdbNotificationShown = false;
+            mNotificationManager.cancel(
+                    com.android.internal.R.string.adb_active_notification_title);
+        }
+    }
+
+    /*
+     * Listens for uevent messages from the kernel to monitor the USB state
+     */
+    private final UEventObserver mUEventObserver = new UEventObserver() {
+        @Override
+        public void onUEvent(UEventObserver.UEvent event) {
+            if (Log.isLoggable(TAG, Log.VERBOSE)) {
+                Slog.v(TAG, "USB UEVENT: " + event.toString());
+            }
+
+            String state = event.get("USB_STATE");
+            String accessory = event.get("ACCESSORY");
+            if (state != null) {
+                mHandler.updateState(state);
+            } else if ("START".equals(accessory)) {
+                Slog.d(TAG, "got accessory start");
+                setPrimaryFunction(UsbManager.USB_FUNCTION_ACCESSORY);
+            }
+        }
+    };
+
+    public UsbDeviceManager(Context context, UsbSettingsManager settingsManager) {
+        mContext = context;
+        mContentResolver = context.getContentResolver();
+        mSettingsManager = settingsManager;
+        PackageManager pm = mContext.getPackageManager();
+        mHasUsbAccessory = pm.hasSystemFeature(PackageManager.FEATURE_USB_ACCESSORY);
+
+        // create a thread for our Handler
+        HandlerThread thread = new HandlerThread("UsbDeviceManager",
+                Process.THREAD_PRIORITY_BACKGROUND) {
+            protected void onLooperPrepared() {
+                mHandler = new UsbHandler();
+            }
+        };
+        thread.start();
+    }
+
+    public void systemReady() {
+        mSystemReady = true;
+
+        mNotificationManager = (NotificationManager)
+                mContext.getSystemService(Context.NOTIFICATION_SERVICE);
+
+        // We do not show the USB notification if the primary volume supports mass storage.
+        // The legacy mass storage UI will be used instead.
+        boolean massStorageSupported = false;
+        StorageManager storageManager = (StorageManager)
+                mContext.getSystemService(Context.STORAGE_SERVICE);
+        StorageVolume[] volumes = storageManager.getVolumeList();
+        if (volumes.length > 0) {
+            massStorageSupported = volumes[0].allowMassStorage();
+        }
+        mUseUsbNotification = !massStorageSupported;
+
+        // make sure the ADB_ENABLED setting value matches the current state
+        Settings.Secure.putInt(mContentResolver, Settings.Secure.ADB_ENABLED, mAdbEnabled ? 1 : 0);
+
+        mHandler.sendEmptyMessage(MSG_SYSTEM_READY);
+    }
+
+     private static String addFunction(String functions, String function) {
+        if (!containsFunction(functions, function)) {
+            if (functions.length() > 0) {
+                functions += ",";
+            }
+            functions += function;
+        }
+        return functions;
+    }
+
+    private static String removeFunction(String functions, String function) {
+        String[] split = functions.split(",");
+        for (int i = 0; i < split.length; i++) {
+            if (function.equals(split[i])) {
+                split[i] = null;
+            }
+        }
+        StringBuilder builder = new StringBuilder();
+         for (int i = 0; i < split.length; i++) {
+            String s = split[i];
+            if (s != null) {
+                if (builder.length() > 0) {
+                    builder.append(",");
+                }
+                builder.append(s);
+            }
+        }
+        return builder.toString();
+    }
+
+    private static boolean containsFunction(String functions, String function) {
+        int index = functions.indexOf(function);
+        if (index < 0) return false;
+        if (index > 0 && functions.charAt(index - 1) != ',') return false;
+        int charAfter = index + function.length();
+        if (charAfter < functions.length() && functions.charAt(charAfter) != ',') return false;
+        return true;
+    }
+
+    private final class UsbHandler extends Handler {
+
+        // current USB state
+        private boolean mConnected;
+        private boolean mConfigured;
+        private String mCurrentFunctions;
+        private String mDefaultFunctions;
+        private UsbAccessory mCurrentAccessory;
+        private boolean mDeferAccessoryAttached;
+
+        public UsbHandler() {
+            // Read initial USB state
+            try {
+                mCurrentFunctions = FileUtils.readTextFile(
+                        new File(FUNCTIONS_PATH), 0, null).trim();
+                mDefaultFunctions = mCurrentFunctions;
+                String state = FileUtils.readTextFile(new File(STATE_PATH), 0, null).trim();
+                updateState(state);
+
+                mAdbEnabled = containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_ADB);
+
+                // Upgrade step for previous versions that used persist.service.adb.enable
+                String value = SystemProperties.get("persist.service.adb.enable", "");
+                if (value.length() > 0) {
+                    char enable = value.charAt(0);
+                    if (enable == '1') {
+                        setAdbEnabled(true);
+                    } else if (enable == '0') {
+                        setAdbEnabled(false);
+                    }
+                    SystemProperties.set("persist.service.adb.enable", "");
+                }
+
+                // register observer to listen for settings changes
+                mContentResolver.registerContentObserver(
+                        Settings.Secure.getUriFor(Settings.Secure.ADB_ENABLED),
+                                false, new AdbSettingsObserver());
+
+                // Watch for USB configuration changes
+                mUEventObserver.startObserving(USB_STATE_MATCH);
+                mUEventObserver.startObserving(ACCESSORY_START_MATCH);
+            } catch (Exception e) {
+                Slog.e(TAG, "Error initializing UsbHandler", e);
+            }
+        }
+
+        public void sendMessage(int what, boolean arg) {
+            removeMessages(what);
+            Message m = Message.obtain(this, what);
+            m.arg1 = (arg ? 1 : 0);
+            sendMessage(m);
+        }
+
+        public void sendMessage(int what, Object arg) {
+            removeMessages(what);
+            Message m = Message.obtain(this, what);
+            m.obj = arg;
+            sendMessage(m);
+        }
+
+        public void updateState(String state) {
+            int connected, configured;
+
+            if ("DISCONNECTED".equals(state)) {
+                connected = 0;
+                configured = 0;
+            } else if ("CONNECTED".equals(state)) {
+                connected = 1;
+                configured = 0;
+            } else if ("CONFIGURED".equals(state)) {
+                connected = 1;
+                configured = 1;
+            } else {
+                Slog.e(TAG, "unknown state " + state);
+                return;
+            }
+            removeMessages(MSG_UPDATE_STATE);
+            Message msg = Message.obtain(this, MSG_UPDATE_STATE);
+            msg.arg1 = connected;
+            msg.arg2 = configured;
+            // debounce disconnects to avoid problems bringing up USB tethering
+            sendMessageDelayed(msg, (connected == 0) ? UPDATE_DELAY : 0);
+        }
+
+        private boolean setUsbConfig(String config) {
+            // set the new configuration
+            SystemProperties.set("sys.usb.config", config);
+            // wait for the transition to complete.
+            // give up after 1 second.
+            for (int i = 0; i < 20; i++) {
+                // State transition is done when sys.usb.conf.done is set to the new configuration
+                if (config.equals(SystemProperties.get("sys.usb.state"))) return true;
+                try {
+                    // try again in 50ms
+                    Thread.sleep(50);
+                } catch (InterruptedException e) {
+                }
+            }
+            return false;
+        }
+
+        private void setCurrentFunctions(String functions) {
+            if (!mCurrentFunctions.equals(functions)) {
+                if (!setUsbConfig("none") || !setUsbConfig(functions)) {
+                    Log.e(TAG, "Failed to switch USB configuration to " + functions);
+                    // revert to previous configuration if we fail
+                    setUsbConfig(mCurrentFunctions);
+                } else {
+                    mCurrentFunctions = functions;
+                }
+            }
+        }
+
+        private void setAdbEnabled(boolean enable) {
+            if (enable != mAdbEnabled) {
+                mAdbEnabled = enable;
+                String functions;
+                if (enable) {
+                    functions = addFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_ADB);
+                    mDefaultFunctions = addFunction(mDefaultFunctions,
+                            UsbManager.USB_FUNCTION_ADB);
+                } else {
+                    functions = removeFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_ADB);
+                    mDefaultFunctions = removeFunction(mDefaultFunctions,
+                            UsbManager.USB_FUNCTION_ADB);
+                }
+                SystemProperties.set("persist.sys.usb.config", mDefaultFunctions);
+                setCurrentFunctions(functions);
+                updateAdbNotification(mAdbEnabled && mConnected);
+            }
+        }
+
+        private void setEnabledFunctions(String functionList) {
+            if (mAdbEnabled) {
+                functionList = addFunction(functionList, UsbManager.USB_FUNCTION_ADB);
+            } else {
+                functionList = removeFunction(functionList, UsbManager.USB_FUNCTION_ADB);
+            }
+            setCurrentFunctions(functionList);
+        }
+
+        private void updateCurrentAccessory() {
+            if (!mHasUsbAccessory) return;
+
+            if (mConfigured) {
+                String[] strings = nativeGetAccessoryStrings();
+                if (strings != null) {
+                    mCurrentAccessory = new UsbAccessory(strings);
+                    Log.d(TAG, "entering USB accessory mode: " + mCurrentAccessory);
+                    // defer accessoryAttached if system is not ready
+                    if (mSystemReady) {
+                        mSettingsManager.accessoryAttached(mCurrentAccessory);
+                    } else {
+                        mDeferAccessoryAttached = true;
+                    }
+                } else {
+                    Log.e(TAG, "nativeGetAccessoryStrings failed");
+                }
+            } else if (!mConnected) {
+                // make sure accessory mode is off
+                // and restore default functions
+                Log.d(TAG, "exited USB accessory mode");
+                setEnabledFunctions(mDefaultFunctions);
+
+                if (mCurrentAccessory != null) {
+                    if (mSystemReady) {
+                        mSettingsManager.accessoryDetached(mCurrentAccessory);
+                    }
+                    mCurrentAccessory = null;
+                }
+            }
+        }
+
+        private void updateUsbState() {
+            // send a sticky broadcast containing current USB state
+            Intent intent = new Intent(UsbManager.ACTION_USB_STATE);
+            intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
+            intent.putExtra(UsbManager.USB_CONNECTED, mConnected);
+            intent.putExtra(UsbManager.USB_CONFIGURED, mConfigured);
+
+            if (mCurrentFunctions != null) {
+                String[] functions = mCurrentFunctions.split(",");
+                for (int i = 0; i < functions.length; i++) {
+                    intent.putExtra(functions[i], true);
+                }
+            }
+
+            mContext.sendStickyBroadcast(intent);
+        }
+
+        @Override
+        public void handleMessage(Message msg) {
+            String function;
+
+            switch (msg.what) {
+                case MSG_UPDATE_STATE:
+                    mConnected = (msg.arg1 == 1);
+                    mConfigured = (msg.arg2 == 1);
+                    updateUsbNotification(mConnected);
+                    updateAdbNotification(mAdbEnabled && mConnected);
+                    if (containsFunction(mCurrentFunctions,
+                            UsbManager.USB_FUNCTION_ACCESSORY)) {
+                        updateCurrentAccessory();
+                    }
+
+                    if (!mConnected) {
+                        // restore defaults when USB is disconnected
+                        setCurrentFunctions(mDefaultFunctions);
+                    }
+                    if (mSystemReady) {
+                        updateUsbState();
+                    }
+                    break;
+                case MSG_ENABLE_ADB:
+                    setAdbEnabled(msg.arg1 == 1);
+                    break;
+                case MSG_SET_PRIMARY_FUNCTION:
+                    function = (String)msg.obj;
+                    if (function == null) {
+                        function = mDefaultFunctions;
+                    }
+                    setEnabledFunctions(function);
+                    break;
+                case MSG_SET_DEFAULT_FUNCTION:
+                    function = (String)msg.obj;
+                    if (mAdbEnabled) {
+                        function = addFunction(function, UsbManager.USB_FUNCTION_ADB);
+                    }
+                    SystemProperties.set("persist.sys.usb.config", function);
+                    mDefaultFunctions = function;
+                    break;
+                case MSG_SYSTEM_READY:
+                    updateUsbNotification(mConnected);
+                    updateAdbNotification(mAdbEnabled && mConnected);
+                    updateUsbState();
+                    if (mCurrentAccessory != null && mDeferAccessoryAttached) {
+                        mSettingsManager.accessoryAttached(mCurrentAccessory);
+                    }
+                    break;
+            }
+        }
+
+        public UsbAccessory getCurrentAccessory() {
+            return mCurrentAccessory;
+        }
+
+        public void dump(FileDescriptor fd, PrintWriter pw) {
+            pw.println("  USB Device State:");
+            pw.println("    Current Functions: " + mCurrentFunctions);
+            pw.println("    Default Functions: " + mDefaultFunctions);
+            pw.println("    mConnected: " + mConnected);
+            pw.println("    mConfigured: " + mConfigured);
+            pw.println("    mCurrentAccessory: " + mCurrentAccessory);
+        }
+    }
+
+    /* returns the currently attached USB accessory */
+    public UsbAccessory getCurrentAccessory() {
+        return mHandler.getCurrentAccessory();
+    }
+
+    /* opens the currently attached USB accessory */
+        public ParcelFileDescriptor openAccessory(UsbAccessory accessory) {
+            UsbAccessory currentAccessory = mHandler.getCurrentAccessory();
+            if (currentAccessory == null) {
+                throw new IllegalArgumentException("no accessory attached");
+            }
+            if (!currentAccessory.equals(accessory)) {
+                String error = accessory.toString()
+                        + " does not match current accessory "
+                        + currentAccessory;
+                throw new IllegalArgumentException(error);
+            }
+            mSettingsManager.checkPermission(accessory);
+            return nativeOpenAccessory();
+        }
+
+    public void setPrimaryFunction(String function) {
+        mHandler.sendMessage(MSG_SET_PRIMARY_FUNCTION, function);
+    }
+
+    public void setDefaultFunction(String function) {
+        if (function == null) {
+            throw new NullPointerException();
+        }
+        mHandler.sendMessage(MSG_SET_DEFAULT_FUNCTION, function);
+    }
+
+    public void setMassStorageBackingFile(String path) {
+        if (path == null) path = "";
+        try {
+            FileUtils.stringToFile(MASS_STORAGE_FILE_PATH, path);
+        } catch (IOException e) {
+           Slog.e(TAG, "failed to write to " + MASS_STORAGE_FILE_PATH);
+        }
+    }
+
+    public void dump(FileDescriptor fd, PrintWriter pw) {
+        if (mHandler != null) {
+            mHandler.dump(fd, pw);
+        }
+    }
+
+    private native String[] nativeGetAccessoryStrings();
+    private native ParcelFileDescriptor nativeOpenAccessory();
+}
diff --git a/services/java/com/android/server/usb/UsbDeviceSettingsManager.java b/services/java/com/android/server/usb/UsbDeviceSettingsManager.java
deleted file mode 100644
index de0b114..0000000
--- a/services/java/com/android/server/usb/UsbDeviceSettingsManager.java
+++ /dev/null
@@ -1,1015 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.server.usb;
-
-import android.app.PendingIntent;
-import android.content.ActivityNotFoundException;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.ActivityInfo;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageInfo;
-import android.content.pm.PackageManager;
-import android.content.pm.PackageManager.NameNotFoundException;
-import android.content.pm.ResolveInfo;
-import android.content.res.XmlResourceParser;
-import android.hardware.usb.UsbAccessory;
-import android.hardware.usb.UsbDevice;
-import android.hardware.usb.UsbInterface;
-import android.hardware.usb.UsbManager;
-import android.os.Binder;
-import android.os.FileUtils;
-import android.os.Process;
-import android.util.Log;
-import android.util.SparseBooleanArray;
-import android.util.Xml;
-
-import com.android.internal.content.PackageMonitor;
-import com.android.internal.util.FastXmlSerializer;
-import com.android.internal.util.XmlUtils;
-
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-import org.xmlpull.v1.XmlSerializer;
-
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileDescriptor;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-
-class UsbDeviceSettingsManager {
-
-    private static final String TAG = "UsbDeviceSettingsManager";
-    private static final File sSettingsFile = new File("/data/system/usb_device_manager.xml");
-
-    private final Context mContext;
-    private final PackageManager mPackageManager;
-
-    // Temporary mapping USB device name to list of UIDs with permissions for the device
-    private final HashMap<String, SparseBooleanArray> mDevicePermissionMap =
-            new HashMap<String, SparseBooleanArray>();
-    // Temporary mapping UsbAccessory to list of UIDs with permissions for the accessory
-    private final HashMap<UsbAccessory, SparseBooleanArray> mAccessoryPermissionMap =
-            new HashMap<UsbAccessory, SparseBooleanArray>();
-    // Maps DeviceFilter to user preferred application package
-    private final HashMap<DeviceFilter, String> mDevicePreferenceMap =
-            new HashMap<DeviceFilter, String>();
-    // Maps AccessoryFilter to user preferred application package
-    private final HashMap<AccessoryFilter, String> mAccessoryPreferenceMap =
-            new HashMap<AccessoryFilter, String>();
-
-    private final Object mLock = new Object();
-
-    // This class is used to describe a USB device.
-    // When used in HashMaps all values must be specified,
-    // but wildcards can be used for any of the fields in
-    // the package meta-data.
-    private static class DeviceFilter {
-        // USB Vendor ID (or -1 for unspecified)
-        public final int mVendorId;
-        // USB Product ID (or -1 for unspecified)
-        public final int mProductId;
-        // USB device or interface class (or -1 for unspecified)
-        public final int mClass;
-        // USB device subclass (or -1 for unspecified)
-        public final int mSubclass;
-        // USB device protocol (or -1 for unspecified)
-        public final int mProtocol;
-
-        public DeviceFilter(int vid, int pid, int clasz, int subclass, int protocol) {
-            mVendorId = vid;
-            mProductId = pid;
-            mClass = clasz;
-            mSubclass = subclass;
-            mProtocol = protocol;
-        }
-
-        public DeviceFilter(UsbDevice device) {
-            mVendorId = device.getVendorId();
-            mProductId = device.getProductId();
-            mClass = device.getDeviceClass();
-            mSubclass = device.getDeviceSubclass();
-            mProtocol = device.getDeviceProtocol();
-        }
-
-        public static DeviceFilter read(XmlPullParser parser)
-                throws XmlPullParserException, IOException {
-            int vendorId = -1;
-            int productId = -1;
-            int deviceClass = -1;
-            int deviceSubclass = -1;
-            int deviceProtocol = -1;
-
-            int count = parser.getAttributeCount();
-            for (int i = 0; i < count; i++) {
-                String name = parser.getAttributeName(i);
-                // All attribute values are ints
-                int value = Integer.parseInt(parser.getAttributeValue(i));
-
-                if ("vendor-id".equals(name)) {
-                    vendorId = value;
-                } else if ("product-id".equals(name)) {
-                    productId = value;
-                } else if ("class".equals(name)) {
-                    deviceClass = value;
-                } else if ("subclass".equals(name)) {
-                    deviceSubclass = value;
-                } else if ("protocol".equals(name)) {
-                    deviceProtocol = value;
-                }
-            }
-            return new DeviceFilter(vendorId, productId,
-                    deviceClass, deviceSubclass, deviceProtocol);
-        }
-
-        public void write(XmlSerializer serializer) throws IOException {
-            serializer.startTag(null, "usb-device");
-            if (mVendorId != -1) {
-                serializer.attribute(null, "vendor-id", Integer.toString(mVendorId));
-            }
-            if (mProductId != -1) {
-                serializer.attribute(null, "product-id", Integer.toString(mProductId));
-            }
-            if (mClass != -1) {
-                serializer.attribute(null, "class", Integer.toString(mClass));
-            }
-            if (mSubclass != -1) {
-                serializer.attribute(null, "subclass", Integer.toString(mSubclass));
-            }
-            if (mProtocol != -1) {
-                serializer.attribute(null, "protocol", Integer.toString(mProtocol));
-            }
-            serializer.endTag(null, "usb-device");
-        }
-
-        private boolean matches(int clasz, int subclass, int protocol) {
-            return ((mClass == -1 || clasz == mClass) &&
-                    (mSubclass == -1 || subclass == mSubclass) &&
-                    (mProtocol == -1 || protocol == mProtocol));
-        }
-
-        public boolean matches(UsbDevice device) {
-            if (mVendorId != -1 && device.getVendorId() != mVendorId) return false;
-            if (mProductId != -1 && device.getProductId() != mProductId) return false;
-
-            // check device class/subclass/protocol
-            if (matches(device.getDeviceClass(), device.getDeviceSubclass(),
-                    device.getDeviceProtocol())) return true;
-
-            // if device doesn't match, check the interfaces
-            int count = device.getInterfaceCount();
-            for (int i = 0; i < count; i++) {
-                UsbInterface intf = device.getInterface(i);
-                 if (matches(intf.getInterfaceClass(), intf.getInterfaceSubclass(),
-                        intf.getInterfaceProtocol())) return true;
-            }
-
-            return false;
-        }
-
-        public boolean matches(DeviceFilter f) {
-            if (mVendorId != -1 && f.mVendorId != mVendorId) return false;
-            if (mProductId != -1 && f.mProductId != mProductId) return false;
-
-            // check device class/subclass/protocol
-            return matches(f.mClass, f.mSubclass, f.mProtocol);
-        }
-
-        @Override
-        public boolean equals(Object obj) {
-            // can't compare if we have wildcard strings
-            if (mVendorId == -1 || mProductId == -1 ||
-                    mClass == -1 || mSubclass == -1 || mProtocol == -1) {
-                return false;
-            }
-            if (obj instanceof DeviceFilter) {
-                DeviceFilter filter = (DeviceFilter)obj;
-                return (filter.mVendorId == mVendorId &&
-                        filter.mProductId == mProductId &&
-                        filter.mClass == mClass &&
-                        filter.mSubclass == mSubclass &&
-                        filter.mProtocol == mProtocol);
-            }
-            if (obj instanceof UsbDevice) {
-                UsbDevice device = (UsbDevice)obj;
-                return (device.getVendorId() == mVendorId &&
-                        device.getProductId() == mProductId &&
-                        device.getDeviceClass() == mClass &&
-                        device.getDeviceSubclass() == mSubclass &&
-                        device.getDeviceProtocol() == mProtocol);
-            }
-            return false;
-        }
-
-        @Override
-        public int hashCode() {
-            return (((mVendorId << 16) | mProductId) ^
-                    ((mClass << 16) | (mSubclass << 8) | mProtocol));
-        }
-
-        @Override
-        public String toString() {
-            return "DeviceFilter[mVendorId=" + mVendorId + ",mProductId=" + mProductId +
-                    ",mClass=" + mClass + ",mSubclass=" + mSubclass +
-                    ",mProtocol=" + mProtocol + "]";
-        }
-    }
-
-    // This class is used to describe a USB accessory.
-    // When used in HashMaps all values must be specified,
-    // but wildcards can be used for any of the fields in
-    // the package meta-data.
-    private static class AccessoryFilter {
-        // USB accessory manufacturer (or null for unspecified)
-        public final String mManufacturer;
-        // USB accessory model (or null for unspecified)
-        public final String mModel;
-        // USB accessory version (or null for unspecified)
-        public final String mVersion;
-
-        public AccessoryFilter(String manufacturer, String model, String version) {
-            mManufacturer = manufacturer;
-            mModel = model;
-            mVersion = version;
-        }
-
-        public AccessoryFilter(UsbAccessory accessory) {
-            mManufacturer = accessory.getManufacturer();
-            mModel = accessory.getModel();
-            mVersion = accessory.getVersion();
-        }
-
-        public static AccessoryFilter read(XmlPullParser parser)
-                throws XmlPullParserException, IOException {
-            String manufacturer = null;
-            String model = null;
-            String version = null;
-
-            int count = parser.getAttributeCount();
-            for (int i = 0; i < count; i++) {
-                String name = parser.getAttributeName(i);
-                String value = parser.getAttributeValue(i);
-
-                if ("manufacturer".equals(name)) {
-                    manufacturer = value;
-                } else if ("model".equals(name)) {
-                    model = value;
-                } else if ("version".equals(name)) {
-                    version = value;
-                }
-             }
-             return new AccessoryFilter(manufacturer, model, version);
-        }
-
-        public void write(XmlSerializer serializer)throws IOException {
-            serializer.startTag(null, "usb-accessory");
-            if (mManufacturer != null) {
-                serializer.attribute(null, "manufacturer", mManufacturer);
-            }
-            if (mModel != null) {
-                serializer.attribute(null, "model", mModel);
-            }
-            if (mVersion != null) {
-                serializer.attribute(null, "version", mVersion);
-            }
-            serializer.endTag(null, "usb-accessory");
-        }
-
-        public boolean matches(UsbAccessory acc) {
-            if (mManufacturer != null && !acc.getManufacturer().equals(mManufacturer)) return false;
-            if (mModel != null && !acc.getModel().equals(mModel)) return false;
-            if (mVersion != null && !acc.getVersion().equals(mVersion)) return false;
-            return true;
-        }
-
-        public boolean matches(AccessoryFilter f) {
-            if (mManufacturer != null && !f.mManufacturer.equals(mManufacturer)) return false;
-            if (mModel != null && !f.mModel.equals(mModel)) return false;
-            if (mVersion != null && !f.mVersion.equals(mVersion)) return false;
-            return true;
-        }
-
-        @Override
-        public boolean equals(Object obj) {
-            // can't compare if we have wildcard strings
-            if (mManufacturer == null || mModel == null || mVersion == null) {
-                return false;
-            }
-            if (obj instanceof AccessoryFilter) {
-                AccessoryFilter filter = (AccessoryFilter)obj;
-                return (mManufacturer.equals(filter.mManufacturer) &&
-                        mModel.equals(filter.mModel) &&
-                        mVersion.equals(filter.mVersion));
-            }
-            if (obj instanceof UsbAccessory) {
-                UsbAccessory accessory = (UsbAccessory)obj;
-                return (mManufacturer.equals(accessory.getManufacturer()) &&
-                        mModel.equals(accessory.getModel()) &&
-                        mVersion.equals(accessory.getVersion()));
-            }
-            return false;
-        }
-
-        @Override
-        public int hashCode() {
-            return ((mManufacturer == null ? 0 : mManufacturer.hashCode()) ^
-                    (mModel == null ? 0 : mModel.hashCode()) ^
-                    (mVersion == null ? 0 : mVersion.hashCode()));
-        }
-
-        @Override
-        public String toString() {
-            return "AccessoryFilter[mManufacturer=\"" + mManufacturer +
-                                "\", mModel=\"" + mModel +
-                                "\", mVersion=\"" + mVersion + "\"]";
-        }
-    }
-
-    private class MyPackageMonitor extends PackageMonitor {
-
-        public void onPackageAdded(String packageName, int uid) {
-            handlePackageUpdate(packageName);
-        }
-
-        public void onPackageChanged(String packageName, int uid, String[] components) {
-            handlePackageUpdate(packageName);
-        }
-
-        public void onPackageRemoved(String packageName, int uid) {
-            clearDefaults(packageName);
-        }
-    }
-    MyPackageMonitor mPackageMonitor = new MyPackageMonitor();
-
-    public UsbDeviceSettingsManager(Context context) {
-        mContext = context;
-        mPackageManager = context.getPackageManager();
-        synchronized (mLock) {
-            readSettingsLocked();
-        }
-        mPackageMonitor.register(context, true);
-    }
-
-    private void readPreference(XmlPullParser parser)
-            throws XmlPullParserException, IOException {
-        String packageName = null;
-        int count = parser.getAttributeCount();
-        for (int i = 0; i < count; i++) {
-            if ("package".equals(parser.getAttributeName(i))) {
-                packageName = parser.getAttributeValue(i);
-                break;
-            }
-        }
-        XmlUtils.nextElement(parser);
-        if ("usb-device".equals(parser.getName())) {
-            DeviceFilter filter = DeviceFilter.read(parser);
-            mDevicePreferenceMap.put(filter, packageName);
-        } else if ("usb-accessory".equals(parser.getName())) {
-            AccessoryFilter filter = AccessoryFilter.read(parser);
-            mAccessoryPreferenceMap.put(filter, packageName);
-        }
-        XmlUtils.nextElement(parser);
-    }
-
-    private void readSettingsLocked() {
-        FileInputStream stream = null;
-        try {
-            stream = new FileInputStream(sSettingsFile);
-            XmlPullParser parser = Xml.newPullParser();
-            parser.setInput(stream, null);
-
-            XmlUtils.nextElement(parser);
-            while (parser.getEventType() != XmlPullParser.END_DOCUMENT) {
-                String tagName = parser.getName();
-                if ("preference".equals(tagName)) {
-                    readPreference(parser);
-                 } else {
-                    XmlUtils.nextElement(parser);
-                }
-            }
-        } catch (FileNotFoundException e) {
-            Log.w(TAG, "settings file not found");
-        } catch (Exception e) {
-            Log.e(TAG, "error reading settings file, deleting to start fresh", e);
-            sSettingsFile.delete();
-        } finally {
-            if (stream != null) {
-                try {
-                    stream.close();
-                } catch (IOException e) {
-                }
-            }
-        }
-    }
-
-    private void writeSettingsLocked() {
-        FileOutputStream fos = null;
-        try {
-            FileOutputStream fstr = new FileOutputStream(sSettingsFile);
-            Log.d(TAG, "writing settings to " + fstr);
-            BufferedOutputStream str = new BufferedOutputStream(fstr);
-            FastXmlSerializer serializer = new FastXmlSerializer();
-            serializer.setOutput(str, "utf-8");
-            serializer.startDocument(null, true);
-            serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
-            serializer.startTag(null, "settings");
-
-            for (DeviceFilter filter : mDevicePreferenceMap.keySet()) {
-                serializer.startTag(null, "preference");
-                serializer.attribute(null, "package", mDevicePreferenceMap.get(filter));
-                filter.write(serializer);
-                serializer.endTag(null, "preference");
-            }
-
-            for (AccessoryFilter filter : mAccessoryPreferenceMap.keySet()) {
-                serializer.startTag(null, "preference");
-                serializer.attribute(null, "package", mAccessoryPreferenceMap.get(filter));
-                filter.write(serializer);
-                serializer.endTag(null, "preference");
-            }
-
-            serializer.endTag(null, "settings");
-            serializer.endDocument();
-
-            str.flush();
-            FileUtils.sync(fstr);
-            str.close();
-        } catch (Exception e) {
-            Log.e(TAG, "error writing settings file, deleting to start fresh", e);
-            sSettingsFile.delete();
-        }
-    }
-
-    // Checks to see if a package matches a device or accessory.
-    // Only one of device and accessory should be non-null.
-    private boolean packageMatchesLocked(ResolveInfo info, String metaDataName,
-            UsbDevice device, UsbAccessory accessory) {
-        ActivityInfo ai = info.activityInfo;
-
-        XmlResourceParser parser = null;
-        try {
-            parser = ai.loadXmlMetaData(mPackageManager, metaDataName);
-            if (parser == null) {
-                Log.w(TAG, "no meta-data for " + info);
-                return false;
-            }
-
-            XmlUtils.nextElement(parser);
-            while (parser.getEventType() != XmlPullParser.END_DOCUMENT) {
-                String tagName = parser.getName();
-                if (device != null && "usb-device".equals(tagName)) {
-                    DeviceFilter filter = DeviceFilter.read(parser);
-                    if (filter.matches(device)) {
-                        return true;
-                    }
-                }
-                else if (accessory != null && "usb-accessory".equals(tagName)) {
-                    AccessoryFilter filter = AccessoryFilter.read(parser);
-                    if (filter.matches(accessory)) {
-                        return true;
-                    }
-                }
-                XmlUtils.nextElement(parser);
-            }
-        } catch (Exception e) {
-            Log.w(TAG, "Unable to load component info " + info.toString(), e);
-        } finally {
-            if (parser != null) parser.close();
-        }
-        return false;
-    }
-
-    private final ArrayList<ResolveInfo> getDeviceMatchesLocked(UsbDevice device, Intent intent) {
-        ArrayList<ResolveInfo> matches = new ArrayList<ResolveInfo>();
-        List<ResolveInfo> resolveInfos = mPackageManager.queryIntentActivities(intent,
-                PackageManager.GET_META_DATA);
-        int count = resolveInfos.size();
-        for (int i = 0; i < count; i++) {
-            ResolveInfo resolveInfo = resolveInfos.get(i);
-            if (packageMatchesLocked(resolveInfo, intent.getAction(), device, null)) {
-                matches.add(resolveInfo);
-            }
-        }
-        return matches;
-    }
-
-    private final ArrayList<ResolveInfo> getAccessoryMatchesLocked(
-            UsbAccessory accessory, Intent intent) {
-        ArrayList<ResolveInfo> matches = new ArrayList<ResolveInfo>();
-        List<ResolveInfo> resolveInfos = mPackageManager.queryIntentActivities(intent,
-                PackageManager.GET_META_DATA);
-        int count = resolveInfos.size();
-        for (int i = 0; i < count; i++) {
-            ResolveInfo resolveInfo = resolveInfos.get(i);
-            if (packageMatchesLocked(resolveInfo, intent.getAction(), null, accessory)) {
-                matches.add(resolveInfo);
-            }
-        }
-        return matches;
-    }
-
-    public void deviceAttached(UsbDevice device) {
-        Intent intent = new Intent(UsbManager.ACTION_USB_DEVICE_ATTACHED);
-        intent.putExtra(UsbManager.EXTRA_DEVICE, device);
-        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-
-        ArrayList<ResolveInfo> matches;
-        String defaultPackage;
-        synchronized (mLock) {
-            matches = getDeviceMatchesLocked(device, intent);
-            // Launch our default activity directly, if we have one.
-            // Otherwise we will start the UsbResolverActivity to allow the user to choose.
-            defaultPackage = mDevicePreferenceMap.get(new DeviceFilter(device));
-        }
-
-        resolveActivity(intent, matches, defaultPackage, device, null);
-    }
-
-    public void deviceDetached(UsbDevice device) {
-        // clear temporary permissions for the device
-        mDevicePermissionMap.remove(device.getDeviceName());
-
-        Intent intent = new Intent(UsbManager.ACTION_USB_DEVICE_DETACHED);
-        intent.putExtra(UsbManager.EXTRA_DEVICE, device);
-        Log.d(TAG, "usbDeviceRemoved, sending " + intent);
-        mContext.sendBroadcast(intent);
-    }
-
-    public void accessoryAttached(UsbAccessory accessory) {
-        Intent intent = new Intent(UsbManager.ACTION_USB_ACCESSORY_ATTACHED);
-        intent.putExtra(UsbManager.EXTRA_ACCESSORY, accessory);
-        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-
-        ArrayList<ResolveInfo> matches;
-        String defaultPackage;
-        synchronized (mLock) {
-            matches = getAccessoryMatchesLocked(accessory, intent);
-            // Launch our default activity directly, if we have one.
-            // Otherwise we will start the UsbResolverActivity to allow the user to choose.
-            defaultPackage = mAccessoryPreferenceMap.get(new AccessoryFilter(accessory));
-        }
-
-        resolveActivity(intent, matches, defaultPackage, null, accessory);
-    }
-
-    public void accessoryDetached(UsbAccessory accessory) {
-        // clear temporary permissions for the accessory
-        mAccessoryPermissionMap.remove(accessory);
-
-        Intent intent = new Intent(
-                UsbManager.ACTION_USB_ACCESSORY_DETACHED);
-        intent.putExtra(UsbManager.EXTRA_ACCESSORY, accessory);
-        mContext.sendBroadcast(intent);
-    }
-
-    private void resolveActivity(Intent intent, ArrayList<ResolveInfo> matches,
-            String defaultPackage, UsbDevice device, UsbAccessory accessory) {
-        int count = matches.size();
-
-        // don't show the resolver activity if there are no choices available
-        if (count == 0) {
-            if (accessory != null) {
-                String uri = accessory.getUri();
-                if (uri != null && uri.length() > 0) {
-                    // display URI to user
-                    // start UsbResolverActivity so user can choose an activity
-                    Intent dialogIntent = new Intent();
-                    dialogIntent.setClassName("com.android.systemui",
-                            "com.android.systemui.usb.UsbAccessoryUriActivity");
-                    dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-                    dialogIntent.putExtra(UsbManager.EXTRA_ACCESSORY, accessory);
-                    dialogIntent.putExtra("uri", uri);
-                    try {
-                        mContext.startActivity(dialogIntent);
-                    } catch (ActivityNotFoundException e) {
-                        Log.e(TAG, "unable to start UsbAccessoryUriActivity");
-                    }
-                }
-            }
-
-            // do nothing
-            return;
-        }
-
-        ResolveInfo defaultRI = null;
-        if (count == 1 && defaultPackage == null) {
-            // Check to see if our single choice is on the system partition.
-            // If so, treat it as our default without calling UsbResolverActivity
-            ResolveInfo rInfo = matches.get(0);
-            if (rInfo.activityInfo != null &&
-                    rInfo.activityInfo.applicationInfo != null &&
-                    (rInfo.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
-                defaultRI = rInfo;
-            }
-        }
-
-        if (defaultRI == null && defaultPackage != null) {
-            // look for default activity
-            for (int i = 0; i < count; i++) {
-                ResolveInfo rInfo = matches.get(i);
-                if (rInfo.activityInfo != null &&
-                        defaultPackage.equals(rInfo.activityInfo.packageName)) {
-                    defaultRI = rInfo;
-                    break;
-                }
-            }
-        }
-
-        if (defaultRI != null) {
-            // grant permission for default activity
-            if (device != null) {
-                grantDevicePermission(device, defaultRI.activityInfo.applicationInfo.uid);
-            } else if (accessory != null) {
-                grantAccessoryPermission(accessory, defaultRI.activityInfo.applicationInfo.uid);
-            }
-
-            // start default activity directly
-            try {
-                intent.setComponent(
-                        new ComponentName(defaultRI.activityInfo.packageName,
-                                defaultRI.activityInfo.name));
-                mContext.startActivity(intent);
-            } catch (ActivityNotFoundException e) {
-                Log.e(TAG, "startActivity failed", e);
-            }
-        } else {
-            Intent resolverIntent = new Intent();
-            resolverIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-
-            if (count == 1) {
-                // start UsbConfirmActivity if there is only one choice
-                resolverIntent.setClassName("com.android.systemui",
-                        "com.android.systemui.usb.UsbConfirmActivity");
-                resolverIntent.putExtra("rinfo", matches.get(0));
-
-                if (device != null) {
-                    resolverIntent.putExtra(UsbManager.EXTRA_DEVICE, device);
-                } else {
-                    resolverIntent.putExtra(UsbManager.EXTRA_ACCESSORY, accessory);
-                }
-            } else {
-                // start UsbResolverActivity so user can choose an activity
-                resolverIntent.setClassName("com.android.systemui",
-                        "com.android.systemui.usb.UsbResolverActivity");
-                resolverIntent.putParcelableArrayListExtra("rlist", matches);
-                resolverIntent.putExtra(Intent.EXTRA_INTENT, intent);
-            }
-            try {
-                mContext.startActivity(resolverIntent);
-            } catch (ActivityNotFoundException e) {
-                Log.e(TAG, "unable to start activity " + resolverIntent);
-            }
-        }
-    }
-
-    private boolean clearCompatibleMatchesLocked(String packageName, DeviceFilter filter) {
-        boolean changed = false;
-        for (DeviceFilter test : mDevicePreferenceMap.keySet()) {
-            if (filter.matches(test)) {
-                mDevicePreferenceMap.remove(test);
-                changed = true;
-            }
-        }
-        return changed;
-    }
-
-    private boolean clearCompatibleMatchesLocked(String packageName, AccessoryFilter filter) {
-        boolean changed = false;
-        for (AccessoryFilter test : mAccessoryPreferenceMap.keySet()) {
-            if (filter.matches(test)) {
-                mAccessoryPreferenceMap.remove(test);
-                changed = true;
-            }
-        }
-        return changed;
-    }
-
-    private boolean handlePackageUpdateLocked(String packageName, ActivityInfo aInfo,
-            String metaDataName) {
-        XmlResourceParser parser = null;
-        boolean changed = false;
-
-        try {
-            parser = aInfo.loadXmlMetaData(mPackageManager, metaDataName);
-            if (parser == null) return false;
-
-            XmlUtils.nextElement(parser);
-            while (parser.getEventType() != XmlPullParser.END_DOCUMENT) {
-                String tagName = parser.getName();
-                if ("usb-device".equals(tagName)) {
-                    DeviceFilter filter = DeviceFilter.read(parser);
-                    if (clearCompatibleMatchesLocked(packageName, filter)) {
-                        changed = true;
-                    }
-                }
-                else if ("usb-accessory".equals(tagName)) {
-                    AccessoryFilter filter = AccessoryFilter.read(parser);
-                    if (clearCompatibleMatchesLocked(packageName, filter)) {
-                        changed = true;
-                    }
-                }
-                XmlUtils.nextElement(parser);
-            }
-        } catch (Exception e) {
-            Log.w(TAG, "Unable to load component info " + aInfo.toString(), e);
-        } finally {
-            if (parser != null) parser.close();
-        }
-        return changed;
-    }
-
-    // Check to see if the package supports any USB devices or accessories.
-    // If so, clear any non-matching preferences for matching devices/accessories.
-    private void handlePackageUpdate(String packageName) {
-        synchronized (mLock) {
-            PackageInfo info;
-            boolean changed = false;
-
-            try {
-                info = mPackageManager.getPackageInfo(packageName,
-                        PackageManager.GET_ACTIVITIES | PackageManager.GET_META_DATA);
-            } catch (NameNotFoundException e) {
-                Log.e(TAG, "handlePackageUpdate could not find package " + packageName, e);
-                return;
-            }
-
-            ActivityInfo[] activities = info.activities;
-            if (activities == null) return;
-            for (int i = 0; i < activities.length; i++) {
-                // check for meta-data, both for devices and accessories
-                if (handlePackageUpdateLocked(packageName, activities[i],
-                        UsbManager.ACTION_USB_DEVICE_ATTACHED)) {
-                    changed = true;
-                }
-                if (handlePackageUpdateLocked(packageName, activities[i],
-                        UsbManager.ACTION_USB_ACCESSORY_ATTACHED)) {
-                    changed = true;
-                }
-            }
-
-            if (changed) {
-                writeSettingsLocked();
-            }
-        }
-    }
-
-    public boolean hasPermission(UsbDevice device) {
-        synchronized (mLock) {
-            SparseBooleanArray uidList = mDevicePermissionMap.get(device.getDeviceName());
-            if (uidList == null) {
-                return false;
-            }
-            return uidList.get(Binder.getCallingUid());
-        }
-    }
-
-    public boolean hasPermission(UsbAccessory accessory) {
-        synchronized (mLock) {
-            SparseBooleanArray uidList = mAccessoryPermissionMap.get(accessory);
-            if (uidList == null) {
-                return false;
-            }
-            return uidList.get(Binder.getCallingUid());
-        }
-    }
-
-    public void checkPermission(UsbDevice device) {
-        if (!hasPermission(device)) {
-            throw new SecurityException("User has not given permission to device " + device);
-        }
-    }
-
-    public void checkPermission(UsbAccessory accessory) {
-        if (!hasPermission(accessory)) {
-            throw new SecurityException("User has not given permission to accessory " + accessory);
-        }
-    }
-
-    private void requestPermissionDialog(Intent intent, String packageName, PendingIntent pi) {
-        int uid = Binder.getCallingUid();
-
-        // compare uid with packageName to foil apps pretending to be someone else
-        try {
-            ApplicationInfo aInfo = mPackageManager.getApplicationInfo(packageName, 0);
-            if (aInfo.uid != uid) {
-                throw new IllegalArgumentException("package " + packageName +
-                        " does not match caller's uid " + uid);
-            }
-        } catch (PackageManager.NameNotFoundException e) {
-            throw new IllegalArgumentException("package " + packageName + " not found");
-        }
-
-        long identity = Binder.clearCallingIdentity();
-        intent.setClassName("com.android.systemui",
-                "com.android.systemui.usb.UsbPermissionActivity");
-        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-        intent.putExtra(Intent.EXTRA_INTENT, pi);
-        intent.putExtra("package", packageName);
-        intent.putExtra("uid", uid);
-        try {
-            mContext.startActivity(intent);
-        } catch (ActivityNotFoundException e) {
-            Log.e(TAG, "unable to start UsbPermissionActivity");
-        } finally {
-            Binder.restoreCallingIdentity(identity);
-        }
-    }
-
-    public void requestPermission(UsbDevice device, String packageName, PendingIntent pi) {
-      Intent intent = new Intent();
-
-        // respond immediately if permission has already been granted
-      if (hasPermission(device)) {
-            intent.putExtra(UsbManager.EXTRA_DEVICE, device);
-            intent.putExtra(UsbManager.EXTRA_PERMISSION_GRANTED, true);
-            try {
-                pi.send(mContext, 0, intent);
-            } catch (PendingIntent.CanceledException e) {
-                Log.w(TAG, "requestPermission PendingIntent was cancelled");
-            }
-            return;
-        }
-
-        // start UsbPermissionActivity so user can choose an activity
-        intent.putExtra(UsbManager.EXTRA_DEVICE, device);
-        requestPermissionDialog(intent, packageName, pi);
-    }
-
-    public void requestPermission(UsbAccessory accessory, String packageName, PendingIntent pi) {
-      Intent intent = new Intent();
-
-        // respond immediately if permission has already been granted
-        if (hasPermission(accessory)) {
-            intent.putExtra(UsbManager.EXTRA_ACCESSORY, accessory);
-            intent.putExtra(UsbManager.EXTRA_PERMISSION_GRANTED, true);
-           try {
-                pi.send(mContext, 0, intent);
-            } catch (PendingIntent.CanceledException e) {
-                Log.w(TAG, "requestPermission PendingIntent was cancelled");
-            }
-            return;
-        }
-
-        intent.putExtra(UsbManager.EXTRA_ACCESSORY, accessory);
-        requestPermissionDialog(intent, packageName, pi);
-    }
-
-    public void setDevicePackage(UsbDevice device, String packageName) {
-        DeviceFilter filter = new DeviceFilter(device);
-        boolean changed = false;
-        synchronized (mLock) {
-            if (packageName == null) {
-                changed = (mDevicePreferenceMap.remove(filter) != null);
-            } else {
-                changed = !packageName.equals(mDevicePreferenceMap.get(filter));
-                if (changed) {
-                    mDevicePreferenceMap.put(filter, packageName);
-                }
-            }
-            if (changed) {
-                writeSettingsLocked();
-            }
-        }
-    }
-
-    public void setAccessoryPackage(UsbAccessory accessory, String packageName) {
-        AccessoryFilter filter = new AccessoryFilter(accessory);
-        boolean changed = false;
-        synchronized (mLock) {
-            if (packageName == null) {
-                changed = (mAccessoryPreferenceMap.remove(filter) != null);
-            } else {
-                changed = !packageName.equals(mAccessoryPreferenceMap.get(filter));
-                if (changed) {
-                    mAccessoryPreferenceMap.put(filter, packageName);
-                }
-            }
-            if (changed) {
-                writeSettingsLocked();
-            }
-        }
-    }
-
-    public void grantDevicePermission(UsbDevice device, int uid) {
-        synchronized (mLock) {
-            String deviceName = device.getDeviceName();
-            SparseBooleanArray uidList = mDevicePermissionMap.get(deviceName);
-            if (uidList == null) {
-                uidList = new SparseBooleanArray(1);
-                mDevicePermissionMap.put(deviceName, uidList);
-            }
-            uidList.put(uid, true);
-        }
-    }
-
-    public void grantAccessoryPermission(UsbAccessory accessory, int uid) {
-        synchronized (mLock) {
-            SparseBooleanArray uidList = mAccessoryPermissionMap.get(accessory);
-            if (uidList == null) {
-                uidList = new SparseBooleanArray(1);
-                mAccessoryPermissionMap.put(accessory, uidList);
-            }
-            uidList.put(uid, true);
-        }
-    }
-
-    public boolean hasDefaults(String packageName) {
-        synchronized (mLock) {
-            if (mDevicePreferenceMap.values().contains(packageName)) return true;
-            if (mAccessoryPreferenceMap.values().contains(packageName)) return true;
-            return false;
-        }
-    }
-
-    public void clearDefaults(String packageName) {
-        synchronized (mLock) {
-            if (clearPackageDefaultsLocked(packageName)) {
-                writeSettingsLocked();
-            }
-        }
-    }
-
-    private boolean clearPackageDefaultsLocked(String packageName) {
-        boolean cleared = false;
-        synchronized (mLock) {
-            if (mDevicePreferenceMap.containsValue(packageName)) {
-                // make a copy of the key set to avoid ConcurrentModificationException
-                Object[] keys = mDevicePreferenceMap.keySet().toArray();
-                for (int i = 0; i < keys.length; i++) {
-                    Object key = keys[i];
-                    if (packageName.equals(mDevicePreferenceMap.get(key))) {
-                        mDevicePreferenceMap.remove(key);
-                        cleared = true;
-                    }
-                }
-            }
-            if (mAccessoryPreferenceMap.containsValue(packageName)) {
-                // make a copy of the key set to avoid ConcurrentModificationException
-                Object[] keys = mAccessoryPreferenceMap.keySet().toArray();
-                for (int i = 0; i < keys.length; i++) {
-                    Object key = keys[i];
-                    if (packageName.equals(mAccessoryPreferenceMap.get(key))) {
-                        mAccessoryPreferenceMap.remove(key);
-                        cleared = true;
-                    }
-                }
-            }
-            return cleared;
-        }
-    }
-
-    public void dump(FileDescriptor fd, PrintWriter pw) {
-        synchronized (mLock) {
-            pw.println("  Device permissions:");
-            for (String deviceName : mDevicePermissionMap.keySet()) {
-                pw.print("    " + deviceName + ": ");
-                SparseBooleanArray uidList = mDevicePermissionMap.get(deviceName);
-                int count = uidList.size();
-                for (int i = 0; i < count; i++) {
-                    pw.print(Integer.toString(uidList.keyAt(i)) + " ");
-                }
-                pw.println("");
-            }
-            pw.println("  Accessory permissions:");
-            for (UsbAccessory accessory : mAccessoryPermissionMap.keySet()) {
-                pw.print("    " + accessory + ": ");
-                SparseBooleanArray uidList = mAccessoryPermissionMap.get(accessory);
-                int count = uidList.size();
-                for (int i = 0; i < count; i++) {
-                    pw.print(Integer.toString(uidList.keyAt(i)) + " ");
-                }
-                pw.println("");
-            }
-            pw.println("  Device preferences:");
-            for (DeviceFilter filter : mDevicePreferenceMap.keySet()) {
-                pw.println("    " + filter + ": " + mDevicePreferenceMap.get(filter));
-            }
-            pw.println("  Accessory preferences:");
-            for (AccessoryFilter filter : mAccessoryPreferenceMap.keySet()) {
-                pw.println("    " + filter + ": " + mAccessoryPreferenceMap.get(filter));
-            }
-        }
-    }
-}
diff --git a/services/java/com/android/server/usb/UsbHostManager.java b/services/java/com/android/server/usb/UsbHostManager.java
new file mode 100644
index 0000000..923b049
--- /dev/null
+++ b/services/java/com/android/server/usb/UsbHostManager.java
@@ -0,0 +1,222 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions an
+ * limitations under the License.
+ */
+
+package com.android.server.usb;
+
+import android.app.PendingIntent;
+import android.content.BroadcastReceiver;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.hardware.usb.IUsbManager;
+import android.hardware.usb.UsbConstants;
+import android.hardware.usb.UsbDevice;
+import android.hardware.usb.UsbEndpoint;
+import android.hardware.usb.UsbInterface;
+import android.hardware.usb.UsbManager;
+import android.net.Uri;
+import android.os.Binder;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.os.Parcelable;
+import android.os.ParcelFileDescriptor;
+import android.os.UEventObserver;
+import android.provider.Settings;
+import android.util.Log;
+import android.util.Slog;
+
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.FileReader;
+import java.io.PrintWriter;
+import java.util.HashMap;
+import java.util.List;
+
+/**
+ * UsbHostManager manages USB state in host mode.
+ */
+public class UsbHostManager {
+    private static final String TAG = UsbHostManager.class.getSimpleName();
+    private static final boolean LOG = false;
+
+    // contains all connected USB devices
+    private final HashMap<String,UsbDevice> mDevices = new HashMap<String,UsbDevice>();
+
+    // USB busses to exclude from USB host support
+    private final String[] mHostBlacklist;
+
+    private final Context mContext;
+    private final Object mLock = new Object();
+    private final UsbSettingsManager mSettingsManager;
+
+    public UsbHostManager(Context context, UsbSettingsManager settingsManager) {
+        mContext = context;
+        mSettingsManager = settingsManager;
+        mHostBlacklist = context.getResources().getStringArray(
+                com.android.internal.R.array.config_usbHostBlacklist);
+    }
+
+    private boolean isBlackListed(String deviceName) {
+        int count = mHostBlacklist.length;
+        for (int i = 0; i < count; i++) {
+            if (deviceName.startsWith(mHostBlacklist[i])) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /* returns true if the USB device should not be accessible by applications */
+    private boolean isBlackListed(int clazz, int subClass, int protocol) {
+        // blacklist hubs
+        if (clazz == UsbConstants.USB_CLASS_HUB) return true;
+
+        // blacklist HID boot devices (mouse and keyboard)
+        if (clazz == UsbConstants.USB_CLASS_HID &&
+                subClass == UsbConstants.USB_INTERFACE_SUBCLASS_BOOT) {
+            return true;
+        }
+
+        return false;
+    }
+
+    /* Called from JNI in monitorUsbHostBus() to report new USB devices */
+    private void usbDeviceAdded(String deviceName, int vendorID, int productID,
+            int deviceClass, int deviceSubclass, int deviceProtocol,
+            /* array of quintuples containing id, class, subclass, protocol
+               and number of endpoints for each interface */
+            int[] interfaceValues,
+           /* array of quadruples containing address, attributes, max packet size
+              and interval for each endpoint */
+            int[] endpointValues) {
+
+        if (isBlackListed(deviceName) ||
+                isBlackListed(deviceClass, deviceSubclass, deviceProtocol)) {
+            return;
+        }
+
+        synchronized (mLock) {
+            if (mDevices.get(deviceName) != null) {
+                Log.w(TAG, "device already on mDevices list: " + deviceName);
+                return;
+            }
+
+            int numInterfaces = interfaceValues.length / 5;
+            Parcelable[] interfaces = new UsbInterface[numInterfaces];
+            try {
+                // repackage interfaceValues as an array of UsbInterface
+                int intf, endp, ival = 0, eval = 0;
+                for (intf = 0; intf < numInterfaces; intf++) {
+                    int interfaceId = interfaceValues[ival++];
+                    int interfaceClass = interfaceValues[ival++];
+                    int interfaceSubclass = interfaceValues[ival++];
+                    int interfaceProtocol = interfaceValues[ival++];
+                    int numEndpoints = interfaceValues[ival++];
+
+                    Parcelable[] endpoints = new UsbEndpoint[numEndpoints];
+                    for (endp = 0; endp < numEndpoints; endp++) {
+                        int address = endpointValues[eval++];
+                        int attributes = endpointValues[eval++];
+                        int maxPacketSize = endpointValues[eval++];
+                        int interval = endpointValues[eval++];
+                        endpoints[endp] = new UsbEndpoint(address, attributes,
+                                maxPacketSize, interval);
+                    }
+
+                    // don't allow if any interfaces are blacklisted
+                    if (isBlackListed(interfaceClass, interfaceSubclass, interfaceProtocol)) {
+                        return;
+                    }
+                    interfaces[intf] = new UsbInterface(interfaceId, interfaceClass,
+                            interfaceSubclass, interfaceProtocol, endpoints);
+                }
+            } catch (Exception e) {
+                // beware of index out of bound exceptions, which might happen if
+                // a device does not set bNumEndpoints correctly
+                Log.e(TAG, "error parsing USB descriptors", e);
+                return;
+            }
+
+            UsbDevice device = new UsbDevice(deviceName, vendorID, productID,
+                    deviceClass, deviceSubclass, deviceProtocol, interfaces);
+            mDevices.put(deviceName, device);
+            mSettingsManager.deviceAttached(device);
+        }
+    }
+
+    /* Called from JNI in monitorUsbHostBus to report USB device removal */
+    private void usbDeviceRemoved(String deviceName) {
+        synchronized (mLock) {
+            UsbDevice device = mDevices.remove(deviceName);
+            if (device != null) {
+                mSettingsManager.deviceDetached(device);
+            }
+        }
+    }
+
+    public void systemReady() {
+        synchronized (mLock) {
+            // Create a thread to call into native code to wait for USB host events.
+            // This thread will call us back on usbDeviceAdded and usbDeviceRemoved.
+            Runnable runnable = new Runnable() {
+                public void run() {
+                    monitorUsbHostBus();
+                }
+            };
+            new Thread(null, runnable, "UsbService host thread").start();
+        }
+    }
+
+    /* Returns a list of all currently attached USB devices */
+    public void getDeviceList(Bundle devices) {
+        synchronized (mLock) {
+            for (String name : mDevices.keySet()) {
+                devices.putParcelable(name, mDevices.get(name));
+            }
+        }
+    }
+
+    /* Opens the specified USB device */
+    public ParcelFileDescriptor openDevice(String deviceName) {
+        synchronized (mLock) {
+            if (isBlackListed(deviceName)) {
+                throw new SecurityException("USB device is on a restricted bus");
+            }
+            UsbDevice device = mDevices.get(deviceName);
+            if (device == null) {
+                // if it is not in mDevices, it either does not exist or is blacklisted
+                throw new IllegalArgumentException(
+                        "device " + deviceName + " does not exist or is restricted");
+            }
+            mSettingsManager.checkPermission(device);
+            return nativeOpenDevice(deviceName);
+        }
+    }
+
+    public void dump(FileDescriptor fd, PrintWriter pw) {
+        synchronized (mLock) {
+            pw.println("  USB Host State:");
+            for (String name : mDevices.keySet()) {
+                pw.println("    " + name + ": " + mDevices.get(name));
+            }
+        }
+    }
+
+    private native void monitorUsbHostBus();
+    private native ParcelFileDescriptor nativeOpenDevice(String deviceName);
+}
diff --git a/services/java/com/android/server/usb/UsbService.java b/services/java/com/android/server/usb/UsbService.java
index a151af0..193638f 100644
--- a/services/java/com/android/server/usb/UsbService.java
+++ b/services/java/com/android/server/usb/UsbService.java
@@ -10,607 +10,168 @@
  * 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
+ * See the License for the specific language governing permissions an
  * limitations under the License.
  */
 
 package com.android.server.usb;
 
 import android.app.PendingIntent;
-import android.content.BroadcastReceiver;
-import android.content.ContentResolver;
 import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
 import android.content.pm.PackageManager;
 import android.hardware.usb.IUsbManager;
 import android.hardware.usb.UsbAccessory;
-import android.hardware.usb.UsbConstants;
 import android.hardware.usb.UsbDevice;
-import android.hardware.usb.UsbEndpoint;
-import android.hardware.usb.UsbInterface;
-import android.hardware.usb.UsbManager;
 import android.net.Uri;
 import android.os.Binder;
 import android.os.Bundle;
-import android.os.Handler;
-import android.os.Message;
-import android.os.Parcelable;
 import android.os.ParcelFileDescriptor;
-import android.os.UEventObserver;
-import android.provider.Settings;
-import android.util.Log;
-import android.util.Slog;
 
 import java.io.File;
 import java.io.FileDescriptor;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
 import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
 
 /**
- * UsbService monitors for changes to USB state.
- * This includes code for both USB host support (where the android device is the host)
- * as well as USB device support (android device is connected to a USB host).
- * Accessory mode is a special case of USB device mode, where the android device is
- * connected to a USB host that supports the android accessory protocol.
+ * UsbService manages all USB related state, including both host and device support.
+ * Host related events and calls are delegated to UsbHostManager, and device related
+ * support is delegated to UsbDeviceManager.
  */
 public class UsbService extends IUsbManager.Stub {
-    private static final String TAG = UsbService.class.getSimpleName();
-    private static final boolean LOG = false;
-
-    private static final String USB_CONNECTED_MATCH =
-            "DEVPATH=/devices/virtual/switch/usb_connected";
-    private static final String USB_CONFIGURATION_MATCH =
-            "DEVPATH=/devices/virtual/switch/usb_configuration";
-    private static final String USB_FUNCTIONS_MATCH =
-            "DEVPATH=/devices/virtual/usb_composite/";
-    private static final String USB_CONNECTED_PATH =
-            "/sys/class/switch/usb_connected/state";
-    private static final String USB_CONFIGURATION_PATH =
-            "/sys/class/switch/usb_configuration/state";
-    private static final String USB_COMPOSITE_CLASS_PATH =
-            "/sys/class/usb_composite";
-
-    private static final int MSG_UPDATE_STATE = 0;
-    private static final int MSG_FUNCTION_ENABLED = 1;
-    private static final int MSG_FUNCTION_DISABLED = 2;
-
-    // Delay for debouncing USB disconnects.
-    // We often get rapid connect/disconnect events when enabling USB functions,
-    // which need debouncing.
-    private static final int UPDATE_DELAY = 1000;
-
-    // current connected and configuration state
-    private int mConnected;
-    private int mConfiguration;
-
-    // last broadcasted connected and configuration state
-    private int mLastConnected = -1;
-    private int mLastConfiguration = -1;
-
-    // lists of enabled and disabled USB functions (for USB device mode)
-    private final ArrayList<String> mEnabledFunctions = new ArrayList<String>();
-    private final ArrayList<String> mDisabledFunctions = new ArrayList<String>();
-
-    // contains all connected USB devices (for USB host mode)
-    private final HashMap<String,UsbDevice> mDevices = new HashMap<String,UsbDevice>();
-
-    // USB busses to exclude from USB host support
-    private final String[] mHostBlacklist;
-
-    private boolean mSystemReady;
-
-    private UsbAccessory mCurrentAccessory;
-    // USB functions that are enabled by default, to restore after exiting accessory mode
-    private final ArrayList<String> mDefaultFunctions = new ArrayList<String>();
-
     private final Context mContext;
-    private final Object mLock = new Object();
-    private final UsbDeviceSettingsManager mDeviceManager;
-    private final boolean mHasUsbHost;
-    private final boolean mHasUsbAccessory;
+    private UsbDeviceManager mDeviceManager;
+    private UsbHostManager mHostManager;
+    private final UsbSettingsManager mSettingsManager;
 
-    private final void readCurrentAccessoryLocked() {
-        if (mHasUsbAccessory) {
-            String[] strings = nativeGetAccessoryStrings();
-            if (strings != null) {
-                mCurrentAccessory = new UsbAccessory(strings);
-                Log.d(TAG, "entering USB accessory mode: " + mCurrentAccessory);
-                if (mSystemReady) {
-                    mDeviceManager.accessoryAttached(mCurrentAccessory);
-                }
-            } else {
-                Log.e(TAG, "nativeGetAccessoryStrings failed");
-            }
-        }
-    }
-
-    /*
-     * Handles USB function enable/disable events (device mode)
-     */
-    private final void functionEnabledLocked(String function, boolean enabled) {
-        if (enabled) {
-            if (!mEnabledFunctions.contains(function)) {
-                mEnabledFunctions.add(function);
-            }
-            mDisabledFunctions.remove(function);
-
-            if (UsbManager.USB_FUNCTION_ACCESSORY.equals(function)) {
-                readCurrentAccessoryLocked();
-            }
-        } else {
-            if (!mDisabledFunctions.contains(function)) {
-                mDisabledFunctions.add(function);
-            }
-            mEnabledFunctions.remove(function);
-        }
-    }
-
-    /*
-     * Listens for uevent messages from the kernel to monitor the USB state (device mode)
-     */
-    private final UEventObserver mUEventObserver = new UEventObserver() {
-        @Override
-        public void onUEvent(UEventObserver.UEvent event) {
-            if (Log.isLoggable(TAG, Log.VERBOSE)) {
-                Slog.v(TAG, "USB UEVENT: " + event.toString());
-            }
-
-            synchronized (mLock) {
-                String name = event.get("SWITCH_NAME");
-                String state = event.get("SWITCH_STATE");
-                if (name != null && state != null) {
-                    try {
-                        int intState = Integer.parseInt(state);
-                        if ("usb_connected".equals(name)) {
-                            mConnected = intState;
-                            // trigger an Intent broadcast
-                            if (mSystemReady) {
-                                // debounce disconnects to avoid problems bringing up USB tethering
-                                update(mConnected == 0);
-                            }
-                        } else if ("usb_configuration".equals(name)) {
-                            mConfiguration = intState;
-                            // trigger an Intent broadcast
-                            if (mSystemReady) {
-                                update(mConnected == 0);
-                            }
-                        }
-                    } catch (NumberFormatException e) {
-                        Slog.e(TAG, "Could not parse switch state from event " + event);
-                    }
-                } else {
-                    String function = event.get("FUNCTION");
-                    String enabledStr = event.get("ENABLED");
-                    if (function != null && enabledStr != null) {
-                        // Note: we do not broadcast a change when a function is enabled or disabled.
-                        // We just record the state change for the next broadcast.
-                        int what = ("1".equals(enabledStr) ?
-                                MSG_FUNCTION_ENABLED : MSG_FUNCTION_DISABLED);
-                        Message msg = Message.obtain(mHandler, what);
-                        msg.obj = function;
-                        mHandler.sendMessage(msg);
-                    }
-                }
-            }
-        }
-    };
-
-   private final BroadcastReceiver mBootCompletedReceiver = new BroadcastReceiver() {
-        public void onReceive(Context context, Intent intent) {
-            // handle accessories attached at boot time
-            synchronized (mLock) {
-                if (mCurrentAccessory != null) {
-                    mDeviceManager.accessoryAttached(mCurrentAccessory);
-                }
-            }
-        }
-    };
 
     public UsbService(Context context) {
         mContext = context;
-        mDeviceManager = new UsbDeviceSettingsManager(context);
+        mSettingsManager = new UsbSettingsManager(context);
         PackageManager pm = mContext.getPackageManager();
-        mHasUsbHost = pm.hasSystemFeature(PackageManager.FEATURE_USB_HOST);
-        mHasUsbAccessory = pm.hasSystemFeature(PackageManager.FEATURE_USB_ACCESSORY);
-
-        mHostBlacklist = context.getResources().getStringArray(
-                com.android.internal.R.array.config_usbHostBlacklist);
-
-        synchronized (mLock) {
-            init();  // set initial status
-
-            // Watch for USB configuration changes
-            if (mConfiguration >= 0) {
-                mUEventObserver.startObserving(USB_CONNECTED_MATCH);
-                mUEventObserver.startObserving(USB_CONFIGURATION_MATCH);
-                mUEventObserver.startObserving(USB_FUNCTIONS_MATCH);
-            }
+        if (pm.hasSystemFeature(PackageManager.FEATURE_USB_HOST)) {
+            mHostManager = new UsbHostManager(context, mSettingsManager);
         }
-    }
-
-    private final void init() {
-        char[] buffer = new char[1024];
-        boolean inAccessoryMode = false;
-
-        // Read initial USB state (device mode)
-        mConfiguration = -1;
-        try {
-            FileReader file = new FileReader(USB_CONNECTED_PATH);
-            int len = file.read(buffer, 0, 1024);
-            file.close();
-            mConnected = Integer.valueOf((new String(buffer, 0, len)).trim());
-
-            file = new FileReader(USB_CONFIGURATION_PATH);
-            len = file.read(buffer, 0, 1024);
-            file.close();
-            mConfiguration = Integer.valueOf((new String(buffer, 0, len)).trim());
-
-        } catch (FileNotFoundException e) {
-            Slog.i(TAG, "This kernel does not have USB configuration switch support");
-        } catch (Exception e) {
-            Slog.e(TAG, "" , e);
+        if (new File("/sys/class/android_usb").exists()) {
+            mDeviceManager = new UsbDeviceManager(context, mSettingsManager);
         }
-        if (mConfiguration < 0) {
-            // This may happen in the emulator or devices without USB device mode support
-            return;
-        }
-
-        // Read initial list of enabled and disabled functions (device mode)
-        try {
-            File[] files = new File(USB_COMPOSITE_CLASS_PATH).listFiles();
-            for (int i = 0; i < files.length; i++) {
-                File file = new File(files[i], "enable");
-                FileReader reader = new FileReader(file);
-                int len = reader.read(buffer, 0, 1024);
-                reader.close();
-                int value = Integer.valueOf((new String(buffer, 0, len)).trim());
-                String functionName = files[i].getName();
-                if (value == 1) {
-                    mEnabledFunctions.add(functionName);
-                if (UsbManager.USB_FUNCTION_ACCESSORY.equals(functionName)) {
-                        // The USB accessory driver is on by default, but it might have been
-                        // enabled before the USB service has initialized.
-                        inAccessoryMode = true;
-                    } else if (!UsbManager.USB_FUNCTION_ADB.equals(functionName)) {
-                        // adb is enabled/disabled automatically by the adbd daemon,
-                        // so don't treat it as a default function.
-                        mDefaultFunctions.add(functionName);
-                    }
-                } else {
-                    mDisabledFunctions.add(functionName);
-                }
-            }
-        } catch (FileNotFoundException e) {
-            Slog.w(TAG, "This kernel does not have USB composite class support");
-        } catch (Exception e) {
-            Slog.e(TAG, "" , e);
-        }
-
-        // handle the case where an accessory switched the driver to accessory mode
-        // before the framework finished booting
-        if (inAccessoryMode) {
-            readCurrentAccessoryLocked();
-
-            // FIXME - if we booted in accessory mode, then we have no way to figure out
-            // which functions are enabled by default.
-            // For now, assume that MTP or mass storage are the only possibilities
-            if (mDisabledFunctions.contains(UsbManager.USB_FUNCTION_MTP)) {
-                mDefaultFunctions.add(UsbManager.USB_FUNCTION_MTP);
-            } else if (mDisabledFunctions.contains(UsbManager.USB_FUNCTION_MASS_STORAGE)) {
-                mDefaultFunctions.add(UsbManager.USB_FUNCTION_MASS_STORAGE);
-            }
-        }
-    }
-
-    private boolean isBlackListed(String deviceName) {
-        int count = mHostBlacklist.length;
-        for (int i = 0; i < count; i++) {
-            if (deviceName.startsWith(mHostBlacklist[i])) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    /* returns true if the USB device should not be accessible by applications (host mode) */
-    private boolean isBlackListed(int clazz, int subClass, int protocol) {
-        // blacklist hubs
-        if (clazz == UsbConstants.USB_CLASS_HUB) return true;
-
-        // blacklist HID boot devices (mouse and keyboard)
-        if (clazz == UsbConstants.USB_CLASS_HID &&
-                subClass == UsbConstants.USB_INTERFACE_SUBCLASS_BOOT) {
-            return true;
-        }
-
-        return false;
-    }
-
-    /* Called from JNI in monitorUsbHostBus() to report new USB devices (host mode) */
-    private void usbDeviceAdded(String deviceName, int vendorID, int productID,
-            int deviceClass, int deviceSubclass, int deviceProtocol,
-            /* array of quintuples containing id, class, subclass, protocol
-               and number of endpoints for each interface */
-            int[] interfaceValues,
-           /* array of quadruples containing address, attributes, max packet size
-              and interval for each endpoint */
-            int[] endpointValues) {
-
-        if (isBlackListed(deviceName) ||
-                isBlackListed(deviceClass, deviceSubclass, deviceProtocol)) {
-            return;
-        }
-
-        synchronized (mLock) {
-            if (mDevices.get(deviceName) != null) {
-                Log.w(TAG, "device already on mDevices list: " + deviceName);
-                return;
-            }
-
-            int numInterfaces = interfaceValues.length / 5;
-            Parcelable[] interfaces = new UsbInterface[numInterfaces];
-            try {
-                // repackage interfaceValues as an array of UsbInterface
-                int intf, endp, ival = 0, eval = 0;
-                for (intf = 0; intf < numInterfaces; intf++) {
-                    int interfaceId = interfaceValues[ival++];
-                    int interfaceClass = interfaceValues[ival++];
-                    int interfaceSubclass = interfaceValues[ival++];
-                    int interfaceProtocol = interfaceValues[ival++];
-                    int numEndpoints = interfaceValues[ival++];
-
-                    Parcelable[] endpoints = new UsbEndpoint[numEndpoints];
-                    for (endp = 0; endp < numEndpoints; endp++) {
-                        int address = endpointValues[eval++];
-                        int attributes = endpointValues[eval++];
-                        int maxPacketSize = endpointValues[eval++];
-                        int interval = endpointValues[eval++];
-                        endpoints[endp] = new UsbEndpoint(address, attributes,
-                                maxPacketSize, interval);
-                    }
-
-                    // don't allow if any interfaces are blacklisted
-                    if (isBlackListed(interfaceClass, interfaceSubclass, interfaceProtocol)) {
-                        return;
-                    }
-                    interfaces[intf] = new UsbInterface(interfaceId, interfaceClass,
-                            interfaceSubclass, interfaceProtocol, endpoints);
-                }
-            } catch (Exception e) {
-                // beware of index out of bound exceptions, which might happen if
-                // a device does not set bNumEndpoints correctly
-                Log.e(TAG, "error parsing USB descriptors", e);
-                return;
-            }
-
-            UsbDevice device = new UsbDevice(deviceName, vendorID, productID,
-                    deviceClass, deviceSubclass, deviceProtocol, interfaces);
-            mDevices.put(deviceName, device);
-            mDeviceManager.deviceAttached(device);
-        }
-    }
-
-    /* Called from JNI in monitorUsbHostBus to report USB device removal (host mode) */
-    private void usbDeviceRemoved(String deviceName) {
-        synchronized (mLock) {
-            UsbDevice device = mDevices.remove(deviceName);
-            if (device != null) {
-                mDeviceManager.deviceDetached(device);
-            }
-        }
-    }
-
-    private void initHostSupport() {
-        // Create a thread to call into native code to wait for USB host events.
-        // This thread will call us back on usbDeviceAdded and usbDeviceRemoved.
-        Runnable runnable = new Runnable() {
-            public void run() {
-                monitorUsbHostBus();
-            }
-        };
-        new Thread(null, runnable, "UsbService host thread").start();
     }
 
     public void systemReady() {
-        synchronized (mLock) {
-            if (mHasUsbHost) {
-                // start monitoring for connected USB devices
-                initHostSupport();
-            }
-
-            update(false);
-            if (mCurrentAccessory != null) {
-                Log.d(TAG, "accessoryAttached at systemReady");
-                // its still too early to handle accessories, so add a BOOT_COMPLETED receiver
-                // to handle this later.
-                mContext.registerReceiver(mBootCompletedReceiver,
-                        new IntentFilter(Intent.ACTION_BOOT_COMPLETED));
-            }
-            mSystemReady = true;
+        if (mDeviceManager != null) {
+            mDeviceManager.systemReady();
         }
-    }
-
-    /*
-     * Sends a message to update the USB connected and configured state (device mode).
-     * If delayed is true, then we add a small delay in sending the message to debounce
-     * the USB connection when enabling USB tethering.
-     */
-    private final void update(boolean delayed) {
-        mHandler.removeMessages(MSG_UPDATE_STATE);
-        mHandler.sendEmptyMessageDelayed(MSG_UPDATE_STATE, delayed ? UPDATE_DELAY : 0);
+        if (mHostManager != null) {
+            mHostManager.systemReady();
+        }
     }
 
     /* Returns a list of all currently attached USB devices (host mdoe) */
     public void getDeviceList(Bundle devices) {
-        synchronized (mLock) {
-            for (String name : mDevices.keySet()) {
-                devices.putParcelable(name, mDevices.get(name));
-            }
+        if (mHostManager != null) {
+            mHostManager.getDeviceList(devices);
         }
     }
 
     /* Opens the specified USB device (host mode) */
     public ParcelFileDescriptor openDevice(String deviceName) {
-        synchronized (mLock) {
-            if (isBlackListed(deviceName)) {
-                throw new SecurityException("USB device is on a restricted bus");
-            }
-            UsbDevice device = mDevices.get(deviceName);
-            if (device == null) {
-                // if it is not in mDevices, it either does not exist or is blacklisted
-                throw new IllegalArgumentException(
-                        "device " + deviceName + " does not exist or is restricted");
-            }
-            mDeviceManager.checkPermission(device);
-            return nativeOpenDevice(deviceName);
+        if (mHostManager != null) {
+            return mHostManager.openDevice(deviceName);
+        } else {
+            return null;
         }
     }
 
     /* returns the currently attached USB accessory (device mode) */
     public UsbAccessory getCurrentAccessory() {
-        return mCurrentAccessory;
+        if (mDeviceManager != null) {
+            return mDeviceManager.getCurrentAccessory();
+        } else {
+            return null;
+        }
     }
 
     /* opens the currently attached USB accessory (device mode) */
     public ParcelFileDescriptor openAccessory(UsbAccessory accessory) {
-        synchronized (mLock) {
-            if (mCurrentAccessory == null) {
-                throw new IllegalArgumentException("no accessory attached");
-            }
-            if (!mCurrentAccessory.equals(accessory)) {
-                Log.e(TAG, accessory.toString() + " does not match current accessory "
-                        + mCurrentAccessory);
-                throw new IllegalArgumentException("accessory not attached");
-            }
-            mDeviceManager.checkPermission(mCurrentAccessory);
-            return nativeOpenAccessory();
+        if (mDeviceManager != null) {
+            return mDeviceManager.openAccessory(accessory);
+        } else {
+            return null;
         }
     }
 
     public void setDevicePackage(UsbDevice device, String packageName) {
         mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null);
-        mDeviceManager.setDevicePackage(device, packageName);
+        mSettingsManager.setDevicePackage(device, packageName);
     }
 
     public void setAccessoryPackage(UsbAccessory accessory, String packageName) {
         mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null);
-        mDeviceManager.setAccessoryPackage(accessory, packageName);
+        mSettingsManager.setAccessoryPackage(accessory, packageName);
     }
 
     public boolean hasDevicePermission(UsbDevice device) {
-        return mDeviceManager.hasPermission(device);
+        return mSettingsManager.hasPermission(device);
     }
 
     public boolean hasAccessoryPermission(UsbAccessory accessory) {
-        return mDeviceManager.hasPermission(accessory);
+        return mSettingsManager.hasPermission(accessory);
     }
 
     public void requestDevicePermission(UsbDevice device, String packageName,
             PendingIntent pi) {
-        mDeviceManager.requestPermission(device, packageName, pi);
+        mSettingsManager.requestPermission(device, packageName, pi);
     }
 
     public void requestAccessoryPermission(UsbAccessory accessory, String packageName,
             PendingIntent pi) {
-        mDeviceManager.requestPermission(accessory, packageName, pi);
+        mSettingsManager.requestPermission(accessory, packageName, pi);
     }
 
     public void grantDevicePermission(UsbDevice device, int uid) {
         mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null);
-        mDeviceManager.grantDevicePermission(device, uid);
+        mSettingsManager.grantDevicePermission(device, uid);
     }
 
     public void grantAccessoryPermission(UsbAccessory accessory, int uid) {
         mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null);
-        mDeviceManager.grantAccessoryPermission(accessory, uid);
+        mSettingsManager.grantAccessoryPermission(accessory, uid);
     }
 
     public boolean hasDefaults(String packageName) {
         mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null);
-        return mDeviceManager.hasDefaults(packageName);
+        return mSettingsManager.hasDefaults(packageName);
     }
 
     public void clearDefaults(String packageName) {
         mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null);
-        mDeviceManager.clearDefaults(packageName);
+        mSettingsManager.clearDefaults(packageName);
     }
 
-    /*
-     * This handler is for deferred handling of events related to device mode and accessories.
-     */
-    private final Handler mHandler = new Handler() {
-        private void addEnabledFunctionsLocked(Intent intent) {
-            // include state of all USB functions in our extras
-            for (int i = 0; i < mEnabledFunctions.size(); i++) {
-                intent.putExtra(mEnabledFunctions.get(i), UsbManager.USB_FUNCTION_ENABLED);
-            }
-            for (int i = 0; i < mDisabledFunctions.size(); i++) {
-                intent.putExtra(mDisabledFunctions.get(i), UsbManager.USB_FUNCTION_DISABLED);
-            }
+    public void setPrimaryFunction(String function) {
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null);
+        if (mDeviceManager != null) {
+            mDeviceManager.setPrimaryFunction(function);
+        } else {
+            throw new IllegalStateException("USB device mode not supported");
         }
+    }
 
-        @Override
-        public void handleMessage(Message msg) {
-            synchronized (mLock) {
-                switch (msg.what) {
-                    case MSG_UPDATE_STATE:
-                        if (mConnected != mLastConnected || mConfiguration != mLastConfiguration) {
-                            if (mConnected == 0) {
-                                if (UsbManager.isFunctionEnabled(
-                                            UsbManager.USB_FUNCTION_ACCESSORY)) {
-                                    // make sure accessory mode is off, and restore default functions
-                                    Log.d(TAG, "exited USB accessory mode");
-                                    if (!UsbManager.setFunctionEnabled
-                                            (UsbManager.USB_FUNCTION_ACCESSORY, false)) {
-                                        Log.e(TAG, "could not disable accessory function");
-                                    }
-                                    int count = mDefaultFunctions.size();
-                                    for (int i = 0; i < count; i++) {
-                                        String function = mDefaultFunctions.get(i);
-                                        if (!UsbManager.setFunctionEnabled(function, true)) {
-                                            Log.e(TAG, "could not reenable function " + function);
-                                        }
-                                    }
-
-                                    if (mCurrentAccessory != null) {
-                                        mDeviceManager.accessoryDetached(mCurrentAccessory);
-                                        mCurrentAccessory = null;
-                                    }
-                                }
-                            }
-
-                            final ContentResolver cr = mContext.getContentResolver();
-                            if (Settings.Secure.getInt(cr,
-                                    Settings.Secure.DEVICE_PROVISIONED, 0) == 0) {
-                                Slog.i(TAG, "Device not provisioned, skipping USB broadcast");
-                                return;
-                            }
-
-                            mLastConnected = mConnected;
-                            mLastConfiguration = mConfiguration;
-
-                            // send a sticky broadcast containing current USB state
-                            Intent intent = new Intent(UsbManager.ACTION_USB_STATE);
-                            intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
-                            intent.putExtra(UsbManager.USB_CONNECTED, mConnected != 0);
-                            intent.putExtra(UsbManager.USB_CONFIGURATION, mConfiguration);
-                            addEnabledFunctionsLocked(intent);
-                            mContext.sendStickyBroadcast(intent);
-                        }
-                        break;
-                    case MSG_FUNCTION_ENABLED:
-                    case MSG_FUNCTION_DISABLED:
-                        functionEnabledLocked((String)msg.obj, msg.what == MSG_FUNCTION_ENABLED);
-                        break;
-                }
-            }
+    public void setDefaultFunction(String function) {
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null);
+        if (mDeviceManager != null) {
+            mDeviceManager.setDefaultFunction(function);
+        } else {
+            throw new IllegalStateException("USB device mode not supported");
         }
-    };
+    }
+
+    public void setMassStorageBackingFile(String path) {
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null);
+        if (mDeviceManager != null) {
+            mDeviceManager.setMassStorageBackingFile(path);
+        } else {
+            throw new IllegalStateException("USB device mode not supported");
+        }
+    }
 
     @Override
     public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
@@ -622,40 +183,14 @@
             return;
         }
 
-        synchronized (mLock) {
-            pw.println("USB Manager State:");
+        pw.println("USB Manager State:");
 
-            pw.println("  USB Device State:");
-            pw.print("    Enabled Functions: ");
-            for (int i = 0; i < mEnabledFunctions.size(); i++) {
-                pw.print(mEnabledFunctions.get(i) + " ");
-            }
-            pw.println("");
-            pw.print("    Disabled Functions: ");
-            for (int i = 0; i < mDisabledFunctions.size(); i++) {
-                pw.print(mDisabledFunctions.get(i) + " ");
-            }
-            pw.println("");
-            pw.print("    Default Functions: ");
-            for (int i = 0; i < mDefaultFunctions.size(); i++) {
-                pw.print(mDefaultFunctions.get(i) + " ");
-            }
-            pw.println("");
-            pw.println("    mConnected: " + mConnected + ", mConfiguration: " + mConfiguration);
-            pw.println("    mCurrentAccessory: " + mCurrentAccessory);
-
-            pw.println("  USB Host State:");
-            for (String name : mDevices.keySet()) {
-                pw.println("    " + name + ": " + mDevices.get(name));
-            }
+        if (mDeviceManager != null) {
             mDeviceManager.dump(fd, pw);
         }
+        if (mHostManager != null) {
+            mHostManager.dump(fd, pw);
+        }
+        mSettingsManager.dump(fd, pw);
     }
-
-    // host support
-    private native void monitorUsbHostBus();
-    private native ParcelFileDescriptor nativeOpenDevice(String deviceName);
-    // accessory support
-    private native String[] nativeGetAccessoryStrings();
-    private native ParcelFileDescriptor nativeOpenAccessory();
 }
diff --git a/services/java/com/android/server/usb/UsbSettingsManager.java b/services/java/com/android/server/usb/UsbSettingsManager.java
new file mode 100644
index 0000000..9113677
--- /dev/null
+++ b/services/java/com/android/server/usb/UsbSettingsManager.java
@@ -0,0 +1,1015 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.usb;
+
+import android.app.PendingIntent;
+import android.content.ActivityNotFoundException;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.ActivityInfo;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.pm.ResolveInfo;
+import android.content.res.XmlResourceParser;
+import android.hardware.usb.UsbAccessory;
+import android.hardware.usb.UsbDevice;
+import android.hardware.usb.UsbInterface;
+import android.hardware.usb.UsbManager;
+import android.os.Binder;
+import android.os.FileUtils;
+import android.os.Process;
+import android.util.Log;
+import android.util.SparseBooleanArray;
+import android.util.Xml;
+
+import com.android.internal.content.PackageMonitor;
+import com.android.internal.util.FastXmlSerializer;
+import com.android.internal.util.XmlUtils;
+
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+import org.xmlpull.v1.XmlSerializer;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+class UsbSettingsManager {
+
+    private static final String TAG = "UsbSettingsManager";
+    private static final File sSettingsFile = new File("/data/system/usb_device_manager.xml");
+
+    private final Context mContext;
+    private final PackageManager mPackageManager;
+
+    // Temporary mapping USB device name to list of UIDs with permissions for the device
+    private final HashMap<String, SparseBooleanArray> mDevicePermissionMap =
+            new HashMap<String, SparseBooleanArray>();
+    // Temporary mapping UsbAccessory to list of UIDs with permissions for the accessory
+    private final HashMap<UsbAccessory, SparseBooleanArray> mAccessoryPermissionMap =
+            new HashMap<UsbAccessory, SparseBooleanArray>();
+    // Maps DeviceFilter to user preferred application package
+    private final HashMap<DeviceFilter, String> mDevicePreferenceMap =
+            new HashMap<DeviceFilter, String>();
+    // Maps AccessoryFilter to user preferred application package
+    private final HashMap<AccessoryFilter, String> mAccessoryPreferenceMap =
+            new HashMap<AccessoryFilter, String>();
+
+    private final Object mLock = new Object();
+
+    // This class is used to describe a USB device.
+    // When used in HashMaps all values must be specified,
+    // but wildcards can be used for any of the fields in
+    // the package meta-data.
+    private static class DeviceFilter {
+        // USB Vendor ID (or -1 for unspecified)
+        public final int mVendorId;
+        // USB Product ID (or -1 for unspecified)
+        public final int mProductId;
+        // USB device or interface class (or -1 for unspecified)
+        public final int mClass;
+        // USB device subclass (or -1 for unspecified)
+        public final int mSubclass;
+        // USB device protocol (or -1 for unspecified)
+        public final int mProtocol;
+
+        public DeviceFilter(int vid, int pid, int clasz, int subclass, int protocol) {
+            mVendorId = vid;
+            mProductId = pid;
+            mClass = clasz;
+            mSubclass = subclass;
+            mProtocol = protocol;
+        }
+
+        public DeviceFilter(UsbDevice device) {
+            mVendorId = device.getVendorId();
+            mProductId = device.getProductId();
+            mClass = device.getDeviceClass();
+            mSubclass = device.getDeviceSubclass();
+            mProtocol = device.getDeviceProtocol();
+        }
+
+        public static DeviceFilter read(XmlPullParser parser)
+                throws XmlPullParserException, IOException {
+            int vendorId = -1;
+            int productId = -1;
+            int deviceClass = -1;
+            int deviceSubclass = -1;
+            int deviceProtocol = -1;
+
+            int count = parser.getAttributeCount();
+            for (int i = 0; i < count; i++) {
+                String name = parser.getAttributeName(i);
+                // All attribute values are ints
+                int value = Integer.parseInt(parser.getAttributeValue(i));
+
+                if ("vendor-id".equals(name)) {
+                    vendorId = value;
+                } else if ("product-id".equals(name)) {
+                    productId = value;
+                } else if ("class".equals(name)) {
+                    deviceClass = value;
+                } else if ("subclass".equals(name)) {
+                    deviceSubclass = value;
+                } else if ("protocol".equals(name)) {
+                    deviceProtocol = value;
+                }
+            }
+            return new DeviceFilter(vendorId, productId,
+                    deviceClass, deviceSubclass, deviceProtocol);
+        }
+
+        public void write(XmlSerializer serializer) throws IOException {
+            serializer.startTag(null, "usb-device");
+            if (mVendorId != -1) {
+                serializer.attribute(null, "vendor-id", Integer.toString(mVendorId));
+            }
+            if (mProductId != -1) {
+                serializer.attribute(null, "product-id", Integer.toString(mProductId));
+            }
+            if (mClass != -1) {
+                serializer.attribute(null, "class", Integer.toString(mClass));
+            }
+            if (mSubclass != -1) {
+                serializer.attribute(null, "subclass", Integer.toString(mSubclass));
+            }
+            if (mProtocol != -1) {
+                serializer.attribute(null, "protocol", Integer.toString(mProtocol));
+            }
+            serializer.endTag(null, "usb-device");
+        }
+
+        private boolean matches(int clasz, int subclass, int protocol) {
+            return ((mClass == -1 || clasz == mClass) &&
+                    (mSubclass == -1 || subclass == mSubclass) &&
+                    (mProtocol == -1 || protocol == mProtocol));
+        }
+
+        public boolean matches(UsbDevice device) {
+            if (mVendorId != -1 && device.getVendorId() != mVendorId) return false;
+            if (mProductId != -1 && device.getProductId() != mProductId) return false;
+
+            // check device class/subclass/protocol
+            if (matches(device.getDeviceClass(), device.getDeviceSubclass(),
+                    device.getDeviceProtocol())) return true;
+
+            // if device doesn't match, check the interfaces
+            int count = device.getInterfaceCount();
+            for (int i = 0; i < count; i++) {
+                UsbInterface intf = device.getInterface(i);
+                 if (matches(intf.getInterfaceClass(), intf.getInterfaceSubclass(),
+                        intf.getInterfaceProtocol())) return true;
+            }
+
+            return false;
+        }
+
+        public boolean matches(DeviceFilter f) {
+            if (mVendorId != -1 && f.mVendorId != mVendorId) return false;
+            if (mProductId != -1 && f.mProductId != mProductId) return false;
+
+            // check device class/subclass/protocol
+            return matches(f.mClass, f.mSubclass, f.mProtocol);
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            // can't compare if we have wildcard strings
+            if (mVendorId == -1 || mProductId == -1 ||
+                    mClass == -1 || mSubclass == -1 || mProtocol == -1) {
+                return false;
+            }
+            if (obj instanceof DeviceFilter) {
+                DeviceFilter filter = (DeviceFilter)obj;
+                return (filter.mVendorId == mVendorId &&
+                        filter.mProductId == mProductId &&
+                        filter.mClass == mClass &&
+                        filter.mSubclass == mSubclass &&
+                        filter.mProtocol == mProtocol);
+            }
+            if (obj instanceof UsbDevice) {
+                UsbDevice device = (UsbDevice)obj;
+                return (device.getVendorId() == mVendorId &&
+                        device.getProductId() == mProductId &&
+                        device.getDeviceClass() == mClass &&
+                        device.getDeviceSubclass() == mSubclass &&
+                        device.getDeviceProtocol() == mProtocol);
+            }
+            return false;
+        }
+
+        @Override
+        public int hashCode() {
+            return (((mVendorId << 16) | mProductId) ^
+                    ((mClass << 16) | (mSubclass << 8) | mProtocol));
+        }
+
+        @Override
+        public String toString() {
+            return "DeviceFilter[mVendorId=" + mVendorId + ",mProductId=" + mProductId +
+                    ",mClass=" + mClass + ",mSubclass=" + mSubclass +
+                    ",mProtocol=" + mProtocol + "]";
+        }
+    }
+
+    // This class is used to describe a USB accessory.
+    // When used in HashMaps all values must be specified,
+    // but wildcards can be used for any of the fields in
+    // the package meta-data.
+    private static class AccessoryFilter {
+        // USB accessory manufacturer (or null for unspecified)
+        public final String mManufacturer;
+        // USB accessory model (or null for unspecified)
+        public final String mModel;
+        // USB accessory version (or null for unspecified)
+        public final String mVersion;
+
+        public AccessoryFilter(String manufacturer, String model, String version) {
+            mManufacturer = manufacturer;
+            mModel = model;
+            mVersion = version;
+        }
+
+        public AccessoryFilter(UsbAccessory accessory) {
+            mManufacturer = accessory.getManufacturer();
+            mModel = accessory.getModel();
+            mVersion = accessory.getVersion();
+        }
+
+        public static AccessoryFilter read(XmlPullParser parser)
+                throws XmlPullParserException, IOException {
+            String manufacturer = null;
+            String model = null;
+            String version = null;
+
+            int count = parser.getAttributeCount();
+            for (int i = 0; i < count; i++) {
+                String name = parser.getAttributeName(i);
+                String value = parser.getAttributeValue(i);
+
+                if ("manufacturer".equals(name)) {
+                    manufacturer = value;
+                } else if ("model".equals(name)) {
+                    model = value;
+                } else if ("version".equals(name)) {
+                    version = value;
+                }
+             }
+             return new AccessoryFilter(manufacturer, model, version);
+        }
+
+        public void write(XmlSerializer serializer)throws IOException {
+            serializer.startTag(null, "usb-accessory");
+            if (mManufacturer != null) {
+                serializer.attribute(null, "manufacturer", mManufacturer);
+            }
+            if (mModel != null) {
+                serializer.attribute(null, "model", mModel);
+            }
+            if (mVersion != null) {
+                serializer.attribute(null, "version", mVersion);
+            }
+            serializer.endTag(null, "usb-accessory");
+        }
+
+        public boolean matches(UsbAccessory acc) {
+            if (mManufacturer != null && !acc.getManufacturer().equals(mManufacturer)) return false;
+            if (mModel != null && !acc.getModel().equals(mModel)) return false;
+            if (mVersion != null && !acc.getVersion().equals(mVersion)) return false;
+            return true;
+        }
+
+        public boolean matches(AccessoryFilter f) {
+            if (mManufacturer != null && !f.mManufacturer.equals(mManufacturer)) return false;
+            if (mModel != null && !f.mModel.equals(mModel)) return false;
+            if (mVersion != null && !f.mVersion.equals(mVersion)) return false;
+            return true;
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            // can't compare if we have wildcard strings
+            if (mManufacturer == null || mModel == null || mVersion == null) {
+                return false;
+            }
+            if (obj instanceof AccessoryFilter) {
+                AccessoryFilter filter = (AccessoryFilter)obj;
+                return (mManufacturer.equals(filter.mManufacturer) &&
+                        mModel.equals(filter.mModel) &&
+                        mVersion.equals(filter.mVersion));
+            }
+            if (obj instanceof UsbAccessory) {
+                UsbAccessory accessory = (UsbAccessory)obj;
+                return (mManufacturer.equals(accessory.getManufacturer()) &&
+                        mModel.equals(accessory.getModel()) &&
+                        mVersion.equals(accessory.getVersion()));
+            }
+            return false;
+        }
+
+        @Override
+        public int hashCode() {
+            return ((mManufacturer == null ? 0 : mManufacturer.hashCode()) ^
+                    (mModel == null ? 0 : mModel.hashCode()) ^
+                    (mVersion == null ? 0 : mVersion.hashCode()));
+        }
+
+        @Override
+        public String toString() {
+            return "AccessoryFilter[mManufacturer=\"" + mManufacturer +
+                                "\", mModel=\"" + mModel +
+                                "\", mVersion=\"" + mVersion + "\"]";
+        }
+    }
+
+    private class MyPackageMonitor extends PackageMonitor {
+
+        public void onPackageAdded(String packageName, int uid) {
+            handlePackageUpdate(packageName);
+        }
+
+        public void onPackageChanged(String packageName, int uid, String[] components) {
+            handlePackageUpdate(packageName);
+        }
+
+        public void onPackageRemoved(String packageName, int uid) {
+            clearDefaults(packageName);
+        }
+    }
+    MyPackageMonitor mPackageMonitor = new MyPackageMonitor();
+
+    public UsbSettingsManager(Context context) {
+        mContext = context;
+        mPackageManager = context.getPackageManager();
+        synchronized (mLock) {
+            readSettingsLocked();
+        }
+        mPackageMonitor.register(context, true);
+    }
+
+    private void readPreference(XmlPullParser parser)
+            throws XmlPullParserException, IOException {
+        String packageName = null;
+        int count = parser.getAttributeCount();
+        for (int i = 0; i < count; i++) {
+            if ("package".equals(parser.getAttributeName(i))) {
+                packageName = parser.getAttributeValue(i);
+                break;
+            }
+        }
+        XmlUtils.nextElement(parser);
+        if ("usb-device".equals(parser.getName())) {
+            DeviceFilter filter = DeviceFilter.read(parser);
+            mDevicePreferenceMap.put(filter, packageName);
+        } else if ("usb-accessory".equals(parser.getName())) {
+            AccessoryFilter filter = AccessoryFilter.read(parser);
+            mAccessoryPreferenceMap.put(filter, packageName);
+        }
+        XmlUtils.nextElement(parser);
+    }
+
+    private void readSettingsLocked() {
+        FileInputStream stream = null;
+        try {
+            stream = new FileInputStream(sSettingsFile);
+            XmlPullParser parser = Xml.newPullParser();
+            parser.setInput(stream, null);
+
+            XmlUtils.nextElement(parser);
+            while (parser.getEventType() != XmlPullParser.END_DOCUMENT) {
+                String tagName = parser.getName();
+                if ("preference".equals(tagName)) {
+                    readPreference(parser);
+                 } else {
+                    XmlUtils.nextElement(parser);
+                }
+            }
+        } catch (FileNotFoundException e) {
+            Log.w(TAG, "settings file not found");
+        } catch (Exception e) {
+            Log.e(TAG, "error reading settings file, deleting to start fresh", e);
+            sSettingsFile.delete();
+        } finally {
+            if (stream != null) {
+                try {
+                    stream.close();
+                } catch (IOException e) {
+                }
+            }
+        }
+    }
+
+    private void writeSettingsLocked() {
+        FileOutputStream fos = null;
+        try {
+            FileOutputStream fstr = new FileOutputStream(sSettingsFile);
+            Log.d(TAG, "writing settings to " + fstr);
+            BufferedOutputStream str = new BufferedOutputStream(fstr);
+            FastXmlSerializer serializer = new FastXmlSerializer();
+            serializer.setOutput(str, "utf-8");
+            serializer.startDocument(null, true);
+            serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
+            serializer.startTag(null, "settings");
+
+            for (DeviceFilter filter : mDevicePreferenceMap.keySet()) {
+                serializer.startTag(null, "preference");
+                serializer.attribute(null, "package", mDevicePreferenceMap.get(filter));
+                filter.write(serializer);
+                serializer.endTag(null, "preference");
+            }
+
+            for (AccessoryFilter filter : mAccessoryPreferenceMap.keySet()) {
+                serializer.startTag(null, "preference");
+                serializer.attribute(null, "package", mAccessoryPreferenceMap.get(filter));
+                filter.write(serializer);
+                serializer.endTag(null, "preference");
+            }
+
+            serializer.endTag(null, "settings");
+            serializer.endDocument();
+
+            str.flush();
+            FileUtils.sync(fstr);
+            str.close();
+        } catch (Exception e) {
+            Log.e(TAG, "error writing settings file, deleting to start fresh", e);
+            sSettingsFile.delete();
+        }
+    }
+
+    // Checks to see if a package matches a device or accessory.
+    // Only one of device and accessory should be non-null.
+    private boolean packageMatchesLocked(ResolveInfo info, String metaDataName,
+            UsbDevice device, UsbAccessory accessory) {
+        ActivityInfo ai = info.activityInfo;
+
+        XmlResourceParser parser = null;
+        try {
+            parser = ai.loadXmlMetaData(mPackageManager, metaDataName);
+            if (parser == null) {
+                Log.w(TAG, "no meta-data for " + info);
+                return false;
+            }
+
+            XmlUtils.nextElement(parser);
+            while (parser.getEventType() != XmlPullParser.END_DOCUMENT) {
+                String tagName = parser.getName();
+                if (device != null && "usb-device".equals(tagName)) {
+                    DeviceFilter filter = DeviceFilter.read(parser);
+                    if (filter.matches(device)) {
+                        return true;
+                    }
+                }
+                else if (accessory != null && "usb-accessory".equals(tagName)) {
+                    AccessoryFilter filter = AccessoryFilter.read(parser);
+                    if (filter.matches(accessory)) {
+                        return true;
+                    }
+                }
+                XmlUtils.nextElement(parser);
+            }
+        } catch (Exception e) {
+            Log.w(TAG, "Unable to load component info " + info.toString(), e);
+        } finally {
+            if (parser != null) parser.close();
+        }
+        return false;
+    }
+
+    private final ArrayList<ResolveInfo> getDeviceMatchesLocked(UsbDevice device, Intent intent) {
+        ArrayList<ResolveInfo> matches = new ArrayList<ResolveInfo>();
+        List<ResolveInfo> resolveInfos = mPackageManager.queryIntentActivities(intent,
+                PackageManager.GET_META_DATA);
+        int count = resolveInfos.size();
+        for (int i = 0; i < count; i++) {
+            ResolveInfo resolveInfo = resolveInfos.get(i);
+            if (packageMatchesLocked(resolveInfo, intent.getAction(), device, null)) {
+                matches.add(resolveInfo);
+            }
+        }
+        return matches;
+    }
+
+    private final ArrayList<ResolveInfo> getAccessoryMatchesLocked(
+            UsbAccessory accessory, Intent intent) {
+        ArrayList<ResolveInfo> matches = new ArrayList<ResolveInfo>();
+        List<ResolveInfo> resolveInfos = mPackageManager.queryIntentActivities(intent,
+                PackageManager.GET_META_DATA);
+        int count = resolveInfos.size();
+        for (int i = 0; i < count; i++) {
+            ResolveInfo resolveInfo = resolveInfos.get(i);
+            if (packageMatchesLocked(resolveInfo, intent.getAction(), null, accessory)) {
+                matches.add(resolveInfo);
+            }
+        }
+        return matches;
+    }
+
+    public void deviceAttached(UsbDevice device) {
+        Intent intent = new Intent(UsbManager.ACTION_USB_DEVICE_ATTACHED);
+        intent.putExtra(UsbManager.EXTRA_DEVICE, device);
+        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+
+        ArrayList<ResolveInfo> matches;
+        String defaultPackage;
+        synchronized (mLock) {
+            matches = getDeviceMatchesLocked(device, intent);
+            // Launch our default activity directly, if we have one.
+            // Otherwise we will start the UsbResolverActivity to allow the user to choose.
+            defaultPackage = mDevicePreferenceMap.get(new DeviceFilter(device));
+        }
+
+        resolveActivity(intent, matches, defaultPackage, device, null);
+    }
+
+    public void deviceDetached(UsbDevice device) {
+        // clear temporary permissions for the device
+        mDevicePermissionMap.remove(device.getDeviceName());
+
+        Intent intent = new Intent(UsbManager.ACTION_USB_DEVICE_DETACHED);
+        intent.putExtra(UsbManager.EXTRA_DEVICE, device);
+        Log.d(TAG, "usbDeviceRemoved, sending " + intent);
+        mContext.sendBroadcast(intent);
+    }
+
+    public void accessoryAttached(UsbAccessory accessory) {
+        Intent intent = new Intent(UsbManager.ACTION_USB_ACCESSORY_ATTACHED);
+        intent.putExtra(UsbManager.EXTRA_ACCESSORY, accessory);
+        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+
+        ArrayList<ResolveInfo> matches;
+        String defaultPackage;
+        synchronized (mLock) {
+            matches = getAccessoryMatchesLocked(accessory, intent);
+            // Launch our default activity directly, if we have one.
+            // Otherwise we will start the UsbResolverActivity to allow the user to choose.
+            defaultPackage = mAccessoryPreferenceMap.get(new AccessoryFilter(accessory));
+        }
+
+        resolveActivity(intent, matches, defaultPackage, null, accessory);
+    }
+
+    public void accessoryDetached(UsbAccessory accessory) {
+        // clear temporary permissions for the accessory
+        mAccessoryPermissionMap.remove(accessory);
+
+        Intent intent = new Intent(
+                UsbManager.ACTION_USB_ACCESSORY_DETACHED);
+        intent.putExtra(UsbManager.EXTRA_ACCESSORY, accessory);
+        mContext.sendBroadcast(intent);
+    }
+
+    private void resolveActivity(Intent intent, ArrayList<ResolveInfo> matches,
+            String defaultPackage, UsbDevice device, UsbAccessory accessory) {
+        int count = matches.size();
+
+        // don't show the resolver activity if there are no choices available
+        if (count == 0) {
+            if (accessory != null) {
+                String uri = accessory.getUri();
+                if (uri != null && uri.length() > 0) {
+                    // display URI to user
+                    // start UsbResolverActivity so user can choose an activity
+                    Intent dialogIntent = new Intent();
+                    dialogIntent.setClassName("com.android.systemui",
+                            "com.android.systemui.usb.UsbAccessoryUriActivity");
+                    dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+                    dialogIntent.putExtra(UsbManager.EXTRA_ACCESSORY, accessory);
+                    dialogIntent.putExtra("uri", uri);
+                    try {
+                        mContext.startActivity(dialogIntent);
+                    } catch (ActivityNotFoundException e) {
+                        Log.e(TAG, "unable to start UsbAccessoryUriActivity");
+                    }
+                }
+            }
+
+            // do nothing
+            return;
+        }
+
+        ResolveInfo defaultRI = null;
+        if (count == 1 && defaultPackage == null) {
+            // Check to see if our single choice is on the system partition.
+            // If so, treat it as our default without calling UsbResolverActivity
+            ResolveInfo rInfo = matches.get(0);
+            if (rInfo.activityInfo != null &&
+                    rInfo.activityInfo.applicationInfo != null &&
+                    (rInfo.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
+                defaultRI = rInfo;
+            }
+        }
+
+        if (defaultRI == null && defaultPackage != null) {
+            // look for default activity
+            for (int i = 0; i < count; i++) {
+                ResolveInfo rInfo = matches.get(i);
+                if (rInfo.activityInfo != null &&
+                        defaultPackage.equals(rInfo.activityInfo.packageName)) {
+                    defaultRI = rInfo;
+                    break;
+                }
+            }
+        }
+
+        if (defaultRI != null) {
+            // grant permission for default activity
+            if (device != null) {
+                grantDevicePermission(device, defaultRI.activityInfo.applicationInfo.uid);
+            } else if (accessory != null) {
+                grantAccessoryPermission(accessory, defaultRI.activityInfo.applicationInfo.uid);
+            }
+
+            // start default activity directly
+            try {
+                intent.setComponent(
+                        new ComponentName(defaultRI.activityInfo.packageName,
+                                defaultRI.activityInfo.name));
+                mContext.startActivity(intent);
+            } catch (ActivityNotFoundException e) {
+                Log.e(TAG, "startActivity failed", e);
+            }
+        } else {
+            Intent resolverIntent = new Intent();
+            resolverIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+
+            if (count == 1) {
+                // start UsbConfirmActivity if there is only one choice
+                resolverIntent.setClassName("com.android.systemui",
+                        "com.android.systemui.usb.UsbConfirmActivity");
+                resolverIntent.putExtra("rinfo", matches.get(0));
+
+                if (device != null) {
+                    resolverIntent.putExtra(UsbManager.EXTRA_DEVICE, device);
+                } else {
+                    resolverIntent.putExtra(UsbManager.EXTRA_ACCESSORY, accessory);
+                }
+            } else {
+                // start UsbResolverActivity so user can choose an activity
+                resolverIntent.setClassName("com.android.systemui",
+                        "com.android.systemui.usb.UsbResolverActivity");
+                resolverIntent.putParcelableArrayListExtra("rlist", matches);
+                resolverIntent.putExtra(Intent.EXTRA_INTENT, intent);
+            }
+            try {
+                mContext.startActivity(resolverIntent);
+            } catch (ActivityNotFoundException e) {
+                Log.e(TAG, "unable to start activity " + resolverIntent);
+            }
+        }
+    }
+
+    private boolean clearCompatibleMatchesLocked(String packageName, DeviceFilter filter) {
+        boolean changed = false;
+        for (DeviceFilter test : mDevicePreferenceMap.keySet()) {
+            if (filter.matches(test)) {
+                mDevicePreferenceMap.remove(test);
+                changed = true;
+            }
+        }
+        return changed;
+    }
+
+    private boolean clearCompatibleMatchesLocked(String packageName, AccessoryFilter filter) {
+        boolean changed = false;
+        for (AccessoryFilter test : mAccessoryPreferenceMap.keySet()) {
+            if (filter.matches(test)) {
+                mAccessoryPreferenceMap.remove(test);
+                changed = true;
+            }
+        }
+        return changed;
+    }
+
+    private boolean handlePackageUpdateLocked(String packageName, ActivityInfo aInfo,
+            String metaDataName) {
+        XmlResourceParser parser = null;
+        boolean changed = false;
+
+        try {
+            parser = aInfo.loadXmlMetaData(mPackageManager, metaDataName);
+            if (parser == null) return false;
+
+            XmlUtils.nextElement(parser);
+            while (parser.getEventType() != XmlPullParser.END_DOCUMENT) {
+                String tagName = parser.getName();
+                if ("usb-device".equals(tagName)) {
+                    DeviceFilter filter = DeviceFilter.read(parser);
+                    if (clearCompatibleMatchesLocked(packageName, filter)) {
+                        changed = true;
+                    }
+                }
+                else if ("usb-accessory".equals(tagName)) {
+                    AccessoryFilter filter = AccessoryFilter.read(parser);
+                    if (clearCompatibleMatchesLocked(packageName, filter)) {
+                        changed = true;
+                    }
+                }
+                XmlUtils.nextElement(parser);
+            }
+        } catch (Exception e) {
+            Log.w(TAG, "Unable to load component info " + aInfo.toString(), e);
+        } finally {
+            if (parser != null) parser.close();
+        }
+        return changed;
+    }
+
+    // Check to see if the package supports any USB devices or accessories.
+    // If so, clear any non-matching preferences for matching devices/accessories.
+    private void handlePackageUpdate(String packageName) {
+        synchronized (mLock) {
+            PackageInfo info;
+            boolean changed = false;
+
+            try {
+                info = mPackageManager.getPackageInfo(packageName,
+                        PackageManager.GET_ACTIVITIES | PackageManager.GET_META_DATA);
+            } catch (NameNotFoundException e) {
+                Log.e(TAG, "handlePackageUpdate could not find package " + packageName, e);
+                return;
+            }
+
+            ActivityInfo[] activities = info.activities;
+            if (activities == null) return;
+            for (int i = 0; i < activities.length; i++) {
+                // check for meta-data, both for devices and accessories
+                if (handlePackageUpdateLocked(packageName, activities[i],
+                        UsbManager.ACTION_USB_DEVICE_ATTACHED)) {
+                    changed = true;
+                }
+                if (handlePackageUpdateLocked(packageName, activities[i],
+                        UsbManager.ACTION_USB_ACCESSORY_ATTACHED)) {
+                    changed = true;
+                }
+            }
+
+            if (changed) {
+                writeSettingsLocked();
+            }
+        }
+    }
+
+    public boolean hasPermission(UsbDevice device) {
+        synchronized (mLock) {
+            SparseBooleanArray uidList = mDevicePermissionMap.get(device.getDeviceName());
+            if (uidList == null) {
+                return false;
+            }
+            return uidList.get(Binder.getCallingUid());
+        }
+    }
+
+    public boolean hasPermission(UsbAccessory accessory) {
+        synchronized (mLock) {
+            SparseBooleanArray uidList = mAccessoryPermissionMap.get(accessory);
+            if (uidList == null) {
+                return false;
+            }
+            return uidList.get(Binder.getCallingUid());
+        }
+    }
+
+    public void checkPermission(UsbDevice device) {
+        if (!hasPermission(device)) {
+            throw new SecurityException("User has not given permission to device " + device);
+        }
+    }
+
+    public void checkPermission(UsbAccessory accessory) {
+        if (!hasPermission(accessory)) {
+            throw new SecurityException("User has not given permission to accessory " + accessory);
+        }
+    }
+
+    private void requestPermissionDialog(Intent intent, String packageName, PendingIntent pi) {
+        int uid = Binder.getCallingUid();
+
+        // compare uid with packageName to foil apps pretending to be someone else
+        try {
+            ApplicationInfo aInfo = mPackageManager.getApplicationInfo(packageName, 0);
+            if (aInfo.uid != uid) {
+                throw new IllegalArgumentException("package " + packageName +
+                        " does not match caller's uid " + uid);
+            }
+        } catch (PackageManager.NameNotFoundException e) {
+            throw new IllegalArgumentException("package " + packageName + " not found");
+        }
+
+        long identity = Binder.clearCallingIdentity();
+        intent.setClassName("com.android.systemui",
+                "com.android.systemui.usb.UsbPermissionActivity");
+        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+        intent.putExtra(Intent.EXTRA_INTENT, pi);
+        intent.putExtra("package", packageName);
+        intent.putExtra("uid", uid);
+        try {
+            mContext.startActivity(intent);
+        } catch (ActivityNotFoundException e) {
+            Log.e(TAG, "unable to start UsbPermissionActivity");
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
+    }
+
+    public void requestPermission(UsbDevice device, String packageName, PendingIntent pi) {
+      Intent intent = new Intent();
+
+        // respond immediately if permission has already been granted
+      if (hasPermission(device)) {
+            intent.putExtra(UsbManager.EXTRA_DEVICE, device);
+            intent.putExtra(UsbManager.EXTRA_PERMISSION_GRANTED, true);
+            try {
+                pi.send(mContext, 0, intent);
+            } catch (PendingIntent.CanceledException e) {
+                Log.w(TAG, "requestPermission PendingIntent was cancelled");
+            }
+            return;
+        }
+
+        // start UsbPermissionActivity so user can choose an activity
+        intent.putExtra(UsbManager.EXTRA_DEVICE, device);
+        requestPermissionDialog(intent, packageName, pi);
+    }
+
+    public void requestPermission(UsbAccessory accessory, String packageName, PendingIntent pi) {
+      Intent intent = new Intent();
+
+        // respond immediately if permission has already been granted
+        if (hasPermission(accessory)) {
+            intent.putExtra(UsbManager.EXTRA_ACCESSORY, accessory);
+            intent.putExtra(UsbManager.EXTRA_PERMISSION_GRANTED, true);
+           try {
+                pi.send(mContext, 0, intent);
+            } catch (PendingIntent.CanceledException e) {
+                Log.w(TAG, "requestPermission PendingIntent was cancelled");
+            }
+            return;
+        }
+
+        intent.putExtra(UsbManager.EXTRA_ACCESSORY, accessory);
+        requestPermissionDialog(intent, packageName, pi);
+    }
+
+    public void setDevicePackage(UsbDevice device, String packageName) {
+        DeviceFilter filter = new DeviceFilter(device);
+        boolean changed = false;
+        synchronized (mLock) {
+            if (packageName == null) {
+                changed = (mDevicePreferenceMap.remove(filter) != null);
+            } else {
+                changed = !packageName.equals(mDevicePreferenceMap.get(filter));
+                if (changed) {
+                    mDevicePreferenceMap.put(filter, packageName);
+                }
+            }
+            if (changed) {
+                writeSettingsLocked();
+            }
+        }
+    }
+
+    public void setAccessoryPackage(UsbAccessory accessory, String packageName) {
+        AccessoryFilter filter = new AccessoryFilter(accessory);
+        boolean changed = false;
+        synchronized (mLock) {
+            if (packageName == null) {
+                changed = (mAccessoryPreferenceMap.remove(filter) != null);
+            } else {
+                changed = !packageName.equals(mAccessoryPreferenceMap.get(filter));
+                if (changed) {
+                    mAccessoryPreferenceMap.put(filter, packageName);
+                }
+            }
+            if (changed) {
+                writeSettingsLocked();
+            }
+        }
+    }
+
+    public void grantDevicePermission(UsbDevice device, int uid) {
+        synchronized (mLock) {
+            String deviceName = device.getDeviceName();
+            SparseBooleanArray uidList = mDevicePermissionMap.get(deviceName);
+            if (uidList == null) {
+                uidList = new SparseBooleanArray(1);
+                mDevicePermissionMap.put(deviceName, uidList);
+            }
+            uidList.put(uid, true);
+        }
+    }
+
+    public void grantAccessoryPermission(UsbAccessory accessory, int uid) {
+        synchronized (mLock) {
+            SparseBooleanArray uidList = mAccessoryPermissionMap.get(accessory);
+            if (uidList == null) {
+                uidList = new SparseBooleanArray(1);
+                mAccessoryPermissionMap.put(accessory, uidList);
+            }
+            uidList.put(uid, true);
+        }
+    }
+
+    public boolean hasDefaults(String packageName) {
+        synchronized (mLock) {
+            if (mDevicePreferenceMap.values().contains(packageName)) return true;
+            if (mAccessoryPreferenceMap.values().contains(packageName)) return true;
+            return false;
+        }
+    }
+
+    public void clearDefaults(String packageName) {
+        synchronized (mLock) {
+            if (clearPackageDefaultsLocked(packageName)) {
+                writeSettingsLocked();
+            }
+        }
+    }
+
+    private boolean clearPackageDefaultsLocked(String packageName) {
+        boolean cleared = false;
+        synchronized (mLock) {
+            if (mDevicePreferenceMap.containsValue(packageName)) {
+                // make a copy of the key set to avoid ConcurrentModificationException
+                Object[] keys = mDevicePreferenceMap.keySet().toArray();
+                for (int i = 0; i < keys.length; i++) {
+                    Object key = keys[i];
+                    if (packageName.equals(mDevicePreferenceMap.get(key))) {
+                        mDevicePreferenceMap.remove(key);
+                        cleared = true;
+                    }
+                }
+            }
+            if (mAccessoryPreferenceMap.containsValue(packageName)) {
+                // make a copy of the key set to avoid ConcurrentModificationException
+                Object[] keys = mAccessoryPreferenceMap.keySet().toArray();
+                for (int i = 0; i < keys.length; i++) {
+                    Object key = keys[i];
+                    if (packageName.equals(mAccessoryPreferenceMap.get(key))) {
+                        mAccessoryPreferenceMap.remove(key);
+                        cleared = true;
+                    }
+                }
+            }
+            return cleared;
+        }
+    }
+
+    public void dump(FileDescriptor fd, PrintWriter pw) {
+        synchronized (mLock) {
+            pw.println("  Device permissions:");
+            for (String deviceName : mDevicePermissionMap.keySet()) {
+                pw.print("    " + deviceName + ": ");
+                SparseBooleanArray uidList = mDevicePermissionMap.get(deviceName);
+                int count = uidList.size();
+                for (int i = 0; i < count; i++) {
+                    pw.print(Integer.toString(uidList.keyAt(i)) + " ");
+                }
+                pw.println("");
+            }
+            pw.println("  Accessory permissions:");
+            for (UsbAccessory accessory : mAccessoryPermissionMap.keySet()) {
+                pw.print("    " + accessory + ": ");
+                SparseBooleanArray uidList = mAccessoryPermissionMap.get(accessory);
+                int count = uidList.size();
+                for (int i = 0; i < count; i++) {
+                    pw.print(Integer.toString(uidList.keyAt(i)) + " ");
+                }
+                pw.println("");
+            }
+            pw.println("  Device preferences:");
+            for (DeviceFilter filter : mDevicePreferenceMap.keySet()) {
+                pw.println("    " + filter + ": " + mDevicePreferenceMap.get(filter));
+            }
+            pw.println("  Accessory preferences:");
+            for (AccessoryFilter filter : mAccessoryPreferenceMap.keySet()) {
+                pw.println("    " + filter + ": " + mAccessoryPreferenceMap.get(filter));
+            }
+        }
+    }
+}
diff --git a/services/java/com/android/server/wm/BlackFrame.java b/services/java/com/android/server/wm/BlackFrame.java
index f9f5758..d8fd7fe 100644
--- a/services/java/com/android/server/wm/BlackFrame.java
+++ b/services/java/com/android/server/wm/BlackFrame.java
@@ -38,6 +38,9 @@
             top = t;
             surface = new Surface(session, 0, "BlackSurface",
                     -1, w, h, PixelFormat.OPAQUE, Surface.FX_SURFACE_DIM);
+            if (WindowManagerService.SHOW_TRANSACTIONS ||
+                    WindowManagerService.SHOW_SURFACE_ALLOC) Slog.i(WindowManagerService.TAG,
+                            "  BLACK " + surface + ": CREATE layer=" + layer);
             surface.setAlpha(1.0f);
             surface.setLayer(layer);
         }
@@ -104,6 +107,10 @@
         if (mBlackSurfaces != null) {
             for (int i=0; i<mBlackSurfaces.length; i++) {
                 if (mBlackSurfaces[i] != null) {
+                    if (WindowManagerService.SHOW_TRANSACTIONS ||
+                            WindowManagerService.SHOW_SURFACE_ALLOC) Slog.i(
+                                    WindowManagerService.TAG,
+                                    "  BLACK " + mBlackSurfaces[i].surface + ": DESTROY");
                     mBlackSurfaces[i].surface.destroy();
                     mBlackSurfaces[i] = null;
                 }
diff --git a/services/java/com/android/server/wm/DimAnimator.java b/services/java/com/android/server/wm/DimAnimator.java
index a266d70..a3293e8 100644
--- a/services/java/com/android/server/wm/DimAnimator.java
+++ b/services/java/com/android/server/wm/DimAnimator.java
@@ -41,8 +41,9 @@
 
     DimAnimator (SurfaceSession session) {
         if (mDimSurface == null) {
-            if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i(WindowManagerService.TAG, "  DIM "
-                    + mDimSurface + ": CREATE");
+            if (WindowManagerService.SHOW_TRANSACTIONS ||
+                    WindowManagerService.SHOW_SURFACE_ALLOC) Slog.i(WindowManagerService.TAG,
+                            "  DIM " + mDimSurface + ": CREATE");
             try {
                 mDimSurface = new Surface(session, 0,
                         "DimAnimator",
diff --git a/services/java/com/android/server/wm/DimSurface.java b/services/java/com/android/server/wm/DimSurface.java
index 220c7fb..d7bb8b3 100644
--- a/services/java/com/android/server/wm/DimSurface.java
+++ b/services/java/com/android/server/wm/DimSurface.java
@@ -32,8 +32,9 @@
 
     DimSurface(SurfaceSession session) {
         if (mDimSurface == null) {
-            if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i(WindowManagerService.TAG, "  DIM "
-                    + mDimSurface + ": CREATE");
+            if (WindowManagerService.SHOW_TRANSACTIONS ||
+                    WindowManagerService.SHOW_SURFACE_ALLOC) Slog.i(WindowManagerService.TAG,
+                            "  DIM " + mDimSurface + ": CREATE");
             try {
                 mDimSurface = new Surface(session, 0,
                         "DimSurface",
diff --git a/services/java/com/android/server/wm/InputManager.java b/services/java/com/android/server/wm/InputManager.java
index 69bde41f..ee69311 100644
--- a/services/java/com/android/server/wm/InputManager.java
+++ b/services/java/com/android/server/wm/InputManager.java
@@ -23,10 +23,14 @@
 import android.content.Context;
 import android.content.pm.PackageManager;
 import android.content.res.Configuration;
+import android.database.ContentObserver;
 import android.os.Environment;
+import android.os.Handler;
 import android.os.Looper;
 import android.os.MessageQueue;
 import android.os.SystemProperties;
+import android.provider.Settings;
+import android.provider.Settings.SettingNotFoundException;
 import android.util.Slog;
 import android.util.Xml;
 import android.view.InputChannel;
@@ -57,7 +61,7 @@
     private final Callbacks mCallbacks;
     private final Context mContext;
     private final WindowManagerService mWindowManagerService;
-    
+
     private static native void nativeInit(Context context,
             Callbacks callbacks, MessageQueue messageQueue);
     private static native void nativeStart();
@@ -88,6 +92,7 @@
     private static native int[] nativeGetInputDeviceIds();
     private static native boolean nativeTransferTouchFocus(InputChannel fromChannel,
             InputChannel toChannel);
+    private static native void nativeSetPointerSpeed(int speed);
     private static native String nativeDump();
     
     // Input event injection constants defined in InputDispatcher.h.
@@ -131,10 +136,13 @@
         Slog.i(TAG, "Initializing input manager");
         nativeInit(mContext, mCallbacks, looper.getQueue());
     }
-    
+
     public void start() {
         Slog.i(TAG, "Starting input manager");
         nativeStart();
+
+        registerPointerSpeedSettingObserver();
+        updatePointerSpeedFromSettings();
     }
     
     public void setDisplaySize(int displayId, int width, int height) {
@@ -403,6 +411,42 @@
         return nativeTransferTouchFocus(fromChannel, toChannel);
     }
 
+    /**
+     * Set the pointer speed.
+     * @param speed The pointer speed as a value between -7 (slowest) and 7 (fastest)
+     * where 0 is the default speed.
+     */
+    public void setPointerSpeed(int speed) {
+        speed = Math.min(Math.max(speed, -7), 7);
+        nativeSetPointerSpeed(speed);
+    }
+
+    public void updatePointerSpeedFromSettings() {
+        int speed = getPointerSpeedSetting(0);
+        setPointerSpeed(speed);
+    }
+
+    private void registerPointerSpeedSettingObserver() {
+        mContext.getContentResolver().registerContentObserver(
+                Settings.System.getUriFor(Settings.System.POINTER_SPEED), true,
+                new ContentObserver(mWindowManagerService.mH) {
+                    @Override
+                    public void onChange(boolean selfChange) {
+                        updatePointerSpeedFromSettings();
+                    }
+                });
+    }
+
+    private int getPointerSpeedSetting(int defaultValue) {
+        int speed = defaultValue;
+        try {
+            speed = Settings.System.getInt(mContext.getContentResolver(),
+                    Settings.System.POINTER_SPEED);
+        } catch (SettingNotFoundException snfe) {
+        }
+        return speed;
+    }
+
     public void dump(PrintWriter pw) {
         String dumpStr = nativeDump();
         if (dumpStr != null) {
@@ -573,6 +617,26 @@
         }
 
         @SuppressWarnings("unused")
+        public int getHoverTapTimeout() {
+            return ViewConfiguration.getHoverTapTimeout();
+        }
+
+        @SuppressWarnings("unused")
+        public int getHoverTapSlop() {
+            return ViewConfiguration.getHoverTapSlop();
+        }
+
+        @SuppressWarnings("unused")
+        public int getDoubleTapTimeout() {
+            return ViewConfiguration.getDoubleTapTimeout();
+        }
+
+        @SuppressWarnings("unused")
+        public int getLongPressTimeout() {
+            return ViewConfiguration.getLongPressTimeout();
+        }
+
+        @SuppressWarnings("unused")
         public int getMaxEventsPerSecond() {
             int result = 0;
             try {
diff --git a/services/java/com/android/server/wm/InputMonitor.java b/services/java/com/android/server/wm/InputMonitor.java
index 9dc92d3..3be8af6 100644
--- a/services/java/com/android/server/wm/InputMonitor.java
+++ b/services/java/com/android/server/wm/InputMonitor.java
@@ -128,6 +128,8 @@
         inputWindow.layer = mService.mDragState.getDragLayerLw();
         inputWindow.ownerPid = Process.myPid();
         inputWindow.ownerUid = Process.myUid();
+        inputWindow.inputFeatures = 0;
+        inputWindow.scaleFactor = 1.0f;
 
         // The drag window covers the entire display
         inputWindow.frameLeft = 0;
@@ -204,7 +206,8 @@
             inputWindow.layer = child.mLayer;
             inputWindow.ownerPid = child.mSession.mPid;
             inputWindow.ownerUid = child.mSession.mUid;
-            
+            inputWindow.inputFeatures = child.mAttrs.inputFeatures;
+
             final Rect frame = child.mFrame;
             inputWindow.frameLeft = frame.left;
             inputWindow.frameTop = frame.top;
diff --git a/services/java/com/android/server/wm/InputWindow.java b/services/java/com/android/server/wm/InputWindow.java
index 578120e..655d734 100644
--- a/services/java/com/android/server/wm/InputWindow.java
+++ b/services/java/com/android/server/wm/InputWindow.java
@@ -75,6 +75,9 @@
     public int ownerPid;
     public int ownerUid;
 
+    // Window input features.
+    public int inputFeatures;
+
     public void recycle() {
         inputWindowHandle = null;
         inputChannel = null;
diff --git a/services/java/com/android/server/wm/ScreenRotationAnimation.java b/services/java/com/android/server/wm/ScreenRotationAnimation.java
index bb01633..8470918 100644
--- a/services/java/com/android/server/wm/ScreenRotationAnimation.java
+++ b/services/java/com/android/server/wm/ScreenRotationAnimation.java
@@ -69,7 +69,7 @@
         mContext = context;
         mDisplay = display;
 
-        display.getMetrics(mDisplayMetrics);
+        display.getRealMetrics(mDisplayMetrics);
 
         Bitmap screenshot = Surface.screenshot(0, 0);
 
@@ -102,6 +102,10 @@
                 Slog.w(TAG, "Unable to allocate freeze surface", e);
             }
 
+            if (WindowManagerService.SHOW_TRANSACTIONS ||
+                    WindowManagerService.SHOW_SURFACE_ALLOC) Slog.i(WindowManagerService.TAG,
+                            "  FREEZE " + mSurface + ": CREATE");
+
             setRotation(display.getRotation());
 
             if (mSurface != null) {
@@ -244,7 +248,7 @@
                 break;
         }
 
-        mDisplay.getMetrics(mDisplayMetrics);
+        mDisplay.getRealMetrics(mDisplayMetrics);
 
         // Initialize the animations.  This is a hack, redefining what "parent"
         // means to allow supplying the last and next size.  In this definition
@@ -284,6 +288,9 @@
 
     public void kill() {
         if (mSurface != null) {
+            if (WindowManagerService.SHOW_TRANSACTIONS ||
+                    WindowManagerService.SHOW_SURFACE_ALLOC) Slog.i(WindowManagerService.TAG,
+                            "  FREEZE " + mSurface + ": DESTROY");
             mSurface.destroy();
             mSurface = null;
         }
diff --git a/services/java/com/android/server/wm/StartingData.java b/services/java/com/android/server/wm/StartingData.java
index 625fcfe..46bb480 100644
--- a/services/java/com/android/server/wm/StartingData.java
+++ b/services/java/com/android/server/wm/StartingData.java
@@ -16,18 +16,23 @@
 
 package com.android.server.wm;
 
+import android.content.res.CompatibilityInfo;
+
 final class StartingData {
     final String pkg;
     final int theme;
+    final CompatibilityInfo compatInfo;
     final CharSequence nonLocalizedLabel;
     final int labelRes;
     final int icon;
     final int windowFlags;
 
-    StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
+    StartingData(String _pkg, int _theme, CompatibilityInfo _compatInfo,
+            CharSequence _nonLocalizedLabel,
             int _labelRes, int _icon, int _windowFlags) {
         pkg = _pkg;
         theme = _theme;
+        compatInfo = _compatInfo;
         nonLocalizedLabel = _nonLocalizedLabel;
         labelRes = _labelRes;
         icon = _icon;
diff --git a/services/java/com/android/server/wm/StrictModeFlash.java b/services/java/com/android/server/wm/StrictModeFlash.java
index 2c62080..71b5952 100644
--- a/services/java/com/android/server/wm/StrictModeFlash.java
+++ b/services/java/com/android/server/wm/StrictModeFlash.java
@@ -39,7 +39,7 @@
 
     public StrictModeFlash(Display display, SurfaceSession session) {
         final DisplayMetrics dm = new DisplayMetrics();
-        display.getMetrics(dm);
+        display.getRealMetrics(dm);
 
         try {
             mSurface = new Surface(session, 0, "StrictModeFlash", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
diff --git a/services/java/com/android/server/wm/Watermark.java b/services/java/com/android/server/wm/Watermark.java
index 22126f3..375abe5 100644
--- a/services/java/com/android/server/wm/Watermark.java
+++ b/services/java/com/android/server/wm/Watermark.java
@@ -52,7 +52,7 @@
 
     Watermark(Display display, SurfaceSession session, String[] tokens) {
         final DisplayMetrics dm = new DisplayMetrics();
-        display.getMetrics(dm);
+        display.getRealMetrics(dm);
 
         if (false) {
             Log.i(WindowManagerService.TAG, "*********************** WATERMARK");
diff --git a/services/java/com/android/server/wm/WindowManagerService.java b/services/java/com/android/server/wm/WindowManagerService.java
index 08fea1b..1c87f5b 100644
--- a/services/java/com/android/server/wm/WindowManagerService.java
+++ b/services/java/com/android/server/wm/WindowManagerService.java
@@ -19,6 +19,7 @@
 import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
 import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
 import static android.view.WindowManager.LayoutParams.FLAG_BLUR_BEHIND;
+import static android.view.WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW;
 import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
 import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
 import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
@@ -153,12 +154,14 @@
     static final boolean DEBUG_WINDOW_MOVEMENT = false;
     static final boolean DEBUG_TOKEN_MOVEMENT = false;
     static final boolean DEBUG_ORIENTATION = false;
+    static final boolean DEBUG_APP_ORIENTATION = false;
     static final boolean DEBUG_CONFIGURATION = false;
     static final boolean DEBUG_APP_TRANSITIONS = false;
     static final boolean DEBUG_STARTING_WINDOW = false;
     static final boolean DEBUG_REORDER = false;
     static final boolean DEBUG_WALLPAPER = false;
     static final boolean DEBUG_DRAG = false;
+    static final boolean SHOW_SURFACE_ALLOC = false;
     static final boolean SHOW_TRANSACTIONS = false;
     static final boolean HIDE_STACK_CRAWLS = true;
 
@@ -408,6 +411,8 @@
     int mBaseDisplayHeight = 0;
     int mCurDisplayWidth = 0;
     int mCurDisplayHeight = 0;
+    int mAppDisplayWidth = 0;
+    int mAppDisplayHeight = 0;
     int mRotation = 0;
     int mRequestedRotation = 0;
     int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
@@ -423,8 +428,8 @@
     boolean mDisplayFrozen = false;
     boolean mWaitingForConfig = false;
     boolean mWindowsFreezingScreen = false;
-    long mFreezeGcPending = 0;
     int mAppsFreezingScreen = 0;
+    int mLastWindowForcedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
 
     int mLayoutSeq = 0;
     
@@ -459,6 +464,10 @@
 
     Display mDisplay;
 
+    final DisplayMetrics mDisplayMetrics = new DisplayMetrics();
+    final DisplayMetrics mTmpDisplayMetrics = new DisplayMetrics();
+    final DisplayMetrics mCompatDisplayMetrics = new DisplayMetrics();
+
     H mH = new H();
 
     WindowState mCurrentFocus = null;
@@ -600,8 +609,7 @@
 
     final Configuration mTempConfiguration = new Configuration();
 
-    // The frame use to limit the size of the app running in compatibility mode.
-    Rect mCompatibleScreenFrame = new Rect();
+    // The desired scaling factor for compatible apps.
     float mCompatibleScreenScale;
 
     public static WindowManagerService main(Context context,
@@ -1433,8 +1441,8 @@
     int adjustWallpaperWindowsLocked() {
         int changed = 0;
 
-        final int dw = mCurDisplayWidth;
-        final int dh = mCurDisplayHeight;
+        final int dw = mAppDisplayWidth;
+        final int dh = mAppDisplayHeight;
 
         // First find top-most window that has asked to be on top of the
         // wallpaper; all wallpapers go behind it.
@@ -1852,8 +1860,8 @@
     }
 
     boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
-        final int dw = mCurDisplayWidth;
-        final int dh = mCurDisplayHeight;
+        final int dw = mAppDisplayWidth;
+        final int dh = mAppDisplayHeight;
 
         boolean changed = false;
 
@@ -1893,8 +1901,8 @@
 
     void updateWallpaperVisibilityLocked() {
         final boolean visible = isWallpaperVisible(mWallpaperTarget);
-        final int dw = mCurDisplayWidth;
-        final int dh = mCurDisplayHeight;
+        final int dw = mAppDisplayWidth;
+        final int dh = mAppDisplayHeight;
 
         int curTokenIndex = mWallpaperTokens.size();
         while (curTokenIndex > 0) {
@@ -2486,6 +2494,8 @@
 
             if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
 
+            win.mEnforceSizeCompat = (win.mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0;
+
             if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
                 win.mAlpha = attrs.alpha;
             }
@@ -2701,7 +2711,7 @@
             configChanged = updateOrientationFromAppTokensLocked(false);
             performLayoutAndPlaceSurfacesLocked();
             if (displayed && win.mIsWallpaper) {
-                updateWallpaperOffsetLocked(win, mCurDisplayWidth, mCurDisplayHeight, false);
+                updateWallpaperOffsetLocked(win, mAppDisplayWidth, mAppDisplayHeight, false);
             }
             if (win.mAppToken != null) {
                 win.mAppToken.updateReportedVisibilityLocked();
@@ -3186,6 +3196,15 @@
     }
 
     public int getOrientationFromWindowsLocked() {
+        if (mDisplayFrozen || mOpeningApps.size() > 0 || mClosingApps.size() > 0) {
+            // If the display is frozen, some activities may be in the middle
+            // of restarting, and thus have removed their old window.  If the
+            // window has the flag to hide the lock screen, then the lock screen
+            // can re-appear and inflict its own orientation on us.  Keep the
+            // orientation stable until this all settles down.
+            return mLastWindowForcedOrientation;
+        }
+
         int pos = mWindows.size() - 1;
         while (pos >= 0) {
             WindowState wtoken = mWindows.get(pos);
@@ -3193,7 +3212,7 @@
             if (wtoken.mAppToken != null) {
                 // We hit an application window. so the orientation will be determined by the
                 // app window. No point in continuing further.
-                return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
+                return (mLastWindowForcedOrientation=ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
             }
             if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
                 continue;
@@ -3203,10 +3222,10 @@
                     (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
                 continue;
             } else {
-                return req;
+                return (mLastWindowForcedOrientation=req);
             }
         }
-        return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
+        return (mLastWindowForcedOrientation=ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
     }
 
     public int getOrientationFromAppTokensLocked() {
@@ -3219,16 +3238,23 @@
         while (pos >= 0) {
             AppWindowToken wtoken = mAppTokens.get(pos);
             pos--;
+
+            if (DEBUG_APP_ORIENTATION) Slog.v(TAG, "Checking app orientation: " + wtoken);
+
             // if we're about to tear down this window and not seek for
             // the behind activity, don't use it for orientation
             if (!findingBehind
                     && (!wtoken.hidden && wtoken.hiddenRequested)) {
+                if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping " + wtoken
+                        + " -- going to hide");
                 continue;
             }
 
             if (!haveGroup) {
                 // We ignore any hidden applications on the top.
                 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
+                    if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping " + wtoken
+                            + " -- hidden on top");
                     continue;
                 }
                 haveGroup = true;
@@ -3242,6 +3268,8 @@
                 // user's orientation.
                 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
                         && lastFullscreen) {
+                    if (DEBUG_ORIENTATION) Slog.v(TAG, "Done at " + wtoken
+                            + " -- end of group, return " + lastOrientation);
                     return lastOrientation;
                 }
             }
@@ -3252,16 +3280,21 @@
             lastFullscreen = wtoken.appFullscreen;
             if (lastFullscreen
                     && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
+                if (DEBUG_ORIENTATION) Slog.v(TAG, "Done at " + wtoken
+                        + " -- full screen, return " + or);
                 return or;
             }
             // If this application has requested an explicit orientation,
             // then use it.
             if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
                     && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
+                if (DEBUG_ORIENTATION) Slog.v(TAG, "Done at " + wtoken
+                        + " -- explicitly set, return " + or);
                 return or;
             }
             findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
         }
+        if (DEBUG_ORIENTATION) Slog.v(TAG, "No app is requesting an orientation");
         return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
     }
 
@@ -3334,15 +3367,6 @@
      * android.os.IBinder)
      */
     boolean updateOrientationFromAppTokensLocked(boolean inTransaction) {
-        if (mDisplayFrozen || mOpeningApps.size() > 0 || mClosingApps.size() > 0) {
-            // If the display is frozen, some activities may be in the middle
-            // of restarting, and thus have removed their old window.  If the
-            // window has the flag to hide the lock screen, then the lock screen
-            // can re-appear and inflict its own orientation on us.  Keep the
-            // orientation stable until this all settles down.
-            return false;
-        }
-
         boolean changed = false;
         long ident = Binder.clearCallingIdentity();
         try {
@@ -3524,7 +3548,8 @@
     }
 
     public void setAppStartingWindow(IBinder token, String pkg,
-            int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
+            int theme, CompatibilityInfo compatInfo,
+            CharSequence nonLocalizedLabel, int labelRes, int icon,
             int windowFlags, IBinder transferFrom, boolean createIfNeeded) {
         if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
                 "setAppStartingIcon()")) {
@@ -3674,8 +3699,7 @@
             }
 
             mStartingIconInTransition = true;
-            wtoken.startingData = new StartingData(
-                    pkg, theme, nonLocalizedLabel,
+            wtoken.startingData = new StartingData(pkg, theme, compatInfo, nonLocalizedLabel,
                     labelRes, icon, windowFlags);
             Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
             // Note: we really want to do sendMessageAtFrontOfQueue() because we
@@ -4783,8 +4807,8 @@
         synchronized(mWindowMap) {
             long ident = Binder.clearCallingIdentity();
 
-            dw = mPolicy.getNonDecorDisplayWidth(mRotation, mCurDisplayWidth);
-            dh = mPolicy.getNonDecorDisplayHeight(mRotation, mCurDisplayHeight);
+            dw = mAppDisplayWidth;
+            dh = mAppDisplayHeight;
 
             int aboveAppLayer = mPolicy.windowTypeToLayerLw(
                     WindowManager.LayoutParams.TYPE_APPLICATION) * TYPE_LAYER_MULTIPLIER
@@ -4950,9 +4974,11 @@
      * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
      */
     public boolean setRotationUncheckedLocked(int rotation, int animFlags, boolean inTransaction) {
-        if (mDragState != null || mScreenRotationAnimation != null) {
-            // Potential rotation during a drag.  Don't do the rotation now, but make
-            // a note to perform the rotation later.
+        if (mDragState != null
+                || (mScreenRotationAnimation != null && mScreenRotationAnimation.isAnimating())) {
+            // Potential rotation during a drag or while waiting for a previous orientation
+            // change to finish (rotation animation will be dismissed).
+            // Don't do the rotation now, but make a note to perform the rotation later.
             if (DEBUG_ORIENTATION) Slog.v(TAG, "Deferring rotation.");
             if (rotation != WindowManagerPolicy.USE_LAST_ROTATION) {
                 mDeferredRotation = rotation;
@@ -5039,7 +5065,7 @@
             mWaitingForConfig = true;
             mLayoutNeeded = true;
             startFreezingDisplayLocked(inTransaction);
-            Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
+            //Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
             mInputManager.setDisplayOrientation(0, rotation);
             if (mDisplayEnabled) {
                 // NOTE: We disable the rotation in the emulator because
@@ -5509,6 +5535,56 @@
         return curSize;
     }
 
+    private int computeSmallestWidth(boolean rotated, int dw, int dh, float density) {
+        // We need to determine the smallest width that will occur under normal
+        // operation.  To this, start with the base screen size and compute the
+        // width under the different possible rotations.  We need to un-rotate
+        // the current screen dimensions before doing this.
+        int unrotDw, unrotDh;
+        if (rotated) {
+            unrotDw = dh;
+            unrotDh = dw;
+        } else {
+            unrotDw = dw;
+            unrotDh = dh;
+        }
+        int sw = reduceConfigWidthSize(unrotDw, Surface.ROTATION_0, density, unrotDw);
+        sw = reduceConfigWidthSize(sw, Surface.ROTATION_90, density, unrotDh);
+        sw = reduceConfigWidthSize(sw, Surface.ROTATION_180, density, unrotDw);
+        sw = reduceConfigWidthSize(sw, Surface.ROTATION_270, density, unrotDh);
+        return sw;
+    }
+
+    private int reduceCompatConfigWidthSize(int curSize, int rotation, DisplayMetrics dm,
+            int dw, int dh) {
+        dm.unscaledWidthPixels = mPolicy.getNonDecorDisplayWidth(rotation, dw);
+        dm.unscaledHeightPixels = mPolicy.getNonDecorDisplayHeight(rotation, dh);
+        float scale = CompatibilityInfo.computeCompatibleScaling(dm, null);
+        int size = (int)(((dm.unscaledWidthPixels / scale) / dm.density) + .5f);
+        if (curSize == 0 || size < curSize) {
+            curSize = size;
+        }
+        return curSize;
+    }
+
+    private int computeCompatSmallestWidth(boolean rotated, DisplayMetrics dm, int dw, int dh) {
+        mTmpDisplayMetrics.setTo(dm);
+        dm = mTmpDisplayMetrics;
+        int unrotDw, unrotDh;
+        if (rotated) {
+            unrotDw = dh;
+            unrotDh = dw;
+        } else {
+            unrotDw = dw;
+            unrotDh = dh;
+        }
+        int sw = reduceCompatConfigWidthSize(0, Surface.ROTATION_0, dm, unrotDw, unrotDh);
+        sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_90, dm, unrotDh, unrotDw);
+        sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_180, dm, unrotDw, unrotDh);
+        sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_270, dm, unrotDh, unrotDw);
+        return sw;
+    }
+
     boolean computeNewConfigurationLocked(Configuration config) {
         if (mDisplay == null) {
             return false;
@@ -5554,21 +5630,26 @@
         }
         config.orientation = orientation;
 
-        DisplayMetrics dm = new DisplayMetrics();
+        DisplayMetrics dm = mDisplayMetrics;
         mDisplay.getRealMetrics(dm);
 
         // Override display width and height with what we are computing,
         // to be sure they remain consistent.
-        dm.widthPixels = dm.realWidthPixels = mPolicy.getNonDecorDisplayWidth(
-                mRotation, dw);
-        dm.heightPixels = dm.realHeightPixels = mPolicy.getNonDecorDisplayHeight(
-                mRotation, dh);
+        dm.widthPixels = dm.unscaledWidthPixels = mAppDisplayWidth
+                = mPolicy.getNonDecorDisplayWidth(mRotation, dw);
+        dm.heightPixels = dm.unscaledHeightPixels = mAppDisplayHeight
+                = mPolicy.getNonDecorDisplayHeight(mRotation, dh);
 
-        mCompatibleScreenScale = CompatibilityInfo.updateCompatibleScreenFrame(
-                dm, mCompatibleScreenFrame, null);
+        mCompatibleScreenScale = CompatibilityInfo.computeCompatibleScaling(dm,
+                mCompatDisplayMetrics);
 
         config.screenWidthDp = (int)(mPolicy.getConfigDisplayWidth(mRotation, dw) / dm.density);
         config.screenHeightDp = (int)(mPolicy.getConfigDisplayHeight(mRotation, dh) / dm.density);
+        config.smallestScreenWidthDp = computeSmallestWidth(rotated, dw, dh, dm.density);
+
+        config.compatScreenWidthDp = (int)(config.screenWidthDp / mCompatibleScreenScale);
+        config.compatScreenHeightDp = (int)(config.screenHeightDp / mCompatibleScreenScale);
+        config.compatSmallestScreenWidthDp = computeCompatSmallestWidth(rotated, dm, dw, dh);
 
         // We need to determine the smallest width that will occur under normal
         // operation.  To this, start with the base screen size and compute the
@@ -5951,6 +6032,19 @@
         }
     }
 
+    /**
+     * Temporarily set the pointer speed.  Does not save the new setting.
+     * Used by the settings application.
+     */
+    public void setPointerSpeed(int speed) {
+        if (!checkCallingPermission(android.Manifest.permission.SET_POINTER_SPEED,
+                "setPointerSpeed()")) {
+            throw new SecurityException("Requires SET_POINTER_SPEED permission");
+        }
+
+        mInputManager.setPointerSpeed(speed);
+    }
+
     private WindowState getFocusedWindow() {
         synchronized (mWindowMap) {
             return getFocusedWindowLocked();
@@ -5990,8 +6084,8 @@
                 mInitialDisplayWidth = mInitialDisplayHeight;
                 mInitialDisplayHeight = tmp;
             }
-            mBaseDisplayWidth = mCurDisplayWidth = mInitialDisplayWidth;
-            mBaseDisplayHeight = mCurDisplayHeight = mInitialDisplayHeight;
+            mBaseDisplayWidth = mCurDisplayWidth = mAppDisplayWidth = mInitialDisplayWidth;
+            mBaseDisplayHeight = mCurDisplayHeight = mAppDisplayHeight = mInitialDisplayHeight;
             mInputManager.setDisplaySize(0, mDisplay.getRawWidth(), mDisplay.getRawHeight());
             mPolicy.setInitialDisplaySize(mInitialDisplayWidth, mInitialDisplayHeight);
         }
@@ -6140,9 +6234,8 @@
                     View view = null;
                     try {
                         view = mPolicy.addStartingWindow(
-                            wtoken.token, sd.pkg,
-                            sd.theme, sd.nonLocalizedLabel, sd.labelRes,
-                            sd.icon, sd.windowFlags);
+                            wtoken.token, sd.pkg, sd.theme, sd.compatInfo,
+                            sd.nonLocalizedLabel, sd.labelRes, sd.icon, sd.windowFlags);
                     } catch (Exception e) {
                         Slog.w(TAG, "Exception when adding starting window", e);
                     }
@@ -6343,7 +6436,6 @@
                         if (mDisplayFrozen) {
                             return;
                         }
-                        mFreezeGcPending = 0;
                     }
                     Runtime.getRuntime().gc();
                     break;
@@ -6493,8 +6585,8 @@
 
     public void getDisplaySize(Point size) {
         synchronized(mWindowMap) {
-            size.x = mCurDisplayWidth;
-            size.y = mCurDisplayHeight;
+            size.x = mAppDisplayWidth;
+            size.y = mAppDisplayHeight;
         }
     }
 
@@ -6626,6 +6718,10 @@
         }
     }
 
+    public boolean canStatusBarHide() {
+        return mPolicy.canStatusBarHide();
+    }
+
     // -------------------------------------------------------------
     // Internals
     // -------------------------------------------------------------
@@ -6990,9 +7086,8 @@
         final long currentTime = SystemClock.uptimeMillis();
         final int dw = mCurDisplayWidth;
         final int dh = mCurDisplayHeight;
-
-        final int innerDw = mPolicy.getNonDecorDisplayWidth(mRotation, dw);
-        final int innerDh = mPolicy.getNonDecorDisplayHeight(mRotation, dh);
+        final int innerDw = mAppDisplayWidth;
+        final int innerDh = mAppDisplayHeight;
 
         int i;
 
@@ -8030,7 +8125,7 @@
                                 if (mDimAnimator == null) {
                                     mDimAnimator = new DimAnimator(mFxSession);
                                 }
-                                mDimAnimator.show(dw, dh);
+                                mDimAnimator.show(innerDw, innerDh);
                                 mDimAnimator.updateParameters(mContext.getResources(),
                                         w, currentTime);
                             }
@@ -8420,7 +8515,8 @@
                 // surface and ask the app to request another one.
                 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
                 if (surface != null) {
-                    if (SHOW_TRANSACTIONS) logSurface(win, "RECOVER DESTROY", null);
+                    if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) logSurface(win,
+                            "RECOVER DESTROY", null);
                     surface.destroy();
                     win.mSurfaceShown = false;
                     win.mSurface = null;
@@ -8557,19 +8653,6 @@
 
         mScreenFrozenLock.acquire();
 
-        long now = SystemClock.uptimeMillis();
-        //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
-        if (mFreezeGcPending != 0) {
-            if (now > (mFreezeGcPending+1000)) {
-                //Slog.i(TAG, "Gc!  " + now + " > " + (mFreezeGcPending+1000));
-                mH.removeMessages(H.FORCE_GC);
-                Runtime.getRuntime().gc();
-                mFreezeGcPending = now;
-            }
-        } else {
-            mFreezeGcPending = now;
-        }
-
         mDisplayFrozen = true;
         
         mInputMonitor.freezeInputDispatchingLw();
@@ -8924,9 +9007,10 @@
                     pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
                     pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
             pw.print("  mRotation="); pw.print(mRotation);
-                    pw.print(" mForcedAppOrientation="); pw.print(mForcedAppOrientation);
                     pw.print(" mRequestedRotation="); pw.print(mRequestedRotation);
                     pw.print(" mAltOrientation="); pw.println(mAltOrientation);
+            pw.print("  mLastWindowForcedOrientation"); pw.print(mLastWindowForcedOrientation);
+                    pw.print(" mForcedAppOrientation="); pw.println(mForcedAppOrientation);
             pw.print("  mDeferredRotation="); pw.print(mDeferredRotation);
                     pw.print(", mDeferredRotationAnimFlags="); pw.println(mDeferredRotationAnimFlags);
             pw.print("  mAnimationPending="); pw.print(mAnimationPending);
@@ -8965,6 +9049,8 @@
                         pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
                         pw.print(" cur=");
                         pw.print(mCurDisplayWidth); pw.print("x"); pw.print(mCurDisplayHeight);
+                        pw.print(" app=");
+                        pw.print(mAppDisplayWidth); pw.print("x"); pw.print(mAppDisplayHeight);
                         pw.print(" real="); pw.print(mDisplay.getRealWidth());
                         pw.print("x"); pw.print(mDisplay.getRealHeight());
                         pw.print(" raw="); pw.print(mDisplay.getRawWidth());
diff --git a/services/java/com/android/server/wm/WindowState.java b/services/java/com/android/server/wm/WindowState.java
index 144341b..587685e 100644
--- a/services/java/com/android/server/wm/WindowState.java
+++ b/services/java/com/android/server/wm/WindowState.java
@@ -54,6 +54,10 @@
  * A window in the window manager.
  */
 final class WindowState implements WindowManagerPolicy.WindowState {
+    static final boolean DEBUG_VISIBILITY = WindowManagerService.DEBUG_VISIBILITY;
+    static final boolean SHOW_TRANSACTIONS = WindowManagerService.SHOW_TRANSACTIONS;
+    static final boolean SHOW_SURFACE_ALLOC = WindowManagerService.SHOW_SURFACE_ALLOC;
+
     final WindowManagerService mService;
     final Session mSession;
     final IWindow mClient;
@@ -71,7 +75,7 @@
     final boolean mIsImWindow;
     final boolean mIsWallpaper;
     final boolean mIsFloatingLayer;
-    final boolean mEnforceSizeCompat;
+    boolean mEnforceSizeCompat;
     int mViewVisibility;
     boolean mPolicyVisibility = true;
     boolean mPolicyVisibilityAfterAnim = true;
@@ -600,7 +604,7 @@
             if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
                 flags |= Surface.SECURE;
             }
-            if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(
+            if (DEBUG_VISIBILITY) Slog.v(
                 WindowManagerService.TAG, "Creating surface in session "
                 + mSession.mSurfaceSession + " window " + this
                 + " w=" + mCompatFrame.width()
@@ -639,7 +643,8 @@
                         mSession.mSurfaceSession, mSession.mPid,
                         mAttrs.getTitle().toString(),
                         0, w, h, format, flags);
-                if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i(WindowManagerService.TAG, "  CREATE SURFACE "
+                if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) Slog.i(WindowManagerService.TAG,
+                        "  CREATE SURFACE "
                         + mSurface + " IN SESSION "
                         + mSession.mSurfaceSession
                         + ": pid=" + mSession.mPid + " format="
@@ -659,7 +664,7 @@
                 WindowManagerService.TAG, "Got surface: " + mSurface
                 + ", set left=" + mFrame.left + " top=" + mFrame.top
                 + ", animLayer=" + mAnimLayer);
-            if (WindowManagerService.SHOW_TRANSACTIONS) {
+            if (SHOW_TRANSACTIONS) {
                 Slog.i(WindowManagerService.TAG, ">>> OPEN TRANSACTION createSurfaceLocked");
                 WindowManagerService.logSurface(this, "CREATE pos=(" + mFrame.left
                         + "," + mFrame.top + ") (" +
@@ -677,7 +682,7 @@
                     mSurfaceShown = false;
                     mSurface.hide();
                     if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
-                        if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(this, "DITHER", null);
+                        if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(this, "DITHER", null);
                         mSurface.setFlags(Surface.SURFACE_DITHER,
                                 Surface.SURFACE_DITHER);
                     }
@@ -688,7 +693,7 @@
                 mLastHidden = true;
             } finally {
                 Surface.closeTransaction();
-                if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i(WindowManagerService.TAG, "<<< CLOSE TRANSACTION createSurfaceLocked");
+                if (SHOW_TRANSACTIONS) Slog.i(WindowManagerService.TAG, "<<< CLOSE TRANSACTION createSurfaceLocked");
             }
             if (WindowManagerService.localLOGV) Slog.v(
                     WindowManagerService.TAG, "Created surface " + this);
@@ -725,7 +730,7 @@
             }
 
             try {
-                if (WindowManagerService.DEBUG_VISIBILITY) {
+                if (DEBUG_VISIBILITY) {
                     RuntimeException e = null;
                     if (!WindowManagerService.HIDE_STACK_CRAWLS) {
                         e = new RuntimeException();
@@ -734,13 +739,13 @@
                     Slog.w(WindowManagerService.TAG, "Window " + this + " destroying surface "
                             + mSurface + ", session " + mSession, e);
                 }
-                if (WindowManagerService.SHOW_TRANSACTIONS) {
+                if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
                     RuntimeException e = null;
                     if (!WindowManagerService.HIDE_STACK_CRAWLS) {
                         e = new RuntimeException();
                         e.fillInStackTrace();
                     }
-                    if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(this, "DESTROY", e);
+                    WindowManagerService.logSurface(this, "DESTROY", e);
                 }
                 mSurface.destroy();
             } catch (RuntimeException e) {
@@ -756,7 +761,7 @@
 
     boolean finishDrawingLocked() {
         if (mDrawPending) {
-            if (WindowManagerService.SHOW_TRANSACTIONS || WindowManagerService.DEBUG_ORIENTATION) Slog.v(
+            if (SHOW_TRANSACTIONS || WindowManagerService.DEBUG_ORIENTATION) Slog.v(
                 WindowManagerService.TAG, "finishDrawingLocked: " + mSurface);
             mCommitDrawPending = true;
             mDrawPending = false;
@@ -783,7 +788,7 @@
 
     // This must be called while inside a transaction.
     boolean performShowLocked() {
-        if (WindowManagerService.DEBUG_VISIBILITY) {
+        if (DEBUG_VISIBILITY) {
             RuntimeException e = null;
             if (!WindowManagerService.HIDE_STACK_CRAWLS) {
                 e = new RuntimeException();
@@ -794,9 +799,9 @@
                     + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
         }
         if (mReadyToShow && isReadyForDisplay()) {
-            if (WindowManagerService.SHOW_TRANSACTIONS || WindowManagerService.DEBUG_ORIENTATION) WindowManagerService.logSurface(this,
+            if (SHOW_TRANSACTIONS || WindowManagerService.DEBUG_ORIENTATION) WindowManagerService.logSurface(this,
                     "SHOW (performShowLocked)", null);
-            if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG, "Showing " + this
+            if (DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG, "Showing " + this
                     + " during animation: policyVis=" + mPolicyVisibility
                     + " attHidden=" + mAttachedHidden
                     + " tok.hiddenRequested="
@@ -958,7 +963,7 @@
         mHasTransformation = false;
         mHasLocalTransformation = false;
         if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
-            if (WindowManagerService.DEBUG_VISIBILITY) {
+            if (DEBUG_VISIBILITY) {
                 Slog.v(WindowManagerService.TAG, "Policy visibility changing after anim in " + this + ": "
                         + mPolicyVisibilityAfterAnim);
             }
@@ -1020,7 +1025,7 @@
         if (mSurface != null) {
             mService.mDestroySurface.add(this);
             mDestroying = true;
-            if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(this, "HIDE (finishExit)", null);
+            if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(this, "HIDE (finishExit)", null);
             mSurfaceShown = false;
             try {
                 mSurface.hide();
@@ -1414,9 +1419,9 @@
         if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
             return false;
         }
-        if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG, "Policy visibility true: " + this);
+        if (DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG, "Policy visibility true: " + this);
         if (doAnimation) {
-            if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG, "doAnimation: mPolicyVisibility="
+            if (DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG, "doAnimation: mPolicyVisibility="
                     + mPolicyVisibility + " mAnimation=" + mAnimation);
             if (mService.mDisplayFrozen || !mService.mPolicy.isScreenOn()) {
                 doAnimation = false;
@@ -1462,7 +1467,7 @@
         if (doAnimation) {
             mPolicyVisibilityAfterAnim = false;
         } else {
-            if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG, "Policy visibility false: " + this);
+            if (DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG, "Policy visibility false: " + this);
             mPolicyVisibilityAfterAnim = false;
             mPolicyVisibility = false;
             // Window is no longer visible -- make sure if we were waiting
diff --git a/services/jni/Android.mk b/services/jni/Android.mk
index 4e93fe2..f33920d 100644
--- a/services/jni/Android.mk
+++ b/services/jni/Android.mk
@@ -12,9 +12,11 @@
     com_android_server_LightsService.cpp \
     com_android_server_PowerManagerService.cpp \
     com_android_server_SystemServer.cpp \
-    com_android_server_UsbService.cpp \
+    com_android_server_UsbDeviceManager.cpp \
+    com_android_server_UsbHostManager.cpp \
     com_android_server_VibratorService.cpp \
     com_android_server_location_GpsLocationProvider.cpp \
+    com_android_server_connectivity_Vpn.cpp \
     onload.cpp
 
 LOCAL_C_INCLUDES += \
diff --git a/services/jni/com_android_server_InputManager.cpp b/services/jni/com_android_server_InputManager.cpp
index 1f10d9c..8a46ab0 100644
--- a/services/jni/com_android_server_InputManager.cpp
+++ b/services/jni/com_android_server_InputManager.cpp
@@ -53,6 +53,11 @@
 
 namespace android {
 
+// The exponent used to calculate the pointer speed scaling factor.
+// The scaling factor is calculated as 2 ^ (speed * exponent),
+// where the speed ranges from -7 to + 7 and is supplied by the user.
+static const float POINTER_SPEED_EXPONENT = 1.0f / 4;
+
 static struct {
     jmethodID notifyConfigurationChanged;
     jmethodID notifyLidSwitchChanged;
@@ -71,6 +76,10 @@
     jmethodID getKeyRepeatTimeout;
     jmethodID getKeyRepeatDelay;
     jmethodID getMaxEventsPerSecond;
+    jmethodID getHoverTapTimeout;
+    jmethodID getHoverTapSlop;
+    jmethodID getDoubleTapTimeout;
+    jmethodID getLongPressTimeout;
     jmethodID getPointerLayer;
     jmethodID getPointerIcon;
 } gCallbacksClassInfo;
@@ -104,6 +113,16 @@
 
 // --- Global functions ---
 
+template<typename T>
+inline static T min(const T& a, const T& b) {
+    return a < b ? a : b;
+}
+
+template<typename T>
+inline static T max(const T& a, const T& b) {
+    return a > b ? a : b;
+}
+
 static jobject getInputApplicationHandleObjLocalRef(JNIEnv* env,
         const sp<InputApplicationHandle>& inputApplicationHandle) {
     if (inputApplicationHandle == NULL) {
@@ -162,15 +181,13 @@
     void setFocusedApplication(JNIEnv* env, jobject applicationObj);
     void setInputDispatchMode(bool enabled, bool frozen);
     void setSystemUiVisibility(int32_t visibility);
+    void setPointerSpeed(int32_t speed);
 
     /* --- InputReaderPolicyInterface implementation --- */
 
     virtual bool getDisplayInfo(int32_t displayId,
             int32_t* width, int32_t* height, int32_t* orientation);
-    virtual bool filterTouchEvents();
-    virtual bool filterJumpyTouchEvents();
-    virtual nsecs_t getVirtualKeyQuietTime();
-    virtual void getExcludedDeviceNames(Vector<String8>& outExcludedDeviceNames);
+    virtual void getReaderConfiguration(InputReaderConfiguration* outConfig);
     virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId);
 
     /* --- InputDispatcherPolicyInterface implementation --- */
@@ -181,10 +198,9 @@
     virtual nsecs_t notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
             const sp<InputWindowHandle>& inputWindowHandle);
     virtual void notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle);
-    virtual nsecs_t getKeyRepeatTimeout();
-    virtual nsecs_t getKeyRepeatDelay();
-    virtual int32_t getMaxEventsPerSecond();
     virtual bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags);
+    virtual void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig);
+    virtual bool isKeyRepeatEnabled();
     virtual void interceptKeyBeforeQueueing(const KeyEvent* keyEvent, uint32_t& policyFlags);
     virtual void interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags);
     virtual bool interceptKeyBeforeDispatching(const sp<InputWindowHandle>& inputWindowHandle,
@@ -206,18 +222,6 @@
     jobject mCallbacksObj;
     sp<Looper> mLooper;
 
-    // Cached filtering policies.
-    int32_t mFilterTouchEvents;
-    int32_t mFilterJumpyTouchEvents;
-    nsecs_t mVirtualKeyQuietTime;
-
-    // Cached key repeat policy.
-    nsecs_t mKeyRepeatTimeout;
-    nsecs_t mKeyRepeatDelay;
-
-    // Cached throttling policy.
-    int32_t mMaxEventsPerSecond;
-
     Mutex mLock;
     struct Locked {
         // Display size information.
@@ -227,6 +231,12 @@
         // System UI visibility.
         int32_t systemUiVisibility;
 
+        // Pointer speed.
+        int32_t pointerSpeed;
+
+        // True if pointer gestures are enabled.
+        bool pointerGesturesEnabled;
+
         // Sprite controller singleton, created on first use.
         sp<SpriteController> spriteController;
 
@@ -253,10 +263,7 @@
 
 NativeInputManager::NativeInputManager(jobject contextObj,
         jobject callbacksObj, const sp<Looper>& looper) :
-        mLooper(looper),
-        mFilterTouchEvents(-1), mFilterJumpyTouchEvents(-1), mVirtualKeyQuietTime(-1),
-        mKeyRepeatTimeout(-1), mKeyRepeatDelay(-1),
-        mMaxEventsPerSecond(-1) {
+        mLooper(looper) {
     JNIEnv* env = jniEnv();
 
     mContextObj = env->NewGlobalRef(contextObj);
@@ -269,6 +276,8 @@
         mLocked.displayOrientation = ROTATION_0;
 
         mLocked.systemUiVisibility = ASYSTEM_UI_VISIBILITY_STATUS_BAR_VISIBLE;
+        mLocked.pointerSpeed = 0;
+        mLocked.pointerGesturesEnabled = true;
     }
 
     sp<EventHub> eventHub = new EventHub();
@@ -369,74 +378,77 @@
     return result;
 }
 
-bool NativeInputManager::filterTouchEvents() {
-    if (mFilterTouchEvents < 0) {
-        JNIEnv* env = jniEnv();
-
-        jboolean result = env->CallBooleanMethod(mCallbacksObj,
-                gCallbacksClassInfo.filterTouchEvents);
-        if (checkAndClearExceptionFromCallback(env, "filterTouchEvents")) {
-            result = false;
-        }
-
-        mFilterTouchEvents = result ? 1 : 0;
-    }
-    return mFilterTouchEvents;
-}
-
-bool NativeInputManager::filterJumpyTouchEvents() {
-    if (mFilterJumpyTouchEvents < 0) {
-        JNIEnv* env = jniEnv();
-
-        jboolean result = env->CallBooleanMethod(mCallbacksObj,
-                gCallbacksClassInfo.filterJumpyTouchEvents);
-        if (checkAndClearExceptionFromCallback(env, "filterJumpyTouchEvents")) {
-            result = false;
-        }
-
-        mFilterJumpyTouchEvents = result ? 1 : 0;
-    }
-    return mFilterJumpyTouchEvents;
-}
-
-nsecs_t NativeInputManager::getVirtualKeyQuietTime() {
-    if (mVirtualKeyQuietTime < 0) {
-        JNIEnv* env = jniEnv();
-
-        jint result = env->CallIntMethod(mCallbacksObj,
-                gCallbacksClassInfo.getVirtualKeyQuietTimeMillis);
-        if (checkAndClearExceptionFromCallback(env, "getVirtualKeyQuietTimeMillis")) {
-            result = 0;
-        }
-        if (result < 0) {
-            result = 0;
-        }
-
-        mVirtualKeyQuietTime = milliseconds_to_nanoseconds(result);
-    }
-    return mVirtualKeyQuietTime;
-}
-
-void NativeInputManager::getExcludedDeviceNames(Vector<String8>& outExcludedDeviceNames) {
-    outExcludedDeviceNames.clear();
-
+void NativeInputManager::getReaderConfiguration(InputReaderConfiguration* outConfig) {
     JNIEnv* env = jniEnv();
 
-    jobjectArray result = jobjectArray(env->CallObjectMethod(mCallbacksObj,
+    jboolean filterTouchEvents = env->CallBooleanMethod(mCallbacksObj,
+            gCallbacksClassInfo.filterTouchEvents);
+    if (!checkAndClearExceptionFromCallback(env, "filterTouchEvents")) {
+        outConfig->filterTouchEvents = filterTouchEvents;
+    }
+
+    jboolean filterJumpyTouchEvents = env->CallBooleanMethod(mCallbacksObj,
+            gCallbacksClassInfo.filterJumpyTouchEvents);
+    if (!checkAndClearExceptionFromCallback(env, "filterJumpyTouchEvents")) {
+        outConfig->filterJumpyTouchEvents = filterJumpyTouchEvents;
+    }
+
+    jint virtualKeyQuietTime = env->CallIntMethod(mCallbacksObj,
+            gCallbacksClassInfo.getVirtualKeyQuietTimeMillis);
+    if (!checkAndClearExceptionFromCallback(env, "getVirtualKeyQuietTimeMillis")) {
+        outConfig->virtualKeyQuietTime = milliseconds_to_nanoseconds(virtualKeyQuietTime);
+    }
+
+    outConfig->excludedDeviceNames.clear();
+    jobjectArray excludedDeviceNames = jobjectArray(env->CallObjectMethod(mCallbacksObj,
             gCallbacksClassInfo.getExcludedDeviceNames));
-    if (! checkAndClearExceptionFromCallback(env, "getExcludedDeviceNames") && result) {
-        jsize length = env->GetArrayLength(result);
+    if (!checkAndClearExceptionFromCallback(env, "getExcludedDeviceNames") && excludedDeviceNames) {
+        jsize length = env->GetArrayLength(excludedDeviceNames);
         for (jsize i = 0; i < length; i++) {
-            jstring item = jstring(env->GetObjectArrayElement(result, i));
-
+            jstring item = jstring(env->GetObjectArrayElement(excludedDeviceNames, i));
             const char* deviceNameChars = env->GetStringUTFChars(item, NULL);
-            outExcludedDeviceNames.add(String8(deviceNameChars));
+            outConfig->excludedDeviceNames.add(String8(deviceNameChars));
             env->ReleaseStringUTFChars(item, deviceNameChars);
-
             env->DeleteLocalRef(item);
         }
-        env->DeleteLocalRef(result);
+        env->DeleteLocalRef(excludedDeviceNames);
     }
+
+    jint hoverTapTimeout = env->CallIntMethod(mCallbacksObj,
+            gCallbacksClassInfo.getHoverTapTimeout);
+    if (!checkAndClearExceptionFromCallback(env, "getHoverTapTimeout")) {
+        jint doubleTapTimeout = env->CallIntMethod(mCallbacksObj,
+                gCallbacksClassInfo.getDoubleTapTimeout);
+        if (!checkAndClearExceptionFromCallback(env, "getDoubleTapTimeout")) {
+            jint longPressTimeout = env->CallIntMethod(mCallbacksObj,
+                    gCallbacksClassInfo.getLongPressTimeout);
+            if (!checkAndClearExceptionFromCallback(env, "getLongPressTimeout")) {
+                outConfig->pointerGestureTapInterval = milliseconds_to_nanoseconds(hoverTapTimeout);
+
+                // We must ensure that the tap-drag interval is significantly shorter than
+                // the long-press timeout because the tap is held down for the entire duration
+                // of the double-tap timeout.
+                jint tapDragInterval = max(min(longPressTimeout - 100,
+                        doubleTapTimeout), hoverTapTimeout);
+                outConfig->pointerGestureTapDragInterval =
+                        milliseconds_to_nanoseconds(tapDragInterval);
+            }
+        }
+    }
+
+    jint hoverTapSlop = env->CallIntMethod(mCallbacksObj,
+            gCallbacksClassInfo.getHoverTapSlop);
+    if (!checkAndClearExceptionFromCallback(env, "getHoverTapSlop")) {
+        outConfig->pointerGestureTapSlop = hoverTapSlop;
+    }
+
+    { // acquire lock
+        AutoMutex _l(mLock);
+
+        outConfig->pointerVelocityControlParameters.scale = exp2f(mLocked.pointerSpeed
+                * POINTER_SPEED_EXPONENT);
+        outConfig->pointerGesturesEnabled = mLocked.pointerGesturesEnabled;
+    } // release lock
 }
 
 sp<PointerControllerInterface> NativeInputManager::obtainPointerController(int32_t deviceId) {
@@ -557,59 +569,37 @@
     }
 }
 
-nsecs_t NativeInputManager::getKeyRepeatTimeout() {
-    if (! isScreenOn()) {
-        // Disable key repeat when the screen is off.
-        return -1;
-    } else {
-        if (mKeyRepeatTimeout < 0) {
-            JNIEnv* env = jniEnv();
+void NativeInputManager::getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) {
+    JNIEnv* env = jniEnv();
 
-            jint result = env->CallIntMethod(mCallbacksObj,
-                    gCallbacksClassInfo.getKeyRepeatTimeout);
-            if (checkAndClearExceptionFromCallback(env, "getKeyRepeatTimeout")) {
-                result = 500;
-            }
+    jint keyRepeatTimeout = env->CallIntMethod(mCallbacksObj,
+            gCallbacksClassInfo.getKeyRepeatTimeout);
+    if (!checkAndClearExceptionFromCallback(env, "getKeyRepeatTimeout")) {
+        outConfig->keyRepeatTimeout = milliseconds_to_nanoseconds(keyRepeatTimeout);
+    }
 
-            mKeyRepeatTimeout = milliseconds_to_nanoseconds(result);
-        }
-        return mKeyRepeatTimeout;
+    jint keyRepeatDelay = env->CallIntMethod(mCallbacksObj,
+            gCallbacksClassInfo.getKeyRepeatDelay);
+    if (!checkAndClearExceptionFromCallback(env, "getKeyRepeatDelay")) {
+        outConfig->keyRepeatDelay = milliseconds_to_nanoseconds(keyRepeatDelay);
+    }
+
+    jint maxEventsPerSecond = env->CallIntMethod(mCallbacksObj,
+            gCallbacksClassInfo.getMaxEventsPerSecond);
+    if (!checkAndClearExceptionFromCallback(env, "getMaxEventsPerSecond")) {
+        outConfig->maxEventsPerSecond = maxEventsPerSecond;
     }
 }
 
-nsecs_t NativeInputManager::getKeyRepeatDelay() {
-    if (mKeyRepeatDelay < 0) {
-        JNIEnv* env = jniEnv();
-
-        jint result = env->CallIntMethod(mCallbacksObj,
-                gCallbacksClassInfo.getKeyRepeatDelay);
-        if (checkAndClearExceptionFromCallback(env, "getKeyRepeatDelay")) {
-            result = 50;
-        }
-
-        mKeyRepeatDelay = milliseconds_to_nanoseconds(result);
-    }
-    return mKeyRepeatDelay;
-}
-
-int32_t NativeInputManager::getMaxEventsPerSecond() {
-    if (mMaxEventsPerSecond < 0) {
-        JNIEnv* env = jniEnv();
-
-        jint result = env->CallIntMethod(mCallbacksObj,
-                gCallbacksClassInfo.getMaxEventsPerSecond);
-        if (checkAndClearExceptionFromCallback(env, "getMaxEventsPerSecond")) {
-            result = 60;
-        }
-
-        mMaxEventsPerSecond = result;
-    }
-    return mMaxEventsPerSecond;
+bool NativeInputManager::isKeyRepeatEnabled() {
+    // Only enable automatic key repeating when the screen is on.
+    return isScreenOn();
 }
 
 void NativeInputManager::setInputWindows(JNIEnv* env, jobjectArray windowObjArray) {
     Vector<InputWindow> windows;
 
+    bool newPointerGesturesEnabled = true;
     jsize length = env->GetArrayLength(windowObjArray);
     for (jsize i = 0; i < length; i++) {
         jobject windowObj = env->GetObjectArrayElement(windowObjArray, i);
@@ -622,11 +612,29 @@
         android_server_InputWindow_toNative(env, windowObj, &window);
         if (window.inputChannel == NULL) {
             windows.pop();
+        } else if (window.hasFocus) {
+            if (window.inputFeatures & InputWindow::INPUT_FEATURE_DISABLE_TOUCH_PAD_GESTURES) {
+                newPointerGesturesEnabled = false;
+            }
         }
         env->DeleteLocalRef(windowObj);
     }
 
     mInputManager->getDispatcher()->setInputWindows(windows);
+
+    uint32_t changes = 0;
+    { // acquire lock
+        AutoMutex _l(mLock);
+
+        if (mLocked.pointerGesturesEnabled != newPointerGesturesEnabled) {
+            mLocked.pointerGesturesEnabled = newPointerGesturesEnabled;
+            changes |= InputReaderConfiguration::CHANGE_POINTER_GESTURE_ENABLEMENT;
+        }
+    } // release lock
+
+    if (changes) {
+        mInputManager->getReader()->requestRefreshConfiguration(changes);
+    }
 }
 
 void NativeInputManager::setFocusedApplication(JNIEnv* env, jobject applicationObj) {
@@ -665,6 +673,22 @@
             : PointerController::INACTIVITY_TIMEOUT_NORMAL);
 }
 
+void NativeInputManager::setPointerSpeed(int32_t speed) {
+    { // acquire lock
+        AutoMutex _l(mLock);
+
+        if (mLocked.pointerSpeed == speed) {
+            return;
+        }
+
+        LOGI("Setting pointer speed to %d.", speed);
+        mLocked.pointerSpeed = speed;
+    } // release lock
+
+    mInputManager->getReader()->requestRefreshConfiguration(
+            InputReaderConfiguration::CHANGE_POINTER_SPEED);
+}
+
 bool NativeInputManager::isScreenOn() {
     return android_server_PowerManagerService_isScreenOn();
 }
@@ -1254,6 +1278,15 @@
             transferTouchFocus(fromChannel, toChannel);
 }
 
+static void android_server_InputManager_nativeSetPointerSpeed(JNIEnv* env,
+        jclass clazz, jint speed) {
+    if (checkInputManagerUnitialized(env)) {
+        return;
+    }
+
+    gNativeInputManager->setPointerSpeed(speed);
+}
+
 static jstring android_server_InputManager_nativeDump(JNIEnv* env, jclass clazz) {
     if (checkInputManagerUnitialized(env)) {
         return NULL;
@@ -1310,6 +1343,8 @@
             (void*) android_server_InputManager_nativeGetInputConfiguration },
     { "nativeTransferTouchFocus", "(Landroid/view/InputChannel;Landroid/view/InputChannel;)Z",
             (void*) android_server_InputManager_nativeTransferTouchFocus },
+    { "nativeSetPointerSpeed", "(I)V",
+            (void*) android_server_InputManager_nativeSetPointerSpeed },
     { "nativeDump", "()Ljava/lang/String;",
             (void*) android_server_InputManager_nativeDump },
 };
@@ -1388,6 +1423,18 @@
     GET_METHOD_ID(gCallbacksClassInfo.getKeyRepeatDelay, clazz,
             "getKeyRepeatDelay", "()I");
 
+    GET_METHOD_ID(gCallbacksClassInfo.getHoverTapTimeout, clazz,
+            "getHoverTapTimeout", "()I");
+
+    GET_METHOD_ID(gCallbacksClassInfo.getHoverTapSlop, clazz,
+            "getHoverTapSlop", "()I");
+
+    GET_METHOD_ID(gCallbacksClassInfo.getDoubleTapTimeout, clazz,
+            "getDoubleTapTimeout", "()I");
+
+    GET_METHOD_ID(gCallbacksClassInfo.getLongPressTimeout, clazz,
+            "getLongPressTimeout", "()I");
+
     GET_METHOD_ID(gCallbacksClassInfo.getMaxEventsPerSecond, clazz,
             "getMaxEventsPerSecond", "()I");
 
diff --git a/services/jni/com_android_server_InputWindow.cpp b/services/jni/com_android_server_InputWindow.cpp
index 012ce21..0426f63 100644
--- a/services/jni/com_android_server_InputWindow.cpp
+++ b/services/jni/com_android_server_InputWindow.cpp
@@ -48,6 +48,7 @@
     jfieldID layer;
     jfieldID ownerPid;
     jfieldID ownerUid;
+    jfieldID inputFeatures;
 } gInputWindowClassInfo;
 
 
@@ -130,6 +131,8 @@
             gInputWindowClassInfo.ownerPid);
     outInputWindow->ownerUid = env->GetIntField(inputWindowObj,
             gInputWindowClassInfo.ownerUid);
+    outInputWindow->inputFeatures = env->GetIntField(inputWindowObj,
+            gInputWindowClassInfo.inputFeatures);
 }
 
 
@@ -206,6 +209,9 @@
 
     GET_FIELD_ID(gInputWindowClassInfo.ownerUid, clazz,
             "ownerUid", "I");
+
+    GET_FIELD_ID(gInputWindowClassInfo.inputFeatures, clazz,
+            "inputFeatures", "I");
     return 0;
 }
 
diff --git a/services/jni/com_android_server_UsbDeviceManager.cpp b/services/jni/com_android_server_UsbDeviceManager.cpp
new file mode 100644
index 0000000..6954171
--- /dev/null
+++ b/services/jni/com_android_server_UsbDeviceManager.cpp
@@ -0,0 +1,128 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "UsbDeviceManagerJNI"
+#include "utils/Log.h"
+
+#include "jni.h"
+#include "JNIHelp.h"
+#include "android_runtime/AndroidRuntime.h"
+
+#include <stdio.h>
+#include <asm/byteorder.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <linux/usb/f_accessory.h>
+
+#define DRIVER_NAME "/dev/usb_accessory"
+
+namespace android
+{
+
+static struct parcel_file_descriptor_offsets_t
+{
+    jclass mClass;
+    jmethodID mConstructor;
+} gParcelFileDescriptorOffsets;
+
+static void checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) {
+    if (env->ExceptionCheck()) {
+        LOGE("An exception was thrown by callback '%s'.", methodName);
+        LOGE_EX(env);
+        env->ExceptionClear();
+    }
+}
+
+static void set_accessory_string(JNIEnv *env, int fd, int cmd, jobjectArray strArray, int index)
+{
+    char buffer[256];
+
+    buffer[0] = 0;
+    int length = ioctl(fd, cmd, buffer);
+    if (buffer[0]) {
+        jstring obj = env->NewStringUTF(buffer);
+        env->SetObjectArrayElement(strArray, index, obj);
+        env->DeleteLocalRef(obj);
+    }
+}
+
+
+static jobjectArray android_server_UsbDeviceManager_getAccessoryStrings(JNIEnv *env, jobject thiz)
+{
+    int fd = open(DRIVER_NAME, O_RDWR);
+    if (fd < 0) {
+        LOGE("could not open %s", DRIVER_NAME);
+        return NULL;
+    }
+    jclass stringClass = env->FindClass("java/lang/String");
+    jobjectArray strArray = env->NewObjectArray(6, stringClass, NULL);
+    if (!strArray) goto out;
+    set_accessory_string(env, fd, ACCESSORY_GET_STRING_MANUFACTURER, strArray, 0);
+    set_accessory_string(env, fd, ACCESSORY_GET_STRING_MODEL, strArray, 1);
+    set_accessory_string(env, fd, ACCESSORY_GET_STRING_DESCRIPTION, strArray, 2);
+    set_accessory_string(env, fd, ACCESSORY_GET_STRING_VERSION, strArray, 3);
+    set_accessory_string(env, fd, ACCESSORY_GET_STRING_URI, strArray, 4);
+    set_accessory_string(env, fd, ACCESSORY_GET_STRING_SERIAL, strArray, 5);
+
+out:
+    close(fd);
+    return strArray;
+}
+
+static jobject android_server_UsbDeviceManager_openAccessory(JNIEnv *env, jobject thiz)
+{
+    int fd = open(DRIVER_NAME, O_RDWR);
+    if (fd < 0) {
+        LOGE("could not open %s", DRIVER_NAME);
+        return NULL;
+    }
+    jobject fileDescriptor = jniCreateFileDescriptor(env, fd);
+    if (fileDescriptor == NULL) {
+        return NULL;
+    }
+    return env->NewObject(gParcelFileDescriptorOffsets.mClass,
+        gParcelFileDescriptorOffsets.mConstructor, fileDescriptor);
+}
+
+static JNINativeMethod method_table[] = {
+    { "nativeGetAccessoryStrings",  "()[Ljava/lang/String;",
+                                    (void*)android_server_UsbDeviceManager_getAccessoryStrings },
+    { "nativeOpenAccessory",        "()Landroid/os/ParcelFileDescriptor;",
+                                    (void*)android_server_UsbDeviceManager_openAccessory },
+};
+
+int register_android_server_UsbDeviceManager(JNIEnv *env)
+{
+    jclass clazz = env->FindClass("com/android/server/usb/UsbDeviceManager");
+    if (clazz == NULL) {
+        LOGE("Can't find com/android/server/usb/UsbDeviceManager");
+        return -1;
+    }
+
+    clazz = env->FindClass("android/os/ParcelFileDescriptor");
+    LOG_FATAL_IF(clazz == NULL, "Unable to find class android.os.ParcelFileDescriptor");
+    gParcelFileDescriptorOffsets.mClass = (jclass) env->NewGlobalRef(clazz);
+    gParcelFileDescriptorOffsets.mConstructor = env->GetMethodID(clazz, "<init>", "(Ljava/io/FileDescriptor;)V");
+    LOG_FATAL_IF(gParcelFileDescriptorOffsets.mConstructor == NULL,
+                 "Unable to find constructor for android.os.ParcelFileDescriptor");
+
+    return jniRegisterNativeMethods(env, "com/android/server/usb/UsbDeviceManager",
+            method_table, NELEM(method_table));
+}
+
+};
diff --git a/services/jni/com_android_server_UsbHostManager.cpp b/services/jni/com_android_server_UsbHostManager.cpp
new file mode 100644
index 0000000..f1abf56
--- /dev/null
+++ b/services/jni/com_android_server_UsbHostManager.cpp
@@ -0,0 +1,203 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "UsbHostManagerJNI"
+#include "utils/Log.h"
+
+#include "jni.h"
+#include "JNIHelp.h"
+#include "android_runtime/AndroidRuntime.h"
+#include "utils/Vector.h"
+
+#include <usbhost/usbhost.h>
+
+#include <stdio.h>
+#include <asm/byteorder.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+
+namespace android
+{
+
+static struct parcel_file_descriptor_offsets_t
+{
+    jclass mClass;
+    jmethodID mConstructor;
+} gParcelFileDescriptorOffsets;
+
+static jmethodID method_usbDeviceAdded;
+static jmethodID method_usbDeviceRemoved;
+
+static void checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) {
+    if (env->ExceptionCheck()) {
+        LOGE("An exception was thrown by callback '%s'.", methodName);
+        LOGE_EX(env);
+        env->ExceptionClear();
+    }
+}
+
+static int usb_device_added(const char *devname, void* client_data) {
+    struct usb_descriptor_header* desc;
+    struct usb_descriptor_iter iter;
+
+    struct usb_device *device = usb_device_open(devname);
+    if (!device) {
+        LOGE("usb_device_open failed\n");
+        return 0;
+    }
+
+    JNIEnv* env = AndroidRuntime::getJNIEnv();
+    jobject thiz = (jobject)client_data;
+    Vector<int> interfaceValues;
+    Vector<int> endpointValues;
+    const usb_device_descriptor* deviceDesc = usb_device_get_device_descriptor(device);
+
+    uint16_t vendorId = usb_device_get_vendor_id(device);
+    uint16_t productId = usb_device_get_product_id(device);
+    uint8_t deviceClass = deviceDesc->bDeviceClass;
+    uint8_t deviceSubClass = deviceDesc->bDeviceSubClass;
+    uint8_t protocol = deviceDesc->bDeviceProtocol;
+
+    usb_descriptor_iter_init(device, &iter);
+
+    while ((desc = usb_descriptor_iter_next(&iter)) != NULL) {
+        if (desc->bDescriptorType == USB_DT_INTERFACE) {
+            struct usb_interface_descriptor *interface = (struct usb_interface_descriptor *)desc;
+
+            // push class, subclass, protocol and number of endpoints into interfaceValues vector
+            interfaceValues.add(interface->bInterfaceNumber);
+            interfaceValues.add(interface->bInterfaceClass);
+            interfaceValues.add(interface->bInterfaceSubClass);
+            interfaceValues.add(interface->bInterfaceProtocol);
+            interfaceValues.add(interface->bNumEndpoints);
+        } else if (desc->bDescriptorType == USB_DT_ENDPOINT) {
+            struct usb_endpoint_descriptor *endpoint = (struct usb_endpoint_descriptor *)desc;
+
+            // push address, attributes, max packet size and interval into endpointValues vector
+            endpointValues.add(endpoint->bEndpointAddress);
+            endpointValues.add(endpoint->bmAttributes);
+            endpointValues.add(__le16_to_cpu(endpoint->wMaxPacketSize));
+            endpointValues.add(endpoint->bInterval);
+        }
+    }
+
+    usb_device_close(device);
+
+    // handle generic device notification
+    int length = interfaceValues.size();
+    jintArray interfaceArray = env->NewIntArray(length);
+    env->SetIntArrayRegion(interfaceArray, 0, length, interfaceValues.array());
+
+    length = endpointValues.size();
+    jintArray endpointArray = env->NewIntArray(length);
+    env->SetIntArrayRegion(endpointArray, 0, length, endpointValues.array());
+
+    jstring deviceName = env->NewStringUTF(devname);
+    env->CallVoidMethod(thiz, method_usbDeviceAdded,
+            deviceName, vendorId, productId, deviceClass,
+            deviceSubClass, protocol, interfaceArray, endpointArray);
+
+    env->DeleteLocalRef(interfaceArray);
+    env->DeleteLocalRef(endpointArray);
+    env->DeleteLocalRef(deviceName);
+    checkAndClearExceptionFromCallback(env, __FUNCTION__);
+
+    return 0;
+}
+
+static int usb_device_removed(const char *devname, void* client_data) {
+    JNIEnv* env = AndroidRuntime::getJNIEnv();
+    jobject thiz = (jobject)client_data;
+
+    jstring deviceName = env->NewStringUTF(devname);
+    env->CallVoidMethod(thiz, method_usbDeviceRemoved, deviceName);
+    env->DeleteLocalRef(deviceName);
+    checkAndClearExceptionFromCallback(env, __FUNCTION__);
+    return 0;
+}
+
+static void android_server_UsbHostManager_monitorUsbHostBus(JNIEnv *env, jobject thiz)
+{
+    struct usb_host_context* context = usb_host_init();
+    if (!context) {
+        LOGE("usb_host_init failed");
+        return;
+    }
+    // this will never return so it is safe to pass thiz directly
+    usb_host_run(context, usb_device_added, usb_device_removed, NULL, (void *)thiz);
+}
+
+static jobject android_server_UsbHostManager_openDevice(JNIEnv *env, jobject thiz, jstring deviceName)
+{
+    const char *deviceNameStr = env->GetStringUTFChars(deviceName, NULL);
+    struct usb_device* device = usb_device_open(deviceNameStr);
+    env->ReleaseStringUTFChars(deviceName, deviceNameStr);
+
+    if (!device)
+        return NULL;
+
+    int fd = usb_device_get_fd(device);
+    if (fd < 0)
+        return NULL;
+    int newFD = dup(fd);
+    usb_device_close(device);
+
+    jobject fileDescriptor = jniCreateFileDescriptor(env, newFD);
+    if (fileDescriptor == NULL) {
+        return NULL;
+    }
+    return env->NewObject(gParcelFileDescriptorOffsets.mClass,
+        gParcelFileDescriptorOffsets.mConstructor, fileDescriptor);
+}
+
+static JNINativeMethod method_table[] = {
+    { "monitorUsbHostBus", "()V", (void*)android_server_UsbHostManager_monitorUsbHostBus },
+    { "nativeOpenDevice",  "(Ljava/lang/String;)Landroid/os/ParcelFileDescriptor;",
+                                  (void*)android_server_UsbHostManager_openDevice },
+};
+
+int register_android_server_UsbHostManager(JNIEnv *env)
+{
+    jclass clazz = env->FindClass("com/android/server/usb/UsbHostManager");
+    if (clazz == NULL) {
+        LOGE("Can't find com/android/server/usb/UsbHostManager");
+        return -1;
+    }
+    method_usbDeviceAdded = env->GetMethodID(clazz, "usbDeviceAdded", "(Ljava/lang/String;IIIII[I[I)V");
+    if (method_usbDeviceAdded == NULL) {
+        LOGE("Can't find usbDeviceAdded");
+        return -1;
+    }
+    method_usbDeviceRemoved = env->GetMethodID(clazz, "usbDeviceRemoved", "(Ljava/lang/String;)V");
+    if (method_usbDeviceRemoved == NULL) {
+        LOGE("Can't find usbDeviceRemoved");
+        return -1;
+    }
+
+    clazz = env->FindClass("android/os/ParcelFileDescriptor");
+    LOG_FATAL_IF(clazz == NULL, "Unable to find class android.os.ParcelFileDescriptor");
+    gParcelFileDescriptorOffsets.mClass = (jclass) env->NewGlobalRef(clazz);
+    gParcelFileDescriptorOffsets.mConstructor = env->GetMethodID(clazz, "<init>", "(Ljava/io/FileDescriptor;)V");
+    LOG_FATAL_IF(gParcelFileDescriptorOffsets.mConstructor == NULL,
+                 "Unable to find constructor for android.os.ParcelFileDescriptor");
+
+    return jniRegisterNativeMethods(env, "com/android/server/usb/UsbHostManager",
+            method_table, NELEM(method_table));
+}
+
+};
diff --git a/services/jni/com_android_server_UsbService.cpp b/services/jni/com_android_server_UsbService.cpp
deleted file mode 100644
index 9cd04f6..0000000
--- a/services/jni/com_android_server_UsbService.cpp
+++ /dev/null
@@ -1,261 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define LOG_TAG "UsbService"
-#include "utils/Log.h"
-
-#include "jni.h"
-#include "JNIHelp.h"
-#include "android_runtime/AndroidRuntime.h"
-#include "utils/Vector.h"
-
-#include <usbhost/usbhost.h>
-
-#include <stdio.h>
-#include <asm/byteorder.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <linux/usb/f_accessory.h>
-
-#define DRIVER_NAME "/dev/usb_accessory"
-
-namespace android
-{
-
-static struct parcel_file_descriptor_offsets_t
-{
-    jclass mClass;
-    jmethodID mConstructor;
-} gParcelFileDescriptorOffsets;
-
-static jmethodID method_usbDeviceAdded;
-static jmethodID method_usbDeviceRemoved;
-
-static void checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) {
-    if (env->ExceptionCheck()) {
-        LOGE("An exception was thrown by callback '%s'.", methodName);
-        LOGE_EX(env);
-        env->ExceptionClear();
-    }
-}
-
-static int usb_device_added(const char *devname, void* client_data) {
-    struct usb_descriptor_header* desc;
-    struct usb_descriptor_iter iter;
-
-    struct usb_device *device = usb_device_open(devname);
-    if (!device) {
-        LOGE("usb_device_open failed\n");
-        return 0;
-    }
-
-    JNIEnv* env = AndroidRuntime::getJNIEnv();
-    jobject thiz = (jobject)client_data;
-    Vector<int> interfaceValues;
-    Vector<int> endpointValues;
-    const usb_device_descriptor* deviceDesc = usb_device_get_device_descriptor(device);
-
-    uint16_t vendorId = usb_device_get_vendor_id(device);
-    uint16_t productId = usb_device_get_product_id(device);
-    uint8_t deviceClass = deviceDesc->bDeviceClass;
-    uint8_t deviceSubClass = deviceDesc->bDeviceSubClass;
-    uint8_t protocol = deviceDesc->bDeviceProtocol;
-
-    usb_descriptor_iter_init(device, &iter);
-
-    while ((desc = usb_descriptor_iter_next(&iter)) != NULL) {
-        if (desc->bDescriptorType == USB_DT_INTERFACE) {
-            struct usb_interface_descriptor *interface = (struct usb_interface_descriptor *)desc;
-
-            // push class, subclass, protocol and number of endpoints into interfaceValues vector
-            interfaceValues.add(interface->bInterfaceNumber);
-            interfaceValues.add(interface->bInterfaceClass);
-            interfaceValues.add(interface->bInterfaceSubClass);
-            interfaceValues.add(interface->bInterfaceProtocol);
-            interfaceValues.add(interface->bNumEndpoints);
-        } else if (desc->bDescriptorType == USB_DT_ENDPOINT) {
-            struct usb_endpoint_descriptor *endpoint = (struct usb_endpoint_descriptor *)desc;
-
-            // push address, attributes, max packet size and interval into endpointValues vector
-            endpointValues.add(endpoint->bEndpointAddress);
-            endpointValues.add(endpoint->bmAttributes);
-            endpointValues.add(__le16_to_cpu(endpoint->wMaxPacketSize));
-            endpointValues.add(endpoint->bInterval);
-        }
-    }
-
-    usb_device_close(device);
-
-    // handle generic device notification
-    int length = interfaceValues.size();
-    jintArray interfaceArray = env->NewIntArray(length);
-    env->SetIntArrayRegion(interfaceArray, 0, length, interfaceValues.array());
-
-    length = endpointValues.size();
-    jintArray endpointArray = env->NewIntArray(length);
-    env->SetIntArrayRegion(endpointArray, 0, length, endpointValues.array());
-
-    jstring deviceName = env->NewStringUTF(devname);
-    env->CallVoidMethod(thiz, method_usbDeviceAdded,
-            deviceName, vendorId, productId, deviceClass,
-            deviceSubClass, protocol, interfaceArray, endpointArray);
-
-    env->DeleteLocalRef(interfaceArray);
-    env->DeleteLocalRef(endpointArray);
-    env->DeleteLocalRef(deviceName);
-    checkAndClearExceptionFromCallback(env, __FUNCTION__);
-
-    return 0;
-}
-
-static int usb_device_removed(const char *devname, void* client_data) {
-    JNIEnv* env = AndroidRuntime::getJNIEnv();
-    jobject thiz = (jobject)client_data;
-
-    jstring deviceName = env->NewStringUTF(devname);
-    env->CallVoidMethod(thiz, method_usbDeviceRemoved, env->NewStringUTF(devname));
-    env->DeleteLocalRef(deviceName);
-    checkAndClearExceptionFromCallback(env, __FUNCTION__);
-    return 0;
-}
-
-static void android_server_UsbService_monitorUsbHostBus(JNIEnv *env, jobject thiz)
-{
-    struct usb_host_context* context = usb_host_init();
-    if (!context) {
-        LOGE("usb_host_init failed");
-        return;
-    }
-    // this will never return so it is safe to pass thiz directly
-    usb_host_run(context, usb_device_added, usb_device_removed, NULL, (void *)thiz);
-}
-
-static jobject android_server_UsbService_openDevice(JNIEnv *env, jobject thiz, jstring deviceName)
-{
-    const char *deviceNameStr = env->GetStringUTFChars(deviceName, NULL);
-    struct usb_device* device = usb_device_open(deviceNameStr);
-    env->ReleaseStringUTFChars(deviceName, deviceNameStr);
-
-    if (!device)
-        return NULL;
-
-    int fd = usb_device_get_fd(device);
-    if (fd < 0)
-        return NULL;
-    int newFD = dup(fd);
-    usb_device_close(device);
-
-    jobject fileDescriptor = jniCreateFileDescriptor(env, newFD);
-    if (fileDescriptor == NULL) {
-        return NULL;
-    }
-    return env->NewObject(gParcelFileDescriptorOffsets.mClass,
-        gParcelFileDescriptorOffsets.mConstructor, fileDescriptor);
-}
-
-static void set_accessory_string(JNIEnv *env, int fd, int cmd, jobjectArray strArray, int index)
-{
-    char buffer[256];
-
-    buffer[0] = 0;
-    int length = ioctl(fd, cmd, buffer);
-    if (buffer[0]) {
-        jstring obj = env->NewStringUTF(buffer);
-        env->SetObjectArrayElement(strArray, index, obj);
-        env->DeleteLocalRef(obj);
-    }
-}
-
-
-static jobjectArray android_server_UsbService_getAccessoryStrings(JNIEnv *env, jobject thiz)
-{
-    int fd = open(DRIVER_NAME, O_RDWR);
-    if (fd < 0) {
-        LOGE("could not open %s", DRIVER_NAME);
-        return NULL;
-    }
-    jclass stringClass = env->FindClass("java/lang/String");
-    jobjectArray strArray = env->NewObjectArray(6, stringClass, NULL);
-    if (!strArray) goto out;
-    set_accessory_string(env, fd, ACCESSORY_GET_STRING_MANUFACTURER, strArray, 0);
-    set_accessory_string(env, fd, ACCESSORY_GET_STRING_MODEL, strArray, 1);
-    set_accessory_string(env, fd, ACCESSORY_GET_STRING_DESCRIPTION, strArray, 2);
-    set_accessory_string(env, fd, ACCESSORY_GET_STRING_VERSION, strArray, 3);
-    set_accessory_string(env, fd, ACCESSORY_GET_STRING_URI, strArray, 4);
-    set_accessory_string(env, fd, ACCESSORY_GET_STRING_SERIAL, strArray, 5);
-
-out:
-    close(fd);
-    return strArray;
-}
-
-static jobject android_server_UsbService_openAccessory(JNIEnv *env, jobject thiz)
-{
-    int fd = open(DRIVER_NAME, O_RDWR);
-    if (fd < 0) {
-        LOGE("could not open %s", DRIVER_NAME);
-        return NULL;
-    }
-    jobject fileDescriptor = jniCreateFileDescriptor(env, fd);
-    if (fileDescriptor == NULL) {
-        return NULL;
-    }
-    return env->NewObject(gParcelFileDescriptorOffsets.mClass,
-        gParcelFileDescriptorOffsets.mConstructor, fileDescriptor);
-}
-
-static JNINativeMethod method_table[] = {
-    { "monitorUsbHostBus", "()V", (void*)android_server_UsbService_monitorUsbHostBus },
-    { "nativeOpenDevice",  "(Ljava/lang/String;)Landroid/os/ParcelFileDescriptor;",
-                                  (void*)android_server_UsbService_openDevice },
-    { "nativeGetAccessoryStrings", "()[Ljava/lang/String;",
-                                  (void*)android_server_UsbService_getAccessoryStrings },
-    { "nativeOpenAccessory","()Landroid/os/ParcelFileDescriptor;",
-                                  (void*)android_server_UsbService_openAccessory },
-};
-
-int register_android_server_UsbService(JNIEnv *env)
-{
-    jclass clazz = env->FindClass("com/android/server/usb/UsbService");
-    if (clazz == NULL) {
-        LOGE("Can't find com/android/server/usb/UsbService");
-        return -1;
-    }
-    method_usbDeviceAdded = env->GetMethodID(clazz, "usbDeviceAdded", "(Ljava/lang/String;IIIII[I[I)V");
-    if (method_usbDeviceAdded == NULL) {
-        LOGE("Can't find usbDeviceAdded");
-        return -1;
-    }
-    method_usbDeviceRemoved = env->GetMethodID(clazz, "usbDeviceRemoved", "(Ljava/lang/String;)V");
-    if (method_usbDeviceRemoved == NULL) {
-        LOGE("Can't find usbDeviceRemoved");
-        return -1;
-    }
-
-    clazz = env->FindClass("android/os/ParcelFileDescriptor");
-    LOG_FATAL_IF(clazz == NULL, "Unable to find class android.os.ParcelFileDescriptor");
-    gParcelFileDescriptorOffsets.mClass = (jclass) env->NewGlobalRef(clazz);
-    gParcelFileDescriptorOffsets.mConstructor = env->GetMethodID(clazz, "<init>", "(Ljava/io/FileDescriptor;)V");
-    LOG_FATAL_IF(gParcelFileDescriptorOffsets.mConstructor == NULL,
-                 "Unable to find constructor for android.os.ParcelFileDescriptor");
-
-    return jniRegisterNativeMethods(env, "com/android/server/usb/UsbService",
-            method_table, NELEM(method_table));
-}
-
-};
diff --git a/services/jni/com_android_server_connectivity_Vpn.cpp b/services/jni/com_android_server_connectivity_Vpn.cpp
new file mode 100644
index 0000000..ae7fbfe
--- /dev/null
+++ b/services/jni/com_android_server_connectivity_Vpn.cpp
@@ -0,0 +1,440 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_NDEBUG 0
+
+#define LOG_TAG "VpnJni"
+#include <cutils/log.h>
+#include <cutils/properties.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <errno.h>
+#include <fcntl.h>
+
+#include <linux/if.h>
+#include <linux/if_tun.h>
+#include <linux/route.h>
+#include <linux/ipv6_route.h>
+
+#include "jni.h"
+#include "JNIHelp.h"
+
+namespace android
+{
+
+static inline in_addr_t *as_in_addr(sockaddr *sa) {
+    return &((sockaddr_in *)sa)->sin_addr.s_addr;
+}
+
+//------------------------------------------------------------------------------
+
+#define SYSTEM_ERROR -1
+#define BAD_ARGUMENT -2
+
+static int create_interface(int mtu, char *name, int *index)
+{
+    int tun = open("/dev/tun", O_RDWR);
+    int inet4 = socket(AF_INET, SOCK_DGRAM, 0);
+    int flags;
+
+    ifreq ifr4;
+    memset(&ifr4, 0, sizeof(ifr4));
+
+    // Allocate interface.
+    ifr4.ifr_flags = IFF_TUN | IFF_NO_PI;
+    if (ioctl(tun, TUNSETIFF, &ifr4)) {
+        LOGE("Cannot allocate TUN: %s", strerror(errno));
+        goto error;
+    }
+
+    // Activate interface.
+    ifr4.ifr_flags = IFF_UP;
+    if (ioctl(inet4, SIOCSIFFLAGS, &ifr4)) {
+        LOGE("Cannot activate %s: %s", ifr4.ifr_name, strerror(errno));
+        goto error;
+    }
+
+    // Set MTU if it is specified.
+    ifr4.ifr_mtu = mtu;
+    if (mtu > 0 && ioctl(inet4, SIOCSIFMTU, &ifr4)) {
+        LOGE("Cannot set MTU on %s: %s", ifr4.ifr_name, strerror(errno));
+        goto error;
+    }
+
+    // Get interface index.
+    if (ioctl(inet4, SIOGIFINDEX, &ifr4)) {
+        LOGE("Cannot get index of %s: %s", ifr4.ifr_name, strerror(errno));
+        goto error;
+    }
+
+    // Make it non-blocking.
+    flags = fcntl(tun, F_GETFL, 0);
+    if (flags == -1 || fcntl(tun, F_SETFL, flags | O_NONBLOCK)) {
+        LOGE("Cannot set non-blocking on %s: %s", ifr4.ifr_name, strerror(errno));
+        goto error;
+    }
+
+    strcpy(name, ifr4.ifr_name);
+    *index = ifr4.ifr_ifindex;
+    close(inet4);
+    return tun;
+
+error:
+    close(tun);
+    close(inet4);
+    return SYSTEM_ERROR;
+}
+
+static int set_addresses(const char *name, int index, const char *addresses)
+{
+    int inet4 = socket(AF_INET, SOCK_DGRAM, 0);
+    int inet6 = socket(AF_INET6, SOCK_DGRAM, 0);
+
+    ifreq ifr4;
+    memset(&ifr4, 0, sizeof(ifr4));
+    strcpy(ifr4.ifr_name, name);
+    ifr4.ifr_addr.sa_family = AF_INET;
+
+    in6_ifreq ifr6;
+    memset(&ifr6, 0, sizeof(ifr6));
+    ifr6.ifr6_ifindex = index;
+
+    char address[65];
+    int prefix;
+
+    int chars;
+    int count = 0;
+
+    while (sscanf(addresses, " %64[^/]/%d %n", address, &prefix, &chars) == 2) {
+        addresses += chars;
+
+        if (strchr(address, ':')) {
+            // Add an IPv6 address.
+            if (inet_pton(AF_INET6, address, &ifr6.ifr6_addr) != 1 ||
+                    prefix < 0 || prefix > 128) {
+                count = BAD_ARGUMENT;
+                break;
+            }
+
+            ifr6.ifr6_prefixlen = prefix;
+            if (ioctl(inet6, SIOCSIFADDR, &ifr6)) {
+                count = (errno == EINVAL) ? BAD_ARGUMENT : SYSTEM_ERROR;
+                break;
+            }
+        } else {
+            // Add an IPv4 address.
+            if (inet_pton(AF_INET, address, as_in_addr(&ifr4.ifr_addr)) != 1 ||
+                    prefix < 0 || prefix > 32) {
+                count = BAD_ARGUMENT;
+                break;
+            }
+
+            if (count) {
+                sprintf(ifr4.ifr_name, "%s:%d", name, count);
+            }
+            if (ioctl(inet4, SIOCSIFADDR, &ifr4)) {
+                count = (errno == EINVAL) ? BAD_ARGUMENT : SYSTEM_ERROR;
+                break;
+            }
+
+            in_addr_t mask = prefix ? (~0 << (32 - prefix)) : 0;
+            *as_in_addr(&ifr4.ifr_addr) = htonl(mask);
+            if (ioctl(inet4, SIOCSIFNETMASK, &ifr4)) {
+                count = (errno == EINVAL) ? BAD_ARGUMENT : SYSTEM_ERROR;
+                break;
+            }
+        }
+        LOGV("Address added on %s: %s/%d", name, address, prefix);
+        ++count;
+    }
+
+    if (count == BAD_ARGUMENT) {
+        LOGE("Invalid address: %s/%d", address, prefix);
+    } else if (count == SYSTEM_ERROR) {
+        LOGE("Cannot add address: %s/%d: %s", address, prefix, strerror(errno));
+    } else if (*addresses) {
+        LOGE("Invalid address: %s", addresses);
+        count = BAD_ARGUMENT;
+    }
+
+    close(inet4);
+    close(inet6);
+    return count;
+}
+
+static int set_routes(const char *name, int index, const char *routes)
+{
+    int inet4 = socket(AF_INET, SOCK_DGRAM, 0);
+    int inet6 = socket(AF_INET6, SOCK_DGRAM, 0);
+
+    rtentry rt4;
+    memset(&rt4, 0, sizeof(rt4));
+    rt4.rt_dev = (char *)name;
+    rt4.rt_flags = RTF_UP;
+    rt4.rt_dst.sa_family = AF_INET;
+    rt4.rt_genmask.sa_family = AF_INET;
+
+    in6_rtmsg rt6;
+    memset(&rt6, 0, sizeof(rt6));
+    rt6.rtmsg_ifindex = index;
+    rt6.rtmsg_flags = RTF_UP;
+
+    char address[65];
+    int prefix;
+
+    int chars;
+    int count = 0;
+
+    while (sscanf(routes, " %64[^/]/%d %n", address, &prefix, &chars) == 2) {
+        routes += chars;
+
+        if (strchr(address, ':')) {
+            // Add an IPv6 route.
+            if (inet_pton(AF_INET6, address, &rt6.rtmsg_dst) != 1 ||
+                    prefix < 1 || prefix > 128) {
+                count = BAD_ARGUMENT;
+                break;
+            }
+
+            rt6.rtmsg_dst_len = prefix;
+            if (ioctl(inet6, SIOCADDRT, &rt6) && errno != EEXIST) {
+                count = (errno == EINVAL) ? BAD_ARGUMENT : SYSTEM_ERROR;
+                break;
+            }
+        } else {
+            // Add an IPv4 route.
+            if (inet_pton(AF_INET, address, as_in_addr(&rt4.rt_dst)) != 1 ||
+                    prefix < 1 || prefix > 32) {
+                count = BAD_ARGUMENT;
+                break;
+            }
+
+            in_addr_t mask = prefix ? (~0 << (32 - prefix)) : 0;
+            *as_in_addr(&rt4.rt_genmask) = htonl(mask);
+            if (ioctl(inet4, SIOCADDRT, &rt4) && errno != EEXIST) {
+                count = (errno == EINVAL) ? BAD_ARGUMENT : SYSTEM_ERROR;
+                break;
+            }
+        }
+        LOGV("Route added on %s: %s/%d", name, address, prefix);
+        ++count;
+    }
+
+    if (count == BAD_ARGUMENT) {
+        LOGE("Invalid route: %s/%d", address, prefix);
+    } else if (count == SYSTEM_ERROR) {
+        LOGE("Cannot add route: %s/%d: %s",
+                address, prefix, strerror(errno));
+    } else if (*routes) {
+        LOGE("Invalid route: %s", routes);
+        count = BAD_ARGUMENT;
+    }
+
+    close(inet4);
+    close(inet6);
+    return count;
+}
+
+static int get_interface_name(char *name, int tun)
+{
+    ifreq ifr4;
+    if (ioctl(tun, TUNGETIFF, &ifr4)) {
+        LOGE("Cannot get interface name: %s", strerror(errno));
+        return SYSTEM_ERROR;
+    }
+    strcpy(name, ifr4.ifr_name);
+    return 0;
+}
+
+static int reset_interface(const char *name)
+{
+    int inet4 = socket(AF_INET, SOCK_DGRAM, 0);
+
+    ifreq ifr4;
+    ifr4.ifr_flags = 0;
+    strncpy(ifr4.ifr_name, name, IFNAMSIZ);
+
+    if (ioctl(inet4, SIOCSIFFLAGS, &ifr4) && errno != ENODEV) {
+        LOGE("Cannot reset %s: %s", name, strerror(errno));
+        close(inet4);
+        return SYSTEM_ERROR;
+    }
+    close(inet4);
+    return 0;
+}
+
+static int check_interface(const char *name)
+{
+    int inet4 = socket(AF_INET, SOCK_DGRAM, 0);
+
+    ifreq ifr4;
+    strncpy(ifr4.ifr_name, name, IFNAMSIZ);
+    ifr4.ifr_flags = 0;
+
+    if (ioctl(inet4, SIOCGIFFLAGS, &ifr4) && errno != ENODEV) {
+        LOGE("Cannot check %s: %s", name, strerror(errno));
+    }
+    close(inet4);
+    return ifr4.ifr_flags;
+}
+
+static int bind_to_interface(int fd, const char *name)
+{
+    if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, name, strlen(name))) {
+        LOGE("Cannot bind socket to %s: %s", name, strerror(errno));
+        return SYSTEM_ERROR;
+    }
+    return 0;
+}
+
+//------------------------------------------------------------------------------
+
+static void throwException(JNIEnv *env, int error, const char *message)
+{
+    if (error == SYSTEM_ERROR) {
+        jniThrowException(env, "java/lang/IllegalStateException", message);
+    } else {
+        jniThrowException(env, "java/lang/IllegalArgumentException", message);
+    }
+}
+
+static jint establish(JNIEnv *env, jobject thiz,
+        jint mtu, jstring jAddresses, jstring jRoutes)
+{
+    char name[IFNAMSIZ];
+    int index;
+    int tun = create_interface(mtu, name, &index);
+    if (tun < 0) {
+        throwException(env, tun, "Cannot create interface");
+        return -1;
+    }
+    LOGD("%s is created", name);
+
+    const char *addresses;
+    const char *routes;
+    int count;
+
+    // Addresses are required.
+    addresses = jAddresses ? env->GetStringUTFChars(jAddresses, NULL) : NULL;
+    if (!addresses) {
+        jniThrowNullPointerException(env, "address");
+        goto error;
+    }
+    count = set_addresses(name, index, addresses);
+    env->ReleaseStringUTFChars(jAddresses, addresses);
+    if (count <= 0) {
+        throwException(env, count, "Cannot set address");
+        goto error;
+    }
+    LOGD("Configured %d address(es) on %s", count, name);
+
+    // Routes are optional.
+    routes = jRoutes ? env->GetStringUTFChars(jRoutes, NULL) : NULL;
+    if (routes) {
+        count = set_routes(name, index, routes);
+        env->ReleaseStringUTFChars(jRoutes, routes);
+        if (count < 0) {
+            throwException(env, count, "Cannot set route");
+            goto error;
+        }
+        LOGD("Configured %d route(s) on %s", count, name);
+    }
+
+    return tun;
+
+error:
+    close(tun);
+    LOGD("%s is destroyed", name);
+    return -1;
+}
+
+static jstring getName(JNIEnv *env, jobject thiz, jint fd)
+{
+    char name[IFNAMSIZ];
+    if (get_interface_name(name, fd) < 0) {
+        throwException(env, SYSTEM_ERROR, "Cannot get interface name");
+        return NULL;
+    }
+    return env->NewStringUTF(name);
+}
+
+static void reset(JNIEnv *env, jobject thiz, jstring jName)
+{
+    const char *name = jName ?
+            env->GetStringUTFChars(jName, NULL) : NULL;
+    if (!name) {
+        jniThrowNullPointerException(env, "name");
+        return;
+    }
+    if (reset_interface(name) < 0) {
+        throwException(env, SYSTEM_ERROR, "Cannot reset interface");
+    } else {
+        LOGD("%s is deactivated", name);
+    }
+    env->ReleaseStringUTFChars(jName, name);
+}
+
+static jint check(JNIEnv *env, jobject thiz, jstring jName)
+{
+    const char *name = jName ?
+            env->GetStringUTFChars(jName, NULL) : NULL;
+    if (!name) {
+        jniThrowNullPointerException(env, "name");
+        return 0;
+    }
+    int flags = check_interface(name);
+    env->ReleaseStringUTFChars(jName, name);
+    return flags;
+}
+
+static void protect(JNIEnv *env, jobject thiz, jint fd, jstring jName)
+{
+    const char *name = jName ?
+            env->GetStringUTFChars(jName, NULL) : NULL;
+    if (!name) {
+        jniThrowNullPointerException(env, "name");
+        return;
+    }
+    if (bind_to_interface(fd, name) < 0) {
+        throwException(env, SYSTEM_ERROR, "Cannot protect socket");
+    }
+    env->ReleaseStringUTFChars(jName, name);
+}
+
+//------------------------------------------------------------------------------
+
+static JNINativeMethod gMethods[] = {
+    {"nativeEstablish", "(ILjava/lang/String;Ljava/lang/String;)I", (void *)establish},
+    {"nativeGetName", "(I)Ljava/lang/String;", (void *)getName},
+    {"nativeReset", "(Ljava/lang/String;)V", (void *)reset},
+    {"nativeCheck", "(Ljava/lang/String;)I", (void *)check},
+    {"nativeProtect", "(ILjava/lang/String;)V", (void *)protect},
+};
+
+int register_android_server_connectivity_Vpn(JNIEnv *env)
+{
+    return jniRegisterNativeMethods(env, "com/android/server/connectivity/Vpn",
+            gMethods, NELEM(gMethods));
+}
+
+};
diff --git a/services/jni/onload.cpp b/services/jni/onload.cpp
index 0c46eee..9dff48b 100644
--- a/services/jni/onload.cpp
+++ b/services/jni/onload.cpp
@@ -29,10 +29,12 @@
 int register_android_server_InputManager(JNIEnv* env);
 int register_android_server_LightsService(JNIEnv* env);
 int register_android_server_PowerManagerService(JNIEnv* env);
-int register_android_server_UsbService(JNIEnv* env);
+int register_android_server_UsbDeviceManager(JNIEnv* env);
+int register_android_server_UsbHostManager(JNIEnv* env);
 int register_android_server_VibratorService(JNIEnv* env);
 int register_android_server_SystemServer(JNIEnv* env);
 int register_android_server_location_GpsLocationProvider(JNIEnv* env);
+int register_android_server_connectivity_Vpn(JNIEnv* env);
 };
 
 using namespace android;
@@ -57,10 +59,12 @@
     register_android_server_LightsService(env);
     register_android_server_AlarmManagerService(env);
     register_android_server_BatteryService(env);
-    register_android_server_UsbService(env);
+    register_android_server_UsbDeviceManager(env);
+    register_android_server_UsbHostManager(env);
     register_android_server_VibratorService(env);
     register_android_server_SystemServer(env);
     register_android_server_location_GpsLocationProvider(env);
+    register_android_server_connectivity_Vpn(env);
 
     return JNI_VERSION_1_4;
 }
diff --git a/services/sensorservice/Android.mk b/services/sensorservice/Android.mk
index 57a3b15..ba3e6e5 100644
--- a/services/sensorservice/Android.mk
+++ b/services/sensorservice/Android.mk
@@ -8,7 +8,6 @@
     LinearAccelerationSensor.cpp \
     OrientationSensor.cpp \
     RotationVectorSensor.cpp \
-    SecondOrderLowPassFilter.cpp \
     SensorDevice.cpp \
     SensorFusion.cpp \
     SensorInterface.cpp \
diff --git a/services/sensorservice/CorrectedGyroSensor.cpp b/services/sensorservice/CorrectedGyroSensor.cpp
index 9b75b70..1857443 100644
--- a/services/sensorservice/CorrectedGyroSensor.cpp
+++ b/services/sensorservice/CorrectedGyroSensor.cpp
@@ -45,7 +45,7 @@
         const sensors_event_t& event)
 {
     if (event.type == SENSOR_TYPE_GYROSCOPE) {
-        const vec3_t bias(mSensorFusion.getGyroBias() * mSensorFusion.getEstimatedRate());
+        const vec3_t bias(mSensorFusion.getGyroBias());
         *outEvent = event;
         outEvent->data[0] -= bias.x;
         outEvent->data[1] -= bias.y;
diff --git a/services/sensorservice/Fusion.cpp b/services/sensorservice/Fusion.cpp
index 56ac9f9..d706af5 100644
--- a/services/sensorservice/Fusion.cpp
+++ b/services/sensorservice/Fusion.cpp
@@ -24,15 +24,32 @@
 
 // -----------------------------------------------------------------------
 
-template <typename TYPE>
-static inline TYPE sqr(TYPE x) {
-    return x*x;
-}
+/*
+ * gyroVAR gives the measured variance of the gyro's output per
+ * Hz (or variance at 1 Hz). This is an "intrinsic" parameter of the gyro,
+ * which is independent of the sampling frequency.
+ *
+ * The variance of gyro's output at a given sampling period can be
+ * calculated as:
+ *      variance(T) = gyroVAR / T
+ *
+ * The variance of the INTEGRATED OUTPUT at a given sampling period can be
+ * calculated as:
+ *       variance_integrate_output(T) = gyroVAR * T
+ *
+ */
+static const float gyroVAR = 1e-7;      // (rad/s)^2 / Hz
+static const float biasVAR = 1e-8;      // (rad/s)^2 / s (guessed)
 
-template <typename T>
-static inline T clamp(T v) {
-    return v < 0 ? 0 : v;
-}
+/*
+ * Standard deviations of accelerometer and magnetometer
+ */
+static const float accSTDEV  = 0.05f;   // m/s^2 (measured 0.08 / CDD 0.05)
+static const float magSTDEV  = 0.5f;    // uT    (measured 0.7  / CDD 0.5)
+
+static const float FREE_FALL_THRESHOLD = 0.981f;
+
+// -----------------------------------------------------------------------
 
 template <typename TYPE, size_t C, size_t R>
 static mat<TYPE, R, R> scaleCovariance(
@@ -71,33 +88,6 @@
     return r;
 }
 
-template <typename TYPE>
-static mat<TYPE, 3, 3> MRPsToMatrix(const vec<TYPE, 3>& p) {
-    mat<TYPE, 3, 3> res(1);
-    const mat<TYPE, 3, 3> px(crossMatrix(p, 0));
-    const TYPE ptp(dot_product(p,p));
-    const TYPE t = 4/sqr(1+ptp);
-    res -= t * (1-ptp) * px;
-    res += t * 2 * sqr(px);
-    return res;
-}
-
-template <typename TYPE>
-vec<TYPE, 3> matrixToMRPs(const mat<TYPE, 3, 3>& R) {
-    // matrix to MRPs
-    vec<TYPE, 3> q;
-    const float Hx = R[0].x;
-    const float My = R[1].y;
-    const float Az = R[2].z;
-    const float w = 1 / (1 + sqrtf( clamp( Hx + My + Az + 1) * 0.25f ));
-    q.x = sqrtf( clamp( Hx - My - Az + 1) * 0.25f ) * w;
-    q.y = sqrtf( clamp(-Hx + My - Az + 1) * 0.25f ) * w;
-    q.z = sqrtf( clamp(-Hx - My + Az + 1) * 0.25f ) * w;
-    q.x = copysignf(q.x, R[2].y - R[1].z);
-    q.y = copysignf(q.y, R[0].z - R[2].x);
-    q.z = copysignf(q.z, R[1].x - R[0].y);
-    return q;
-}
 
 template<typename TYPE, size_t SIZE>
 class Covariance {
@@ -128,11 +118,8 @@
 // -----------------------------------------------------------------------
 
 Fusion::Fusion() {
-    // process noise covariance matrix
-    const float w1 = gyroSTDEV;
-    const float w2 = biasSTDEV;
-    Q[0] = w1*w1;
-    Q[1] = w2*w2;
+    Phi[0][1] = 0;
+    Phi[1][1] = 1;
 
     Ba.x = 0;
     Ba.y = 0;
@@ -146,25 +133,57 @@
 }
 
 void Fusion::init() {
-    // initial estimate: E{ x(t0) }
-    x = 0;
-
-    // initial covariance: Var{ x(t0) }
-    P = 0;
-
     mInitState = 0;
+    mGyroRate = 0;
     mCount[0] = 0;
     mCount[1] = 0;
     mCount[2] = 0;
     mData = 0;
 }
 
+void Fusion::initFusion(const vec4_t& q, float dT)
+{
+    // initial estimate: E{ x(t0) }
+    x0 = q;
+    x1 = 0;
+
+    // process noise covariance matrix: G.Q.Gt, with
+    //
+    //  G = | -1 0 |        Q = | q00 q10 |
+    //      |  0 1 |            | q01 q11 |
+    //
+    // q00 = sv^2.dt + 1/3.su^2.dt^3
+    // q10 = q01 = 1/2.su^2.dt^2
+    // q11 = su^2.dt
+    //
+
+    // variance of integrated output at 1/dT Hz
+    // (random drift)
+    const float q00 = gyroVAR * dT;
+
+    // variance of drift rate ramp
+    const float q11 = biasVAR * dT;
+
+    const float u   = q11 / dT;
+    const float q10 = 0.5f*u*dT*dT;
+    const float q01 = q10;
+
+    GQGt[0][0] =  q00;      // rad^2
+    GQGt[1][0] = -q10;
+    GQGt[0][1] = -q01;
+    GQGt[1][1] =  q11;      // (rad/s)^2
+
+    // initial covariance: Var{ x(t0) }
+    // TODO: initialize P correctly
+    P = 0;
+}
+
 bool Fusion::hasEstimate() const {
     return (mInitState == (MAG|ACC|GYRO));
 }
 
-bool Fusion::checkInitComplete(int what, const vec3_t& d) {
-    if (mInitState == (MAG|ACC|GYRO))
+bool Fusion::checkInitComplete(int what, const vec3_t& d, float dT) {
+    if (hasEstimate())
         return true;
 
     if (what == ACC) {
@@ -176,7 +195,8 @@
         mCount[1]++;
         mInitState |= MAG;
     } else if (what == GYRO) {
-        mData[2] += d;
+        mGyroRate = dT;
+        mData[2] += d*dT;
         mCount[2]++;
         if (mCount[2] == 64) {
             // 64 samples is good enough to estimate the gyro drift and
@@ -199,37 +219,29 @@
         east *= 1/length(east);
         vec3_t north(cross_product(up, east));
         R << east << north << up;
-        x[0] = matrixToMRPs(R);
+        const vec4_t q = matrixToQuat(R);
 
-        // NOTE: we could try to use the average of the gyro data
-        // to estimate the initial bias, but this only works if
-        // the device is not moving. For now, we don't use that value
-        // and start with a bias of 0.
-        x[1] = 0;
-
-        // initial covariance
-        P = 0;
+        initFusion(q, mGyroRate);
     }
 
     return false;
 }
 
 void Fusion::handleGyro(const vec3_t& w, float dT) {
-    const vec3_t wdT(w * dT);   // rad/s * s -> rad
-    if (!checkInitComplete(GYRO, wdT))
+    if (!checkInitComplete(GYRO, w, dT))
         return;
 
-    predict(wdT);
+    predict(w, dT);
 }
 
 status_t Fusion::handleAcc(const vec3_t& a) {
-    if (length(a) < 0.981f)
+    // ignore acceleration data if we're close to free-fall
+    if (length(a) < FREE_FALL_THRESHOLD)
         return BAD_VALUE;
 
     if (!checkInitComplete(ACC, a))
         return BAD_VALUE;
 
-    // ignore acceleration data if we're close to free-fall
     const float l = 1/length(a);
     update(a*l, Ba, accSTDEV*l);
     return NO_ERROR;
@@ -251,20 +263,6 @@
     const float l = 1 / length(north);
     north *= l;
 
-#if 0
-    // in practice the magnetic-field sensor is so wrong
-    // that there is no point trying to use it to constantly
-    // correct the gyro. instead, we use the mag-sensor only when
-    // the device points north (just to give us a reference).
-    // We're hoping that it'll actually point north, if it doesn't
-    // we'll be offset, but at least the instantaneous posture
-    // of the device will be correct.
-
-    const float cos_30 = 0.8660254f;
-    if (dot_product(north, Bm) < cos_30)
-        return BAD_VALUE;
-#endif
-
     update(north, Bm, magSTDEV*l);
     return NO_ERROR;
 }
@@ -273,7 +271,7 @@
     if (isnanf(length(v))) {
         LOGW("9-axis fusion diverged. reseting state.");
         P = 0;
-        x[1] = 0;
+        x1 = 0;
         mInitState = 0;
         mCount[0] = 0;
         mCount[1] = 0;
@@ -284,145 +282,89 @@
     return true;
 }
 
-vec3_t Fusion::getAttitude() const {
-    return x[0];
+vec4_t Fusion::getAttitude() const {
+    return x0;
 }
 
 vec3_t Fusion::getBias() const {
-    return x[1];
+    return x1;
 }
 
 mat33_t Fusion::getRotationMatrix() const {
-    return MRPsToMatrix(x[0]);
+    return quatToMatrix(x0);
 }
 
-mat33_t Fusion::getF(const vec3_t& p) {
-    const float p0 = p.x;
-    const float p1 = p.y;
-    const float p2 = p.z;
-
-    // f(p, w)
-    const float p0p1 = p0*p1;
-    const float p0p2 = p0*p2;
-    const float p1p2 = p1*p2;
-    const float p0p0 = p0*p0;
-    const float p1p1 = p1*p1;
-    const float p2p2 = p2*p2;
-    const float pp = 0.5f * (1 - (p0p0 + p1p1 + p2p2));
-
-    mat33_t F;
-    F[0][0] = 0.5f*(p0p0 + pp);
-    F[0][1] = 0.5f*(p0p1 + p2);
-    F[0][2] = 0.5f*(p0p2 - p1);
-    F[1][0] = 0.5f*(p0p1 - p2);
-    F[1][1] = 0.5f*(p1p1 + pp);
-    F[1][2] = 0.5f*(p1p2 + p0);
-    F[2][0] = 0.5f*(p0p2 + p1);
-    F[2][1] = 0.5f*(p1p2 - p0);
-    F[2][2] = 0.5f*(p2p2 + pp);
+mat34_t Fusion::getF(const vec4_t& q) {
+    mat34_t F;
+    F[0].x = q.w;   F[1].x =-q.z;   F[2].x = q.y;
+    F[0].y = q.z;   F[1].y = q.w;   F[2].y =-q.x;
+    F[0].z =-q.y;   F[1].z = q.x;   F[2].z = q.w;
+    F[0].w =-q.x;   F[1].w =-q.y;   F[2].w =-q.z;
     return F;
 }
 
-mat33_t Fusion::getdFdp(const vec3_t& p, const vec3_t& we) {
+void Fusion::predict(const vec3_t& w, float dT) {
+    const vec4_t q  = x0;
+    const vec3_t b  = x1;
+    const vec3_t we = w - b;
+    const vec4_t dq = getF(q)*((0.5f*dT)*we);
+    x0 = normalize_quat(q + dq);
 
-    // dF = | A = df/dp  -F |
-    //      |   0         0 |
+    // P(k+1) = F*P(k)*Ft + G*Q*Gt
 
-    mat33_t A;
-    A[0][0] = A[1][1] = A[2][2] = 0.5f * (p.x*we.x + p.y*we.y + p.z*we.z);
-    A[0][1] = 0.5f * (p.y*we.x - p.x*we.y - we.z);
-    A[0][2] = 0.5f * (p.z*we.x - p.x*we.z + we.y);
-    A[1][2] = 0.5f * (p.z*we.y - p.y*we.z - we.x);
-    A[1][0] = -A[0][1];
-    A[2][0] = -A[0][2];
-    A[2][1] = -A[1][2];
-    return A;
-}
+    //  Phi = | Phi00 Phi10 |
+    //        |   0     1   |
+    const mat33_t I33(1);
+    const mat33_t I33dT(dT);
+    const mat33_t wx(crossMatrix(we, 0));
+    const mat33_t wx2(wx*wx);
+    const float lwedT = length(we)*dT;
+    const float ilwe = 1/length(we);
+    const float k0 = (1-cosf(lwedT))*(ilwe*ilwe);
+    const float k1 = sinf(lwedT);
 
-void Fusion::predict(const vec3_t& w) {
-    // f(p, w)
-    vec3_t& p(x[0]);
+    Phi[0][0] = I33 - wx*(k1*ilwe) + wx2*k0;
+    Phi[1][0] = wx*k0 - I33dT - wx2*(ilwe*ilwe*ilwe)*(lwedT-k1);
 
-    // There is a discontinuity at 2.pi, to avoid it we need to switch to
-    // the shadow of p when pT.p gets too big.
-    const float ptp(dot_product(p,p));
-    if (ptp >= 2.0f) {
-        p = -p * (1/ptp);
-    }
-
-    const mat33_t F(getF(p));
-
-    // compute w with the bias correction:
-    //  w_estimated = w - b_estimated
-    const vec3_t& b(x[1]);
-    const vec3_t we(w - b);
-
-    // prediction
-    const vec3_t dX(F*we);
-
-    if (!checkState(dX))
-        return;
-
-    p += dX;
-
-    const mat33_t A(getdFdp(p, we));
-
-    // G  = | G0  0 |  =  | -F  0 |
-    //      |  0  1 |     |  0  1 |
-
-    // P += A*P + P*At + F*Q*Ft
-    const mat33_t AP(A*transpose(P[0][0]));
-    const mat33_t PAt(P[0][0]*transpose(A));
-    const mat33_t FPSt(F*transpose(P[1][0]));
-    const mat33_t PSFt(P[1][0]*transpose(F));
-    const mat33_t FQFt(scaleCovariance(F, Q[0]));
-    P[0][0] += AP + PAt - FPSt - PSFt + FQFt;
-    P[1][0] += A*P[1][0] - F*P[1][1];
-    P[1][1] += Q[1];
+    P = Phi*P*transpose(Phi) + GQGt;
 }
 
 void Fusion::update(const vec3_t& z, const vec3_t& Bi, float sigma) {
-    const vec3_t p(x[0]);
+    vec4_t q(x0);
     // measured vector in body space: h(p) = A(p)*Bi
-    const mat33_t A(MRPsToMatrix(p));
+    const mat33_t A(quatToMatrix(q));
     const vec3_t Bb(A*Bi);
 
     // Sensitivity matrix H = dh(p)/dp
     // H = [ L 0 ]
-    const float ptp(dot_product(p,p));
-    const mat33_t px(crossMatrix(p, 0.5f*(ptp-1)));
-    const mat33_t ppt(p*transpose(p));
-    const mat33_t L((8 / sqr(1+ptp))*crossMatrix(Bb, 0)*(ppt-px));
+    const mat33_t L(crossMatrix(Bb, 0));
 
-    // update...
+    // gain...
+    // K = P*Ht / [H*P*Ht + R]
+    vec<mat33_t, 2> K;
     const mat33_t R(sigma*sigma);
     const mat33_t S(scaleCovariance(L, P[0][0]) + R);
     const mat33_t Si(invert(S));
     const mat33_t LtSi(transpose(L)*Si);
-
-    vec<mat33_t, 2> K;
     K[0] = P[0][0] * LtSi;
     K[1] = transpose(P[1][0])*LtSi;
 
-    const vec3_t e(z - Bb);
-    const vec3_t K0e(K[0]*e);
-    const vec3_t K1e(K[1]*e);
-
-    if (!checkState(K0e))
-        return;
-
-    if (!checkState(K1e))
-        return;
-
-    x[0] += K0e;
-    x[1] += K1e;
-
+    // update...
     // P -= K*H*P;
     const mat33_t K0L(K[0] * L);
     const mat33_t K1L(K[1] * L);
     P[0][0] -= K0L*P[0][0];
     P[1][1] -= K1L*P[1][0];
     P[1][0] -= K0L*P[1][0];
+    P[0][1] = transpose(P[1][0]);
+
+    const vec3_t e(z - Bb);
+    const vec3_t dq(K[0]*e);
+    const vec3_t db(K[1]*e);
+
+    q += getF(q)*(0.5f*dq);
+    x0 = normalize_quat(q);
+    x1 += db;
 }
 
 // -----------------------------------------------------------------------
diff --git a/services/sensorservice/Fusion.h b/services/sensorservice/Fusion.h
index 571a415..556944b 100644
--- a/services/sensorservice/Fusion.h
+++ b/services/sensorservice/Fusion.h
@@ -19,42 +19,39 @@
 
 #include <utils/Errors.h>
 
-#include "vec.h"
+#include "quat.h"
 #include "mat.h"
+#include "vec.h"
 
 namespace android {
 
+typedef mat<float, 3, 4> mat34_t;
+
 class Fusion {
     /*
      * the state vector is made of two sub-vector containing respectively:
      * - modified Rodrigues parameters
      * - the estimated gyro bias
      */
-    vec<vec3_t, 2> x;
+    quat_t  x0;
+    vec3_t  x1;
 
     /*
      * the predicated covariance matrix is made of 4 3x3 sub-matrices and it
      * semi-definite positive.
      *
      * P = | P00  P10 | = | P00  P10 |
-     *     | P01  P11 |   | P10t  Q1 |
+     *     | P01  P11 |   | P10t P11 |
      *
      * Since P01 = transpose(P10), the code below never calculates or
-     * stores P01. P11 is always equal to Q1, so we don't store it either.
+     * stores P01.
      */
     mat<mat33_t, 2, 2> P;
 
     /*
-     * the process noise covariance matrix is made of 2 3x3 sub-matrices
-     * Q0 encodes the attitude's noise
-     * Q1 encodes the bias' noise
+     * the process noise covariance matrix
      */
-    vec<mat33_t, 2> Q;
-
-    static const float gyroSTDEV = 1.0e-5;  // rad/s (measured 1.2e-5)
-    static const float accSTDEV  = 0.05f;   // m/s^2 (measured 0.08 / CDD 0.05)
-    static const float magSTDEV  = 0.5f;    // uT    (measured 0.7  / CDD 0.5)
-    static const float biasSTDEV = 2e-9;    // rad/s^2 (guessed)
+    mat<mat33_t, 2, 2> GQGt;
 
 public:
     Fusion();
@@ -62,23 +59,25 @@
     void handleGyro(const vec3_t& w, float dT);
     status_t handleAcc(const vec3_t& a);
     status_t handleMag(const vec3_t& m);
-    vec3_t getAttitude() const;
+    vec4_t getAttitude() const;
     vec3_t getBias() const;
     mat33_t getRotationMatrix() const;
     bool hasEstimate() const;
 
 private:
+    mat<mat33_t, 2, 2> Phi;
     vec3_t Ba, Bm;
     uint32_t mInitState;
+    float mGyroRate;
     vec<vec3_t, 3> mData;
     size_t mCount[3];
     enum { ACC=0x1, MAG=0x2, GYRO=0x4 };
-    bool checkInitComplete(int, const vec3_t&);
+    bool checkInitComplete(int, const vec3_t& w, float d = 0);
+    void initFusion(const vec4_t& q0, float dT);
     bool checkState(const vec3_t& v);
-    void predict(const vec3_t& w);
+    void predict(const vec3_t& w, float dT);
     void update(const vec3_t& z, const vec3_t& Bi, float sigma);
-    static mat33_t getF(const vec3_t& p);
-    static mat33_t getdFdp(const vec3_t& p, const vec3_t& we);
+    static mat34_t getF(const vec4_t& p);
 };
 
 }; // namespace android
diff --git a/services/sensorservice/GravitySensor.cpp b/services/sensorservice/GravitySensor.cpp
index 541fad2..c57715f 100644
--- a/services/sensorservice/GravitySensor.cpp
+++ b/services/sensorservice/GravitySensor.cpp
@@ -31,10 +31,7 @@
 
 GravitySensor::GravitySensor(sensor_t const* list, size_t count)
     : mSensorDevice(SensorDevice::getInstance()),
-      mSensorFusion(SensorFusion::getInstance()),
-      mAccTime(0),
-      mLowPass(M_SQRT1_2, 1.5f),
-      mX(mLowPass), mY(mLowPass), mZ(mLowPass)
+      mSensorFusion(SensorFusion::getInstance())
 {
     for (size_t i=0 ; i<count ; i++) {
         if (list[i].type == SENSOR_TYPE_ACCELEROMETER) {
@@ -50,30 +47,14 @@
     const static double NS2S = 1.0 / 1000000000.0;
     if (event.type == SENSOR_TYPE_ACCELEROMETER) {
         vec3_t g;
-        if (mSensorFusion.hasGyro()) {
-            if (!mSensorFusion.hasEstimate())
-                return false;
-            const mat33_t R(mSensorFusion.getRotationMatrix());
-            // FIXME: we need to estimate the length of gravity because
-            // the accelerometer may have a small scaling error. This
-            // translates to an offset in the linear-acceleration sensor.
-            g = R[2] * GRAVITY_EARTH;
-        } else {
-            const double now = event.timestamp * NS2S;
-            if (mAccTime == 0) {
-                g.x = mX.init(event.acceleration.x);
-                g.y = mY.init(event.acceleration.y);
-                g.z = mZ.init(event.acceleration.z);
-            } else {
-                double dT = now - mAccTime;
-                mLowPass.setSamplingPeriod(dT);
-                g.x = mX(event.acceleration.x);
-                g.y = mY(event.acceleration.y);
-                g.z = mZ(event.acceleration.z);
-            }
-            g *= (GRAVITY_EARTH / length(g));
-            mAccTime = now;
-        }
+        if (!mSensorFusion.hasEstimate())
+            return false;
+        const mat33_t R(mSensorFusion.getRotationMatrix());
+        // FIXME: we need to estimate the length of gravity because
+        // the accelerometer may have a small scaling error. This
+        // translates to an offset in the linear-acceleration sensor.
+        g = R[2] * GRAVITY_EARTH;
+
         *outEvent = event;
         outEvent->data[0] = g.x;
         outEvent->data[1] = g.y;
@@ -86,42 +67,24 @@
 }
 
 status_t GravitySensor::activate(void* ident, bool enabled) {
-    status_t err;
-    if (mSensorFusion.hasGyro()) {
-        err = mSensorFusion.activate(this, enabled);
-    } else {
-        err = mSensorDevice.activate(this, mAccelerometer.getHandle(), enabled);
-        if (err == NO_ERROR) {
-            if (enabled) {
-                mAccTime = 0;
-            }
-        }
-    }
-    return err;
+    return mSensorFusion.activate(this, enabled);
 }
 
-status_t GravitySensor::setDelay(void* ident, int handle, int64_t ns)
-{
-    if (mSensorFusion.hasGyro()) {
-        return mSensorFusion.setDelay(this, ns);
-    } else {
-        return mSensorDevice.setDelay(this, mAccelerometer.getHandle(), ns);
-    }
+status_t GravitySensor::setDelay(void* ident, int handle, int64_t ns) {
+    return mSensorFusion.setDelay(this, ns);
 }
 
 Sensor GravitySensor::getSensor() const {
     sensor_t hwSensor;
     hwSensor.name       = "Gravity Sensor";
     hwSensor.vendor     = "Google Inc.";
-    hwSensor.version    = mSensorFusion.hasGyro() ? 3 : 2;
+    hwSensor.version    = 3;
     hwSensor.handle     = '_grv';
     hwSensor.type       = SENSOR_TYPE_GRAVITY;
     hwSensor.maxRange   = GRAVITY_EARTH * 2;
     hwSensor.resolution = mAccelerometer.getResolution();
-    hwSensor.power      = mSensorFusion.hasGyro() ?
-            mSensorFusion.getPowerUsage() : mAccelerometer.getPowerUsage();
-    hwSensor.minDelay   = mSensorFusion.hasGyro() ?
-            mSensorFusion.getMinDelay() : mAccelerometer.getMinDelay();
+    hwSensor.power      = mSensorFusion.getPowerUsage();
+    hwSensor.minDelay   = mSensorFusion.getMinDelay();
     Sensor sensor(&hwSensor);
     return sensor;
 }
diff --git a/services/sensorservice/GravitySensor.h b/services/sensorservice/GravitySensor.h
index 0ca3a3c..ac177c4 100644
--- a/services/sensorservice/GravitySensor.h
+++ b/services/sensorservice/GravitySensor.h
@@ -23,7 +23,6 @@
 #include <gui/Sensor.h>
 
 #include "SensorInterface.h"
-#include "SecondOrderLowPassFilter.h"
 
 // ---------------------------------------------------------------------------
 namespace android {
@@ -36,10 +35,6 @@
     SensorDevice& mSensorDevice;
     SensorFusion& mSensorFusion;
     Sensor mAccelerometer;
-    double mAccTime;
-
-    SecondOrderLowPassFilter mLowPass;
-    CascadedBiquadFilter<float> mX, mY, mZ;
 
 public:
     GravitySensor(sensor_t const* list, size_t count);
diff --git a/services/sensorservice/OrientationSensor.cpp b/services/sensorservice/OrientationSensor.cpp
index c9e5080..037adaa 100644
--- a/services/sensorservice/OrientationSensor.cpp
+++ b/services/sensorservice/OrientationSensor.cpp
@@ -50,9 +50,10 @@
                 g[0] += 360;
 
             *outEvent = event;
-            outEvent->data[0] = g.x;
-            outEvent->data[1] = g.y;
-            outEvent->data[2] = g.z;
+            outEvent->orientation.azimuth = g.x;
+            outEvent->orientation.pitch   = g.y;
+            outEvent->orientation.roll    = g.z;
+            outEvent->orientation.status  = SENSOR_STATUS_ACCURACY_HIGH;
             outEvent->sensor = '_ypr';
             outEvent->type = SENSOR_TYPE_ORIENTATION;
             return true;
diff --git a/services/sensorservice/RotationVectorSensor.cpp b/services/sensorservice/RotationVectorSensor.cpp
index cba89c9..5ea9568 100644
--- a/services/sensorservice/RotationVectorSensor.cpp
+++ b/services/sensorservice/RotationVectorSensor.cpp
@@ -27,11 +27,6 @@
 namespace android {
 // ---------------------------------------------------------------------------
 
-template <typename T>
-static inline T clamp(T v) {
-    return v < 0 ? 0 : v;
-}
-
 RotationVectorSensor::RotationVectorSensor()
     : mSensorDevice(SensorDevice::getInstance()),
       mSensorFusion(SensorFusion::getInstance())
@@ -43,29 +38,12 @@
 {
     if (event.type == SENSOR_TYPE_ACCELEROMETER) {
         if (mSensorFusion.hasEstimate()) {
-            const mat33_t R(mSensorFusion.getRotationMatrix());
-
-            // matrix to rotation vector (normalized quaternion)
-            const float Hx = R[0].x;
-            const float My = R[1].y;
-            const float Az = R[2].z;
-
-            float qw = sqrtf( clamp( Hx + My + Az + 1) * 0.25f );
-            float qx = sqrtf( clamp( Hx - My - Az + 1) * 0.25f );
-            float qy = sqrtf( clamp(-Hx + My - Az + 1) * 0.25f );
-            float qz = sqrtf( clamp(-Hx - My + Az + 1) * 0.25f );
-            qx = copysignf(qx, R[2].y - R[1].z);
-            qy = copysignf(qy, R[0].z - R[2].x);
-            qz = copysignf(qz, R[1].x - R[0].y);
-
-            // this quaternion is guaranteed to be normalized, by construction
-            // of the rotation matrix.
-
+            const vec4_t q(mSensorFusion.getAttitude());
             *outEvent = event;
-            outEvent->data[0] = qx;
-            outEvent->data[1] = qy;
-            outEvent->data[2] = qz;
-            outEvent->data[3] = qw;
+            outEvent->data[0] = q.x;
+            outEvent->data[1] = q.y;
+            outEvent->data[2] = q.z;
+            outEvent->data[3] = q.w;
             outEvent->sensor = '_rov';
             outEvent->type = SENSOR_TYPE_ROTATION_VECTOR;
             return true;
@@ -86,7 +64,7 @@
     sensor_t hwSensor;
     hwSensor.name       = "Rotation Vector Sensor";
     hwSensor.vendor     = "Google Inc.";
-    hwSensor.version    = mSensorFusion.hasGyro() ? 3 : 2;
+    hwSensor.version    = 3;
     hwSensor.handle     = '_rov';
     hwSensor.type       = SENSOR_TYPE_ROTATION_VECTOR;
     hwSensor.maxRange   = 1;
@@ -98,5 +76,54 @@
 }
 
 // ---------------------------------------------------------------------------
+
+GyroDriftSensor::GyroDriftSensor()
+    : mSensorDevice(SensorDevice::getInstance()),
+      mSensorFusion(SensorFusion::getInstance())
+{
+}
+
+bool GyroDriftSensor::process(sensors_event_t* outEvent,
+        const sensors_event_t& event)
+{
+    if (event.type == SENSOR_TYPE_ACCELEROMETER) {
+        if (mSensorFusion.hasEstimate()) {
+            const vec3_t b(mSensorFusion.getGyroBias());
+            *outEvent = event;
+            outEvent->data[0] = b.x;
+            outEvent->data[1] = b.y;
+            outEvent->data[2] = b.z;
+            outEvent->sensor = '_gbs';
+            outEvent->type = SENSOR_TYPE_ACCELEROMETER;
+            return true;
+        }
+    }
+    return false;
+}
+
+status_t GyroDriftSensor::activate(void* ident, bool enabled) {
+    return mSensorFusion.activate(this, enabled);
+}
+
+status_t GyroDriftSensor::setDelay(void* ident, int handle, int64_t ns) {
+    return mSensorFusion.setDelay(this, ns);
+}
+
+Sensor GyroDriftSensor::getSensor() const {
+    sensor_t hwSensor;
+    hwSensor.name       = "Gyroscope Bias (debug)";
+    hwSensor.vendor     = "Google Inc.";
+    hwSensor.version    = 1;
+    hwSensor.handle     = '_gbs';
+    hwSensor.type       = SENSOR_TYPE_ACCELEROMETER;
+    hwSensor.maxRange   = 1;
+    hwSensor.resolution = 1.0f / (1<<24);
+    hwSensor.power      = mSensorFusion.getPowerUsage();
+    hwSensor.minDelay   = mSensorFusion.getMinDelay();
+    Sensor sensor(&hwSensor);
+    return sensor;
+}
+
+// ---------------------------------------------------------------------------
 }; // namespace android
 
diff --git a/services/sensorservice/RotationVectorSensor.h b/services/sensorservice/RotationVectorSensor.h
index ac76487..bb97fe1 100644
--- a/services/sensorservice/RotationVectorSensor.h
+++ b/services/sensorservice/RotationVectorSensor.h
@@ -24,7 +24,6 @@
 
 #include "SensorDevice.h"
 #include "SensorInterface.h"
-#include "SecondOrderLowPassFilter.h"
 
 #include "Fusion.h"
 #include "SensorFusion.h"
@@ -47,6 +46,20 @@
     virtual bool isVirtual() const { return true; }
 };
 
+class GyroDriftSensor : public SensorInterface {
+    SensorDevice& mSensorDevice;
+    SensorFusion& mSensorFusion;
+
+public:
+    GyroDriftSensor();
+    virtual bool process(sensors_event_t* outEvent,
+            const sensors_event_t& event);
+    virtual status_t activate(void* ident, bool enabled);
+    virtual status_t setDelay(void* ident, int handle, int64_t ns);
+    virtual Sensor getSensor() const;
+    virtual bool isVirtual() const { return true; }
+};
+
 // ---------------------------------------------------------------------------
 }; // namespace android
 
diff --git a/services/sensorservice/SecondOrderLowPassFilter.cpp b/services/sensorservice/SecondOrderLowPassFilter.cpp
deleted file mode 100644
index c76dd4c..0000000
--- a/services/sensorservice/SecondOrderLowPassFilter.cpp
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdint.h>
-#include <sys/types.h>
-#include <math.h>
-
-#include <cutils/log.h>
-
-#include "SecondOrderLowPassFilter.h"
-#include "vec.h"
-
-// ---------------------------------------------------------------------------
-
-namespace android {
-// ---------------------------------------------------------------------------
-
-SecondOrderLowPassFilter::SecondOrderLowPassFilter(float Q, float fc)
-    : iQ(1.0f / Q), fc(fc)
-{
-}
-
-void SecondOrderLowPassFilter::setSamplingPeriod(float dT)
-{
-    K = tanf(float(M_PI) * fc * dT);
-    iD = 1.0f / (K*K + K*iQ + 1);
-    a0 = K*K*iD;
-    a1 = 2.0f * a0;
-    b1 = 2.0f*(K*K - 1)*iD;
-    b2 = (K*K - K*iQ + 1)*iD;
-}
-
-// ---------------------------------------------------------------------------
-
-template<typename T>
-BiquadFilter<T>::BiquadFilter(const SecondOrderLowPassFilter& s)
-    : s(s)
-{
-}
-
-template<typename T>
-T BiquadFilter<T>::init(const T& x)
-{
-    x1 = x2 = x;
-    y1 = y2 = x;
-    return x;
-}
-
-template<typename T>
-T BiquadFilter<T>::operator()(const T& x)
-{
-    T y = (x + x2)*s.a0 + x1*s.a1 - y1*s.b1 - y2*s.b2;
-    x2 = x1;
-    y2 = y1;
-    x1 = x;
-    y1 = y;
-    return y;
-}
-
-// ---------------------------------------------------------------------------
-
-template<typename T>
-CascadedBiquadFilter<T>::CascadedBiquadFilter(const SecondOrderLowPassFilter& s)
-    : mA(s), mB(s)
-{
-}
-
-template<typename T>
-T CascadedBiquadFilter<T>::init(const T& x)
-{
-    mA.init(x);
-    mB.init(x);
-    return x;
-}
-
-template<typename T>
-T CascadedBiquadFilter<T>::operator()(const T& x)
-{
-    return mB(mA(x));
-}
-
-// ---------------------------------------------------------------------------
-
-template class BiquadFilter<float>;
-template class CascadedBiquadFilter<float>;
-template class BiquadFilter<vec3_t>;
-template class CascadedBiquadFilter<vec3_t>;
-
-// ---------------------------------------------------------------------------
-}; // namespace android
diff --git a/services/sensorservice/SecondOrderLowPassFilter.h b/services/sensorservice/SecondOrderLowPassFilter.h
deleted file mode 100644
index 0cc2446..0000000
--- a/services/sensorservice/SecondOrderLowPassFilter.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ANDROID_SECOND_ORDER_LOW_PASS_FILTER_H
-#define ANDROID_SECOND_ORDER_LOW_PASS_FILTER_H
-
-#include <stdint.h>
-#include <sys/types.h>
-
-// ---------------------------------------------------------------------------
-
-namespace android {
-// ---------------------------------------------------------------------------
-
-template<typename T>
-class BiquadFilter;
-
-/*
- * State of a 2nd order low-pass IIR filter
- */
-class SecondOrderLowPassFilter {
-    template<typename T>
-    friend class BiquadFilter;
-    float iQ, fc;
-    float K, iD;
-    float a0, a1;
-    float b1, b2;
-public:
-    SecondOrderLowPassFilter(float Q, float fc);
-    void setSamplingPeriod(float dT);
-};
-
-/*
- * Implements a Biquad IIR filter
- */
-template<typename T>
-class BiquadFilter {
-    T x1, x2;
-    T y1, y2;
-    const SecondOrderLowPassFilter& s;
-public:
-    BiquadFilter(const SecondOrderLowPassFilter& s);
-    T init(const T& in);
-    T operator()(const T& in);
-};
-
-/*
- * Two cascaded biquad IIR filters
- * (4-poles IIR)
- */
-template<typename T>
-class CascadedBiquadFilter {
-    BiquadFilter<T> mA;
-    BiquadFilter<T> mB;
-public:
-    CascadedBiquadFilter(const SecondOrderLowPassFilter& s);
-    T init(const T& in);
-    T operator()(const T& in);
-};
-
-// ---------------------------------------------------------------------------
-}; // namespace android
-
-#endif // ANDROID_SECOND_ORDER_LOW_PASS_FILTER_H
diff --git a/services/sensorservice/SensorFusion.cpp b/services/sensorservice/SensorFusion.cpp
index d4226ec1..4ec0c8c 100644
--- a/services/sensorservice/SensorFusion.cpp
+++ b/services/sensorservice/SensorFusion.cpp
@@ -25,9 +25,7 @@
 
 SensorFusion::SensorFusion()
     : mSensorDevice(SensorDevice::getInstance()),
-      mEnabled(false), mHasGyro(false), mGyroTime(0), mRotationMatrix(1),
-      mLowPass(M_SQRT1_2, 1.0f), mAccData(mLowPass),
-      mFilteredMag(0.0f), mFilteredAcc(0.0f)
+      mEnabled(false), mGyroTime(0)
 {
     sensor_t const* list;
     size_t count = mSensorDevice.getSensorList(&list);
@@ -42,55 +40,32 @@
             mGyro = Sensor(list + i);
             // 200 Hz for gyro events is a good compromise between precision
             // and power/cpu usage.
-            mTargetDelayNs = 1000000000LL/200;
-            mGyroRate = 1000000000.0f / mTargetDelayNs;
-            mHasGyro = true;
+            mGyroRate = 200;
+            mTargetDelayNs = 1000000000LL/mGyroRate;
         }
     }
     mFusion.init();
-    mAccData.init(vec3_t(0.0f));
 }
 
 void SensorFusion::process(const sensors_event_t& event) {
-
-    if (event.type == SENSOR_TYPE_GYROSCOPE && mHasGyro) {
+    if (event.type == SENSOR_TYPE_GYROSCOPE) {
         if (mGyroTime != 0) {
             const float dT = (event.timestamp - mGyroTime) / 1000000000.0f;
             const float freq = 1 / dT;
-            const float alpha = 2 / (2 + dT); // 2s time-constant
-            mGyroRate = mGyroRate*alpha +  freq*(1 - alpha);
+            if (freq >= 100 && freq<1000) { // filter values obviously wrong
+                const float alpha = 1 / (1 + dT); // 1s time-constant
+                mGyroRate = freq + (mGyroRate - freq)*alpha;
+            }
         }
         mGyroTime = event.timestamp;
         mFusion.handleGyro(vec3_t(event.data), 1.0f/mGyroRate);
     } else if (event.type == SENSOR_TYPE_MAGNETIC_FIELD) {
         const vec3_t mag(event.data);
-        if (mHasGyro) {
-            mFusion.handleMag(mag);
-        } else {
-            const float l(length(mag));
-            if (l>5 && l<100) {
-                mFilteredMag = mag * (1/l);
-            }
-        }
+        mFusion.handleMag(mag);
     } else if (event.type == SENSOR_TYPE_ACCELEROMETER) {
         const vec3_t acc(event.data);
-        if (mHasGyro) {
-            mFusion.handleAcc(acc);
-            mRotationMatrix = mFusion.getRotationMatrix();
-        } else {
-            const float l(length(acc));
-            if (l > 0.981f) {
-                // remove the linear-acceleration components
-                mFilteredAcc = mAccData(acc * (1/l));
-            }
-            if (length(mFilteredAcc)>0 && length(mFilteredMag)>0) {
-                vec3_t up(mFilteredAcc);
-                vec3_t east(cross_product(mFilteredMag, up));
-                east *= 1/length(east);
-                vec3_t north(cross_product(up, east));
-                mRotationMatrix << east << north << up;
-            }
-        }
+        mFusion.handleAcc(acc);
+        mAttitude = mFusion.getAttitude();
     }
 }
 
@@ -116,40 +91,31 @@
 
     mSensorDevice.activate(ident, mAcc.getHandle(), enabled);
     mSensorDevice.activate(ident, mMag.getHandle(), enabled);
-    if (mHasGyro) {
-        mSensorDevice.activate(ident, mGyro.getHandle(), enabled);
-    }
+    mSensorDevice.activate(ident, mGyro.getHandle(), enabled);
 
     const bool newState = mClients.size() != 0;
     if (newState != mEnabled) {
         mEnabled = newState;
         if (newState) {
             mFusion.init();
+            mGyroTime = 0;
         }
     }
     return NO_ERROR;
 }
 
 status_t SensorFusion::setDelay(void* ident, int64_t ns) {
-    if (mHasGyro) {
-        mSensorDevice.setDelay(ident, mAcc.getHandle(), ns);
-        mSensorDevice.setDelay(ident, mMag.getHandle(), ms2ns(20));
-        mSensorDevice.setDelay(ident, mGyro.getHandle(), mTargetDelayNs);
-    } else {
-        const static double NS2S = 1.0 / 1000000000.0;
-        mSensorDevice.setDelay(ident, mAcc.getHandle(), ns);
-        mSensorDevice.setDelay(ident, mMag.getHandle(), max(ns, mMag.getMinDelayNs()));
-        mLowPass.setSamplingPeriod(ns*NS2S);
-    }
+    mSensorDevice.setDelay(ident, mAcc.getHandle(), ns);
+    mSensorDevice.setDelay(ident, mMag.getHandle(), ms2ns(20));
+    mSensorDevice.setDelay(ident, mGyro.getHandle(), mTargetDelayNs);
     return NO_ERROR;
 }
 
 
 float SensorFusion::getPowerUsage() const {
-    float power = mAcc.getPowerUsage() + mMag.getPowerUsage();
-    if (mHasGyro) {
-        power += mGyro.getPowerUsage();
-    }
+    float power =   mAcc.getPowerUsage() +
+                    mMag.getPowerUsage() +
+                    mGyro.getPowerUsage();
     return power;
 }
 
@@ -159,17 +125,17 @@
 
 void SensorFusion::dump(String8& result, char* buffer, size_t SIZE) {
     const Fusion& fusion(mFusion);
-    snprintf(buffer, SIZE, "Fusion (%s) %s (%d clients), gyro-rate=%7.2fHz, "
-            "MRPS=< %g, %g, %g > (%g), "
-            "BIAS=< %g, %g, %g >\n",
-            mHasGyro ? "9-axis" : "6-axis",
+    snprintf(buffer, SIZE, "9-axis fusion %s (%d clients), gyro-rate=%7.2fHz, "
+            "q=< %g, %g, %g, %g > (%g), "
+            "b=< %g, %g, %g >\n",
             mEnabled ? "enabled" : "disabled",
             mClients.size(),
             mGyroRate,
             fusion.getAttitude().x,
             fusion.getAttitude().y,
             fusion.getAttitude().z,
-            dot_product(fusion.getAttitude(), fusion.getAttitude()),
+            fusion.getAttitude().w,
+            length(fusion.getAttitude()),
             fusion.getBias().x,
             fusion.getBias().y,
             fusion.getBias().z);
diff --git a/services/sensorservice/SensorFusion.h b/services/sensorservice/SensorFusion.h
index c7eab12..4c99bcb 100644
--- a/services/sensorservice/SensorFusion.h
+++ b/services/sensorservice/SensorFusion.h
@@ -27,7 +27,6 @@
 #include <gui/Sensor.h>
 
 #include "Fusion.h"
-#include "SecondOrderLowPassFilter.h"
 
 // ---------------------------------------------------------------------------
 
@@ -45,15 +44,10 @@
     Sensor mGyro;
     Fusion mFusion;
     bool mEnabled;
-    bool mHasGyro;
     float mGyroRate;
     nsecs_t mTargetDelayNs;
     nsecs_t mGyroTime;
-    mat33_t mRotationMatrix;
-    SecondOrderLowPassFilter mLowPass;
-    BiquadFilter<vec3_t> mAccData;
-    vec3_t mFilteredMag;
-    vec3_t mFilteredAcc;
+    vec4_t mAttitude;
     SortedVector<void*> mClients;
 
     SensorFusion();
@@ -62,9 +56,9 @@
     void process(const sensors_event_t& event);
 
     bool isEnabled() const { return mEnabled; }
-    bool hasGyro() const { return mHasGyro; }
-    bool hasEstimate() const { return !mHasGyro || mFusion.hasEstimate(); }
-    mat33_t getRotationMatrix() const { return mRotationMatrix; }
+    bool hasEstimate() const { return mFusion.hasEstimate(); }
+    mat33_t getRotationMatrix() const { return mFusion.getRotationMatrix(); }
+    vec4_t getAttitude() const { return mAttitude; }
     vec3_t getGyroBias() const { return mFusion.getBias(); }
     float getEstimatedRate() const { return mGyroRate; }
 
diff --git a/services/sensorservice/SensorService.cpp b/services/sensorservice/SensorService.cpp
index 5b86d10..0ae7929 100644
--- a/services/sensorservice/SensorService.cpp
+++ b/services/sensorservice/SensorService.cpp
@@ -18,6 +18,8 @@
 #include <math.h>
 #include <sys/types.h>
 
+#include <cutils/properties.h>
+
 #include <utils/SortedVector.h>
 #include <utils/KeyedVector.h>
 #include <utils/threads.h>
@@ -46,6 +48,15 @@
 namespace android {
 // ---------------------------------------------------------------------------
 
+/*
+ * Notes:
+ *
+ * - what about a gyro-corrected magnetic-field sensor?
+ * - run mag sensor from time to time to force calibration
+ * - gravity sensor length is wrong (=> drift in linear-acc sensor)
+ *
+ */
+
 SensorService::SensorService()
     : mDump("android.permission.DUMP"),
       mInitCheck(NO_INIT)
@@ -59,6 +70,8 @@
     SensorDevice& dev(SensorDevice::getInstance());
 
     if (dev.initCheck() == NO_ERROR) {
+        ssize_t orientationIndex = -1;
+        bool hasGyro = false;
         uint32_t virtualSensorsNeeds =
                 (1<<SENSOR_TYPE_GRAVITY) |
                 (1<<SENSOR_TYPE_LINEAR_ACCELERATION) |
@@ -69,6 +82,12 @@
         for (int i=0 ; i<count ; i++) {
             registerSensor( new HardwareSensor(list[i]) );
             switch (list[i].type) {
+                case SENSOR_TYPE_ORIENTATION:
+                    orientationIndex = i;
+                    break;
+                case SENSOR_TYPE_GYROSCOPE:
+                    hasGyro = true;
+                    break;
                 case SENSOR_TYPE_GRAVITY:
                 case SENSOR_TYPE_LINEAR_ACCELERATION:
                 case SENSOR_TYPE_ROTATION_VECTOR:
@@ -82,21 +101,38 @@
         // registered)
         const SensorFusion& fusion(SensorFusion::getInstance());
 
-        // Always instantiate Android's virtual sensors. Since they are
-        // instantiated behind sensors from the HAL, they won't
-        // interfere with applications, unless they looks specifically
-        // for them (by name).
+        if (hasGyro) {
+            // Always instantiate Android's virtual sensors. Since they are
+            // instantiated behind sensors from the HAL, they won't
+            // interfere with applications, unless they looks specifically
+            // for them (by name).
 
-        registerVirtualSensor( new RotationVectorSensor() );
-        registerVirtualSensor( new GravitySensor(list, count) );
-        registerVirtualSensor( new LinearAccelerationSensor(list, count) );
+            registerVirtualSensor( new RotationVectorSensor() );
+            registerVirtualSensor( new GravitySensor(list, count) );
+            registerVirtualSensor( new LinearAccelerationSensor(list, count) );
 
-        // if we have a gyro, we have the option of enabling these
-        // "better" orientation and gyro sensors
-        if (fusion.hasGyro()) {
-            // FIXME: OrientationSensor buggy when not pointing north
+            // these are optional
             registerVirtualSensor( new OrientationSensor() );
             registerVirtualSensor( new CorrectedGyroSensor(list, count) );
+
+            // virtual debugging sensors...
+            char value[PROPERTY_VALUE_MAX];
+            property_get("debug.sensors", value, "0");
+            if (atoi(value)) {
+                registerVirtualSensor( new GyroDriftSensor() );
+            }
+        }
+
+        // build the sensor list returned to users
+        mUserSensorList = mSensorList;
+        if (hasGyro &&
+                (virtualSensorsNeeds & (1<<SENSOR_TYPE_ROTATION_VECTOR))) {
+            // if we have the fancy sensor fusion, and it's not provided by the
+            // HAL, use our own (fused) orientation sensor by removing the
+            // HAL supplied one form the user list.
+            if (orientationIndex >= 0) {
+                mUserSensorList.removeItemsAt(orientationIndex);
+            }
         }
 
         run("SensorService", PRIORITY_URGENT_DISPLAY);
@@ -294,9 +330,9 @@
 }
 
 String8 SensorService::getSensorName(int handle) const {
-    size_t count = mSensorList.size();
+    size_t count = mUserSensorList.size();
     for (size_t i=0 ; i<count ; i++) {
-        const Sensor& sensor(mSensorList[i]);
+        const Sensor& sensor(mUserSensorList[i]);
         if (sensor.getHandle() == handle) {
             return sensor.getName();
         }
@@ -307,7 +343,7 @@
 
 Vector<Sensor> SensorService::getSensorList()
 {
-    return mSensorList;
+    return mUserSensorList;
 }
 
 sp<ISensorEventConnection> SensorService::createSensorEventConnection()
diff --git a/services/sensorservice/SensorService.h b/services/sensorservice/SensorService.h
index 77a7e34..4d0f1d9 100644
--- a/services/sensorservice/SensorService.h
+++ b/services/sensorservice/SensorService.h
@@ -114,6 +114,7 @@
 
     // constants
     Vector<Sensor> mSensorList;
+    Vector<Sensor> mUserSensorList;
     DefaultKeyedVector<int, SensorInterface*> mSensorMap;
     Vector<SensorInterface *> mVirtualSensorList;
     Permission mDump;
diff --git a/services/sensorservice/quat.h b/services/sensorservice/quat.h
new file mode 100644
index 0000000..fea1afe
--- /dev/null
+++ b/services/sensorservice/quat.h
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_QUAT_H
+#define ANDROID_QUAT_H
+
+#include <math.h>
+
+#include "vec.h"
+#include "mat.h"
+
+// -----------------------------------------------------------------------
+namespace android {
+// -----------------------------------------------------------------------
+
+template <typename TYPE>
+mat<TYPE, 3, 3> quatToMatrix(const vec<TYPE, 4>& q) {
+    mat<TYPE, 3, 3> R;
+    TYPE q0(q.w);
+    TYPE q1(q.x);
+    TYPE q2(q.y);
+    TYPE q3(q.z);
+    TYPE sq_q1 = 2 * q1 * q1;
+    TYPE sq_q2 = 2 * q2 * q2;
+    TYPE sq_q3 = 2 * q3 * q3;
+    TYPE q1_q2 = 2 * q1 * q2;
+    TYPE q3_q0 = 2 * q3 * q0;
+    TYPE q1_q3 = 2 * q1 * q3;
+    TYPE q2_q0 = 2 * q2 * q0;
+    TYPE q2_q3 = 2 * q2 * q3;
+    TYPE q1_q0 = 2 * q1 * q0;
+    R[0][0] = 1 - sq_q2 - sq_q3;
+    R[0][1] = q1_q2 - q3_q0;
+    R[0][2] = q1_q3 + q2_q0;
+    R[1][0] = q1_q2 + q3_q0;
+    R[1][1] = 1 - sq_q1 - sq_q3;
+    R[1][2] = q2_q3 - q1_q0;
+    R[2][0] = q1_q3 - q2_q0;
+    R[2][1] = q2_q3 + q1_q0;
+    R[2][2] = 1 - sq_q1 - sq_q2;
+    return R;
+}
+
+template <typename TYPE>
+vec<TYPE, 4> matrixToQuat(const mat<TYPE, 3, 3>& R) {
+    // matrix to quaternion
+
+    struct {
+        inline TYPE operator()(TYPE v) {
+            return v < 0 ? 0 : v;
+        }
+    } clamp;
+
+    vec<TYPE, 4> q;
+    const float Hx = R[0].x;
+    const float My = R[1].y;
+    const float Az = R[2].z;
+    q.x = sqrtf( clamp( Hx - My - Az + 1) * 0.25f );
+    q.y = sqrtf( clamp(-Hx + My - Az + 1) * 0.25f );
+    q.z = sqrtf( clamp(-Hx - My + Az + 1) * 0.25f );
+    q.w = sqrtf( clamp( Hx + My + Az + 1) * 0.25f );
+    q.x = copysignf(q.x, R[2].y - R[1].z);
+    q.y = copysignf(q.y, R[0].z - R[2].x);
+    q.z = copysignf(q.z, R[1].x - R[0].y);
+    // guaranteed to be unit-quaternion
+    return q;
+}
+
+template <typename TYPE>
+vec<TYPE, 4> normalize_quat(const vec<TYPE, 4>& q) {
+    vec<TYPE, 4> r(q);
+    if (r.w < 0) {
+        r = -r;
+    }
+    return normalize(r);
+}
+
+// -----------------------------------------------------------------------
+
+typedef vec4_t quat_t;
+
+// -----------------------------------------------------------------------
+}; // namespace android
+
+#endif /* ANDROID_QUAT_H */
diff --git a/services/sensorservice/vec.h b/services/sensorservice/vec.h
index 736ff37..f74ccc5 100644
--- a/services/sensorservice/vec.h
+++ b/services/sensorservice/vec.h
@@ -208,6 +208,15 @@
 }
 
 template <
+    template<typename T, size_t S> class V,
+    typename TYPE,
+    size_t SIZE
+>
+V<TYPE, SIZE> PURE normalize(const V<TYPE, SIZE>& v) {
+    return v * (1/length(v));
+}
+
+template <
     template<typename T, size_t S> class VLHS,
     template<typename T, size_t S> class VRHS,
     typename TYPE
diff --git a/services/surfaceflinger/Android.mk b/services/surfaceflinger/Android.mk
index 9daaad8..c618263 100644
--- a/services/surfaceflinger/Android.mk
+++ b/services/surfaceflinger/Android.mk
@@ -2,18 +2,18 @@
 include $(CLEAR_VARS)
 
 LOCAL_SRC_FILES:= \
-    clz.cpp.arm \
-    DisplayHardware/DisplayHardware.cpp \
+    Layer.cpp 								\
+    LayerBase.cpp 							\
+    LayerDim.cpp 							\
+    DisplayHardware/DisplayHardware.cpp 	\
     DisplayHardware/DisplayHardwareBase.cpp \
-    DisplayHardware/HWComposer.cpp \
-    GLExtensions.cpp \
-    Layer.cpp \
-    LayerBase.cpp \
-    LayerDim.cpp \
-    MessageQueue.cpp \
-    SurfaceFlinger.cpp \
-    TextureManager.cpp \
-    Transform.cpp
+    DisplayHardware/HWComposer.cpp 			\
+    GLExtensions.cpp 						\
+    MessageQueue.cpp 						\
+    SurfaceFlinger.cpp 						\
+    SurfaceTextureLayer.cpp 				\
+    Transform.cpp 							\
+    
 
 LOCAL_CFLAGS:= -DLOG_TAG=\"SurfaceFlinger\"
 LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index 8df2b92..2bab6a8 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -18,8 +18,9 @@
 #include <stdint.h>
 #include <sys/types.h>
 
-#include <cutils/properties.h>
+#include <cutils/compiler.h>
 #include <cutils/native_handle.h>
+#include <cutils/properties.h>
 
 #include <utils/Errors.h>
 #include <utils/Log.h>
@@ -31,12 +32,12 @@
 #include <surfaceflinger/Surface.h>
 
 #include "clz.h"
+#include "DisplayHardware/DisplayHardware.h"
+#include "DisplayHardware/HWComposer.h"
 #include "GLExtensions.h"
 #include "Layer.h"
 #include "SurfaceFlinger.h"
-#include "DisplayHardware/DisplayHardware.h"
-#include "DisplayHardware/HWComposer.h"
-
+#include "SurfaceTextureLayer.h"
 
 #define DEBUG_RESIZE    0
 
@@ -52,102 +53,83 @@
 Layer::Layer(SurfaceFlinger* flinger,
         DisplayID display, const sp<Client>& client)
     :   LayerBaseClient(flinger, display, client),
+        mTextureName(-1U),
+        mQueuedFrames(0),
+        mCurrentTransform(0),
+        mCurrentOpacity(true),
         mFormat(PIXEL_FORMAT_NONE),
         mGLExtensions(GLExtensions::getInstance()),
-        mNeedsBlending(true),
+        mOpaqueLayer(true),
         mNeedsDithering(false),
         mSecure(false),
         mProtectedByApp(false),
-        mTextureManager(),
-        mBufferManager(mTextureManager),
-        mWidth(0), mHeight(0),
-        mNeedsScaling(false), mFixedSize(false)
+        mFixedSize(false)
 {
+    mCurrentCrop.makeInvalid();
+    glGenTextures(1, &mTextureName);
+}
+
+void Layer::destroy(RefBase const* base) {
+    mFlinger->destroyLayer(static_cast<LayerBase const*>(base));
+}
+
+void Layer::onFirstRef()
+{
+    LayerBaseClient::onFirstRef();
+    setDestroyer(this);
+
+    struct FrameQueuedListener : public SurfaceTexture::FrameAvailableListener {
+        FrameQueuedListener(Layer* layer) : mLayer(layer) { }
+    private:
+        wp<Layer> mLayer;
+        virtual void onFrameAvailable() {
+            sp<Layer> that(mLayer.promote());
+            if (that != 0) {
+                that->onFrameQueued();
+            }
+        }
+    };
+    mSurfaceTexture = new SurfaceTextureLayer(mTextureName, this);
+    mSurfaceTexture->setFrameAvailableListener(new FrameQueuedListener(this));
+    mSurfaceTexture->setSynchronousMode(true);
+    mSurfaceTexture->setBufferCountServer(2);
 }
 
 Layer::~Layer()
 {
-    // FIXME: must be called from the main UI thread
-    EGLDisplay dpy(mFlinger->graphicPlane(0).getEGLDisplay());
-    mBufferManager.destroy(dpy);
+    glDeleteTextures(1, &mTextureName);
+}
 
-    // we can use getUserClientUnsafe here because we know we're
-    // single-threaded at that point.
-    sp<UserClient> ourClient(mUserClientRef.getUserClientUnsafe());
-    if (ourClient != 0) {
-        ourClient->detachLayer(this);
+void Layer::onFrameQueued() {
+    if (android_atomic_or(1, &mQueuedFrames) == 0) {
+        mFlinger->signalEvent();
     }
 }
 
-void Layer::destroy() const {
-    mFlinger->destroyLayer(this);
-}
-
-status_t Layer::setToken(const sp<UserClient>& userClient,
-        SharedClient* sharedClient, int32_t token)
-{
-    sp<SharedBufferServer> lcblk = new SharedBufferServer(
-            sharedClient, token, mBufferManager.getDefaultBufferCount(),
-            getIdentity());
-
-
-    sp<UserClient> ourClient(mUserClientRef.getClient());
-
-    /*
-     *  Here it is guaranteed that userClient != ourClient
-     *  (see UserClient::getTokenForSurface()).
-     *
-     *  We release the token used by this surface in ourClient below.
-     *  This should be safe to do so now, since this layer won't be attached
-     *  to this client, it should be okay to reuse that id.
-     *
-     *  If this causes problems, an other solution would be to keep a list
-     *  of all the {UserClient, token} ever used and release them when the
-     *  Layer is destroyed.
-     *
-     */
-
-    if (ourClient != 0) {
-        ourClient->detachLayer(this);
-    }
-
-    status_t err = mUserClientRef.setToken(userClient, lcblk, token);
-    LOGE_IF(err != NO_ERROR,
-            "ClientRef::setToken(%p, %p, %u) failed",
-            userClient.get(), lcblk.get(), token);
-
-    if (err == NO_ERROR) {
-        // we need to free the buffers associated with this surface
-    }
-
-    return err;
-}
-
-int32_t Layer::getToken() const
-{
-    return mUserClientRef.getToken();
-}
-
-sp<UserClient> Layer::getClient() const
-{
-    return mUserClientRef.getClient();
-}
-
 // called with SurfaceFlinger::mStateLock as soon as the layer is entered
 // in the purgatory list
 void Layer::onRemoved()
 {
-    ClientRef::Access sharedClient(mUserClientRef);
-    SharedBufferServer* lcblk(sharedClient.get());
-    if (lcblk) {
-        // wake up the condition
-        lcblk->setStatus(NO_INIT);
-    }
 }
 
-sp<LayerBaseClient::Surface> Layer::createSurface() const
+sp<ISurface> Layer::createSurface()
 {
-    sp<Surface> sur(new SurfaceLayer(mFlinger, const_cast<Layer *>(this)));
+    class BSurface : public BnSurface, public LayerCleaner {
+        wp<const Layer> mOwner;
+        virtual sp<ISurfaceTexture> getSurfaceTexture() const {
+            sp<ISurfaceTexture> res;
+            sp<const Layer> that( mOwner.promote() );
+            if (that != NULL) {
+                res = that->mSurfaceTexture;
+            }
+            return res;
+        }
+    public:
+        BSurface(const sp<SurfaceFlinger>& flinger,
+                const sp<Layer>& layer)
+            : LayerCleaner(flinger, layer), mOwner(layer) { }
+    };
+    sp<ISurface> sur(new BSurface(mFlinger, this));
     return sur;
 }
 
@@ -175,17 +157,14 @@
     const uint32_t hwFlags = hw.getFlags();
     
     mFormat = format;
-    mWidth  = w;
-    mHeight = h;
-
-    mReqFormat = format;
-    mReqWidth = w;
-    mReqHeight = h;
 
     mSecure = (flags & ISurfaceComposer::eSecure) ? true : false;
     mProtectedByApp = (flags & ISurfaceComposer::eProtectedByApp) ? true : false;
-    mNeedsBlending = (info.h_alpha - info.l_alpha) > 0 &&
-            (flags & ISurfaceComposer::eOpaque) == 0;
+    mOpaqueLayer = (flags & ISurfaceComposer::eOpaque);
+    mCurrentOpacity = getOpacityForFormat(format);
+
+    mSurfaceTexture->setDefaultBufferSize(w, h);
+    mSurfaceTexture->setDefaultBufferFormat(format);
 
     // we use the red index
     int displayRedSize = displayInfo.getSize(PixelFormatInfo::INDEX_RED);
@@ -216,10 +195,12 @@
         return;
     }
 
-    Transform tr(Transform(mOrientation) * Transform(mBufferTransform));
+    // FIXME: shouldn't we take the state's transform into account here?
+
+    Transform tr(Transform(mOrientation) * Transform(mCurrentTransform));
     hwcl->transform = tr.getOrientation();
 
-    if (needsBlending()) {
+    if (!isOpaque()) {
         hwcl->blending = mPremultipliedAlpha ?
                 HWC_BLENDING_PREMULT : HWC_BLENDING_COVERAGE;
     }
@@ -236,7 +217,7 @@
 }
 
 void Layer::setPerFrameData(hwc_layer_t* hwcl) {
-    sp<GraphicBuffer> buffer(mBufferManager.getActiveBuffer());
+    const sp<GraphicBuffer>& buffer(mActiveBuffer);
     if (buffer == NULL) {
         // this can happen if the client never drew into this layer yet,
         // or if we ran out of memory. In that case, don't let
@@ -247,11 +228,11 @@
     }
     hwcl->handle = buffer->handle;
 
-    if (!mBufferCrop.isEmpty()) {
-        hwcl->sourceCrop.left   = mBufferCrop.left;
-        hwcl->sourceCrop.top    = mBufferCrop.top;
-        hwcl->sourceCrop.right  = mBufferCrop.right;
-        hwcl->sourceCrop.bottom = mBufferCrop.bottom;
+    if (isCropped()) {
+        hwcl->sourceCrop.left   = mCurrentCrop.left;
+        hwcl->sourceCrop.top    = mCurrentCrop.top;
+        hwcl->sourceCrop.right  = mCurrentCrop.right;
+        hwcl->sourceCrop.bottom = mCurrentCrop.bottom;
     } else {
         hwcl->sourceCrop.left   = 0;
         hwcl->sourceCrop.top    = 0;
@@ -260,51 +241,12 @@
     }
 }
 
-void Layer::reloadTexture(const Region& dirty)
-{
-    sp<GraphicBuffer> buffer(mBufferManager.getActiveBuffer());
-    if (buffer == NULL) {
-        // this situation can happen if we ran out of memory for instance.
-        // not much we can do. continue to use whatever texture was bound
-        // to this context.
-        return;
-    }
-
-    if (mGLExtensions.haveDirectTexture()) {
-        EGLDisplay dpy(mFlinger->graphicPlane(0).getEGLDisplay());
-        if (mBufferManager.initEglImage(dpy, buffer) != NO_ERROR) {
-            // not sure what we can do here...
-            goto slowpath;
-        }
-    } else {
-slowpath:
-        GGLSurface t;
-        if (buffer->usage & GRALLOC_USAGE_SW_READ_MASK) {
-            status_t res = buffer->lock(&t, GRALLOC_USAGE_SW_READ_OFTEN);
-            LOGE_IF(res, "error %d (%s) locking buffer %p",
-                    res, strerror(res), buffer.get());
-            if (res == NO_ERROR) {
-                mBufferManager.loadTexture(dirty, t);
-                buffer->unlock();
-            }
-        } else {
-            // we can't do anything
-        }
-    }
+static inline uint16_t pack565(int r, int g, int b) {
+    return (r<<11)|(g<<5)|b;
 }
-
-void Layer::drawForSreenShot() const
-{
-    const bool currentFiltering = mNeedsFiltering;
-    const_cast<Layer*>(this)->mNeedsFiltering = true;
-    LayerBase::drawForSreenShot();
-    const_cast<Layer*>(this)->mNeedsFiltering = currentFiltering;
-}
-
 void Layer::onDraw(const Region& clip) const
 {
-    Texture tex(mBufferManager.getActiveTexture());
-    if (tex.name == -1LU) {
+    if (CC_UNLIKELY(mActiveBuffer == 0)) {
         // the texture has not been created yet, this Layer has
         // in fact never been drawn into. This happens frequently with
         // SurfaceView because the WindowManager can't know when the client
@@ -330,7 +272,25 @@
         }
         return;
     }
-    drawWithOpenGL(clip, tex);
+
+    GLenum target = mSurfaceTexture->getCurrentTextureTarget();
+    glBindTexture(target, mTextureName);
+    if (getFiltering() || needsFiltering() || isFixedSize() || isCropped()) {
+        // TODO: we could be more subtle with isFixedSize()
+        glTexParameterx(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+        glTexParameterx(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+    } else {
+        glTexParameterx(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+        glTexParameterx(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+    }
+    glEnable(target);
+    glMatrixMode(GL_TEXTURE);
+    glLoadMatrixf(mTextureMatrix);
+    glMatrixMode(GL_MODELVIEW);
+
+    drawWithOpenGL(clip);
+
+    glDisable(target);
 }
 
 // As documented in libhardware header, formats in the range
@@ -340,186 +300,37 @@
 // hardware.h, instead of using hard-coded values here.
 #define HARDWARE_IS_DEVICE_FORMAT(f) ((f) >= 0x100 && (f) <= 0x1FF)
 
-bool Layer::needsBlending(const sp<GraphicBuffer>& buffer) const
+bool Layer::getOpacityForFormat(uint32_t format)
 {
-    // If buffers where set with eOpaque flag, all buffers are known to
-    // be opaque without having to check their actual format
-    if (mNeedsBlending && buffer != NULL) {
-        PixelFormat format = buffer->getPixelFormat();
-
-        if (HARDWARE_IS_DEVICE_FORMAT(format)) {
-            return false;
-        }
-
-        PixelFormatInfo info;
-        status_t err = getPixelFormatInfo(format, &info);
-        if (!err && info.h_alpha <= info.l_alpha) {
-            return false;
-        }
+    if (HARDWARE_IS_DEVICE_FORMAT(format)) {
+        return true;
     }
-
-    // Return opacity as determined from flags and format options
-    // passed to setBuffers()
-    return mNeedsBlending;
+    PixelFormatInfo info;
+    status_t err = getPixelFormatInfo(PixelFormat(format), &info);
+    // in case of error (unknown format), we assume no blending
+    return (err || info.h_alpha <= info.l_alpha);
 }
 
-bool Layer::needsBlending() const
-{
-    if (mBufferManager.hasActiveBuffer()) {
-        return needsBlending(mBufferManager.getActiveBuffer());
-    }
 
-    return mNeedsBlending;
-}
-
-bool Layer::needsFiltering() const
+bool Layer::isOpaque() const
 {
-    if (!(mFlags & DisplayHardware::SLOW_CONFIG)) {
-        // if our buffer is not the same size than ourselves,
-        // we need filtering.
-        Mutex::Autolock _l(mLock);
-        if (mNeedsScaling)
-            return true;
-    }
-    return LayerBase::needsFiltering();
+    // if we don't have a buffer yet, we're translucent regardless of the
+    // layer's opaque flag.
+    if (mActiveBuffer == 0)
+        return false;
+
+    // if the layer has the opaque flag, then we're always opaque,
+    // otherwise we use the current buffer's format.
+    return mOpaqueLayer || mCurrentOpacity;
 }
 
 bool Layer::isProtected() const
 {
-    sp<GraphicBuffer> activeBuffer(mBufferManager.getActiveBuffer());
+    const sp<GraphicBuffer>& activeBuffer(mActiveBuffer);
     return (activeBuffer != 0) &&
             (activeBuffer->getUsage() & GRALLOC_USAGE_PROTECTED);
 }
 
-status_t Layer::setBufferCount(int bufferCount)
-{
-    ClientRef::Access sharedClient(mUserClientRef);
-    SharedBufferServer* lcblk(sharedClient.get());
-    if (!lcblk) {
-        // oops, the client is already gone
-        return DEAD_OBJECT;
-    }
-
-    // NOTE: lcblk->resize() is protected by an internal lock
-    status_t err = lcblk->resize(bufferCount);
-    if (err == NO_ERROR) {
-        EGLDisplay dpy(mFlinger->graphicPlane(0).getEGLDisplay());
-        mBufferManager.resize(bufferCount, mFlinger, dpy);
-    }
-
-    return err;
-}
-
-sp<GraphicBuffer> Layer::requestBuffer(int index,
-        uint32_t reqWidth, uint32_t reqHeight, uint32_t reqFormat,
-        uint32_t usage)
-{
-    sp<GraphicBuffer> buffer;
-
-    if (int32_t(reqWidth | reqHeight | reqFormat) < 0)
-        return buffer;
-
-    if ((!reqWidth && reqHeight) || (reqWidth && !reqHeight))
-        return buffer;
-
-    // this ensures our client doesn't go away while we're accessing
-    // the shared area.
-    ClientRef::Access sharedClient(mUserClientRef);
-    SharedBufferServer* lcblk(sharedClient.get());
-    if (!lcblk) {
-        // oops, the client is already gone
-        return buffer;
-    }
-
-    /*
-     * This is called from the client's Surface::dequeue(). This can happen
-     * at any time, especially while we're in the middle of using the
-     * buffer 'index' as our front buffer.
-     */
-
-    status_t err = NO_ERROR;
-    uint32_t w, h, f;
-    { // scope for the lock
-        Mutex::Autolock _l(mLock);
-
-        // zero means default
-        const bool fixedSize = reqWidth && reqHeight;
-        if (!reqFormat) reqFormat = mFormat;
-        if (!reqWidth)  reqWidth = mWidth;
-        if (!reqHeight) reqHeight = mHeight;
-
-        w = reqWidth;
-        h = reqHeight;
-        f = reqFormat;
-
-        if ((reqWidth != mReqWidth) || (reqHeight != mReqHeight) ||
-                (reqFormat != mReqFormat)) {
-            mReqWidth  = reqWidth;
-            mReqHeight = reqHeight;
-            mReqFormat = reqFormat;
-            mFixedSize = fixedSize;
-            mNeedsScaling = mWidth != mReqWidth || mHeight != mReqHeight;
-
-            lcblk->reallocateAllExcept(index);
-        }
-    }
-
-    // here we have to reallocate a new buffer because the buffer could be
-    // used as the front buffer, or by a client in our process
-    // (eg: status bar), and we can't release the handle under its feet.
-    const uint32_t effectiveUsage = getEffectiveUsage(usage);
-    buffer = new GraphicBuffer(w, h, f, effectiveUsage);
-    err = buffer->initCheck();
-
-    if (err || buffer->handle == 0) {
-        GraphicBuffer::dumpAllocationsToSystemLog();
-        LOGE_IF(err || buffer->handle == 0,
-                "Layer::requestBuffer(this=%p), index=%d, w=%d, h=%d failed (%s)",
-                this, index, w, h, strerror(-err));
-    } else {
-        LOGD_IF(DEBUG_RESIZE,
-                "Layer::requestBuffer(this=%p), index=%d, w=%d, h=%d, handle=%p",
-                this, index, w, h, buffer->handle);
-    }
-
-    if (err == NO_ERROR && buffer->handle != 0) {
-        Mutex::Autolock _l(mLock);
-        mBufferManager.attachBuffer(index, buffer);
-    }
-    return buffer;
-}
-
-uint32_t Layer::getEffectiveUsage(uint32_t usage) const
-{
-    /*
-     *  buffers used for software rendering, but h/w composition
-     *  are allocated with SW_READ_OFTEN | SW_WRITE_OFTEN | HW_TEXTURE
-     *
-     *  buffers used for h/w rendering and h/w composition
-     *  are allocated with  HW_RENDER | HW_TEXTURE
-     *
-     *  buffers used with h/w rendering and either NPOT or no egl_image_ext
-     *  are allocated with SW_READ_RARELY | HW_RENDER
-     *
-     */
-
-    if (mSecure) {
-        // secure buffer, don't store it into the GPU
-        usage = GraphicBuffer::USAGE_SW_READ_OFTEN |
-                GraphicBuffer::USAGE_SW_WRITE_OFTEN;
-    } else {
-        // it's allowed to modify the usage flags here, but generally
-        // the requested flags should be honored.
-        // request EGLImage for all buffers
-        usage |= GraphicBuffer::USAGE_HW_TEXTURE;
-    }
-    if (mProtectedByApp) {
-        // need a hardware-protected path to external video sink
-        usage |= GraphicBuffer::USAGE_PROTECTED;
-    }
-    return usage;
-}
-
 uint32_t Layer::doTransaction(uint32_t flags)
 {
     const Layer::State& front(drawingState());
@@ -531,10 +342,12 @@
     if (sizeChanged) {
         // the size changed, we need to ask our client to request a new buffer
         LOGD_IF(DEBUG_RESIZE,
-                "resize (layer=%p), requested (%dx%d), drawing (%d,%d)",
+                "resize (layer=%p), requested (%dx%d), drawing (%d,%d), "
+                "fixedSize=%d",
                 this,
                 int(temp.requested_w), int(temp.requested_h),
-                int(front.requested_w), int(front.requested_h));
+                int(front.requested_w), int(front.requested_h),
+                isFixedSize());
 
         if (!isFixedSize()) {
             // we're being resized and there is a freeze display request,
@@ -557,17 +370,7 @@
 
             // record the new size, form this point on, when the client request
             // a buffer, it'll get the new size.
-            setBufferSize(temp.requested_w, temp.requested_h);
-
-            ClientRef::Access sharedClient(mUserClientRef);
-            SharedBufferServer* lcblk(sharedClient.get());
-            if (lcblk) {
-                // all buffers need reallocation
-                lcblk->reallocateAll();
-            }
-        } else {
-            // record the new size
-            setBufferSize(temp.requested_w, temp.requested_h);
+            mSurfaceTexture->setDefaultBufferSize(temp.requested_w, temp.requested_h);
         }
     }
 
@@ -582,79 +385,69 @@
     return LayerBase::doTransaction(flags);
 }
 
-void Layer::setBufferSize(uint32_t w, uint32_t h) {
-    Mutex::Autolock _l(mLock);
-    mWidth = w;
-    mHeight = h;
-    mNeedsScaling = mWidth != mReqWidth || mHeight != mReqHeight;
-}
-
 bool Layer::isFixedSize() const {
     Mutex::Autolock _l(mLock);
     return mFixedSize;
 }
 
+void Layer::setFixedSize(bool fixedSize)
+{
+    Mutex::Autolock _l(mLock);
+    mFixedSize = fixedSize;
+}
+
+bool Layer::isCropped() const {
+    return !mCurrentCrop.isEmpty();
+}
+
 // ----------------------------------------------------------------------------
 // pageflip handling...
 // ----------------------------------------------------------------------------
 
 void Layer::lockPageFlip(bool& recomputeVisibleRegions)
 {
-    ClientRef::Access sharedClient(mUserClientRef);
-    SharedBufferServer* lcblk(sharedClient.get());
-    if (!lcblk) {
-        // client died
-        recomputeVisibleRegions = true;
-        return;
-    }
+    if (android_atomic_and(0, &mQueuedFrames)) {
+        if (mSurfaceTexture->updateTexImage() < NO_ERROR) {
+            // something happened!
+            recomputeVisibleRegions = true;
+            return;
+        }
 
-    ssize_t buf = lcblk->retireAndLock();
-    if (buf == NOT_ENOUGH_DATA) {
-        // NOTE: This is not an error, it simply means there is nothing to
-        // retire. The buffer is locked because we will use it
-        // for composition later in the loop
-        return;
-    }
+        // signal another event if we have more frames waiting
+        if (mSurfaceTexture->getQueuedCount()) {
+            if (android_atomic_or(1, &mQueuedFrames) == 0) {
+                mFlinger->signalEvent();
+            }
+        }
 
-    if (buf < NO_ERROR) {
-        LOGE("retireAndLock() buffer index (%d) out of range", int(buf));
-        mPostedDirtyRegion.clear();
-        return;
-    }
+        mActiveBuffer = mSurfaceTexture->getCurrentBuffer();
+        mSurfaceTexture->getTransformMatrix(mTextureMatrix);
 
-    // we retired a buffer, which becomes the new front buffer
+        const Rect crop(mSurfaceTexture->getCurrentCrop());
+        const uint32_t transform(mSurfaceTexture->getCurrentTransform());
+        if ((crop != mCurrentCrop) || (transform != mCurrentTransform)) {
+            mCurrentCrop = crop;
+            mCurrentTransform = transform;
+            mFlinger->invalidateHwcGeometry();
+        }
 
-    const bool noActiveBuffer = !mBufferManager.hasActiveBuffer();
-    const bool activeBlending =
-            noActiveBuffer ? true : needsBlending(mBufferManager.getActiveBuffer());
-
-    if (mBufferManager.setActiveBufferIndex(buf) < NO_ERROR) {
-        LOGE("retireAndLock() buffer index (%d) out of range", int(buf));
-        mPostedDirtyRegion.clear();
-        return;
-    }
-
-    if (noActiveBuffer) {
-        // we didn't have an active buffer, we need to recompute
-        // our visible region
-        recomputeVisibleRegions = true;
-    }
-
-    sp<GraphicBuffer> newFrontBuffer(getBuffer(buf));
-    if (newFrontBuffer != NULL) {
-        if (!noActiveBuffer && activeBlending != needsBlending(newFrontBuffer)) {
-            // new buffer has different opacity than previous active buffer, need
-            // to recompute visible regions accordingly
+        const bool opacity(getOpacityForFormat(mActiveBuffer->format));
+        if (opacity != mCurrentOpacity) {
+            mCurrentOpacity = opacity;
             recomputeVisibleRegions = true;
         }
 
-        // get the dirty region
-        // compute the posted region
-        const Region dirty(lcblk->getDirtyRegion(buf));
-        mPostedDirtyRegion = dirty.intersect( newFrontBuffer->getBounds() );
+        const GLenum target(mSurfaceTexture->getCurrentTextureTarget());
+        glTexParameterx(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+        glTexParameterx(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
 
         // update the layer size and release freeze-lock
         const Layer::State& front(drawingState());
+
+        // FIXME: mPostedDirtyRegion = dirty & bounds
+        mPostedDirtyRegion.set(front.w, front.h);
+
+        sp<GraphicBuffer> newFrontBuffer(mActiveBuffer);
         if ((newFrontBuffer->getWidth()  == front.requested_w &&
             newFrontBuffer->getHeight() == front.requested_h) ||
             isFixedSize())
@@ -685,35 +478,7 @@
             // we now have the correct size, unfreeze the screen
             mFreezeLock.clear();
         }
-
-        // get the crop region
-        setBufferCrop( lcblk->getCrop(buf) );
-
-        // get the transformation
-        setBufferTransform( lcblk->getTransform(buf) );
-
-    } else {
-        // this should not happen unless we ran out of memory while
-        // allocating the buffer. we're hoping that things will get back
-        // to normal the next time the app tries to draw into this buffer.
-        // meanwhile, pretend the screen didn't update.
-        mPostedDirtyRegion.clear();
     }
-
-    if (lcblk->getQueuedCount()) {
-        // signal an event if we have more buffers waiting
-        mFlinger->signalEvent();
-    }
-
-    /* a buffer was posted, so we need to call reloadTexture(), which
-     * will update our internal data structures (eg: EGLImageKHR or
-     * texture names). we need to do this even if mPostedDirtyRegion is
-     * empty -- it's orthogonal to the fact that a new buffer was posted,
-     * for instance, a degenerate case could be that the user did an empty
-     * update but repainted the buffer with appropriate content (after a
-     * resize for instance).
-     */
-    reloadTexture( mPostedDirtyRegion );
 }
 
 void Layer::unlockPageFlip(
@@ -746,329 +511,36 @@
 {
     LayerBaseClient::dump(result, buffer, SIZE);
 
-    ClientRef::Access sharedClient(mUserClientRef);
-    SharedBufferServer* lcblk(sharedClient.get());
-    uint32_t totalTime = 0;
-    if (lcblk) {
-        SharedBufferStack::Statistics stats = lcblk->getStats();
-        totalTime= stats.totalTime;
-        result.append( lcblk->dump("      ") );
-    }
-
-    sp<const GraphicBuffer> buf0(getBuffer(0));
-    sp<const GraphicBuffer> buf1(getBuffer(1));
-    uint32_t w0=0, h0=0, s0=0;
-    uint32_t w1=0, h1=0, s1=0;
+    sp<const GraphicBuffer> buf0(mActiveBuffer);
+    uint32_t w0=0, h0=0, s0=0, f0=0;
     if (buf0 != 0) {
         w0 = buf0->getWidth();
         h0 = buf0->getHeight();
         s0 = buf0->getStride();
-    }
-    if (buf1 != 0) {
-        w1 = buf1->getWidth();
-        h1 = buf1->getHeight();
-        s1 = buf1->getStride();
+        f0 = buf0->format;
     }
     snprintf(buffer, SIZE,
             "      "
-            "format=%2d, [%3ux%3u:%3u] [%3ux%3u:%3u],"
-            " freezeLock=%p, dq-q-time=%u us\n",
-            mFormat, w0, h0, s0, w1, h1, s1,
-            getFreezeLock().get(), totalTime);
+            "format=%2d, activeBuffer=[%3ux%3u:%3u,%3u],"
+            " freezeLock=%p, queued-frames=%d\n",
+            mFormat, w0, h0, s0,f0,
+            getFreezeLock().get(), mQueuedFrames);
 
     result.append(buffer);
-}
 
-// ---------------------------------------------------------------------------
-
-Layer::ClientRef::ClientRef()
-    : mControlBlock(0), mToken(-1) {
-}
-
-Layer::ClientRef::~ClientRef() {
-}
-
-int32_t Layer::ClientRef::getToken() const {
-    Mutex::Autolock _l(mLock);
-    return mToken;
-}
-
-sp<UserClient> Layer::ClientRef::getClient() const {
-    Mutex::Autolock _l(mLock);
-    return mUserClient.promote();
-}
-
-status_t Layer::ClientRef::setToken(const sp<UserClient>& uc,
-        const sp<SharedBufferServer>& sharedClient, int32_t token) {
-    Mutex::Autolock _l(mLock);
-
-    { // scope for strong mUserClient reference
-        sp<UserClient> userClient(mUserClient.promote());
-        if (userClient != 0 && mControlBlock != 0) {
-            mControlBlock->setStatus(NO_INIT);
-        }
+    if (mSurfaceTexture != 0) {
+        mSurfaceTexture->dump(result, "            ", buffer, SIZE);
     }
-
-    mUserClient = uc;
-    mToken = token;
-    mControlBlock = sharedClient;
-    return NO_ERROR;
 }
 
-sp<UserClient> Layer::ClientRef::getUserClientUnsafe() const {
-    return mUserClient.promote();
-}
-
-// this class gives us access to SharedBufferServer safely
-// it makes sure the UserClient (and its associated shared memory)
-// won't go away while we're accessing it.
-Layer::ClientRef::Access::Access(const ClientRef& ref)
-    : mControlBlock(0)
+uint32_t Layer::getEffectiveUsage(uint32_t usage) const
 {
-    Mutex::Autolock _l(ref.mLock);
-    mUserClientStrongRef = ref.mUserClient.promote();
-    if (mUserClientStrongRef != 0)
-        mControlBlock = ref.mControlBlock;
-}
-
-Layer::ClientRef::Access::~Access()
-{
-}
-
-// ---------------------------------------------------------------------------
-
-Layer::BufferManager::BufferManager(TextureManager& tm)
-    : mNumBuffers(NUM_BUFFERS), mTextureManager(tm),
-      mActiveBufferIndex(-1), mFailover(false)
-{
-}
-
-Layer::BufferManager::~BufferManager()
-{
-}
-
-status_t Layer::BufferManager::resize(size_t size,
-        const sp<SurfaceFlinger>& flinger, EGLDisplay dpy)
-{
-    Mutex::Autolock _l(mLock);
-
-    if (size < mNumBuffers) {
-        // If there is an active texture, move it into slot 0 if needed
-        if (mActiveBufferIndex > 0) {
-            BufferData activeBufferData = mBufferData[mActiveBufferIndex];
-            mBufferData[mActiveBufferIndex] = mBufferData[0];
-            mBufferData[0] = activeBufferData;
-            mActiveBufferIndex = 0;
-        }
-
-        // Free the buffers that are no longer needed.
-        for (size_t i = size; i < mNumBuffers; i++) {
-            mBufferData[i].buffer = 0;
-
-            // Create a message to destroy the textures on SurfaceFlinger's GL
-            // thread.
-            class MessageDestroyTexture : public MessageBase {
-                Image mTexture;
-                EGLDisplay mDpy;
-             public:
-                MessageDestroyTexture(const Image& texture, EGLDisplay dpy)
-                    : mTexture(texture), mDpy(dpy) { }
-                virtual bool handler() {
-                    status_t err = Layer::BufferManager::destroyTexture(
-                            &mTexture, mDpy);
-                    LOGE_IF(err<0, "error destroying texture: %d (%s)",
-                            mTexture.name, strerror(-err));
-                    return true; // XXX: err == 0;  ????
-                }
-            };
-
-            MessageDestroyTexture *msg = new MessageDestroyTexture(
-                    mBufferData[i].texture, dpy);
-
-            // Don't allow this texture to be cleaned up by
-            // BufferManager::destroy.
-            mBufferData[i].texture.name = -1U;
-            mBufferData[i].texture.image = EGL_NO_IMAGE_KHR;
-
-            // Post the message to the SurfaceFlinger object.
-            flinger->postMessageAsync(msg);
-        }
+    // TODO: should we do something special if mSecure is set?
+    if (mProtectedByApp) {
+        // need a hardware-protected path to external video sink
+        usage |= GraphicBuffer::USAGE_PROTECTED;
     }
-
-    mNumBuffers = size;
-    return NO_ERROR;
-}
-
-// only for debugging
-sp<GraphicBuffer> Layer::BufferManager::getBuffer(size_t index) const {
-    return mBufferData[index].buffer;
-}
-
-status_t Layer::BufferManager::setActiveBufferIndex(size_t index) {
-    BufferData const * const buffers = mBufferData;
-    Mutex::Autolock _l(mLock);
-    mActiveBuffer = buffers[index].buffer;
-    mActiveBufferIndex = index;
-    return NO_ERROR;
-}
-
-size_t Layer::BufferManager::getActiveBufferIndex() const {
-    return mActiveBufferIndex;
-}
-
-Texture Layer::BufferManager::getActiveTexture() const {
-    Texture res;
-    if (mFailover || mActiveBufferIndex<0) {
-        res = mFailoverTexture;
-    } else {
-        static_cast<Image&>(res) = mBufferData[mActiveBufferIndex].texture;
-    }
-    return res;
-}
-
-sp<GraphicBuffer> Layer::BufferManager::getActiveBuffer() const {
-    return mActiveBuffer;
-}
-
-bool Layer::BufferManager::hasActiveBuffer() const {
-    return mActiveBufferIndex >= 0;
-}
-
-sp<GraphicBuffer> Layer::BufferManager::detachBuffer(size_t index)
-{
-    BufferData* const buffers = mBufferData;
-    sp<GraphicBuffer> buffer;
-    Mutex::Autolock _l(mLock);
-    buffer = buffers[index].buffer;
-    buffers[index].buffer = 0;
-    return buffer;
-}
-
-status_t Layer::BufferManager::attachBuffer(size_t index,
-        const sp<GraphicBuffer>& buffer)
-{
-    BufferData* const buffers = mBufferData;
-    Mutex::Autolock _l(mLock);
-    buffers[index].buffer = buffer;
-    buffers[index].texture.dirty = true;
-    return NO_ERROR;
-}
-
-status_t Layer::BufferManager::destroy(EGLDisplay dpy)
-{
-    BufferData* const buffers = mBufferData;
-    size_t num;
-    { // scope for the lock
-        Mutex::Autolock _l(mLock);
-        num = mNumBuffers;
-        for (size_t i=0 ; i<num ; i++) {
-            buffers[i].buffer = 0;
-        }
-    }
-    for (size_t i=0 ; i<num ; i++) {
-        destroyTexture(&buffers[i].texture, dpy);
-    }
-    destroyTexture(&mFailoverTexture, dpy);
-    return NO_ERROR;
-}
-
-status_t Layer::BufferManager::initEglImage(EGLDisplay dpy,
-        const sp<GraphicBuffer>& buffer)
-{
-    status_t err = NO_INIT;
-    ssize_t index = mActiveBufferIndex;
-    if (index >= 0) {
-        if (!mFailover) {
-            {
-               // Without that lock, there is a chance of race condition
-               // where while composing a specific index, requestBuf
-               // with the same index can be executed and touch the same data
-               // that is being used in initEglImage.
-               // (e.g. dirty flag in texture)
-               Mutex::Autolock _l(mLock);
-               Image& texture(mBufferData[index].texture);
-               err = mTextureManager.initEglImage(&texture, dpy, buffer);
-            }
-            // if EGLImage fails, we switch to regular texture mode, and we
-            // free all resources associated with using EGLImages.
-            if (err == NO_ERROR) {
-                mFailover = false;
-                destroyTexture(&mFailoverTexture, dpy);
-            } else {
-                mFailover = true;
-                const size_t num = mNumBuffers;
-                for (size_t i=0 ; i<num ; i++) {
-                    destroyTexture(&mBufferData[i].texture, dpy);
-                }
-            }
-        } else {
-            // we failed once, don't try again
-            err = BAD_VALUE;
-        }
-    }
-    return err;
-}
-
-status_t Layer::BufferManager::loadTexture(
-        const Region& dirty, const GGLSurface& t)
-{
-    return mTextureManager.loadTexture(&mFailoverTexture, dirty, t);
-}
-
-status_t Layer::BufferManager::destroyTexture(Image* tex, EGLDisplay dpy)
-{
-    if (tex->name != -1U) {
-        glDeleteTextures(1, &tex->name);
-        tex->name = -1U;
-    }
-    if (tex->image != EGL_NO_IMAGE_KHR) {
-        eglDestroyImageKHR(dpy, tex->image);
-        tex->image = EGL_NO_IMAGE_KHR;
-    }
-    return NO_ERROR;
-}
-
-// ---------------------------------------------------------------------------
-
-Layer::SurfaceLayer::SurfaceLayer(const sp<SurfaceFlinger>& flinger,
-        const sp<Layer>& owner)
-    : Surface(flinger, owner->getIdentity(), owner)
-{
-}
-
-Layer::SurfaceLayer::~SurfaceLayer()
-{
-}
-
-sp<GraphicBuffer> Layer::SurfaceLayer::requestBuffer(int index,
-        uint32_t w, uint32_t h, uint32_t format, uint32_t usage)
-{
-    sp<GraphicBuffer> buffer;
-    sp<Layer> owner(getOwner());
-    if (owner != 0) {
-        /*
-         * requestBuffer() cannot be called from the main thread
-         * as it could cause a dead-lock, since it may have to wait
-         * on conditions updated my the main thread.
-         */
-        buffer = owner->requestBuffer(index, w, h, format, usage);
-    }
-    return buffer;
-}
-
-status_t Layer::SurfaceLayer::setBufferCount(int bufferCount)
-{
-    status_t err = DEAD_OBJECT;
-    sp<Layer> owner(getOwner());
-    if (owner != 0) {
-        /*
-         * setBufferCount() cannot be called from the main thread
-         * as it could cause a dead-lock, since it may have to wait
-         * on conditions updated my the main thread.
-         */
-        err = owner->setBufferCount(bufferCount);
-    }
-    return err;
+    return usage;
 }
 
 // ---------------------------------------------------------------------------
diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h
index 278d64e..e3fc13d 100644
--- a/services/surfaceflinger/Layer.h
+++ b/services/surfaceflinger/Layer.h
@@ -20,9 +20,11 @@
 #include <stdint.h>
 #include <sys/types.h>
 
+#include <gui/SurfaceTexture.h>
+
+#include <pixelflinger/pixelflinger.h>
 #include <ui/GraphicBuffer.h>
 #include <ui/PixelFormat.h>
-#include <pixelflinger/pixelflinger.h>
 
 #include <EGL/egl.h>
 #include <EGL/eglext.h>
@@ -30,8 +32,8 @@
 #include <GLES/glext.h>
 
 #include "LayerBase.h"
+#include "SurfaceTextureLayer.h"
 #include "Transform.h"
-#include "TextureManager.h"
 
 namespace android {
 
@@ -40,11 +42,10 @@
 class FreezeLock;
 class Client;
 class GLExtensions;
-class UserClient;
 
 // ---------------------------------------------------------------------------
 
-class Layer : public LayerBaseClient
+class Layer : public LayerBaseClient, private RefBase::Destroyer
 {
 public:
             Layer(SurfaceFlinger* flinger, DisplayID display,
@@ -58,164 +59,59 @@
     status_t setBuffers(uint32_t w, uint32_t h, 
             PixelFormat format, uint32_t flags=0);
 
-    // associate a UserClient to this Layer
-    status_t setToken(const sp<UserClient>& uc, SharedClient* sc, int32_t idx);
-    int32_t getToken() const;
-    sp<UserClient> getClient() const;
-
     // Set this Layer's buffers size
-    void setBufferSize(uint32_t w, uint32_t h);
     bool isFixedSize() const;
 
     // LayerBase interface
     virtual void setGeometry(hwc_layer_t* hwcl);
     virtual void setPerFrameData(hwc_layer_t* hwcl);
-    virtual void drawForSreenShot() const;
     virtual void onDraw(const Region& clip) const;
     virtual uint32_t doTransaction(uint32_t transactionFlags);
     virtual void lockPageFlip(bool& recomputeVisibleRegions);
     virtual void unlockPageFlip(const Transform& planeTransform, Region& outDirtyRegion);
-    virtual bool needsBlending(const sp<GraphicBuffer>& buffer) const;
-    virtual bool needsBlending() const;
+    virtual bool isOpaque() const;
     virtual bool needsDithering() const     { return mNeedsDithering; }
-    virtual bool needsFiltering() const;
     virtual bool isSecure() const           { return mSecure; }
     virtual bool isProtected() const;
-    virtual sp<Surface> createSurface() const;
     virtual void onRemoved();
 
     // only for debugging
-    inline sp<GraphicBuffer> getBuffer(int i) const {
-        return mBufferManager.getBuffer(i); }
-    // only for debugging
-    inline const sp<FreezeLock>&  getFreezeLock() const {
-        return mFreezeLock; }
+    inline const sp<FreezeLock>&  getFreezeLock() const { return mFreezeLock; }
 
 protected:
-    virtual void destroy() const;
+    virtual void destroy(RefBase const* base);
+    virtual void onFirstRef();
     virtual void dump(String8& result, char* scratch, size_t size) const;
 
 private:
-    void reloadTexture(const Region& dirty);
+    friend class SurfaceTextureLayer;
+    void onFrameQueued();
+    virtual sp<ISurface> createSurface();
     uint32_t getEffectiveUsage(uint32_t usage) const;
-    sp<GraphicBuffer> requestBuffer(int bufferIdx,
-            uint32_t w, uint32_t h, uint32_t format, uint32_t usage);
-    status_t setBufferCount(int bufferCount);
+    void setFixedSize(bool fixedSize);
+    bool isCropped() const;
+    static bool getOpacityForFormat(uint32_t format);
 
     // -----------------------------------------------------------------------
 
-    class SurfaceLayer : public LayerBaseClient::Surface {
-    public:
-        SurfaceLayer(const sp<SurfaceFlinger>& flinger, const sp<Layer>& owner);
-        ~SurfaceLayer();
-    private:
-        virtual sp<GraphicBuffer> requestBuffer(int bufferIdx,
-                uint32_t w, uint32_t h, uint32_t format, uint32_t usage);
-        virtual status_t setBufferCount(int bufferCount);
-        sp<Layer> getOwner() const {
-            return static_cast<Layer*>(Surface::getOwner().get());
-        }
-    };
-    friend class SurfaceLayer;
-
-    // -----------------------------------------------------------------------
-
-    class ClientRef {
-        ClientRef(const ClientRef& rhs);
-        ClientRef& operator = (const ClientRef& rhs);
-        mutable Mutex mLock;
-        // binder thread, page-flip thread
-        sp<SharedBufferServer> mControlBlock;
-        wp<UserClient> mUserClient;
-        int32_t mToken;
-    public:
-        ClientRef();
-        ~ClientRef();
-        int32_t getToken() const;
-        sp<UserClient> getClient() const;
-        status_t setToken(const sp<UserClient>& uc,
-                const sp<SharedBufferServer>& sharedClient, int32_t token);
-        sp<UserClient> getUserClientUnsafe() const;
-        class Access {
-            Access(const Access& rhs);
-            Access& operator = (const Access& rhs);
-            sp<UserClient> mUserClientStrongRef;
-            sp<SharedBufferServer> mControlBlock;
-        public:
-            Access(const ClientRef& ref);
-            ~Access();
-            inline SharedBufferServer* get() const { return mControlBlock.get(); }
-        };
-        friend class Access;
-    };
-
-    // -----------------------------------------------------------------------
-
-    class BufferManager {
-        static const size_t NUM_BUFFERS = 2;
-        struct BufferData {
-            sp<GraphicBuffer>   buffer;
-            Image               texture;
-        };
-        // this lock protect mBufferData[].buffer but since there
-        // is very little contention, we have only one like for
-        // the whole array, we also use it to protect mNumBuffers.
-        mutable Mutex mLock;
-        BufferData          mBufferData[SharedBufferStack::NUM_BUFFER_MAX];
-        size_t              mNumBuffers;
-        Texture             mFailoverTexture;
-        TextureManager&     mTextureManager;
-        ssize_t             mActiveBufferIndex;
-        sp<GraphicBuffer>   mActiveBuffer;
-        bool                mFailover;
-        static status_t destroyTexture(Image* tex, EGLDisplay dpy);
-
-    public:
-        static size_t getDefaultBufferCount() { return NUM_BUFFERS; }
-        BufferManager(TextureManager& tm);
-        ~BufferManager();
-
-        // detach/attach buffer from/to given index
-        sp<GraphicBuffer> detachBuffer(size_t index);
-        status_t attachBuffer(size_t index, const sp<GraphicBuffer>& buffer);
-        // resize the number of active buffers
-        status_t resize(size_t size, const sp<SurfaceFlinger>& flinger,
-                EGLDisplay dpy);
-
-        // ----------------------------------------------
-        // must be called from GL thread
-
-        // set/get active buffer index
-        status_t setActiveBufferIndex(size_t index);
-        size_t getActiveBufferIndex() const;
-        // return the active buffer
-        sp<GraphicBuffer> getActiveBuffer() const;
-        // return wether we have an active buffer
-        bool hasActiveBuffer() const;
-        // return the active texture (or fail-over)
-        Texture getActiveTexture() const;
-        // frees resources associated with all buffers
-        status_t destroy(EGLDisplay dpy);
-        // load bitmap data into the active buffer
-        status_t loadTexture(const Region& dirty, const GGLSurface& t);
-        // make active buffer an EGLImage if needed
-        status_t initEglImage(EGLDisplay dpy,
-                const sp<GraphicBuffer>& buffer);
-
-        // ----------------------------------------------
-        // only for debugging
-        sp<GraphicBuffer> getBuffer(size_t index) const;
-    };
-
-    // -----------------------------------------------------------------------
+    // constants
+    sp<SurfaceTextureLayer> mSurfaceTexture;
+    GLuint mTextureName;
 
     // thread-safe
-    ClientRef mUserClientRef;
+    volatile int32_t mQueuedFrames;
+
+    // main thread
+    sp<GraphicBuffer> mActiveBuffer;
+    GLfloat mTextureMatrix[16];
+    Rect mCurrentCrop;
+    uint32_t mCurrentTransform;
+    bool mCurrentOpacity;
 
     // constants
     PixelFormat mFormat;
     const GLExtensions& mGLExtensions;
-    bool mNeedsBlending;
+    bool mOpaqueLayer;
     bool mNeedsDithering;
 
     // page-flip thread (currently main thread)
@@ -226,18 +122,8 @@
     // page-flip thread and transaction thread (currently main thread)
     sp<FreezeLock>  mFreezeLock;
 
-    // see threading usage in declaration
-    TextureManager mTextureManager;
-    BufferManager mBufferManager;
-
     // binder thread, transaction thread
     mutable Mutex mLock;
-    uint32_t mWidth;
-    uint32_t mHeight;
-    uint32_t mReqWidth;
-    uint32_t mReqHeight;
-    uint32_t mReqFormat;
-    bool mNeedsScaling;
     bool mFixedSize;
 };
 
diff --git a/services/surfaceflinger/LayerBase.cpp b/services/surfaceflinger/LayerBase.cpp
index 022f251..bcd8c83 100644
--- a/services/surfaceflinger/LayerBase.cpp
+++ b/services/surfaceflinger/LayerBase.cpp
@@ -32,8 +32,6 @@
 #include "LayerBase.h"
 #include "SurfaceFlinger.h"
 #include "DisplayHardware/DisplayHardware.h"
-#include "TextureManager.h"
-
 
 namespace android {
 
@@ -44,7 +42,7 @@
 LayerBase::LayerBase(SurfaceFlinger* flinger, DisplayID display)
     : dpy(display), contentDirty(false),
       sequence(uint32_t(android_atomic_inc(&sSequence))),
-      mFlinger(flinger),
+      mFlinger(flinger), mFiltering(false),
       mNeedsFiltering(false),
       mOrientation(0),
       mLeft(0), mTop(0),
@@ -54,8 +52,6 @@
 {
     const DisplayHardware& hw(flinger->graphicPlane(0).displayHardware());
     mFlags = hw.getFlags();
-    mBufferCrop.makeInvalid();
-    mBufferTransform = 0;
 }
 
 LayerBase::~LayerBase()
@@ -310,6 +306,16 @@
     hwcl->handle = NULL;
 }
 
+void LayerBase::setFiltering(bool filtering)
+{
+    mFiltering = filtering;
+}
+
+bool LayerBase::getFiltering() const
+{
+    return mFiltering;
+}
+
 void LayerBase::draw(const Region& clip) const
 {
     // reset GL state
@@ -318,10 +324,12 @@
     onDraw(clip);
 }
 
-void LayerBase::drawForSreenShot() const
+void LayerBase::drawForSreenShot()
 {
     const DisplayHardware& hw(graphicPlane(0).displayHardware());
+    setFiltering(true);
     onDraw( Region(hw.bounds()) );
+    setFiltering(false);
 }
 
 void LayerBase::clearWithOpenGL(const Region& clip, GLclampf red,
@@ -332,8 +340,12 @@
     const uint32_t fbHeight = hw.getHeight();
     glColor4f(red,green,blue,alpha);
 
-    TextureManager::deactivateTextures();
-
+#if defined(GL_OES_EGL_image_external)
+        if (GLExtensions::getInstance().haveTextureExternal()) {
+            glDisable(GL_TEXTURE_EXTERNAL_OES);
+        }
+#endif
+    glDisable(GL_TEXTURE_2D);
     glDisable(GL_BLEND);
     glDisable(GL_DITHER);
 
@@ -354,24 +366,11 @@
     clearWithOpenGL(clip,0,0,0,0);
 }
 
-template <typename T>
-static inline
-void swap(T& a, T& b) {
-    T t(a);
-    a = b;
-    b = t;
-}
-
-void LayerBase::drawWithOpenGL(const Region& clip, const Texture& texture) const
+void LayerBase::drawWithOpenGL(const Region& clip) const
 {
     const DisplayHardware& hw(graphicPlane(0).displayHardware());
     const uint32_t fbHeight = hw.getHeight();
     const State& s(drawingState());
-    
-    // bind our texture
-    TextureManager::activateTexture(texture, needsFiltering());
-    uint32_t width  = texture.width; 
-    uint32_t height = texture.height;
 
     GLenum src = mPremultipliedAlpha ? GL_ONE : GL_SRC_ALPHA;
     if (UNLIKELY(s.alpha < 0xFF)) {
@@ -387,7 +386,7 @@
     } else {
         glColor4f(1, 1, 1, 1);
         glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
-        if (needsBlending()) {
+        if (!isOpaque()) {
             glEnable(GL_BLEND);
             glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
         } else {
@@ -395,86 +394,20 @@
         }
     }
 
-    /*
-     *  compute texture coordinates
-     *  here, we handle NPOT, cropping and buffer transformations
-     */
-
-    GLfloat cl, ct, cr, cb;
-    if (!mBufferCrop.isEmpty()) {
-        // source is cropped
-        const GLfloat us = (texture.NPOTAdjust ? texture.wScale : 1.0f) / width;
-        const GLfloat vs = (texture.NPOTAdjust ? texture.hScale : 1.0f) / height;
-        cl = mBufferCrop.left   * us;
-        ct = mBufferCrop.top    * vs;
-        cr = mBufferCrop.right  * us;
-        cb = mBufferCrop.bottom * vs;
-    } else {
-        cl = 0;
-        ct = 0;
-        cr = (texture.NPOTAdjust ? texture.wScale : 1.0f);
-        cb = (texture.NPOTAdjust ? texture.hScale : 1.0f);
-    }
-
-    /*
-     * For the buffer transformation, we apply the rotation last.
-     * Since we're transforming the texture-coordinates, we need
-     * to apply the inverse of the buffer transformation:
-     *   inverse( FLIP_V -> FLIP_H -> ROT_90 )
-     *   <=> inverse( ROT_90 * FLIP_H * FLIP_V )
-     *    =  inverse(FLIP_V) * inverse(FLIP_H) * inverse(ROT_90)
-     *    =  FLIP_V * FLIP_H * ROT_270
-     *   <=> ROT_270 -> FLIP_H -> FLIP_V
-     *
-     * The rotation is performed first, in the texture coordinate space.
-     *
-     */
-
     struct TexCoords {
         GLfloat u;
         GLfloat v;
     };
 
-    enum {
-        // name of the corners in the texture map
-        LB = 0, // left-bottom
-        LT = 1, // left-top
-        RT = 2, // right-top
-        RB = 3  // right-bottom
-    };
-
-    // vertices in screen space
-    int vLT = LB;
-    int vLB = LT;
-    int vRB = RT;
-    int vRT = RB;
-
-    // the texture's source is rotated
-    uint32_t transform = mBufferTransform;
-    if (transform & HAL_TRANSFORM_ROT_90) {
-        vLT = RB;
-        vLB = LB;
-        vRB = LT;
-        vRT = RT;
-    }
-    if (transform & HAL_TRANSFORM_FLIP_V) {
-        swap(vLT, vLB);
-        swap(vRT, vRB);
-    }
-    if (transform & HAL_TRANSFORM_FLIP_H) {
-        swap(vLT, vRT);
-        swap(vLB, vRB);
-    }
-
     TexCoords texCoords[4];
-    texCoords[vLT].u = cl;
-    texCoords[vLT].v = ct;
-    texCoords[vLB].u = cl;
-    texCoords[vLB].v = cb;
-    texCoords[vRB].u = cr;
-    texCoords[vRB].v = cb;
-    texCoords[vRT].u = cr;
-    texCoords[vRT].v = ct;
+    texCoords[0].u = 0;
+    texCoords[0].v = 1;
+    texCoords[1].u = 0;
+    texCoords[1].v = 0;
+    texCoords[2].u = 1;
+    texCoords[2].v = 0;
+    texCoords[3].u = 1;
+    texCoords[3].v = 1;
 
     if (needsDithering()) {
         glEnable(GL_DITHER);
@@ -497,20 +430,6 @@
     glDisableClientState(GL_TEXTURE_COORD_ARRAY);
 }
 
-void LayerBase::setBufferCrop(const Rect& crop) {
-    if (mBufferCrop != crop) {
-        mBufferCrop = crop;
-        mFlinger->invalidateHwcGeometry();
-    }
-}
-
-void LayerBase::setBufferTransform(uint32_t transform) {
-    if (mBufferTransform != transform) {
-        mBufferTransform = transform;
-        mFlinger->invalidateHwcGeometry();
-    }
-}
-
 void LayerBase::dump(String8& result, char* buffer, size_t SIZE) const
 {
     const Layer::State& s(drawingState());
@@ -518,10 +437,10 @@
             "+ %s %p\n"
             "      "
             "z=%9d, pos=(%4d,%4d), size=(%4d,%4d), "
-            "needsBlending=%1d, needsDithering=%1d, invalidate=%1d, "
+            "isOpaque=%1d, needsDithering=%1d, invalidate=%1d, "
             "alpha=0x%02x, flags=0x%08x, tr=[%.2f, %.2f][%.2f, %.2f]\n",
             getTypeId(), this, s.z, tx(), ty(), s.w, s.h,
-            needsBlending(), needsDithering(), contentDirty,
+            isOpaque(), needsDithering(), contentDirty,
             s.alpha, s.flags,
             s.transform[0][0], s.transform[0][1],
             s.transform[1][0], s.transform[1][1]);
@@ -555,9 +474,22 @@
     }
 }
 
-sp<LayerBaseClient::Surface> LayerBaseClient::getSurface()
+sp<ISurface> LayerBaseClient::createSurface()
 {
-    sp<Surface> s;
+    class BSurface : public BnSurface, public LayerCleaner {
+        virtual sp<ISurfaceTexture> getSurfaceTexture() const { return 0; }
+    public:
+        BSurface(const sp<SurfaceFlinger>& flinger,
+                const sp<LayerBaseClient>& layer)
+            : LayerCleaner(flinger, layer) { }
+    };
+    sp<ISurface> sur(new BSurface(mFlinger, this));
+    return sur;
+}
+
+sp<ISurface> LayerBaseClient::getSurface()
+{
+    sp<ISurface> s;
     Mutex::Autolock _l(mLock);
 
     LOG_ALWAYS_FATAL_IF(mHasSurface,
@@ -573,12 +505,6 @@
     return mClientSurfaceBinder;
 }
 
-sp<LayerBaseClient::Surface> LayerBaseClient::createSurface() const
-{
-    return new Surface(mFlinger, mIdentity,
-            const_cast<LayerBaseClient *>(this));
-}
-
 void LayerBaseClient::dump(String8& result, char* buffer, size_t SIZE) const
 {
     LayerBase::dump(result, buffer, SIZE);
@@ -601,44 +527,14 @@
 
 // ---------------------------------------------------------------------------
 
-LayerBaseClient::Surface::Surface(
-        const sp<SurfaceFlinger>& flinger,
-        int identity,
-        const sp<LayerBaseClient>& owner) 
-    : mFlinger(flinger), mIdentity(identity), mOwner(owner)
-{
+LayerBaseClient::LayerCleaner::LayerCleaner(const sp<SurfaceFlinger>& flinger,
+        const sp<LayerBaseClient>& layer)
+    : mFlinger(flinger), mLayer(layer) {
 }
 
-LayerBaseClient::Surface::~Surface() 
-{
-    /*
-     * This is a good place to clean-up all client resources 
-     */
-
+LayerBaseClient::LayerCleaner::~LayerCleaner() {
     // destroy client resources
-    mFlinger->destroySurface(mOwner);
-}
-
-sp<LayerBaseClient> LayerBaseClient::Surface::getOwner() const {
-    sp<LayerBaseClient> owner(mOwner.promote());
-    return owner;
-}
-
-status_t LayerBaseClient::Surface::onTransact(
-        uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
-{
-    return BnSurface::onTransact(code, data, reply, flags);
-}
-
-sp<GraphicBuffer> LayerBaseClient::Surface::requestBuffer(int bufferIdx,
-        uint32_t w, uint32_t h, uint32_t format, uint32_t usage)
-{
-    return NULL; 
-}
-
-status_t LayerBaseClient::Surface::setBufferCount(int bufferCount)
-{
-    return INVALID_OPERATION;
+    mFlinger->destroySurface(mLayer);
 }
 
 // ---------------------------------------------------------------------------
diff --git a/services/surfaceflinger/LayerBase.h b/services/surfaceflinger/LayerBase.h
index 6c49a19..faf71dd 100644
--- a/services/surfaceflinger/LayerBase.h
+++ b/services/surfaceflinger/LayerBase.h
@@ -29,7 +29,6 @@
 #include <ui/Region.h>
 
 #include <surfaceflinger/ISurfaceComposerClient.h>
-#include <private/surfaceflinger/SharedBufferStack.h>
 #include <private/surfaceflinger/LayerState.h>
 
 #include <pixelflinger/pixelflinger.h>
@@ -43,13 +42,12 @@
 
 // ---------------------------------------------------------------------------
 
-class DisplayHardware;
 class Client;
+class DisplayHardware;
 class GraphicBuffer;
 class GraphicPlane;
 class LayerBaseClient;
 class SurfaceFlinger;
-class Texture;
 
 // ---------------------------------------------------------------------------
 
@@ -121,7 +119,7 @@
      * to perform the actual drawing.  
      */
     virtual void draw(const Region& clip) const;
-    virtual void drawForSreenShot() const;
+    virtual void drawForSreenShot();
     
     /**
      * onDraw - draws the surface.
@@ -174,9 +172,9 @@
     virtual void unlockPageFlip(const Transform& planeTransform, Region& outDirtyRegion);
     
     /**
-     * needsBlending - true if this surface needs blending
+     * isOpaque - true if this surface is opaque
      */
-    virtual bool needsBlending() const  { return false; }
+    virtual bool isOpaque() const  { return true; }
 
     /**
      * needsDithering - true if this surface needs dithering
@@ -184,11 +182,9 @@
     virtual bool needsDithering() const { return false; }
 
     /**
-     * needsLinearFiltering - true if this surface needs filtering
+     * needsLinearFiltering - true if this surface's state requires filtering
      */
-    virtual bool needsFiltering() const {
-        return (!(mFlags & DisplayHardware::SLOW_CONFIG)) && mNeedsFiltering;
-    }
+    virtual bool needsFiltering() const { return mNeedsFiltering; }
 
     /**
      * isSecure - true if this surface is secure, that is if it prevents
@@ -231,21 +227,25 @@
           void clearWithOpenGL(const Region& clip, GLclampf r, GLclampf g,
                                GLclampf b, GLclampf alpha) const;
           void clearWithOpenGL(const Region& clip) const;
-          void drawWithOpenGL(const Region& clip, const Texture& texture) const;
-          
-          // these must be called from the post/drawing thread
-          void setBufferCrop(const Rect& crop);
-          void setBufferTransform(uint32_t transform);
+          void drawWithOpenGL(const Region& clip) const;
+
+          void setFiltering(bool filtering);
+          bool getFiltering() const;
 
                 sp<SurfaceFlinger> mFlinger;
                 uint32_t        mFlags;
 
-                // post/drawing thread
-                Rect mBufferCrop;
-                uint32_t mBufferTransform;
+private:
+                // accessed only in the main thread
+                // Whether filtering is forced on or not
+                bool            mFiltering;
 
                 // cached during validateVisibility()
+                // Whether filtering is needed b/c of the drawingstate
                 bool            mNeedsFiltering;
+
+protected:
+                // cached during validateVisibility()
                 int32_t         mOrientation;
                 GLfloat         mVertices[4][2];
                 Rect            mTransformedBounds;
@@ -281,52 +281,38 @@
 class LayerBaseClient : public LayerBase
 {
 public:
-    class Surface;
-
             LayerBaseClient(SurfaceFlinger* flinger, DisplayID display,
                         const sp<Client>& client);
-    virtual ~LayerBaseClient();
 
-            sp<Surface> getSurface();
+            virtual ~LayerBaseClient();
+
+            sp<ISurface> getSurface();
             wp<IBinder> getSurfaceBinder() const;
-    virtual sp<Surface> createSurface() const;
+
     virtual sp<LayerBaseClient> getLayerBaseClient() const {
         return const_cast<LayerBaseClient*>(this); }
+
     virtual const char* getTypeId() const { return "LayerBaseClient"; }
 
     uint32_t getIdentity() const { return mIdentity; }
 
-    class Surface : public BnSurface  {
-    public:
-        int32_t getIdentity() const { return mIdentity; }
-        
-    protected:
-        Surface(const sp<SurfaceFlinger>& flinger, int identity,
-                const sp<LayerBaseClient>& owner);
-        virtual ~Surface();
-        virtual status_t onTransact(uint32_t code, const Parcel& data,
-                Parcel* reply, uint32_t flags);
-        sp<LayerBaseClient> getOwner() const;
-
-    private:
-        virtual sp<GraphicBuffer> requestBuffer(int bufferIdx,
-                uint32_t w, uint32_t h, uint32_t format, uint32_t usage);
-        virtual status_t setBufferCount(int bufferCount);
-
-    protected:
-        friend class LayerBaseClient;
-        sp<SurfaceFlinger>  mFlinger;
-        int32_t             mIdentity;
-        wp<LayerBaseClient> mOwner;
-    };
-
-    friend class Surface;
-
 protected:
     virtual void dump(String8& result, char* scratch, size_t size) const;
     virtual void shortDump(String8& result, char* scratch, size_t size) const;
 
+    class LayerCleaner {
+        sp<SurfaceFlinger> mFlinger;
+        wp<LayerBaseClient> mLayer;
+    protected:
+        ~LayerCleaner();
+    public:
+        LayerCleaner(const sp<SurfaceFlinger>& flinger,
+                const sp<LayerBaseClient>& layer);
+    };
+
 private:
+    virtual sp<ISurface> createSurface();
+
     mutable Mutex mLock;
     mutable bool mHasSurface;
     wp<IBinder> mClientSurfaceBinder;
diff --git a/services/surfaceflinger/LayerDim.cpp b/services/surfaceflinger/LayerDim.cpp
index f79166d..654817d 100644
--- a/services/surfaceflinger/LayerDim.cpp
+++ b/services/surfaceflinger/LayerDim.cpp
@@ -65,8 +65,6 @@
             glDisable(GL_TEXTURE_EXTERNAL_OES);
         }
 #endif
-        glDisable(GL_TEXTURE_2D);
-
         glVertexPointer(2, GL_FLOAT, 0, mVertices);
 
         while (it != end) {
diff --git a/services/surfaceflinger/LayerDim.h b/services/surfaceflinger/LayerDim.h
index 75f9a89..8770e6d 100644
--- a/services/surfaceflinger/LayerDim.h
+++ b/services/surfaceflinger/LayerDim.h
@@ -37,7 +37,7 @@
         virtual ~LayerDim();
 
     virtual void onDraw(const Region& clip) const;
-    virtual bool needsBlending() const    { return true; }
+    virtual bool isOpaque() const         { return false; }
     virtual bool isSecure() const         { return false; }
     virtual bool isProtectedByApp() const { return false; }
     virtual bool isProtectedByDRM() const { return false; }
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index b7a51a4..97edfee 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -53,6 +53,8 @@
 #include "DisplayHardware/DisplayHardware.h"
 #include "DisplayHardware/HWComposer.h"
 
+#include <private/surfaceflinger/SharedBufferStack.h>
+
 /* ideally AID_GRAPHICS would be in a semi-public header
  * or there would be a way to map a user/group name to its id
  */
@@ -133,17 +135,6 @@
     return bclient;
 }
 
-sp<ISurfaceComposerClient> SurfaceFlinger::createClientConnection()
-{
-    sp<ISurfaceComposerClient> bclient;
-    sp<UserClient> client(new UserClient(this));
-    status_t err = client->initCheck();
-    if (err == NO_ERROR) {
-        bclient = client;
-    }
-    return bclient;
-}
-
 sp<IGraphicBufferAlloc> SurfaceFlinger::createGraphicBufferAlloc()
 {
     sp<GraphicBufferAlloc> gba(new GraphicBufferAlloc());
@@ -322,11 +313,6 @@
     mEventQueue.invalidate();
 }
 
-void SurfaceFlinger::signal() const {
-    // this is the IPC call
-    const_cast<SurfaceFlinger*>(this)->signalEvent();
-}
-
 bool SurfaceFlinger::authenticateSurface(const sp<ISurface>& surface) const {
     Mutex::Autolock _l(mStateLock);
     sp<IBinder> surfBinder(surface->asBinder());
@@ -658,7 +644,7 @@
 
         // handle hidden surfaces by setting the visible region to empty
         if (LIKELY(!(s.flags & ISurfaceComposer::eLayerHidden) && s.alpha)) {
-            const bool translucent = layer->needsBlending();
+            const bool translucent = !layer->isOpaque();
             const Rect bounds(layer->visibleBounds());
             visibleRegion.set(bounds);
             visibleRegion.andSelf(screenRegion);
@@ -921,7 +907,7 @@
             for (size_t i=0 ; i<count ; i++) {
                 if (cur[i].hints & HWC_HINT_CLEAR_FB) {
                     const sp<LayerBase>& layer(layers[i]);
-                    if (!(layer->needsBlending())) {
+                    if (layer->isOpaque()) {
                         transparent.orSelf(layer->visibleRegionScreen);
                     }
                 }
@@ -979,8 +965,6 @@
         composeSurfaces(repaint);
     }
 
-    TextureManager::deactivateTextures();
-
     glDisable(GL_BLEND);
     glDisable(GL_DITHER);
     glDisable(GL_SCISSOR_TEST);
@@ -1070,6 +1054,7 @@
             glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
         }
         glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+        glDisable(GL_TEXTURE_2D);
         glLoadIdentity();
         glMatrixMode(GL_MODELVIEW);
     }
@@ -1269,7 +1254,7 @@
         uint32_t flags)
 {
     sp<LayerBaseClient> layer;
-    sp<LayerBaseClient::Surface> surfaceHandle;
+    sp<ISurface> surfaceHandle;
 
     if (int32_t(w|h) < 0) {
         LOGE("createSurface() failed, w or h is negative (w=%d, h=%d)",
@@ -1300,13 +1285,13 @@
         surfaceHandle = layer->getSurface();
         if (surfaceHandle != 0) {
             params->token = token;
-            params->identity = surfaceHandle->getIdentity();
+            params->identity = layer->getIdentity();
             params->width = w;
             params->height = h;
             params->format = format;
             if (normalLayer != 0) {
                 Mutex::Autolock _l(mStateLock);
-                mLayerMap.add(surfaceHandle->asBinder(), normalLayer);
+                mLayerMap.add(layer->getSurfaceBinder(), normalLayer);
             }
         }
 
@@ -1782,7 +1767,6 @@
 
     GLfloat vtx[8];
     const GLfloat texCoords[4][2] = { {0,v}, {0,0}, {u,0}, {u,v} };
-    glEnable(GL_TEXTURE_2D);
     glBindTexture(GL_TEXTURE_2D, tname);
     glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
     glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
@@ -1900,6 +1884,7 @@
     glEnable(GL_SCISSOR_TEST);
     glDisableClientState(GL_TEXTURE_COORD_ARRAY);
     glDeleteTextures(1, &tname);
+    glDisable(GL_TEXTURE_2D);
     return NO_ERROR;
 }
 
@@ -1930,7 +1915,6 @@
 
     GLfloat vtx[8];
     const GLfloat texCoords[4][2] = { {0,v}, {0,0}, {u,0}, {u,v} };
-    glEnable(GL_TEXTURE_2D);
     glBindTexture(GL_TEXTURE_2D, tname);
     glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
     glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
@@ -2044,6 +2028,7 @@
     glEnable(GL_SCISSOR_TEST);
     glDisableClientState(GL_TEXTURE_COORD_ARRAY);
     glDeleteTextures(1, &tname);
+    glDisable(GL_TEXTURE_2D);
 
     return NO_ERROR;
 }
@@ -2408,20 +2393,72 @@
     return lbc;
 }
 
-sp<IMemoryHeap> Client::getControlBlock() const {
-    return 0;
+
+status_t Client::onTransact(
+    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
+{
+    // these must be checked
+     IPCThreadState* ipc = IPCThreadState::self();
+     const int pid = ipc->getCallingPid();
+     const int uid = ipc->getCallingUid();
+     const int self_pid = getpid();
+     if (UNLIKELY(pid != self_pid && uid != AID_GRAPHICS && uid != 0)) {
+         // we're called from a different process, do the real check
+         if (!checkCallingPermission(
+                 String16("android.permission.ACCESS_SURFACE_FLINGER")))
+         {
+             LOGE("Permission Denial: "
+                     "can't openGlobalTransaction pid=%d, uid=%d", pid, uid);
+             return PERMISSION_DENIED;
+         }
+     }
+     return BnSurfaceComposerClient::onTransact(code, data, reply, flags);
 }
-ssize_t Client::getTokenForSurface(const sp<ISurface>& sur) const {
-    return -1;
-}
+
+
 sp<ISurface> Client::createSurface(
         ISurfaceComposerClient::surface_data_t* params,
         const String8& name,
         DisplayID display, uint32_t w, uint32_t h, PixelFormat format,
         uint32_t flags)
 {
-    return mFlinger->createSurface(params, name, this,
-            display, w, h, format, flags);
+    /*
+     * createSurface must be called from the GL thread so that it can
+     * have access to the GL context.
+     */
+
+    class MessageCreateSurface : public MessageBase {
+        sp<ISurface> result;
+        SurfaceFlinger* flinger;
+        ISurfaceComposerClient::surface_data_t* params;
+        Client* client;
+        const String8& name;
+        DisplayID display;
+        uint32_t w, h;
+        PixelFormat format;
+        uint32_t flags;
+    public:
+        MessageCreateSurface(SurfaceFlinger* flinger,
+                ISurfaceComposerClient::surface_data_t* params,
+                const String8& name, Client* client,
+                DisplayID display, uint32_t w, uint32_t h, PixelFormat format,
+                uint32_t flags)
+            : flinger(flinger), params(params), client(client), name(name),
+              display(display), w(w), h(h), format(format), flags(flags)
+        {
+        }
+        sp<ISurface> getResult() const { return result; }
+        virtual bool handler() {
+            result = flinger->createSurface(params, name, client,
+                    display, w, h, format, flags);
+            return true;
+        }
+    };
+
+    sp<MessageBase> msg = new MessageCreateSurface(mFlinger.get(),
+            params, name, this, display, w, h, format, flags);
+    mFlinger->postMessageSync(msg);
+    return static_cast<MessageCreateSurface*>( msg.get() )->getResult();
 }
 status_t Client::destroySurface(SurfaceID sid) {
     return mFlinger->removeSurface(this, sid);
@@ -2432,113 +2469,6 @@
 
 // ---------------------------------------------------------------------------
 
-UserClient::UserClient(const sp<SurfaceFlinger>& flinger)
-    : ctrlblk(0), mBitmap(0), mFlinger(flinger)
-{
-    const int pgsize = getpagesize();
-    const int cblksize = ((sizeof(SharedClient)+(pgsize-1))&~(pgsize-1));
-
-    mCblkHeap = new MemoryHeapBase(cblksize, 0,
-            "SurfaceFlinger Client control-block");
-
-    ctrlblk = static_cast<SharedClient *>(mCblkHeap->getBase());
-    if (ctrlblk) { // construct the shared structure in-place.
-        new(ctrlblk) SharedClient;
-    }
-}
-
-UserClient::~UserClient()
-{
-    if (ctrlblk) {
-        ctrlblk->~SharedClient();  // destroy our shared-structure.
-    }
-
-    /*
-     * When a UserClient dies, it's unclear what to do exactly.
-     * We could go ahead and destroy all surfaces linked to that client
-     * however, it wouldn't be fair to the main Client
-     * (usually the the window-manager), which might want to re-target
-     * the layer to another UserClient.
-     * I think the best is to do nothing, or not much; in most cases the
-     * WM itself will go ahead and clean things up when it detects a client of
-     * his has died.
-     * The remaining question is what to display? currently we keep
-     * just keep the current buffer.
-     */
-}
-
-status_t UserClient::initCheck() const {
-    return ctrlblk == 0 ? NO_INIT : NO_ERROR;
-}
-
-void UserClient::detachLayer(const Layer* layer)
-{
-    int32_t name = layer->getToken();
-    if (name >= 0) {
-        int32_t mask = 1LU<<name;
-        if ((android_atomic_and(~mask, &mBitmap) & mask) == 0) {
-            LOGW("token %d wasn't marked as used %08x", name, int(mBitmap));
-        }
-    }
-}
-
-sp<IMemoryHeap> UserClient::getControlBlock() const {
-    return mCblkHeap;
-}
-
-ssize_t UserClient::getTokenForSurface(const sp<ISurface>& sur) const
-{
-    int32_t name = NAME_NOT_FOUND;
-    sp<Layer> layer(mFlinger->getLayer(sur));
-    if (layer == 0) {
-        return name;
-    }
-
-    // if this layer already has a token, just return it
-    name = layer->getToken();
-    if ((name >= 0) && (layer->getClient() == this)) {
-        return name;
-    }
-
-    name = 0;
-    do {
-        int32_t mask = 1LU<<name;
-        if ((android_atomic_or(mask, &mBitmap) & mask) == 0) {
-            // we found and locked that name
-            status_t err = layer->setToken(
-                    const_cast<UserClient*>(this), ctrlblk, name);
-            if (err != NO_ERROR) {
-                // free the name
-                android_atomic_and(~mask, &mBitmap);
-                name = err;
-            }
-            break;
-        }
-        if (++name >= int32_t(SharedBufferStack::NUM_LAYERS_MAX))
-            name = NO_MEMORY;
-    } while(name >= 0);
-
-    //LOGD("getTokenForSurface(%p) => %d (client=%p, bitmap=%08lx)",
-    //        sur->asBinder().get(), name, this, mBitmap);
-    return name;
-}
-
-sp<ISurface> UserClient::createSurface(
-        ISurfaceComposerClient::surface_data_t* params,
-        const String8& name,
-        DisplayID display, uint32_t w, uint32_t h, PixelFormat format,
-        uint32_t flags) {
-    return 0;
-}
-status_t UserClient::destroySurface(SurfaceID sid) {
-    return INVALID_OPERATION;
-}
-status_t UserClient::setState(int32_t count, const layer_state_t* states) {
-    return INVALID_OPERATION;
-}
-
-// ---------------------------------------------------------------------------
-
 GraphicBufferAlloc::GraphicBufferAlloc() {}
 
 GraphicBufferAlloc::~GraphicBufferAlloc() {}
@@ -2547,11 +2477,11 @@
         PixelFormat format, uint32_t usage) {
     sp<GraphicBuffer> graphicBuffer(new GraphicBuffer(w, h, format, usage));
     status_t err = graphicBuffer->initCheck();
-    if (err != 0) {
-        LOGE("createGraphicBuffer: init check failed: %d", err);
-        return 0;
-    } else if (graphicBuffer->handle == 0) {
-        LOGE("createGraphicBuffer: unable to create GraphicBuffer");
+    if (err != 0 || graphicBuffer->handle == 0) {
+        GraphicBuffer::dumpAllocationsToSystemLog();
+        LOGE("GraphicBufferAlloc::createGraphicBuffer(w=%d, h=%d) "
+             "failed (%s), handle=%p",
+                w, h, strerror(-err), graphicBuffer->handle);
         return 0;
     }
     return graphicBuffer;
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index 992861a..af1ef04 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -50,6 +50,7 @@
 class FreezeLock;
 class Layer;
 class LayerDim;
+struct surface_flinger_cblk_t;
 
 #define LIKELY( exp )       (__builtin_expect( (exp) != 0, true  ))
 #define UNLIKELY( exp )     (__builtin_expect( (exp) != 0, false ))
@@ -72,14 +73,14 @@
 private:
 
     // ISurfaceComposerClient interface
-    virtual sp<IMemoryHeap> getControlBlock() const;
-    virtual ssize_t getTokenForSurface(const sp<ISurface>& sur) const;
     virtual sp<ISurface> createSurface(
             surface_data_t* params, const String8& name,
             DisplayID display, uint32_t w, uint32_t h,PixelFormat format,
             uint32_t flags);
     virtual status_t destroySurface(SurfaceID surfaceId);
     virtual status_t setState(int32_t count, const layer_state_t* states);
+    virtual status_t onTransact(
+        uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags);
 
     // constant
     sp<SurfaceFlinger> mFlinger;
@@ -92,40 +93,6 @@
     mutable Mutex mLock;
 };
 
-class UserClient : public BnSurfaceComposerClient
-{
-public:
-    // pointer to this client's control block
-    SharedClient* ctrlblk;
-
-public:
-        UserClient(const sp<SurfaceFlinger>& flinger);
-        ~UserClient();
-
-    status_t initCheck() const;
-
-    // protected by SurfaceFlinger::mStateLock
-    void detachLayer(const Layer* layer);
-
-private:
-
-    // ISurfaceComposerClient interface
-    virtual sp<IMemoryHeap> getControlBlock() const;
-    virtual ssize_t getTokenForSurface(const sp<ISurface>& sur) const;
-    virtual sp<ISurface> createSurface(
-            surface_data_t* params, const String8& name,
-            DisplayID display, uint32_t w, uint32_t h,PixelFormat format,
-            uint32_t flags);
-    virtual status_t destroySurface(SurfaceID surfaceId);
-    virtual status_t setState(int32_t count, const layer_state_t* states);
-
-    // atomic-ops
-    mutable volatile int32_t mBitmap;
-
-    sp<IMemoryHeap> mCblkHeap;
-    sp<SurfaceFlinger> mFlinger;
-};
-
 class GraphicBufferAlloc : public BnGraphicBufferAlloc
 {
 public:
@@ -199,7 +166,6 @@
 
     // ISurfaceComposer interface
     virtual sp<ISurfaceComposerClient>  createConnection();
-    virtual sp<ISurfaceComposerClient>  createClientConnection();
     virtual sp<IGraphicBufferAlloc>     createGraphicBufferAlloc();
     virtual sp<IMemoryHeap>             getCblk() const;
     virtual void                        bootFinished();
@@ -208,7 +174,6 @@
     virtual status_t                    freezeDisplay(DisplayID dpy, uint32_t flags);
     virtual status_t                    unfreezeDisplay(DisplayID dpy, uint32_t flags);
     virtual int                         setOrientation(DisplayID dpy, int orientation, uint32_t flags);
-    virtual void                        signal() const;
     virtual bool                        authenticateSurface(const sp<ISurface>& surface) const;
 
     virtual status_t captureScreen(DisplayID dpy,
@@ -235,7 +200,6 @@
     friend class Client;
     friend class LayerBase;
     friend class LayerBaseClient;
-    friend class LayerBaseClient::Surface;
     friend class Layer;
     friend class LayerDim;
 
diff --git a/services/surfaceflinger/SurfaceTextureLayer.cpp b/services/surfaceflinger/SurfaceTextureLayer.cpp
new file mode 100644
index 0000000..60fa965
--- /dev/null
+++ b/services/surfaceflinger/SurfaceTextureLayer.cpp
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdlib.h>
+#include <stdint.h>
+#include <sys/types.h>
+
+#include <utils/Errors.h>
+
+#include "Layer.h"
+#include "SurfaceTextureLayer.h"
+
+namespace android {
+// ---------------------------------------------------------------------------
+
+
+SurfaceTextureLayer::SurfaceTextureLayer(GLuint tex, const sp<Layer>& layer)
+    : SurfaceTexture(tex), mLayer(layer) {
+}
+
+SurfaceTextureLayer::~SurfaceTextureLayer() {
+}
+
+
+status_t SurfaceTextureLayer::setDefaultBufferSize(uint32_t w, uint32_t h)
+{
+    //LOGD("%s, w=%u, h=%u", __PRETTY_FUNCTION__, w, h);
+    return SurfaceTexture::setDefaultBufferSize(w, h);
+}
+
+status_t SurfaceTextureLayer::setDefaultBufferFormat(uint32_t format)
+{
+    mDefaultFormat = format;
+    return NO_ERROR;
+}
+
+status_t SurfaceTextureLayer::setBufferCount(int bufferCount) {
+    status_t res = SurfaceTexture::setBufferCount(bufferCount);
+    return res;
+}
+
+status_t SurfaceTextureLayer::dequeueBuffer(int *buf,
+        uint32_t w, uint32_t h, uint32_t format, uint32_t usage) {
+
+    status_t res(NO_INIT);
+    sp<Layer> layer(mLayer.promote());
+    if (layer != NULL) {
+        if (format == 0)
+            format = mDefaultFormat;
+        uint32_t effectiveUsage = layer->getEffectiveUsage(usage);
+        //LOGD("%s, w=%u, h=%u, format=%u, usage=%08x, effectiveUsage=%08x",
+        //        __PRETTY_FUNCTION__, w, h, format, usage, effectiveUsage);
+        res = SurfaceTexture::dequeueBuffer(buf, w, h, format, effectiveUsage);
+        if (res == NO_ERROR) {
+            layer->setFixedSize(w && h);
+        }
+    }
+    return res;
+}
+
+
+// ---------------------------------------------------------------------------
+}; // namespace android
diff --git a/services/surfaceflinger/SurfaceTextureLayer.h b/services/surfaceflinger/SurfaceTextureLayer.h
new file mode 100644
index 0000000..7faff54
--- /dev/null
+++ b/services/surfaceflinger/SurfaceTextureLayer.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_SURFACE_TEXTURE_LAYER_H
+#define ANDROID_SURFACE_TEXTURE_LAYER_H
+
+#include <stdlib.h>
+#include <stdint.h>
+#include <sys/types.h>
+
+#include <utils/Errors.h>
+#include <gui/SurfaceTexture.h>
+
+namespace android {
+// ---------------------------------------------------------------------------
+
+class Layer;
+
+class SurfaceTextureLayer : public SurfaceTexture
+{
+    wp<Layer> mLayer;
+    uint32_t mDefaultFormat;
+
+public:
+    SurfaceTextureLayer(GLuint tex, const sp<Layer>& layer);
+    ~SurfaceTextureLayer();
+
+    status_t setDefaultBufferSize(uint32_t w, uint32_t h);
+    status_t setDefaultBufferFormat(uint32_t format);
+
+public:
+    virtual status_t setBufferCount(int bufferCount);
+
+protected:
+    virtual status_t dequeueBuffer(int *buf, uint32_t w, uint32_t h,
+            uint32_t format, uint32_t usage);
+};
+
+// ---------------------------------------------------------------------------
+}; // namespace android
+
+#endif // ANDROID_SURFACE_TEXTURE_LAYER_H
diff --git a/services/surfaceflinger/clz.h b/services/surfaceflinger/clz.h
index 0ddf986..ca445553 100644
--- a/services/surfaceflinger/clz.h
+++ b/services/surfaceflinger/clz.h
@@ -20,18 +20,10 @@
 
 namespace android {
 
-int clz_impl(int32_t x);
-
-int inline clz(int32_t x)
-{
-#if defined(__arm__) && !defined(__thumb__)
+int inline clz(int32_t x) {
     return __builtin_clz(x);
-#else
-    return clz_impl(x);
-#endif
 }
 
-
 }; // namespace android
 
 #endif /* ANDROID_SURFACE_FLINGER_CLZ_H */
diff --git a/services/tests/servicestests/AndroidManifest.xml b/services/tests/servicestests/AndroidManifest.xml
index f8d1426..ee5f3f5 100644
--- a/services/tests/servicestests/AndroidManifest.xml
+++ b/services/tests/servicestests/AndroidManifest.xml
@@ -24,7 +24,12 @@
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
     <uses-permission android:name="android.permission.BROADCAST_STICKY" />
     <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
-    
+    <uses-permission android:name="android.permission.UPDATE_DEVICE_STATS" />
+    <uses-permission android:name="android.permission.MANAGE_APP_TOKENS" />
+    <uses-permission android:name="android.permission.MANAGE_NETWORK_POLICY" />
+    <uses-permission android:name="android.permission.READ_NETWORK_USAGE_HISTORY" />
+    <uses-permission android:name="android.permission.CONNECTIVITY_INTERNAL" />
+
     <application>
         <uses-library android:name="android.test.runner" />
 
diff --git a/services/tests/servicestests/src/com/android/server/AccessibilityManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/AccessibilityManagerServiceTest.java
index 2bc6825..302a2d6 100644
--- a/services/tests/servicestests/src/com/android/server/AccessibilityManagerServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/AccessibilityManagerServiceTest.java
@@ -150,7 +150,8 @@
         String secondMockServiceClassName = MySecondMockAccessibilityService.class.getName();
 
         // look for the two mock services
-        for (ServiceInfo serviceInfo : mManagerService.getAccessibilityServiceList()) {
+        for (AccessibilityServiceInfo info : mManagerService.getInstalledAccessibilityServiceList()) {
+            ServiceInfo serviceInfo = info.getResolveInfo().serviceInfo;
             if (packageName.equals(serviceInfo.packageName)) {
                 if (firstMockServiceClassName.equals(serviceInfo.name)) {
                     firstMockServiceInstalled = true;
diff --git a/services/tests/servicestests/src/com/android/server/AccessibilityManagerTest.java b/services/tests/servicestests/src/com/android/server/AccessibilityManagerTest.java
index 38fed22..1463d30 100644
--- a/services/tests/servicestests/src/com/android/server/AccessibilityManagerTest.java
+++ b/services/tests/servicestests/src/com/android/server/AccessibilityManagerTest.java
@@ -25,6 +25,7 @@
 
 import org.easymock.IArgumentMatcher;
 
+import android.accessibilityservice.AccessibilityServiceInfo;
 import android.content.pm.ServiceInfo;
 import android.test.AndroidTestCase;
 import android.test.suitebuilder.annotation.LargeTest;
@@ -62,20 +63,22 @@
     @MediumTest
     public void testGetAccessibilityServiceList() throws Exception {
         // create a list of installed accessibility services the mock service returns
-        List<ServiceInfo> expectedServices = new ArrayList<ServiceInfo>();
-        ServiceInfo serviceInfo = new ServiceInfo();
-        serviceInfo.name = "TestServiceInfoName";
-        expectedServices.add(serviceInfo);
+        List<AccessibilityServiceInfo> expectedServices = new ArrayList<AccessibilityServiceInfo>();
+        AccessibilityServiceInfo accessibilityServiceInfo = new AccessibilityServiceInfo();
+        accessibilityServiceInfo.packageNames = new String[] { "foo.bar" };
+        expectedServices.add(accessibilityServiceInfo);
 
         // configure the mock service behavior
         IAccessibilityManager mockServiceInterface = mMockServiceInterface;
         expect(mockServiceInterface.addClient(anyIAccessibilityManagerClient())).andReturn(true);
-        expect(mockServiceInterface.getAccessibilityServiceList()).andReturn(expectedServices);
+        expect(mockServiceInterface.getInstalledAccessibilityServiceList()).andReturn(
+                expectedServices);
         replay(mockServiceInterface);
 
         // invoke the method under test
         AccessibilityManager manager = new AccessibilityManager(mContext, mockServiceInterface);
-        List<ServiceInfo> receivedServices = manager.getAccessibilityServiceList();
+        List<AccessibilityServiceInfo> receivedServices =
+            manager.getInstalledAccessibilityServiceList();
 
         // check expected result (list equals() compares it contents as well)
         assertEquals("All expected services must be returned", receivedServices, expectedServices);
diff --git a/services/tests/servicestests/src/com/android/server/BroadcastInterceptingContext.java b/services/tests/servicestests/src/com/android/server/BroadcastInterceptingContext.java
new file mode 100644
index 0000000..fe88793
--- /dev/null
+++ b/services/tests/servicestests/src/com/android/server/BroadcastInterceptingContext.java
@@ -0,0 +1,132 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.ContextWrapper;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.Handler;
+
+import com.google.common.collect.Lists;
+import com.google.common.util.concurrent.AbstractFuture;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.concurrent.Future;
+
+/**
+ * {@link ContextWrapper} that can attach listeners for upcoming
+ * {@link Context#sendBroadcast(Intent)}.
+ */
+public class BroadcastInterceptingContext extends ContextWrapper {
+    private static final String TAG = "WatchingContext";
+
+    private final List<BroadcastInterceptor> mInterceptors = Lists.newArrayList();
+
+    public class BroadcastInterceptor extends AbstractFuture<Intent> {
+        private final BroadcastReceiver mReceiver;
+        private final IntentFilter mFilter;
+
+        public BroadcastInterceptor(BroadcastReceiver receiver, IntentFilter filter) {
+            mReceiver = receiver;
+            mFilter = filter;
+        }
+
+        public boolean dispatchBroadcast(Intent intent) {
+            if (mFilter.match(getContentResolver(), intent, false, TAG) > 0) {
+                if (mReceiver != null) {
+                    final Context context = BroadcastInterceptingContext.this;
+                    mReceiver.onReceive(context, intent);
+                    return false;
+                } else {
+                    set(intent);
+                    return true;
+                }
+            } else {
+                return false;
+            }
+        }
+    }
+
+    public BroadcastInterceptingContext(Context base) {
+        super(base);
+    }
+
+    public Future<Intent> nextBroadcastIntent(String action) {
+        return nextBroadcastIntent(new IntentFilter(action));
+    }
+
+    public Future<Intent> nextBroadcastIntent(IntentFilter filter) {
+        final BroadcastInterceptor interceptor = new BroadcastInterceptor(null, filter);
+        synchronized (mInterceptors) {
+            mInterceptors.add(interceptor);
+        }
+        return interceptor;
+    }
+
+    @Override
+    public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter) {
+        synchronized (mInterceptors) {
+            mInterceptors.add(new BroadcastInterceptor(receiver, filter));
+        }
+        return null;
+    }
+
+    @Override
+    public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter,
+            String broadcastPermission, Handler scheduler) {
+        return registerReceiver(receiver, filter);
+    }
+
+    @Override
+    public void unregisterReceiver(BroadcastReceiver receiver) {
+        synchronized (mInterceptors) {
+            final Iterator<BroadcastInterceptor> i = mInterceptors.iterator();
+            while (i.hasNext()) {
+                final BroadcastInterceptor interceptor = i.next();
+                if (receiver.equals(interceptor.mReceiver)) {
+                    i.remove();
+                }
+            }
+        }
+    }
+
+    @Override
+    public void sendBroadcast(Intent intent) {
+        synchronized (mInterceptors) {
+            final Iterator<BroadcastInterceptor> i = mInterceptors.iterator();
+            while (i.hasNext()) {
+                final BroadcastInterceptor interceptor = i.next();
+                if (interceptor.dispatchBroadcast(intent)) {
+                    i.remove();
+                }
+            }
+        }
+    }
+
+    @Override
+    public void sendStickyBroadcast(Intent intent) {
+        sendBroadcast(intent);
+    }
+
+    @Override
+    public void removeStickyBroadcast(Intent intent) {
+        // ignored
+    }
+}
diff --git a/services/tests/servicestests/src/com/android/server/NetworkPolicyManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/NetworkPolicyManagerServiceTest.java
new file mode 100644
index 0000000..07e5425
--- /dev/null
+++ b/services/tests/servicestests/src/com/android/server/NetworkPolicyManagerServiceTest.java
@@ -0,0 +1,459 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server;
+
+import static android.content.Intent.ACTION_UID_REMOVED;
+import static android.content.Intent.EXTRA_UID;
+import static android.net.ConnectivityManager.CONNECTIVITY_ACTION;
+import static android.net.ConnectivityManager.TYPE_WIFI;
+import static android.net.NetworkPolicyManager.POLICY_NONE;
+import static android.net.NetworkPolicyManager.POLICY_REJECT_METERED_BACKGROUND;
+import static android.net.NetworkPolicyManager.RULE_ALLOW_ALL;
+import static android.net.NetworkPolicyManager.RULE_REJECT_METERED;
+import static android.net.NetworkPolicyManager.computeLastCycleBoundary;
+import static android.net.NetworkStats.TAG_NONE;
+import static android.net.NetworkStats.UID_ALL;
+import static android.net.NetworkTemplate.MATCH_WIFI;
+import static org.easymock.EasyMock.anyInt;
+import static org.easymock.EasyMock.aryEq;
+import static org.easymock.EasyMock.capture;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.isA;
+
+import android.app.IActivityManager;
+import android.app.INotificationManager;
+import android.app.IProcessObserver;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.net.ConnectivityManager;
+import android.net.IConnectivityManager;
+import android.net.INetworkPolicyListener;
+import android.net.INetworkStatsService;
+import android.net.LinkProperties;
+import android.net.NetworkInfo;
+import android.net.NetworkInfo.DetailedState;
+import android.net.NetworkPolicy;
+import android.net.NetworkState;
+import android.net.NetworkStats;
+import android.net.NetworkTemplate;
+import android.os.Binder;
+import android.os.IPowerManager;
+import android.test.AndroidTestCase;
+import android.test.mock.MockPackageManager;
+import android.test.suitebuilder.annotation.LargeTest;
+import android.test.suitebuilder.annotation.Suppress;
+import android.text.format.Time;
+import android.util.TrustedTime;
+
+import com.android.server.net.NetworkPolicyManagerService;
+
+import org.easymock.Capture;
+import org.easymock.EasyMock;
+
+import java.io.File;
+import java.util.concurrent.Future;
+
+/**
+ * Tests for {@link NetworkPolicyManagerService}.
+ */
+@LargeTest
+public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
+    private static final String TAG = "NetworkPolicyManagerServiceTest";
+
+    private static final long TEST_START = 1194220800000L;
+    private static final String TEST_IFACE = "test0";
+
+    private static NetworkTemplate sTemplateWifi = new NetworkTemplate(MATCH_WIFI, null);
+
+    private BroadcastInterceptingContext mServiceContext;
+    private File mPolicyDir;
+
+    private IActivityManager mActivityManager;
+    private IPowerManager mPowerManager;
+    private INetworkStatsService mStatsService;
+    private INetworkPolicyListener mPolicyListener;
+    private TrustedTime mTime;
+    private IConnectivityManager mConnManager;
+    private INotificationManager mNotifManager;
+
+    private NetworkPolicyManagerService mService;
+    private IProcessObserver mProcessObserver;
+
+    private Binder mStubBinder = new Binder();
+
+    private static final int UID_A = android.os.Process.FIRST_APPLICATION_UID + 800;
+    private static final int UID_B = android.os.Process.FIRST_APPLICATION_UID + 801;
+
+    private static final int PID_1 = 400;
+    private static final int PID_2 = 401;
+    private static final int PID_3 = 402;
+
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+
+        // intercept various broadcasts, and pretend that uids have packages
+        mServiceContext = new BroadcastInterceptingContext(getContext()) {
+            @Override
+            public PackageManager getPackageManager() {
+                return new MockPackageManager() {
+                    @Override
+                    public String[] getPackagesForUid(int uid) {
+                        return new String[] { "com.example" };
+                    }
+                };
+            }
+        };
+
+        mPolicyDir = getContext().getFilesDir();
+
+        mActivityManager = createMock(IActivityManager.class);
+        mPowerManager = createMock(IPowerManager.class);
+        mStatsService = createMock(INetworkStatsService.class);
+        mPolicyListener = createMock(INetworkPolicyListener.class);
+        mTime = createMock(TrustedTime.class);
+        mConnManager = createMock(IConnectivityManager.class);
+        mNotifManager = createMock(INotificationManager.class);
+
+        mService = new NetworkPolicyManagerService(
+                mServiceContext, mActivityManager, mPowerManager, mStatsService, mTime, mPolicyDir);
+        mService.bindConnectivityManager(mConnManager);
+        mService.bindNotificationManager(mNotifManager);
+
+        // RemoteCallbackList needs a binder to use as key
+        expect(mPolicyListener.asBinder()).andReturn(mStubBinder).atLeastOnce();
+        replay();
+        mService.registerListener(mPolicyListener);
+        verifyAndReset();
+
+        // catch the registered IProcessObserver during systemReady()
+        final Capture<IProcessObserver> processObserver = new Capture<IProcessObserver>();
+        mActivityManager.registerProcessObserver(capture(processObserver));
+        expectLastCall().atLeastOnce();
+
+        // expect to answer screen status during systemReady()
+        expect(mPowerManager.isScreenOn()).andReturn(true).atLeastOnce();
+        expectTime(System.currentTimeMillis());
+
+        replay();
+        mService.systemReady();
+        verifyAndReset();
+
+        mProcessObserver = processObserver.getValue();
+
+    }
+
+    @Override
+    public void tearDown() throws Exception {
+        for (File file : mPolicyDir.listFiles()) {
+            file.delete();
+        }
+
+        mServiceContext = null;
+        mPolicyDir = null;
+
+        mActivityManager = null;
+        mPowerManager = null;
+        mStatsService = null;
+        mPolicyListener = null;
+        mTime = null;
+
+        mService = null;
+        mProcessObserver = null;
+
+        super.tearDown();
+    }
+
+    @Suppress
+    public void testPolicyChangeTriggersBroadcast() throws Exception {
+        mService.setUidPolicy(UID_A, POLICY_NONE);
+
+        // change background policy and expect broadcast
+        final Future<Intent> backgroundChanged = mServiceContext.nextBroadcastIntent(
+                ConnectivityManager.ACTION_BACKGROUND_DATA_SETTING_CHANGED);
+
+        mService.setUidPolicy(UID_A, POLICY_REJECT_METERED_BACKGROUND);
+
+        backgroundChanged.get();
+    }
+
+    public void testPidForegroundCombined() throws Exception {
+        // push all uid into background
+        mProcessObserver.onForegroundActivitiesChanged(PID_1, UID_A, false);
+        mProcessObserver.onForegroundActivitiesChanged(PID_2, UID_A, false);
+        mProcessObserver.onForegroundActivitiesChanged(PID_3, UID_B, false);
+        assertFalse(mService.isUidForeground(UID_A));
+        assertFalse(mService.isUidForeground(UID_B));
+
+        // push one of the shared pids into foreground
+        mProcessObserver.onForegroundActivitiesChanged(PID_2, UID_A, true);
+        assertTrue(mService.isUidForeground(UID_A));
+        assertFalse(mService.isUidForeground(UID_B));
+
+        // and swap another uid into foreground
+        mProcessObserver.onForegroundActivitiesChanged(PID_2, UID_A, false);
+        mProcessObserver.onForegroundActivitiesChanged(PID_3, UID_B, true);
+        assertFalse(mService.isUidForeground(UID_A));
+        assertTrue(mService.isUidForeground(UID_B));
+
+        // push both pid into foreground
+        mProcessObserver.onForegroundActivitiesChanged(PID_1, UID_A, true);
+        mProcessObserver.onForegroundActivitiesChanged(PID_2, UID_A, true);
+        assertTrue(mService.isUidForeground(UID_A));
+
+        // pull one out, should still be foreground
+        mProcessObserver.onForegroundActivitiesChanged(PID_1, UID_A, false);
+        assertTrue(mService.isUidForeground(UID_A));
+
+        // pull final pid out, should now be background
+        mProcessObserver.onForegroundActivitiesChanged(PID_2, UID_A, false);
+        assertFalse(mService.isUidForeground(UID_A));
+    }
+
+    public void testScreenChangesRules() throws Exception {
+        // push strict policy for foreground uid, verify ALLOW rule
+        expectRulesChanged(UID_A, RULE_ALLOW_ALL);
+        replay();
+        mProcessObserver.onForegroundActivitiesChanged(PID_1, UID_A, true);
+        mService.setUidPolicy(UID_A, POLICY_REJECT_METERED_BACKGROUND);
+        verifyAndReset();
+
+        // now turn screen off and verify REJECT rule
+        expect(mPowerManager.isScreenOn()).andReturn(false).atLeastOnce();
+        expectRulesChanged(UID_A, RULE_REJECT_METERED);
+        replay();
+        mServiceContext.sendBroadcast(new Intent(Intent.ACTION_SCREEN_OFF));
+        verifyAndReset();
+
+        // and turn screen back on, verify ALLOW rule restored
+        expect(mPowerManager.isScreenOn()).andReturn(true).atLeastOnce();
+        expectRulesChanged(UID_A, RULE_ALLOW_ALL);
+        replay();
+        mServiceContext.sendBroadcast(new Intent(Intent.ACTION_SCREEN_ON));
+        verifyAndReset();
+    }
+
+    public void testPolicyNone() throws Exception {
+        // POLICY_NONE should RULE_ALLOW in foreground
+        expectRulesChanged(UID_A, RULE_ALLOW_ALL);
+        replay();
+        mService.setUidPolicy(UID_A, POLICY_NONE);
+        mProcessObserver.onForegroundActivitiesChanged(PID_1, UID_A, true);
+        verifyAndReset();
+
+        // POLICY_NONE should RULE_ALLOW in background
+        expectRulesChanged(UID_A, RULE_ALLOW_ALL);
+        replay();
+        mProcessObserver.onForegroundActivitiesChanged(PID_1, UID_A, false);
+        verifyAndReset();
+    }
+
+    public void testPolicyReject() throws Exception {
+        // POLICY_REJECT should RULE_ALLOW in background
+        expectRulesChanged(UID_A, RULE_REJECT_METERED);
+        replay();
+        mService.setUidPolicy(UID_A, POLICY_REJECT_METERED_BACKGROUND);
+        verifyAndReset();
+
+        // POLICY_REJECT should RULE_ALLOW in foreground
+        expectRulesChanged(UID_A, RULE_ALLOW_ALL);
+        replay();
+        mProcessObserver.onForegroundActivitiesChanged(PID_1, UID_A, true);
+        verifyAndReset();
+
+        // POLICY_REJECT should RULE_REJECT in background
+        expectRulesChanged(UID_A, RULE_REJECT_METERED);
+        replay();
+        mProcessObserver.onForegroundActivitiesChanged(PID_1, UID_A, false);
+        verifyAndReset();
+    }
+
+    public void testPolicyRejectAddRemove() throws Exception {
+        // POLICY_NONE should have RULE_ALLOW in background
+        expectRulesChanged(UID_A, RULE_ALLOW_ALL);
+        replay();
+        mService.setUidPolicy(UID_A, POLICY_NONE);
+        mProcessObserver.onForegroundActivitiesChanged(PID_1, UID_A, false);
+        verifyAndReset();
+
+        // adding POLICY_REJECT should cause RULE_REJECT
+        expectRulesChanged(UID_A, RULE_REJECT_METERED);
+        replay();
+        mService.setUidPolicy(UID_A, POLICY_REJECT_METERED_BACKGROUND);
+        verifyAndReset();
+
+        // removing POLICY_REJECT should return us to RULE_ALLOW
+        expectRulesChanged(UID_A, RULE_ALLOW_ALL);
+        replay();
+        mService.setUidPolicy(UID_A, POLICY_NONE);
+        verifyAndReset();
+    }
+
+    public void testLastCycleBoundaryThisMonth() throws Exception {
+        // assume cycle day of "5th", which should be in same month
+        final long currentTime = parseTime("2007-11-14T00:00:00.000Z");
+        final long expectedCycle = parseTime("2007-11-05T00:00:00.000Z");
+
+        final NetworkPolicy policy = new NetworkPolicy(sTemplateWifi, 5, 1024L, 1024L);
+        final long actualCycle = computeLastCycleBoundary(currentTime, policy);
+        assertEquals(expectedCycle, actualCycle);
+    }
+
+    public void testLastCycleBoundaryLastMonth() throws Exception {
+        // assume cycle day of "20th", which should be in last month
+        final long currentTime = parseTime("2007-11-14T00:00:00.000Z");
+        final long expectedCycle = parseTime("2007-10-20T00:00:00.000Z");
+
+        final NetworkPolicy policy = new NetworkPolicy(sTemplateWifi, 20, 1024L, 1024L);
+        final long actualCycle = computeLastCycleBoundary(currentTime, policy);
+        assertEquals(expectedCycle, actualCycle);
+    }
+
+    public void testLastCycleBoundaryThisMonthFebruary() throws Exception {
+        // assume cycle day of "30th" in february; should go to january
+        final long currentTime = parseTime("2007-02-14T00:00:00.000Z");
+        final long expectedCycle = parseTime("2007-01-30T00:00:00.000Z");
+
+        final NetworkPolicy policy = new NetworkPolicy(sTemplateWifi, 30, 1024L, 1024L);
+        final long actualCycle = computeLastCycleBoundary(currentTime, policy);
+        assertEquals(expectedCycle, actualCycle);
+    }
+
+    public void testLastCycleBoundaryLastMonthFebruary() throws Exception {
+        // assume cycle day of "30th" in february, which should clamp
+        final long currentTime = parseTime("2007-03-14T00:00:00.000Z");
+        final long expectedCycle = parseTime("2007-03-01T00:00:00.000Z");
+
+        final NetworkPolicy policy = new NetworkPolicy(sTemplateWifi, 30, 1024L, 1024L);
+        final long actualCycle = computeLastCycleBoundary(currentTime, policy);
+        assertEquals(expectedCycle, actualCycle);
+    }
+
+    public void testNetworkPolicyAppliedCycleLastMonth() throws Exception {
+        long elapsedRealtime = 0;
+        NetworkState[] state = null;
+        NetworkStats stats = null;
+
+        final long TIME_FEB_15 = 1171497600000L;
+        final long TIME_MAR_10 = 1173484800000L;
+        final int CYCLE_DAY = 15;
+
+        // first, pretend that wifi network comes online. no policy active,
+        // which means we shouldn't push limit to interface.
+        state = new NetworkState[] { buildWifi() };
+        expect(mConnManager.getAllNetworkState()).andReturn(state).atLeastOnce();
+        expectTime(TIME_MAR_10 + elapsedRealtime);
+        expectMeteredIfacesChanged();
+
+        replay();
+        mServiceContext.sendBroadcast(new Intent(CONNECTIVITY_ACTION));
+        verifyAndReset();
+
+        // now change cycle to be on 15th, and test in early march, to verify we
+        // pick cycle day in previous month.
+        expect(mConnManager.getAllNetworkState()).andReturn(state).atLeastOnce();
+        expectTime(TIME_MAR_10 + elapsedRealtime);
+
+        // pretend that 512 bytes total have happened
+        stats = new NetworkStats(elapsedRealtime, 1)
+                .addEntry(TEST_IFACE, UID_ALL, TAG_NONE, 256L, 256L);
+        expect(mStatsService.getSummaryForNetwork(sTemplateWifi, TIME_FEB_15, TIME_MAR_10))
+                .andReturn(stats).atLeastOnce();
+
+        // expect that quota remaining should be 1536 bytes
+        // TODO: write up NetworkManagementService mock
+
+        expectClearNotifications();
+        expectMeteredIfacesChanged(TEST_IFACE);
+
+        replay();
+        setNetworkPolicies(new NetworkPolicy(sTemplateWifi, CYCLE_DAY, 1024L, 2048L));
+        verifyAndReset();
+    }
+
+    public void testUidRemovedPolicyCleared() throws Exception {
+        // POLICY_REJECT should RULE_REJECT in background
+        expectRulesChanged(UID_A, RULE_REJECT_METERED);
+        replay();
+        mService.setUidPolicy(UID_A, POLICY_REJECT_METERED_BACKGROUND);
+        verifyAndReset();
+
+        // uninstall should clear RULE_REJECT
+        expectRulesChanged(UID_A, RULE_ALLOW_ALL);
+        replay();
+        final Intent intent = new Intent(ACTION_UID_REMOVED);
+        intent.putExtra(EXTRA_UID, UID_A);
+        mServiceContext.sendBroadcast(intent);
+        verifyAndReset();
+    }
+
+    private static long parseTime(String time) {
+        final Time result = new Time();
+        result.parse3339(time);
+        return result.toMillis(true);
+    }
+
+    private void setNetworkPolicies(NetworkPolicy... policies) {
+        mService.setNetworkPolicies(policies);
+    }
+
+    private static NetworkState buildWifi() {
+        final NetworkInfo info = new NetworkInfo(TYPE_WIFI, 0, null, null);
+        info.setDetailedState(DetailedState.CONNECTED, null, null);
+        final LinkProperties prop = new LinkProperties();
+        prop.setInterfaceName(TEST_IFACE);
+        return new NetworkState(info, prop, null);
+    }
+
+    private void expectTime(long currentTime) throws Exception {
+        expect(mTime.forceRefresh()).andReturn(false).anyTimes();
+        expect(mTime.hasCache()).andReturn(true).anyTimes();
+        expect(mTime.currentTimeMillis()).andReturn(currentTime).anyTimes();
+        expect(mTime.getCacheAge()).andReturn(0L).anyTimes();
+        expect(mTime.getCacheCertainty()).andReturn(0L).anyTimes();
+    }
+
+    private void expectClearNotifications() throws Exception {
+        mNotifManager.cancelNotificationWithTag(isA(String.class), isA(String.class), anyInt());
+        expectLastCall().anyTimes();
+    }
+
+    private void expectRulesChanged(int uid, int policy) throws Exception {
+        mPolicyListener.onUidRulesChanged(eq(uid), eq(policy));
+        expectLastCall().atLeastOnce();
+    }
+
+    private void expectMeteredIfacesChanged(String... ifaces) throws Exception {
+        mPolicyListener.onMeteredIfacesChanged(aryEq(ifaces));
+        expectLastCall().atLeastOnce();
+    }
+
+    private void replay() {
+        EasyMock.replay(mActivityManager, mPowerManager, mStatsService, mPolicyListener, mTime,
+                mConnManager, mNotifManager);
+    }
+
+    private void verifyAndReset() {
+        EasyMock.verify(mActivityManager, mPowerManager, mStatsService, mPolicyListener, mTime,
+                mConnManager, mNotifManager);
+        EasyMock.reset(mActivityManager, mPowerManager, mStatsService, mPolicyListener, mTime,
+                mConnManager, mNotifManager);
+    }
+}
diff --git a/services/tests/servicestests/src/com/android/server/NetworkStatsServiceTest.java b/services/tests/servicestests/src/com/android/server/NetworkStatsServiceTest.java
new file mode 100644
index 0000000..636d059
--- /dev/null
+++ b/services/tests/servicestests/src/com/android/server/NetworkStatsServiceTest.java
@@ -0,0 +1,710 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server;
+
+import static android.content.Intent.ACTION_UID_REMOVED;
+import static android.content.Intent.EXTRA_UID;
+import static android.net.ConnectivityManager.CONNECTIVITY_ACTION;
+import static android.net.ConnectivityManager.TYPE_MOBILE;
+import static android.net.ConnectivityManager.TYPE_WIFI;
+import static android.net.ConnectivityManager.TYPE_WIMAX;
+import static android.net.NetworkStats.IFACE_ALL;
+import static android.net.NetworkStats.TAG_NONE;
+import static android.net.NetworkStats.UID_ALL;
+import static android.net.NetworkTemplate.MATCH_MOBILE_ALL;
+import static android.net.NetworkTemplate.MATCH_WIFI;
+import static android.net.TrafficStats.UID_REMOVED;
+import static android.text.format.DateUtils.DAY_IN_MILLIS;
+import static android.text.format.DateUtils.HOUR_IN_MILLIS;
+import static android.text.format.DateUtils.MINUTE_IN_MILLIS;
+import static android.text.format.DateUtils.WEEK_IN_MILLIS;
+import static com.android.server.net.NetworkStatsService.ACTION_NETWORK_STATS_POLL;
+import static com.android.server.net.NetworkStatsService.packUidAndTag;
+import static com.android.server.net.NetworkStatsService.unpackTag;
+import static com.android.server.net.NetworkStatsService.unpackUid;
+import static org.easymock.EasyMock.anyLong;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.isA;
+
+import android.app.AlarmManager;
+import android.app.IAlarmManager;
+import android.app.PendingIntent;
+import android.content.Intent;
+import android.net.IConnectivityManager;
+import android.net.LinkProperties;
+import android.net.NetworkInfo;
+import android.net.NetworkInfo.DetailedState;
+import android.net.NetworkState;
+import android.net.NetworkStats;
+import android.net.NetworkStatsHistory;
+import android.net.NetworkTemplate;
+import android.os.INetworkManagementService;
+import android.telephony.TelephonyManager;
+import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.LargeTest;
+import android.util.Log;
+import android.util.TrustedTime;
+
+import com.android.server.net.NetworkStatsService;
+import com.android.server.net.NetworkStatsService.NetworkStatsSettings;
+
+import org.easymock.EasyMock;
+
+import java.io.File;
+
+/**
+ * Tests for {@link NetworkStatsService}.
+ */
+@LargeTest
+public class NetworkStatsServiceTest extends AndroidTestCase {
+    private static final String TAG = "NetworkStatsServiceTest";
+
+    private static final String TEST_IFACE = "test0";
+    private static final long TEST_START = 1194220800000L;
+
+    private static final String IMSI_1 = "310004";
+    private static final String IMSI_2 = "310260";
+
+    private static NetworkTemplate sTemplateWifi = new NetworkTemplate(MATCH_WIFI, null);
+    private static NetworkTemplate sTemplateImsi1 = new NetworkTemplate(MATCH_MOBILE_ALL, IMSI_1);
+    private static NetworkTemplate sTemplateImsi2 = new NetworkTemplate(MATCH_MOBILE_ALL, IMSI_2);
+
+    private static final int UID_RED = 1001;
+    private static final int UID_BLUE = 1002;
+    private static final int UID_GREEN = 1003;
+
+    private BroadcastInterceptingContext mServiceContext;
+    private File mStatsDir;
+
+    private INetworkManagementService mNetManager;
+    private IAlarmManager mAlarmManager;
+    private TrustedTime mTime;
+    private NetworkStatsSettings mSettings;
+    private IConnectivityManager mConnManager;
+
+    private NetworkStatsService mService;
+
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+
+        mServiceContext = new BroadcastInterceptingContext(getContext());
+        mStatsDir = getContext().getFilesDir();
+
+        mNetManager = createMock(INetworkManagementService.class);
+        mAlarmManager = createMock(IAlarmManager.class);
+        mTime = createMock(TrustedTime.class);
+        mSettings = createMock(NetworkStatsSettings.class);
+        mConnManager = createMock(IConnectivityManager.class);
+
+        mService = new NetworkStatsService(
+                mServiceContext, mNetManager, mAlarmManager, mTime, mStatsDir, mSettings);
+        mService.bindConnectivityManager(mConnManager);
+
+        expectDefaultSettings();
+        expectSystemReady();
+
+        replay();
+        mService.systemReady();
+        verifyAndReset();
+
+    }
+
+    @Override
+    public void tearDown() throws Exception {
+        for (File file : mStatsDir.listFiles()) {
+            file.delete();
+        }
+
+        mServiceContext = null;
+        mStatsDir = null;
+
+        mNetManager = null;
+        mAlarmManager = null;
+        mTime = null;
+        mSettings = null;
+        mConnManager = null;
+
+        mService = null;
+
+        super.tearDown();
+    }
+
+    public void testNetworkStatsWifi() throws Exception {
+        long elapsedRealtime = 0;
+
+        // pretend that wifi network comes online; service should ask about full
+        // network state, and poll any existing interfaces before updating.
+        expectTime(TEST_START + elapsedRealtime);
+        expectDefaultSettings();
+        expectNetworkState(buildWifiState());
+        expectNetworkStatsSummary(buildEmptyStats(elapsedRealtime));
+
+        replay();
+        mServiceContext.sendBroadcast(new Intent(CONNECTIVITY_ACTION));
+
+        // verify service has empty history for wifi
+        assertNetworkTotal(sTemplateWifi, 0L, 0L);
+        verifyAndReset();
+
+        // modify some number on wifi, and trigger poll event
+        elapsedRealtime += HOUR_IN_MILLIS;
+        expectTime(TEST_START + elapsedRealtime);
+        expectDefaultSettings();
+        expectNetworkStatsSummary(new NetworkStats(elapsedRealtime, 1)
+                .addEntry(TEST_IFACE, UID_ALL, TAG_NONE, 1024L, 2048L));
+        expectNetworkStatsDetail(buildEmptyStats(elapsedRealtime));
+
+        replay();
+        mServiceContext.sendBroadcast(new Intent(ACTION_NETWORK_STATS_POLL));
+
+        // verify service recorded history
+        assertNetworkTotal(sTemplateWifi, 1024L, 2048L);
+        verifyAndReset();
+
+        // and bump forward again, with counters going higher. this is
+        // important, since polling should correctly subtract last snapshot.
+        elapsedRealtime += DAY_IN_MILLIS;
+        expectTime(TEST_START + elapsedRealtime);
+        expectDefaultSettings();
+        expectNetworkStatsSummary(new NetworkStats(elapsedRealtime, 1)
+                .addEntry(TEST_IFACE, UID_ALL, TAG_NONE, 4096L, 8192L));
+        expectNetworkStatsDetail(buildEmptyStats(elapsedRealtime));
+
+        replay();
+        mServiceContext.sendBroadcast(new Intent(ACTION_NETWORK_STATS_POLL));
+
+        // verify service recorded history
+        assertNetworkTotal(sTemplateWifi, 4096L, 8192L);
+        verifyAndReset();
+
+    }
+
+    public void testStatsRebootPersist() throws Exception {
+        long elapsedRealtime = 0;
+        assertStatsFilesExist(false);
+
+        // pretend that wifi network comes online; service should ask about full
+        // network state, and poll any existing interfaces before updating.
+        expectTime(TEST_START + elapsedRealtime);
+        expectDefaultSettings();
+        expectNetworkState(buildWifiState());
+        expectNetworkStatsSummary(buildEmptyStats(elapsedRealtime));
+
+        replay();
+        mServiceContext.sendBroadcast(new Intent(CONNECTIVITY_ACTION));
+
+        // verify service has empty history for wifi
+        assertNetworkTotal(sTemplateWifi, 0L, 0L);
+        verifyAndReset();
+
+        // modify some number on wifi, and trigger poll event
+        elapsedRealtime += HOUR_IN_MILLIS;
+        expectTime(TEST_START + elapsedRealtime);
+        expectDefaultSettings();
+        expectNetworkStatsSummary(new NetworkStats(elapsedRealtime, 1)
+                .addEntry(TEST_IFACE, UID_ALL, TAG_NONE, 1024L, 2048L));
+        expectNetworkStatsDetail(new NetworkStats(elapsedRealtime, 2)
+                .addEntry(TEST_IFACE, UID_RED, TAG_NONE, 512L, 256L)
+                .addEntry(TEST_IFACE, UID_BLUE, TAG_NONE, 128L, 128L));
+
+        replay();
+        mServiceContext.sendBroadcast(new Intent(ACTION_NETWORK_STATS_POLL));
+
+        // verify service recorded history
+        assertNetworkTotal(sTemplateWifi, 1024L, 2048L);
+        assertUidTotal(sTemplateWifi, UID_RED, 512L, 256L);
+        assertUidTotal(sTemplateWifi, UID_BLUE, 128L, 128L);
+        verifyAndReset();
+
+        // graceful shutdown system, which should trigger persist of stats, and
+        // clear any values in memory.
+        mServiceContext.sendBroadcast(new Intent(Intent.ACTION_SHUTDOWN));
+
+        // talk with zombie service to assert stats have gone; and assert that
+        // we persisted them to file.
+        expectDefaultSettings();
+        replay();
+        assertNetworkTotal(sTemplateWifi, 0L, 0L);
+        verifyAndReset();
+
+        assertStatsFilesExist(true);
+
+        // boot through serviceReady() again
+        expectDefaultSettings();
+        expectSystemReady();
+
+        replay();
+        mService.systemReady();
+
+        // after systemReady(), we should have historical stats loaded again
+        assertNetworkTotal(sTemplateWifi, 1024L, 2048L);
+        assertUidTotal(sTemplateWifi, UID_RED, 512L, 256L);
+        assertUidTotal(sTemplateWifi, UID_BLUE, 128L, 128L);
+        verifyAndReset();
+
+    }
+
+    public void testStatsBucketResize() throws Exception {
+        long elapsedRealtime = 0;
+        NetworkStatsHistory history = null;
+        long[] total = null;
+
+        assertStatsFilesExist(false);
+
+        // pretend that wifi network comes online; service should ask about full
+        // network state, and poll any existing interfaces before updating.
+        expectTime(TEST_START + elapsedRealtime);
+        expectSettings(0L, HOUR_IN_MILLIS, WEEK_IN_MILLIS);
+        expectNetworkState(buildWifiState());
+        expectNetworkStatsSummary(buildEmptyStats(elapsedRealtime));
+
+        replay();
+        mServiceContext.sendBroadcast(new Intent(CONNECTIVITY_ACTION));
+        verifyAndReset();
+
+        // modify some number on wifi, and trigger poll event
+        elapsedRealtime += 2 * HOUR_IN_MILLIS;
+        expectTime(TEST_START + elapsedRealtime);
+        expectSettings(0L, HOUR_IN_MILLIS, WEEK_IN_MILLIS);
+        expectNetworkStatsSummary(new NetworkStats(elapsedRealtime, 1)
+                .addEntry(TEST_IFACE, UID_ALL, TAG_NONE, 512L, 512L));
+        expectNetworkStatsDetail(buildEmptyStats(elapsedRealtime));
+
+        replay();
+        mServiceContext.sendBroadcast(new Intent(ACTION_NETWORK_STATS_POLL));
+
+        // verify service recorded history
+        history = mService.getHistoryForNetwork(new NetworkTemplate(MATCH_WIFI, null));
+        total = history.getTotalData(Long.MIN_VALUE, Long.MAX_VALUE, null);
+        assertEquals(512L, total[0]);
+        assertEquals(512L, total[1]);
+        assertEquals(HOUR_IN_MILLIS, history.bucketDuration);
+        assertEquals(2, history.bucketCount);
+        verifyAndReset();
+
+        // now change bucket duration setting and trigger another poll with
+        // exact same values, which should resize existing buckets.
+        expectTime(TEST_START + elapsedRealtime);
+        expectSettings(0L, 30 * MINUTE_IN_MILLIS, WEEK_IN_MILLIS);
+        expectNetworkStatsSummary(buildEmptyStats(elapsedRealtime));
+        expectNetworkStatsDetail(buildEmptyStats(elapsedRealtime));
+
+        replay();
+        mServiceContext.sendBroadcast(new Intent(ACTION_NETWORK_STATS_POLL));
+
+        // verify identical stats, but spread across 4 buckets now
+        history = mService.getHistoryForNetwork(new NetworkTemplate(MATCH_WIFI, null));
+        total = history.getTotalData(Long.MIN_VALUE, Long.MAX_VALUE, null);
+        assertEquals(512L, total[0]);
+        assertEquals(512L, total[1]);
+        assertEquals(30 * MINUTE_IN_MILLIS, history.bucketDuration);
+        assertEquals(4, history.bucketCount);
+        verifyAndReset();
+
+    }
+
+    public void testUidStatsAcrossNetworks() throws Exception {
+        long elapsedRealtime = 0;
+
+        // pretend first mobile network comes online
+        expectTime(TEST_START + elapsedRealtime);
+        expectDefaultSettings();
+        expectNetworkState(buildMobile3gState(IMSI_1));
+        expectNetworkStatsSummary(buildEmptyStats(elapsedRealtime));
+
+        replay();
+        mServiceContext.sendBroadcast(new Intent(CONNECTIVITY_ACTION));
+        verifyAndReset();
+
+        // create some traffic on first network
+        elapsedRealtime += HOUR_IN_MILLIS;
+        expectTime(TEST_START + elapsedRealtime);
+        expectDefaultSettings();
+        expectNetworkStatsSummary(new NetworkStats(elapsedRealtime, 1)
+                .addEntry(TEST_IFACE, UID_ALL, TAG_NONE, 2048L, 512L));
+        expectNetworkStatsDetail(new NetworkStats(elapsedRealtime, 3)
+                .addEntry(TEST_IFACE, UID_RED, TAG_NONE, 1536L, 512L)
+                .addEntry(TEST_IFACE, UID_RED, 0xF00D, 512L, 512L)
+                .addEntry(TEST_IFACE, UID_BLUE, TAG_NONE, 512L, 0L));
+
+        replay();
+        mServiceContext.sendBroadcast(new Intent(ACTION_NETWORK_STATS_POLL));
+
+        // verify service recorded history
+        assertNetworkTotal(sTemplateImsi1, 2048L, 512L);
+        assertNetworkTotal(sTemplateWifi, 0L, 0L);
+        assertUidTotal(sTemplateImsi1, UID_RED, 1536L, 512L);
+        assertUidTotal(sTemplateImsi1, UID_BLUE, 512L, 0L);
+        verifyAndReset();
+
+        // now switch networks; this also tests that we're okay with interfaces
+        // disappearing, to verify we don't count backwards.
+        elapsedRealtime += HOUR_IN_MILLIS;
+        expectTime(TEST_START + elapsedRealtime);
+        expectDefaultSettings();
+        expectNetworkState(buildMobile3gState(IMSI_2));
+        expectNetworkStatsSummary(buildEmptyStats(elapsedRealtime));
+        expectNetworkStatsDetail(buildEmptyStats(elapsedRealtime));
+
+        replay();
+        mServiceContext.sendBroadcast(new Intent(CONNECTIVITY_ACTION));
+        mServiceContext.sendBroadcast(new Intent(ACTION_NETWORK_STATS_POLL));
+        verifyAndReset();
+
+        // create traffic on second network
+        elapsedRealtime += HOUR_IN_MILLIS;
+        expectTime(TEST_START + elapsedRealtime);
+        expectDefaultSettings();
+        expectNetworkStatsSummary(new NetworkStats(elapsedRealtime, 1)
+                .addEntry(TEST_IFACE, UID_ALL, TAG_NONE, 128L, 1024L));
+        expectNetworkStatsDetail(new NetworkStats(elapsedRealtime, 1)
+                .addEntry(TEST_IFACE, UID_BLUE, TAG_NONE, 128L, 1024L));
+
+        replay();
+        mServiceContext.sendBroadcast(new Intent(ACTION_NETWORK_STATS_POLL));
+
+        // verify original history still intact
+        assertNetworkTotal(sTemplateImsi1, 2048L, 512L);
+        assertUidTotal(sTemplateImsi1, UID_RED, 1536L, 512L);
+        assertUidTotal(sTemplateImsi1, UID_BLUE, 512L, 0L);
+
+        // and verify new history also recorded under different template, which
+        // verifies that we didn't cross the streams.
+        assertNetworkTotal(sTemplateImsi2, 128L, 1024L);
+        assertNetworkTotal(sTemplateWifi, 0L, 0L);
+        assertUidTotal(sTemplateImsi2, UID_BLUE, 128L, 1024L);
+        verifyAndReset();
+
+    }
+
+    public void testUidRemovedIsMoved() throws Exception {
+        long elapsedRealtime = 0;
+
+        // pretend that network comes online
+        expectTime(TEST_START + elapsedRealtime);
+        expectDefaultSettings();
+        expectNetworkState(buildWifiState());
+        expectNetworkStatsSummary(buildEmptyStats(elapsedRealtime));
+
+        replay();
+        mServiceContext.sendBroadcast(new Intent(CONNECTIVITY_ACTION));
+        verifyAndReset();
+
+        // create some traffic
+        elapsedRealtime += HOUR_IN_MILLIS;
+        expectTime(TEST_START + elapsedRealtime);
+        expectDefaultSettings();
+        expectNetworkStatsSummary(new NetworkStats(elapsedRealtime, 1)
+                .addEntry(TEST_IFACE, UID_ALL, TAG_NONE, 4128L, 544L));
+        expectNetworkStatsDetail(new NetworkStats(elapsedRealtime, 1)
+                .addEntry(TEST_IFACE, UID_RED, TAG_NONE, 16L, 16L)
+                .addEntry(TEST_IFACE, UID_BLUE, TAG_NONE, 4096L, 512L)
+                .addEntry(TEST_IFACE, UID_GREEN, TAG_NONE, 16L, 16L));
+
+        replay();
+        mServiceContext.sendBroadcast(new Intent(ACTION_NETWORK_STATS_POLL));
+
+        // verify service recorded history
+        assertNetworkTotal(sTemplateWifi, 4128L, 544L);
+        assertUidTotal(sTemplateWifi, UID_RED, 16L, 16L);
+        assertUidTotal(sTemplateWifi, UID_BLUE, 4096L, 512L);
+        assertUidTotal(sTemplateWifi, UID_GREEN, 16L, 16L);
+        verifyAndReset();
+
+        // now pretend two UIDs are uninstalled, which should migrate stats to
+        // special "removed" bucket.
+        expectDefaultSettings();
+        replay();
+        final Intent intent = new Intent(ACTION_UID_REMOVED);
+        intent.putExtra(EXTRA_UID, UID_BLUE);
+        mServiceContext.sendBroadcast(intent);
+        intent.putExtra(EXTRA_UID, UID_RED);
+        mServiceContext.sendBroadcast(intent);
+
+        // existing uid and total should remain unchanged; but removed UID
+        // should be gone completely.
+        assertNetworkTotal(sTemplateWifi, 4128L, 544L);
+        assertUidTotal(sTemplateWifi, UID_RED, 0L, 0L);
+        assertUidTotal(sTemplateWifi, UID_BLUE, 0L, 0L);
+        assertUidTotal(sTemplateWifi, UID_GREEN, 16L, 16L);
+        assertUidTotal(sTemplateWifi, UID_REMOVED, 4112L, 528L);
+        verifyAndReset();
+
+    }
+
+    public void testUid3g4gCombinedByTemplate() throws Exception {
+        long elapsedRealtime = 0;
+
+        // pretend that network comes online
+        expectTime(TEST_START + elapsedRealtime);
+        expectDefaultSettings();
+        expectNetworkState(buildMobile3gState(IMSI_1));
+        expectNetworkStatsSummary(buildEmptyStats(elapsedRealtime));
+
+        replay();
+        mServiceContext.sendBroadcast(new Intent(CONNECTIVITY_ACTION));
+        verifyAndReset();
+
+        // create some traffic
+        elapsedRealtime += HOUR_IN_MILLIS;
+        expectTime(TEST_START + elapsedRealtime);
+        expectDefaultSettings();
+        expectNetworkStatsSummary(buildEmptyStats(elapsedRealtime));
+        expectNetworkStatsDetail(new NetworkStats(elapsedRealtime, 1)
+                .addEntry(TEST_IFACE, UID_RED, TAG_NONE, 1024L, 1024L)
+                .addEntry(TEST_IFACE, UID_RED, 0xF00D, 512L, 512L));
+
+        replay();
+        mServiceContext.sendBroadcast(new Intent(ACTION_NETWORK_STATS_POLL));
+
+        // verify service recorded history
+        assertUidTotal(sTemplateImsi1, UID_RED, 1024L, 1024L);
+        verifyAndReset();
+
+        // now switch over to 4g network
+        elapsedRealtime += HOUR_IN_MILLIS;
+        expectTime(TEST_START + elapsedRealtime);
+        expectDefaultSettings();
+        expectNetworkState(buildMobile4gState());
+        expectNetworkStatsSummary(buildEmptyStats(elapsedRealtime));
+        expectNetworkStatsDetail(buildEmptyStats(elapsedRealtime));
+
+        replay();
+        mServiceContext.sendBroadcast(new Intent(CONNECTIVITY_ACTION));
+        mServiceContext.sendBroadcast(new Intent(ACTION_NETWORK_STATS_POLL));
+        verifyAndReset();
+
+        // create traffic on second network
+        elapsedRealtime += HOUR_IN_MILLIS;
+        expectTime(TEST_START + elapsedRealtime);
+        expectDefaultSettings();
+        expectNetworkStatsSummary(buildEmptyStats(elapsedRealtime));
+        expectNetworkStatsDetail(new NetworkStats(elapsedRealtime, 1)
+                .addEntry(TEST_IFACE, UID_RED, TAG_NONE, 512L, 256L));
+
+        replay();
+        mServiceContext.sendBroadcast(new Intent(ACTION_NETWORK_STATS_POLL));
+
+        // verify that ALL_MOBILE template combines both
+        assertUidTotal(sTemplateImsi1, UID_RED, 1536L, 1280L);
+
+        verifyAndReset();
+
+    }
+    
+    public void testPackedUidAndTag() throws Exception {
+        assertEquals(0x0000000000000000L, packUidAndTag(0, 0x0));
+        assertEquals(0x000003E900000000L, packUidAndTag(1001, 0x0));
+        assertEquals(0x000003E90000F00DL, packUidAndTag(1001, 0xF00D));
+
+        long packed;
+        packed = packUidAndTag(Integer.MAX_VALUE, Integer.MIN_VALUE);
+        assertEquals(Integer.MAX_VALUE, unpackUid(packed));
+        assertEquals(Integer.MIN_VALUE, unpackTag(packed));
+
+        packed = packUidAndTag(Integer.MIN_VALUE, Integer.MAX_VALUE);
+        assertEquals(Integer.MIN_VALUE, unpackUid(packed));
+        assertEquals(Integer.MAX_VALUE, unpackTag(packed));
+
+        packed = packUidAndTag(10005, 0xFFFFFFFF);
+        assertEquals(10005, unpackUid(packed));
+        assertEquals(0xFFFFFFFF, unpackTag(packed));
+        
+    }
+
+    public void testSummaryForAllUid() throws Exception {
+        long elapsedRealtime = 0;
+
+        // pretend that network comes online
+        expectTime(TEST_START + elapsedRealtime);
+        expectDefaultSettings();
+        expectNetworkState(buildWifiState());
+        expectNetworkStatsSummary(buildEmptyStats(elapsedRealtime));
+
+        replay();
+        mServiceContext.sendBroadcast(new Intent(CONNECTIVITY_ACTION));
+        verifyAndReset();
+
+        // create some traffic for two apps
+        elapsedRealtime += HOUR_IN_MILLIS;
+        expectTime(TEST_START + elapsedRealtime);
+        expectDefaultSettings();
+        expectNetworkStatsSummary(buildEmptyStats(elapsedRealtime));
+        expectNetworkStatsDetail(new NetworkStats(elapsedRealtime, 1)
+                .addEntry(TEST_IFACE, UID_RED, TAG_NONE, 50L, 50L)
+                .addEntry(TEST_IFACE, UID_RED, 0xF00D, 10L, 10L)
+                .addEntry(TEST_IFACE, UID_BLUE, TAG_NONE, 1024L, 512L));
+
+        replay();
+        mServiceContext.sendBroadcast(new Intent(ACTION_NETWORK_STATS_POLL));
+
+        // verify service recorded history
+        assertUidTotal(sTemplateWifi, UID_RED, 50L, 50L);
+        assertUidTotal(sTemplateWifi, UID_BLUE, 1024L, 512L);
+        verifyAndReset();
+        
+        // now create more traffic in next hour, but only for one app
+        elapsedRealtime += HOUR_IN_MILLIS;
+        expectTime(TEST_START + elapsedRealtime);
+        expectDefaultSettings();
+        expectNetworkStatsSummary(buildEmptyStats(elapsedRealtime));
+        expectNetworkStatsDetail(new NetworkStats(elapsedRealtime, 1)
+                .addEntry(TEST_IFACE, UID_BLUE, TAG_NONE, 2048L, 1024L));
+
+        replay();
+        mServiceContext.sendBroadcast(new Intent(ACTION_NETWORK_STATS_POLL));
+
+        // first verify entire history present
+        NetworkStats stats = mService.getSummaryForAllUid(
+                sTemplateWifi, Long.MIN_VALUE, Long.MAX_VALUE, true);
+        assertEquals(3, stats.size);
+        assertStatsEntry(stats, 0, IFACE_ALL, UID_RED, TAG_NONE, 50L, 50L);
+        assertStatsEntry(stats, 1, IFACE_ALL, UID_RED, 0xF00D, 10L, 10L);
+        assertStatsEntry(stats, 2, IFACE_ALL, UID_BLUE, TAG_NONE, 2048L, 1024L);
+
+        // now verify that recent history only contains one uid
+        final long currentTime = TEST_START + elapsedRealtime;
+        stats = mService.getSummaryForAllUid(
+                sTemplateWifi, currentTime - HOUR_IN_MILLIS, currentTime, true);
+        assertEquals(1, stats.size);
+        assertStatsEntry(stats, 0, IFACE_ALL, UID_BLUE, TAG_NONE, 1024L, 512L);
+
+        verifyAndReset();
+    }
+
+    private void assertNetworkTotal(NetworkTemplate template, long rx, long tx) {
+        final NetworkStatsHistory history = mService.getHistoryForNetwork(template);
+        final long[] total = history.getTotalData(Long.MIN_VALUE, Long.MAX_VALUE, null);
+        assertEquals(rx, total[0]);
+        assertEquals(tx, total[1]);
+    }
+
+    private void assertUidTotal(NetworkTemplate template, int uid, long rx, long tx) {
+        final NetworkStatsHistory history = mService.getHistoryForUid(template, uid, TAG_NONE);
+        final long[] total = history.getTotalData(Long.MIN_VALUE, Long.MAX_VALUE, null);
+        assertEquals(rx, total[0]);
+        assertEquals(tx, total[1]);
+    }
+
+    private void expectSystemReady() throws Exception {
+        mAlarmManager.remove(isA(PendingIntent.class));
+        expectLastCall().anyTimes();
+
+        mAlarmManager.setInexactRepeating(
+                eq(AlarmManager.ELAPSED_REALTIME), anyLong(), anyLong(), isA(PendingIntent.class));
+        expectLastCall().atLeastOnce();
+    }
+
+    private void expectNetworkState(NetworkState... state) throws Exception {
+        expect(mConnManager.getAllNetworkState()).andReturn(state).atLeastOnce();
+    }
+
+    private void expectNetworkStatsSummary(NetworkStats summary) throws Exception {
+        expect(mNetManager.getNetworkStatsSummary()).andReturn(summary).atLeastOnce();
+    }
+
+    private void expectNetworkStatsDetail(NetworkStats detail) throws Exception {
+        expect(mNetManager.getNetworkStatsDetail()).andReturn(detail).atLeastOnce();
+    }
+
+    private void expectDefaultSettings() throws Exception {
+        expectSettings(0L, HOUR_IN_MILLIS, WEEK_IN_MILLIS);
+    }
+
+    private void expectSettings(long persistThreshold, long bucketDuration, long maxHistory)
+            throws Exception {
+        expect(mSettings.getPollInterval()).andReturn(HOUR_IN_MILLIS).anyTimes();
+        expect(mSettings.getPersistThreshold()).andReturn(persistThreshold).anyTimes();
+        expect(mSettings.getNetworkBucketDuration()).andReturn(bucketDuration).anyTimes();
+        expect(mSettings.getNetworkMaxHistory()).andReturn(maxHistory).anyTimes();
+        expect(mSettings.getUidBucketDuration()).andReturn(bucketDuration).anyTimes();
+        expect(mSettings.getUidMaxHistory()).andReturn(maxHistory).anyTimes();
+        expect(mSettings.getTagMaxHistory()).andReturn(maxHistory).anyTimes();
+        expect(mSettings.getTimeCacheMaxAge()).andReturn(DAY_IN_MILLIS).anyTimes();
+    }
+
+    private void expectTime(long currentTime) throws Exception {
+        expect(mTime.forceRefresh()).andReturn(false).anyTimes();
+        expect(mTime.hasCache()).andReturn(true).anyTimes();
+        expect(mTime.currentTimeMillis()).andReturn(currentTime).anyTimes();
+        expect(mTime.getCacheAge()).andReturn(0L).anyTimes();
+        expect(mTime.getCacheCertainty()).andReturn(0L).anyTimes();
+    }
+
+    private void assertStatsFilesExist(boolean exist) {
+        final File networkFile = new File(mStatsDir, "netstats.bin");
+        final File uidFile = new File(mStatsDir, "netstats_uid.bin");
+        if (exist) {
+            assertTrue(networkFile.exists());
+            assertTrue(uidFile.exists());
+        } else {
+            assertFalse(networkFile.exists());
+            assertFalse(uidFile.exists());
+        }
+    }
+
+    private static void assertStatsEntry(
+            NetworkStats stats, int i, String iface, int uid, int tag, long rx, long tx) {
+        assertEquals(iface, stats.iface[i]);
+        assertEquals(uid, stats.uid[i]);
+        assertEquals(tag, stats.tag[i]);
+        assertEquals(rx, stats.rx[i]);
+        assertEquals(tx, stats.tx[i]);
+    }
+
+    private static NetworkState buildWifiState() {
+        final NetworkInfo info = new NetworkInfo(TYPE_WIFI, 0, null, null);
+        info.setDetailedState(DetailedState.CONNECTED, null, null);
+        final LinkProperties prop = new LinkProperties();
+        prop.setInterfaceName(TEST_IFACE);
+        return new NetworkState(info, prop, null);
+    }
+
+    private static NetworkState buildMobile3gState(String subscriberId) {
+        final NetworkInfo info = new NetworkInfo(
+                TYPE_MOBILE, TelephonyManager.NETWORK_TYPE_UMTS, null, null);
+        info.setDetailedState(DetailedState.CONNECTED, null, null);
+        final LinkProperties prop = new LinkProperties();
+        prop.setInterfaceName(TEST_IFACE);
+        return new NetworkState(info, prop, null, subscriberId);
+    }
+
+    private static NetworkState buildMobile4gState() {
+        final NetworkInfo info = new NetworkInfo(TYPE_WIMAX, 0, null, null);
+        info.setDetailedState(DetailedState.CONNECTED, null, null);
+        final LinkProperties prop = new LinkProperties();
+        prop.setInterfaceName(TEST_IFACE);
+        return new NetworkState(info, prop, null);
+    }
+
+    private static NetworkStats buildEmptyStats(long elapsedRealtime) {
+        return new NetworkStats(elapsedRealtime, 0);
+    }
+
+    private void replay() {
+        EasyMock.replay(mNetManager, mAlarmManager, mTime, mSettings, mConnManager);
+    }
+
+    private void verifyAndReset() {
+        EasyMock.verify(mNetManager, mAlarmManager, mTime, mSettings, mConnManager);
+        EasyMock.reset(mNetManager, mAlarmManager, mTime, mSettings, mConnManager);
+    }
+}
diff --git a/services/tests/servicestests/src/com/android/server/ThrottleServiceTest.java b/services/tests/servicestests/src/com/android/server/ThrottleServiceTest.java
index ca33d32..2f275c3 100644
--- a/services/tests/servicestests/src/com/android/server/ThrottleServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/ThrottleServiceTest.java
@@ -25,14 +25,9 @@
 import static org.easymock.EasyMock.reset;
 import static org.easymock.EasyMock.verify;
 
-import com.google.common.collect.Lists;
-import com.google.common.util.concurrent.AbstractFuture;
-
 import android.content.ContentResolver;
 import android.content.Context;
-import android.content.ContextWrapper;
 import android.content.Intent;
-import android.content.IntentFilter;
 import android.net.INetworkManagementEventObserver;
 import android.net.NetworkStats;
 import android.net.ThrottleManager;
@@ -48,8 +43,6 @@
 import android.util.Log;
 import android.util.TrustedTime;
 
-import java.util.Iterator;
-import java.util.List;
 import java.util.concurrent.Future;
 
 /**
@@ -66,7 +59,7 @@
 
     private static final String TEST_IFACE = "test0";
 
-    private WatchingContext mWatchingContext;
+    private BroadcastInterceptingContext mWatchingContext;
     private INetworkManagementService mMockNMService;
     private TrustedTime mMockTime;
 
@@ -76,7 +69,7 @@
     public void setUp() throws Exception {
         super.setUp();
 
-        mWatchingContext = new WatchingContext(getContext());
+        mWatchingContext = new BroadcastInterceptingContext(getContext());
 
         mMockNMService = createMock(INetworkManagementService.class);
         mMockTime = createMock(TrustedTime.class);
@@ -295,11 +288,10 @@
      */
     public void expectGetInterfaceCounter(long rx, long tx) throws Exception {
         // TODO: provide elapsedRealtime mock to match TimeAuthority
-        final NetworkStats.Builder stats = new NetworkStats.Builder(
-                SystemClock.elapsedRealtime(), 1);
-        stats.addEntry(TEST_IFACE, NetworkStats.UID_ALL, rx, tx);
+        final NetworkStats stats = new NetworkStats(SystemClock.elapsedRealtime(), 1);
+        stats.addEntry(TEST_IFACE, NetworkStats.UID_ALL, NetworkStats.TAG_NONE, rx, tx);
 
-        expect(mMockNMService.getNetworkStatsSummary()).andReturn(stats.build()).atLeastOnce();
+        expect(mMockNMService.getNetworkStatsSummary()).andReturn(stats).atLeastOnce();
     }
 
     /**
@@ -354,69 +346,4 @@
 
         pollAction.get();
     }
-
-
-    /**
-     * {@link ContextWrapper} that can attach listeners for upcoming
-     * {@link Context#sendBroadcast(Intent)}.
-     */
-    private static class WatchingContext extends ContextWrapper {
-        private List<LocalBroadcastReceiver> mReceivers = Lists.newArrayList();
-
-        public class LocalBroadcastReceiver extends AbstractFuture<Intent> {
-            private IntentFilter mFilter;
-
-            public LocalBroadcastReceiver(IntentFilter filter) {
-                mFilter = filter;
-            }
-
-            public boolean dispatchBroadcast(Intent intent) {
-                if (mFilter.match(getContentResolver(), intent, false, TAG) > 0) {
-                    set(intent);
-                    return true;
-                } else {
-                    return false;
-                }
-            }
-        }
-
-        public WatchingContext(Context base) {
-            super(base);
-        }
-
-        public Future<Intent> nextBroadcastIntent(String action) {
-            return nextBroadcastIntent(new IntentFilter(action));
-        }
-
-        public Future<Intent> nextBroadcastIntent(IntentFilter filter) {
-            final LocalBroadcastReceiver receiver = new LocalBroadcastReceiver(filter);
-            synchronized (mReceivers) {
-                mReceivers.add(receiver);
-            }
-            return receiver;
-        }
-
-        @Override
-        public void sendBroadcast(Intent intent) {
-            synchronized (mReceivers) {
-                final Iterator<LocalBroadcastReceiver> i = mReceivers.iterator();
-                while (i.hasNext()) {
-                    final LocalBroadcastReceiver receiver = i.next();
-                    if (receiver.dispatchBroadcast(intent)) {
-                        i.remove();
-                    }
-                }
-            }
-        }
-
-        @Override
-        public void sendStickyBroadcast(Intent intent) {
-            sendBroadcast(intent);
-        }
-
-        @Override
-        public void removeStickyBroadcast(Intent intent) {
-            // ignored
-        }
-    }
 }
diff --git a/telephony/java/android/telephony/ServiceState.java b/telephony/java/android/telephony/ServiceState.java
index ba05837..fce7cdc 100644
--- a/telephony/java/android/telephony/ServiceState.java
+++ b/telephony/java/android/telephony/ServiceState.java
@@ -387,62 +387,77 @@
                 && mIsEmergencyOnly == s.mIsEmergencyOnly);
     }
 
+    /**
+     * Convert radio technology to String
+     *
+     * @param radioTechnology
+     * @return String representation of the RAT
+     *
+     * @hide
+     */
+    public static String radioTechnologyToString(int rt) {
+        String rtString;
+
+        switch(rt) {
+            case 0:
+                rtString = "Unknown";
+                break;
+            case 1:
+                rtString = "GPRS";
+                break;
+            case 2:
+                rtString = "EDGE";
+                break;
+            case 3:
+                rtString = "UMTS";
+                break;
+            case 4:
+                rtString = "CDMA-IS95A";
+                break;
+            case 5:
+                rtString = "CDMA-IS95B";
+                break;
+            case 6:
+                rtString = "1xRTT";
+                break;
+            case 7:
+                rtString = "EvDo-rev.0";
+                break;
+            case 8:
+                rtString = "EvDo-rev.A";
+                break;
+            case 9:
+                rtString = "HSDPA";
+                break;
+            case 10:
+                rtString = "HSUPA";
+                break;
+            case 11:
+                rtString = "HSPA";
+                break;
+            case 12:
+                rtString = "EvDo-rev.B";
+                break;
+            case 13:
+                rtString = "eHRPD";
+                break;
+            case 14:
+                rtString = "LTE";
+                break;
+            case 15:
+                rtString = "HSPAP";
+                break;
+            default:
+                rtString = "Unexpected";
+                Log.w(LOG_TAG, "Unexpected radioTechnology=" + rt);
+                break;
+        }
+        return rtString + ":" + rt;
+    }
+
     @Override
     public String toString() {
-        String radioTechnology = new String("Error in radioTechnology");
-        switch(this.mRadioTechnology) {
-        case 0:
-            radioTechnology = "Unknown";
-            break;
-        case 1:
-            radioTechnology = "GPRS";
-            break;
-        case 2:
-            radioTechnology = "EDGE";
-            break;
-        case 3:
-            radioTechnology = "UMTS";
-            break;
-        case 4:
-            radioTechnology = "IS95A";
-            break;
-        case 5:
-            radioTechnology = "IS95B";
-            break;
-        case 6:
-            radioTechnology = "1xRTT";
-            break;
-        case 7:
-            radioTechnology = "EvDo rev. 0";
-            break;
-        case 8:
-            radioTechnology = "EvDo rev. A";
-            break;
-        case 9:
-            radioTechnology = "HSDPA";
-            break;
-        case 10:
-            radioTechnology = "HSUPA";
-            break;
-        case 11:
-            radioTechnology = "HSPA";
-            break;
-        case 12:
-            radioTechnology = "EvDo rev. B";
-            break;
-        case 13:
-            radioTechnology = "eHRPD";
-            break;
-        case 14:
-            radioTechnology = "LTE";
-            break;
-        case 15:
-            radioTechnology = "HSPAP";
-            break;
-        default:
-            Log.w(LOG_TAG, "mRadioTechnology variable out of range.");
-        break;
-        }
+        String radioTechnology = radioTechnologyToString(mRadioTechnology);
 
         return (mState + " " + (mRoaming ? "roaming" : "home")
                 + " " + mOperatorAlphaLong
@@ -551,7 +566,7 @@
      *
      * @hide
      */
-    public void setCdmaEriText(String longName) {
+    public void setOperatorAlphaLong(String longName) {
         mOperatorAlphaLong = longName;
     }
 
diff --git a/telephony/java/android/telephony/SmsCbConstants.java b/telephony/java/android/telephony/SmsCbConstants.java
new file mode 100644
index 0000000..a1b4adf
--- /dev/null
+++ b/telephony/java/android/telephony/SmsCbConstants.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.telephony;
+
+/**
+ * Constants used in SMS Cell Broadcast messages.
+ *
+ * {@hide}
+ */
+public interface SmsCbConstants {
+    /** Start of PWS Message Identifier range (includes ETWS and CMAS). */
+    public static final int MESSAGE_ID_PWS_FIRST_IDENTIFIER = 0x1100;
+
+    /** Bitmask for messages of ETWS type (including future extensions). */
+    public static final int MESSAGE_ID_ETWS_TYPE_MASK       = 0xFFF8;
+
+    /** Value for messages of ETWS type after applying {@link #MESSAGE_ID_ETWS_TYPE_MASK}. */
+    public static final int MESSAGE_ID_ETWS_TYPE            = 0x1100;
+
+    /** ETWS Message Identifier for earthquake warning message. */
+    public static final int MESSAGE_ID_ETWS_EARTHQUAKE_WARNING      = 0x1100;
+
+    /** ETWS Message Identifier for tsunami warning message. */
+    public static final int MESSAGE_ID_ETWS_TSUNAMI_WARNING         = 0x1101;
+
+    /** ETWS Message Identifier for earthquake and tsunami combined warning message. */
+    public static final int MESSAGE_ID_ETWS_EARTHQUAKE_AND_TSUNAMI_WARNING  = 0x1102;
+
+    /** ETWS Message Identifier for test message. */
+    public static final int MESSAGE_ID_ETWS_TEST_MESSAGE            = 0x1103;
+
+    /** ETWS Message Identifier for messages related to other emergency types. */
+    public static final int MESSAGE_ID_ETWS_OTHER_EMERGENCY_TYPE    = 0x1104;
+
+    /** Start of CMAS Message Identifier range. */
+    public static final int MESSAGE_ID_CMAS_FIRST_IDENTIFIER                = 0x1112;
+
+    /** CMAS Message Identifier for Presidential Level alerts. */
+    public static final int MESSAGE_ID_CMAS_ALERT_PRESIDENTIAL_LEVEL        = 0x1112;
+
+    /** CMAS Message Identifier for Extreme alerts, Urgency=Immediate, Certainty=Observed. */
+    public static final int MESSAGE_ID_CMAS_ALERT_EXTREME_IMMEDIATE_OBSERVED = 0x1113;
+
+    /** CMAS Message Identifier for Extreme alerts, Urgency=Immediate, Certainty=Likely. */
+    public static final int MESSAGE_ID_CMAS_ALERT_EXTREME_IMMEDIATE_LIKELY  = 0x1114;
+
+    /** CMAS Message Identifier for Extreme alerts, Urgency=Expected, Certainty=Observed. */
+    public static final int MESSAGE_ID_CMAS_ALERT_EXTREME_EXPECTED_OBSERVED = 0x1115;
+
+    /** CMAS Message Identifier for Extreme alerts, Urgency=Expected, Certainty=Likely. */
+    public static final int MESSAGE_ID_CMAS_ALERT_EXTREME_EXPECTED_LIKELY   = 0x1116;
+
+    /** CMAS Message Identifier for Severe alerts, Urgency=Immediate, Certainty=Observed. */
+    public static final int MESSAGE_ID_CMAS_ALERT_SEVERE_IMMEDIATE_OBSERVED = 0x1117;
+
+    /** CMAS Message Identifier for Severe alerts, Urgency=Immediate, Certainty=Likely. */
+    public static final int MESSAGE_ID_CMAS_ALERT_SEVERE_IMMEDIATE_LIKELY   = 0x1118;
+
+    /** CMAS Message Identifier for Severe alerts, Urgency=Expected, Certainty=Observed. */
+    public static final int MESSAGE_ID_CMAS_ALERT_SEVERE_EXPECTED_OBSERVED  = 0x1119;
+
+    /** CMAS Message Identifier for Severe alerts, Urgency=Expected, Certainty=Likely. */
+    public static final int MESSAGE_ID_CMAS_ALERT_SEVERE_EXPECTED_LIKELY    = 0x111A;
+
+    /** CMAS Message Identifier for Child Abduction Emergency (Amber Alert). */
+    public static final int MESSAGE_ID_CMAS_ALERT_CHILD_ABDUCTION_EMERGENCY = 0x111B;
+
+    /** CMAS Message Identifier for the Required Monthly Test. */
+    public static final int MESSAGE_ID_CMAS_ALERT_REQUIRED_MONTHLY_TEST     = 0x111C;
+
+    /** CMAS Message Identifier for CMAS Exercise. */
+    public static final int MESSAGE_ID_CMAS_ALERT_EXERCISE                  = 0x111D;
+
+    /** CMAS Message Identifier for operator defined use. */
+    public static final int MESSAGE_ID_CMAS_ALERT_OPERATOR_DEFINED_USE      = 0x111E;
+
+    /** End of CMAS Message Identifier range (including future extensions). */
+    public static final int MESSAGE_ID_CMAS_LAST_IDENTIFIER                 = 0x112F;
+
+    /** End of PWS Message Identifier range (includes ETWS, CMAS, and future extensions). */
+    public static final int MESSAGE_ID_PWS_LAST_IDENTIFIER                  = 0x18FF;
+
+    /** ETWS message code flag to activate the popup display. */
+    public static final int MESSAGE_CODE_ETWS_ACTIVATE_POPUP                = 0x100;
+
+    /** ETWS message code flag to activate the emergency user alert. */
+    public static final int MESSAGE_CODE_ETWS_EMERGENCY_USER_ALERT          = 0x200;
+
+    /** ETWS warning type value for earthquake. */
+    public static final int ETWS_WARNING_TYPE_EARTHQUAKE                    = 0x00;
+
+    /** ETWS warning type value for tsunami. */
+    public static final int ETWS_WARNING_TYPE_TSUNAMI                       = 0x01;
+
+    /** ETWS warning type value for earthquake and tsunami. */
+    public static final int ETWS_WARNING_TYPE_EARTHQUAKE_AND_TSUNAMI        = 0x02;
+
+    /** ETWS warning type value for test broadcast. */
+    public static final int ETWS_WARNING_TYPE_TEST                          = 0x03;
+
+    /** ETWS warning type value for other notifications. */
+    public static final int ETWS_WARNING_TYPE_OTHER                         = 0x04;
+}
diff --git a/telephony/java/android/telephony/SmsCbMessage.java b/telephony/java/android/telephony/SmsCbMessage.java
index 3543275..383e0f9 100644
--- a/telephony/java/android/telephony/SmsCbMessage.java
+++ b/telephony/java/android/telephony/SmsCbMessage.java
@@ -16,7 +16,11 @@
 
 package android.telephony;
 
+import android.text.format.Time;
+import android.util.Log;
+
 import com.android.internal.telephony.GsmAlphabet;
+import com.android.internal.telephony.IccUtils;
 import com.android.internal.telephony.gsm.SmsCbHeader;
 
 import java.io.UnsupportedEncodingException;
@@ -58,10 +62,13 @@
         try {
             return new SmsCbMessage(pdu);
         } catch (IllegalArgumentException e) {
+            Log.w(LOG_TAG, "Failed parsing SMS-CB pdu", e);
             return null;
         }
     }
 
+    private static final String LOG_TAG = "SMSCB";
+
     /**
      * Languages in the 0000xxxx DCS group as defined in 3GPP TS 23.038, section 5.
      */
@@ -80,15 +87,34 @@
 
     private static final char CARRIAGE_RETURN = 0x0d;
 
+    private static final int PDU_BODY_PAGE_LENGTH = 82;
+
     private SmsCbHeader mHeader;
 
     private String mLanguage;
 
     private String mBody;
 
+    /** Timestamp of ETWS primary notification with security. */
+    private long mPrimaryNotificationTimestamp;
+
+    /** 43 byte digital signature of ETWS primary notification with security. */
+    private byte[] mPrimaryNotificationDigitalSignature;
+
     private SmsCbMessage(byte[] pdu) throws IllegalArgumentException {
         mHeader = new SmsCbHeader(pdu);
-        parseBody(pdu);
+        if (mHeader.format == SmsCbHeader.FORMAT_ETWS_PRIMARY) {
+            mBody = "ETWS";
+            // ETWS primary notification with security is 56 octets in length
+            if (pdu.length >= SmsCbHeader.PDU_LENGTH_ETWS) {
+                mPrimaryNotificationTimestamp = getTimestampMillis(pdu);
+                mPrimaryNotificationDigitalSignature = new byte[43];
+                // digital signature starts after 6 byte header and 7 byte timestamp
+                System.arraycopy(pdu, 13, mPrimaryNotificationDigitalSignature, 0, 43);
+            }
+        } else {
+            parseBody(pdu);
+        }
     }
 
     /**
@@ -149,6 +175,62 @@
         return mHeader.updateNumber;
     }
 
+    /**
+     * Get the format of this message.
+     * @return {@link SmsCbHeader#FORMAT_GSM}, {@link SmsCbHeader#FORMAT_UMTS}, or
+     *         {@link SmsCbHeader#FORMAT_ETWS_PRIMARY}
+     */
+    public int getMessageFormat() {
+        return mHeader.format;
+    }
+
+    /**
+     * For ETWS primary notifications, return the emergency user alert flag.
+     * @return true to notify terminal to activate emergency user alert; false otherwise
+     */
+    public boolean getEtwsEmergencyUserAlert() {
+        return mHeader.etwsEmergencyUserAlert;
+    }
+
+    /**
+     * For ETWS primary notifications, return the popup flag.
+     * @return true to notify terminal to activate display popup; false otherwise
+     */
+    public boolean getEtwsPopup() {
+        return mHeader.etwsPopup;
+    }
+
+    /**
+     * For ETWS primary notifications, return the warning type.
+     * @return a value such as {@link SmsCbConstants#ETWS_WARNING_TYPE_EARTHQUAKE}
+     */
+    public int getEtwsWarningType() {
+        return mHeader.etwsWarningType;
+    }
+
+    /**
+     * For ETWS primary notifications, return the Warning-Security-Information timestamp.
+     * @return a timestamp in System.currentTimeMillis() format.
+     */
+    public long getEtwsSecurityTimestamp() {
+        return mPrimaryNotificationTimestamp;
+    }
+
+    /**
+     * For ETWS primary notifications, return the 43 byte digital signature.
+     * @return a byte array containing a copy of the digital signature
+     */
+    public byte[] getEtwsSecuritySignature() {
+        return mPrimaryNotificationDigitalSignature.clone();
+    }
+
+    /**
+     * Parse and unpack the body text according to the encoding in the DCS.
+     * After completing successfully this method will have assigned the body
+     * text into mBody, and optionally the language code into mLanguage
+     *
+     * @param pdu The pdu
+     */
     private void parseBody(byte[] pdu) {
         int encoding;
         boolean hasLanguageIndicator = false;
@@ -221,28 +303,81 @@
                 break;
         }
 
+        if (mHeader.format == SmsCbHeader.FORMAT_UMTS) {
+            // Payload may contain multiple pages
+            int nrPages = pdu[SmsCbHeader.PDU_HEADER_LENGTH];
+
+            if (pdu.length < SmsCbHeader.PDU_HEADER_LENGTH + 1 + (PDU_BODY_PAGE_LENGTH + 1)
+                    * nrPages) {
+                throw new IllegalArgumentException("Pdu length " + pdu.length + " does not match "
+                        + nrPages + " pages");
+            }
+
+            StringBuilder sb = new StringBuilder();
+
+            for (int i = 0; i < nrPages; i++) {
+                // Each page is 82 bytes followed by a length octet indicating
+                // the number of useful octets within those 82
+                int offset = SmsCbHeader.PDU_HEADER_LENGTH + 1 + (PDU_BODY_PAGE_LENGTH + 1) * i;
+                int length = pdu[offset + PDU_BODY_PAGE_LENGTH];
+
+                if (length > PDU_BODY_PAGE_LENGTH) {
+                    throw new IllegalArgumentException("Page length " + length
+                            + " exceeds maximum value " + PDU_BODY_PAGE_LENGTH);
+                }
+
+                sb.append(unpackBody(pdu, encoding, offset, length, hasLanguageIndicator));
+            }
+            mBody = sb.toString();
+        } else {
+            // Payload is one single page
+            int offset = SmsCbHeader.PDU_HEADER_LENGTH;
+            int length = pdu.length - offset;
+
+            mBody = unpackBody(pdu, encoding, offset, length, hasLanguageIndicator);
+        }
+    }
+
+    /**
+     * Unpack body text from the pdu using the given encoding, position and
+     * length within the pdu
+     *
+     * @param pdu The pdu
+     * @param encoding The encoding, as derived from the DCS
+     * @param offset Position of the first byte to unpack
+     * @param length Number of bytes to unpack
+     * @param hasLanguageIndicator true if the body text is preceded by a
+     *            language indicator. If so, this method will as a side-effect
+     *            assign the extracted language code into mLanguage
+     * @return Body text
+     */
+    private String unpackBody(byte[] pdu, int encoding, int offset, int length,
+            boolean hasLanguageIndicator) {
+        String body = null;
+
         switch (encoding) {
             case SmsMessage.ENCODING_7BIT:
-                mBody = GsmAlphabet.gsm7BitPackedToString(pdu, SmsCbHeader.PDU_HEADER_LENGTH,
-                        (pdu.length - SmsCbHeader.PDU_HEADER_LENGTH) * 8 / 7);
+                body = GsmAlphabet.gsm7BitPackedToString(pdu, offset, length * 8 / 7);
 
-                if (hasLanguageIndicator && mBody != null && mBody.length() > 2) {
-                    mLanguage = mBody.substring(0, 2);
-                    mBody = mBody.substring(3);
+                if (hasLanguageIndicator && body != null && body.length() > 2) {
+                    // Language is two GSM characters followed by a CR.
+                    // The actual body text is offset by 3 characters.
+                    mLanguage = body.substring(0, 2);
+                    body = body.substring(3);
                 }
                 break;
 
             case SmsMessage.ENCODING_16BIT:
-                int offset = SmsCbHeader.PDU_HEADER_LENGTH;
-
-                if (hasLanguageIndicator && pdu.length >= SmsCbHeader.PDU_HEADER_LENGTH + 2) {
-                    mLanguage = GsmAlphabet.gsm7BitPackedToString(pdu,
-                            SmsCbHeader.PDU_HEADER_LENGTH, 2);
+                if (hasLanguageIndicator && pdu.length >= offset + 2) {
+                    // Language is two GSM characters.
+                    // The actual body text is offset by 2 bytes.
+                    mLanguage = GsmAlphabet.gsm7BitPackedToString(pdu, offset, 2);
                     offset += 2;
+                    length -= 2;
                 }
 
                 try {
-                    mBody = new String(pdu, offset, (pdu.length & 0xfffe) - offset, "utf-16");
+                    body = new String(pdu, offset, (length & 0xfffe), "utf-16");
                 } catch (UnsupportedEncodingException e) {
                     // Eeeek
                 }
@@ -252,16 +387,73 @@
                 break;
         }
 
-        if (mBody != null) {
+        if (body != null) {
             // Remove trailing carriage return
-            for (int i = mBody.length() - 1; i >= 0; i--) {
-                if (mBody.charAt(i) != CARRIAGE_RETURN) {
-                    mBody = mBody.substring(0, i + 1);
+            for (int i = body.length() - 1; i >= 0; i--) {
+                if (body.charAt(i) != CARRIAGE_RETURN) {
+                    body = body.substring(0, i + 1);
                     break;
                 }
             }
         } else {
-            mBody = "";
+            body = "";
         }
+
+        return body;
+    }
+
+    /**
+     * Parses an ETWS primary notification timestamp and returns a currentTimeMillis()-style
+     * timestamp. Copied from com.android.internal.telephony.gsm.SmsMessage.
+     * @param pdu the ETWS primary notification PDU to decode
+     * @return the UTC timestamp from the Warning-Security-Information parameter
+     */
+    private long getTimestampMillis(byte[] pdu) {
+        // Timestamp starts after CB header, in pdu[6]
+        int year = IccUtils.gsmBcdByteToInt(pdu[6]);
+        int month = IccUtils.gsmBcdByteToInt(pdu[7]);
+        int day = IccUtils.gsmBcdByteToInt(pdu[8]);
+        int hour = IccUtils.gsmBcdByteToInt(pdu[9]);
+        int minute = IccUtils.gsmBcdByteToInt(pdu[10]);
+        int second = IccUtils.gsmBcdByteToInt(pdu[11]);
+
+        // For the timezone, the most significant bit of the
+        // least significant nibble is the sign byte
+        // (meaning the max range of this field is 79 quarter-hours,
+        // which is more than enough)
+
+        byte tzByte = pdu[12];
+
+        // Mask out sign bit.
+        int timezoneOffset = IccUtils.gsmBcdByteToInt((byte) (tzByte & (~0x08)));
+
+        timezoneOffset = ((tzByte & 0x08) == 0) ? timezoneOffset : -timezoneOffset;
+
+        Time time = new Time(Time.TIMEZONE_UTC);
+
+        // It's 2006.  Should I really support years < 2000?
+        time.year = year >= 90 ? year + 1900 : year + 2000;
+        time.month = month - 1;
+        time.monthDay = day;
+        time.hour = hour;
+        time.minute = minute;
+        time.second = second;
+
+        // Timezone offset is in quarter hours.
+        return time.toMillis(true) - (timezoneOffset * 15 * 60 * 1000);
+    }
+
+    /**
+     * Append text to the message body. This is used to concatenate multi-page GSM broadcasts.
+     * @param body the text to append to this message
+     */
+    public void appendToBody(String body) {
+        mBody = mBody + body;
+    }
+
+    @Override
+    public String toString() {
+        return "SmsCbMessage{" + mHeader.toString() + ", language=" + mLanguage +
+                ", body=\"" + mBody + "\"}";
     }
 }
diff --git a/telephony/java/android/telephony/SmsManager.java b/telephony/java/android/telephony/SmsManager.java
index 6a346af..5bdc146 100644
--- a/telephony/java/android/telephony/SmsManager.java
+++ b/telephony/java/android/telephony/SmsManager.java
@@ -345,7 +345,7 @@
      * message identifier. Note that if two different clients enable the same
      * message identifier, they must both disable it for the device to stop
      * receiving those messages. All received messages will be broadcast in an
-     * intent with the action "android.provider.telephony.SMS_CB_RECEIVED".
+     * intent with the action "android.provider.Telephony.SMS_CB_RECEIVED".
      * Note: This call is blocking, callers may want to avoid calling it from
      * the main thread of an application.
      *
@@ -401,6 +401,68 @@
     }
 
     /**
+     * Enable reception of cell broadcast (SMS-CB) messages with the given
+     * message identifier range. Note that if two different clients enable the same
+     * message identifier, they must both disable it for the device to stop
+     * receiving those messages. All received messages will be broadcast in an
+     * intent with the action "android.provider.Telephony.SMS_CB_RECEIVED".
+     * Note: This call is blocking, callers may want to avoid calling it from
+     * the main thread of an application.
+     *
+     * @param startMessageId first message identifier as specified in TS 23.041
+     * @param endMessageId last message identifier as specified in TS 23.041
+     * @return true if successful, false otherwise
+     * @see #disableCellBroadcastRange(int, int)
+     *
+     * {@hide}
+     */
+    public boolean enableCellBroadcastRange(int startMessageId, int endMessageId) {
+        boolean success = false;
+
+        try {
+            ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
+            if (iccISms != null) {
+                success = iccISms.enableCellBroadcastRange(startMessageId, endMessageId);
+            }
+        } catch (RemoteException ex) {
+            // ignore it
+        }
+
+        return success;
+    }
+
+    /**
+     * Disable reception of cell broadcast (SMS-CB) messages with the given
+     * message identifier range. Note that if two different clients enable the same
+     * message identifier, they must both disable it for the device to stop
+     * receiving those messages.
+     * Note: This call is blocking, callers may want to avoid calling it from
+     * the main thread of an application.
+     *
+     * @param startMessageId first message identifier as specified in TS 23.041
+     * @param endMessageId last message identifier as specified in TS 23.041
+     * @return true if successful, false otherwise
+     *
+     * @see #enableCellBroadcastRange(int, int)
+     *
+     * {@hide}
+     */
+    public boolean disableCellBroadcastRange(int startMessageId, int endMessageId) {
+        boolean success = false;
+
+        try {
+            ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
+            if (iccISms != null) {
+                success = iccISms.disableCellBroadcastRange(startMessageId, endMessageId);
+            }
+        } catch (RemoteException ex) {
+            // ignore it
+        }
+
+        return success;
+    }
+
+    /**
      * Create a list of <code>SmsMessage</code>s from a list of RawSmsData
      * records returned by <code>getAllMessagesFromIcc()</code>
      *
diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java
index 8732e21..184d665 100644
--- a/telephony/java/android/telephony/TelephonyManager.java
+++ b/telephony/java/android/telephony/TelephonyManager.java
@@ -191,6 +191,10 @@
      *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
      */
     public String getDeviceId() {
+        if (!isVoiceCapable()) {
+            return null;
+        }
+
         try {
             return getSubscriberInfo().getDeviceId();
         } catch (RemoteException ex) {
@@ -426,8 +430,7 @@
     public static final int NETWORK_TYPE_LTE = 13;
     /** Current network is eHRPD */
     public static final int NETWORK_TYPE_EHRPD = 14;
-    /** Current network is HSPA+
-     * @hide */
+    /** Current network is HSPA+ */
     public static final int NETWORK_TYPE_HSPAP = 15;
 
     /**
@@ -450,6 +453,7 @@
      * @see #NETWORK_TYPE_IDEN
      * @see #NETWORK_TYPE_LTE
      * @see #NETWORK_TYPE_EHRPD
+     * @see #NETWORK_TYPE_HSPAP
      */
     public int getNetworkType() {
         try{
@@ -469,6 +473,46 @@
         }
     }
 
+    /** Unknown network class. {@hide} */
+    public static final int NETWORK_CLASS_UNKNOWN = 0;
+    /** Class of broadly defined "2G" networks. {@hide} */
+    public static final int NETWORK_CLASS_2_G = 1;
+    /** Class of broadly defined "3G" networks. {@hide} */
+    public static final int NETWORK_CLASS_3_G = 2;
+    /** Class of broadly defined "4G" networks. {@hide} */
+    public static final int NETWORK_CLASS_4_G = 3;
+
+    /**
+     * Return general class of network type, such as "3G" or "4G". In cases
+     * where classification is contentious, this method is conservative.
+     *
+     * @hide
+     */
+    public static int getNetworkClass(int networkType) {
+        switch (networkType) {
+            case NETWORK_TYPE_GPRS:
+            case NETWORK_TYPE_EDGE:
+            case NETWORK_TYPE_CDMA:
+            case NETWORK_TYPE_1xRTT:
+            case NETWORK_TYPE_IDEN:
+                return NETWORK_CLASS_2_G;
+            case NETWORK_TYPE_UMTS:
+            case NETWORK_TYPE_EVDO_0:
+            case NETWORK_TYPE_EVDO_A:
+            case NETWORK_TYPE_HSDPA:
+            case NETWORK_TYPE_HSUPA:
+            case NETWORK_TYPE_HSPA:
+            case NETWORK_TYPE_EVDO_B:
+            case NETWORK_TYPE_EHRPD:
+            case NETWORK_TYPE_HSPAP:
+                return NETWORK_CLASS_3_G;
+            case NETWORK_TYPE_LTE:
+                return NETWORK_CLASS_4_G;
+            default:
+                return NETWORK_CLASS_UNKNOWN;
+        }
+    }
+
     /**
      * Returns a string representation of the radio technology (network type)
      * currently in use on the device.
@@ -477,7 +521,12 @@
      * @hide pending API council review
      */
     public String getNetworkTypeName() {
-        switch (getNetworkType()) {
+        return getNetworkTypeName(getNetworkType());
+    }
+
+    /** {@hide} */
+    public static String getNetworkTypeName(int type) {
+        switch (type) {
             case NETWORK_TYPE_GPRS:
                 return "GPRS";
             case NETWORK_TYPE_EDGE:
@@ -506,6 +555,8 @@
                 return "CDMA - eHRPD";
             case NETWORK_TYPE_IDEN:
                 return "iDEN";
+            case NETWORK_TYPE_HSPAP:
+                return "HSPA+";
             default:
                 return "UNKNOWN";
         }
diff --git a/telephony/java/com/android/internal/telephony/BaseCommands.java b/telephony/java/com/android/internal/telephony/BaseCommands.java
index 0c4581b..8427d14 100644
--- a/telephony/java/com/android/internal/telephony/BaseCommands.java
+++ b/telephony/java/com/android/internal/telephony/BaseCommands.java
@@ -96,8 +96,10 @@
     protected Registrant mRestrictedStateRegistrant;
     protected Registrant mGsmBroadcastSmsRegistrant;
 
-    // Network Mode received from PhoneFactory
-    protected int mNetworkMode;
+    // Preferred network type received from PhoneFactory.
+    // This is used when establishing a connection to the
+    // vendor ril so it starts up in the correct mode.
+    protected int mPreferredNetworkType;
     // CDMA subscription received from PhoneFactory
     protected int mCdmaSubscription;
     // Type of Phone, GSM or CDMA. Set by CDMAPhone or GSMPhone.
diff --git a/telephony/java/com/android/internal/telephony/CallManager.java b/telephony/java/com/android/internal/telephony/CallManager.java
index 7abae09..171b371 100644
--- a/telephony/java/com/android/internal/telephony/CallManager.java
+++ b/telephony/java/com/android/internal/telephony/CallManager.java
@@ -1803,33 +1803,33 @@
         Call call;
         StringBuilder b = new StringBuilder();
 
-        b.append("########### Dump CallManager ############");
-        b.append("\nCallManager state = " + getState());
+        b.append("CallManager {");
+        b.append("\nstate = " + getState());
         call = getActiveFgCall();
-        b.append("\n   - Foreground: " + getActiveFgCallState());
+        b.append("\n- Foreground: " + getActiveFgCallState());
         b.append(" from " + call.getPhone());
-        b.append("\n     Conn: ").append(getFgCallConnections());
+        b.append("\n  Conn: ").append(getFgCallConnections());
         call = getFirstActiveBgCall();
-        b.append("\n   - Background: " + call.getState());
+        b.append("\n- Background: " + call.getState());
         b.append(" from " + call.getPhone());
-        b.append("\n     Conn: ").append(getBgCallConnections());
+        b.append("\n  Conn: ").append(getBgCallConnections());
         call = getFirstActiveRingingCall();
-        b.append("\n   - Ringing: " +call.getState());
+        b.append("\n- Ringing: " +call.getState());
         b.append(" from " + call.getPhone());
 
         for (Phone phone : getAllPhones()) {
             if (phone != null) {
-                b.append("\n Phone: " + phone + ", name = " + phone.getPhoneName()
+                b.append("\nPhone: " + phone + ", name = " + phone.getPhoneName()
                         + ", state = " + phone.getState());
                 call = phone.getForegroundCall();
-                b.append("\n   - Foreground: ").append(call);
+                b.append("\n- Foreground: ").append(call);
                 call = phone.getBackgroundCall();
                 b.append(" Background: ").append(call);
                 call = phone.getRingingCall();
                 b.append(" Ringing: ").append(call);
             }
         }
-        b.append("\n########## End Dump CallManager ##########");
+        b.append("\n}");
         return b.toString();
     }
 }
diff --git a/telephony/java/com/android/internal/telephony/CallerInfo.java b/telephony/java/com/android/internal/telephony/CallerInfo.java
index 014901d..457fa7aa 100644
--- a/telephony/java/com/android/internal/telephony/CallerInfo.java
+++ b/telephony/java/com/android/internal/telephony/CallerInfo.java
@@ -19,6 +19,7 @@
 import android.content.Context;
 import android.database.Cursor;
 import android.graphics.drawable.Drawable;
+import android.location.CountryDetector;
 import android.net.Uri;
 import android.provider.ContactsContract.CommonDataKinds.Phone;
 import android.provider.ContactsContract.Data;
@@ -29,6 +30,13 @@
 import android.text.TextUtils;
 import android.util.Log;
 
+import com.google.i18n.phonenumbers.NumberParseException;
+import com.google.i18n.phonenumbers.PhoneNumberOfflineGeocoder;
+import com.google.i18n.phonenumbers.PhoneNumberUtil;
+import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
+
+import java.util.Locale;
+
 
 /**
  * Looks up caller information for the given phone number.
@@ -72,7 +80,8 @@
      */
     public String name;
     public String phoneNumber;
-    public String nomalizedNumber;
+    public String normalizedNumber;
+    public String geoDescription;
 
     public String cnapName;
     public int numberPresentation;
@@ -131,7 +140,7 @@
         info.isCachedPhotoCurrent = false;
         info.contactExists = false;
 
-        if (VDBG) Log.v(TAG, "construct callerInfo from cursor");
+        if (VDBG) Log.v(TAG, "getCallerInfo() based on cursor...");
 
         if (cursor != null) {
             if (cursor.moveToFirst()) {
@@ -156,7 +165,7 @@
                 // Look for the normalized number
                 columnIndex = cursor.getColumnIndex(PhoneLookup.NORMALIZED_NUMBER);
                 if (columnIndex != -1) {
-                    info.nomalizedNumber = cursor.getString(columnIndex);
+                    info.normalizedNumber = cursor.getString(columnIndex);
                 }
 
                 // Look for the label/type combo
@@ -236,6 +245,8 @@
      * with all relevant fields empty or null.
      */
     public static CallerInfo getCallerInfo(Context context, String number) {
+        if (VDBG) Log.v(TAG, "getCallerInfo() based on number...");
+
         if (TextUtils.isEmpty(number)) {
             return null;
         }
@@ -473,6 +484,66 @@
     }
 
     /**
+     * Updates this CallerInfo's geoDescription field, based on the raw
+     * phone number in the phoneNumber field.
+     *
+     * (Note that the various getCallerInfo() methods do *not* set the
+     * geoDescription automatically; you need to call this method
+     * explicitly to get it.)
+     *
+     * @param context the context used to look up the current locale / country
+     * @param fallbackNumber if this CallerInfo's phoneNumber field is empty,
+     *        this specifies a fallback number to use instead.
+     */
+    public void updateGeoDescription(Context context, String fallbackNumber) {
+        String number = TextUtils.isEmpty(phoneNumber) ? fallbackNumber : phoneNumber;
+        geoDescription = getGeoDescription(context, number);
+    }
+
+    /**
+     * @return a geographical description string for the specified number.
+     * @see com.google.i18n.phonenumbers.PhoneNumberOfflineGeocoder
+     */
+    private static String getGeoDescription(Context context, String number) {
+        if (VDBG) Log.v(TAG, "getGeoDescription('" + number + "')...");
+
+        if (TextUtils.isEmpty(number)) {
+            return null;
+        }
+
+        PhoneNumberUtil util = PhoneNumberUtil.getInstance();
+        PhoneNumberOfflineGeocoder geocoder = PhoneNumberOfflineGeocoder.getInstance();
+
+        String countryIso;
+        Locale locale = context.getResources().getConfiguration().locale;
+        CountryDetector detector = (CountryDetector) context.getSystemService(
+                Context.COUNTRY_DETECTOR);
+        if (detector != null) {
+            countryIso = detector.detectCountry().getCountryIso();
+        } else {
+            countryIso = locale.getCountry();
+            Log.w(TAG, "No CountryDetector; falling back to countryIso based on locale: "
+                  + countryIso);
+        }
+
+        PhoneNumber pn = null;
+        try {
+            pn = util.parse(number, countryIso);
+            if (VDBG) Log.v(TAG, "- parsed number: " + pn);
+        } catch (NumberParseException e) {
+            Log.w(TAG, "getGeoDescription: NumberParseException for incoming number '" + number + "'");
+        }
+
+        if (pn != null) {
+            String description = geocoder.getDescriptionForNumber(pn, locale);
+            if (VDBG) Log.v(TAG, "- got description: '" + description + "'");
+            return description;
+        } else {
+            return null;
+        }
+    }
+
+    /**
      * @return a string debug representation of this instance.
      */
     public String toString() {
@@ -482,8 +553,11 @@
 
         if (VERBOSE_DEBUG) {
             return new StringBuilder(384)
+                    .append(super.toString() + " { ")
                     .append("\nname: " + name)
                     .append("\nphoneNumber: " + phoneNumber)
+                    .append("\nnormalizedNumber: " + normalizedNumber)
+                    .append("\ngeoDescription: " + geoDescription)
                     .append("\ncnapName: " + cnapName)
                     .append("\nnumberPresentation: " + numberPresentation)
                     .append("\nnamePresentation: " + namePresentation)
@@ -502,10 +576,11 @@
                     .append("\nemergency: " + mIsEmergency)
                     .append("\nvoicemail " + mIsVoiceMail)
                     .append("\ncontactExists " + contactExists)
+                    .append(" }")
                     .toString();
         } else {
             return new StringBuilder(128)
-                    .append("CallerInfo { ")
+                    .append(super.toString() + " { ")
                     .append("name " + ((name == null) ? "null" : "non-null"))
                     .append(", phoneNumber " + ((phoneNumber == null) ? "null" : "non-null"))
                     .append(" }")
diff --git a/telephony/java/com/android/internal/telephony/CallerInfoAsyncQuery.java b/telephony/java/com/android/internal/telephony/CallerInfoAsyncQuery.java
index c47e076..bbd4232 100644
--- a/telephony/java/com/android/internal/telephony/CallerInfoAsyncQuery.java
+++ b/telephony/java/com/android/internal/telephony/CallerInfoAsyncQuery.java
@@ -34,9 +34,11 @@
 import android.util.Log;
 
 /**
- * ASYNCHRONOUS QUERY API
+ * Helper class to make it easier to run asynchronous caller-id lookup queries.
+ * @see CallerInfo
+ *
+ * {@hide}
  */
-
 public class CallerInfoAsyncQuery {
     private static final boolean DBG = false;
     private static final String LOG_TAG = "CallerInfoAsyncQuery";
@@ -239,12 +241,31 @@
                                 + mCallerInfo);
                     }
 
+                    // Final step: look up the geocoded description.
+                    //
+                    // For now, do this only if we *don't* have a valid name (i.e. if
+                    // no contacts matched the phone number of the incoming call),
+                    // since that's the only case where the incoming-call UI cares
+                    // about this field.
+                    // (TODO: But if we ever want the UI to show the geoDescription
+                    // even when we *do* match a contact, we'll need to either call
+                    // updateGeoDescription() unconditionally here, or possibly add a
+                    // new parameter to CallerInfoAsyncQuery.startQuery() to force
+                    // the geoDescription field to be populated.)
+                    if (TextUtils.isEmpty(mCallerInfo.name)) {
+                        // Actually when no contacts match the incoming phone number,
+                        // the CallerInfo object is totally blank here (i.e. no name
+                        // *or* phoneNumber).  So we need to pass in cw.number as
+                        // a fallback number.
+                        mCallerInfo.updateGeoDescription(mQueryContext, cw.number);
+                    }
+
                     // Use the number entered by the user for display.
                     if (!TextUtils.isEmpty(cw.number)) {
                         CountryDetector detector = (CountryDetector) mQueryContext.getSystemService(
                                 Context.COUNTRY_DETECTOR);
                         mCallerInfo.phoneNumber = PhoneNumberUtils.formatNumber(cw.number,
-                                mCallerInfo.nomalizedNumber,
+                                mCallerInfo.normalizedNumber,
                                 detector.detectCountry().getCountryIso());
                     }
                 }
@@ -412,7 +433,7 @@
      * Method to create a new CallerInfoAsyncQueryHandler object, ensuring correct
      * state of context and uri.
      */
-    private void allocate (Context context, Uri contactRef) {
+    private void allocate(Context context, Uri contactRef) {
         if ((context == null) || (contactRef == null)){
             throw new QueryPoolException("Bad context or query uri.");
         }
@@ -424,7 +445,7 @@
     /**
      * Releases the relevant data.
      */
-    private void release () {
+    private void release() {
         mHandler.mQueryContext = null;
         mHandler.mQueryUri = null;
         mHandler.mCallerInfo = null;
diff --git a/telephony/java/com/android/internal/telephony/DataCallState.java b/telephony/java/com/android/internal/telephony/DataCallState.java
index 1d67d45..f5651e0 100644
--- a/telephony/java/com/android/internal/telephony/DataCallState.java
+++ b/telephony/java/com/android/internal/telephony/DataCallState.java
@@ -202,7 +202,7 @@
 
                 result = SetupResult.SUCCESS;
             } catch (UnknownHostException e) {
-                Log.d(LOG_TAG, "onSetupCompleted: UnknownHostException " + e);
+                Log.d(LOG_TAG, "setLinkProperties: UnknownHostException " + e);
                 e.printStackTrace();
                 result = SetupResult.ERR_UnacceptableParameter;
             }
@@ -216,8 +216,10 @@
 
         // An error occurred so clear properties
         if (result != SetupResult.SUCCESS) {
-            if(DBG) Log.d(LOG_TAG,
-                    "onSetupConnectionCompleted with an error, clearing LinkProperties");
+            if(DBG) {
+                Log.d(LOG_TAG, "setLinkProperties: error clearing LinkProperties " +
+                        "status=" + status + " result=" + result);
+            }
             linkProperties.clear();
         }
 
diff --git a/telephony/java/com/android/internal/telephony/DataConnection.java b/telephony/java/com/android/internal/telephony/DataConnection.java
index 3636baa..5c030fd 100644
--- a/telephony/java/com/android/internal/telephony/DataConnection.java
+++ b/telephony/java/com/android/internal/telephony/DataConnection.java
@@ -62,6 +62,7 @@
  */
 public abstract class DataConnection extends StateMachine {
     protected static final boolean DBG = true;
+    protected static final boolean VDBG = false;
 
     protected static Object mCountLock = new Object();
     protected static int mCount;
@@ -141,7 +142,7 @@
         static {
             sErrorCodeToFailCauseMap = new HashMap<Integer, FailCause>();
             for (FailCause fc : values()) {
-                sErrorCodeToFailCauseMap.put(fc.ordinal(), fc);
+                sErrorCodeToFailCauseMap.put(fc.getErrorCode(), fc);
             }
         }
 
@@ -227,7 +228,6 @@
         mId = id;
         mRetryMgr = rm;
         this.cid = -1;
-        clearSettings();
 
         setDbg(false);
         addState(mDefaultState);
@@ -290,7 +290,7 @@
             lastFailTime = timeStamp;
             AsyncResult.forMessage(connectionCompletedMsg, cause, new Exception());
         }
-        if (DBG) log("notifyConnection at " + timeStamp + " cause=" + cause);
+        if (DBG) log("notifyConnectionCompleted at " + timeStamp + " cause=" + cause);
 
         connectionCompletedMsg.sendToTarget();
     }
@@ -301,16 +301,17 @@
      * @param dp is the DisconnectParams.
      */
     private void notifyDisconnectCompleted(DisconnectParams dp) {
-        if (DBG) log("NotifyDisconnectCompleted");
+        if (VDBG) log("NotifyDisconnectCompleted");
 
         if (dp.onCompletedMsg != null) {
             Message msg = dp.onCompletedMsg;
-            log(String.format("msg=%s msg.obj=%s", msg.toString(),
+            if (VDBG) {
+                log(String.format("msg=%s msg.obj=%s", msg.toString(),
                     ((msg.obj instanceof String) ? (String) msg.obj : "<no-reason>")));
+            }
             AsyncResult.forMessage(msg);
             msg.sendToTarget();
         }
-        clearSettings();
         if (DBG) log("NotifyDisconnectCompleted DisconnectParams=" + dp);
     }
 
@@ -472,7 +473,7 @@
             result = DataCallState.SetupResult.ERR_RilError;
             result.mFailCause = FailCause.fromInt(response.status);
         } else {
-            log("onSetupConnectionCompleted received DataCallState: " + response);
+            if (DBG) log("onSetupConnectionCompleted received DataCallState: " + response);
             cid = response.cid;
             // set link properties based on data call response
             result = setLinkProperties(response, mLinkProperties);
@@ -558,53 +559,53 @@
             switch (msg.what) {
                 case AsyncChannel.CMD_CHANNEL_FULL_CONNECTION: {
                     if (mAc != null) {
-                        log("Disconnecting to previous connection mAc=" + mAc);
+                        if (VDBG) log("Disconnecting to previous connection mAc=" + mAc);
                         mAc.replyToMessage(msg, AsyncChannel.CMD_CHANNEL_FULLY_CONNECTED,
                                 AsyncChannel.STATUS_FULL_CONNECTION_REFUSED_ALREADY_CONNECTED);
                     } else {
                         mAc = new AsyncChannel();
                         mAc.connected(null, getHandler(), msg.replyTo);
-                        log("DcDefaultState: FULL_CONNECTION reply connected");
+                        if (VDBG) log("DcDefaultState: FULL_CONNECTION reply connected");
                         mAc.replyToMessage(msg, AsyncChannel.CMD_CHANNEL_FULLY_CONNECTED,
                                 AsyncChannel.STATUS_SUCCESSFUL, mId, "hi");
                     }
                     break;
                 }
                 case AsyncChannel.CMD_CHANNEL_DISCONNECT: {
-                    log("CMD_CHANNEL_DISCONNECT");
+                    if (VDBG) log("CMD_CHANNEL_DISCONNECT");
                     mAc.disconnect();
                     break;
                 }
                 case AsyncChannel.CMD_CHANNEL_DISCONNECTED: {
-                    log("CMD_CHANNEL_DISCONNECTED");
+                    if (VDBG) log("CMD_CHANNEL_DISCONNECTED");
                     mAc = null;
                     break;
                 }
                 case DataConnectionAc.REQ_IS_INACTIVE: {
                     boolean val = getCurrentState() == mInactiveState;
-                    log("REQ_IS_INACTIVE  isInactive=" + val);
+                    if (VDBG) log("REQ_IS_INACTIVE  isInactive=" + val);
                     mAc.replyToMessage(msg, DataConnectionAc.RSP_IS_INACTIVE, val ? 1 : 0);
                     break;
                 }
                 case DataConnectionAc.REQ_GET_CID: {
-                    log("REQ_GET_CID  cid=" + cid);
+                    if (VDBG) log("REQ_GET_CID  cid=" + cid);
                     mAc.replyToMessage(msg, DataConnectionAc.RSP_GET_CID, cid);
                     break;
                 }
                 case DataConnectionAc.REQ_GET_APNSETTING: {
-                    log("REQ_GET_APNSETTING  apnSetting=" + mApn);
+                    if (VDBG) log("REQ_GET_APNSETTING  apnSetting=" + mApn);
                     mAc.replyToMessage(msg, DataConnectionAc.RSP_GET_APNSETTING, mApn);
                     break;
                 }
                 case DataConnectionAc.REQ_GET_LINK_PROPERTIES: {
                     LinkProperties lp = new LinkProperties(mLinkProperties);
-                    log("REQ_GET_LINK_PROPERTIES linkProperties" + lp);
+                    if (VDBG) log("REQ_GET_LINK_PROPERTIES linkProperties" + lp);
                     mAc.replyToMessage(msg, DataConnectionAc.RSP_GET_LINK_PROPERTIES, lp);
                     break;
                 }
                 case DataConnectionAc.REQ_SET_LINK_PROPERTIES_HTTP_PROXY: {
                     ProxyProperties proxy = (ProxyProperties) msg.obj;
-                    log("REQ_SET_LINK_PROPERTIES_HTTP_PROXY proxy=" + proxy);
+                    if (VDBG) log("REQ_SET_LINK_PROPERTIES_HTTP_PROXY proxy=" + proxy);
                     mLinkProperties.setHttpProxy(proxy);
                     mAc.replyToMessage(msg, DataConnectionAc.RSP_SET_LINK_PROPERTIES_HTTP_PROXY);
                     break;
@@ -612,7 +613,7 @@
                 case DataConnectionAc.REQ_UPDATE_LINK_PROPERTIES_DATA_CALL_STATE: {
                     DataCallState newState = (DataCallState) msg.obj;
                     DataConnectionAc.LinkPropertyChangeAction action = updateLinkProperty(newState);
-                    if (DBG) {
+                    if (VDBG) {
                         log("REQ_UPDATE_LINK_PROPERTIES_DATA_CALL_STATE action="
                             + action + " newState=" + newState);
                     }
@@ -623,18 +624,17 @@
                 }
                 case DataConnectionAc.REQ_GET_LINK_CAPABILITIES: {
                     LinkCapabilities lc = new LinkCapabilities(mCapabilities);
-                    log("REQ_GET_LINK_CAPABILITIES linkCapabilities" + lc);
+                    if (VDBG) log("REQ_GET_LINK_CAPABILITIES linkCapabilities" + lc);
                     mAc.replyToMessage(msg, DataConnectionAc.RSP_GET_LINK_CAPABILITIES, lc);
                     break;
                 }
                 case DataConnectionAc.REQ_RESET:
-                    if (DBG) log("DcDefaultState: msg.what=REQ_RESET");
-                    clearSettings();
+                    if (VDBG) log("DcDefaultState: msg.what=REQ_RESET");
                     mAc.replyToMessage(msg, DataConnectionAc.RSP_RESET);
                     transitionTo(mInactiveState);
                     break;
                 case DataConnectionAc.REQ_GET_REFCOUNT: {
-                    log("REQ_GET_REFCOUNT  refCount=" + mRefCount);
+                    if (VDBG) log("REQ_GET_REFCOUNT  refCount=" + mRefCount);
                     mAc.replyToMessage(msg, DataConnectionAc.RSP_GET_REFCOUNT, mRefCount);
                     break;
                 }
@@ -666,7 +666,8 @@
 
                 default:
                     if (DBG) {
-                        log("DcDefaultState: shouldn't happen but ignore msg.what=" + msg.what);
+                        log("DcDefaultState: shouldn't happen but ignore msg.what=0x" +
+                                Integer.toHexString(msg.what));
                     }
                     break;
             }
@@ -685,13 +686,13 @@
         private DisconnectParams mDisconnectParams = null;
 
         public void setEnterNotificationParams(ConnectionParams cp, FailCause cause) {
-            log("DcInactiveState: setEnterNoticationParams cp,cause");
+            if (VDBG) log("DcInactiveState: setEnterNoticationParams cp,cause");
             mConnectionParams = cp;
             mFailCause = cause;
         }
 
         public void setEnterNotificationParams(DisconnectParams dp) {
-          log("DcInactiveState: setEnterNoticationParams dp");
+            if (VDBG) log("DcInactiveState: setEnterNoticationParams dp");
             mDisconnectParams = dp;
         }
 
@@ -707,13 +708,14 @@
              * call to isInactive.
              */
             if ((mConnectionParams != null) && (mFailCause != null)) {
-                log("DcInactiveState: enter notifyConnectCompleted");
+                if (VDBG) log("DcInactiveState: enter notifyConnectCompleted");
                 notifyConnectCompleted(mConnectionParams, mFailCause);
             }
             if (mDisconnectParams != null) {
-              log("DcInactiveState: enter notifyDisconnectCompleted");
+                if (VDBG) log("DcInactiveState: enter notifyDisconnectCompleted");
                 notifyDisconnectCompleted(mDisconnectParams);
             }
+            clearSettings();
         }
 
         @Override
@@ -751,7 +753,10 @@
                     break;
 
                 default:
-                    if (DBG) log("DcInactiveState nothandled msg.what=" + msg.what);
+                    if (VDBG) {
+                        log("DcInactiveState nothandled msg.what=0x" +
+                                Integer.toHexString(msg.what));
+                    }
                     retVal = NOT_HANDLED;
                     break;
             }
@@ -856,7 +861,10 @@
                     break;
 
                 default:
-                    if (DBG) log("DcActivatingState not handled msg.what=" + msg.what);
+                    if (VDBG) {
+                        log("DcActivatingState not handled msg.what=0x" +
+                                Integer.toHexString(msg.what));
+                    }
                     retVal = NOT_HANDLED;
                     break;
             }
@@ -873,7 +881,7 @@
         private FailCause mFailCause = null;
 
         public void setEnterNotificationParams(ConnectionParams cp, FailCause cause) {
-            log("DcInactiveState: setEnterNoticationParams cp,cause");
+            if (VDBG) log("DcInactiveState: setEnterNoticationParams cp,cause");
             mConnectionParams = cp;
             mFailCause = cause;
         }
@@ -887,7 +895,7 @@
              * call to isActive.
              */
             if ((mConnectionParams != null) && (mFailCause != null)) {
-                log("DcActiveState: enter notifyConnectCompleted");
+                if (VDBG) log("DcActiveState: enter notifyConnectCompleted");
                 notifyConnectCompleted(mConnectionParams, mFailCause);
             }
         }
@@ -930,7 +938,10 @@
                     break;
 
                 default:
-                    if (DBG) log("DcActiveState nothandled msg.what=" + msg.what);
+                    if (VDBG) {
+                        log("DcActiveState not handled msg.what=0x" +
+                                Integer.toHexString(msg.what));
+                    }
                     retVal = NOT_HANDLED;
                     break;
             }
@@ -972,7 +983,10 @@
                     break;
 
                 default:
-                    if (DBG) log("DcDisconnectingState not handled msg.what=" + msg.what);
+                    if (VDBG) {
+                        log("DcDisconnectingState not handled msg.what=0x" +
+                                Integer.toHexString(msg.what));
+                    }
                     retVal = NOT_HANDLED;
                     break;
             }
@@ -1014,9 +1028,9 @@
                     break;
 
                 default:
-                    if (DBG) {
-                        log("DcDisconnectionErrorCreatingConnection not handled msg.what="
-                                + msg.what);
+                    if (VDBG) {
+                        log("DcDisconnectionErrorCreatingConnection not handled msg.what=0x"
+                                + Integer.toHexString(msg.what));
                     }
                     retVal = NOT_HANDLED;
                     break;
diff --git a/telephony/java/com/android/internal/telephony/DataConnectionAc.java b/telephony/java/com/android/internal/telephony/DataConnectionAc.java
index a0d9b0f..62b90ae 100644
--- a/telephony/java/com/android/internal/telephony/DataConnectionAc.java
+++ b/telephony/java/com/android/internal/telephony/DataConnectionAc.java
@@ -28,7 +28,7 @@
  * AsyncChannel to a DataConnection
  */
 public class DataConnectionAc extends AsyncChannel {
-    private static final boolean DBG = true;
+    private static final boolean DBG = false;
     private String mLogTag;
 
     public DataConnection dataConnection;
@@ -367,7 +367,7 @@
         if ((response != null) && (response.what == RSP_RESET)) {
             if (DBG) log("restSync ok");
         } else {
-            if (DBG) log("restSync error response=" + response);
+            log("restSync error response=" + response);
         }
     }
 
diff --git a/telephony/java/com/android/internal/telephony/DataConnectionTracker.java b/telephony/java/com/android/internal/telephony/DataConnectionTracker.java
index 5ddfcd1..977b412 100644
--- a/telephony/java/com/android/internal/telephony/DataConnectionTracker.java
+++ b/telephony/java/com/android/internal/telephony/DataConnectionTracker.java
@@ -145,8 +145,10 @@
 
     public static final String APN_TYPE_KEY = "apnType";
 
-    /** Delay between APN attempts */
-    protected static final int APN_DELAY_MILLIS = 5000;
+    /** Delay between APN attempts.
+        Note the property override mechanism is there just for testing purpose only. */
+    protected static final int APN_DELAY_MILLIS =
+                                SystemProperties.getInt("persist.radio.apn_delay", 5000);
 
     // responds to the setInternalDataEnabled call - used internally to turn off data
     // for example during emergency calls
@@ -304,7 +306,7 @@
                 mIsScreenOn = false;
                 stopNetStatPoll();
                 startNetStatPoll();
-            } else if (action.equals(getActionIntentReconnectAlarm())) {
+            } else if (action.startsWith(getActionIntentReconnectAlarm())) {
                 log("Reconnect alarm. Previous state was " + mState);
                 onActionIntentReconnectAlarm(intent);
 
@@ -509,7 +511,6 @@
     protected abstract void onVoiceCallEnded();
     protected abstract void onCleanUpConnection(boolean tearDown, int apnId, String reason);
     protected abstract void onCleanUpAllConnections(String cause);
-    protected abstract boolean isDataPossible();
     protected abstract boolean isDataPossible(String apnType);
 
     @Override
@@ -752,7 +753,7 @@
     protected void notifyDataAvailability(String reason) {
         // note that we either just turned all off because we lost availability
         // or all were off and could now go on, so only have off apns to worry about
-        notifyOffApnsOfAvailability(reason, isDataPossible());
+        notifyOffApnsOfAvailability(reason, isDataPossible(Phone.APN_TYPE_DEFAULT));
     }
 
     public boolean isApnTypeEnabled(String apnType) {
@@ -968,11 +969,7 @@
         sendMessage(msg);
     }
 
-    public boolean isAnyActiveDataConnections() {
-        // TODO: Remember if there are any connected or
-        // loop asking each DC/APN?
-        return true;
-    }
+    public abstract boolean isAnyActiveDataConnections();
 
     protected void onSetDataEnabled(boolean enable) {
         boolean prevEnabled = getAnyDataEnabled();
diff --git a/telephony/java/com/android/internal/telephony/GsmAlphabet.java b/telephony/java/com/android/internal/telephony/GsmAlphabet.java
index c7c91e4..a3f4f1f 100644
--- a/telephony/java/com/android/internal/telephony/GsmAlphabet.java
+++ b/telephony/java/com/android/internal/telephony/GsmAlphabet.java
@@ -86,6 +86,8 @@
      * GSM_EXTENDED_ESCAPE if this character is in the extended table.
      * In this case, you must call charToGsmExtended() for the value
      * that should follow GSM_EXTENDED_ESCAPE in the GSM alphabet string.
+     * @param c the character to convert
+     * @return the GSM 7 bit table index for the specified character
      */
     public static int
     charToGsm(char c) {
@@ -99,12 +101,15 @@
 
     /**
      * Converts a char to a GSM 7 bit table index.
+     * Returns GSM_EXTENDED_ESCAPE if this character is in the extended table.
+     * In this case, you must call charToGsmExtended() for the value that
+     * should follow GSM_EXTENDED_ESCAPE in the GSM alphabet string.
+     *
+     * @param c the character to convert
      * @param throwException If true, throws EncodeException on invalid char.
      *   If false, returns GSM alphabet ' ' char.
-     *
-     * Returns GSM_EXTENDED_ESCAPE if this character is in the extended table
-     * In this case, you must call charToGsmExtended() for the value that
-     * should follow GSM_EXTENDED_ESCAPE in the GSM alphabet string
+     * @throws EncodeException encode error when throwException is true
+     * @return the GSM 7 bit table index for the specified character
      */
     public static int
     charToGsm(char c, boolean throwException) throws EncodeException {
@@ -133,6 +138,8 @@
      * Converts a char to an extended GSM 7 bit table index.
      * Extended chars should be escaped with GSM_EXTENDED_ESCAPE.
      * Returns ' ' in GSM alphabet if there's no possible match.
+     * @param c the character to convert
+     * @return the GSM 7 bit extended table index for the specified character
      */
     public static int
     charToGsmExtended(char c) {
@@ -155,6 +162,9 @@
      * gsmExtendedToChar().
      *
      * If an unmappable value is passed (one greater than 127), ' ' is returned.
+     *
+     * @param gsmChar the GSM 7 bit table index to convert
+     * @return the decoded character
      */
     public static char
     gsmToChar(int gsmChar) {
@@ -174,6 +184,9 @@
      *
      * If an unmappable value is passed, the character from the GSM 7 bit
      * default table will be used (table 6.2.1.1 of TS 23.038).
+     *
+     * @param gsmChar the GSM 7 bit extended table index to convert
+     * @return the decoded character
      */
     public static char
     gsmExtendedToChar(int gsmChar) {
@@ -244,6 +257,26 @@
      * septets.
      *
      * @param data the data string to encode
+     * @return the encoded string
+     * @throws EncodeException if String is too large to encode
+     */
+    public static byte[] stringToGsm7BitPacked(String data)
+            throws EncodeException {
+        return stringToGsm7BitPacked(data, 0, true, 0, 0);
+    }
+
+    /**
+     * Converts a String into a byte array containing
+     * the 7-bit packed GSM Alphabet representation of the string.
+     *
+     * Unencodable chars are encoded as spaces
+     *
+     * Byte 0 in the returned byte array is the count of septets used
+     * The returned byte array is the minimum size required to store
+     * the packed septets. The returned array cannot contain more than 255
+     * septets.
+     *
+     * @param data the data string to encode
      * @param languageTable the 7 bit language table, or 0 for the default GSM alphabet
      * @param languageShiftTable the 7 bit single shift language table, or 0 for the default
      *     GSM extension table
@@ -449,6 +482,11 @@
      *
      * Field may be padded with trailing 0xff's. The decode stops
      * at the first 0xff encountered.
+     *
+     * @param data the byte array to decode
+     * @param offset array offset for the first character to decode
+     * @param length the number of bytes to decode
+     * @return the decoded string
      */
     public static String
     gsm8BitUnpackedToString(byte[] data, int offset, int length) {
@@ -532,6 +570,8 @@
     /**
      * Convert a string into an 8-bit unpacked GSM alphabet byte array.
      * Always uses GSM default 7-bit alphabet and extension table.
+     * @param s the string to encode
+     * @return the 8-bit GSM encoded byte array for the string
      */
     public static byte[]
     stringToGsm8BitPacked(String s) {
@@ -550,11 +590,13 @@
 
     /**
      * Write a String into a GSM 8-bit unpacked field of
-     * @param length size at @param offset in @param dest
-     *
      * Field is padded with 0xff's, string is truncated if necessary
+     *
+     * @param s the string to encode
+     * @param dest the destination byte array
+     * @param offset the starting offset for the encoded string
+     * @param length the maximum number of bytes to write
      */
-
     public static void
     stringToGsm8BitUnpackedField(String s, byte dest[], int offset, int length) {
         int outByteIndex = offset;
@@ -596,6 +638,8 @@
     /**
      * Returns the count of 7-bit GSM alphabet characters
      * needed to represent this character. Counts unencodable char as 1 septet.
+     * @param c the character to examine
+     * @return the number of septets for this character
      */
     public static int
     countGsmSeptets(char c) {
@@ -610,8 +654,11 @@
     /**
      * Returns the count of 7-bit GSM alphabet characters
      * needed to represent this character using the default 7 bit GSM alphabet.
+     * @param c the character to examine
      * @param throwsException If true, throws EncodeException if unencodable
-     * char. Otherwise, counts invalid char as 1 septet
+     * char. Otherwise, counts invalid char as 1 septet.
+     * @return the number of septets for this character
+     * @throws EncodeException the character can't be encoded and throwsException is true
      */
     public static int
     countGsmSeptets(char c, boolean throwsException) throws EncodeException {
diff --git a/telephony/java/com/android/internal/telephony/ISms.aidl b/telephony/java/com/android/internal/telephony/ISms.aidl
index 90de5e1..735f986 100644
--- a/telephony/java/com/android/internal/telephony/ISms.aidl
+++ b/telephony/java/com/android/internal/telephony/ISms.aidl
@@ -170,4 +170,32 @@
      */
     boolean disableCellBroadcast(int messageIdentifier);
 
+    /**
+     * Enable reception of cell broadcast (SMS-CB) messages with the given
+     * message identifier range. Note that if two different clients enable
+     * a message identifier range, they must both disable it for the device
+     * to stop receiving those messages.
+     *
+     * @param startMessageId first message identifier as specified in TS 23.041
+     * @param endMessageId last message identifier as specified in TS 23.041
+     * @return true if successful, false otherwise
+     *
+     * @see #disableCellBroadcastRange(int, int)
+     */
+    boolean enableCellBroadcastRange(int startMessageId, int endMessageId);
+
+    /**
+     * Disable reception of cell broadcast (SMS-CB) messages with the given
+     * message identifier range. Note that if two different clients enable
+     * a message identifier range, they must both disable it for the device
+     * to stop receiving those messages.
+     *
+     * @param startMessageId first message identifier as specified in TS 23.041
+     * @param endMessageId last message identifier as specified in TS 23.041
+     * @return true if successful, false otherwise
+     *
+     * @see #enableCellBroadcastRange(int, int)
+     */
+    boolean disableCellBroadcastRange(int startMessageId, int endMessageId);
+
 }
diff --git a/telephony/java/com/android/internal/telephony/ITelephony.aidl b/telephony/java/com/android/internal/telephony/ITelephony.aidl
index da233cc..19441cd 100644
--- a/telephony/java/com/android/internal/telephony/ITelephony.aidl
+++ b/telephony/java/com/android/internal/telephony/ITelephony.aidl
@@ -145,6 +145,15 @@
     boolean supplyPin(String pin);
 
     /**
+     * Supply puk to unlock the SIM and set SIM pin to new pin.
+     *  Blocks until a result is determined.
+     * @param puk The puk to check.
+     *        pin The new pin to be set in SIM
+     * @return whether the operation was a success.
+     */
+    boolean supplyPuk(String puk, String pin);
+
+    /**
      * Handles PIN MMI commands (PIN/PIN2/PUK/PUK2), which are initiated
      * without SEND (so <code>dial</code> is not appropriate).
      *
@@ -254,7 +263,7 @@
       * Returns the network type
       */
     int getNetworkType();
-    
+
     /**
      * Return true if an ICC card is present
      */
diff --git a/telephony/java/com/android/internal/telephony/IccCard.java b/telephony/java/com/android/internal/telephony/IccCard.java
index a516b49..02617c8 100644
--- a/telephony/java/com/android/internal/telephony/IccCard.java
+++ b/telephony/java/com/android/internal/telephony/IccCard.java
@@ -84,6 +84,9 @@
     static public final String INTENT_VALUE_LOCKED_ON_PUK = "PUK";
     /* NETWORK means ICC is locked on NETWORK PERSONALIZATION */
     static public final String INTENT_VALUE_LOCKED_NETWORK = "NETWORK";
+    /* PERM_DISABLED means ICC is permanently disabled due to puk fails */
+    static public final String INTENT_VALUE_ABSENT_ON_PERM_DISABLED = "PERM_DISABLED";
+
 
     protected static final int EVENT_ICC_LOCKED_OR_ABSENT = 1;
     private static final int EVENT_GET_ICC_STATUS_DONE = 2;
@@ -112,7 +115,8 @@
         PUK_REQUIRED,
         NETWORK_LOCKED,
         READY,
-        NOT_READY;
+        NOT_READY,
+        PERM_DISABLED;
 
         public boolean isPinLocked() {
             return ((this == PIN_REQUIRED) || (this == PUK_REQUIRED));
@@ -120,7 +124,8 @@
 
         public boolean iccCardExist() {
             return ((this == PIN_REQUIRED) || (this == PUK_REQUIRED)
-                    || (this == NETWORK_LOCKED) || (this == READY));
+                    || (this == NETWORK_LOCKED) || (this == READY)
+                    || (this == PERM_DISABLED));
         }
     }
 
@@ -416,6 +421,7 @@
         boolean transitionedIntoPinLocked;
         boolean transitionedIntoAbsent;
         boolean transitionedIntoNetworkLocked;
+        boolean transitionedIntoPermBlocked;
         boolean isIccCardRemoved;
         boolean isIccCardAdded;
 
@@ -434,6 +440,8 @@
         transitionedIntoAbsent = (oldState != State.ABSENT && newState == State.ABSENT);
         transitionedIntoNetworkLocked = (oldState != State.NETWORK_LOCKED
                 && newState == State.NETWORK_LOCKED);
+        transitionedIntoPermBlocked = (oldState != State.PERM_DISABLED
+                && newState == State.PERM_DISABLED);
         isIccCardRemoved = (oldState != null &&
                         oldState.iccCardExist() && newState == State.ABSENT);
         isIccCardAdded = (oldState == State.ABSENT &&
@@ -454,6 +462,10 @@
             mNetworkLockedRegistrants.notifyRegistrants();
             broadcastIccStateChangedIntent(INTENT_VALUE_ICC_LOCKED,
                   INTENT_VALUE_LOCKED_NETWORK);
+        } else if (transitionedIntoPermBlocked) {
+            if (mDbg) log("Notify SIM permanently disabled.");
+            broadcastIccStateChangedIntent(INTENT_VALUE_ICC_ABSENT,
+                    INTENT_VALUE_ABSENT_ON_PERM_DISABLED);
         }
 
         if (isIccCardRemoved) {
@@ -722,52 +734,91 @@
             currentRadioState == RadioState.RUIM_READY ||
             (currentRadioState == RadioState.NV_READY &&
                     (mPhone.getLteOnCdmaMode() == Phone.LTE_ON_CDMA_TRUE))) {
-            int index;
+
+            State csimState =
+                getAppState(mIccCardStatus.getCdmaSubscriptionAppIndex());
+            State usimState =
+                getAppState(mIccCardStatus.getGsmUmtsSubscriptionAppIndex());
+
+            if(mDbg) log("USIM=" + usimState + " CSIM=" + csimState);
+
+            if (mPhone.getLteOnCdmaMode() == Phone.LTE_ON_CDMA_TRUE) {
+                // UICC card contains both USIM and CSIM
+                // Return consolidated status
+                return getConsolidatedState(csimState, usimState, csimState);
+            }
 
             // check for CDMA radio technology
             if (currentRadioState == RadioState.RUIM_LOCKED_OR_ABSENT ||
                 currentRadioState == RadioState.RUIM_READY) {
-                index = mIccCardStatus.getCdmaSubscriptionAppIndex();
+                return csimState;
             }
-            else {
-                index = mIccCardStatus.getGsmUmtsSubscriptionAppIndex();
-            }
-
-            IccCardApplication app;
-            if (index >= 0 && index < IccCardStatus.CARD_MAX_APPS) {
-                app = mIccCardStatus.getApplication(index);
-            } else {
-                Log.e(mLogTag, "[IccCard] Invalid Subscription Application index:" + index);
-                return IccCard.State.ABSENT;
-            }
-
-            if (app == null) {
-                Log.e(mLogTag, "[IccCard] Subscription Application in not present");
-                return IccCard.State.ABSENT;
-            }
-
-            // check if PIN required
-            if (app.app_state.isPinRequired()) {
-                return IccCard.State.PIN_REQUIRED;
-            }
-            if (app.app_state.isPukRequired()) {
-                return IccCard.State.PUK_REQUIRED;
-            }
-            if (app.app_state.isSubscriptionPersoEnabled()) {
-                return IccCard.State.NETWORK_LOCKED;
-            }
-            if (app.app_state.isAppReady()) {
-                return IccCard.State.READY;
-            }
-            if (app.app_state.isAppNotReady()) {
-                return IccCard.State.NOT_READY;
-            }
-            return IccCard.State.NOT_READY;
+            return usimState;
         }
 
         return IccCard.State.ABSENT;
     }
 
+    private State getAppState(int appIndex) {
+        IccCardApplication app;
+        if (appIndex >= 0 && appIndex < IccCardStatus.CARD_MAX_APPS) {
+            app = mIccCardStatus.getApplication(appIndex);
+        } else {
+            Log.e(mLogTag, "[IccCard] Invalid Subscription Application index:" + appIndex);
+            return IccCard.State.ABSENT;
+        }
+
+        if (app == null) {
+            Log.e(mLogTag, "[IccCard] Subscription Application in not present");
+            return IccCard.State.ABSENT;
+        }
+
+        // check if PIN required
+        if (app.pin1.isPermBlocked()) {
+            return IccCard.State.PERM_DISABLED;
+        }
+        if (app.app_state.isPinRequired()) {
+            return IccCard.State.PIN_REQUIRED;
+        }
+        if (app.app_state.isPukRequired()) {
+            return IccCard.State.PUK_REQUIRED;
+        }
+        if (app.app_state.isSubscriptionPersoEnabled()) {
+            return IccCard.State.NETWORK_LOCKED;
+        }
+        if (app.app_state.isAppReady()) {
+            return IccCard.State.READY;
+        }
+        if (app.app_state.isAppNotReady()) {
+            return IccCard.State.NOT_READY;
+        }
+        return IccCard.State.NOT_READY;
+    }
+
+    private State getConsolidatedState(State left, State right, State preferredState) {
+        // Check if either is absent.
+        if (right == IccCard.State.ABSENT) return left;
+        if (left == IccCard.State.ABSENT) return right;
+
+        // Only if both are ready, return ready
+        if ((left == IccCard.State.READY) && (right == IccCard.State.READY)) {
+            return State.READY;
+        }
+
+        // Case one is ready, but the other is not.
+        if (((right == IccCard.State.NOT_READY) && (left == IccCard.State.READY)) ||
+            ((left == IccCard.State.NOT_READY) && (right == IccCard.State.READY))) {
+            return IccCard.State.NOT_READY;
+        }
+
+        // At this point, the other state is assumed to be one of locked state
+        if (right == IccCard.State.NOT_READY) return left;
+        if (left == IccCard.State.NOT_READY) return right;
+
+        // At this point, FW currently just assumes the status will be
+        // consistent across the applications...
+        return preferredState;
+    }
 
     public boolean isApplicationOnIcc(IccCardApplication.AppType type) {
         if (mIccCardStatus == null) return false;
diff --git a/telephony/java/com/android/internal/telephony/IccCardApplication.java b/telephony/java/com/android/internal/telephony/IccCardApplication.java
index 4cf21ee..abb740e 100644
--- a/telephony/java/com/android/internal/telephony/IccCardApplication.java
+++ b/telephony/java/com/android/internal/telephony/IccCardApplication.java
@@ -16,6 +16,8 @@
 
 package com.android.internal.telephony;
 
+import com.android.internal.telephony.IccCardStatus.PinState;
+
 
 /**
  * See also RIL_AppStatus in include/telephony/ril.h
@@ -104,8 +106,8 @@
     public String         app_label;
     // applicable to USIM and CSIM
     public int            pin1_replaced;
-    public int            pin1;
-    public int            pin2;
+    public PinState            pin1;
+    public PinState            pin2;
 
     AppType AppTypeFromRILInt(int type) {
         AppType newType;
@@ -177,4 +179,48 @@
         return newSubState;
     }
 
+    PinState PinStateFromRILInt(int state) {
+        PinState newPinState;
+        switch(state) {
+            case 0:
+                newPinState = PinState.PINSTATE_UNKNOWN;
+                break;
+            case 1:
+                newPinState = PinState.PINSTATE_ENABLED_NOT_VERIFIED;
+                break;
+            case 2:
+                newPinState = PinState.PINSTATE_ENABLED_VERIFIED;
+                break;
+            case 3:
+                newPinState = PinState.PINSTATE_DISABLED;
+                break;
+            case 4:
+                newPinState = PinState.PINSTATE_ENABLED_BLOCKED;
+                break;
+            case 5:
+                newPinState = PinState.PINSTATE_ENABLED_PERM_BLOCKED;
+                break;
+            default:
+                throw new RuntimeException("Unrecognized RIL_PinState: " + state);
+        }
+        return newPinState;
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+
+        sb.append("{").append(app_type).append(",").append(app_state);
+        if (app_state == AppState.APPSTATE_SUBSCRIPTION_PERSO) {
+            sb.append(",").append(perso_substate);
+        }
+        if (app_type == AppType.APPTYPE_CSIM ||
+                app_type == AppType.APPTYPE_USIM ||
+                app_type == AppType.APPTYPE_ISIM) {
+            sb.append(",pin1=").append(pin1);
+            sb.append(",pin2=").append(pin2);
+        }
+        sb.append("}");
+        return sb.toString();
+    }
 }
diff --git a/telephony/java/com/android/internal/telephony/IccCardStatus.java b/telephony/java/com/android/internal/telephony/IccCardStatus.java
index 7199616..c751a21 100644
--- a/telephony/java/com/android/internal/telephony/IccCardStatus.java
+++ b/telephony/java/com/android/internal/telephony/IccCardStatus.java
@@ -42,7 +42,19 @@
         PINSTATE_ENABLED_VERIFIED,
         PINSTATE_DISABLED,
         PINSTATE_ENABLED_BLOCKED,
-        PINSTATE_ENABLED_PERM_BLOCKED
+        PINSTATE_ENABLED_PERM_BLOCKED;
+
+        boolean isPermBlocked() {
+            return this == PINSTATE_ENABLED_PERM_BLOCKED;
+        }
+
+        boolean isPinRequired() {
+            return this == PINSTATE_ENABLED_NOT_VERIFIED;
+        }
+
+        boolean isPukRequired() {
+            return this == PINSTATE_ENABLED_BLOCKED;
+        }
     }
 
     private CardState  mCardState;
@@ -144,4 +156,33 @@
         return mApplications.get(index);
     }
 
+    @Override
+    public String toString() {
+        IccCardApplication app;
+
+        StringBuilder sb = new StringBuilder();
+        sb.append("IccCardState {").append(mCardState).append(",")
+        .append(mUniversalPinState)
+        .append(",num_apps=").append(mNumApplications)
+        .append(",gsm_id=").append(mGsmUmtsSubscriptionAppIndex);
+        if (mGsmUmtsSubscriptionAppIndex >=0
+                && mGsmUmtsSubscriptionAppIndex <CARD_MAX_APPS) {
+            app = getApplication(mGsmUmtsSubscriptionAppIndex);
+            sb.append(app == null ? "null" : app);
+        }
+
+        sb.append(",cmda_id=").append(mCdmaSubscriptionAppIndex);
+        if (mCdmaSubscriptionAppIndex >=0
+                && mCdmaSubscriptionAppIndex <CARD_MAX_APPS) {
+            app = getApplication(mCdmaSubscriptionAppIndex);
+            sb.append(app == null ? "null" : app);
+        }
+
+        sb.append(",ism_id=").append(mImsSubscriptionAppIndex);
+
+        sb.append("}");
+
+        return sb.toString();
+    }
+
 }
diff --git a/telephony/java/com/android/internal/telephony/IccConstants.java b/telephony/java/com/android/internal/telephony/IccConstants.java
index b40f945..1ba6dfe 100644
--- a/telephony/java/com/android/internal/telephony/IccConstants.java
+++ b/telephony/java/com/android/internal/telephony/IccConstants.java
@@ -58,6 +58,16 @@
     static final int EF_CST = 0x6f32;
     static final int EF_RUIM_SPN =0x6F41;
 
+    // ETSI TS.102.221
+    static final int EF_PL = 0x2F05;
+    // 3GPP2 C.S0065
+    static final int EF_CSIM_LI = 0x6F3A;
+    static final int EF_CSIM_SPN =0x6F41;
+    static final int EF_CSIM_MDN = 0x6F44;
+    static final int EF_CSIM_IMSIM = 0x6F22;
+    static final int EF_CSIM_CDMAHOME = 0x6F28;
+    static final int EF_CSIM_EPRL = 0x6F5A;
+
     //ISIM access
     static final int EF_IMPU = 0x6f04;
     static final int EF_IMPI = 0x6f02;
diff --git a/telephony/java/com/android/internal/telephony/IccFileHandler.java b/telephony/java/com/android/internal/telephony/IccFileHandler.java
index 92ddd2c..93b9b79 100644
--- a/telephony/java/com/android/internal/telephony/IccFileHandler.java
+++ b/telephony/java/com/android/internal/telephony/IccFileHandler.java
@@ -529,6 +529,7 @@
             return MF_SIM + DF_TELECOM;
 
         case EF_ICCID:
+        case EF_PL:
             return MF_SIM;
         case EF_IMG:
             return MF_SIM + DF_TELECOM + DF_GRAPHICS;
diff --git a/telephony/java/com/android/internal/telephony/IccPhoneBookInterfaceManager.java b/telephony/java/com/android/internal/telephony/IccPhoneBookInterfaceManager.java
index 2f22d74..45562ca 100644
--- a/telephony/java/com/android/internal/telephony/IccPhoneBookInterfaceManager.java
+++ b/telephony/java/com/android/internal/telephony/IccPhoneBookInterfaceManager.java
@@ -24,6 +24,7 @@
 import android.os.ServiceManager;
 
 import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 /**
  * SimPhoneBookInterfaceManager to provide an inter-process communication to
@@ -63,14 +64,14 @@
                                     " total " + recordSize[1] +
                                     " #record " + recordSize[2]);
                         }
-                        mLock.notifyAll();
+                        notifyPending(ar);
                     }
                     break;
                 case EVENT_UPDATE_DONE:
                     ar = (AsyncResult) msg.obj;
                     synchronized (mLock) {
                         success = (ar.exception == null);
-                        mLock.notifyAll();
+                        notifyPending(ar);
                     }
                     break;
                 case EVENT_LOAD_DONE:
@@ -84,11 +85,20 @@
                                 records.clear();
                             }
                         }
-                        mLock.notifyAll();
+                        notifyPending(ar);
                     }
                     break;
             }
         }
+
+        private void notifyPending(AsyncResult ar) {
+            if (ar.userObj == null) {
+                return;
+            }
+            AtomicBoolean status = (AtomicBoolean) ar.userObj;
+            status.set(true);
+            mLock.notifyAll();
+        }
     };
 
     public IccPhoneBookInterfaceManager(PhoneBase phone) {
@@ -150,15 +160,12 @@
         synchronized(mLock) {
             checkThread();
             success = false;
-            Message response = mBaseHandler.obtainMessage(EVENT_UPDATE_DONE);
+            AtomicBoolean status = new AtomicBoolean(false);
+            Message response = mBaseHandler.obtainMessage(EVENT_UPDATE_DONE, status);
             AdnRecord oldAdn = new AdnRecord(oldTag, oldPhoneNumber);
             AdnRecord newAdn = new AdnRecord(newTag, newPhoneNumber);
             adnCache.updateAdnBySearch(efid, oldAdn, newAdn, pin2, response);
-            try {
-                mLock.wait();
-            } catch (InterruptedException e) {
-                logd("interrupted while trying to update by search");
-            }
+            waitForResult(status);
         }
         return success;
     }
@@ -197,14 +204,11 @@
         synchronized(mLock) {
             checkThread();
             success = false;
-            Message response = mBaseHandler.obtainMessage(EVENT_UPDATE_DONE);
+            AtomicBoolean status = new AtomicBoolean(false);
+            Message response = mBaseHandler.obtainMessage(EVENT_UPDATE_DONE, status);
             AdnRecord newAdn = new AdnRecord(newTag, newPhoneNumber);
             adnCache.updateAdnByIndex(efid, newAdn, index, pin2, response);
-            try {
-                mLock.wait();
-            } catch (InterruptedException e) {
-                logd("interrupted while trying to update by index");
-            }
+            waitForResult(status);
         }
         return success;
     }
@@ -243,15 +247,12 @@
 
         synchronized(mLock) {
             checkThread();
-            Message response = mBaseHandler.obtainMessage(EVENT_LOAD_DONE);
+            AtomicBoolean status = new AtomicBoolean(false);
+            Message response = mBaseHandler.obtainMessage(EVENT_LOAD_DONE, status);
             adnCache.requestLoadAllAdnLike(efid, adnCache.extensionEfForEf(efid), response);
-            try {
-                mLock.wait();
-            } catch (InterruptedException e) {
-                logd("interrupted while trying to load from the SIM");
-            }
+            waitForResult(status);
         }
-            return records;
+        return records;
     }
 
     protected void checkThread() {
@@ -265,6 +266,16 @@
         }
     }
 
+    protected void waitForResult(AtomicBoolean status) {
+        while (!status.get()) {
+            try {
+                mLock.wait();
+            } catch (InterruptedException e) {
+                logd("interrupted while trying to update by search");
+            }
+        }
+    }
+
     private int updateEfForIccType(int efid) {
         // Check if we are trying to read ADN records
         if (efid == IccConstants.EF_ADN) {
diff --git a/telephony/java/com/android/internal/telephony/IccRecords.java b/telephony/java/com/android/internal/telephony/IccRecords.java
index 10a3b69..3a27901 100644
--- a/telephony/java/com/android/internal/telephony/IccRecords.java
+++ b/telephony/java/com/android/internal/telephony/IccRecords.java
@@ -288,6 +288,16 @@
     }
 
     /**
+     * Indicates wether SIM is in provisioned state or not.
+     * Overridden only if SIM can be dynamically provisioned via OTA.
+     *
+     * @return true if provisioned
+     */
+    public boolean isProvisioned () {
+        return true;
+    }
+
+    /**
      * Write string to log file
      *
      * @param s is the string to write
diff --git a/telephony/java/com/android/internal/telephony/IccSmsInterfaceManager.java b/telephony/java/com/android/internal/telephony/IccSmsInterfaceManager.java
index 5fef6de..9763265 100644
--- a/telephony/java/com/android/internal/telephony/IccSmsInterfaceManager.java
+++ b/telephony/java/com/android/internal/telephony/IccSmsInterfaceManager.java
@@ -112,7 +112,7 @@
      */
     public void sendText(String destAddr, String scAddr,
             String text, PendingIntent sentIntent, PendingIntent deliveryIntent) {
-        mPhone.getContext().enforceCallingPermission(
+        mPhone.getContext().enforceCallingOrSelfPermission(
                 "android.permission.SEND_SMS",
                 "Sending SMS message");
         if (Log.isLoggable("SMS", Log.VERBOSE)) {
diff --git a/telephony/java/com/android/internal/telephony/IccSmsInterfaceManagerProxy.java b/telephony/java/com/android/internal/telephony/IccSmsInterfaceManagerProxy.java
index 5049249..54de508 100644
--- a/telephony/java/com/android/internal/telephony/IccSmsInterfaceManagerProxy.java
+++ b/telephony/java/com/android/internal/telephony/IccSmsInterfaceManagerProxy.java
@@ -76,4 +76,13 @@
         return mIccSmsInterfaceManager.disableCellBroadcast(messageIdentifier);
     }
 
+    public boolean enableCellBroadcastRange(int startMessageId, int endMessageId)
+            throws android.os.RemoteException {
+        return mIccSmsInterfaceManager.enableCellBroadcastRange(startMessageId, endMessageId);
+    }
+
+    public boolean disableCellBroadcastRange(int startMessageId, int endMessageId)
+            throws android.os.RemoteException {
+        return mIccSmsInterfaceManager.disableCellBroadcastRange(startMessageId, endMessageId);
+    }
 }
diff --git a/telephony/java/com/android/internal/telephony/IccUtils.java b/telephony/java/com/android/internal/telephony/IccUtils.java
index c3b0ffc..a966f76 100644
--- a/telephony/java/com/android/internal/telephony/IccUtils.java
+++ b/telephony/java/com/android/internal/telephony/IccUtils.java
@@ -63,6 +63,29 @@
         return ret.toString();
     }
 
+    /**
+     * Decode cdma byte into String.
+     */
+    public static String
+    cdmaBcdToString(byte[] data, int offset, int length) {
+        StringBuilder ret = new StringBuilder(length);
+
+        int count = 0;
+        for (int i = offset; count < length; i++) {
+            int v;
+            v = data[i] & 0xf;
+            if (v > 9)  v = 0;
+            ret.append((char)('0' + v));
+
+            if (++count == length) break;
+
+            v = (data[i] >> 4) & 0xf;
+            if (v > 9)  v = 0;
+            ret.append((char)('0' + v));
+            ++count;
+        }
+        return ret.toString();
+    }
 
     /**
      * Decodes a GSM-style BCD byte, returning an int ranging from 0-99.
diff --git a/telephony/java/com/android/internal/telephony/IntRangeManager.java b/telephony/java/com/android/internal/telephony/IntRangeManager.java
new file mode 100644
index 0000000..970bc44
--- /dev/null
+++ b/telephony/java/com/android/internal/telephony/IntRangeManager.java
@@ -0,0 +1,568 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.telephony;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+/**
+ * Clients can enable reception of SMS-CB messages for specific ranges of
+ * message identifiers (channels). This class keeps track of the currently
+ * enabled message identifiers and calls abstract methods to update the
+ * radio when the range of enabled message identifiers changes.
+ *
+ * An update is a call to {@link #startUpdate} followed by zero or more
+ * calls to {@link #addRange} followed by a call to {@link #finishUpdate}.
+ * Calls to {@link #enableRange} and {@link #disableRange} will perform
+ * an incremental update operation if the enabled ranges have changed.
+ * A full update operation (i.e. after a radio reset) can be performed
+ * by a call to {@link #updateRanges}.
+ *
+ * Clients are identified by String (the name associated with the User ID
+ * of the caller) so that a call to remove a range can be mapped to the
+ * client that enabled that range (or else rejected).
+ */
+public abstract class IntRangeManager {
+
+    /**
+     * Initial capacity for IntRange clients array list. There will be
+     * few cell broadcast listeners on a typical device, so this can be small.
+     */
+    private static final int INITIAL_CLIENTS_ARRAY_SIZE = 4;
+
+    /**
+     * One or more clients forming the continuous range [startId, endId].
+     * <p>When a client is added, the IntRange may merge with one or more
+     * adjacent IntRanges to form a single combined IntRange.
+     * <p>When a client is removed, the IntRange may divide into several
+     * non-contiguous IntRanges.
+     */
+    private class IntRange {
+        int startId;
+        int endId;
+        // sorted by earliest start id
+        final ArrayList<ClientRange> clients;
+
+        /**
+         * Create a new IntRange with a single client.
+         * @param startId the first id included in the range
+         * @param endId the last id included in the range
+         * @param client the client requesting the enabled range
+         */
+        IntRange(int startId, int endId, String client) {
+            this.startId = startId;
+            this.endId = endId;
+            clients = new ArrayList<ClientRange>(INITIAL_CLIENTS_ARRAY_SIZE);
+            clients.add(new ClientRange(startId, endId, client));
+        }
+
+        /**
+         * Create a new IntRange for an existing ClientRange.
+         * @param clientRange the initial ClientRange to add
+         */
+        IntRange(ClientRange clientRange) {
+            startId = clientRange.startId;
+            endId = clientRange.endId;
+            clients = new ArrayList<ClientRange>(INITIAL_CLIENTS_ARRAY_SIZE);
+            clients.add(clientRange);
+        }
+
+        /**
+         * Create a new IntRange from an existing IntRange. This is used for
+         * removing a ClientRange, because new IntRanges may need to be created
+         * for any gaps that open up after the ClientRange is removed. A copy
+         * is made of the elements of the original IntRange preceding the element
+         * that is being removed. The following elements will be added to this
+         * IntRange or to a new IntRange when a gap is found.
+         * @param intRange the original IntRange to copy elements from
+         * @param numElements the number of elements to copy from the original
+         */
+        IntRange(IntRange intRange, int numElements) {
+            this.startId = intRange.startId;
+            this.endId = intRange.endId;
+            this.clients = new ArrayList<ClientRange>(intRange.clients.size());
+            for (int i=0; i < numElements; i++) {
+                this.clients.add(intRange.clients.get(i));
+            }
+        }
+
+        /**
+         * Insert new ClientRange in order by start id.
+         * <p>If the new ClientRange is known to be sorted before or after the
+         * existing ClientRanges, or at a particular index, it can be added
+         * to the clients array list directly, instead of via this method.
+         * <p>Note that this can be changed from linear to binary search if the
+         * number of clients grows large enough that it would make a difference.
+         * @param range the new ClientRange to insert
+         */
+        void insert(ClientRange range) {
+            int len = clients.size();
+            for (int i=0; i < len; i++) {
+                ClientRange nextRange = clients.get(i);
+                if (range.startId <= nextRange.startId) {
+                    // ignore duplicate ranges from the same client
+                    if (!range.equals(nextRange)) {
+                        clients.add(i, range);
+                    }
+                    return;
+                }
+            }
+            clients.add(range);    // append to end of list
+        }
+    }
+
+    /**
+     * The message id range for a single client.
+     */
+    private class ClientRange {
+        final int startId;
+        final int endId;
+        final String client;
+
+        ClientRange(int startId, int endId, String client) {
+            this.startId = startId;
+            this.endId = endId;
+            this.client = client;
+        }
+
+        @Override
+        public boolean equals(Object o) {
+            if (o != null && o instanceof ClientRange) {
+                ClientRange other = (ClientRange) o;
+                return startId == other.startId &&
+                        endId == other.endId &&
+                        client.equals(other.client);
+            } else {
+                return false;
+            }
+        }
+
+        @Override
+        public int hashCode() {
+            return (startId * 31 + endId) * 31 + client.hashCode();
+        }
+    }
+
+    /**
+     * List of integer ranges, one per client, sorted by start id.
+     */
+    private ArrayList<IntRange> mRanges = new ArrayList<IntRange>();
+
+    protected IntRangeManager() {}
+
+    /**
+     * Enable a range for the specified client and update ranges
+     * if necessary. If {@link #finishUpdate} returns failure,
+     * false is returned and the range is not added.
+     *
+     * @param startId the first id included in the range
+     * @param endId the last id included in the range
+     * @param client the client requesting the enabled range
+     * @return true if successful, false otherwise
+     */
+    public synchronized boolean enableRange(int startId, int endId, String client) {
+        int len = mRanges.size();
+
+        // empty range list: add the initial IntRange
+        if (len == 0) {
+            if (tryAddSingleRange(startId, endId, true)) {
+                mRanges.add(new IntRange(startId, endId, client));
+                return true;
+            } else {
+                return false;   // failed to update radio
+            }
+        }
+
+        for (int startIndex = 0; startIndex < len; startIndex++) {
+            IntRange range = mRanges.get(startIndex);
+            if (startId < range.startId) {
+                // test if new range completely precedes this range
+                // note that [1, 4] and [5, 6] coalesce to [1, 6]
+                if ((endId + 1) < range.startId) {
+                    // insert new int range before previous first range
+                    if (tryAddSingleRange(startId, endId, true)) {
+                        mRanges.add(startIndex, new IntRange(startId, endId, client));
+                        return true;
+                    } else {
+                        return false;   // failed to update radio
+                    }
+                } else if (endId <= range.endId) {
+                    // extend the start of this range
+                    if (tryAddSingleRange(startId, range.startId - 1, true)) {
+                        range.startId = startId;
+                        range.clients.add(0, new ClientRange(startId, endId, client));
+                        return true;
+                    } else {
+                        return false;   // failed to update radio
+                    }
+                } else {
+                    // find last range that can coalesce into the new combined range
+                    for (int endIndex = startIndex+1; endIndex < len; endIndex++) {
+                        IntRange endRange = mRanges.get(endIndex);
+                        if ((endId + 1) < endRange.startId) {
+                            // try to add entire new range
+                            if (tryAddSingleRange(startId, endId, true)) {
+                                range.startId = startId;
+                                range.endId = endId;
+                                // insert new ClientRange before existing ranges
+                                range.clients.add(0, new ClientRange(startId, endId, client));
+                                // coalesce range with following ranges up to endIndex-1
+                                // remove each range after adding its elements, so the index
+                                // of the next range to join is always startIndex+1.
+                                // i is the index if no elements were removed: we only care
+                                // about the number of loop iterations, not the value of i.
+                                int joinIndex = startIndex + 1;
+                                for (int i = joinIndex; i < endIndex; i++) {
+                                    IntRange joinRange = mRanges.get(joinIndex);
+                                    range.clients.addAll(joinRange.clients);
+                                    mRanges.remove(joinRange);
+                                }
+                                return true;
+                            } else {
+                                return false;   // failed to update radio
+                            }
+                        } else if (endId <= endRange.endId) {
+                            // add range from start id to start of last overlapping range,
+                            // values from endRange.startId to endId are already enabled
+                            if (tryAddSingleRange(startId, endRange.startId - 1, true)) {
+                                range.startId = startId;
+                                range.endId = endRange.endId;
+                                // insert new ClientRange before existing ranges
+                                range.clients.add(0, new ClientRange(startId, endId, client));
+                                // coalesce range with following ranges up to endIndex
+                                // remove each range after adding its elements, so the index
+                                // of the next range to join is always startIndex+1.
+                                // i is the index if no elements were removed: we only care
+                                // about the number of loop iterations, not the value of i.
+                                int joinIndex = startIndex + 1;
+                                for (int i = joinIndex; i <= endIndex; i++) {
+                                    IntRange joinRange = mRanges.get(joinIndex);
+                                    range.clients.addAll(joinRange.clients);
+                                    mRanges.remove(joinRange);
+                                }
+                                return true;
+                            } else {
+                                return false;   // failed to update radio
+                            }
+                        }
+                    }
+
+                    // endId extends past all existing IntRanges: combine them all together
+                    if (tryAddSingleRange(startId, endId, true)) {
+                        range.startId = startId;
+                        range.endId = endId;
+                        // insert new ClientRange before existing ranges
+                        range.clients.add(0, new ClientRange(startId, endId, client));
+                        // coalesce range with following ranges up to len-1
+                        // remove each range after adding its elements, so the index
+                        // of the next range to join is always startIndex+1.
+                        // i is the index if no elements were removed: we only care
+                        // about the number of loop iterations, not the value of i.
+                        int joinIndex = startIndex + 1;
+                        for (int i = joinIndex; i < len; i++) {
+                            IntRange joinRange = mRanges.get(joinIndex);
+                            range.clients.addAll(joinRange.clients);
+                            mRanges.remove(joinRange);
+                        }
+                        return true;
+                    } else {
+                        return false;   // failed to update radio
+                    }
+                }
+            } else if ((startId + 1) <= range.endId) {
+                if (endId <= range.endId) {
+                    // completely contained in existing range; no radio changes
+                    range.insert(new ClientRange(startId, endId, client));
+                    return true;
+                } else {
+                    // find last range that can coalesce into the new combined range
+                    int endIndex = startIndex;
+                    for (int testIndex = startIndex+1; testIndex < len; testIndex++) {
+                        IntRange testRange = mRanges.get(testIndex);
+                        if ((endId + 1) < testRange.startId) {
+                            break;
+                        } else {
+                            endIndex = testIndex;
+                        }
+                    }
+                    // no adjacent IntRanges to combine
+                    if (endIndex == startIndex) {
+                        // add range from range.endId+1 to endId,
+                        // values from startId to range.endId are already enabled
+                        if (tryAddSingleRange(range.endId + 1, endId, true)) {
+                            range.endId = endId;
+                            range.insert(new ClientRange(startId, endId, client));
+                            return true;
+                        } else {
+                            return false;   // failed to update radio
+                        }
+                    }
+                    // get last range to coalesce into start range
+                    IntRange endRange = mRanges.get(endIndex);
+                    // Values from startId to range.endId have already been enabled.
+                    // if endId > endRange.endId, then enable range from range.endId+1 to endId,
+                    // else enable range from range.endId+1 to endRange.startId-1, because
+                    // values from endRange.startId to endId have already been added.
+                    int newRangeEndId = (endId <= endRange.endId) ? endRange.startId - 1 : endId;
+                    if (tryAddSingleRange(range.endId + 1, newRangeEndId, true)) {
+                        range.endId = endId;
+                        // insert new ClientRange in place
+                        range.insert(new ClientRange(startId, endId, client));
+                        // coalesce range with following ranges up to endIndex-1
+                        // remove each range after adding its elements, so the index
+                        // of the next range to join is always startIndex+1 (joinIndex).
+                        // i is the index if no elements had been removed: we only care
+                        // about the number of loop iterations, not the value of i.
+                        int joinIndex = startIndex + 1;
+                        for (int i = joinIndex; i < endIndex; i++) {
+                            IntRange joinRange = mRanges.get(joinIndex);
+                            range.clients.addAll(joinRange.clients);
+                            mRanges.remove(joinRange);
+                        }
+                        return true;
+                    } else {
+                        return false;   // failed to update radio
+                    }
+                }
+            }
+        }
+
+        // append new range after existing IntRanges
+        if (tryAddSingleRange(startId, endId, true)) {
+            mRanges.add(new IntRange(startId, endId, client));
+            return true;
+        } else {
+            return false;   // failed to update radio
+        }
+    }
+
+    /**
+     * Disable a range for the specified client and update ranges
+     * if necessary. If {@link #finishUpdate} returns failure,
+     * false is returned and the range is not removed.
+     *
+     * @param startId the first id included in the range
+     * @param endId the last id included in the range
+     * @param client the client requesting to disable the range
+     * @return true if successful, false otherwise
+     */
+    public synchronized boolean disableRange(int startId, int endId, String client) {
+        int len = mRanges.size();
+
+        for (int i=0; i < len; i++) {
+            IntRange range = mRanges.get(i);
+            if (startId < range.startId) {
+                return false;   // not found
+            } else if (endId <= range.endId) {
+                // found the IntRange that encloses the client range, if any
+                // search for it in the clients list
+                ArrayList<ClientRange> clients = range.clients;
+
+                // handle common case of IntRange containing one ClientRange
+                int crLength = clients.size();
+                if (crLength == 1) {
+                    ClientRange cr = clients.get(0);
+                    if (cr.startId == startId && cr.endId == endId && cr.client.equals(client)) {
+                        // disable range in radio then remove the entire IntRange
+                        if (tryAddSingleRange(startId, endId, false)) {
+                            mRanges.remove(i);
+                            return true;
+                        } else {
+                            return false;   // failed to update radio
+                        }
+                    } else {
+                        return false;   // not found
+                    }
+                }
+
+                // several ClientRanges: remove one, potentially splitting into many IntRanges.
+                // Save the original start and end id for the original IntRange
+                // in case the radio update fails and we have to revert it. If the
+                // update succeeds, we remove the client range and insert the new IntRanges.
+                int largestEndId = Integer.MIN_VALUE;  // largest end identifier found
+                boolean updateStarted = false;
+
+                for (int crIndex=0; crIndex < crLength; crIndex++) {
+                    ClientRange cr = clients.get(crIndex);
+                    if (cr.startId == startId && cr.endId == endId && cr.client.equals(client)) {
+                        // found the ClientRange to remove, check if it's the last in the list
+                        if (crIndex == crLength - 1) {
+                            if (range.endId == largestEndId) {
+                                // no channels to remove from radio; return success
+                                clients.remove(crIndex);
+                                return true;
+                            } else {
+                                // disable the channels at the end and lower the end id
+                                if (tryAddSingleRange(largestEndId + 1, range.endId, false)) {
+                                    clients.remove(crIndex);
+                                    range.endId = largestEndId;
+                                    return true;
+                                } else {
+                                    return false;
+                                }
+                            }
+                        }
+
+                        // copy the IntRange so that we can remove elements and modify the
+                        // start and end id's in the copy, leaving the original unmodified
+                        // until after the radio update succeeds
+                        IntRange rangeCopy = new IntRange(range, crIndex);
+
+                        if (crIndex == 0) {
+                            // removing the first ClientRange, so we may need to increase
+                            // the start id of the IntRange.
+                            // We know there are at least two ClientRanges in the list,
+                            // so clients.get(1) should always succeed.
+                            int nextStartId = clients.get(1).startId;
+                            if (nextStartId != range.startId) {
+                                startUpdate();
+                                updateStarted = true;
+                                addRange(range.startId, nextStartId - 1, false);
+                                rangeCopy.startId = nextStartId;
+                            }
+                            // init largestEndId
+                            largestEndId = clients.get(1).endId;
+                        }
+
+                        // go through remaining ClientRanges, creating new IntRanges when
+                        // there is a gap in the sequence. After radio update succeeds,
+                        // remove the original IntRange and append newRanges to mRanges.
+                        // Otherwise, leave the original IntRange in mRanges and return false.
+                        ArrayList<IntRange> newRanges = new ArrayList<IntRange>();
+
+                        IntRange currentRange = rangeCopy;
+                        for (int nextIndex = crIndex + 1; nextIndex < crLength; nextIndex++) {
+                            ClientRange nextCr = clients.get(nextIndex);
+                            if (nextCr.startId > largestEndId + 1) {
+                                if (!updateStarted) {
+                                    startUpdate();
+                                    updateStarted = true;
+                                }
+                                addRange(largestEndId + 1, nextCr.startId - 1, false);
+                                currentRange.endId = largestEndId;
+                                newRanges.add(currentRange);
+                                currentRange = new IntRange(nextCr);
+                            } else {
+                                currentRange.clients.add(nextCr);
+                            }
+                            if (nextCr.endId > largestEndId) {
+                                largestEndId = nextCr.endId;
+                            }
+                        }
+
+                        // remove any channels between largestEndId and endId
+                        if (largestEndId < endId) {
+                            if (!updateStarted) {
+                                startUpdate();
+                                updateStarted = true;
+                            }
+                            addRange(largestEndId + 1, endId, false);
+                            currentRange.endId = largestEndId;
+                        }
+                        newRanges.add(currentRange);
+
+                        if (updateStarted && !finishUpdate()) {
+                            return false;   // failed to update radio
+                        }
+
+                        // replace the original IntRange with newRanges
+                        mRanges.remove(i);
+                        mRanges.addAll(i, newRanges);
+                        return true;
+                    } else {
+                        // not the ClientRange to remove; save highest end ID seen so far
+                        if (cr.endId > largestEndId) {
+                            largestEndId = cr.endId;
+                        }
+                    }
+                }
+            }
+        }
+
+        return false;   // not found
+    }
+
+    /**
+     * Perform a complete update operation (enable all ranges). Useful
+     * after a radio reset. Calls {@link #startUpdate}, followed by zero or
+     * more calls to {@link #addRange}, followed by {@link #finishUpdate}.
+     * @return true if successful, false otherwise
+     */
+    public boolean updateRanges() {
+        startUpdate();
+        Iterator<IntRange> iterator = mRanges.iterator();
+        if (iterator.hasNext()) {
+            IntRange range = iterator.next();
+            int start = range.startId;
+            int end = range.endId;
+            // accumulate ranges of [startId, endId]
+            while (iterator.hasNext()) {
+                IntRange nextNode = iterator.next();
+                // [startIdA, endIdA], [endIdA + 1, endIdB] -> [startIdA, endIdB]
+                if (nextNode.startId <= (end + 1)) {
+                    if (nextNode.endId > end) {
+                        end = nextNode.endId;
+                    }
+                } else {
+                    addRange(start, end, true);
+                    start = nextNode.startId;
+                    end = nextNode.endId;
+                }
+            }
+            // add final range
+            addRange(start, end, true);
+        }
+        return finishUpdate();
+    }
+
+    /**
+     * Enable or disable a single range of message identifiers.
+     * @param startId the first id included in the range
+     * @param endId the last id included in the range
+     * @param selected true to enable range, false to disable range
+     * @return true if successful, false otherwise
+     */
+    private boolean tryAddSingleRange(int startId, int endId, boolean selected) {
+        startUpdate();
+        addRange(startId, endId, selected);
+        return finishUpdate();
+    }
+
+    /**
+     * Called when the list of enabled ranges has changed. This will be
+     * followed by zero or more calls to {@link #addRange} followed by
+     * a call to {@link #finishUpdate}.
+     */
+    protected abstract void startUpdate();
+
+    /**
+     * Called after {@link #startUpdate} to indicate a range of enabled
+     * or disabled values.
+     *
+     * @param startId the first id included in the range
+     * @param endId the last id included in the range
+     * @param selected true to enable range, false to disable range
+     */
+    protected abstract void addRange(int startId, int endId, boolean selected);
+
+    /**
+     * Called to indicate the end of a range update started by the
+     * previous call to {@link #startUpdate}.
+     * @return true if successful, false otherwise
+     */
+    protected abstract boolean finishUpdate();
+}
diff --git a/telephony/java/com/android/internal/telephony/MccTable.java b/telephony/java/com/android/internal/telephony/MccTable.java
index fde1b59..cdce841 100644
--- a/telephony/java/com/android/internal/telephony/MccTable.java
+++ b/telephony/java/com/android/internal/telephony/MccTable.java
@@ -234,7 +234,7 @@
         String country = MccTable.countryCodeForMcc(mcc);
 
         Log.d(LOG_TAG, "locale set to "+language+"_"+country);
-        phone.setSystemLocale(language, country);
+        phone.setSystemLocale(language, country, true);
     }
 
     /**
diff --git a/telephony/java/com/android/internal/telephony/PhoneBase.java b/telephony/java/com/android/internal/telephony/PhoneBase.java
index b77e134..40a70a8 100644
--- a/telephony/java/com/android/internal/telephony/PhoneBase.java
+++ b/telephony/java/com/android/internal/telephony/PhoneBase.java
@@ -580,7 +580,7 @@
                 if (l.length() >=5) {
                     country = l.substring(3, 5);
                 }
-                setSystemLocale(language, country);
+                setSystemLocale(language, country, false);
 
                 if (!country.isEmpty()) {
                     try {
@@ -602,10 +602,14 @@
      * Utility code to set the system locale if it's not set already
      * @param language Two character language code desired
      * @param country Two character country code desired
+     * @param fromMcc Indicating whether the locale is set according to MCC table.
+     *                This flag wil be ignored by default implementation.
+     *                TODO: Use a source enumeration so that source of the locale
+     *                      can be prioritized.
      *
      *  {@hide}
      */
-    public void setSystemLocale(String language, String country) {
+    public void setSystemLocale(String language, String country, boolean fromMcc) {
         String l = SystemProperties.get("persist.sys.language");
         String c = SystemProperties.get("persist.sys.country");
 
@@ -1023,7 +1027,7 @@
     }
 
     public boolean isDataConnectivityPossible() {
-        return ((mDataConnectionTracker != null) && (mDataConnectionTracker.isDataPossible()));
+        return isDataConnectivityPossible(Phone.APN_TYPE_DEFAULT);
     }
 
     public boolean isDataConnectivityPossible(String apnType) {
diff --git a/telephony/java/com/android/internal/telephony/PhoneFactory.java b/telephony/java/com/android/internal/telephony/PhoneFactory.java
index 6a2d7c9..74bae44 100644
--- a/telephony/java/com/android/internal/telephony/PhoneFactory.java
+++ b/telephony/java/com/android/internal/telephony/PhoneFactory.java
@@ -47,8 +47,6 @@
     static private Looper sLooper;
     static private Context sContext;
 
-    static final int preferredNetworkMode = RILConstants.PREFERRED_NETWORK_MODE;
-
     static final int preferredCdmaSubscription = RILConstants.PREFERRED_CDMA_SUBSCRIPTION;
 
     //***** Class Methods
@@ -99,7 +97,11 @@
 
                 sPhoneNotifier = new DefaultPhoneNotifier();
 
-                //Get preferredNetworkMode from Settings.System
+                // Get preferred network mode
+                int preferredNetworkMode = RILConstants.PREFERRED_NETWORK_MODE;
+                if (BaseCommands.getLteOnCdmaModeStatic() == Phone.LTE_ON_CDMA_TRUE) {
+                    preferredNetworkMode = Phone.NT_MODE_GLOBAL;
+                }
                 int networkMode = Settings.Secure.getInt(context.getContentResolver(),
                         Settings.Secure.PREFERRED_NETWORK_MODE, preferredNetworkMode);
                 Log.i(LOG_TAG, "Network Mode set to " + Integer.toString(networkMode));
diff --git a/telephony/java/com/android/internal/telephony/PhoneProxy.java b/telephony/java/com/android/internal/telephony/PhoneProxy.java
index 68f1c5f..c2212db 100644
--- a/telephony/java/com/android/internal/telephony/PhoneProxy.java
+++ b/telephony/java/com/android/internal/telephony/PhoneProxy.java
@@ -654,7 +654,7 @@
     }
 
     public boolean isDataConnectivityPossible() {
-        return mActivePhone.isDataConnectivityPossible();
+        return mActivePhone.isDataConnectivityPossible(Phone.APN_TYPE_DEFAULT);
     }
 
     public boolean isDataConnectivityPossible(String apnType) {
diff --git a/telephony/java/com/android/internal/telephony/RIL.java b/telephony/java/com/android/internal/telephony/RIL.java
index 0621cfd..76f1ab7e 100644
--- a/telephony/java/com/android/internal/telephony/RIL.java
+++ b/telephony/java/com/android/internal/telephony/RIL.java
@@ -611,14 +611,14 @@
 
     //***** Constructors
 
-    public RIL(Context context, int networkMode, int cdmaSubscription) {
+    public RIL(Context context, int preferredNetworkType, int cdmaSubscription) {
         super(context);
         if (RILJ_LOGD) {
-            riljLog("RIL(context, networkMode=" + networkMode +
+            riljLog("RIL(context, preferredNetworkType=" + preferredNetworkType +
                     " cdmaSubscription=" + cdmaSubscription + ")");
         }
         mCdmaSubscription  = cdmaSubscription;
-        mNetworkMode = networkMode;
+        mPreferredNetworkType = preferredNetworkType;
         mPhoneType = RILConstants.NO_PHONE;
 
         PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
@@ -1813,6 +1813,8 @@
         rr.mp.writeInt(1);
         rr.mp.writeInt(networkType);
 
+        mPreferredNetworkType = networkType;
+
         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
                 + " : " + networkType);
 
@@ -2222,7 +2224,7 @@
             case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: ret =  responseInts(p); break;
             case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: ret =  responseVoid(p); break;
             case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: ret =  responseVoid(p); break;
-            case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: ret =  responseInts(p); break;
+            case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: ret =  responseGetPreferredNetworkType(p); break;
             case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: ret = responseCellList(p); break;
             case RIL_REQUEST_SET_LOCATION_UPDATES: ret =  responseVoid(p); break;
             case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE: ret =  responseVoid(p); break;
@@ -2737,7 +2739,7 @@
 
                 // Initial conditions
                 setRadioPower(false, null);
-                setPreferredNetworkType(mNetworkMode, null);
+                setPreferredNetworkType(mPreferredNetworkType, null);
                 setCdmaSubscriptionSource(mCdmaSubscription, null);
                 notifyRegistrantsRilConnectionChanged(((int[])ret)[0]);
                 break;
@@ -2888,7 +2890,7 @@
 
         String s = p.readString();
 
-        if (RILJ_LOGD) riljLog("< iccIO: "
+        if (RILJ_LOGV) riljLog("< iccIO: "
                 + " 0x" + Integer.toHexString(sw1)
                 + " 0x" + Integer.toHexString(sw2) + " "
                 + s);
@@ -2922,8 +2924,8 @@
             ca.aid            = p.readString();
             ca.app_label      = p.readString();
             ca.pin1_replaced  = p.readInt();
-            ca.pin1           = p.readInt();
-            ca.pin2           = p.readInt();
+            ca.pin1           = ca.PinStateFromRILInt(p.readInt());
+            ca.pin2           = ca.PinStateFromRILInt(p.readInt());
             status.addApplication(ca);
         }
         return status;
@@ -3051,7 +3053,7 @@
     responseSetupDataCall(Parcel p) {
         int ver = p.readInt();
         int num = p.readInt();
-        if (RILJ_LOGD) riljLog("responseSetupDataCall ver=" + ver + " num=" + num);
+        if (RILJ_LOGV) riljLog("responseSetupDataCall ver=" + ver + " num=" + num);
 
         DataCallState dataCall;
 
@@ -3161,6 +3163,18 @@
        return response;
     }
 
+    private Object responseGetPreferredNetworkType(Parcel p) {
+       int [] response = (int[]) responseInts(p);
+
+       if (response.length >= 1) {
+           // Since this is the response for getPreferredNetworkType
+           // we'll assume that it should be the value we want the
+           // vendor ril to take if we reestablish a connection to it.
+           mPreferredNetworkType = response[0];
+       }
+       return response;
+    }
+
     private Object responseGmsBroadcastConfig(Parcel p) {
         int num;
         ArrayList<SmsBroadcastConfigInfo> response;
diff --git a/telephony/java/com/android/internal/telephony/SMSDispatcher.java b/telephony/java/com/android/internal/telephony/SMSDispatcher.java
old mode 100755
new mode 100644
index 8efc9aa..76e719c
--- a/telephony/java/com/android/internal/telephony/SMSDispatcher.java
+++ b/telephony/java/com/android/internal/telephony/SMSDispatcher.java
@@ -32,11 +32,9 @@
 import android.database.SQLException;
 import android.net.Uri;
 import android.os.AsyncResult;
-import android.os.Environment;
 import android.os.Handler;
 import android.os.Message;
 import android.os.PowerManager;
-import android.os.StatFs;
 import android.os.SystemProperties;
 import android.provider.Telephony;
 import android.provider.Telephony.Sms.Intents;
@@ -908,37 +906,6 @@
     protected abstract void sendMultipartSms (SmsTracker tracker);
 
     /**
-     * Activate or deactivate cell broadcast SMS.
-     *
-     * @param activate
-     *            0 = activate, 1 = deactivate
-     * @param response
-     *            Callback message is empty on completion
-     */
-    public abstract void activateCellBroadcastSms(int activate, Message response);
-
-    /**
-     * Query the current configuration of cell broadcast SMS.
-     *
-     * @param response
-     *            Callback message contains the configuration from the modem on completion
-     *            @see #setCellBroadcastConfig
-     */
-    public abstract void getCellBroadcastSmsConfig(Message response);
-
-    /**
-     * Configure cell broadcast SMS.
-     *
-     * @param configValuesArray
-     *          The first element defines the number of triples that follow.
-     *          A triple is made up of the service category, the language identifier
-     *          and a boolean that specifies whether the category is set active.
-     * @param response
-     *            Callback message is empty on completion
-     */
-    public abstract void setCellBroadcastConfig(int[] configValuesArray, Message response);
-
-    /**
      * Send an acknowledge message.
      * @param success indicates that last message was successfully received.
      * @param result result code indicating any error
@@ -1065,14 +1032,17 @@
 
     protected abstract void handleBroadcastSms(AsyncResult ar);
 
-    protected void dispatchBroadcastPdus(byte[][] pdus) {
-        Intent intent = new Intent("android.provider.telephony.SMS_CB_RECEIVED");
-        intent.putExtra("pdus", pdus);
-
-        if (false)
+    protected void dispatchBroadcastPdus(byte[][] pdus, boolean isEmergencyMessage) {
+        if (isEmergencyMessage) {
+            Intent intent = new Intent(Intents.SMS_EMERGENCY_CB_RECEIVED_ACTION);
+            intent.putExtra("pdus", pdus);
+            Log.d(TAG, "Dispatching " + pdus.length + " emergency SMS CB pdus");
+            dispatch(intent, "android.permission.RECEIVE_EMERGENCY_BROADCAST");
+        } else {
+            Intent intent = new Intent(Intents.SMS_CB_RECEIVED_ACTION);
+            intent.putExtra("pdus", pdus);
             Log.d(TAG, "Dispatching " + pdus.length + " SMS CB pdus");
-
-        dispatch(intent, "android.permission.RECEIVE_SMS");
+            dispatch(intent, "android.permission.RECEIVE_SMS");
+        }
     }
-
 }
diff --git a/telephony/java/com/android/internal/telephony/ServiceStateTracker.java b/telephony/java/com/android/internal/telephony/ServiceStateTracker.java
index 695805c..01b807d 100644
--- a/telephony/java/com/android/internal/telephony/ServiceStateTracker.java
+++ b/telephony/java/com/android/internal/telephony/ServiceStateTracker.java
@@ -54,6 +54,12 @@
     protected boolean mDesiredPowerState;
 
     /**
+     *  Values correspond to ServiceState.RADIO_TECHNOLOGY_ definitions.
+     */
+    protected int mRadioTechnology = 0;
+    protected int mNewRadioTechnology = 0;
+
+    /**
      * By default, strength polling is enabled.  However, if we're
      * getting unsolicited signal strength updates from the radio, set
      * value to true and don't bother polling any more.
diff --git a/telephony/java/com/android/internal/telephony/WapPushOverSms.java b/telephony/java/com/android/internal/telephony/WapPushOverSms.java
old mode 100644
new mode 100755
diff --git a/telephony/java/com/android/internal/telephony/WspTypeDecoder.java b/telephony/java/com/android/internal/telephony/WspTypeDecoder.java
old mode 100644
new mode 100755
index c8dd718..73260fb
--- a/telephony/java/com/android/internal/telephony/WspTypeDecoder.java
+++ b/telephony/java/com/android/internal/telephony/WspTypeDecoder.java
@@ -194,6 +194,7 @@
 
     public static final String CONTENT_TYPE_B_PUSH_CO = "application/vnd.wap.coc";
     public static final String CONTENT_TYPE_B_MMS = "application/vnd.wap.mms-message";
+    public static final String CONTENT_TYPE_B_PUSH_SYNCML_NOTI = "application/vnd.syncml.notification";
 
     byte[] wspData;
     int    dataLength;
diff --git a/telephony/java/com/android/internal/telephony/cdma/CDMALTEPhone.java b/telephony/java/com/android/internal/telephony/cdma/CDMALTEPhone.java
index 586e6b3..6a95b67 100644
--- a/telephony/java/com/android/internal/telephony/cdma/CDMALTEPhone.java
+++ b/telephony/java/com/android/internal/telephony/cdma/CDMALTEPhone.java
@@ -58,39 +58,20 @@
     @Override
     protected void initSstIcc() {
         mSST = new CdmaLteServiceStateTracker(this);
-        mIccRecords = new SIMRecords(this);
+        mIccRecords = new CdmaLteUiccRecords(this);
         mIccCard = new SimCard(this, LOG_TAG, DBG);
+        mIccFileHandler = new CdmaLteUiccFileHandler(this);
     }
 
     @Override
     public DataState getDataConnectionState(String apnType) {
-        // TODO: Remove instanceof if possible.
-        boolean isCdmaDataConnectionTracker = false;
-        if (mDataConnectionTracker instanceof CdmaDataConnectionTracker) {
-            log("getDataConnectionState isCdmaDataConnectionTracker");
-            isCdmaDataConnectionTracker = true;
-        } else {
-            log("getDataConnectionState NOT CdmaDataConnectionTracker");
-        }
         DataState ret = DataState.DISCONNECTED;
 
-        if (!isCdmaDataConnectionTracker && (SystemProperties.get("adb.connected", "").length()
-                > 0)) {
-            // We're connected to an ADB host and we have USB networking
-            // turned on. No matter what the radio state is,
-            // we report data connected
-
-            ret = DataState.CONNECTED;
-        } else if (mSST == null) {
+        if (mSST == null) {
             // Radio Technology Change is ongoning, dispose() and
-            // removeReferences() have
-            // already been called
+            // removeReferences() have already been called
 
             ret = DataState.DISCONNECTED;
-        } else if (mSST.getCurrentCdmaDataConnectionState() != ServiceState.STATE_IN_SERVICE) {
-            // If we're out of service, open TCP sockets may still work
-            // but no data will flow
-            ret = DataState.DISCONNECTED;
         } else if (mDataConnectionTracker.isApnTypeEnabled(apnType) == false) {
             ret = DataState.DISCONNECTED;
         } else {
@@ -140,6 +121,15 @@
     }
 
     @Override
+    public void setSystemLocale(String language, String country, boolean fromMcc) {
+        // Avoid system locale is set from MCC table if CDMALTEPhone is used.
+        // The locale will be picked up based on EFpl/EFli once CSIM records are loaded.
+        if (fromMcc) return;
+
+        super.setSystemLocale(language, country, false);
+    }
+
+    @Override
     protected void log(String s) {
         if (DBG)
             Log.d(LOG_TAG, "[CDMALTEPhone] " + s);
diff --git a/telephony/java/com/android/internal/telephony/cdma/CDMAPhone.java b/telephony/java/com/android/internal/telephony/cdma/CDMAPhone.java
index 4fa369c3..bac15a6 100755
--- a/telephony/java/com/android/internal/telephony/cdma/CDMAPhone.java
+++ b/telephony/java/com/android/internal/telephony/cdma/CDMAPhone.java
@@ -156,13 +156,13 @@
         mSST = new CdmaServiceStateTracker(this);
         mIccRecords = new RuimRecords(this);
         mIccCard = new RuimCard(this, LOG_TAG, DBG);
+        mIccFileHandler = new RuimFileHandler(this);
     }
 
     protected void init(Context context, PhoneNotifier notifier) {
         mCM.setPhoneType(Phone.PHONE_TYPE_CDMA);
         mCT = new CdmaCallTracker(this);
         mSMS = new CdmaSMSDispatcher(this);
-        mIccFileHandler = new RuimFileHandler(this);
         mDataConnectionTracker = new CdmaDataConnectionTracker (this);
         mRuimPhoneBookInterfaceManager = new RuimPhoneBookInterfaceManager(this);
         mRuimSmsInterfaceManager = new RuimSmsInterfaceManager(this, mSMS);
@@ -337,7 +337,7 @@
     public DataActivityState getDataActivityState() {
         DataActivityState ret = DataActivityState.NONE;
 
-        if (mSST.getCurrentCdmaDataConnectionState() == ServiceState.STATE_IN_SERVICE) {
+        if (mSST.getCurrentDataConnectionState() == ServiceState.STATE_IN_SERVICE) {
 
             switch (mDataConnectionTracker.getActivity()) {
                 case DATAIN:
@@ -618,7 +618,7 @@
              // already been called
 
              ret = DataState.DISCONNECTED;
-        } else if (mSST.getCurrentCdmaDataConnectionState() != ServiceState.STATE_IN_SERVICE) {
+        } else if (mSST.getCurrentDataConnectionState() != ServiceState.STATE_IN_SERVICE) {
             // If we're out of service, open TCP sockets may still work
             // but no data will flow
             ret = DataState.DISCONNECTED;
@@ -1121,7 +1121,8 @@
      * @param response Callback message is empty on completion
      */
     public void activateCellBroadcastSms(int activate, Message response) {
-        mSMS.activateCellBroadcastSms(activate, response);
+        Log.e(LOG_TAG, "[CDMAPhone] activateCellBroadcastSms() is obsolete; use SmsManager");
+        response.sendToTarget();
     }
 
     /**
@@ -1130,7 +1131,8 @@
      * @param response Callback message is empty on completion
      */
     public void getCellBroadcastSmsConfig(Message response) {
-        mSMS.getCellBroadcastSmsConfig(response);
+        Log.e(LOG_TAG, "[CDMAPhone] getCellBroadcastSmsConfig() is obsolete; use SmsManager");
+        response.sendToTarget();
     }
 
     /**
@@ -1139,7 +1141,8 @@
      * @param response Callback message is empty on completion
      */
     public void setCellBroadcastSmsConfig(int[] configValuesArray, Message response) {
-        mSMS.setCellBroadcastConfig(configValuesArray, response);
+        Log.e(LOG_TAG, "[CDMAPhone] setCellBroadcastSmsConfig() is obsolete; use SmsManager");
+        response.sendToTarget();
     }
 
     /**
diff --git a/telephony/java/com/android/internal/telephony/cdma/CdmaDataConnectionTracker.java b/telephony/java/com/android/internal/telephony/cdma/CdmaDataConnectionTracker.java
index e3e3d78..800615c 100644
--- a/telephony/java/com/android/internal/telephony/cdma/CdmaDataConnectionTracker.java
+++ b/telephony/java/com/android/internal/telephony/cdma/CdmaDataConnectionTracker.java
@@ -175,7 +175,7 @@
 
     @Override
     protected boolean isDataAllowed() {
-        int psState = mCdmaPhone.mSST.getCurrentCdmaDataConnectionState();
+        int psState = mCdmaPhone.mSST.getCurrentDataConnectionState();
         boolean roaming = (mPhone.getServiceState().getRoaming() && !getDataOnRoamingEnabled());
         boolean desiredPowerState = mCdmaPhone.mSST.getDesiredPowerState();
 
@@ -214,35 +214,15 @@
         return allowed;
     }
 
-    /**
-     * The only circumstances under which we report that data connectivity is not
-     * possible are
-     * <ul>
-     * <li>Data is disallowed (roaming, power state, voice call, etc).</li>
-     * <li>The current data state is {@code DISCONNECTED} for a reason other than
-     * having explicitly disabled connectivity. In other words, data is not available
-     * because the phone is out of coverage or some like reason.</li>
-     * </ul>
-     * @return {@code true} if data connectivity is possible, {@code false} otherwise.
-     */
     @Override
-    protected boolean isDataPossible() {
-        boolean dataAllowed = isDataAllowed();
-        boolean anyDataEnabled = getAnyDataEnabled();
-        boolean possible = (dataAllowed
-                && !(anyDataEnabled && (mState == State.FAILED || mState == State.IDLE)));
-        if (!possible && DBG) {
-            log("isDataPossible() " + possible + ", dataAllowed=" + dataAllowed +
-                    " anyDataEnabled=" + anyDataEnabled + " dataState=" + mState);
+    protected boolean isDataPossible(String apnType) {
+        boolean possible = isDataAllowed() && !(getAnyDataEnabled() &&
+                (mState == State.FAILED || mState == State.IDLE));
+        if (!possible && DBG && isDataAllowed()) {
+            log("Data not possible.  No coverage: dataState = " + mState);
         }
         return possible;
     }
- 
-    @Override
-    protected boolean isDataPossible(String apnType) {
-        return isDataPossible();
-    }
-
 
     private boolean trySetupData(String reason) {
         if (DBG) log("***trySetupData due to " + (reason == null ? "(unspecified)" : reason));
@@ -258,7 +238,7 @@
             return true;
         }
 
-        int psState = mCdmaPhone.mSST.getCurrentCdmaDataConnectionState();
+        int psState = mCdmaPhone.mSST.getCurrentDataConnectionState();
         boolean roaming = mPhone.getServiceState().getRoaming();
         boolean desiredPowerState = mCdmaPhone.mSST.getDesiredPowerState();
 
diff --git a/telephony/java/com/android/internal/telephony/cdma/CdmaLteServiceStateTracker.java b/telephony/java/com/android/internal/telephony/cdma/CdmaLteServiceStateTracker.java
index d79f0a1e..318cf37 100644
--- a/telephony/java/com/android/internal/telephony/cdma/CdmaLteServiceStateTracker.java
+++ b/telephony/java/com/android/internal/telephony/cdma/CdmaLteServiceStateTracker.java
@@ -16,7 +16,6 @@
 
 package com.android.internal.telephony.cdma;
 
-import com.android.internal.telephony.DataConnectionTracker;
 import com.android.internal.telephony.TelephonyProperties;
 import com.android.internal.telephony.MccTable;
 import com.android.internal.telephony.EventLogTags;
@@ -26,28 +25,22 @@
 import android.telephony.ServiceState;
 import android.telephony.cdma.CdmaCellLocation;
 import android.os.AsyncResult;
-import android.os.Handler;
 import android.os.Message;
-import android.os.Registrant;
-import android.os.RegistrantList;
-import android.os.AsyncResult;
-import android.os.Message;
+
 
 import android.util.Log;
 import android.util.EventLog;
 
-import com.android.internal.telephony.RestrictedState;
 import com.android.internal.telephony.gsm.GsmDataConnectionTracker;
 
 public class CdmaLteServiceStateTracker extends CdmaServiceStateTracker {
-    static final String LOG_TAG = "CDMA";
-
     CDMALTEPhone mCdmaLtePhone;
 
     private ServiceState  mLteSS;  // The last LTE state from Voice Registration
 
     public CdmaLteServiceStateTracker(CDMALTEPhone phone) {
         super(phone);
+        cm.registerForSIMReady(this, EVENT_SIM_READY, null);
         mCdmaLtePhone = phone;
 
         mLteSS = new ServiceState();
@@ -55,15 +48,44 @@
     }
 
     @Override
+    public void dispose() {
+        cm.unregisterForSIMReady(this);
+        super.dispose();
+    }
+
+    @Override
     public void handleMessage(Message msg) {
         AsyncResult ar;
         int[] ints;
         String[] strings;
-        if (msg.what == EVENT_POLL_STATE_GPRS) {
+        switch (msg.what) {
+        case EVENT_POLL_STATE_GPRS:
             if (DBG) log("handleMessage EVENT_POLL_STATE_GPRS");
             ar = (AsyncResult)msg.obj;
             handlePollStateResult(msg.what, ar);
-        } else {
+            break;
+        case EVENT_SIM_READY:
+            if (DBG) log("handleMessage EVENT_SIM_READY");
+            isSubscriptionFromRuim = false;
+            // Register SIM_RECORDS_LOADED dynamically.
+            // This is to avoid confilct with RUIM_READY scenario)
+            phone.mIccRecords.registerForRecordsLoaded(this, EVENT_SIM_RECORDS_LOADED, null);
+            pollState();
+            // Signal strength polling stops when radio is off.
+            queueNextSignalStrengthPoll();
+            break;
+        case EVENT_SIM_RECORDS_LOADED:
+            CdmaLteUiccRecords sim = (CdmaLteUiccRecords)phone.mIccRecords;
+            if ((sim != null) && sim.isProvisioned()) {
+                mMdn = sim.getMdn();
+                mMin = sim.getMin();
+                parseSidNid(sim.getSid(), sim.getNid());
+                mPrlVersion = sim.getPrlVersion();;
+                mIsMinInfoReady = true;
+                updateOtaspState();
+            }
+            break;
+        default:
             super.handleMessage(msg);
         }
     }
@@ -171,39 +193,6 @@
         }
     }
 
-    protected static String networkTypeToString(int type) {
-        String ret = "unknown";
-
-        switch (type) {
-            case ServiceState.RADIO_TECHNOLOGY_IS95A:
-            case ServiceState.RADIO_TECHNOLOGY_IS95B:
-                ret = "CDMA";
-                break;
-            case ServiceState.RADIO_TECHNOLOGY_1xRTT:
-                ret = "CDMA - 1xRTT";
-                break;
-            case ServiceState.RADIO_TECHNOLOGY_EVDO_0:
-                ret = "CDMA - EvDo rev. 0";
-                break;
-            case ServiceState.RADIO_TECHNOLOGY_EVDO_A:
-                ret = "CDMA - EvDo rev. A";
-                break;
-            case ServiceState.RADIO_TECHNOLOGY_EVDO_B:
-                ret = "CDMA - EvDo rev. B";
-                break;
-            case ServiceState.RADIO_TECHNOLOGY_LTE:
-                ret = "LTE";
-                break;
-            case ServiceState.RADIO_TECHNOLOGY_EHRPD:
-                ret = "CDMA - eHRPD";
-                break;
-            default:
-                sloge("networkTypeToString: Wrong network, can not return a string.");
-                break;
-        }
-        return ret;
-    }
-
     @Override
     protected void pollStateDone() {
         // determine data NetworkType from both LET and CDMA SS
@@ -267,13 +256,20 @@
              (newNetworkType <= ServiceState.RADIO_TECHNOLOGY_EVDO_A));
 
         if (DBG) {
-            log("pollStateDone: hasRegistered = "
-                + hasRegistered + " hasCdmaDataConnectionAttached = "
-                + hasCdmaDataConnectionAttached + " hasCdmaDataConnectionChanged = "
-                + hasCdmaDataConnectionChanged + " hasNetworkTypeChanged = "
-                + hasNetworkTypeChanged + " has4gHandoff = " + has4gHandoff
-                + " hasMultiApnSupport = " + hasMultiApnSupport + " hasLostMultiApnSupport = "
-                + hasLostMultiApnSupport);
+            log("pollStateDone:"
+                + " hasRegistered=" + hasRegistered
+                + " hasDeegistered=" + hasDeregistered
+                + " hasCdmaDataConnectionAttached=" + hasCdmaDataConnectionAttached
+                + " hasCdmaDataConnectionDetached=" + hasCdmaDataConnectionDetached
+                + " hasCdmaDataConnectionChanged=" + hasCdmaDataConnectionChanged
+                + " hasNetworkTypeChanged = " + hasNetworkTypeChanged
+                + " hasChanged=" + hasChanged
+                + " hasRoamingOn=" + hasRoamingOn
+                + " hasRoamingOff=" + hasRoamingOff
+                + " hasLocationChanged=" + hasLocationChanged
+                + " has4gHandoff = " + has4gHandoff
+                + " hasMultiApnSupport=" + hasMultiApnSupport
+                + " hasLostMultiApnSupport=" + hasLostMultiApnSupport);
         }
         // Add an event log when connection state changes
         if (ss.getState() != newSS.getState()
@@ -301,7 +297,7 @@
                 && (phone.mDataConnectionTracker instanceof GsmDataConnectionTracker)) {
             if (DBG)log("GsmDataConnectionTracker disposed");
             phone.mDataConnectionTracker.dispose();
-            phone.mDataConnectionTracker = new CdmaDataConnectionTracker((CDMAPhone)phone);
+            phone.mDataConnectionTracker = new CdmaDataConnectionTracker(phone);
         }
 
         CdmaCellLocation tcl = cellLoc;
@@ -315,7 +311,7 @@
 
         if (hasNetworkTypeChanged) {
             phone.setSystemProperty(TelephonyProperties.PROPERTY_DATA_NETWORK_TYPE,
-                    networkTypeToString(networkType));
+                    ServiceState.radioTechnologyToString(networkType));
         }
 
         if (hasRegistered) {
@@ -336,7 +332,14 @@
                     eriText = phone.getContext()
                             .getText(com.android.internal.R.string.roamingTextSearching).toString();
                 }
-                ss.setCdmaEriText(eriText);
+                ss.setOperatorAlphaLong(eriText);
+            }
+            if (cm.getSimState().isSIMReady()) {
+                // SIM is found on the device. Read the operator name from the card.
+                ss.setOperatorAlphaLong(phone.mIccRecords.getServiceProviderName());
+
+                // If SIM card is present, Eri will not be used. Turn it off
+                ss.setCdmaEriIconIndex(EriInfo.ROAMING_INDICATOR_OFF);
             }
 
             String operatorNumeric;
@@ -400,6 +403,7 @@
         }
     }
 
+    @Override
     protected void onSignalStrengthResult(AsyncResult ar) {
         SignalStrength oldSignalStrength = mSignalStrength;
 
@@ -441,6 +445,7 @@
         }
     }
 
+    @Override
     public boolean isConcurrentVoiceAndDataAllowed() {
         // Note: it needs to be confirmed which CDMA network types
         // can support voice and data calls concurrently.
@@ -449,6 +454,16 @@
         return false;
     }
 
+    /**
+     * Returns OTASP_NOT_NEEDED as its not needed for LTE
+     */
+    @Override
+    int getOtasp() {
+        int provisioningState = OTASP_NOT_NEEDED;
+        if (DBG) log("getOtasp: state=" + provisioningState);
+        return provisioningState;
+    }
+
     @Override
     protected void log(String s) {
         Log.d(LOG_TAG, "[CdmaLteSST] " + s);
@@ -458,8 +473,4 @@
     protected void loge(String s) {
         Log.e(LOG_TAG, "[CdmaLteSST] " + s);
     }
-
-    protected static void sloge(String s) {
-        Log.e(LOG_TAG, "[CdmaLteSST] " + s);
-    }
 }
diff --git a/telephony/java/com/android/internal/telephony/cdma/CdmaLteUiccFileHandler.java b/telephony/java/com/android/internal/telephony/cdma/CdmaLteUiccFileHandler.java
new file mode 100644
index 0000000..b9d7c46
--- /dev/null
+++ b/telephony/java/com/android/internal/telephony/cdma/CdmaLteUiccFileHandler.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.telephony.cdma;
+
+import android.util.Log;
+import com.android.internal.telephony.IccConstants;
+import com.android.internal.telephony.IccFileHandler;
+import android.os.Message;
+
+/**
+ * {@hide}
+ */
+public final class CdmaLteUiccFileHandler extends IccFileHandler {
+    static final String LOG_TAG = "CDMA";
+
+    CdmaLteUiccFileHandler(CDMALTEPhone phone) {
+        super(phone);
+    }
+
+    protected String getEFPath(int efid) {
+        switch(efid) {
+        case EF_CSIM_SPN:
+        case EF_CSIM_LI:
+        case EF_CSIM_MDN:
+        case EF_CSIM_IMSIM:
+        case EF_CSIM_CDMAHOME:
+        case EF_CSIM_EPRL:
+            return MF_SIM + DF_CDMA;
+        case EF_AD:
+            return MF_SIM + DF_GSM;
+        }
+        return getCommonIccEFPath(efid);
+    }
+
+    @Override
+    public void loadEFTransparent(int fileid, Message onLoaded) {
+        if (fileid == EF_CSIM_EPRL) {
+            // Entire PRL could be huge. We are only interested in
+            // the first 4 bytes of the record.
+            phone.mCM.iccIO(COMMAND_READ_BINARY, fileid, getEFPath(fileid),
+                            0, 0, 4, null, null,
+                            obtainMessage(EVENT_READ_BINARY_DONE,
+                                          fileid, 0, onLoaded));
+        } else {
+            super.loadEFTransparent(fileid, onLoaded);
+        }
+    }
+
+
+    protected void logd(String msg) {
+        Log.d(LOG_TAG, "[CdmaLteUiccFileHandler] " + msg);
+    }
+
+    protected void loge(String msg) {
+        Log.e(LOG_TAG, "[CdmaLteUiccFileHandler] " + msg);
+    }
+
+}
diff --git a/telephony/java/com/android/internal/telephony/cdma/CdmaLteUiccRecords.java b/telephony/java/com/android/internal/telephony/cdma/CdmaLteUiccRecords.java
new file mode 100755
index 0000000..73b5d97
--- /dev/null
+++ b/telephony/java/com/android/internal/telephony/cdma/CdmaLteUiccRecords.java
@@ -0,0 +1,452 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.internal.telephony.cdma;
+
+import static com.android.internal.telephony.TelephonyProperties.PROPERTY_ICC_OPERATOR_ALPHA;
+import com.android.internal.telephony.GsmAlphabet;
+import com.android.internal.telephony.IccCardApplication.AppType;
+import com.android.internal.telephony.IccFileHandler;
+import com.android.internal.telephony.IccUtils;
+import com.android.internal.telephony.MccTable;
+import com.android.internal.telephony.PhoneBase;
+import com.android.internal.telephony.cdma.sms.UserData;
+import com.android.internal.telephony.gsm.SIMRecords;
+import android.os.AsyncResult;
+import android.os.Message;
+import android.os.SystemProperties;
+import android.util.Log;
+import java.util.Locale;
+import java.util.ArrayList;
+
+/**
+ * {@hide}
+ */
+public final class CdmaLteUiccRecords extends SIMRecords {
+    // From CSIM application
+    private byte[] mEFpl = null;
+    private byte[] mEFli = null;
+    boolean csimSpnDisplayCondition = false;
+    private String mMdn;
+    private String mMin;
+    private String mPrlVersion;
+    private String mHomeSystemId;
+    private String mHomeNetworkId;
+
+    private static final int EVENT_GET_PL_DONE = CSIM_EVENT_BASE;
+    private static final int EVENT_GET_CSIM_LI_DONE = CSIM_EVENT_BASE + 1;
+    private static final int EVENT_GET_CSIM_SPN_DONE = CSIM_EVENT_BASE + 2;
+    private static final int EVENT_GET_CSIM_MDN_DONE = CSIM_EVENT_BASE + 3;
+    private static final int EVENT_GET_CSIM_IMSIM_DONE = CSIM_EVENT_BASE + 4;
+    private static final int EVENT_GET_CSIM_CDMAHOME_DONE = CSIM_EVENT_BASE + 5;
+    private static final int EVENT_GET_CSIM_EPRL_DONE = CSIM_EVENT_BASE + 6;
+
+    public CdmaLteUiccRecords(PhoneBase p) {
+        super(p);
+    }
+
+    @Override
+    public void handleMessage(Message msg) {
+        AsyncResult ar;
+        byte data[];
+
+        boolean isCsimRecordLoadResponse = false;
+
+        try { switch (msg.what) {
+            case EVENT_GET_PL_DONE:
+                // Refer to ETSI TS.102.221
+                if (DBG) log("EF_GET_EF_PL_DONE");
+                isCsimRecordLoadResponse = true;
+
+                ar = (AsyncResult) msg.obj;
+
+                if (ar.exception != null) {
+                    Log.e(LOG_TAG, "ar.exception = " + ar.exception);
+                    break;
+                }
+
+                mEFpl = (byte[]) ar.result;
+                if (DBG) log("EF_PL=" + IccUtils.bytesToHexString(mEFpl));
+                break;
+
+            case EVENT_GET_CSIM_LI_DONE:
+                // Refer to C.S0065 5.2.26
+                if (DBG) log("EVENT_GET_CSIM_LI_DONE");
+                isCsimRecordLoadResponse = true;
+
+                ar = (AsyncResult) msg.obj;
+                if (ar.exception != null) {
+                    Log.e(LOG_TAG, "ar.exception = " + ar.exception);
+                    break;
+                }
+
+                mEFli = (byte[]) ar.result;
+                // convert csim efli data to iso 639 format
+                for (int i = 0; i < mEFli.length; i+=2) {
+                    switch(mEFli[i+1]) {
+                    case 0x01: mEFli[i] = 'e'; mEFli[i+1] = 'n';break;
+                    case 0x02: mEFli[i] = 'f'; mEFli[i+1] = 'r';break;
+                    case 0x03: mEFli[i] = 'e'; mEFli[i+1] = 's';break;
+                    case 0x04: mEFli[i] = 'j'; mEFli[i+1] = 'a';break;
+                    case 0x05: mEFli[i] = 'k'; mEFli[i+1] = 'o';break;
+                    case 0x06: mEFli[i] = 'z'; mEFli[i+1] = 'h';break;
+                    case 0x07: mEFli[i] = 'h'; mEFli[i+1] = 'e';break;
+                    default: mEFli[i] = ' '; mEFli[i+1] = ' ';
+                    }
+                }
+
+                if (DBG) log("EF_LI=" + IccUtils.bytesToHexString(mEFli));
+                break;
+            case EVENT_GET_CSIM_SPN_DONE:
+                // Refer to C.S0065 5.2.32
+                if (DBG) log("EVENT_GET_CSIM_SPN_DONE");
+                isCsimRecordLoadResponse = true;
+                ar = (AsyncResult) msg.obj;
+
+                if (ar.exception != null) {
+                    Log.e(LOG_TAG, "ar.exception=" + ar.exception);
+                    break;
+                }
+                onGetCSimSpnDone(ar);
+                break;
+            case EVENT_GET_CSIM_MDN_DONE:
+                if (DBG) log("EVENT_GET_CSIM_MDN_DONE");
+                isCsimRecordLoadResponse = true;
+                ar = (AsyncResult) msg.obj;
+                if (ar.exception != null) {
+                    Log.e(LOG_TAG, "ar.exception=" + ar.exception);
+                    break;
+                }
+                onGetCSimMdnDone(ar);
+                break;
+            case EVENT_GET_CSIM_IMSIM_DONE:
+                if (DBG) log("EVENT_GET_CSIM_IMSIM_DONE");
+                isCsimRecordLoadResponse = true;
+                ar = (AsyncResult) msg.obj;
+                if (ar.exception != null) {
+                    Log.e(LOG_TAG, "ar.exception=" + ar.exception);
+                    break;
+                }
+                onGetCSimImsimDone(ar);
+                break;
+            case EVENT_GET_CSIM_CDMAHOME_DONE:
+                if (DBG) log("EVENT_GET_CSIM_CDMAHOME_DONE");
+                isCsimRecordLoadResponse = true;
+                ar = (AsyncResult) msg.obj;
+                if (ar.exception != null) {
+                    Log.e(LOG_TAG, "ar.exception=" + ar.exception);
+                    break;
+                }
+                onGetCSimCdmaHomeDone(ar);
+                break;
+            case EVENT_GET_CSIM_EPRL_DONE:
+                if (DBG) log("EVENT_GET_CSIM_EPRL_DONE");
+                isCsimRecordLoadResponse = true;
+                ar = (AsyncResult) msg.obj;
+                if (ar.exception != null) {
+                    Log.e(LOG_TAG, "ar.exception=" + ar.exception);
+                    break;
+                }
+                onGetCSimEprlDone(ar);
+                break;
+            default:
+                super.handleMessage(msg);
+        }}catch (RuntimeException exc) {
+            Log.w(LOG_TAG, "Exception parsing SIM record", exc);
+        } finally {
+            if (isCsimRecordLoadResponse) {
+                onRecordLoaded();
+            }
+        }
+    }
+
+    @Override
+    protected void onRecordLoaded() {
+        // One record loaded successfully or failed, In either case
+        // we need to update the recordsToLoad count
+        recordsToLoad -= 1;
+
+        if (recordsToLoad == 0 && recordsRequested == true) {
+            onAllRecordsLoaded();
+        } else if (recordsToLoad < 0) {
+            Log.e(LOG_TAG, "SIMRecords: recordsToLoad <0, programmer error suspected");
+            recordsToLoad = 0;
+        }
+    }
+
+    @Override
+    protected void onAllRecordsLoaded() {
+        super.onAllRecordsLoaded();
+        setLocaleFromCsim();
+    }
+
+    @Override
+    protected void fetchSimRecords() {
+        IccFileHandler iccFh = phone.getIccFileHandler();
+        recordsRequested = true;
+
+        phone.mCM.getIMSI(obtainMessage(EVENT_GET_IMSI_DONE));
+        recordsToLoad++;
+
+        iccFh.loadEFTransparent(EF_ICCID, obtainMessage(EVENT_GET_ICCID_DONE));
+        recordsToLoad++;
+
+        iccFh.loadEFTransparent(EF_AD, obtainMessage(EVENT_GET_AD_DONE));
+        recordsToLoad++;
+
+        iccFh.loadEFTransparent(EF_PL, obtainMessage(EVENT_GET_PL_DONE));
+        recordsToLoad++;
+
+        iccFh.loadEFTransparent(EF_CSIM_LI, obtainMessage(EVENT_GET_CSIM_LI_DONE));
+        recordsToLoad++;
+
+        iccFh.loadEFTransparent(EF_CSIM_SPN, obtainMessage(EVENT_GET_CSIM_SPN_DONE));
+        recordsToLoad++;
+
+        iccFh.loadEFLinearFixed(EF_CSIM_MDN, 1, obtainMessage(EVENT_GET_CSIM_MDN_DONE));
+        recordsToLoad++;
+
+        iccFh.loadEFTransparent(EF_CSIM_IMSIM, obtainMessage(EVENT_GET_CSIM_IMSIM_DONE));
+        recordsToLoad++;
+
+        iccFh.loadEFLinearFixedAll(EF_CSIM_CDMAHOME,
+                                   obtainMessage(EVENT_GET_CSIM_CDMAHOME_DONE));
+        recordsToLoad++;
+
+        iccFh.loadEFTransparent(EF_CSIM_EPRL, obtainMessage(EVENT_GET_CSIM_EPRL_DONE));
+        recordsToLoad++;
+    }
+
+    private void onGetCSimSpnDone(AsyncResult ar) {
+        byte[] data = (byte[]) ar.result;
+        if (DBG) log("CSIM_SPN=" +
+                     IccUtils.bytesToHexString(data));
+
+        // C.S0065 for EF_SPN decoding
+        csimSpnDisplayCondition = ((0x02 & data[0]) > 0)?true:false;
+
+        int encoding = data[1];
+        int language = data[2];
+        byte[] spnData = new byte[32];
+        System.arraycopy(data, 3, spnData, 0, (data.length < 32)?data.length:32);
+
+        int numBytes;
+        for (numBytes = 0; numBytes < spnData.length; numBytes++) {
+            if ((spnData[numBytes] & 0xFF) == 0xFF) break;
+        }
+
+        if (numBytes == 0) {
+            spn = "";
+            return;
+        }
+        try {
+            switch (encoding) {
+            case UserData.ENCODING_OCTET:
+            case UserData.ENCODING_LATIN:
+                spn = new String(spnData, 0, numBytes, "ISO-8859-1");
+                break;
+            case UserData.ENCODING_IA5:
+            case UserData.ENCODING_GSM_7BIT_ALPHABET:
+            case UserData.ENCODING_7BIT_ASCII:
+                spn = GsmAlphabet.gsm7BitPackedToString(spnData, 0, (numBytes*8)/7);
+                break;
+            case UserData.ENCODING_UNICODE_16:
+                spn =  new String(spnData, 0, numBytes, "utf-16");
+                break;
+            default:
+                log("SPN encoding not supported");
+            }
+        } catch(Exception e) {
+            log("spn decode error: " + e);
+        }
+        if (DBG) log("spn=" + spn);
+        if (DBG) log("spnCondition=" + csimSpnDisplayCondition);
+        phone.setSystemProperty(PROPERTY_ICC_OPERATOR_ALPHA, spn);
+    }
+
+    private void onGetCSimMdnDone(AsyncResult ar) {
+        byte[] data = (byte[]) ar.result;
+        if (DBG) log("CSIM_MDN=" + IccUtils.bytesToHexString(data));
+        int mdnDigitsNum = 0x0F & data[0];
+        mMdn = IccUtils.cdmaBcdToString(data, 1, mdnDigitsNum);
+        if (DBG) log("CSIM MDN=" + mMdn);
+    }
+
+    private void onGetCSimImsimDone(AsyncResult ar) {
+        byte[] data = (byte[]) ar.result;
+        if (DBG) log("CSIM_IMSIM=" + IccUtils.bytesToHexString(data));
+        // C.S0065 section 5.2.2 for IMSI_M encoding
+        // C.S0005 section 2.3.1 for MIN encoding in IMSI_M.
+        boolean provisioned = ((data[7] & 0x80) == 0x80);
+
+        if (provisioned) {
+            int first3digits = ((0x03 & data[2]) << 8) + (0xFF & data[1]);
+            int second3digits = (((0xFF & data[5]) << 8) | (0xFF & data[4])) >> 6;
+            int digit7 = 0x0F & (data[4] >> 2);
+            if (digit7 > 0x09) digit7 = 0;
+            int last3digits = ((0x03 & data[4]) << 8) | (0xFF & data[3]);
+            first3digits = adjstMinDigits(first3digits);
+            second3digits = adjstMinDigits(second3digits);
+            last3digits = adjstMinDigits(last3digits);
+
+            StringBuilder builder = new StringBuilder();
+            builder.append(String.format(Locale.US, "%03d", first3digits));
+            builder.append(String.format(Locale.US, "%03d", second3digits));
+            builder.append(String.format(Locale.US, "%d", digit7));
+            builder.append(String.format(Locale.US, "%03d", last3digits));
+            if (DBG) log("min present=" + builder.toString());
+
+            mMin = builder.toString();
+        } else {
+            if (DBG) log("min not present");
+        }
+    }
+
+    private int adjstMinDigits (int digits) {
+        // Per C.S0005 section 2.3.1.
+        digits += 111;
+        digits = (digits % 10 == 0)?(digits - 10):digits;
+        digits = ((digits / 10) % 10 == 0)?(digits - 100):digits;
+        digits = ((digits / 100) % 10 == 0)?(digits - 1000):digits;
+        return digits;
+    }
+
+    private void onGetCSimCdmaHomeDone(AsyncResult ar) {
+        // Per C.S0065 section 5.2.8
+        ArrayList<byte[]> dataList = (ArrayList<byte[]>) ar.result;
+        if (DBG) log("CSIM_CDMAHOME data size=" + dataList.size());
+        if (dataList.isEmpty()) {
+            return;
+        }
+        StringBuilder sidBuf = new StringBuilder();
+        StringBuilder nidBuf = new StringBuilder();
+
+        for (byte[] data : dataList) {
+            if (data.length == 5) {
+                int sid = ((data[1] & 0xFF) << 8) | (data[0] & 0xFF);
+                int nid = ((data[3] & 0xFF) << 8) | (data[2] & 0xFF);
+                sidBuf.append(sid).append(",");
+                nidBuf.append(nid).append(",");
+            }
+        }
+        // remove trailing ","
+        sidBuf.setLength(sidBuf.length()-1);
+        nidBuf.setLength(nidBuf.length()-1);
+
+        mHomeSystemId = sidBuf.toString();
+        mHomeNetworkId = nidBuf.toString();
+    }
+
+    private void onGetCSimEprlDone(AsyncResult ar) {
+        // C.S0065 section 5.2.57 for EFeprl encoding
+        // C.S0016 section 3.5.5 for PRL format.
+        byte[] data = (byte[]) ar.result;
+        if (DBG) log("CSIM_EPRL=" + IccUtils.bytesToHexString(data));
+
+        // Only need the first 4 bytes of record
+        if (data.length > 3) {
+            int prlId = ((data[2] & 0xFF) << 8) | (data[3] & 0xFF);
+            mPrlVersion = Integer.toString(prlId);
+        }
+        if (DBG) log("CSIM PRL version=" + mPrlVersion);
+    }
+
+    private void setLocaleFromCsim() {
+        String prefLang = null;
+        // check EFli then EFpl
+        prefLang = findBestLanguage(mEFli);
+
+        if (prefLang == null) {
+            prefLang = findBestLanguage(mEFpl);
+        }
+
+        if (prefLang != null) {
+            // check country code from SIM
+            String imsi = getIMSI();
+            String country = null;
+            if (imsi != null) {
+                country = MccTable.countryCodeForMcc(
+                                    Integer.parseInt(imsi.substring(0,3)));
+            }
+            log("Setting locale to " + prefLang + "_" + country);
+            phone.setSystemLocale(prefLang, country, false);
+        } else {
+            log ("No suitable CSIM selected locale");
+        }
+    }
+
+    private String findBestLanguage(byte[] languages) {
+        String bestMatch = null;
+        String[] locales = phone.getContext().getAssets().getLocales();
+
+        if ((languages == null) || (locales == null)) return null;
+
+        // Each 2-bytes consists of one language
+        for (int i = 0; (i + 1) < languages.length; i += 2) {
+            try {
+                String lang = new String(languages, i, 2, "ISO-8859-1");
+                for (int j = 0; j < locales.length; j++) {
+                    if (locales[j] != null && locales[j].length() >= 2 &&
+                        locales[j].substring(0, 2).equals(lang)) {
+                        return lang;
+                    }
+                }
+                if (bestMatch != null) break;
+            } catch(java.io.UnsupportedEncodingException e) {
+                log ("Failed to parse SIM language records");
+            }
+        }
+        // no match found. return null
+        return null;
+    }
+
+    @Override
+    protected void log(String s) {
+        if (DBG) Log.d(LOG_TAG, "[CSIM] " + s);
+    }
+
+    public String getMdn() {
+        return mMdn;
+    }
+
+    public String getMin() {
+        return mMin;
+    }
+
+    public String getSid() {
+        return mHomeSystemId;
+    }
+
+    public String getNid() {
+        return mHomeNetworkId;
+    }
+
+    public String getPrlVersion() {
+        return mPrlVersion;
+    }
+
+    @Override
+    public boolean isProvisioned() {
+        // If UICC card has CSIM app, look for MDN and MIN field
+        // to determine if the SIM is provisioned.  Otherwise,
+        // consider the SIM is provisioned. (for case of ordinal
+        // USIM only UICC.)
+        if (phone.mIccCard.isApplicationOnIcc(AppType.APPTYPE_CSIM) &&
+            ((mMdn == null) || (mMin == null))) {
+            return false;
+        }
+        return true;
+    }
+}
diff --git a/telephony/java/com/android/internal/telephony/cdma/CdmaSMSDispatcher.java b/telephony/java/com/android/internal/telephony/cdma/CdmaSMSDispatcher.java
old mode 100644
new mode 100755
index cf6b78a..07b0f4f
--- a/telephony/java/com/android/internal/telephony/cdma/CdmaSMSDispatcher.java
+++ b/telephony/java/com/android/internal/telephony/cdma/CdmaSMSDispatcher.java
@@ -41,6 +41,7 @@
 import com.android.internal.telephony.SmsMessageBase;
 import com.android.internal.telephony.SmsMessageBase.TextEncodingDetails;
 import com.android.internal.telephony.TelephonyProperties;
+import com.android.internal.telephony.WspTypeDecoder;
 import com.android.internal.telephony.cdma.sms.SmsEnvelope;
 import com.android.internal.telephony.cdma.sms.UserData;
 import com.android.internal.util.HexDump;
@@ -50,6 +51,8 @@
 import java.util.Arrays;
 import java.util.HashMap;
 
+import android.content.res.Resources;
+
 
 final class CdmaSMSDispatcher extends SMSDispatcher {
     private static final String TAG = "CDMA";
@@ -57,6 +60,9 @@
     private byte[] mLastDispatchedSmsFingerprint;
     private byte[] mLastAcknowledgedSmsFingerprint;
 
+    private boolean mCheckForDuplicatePortsInOmadmWapPush = Resources.getSystem().getBoolean(
+            com.android.internal.R.bool.config_duplicate_port_omadm_wappush);
+
     CdmaSMSDispatcher(CDMAPhone phone) {
         super(phone);
     }
@@ -253,6 +259,13 @@
             sourcePort |= 0xFF & pdu[index++];
             destinationPort = (0xFF & pdu[index++]) << 8;
             destinationPort |= 0xFF & pdu[index++];
+            // Some carriers incorrectly send duplicate port fields in omadm wap pushes.
+            // If configured, check for that here
+            if (mCheckForDuplicatePortsInOmadmWapPush) {
+                if (checkDuplicatePortOmadmWappush(pdu,index)) {
+                    index = index + 4; // skip duplicate port fields
+                }
+            }
         }
 
         // Lookup all other related parts
@@ -273,7 +286,7 @@
             if (cursorCount != totalSegments - 1) {
                 // We don't have all the parts yet, store this one away
                 ContentValues values = new ContentValues();
-                values.put("date", new Long(0));
+                values.put("date", (long) 0);
                 values.put("pdu", HexDump.toHexString(pdu, index, pdu.length - index));
                 values.put("address", address);
                 values.put("reference_number", referenceNumber);
@@ -482,24 +495,6 @@
         }
     }
 
-    /** {@inheritDoc} */
-    @Override
-    public void activateCellBroadcastSms(int activate, Message response) {
-        mCm.setCdmaBroadcastActivation((activate == 0), response);
-    }
-
-    /** {@inheritDoc} */
-    @Override
-    public void getCellBroadcastSmsConfig(Message response) {
-        mCm.getCdmaBroadcastConfig(response);
-    }
-
-    /** {@inheritDoc} */
-    @Override
-    public void setCellBroadcastConfig(int[] configValuesArray, Message response) {
-        mCm.setCdmaBroadcastConfig(configValuesArray, response);
-    }
-
     protected void handleBroadcastSms(AsyncResult ar) {
         // Not supported
         Log.e(TAG, "Error! Not implemented for CDMA.");
@@ -520,4 +515,42 @@
             return CommandsInterface.CDMA_SMS_FAIL_CAUSE_ENCODING_PROBLEM;
         }
     }
+
+    /**
+     * Optional check to see if the received WapPush is an OMADM notification with erroneous
+     * extra port fields.
+     * - Some carriers make this mistake.
+     * ex: MSGTYPE-TotalSegments-CurrentSegment
+     *       -SourcePortDestPort-SourcePortDestPort-OMADM PDU
+     * @param origPdu The WAP-WDP PDU segment
+     * @param index Current Index while parsing the PDU.
+     * @return True if OrigPdu is OmaDM Push Message which has duplicate ports.
+     *         False if OrigPdu is NOT OmaDM Push Message which has duplicate ports.
+     */
+    private boolean checkDuplicatePortOmadmWappush(byte[] origPdu, int index) {
+        index += 4;
+        byte[] omaPdu = new byte[origPdu.length - index];
+        System.arraycopy(origPdu, index, omaPdu, 0, omaPdu.length);
+
+        WspTypeDecoder pduDecoder = new WspTypeDecoder(omaPdu);
+        int wspIndex = 2;
+
+        // Process header length field
+        if (pduDecoder.decodeUintvarInteger(wspIndex) == false) {
+            return false;
+        }
+
+        wspIndex += pduDecoder.getDecodedDataLength(); // advance to next field
+
+        // Process content type field
+        if (pduDecoder.decodeContentType(wspIndex) == false) {
+            return false;
+        }
+
+        String mimeType = pduDecoder.getValueString();
+        if (mimeType != null && mimeType.equals(WspTypeDecoder.CONTENT_TYPE_B_PUSH_SYNCML_NOTI)) {
+            return true;
+        }
+        return false;
+    }
 }
diff --git a/telephony/java/com/android/internal/telephony/cdma/CdmaServiceStateTracker.java b/telephony/java/com/android/internal/telephony/cdma/CdmaServiceStateTracker.java
index 35a98edc..5ebdd22 100755
--- a/telephony/java/com/android/internal/telephony/cdma/CdmaServiceStateTracker.java
+++ b/telephony/java/com/android/internal/telephony/cdma/CdmaServiceStateTracker.java
@@ -129,15 +129,15 @@
     /** Contains the name of the registered network in CDMA (either ONS or ERI text). */
     private String curPlmn = null;
 
-    private String mMdn;
+    protected String mMdn;
     private int mHomeSystemId[] = null;
     private int mHomeNetworkId[] = null;
-    private String mMin;
-    private String mPrlVersion;
-    private boolean mIsMinInfoReady = false;
+    protected String mMin;
+    protected String mPrlVersion;
+    protected boolean mIsMinInfoReady = false;
 
     private boolean isEriTextLoaded = false;
-    private boolean isSubscriptionFromRuim = false;
+    protected boolean isSubscriptionFromRuim = false;
 
     /* Used only for debugging purposes. */
     private String mRegistrationDeniedReason;
@@ -253,6 +253,7 @@
 
         switch (msg.what) {
         case EVENT_RADIO_AVAILABLE:
+            if (DBG) log("handleMessage: EVENT_RADIO_AVAILABLE");
             break;
 
         case EVENT_RUIM_READY:
@@ -266,7 +267,7 @@
             }
 
             cm.getCDMASubscription(obtainMessage(EVENT_POLL_STATE_CDMA_SUBSCRIPTION));
-            if (DBG) log("Receive EVENT_RUIM_READY and Send Request getCDMASubscription.");
+            if (DBG) log("handleMessage: EVENT_RUIM_READY, Send Request getCDMASubscription.");
 
             // Restore the previous network selection.
             pollState();
@@ -280,6 +281,7 @@
             // For Non-RUIM phones, the subscription information is stored in
             // Non Volatile. Here when Non-Volatile is ready, we can poll the CDMA
             // subscription info.
+            if (DBG) log("handleMessage: EVENT_NV_READY, Send Request getCDMASubscription.");
             cm.getCDMASubscription( obtainMessage(EVENT_POLL_STATE_CDMA_SUBSCRIPTION));
             pollState();
             // Signal strength polling stops when radio is off.
@@ -371,53 +373,15 @@
                 String cdmaSubscription[] = (String[])ar.result;
                 if (cdmaSubscription != null && cdmaSubscription.length >= 5) {
                     mMdn = cdmaSubscription[0];
-                    if (cdmaSubscription[1] != null) {
-                        String[] sid = cdmaSubscription[1].split(",");
-                        mHomeSystemId = new int[sid.length];
-                        for (int i = 0; i < sid.length; i++) {
-                            try {
-                                mHomeSystemId[i] = Integer.parseInt(sid[i]);
-                            } catch (NumberFormatException ex) {
-                                loge("error parsing system id: " + ex);
-                            }
-                        }
-                    }
-                    if (DBG) log("GET_CDMA_SUBSCRIPTION: SID=" + cdmaSubscription[1] );
+                    parseSidNid(cdmaSubscription[1], cdmaSubscription[2]);
 
-                    if (cdmaSubscription[2] != null) {
-                        String[] nid = cdmaSubscription[2].split(",");
-                        mHomeNetworkId = new int[nid.length];
-                        for (int i = 0; i < nid.length; i++) {
-                            try {
-                                mHomeNetworkId[i] = Integer.parseInt(nid[i]);
-                            } catch (NumberFormatException ex) {
-                                loge("GET_CDMA_SUBSCRIPTION: error parsing network id: " + ex);
-                            }
-                        }
-                    }
-                    if (DBG) log("GET_CDMA_SUBSCRIPTION: NID=" + cdmaSubscription[2]);
                     mMin = cdmaSubscription[3];
                     mPrlVersion = cdmaSubscription[4];
                     if (DBG) log("GET_CDMA_SUBSCRIPTION: MDN=" + mMdn);
 
                     mIsMinInfoReady = true;
 
-                    int otaspMode = getOtasp();
-                    int oldOtaspMode = mCurrentOtaspMode;
-                    mCurrentOtaspMode = otaspMode;
-
-                    // Notify apps subscription info is ready
-                    if (cdmaForSubscriptionInfoReadyRegistrants != null) {
-                        if (DBG) log("GET_CDMA_SUBSCRIPTION: call notifyRegistrants()");
-                        cdmaForSubscriptionInfoReadyRegistrants.notifyRegistrants();
-                    }
-                    if (oldOtaspMode != mCurrentOtaspMode) {
-                        if (DBG) {
-                            log("GET_CDMA_SUBSCRIPTION: call notifyOtaspChanged old otaspMode=" +
-                                oldOtaspMode + " new otaspMode=" + mCurrentOtaspMode);
-                        }
-                        phone.notifyOtaspChanged(mCurrentOtaspMode);
-                    }
+                    updateOtaspState();
                     phone.getIccCard().broadcastIccStateChangedIntent(IccCard.INTENT_VALUE_ICC_IMSI,
                             null);
                 } else {
@@ -871,36 +835,6 @@
         }
     }
 
-    protected static String networkTypeToString(int type) {
-        String ret = "unknown";
-
-        switch (type) {
-        case ServiceState.RADIO_TECHNOLOGY_IS95A:
-        case ServiceState.RADIO_TECHNOLOGY_IS95B:
-            ret = "CDMA";
-            break;
-        case ServiceState.RADIO_TECHNOLOGY_1xRTT:
-            ret = "CDMA - 1xRTT";
-            break;
-        case ServiceState.RADIO_TECHNOLOGY_EVDO_0:
-            ret = "CDMA - EvDo rev. 0";
-            break;
-        case ServiceState.RADIO_TECHNOLOGY_EVDO_A:
-            ret = "CDMA - EvDo rev. A";
-            break;
-        case ServiceState.RADIO_TECHNOLOGY_EVDO_B:
-            ret = "CDMA - EvDo rev. B";
-            break;
-        default:
-            if (DBG) {
-                slog("Wrong network. Can not return a string.");
-            }
-        break;
-        }
-
-        return ret;
-    }
-
     protected void fixTimeZone(String isoCountryCode) {
         TimeZone zone = null;
         // If the offset is (0, false) and the time zone property
@@ -998,7 +932,7 @@
 
         if (hasNetworkTypeChanged) {
             phone.setSystemProperty(TelephonyProperties.PROPERTY_DATA_NETWORK_TYPE,
-                    networkTypeToString(networkType));
+                    ServiceState.radioTechnologyToString(networkType));
         }
 
         if (hasRegistered) {
@@ -1017,7 +951,7 @@
                     eriText = phone.getContext().getText(
                             com.android.internal.R.string.roamingTextSearching).toString();
                 }
-                ss.setCdmaEriText(eriText);
+                ss.setOperatorAlphaLong(eriText);
             }
 
             String operatorNumeric;
@@ -1120,7 +1054,7 @@
      * This code should probably be hoisted to the base class so
      * the fix, when added, works for both.
      */
-    private void
+    protected void
     queueNextSignalStrengthPoll() {
         if (dontPollSignalStrength || (cm.getRadioState().isGsm())) {
             // The radio is telling us about signal strength changes
@@ -1217,18 +1151,6 @@
         }
     }
 
-    /**
-     * @return The current CDMA data connection state. ServiceState.RADIO_TECHNOLOGY_1xRTT or
-     * ServiceState.RADIO_TECHNOLOGY_EVDO is the same as "attached" and
-     * ServiceState.RADIO_TECHNOLOGY_UNKNOWN is the same as detached.
-     */
-    /*package*/ int getCurrentCdmaDataConnectionState() {
-        return mDataConnectionState;
-    }
-
-    /**
-    * TODO: In the future, we need remove getCurrentCdmaDataConnectionState
-    */
     public int getCurrentDataConnectionState() {
         return mDataConnectionState;
     }
@@ -1662,6 +1584,53 @@
         cm.setRadioPower(false, null);
     }
 
+    protected void parseSidNid (String sidStr, String nidStr) {
+        if (sidStr != null) {
+            String[] sid = sidStr.split(",");
+            mHomeSystemId = new int[sid.length];
+            for (int i = 0; i < sid.length; i++) {
+                try {
+                    mHomeSystemId[i] = Integer.parseInt(sid[i]);
+                } catch (NumberFormatException ex) {
+                    loge("error parsing system id: " + ex);
+                }
+            }
+        }
+        if (DBG) log("CDMA_SUBSCRIPTION: SID=" + sidStr);
+
+        if (nidStr != null) {
+            String[] nid = nidStr.split(",");
+            mHomeNetworkId = new int[nid.length];
+            for (int i = 0; i < nid.length; i++) {
+                try {
+                    mHomeNetworkId[i] = Integer.parseInt(nid[i]);
+                } catch (NumberFormatException ex) {
+                    loge("CDMA_SUBSCRIPTION: error parsing network id: " + ex);
+                }
+            }
+        }
+        if (DBG) log("CDMA_SUBSCRIPTION: NID=" + nidStr);
+    }
+
+    protected void updateOtaspState() {
+        int otaspMode = getOtasp();
+        int oldOtaspMode = mCurrentOtaspMode;
+        mCurrentOtaspMode = otaspMode;
+
+        // Notify apps subscription info is ready
+        if (cdmaForSubscriptionInfoReadyRegistrants != null) {
+            if (DBG) log("CDMA_SUBSCRIPTION: call notifyRegistrants()");
+            cdmaForSubscriptionInfoReadyRegistrants.notifyRegistrants();
+        }
+        if (oldOtaspMode != mCurrentOtaspMode) {
+            if (DBG) {
+                log("CDMA_SUBSCRIPTION: call notifyOtaspChanged old otaspMode=" +
+                    oldOtaspMode + " new otaspMode=" + mCurrentOtaspMode);
+            }
+            phone.notifyOtaspChanged(mCurrentOtaspMode);
+        }
+    }
+
     @Override
     protected void log(String s) {
         Log.d(LOG_TAG, "[CdmaSST] " + s);
@@ -1671,8 +1640,4 @@
     protected void loge(String s) {
         Log.e(LOG_TAG, "[CdmaSST] " + s);
     }
-
-    private static void slog(String s) {
-        Log.d(LOG_TAG, "[CdmaSST] " + s);
-    }
 }
diff --git a/telephony/java/com/android/internal/telephony/cdma/RuimPhoneBookInterfaceManager.java b/telephony/java/com/android/internal/telephony/cdma/RuimPhoneBookInterfaceManager.java
index ce33066..04ee2dd8 100644
--- a/telephony/java/com/android/internal/telephony/cdma/RuimPhoneBookInterfaceManager.java
+++ b/telephony/java/com/android/internal/telephony/cdma/RuimPhoneBookInterfaceManager.java
@@ -16,6 +16,8 @@
 
 package com.android.internal.telephony.cdma;
 
+import java.util.concurrent.atomic.AtomicBoolean;
+
 import android.os.Message;
 import android.util.Log;
 
@@ -56,14 +58,11 @@
             recordSize = new int[3];
 
             //Using mBaseHandler, no difference in EVENT_GET_SIZE_DONE handling
-            Message response = mBaseHandler.obtainMessage(EVENT_GET_SIZE_DONE);
+            AtomicBoolean status = new AtomicBoolean(false);
+            Message response = mBaseHandler.obtainMessage(EVENT_GET_SIZE_DONE, status);
 
             phone.getIccFileHandler().getEFLinearRecordSize(efid, response);
-            try {
-                mLock.wait();
-            } catch (InterruptedException e) {
-                logd("interrupted while trying to load from the RUIM");
-            }
+            waitForResult(status);
         }
 
         return recordSize;
diff --git a/telephony/java/com/android/internal/telephony/cdma/RuimRecords.java b/telephony/java/com/android/internal/telephony/cdma/RuimRecords.java
index ee63ede..9af2d26 100755
--- a/telephony/java/com/android/internal/telephony/cdma/RuimRecords.java
+++ b/telephony/java/com/android/internal/telephony/cdma/RuimRecords.java
@@ -119,8 +119,11 @@
 
         adnCache.reset();
 
-        phone.setSystemProperty(PROPERTY_ICC_OPERATOR_NUMERIC, null);
-        phone.setSystemProperty(PROPERTY_ICC_OPERATOR_ISO_COUNTRY, null);
+        // Don't clean up PROPERTY_ICC_OPERATOR_ISO_COUNTRY and
+        // PROPERTY_ICC_OPERATOR_NUMERIC here. Since not all CDMA
+        // devices have RUIM, these properties should keep the original
+        // values, e.g. build time settings, when there is no RUIM but
+        // set new values when RUIM is available and loaded.
 
         // recordsRequested is set to false indicating that the SIM
         // read requests made so far are not valid. This is set to
diff --git a/telephony/java/com/android/internal/telephony/cdma/RuimSmsInterfaceManager.java b/telephony/java/com/android/internal/telephony/cdma/RuimSmsInterfaceManager.java
index 29f3bc1..9cd059d 100644
--- a/telephony/java/com/android/internal/telephony/cdma/RuimSmsInterfaceManager.java
+++ b/telephony/java/com/android/internal/telephony/cdma/RuimSmsInterfaceManager.java
@@ -203,6 +203,18 @@
         return false;
     }
 
+    public boolean enableCellBroadcastRange(int startMessageId, int endMessageId) {
+        // Not implemented
+        Log.e(LOG_TAG, "Error! Not implemented for CDMA.");
+        return false;
+    }
+
+    public boolean disableCellBroadcastRange(int startMessageId, int endMessageId) {
+        // Not implemented
+        Log.e(LOG_TAG, "Error! Not implemented for CDMA.");
+        return false;
+    }
+
     protected void log(String msg) {
         Log.d(LOG_TAG, "[RuimSmsInterfaceManager] " + msg);
     }
diff --git a/telephony/java/com/android/internal/telephony/cdma/SmsMessage.java b/telephony/java/com/android/internal/telephony/cdma/SmsMessage.java
index 3f4cd67..be5c616 100644
--- a/telephony/java/com/android/internal/telephony/cdma/SmsMessage.java
+++ b/telephony/java/com/android/internal/telephony/cdma/SmsMessage.java
@@ -18,6 +18,7 @@
 
 import android.os.Parcel;
 import android.os.SystemProperties;
+import android.telephony.PhoneNumberUtils;
 import android.util.Log;
 import com.android.internal.telephony.IccUtils;
 import com.android.internal.telephony.SmsHeader;
@@ -806,7 +807,12 @@
          * mechanism, and avoid null pointer exceptions.
          */
 
-        CdmaSmsAddress destAddr = CdmaSmsAddress.parse(destAddrStr);
+        /**
+         * North America Plus Code :
+         * Convert + code to 011 and dial out for international SMS
+         */
+        CdmaSmsAddress destAddr = CdmaSmsAddress.parse(
+                PhoneNumberUtils.cdmaCheckAndProcessPlusCode(destAddrStr));
         if (destAddr == null) return null;
 
         BearerData bearerData = new BearerData();
diff --git a/telephony/java/com/android/internal/telephony/gsm/GSMPhone.java b/telephony/java/com/android/internal/telephony/gsm/GSMPhone.java
index 3ccc03d..d357eac 100644
--- a/telephony/java/com/android/internal/telephony/gsm/GSMPhone.java
+++ b/telephony/java/com/android/internal/telephony/gsm/GSMPhone.java
@@ -301,6 +301,9 @@
             ret = DataState.DISCONNECTED;
         } else if (mDataConnectionTracker.isApnTypeEnabled(apnType) == false ||
                 mDataConnectionTracker.isApnTypeActive(apnType) == false) {
+            //TODO: isApnTypeActive() is just checking whether ApnContext holds
+            //      Dataconnection or not. Checking each ApnState below should
+            //      provide the same state. Calling isApnTypeActive() can be removed.
             ret = DataState.DISCONNECTED;
         } else { /* mSST.gprsState == ServiceState.STATE_IN_SERVICE */
             switch (mDataConnectionTracker.getState(apnType)) {
@@ -1427,16 +1430,35 @@
         return this.mIccFileHandler;
     }
 
+    /**
+     * Activate or deactivate cell broadcast SMS.
+     *
+     * @param activate 0 = activate, 1 = deactivate
+     * @param response Callback message is empty on completion
+     */
     public void activateCellBroadcastSms(int activate, Message response) {
-        Log.e(LOG_TAG, "Error! This functionality is not implemented for GSM.");
+        Log.e(LOG_TAG, "[GSMPhone] activateCellBroadcastSms() is obsolete; use SmsManager");
+        response.sendToTarget();
     }
 
+    /**
+     * Query the current configuration of cdma cell broadcast SMS.
+     *
+     * @param response Callback message is empty on completion
+     */
     public void getCellBroadcastSmsConfig(Message response) {
-        Log.e(LOG_TAG, "Error! This functionality is not implemented for GSM.");
+        Log.e(LOG_TAG, "[GSMPhone] getCellBroadcastSmsConfig() is obsolete; use SmsManager");
+        response.sendToTarget();
     }
 
-    public void setCellBroadcastSmsConfig(int[] configValuesArray, Message response){
-        Log.e(LOG_TAG, "Error! This functionality is not implemented for GSM.");
+    /**
+     * Configure cdma cell broadcast SMS.
+     *
+     * @param response Callback message is empty on completion
+     */
+    public void setCellBroadcastSmsConfig(int[] configValuesArray, Message response) {
+        Log.e(LOG_TAG, "[GSMPhone] setCellBroadcastSmsConfig() is obsolete; use SmsManager");
+        response.sendToTarget();
     }
 
     public boolean isCspPlmnEnabled() {
diff --git a/telephony/java/com/android/internal/telephony/gsm/GsmDataConnectionTracker.java b/telephony/java/com/android/internal/telephony/gsm/GsmDataConnectionTracker.java
index e1a6fef..19c06f6 100644
--- a/telephony/java/com/android/internal/telephony/gsm/GsmDataConnectionTracker.java
+++ b/telephony/java/com/android/internal/telephony/gsm/GsmDataConnectionTracker.java
@@ -22,6 +22,7 @@
 import android.content.ContentValues;
 import android.content.Context;
 import android.content.Intent;
+import android.content.IntentFilter;
 import android.database.ContentObserver;
 import android.database.Cursor;
 import android.net.ConnectivityManager;
@@ -204,28 +205,6 @@
         return (apnContext.getDataConnection() != null);
     }
 
-    /**
-     * The only circumstances under which we report that data connectivity is not
-     * possible are
-     * <ul>
-     * <li>Data is disallowed (roaming, power state, voice call, etc).</li>
-     * <li>The current data state is {@code DISCONNECTED} for a reason other than
-     * having explicitly disabled connectivity. In other words, data is not available
-     * because the phone is out of coverage or some like reason.</li>
-     * </ul>
-     * @return {@code true} if data connectivity is possible, {@code false} otherwise.
-     * TODO - do per-apn notifications of availability using dependencyMet values.
-     */
-    @Override
-    protected boolean isDataPossible() {
-        boolean possible = (isDataAllowed()
-                && !(getAnyDataEnabled() && (getOverallState() == State.FAILED)));
-        if (!possible && DBG && isDataAllowed()) {
-            if (DBG) log("Data not possible.  No coverage: dataState = " + getOverallState());
-        }
-        return possible;
-    }
-
     @Override
     protected boolean isDataPossible(String apnType) {
         ApnContext apnContext = mApnContexts.get(apnType);
@@ -582,6 +561,7 @@
         boolean allowed =
                     (gprsState == ServiceState.STATE_IN_SERVICE || mAutoAttachOnCreation) &&
                     mPhone.mIccRecords.getRecordsLoaded() &&
+                    mPhone.mIccRecords.isProvisioned() &&
                     mPhone.getState() == Phone.State.IDLE &&
                     mInternalDataEnabled &&
                     (!mPhone.getServiceState().getRoaming() || getDataOnRoamingEnabled()) &&
@@ -593,6 +573,7 @@
                 reason += " - gprs= " + gprsState;
             }
             if (!mPhone.mIccRecords.getRecordsLoaded()) reason += " - SIM not loaded";
+            if (!mPhone.mIccRecords.isProvisioned()) reason += " - SIM not provisioned";
             if (mPhone.getState() != Phone.State.IDLE) {
                 reason += " - PhoneState= " + mPhone.getState();
             }
@@ -607,33 +588,6 @@
         return allowed;
     }
 
-    /**
-     * Release the apnContext
-     *
-     * @param apnContext
-     * @param tearDown
-     * @return none
-     */
-    private void releaseApnContext(ApnContext apnContext, boolean tearDown) {
-        if (apnContext == null) {
-            if (DBG) loge("releaseApnContext: apnContext null should not happen, ignore");
-            return;
-        }
-        DataConnection dc = apnContext.getDataConnection();
-        if (dc == null) {
-            if (DBG) loge("releaseApnContext: apnContext dc == null should not happen, ignore");
-            return;
-        }
-        if (tearDown) {
-            if (DBG) log("releaseApnContext: tearing down");
-            Message msg = obtainMessage(EVENT_DISCONNECT_DONE, apnContext);
-            apnContext.getDataConnection().tearDown(apnContext.getReason(), msg);
-        }
-        apnContext.setDataConnection(null);
-        apnContext.setDataConnectionAc(null);
-        return;
-    }
-
     private void setupDataOnReadyApns(String reason) {
         // Only check for default APN state
         for (ApnContext apnContext : mApnContexts.values()) {
@@ -802,17 +756,17 @@
         }
 
         DataConnectionAc dcac = apnContext.getDataConnectionAc();
-        if (dcac != null) {
-            if (tearDown) {
-                apnContext.setState(State.DISCONNECTING);
-                releaseApnContext(apnContext, tearDown);
-            } else {
-                dcac.resetSync();
-                apnContext.setState(State.IDLE);
-                mPhone.notifyDataConnection(apnContext.getReason(), apnContext.getApnType());
-                apnContext.setDataConnection(null);
-                apnContext.setDataConnectionAc(null);
-            }
+        if (tearDown && (dcac != null)) {
+            if (DBG) log("cleanUpConnection: tearing down");
+            Message msg = obtainMessage(EVENT_DISCONNECT_DONE, apnContext);
+            apnContext.getDataConnection().tearDown(apnContext.getReason(), msg);
+            apnContext.setState(State.DISCONNECTING);
+        } else {
+            if (dcac != null) dcac.resetSync();
+            apnContext.setState(State.IDLE);
+            mPhone.notifyDataConnection(apnContext.getReason(), apnContext.getApnType());
+            apnContext.setDataConnection(null);
+            apnContext.setDataConnectionAc(null);
         }
     }
 
@@ -1427,7 +1381,13 @@
 
         AlarmManager am =
             (AlarmManager) mPhone.getContext().getSystemService(Context.ALARM_SERVICE);
-        Intent intent = new Intent(INTENT_RECONNECT_ALARM);
+
+        // TODO : Register the receiver only once maybe in baseclass.
+        IntentFilter filter = new IntentFilter();
+        filter.addAction(INTENT_RECONNECT_ALARM + '.'+apnContext.getApnType());
+        mPhone.getContext().registerReceiver(mIntentReceiver, filter, null, mPhone);
+
+        Intent intent = new Intent(INTENT_RECONNECT_ALARM + '.' + apnContext.getApnType());
         intent.putExtra(INTENT_RECONNECT_ALARM_EXTRA_REASON, apnContext.getReason());
         intent.putExtra(INTENT_RECONNECT_ALARM_EXTRA_TYPE, apnContext.getApnType());
         apnContext.setReconnectIntent(PendingIntent.getBroadcast (
@@ -1697,7 +1657,8 @@
                     apnContext.setState(State.FAILED);
                     mPhone.notifyDataConnection(Phone.REASON_APN_FAILED, apnContext.getApnType());
 
-                    releaseApnContext(apnContext, false);
+                    apnContext.setDataConnection(null);
+                    apnContext.setDataConnectionAc(null);
                     if (DBG) {
                         log("onDataSetupComplete: permanent error apn=%s" + apnString );
                     }
@@ -1732,6 +1693,8 @@
 
         apnContext.setState(State.IDLE);
         apnContext.setApnSetting(null);
+        apnContext.setDataConnection(null);
+        apnContext.setDataConnectionAc(null);
 
         mPhone.notifyDataConnection(apnContext.getReason(), apnContext.getApnType());
 
@@ -1887,7 +1850,7 @@
             if (!dc.configureRetry(SystemProperties.get("ro.gsm.data_retry_config"))) {
                 if (!dc.configureRetry(DEFAULT_DATA_RETRY_CONFIG)) {
                     // Should never happen, log an error and default to a simple linear sequence.
-                    loge("createDataConnection: Could not configure using " +
+                    loge("configureRetry: Could not configure using " +
                             "DEFAULT_DATA_RETRY_CONFIG=" + DEFAULT_DATA_RETRY_CONFIG);
                     dc.configureRetry(20, 2000, 1000);
                 }
@@ -1896,7 +1859,7 @@
             if (!dc.configureRetry(SystemProperties.get("ro.gsm.2nd_data_retry_config"))) {
                 if (!dc.configureRetry(SECONDARY_DATA_RETRY_CONFIG)) {
                     // Should never happen, log an error and default to a simple sequence.
-                    loge("createDataConnection: Could note configure using " +
+                    loge("configureRetry: Could note configure using " +
                             "SECONDARY_DATA_RETRY_CONFIG=" + SECONDARY_DATA_RETRY_CONFIG);
                     dc.configureRetry("max_retries=3, 333, 333, 333");
                 }
@@ -1909,7 +1872,7 @@
             if (DBG) log("destroyDataConnections: clear mDataConnectionList");
             mDataConnections.clear();
         } else {
-            if (DBG) log("destroyDataConnectionList mDataConnecitonList is empty, ignore");
+            if (DBG) log("destroyDataConnections: mDataConnecitonList is empty, ignore");
         }
     }
 
diff --git a/telephony/java/com/android/internal/telephony/gsm/GsmSMSDispatcher.java b/telephony/java/com/android/internal/telephony/gsm/GsmSMSDispatcher.java
old mode 100755
new mode 100644
index b021967..52ca453
--- a/telephony/java/com/android/internal/telephony/gsm/GsmSMSDispatcher.java
+++ b/telephony/java/com/android/internal/telephony/gsm/GsmSMSDispatcher.java
@@ -391,30 +391,6 @@
         }
     }
 
-    /** {@inheritDoc} */
-    @Override
-    public void activateCellBroadcastSms(int activate, Message response) {
-        // Unless CBS is implemented for GSM, this point should be unreachable.
-        Log.e(TAG, "Error! The functionality cell broadcast sms is not implemented for GSM.");
-        response.recycle();
-    }
-
-    /** {@inheritDoc} */
-    @Override
-    public void getCellBroadcastSmsConfig(Message response){
-        // Unless CBS is implemented for GSM, this point should be unreachable.
-        Log.e(TAG, "Error! The functionality cell broadcast sms is not implemented for GSM.");
-        response.recycle();
-    }
-
-    /** {@inheritDoc} */
-    @Override
-    public  void setCellBroadcastConfig(int[] configValuesArray, Message response) {
-        // Unless CBS is implemented for GSM, this point should be unreachable.
-        Log.e(TAG, "Error! The functionality cell broadcast sms is not implemented for GSM.");
-        response.recycle();
-    }
-
     private int resultToCause(int rc) {
         switch (rc) {
             case Activity.RESULT_OK:
@@ -506,9 +482,10 @@
     }
 
     // This map holds incomplete concatenated messages waiting for assembly
-    private HashMap<SmsCbConcatInfo, byte[][]> mSmsCbPageMap =
+    private final HashMap<SmsCbConcatInfo, byte[][]> mSmsCbPageMap =
             new HashMap<SmsCbConcatInfo, byte[][]>();
 
+    @Override
     protected void handleBroadcastSms(AsyncResult ar) {
         try {
             byte[][] pdus = null;
@@ -520,9 +497,9 @@
                     for (int j = i; j < i + 8 && j < receivedPdu.length; j++) {
                         int b = receivedPdu[j] & 0xff;
                         if (b < 0x10) {
-                            sb.append("0");
+                            sb.append('0');
                         }
-                        sb.append(Integer.toHexString(b)).append(" ");
+                        sb.append(Integer.toHexString(b)).append(' ');
                     }
                     Log.d(TAG, sb.toString());
                 }
@@ -567,7 +544,8 @@
                 pdus[0] = receivedPdu;
             }
 
-            dispatchBroadcastPdus(pdus);
+            boolean isEmergencyMessage = SmsCbHeader.isEmergencyMessage(header.messageIdentifier);
+            dispatchBroadcastPdus(pdus, isEmergencyMessage);
 
             // Remove messages that are out of scope to prevent the map from
             // growing indefinitely, containing incomplete messages that were
diff --git a/telephony/java/com/android/internal/telephony/gsm/GsmServiceStateTracker.java b/telephony/java/com/android/internal/telephony/gsm/GsmServiceStateTracker.java
index 4352831..93f4b4e 100644
--- a/telephony/java/com/android/internal/telephony/gsm/GsmServiceStateTracker.java
+++ b/telephony/java/com/android/internal/telephony/gsm/GsmServiceStateTracker.java
@@ -84,12 +84,6 @@
     private int mNewReasonDataDenied = -1;
 
     /**
-     *  Values correspond to ServiceState.RADIO_TECHNOLOGY_ definitions.
-     */
-    private int networkType = 0;
-    private int newNetworkType = 0;
-
-    /**
      * GSM roaming status solely based on TS 27.007 7.2 CREG. Only used by
      * handlePollStateResult to store CREG roaming result.
      */
@@ -628,7 +622,7 @@
                     }
                     newGPRSState = regCodeToServiceState(regState);
                     mDataRoaming = regCodeIsRoaming(regState);
-                    newNetworkType = type;
+                    mNewRadioTechnology = type;
                     newSS.setRadioTechnology(type);
                 break;
 
@@ -748,37 +742,6 @@
         }
     }
 
-    private static String networkTypeToString(int type) {
-        //Network Type from GPRS_REGISTRATION_STATE
-        String ret = "unknown";
-
-        switch (type) {
-            case ServiceState.RADIO_TECHNOLOGY_GPRS:
-                ret = "GPRS";
-                break;
-            case ServiceState.RADIO_TECHNOLOGY_EDGE:
-                ret = "EDGE";
-                break;
-            case ServiceState.RADIO_TECHNOLOGY_UMTS:
-                ret = "UMTS";
-                break;
-            case ServiceState.RADIO_TECHNOLOGY_HSDPA:
-                ret = "HSDPA";
-                break;
-            case ServiceState.RADIO_TECHNOLOGY_HSUPA:
-                ret = "HSUPA";
-                break;
-            case ServiceState.RADIO_TECHNOLOGY_HSPA:
-                ret = "HSPA";
-                break;
-            default:
-                sloge("Wrong network type: " + Integer.toString(type));
-                break;
-        }
-
-        return ret;
-    }
-
     private void pollStateDone() {
         if (DBG) {
             log("Poll ServiceState done: " +
@@ -788,8 +751,8 @@
                 " mNewMaxDataCalls=" + mNewMaxDataCalls +
                 " oldReasonDataDenied=" + mReasonDataDenied +
                 " mNewReasonDataDenied=" + mNewReasonDataDenied +
-                " oldType=" + networkTypeToString(networkType) +
-                " newType=" + networkTypeToString(newNetworkType));
+                " oldType=" + ServiceState.radioTechnologyToString(mRadioTechnology) +
+                " newType=" + ServiceState.radioTechnologyToString(mNewRadioTechnology));
         }
 
         boolean hasRegistered =
@@ -808,7 +771,7 @@
                 gprsState == ServiceState.STATE_IN_SERVICE
                 && newGPRSState != ServiceState.STATE_IN_SERVICE;
 
-        boolean hasNetworkTypeChanged = networkType != newNetworkType;
+        boolean hasRadioTechnologyChanged = mRadioTechnology != mNewRadioTechnology;
 
         boolean hasChanged = !newSS.equals(ss);
 
@@ -838,30 +801,32 @@
         // Add an event log when network type switched
         // TODO: we may add filtering to reduce the event logged,
         // i.e. check preferred network setting, only switch to 2G, etc
-        if (hasNetworkTypeChanged) {
+        if (hasRadioTechnologyChanged) {
             int cid = -1;
             GsmCellLocation loc = ((GsmCellLocation)phone.getCellLocation());
             if (loc != null) cid = loc.getCid();
-            EventLog.writeEvent(EventLogTags.GSM_RAT_SWITCHED, cid, networkType, newNetworkType);
+            EventLog.writeEvent(EventLogTags.GSM_RAT_SWITCHED, cid, mRadioTechnology,
+                    mNewRadioTechnology);
             if (DBG) {
-                log("RAT switched " + networkTypeToString(networkType) + " -> "
-                    + networkTypeToString(newNetworkType) + " at cell " + cid);
+                log("RAT switched " + ServiceState.radioTechnologyToString(mRadioTechnology) +
+                        " -> " + ServiceState.radioTechnologyToString(mNewRadioTechnology) +
+                        " at cell " + cid);
             }
         }
 
         gprsState = newGPRSState;
         mReasonDataDenied = mNewReasonDataDenied;
         mMaxDataCalls = mNewMaxDataCalls;
-        networkType = newNetworkType;
+        mRadioTechnology = mNewRadioTechnology;
         // this new state has been applied - forget it until we get a new new state
-        newNetworkType = 0;
+        mNewRadioTechnology = 0;
 
 
         newSS.setStateOutOfService(); // clean slate for next time
 
-        if (hasNetworkTypeChanged) {
+        if (hasRadioTechnologyChanged) {
             phone.setSystemProperty(TelephonyProperties.PROPERTY_DATA_NETWORK_TYPE,
-                    networkTypeToString(networkType));
+                    ServiceState.radioTechnologyToString(mRadioTechnology));
         }
 
         if (hasRegistered) {
@@ -949,7 +914,7 @@
             mDetachedRegistrants.notifyRegistrants();
         }
 
-        if (hasNetworkTypeChanged) {
+        if (hasRadioTechnologyChanged) {
             phone.notifyDataConnection(Phone.REASON_NW_TYPE_CHANGED, Phone.APN_TYPE_ALL);
         }
 
@@ -1285,7 +1250,7 @@
      * that could support voice and data simultaneously.
      */
     public boolean isConcurrentVoiceAndDataAllowed() {
-        return (networkType >= ServiceState.RADIO_TECHNOLOGY_UMTS);
+        return (mRadioTechnology >= ServiceState.RADIO_TECHNOLOGY_UMTS);
     }
 
     /**
diff --git a/telephony/java/com/android/internal/telephony/gsm/SIMRecords.java b/telephony/java/com/android/internal/telephony/gsm/SIMRecords.java
index 891c7cb..b0bad56 100755
--- a/telephony/java/com/android/internal/telephony/gsm/SIMRecords.java
+++ b/telephony/java/com/android/internal/telephony/gsm/SIMRecords.java
@@ -45,12 +45,12 @@
 /**
  * {@hide}
  */
-public final class SIMRecords extends IccRecords {
-    static final String LOG_TAG = "GSM";
+public class SIMRecords extends IccRecords {
+    protected static final String LOG_TAG = "GSM";
 
     private static final boolean CRASH_RIL = false;
 
-    private static final boolean DBG = true;
+    protected static final boolean DBG = true;
 
     // ***** Instance Variables
 
@@ -120,13 +120,13 @@
 
     private static final int EVENT_SIM_READY = 1;
     private static final int EVENT_RADIO_OFF_OR_NOT_AVAILABLE = 2;
-    private static final int EVENT_GET_IMSI_DONE = 3;
-    private static final int EVENT_GET_ICCID_DONE = 4;
+    protected static final int EVENT_GET_IMSI_DONE = 3;
+    protected static final int EVENT_GET_ICCID_DONE = 4;
     private static final int EVENT_GET_MBI_DONE = 5;
     private static final int EVENT_GET_MBDN_DONE = 6;
     private static final int EVENT_GET_MWIS_DONE = 7;
     private static final int EVENT_GET_VOICE_MAIL_INDICATOR_CPHS_DONE = 8;
-    private static final int EVENT_GET_AD_DONE = 9; // Admin data on SIM
+    protected static final int EVENT_GET_AD_DONE = 9; // Admin data on SIM
     private static final int EVENT_GET_MSISDN_DONE = 10;
     private static final int EVENT_GET_CPHS_MAILBOX_DONE = 11;
     private static final int EVENT_GET_SPN_DONE = 12;
@@ -147,6 +147,8 @@
     private static final int EVENT_GET_CFIS_DONE = 32;
     private static final int EVENT_GET_CSP_CPHS_DONE = 33;
 
+    protected static final int CSIM_EVENT_BASE = 100;
+
     // Lookup table for carriers known to produce SIMs which incorrectly indicate MNC length.
 
     private static final String[] MCCMNC_CODES_HAVING_3DIGITS_MNC = {
@@ -181,8 +183,11 @@
         // recordsToLoad is set to 0 because no requests are made yet
         recordsToLoad = 0;
 
-
-        p.mCM.registerForSIMReady(this, EVENT_SIM_READY, null);
+        // SIMRecord is used by CDMA+LTE mode, and SIM_READY event
+        // will be subscribed by CdmaLteServiceStateTracker.
+        if (phone.getLteOnCdmaMode() != Phone.LTE_ON_CDMA_TRUE) {
+            p.mCM.registerForSIMReady(this, EVENT_SIM_READY, null);
+        }
         p.mCM.registerForOffOrNotAvailable(
                         this, EVENT_RADIO_OFF_OR_NOT_AVAILABLE, null);
         p.mCM.setOnSmsOnSim(this, EVENT_SMS_ON_SIM, null);
@@ -196,7 +201,9 @@
     @Override
     public void dispose() {
         //Unregister for all events
-        phone.mCM.unregisterForSIMReady(this);
+        if (phone.getLteOnCdmaMode() != Phone.LTE_ON_CDMA_TRUE) {
+            phone.mCM.unregisterForSIMReady(this);
+        }
         phone.mCM.unregisterForOffOrNotAvailable( this);
         phone.mCM.unregisterForIccRefresh(this);
     }
@@ -1280,7 +1287,7 @@
         fetchSimRecords();
     }
 
-    private void fetchSimRecords() {
+    protected void fetchSimRecords() {
         recordsRequested = true;
         IccFileHandler iccFh = phone.getIccFileHandler();
 
diff --git a/telephony/java/com/android/internal/telephony/gsm/SimPhoneBookInterfaceManager.java b/telephony/java/com/android/internal/telephony/gsm/SimPhoneBookInterfaceManager.java
index 377f8f0..35ba0d1 100644
--- a/telephony/java/com/android/internal/telephony/gsm/SimPhoneBookInterfaceManager.java
+++ b/telephony/java/com/android/internal/telephony/gsm/SimPhoneBookInterfaceManager.java
@@ -16,6 +16,8 @@
 
 package com.android.internal.telephony.gsm;
 
+import java.util.concurrent.atomic.AtomicBoolean;
+
 import android.os.Message;
 import android.util.Log;
 
@@ -56,14 +58,11 @@
             recordSize = new int[3];
 
             //Using mBaseHandler, no difference in EVENT_GET_SIZE_DONE handling
-            Message response = mBaseHandler.obtainMessage(EVENT_GET_SIZE_DONE);
+            AtomicBoolean status = new AtomicBoolean(false);
+            Message response = mBaseHandler.obtainMessage(EVENT_GET_SIZE_DONE, status);
 
             phone.getIccFileHandler().getEFLinearRecordSize(efid, response);
-            try {
-                mLock.wait();
-            } catch (InterruptedException e) {
-                logd("interrupted while trying to load from the SIM");
-            }
+            waitForResult(status);
         }
 
         return recordSize;
diff --git a/telephony/java/com/android/internal/telephony/gsm/SimSmsInterfaceManager.java b/telephony/java/com/android/internal/telephony/gsm/SimSmsInterfaceManager.java
index 5abba6e..8d0e5d3 100644
--- a/telephony/java/com/android/internal/telephony/gsm/SimSmsInterfaceManager.java
+++ b/telephony/java/com/android/internal/telephony/gsm/SimSmsInterfaceManager.java
@@ -27,6 +27,7 @@
 import com.android.internal.telephony.IccConstants;
 import com.android.internal.telephony.IccSmsInterfaceManager;
 import com.android.internal.telephony.IccUtils;
+import com.android.internal.telephony.IntRangeManager;
 import com.android.internal.telephony.SMSDispatcher;
 import com.android.internal.telephony.SmsRawData;
 
@@ -53,6 +54,9 @@
     private HashMap<Integer, HashSet<String>> mCellBroadcastSubscriptions =
             new HashMap<Integer, HashSet<String>>();
 
+    private CellBroadcastRangeManager mCellBroadcastRangeManager =
+            new CellBroadcastRangeManager();
+
     private static final int EVENT_LOAD_DONE = 1;
     private static final int EVENT_UPDATE_DONE = 2;
     private static final int EVENT_SET_BROADCAST_ACTIVATION_DONE = 3;
@@ -213,7 +217,15 @@
     }
 
     public boolean enableCellBroadcast(int messageIdentifier) {
-        if (DBG) log("enableCellBroadcast");
+        return enableCellBroadcastRange(messageIdentifier, messageIdentifier);
+    }
+
+    public boolean disableCellBroadcast(int messageIdentifier) {
+        return disableCellBroadcastRange(messageIdentifier, messageIdentifier);
+    }
+
+    public boolean enableCellBroadcastRange(int startMessageId, int endMessageId) {
+        if (DBG) log("enableCellBroadcastRange");
 
         Context context = mPhone.getContext();
 
@@ -223,30 +235,22 @@
 
         String client = context.getPackageManager().getNameForUid(
                 Binder.getCallingUid());
-        HashSet<String> clients = mCellBroadcastSubscriptions.get(messageIdentifier);
 
-        if (clients == null) {
-            // This is a new message identifier
-            clients = new HashSet<String>();
-            mCellBroadcastSubscriptions.put(messageIdentifier, clients);
-
-            if (!updateCellBroadcastConfig()) {
-                mCellBroadcastSubscriptions.remove(messageIdentifier);
-                return false;
-            }
+        if (!mCellBroadcastRangeManager.enableRange(startMessageId, endMessageId, client)) {
+            log("Failed to add cell broadcast subscription for MID range " + startMessageId
+                    + " to " + endMessageId + " from client " + client);
+            return false;
         }
 
-        clients.add(client);
-
         if (DBG)
-            log("Added cell broadcast subscription for MID " + messageIdentifier
-                    + " from client " + client);
+            log("Added cell broadcast subscription for MID range " + startMessageId
+                    + " to " + endMessageId + " from client " + client);
 
         return true;
     }
 
-    public boolean disableCellBroadcast(int messageIdentifier) {
-        if (DBG) log("disableCellBroadcast");
+    public boolean disableCellBroadcastRange(int startMessageId, int endMessageId) {
+        if (DBG) log("disableCellBroadcastRange");
 
         Context context = mPhone.getContext();
 
@@ -256,39 +260,56 @@
 
         String client = context.getPackageManager().getNameForUid(
                 Binder.getCallingUid());
-        HashSet<String> clients = mCellBroadcastSubscriptions.get(messageIdentifier);
 
-        if (clients != null && clients.remove(client)) {
-            if (DBG)
-                log("Removed cell broadcast subscription for MID " + messageIdentifier
-                        + " from client " + client);
-
-            if (clients.isEmpty()) {
-                mCellBroadcastSubscriptions.remove(messageIdentifier);
-                updateCellBroadcastConfig();
-            }
-            return true;
+        if (!mCellBroadcastRangeManager.disableRange(startMessageId, endMessageId, client)) {
+            log("Failed to remove cell broadcast subscription for MID range " + startMessageId
+                    + " to " + endMessageId + " from client " + client);
+            return false;
         }
 
-        return false;
+        if (DBG)
+            log("Removed cell broadcast subscription for MID range " + startMessageId
+                    + " to " + endMessageId + " from client " + client);
+
+        return true;
     }
 
-    private boolean updateCellBroadcastConfig() {
-        Set<Integer> messageIdentifiers = mCellBroadcastSubscriptions.keySet();
+    class CellBroadcastRangeManager extends IntRangeManager {
+        private ArrayList<SmsBroadcastConfigInfo> mConfigList =
+                new ArrayList<SmsBroadcastConfigInfo>();
 
-        if (messageIdentifiers.size() > 0) {
-            SmsBroadcastConfigInfo[] configs =
-                    new SmsBroadcastConfigInfo[messageIdentifiers.size()];
-            int i = 0;
+        /**
+         * Called when the list of enabled ranges has changed. This will be
+         * followed by zero or more calls to {@link #addRange} followed by
+         * a call to {@link #finishUpdate}.
+         */
+        protected void startUpdate() {
+            mConfigList.clear();
+        }
 
-            for (int messageIdentifier : messageIdentifiers) {
-                configs[i++] = new SmsBroadcastConfigInfo(messageIdentifier, messageIdentifier,
-                        SMS_CB_CODE_SCHEME_MIN, SMS_CB_CODE_SCHEME_MAX, true);
+        /**
+         * Called after {@link #startUpdate} to indicate a range of enabled
+         * values.
+         * @param startId the first id included in the range
+         * @param endId the last id included in the range
+         */
+        protected void addRange(int startId, int endId, boolean selected) {
+            mConfigList.add(new SmsBroadcastConfigInfo(startId, endId,
+                        SMS_CB_CODE_SCHEME_MIN, SMS_CB_CODE_SCHEME_MAX, selected));
+        }
+
+        /**
+         * Called to indicate the end of a range update started by the
+         * previous call to {@link #startUpdate}.
+         */
+        protected boolean finishUpdate() {
+            if (mConfigList.isEmpty()) {
+                return setCellBroadcastActivation(false);
+            } else {
+                SmsBroadcastConfigInfo[] configs =
+                        mConfigList.toArray(new SmsBroadcastConfigInfo[mConfigList.size()]);
+                return setCellBroadcastConfig(configs) && setCellBroadcastActivation(true);
             }
-
-            return setCellBroadcastConfig(configs) && setCellBroadcastActivation(true);
-        } else {
-            return setCellBroadcastActivation(false);
         }
     }
 
@@ -314,7 +335,7 @@
 
     private boolean setCellBroadcastActivation(boolean activate) {
         if (DBG)
-            log("Calling setCellBroadcastActivation(" + activate + ")");
+            log("Calling setCellBroadcastActivation(" + activate + ')');
 
         synchronized (mLock) {
             Message response = mHandler.obtainMessage(EVENT_SET_BROADCAST_ACTIVATION_DONE);
diff --git a/telephony/java/com/android/internal/telephony/gsm/SmsBroadcastConfigInfo.java b/telephony/java/com/android/internal/telephony/gsm/SmsBroadcastConfigInfo.java
index 45f50bc4..66e7ce0 100644
--- a/telephony/java/com/android/internal/telephony/gsm/SmsBroadcastConfigInfo.java
+++ b/telephony/java/com/android/internal/telephony/gsm/SmsBroadcastConfigInfo.java
@@ -30,11 +30,11 @@
  * and 9.4.4.2.3 for UMTS.
  * All other values can be treated as empty CBM data coding scheme.
  *
- * selected false means message types specified in <fromServiceId, toServiceId>
- * and <fromCodeScheme, toCodeScheme>are not accepted, while true means accepted.
+ * selected false means message types specified in {@code <fromServiceId, toServiceId>}
+ * and {@code <fromCodeScheme, toCodeScheme>} are not accepted, while true means accepted.
  *
  */
-public class SmsBroadcastConfigInfo {
+public final class SmsBroadcastConfigInfo {
     private int fromServiceId;
     private int toServiceId;
     private int fromCodeScheme;
@@ -46,11 +46,11 @@
      */
     public SmsBroadcastConfigInfo(int fromId, int toId, int fromScheme,
             int toScheme, boolean selected) {
-        setFromServiceId(fromId);
-        setToServiceId(toId);
-        setFromCodeScheme(fromScheme);
-        setToCodeScheme(toScheme);
-        this.setSelected(selected);
+        fromServiceId = fromId;
+        toServiceId = toId;
+        fromCodeScheme = fromScheme;
+        toCodeScheme = toScheme;
+        this.selected = selected;
     }
 
     /**
@@ -126,8 +126,8 @@
     @Override
     public String toString() {
         return "SmsBroadcastConfigInfo: Id [" +
-            getFromServiceId() + "," + getToServiceId() + "] Code [" +
-            getFromCodeScheme() + "," + getToCodeScheme() + "] " +
-            (isSelected() ? "ENABLED" : "DISABLED");
+                fromServiceId + ',' + toServiceId + "] Code [" +
+                fromCodeScheme + ',' + toCodeScheme + "] " +
+            (selected ? "ENABLED" : "DISABLED");
     }
-}
\ No newline at end of file
+}
diff --git a/telephony/java/com/android/internal/telephony/gsm/SmsCbHeader.java b/telephony/java/com/android/internal/telephony/gsm/SmsCbHeader.java
index 5f27cfc..8e6b79b 100644
--- a/telephony/java/com/android/internal/telephony/gsm/SmsCbHeader.java
+++ b/telephony/java/com/android/internal/telephony/gsm/SmsCbHeader.java
@@ -16,9 +16,44 @@
 
 package com.android.internal.telephony.gsm;
 
-public class SmsCbHeader {
+import android.telephony.SmsCbConstants;
+
+public class SmsCbHeader implements SmsCbConstants {
+    /**
+     * Length of SMS-CB header
+     */
     public static final int PDU_HEADER_LENGTH = 6;
 
+    /**
+     * GSM pdu format, as defined in 3gpp TS 23.041, section 9.4.1
+     */
+    public static final int FORMAT_GSM = 1;
+
+    /**
+     * UMTS pdu format, as defined in 3gpp TS 23.041, section 9.4.2
+     */
+    public static final int FORMAT_UMTS = 2;
+
+    /**
+     * GSM pdu format, as defined in 3gpp TS 23.041, section 9.4.1.3
+     */
+    public static final int FORMAT_ETWS_PRIMARY = 3;
+
+    /**
+     * Message type value as defined in 3gpp TS 25.324, section 11.1.
+     */
+    private static final int MESSAGE_TYPE_CBS_MESSAGE = 1;
+
+    /**
+     * Length of GSM pdus
+     */
+    public static final int PDU_LENGTH_GSM = 88;
+
+    /**
+     * Maximum length of ETWS primary message GSM pdus
+     */
+    public static final int PDU_LENGTH_ETWS = 56;
+
     public final int geographicalScope;
 
     public final int messageCode;
@@ -33,27 +68,147 @@
 
     public final int nrOfPages;
 
+    public final int format;
+
+    public final boolean etwsEmergencyUserAlert;
+
+    public final boolean etwsPopup;
+
+    public final int etwsWarningType;
+
     public SmsCbHeader(byte[] pdu) throws IllegalArgumentException {
         if (pdu == null || pdu.length < PDU_HEADER_LENGTH) {
             throw new IllegalArgumentException("Illegal PDU");
         }
 
-        geographicalScope = (pdu[0] & 0xc0) >> 6;
-        messageCode = ((pdu[0] & 0x3f) << 4) | ((pdu[1] & 0xf0) >> 4);
-        updateNumber = pdu[1] & 0x0f;
-        messageIdentifier = (pdu[2] << 8) | pdu[3];
-        dataCodingScheme = pdu[4];
+        if (pdu.length <= PDU_LENGTH_ETWS) {
+            format = FORMAT_ETWS_PRIMARY;
+            geographicalScope = -1; //not applicable
+            messageCode = -1;
+            updateNumber = -1;
+            messageIdentifier = ((pdu[2] & 0xff) << 8) | (pdu[3] & 0xff);
+            dataCodingScheme = -1;
+            pageIndex = -1;
+            nrOfPages = -1;
+            etwsEmergencyUserAlert = (pdu[4] & 0x1) != 0;
+            etwsPopup = (pdu[5] & 0x80) != 0;
+            etwsWarningType = (pdu[4] & 0xfe) >> 1;
+        } else if (pdu.length <= PDU_LENGTH_GSM) {
+            // GSM pdus are no more than 88 bytes
+            format = FORMAT_GSM;
+            geographicalScope = (pdu[0] & 0xc0) >> 6;
+            messageCode = ((pdu[0] & 0x3f) << 4) | ((pdu[1] & 0xf0) >> 4);
+            updateNumber = pdu[1] & 0x0f;
+            messageIdentifier = ((pdu[2] & 0xff) << 8) | (pdu[3] & 0xff);
+            dataCodingScheme = pdu[4] & 0xff;
 
-        // Check for invalid page parameter
-        int pageIndex = (pdu[5] & 0xf0) >> 4;
-        int nrOfPages = pdu[5] & 0x0f;
+            // Check for invalid page parameter
+            int pageIndex = (pdu[5] & 0xf0) >> 4;
+            int nrOfPages = pdu[5] & 0x0f;
 
-        if (pageIndex == 0 || nrOfPages == 0 || pageIndex > nrOfPages) {
+            if (pageIndex == 0 || nrOfPages == 0 || pageIndex > nrOfPages) {
+                pageIndex = 1;
+                nrOfPages = 1;
+            }
+
+            this.pageIndex = pageIndex;
+            this.nrOfPages = nrOfPages;
+            etwsEmergencyUserAlert = false;
+            etwsPopup = false;
+            etwsWarningType = -1;
+        } else {
+            // UMTS pdus are always at least 90 bytes since the payload includes
+            // a number-of-pages octet and also one length octet per page
+            format = FORMAT_UMTS;
+
+            int messageType = pdu[0];
+
+            if (messageType != MESSAGE_TYPE_CBS_MESSAGE) {
+                throw new IllegalArgumentException("Unsupported message type " + messageType);
+            }
+
+            messageIdentifier = ((pdu[1] & 0xff) << 8) | pdu[2] & 0xff;
+            geographicalScope = (pdu[3] & 0xc0) >> 6;
+            messageCode = ((pdu[3] & 0x3f) << 4) | ((pdu[4] & 0xf0) >> 4);
+            updateNumber = pdu[4] & 0x0f;
+            dataCodingScheme = pdu[5] & 0xff;
+
+            // We will always consider a UMTS message as having one single page
+            // since there's only one instance of the header, even though the
+            // actual payload may contain several pages.
             pageIndex = 1;
             nrOfPages = 1;
+            etwsEmergencyUserAlert = false;
+            etwsPopup = false;
+            etwsWarningType = -1;
         }
+    }
 
-        this.pageIndex = pageIndex;
-        this.nrOfPages = nrOfPages;
+    /**
+     * Return whether the specified message ID is an emergency (PWS) message type.
+     * This method is static and takes an argument so that it can be used by
+     * CellBroadcastReceiver, which stores message ID's in SQLite rather than PDU.
+     * @param id the message identifier to check
+     * @return true if the message is emergency type; false otherwise
+     */
+    public static boolean isEmergencyMessage(int id) {
+        return id >= MESSAGE_ID_PWS_FIRST_IDENTIFIER && id <= MESSAGE_ID_PWS_LAST_IDENTIFIER;
+    }
+
+    /**
+     * Return whether the specified message ID is an ETWS emergency message type.
+     * This method is static and takes an argument so that it can be used by
+     * CellBroadcastReceiver, which stores message ID's in SQLite rather than PDU.
+     * @param id the message identifier to check
+     * @return true if the message is ETWS emergency type; false otherwise
+     */
+    public static boolean isEtwsMessage(int id) {
+        return (id & MESSAGE_ID_ETWS_TYPE_MASK) == MESSAGE_ID_ETWS_TYPE;
+    }
+
+    /**
+     * Return whether the specified message ID is a CMAS emergency message type.
+     * This method is static and takes an argument so that it can be used by
+     * CellBroadcastReceiver, which stores message ID's in SQLite rather than PDU.
+     * @param id the message identifier to check
+     * @return true if the message is CMAS emergency type; false otherwise
+     */
+    public static boolean isCmasMessage(int id) {
+        return id >= MESSAGE_ID_CMAS_FIRST_IDENTIFIER && id <= MESSAGE_ID_CMAS_LAST_IDENTIFIER;
+    }
+
+    /**
+     * Return whether the specified message code indicates an ETWS popup alert.
+     * This method is static and takes an argument so that it can be used by
+     * CellBroadcastReceiver, which stores message codes in SQLite rather than PDU.
+     * This method assumes that the message ID has already been checked for ETWS type.
+     *
+     * @param messageCode the message code to check
+     * @return true if the message code indicates a popup alert should be displayed
+     */
+    public static boolean isEtwsPopupAlert(int messageCode) {
+        return (messageCode & MESSAGE_CODE_ETWS_ACTIVATE_POPUP) != 0;
+    }
+
+    /**
+     * Return whether the specified message code indicates an ETWS emergency user alert.
+     * This method is static and takes an argument so that it can be used by
+     * CellBroadcastReceiver, which stores message codes in SQLite rather than PDU.
+     * This method assumes that the message ID has already been checked for ETWS type.
+     *
+     * @param messageCode the message code to check
+     * @return true if the message code indicates an emergency user alert
+     */
+    public static boolean isEtwsEmergencyUserAlert(int messageCode) {
+        return (messageCode & MESSAGE_CODE_ETWS_EMERGENCY_USER_ALERT) != 0;
+    }
+
+    @Override
+    public String toString() {
+        return "SmsCbHeader{GS=" + geographicalScope + ", messageCode=0x" +
+                Integer.toHexString(messageCode) + ", updateNumber=" + updateNumber +
+                ", messageIdentifier=0x" + Integer.toHexString(messageIdentifier) +
+                ", DCS=0x" + Integer.toHexString(dataCodingScheme) +
+                ", page " + pageIndex + " of " + nrOfPages + '}';
     }
 }
diff --git a/telephony/tests/telephonytests/src/com/android/internal/telephony/GsmSmsCbTest.java b/telephony/tests/telephonytests/src/com/android/internal/telephony/GsmSmsCbTest.java
index 7136ea0..417aac4 100644
--- a/telephony/tests/telephonytests/src/com/android/internal/telephony/GsmSmsCbTest.java
+++ b/telephony/tests/telephonytests/src/com/android/internal/telephony/GsmSmsCbTest.java
@@ -18,6 +18,7 @@
 
 import android.telephony.SmsCbMessage;
 import android.test.AndroidTestCase;
+import android.util.Log;
 
 /**
  * Test cases for basic SmsCbMessage operations
@@ -69,6 +70,36 @@
         doTestGeographicalScopeValue(pdu, (byte)0xC0, SmsCbMessage.GEOGRAPHICAL_SCOPE_CELL_WIDE);
     }
 
+    public void testGetGeographicalScopeUmts() {
+        byte[] pdu = {
+                (byte)0x01, (byte)0x00, (byte)0x32, (byte)0xC0, (byte)0x00, (byte)0x40,
+
+                (byte)0x01,
+
+                (byte)0x41, (byte)0xD0, (byte)0x71, (byte)0xDA, (byte)0x04, (byte)0x91,
+                (byte)0xCB, (byte)0xE6, (byte)0x70, (byte)0x9D, (byte)0x4D, (byte)0x07,
+                (byte)0x85, (byte)0xD9, (byte)0x70, (byte)0x74, (byte)0x58, (byte)0x5C,
+                (byte)0xA6, (byte)0x83, (byte)0xDA, (byte)0xE5, (byte)0xF9, (byte)0x3C,
+                (byte)0x7C, (byte)0x2E, (byte)0x83, (byte)0xEE, (byte)0x69, (byte)0x3A,
+                (byte)0x1A, (byte)0x34, (byte)0x0E, (byte)0xCB, (byte)0xE5, (byte)0xE9,
+                (byte)0xF0, (byte)0xB9, (byte)0x0C, (byte)0x92, (byte)0x97, (byte)0xE9,
+                (byte)0x75, (byte)0xB9, (byte)0x1B, (byte)0x04, (byte)0x0F, (byte)0x93,
+                (byte)0xC9, (byte)0x69, (byte)0xF7, (byte)0xB9, (byte)0xD1, (byte)0x68,
+                (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1,
+                (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3,
+                (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46,
+                (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
+                (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x00,
+
+                (byte)0x34
+        };
+
+        SmsCbMessage msg = SmsCbMessage.createFromPdu(pdu);
+
+        assertEquals("Unexpected geographical scope decoded",
+                SmsCbMessage.GEOGRAPHICAL_SCOPE_CELL_WIDE, msg.getGeographicalScope());
+    }
+
     public void testGetMessageBody7Bit() {
         byte[] pdu = {
                 (byte)0xC0, (byte)0x00, (byte)0x00, (byte)0x32, (byte)0x40, (byte)0x11, (byte)0x41,
@@ -92,6 +123,83 @@
                 msg.getMessageBody());
     }
 
+    public void testGetMessageBody7BitUmts() {
+        byte[] pdu = {
+                (byte)0x01, (byte)0x00, (byte)0x32, (byte)0xC0, (byte)0x00, (byte)0x40,
+
+                (byte)0x01,
+
+                (byte)0x41, (byte)0xD0, (byte)0x71, (byte)0xDA, (byte)0x04, (byte)0x91,
+                (byte)0xCB, (byte)0xE6, (byte)0x70, (byte)0x9D, (byte)0x4D, (byte)0x07,
+                (byte)0x85, (byte)0xD9, (byte)0x70, (byte)0x74, (byte)0x58, (byte)0x5C,
+                (byte)0xA6, (byte)0x83, (byte)0xDA, (byte)0xE5, (byte)0xF9, (byte)0x3C,
+                (byte)0x7C, (byte)0x2E, (byte)0x83, (byte)0xEE, (byte)0x69, (byte)0x3A,
+                (byte)0x1A, (byte)0x34, (byte)0x0E, (byte)0xCB, (byte)0xE5, (byte)0xE9,
+                (byte)0xF0, (byte)0xB9, (byte)0x0C, (byte)0x92, (byte)0x97, (byte)0xE9,
+                (byte)0x75, (byte)0xB9, (byte)0x1B, (byte)0x04, (byte)0x0F, (byte)0x93,
+                (byte)0xC9, (byte)0x69, (byte)0xF7, (byte)0xB9, (byte)0xD1, (byte)0x68,
+                (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1,
+                (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3,
+                (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46,
+                (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
+                (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x00,
+
+                (byte)0x34
+        };
+        SmsCbMessage msg = SmsCbMessage.createFromPdu(pdu);
+
+        assertEquals("Unexpected 7-bit string decoded",
+                "A GSM default alphabet message with carriage return padding",
+                msg.getMessageBody());
+    }
+
+    public void testGetMessageBody7BitMultipageUmts() {
+        byte[] pdu = {
+                (byte)0x01, (byte)0x00, (byte)0x01, (byte)0xC0, (byte)0x00, (byte)0x40,
+
+                (byte)0x02,
+
+                (byte)0xC6, (byte)0xB4, (byte)0x7C, (byte)0x4E, (byte)0x07, (byte)0xC1,
+                (byte)0xC3, (byte)0xE7, (byte)0xF2, (byte)0xAA, (byte)0xD1, (byte)0x68,
+                (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1,
+                (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3,
+                (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46,
+                (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
+                (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A,
+                (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34,
+                (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68,
+                (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1,
+                (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3,
+                (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46,
+                (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
+                (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x00,
+
+                (byte)0x0A,
+
+                (byte)0xD3, (byte)0xF2, (byte)0xF8, (byte)0xED, (byte)0x26, (byte)0x83,
+                (byte)0xE0, (byte)0xE1, (byte)0x73, (byte)0xB9, (byte)0xD1, (byte)0x68,
+                (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1,
+                (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3,
+                (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46,
+                (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
+                (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A,
+                (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34,
+                (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68,
+                (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1,
+                (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3,
+                (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46,
+                (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
+                (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x00,
+
+                (byte)0x0A
+        };
+        SmsCbMessage msg = SmsCbMessage.createFromPdu(pdu);
+
+        assertEquals("Unexpected multipage 7-bit string decoded",
+                "First page+Second page",
+                msg.getMessageBody());
+    }
+
     public void testGetMessageBody7BitFull() {
         byte[] pdu = {
                 (byte)0xC0, (byte)0x00, (byte)0x00, (byte)0x32, (byte)0x40, (byte)0x11, (byte)0x41,
@@ -117,6 +225,38 @@
                 msg.getMessageBody());
     }
 
+    public void testGetMessageBody7BitFullUmts() {
+        byte[] pdu = {
+                (byte)0x01, (byte)0x00, (byte)0x32, (byte)0xC0, (byte)0x00, (byte)0x40,
+
+                (byte)0x01,
+
+                (byte)0x41, (byte)0xD0, (byte)0x71, (byte)0xDA, (byte)0x04, (byte)0x91,
+                (byte)0xCB, (byte)0xE6, (byte)0x70, (byte)0x9D, (byte)0x4D, (byte)0x07,
+                (byte)0x85, (byte)0xD9, (byte)0x70, (byte)0x74, (byte)0x58, (byte)0x5C,
+                (byte)0xA6, (byte)0x83, (byte)0xDA, (byte)0xE5, (byte)0xF9, (byte)0x3C,
+                (byte)0x7C, (byte)0x2E, (byte)0x83, (byte)0xC4, (byte)0xE5, (byte)0xB4,
+                (byte)0xFB, (byte)0x0C, (byte)0x2A, (byte)0xE3, (byte)0xC3, (byte)0x63,
+                (byte)0x3A, (byte)0x3B, (byte)0x0F, (byte)0xCA, (byte)0xCD, (byte)0x40,
+                (byte)0x63, (byte)0x74, (byte)0x58, (byte)0x1E, (byte)0x1E, (byte)0xD3,
+                (byte)0xCB, (byte)0xF2, (byte)0x39, (byte)0x88, (byte)0xFD, (byte)0x76,
+                (byte)0x9F, (byte)0x59, (byte)0xA0, (byte)0x76, (byte)0x39, (byte)0xEC,
+                (byte)0x4E, (byte)0xBB, (byte)0xCF, (byte)0x20, (byte)0x3A, (byte)0xBA,
+                (byte)0x2C, (byte)0x2F, (byte)0x83, (byte)0xD2, (byte)0x73, (byte)0x90,
+                (byte)0xFB, (byte)0x0D, (byte)0x82, (byte)0x87, (byte)0xC9, (byte)0xE4,
+                (byte)0xB4, (byte)0xFB, (byte)0x1C, (byte)0x02,
+
+                (byte)0x52
+        };
+        SmsCbMessage msg = SmsCbMessage.createFromPdu(pdu);
+
+        assertEquals(
+                "Unexpected 7-bit string decoded",
+                "A GSM default alphabet message being exactly 93 characters long, " +
+                "meaning there is no padding!",
+                msg.getMessageBody());
+    }
+
     public void testGetMessageBody7BitWithLanguage() {
         byte[] pdu = {
                 (byte)0xC0, (byte)0x00, (byte)0x00, (byte)0x32, (byte)0x04, (byte)0x11, (byte)0x41,
@@ -167,6 +307,38 @@
         assertEquals("Unexpected language indicator decoded", "sv", msg.getLanguageCode());
     }
 
+    public void testGetMessageBody7BitWithLanguageInBodyUmts() {
+        byte[] pdu = {
+                (byte)0x01, (byte)0x00, (byte)0x32, (byte)0xC0, (byte)0x00, (byte)0x10,
+
+                (byte)0x01,
+
+                (byte)0x73, (byte)0x7B, (byte)0x23, (byte)0x08, (byte)0x3A, (byte)0x4E,
+                (byte)0x9B, (byte)0x20, (byte)0x72, (byte)0xD9, (byte)0x1C, (byte)0xAE,
+                (byte)0xB3, (byte)0xE9, (byte)0xA0, (byte)0x30, (byte)0x1B, (byte)0x8E,
+                (byte)0x0E, (byte)0x8B, (byte)0xCB, (byte)0x74, (byte)0x50, (byte)0xBB,
+                (byte)0x3C, (byte)0x9F, (byte)0x87, (byte)0xCF, (byte)0x65, (byte)0xD0,
+                (byte)0x3D, (byte)0x4D, (byte)0x47, (byte)0x83, (byte)0xC6, (byte)0x61,
+                (byte)0xB9, (byte)0x3C, (byte)0x1D, (byte)0x3E, (byte)0x97, (byte)0x41,
+                (byte)0xF2, (byte)0x32, (byte)0xBD, (byte)0x2E, (byte)0x77, (byte)0x83,
+                (byte)0xE0, (byte)0x61, (byte)0x32, (byte)0x39, (byte)0xED, (byte)0x3E,
+                (byte)0x37, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1,
+                (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3,
+                (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46,
+                (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
+                (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x00,
+
+                (byte)0x37
+        };
+        SmsCbMessage msg = SmsCbMessage.createFromPdu(pdu);
+
+        assertEquals("Unexpected 7-bit string decoded",
+                "A GSM default alphabet message with carriage return padding",
+                msg.getMessageBody());
+
+        assertEquals("Unexpected language indicator decoded", "sv", msg.getLanguageCode());
+    }
+
     public void testGetMessageBody8Bit() {
         byte[] pdu = {
                 (byte)0xC0, (byte)0x00, (byte)0x00, (byte)0x32, (byte)0x44, (byte)0x11, (byte)0x41,
@@ -210,6 +382,81 @@
                 "A UCS2 message containing a \u0434 character", msg.getMessageBody());
     }
 
+    public void testGetMessageBodyUcs2Umts() {
+        byte[] pdu = {
+                (byte)0x01, (byte)0x00, (byte)0x32, (byte)0xC0, (byte)0x00, (byte)0x48,
+
+                (byte)0x01,
+
+                (byte)0x00, (byte)0x41, (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x55,
+                (byte)0x00, (byte)0x43, (byte)0x00, (byte)0x53, (byte)0x00, (byte)0x32,
+                (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x6D, (byte)0x00, (byte)0x65,
+                (byte)0x00, (byte)0x73, (byte)0x00, (byte)0x73, (byte)0x00, (byte)0x61,
+                (byte)0x00, (byte)0x67, (byte)0x00, (byte)0x65, (byte)0x00, (byte)0x20,
+                (byte)0x00, (byte)0x63, (byte)0x00, (byte)0x6F, (byte)0x00, (byte)0x6E,
+                (byte)0x00, (byte)0x74, (byte)0x00, (byte)0x61, (byte)0x00, (byte)0x69,
+                (byte)0x00, (byte)0x6E, (byte)0x00, (byte)0x69, (byte)0x00, (byte)0x6E,
+                (byte)0x00, (byte)0x67, (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x61,
+                (byte)0x00, (byte)0x20, (byte)0x04, (byte)0x34, (byte)0x00, (byte)0x20,
+                (byte)0x00, (byte)0x63, (byte)0x00, (byte)0x68, (byte)0x00, (byte)0x61,
+                (byte)0x00, (byte)0x72, (byte)0x00, (byte)0x61, (byte)0x00, (byte)0x63,
+                (byte)0x00, (byte)0x74, (byte)0x00, (byte)0x65, (byte)0x00, (byte)0x72,
+                (byte)0x00, (byte)0x0D, (byte)0x00, (byte)0x0D,
+
+                (byte)0x4E
+        };
+        SmsCbMessage msg = SmsCbMessage.createFromPdu(pdu);
+
+        assertEquals("Unexpected 7-bit string decoded",
+                "A UCS2 message containing a \u0434 character", msg.getMessageBody());
+    }
+
+    public void testGetMessageBodyUcs2MultipageUmts() {
+        byte[] pdu = {
+                (byte)0x01, (byte)0x00, (byte)0x32, (byte)0xC0, (byte)0x00, (byte)0x48,
+
+                (byte)0x02,
+
+                (byte)0x00, (byte)0x41, (byte)0x00, (byte)0x41, (byte)0x00, (byte)0x41,
+                (byte)0x00, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+                (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+                (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+                (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+                (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+                (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+                (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+                (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+                (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+                (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+                (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+                (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+                (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+
+                (byte)0x06,
+
+                (byte)0x00, (byte)0x42, (byte)0x00, (byte)0x42, (byte)0x00, (byte)0x42,
+                (byte)0x00, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+                (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+                (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+                (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+                (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+                (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+                (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+                (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+                (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+                (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+                (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+                (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+                (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+
+                (byte)0x06
+        };
+        SmsCbMessage msg = SmsCbMessage.createFromPdu(pdu);
+
+        assertEquals("Unexpected multipage UCS2 string decoded",
+                "AAABBB", msg.getMessageBody());
+    }
+
     public void testGetMessageBodyUcs2WithLanguageInBody() {
         byte[] pdu = {
                 (byte)0xC0, (byte)0x00, (byte)0x00, (byte)0x32, (byte)0x11, (byte)0x11, (byte)0x78,
@@ -234,6 +481,37 @@
         assertEquals("Unexpected language indicator decoded", "xx", msg.getLanguageCode());
     }
 
+    public void testGetMessageBodyUcs2WithLanguageInBodyUmts() {
+        byte[] pdu = {
+                (byte)0x01, (byte)0x00, (byte)0x32, (byte)0xC0, (byte)0x00, (byte)0x11,
+
+                (byte)0x01,
+
+                (byte)0x78, (byte)0x3C, (byte)0x00, (byte)0x41, (byte)0x00, (byte)0x20,
+                (byte)0x00, (byte)0x55, (byte)0x00, (byte)0x43, (byte)0x00, (byte)0x53,
+                (byte)0x00, (byte)0x32, (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x6D,
+                (byte)0x00, (byte)0x65, (byte)0x00, (byte)0x73, (byte)0x00, (byte)0x73,
+                (byte)0x00, (byte)0x61, (byte)0x00, (byte)0x67, (byte)0x00, (byte)0x65,
+                (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x63, (byte)0x00, (byte)0x6F,
+                (byte)0x00, (byte)0x6E, (byte)0x00, (byte)0x74, (byte)0x00, (byte)0x61,
+                (byte)0x00, (byte)0x69, (byte)0x00, (byte)0x6E, (byte)0x00, (byte)0x69,
+                (byte)0x00, (byte)0x6E, (byte)0x00, (byte)0x67, (byte)0x00, (byte)0x20,
+                (byte)0x00, (byte)0x61, (byte)0x00, (byte)0x20, (byte)0x04, (byte)0x34,
+                (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x63, (byte)0x00, (byte)0x68,
+                (byte)0x00, (byte)0x61, (byte)0x00, (byte)0x72, (byte)0x00, (byte)0x61,
+                (byte)0x00, (byte)0x63, (byte)0x00, (byte)0x74, (byte)0x00, (byte)0x65,
+                (byte)0x00, (byte)0x72, (byte)0x00, (byte)0x0D,
+
+                (byte)0x50
+        };
+        SmsCbMessage msg = SmsCbMessage.createFromPdu(pdu);
+
+        assertEquals("Unexpected 7-bit string decoded",
+                "A UCS2 message containing a \u0434 character", msg.getMessageBody());
+
+        assertEquals("Unexpected language indicator decoded", "xx", msg.getLanguageCode());
+    }
+
     public void testGetMessageIdentifier() {
         byte[] pdu = {
                 (byte)0xC0, (byte)0x00, (byte)0x30, (byte)0x39, (byte)0x40, (byte)0x11, (byte)0x41,
@@ -256,6 +534,35 @@
         assertEquals("Unexpected message identifier decoded", 12345, msg.getMessageIdentifier());
     }
 
+    public void testGetMessageIdentifierUmts() {
+        byte[] pdu = {
+                (byte)0x01, (byte)0x30, (byte)0x39, (byte)0x2A, (byte)0xA5, (byte)0x40,
+
+                (byte)0x01,
+
+                (byte)0x41, (byte)0xD0, (byte)0x71, (byte)0xDA, (byte)0x04, (byte)0x91,
+                (byte)0xCB, (byte)0xE6, (byte)0x70, (byte)0x9D, (byte)0x4D, (byte)0x07,
+                (byte)0x85, (byte)0xD9, (byte)0x70, (byte)0x74, (byte)0x58, (byte)0x5C,
+                (byte)0xA6, (byte)0x83, (byte)0xDA, (byte)0xE5, (byte)0xF9, (byte)0x3C,
+                (byte)0x7C, (byte)0x2E, (byte)0x83, (byte)0xEE, (byte)0x69, (byte)0x3A,
+                (byte)0x1A, (byte)0x34, (byte)0x0E, (byte)0xCB, (byte)0xE5, (byte)0xE9,
+                (byte)0xF0, (byte)0xB9, (byte)0x0C, (byte)0x92, (byte)0x97, (byte)0xE9,
+                (byte)0x75, (byte)0xB9, (byte)0x1B, (byte)0x04, (byte)0x0F, (byte)0x93,
+                (byte)0xC9, (byte)0x69, (byte)0xF7, (byte)0xB9, (byte)0xD1, (byte)0x68,
+                (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1,
+                (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3,
+                (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46,
+                (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
+                (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x00,
+
+                (byte)0x34
+        };
+
+        SmsCbMessage msg = SmsCbMessage.createFromPdu(pdu);
+
+        assertEquals("Unexpected message identifier decoded", 12345, msg.getMessageIdentifier());
+    }
+
     public void testGetMessageCode() {
         byte[] pdu = {
                 (byte)0x2A, (byte)0xA5, (byte)0x30, (byte)0x39, (byte)0x40, (byte)0x11, (byte)0x41,
@@ -278,6 +585,35 @@
         assertEquals("Unexpected message code decoded", 682, msg.getMessageCode());
     }
 
+    public void testGetMessageCodeUmts() {
+        byte[] pdu = {
+                (byte)0x01, (byte)0x30, (byte)0x39, (byte)0x2A, (byte)0xA5, (byte)0x40,
+
+                (byte)0x01,
+
+                (byte)0x41, (byte)0xD0, (byte)0x71, (byte)0xDA, (byte)0x04, (byte)0x91,
+                (byte)0xCB, (byte)0xE6, (byte)0x70, (byte)0x9D, (byte)0x4D, (byte)0x07,
+                (byte)0x85, (byte)0xD9, (byte)0x70, (byte)0x74, (byte)0x58, (byte)0x5C,
+                (byte)0xA6, (byte)0x83, (byte)0xDA, (byte)0xE5, (byte)0xF9, (byte)0x3C,
+                (byte)0x7C, (byte)0x2E, (byte)0x83, (byte)0xEE, (byte)0x69, (byte)0x3A,
+                (byte)0x1A, (byte)0x34, (byte)0x0E, (byte)0xCB, (byte)0xE5, (byte)0xE9,
+                (byte)0xF0, (byte)0xB9, (byte)0x0C, (byte)0x92, (byte)0x97, (byte)0xE9,
+                (byte)0x75, (byte)0xB9, (byte)0x1B, (byte)0x04, (byte)0x0F, (byte)0x93,
+                (byte)0xC9, (byte)0x69, (byte)0xF7, (byte)0xB9, (byte)0xD1, (byte)0x68,
+                (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1,
+                (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3,
+                (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46,
+                (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
+                (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x00,
+
+                (byte)0x34
+        };
+
+        SmsCbMessage msg = SmsCbMessage.createFromPdu(pdu);
+
+        assertEquals("Unexpected message code decoded", 682, msg.getMessageCode());
+    }
+
     public void testGetUpdateNumber() {
         byte[] pdu = {
                 (byte)0x2A, (byte)0xA5, (byte)0x30, (byte)0x39, (byte)0x40, (byte)0x11, (byte)0x41,
@@ -299,4 +635,78 @@
 
         assertEquals("Unexpected update number decoded", 5, msg.getUpdateNumber());
     }
+
+    public void testGetUpdateNumberUmts() {
+        byte[] pdu = {
+                (byte)0x01, (byte)0x30, (byte)0x39, (byte)0x2A, (byte)0xA5, (byte)0x40,
+
+                (byte)0x01,
+
+                (byte)0x41, (byte)0xD0, (byte)0x71, (byte)0xDA, (byte)0x04, (byte)0x91,
+                (byte)0xCB, (byte)0xE6, (byte)0x70, (byte)0x9D, (byte)0x4D, (byte)0x07,
+                (byte)0x85, (byte)0xD9, (byte)0x70, (byte)0x74, (byte)0x58, (byte)0x5C,
+                (byte)0xA6, (byte)0x83, (byte)0xDA, (byte)0xE5, (byte)0xF9, (byte)0x3C,
+                (byte)0x7C, (byte)0x2E, (byte)0x83, (byte)0xEE, (byte)0x69, (byte)0x3A,
+                (byte)0x1A, (byte)0x34, (byte)0x0E, (byte)0xCB, (byte)0xE5, (byte)0xE9,
+                (byte)0xF0, (byte)0xB9, (byte)0x0C, (byte)0x92, (byte)0x97, (byte)0xE9,
+                (byte)0x75, (byte)0xB9, (byte)0x1B, (byte)0x04, (byte)0x0F, (byte)0x93,
+                (byte)0xC9, (byte)0x69, (byte)0xF7, (byte)0xB9, (byte)0xD1, (byte)0x68,
+                (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1,
+                (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3,
+                (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46,
+                (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
+                (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x00,
+
+                (byte)0x34
+        };
+
+        SmsCbMessage msg = SmsCbMessage.createFromPdu(pdu);
+
+        assertEquals("Unexpected update number decoded", 5, msg.getUpdateNumber());
+    }
+
+    /* ETWS Test message including header */
+    private static final byte[] etwsMessageNormal = IccUtils.hexStringToBytes("000011001101" +
+            "0D0A5BAE57CE770C531790E85C716CBF3044573065B930675730" +
+            "9707767A751F30025F37304463FA308C306B5099304830664E0B30553044FF086C178C615E81FF09" +
+            "0000000000000000000000000000");
+
+    private static final byte[] etwsMessageCancel = IccUtils.hexStringToBytes("000011001101" +
+            "0D0A5148307B3069002800310030003A0035" +
+            "00320029306E7DCA602557309707901F5831309253D66D883057307E3059FF086C178C615E81FF09" +
+            "00000000000000000000000000000000000000000000");
+
+    private static final byte[] etwsMessageTest = IccUtils.hexStringToBytes("000011031101" +
+            "0D0A5BAE57CE770C531790E85C716CBF3044" +
+            "573065B9306757309707300263FA308C306B5099304830664E0B30553044FF086C178C615E81FF09" +
+            "00000000000000000000000000000000000000000000");
+
+    // FIXME: add example of ETWS primary notification PDU
+
+    public void testEtwsMessageNormal() {
+        SmsCbMessage msg = SmsCbMessage.createFromPdu(etwsMessageNormal);
+        Log.d("GsmSmsCbTest", msg.toString());
+        assertEquals("GS mismatch", 0, msg.getGeographicalScope());
+        assertEquals("message code mismatch", 0, msg.getMessageCode());
+        assertEquals("update number mismatch", 0, msg.getUpdateNumber());
+        assertEquals("message ID mismatch", 0x1100, msg.getMessageIdentifier());
+    }
+
+    public void testEtwsMessageCancel() {
+        SmsCbMessage msg = SmsCbMessage.createFromPdu(etwsMessageCancel);
+        Log.d("GsmSmsCbTest", msg.toString());
+        assertEquals("GS mismatch", 0, msg.getGeographicalScope());
+        assertEquals("message code mismatch", 0, msg.getMessageCode());
+        assertEquals("update number mismatch", 0, msg.getUpdateNumber());
+        assertEquals("message ID mismatch", 0x1100, msg.getMessageIdentifier());
+    }
+
+    public void testEtwsMessageTest() {
+        SmsCbMessage msg = SmsCbMessage.createFromPdu(etwsMessageTest);
+        Log.d("GsmSmsCbTest", msg.toString());
+        assertEquals("GS mismatch", 0, msg.getGeographicalScope());
+        assertEquals("message code mismatch", 0, msg.getMessageCode());
+        assertEquals("update number mismatch", 0, msg.getUpdateNumber());
+        assertEquals("message ID mismatch", 0x1103, msg.getMessageIdentifier());
+    }
 }
diff --git a/telephony/tests/telephonytests/src/com/android/internal/telephony/IntRangeManagerTest.java b/telephony/tests/telephonytests/src/com/android/internal/telephony/IntRangeManagerTest.java
new file mode 100644
index 0000000..79dca39
--- /dev/null
+++ b/telephony/tests/telephonytests/src/com/android/internal/telephony/IntRangeManagerTest.java
@@ -0,0 +1,374 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.telephony;
+
+import android.test.AndroidTestCase;
+
+import com.android.internal.telephony.gsm.SmsBroadcastConfigInfo;
+
+import java.util.ArrayList;
+
+/**
+ * Test cases for the IntRangeManager class.
+ */
+public class IntRangeManagerTest extends AndroidTestCase {
+
+    private static final int SMS_CB_CODE_SCHEME_MIN = 0;
+    private static final int SMS_CB_CODE_SCHEME_MAX = 255;
+
+    private static final int FLAG_START_UPDATE_CALLED   = 0x01;
+    private static final int FLAG_ADD_RANGE_CALLED      = 0x02;
+    private static final int FLAG_FINISH_UPDATE_CALLED  = 0x04;
+
+    private static final int ALL_FLAGS_SET = FLAG_START_UPDATE_CALLED | FLAG_ADD_RANGE_CALLED |
+            FLAG_FINISH_UPDATE_CALLED;
+
+    /** Dummy IntRangeManager for testing. */
+    class TestIntRangeManager extends IntRangeManager {
+        ArrayList<SmsBroadcastConfigInfo> mConfigList =
+                new ArrayList<SmsBroadcastConfigInfo>();
+
+        int flags;
+        boolean finishUpdateReturnValue = true;
+
+        /**
+         * Called when the list of enabled ranges has changed. This will be
+         * followed by zero or more calls to {@link #addRange} followed by
+         * a call to {@link #finishUpdate}.
+         */
+        protected void startUpdate() {
+            mConfigList.clear();
+            flags |= FLAG_START_UPDATE_CALLED;
+        }
+
+        /**
+         * Called after {@link #startUpdate} to indicate a range of enabled
+         * values.
+         * @param startId the first id included in the range
+         * @param endId the last id included in the range
+         */
+        protected void addRange(int startId, int endId, boolean selected) {
+            mConfigList.add(new SmsBroadcastConfigInfo(startId, endId,
+                        SMS_CB_CODE_SCHEME_MIN, SMS_CB_CODE_SCHEME_MAX, selected));
+            flags |= FLAG_ADD_RANGE_CALLED;
+        }
+
+        /**
+         * Called to indicate the end of a range update started by the
+         * previous call to {@link #startUpdate}.
+         */
+        protected boolean finishUpdate() {
+            flags |= FLAG_FINISH_UPDATE_CALLED;
+            return finishUpdateReturnValue;
+        }
+
+        /** Reset the object for the next test case. */
+        void reset() {
+            flags = 0;
+            mConfigList.clear();
+        }
+    }
+
+    public void testEmptyRangeManager() {
+        TestIntRangeManager testManager = new TestIntRangeManager();
+        assertEquals("expecting empty configlist", 0, testManager.mConfigList.size());
+    }
+
+    private void checkConfigInfo(SmsBroadcastConfigInfo info, int fromServiceId,
+            int toServiceId, int fromCodeScheme, int toCodeScheme, boolean selected) {
+        assertEquals("fromServiceId", fromServiceId, info.getFromServiceId());
+        assertEquals("toServiceId", toServiceId, info.getToServiceId());
+        assertEquals("fromCodeScheme", fromCodeScheme, info.getFromCodeScheme());
+        assertEquals("toCodeScheme", toCodeScheme, info.getToCodeScheme());
+        assertEquals("selected", selected, info.isSelected());
+    }
+
+    public void testAddSingleChannel() {
+        TestIntRangeManager testManager = new TestIntRangeManager();
+        assertEquals("flags before test", 0, testManager.flags);
+        assertTrue("enabling range", testManager.enableRange(123, 123, "client1"));
+        assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+        assertEquals("configlist size", 1, testManager.mConfigList.size());
+        checkConfigInfo(testManager.mConfigList.get(0), 123, 123, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, true);
+        testManager.reset();
+        assertTrue("updating ranges", testManager.updateRanges());
+        assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+        assertEquals("configlist size", 1, testManager.mConfigList.size());
+        checkConfigInfo(testManager.mConfigList.get(0), 123, 123, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, true);
+    }
+
+    public void testRemoveSingleChannel() {
+        TestIntRangeManager testManager = new TestIntRangeManager();
+        assertTrue("enabling range", testManager.enableRange(123, 123, "client1"));
+        assertEquals("flags after enable", ALL_FLAGS_SET, testManager.flags);
+        assertEquals("configlist size", 1, testManager.mConfigList.size());
+        testManager.reset();
+        assertTrue("disabling range", testManager.disableRange(123, 123, "client1"));
+        assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+        assertEquals("configlist size", 1, testManager.mConfigList.size());
+        checkConfigInfo(testManager.mConfigList.get(0), 123, 123, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, false);
+        testManager.reset();
+        assertTrue("updating ranges", testManager.updateRanges());
+        assertEquals("flags after test", FLAG_START_UPDATE_CALLED | FLAG_FINISH_UPDATE_CALLED,
+                testManager.flags);
+        assertEquals("configlist size", 0, testManager.mConfigList.size());
+    }
+
+    public void testRemoveBadChannel() {
+        TestIntRangeManager testManager = new TestIntRangeManager();
+        assertFalse("disabling missing range", testManager.disableRange(123, 123, "client1"));
+        assertEquals("flags after test", 0, testManager.flags);
+        assertEquals("configlist size", 0, testManager.mConfigList.size());
+    }
+
+    public void testAddTwoChannels() {
+        TestIntRangeManager testManager = new TestIntRangeManager();
+        assertEquals("flags before test", 0, testManager.flags);
+        assertTrue("enabling range 1", testManager.enableRange(100, 120, "client1"));
+        assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+        assertEquals("configlist size", 1, testManager.mConfigList.size());
+        checkConfigInfo(testManager.mConfigList.get(0), 100, 120, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, true);
+        testManager.reset();
+        assertTrue("enabling range 2", testManager.enableRange(200, 250, "client2"));
+        assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+        assertEquals("configlist size", 1, testManager.mConfigList.size());
+        checkConfigInfo(testManager.mConfigList.get(0), 200, 250, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, true);
+        testManager.reset();
+        assertTrue("updating ranges", testManager.updateRanges());
+        assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+        assertEquals("configlist size", 2, testManager.mConfigList.size());
+        checkConfigInfo(testManager.mConfigList.get(0), 100, 120, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, true);
+        checkConfigInfo(testManager.mConfigList.get(1), 200, 250, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, true);
+    }
+
+    public void testOverlappingChannels() {
+        TestIntRangeManager testManager = new TestIntRangeManager();
+        assertEquals("flags before test", 0, testManager.flags);
+        assertTrue("enabling range 1", testManager.enableRange(100, 200, "client1"));
+        assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+        assertEquals("configlist size", 1, testManager.mConfigList.size());
+        checkConfigInfo(testManager.mConfigList.get(0), 100, 200, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, true);
+        testManager.reset();
+        assertTrue("enabling range 2", testManager.enableRange(150, 250, "client2"));
+        assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+        assertEquals("configlist size", 1, testManager.mConfigList.size());
+        checkConfigInfo(testManager.mConfigList.get(0), 201, 250, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, true);
+        testManager.reset();
+        assertTrue("updating ranges", testManager.updateRanges());
+        assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+        assertEquals("configlist size", 1, testManager.mConfigList.size());
+        checkConfigInfo(testManager.mConfigList.get(0), 100, 250, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, true);
+        testManager.reset();
+        assertTrue("disabling range 1", testManager.disableRange(100, 200, "client1"));
+        assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+        assertEquals("configlist size", 1, testManager.mConfigList.size());
+        checkConfigInfo(testManager.mConfigList.get(0), 100, 149, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, false);
+        testManager.reset();
+        assertTrue("disabling range 2", testManager.disableRange(150, 250, "client2"));
+        assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+        assertEquals("configlist size", 1, testManager.mConfigList.size());
+        checkConfigInfo(testManager.mConfigList.get(0), 150, 250, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, false);
+        testManager.reset();
+        assertTrue("updating ranges", testManager.updateRanges());
+        assertEquals("flags after test", FLAG_START_UPDATE_CALLED | FLAG_FINISH_UPDATE_CALLED,
+                testManager.flags);
+        assertEquals("configlist size", 0, testManager.mConfigList.size());
+    }
+
+    public void testOverlappingChannels2() {
+        TestIntRangeManager testManager = new TestIntRangeManager();
+        assertEquals("flags before test", 0, testManager.flags);
+        assertTrue("enabling range 1", testManager.enableRange(100, 200, "client1"));
+        assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+        assertEquals("configlist size", 1, testManager.mConfigList.size());
+        checkConfigInfo(testManager.mConfigList.get(0), 100, 200, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, true);
+        testManager.reset();
+        assertTrue("enabling range 2", testManager.enableRange(150, 250, "client2"));
+        assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+        assertEquals("configlist size", 1, testManager.mConfigList.size());
+        checkConfigInfo(testManager.mConfigList.get(0), 201, 250, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, true);
+        testManager.reset();
+        assertTrue("disabling range 2", testManager.disableRange(150, 250, "client2"));
+        assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+        assertEquals("configlist size", 1, testManager.mConfigList.size());
+        checkConfigInfo(testManager.mConfigList.get(0), 201, 250, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, false);
+        testManager.reset();
+        assertTrue("updating ranges", testManager.updateRanges());
+        assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+        assertEquals("configlist size", 1, testManager.mConfigList.size());
+        checkConfigInfo(testManager.mConfigList.get(0), 100, 200, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, true);
+        testManager.reset();
+        assertTrue("disabling range 1", testManager.disableRange(100, 200, "client1"));
+        assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+        assertEquals("configlist size", 1, testManager.mConfigList.size());
+        checkConfigInfo(testManager.mConfigList.get(0), 100, 200, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, false);
+    }
+
+    public void testMultipleOverlappingChannels() {
+        TestIntRangeManager testManager = new TestIntRangeManager();
+        assertEquals("flags before test", 0, testManager.flags);
+        assertTrue("enabling range 1", testManager.enableRange(67, 9999, "client1"));
+        assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+        assertEquals("configlist size", 1, testManager.mConfigList.size());
+        checkConfigInfo(testManager.mConfigList.get(0), 67, 9999, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, true);
+        testManager.reset();
+        assertTrue("enabling range 2", testManager.enableRange(150, 250, "client2"));
+        assertEquals("flags after test", 0, testManager.flags);
+        assertEquals("configlist size", 0, testManager.mConfigList.size());
+        testManager.reset();
+        assertTrue("enabling range 3", testManager.enableRange(25, 75, "client3"));
+        assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+        assertEquals("configlist size", 1, testManager.mConfigList.size());
+        checkConfigInfo(testManager.mConfigList.get(0), 25, 66, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, true);
+        testManager.reset();
+        assertTrue("enabling range 4", testManager.enableRange(12, 500, "client4"));
+        assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+        assertEquals("configlist size", 1, testManager.mConfigList.size());
+        checkConfigInfo(testManager.mConfigList.get(0), 12, 24, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, true);
+        testManager.reset();
+        assertTrue("enabling range 5", testManager.enableRange(8000, 9998, "client5"));
+        assertEquals("flags after test", 0, testManager.flags);
+        assertEquals("configlist size", 0, testManager.mConfigList.size());
+        testManager.reset();
+        assertTrue("enabling range 6", testManager.enableRange(50000, 65535, "client6"));
+        assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+        assertEquals("configlist size", 1, testManager.mConfigList.size());
+        checkConfigInfo(testManager.mConfigList.get(0), 50000, 65535, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, true);
+        testManager.reset();
+        assertTrue("updating ranges", testManager.updateRanges());
+        assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+        assertEquals("configlist size", 2, testManager.mConfigList.size());
+        checkConfigInfo(testManager.mConfigList.get(0), 12, 9999, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, true);
+        checkConfigInfo(testManager.mConfigList.get(1), 50000, 65535, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, true);
+        testManager.reset();
+        assertTrue("disabling range 1", testManager.disableRange(67, 9999, "client1"));
+        assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+        assertEquals("configlist size", 2, testManager.mConfigList.size());
+        checkConfigInfo(testManager.mConfigList.get(0), 501, 7999, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, false);
+        checkConfigInfo(testManager.mConfigList.get(1), 9999, 9999, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, false);
+        testManager.reset();
+        assertTrue("updating ranges", testManager.updateRanges());
+        assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+        assertEquals("configlist size", 3, testManager.mConfigList.size());
+        checkConfigInfo(testManager.mConfigList.get(0), 12, 500, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, true);
+        checkConfigInfo(testManager.mConfigList.get(1), 8000, 9998, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, true);
+        checkConfigInfo(testManager.mConfigList.get(2), 50000, 65535, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, true);
+        testManager.reset();
+        assertTrue("disabling range 4", testManager.disableRange(12, 500, "client4"));
+        assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+        assertEquals("configlist size", 3, testManager.mConfigList.size());
+        checkConfigInfo(testManager.mConfigList.get(0), 12, 24, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, false);
+        checkConfigInfo(testManager.mConfigList.get(1), 76, 149, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, false);
+        checkConfigInfo(testManager.mConfigList.get(2), 251, 500, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, false);
+        testManager.reset();
+        assertTrue("updating ranges", testManager.updateRanges());
+        assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+        assertEquals("configlist size", 4, testManager.mConfigList.size());
+        checkConfigInfo(testManager.mConfigList.get(0), 25, 75, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, true);
+        checkConfigInfo(testManager.mConfigList.get(1), 150, 250, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, true);
+        checkConfigInfo(testManager.mConfigList.get(2), 8000, 9998, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, true);
+        checkConfigInfo(testManager.mConfigList.get(3), 50000, 65535, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, true);
+        testManager.reset();
+        assertTrue("disabling range 5", testManager.disableRange(8000, 9998, "client5"));
+        assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+        assertEquals("configlist size", 1, testManager.mConfigList.size());
+        checkConfigInfo(testManager.mConfigList.get(0), 8000, 9998, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, false);
+        testManager.reset();
+        assertTrue("updating ranges", testManager.updateRanges());
+        assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+        assertEquals("configlist size", 3, testManager.mConfigList.size());
+        checkConfigInfo(testManager.mConfigList.get(0), 25, 75, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, true);
+        checkConfigInfo(testManager.mConfigList.get(1), 150, 250, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, true);
+        checkConfigInfo(testManager.mConfigList.get(2), 50000, 65535, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, true);
+        testManager.reset();
+        assertTrue("disabling range 6", testManager.disableRange(50000, 65535, "client6"));
+        assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+        assertEquals("configlist size", 1, testManager.mConfigList.size());
+        checkConfigInfo(testManager.mConfigList.get(0), 50000, 65535, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, false);
+        testManager.reset();
+        assertTrue("updating ranges", testManager.updateRanges());
+        assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+        assertEquals("configlist size", 2, testManager.mConfigList.size());
+        checkConfigInfo(testManager.mConfigList.get(0), 25, 75, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, true);
+        checkConfigInfo(testManager.mConfigList.get(1), 150, 250, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, true);
+        testManager.reset();
+        assertTrue("disabling range 2", testManager.disableRange(150, 250, "client2"));
+        assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+        assertEquals("configlist size", 1, testManager.mConfigList.size());
+        checkConfigInfo(testManager.mConfigList.get(0), 150, 250, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, false);
+        testManager.reset();
+        assertTrue("updating ranges", testManager.updateRanges());
+        assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+        assertEquals("configlist size", 1, testManager.mConfigList.size());
+        checkConfigInfo(testManager.mConfigList.get(0), 25, 75, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, true);
+        testManager.reset();
+        assertTrue("disabling range 3", testManager.disableRange(25, 75, "client3"));
+        assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+        assertEquals("configlist size", 1, testManager.mConfigList.size());
+        checkConfigInfo(testManager.mConfigList.get(0), 25, 75, SMS_CB_CODE_SCHEME_MIN,
+                SMS_CB_CODE_SCHEME_MAX, false);
+        testManager.reset();
+        assertTrue("updating ranges", testManager.updateRanges());
+        assertEquals("flags after test", FLAG_START_UPDATE_CALLED | FLAG_FINISH_UPDATE_CALLED,
+                testManager.flags);
+        assertEquals("configlist size", 0, testManager.mConfigList.size());
+    }
+}
diff --git a/test-runner/src/android/test/BundlePrinter.java b/test-runner/src/android/test/BundlePrinter.java
deleted file mode 100644
index 3c47379..0000000
--- a/test-runner/src/android/test/BundlePrinter.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright (C) 2007 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.test;
-
-import java.io.PrintStream;
-
-import android.os.Bundle;
-
-import junit.framework.AssertionFailedError;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.runner.BaseTestRunner;
-import junit.textui.ResultPrinter;
-
-
-/**
- * Subclass of ResultPrinter that adds test case results to a bundle.
- * 
- * {@hide} - This class is deprecated, and will be going away.  Please don't use it.
- */
-public class BundlePrinter extends ResultPrinter {
-
-    private Bundle mResults;
-    private boolean mFailure;
-    private boolean mError;
-    
-    public BundlePrinter(PrintStream writer, Bundle result) {
-        super(writer);
-        mResults = result;
-    }
-    
-    @Override
-    public void addError(Test test, Throwable t) {
-        mResults.putString(getComboName(test), BaseTestRunner.getFilteredTrace(t));
-        mFailure = true;
-        super.addError(test, t);
-    }
-
-    @Override
-    public void addFailure(Test test, AssertionFailedError t) {
-        mResults.putString(getComboName(test), BaseTestRunner.getFilteredTrace(t));
-        mError = true;
-        super.addFailure(test, t);
-    }
-
-    @Override
-    public void endTest(Test test) {
-        if (!mFailure && !mError) {
-            mResults.putString(getComboName(test), "passed");
-        }
-        super.endTest(test);
-    }
-
-    @Override
-    public void startTest(Test test) {
-        mFailure = false;
-        mError = false;
-        super.startTest(test);
-    }
-    
-    private String getComboName(Test test) {
-        return test.getClass().getName() + ":" + ((TestCase) test).getName();
-    }
-    
-}
diff --git a/test-runner/src/android/test/BundleTestListener.java b/test-runner/src/android/test/BundleTestListener.java
deleted file mode 100644
index 772713f..0000000
--- a/test-runner/src/android/test/BundleTestListener.java
+++ /dev/null
@@ -1,63 +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.test;
-
-import junit.framework.*;
-import junit.framework.TestCase;
-import junit.runner.BaseTestRunner;
-import android.os.Bundle;
-
-/**
- * A {@link TestListener} that adds test case results to a bundle.
- * 
- * {@hide} - This class is deprecated, and will be going away.  Please don't use it.
- */
-public class BundleTestListener implements TestListener {
-
-    private Bundle mBundle;
-    private boolean mFailed;
-
-    public BundleTestListener(Bundle bundle) {
-        mBundle = bundle;
-    }
-
-
-    public void addError(Test test, Throwable t) {
-        mBundle.putString(getComboName(test), BaseTestRunner.getFilteredTrace(t));
-        mFailed = true;
-    }
-
-    public void addFailure(Test test, junit.framework.AssertionFailedError t) {
-        mBundle.putString(getComboName(test), BaseTestRunner.getFilteredTrace(t));
-        mFailed = true;
-    }
-
-    public void endTest(Test test) {
-        if (!mFailed) {
-            mBundle.putString(getComboName(test), "passed");
-        }
-    }
-
-    public void startTest(Test test) {
-        mFailed = false;
-    }
-
-    private String getComboName(Test test) {
-        return test.getClass().getName() + ":" + ((TestCase) test).getName();
-    }
-
-}
diff --git a/test-runner/src/android/test/ServiceLocator.java b/test-runner/src/android/test/ServiceLocator.java
deleted file mode 100644
index 3324008..0000000
--- a/test-runner/src/android/test/ServiceLocator.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2007 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.test;
-
-/**
- * @hide - This is part of a framework that is under development and should not be used for
- * active development.
- */
-public class ServiceLocator {
-
-    private static TestBrowserController mTestBrowserController =
-            new TestBrowserControllerImpl();
-
-    public static TestBrowserController getTestBrowserController() {
-        return mTestBrowserController;
-    }
-
-    static void setTestBrowserController(TestBrowserController testBrowserController) {
-        mTestBrowserController = testBrowserController;
-    }
-}
diff --git a/test-runner/src/android/test/TestBrowserActivity.java b/test-runner/src/android/test/TestBrowserActivity.java
deleted file mode 100644
index ea5f91e..0000000
--- a/test-runner/src/android/test/TestBrowserActivity.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Copyright (C) 2007 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.test;
-
-import com.android.internal.R;
-
-import android.app.ListActivity;
-import android.content.Intent;
-import android.os.Bundle;
-import android.util.Log;
-import android.view.View;
-import android.widget.AdapterView;
-import android.widget.ArrayAdapter;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-import java.util.List;
-
-/**
- * @hide - This is part of a framework that is under development and should not be used for
- * active development.
- */
-public abstract class TestBrowserActivity extends ListActivity
-        implements android.test.TestBrowserView, AdapterView.OnItemClickListener,
-        TestSuiteProvider {
-
-    private TestBrowserController mTestBrowserController;
-    public static final String BUNDLE_EXTRA_PACKAGE = "package";
-
-    @Override
-    protected void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-
-        getListView().setOnItemClickListener(this);
-
-        mTestBrowserController = ServiceLocator.getTestBrowserController();
-        mTestBrowserController.setTargetPackageName(getPackageName());
-        mTestBrowserController.registerView(this);
-        mTestBrowserController.setTargetBrowserActivityClassName(this.getClass().getName());
-
-        // Apk paths used to search for test classes when using TestSuiteBuilders.
-        String[] apkPaths = {getPackageCodePath()};
-        ClassPathPackageInfoSource.setApkPaths(apkPaths);
-    }
-
-    @Override
-    protected void onStart() {
-        super.onStart();
-        TestSuite testSuite = getTestSuiteToBrowse();
-        mTestBrowserController.setTestSuite(testSuite);
-        
-        String name = testSuite.getName();
-        if (name != null) {
-            setTitle(name.substring(name.lastIndexOf(".") + 1));
-        }
-    }
-
-    /**
-     * Subclasses will override this method and return the TestSuite specific to their .apk.
-     * When this method is invoked due to an intent fired from
-     * {@link #onItemClick(android.widget.AdapterView, android.view.View, int, long)} then get the
-     * targeted TestSuite from the intent.
-     *
-     * @return testSuite to browse
-     */
-    @SuppressWarnings("unchecked")
-    private TestSuite getTestSuiteToBrowse() {
-        Intent intent = getIntent();
-        if (Intent.ACTION_RUN.equals(intent.getAction())) {
-            String testClassName = intent.getData().toString();
-
-            try {
-                Class<Test> testClass = (Class<Test>) getClassLoader().loadClass(testClassName);
-                return TestCaseUtil.createTestSuite(testClass);
-            } catch (ClassNotFoundException e) {
-                Log.e("TestBrowserActivity", "ClassNotFoundException for " + testClassName, e);
-                throw new RuntimeException(e);
-            } catch (IllegalAccessException e) {
-                Log.e("TestBrowserActivity", "IllegalAccessException for " + testClassName, e);
-                throw new RuntimeException(e);
-            } catch (InstantiationException e) {
-                Log.e("TestBrowserActivity", "InstantiationException for " + testClassName, e);
-                throw new RuntimeException(e);
-            }
-        } else {
-            // get test classes to browwes from subclass
-            return getTopTestSuite();
-        }
-
-    }
-
-    public TestSuite getTestSuite() {
-        return getTopTestSuite();
-    }
-
-    /**
-     * @return A TestSuite that should be run for a given application.
-     */
-    public abstract TestSuite getTopTestSuite();
-
-    public void onItemClick(AdapterView parent, View v, int position, long id) {
-        Intent intent = mTestBrowserController.getIntentForTestAt(position);
-        intent.putExtra(BUNDLE_EXTRA_PACKAGE, getPackageName());
-        startActivity(intent);
-    }
-
-    public void setTestNames(List<String> testNames) {
-        ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,
-                R.layout.test_list_item, testNames);
-        setListAdapter(arrayAdapter);
-    }
-}
-
diff --git a/test-runner/src/android/test/TestBrowserController.java b/test-runner/src/android/test/TestBrowserController.java
deleted file mode 100644
index 044e39f..0000000
--- a/test-runner/src/android/test/TestBrowserController.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (C) 2007 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.test;
-
-import android.content.Intent;
-import junit.framework.TestSuite;
-
-/**
- * @hide - This is part of a framework that is under development and should not be used for
- * active development.
- */
-public interface TestBrowserController {
-    String BUNDLE_EXTRA_TEST_METHOD_NAME = "testMethodName";
-
-    Intent getIntentForTestAt(int position);
-
-    void setTestSuite(TestSuite testSuite);
-
-    void registerView(TestBrowserView testBrowserView);
-
-    void setTargetBrowserActivityClassName(String targetBrowserActivityClassName);
-
-    void setTargetPackageName(String targetPackageName);
-}
diff --git a/test-runner/src/android/test/TestBrowserControllerImpl.java b/test-runner/src/android/test/TestBrowserControllerImpl.java
deleted file mode 100644
index b8f8975..0000000
--- a/test-runner/src/android/test/TestBrowserControllerImpl.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright (C) 2007 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.test;
-
-import android.content.Intent;
-import android.net.Uri;
-import com.google.android.collect.Lists;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-import java.util.List;
-
-/**
- * @hide - This is part of a framework that is under development and should not be used for
- * active development.
- */
-public class TestBrowserControllerImpl implements TestBrowserController {
-
-    static final String TEST_RUNNER_ACTIVITY_CLASS_NAME =
-           "com.android.testharness.TestRunnerActivity";
-
-    private TestSuite mTestSuite;
-    private TestBrowserView mTestBrowserView;
-    private static final int RUN_ALL_INDEX = 0;
-    private String mTargetBrowserActivityClassName;
-    private String mTargetPackageName;
-
-    public void setTargetPackageName(String targetPackageName) {
-        mTargetPackageName = targetPackageName;
-    }
-
-    public Intent getIntentForTestAt(int position) {
-        Intent intent = new Intent();
-        intent.setAction(Intent.ACTION_RUN);
-        // We must add the following two flags to make sure that we create a new activity when
-        // we browse nested test suites.
-        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-        intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
-
-        String packageName = getDefaultPackageNameForTestRunner();
-        String className = "";
-        String testName = "";
-        if (shouldAllTestsBeRun(position)) {
-            testName = mTestSuite.getName();
-            className = TEST_RUNNER_ACTIVITY_CLASS_NAME;
-        } else {
-            Test test = TestCaseUtil.getTestAtIndex(mTestSuite, position - 1);
-            if (TestSuite.class.isAssignableFrom(test.getClass())) {
-                TestSuite testSuite = (TestSuite) test;
-                testName = testSuite.getName();
-                className = mTargetBrowserActivityClassName;
-                packageName = mTargetPackageName;
-            } else if (TestCase.class.isAssignableFrom(test.getClass())) {
-                TestCase testCase = (TestCase) test;
-                testName = testCase.getClass().getName();
-                className = TEST_RUNNER_ACTIVITY_CLASS_NAME;
-                String testMethodName = testCase.getName();
-                intent.putExtra(BUNDLE_EXTRA_TEST_METHOD_NAME, testMethodName);
-            }
-        }
-
-        intent.setClassName(packageName, className);
-        intent.setData(Uri.parse(testName));
-
-        return intent;
-    }
-
-    private String getDefaultPackageNameForTestRunner() {
-        return TEST_RUNNER_ACTIVITY_CLASS_NAME.substring(0,
-                TEST_RUNNER_ACTIVITY_CLASS_NAME.lastIndexOf("."));
-    }
-
-    private boolean shouldAllTestsBeRun(int position) {
-        return position == RUN_ALL_INDEX;
-    }
-
-    public void setTestSuite(TestSuite testSuite) {
-        mTestSuite = testSuite;
-
-        List<String> testCaseNames = Lists.newArrayList();
-        testCaseNames.add("Run All");
-        testCaseNames.addAll(TestCaseUtil.getTestCaseNames(testSuite, false));
-
-        mTestBrowserView.setTestNames(testCaseNames);
-    }
-
-    public void registerView(TestBrowserView testBrowserView) {
-        mTestBrowserView = testBrowserView;
-    }
-
-
-    public void setTargetBrowserActivityClassName(String targetBrowserActivityClassName) {
-        mTargetBrowserActivityClassName = targetBrowserActivityClassName;
-    }
-}
diff --git a/test-runner/src/android/test/TestBrowserView.java b/test-runner/src/android/test/TestBrowserView.java
deleted file mode 100644
index 4799f196..0000000
--- a/test-runner/src/android/test/TestBrowserView.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (C) 2007 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.test;
-
-import java.util.List;
-
-/**
- * @hide - This is part of a framework that is under development and should not be used for
- * active development.
- */
-public interface TestBrowserView {
-    void setTestNames(List<String> testNames);
-}
diff --git a/test-runner/src/android/test/TestListActivity.java b/test-runner/src/android/test/TestListActivity.java
deleted file mode 100644
index a076a70..0000000
--- a/test-runner/src/android/test/TestListActivity.java
+++ /dev/null
@@ -1,253 +0,0 @@
-/*
- * Copyright (C) 2007 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.test;
-
-import android.app.ListActivity;
-import android.content.Intent;
-import android.database.MatrixCursor;
-import android.net.Uri;
-import android.os.Bundle;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.View;
-import android.widget.CursorAdapter;
-import android.widget.ListView;
-import android.widget.SimpleCursorAdapter;
-
-import java.util.Arrays;
-import java.util.Comparator;
-
-/**
- * Activity base class to use to implement your application's tests.
- *
- * <p>Implement the getTestSuite() method to return the name of your
- * test suite class.
- *
- * <p>See the android.test package documentation (click the more... link)
- * for a full description
- * 
- * {@hide} Not needed for SDK
- */
-public abstract class TestListActivity extends ListActivity {
-    /** Supplied in the intent extras if we are running performance tests. */
-    public static final String PERFORMANCE_TESTS = "android.test.performance";
-
-    /** "Mode" group in the menu. */
-    static final int MODE_GROUP = Menu.FIRST;
-
-    /** Our suite */
-    String mSuite;
-
-    /** Our children tests */
-    String[] mTests;
-
-    /** which mode, REGRESSION, PERFORMANCE or PROFILING */
-    private int mMode = TestRunner.REGRESSION;
-
-    /** "Regression" menu item */
-    private MenuItem mRegressionItem;
-
-    /** "Performance" menu item */
-    private MenuItem mPerformanceItem;
-
-    /** "Profiling" menu item */
-    private MenuItem mProfilingItem;
-
-    private final Comparator<String> sComparator = new Comparator<String>() {
-        public final int compare(String a, String b) {
-            String s1 = makeCompareName(a);
-            String s2 = makeCompareName(b);
-            
-            return s1.compareToIgnoreCase(s2);
-        }
-    };
-
-    /**
-     * Constructor that doesn't do much.
-     */
-    public TestListActivity() {
-        super();
-    }
-
-    /**
-     * Subclasses should implement this to return the names of the classes
-     * of their tests.
-     *
-     * @return test suite class name
-     */
-    public abstract String getTestSuite();
-
-    /**
-     * Typical onCreate(Bundle icicle) implementation.
-     */
-    public void onCreate(Bundle icicle) {
-        super.onCreate(icicle);
-
-        Intent intent = getIntent();
-
-        mMode = intent.getIntExtra(TestListActivity.PERFORMANCE_TESTS, mMode);
-
-
-        if (intent.getAction().equals(Intent.ACTION_MAIN)) {
-            // if we were called as MAIN, get the test suites,
-            mSuite = getTestSuite();
-        } else if (intent.getAction().equals(Intent.ACTION_RUN)) {
-            // We should have been provided a status channel.  Bail out and
-            // run the test instead.  This is how the TestHarness gets us
-            // loaded in our process for "Run All Tests."
-            Intent ntent = new Intent(Intent.ACTION_RUN,
-                    intent.getData() != null
-                            ? intent.getData()
-                            : Uri.parse(getTestSuite()));
-            ntent.setClassName("com.android.testharness",
-                    "com.android.testharness.RunTest");
-            ntent.putExtras(intent);
-            ntent.putExtra("package", getPackageName());
-            startActivity(ntent);
-            finish();
-            return;
-        } else if (intent.getAction().equals(Intent.ACTION_VIEW)) {
-            // otherwise use the one in the intent
-            mSuite = intent.getData() != null ? intent.getData().toString()
-                    : null;
-        }
-
-        String[] children = TestRunner.getChildren(this, mSuite);
-
-        Arrays.sort(children, sComparator);
-
-        int len = children.length;
-        mTests = new String[len];
-        System.arraycopy(children, 0, mTests, 0, len);
-
-        setTitle(TestRunner.getTitle(mSuite));
-
-        MatrixCursor cursor = new MatrixCursor(new String[] { "name", "_id" });
-        addTestRows(cursor);
-
-        CursorAdapter adapter = new SimpleCursorAdapter(
-                this,
-                com.android.internal.R.layout.simple_list_item_1,
-                cursor,
-                new String[] {"name"},
-                new int[] {com.android.internal.R.id.text1});
-        
-        setListAdapter(adapter);
-    }
-
-    private void addTestRows(MatrixCursor cursor) {
-        int id = 0;
-        cursor.newRow().add("Run All").add(id++);       
-        for (String test : mTests) {
-            String title = TestRunner.getTitle(test);
-            String prefix = TestRunner.isTestSuite(this, test)
-                    ? "Browse " : "Run ";
-
-            // I'd rather do this with an icon column, but I don't know how
-            cursor.newRow().add(prefix + title).add(id++);
-        }
-    }
-
-    @Override
-    protected void onResume() {
-        super.onResume();
-    }
-
-    @Override
-    public boolean onCreateOptionsMenu(Menu menu) {
-        super.onCreateOptionsMenu(menu);
-        mRegressionItem = menu.add(MODE_GROUP, -1, 0, "Regression Mode");
-        mPerformanceItem = menu.add(MODE_GROUP, -1, 0, "Performance Mode");
-        mProfilingItem = menu.add(MODE_GROUP, -1, 0, "Profiling Mode");
-        menu.setGroupCheckable(MODE_GROUP, true, true);
-        return true;
-    }
-
-    @Override
-    public boolean onOptionsItemSelected(MenuItem item) {
-        if (item == mRegressionItem) {
-            mMode = TestRunner.REGRESSION;
-        } else if (item == mPerformanceItem) {
-            mMode = TestRunner.PERFORMANCE;
-        } else if (item == mProfilingItem) {
-            mMode = TestRunner.PROFILING;
-        }
-        
-        return true;
-    }
-
-    @Override
-    public boolean onPrepareOptionsMenu(Menu menu) {
-        super.onPrepareOptionsMenu(menu);
-        switch (mMode) {
-        case TestRunner.REGRESSION:
-            mRegressionItem.setChecked(true);
-            break;
-
-        case TestRunner.PERFORMANCE:
-            mPerformanceItem.setChecked(true);
-            break;
-
-        case TestRunner.PROFILING:
-            mProfilingItem.setChecked(true);
-            break;
-        }
-        return true;
-    }
-
-    @Override
-    protected void onListItemClick(ListView l, View v, int position, long id) {
-        Intent intent = new Intent();
-
-        if (position == 0) {
-            if (false) {
-                intent.setClassName("com.android.testharness",
-                        "com.android.testharness.RunAll");
-                intent.putExtra("tests", new String[]{mSuite});
-            } else {
-                intent.setClassName("com.android.testharness",
-                        "com.android.testharness.RunTest");
-                intent.setAction(Intent.ACTION_RUN);
-                intent.setData(Uri.parse(mSuite));
-            }
-        } else {
-            String test = mTests[position - 1];
-            if (TestRunner.isTestSuite(this, test)) {
-                intent.setClassName(getPackageName(), this.getClass().getName());
-                intent.setAction(Intent.ACTION_VIEW);
-            } else {
-                intent.setClassName("com.android.testharness",
-                        "com.android.testharness.RunTest");
-            }
-            intent.setData(Uri.parse(test));
-        }
-
-        intent.putExtra(PERFORMANCE_TESTS, mMode);
-        intent.putExtra("package", getPackageName());
-        startActivity(intent);
-    }
-
-    private String makeCompareName(String s) {
-        int index = s.lastIndexOf('.');
-        
-        if (index == -1) {
-            return s;
-        }
-        
-        return s.substring(index + 1);
-    }
-}
diff --git a/test-runner/src/android/test/TestRecorder.java b/test-runner/src/android/test/TestRecorder.java
deleted file mode 100644
index 7c368a0..0000000
--- a/test-runner/src/android/test/TestRecorder.java
+++ /dev/null
@@ -1,186 +0,0 @@
-/*
- * Copyright (C) 2006 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.test;
-
-import android.content.ContentValues;
-import android.database.sqlite.SQLiteDatabase;
-import android.os.Environment;
-import android.os.FileUtils;
-import android.test.TestRunner.IntermediateTime;
-import android.util.Log;
-import junit.framework.Test;
-import junit.framework.TestListener;
-
-import java.io.File;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-/**
- * {@hide} Not needed for 1.0 SDK.
- */
-public class TestRecorder implements TestRunner.Listener, TestListener {
-    private static final int DATABASE_VERSION = 1;
-    private static SQLiteDatabase sDb;
-    private Set<String> mFailedTests = new HashSet<String>();
-
-    private static SQLiteDatabase getDatabase() {
-        if (sDb == null) {
-            File dir = new File(Environment.getDataDirectory(), "test_results");
-
-            /* TODO: add a DB version number and bootstrap/upgrade methods
-            * if the format of the table changes.
-            */
-            String dbName = "TestHarness.db";
-            File file = new File(dir, dbName);
-            sDb = SQLiteDatabase.openOrCreateDatabase(file.getPath(), null);
-
-            if (sDb.getVersion() == 0) {
-                int code = FileUtils.setPermissions(file.getPath(),
-                        FileUtils.S_IRUSR | FileUtils.S_IWUSR |
-                                FileUtils.S_IRGRP | FileUtils.S_IWGRP |
-                                FileUtils.S_IROTH | FileUtils.S_IWOTH, -1, -1);
-    
-                if (code != 0) {
-                    Log.w("TestRecorder",
-                            "Set permissions for " + file.getPath() + " returned = " + code);
-                }
-    
-                try {
-                    sDb.execSQL("CREATE TABLE IF NOT EXISTS tests (_id INT PRIMARY KEY," +
-                            "name TEXT," +
-                            "result TEXT," +
-                            "exception TEXT," +
-                            "started INTEGER," +
-                            "finished INTEGER," +
-                            "time INTEGER," +
-                            "iterations INTEGER," +
-                            "allocations INTEGER," +
-                            "parent INTEGER);");
-                    sDb.setVersion(DATABASE_VERSION);
-                } catch (Exception e) {
-                    Log.e("TestRecorder", "failed to create table 'tests'", e);
-                    sDb = null;
-                }
-            }
-        }
-
-        return sDb;
-    }
-
-    public TestRecorder() {
-    }
-
-    public void started(String className) {
-        ContentValues map = new ContentValues(2);
-        map.put("name", className);
-        map.put("started", System.currentTimeMillis());
-
-        // try to update the row first in case we've ran this test before.
-        int rowsAffected = getDatabase().update("tests", map, "name = '" + className + "'", null);
-
-        if (rowsAffected == 0) {
-            getDatabase().insert("tests", null, map);
-        }
-    }
-
-    public void finished(String className) {
-        ContentValues map = new ContentValues(1);
-        map.put("finished", System.currentTimeMillis());
-
-        getDatabase().update("tests", map, "name = '" + className + "'", null);
-    }
-
-    public void performance(String className, long itemTimeNS, int iterations, List<IntermediateTime> intermediates) {
-        ContentValues map = new ContentValues();
-        map.put("time", itemTimeNS);
-        map.put("iterations", iterations);
-
-        getDatabase().update("tests", map, "name = '" + className + "'", null);
-
-        if (intermediates != null && intermediates.size() > 0) {
-            int n = intermediates.size();
-            for (int i = 0; i < n; i++) {
-                TestRunner.IntermediateTime time = intermediates.get(i);
-
-                getDatabase().execSQL("INSERT INTO tests (name, time, parent) VALUES ('" +
-                        time.name + "', " + time.timeInNS + ", " +
-                        "(SELECT _id FROM tests WHERE name = '" + className + "'));");
-            }
-        }
-    }
-
-    public void passed(String className) {
-        ContentValues map = new ContentValues();
-        map.put("result", "passed");
-
-        getDatabase().update("tests", map, "name = '" + className + "'", null);
-    }
-
-    public void failed(String className, Throwable exception) {
-        StringWriter stringWriter = new StringWriter();
-        PrintWriter printWriter = new PrintWriter(stringWriter);
-        try {
-            exception.printStackTrace(printWriter);
-        } finally {
-            printWriter.close();
-        }
-        ContentValues map = new ContentValues();
-        map.put("result", "failed");
-        map.put("exception", stringWriter.toString());
-
-        getDatabase().update("tests", map, "name = '" + className + "'", null);
-    }
-
-    /**
-     * Reports a test case failure.
-     *
-     * @param className Name of the class/test.
-     * @param reason    Reason for failure.
-     */
-    public void failed(String className, String reason) {
-        ContentValues map = new ContentValues();
-        map.put("result", "failed");
-        // The reason is put as the exception.
-        map.put("exception", reason);
-        getDatabase().update("tests", map, "name = '" + className + "'", null);
-    }
-
-    public void addError(Test test, Throwable t) {
-        mFailedTests.add(test.toString());
-        failed(test.toString(), t);
-    }
-
-    public void addFailure(Test test, junit.framework.AssertionFailedError t) {
-        mFailedTests.add(test.toString());
-        failed(test.toString(), t.getMessage());
-    }
-
-    public void endTest(Test test) {
-        finished(test.toString());
-        if (!mFailedTests.contains(test.toString())) {
-            passed(test.toString());
-        }
-        mFailedTests.remove(test.toString());
-    }
-
-    public void startTest(Test test) {
-        started(test.toString());
-    }
-}
diff --git a/test-runner/src/android/test/TestRunnerView.java b/test-runner/src/android/test/TestRunnerView.java
deleted file mode 100644
index be90951..0000000
--- a/test-runner/src/android/test/TestRunnerView.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2007 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.test;
-
-import java.util.List;
-
-/**
- * @hide - This is part of a framework that is under development and should not be used for
- * active development.
- */
-public interface TestRunnerView {
-    void setTestNames(List<String> testNames);
-
-    void setItemColorAt(int position, int color);
-
-    void setFailureCount(int failureCount);
-
-    void setRunCount(int runCount);
-
-    void setErrorCount(int errorCount);
-
-    void setTotalCount(int totalCount);
-
-    void setProgressBarColor(int color);
-
-    void testsCompleted();
-}
diff --git a/test-runner/src/junit/runner/logo.gif b/test-runner/src/junit/runner/logo.gif
deleted file mode 100644
index d0e1547..0000000
--- a/test-runner/src/junit/runner/logo.gif
+++ /dev/null
Binary files differ
diff --git a/test-runner/src/junit/runner/smalllogo.gif b/test-runner/src/junit/runner/smalllogo.gif
deleted file mode 100644
index 7b25eaf6..0000000
--- a/test-runner/src/junit/runner/smalllogo.gif
+++ /dev/null
Binary files differ
diff --git a/test-runner/tests/src/android/test/StubTestBrowserActivity.java b/test-runner/tests/src/android/test/StubTestBrowserActivity.java
deleted file mode 100644
index 97ed3ce..0000000
--- a/test-runner/tests/src/android/test/StubTestBrowserActivity.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2007 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.test;
-
-import junit.framework.TestSuite;
-
-public class StubTestBrowserActivity extends TestBrowserActivity {
-
-    private static TestSuite mTestSuite;
-
-    static void setTopTestSuite(TestSuite testSuite) {
-        mTestSuite = testSuite;
-    }
-
-    @Override
-    public TestSuite getTopTestSuite() {
-        return mTestSuite;
-    }
-}
diff --git a/test-runner/tests/src/android/test/TestBrowserActivityTest.java b/test-runner/tests/src/android/test/TestBrowserActivityTest.java
deleted file mode 100644
index 355409e..0000000
--- a/test-runner/tests/src/android/test/TestBrowserActivityTest.java
+++ /dev/null
@@ -1,275 +0,0 @@
-/*
- * Copyright (C) 2007 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.test;
-
-import android.app.Activity;
-import android.app.Instrumentation;
-import android.content.Intent;
-import android.net.Uri;
-import android.os.RemoteException;
-import android.os.ServiceManager;
-import android.view.IWindowManager;
-import android.widget.ListView;
-
-import com.google.android.collect.Lists;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-import java.util.List;
-
-public class TestBrowserActivityTest extends InstrumentationTestCase {
-
-    private TestBrowserActivity mTestBrowserActivity;
-    private StubTestBrowserController mTestBrowserController;
-
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        StubTestBrowserActivity.setTopTestSuite(null);
-        mTestBrowserController = new StubTestBrowserController();
-        ServiceLocator.setTestBrowserController(mTestBrowserController);
-    }
-
-    @Override
-    protected void tearDown() throws Exception {
-        if (mTestBrowserActivity != null) {
-            mTestBrowserActivity.finish();
-        }
-        mTestBrowserActivity = null;
-        super.tearDown();
-    }
-
-    public void testEmptyListContent() throws Exception {
-        StubTestBrowserActivity.setTopTestSuite(new TestSuite());
-
-        mTestBrowserActivity = createActivity();
-
-        ListView listView = getListView();
-        // There is always an item on the list for running all tests.
-        assertEquals("Unexpected number of items on list view.", 1, listView.getCount());
-
-        assertEquals("Stubbed Test Browser", mTestBrowserActivity.getTitle().toString());
-    }
-
-    public void testOneListContent() throws Exception {
-        List<String> testCaseNames = Lists.newArrayList("AllTests");
-        StubTestBrowserActivity.setTopTestSuite(createTestSuite(testCaseNames));
-
-        mTestBrowserActivity = createActivity();
-
-        ListView listView = getListView();
-        assertListViewContents(testCaseNames, listView);
-    }
-
-    public void testListWithTestCases() throws Exception {
-        List<String> testCaseNames = Lists.newArrayList("AllTests", "Apples", "Bananas", "Oranges");
-        StubTestBrowserActivity.setTopTestSuite(createTestSuite(testCaseNames));
-
-        mTestBrowserActivity = createActivity();
-
-        ListView listView = getListView();
-        assertListViewContents(testCaseNames, listView);
-    }
-
-    public void testListWithTestSuite() throws Exception {
-        List<String> testCaseNames = Lists.newArrayList(OneTestTestCase.class.getSimpleName());
-        StubTestBrowserActivity.setTopTestSuite(new OneTestInTestSuite());
-
-        mTestBrowserActivity = createActivity();
-
-        ListView listView = getListView();
-        assertListViewContents(testCaseNames, listView);
-    }
-
-    public void testSelectATestCase() throws Exception {
-        List<String> testCaseNames = Lists.newArrayList("AllTests");
-        TestSuite testSuite = createTestSuite(testCaseNames);
-        StubTestBrowserActivity.setTopTestSuite(testSuite);
-
-        mTestBrowserController.setTestCase(OneTestTestCase.class);
-        mTestBrowserActivity = createActivity();
-
-        Instrumentation.ActivityMonitor activityMonitor = getInstrumentation().addMonitor(
-                TestBrowserControllerImpl.TEST_RUNNER_ACTIVITY_CLASS_NAME, null, false);
-        try {
-            assertEquals(0, activityMonitor.getHits());
-
-            ListView listView = getListView();
-            int invokedTestCaseIndex = 0;
-            listView.performItemClick(listView, invokedTestCaseIndex, 0);
-
-            Activity activity = activityMonitor.waitForActivityWithTimeout(2000);
-            assertNotNull(activity);
-            try {
-                assertEquals(1, activityMonitor.getHits());
-                assertEquals(invokedTestCaseIndex, mTestBrowserController.getLastPosition());
-            } finally {
-                activity.finish();
-            }
-        } finally {
-            getInstrumentation().removeMonitor(activityMonitor);
-        }
-    }
-
-    public void testCreateFromIntentWithOneTest() throws Exception {
-        List<String> testCaseNames = Lists.newArrayList("testOne");
-
-        mTestBrowserActivity = launchTestBrowserActivity(new TestSuite(OneTestTestCase.class));
-
-        ListView listView = getListView();
-        assertListViewContents(testCaseNames, listView);
-    }
-
-    public void testUpdateListOnStart() throws Exception {
-        StubTestBrowserActivity.setTopTestSuite(new TestSuite());
-
-        mTestBrowserActivity = createActivity();
-
-        ListView listView = getListView();
-        assertEquals("Unexpected number of items on list view.", 1, listView.getCount());
-
-        List<String> testCaseNames = Lists.newArrayList("AllTests");
-        StubTestBrowserActivity.setTopTestSuite(createTestSuite(testCaseNames));
-
-        getInstrumentation().runOnMainSync(new Runnable() {
-            public void run() {
-                ((StubTestBrowserActivity) mTestBrowserActivity).onStart();
-            }
-        });
-
-        listView = getListView();
-        assertListViewContents(testCaseNames, listView);
-    }
-
-    public void testTitleHasTestSuiteName() throws Exception {
-        final String testSuiteName = "com.android.TestSuite";
-        StubTestBrowserActivity.setTopTestSuite(new TestSuite(testSuiteName));
-
-        mTestBrowserActivity = createActivity();
-
-        assertEquals("TestSuite", mTestBrowserActivity.getTitle().toString());
-    }
-    
-    private TestSuite createTestSuite(List<String> testCaseNames) {
-        return createTestSuite(testCaseNames.toArray(new String[testCaseNames.size()]));
-    }
-
-    private TestSuite createTestSuite(String... testCaseNames) {
-        TestSuite testSuite = new TestSuite();
-        for (String testCaseName : testCaseNames) {
-            testSuite.addTest(new FakeTestCase(testCaseName));
-        }
-
-        return testSuite;
-    }
-
-    public static class FakeTestCase extends TestCase {
-        public FakeTestCase(String name) {
-            super(name);
-        }
-    }
-
-    public static class OneTestTestCase extends TestCase {
-        public void testOne() throws Exception {
-        }
-    }
-
-    public static class OneTestInTestSuite extends TestSuite {
-        public static Test suite() {
-            TestSuite suite = new TestSuite(OneTestInTestSuite.class.getName());
-            suite.addTestSuite(OneTestTestCase.class);
-            return suite;
-        }
-    }
-
-    private void assertListViewContents(List<String> expectedTestCaseNames, ListView listView) {
-        assertEquals("Run All", listView.getItemAtPosition(0).toString());
-        assertEquals("Unexpected number of items on list view.",
-                expectedTestCaseNames.size() + 1, listView.getCount());
-        for (int i = 0; i < expectedTestCaseNames.size(); i++) {
-            String expectedTestCaseName = expectedTestCaseNames.get(i);
-            String actualTestCaseName = listView.getItemAtPosition(i + 1).toString();
-            assertEquals("Unexpected test case name. Index: " + i,
-                    expectedTestCaseName, actualTestCaseName);
-        }
-    }
-
-    private ListView getListView() {
-        return mTestBrowserActivity.getListView();
-    }
-
-    private TestBrowserActivity createActivity() throws RemoteException {
-        return launchActivity(getAndroidPackageName(), StubTestBrowserActivity.class, null);
-    }
-
-    private Intent createIntent(TestSuite testSuite) {
-        Intent intent = new Intent(Intent.ACTION_RUN);
-        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-        String className = StubTestBrowserActivity.class.getName();
-        String packageName = getAndroidPackageName();
-        intent.setClassName(packageName, className);
-        intent.setData(Uri.parse(testSuite.getName()));
-        return intent;
-    }
-
-    private String getAndroidPackageName() {
-        String packageName = getInstrumentation().getTargetContext().getPackageName();
-        return packageName;
-    }
-
-    private TestBrowserActivity launchTestBrowserActivity(TestSuite testSuite)
-            throws RemoteException {
-        getInstrumentation().setInTouchMode(false);
-
-        TestBrowserActivity activity =
-                (TestBrowserActivity) getInstrumentation().startActivitySync(
-                        createIntent(testSuite));
-        getInstrumentation().waitForIdleSync();
-        return activity;
-    }
-
-    private static class StubTestBrowserController extends TestBrowserControllerImpl {
-        private int mPosition;
-        private Class<? extends TestCase> mTestCaseClass;
-
-        public Intent getIntentForTestAt(int position) {
-            mPosition = position;
-
-            Intent intent = new Intent();
-            intent.setAction(Intent.ACTION_RUN);
-
-            String className = TestBrowserControllerImpl.TEST_RUNNER_ACTIVITY_CLASS_NAME;
-            String testName = mTestCaseClass.getClass().getName();
-
-            String packageName = className.substring(0, className.lastIndexOf("."));
-            intent.setClassName(packageName, className);
-            intent.setData(Uri.parse(testName));
-
-            return intent;
-        }
-
-        public void setTestCase(Class<? extends TestCase> testCaseClass) {
-            mTestCaseClass = testCaseClass;
-        }
-
-        public int getLastPosition() {
-            return mPosition;
-        }
-    }
-}
diff --git a/test-runner/tests/src/android/test/TestBrowserControllerImplTest.java b/test-runner/tests/src/android/test/TestBrowserControllerImplTest.java
deleted file mode 100644
index 1315606..0000000
--- a/test-runner/tests/src/android/test/TestBrowserControllerImplTest.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * Copyright (C) 2007 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.test;
-
-import android.content.Intent;
-
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-import java.util.Arrays;
-import java.util.List;
-
-public class TestBrowserControllerImplTest extends TestCase {
-    private TestBrowserControllerImpl mTestBrowserController;
-    private TestBrowserViewStub mTestBrowserView;
-
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        mTestBrowserController = new TestBrowserControllerImpl();
-        mTestBrowserView = new TestBrowserViewStub();
-        mTestBrowserController.registerView(mTestBrowserView);
-    }
-
-    public void testSetTestSuite() throws Exception {
-        TestSuite testSuite = new TestSuite();
-        testSuite.addTestSuite(DummyTestCase.class);
-
-        mTestBrowserController.setTestSuite(testSuite);
-
-        verifyTestNames(Arrays.asList("Run All", DummyTestCase.class.getSimpleName()),
-                mTestBrowserView.getTestNames());
-    }
-
-    private static void verifyTestNames(List<String> expectedTestNames,
-            List<String> actualTestNames) {
-        assertEquals(expectedTestNames.size(), actualTestNames.size());
-
-        // We use endsWith instead of equals because the return value of
-        // class.getSimpleName(), when called on an inner class, varies
-        // from one vm to another.
-        // This allows the test to pass in multiple environments.
-        for (int i = 0; i < expectedTestNames.size(); i++) {
-            assertTrue(actualTestNames.get(i).endsWith(expectedTestNames.get(i)));
-        }
-    }
-
-    public void testGetIntentForTestSuite() throws Exception {
-        TestSuite testSuite = new TestSuite();
-        testSuite.addTestSuite(DummyTestCase.class);
-
-        String targetBrowserActvityClassName = "com.android.bogus.DummyActivity";
-        String expectedTargetPackageName = "com.android.bogus";
-        mTestBrowserController.setTargetBrowserActivityClassName(targetBrowserActvityClassName);
-        mTestBrowserController.setTestSuite(testSuite);
-        mTestBrowserController.setTargetPackageName(expectedTargetPackageName);
-        Intent intent = mTestBrowserController.getIntentForTestAt(1);
-        verifyIntent(intent, DummyTestCase.class, expectedTargetPackageName);
-        assertEquals(targetBrowserActvityClassName, intent.getComponent().getClassName());
-    }
-
-    public void testGetIntentForTestCase() throws Exception {
-        TestSuite testSuite = new TestSuite();
-        testSuite.addTest(new DummyTestCase());
-
-        mTestBrowserController.setTestSuite(testSuite);
-        Intent intent = mTestBrowserController.getIntentForTestAt(1);
-        verifyIntent(intent, DummyTestCase.class, "com.android.testharness");
-        assertEquals(TestBrowserControllerImpl.TEST_RUNNER_ACTIVITY_CLASS_NAME,
-                intent.getComponent().getClassName());
-        assertEquals("testDummyTest",
-                intent.getStringExtra(TestBrowserController.BUNDLE_EXTRA_TEST_METHOD_NAME));
-    }
-
-    public void testGetIntentForRunAll() throws Exception {
-        TestSuite testSuite = new DummyTestSuite();
-        testSuite.addTestSuite(DummyTestCase.class);
-
-        mTestBrowserController.setTestSuite(testSuite);
-        Intent intent = mTestBrowserController.getIntentForTestAt(0);
-        verifyIntent(intent, DummyTestSuite.class, "com.android.testharness");
-    }
-
-    private static void verifyIntent(Intent intent, Class testClass, String expectedPackageName) {
-        assertEquals(Intent.ACTION_RUN, intent.getAction());
-        assertEquals(Intent.FLAG_ACTIVITY_NEW_TASK,
-                intent.getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK);
-        assertEquals(Intent.FLAG_ACTIVITY_MULTIPLE_TASK,
-                intent.getFlags() & Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
-        assertEquals(testClass.getName(), intent.getData().toString());
-        assertEquals(expectedPackageName, intent.getComponent().getPackageName());
-    }
-
-    private static class DummyTestSuite extends TestSuite {
-        private DummyTestSuite() {
-            super(DummyTestSuite.class.getName());
-        }
-    }
-
-    private static class DummyTestCase extends TestCase {
-        private DummyTestCase() {
-            super("testDummyTest");
-        }
-
-        public void testDummyTest() throws Exception {
-        }
-    }
-
-    private class TestBrowserViewStub implements TestBrowserView {
-        private List<String> mTestNames;
-
-        public void setTestNames(List<String> testNames) {
-            mTestNames = testNames;
-        }
-
-        public List<String> getTestNames() {
-            return mTestNames;
-        }
-    }
-}
diff --git a/test-runner/tests/src/android/test/TestBrowserTests.java b/test-runner/tests/src/android/test/TestBrowserTests.java
deleted file mode 100644
index 535e2f8..0000000
--- a/test-runner/tests/src/android/test/TestBrowserTests.java
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright 2007 The Android Open Source Project
-
-
-package android.test;
-
-import junit.framework.TestSuite;
-
-public class TestBrowserTests extends TestBrowserActivity {
-
-    @Override
-    public TestSuite getTopTestSuite() {
-        return suite();
-    }
-
-    public static TestSuite suite() {
-        TestSuite testSuite = new TestSuite(TestBrowserTests.class.getName());
-        testSuite.addTestSuite(TestBrowserControllerImplTest.class);
-        testSuite.addTestSuite(TestCaseUtilTest.class);
-
-        return testSuite;
-    }
-}
diff --git a/services/java/com/android/server/WifiStateTracker.java b/tests/BiDiTests/Android
similarity index 100%
rename from services/java/com/android/server/WifiStateTracker.java
rename to tests/BiDiTests/Android
diff --git a/tests/BiDiTests/AndroidManifest.xml b/tests/BiDiTests/AndroidManifest.xml
index 8a77519..4a687f2 100644
--- a/tests/BiDiTests/AndroidManifest.xml
+++ b/tests/BiDiTests/AndroidManifest.xml
@@ -19,7 +19,7 @@
     android:versionCode="1"
     android:versionName="1.0">
 
-    <application android:label="BiDiTests">
+    <application android:label="BiDiTests" android:hardwareAccelerated="true">
 
         <activity android:name=".BiDiTestActivity"
             android:windowSoftInputMode="stateAlwaysHidden">
@@ -29,34 +29,6 @@
             </intent-filter>
         </activity>
 
-        <activity android:name=".BiDiTestBasicActivity"
-                android:windowSoftInputMode="stateAlwaysHidden">
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-            </intent-filter>
-        </activity>
-
-        <activity android:name=".BiDiTestCanvasActivity"
-                  android:windowSoftInputMode="stateAlwaysHidden">
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-            </intent-filter>
-        </activity>
-
-        <activity android:name=".BiDiTestLinearLayoutLtrActivity"
-                  android:windowSoftInputMode="stateAlwaysHidden">
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-            </intent-filter>
-        </activity>
-
-        <activity android:name=".BiDiTestLinearLayoutRtlActivity"
-                  android:windowSoftInputMode="stateAlwaysHidden">
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-            </intent-filter>
-        </activity>
-
     </application>
 
-</manifest>
\ No newline at end of file
+</manifest>
diff --git a/tests/BiDiTests/res/layout/basic.xml b/tests/BiDiTests/res/layout/basic.xml
index c4807ff..d438b2c 100644
--- a/tests/BiDiTests/res/layout/basic.xml
+++ b/tests/BiDiTests/res/layout/basic.xml
@@ -14,37 +14,41 @@
      limitations under the License.
 -->
 
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:orientation="vertical"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent">
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+        android:id="@+id/basic"
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent">
 
-    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-        android:orientation="vertical"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content">
-
-       <Button android:id="@+id/button"
-               android:layout_height="wrap_content"
-               android:layout_width="wrap_content"
-               android:onClick="onButtonClick"
-               android:text="@string/button_text"
-               android:textSize="32dip"
-        />
-
-        <TextView android:id="@+id/textview"
-                  android:layout_height="wrap_content"
-                  android:layout_width="wrap_content"
-                  android:textSize="32dip"
-                  android:text="@string/textview_text"
-        />
-
-        <EditText android:id="@+id/edittext"
-                  android:layout_height="wrap_content"
+    <LinearLayout android:orientation="vertical"
                   android:layout_width="match_parent"
-                  android:textSize="32dip"
-        />
+                  android:layout_height="match_parent">
+
+        <LinearLayout android:orientation="vertical"
+                      android:layout_width="match_parent"
+                      android:layout_height="wrap_content">
+
+            <Button android:id="@+id/button"
+                    android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button_text"
+                    android:textSize="32dip"
+                    />
+
+            <TextView android:id="@+id/textview"
+                      android:layout_height="wrap_content"
+                      android:layout_width="wrap_content"
+                      android:textSize="32dip"
+                      android:text="@string/textview_text"
+                    />
+    
+            <EditText android:id="@+id/edittext"
+                      android:layout_height="wrap_content"
+                      android:layout_width="match_parent"
+                      android:textSize="32dip"
+                    />
+
+        </LinearLayout>
 
     </LinearLayout>
 
-</LinearLayout>
\ No newline at end of file
+</FrameLayout>
\ No newline at end of file
diff --git a/tests/BiDiTests/res/layout/canvas.xml b/tests/BiDiTests/res/layout/canvas.xml
index 77007af3..0319a83 100644
--- a/tests/BiDiTests/res/layout/canvas.xml
+++ b/tests/BiDiTests/res/layout/canvas.xml
@@ -14,21 +14,27 @@
      limitations under the License.
 -->
 
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:orientation="vertical"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent">
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+        android:id="@+id/canvas"
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent">
 
-    <SeekBar android:id="@+id/seekbar"
-               android:layout_height="wrap_content"
-               android:layout_width="match_parent"
-               />
+    <LinearLayout android:orientation="vertical"
+                  android:layout_width="match_parent"
+                  android:layout_height="match_parent">
 
-    <view class="com.android.bidi.BiDiTestView"
-        android:id="@+id/testview"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:background="#FF0000"
-    />
+        <SeekBar android:id="@+id/seekbar"
+                 android:layout_height="wrap_content"
+                 android:layout_width="match_parent"
+                />
 
-</LinearLayout>
+        <view class="com.android.bidi.BiDiTestView"
+              android:id="@+id/testview"
+              android:layout_width="match_parent"
+              android:layout_height="wrap_content"
+              android:background="#FF0000"
+                />
+
+    </LinearLayout>
+
+</FrameLayout>
\ No newline at end of file
diff --git a/tests/BiDiTests/res/layout/custom_list_item.xml b/tests/BiDiTests/res/layout/custom_list_item.xml
new file mode 100644
index 0000000..069424e
--- /dev/null
+++ b/tests/BiDiTests/res/layout/custom_list_item.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2006 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+  
+          http://www.apache.org/licenses/LICENSE-2.0
+  
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<TextView xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@android:id/text1"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:textAppearance="?android:attr/textAppearanceLarge"
+    android:gravity="center_vertical"
+    android:paddingLeft="6dip"
+    android:minHeight="?android:attr/listPreferredItemHeight"
+    android:background="?android:attr/activatedBackgroundIndicator"
+/>
diff --git a/tests/BiDiTests/res/layout/frame_layout_locale.xml b/tests/BiDiTests/res/layout/frame_layout_locale.xml
new file mode 100644
index 0000000..3382234
--- /dev/null
+++ b/tests/BiDiTests/res/layout/frame_layout_locale.xml
@@ -0,0 +1,92 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+        android:id="@+id/frame_layout_locale"
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent">
+
+    <FrameLayout android:layout_width="match_parent"
+                 android:layout_height="match_parent"
+                 android:layoutDirection="locale"
+                 android:background="#FF000000">
+
+        <FrameLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="right|center_vertical"
+                android:background="#FFFF0000">
+        </FrameLayout>
+
+        <FrameLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="left|center_vertical"
+                android:background="#FF00FF00">
+        </FrameLayout>
+
+        <FrameLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="top|center_horizontal"
+                android:background="#FF0000FF">
+        </FrameLayout>
+
+        <FrameLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="bottom|center_horizontal"
+                android:background="#FF00FFFF">
+        </FrameLayout>
+
+        <FrameLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="top|start"
+                android:background="#FFFFFFFF">
+        </FrameLayout>
+
+        <FrameLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="top|end"
+                android:background="#FFFFFF00">
+        </FrameLayout>
+
+        <FrameLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="bottom|start"
+                android:background="#FFFFFFFF">
+        </FrameLayout>
+
+        <FrameLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="bottom|end"
+                android:background="#FFFFFF00">
+        </FrameLayout>
+
+        <FrameLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="center_horizontal|center_vertical"
+                android:background="#FF888888">
+        </FrameLayout>
+
+    </FrameLayout>
+
+</FrameLayout>
diff --git a/tests/BiDiTests/res/layout/frame_layout_ltr.xml b/tests/BiDiTests/res/layout/frame_layout_ltr.xml
new file mode 100644
index 0000000..a8ae9144
--- /dev/null
+++ b/tests/BiDiTests/res/layout/frame_layout_ltr.xml
@@ -0,0 +1,92 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+        android:id="@+id/frame_layout_ltr"
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent">
+
+    <FrameLayout android:layout_width="match_parent"
+                 android:layout_height="match_parent"
+                 android:layoutDirection="ltr"
+                 android:background="#FF000000">
+
+        <FrameLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="right|center_vertical"
+                android:background="#FFFF0000">
+        </FrameLayout>
+
+        <FrameLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="left|center_vertical"
+                android:background="#FF00FF00">
+        </FrameLayout>
+
+        <FrameLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="top|center_horizontal"
+                android:background="#FF0000FF">
+        </FrameLayout>
+
+        <FrameLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="bottom|center_horizontal"
+                android:background="#FF00FFFF">
+        </FrameLayout>
+
+        <FrameLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="top|start"
+                android:background="#FFFFFFFF">
+        </FrameLayout>
+
+        <FrameLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="top|end"
+                android:background="#FFFFFF00">
+        </FrameLayout>
+
+        <FrameLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="bottom|start"
+                android:background="#FFFFFFFF">
+        </FrameLayout>
+
+        <FrameLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="bottom|end"
+                android:background="#FFFFFF00">
+        </FrameLayout>
+
+        <FrameLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="center_horizontal|center_vertical"
+                android:background="#FF888888">
+        </FrameLayout>
+
+    </FrameLayout>
+
+</FrameLayout>
diff --git a/tests/BiDiTests/res/layout/frame_layout_rtl.xml b/tests/BiDiTests/res/layout/frame_layout_rtl.xml
new file mode 100644
index 0000000..a84904c
--- /dev/null
+++ b/tests/BiDiTests/res/layout/frame_layout_rtl.xml
@@ -0,0 +1,92 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+        android:id="@+id/frame_layout_rtl"
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent">
+
+    <FrameLayout android:layout_width="match_parent"
+                 android:layout_height="match_parent"
+                 android:layoutDirection="rtl"
+                 android:background="#FF000000">
+
+        <FrameLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="right|center_vertical"
+                android:background="#FFFF0000">
+        </FrameLayout>
+
+        <FrameLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="left|center_vertical"
+                android:background="#FF00FF00">
+        </FrameLayout>
+
+        <FrameLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="top|center_horizontal"
+                android:background="#FF0000FF">
+        </FrameLayout>
+
+        <FrameLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="bottom|center_horizontal"
+                android:background="#FF00FFFF">
+        </FrameLayout>
+
+        <FrameLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="top|start"
+                android:background="#FFFFFFFF">
+        </FrameLayout>
+
+        <FrameLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="top|end"
+                android:background="#FFFFFF00">
+        </FrameLayout>
+
+        <FrameLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="bottom|start"
+                android:background="#FFFFFFFF">
+        </FrameLayout>
+
+        <FrameLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="bottom|end"
+                android:background="#FFFFFF00">
+        </FrameLayout>
+
+        <FrameLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="center_horizontal|center_vertical"
+                android:background="#FF888888">
+        </FrameLayout>
+
+    </FrameLayout>
+
+</FrameLayout>
diff --git a/tests/BiDiTests/res/layout/linear_layout_locale.xml b/tests/BiDiTests/res/layout/linear_layout_locale.xml
new file mode 100644
index 0000000..bddb458
--- /dev/null
+++ b/tests/BiDiTests/res/layout/linear_layout_locale.xml
@@ -0,0 +1,253 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+        android:id="@+id/linear_layout_locale"
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent">
+        
+    <LinearLayout android:orientation="vertical"
+                  android:layout_width="match_parent"
+                  android:layout_height="match_parent"
+                  android:layoutDirection="locale">
+    
+        <LinearLayout android:orientation="horizontal"
+                      android:layout_width="match_parent"
+                      android:layout_height="wrap_content">
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button1_text"
+                    android:textSize="24dip"
+                    />
+    
+            <TextView android:id="@+id/textview"
+                      android:layout_height="wrap_content"
+                      android:layout_width="wrap_content"
+                      android:textSize="24dip"
+                      android:text="@string/textview_text"
+                    />
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button2_text"
+                    android:textSize="24dip"
+                    />
+        </LinearLayout>
+    
+        <LinearLayout android:orientation="horizontal"
+                      android:layout_width="match_parent"
+                      android:layout_height="wrap_content"
+                      android:layoutDirection="inherit">
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button1_text"
+                    android:textSize="24dip"
+                    />
+    
+            <TextView android:id="@+id/textview"
+                      android:layout_height="wrap_content"
+                      android:layout_width="wrap_content"
+                      android:textSize="24dip"
+                      android:text="@string/textview_text"
+                    />
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button2_text"
+                    android:textSize="24dip"
+                    />
+        </LinearLayout>
+    
+        <LinearLayout android:orientation="horizontal"
+                      android:layout_width="match_parent"
+                      android:layout_height="wrap_content"
+                      android:layoutDirection="ltr">
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button1_text"
+                    android:textSize="24dip"
+                    />
+    
+            <TextView android:id="@+id/textview"
+                      android:layout_height="wrap_content"
+                      android:layout_width="wrap_content"
+                      android:textSize="24dip"
+                      android:text="@string/textview_text"
+                    />
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button2_text"
+                    android:textSize="24dip"
+                    />
+        </LinearLayout>
+    
+        <LinearLayout android:orientation="horizontal"
+                      android:layout_width="match_parent"
+                      android:layout_height="wrap_content"
+                      android:layoutDirection="rtl">
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button1_text"
+                    android:textSize="24dip"
+                    />
+    
+            <TextView android:id="@+id/textview"
+                      android:layout_height="wrap_content"
+                      android:layout_width="wrap_content"
+                      android:textSize="24dip"
+                      android:text="@string/textview_text"
+                    />
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button2_text"
+                    android:textSize="24dip"
+                    />
+        </LinearLayout>
+    
+        <LinearLayout android:orientation="horizontal"
+                      android:layout_width="match_parent"
+                      android:layout_height="wrap_content"
+                      android:layoutDirection="locale">
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button1_text"
+                    android:textSize="24dip"
+                    />
+    
+            <TextView android:id="@+id/textview"
+                      android:layout_height="wrap_content"
+                      android:layout_width="wrap_content"
+                      android:textSize="24dip"
+                      android:text="@string/textview_text"
+                    />
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button2_text"
+                    android:textSize="24dip"
+                    />
+        </LinearLayout>
+    
+        <LinearLayout android:orientation="vertical"
+                      android:layout_width="match_parent"
+                      android:layout_height="wrap_content"
+                      android:layoutDirection="inherit">
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button1_text"
+                    android:textSize="24dip"
+                    />
+    
+            <TextView android:id="@+id/textview"
+                      android:layout_height="wrap_content"
+                      android:layout_width="wrap_content"
+                      android:textSize="24dip"
+                      android:text="@string/textview_text"
+                    />
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button2_text"
+                    android:textSize="24dip"
+                    />
+        </LinearLayout>
+    
+        <LinearLayout android:orientation="vertical"
+                      android:layout_width="match_parent"
+                      android:layout_height="wrap_content"
+                      android:layoutDirection="ltr">
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button1_text"
+                    android:textSize="24dip"
+                    />
+    
+            <TextView android:id="@+id/textview"
+                      android:layout_height="wrap_content"
+                      android:layout_width="wrap_content"
+                      android:textSize="24dip"
+                      android:text="@string/textview_text"
+                    />
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button2_text"
+                    android:textSize="24dip"
+                    />
+        </LinearLayout>
+    
+        <LinearLayout android:orientation="vertical"
+                      android:layout_width="match_parent"
+                      android:layout_height="wrap_content"
+                      android:layoutDirection="rtl">
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button1_text"
+                    android:textSize="24dip"
+                    />
+    
+            <TextView android:id="@+id/textview"
+                      android:layout_height="wrap_content"
+                      android:layout_width="wrap_content"
+                      android:textSize="24dip"
+                      android:text="@string/textview_text"
+                    />
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button2_text"
+                    android:textSize="24dip"
+                    />
+        </LinearLayout>
+    
+        <LinearLayout android:orientation="vertical"
+                      android:layout_width="match_parent"
+                      android:layout_height="wrap_content"
+                      android:layoutDirection="locale">
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button1_text"
+                    android:textSize="24dip"
+                    />
+    
+            <TextView android:id="@+id/textview"
+                      android:layout_height="wrap_content"
+                      android:layout_width="wrap_content"
+                      android:textSize="24dip"
+                      android:text="@string/textview_text"
+                    />
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button2_text"
+                    android:textSize="24dip"
+                    />
+        </LinearLayout>
+    
+    </LinearLayout>
+
+</FrameLayout>
\ No newline at end of file
diff --git a/tests/BiDiTests/res/layout/linear_layout_ltr.xml b/tests/BiDiTests/res/layout/linear_layout_ltr.xml
index a95fb0e..060112d 100644
--- a/tests/BiDiTests/res/layout/linear_layout_ltr.xml
+++ b/tests/BiDiTests/res/layout/linear_layout_ltr.xml
@@ -14,173 +14,240 @@
      limitations under the License.
 -->
 
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:id="@+id/layouttest"
-    android:orientation="vertical"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent"
-    android:horizontalDirection="ltr">
-
-    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-        android:orientation="horizontal"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:horizontalDirection="inherit">
-
-       <Button android:layout_height="wrap_content"
-               android:layout_width="wrap_content"
-               android:text="@string/button1_text"
-               android:textSize="32dip"
-        />
-
-        <TextView android:id="@+id/textview"
-                  android:layout_height="wrap_content"
-                  android:layout_width="wrap_content"
-                  android:textSize="32dip"
-                  android:text="@string/textview_text"
-        />
-
-        <Button android:layout_height="wrap_content"
-                android:layout_width="wrap_content"
-                android:text="@string/button2_text"
-                android:textSize="32dip"
-         />
-
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+        android:id="@+id/linear_layout_ltr"
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent">
+        
+    <LinearLayout android:orientation="vertical"
+                  android:layout_width="match_parent"
+                  android:layout_height="match_parent"
+                  android:layoutDirection="ltr">
+    
+        <LinearLayout android:orientation="horizontal"
+                      android:layout_width="match_parent"
+                      android:layout_height="wrap_content">
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button1_text"
+                    android:textSize="24dip"
+                    />
+    
+            <TextView android:id="@+id/textview"
+                      android:layout_height="wrap_content"
+                      android:layout_width="wrap_content"
+                      android:textSize="24dip"
+                      android:text="@string/textview_text"
+                    />
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button2_text"
+                    android:textSize="24dip"
+                    />
+        </LinearLayout>
+    
+        <LinearLayout android:orientation="horizontal"
+                      android:layout_width="match_parent"
+                      android:layout_height="wrap_content"
+                      android:layoutDirection="inherit">
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button1_text"
+                    android:textSize="24dip"
+                    />
+    
+            <TextView android:id="@+id/textview"
+                      android:layout_height="wrap_content"
+                      android:layout_width="wrap_content"
+                      android:textSize="24dip"
+                      android:text="@string/textview_text"
+                    />
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button2_text"
+                    android:textSize="24dip"
+                    />
+        </LinearLayout>
+    
+        <LinearLayout android:orientation="horizontal"
+                      android:layout_width="match_parent"
+                      android:layout_height="wrap_content"
+                      android:layoutDirection="ltr">
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button1_text"
+                    android:textSize="24dip"
+                    />
+    
+            <TextView android:id="@+id/textview"
+                      android:layout_height="wrap_content"
+                      android:layout_width="wrap_content"
+                      android:textSize="24dip"
+                      android:text="@string/textview_text"
+                    />
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button2_text"
+                    android:textSize="24dip"
+                    />
+        </LinearLayout>
+    
+        <LinearLayout android:orientation="horizontal"
+                      android:layout_width="match_parent"
+                      android:layout_height="wrap_content"
+                      android:layoutDirection="rtl">
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button1_text"
+                    android:textSize="24dip"
+                    />
+    
+            <TextView android:id="@+id/textview"
+                      android:layout_height="wrap_content"
+                      android:layout_width="wrap_content"
+                      android:textSize="24dip"
+                      android:text="@string/textview_text"
+                    />
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button2_text"
+                    android:textSize="24dip"
+                    />
+        </LinearLayout>
+    
+        <LinearLayout android:orientation="horizontal"
+                      android:layout_width="match_parent"
+                      android:layout_height="wrap_content"
+                      android:layoutDirection="locale">
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button1_text"
+                    android:textSize="24dip"
+                    />
+    
+            <TextView android:id="@+id/textview"
+                      android:layout_height="wrap_content"
+                      android:layout_width="wrap_content"
+                      android:textSize="24dip"
+                      android:text="@string/textview_text"
+                    />
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button2_text"
+                    android:textSize="24dip"
+                    />
+        </LinearLayout>
+    
+        <LinearLayout android:orientation="vertical"
+                      android:layout_width="match_parent"
+                      android:layout_height="wrap_content"
+                      android:layoutDirection="inherit">
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button1_text"
+                    android:textSize="24dip"
+                    />
+    
+            <TextView android:id="@+id/textview"
+                      android:layout_height="wrap_content"
+                      android:layout_width="wrap_content"
+                      android:textSize="24dip"
+                      android:text="@string/textview_text"
+                    />
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button2_text"
+                    android:textSize="24dip"
+                    />
+        </LinearLayout>
+    
+        <LinearLayout android:orientation="vertical"
+                      android:layout_width="match_parent"
+                      android:layout_height="wrap_content"
+                      android:layoutDirection="ltr">
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button1_text"
+                    android:textSize="24dip"
+                    />
+    
+            <TextView android:id="@+id/textview"
+                      android:layout_height="wrap_content"
+                      android:layout_width="wrap_content"
+                      android:textSize="24dip"
+                      android:text="@string/textview_text"
+                    />
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button2_text"
+                    android:textSize="24dip"
+                    />
+        </LinearLayout>
+    
+        <LinearLayout android:orientation="vertical"
+                      android:layout_width="match_parent"
+                      android:layout_height="wrap_content"
+                      android:layoutDirection="rtl">
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button1_text"
+                    android:textSize="24dip"
+                    />
+    
+            <TextView android:id="@+id/textview"
+                      android:layout_height="wrap_content"
+                      android:layout_width="wrap_content"
+                      android:textSize="24dip"
+                      android:text="@string/textview_text"
+                    />
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button2_text"
+                    android:textSize="24dip"
+                    />
+        </LinearLayout>
+    
+        <LinearLayout android:orientation="vertical"
+                      android:layout_width="match_parent"
+                      android:layout_height="wrap_content"
+                      android:layoutDirection="locale">
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button1_text"
+                    android:textSize="24dip"
+                    />
+    
+            <TextView android:id="@+id/textview"
+                      android:layout_height="wrap_content"
+                      android:layout_width="wrap_content"
+                      android:textSize="24dip"
+                      android:text="@string/textview_text"
+                    />
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button2_text"
+                    android:textSize="24dip"
+                    />
+        </LinearLayout>
+    
     </LinearLayout>
 
-    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-        android:orientation="horizontal"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:horizontalDirection="ltr">
-
-       <Button android:layout_height="wrap_content"
-               android:layout_width="wrap_content"
-               android:text="@string/button1_text"
-               android:textSize="32dip"
-        />
-
-        <TextView android:id="@+id/textview"
-                  android:layout_height="wrap_content"
-                  android:layout_width="wrap_content"
-                  android:textSize="32dip"
-                  android:text="@string/textview_text"
-        />
-
-        <Button android:layout_height="wrap_content"
-                android:layout_width="wrap_content"
-                android:text="@string/button2_text"
-                android:textSize="32dip"
-         />
-
-    </LinearLayout>
-
-    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-        android:orientation="horizontal"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:horizontalDirection="rtl">
-
-       <Button android:layout_height="wrap_content"
-               android:layout_width="wrap_content"
-               android:text="@string/button1_text"
-               android:textSize="32dip"
-        />
-
-        <TextView android:id="@+id/textview"
-                  android:layout_height="wrap_content"
-                  android:layout_width="wrap_content"
-                  android:textSize="32dip"
-                  android:text="@string/textview_text"
-        />
-
-        <Button android:layout_height="wrap_content"
-                android:layout_width="wrap_content"
-                android:text="@string/button2_text"
-                android:textSize="32dip"
-         />
-
-    </LinearLayout>
-
-    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-        android:orientation="vertical"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:horizontalDirection="inherit">
-
-       <Button android:layout_height="wrap_content"
-               android:layout_width="wrap_content"
-               android:text="@string/button1_text"
-               android:textSize="32dip"
-        />
-
-        <TextView android:id="@+id/textview"
-                  android:layout_height="wrap_content"
-                  android:layout_width="wrap_content"
-                  android:textSize="32dip"
-                  android:text="@string/textview_text"
-        />
-
-        <Button android:layout_height="wrap_content"
-                android:layout_width="wrap_content"
-                android:text="@string/button2_text"
-                android:textSize="32dip"
-         />
-
-    </LinearLayout>
-
-    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-        android:orientation="vertical"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:horizontalDirection="ltr">
-
-       <Button android:layout_height="wrap_content"
-               android:layout_width="wrap_content"
-               android:text="@string/button1_text"
-               android:textSize="32dip"
-        />
-
-        <TextView android:id="@+id/textview"
-                  android:layout_height="wrap_content"
-                  android:layout_width="wrap_content"
-                  android:textSize="32dip"
-                  android:text="@string/textview_text"
-        />
-
-        <Button android:layout_height="wrap_content"
-                android:layout_width="wrap_content"
-                android:text="@string/button2_text"
-                android:textSize="32dip"
-         />
-
-    </LinearLayout>
-
-    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-        android:orientation="vertical"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:horizontalDirection="rtl">
-
-       <Button android:layout_height="wrap_content"
-               android:layout_width="wrap_content"
-               android:text="@string/button1_text"
-               android:textSize="32dip"
-        />
-
-        <TextView android:id="@+id/textview"
-                  android:layout_height="wrap_content"
-                  android:layout_width="wrap_content"
-                  android:textSize="32dip"
-                  android:text="@string/textview_text"
-        />
-
-        <Button android:layout_height="wrap_content"
-                android:layout_width="wrap_content"
-                android:text="@string/button2_text"
-                android:textSize="32dip"
-         />
-
-    </LinearLayout>
-
-</LinearLayout>
\ No newline at end of file
+</FrameLayout>
\ No newline at end of file
diff --git a/tests/BiDiTests/res/layout/linear_layout_rtl.xml b/tests/BiDiTests/res/layout/linear_layout_rtl.xml
index 0d60950..53ecbcc 100644
--- a/tests/BiDiTests/res/layout/linear_layout_rtl.xml
+++ b/tests/BiDiTests/res/layout/linear_layout_rtl.xml
@@ -14,173 +14,240 @@
      limitations under the License.
 -->
 
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:id="@+id/layouttest"
-    android:orientation="vertical"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent"
-    android:horizontalDirection="rtl">
-
-    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-        android:orientation="horizontal"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:horizontalDirection="inherit">
-
-       <Button android:layout_height="wrap_content"
-               android:layout_width="wrap_content"
-               android:text="@string/button1_text"
-               android:textSize="32dip"
-        />
-
-        <TextView android:id="@+id/textview"
-                  android:layout_height="wrap_content"
-                  android:layout_width="wrap_content"
-                  android:textSize="32dip"
-                  android:text="@string/textview_text"
-        />
-
-        <Button android:layout_height="wrap_content"
-                android:layout_width="wrap_content"
-                android:text="@string/button2_text"
-                android:textSize="32dip"
-         />
-
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+        android:id="@+id/linear_layout_rtl"
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent">
+        
+    <LinearLayout android:orientation="vertical"
+                  android:layout_width="match_parent"
+                  android:layout_height="match_parent"
+                  android:layoutDirection="rtl">
+    
+        <LinearLayout android:orientation="horizontal"
+                      android:layout_width="match_parent"
+                      android:layout_height="wrap_content">
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button1_text"
+                    android:textSize="24dip"
+                    />
+    
+            <TextView android:id="@+id/textview"
+                      android:layout_height="wrap_content"
+                      android:layout_width="wrap_content"
+                      android:textSize="24dip"
+                      android:text="@string/textview_text"
+                    />
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button2_text"
+                    android:textSize="24dip"
+                    />
+        </LinearLayout>
+    
+        <LinearLayout android:orientation="horizontal"
+                      android:layout_width="match_parent"
+                      android:layout_height="wrap_content"
+                      android:layoutDirection="inherit">
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button1_text"
+                    android:textSize="24dip"
+                    />
+    
+            <TextView android:id="@+id/textview"
+                      android:layout_height="wrap_content"
+                      android:layout_width="wrap_content"
+                      android:textSize="24dip"
+                      android:text="@string/textview_text"
+                    />
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button2_text"
+                    android:textSize="24dip"
+                    />
+        </LinearLayout>
+    
+        <LinearLayout android:orientation="horizontal"
+                      android:layout_width="match_parent"
+                      android:layout_height="wrap_content"
+                      android:layoutDirection="ltr">
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button1_text"
+                    android:textSize="24dip"
+                    />
+    
+            <TextView android:id="@+id/textview"
+                      android:layout_height="wrap_content"
+                      android:layout_width="wrap_content"
+                      android:textSize="24dip"
+                      android:text="@string/textview_text"
+                    />
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button2_text"
+                    android:textSize="24dip"
+                    />
+        </LinearLayout>
+    
+        <LinearLayout android:orientation="horizontal"
+                      android:layout_width="match_parent"
+                      android:layout_height="wrap_content"
+                      android:layoutDirection="rtl">
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button1_text"
+                    android:textSize="24dip"
+                    />
+    
+            <TextView android:id="@+id/textview"
+                      android:layout_height="wrap_content"
+                      android:layout_width="wrap_content"
+                      android:textSize="24dip"
+                      android:text="@string/textview_text"
+                    />
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button2_text"
+                    android:textSize="24dip"
+                    />
+        </LinearLayout>
+    
+        <LinearLayout android:orientation="horizontal"
+                      android:layout_width="match_parent"
+                      android:layout_height="wrap_content"
+                      android:layoutDirection="locale">
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button1_text"
+                    android:textSize="24dip"
+                    />
+    
+            <TextView android:id="@+id/textview"
+                      android:layout_height="wrap_content"
+                      android:layout_width="wrap_content"
+                      android:textSize="24dip"
+                      android:text="@string/textview_text"
+                    />
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button2_text"
+                    android:textSize="24dip"
+                    />
+        </LinearLayout>
+    
+        <LinearLayout android:orientation="vertical"
+                      android:layout_width="match_parent"
+                      android:layout_height="wrap_content"
+                      android:layoutDirection="inherit">
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button1_text"
+                    android:textSize="24dip"
+                    />
+    
+            <TextView android:id="@+id/textview"
+                      android:layout_height="wrap_content"
+                      android:layout_width="wrap_content"
+                      android:textSize="24dip"
+                      android:text="@string/textview_text"
+                    />
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button2_text"
+                    android:textSize="24dip"
+                    />
+        </LinearLayout>
+    
+        <LinearLayout android:orientation="vertical"
+                      android:layout_width="match_parent"
+                      android:layout_height="wrap_content"
+                      android:layoutDirection="ltr">
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button1_text"
+                    android:textSize="24dip"
+                    />
+    
+            <TextView android:id="@+id/textview"
+                      android:layout_height="wrap_content"
+                      android:layout_width="wrap_content"
+                      android:textSize="24dip"
+                      android:text="@string/textview_text"
+                    />
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button2_text"
+                    android:textSize="24dip"
+                    />
+        </LinearLayout>
+    
+        <LinearLayout android:orientation="vertical"
+                      android:layout_width="match_parent"
+                      android:layout_height="wrap_content"
+                      android:layoutDirection="rtl">
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button1_text"
+                    android:textSize="24dip"
+                    />
+    
+            <TextView android:id="@+id/textview"
+                      android:layout_height="wrap_content"
+                      android:layout_width="wrap_content"
+                      android:textSize="24dip"
+                      android:text="@string/textview_text"
+                    />
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button2_text"
+                    android:textSize="24dip"
+                    />
+        </LinearLayout>
+    
+        <LinearLayout android:orientation="vertical"
+                      android:layout_width="match_parent"
+                      android:layout_height="wrap_content"
+                      android:layoutDirection="locale">
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button1_text"
+                    android:textSize="24dip"
+                    />
+    
+            <TextView android:id="@+id/textview"
+                      android:layout_height="wrap_content"
+                      android:layout_width="wrap_content"
+                      android:textSize="24dip"
+                      android:text="@string/textview_text"
+                    />
+    
+            <Button android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/button2_text"
+                    android:textSize="24dip"
+                    />
+        </LinearLayout>
+    
     </LinearLayout>
 
-    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-        android:orientation="horizontal"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:horizontalDirection="ltr">
-
-       <Button android:layout_height="wrap_content"
-               android:layout_width="wrap_content"
-               android:text="@string/button1_text"
-               android:textSize="32dip"
-        />
-
-        <TextView android:id="@+id/textview"
-                  android:layout_height="wrap_content"
-                  android:layout_width="wrap_content"
-                  android:textSize="32dip"
-                  android:text="@string/textview_text"
-        />
-
-        <Button android:layout_height="wrap_content"
-                android:layout_width="wrap_content"
-                android:text="@string/button2_text"
-                android:textSize="32dip"
-         />
-
-    </LinearLayout>
-
-    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-        android:orientation="horizontal"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:horizontalDirection="rtl">
-
-       <Button android:layout_height="wrap_content"
-               android:layout_width="wrap_content"
-               android:text="@string/button1_text"
-               android:textSize="32dip"
-        />
-
-        <TextView android:id="@+id/textview"
-                  android:layout_height="wrap_content"
-                  android:layout_width="wrap_content"
-                  android:textSize="32dip"
-                  android:text="@string/textview_text"
-        />
-
-        <Button android:layout_height="wrap_content"
-                android:layout_width="wrap_content"
-                android:text="@string/button2_text"
-                android:textSize="32dip"
-         />
-
-    </LinearLayout>
-
-    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-        android:orientation="vertical"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:horizontalDirection="inherit">
-
-       <Button android:layout_height="wrap_content"
-               android:layout_width="wrap_content"
-               android:text="@string/button1_text"
-               android:textSize="32dip"
-        />
-
-        <TextView android:id="@+id/textview"
-                  android:layout_height="wrap_content"
-                  android:layout_width="wrap_content"
-                  android:textSize="32dip"
-                  android:text="@string/textview_text"
-        />
-
-        <Button android:layout_height="wrap_content"
-                android:layout_width="wrap_content"
-                android:text="@string/button2_text"
-                android:textSize="32dip"
-         />
-
-    </LinearLayout>
-
-    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-        android:orientation="vertical"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:horizontalDirection="ltr">
-
-       <Button android:layout_height="wrap_content"
-               android:layout_width="wrap_content"
-               android:text="@string/button1_text"
-               android:textSize="32dip"
-        />
-
-        <TextView android:id="@+id/textview"
-                  android:layout_height="wrap_content"
-                  android:layout_width="wrap_content"
-                  android:textSize="32dip"
-                  android:text="@string/textview_text"
-        />
-
-        <Button android:layout_height="wrap_content"
-                android:layout_width="wrap_content"
-                android:text="@string/button2_text"
-                android:textSize="32dip"
-         />
-
-    </LinearLayout>
-
-    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-        android:orientation="vertical"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:horizontalDirection="rtl">
-
-       <Button android:layout_height="wrap_content"
-               android:layout_width="wrap_content"
-               android:text="@string/button1_text"
-               android:textSize="32dip"
-        />
-
-        <TextView android:id="@+id/textview"
-                  android:layout_height="wrap_content"
-                  android:layout_width="wrap_content"
-                  android:textSize="32dip"
-                  android:text="@string/textview_text"
-        />
-
-        <Button android:layout_height="wrap_content"
-                android:layout_width="wrap_content"
-                android:text="@string/button2_text"
-                android:textSize="32dip"
-         />
-
-    </LinearLayout>
-
-</LinearLayout>
\ No newline at end of file
+</FrameLayout>
\ No newline at end of file
diff --git a/tests/BiDiTests/res/layout/main.xml b/tests/BiDiTests/res/layout/main.xml
index e39d1d6..3543eb7 100644
--- a/tests/BiDiTests/res/layout/main.xml
+++ b/tests/BiDiTests/res/layout/main.xml
@@ -14,28 +14,20 @@
      limitations under the License.
 -->
 
-<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
-    android:id="@android:id/tabhost"
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:orientation="horizontal"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent">
 
-    <LinearLayout
-        android:orientation="vertical"
-        android:layout_width="fill_parent"
+    <ListView android:id="@+id/testlist"
+        android:layout_width="0px" 
         android:layout_height="fill_parent"
-        android:padding="5dp">
+        android:layout_weight="1"/>
 
-        <TabWidget
-            android:id="@android:id/tabs"
-            android:layout_width="fill_parent"
-            android:layout_height="wrap_content" />
+    <FrameLayout android:id="@+id/testframe"
+        android:layout_width="0px" 
+        android:layout_height="fill_parent"
+        android:layout_weight="6">
+    </FrameLayout>
 
-        <FrameLayout
-            android:id="@android:id/tabcontent"
-            android:layout_width="fill_parent"
-            android:layout_height="fill_parent"
-            android:padding="5dp" />
-
-    </LinearLayout>
-
-</TabHost>
+</LinearLayout>
diff --git a/tests/BiDiTests/res/layout/relative_layout_2_locale.xml b/tests/BiDiTests/res/layout/relative_layout_2_locale.xml
new file mode 100644
index 0000000..ff5bf7b
--- /dev/null
+++ b/tests/BiDiTests/res/layout/relative_layout_2_locale.xml
@@ -0,0 +1,183 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+        android:id="@+id/relative_layout_2_locale"
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent">
+
+    <LinearLayout android:orientation="vertical"
+                  android:layout_width="match_parent"
+                  android:layout_height="match_parent"
+                  android:layoutDirection="locale">
+
+        <RelativeLayout android:layout_width="fill_parent"
+                        android:layout_height="wrap_content"
+                        android:background="#FF000000"
+                        android:padding="10px">
+
+            <TextView android:id="@+id/label_1"
+                      android:layout_width="fill_parent"
+                      android:layout_height="wrap_content"
+                      android:text="Type here:"/>
+
+            <EditText android:id="@+id/entry_1"
+                      android:layout_width="fill_parent"
+                      android:layout_height="wrap_content"
+                      android:layout_below="@id/label_1"/>
+
+            <Button android:id="@+id/ok_1"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_below="@id/entry_1"
+                    android:layout_alignParentRight="true"
+                    android:layout_marginLeft="10px"
+                    android:text="OK"/>
+
+            <Button android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_toLeftOf="@id/ok_1"
+                    android:layout_alignTop="@id/ok_1"
+                    android:text="Cancel"/>
+        </RelativeLayout>
+
+        <RelativeLayout android:layout_width="fill_parent"
+                        android:layout_height="wrap_content"
+                        android:background="#FF000000"
+                        android:padding="10px"
+                        android:layoutDirection="ltr">
+
+            <TextView android:id="@+id/label_2"
+                      android:layout_width="fill_parent"
+                      android:layout_height="wrap_content"
+                      android:text="Type here:"/>
+
+            <EditText android:id="@+id/entry_2"
+                      android:layout_width="fill_parent"
+                      android:layout_height="wrap_content"
+                      android:layout_below="@id/label_2"/>
+
+            <Button android:id="@+id/ok_2"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_below="@id/entry_2"
+                    android:layout_alignParentRight="true"
+                    android:layout_marginLeft="10px"
+                    android:text="OK"/>
+
+            <Button android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_toLeftOf="@id/ok_2"
+                    android:layout_alignTop="@id/ok_2"
+                    android:text="Cancel"/>
+        </RelativeLayout>
+
+        <RelativeLayout android:layout_width="fill_parent"
+                        android:layout_height="wrap_content"
+                        android:background="#FF000000"
+                        android:padding="10px"
+                        android:layoutDirection="inherit">
+    
+            <TextView android:id="@+id/label_3"
+                      android:layout_width="fill_parent"
+                      android:layout_height="wrap_content"
+                      android:text="Type here:"/>
+    
+            <EditText android:id="@+id/entry_3"
+                      android:layout_width="fill_parent"
+                      android:layout_height="wrap_content"
+                      android:layout_below="@id/label_3"/>
+    
+            <Button android:id="@+id/ok_3"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_below="@id/entry_3"
+                    android:layout_alignParentRight="true"
+                    android:layout_marginLeft="10px"
+                    android:text="OK"/>
+    
+            <Button android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_toLeftOf="@id/ok_3"
+                    android:layout_alignTop="@id/ok_3"
+                    android:text="Cancel"/>
+        </RelativeLayout>
+
+        <RelativeLayout android:layout_width="fill_parent"
+                        android:layout_height="wrap_content"
+                        android:background="#FF000000"
+                        android:padding="10px"
+                        android:layoutDirection="rtl">
+
+            <TextView android:id="@+id/label_4"
+                      android:layout_width="fill_parent"
+                      android:layout_height="wrap_content"
+                      android:text="Type here:"/>
+
+            <EditText android:id="@+id/entry_4"
+                      android:layout_width="fill_parent"
+                      android:layout_height="wrap_content"
+                      android:layout_below="@id/label_4"/>
+
+            <Button android:id="@+id/ok_4"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_below="@id/entry_4"
+                    android:layout_alignParentRight="true"
+                    android:layout_marginLeft="10px"
+                    android:text="OK"/>
+
+            <Button android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_toLeftOf="@id/ok_4"
+                    android:layout_alignTop="@id/ok_4"
+                    android:text="Cancel"/>
+        </RelativeLayout>
+
+        <RelativeLayout android:layout_width="fill_parent"
+                        android:layout_height="wrap_content"
+                        android:background="#FF000000"
+                        android:padding="10px"
+                        android:layoutDirection="locale">
+    
+            <TextView android:id="@+id/label_4"
+                      android:layout_width="fill_parent"
+                      android:layout_height="wrap_content"
+                      android:text="Type here:"/>
+    
+            <EditText android:id="@+id/entry_4"
+                      android:layout_width="fill_parent"
+                      android:layout_height="wrap_content"
+                      android:layout_below="@id/label_4"/>
+
+            <Button android:id="@+id/ok_4"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_below="@id/entry_4"
+                    android:layout_alignParentRight="true"
+                    android:layout_marginLeft="10px"
+                    android:text="OK"/>
+    
+            <Button android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_toLeftOf="@id/ok_4"
+                    android:layout_alignTop="@id/ok_4"
+                    android:text="Cancel"/>
+        </RelativeLayout>
+
+    </LinearLayout>
+
+</FrameLayout>
\ No newline at end of file
diff --git a/tests/BiDiTests/res/layout/relative_layout_2_ltr.xml b/tests/BiDiTests/res/layout/relative_layout_2_ltr.xml
new file mode 100644
index 0000000..cf585b5
--- /dev/null
+++ b/tests/BiDiTests/res/layout/relative_layout_2_ltr.xml
@@ -0,0 +1,183 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+        android:id="@+id/relative_layout_2_ltr"
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent">
+
+    <LinearLayout android:orientation="vertical"
+                  android:layout_width="match_parent"
+                  android:layout_height="match_parent"
+                  android:layoutDirection="ltr">
+
+        <RelativeLayout android:layout_width="fill_parent"
+                        android:layout_height="wrap_content"
+                        android:background="#FF000000"
+                        android:padding="10px">
+
+            <TextView android:id="@+id/label_1"
+                      android:layout_width="fill_parent"
+                      android:layout_height="wrap_content"
+                      android:text="Type here:"/>
+
+            <EditText android:id="@+id/entry_1"
+                      android:layout_width="fill_parent"
+                      android:layout_height="wrap_content"
+                      android:layout_below="@id/label_1"/>
+
+            <Button android:id="@+id/ok_1"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_below="@id/entry_1"
+                    android:layout_alignParentRight="true"
+                    android:layout_marginLeft="10px"
+                    android:text="OK"/>
+
+            <Button android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_toLeftOf="@id/ok_1"
+                    android:layout_alignTop="@id/ok_1"
+                    android:text="Cancel"/>
+        </RelativeLayout>
+
+        <RelativeLayout android:layout_width="fill_parent"
+                        android:layout_height="wrap_content"
+                        android:background="#FF000000"
+                        android:padding="10px"
+                        android:layoutDirection="ltr">
+
+            <TextView android:id="@+id/label_2"
+                      android:layout_width="fill_parent"
+                      android:layout_height="wrap_content"
+                      android:text="Type here:"/>
+
+            <EditText android:id="@+id/entry_2"
+                      android:layout_width="fill_parent"
+                      android:layout_height="wrap_content"
+                      android:layout_below="@id/label_2"/>
+
+            <Button android:id="@+id/ok_2"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_below="@id/entry_2"
+                    android:layout_alignParentRight="true"
+                    android:layout_marginLeft="10px"
+                    android:text="OK"/>
+
+            <Button android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_toLeftOf="@id/ok_2"
+                    android:layout_alignTop="@id/ok_2"
+                    android:text="Cancel"/>
+        </RelativeLayout>
+
+        <RelativeLayout android:layout_width="fill_parent"
+                        android:layout_height="wrap_content"
+                        android:background="#FF000000"
+                        android:padding="10px"
+                        android:layoutDirection="inherit">
+    
+            <TextView android:id="@+id/label_3"
+                      android:layout_width="fill_parent"
+                      android:layout_height="wrap_content"
+                      android:text="Type here:"/>
+    
+            <EditText android:id="@+id/entry_3"
+                      android:layout_width="fill_parent"
+                      android:layout_height="wrap_content"
+                      android:layout_below="@id/label_3"/>
+    
+            <Button android:id="@+id/ok_3"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_below="@id/entry_3"
+                    android:layout_alignParentRight="true"
+                    android:layout_marginLeft="10px"
+                    android:text="OK"/>
+    
+            <Button android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_toLeftOf="@id/ok_3"
+                    android:layout_alignTop="@id/ok_3"
+                    android:text="Cancel"/>
+        </RelativeLayout>
+
+        <RelativeLayout android:layout_width="fill_parent"
+                        android:layout_height="wrap_content"
+                        android:background="#FF000000"
+                        android:padding="10px"
+                        android:layoutDirection="rtl">
+
+            <TextView android:id="@+id/label_4"
+                      android:layout_width="fill_parent"
+                      android:layout_height="wrap_content"
+                      android:text="Type here:"/>
+
+            <EditText android:id="@+id/entry_4"
+                      android:layout_width="fill_parent"
+                      android:layout_height="wrap_content"
+                      android:layout_below="@id/label_4"/>
+
+            <Button android:id="@+id/ok_4"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_below="@id/entry_4"
+                    android:layout_alignParentRight="true"
+                    android:layout_marginLeft="10px"
+                    android:text="OK"/>
+
+            <Button android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_toLeftOf="@id/ok_4"
+                    android:layout_alignTop="@id/ok_4"
+                    android:text="Cancel"/>
+        </RelativeLayout>
+
+        <RelativeLayout android:layout_width="fill_parent"
+                        android:layout_height="wrap_content"
+                        android:background="#FF000000"
+                        android:padding="10px"
+                        android:layoutDirection="locale">
+    
+            <TextView android:id="@+id/label_4"
+                      android:layout_width="fill_parent"
+                      android:layout_height="wrap_content"
+                      android:text="Type here:"/>
+    
+            <EditText android:id="@+id/entry_4"
+                      android:layout_width="fill_parent"
+                      android:layout_height="wrap_content"
+                      android:layout_below="@id/label_4"/>
+
+            <Button android:id="@+id/ok_4"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_below="@id/entry_4"
+                    android:layout_alignParentRight="true"
+                    android:layout_marginLeft="10px"
+                    android:text="OK"/>
+    
+            <Button android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_toLeftOf="@id/ok_4"
+                    android:layout_alignTop="@id/ok_4"
+                    android:text="Cancel"/>
+        </RelativeLayout>
+
+    </LinearLayout>
+
+</FrameLayout>
\ No newline at end of file
diff --git a/tests/BiDiTests/res/layout/relative_layout_2_rtl.xml b/tests/BiDiTests/res/layout/relative_layout_2_rtl.xml
new file mode 100644
index 0000000..729f1ca
--- /dev/null
+++ b/tests/BiDiTests/res/layout/relative_layout_2_rtl.xml
@@ -0,0 +1,183 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+        android:id="@+id/relative_layout_2_rtl"
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent">
+
+    <LinearLayout android:orientation="vertical"
+                  android:layout_width="match_parent"
+                  android:layout_height="match_parent"
+                  android:layoutDirection="rtl">
+
+        <RelativeLayout android:layout_width="fill_parent"
+                        android:layout_height="wrap_content"
+                        android:background="#FF000000"
+                        android:padding="10px">
+
+            <TextView android:id="@+id/label_1"
+                      android:layout_width="fill_parent"
+                      android:layout_height="wrap_content"
+                      android:text="Type here:"/>
+
+            <EditText android:id="@+id/entry_1"
+                      android:layout_width="fill_parent"
+                      android:layout_height="wrap_content"
+                      android:layout_below="@id/label_1"/>
+
+            <Button android:id="@+id/ok_1"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_below="@id/entry_1"
+                    android:layout_alignParentRight="true"
+                    android:layout_marginLeft="10px"
+                    android:text="OK"/>
+
+            <Button android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_toLeftOf="@id/ok_1"
+                    android:layout_alignTop="@id/ok_1"
+                    android:text="Cancel"/>
+        </RelativeLayout>
+
+        <RelativeLayout android:layout_width="fill_parent"
+                        android:layout_height="wrap_content"
+                        android:background="#FF000000"
+                        android:padding="10px"
+                        android:layoutDirection="ltr">
+
+            <TextView android:id="@+id/label_2"
+                      android:layout_width="fill_parent"
+                      android:layout_height="wrap_content"
+                      android:text="Type here:"/>
+
+            <EditText android:id="@+id/entry_2"
+                      android:layout_width="fill_parent"
+                      android:layout_height="wrap_content"
+                      android:layout_below="@id/label_2"/>
+
+            <Button android:id="@+id/ok_2"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_below="@id/entry_2"
+                    android:layout_alignParentRight="true"
+                    android:layout_marginLeft="10px"
+                    android:text="OK"/>
+
+            <Button android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_toLeftOf="@id/ok_2"
+                    android:layout_alignTop="@id/ok_2"
+                    android:text="Cancel"/>
+        </RelativeLayout>
+
+        <RelativeLayout android:layout_width="fill_parent"
+                        android:layout_height="wrap_content"
+                        android:background="#FF000000"
+                        android:padding="10px"
+                        android:layoutDirection="inherit">
+    
+            <TextView android:id="@+id/label_3"
+                      android:layout_width="fill_parent"
+                      android:layout_height="wrap_content"
+                      android:text="Type here:"/>
+    
+            <EditText android:id="@+id/entry_3"
+                      android:layout_width="fill_parent"
+                      android:layout_height="wrap_content"
+                      android:layout_below="@id/label_3"/>
+    
+            <Button android:id="@+id/ok_3"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_below="@id/entry_3"
+                    android:layout_alignParentRight="true"
+                    android:layout_marginLeft="10px"
+                    android:text="OK"/>
+    
+            <Button android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_toLeftOf="@id/ok_3"
+                    android:layout_alignTop="@id/ok_3"
+                    android:text="Cancel"/>
+        </RelativeLayout>
+
+        <RelativeLayout android:layout_width="fill_parent"
+                        android:layout_height="wrap_content"
+                        android:background="#FF000000"
+                        android:padding="10px"
+                        android:layoutDirection="rtl">
+
+            <TextView android:id="@+id/label_4"
+                      android:layout_width="fill_parent"
+                      android:layout_height="wrap_content"
+                      android:text="Type here:"/>
+
+            <EditText android:id="@+id/entry_4"
+                      android:layout_width="fill_parent"
+                      android:layout_height="wrap_content"
+                      android:layout_below="@id/label_4"/>
+
+            <Button android:id="@+id/ok_4"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_below="@id/entry_4"
+                    android:layout_alignParentRight="true"
+                    android:layout_marginLeft="10px"
+                    android:text="OK"/>
+
+            <Button android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_toLeftOf="@id/ok_4"
+                    android:layout_alignTop="@id/ok_4"
+                    android:text="Cancel"/>
+        </RelativeLayout>
+
+        <RelativeLayout android:layout_width="fill_parent"
+                        android:layout_height="wrap_content"
+                        android:background="#FF000000"
+                        android:padding="10px"
+                        android:layoutDirection="locale">
+    
+            <TextView android:id="@+id/label_4"
+                      android:layout_width="fill_parent"
+                      android:layout_height="wrap_content"
+                      android:text="Type here:"/>
+    
+            <EditText android:id="@+id/entry_4"
+                      android:layout_width="fill_parent"
+                      android:layout_height="wrap_content"
+                      android:layout_below="@id/label_4"/>
+
+            <Button android:id="@+id/ok_4"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_below="@id/entry_4"
+                    android:layout_alignParentRight="true"
+                    android:layout_marginLeft="10px"
+                    android:text="OK"/>
+    
+            <Button android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_toLeftOf="@id/ok_4"
+                    android:layout_alignTop="@id/ok_4"
+                    android:text="Cancel"/>
+        </RelativeLayout>
+
+    </LinearLayout>
+
+</FrameLayout>
\ No newline at end of file
diff --git a/tests/BiDiTests/res/layout/relative_layout_ltr.xml b/tests/BiDiTests/res/layout/relative_layout_ltr.xml
new file mode 100644
index 0000000..461ec98
--- /dev/null
+++ b/tests/BiDiTests/res/layout/relative_layout_ltr.xml
@@ -0,0 +1,92 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+        android:id="@+id/relative_layout_ltr"
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent">
+
+    <FrameLayout android:layout_width="match_parent"
+                 android:layout_height="match_parent"
+                 android:layoutDirection="ltr"
+                 android:background="#FF000000">
+
+        <RelativeLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="right|center_vertical"
+                android:background="#FFFF0000">
+        </RelativeLayout>
+
+        <RelativeLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="left|center_vertical"
+                android:background="#FF00FF00">
+        </RelativeLayout>
+
+        <RelativeLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="top|center_horizontal"
+                android:background="#FF0000FF">
+        </RelativeLayout>
+
+        <RelativeLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="bottom|center_horizontal"
+                android:background="#FF00FFFF">
+        </RelativeLayout>
+
+        <RelativeLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="top|start"
+                android:background="#FFFFFFFF">
+        </RelativeLayout>
+
+        <RelativeLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="top|end"
+                android:background="#FFFFFF00">
+        </RelativeLayout>
+
+        <RelativeLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="bottom|start"
+                android:background="#FFFFFFFF">
+        </RelativeLayout>
+
+        <RelativeLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="bottom|end"
+                android:background="#FFFFFF00">
+        </RelativeLayout>
+
+        <RelativeLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="center_horizontal|center_vertical"
+                android:background="#FF888888">
+        </RelativeLayout>
+    
+    </FrameLayout>
+
+</FrameLayout>
\ No newline at end of file
diff --git a/tests/BiDiTests/res/layout/relative_layout_rtl.xml b/tests/BiDiTests/res/layout/relative_layout_rtl.xml
new file mode 100644
index 0000000..545d16e
--- /dev/null
+++ b/tests/BiDiTests/res/layout/relative_layout_rtl.xml
@@ -0,0 +1,92 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+        android:id="@+id/relative_layout_rtl"
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent">
+
+    <FrameLayout android:layout_width="match_parent"
+                 android:layout_height="match_parent"
+                 android:layoutDirection="rtl"
+                 android:background="#FF000000">
+
+        <RelativeLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="right|center_vertical"
+                android:background="#FFFF0000">
+        </RelativeLayout>
+
+        <RelativeLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="left|center_vertical"
+                android:background="#FF00FF00">
+        </RelativeLayout>
+
+        <RelativeLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="top|center_horizontal"
+                android:background="#FF0000FF">
+        </RelativeLayout>
+
+        <RelativeLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="bottom|center_horizontal"
+                android:background="#FF00FFFF">
+        </RelativeLayout>
+
+        <RelativeLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="top|start"
+                android:background="#FFFFFFFF">
+        </RelativeLayout>
+
+        <RelativeLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="top|end"
+                android:background="#FFFFFF00">
+        </RelativeLayout>
+
+        <RelativeLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="bottom|start"
+                android:background="#FFFFFFFF">
+        </RelativeLayout>
+
+        <RelativeLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="bottom|end"
+                android:background="#FFFFFF00">
+        </RelativeLayout>
+
+        <RelativeLayout
+                android:layout_width="100dp"
+                android:layout_height="100dp"
+                android:layout_gravity="center_horizontal|center_vertical"
+                android:background="#FF888888">
+        </RelativeLayout>
+    
+    </FrameLayout>
+
+</FrameLayout>
\ No newline at end of file
diff --git a/tests/BiDiTests/res/layout/table_layout_locale.xml b/tests/BiDiTests/res/layout/table_layout_locale.xml
new file mode 100644
index 0000000..bd2ad23
--- /dev/null
+++ b/tests/BiDiTests/res/layout/table_layout_locale.xml
@@ -0,0 +1,258 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+        android:id="@+id/table_layout_locale"
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent">
+
+    <LinearLayout android:orientation="vertical"
+                  android:layout_width="match_parent"
+                  android:layout_height="match_parent"
+                  android:layoutDirection="locale">
+
+        <TableLayout android:layout_width="wrap_content"
+                     android:layout_height="wrap_content"
+                     android:stretchColumns="1,2">
+
+            <TableRow>
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button1_text"
+                        android:textSize="24dip"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_right_text"
+                        android:textSize="24dip"
+                        android:gravity="right"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_after_text"
+                        android:textSize="24dip"
+                        android:gravity="end"
+                        />
+            </TableRow>
+
+            <TableRow>
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button2_text"
+                        android:textSize="24dip"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_left_text"
+                        android:textSize="24dip"
+                        android:gravity="left"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_before_text"
+                        android:textSize="24dip"
+                        android:gravity="start"
+                        />
+            </TableRow>
+        </TableLayout>
+
+        <TableLayout android:layout_width="wrap_content"
+                     android:layout_height="wrap_content"
+                     android:stretchColumns="1,2"
+                     android:layoutDirection="inherit">
+
+            <TableRow>
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button1_text"
+                        android:textSize="24dip"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_right_text"
+                        android:textSize="24dip"
+                        android:gravity="right"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_after_text"
+                        android:textSize="24dip"
+                        android:gravity="end"
+                        />
+            </TableRow>
+
+            <TableRow>
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button2_text"
+                        android:textSize="24dip"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_left_text"
+                        android:textSize="24dip"
+                        android:gravity="left"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_before_text"
+                        android:textSize="24dip"
+                        android:gravity="start"
+                        />
+            </TableRow>
+        </TableLayout>
+
+        <TableLayout android:layout_width="wrap_content"
+                     android:layout_height="wrap_content"
+                     android:stretchColumns="1,2"
+                     android:layoutDirection="ltr">
+
+            <TableRow>
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button1_text"
+                        android:textSize="24dip"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_right_text"
+                        android:textSize="24dip"
+                        android:gravity="right"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_after_text"
+                        android:textSize="24dip"
+                        android:gravity="end"
+                        />
+            </TableRow>
+
+            <TableRow>
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button2_text"
+                        android:textSize="24dip"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_left_text"
+                        android:textSize="24dip"
+                        android:gravity="left"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_before_text"
+                        android:textSize="24dip"
+                        android:gravity="start"
+                        />
+            </TableRow>
+        </TableLayout>
+
+        <TableLayout android:layout_width="wrap_content"
+                     android:layout_height="wrap_content"
+                     android:stretchColumns="1,2"
+                     android:layoutDirection="rtl">
+
+            <TableRow>
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button1_text"
+                        android:textSize="24dip"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_right_text"
+                        android:textSize="24dip"
+                        android:gravity="right"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_after_text"
+                        android:textSize="24dip"
+                        android:gravity="end"
+                        />
+            </TableRow>
+
+            <TableRow>
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button2_text"
+                        android:textSize="24dip"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_left_text"
+                        android:textSize="24dip"
+                        android:gravity="left"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_before_text"
+                        android:textSize="24dip"
+                        android:gravity="start"
+                        />
+            </TableRow>
+        </TableLayout>
+
+        <TableLayout android:layout_width="wrap_content"
+                     android:layout_height="wrap_content"
+                     android:stretchColumns="1,2"
+                     android:layoutDirection="locale">
+
+            <TableRow>
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button1_text"
+                        android:textSize="24dip"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_right_text"
+                        android:textSize="24dip"
+                        android:gravity="right"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_after_text"
+                        android:textSize="24dip"
+                        android:gravity="end"
+                        />
+            </TableRow>
+
+            <TableRow>
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button2_text"
+                        android:textSize="24dip"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_left_text"
+                        android:textSize="24dip"
+                        android:gravity="left"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_before_text"
+                        android:textSize="24dip"
+                        android:gravity="start"
+                        />
+            </TableRow>
+        </TableLayout>
+
+    </LinearLayout>
+
+</FrameLayout>
\ No newline at end of file
diff --git a/tests/BiDiTests/res/layout/table_layout_ltr.xml b/tests/BiDiTests/res/layout/table_layout_ltr.xml
new file mode 100644
index 0000000..18c0817
--- /dev/null
+++ b/tests/BiDiTests/res/layout/table_layout_ltr.xml
@@ -0,0 +1,258 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+        android:id="@+id/table_layout_ltr"
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent">
+
+    <LinearLayout android:orientation="vertical"
+                  android:layout_width="match_parent"
+                  android:layout_height="match_parent"
+                  android:layoutDirection="ltr">
+
+        <TableLayout android:layout_width="wrap_content"
+                     android:layout_height="wrap_content"
+                     android:stretchColumns="1,2">
+
+            <TableRow>
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button1_text"
+                        android:textSize="24dip"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_right_text"
+                        android:textSize="24dip"
+                        android:gravity="right"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_after_text"
+                        android:textSize="24dip"
+                        android:gravity="end"
+                        />
+            </TableRow>
+
+            <TableRow>
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button2_text"
+                        android:textSize="24dip"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_left_text"
+                        android:textSize="24dip"
+                        android:gravity="left"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_before_text"
+                        android:textSize="24dip"
+                        android:gravity="start"
+                        />
+            </TableRow>
+        </TableLayout>
+
+        <TableLayout android:layout_width="wrap_content"
+                     android:layout_height="wrap_content"
+                     android:stretchColumns="1,2"
+                     android:layoutDirection="inherit">
+    
+            <TableRow>
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button1_text"
+                        android:textSize="24dip"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_right_text"
+                        android:textSize="24dip"
+                        android:gravity="right"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_after_text"
+                        android:textSize="24dip"
+                        android:gravity="end"
+                        />
+            </TableRow>
+
+            <TableRow>
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button2_text"
+                        android:textSize="24dip"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_left_text"
+                        android:textSize="24dip"
+                        android:gravity="left"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_before_text"
+                        android:textSize="24dip"
+                        android:gravity="start"
+                        />
+            </TableRow>
+        </TableLayout>
+
+        <TableLayout android:layout_width="wrap_content"
+                     android:layout_height="wrap_content"
+                     android:stretchColumns="1,2"
+                     android:layoutDirection="ltr">
+    
+            <TableRow>
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button1_text"
+                        android:textSize="24dip"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_right_text"
+                        android:textSize="24dip"
+                        android:gravity="right"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_after_text"
+                        android:textSize="24dip"
+                        android:gravity="end"
+                        />
+            </TableRow>
+
+            <TableRow>
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button2_text"
+                        android:textSize="24dip"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_left_text"
+                        android:textSize="24dip"
+                        android:gravity="left"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_before_text"
+                        android:textSize="24dip"
+                        android:gravity="start"
+                        />
+            </TableRow>
+        </TableLayout>
+
+        <TableLayout android:layout_width="wrap_content"
+                     android:layout_height="wrap_content"
+                     android:stretchColumns="1,2"
+                     android:layoutDirection="rtl">
+    
+            <TableRow>
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button1_text"
+                        android:textSize="24dip"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_right_text"
+                        android:textSize="24dip"
+                        android:gravity="right"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_after_text"
+                        android:textSize="24dip"
+                        android:gravity="end"
+                        />
+            </TableRow>
+
+            <TableRow>
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button2_text"
+                        android:textSize="24dip"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_left_text"
+                        android:textSize="24dip"
+                        android:gravity="left"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_before_text"
+                        android:textSize="24dip"
+                        android:gravity="start"
+                        />
+            </TableRow>
+        </TableLayout>
+
+        <TableLayout android:layout_width="wrap_content"
+                     android:layout_height="wrap_content"
+                     android:stretchColumns="1,2"
+                     android:layoutDirection="locale">
+    
+            <TableRow>
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button1_text"
+                        android:textSize="24dip"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_right_text"
+                        android:textSize="24dip"
+                        android:gravity="right"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_after_text"
+                        android:textSize="24dip"
+                        android:gravity="end"
+                        />
+            </TableRow>
+
+            <TableRow>
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button2_text"
+                        android:textSize="24dip"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_left_text"
+                        android:textSize="24dip"
+                        android:gravity="left"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_before_text"
+                        android:textSize="24dip"
+                        android:gravity="start"
+                        />
+            </TableRow>
+        </TableLayout>
+
+    </LinearLayout>
+
+</FrameLayout>
\ No newline at end of file
diff --git a/tests/BiDiTests/res/layout/table_layout_rtl.xml b/tests/BiDiTests/res/layout/table_layout_rtl.xml
new file mode 100644
index 0000000..d7e097d
--- /dev/null
+++ b/tests/BiDiTests/res/layout/table_layout_rtl.xml
@@ -0,0 +1,258 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+        android:id="@+id/table_layout_rtl"
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent">
+
+    <LinearLayout android:orientation="vertical"
+                  android:layout_width="match_parent"
+                  android:layout_height="match_parent"
+                  android:layoutDirection="rtl">
+
+        <TableLayout android:layout_width="wrap_content"
+                     android:layout_height="wrap_content"
+                     android:stretchColumns="1,2">
+
+            <TableRow>
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button1_text"
+                        android:textSize="24dip"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_right_text"
+                        android:textSize="24dip"
+                        android:gravity="right"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_after_text"
+                        android:textSize="24dip"
+                        android:gravity="end"
+                        />
+            </TableRow>
+
+            <TableRow>
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button2_text"
+                        android:textSize="24dip"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_left_text"
+                        android:textSize="24dip"
+                        android:gravity="left"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_before_text"
+                        android:textSize="24dip"
+                        android:gravity="start"
+                        />
+            </TableRow>
+        </TableLayout>
+
+        <TableLayout android:layout_width="wrap_content"
+                     android:layout_height="wrap_content"
+                     android:stretchColumns="1,2"
+                     android:layoutDirection="inherit">
+
+            <TableRow>
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button1_text"
+                        android:textSize="24dip"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_right_text"
+                        android:textSize="24dip"
+                        android:gravity="right"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_after_text"
+                        android:textSize="24dip"
+                        android:gravity="end"
+                        />
+            </TableRow>
+
+            <TableRow>
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button2_text"
+                        android:textSize="24dip"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_left_text"
+                        android:textSize="24dip"
+                        android:gravity="left"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_before_text"
+                        android:textSize="24dip"
+                        android:gravity="start"
+                        />
+            </TableRow>
+        </TableLayout>
+
+        <TableLayout android:layout_width="wrap_content"
+                     android:layout_height="wrap_content"
+                     android:stretchColumns="1,2"
+                     android:layoutDirection="ltr">
+
+            <TableRow>
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button1_text"
+                        android:textSize="24dip"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_right_text"
+                        android:textSize="24dip"
+                        android:gravity="right"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_after_text"
+                        android:textSize="24dip"
+                        android:gravity="end"
+                        />
+            </TableRow>
+
+            <TableRow>
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button2_text"
+                        android:textSize="24dip"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_left_text"
+                        android:textSize="24dip"
+                        android:gravity="left"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_before_text"
+                        android:textSize="24dip"
+                        android:gravity="start"
+                        />
+            </TableRow>
+        </TableLayout>
+
+        <TableLayout android:layout_width="wrap_content"
+                     android:layout_height="wrap_content"
+                     android:stretchColumns="1,2"
+                     android:layoutDirection="rtl">
+
+            <TableRow>
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button1_text"
+                        android:textSize="24dip"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_right_text"
+                        android:textSize="24dip"
+                        android:gravity="right"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_after_text"
+                        android:textSize="24dip"
+                        android:gravity="end"
+                        />
+            </TableRow>
+
+            <TableRow>
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button2_text"
+                        android:textSize="24dip"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_left_text"
+                        android:textSize="24dip"
+                        android:gravity="left"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_before_text"
+                        android:textSize="24dip"
+                        android:gravity="start"
+                        />
+            </TableRow>
+        </TableLayout>
+
+        <TableLayout android:layout_width="wrap_content"
+                     android:layout_height="wrap_content"
+                     android:stretchColumns="1,2"
+                     android:layoutDirection="locale">
+
+            <TableRow>
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button1_text"
+                        android:textSize="24dip"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_right_text"
+                        android:textSize="24dip"
+                        android:gravity="right"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_after_text"
+                        android:textSize="24dip"
+                        android:gravity="end"
+                        />
+            </TableRow>
+
+            <TableRow>
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button2_text"
+                        android:textSize="24dip"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_left_text"
+                        android:textSize="24dip"
+                        android:gravity="left"
+                        />
+                <Button android:layout_height="wrap_content"
+                        android:layout_width="wrap_content"
+                        android:text="@string/button_before_text"
+                        android:textSize="24dip"
+                        android:gravity="start"
+                        />
+            </TableRow>
+        </TableLayout>
+
+    </LinearLayout>
+
+</FrameLayout>
\ No newline at end of file
diff --git a/tests/BiDiTests/res/layout/view_padding.xml b/tests/BiDiTests/res/layout/view_padding.xml
new file mode 100644
index 0000000..1652d04
--- /dev/null
+++ b/tests/BiDiTests/res/layout/view_padding.xml
@@ -0,0 +1,156 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+        android:id="@+id/view_padding"
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent">
+
+    <FrameLayout android:layout_width="match_parent"
+                 android:layout_height="match_parent">
+
+        <FrameLayout
+                android:layout_width="300dp"
+                android:layout_height="300dp"
+                android:layout_gravity="top|left"
+                android:background="#FF888888"
+                android:paddingTop="20dip"
+                android:paddingLeft="40dip"
+                android:paddingBottom="30dip"
+                android:paddingRight="50dip">
+
+            <FrameLayout
+                    android:layout_width="100dp"
+                    android:layout_height="100dp"
+                    android:layout_gravity="top|left"
+                    android:background="#FF0000FF">
+            </FrameLayout>
+
+            <FrameLayout
+                    android:layout_width="100dp"
+                    android:layout_height="100dp"
+                    android:layout_gravity="bottom|right"
+                    android:background="#FF00FF00">
+            </FrameLayout>
+        </FrameLayout>
+
+        <FrameLayout
+                android:layout_width="300dp"
+                android:layout_height="300dp"
+                android:layout_gravity="top|center_horizontal"
+                android:background="#FF888888"
+                android:paddingTop="20dip"
+                android:paddingLeft="40dip"
+                android:paddingBottom="30dip"
+                android:paddingRight="50dip"
+                android:layoutDirection="inherit">
+
+            <FrameLayout
+                    android:layout_width="100dp"
+                    android:layout_height="100dp"
+                    android:layout_gravity="top|left"
+                    android:background="#FF0000FF">
+            </FrameLayout>
+
+            <FrameLayout
+                    android:layout_width="100dp"
+                    android:layout_height="100dp"
+                    android:layout_gravity="bottom|right"
+                    android:background="#FF00FF00">
+            </FrameLayout>
+        </FrameLayout>
+
+        <FrameLayout
+                android:layout_width="300dp"
+                android:layout_height="300dp"
+                android:layout_gravity="top|right"
+                android:background="#FF888888"
+                android:paddingTop="20dip"
+                android:paddingLeft="40dip"
+                android:paddingBottom="30dip"
+                android:paddingRight="50dip"
+                android:layoutDirection="ltr">
+
+            <FrameLayout
+                    android:layout_width="100dp"
+                    android:layout_height="100dp"
+                    android:layout_gravity="top|left"
+                    android:background="#FF0000FF">
+            </FrameLayout>
+
+            <FrameLayout
+                    android:layout_width="100dp"
+                    android:layout_height="100dp"
+                    android:layout_gravity="bottom|right"
+                    android:background="#FF00FF00">
+            </FrameLayout>
+        </FrameLayout>
+
+        <FrameLayout
+                android:layout_width="300dp"
+                android:layout_height="300dp"
+                android:layout_gravity="bottom|left"
+                android:background="#FF888888"
+                android:paddingTop="20dip"
+                android:paddingLeft="40dip"
+                android:paddingBottom="30dip"
+                android:paddingRight="50dip"
+                android:layoutDirection="rtl">
+
+            <FrameLayout
+                    android:layout_width="100dp"
+                    android:layout_height="100dp"
+                    android:layout_gravity="top|left"
+                    android:background="#FF0000FF">
+            </FrameLayout>
+
+            <FrameLayout
+                    android:layout_width="100dp"
+                    android:layout_height="100dp"
+                    android:layout_gravity="bottom|right"
+                    android:background="#FF00FF00">
+            </FrameLayout>
+        </FrameLayout>
+
+        <FrameLayout
+                android:layout_width="300dp"
+                android:layout_height="300dp"
+                android:layout_gravity="bottom|center_horizontal"
+                android:background="#FF888888"
+                android:paddingTop="20dip"
+                android:paddingLeft="40dip"
+                android:paddingBottom="30dip"
+                android:paddingRight="50dip"
+                android:layoutDirection="locale">
+
+            <FrameLayout
+                    android:layout_width="100dp"
+                    android:layout_height="100dp"
+                    android:layout_gravity="top|left"
+                    android:background="#FF0000FF">
+            </FrameLayout>
+
+            <FrameLayout
+                    android:layout_width="100dp"
+                    android:layout_height="100dp"
+                    android:layout_gravity="bottom|right"
+                    android:background="#FF00FF00">
+            </FrameLayout>
+        </FrameLayout>
+
+    </FrameLayout>
+
+</FrameLayout>
diff --git a/tests/BiDiTests/res/layout/view_padding_mixed.xml b/tests/BiDiTests/res/layout/view_padding_mixed.xml
new file mode 100644
index 0000000..092f55b
--- /dev/null
+++ b/tests/BiDiTests/res/layout/view_padding_mixed.xml
@@ -0,0 +1,135 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+        android:id="@+id/view_padding_mixed"
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent">
+
+    <FrameLayout android:layout_width="match_parent"
+                 android:layout_height="match_parent">
+
+        <FrameLayout
+                android:layout_width="300dp"
+                android:layout_height="300dp"
+                android:layout_gravity="top|left"
+                android:background="#FF888888"
+                android:paddingTop="20dip"
+                android:paddingLeft="40dip"
+                android:paddingStart="5dip"
+                android:paddingBottom="30dip"
+                android:paddingRight="50dip"
+                android:layoutDirection="ltr">
+
+            <FrameLayout
+                    android:layout_width="100dp"
+                    android:layout_height="100dp"
+                    android:layout_gravity="top|left"
+                    android:background="#FF0000FF">
+            </FrameLayout>
+
+            <FrameLayout
+                    android:layout_width="100dp"
+                    android:layout_height="100dp"
+                    android:layout_gravity="bottom|right"
+                    android:background="#FF00FF00">
+            </FrameLayout>
+        </FrameLayout>
+
+        <FrameLayout
+                android:layout_width="300dp"
+                android:layout_height="300dp"
+                android:layout_gravity="top|center_horizontal"
+                android:background="#FF888888"
+                android:paddingTop="20dip"
+                android:paddingLeft="40dip"
+                android:paddingEnd="5dip"
+                android:paddingBottom="30dip"
+                android:paddingRight="50dip"
+                android:layoutDirection="ltr">
+
+            <FrameLayout
+                    android:layout_width="100dp"
+                    android:layout_height="100dp"
+                    android:layout_gravity="top|left"
+                    android:background="#FF0000FF">
+            </FrameLayout>
+
+            <FrameLayout
+                    android:layout_width="100dp"
+                    android:layout_height="100dp"
+                    android:layout_gravity="bottom|right"
+                    android:background="#FF00FF00">
+            </FrameLayout>
+        </FrameLayout>
+
+        <FrameLayout
+                android:layout_width="300dp"
+                android:layout_height="300dp"
+                android:layout_gravity="bottom|left"
+                android:background="#FF888888"
+                android:paddingTop="20dip"
+                android:paddingLeft="40dip"
+                android:paddingStart="5dip"
+                android:paddingBottom="30dip"
+                android:paddingRight="50dip"
+                android:layoutDirection="rtl">
+
+            <FrameLayout
+                    android:layout_width="100dp"
+                    android:layout_height="100dp"
+                    android:layout_gravity="top|left"
+                    android:background="#FF0000FF">
+            </FrameLayout>
+
+            <FrameLayout
+                    android:layout_width="100dp"
+                    android:layout_height="100dp"
+                    android:layout_gravity="bottom|right"
+                    android:background="#FF00FF00">
+            </FrameLayout>
+        </FrameLayout>
+
+        <FrameLayout
+                android:layout_width="300dp"
+                android:layout_height="300dp"
+                android:layout_gravity="bottom|center_horizontal"
+                android:background="#FF888888"
+                android:paddingTop="20dip"
+                android:paddingLeft="40dip"
+                android:paddingEnd="5dip"
+                android:paddingBottom="30dip"
+                android:paddingRight="50dip"
+                android:layoutDirection="rtl">
+
+            <FrameLayout
+                    android:layout_width="100dp"
+                    android:layout_height="100dp"
+                    android:layout_gravity="top|left"
+                    android:background="#FF0000FF">
+            </FrameLayout>
+
+            <FrameLayout
+                    android:layout_width="100dp"
+                    android:layout_height="100dp"
+                    android:layout_gravity="bottom|right"
+                    android:background="#FF00FF00">
+            </FrameLayout>
+        </FrameLayout>
+
+    </FrameLayout>
+
+</FrameLayout>
diff --git a/tests/BiDiTests/res/values/strings.xml b/tests/BiDiTests/res/values/strings.xml
index 3795d4b..d067e7d 100644
--- a/tests/BiDiTests/res/values/strings.xml
+++ b/tests/BiDiTests/res/values/strings.xml
@@ -16,6 +16,12 @@
     <string name="button_text">Button</string>
     <string name="button1_text">Button1</string>
     <string name="button2_text">Button2</string>
+    <string name="button3_text">Button3</string>
+    <string name="button4_text">Button4</string>
+    <string name="button_right_text">Right</string>
+    <string name="button_after_text">End</string>
+    <string name="button_left_text">Left</string>
+    <string name="button_before_text">Start</string>
     <string name="button_requestlayout_text">Request Layout</string>
     <string name="textview_text">This is a text for a TextView</string>
     <string name="edittext_text">mmmmmmmmmmmmmmmmmmmmmmmm</string>
diff --git a/tests/BiDiTests/src/com/android/bidi/BiDiTestActivity.java b/tests/BiDiTests/src/com/android/bidi/BiDiTestActivity.java
index 0d9b4f7..c5e2273 100644
--- a/tests/BiDiTests/src/com/android/bidi/BiDiTestActivity.java
+++ b/tests/BiDiTests/src/com/android/bidi/BiDiTestActivity.java
@@ -16,12 +16,56 @@
 
 package com.android.bidi;
 
-import android.app.TabActivity;
-import android.content.Intent;
-import android.os.Bundle;
-import android.widget.TabHost;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
-public class BiDiTestActivity extends TabActivity {
+import android.app.Activity;
+import android.app.Fragment;
+import android.app.FragmentTransaction;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.ListView;
+import android.widget.SimpleAdapter;
+
+public class BiDiTestActivity extends Activity {
+
+    private static final String KEY_CLASS = "class";
+    private static final String KEY_TITLE = "title";
+    private static final String KEY_FRAGMENT_ID = "id";
+    
+    private ListView mList;
+    
+    private AdapterView.OnItemClickListener mOnClickListener = 
+            new AdapterView.OnItemClickListener() {
+                public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
+                    onListItemClick((ListView)parent, v, position, id);
+                }
+    };
+
+    private void onListItemClick(ListView lv, View v, int position, long id) {
+        // Show the test
+        Map<String, Object> map = (Map<String, Object>)lv.getItemAtPosition(position);
+        int fragmentId = (Integer) map.get(KEY_FRAGMENT_ID);
+        Fragment fragment = getFragmentManager().findFragmentById(fragmentId);
+        if (fragment == null) {
+            try {
+                // Create an instance of the test
+                Class<? extends Fragment> clazz = (Class<? extends Fragment>) map.get(KEY_CLASS);  
+                fragment = clazz.newInstance();
+                
+                // Replace the old test fragment with the new one
+                FragmentTransaction ft = getFragmentManager().beginTransaction();
+                ft.replace(R.id.testframe, fragment);
+                ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
+                ft.commit();
+            } catch (InstantiationException e) {
+            } catch (IllegalAccessException e) {
+            }
+        }
+    }
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -29,30 +73,55 @@
 
         setContentView(R.layout.main);
 
-        TabHost tabHost = getTabHost();
-        TabHost.TabSpec spec;
-        Intent intent;
+        mList = (ListView) findViewById(R.id.testlist);
+        mList.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
+        mList.setFocusableInTouchMode(true);
+        
+        final SimpleAdapter adapter = new SimpleAdapter(this, getTests(),
+                R.layout.custom_list_item, new String[]{"title"},
+                new int[]{android.R.id.text1});
+        mList.setAdapter(adapter);
+        
+        mList.setOnItemClickListener(mOnClickListener);
+    }
 
-        // Create an Intent to launch an Activity for the tab (to be reused)
-        intent = new Intent().setClass(this, BiDiTestBasicActivity.class);
+    private void addItem(List<Map<String, Object>> data, String name,
+            Class<? extends Fragment> clazz, int fragmentId) {
+        Map<String, Object> temp = new HashMap<String, Object>();
+        temp.put(KEY_TITLE, name);
+        temp.put(KEY_CLASS, clazz);
+        temp.put(KEY_FRAGMENT_ID, fragmentId);
+        data.add(temp);
+    }
 
-        // Initialize a TabSpec for each tab and add it to the TabHost
-        spec = tabHost.newTabSpec("basic").setIndicator("Basic").setContent(intent);
-        tabHost.addTab(spec);
+    private List<Map<String, Object>> getTests() {
+        List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
 
-        // Do the same for the other tabs
-        intent = new Intent().setClass(this, BiDiTestCanvasActivity.class);
-        spec = tabHost.newTabSpec("canvas").setIndicator("Canvas").setContent(intent);
-        tabHost.addTab(spec);
+        addItem(result, "Basic", BiDiTestBasic.class, R.id.basic);
+        addItem(result, "Canvas", BiDiTestCanvas.class, R.id.canvas);
+        
+        addItem(result, "Linear LTR", BiDiTestLinearLayoutLtr.class, R.id.linear_layout_ltr);
+        addItem(result, "Linear RTL", BiDiTestLinearLayoutRtl.class, R.id.linear_layout_rtl);
+        addItem(result, "Linear LOC", BiDiTestLinearLayoutLocale.class, R.id.linear_layout_locale);
+        
+        addItem(result, "Frame LTR", BiDiTestFrameLayoutLtr.class, R.id.frame_layout_ltr);
+        addItem(result, "Frame RTL", BiDiTestFrameLayoutRtl.class, R.id.frame_layout_rtl);
+        addItem(result, "Frame LOC", BiDiTestFrameLayoutLocale.class, R.id.frame_layout_locale);
+        
+        addItem(result, "Relative LTR", BiDiTestRelativeLayoutLtr.class, R.id.relative_layout_ltr);
+        addItem(result, "Relative RTL", BiDiTestRelativeLayoutRtl.class, R.id.relative_layout_rtl);
+        
+        addItem(result, "Relative2 LTR", BiDiTestRelativeLayout2Ltr.class, R.id.relative_layout_2_ltr);
+        addItem(result, "Relative2 RTL", BiDiTestRelativeLayout2Rtl.class, R.id.relative_layout_2_rtl);
+        addItem(result, "Relative2 LOC", BiDiTestRelativeLayout2Locale.class, R.id.relative_layout_2_locale);
+        
+        addItem(result, "Table LTR", BiDiTestTableLayoutLtr.class, R.id.table_layout_ltr);
+        addItem(result, "Table RTL", BiDiTestTableLayoutRtl.class, R.id.table_layout_rtl);
+        addItem(result, "Table LOC", BiDiTestTableLayoutLocale.class, R.id.table_layout_locale);
 
-        intent = new Intent().setClass(this, BiDiTestLinearLayoutLtrActivity.class);
-        spec = tabHost.newTabSpec("layout-ltr").setIndicator("LinearLayout LTR").setContent(intent);
-        tabHost.addTab(spec);
+        addItem(result, "ViewPadding", BiDiTestViewPadding.class, R.id.view_padding);
+        addItem(result, "ViewPadding MIXED", BiDiTestViewPaddingMixed.class, R.id.view_padding_mixed);
 
-        intent = new Intent().setClass(this, BiDiTestLinearLayoutRtlActivity.class);
-        spec = tabHost.newTabSpec("layout-rtl").setIndicator("LinearLayout RTL").setContent(intent);
-        tabHost.addTab(spec);
-
-        tabHost.setCurrentTab(0);
+        return result;
     }
 }
\ No newline at end of file
diff --git a/tests/BiDiTests/src/com/android/bidi/BiDiTestBasic.java b/tests/BiDiTests/src/com/android/bidi/BiDiTestBasic.java
new file mode 100644
index 0000000..9b3918d
--- /dev/null
+++ b/tests/BiDiTests/src/com/android/bidi/BiDiTestBasic.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.bidi;
+
+import android.app.Fragment;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+public class BiDiTestBasic extends Fragment {
+    
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+            Bundle savedInstanceState) {
+        return inflater.inflate(R.layout.basic, container, false);
+    }
+}
diff --git a/tests/BiDiTests/src/com/android/bidi/BiDiTestBasicActivity.java b/tests/BiDiTests/src/com/android/bidi/BiDiTestBasicActivity.java
deleted file mode 100644
index 2a8de04..0000000
--- a/tests/BiDiTests/src/com/android/bidi/BiDiTestBasicActivity.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.bidi;
-
-import android.app.Activity;
-import android.os.Bundle;
-
-public class BiDiTestBasicActivity extends Activity {
-
-    @Override
-    protected void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-
-        setContentView(R.layout.basic);
-    }
-}
diff --git a/tests/BiDiTests/src/com/android/bidi/BiDiTestCanvas.java b/tests/BiDiTests/src/com/android/bidi/BiDiTestCanvas.java
new file mode 100644
index 0000000..33ed731
--- /dev/null
+++ b/tests/BiDiTests/src/com/android/bidi/BiDiTestCanvas.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.bidi;
+
+import android.app.Fragment;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.SeekBar;
+
+import static com.android.bidi.BiDiTestConstants.FONT_MAX_SIZE;
+import static com.android.bidi.BiDiTestConstants.FONT_MIN_SIZE;
+
+public class BiDiTestCanvas extends Fragment {
+
+    static final int INIT_TEXT_SIZE = (FONT_MAX_SIZE - FONT_MIN_SIZE) / 2;
+
+    private BiDiTestView testView;
+    private SeekBar textSizeSeekBar;
+    private View currentView;
+
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+            Bundle savedInstanceState) {
+        currentView = inflater.inflate(R.layout.canvas, container, false);
+        return currentView;
+    }
+
+    @Override
+    public void onViewCreated(View view, Bundle savedInstanceState) {
+        super.onViewCreated(view, savedInstanceState);
+
+        testView = (BiDiTestView) currentView.findViewById(R.id.testview);
+        testView.setCurrentTextSize(INIT_TEXT_SIZE);
+
+        textSizeSeekBar = (SeekBar) currentView.findViewById(R.id.seekbar);
+        textSizeSeekBar.setProgress(INIT_TEXT_SIZE);
+        textSizeSeekBar.setMax(FONT_MAX_SIZE - FONT_MIN_SIZE);
+
+        textSizeSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
+            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+                testView.setCurrentTextSize(FONT_MIN_SIZE + progress);
+            }
+
+            public void onStartTrackingTouch(SeekBar seekBar) {
+            }
+
+            public void onStopTrackingTouch(SeekBar seekBar) {
+            }
+        });
+    }
+}
diff --git a/tests/BiDiTests/src/com/android/bidi/BiDiTestCanvasActivity.java b/tests/BiDiTests/src/com/android/bidi/BiDiTestCanvasActivity.java
deleted file mode 100644
index 3ab75d5..0000000
--- a/tests/BiDiTests/src/com/android/bidi/BiDiTestCanvasActivity.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.bidi;
-
-import android.app.Activity;
-import android.os.Bundle;
-import android.widget.SeekBar;
-
-import static com.android.bidi.BiDiTestConstants.FONT_MAX_SIZE;
-import static com.android.bidi.BiDiTestConstants.FONT_MIN_SIZE;
-
-public class BiDiTestCanvasActivity extends Activity {
-
-    static final int INIT_TEXT_SIZE = (FONT_MAX_SIZE - FONT_MIN_SIZE) / 2;
-
-    private BiDiTestView testView;
-    private SeekBar textSizeSeekBar;
-
-    @Override
-    protected void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-
-        setContentView(R.layout.canvas);
-
-        testView = (BiDiTestView) findViewById(R.id.testview);
-        testView.setCurrentTextSize(INIT_TEXT_SIZE);
-
-        textSizeSeekBar = (SeekBar) findViewById(R.id.seekbar);
-        textSizeSeekBar.setProgress(INIT_TEXT_SIZE);
-        textSizeSeekBar.setMax(FONT_MAX_SIZE - FONT_MIN_SIZE);
-
-        textSizeSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
-            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
-                testView.setCurrentTextSize(FONT_MIN_SIZE + progress);
-            }
-
-            public void onStartTrackingTouch(SeekBar seekBar) {
-            }
-
-            public void onStopTrackingTouch(SeekBar seekBar) {
-            }
-        });
-    }
-}
diff --git a/tests/BiDiTests/src/com/android/bidi/BiDiTestFrameLayoutLocale.java b/tests/BiDiTests/src/com/android/bidi/BiDiTestFrameLayoutLocale.java
new file mode 100644
index 0000000..900bcd1
--- /dev/null
+++ b/tests/BiDiTests/src/com/android/bidi/BiDiTestFrameLayoutLocale.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.bidi;
+
+import android.app.Fragment;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+public class BiDiTestFrameLayoutLocale extends Fragment {
+
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+            Bundle savedInstanceState) {
+        return inflater.inflate(R.layout.frame_layout_locale, container, false);
+    }
+}
+
diff --git a/tests/BiDiTests/src/com/android/bidi/BiDiTestFrameLayoutLtr.java b/tests/BiDiTests/src/com/android/bidi/BiDiTestFrameLayoutLtr.java
new file mode 100644
index 0000000..43900da
--- /dev/null
+++ b/tests/BiDiTests/src/com/android/bidi/BiDiTestFrameLayoutLtr.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.bidi;
+
+import android.app.Fragment;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+public class BiDiTestFrameLayoutLtr extends Fragment {
+
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+            Bundle savedInstanceState) {
+        return inflater.inflate(R.layout.frame_layout_ltr, container, false);
+    }
+}
+
diff --git a/tests/BiDiTests/src/com/android/bidi/BiDiTestFrameLayoutRtl.java b/tests/BiDiTests/src/com/android/bidi/BiDiTestFrameLayoutRtl.java
new file mode 100644
index 0000000..a261449
--- /dev/null
+++ b/tests/BiDiTests/src/com/android/bidi/BiDiTestFrameLayoutRtl.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.bidi;
+
+import android.app.Fragment;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+public class BiDiTestFrameLayoutRtl extends Fragment {
+
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+            Bundle savedInstanceState) {
+        return inflater.inflate(R.layout.frame_layout_rtl, container, false);
+    }
+}
+
diff --git a/tests/BiDiTests/src/com/android/bidi/BiDiTestLinearLayoutLocale.java b/tests/BiDiTests/src/com/android/bidi/BiDiTestLinearLayoutLocale.java
new file mode 100644
index 0000000..ad686df
--- /dev/null
+++ b/tests/BiDiTests/src/com/android/bidi/BiDiTestLinearLayoutLocale.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.bidi;
+
+import android.app.Fragment;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+public class BiDiTestLinearLayoutLocale extends Fragment {
+
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+            Bundle savedInstanceState) {
+        return inflater.inflate(R.layout.linear_layout_locale, container, false);
+    }
+}
diff --git a/tests/BiDiTests/src/com/android/bidi/BiDiTestLinearLayoutLtr.java b/tests/BiDiTests/src/com/android/bidi/BiDiTestLinearLayoutLtr.java
new file mode 100644
index 0000000..da9195a
--- /dev/null
+++ b/tests/BiDiTests/src/com/android/bidi/BiDiTestLinearLayoutLtr.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.bidi;
+
+import android.app.Fragment;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+public class BiDiTestLinearLayoutLtr extends Fragment {
+
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+            Bundle savedInstanceState) {
+        return inflater.inflate(R.layout.linear_layout_ltr, container, false);
+    }
+}
diff --git a/tests/BiDiTests/src/com/android/bidi/BiDiTestLinearLayoutLtrActivity.java b/tests/BiDiTests/src/com/android/bidi/BiDiTestLinearLayoutLtrActivity.java
deleted file mode 100644
index 6d8f11d..0000000
--- a/tests/BiDiTests/src/com/android/bidi/BiDiTestLinearLayoutLtrActivity.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.bidi;
-
-import android.app.Activity;
-import android.os.Bundle;
-import android.widget.LinearLayout;
-
-public class BiDiTestLinearLayoutLtrActivity extends Activity {
-
-    private LinearLayout layout;
-
-    @Override
-    protected void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-
-        setContentView(R.layout.linear_layout_ltr);
-
-        layout = (LinearLayout) findViewById(R.id.layouttest);
-    }
-}
diff --git a/tests/BiDiTests/src/com/android/bidi/BiDiTestLinearLayoutRtl.java b/tests/BiDiTests/src/com/android/bidi/BiDiTestLinearLayoutRtl.java
new file mode 100644
index 0000000..dfe247f
--- /dev/null
+++ b/tests/BiDiTests/src/com/android/bidi/BiDiTestLinearLayoutRtl.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.bidi;
+
+import android.app.Fragment;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+public class BiDiTestLinearLayoutRtl extends Fragment {
+
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+            Bundle savedInstanceState) {
+        return inflater.inflate(R.layout.linear_layout_rtl, container, false);
+    }
+}
diff --git a/tests/BiDiTests/src/com/android/bidi/BiDiTestLinearLayoutRtlActivity.java b/tests/BiDiTests/src/com/android/bidi/BiDiTestLinearLayoutRtlActivity.java
deleted file mode 100644
index 0130793..0000000
--- a/tests/BiDiTests/src/com/android/bidi/BiDiTestLinearLayoutRtlActivity.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.bidi;
-
-import android.app.Activity;
-import android.os.Bundle;
-import android.widget.LinearLayout;
-
-public class BiDiTestLinearLayoutRtlActivity extends Activity {
-
-    private LinearLayout layout;
-
-    @Override
-    protected void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-
-        setContentView(R.layout.linear_layout_rtl);
-
-        layout = (LinearLayout) findViewById(R.id.layouttest);
-    }
-}
diff --git a/tests/BiDiTests/src/com/android/bidi/BiDiTestRelativeLayout2Locale.java b/tests/BiDiTests/src/com/android/bidi/BiDiTestRelativeLayout2Locale.java
new file mode 100644
index 0000000..957f189
--- /dev/null
+++ b/tests/BiDiTests/src/com/android/bidi/BiDiTestRelativeLayout2Locale.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.bidi;
+
+import android.app.Fragment;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+public class BiDiTestRelativeLayout2Locale extends Fragment {
+
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+            Bundle savedInstanceState) {
+        return inflater.inflate(R.layout.relative_layout_2_locale, container, false);
+    }
+}
+
diff --git a/tests/BiDiTests/src/com/android/bidi/BiDiTestRelativeLayout2Ltr.java b/tests/BiDiTests/src/com/android/bidi/BiDiTestRelativeLayout2Ltr.java
new file mode 100644
index 0000000..a27b3a4
--- /dev/null
+++ b/tests/BiDiTests/src/com/android/bidi/BiDiTestRelativeLayout2Ltr.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.bidi;
+
+import android.app.Fragment;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+public class BiDiTestRelativeLayout2Ltr extends Fragment {
+
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+            Bundle savedInstanceState) {
+        return inflater.inflate(R.layout.relative_layout_2_ltr, container, false);
+    }
+}
+
diff --git a/tests/BiDiTests/src/com/android/bidi/BiDiTestRelativeLayout2Rtl.java b/tests/BiDiTests/src/com/android/bidi/BiDiTestRelativeLayout2Rtl.java
new file mode 100644
index 0000000..6185a6f
--- /dev/null
+++ b/tests/BiDiTests/src/com/android/bidi/BiDiTestRelativeLayout2Rtl.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.bidi;
+
+import android.app.Fragment;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+public class BiDiTestRelativeLayout2Rtl extends Fragment {
+
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+            Bundle savedInstanceState) {
+        return inflater.inflate(R.layout.relative_layout_2_rtl, container, false);
+    }
+}
+
diff --git a/tests/BiDiTests/src/com/android/bidi/BiDiTestRelativeLayoutLtr.java b/tests/BiDiTests/src/com/android/bidi/BiDiTestRelativeLayoutLtr.java
new file mode 100644
index 0000000..d854e7a
--- /dev/null
+++ b/tests/BiDiTests/src/com/android/bidi/BiDiTestRelativeLayoutLtr.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.bidi;
+
+import android.app.Fragment;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+public class BiDiTestRelativeLayoutLtr extends Fragment {
+
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+            Bundle savedInstanceState) {
+        return inflater.inflate(R.layout.relative_layout_ltr, container, false);
+    }
+}
+
diff --git a/tests/BiDiTests/src/com/android/bidi/BiDiTestRelativeLayoutRtl.java b/tests/BiDiTests/src/com/android/bidi/BiDiTestRelativeLayoutRtl.java
new file mode 100644
index 0000000..ed5607a
--- /dev/null
+++ b/tests/BiDiTests/src/com/android/bidi/BiDiTestRelativeLayoutRtl.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.bidi;
+
+import android.app.Fragment;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+public class BiDiTestRelativeLayoutRtl extends Fragment {
+
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+            Bundle savedInstanceState) {
+        return inflater.inflate(R.layout.relative_layout_rtl, container, false);
+    }
+}
+
diff --git a/tests/BiDiTests/src/com/android/bidi/BiDiTestTableLayoutLocale.java b/tests/BiDiTests/src/com/android/bidi/BiDiTestTableLayoutLocale.java
new file mode 100644
index 0000000..7172c94
--- /dev/null
+++ b/tests/BiDiTests/src/com/android/bidi/BiDiTestTableLayoutLocale.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.bidi;
+
+import android.app.Fragment;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+public class BiDiTestTableLayoutLocale extends Fragment {
+
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+            Bundle savedInstanceState) {
+        return inflater.inflate(R.layout.table_layout_locale, container, false);
+    }
+}
+
diff --git a/tests/BiDiTests/src/com/android/bidi/BiDiTestTableLayoutLtr.java b/tests/BiDiTests/src/com/android/bidi/BiDiTestTableLayoutLtr.java
new file mode 100644
index 0000000..ef75b5e
--- /dev/null
+++ b/tests/BiDiTests/src/com/android/bidi/BiDiTestTableLayoutLtr.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.bidi;
+
+import android.app.Fragment;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+public class BiDiTestTableLayoutLtr extends Fragment {
+
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+            Bundle savedInstanceState) {
+        return inflater.inflate(R.layout.table_layout_ltr, container, false);
+    }
+}
+
diff --git a/tests/BiDiTests/src/com/android/bidi/BiDiTestTableLayoutRtl.java b/tests/BiDiTests/src/com/android/bidi/BiDiTestTableLayoutRtl.java
new file mode 100644
index 0000000..d3c20ff
--- /dev/null
+++ b/tests/BiDiTests/src/com/android/bidi/BiDiTestTableLayoutRtl.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.bidi;
+
+import android.app.Fragment;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+public class BiDiTestTableLayoutRtl extends Fragment {
+
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+            Bundle savedInstanceState) {
+        return inflater.inflate(R.layout.table_layout_rtl, container, false);
+    }
+}
+
diff --git a/tests/BiDiTests/src/com/android/bidi/BiDiTestViewPadding.java b/tests/BiDiTests/src/com/android/bidi/BiDiTestViewPadding.java
new file mode 100644
index 0000000..6bb410a
--- /dev/null
+++ b/tests/BiDiTests/src/com/android/bidi/BiDiTestViewPadding.java
@@ -0,0 +1,17 @@
+// Copyright 2011 Google Inc. All Rights Reserved.
+package com.android.bidi;
+
+import android.app.Fragment;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+public class BiDiTestViewPadding extends Fragment {
+
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+            Bundle savedInstanceState) {
+        return inflater.inflate(R.layout.view_padding, container, false);
+    }
+}
diff --git a/tests/BiDiTests/src/com/android/bidi/BiDiTestViewPaddingMixed.java b/tests/BiDiTests/src/com/android/bidi/BiDiTestViewPaddingMixed.java
new file mode 100644
index 0000000..7ca2707
--- /dev/null
+++ b/tests/BiDiTests/src/com/android/bidi/BiDiTestViewPaddingMixed.java
@@ -0,0 +1,17 @@
+// Copyright 2011 Google Inc. All Rights Reserved.
+package com.android.bidi;
+
+import android.app.Fragment;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+public class BiDiTestViewPaddingMixed extends Fragment {
+
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+            Bundle savedInstanceState) {
+        return inflater.inflate(R.layout.view_padding_mixed, container, false);
+    }
+}
diff --git a/tests/DpiTest/src/com/google/android/test/dpi/DpiTestActivity.java b/tests/DpiTest/src/com/google/android/test/dpi/DpiTestActivity.java
index 2a40c57..01c1c70 100644
--- a/tests/DpiTest/src/com/google/android/test/dpi/DpiTestActivity.java
+++ b/tests/DpiTest/src/com/google/android/test/dpi/DpiTestActivity.java
@@ -63,7 +63,8 @@
                     | ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS
                     | ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES;
                 app.getResources().setCompatibilityInfo(new CompatibilityInfo(ai,
-                        getResources().getConfiguration().screenLayout, false));
+                        getResources().getConfiguration().screenLayout,
+                        getResources().getConfiguration().smallestScreenWidthDp, false));
             }
         } catch (PackageManager.NameNotFoundException e) {
             throw new RuntimeException("ouch", e);
diff --git a/tests/GridLayoutTest/AndroidManifest.xml b/tests/GridLayoutTest/AndroidManifest.xml
index 53ca4ce..1b72357 100644
--- a/tests/GridLayoutTest/AndroidManifest.xml
+++ b/tests/GridLayoutTest/AndroidManifest.xml
@@ -76,6 +76,27 @@
                 <category android:name="android.intent.category.LAUNCHER"/>
             </intent-filter>
         </activity>
+
+        <activity android:name="AlignmentTest" android:label="AlignmentTest">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN"/>
+                <category android:name="android.intent.category.LAUNCHER"/>
+            </intent-filter>
+        </activity>
+
+        <activity android:name="LinearLayoutTest" android:label="LinearLayoutTest">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN"/>
+                <category android:name="android.intent.category.LAUNCHER"/>
+            </intent-filter>
+        </activity>
+
+        <activity android:name="GridLayoutTest" android:label="GridLayoutTest">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN"/>
+                <category android:name="android.intent.category.LAUNCHER"/>
+            </intent-filter>
+        </activity>
     </application>
 
 
diff --git a/tests/GridLayoutTest/res/layout/grid3.xml b/tests/GridLayoutTest/res/layout/grid3.xml
index ace7b4c..ba911c2 100644
--- a/tests/GridLayoutTest/res/layout/grid3.xml
+++ b/tests/GridLayoutTest/res/layout/grid3.xml
@@ -19,59 +19,69 @@
 
         android:layout_width="match_parent"
         android:layout_height="match_parent"
+
+        android:useDefaultMargins="true"
+        android:alignmentMode="alignBounds"
+
+        android:columnCount="4"
         >
 
-    <Button
-            android:text="fill"
-            android:width="200dip"
-            android:height="100dip"
-            android:layout_marginLeft="50dip"
-            android:layout_row="0"
-            android:layout_column="0"
-            android:layout_gravity="fill_horizontal"
+    <TextView
+            android:text="Email account"
+            android:textSize="48dip"
+
+            android:layout_columnSpan="4"
+            android:layout_gravity="center_horizontal"
+            />
+
+    <TextView
+            android:text="You can configure email in just a few steps:"
+            android:textSize="20dip"
+
+            android:layout_columnSpan="4"
+            android:layout_gravity="left"
+            />
+
+    <TextView
+            android:text="Email address:"
+
+            android:layout_gravity="right"
             />
 
     <EditText
-            android:layout_row="0"
-            android:layout_column="1"
+            android:layout_width="100dip"
             />
 
-    <Button
-            android:text="left"
-            android:layout_row="1"
-            android:layout_column="0"
-            />
+    <TextView
+            android:text="Password:"
 
-    <EditText
-            android:layout_row="1"
-            android:layout_column="1"
-            />
-
-    <Button
-            android:text="right"
-            android:layout_row="2"
             android:layout_column="0"
             android:layout_gravity="right"
             />
 
     <EditText
-            android:layout_margin="50dip"
-            android:textSize="100dip"
-            android:layout_row="2"
-            android:layout_column="1"
+            android:layout_width="50dip"
+            />
+
+    <Space
+            android:layout_row="4"
+            android:layout_column="2"
+            android:layout_rowWeight="1"
+            android:layout_columnWeight="1"
             />
 
     <Button
-            android:text="center"
-            android:layout_row="3"
-            android:layout_column="0"
-            android:layout_gravity="center_horizontal"
+            android:text="Manual setup"
+
+            android:layout_row="5"
+            android:layout_column="3"
+            android:layout_gravity="fill_horizontal"
             />
 
-    <EditText
-            android:layout_height="fill_parent"
-            android:layout_row="3"
-            android:layout_column="1"
-            />
+    <Button
+            android:text="Next"
 
+            android:layout_column="3"
+            android:layout_gravity="fill_horizontal"
+            />
 </GridLayout>
diff --git a/tests/GridLayoutTest/src/com/android/test/layout/AbstractLayoutTest.java b/tests/GridLayoutTest/src/com/android/test/layout/AbstractLayoutTest.java
new file mode 100644
index 0000000..4d3a843
--- /dev/null
+++ b/tests/GridLayoutTest/src/com/android/test/layout/AbstractLayoutTest.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.test.layout;
+
+import android.app.Activity;
+import android.content.Context;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+
+import static android.view.Gravity.*;
+
+public abstract class AbstractLayoutTest extends Activity {
+
+    public static final String[] HORIZONTAL_NAMES = { "LEFT", "CENTER", "RIGHT", "FILL" };
+    public static final int[] HORIZONTAL_ALIGNMENTS = { LEFT, CENTER, RIGHT, FILL };
+    public static final String[] VERTICAL_NAMES = { "TOP", "CENTER", "BASELINE", "BOTTOM", "FILL" };
+    public static final int[] VERTICAL_ALIGNMENTS = { TOP, CENTER, NO_GRAVITY, BOTTOM, FILL };
+
+    public View create(Context context, String name, int size) {
+        Button result = new Button(context);
+        result.setText(name);
+        result.setOnClickListener(new View.OnClickListener() {
+            public void onClick(View v) {
+                animate(v);
+            }
+        });
+        return result;
+    }
+
+    public abstract ViewGroup create(Context context);
+    public abstract String tag();
+
+    public void animate(View v) {
+        long start = System.currentTimeMillis();
+        int N = 1000;
+        for (int i = 0; i < N; i++) {
+            ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
+            lp.topMargin = (lp.topMargin + 1) % 31;
+            lp.leftMargin = (lp.leftMargin + 1) % 31;
+
+            v.requestLayout();
+            v.invalidate();
+            ViewGroup p = (ViewGroup) v.getParent();
+            p.layout(0, 0, 1000 + (i % 2), 500 + (i % 2));
+        }
+        Log.d(tag(), "Time: " + (float) (System.currentTimeMillis() - start) / N * 1000 + "mics");
+    }
+
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(create(getBaseContext()));
+    }
+
+}
\ No newline at end of file
diff --git a/tests/GridLayoutTest/src/com/android/test/layout/Activity2.java b/tests/GridLayoutTest/src/com/android/test/layout/Activity2.java
index 6359903..e010a00 100644
--- a/tests/GridLayoutTest/src/com/android/test/layout/Activity2.java
+++ b/tests/GridLayoutTest/src/com/android/test/layout/Activity2.java
@@ -20,11 +20,15 @@
 import android.content.Context;
 import android.os.Bundle;
 import android.view.View;
-
-import android.widget.*;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.GridLayout;
+import android.widget.Space;
+import android.widget.TextView;
 
 import static android.text.InputType.TYPE_CLASS_TEXT;
-import static android.view.inputmethod.EditorInfo.*;
+import static android.view.inputmethod.EditorInfo.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
+import static android.view.inputmethod.EditorInfo.TYPE_TEXT_VARIATION_PASSWORD;
 import static android.widget.GridLayout.*;
 
 public class Activity2 extends Activity {
@@ -32,6 +36,7 @@
     public static View create(Context context) {
         GridLayout vg = new GridLayout(context);
         vg.setUseDefaultMargins(true);
+        vg.setAlignmentMode(ALIGN_BOUNDS);
 
         Group row1 = new Group(1, CENTER);
         Group row2 = new Group(2, CENTER);
@@ -41,12 +46,12 @@
         Group row6 = new Group(6, CENTER);
         Group row7 = new Group(7, CENTER);
 
-        Group col1a = new Group(1, 5, CENTER);
-        Group col1b = new Group(1, 5, LEFT);
+        Group col1a = new Group(1, 4, CENTER);
+        Group col1b = new Group(1, 4, LEFT);
         Group col1c = new Group(1, RIGHT);
-        Group col2 =  new Group(2, LEFT);
-        Group col3 =  new Group(3, FILL);
-        Group col4 =  new Group(4, FILL);
+        Group col2 = new Group(2, LEFT);
+        Group col3 = new Group(3, FILL);
+        Group col4 = new Group(4, FILL);
 
         {
             TextView v = new TextView(context);
@@ -54,20 +59,17 @@
             v.setText("Email setup");
             vg.addView(v, new LayoutParams(row1, col1a));
         }
-
         {
             TextView v = new TextView(context);
             v.setTextSize(20);
             v.setText("You can configure email in just a few steps:");
             vg.addView(v, new LayoutParams(row2, col1b));
         }
-
         {
             TextView v = new TextView(context);
             v.setText("Email address:");
             vg.addView(v, new LayoutParams(row3, col1c));
         }
-
         {
             EditText v = new EditText(context);
             v.setInputType(TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
@@ -77,13 +79,11 @@
                 vg.addView(v, lp);
             }
         }
-
         {
             TextView v = new TextView(context);
             v.setText("Password:");
             vg.addView(v, new LayoutParams(row4, col1c));
         }
-
         {
             TextView v = new EditText(context);
             v.setInputType(TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_PASSWORD);
@@ -93,7 +93,6 @@
                 vg.addView(v, lp);
             }
         }
-
         {
             Space v = new Space(context);
             {
@@ -103,13 +102,11 @@
                 vg.addView(v, lp);
             }
         }
-
         {
             Button v = new Button(context);
             v.setText("Manual setup");
             vg.addView(v, new LayoutParams(row6, col4));
         }
-
         {
             Button v = new Button(context);
             v.setText("Next");
diff --git a/tests/GridLayoutTest/src/com/android/test/layout/AlignmentTest.java b/tests/GridLayoutTest/src/com/android/test/layout/AlignmentTest.java
new file mode 100755
index 0000000..505c83d
--- /dev/null
+++ b/tests/GridLayoutTest/src/com/android/test/layout/AlignmentTest.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.test.layout;
+
+import android.app.Activity;
+import android.content.Context;
+import android.os.Bundle;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.ViewParent;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.GridLayout;
+import android.widget.TextView;
+
+import static android.widget.GridLayout.*;
+
+public class AlignmentTest  extends Activity {
+
+    public static final String[] HORIZONTAL_NAMES = {"LEFT", "center", "east", "fill"};
+    public static final Alignment[] HORIZONTAL_ALIGNMENTS = {LEFT, CENTER, RIGHT, FILL};
+    public static final String[] VERTICAL_NAMES = {"north", "center", "baseline", "south", "fill"};
+    public static final Alignment[] VERTICAL_ALIGNMENTS = {TOP, CENTER, BASELINE, BOTTOM, FILL};
+    private static Context CONTEXT;
+
+    public static interface ViewFactory {
+        View create(String name, int size);
+    }
+
+    public static final ViewFactory BUTTON_FACTORY = new ViewFactory() {
+        public View create(String name, int size) {
+            Button result = new Button(CONTEXT);
+            result.setText(name);
+           result.setOnClickListener(new OnClickListener() {
+               @Override
+               public void onClick(View v) {
+                    animate(v);
+               }
+           });
+            return result;
+        }
+    };
+
+    public static final ViewFactory LABEL_FACTORY = new ViewFactory() {
+        public View create(String name, int size) {
+            TextView result = new TextView(CONTEXT);
+            result.setText(name);
+            result.setTextSize(40);
+            return result;
+        }
+    };
+
+    public static final ViewFactory TEXT_FIELD_FACTORY = new ViewFactory() {
+        public View create(String name, int size) {
+            EditText result = new EditText(CONTEXT);
+            result.setText(name);
+            return result;
+        }
+    };
+
+    public static final ViewFactory[] FACTORIES =
+                            {BUTTON_FACTORY, LABEL_FACTORY, TEXT_FIELD_FACTORY};
+
+    public static ViewGroup create(Context context1) {
+        CONTEXT = context1;
+        GridLayout container = new GridLayout(context1);
+        container.setUseDefaultMargins(true);
+
+        for (int i = 0; i < VERTICAL_ALIGNMENTS.length; i++) {
+            Alignment va = VERTICAL_ALIGNMENTS[i];
+            for (int j = 0; j < HORIZONTAL_ALIGNMENTS.length; j++) {
+                Alignment ha = HORIZONTAL_ALIGNMENTS[j];
+                Group rowGroup = new Group(i, va);
+                Group colGroup = new Group(j, ha);
+                LayoutParams layoutParams = new LayoutParams(rowGroup, colGroup);
+                String name = VERTICAL_NAMES[i] + "-" + HORIZONTAL_NAMES[j];
+                ViewFactory factory = FACTORIES[(i + j) % FACTORIES.length];
+                container.addView(factory.create(name, 20), layoutParams);
+            }
+        }
+
+        return container;
+    }
+
+    public static void animate(View v) {
+
+        long start = System.currentTimeMillis();
+        int N = 1000;
+        for (int i = 0; i < N; i++) {
+            ViewGroup.LayoutParams lp = v.getLayoutParams();
+            lp.width += 1; // width;
+            lp.height += 1; // height;
+            v.requestLayout();
+            GridLayout p = (GridLayout) v.getParent();
+            p.layout(0, 0, 1000 + (i % 2), 500 + (i % 2));
+        }
+        float time = (float) (System.currentTimeMillis() - start) / N * 1000;
+        System.out.println("Time: " + time + "mics");
+    }
+
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(create(getBaseContext()));
+    }
+
+}
\ No newline at end of file
diff --git a/tests/GridLayoutTest/src/com/android/test/layout/GridLayoutTest.java b/tests/GridLayoutTest/src/com/android/test/layout/GridLayoutTest.java
new file mode 100644
index 0000000..c5681e2
--- /dev/null
+++ b/tests/GridLayoutTest/src/com/android/test/layout/GridLayoutTest.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.test.layout;
+
+import android.content.Context;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.GridLayout;
+
+import static android.widget.GridLayout.*;
+
+public class GridLayoutTest extends AbstractLayoutTest {
+    public ViewGroup create(Context context) {
+        GridLayout container = new GridLayout(context);
+        container.setOrientation(VERTICAL);
+//        container.setUseDefaultMargins(true);
+
+        for (int i = 0; i < VERTICAL_ALIGNMENTS.length; i++) {
+            int va = VERTICAL_ALIGNMENTS[i];
+            for (int j = 0; j < HORIZONTAL_ALIGNMENTS.length; j++) {
+                int ha = HORIZONTAL_ALIGNMENTS[j];
+                GridLayout.Group rowGroup = new GridLayout.Group(UNDEFINED, null);
+                GridLayout.Group colGroup = new GridLayout.Group(UNDEFINED, null);
+                GridLayout.LayoutParams lp = new GridLayout.LayoutParams(rowGroup, colGroup);
+                //GridLayout.LayoutParams lp = new GridLayout.LayoutParams();
+                lp.setGravity(va | ha);
+                View v = create(context, VERTICAL_NAMES[i] + "-" + HORIZONTAL_NAMES[j], 20);
+                container.addView(v, lp);
+            }
+        }
+
+        return container;
+    }
+
+    public String tag() {
+        return GridLayoutTest.class.getName();
+    }
+}
diff --git a/tests/GridLayoutTest/src/com/android/test/layout/LinearLayoutTest.java b/tests/GridLayoutTest/src/com/android/test/layout/LinearLayoutTest.java
new file mode 100644
index 0000000..c7f4665
--- /dev/null
+++ b/tests/GridLayoutTest/src/com/android/test/layout/LinearLayoutTest.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.test.layout;
+
+import android.content.Context;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.LinearLayout;
+
+import static android.widget.LinearLayout.*;
+import static android.widget.LinearLayout.LayoutParams.*;
+
+public class LinearLayoutTest extends AbstractLayoutTest {
+    public ViewGroup create(Context context) {
+        LinearLayout container = new LinearLayout(context);
+        container.setOrientation(LinearLayout.VERTICAL);
+
+        for (int i = 0; i < VERTICAL_ALIGNMENTS.length; i++) {
+            int va = VERTICAL_ALIGNMENTS[i];
+            for (int j = 0; j < HORIZONTAL_ALIGNMENTS.length; j++) {
+                int ha = HORIZONTAL_ALIGNMENTS[j];
+                LayoutParams lp = new LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
+                lp.gravity = va | ha;
+                View v = create(context, VERTICAL_NAMES[i] + "-" + HORIZONTAL_NAMES[j], 20);
+                container.addView(v, lp);
+            }
+        }
+
+        return container;
+    }
+
+    public String tag() {
+        return LinearLayoutTest.class.getName();
+    }
+}
diff --git a/tests/HwAccelerationTest/AndroidManifest.xml b/tests/HwAccelerationTest/AndroidManifest.xml
index 01d30eb..c650021 100644
--- a/tests/HwAccelerationTest/AndroidManifest.xml
+++ b/tests/HwAccelerationTest/AndroidManifest.xml
@@ -19,6 +19,7 @@
 
     <uses-permission android:name="android.permission.INTERNET" />
     <uses-permission android:name="android.permission.CAMERA" />
+    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
 
     <uses-feature android:name="android.hardware.camera" />
     <uses-feature android:name="android.hardware.camera.autofocus" />
@@ -30,6 +31,24 @@
         android:hardwareAccelerated="true">
 
         <activity
+                android:name="GetBitmapActivity"
+                android:label="_GetBitmap">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+        
+        <activity
+                android:name="SmallCircleActivity"
+                android:label="_SmallCircle">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+
+        <activity
                 android:name="ClearActivity"
                 android:label="_Clear">
             <intent-filter>
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/ClearActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/ClearActivity.java
index b49db7c5..1c82e9b 100644
--- a/tests/HwAccelerationTest/src/com/android/test/hwui/ClearActivity.java
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/ClearActivity.java
@@ -20,7 +20,6 @@
 import android.content.Context;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
-import android.graphics.BitmapShader;
 import android.graphics.Canvas;
 import android.graphics.Paint;
 import android.graphics.Path;
@@ -79,6 +78,9 @@
                 }
                 canvas.restore();
                 canvas.drawText("OpenGLRenderer", 50.0f, 50.0f, mClearPaint);
+                mClearPaint.setColor(0xff000000);
+                canvas.drawRect(800.0f, 100.0f, 900.0f, 200.0f, mClearPaint);
+                mClearPaint.setColor(0x0000ff00);
             }
             canvas.restore();
         }
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/GLTextureViewActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/GLTextureViewActivity.java
index 7f97098..9bb5ba8 100644
--- a/tests/HwAccelerationTest/src/com/android/test/hwui/GLTextureViewActivity.java
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/GLTextureViewActivity.java
@@ -52,13 +52,7 @@
     }
 
     @Override
-    protected void onDestroy() {
-        super.onDestroy();
-        mRenderThread.finish();
-    }
-
-    @Override
-    public void onSurfaceTextureAvailable(SurfaceTexture surface) {
+    public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
         mRenderThread = new RenderThread(surface);
         mRenderThread.start();
 
@@ -81,6 +75,16 @@
     public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
     }
 
+    @Override
+    public void onSurfaceTextureDestroyed(SurfaceTexture surface) {
+        mRenderThread.finish();
+        try {
+            mRenderThread.join();
+        } catch (InterruptedException e) {
+            Log.e(RenderThread.LOG_TAG, "Could not wait for render thread");
+        }
+    }
+
     private static class RenderThread extends Thread {
         private static final String LOG_TAG = "GLTextureView";
 
@@ -108,26 +112,23 @@
         public void run() {
             initGL();
 
-            float red = 0.0f;
+            float red = 1.0f;
             while (!mFinished) {
                 checkCurrent();
 
+                Log.d(LOG_TAG, "Rendering frame");
+
                 GLES20.glClearColor(red, 0.0f, 0.0f, 1.0f);
-                int error = GLES20.glGetError();
-                if (error != GLES20.GL_NO_ERROR) {
-                    Log.w(LOG_TAG, "GL error = 0x" + Integer.toHexString(error));
-                }
+                checkGlError();
 
                 GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
-                error = GLES20.glGetError();
-                if (error != GLES20.GL_NO_ERROR) {
-                    Log.w(LOG_TAG, "GL error = 0x" + Integer.toHexString(error));
-                }
+                checkGlError();
 
                 if (!mEgl.eglSwapBuffers(mEglDisplay, mEglSurface)) {
                     throw new RuntimeException("Cannot swap buffers");
                 }
-                
+                checkEglError();
+
                 try {
                     Thread.sleep(20);
                 } catch (InterruptedException e) {
@@ -141,6 +142,20 @@
             finishGL();
         }
 
+        private void checkEglError() {
+            int error = mEgl.eglGetError();
+            if (error != EGL10.EGL_SUCCESS) {
+                Log.w(LOG_TAG, "EGL error = 0x" + Integer.toHexString(error));
+            }
+        }
+
+        private void checkGlError() {
+            int error = GLES20.glGetError();
+            if (error != GLES20.GL_NO_ERROR) {
+                Log.w(LOG_TAG, "GL error = 0x" + Integer.toHexString(error));
+            }
+        }
+
         private void finishGL() {
             mEgl.eglDestroyContext(mEglDisplay, mEglContext);
             mEgl.eglDestroySurface(mEglDisplay, mEglSurface);
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/GetBitmapActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/GetBitmapActivity.java
new file mode 100644
index 0000000..2e23aaa
--- /dev/null
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/GetBitmapActivity.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.test.hwui;
+
+import android.app.Activity;
+import android.graphics.Bitmap;
+import android.graphics.SurfaceTexture;
+import android.hardware.Camera;
+import android.os.Bundle;
+import android.os.Environment;
+import android.view.Gravity;
+import android.view.TextureView;
+import android.view.View;
+import android.widget.Button;
+import android.widget.FrameLayout;
+
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+@SuppressWarnings({"UnusedDeclaration"})
+public class GetBitmapActivity extends Activity implements TextureView.SurfaceTextureListener {
+    private Camera mCamera;
+    private TextureView mTextureView;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        FrameLayout content = new FrameLayout(this);
+
+        mTextureView = new TextureView(this);
+        mTextureView.setSurfaceTextureListener(this);
+
+        Button button = new Button(this);
+        button.setText("Copy bitmap to /sdcard/textureview.png");
+        button.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                Bitmap b = mTextureView.getBitmap();
+                try {
+                    FileOutputStream out = new FileOutputStream(
+                            Environment.getExternalStorageDirectory() + "/textureview.png");
+                    try {
+                        b.compress(Bitmap.CompressFormat.PNG, 100, out);
+                    } finally {
+                        try {
+                            out.close();
+                        } catch (IOException e) {
+                            // Ignore
+                        }
+                    }
+                } catch (FileNotFoundException e) {
+                    // Ignore
+                }
+            }
+        });
+
+        content.addView(mTextureView, new FrameLayout.LayoutParams(500, 400, Gravity.CENTER));
+        content.addView(button, new FrameLayout.LayoutParams(
+                FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT,
+                Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM));
+        setContentView(content);
+    }
+
+    @Override
+    public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
+        mCamera = Camera.open();
+
+        try {
+            mCamera.setPreviewTexture(surface);
+        } catch (IOException t) {
+            android.util.Log.e("TextureView", "Cannot set preview texture target!", t);
+        }
+
+        mCamera.startPreview();
+    }
+
+    @Override
+    public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
+        // Ignored, the Camera does all the work for us
+    }
+
+    @Override
+    public void onSurfaceTextureDestroyed(SurfaceTexture surface) {
+        mCamera.stopPreview();
+        mCamera.release();
+    }
+}
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/SmallCircleActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/SmallCircleActivity.java
new file mode 100644
index 0000000..8c02539
--- /dev/null
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/SmallCircleActivity.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.test.hwui;
+
+import android.app.Activity;
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.Path;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.LinearLayout;
+
+@SuppressWarnings({"UnusedDeclaration"})
+public class SmallCircleActivity extends Activity {
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        final LinearLayout layout = new LinearLayout(this);
+        layout.setOrientation(LinearLayout.VERTICAL);
+
+        View view = new PathView(this);
+        layout.addView(view, new LinearLayout.LayoutParams(PathView.SIZE, PathView.SIZE));
+        view = new PathView(this);
+        view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
+        layout.addView(view, new LinearLayout.LayoutParams(PathView.SIZE, PathView.SIZE));
+
+        setContentView(layout);
+    }
+
+    static class PathView extends View {
+        private static final int SIZE = 37;
+        private final Paint mPaint;
+        private final Path mPath;
+
+        PathView(Context c) {
+            super(c);
+
+            mPath = new Path();
+            mPath.addCircle(SIZE * 0.5f, SIZE * 0.5f, SIZE * 0.275f, Path.Direction.CW);
+            mPath.addCircle(SIZE * 0.5f, SIZE * 0.5f, SIZE * 0.225f, Path.Direction.CCW);
+            
+            mPaint = new Paint();
+            mPaint.setAntiAlias(true);
+            mPaint.setColor(0xffffffff);
+        }
+
+        @Override
+        protected void onDraw(Canvas canvas) {
+            super.onDraw(canvas);
+
+            canvas.drawPath(mPath, mPaint);
+        }
+    }
+}
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/TextureViewActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/TextureViewActivity.java
index 2feda57..fa2e39a 100644
--- a/tests/HwAccelerationTest/src/com/android/test/hwui/TextureViewActivity.java
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/TextureViewActivity.java
@@ -16,6 +16,7 @@
 
 package com.android.test.hwui;
 
+import android.animation.AnimatorSet;
 import android.animation.ObjectAnimator;
 import android.animation.ValueAnimator;
 import android.app.Activity;
@@ -25,6 +26,7 @@
 import android.view.Gravity;
 import android.view.TextureView;
 import android.view.View;
+import android.widget.Button;
 import android.widget.FrameLayout;
 
 import java.io.IOException;
@@ -33,27 +35,44 @@
 public class TextureViewActivity extends Activity implements TextureView.SurfaceTextureListener {
     private Camera mCamera;
     private TextureView mTextureView;
+    private FrameLayout mContent;
+    private AnimatorSet mAnimatorSet;
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
 
+        mContent = new FrameLayout(this);
+
         mTextureView = new TextureView(this);
         mTextureView.setSurfaceTextureListener(this);
 
-        setContentView(mTextureView, new FrameLayout.LayoutParams(500, 400, Gravity.CENTER));
+        Button button = new Button(this);
+        button.setText("Remove/Add");
+        button.setOnClickListener(new View.OnClickListener() {
+            private boolean mAdded = true;
+
+            @Override
+            public void onClick(View v) {
+                if (mAdded) {
+                    mAnimatorSet.cancel();
+                    mContent.removeView(mTextureView);
+                } else {
+                    mContent.addView(mTextureView);
+                }
+                mAdded = !mAdded;
+            }
+        });
+
+        mContent.addView(mTextureView, new FrameLayout.LayoutParams(500, 400, Gravity.CENTER));
+        mContent.addView(button, new FrameLayout.LayoutParams(
+                FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT,
+                Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM));
+        setContentView(mContent);
     }
 
     @Override
-    protected void onDestroy() {
-        super.onDestroy();
-
-        mCamera.stopPreview();
-        mCamera.release();
-    }
-
-    @Override
-    public void onSurfaceTextureAvailable(SurfaceTexture surface) {
+    public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
         mCamera = Camera.open();
 
         try {
@@ -66,27 +85,35 @@
 
         mTextureView.setCameraDistance(5000);
 
-        ObjectAnimator animator = ObjectAnimator.ofFloat(mTextureView, "rotationY", 0.0f, 360.0f);
-        animator.setRepeatMode(ObjectAnimator.REVERSE);
-        animator.setRepeatCount(ObjectAnimator.INFINITE);
-        animator.setDuration(4000);
-        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
+        ObjectAnimator rotationY = ObjectAnimator.ofFloat(mTextureView, "rotationY", 0.0f, 360.0f);
+        rotationY.setRepeatMode(ObjectAnimator.REVERSE);
+        rotationY.setRepeatCount(ObjectAnimator.INFINITE);
+        rotationY.setDuration(4000);
+        rotationY.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
             @Override
             public void onAnimationUpdate(ValueAnimator animation) {
                 ((View) mTextureView.getParent()).invalidate();
             }
         });
-        animator.start();
 
-        animator = ObjectAnimator.ofFloat(mTextureView, "alpha", 1.0f, 0.0f);
-        animator.setRepeatMode(ObjectAnimator.REVERSE);
-        animator.setRepeatCount(ObjectAnimator.INFINITE);
-        animator.setDuration(4000);
-        animator.start();
+        ObjectAnimator alpha = ObjectAnimator.ofFloat(mTextureView, "alpha", 1.0f, 0.0f);
+        alpha.setRepeatMode(ObjectAnimator.REVERSE);
+        alpha.setRepeatCount(ObjectAnimator.INFINITE);
+        alpha.setDuration(4000);
+
+        mAnimatorSet = new AnimatorSet();
+        mAnimatorSet.play(alpha).with(rotationY);
+        mAnimatorSet.start();
     }
 
     @Override
     public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
         // Ignored, the Camera does all the work for us
     }
+
+    @Override
+    public void onSurfaceTextureDestroyed(SurfaceTexture surface) {
+        mCamera.stopPreview();
+        mCamera.release();
+    }
 }
diff --git a/tests/RenderScriptTests/FBOTest/AndroidManifest.xml b/tests/RenderScriptTests/FBOTest/AndroidManifest.xml
index c2e0cc6..788e856 100644
--- a/tests/RenderScriptTests/FBOTest/AndroidManifest.xml
+++ b/tests/RenderScriptTests/FBOTest/AndroidManifest.xml
@@ -3,11 +3,20 @@
     package="com.android.fbotest">
     <application android:label="_FBOTest">
         <activity android:name="FBOTest"
+                  android:label="FBO Base Test"
                   android:theme="@android:style/Theme.Black.NoTitleBar">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
-        </activity>        
+        </activity>
+        <activity android:name="FBOSync"
+                  android:label="FBO Sync Test"
+                  android:theme="@android:style/Theme.Black.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/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/FBOSync.java b/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/FBOSync.java
new file mode 100644
index 0000000..d30ad7e
--- /dev/null
+++ b/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/FBOSync.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.fbotest;
+
+import android.renderscript.RSSurfaceView;
+import android.renderscript.RenderScript;
+
+import android.app.Activity;
+import android.content.res.Configuration;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.Message;
+import android.provider.Settings.System;
+import android.util.Log;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.MenuInflater;
+import android.view.Window;
+import android.widget.Button;
+import android.widget.ListView;
+import android.net.Uri;
+
+import java.lang.Runtime;
+
+public class FBOSync extends Activity {
+
+    private FBOSyncView mView;
+
+    @Override
+    public void onCreate(Bundle icicle) {
+        super.onCreate(icicle);
+
+        // Create our Preview view and set it as the content of our
+        // Activity
+        mView = new FBOSyncView(this);
+        setContentView(mView);
+    }
+
+    @Override
+    protected void onResume() {
+        // Ideally a game should implement onResume() and onPause()
+        // to take appropriate action when the activity looses focus
+        super.onResume();
+        mView.resume();
+    }
+
+    @Override
+    protected void onPause() {
+        // Ideally a game should implement onResume() and onPause()
+        // to take appropriate action when the activity looses focus
+        super.onPause();
+        mView.pause();
+    }
+}
+
diff --git a/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/FBOSyncRS.java b/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/FBOSyncRS.java
new file mode 100644
index 0000000..57a117c
--- /dev/null
+++ b/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/FBOSyncRS.java
@@ -0,0 +1,213 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.fbotest;
+
+import java.io.Writer;
+
+import android.content.res.Resources;
+import android.renderscript.*;
+import android.renderscript.Element.DataType;
+import android.renderscript.Element.DataKind;
+import android.renderscript.ProgramStore.DepthFunc;
+import android.renderscript.Type.Builder;
+import android.util.Log;
+
+
+public class FBOSyncRS {
+
+    public FBOSyncRS() {
+    }
+
+    public void init(RenderScriptGL rs, Resources res) {
+        mRS = rs;
+        mRes = res;
+        initRS();
+    }
+
+    public void surfaceChanged() {
+        mRS.getWidth();
+        mRS.getHeight();
+    }
+
+    private Resources mRes;
+    private RenderScriptGL mRS;
+    private Sampler mSampler;
+    private ProgramStore mPSBackground;
+    private ProgramFragment mPFBackground;
+    private ProgramVertex mPVBackground;
+    private ProgramVertexFixedFunction.Constants mPVA;
+
+    private Allocation mGridImage;
+    private Allocation mOffscreen;
+    private Allocation mOffscreenDepth;
+    private Allocation mAllocPV;
+    private Allocation mReadBackTest;
+
+    private Font mItalic;
+    private Allocation mTextAlloc;
+
+    private ScriptField_MeshInfo mMeshes;
+    private ScriptC_fbosync mScript;
+
+
+    public void onActionDown(float x, float y) {
+        mScript.invoke_onActionDown(x, y);
+    }
+
+    public void onActionScale(float scale) {
+        mScript.invoke_onActionScale(scale);
+    }
+
+    public void onActionMove(float x, float y) {
+        mScript.invoke_onActionMove(x, y);
+    }
+
+    private void initPFS() {
+        ProgramStore.Builder b = new ProgramStore.Builder(mRS);
+
+        b.setDepthFunc(ProgramStore.DepthFunc.LESS);
+        b.setDitherEnabled(false);
+        b.setDepthMaskEnabled(true);
+        mPSBackground = b.create();
+
+        mScript.set_gPFSBackground(mPSBackground);
+    }
+
+    private void initPF() {
+        Sampler.Builder bs = new Sampler.Builder(mRS);
+        bs.setMinification(Sampler.Value.LINEAR);
+        bs.setMagnification(Sampler.Value.LINEAR);
+        bs.setWrapS(Sampler.Value.CLAMP);
+        bs.setWrapT(Sampler.Value.CLAMP);
+        mSampler = bs.create();
+
+        ProgramFragmentFixedFunction.Builder b = new ProgramFragmentFixedFunction.Builder(mRS);
+        b.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE,
+                     ProgramFragmentFixedFunction.Builder.Format.RGBA, 0);
+        mPFBackground = b.create();
+        mPFBackground.bindSampler(mSampler, 0);
+
+        mScript.set_gPFBackground(mPFBackground);
+    }
+
+    private void initPV() {
+        ProgramVertexFixedFunction.Builder pvb = new ProgramVertexFixedFunction.Builder(mRS);
+        mPVBackground = pvb.create();
+
+        mPVA = new ProgramVertexFixedFunction.Constants(mRS);
+        ((ProgramVertexFixedFunction)mPVBackground).bindConstants(mPVA);
+
+        mScript.set_gPVBackground(mPVBackground);
+    }
+
+    private void loadImage() {
+        mGridImage = Allocation.createFromBitmapResource(mRS, mRes, R.drawable.robot,
+                                                         Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
+                                                         Allocation.USAGE_GRAPHICS_TEXTURE);
+        mScript.set_gTGrid(mGridImage);
+    }
+
+    private void initTextAllocation(String fileName) {
+        String allocString = "Displaying file: " + fileName;
+        mTextAlloc = Allocation.createFromString(mRS, allocString, Allocation.USAGE_SCRIPT);
+        mScript.set_gTextAlloc(mTextAlloc);
+    }
+
+    private void initMeshes(FileA3D model) {
+        int numEntries = model.getIndexEntryCount();
+        int numMeshes = 0;
+        for (int i = 0; i < numEntries; i ++) {
+            FileA3D.IndexEntry entry = model.getIndexEntry(i);
+            if (entry != null && entry.getEntryType() == FileA3D.EntryType.MESH) {
+                numMeshes ++;
+            }
+        }
+
+        if (numMeshes > 0) {
+            mMeshes = new ScriptField_MeshInfo(mRS, numMeshes);
+
+            for (int i = 0; i < numEntries; i ++) {
+                FileA3D.IndexEntry entry = model.getIndexEntry(i);
+                if (entry != null && entry.getEntryType() == FileA3D.EntryType.MESH) {
+                    Mesh mesh = entry.getMesh();
+                    mMeshes.set_mMesh(i, mesh, false);
+                    mMeshes.set_mNumIndexSets(i, mesh.getPrimitiveCount(), false);
+                }
+            }
+            mMeshes.copyAll();
+        } else {
+            throw new RSRuntimeException("No valid meshes in file");
+        }
+
+        mScript.bind_gMeshes(mMeshes);
+        mScript.invoke_updateMeshInfo();
+    }
+
+    public void loadA3DFile(String path) {
+        FileA3D model = FileA3D.createFromFile(mRS, path);
+        initMeshes(model);
+        initTextAllocation(path);
+    }
+
+    private void initRS() {
+
+        mScript = new ScriptC_fbosync(mRS, mRes, R.raw.fbosync);
+
+        initPFS();
+        initPF();
+        initPV();
+
+        loadImage();
+
+        Type.Builder b = new Type.Builder(mRS, Element.RGBA_8888(mRS));
+        b.setX(512).setY(512);
+        mOffscreen = Allocation.createTyped(mRS,
+                                            b.create(),
+                                            Allocation.USAGE_SCRIPT |
+                                            Allocation.USAGE_GRAPHICS_TEXTURE |
+                                            Allocation.USAGE_GRAPHICS_RENDER_TARGET);
+        mScript.set_gOffscreen(mOffscreen);
+
+        mReadBackTest = Allocation.createTyped(mRS,
+                                               b.create(),
+                                               Allocation.USAGE_SCRIPT |
+                                               Allocation.USAGE_GRAPHICS_TEXTURE);
+        mScript.set_gReadBackTest(mReadBackTest);
+
+        b = new Type.Builder(mRS,
+                             Element.createPixel(mRS, DataType.UNSIGNED_16,
+                             DataKind.PIXEL_DEPTH));
+        b.setX(512).setY(512);
+        mOffscreenDepth = Allocation.createTyped(mRS,
+                                                 b.create(),
+                                                 Allocation.USAGE_GRAPHICS_RENDER_TARGET);
+        mScript.set_gOffscreenDepth(mOffscreenDepth);
+
+        FileA3D model = FileA3D.createFromResource(mRS, mRes, R.raw.robot);
+        initMeshes(model);
+
+        mItalic = Font.create(mRS, mRes, "serif", Font.Style.ITALIC, 8);
+        mScript.set_gItalic(mItalic);
+
+        initTextAllocation("R.raw.robot");
+
+        mRS.bindRootScript(mScript);
+    }
+}
+
+
+
diff --git a/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/FBOSyncView.java b/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/FBOSyncView.java
new file mode 100644
index 0000000..6a85628
--- /dev/null
+++ b/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/FBOSyncView.java
@@ -0,0 +1,144 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.fbotest;
+
+import android.renderscript.RSSurfaceView;
+import android.renderscript.RenderScriptGL;
+
+import android.content.Context;
+import android.view.MotionEvent;
+import android.view.SurfaceHolder;
+import android.view.ScaleGestureDetector;
+import android.util.Log;
+
+public class FBOSyncView extends RSSurfaceView {
+
+    private RenderScriptGL mRS;
+    private FBOSyncRS mRender;
+
+    private ScaleGestureDetector mScaleDetector;
+
+    private static final int INVALID_POINTER_ID = -1;
+    private int mActivePointerId = INVALID_POINTER_ID;
+
+    public FBOSyncView(Context context) {
+        super(context);
+        ensureRenderScript();
+        mScaleDetector = new ScaleGestureDetector(context, new ScaleListener());
+    }
+
+    private void ensureRenderScript() {
+        if (mRS == null) {
+            RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
+            sc.setDepth(16, 24);
+            mRS = createRenderScriptGL(sc);
+            mRender = new FBOSyncRS();
+            mRender.init(mRS, getResources());
+        }
+    }
+
+    @Override
+    protected void onAttachedToWindow() {
+        super.onAttachedToWindow();
+        ensureRenderScript();
+    }
+
+    @Override
+    public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
+        super.surfaceChanged(holder, format, w, h);
+        mRender.surfaceChanged();
+    }
+
+    @Override
+    protected void onDetachedFromWindow() {
+        mRender = null;
+        if (mRS != null) {
+            mRS = null;
+            destroyRenderScriptGL();
+        }
+    }
+
+    public void loadA3DFile(String path) {
+        mRender.loadA3DFile(path);
+    }
+
+    @Override
+    public boolean onTouchEvent(MotionEvent ev) {
+        mScaleDetector.onTouchEvent(ev);
+
+        boolean ret = false;
+        float x = ev.getX();
+        float y = ev.getY();
+
+        final int action = ev.getAction();
+
+        switch (action & MotionEvent.ACTION_MASK) {
+        case MotionEvent.ACTION_DOWN: {
+            mRender.onActionDown(x, y);
+            mActivePointerId = ev.getPointerId(0);
+            ret = true;
+            break;
+        }
+        case MotionEvent.ACTION_MOVE: {
+            if (!mScaleDetector.isInProgress()) {
+                mRender.onActionMove(x, y);
+            }
+            mRender.onActionDown(x, y);
+            ret = true;
+            break;
+        }
+
+        case MotionEvent.ACTION_UP: {
+            mActivePointerId = INVALID_POINTER_ID;
+            break;
+        }
+
+        case MotionEvent.ACTION_CANCEL: {
+            mActivePointerId = INVALID_POINTER_ID;
+            break;
+        }
+
+        case MotionEvent.ACTION_POINTER_UP: {
+            final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK)
+                    >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
+            final int pointerId = ev.getPointerId(pointerIndex);
+            if (pointerId == mActivePointerId) {
+                // This was our active pointer going up. Choose a new
+                // active pointer and adjust accordingly.
+                final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
+                x = ev.getX(newPointerIndex);
+                y = ev.getY(newPointerIndex);
+                mRender.onActionDown(x, y);
+                mActivePointerId = ev.getPointerId(newPointerIndex);
+            }
+            break;
+        }
+        }
+
+        return ret;
+    }
+
+    private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
+        @Override
+        public boolean onScale(ScaleGestureDetector detector) {
+            mRender.onActionScale(detector.getScaleFactor());
+            return true;
+        }
+    }
+}
+
+
diff --git a/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/fbosync.rs b/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/fbosync.rs
new file mode 100644
index 0000000..b77ccb4
--- /dev/null
+++ b/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/fbosync.rs
@@ -0,0 +1,233 @@
+// Copyright (C) 2011 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#pragma version(1)
+
+#pragma rs java_package_name(com.android.fbotest)
+
+#include "rs_graphics.rsh"
+
+rs_program_vertex gPVBackground;
+rs_program_fragment gPFBackground;
+
+rs_allocation gTGrid;
+
+rs_program_store gPFSBackground;
+
+rs_font gItalic;
+rs_allocation gTextAlloc;
+
+rs_allocation gOffscreen;
+rs_allocation gOffscreenDepth;
+rs_allocation gReadBackTest;
+
+typedef struct MeshInfo {
+    rs_mesh mMesh;
+    int mNumIndexSets;
+    float3 bBoxMin;
+    float3 bBoxMax;
+} MeshInfo_t;
+
+MeshInfo_t *gMeshes;
+
+static float3 gLookAt;
+
+static float gRotateX;
+static float gRotateY;
+static float gZoom;
+
+static float gLastX;
+static float gLastY;
+
+void onActionDown(float x, float y) {
+    gLastX = x;
+    gLastY = y;
+}
+
+void onActionScale(float scale) {
+
+    gZoom *= 1.0f / scale;
+    gZoom = max(0.1f, min(gZoom, 500.0f));
+}
+
+void onActionMove(float x, float y) {
+    float dx = gLastX - x;
+    float dy = gLastY - y;
+
+    if (fabs(dy) <= 2.0f) {
+        dy = 0.0f;
+    }
+    if (fabs(dx) <= 2.0f) {
+        dx = 0.0f;
+    }
+
+    gRotateY -= dx;
+    if (gRotateY > 360) {
+        gRotateY -= 360;
+    }
+    if (gRotateY < 0) {
+        gRotateY += 360;
+    }
+
+    gRotateX -= dy;
+    gRotateX = min(gRotateX, 80.0f);
+    gRotateX = max(gRotateX, -80.0f);
+
+    gLastX = x;
+    gLastY = y;
+}
+
+void init() {
+    gRotateX = 0.0f;
+    gRotateY = 0.0f;
+    gZoom = 50.0f;
+    gLookAt = 0.0f;
+}
+
+void updateMeshInfo() {
+    rs_allocation allMeshes = rsGetAllocation(gMeshes);
+    int size = rsAllocationGetDimX(allMeshes);
+    gLookAt = 0.0f;
+    float minX, minY, minZ, maxX, maxY, maxZ;
+    for (int i = 0; i < size; i++) {
+        MeshInfo_t *info = (MeshInfo_t*)rsGetElementAt(allMeshes, i);
+        rsgMeshComputeBoundingBox(info->mMesh,
+                                  &minX, &minY, &minZ,
+                                  &maxX, &maxY, &maxZ);
+        info->bBoxMin = (minX, minY, minZ);
+        info->bBoxMax = (maxX, maxY, maxZ);
+        gLookAt += (info->bBoxMin + info->bBoxMax)*0.5f;
+    }
+    gLookAt = gLookAt / (float)size;
+}
+
+static void renderAllMeshes() {
+    rs_allocation allMeshes = rsGetAllocation(gMeshes);
+    int size = rsAllocationGetDimX(allMeshes);
+    gLookAt = 0.0f;
+    float minX, minY, minZ, maxX, maxY, maxZ;
+    for (int i = 0; i < size; i++) {
+        MeshInfo_t *info = (MeshInfo_t*)rsGetElementAt(allMeshes, i);
+        rsgDrawMesh(info->mMesh);
+    }
+}
+
+static void drawDescription() {
+    uint width = rsgGetWidth();
+    uint height = rsgGetHeight();
+    int left = 0, right = 0, top = 0, bottom = 0;
+
+    rsgBindFont(gItalic);
+
+    rsgMeasureText(gTextAlloc, &left, &right, &top, &bottom);
+    rsgDrawText(gTextAlloc, 2 -left, height - 2 + bottom);
+}
+
+static void renderOffscreen(bool useDepth) {
+
+    rsgBindColorTarget(gOffscreen, 0);
+    if (useDepth) {
+        rsgBindDepthTarget(gOffscreenDepth);
+        rsgClearDepth(1.0f);
+    } else {
+        rsgClearDepthTarget();
+    }
+    rsgClearColor(0.8f, 0.0f, 0.0f, 1.0f);
+
+    rsgBindProgramVertex(gPVBackground);
+    rs_matrix4x4 proj;
+    float aspect = (float)rsAllocationGetDimX(gOffscreen) / (float)rsAllocationGetDimY(gOffscreen);
+    rsMatrixLoadPerspective(&proj, 30.0f, aspect, 1.0f, 100.0f);
+    rsgProgramVertexLoadProjectionMatrix(&proj);
+
+    rsgBindProgramFragment(gPFBackground);
+    rsgBindProgramStore(gPFSBackground);
+    rsgBindTexture(gPFBackground, 0, gTGrid);
+
+    rs_matrix4x4 matrix;
+    rsMatrixLoadIdentity(&matrix);
+    // Position our models on the screen
+    rsMatrixTranslate(&matrix, gLookAt.x, gLookAt.y, gLookAt.z - gZoom);
+    rsMatrixRotate(&matrix, gRotateX, 1.0f, 0.0f, 0.0f);
+    rsMatrixRotate(&matrix, gRotateY, 0.0f, 1.0f, 0.0f);
+    rsgProgramVertexLoadModelMatrix(&matrix);
+
+    renderAllMeshes();
+
+    // Render into the frambuffer
+    rsgClearAllRenderTargets();
+}
+
+static void drawOffscreenResult(int posX, int posY, rs_allocation texture) {
+    // display the result
+    rs_matrix4x4 proj, matrix;
+    rsMatrixLoadOrtho(&proj, 0, rsgGetWidth(), rsgGetHeight(), 0, -500, 500);
+    rsgProgramVertexLoadProjectionMatrix(&proj);
+    rsMatrixLoadIdentity(&matrix);
+    rsgProgramVertexLoadModelMatrix(&matrix);
+    rsgBindTexture(gPFBackground, 0, texture);
+    float startX = posX, startY = posY;
+    float width = 256, height = 256;
+    rsgDrawQuadTexCoords(startX, startY, 0, 0, 1,
+                         startX, startY + height, 0, 0, 0,
+                         startX + width, startY + height, 0, 1, 0,
+                         startX + width, startY, 0, 1, 1);
+}
+
+int root(void) {
+
+    rsgClearColor(1.0f, 1.0f, 1.0f, 1.0f);
+    rsgClearDepth(1.0f);
+
+    renderOffscreen(true);
+    drawOffscreenResult(0, 0, gOffscreen);
+
+
+    uint32_t w = rsAllocationGetDimX(gOffscreen);
+    uint32_t h = rsAllocationGetDimY(gOffscreen);
+    uint32_t numElements = w*h;
+
+    rsgAllocationSyncAll(gOffscreen, RS_ALLOCATION_USAGE_GRAPHICS_RENDER_TARGET);
+
+    rsAllocationCopy2DRange(gReadBackTest, 0, 0, 0,
+                            RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X, w, h,
+                            gOffscreen, 0, 0, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X);
+
+    rsgAllocationSyncAll(gReadBackTest);
+    drawOffscreenResult(0, 300, gReadBackTest);
+
+    rsgBindProgramVertex(gPVBackground);
+    rs_matrix4x4 proj;
+    float aspect = (float)rsgGetWidth() / (float)rsgGetHeight();
+    rsMatrixLoadPerspective(&proj, 30.0f, aspect, 1.0f, 100.0f);
+    rsgProgramVertexLoadProjectionMatrix(&proj);
+
+    rsgBindProgramFragment(gPFBackground);
+    rsgBindProgramStore(gPFSBackground);
+    rsgBindTexture(gPFBackground, 0, gTGrid);
+
+    rs_matrix4x4 matrix;
+    rsMatrixLoadIdentity(&matrix);
+    // Position our models on the screen
+    rsMatrixTranslate(&matrix, gLookAt.x, gLookAt.y, gLookAt.z - gZoom);
+    rsMatrixRotate(&matrix, gRotateX, 1.0f, 0.0f, 0.0f);
+    rsMatrixRotate(&matrix, gRotateY, 0.0f, 1.0f, 0.0f);
+    rsgProgramVertexLoadModelMatrix(&matrix);
+
+    renderAllMeshes();
+
+    drawDescription();
+
+    return 0;
+}
diff --git a/tests/RenderScriptTests/PerfTest/res/drawable/flares.png b/tests/RenderScriptTests/PerfTest/res/drawable/flares.png
new file mode 100644
index 0000000..3a5c970
--- /dev/null
+++ b/tests/RenderScriptTests/PerfTest/res/drawable/flares.png
Binary files differ
diff --git a/tests/RenderScriptTests/PerfTest/res/drawable/globe.png b/tests/RenderScriptTests/PerfTest/res/drawable/globe.png
new file mode 100755
index 0000000..f9d6172
--- /dev/null
+++ b/tests/RenderScriptTests/PerfTest/res/drawable/globe.png
Binary files differ
diff --git a/tests/RenderScriptTests/PerfTest/res/drawable/light1.jpg b/tests/RenderScriptTests/PerfTest/res/drawable/light1.jpg
new file mode 100644
index 0000000..2f2f10e
--- /dev/null
+++ b/tests/RenderScriptTests/PerfTest/res/drawable/light1.jpg
Binary files differ
diff --git a/tests/RenderScriptTests/PerfTest/res/drawable/space.jpg b/tests/RenderScriptTests/PerfTest/res/drawable/space.jpg
new file mode 100644
index 0000000..b61f6a3
--- /dev/null
+++ b/tests/RenderScriptTests/PerfTest/res/drawable/space.jpg
Binary files differ
diff --git a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBenchRS.java b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBenchRS.java
index 5377f12..3f57799 100644
--- a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBenchRS.java
+++ b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBenchRS.java
@@ -38,13 +38,20 @@
 import android.renderscript.ProgramStore.BlendDstFunc;
 import android.renderscript.RenderScript.RSMessageHandler;
 import android.renderscript.Sampler.Value;
+import android.renderscript.Mesh.Primitive;
+import android.renderscript.Matrix4f;
+import android.renderscript.ProgramVertexFixedFunction;
+
 import android.util.Log;
 
 
 public class RsBenchRS {
 
     private static final String TAG = "RsBenchRS";
-
+    private static final String SAMPLE_TEXT = "Bench Test";
+    private static final String LIST_TEXT =
+      "This is a sample list of text to show in the list view";
+    private static int PARTICLES_COUNT = 12000;
     int mWidth;
     int mHeight;
     int mLoops;
@@ -81,6 +88,7 @@
     private Sampler mLinearWrap;
     private Sampler mMipLinearWrap;
     private Sampler mNearestClamp;
+    private Sampler mNearesWrap;
 
     private ProgramStore mProgStoreBlendNoneDepth;
     private ProgramStore mProgStoreBlendNone;
@@ -105,6 +113,7 @@
     private ScriptField_VertexShaderConstants3_s mVSConstPixel;
     private ScriptField_FragentShaderConstants3_s mFSConstPixel;
 
+
     private ProgramRaster mCullBack;
     private ProgramRaster mCullFront;
     private ProgramRaster mCullNone;
@@ -113,16 +122,25 @@
     private Allocation mTexOpaque;
     private Allocation mTexTransparent;
     private Allocation mTexChecker;
+    private Allocation mTexGlobe;
 
     private Mesh m10by10Mesh;
     private Mesh m100by100Mesh;
     private Mesh mWbyHMesh;
     private Mesh mTorus;
+    private Mesh mSingleMesh;
+    private Mesh mParticlesMesh;
 
     Font mFontSans;
     Font mFontSerif;
     private Allocation mTextAlloc;
 
+    private ScriptField_ListAllocs_s mTextureAllocs;
+    private ScriptField_ListAllocs_s mSampleTextAllocs;
+    private ScriptField_ListAllocs_s mSampleListViewAllocs;
+    private ScriptField_VpConsts mPvStarAlloc;
+
+
     private ScriptC_rsbench mScript;
 
     private final BitmapFactory.Options mOptionsARGB = new BitmapFactory.Options();
@@ -253,6 +271,27 @@
         return tmb.create(true);
     }
 
+    /**
+     * Create a mesh with a single quad for the given width and height.
+     */
+    private Mesh getSingleMesh(float width, float height) {
+        Mesh.TriangleMeshBuilder tmb = new Mesh.TriangleMeshBuilder(mRS,
+                                           2, Mesh.TriangleMeshBuilder.TEXTURE_0);
+        float xOffset = width/2;
+        float yOffset = height/2;
+        tmb.setTexture(0, 0);
+        tmb.addVertex(-1.0f * xOffset, -1.0f * yOffset);
+        tmb.setTexture(1, 0);
+        tmb.addVertex(xOffset, -1.0f * yOffset);
+        tmb.setTexture(1, 1);
+        tmb.addVertex(xOffset, yOffset);
+        tmb.setTexture(0, 1);
+        tmb.addVertex(-1.0f * xOffset, yOffset);
+        tmb.addTriangle(0, 3, 1);
+        tmb.addTriangle(1, 3, 2);
+        return tmb.create(true);
+    }
+
     private void initProgramStore() {
         // Use stock the stock program store object
         mProgStoreBlendNoneDepth = ProgramStore.BLEND_NONE_DEPTH_TEST(mRS);
@@ -273,6 +312,15 @@
         mScript.set_gProgStoreBlendNone(mProgStoreBlendNone);
         mScript.set_gProgStoreBlendAlpha(mProgStoreBlendAlpha);
         mScript.set_gProgStoreBlendAdd(mProgStoreBlendAdd);
+
+        // For GALAXY
+        builder = new ProgramStore.Builder(mRS);
+        builder.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ZERO);
+        mRS.bindProgramStore(builder.create());
+
+        builder.setBlendFunc(BlendSrcFunc.SRC_ALPHA, BlendDstFunc.ONE);
+        mScript.set_gPSLights(builder.create());
+
     }
 
     private void initProgramFragment() {
@@ -289,8 +337,59 @@
 
         mScript.set_gProgFragmentColor(mProgFragmentColor);
         mScript.set_gProgFragmentTexture(mProgFragmentTexture);
+
+
+        // For Galaxy live wallpaper drawing
+        ProgramFragmentFixedFunction.Builder builder = new ProgramFragmentFixedFunction.Builder(mRS);
+        builder.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE,
+                           ProgramFragmentFixedFunction.Builder.Format.RGB, 0);
+        ProgramFragment pfb = builder.create();
+        pfb.bindSampler(mNearesWrap, 0);
+        mScript.set_gPFBackground(pfb);
+
+        builder = new ProgramFragmentFixedFunction.Builder(mRS);
+        builder.setPointSpriteTexCoordinateReplacement(true);
+        builder.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.MODULATE,
+                           ProgramFragmentFixedFunction.Builder.Format.RGBA, 0);
+        builder.setVaryingColor(true);
+        ProgramFragment pfs = builder.create();
+        pfs.bindSampler(mMipLinearWrap, 0);
+        mScript.set_gPFStars(pfs);
+
     }
 
+    private Matrix4f getProjectionNormalized(int w, int h) {
+      // range -1,1 in the narrow axis at z = 0.
+      Matrix4f m1 = new Matrix4f();
+      Matrix4f m2 = new Matrix4f();
+
+      if(w > h) {
+          float aspect = ((float)w) / h;
+          m1.loadFrustum(-aspect,aspect,  -1,1,  1,100);
+      } else {
+          float aspect = ((float)h) / w;
+          m1.loadFrustum(-1,1, -aspect,aspect, 1,100);
+      }
+
+      m2.loadRotate(180, 0, 1, 0);
+      m1.loadMultiply(m1, m2);
+
+      m2.loadScale(-2, 2, 1);
+      m1.loadMultiply(m1, m2);
+
+      m2.loadTranslate(0, 0, 2);
+      m1.loadMultiply(m1, m2);
+      return m1;
+  }
+
+    private void updateProjectionMatrices() {
+      Matrix4f projNorm = getProjectionNormalized(mBenchmarkDimX, mBenchmarkDimY);
+      ScriptField_VpConsts.Item i = new ScriptField_VpConsts.Item();
+      i.Proj = projNorm;
+      i.MVP = projNorm;
+      mPvStarAlloc.set(i, 0, true);
+  }
+
     private void initProgramVertex() {
         ProgramVertexFixedFunction.Builder pvb = new ProgramVertexFixedFunction.Builder(mRS);
         mProgVertex = pvb.create();
@@ -302,6 +401,39 @@
         mPVA.setProjection(proj);
 
         mScript.set_gProgVertex(mProgVertex);
+
+        // For galaxy live wallpaper
+        mPvStarAlloc = new ScriptField_VpConsts(mRS, 1);
+        mScript.bind_vpConstants(mPvStarAlloc);
+        updateProjectionMatrices();
+
+        ProgramVertex.Builder sb = new ProgramVertex.Builder(mRS);
+        String t =  "varying vec4 varColor;\n" +
+                    "varying vec2 varTex0;\n" +
+                    "void main() {\n" +
+                    "  float dist = ATTRIB_position.y;\n" +
+                    "  float angle = ATTRIB_position.x;\n" +
+                    "  float x = dist * sin(angle);\n" +
+                    "  float y = dist * cos(angle) * 0.892;\n" +
+                    "  float p = dist * 5.5;\n" +
+                    "  float s = cos(p);\n" +
+                    "  float t = sin(p);\n" +
+                    "  vec4 pos;\n" +
+                    "  pos.x = t * x + s * y;\n" +
+                    "  pos.y = s * x - t * y;\n" +
+                    "  pos.z = ATTRIB_position.z;\n" +
+                    "  pos.w = 1.0;\n" +
+                    "  gl_Position = UNI_MVP * pos;\n" +
+                    "  gl_PointSize = ATTRIB_color.a * 10.0;\n" +
+                    "  varColor.rgb = ATTRIB_color.rgb;\n" +
+                    "  varColor.a = 1.0;\n" +
+                    "}\n";
+        sb.setShader(t);
+        sb.addInput(mParticlesMesh.getVertexAllocation(0).getType().getElement());
+        sb.addConstant(mPvStarAlloc.getType());
+        ProgramVertex pvs = sb.create();
+        pvs.bindConstants(mPvStarAlloc.getAllocation(), 0);
+        mScript.set_gPVStars(pvs);
     }
 
     private void initCustomShaders() {
@@ -392,11 +524,18 @@
         mTexOpaque = loadTextureRGB(R.drawable.data);
         mTexTransparent = loadTextureARGB(R.drawable.leaf);
         mTexChecker = loadTextureRGB(R.drawable.checker);
+        mTexGlobe = loadTextureRGB(R.drawable.globe);
 
         mScript.set_gTexTorus(mTexTorus);
         mScript.set_gTexOpaque(mTexOpaque);
         mScript.set_gTexTransparent(mTexTransparent);
         mScript.set_gTexChecker(mTexChecker);
+        mScript.set_gTexGlobe(mTexGlobe);
+
+        // For Galaxy live wallpaper
+        mScript.set_gTSpace(loadTextureRGB(R.drawable.space));
+        mScript.set_gTLight1(loadTextureRGB(R.drawable.light1));
+        mScript.set_gTFlares(loadTextureARGB(R.drawable.flares));
     }
 
     private void initFonts() {
@@ -411,6 +550,19 @@
         mScript.set_gFontSerif(mFontSerif);
     }
 
+    private void createParticlesMesh() {
+        ScriptField_Particle p = new ScriptField_Particle(mRS, PARTICLES_COUNT);
+
+        final Mesh.AllocationBuilder meshBuilder = new Mesh.AllocationBuilder(mRS);
+        meshBuilder.addVertexAllocation(p.getAllocation());
+        final int vertexSlot = meshBuilder.getCurrentVertexTypeIndex();
+        meshBuilder.addIndexSetType(Primitive.POINT);
+        mParticlesMesh = meshBuilder.create();
+
+        mScript.set_gParticlesMesh(mParticlesMesh);
+        mScript.bind_Particles(p);
+    }
+
     private void initMesh() {
         m10by10Mesh = getMbyNMesh(mBenchmarkDimX, mBenchmarkDimY, 10, 10);
         mScript.set_g10by10Mesh(m10by10Mesh);
@@ -418,6 +570,8 @@
         mScript.set_g100by100Mesh(m100by100Mesh);
         mWbyHMesh= getMbyNMesh(mBenchmarkDimX, mBenchmarkDimY, mBenchmarkDimX/4, mBenchmarkDimY/4);
         mScript.set_gWbyHMesh(mWbyHMesh);
+        mSingleMesh = getSingleMesh(1, 1);  // a unit size mesh
+        mScript.set_gSingleMesh(mSingleMesh);
 
         FileA3D model = FileA3D.createFromResource(mRS, mRes, R.raw.torus);
         FileA3D.IndexEntry entry = model.getIndexEntry(0);
@@ -427,6 +581,8 @@
             mTorus = (Mesh)entry.getObject();
             mScript.set_gTorusMesh(mTorus);
         }
+
+        createParticlesMesh();
     }
 
     private void initSamplers() {
@@ -440,6 +596,7 @@
         mLinearClamp = Sampler.CLAMP_LINEAR(mRS);
         mNearestClamp = Sampler.CLAMP_NEAREST(mRS);
         mMipLinearWrap = Sampler.WRAP_LINEAR_MIP_LINEAR(mRS);
+        mNearesWrap = Sampler.WRAP_NEAREST(mRS);
 
         mScript.set_gLinearClamp(mLinearClamp);
         mScript.set_gLinearWrap(mLinearWrap);
@@ -493,10 +650,10 @@
         initSamplers();
         initProgramStore();
         initProgramFragment();
+        initMesh();
         initProgramVertex();
         initFonts();
         loadImages();
-        initMesh();
         initProgramRaster();
         initCustomShaders();
 
@@ -517,6 +674,34 @@
                                            Allocation.USAGE_GRAPHICS_RENDER_TARGET);
         mScript.set_gRenderBufferDepth(offscreen);
 
+
+        mTextureAllocs = new ScriptField_ListAllocs_s(mRS, 100);
+        for (int i = 0; i < 100; i++) {
+            ScriptField_ListAllocs_s.Item texElem = new ScriptField_ListAllocs_s.Item();
+            texElem.item = loadTextureRGB(R.drawable.globe);
+            mTextureAllocs.set(texElem, i, false);
+        }
+        mTextureAllocs.copyAll();
+        mScript.bind_gTexList100(mTextureAllocs);
+
+        mSampleTextAllocs = new ScriptField_ListAllocs_s(mRS, 100);
+        for (int i = 0; i < 100; i++) {
+            ScriptField_ListAllocs_s.Item textElem = new ScriptField_ListAllocs_s.Item();
+            textElem.item = Allocation.createFromString(mRS, SAMPLE_TEXT, Allocation.USAGE_SCRIPT);
+            mSampleTextAllocs.set(textElem, i, false);
+        }
+        mSampleTextAllocs.copyAll();
+        mScript.bind_gSampleTextList100(mSampleTextAllocs);
+
+        mSampleListViewAllocs = new ScriptField_ListAllocs_s(mRS, 1000);
+        for (int i = 0; i < 1000; i++) {
+            ScriptField_ListAllocs_s.Item textElem = new ScriptField_ListAllocs_s.Item();
+            textElem.item = Allocation.createFromString(mRS, LIST_TEXT, Allocation.USAGE_SCRIPT);
+            mSampleListViewAllocs.set(textElem, i, false);
+        }
+        mSampleListViewAllocs.copyAll();
+        mScript.bind_gListViewText(mSampleListViewAllocs);
+
         mRS.bindRootScript(mScript);
     }
 }
diff --git a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/rsbench.rs b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/rsbench.rs
index e7f5cd4..6d80b0e 100644
--- a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/rsbench.rs
+++ b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/rsbench.rs
@@ -23,9 +23,50 @@
 const int RS_MSG_TEST_DONE = 100;
 const int RS_MSG_RESULTS_READY = 101;
 
-const int gMaxModes = 25;
+const int gMaxModes = 31;
 int gMaxLoops;
 
+// Parameters for galaxy live wallpaper
+rs_allocation gTSpace;
+rs_allocation gTLight1;
+rs_allocation gTFlares;
+rs_mesh gParticlesMesh;
+
+rs_program_fragment gPFBackground;
+rs_program_fragment gPFStars;
+rs_program_vertex gPVStars;
+rs_program_vertex gPVBkProj;
+rs_program_store gPSLights;
+
+float gXOffset = 0.5f;
+
+#define ELLIPSE_RATIO 0.892f
+#define PI 3.1415f
+#define TWO_PI 6.283f
+#define ELLIPSE_TWIST 0.023333333f
+
+static float angle = 50.f;
+static int gOldWidth;
+static int gOldHeight;
+static int gWidth;
+static int gHeight;
+static float gSpeed[12000];
+static int gGalaxyRadius = 300;
+static rs_allocation gParticlesBuffer;
+
+typedef struct __attribute__((packed, aligned(4))) Particle {
+    uchar4 color;
+    float3 position;
+} Particle_t;
+Particle_t *Particles;
+
+typedef struct VpConsts {
+    rs_matrix4x4 Proj;
+    rs_matrix4x4 MVP;
+} VpConsts_t;
+VpConsts_t *vpConstants;
+// End of parameters for galaxy live wallpaper
+
 // Allocation to send test names back to java
 char *gStringBuffer = 0;
 // Allocation to write the results into
@@ -44,11 +85,21 @@
 rs_allocation gTexTorus;
 rs_allocation gTexTransparent;
 rs_allocation gTexChecker;
+rs_allocation gTexGlobe;
+
+typedef struct ListAllocs_s {
+    rs_allocation item;
+} ListAllocs;
+
+ListAllocs *gTexList100;
+ListAllocs *gSampleTextList100;
+ListAllocs *gListViewText;
 
 rs_mesh g10by10Mesh;
 rs_mesh g100by100Mesh;
 rs_mesh gWbyHMesh;
 rs_mesh gTorusMesh;
+rs_mesh gSingleMesh;
 
 rs_font gFontSans;
 rs_font gFontSerif;
@@ -100,6 +151,141 @@
                              0.5f, 0.6f, 0.7f, 1.0f,
 };
 
+/**
+  * Methods to draw the galaxy live wall paper
+  */
+static float mapf(float minStart, float minStop, float maxStart, float maxStop, float value) {
+    return maxStart + (maxStart - maxStop) * ((value - minStart) / (minStop - minStart));
+}
+
+/**
+ * Helper function to generate the stars.
+ */
+static float randomGauss() {
+    float x1;
+    float x2;
+    float w = 2.f;
+
+    while (w >= 1.0f) {
+        x1 = rsRand(2.0f) - 1.0f;
+        x2 = rsRand(2.0f) - 1.0f;
+        w = x1 * x1 + x2 * x2;
+    }
+
+    w = sqrt(-2.0f * log(w) / w);
+    return x1 * w;
+}
+
+/**
+ * Generates the properties for a given star.
+ */
+static void createParticle(Particle_t *part, int idx, float scale) {
+    float d = fabs(randomGauss()) * gGalaxyRadius * 0.5f + rsRand(64.0f);
+    float id = d / gGalaxyRadius;
+    float z = randomGauss() * 0.4f * (1.0f - id);
+    float p = -d * ELLIPSE_TWIST;
+
+    if (d < gGalaxyRadius * 0.33f) {
+        part->color.x = (uchar) (220 + id * 35);
+        part->color.y = 220;
+        part->color.z = 220;
+    } else {
+        part->color.x = 180;
+        part->color.y = 180;
+        part->color.z = (uchar) clamp(140.f + id * 115.f, 140.f, 255.f);
+    }
+    // Stash point size * 10 in Alpha
+    part->color.w = (uchar) (rsRand(1.2f, 2.1f) * 60);
+
+    if (d > gGalaxyRadius * 0.15f) {
+        z *= 0.6f * (1.0f - id);
+    } else {
+        z *= 0.72f;
+    }
+
+    // Map to the projection coordinates (viewport.x = -1.0 -> 1.0)
+    d = mapf(-4.0f, gGalaxyRadius + 4.0f, 0.0f, scale, d);
+
+    part->position.x = rsRand(TWO_PI);
+    part->position.y = d;
+    gSpeed[idx] = rsRand(0.0015f, 0.0025f) * (0.5f + (scale / d)) * 0.8f;
+
+    part->position.z = z / 5.0f;
+}
+
+/**
+ * Initialize all the starts, called from Java
+ */
+void initParticles() {
+    Particle_t *part = Particles;
+    float scale = gGalaxyRadius / (gWidth * 0.5f);
+    int count = rsAllocationGetDimX(gParticlesBuffer);
+    for (int i = 0; i < count; i ++) {
+        createParticle(part, i, scale);
+        part++;
+    }
+}
+
+static void drawSpace() {
+    rsgBindProgramFragment(gPFBackground);
+    rsgBindTexture(gPFBackground, 0, gTSpace);
+    rsgDrawQuadTexCoords(
+            0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
+            gWidth, 0.0f, 0.0f, 2.0f, 1.0f,
+            gWidth, gHeight, 0.0f, 2.0f, 0.0f,
+            0.0f, gHeight, 0.0f, 0.0f, 0.0f);
+}
+
+static void drawLights() {
+    rsgBindProgramVertex(gPVBkProj);
+    rsgBindProgramFragment(gPFBackground);
+    rsgBindTexture(gPFBackground, 0, gTLight1);
+
+    float scale = 512.0f / gWidth;
+    float x = -scale - scale * 0.05f;
+    float y = -scale;
+
+    scale *= 2.0f;
+
+    rsgDrawQuad(x, y, 0.0f,
+             x + scale * 1.1f, y, 0.0f,
+             x + scale * 1.1f, y + scale, 0.0f,
+             x, y + scale, 0.0f);
+}
+
+static void drawParticles(float offset) {
+    float a = offset * angle;
+    float absoluteAngle = fabs(a);
+
+    rs_matrix4x4 matrix;
+    rsMatrixLoadTranslate(&matrix, 0.0f, 0.0f, 10.0f - 6.0f * absoluteAngle / 50.0f);
+    if (gHeight > gWidth) {
+        rsMatrixScale(&matrix, 6.6f, 6.0f, 1.0f);
+    } else {
+        rsMatrixScale(&matrix, 12.6f, 12.0f, 1.0f);
+    }
+    rsMatrixRotate(&matrix, absoluteAngle, 1.0f, 0.0f, 0.0f);
+    rsMatrixRotate(&matrix, a, 0.0f, 0.4f, 0.1f);
+    rsMatrixLoad(&vpConstants->MVP, &vpConstants->Proj);
+    rsMatrixMultiply(&vpConstants->MVP, &matrix);
+    rsgAllocationSyncAll(rsGetAllocation(vpConstants));
+
+    rsgBindProgramVertex(gPVStars);
+    rsgBindProgramFragment(gPFStars);
+    rsgBindProgramStore(gPSLights);
+    rsgBindTexture(gPFStars, 0, gTFlares);
+
+    Particle_t *vtx = Particles;
+    int count = rsAllocationGetDimX(gParticlesBuffer);
+    for (int i = 0; i < count; i++) {
+        vtx->position.x = vtx->position.x + gSpeed[i];
+        vtx++;
+    }
+
+    rsgDrawMesh(gParticlesMesh);
+}
+/* end of methods for drawing galaxy */
+
 static void setupOffscreenTarget() {
     rsgBindColorTarget(gRenderBufferColor, 0);
     rsgBindDepthTarget(gRenderBufferDepth);
@@ -142,7 +328,7 @@
 }
 
 static void bindProgramVertexOrtho() {
-    // Default vertex sahder
+    // Default vertex shader
     rsgBindProgramVertex(gProgVertex);
     // Setup the projection matrix
     rs_matrix4x4 proj;
@@ -187,6 +373,7 @@
     rsgBindProgramStore(gProgStoreBlendNone);
     rsgBindProgramFragment(gProgFragmentTexture);
     rsgBindSampler(gProgFragmentTexture, 0, gLinearClamp);
+
     rsgBindTexture(gProgFragmentTexture, 0, gTexOpaque);
 
     if (meshNum == 0) {
@@ -198,6 +385,166 @@
     }
 }
 
+// Display sample images in a mesh with different texture
+static void displayIcons(int meshMode) {
+    bindProgramVertexOrtho();
+
+    // Fragment shader with texture
+    rsgBindProgramStore(gProgStoreBlendAlpha);
+    rsgBindProgramFragment(gProgFragmentTexture);
+    rsgBindSampler(gProgFragmentTexture, 0, gLinearClamp);
+
+    int meshCount = (int)pow(10.0f, (float)(meshMode + 1));
+
+    float size = 50.0;
+    rs_matrix4x4 matrix;
+    rsMatrixLoadScale(&matrix, size, size, 1.0);
+
+    float yPos = 0;
+    for (int y = 0; y < meshCount; y++) {
+        yPos = (y + 1) * 50;
+        float xPos = 0;
+        for (int x = 0; x < meshCount; x++) {
+            xPos = (x + 1) * 50;
+            rs_matrix4x4 transMatrix;
+            rsMatrixLoadTranslate(&transMatrix, xPos, yPos, 0);
+            rsMatrixMultiply(&transMatrix, &matrix);
+            rsgProgramVertexLoadModelMatrix(&transMatrix);
+            int i = (x + y * meshCount) % 100;
+            rsgBindTexture(gProgFragmentTexture, 0, gTexList100[i].item);
+            rsgDrawMesh(gSingleMesh);
+        }
+    }
+}
+
+// Draw meshes in a single page with top left corner coordinates (xStart, yStart)
+static void drawMeshInPage(float xStart, float yStart, int wResolution, int hResolution) {
+    // Draw wResolution * hResolution meshes in one page
+    float wMargin = 100.0f;
+    float hMargin = 100.0f;
+    float xPad = 50.0f;
+    float yPad = 20.0f;
+    float size = 100.0f;  // size of images
+
+    // font info
+    rs_font font = gFontSans;
+    rsgBindFont(font);
+    rsgFontColor(1.0f, 1.0f, 1.0f, 1.0f);
+
+    // Measure text size
+    int left = 0, right = 0, top = 0, bottom = 0;
+    rsgMeasureText(gSampleTextList100[0].item, &left, &right, &top, &bottom);
+    float textHeight = (float)(top - bottom);
+    float textWidth = (float)(right - left);
+
+    rs_matrix4x4 matrix;
+    rsMatrixLoadScale(&matrix, size, size, 1.0);
+
+    for (int y = 0; y < hResolution; y++) {
+        float yPos = yStart + hMargin + y * size + y * yPad;
+        for (int x = 0; x < wResolution; x++) {
+            float xPos = xStart + wMargin + x * size + x * xPad;
+
+            rs_matrix4x4 transMatrix;
+            rsMatrixLoadTranslate(&transMatrix, xPos + size/2, yPos + size/2, 0);
+            rsMatrixMultiply(&transMatrix, &matrix);  // scale the mesh
+            rsgProgramVertexLoadModelMatrix(&transMatrix);
+
+            int i = (y * wResolution + x) % 100;
+            rsgBindTexture(gProgFragmentTexture, 0, gTexList100[i].item);
+            rsgDrawMesh(gSingleMesh);
+            rsgDrawText(gSampleTextList100[i].item, xPos, yPos + size + yPad/2 + textHeight);
+        }
+    }
+}
+
+// Display both images and text as shown in launcher and homepage
+// meshMode will decide how many pages we draw
+// meshMode = 0: draw 3 pages of meshes
+// meshMode = 1: draw 5 pages of meshes
+static void displayImageWithText(int wResolution, int hResolution, int meshMode) {
+    bindProgramVertexOrtho();
+
+    // Fragment shader with texture
+    rsgBindProgramStore(gProgStoreBlendAlpha);
+    rsgBindProgramFragment(gProgFragmentTexture);
+    rsgBindSampler(gProgFragmentTexture, 0, gLinearClamp);
+
+    drawMeshInPage(0, 0, wResolution, hResolution);
+    drawMeshInPage(-1.0f*gRenderSurfaceW, 0, wResolution, hResolution);
+    drawMeshInPage(1.0f*gRenderSurfaceW, 0, wResolution, hResolution);
+    if (meshMode == 1) {
+        // draw another two pages of meshes
+        drawMeshInPage(-2.0f*gRenderSurfaceW, 0, wResolution, hResolution);
+        drawMeshInPage(2.0f*gRenderSurfaceW, 0, wResolution, hResolution);
+    }
+}
+
+// Display a list of text as the list view
+static void displayListView() {
+    // set text color
+    rsgFontColor(0.9f, 0.9f, 0.9f, 1.0f);
+    rsgBindFont(gFontSans);
+
+    // get the size of the list
+    rs_allocation textAlloc;
+    textAlloc = rsGetAllocation(gListViewText);
+    int allocSize = rsAllocationGetDimX(textAlloc);
+
+    int listItemHeight = 80;
+    int yOffset = listItemHeight;
+
+    // set the color for the list divider
+    rsgBindProgramFragment(gProgFragmentColor);
+    rsgProgramFragmentConstantColor(gProgFragmentColor, 1.0, 1.0, 1.0, 1);
+
+    // draw the list with divider
+    for (int i = 0; i < allocSize; i++) {
+        if (yOffset - listItemHeight > gRenderSurfaceH) {
+            break;
+        }
+        rsgDrawRect(0, yOffset - 1, gRenderSurfaceW, yOffset, 0);
+        rsgDrawText(gListViewText[i].item, 20, yOffset - 10);
+        yOffset += listItemHeight;
+    }
+}
+
+static void drawGalaxy() {
+    rsgClearColor(0.f, 0.f, 0.f, 1.f);
+    gParticlesBuffer = rsGetAllocation(Particles);
+    rsgBindProgramFragment(gPFBackground);
+
+    gWidth = rsgGetWidth();
+    gHeight = rsgGetHeight();
+    if ((gWidth != gOldWidth) || (gHeight != gOldHeight)) {
+        initParticles();
+        gOldWidth = gWidth;
+        gOldHeight = gHeight;
+    }
+
+    float offset = mix(-1.0f, 1.0f, gXOffset);
+    drawSpace();
+    drawParticles(offset);
+    drawLights();
+}
+
+// Display images and text with live wallpaper in the background
+static void dispalyLiveWallPaper(int wResolution, int hResolution) {
+    bindProgramVertexOrtho();
+
+    drawGalaxy();
+
+    rsgBindProgramStore(gProgStoreBlendAlpha);
+    rsgBindProgramFragment(gProgFragmentTexture);
+    rsgBindSampler(gProgFragmentTexture, 0, gLinearClamp);
+
+    drawMeshInPage(0, 0, wResolution, hResolution);
+    drawMeshInPage(-1.0f*gRenderSurfaceW, 0, wResolution, hResolution);
+    drawMeshInPage(1.0f*gRenderSurfaceW, 0, wResolution, hResolution);
+    drawMeshInPage(-2.0f*gRenderSurfaceW, 0, wResolution, hResolution);
+    drawMeshInPage(2.0f*gRenderSurfaceW, 0, wResolution, hResolution);
+}
+
 static float gTorusRotation = 0;
 static void updateModelMatrix(rs_matrix4x4 *matrix, void *buffer) {
     if (buffer == 0) {
@@ -497,6 +844,12 @@
     "Geo test 25.6k heavy fragment heavy vertex",
     "Geo test 51.2k heavy fragment heavy vertex",
     "Geo test 204.8k small tries heavy fragment heavy vertex",
+    "UI test with icon display 10 by 10",
+    "UI test with icon display 100 by 100",
+    "UI test with image and text display 3 pages",
+    "UI test with image and text display 5 pages",
+    "UI test with list view",
+    "UI test with live wallpaper",
 };
 
 void getTestName(int testIndex) {
@@ -589,6 +942,24 @@
     case 24:
         displayPixelLightSamples(8, true);
         break;
+    case 25:
+        displayIcons(0);
+        break;
+    case 26:
+        displayIcons(1);
+        break;
+    case 27:
+        displayImageWithText(7, 5, 0);
+        break;
+    case 28:
+        displayImageWithText(7, 5, 1);
+        break;
+    case 29:
+        displayListView();
+        break;
+    case 30:
+        dispalyLiveWallPaper(7, 5);
+        break;
     }
 }
 
@@ -612,7 +983,6 @@
 }
 
 int root(void) {
-
     gRenderSurfaceW = rsgGetWidth();
     gRenderSurfaceH = rsgGetHeight();
     rsgClearColor(0.2f, 0.2f, 0.2f, 1.0f);
@@ -640,6 +1010,7 @@
         gRenderSurfaceW = rsgGetWidth();
         gRenderSurfaceH = rsgGetHeight();
         int size = 8;
+        // draw each frame at (8, 3/4 gRenderSurfaceH) with size
         drawOffscreenResult((drawPos+=size)%gRenderSurfaceW, (gRenderSurfaceH * 3) / 4, size, size);
     }
 
@@ -649,11 +1020,9 @@
     float fps = (float)(frameCount) / ((float)(end - start)*0.001f);
     rsDebug(testNames[benchMode], fps);
     gResultBuffer[benchMode] = fps;
-
     drawOffscreenResult(0, 0,
                         gRenderSurfaceW / 2,
                         gRenderSurfaceH / 2);
-
     const char* text = testNames[benchMode];
     int left = 0, right = 0, top = 0, bottom = 0;
     uint width = rsgGetWidth();
diff --git a/tests/StatusBar/res/drawable-hdpi/emo_im_kissing.png b/tests/StatusBar/res/drawable-hdpi/emo_im_kissing.png
new file mode 100644
index 0000000..0a8f0d7
--- /dev/null
+++ b/tests/StatusBar/res/drawable-hdpi/emo_im_kissing.png
Binary files differ
diff --git a/tests/StatusBar/res/drawable-hdpi/notification0.png b/tests/StatusBar/res/drawable-hdpi/notification0.png
new file mode 100644
index 0000000..6d2612e
--- /dev/null
+++ b/tests/StatusBar/res/drawable-hdpi/notification0.png
Binary files differ
diff --git a/tests/StatusBar/res/drawable-hdpi/notification1.png b/tests/StatusBar/res/drawable-hdpi/notification1.png
new file mode 100644
index 0000000..ce9009c
--- /dev/null
+++ b/tests/StatusBar/res/drawable-hdpi/notification1.png
Binary files differ
diff --git a/tests/StatusBar/res/drawable-hdpi/notification2.png b/tests/StatusBar/res/drawable-hdpi/notification2.png
new file mode 100644
index 0000000..772d70a
--- /dev/null
+++ b/tests/StatusBar/res/drawable-hdpi/notification2.png
Binary files differ
diff --git a/tests/StatusBar/res/drawable-hdpi/notification3.png b/tests/StatusBar/res/drawable-hdpi/notification3.png
new file mode 100644
index 0000000..61127ee
--- /dev/null
+++ b/tests/StatusBar/res/drawable-hdpi/notification3.png
Binary files differ
diff --git a/tests/StatusBar/res/drawable-hdpi/notification4.png b/tests/StatusBar/res/drawable-hdpi/notification4.png
new file mode 100644
index 0000000..40b7d55
--- /dev/null
+++ b/tests/StatusBar/res/drawable-hdpi/notification4.png
Binary files differ
diff --git a/tests/StatusBar/res/drawable-hdpi/notification5.png b/tests/StatusBar/res/drawable-hdpi/notification5.png
new file mode 100644
index 0000000..e89903a
--- /dev/null
+++ b/tests/StatusBar/res/drawable-hdpi/notification5.png
Binary files differ
diff --git a/tests/StatusBar/res/drawable-hdpi/notification6.png b/tests/StatusBar/res/drawable-hdpi/notification6.png
new file mode 100644
index 0000000..e0878f5
--- /dev/null
+++ b/tests/StatusBar/res/drawable-hdpi/notification6.png
Binary files differ
diff --git a/tests/StatusBar/res/drawable-hdpi/notification7.png b/tests/StatusBar/res/drawable-hdpi/notification7.png
new file mode 100644
index 0000000..49397ca
--- /dev/null
+++ b/tests/StatusBar/res/drawable-hdpi/notification7.png
Binary files differ
diff --git a/tests/StatusBar/res/drawable-hdpi/notification8.png b/tests/StatusBar/res/drawable-hdpi/notification8.png
new file mode 100644
index 0000000..763b048
--- /dev/null
+++ b/tests/StatusBar/res/drawable-hdpi/notification8.png
Binary files differ
diff --git a/tests/StatusBar/res/drawable-hdpi/notification9.png b/tests/StatusBar/res/drawable-hdpi/notification9.png
new file mode 100644
index 0000000..c3c3771
--- /dev/null
+++ b/tests/StatusBar/res/drawable-hdpi/notification9.png
Binary files differ
diff --git a/tests/StatusBar/res/drawable-hdpi/notificationx.png b/tests/StatusBar/res/drawable-hdpi/notificationx.png
new file mode 100644
index 0000000..7267286
--- /dev/null
+++ b/tests/StatusBar/res/drawable-hdpi/notificationx.png
Binary files differ
diff --git a/tests/StatusBar/res/drawable-hdpi/pineapple.png b/tests/StatusBar/res/drawable-hdpi/pineapple.png
new file mode 100644
index 0000000..e62d3c8
--- /dev/null
+++ b/tests/StatusBar/res/drawable-hdpi/pineapple.png
Binary files differ
diff --git a/tests/StatusBar/res/drawable-hdpi/pineapple2.png b/tests/StatusBar/res/drawable-hdpi/pineapple2.png
new file mode 100644
index 0000000..54146a8
--- /dev/null
+++ b/tests/StatusBar/res/drawable-hdpi/pineapple2.png
Binary files differ
diff --git a/tests/StatusBar/res/layout/notification_builder_test.xml b/tests/StatusBar/res/layout/notification_builder_test.xml
index 3c37a73..e1199c7 100644
--- a/tests/StatusBar/res/layout/notification_builder_test.xml
+++ b/tests/StatusBar/res/layout/notification_builder_test.xml
@@ -1,224 +1,220 @@
 <?xml version="1.0" encoding="utf-8"?>
-<LinearLayout
-        xmlns:android="http://schemas.android.com/apk/res/android"
+<ScrollView
         android:layout_width="match_parent"
         android:layout_height="match_parent"
-        android:orientation="horizontal"
-        android:paddingLeft="40dp"
-        android:paddingTop="12dp"
-        android:paddingRight="24dp"
-        android:paddingBottom="12dp"
+        xmlns:android="http://schemas.android.com/apk/res/android"
         >
-
     <LinearLayout
-            android:layout_width="220sp"
+            android:layout_width="match_parent"
             android:layout_height="match_parent"
-            android:layout_marginRight="24dp"
-            android:orientation="vertical"
+            android:orientation="horizontal"
             >
+
         <LinearLayout
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:orientation="horizontal"
+                android:layout_width="120dp"
+                android:layout_height="match_parent"
+                android:orientation="vertical"
                 >
+            <LinearLayout
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:orientation="horizontal"
+                    >
+                <Button
+                        style="@style/IdButton.Minus"
+                        android:id="@+id/clear_1"
+                        />
+                <TextView
+                        style="@style/IdTitle"
+                        android:text="1"
+                        />
+                <Button
+                        style="@style/IdButton.Plus"
+                        android:id="@+id/notify_1"
+                        />
+            </LinearLayout>
+            <LinearLayout
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:orientation="horizontal"
+                    >
+                <Button
+                        style="@style/IdButton.Minus"
+                        android:id="@+id/clear_2"
+                        />
+                <TextView
+                        style="@style/IdTitle"
+                        android:text="2"
+                        />
+                <Button
+                        style="@style/IdButton.Plus"
+                        android:id="@+id/notify_2"
+                        />
+            </LinearLayout>
+            <LinearLayout
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:orientation="horizontal"
+                    >
+                <Button
+                        style="@style/IdButton.Minus"
+                        android:id="@+id/clear_3"
+                        />
+                <TextView
+                        style="@style/IdTitle"
+                        android:text="3"
+                        />
+                <Button
+                        style="@style/IdButton.Plus"
+                        android:id="@+id/notify_3"
+                        />
+            </LinearLayout>
+            <LinearLayout
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:orientation="horizontal"
+                    >
+                <Button
+                        style="@style/IdButton.Minus"
+                        android:id="@+id/clear_4"
+                        />
+                <TextView
+                        style="@style/IdTitle"
+                        android:text="4"
+                        />
+                <Button
+                        style="@style/IdButton.Plus"
+                        android:id="@+id/notify_4"
+                        />
+            </LinearLayout>
+            <LinearLayout
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:orientation="horizontal"
+                    >
+                <Button
+                        style="@style/IdButton.Minus"
+                        android:id="@+id/clear_5"
+                        />
+                <TextView
+                        style="@style/IdTitle"
+                        android:text="5"
+                        />
+                <Button
+                        style="@style/IdButton.Plus"
+                        android:id="@+id/notify_5"
+                        />
+            </LinearLayout>
+            <LinearLayout
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:orientation="horizontal"
+                    >
+                <Button
+                        style="@style/IdButton.Minus"
+                        android:id="@+id/clear_6"
+                        />
+                <TextView
+                        style="@style/IdTitle"
+                        android:text="6"
+                        />
+                <Button
+                        style="@style/IdButton.Plus"
+                        android:id="@+id/notify_6"
+                        />
+            </LinearLayout>
+            <LinearLayout
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:orientation="horizontal"
+                    >
+                <Button
+                        style="@style/IdButton.Minus"
+                        android:id="@+id/clear_7"
+                        />
+                <TextView
+                        style="@style/IdTitle"
+                        android:text="7"
+                        />
+                <Button
+                        style="@style/IdButton.Plus"
+                        android:id="@+id/notify_7"
+                        />
+            </LinearLayout>
+            <LinearLayout
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:orientation="horizontal"
+                    >
+                <Button
+                        style="@style/IdButton.Minus"
+                        android:id="@+id/clear_8"
+                        />
+                <TextView
+                        style="@style/IdTitle"
+                        android:text="8"
+                        />
+                <Button
+                        style="@style/IdButton.Plus"
+                        android:id="@+id/notify_8"
+                        />
+            </LinearLayout>
+            <LinearLayout
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:orientation="horizontal"
+                    >
+                <Button
+                        style="@style/IdButton.Minus"
+                        android:id="@+id/clear_9"
+                        />
+                <TextView
+                        style="@style/IdTitle"
+                        android:text="9"
+                        />
+                <Button
+                        style="@style/IdButton.Plus"
+                        android:id="@+id/notify_9"
+                        />
+            </LinearLayout>
+            <LinearLayout
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:orientation="horizontal"
+                    >
+                <Button
+                        style="@style/IdButton.Minus"
+                        android:id="@+id/clear_10"
+                        />
+                <TextView
+                        style="@style/IdTitle"
+                        android:text="10"
+                        />
+                <Button
+                        style="@style/IdButton.Plus"
+                        android:id="@+id/notify_10"
+                        />
+            </LinearLayout>
+
             <Button
-                    style="@style/IdButton.Minus"
-                    android:id="@+id/clear_1"
-                    />
-            <TextView
-                    style="@style/IdTitle"
-                    android:text="1"
+                    android:id="@+id/clear_all"
+                    android:textAppearance="?android:attr/textAppearanceSmall"
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:layout_marginTop="12dp"
+                    android:layout_marginBottom="12dp"
+                    android:text="Clear All"
                     />
             <Button
-                    style="@style/IdButton.Plus"
-                    android:id="@+id/notify_1"
+                    android:id="@+id/ten"
+                    android:textAppearance="?android:attr/textAppearanceSmall"
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:text="Ten notifications"
                     />
-        </LinearLayout>
-        <LinearLayout
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:orientation="horizontal"
-                >
-            <Button
-                    style="@style/IdButton.Minus"
-                    android:id="@+id/clear_2"
-                    />
-            <TextView
-                    style="@style/IdTitle"
-                    android:text="2"
-                    />
-            <Button
-                    style="@style/IdButton.Plus"
-                    android:id="@+id/notify_2"
-                    />
-        </LinearLayout>
-        <LinearLayout
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:orientation="horizontal"
-                >
-            <Button
-                    style="@style/IdButton.Minus"
-                    android:id="@+id/clear_3"
-                    />
-            <TextView
-                    style="@style/IdTitle"
-                    android:text="3"
-                    />
-            <Button
-                    style="@style/IdButton.Plus"
-                    android:id="@+id/notify_3"
-                    />
-        </LinearLayout>
-        <LinearLayout
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:orientation="horizontal"
-                >
-            <Button
-                    style="@style/IdButton.Minus"
-                    android:id="@+id/clear_4"
-                    />
-            <TextView
-                    style="@style/IdTitle"
-                    android:text="4"
-                    />
-            <Button
-                    style="@style/IdButton.Plus"
-                    android:id="@+id/notify_4"
-                    />
-        </LinearLayout>
-        <LinearLayout
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:orientation="horizontal"
-                >
-            <Button
-                    style="@style/IdButton.Minus"
-                    android:id="@+id/clear_5"
-                    />
-            <TextView
-                    style="@style/IdTitle"
-                    android:text="5"
-                    />
-            <Button
-                    style="@style/IdButton.Plus"
-                    android:id="@+id/notify_5"
-                    />
-        </LinearLayout>
-        <LinearLayout
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:orientation="horizontal"
-                >
-            <Button
-                    style="@style/IdButton.Minus"
-                    android:id="@+id/clear_6"
-                    />
-            <TextView
-                    style="@style/IdTitle"
-                    android:text="6"
-                    />
-            <Button
-                    style="@style/IdButton.Plus"
-                    android:id="@+id/notify_6"
-                    />
-        </LinearLayout>
-        <LinearLayout
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:orientation="horizontal"
-                >
-            <Button
-                    style="@style/IdButton.Minus"
-                    android:id="@+id/clear_7"
-                    />
-            <TextView
-                    style="@style/IdTitle"
-                    android:text="7"
-                    />
-            <Button
-                    style="@style/IdButton.Plus"
-                    android:id="@+id/notify_7"
-                    />
-        </LinearLayout>
-        <LinearLayout
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:orientation="horizontal"
-                >
-            <Button
-                    style="@style/IdButton.Minus"
-                    android:id="@+id/clear_8"
-                    />
-            <TextView
-                    style="@style/IdTitle"
-                    android:text="8"
-                    />
-            <Button
-                    style="@style/IdButton.Plus"
-                    android:id="@+id/notify_8"
-                    />
-        </LinearLayout>
-        <LinearLayout
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:orientation="horizontal"
-                >
-            <Button
-                    style="@style/IdButton.Minus"
-                    android:id="@+id/clear_9"
-                    />
-            <TextView
-                    style="@style/IdTitle"
-                    android:text="9"
-                    />
-            <Button
-                    style="@style/IdButton.Plus"
-                    android:id="@+id/notify_9"
-                    />
-        </LinearLayout>
-        <LinearLayout
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:orientation="horizontal"
-                >
-            <Button
-                    style="@style/IdButton.Minus"
-                    android:id="@+id/clear_10"
-                    />
-            <TextView
-                    style="@style/IdTitle"
-                    android:text="10"
-                    />
-            <Button
-                    style="@style/IdButton.Plus"
-                    android:id="@+id/notify_10"
-                    />
+                    
         </LinearLayout>
 
-        <Button
-                android:id="@+id/clear_all"
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:layout_marginTop="12dp"
-                android:layout_marginBottom="12dp"
-                android:text="Clear All"
-                />
-        <Button
-                android:id="@+id/ten"
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:text="Ten notifications"
-                />
-                
-    </LinearLayout>
-
-    <ScrollView
-            android:layout_width="wrap_content"
-            android:layout_height="match_parent"
-            android:layout_weight="1"
-            >
         <LinearLayout
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
@@ -818,7 +814,6 @@
 
 
         </LinearLayout>
-    </ScrollView>
+    </LinearLayout>
 
-
-</LinearLayout>
+</ScrollView>
diff --git a/tests/StatusBar/res/values-sw600dp/styles.xml b/tests/StatusBar/res/values-sw600dp/styles.xml
new file mode 100644
index 0000000..f29847c
--- /dev/null
+++ b/tests/StatusBar/res/values-sw600dp/styles.xml
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+  
+          http://www.apache.org/licenses/LICENSE-2.0
+  
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+<resources>
+    <style name="IdTitle">
+        <item name="android:textAppearance">?android:attr/textAppearanceLarge</item>
+        <item name="android:layout_width">30sp</item>
+        <item name="android:layout_height">wrap_content</item>
+        <item name="android:gravity">center</item>
+        <item name="android:textStyle">bold</item>
+    </style>
+
+    <style name="IdButton">
+        <item name="android:textAppearance">?android:attr/textAppearanceLarge</item>
+        <item name="android:layout_width">0dp</item>
+        <item name="android:layout_height">wrap_content</item>
+        <item name="android:layout_weight">1</item>
+        <item name="android:layout_marginRight">8dp</item>
+        <item name="android:layout_marginLeft">8dp</item>
+        <item name="android:textStyle">bold</item>
+    </style>
+
+    <style name="IdButton.Minus">
+        <item name="android:text">-</item>
+    </style>
+
+    <style name="IdButton.Plus">
+        <item name="android:text">+</item>
+    </style>
+
+    <style name="FieldTitle">
+        <item name="android:textAppearance">?android:attr/textAppearanceLarge</item>
+        <item name="android:layout_width">208sp</item>
+        <item name="android:layout_height">wrap_content</item>
+    </style>
+
+    <style name="FieldContents">
+        <item name="android:textAppearance">?android:attr/textAppearanceMedium</item>
+        <item name="android:layout_width">wrap_content</item>
+        <item name="android:layout_height">wrap_content</item>
+        <item name="android:layout_marginRight">20dp</item>
+    </style>
+
+    <style name="FieldContents.Disabled">
+        <item name="android:clickable">false</item>
+        <item name="android:visibility">gone</item>
+    </style>
+
+</resources>
+
+
diff --git a/tests/StatusBar/res/values/styles.xml b/tests/StatusBar/res/values/styles.xml
index e051efd..103a25a 100644
--- a/tests/StatusBar/res/values/styles.xml
+++ b/tests/StatusBar/res/values/styles.xml
@@ -16,21 +16,23 @@
 <resources>
 
     <style name="IdTitle">
-        <item name="android:textAppearance">?android:attr/textAppearanceLarge</item>
-        <item name="android:layout_width">30sp</item>
+        <item name="android:textAppearance">?android:attr/textAppearanceSmall</item>
+        <item name="android:layout_width">20sp</item>
         <item name="android:layout_height">wrap_content</item>
         <item name="android:gravity">center</item>
         <item name="android:textStyle">bold</item>
     </style>
 
     <style name="IdButton">
-        <item name="android:textAppearance">?android:attr/textAppearanceLarge</item>
-        <item name="android:layout_width">0dp</item>
+        <item name="android:textAppearance">?android:attr/textAppearanceMedium</item>
+        <item name="android:layout_width">10dp</item>
         <item name="android:layout_height">wrap_content</item>
         <item name="android:layout_weight">1</item>
-        <item name="android:layout_marginRight">8dp</item>
-        <item name="android:layout_marginLeft">8dp</item>
         <item name="android:textStyle">bold</item>
+        <item name="android:layout_marginLeft">1dp</item>
+        <item name="android:layout_marginRight">1dp</item>
+        <item name="android:paddingLeft">6dp</item>
+        <item name="android:paddingRight">6dp</item>
     </style>
 
     <style name="IdButton.Minus">
@@ -42,16 +44,16 @@
     </style>
 
     <style name="FieldTitle">
-        <item name="android:textAppearance">?android:attr/textAppearanceLarge</item>
-        <item name="android:layout_width">208sp</item>
+        <item name="android:textAppearance">?android:attr/textAppearanceSmall</item>
+        <item name="android:layout_width">wrap_content</item>
         <item name="android:layout_height">wrap_content</item>
     </style>
 
     <style name="FieldContents">
-        <item name="android:textAppearance">?android:attr/textAppearanceMedium</item>
+        <item name="android:textAppearance">?android:attr/textAppearanceSmall</item>
         <item name="android:layout_width">wrap_content</item>
         <item name="android:layout_height">wrap_content</item>
-        <item name="android:layout_marginRight">20dp</item>
+        <item name="android:layout_marginRight">4dp</item>
     </style>
 
     <style name="FieldContents.Disabled">
diff --git a/tests/StatusBar/src/com/android/statusbartest/StatusBarTest.java b/tests/StatusBar/src/com/android/statusbartest/StatusBarTest.java
index 0129114..b212533 100644
--- a/tests/StatusBar/src/com/android/statusbartest/StatusBarTest.java
+++ b/tests/StatusBar/src/com/android/statusbartest/StatusBarTest.java
@@ -145,13 +145,10 @@
         },
         new Test("Priority notification") {
             public void run() {
-                Notification not = new Notification(StatusBarTest.this,
+                Notification not = new Notification(
                                 R.drawable.stat_sys_phone,
                                 "Incoming call from: Imperious Leader",
-                                System.currentTimeMillis()-(1000*60*60*24),
-                                "Imperious Leader",
-                                "(888) 555-5038",
-                                null
+                                System.currentTimeMillis()-(1000*60*60*24)
                                 );
                 not.flags |= Notification.FLAG_HIGH_PRIORITY;
                 Intent fullScreenIntent = new Intent(StatusBarTest.this, TestAlertActivity.class);
@@ -248,12 +245,10 @@
                 mHandler.postDelayed(new Runnable() {
                         public void run() {
                             mNotificationManager.notify(1,
-                                    new Notification(StatusBarTest.this,
+                                    new Notification(
                                             R.drawable.ic_statusbar_missedcall,
                                             "tick tick tick",
-                                            System.currentTimeMillis()-(1000*60*60*24),
-                                            "(453) 123-2328",
-                                            "", null
+                                            System.currentTimeMillis()-(1000*60*60*24)
                                             ));
                         }
                     }, 3000);
diff --git a/tests/permission/src/com/android/framework/permission/tests/WindowManagerPermissionTests.java b/tests/permission/src/com/android/framework/permission/tests/WindowManagerPermissionTests.java
index e0f0f05..f015378 100644
--- a/tests/permission/src/com/android/framework/permission/tests/WindowManagerPermissionTests.java
+++ b/tests/permission/src/com/android/framework/permission/tests/WindowManagerPermissionTests.java
@@ -164,7 +164,7 @@
         }
         
         try {
-            mWm.setAppStartingWindow(null, "foo", 0, null, 0, 0, 0, null, false);
+            mWm.setAppStartingWindow(null, "foo", 0, null, null, 0, 0, 0, null, false);
             fail("IWindowManager.setAppStartingWindow did not throw SecurityException as"
                     + " expected");
         } catch (SecurityException e) {
diff --git a/tools/aapt/AaptAssets.cpp b/tools/aapt/AaptAssets.cpp
index 4894196..29d2b87 100644
--- a/tools/aapt/AaptAssets.cpp
+++ b/tools/aapt/AaptAssets.cpp
@@ -969,6 +969,11 @@
         return true;
     }
     
+    if (strcmp(name, "tvdpi") == 0) {
+        if (out) out->density = ResTable_config::DENSITY_TV;
+        return true;
+    }
+    
     if (strcmp(name, "hdpi") == 0) {
         if (out) out->density = ResTable_config::DENSITY_HIGH;
         return true;
diff --git a/tools/aapt/Command.cpp b/tools/aapt/Command.cpp
index 8ac7590..7852197 100644
--- a/tools/aapt/Command.cpp
+++ b/tools/aapt/Command.cpp
@@ -291,6 +291,27 @@
     return value.data;
 }
 
+static int32_t getResolvedIntegerAttribute(const ResTable* resTable, const ResXMLTree& tree,
+        uint32_t attrRes, String8* outError, int32_t defValue = -1)
+{
+    ssize_t idx = indexOfAttribute(tree, attrRes);
+    if (idx < 0) {
+        return defValue;
+    }
+    Res_value value;
+    if (tree.getAttributeValue(idx, &value) != NO_ERROR) {
+        if (value.dataType == Res_value::TYPE_REFERENCE) {
+            resTable->resolveReference(&value, 0);
+        }
+        if (value.dataType < Res_value::TYPE_FIRST_INT
+                || value.dataType > Res_value::TYPE_LAST_INT) {
+            if (outError != NULL) *outError = "attribute is not an integer value";
+            return defValue;
+        }
+    }
+    return value.data;
+}
+
 static String8 getResolvedAttribute(const ResTable* resTable, const ResXMLTree& tree,
         uint32_t attrRes, String8* outError)
 {
@@ -320,11 +341,12 @@
 // These are attribute resource constants for the platform, as found
 // in android.R.attr
 enum {
+    LABEL_ATTR = 0x01010001,
+    ICON_ATTR = 0x01010002,
     NAME_ATTR = 0x01010003,
     VERSION_CODE_ATTR = 0x0101021b,
     VERSION_NAME_ATTR = 0x0101021c,
-    LABEL_ATTR = 0x01010001,
-    ICON_ATTR = 0x01010002,
+    SCREEN_ORIENTATION_ATTR = 0x0101001e,
     MIN_SDK_VERSION_ATTR = 0x0101020c,
     MAX_SDK_VERSION_ATTR = 0x01010271,
     REQ_TOUCH_SCREEN_ATTR = 0x01010227,
@@ -343,6 +365,9 @@
     REQUIRED_ATTR = 0x0101028e,
     SCREEN_SIZE_ATTR = 0x010102ca,
     SCREEN_DENSITY_ATTR = 0x010102cb,
+    REQUIRES_SMALLEST_WIDTH_DP_ATTR = 0x01010364,
+    COMPATIBLE_WIDTH_LIMIT_DP_ATTR = 0x01010365,
+    LARGEST_WIDTH_LIMIT_DP_ATTR = 0x01010366,
 };
 
 const char *getComponentName(String8 &pkgName, String8 &componentName) {
@@ -423,6 +448,24 @@
         return 1;
     }
 
+    // Make a dummy config for retrieving resources...  we need to supply
+    // non-default values for some configs so that we can retrieve resources
+    // in the app that don't have a default.  The most important of these is
+    // the API version because key resources like icons will have an implicit
+    // version if they are using newer config types like density.
+    ResTable_config config;
+    config.language[0] = 'e';
+    config.language[1] = 'n';
+    config.country[0] = 'U';
+    config.country[1] = 'S';
+    config.orientation = ResTable_config::ORIENTATION_PORT;
+    config.density = ResTable_config::DENSITY_MEDIUM;
+    config.sdkVersion = 10000; // Very high.
+    config.screenWidthDp = 320;
+    config.screenHeightDp = 480;
+    config.smallestScreenWidthDp = 320;
+    assets.setConfiguration(config);
+
     const ResTable& res = assets.getResources(false);
     if (&res == NULL) {
         fprintf(stderr, "ERROR: dump failed because no resource table was found\n");
@@ -542,6 +585,19 @@
                 }
             }
         } else if (strcmp("badging", option) == 0) {
+            Vector<String8> locales;
+            res.getLocales(&locales);
+
+            Vector<ResTable_config> configs;
+            res.getConfigurations(&configs);
+            SortedVector<int> densities;
+            const size_t NC = configs.size();
+            for (size_t i=0; i<NC; i++) {
+                int dens = configs[i].density;
+                if (dens == 0) dens = 160;
+                densities.add(dens);
+            }
+
             size_t len;
             ResXMLTree::event_code_t code;
             int depth = 0;
@@ -598,6 +654,10 @@
             bool specTouchscreenFeature = false; // touchscreen-related
             bool specMultitouchFeature = false;
             bool reqDistinctMultitouchFeature = false;
+            bool specScreenPortraitFeature = false;
+            bool specScreenLandscapeFeature = false;
+            bool reqScreenPortraitFeature = false;
+            bool reqScreenLandscapeFeature = false;
             // 2.2 also added some other features that apps can request, but that
             // have no corresponding permission, so we cannot implement any
             // back-compatibility heuristic for them. The below are thus unnecessary
@@ -614,6 +674,9 @@
             int largeScreen = 1;
             int xlargeScreen = 1;
             int anyDensity = 1;
+            int requiresSmallestWidthDp = 0;
+            int compatibleWidthLimitDp = 0;
+            int largestWidthLimitDp = 0;
             String8 pkg;
             String8 activityName;
             String8 activityLabel;
@@ -628,10 +691,11 @@
                     } else if (depth < 3) {
                         if (withinActivity && isMainActivity && isLauncherActivity) {
                             const char *aName = getComponentName(pkg, activityName);
+                            printf("launchable-activity:");
                             if (aName != NULL) {
-                                printf("launchable activity name='%s'", aName);
+                                printf(" name='%s' ", aName);
                             }
-                            printf("label='%s' icon='%s'\n",
+                            printf(" label='%s' icon='%s'\n",
                                     activityLabel.string(),
                                     activityIcon.string());
                         }
@@ -696,23 +760,51 @@
                     withinApplication = false;
                     if (tag == "application") {
                         withinApplication = true;
-                        String8 label = getResolvedAttribute(&res, tree, LABEL_ATTR, &error);
-                         if (error != "") {
-                             fprintf(stderr, "ERROR getting 'android:label' attribute: %s\n", error.string());
-                             goto bail;
+
+                        String8 label;
+                        const size_t NL = locales.size();
+                        for (size_t i=0; i<NL; i++) {
+                            const char* localeStr =  locales[i].string();
+                            assets.setLocale(localeStr != NULL ? localeStr : "");
+                            String8 llabel = getResolvedAttribute(&res, tree, LABEL_ATTR, &error);
+                            if (llabel != "") {
+                                if (localeStr == NULL || strlen(localeStr) == 0) {
+                                    label = llabel;
+                                    printf("application-label:'%s'\n", llabel.string());
+                                } else {
+                                    if (label == "") {
+                                        label = llabel;
+                                    }
+                                    printf("application-label-%s:'%s'\n", localeStr,
+                                            llabel.string());
+                                }
+                            }
                         }
-                        printf("application: label='%s' ", label.string());
+
+                        ResTable_config tmpConfig = config;
+                        const size_t ND = densities.size();
+                        for (size_t i=0; i<ND; i++) {
+                            tmpConfig.density = densities[i];
+                            assets.setConfiguration(tmpConfig);
+                            String8 icon = getResolvedAttribute(&res, tree, ICON_ATTR, &error);
+                            if (icon != "") {
+                                printf("application-icon-%d:'%s'\n", densities[i], icon.string());
+                            }
+                        }
+                        assets.setConfiguration(config);
+
                         String8 icon = getResolvedAttribute(&res, tree, ICON_ATTR, &error);
                         if (error != "") {
                             fprintf(stderr, "ERROR getting 'android:icon' attribute: %s\n", error.string());
                             goto bail;
                         }
-                        printf("icon='%s'\n", icon.string());
                         int32_t testOnly = getIntegerAttribute(tree, TEST_ONLY_ATTR, &error, 0);
                         if (error != "") {
                             fprintf(stderr, "ERROR getting 'android:testOnly' attribute: %s\n", error.string());
                             goto bail;
                         }
+                        printf("application: label='%s' ", label.string());
+                        printf("icon='%s'\n", icon.string());
                         if (testOnly != 0) {
                             printf("testOnly='%d'\n", testOnly);
                         }
@@ -792,6 +884,12 @@
                                 XLARGE_SCREEN_ATTR, NULL, 1);
                         anyDensity = getIntegerAttribute(tree,
                                 ANY_DENSITY_ATTR, NULL, 1);
+                        requiresSmallestWidthDp = getIntegerAttribute(tree,
+                                REQUIRES_SMALLEST_WIDTH_DP_ATTR, NULL, 0);
+                        compatibleWidthLimitDp = getIntegerAttribute(tree,
+                                COMPATIBLE_WIDTH_LIMIT_DP_ATTR, NULL, 0);
+                        largestWidthLimitDp = getIntegerAttribute(tree,
+                                LARGEST_WIDTH_LIMIT_DP_ATTR, NULL, 0);
                     } else if (tag == "uses-feature") {
                         String8 name = getAttribute(tree, NAME_ATTR, &error);
 
@@ -837,6 +935,10 @@
                                 // these have no corresponding permission to check for,
                                 // but should imply the foundational telephony permission
                                 reqTelephonySubFeature = true;
+                            } else if (name == "android.hardware.screen.portrait") {
+                                specScreenPortraitFeature = true;
+                            } else if (name == "android.hardware.screen.landscape") {
+                                specScreenLandscapeFeature = true;
                             }
                             printf("uses-feature%s:'%s'\n",
                                     req ? "" : "-not-required", name.string());
@@ -944,6 +1046,18 @@
                             fprintf(stderr, "ERROR getting 'android:icon' attribute: %s\n", error.string());
                             goto bail;
                         }
+
+                        int32_t orien = getResolvedIntegerAttribute(&res, tree,
+                                SCREEN_ORIENTATION_ATTR, &error);
+                        if (error == "") {
+                            if (orien == 0 || orien == 6 || orien == 8) {
+                                // Requests landscape, sensorLandscape, or reverseLandscape.
+                                reqScreenLandscapeFeature = true;
+                            } else if (orien == 1 || orien == 7 || orien == 9) {
+                                // Requests portrait, sensorPortrait, or reversePortrait.
+                                reqScreenPortraitFeature = true;
+                            }
+                        }
                     } else if (tag == "uses-library") {
                         String8 libraryName = getAttribute(tree, NAME_ATTR, &error);
                         if (error != "") {
@@ -1103,6 +1217,19 @@
                 printf("uses-feature:'android.hardware.touchscreen.multitouch'\n");
             }
 
+            // Landscape/portrait-related compatibility logic
+            if (!specScreenLandscapeFeature && !specScreenPortraitFeature) {
+                // If the app has specified any activities in its manifest
+                // that request a specific orientation, then assume that
+                // orientation is required.
+                if (reqScreenLandscapeFeature) {
+                    printf("uses-feature:'android.hardware.screen.landscape'\n");
+                }
+                if (reqScreenPortraitFeature) {
+                    printf("uses-feature:'android.hardware.screen.portrait'\n");
+                }
+            }
+
             if (hasMainActivity) {
                 printf("main\n");
             }
@@ -1128,6 +1255,34 @@
                 printf("other-services\n");
             }
 
+            // For modern apps, if screen size buckets haven't been specified
+            // but the new width ranges have, then infer the buckets from them.
+            if (smallScreen > 0 && normalScreen > 0 && largeScreen > 0 && xlargeScreen > 0
+                    && requiresSmallestWidthDp > 0) {
+                int compatWidth = compatibleWidthLimitDp;
+                if (compatWidth <= 0) compatWidth = requiresSmallestWidthDp;
+                if (requiresSmallestWidthDp <= 240 && compatWidth >= 240) {
+                    smallScreen = -1;
+                } else {
+                    smallScreen = 0;
+                }
+                if (requiresSmallestWidthDp <= 320 && compatWidth >= 320) {
+                    normalScreen = -1;
+                } else {
+                    normalScreen = 0;
+                }
+                if (requiresSmallestWidthDp <= 480 && compatWidth >= 480) {
+                    largeScreen = -1;
+                } else {
+                    largeScreen = 0;
+                }
+                if (requiresSmallestWidthDp <= 720 && compatWidth >= 720) {
+                    xlargeScreen = -1;
+                } else {
+                    xlargeScreen = 0;
+                }
+            }
+
             // Determine default values for any unspecified screen sizes,
             // based on the target SDK of the package.  As of 4 (donut)
             // the screen size support was introduced, so all default to
@@ -1146,7 +1301,8 @@
                 xlargeScreen = targetSdk >= 9 ? -1 : 0;
             }
             if (anyDensity > 0) {
-                anyDensity = targetSdk >= 4 ? -1 : 0;
+                anyDensity = (targetSdk >= 4 || requiresSmallestWidthDp > 0
+                        || compatibleWidthLimitDp > 0) ? -1 : 0;
             }
             printf("supports-screens:");
             if (smallScreen != 0) printf(" 'small'");
@@ -1154,12 +1310,18 @@
             if (largeScreen != 0) printf(" 'large'");
             if (xlargeScreen != 0) printf(" 'xlarge'");
             printf("\n");
-
             printf("supports-any-density: '%s'\n", anyDensity ? "true" : "false");
+            if (requiresSmallestWidthDp > 0) {
+                printf("requires-smallest-width:'%d'\n", requiresSmallestWidthDp);
+            }
+            if (compatibleWidthLimitDp > 0) {
+                printf("compatible-width-limit:'%d'\n", compatibleWidthLimitDp);
+            }
+            if (largestWidthLimitDp > 0) {
+                printf("largest-width-limit:'%d'\n", largestWidthLimitDp);
+            }
 
             printf("locales:");
-            Vector<String8> locales;
-            res.getLocales(&locales);
             const size_t NL = locales.size();
             for (size_t i=0; i<NL; i++) {
                 const char* localeStr =  locales[i].string();
@@ -1170,16 +1332,6 @@
             }
             printf("\n");
 
-            Vector<ResTable_config> configs;
-            res.getConfigurations(&configs);
-            SortedVector<int> densities;
-            const size_t NC = configs.size();
-            for (size_t i=0; i<NC; i++) {
-                int dens = configs[i].density;
-                if (dens == 0) dens = 160;
-                densities.add(dens);
-            }
-
             printf("densities:");
             const size_t ND = densities.size();
             for (size_t i=0; i<ND; i++) {
diff --git a/tools/aapt/ResourceTable.cpp b/tools/aapt/ResourceTable.cpp
index 5c5b4fd..81b924a 100644
--- a/tools/aapt/ResourceTable.cpp
+++ b/tools/aapt/ResourceTable.cpp
@@ -1963,10 +1963,11 @@
                                  bool onlyPublic) const
 {
     String16 package, type, name;
+    bool refOnlyPublic = true;
     if (!ResTable::expandResourceRef(
         ref.string(), ref.size(), &package, &type, &name,
         defType, defPackage ? defPackage:&mAssetsPackage,
-        outErrorMsg)) {
+        outErrorMsg, &refOnlyPublic)) {
         NOISY(printf("Expanding resource: ref=%s\n",
                      String8(ref).string()));
         NOISY(printf("Expanding resource: defType=%s\n",
@@ -1979,7 +1980,7 @@
                      String8(name).string()));
         return 0;
     }
-    uint32_t res = getResId(package, type, name, onlyPublic);
+    uint32_t res = getResId(package, type, name, onlyPublic && refOnlyPublic);
     NOISY(printf("Expanded resource: p=%s, t=%s, n=%s, res=%d\n",
                  String8(package).string(), String8(type).string(),
                  String8(name).string(), res));
diff --git a/tools/aapt/ResourceTable.h b/tools/aapt/ResourceTable.h
index bbb8140..734c541 100644
--- a/tools/aapt/ResourceTable.h
+++ b/tools/aapt/ResourceTable.h
@@ -162,13 +162,13 @@
     uint32_t getResId(const String16& package,
                       const String16& type,
                       const String16& name,
-                      bool onlyPublic = false) const;
+                      bool onlyPublic = true) const;
 
     uint32_t getResId(const String16& ref,
                       const String16* defType = NULL,
                       const String16* defPackage = NULL,
                       const char** outErrorMsg = NULL,
-                      bool onlyPublic = false) const;
+                      bool onlyPublic = true) const;
 
     static bool isValidResourceName(const String16& s);
     
diff --git a/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java
index 922cd4c..b4448a9 100644
--- a/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java
@@ -425,7 +425,7 @@
         AffineTransform matrixTx = matrixDelegate.getAffineTransform();
 
         // combine them so that the given matrix is applied after.
-        currentTx.preConcatenate(matrixTx);
+        currentTx.concatenate(matrixTx);
 
         // give it to the graphics2D as a new matrix replacing all previous transform
         snapshot.setTransform(currentTx);
@@ -717,7 +717,7 @@
     /*package*/ static void native_drawCircle(int nativeCanvas,
             float cx, float cy, float radius, int paint) {
         native_drawOval(nativeCanvas,
-                new RectF(cx - radius, cy - radius, radius*2, radius*2),
+                new RectF(cx - radius, cy - radius, radius, radius),
                 paint);
     }
 
@@ -1093,6 +1093,33 @@
     }
 
     @LayoutlibDelegate
+    /*package*/ static void native_drawTextWithGlyphs(int nativeCanvas, char[] text,
+            int index, int count, float x,
+            float y, int flags, int paint) {
+        native_drawText(nativeCanvas, text, index, count, x, y, flags, paint);
+    }
+
+    @LayoutlibDelegate
+    /*package*/ static void native_drawTextWithGlyphs(int nativeCanvas, String text,
+            int start, int end, float x,
+            float y, int flags, int paint) {
+        int count = end - start;
+        char[] buffer = TemporaryBuffer.obtain(count);
+        TextUtils.getChars(text, start, end, buffer, 0);
+
+        native_drawText(nativeCanvas, text, 0, count, x, y, flags, paint);
+    }
+
+    @LayoutlibDelegate
+    /*package*/ static void native_drawGlyphs(int nativeCanvas, char[] glyphs,
+            int index, int count, float x,
+            float y, int flags, int paint) {
+        // FIXME
+        Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
+                "Canvas.drawGlyphs is not supported.", null, null /*data*/);
+    }
+
+    @LayoutlibDelegate
     /*package*/ static void native_drawPosText(int nativeCanvas,
                                                   char[] text, int index,
                                                   int count, float[] pos,
diff --git a/tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java
index 373f482..7777e19 100644
--- a/tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java
@@ -940,9 +940,16 @@
     }
 
     @LayoutlibDelegate
+    /* package */static int native_getTextGlyphs(int native_object, String text, int start,
+            int end, int contextStart, int contextEnd, int flags, char[] glyphs) {
+        // FIXME
+        return 0;
+    }
+
+    @LayoutlibDelegate
     /*package*/ static float native_getTextRunAdvances(int native_object,
             char[] text, int index, int count, int contextIndex, int contextCount,
-            int flags, float[] advances, int advancesIndex) {
+            int flags, float[] advances, int advancesIndex, int reserved) {
         // get the delegate from the native int.
         Paint_Delegate delegate = sManager.getDelegate(native_object);
         if (delegate == null) {
@@ -986,14 +993,14 @@
     @LayoutlibDelegate
     /*package*/ static float native_getTextRunAdvances(int native_object,
             String text, int start, int end, int contextStart, int contextEnd,
-            int flags, float[] advances, int advancesIndex) {
+            int flags, float[] advances, int advancesIndex, int reserved) {
         // FIXME: support contextStart, contextEnd and direction flag
         int count = end - start;
         char[] buffer = TemporaryBuffer.obtain(count);
         TextUtils.getChars(text, start, end, buffer, 0);
 
         return native_getTextRunAdvances(native_object, buffer, 0, count, contextStart,
-                contextEnd - contextStart, flags, advances, advancesIndex);
+                contextEnd - contextStart, flags, advances, advancesIndex, reserved);
     }
 
     @LayoutlibDelegate
diff --git a/tools/layoutlib/bridge/src/android/os/HandlerThread_Delegate.java b/tools/layoutlib/bridge/src/android/os/HandlerThread_Delegate.java
new file mode 100644
index 0000000..afbe97c0
--- /dev/null
+++ b/tools/layoutlib/bridge/src/android/os/HandlerThread_Delegate.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.os;
+
+import com.android.layoutlib.bridge.android.BridgeContext;
+import com.android.layoutlib.bridge.impl.RenderAction;
+import com.android.tools.layoutlib.annotations.LayoutlibDelegate;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Delegate overriding selected methods of android.os.HandlerThread
+ *
+ * Through the layoutlib_create tool, selected methods of Handler have been replaced
+ * by calls to methods of the same name in this delegate class.
+ *
+ *
+ */
+public class HandlerThread_Delegate {
+
+    private static Map<BridgeContext, List<HandlerThread>> sThreads =
+            new HashMap<BridgeContext, List<HandlerThread>>();
+
+    public static void cleanUp(BridgeContext context) {
+        List<HandlerThread> list = sThreads.get(context);
+        if (list != null) {
+            for (HandlerThread thread : list) {
+                thread.quit();
+            }
+
+            list.clear();
+            sThreads.remove(context);
+        }
+    }
+
+    // -------- Delegate methods
+
+    @LayoutlibDelegate
+    /*package*/ static void run(HandlerThread theThread) {
+        // record the thread so that it can be quit() on clean up.
+        BridgeContext context = RenderAction.getCurrentContext();
+        List<HandlerThread> list = sThreads.get(context);
+        if (list == null) {
+            list = new ArrayList<HandlerThread>();
+            sThreads.put(context, list);
+        }
+
+        list.add(theThread);
+
+        // ---- START DEFAULT IMPLEMENTATION.
+
+        theThread.mTid = Process.myTid();
+        Looper.prepare();
+        synchronized (theThread) {
+            theThread.mLooper = Looper.myLooper();
+            theThread.notifyAll();
+        }
+        Process.setThreadPriority(theThread.mPriority);
+        theThread.onLooperPrepared();
+        Looper.loop();
+        theThread.mTid = -1;
+    }
+}
diff --git a/tools/layoutlib/bridge/src/android/view/LayoutInflater_Delegate.java b/tools/layoutlib/bridge/src/android/view/LayoutInflater_Delegate.java
index 0f3cf57..3ef3288 100644
--- a/tools/layoutlib/bridge/src/android/view/LayoutInflater_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/view/LayoutInflater_Delegate.java
@@ -22,7 +22,10 @@
 import org.xmlpull.v1.XmlPullParser;
 import org.xmlpull.v1.XmlPullParserException;
 
+import android.content.res.TypedArray;
+import android.content.res.XmlResourceParser;
 import android.util.AttributeSet;
+import android.util.Xml;
 
 import java.io.IOException;
 
@@ -35,6 +38,8 @@
  */
 public class LayoutInflater_Delegate {
 
+    public static boolean sIsInInclude = false;
+
     /**
      * Recursive method used to descend down the xml hierarchy and instantiate
      * views, instantiate their children, and then call onFinishInflate().
@@ -94,4 +99,128 @@
             }
         }
     }
+
+    @LayoutlibDelegate
+    public static void parseInclude(
+            LayoutInflater thisInflater,
+            XmlPullParser parser, View parent, AttributeSet attrs)
+            throws XmlPullParserException, IOException {
+
+        int type;
+
+        if (parent instanceof ViewGroup) {
+            final int layout = attrs.getAttributeResourceValue(null, "layout", 0);
+            if (layout == 0) {
+                final String value = attrs.getAttributeValue(null, "layout");
+                if (value == null) {
+                    throw new InflateException("You must specifiy a layout in the"
+                            + " include tag: <include layout=\"@layout/layoutID\" />");
+                } else {
+                    throw new InflateException("You must specifiy a valid layout "
+                            + "reference. The layout ID " + value + " is not valid.");
+                }
+            } else {
+                final XmlResourceParser childParser =
+                    thisInflater.getContext().getResources().getLayout(layout);
+
+                try {
+                    final AttributeSet childAttrs = Xml.asAttributeSet(childParser);
+
+                    while ((type = childParser.next()) != XmlPullParser.START_TAG &&
+                            type != XmlPullParser.END_DOCUMENT) {
+                        // Empty.
+                    }
+
+                    if (type != XmlPullParser.START_TAG) {
+                        throw new InflateException(childParser.getPositionDescription() +
+                                ": No start tag found!");
+                    }
+
+                    final String childName = childParser.getName();
+
+                    if (LayoutInflater.TAG_MERGE.equals(childName)) {
+                        // Inflate all children.
+                        thisInflater.rInflate(childParser, parent, childAttrs, false);
+                    } else {
+                        final View view = thisInflater.createViewFromTag(parent, childName, childAttrs);
+                        final ViewGroup group = (ViewGroup) parent;
+
+                        // We try to load the layout params set in the <include /> tag. If
+                        // they don't exist, we will rely on the layout params set in the
+                        // included XML file.
+                        // During a layoutparams generation, a runtime exception is thrown
+                        // if either layout_width or layout_height is missing. We catch
+                        // this exception and set localParams accordingly: true means we
+                        // successfully loaded layout params from the <include /> tag,
+                        // false means we need to rely on the included layout params.
+                        ViewGroup.LayoutParams params = null;
+                        try {
+                            // ---- START CHANGES
+                            sIsInInclude = true;
+                            // ---- END CHANGES
+
+                            params = group.generateLayoutParams(attrs);
+
+                        } catch (RuntimeException e) {
+                            // ---- START CHANGES
+                            sIsInInclude = false;
+                            // ---- END CHANGES
+
+                            params = group.generateLayoutParams(childAttrs);
+                        } finally {
+                            // ---- START CHANGES
+                            sIsInInclude = false;
+                            // ---- END CHANGES
+
+                            if (params != null) {
+                                view.setLayoutParams(params);
+                            }
+                        }
+
+                        // Inflate all children.
+                        thisInflater.rInflate(childParser, view, childAttrs, true);
+
+                        // Attempt to override the included layout's android:id with the
+                        // one set on the <include /> tag itself.
+                        TypedArray a = thisInflater.mContext.obtainStyledAttributes(attrs,
+                            com.android.internal.R.styleable.View, 0, 0);
+                        int id = a.getResourceId(com.android.internal.R.styleable.View_id, View.NO_ID);
+                        // While we're at it, let's try to override android:visibility.
+                        int visibility = a.getInt(com.android.internal.R.styleable.View_visibility, -1);
+                        a.recycle();
+
+                        if (id != View.NO_ID) {
+                            view.setId(id);
+                        }
+
+                        switch (visibility) {
+                            case 0:
+                                view.setVisibility(View.VISIBLE);
+                                break;
+                            case 1:
+                                view.setVisibility(View.INVISIBLE);
+                                break;
+                            case 2:
+                                view.setVisibility(View.GONE);
+                                break;
+                        }
+
+                        group.addView(view);
+                    }
+                } finally {
+                    childParser.close();
+                }
+            }
+        } else {
+            throw new InflateException("<include /> can only be used inside of a ViewGroup");
+        }
+
+        final int currentDepth = parser.getDepth();
+        while (((type = parser.next()) != XmlPullParser.END_TAG ||
+                parser.getDepth() > currentDepth) && type != XmlPullParser.END_DOCUMENT) {
+            // Empty
+        }
+    }
+
+
 }
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java
index 144ec42..3ba3257 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java
@@ -196,7 +196,7 @@
                 Capability.UNBOUND_RENDERING,
                 Capability.CUSTOM_BACKGROUND_COLOR,
                 Capability.RENDER,
-                //Capability.LAYOUT_ONLY, // disable to run on ADT 10.0 which doesn't include this.
+                Capability.LAYOUT_ONLY,
                 Capability.EMBEDDED_LAYOUT,
                 Capability.VIEW_MANIPULATION,
                 Capability.PLAY_ANIMATION,
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
index e536028..47fa68e 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
@@ -25,11 +25,11 @@
 import com.android.ide.common.rendering.api.StyleResourceValue;
 import com.android.layoutlib.bridge.Bridge;
 import com.android.layoutlib.bridge.BridgeConstants;
+import com.android.layoutlib.bridge.impl.ParserFactory;
 import com.android.layoutlib.bridge.impl.Stack;
 import com.android.resources.ResourceType;
 import com.android.util.Pair;
 
-import org.kxml2.io.KXmlParser;
 import org.xmlpull.v1.XmlPullParser;
 import org.xmlpull.v1.XmlPullParserException;
 
@@ -71,7 +71,6 @@
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
-import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.HashMap;
@@ -79,6 +78,8 @@
 import java.util.Map;
 import java.util.TreeMap;
 import java.util.Map.Entry;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicReference;
 
 /**
  * Custom implementation of Context/Activity to handle non compiled resources.
@@ -205,6 +206,9 @@
      * @param parser the parser to add.
      */
     public void pushParser(BridgeXmlBlockParser parser) {
+        if (ParserFactory.LOG_PARSER) {
+            System.out.println("PUSH " + parser.getParser().toString());
+        }
         mParserStack.push(parser);
     }
 
@@ -212,7 +216,10 @@
      * Removes the parser at the top of the stack
      */
     public void popParser() {
-        mParserStack.pop();
+        BridgeXmlBlockParser parser = mParserStack.pop();
+        if (ParserFactory.LOG_PARSER) {
+            System.out.println("POPD " + parser.getParser().toString());
+        }
     }
 
     /**
@@ -300,12 +307,17 @@
 
     public Pair<View, Boolean> inflateView(ResourceReference resource, ViewGroup parent,
             boolean attachToRoot, boolean skipCallbackParser) {
-        String layoutName = resource.getName();
         boolean isPlatformLayout = resource.isFramework();
 
         if (isPlatformLayout == false && skipCallbackParser == false) {
             // check if the project callback can provide us with a custom parser.
-            ILayoutPullParser parser = mProjectCallback.getParser(layoutName);
+            ILayoutPullParser parser;
+            if (resource instanceof ResourceValue) {
+                parser = mProjectCallback.getParser((ResourceValue) resource);
+            } else {
+                parser = mProjectCallback.getParser(resource.getName());
+            }
+
             if (parser != null) {
                 BridgeXmlBlockParser blockParser = new BridgeXmlBlockParser(parser,
                         this, resource.isFramework());
@@ -340,9 +352,7 @@
                 // we need to create a pull parser around the layout XML file, and then
                 // give that to our XmlBlockParser
                 try {
-                    KXmlParser parser = new KXmlParser();
-                    parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
-                    parser.setInput(new FileReader(xml));
+                    XmlPullParser parser = ParserFactory.create(xml);
 
                     // set the resource ref to have correct view cookies
                     mBridgeInflater.setResourceReference(resource);
@@ -373,7 +383,7 @@
         } else {
             Bridge.getLog().error(LayoutLog.TAG_BROKEN,
                     String.format("Layout %s%s does not exist.", isPlatformLayout ? "android:" : "",
-                            layoutName), null);
+                            resource.getName()), null);
         }
 
         return Pair.of(null, false);
@@ -508,20 +518,20 @@
             return null;
         }
 
-        boolean[] frameworkAttributes = new boolean[1];
-        TreeMap<Integer, String> styleNameMap = searchAttrs(attrs, frameworkAttributes);
+        AtomicBoolean frameworkAttributes = new AtomicBoolean();
+        AtomicReference<String> attrName = new AtomicReference<String>();
+        TreeMap<Integer, String> styleNameMap = searchAttrs(attrs, frameworkAttributes, attrName);
 
         BridgeTypedArray ta = ((BridgeResources) mSystemResources).newTypeArray(attrs.length,
-                isPlatformFile);
-
-        // resolve the defStyleAttr value into a IStyleResourceValue
-        StyleResourceValue defStyleValues = null;
+                isPlatformFile, frameworkAttributes.get(), attrName.get());
 
         // look for a custom style.
         String customStyle = null;
         if (set != null) {
             customStyle = set.getAttributeValue(null /* namespace*/, "style");
         }
+
+        StyleResourceValue customStyleValues = null;
         if (customStyle != null) {
             ResourceValue item = mRenderResources.findResValue(customStyle,
                     false /*forceFrameworkOnly*/);
@@ -530,80 +540,81 @@
             item = mRenderResources.resolveResValue(item);
 
             if (item instanceof StyleResourceValue) {
-                defStyleValues = (StyleResourceValue)item;
+                customStyleValues = (StyleResourceValue)item;
             }
         }
 
-        if (defStyleValues == null) {
-            if (defStyleAttr != 0) {
-                // get the name from the int.
-                String defStyleName = searchAttr(defStyleAttr);
+        // resolve the defStyleAttr value into a IStyleResourceValue
+        StyleResourceValue defStyleValues = null;
 
-                if (defaultPropMap != null) {
-                    defaultPropMap.put("style", defStyleName);
+        if (defStyleAttr != 0) {
+            // get the name from the int.
+            String defStyleName = searchAttr(defStyleAttr);
+
+            if (defaultPropMap != null) {
+                defaultPropMap.put("style", defStyleName);
+            }
+
+            // look for the style in the current theme, and its parent:
+            ResourceValue item = mRenderResources.findItemInTheme(defStyleName);
+
+            if (item != null) {
+                // item is a reference to a style entry. Search for it.
+                item = mRenderResources.findResValue(item.getValue(),
+                        false /*forceFrameworkOnly*/);
+
+                if (item instanceof StyleResourceValue) {
+                    defStyleValues = (StyleResourceValue)item;
                 }
+            } else {
+                Bridge.getLog().error(null,
+                        String.format(
+                                "Failed to find style '%s' in current theme", defStyleName),
+                        null /*data*/);
+            }
+        } else if (defStyleRes != 0) {
+            Pair<ResourceType, String> value = Bridge.resolveResourceId(defStyleRes);
+            if (value == null) {
+                value = mProjectCallback.resolveResourceId(defStyleRes);
+            }
 
-                // look for the style in the current theme, and its parent:
-                ResourceValue item = mRenderResources.findItemInTheme(defStyleName);
-
-                if (item != null) {
-                    // item is a reference to a style entry. Search for it.
-                    item = mRenderResources.findResValue(item.getValue(),
-                            false /*forceFrameworkOnly*/);
-
-                    if (item instanceof StyleResourceValue) {
-                        defStyleValues = (StyleResourceValue)item;
-                    }
-                } else {
-                    Bridge.getLog().error(null,
-                            String.format(
-                                    "Failed to find style '%s' in current theme", defStyleName),
-                            null /*data*/);
-                }
-            } else if (defStyleRes != 0) {
-                Pair<ResourceType, String> value = Bridge.resolveResourceId(defStyleRes);
-                if (value == null) {
-                    value = mProjectCallback.resolveResourceId(defStyleRes);
-                }
-
-                if (value != null) {
-                    if (value.getFirst() == ResourceType.STYLE) {
-                        // look for the style in the current theme, and its parent:
-                        ResourceValue item = mRenderResources.findItemInTheme(value.getSecond());
-                        if (item != null) {
-                            if (item instanceof StyleResourceValue) {
-                                if (defaultPropMap != null) {
-                                    defaultPropMap.put("style", item.getName());
-                                }
-
-                                defStyleValues = (StyleResourceValue)item;
+            if (value != null) {
+                if (value.getFirst() == ResourceType.STYLE) {
+                    // look for the style in the current theme, and its parent:
+                    ResourceValue item = mRenderResources.findItemInTheme(value.getSecond());
+                    if (item != null) {
+                        if (item instanceof StyleResourceValue) {
+                            if (defaultPropMap != null) {
+                                defaultPropMap.put("style", item.getName());
                             }
-                        } else {
-                            Bridge.getLog().error(null,
-                                    String.format(
-                                            "Style with id 0x%x (resolved to '%s') does not exist.",
-                                            defStyleRes, value.getSecond()),
-                                    null /*data*/);
+
+                            defStyleValues = (StyleResourceValue)item;
                         }
                     } else {
                         Bridge.getLog().error(null,
                                 String.format(
-                                        "Resouce id 0x%x is not of type STYLE (instead %s)",
-                                        defStyleRes, value.getFirst().toString()),
+                                        "Style with id 0x%x (resolved to '%s') does not exist.",
+                                        defStyleRes, value.getSecond()),
                                 null /*data*/);
                     }
                 } else {
                     Bridge.getLog().error(null,
                             String.format(
-                                    "Failed to find style with id 0x%x in current theme",
-                                    defStyleRes),
+                                    "Resouce id 0x%x is not of type STYLE (instead %s)",
+                                    defStyleRes, value.getFirst().toString()),
                             null /*data*/);
                 }
+            } else {
+                Bridge.getLog().error(null,
+                        String.format(
+                                "Failed to find style with id 0x%x in current theme",
+                                defStyleRes),
+                        null /*data*/);
             }
         }
 
         String namespace = BridgeConstants.NS_RESOURCES;
-        if (frameworkAttributes[0] == false) {
+        if (frameworkAttributes.get() == false) {
             // need to use the application namespace
             namespace = mProjectCallback.getNamespace();
         }
@@ -623,8 +634,13 @@
                 if (value == null) {
                     ResourceValue resValue = null;
 
-                    // look for the value in the defStyle first (and its parent if needed)
-                    if (defStyleValues != null) {
+                    // look for the value in the custom style first (and its parent if needed)
+                    if (customStyleValues != null) {
+                        resValue = mRenderResources.findItemInStyle(customStyleValues, name);
+                    }
+
+                    // then look for the value in the default Style (and its parent if needed)
+                    if (resValue == null && defStyleValues != null) {
                         resValue = mRenderResources.findItemInStyle(defStyleValues, name);
                     }
 
@@ -675,23 +691,25 @@
      */
     private BridgeTypedArray createStyleBasedTypedArray(StyleResourceValue style, int[] attrs)
             throws Resources.NotFoundException {
-        TreeMap<Integer, String> styleNameMap = searchAttrs(attrs, null);
 
         BridgeTypedArray ta = ((BridgeResources) mSystemResources).newTypeArray(attrs.length,
-                false /* platformResourceFlag */);
+                false, true, null);
 
-        // loop through all the values in the style map, and init the TypedArray with
-        // the style we got from the dynamic id
-        for (Entry<Integer, String> styleAttribute : styleNameMap.entrySet()) {
-            int index = styleAttribute.getKey().intValue();
+        // for each attribute, get its name so that we can search it in the style
+        for (int i = 0 ; i < attrs.length ; i++) {
+            Pair<ResourceType, String> resolvedResource = Bridge.resolveResourceId(attrs[i]);
+            if (resolvedResource != null) {
+                String attrName = resolvedResource.getSecond();
+                // look for the value in the given style
+                ResourceValue resValue = mRenderResources.findItemInStyle(style, attrName);
 
-            String name = styleAttribute.getValue();
+                if (resValue != null) {
+                    // resolve it to make sure there are no references left.
+                    ta.bridgeSetValue(i, attrName, mRenderResources.resolveResValue(resValue));
 
-            // get the value from the style, or its parent styles.
-            ResourceValue resValue = mRenderResources.findItemInStyle(style, name);
-
-            // resolve it to make sure there are no references left.
-            ta.bridgeSetValue(index, name, mRenderResources.resolveResValue(resValue));
+                    resValue = mRenderResources.resolveResValue(resValue);
+                }
+            }
         }
 
         ta.sealArray();
@@ -710,10 +728,13 @@
      * that is used to reference the attribute later in the TypedArray.
      *
      * @param attrs An attribute array reference given to obtainStyledAttributes.
+     * @param outFrameworkFlag out value indicating if the attr array is a framework value
+     * @param outAttrName out value for the resolved attr name.
      * @return A sorted map Attribute-Value to Attribute-Name for all attributes declared by the
      *         attribute array. Returns null if nothing is found.
      */
-    private TreeMap<Integer,String> searchAttrs(int[] attrs, boolean[] outFrameworkFlag) {
+    private TreeMap<Integer,String> searchAttrs(int[] attrs, AtomicBoolean outFrameworkFlag,
+            AtomicReference<String> outAttrName) {
         // get the name of the array from the framework resources
         String arrayName = Bridge.resolveResourceId(attrs);
         if (arrayName != null) {
@@ -730,7 +751,10 @@
             }
 
             if (outFrameworkFlag != null) {
-                outFrameworkFlag[0] = true;
+                outFrameworkFlag.set(true);
+            }
+            if (outAttrName != null) {
+                outAttrName.set(arrayName);
             }
 
             return attributes;
@@ -752,7 +776,10 @@
             }
 
             if (outFrameworkFlag != null) {
-                outFrameworkFlag[0] = false;
+                outFrameworkFlag.set(false);
+            }
+            if (outAttrName != null) {
+                outAttrName.set(arrayName);
             }
 
             return attributes;
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeInflater.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeInflater.java
index d6bbebd..4a6393d 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeInflater.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeInflater.java
@@ -22,10 +22,10 @@
 import com.android.ide.common.rendering.api.ResourceReference;
 import com.android.ide.common.rendering.api.ResourceValue;
 import com.android.layoutlib.bridge.Bridge;
+import com.android.layoutlib.bridge.impl.ParserFactory;
 import com.android.resources.ResourceType;
 import com.android.util.Pair;
 
-import org.kxml2.io.KXmlParser;
 import org.xmlpull.v1.XmlPullParser;
 
 import android.content.Context;
@@ -36,7 +36,6 @@
 import android.view.ViewGroup;
 
 import java.io.File;
-import java.io.FileReader;
 
 /**
  * Custom implementation of {@link LayoutInflater} to handle custom views.
@@ -175,9 +174,7 @@
                 File f = new File(value.getValue());
                 if (f.isFile()) {
                     try {
-                        KXmlParser parser = new KXmlParser();
-                        parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
-                        parser.setInput(new FileReader(f));
+                        XmlPullParser parser = ParserFactory.create(f);
 
                         BridgeXmlBlockParser bridgeParser = new BridgeXmlBlockParser(
                                 parser, bridgeContext, false);
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeResources.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeResources.java
index 273e493..1756496f 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeResources.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeResources.java
@@ -21,12 +21,12 @@
 import com.android.ide.common.rendering.api.ResourceValue;
 import com.android.layoutlib.bridge.Bridge;
 import com.android.layoutlib.bridge.BridgeConstants;
+import com.android.layoutlib.bridge.impl.ParserFactory;
 import com.android.layoutlib.bridge.impl.ResourceHelper;
 import com.android.ninepatch.NinePatch;
 import com.android.resources.ResourceType;
 import com.android.util.Pair;
 
-import org.kxml2.io.KXmlParser;
 import org.xmlpull.v1.XmlPullParser;
 import org.xmlpull.v1.XmlPullParserException;
 
@@ -46,7 +46,6 @@
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
-import java.io.FileReader;
 import java.io.InputStream;
 
 /**
@@ -126,18 +125,22 @@
         mProjectCallback = projectCallback;
     }
 
-    public BridgeTypedArray newTypeArray(int numEntries, boolean platformFile) {
-        return new BridgeTypedArray(this, mContext, numEntries, platformFile);
+    public BridgeTypedArray newTypeArray(int numEntries, boolean platformFile,
+            boolean platformStyleable, String styleableName) {
+        return new BridgeTypedArray(this, mContext, numEntries, platformFile,
+                platformStyleable, styleableName);
     }
 
-    private ResourceValue getResourceValue(int id, boolean[] platformResFlag_out) {
+    private Pair<String, ResourceValue> getResourceValue(int id, boolean[] platformResFlag_out) {
         // first get the String related to this id in the framework
         Pair<ResourceType, String> resourceInfo = Bridge.resolveResourceId(id);
 
         if (resourceInfo != null) {
             platformResFlag_out[0] = true;
-            return mContext.getRenderResources().getFrameworkResource(
-                    resourceInfo.getFirst(), resourceInfo.getSecond());
+            String attributeName = resourceInfo.getSecond();
+
+            return Pair.of(attributeName, mContext.getRenderResources().getFrameworkResource(
+                    resourceInfo.getFirst(), attributeName));
         }
 
         // didn't find a match in the framework? look in the project.
@@ -146,8 +149,10 @@
 
             if (resourceInfo != null) {
                 platformResFlag_out[0] = false;
-                return mContext.getRenderResources().getProjectResource(
-                        resourceInfo.getFirst(), resourceInfo.getSecond());
+                String attributeName = resourceInfo.getSecond();
+
+                return Pair.of(attributeName, mContext.getRenderResources().getProjectResource(
+                        resourceInfo.getFirst(), attributeName));
             }
         }
 
@@ -156,10 +161,10 @@
 
     @Override
     public Drawable getDrawable(int id) throws NotFoundException {
-        ResourceValue value = getResourceValue(id, mPlatformResourceFlag);
+        Pair<String, ResourceValue> value = getResourceValue(id, mPlatformResourceFlag);
 
         if (value != null) {
-            return ResourceHelper.getDrawable(value, mContext);
+            return ResourceHelper.getDrawable(value.getSecond(), mContext);
         }
 
         // id was not found or not resolved. Throw a NotFoundException.
@@ -171,11 +176,11 @@
 
     @Override
     public int getColor(int id) throws NotFoundException {
-        ResourceValue value = getResourceValue(id, mPlatformResourceFlag);
+        Pair<String, ResourceValue> value = getResourceValue(id, mPlatformResourceFlag);
 
         if (value != null) {
             try {
-                return ResourceHelper.getColor(value.getValue());
+                return ResourceHelper.getColor(value.getSecond().getValue());
             } catch (NumberFormatException e) {
                 Bridge.getLog().error(LayoutLog.TAG_RESOURCES_FORMAT, e.getMessage(), e,
                         null /*data*/);
@@ -192,10 +197,11 @@
 
     @Override
     public ColorStateList getColorStateList(int id) throws NotFoundException {
-        ResourceValue resValue = getResourceValue(id, mPlatformResourceFlag);
+        Pair<String, ResourceValue> resValue = getResourceValue(id, mPlatformResourceFlag);
 
         if (resValue != null) {
-            ColorStateList stateList = ResourceHelper.getColorStateList(resValue, mContext);
+            ColorStateList stateList = ResourceHelper.getColorStateList(resValue.getSecond(),
+                    mContext);
             if (stateList != null) {
                 return stateList;
             }
@@ -210,10 +216,10 @@
 
     @Override
     public CharSequence getText(int id) throws NotFoundException {
-        ResourceValue value = getResourceValue(id, mPlatformResourceFlag);
+        Pair<String, ResourceValue> value = getResourceValue(id, mPlatformResourceFlag);
 
         if (value != null) {
-            return value.getValue();
+            return value.getSecond().getValue();
         }
 
         // id was not found or not resolved. Throw a NotFoundException.
@@ -225,15 +231,16 @@
 
     @Override
     public XmlResourceParser getLayout(int id) throws NotFoundException {
-        ResourceValue value = getResourceValue(id, mPlatformResourceFlag);
+        Pair<String, ResourceValue> v = getResourceValue(id, mPlatformResourceFlag);
 
-        if (value != null) {
+        if (v != null) {
+            ResourceValue value = v.getSecond();
             XmlPullParser parser = null;
 
             try {
                 // check if the current parser can provide us with a custom parser.
                 if (mPlatformResourceFlag[0] == false) {
-                    parser = mProjectCallback.getParser(value.getName());
+                    parser = mProjectCallback.getParser(value);
                 }
 
                 // create a new one manually if needed.
@@ -242,9 +249,7 @@
                     if (xml.isFile()) {
                         // we need to create a pull parser around the layout XML file, and then
                         // give that to our XmlBlockParser
-                        parser = new KXmlParser();
-                        parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
-                        parser.setInput(new FileReader(xml));
+                        parser = ParserFactory.create(xml);
                     }
                 }
 
@@ -270,9 +275,10 @@
 
     @Override
     public XmlResourceParser getAnimation(int id) throws NotFoundException {
-        ResourceValue value = getResourceValue(id, mPlatformResourceFlag);
+        Pair<String, ResourceValue> v = getResourceValue(id, mPlatformResourceFlag);
 
-        if (value != null) {
+        if (v != null) {
+            ResourceValue value = v.getSecond();
             XmlPullParser parser = null;
 
             try {
@@ -280,9 +286,7 @@
                 if (xml.isFile()) {
                     // we need to create a pull parser around the layout XML file, and then
                     // give that to our XmlBlockParser
-                    parser = new KXmlParser();
-                    parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
-                    parser.setInput(new FileReader(xml));
+                    parser = ParserFactory.create(xml);
 
                     return new BridgeXmlBlockParser(parser, mContext, mPlatformResourceFlag[0]);
                 }
@@ -316,10 +320,10 @@
 
     @Override
     public float getDimension(int id) throws NotFoundException {
-        ResourceValue value = getResourceValue(id, mPlatformResourceFlag);
+        Pair<String, ResourceValue> value = getResourceValue(id, mPlatformResourceFlag);
 
         if (value != null) {
-            String v = value.getValue();
+            String v = value.getSecond().getValue();
 
             if (v != null) {
                 if (v.equals(BridgeConstants.MATCH_PARENT) ||
@@ -329,7 +333,8 @@
                     return LayoutParams.WRAP_CONTENT;
                 }
 
-                if (ResourceHelper.stringToFloat(v, mTmpValue) &&
+                if (ResourceHelper.parseFloatAttribute(
+                        value.getFirst(), v, mTmpValue, true /*requireUnit*/) &&
                         mTmpValue.type == TypedValue.TYPE_DIMENSION) {
                     return mTmpValue.getDimension(mMetrics);
                 }
@@ -345,13 +350,14 @@
 
     @Override
     public int getDimensionPixelOffset(int id) throws NotFoundException {
-        ResourceValue value = getResourceValue(id, mPlatformResourceFlag);
+        Pair<String, ResourceValue> value = getResourceValue(id, mPlatformResourceFlag);
 
         if (value != null) {
-            String v = value.getValue();
+            String v = value.getSecond().getValue();
 
             if (v != null) {
-                if (ResourceHelper.stringToFloat(v, mTmpValue) &&
+                if (ResourceHelper.parseFloatAttribute(
+                        value.getFirst(), v, mTmpValue, true /*requireUnit*/) &&
                         mTmpValue.type == TypedValue.TYPE_DIMENSION) {
                     return TypedValue.complexToDimensionPixelOffset(mTmpValue.data, mMetrics);
                 }
@@ -367,13 +373,14 @@
 
     @Override
     public int getDimensionPixelSize(int id) throws NotFoundException {
-        ResourceValue value = getResourceValue(id, mPlatformResourceFlag);
+        Pair<String, ResourceValue> value = getResourceValue(id, mPlatformResourceFlag);
 
         if (value != null) {
-            String v = value.getValue();
+            String v = value.getSecond().getValue();
 
             if (v != null) {
-                if (ResourceHelper.stringToFloat(v, mTmpValue) &&
+                if (ResourceHelper.parseFloatAttribute(
+                        value.getFirst(), v, mTmpValue, true /*requireUnit*/) &&
                         mTmpValue.type == TypedValue.TYPE_DIMENSION) {
                     return TypedValue.complexToDimensionPixelSize(mTmpValue.data, mMetrics);
                 }
@@ -389,10 +396,10 @@
 
     @Override
     public int getInteger(int id) throws NotFoundException {
-        ResourceValue value = getResourceValue(id, mPlatformResourceFlag);
+        Pair<String, ResourceValue> value = getResourceValue(id, mPlatformResourceFlag);
 
-        if (value != null && value.getValue() != null) {
-            String v = value.getValue();
+        if (value != null && value.getSecond().getValue() != null) {
+            String v = value.getSecond().getValue();
             int radix = 10;
             if (v.startsWith("0x")) {
                 v = v.substring(2);
@@ -444,10 +451,10 @@
 
     @Override
     public String getString(int id) throws NotFoundException {
-        ResourceValue value = getResourceValue(id, mPlatformResourceFlag);
+        Pair<String, ResourceValue> value = getResourceValue(id, mPlatformResourceFlag);
 
-        if (value != null && value.getValue() != null) {
-            return value.getValue();
+        if (value != null && value.getSecond().getValue() != null) {
+            return value.getSecond().getValue();
         }
 
         // id was not found or not resolved. Throw a NotFoundException.
@@ -460,13 +467,14 @@
     @Override
     public void getValue(int id, TypedValue outValue, boolean resolveRefs)
             throws NotFoundException {
-        ResourceValue value = getResourceValue(id, mPlatformResourceFlag);
+        Pair<String, ResourceValue> value = getResourceValue(id, mPlatformResourceFlag);
 
         if (value != null) {
-            String v = value.getValue();
+            String v = value.getSecond().getValue();
 
             if (v != null) {
-                if (ResourceHelper.stringToFloat(v, outValue)) {
+                if (ResourceHelper.parseFloatAttribute(value.getFirst(), v, outValue,
+                        false /*requireUnit*/)) {
                     return;
                 }
 
@@ -489,19 +497,17 @@
 
     @Override
     public XmlResourceParser getXml(int id) throws NotFoundException {
-        ResourceValue value = getResourceValue(id, mPlatformResourceFlag);
+        Pair<String, ResourceValue> value = getResourceValue(id, mPlatformResourceFlag);
 
         if (value != null) {
-            String v = value.getValue();
+            String v = value.getSecond().getValue();
 
             if (v != null) {
                 // check this is a file
-                File f = new File(value.getValue());
+                File f = new File(v);
                 if (f.isFile()) {
                     try {
-                        KXmlParser parser = new KXmlParser();
-                        parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
-                        parser.setInput(new FileReader(f));
+                        XmlPullParser parser = ParserFactory.create(f);
 
                         return new BridgeXmlBlockParser(parser, mContext, mPlatformResourceFlag[0]);
                     } catch (XmlPullParserException e) {
@@ -534,9 +540,7 @@
 
         File f = new File(file);
         try {
-            KXmlParser parser = new KXmlParser();
-            parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
-            parser.setInput(new FileReader(f));
+            XmlPullParser parser = ParserFactory.create(f);
 
             return new BridgeXmlBlockParser(parser, mContext, mPlatformResourceFlag[0]);
         } catch (XmlPullParserException e) {
@@ -553,10 +557,10 @@
 
     @Override
     public InputStream openRawResource(int id) throws NotFoundException {
-        ResourceValue value = getResourceValue(id, mPlatformResourceFlag);
+        Pair<String, ResourceValue> value = getResourceValue(id, mPlatformResourceFlag);
 
         if (value != null) {
-            String path = value.getValue();
+            String path = value.getSecond().getValue();
 
             if (path != null) {
                 // check this is a file
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeTypedArray.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeTypedArray.java
index b9f769f..260cdc8 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeTypedArray.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeTypedArray.java
@@ -16,6 +16,7 @@
 
 package com.android.layoutlib.bridge.android;
 
+import com.android.ide.common.rendering.api.DeclareStyleableResourceValue;
 import com.android.ide.common.rendering.api.LayoutLog;
 import com.android.ide.common.rendering.api.RenderResources;
 import com.android.ide.common.rendering.api.ResourceValue;
@@ -23,10 +24,10 @@
 import com.android.internal.util.XmlUtils;
 import com.android.layoutlib.bridge.Bridge;
 import com.android.layoutlib.bridge.BridgeConstants;
+import com.android.layoutlib.bridge.impl.ParserFactory;
 import com.android.layoutlib.bridge.impl.ResourceHelper;
 import com.android.resources.ResourceType;
 
-import org.kxml2.io.KXmlParser;
 import org.xmlpull.v1.XmlPullParser;
 import org.xmlpull.v1.XmlPullParserException;
 
@@ -36,10 +37,10 @@
 import android.graphics.drawable.Drawable;
 import android.util.DisplayMetrics;
 import android.util.TypedValue;
+import android.view.LayoutInflater_Delegate;
 import android.view.ViewGroup.LayoutParams;
 
 import java.io.File;
-import java.io.FileReader;
 import java.util.Arrays;
 import java.util.Map;
 
@@ -48,18 +49,23 @@
  */
 public final class BridgeTypedArray extends TypedArray {
 
-    private BridgeResources mBridgeResources;
-    private BridgeContext mContext;
+    private final BridgeResources mBridgeResources;
+    private final BridgeContext mContext;
+    private final boolean mPlatformFile;
+    private final boolean mPlatformStyleable;
+    private final String mStyleableName;
+
     private ResourceValue[] mResourceData;
     private String[] mNames;
-    private final boolean mPlatformFile;
 
     public BridgeTypedArray(BridgeResources resources, BridgeContext context, int len,
-            boolean platformFile) {
+            boolean platformFile, boolean platformStyleable, String styleableName) {
         super(null, null, null, 0);
         mBridgeResources = resources;
         mContext = context;
         mPlatformFile = platformFile;
+        mPlatformStyleable = platformStyleable;
+        mStyleableName = styleableName;
         mResourceData = new ResourceValue[len];
         mNames = new String[len];
     }
@@ -201,7 +207,18 @@
         // Field is not null and is not an integer.
         // Check for possible constants and try to find them.
         // Get the map of attribute-constant -> IntegerValue
-        Map<String, Integer> map = Bridge.getEnumValues(mNames[index]);
+        Map<String, Integer> map = null;
+        if (mPlatformStyleable) {
+            map = Bridge.getEnumValues(mNames[index]);
+        } else if (mStyleableName != null) {
+            // get the styleable matching the resolved name
+            RenderResources res = mContext.getRenderResources();
+            ResourceValue styleable = res.getProjectResource(ResourceType.DECLARE_STYLEABLE,
+                    mStyleableName);
+            if (styleable instanceof DeclareStyleableResourceValue) {
+                map = ((DeclareStyleableResourceValue) styleable).getAttributeValues(mNames[index]);
+            }
+        }
 
         if (map != null) {
             // accumulator to store the value of the 1+ constants.
@@ -313,9 +330,7 @@
         File f = new File(value);
         if (f.isFile()) {
             try {
-                KXmlParser parser = new KXmlParser();
-                parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
-                parser.setInput(new FileReader(f));
+                XmlPullParser parser = ParserFactory.create(f);
 
                 BridgeXmlBlockParser blockParser = new BridgeXmlBlockParser(
                         parser, mContext, resValue.isFramework());
@@ -359,26 +374,7 @@
      */
     @Override
     public int getInteger(int index, int defValue) {
-        if (mResourceData[index] == null) {
-            return defValue;
-        }
-
-        String s = mResourceData[index].getValue();
-
-        if (s != null) {
-            try {
-                return Integer.parseInt(s);
-            } catch (NumberFormatException e) {
-                Bridge.getLog().warning(LayoutLog.TAG_RESOURCES_FORMAT,
-                        String.format(
-                            "\"%s\" in attribute \"%2$s\" cannont be converted to an integer.",
-                            s, mNames[index]), null /*data*/);
-
-                // The default value is returned below.
-            }
-        }
-
-        return defValue;
+        return getInt(index, defValue);
     }
 
     /**
@@ -416,7 +412,7 @@
             return defValue;
         }
 
-        if (ResourceHelper.stringToFloat(s, mValue)) {
+        if (ResourceHelper.parseFloatAttribute(mNames[index], s, mValue, true /*requireUnit*/)) {
             return mValue.getDimension(mBridgeResources.mMetrics);
         }
 
@@ -471,40 +467,23 @@
      */
     @Override
     public int getDimensionPixelSize(int index, int defValue) {
-        if (mResourceData[index] == null) {
+        try {
+            return getDimension(index);
+        } catch (RuntimeException e) {
+            if (mResourceData[index] != null) {
+                String s = mResourceData[index].getValue();
+
+                if (s != null) {
+                    // looks like we were unable to resolve the dimension value
+                    Bridge.getLog().warning(LayoutLog.TAG_RESOURCES_FORMAT,
+                            String.format(
+                                "\"%1$s\" in attribute \"%2$s\" is not a valid format.",
+                                s, mNames[index]), null /*data*/);
+                }
+            }
+
             return defValue;
         }
-
-        String s = mResourceData[index].getValue();
-
-        if (s == null) {
-            return defValue;
-        } else if (s.equals(BridgeConstants.MATCH_PARENT) ||
-                s.equals(BridgeConstants.FILL_PARENT)) {
-            return LayoutParams.MATCH_PARENT;
-        } else if (s.equals(BridgeConstants.WRAP_CONTENT)) {
-            return LayoutParams.WRAP_CONTENT;
-        } else if (RenderResources.REFERENCE_NULL.equals(s)) {
-            return defValue;
-        }
-
-        if (ResourceHelper.stringToFloat(s, mValue)) {
-            float f = mValue.getDimension(mBridgeResources.mMetrics);
-
-            final int res = (int)(f+0.5f);
-            if (res != 0) return res;
-            if (f == 0) return 0;
-            if (f > 0) return 1;
-            return defValue; // this is basically unreachable.
-        }
-
-        // looks like we were unable to resolve the dimension value
-        Bridge.getLog().warning(LayoutLog.TAG_RESOURCES_FORMAT,
-                String.format(
-                    "\"%1$s\" in attribute \"%2$s\" is not a valid format.",
-                    s, mNames[index]), null /*data*/);
-
-        return defValue;
     }
 
     /**
@@ -521,7 +500,20 @@
      */
     @Override
     public int getLayoutDimension(int index, String name) {
-        return getDimensionPixelSize(index, 0);
+        try {
+            // this will throw an exception
+            return getDimension(index);
+        } catch (RuntimeException e) {
+
+            if (LayoutInflater_Delegate.sIsInInclude) {
+                throw new RuntimeException();
+            }
+
+            Bridge.getLog().warning(LayoutLog.TAG_RESOURCES_FORMAT,
+                    "You must supply a " + name + " attribute.", null);
+
+            return 0;
+        }
     }
 
     @Override
@@ -529,6 +521,36 @@
         return getDimensionPixelSize(index, defValue);
     }
 
+    private int getDimension(int index) {
+        if (mResourceData[index] == null) {
+            throw new RuntimeException();
+        }
+
+        String s = mResourceData[index].getValue();
+
+        if (s == null) {
+            throw new RuntimeException();
+        } else if (s.equals(BridgeConstants.MATCH_PARENT) ||
+                s.equals(BridgeConstants.FILL_PARENT)) {
+            return LayoutParams.MATCH_PARENT;
+        } else if (s.equals(BridgeConstants.WRAP_CONTENT)) {
+            return LayoutParams.WRAP_CONTENT;
+        } else if (RenderResources.REFERENCE_NULL.equals(s)) {
+            throw new RuntimeException();
+        }
+
+        if (ResourceHelper.parseFloatAttribute(mNames[index], s, mValue, true /*requireUnit*/)) {
+            float f = mValue.getDimension(mBridgeResources.mMetrics);
+
+            final int res = (int)(f+0.5f);
+            if (res != 0) return res;
+            if (f == 0) return 0;
+            if (f > 0) return 1;
+        }
+
+        throw new RuntimeException();
+    }
+
     /**
      * Retrieve a fractional unit attribute at <var>index</var>.
      *
@@ -555,14 +577,15 @@
             return defValue;
         }
 
-        if (ResourceHelper.stringToFloat(value, mValue)) {
+        if (ResourceHelper.parseFloatAttribute(mNames[index], value, mValue,
+                false /*requireUnit*/)) {
             return mValue.getFraction(base, pbase);
         }
 
         // looks like we were unable to resolve the fraction value
         Bridge.getLog().warning(LayoutLog.TAG_RESOURCES_FORMAT,
                 String.format(
-                    "\"%1$s\" in attribute \"%2$s\" cannont be converted to a fraction.",
+                    "\"%1$s\" in attribute \"%2$s\" cannot be converted to a fraction.",
                     value, mNames[index]), null /*data*/);
 
         return defValue;
@@ -759,7 +782,8 @@
 
         String s = mResourceData[index].getValue();
 
-        return ResourceHelper.stringToFloat(s, outValue);
+        return ResourceHelper.parseFloatAttribute(mNames[index], s, outValue,
+                false /*requireUnit*/);
     }
 
     /**
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeXmlBlockParser.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeXmlBlockParser.java
index 70dbaa4..1016b32 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeXmlBlockParser.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeXmlBlockParser.java
@@ -18,6 +18,7 @@
 
 
 import com.android.ide.common.rendering.api.ILayoutPullParser;
+import com.android.layoutlib.bridge.impl.ParserFactory;
 
 import org.xmlpull.v1.XmlPullParser;
 import org.xmlpull.v1.XmlPullParserException;
@@ -54,6 +55,10 @@
      * @param platformFile Indicates whether the the file is a platform file or not.
      */
     public BridgeXmlBlockParser(XmlPullParser parser, BridgeContext context, boolean platformFile) {
+        if (ParserFactory.LOG_PARSER) {
+            System.out.println("CRTE " + parser.toString());
+        }
+
         mParser = parser;
         mContext = context;
         mPlatformFile = platformFile;
@@ -65,6 +70,10 @@
         }
     }
 
+    public XmlPullParser getParser() {
+        return mParser;
+    }
+
     public boolean isPlatformFile() {
         return mPlatformFile;
     }
@@ -247,18 +256,63 @@
     public int next() throws XmlPullParserException, IOException {
         if (!mStarted) {
             mStarted = true;
+
+            if (ParserFactory.LOG_PARSER) {
+                System.out.println("STRT " + mParser.toString());
+            }
+
             return START_DOCUMENT;
         }
+
         int ev = mParser.next();
 
+        if (ParserFactory.LOG_PARSER) {
+            System.out.println("NEXT " + mParser.toString() + " " +
+                    eventTypeToString(mEventType) + " -> " + eventTypeToString(ev));
+        }
+
         if (ev == END_TAG && mParser.getDepth() == 1) {
             // done with parser remove it from the context stack.
             ensurePopped();
+
+            if (ParserFactory.LOG_PARSER) {
+                System.out.println("");
+            }
         }
+
         mEventType = ev;
         return ev;
     }
 
+    public static String eventTypeToString(int eventType) {
+        switch (eventType) {
+            case START_DOCUMENT:
+                return "START_DOC";
+            case END_DOCUMENT:
+                return "END_DOC";
+            case START_TAG:
+                return "START_TAG";
+            case END_TAG:
+                return "END_TAG";
+            case TEXT:
+                return "TEXT";
+            case CDSECT:
+                return "CDSECT";
+            case ENTITY_REF:
+                return "ENTITY_REF";
+            case IGNORABLE_WHITESPACE:
+                return "IGNORABLE_WHITESPACE";
+            case PROCESSING_INSTRUCTION:
+                return "PROCESSING_INSTRUCTION";
+            case COMMENT:
+                return "COMMENT";
+            case DOCDECL:
+                return "DOCDECL";
+        }
+
+        return "????";
+    }
+
     public void require(int type, String namespace, String name)
             throws XmlPullParserException {
         if (type != getEventType()
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/CustomBar.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/CustomBar.java
index 0c4b0d3..df701d5 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/CustomBar.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/CustomBar.java
@@ -22,11 +22,11 @@
 import com.android.layoutlib.bridge.Bridge;
 import com.android.layoutlib.bridge.android.BridgeContext;
 import com.android.layoutlib.bridge.android.BridgeXmlBlockParser;
+import com.android.layoutlib.bridge.impl.ParserFactory;
 import com.android.layoutlib.bridge.impl.ResourceHelper;
 import com.android.resources.Density;
 import com.android.resources.ResourceType;
 
-import org.kxml2.io.KXmlParser;
 import org.xmlpull.v1.XmlPullParser;
 import org.xmlpull.v1.XmlPullParserException;
 
@@ -60,7 +60,7 @@
 
     protected abstract TextView getStyleableTextView();
 
-    protected CustomBar(Context context, Density density, String layoutPath)
+    protected CustomBar(Context context, Density density, String layoutPath, String name)
             throws XmlPullParserException {
         super(context);
         setOrientation(LinearLayout.HORIZONTAL);
@@ -69,11 +69,8 @@
         LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(
                 Context.LAYOUT_INFLATER_SERVICE);
 
-        KXmlParser parser = new KXmlParser();
-        parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
-        parser.setInput(
-                getClass().getResourceAsStream(layoutPath),
-                "UTF8");
+        XmlPullParser parser = ParserFactory.create(getClass().getResourceAsStream(layoutPath),
+                name);
 
         BridgeXmlBlockParser bridgeParser = new BridgeXmlBlockParser(
                 parser, (BridgeContext) context, false /*platformFile*/);
@@ -230,7 +227,8 @@
 
                 if (textSize != null) {
                     TypedValue out = new TypedValue();
-                    if (ResourceHelper.stringToFloat(textSize.getValue(), out)) {
+                    if (ResourceHelper.parseFloatAttribute("textSize", textSize.getValue(), out,
+                            true /*requireUnit*/)) {
                         textView.setTextSize(
                                 out.getDimension(bridgeContext.getResources().mMetrics));
                     }
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/FakeActionBar.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/FakeActionBar.java
index 3af4e3a..f6edea4 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/FakeActionBar.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/FakeActionBar.java
@@ -29,7 +29,7 @@
 
     public FakeActionBar(Context context, Density density, String label, String icon)
             throws XmlPullParserException {
-        super(context, density, "/bars/action_bar.xml");
+        super(context, density, "/bars/action_bar.xml", "action_bar.xml");
 
         // Cannot access the inside items through id because no R.id values have been
         // created for them.
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/PhoneSystemBar.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/PhoneSystemBar.java
index 9fab51a..5569e06 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/PhoneSystemBar.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/PhoneSystemBar.java
@@ -30,7 +30,7 @@
 public class PhoneSystemBar extends CustomBar {
 
     public PhoneSystemBar(Context context, Density density) throws XmlPullParserException {
-        super(context, density, "/bars/phone_system_bar.xml");
+        super(context, density, "/bars/phone_system_bar.xml", "phone_system_bar.xml");
 
         setGravity(mGravity | Gravity.RIGHT);
         setBackgroundColor(0xFF000000);
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/TabletSystemBar.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/TabletSystemBar.java
index 5ca68fa..456ddb4 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/TabletSystemBar.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/TabletSystemBar.java
@@ -29,7 +29,7 @@
 public class TabletSystemBar extends CustomBar {
 
     public TabletSystemBar(Context context, Density density) throws XmlPullParserException {
-        super(context, density, "/bars/tablet_system_bar.xml");
+        super(context, density, "/bars/tablet_system_bar.xml", "tablet_system_bar.xml");
 
         setBackgroundColor(0xFF000000);
 
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/TitleBar.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/TitleBar.java
index d7401d9..5f5ebc4 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/TitleBar.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/TitleBar.java
@@ -29,7 +29,7 @@
 
     public TitleBar(Context context, Density density, String label)
             throws XmlPullParserException {
-        super(context, density, "/bars/title_bar.xml");
+        super(context, density, "/bars/title_bar.xml", "title_bar.xml");
 
         // Cannot access the inside items through id because no R.id values have been
         // created for them.
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ParserFactory.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ParserFactory.java
new file mode 100644
index 0000000..a235ec3
--- /dev/null
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ParserFactory.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.layoutlib.bridge.impl;
+
+
+import org.kxml2.io.KXmlParser;
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+
+/**
+ * A factory for {@link XmlPullParser}.
+ *
+ */
+public class ParserFactory {
+
+    private final static String ENCODING = "UTF-8"; //$NON-NLS-1$
+
+    public final static boolean LOG_PARSER = false;
+
+    public static XmlPullParser create(File f)
+            throws XmlPullParserException, FileNotFoundException {
+        KXmlParser parser = instantiateParser(f.getName());
+        parser.setInput(new FileInputStream(f), ENCODING);
+        return parser;
+    }
+
+    public static XmlPullParser create(InputStream stream, String name)
+            throws XmlPullParserException {
+        KXmlParser parser = instantiateParser(name);
+        parser.setInput(stream, ENCODING);
+        return parser;
+    }
+
+    private static KXmlParser instantiateParser(String name) throws XmlPullParserException {
+        KXmlParser parser;
+        if (name != null) {
+            parser = new CustomParser(name);
+        } else {
+            parser = new KXmlParser();
+        }
+        parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
+        return parser;
+    }
+
+    private static class CustomParser extends KXmlParser {
+        private final String mName;
+
+        CustomParser(String name) {
+            super();
+            mName = name;
+        }
+
+        @Override
+        public String toString() {
+            return mName;
+        }
+    }
+}
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java
index 8e80c21..6194f5d 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java
@@ -29,6 +29,7 @@
 import com.android.layoutlib.bridge.android.BridgeContext;
 import com.android.resources.ResourceType;
 
+import android.os.HandlerThread_Delegate;
 import android.util.DisplayMetrics;
 
 import java.util.concurrent.TimeUnit;
@@ -228,6 +229,10 @@
     private void tearDown() {
         // Make sure to remove static references, otherwise we could not unload the lib
         mContext.disposeResources();
+
+        // quit HandlerThread created during this session.
+        HandlerThread_Delegate.cleanUp(sCurrentContext);
+
         sCurrentContext = null;
 
         Bridge.setLog(null);
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
index b800519..aa30e29 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
@@ -984,7 +984,8 @@
                         "status_bar_height");
 
                 if (value != null) {
-                    TypedValue typedValue = ResourceHelper.getValue(value.getValue());
+                    TypedValue typedValue = ResourceHelper.getValue("status_bar_height",
+                            value.getValue(), true /*requireUnit*/);
                     if (typedValue != null) {
                         // compute the pixel value based on the display metrics
                         mStatusBarSize = (int)typedValue.getDimension(metrics);
@@ -1016,7 +1017,8 @@
 
             if (value != null) {
                 // get the numerical value, if available
-                TypedValue typedValue = ResourceHelper.getValue(value.getValue());
+                TypedValue typedValue = ResourceHelper.getValue("actionBarSize", value.getValue(),
+                        true /*requireUnit*/);
                 if (typedValue != null) {
                     // compute the pixel value based on the display metrics
                     mActionBarSize = (int)typedValue.getDimension(metrics);
@@ -1040,7 +1042,8 @@
 
                 if (value != null) {
                     // get the numerical value, if available
-                    TypedValue typedValue = ResourceHelper.getValue(value.getValue());
+                    TypedValue typedValue = ResourceHelper.getValue("windowTitleSize",
+                            value.getValue(), true /*requireUnit*/);
                     if (typedValue != null) {
                         // compute the pixel value based on the display metrics
                         mTitleBarSize = (int)typedValue.getDimension(metrics);
@@ -1062,7 +1065,8 @@
                     "status_bar_height");
 
             if (value != null) {
-                TypedValue typedValue = ResourceHelper.getValue(value.getValue());
+                TypedValue typedValue = ResourceHelper.getValue("status_bar_height",
+                        value.getValue(), true /*requireUnit*/);
                 if (typedValue != null) {
                     // compute the pixel value based on the display metrics
                     mSystemBarSize = (int)typedValue.getDimension(metrics);
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ResourceHelper.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ResourceHelper.java
index 96ab30f..6dcb693 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ResourceHelper.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ResourceHelper.java
@@ -27,7 +27,6 @@
 import com.android.ninepatch.NinePatchChunk;
 import com.android.resources.Density;
 
-import org.kxml2.io.KXmlParser;
 import org.xmlpull.v1.XmlPullParser;
 import org.xmlpull.v1.XmlPullParserException;
 
@@ -44,7 +43,6 @@
 
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.MalformedURLException;
@@ -122,9 +120,7 @@
                 try {
                     // let the framework inflate the ColorStateList from the XML file, by
                     // providing an XmlPullParser
-                    KXmlParser parser = new KXmlParser();
-                    parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
-                    parser.setInput(new FileReader(f));
+                    XmlPullParser parser = ParserFactory.create(f);
 
                     BridgeXmlBlockParser blockParser = new BridgeXmlBlockParser(
                             parser, context, resValue.isFramework());
@@ -204,9 +200,7 @@
             if (f.isFile()) {
                 try {
                     // let the framework inflate the Drawable from the XML file.
-                    KXmlParser parser = new KXmlParser();
-                    parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
-                    parser.setInput(new FileReader(f));
+                    XmlPullParser parser = ParserFactory.create(f);
 
                     BridgeXmlBlockParser blockParser = new BridgeXmlBlockParser(
                             parser, context, value.isFramework());
@@ -342,11 +336,11 @@
     };
 
     /**
-     * Returns the raw value from the given string.
+     * Returns the raw value from the given attribute float-type value string.
      * This object is only valid until the next call on to {@link ResourceHelper}.
      */
-    public static TypedValue getValue(String s) {
-        if (stringToFloat(s, mValue)) {
+    public static TypedValue getValue(String attribute, String value, boolean requireUnit) {
+        if (parseFloatAttribute(attribute, value, mValue, requireUnit)) {
             return mValue;
         }
 
@@ -354,22 +348,27 @@
     }
 
     /**
-     * Convert the string into a {@link TypedValue}.
-     * @param s
-     * @param outValue
+     * Parse a float attribute and return the parsed value into a given TypedValue.
+     * @param attribute the name of the attribute. Can be null if <var>requireUnit</var> is false.
+     * @param value the string value of the attribute
+     * @param outValue the TypedValue to receive the parsed value
+     * @param requireUnit whether the value is expected to contain a unit.
      * @return true if success.
      */
-    public static boolean stringToFloat(String s, TypedValue outValue) {
+    public static boolean parseFloatAttribute(String attribute, String value,
+            TypedValue outValue, boolean requireUnit) {
+        assert requireUnit == false || attribute != null;
+
         // remove the space before and after
-        s = s.trim();
-        int len = s.length();
+        value = value.trim();
+        int len = value.length();
 
         if (len <= 0) {
             return false;
         }
 
         // check that there's no non ascii characters.
-        char[] buf = s.toCharArray();
+        char[] buf = value.toCharArray();
         for (int i = 0 ; i < len ; i++) {
             if (buf[i] > 255) {
                 return false;
@@ -382,7 +381,7 @@
         }
 
         // now look for the string that is after the float...
-        Matcher m = sFloatPattern.matcher(s);
+        Matcher m = sFloatPattern.matcher(value);
         if (m.matches()) {
             String f_str = m.group(1);
             String end = m.group(2);
@@ -398,45 +397,7 @@
             if (end.length() > 0 && end.charAt(0) != ' ') {
                 // Might be a unit...
                 if (parseUnit(end, outValue, sFloatOut)) {
-
-                    f *= sFloatOut[0];
-                    boolean neg = f < 0;
-                    if (neg) {
-                        f = -f;
-                    }
-                    long bits = (long)(f*(1<<23)+.5f);
-                    int radix;
-                    int shift;
-                    if ((bits&0x7fffff) == 0) {
-                        // Always use 23p0 if there is no fraction, just to make
-                        // things easier to read.
-                        radix = TypedValue.COMPLEX_RADIX_23p0;
-                        shift = 23;
-                    } else if ((bits&0xffffffffff800000L) == 0) {
-                        // Magnitude is zero -- can fit in 0 bits of precision.
-                        radix = TypedValue.COMPLEX_RADIX_0p23;
-                        shift = 0;
-                    } else if ((bits&0xffffffff80000000L) == 0) {
-                        // Magnitude can fit in 8 bits of precision.
-                        radix = TypedValue.COMPLEX_RADIX_8p15;
-                        shift = 8;
-                    } else if ((bits&0xffffff8000000000L) == 0) {
-                        // Magnitude can fit in 16 bits of precision.
-                        radix = TypedValue.COMPLEX_RADIX_16p7;
-                        shift = 16;
-                    } else {
-                        // Magnitude needs entire range, so no fractional part.
-                        radix = TypedValue.COMPLEX_RADIX_23p0;
-                        shift = 23;
-                    }
-                    int mantissa = (int)(
-                        (bits>>shift) & TypedValue.COMPLEX_MANTISSA_MASK);
-                    if (neg) {
-                        mantissa = (-mantissa) & TypedValue.COMPLEX_MANTISSA_MASK;
-                    }
-                    outValue.data |=
-                        (radix<<TypedValue.COMPLEX_RADIX_SHIFT)
-                        | (mantissa<<TypedValue.COMPLEX_MANTISSA_SHIFT);
+                    computeTypedValue(outValue, f, sFloatOut[0]);
                     return true;
                 }
                 return false;
@@ -447,8 +408,20 @@
 
             if (end.length() == 0) {
                 if (outValue != null) {
-                    outValue.type = TypedValue.TYPE_FLOAT;
-                    outValue.data = Float.floatToIntBits(f);
+                    if (requireUnit == false) {
+                        outValue.type = TypedValue.TYPE_FLOAT;
+                        outValue.data = Float.floatToIntBits(f);
+                    } else {
+                        // no unit when required? Use dp and out an error.
+                        applyUnit(sUnitNames[1], outValue, sFloatOut);
+                        computeTypedValue(outValue, f, sFloatOut[0]);
+
+                        Bridge.getLog().error(LayoutLog.TAG_RESOURCES_RESOLVE,
+                                String.format(
+                                        "Dimension \"%1$s\" in attribute \"%2$s\" is missing unit!",
+                                        value, attribute),
+                                null);
+                    }
                     return true;
                 }
             }
@@ -457,20 +430,64 @@
         return false;
     }
 
+    private static void computeTypedValue(TypedValue outValue, float value, float scale) {
+        value *= scale;
+        boolean neg = value < 0;
+        if (neg) {
+            value = -value;
+        }
+        long bits = (long)(value*(1<<23)+.5f);
+        int radix;
+        int shift;
+        if ((bits&0x7fffff) == 0) {
+            // Always use 23p0 if there is no fraction, just to make
+            // things easier to read.
+            radix = TypedValue.COMPLEX_RADIX_23p0;
+            shift = 23;
+        } else if ((bits&0xffffffffff800000L) == 0) {
+            // Magnitude is zero -- can fit in 0 bits of precision.
+            radix = TypedValue.COMPLEX_RADIX_0p23;
+            shift = 0;
+        } else if ((bits&0xffffffff80000000L) == 0) {
+            // Magnitude can fit in 8 bits of precision.
+            radix = TypedValue.COMPLEX_RADIX_8p15;
+            shift = 8;
+        } else if ((bits&0xffffff8000000000L) == 0) {
+            // Magnitude can fit in 16 bits of precision.
+            radix = TypedValue.COMPLEX_RADIX_16p7;
+            shift = 16;
+        } else {
+            // Magnitude needs entire range, so no fractional part.
+            radix = TypedValue.COMPLEX_RADIX_23p0;
+            shift = 23;
+        }
+        int mantissa = (int)(
+            (bits>>shift) & TypedValue.COMPLEX_MANTISSA_MASK);
+        if (neg) {
+            mantissa = (-mantissa) & TypedValue.COMPLEX_MANTISSA_MASK;
+        }
+        outValue.data |=
+            (radix<<TypedValue.COMPLEX_RADIX_SHIFT)
+            | (mantissa<<TypedValue.COMPLEX_MANTISSA_SHIFT);
+    }
+
     private static boolean parseUnit(String str, TypedValue outValue, float[] outScale) {
         str = str.trim();
 
         for (UnitEntry unit : sUnitNames) {
             if (unit.name.equals(str)) {
-                outValue.type = unit.type;
-                outValue.data = unit.unit << TypedValue.COMPLEX_UNIT_SHIFT;
-                outScale[0] = unit.scale;
-
+                applyUnit(unit, outValue, outScale);
                 return true;
             }
         }
 
         return false;
     }
+
+    private static void applyUnit(UnitEntry unit, TypedValue outValue, float[] outScale) {
+        outValue.type = unit.type;
+        outValue.data = unit.unit << TypedValue.COMPLEX_UNIT_SHIFT;
+        outScale[0] = unit.scale;
+    }
 }
 
diff --git a/tools/layoutlib/bridge/src/libcore/icu/ICU_Delegate.java b/tools/layoutlib/bridge/src/libcore/icu/ICU_Delegate.java
index e6dc646..98f8529 100644
--- a/tools/layoutlib/bridge/src/libcore/icu/ICU_Delegate.java
+++ b/tools/layoutlib/bridge/src/libcore/icu/ICU_Delegate.java
@@ -44,6 +44,16 @@
     // --- Native methods accessing ICU's database.
 
     @LayoutlibDelegate
+    /*package*/ static String getIcuVersion() {
+        return "unknown_layoutlib";
+    }
+
+    @LayoutlibDelegate
+    /*package*/ static String getUnicodeVersion() {
+        return "5.2";
+    }
+
+    @LayoutlibDelegate
     /*package*/ static String[] getAvailableBreakIteratorLocalesNative() {
         return new String[0];
     }
@@ -74,17 +84,27 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static String getCurrencyCodeNative(String locale) {
+    /*package*/ static String[] getAvailableCurrencyCodes() {
+        return new String[0];
+    }
+
+    @LayoutlibDelegate
+    /*package*/ static String getCurrencyCode(String locale) {
         return "";
     }
 
     @LayoutlibDelegate
-    /*package*/ static int getCurrencyFractionDigitsNative(String currencyCode) {
+    /*package*/ static String getCurrencyDisplayName(String locale, String currencyCode) {
+        return "";
+    }
+
+    @LayoutlibDelegate
+    /*package*/ static int getCurrencyFractionDigits(String currencyCode) {
         return 0;
     }
 
     @LayoutlibDelegate
-    /*package*/ static String getCurrencySymbolNative(String locale, String currencyCode) {
+    /*package*/ static String getCurrencySymbol(String locale, String currencyCode) {
         return "";
     }
 
@@ -114,6 +134,12 @@
     }
 
     @LayoutlibDelegate
+    /*package*/ static String addLikelySubtags(String locale) {
+        return "";
+    }
+
+
+    @LayoutlibDelegate
     /*package*/ static String[] getISOLanguagesNative() {
         return Locale.getISOLanguages();
     }
diff --git a/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/android/BridgeXmlBlockParserTest.java b/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/android/BridgeXmlBlockParserTest.java
index 3252fb49..96436fe 100644
--- a/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/android/BridgeXmlBlockParserTest.java
+++ b/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/android/BridgeXmlBlockParserTest.java
@@ -16,14 +16,11 @@
 
 package com.android.layoutlib.bridge.android;
 
-import com.android.layoutlib.bridge.android.BridgeXmlBlockParser;
+import com.android.layoutlib.bridge.impl.ParserFactory;
 
-import org.kxml2.io.KXmlParser;
 import org.w3c.dom.Node;
 import org.xmlpull.v1.XmlPullParser;
 
-import java.io.InputStream;
-
 import junit.framework.TestCase;
 
 public class BridgeXmlBlockParserTest extends TestCase {
@@ -39,12 +36,12 @@
     }
 
     public void testXmlBlockParser() throws Exception {
-        XmlPullParser parser = new KXmlParser();
-        parser = new BridgeXmlBlockParser(parser, null, false /* platformResourceFlag */);
 
-        InputStream input = this.getClass().getClassLoader().getResourceAsStream(
-            "com/android/layoutlib/testdata/layout1.xml");
-        parser.setInput(input, null /*encoding*/);
+        XmlPullParser parser = ParserFactory.create(
+                getClass().getResourceAsStream("com/android/layoutlib/testdata/layout1.xml"),
+                        "layout1.xml");
+
+        parser = new BridgeXmlBlockParser(parser, null, false /* platformResourceFlag */);
 
         assertEquals(XmlPullParser.START_DOCUMENT, parser.next());
 
diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java
index eff6bbc..5c60318 100644
--- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java
+++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java
@@ -99,8 +99,10 @@
         "android.content.res.Resources$Theme#resolveAttribute",
         "android.graphics.BitmapFactory#finishDecode",
         "android.os.Handler#sendMessageAtTime",
+        "android.os.HandlerThread#run",
         "android.os.Build#getString",
         "android.view.LayoutInflater#rInflate",
+        "android.view.LayoutInflater#parseInclude",
         "android.view.View#isInEditMode",
         "com.android.internal.util.XmlUtils#convertValueToInt",
         // TODO: comment out once DelegateClass is working
diff --git a/voip/java/com/android/server/sip/SipService.java b/voip/java/com/android/server/sip/SipService.java
index dc66989..5ad5d26 100644
--- a/voip/java/com/android/server/sip/SipService.java
+++ b/voip/java/com/android/server/sip/SipService.java
@@ -60,6 +60,7 @@
 import java.util.Timer;
 import java.util.TimerTask;
 import java.util.TreeSet;
+import java.util.concurrent.Executor;
 import javax.sip.SipException;
 
 /**
@@ -68,8 +69,7 @@
 public final class SipService extends ISipService.Stub {
     static final String TAG = "SipService";
     static final boolean DEBUGV = false;
-    private static final boolean DEBUG = false;
-    private static final boolean DEBUG_TIMER = DEBUG && false;
+    static final boolean DEBUG = false;
     private static final int EXPIRY_TIME = 3600;
     private static final int SHORT_EXPIRY_TIME = 10;
     private static final int MIN_EXPIRY_TIME = 60;
@@ -78,12 +78,13 @@
     private String mLocalIp;
     private String mNetworkType;
     private boolean mConnected;
-    private WakeupTimer mTimer;
+    private SipWakeupTimer mTimer;
     private WifiScanProcess mWifiScanProcess;
     private WifiManager.WifiLock mWifiLock;
     private boolean mWifiOnly;
+    private IntervalMeasurementProcess mIntervalMeasurementProcess;
 
-    private MyExecutor mExecutor;
+    private MyExecutor mExecutor = new MyExecutor();
 
     // SipProfile URI --> group
     private Map<String, SipSessionGroupExt> mSipGroups =
@@ -96,6 +97,7 @@
     private ConnectivityReceiver mConnectivityReceiver;
     private boolean mWifiEnabled;
     private SipWakeLock mMyWakeLock;
+    private int mKeepAliveInterval;
 
     /**
      * Starts the SIP service. Do nothing if the SIP API is not supported on the
@@ -116,7 +118,7 @@
         mMyWakeLock = new SipWakeLock((PowerManager)
                 context.getSystemService(Context.POWER_SERVICE));
 
-        mTimer = new WakeupTimer(context);
+        mTimer = new SipWakeupTimer(context, mExecutor);
         mWifiOnly = SipManager.isSipWifiOnly(context);
     }
 
@@ -157,12 +159,6 @@
         if (DEBUG) Log.d(TAG, " --- unregister receivers");
     }
 
-    private MyExecutor getExecutor() {
-        // create mExecutor lazily
-        if (mExecutor == null) mExecutor = new MyExecutor();
-        return mExecutor;
-    }
-
     public synchronized SipProfile[] getListOfProfiles() {
         mContext.enforceCallingOrSelfPermission(
                 android.Manifest.permission.USE_SIP, null);
@@ -441,12 +437,14 @@
 
             if (connected) {
                 mLocalIp = determineLocalIp();
+                mKeepAliveInterval = -1;
                 for (SipSessionGroupExt group : mSipGroups.values()) {
                     group.onConnectivityChanged(true);
                 }
                 if (isWifi && (mWifiLock != null)) stopWifiScanner();
             } else {
                 mMyWakeLock.reset(); // in case there's a leak
+                stopPortMappingMeasurement();
                 if (isWifi && (mWifiLock != null)) startWifiScanner();
             }
         } catch (SipException e) {
@@ -454,6 +452,18 @@
         }
     }
 
+    private void stopPortMappingMeasurement() {
+        if (mIntervalMeasurementProcess != null) {
+            mIntervalMeasurementProcess.stop();
+            mIntervalMeasurementProcess = null;
+        }
+    }
+
+    private void startPortMappingLifetimeMeasurement(SipSessionGroup group) {
+        mIntervalMeasurementProcess = new IntervalMeasurementProcess(group);
+        mIntervalMeasurementProcess.start();
+    }
+
     private synchronized void addPendingSession(ISipSession session) {
         try {
             cleanUpPendingSessions();
@@ -687,6 +697,93 @@
         }
     }
 
+    private class IntervalMeasurementProcess extends SipSessionAdapter
+            implements Runnable {
+        private static final String TAG = "\\INTERVAL/";
+        private static final int MAX_INTERVAL = 120; // seconds
+        private static final int MIN_INTERVAL = SHORT_EXPIRY_TIME;
+        private static final int PASS_THRESHOLD = 6;
+        private SipSessionGroupExt mGroup;
+        private SipSessionGroup.SipSessionImpl mSession;
+        private boolean mRunning;
+        private int mMinInterval = 10;
+        private int mMaxInterval = MAX_INTERVAL;
+        private int mInterval = MAX_INTERVAL / 2;
+        private int mPassCounter = 0;
+        private SipWakeupTimer mTimer = new SipWakeupTimer(mContext, mExecutor);
+        // TODO: fix SipWakeupTimer so that we only use one instance of the timer
+
+        public IntervalMeasurementProcess(SipSessionGroup group) {
+            try {
+                mGroup =  new SipSessionGroupExt(
+                        group.getLocalProfile(), null, null);
+                mSession = (SipSessionGroup.SipSessionImpl)
+                        mGroup.createSession(this);
+            } catch (Exception e) {
+                Log.w(TAG, "start interval measurement error: " + e);
+            }
+        }
+
+        public void start() {
+            if (mRunning) return;
+            mRunning = true;
+            mTimer.set(mInterval * 1000, this);
+            if (DEBUGV) Log.v(TAG, "start interval measurement");
+            run();
+        }
+
+        public void stop() {
+            mRunning = false;
+            mTimer.cancel(this);
+        }
+
+        private void restart() {
+            mTimer.cancel(this);
+            mTimer.set(mInterval * 1000, this);
+        }
+
+        private void calculateNewInterval() {
+            if (!mSession.isReRegisterRequired()) {
+                if (++mPassCounter != PASS_THRESHOLD) return;
+                // update the interval, since the current interval is good to
+                // keep the port mapping.
+                mKeepAliveInterval = mMinInterval = mInterval;
+            } else {
+                // Since the rport is changed, shorten the interval.
+                mSession.clearReRegisterRequired();
+                mMaxInterval = mInterval;
+            }
+            if ((mMaxInterval - mMinInterval) < MIN_INTERVAL) {
+                // update mKeepAliveInterval and stop measurement.
+                stop();
+                mKeepAliveInterval = mMinInterval;
+                if (DEBUGV) Log.v(TAG, "measured interval: " + mKeepAliveInterval);
+            } else {
+                // calculate the new interval and continue.
+                mInterval = (mMaxInterval + mMinInterval) / 2;
+                mPassCounter = 0;
+                if (DEBUGV) {
+                    Log.v(TAG, " current interval: " + mKeepAliveInterval
+                            + "test new interval: " + mInterval);
+                }
+                restart();
+            }
+        }
+
+        public void run() {
+            synchronized (SipService.this) {
+                if (!mRunning) return;
+                try {
+                    mSession.sendKeepAlive();
+                    calculateNewInterval();
+                } catch (Throwable t) {
+                    stop();
+                    Log.w(TAG, "interval measurement error: " + t);
+                }
+            }
+        }
+    }
+
     // KeepAliveProcess is controlled by AutoRegistrationProcess.
     // All methods will be invoked in sync with SipService.this.
     private class KeepAliveProcess implements Runnable {
@@ -694,6 +791,7 @@
         private static final int INTERVAL = 10;
         private SipSessionGroup.SipSessionImpl mSession;
         private boolean mRunning = false;
+        private int mInterval = INTERVAL;
 
         public KeepAliveProcess(SipSessionGroup.SipSessionImpl session) {
             mSession = session;
@@ -705,6 +803,12 @@
             mTimer.set(INTERVAL * 1000, this);
         }
 
+        private void restart(int duration) {
+            if (DEBUG) Log.d(TAG, "Refresh NAT port mapping " + duration + "s later.");
+            mTimer.cancel(this);
+            mTimer.set(duration * 1000, this);
+        }
+
         // timeout handler
         public void run() {
             synchronized (SipService.this) {
@@ -721,6 +825,10 @@
                         mMyWakeLock.acquire(mSession);
                         mSession.register(EXPIRY_TIME);
                     }
+                    if (mKeepAliveInterval > mInterval) {
+                        mInterval = mKeepAliveInterval;
+                        restart(mInterval);
+                    }
                 } catch (Throwable t) {
                     Log.w(TAG, "keepalive error: " + t);
                 }
@@ -761,6 +869,17 @@
                 // return right away if no active network connection.
                 if (mSession == null) return;
 
+                synchronized (SipService.this) {
+                    if (isBehindNAT(mLocalIp)
+                            && (mIntervalMeasurementProcess == null)
+                            && (mKeepAliveInterval == -1)) {
+                        // Start keep-alive interval measurement, here we allow
+                        // the first profile only as the target service provider
+                        // to measure the life time of NAT port mapping.
+                        startPortMappingLifetimeMeasurement(group);
+                    }
+                }
+
                 // start unregistration to clear up old registration at server
                 // TODO: when rfc5626 is deployed, use reg-id and sip.instance
                 // in registration to avoid adding duplicate entries to server
@@ -998,7 +1117,7 @@
         @Override
         public void onReceive(final Context context, final Intent intent) {
             // Run the handler in MyExecutor to be protected by wake lock
-            getExecutor().execute(new Runnable() {
+            mExecutor.execute(new Runnable() {
                 public void run() {
                     onReceiveInternal(context, intent);
                 }
@@ -1102,7 +1221,7 @@
             @Override
             public void run() {
                 // delegate to mExecutor
-                getExecutor().execute(new Runnable() {
+                mExecutor.execute(new Runnable() {
                     public void run() {
                         realRun();
                     }
@@ -1127,300 +1246,6 @@
         }
     }
 
-    /**
-     * Timer that can schedule events to occur even when the device is in sleep.
-     * Only used internally in this package.
-     */
-    class WakeupTimer extends BroadcastReceiver {
-        private static final String TAG = "_SIP.WkTimer_";
-        private static final String TRIGGER_TIME = "TriggerTime";
-
-        private Context mContext;
-        private AlarmManager mAlarmManager;
-
-        // runnable --> time to execute in SystemClock
-        private TreeSet<MyEvent> mEventQueue =
-                new TreeSet<MyEvent>(new MyEventComparator());
-
-        private PendingIntent mPendingIntent;
-
-        public WakeupTimer(Context context) {
-            mContext = context;
-            mAlarmManager = (AlarmManager)
-                    context.getSystemService(Context.ALARM_SERVICE);
-
-            IntentFilter filter = new IntentFilter(getAction());
-            context.registerReceiver(this, filter);
-        }
-
-        /**
-         * Stops the timer. No event can be scheduled after this method is called.
-         */
-        public synchronized void stop() {
-            mContext.unregisterReceiver(this);
-            if (mPendingIntent != null) {
-                mAlarmManager.cancel(mPendingIntent);
-                mPendingIntent = null;
-            }
-            mEventQueue.clear();
-            mEventQueue = null;
-        }
-
-        private synchronized boolean stopped() {
-            if (mEventQueue == null) {
-                Log.w(TAG, "Timer stopped");
-                return true;
-            } else {
-                return false;
-            }
-        }
-
-        private void cancelAlarm() {
-            mAlarmManager.cancel(mPendingIntent);
-            mPendingIntent = null;
-        }
-
-        private void recalculatePeriods() {
-            if (mEventQueue.isEmpty()) return;
-
-            MyEvent firstEvent = mEventQueue.first();
-            int minPeriod = firstEvent.mMaxPeriod;
-            long minTriggerTime = firstEvent.mTriggerTime;
-            for (MyEvent e : mEventQueue) {
-                e.mPeriod = e.mMaxPeriod / minPeriod * minPeriod;
-                int interval = (int) (e.mLastTriggerTime + e.mMaxPeriod
-                        - minTriggerTime);
-                interval = interval / minPeriod * minPeriod;
-                e.mTriggerTime = minTriggerTime + interval;
-            }
-            TreeSet<MyEvent> newQueue = new TreeSet<MyEvent>(
-                    mEventQueue.comparator());
-            newQueue.addAll((Collection<MyEvent>) mEventQueue);
-            mEventQueue.clear();
-            mEventQueue = newQueue;
-            if (DEBUG_TIMER) {
-                Log.d(TAG, "queue re-calculated");
-                printQueue();
-            }
-        }
-
-        // Determines the period and the trigger time of the new event and insert it
-        // to the queue.
-        private void insertEvent(MyEvent event) {
-            long now = SystemClock.elapsedRealtime();
-            if (mEventQueue.isEmpty()) {
-                event.mTriggerTime = now + event.mPeriod;
-                mEventQueue.add(event);
-                return;
-            }
-            MyEvent firstEvent = mEventQueue.first();
-            int minPeriod = firstEvent.mPeriod;
-            if (minPeriod <= event.mMaxPeriod) {
-                event.mPeriod = event.mMaxPeriod / minPeriod * minPeriod;
-                int interval = event.mMaxPeriod;
-                interval -= (int) (firstEvent.mTriggerTime - now);
-                interval = interval / minPeriod * minPeriod;
-                event.mTriggerTime = firstEvent.mTriggerTime + interval;
-                mEventQueue.add(event);
-            } else {
-                long triggerTime = now + event.mPeriod;
-                if (firstEvent.mTriggerTime < triggerTime) {
-                    event.mTriggerTime = firstEvent.mTriggerTime;
-                    event.mLastTriggerTime -= event.mPeriod;
-                } else {
-                    event.mTriggerTime = triggerTime;
-                }
-                mEventQueue.add(event);
-                recalculatePeriods();
-            }
-        }
-
-        /**
-         * Sets a periodic timer.
-         *
-         * @param period the timer period; in milli-second
-         * @param callback is called back when the timer goes off; the same callback
-         *      can be specified in multiple timer events
-         */
-        public synchronized void set(int period, Runnable callback) {
-            if (stopped()) return;
-
-            long now = SystemClock.elapsedRealtime();
-            MyEvent event = new MyEvent(period, callback, now);
-            insertEvent(event);
-
-            if (mEventQueue.first() == event) {
-                if (mEventQueue.size() > 1) cancelAlarm();
-                scheduleNext();
-            }
-
-            long triggerTime = event.mTriggerTime;
-            if (DEBUG_TIMER) {
-                Log.d(TAG, " add event " + event + " scheduled at "
-                        + showTime(triggerTime) + " at " + showTime(now)
-                        + ", #events=" + mEventQueue.size());
-                printQueue();
-            }
-        }
-
-        /**
-         * Cancels all the timer events with the specified callback.
-         *
-         * @param callback the callback
-         */
-        public synchronized void cancel(Runnable callback) {
-            if (stopped() || mEventQueue.isEmpty()) return;
-            if (DEBUG_TIMER) Log.d(TAG, "cancel:" + callback);
-
-            MyEvent firstEvent = mEventQueue.first();
-            for (Iterator<MyEvent> iter = mEventQueue.iterator();
-                    iter.hasNext();) {
-                MyEvent event = iter.next();
-                if (event.mCallback == callback) {
-                    iter.remove();
-                    if (DEBUG_TIMER) Log.d(TAG, "    cancel found:" + event);
-                }
-            }
-            if (mEventQueue.isEmpty()) {
-                cancelAlarm();
-            } else if (mEventQueue.first() != firstEvent) {
-                cancelAlarm();
-                firstEvent = mEventQueue.first();
-                firstEvent.mPeriod = firstEvent.mMaxPeriod;
-                firstEvent.mTriggerTime = firstEvent.mLastTriggerTime
-                        + firstEvent.mPeriod;
-                recalculatePeriods();
-                scheduleNext();
-            }
-            if (DEBUG_TIMER) {
-                Log.d(TAG, "after cancel:");
-                printQueue();
-            }
-        }
-
-        private void scheduleNext() {
-            if (stopped() || mEventQueue.isEmpty()) return;
-
-            if (mPendingIntent != null) {
-                throw new RuntimeException("pendingIntent is not null!");
-            }
-
-            MyEvent event = mEventQueue.first();
-            Intent intent = new Intent(getAction());
-            intent.putExtra(TRIGGER_TIME, event.mTriggerTime);
-            PendingIntent pendingIntent = mPendingIntent =
-                    PendingIntent.getBroadcast(mContext, 0, intent,
-                            PendingIntent.FLAG_UPDATE_CURRENT);
-            mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
-                    event.mTriggerTime, pendingIntent);
-        }
-
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            // This callback is already protected by AlarmManager's wake lock.
-            String action = intent.getAction();
-            if (getAction().equals(action)
-                    && intent.getExtras().containsKey(TRIGGER_TIME)) {
-                mPendingIntent = null;
-                long triggerTime = intent.getLongExtra(TRIGGER_TIME, -1L);
-                execute(triggerTime);
-            } else {
-                Log.d(TAG, "unrecognized intent: " + intent);
-            }
-        }
-
-        private void printQueue() {
-            int count = 0;
-            for (MyEvent event : mEventQueue) {
-                Log.d(TAG, "     " + event + ": scheduled at "
-                        + showTime(event.mTriggerTime) + ": last at "
-                        + showTime(event.mLastTriggerTime));
-                if (++count >= 5) break;
-            }
-            if (mEventQueue.size() > count) {
-                Log.d(TAG, "     .....");
-            } else if (count == 0) {
-                Log.d(TAG, "     <empty>");
-            }
-        }
-
-        private synchronized void execute(long triggerTime) {
-            if (DEBUG_TIMER) Log.d(TAG, "time's up, triggerTime = "
-                    + showTime(triggerTime) + ": " + mEventQueue.size());
-            if (stopped() || mEventQueue.isEmpty()) return;
-
-            for (MyEvent event : mEventQueue) {
-                if (event.mTriggerTime != triggerTime) break;
-                if (DEBUG_TIMER) Log.d(TAG, "execute " + event);
-
-                event.mLastTriggerTime = event.mTriggerTime;
-                event.mTriggerTime += event.mPeriod;
-
-                // run the callback in the handler thread to prevent deadlock
-                getExecutor().execute(event.mCallback);
-            }
-            if (DEBUG_TIMER) {
-                Log.d(TAG, "after timeout execution");
-                printQueue();
-            }
-            scheduleNext();
-        }
-
-        private String getAction() {
-            return toString();
-        }
-
-        private String showTime(long time) {
-            int ms = (int) (time % 1000);
-            int s = (int) (time / 1000);
-            int m = s / 60;
-            s %= 60;
-            return String.format("%d.%d.%d", m, s, ms);
-        }
-    }
-
-    private static class MyEvent {
-        int mPeriod;
-        int mMaxPeriod;
-        long mTriggerTime;
-        long mLastTriggerTime;
-        Runnable mCallback;
-
-        MyEvent(int period, Runnable callback, long now) {
-            mPeriod = mMaxPeriod = period;
-            mCallback = callback;
-            mLastTriggerTime = now;
-        }
-
-        @Override
-        public String toString() {
-            String s = super.toString();
-            s = s.substring(s.indexOf("@"));
-            return s + ":" + (mPeriod / 1000) + ":" + (mMaxPeriod / 1000) + ":"
-                    + toString(mCallback);
-        }
-
-        private String toString(Object o) {
-            String s = o.toString();
-            int index = s.indexOf("$");
-            if (index > 0) s = s.substring(index + 1);
-            return s;
-        }
-    }
-
-    private static class MyEventComparator implements Comparator<MyEvent> {
-        public int compare(MyEvent e1, MyEvent e2) {
-            if (e1 == e2) return 0;
-            int diff = e1.mMaxPeriod - e2.mMaxPeriod;
-            if (diff == 0) diff = -1;
-            return diff;
-        }
-
-        public boolean equals(Object that) {
-            return (this == that);
-        }
-    }
-
     private static Looper createLooper() {
         HandlerThread thread = new HandlerThread("SipService.Executor");
         thread.start();
@@ -1429,12 +1254,13 @@
 
     // Executes immediate tasks in a single thread.
     // Hold/release wake lock for running tasks
-    private class MyExecutor extends Handler {
+    private class MyExecutor extends Handler implements Executor {
         MyExecutor() {
             super(createLooper());
         }
 
-        void execute(Runnable task) {
+        @Override
+        public void execute(Runnable task) {
             mMyWakeLock.acquire(task);
             Message.obtain(this, 0/* don't care */, task).sendToTarget();
         }
diff --git a/voip/java/com/android/server/sip/SipSessionGroup.java b/voip/java/com/android/server/sip/SipSessionGroup.java
index aa616a9..4837eb9 100644
--- a/voip/java/com/android/server/sip/SipSessionGroup.java
+++ b/voip/java/com/android/server/sip/SipSessionGroup.java
@@ -397,7 +397,7 @@
 
         // for registration
         boolean mReRegisterFlag = false;
-        int mRPort;
+        int mRPort = 0;
 
         // lightweight timer
         class SessionTimer {
@@ -447,7 +447,6 @@
             mState = SipSession.State.READY_TO_CALL;
             mInviteReceived = null;
             mPeerSessionDescription = null;
-            mRPort = 0;
             mAuthenticationRetryCount = 0;
 
             if (mDialog != null) mDialog.delete();
@@ -529,12 +528,8 @@
         public void answerCall(String sessionDescription, int timeout) {
             synchronized (SipSessionGroup.this) {
                 if (mPeerProfile == null) return;
-                try {
-                    processCommand(new MakeCallCommand(mPeerProfile,
-                            sessionDescription, timeout));
-                } catch (SipException e) {
-                    onError(e);
-                }
+                doCommandAsync(new MakeCallCommand(mPeerProfile,
+                        sessionDescription, timeout));
             }
         }
 
diff --git a/voip/java/com/android/server/sip/SipWakeupTimer.java b/voip/java/com/android/server/sip/SipWakeupTimer.java
new file mode 100644
index 0000000..9cc26b0
--- /dev/null
+++ b/voip/java/com/android/server/sip/SipWakeupTimer.java
@@ -0,0 +1,339 @@
+/*
+ * Copyright (C) 2011, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.sip;
+
+import android.app.AlarmManager;
+import android.app.PendingIntent;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.SystemClock;
+import android.util.Log;
+
+import java.io.IOException;
+import java.net.DatagramSocket;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.TreeSet;
+import java.util.concurrent.Executor;
+import javax.sip.SipException;
+
+/**
+ * Timer that can schedule events to occur even when the device is in sleep.
+ */
+class SipWakeupTimer extends BroadcastReceiver {
+    private static final String TAG = "_SIP.WkTimer_";
+    private static final String TRIGGER_TIME = "TriggerTime";
+    private static final boolean DEBUG_TIMER = SipService.DEBUG && false;
+
+    private Context mContext;
+    private AlarmManager mAlarmManager;
+
+    // runnable --> time to execute in SystemClock
+    private TreeSet<MyEvent> mEventQueue =
+            new TreeSet<MyEvent>(new MyEventComparator());
+
+    private PendingIntent mPendingIntent;
+
+    private Executor mExecutor;
+
+    public SipWakeupTimer(Context context, Executor executor) {
+        mContext = context;
+        mAlarmManager = (AlarmManager)
+                context.getSystemService(Context.ALARM_SERVICE);
+
+        IntentFilter filter = new IntentFilter(getAction());
+        context.registerReceiver(this, filter);
+        mExecutor = executor;
+    }
+
+    /**
+     * Stops the timer. No event can be scheduled after this method is called.
+     */
+    public synchronized void stop() {
+        mContext.unregisterReceiver(this);
+        if (mPendingIntent != null) {
+            mAlarmManager.cancel(mPendingIntent);
+            mPendingIntent = null;
+        }
+        mEventQueue.clear();
+        mEventQueue = null;
+    }
+
+    private synchronized boolean stopped() {
+        if (mEventQueue == null) {
+            Log.w(TAG, "Timer stopped");
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    private void cancelAlarm() {
+        mAlarmManager.cancel(mPendingIntent);
+        mPendingIntent = null;
+    }
+
+    private void recalculatePeriods() {
+        if (mEventQueue.isEmpty()) return;
+
+        MyEvent firstEvent = mEventQueue.first();
+        int minPeriod = firstEvent.mMaxPeriod;
+        long minTriggerTime = firstEvent.mTriggerTime;
+        for (MyEvent e : mEventQueue) {
+            e.mPeriod = e.mMaxPeriod / minPeriod * minPeriod;
+            int interval = (int) (e.mLastTriggerTime + e.mMaxPeriod
+                    - minTriggerTime);
+            interval = interval / minPeriod * minPeriod;
+            e.mTriggerTime = minTriggerTime + interval;
+        }
+        TreeSet<MyEvent> newQueue = new TreeSet<MyEvent>(
+                mEventQueue.comparator());
+        newQueue.addAll((Collection<MyEvent>) mEventQueue);
+        mEventQueue.clear();
+        mEventQueue = newQueue;
+        if (DEBUG_TIMER) {
+            Log.d(TAG, "queue re-calculated");
+            printQueue();
+        }
+    }
+
+    // Determines the period and the trigger time of the new event and insert it
+    // to the queue.
+    private void insertEvent(MyEvent event) {
+        long now = SystemClock.elapsedRealtime();
+        if (mEventQueue.isEmpty()) {
+            event.mTriggerTime = now + event.mPeriod;
+            mEventQueue.add(event);
+            return;
+        }
+        MyEvent firstEvent = mEventQueue.first();
+        int minPeriod = firstEvent.mPeriod;
+        if (minPeriod <= event.mMaxPeriod) {
+            event.mPeriod = event.mMaxPeriod / minPeriod * minPeriod;
+            int interval = event.mMaxPeriod;
+            interval -= (int) (firstEvent.mTriggerTime - now);
+            interval = interval / minPeriod * minPeriod;
+            event.mTriggerTime = firstEvent.mTriggerTime + interval;
+            mEventQueue.add(event);
+        } else {
+            long triggerTime = now + event.mPeriod;
+            if (firstEvent.mTriggerTime < triggerTime) {
+                event.mTriggerTime = firstEvent.mTriggerTime;
+                event.mLastTriggerTime -= event.mPeriod;
+            } else {
+                event.mTriggerTime = triggerTime;
+            }
+            mEventQueue.add(event);
+            recalculatePeriods();
+        }
+    }
+
+    /**
+     * Sets a periodic timer.
+     *
+     * @param period the timer period; in milli-second
+     * @param callback is called back when the timer goes off; the same callback
+     *      can be specified in multiple timer events
+     */
+    public synchronized void set(int period, Runnable callback) {
+        if (stopped()) return;
+
+        long now = SystemClock.elapsedRealtime();
+        MyEvent event = new MyEvent(period, callback, now);
+        insertEvent(event);
+
+        if (mEventQueue.first() == event) {
+            if (mEventQueue.size() > 1) cancelAlarm();
+            scheduleNext();
+        }
+
+        long triggerTime = event.mTriggerTime;
+        if (DEBUG_TIMER) {
+            Log.d(TAG, " add event " + event + " scheduled at "
+                    + showTime(triggerTime) + " at " + showTime(now)
+                    + ", #events=" + mEventQueue.size());
+            printQueue();
+        }
+    }
+
+    /**
+     * Cancels all the timer events with the specified callback.
+     *
+     * @param callback the callback
+     */
+    public synchronized void cancel(Runnable callback) {
+        if (stopped() || mEventQueue.isEmpty()) return;
+        if (DEBUG_TIMER) Log.d(TAG, "cancel:" + callback);
+
+        MyEvent firstEvent = mEventQueue.first();
+        for (Iterator<MyEvent> iter = mEventQueue.iterator();
+                iter.hasNext();) {
+            MyEvent event = iter.next();
+            if (event.mCallback == callback) {
+                iter.remove();
+                if (DEBUG_TIMER) Log.d(TAG, "    cancel found:" + event);
+            }
+        }
+        if (mEventQueue.isEmpty()) {
+            cancelAlarm();
+        } else if (mEventQueue.first() != firstEvent) {
+            cancelAlarm();
+            firstEvent = mEventQueue.first();
+            firstEvent.mPeriod = firstEvent.mMaxPeriod;
+            firstEvent.mTriggerTime = firstEvent.mLastTriggerTime
+                    + firstEvent.mPeriod;
+            recalculatePeriods();
+            scheduleNext();
+        }
+        if (DEBUG_TIMER) {
+            Log.d(TAG, "after cancel:");
+            printQueue();
+        }
+    }
+
+    private void scheduleNext() {
+        if (stopped() || mEventQueue.isEmpty()) return;
+
+        if (mPendingIntent != null) {
+            throw new RuntimeException("pendingIntent is not null!");
+        }
+
+        MyEvent event = mEventQueue.first();
+        Intent intent = new Intent(getAction());
+        intent.putExtra(TRIGGER_TIME, event.mTriggerTime);
+        PendingIntent pendingIntent = mPendingIntent =
+                PendingIntent.getBroadcast(mContext, 0, intent,
+                        PendingIntent.FLAG_UPDATE_CURRENT);
+        mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
+                event.mTriggerTime, pendingIntent);
+    }
+
+    @Override
+    public void onReceive(Context context, Intent intent) {
+        // This callback is already protected by AlarmManager's wake lock.
+        String action = intent.getAction();
+        if (getAction().equals(action)
+                && intent.getExtras().containsKey(TRIGGER_TIME)) {
+            mPendingIntent = null;
+            long triggerTime = intent.getLongExtra(TRIGGER_TIME, -1L);
+            execute(triggerTime);
+        } else {
+            Log.d(TAG, "unrecognized intent: " + intent);
+        }
+    }
+
+    private void printQueue() {
+        int count = 0;
+        for (MyEvent event : mEventQueue) {
+            Log.d(TAG, "     " + event + ": scheduled at "
+                    + showTime(event.mTriggerTime) + ": last at "
+                    + showTime(event.mLastTriggerTime));
+            if (++count >= 5) break;
+        }
+        if (mEventQueue.size() > count) {
+            Log.d(TAG, "     .....");
+        } else if (count == 0) {
+            Log.d(TAG, "     <empty>");
+        }
+    }
+
+    private synchronized void execute(long triggerTime) {
+        if (DEBUG_TIMER) Log.d(TAG, "time's up, triggerTime = "
+                + showTime(triggerTime) + ": " + mEventQueue.size());
+        if (stopped() || mEventQueue.isEmpty()) return;
+
+        for (MyEvent event : mEventQueue) {
+            if (event.mTriggerTime != triggerTime) break;
+            if (DEBUG_TIMER) Log.d(TAG, "execute " + event);
+
+            event.mLastTriggerTime = event.mTriggerTime;
+            event.mTriggerTime += event.mPeriod;
+
+            // run the callback in the handler thread to prevent deadlock
+            mExecutor.execute(event.mCallback);
+        }
+        if (DEBUG_TIMER) {
+            Log.d(TAG, "after timeout execution");
+            printQueue();
+        }
+        scheduleNext();
+    }
+
+    private String getAction() {
+        return toString();
+    }
+
+    private String showTime(long time) {
+        int ms = (int) (time % 1000);
+        int s = (int) (time / 1000);
+        int m = s / 60;
+        s %= 60;
+        return String.format("%d.%d.%d", m, s, ms);
+    }
+
+    private static class MyEvent {
+        int mPeriod;
+        int mMaxPeriod;
+        long mTriggerTime;
+        long mLastTriggerTime;
+        Runnable mCallback;
+
+        MyEvent(int period, Runnable callback, long now) {
+            mPeriod = mMaxPeriod = period;
+            mCallback = callback;
+            mLastTriggerTime = now;
+        }
+
+        @Override
+        public String toString() {
+            String s = super.toString();
+            s = s.substring(s.indexOf("@"));
+            return s + ":" + (mPeriod / 1000) + ":" + (mMaxPeriod / 1000) + ":"
+                    + toString(mCallback);
+        }
+
+        private String toString(Object o) {
+            String s = o.toString();
+            int index = s.indexOf("$");
+            if (index > 0) s = s.substring(index + 1);
+            return s;
+        }
+    }
+
+    private static class MyEventComparator implements Comparator<MyEvent> {
+        public int compare(MyEvent e1, MyEvent e2) {
+            if (e1 == e2) return 0;
+            int diff = e1.mMaxPeriod - e2.mMaxPeriod;
+            if (diff == 0) diff = -1;
+            return diff;
+        }
+
+        public boolean equals(Object that) {
+            return (this == that);
+        }
+    }
+}
diff --git a/wifi/java/android/net/wifi/SupplicantState.java b/wifi/java/android/net/wifi/SupplicantState.java
index 6b79210..509b02c 100644
--- a/wifi/java/android/net/wifi/SupplicantState.java
+++ b/wifi/java/android/net/wifi/SupplicantState.java
@@ -39,6 +39,15 @@
     DISCONNECTED,
 
     /**
+     * Interface is disabled
+     * <p/>
+     * This state is entered if the network interface is disabled.
+     * wpa_supplicant refuses any new operations that would
+     * use the radio until the interface has been enabled.
+     */
+    INTERFACE_DISABLED,
+
+    /**
      * Inactive state (wpa_supplicant disabled).
      * <p/>
      * This state is entered if there are no enabled networks in the
@@ -57,6 +66,15 @@
     SCANNING,
 
     /**
+     * Trying to authenticate with a BSS/SSID
+     * <p/>
+     * This state is entered when wpa_supplicant has found a suitable BSS
+     * to authenticate with and the driver is configured to try to
+     * authenticate with this BSS.
+     */
+    AUTHENTICATING,
+
+    /**
      * Trying to associate with a BSS/SSID.
      * <p/>
      * This state is entered when wpa_supplicant has found a suitable BSS
@@ -152,8 +170,33 @@
         return state != UNINITIALIZED && state != INVALID;
     }
 
+
+    /* Supplicant associating or authenticating is considered a handshake state */
+    static boolean isHandshakeState(SupplicantState state) {
+        switch(state) {
+            case AUTHENTICATING:
+            case ASSOCIATING:
+            case ASSOCIATED:
+            case FOUR_WAY_HANDSHAKE:
+            case GROUP_HANDSHAKE:
+                return true;
+            case COMPLETED:
+            case DISCONNECTED:
+            case INTERFACE_DISABLED:
+            case INACTIVE:
+            case SCANNING:
+            case DORMANT:
+            case UNINITIALIZED:
+            case INVALID:
+                return false;
+            default:
+                throw new IllegalArgumentException("Unknown supplicant state");
+        }
+    }
+
     static boolean isConnecting(SupplicantState state) {
         switch(state) {
+            case AUTHENTICATING:
             case ASSOCIATING:
             case ASSOCIATED:
             case FOUR_WAY_HANDSHAKE:
@@ -161,6 +204,7 @@
             case COMPLETED:
                 return true;
             case DISCONNECTED:
+            case INTERFACE_DISABLED:
             case INACTIVE:
             case SCANNING:
             case DORMANT:
@@ -172,6 +216,28 @@
         }
     }
 
+    static boolean isDriverActive(SupplicantState state) {
+        switch(state) {
+            case DISCONNECTED:
+            case DORMANT:
+            case INACTIVE:
+            case AUTHENTICATING:
+            case ASSOCIATING:
+            case ASSOCIATED:
+            case SCANNING:
+            case FOUR_WAY_HANDSHAKE:
+            case GROUP_HANDSHAKE:
+            case COMPLETED:
+                return true;
+            case INTERFACE_DISABLED:
+            case UNINITIALIZED:
+            case INVALID:
+                return false;
+            default:
+                throw new IllegalArgumentException("Unknown supplicant state");
+        }
+    }
+
     /** Implement the Parcelable interface {@hide} */
     public int describeContents() {
         return 0;
diff --git a/wifi/java/android/net/wifi/SupplicantStateTracker.java b/wifi/java/android/net/wifi/SupplicantStateTracker.java
index 9ae26da..0c4f9f6 100644
--- a/wifi/java/android/net/wifi/SupplicantStateTracker.java
+++ b/wifi/java/android/net/wifi/SupplicantStateTracker.java
@@ -98,12 +98,16 @@
         if (DBG) Log.d(TAG, "Supplicant state: " + supState.toString() + "\n");
 
         switch (supState) {
-            case DISCONNECTED:
+           case DISCONNECTED:
                 transitionTo(mDisconnectState);
                 break;
+            case INTERFACE_DISABLED:
+                //we should have received a disconnection already, do nothing
+                break;
             case SCANNING:
                 transitionTo(mScanState);
                 break;
+            case AUTHENTICATING:
             case ASSOCIATING:
             case ASSOCIATED:
             case FOUR_WAY_HANDSHAKE:
@@ -250,10 +254,7 @@
                 case WifiStateMachine.SUPPLICANT_STATE_CHANGE_EVENT:
                     StateChangeResult stateChangeResult = (StateChangeResult) message.obj;
                     SupplicantState state = stateChangeResult.state;
-                    if (state == SupplicantState.ASSOCIATING ||
-                            state == SupplicantState.ASSOCIATED ||
-                            state == SupplicantState.FOUR_WAY_HANDSHAKE ||
-                            state == SupplicantState.GROUP_HANDSHAKE) {
+                    if (SupplicantState.isHandshakeState(state)) {
                         if (mLoopDetectIndex > state.ordinal()) {
                             mLoopDetectCount++;
                         }
@@ -296,12 +297,11 @@
                     StateChangeResult stateChangeResult = (StateChangeResult) message.obj;
                     SupplicantState state = stateChangeResult.state;
                     sendSupplicantStateChangedBroadcast(state, mAuthFailureInSupplicantBroadcast);
-                    /* Ignore a re-auth in completed state */
-                    if (state == SupplicantState.ASSOCIATING ||
-                            state == SupplicantState.ASSOCIATED ||
-                            state == SupplicantState.FOUR_WAY_HANDSHAKE ||
-                            state == SupplicantState.GROUP_HANDSHAKE ||
-                            state == SupplicantState.COMPLETED) {
+                    /* Ignore any connecting state in completed state. Group re-keying
+                     * events and other auth events that do not affect connectivity are
+                     * ignored
+                     */
+                    if (SupplicantState.isConnecting(state)) {
                         break;
                     }
                     transitionOnSupplicantStateChange(stateChangeResult);
diff --git a/wifi/java/android/net/wifi/WifiConfigStore.java b/wifi/java/android/net/wifi/WifiConfigStore.java
index 7f9fc31..d83b968 100644
--- a/wifi/java/android/net/wifi/WifiConfigStore.java
+++ b/wifi/java/android/net/wifi/WifiConfigStore.java
@@ -478,6 +478,21 @@
         }
     }
 
+    /**
+     * clear IP configuration for a given network id
+     */
+    static void clearIpConfiguration(int netId) {
+        synchronized (sConfiguredNetworks) {
+            WifiConfiguration config = sConfiguredNetworks.get(netId);
+            if (config != null && config.linkProperties != null) {
+                // Clear everything except proxy
+                ProxyProperties proxy = config.linkProperties.getHttpProxy();
+                config.linkProperties.clear();
+                config.linkProperties.setHttpProxy(proxy);
+            }
+        }
+    }
+
 
     /**
      * Fetch the proxy properties for a given network id
diff --git a/wifi/java/android/net/wifi/WifiInfo.java b/wifi/java/android/net/wifi/WifiInfo.java
index f60ae48..e3661bf 100644
--- a/wifi/java/android/net/wifi/WifiInfo.java
+++ b/wifi/java/android/net/wifi/WifiInfo.java
@@ -41,8 +41,10 @@
 
     static {
         stateMap.put(SupplicantState.DISCONNECTED, DetailedState.DISCONNECTED);
+        stateMap.put(SupplicantState.INTERFACE_DISABLED, DetailedState.DISCONNECTED);
         stateMap.put(SupplicantState.INACTIVE, DetailedState.IDLE);
         stateMap.put(SupplicantState.SCANNING, DetailedState.SCANNING);
+        stateMap.put(SupplicantState.AUTHENTICATING, DetailedState.CONNECTING);
         stateMap.put(SupplicantState.ASSOCIATING, DetailedState.CONNECTING);
         stateMap.put(SupplicantState.ASSOCIATED, DetailedState.CONNECTING);
         stateMap.put(SupplicantState.FOUR_WAY_HANDSHAKE, DetailedState.AUTHENTICATING);
diff --git a/wifi/java/android/net/wifi/WifiMonitor.java b/wifi/java/android/net/wifi/WifiMonitor.java
index 4a45825..4ec4cfc 100644
--- a/wifi/java/android/net/wifi/WifiMonitor.java
+++ b/wifi/java/android/net/wifi/WifiMonitor.java
@@ -107,7 +107,7 @@
      * <pre>
      * CTRL-EVENT-DRIVER-STATE state
      * </pre>
-     * <code>state</code> is either STARTED or STOPPED
+     * <code>state</code> can be HANGED
      */
     private static final String driverStateEvent = "DRIVER-STATE";
     /**
@@ -304,11 +304,7 @@
             if (state == null) {
                 return;
             }
-            if (state.equals("STOPPED")) {
-                mWifiStateMachine.notifyDriverStopped();
-            } else if (state.equals("STARTED")) {
-                mWifiStateMachine.notifyDriverStarted();
-            } else if (state.equals("HANGED")) {
+            if (state.equals("HANGED")) {
                 mWifiStateMachine.notifyDriverHung();
             }
         }
diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java
index bd6da64..2a033d1 100644
--- a/wifi/java/android/net/wifi/WifiStateMachine.java
+++ b/wifi/java/android/net/wifi/WifiStateMachine.java
@@ -212,22 +212,18 @@
     static final int SUP_CONNECTION_EVENT                 = BASE + 31;
     /* Connection to supplicant lost */
     static final int SUP_DISCONNECTION_EVENT              = BASE + 32;
-    /* Driver start completed */
-    static final int DRIVER_START_EVENT                   = BASE + 33;
-    /* Driver stop completed */
-    static final int DRIVER_STOP_EVENT                    = BASE + 34;
-    /* Network connection completed */
-    static final int NETWORK_CONNECTION_EVENT             = BASE + 36;
+   /* Network connection completed */
+    static final int NETWORK_CONNECTION_EVENT             = BASE + 33;
     /* Network disconnection completed */
-    static final int NETWORK_DISCONNECTION_EVENT          = BASE + 37;
+    static final int NETWORK_DISCONNECTION_EVENT          = BASE + 34;
     /* Scan results are available */
-    static final int SCAN_RESULTS_EVENT                   = BASE + 38;
+    static final int SCAN_RESULTS_EVENT                   = BASE + 35;
     /* Supplicate state changed */
-    static final int SUPPLICANT_STATE_CHANGE_EVENT        = BASE + 39;
+    static final int SUPPLICANT_STATE_CHANGE_EVENT        = BASE + 36;
     /* Password failure and EAP authentication failure */
-    static final int AUTHENTICATION_FAILURE_EVENT         = BASE + 40;
+    static final int AUTHENTICATION_FAILURE_EVENT         = BASE + 37;
     /* WPS overlap detected */
-    static final int WPS_OVERLAP_EVENT                    = BASE + 41;
+    static final int WPS_OVERLAP_EVENT                    = BASE + 38;
 
 
     /* Supplicant commands */
@@ -1032,9 +1028,6 @@
         boolean wifiTethered = false;
         boolean wifiAvailable = false;
 
-        IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE);
-        INetworkManagementService service = INetworkManagementService.Stub.asInterface(b);
-
         if (mCm == null) {
             mCm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
         }
@@ -1047,14 +1040,14 @@
 
                     InterfaceConfiguration ifcg = null;
                     try {
-                        ifcg = service.getInterfaceConfig(intf);
+                        ifcg = nwService.getInterfaceConfig(intf);
                         if (ifcg != null) {
                             /* IP/netmask: 192.168.43.1/255.255.255.0 */
                             ifcg.addr = new LinkAddress(NetworkUtils.numericToInetAddress(
                                     "192.168.43.1"), 24);
                             ifcg.interfaceFlags = "[up]";
 
-                            service.setInterfaceConfig(intf, ifcg);
+                            nwService.setInterfaceConfig(intf, ifcg);
                         }
                     } catch (Exception e) {
                         Log.e(TAG, "Error configuring interface " + intf + ", :" + e);
@@ -1378,7 +1371,7 @@
         intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT
                 | Intent.FLAG_RECEIVER_REPLACE_PENDING);
         intent.putExtra(WifiManager.EXTRA_NETWORK_INFO, mNetworkInfo);
-        intent.putExtra(WifiManager.EXTRA_LINK_PROPERTIES, mLinkProperties);
+        intent.putExtra(WifiManager.EXTRA_LINK_PROPERTIES, new LinkProperties (mLinkProperties));
         if (bssid != null)
             intent.putExtra(WifiManager.EXTRA_BSSID, bssid);
         mContext.sendStickyBroadcast(intent);
@@ -1394,7 +1387,7 @@
     private void sendLinkConfigurationChangedBroadcast() {
         Intent intent = new Intent(WifiManager.LINK_CONFIGURATION_CHANGED_ACTION);
         intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
-        intent.putExtra(WifiManager.EXTRA_LINK_PROPERTIES, mLinkProperties);
+        intent.putExtra(WifiManager.EXTRA_LINK_PROPERTIES, new LinkProperties(mLinkProperties));
         mContext.sendBroadcast(intent);
     }
 
@@ -1421,26 +1414,55 @@
         return mNetworkInfo.getDetailedState();
     }
 
+
+    private SupplicantState handleSupplicantStateChange(Message message) {
+        StateChangeResult stateChangeResult = (StateChangeResult) message.obj;
+        SupplicantState state = stateChangeResult.state;
+        // Supplicant state change
+        // [31-13] Reserved for future use
+        // [8 - 0] Supplicant state (as defined in SupplicantState.java)
+        // 50023 supplicant_state_changed (custom|1|5)
+        EventLog.writeEvent(EVENTLOG_SUPPLICANT_STATE_CHANGED, state.ordinal());
+        mWifiInfo.setSupplicantState(state);
+        // Network id is only valid when we start connecting
+        if (SupplicantState.isConnecting(state)) {
+            mWifiInfo.setNetworkId(stateChangeResult.networkId);
+        } else {
+            mWifiInfo.setNetworkId(WifiConfiguration.INVALID_NETWORK_ID);
+        }
+
+        if (state == SupplicantState.ASSOCIATING) {
+            /* BSSID is valid only in ASSOCIATING state */
+            mWifiInfo.setBSSID(stateChangeResult.BSSID);
+        }
+
+        mSupplicantStateTracker.sendMessage(Message.obtain(message));
+        mWpsStateMachine.sendMessage(Message.obtain(message));
+
+        return state;
+    }
+
     /**
      * Resets the Wi-Fi Connections by clearing any state, resetting any sockets
      * using the interface, stopping DHCP & disabling interface
      */
     private void handleNetworkDisconnect() {
-        Log.d(TAG, "Reset connections and stopping DHCP");
+        Log.d(TAG, "Stopping DHCP and clearing IP");
 
         /*
-         * Reset connections & stop DHCP
+         * stop DHCP
          */
-        NetworkUtils.resetConnections(mInterfaceName);
-
         if (mDhcpStateMachine != null) {
             mDhcpStateMachine.sendMessage(DhcpStateMachine.CMD_STOP_DHCP);
             mDhcpStateMachine.quit();
             mDhcpStateMachine = null;
         }
 
-        /* Disable interface */
-        NetworkUtils.disableInterface(mInterfaceName);
+        try {
+            nwService.clearInterfaceAddresses(mInterfaceName);
+        } catch (Exception e) {
+            Log.e(TAG, "Failed to clear IP addresses on disconnect" + e);
+        }
 
         /* Reset data structures */
         mWifiInfo.setInetAddress(null);
@@ -1456,10 +1478,13 @@
 
         /* Clear network properties */
         mLinkProperties.clear();
+        /* Clear IP settings if the network used DHCP */
+        if (!WifiConfigStore.isUsingStaticIp(mLastNetworkId)) {
+            WifiConfigStore.clearIpConfiguration(mLastNetworkId);
+        }
 
         mLastBssid= null;
         mLastNetworkId = WifiConfiguration.INVALID_NETWORK_ID;
-
     }
 
     void handlePreDhcpSetup() {
@@ -1522,7 +1547,6 @@
             if (!linkProperties.equals(mLinkProperties)) {
                 Log.d(TAG, "Link configuration changed for netId: " + mLastNetworkId
                     + " old: " + mLinkProperties + "new: " + linkProperties);
-                NetworkUtils.resetConnections(mInterfaceName);
                 mLinkProperties = linkProperties;
                 sendLinkConfigurationChangedBroadcast();
             }
@@ -1674,14 +1698,6 @@
         sendMessage(SCAN_RESULTS_EVENT);
     }
 
-    void notifyDriverStarted() {
-        sendMessage(DRIVER_START_EVENT);
-    }
-
-    void notifyDriverStopped() {
-        sendMessage(DRIVER_STOP_EVENT);
-    }
-
     void notifyDriverHung() {
         setWifiEnabled(false);
         setWifiEnabled(true);
@@ -1737,8 +1753,6 @@
                 case CMD_REASSOCIATE:
                 case SUP_CONNECTION_EVENT:
                 case SUP_DISCONNECTION_EVENT:
-                case DRIVER_START_EVENT:
-                case DRIVER_STOP_EVENT:
                 case NETWORK_CONNECTION_EVENT:
                 case NETWORK_DISCONNECTION_EVENT:
                 case SCAN_RESULTS_EVENT:
@@ -2284,13 +2298,19 @@
         public boolean processMessage(Message message) {
             if (DBG) Log.d(TAG, getName() + message.toString() + "\n");
             switch(message.what) {
-                case DRIVER_START_EVENT:
-                    transitionTo(mDriverStartedState);
+               case SUPPLICANT_STATE_CHANGE_EVENT:
+                    SupplicantState state = handleSupplicantStateChange(message);
+                    /* If suplicant is exiting out of INTERFACE_DISABLED state into
+                     * a state that indicates driver has started, it is ready to
+                     * receive driver commands
+                     */
+                    if (SupplicantState.isDriverActive(state)) {
+                        transitionTo(mDriverStartedState);
+                    }
                     break;
                     /* Queue driver commands & connection events */
                 case CMD_START_DRIVER:
                 case CMD_STOP_DRIVER:
-                case SUPPLICANT_STATE_CHANGE_EVENT:
                 case NETWORK_CONNECTION_EVENT:
                 case NETWORK_DISCONNECTION_EVENT:
                 case AUTHENTICATION_FAILURE_EVENT:
@@ -2429,8 +2449,11 @@
         public boolean processMessage(Message message) {
             if (DBG) Log.d(TAG, getName() + message.toString() + "\n");
             switch(message.what) {
-                case DRIVER_STOP_EVENT:
-                    transitionTo(mDriverStoppedState);
+                case SUPPLICANT_STATE_CHANGE_EVENT:
+                    SupplicantState state = handleSupplicantStateChange(message);
+                    if (state == SupplicantState.INTERFACE_DISABLED) {
+                        transitionTo(mDriverStoppedState);
+                    }
                     break;
                     /* Queue driver commands */
                 case CMD_START_DRIVER:
@@ -2465,11 +2488,23 @@
         public boolean processMessage(Message message) {
             if (DBG) Log.d(TAG, getName() + message.toString() + "\n");
             switch (message.what) {
-                case CMD_START_DRIVER:
-                    mWakeLock.acquire();
-                    WifiNative.startDriverCommand();
-                    transitionTo(mDriverStartingState);
-                    mWakeLock.release();
+               case CMD_START_DRIVER:
+                   mWakeLock.acquire();
+                   WifiNative.startDriverCommand();
+                   mWakeLock.release();
+                   break;
+                case SUPPLICANT_STATE_CHANGE_EVENT:
+                    SupplicantState state = handleSupplicantStateChange(message);
+                    /* A driver start causes supplicant to first report an INTERFACE_DISABLED
+                     * state before transitioning out of it for connection. Stay in
+                     * DriverStoppedState until we get an INTERFACE_DISABLED state and transition
+                     * to DriverStarting upon getting that
+                     * TODO: Fix this when the supplicant can be made to just transition out of
+                     * INTERFACE_DISABLED state when driver gets started
+                     */
+                    if (state == SupplicantState.INTERFACE_DISABLED) {
+                        transitionTo(mDriverStartingState);
+                    }
                     break;
                 default:
                     return NOT_HANDLED;
@@ -2535,29 +2570,8 @@
                     sendErrorBroadcast(WifiManager.WPS_OVERLAP_ERROR);
                     break;
                 case SUPPLICANT_STATE_CHANGE_EVENT:
-                    stateChangeResult = (StateChangeResult) message.obj;
-                    SupplicantState state = stateChangeResult.state;
-                    // Supplicant state change
-                    // [31-13] Reserved for future use
-                    // [8 - 0] Supplicant state (as defined in SupplicantState.java)
-                    // 50023 supplicant_state_changed (custom|1|5)
-                    EventLog.writeEvent(EVENTLOG_SUPPLICANT_STATE_CHANGED, state.ordinal());
-                    mWifiInfo.setSupplicantState(state);
-                    // Network id is only valid when we start connecting
-                    if (SupplicantState.isConnecting(state)) {
-                        mWifiInfo.setNetworkId(stateChangeResult.networkId);
-                    } else {
-                        mWifiInfo.setNetworkId(WifiConfiguration.INVALID_NETWORK_ID);
-                    }
-
-                    if (state == SupplicantState.ASSOCIATING) {
-                        /* BSSID is valid only in ASSOCIATING state */
-                        mWifiInfo.setBSSID(stateChangeResult.BSSID);
-                    }
-
-                    mSupplicantStateTracker.sendMessage(Message.obtain(message));
-                    mWpsStateMachine.sendMessage(Message.obtain(message));
-                    break;
+                    handleSupplicantStateChange(message);
+                   break;
                     /* Do a redundant disconnect without transition */
                 case CMD_DISCONNECT:
                     WifiNative.disconnectCommand();
@@ -2645,13 +2659,11 @@
             } else {
                 DhcpInfoInternal dhcpInfoInternal = WifiConfigStore.getIpConfiguration(
                         mLastNetworkId);
-                IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE);
-                INetworkManagementService netd = INetworkManagementService.Stub.asInterface(b);
                 InterfaceConfiguration ifcg = new InterfaceConfiguration();
                 ifcg.addr = dhcpInfoInternal.makeLinkAddress();
                 ifcg.interfaceFlags = "[up]";
                 try {
-                    netd.setInterfaceConfig(mInterfaceName, ifcg);
+                    nwService.setInterfaceConfig(mInterfaceName, ifcg);
                     Log.v(TAG, "Static IP configuration succeeded");
                     sendMessage(CMD_STATIC_IP_SUCCESS, dhcpInfoInternal);
                 } catch (RemoteException re) {
@@ -2805,7 +2817,6 @@
                     if (mWifiInfo.getNetworkId() == result.getNetworkId()) {
                         if (result.hasIpChanged()) {
                             Log.d(TAG,"Reconfiguring IP on connection");
-                            NetworkUtils.resetConnections(mInterfaceName);
                             transitionTo(mConnectingState);
                         }
                         if (result.hasProxyChanged()) {
@@ -2967,7 +2978,7 @@
                 case SUPPLICANT_STATE_CHANGE_EVENT:
                     StateChangeResult stateChangeResult = (StateChangeResult) message.obj;
                     setNetworkDetailedState(WifiInfo.getDetailedStateOf(stateChangeResult.state));
-                    /* DriverStartedState does the rest of the handling */
+                    /* ConnectModeState does the rest of the handling */
                     return NOT_HANDLED;
                 case CMD_START_SCAN:
                     /* Disable background scan temporarily during a regular scan */